From 7ef29aba37f232b0abfc002fd882a6a009c696c0 Mon Sep 17 00:00:00 2001 From: vikingowl Date: Fri, 2 Jan 2026 21:08:52 +0100 Subject: [PATCH] fix: coerce numeric tool args to handle string values from Ollama MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ollama models sometimes output numbers as strings in tool call arguments. Go backend strictly rejects string→int coercion, causing errors like: "cannot unmarshal string into Go struct field URLFetchRequest.maxLength" - fetch_url: coerce maxLength, timeout - web_search: coerce maxResults, timeout - calculate: coerce precision --- frontend/src/lib/tools/builtin.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/tools/builtin.ts b/frontend/src/lib/tools/builtin.ts index 971e3c7..65c7307 100644 --- a/frontend/src/lib/tools/builtin.ts +++ b/frontend/src/lib/tools/builtin.ts @@ -292,7 +292,9 @@ class MathParser { const mathParser = new MathParser(); const calculateHandler: BuiltinToolHandler = (args) => { - const { expression, precision = 10 } = args; + const { expression } = args; + // Coerce to number - Ollama models sometimes output numbers as strings + const precision = Number(args.precision) || 10; try { const result = mathParser.parse(expression); @@ -423,7 +425,10 @@ async function fetchViaProxy(url: string, maxLength: number, timeout: number): P } const fetchUrlHandler: BuiltinToolHandler = async (args) => { - const { url, extract = 'text', maxLength = 50000, timeout = 30 } = args; + const { url, extract = 'text' } = args; + // Coerce to numbers - Ollama models sometimes output numbers as strings + const maxLength = Number(args.maxLength) || 50000; + const timeout = Number(args.timeout) || 30; try { const parsedUrl = new URL(url); @@ -683,7 +688,10 @@ const webSearchDefinition: ToolDefinition = { }; const webSearchHandler: BuiltinToolHandler = async (args) => { - const { query, maxResults = 5, site, freshness, region, timeout } = args; + const { query, site, freshness, region } = args; + // Coerce to numbers - Ollama models sometimes output numbers as strings + const maxResults = Number(args.maxResults) || 5; + const timeout = Number(args.timeout) || undefined; if (!query || query.trim() === '') { return { error: 'Search query is required' };