Repository navigation
fix(provider): catch an empty image attachment on the file part shape - #46860
devYRPauli wants to merge 1 commit into
Conversation
unsupportedParts checked part.image for empty base64 data. The prompt pipeline pushes an attachment as a file part and convertToModelMessages keeps it as one, so the guard never ran on a real attachment and the empty image reached the provider. Read the data from whichever shape the part carries, and require an image media type so an empty PDF does not get the image error text. The two existing tests build the image shape by hand, which is why they passed. The new tests drive convertToModelMessages instead. Closes anomalyco#46859
|
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:
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. |
|
This remains on dev at 907b3bc. AI SDK 6.0.168 converts an empty image attachment to a file part, and the current unsupportedParts function leaves it unchanged. Applying this fix to that function produces the intended error text and preserves a nonempty attachment. Could you reopen this PR? |
Issue for this PR
Closes #46859
Type of change
What does this PR do?
unsupportedPartsreplaces an empty image with error text so the request does not reach the provider. The check readpart.image, which only exists on animagepart.The prompt pipeline does not build that shape.
session/message-v2.ts:220pushes an attachment as{ type: "file", url, mediaType, filename }, andconvertToModelMessageskeeps it afilepart with the data URL inpart.data. So the guard never ran on a real attachment, and the empty image went to the provider, which failed the request with its own error.The two tests that cover the guard build the
imageshape by hand, so they passed while the production path was broken.This reads the data from whichever shape the part carries. It also requires an
image/media type, so an empty PDF no longer gets a message about an image. Moving themimeline above the check is what makes that media-type test available; nothing else aboutmimechanged.How did you verify your code works?
bun test test/provider/transform.test.tsfrompackages/opencode: 557 pass, 0 fail. The wholetest/provider/directory: 706 pass, 0 fail.bun run typecheck: 30/30 tasks pass.I reverted the source change and kept the new tests. Exactly one test fails, and it is the one that drives the real path:
I also measured the part shape directly against the pinned
[email protected], which is the evidence in the issue:convertToModelMessagesreturnstype: "file", nevertype: "image".The second new test sends a valid 1x1 PNG through the same path and asserts the part is untouched, so a regex that matched too much would fail it.
prettier --checkandoxlintare clean on both files (0 errors).Screenshots / recordings
Not a UI change.
Checklist