fix(opencode): fold schema items into gemini union branches - #43495
Open
Role1776 wants to merge 1 commit into
Open
fix(opencode): fold schema items into gemini union branches#43495Role1776 wants to merge 1 commit into
Role1776 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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