fraudTech commited on
Commit
07ce4b4
·
1 Parent(s): 687fe0f

thinking expander

Browse files
Files changed (2) hide show
  1. web/src/App.css +68 -0
  2. web/src/App.tsx +72 -3
web/src/App.css CHANGED
@@ -1251,4 +1251,72 @@ details.tool-section[open] summary::before {
1251
  .thinking-expander:not([open]) .thinking-spinner {
1252
  border-top-color: #6e5d4d;
1253
  animation: none;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1254
  }
 
1251
  .thinking-expander:not([open]) .thinking-spinner {
1252
  border-top-color: #6e5d4d;
1253
  animation: none;
1254
+ }
1255
+
1256
+ /* Thinking Section - Expandable Intermediate Responses */
1257
+ .thinking-section {
1258
+ margin: 1rem 0;
1259
+ border: 1px solid #3a342e;
1260
+ border-radius: 6px;
1261
+ background: #1a1614;
1262
+ overflow: hidden;
1263
+ }
1264
+
1265
+ .thinking-header {
1266
+ padding: 0.75rem 1rem;
1267
+ background: #211d1a;
1268
+ cursor: pointer;
1269
+ display: flex;
1270
+ align-items: center;
1271
+ gap: 0.5rem;
1272
+ user-select: none;
1273
+ transition: background 0.2s ease;
1274
+ }
1275
+
1276
+ .thinking-header:hover {
1277
+ background: #2a2520;
1278
+ }
1279
+
1280
+ .thinking-icon {
1281
+ font-size: 1rem;
1282
+ opacity: 0.8;
1283
+ }
1284
+
1285
+ .thinking-label {
1286
+ color: #9d8264;
1287
+ font-size: 0.9rem;
1288
+ font-weight: 500;
1289
+ letter-spacing: 0.3px;
1290
+ }
1291
+
1292
+ .thinking-section[open] .thinking-header {
1293
+ border-bottom: 1px solid #3a342e;
1294
+ }
1295
+
1296
+ .thinking-content {
1297
+ padding: 1rem;
1298
+ background: #1a1614;
1299
+ color: #c9b8a3;
1300
+ font-size: 0.9rem;
1301
+ line-height: 1.6;
1302
+ max-height: 500px;
1303
+ overflow-y: auto;
1304
+ }
1305
+
1306
+ /* Live thinking indicator (while streaming, before final response) */
1307
+ .thinking-live {
1308
+ border-left: 3px solid #8b7355;
1309
+ padding-left: 1rem;
1310
+ margin: 0.5rem 0;
1311
+ background: rgba(139, 115, 85, 0.05);
1312
+ border-radius: 4px;
1313
+ }
1314
+
1315
+ .thinking-live-header {
1316
+ color: #8b7355;
1317
+ font-size: 0.85rem;
1318
+ font-weight: 600;
1319
+ margin-bottom: 0.5rem;
1320
+ letter-spacing: 0.5px;
1321
+ opacity: 0.9;
1322
  }
web/src/App.tsx CHANGED
@@ -399,17 +399,17 @@ function App() {
399
  // Stream content chunks as they arrive
400
  // CRITICAL: Immediately hide spinner when content starts streaming
401
  setIsLoading(false);
402
- setResponseComplete(true);
403
  setStatusMessage('');
404
 
405
  setMessages((prev) =>
406
  prev.map((msg) => {
407
  if (msg.id !== assistantId) return msg;
408
 
409
- // Always accumulate in content field (no separate thinking)
410
  return {
411
  ...msg,
412
- content: (msg.content || '') + data.chunk,
413
  };
414
  })
415
  );
@@ -502,6 +502,8 @@ function App() {
502
  ? {
503
  ...msg,
504
  content: data.content,
 
 
505
  // Keep existing toolCalls with their error flags, don't overwrite
506
  toolCalls: msg.toolCalls,
507
  }
@@ -694,6 +696,42 @@ function App() {
694
  </span>
695
  </div>
696
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
697
  {/* Final response content */}
698
  {message.content && (
699
  <div className="message-content">
@@ -724,6 +762,37 @@ function App() {
724
  </ReactMarkdown>
725
  </div>
726
  )}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
727
  {/* Tool calls - unchanged from original */}
728
  {message.toolCalls && message.toolCalls.length > 0 && (
729
  <div className="tool-calls">
 
399
  // Stream content chunks as they arrive
400
  // CRITICAL: Immediately hide spinner when content starts streaming
401
  setIsLoading(false);
402
+ setResponseComplete(false); // Still streaming, not complete yet
403
  setStatusMessage('');
404
 
405
  setMessages((prev) =>
406
  prev.map((msg) => {
407
  if (msg.id !== assistantId) return msg;
408
 
409
+ // Accumulate in thinkingContent while streaming
410
  return {
411
  ...msg,
412
+ thinkingContent: (msg.thinkingContent || '') + data.chunk,
413
  };
414
  })
415
  );
 
502
  ? {
503
  ...msg,
504
  content: data.content,
505
+ // Keep thinkingContent separate - don't overwrite
506
+ thinkingContent: msg.thinkingContent,
507
  // Keep existing toolCalls with their error flags, don't overwrite
508
  toolCalls: msg.toolCalls,
509
  }
 
696
  </span>
697
  </div>
698
  </div>
699
+ {/* Thinking/working content in expandable section */}
700
+ {message.thinkingContent && message.content && (
701
+ <details className="thinking-section" open={false}>
702
+ <summary className="thinking-header">
703
+ <span className="thinking-icon">💭</span>
704
+ <span className="thinking-label">View Thinking Process</span>
705
+ </summary>
706
+ <div className="thinking-content">
707
+ <ReactMarkdown
708
+ remarkPlugins={[remarkMath, remarkGfm]}
709
+ rehypePlugins={[rehypeKatex]}
710
+ components={{
711
+ code({ className, children, ...props }: any) {
712
+ const match = /language-(\w+)/.exec(className || '');
713
+ return match ? (
714
+ <SyntaxHighlighter
715
+ style={terminalTheme as any}
716
+ language={match[1]}
717
+ PreTag="div"
718
+ {...props}
719
+ >
720
+ {String(children).replace(/\n$/, '')}
721
+ </SyntaxHighlighter>
722
+ ) : (
723
+ <code className={className} {...props}>
724
+ {children}
725
+ </code>
726
+ );
727
+ },
728
+ }}
729
+ >
730
+ {preprocessMath(message.thinkingContent)}
731
+ </ReactMarkdown>
732
+ </div>
733
+ </details>
734
+ )}
735
  {/* Final response content */}
736
  {message.content && (
737
  <div className="message-content">
 
762
  </ReactMarkdown>
763
  </div>
764
  )}
765
+ {/* Show thinking content while streaming (no final response yet) */}
766
+ {message.thinkingContent && !message.content && (
767
+ <div className="message-content thinking-live">
768
+ <div className="thinking-live-header">💭 Thinking...</div>
769
+ <ReactMarkdown
770
+ remarkPlugins={[remarkMath, remarkGfm]}
771
+ rehypePlugins={[rehypeKatex]}
772
+ components={{
773
+ code({ className, children, ...props }: any) {
774
+ const match = /language-(\w+)/.exec(className || '');
775
+ return match ? (
776
+ <SyntaxHighlighter
777
+ style={terminalTheme as any}
778
+ language={match[1]}
779
+ PreTag="div"
780
+ {...props}
781
+ >
782
+ {String(children).replace(/\n$/, '')}
783
+ </SyntaxHighlighter>
784
+ ) : (
785
+ <code className={className} {...props}>
786
+ {children}
787
+ </code>
788
+ );
789
+ },
790
+ }}
791
+ >
792
+ {preprocessMath(message.thinkingContent)}
793
+ </ReactMarkdown>
794
+ </div>
795
+ )}
796
  {/* Tool calls - unchanged from original */}
797
  {message.toolCalls && message.toolCalls.length > 0 && (
798
  <div className="tool-calls">