diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx index bee98e866..6d3346f53 100644 --- a/gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx +++ b/gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx @@ -1,7 +1,7 @@ import { useAppDispatch, useAppSelector } from "../../../../redux/hooks"; import { selectPendingToolCalls } from "../../../../redux/selectors/selectToolCalls"; -import { cancelToolCall } from "../../../../redux/slices/sessionSlice"; import { callToolById } from "../../../../redux/thunks/callToolById"; +import { cancelToolCallThunk } from "../../../../redux/thunks/cancelToolCall"; import { getAltKeyLabel, getMetaKeyLabel, isJetBrains } from "../../../../util"; import { Button } from "../../../ui"; @@ -26,7 +26,7 @@ export function PendingToolCallToolbar() { }; const handleReject = (toolCallId: string) => { - void dispatch(cancelToolCall({ toolCallId })); + void dispatch(cancelToolCallThunk({ toolCallId })); }; return ( diff --git a/gui/src/redux/thunks/callToolById.ts b/gui/src/redux/thunks/callToolById.ts index 6afcd2981..26640709b 100644 --- a/gui/src/redux/thunks/callToolById.ts +++ b/gui/src/redux/thunks/callToolById.ts @@ -31,7 +31,7 @@ export const callToolById = createAsyncThunk< return; } - // Capture telemetry for user accepting the tool call + // Track tool call acceptance posthog.capture("gui_tool_call_decision", { decision: "accept", toolName: toolCallState.toolCall.function.name, diff --git a/gui/src/redux/thunks/cancelToolCall.ts b/gui/src/redux/thunks/cancelToolCall.ts new file mode 100644 index 000000000..3345bc153 --- /dev/null +++ b/gui/src/redux/thunks/cancelToolCall.ts @@ -0,0 +1,26 @@ +import { createAsyncThunk } from "@reduxjs/toolkit"; +import posthog from "posthog-js"; +import { cancelToolCall as cancelToolCallAction } from "../slices/sessionSlice"; +import { ThunkApiType } from "../store"; +import { findToolCallById } from "../util"; + +export const cancelToolCallThunk = createAsyncThunk< + void, + { toolCallId: string }, + ThunkApiType +>("chat/cancelToolCall", async ({ toolCallId }, { dispatch, getState }) => { + const state = getState(); + const toolCallState = findToolCallById(state.session.history, toolCallId); + + if (toolCallState) { + // Track tool call rejection + posthog.capture("gui_tool_call_decision", { + decision: "reject", + toolName: toolCallState.toolCall.function.name, + toolCallId: toolCallId, + }); + } + + // Dispatch the actual cancel action + dispatch(cancelToolCallAction({ toolCallId })); +}); diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts index bd2f6f92f..fe74ed886 100644 --- a/gui/src/redux/thunks/streamNormalInput.ts +++ b/gui/src/redux/thunks/streamNormalInput.ts @@ -3,6 +3,7 @@ import { LLMFullCompletionOptions, ModelDescription, Tool } from "core"; import { getRuleId } from "core/llm/rules/getSystemMessageWithRules"; import { ToCoreProtocol } from "core/protocol"; import { BuiltInToolNames } from "core/tools/builtIn"; +import posthog from "posthog-js"; import { selectActiveTools } from "../selectors/selectActiveTools"; import { selectUseSystemMessageTools } from "../selectors/selectUseSystemMessageTools"; import { selectSelectedChatModel } from "../slices/configSlice"; @@ -68,6 +69,15 @@ async function handleToolCallExecution( // Only run if we have auto-approve for all if (allAutoApproved && toolCallStates.length > 0) { + // Track auto-approved tool execution + toolCallStates.forEach((toolCallState) => { + posthog.capture("gui_tool_call_decision", { + decision: "auto_accept", + toolName: toolCallState.toolCall.function.name, + toolCallId: toolCallState.toolCallId, + }); + }); + const toolCallPromises = toolCallStates.map(async (toolCallState) => { const response = await dispatch( callToolById({ toolCallId: toolCallState.toolCallId }), @@ -276,7 +286,7 @@ export const streamNormalInput = createAsyncThunk< console.error("Failed to send dev data interaction log", e); } } - + // Check if we have any tool calls that were just generated const newState = getState(); const toolSettings = newState.ui.toolSettings; @@ -284,14 +294,16 @@ export const streamNormalInput = createAsyncThunk< const generatingToolCalls = allToolCallStates.filter( (toolCallState) => toolCallState.status === "generating", ); - + // Check if ALL generating tool calls are auto-approved - const allAutoApproved = generatingToolCalls.length > 0 && + const allAutoApproved = + generatingToolCalls.length > 0 && generatingToolCalls.every( (toolCallState) => - toolSettings[toolCallState.toolCall.function.name] === "allowedWithoutPermission", + toolSettings[toolCallState.toolCall.function.name] === + "allowedWithoutPermission", ); - + // Only set inactive if: // 1. There are no tool calls, OR // 2. There are tool calls but they require manual approval @@ -299,7 +311,7 @@ export const streamNormalInput = createAsyncThunk< if (generatingToolCalls.length === 0 || !allAutoApproved) { dispatch(setInactive()); } - + await handleToolCallExecution(dispatch, getState); }, );