cleanup group header

This commit is contained in:
Patrick Erichsen 2025-07-10 22:18:28 -07:00
parent e3a5582e94
commit 326440f656
12 changed files with 207 additions and 196 deletions

View file

@ -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();

View file

@ -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";

View file

@ -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 (
<div
onClick={onClick}
className="text-2xs cursor-pointer px-1.5 py-0.5 hover:brightness-125"
>
{children || (
<>
{showKeyboardShortcut && (
<span className="text-description-muted mr-1">
{jetbrains ? getAltKeyLabel() : getMetaKeyLabel()}⌫
</span>
)}
<span className="text-description">Cancel</span>
</>
)}
</div>
);
}

View file

@ -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}
</span>
<div className="flex items-center gap-2">
{index === 0 && (
<CancelButton
onClick={() => handleReject(toolCall.toolCallId)}
data-testid={`reject-tool-call-button-${toolCall.toolCallId}`}
/>
)}
<div className="flex items-center gap-1">
<Button
variant="ghost"
size="sm"
className="text-description-muted my-1 font-medium"
onClick={() => handleReject(toolCall.toolCallId)}
data-testid={`reject-tool-call-button-${toolCall.toolCallId}`}
>
{/* JetBrains overrides cmd+backspace, so we have to use another shortcut */}
{index === 0 && (
<span className="text-2xs mr-1">
{jetbrains ? getAltKeyLabel() : getMetaKeyLabel()}⌫
</span>
)}
<span>Reject</span>
</Button>
<Button
variant="primary"
@ -50,7 +58,7 @@ export function PendingToolCallToolbar() {
data-testid={`accept-tool-call-button-${toolCall.toolCallId}`}
>
{index === 0 && (
<span className="text-2xs mr-1.5">{getMetaKeyLabel()}⏎</span>
<span className="text-2xs mr-1">{getMetaKeyLabel()}⏎</span>
)}
<span>Accept</span>
</Button>

View file

@ -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 (
<div className="flex w-full items-center justify-between">
<GeneratingIndicator />
<CancelButton onClick={() => void dispatch(cancelStream())} />
<div
onClick={() => void dispatch(cancelStream())}
className="text-2xs cursor-pointer px-1.5 py-0.5 hover:brightness-125"
>
<span className="text-description">Pause</span>
{/* JetBrains overrides cmd+backspace, so we have to use another shortcut */}
<span className="text-description-muted ml-1 opacity-75">
{jetbrains ? getAltKeyLabel() : getMetaKeyLabel()}⌫
</span>
</div>
</div>
);
}

View file

@ -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 = {

View file

@ -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 (
<div className="mb-2">
<div
className="text-description flex cursor-pointer items-center gap-1.5 transition-colors duration-200 ease-in-out hover:brightness-125"
data-testid="performing-actions"
onClick={onToggle}
>
<ToggleWithIcon
isToggleable
icon={FolderIcon}
open={open}
onClick={onToggle}
/>
{getGroupActionVerb(toolCallStates)} {activeCalls.length}{" "}
{activeCalls.length === 1 ? "action" : "actions"}
</div>
</div>
);
}

View file

@ -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 ? (
<ChevronRightIcon
className={`text-description h-4 w-4 transition-transform duration-200 ease-in-out ${
shouldShowContent ? "rotate-90" : "rotate-0"
}`}
/>
) : (
Icon && <Icon className="text-description h-4 w-4" />
);
setOpen((prev) => !prev);
}
}
return Icon ? <Icon className="text-description h-4 w-4" /> : 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"
>
<div className="flex h-4 w-4 flex-shrink-0 flex-col items-center justify-center">
{renderIcon()}
</div>
<ToggleWithIcon
icon={Icon}
isToggleable={isToggleable}
open={shouldShowContent}
onClick={isToggleable ? handleToggleClick : handleIconClick}
isClickable={isSingleItem}
/>
<ToolCallStatusMessage tool={tool} toolCallState={toolCallState} />
</div>
<div className="flex flex-row items-center gap-1.5">

View file

@ -0,0 +1,58 @@
import { ChevronRightIcon } from "@heroicons/react/24/outline";
import { ComponentType, useState } from "react";
interface ToggleWithIconProps {
icon?: ComponentType<React.SVGProps<SVGSVGElement>>;
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 (
<ChevronRightIcon
className={`text-description h-4 w-4 transition-transform duration-200 ease-in-out ${
open ? "rotate-90" : "rotate-0"
}`}
/>
);
}
return Icon ? <Icon className="text-description h-4 w-4" /> : null;
}
return (
<div
className={`flex h-4 w-4 flex-shrink-0 flex-col items-center justify-center ${className}`}
onClick={isToggleable || isClickable ? handleClick : undefined}
onMouseEnter={isToggleable ? () => setIsHovered(true) : undefined}
onMouseLeave={isToggleable ? () => setIsHovered(false) : undefined}
>
{renderIcon()}
</div>
);
}

View file

@ -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 (
<SimpleToolCallUI
tool={tool}
toolCallState={toolCallState}
icon={toolCallState.status === "generated" ? ArrowRightIcon : icon}
historyIndex={historyIndex}
/>
);
}
return (
<div className="rounded-lg border border-gray-200 p-3 dark:border-gray-700">
<div
className="text-description flex cursor-pointer items-center gap-1.5 transition-colors duration-200 ease-in-out hover:brightness-125"
data-testid="performing-actions"
onClick={() => setOpen((prev) => !prev)}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
>
<div className="flex h-4 w-4 flex-shrink-0 flex-col items-center justify-center">
{showChevron ? (
<ChevronRightIcon
className={`text-description h-4 w-4 transition-transform duration-200 ease-in-out ${
open ? "rotate-90" : "rotate-0"
}`}
/>
) : (
<FolderIcon className="text-description h-4 w-4" />
)}
</div>
{getGroupActionVerb(toolCallStates)} {validToolCalls.length} actions
</div>
<ToolCallDisplay
icon={getStatusIcon(toolCallState.status)}
tool={tool}
toolCallState={toolCallState}
historyIndex={historyIndex}
>
<FunctionSpecificToolCallDiv
toolCall={toolCallState.toolCall}
toolCallState={toolCallState}
historyIndex={historyIndex}
/>
</ToolCallDisplay>
);
};
if (shouldShowGroupedUI) {
return (
<div className="border-border rounded-lg border p-3">
<GroupedToolCallHeader
toolCallStates={toolCallStates}
activeCalls={activeCalls}
open={open}
onToggle={() => setOpen(!open)}
/>
<div
className={`overflow-y-auto transition-all duration-300 ease-in-out ${
open ? "mt-2 max-h-[50vh] opacity-100" : "max-h-0 opacity-0"
open ? "max-h-[50vh] opacity-100" : "max-h-0 opacity-0"
}`}
>
{toolCallStates.map((toolCallState) => (
<div className="py-1 pl-6" key={toolCallState.toolCallId}>
{(() => {
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 (
<SimpleToolCallUI
tool={tool}
toolCallState={toolCallState}
icon={
toolCallState.status === "generated"
? ArrowRightIcon
: icon
}
historyIndex={historyIndex}
/>
);
}
return (
<ToolCallDisplay
icon={getStatusIcon(toolCallState.status)}
tool={tool}
toolCallState={toolCallState}
historyIndex={historyIndex}
>
<FunctionSpecificToolCallDiv
toolCall={toolCallState.toolCall}
toolCallState={toolCallState}
historyIndex={historyIndex}
/>
</ToolCallDisplay>
);
})()}
{renderToolCall(toolCallState)}
</div>
))}
</div>
@ -107,48 +89,14 @@ export function ToolCallDiv({
);
}
return (
<div>
<div className="space-y-1">
{toolCallStates.map((toolCallState) => (
<div className="p-2" key={toolCallState.toolCallId}>
{(() => {
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 (
<SimpleToolCallUI
tool={tool}
toolCallState={toolCallState}
icon={
toolCallState.status === "generated" ? ArrowRightIcon : icon
}
historyIndex={historyIndex}
/>
);
}
return (
<ToolCallDisplay
icon={getStatusIcon(toolCallState.status)}
tool={tool}
toolCallState={toolCallState}
historyIndex={historyIndex}
>
<FunctionSpecificToolCallDiv
toolCall={toolCallState.toolCall}
toolCallState={toolCallState}
historyIndex={historyIndex}
/>
</ToolCallDisplay>
);
})()}
<div
className="border-border rounded-lg border p-3"
key={toolCallState.toolCallId}
>
{renderToolCall(toolCallState)}
</div>
))}
</div>

View file

@ -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<string, ComponentType> = {
[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 <ArrowRightIcon color={vscButtonBackground} />;
case "done":
return <CheckIcon className="text-green-500" />;
return <CheckIcon className="text-success" />;
case "canceled":
case "errored":
return <XMarkIcon className="text-red-500" />;
return <XMarkIcon className="text-error" />;
}
}

View file

@ -414,7 +414,6 @@ export const sessionSlice = createSlice({
}
},
setInactive: (state) => {
debugger;
const curMessage = state.history.at(-1);
if (curMessage) {