diff --git a/gui/src/redux/selectors/selectLastToolCall.ts b/gui/src/redux/selectors/selectLastToolCall.ts new file mode 100644 index 000000000..610a03b4d --- /dev/null +++ b/gui/src/redux/selectors/selectLastToolCall.ts @@ -0,0 +1,15 @@ +import { createSelector } from "@reduxjs/toolkit"; +import { ToolCallState } from "core"; +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, + ); + if (!lastToolCallHistoryItem) return null; + return lastToolCallHistoryItem.toolCallState; + }, +);