fix(core): normalize JSON Schema nullable type arrays in toGeminiSchema

MV
1d ago
+344-5

Fixes #44

Summary

toGeminiSchema already normalizes anyOf / oneOf null unions into { type, nullable: true }, but JSON Schema nullable type arrays (type: ["string", "null"]) reached typeof inputSchema.type === 'string' as an array and had their type dropped. Tools that declare nullable arguments via type arrays (such as OpenCode 2.x tools with type: ["string", "null"]) then failed on Gemini models with HTTP 400.

Changes

  • Add normalizeNullableTypeArray in packages/core/src/transform/gemini.ts after mergeSchemaAllOf to normalize:
    • 2-element nullable type arrays (["string", "null"], ["null", "integer"], etc., case-insensitive and deduplicated) to { type: "<type>", nullable: true }
    • 1-element arrays (["string"] -> type: "string", ["null"] -> type: "null")
    • Nested object properties, array items, and allOf-merged schemas
  • Leave genuine multi-type arrays (["string", "number"]) and unknown type entries untouched so existing provider validation handles them without misclassifying schema errors.
  • Add unit coverage in packages/core/src/transform/gemini.test.ts.

Verification

  • bun test --isolate packages/core/src/transform/gemini.test.ts (166 pass, 0 fail)
  • bun run --cwd packages/core typecheck (0 errors)
  • bun x @biomejs/biome check packages/core/src/transform/gemini.ts packages/core/src/transform/gemini.test.ts
  • Live tool-call round-trips with explicit null arguments on antigravity-gemini-3.8-flash and antigravity-gemini-4-argon.