Migrate to AI SDK v7 (@ai-sdk/google ≥4.0.70) so Gemini receives the full JSON Schema (fixes #139) #141
Description
Context
#139 is reproduced on 0.4.7: @ai-sdk/google 2.0.54's convertJSONSchemaToOpenAPISchema strips additionalProperties (and pattern, min/max, $ref), so Gemini returns {} for map-typed fields. All 5 Gemini PR Explanation runs in aictrl prod on 2026-10-10 lost every diagram element.
The upstream fix is @ai-sdk/google 4.0.70 (vercel/ai#20757, merged 2026-09-14): it sends parametersJsonSchema for tools and responseJsonSchema for outputs, and removes the lossy converter. It ships only on the AI SDK v7 line (provider 4.x, provider-utils 5.x, google-vertex 5.x). The v6 line (google 3.0.131) still converts, and there is no v5/v6 backport. Upstream OpenCode dev is on ai 6.0.168 / google 3.0.73 and has the same bug.
Founder decision (2026-10-10): fix #139 by migrating the SDK, not with a local patch or a contract workaround.
Goal
Move the fork from ai 5.0.124 / @ai-sdk/google 2.0.54 / @ai-sdk/google-vertex 3.0.106 to AI SDK v7 (google ≥ 4.0.70, google-vertex 5.x) across every provider package we use, with no behaviour regressions.
Acceptance Criteria
- All
ai/@ai-sdk/*/ provider-utils packages on the v7 line; lockfile clean; typecheck and the full suite pass. - StructuredOutput drops additionalProperties (map) fields on Gemini; Ajv accepts the lossy {} #139's reproduction (comment on StructuredOutput drops additionalProperties (map) fields on Gemini; Ajv accepts the lossy {} #139) passes on Gemini 3.8 Flash:
out.jsonhas all 6 keys, 5/5 runs. - Schema mode still works on GLM (z.ai) and Anthropic/OpenAI providers: rerun the feat(run): enforce output schemas with bounded corrective retries (aictrl#5958) #129 live checks.
- Gemini native validation reviewed: whether to use
functionCallingConfigVALIDATED now that the full schema is sent. - Release notes list the breaking SDK changes handled.
Notes
- Scope it first: count
ai/@ai-sdkusages and walk the v5→v6→v7 migration guides (streamText/tool APIs, message parts, provider options, usage/finishReason shapes). - StructuredOutput: accept a validated result file path instead of re-emitted JSON #140 (publish the validated file instead of re-emitted args) is independent and still worth doing: no SDK version changes the re-emission design.
Activity
byapparov commentedon Oct 10, 2026
Scoping result (2026-10-10). Recommendation: one PR jumping straight to v7, after #140. Estimate 4–5 days.
"unknown"is removed; it affects termination, retry and the processor);messagesare rejected at runtime;strictJsonSchema, Azure/xAI Responses API).Probe on v7: #139 is only partly fixed. The full schema now reaches Gemini (
parametersJsonSchemawithadditionalProperties), andelementscomes back with 6 entries instead of{}. But Gemini rewrites the map keys in its function-call response:queued->running→queued__running,1→_1orfirst_step,TASKS.org_id→TASKS_org_id. Ajv accepts the result and the run exits 0, so it's silently corrupted. The array-shaped schema and GLM both came back intact. So map-keyed results aren't safe through Gemini function calling even with the full schema; #140's path form avoids the issue entirely for file-based results.byapparov commentedon Oct 11, 2026
Closed for now (founder, 2026-10-11): no current driver. #142 (released in 0.4.8) made schema-mode StructuredOutput take only
{path}, so the big result schema no longer goes through @ai-sdk/google's lossy converter, and the prod symptom (Gemini PR Explanations with empty diagram elements) is fixed and verified. Upstream anomalyco/opencode closed its own v7 migration PR (#52064) unmerged, so there's no upstream to follow yet either. The scoping notes above stand (4–5 days, risk list). Reopen when a concrete problem needs AI SDK v7, e.g. an MCP tool with a map-typed schema misbehaving on Gemini, or a provider feature only v7 has. A lighter alternative if only Gemini is affected: a native Gemini path that sendsparametersJsonSchema(as NousResearch/hermes-agent does in agent/gemini_schema.py).