File size: 1,752 Bytes
fc93158 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | import type { AgentTool } from "@mariozechner/pi-agent-core";
import { describe, expect, it } from "vitest";
import { sanitizeToolsForGoogle } from "./google.js";
describe("sanitizeToolsForGoogle", () => {
const createTool = (parameters: Record<string, unknown>) =>
({
name: "test",
description: "test",
parameters,
execute: async () => ({ ok: true, content: [] }),
}) as unknown as AgentTool;
const expectFormatRemoved = (
sanitized: AgentTool,
key: "additionalProperties" | "patternProperties",
) => {
const params = sanitized.parameters as {
additionalProperties?: unknown;
patternProperties?: unknown;
properties?: Record<string, { format?: unknown }>;
};
expect(params[key]).toBeUndefined();
expect(params.properties?.foo?.format).toBeUndefined();
};
it("strips unsupported schema keywords for Google providers", () => {
const tool = createTool({
type: "object",
additionalProperties: false,
properties: {
foo: {
type: "string",
format: "uuid",
},
},
});
const [sanitized] = sanitizeToolsForGoogle({
tools: [tool],
provider: "google-gemini-cli",
});
expectFormatRemoved(sanitized, "additionalProperties");
});
it("returns original tools for non-google providers", () => {
const tool = createTool({
type: "object",
additionalProperties: false,
properties: {
foo: {
type: "string",
format: "uuid",
},
},
});
const sanitized = sanitizeToolsForGoogle({
tools: [tool],
provider: "openai",
});
expect(sanitized).toEqual([tool]);
expect(sanitized[0]).toBe(tool);
});
});
|