Skip to content

fix(opencode): fold schema items into gemini union branches - #43495

Open
Role1776 wants to merge 1 commit into
anomalyco:devfrom
Role1776:fix/gemini-tool-schema-anyof-items
Open

fix(opencode): fold schema items into gemini union branches#43495
Role1776 wants to merge 1 commit into
anomalyco:devfrom
Role1776:fix/gemini-tool-schema-anyof-items

Conversation

@Role1776

Copy link
Copy Markdown

Issue for this PR

Closes #43494

Type of change

  • Bug fix

What does this PR do?

When a tool input is declared as a nullable array (type: ["null", "array"]), @ai-sdk/google's convertJSONSchemaToOpenAPISchema emits anyOf: [{ type: "array" }] but leaves a dangling sibling items at 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 foldArrayItems helper in packages/opencode/src/session/llm/request.ts that recursively folds the sibling items into the array-typed branches of any union (anyOf/oneOf/allOf) — and rewrites the parent type: ["null", "array"] form into an anyOf of an array branch carrying items plus a null branch. It mutates the plain schema in place so the surrounding jsonSchema() wrapper (whose jsonSchema getter returns this same reference) keeps working, and only runs for models whose npm is @ai-sdk/google or @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 with items nested 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

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gemini tool schema fails when a tool input is a nullable array

1 participant