diff --git a/src/agents/pi-embedded-utils.test.ts b/src/agents/pi-embedded-utils.test.ts index ab84a375d94..a7894452cec 100644 --- a/src/agents/pi-embedded-utils.test.ts +++ b/src/agents/pi-embedded-utils.test.ts @@ -461,6 +461,11 @@ File contents here`, text: "Some reasoningThe actual answer.", expected: "The actual answer.", }, + { + name: "antml namespaced thinking tag", + text: "This shows Robin Waslander DMing maintainers o...Actual reply.", + expected: "Actual reply.", + }, { name: "final wrapper", text: "\nAnswer\n", diff --git a/src/shared/text/reasoning-tags.test.ts b/src/shared/text/reasoning-tags.test.ts index 59f22c9212e..e85ee56615c 100644 --- a/src/shared/text/reasoning-tags.test.ts +++ b/src/shared/text/reasoning-tags.test.ts @@ -50,6 +50,11 @@ describe("stripReasoningTagsFromText", () => { input: "X internal Y", expected: "X Y", }, + { + name: "strips antml namespaced thinking tags", + input: "Before secret after", + expected: "Before after", + }, { name: "strips multiple reasoning blocks", input: "firstAsecondB", @@ -194,6 +199,10 @@ describe("stripReasoningTagsFromText", () => { input: "A hidden also hidden B", expected: "A B", }, + { + input: "A B", + expected: "A B", + }, ] as const)("handles unicode/attributes/case-insensitive names: %j", (testCase) => { expectStrippedCase(testCase); }); diff --git a/src/shared/text/reasoning-tags.ts b/src/shared/text/reasoning-tags.ts index fcf508b5724..62b73d5fe4f 100644 --- a/src/shared/text/reasoning-tags.ts +++ b/src/shared/text/reasoning-tags.ts @@ -2,9 +2,10 @@ import { findCodeRegions, isInsideCode } from "./code-regions.js"; export type ReasoningTagMode = "strict" | "preserve"; export type ReasoningTagTrim = "none" | "start" | "both"; -const QUICK_TAG_RE = /<\s*\/?\s*(?:think(?:ing)?|thought|antthinking|final)\b/i; +const QUICK_TAG_RE = /<\s*\/?\s*(?:(?:antml:)?(?:think(?:ing)?|thought)|antthinking|final)\b/i; const FINAL_TAG_RE = /<\s*\/?\s*final\b[^<>]*>/gi; -const THINKING_TAG_RE = /<\s*(\/?)\s*(?:think(?:ing)?|thought|antthinking)\b[^<>]*>/gi; +const THINKING_TAG_RE = + /<\s*(\/?)\s*(?:(?:antml:)?(?:think(?:ing)?|thought)|antthinking)\b[^<>]*>/gi; function applyTrim(value: string, mode: ReasoningTagTrim): string { if (mode === "none") {