change cleanSchemaForGemini to cleanSchema

This commit is contained in:
Badri Narayanan S
2026-01-10 00:35:50 +05:30
parent e4145ad277
commit f1e945a7e6
2 changed files with 8 additions and 8 deletions

View File

@@ -9,7 +9,7 @@ import {
isThinkingModel isThinkingModel
} from '../constants.js'; } from '../constants.js';
import { convertContentToParts, convertRole } from './content-converter.js'; import { convertContentToParts, convertRole } from './content-converter.js';
import { sanitizeSchema, cleanSchemaForGemini } from './schema-sanitizer.js'; import { sanitizeSchema, cleanSchema } from './schema-sanitizer.js';
import { import {
restoreThinkingSignatures, restoreThinkingSignatures,
removeTrailingThinkingBlocks, removeTrailingThinkingBlocks,
@@ -214,7 +214,7 @@ export function convertAnthropicToGoogle(anthropicRequest) {
// Cloud Code API which validates schemas using Google's protobuf format. // Cloud Code API which validates schemas using Google's protobuf format.
// This fixes issue #82: /compact command fails with schema transformation error // This fixes issue #82: /compact command fails with schema transformation error
// "Proto field is not repeating, cannot start list" for Claude models. // "Proto field is not repeating, cannot start list" for Claude models.
parameters = cleanSchemaForGemini(parameters); parameters = cleanSchema(parameters);
return { return {
name: String(name).replace(/[^a-zA-Z0-9_-]/g, '_').slice(0, 64), name: String(name).replace(/[^a-zA-Z0-9_-]/g, '_').slice(0, 64),

View File

@@ -592,9 +592,9 @@ function toGoogleType(type) {
* @param {Object} schema - The JSON schema to clean * @param {Object} schema - The JSON schema to clean
* @returns {Object} Cleaned schema safe for Gemini API * @returns {Object} Cleaned schema safe for Gemini API
*/ */
export function cleanSchemaForGemini(schema) { export function cleanSchema(schema) {
if (!schema || typeof schema !== 'object') return schema; if (!schema || typeof schema !== 'object') return schema;
if (Array.isArray(schema)) return schema.map(cleanSchemaForGemini); if (Array.isArray(schema)) return schema.map(cleanSchema);
// Phase 1: Convert $refs to hints // Phase 1: Convert $refs to hints
let result = convertRefsToHints(schema); let result = convertRefsToHints(schema);
@@ -641,16 +641,16 @@ export function cleanSchemaForGemini(schema) {
if (result.properties && typeof result.properties === 'object') { if (result.properties && typeof result.properties === 'object') {
const newProps = {}; const newProps = {};
for (const [key, value] of Object.entries(result.properties)) { for (const [key, value] of Object.entries(result.properties)) {
newProps[key] = cleanSchemaForGemini(value); newProps[key] = cleanSchema(value);
} }
result.properties = newProps; result.properties = newProps;
} }
if (result.items) { if (result.items) {
if (Array.isArray(result.items)) { if (Array.isArray(result.items)) {
result.items = result.items.map(cleanSchemaForGemini); result.items = result.items.map(cleanSchema);
} else if (typeof result.items === 'object') { } else if (typeof result.items === 'object') {
result.items = cleanSchemaForGemini(result.items); result.items = cleanSchema(result.items);
} }
} }
@@ -664,7 +664,7 @@ export function cleanSchemaForGemini(schema) {
} }
// Phase 5: Convert type to Google's uppercase format (STRING, OBJECT, ARRAY, etc.) // Phase 5: Convert type to Google's uppercase format (STRING, OBJECT, ARRAY, etc.)
// Only convert at current level - nested types already converted by recursive cleanSchemaForGemini calls // Only convert at current level - nested types already converted by recursive cleanSchema calls
if (result.type && typeof result.type === 'string') { if (result.type && typeof result.type === 'string') {
result.type = toGoogleType(result.type); result.type = toGoogleType(result.type);
} }