@@ -19,7 +19,8 @@ export async function executeToolCall(toolCall: ToolCall): Promise<Message> {
1919 forecastDays?: number;
2020 };
2121
22- const tools = {
22+ type ToolName = "query_web_search" | "query_weather" | "query_duckduckgo" | "fetch_page";
23+ const tools: Record<ToolName, (query: string) => Promise<string>> = {
2324 query_web_search: queryWebSearch,
2425 query_weather: queryWeather,
2526 query_duckduckgo: queryDuckDuckGo,
@@ -32,8 +33,10 @@ export async function executeToolCall(toolCall: ToolCall): Promise<Message> {
3233 result = await queryWeather(query!, timezone, forecastDays);
3334 } else if (name === "fetch_page") {
3435 result = await fetchPage(url!);
36+ } else if (name in tools) {
37+ result = await tools[name as ToolName](query!);
3538 } else {
36- result = await tools[name](query!);
39+ throw new Error(`Unknown tool: ${name}`);
3740 }
3841 debug(`[Tool] ${name} completed (${result.length} chars)`);
3942 } catch (error) {