diff --git a/frontend/src/components/ai-elements/reasoning.tsx b/frontend/src/components/ai-elements/reasoning.tsx index 8c9d5b20..68c3f4bd 100644 --- a/frontend/src/components/ai-elements/reasoning.tsx +++ b/frontend/src/components/ai-elements/reasoning.tsx @@ -168,18 +168,56 @@ export type ReasoningContentProps = ComponentProps< }; export const ReasoningContent = memo( - ({ className, children, ...props }: ReasoningContentProps) => ( - - {children} - - ), + ({ className, children, ...props }: ReasoningContentProps) => { + const { isStreaming } = useReasoning(); + const thinkingComponents = { + code: ({ className, children, ...codeProps }: ComponentProps<"code">) => { + const isBlock = + typeof className === "string" && className.includes("language-"); + if (!isBlock) { + return ( + + {children} + + ); + } + return ( +
+ + Show code + +
+              
+                {children}
+              
+            
+
+ ); + }, + }; + return ( + + {isStreaming ? ( +
{children}
+ ) : ( + + {children} + + )} +
+ ); + }, ); Reasoning.displayName = "Reasoning"; diff --git a/frontend/src/components/workspace/messages/markdown-content.tsx b/frontend/src/components/workspace/messages/markdown-content.tsx index bf9e6f51..ab5de7ea 100644 --- a/frontend/src/components/workspace/messages/markdown-content.tsx +++ b/frontend/src/components/workspace/messages/markdown-content.tsx @@ -28,6 +28,7 @@ export type MarkdownContentProps = { /** Renders markdown content. */ export function MarkdownContent({ content, + isLoading, rehypePlugins, className, remarkPlugins = streamdownPlugins.remarkPlugins, @@ -66,6 +67,8 @@ export function MarkdownContent({ return ( ({ + code: ({ + className, + children, + ...props + }: ComponentProps<"code">) => { + const isBlock = + typeof className === "string" && className.includes("language-"); + if (!isBlock) { + return ( + + {children} + + ); + } + return ( +
+ + {t.toolCalls.expandContent} + +
+              
+                {children}
+              
+            
+
+ ); + }, + }), + [t.toolCalls.expandContent], + ); return ( } > @@ -185,6 +219,7 @@ export function MessageGroup({ content={lastReasoningStep.reasoning ?? ""} isLoading={isLoading} rehypePlugins={rehypePlugins} + components={thinkingComponents} /> } > @@ -227,8 +262,8 @@ function ToolCall({ language?: BundledLanguage; expanded?: boolean; }) => { - const shouldCollapse = content.length > TOOL_CONTENT_COLLAPSE_THRESHOLD; - const shouldShowCodeBlock = !shouldCollapse || expanded; + // Always start collapsed in thinking blocks; user must explicitly expand. + const shouldShowCodeBlock = expanded; return (
@@ -417,28 +452,24 @@ function ToolCall({ return t.toolCalls.executeCommand; } const command: string | undefined = (args as { command: string })?.command; - const shouldCollapse = - !!command && command.length > TOOL_CONTENT_COLLAPSE_THRESHOLD; return ( { - event.stopPropagation(); - setIsCommandExpanded((prev) => !prev); - }} - > - {isCommandExpanded - ? t.toolCalls.collapseContent - : t.toolCalls.expandContent} - - ) : undefined + } > {command && (