diff --git a/core/index.d.ts b/core/index.d.ts index 1dfcbb1fd..26421368c 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -914,6 +914,9 @@ export interface Tool { parameters?: Record; strict?: boolean | null; }; + + displayTitle: string; + wouldLikeTo: string; } interface BaseCompletionOptions { diff --git a/core/tools/definitions/createNewFile.ts b/core/tools/definitions/createNewFile.ts index 2a113865f..1123de217 100644 --- a/core/tools/definitions/createNewFile.ts +++ b/core/tools/definitions/createNewFile.ts @@ -3,6 +3,8 @@ import { BuiltInToolNames } from "../builtIn"; export const createNewFileTool: Tool = { type: "function", + displayTitle: "Create New File", + wouldLikeTo: "create a new file", function: { name: BuiltInToolNames.CreateNewFile, description: "Create a new file", diff --git a/core/tools/definitions/exactSearch.ts b/core/tools/definitions/exactSearch.ts index 14986eb90..5e55c8667 100644 --- a/core/tools/definitions/exactSearch.ts +++ b/core/tools/definitions/exactSearch.ts @@ -3,6 +3,8 @@ import { BuiltInToolNames } from "../builtIn"; export const exactSearchTool: Tool = { type: "function", + displayTitle: "Exact Search", + wouldLikeTo: "search for a specific term within the repository", function: { name: BuiltInToolNames.ExactSearch, description: "Perform an exact search over the repository using ripgrep", diff --git a/core/tools/definitions/runTerminalCommand.ts b/core/tools/definitions/runTerminalCommand.ts index 4af56955a..b3c40ca32 100644 --- a/core/tools/definitions/runTerminalCommand.ts +++ b/core/tools/definitions/runTerminalCommand.ts @@ -4,6 +4,8 @@ import { BuiltInToolNames } from "../builtIn"; export const runTerminalCommandTool: Tool = { type: "function", + displayTitle: "Run Terminal Command", + wouldLikeTo: "run a terminal command", function: { name: BuiltInToolNames.RunTerminalCommand, description: "Run a terminal command in the current directory", diff --git a/core/tools/definitions/searchWeb.ts b/core/tools/definitions/searchWeb.ts index 12aeaefa9..c8ead3c28 100644 --- a/core/tools/definitions/searchWeb.ts +++ b/core/tools/definitions/searchWeb.ts @@ -4,6 +4,8 @@ import { BuiltInToolNames } from "../builtIn"; export const searchWebTool: Tool = { type: "function", + displayTitle: "Search Web", + wouldLikeTo: "search the web", function: { name: BuiltInToolNames.SearchWeb, description: diff --git a/core/tools/definitions/viewDiff.ts b/core/tools/definitions/viewDiff.ts index 4e88bcb9e..554f49878 100644 --- a/core/tools/definitions/viewDiff.ts +++ b/core/tools/definitions/viewDiff.ts @@ -4,6 +4,8 @@ import { BuiltInToolNames } from "../builtIn"; export const viewDiffTool: Tool = { type: "function", + displayTitle: "View Diff", + wouldLikeTo: "view a diff", function: { name: BuiltInToolNames.ViewDiff, description: "View the current diff of working changes", diff --git a/core/tools/definitions/viewRepoMap.ts b/core/tools/definitions/viewRepoMap.ts index bb009486a..aca91a78b 100644 --- a/core/tools/definitions/viewRepoMap.ts +++ b/core/tools/definitions/viewRepoMap.ts @@ -4,6 +4,8 @@ import { BuiltInToolNames } from "../builtIn"; export const viewRepoMapTool: Tool = { type: "function", + displayTitle: "View Repo Map", + wouldLikeTo: "view the repository map", function: { name: BuiltInToolNames.ViewRepoMap, description: "View the repository map", diff --git a/core/tools/definitions/viewSubdirectory.ts b/core/tools/definitions/viewSubdirectory.ts index 40bce4850..4ac1b5c40 100644 --- a/core/tools/definitions/viewSubdirectory.ts +++ b/core/tools/definitions/viewSubdirectory.ts @@ -4,6 +4,8 @@ import { BuiltInToolNames } from "../builtIn"; export const viewSubdirectoryTool: Tool = { type: "function", + displayTitle: "View Subdirectory", + wouldLikeTo: "view the contents of a subdirectory", function: { name: BuiltInToolNames.ViewSubdirectory, description: "View the contents of a subdirectory", diff --git a/gui/src/components/mainInput/InputToolbar/ToggleToolsButton.tsx b/gui/src/components/mainInput/InputToolbar/ToggleToolsButton.tsx index d91642216..6433959b8 100644 --- a/gui/src/components/mainInput/InputToolbar/ToggleToolsButton.tsx +++ b/gui/src/components/mainInput/InputToolbar/ToggleToolsButton.tsx @@ -1,11 +1,12 @@ import { Listbox } from "@headlessui/react"; import { ChevronDownIcon, + ChevronUpIcon, WrenchScrewdriverIcon, } from "@heroicons/react/24/outline"; import { modelSupportsTools } from "core/llm/autodetect"; import { allTools } from "core/tools/index"; -import { useRef } from "react"; +import { useRef, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; import styled from "styled-components"; import { defaultBorderRadius, lightGray, vscForeground } from "../.."; @@ -14,6 +15,7 @@ import { toggleUseTools } from "../../../redux/slices/uiStateSlice"; import { RootState } from "../../../redux/store"; import { getFontSize } from "../../../util"; import HoverItem from "./HoverItem"; +import ToolDropdownItem from "./ToolDropdownItem"; const BackgroundDiv = styled.div<{ useTools: boolean }>` background-color: ${(props) => @@ -34,6 +36,7 @@ const BackgroundDiv = styled.div<{ useTools: boolean }>` export default function ToolDropdown() { const buttonRef = useRef(null); const dispatch = useDispatch(); + const [isDropdownOpen, setDropdownOpen] = useState(false); const useTools = useSelector((store: RootState) => store.uiState.useTools); const defaultModel = useSelector(defaultModelSelector); @@ -63,18 +66,24 @@ export default function ToolDropdown() { ref={buttonRef} onClick={(e) => { e.stopPropagation(); + setDropdownOpen((prev) => !prev); }} className="text-lightgray flex cursor-pointer items-center border-none bg-transparent outline-none" > - + {isDropdownOpen ? ( + + ) : ( + + )} {allTools.map((tool) => ( - {tool.function.name} + ))} diff --git a/gui/src/components/mainInput/InputToolbar/ToolDropdownItem.tsx b/gui/src/components/mainInput/InputToolbar/ToolDropdownItem.tsx new file mode 100644 index 000000000..e137c18dc --- /dev/null +++ b/gui/src/components/mainInput/InputToolbar/ToolDropdownItem.tsx @@ -0,0 +1,46 @@ +import { Tool } from "core"; +import { useDispatch, useSelector } from "react-redux"; +import { + DEFAULT_TOOL_SETTING, + toggleToolSetting, +} from "../../../redux/slices/uiStateSlice"; +import { RootState } from "../../../redux/store"; + +interface ToolDropdownItemProps { + tool: Tool; +} + +function ToolDropdownItem(props: ToolDropdownItemProps) { + const dispatch = useDispatch(); + const settings = useSelector( + (state: RootState) => + state.uiState.toolSettings[props.tool.function.name] ?? + DEFAULT_TOOL_SETTING, + ); + + return ( +
{ + dispatch(toggleToolSetting(props.tool.function.name)); + e.stopPropagation(); + e.preventDefault(); + }} + > + {props.tool.displayTitle} +
+ {(settings === "allowedWithPermission" || settings === undefined) && ( + Allowed + )} + {settings === "allowedWithoutPermission" && ( + Automatic + )} + {settings === "disabled" && ( + Disabled + )} +
+
+ ); +} + +export default ToolDropdownItem; diff --git a/gui/src/pages/gui/ToolCallDiv/FunctionSpecificHeader.tsx b/gui/src/pages/gui/ToolCallDiv/FunctionSpecificHeader.tsx deleted file mode 100644 index 896e9f81a..000000000 --- a/gui/src/pages/gui/ToolCallDiv/FunctionSpecificHeader.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import { ToolCall } from "core"; -import { incrementalParseJson } from "core/util/incrementalParseJson"; - -interface FunctionSpecificHeaderProps { - toolCall: ToolCall; -} - -export function FunctionSpecificHeader(props: FunctionSpecificHeaderProps) { - const [done, incrementalJson] = incrementalParseJson( - props.toolCall.function.arguments, - ); - - let message; - - switch (props.toolCall.function.name) { - case "create_new_file": - message = "Continue wants to write to a file"; - break; - case "run_terminal_command": - message = "Continue wants to run a terminal command."; - break; - case "exact_search": - message = "Continue wants to search your codebase"; - break; - case "search_web": - message = "Continue wants to search the internet"; - break; - case "view_diff": - message = "Continue wants to view the current git diff"; - break; - case "view_repo_map": - message = "Continue wants to view a map of your repository"; - break; - case "view_subdirectory": - message = `Continue wants to view the contents of ${incrementalJson.directory_path ?? "a subdirectory"}`; - break; - default: - message = `Continue wants to use the ${props.toolCall.function.name} function.`; - } - - return
{message}
; -} diff --git a/gui/src/pages/gui/ToolCallDiv/ThreadDiv.tsx b/gui/src/pages/gui/ToolCallDiv/ThreadDiv.tsx index de20f6437..12f28eea8 100644 --- a/gui/src/pages/gui/ToolCallDiv/ThreadDiv.tsx +++ b/gui/src/pages/gui/ToolCallDiv/ThreadDiv.tsx @@ -1,6 +1,6 @@ import { ToolCall } from "core"; +import { allTools } from "core/tools"; import styled from "styled-components"; -import { FunctionSpecificHeader } from "./FunctionSpecificHeader"; interface ThreadDivProps { children: React.ReactNode; @@ -42,7 +42,12 @@ export function ThreadDiv(props: ThreadDivProps) { > {props.icon} - + Continue wants to{" "} + { + allTools.find( + (tool) => props.toolCall.function.name === tool.function.name, + )?.wouldLikeTo + } {props.children} diff --git a/gui/src/redux/slices/uiStateSlice.ts b/gui/src/redux/slices/uiStateSlice.ts index a31f36d66..3d88c5435 100644 --- a/gui/src/redux/slices/uiStateSlice.ts +++ b/gui/src/redux/slices/uiStateSlice.ts @@ -4,6 +4,11 @@ import { OnboardingCardState, } from "../../components/OnboardingCard"; +type ToolSetting = + | "allowedWithPermission" + | "allowedWithoutPermission" + | "disabled"; + type UiState = { showDialog: boolean; dialogMessage: string | JSX.Element | undefined; @@ -11,8 +16,11 @@ type UiState = { onboardingCard: OnboardingCardState; shouldAddFileForEditing: boolean; useTools: boolean; + toolSettings: { [toolName: string]: ToolSetting }; }; +export const DEFAULT_TOOL_SETTING: ToolSetting = "allowedWithPermission"; + export const uiStateSlice = createSlice({ name: "uiState", initialState: { @@ -21,7 +29,9 @@ export const uiStateSlice = createSlice({ dialogEntryOn: false, onboardingCard: defaultOnboardingCardState, shouldAddFileForEditing: false, + useTools: false, + toolSettings: {}, } as UiState, reducers: { setOnboardingCard: ( @@ -51,9 +61,29 @@ export const uiStateSlice = createSlice({ ) => { state.shouldAddFileForEditing = action.payload; }, + + // Tools toggleUseTools: (state) => { state.useTools = !state.useTools; }, + toggleToolSetting: (state, action: PayloadAction) => { + const setting = state.toolSettings[action.payload]; + + switch (setting) { + case "allowedWithPermission": + state.toolSettings[action.payload] = "allowedWithoutPermission"; + break; + case "allowedWithoutPermission": + state.toolSettings[action.payload] = "disabled"; + break; + case "disabled": + state.toolSettings[action.payload] = "allowedWithPermission"; + break; + default: + state.toolSettings[action.payload] = DEFAULT_TOOL_SETTING; + break; + } + }, }, }); @@ -64,6 +94,7 @@ export const { setShowDialog, setShouldAddFileForEditing, toggleUseTools, + toggleToolSetting, } = uiStateSlice.actions; export default uiStateSlice.reducer;