Skip to content
This repository was archived by the owner on May 23, 2026. It is now read-only.

Commit f19d863

Browse files
authored
ignore: split up reasoning transforms (anomalyco#24574)
1 parent 025a639 commit f19d863

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

packages/opencode/src/provider/transform.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,28 @@ function normalizeMessages(
5252
): ModelMessage[] {
5353
// Anthropic rejects messages with empty content - filter out empty string messages
5454
// and remove empty text/reasoning parts from array content
55-
if (model.api.npm === "@ai-sdk/anthropic" || model.api.npm === "@ai-sdk/amazon-bedrock") {
55+
if (model.api.npm === "@ai-sdk/anthropic") {
56+
msgs = msgs
57+
.map((msg) => {
58+
if (typeof msg.content === "string") {
59+
if (msg.content === "") return undefined
60+
return msg
61+
}
62+
if (!Array.isArray(msg.content)) return msg
63+
const filtered = msg.content.filter((part) => {
64+
if (part.type === "text" || part.type === "reasoning") {
65+
return part.text !== ""
66+
}
67+
return true
68+
})
69+
if (filtered.length === 0) return undefined
70+
return { ...msg, content: filtered }
71+
})
72+
.filter((msg): msg is ModelMessage => msg !== undefined && msg.content !== "")
73+
}
74+
75+
// Bedrock specific transforms
76+
if (model.api.npm === "@ai-sdk/amazon-bedrock") {
5677
msgs = msgs
5778
.map((msg) => {
5879
if (typeof msg.content === "string") {

0 commit comments

Comments
 (0)