tokenrace 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.html CHANGED
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>tokenrace</title>
7
- <script type="module" crossorigin src="/assets/index-18NqIjOk.js"></script>
7
+ <script type="module" crossorigin src="/assets/index-Bq_1mbQ9.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="/assets/index-B0dy8dWP.css">
9
9
  </head>
10
10
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokenrace",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Monitor en tiempo real para Claude Code",
5
5
  "bin": {
6
6
  "tokenrace": "bin/cli.js"
package/src/store.js CHANGED
@@ -263,7 +263,44 @@ export function processEvent({ eventName, timestamp, severity, attributes }) {
263
263
  }
264
264
  state.eventIndex++
265
265
 
266
- // ── Tool stats ──
266
+ // ── Asegurar que la sesión existe (puede llegar un evento antes que una métrica) ──
267
+ if (sessionId && !state.sessions.has(sessionId)) {
268
+ state.sessions.set(sessionId, {
269
+ sessionId,
270
+ project,
271
+ feature: attributes.feature ?? null,
272
+ model,
273
+ startTime: timestamp,
274
+ lastSeen: timestamp,
275
+ durationActiveMs: 0,
276
+ tokensInput: 0,
277
+ tokensOutput: 0,
278
+ tokensCache: 0,
279
+ cost: 0,
280
+ apiRequests: 0,
281
+ toolCalls: 0
282
+ })
283
+ }
284
+
285
+ if (sessionId && state.sessions.has(sessionId)) {
286
+ const session = state.sessions.get(sessionId)
287
+ session.lastSeen = Math.max(session.lastSeen, timestamp)
288
+ if (model && !session.model) session.model = model
289
+
290
+ // ── Tiempo activo desde eventos api_request (duration_ms) ──
291
+ if (eventName === 'api_request') {
292
+ const dur = Number(attributes['duration_ms'] ?? 0)
293
+ if (dur > 0) session.durationActiveMs += dur
294
+ session.apiRequests++
295
+ }
296
+
297
+ // ── Tool stats ──
298
+ if (eventName === 'tool_use') {
299
+ session.toolCalls++
300
+ }
301
+ }
302
+
303
+ // ── Tool stats globales ──
267
304
  if (eventName === 'tool_use') {
268
305
  const toolName = attributes['tool.name'] ?? attributes.tool ?? 'unknown'
269
306
 
@@ -279,11 +316,6 @@ export function processEvent({ eventName, timestamp, severity, attributes }) {
279
316
  if (attributes['tool.duration_ms'] !== undefined) {
280
317
  tool.totalDurationMs += Number(attributes['tool.duration_ms'])
281
318
  }
282
-
283
- // Incrementar toolCalls en la sesión
284
- if (sessionId && state.sessions.has(sessionId)) {
285
- state.sessions.get(sessionId).toolCalls++
286
- }
287
319
  }
288
320
 
289
321
  state.lastSeen = timestamp