diff options
| author | Tom Ryder <[email protected]> | 2026-03-12 20:13:09 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-03-12 22:13:09 -0500 |
| commit | 4a2a046d79ab8a0f2c152b6af4fd637d33843c9b (patch) | |
| tree | b87344840b0055ec8dd2c83a702866b493810233 | |
| parent | 8f8c74cfb862b4fd92914f2137b64fefd544fe33 (diff) | |
| download | opencode-4a2a046d79ab8a0f2c152b6af4fd637d33843c9b.tar.gz opencode-4a2a046d79ab8a0f2c152b6af4fd637d33843c9b.zip | |
fix: filter empty content blocks for Bedrock provider (#14586)
| -rw-r--r-- | packages/opencode/src/provider/transform.ts | 2 | ||||
| -rw-r--r-- | packages/opencode/test/provider/transform.test.ts | 32 |
2 files changed, 33 insertions, 1 deletions
diff --git a/packages/opencode/src/provider/transform.ts b/packages/opencode/src/provider/transform.ts index 407c26878..05b9f031f 100644 --- a/packages/opencode/src/provider/transform.ts +++ b/packages/opencode/src/provider/transform.ts @@ -51,7 +51,7 @@ export namespace ProviderTransform { ): ModelMessage[] { // Anthropic rejects messages with empty content - filter out empty string messages // and remove empty text/reasoning parts from array content - if (model.api.npm === "@ai-sdk/anthropic") { + if (model.api.npm === "@ai-sdk/anthropic" || model.api.npm === "@ai-sdk/amazon-bedrock") { msgs = msgs .map((msg) => { if (typeof msg.content === "string") { diff --git a/packages/opencode/test/provider/transform.test.ts b/packages/opencode/test/provider/transform.test.ts index ecb3a7480..917d357ea 100644 --- a/packages/opencode/test/provider/transform.test.ts +++ b/packages/opencode/test/provider/transform.test.ts @@ -1096,6 +1096,38 @@ describe("ProviderTransform.message - anthropic empty content filtering", () => expect(result[0].content[1]).toEqual({ type: "text", text: "Result" }) }) + test("filters empty content for bedrock provider", () => { + const bedrockModel = { + ...anthropicModel, + id: "amazon-bedrock/anthropic.claude-opus-4-6", + providerID: "amazon-bedrock", + api: { + id: "anthropic.claude-opus-4-6", + url: "https://bedrock-runtime.us-east-1.amazonaws.com", + npm: "@ai-sdk/amazon-bedrock", + }, + } + + const msgs = [ + { role: "user", content: "Hello" }, + { role: "assistant", content: "" }, + { + role: "assistant", + content: [ + { type: "text", text: "" }, + { type: "text", text: "Answer" }, + ], + }, + ] as any[] + + const result = ProviderTransform.message(msgs, bedrockModel, {}) + + expect(result).toHaveLength(2) + expect(result[0].content).toBe("Hello") + expect(result[1].content).toHaveLength(1) + expect(result[1].content[0]).toEqual({ type: "text", text: "Answer" }) + }) + test("does not filter for non-anthropic providers", () => { const openaiModel = { ...anthropicModel, |
