mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
fix(claude): drop foreign thinking signatures in passthrough
Combo mixes models, so non-Claude thinking signatures leak into conversation history. Native passthrough forwarded them verbatim and Anthropic rejected the request. Validate signatures and drop invalid thinking blocks, re-inserting a placeholder when tool_use requires one. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -150,6 +150,33 @@ export function normalizeClaudePassthrough(body, model = "") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3. Drop thinking blocks whose signature is not Claude's (combo mixes models,
|
||||||
|
// so foreign signatures leak into history and Anthropic rejects them).
|
||||||
|
const thinkingEnabled = body.thinking?.type === "enabled";
|
||||||
|
if (Array.isArray(body.messages)) {
|
||||||
|
for (const msg of body.messages) {
|
||||||
|
if (msg.role !== ROLE.ASSISTANT || !Array.isArray(msg.content)) continue;
|
||||||
|
let hasToolUse = false;
|
||||||
|
let hasKeptThinking = false;
|
||||||
|
const kept = [];
|
||||||
|
for (const block of msg.content) {
|
||||||
|
if (block.type === CLAUDE_BLOCK.THINKING || block.type === CLAUDE_BLOCK.REDACTED_THINKING) {
|
||||||
|
if (isValidClaudeSignature(block.signature)) {
|
||||||
|
hasKeptThinking = true;
|
||||||
|
kept.push(block);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (block.type === CLAUDE_BLOCK.TOOL_USE) hasToolUse = true;
|
||||||
|
kept.push(block);
|
||||||
|
}
|
||||||
|
msg.content = kept;
|
||||||
|
if (thinkingEnabled && !hasKeptThinking && hasToolUse) {
|
||||||
|
msg.content.unshift(buildThinkingPlaceholder("claude"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user