Skip to content

fix(opencode): normalize cloudflare-workers-ai mixed message content types - #36850

Open
ulises-jeremias wants to merge 3 commits into
anomalyco:devfrom
ulises-jeremias:fix/30381-cloudflare-workers-ai-message-content
Open

fix(opencode): normalize cloudflare-workers-ai mixed message content types#36850
ulises-jeremias wants to merge 3 commits into
anomalyco:devfrom
ulises-jeremias:fix/30381-cloudflare-workers-ai-message-content

Conversation

@ulises-jeremias

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #30381

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Cloudflare Workers AI rejects requests when message content types 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-ai that 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 path
  • bun typecheck — clean, no errors

Screenshots / recordings

N/A (no UI changes)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AiError: Bad input when using Cloudflare Workers AI — message content format mismatch

1 participant