fix(ai): remove <thinking> tag wrapping, convert to plain text on cross-model handoff

- Remove <thinking> tag generation from google-shared.ts, transorm-messages.ts, openai-completions.ts
- Thinking blocks now convert to plain text when switching models (prevents models mimicking tags)
- Skip empty thinking blocks to avoid API errors
- Keep thinking blocks only when same provider AND same model

fixes #561
This commit is contained in:
Mario Zechner
2026-01-08 21:19:16 +01:00
parent 8fda948866
commit 16e142ef7d
5 changed files with 17 additions and 12 deletions
@@ -490,10 +490,8 @@ function convertMessages(
const nonEmptyThinkingBlocks = thinkingBlocks.filter((b) => b.thinking && b.thinking.trim().length > 0);
if (nonEmptyThinkingBlocks.length > 0) {
if (compat.requiresThinkingAsText) {
// Convert thinking blocks to text with <thinking> delimiters
const thinkingText = nonEmptyThinkingBlocks
.map((b) => `<thinking>\n${b.thinking}\n</thinking>`)
.join("\n");
// Convert thinking blocks to plain text (no tags to avoid model mimicking them)
const thinkingText = nonEmptyThinkingBlocks.map((b) => b.thinking).join("\n\n");
const textContent = assistantMsg.content as Array<{ type: "text"; text: string }> | null;
if (textContent) {
textContent.unshift({ type: "text", text: thinkingText });