fix(ai): preserve tuple item schemas in structured output conversion - #1257
fix(ai): preserve tuple item schemas in structured output conversion#1257AlemTuzlak wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe schema converter now preserves draft-07 tuple item schemas and records positional null-widening maps. Homogeneous arrays retain one shared map for all elements. Tests cover tuple preservation, optional tuple objects, and homogeneous-array null restoration. ChangesTuple Array Conversion
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This preserves all positional tuple schemas without changing homogeneous-array behavior or adding new runtime surfaces. No actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description follows the required template and includes the change summary, checklist, release impact, testing results, root cause, alternatives, linked issues, and rollback risk. It clearly states that pnpm test:pr and E2E tests were not run. Full details: Docstring CoverageExplanation Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
View your CI Pipeline Execution ↗ for commit 0a70023
☁️ Nx Cloud last updated this comment at |
@tanstack/ai
@tanstack/ai-acp
@tanstack/ai-angular
@tanstack/ai-anthropic
@tanstack/ai-bedrock
@tanstack/ai-byteplus
@tanstack/ai-claude-code
@tanstack/ai-client
@tanstack/ai-code-mode
@tanstack/ai-code-mode-snippets
@tanstack/ai-codex
@tanstack/ai-cohere
@tanstack/ai-devtools-core
@tanstack/ai-durable-stream
@tanstack/ai-elevenlabs
@tanstack/ai-event-client
@tanstack/ai-fal
@tanstack/ai-gemini
@tanstack/ai-grok
@tanstack/ai-grok-build
@tanstack/ai-groq
@tanstack/ai-isolate-cloudflare
@tanstack/ai-isolate-daytona
@tanstack/ai-isolate-node
@tanstack/ai-isolate-quickjs
@tanstack/ai-isolate-quickjs-bun
@tanstack/ai-llmgateway
@tanstack/ai-lovable
@tanstack/ai-mcp
@tanstack/ai-memory
@tanstack/ai-mistral
@tanstack/ai-octane
@tanstack/ai-ollama
@tanstack/ai-openai
@tanstack/ai-opencode
@tanstack/ai-openrouter
@tanstack/ai-perplexity
@tanstack/ai-persistence
@tanstack/ai-preact
@tanstack/ai-react
@tanstack/ai-react-ui
@tanstack/ai-sandbox
@tanstack/ai-sandbox-cloudflare
@tanstack/ai-sandbox-daytona
@tanstack/ai-sandbox-docker
@tanstack/ai-sandbox-local-process
@tanstack/ai-sandbox-sprites
@tanstack/ai-sandbox-upstash-box
@tanstack/ai-sandbox-vercel
@tanstack/ai-skills
@tanstack/ai-solid
@tanstack/ai-solid-ui
@tanstack/ai-svelte
@tanstack/ai-utils
@tanstack/ai-vercel-gateway
@tanstack/ai-vertex
@tanstack/ai-vue
@tanstack/ai-vue-ui
@tanstack/openai-base
@tanstack/preact-ai-devtools
@tanstack/react-ai-devtools
@tanstack/solid-ai-devtools
@tanstack/svelte-ai-devtools
commit: |
The converter kept only items[0] for draft-07 tuples, so later positions were dropped. Map every tuple position and keep a single widening map for homogeneous arrays so undoNullWidening still applies to every element.
1d5ef16 to
0a70023
Compare
convertSchemaForStructuredOutputkept onlyitems[0]for draft-07 tuples, so later positions were dropped. This PR maps every tuple position. Homogeneous arrays still use one widening map, soundoNullWideningapplies it to every element (jsve’s note on #1210).Changes
itemsarray, including tuples nested in object properties.itemsmap for homogeneous arrays. A list-shaped map would un-widen only index 0.items..changeset/ai-tuple-item-maps.mdfor@tanstack/ai.Follow-up to #1210, which fixed the same tuple drop in
@tanstack/openai-base.Checklist
pnpm run test:pr, or these tests do not apply to this pull request.docs/for this change, or this change is not user-facing.pnpm changeset), or this PR does not change a published package.Release Impact
Root cause
Issue. A structured-output schema with a bbox tuple (
items: [{ minimum: -180 }, …]) kept only the first position.Cause. Both array branches in
makeStructuredOutputCompatibleusedArray.isArray(items) ? items[0] : items.Fix. Map every tuple entry. Store a list of maps for tuples and one map for a homogeneous
itemsschema.Possible alternatives
@tanstack/ai.Testing
Commands run
pnpm --filter @tanstack/ai... build— passedpnpm --filter @tanstack/ai exec vitest run tests/tuple-array-null-widening.test.ts tests/chat-structured-output-null-normalization.test.ts— 12 passedpnpm --filter @tanstack/ai test:types— passedpnpm --filter @tanstack/ai test:oxlint— passed (existinganywarnings only)pnpm test:pr— not runManual test
main, pass{ type: 'object', properties: { bbox: { type: 'array', items: [{ type: 'number', minimum: -180 }, { type: 'number', minimum: -90 }] } }, required: ['bbox'] }toconvertSchemaForStructuredOutput.itemsbecomes the first number schema only.itemsstays a two-entry array.Gate 1 on
main:On this branch:
How this PR makes testing easy.
packages/ai/tests/tuple-array-null-widening.test.tscovers tuples and jsve’s 3-element homogeneous round trip.Linked issues
Related: #1210, #1208
Risk / rollback
Low. Tuple structured-output schemas keep every position. Homogeneous arrays keep the old single-map behavior. Revert the PR to undo.
Summary by CodeRabbit
Bug Fixes
Tests
Chores