fix(ai): sanitize Mistral tool schemas closes #3361

This commit is contained in:
Mario Zechner
2026-04-18 00:54:21 +02:00
parent bfa11a50e4
commit 2dddc5ba25
4 changed files with 85 additions and 3 deletions

View File

@@ -456,12 +456,28 @@ function toFunctionTools(tools: Tool[]): Array<FunctionTool & { type: "function"
function: {
name: tool.name,
description: tool.description,
parameters: tool.parameters as unknown as Record<string, unknown>,
parameters: stripSymbolKeys(tool.parameters) as Record<string, unknown>,
strict: false,
},
}));
}
function stripSymbolKeys(value: unknown): unknown {
if (Array.isArray(value)) {
return value.map((item) => stripSymbolKeys(item));
}
if (value && typeof value === "object") {
const result: Record<string, unknown> = {};
for (const [key, entry] of Object.entries(value)) {
result[key] = stripSymbolKeys(entry);
}
return result;
}
return value;
}
function toChatMessages(messages: Message[], supportsImages: boolean): ChatCompletionStreamRequestMessage[] {
const result: ChatCompletionStreamRequestMessage[] = [];