| 1 | import { createSelector } from "@reduxjs/toolkit"; |
| 2 | import { ToolCallState } from "core"; |
| 3 | import { RootState } from "../store"; |
| 4 | |
| 5 | export const selectLastToolCall = createSelector( |
| 6 | [(store: RootState) => store.session.history], |
| 7 | (history): ToolCallState | null => { |
| 8 | let lastToolCallHistoryItem = null; |
| 9 | for (let i = history.length - 1; i >= 0; i--) { |
| 10 | const item = history[i]; |
| 11 | if (item.message.role === "assistant" && item.message.toolCalls?.length) { |
| 12 | lastToolCallHistoryItem = item; |
| 13 | break; |
| 14 | } |
| 15 | } |
| 16 | return lastToolCallHistoryItem?.toolCallState ?? null; |
| 17 | }, |
| 18 | ); |