diff --git a/packages/ai/src/dialect/demotion.ts b/packages/ai/src/dialect/demotion.ts index bf5ea07e1..f89b2218f 100644 --- a/packages/ai/src/dialect/demotion.ts +++ b/packages/ai/src/dialect/demotion.ts @@ -28,8 +28,9 @@ const CLAUDE_FABLE_ID = /(?:^|[./])claude[-.]fable(?:[-.]|$)/i; export function renderDemotedThinking(modelId: string, text: string): string { if (!text) return ""; text = text.toWellFormed(); + const canonicalId = bareModelId(modelId); const dialect = preferredDialect(modelId); - if (CLAUDE_FABLE_ID.test(bareModelId(modelId))) return `_Hmm. ${text}_\n`; + if (CLAUDE_FABLE_ID.test(canonicalId)) return `_Hmm. ${text}_\n`; if (dialect === "harmony" || dialect === "gemma") return `\n${text}\n\n`; return `${getDialectDefinition(dialect).renderThinking(text)}\n`; } diff --git a/packages/ai/test/anthropic-prior-turn-thinking.test.ts b/packages/ai/test/anthropic-prior-turn-thinking.test.ts index 57f06d17f..10023131b 100644 --- a/packages/ai/test/anthropic-prior-turn-thinking.test.ts +++ b/packages/ai/test/anthropic-prior-turn-thinking.test.ts @@ -344,9 +344,7 @@ describe("Anthropic prior-turn thinking preservation (#2257, #2265)", () => { if (!assistant) throw new Error("expected assistant wire message"); const blocks = assistant.content as WireBlock[]; const textBlocks = blocks.filter((b): b is WireTextBlock => b.type === "text"); - expect(textBlocks.every(block => block.text !== renderDemotedThinking(modelCase.id, reasoning))).toBe(true); - expect(textBlocks.every(block => !block.text.startsWith("_Hmm."))).toBe(true); - expect(textBlocks.every(block => !block.text.includes(""))).toBe(true); + expect(textBlocks).toHaveLength(0); expect(blocks.find(b => b.type === "thinking")).toBeUndefined(); const toolUse = blocks.find(b => b.type === "tool_use") as WireToolUseBlock | undefined; expect(toolUse?.id).toBe(toolCallId);