Skip to content

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

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

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
@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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