RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
fix(web): hide empty thinking strip in floating chat widget (#18608)
euvre2611ea5bdf79
diff --git a/web/src/utils/__tests__/chat.test.ts b/web/src/utils/__tests__/chat.test.tsindex 58626594e1..d187bfbbfc 100644--- a/web/src/utils/__tests__/chat.test.ts+++ b/web/src/utils/__tests__/chat.test.ts@@ -1,4 +1,4 @@-import { preprocessLaTeX } from '../chat';+import { preprocessLaTeX, replaceThinkToSection } from '../chat';describe('preprocessLaTeX', () => {it('converts block \\[ \\] to $$ $$', () => {@@ -33,3 +33,33 @@ describe('preprocessLaTeX', () => {expect(result).toBe('First $$a$$ then $$ b \\right] c $$');});});++describe('replaceThinkToSection', () => {+ it('drops an empty think section instead of rendering a bare strip', () => {+ expect(replaceThinkToSection('<think></think>Here is the answer.')).toBe(+ 'Here is the answer.',+ );+ });++ it('drops a whitespace-only think section', () => {+ expect(replaceThinkToSection('<think> \n </think>answer')).toBe('answer');+ });++ it('keeps a non-empty think section as a details block', () => {+ expect(replaceThinkToSection('<think>some reasoning</think>answer')).toBe(+ '<details class="think"><summary>Thinking...</summary>some reasoning</details>answer',+ );+ });++ it('uses the provided summary for non-empty sections', () => {+ expect(+ replaceThinkToSection('<think>reasoning</think>', 'Deep thought'),+ ).toBe(+ '<details class="think"><summary>Deep thought</summary>reasoning</details>',+ );+ });++ it('leaves text without think markers unchanged', () => {+ expect(replaceThinkToSection('plain answer')).toBe('plain answer');+ });+});diff --git a/web/src/utils/chat.ts b/web/src/utils/chat.tsindex d562851767..7041624fb1 100644--- a/web/src/utils/chat.ts+++ b/web/src/utils/chat.ts@@ -100,9 +100,12 @@ export function replaceThinkToSection() {const pattern = /<think>([\s\S]*?)<\/think>/g;- const result = text.replace(- pattern,- `<details class="think"><summary>${summary}</summary>$1</details>`,+ // An empty think section (the model replied without reasoning) must not+ // render as a bare "Thinking..." strip above the answer.+ const result = text.replace(pattern, (_match, thinkContent: string) =>+ thinkContent.trim().length === 0+ ? ''+ : `<details class="think"><summary>${summary}</summary>${thinkContent}</details>`,);return result;