Elffuss BraidHub

kikocis/continue public

a0c996c3d18a · 1.6 KiBRawPermalink
1import { ContextItem, ToolCallState } from "core";
2import { safeParseToolCallArgs } from "core/tools/parseArgs";
3import { IIdeMessenger } from "../../context/IdeMessenger";
4import { ChatHistoryItemWithMessageId } from "../slices/sessionSlice";
5import { RootState } from "../store";
6
7export function findCurrentToolCall(
8 chatHistory: RootState["session"]["history"],
9): ToolCallState | undefined {
10 return chatHistory[chatHistory.length - 1]?.toolCallState;
11}
12
13// TODO parallel tool calls - find tool call must search within arrays
14export function findToolCall(
15 chatHistory: RootState["session"]["history"],
16 toolCallId: string,
17): ToolCallState | undefined {
18 return chatHistory.find(
19 (item) => item.toolCallState?.toolCallId === toolCallId,
20 )?.toolCallState;
21}
22
23export function findToolOutput(
24 chatHistory: RootState["session"]["history"],
25 toolCallId: string,
26): ChatHistoryItemWithMessageId | undefined {
27 return chatHistory.find(
28 (item) =>
29 item.message.role === "tool" && item.message.toolCallId === toolCallId,
30 );
31}
32
33export function logToolUsage(
34 toolCallState: ToolCallState,
35 success: boolean,
36 messenger: IIdeMessenger,
37 finalOutput?: ContextItem[],
38) {
39 messenger.post("devdata/log", {
40 name: "toolUsage",
41 data: {
42 toolCallId: toolCallState.toolCallId,
43 functionName: toolCallState.toolCall?.function?.name,
44 functionArgs: toolCallState.toolCall?.function?.arguments,
45 toolCallArgs: safeParseToolCallArgs(toolCallState.toolCall),
46 parsedArgs: toolCallState.parsedArgs,
47 output: finalOutput || toolCallState.output || [],
48 succeeded: success,
49 },
50 });
51}