Repository navigation
feat(server-utils): normalize Vercel AI gen_ai.extract spans - #26831
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
size-limit report 📦Compared: d98ba31 (PR test merge using develop at 910d793) Against: 910d793 (develop) · base run #67961 ✅ Baseline matches: this diff contains only this PR's changes.
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 9d79707. Configure here.
Optional E2E testsSome optional checks were not successful. They do not block the merge. 2 not successful, 75 successful. See the run.
Successful checks
|
|
One or more gzipped bundles increased by more than 500 bytes. If this increase is intentional, add the Accept Bundlesize Increase label to this PR to rerun and accept the check. |
gen_ai.extract spans
| return undefined; | ||
| } | ||
| if (part.type === 'file') { | ||
| if (String(part.mediaType).startsWith('image/')) { |
There was a problem hiding this comment.
h: The AI SDK also takes the top-level media type alone mediaType: 'image', so this would fall through here (https://github.com/vercel/ai/blob/3dad57f204c7332178d28c3467c7311875b66a3e/packages/provider-utils/src/types/content-part.ts#L82-L94):
| if (String(part.mediaType).startsWith('image/')) { | |
| if (String(part.mediaType).split('/')[0] === 'image') { |
|
You're a nice mermaid |

What
Vercel AI
experimental_extractspans now record their input and output messages in the shape that Cloudflare Workers AI already records for Clairic. File data in the state is replaced with[Blob substitute].Why
The
gen_ai.extractschemas in getsentry/sentry-conventions#832 and getsentry/sentry-conventions#835 describe the Clairic request and response. Before this change, Vercel AI recorded the AI SDK's own shape, so the product could not read it.State mapping
flowchart LR S["AI SDK state"] --> K{"Shape"} K -->|"string"| T1["one text part"] K -->|"JSON object"| J1["one JSON part"] K -->|"array of parts"| P["each part in order"] T1 --> TXT J1 --> TXT P -->|"text part"| TXT["append text, remember its offset"] P -->|"JSON part"| JS["stringify value"] --> TXT P -->|"image file part"| IMG["images: [Blob substitute]"] P -->|"PDF file part"| DOC["documents: [Blob substitute]"] TXT --> ST["state: texts joined with a blank line"] A["AI SDK answer source"] --> SK{"source.type"} SK -->|"text: part, start, end"| SP["span: offset of part + start, offset of part + end<br/>source: input"] SK -->|"file, part is an image"| SI["source: image"] SK -->|"file, part is a PDF"| SN["no source"]Sentry traces
Node script that calls
experimental_extracton a mock Clairic model, with a state of two text parts and one image.Before,
@sentry/node@11.16.0records no extract span (released versions do not have the extract instrumentation yet):After, the extraction view shows the joined state with the answer spans highlighted: