fix: send anthropic thinking blocks also when thinking text is empty (#6457)

fixes: #6376
This commit is contained in:
David Brailovsky
2026-07-09 23:25:22 +02:00
committed by GitHub
parent 1a2542b11b
commit 6731a0ba9e
2 changed files with 13 additions and 5 deletions
+5 -3
View File
@@ -1081,11 +1081,13 @@ function convertMessages(
});
continue;
}
if (block.thinking.trim().length === 0) continue;
const thinkingSignature = block.thinkingSignature;
const hasThinkingSignature = !!thinkingSignature && thinkingSignature.trim().length > 0;
if (block.thinking.trim().length === 0 && !hasThinkingSignature) continue;
// If thinking signature is missing/empty (e.g., from aborted stream),
// convert to plain text for Anthropic. Some compatible providers emit
// and accept empty signatures, so let marked models preserve the block.
if (!block.thinkingSignature || block.thinkingSignature.trim().length === 0) {
if (!hasThinkingSignature) {
blocks.push(
allowEmptySignature
? {
@@ -1102,7 +1104,7 @@ function convertMessages(
blocks.push({
type: "thinking",
thinking: sanitizeSurrogates(block.thinking),
signature: block.thinkingSignature,
signature: thinkingSignature,
});
}
} else if (block.type === "toolCall") {