From 9ddd30341e7b3d05f799430298425bb137b629f3 Mon Sep 17 00:00:00 2001 From: xiaohuanxiong3 <39520495+xiaohuanxiong3@users.noreply.github.com> Date: Tue, 23 Sep 2025 05:31:24 +0800 Subject: [PATCH] feat: adapt duplicate toolCallId (#7733) --- gui/src/redux/selectors/selectToolCalls.ts | 4 +++- gui/src/redux/thunks/streamResponseAfterToolCall.ts | 2 +- gui/src/redux/util/index.ts | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/gui/src/redux/selectors/selectToolCalls.ts b/gui/src/redux/selectors/selectToolCalls.ts index 23a586110..a65f70140 100644 --- a/gui/src/redux/selectors/selectToolCalls.ts +++ b/gui/src/redux/selectors/selectToolCalls.ts @@ -50,7 +50,9 @@ export const selectApplyStateByToolCallId = createSelector( (_store: RootState, toolCallId: string) => toolCallId, ], (applyStates, toolCallId) => { - return applyStates.states.find((state) => state.toolCallId === toolCallId); + return applyStates.states.findLast( + (state) => state.toolCallId === toolCallId, + ); }, ); diff --git a/gui/src/redux/thunks/streamResponseAfterToolCall.ts b/gui/src/redux/thunks/streamResponseAfterToolCall.ts index 892e39619..357ef944e 100644 --- a/gui/src/redux/thunks/streamResponseAfterToolCall.ts +++ b/gui/src/redux/thunks/streamResponseAfterToolCall.ts @@ -69,7 +69,7 @@ export const streamResponseAfterToolCall = createAsyncThunk< // Check if we should continue streaming based on tool call completion const history = getState().session.history; - const assistantMessage = history.find( + const assistantMessage = history.findLast( (item) => item.message.role === "assistant" && item.toolCallStates?.some((tc) => tc.toolCallId === toolCallId), diff --git a/gui/src/redux/util/index.ts b/gui/src/redux/util/index.ts index 2bceb8fb3..8a390e32e 100644 --- a/gui/src/redux/util/index.ts +++ b/gui/src/redux/util/index.ts @@ -66,7 +66,8 @@ export function findToolCallById( chatHistory: RootState["session"]["history"], toolCallId: string, ): ToolCallState | undefined { - for (const item of chatHistory) { + for (let i = chatHistory.length - 1; i >= 0; i--) { + const item = chatHistory[i]; if (item.toolCallStates) { const toolCallState = item.toolCallStates.find( (state) => state.toolCallId === toolCallId, @@ -84,7 +85,7 @@ export function findChatHistoryItemByToolCallId( chatHistory: RootState["session"]["history"], toolCallId: string, ): ChatHistoryItemWithMessageId | undefined { - return chatHistory.find( + return chatHistory.findLast( (item) => item.message.role === "tool" && item.message.toolCallId === toolCallId, );