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
|
Addressed the review points in f6a0c55: foldArrayItems now works on a structuredClone of the schema instead of mutating in place, so schemas shared across providers stay untouched. Non array members of a multi-type union are kept instead of being dropped. Added test/session/llm-fold-array-items.test.ts, 10 cases covering nullable array unions, nested schemas, non-schema objects and idempotency. I also updated the PR description above, it still described the old in-place version. @kitlangton you are assigned on #43494, could you take a look when you have a moment? |
|
With this applied, the Kaggle MCP tools still fail on gemini-3.8-flash: 22 |
Nullable objects (`type: ["object", "null"]`) hit the same @ai-sdk/google conversion gap as nullable arrays: `properties`/`required` stay on the anyOf parent and Gemini rejects the request with `properties: only allowed for OBJECT type`. Generalize the fold to move every type-specific keyword (items/minItems/maxItems, properties/required/additionalProperties) into its own branch, and leave nodes with a single type alone.
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, and Gemini rejects the function declaration.This PR adds a
foldArrayItemshelper inpackages/opencode/src/session/llm/request.tsthat recursively folds the siblingitemsinto the array-typed branches of ananyOforoneOfunion.allOfis deliberately left alone, since folding into every branch there would change the intersection semantics. It works on astructuredCloneof the schema rather than mutating it in place, so tool schemas shared across providers are not affected by a Gemini specific request. Non-array members of a multi-type union are preserved. It only runs for models whose npm is@ai-sdk/googleor@ai-sdk/google-vertex.How did you verify your code works?
A tool whose input schema is
type: ["null", "array"]now produces a Gemini function declaration withitemsnested inside the array branch.Added
test/session/llm-fold-array-items.test.ts, 10 cases covering nullable array unions, multi-type unions, nested schemas, non-schema objects and idempotency.Screenshots / recordings
Not a UI change.
Checklist