From 326440f65651c2af2c978aa88a65d660353decfe Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Thu, 10 Jul 2025 22:18:28 -0700 Subject: [PATCH] cleanup group header --- gui/src/components/History/index.tsx | 2 +- .../StepContainer/StepContainer.tsx | 1 - .../Lump/LumpToolbar/CancelButton.tsx | 35 ---- .../LumpToolbar/PendingToolCallToolbar.tsx | 28 ++- .../Lump/LumpToolbar/StreamingToolbar.tsx | 14 +- gui/src/components/ui/Button.tsx | 4 +- .../gui/ToolCallDiv/GroupedToolCallHeader.tsx | 37 ++++ .../gui/ToolCallDiv/SimpleToolCallUI.tsx | 38 ++-- .../pages/gui/ToolCallDiv/ToggleWithIcon.tsx | 58 ++++++ gui/src/pages/gui/ToolCallDiv/index.tsx | 174 ++++++------------ gui/src/pages/gui/ToolCallDiv/utils.tsx | 11 +- gui/src/redux/slices/sessionSlice.ts | 1 - 12 files changed, 207 insertions(+), 196 deletions(-) delete mode 100644 gui/src/components/mainInput/Lump/LumpToolbar/CancelButton.tsx create mode 100644 gui/src/pages/gui/ToolCallDiv/GroupedToolCallHeader.tsx create mode 100644 gui/src/pages/gui/ToolCallDiv/ToggleWithIcon.tsx diff --git a/gui/src/components/History/index.tsx b/gui/src/components/History/index.tsx index fd5bec166..b02f7eb5c 100644 --- a/gui/src/components/History/index.tsx +++ b/gui/src/components/History/index.tsx @@ -34,7 +34,7 @@ const parseDate = (date: string): Date => { }; const HEADER_CLASS = - "flex user-select-none pt-2 pb-3 opacity-75 text-center font-bold items-center justify-center sticky h-6"; + "flex user-select-none mt-1 opacity-75 text-center font-bold items-center justify-center sticky h-6"; export function History() { const dispatch = useAppDispatch(); diff --git a/gui/src/components/StepContainer/StepContainer.tsx b/gui/src/components/StepContainer/StepContainer.tsx index 88e1e753c..6f28333ed 100644 --- a/gui/src/components/StepContainer/StepContainer.tsx +++ b/gui/src/components/StepContainer/StepContainer.tsx @@ -39,7 +39,6 @@ export default function StepContainer(props: StepContainerProps) { const uiConfig = useAppSelector(selectUIConfig); const isUserOrSysMsg = - !historyItemAfterThis || historyItemAfterThis?.message.role === "user" || historyItemAfterThis?.message.role === "system"; diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/CancelButton.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/CancelButton.tsx deleted file mode 100644 index 67a5deb64..000000000 --- a/gui/src/components/mainInput/Lump/LumpToolbar/CancelButton.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import * as React from "react"; -import { getAltKeyLabel, getMetaKeyLabel, isJetBrains } from "../../../../util"; - -interface CancelButtonProps { - onClick: () => void; - className?: string; - showKeyboardShortcut?: boolean; - children?: React.ReactNode; -} - -export function CancelButton({ - onClick, - showKeyboardShortcut = true, - children, -}: CancelButtonProps) { - const jetbrains = isJetBrains(); - - return ( -
- {children || ( - <> - {showKeyboardShortcut && ( - - {jetbrains ? getAltKeyLabel() : getMetaKeyLabel()}⌫ - - )} - Cancel - - )} -
- ); -} diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx index 912d947b1..b3319fd3a 100644 --- a/gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx +++ b/gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx @@ -2,9 +2,8 @@ import { useAppDispatch, useAppSelector } from "../../../../redux/hooks"; import { selectPendingToolCalls } from "../../../../redux/selectors/selectToolCalls"; import { cancelToolCall } from "../../../../redux/slices/sessionSlice"; import { callToolById } from "../../../../redux/thunks/callToolById"; -import { getMetaKeyLabel, isJetBrains } from "../../../../util"; +import { getAltKeyLabel, getMetaKeyLabel, isJetBrains } from "../../../../util"; import { Button } from "../../../ui"; -import { CancelButton } from "./CancelButton"; export function PendingToolCallToolbar() { const dispatch = useAppDispatch(); @@ -34,13 +33,22 @@ export function PendingToolCallToolbar() { {toolCall.tool?.displayTitle ?? toolCall.toolCall.function.name} -
- {index === 0 && ( - handleReject(toolCall.toolCallId)} - data-testid={`reject-tool-call-button-${toolCall.toolCallId}`} - /> - )} +
+ diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx index 83ba508dc..7ce24d9cf 100644 --- a/gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx +++ b/gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx @@ -1,15 +1,25 @@ import { useAppDispatch } from "../../../../redux/hooks"; import { cancelStream } from "../../../../redux/thunks/cancelStream"; -import { CancelButton } from "./CancelButton"; +import { getAltKeyLabel, getMetaKeyLabel, isJetBrains } from "../../../../util"; import { GeneratingIndicator } from "./GeneratingIndicator"; export function StreamingToolbar() { + const jetbrains = isJetBrains(); const dispatch = useAppDispatch(); return (
- void dispatch(cancelStream())} /> +
void dispatch(cancelStream())} + className="text-2xs cursor-pointer px-1.5 py-0.5 hover:brightness-125" + > + Pause + {/* JetBrains overrides cmd+backspace, so we have to use another shortcut */} + + {jetbrains ? getAltKeyLabel() : getMetaKeyLabel()}⌫ + +
); } diff --git a/gui/src/components/ui/Button.tsx b/gui/src/components/ui/Button.tsx index 09ff269bf..608b8d774 100644 --- a/gui/src/components/ui/Button.tsx +++ b/gui/src/components/ui/Button.tsx @@ -15,9 +15,9 @@ const buttonVariants = { secondary: "border-none text-foreground bg-border hover:enabled:brightness-125", outline: - "border border-solid border-badge border-border text-foreground bg-transparent hover:enabled:bg-input", + "border border-solid border-badge border-border text-foreground bg-transparent hover:enabled:bg-input", ghost: - "border-none text-foreground bg-gray-500/40 hover:enabled:brightness-125", + "border-none text-foreground bg-inherit hover:enabled:brightness-125 hover:enabled:bg-input", }; const buttonSizes = { diff --git a/gui/src/pages/gui/ToolCallDiv/GroupedToolCallHeader.tsx b/gui/src/pages/gui/ToolCallDiv/GroupedToolCallHeader.tsx new file mode 100644 index 000000000..e3e8ffdca --- /dev/null +++ b/gui/src/pages/gui/ToolCallDiv/GroupedToolCallHeader.tsx @@ -0,0 +1,37 @@ +import { FolderIcon } from "@heroicons/react/24/outline"; +import { ToolCallState } from "core"; +import { ToggleWithIcon } from "./ToggleWithIcon"; +import { getGroupActionVerb } from "./utils"; + +interface GroupedToolCallHeaderProps { + toolCallStates: ToolCallState[]; + activeCalls: ToolCallState[]; + open: boolean; + onToggle: () => void; +} + +export function GroupedToolCallHeader({ + toolCallStates, + activeCalls, + open, + onToggle, +}: GroupedToolCallHeaderProps) { + return ( +
+
+ + {getGroupActionVerb(toolCallStates)} {activeCalls.length}{" "} + {activeCalls.length === 1 ? "action" : "actions"} +
+
+ ); +} diff --git a/gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx b/gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx index f35c43051..8ada08e53 100644 --- a/gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx +++ b/gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx @@ -1,4 +1,3 @@ -import { ChevronRightIcon } from "@heroicons/react/24/outline"; import { Tool, ToolCallState } from "core"; import { ComponentType, useContext, useMemo, useState } from "react"; import { @@ -6,6 +5,7 @@ import { openContextItem, } from "../../../components/mainInput/belowMainInput/ContextItemsPeek"; import { IdeMessengerContext } from "../../../context/IdeMessenger"; +import { ToggleWithIcon } from "./ToggleWithIcon"; import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs"; import { ToolCallStatusMessage } from "./ToolCallStatusMessage"; import { ToolTruncateHistoryIcon } from "./ToolTruncateHistoryIcon"; @@ -31,7 +31,6 @@ export function SimpleToolCallUI({ }, [toolCallState]); const [open, setOpen] = useState(false); - const [isHovered, setIsHovered] = useState(false); const [showingArgs, setShowingArgs] = useState(false); const args: [string, any][] = useMemo(() => { @@ -51,25 +50,16 @@ export function SimpleToolCallUI({ } } - function renderIcon() { - if (!Icon && !isToggleable) { - return null; - } - + function handleToggleClick() { if (isToggleable) { - const showChevron = isHovered || shouldShowContent; - return showChevron ? ( - - ) : ( - Icon && - ); + setOpen((prev) => !prev); } + } - return Icon ? : null; + function handleIconClick() { + if (isSingleItem) { + openContextItem(shownContextItems[0], ideMessenger); + } } return ( @@ -80,13 +70,15 @@ export function SimpleToolCallUI({ isClickable ? "cursor-pointer hover:brightness-125" : "" }`} onClick={isClickable ? handleClick : undefined} - onMouseEnter={isToggleable ? () => setIsHovered(true) : undefined} - onMouseLeave={isToggleable ? () => setIsHovered(false) : undefined} data-testid="context-items-peek" > -
- {renderIcon()} -
+
diff --git a/gui/src/pages/gui/ToolCallDiv/ToggleWithIcon.tsx b/gui/src/pages/gui/ToolCallDiv/ToggleWithIcon.tsx new file mode 100644 index 000000000..27862065f --- /dev/null +++ b/gui/src/pages/gui/ToolCallDiv/ToggleWithIcon.tsx @@ -0,0 +1,58 @@ +import { ChevronRightIcon } from "@heroicons/react/24/outline"; +import { ComponentType, useState } from "react"; + +interface ToggleWithIconProps { + icon?: ComponentType>; + isToggleable?: boolean; + open?: boolean; + onClick?: () => void; + className?: string; + isClickable?: boolean; +} + +export function ToggleWithIcon({ + icon: Icon, + isToggleable = false, + open = false, + onClick, + className = "", + isClickable = false, +}: ToggleWithIconProps) { + const [isHovered, setIsHovered] = useState(false); + const showChevron = isToggleable && (isHovered || open); + + function handleClick() { + if ((isToggleable || isClickable) && onClick) { + onClick(); + } + } + + function renderIcon() { + if (!Icon && !isToggleable) { + return null; + } + + if (showChevron) { + return ( + + ); + } + + return Icon ? : null; + } + + return ( +
setIsHovered(true) : undefined} + onMouseLeave={isToggleable ? () => setIsHovered(false) : undefined} + > + {renderIcon()} +
+ ); +} diff --git a/gui/src/pages/gui/ToolCallDiv/index.tsx b/gui/src/pages/gui/ToolCallDiv/index.tsx index e9c725dbd..faa6bca1f 100644 --- a/gui/src/pages/gui/ToolCallDiv/index.tsx +++ b/gui/src/pages/gui/ToolCallDiv/index.tsx @@ -1,15 +1,12 @@ -import { - ArrowRightIcon, - ChevronRightIcon, - FolderIcon, -} from "@heroicons/react/24/outline"; +import { ArrowRightIcon } from "@heroicons/react/24/outline"; import { ToolCallState } from "core"; import { useState } from "react"; import { useAppSelector } from "../../../redux/hooks"; import FunctionSpecificToolCallDiv from "./FunctionSpecificToolCallDiv"; +import { GroupedToolCallHeader } from "./GroupedToolCallHeader"; import { SimpleToolCallUI } from "./SimpleToolCallUI"; import { ToolCallDisplay } from "./ToolCall"; -import { getGroupActionVerb, getStatusIcon, toolCallIcons } from "./utils"; +import { getStatusIcon, toolCallIcons } from "./utils"; interface ToolCallDivProps { toolCallStates: ToolCallState[]; @@ -21,85 +18,70 @@ export function ToolCallDiv({ historyIndex, }: ToolCallDivProps) { const [open, setOpen] = useState(true); - const [isHovered, setIsHovered] = useState(false); const availableTools = useAppSelector((state) => state.config.config.tools); - if (!toolCallStates || toolCallStates.length === 0) return null; + if (!toolCallStates?.length) return null; - const validToolCalls = toolCallStates.map((state) => state.toolCall); + const isStreamingComplete = toolCallStates.every( + (toolCall) => toolCall.status !== "generating", + ); - if (validToolCalls.length > 1) { - const showChevron = isHovered || open; + const shouldShowGroupedUI = toolCallStates.length > 1 && isStreamingComplete; + const activeCalls = toolCallStates.filter( + (call) => call.status !== "canceled", + ); + + const renderToolCall = (toolCallState: ToolCallState) => { + const tool = availableTools.find( + (tool) => toolCallState.toolCall.function?.name === tool.function.name, + ); + const functionName = toolCallState.toolCall.function?.name; + const icon = functionName && toolCallIcons[functionName]; + + if (icon) { + return ( + + ); + } return ( -
-
setOpen((prev) => !prev)} - onMouseEnter={() => setIsHovered(true)} - onMouseLeave={() => setIsHovered(false)} - > -
- {showChevron ? ( - - ) : ( - - )} -
- {getGroupActionVerb(toolCallStates)} {validToolCalls.length} actions -
+ + + + ); + }; + + if (shouldShowGroupedUI) { + return ( +
+ setOpen(!open)} + />
{toolCallStates.map((toolCallState) => (
- {(() => { - const tool = availableTools.find( - (tool) => - toolCallState.toolCall.function?.name === - tool.function.name, - ); - const icon = - toolCallState.toolCall.function?.name && - toolCallIcons[toolCallState.toolCall.function.name]; - - if (icon) { - return ( - - ); - } - - return ( - - - - ); - })()} + {renderToolCall(toolCallState)}
))}
@@ -107,48 +89,14 @@ export function ToolCallDiv({ ); } - return ( -
+
{toolCallStates.map((toolCallState) => ( -
- {(() => { - const tool = availableTools.find( - (tool) => - toolCallState.toolCall.function?.name === tool.function.name, - ); - const icon = - toolCallState.toolCall.function?.name && - toolCallIcons[toolCallState.toolCall.function.name]; - - if (icon) { - return ( - - ); - } - - return ( - - - - ); - })()} +
+ {renderToolCall(toolCallState)}
))}
diff --git a/gui/src/pages/gui/ToolCallDiv/utils.tsx b/gui/src/pages/gui/ToolCallDiv/utils.tsx index 07a133bdb..c85d12d40 100644 --- a/gui/src/pages/gui/ToolCallDiv/utils.tsx +++ b/gui/src/pages/gui/ToolCallDiv/utils.tsx @@ -54,15 +54,13 @@ export function getGroupActionVerb(toolCallStates: ToolCallState[]): string { // Get the most "active" status from all tool calls const statuses = toolCallStates.map((state) => state.status); - console.log({ statuses }); - // Priority order: calling > generating > generated > done > errored/canceled if (statuses.includes("calling")) { return "Performing"; } else if (statuses.includes("generating")) { return "Generating"; } else if (statuses.includes("generated")) { - return "Will perform"; + return "Pending"; } else if (statuses.some((s) => s === "done")) { return "Performed"; } else if (statuses.some((s) => s === "errored" || s === "canceled")) { @@ -84,9 +82,6 @@ export const toolCallIcons: Record = { [BuiltInToolNames.ViewRepoMap]: MapIcon, [BuiltInToolNames.ViewSubdirectory]: FolderOpenIcon, [BuiltInToolNames.CreateRuleBlock]: PencilIcon, - // EditExistingFile - // CreateNewFile - // RunTerminalCommand }; export function getStatusIcon(state: ToolStatus) { @@ -97,10 +92,10 @@ export function getStatusIcon(state: ToolStatus) { case "generated": return ; case "done": - return ; + return ; case "canceled": case "errored": - return ; + return ; } } diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 00c0e1ed6..31086d51f 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -414,7 +414,6 @@ export const sessionSlice = createSlice({ } }, setInactive: (state) => { - debugger; const curMessage = state.history.at(-1); if (curMessage) {