| 1 | import { createAsyncThunk } from "@reduxjs/toolkit"; |
| 2 | import posthog from "posthog-js"; |
| 3 | import { cancelToolCall as cancelToolCallAction } from "../slices/sessionSlice"; |
| 4 | import { ThunkApiType } from "../store"; |
| 5 | import { findToolCallById } from "../util"; |
| 6 | |
| 7 | export const cancelToolCallThunk = createAsyncThunk< |
| 8 | void, |
| 9 | { toolCallId: string }, |
| 10 | ThunkApiType |
| 11 | >("chat/cancelToolCall", async ({ toolCallId }, { dispatch, getState }) => { |
| 12 | const state = getState(); |
| 13 | const toolCallState = findToolCallById(state.session.history, toolCallId); |
| 14 | |
| 15 | if (toolCallState) { |
| 16 | // Track tool call rejection |
| 17 | posthog.capture("gui_tool_call_decision", { |
| 18 | decision: "reject", |
| 19 | toolName: toolCallState.toolCall.function.name, |
| 20 | toolCallId: toolCallId, |
| 21 | }); |
| 22 | } |
| 23 | |
| 24 | // Dispatch the actual cancel action |
| 25 | dispatch(cancelToolCallAction({ toolCallId })); |
| 26 | }); |