mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 08:47:44 +00:00
fix(core): Sanitize tool parameters to fix 400 API errors (#3300)
This commit is contained in:
@@ -14,13 +14,8 @@ import {
|
||||
import { parse } from 'shell-quote';
|
||||
import { MCPServerConfig } from '../config/config.js';
|
||||
import { DiscoveredMCPTool } from './mcp-tool.js';
|
||||
import {
|
||||
CallableTool,
|
||||
FunctionDeclaration,
|
||||
mcpToTool,
|
||||
Schema,
|
||||
} from '@google/genai';
|
||||
import { ToolRegistry } from './tool-registry.js';
|
||||
import { CallableTool, FunctionDeclaration, mcpToTool } from '@google/genai';
|
||||
import { sanitizeParameters, ToolRegistry } from './tool-registry.js';
|
||||
|
||||
export const MCP_DEFAULT_TIMEOUT_MSEC = 10 * 60 * 1000; // default to 10 minutes
|
||||
|
||||
@@ -384,31 +379,3 @@ async function connectAndDiscover(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes a JSON schema object to ensure compatibility with Vertex AI.
|
||||
* This function recursively processes the schema to remove problematic properties
|
||||
* that can cause issues with the Gemini API.
|
||||
*
|
||||
* @param schema The JSON schema object to sanitize (modified in-place)
|
||||
*/
|
||||
export function sanitizeParameters(schema?: Schema) {
|
||||
if (!schema) {
|
||||
return;
|
||||
}
|
||||
if (schema.anyOf) {
|
||||
// Vertex AI gets confused if both anyOf and default are set.
|
||||
schema.default = undefined;
|
||||
for (const item of schema.anyOf) {
|
||||
sanitizeParameters(item);
|
||||
}
|
||||
}
|
||||
if (schema.items) {
|
||||
sanitizeParameters(schema.items);
|
||||
}
|
||||
if (schema.properties) {
|
||||
for (const item of Object.values(schema.properties)) {
|
||||
sanitizeParameters(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user