Spaces:
Sleeping
Sleeping
Thinking.. bubble
Browse files- src/App.js +21 -5
src/App.js
CHANGED
|
@@ -467,8 +467,9 @@ function App() {
|
|
| 467 |
const userMsg = { role: "user", text: input.trim() };
|
| 468 |
const newMessages = [...messages, userMsg];
|
| 469 |
|
| 470 |
-
// Create empty assistant bubble for streaming
|
| 471 |
-
|
|
|
|
| 472 |
newMessages.push(assistantMsg);
|
| 473 |
|
| 474 |
setMessages(newMessages);
|
|
@@ -489,7 +490,12 @@ function App() {
|
|
| 489 |
historyForBackend,
|
| 490 |
token,
|
| 491 |
(chunk) => {
|
| 492 |
-
assistantMsg.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 493 |
setMessages([...newMessages]); // re-render UI
|
| 494 |
},
|
| 495 |
sessionId
|
|
@@ -504,6 +510,7 @@ function App() {
|
|
| 504 |
if (typeof debugResult.reply === "string" && debugResult.reply.trim()) {
|
| 505 |
assistantMsg.text = debugResult.reply;
|
| 506 |
}
|
|
|
|
| 507 |
assistantMsg.debug = debugResult.prolog_query_info;
|
| 508 |
setMessages([...newMessages]);
|
| 509 |
} else {
|
|
@@ -515,6 +522,7 @@ function App() {
|
|
| 515 |
}
|
| 516 |
|
| 517 |
} catch (err) {
|
|
|
|
| 518 |
assistantMsg.text += `\n[Error: ${err.message}]`;
|
| 519 |
setMessages([...newMessages]);
|
| 520 |
} finally {
|
|
@@ -951,9 +959,17 @@ function Message({ message }) {
|
|
| 951 |
.replace(/```/g, "")
|
| 952 |
.trim();
|
| 953 |
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 954 |
const normalizedText = React.useMemo(
|
| 955 |
-
() => normalizeLatex(
|
| 956 |
-
[
|
| 957 |
);
|
| 958 |
|
| 959 |
return (
|
|
|
|
| 467 |
const userMsg = { role: "user", text: input.trim() };
|
| 468 |
const newMessages = [...messages, userMsg];
|
| 469 |
|
| 470 |
+
// Create empty assistant bubble for streaming.
|
| 471 |
+
// We render a "Thinking..." placeholder while text is still empty.
|
| 472 |
+
const assistantMsg = { role: "assistant", text: "", debug: null, thinking: true };
|
| 473 |
newMessages.push(assistantMsg);
|
| 474 |
|
| 475 |
setMessages(newMessages);
|
|
|
|
| 490 |
historyForBackend,
|
| 491 |
token,
|
| 492 |
(chunk) => {
|
| 493 |
+
if (assistantMsg.thinking && !(assistantMsg.text || "").trim()) {
|
| 494 |
+
assistantMsg.text = chunk;
|
| 495 |
+
assistantMsg.thinking = false;
|
| 496 |
+
} else {
|
| 497 |
+
assistantMsg.text += chunk; // append chunk
|
| 498 |
+
}
|
| 499 |
setMessages([...newMessages]); // re-render UI
|
| 500 |
},
|
| 501 |
sessionId
|
|
|
|
| 510 |
if (typeof debugResult.reply === "string" && debugResult.reply.trim()) {
|
| 511 |
assistantMsg.text = debugResult.reply;
|
| 512 |
}
|
| 513 |
+
assistantMsg.thinking = false;
|
| 514 |
assistantMsg.debug = debugResult.prolog_query_info;
|
| 515 |
setMessages([...newMessages]);
|
| 516 |
} else {
|
|
|
|
| 522 |
}
|
| 523 |
|
| 524 |
} catch (err) {
|
| 525 |
+
assistantMsg.thinking = false;
|
| 526 |
assistantMsg.text += `\n[Error: ${err.message}]`;
|
| 527 |
setMessages([...newMessages]);
|
| 528 |
} finally {
|
|
|
|
| 959 |
.replace(/```/g, "")
|
| 960 |
.trim();
|
| 961 |
}, []);
|
| 962 |
+
const displayText = React.useMemo(() => {
|
| 963 |
+
const raw = typeof message.text === "string" ? message.text : "";
|
| 964 |
+
if (!isUser && message.thinking && !raw.trim()) {
|
| 965 |
+
return "Thinking...";
|
| 966 |
+
}
|
| 967 |
+
return raw;
|
| 968 |
+
}, [message.text, message.thinking, isUser]);
|
| 969 |
+
|
| 970 |
const normalizedText = React.useMemo(
|
| 971 |
+
() => normalizeLatex(displayText),
|
| 972 |
+
[displayText]
|
| 973 |
);
|
| 974 |
|
| 975 |
return (
|