From d757303fa4bf9e05b285ab04606b16d7870746bf Mon Sep 17 00:00:00 2001 From: euvre <93761161+euvre@users.noreply.github.com> Date: Wed, 22 Jul 2026 19:30:09 +0800 Subject: [PATCH] fix(web): show completed label for think block after streaming ends (#17149) --- web/src/components/markdown-content/index.tsx | 7 +++++-- .../components/next-markdown-content/index.tsx | 7 +++++-- web/src/locales/en.ts | 1 + web/src/utils/chat.ts | 15 ++++++++++++--- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/web/src/components/markdown-content/index.tsx b/web/src/components/markdown-content/index.tsx index 7f3e4b21a2..f6378bfea0 100644 --- a/web/src/components/markdown-content/index.tsx +++ b/web/src/components/markdown-content/index.tsx @@ -75,12 +75,15 @@ const MarkdownContent = ({ text = t('chat.searching'); } const nextText = replaceTextByOldReg(text); + const thinkSummary = loading + ? `${t('chat.thinking')}...` + : t('chat.thought'); return pipe( - replaceThinkToSection, + (value: string) => replaceThinkToSection(value, thinkSummary), replaceRetrievingToSection, preprocessLaTeX, )(nextText); - }, [content, t]); + }, [content, loading, t]); useEffect(() => { const docAggs = reference?.doc_aggs; diff --git a/web/src/components/next-markdown-content/index.tsx b/web/src/components/next-markdown-content/index.tsx index c30656912a..b56b584f4b 100644 --- a/web/src/components/next-markdown-content/index.tsx +++ b/web/src/components/next-markdown-content/index.tsx @@ -181,12 +181,15 @@ function MarkdownContent({ text = t('chat.searching'); } const nextText = replaceTextByOldReg(text); + const thinkSummary = loading + ? `${t('chat.thinking')}...` + : t('chat.thought'); return pipe( - replaceThinkToSection, + (value: string) => replaceThinkToSection(value, thinkSummary), replaceRetrievingToSection, preprocessLaTeX, )(nextText); - }, [content, t]); + }, [content, loading, t]); useEffect(() => { const docAggs = reference?.doc_aggs; diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts index 21debc71cc..6b54ef8546 100644 --- a/web/src/locales/en.ts +++ b/web/src/locales/en.ts @@ -1120,6 +1120,7 @@ This auto-tagging feature enhances retrieval by adding another layer of domain-s maxTokensInvalidMessage: 'Please enter a valid number for Max tokens.', maxTokensMinMessage: 'Max tokens cannot be less than 0.', thinking: 'Thinking', + thought: 'Thought', thinkingDefault: 'System default', thinkingEnabled: 'Enabled', thinkingDisabled: 'Disabled', diff --git a/web/src/utils/chat.ts b/web/src/utils/chat.ts index 923a4a9e3e..5b5bfd2cae 100644 --- a/web/src/utils/chat.ts +++ b/web/src/utils/chat.ts @@ -78,10 +78,16 @@ export const preprocessLaTeX = (content: string) => { return inlineProcessedContent; }; -export function replaceThinkToSection(text: string = '') { +export function replaceThinkToSection( + text: string = '', + summary: string = 'Thinking...', +) { const pattern = /([\s\S]*?)<\/think>/g; - const result = text.replace(pattern, '
Thinking...$1
'); + const result = text.replace( + pattern, + `
${summary}$1
`, + ); return result; } @@ -89,7 +95,10 @@ export function replaceThinkToSection(text: string = '') { export function replaceRetrievingToSection(text: string = '') { const pattern = /([\s\S]*?)<\/retrieving>/g; - const result = text.replace(pattern, '
Retrieving...$1
'); + const result = text.replace( + pattern, + '
Retrieving...$1
', + ); return result; }