fix(ai): use parametersJsonSchema for Google tool declarations, revert Antigravity opus model

- Use parametersJsonSchema instead of parameters for Gemini tool declarations
  to support full JSON Schema (anyOf, oneOf, const, etc.)
- Keep legacy parameters field for Claude models on Cloud Code Assist, where
  the API translates parameters into Anthropic's input_schema
- Revert claude-opus-4-6-thinking back to claude-opus-4-5-thinking (model
  doesn't exist on the Antigravity endpoint)

fixes #1398
This commit is contained in:
Mario Zechner 2026-02-08 15:53:09 +01:00
parent 82caf064e0
commit 1caadb2e2a
6 changed files with 26 additions and 12 deletions

View file

@ -2,6 +2,11 @@
## [Unreleased] ## [Unreleased]
### Fixed
- Use `parametersJsonSchema` for Google provider tool declarations to support full JSON Schema (anyOf, oneOf, const, etc.) ([#1398](https://github.com/badlogic/pi-mono/issues/1398) by [@jarib](https://github.com/jarib))
- Reverted incorrect Antigravity model change: `claude-opus-4-6-thinking` back to `claude-opus-4-5-thinking` (model doesn't exist on Antigravity endpoint)
## [0.52.8] - 2026-02-07 ## [0.52.8] - 2026-02-07
### Added ### Added

View file

@ -1021,8 +1021,8 @@ async function generateModels() {
maxTokens: 64000, maxTokens: 64000,
}, },
{ {
id: "claude-opus-4-6-thinking", id: "claude-opus-4-5-thinking",
name: "Claude Opus 4.6 Thinking (Antigravity)", name: "Claude Opus 4.5 Thinking (Antigravity)",
api: "google-gemini-cli", api: "google-gemini-cli",
provider: "google-antigravity", provider: "google-antigravity",
baseUrl: ANTIGRAVITY_ENDPOINT, baseUrl: ANTIGRAVITY_ENDPOINT,

View file

@ -2971,9 +2971,9 @@ export const MODELS = {
} satisfies Model<"google-generative-ai">, } satisfies Model<"google-generative-ai">,
}, },
"google-antigravity": { "google-antigravity": {
"claude-opus-4-6-thinking": { "claude-opus-4-5-thinking": {
id: "claude-opus-4-6-thinking", id: "claude-opus-4-5-thinking",
name: "Claude Opus 4.6 Thinking (Antigravity)", name: "Claude Opus 4.5 Thinking (Antigravity)",
api: "google-gemini-cli", api: "google-gemini-cli",
provider: "google-antigravity", provider: "google-antigravity",
baseUrl: "https://daily-cloudcode-pa.sandbox.googleapis.com", baseUrl: "https://daily-cloudcode-pa.sandbox.googleapis.com",

View file

@ -953,7 +953,10 @@ export function buildRequest(
} }
if (context.tools && context.tools.length > 0) { if (context.tools && context.tools.length > 0) {
request.tools = convertTools(context.tools); // Claude models on Cloud Code Assist need the legacy `parameters` field;
// the API translates it into Anthropic's `input_schema`.
const useParameters = model.id.startsWith("claude-");
request.tools = convertTools(context.tools, useParameters);
if (options.toolChoice) { if (options.toolChoice) {
request.toolConfig = { request.toolConfig = {
functionCallingConfig: { functionCallingConfig: {

View file

@ -2,7 +2,7 @@
* Shared utilities for Google Generative AI and Google Cloud Code Assist providers. * Shared utilities for Google Generative AI and Google Cloud Code Assist providers.
*/ */
import { type Content, FinishReason, FunctionCallingConfigMode, type Part, type Schema } from "@google/genai"; import { type Content, FinishReason, FunctionCallingConfigMode, type Part } from "@google/genai";
import type { Context, ImageContent, Model, StopReason, TextContent, Tool } from "../types.js"; import type { Context, ImageContent, Model, StopReason, TextContent, Tool } from "../types.js";
import { sanitizeSurrogates } from "../utils/sanitize-unicode.js"; import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
import { transformMessages } from "./transform-messages.js"; import { transformMessages } from "./transform-messages.js";
@ -232,17 +232,23 @@ export function convertMessages<T extends GoogleApiType>(model: Model<T>, contex
/** /**
* Convert tools to Gemini function declarations format. * Convert tools to Gemini function declarations format.
*
* By default uses `parametersJsonSchema` which supports full JSON Schema (including
* anyOf, oneOf, const, etc.). Set `useParameters` to true to use the legacy `parameters`
* field instead (OpenAPI 3.03 Schema). This is needed for Cloud Code Assist with Claude
* models, where the API translates `parameters` into Anthropic's `input_schema`.
*/ */
export function convertTools( export function convertTools(
tools: Tool[], tools: Tool[],
): { functionDeclarations: { name: string; description?: string; parameters: Schema }[] }[] | undefined { useParameters = false,
): { functionDeclarations: Record<string, unknown>[] }[] | undefined {
if (tools.length === 0) return undefined; if (tools.length === 0) return undefined;
return [ return [
{ {
functionDeclarations: tools.map((tool) => ({ functionDeclarations: tools.map((tool) => ({
name: tool.name, name: tool.name,
description: tool.description, description: tool.description,
parameters: tool.parameters as Schema, ...(useParameters ? { parameters: tool.parameters } : { parametersJsonSchema: tool.parameters }),
})), })),
}, },
]; ];

View file

@ -57,7 +57,7 @@ describe.skipIf(!HAS_ANTIGRAVITY_AUTH)("Compaction with thinking models (Antigra
}); });
function createSession( function createSession(
modelId: "claude-opus-4-6-thinking" | "claude-sonnet-4-5", modelId: "claude-opus-4-5-thinking" | "claude-sonnet-4-5",
thinkingLevel: ThinkingLevel = "high", thinkingLevel: ThinkingLevel = "high",
) { ) {
const model = getModel("google-antigravity", modelId); const model = getModel("google-antigravity", modelId);
@ -97,8 +97,8 @@ describe.skipIf(!HAS_ANTIGRAVITY_AUTH)("Compaction with thinking models (Antigra
return session; return session;
} }
it("should compact successfully with claude-opus-4-6-thinking and thinking level high", async () => { it("should compact successfully with claude-opus-4-5-thinking and thinking level high", async () => {
createSession("claude-opus-4-6-thinking", "high"); createSession("claude-opus-4-5-thinking", "high");
// Send a simple prompt // Send a simple prompt
await session.prompt("Write down the first 10 prime numbers."); await session.prompt("Write down the first 10 prime numbers.");