Elffuss BraidHub

kikocis/continue public

f4d972701df9 · 915 BRawPermalink
1import { ToolCallState } from "core";
2import { ChatHistoryItemWithMessageId } from "../slices/sessionSlice";
3import { RootState } from "../store";
4
5export 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
12export 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
21export 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}