Repository navigation
fix(ai-sdk): log AI SDK v7 inline file data as attachments - #2751
Closed
Paulo Martins (pmartinsdev) wants to merge 1 commit into
Closed
Paulo Martins (pmartinsdev) wants to merge 1 commit into
Paulo Martins (pmartinsdev) wants to merge 1 commit into
Conversation
Member
|
hey Paulo Martins (@pmartinsdev) thanks for the PR! I opened #2752 on top of it to add some more tests. Gonna close this one in favor of that. |
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.
Fixes #2750.
Context
With AI SDK 7, file parts reach the model spans as
{ type: "file", mediaType, data: { type: "data", data: Uint8Array } }(SharedV4FileData).processContentPartpassedpart.data, the wrapper, toconvertDataToAttachment, which only handles a string,Uint8Array,BufferorBlob, so no attachment was made anddeepCopyEventcopied the raw bytes as an object with one key per byte. 1 MB of image becomes about 120 MB of heap on every model call.We call Claude through Vertex, which takes no image URLs, so the AI SDK downloads every image in the conversation and each model call carries all of them. A 38-image call (24.5 MB of images) peaked at 2,651 MB of heap with
wrapAISDKand at 117 MB without it, and our 4 GB serverless instances were killed for memory.Description
processContentPartnow unwraps{ type: "data", data }before callingconvertDataToAttachment, so the bytes (or a base64 string) become an attachment the same way a plainUint8Arrayalready does. The other tagged variants (url,reference,text) are left as they were, and aBlobis never unwrapped since the check requires adatakey.Testing
ai-sdk-plugin.test.tssends a taggedUint8Arrayfile part throughprocessAISDKCallInputand checks that it is logged as anAttachment. It fails without the fix and passes with it.vitest run src/instrumentation/plugins/ai-sdk-plugin.test.ts(134 passed),vitest run src/wrappers/ai-sdk(20 passed),pnpm run check:typingsand prettier are clean. Changeset included (patch).pnpm patch, and the same 38-image call peaked at 130 MB of heap with tracing on.