From 58101a0ef9202f21be717a4a88953bda09a3bd87 Mon Sep 17 00:00:00 2001 From: Petr Ivanov Date: Tue, 20 Oct 2026 21:12:11 +0000 Subject: [PATCH] fix: drop unsupported JSON Schema 'format' from tool parameters GigaChat API only accepts format 'date', 'date-time' or 'time'. Other JSON Schema formats such as 'uri' (used by webfetch tool schemas) cause the API to reject the request with 422 INVALID_PARAMS. sanitizeFunctionParameters now filters out any format value outside the allowed set. --- src/plugin/tools.ts | 4 ++++ src/plugin/translation.test.ts | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/plugin/tools.ts b/src/plugin/tools.ts index 83f95b4..372bce9 100644 --- a/src/plugin/tools.ts +++ b/src/plugin/tools.ts @@ -40,6 +40,10 @@ export function sanitizeFunctionParameters(params: any): any { ) continue; const val = params[key]; + // GigaChat API only accepts format "date", "date-time" or "time". + // Other JSON Schema formats (e.g. "uri" used by webfetch) cause 422. + if (key === "format" && !["date", "date-time", "time"].includes(val)) + continue; if (key === "properties" && val !== null && typeof val === "object") { out[key] = {}; for (const propKey of Object.keys(val)) { diff --git a/src/plugin/translation.test.ts b/src/plugin/translation.test.ts index 44d6fa4..be51267 100644 --- a/src/plugin/translation.test.ts +++ b/src/plugin/translation.test.ts @@ -22,6 +22,28 @@ describe("GigaChat Request Translator", () => { expect(stringifyArguments(null)).toBe("{}"); }); + it("drops unsupported JSON Schema format values (422 guard) but keeps date/time", () => { + expect( + sanitizeFunctionParameters({ + type: "object", + properties: { + url: { type: "string", format: "uri" }, + created: { type: "string", format: "date-time" }, + day: { type: "string", format: "date" }, + clock: { type: "string", format: "time" }, + }, + }), + ).toEqual({ + type: "object", + properties: { + url: { type: "string" }, + created: { type: "string", format: "date-time" }, + day: { type: "string", format: "date" }, + clock: { type: "string", format: "time" }, + }, + }); + }); + it("rejects an upload response without a usable file ID", async () => { const post = vi.spyOn(axios, "post").mockResolvedValue({ data: {} }); try {