| 1 | import { ToolCallState } from "core"; |
| 2 | import { ChatHistoryItemWithMessageId } from "../slices/sessionSlice"; |
| 3 | import { RootState } from "../store"; |
| 4 | |
| 5 | export function findCurrentToolCall( |
| 6 | chatHistory: RootState["session"]["history"], |
| 7 | ): ToolCallState | undefined { |
| 8 | return chatHistory[chatHistory.length - 1]?.toolCallState; |
| 9 | } |
| 10 | |
| 11 | // TODO parallel tool calls - find tool call must search within arrays |
| 12 | export function findToolCall( |
| 13 | chatHistory: RootState["session"]["history"], |
| 14 | toolCallId: string, |
| 15 | ): ToolCallState | undefined { |
| 16 | return chatHistory.find( |
| 17 | (item) => item.toolCallState?.toolCallId === toolCallId, |
| 18 | )?.toolCallState; |
| 19 | } |
| 20 | |
| 21 | export function findToolOutput( |
| 22 | chatHistory: RootState["session"]["history"], |
| 23 | toolCallId: string, |
| 24 | ): ChatHistoryItemWithMessageId | undefined { |
| 25 | return chatHistory.find( |
| 26 | (item) => |
| 27 | item.message.role === "tool" && item.message.toolCallId === toolCallId, |
| 28 | ); |
| 29 | } |