finished out tool usage dev data logging

This commit is contained in:
adarshramiyer 2025-06-25 18:30:26 -07:00
parent 15c672c16f
commit 9b4ec0a3a4
4 changed files with 34 additions and 1 deletions

View file

@ -18,7 +18,9 @@ import {
RuleWithSource,
Session,
SessionMetadata,
ToolCallState,
} from "core";
import { safeParseToolCallArgs } from "core/tools/parseArgs";
import { NEW_SESSION_TITLE } from "core/util/constants";
import { renderChatMessage } from "core/util/messageContent";
import { findUriInDirs, getUriPathBasename } from "core/util/uri";
@ -28,6 +30,25 @@ import { RootState } from "../store";
import { streamResponseThunk } from "../thunks/streamResponse";
import { findCurrentToolCall, findToolCall } from "../util";
const getIdeMessenger = () => (window as any).ideMessenger;
const logToolUsage = (toolCallState: ToolCallState, success: boolean) => {
const ideMessenger = getIdeMessenger();
if (ideMessenger) {
ideMessenger.post("devdata/log", {
name: "toolUsage",
data: {
toolCallId: toolCallState.toolCallId,
functionName: toolCallState.toolCall.function.name,
functionArgs: toolCallState.toolCall.function.arguments,
parsedArgs: safeParseToolCallArgs(toolCallState.toolCall),
succeeded: success,
output: toolCallState.output || [],
},
});
}
};
// 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 & {
@ -559,6 +580,7 @@ export const sessionSlice = createSlice({
);
if (toolCallState) {
toolCallState.status = "errored";
logToolUsage(toolCallState, false);
}
},
acceptToolCall: (
@ -573,6 +595,7 @@ export const sessionSlice = createSlice({
);
if (toolCallState) {
toolCallState.status = "done";
logToolUsage(toolCallState, true);
}
},
setToolCallCalling: (

View file

@ -42,6 +42,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-]+)*))?$/;
@ -72,6 +77,7 @@ const devEventAllVersionDataSchemas = z.object({
tokensGenerated: tokensGeneratedEventAllSchema,
chatInteraction: chatInteractionEventAllSchema,
editInteraction: editInteractionEventAllSchema,
toolUsage: toolUsageEventAllSchema,
});
// Version and level specific schemas are organized here
@ -97,6 +103,7 @@ export const devDataVersionedSchemas = {
tokensGenerated: tokensGeneratedEventSchema_0_2_0,
chatInteraction: chatInteractionEventSchema_0_2_0,
editInteraction: editInteractionEventSchema_0_2_0,
toolUsage: toolUsageEventSchema_0_2_0,
},
noCode: {
autocomplete: autocompleteEventSchema_0_2_0_noCode,
@ -104,6 +111,7 @@ export const devDataVersionedSchemas = {
tokensGenerated: tokensGeneratedEventSchema_0_2_0_noCode,
chatInteraction: chatInteractionEventSchema_0_2_0_noCode,
editInteraction: editInteractionEventSchema_0_2_0_noCode,
toolUsage: toolUsageEventSchema_0_2_0_noCode,
},
},
};

View file

@ -6,5 +6,6 @@ export const toolUsageEventAllSchema = baseDevDataAllSchema.extend({
functionName: z.string(),
functionArgs: z.string(),
parsedArgs: z.any(),
succeeded: z.boolean(),
output: z.array(z.any()).optional(),
});

View file

@ -14,10 +14,11 @@ export const toolUsageEventSchema_0_2_0 = toolUsageEventAllSchema.pick({
functionName: true,
functionArgs: true,
parsedArgs: true,
succeeded: true,
output: true,
});
export const autocompleteEventSchema_0_2_0_noCode =
export const toolUsageEventSchema_0_2_0_noCode =
toolUsageEventSchema_0_2_0.omit({
functionArgs: true,
parsedArgs: true,