diff --git a/src/api/transform/__tests__/gemini-format.spec.ts b/src/api/transform/__tests__/gemini-format.spec.ts index e30b01bd736..14ab6f8d8f0 100644 --- a/src/api/transform/__tests__/gemini-format.spec.ts +++ b/src/api/transform/__tests__/gemini-format.spec.ts @@ -420,7 +420,7 @@ describe("convertAnthropicMessageToGemini", () => { ) }) - it("should throw an error for unsupported content block type", () => { + it("should skip unsupported content block types", () => { const anthropicMessage: Anthropic.Messages.MessageParam = { role: "user", content: [ @@ -428,11 +428,39 @@ describe("convertAnthropicMessageToGemini", () => { type: "unknown_type", // Unsupported type data: "some data", } as any, + { type: "text", text: "Valid content" }, ], } - expect(() => convertAnthropicMessageToGemini(anthropicMessage)).toThrow( - "Unsupported content block type: unknown_type", - ) + const result = convertAnthropicMessageToGemini(anthropicMessage) + + expect(result).toEqual([ + { + role: "user", + parts: [{ text: "Valid content" }], + }, + ]) + }) + + it("should skip reasoning content blocks", () => { + const anthropicMessage: Anthropic.Messages.MessageParam = { + role: "assistant", + content: [ + { + type: "reasoning" as any, + text: "Let me think about this...", + }, + { type: "text", text: "Here's my answer" }, + ], + } + + const result = convertAnthropicMessageToGemini(anthropicMessage) + + expect(result).toEqual([ + { + role: "model", + parts: [{ text: "Here's my answer" }], + }, + ]) }) }) diff --git a/src/api/transform/gemini-format.ts b/src/api/transform/gemini-format.ts index ffb8b8f789c..f9d855dda93 100644 --- a/src/api/transform/gemini-format.ts +++ b/src/api/transform/gemini-format.ts @@ -6,7 +6,12 @@ type ThoughtSignatureContentBlock = { thoughtSignature?: string } -type ExtendedContentBlockParam = Anthropic.ContentBlockParam | ThoughtSignatureContentBlock +type ReasoningContentBlock = { + type: "reasoning" + text: string +} + +type ExtendedContentBlockParam = Anthropic.ContentBlockParam | ThoughtSignatureContentBlock | ReasoningContentBlock type ExtendedAnthropicContent = string | ExtendedContentBlockParam[] function isThoughtSignatureContentBlock(block: ExtendedContentBlockParam): block is ThoughtSignatureContentBlock { @@ -124,8 +129,10 @@ export function convertAnthropicContentToGemini( ] } default: - // Currently unsupported: "thinking" | "redacted_thinking" | "document" - throw new Error(`Unsupported content block type: ${block.type}`) + // Skip unsupported content block types (e.g., "reasoning", "thinking", "redacted_thinking", "document") + // These are typically metadata from other providers that don't need to be sent to Gemini + console.warn(`Skipping unsupported content block type: ${block.type}`) + return [] } }) }