token-stats-timer 1.0.17 → 1.0.18

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/token-stats.ts +18 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "token-stats-timer",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "description": "pi extension to display token usage and time spend.",
5
5
  "keywords": [
6
6
  "pi-package",
package/token-stats.ts CHANGED
@@ -196,7 +196,7 @@ type QuotaError =
196
196
  * Token 格式化(对齐 @firstpick/pi-utils formatTokens)
197
197
  */
198
198
  function formatTokens(count: number): string {
199
- if (count < 1000) return count.toString();
199
+ if (count < 1000) return count.toFixed(1);
200
200
  if (count < 10000) return `${(count / 1000).toFixed(1)}k`;
201
201
  if (count < 1000000) return `${Math.round(count / 1000)}k`;
202
202
  if (count < 10000000) return `${(count / 1000000).toFixed(1)}M`;
@@ -1632,16 +1632,23 @@ export function createTokenStats(
1632
1632
  records.sort((a, b) => a.hour - b.hour);
1633
1633
 
1634
1634
  const lines = renderTable(
1635
- ["时间", "次数", "输入", "输出", "命中率", "速率"],
1636
- records.map((r) => [
1637
- String(r.hour).padStart(2, "0"),
1638
- String(r.count),
1639
- formatTokens(r.sumInput),
1640
- formatTokens(r.sumOutput),
1641
- `${weightedCacheHitRate(r).toFixed(1)}%`,
1642
- `${(r.sumTokensPerSec / r.count).toFixed(1)}`,
1643
- ]),
1644
- { aligns: ["left", "right", "right", "right", "right", "right"] },
1635
+ ["时间", "次数", "新增输入", "缓存输入", "输出", "总token", "命中率", "速率"],
1636
+ records.map((r) => {
1637
+ const totalPrompt = r.sumInput + r.sumCacheRead + r.sumCacheWrite;
1638
+ return [
1639
+ String(r.hour).padStart(2, "0"),
1640
+ String(r.count),
1641
+ formatTokens(r.sumInput),
1642
+ formatTokens(r.sumCacheRead),
1643
+ formatTokens(r.sumOutput),
1644
+ formatTokens(totalPrompt),
1645
+ `${weightedCacheHitRate(r).toFixed(1)}%`,
1646
+ `${(r.sumTokensPerSec / r.count).toFixed(1)}`,
1647
+ ];
1648
+ }),
1649
+ {
1650
+ aligns: ["left", "right", "right", "right", "right", "right", "right", "right"],
1651
+ },
1645
1652
  );
1646
1653
 
1647
1654
  await showStats(lines, `按小时分布 | ${date}`, ctx);