@giladbarnea/pi-custom-footer 0.1.9 → 0.1.10
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/index.ts +11 -1
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -496,6 +496,7 @@ interface SessionStats {
|
|
|
496
496
|
function getSessionStats(branch: readonly SessionEntry[]): SessionStats {
|
|
497
497
|
let turnCount = 0;
|
|
498
498
|
let totalCost = 0;
|
|
499
|
+
let turnCost = 0;
|
|
499
500
|
let totalReused = 0;
|
|
500
501
|
let totalFresh = 0;
|
|
501
502
|
let lastContextTokens = 0;
|
|
@@ -509,12 +510,21 @@ function getSessionStats(branch: readonly SessionEntry[]): SessionStats {
|
|
|
509
510
|
cacheWasReported = false;
|
|
510
511
|
continue;
|
|
511
512
|
}
|
|
513
|
+
// Like Pi's footer, count usage entries (cache warms) in the totals only: they are not turns.
|
|
514
|
+
if (entry.type === "usage") {
|
|
515
|
+
const { input, cacheRead, cacheWrite, cost } = entry.usage;
|
|
516
|
+
totalCost += cost.total;
|
|
517
|
+
totalReused += cacheRead;
|
|
518
|
+
totalFresh += input + cacheWrite;
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
512
521
|
if (entry.type !== "message" || entry.message?.role !== "assistant") continue;
|
|
513
522
|
const message = entry.message as AssistantMessage;
|
|
514
523
|
if (message.stopReason === "error" || message.stopReason === "aborted") continue;
|
|
515
524
|
const { input, output, cacheRead, cacheWrite, cost } = message.usage;
|
|
516
525
|
const promptTokens = input + cacheRead + cacheWrite;
|
|
517
526
|
turnCount += 1;
|
|
527
|
+
turnCost += cost.total;
|
|
518
528
|
totalCost += cost.total;
|
|
519
529
|
totalReused += cacheRead;
|
|
520
530
|
totalFresh += input + cacheWrite;
|
|
@@ -540,7 +550,7 @@ function getSessionStats(branch: readonly SessionEntry[]): SessionStats {
|
|
|
540
550
|
sessionCacheHitRate: totalPrompt > 0 ? (totalReused / totalPrompt) * 100 : null,
|
|
541
551
|
latestCacheHitRate,
|
|
542
552
|
latestCacheMissTokens,
|
|
543
|
-
averageCostPerTurn: turnCount > 0 ?
|
|
553
|
+
averageCostPerTurn: turnCount > 0 ? turnCost / turnCount : 0,
|
|
544
554
|
lastContextTokens,
|
|
545
555
|
};
|
|
546
556
|
}
|