Spaces:
Sleeping
Sleeping
memorisation fix
Browse files- web/src/App.tsx +231 -199
web/src/App.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import React, { useState, useRef, useEffect, useMemo } from 'react';
|
| 2 |
import ReactMarkdown, { defaultUrlTransform } from 'react-markdown';
|
| 3 |
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
| 4 |
import remarkMath from 'remark-math';
|
|
@@ -573,6 +573,218 @@ interface ConversationItem {
|
|
| 573 |
const GATEWAY_URL = import.meta.env.VITE_GATEWAY_URL || 'https://deepthoughtai-evo-gateway.hf.space';
|
| 574 |
console.log('App Gateway URL:', GATEWAY_URL); // Debug log
|
| 575 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 576 |
function App() {
|
| 577 |
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
| 578 |
const [user, setUser] = useState<User | null>(null);
|
|
@@ -1071,7 +1283,7 @@ function App() {
|
|
| 1071 |
}
|
| 1072 |
};
|
| 1073 |
|
| 1074 |
-
const copyAsMarkdown = (content: string, event: React.MouseEvent) => {
|
| 1075 |
const btn = event.currentTarget as HTMLElement;
|
| 1076 |
const svg = btn.querySelector('svg');
|
| 1077 |
|
|
@@ -1090,9 +1302,9 @@ function App() {
|
|
| 1090 |
}).catch(err => {
|
| 1091 |
console.error('Failed to copy:', err);
|
| 1092 |
});
|
| 1093 |
-
};
|
| 1094 |
|
| 1095 |
-
const copyEverything = (message: Message, event: React.MouseEvent) => {
|
| 1096 |
const btn = event.currentTarget as HTMLElement;
|
| 1097 |
const svg = btn.querySelector('svg');
|
| 1098 |
|
|
@@ -1131,7 +1343,11 @@ function App() {
|
|
| 1131 |
}).catch(err => {
|
| 1132 |
console.error('Failed to copy:', err);
|
| 1133 |
});
|
| 1134 |
-
};
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1135 |
|
| 1136 |
const handleLogin = (sessionId: string, userData: User) => {
|
| 1137 |
// Keep session only in memory - will be lost on refresh
|
|
@@ -1371,200 +1587,16 @@ function App() {
|
|
| 1371 |
</div>
|
| 1372 |
</div>
|
| 1373 |
) : (
|
| 1374 |
-
messages.map((message) =>
|
| 1375 |
-
|
| 1376 |
-
|
| 1377 |
-
|
| 1378 |
-
|
| 1379 |
-
|
| 1380 |
-
|
| 1381 |
-
|
| 1382 |
-
|
| 1383 |
-
|
| 1384 |
-
) : (
|
| 1385 |
-
<div className="avatar avatar--assistant">
|
| 1386 |
-
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
| 1387 |
-
<circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><line x1="12" y1="17" x2="12.01" y2="17"/>
|
| 1388 |
-
</svg>
|
| 1389 |
-
</div>
|
| 1390 |
-
)}
|
| 1391 |
-
</div>
|
| 1392 |
-
{/* Message body */}
|
| 1393 |
-
<div className="message-body">
|
| 1394 |
-
<div className="message-meta">
|
| 1395 |
-
<span className="message-role-label">
|
| 1396 |
-
{message.role === 'user' ? (user?.name ?? 'You') : 'EVO'}
|
| 1397 |
-
</span>
|
| 1398 |
-
<span className="message-time">{message.timestamp.toLocaleTimeString()}</span>
|
| 1399 |
-
{message.role === 'assistant' && (
|
| 1400 |
-
<div className="message-actions">
|
| 1401 |
-
<button
|
| 1402 |
-
className="action-btn"
|
| 1403 |
-
onClick={(e) => copyEverything(message, e)}
|
| 1404 |
-
title="Copy all (with tool outputs)"
|
| 1405 |
-
>
|
| 1406 |
-
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
| 1407 |
-
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
|
| 1408 |
-
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
|
| 1409 |
-
<circle cx="11.5" cy="11.5" r="1.5" fill="currentColor"></circle>
|
| 1410 |
-
<circle cx="16.5" cy="11.5" r="1.5" fill="currentColor"></circle>
|
| 1411 |
-
<circle cx="11.5" cy="16.5" r="1.5" fill="currentColor"></circle>
|
| 1412 |
-
<circle cx="16.5" cy="16.5" r="1.5" fill="currentColor"></circle>
|
| 1413 |
-
</svg>
|
| 1414 |
-
</button>
|
| 1415 |
-
<button
|
| 1416 |
-
className="action-btn"
|
| 1417 |
-
onClick={(e) => copyAsMarkdown(message.content, e)}
|
| 1418 |
-
title="Copy markdown"
|
| 1419 |
-
>
|
| 1420 |
-
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
| 1421 |
-
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
|
| 1422 |
-
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
|
| 1423 |
-
</svg>
|
| 1424 |
-
</button>
|
| 1425 |
-
</div>
|
| 1426 |
-
)}
|
| 1427 |
-
</div>
|
| 1428 |
-
{/* Message content */}
|
| 1429 |
-
{message.content && (
|
| 1430 |
-
<div className="message-content">
|
| 1431 |
-
{message.role === 'assistant' && message.isStreaming ? (
|
| 1432 |
-
(() => {
|
| 1433 |
-
const { safe, tail } = splitStreamingContent(message.content);
|
| 1434 |
-
return (
|
| 1435 |
-
<>
|
| 1436 |
-
{safe && <SegmentedMarkdown content={safe} />}
|
| 1437 |
-
{tail && <div className="streaming-content">{tail}</div>}
|
| 1438 |
-
</>
|
| 1439 |
-
);
|
| 1440 |
-
})()
|
| 1441 |
-
) : (
|
| 1442 |
-
<ReactMarkdown
|
| 1443 |
-
remarkPlugins={[[remarkMath, { singleDollarTextMath: true }], remarkGfm]}
|
| 1444 |
-
rehypePlugins={[[rehypeKatex, { throwOnError: false, strict: false }]]}
|
| 1445 |
-
urlTransform={allowDataImageUrl}
|
| 1446 |
-
components={{
|
| 1447 |
-
code({ className, children, ...props }: any) {
|
| 1448 |
-
const match = /language-(\w+)/.exec(className || '');
|
| 1449 |
-
const rawContent = String(children).replace(/\n$/, '');
|
| 1450 |
-
if (/\\begin\{(?:aligned|align\*?|equation\*?|gather\*?|multline\*?|array|matrix|pmatrix|bmatrix|vmatrix|Vmatrix|cases|split|eqnarray\*?)\}/.test(rawContent)) {
|
| 1451 |
-
return <KatexDisplay math={rawContent} />;
|
| 1452 |
-
}
|
| 1453 |
-
return match ? (
|
| 1454 |
-
<SyntaxHighlighter style={codeTheme as any} language={match[1]} PreTag="div" {...props}>
|
| 1455 |
-
{rawContent}
|
| 1456 |
-
</SyntaxHighlighter>
|
| 1457 |
-
) : (
|
| 1458 |
-
<code className={className} {...props}>{children}</code>
|
| 1459 |
-
);
|
| 1460 |
-
},
|
| 1461 |
-
img({ src, alt, ...props }: any) { return <PlotImage src={src} alt={alt} {...props} />; },
|
| 1462 |
-
}}
|
| 1463 |
-
>
|
| 1464 |
-
{preprocessMathContent(message.content)}
|
| 1465 |
-
</ReactMarkdown>
|
| 1466 |
-
)}
|
| 1467 |
-
</div>
|
| 1468 |
-
)}
|
| 1469 |
-
{/* Reasoning trace */}
|
| 1470 |
-
{message.reasoningContent && (
|
| 1471 |
-
<details
|
| 1472 |
-
className={`reasoning-trace${message.isStreaming ? ' reasoning-streaming' : ''}`}
|
| 1473 |
-
open={message.reasoningExpanded}
|
| 1474 |
-
onToggle={(e) => {
|
| 1475 |
-
const open = (e.currentTarget as HTMLDetailsElement).open;
|
| 1476 |
-
setMessages((prev) =>
|
| 1477 |
-
prev.map((m) => m.id === message.id ? { ...m, reasoningExpanded: open } : m)
|
| 1478 |
-
);
|
| 1479 |
-
}}
|
| 1480 |
-
>
|
| 1481 |
-
<summary className="reasoning-header">
|
| 1482 |
-
<span className="reasoning-icon"></span>
|
| 1483 |
-
<span>Reasoning</span>
|
| 1484 |
-
{message.isStreaming && (
|
| 1485 |
-
<span className="reasoning-live-indicator">
|
| 1486 |
-
<span className="reasoning-live-dot" />
|
| 1487 |
-
<span className="reasoning-live-dot" />
|
| 1488 |
-
<span className="reasoning-live-dot" />
|
| 1489 |
-
</span>
|
| 1490 |
-
)}
|
| 1491 |
-
</summary>
|
| 1492 |
-
<div
|
| 1493 |
-
className="reasoning-content"
|
| 1494 |
-
ref={(el) => { if (el && message.isStreaming) el.scrollTop = el.scrollHeight; }}
|
| 1495 |
-
>
|
| 1496 |
-
{message.reasoningContent}
|
| 1497 |
-
</div>
|
| 1498 |
-
</details>
|
| 1499 |
-
)}
|
| 1500 |
-
{/* Tool calls */}
|
| 1501 |
-
{message.toolCalls && message.toolCalls.length > 0 && (
|
| 1502 |
-
<div className="tool-calls">
|
| 1503 |
-
{message.toolCalls.map((tool, idx) => (
|
| 1504 |
-
<details key={idx} className="tool-call">
|
| 1505 |
-
<summary className="tool-call-header">
|
| 1506 |
-
<span className="tool-name">{tool.name.replace(/_exec$/, '').replace(/_/g, ' ')}</span>
|
| 1507 |
-
{tool.isGenerating && (
|
| 1508 |
-
<span className="tool-status generating">
|
| 1509 |
-
<span className="dot"></span><span className="dot"></span><span className="dot"></span>
|
| 1510 |
-
<span className="status-text">Generating...</span>
|
| 1511 |
-
</span>
|
| 1512 |
-
)}
|
| 1513 |
-
{tool.isExecuting && (
|
| 1514 |
-
<span className="tool-status executing">
|
| 1515 |
-
<span className="dot"></span><span className="dot"></span><span className="dot"></span>
|
| 1516 |
-
<span className="status-text">Executing...</span>
|
| 1517 |
-
</span>
|
| 1518 |
-
)}
|
| 1519 |
-
{tool.output && !tool.isGenerating && !tool.isExecuting && (
|
| 1520 |
-
tool.error ? <span className="crossmark">✗</span> : <span className="checkmark">✓</span>
|
| 1521 |
-
)}
|
| 1522 |
-
</summary>
|
| 1523 |
-
<div className="tool-call-content">
|
| 1524 |
-
<details className="tool-section">
|
| 1525 |
-
<summary className="tool-section-label">Input:</summary>
|
| 1526 |
-
<pre className="tool-code tool-input-scroll">{tool.input}</pre>
|
| 1527 |
-
</details>
|
| 1528 |
-
{tool.output && (
|
| 1529 |
-
<div className="tool-section">
|
| 1530 |
-
<div className="tool-section-label">Output:</div>
|
| 1531 |
-
<div className="tool-output">
|
| 1532 |
-
<ReactMarkdown
|
| 1533 |
-
remarkPlugins={[[remarkMath, { singleDollarTextMath: true }], remarkGfm]}
|
| 1534 |
-
rehypePlugins={[[rehypeKatex, { throwOnError: false, strict: false }]]}
|
| 1535 |
-
urlTransform={allowDataImageUrl}
|
| 1536 |
-
components={{
|
| 1537 |
-
code({ className, children, ...props }: any) {
|
| 1538 |
-
const match = /language-(\w+)/.exec(className || '');
|
| 1539 |
-
const rawContent = String(children).replace(/\n$/, '');
|
| 1540 |
-
if (/\\begin\{(?:aligned|align\*?|equation\*?|gather\*?|multline\*?|array|matrix|pmatrix|bmatrix|vmatrix|Vmatrix|cases|split|eqnarray\*?)\}/.test(rawContent)) {
|
| 1541 |
-
return <KatexDisplay math={rawContent} />;
|
| 1542 |
-
}
|
| 1543 |
-
return match ? (
|
| 1544 |
-
<SyntaxHighlighter style={codeTheme as any} language={match[1]} PreTag="div" {...props}>
|
| 1545 |
-
{rawContent}
|
| 1546 |
-
</SyntaxHighlighter>
|
| 1547 |
-
) : (
|
| 1548 |
-
<code className={className} {...props}>{children}</code>
|
| 1549 |
-
);
|
| 1550 |
-
},
|
| 1551 |
-
img({ src, alt, ...props }: any) { return <PlotImage src={src} alt={alt} {...props} />; },
|
| 1552 |
-
}}
|
| 1553 |
-
>
|
| 1554 |
-
{preprocessMathContent(tool.output)}
|
| 1555 |
-
</ReactMarkdown>
|
| 1556 |
-
</div>
|
| 1557 |
-
</div>
|
| 1558 |
-
)}
|
| 1559 |
-
</div>
|
| 1560 |
-
</details>
|
| 1561 |
-
))}
|
| 1562 |
-
</div>
|
| 1563 |
-
)}
|
| 1564 |
-
</div>
|
| 1565 |
-
</div>
|
| 1566 |
-
);
|
| 1567 |
-
})
|
| 1568 |
)}
|
| 1569 |
|
| 1570 |
{isLoading && !responseComplete && (
|
|
|
|
| 1 |
+
import React, { useState, useRef, useEffect, useMemo, useCallback } from 'react';
|
| 2 |
import ReactMarkdown, { defaultUrlTransform } from 'react-markdown';
|
| 3 |
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
| 4 |
import remarkMath from 'remark-math';
|
|
|
|
| 573 |
const GATEWAY_URL = import.meta.env.VITE_GATEWAY_URL || 'https://deepthoughtai-evo-gateway.hf.space';
|
| 574 |
console.log('App Gateway URL:', GATEWAY_URL); // Debug log
|
| 575 |
|
| 576 |
+
// ---------------------------------------------------------------------------
|
| 577 |
+
// MessageItem – memoized so keystroke-driven re-renders don't re-render every
|
| 578 |
+
// historical message. Only the specific message that changes re-renders.
|
| 579 |
+
// ---------------------------------------------------------------------------
|
| 580 |
+
interface MessageItemProps {
|
| 581 |
+
message: Message;
|
| 582 |
+
userName: string | undefined;
|
| 583 |
+
onCopyMarkdown: (content: string, event: React.MouseEvent) => void;
|
| 584 |
+
onCopyEverything: (message: Message, event: React.MouseEvent) => void;
|
| 585 |
+
onToggleReasoning: (messageId: string, open: boolean) => void;
|
| 586 |
+
}
|
| 587 |
+
|
| 588 |
+
const MessageItem = React.memo(function MessageItem({
|
| 589 |
+
message,
|
| 590 |
+
userName,
|
| 591 |
+
onCopyMarkdown,
|
| 592 |
+
onCopyEverything,
|
| 593 |
+
onToggleReasoning,
|
| 594 |
+
}: MessageItemProps) {
|
| 595 |
+
const codeTheme = React.useContext(CodeThemeContext);
|
| 596 |
+
if (
|
| 597 |
+
message.role === 'assistant' &&
|
| 598 |
+
!message.content &&
|
| 599 |
+
!message.reasoningContent &&
|
| 600 |
+
(!message.toolCalls || message.toolCalls.length === 0)
|
| 601 |
+
) {
|
| 602 |
+
return null;
|
| 603 |
+
}
|
| 604 |
+
return (
|
| 605 |
+
<div className={`message message-${message.role}`}>
|
| 606 |
+
<div className="message-avatar">
|
| 607 |
+
{message.role === 'user' ? (
|
| 608 |
+
<div className="avatar avatar--user">{userName?.[0]?.toUpperCase() ?? 'U'}</div>
|
| 609 |
+
) : (
|
| 610 |
+
<div className="avatar avatar--assistant">
|
| 611 |
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
| 612 |
+
<circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><line x1="12" y1="17" x2="12.01" y2="17"/>
|
| 613 |
+
</svg>
|
| 614 |
+
</div>
|
| 615 |
+
)}
|
| 616 |
+
</div>
|
| 617 |
+
<div className="message-body">
|
| 618 |
+
<div className="message-meta">
|
| 619 |
+
<span className="message-role-label">
|
| 620 |
+
{message.role === 'user' ? (userName ?? 'You') : 'EVO'}
|
| 621 |
+
</span>
|
| 622 |
+
<span className="message-time">{message.timestamp.toLocaleTimeString()}</span>
|
| 623 |
+
{message.role === 'assistant' && (
|
| 624 |
+
<div className="message-actions">
|
| 625 |
+
<button
|
| 626 |
+
className="action-btn"
|
| 627 |
+
onClick={(e) => onCopyEverything(message, e)}
|
| 628 |
+
title="Copy all (with tool outputs)"
|
| 629 |
+
>
|
| 630 |
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
| 631 |
+
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
|
| 632 |
+
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
|
| 633 |
+
<circle cx="11.5" cy="11.5" r="1.5" fill="currentColor"></circle>
|
| 634 |
+
<circle cx="16.5" cy="11.5" r="1.5" fill="currentColor"></circle>
|
| 635 |
+
<circle cx="11.5" cy="16.5" r="1.5" fill="currentColor"></circle>
|
| 636 |
+
<circle cx="16.5" cy="16.5" r="1.5" fill="currentColor"></circle>
|
| 637 |
+
</svg>
|
| 638 |
+
</button>
|
| 639 |
+
<button
|
| 640 |
+
className="action-btn"
|
| 641 |
+
onClick={(e) => onCopyMarkdown(message.content, e)}
|
| 642 |
+
title="Copy markdown"
|
| 643 |
+
>
|
| 644 |
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
| 645 |
+
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
|
| 646 |
+
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
|
| 647 |
+
</svg>
|
| 648 |
+
</button>
|
| 649 |
+
</div>
|
| 650 |
+
)}
|
| 651 |
+
</div>
|
| 652 |
+
{message.content && (
|
| 653 |
+
<div className="message-content">
|
| 654 |
+
{message.role === 'assistant' && message.isStreaming ? (
|
| 655 |
+
(() => {
|
| 656 |
+
const { safe, tail } = splitStreamingContent(message.content);
|
| 657 |
+
return (
|
| 658 |
+
<>
|
| 659 |
+
{safe && <SegmentedMarkdown content={safe} />}
|
| 660 |
+
{tail && <div className="streaming-content">{tail}</div>}
|
| 661 |
+
</>
|
| 662 |
+
);
|
| 663 |
+
})()
|
| 664 |
+
) : (
|
| 665 |
+
<ReactMarkdown
|
| 666 |
+
remarkPlugins={[[remarkMath, { singleDollarTextMath: true }], remarkGfm]}
|
| 667 |
+
rehypePlugins={[[rehypeKatex, { throwOnError: false, strict: false }]]}
|
| 668 |
+
urlTransform={allowDataImageUrl}
|
| 669 |
+
components={{
|
| 670 |
+
code({ className, children, ...props }: any) {
|
| 671 |
+
const match = /language-(\w+)/.exec(className || '');
|
| 672 |
+
const rawContent = String(children).replace(/\n$/, '');
|
| 673 |
+
if (/\\begin\{(?:aligned|align\*?|equation\*?|gather\*?|multline\*?|array|matrix|pmatrix|bmatrix|vmatrix|Vmatrix|cases|split|eqnarray\*?)\}/.test(rawContent)) {
|
| 674 |
+
return <KatexDisplay math={rawContent} />;
|
| 675 |
+
}
|
| 676 |
+
return match ? (
|
| 677 |
+
<SyntaxHighlighter style={codeTheme as any} language={match[1]} PreTag="div" {...props}>
|
| 678 |
+
{rawContent}
|
| 679 |
+
</SyntaxHighlighter>
|
| 680 |
+
) : (
|
| 681 |
+
<code className={className} {...props}>{children}</code>
|
| 682 |
+
);
|
| 683 |
+
},
|
| 684 |
+
img({ src, alt, ...props }: any) { return <PlotImage src={src} alt={alt} {...props} />; },
|
| 685 |
+
}}
|
| 686 |
+
>
|
| 687 |
+
{preprocessMathContent(message.content)}
|
| 688 |
+
</ReactMarkdown>
|
| 689 |
+
)}
|
| 690 |
+
</div>
|
| 691 |
+
)}
|
| 692 |
+
{message.reasoningContent && (
|
| 693 |
+
<details
|
| 694 |
+
className={`reasoning-trace${message.isStreaming ? ' reasoning-streaming' : ''}`}
|
| 695 |
+
open={message.reasoningExpanded}
|
| 696 |
+
onToggle={(e) => {
|
| 697 |
+
const open = (e.currentTarget as HTMLDetailsElement).open;
|
| 698 |
+
onToggleReasoning(message.id, open);
|
| 699 |
+
}}
|
| 700 |
+
>
|
| 701 |
+
<summary className="reasoning-header">
|
| 702 |
+
<span className="reasoning-icon"></span>
|
| 703 |
+
<span>Reasoning</span>
|
| 704 |
+
{message.isStreaming && (
|
| 705 |
+
<span className="reasoning-live-indicator">
|
| 706 |
+
<span className="reasoning-live-dot" />
|
| 707 |
+
<span className="reasoning-live-dot" />
|
| 708 |
+
<span className="reasoning-live-dot" />
|
| 709 |
+
</span>
|
| 710 |
+
)}
|
| 711 |
+
</summary>
|
| 712 |
+
<div
|
| 713 |
+
className="reasoning-content"
|
| 714 |
+
ref={(el) => { if (el && message.isStreaming) el.scrollTop = el.scrollHeight; }}
|
| 715 |
+
>
|
| 716 |
+
{message.reasoningContent}
|
| 717 |
+
</div>
|
| 718 |
+
</details>
|
| 719 |
+
)}
|
| 720 |
+
{message.toolCalls && message.toolCalls.length > 0 && (
|
| 721 |
+
<div className="tool-calls">
|
| 722 |
+
{message.toolCalls.map((tool, idx) => (
|
| 723 |
+
<details key={idx} className="tool-call">
|
| 724 |
+
<summary className="tool-call-header">
|
| 725 |
+
<span className="tool-name">{tool.name.replace(/_exec$/, '').replace(/_/g, ' ')}</span>
|
| 726 |
+
{tool.isGenerating && (
|
| 727 |
+
<span className="tool-status generating">
|
| 728 |
+
<span className="dot"></span><span className="dot"></span><span className="dot"></span>
|
| 729 |
+
<span className="status-text">Generating...</span>
|
| 730 |
+
</span>
|
| 731 |
+
)}
|
| 732 |
+
{tool.isExecuting && (
|
| 733 |
+
<span className="tool-status executing">
|
| 734 |
+
<span className="dot"></span><span className="dot"></span><span className="dot"></span>
|
| 735 |
+
<span className="status-text">Executing...</span>
|
| 736 |
+
</span>
|
| 737 |
+
)}
|
| 738 |
+
{tool.output && !tool.isGenerating && !tool.isExecuting && (
|
| 739 |
+
tool.error ? <span className="crossmark">✗</span> : <span className="checkmark">✓</span>
|
| 740 |
+
)}
|
| 741 |
+
</summary>
|
| 742 |
+
<div className="tool-call-content">
|
| 743 |
+
<details className="tool-section">
|
| 744 |
+
<summary className="tool-section-label">Input:</summary>
|
| 745 |
+
<pre className="tool-code tool-input-scroll">{tool.input}</pre>
|
| 746 |
+
</details>
|
| 747 |
+
{tool.output && (
|
| 748 |
+
<div className="tool-section">
|
| 749 |
+
<div className="tool-section-label">Output:</div>
|
| 750 |
+
<div className="tool-output">
|
| 751 |
+
<ReactMarkdown
|
| 752 |
+
remarkPlugins={[[remarkMath, { singleDollarTextMath: true }], remarkGfm]}
|
| 753 |
+
rehypePlugins={[[rehypeKatex, { throwOnError: false, strict: false }]]}
|
| 754 |
+
urlTransform={allowDataImageUrl}
|
| 755 |
+
components={{
|
| 756 |
+
code({ className, children, ...props }: any) {
|
| 757 |
+
const match = /language-(\w+)/.exec(className || '');
|
| 758 |
+
const rawContent = String(children).replace(/\n$/, '');
|
| 759 |
+
if (/\\begin\{(?:aligned|align\*?|equation\*?|gather\*?|multline\*?|array|matrix|pmatrix|bmatrix|vmatrix|Vmatrix|cases|split|eqnarray\*?)\}/.test(rawContent)) {
|
| 760 |
+
return <KatexDisplay math={rawContent} />;
|
| 761 |
+
}
|
| 762 |
+
return match ? (
|
| 763 |
+
<SyntaxHighlighter style={codeTheme as any} language={match[1]} PreTag="div" {...props}>
|
| 764 |
+
{rawContent}
|
| 765 |
+
</SyntaxHighlighter>
|
| 766 |
+
) : (
|
| 767 |
+
<code className={className} {...props}>{children}</code>
|
| 768 |
+
);
|
| 769 |
+
},
|
| 770 |
+
img({ src, alt, ...props }: any) { return <PlotImage src={src} alt={alt} {...props} />; },
|
| 771 |
+
}}
|
| 772 |
+
>
|
| 773 |
+
{preprocessMathContent(tool.output)}
|
| 774 |
+
</ReactMarkdown>
|
| 775 |
+
</div>
|
| 776 |
+
</div>
|
| 777 |
+
)}
|
| 778 |
+
</div>
|
| 779 |
+
</details>
|
| 780 |
+
))}
|
| 781 |
+
</div>
|
| 782 |
+
)}
|
| 783 |
+
</div>
|
| 784 |
+
</div>
|
| 785 |
+
);
|
| 786 |
+
});
|
| 787 |
+
|
| 788 |
function App() {
|
| 789 |
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
| 790 |
const [user, setUser] = useState<User | null>(null);
|
|
|
|
| 1283 |
}
|
| 1284 |
};
|
| 1285 |
|
| 1286 |
+
const copyAsMarkdown = useCallback((content: string, event: React.MouseEvent) => {
|
| 1287 |
const btn = event.currentTarget as HTMLElement;
|
| 1288 |
const svg = btn.querySelector('svg');
|
| 1289 |
|
|
|
|
| 1302 |
}).catch(err => {
|
| 1303 |
console.error('Failed to copy:', err);
|
| 1304 |
});
|
| 1305 |
+
}, []);
|
| 1306 |
|
| 1307 |
+
const copyEverything = useCallback((message: Message, event: React.MouseEvent) => {
|
| 1308 |
const btn = event.currentTarget as HTMLElement;
|
| 1309 |
const svg = btn.querySelector('svg');
|
| 1310 |
|
|
|
|
| 1343 |
}).catch(err => {
|
| 1344 |
console.error('Failed to copy:', err);
|
| 1345 |
});
|
| 1346 |
+
}, []);
|
| 1347 |
+
|
| 1348 |
+
const handleToggleReasoning = useCallback((messageId: string, open: boolean) => {
|
| 1349 |
+
setMessages((prev) => prev.map((m) => m.id === messageId ? { ...m, reasoningExpanded: open } : m));
|
| 1350 |
+
}, []);
|
| 1351 |
|
| 1352 |
const handleLogin = (sessionId: string, userData: User) => {
|
| 1353 |
// Keep session only in memory - will be lost on refresh
|
|
|
|
| 1587 |
</div>
|
| 1588 |
</div>
|
| 1589 |
) : (
|
| 1590 |
+
messages.map((message) => (
|
| 1591 |
+
<MessageItem
|
| 1592 |
+
key={message.id}
|
| 1593 |
+
message={message}
|
| 1594 |
+
userName={user?.name}
|
| 1595 |
+
onCopyMarkdown={copyAsMarkdown}
|
| 1596 |
+
onCopyEverything={copyEverything}
|
| 1597 |
+
onToggleReasoning={handleToggleReasoning}
|
| 1598 |
+
/>
|
| 1599 |
+
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1600 |
)}
|
| 1601 |
|
| 1602 |
{isLoading && !responseComplete && (
|