fix(telemetry): report token usage for SSE streaming paths (#1475)

* fix(telemetry): report token usage for SSE streaming paths

ParseSSEStream already parsed the usage block from SSE chunks but only
printed it, so claw402 streaming calls (and native streaming) never
fired TokenUsageCallback. GA4 therefore undercounted AI usage on the
streaming path.

Return the parsed usage from ParseSSEStream and have both callers fire
the callback with their own Provider/Model.

* chore: drop leftover debug Printf in ParseSSEStream

Telemetry is now wired via TokenUsageCallback, so the Printf is
redundant noise in the stream path.
This commit is contained in:
Lance
2026-04-16 21:31:13 +08:00
committed by GitHub
parent 2f483633ed
commit a1f909adbe
2 changed files with 30 additions and 8 deletions
+2 -1
View File
@@ -452,7 +452,8 @@ func X402CallStream(c *mcp.Client, signFn X402SignFunc, tag string, systemPrompt
var bodyBuf bytes.Buffer
tee := io.TeeReader(resp.Body, &bodyBuf)
text, sseErr := mcp.ParseSSEStream(tee, onChunk, onLine)
text, usage, sseErr := mcp.ParseSSEStream(tee, onChunk, onLine)
mcp.ReportStreamUsage(usage, c.Provider, c.Model)
if text != "" {
c.Log.Infof("📡 [%s] SSE stream complete, got %d chars", tag, len(text))