Skip to content

Commit 4fc0fa0

Browse files
committed
refactor: optimize content conversion logic in convertToolResultContent function
1 parent 87899a1 commit 4fc0fa0

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/routes/messages/responses-translation.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -645,17 +645,23 @@ const convertToolResultContent = (
645645
}
646646

647647
if (Array.isArray(content)) {
648-
if (content.length > 0 && content[0].type === "text") {
649-
return (content as Array<AnthropicTextBlock>).map((block) =>
650-
createTextContent(block.text),
651-
)
652-
}
653-
654-
if (content.length > 0 && content[0].type === "image") {
655-
return (content as Array<AnthropicImageBlock>).map((block) =>
656-
createImageContent(block),
657-
)
648+
const result: Array<ResponseInputContent> = []
649+
for (const block of content) {
650+
switch (block.type) {
651+
case "text": {
652+
result.push(createTextContent(block.text))
653+
break
654+
}
655+
case "image": {
656+
result.push(createImageContent(block))
657+
break
658+
}
659+
default: {
660+
break
661+
}
662+
}
658663
}
664+
return result
659665
}
660666

661667
return ""

0 commit comments

Comments
 (0)