From 5d34652d4604b2187d9e27dd275527d8c8a4564b Mon Sep 17 00:00:00 2001 From: ztimson Date: Sun, 1 Mar 2026 18:11:25 -0500 Subject: [PATCH] Fixed CLI tool --- package.json | 2 +- src/open-ai.ts | 1 + src/tools.ts | 14 ++++++++------ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 7526090..166f253 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ztimson/ai-utils", - "version": "0.8.6", + "version": "0.8.7", "description": "AI Utility library", "author": "Zak Timson", "license": "MIT", diff --git a/src/open-ai.ts b/src/open-ai.ts index 5e1c4e9..def16d2 100644 --- a/src/open-ai.ts +++ b/src/open-ai.ts @@ -148,6 +148,7 @@ export class OpenAi extends LLMProvider { try { const args = JSONAttemptParse(toolCall.function.arguments, {}); const result = await tool.fn(args, options.stream, this.ai); + console.log(result); return {role: 'tool', tool_call_id: toolCall.id, content: JSONSanitize(result)}; } catch (err: any) { return {role: 'tool', tool_call_id: toolCall.id, content: JSONSanitize({error: err?.message || err?.toString() || 'Unknown'})}; diff --git a/src/tools.ts b/src/tools.ts index 5ac8a94..351e80b 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -65,14 +65,15 @@ export const ExecTool: AiTool = { }, fn: async (args, stream, ai) => { try { - switch(args.type) { + switch(args.language) { case 'cli': return await CliTool.fn({command: args.code}, stream, ai); case 'node': return await JSTool.fn({code: args.code}, stream, ai); - case 'python': { + case 'python': return await PythonTool.fn({code: args.code}, stream, ai); - } + default: + throw new Error(`Unsupported language: ${args.language}`); } } catch(err: any) { return {error: err?.message || err.toString()}; @@ -104,9 +105,10 @@ export const JSTool: AiTool = { code: {type: 'string', description: 'CommonJS javascript', required: true} }, fn: async (args: {code: string}) => { - const console = consoleInterceptor(null); - const resp = await Fn({console}, args.code, true).catch((err: any) => console.output.error.push(err)); - return {...console.output, return: resp, stdout: undefined, stderr: undefined}; + console.log('executing js') + const c = consoleInterceptor(null); + const resp = await Fn({console: c}, args.code, true).catch((err: any) => c.output.error.push(err)); + return {...c.output, return: resp, stdout: undefined, stderr: undefined}; } }