From 6cda84432ebf2c2afe9ebdbc4e6c7fee1d775dfc Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 3 Jan 2026 05:22:09 +0100 Subject: [PATCH] fix: stabilize pi-ai patch + tests --- package.json | 1 + patches/@mariozechner__pi-ai.patch | 2 +- pnpm-lock.yaml | 13 ++-- src/providers/google-shared.test.ts | 106 ++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 src/providers/google-shared.test.ts diff --git a/package.json b/package.json index a000aa07b..09fda15a3 100644 --- a/package.json +++ b/package.json @@ -86,6 +86,7 @@ "commander": "^14.0.2", "croner": "^9.1.0", "detect-libc": "^2.1.2", + "discord-api-types": "^0.38.33", "discord.js": "^14.25.1", "dotenv": "^17.2.3", "express": "^5.2.1", diff --git a/patches/@mariozechner__pi-ai.patch b/patches/@mariozechner__pi-ai.patch index ac330e87a..5bc1e51b0 100644 --- a/patches/@mariozechner__pi-ai.patch +++ b/patches/@mariozechner__pi-ai.patch @@ -2,7 +2,7 @@ diff --git a/dist/providers/google-shared.js b/dist/providers/google-shared.js index ff9cbcfebfac6b4370d85dc838f5cacf2a60ed64..42096c82aec925b412258348a36ba4a7025b283b 100644 --- a/dist/providers/google-shared.js +++ b/dist/providers/google-shared.js -@@ -140,6 +140,71 @@ export function convertMessages(model, context) { +@@ -140,6 +140,72 @@ export function convertMessages(model, context) { } return contents; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 16594cd5d..b71dfa378 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,7 +9,7 @@ overrides: patchedDependencies: '@mariozechner/pi-ai': - hash: 717192ba4aea08520822591984491823add75c2f88037188acc7a916b52326f4 + hash: 969db6f3f4cc91fec48124e1f5e515b386b1f1bed807769d0a80c28abadbaaae path: patches/@mariozechner__pi-ai.patch '@mariozechner/pi-coding-agent@0.31.1': hash: d0d5ffa1bfda8a0f9d14a5e73a074014346d3edbdb2ffc91444d3be5119f5745 @@ -33,7 +33,7 @@ importers: version: 0.31.1(ws@8.18.3)(zod@4.3.4) '@mariozechner/pi-ai': specifier: ^0.31.1 - version: 0.31.1(patch_hash=717192ba4aea08520822591984491823add75c2f88037188acc7a916b52326f4)(ws@8.18.3)(zod@4.3.4) + version: 0.31.1(patch_hash=969db6f3f4cc91fec48124e1f5e515b386b1f1bed807769d0a80c28abadbaaae)(ws@8.18.3)(zod@4.3.4) '@mariozechner/pi-coding-agent': specifier: ^0.31.1 version: 0.31.1(patch_hash=d0d5ffa1bfda8a0f9d14a5e73a074014346d3edbdb2ffc91444d3be5119f5745)(ws@8.18.3)(zod@4.3.4) @@ -70,6 +70,9 @@ importers: detect-libc: specifier: ^2.1.2 version: 2.1.2 + discord-api-types: + specifier: ^0.38.33 + version: 0.38.37 discord.js: specifier: ^14.25.1 version: 14.25.1 @@ -3350,7 +3353,7 @@ snapshots: '@mariozechner/pi-agent-core@0.31.1(ws@8.18.3)(zod@4.3.4)': dependencies: - '@mariozechner/pi-ai': 0.31.1(patch_hash=717192ba4aea08520822591984491823add75c2f88037188acc7a916b52326f4)(ws@8.18.3)(zod@4.3.4) + '@mariozechner/pi-ai': 0.31.1(patch_hash=969db6f3f4cc91fec48124e1f5e515b386b1f1bed807769d0a80c28abadbaaae)(ws@8.18.3)(zod@4.3.4) '@mariozechner/pi-tui': 0.31.1 transitivePeerDependencies: - '@modelcontextprotocol/sdk' @@ -3360,7 +3363,7 @@ snapshots: - ws - zod - '@mariozechner/pi-ai@0.31.1(patch_hash=717192ba4aea08520822591984491823add75c2f88037188acc7a916b52326f4)(ws@8.18.3)(zod@4.3.4)': + '@mariozechner/pi-ai@0.31.1(patch_hash=969db6f3f4cc91fec48124e1f5e515b386b1f1bed807769d0a80c28abadbaaae)(ws@8.18.3)(zod@4.3.4)': dependencies: '@anthropic-ai/sdk': 0.71.2(zod@4.3.4) '@google/genai': 1.34.0 @@ -3383,7 +3386,7 @@ snapshots: '@mariozechner/pi-coding-agent@0.31.1(patch_hash=d0d5ffa1bfda8a0f9d14a5e73a074014346d3edbdb2ffc91444d3be5119f5745)(ws@8.18.3)(zod@4.3.4)': dependencies: '@mariozechner/pi-agent-core': 0.31.1(ws@8.18.3)(zod@4.3.4) - '@mariozechner/pi-ai': 0.31.1(patch_hash=717192ba4aea08520822591984491823add75c2f88037188acc7a916b52326f4)(ws@8.18.3)(zod@4.3.4) + '@mariozechner/pi-ai': 0.31.1(patch_hash=969db6f3f4cc91fec48124e1f5e515b386b1f1bed807769d0a80c28abadbaaae)(ws@8.18.3)(zod@4.3.4) '@mariozechner/pi-tui': 0.31.1 chalk: 5.6.2 cli-highlight: 2.1.11 diff --git a/src/providers/google-shared.test.ts b/src/providers/google-shared.test.ts new file mode 100644 index 000000000..4e07d2421 --- /dev/null +++ b/src/providers/google-shared.test.ts @@ -0,0 +1,106 @@ +import { convertTools } from "@mariozechner/pi-ai/dist/providers/google-shared.js"; +import type { Tool } from "@mariozechner/pi-ai/dist/types.js"; +import { describe, expect, it } from "vitest"; + +const asRecord = (value: unknown): Record => { + expect(value).toBeTruthy(); + expect(typeof value).toBe("object"); + expect(Array.isArray(value)).toBe(false); + return value as Record; +}; + +describe("google-shared convertTools", () => { + it("strips unsupported JSON Schema keywords", () => { + const tools: Tool[] = [ + { + name: "example", + description: "Example tool", + parameters: { + type: "object", + patternProperties: { + "^x-": { type: "string" }, + }, + additionalProperties: false, + properties: { + mode: { + type: "string", + const: "fast", + }, + options: { + anyOf: [{ type: "string" }, { type: "number" }], + }, + list: { + type: "array", + items: { + type: "string", + const: "item", + }, + }, + }, + required: ["mode"], + }, + }, + ]; + + const converted = convertTools(tools); + const params = asRecord( + converted?.[0]?.functionDeclarations?.[0]?.parameters, + ); + const properties = asRecord(params.properties); + const mode = asRecord(properties.mode); + const options = asRecord(properties.options); + const list = asRecord(properties.list); + const items = asRecord(list.items); + + expect(params).not.toHaveProperty("patternProperties"); + expect(params).not.toHaveProperty("additionalProperties"); + expect(mode).not.toHaveProperty("const"); + expect(options).not.toHaveProperty("anyOf"); + expect(items).not.toHaveProperty("const"); + expect(params.required).toEqual(["mode"]); + }); + + it("keeps supported schema fields", () => { + const tools: Tool[] = [ + { + name: "settings", + description: "Settings tool", + parameters: { + type: "object", + properties: { + config: { + type: "object", + properties: { + retries: { type: "number", minimum: 1 }, + tags: { + type: "array", + items: { type: "string" }, + }, + }, + required: ["retries"], + }, + }, + required: ["config"], + }, + }, + ]; + + const converted = convertTools(tools); + const params = asRecord( + converted?.[0]?.functionDeclarations?.[0]?.parameters, + ); + const config = asRecord(asRecord(params.properties).config); + const configProps = asRecord(config.properties); + const retries = asRecord(configProps.retries); + const tags = asRecord(configProps.tags); + const items = asRecord(tags.items); + + expect(params.type).toBe("object"); + expect(config.type).toBe("object"); + expect(retries.minimum).toBe(1); + expect(tags.type).toBe("array"); + expect(items.type).toBe("string"); + expect(config.required).toEqual(["retries"]); + expect(params.required).toEqual(["config"]); + }); +});