From 0c4f80bca864f126ee3283b8faa4556ee2da8b11 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 17 Nov 2024 17:58:18 -0800 Subject: [PATCH] run terminal command tool --- core/config/load.ts | 7 +++-- core/tools/index.ts | 22 ++++++++++++++ gui/src/hooks/useChatHandler.ts | 1 - gui/src/pages/gui/ToolCallDiv/CreateFile.tsx | 4 +-- .../gui/ToolCallDiv/RunTerminalCommand.tsx | 29 +++++++++++++++++++ gui/src/pages/gui/ToolCallDiv/index.tsx | 3 ++ 6 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 gui/src/pages/gui/ToolCallDiv/RunTerminalCommand.tsx diff --git a/core/config/load.ts b/core/config/load.ts index 25a9b510d..b199e0e58 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -58,7 +58,7 @@ import { readAllGlobalPromptFiles, } from "../util/paths"; -import { makeCreateNewFileTool } from "../tools"; +import { makeCreateNewFileTool, runTerminalCommandTool } from "../tools"; import { defaultContextProvidersJetBrains, defaultContextProvidersVsCode, @@ -336,7 +336,10 @@ async function intermediateToFinalConfig( ...model.requestOptions, ...config.requestOptions, }; - model.completionOptions.tools = [makeCreateNewFileTool(ide)]; + model.completionOptions.tools = [ + makeCreateNewFileTool(ide), + runTerminalCommandTool(ide), + ]; } if (allowFreeTrial) { diff --git a/core/tools/index.ts b/core/tools/index.ts index ad6767d9b..aec23de36 100644 --- a/core/tools/index.ts +++ b/core/tools/index.ts @@ -24,3 +24,25 @@ export const makeCreateNewFileTool = (ide: IDE): Tool => ({ }, }, }); + +export const runTerminalCommandTool = (ide: IDE): Tool => ({ + type: "function", + action: async (...args) => { + await ide.runCommand(args[0]); + }, + function: { + name: "run_terminal_command", + description: "Run a terminal command in the current directory", + parameters: { + type: "object", + required: ["command"], + properties: { + command: { + type: "string", + description: + "The command to run. This will be passed directly into the shell.", + }, + }, + }, + }, +}); diff --git a/gui/src/hooks/useChatHandler.ts b/gui/src/hooks/useChatHandler.ts index a66debf80..baf2310c6 100644 --- a/gui/src/hooks/useChatHandler.ts +++ b/gui/src/hooks/useChatHandler.ts @@ -89,7 +89,6 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) { abortController.abort(); break; } - console.log(".......", (next.value as any).role); dispatch(streamUpdate(next.value as ChatMessage)); next = await gen.next(); } diff --git a/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx b/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx index e1e65981e..5dbdaf340 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:

+

Continue wants to run a terminal command:

+ + + + + {props.command} + + + + ); +} diff --git a/gui/src/pages/gui/ToolCallDiv/index.tsx b/gui/src/pages/gui/ToolCallDiv/index.tsx index a505137d8..dbe7c3bed 100644 --- a/gui/src/pages/gui/ToolCallDiv/index.tsx +++ b/gui/src/pages/gui/ToolCallDiv/index.tsx @@ -7,6 +7,7 @@ import { vscButtonForeground, } from "../../../components"; import { CreateFile } from "./CreateFile"; +import { RunTerminalCommand } from "./RunTerminalCommand"; const Container = styled.div` margin: 8px; @@ -66,6 +67,8 @@ function FunctionSpecificToolCallDiv(toolCall: ToolCall) { return ( ); + case "run_terminal_command": + return ; default: return ( <>