From af6832b7f0d1adef7441b214bf182f85fb861d54 Mon Sep 17 00:00:00 2001 From: bbbugg Date: Tue, 5 May 2026 15:58:06 +0800 Subject: [PATCH 1/2] fix: enhance schema sanitization logic in FormatConverter and remove unused tool sanitization in RequestHandler --- src/core/FormatConverter.js | 6 +++--- src/core/RequestHandler.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/FormatConverter.js b/src/core/FormatConverter.js index a030e7c..f135a52 100644 --- a/src/core/FormatConverter.js +++ b/src/core/FormatConverter.js @@ -286,7 +286,7 @@ class FormatConverter { // Helper function to recursively sanitize schema: // 1. Remove unsupported fields ($schema, additionalProperties) // 2. Convert lowercase type to uppercase (object -> OBJECT, string -> STRING, etc.) - const sanitizeSchema = obj => { + const sanitizeSchema = (obj, isPropertiesMap = false) => { if (!obj || typeof obj !== "object") return obj; const result = Array.isArray(obj) ? [] : {}; @@ -302,7 +302,7 @@ class FormatConverter { "patternProperties", "unevaluatedProperties", ]; - if (unsupportedKeys.includes(key)) { + if (!isPropertiesMap && unsupportedKeys.includes(key)) { continue; } @@ -310,7 +310,7 @@ class FormatConverter { // Convert lowercase type to uppercase for Gemini result[key] = obj[key].toUpperCase(); } else if (typeof obj[key] === "object" && obj[key] !== null) { - result[key] = sanitizeSchema(obj[key]); + result[key] = sanitizeSchema(obj[key], key === "properties"); } else { result[key] = obj[key]; } diff --git a/src/core/RequestHandler.js b/src/core/RequestHandler.js index db96f8d..104eaa3 100644 --- a/src/core/RequestHandler.js +++ b/src/core/RequestHandler.js @@ -4137,9 +4137,9 @@ class RequestHandler { if (bodyObj.contents) { this.formatConverter.ensureThoughtSignature(bodyObj); } - if (bodyObj.tools) { - this.formatConverter.sanitizeGeminiTools(bodyObj); - } + // if (bodyObj.tools) { + // this.formatConverter.sanitizeGeminiTools(bodyObj); + // } } // Force web search and URL context for native Google requests From 1b3e05ce39362bee12385ced4e590b50c0bab1fd Mon Sep 17 00:00:00 2001 From: bbbugg Date: Tue, 5 May 2026 16:26:15 +0800 Subject: [PATCH 2/2] fix: simplify schema sanitization logic and re-enable tool sanitization in RequestHandler --- src/core/FormatConverter.js | 18 ++---------------- src/core/RequestHandler.js | 6 +++--- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/core/FormatConverter.js b/src/core/FormatConverter.js index f135a52..c5417c5 100644 --- a/src/core/FormatConverter.js +++ b/src/core/FormatConverter.js @@ -286,31 +286,17 @@ class FormatConverter { // Helper function to recursively sanitize schema: // 1. Remove unsupported fields ($schema, additionalProperties) // 2. Convert lowercase type to uppercase (object -> OBJECT, string -> STRING, etc.) - const sanitizeSchema = (obj, isPropertiesMap = false) => { + const sanitizeSchema = obj => { if (!obj || typeof obj !== "object") return obj; const result = Array.isArray(obj) ? [] : {}; for (const key of Object.keys(obj)) { - // Skip fields not supported by Gemini API - const unsupportedKeys = [ - "$schema", - "additionalProperties", - "ref", - "$ref", - "propertyNames", - "patternProperties", - "unevaluatedProperties", - ]; - if (!isPropertiesMap && unsupportedKeys.includes(key)) { - continue; - } - if (key === "type" && typeof obj[key] === "string") { // Convert lowercase type to uppercase for Gemini result[key] = obj[key].toUpperCase(); } else if (typeof obj[key] === "object" && obj[key] !== null) { - result[key] = sanitizeSchema(obj[key], key === "properties"); + result[key] = sanitizeSchema(obj[key]); } else { result[key] = obj[key]; } diff --git a/src/core/RequestHandler.js b/src/core/RequestHandler.js index 104eaa3..db96f8d 100644 --- a/src/core/RequestHandler.js +++ b/src/core/RequestHandler.js @@ -4137,9 +4137,9 @@ class RequestHandler { if (bodyObj.contents) { this.formatConverter.ensureThoughtSignature(bodyObj); } - // if (bodyObj.tools) { - // this.formatConverter.sanitizeGeminiTools(bodyObj); - // } + if (bodyObj.tools) { + this.formatConverter.sanitizeGeminiTools(bodyObj); + } } // Force web search and URL context for native Google requests