Remove provider-level tool validation, add validateToolCall helper

This commit is contained in:
Mario Zechner 2025-12-08 18:04:33 +01:00
parent 0196308266
commit 8bec289dc6
14 changed files with 59 additions and 68 deletions

View file

@ -27,6 +27,21 @@ if (!isBrowserExtension) {
}
}
/**
* Finds a tool by name and validates the tool call arguments against its TypeBox schema
* @param tools Array of tool definitions
* @param toolCall The tool call from the LLM
* @returns The validated arguments
* @throws Error if tool is not found or validation fails
*/
export function validateToolCall(tools: Tool[], toolCall: ToolCall): any {
const tool = tools.find((t) => t.name === toolCall.name);
if (!tool) {
throw new Error(`Tool "${toolCall.name}" not found`);
}
return validateToolArguments(tool, toolCall);
}
/**
* Validates tool call arguments against the tool's TypeBox schema
* @param tool The tool definition with TypeBox schema