Elffuss BraidHub

kikocis/continue public

Merge pull request #6425 from continuedev/adarsh/feat/toolusage-fix

ToolUsage dev data updates
Changeset3f3908bcc0f48f3c8301dc8ab993d5def3f0a1124be4bd3b2e9bdaa539548039
AuthorDallin Romney <dallinromney@gmail.com> · 2025-07-02 20:10 -07:00
CommitterGitHub <noreply@github.com> · 2025-07-02 20:10 -07:00
Parentsedd4775c6fd9, 496718a3e289

Browse the files at this changeset

10 files changed

modified core/index.d.ts +1 −0
@@ -443,6 +443,7 @@
443443 status: ToolStatus;
444444 parsedArgs: any;
445445 output?: ContextItem[];
446+ tool?: Tool;
446447 }
447448
448449 interface Reasoning {
modified core/tools/callTool.ts +0 −23
@@ -1,6 +1,5 @@
11 import { ContextItem, Tool, ToolCall, ToolExtras } from "..";
22 import { MCPManagerSingleton } from "../context/mcp/MCPManagerSingleton";
3-import { DataLogger } from "../data/log";
43 import { canParseUrl } from "../util/url";
54 import { BuiltInToolNames } from "./builtIn";
65
@@ -173,26 +172,6 @@
173172 }
174173 }
175174
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-
196175 // Handles calls for core/non-client tools
197176 // Returns an error context item if the tool call fails
198177 // Note: Edit tool is handled on client
@@ -214,7 +193,6 @@
214193 item.icon = tool.faviconUrl;
215194 });
216195 }
217- logToolUsage(toolCall, args, contextItems, true);
218196 return {
219197 contextItems,
220198 errorMessage: undefined,
@@ -224,7 +202,6 @@
224202 if (e instanceof Error) {
225203 errorMessage = e.message;
226204 }
227- logToolUsage(toolCall, {}, [], false);
228205 return {
229206 contextItems: [],
230207 errorMessage,
modified gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx +5 −1
@@ -1,9 +1,11 @@
1-import { useEffect } from "react";
1+import { useContext, useEffect } from "react";
22 import { useSelector } from "react-redux";
3+import { IdeMessengerContext } from "../../../../context/IdeMessenger";
34 import { useAppDispatch, useAppSelector } from "../../../../redux/hooks";
45 import { selectCurrentToolCall } from "../../../../redux/selectors/selectCurrentToolCall";
56 import { cancelToolCall } from "../../../../redux/slices/sessionSlice";
67 import { callCurrentTool } from "../../../../redux/thunks/callCurrentTool";
8+import { logToolUsage } from "../../../../redux/util";
79 import { isJetBrains } from "../../../../util";
810 import { BlockSettingsTopToolbar } from "./BlockSettingsTopToolbar";
911 import { EditOutcomeToolbar } from "./EditOutcomeToolbar";
@@ -50,6 +52,8 @@
5052 } else if ((jetbrains ? altKey : metaKey) && event.key === "Backspace") {
5153 event.preventDefault();
5254 event.stopPropagation();
55+ const ideMessenger = useContext(IdeMessengerContext);
56+ logToolUsage(toolCallState, false, true, ideMessenger);
5357 void dispatch(
5458 cancelToolCall({
5559 toolCallId: toolCallState.toolCallId,
modified gui/src/hooks/ParallelListeners.tsx +9 −0
@@ -28,10 +28,12 @@
2828 import { exitEdit } from "../redux/thunks/edit";
2929 import { streamResponseAfterToolCall } from "../redux/thunks/streamResponseAfterToolCall";
3030
31+import { store } from "../redux/store";
3132 import { cancelStream } from "../redux/thunks/cancelStream";
3233 import { refreshSessionMetadata } from "../redux/thunks/session";
3334 import { streamResponseThunk } from "../redux/thunks/streamResponse";
3435 import { updateFileSymbolsFromHistory } from "../redux/thunks/updateFileSymbols";
36+import { findToolCall, logToolUsage } from "../redux/util";
3537 import {
3638 setDocumentStylesFromLocalStorage,
3739 setDocumentStylesFromTheme,
@@ -257,6 +259,13 @@
257259 dispatch(updateEditStateApplyState(state));
258260
259261 if (state.status === "closed") {
262+ const toolCallState = findToolCall(
263+ store.getState().session.history,
264+ state.toolCallId!,
265+ );
266+ if (toolCallState) {
267+ logToolUsage(toolCallState, true, true, ideMessenger);
268+ }
260269 void dispatch(exitEdit({}));
261270 }
262271 } else {
modified gui/src/redux/slices/sessionSlice.ts +9 −0
@@ -18,6 +18,7 @@
1818 RuleWithSource,
1919 Session,
2020 SessionMetadata,
21+ Tool,
2122 } from "core";
2223 import { NEW_SESSION_TITLE } from "core/util/constants";
2324 import {
@@ -535,6 +536,7 @@
535536 state,
536537 action: PayloadAction<{
537538 toolCallId: string;
539+ tools: Tool[];
538540 }>,
539541 ) => {
540542 const toolCallState = findToolCall(
@@ -543,6 +545,13 @@
543545 );
544546 if (toolCallState) {
545547 toolCallState.status = "generated";
548+
549+ const tool = action.payload.tools.find(
550+ (t) => t.function.name === toolCallState.toolCall.function.name,
551+ );
552+ if (tool) {
553+ toolCallState.tool = tool;
554+ }
546555 }
547556 },
548557 updateToolCallOutput: (
modified gui/src/redux/thunks/callCurrentTool.ts +2 −4
@@ -101,8 +101,6 @@
101101 ],
102102 }),
103103 );
104-
105- logToolUsage(toolCallState, false, extra.ideMessenger, output);
106104 } else if (output?.length) {
107105 dispatch(
108106 updateToolCallOutput({
@@ -110,8 +108,6 @@
110108 contextItems: output,
111109 }),
112110 );
113-
114- logToolUsage(toolCallState, true, extra.ideMessenger, output);
115111 }
116112
117113 // Because we don't have access to use hooks, we check `allowAnonymousTelemetry`
@@ -127,12 +123,14 @@
127123
128124 if (streamResponse) {
129125 if (errorMessage) {
126+ logToolUsage(toolCallState, false, false, extra.ideMessenger, output);
130127 dispatch(
131128 errorToolCall({
132129 toolCallId,
133130 }),
134131 );
135132 } else {
133+ logToolUsage(toolCallState, true, true, extra.ideMessenger, output);
136134 dispatch(
137135 acceptToolCall({
138136 toolCallId,
modified gui/src/redux/thunks/streamNormalInput.ts +1 −0
@@ -154,6 +154,7 @@
154154 dispatch(
155155 setToolGenerated({
156156 toolCallId: toolCallState.toolCallId,
157+ tools: state.config.config.tools,
157158 }),
158159 );
159160
modified gui/src/redux/util/index.ts +10 −5
@@ -1,5 +1,4 @@
11 import { ContextItem, ToolCallState } from "core";
2-import { safeParseToolCallArgs } from "core/tools/parseArgs";
32 import { IIdeMessenger } from "../../context/IdeMessenger";
43 import { ChatHistoryItemWithMessageId } from "../slices/sessionSlice";
54 import { RootState } from "../store";
@@ -32,6 +31,7 @@
3231
3332 export function logToolUsage(
3433 toolCallState: ToolCallState,
34+ accepted: boolean,
3535 success: boolean,
3636 messenger: IIdeMessenger,
3737 finalOutput?: ContextItem[],
@@ -40,10 +40,15 @@
4040 name: "toolUsage",
4141 data: {
4242 toolCallId: toolCallState.toolCallId,
43- functionName: toolCallState.toolCall?.function?.name,
44- functionArgs: toolCallState.toolCall?.function?.arguments,
45- toolCallArgs: safeParseToolCallArgs(toolCallState.toolCall),
46- parsedArgs: toolCallState.parsedArgs,
43+
44+ functionName:
45+ toolCallState.tool?.function?.name ||
46+ toolCallState.toolCall.function.name,
47+
48+ functionParams: toolCallState.tool?.function.parameters,
49+
50+ toolCallArgs: toolCallState.toolCall.function.arguments,
51+ accepted: accepted,
4752 output: finalOutput || toolCallState.output || [],
4853 succeeded: success,
4954 },
modified packages/config-yaml/src/schemas/data/toolUsage/index.ts +3 −3
@@ -4,9 +4,9 @@
44 export const toolUsageEventAllSchema = baseDevDataAllSchema.extend({
55 toolCallId: z.string(),
66 functionName: z.string(),
7- functionArgs: z.string(),
8- toolCallArgs: z.any(),
9- parsedArgs: z.any(),
7+ functionParams: z.record(z.string(), z.any()).optional(),
8+ toolCallArgs: z.string(),
9+ accepted: z.boolean(),
1010 succeeded: z.boolean(),
1111 output: z.array(z.any()).optional(),
1212 });
modified packages/config-yaml/src/schemas/data/toolUsage/v0.2.0.ts +4 −4
@@ -12,16 +12,16 @@
1212 // tool-usage-specific
1313 toolCallId: true,
1414 functionName: true,
15- functionArgs: true,
15+ functionParams: true,
1616 toolCallArgs: true,
17- parsedArgs: true,
17+ accepted: true,
1818 succeeded: true,
1919 output: true,
2020 });
2121
2222 export const toolUsageEventSchema_0_2_0_noCode =
2323 toolUsageEventSchema_0_2_0.omit({
24- functionArgs: true,
25- parsedArgs: true,
24+ functionParams: true,
25+ toolCallArgs: true,
2626 output: true,
2727 });