@@ -199,13 +199,19 @@ func GetChatUsage(chat *uctypes.AIChat) uctypes.AIUsage {
199199 return usage
200200}
201201
202- func processToolResults (stopReason * uctypes.WaveStopReason , chatOpts uctypes.WaveChatOpts , sseHandler * sse.SSEHandlerCh ) {
202+ func processToolResults (stopReason * uctypes.WaveStopReason , chatOpts uctypes.WaveChatOpts , sseHandler * sse.SSEHandlerCh , metrics * uctypes. AIMetrics ) {
203203 var toolResults []uctypes.AIToolResult
204204 for _ , toolCall := range stopReason .ToolCalls {
205205 inputJSON , _ := json .Marshal (toolCall .Input )
206206 log .Printf ("TOOLUSE name=%s id=%s input=%s\n " , toolCall .Name , toolCall .ID , utilfn .TruncateString (string (inputJSON ), 40 ))
207207 result := ResolveToolCall (toolCall , chatOpts )
208208 toolResults = append (toolResults , result )
209+
210+ // Track tool usage by ToolLogName
211+ toolDef := getToolDefinition (toolCall .Name , chatOpts )
212+ if toolDef != nil && toolDef .ToolLogName != "" {
213+ metrics .ToolDetail [toolDef .ToolLogName ]++
214+ }
209215 if result .ErrorText != "" {
210216 log .Printf (" error=%s\n " , result .ErrorText )
211217 } else {
@@ -242,6 +248,7 @@ func RunAIChat(ctx context.Context, sseHandler *sse.SSEHandlerCh, chatOpts uctyp
242248 Model : chatOpts .Config .Model ,
243249 },
244250 WidgetAccess : chatOpts .WidgetAccess ,
251+ ToolDetail : make (map [string ]int ),
245252 }
246253 firstStep := true
247254 var cont * uctypes.WaveContinueResponse
@@ -298,7 +305,7 @@ func RunAIChat(ctx context.Context, sseHandler *sse.SSEHandlerCh, chatOpts uctyp
298305 }
299306 if stopReason != nil && stopReason .Kind == uctypes .StopKindToolUse {
300307 metrics .ToolUseCount += len (stopReason .ToolCalls )
301- processToolResults (stopReason , chatOpts , sseHandler )
308+ processToolResults (stopReason , chatOpts , sseHandler , metrics )
302309
303310 var messageID string
304311 if len (rtnMessage ) > 0 && rtnMessage [0 ] != nil {
@@ -318,6 +325,20 @@ func RunAIChat(ctx context.Context, sseHandler *sse.SSEHandlerCh, chatOpts uctyp
318325}
319326
320327// ResolveToolCall resolves a single tool call and returns an AIToolResult
328+ func getToolDefinition (toolName string , chatOpts uctypes.WaveChatOpts ) * uctypes.ToolDefinition {
329+ for _ , tool := range chatOpts .Tools {
330+ if tool .Name == toolName {
331+ return & tool
332+ }
333+ }
334+ for _ , tool := range chatOpts .TabTools {
335+ if tool .Name == toolName {
336+ return & tool
337+ }
338+ }
339+ return nil
340+ }
341+
321342func ResolveToolCall (toolCall uctypes.WaveToolCall , chatOpts uctypes.WaveChatOpts ) (result uctypes.AIToolResult ) {
322343 result = uctypes.AIToolResult {
323344 ToolName : toolCall .Name ,
@@ -331,22 +352,7 @@ func ResolveToolCall(toolCall uctypes.WaveToolCall, chatOpts uctypes.WaveChatOpt
331352 }
332353 }()
333354
334- // Find the matching tool definition
335- var toolDef * uctypes.ToolDefinition
336- for _ , tool := range chatOpts .Tools {
337- if tool .Name == toolCall .Name {
338- toolDef = & tool
339- break
340- }
341- }
342- if toolDef == nil {
343- for _ , tool := range chatOpts .TabTools {
344- if tool .Name == toolCall .Name {
345- toolDef = & tool
346- break
347- }
348- }
349- }
355+ toolDef := getToolDefinition (toolCall .Name , chatOpts )
350356
351357 if toolDef == nil {
352358 result .ErrorText = fmt .Sprintf ("tool '%s' not found" , toolCall .Name )
@@ -442,6 +448,7 @@ func sendAIMetricsTelemetry(ctx context.Context, metrics *uctypes.AIMetrics) {
442448 WaveAIOutputTokens : metrics .Usage .OutputTokens ,
443449 WaveAIRequestCount : metrics .RequestCount ,
444450 WaveAIToolUseCount : metrics .ToolUseCount ,
451+ WaveAIToolDetail : metrics .ToolDetail ,
445452 WaveAIPremiumReq : metrics .PremiumReqCount ,
446453 WaveAIProxyReq : metrics .ProxyReqCount ,
447454 WaveAIHadError : metrics .HadError ,
@@ -519,7 +526,6 @@ func WaveAIPostMessageHandler(w http.ResponseWriter, r *http.Request) {
519526 chatOpts .TabStateGenerator = func () (string , []uctypes.ToolDefinition , error ) {
520527 return GenerateTabStateAndTools (r .Context (), req .TabId , req .WidgetAccess )
521528 }
522- chatOpts .Tools = append (chatOpts .Tools , GetCaptureScreenshotToolDefinition (req .TabId ))
523529
524530 // Validate the message
525531 if err := req .Msg .Validate (); err != nil {
0 commit comments