run terminal command tool

This commit is contained in:
Nate 2024-11-17 17:58:18 -08:00
parent 59bb5f8246
commit 0c4f80bca8
6 changed files with 61 additions and 5 deletions

View file

@ -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) {

View file

@ -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.",
},
},
},
},
});

View file

@ -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();
}

View file

@ -11,10 +11,10 @@ export function CreateFile(props: CreateFileToolCallProps) {
<>
<p>Continue wants to create a file:</p>
<StepContainerPreToolbar
codeBlockContent={props.fileContents ?? "abc"}
codeBlockContent={props.fileContents ?? ""}
codeBlockIndex={0}
language={"javascript"}
filepath={props.filepath ?? "test.js"}
filepath={props.filepath ?? ""}
isGeneratingCodeBlock={false}
expanded={false}
hideApply={true}

View file

@ -0,0 +1,29 @@
import StepContainerPreToolbar from "../../../components/markdown/StepContainerPreToolbar";
import { SyntaxHighlightedPre } from "../../../components/markdown/SyntaxHighlightedPre";
interface RunTerminalCommandToolCallProps {
command: string;
}
export function RunTerminalCommand(props: RunTerminalCommandToolCallProps) {
return (
<>
<p>Continue wants to run a terminal command:</p>
<StepContainerPreToolbar
codeBlockContent={props.command ?? ""}
codeBlockIndex={0}
language={"bash"}
filepath={"bash"}
isGeneratingCodeBlock={false}
expanded={false}
hideApply={true}
>
<SyntaxHighlightedPre>
<span></span>
{props.command}
</SyntaxHighlightedPre>
</StepContainerPreToolbar>
</>
);
}

View file

@ -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 (
<CreateFile filepath={args.filepath} fileContents={args.contents} />
);
case "run_terminal_command":
return <RunTerminalCommand command={args.command} />;
default:
return (
<>