From 535c9bf2bb923e28933281a8429bcf5cabafa5ec Mon Sep 17 00:00:00 2001 From: Ayyan Shaikh <72731349+Ayyanaruto@users.noreply.github.com> Date: Tue, 14 Oct 2025 09:38:54 +0000 Subject: [PATCH] fix: remove blocks from chat title generation - Update removeCodeBlocksAndTrim to handle blocks from models like qwen3 - Add comprehensive test coverage for think block removal - Fixes issue where chat titles showed thinking process instead of content Fixes #5689 --- core/util/index.test.ts | 28 +++++++++++++++++++++++++++- core/util/index.ts | 8 +++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/core/util/index.test.ts b/core/util/index.test.ts index fc48a49b2..a77473c25 100644 --- a/core/util/index.test.ts +++ b/core/util/index.test.ts @@ -1,9 +1,9 @@ // File generated by Continue import { + copyOf, dedent, dedentAndGetCommonWhitespace, deduplicateArray, - copyOf, getMarkdownLanguageTagForFile, removeCodeBlocksAndTrim, removeQuotesAndEscapes, @@ -463,4 +463,30 @@ describe("removeCodeBlocksAndTrim", () => { const output = removeCodeBlocksAndTrim(text); expect(output).toBe(""); }); + it("should remove think blocks from text", () => { + const text = + "Okay, the user wants me to help with...Here is my actual response."; + const output = removeCodeBlocksAndTrim(text); + expect(output).toBe("Here is my actual response."); + }); + + it("should remove both code blocks and think blocks", () => { + const text = + "Let me plan this...Here's some code:\n```javascript\nconsole.log('hello');\n```\nThat should work!"; + const output = removeCodeBlocksAndTrim(text); + expect(output).toBe("Here's some code:\n\nThat should work!"); + }); + + it("should handle multiple think blocks", () => { + const text = + "First thoughtSome textSecond thoughtMore text"; + const output = removeCodeBlocksAndTrim(text); + expect(output).toBe("Some textMore text"); + }); + + it("should handle think blocks with newlines", () => { + const text = "\nMultiline\nthinking\n\nActual response"; + const output = removeCodeBlocksAndTrim(text); + expect(output).toBe("Actual response"); + }); }); diff --git a/core/util/index.ts b/core/util/index.ts index 4b3b17535..76b319bdd 100644 --- a/core/util/index.ts +++ b/core/util/index.ts @@ -197,11 +197,13 @@ export function dedent(strings: TemplateStringsArray, ...values: any[]) { */ export function removeCodeBlocksAndTrim(text: string): string { const codeBlockRegex = /```[\s\S]*?```/g; + const thinkBlockRegex = /[\s\S]*?<\/think>/g; - // Remove code blocks from the message text - const textWithoutCodeBlocks = text.replace(codeBlockRegex, ""); + // Remove code blocks and think blocks from the message text + let processedText = text.replace(codeBlockRegex, ""); + processedText = processedText.replace(thinkBlockRegex, ""); - return textWithoutCodeBlocks.trim(); + return processedText.trim(); } export function splitCamelCaseAndNonAlphaNumeric(value: string) {