Skip to content

feat(ai-sdk): serialize tool outputs like OpenAPI responses and send files to the model - #2334

Merged
dinwwwh merged 1 commit into
mainfrom
claude/ai-sdk-tool-converters-mwqxlc
Oct 24, 2026
Merged

dinwwwh merged 1 commit into
mainfrom
claude/ai-sdk-tool-converters-mwqxlc

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Oct 24, 2026

Copy link
Copy Markdown
Member

Summary

AI SDK tools get a default toModelOutput, modeled on how the MCP integration maps outputs:

  • Outputs are serialized like OpenAPI responses (OpenAPIJsonSerializer). Date, BigInt, Set, Map and similar types now reach the model as JSON. Before, the AI SDK's own JSON round trip turned Set/Map into {}, and a BigInt made it throw.
  • Blob/File outputs, nested or not, are sent as file content.
    • A top-level file becomes a single file part with its MIME type and file name.
    • Nested files are sent as the JSON text plus one file part each, named by path (for example files/0/q3.pdf).
    • File data is base64-encoded once, so providers don't re-encode the bytes on every step.
  • A new serializer option on implementToolFactory / createToolFactory lets you share custom types with an OpenAPI handler, the same as McpRegistrar's option.
  • You can still take over: toModelOutput set in tool options or aiSdkTool meta overrides the default.

@orpc/openapi becomes a runtime dependency of @orpc/ai-sdk, for the serializer, as it already is for @orpc/mcp.

The TODO about adding a JSON Schema converter option is removed: tools keep leaving JSON Schema conversion to the AI SDK.

Notes

  • toModelOutput only shapes what the model receives. The AI SDK still streams and stores the raw tool output, so a BigInt output can still fail UI streaming, and history rebuilt from saved UI messages loses non-JSON values and files.
  • A ReadableStream output still reaches the model as {}, as with the AI SDK's own default.

Testing

  • New tests cover serialization, top-level and nested files, the serializer option, override precedence, and an end-to-end generateText run showing the file part reach the tool message.
  • pnpm vitest run packages/ai-sdk packages/openapi tests, the root tsc and the package type check, eslint, sherif and pnpm docs:validate pass.

Generated by Claude Code

…files to the model

A default `toModelOutput` serializes outputs like OpenAPI responses, so
types such as `Date`, `BigInt`, and `Set` reach the model as JSON, and
sends `Blob`/`File` outputs, nested or not, as file content named by
their path, such as `report/q3.pdf`. The new `serializer` option shares
custom types with an OpenAPI handler, and `toModelOutput` in tool
options or `aiSdkTool` meta still takes over.

The TODO about a JSON Schema `converter` option is removed: tools keep
leaving JSON Schema conversion to the AI SDK.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BsvL9tattvbASxVptTw9kS
@pullfrog

pullfrog Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

This run was cancelled before it finished.

Pullfrog  | View workflow run | via Pullfrog

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
orpc e60d3b2 Commit Preview URL

Branch Preview URL
Oct 24 2026, 02:14 PM

@pkg-pr-new

pkg-pr-new Bot commented Oct 24, 2026

Copy link
Copy Markdown
More templates

@orpc/ai-sdk

npm i https://pkg.pr.new/@orpc/ai-sdk@2334

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@2334

@orpc/bun

npm i https://pkg.pr.new/@orpc/bun@2334

@orpc/client

npm i https://pkg.pr.new/@orpc/client@2334

@orpc/cloudflare

npm i https://pkg.pr.new/@orpc/cloudflare@2334

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@2334

@orpc/effect

npm i https://pkg.pr.new/@orpc/effect@2334

@orpc/evlog

npm i https://pkg.pr.new/@orpc/evlog@2334

@orpc/hibernation

npm i https://pkg.pr.new/@orpc/hibernation@2334

@orpc/json-schema

npm i https://pkg.pr.new/@orpc/json-schema@2334

@orpc/experimental-lock

npm i https://pkg.pr.new/@orpc/experimental-lock@2334

@orpc/mcp

npm i https://pkg.pr.new/@orpc/mcp@2334

@orpc/msw

npm i https://pkg.pr.new/@orpc/msw@2334

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@2334

@orpc/next

npm i https://pkg.pr.new/@orpc/next@2334

@orpc/node

npm i https://pkg.pr.new/@orpc/node@2334

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@2334

@orpc/opentelemetry

npm i https://pkg.pr.new/@orpc/opentelemetry@2334

@orpc/pinia-colada

npm i https://pkg.pr.new/@orpc/pinia-colada@2334

@orpc/pino

npm i https://pkg.pr.new/@orpc/pino@2334

@orpc/publisher

npm i https://pkg.pr.new/@orpc/publisher@2334

@orpc/ratelimit

npm i https://pkg.pr.new/@orpc/ratelimit@2334

@orpc/server

npm i https://pkg.pr.new/@orpc/server@2334

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@2334

@orpc/swr

npm i https://pkg.pr.new/@orpc/swr@2334

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@2334

@orpc/trpc

npm i https://pkg.pr.new/@orpc/trpc@2334

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@2334

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@2334

commit: e60d3b2

@codspeed

codspeed Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 5 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 28 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing claude/ai-sdk-tool-converters-mwqxlc (e60d3b2) with main (4c76597)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@dinwwwh
dinwwwh merged commit 9321935 into main Oct 24, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants