fix(opencode): fold schema items into gemini union branches - #43495
fix(opencode): fold schema items into gemini union branches#43495Role1776 wants to merge 1 commit into
Conversation
The workaround direction is right — fixing the schema before @ai-sdk/google's OpenAPI conversion instead of patching generated output — and correctly scoped to google/google-vertex only. Some concerns:
No blocking issues found. |
cd39190 to
f6a0c55
Compare
Issue for this PR
Closes #43494
Type of change
What does this PR do?
When a tool input is declared as a nullable array (
type: ["null", "array"]),@ai-sdk/google'sconvertJSONSchemaToOpenAPISchemaemitsanyOf: [{ type: "array" }]but leaves a dangling siblingitemsat the parent level. Gemini rejects the resulting function declaration, so any tool with a nullable-array input fails against@ai-sdk/google/@ai-sdk/google-vertex.This PR adds a
foldArrayItemshelper inpackages/opencode/src/session/llm/request.tsthat recursively folds the siblingitemsinto the array-typed branches of any union (anyOf/oneOf/allOf) — and rewrites the parenttype: ["null", "array"]form into ananyOfof an array branch carryingitemsplus anullbranch. It mutates the plain schema in place so the surroundingjsonSchema()wrapper (whosejsonSchemagetter returns this same reference) keeps working, and only runs for models whose npm is@ai-sdk/googleor@ai-sdk/google-vertex.How did you verify your code works?
Verified locally that a tool whose input schema is
type: ["null", "array"]now produces a Gemini function declaration withitemsnested inside the array branch, and that the schema error no longer occurs for Google/Vertex models.Screenshots / recordings
N/A (not a UI change)
Checklist