don't use findLast

This commit is contained in:
Nate 2024-11-29 12:06:50 -08:00
parent f3141cee12
commit 8cb904c49f

View file

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