diff --git a/gui/src/pages/gui/ToolCallDiv/ToolCallStatusMessage.tsx b/gui/src/pages/gui/ToolCallDiv/ToolCallStatusMessage.tsx
index c633b0514..4a88fd7cb 100644
--- a/gui/src/pages/gui/ToolCallDiv/ToolCallStatusMessage.tsx
+++ b/gui/src/pages/gui/ToolCallDiv/ToolCallStatusMessage.tsx
@@ -53,7 +53,7 @@ export function ToolCallStatusMessage({
return (
{`Continue ${intro} ${message}`}
diff --git a/gui/src/pages/gui/ToolCallDiv/index.tsx b/gui/src/pages/gui/ToolCallDiv/index.tsx
index c976a7ddd..ae2839926 100644
--- a/gui/src/pages/gui/ToolCallDiv/index.tsx
+++ b/gui/src/pages/gui/ToolCallDiv/index.tsx
@@ -6,7 +6,7 @@ import { useAppSelector } from "../../../redux/hooks";
import FunctionSpecificToolCallDiv from "./FunctionSpecificToolCallDiv";
import { GroupedToolCallHeader } from "./GroupedToolCallHeader";
import { SimpleToolCallUI } from "./SimpleToolCallUI";
-import { ToolCallDisplay } from "./ToolCall";
+import { ToolCallDisplay } from "./ToolCallDisplay";
import { getStatusIcon, toolCallIcons } from "./utils";
interface ToolCallDivProps {
@@ -103,10 +103,7 @@ export function ToolCallDiv({
}
return toolCallStates.map((toolCallState) => (
-
+
{renderToolCall(toolCallState)}
));
diff --git a/gui/src/redux/thunks/streamResponseAfterToolCall.ts b/gui/src/redux/thunks/streamResponseAfterToolCall.ts
index 58a63f598..ed16b5a5a 100644
--- a/gui/src/redux/thunks/streamResponseAfterToolCall.ts
+++ b/gui/src/redux/thunks/streamResponseAfterToolCall.ts
@@ -2,80 +2,32 @@ import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit";
import { ChatMessage } from "core";
import { renderContextItems } from "core/util/messageContent";
import {
+ ChatHistoryItemWithMessageId,
resetNextCodeBlockToApplyIndex,
streamUpdate,
} from "../slices/sessionSlice";
-import { AppThunkDispatch, RootState, ThunkApiType } from "../store";
+import { ThunkApiType } from "../store";
import { findToolCallById } from "../util";
import { streamNormalInput } from "./streamNormalInput";
import { streamThunkWrapper } from "./streamThunkWrapper";
-/**
- * Finds the assistant message that contains the specified tool call.
- */
-function findAssistantMessageWithToolCall(
- history: RootState["session"]["history"],
- toolCallId: string,
-) {
- return history.find(
- (item) =>
- item.message.role === "assistant" &&
- item.toolCallStates?.some((tc) => tc.toolCallId === toolCallId),
- );
-}
-
-/**
- * Checks if all parallel tool calls in an assistant message are complete.
- */
-function areAllToolCallsComplete(
- toolCallStates: NonNullable<
- ReturnType
- >["toolCallStates"],
-): boolean {
- if (!toolCallStates) return false;
-
- const completedToolCalls = toolCallStates.filter(
- (tc) => tc.status === "done",
- );
-
- return completedToolCalls.length === toolCallStates.length;
-}
-
/**
* Determines if we should continue streaming based on tool call completion status.
*/
-function shouldContinueStreaming(
- assistantMessage: ReturnType,
+function areAllToolsDoneStreaming(
+ assistantMessage: ChatHistoryItemWithMessageId | undefined,
): boolean {
+ // This might occur because of race conditions, if so, the tools are completed
if (!assistantMessage?.toolCallStates) {
- return false; // No assistant message found - don't stream
- }
-
- const totalToolCalls = assistantMessage.toolCallStates.length;
-
- // Single tool call - always continue streaming
- if (totalToolCalls === 1) {
return true;
}
- // Multiple tool calls - only continue if all are complete
- return areAllToolCallsComplete(assistantMessage.toolCallStates);
-}
+ // Only continue if all tool calls are complete
+ const completedToolCalls = assistantMessage.toolCallStates.filter(
+ (tc) => tc.status === "done",
+ );
-/**
- * Creates and dispatches a tool message for the completed tool call.
- */
-function createAndDispatchToolMessage(
- dispatch: AppThunkDispatch,
- toolCallId: string,
- toolOutput: any[],
-): void {
- const newMessage: ChatMessage = {
- role: "tool",
- content: renderContextItems(toolOutput),
- toolCallId,
- };
- dispatch(streamUpdate([newMessage]));
+ return completedToolCalls.length === assistantMessage.toolCallStates.length;
}
export const streamResponseAfterToolCall = createAsyncThunk<
@@ -104,16 +56,22 @@ export const streamResponseAfterToolCall = createAsyncThunk<
await new Promise((resolve) => setTimeout(resolve, 0));
// Create and dispatch the tool message
- createAndDispatchToolMessage(dispatch, toolCallId, toolOutput);
+ const newMessage: ChatMessage = {
+ role: "tool",
+ content: renderContextItems(toolOutput),
+ toolCallId,
+ };
+ dispatch(streamUpdate([newMessage]));
// Check if we should continue streaming based on tool call completion
const history = getState().session.history;
- const assistantMessage = findAssistantMessageWithToolCall(
- history,
- toolCallId,
+ const assistantMessage = history.find(
+ (item) =>
+ item.message.role === "assistant" &&
+ item.toolCallStates?.some((tc) => tc.toolCallId === toolCallId),
);
- if (shouldContinueStreaming(assistantMessage)) {
+ if (areAllToolsDoneStreaming(assistantMessage)) {
unwrapResult(await dispatch(streamNormalInput({})));
}
}),