tycono 0.1.47 → 0.1.48

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tycono",
3
- "version": "0.1.47",
3
+ "version": "0.1.48",
4
4
  "description": "Build an AI company. Watch them work.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -382,13 +382,29 @@ function processStreamEvent(
382
382
  }
383
383
 
384
384
  case 'result': {
385
- // 최종 결과: { type: "result", result: "...", usage: { input_tokens, output_tokens }, cost_usd, ... }
386
- // result 텍스트는 assistant 이벤트에서 이미 전달됨 — 중복 방지를 위해 스킵
387
- // But extract token usage for tracking
388
- const usage = event.usage as Record<string, number> | undefined;
389
- if (usage && handlers.recordTokens) {
390
- const inputTk = usage.input_tokens ?? 0;
391
- const outputTk = usage.output_tokens ?? 0;
385
+ // 최종 결과에서 토큰 사용량 추출
386
+ // modelUsage가 가장 정확 (모델별 cache 포함 상세)
387
+ // fallback: usage.input_tokens / output_tokens (cache 제외)
388
+ if (handlers.recordTokens) {
389
+ let inputTk = 0;
390
+ let outputTk = 0;
391
+
392
+ const modelUsage = event.modelUsage as Record<string, Record<string, number>> | undefined;
393
+ if (modelUsage) {
394
+ // Sum across all models (usually just one)
395
+ for (const mu of Object.values(modelUsage)) {
396
+ inputTk += (mu.inputTokens ?? 0) + (mu.cacheReadInputTokens ?? 0) + (mu.cacheCreationInputTokens ?? 0);
397
+ outputTk += mu.outputTokens ?? 0;
398
+ }
399
+ } else {
400
+ // Fallback to usage field
401
+ const usage = event.usage as Record<string, number> | undefined;
402
+ if (usage) {
403
+ inputTk = (usage.input_tokens ?? 0) + (usage.cache_read_input_tokens ?? 0) + (usage.cache_creation_input_tokens ?? 0);
404
+ outputTk = usage.output_tokens ?? 0;
405
+ }
406
+ }
407
+
392
408
  if (inputTk > 0 || outputTk > 0) {
393
409
  handlers.recordTokens(inputTk, outputTk);
394
410
  }