From c48eeb4642c2f34283025595d5f4671c64fbc263 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 8 Jul 2025 13:22:22 -0700 Subject: [PATCH] Update Redux state management for parallel tool calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Modified streamUpdate to process all tool calls instead of just [0] - Store multiple tool calls in toolCallStates array - Maintain backward compatibility with single toolCallState - Update streaming logic to handle multiple tool call deltas - Enhanced abort logic to cancel all pending tool calls - Removed "Intentionally only supporting one tool call" limitation - TypeScript compilation passes, all utility tests pass 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- gui/src/redux/slices/sessionSlice.ts | 40 ++++++++++++++++++---------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 0a4876e0e..ea1391123 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -140,6 +140,14 @@ export const sessionSlice = createSlice({ if (message.toolCallState?.status === "generated") { message.toolCallState.status = "canceled"; } + // Also cancel any tool calls in the toolCallStates array + if (message.toolCallStates) { + message.toolCallStates.forEach(toolCallState => { + if (toolCallState.status === "generated") { + toolCallState.status = "canceled"; + } + }); + } break; } } @@ -368,12 +376,13 @@ export const sessionSlice = createSlice({ }, contextItems: [], }; - if (message.role === "assistant" && message.toolCalls?.[0]) { - const toolCallDelta = message.toolCalls[0]; - historyItem.toolCallState = addToolCallDeltaToState( - toolCallDelta, - undefined, + if (message.role === "assistant" && message.toolCalls?.length) { + // Handle multiple tool calls + historyItem.toolCallStates = message.toolCalls.map(toolCallDelta => + addToolCallDeltaToState(toolCallDelta, undefined) ); + // Maintain backward compatibility with single toolCallState + historyItem.toolCallState = historyItem.toolCallStates[0]; } state.history.push(historyItem); } else { @@ -409,17 +418,20 @@ export const sessionSlice = createSlice({ } } else if ( message.role === "assistant" && - message.toolCalls?.[0] && + message.toolCalls?.length && lastMessage.role === "assistant" ) { - // Intentionally only supporting one tool call for now. - const toolCallDelta = message.toolCalls[0]; - const newToolCallState = addToolCallDeltaToState( - toolCallDelta, - lastItem.toolCallState, - ); - lastItem.toolCallState = newToolCallState; - lastMessage.toolCalls = [newToolCallState.toolCall]; + // Handle multiple tool calls in streaming updates + const existingToolCallStates = lastItem.toolCallStates || []; + const updatedToolCallStates = message.toolCalls.map((toolCallDelta, index) => { + const existingState = existingToolCallStates[index]; + return addToolCallDeltaToState(toolCallDelta, existingState); + }); + + lastItem.toolCallStates = updatedToolCallStates; + // Maintain backward compatibility + lastItem.toolCallState = updatedToolCallStates[0]; + lastMessage.toolCalls = updatedToolCallStates.map(state => state.toolCall); } } }