From 445716c1ccdc642a261e8aaaa6ecda945ef1f169 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 17 Nov 2024 18:54:23 -0800 Subject: [PATCH] run tools --- core/core.ts | 2 +- core/tools/index.ts | 12 ++++++- gui/src/pages/gui/ToolCallDiv/CreateFile.tsx | 4 +-- gui/src/pages/gui/ToolCallDiv/index.tsx | 37 ++++++++++++++++---- 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/core/core.ts b/core/core.ts index f2dc9387c..babecfec8 100644 --- a/core/core.ts +++ b/core/core.ts @@ -744,7 +744,7 @@ export class Core { on("tools/call", async ({ data: { toolCall } }) => { const tool = instantiateTool(toolCall.function.name, { ide: this.ide }); - const result = await tool.action(toolCall.function.arguments); + const result = await tool.action(JSON.parse(toolCall.function.arguments)); return { result }; }); } diff --git a/core/tools/index.ts b/core/tools/index.ts index ab592b757..862f7dd6b 100644 --- a/core/tools/index.ts +++ b/core/tools/index.ts @@ -1,4 +1,5 @@ import { IDE, Tool } from ".."; +import { getPathModuleForIde } from "../util/pathModule"; export interface ToolParams { ide: IDE; @@ -7,7 +8,16 @@ export interface ToolParams { export const makeCreateNewFileTool = ({ ide }: ToolParams): Tool => ({ type: "function", action: async (args: any) => { - await ide.writeFile(args.filepath, args.contents); + const pathSep = await ide.pathSep(); + let filepath = args.filepath; + if (!args.filepath.startsWith(pathSep)) { + const pathModule = await getPathModuleForIde(ide); + const workspaceDirs = await ide.getWorkspaceDirs(); + const cwd = workspaceDirs[0]; + filepath = pathModule.join(cwd, filepath); + } + await ide.writeFile(filepath, args.contents); + await ide.openFile(filepath); }, function: { name: "create_new_file", diff --git a/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx b/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx index 5dbdaf340..0eee17b96 100644 --- a/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx +++ b/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx @@ -11,10 +11,10 @@ export function CreateFile(props: CreateFileToolCallProps) { <>

Continue wants to create a file:

(true); + + useEffect(() => { + if (props.toolCall.function.arguments.length === 0) { + return; + } + + const [done, _] = incrementalParseJson(props.toolCall.function.arguments); + if (done) { + setLoading(false); + } + }, [props.toolCall.function.arguments]); + async function callTool() { const result = await ideMessenger.request("tools/call", { toolCall: props.toolCall, @@ -109,8 +123,17 @@ export function ToolCallDiv(props: ToolCallDivProps) { - {}}>Cancel - Continue + {loading ? ( +
+ Loading... + +
+ ) : ( + <> + {}}>Cancel + Continue + + )}
);