setOpen((prev) => !prev)}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
data-testid={testId}
>
-
+
{Icon && !isHovered && !open ? (
-
+
) : (
<>
>
)}
-
+
{title}
diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/CancelButton.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/CancelButton.tsx
new file mode 100644
index 000000000..67a5deb64
--- /dev/null
+++ b/gui/src/components/mainInput/Lump/LumpToolbar/CancelButton.tsx
@@ -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 (
+
+ {children || (
+ <>
+ {showKeyboardShortcut && (
+
+ {jetbrains ? getAltKeyLabel() : getMetaKeyLabel()}⌫
+
+ )}
+ Cancel
+ >
+ )}
+
+ );
+}
diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/GeneratingIndicator.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/GeneratingIndicator.tsx
index 05e20420f..3039f2c04 100644
--- a/gui/src/components/mainInput/Lump/LumpToolbar/GeneratingIndicator.tsx
+++ b/gui/src/components/mainInput/Lump/LumpToolbar/GeneratingIndicator.tsx
@@ -8,10 +8,7 @@ export function GeneratingIndicator({
testId?: string;
}) {
return (
-
+
{text}...
diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx
index fcd4d4192..912d947b1 100644
--- a/gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx
+++ b/gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx
@@ -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() {
{index === 0 && (
-
handleReject(toolCall.toolCallId)}
data-testid={`reject-tool-call-button-${toolCall.toolCallId}`}
- >
- {jetbrains ? getAltKeyLabel() : getMetaKeyLabel()} ⌫ Cancel
-
+ />
)}
diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx
index 9b477a2ba..83ba508dc 100644
--- a/gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx
+++ b/gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx
@@ -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 (
-
{
- void dispatch(cancelStream());
- }}
- >
- {jetbrains ? getAltKeyLabel() : getMetaKeyLabel()} ⌫ Cancel
-
+
void dispatch(cancelStream())} />
);
}
diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx
index e29ab0f95..6b2699aae 100644
--- a/gui/src/pages/gui/Chat.tsx
+++ b/gui/src/pages/gui/Chat.tsx
@@ -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() {
- {/* Additionally render tool calls if they exist */}
{toolCallStates && (
-
diff --git a/gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx b/gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx
index 644638309..f35c43051 100644
--- a/gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx
+++ b/gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx
@@ -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 (
-
+
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 (
{`Continue ${intro} ${message}`}
diff --git a/gui/src/pages/gui/ToolCallDiv/index.tsx b/gui/src/pages/gui/ToolCallDiv/index.tsx
index f573a45a0..94ea296c5 100644
--- a/gui/src/pages/gui/ToolCallDiv/index.tsx
+++ b/gui/src/pages/gui/ToolCallDiv/index.tsx
@@ -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
= {
- [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 ;
- case "generated":
- return ;
- case "done":
- return ;
- case "canceled":
- case "errored":
- return ;
- }
-}
-
-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 (
-
+
+
setOpen((prev) => !prev)}
+ onMouseEnter={() => setIsHovered(true)}
+ onMouseLeave={() => setIsHovered(false)}
+ >
+
+ {showChevron ? (
+
+ ) : (
+
+ )}
+
+ {getGroupActionVerb(toolCallStates)} {validToolCalls.length} actions
+
+
+ {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 (
+
+
+
+ );
+ })()}
+
+ ))}
+
+
);
}
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 (
+
+
+
+ );
+ })()}
+
+ ))}
+
);
}
diff --git a/gui/src/pages/gui/ToolCallDiv/toolCallStateToContextItem.ts b/gui/src/pages/gui/ToolCallDiv/toolCallStateToContextItem.ts
deleted file mode 100644
index b3e132cad..000000000
--- a/gui/src/pages/gui/ToolCallDiv/toolCallStateToContextItem.ts
+++ /dev/null
@@ -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,
- },
- };
-}
diff --git a/gui/src/pages/gui/ToolCallDiv/utils.tsx b/gui/src/pages/gui/ToolCallDiv/utils.tsx
new file mode 100644
index 000000000..07a133bdb
--- /dev/null
+++ b/gui/src/pages/gui/ToolCallDiv/utils.tsx
@@ -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 = {
+ [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 ;
+ case "generated":
+ return ;
+ case "done":
+ return ;
+ case "canceled":
+ case "errored":
+ return ;
+ }
+}
+
+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,
+ },
+ };
+}
diff --git a/gui/src/pages/gui/ToolCallsGroup.tsx b/gui/src/pages/gui/ToolCallsGroup.tsx
deleted file mode 100644
index b89306a07..000000000
--- a/gui/src/pages/gui/ToolCallsGroup.tsx
+++ /dev/null
@@ -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 (
-
-
- Performing {validToolCalls.length} actions
-
-
- {toolCallStates.map((toolCallState) => (
-
- ))}
-
-
- );
- }
-
- // Single tool call - render as before
- return (
-
- {toolCallStates.map((toolCallState) => (
-
- ))}
-
- );
-}
\ No newline at end of file
diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts
index 50df496ac..093a10b0b 100644
--- a/gui/src/redux/slices/sessionSlice.ts
+++ b/gui/src/redux/slices/sessionSlice.ts
@@ -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";
diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts
index d09224e39..50585442f 100644
--- a/gui/src/redux/thunks/streamNormalInput.ts
+++ b/gui/src/redux/thunks/streamNormalInput.ts
@@ -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);
}
diff --git a/gui/src/redux/thunks/streamResponseAfterToolCall.ts b/gui/src/redux/thunks/streamResponseAfterToolCall.ts
index 14799ddf0..ab01de3d8 100644
--- a/gui/src/redux/thunks/streamResponseAfterToolCall.ts
+++ b/gui/src/redux/thunks/streamResponseAfterToolCall.ts
@@ -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({})));
diff --git a/gui/src/redux/util/constructMessages.ts b/gui/src/redux/util/constructMessages.ts
index 28fc1b167..d69bc33b3 100644
--- a/gui/src/redux/util/constructMessages.ts
+++ b/gui/src/redux/util/constructMessages.ts
@@ -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",
+ },
+ );
}
}
}