improve tool group ui

This commit is contained in:
Patrick Erichsen 2025-07-10 16:59:04 -07:00
parent 77a1482c09
commit e100d9f8ad
17 changed files with 382 additions and 264 deletions

View file

@ -38,12 +38,12 @@ export default function StepContainer(props: StepContainerProps) {
);
const uiConfig = useAppSelector(selectUIConfig);
const hideActionSpace =
historyItemAfterThis?.message.role === "assistant" ||
historyItemAfterThis?.message.role === "thinking" ||
historyItemAfterThis?.message.role === "tool";
const isUserOrSysMsg =
!historyItemAfterThis ||
historyItemAfterThis?.message.role === "user" ||
historyItemAfterThis?.message.role === "system";
const hideActions = hideActionSpace || (isStreaming && props.isLast);
const showResponseActions = isUserOrSysMsg && !(isStreaming && props.isLast);
useEffect(() => {
if (!isStreaming) {
@ -105,9 +105,9 @@ export default function StepContainer(props: StepContainerProps) {
{props.isLast && <ThinkingIndicator historyItem={props.item} />}
</ContentDiv>
{/* We want to occupy space in the DOM regardless of whether the actions are visible to avoid jank on stream complete */}
{!hideActionSpace && (
{isUserOrSysMsg && (
<div className={`mt-2 h-7 transition-opacity duration-300 ease-in-out`}>
{!hideActions && (
{showResponseActions && (
<ResponseActions
isTruncated={isTruncated}
onDelete={onDelete}

View file

@ -1,6 +1,6 @@
import { ChevronDownIcon, ChevronRightIcon } from "@heroicons/react/24/outline";
import { ComponentType, useState } from "react";
import { lightGray, vscBackground } from ".";
import { vscBackground } from ".";
interface ToggleProps {
children: React.ReactNode;
@ -26,31 +26,31 @@ function ToggleDiv({
}}
>
<div
className="flex cursor-pointer items-center justify-start text-xs text-gray-300"
className="text-description flex cursor-pointer items-center justify-start text-xs hover:brightness-125"
onClick={() => setOpen((prev) => !prev)}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
data-testid={testId}
>
<div className="relative mr-1 h-4 w-4">
<div className="relative h-4 w-4">
{Icon && !isHovered && !open ? (
<Icon className={`absolute h-4 w-4 text-[${lightGray}]`} />
<Icon className="absolute h-4 w-4" />
) : (
<>
<ChevronRightIcon
className={`absolute h-4 w-4 transition-all duration-200 ease-in-out text-[${lightGray}] ${
className={`absolute h-4 w-4 transition-all duration-200 ease-in-out ${
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}] ${
className={`absolute h-4 w-4 transition-all duration-200 ease-in-out ${
open ? "rotate-0 opacity-100" : "-rotate-90 opacity-0"
}`}
/>
</>
)}
</div>
<span className="ml-1 text-xs text-gray-400 transition-colors duration-200">
<span className="ml-1 text-xs transition-colors duration-200">
{title}
</span>
</div>

View file

@ -0,0 +1,35 @@
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

@ -8,10 +8,7 @@ export function GeneratingIndicator({
testId?: string;
}) {
return (
<div
className="text-description-muted flex items-center"
data-testid={testId}
>
<div className="text-description flex items-center" data-testid={testId}>
<ContinueSignet className="animate-spin-slow" width={26} height={26} />
<span className="text-xs">{text}...</span>
</div>

View file

@ -2,8 +2,9 @@ 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 { getAltKeyLabel, getMetaKeyLabel, isJetBrains } from "../../../../util";
import { getMetaKeyLabel, isJetBrains } from "../../../../util";
import { Button } from "../../../ui";
import { CancelButton } from "./CancelButton";
export function PendingToolCallToolbar() {
const dispatch = useAppDispatch();
@ -35,13 +36,10 @@ export function PendingToolCallToolbar() {
<div className="flex items-center gap-2">
{index === 0 && (
<div
className="text-description text-2xs cursor-pointer px-1.5 py-0.5 hover:brightness-125"
<CancelButton
onClick={() => handleReject(toolCall.toolCallId)}
data-testid={`reject-tool-call-button-${toolCall.toolCallId}`}
>
{jetbrains ? getAltKeyLabel() : getMetaKeyLabel()} ⌫ Cancel
</div>
/>
)}
<Button
@ -52,7 +50,7 @@ export function PendingToolCallToolbar() {
data-testid={`accept-tool-call-button-${toolCall.toolCallId}`}
>
{index === 0 && (
<code className="text-2xs mr-1">{getMetaKeyLabel()} ⏎</code>
<span className="text-2xs mr-1.5">{getMetaKeyLabel()}⏎</span>
)}
<span>Accept</span>
</Button>

View file

@ -1,23 +1,15 @@
import { useAppDispatch } from "../../../../redux/hooks";
import { cancelStream } from "../../../../redux/thunks/cancelStream";
import { getAltKeyLabel, getMetaKeyLabel, isJetBrains } from "../../../../util";
import { CancelButton } from "./CancelButton";
import { GeneratingIndicator } from "./GeneratingIndicator";
export function StreamingToolbar() {
const dispatch = useAppDispatch();
const jetbrains = isJetBrains();
return (
<div className="flex w-full items-center justify-between">
<GeneratingIndicator />
<div
className="text-description text-2xs cursor-pointer p-0.5 pr-1 hover:brightness-125"
onClick={() => {
void dispatch(cancelStream());
}}
>
{jetbrains ? getAltKeyLabel() : getMetaKeyLabel()} ⌫ Cancel
</div>
<CancelButton onClick={() => void dispatch(cancelStream())} />
</div>
);
}

View file

@ -47,7 +47,7 @@ import { streamEditThunk } from "../../redux/thunks/edit";
import { loadLastSession } from "../../redux/thunks/session";
import { streamResponseThunk } from "../../redux/thunks/streamResponse";
import { isJetBrains, isMetaEquivalentKeyPressed } from "../../util";
import { ToolCallsGroup } from "./ToolCallsGroup";
import { ToolCallDiv } from "./ToolCallDiv";
import { cancelStream } from "../../redux/thunks/cancelStream";
import { getLocalStorage, setLocalStorage } from "../../util/localStorage";
@ -335,9 +335,8 @@ export function Chat() {
</TimelineItem>
</div>
{/* Additionally render tool calls if they exist */}
{toolCallStates && (
<ToolCallsGroup
<ToolCallDiv
toolCallStates={toolCallStates}
historyIndex={index}
/>

View file

@ -7,9 +7,9 @@ import {
} from "../../../components/mainInput/belowMainInput/ContextItemsPeek";
import { IdeMessengerContext } from "../../../context/IdeMessenger";
import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs";
import { toolCallStateToContextItems } from "./toolCallStateToContextItem";
import { ToolCallStatusMessage } from "./ToolCallStatusMessage";
import { ToolTruncateHistoryIcon } from "./ToolTruncateHistoryIcon";
import { toolCallStateToContextItems } from "./utils";
interface SimpleToolCallUIProps {
toolCallState: ToolCallState;
@ -73,7 +73,7 @@ export function SimpleToolCallUI({
}
return (
<div className="flex flex-col py-4 pl-5 pr-2">
<div className="flex flex-col">
<div className="flex min-w-0 flex-row items-center justify-between gap-2">
<div
className={`text-description flex min-w-0 flex-row items-center justify-between gap-1.5 text-xs transition-colors duration-200 ease-in-out ${

View file

@ -1,6 +1,6 @@
import { Tool, ToolCallState } from "core";
import Mustache from "mustache";
import { useFontSize } from "../../../components/ui/font";
import { getStatusIntro } from "./utils";
interface ToolCallStatusMessageProps {
tool: Tool | undefined;
@ -11,7 +11,6 @@ export function ToolCallStatusMessage({
tool,
toolCallState,
}: ToolCallStatusMessageProps) {
const fontSize = useFontSize();
if (!tool) return "Agent tool use";
const toolName = tool.displayTitle ?? tool.function.name;
@ -23,39 +22,38 @@ export function ToolCallStatusMessage({
// TODO go back and replace arg string values and tool names with <code> tags
// to make them more readable
let intro = "";
let intro = getStatusIntro(toolCallState.status, tool.isInstant);
let message = "";
// Handle the special case for "done" status or instant tools that are calling
if (
toolCallState.status === "done" ||
(tool.isInstant && toolCallState.status === "calling")
) {
intro = "";
message = tool.hasAlready
? Mustache.render(tool.hasAlready, toolCallState.parsedArgs)
: `used the ${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)
: `calling the ${defaultToolDescription}`;
} else if (
toolCallState.status === "canceled" ||
toolCallState.status === "errored"
) {
intro = "tried to";
message = futureMessage;
} else {
switch (toolCallState.status) {
case "generating":
case "generated":
case "canceled":
case "errored":
message = futureMessage;
break;
case "calling":
message = tool.isCurrently
? Mustache.render(tool.isCurrently, toolCallState.parsedArgs)
: `calling the ${defaultToolDescription}`;
break;
default:
message = defaultToolDescription;
}
}
return (
<div
className="text-description line-clamp-4 min-w-0 break-words"
style={{ fontSize }}
data-testid="tool-call-title"
>
{`Continue ${intro} ${message}`}

View file

@ -1,102 +1,155 @@
import {
ArrowRightIcon,
CheckIcon,
CodeBracketIcon,
DocumentIcon,
DocumentTextIcon,
ChevronRightIcon,
FolderIcon,
FolderOpenIcon,
GlobeAltIcon,
MagnifyingGlassIcon,
MapIcon,
PencilIcon,
XMarkIcon,
} from "@heroicons/react/24/outline";
import { 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 { ToolCallState } from "core";
import { useState } from "react";
import { useAppSelector } from "../../../redux/hooks";
import FunctionSpecificToolCallDiv from "./FunctionSpecificToolCallDiv";
import { SimpleToolCallUI } from "./SimpleToolCallUI";
import { ToolCallDisplay } from "./ToolCall";
import { getGroupActionVerb, getStatusIcon, toolCallIcons } from "./utils";
interface ToolCallDivProps {
toolCall: ToolCallDelta;
toolCallState: ToolCallState;
toolCallStates: ToolCallState[];
historyIndex: number;
}
const toolCallIcons: Record<string, ComponentType> = {
[BuiltInToolNames.FileGlobSearch]: MagnifyingGlassIcon,
[BuiltInToolNames.GrepSearch]: MagnifyingGlassIcon,
[BuiltInToolNames.LSTool]: FolderIcon,
[BuiltInToolNames.ReadCurrentlyOpenFile]: DocumentTextIcon,
[BuiltInToolNames.ReadFile]: DocumentIcon,
[BuiltInToolNames.FetchUrlContent]: GlobeAltIcon,
[BuiltInToolNames.SearchWeb]: GlobeAltIcon,
[BuiltInToolNames.ViewDiff]: CodeBracketIcon,
[BuiltInToolNames.ViewRepoMap]: MapIcon,
[BuiltInToolNames.ViewSubdirectory]: FolderOpenIcon,
[BuiltInToolNames.CreateRuleBlock]: PencilIcon,
// EditExistingFile
// CreateNewFile
// RunTerminalCommand
};
function getStatusIcon(state: ToolStatus) {
switch (state) {
case "generating":
case "calling":
return <Spinner />;
case "generated":
return <ArrowRightIcon color={vscButtonBackground} />;
case "done":
return <CheckIcon className="text-green-500" />;
case "canceled":
case "errored":
return <XMarkIcon className="text-red-500" />;
}
}
export function ToolCallDiv(props: ToolCallDivProps) {
export function ToolCallDiv({
toolCallStates,
historyIndex,
}: ToolCallDivProps) {
const [open, setOpen] = useState(true);
const [isHovered, setIsHovered] = useState(false);
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 icon =
props.toolCall.function?.name &&
toolCallIcons[props.toolCall.function.name];
if (!toolCallStates || toolCallStates.length === 0) return null;
const validToolCalls = toolCallStates.map((state) => state.toolCall);
if (validToolCalls.length > 1) {
const showChevron = isHovered || open;
if (icon) {
return (
<SimpleToolCallUI
tool={tool}
toolCallState={props.toolCallState}
icon={
props.toolCallState.status === "generated" ? ArrowRightIcon : icon
}
historyIndex={props.historyIndex}
/>
<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>
<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"
}`}
>
{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>
);
})()}
</div>
))}
</div>
</div>
);
}
return (
<ToolCallDisplay
icon={getStatusIcon(props.toolCallState.status)}
tool={tool}
toolCallState={props.toolCallState}
historyIndex={props.historyIndex}
>
<FunctionSpecificToolCallDiv
toolCall={props.toolCall}
toolCallState={props.toolCallState}
historyIndex={props.historyIndex}
/>
</ToolCallDisplay>
<div>
{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>
))}
</div>
);
}

View file

@ -1,27 +0,0 @@
import { ContextItem, ContextItemWithId, ToolCallState } from "core";
export function toolCallStateToContextItems(
toolCallState: ToolCallState | undefined,
): ContextItemWithId[] {
if (!toolCallState) {
return [];
}
return (
toolCallState.output?.map((ctxItem) =>
toolCallCtxItemToCtxItemWithId(ctxItem, toolCallState.toolCallId),
) ?? []
);
}
export function toolCallCtxItemToCtxItemWithId(
ctxItem: ContextItem,
toolCallId: string,
): ContextItemWithId {
return {
...ctxItem,
id: {
providerTitle: "toolCall",
itemId: toolCallId,
},
};
}

View file

@ -0,0 +1,131 @@
import {
ArrowRightIcon,
CheckIcon,
CodeBracketIcon,
DocumentIcon,
DocumentTextIcon,
FolderIcon,
FolderOpenIcon,
GlobeAltIcon,
MagnifyingGlassIcon,
MapIcon,
PencilIcon,
XMarkIcon,
} from "@heroicons/react/24/outline";
import {
ContextItem,
ContextItemWithId,
ToolCallState,
ToolStatus,
} from "core";
import { BuiltInToolNames } from "core/tools/builtIn";
import { ComponentType } from "react";
import { vscButtonBackground } from "../../../components";
import Spinner from "../../../components/gui/Spinner";
// Helper function to determine the intro verb based on tool call status
export function getStatusIntro(
status: ToolCallState["status"],
isInstant?: boolean,
): string {
if (status === "done" || (isInstant && status === "calling")) {
return "";
}
switch (status) {
case "generating":
return "is generating output to";
case "generated":
return "wants to";
case "calling":
return "is";
case "canceled":
case "errored":
return "tried to";
default:
return "";
}
}
// Helper function to get the appropriate verb for group actions
export function getGroupActionVerb(toolCallStates: ToolCallState[]): string {
if (toolCallStates.length === 0) return "Performing";
// 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";
} else if (statuses.some((s) => s === "done")) {
return "Performed";
} else if (statuses.some((s) => s === "errored" || s === "canceled")) {
return "Attempted";
}
return "Performing";
}
export const toolCallIcons: Record<string, ComponentType> = {
[BuiltInToolNames.FileGlobSearch]: MagnifyingGlassIcon,
[BuiltInToolNames.GrepSearch]: MagnifyingGlassIcon,
[BuiltInToolNames.LSTool]: FolderIcon,
[BuiltInToolNames.ReadCurrentlyOpenFile]: DocumentTextIcon,
[BuiltInToolNames.ReadFile]: DocumentIcon,
[BuiltInToolNames.FetchUrlContent]: GlobeAltIcon,
[BuiltInToolNames.SearchWeb]: GlobeAltIcon,
[BuiltInToolNames.ViewDiff]: CodeBracketIcon,
[BuiltInToolNames.ViewRepoMap]: MapIcon,
[BuiltInToolNames.ViewSubdirectory]: FolderOpenIcon,
[BuiltInToolNames.CreateRuleBlock]: PencilIcon,
// EditExistingFile
// CreateNewFile
// RunTerminalCommand
};
export function getStatusIcon(state: ToolStatus) {
switch (state) {
case "generating":
case "calling":
return <Spinner />;
case "generated":
return <ArrowRightIcon color={vscButtonBackground} />;
case "done":
return <CheckIcon className="text-green-500" />;
case "canceled":
case "errored":
return <XMarkIcon className="text-red-500" />;
}
}
export function toolCallStateToContextItems(
toolCallState: ToolCallState | undefined,
): ContextItemWithId[] {
if (!toolCallState) {
return [];
}
return (
toolCallState.output?.map((ctxItem) =>
toolCallCtxItemToCtxItemWithId(ctxItem, toolCallState.toolCallId),
) ?? []
);
}
export function toolCallCtxItemToCtxItemWithId(
ctxItem: ContextItem,
toolCallId: string,
): ContextItemWithId {
return {
...ctxItem,
id: {
providerTitle: "toolCall",
itemId: toolCallId,
},
};
}

View file

@ -1,55 +0,0 @@
import { ToolCallState } from "core";
import { ToolCallDiv } from "./ToolCallDiv";
interface ToolCallsGroupProps {
toolCallStates: ToolCallState[];
historyIndex: number;
}
export function ToolCallsGroup({
toolCallStates,
historyIndex
}: ToolCallsGroupProps) {
if (!toolCallStates || toolCallStates.length === 0) return null;
// Get the complete ToolCall objects from the tool call states
const validToolCalls = toolCallStates.map(state => state.toolCall);
// If multiple tool calls, group them under "Performing N actions"
if (validToolCalls.length > 1) {
return (
<div className="border border-gray-200 dark:border-gray-700 rounded-lg p-3 mb-2">
<div
className="text-sm font-medium text-gray-700 dark:text-gray-300 mb-3"
data-testid="performing-actions"
>
Performing {validToolCalls.length} actions
</div>
<div className="space-y-2">
{toolCallStates.map((toolCallState) => (
<ToolCallDiv
key={toolCallState.toolCallId}
toolCallState={toolCallState}
toolCall={toolCallState.toolCall}
historyIndex={historyIndex}
/>
))}
</div>
</div>
);
}
// Single tool call - render as before
return (
<div>
{toolCallStates.map((toolCallState) => (
<ToolCallDiv
key={toolCallState.toolCallId}
toolCallState={toolCallState}
toolCall={toolCallState.toolCall}
historyIndex={historyIndex}
/>
))}
</div>
);
}

View file

@ -29,7 +29,7 @@ import {
import { findUriInDirs, getUriPathBasename } from "core/util/uri";
import { findLastIndex } from "lodash";
import { v4 as uuidv4 } from "uuid";
import { toolCallCtxItemToCtxItemWithId } from "../../pages/gui/ToolCallDiv/toolCallStateToContextItem";
import { toolCallCtxItemToCtxItemWithId } from "../../pages/gui/ToolCallDiv/utils";
import { addToolCallDeltaToState } from "../../util/toolCallState";
import { RootState } from "../store";
import { streamResponseThunk } from "../thunks/streamResponse";

View file

@ -128,17 +128,6 @@ export const streamNormalInput = createAsyncThunk<
}),
},
});
// else if (state.session.mode === "edit") {
// extra.ideMessenger.post("devdata/log", {
// name: "editInteraction",
// data: {
// prompt: next.value.prompt,
// completion: next.value.completion,
// modelProvider: selectedChatModel.provider,
// modelTitle: selectedChatModel.title,
// },
// });
// }
} catch (e) {
console.error("Failed to send dev data interaction log", e);
}
@ -159,22 +148,21 @@ export const streamNormalInput = createAsyncThunk<
);
});
// Run tool calls in parallel for auto-approved tools
const autoApprovedToolCalls = toolCallStates.filter(
// Check if ALL tool calls are auto-approved - if not, wait for user approval
const allAutoApproved = toolCallStates.every(
(toolCallState) =>
toolSettings[toolCallState.toolCall.function.name] ===
"allowedWithoutPermission",
);
if (autoApprovedToolCalls.length > 0) {
const toolCallPromises = autoApprovedToolCalls.map(
async (toolCallState) => {
const response = await dispatch(
callToolById({ toolCallId: toolCallState.toolCallId }),
);
return unwrapResult(response);
},
);
// Only execute automatically if ALL tool calls are auto-approved
if (allAutoApproved && toolCallStates.length > 0) {
const toolCallPromises = toolCallStates.map(async (toolCallState) => {
const response = await dispatch(
callToolById({ toolCallId: toolCallState.toolCallId }),
);
return unwrapResult(response);
});
await Promise.all(toolCallPromises);
}

View file

@ -17,12 +17,14 @@ export const streamResponseAfterToolCall = createAsyncThunk<
async ({ toolCallId }, { dispatch, getState }) => {
await dispatch(
streamThunkWrapper(async () => {
debugger;
const state = getState();
const toolCallState = findToolCallById(
state.session.history,
toolCallId,
);
if (!toolCallState) {
return; // in cases where edit tool is cancelled mid apply, this will be triggered
}
@ -43,15 +45,18 @@ export const streamResponseAfterToolCall = createAsyncThunk<
// Check if all parallel tool calls are complete before continuing
const history = getState().session.history;
const assistantMessage = history.find(item =>
item.message.role === "assistant" &&
item.toolCallStates?.some(tc => tc.toolCallId === toolCallId)
const assistantMessage = history.find(
(item) =>
item.message.role === "assistant" &&
item.toolCallStates?.some((tc) => tc.toolCallId === toolCallId),
);
if (assistantMessage && assistantMessage.toolCallStates) {
const totalToolCalls = assistantMessage.toolCallStates.length;
const completedToolCalls = assistantMessage.toolCallStates.filter(tc => tc.status === "done");
const completedToolCalls = assistantMessage.toolCallStates.filter(
(tc) => tc.status === "done",
);
// Only continue streaming if ALL parallel tool calls are complete
if (completedToolCalls.length === totalToolCalls) {
unwrapResult(await dispatch(streamNormalInput({})));

View file

@ -21,7 +21,7 @@ import {
normalizeToMessageParts,
renderContextItems,
} from "core/util/messageContent";
import { toolCallStateToContextItems } from "../../pages/gui/ToolCallDiv/toolCallStateToContextItem";
import { toolCallStateToContextItems } from "../../pages/gui/ToolCallDiv/utils";
export const NO_TOOL_CALL_OUTPUT_MESSAGE = "No tool output";
export const CANCELLED_TOOL_CALL_MESSAGE = "The user cancelled this tool call.";
@ -94,19 +94,18 @@ export function constructMessages(
// If the assistant message has tool calls, we need to insert tool messages
for (const toolCall of item.message.toolCalls) {
let content: string = NO_TOOL_CALL_OUTPUT_MESSAGE;
// Find the corresponding tool call state for this specific tool call
const toolCallState = item.toolCallStates?.find(
state => state.toolCallId === toolCall.id
(state) => state.toolCallId === toolCall.id,
);
if (toolCallState?.status === "canceled") {
content = CANCELLED_TOOL_CALL_MESSAGE;
} else if (toolCallState?.output) {
content = renderContextItems(toolCallState.output);
}
msgs.push({
ctxItems: toolCallStateToContextItems(toolCallState),
message: {
@ -115,15 +114,20 @@ export function constructMessages(
toolCallId: toolCall.id!,
},
});
}
} else if (item.toolCallStates && item.toolCallStates.length > 0) {
// This case indicates a potential mismatch - we have tool call states but no message.toolCalls
console.error("ERROR constructMessages: Assistant message has toolCallStates but no message.toolCalls:", {
toolCallStates: item.toolCallStates.length,
toolCallIds: item.toolCallStates.map(s => s.toolCallId),
messageContent: typeof item.message.content === 'string' ? item.message.content?.substring(0, 50) + "..." : 'Non-string content',
});
console.error(
"ERROR constructMessages: Assistant message has toolCallStates but no message.toolCalls:",
{
toolCallStates: item.toolCallStates.length,
toolCallIds: item.toolCallStates.map((s) => s.toolCallId),
messageContent:
typeof item.message.content === "string"
? item.message.content?.substring(0, 50) + "..."
: "Non-string content",
},
);
}
}
}