From 7ea2bceb789a2a22cd63792e7635ed68bd770b00 Mon Sep 17 00:00:00 2001 From: MT-Mint <798521692@qq.com> Date: Wed, 15 Apr 2026 13:59:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(workspace):=20=E7=BB=9F=E4=B8=80=E6=8A=98?= =?UTF-8?q?=E5=8F=A0=E6=80=9D=E8=80=83=E5=9D=97=E4=BB=A3=E7=A0=81=E4=BB=A5?= =?UTF-8?q?=E6=B6=88=E9=99=A4=E6=B5=81=E5=BC=8F=E6=8A=96=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除思考链代码块按长度判断的折叠策略,改为默认折叠\n- 为思考内容与 reasoning-only 路径添加代码块默认折叠渲染\n- 调整流式 Markdown 渲染参数,降低流式重排与闪烁 --- .../src/components/ai-elements/reasoning.tsx | 62 +++++++++++++--- .../workspace/messages/markdown-content.tsx | 3 + .../workspace/messages/message-group.tsx | 73 +++++++++++++------ 3 files changed, 105 insertions(+), 33 deletions(-) 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 && (