fix: prevent tool-use marker leakage in toolshim output (#8310)

Signed-off-by: Eugenio La Cava <eugeniolcv@gmail.com>
Signed-off-by: Michael Neale <michael.neale@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Michael Neale <michael.neale@gmail.com>
This commit is contained in:
Eugenio
2026-05-14 07:49:37 +02:00
committed by GitHub
parent 826cce0257
commit 7fc3537751
6 changed files with 1161 additions and 60 deletions
+11 -1
View File
@@ -94,14 +94,24 @@ export function getTextAndImageContent(message: Message): {
}
}
// Strip <think> tags from assistant text — the thinking is surfaced via getThinkingContent
// Strip assistant-only markup that shouldn't appear in rendered text
if (message.role === 'assistant') {
textContent = stripToolCallMarkers(textContent);
textContent = textContent.replace(/<think>[\s\S]*?<\/think>/gi, '');
}
return { textContent, imagePaths };
}
function stripToolCallMarkers(text: string): string {
// Remove all tool call XML markers and their content
return text
.replace(/<\|tool_calls_section_begin\|>[\s\S]*?<\|tool_calls_section_end\|>/g, '')
.replace(/<\|tool_call_begin\|>[\s\S]*?<\|tool_call_end\|>/g, '')
.replace(/<\|tool_call_argument_begin\|>[\s\S]*?<\|tool_call_argument_end\|>/g, '')
.trim();
}
export function getThinkingContent(message: Message): string | null {
const parts: string[] = [];