Changesets · Branches · Tags · Compare
| Changeset | 3f3908bcc0f48f3c8301dc8ab993d5def3f0a1124be4bd3b2e9bdaa539548039 |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-07-02 20:10 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-07-02 20:10 -07:00 |
| Parents | edd4775c6fd9, 496718a3e289 |
10 files changed
modified core/index.d.ts +1 −0
| @@ -443,6 +443,7 @@ | ||
| 443 | 443 | status: ToolStatus; |
| 444 | 444 | parsedArgs: any; |
| 445 | 445 | output?: ContextItem[]; |
| 446 | + tool?: Tool; | |
| 446 | 447 | } |
| 447 | 448 | |
| 448 | 449 | interface Reasoning { |
modified core/tools/callTool.ts +0 −23
| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | import { ContextItem, Tool, ToolCall, ToolExtras } from ".."; |
| 2 | 2 | import { MCPManagerSingleton } from "../context/mcp/MCPManagerSingleton"; |
| 3 | -import { DataLogger } from "../data/log"; | |
| 4 | 3 | import { canParseUrl } from "../util/url"; |
| 5 | 4 | import { BuiltInToolNames } from "./builtIn"; |
| 6 | 5 | |
| @@ -173,26 +172,6 @@ | ||
| 173 | 172 | } |
| 174 | 173 | } |
| 175 | 174 | |
| 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 | - | |
| 196 | 175 | // Handles calls for core/non-client tools |
| 197 | 176 | // Returns an error context item if the tool call fails |
| 198 | 177 | // Note: Edit tool is handled on client |
| @@ -214,7 +193,6 @@ | ||
| 214 | 193 | item.icon = tool.faviconUrl; |
| 215 | 194 | }); |
| 216 | 195 | } |
| 217 | - logToolUsage(toolCall, args, contextItems, true); | |
| 218 | 196 | return { |
| 219 | 197 | contextItems, |
| 220 | 198 | errorMessage: undefined, |
| @@ -224,7 +202,6 @@ | ||
| 224 | 202 | if (e instanceof Error) { |
| 225 | 203 | errorMessage = e.message; |
| 226 | 204 | } |
| 227 | - logToolUsage(toolCall, {}, [], false); | |
| 228 | 205 | return { |
| 229 | 206 | contextItems: [], |
| 230 | 207 | 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"; | |
| 2 | 2 | import { useSelector } from "react-redux"; |
| 3 | +import { IdeMessengerContext } from "../../../../context/IdeMessenger"; | |
| 3 | 4 | import { useAppDispatch, useAppSelector } from "../../../../redux/hooks"; |
| 4 | 5 | import { selectCurrentToolCall } from "../../../../redux/selectors/selectCurrentToolCall"; |
| 5 | 6 | import { cancelToolCall } from "../../../../redux/slices/sessionSlice"; |
| 6 | 7 | import { callCurrentTool } from "../../../../redux/thunks/callCurrentTool"; |
| 8 | +import { logToolUsage } from "../../../../redux/util"; | |
| 7 | 9 | import { isJetBrains } from "../../../../util"; |
| 8 | 10 | import { BlockSettingsTopToolbar } from "./BlockSettingsTopToolbar"; |
| 9 | 11 | import { EditOutcomeToolbar } from "./EditOutcomeToolbar"; |
| @@ -50,6 +52,8 @@ | ||
| 50 | 52 | } else if ((jetbrains ? altKey : metaKey) && event.key === "Backspace") { |
| 51 | 53 | event.preventDefault(); |
| 52 | 54 | event.stopPropagation(); |
| 55 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 56 | + logToolUsage(toolCallState, false, true, ideMessenger); | |
| 53 | 57 | void dispatch( |
| 54 | 58 | cancelToolCall({ |
| 55 | 59 | toolCallId: toolCallState.toolCallId, |
modified gui/src/hooks/ParallelListeners.tsx +9 −0
| @@ -28,10 +28,12 @@ | ||
| 28 | 28 | import { exitEdit } from "../redux/thunks/edit"; |
| 29 | 29 | import { streamResponseAfterToolCall } from "../redux/thunks/streamResponseAfterToolCall"; |
| 30 | 30 | |
| 31 | +import { store } from "../redux/store"; | |
| 31 | 32 | import { cancelStream } from "../redux/thunks/cancelStream"; |
| 32 | 33 | import { refreshSessionMetadata } from "../redux/thunks/session"; |
| 33 | 34 | import { streamResponseThunk } from "../redux/thunks/streamResponse"; |
| 34 | 35 | import { updateFileSymbolsFromHistory } from "../redux/thunks/updateFileSymbols"; |
| 36 | +import { findToolCall, logToolUsage } from "../redux/util"; | |
| 35 | 37 | import { |
| 36 | 38 | setDocumentStylesFromLocalStorage, |
| 37 | 39 | setDocumentStylesFromTheme, |
| @@ -257,6 +259,13 @@ | ||
| 257 | 259 | dispatch(updateEditStateApplyState(state)); |
| 258 | 260 | |
| 259 | 261 | 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 | + } | |
| 260 | 269 | void dispatch(exitEdit({})); |
| 261 | 270 | } |
| 262 | 271 | } else { |
modified gui/src/redux/slices/sessionSlice.ts +9 −0
| @@ -18,6 +18,7 @@ | ||
| 18 | 18 | RuleWithSource, |
| 19 | 19 | Session, |
| 20 | 20 | SessionMetadata, |
| 21 | + Tool, | |
| 21 | 22 | } from "core"; |
| 22 | 23 | import { NEW_SESSION_TITLE } from "core/util/constants"; |
| 23 | 24 | import { |
| @@ -535,6 +536,7 @@ | ||
| 535 | 536 | state, |
| 536 | 537 | action: PayloadAction<{ |
| 537 | 538 | toolCallId: string; |
| 539 | + tools: Tool[]; | |
| 538 | 540 | }>, |
| 539 | 541 | ) => { |
| 540 | 542 | const toolCallState = findToolCall( |
| @@ -543,6 +545,13 @@ | ||
| 543 | 545 | ); |
| 544 | 546 | if (toolCallState) { |
| 545 | 547 | 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 | + } | |
| 546 | 555 | } |
| 547 | 556 | }, |
| 548 | 557 | updateToolCallOutput: ( |
modified gui/src/redux/thunks/callCurrentTool.ts +2 −4
| @@ -101,8 +101,6 @@ | ||
| 101 | 101 | ], |
| 102 | 102 | }), |
| 103 | 103 | ); |
| 104 | - | |
| 105 | - logToolUsage(toolCallState, false, extra.ideMessenger, output); | |
| 106 | 104 | } else if (output?.length) { |
| 107 | 105 | dispatch( |
| 108 | 106 | updateToolCallOutput({ |
| @@ -110,8 +108,6 @@ | ||
| 110 | 108 | contextItems: output, |
| 111 | 109 | }), |
| 112 | 110 | ); |
| 113 | - | |
| 114 | - logToolUsage(toolCallState, true, extra.ideMessenger, output); | |
| 115 | 111 | } |
| 116 | 112 | |
| 117 | 113 | // Because we don't have access to use hooks, we check `allowAnonymousTelemetry` |
| @@ -127,12 +123,14 @@ | ||
| 127 | 123 | |
| 128 | 124 | if (streamResponse) { |
| 129 | 125 | if (errorMessage) { |
| 126 | + logToolUsage(toolCallState, false, false, extra.ideMessenger, output); | |
| 130 | 127 | dispatch( |
| 131 | 128 | errorToolCall({ |
| 132 | 129 | toolCallId, |
| 133 | 130 | }), |
| 134 | 131 | ); |
| 135 | 132 | } else { |
| 133 | + logToolUsage(toolCallState, true, true, extra.ideMessenger, output); | |
| 136 | 134 | dispatch( |
| 137 | 135 | acceptToolCall({ |
| 138 | 136 | toolCallId, |
modified gui/src/redux/thunks/streamNormalInput.ts +1 −0
| @@ -154,6 +154,7 @@ | ||
| 154 | 154 | dispatch( |
| 155 | 155 | setToolGenerated({ |
| 156 | 156 | toolCallId: toolCallState.toolCallId, |
| 157 | + tools: state.config.config.tools, | |
| 157 | 158 | }), |
| 158 | 159 | ); |
| 159 | 160 |
modified gui/src/redux/util/index.ts +10 −5
| @@ -1,5 +1,4 @@ | ||
| 1 | 1 | import { ContextItem, ToolCallState } from "core"; |
| 2 | -import { safeParseToolCallArgs } from "core/tools/parseArgs"; | |
| 3 | 2 | import { IIdeMessenger } from "../../context/IdeMessenger"; |
| 4 | 3 | import { ChatHistoryItemWithMessageId } from "../slices/sessionSlice"; |
| 5 | 4 | import { RootState } from "../store"; |
| @@ -32,6 +31,7 @@ | ||
| 32 | 31 | |
| 33 | 32 | export function logToolUsage( |
| 34 | 33 | toolCallState: ToolCallState, |
| 34 | + accepted: boolean, | |
| 35 | 35 | success: boolean, |
| 36 | 36 | messenger: IIdeMessenger, |
| 37 | 37 | finalOutput?: ContextItem[], |
| @@ -40,10 +40,15 @@ | ||
| 40 | 40 | name: "toolUsage", |
| 41 | 41 | data: { |
| 42 | 42 | 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, | |
| 47 | 52 | output: finalOutput || toolCallState.output || [], |
| 48 | 53 | succeeded: success, |
| 49 | 54 | }, |
modified packages/config-yaml/src/schemas/data/toolUsage/index.ts +3 −3
| @@ -4,9 +4,9 @@ | ||
| 4 | 4 | export const toolUsageEventAllSchema = baseDevDataAllSchema.extend({ |
| 5 | 5 | toolCallId: z.string(), |
| 6 | 6 | 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(), | |
| 10 | 10 | succeeded: z.boolean(), |
| 11 | 11 | output: z.array(z.any()).optional(), |
| 12 | 12 | }); |
modified packages/config-yaml/src/schemas/data/toolUsage/v0.2.0.ts +4 −4
| @@ -12,16 +12,16 @@ | ||
| 12 | 12 | // tool-usage-specific |
| 13 | 13 | toolCallId: true, |
| 14 | 14 | functionName: true, |
| 15 | - functionArgs: true, | |
| 15 | + functionParams: true, | |
| 16 | 16 | toolCallArgs: true, |
| 17 | - parsedArgs: true, | |
| 17 | + accepted: true, | |
| 18 | 18 | succeeded: true, |
| 19 | 19 | output: true, |
| 20 | 20 | }); |
| 21 | 21 | |
| 22 | 22 | export const toolUsageEventSchema_0_2_0_noCode = |
| 23 | 23 | toolUsageEventSchema_0_2_0.omit({ |
| 24 | - functionArgs: true, | |
| 25 | - parsedArgs: true, | |
| 24 | + functionParams: true, | |
| 25 | + toolCallArgs: true, | |
| 26 | 26 | output: true, |
| 27 | 27 | }); |