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

toolUsage devdata events
This commit is contained in:
Nate Sesti 2025-07-01 13:54:04 -07:00 • committed by GitHub
commit 130c1e02bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 108 additions and 5 deletions

View file

@ -872,7 +872,7 @@ export class Core {
this.messenger.send("toolCallPartialOutput", params);
};
return await callTool(tool, toolCall, {
const result = await callTool(tool, toolCall, {
config,
ide: this.ide,
llm: config.selectedModelByRole.chat,
@ -883,6 +883,8 @@ export class Core {
onPartialOutput,
codeBaseIndexer: this.codeBaseIndexer,
});
return result;
}
private async isItemTooBig(item: ContextItemWithId) {

View file

@ -1,5 +1,6 @@
import { ContextItem, Tool, ToolCall, ToolExtras } from "..";
import { MCPManagerSingleton } from "../context/mcp/MCPManagerSingleton";
import { DataLogger } from "../data/log";
import { canParseUrl } from "../util/url";
import { BuiltInToolNames } from "./builtIn";
@ -172,6 +173,26 @@ async function callBuiltInTool(
}
}
function logToolUsage(
toolCall: ToolCall,
args: Record<string, any>,
contextItems: ContextItem[],
success: boolean,
) {
void DataLogger.getInstance().logDevData({
name: "toolUsage",
data: {
toolCallId: toolCall.id,
functionName: toolCall.function.name,
functionArgs: toolCall.function.arguments,
toolCallArgs: args,
parsedArgs: args,
output: contextItems,
succeeded: success,
},
});
}
// Handles calls for core/non-client tools
// Returns an error context item if the tool call fails
// Note: Edit tool is handled on client
@ -193,6 +214,7 @@ export async function callTool(
item.icon = tool.faviconUrl;
});
}
logToolUsage(toolCall, args, contextItems, true);
return {
contextItems,
errorMessage: undefined,
@ -202,6 +224,7 @@ export async function callTool(
if (e instanceof Error) {
errorMessage = e.message;
}
logToolUsage(toolCall, {}, [], false);
return {
contextItems: [],
errorMessage,

View file

@ -107,7 +107,7 @@
"@continuedev/config-yaml": "file:../packages/config-yaml",
"@continuedev/fetch": "^1.0.14",
"@continuedev/llm-info": "^1.0.8",
"@continuedev/openai-adapters": "file:../packages/openai-adapters",
"@continuedev/openai-adapters": "1.0.42",
"@modelcontextprotocol/sdk": "^1.12.0",
"@mozilla/readability": "^0.5.0",
"@octokit/rest": "^20.1.1",

View file

@ -2,7 +2,7 @@
"name": "continue",
"icon": "media/icon.png",
"author": "Continue Dev, Inc",
"version": "1.1.53",
"version": "1.1.54",
"repository": {
"type": "git",
"url": "https://github.com/continuedev/continue"

2
gui/package-lock.json generated
View file

@ -116,7 +116,7 @@
"@continuedev/config-yaml": "file:../packages/config-yaml",
"@continuedev/fetch": "^1.0.14",
"@continuedev/llm-info": "^1.0.8",
"@continuedev/openai-adapters": "file:../packages/openai-adapters",
"@continuedev/openai-adapters": "1.0.42",
"@modelcontextprotocol/sdk": "^1.12.0",
"@mozilla/readability": "^0.5.0",
"@octokit/rest": "^20.1.1",

View file

@ -28,6 +28,8 @@ import { RootState } from "../store";
import { streamResponseThunk } from "../thunks/streamResponse";
import { findCurrentToolCall, findToolCall } from "../util";
const getIdeMessenger = () => (window as any).ideMessenger;
// We need this to handle reorderings (e.g. a mid-array deletion) of the messages array.
// The proper fix is adding a UUID to all chat messages, but this is the temp workaround.
export type ChatHistoryItemWithMessageId = ChatHistoryItem & {

View file

@ -12,6 +12,7 @@ import {
updateToolCallOutput,
} from "../slices/sessionSlice";
import { ThunkApiType } from "../store";
import { logToolUsage } from "../util";
import { streamResponseAfterToolCall } from "./streamResponseAfterToolCall";
export const callCurrentTool = createAsyncThunk<void, undefined, ThunkApiType>(
@ -100,6 +101,8 @@ export const callCurrentTool = createAsyncThunk<void, undefined, ThunkApiType>(
],
}),
);
logToolUsage(toolCallState, false, extra.ideMessenger, output);
} else if (output?.length) {
dispatch(
updateToolCallOutput({
@ -107,6 +110,8 @@ export const callCurrentTool = createAsyncThunk<void, undefined, ThunkApiType>(
contextItems: output,
}),
);
logToolUsage(toolCallState, true, extra.ideMessenger, output);
}
// Because we don't have access to use hooks, we check `allowAnonymousTelemetry`

View file

@ -1,4 +1,6 @@
import { ToolCallState } from "core";
import { ContextItem, ToolCallState } from "core";
import { safeParseToolCallArgs } from "core/tools/parseArgs";
import { IIdeMessenger } from "../../context/IdeMessenger";
import { RootState } from "../store";
export function findCurrentToolCall(
@ -15,3 +17,23 @@ export function findToolCall(
(item) => item.toolCallState?.toolCallId === toolCallId,
)?.toolCallState;
}
export function logToolUsage(
toolCallState: ToolCallState,
success: boolean,
messenger: IIdeMessenger,
finalOutput?: ContextItem[],
) {
messenger.post("devdata/log", {
name: "toolUsage",
data: {
toolCallId: toolCallState.toolCallId,
functionName: toolCallState.toolCall?.function?.name,
functionArgs: toolCallState.toolCall?.function?.arguments,
toolCallArgs: safeParseToolCallArgs(toolCallState.toolCall),
parsedArgs: toolCallState.parsedArgs,
output: finalOutput || toolCallState.output || [],
succeeded: success,
},
});
}

View file

@ -28,6 +28,7 @@ import {
editInteractionEventSchema_0_2_0,
editInteractionEventSchema_0_2_0_noCode,
} from "./editInteraction/v0.2.0.js";
import { editOutcomeEventAllSchema } from "./editOutcome/index.js";
import {
editOutcomeEventSchema_0_2_0,
editOutcomeEventSchema_0_2_0_noCode,
@ -51,6 +52,11 @@ import {
tokensGeneratedEventSchema_0_2_0,
tokensGeneratedEventSchema_0_2_0_noCode,
} from "./tokensGenerated/v0.2.0.js";
import { toolUsageEventAllSchema } from "./toolUsage/index.js";
import {
toolUsageEventSchema_0_2_0,
toolUsageEventSchema_0_2_0_noCode,
} from "./toolUsage/v0.2.0.js";
const semverRegex =
/^(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 @@ const devEventAllVersionDataSchemas = z.object({
tokensGenerated: tokensGeneratedEventAllSchema,
chatInteraction: chatInteractionEventAllSchema,
editInteraction: editInteractionEventAllSchema,
editOutcome: editOutcomeEventAllSchema,
nextEdit: nextEditEventAllSchema,
toolUsage: toolUsageEventAllSchema,
});
// Version and level specific schemas are organized here
@ -109,6 +117,7 @@ export const devDataVersionedSchemas = {
editInteraction: editInteractionEventSchema_0_2_0,
editOutcome: editOutcomeEventSchema_0_2_0,
nextEdit: nextEditEventSchema_0_2_0,
toolUsage: toolUsageEventSchema_0_2_0,
},
noCode: {
autocomplete: autocompleteEventSchema_0_2_0_noCode,
@ -118,6 +127,7 @@ export const devDataVersionedSchemas = {
editInteraction: editInteractionEventSchema_0_2_0_noCode,
editOutcome: editOutcomeEventSchema_0_2_0_noCode,
nextEdit: nextEditEventSchema_0_2_0_noCode,
toolUsage: toolUsageEventSchema_0_2_0_noCode,
},
},
};

View file

@ -0,0 +1,12 @@
import { z } from "zod";
import { baseDevDataAllSchema } from "../base.js";
export const toolUsageEventAllSchema = baseDevDataAllSchema.extend({
toolCallId: z.string(),
functionName: z.string(),
functionArgs: z.string(),
toolCallArgs: z.any(),
parsedArgs: z.any(),
succeeded: z.boolean(),
output: z.array(z.any()).optional(),
});

View file

@ -0,0 +1,27 @@
import { toolUsageEventAllSchema } from "./index.js";
export const toolUsageEventSchema_0_2_0 = toolUsageEventAllSchema.pick({
// base
timestamp: true,
userId: true,
userAgent: true,
selectedProfileId: true,
eventName: true,
schema: true,
// tool-usage-specific
toolCallId: true,
functionName: true,
functionArgs: true,
toolCallArgs: true,
parsedArgs: true,
succeeded: true,
output: true,
});
export const toolUsageEventSchema_0_2_0_noCode =
toolUsageEventSchema_0_2_0.omit({
functionArgs: true,
parsedArgs: true,
output: true,
});