feat: adapt duplicate toolCallId (#7733)

This commit is contained in:
xiaohuanxiong3 2025-09-23 05:31:24 +08:00 • committed by GitHub
parent 99fed48494
commit 9ddd30341e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 4 deletions

View file

@ -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,
);
},
);

View file

@ -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),

View file

@ -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,
);