Merge pull request #6299 from continuedev/adarsh/feat/devdata-toolusage
Dev data: added tool usage event
This commit is contained in:
commit
bf1e97bc7c
4 changed files with 68 additions and 0 deletions
|
|
@ -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: (
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
|||
11
packages/config-yaml/src/schemas/data/toolUsage/index.ts
Normal file
11
packages/config-yaml/src/schemas/data/toolUsage/index.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import { z } from "zod";
|
||||
import { baseDevDataAllSchema } from "../base.js";
|
||||
|
||||
export const toolUsageEventAllSchema = baseDevDataAllSchema.extend({
|
||||
toolCallId: z.string(),
|
||||
functionName: z.string(),
|
||||
functionArgs: z.string(),
|
||||
parsedArgs: z.any(),
|
||||
succeeded: z.boolean(),
|
||||
output: z.array(z.any()).optional(),
|
||||
});
|
||||
26
packages/config-yaml/src/schemas/data/toolUsage/v0.2.0.ts
Normal file
26
packages/config-yaml/src/schemas/data/toolUsage/v0.2.0.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
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,
|
||||
parsedArgs: true,
|
||||
succeeded: true,
|
||||
output: true,
|
||||
});
|
||||
|
||||
export const toolUsageEventSchema_0_2_0_noCode =
|
||||
toolUsageEventSchema_0_2_0.omit({
|
||||
functionArgs: true,
|
||||
parsedArgs: true,
|
||||
output: true,
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue