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: