"Run in terminal" button

This commit is contained in:
Nate 2024-11-29 11:37:58 -08:00
parent e8550b0af6
commit d3d9af4292
9 changed files with 75 additions and 24 deletions

1
core/index.d.ts vendored
View file

@ -402,6 +402,7 @@ interface ToolCallState {
toolCall: ToolCall;
status: ToolStatus;
parsedArgs: any;
output?: ContextItem[];
}
export interface ChatHistoryItem {

View file

@ -1,5 +1,4 @@
import { Tool } from "../..";
import { BuiltInToolNames } from "../builtIn";
export const runTerminalCommandTool: Tool = {
@ -9,7 +8,8 @@ export const runTerminalCommandTool: Tool = {
readonly: false,
function: {
name: BuiltInToolNames.RunTerminalCommand,
description: "Run a terminal command in the current directory",
description:
"Run a terminal command in the current directory. The shell is not stateful and will not remember any previous commands.",
parameters: {
type: "object",
required: ["command"],

View file

@ -1,10 +1,10 @@
import { CheckIcon, XMarkIcon, PlayIcon } from "@heroicons/react/24/outline";
import Spinner from "./Spinner";
import { lightGray, vscForeground } from "../..";
import { useState } from "react";
import { getMetaKeyLabel } from "../../../util";
import { ToolbarButtonWithTooltip } from "./ToolbarButtonWithTooltip";
import { CheckIcon, PlayIcon, XMarkIcon } from "@heroicons/react/24/outline";
import { ApplyState } from "core";
import { useState } from "react";
import { lightGray, vscForeground } from "../..";
import { getMetaKeyLabel } from "../../../util";
import Spinner from "./Spinner";
import { ToolbarButtonWithTooltip } from "./ToolbarButtonWithTooltip";
interface ApplyActionsProps {
applyState?: ApplyState;

View file

@ -0,0 +1,35 @@
import { CommandLineIcon } from "@heroicons/react/24/outline";
import { useContext } from "react";
import { lightGray, vscForeground } from "../..";
import { IdeMessengerContext } from "../../../context/IdeMessenger";
interface RunInTerminalButtonProps {
command: string;
}
export default function RunInTerminalButton({
command,
}: RunInTerminalButtonProps) {
const ideMessenger = useContext(IdeMessengerContext);
function runInTerminal() {
void ideMessenger.post("runCommand", { command });
}
return (
<div
className={`flex items-center border-none bg-transparent text-xs text-gray-400 text-[${vscForeground}] cursor-pointer outline-none hover:brightness-125`}
onClick={runInTerminal}
>
<div
className="max-2xs:hidden flex items-center gap-1 transition-colors duration-200 hover:brightness-125"
style={{ color: lightGray }}
>
<>
<CommandLineIcon className="h-3 w-3 hover:brightness-125" />
<span className="text-gray-400 max-sm:hidden">Run</span>
</>
</div>
</div>
);
}

View file

@ -10,11 +10,12 @@ import { useWebviewListener } from "../../../hooks/useWebviewListener";
import { defaultModelSelector } from "../../../redux/selectors/modelSelectors";
import { RootState } from "../../../redux/store";
import { getFontSize } from "../../../util";
import { childrenToText } from "../utils";
import { childrenToText, isTerminalCodeBlock } from "../utils";
import ApplyActions from "./ApplyActions";
import CopyButton from "./CopyButton";
import FileInfo from "./FileInfo";
import GeneratingCodeLoader from "./GeneratingCodeLoader";
import RunInTerminalButton from "./RunInTerminalButton";
const fadeInAnimation = keyframes`
from {
@ -202,14 +203,17 @@ export default function StepContainerPreToolbar(
{!isGeneratingCodeBlock && (
<>
<CopyButton text={props.codeBlockContent} />
{props.hideApply || (
<ApplyActions
applyState={applyState}
onClickApply={onClickApply}
onClickAccept={onClickAcceptApply}
onClickReject={onClickRejectApply}
/>
)}
{props.hideApply ||
(isTerminalCodeBlock(props.language, props.codeBlockContent) ? (
<RunInTerminalButton command={props.codeBlockContent} />
) : (
<ApplyActions
applyState={applyState}
onClickApply={onClickApply}
onClickAccept={onClickAcceptApply}
onClickReject={onClickRejectApply}
/>
))}
</>
)}
</div>

View file

@ -18,7 +18,7 @@ function FunctionSpecificToolCallDiv({
<CreateFile filepath={args.filepath} fileContents={args.contents} />
);
case "run_terminal_command":
return <RunTerminalCommand command={args.command} />;
return <RunTerminalCommand command={args.command} toolCallState={toolCallState} />;
case "exact_search":
return <ExactSearch query={args.query} />;
default:

View file

@ -1,16 +1,16 @@
import { ToolCallState } from "core";
import StyledMarkdownPreview from "../../../components/markdown/StyledMarkdownPreview";
interface RunTerminalCommandToolCallProps {
command: string;
toolCallState: ToolCallState;
}
export function RunTerminalCommand(props: RunTerminalCommandToolCallProps) {
return (
<>
<StyledMarkdownPreview
isRenderingInStepContainer={true}
source={`\`\`\`bash .sh\n${props.command ?? ""}\n\`\`\``}
/>
</>
<StyledMarkdownPreview
isRenderingInStepContainer={true}
source={`\`\`\`bash .sh\n${props.command ?? ""}\n\`\`\``}
/>
);
}

View file

@ -10,6 +10,7 @@ import {
ChatHistoryItem,
ChatMessage,
Checkpoint,
ContextItem,
ContextItemWithId,
FileSymbolMap,
IndexingStatus,
@ -485,6 +486,12 @@ export const stateSlice = createSlice({
toolCallState.status = "generated";
},
setToolCallOutput: (state, action: PayloadAction<ContextItem[]>) => {
const toolCallState = findCurrentToolCall(state.history);
if (!toolCallState) return;
toolCallState.output = action.payload
},
cancelToolCall: (state) => {
const toolCallState = findCurrentToolCall(state.history);
if (!toolCallState) return;
@ -598,6 +605,7 @@ export const {
acceptToolCall,
setToolGenerated,
updateDocsSuggestions,
setToolCallOutput
} = stateSlice.actions;
export default stateSlice.reducer;

View file

@ -1,5 +1,6 @@
import { createAsyncThunk } from "@reduxjs/toolkit";
import { selectCurrentToolCall } from "../selectors/selectCurrentToolCall";
import { setToolCallOutput } from "../slices/stateSlice";
import { ThunkApiType } from "../store";
import { streamResponseAfterToolCall } from "./streamResponseAfterToolCall";
@ -24,6 +25,8 @@ export const callTool = createAsyncThunk<void, undefined, ThunkApiType>(
if (result.status === "success") {
const contextItems = result.content.contextItems;
dispatch(setToolCallOutput(contextItems));
// Send to the LLM to continue the conversation
dispatch(
streamResponseAfterToolCall({