fix(opencode): normalize cloudflare-workers-ai mixed message content types - #36850
Open
ulises-jeremias wants to merge 3 commits into
Open
Conversation
…types Cloudflare Workers AI rejects requests when message content types are inconsistent across messages — some with string content and others with array content. This happens because the AI SDK's openai-compatible provider can emit both shapes depending on whether the message has a single text part or multiple parts. The fix detects text-only array content for cloudflare-workers-ai and normalizes it to a flat string, joining multiple text parts with newlines. Non-text content (tool calls, images, etc.) and tool messages are preserved as-is. Closes anomalyco#30381
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #30381
Type of change
What does this PR do?
Cloudflare Workers AI rejects requests when message
contenttypes are inconsistent across messages — some have string content while others have array content (e.g.[{type: "text", text: "..."}]). This happens because the AI SDK's openai-compatible provider can emit both shapes depending on whether the message has a single text part or multiple parts.This PR adds a normalization step for
cloudflare-workers-aithat converts text-only array content to a flat string, joining multiple text parts with newlines. Tool messages, tool calls, and non-text content (images, files) are preserved as-is.How did you verify your code works?
bun test test/provider/transform.test.ts— 357 tests pass including 15 new tests covering the normalization pathbun typecheck— clean, no errorsScreenshots / recordings
N/A (no UI changes)
Checklist