fix(provider): port upstream Bedrock tool-result image hoisting (anomalyco/opencode#50272)
Issue for this PR
Closes #1713
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
User-visible failure: on Amazon Bedrock, when a tool like read returns an image, the fork always left the image inside the tool result. Bedrock Converse only accepts tool-result images for Claude, Nova and Llama 4. Any other Bedrock model (e.g. openai.gpt-oss-*, Mistral Pixtral) fails the next turn with This model doesn't support the image field for user messages. The image stays in history, so every retry fails the same way.
Port of upstream anomalyco/opencode#50272 (fixes upstream #48069 / #49443). In MessageV2.toModelMessagesEffect, supportsMediaInToolResults now returns true for @ai-sdk/amazon-bedrock only when the model id contains anthropic., nova, llama4 or llama-4. Other Bedrock models fall through to the existing hoist path, which sends the media as a separate user message after the tool result (SYNTHETIC_ATTACHMENT_PROMPT). Claude, Nova and Llama 4 work exactly as before, including the existing PDF-in-tool-result behavior covered by preserves bedrock pdf tool-result media in tool output.
Difference from upstream: upstream had already moved this check to per-attachment and image-only. The fork still uses a per-model boolean, so I ported only the model-id gate. The change is wrapped in altimate_change start — upstream_fix: markers.
How did you verify your code works?
- New
bedrock tool-result imagestests intest/session/message-v2.test.ts: images stay in the tool result forus.anthropic.claude-sonnet-4-6,amazon.nova-pro-v1:0andus.meta.llama4-maverick-17b-instruct-v1:0, and are hoisted into a user message foropenai.gpt-oss-120b-1:0andmistral.pixtral-large-2502-v1:0. The hoist cases fail without the fix. bun test test/session test/providerinpackages/opencode: everything passes except 2 tests intool-result-bigint.test.ts/session.test.ts(scratch store), which also fail on cleanorigin/main.bun typecheck(turbo, 13/13) passes.bun run script/upstream/analyze.ts --markers --base origin/main --strictpasses. Sinceupstream/devis now on the v2 layout, I also re-ran it against a v1.17.9 mirror: 1 shared file checked, properly marked.
Cost side effects
None. No new model calls, queries or resources.
Screenshots / recordings
N/A, no UI change.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
- I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"
Tracked in #1478.
Summary by cubic
Fixes Bedrock tool-result images being rejected on models that don't support media in tool results.
Bedrock Converse only accepts tool-result media for Claude, Nova, and Llama 4. Images now stay in the tool result for those models and are hoisted into a synthetic user message for all other Bedrock models, so the next turn no longer fails with This model doesn't support the image field for user messages.