fix(workers-ai-provider): preserve structured output schema name
Summary
- wrap AI SDK structured-output schemas in the OpenAI-compatible
json_schemaenvelope before sending them to Workers AI - preserve
Output.object({ name, description })on the request body, defaulting the schema name toresponsewhen not provided - add REST regression coverage for the request body sent by
workers-ai-provider
Fixes #559.
Validation
corepack pnpm --filter workers-ai-provider exec vitest --watch=false test/structured-output.test.tscorepack pnpm --filter workers-ai-provider type-checkcorepack pnpm --filter workers-ai-provider test:cicorepack pnpm exec oxfmt --check packages/workers-ai-provider/src/workersai-chat-language-model.ts packages/workers-ai-provider/test/structured-output.test.ts
🦋 Changeset detected
Latest commit: a406b61c544d582584016b5000ac942499b1f391
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
| Name | Type |
|---|---|
| workers-ai-provider | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
Thanks for this, @slegarraga — your diagnosis of #559 was correct, and the request-body regression test was a great instinct (we ended up adding similar wire-shape assertions).
We've resolved #559 a different way, so I'm closing this as superseded. Two pieces landed:
- Partner models (
openai/…) — #573 (gateway delegate, in 3.2.0). Third-party catalog slugs now route through AI Gateway and the real@ai-sdk/*provider, which builds theresponse_format.json_schema.nameenvelope itself (opt in withcreateWorkersAI({ binding, providers: [openai] })). So the native code path no longer needs to construct that envelope. - Native models (
@cf/…) — #576 (in 3.2.0). Here we intentionally did not wrap the schema in{ name, schema }: native Workers AI expects a bare JSON Schema underjson_schema, and wrapping it risks regressing native structured output (it'd be read as a schema with notype/properties). Instead we foldname→ the schema'stitleanddescription→description, preserving the guidance while keeping a valid bare schema.
That's the main reason we went this route over the envelope approach in this PR — applying the OpenAI envelope to @cf/... requests would have changed the native wire contract. Combined, the partner failure you hit is fixed by the routing and the native gap is fixed by #576.
Really appreciate you digging in and filing both the issue and the fix. 🙏