From 8cb904c49f4c4898955236dc1299c841addbbefa Mon Sep 17 00:00:00 2001 From: Nate Date: Fri, 29 Nov 2024 12:06:50 -0800 Subject: [PATCH] don't use findLast --- gui/src/redux/selectors/selectLastToolCall.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gui/src/redux/selectors/selectLastToolCall.ts b/gui/src/redux/selectors/selectLastToolCall.ts index 610a03b4d..5509ab476 100644 --- a/gui/src/redux/selectors/selectLastToolCall.ts +++ b/gui/src/redux/selectors/selectLastToolCall.ts @@ -5,10 +5,14 @@ import { RootState } from "../store"; export const selectLastToolCall = createSelector( [(store: RootState) => store.state.history], (history): ToolCallState | null => { - const lastToolCallHistoryItem = history.findLast( - (item) => - item.message.role === "assistant" && item.message.toolCalls?.length, - ); + let lastToolCallHistoryItem = null; + for (let i = history.length - 1; i >= 0; i--) { + const item = history[i]; + if (item.message.role === "assistant" && item.message.toolCalls?.length) { + lastToolCallHistoryItem = item; + break; + } + } if (!lastToolCallHistoryItem) return null; return lastToolCallHistoryItem.toolCallState; },