tool settings ui
This commit is contained in:
parent
025dc0840d
commit
e6d7f5b511
13 changed files with 114 additions and 48 deletions
3
core/index.d.ts
vendored
3
core/index.d.ts
vendored
|
|
@ -914,6 +914,9 @@ export interface Tool {
|
|||
parameters?: Record<string, any>;
|
||||
strict?: boolean | null;
|
||||
};
|
||||
|
||||
displayTitle: string;
|
||||
wouldLikeTo: string;
|
||||
}
|
||||
|
||||
interface BaseCompletionOptions {
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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<HTMLButtonElement>(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"
|
||||
>
|
||||
<ChevronDownIcon className="h-3 w-3" />
|
||||
{isDropdownOpen ? (
|
||||
<ChevronUpIcon className="h-3 w-3" />
|
||||
) : (
|
||||
<ChevronDownIcon className="h-3 w-3" />
|
||||
)}
|
||||
</Listbox.Button>
|
||||
<Listbox.Options className="bg-vsc-editor-background border-lightgray/50 absolute right-0 top-full z-50 mt-1 min-w-fit whitespace-nowrap rounded-md border border-solid px-1 py-0 shadow-lg">
|
||||
{allTools.map((tool) => (
|
||||
<Listbox.Option
|
||||
key={tool.function.name}
|
||||
value="addAllFiles"
|
||||
className="text-vsc-foreground block w-full cursor-pointer px-2 py-1 text-left text-[10px] brightness-75 hover:brightness-125"
|
||||
className="text-vsc-foreground block w-full cursor-pointer text-left text-[10px] brightness-75 hover:brightness-125"
|
||||
>
|
||||
{tool.function.name}
|
||||
<ToolDropdownItem tool={tool} />
|
||||
</Listbox.Option>
|
||||
))}
|
||||
</Listbox.Options>
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<div
|
||||
className="flex w-full items-center justify-between gap-2 px-2 py-1"
|
||||
onClick={(e) => {
|
||||
dispatch(toggleToolSetting(props.tool.function.name));
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}}
|
||||
>
|
||||
<span>{props.tool.displayTitle}</span>
|
||||
<div className="flex gap-2 pr-4">
|
||||
{(settings === "allowedWithPermission" || settings === undefined) && (
|
||||
<span className="text-yellow-500">Allowed</span>
|
||||
)}
|
||||
{settings === "allowedWithoutPermission" && (
|
||||
<span className="text-green-500">Automatic</span>
|
||||
)}
|
||||
{settings === "disabled" && (
|
||||
<span className="text-red-500">Disabled</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default ToolDropdownItem;
|
||||
|
|
@ -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 <div>{message}</div>;
|
||||
}
|
||||
|
|
@ -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}
|
||||
</div>
|
||||
<FunctionSpecificHeader toolCall={props.toolCall} />
|
||||
Continue wants to{" "}
|
||||
{
|
||||
allTools.find(
|
||||
(tool) => props.toolCall.function.name === tool.function.name,
|
||||
)?.wouldLikeTo
|
||||
}
|
||||
</HeaderDiv>
|
||||
<ChildrenDiv>{props.children}</ChildrenDiv>
|
||||
</Container>
|
||||
|
|
|
|||
|
|
@ -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<string>) => {
|
||||
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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue