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
|
@@ -382,13 +382,29 @@ function processStreamEvent(
|
|
|
382
382
|
}
|
|
383
383
|
|
|
384
384
|
case 'result': {
|
|
385
|
-
// 최종
|
|
386
|
-
//
|
|
387
|
-
//
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
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
|
}
|