fix(antigravity): update user-agent and fix schema validation

- Update hardcoded User-Agent `antigravity/1.11.5` to `1.15.8` in `@mariozechner/pi-ai` via pnpm patch to resolve "version not supported" error.
- Add `sanitizeToolUseInput` helper to ensure `tool_use` payloads include the required `input` field.
- Update `src/infra` usage fetcher User-Agent to match supported version.
This commit is contained in:
Harry Wu committed 2026-01-30 15:45:53 +08:00
1 parent 6af205a13a
commit f2958be6e0
9 files changed
+217 -8

No files matched your search

+5 -1
View File
@@ -32,7 +32,11 @@ export {
parseImageDimensionError,
parseImageSizeError,
} from "./pi-embedded-helpers/errors.js";
export { isGoogleModelApi, sanitizeGoogleTurnOrdering } from "./pi-embedded-helpers/google.js";
export {
isGoogleModelApi,
sanitizeGoogleTurnOrdering,
sanitizeToolUseInput,
} from "./pi-embedded-helpers/google.js";
export { downgradeOpenAIReasoningBlocks } from "./pi-embedded-helpers/openai.js";
export {
@@ -0,0 +1,88 @@
import { describe, it, expect } from "vitest";
import type { AgentMessage } from "@mariozechner/pi-agent-core";
import { sanitizeToolUseInput } from "./google.js";
describe("sanitizeToolUseInput", () => {
it("should add empty input to toolUse blocks missing it", () => {
const messages: AgentMessage[] = [
{
role: "assistant",
content: [
{
type: "toolUse",
id: "tool-1",
name: "readFile",
// missing input
} as any,
{
type: "text",
text: "Searching...",
},
],
},
];
const sanitized = sanitizeToolUseInput(messages);
const content = sanitized[0].content;
const toolUse = (Array.isArray(content) ? content[0] : null) as any;
expect(toolUse).toBeDefined();
expect(toolUse.input).toEqual({});
});
it("should preserve existing input", () => {
const messages: AgentMessage[] = [
{
role: "assistant",
content: [
{
type: "toolUse",
id: "tool-2",
name: "writeFile",
input: { path: "foo.txt" },
},
],
},
];
const sanitized = sanitizeToolUseInput(messages);
const content = sanitized[0].content;
const toolUse = (Array.isArray(content) ? content[0] : null) as any;
expect(toolUse.input).toEqual({ path: "foo.txt" });
});
it("should handle non-array content gracefully", () => {
const messages: AgentMessage[] = [
{
role: "user",
content: "Hello",
},
];
const sanitized = sanitizeToolUseInput(messages);
expect(sanitized).toEqual(messages);
});
it("should recurse through all messages", () => {
const messages: AgentMessage[] = [
{ role: "user", content: "Hi" },
{
role: "assistant",
content: [
{ type: "toolUse", id: "1", name: "a" } as any, // fix me
],
},
{
role: "assistant",
content: [
{ type: "toolUse", id: "2", name: "b", input: { foo: 1 } }, // leave me
],
},
];
const sanitized = sanitizeToolUseInput(messages);
expect((sanitized[1].content as any[])[0].input).toEqual({});
expect((sanitized[2].content as any[])[0].input).toEqual({ foo: 1 });
});
});
+22
View File
@@ -18,3 +18,25 @@ export function isAntigravityClaude(params: {
}
export { sanitizeGoogleTurnOrdering };
export function sanitizeToolUseInput(messages: any[]): any[] {
return messages.map((msg) => {
if (!msg || typeof msg !== "object") return msg;
if (msg.role !== "assistant" && msg.role !== "toolUse") return msg;
if (!Array.isArray(msg.content)) return msg;
return {
...msg,
content: msg.content.map((block: any) => {
if (!block || typeof block !== "object") return block;
if (block.type === "toolUse" || block.type === "toolCall") {
// If input is missing, add empty object
if (!("input" in block) || block.input === undefined) {
return { ...block, input: {} };
}
}
return block;
}),
};
});
}
+6 -2
View File
@@ -11,6 +11,7 @@ import {
isGoogleModelApi,
sanitizeGoogleTurnOrdering,
sanitizeSessionMessagesImages,
sanitizeToolUseInput,
} from "../pi-embedded-helpers.js";
import { sanitizeToolUseResultPairing } from "../session-transcript-repair.js";
import { log } from "./logger.js";
@@ -336,6 +337,9 @@ export async function sanitizeSessionHistory(params: {
? sanitizeToolUseResultPairing(sanitizedThinking)
: sanitizedThinking;
// Ensure toolUse blocks have input field (fixes schema validation "Field required")
const sanitizedInputs = sanitizeToolUseInput(repairedTools);
const isOpenAIResponsesApi =
params.modelApi === "openai-responses" || params.modelApi === "openai-codex-responses";
const hasSnapshot = Boolean(params.provider || params.modelApi || params.modelId);
@@ -350,8 +354,8 @@ export async function sanitizeSessionHistory(params: {
: false;
const sanitizedOpenAI =
isOpenAIResponsesApi && modelChanged
? downgradeOpenAIReasoningBlocks(repairedTools)
: repairedTools;
? downgradeOpenAIReasoningBlocks(sanitizedInputs)
: sanitizedInputs;
if (hasSnapshot && (!priorSnapshot || modelChanged)) {
appendModelSnapshot(params.sessionManager, {
@@ -174,7 +174,7 @@ export async function fetchAntigravityUsage(
const headers: Record<string, string> = {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
"User-Agent": "antigravity",
"User-Agent": "antigravity/1.15.8",
"X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1",
};