Merge pull request #5227 from continuedev/nate/mcp-ui
refactor toggle div
This commit is contained in:
commit
cf92d03a4f
26 changed files with 356 additions and 264 deletions
2
.github/workflows/pr_checks.yaml
vendored
2
.github/workflows/pr_checks.yaml
vendored
|
|
@ -4,12 +4,10 @@ on:
|
|||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
- staging
|
||||
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- staging
|
||||
|
||||
jobs:
|
||||
install-root:
|
||||
|
|
|
|||
6
core/index.d.ts
vendored
6
core/index.d.ts
vendored
|
|
@ -966,7 +966,10 @@ export interface ToolExtras {
|
|||
fetch: FetchFunction;
|
||||
tool: Tool;
|
||||
toolCallId?: string;
|
||||
onPartialOutput?: (params: { toolCallId: string, contextItems: ContextItem[] }) => void;
|
||||
onPartialOutput?: (params: {
|
||||
toolCallId: string;
|
||||
contextItems: ContextItem[];
|
||||
}) => void;
|
||||
}
|
||||
|
||||
export interface Tool {
|
||||
|
|
@ -983,6 +986,7 @@ export interface Tool {
|
|||
isCurrently?: string;
|
||||
hasAlready?: string;
|
||||
readonly: boolean;
|
||||
isInstant?: boolean;
|
||||
uri?: string;
|
||||
faviconUrl?: string;
|
||||
group: string;
|
||||
|
|
|
|||
2
core/package-lock.json
generated
2
core/package-lock.json
generated
|
|
@ -134,7 +134,7 @@
|
|||
},
|
||||
"../packages/config-yaml": {
|
||||
"name": "@continuedev/config-yaml",
|
||||
"version": "1.0.78",
|
||||
"version": "1.0.87",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@continuedev/config-types": "^1.0.14",
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ export const createNewFileTool: Tool = {
|
|||
hasAlready: "created a new file at {{{ filepath }}}",
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
readonly: false,
|
||||
isInstant: true,
|
||||
function: {
|
||||
name: BuiltInToolNames.CreateNewFile,
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ export const createRuleBlock: Tool = {
|
|||
isCurrently: 'creating a rule block for "{{{ rule_name }}}"',
|
||||
hasAlready: 'created a rule block for "{{{ rule_name }}}"',
|
||||
readonly: false,
|
||||
isInstant: true,
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
function: {
|
||||
name: BuiltInToolNames.CreateRuleBlock,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ export const globSearchTool: Tool = {
|
|||
isCurrently: 'finding file matches for "{{{ pattern }}}"',
|
||||
hasAlready: 'retreived file matches for "{{{ pattern }}}"',
|
||||
readonly: true,
|
||||
isInstant: true,
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
function: {
|
||||
name: BuiltInToolNames.FileGlobSearch,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ export const grepSearchTool: Tool = {
|
|||
isCurrently: 'getting search results for "{{{ query }}}"',
|
||||
hasAlready: 'retrieved search results for "{{{ query }}}"',
|
||||
readonly: true,
|
||||
isInstant: true,
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
function: {
|
||||
name: BuiltInToolNames.GrepSearch,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ export const lsTool: Tool = {
|
|||
isCurrently: "listing files and folders in {{{ dirPath }}}",
|
||||
hasAlready: "listed files and folders in {{{ dirPath }}}",
|
||||
readonly: true,
|
||||
isInstant: true,
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
function: {
|
||||
name: BuiltInToolNames.LSTool,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ export const readCurrentlyOpenFileTool: Tool = {
|
|||
isCurrently: "reading the current file",
|
||||
hasAlready: "viewed the current file",
|
||||
readonly: true,
|
||||
isInstant: true,
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
function: {
|
||||
name: BuiltInToolNames.ReadCurrentlyOpenFile,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ export const readFileTool: Tool = {
|
|||
isCurrently: "reading {{{ filepath }}}",
|
||||
hasAlready: "viewed {{{ filepath }}}",
|
||||
readonly: true,
|
||||
isInstant: true,
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
function: {
|
||||
name: BuiltInToolNames.ReadFile,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ export const viewDiffTool: Tool = {
|
|||
isCurrently: "getting the git diff",
|
||||
hasAlready: "viewed the git diff",
|
||||
readonly: true,
|
||||
isInstant: true,
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
function: {
|
||||
name: BuiltInToolNames.ViewDiff,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ export const viewRepoMapTool: Tool = {
|
|||
isCurrently: "getting the repository map",
|
||||
hasAlready: "viewed the repository map",
|
||||
readonly: true,
|
||||
isInstant: true,
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
function: {
|
||||
name: BuiltInToolNames.ViewRepoMap,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ export const viewSubdirectoryTool: Tool = {
|
|||
hasAlready: 'viewed a map of "{{{ directory_path }}}"',
|
||||
readonly: true,
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
isInstant: true,
|
||||
function: {
|
||||
name: BuiltInToolNames.ViewSubdirectory,
|
||||
description: "View the contents of a subdirectory",
|
||||
|
|
|
|||
|
|
@ -46,10 +46,7 @@ export class GUISelectors {
|
|||
}
|
||||
|
||||
public static getToolCallStatusMessage(view: WebView) {
|
||||
return SelectorUtils.getElementByDataTestId(
|
||||
view,
|
||||
"tool-call-status-message",
|
||||
);
|
||||
return SelectorUtils.getElementByDataTestId(view, "toggle-div-title");
|
||||
}
|
||||
|
||||
public static getToolButton(view: WebView) {
|
||||
|
|
|
|||
2
gui/package-lock.json
generated
2
gui/package-lock.json
generated
|
|
@ -206,7 +206,7 @@
|
|||
},
|
||||
"../packages/config-yaml": {
|
||||
"name": "@continuedev/config-yaml",
|
||||
"version": "1.0.78",
|
||||
"version": "1.0.87",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@continuedev/config-types": "^1.0.14",
|
||||
|
|
|
|||
66
gui/src/components/ToggleDiv.tsx
Normal file
66
gui/src/components/ToggleDiv.tsx
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import { ChevronDownIcon, ChevronRightIcon } from "@heroicons/react/24/outline";
|
||||
import { ComponentType, useState } from "react";
|
||||
import { lightGray, vscBackground } from ".";
|
||||
|
||||
interface ToggleProps {
|
||||
children: React.ReactNode;
|
||||
title: React.ReactNode;
|
||||
icon?: ComponentType<React.SVGProps<SVGSVGElement>>;
|
||||
}
|
||||
|
||||
function ToggleDiv({ children, title, icon: Icon }: ToggleProps) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [isHovered, setIsHovered] = useState(false);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`pl-2 pt-2`}
|
||||
style={{
|
||||
backgroundColor: vscBackground,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="flex cursor-pointer items-center justify-start text-xs text-gray-300"
|
||||
onClick={() => setOpen((prev) => !prev)}
|
||||
onMouseEnter={() => setIsHovered(true)}
|
||||
onMouseLeave={() => setIsHovered(false)}
|
||||
data-testid="context-items-peek"
|
||||
>
|
||||
<div className="relative mr-1 h-4 w-4">
|
||||
{Icon && !isHovered && !open ? (
|
||||
<Icon className={`absolute h-4 w-4 text-[${lightGray}]`} />
|
||||
) : (
|
||||
<>
|
||||
<ChevronRightIcon
|
||||
className={`absolute h-4 w-4 transition-all duration-200 ease-in-out text-[${lightGray}] ${
|
||||
open ? "rotate-90 opacity-0" : "rotate-0 opacity-100"
|
||||
}`}
|
||||
/>
|
||||
<ChevronDownIcon
|
||||
className={`absolute h-4 w-4 transition-all duration-200 ease-in-out text-[${lightGray}] ${
|
||||
open ? "rotate-0 opacity-100" : "-rotate-90 opacity-0"
|
||||
}`}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<span
|
||||
className="ml-1 text-xs text-gray-400 transition-colors duration-200"
|
||||
data-testid="toggle-div-title"
|
||||
>
|
||||
{title}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className={`mt-2 overflow-y-auto transition-all duration-300 ease-in-out ${
|
||||
open ? "max-h-[50vh] opacity-100" : "max-h-0 opacity-0"
|
||||
}`}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default ToggleDiv;
|
||||
|
|
@ -3,14 +3,7 @@ import { InputModifiers } from "core";
|
|||
import { modelSupportsImages, modelSupportsTools } from "core/llm/autodetect";
|
||||
import { useRef } from "react";
|
||||
import styled from "styled-components";
|
||||
import {
|
||||
defaultBorderRadius,
|
||||
lightGray,
|
||||
vscButtonBackground,
|
||||
vscButtonForeground,
|
||||
vscForeground,
|
||||
vscInputBackground,
|
||||
} from "..";
|
||||
import { vscInputBackground } from "..";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
import { selectUseActiveFile } from "../../redux/selectors";
|
||||
import { selectCurrentToolCall } from "../../redux/selectors/selectCurrentToolCall";
|
||||
|
|
@ -31,6 +24,7 @@ import { ToolTip } from "../gui/Tooltip";
|
|||
import ModelSelect from "../modelSelection/ModelSelect";
|
||||
import ModeSelect from "../modelSelection/ModeSelect";
|
||||
import { useFontSize } from "../ui/font";
|
||||
import { EnterButton } from "./InputToolbar/EnterButton";
|
||||
import HoverItem from "./InputToolbar/HoverItem";
|
||||
|
||||
const StyledDiv = styled.div<{ isHidden?: boolean }>`
|
||||
|
|
@ -50,25 +44,6 @@ const StyledDiv = styled.div<{ isHidden?: boolean }>`
|
|||
}
|
||||
`;
|
||||
|
||||
const EnterButton = styled.button<{ isPrimary?: boolean }>`
|
||||
all: unset;
|
||||
padding: 2px 4px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background-color: ${(props) =>
|
||||
!props.disabled && props.isPrimary
|
||||
? vscButtonBackground
|
||||
: lightGray + "33"};
|
||||
border-radius: ${defaultBorderRadius};
|
||||
color: ${(props) =>
|
||||
!props.disabled && props.isPrimary ? vscButtonForeground : vscForeground};
|
||||
cursor: pointer;
|
||||
|
||||
:disabled {
|
||||
cursor: wait;
|
||||
}
|
||||
`;
|
||||
|
||||
export interface ToolbarOptions {
|
||||
hideUseCodebase?: boolean;
|
||||
hideImageUpload?: boolean;
|
||||
|
|
|
|||
29
gui/src/components/mainInput/InputToolbar/EnterButton.tsx
Normal file
29
gui/src/components/mainInput/InputToolbar/EnterButton.tsx
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import styled from "styled-components";
|
||||
import {
|
||||
defaultBorderRadius,
|
||||
lightGray,
|
||||
vscButtonBackground,
|
||||
vscButtonForeground,
|
||||
vscForeground,
|
||||
} from "../..";
|
||||
import { fontSize } from "../../../util";
|
||||
|
||||
export const EnterButton = styled.button<{ isPrimary?: boolean }>`
|
||||
all: unset;
|
||||
font-size: ${fontSize(-3)};
|
||||
padding: 2px 4px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background-color: ${(props) =>
|
||||
!props.disabled && props.isPrimary
|
||||
? vscButtonBackground
|
||||
: lightGray + "33"};
|
||||
border-radius: ${defaultBorderRadius};
|
||||
color: ${(props) =>
|
||||
!props.disabled && props.isPrimary ? vscButtonForeground : vscForeground};
|
||||
cursor: pointer;
|
||||
|
||||
:disabled {
|
||||
cursor: wait;
|
||||
}
|
||||
`;
|
||||
|
|
@ -1,10 +1,15 @@
|
|||
import { useContext } from "react";
|
||||
import { useContext, useEffect } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import styled from "styled-components";
|
||||
import { AnimatedEllipsis } from "../..";
|
||||
import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
||||
import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
|
||||
import { selectCurrentToolCall } from "../../../redux/selectors/selectCurrentToolCall";
|
||||
import { callTool } from "../../../redux/thunks/callTool";
|
||||
import { cancelStream } from "../../../redux/thunks/cancelStream";
|
||||
import { cancelTool } from "../../../redux/thunks/cancelTool";
|
||||
import { getFontSize, getMetaKeyLabel } from "../../../util";
|
||||
import { EnterButton } from "../InputToolbar/EnterButton";
|
||||
import { BlockSettingsTopToolbar } from "./BlockSettingsTopToolbar";
|
||||
|
||||
const Container = styled.div`
|
||||
|
|
@ -36,6 +41,31 @@ export function LumpToolbar() {
|
|||
const ttsActive = useAppSelector((state) => state.ui.ttsActive);
|
||||
const isStreaming = useAppSelector((state) => state.session.isStreaming);
|
||||
|
||||
const toolCallState = useSelector(selectCurrentToolCall);
|
||||
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (toolCallState?.status === "generated") {
|
||||
const metaKey = event.metaKey || event.ctrlKey;
|
||||
|
||||
if (metaKey && event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
dispatch(callTool());
|
||||
} else if (metaKey && event.key === "Backspace") {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
dispatch(cancelTool());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
document.addEventListener("keydown", handleKeyDown);
|
||||
return () => {
|
||||
document.removeEventListener("keydown", handleKeyDown);
|
||||
};
|
||||
}, [toolCallState]);
|
||||
|
||||
if (ttsActive) {
|
||||
return (
|
||||
<Container>
|
||||
|
|
@ -68,5 +98,31 @@ export function LumpToolbar() {
|
|||
);
|
||||
}
|
||||
|
||||
if (toolCallState?.status === "generated") {
|
||||
return (
|
||||
<Container>
|
||||
<GeneratingIndicator />
|
||||
|
||||
<div className="flex gap-2 pb-0.5">
|
||||
<StopButton
|
||||
className="text-gray-400"
|
||||
onClick={() => dispatch(cancelTool())}
|
||||
data-testid="reject-tool-call-button"
|
||||
>
|
||||
{getMetaKeyLabel()} ⌫ Cancel
|
||||
</StopButton>
|
||||
<EnterButton
|
||||
isPrimary={true}
|
||||
className="text-gray-400"
|
||||
onClick={() => dispatch(callTool())}
|
||||
data-testid="accept-tool-call-button"
|
||||
>
|
||||
{getMetaKeyLabel()} ⏎ Continue
|
||||
</EnterButton>
|
||||
</div>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return <BlockSettingsTopToolbar />;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,24 @@
|
|||
import {
|
||||
ArrowTopRightOnSquareIcon,
|
||||
ChevronDownIcon,
|
||||
ChevronRightIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { ArrowTopRightOnSquareIcon } from "@heroicons/react/24/outline";
|
||||
import { ContextItemWithId } from "core";
|
||||
import { ctxItemToRifWithContents } from "core/commands/util";
|
||||
import { getUriPathBasename } from "core/util/uri";
|
||||
import { useContext, useMemo, useState } from "react";
|
||||
import { AnimatedEllipsis, lightGray, vscBackground } from "../..";
|
||||
import { ComponentType, useContext, useMemo } from "react";
|
||||
import { AnimatedEllipsis } from "../..";
|
||||
import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
||||
import { useAppSelector } from "../../../redux/hooks";
|
||||
import { selectIsGatheringContext } from "../../../redux/slices/sessionSlice";
|
||||
import FileIcon from "../../FileIcon";
|
||||
import SafeImg from "../../SafeImg";
|
||||
import ToggleDiv from "../../ToggleDiv";
|
||||
import { getIconFromDropdownItem } from "../AtMentionDropdown";
|
||||
import { NAMED_ICONS } from "../icons";
|
||||
|
||||
interface ContextItemsPeekProps {
|
||||
contextItems?: ContextItemWithId[];
|
||||
isCurrentContextPeek: boolean;
|
||||
icon?: ComponentType<React.SVGProps<SVGSVGElement>>;
|
||||
title?: JSX.Element | string;
|
||||
showWhenNoResults?: boolean;
|
||||
}
|
||||
|
||||
interface ContextItemsPeekItemProps {
|
||||
|
|
@ -153,9 +153,10 @@ function ContextItemsPeekItem({ contextItem }: ContextItemsPeekItemProps) {
|
|||
function ContextItemsPeek({
|
||||
contextItems,
|
||||
isCurrentContextPeek,
|
||||
icon,
|
||||
title,
|
||||
showWhenNoResults,
|
||||
}: ContextItemsPeekProps) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const ctxItems = useMemo(() => {
|
||||
return contextItems?.filter((ctxItem) => !ctxItem.hidden) ?? [];
|
||||
}, [contextItems]);
|
||||
|
|
@ -164,59 +165,37 @@ function ContextItemsPeek({
|
|||
|
||||
const indicateIsGathering = isCurrentContextPeek && isGatheringContext;
|
||||
|
||||
if ((!ctxItems || ctxItems.length === 0) && !indicateIsGathering) {
|
||||
if (
|
||||
!showWhenNoResults &&
|
||||
(!ctxItems || ctxItems.length === 0) &&
|
||||
!indicateIsGathering
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`pl-2 pt-2`}
|
||||
style={{
|
||||
backgroundColor: vscBackground,
|
||||
}}
|
||||
<ToggleDiv
|
||||
icon={icon}
|
||||
title={
|
||||
title ??
|
||||
(isGatheringContext ? (
|
||||
<>
|
||||
Gathering context
|
||||
<AnimatedEllipsis />
|
||||
</>
|
||||
) : (
|
||||
`${ctxItems.length} context ${ctxItems.length > 1 ? "items" : "item"}`
|
||||
))
|
||||
}
|
||||
>
|
||||
<div
|
||||
className="flex cursor-pointer items-center justify-start text-xs text-gray-300"
|
||||
onClick={() => setOpen((prev) => !prev)}
|
||||
data-testid="context-items-peek"
|
||||
>
|
||||
<div className="relative mr-1 h-4 w-4">
|
||||
<ChevronRightIcon
|
||||
className={`absolute h-4 w-4 transition-all duration-200 ease-in-out text-[${lightGray}] ${
|
||||
open ? "rotate-90 opacity-0" : "rotate-0 opacity-100"
|
||||
}`}
|
||||
/>
|
||||
<ChevronDownIcon
|
||||
className={`absolute h-4 w-4 transition-all duration-200 ease-in-out text-[${lightGray}] ${
|
||||
open ? "rotate-0 opacity-100" : "-rotate-90 opacity-0"
|
||||
}`}
|
||||
/>
|
||||
</div>
|
||||
<span className="ml-1 text-xs text-gray-400 transition-colors duration-200">
|
||||
{isGatheringContext ? (
|
||||
<>
|
||||
Gathering context
|
||||
<AnimatedEllipsis />
|
||||
</>
|
||||
) : (
|
||||
`${ctxItems.length} context ${
|
||||
ctxItems.length > 1 ? "items" : "item"
|
||||
}`
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className={`mt-2 overflow-y-auto transition-all duration-300 ease-in-out ${
|
||||
open ? "max-h-[50vh] opacity-100" : "max-h-0 opacity-0"
|
||||
}`}
|
||||
>
|
||||
{ctxItems &&
|
||||
ctxItems.map((contextItem, idx) => (
|
||||
<ContextItemsPeekItem key={idx} contextItem={contextItem} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
{ctxItems.length ? (
|
||||
ctxItems.map((contextItem, idx) => (
|
||||
<ContextItemsPeekItem key={idx} contextItem={contextItem} />
|
||||
))
|
||||
) : (
|
||||
<div className="pl-2 text-xs italic text-gray-400">No results</div>
|
||||
)}
|
||||
</ToggleDiv>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ import {
|
|||
newSession,
|
||||
selectIsInEditMode,
|
||||
selectIsSingleRangeEditOrInsertion,
|
||||
updateToolCallOutput
|
||||
updateToolCallOutput,
|
||||
} from "../../redux/slices/sessionSlice";
|
||||
import {
|
||||
setDialogEntryOn,
|
||||
|
|
@ -58,8 +58,6 @@ import { getLocalStorage, setLocalStorage } from "../../util/localStorage";
|
|||
import { EmptyChatBody } from "./EmptyChatBody";
|
||||
import { ExploreDialogWatcher } from "./ExploreDialogWatcher";
|
||||
import { ToolCallDiv } from "./ToolCallDiv";
|
||||
import { ToolCallButtons } from "./ToolCallDiv/ToolCallButtonsDiv";
|
||||
import ToolOutput from "./ToolCallDiv/ToolOutput";
|
||||
import { useAutoScroll } from "./useAutoScroll";
|
||||
|
||||
const StepsDiv = styled.div`
|
||||
|
|
@ -277,13 +275,13 @@ export function Chat() {
|
|||
useWebviewListener(
|
||||
"toolCallPartialOutput",
|
||||
async (data) => {
|
||||
// Update tool call output in Redux store
|
||||
dispatch(
|
||||
updateToolCallOutput({
|
||||
toolCallId: data.toolCallId,
|
||||
contextItems: data.contextItems,
|
||||
}),
|
||||
);
|
||||
// Update tool call output in Redux store
|
||||
dispatch(
|
||||
updateToolCallOutput({
|
||||
toolCallId: data.toolCallId,
|
||||
contextItems: data.contextItems,
|
||||
}),
|
||||
);
|
||||
},
|
||||
[dispatch],
|
||||
);
|
||||
|
|
@ -342,12 +340,11 @@ export function Chat() {
|
|||
inputId={item.message.id}
|
||||
/>
|
||||
</>
|
||||
) : item.message.role === "tool" ? (
|
||||
<ToolOutput
|
||||
contextItems={item.contextItems}
|
||||
toolCallId={item.message.toolCallId}
|
||||
/>
|
||||
) : item.message.role === "assistant" &&
|
||||
) : item.message.role === "tool" ? null : // <ToolOutput
|
||||
// contextItems={item.contextItems}
|
||||
// toolCallId={item.message.toolCallId}
|
||||
// />
|
||||
item.message.role === "assistant" &&
|
||||
item.message.toolCalls &&
|
||||
item.toolCallState ? (
|
||||
<div>
|
||||
|
|
@ -357,6 +354,7 @@ export function Chat() {
|
|||
<ToolCallDiv
|
||||
toolCallState={item.toolCallState!}
|
||||
toolCall={toolCall}
|
||||
output={history[index + 1]?.contextItems}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
|
@ -410,8 +408,6 @@ export function Chat() {
|
|||
))}
|
||||
</StepsDiv>
|
||||
<div className={"relative"}>
|
||||
{toolCallState?.status === "generated" && <ToolCallButtons />}
|
||||
|
||||
{isInEditMode && history.length === 0 && <CodeToEditCard />}
|
||||
|
||||
{isInEditMode && history.length > 0 ? null : (
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/outline";
|
||||
import { ToolCallDelta, ToolCallState } from "core";
|
||||
import { Tool, ToolCallDelta, ToolCallState } from "core";
|
||||
import Mustache from "mustache";
|
||||
import { ReactNode, useMemo, useState } from "react";
|
||||
import { ToolTip } from "../../../components/gui/Tooltip";
|
||||
|
|
@ -12,6 +12,67 @@ interface ToolCallDisplayProps {
|
|||
toolCallState: ToolCallState;
|
||||
}
|
||||
|
||||
export function getToolCallStatusMessage(
|
||||
tool: Tool | undefined,
|
||||
toolCallState: ToolCallState,
|
||||
) {
|
||||
if (!tool) return "Agent tool use";
|
||||
|
||||
const defaultToolDescription = (
|
||||
<>
|
||||
<code>{tool.displayTitle ?? tool.function.name}</code> <span>tool</span>
|
||||
</>
|
||||
);
|
||||
|
||||
const futureMessage = tool.wouldLikeTo ? (
|
||||
Mustache.render(tool.wouldLikeTo, toolCallState.parsedArgs)
|
||||
) : (
|
||||
<>
|
||||
<span>use the</span> {defaultToolDescription}
|
||||
</>
|
||||
);
|
||||
|
||||
let intro = "";
|
||||
let message: ReactNode = "";
|
||||
|
||||
if (
|
||||
toolCallState.status === "done" ||
|
||||
(tool.isInstant && toolCallState.status === "calling")
|
||||
) {
|
||||
intro = "";
|
||||
message = tool.hasAlready ? (
|
||||
Mustache.render(tool.hasAlready, toolCallState.parsedArgs)
|
||||
) : (
|
||||
<>
|
||||
<span>used the</span> {defaultToolDescription}
|
||||
</>
|
||||
);
|
||||
} else if (toolCallState.status === "generating") {
|
||||
intro = "is generating output to";
|
||||
message = futureMessage;
|
||||
} else if (toolCallState.status === "generated") {
|
||||
intro = "wants to";
|
||||
message = futureMessage;
|
||||
} else if (toolCallState.status === "calling") {
|
||||
intro = "is";
|
||||
message = tool.isCurrently ? (
|
||||
Mustache.render(tool.isCurrently, toolCallState.parsedArgs)
|
||||
) : (
|
||||
<>
|
||||
<span>calling the</span> {defaultToolDescription}
|
||||
</>
|
||||
);
|
||||
} else if (toolCallState.status === "canceled") {
|
||||
intro = "tried to";
|
||||
message = futureMessage;
|
||||
}
|
||||
return (
|
||||
<div className="block">
|
||||
<span>Continue</span> {intro} {message}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function ToolCallDisplay(props: ToolCallDisplayProps) {
|
||||
const [isExpanded, setIsExpanded] = useState(false);
|
||||
const availableTools = useAppSelector((state) => state.config.config.tools);
|
||||
|
|
@ -23,58 +84,7 @@ export function ToolCallDisplay(props: ToolCallDisplayProps) {
|
|||
}, [availableTools, props.toolCall]);
|
||||
|
||||
const statusMessage = useMemo(() => {
|
||||
if (!tool) return "Agent tool use";
|
||||
|
||||
const defaultToolDescription = (
|
||||
<>
|
||||
<code>{tool.displayTitle ?? tool.function.name}</code> <span>tool</span>
|
||||
</>
|
||||
);
|
||||
|
||||
const futureMessage = tool.wouldLikeTo ? (
|
||||
Mustache.render(tool.wouldLikeTo, props.toolCallState.parsedArgs)
|
||||
) : (
|
||||
<>
|
||||
<span>use the</span> {defaultToolDescription}
|
||||
</>
|
||||
);
|
||||
|
||||
let intro = "";
|
||||
let message: ReactNode = "";
|
||||
|
||||
if (props.toolCallState.status === "generating") {
|
||||
intro = "is generating output to";
|
||||
message = futureMessage;
|
||||
} else if (props.toolCallState.status === "generated") {
|
||||
intro = "wants to";
|
||||
message = futureMessage;
|
||||
} else if (props.toolCallState.status === "calling") {
|
||||
intro = "is";
|
||||
message = tool.isCurrently ? (
|
||||
Mustache.render(tool.isCurrently, props.toolCallState.parsedArgs)
|
||||
) : (
|
||||
<>
|
||||
<span>calling the</span> {defaultToolDescription}
|
||||
</>
|
||||
);
|
||||
} else if (props.toolCallState.status === "done") {
|
||||
intro = "";
|
||||
message = tool.hasAlready ? (
|
||||
Mustache.render(tool.hasAlready, props.toolCallState.parsedArgs)
|
||||
) : (
|
||||
<>
|
||||
<span>used the</span> {defaultToolDescription}
|
||||
</>
|
||||
);
|
||||
} else if (props.toolCallState.status === "canceled") {
|
||||
intro = "tried to";
|
||||
message = futureMessage;
|
||||
}
|
||||
return (
|
||||
<div className="block">
|
||||
<span>Continue</span> {intro} {message}
|
||||
</div>
|
||||
);
|
||||
return getToolCallStatusMessage(tool, props.toolCallState);
|
||||
}, [props.toolCallState, tool]);
|
||||
|
||||
const args: [string, any][] = useMemo(() => {
|
||||
|
|
|
|||
|
|
@ -1,97 +0,0 @@
|
|||
import { useSelector } from "react-redux";
|
||||
import styled from "styled-components";
|
||||
import {
|
||||
defaultBorderRadius,
|
||||
lightGray,
|
||||
vscButtonBackground,
|
||||
vscButtonForeground,
|
||||
} from "../../../components";
|
||||
import Spinner from "../../../components/gui/Spinner";
|
||||
import { useAppDispatch } from "../../../redux/hooks";
|
||||
import { selectCurrentToolCall } from "../../../redux/selectors/selectCurrentToolCall";
|
||||
import { callTool } from "../../../redux/thunks/callTool";
|
||||
import { cancelTool } from "../../../redux/thunks/cancelTool";
|
||||
|
||||
const ButtonContainer = styled.div`
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-top: 12px;
|
||||
margin: 8px;
|
||||
`;
|
||||
|
||||
const Button = styled.button`
|
||||
padding: 5px;
|
||||
border-radius: ${defaultBorderRadius};
|
||||
flex: 1;
|
||||
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
opacity: 0.8;
|
||||
}
|
||||
`;
|
||||
|
||||
const AcceptButton = styled(Button)`
|
||||
color: ${vscButtonForeground};
|
||||
border: none;
|
||||
background-color: ${vscButtonBackground};
|
||||
color: ${vscButtonForeground};
|
||||
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
`;
|
||||
|
||||
const RejectButton = styled(Button)`
|
||||
color: ${lightGray};
|
||||
border: 1px solid ${lightGray};
|
||||
background-color: transparent;
|
||||
`;
|
||||
|
||||
interface ToolCallButtonsProps {}
|
||||
|
||||
export function ToolCallButtons(props: ToolCallButtonsProps) {
|
||||
const dispatch = useAppDispatch();
|
||||
const toolCallState = useSelector(selectCurrentToolCall);
|
||||
|
||||
if (!toolCallState) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<ButtonContainer>
|
||||
{toolCallState.status === "generating" ? (
|
||||
<div
|
||||
className="flex w-full items-center justify-center gap-4"
|
||||
style={{
|
||||
color: lightGray,
|
||||
minHeight: "40px",
|
||||
}}
|
||||
>
|
||||
Thinking...
|
||||
</div>
|
||||
) : toolCallState.status === "generated" ? (
|
||||
<>
|
||||
<RejectButton
|
||||
onClick={() => dispatch(cancelTool())}
|
||||
data-testid="reject-tool-call-button"
|
||||
>
|
||||
Cancel
|
||||
</RejectButton>
|
||||
<AcceptButton
|
||||
onClick={() => dispatch(callTool())}
|
||||
data-testid="accept-tool-call-button"
|
||||
>
|
||||
Continue
|
||||
</AcceptButton>
|
||||
</>
|
||||
) : toolCallState.status === "calling" ? (
|
||||
<div className="ml-auto flex items-center gap-4">
|
||||
Loading...
|
||||
<Spinner />
|
||||
</div>
|
||||
) : null}
|
||||
</ButtonContainer>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
import { ContextItemWithId } from "core";
|
||||
import { ComponentType } from "react";
|
||||
import ContextItemsPeek from "../../../components/mainInput/belowMainInput/ContextItemsPeek";
|
||||
|
||||
interface ToolOutputProps {
|
||||
contextItems: ContextItemWithId[];
|
||||
toolCallId: string;
|
||||
icon?: ComponentType;
|
||||
title?: JSX.Element | string;
|
||||
}
|
||||
|
||||
function ToolOutput(props: ToolOutputProps) {
|
||||
|
|
@ -15,6 +18,9 @@ function ToolOutput(props: ToolOutputProps) {
|
|||
return (
|
||||
<div>
|
||||
<ContextItemsPeek
|
||||
showWhenNoResults={true}
|
||||
title={props.title}
|
||||
icon={props.icon}
|
||||
isCurrentContextPeek={false}
|
||||
contextItems={props.contextItems}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -1,19 +1,50 @@
|
|||
import {
|
||||
ArrowRightIcon,
|
||||
CheckIcon,
|
||||
CodeBracketIcon,
|
||||
CommandLineIcon,
|
||||
DocumentIcon,
|
||||
DocumentTextIcon,
|
||||
FolderIcon,
|
||||
FolderOpenIcon,
|
||||
GlobeAltIcon,
|
||||
MagnifyingGlassIcon,
|
||||
MapIcon,
|
||||
XMarkIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { ToolCallDelta, ToolCallState, ToolStatus } from "core";
|
||||
import {
|
||||
ContextItemWithId,
|
||||
ToolCallDelta,
|
||||
ToolCallState,
|
||||
ToolStatus,
|
||||
} from "core";
|
||||
import { BuiltInToolNames } from "core/tools/builtIn";
|
||||
import { ComponentType, useMemo } from "react";
|
||||
import { vscButtonBackground } from "../../../components";
|
||||
import Spinner from "../../../components/gui/Spinner";
|
||||
import { useAppSelector } from "../../../redux/hooks";
|
||||
import FunctionSpecificToolCallDiv from "./FunctionSpecificToolCallDiv";
|
||||
import { ToolCallDisplay } from "./ToolCall";
|
||||
import { getToolCallStatusMessage, ToolCallDisplay } from "./ToolCall";
|
||||
import ToolOutput from "./ToolOutput";
|
||||
|
||||
interface ToolCallDivProps {
|
||||
toolCall: ToolCallDelta;
|
||||
toolCallState: ToolCallState;
|
||||
output?: ContextItemWithId[];
|
||||
}
|
||||
|
||||
const toolCallIcons: Record<string, ComponentType> = {
|
||||
[BuiltInToolNames.FileGlobSearch]: MagnifyingGlassIcon,
|
||||
[BuiltInToolNames.GrepSearch]: CommandLineIcon,
|
||||
[BuiltInToolNames.LSTool]: FolderIcon,
|
||||
[BuiltInToolNames.ReadCurrentlyOpenFile]: DocumentTextIcon,
|
||||
[BuiltInToolNames.ReadFile]: DocumentIcon,
|
||||
[BuiltInToolNames.SearchWeb]: GlobeAltIcon,
|
||||
[BuiltInToolNames.ViewDiff]: CodeBracketIcon,
|
||||
[BuiltInToolNames.ViewRepoMap]: MapIcon,
|
||||
[BuiltInToolNames.ViewSubdirectory]: FolderOpenIcon,
|
||||
};
|
||||
|
||||
export function ToolCallDiv(props: ToolCallDivProps) {
|
||||
function getIcon(state: ToolStatus) {
|
||||
switch (state) {
|
||||
|
|
@ -29,6 +60,35 @@ export function ToolCallDiv(props: ToolCallDivProps) {
|
|||
}
|
||||
}
|
||||
|
||||
const availableTools = useAppSelector((state) => state.config.config.tools);
|
||||
const tool = useMemo(() => {
|
||||
return availableTools.find(
|
||||
(tool) => props.toolCall.function?.name === tool.function.name,
|
||||
);
|
||||
}, [availableTools, props.toolCall]);
|
||||
|
||||
const statusMessage = useMemo(() => {
|
||||
return getToolCallStatusMessage(tool, props.toolCallState);
|
||||
}, [props.toolCallState, tool]);
|
||||
|
||||
const icon =
|
||||
props.toolCall.function?.name &&
|
||||
toolCallIcons[props.toolCall.function?.name];
|
||||
if (icon && props.toolCall.id) {
|
||||
return (
|
||||
<div className="ml-4 mt-2">
|
||||
<ToolOutput
|
||||
title={statusMessage}
|
||||
icon={
|
||||
props.toolCallState.status === "generated" ? ArrowRightIcon : icon
|
||||
}
|
||||
contextItems={props.output ?? []}
|
||||
toolCallId={props.toolCall.id}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ToolCallDisplay
|
||||
icon={getIcon(props.toolCallState.status)}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,9 @@ module.exports = {
|
|||
animation: {
|
||||
"spin-slow": "spin 6s linear infinite",
|
||||
},
|
||||
borderRadius: {
|
||||
default: "5px",
|
||||
},
|
||||
colors: {
|
||||
lightgray: "#999998",
|
||||
"vsc-input-background": "var(--vscode-input-background, rgb(45 45 45))",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue