From 6d551b0d6e64d03bde00eb5b5e04e7b1f160ecb9 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 23 Dec 2025 14:09:07 +0000 Subject: [PATCH] fix: normalize tool schemas for lm studio --- src/agents/pi-tools.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/agents/pi-tools.ts b/src/agents/pi-tools.ts index 1ed62ba4d..f489c45e0 100644 --- a/src/agents/pi-tools.ts +++ b/src/agents/pi-tools.ts @@ -99,6 +99,26 @@ async function normalizeReadImageResult( type AnyAgentTool = AgentTool; +function normalizeToolParameters(tool: AnyAgentTool): AnyAgentTool { + const schema = + tool.parameters && typeof tool.parameters === "object" + ? (tool.parameters as Record) + : undefined; + if (!schema) return tool; + if ("type" in schema && "properties" in schema) return tool; + if (!Array.isArray(schema.anyOf)) return tool; + return { + ...tool, + parameters: { + ...schema, + type: "object", + properties: schema.properties ?? {}, + additionalProperties: + "additionalProperties" in schema ? schema.additionalProperties : true, + } as TSchema, + }; +} + function createWhatsAppLoginTool(): AnyAgentTool { return { label: "WhatsApp Login", @@ -206,5 +226,7 @@ export function createClawdisCodingTools(): AnyAgentTool[] { ? createClawdisBashTool(tool) : (tool as AnyAgentTool), ); - return [...base, createWhatsAppLoginTool(), ...createClawdisTools()]; + return [...base, createWhatsAppLoginTool(), ...createClawdisTools()].map( + normalizeToolParameters, + ); }