feat: telemetry
This commit is contained in:
parent
74e0564a4d
commit
a9e5b37d0e
4 changed files with 47 additions and 9 deletions
|
|
@ -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 (
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
26
gui/src/redux/thunks/cancelToolCall.ts
Normal file
26
gui/src/redux/thunks/cancelToolCall.ts
Normal file
|
|
@ -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 }));
|
||||
});
|
||||
|
|
@ -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);
|
||||
},
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue