Skip to content

Commit 64b7f9b

Browse files
committed
fix: add final empty-content guard in message() pipeline
Adds a provider-agnostic safety net at the end of the message() function that filters out messages with empty string content or empty array content before they reach any provider API. Previously only Anthropic and Bedrock had local guards; providers like DeepSeek would receive messages with empty content and fail with "messages.N: all messages must have non-empty content". Fixes anomalyco#23260
1 parent bd149f0 commit 64b7f9b

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎packages/opencode/src/provider/transform.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,29 @@ export function message(msgs: ModelMessage[], model: Provider.Model, options: Re
473473
})
474474
}
475475

476+
// Final safety net: filter out messages with empty content from any provider.
477+
// Individual transforms above each have their own (or no) guard; this single
478+
// pass catches every current and future case that could otherwise cause
479+
// provider API errors — including DeepSeek (messages.N: all messages must
480+
// have non-empty content), Bedrock (ValidationException), and others.
481+
msgs = msgs
482+
.map((msg) => {
483+
if (typeof msg.content === "string") {
484+
if (msg.content === "") return undefined
485+
return msg
486+
}
487+
if (!Array.isArray(msg.content)) return msg
488+
const filtered = msg.content.filter((part) => {
489+
if (part.type === "text") return part.text !== ""
490+
if (part.type === "reasoning") return part.text.trim().length > 0
491+
return true
492+
})
493+
if (filtered.length === 0) return undefined
494+
return { ...msg, content: filtered }
495+
})
496+
.filter((msg): msg is ModelMessage => msg !== undefined)
497+
498+
476499
return msgs
477500
}
478501

0 commit comments

Comments
 (0)