Skip to content

Commit 36c3f93

Browse files
authored
added modelId to tool call events (RooCodeInc#3968)
1 parent 3fb0360 commit 36c3f93

File tree

2 files changed

+106
-20
lines changed

2 files changed

+106
-20
lines changed

src/core/task/index.ts

Lines changed: 97 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,7 +2412,7 @@ export class Task {
24122412
this.removeLastPartialMessageIfExistsWithType("ask", "tool")
24132413
await this.say("tool", completeMessage, undefined, undefined, false)
24142414
this.consecutiveAutoApprovedRequestsCount++
2415-
telemetryService.captureToolUsage(this.taskId, block.name, true, true)
2415+
telemetryService.captureToolUsage(this.taskId, block.name, this.api.getModel().id, true, true)
24162416

24172417
// we need an artificial delay to let the diagnostics catch up to the changes
24182418
await setTimeoutPromise(3_500)
@@ -2450,7 +2450,13 @@ export class Task {
24502450
}
24512451
this.didRejectTool = true
24522452
didApprove = false
2453-
telemetryService.captureToolUsage(this.taskId, block.name, false, false)
2453+
telemetryService.captureToolUsage(
2454+
this.taskId,
2455+
block.name,
2456+
this.api.getModel().id,
2457+
false,
2458+
false,
2459+
)
24542460
} else {
24552461
// User hit the approve button, and may have provided feedback
24562462
if (text || (images && images.length > 0) || (askFiles && askFiles.length > 0)) {
@@ -2463,7 +2469,13 @@ export class Task {
24632469
await this.say("user_feedback", text, images, askFiles)
24642470
await this.saveCheckpoint()
24652471
}
2466-
telemetryService.captureToolUsage(this.taskId, block.name, false, true)
2472+
telemetryService.captureToolUsage(
2473+
this.taskId,
2474+
block.name,
2475+
this.api.getModel().id,
2476+
false,
2477+
true,
2478+
)
24672479
}
24682480

24692481
if (!didApprove) {
@@ -2581,7 +2593,7 @@ export class Task {
25812593
this.removeLastPartialMessageIfExistsWithType("ask", "tool")
25822594
await this.say("tool", completeMessage, undefined, undefined, false) // need to be sending partialValue bool, since undefined has its own purpose in that the message is treated neither as a partial or completion of a partial, but as a single complete message
25832595
this.consecutiveAutoApprovedRequestsCount++
2584-
telemetryService.captureToolUsage(this.taskId, block.name, true, true)
2596+
telemetryService.captureToolUsage(this.taskId, block.name, this.api.getModel().id, true, true)
25852597
} else {
25862598
showNotificationForApprovalIfAutoApprovalEnabled(
25872599
`Cline wants to read ${path.basename(absolutePath)}`,
@@ -2590,10 +2602,22 @@ export class Task {
25902602
const didApprove = await askApproval("tool", completeMessage)
25912603
if (!didApprove) {
25922604
await this.saveCheckpoint()
2593-
telemetryService.captureToolUsage(this.taskId, block.name, false, false)
2605+
telemetryService.captureToolUsage(
2606+
this.taskId,
2607+
block.name,
2608+
this.api.getModel().id,
2609+
false,
2610+
false,
2611+
)
25942612
break
25952613
}
2596-
telemetryService.captureToolUsage(this.taskId, block.name, false, true)
2614+
telemetryService.captureToolUsage(
2615+
this.taskId,
2616+
block.name,
2617+
this.api.getModel().id,
2618+
false,
2619+
true,
2620+
)
25972621
}
25982622
// now execute the tool like normal
25992623
const content = await extractTextFromFile(absolutePath)
@@ -2666,19 +2690,31 @@ export class Task {
26662690
this.removeLastPartialMessageIfExistsWithType("ask", "tool")
26672691
await this.say("tool", completeMessage, undefined, undefined, false)
26682692
this.consecutiveAutoApprovedRequestsCount++
2669-
telemetryService.captureToolUsage(this.taskId, block.name, true, true)
2693+
telemetryService.captureToolUsage(this.taskId, block.name, this.api.getModel().id, true, true)
26702694
} else {
26712695
showNotificationForApprovalIfAutoApprovalEnabled(
26722696
`Cline wants to view directory ${path.basename(absolutePath)}/`,
26732697
)
26742698
this.removeLastPartialMessageIfExistsWithType("say", "tool")
26752699
const didApprove = await askApproval("tool", completeMessage)
26762700
if (!didApprove) {
2677-
telemetryService.captureToolUsage(this.taskId, block.name, false, false)
2701+
telemetryService.captureToolUsage(
2702+
this.taskId,
2703+
block.name,
2704+
this.api.getModel().id,
2705+
false,
2706+
false,
2707+
)
26782708
await this.saveCheckpoint()
26792709
break
26802710
}
2681-
telemetryService.captureToolUsage(this.taskId, block.name, false, true)
2711+
telemetryService.captureToolUsage(
2712+
this.taskId,
2713+
block.name,
2714+
this.api.getModel().id,
2715+
false,
2716+
true,
2717+
)
26822718
}
26832719
pushToolResult(result, isClaude4ModelFamily)
26842720
await this.saveCheckpoint()
@@ -2736,19 +2772,31 @@ export class Task {
27362772
this.removeLastPartialMessageIfExistsWithType("ask", "tool")
27372773
await this.say("tool", completeMessage, undefined, undefined, false)
27382774
this.consecutiveAutoApprovedRequestsCount++
2739-
telemetryService.captureToolUsage(this.taskId, block.name, true, true)
2775+
telemetryService.captureToolUsage(this.taskId, block.name, this.api.getModel().id, true, true)
27402776
} else {
27412777
showNotificationForApprovalIfAutoApprovalEnabled(
27422778
`Cline wants to view source code definitions in ${path.basename(absolutePath)}/`,
27432779
)
27442780
this.removeLastPartialMessageIfExistsWithType("say", "tool")
27452781
const didApprove = await askApproval("tool", completeMessage)
27462782
if (!didApprove) {
2747-
telemetryService.captureToolUsage(this.taskId, block.name, false, false)
2783+
telemetryService.captureToolUsage(
2784+
this.taskId,
2785+
block.name,
2786+
this.api.getModel().id,
2787+
false,
2788+
false,
2789+
)
27482790
await this.saveCheckpoint()
27492791
break
27502792
}
2751-
telemetryService.captureToolUsage(this.taskId, block.name, false, true)
2793+
telemetryService.captureToolUsage(
2794+
this.taskId,
2795+
block.name,
2796+
this.api.getModel().id,
2797+
false,
2798+
true,
2799+
)
27522800
}
27532801
pushToolResult(result)
27542802
await this.saveCheckpoint()
@@ -2825,19 +2873,31 @@ export class Task {
28252873
this.removeLastPartialMessageIfExistsWithType("ask", "tool")
28262874
await this.say("tool", completeMessage, undefined, undefined, false)
28272875
this.consecutiveAutoApprovedRequestsCount++
2828-
telemetryService.captureToolUsage(this.taskId, block.name, true, true)
2876+
telemetryService.captureToolUsage(this.taskId, block.name, this.api.getModel().id, true, true)
28292877
} else {
28302878
showNotificationForApprovalIfAutoApprovalEnabled(
28312879
`Cline wants to search files in ${path.basename(absolutePath)}/`,
28322880
)
28332881
this.removeLastPartialMessageIfExistsWithType("say", "tool")
28342882
const didApprove = await askApproval("tool", completeMessage)
28352883
if (!didApprove) {
2836-
telemetryService.captureToolUsage(this.taskId, block.name, false, false)
2884+
telemetryService.captureToolUsage(
2885+
this.taskId,
2886+
block.name,
2887+
this.api.getModel().id,
2888+
false,
2889+
false,
2890+
)
28372891
await this.saveCheckpoint()
28382892
break
28392893
}
2840-
telemetryService.captureToolUsage(this.taskId, block.name, false, true)
2894+
telemetryService.captureToolUsage(
2895+
this.taskId,
2896+
block.name,
2897+
this.api.getModel().id,
2898+
false,
2899+
true,
2900+
)
28412901
}
28422902
pushToolResult(results, isClaude4ModelFamily)
28432903
await this.saveCheckpoint()
@@ -3742,20 +3802,38 @@ export class Task {
37423802
this.removeLastPartialMessageIfExistsWithType("ask", "tool")
37433803
await this.say("tool", completeMessage, undefined, undefined, false)
37443804
this.consecutiveAutoApprovedRequestsCount++
3745-
telemetryService.captureToolUsage(this.taskId, "web_fetch" as ToolUseName, true, true)
3805+
telemetryService.captureToolUsage(
3806+
this.taskId,
3807+
"web_fetch" as ToolUseName,
3808+
this.api.getModel().id,
3809+
true,
3810+
true,
3811+
)
37463812
} else {
37473813
showNotificationForApprovalIfAutoApprovalEnabled(`Cline wants to fetch content from ${url}`)
37483814
this.removeLastPartialMessageIfExistsWithType("say", "tool")
37493815
const didApprove = await askApproval("tool", completeMessage)
37503816
if (!didApprove) {
3751-
telemetryService.captureToolUsage(this.taskId, "web_fetch" as ToolUseName, false, false)
3817+
telemetryService.captureToolUsage(
3818+
this.taskId,
3819+
"web_fetch" as ToolUseName,
3820+
this.api.getModel().id,
3821+
false,
3822+
false,
3823+
)
37523824
await this.saveCheckpoint()
37533825
break
37543826
}
3755-
telemetryService.captureToolUsage(this.taskId, "web_fetch" as ToolUseName, false, true)
3827+
telemetryService.captureToolUsage(
3828+
this.taskId,
3829+
"web_fetch" as ToolUseName,
3830+
this.api.getModel().id,
3831+
false,
3832+
true,
3833+
)
37563834
}
37573835

3758-
// Fetch Markdown content
3836+
// Fetch Markdown contentcc
37593837
await this.urlContentFetcher.launchBrowser()
37603838
const markdownContent = await this.urlContentFetcher.urlToMarkdown(url)
37613839
await this.urlContentFetcher.closeBrowser()

src/services/posthog/telemetry/TelemetryService.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,14 @@ class TelemetryService {
383383
* @param autoApproved Whether the tool was auto-approved based on settings
384384
* @param success Whether the tool execution was successful
385385
*/
386-
public captureToolUsage(taskId: string, tool: string, autoApproved: boolean, success: boolean, collect: boolean = false) {
386+
public captureToolUsage(
387+
taskId: string,
388+
tool: string,
389+
modelId: string,
390+
autoApproved: boolean,
391+
success: boolean,
392+
collect: boolean = false,
393+
) {
387394
this.capture(
388395
{
389396
event: TelemetryService.EVENTS.TASK.TOOL_USED,
@@ -392,6 +399,7 @@ class TelemetryService {
392399
tool,
393400
autoApproved,
394401
success,
402+
modelId,
395403
},
396404
},
397405
collect,

0 commit comments

Comments
 (0)