fix(agents): guard promoteThinkingTagsToBlocks against malformed content entries (#35143)

Merged via squash.

Prepared head SHA: 3971122f5f
Co-authored-by: Sid-Qin <201593046+Sid-Qin@users.noreply.github.com>
Co-authored-by: shakkernerd <165377636+shakkernerd@users.noreply.github.com>
Reviewed-by: @shakkernerd
This commit is contained in:
Sid
2026-03-05 13:37:33 +08:00
committed by GitHub
parent ce0c13191f
commit d9b69a6145
3 changed files with 42 additions and 1 deletions

View File

@@ -333,7 +333,9 @@ export function promoteThinkingTagsToBlocks(message: AssistantMessage): void {
if (!Array.isArray(message.content)) {
return;
}
const hasThinkingBlock = message.content.some((block) => block.type === "thinking");
const hasThinkingBlock = message.content.some(
(block) => block && typeof block === "object" && block.type === "thinking",
);
if (hasThinkingBlock) {
return;
}
@@ -342,6 +344,10 @@ export function promoteThinkingTagsToBlocks(message: AssistantMessage): void {
let changed = false;
for (const block of message.content) {
if (!block || typeof block !== "object" || !("type" in block)) {
next.push(block);
continue;
}
if (block.type !== "text") {
next.push(block);
continue;