Elffuss BraidHub

kikocis/continue public

Merge pull request #6315 from continuedev/adarsh/feat/devdata-toolusage

toolUsage devdata events
Changeset7f8b1ea26802a360dcbedc46d5449295b3363d54548cdd3463bcc15cf306c6c9
AuthorNate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-07-01 13:54 -07:00
CommitterGitHub <noreply@github.com> · 2025-07-01 13:54 -07:00
Parents54bc82ab2ee9, 0e93a6dcb1e3

Browse the files at this changeset

11 files changed

modified core/core.ts +3 −1
@@ -872,7 +872,7 @@
872872 this.messenger.send("toolCallPartialOutput", params);
873873 };
874874
875- return await callTool(tool, toolCall, {
875+ const result = await callTool(tool, toolCall, {
876876 config,
877877 ide: this.ide,
878878 llm: config.selectedModelByRole.chat,
@@ -883,6 +883,8 @@
883883 onPartialOutput,
884884 codeBaseIndexer: this.codeBaseIndexer,
885885 });
886+
887+ return result;
886888 }
887889
888890 private async isItemTooBig(item: ContextItemWithId) {
modified core/tools/callTool.ts +23 −0
@@ -1,5 +1,6 @@
11 import { ContextItem, Tool, ToolCall, ToolExtras } from "..";
22 import { MCPManagerSingleton } from "../context/mcp/MCPManagerSingleton";
3+import { DataLogger } from "../data/log";
34 import { canParseUrl } from "../util/url";
45 import { BuiltInToolNames } from "./builtIn";
56
@@ -172,6 +173,26 @@
172173 }
173174 }
174175
176+function logToolUsage(
177+ toolCall: ToolCall,
178+ args: Record<string, any>,
179+ contextItems: ContextItem[],
180+ success: boolean,
181+) {
182+ void DataLogger.getInstance().logDevData({
183+ name: "toolUsage",
184+ data: {
185+ toolCallId: toolCall.id,
186+ functionName: toolCall.function.name,
187+ functionArgs: toolCall.function.arguments,
188+ toolCallArgs: args,
189+ parsedArgs: args,
190+ output: contextItems,
191+ succeeded: success,
192+ },
193+ });
194+}
195+
175196 // Handles calls for core/non-client tools
176197 // Returns an error context item if the tool call fails
177198 // Note: Edit tool is handled on client
@@ -193,6 +214,7 @@
193214 item.icon = tool.faviconUrl;
194215 });
195216 }
217+ logToolUsage(toolCall, args, contextItems, true);
196218 return {
197219 contextItems,
198220 errorMessage: undefined,
@@ -202,6 +224,7 @@
202224 if (e instanceof Error) {
203225 errorMessage = e.message;
204226 }
227+ logToolUsage(toolCall, {}, [], false);
205228 return {
206229 contextItems: [],
207230 errorMessage,
modified extensions/vscode/package-lock.json +0 −0

Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.

modified extensions/vscode/package.json +1 −1
@@ -2,7 +2,7 @@
22 "name": "continue",
33 "icon": "media/icon.png",
44 "author": "Continue Dev, Inc",
5- "version": "1.1.53",
5+ "version": "1.1.54",
66 "repository": {
77 "type": "git",
88 "url": "https://github.com/continuedev/continue"
modified gui/package-lock.json +0 −0

Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.

modified gui/src/redux/slices/sessionSlice.ts +2 −0
@@ -28,6 +28,8 @@
2828 import { streamResponseThunk } from "../thunks/streamResponse";
2929 import { findCurrentToolCall, findToolCall } from "../util";
3030
31+const getIdeMessenger = () => (window as any).ideMessenger;
32+
3133 // We need this to handle reorderings (e.g. a mid-array deletion) of the messages array.
3234 // The proper fix is adding a UUID to all chat messages, but this is the temp workaround.
3335 export type ChatHistoryItemWithMessageId = ChatHistoryItem & {
modified gui/src/redux/thunks/callCurrentTool.ts +5 −0
@@ -12,6 +12,7 @@
1212 updateToolCallOutput,
1313 } from "../slices/sessionSlice";
1414 import { ThunkApiType } from "../store";
15+import { logToolUsage } from "../util";
1516 import { streamResponseAfterToolCall } from "./streamResponseAfterToolCall";
1617
1718 export const callCurrentTool = createAsyncThunk<void, undefined, ThunkApiType>(
@@ -100,6 +101,8 @@
100101 ],
101102 }),
102103 );
104+
105+ logToolUsage(toolCallState, false, extra.ideMessenger, output);
103106 } else if (output?.length) {
104107 dispatch(
105108 updateToolCallOutput({
@@ -107,6 +110,8 @@
107110 contextItems: output,
108111 }),
109112 );
113+
114+ logToolUsage(toolCallState, true, extra.ideMessenger, output);
110115 }
111116
112117 // Because we don't have access to use hooks, we check `allowAnonymousTelemetry`
modified gui/src/redux/util/index.ts +23 −1
@@ -1,4 +1,6 @@
1-import { ToolCallState } from "core";
1+import { ContextItem, ToolCallState } from "core";
2+import { safeParseToolCallArgs } from "core/tools/parseArgs";
3+import { IIdeMessenger } from "../../context/IdeMessenger";
24 import { RootState } from "../store";
35
46 export function findCurrentToolCall(
@@ -15,3 +17,23 @@
1517 (item) => item.toolCallState?.toolCallId === toolCallId,
1618 )?.toolCallState;
1719 }
20+
21+export function logToolUsage(
22+ toolCallState: ToolCallState,
23+ success: boolean,
24+ messenger: IIdeMessenger,
25+ finalOutput?: ContextItem[],
26+) {
27+ messenger.post("devdata/log", {
28+ name: "toolUsage",
29+ data: {
30+ toolCallId: toolCallState.toolCallId,
31+ functionName: toolCallState.toolCall?.function?.name,
32+ functionArgs: toolCallState.toolCall?.function?.arguments,
33+ toolCallArgs: safeParseToolCallArgs(toolCallState.toolCall),
34+ parsedArgs: toolCallState.parsedArgs,
35+ output: finalOutput || toolCallState.output || [],
36+ succeeded: success,
37+ },
38+ });
39+}
modified packages/config-yaml/src/schemas/data/index.ts +10 −0
@@ -28,6 +28,7 @@
2828 editInteractionEventSchema_0_2_0,
2929 editInteractionEventSchema_0_2_0_noCode,
3030 } from "./editInteraction/v0.2.0.js";
31+import { editOutcomeEventAllSchema } from "./editOutcome/index.js";
3132 import {
3233 editOutcomeEventSchema_0_2_0,
3334 editOutcomeEventSchema_0_2_0_noCode,
@@ -51,6 +52,11 @@
5152 tokensGeneratedEventSchema_0_2_0,
5253 tokensGeneratedEventSchema_0_2_0_noCode,
5354 } from "./tokensGenerated/v0.2.0.js";
55+import { toolUsageEventAllSchema } from "./toolUsage/index.js";
56+import {
57+ toolUsageEventSchema_0_2_0,
58+ toolUsageEventSchema_0_2_0_noCode,
59+} from "./toolUsage/v0.2.0.js";
5460
5561 const semverRegex =
5662 /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;
@@ -81,7 +87,9 @@
8187 tokensGenerated: tokensGeneratedEventAllSchema,
8288 chatInteraction: chatInteractionEventAllSchema,
8389 editInteraction: editInteractionEventAllSchema,
90+ editOutcome: editOutcomeEventAllSchema,
8491 nextEdit: nextEditEventAllSchema,
92+ toolUsage: toolUsageEventAllSchema,
8593 });
8694
8795 // Version and level specific schemas are organized here
@@ -109,6 +117,7 @@
109117 editInteraction: editInteractionEventSchema_0_2_0,
110118 editOutcome: editOutcomeEventSchema_0_2_0,
111119 nextEdit: nextEditEventSchema_0_2_0,
120+ toolUsage: toolUsageEventSchema_0_2_0,
112121 },
113122 noCode: {
114123 autocomplete: autocompleteEventSchema_0_2_0_noCode,
@@ -118,6 +127,7 @@
118127 editInteraction: editInteractionEventSchema_0_2_0_noCode,
119128 editOutcome: editOutcomeEventSchema_0_2_0_noCode,
120129 nextEdit: nextEditEventSchema_0_2_0_noCode,
130+ toolUsage: toolUsageEventSchema_0_2_0_noCode,
121131 },
122132 },
123133 };
added packages/config-yaml/src/schemas/data/toolUsage/index.ts +12 −0
@@ -0,0 +1,12 @@
1+import { z } from "zod";
2+import { baseDevDataAllSchema } from "../base.js";
3+
4+export const toolUsageEventAllSchema = baseDevDataAllSchema.extend({
5+ toolCallId: z.string(),
6+ functionName: z.string(),
7+ functionArgs: z.string(),
8+ toolCallArgs: z.any(),
9+ parsedArgs: z.any(),
10+ succeeded: z.boolean(),
11+ output: z.array(z.any()).optional(),
12+});
added packages/config-yaml/src/schemas/data/toolUsage/v0.2.0.ts +27 −0
@@ -0,0 +1,27 @@
1+import { toolUsageEventAllSchema } from "./index.js";
2+
3+export const toolUsageEventSchema_0_2_0 = toolUsageEventAllSchema.pick({
4+ // base
5+ timestamp: true,
6+ userId: true,
7+ userAgent: true,
8+ selectedProfileId: true,
9+ eventName: true,
10+ schema: true,
11+
12+ // tool-usage-specific
13+ toolCallId: true,
14+ functionName: true,
15+ functionArgs: true,
16+ toolCallArgs: true,
17+ parsedArgs: true,
18+ succeeded: true,
19+ output: true,
20+});
21+
22+export const toolUsageEventSchema_0_2_0_noCode =
23+ toolUsageEventSchema_0_2_0.omit({
24+ functionArgs: true,
25+ parsedArgs: true,
26+ output: true,
27+ });