@deathbeam/pi-usage 0.0.10 → 0.0.12
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/README.md +1 -1
- package/package.json +1 -1
- package/src/usage.ts +15 -8
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ Day rows include days without usage. Δ compares cost with the previous day. The
|
|
|
27
27
|
|
|
28
28
|
The summary compares the daily spend so far this week and month with last week and month. Weeks start on Monday in local time. `▲new` means the previous period had no spend.
|
|
29
29
|
|
|
30
|
-
Compaction and branch summaries are counted under `
|
|
30
|
+
Compaction and branch summaries are counted under `(summaries)`.
|
|
31
31
|
|
|
32
32
|
## Development
|
|
33
33
|
|
package/package.json
CHANGED
package/src/usage.ts
CHANGED
|
@@ -58,7 +58,7 @@ export type DailyCost = { label: string; cost: number };
|
|
|
58
58
|
|
|
59
59
|
type Tally = { stats: Stats; requests: number; models?: Map<string, Tally>; providers?: Set<string> };
|
|
60
60
|
|
|
61
|
-
const CACHE_VERSION =
|
|
61
|
+
const CACHE_VERSION = 4;
|
|
62
62
|
|
|
63
63
|
function emptyStats(): Stats {
|
|
64
64
|
return { cost: 0, input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
|
|
@@ -198,21 +198,28 @@ async function parseFile(file: string): Promise<UsageRecord[]> {
|
|
|
198
198
|
provider = String(entry.provider);
|
|
199
199
|
model = String(entry.model);
|
|
200
200
|
} else {
|
|
201
|
-
// Compaction and branch-summary calls carry no model, so their cost gets its own row.
|
|
202
|
-
provider
|
|
203
|
-
|
|
201
|
+
// Compaction and branch-summary calls carry no model, so their cost gets its own row. Subagent
|
|
202
|
+
// artifact transcripts carry no type at all and keep provider/model on the nested message.
|
|
203
|
+
provider = String(message?.provider || entry.provider || "(summaries)");
|
|
204
|
+
model = String(message?.model || entry.model || entry.type || "unknown");
|
|
204
205
|
}
|
|
205
206
|
const cost = typeof usage.cost === "number" ? usage.cost : num(usage.cost?.total);
|
|
207
|
+
const input = num(usage.input);
|
|
208
|
+
const output = num(usage.output);
|
|
209
|
+
const cacheRead = num(usage.cacheRead);
|
|
210
|
+
const cacheWrite = num(usage.cacheWrite);
|
|
211
|
+
// An aborted request (delegate children report one) carries no usage; counting it adds a phantom row.
|
|
212
|
+
if (cost === 0 && input === 0 && output === 0 && cacheRead === 0 && cacheWrite === 0) continue;
|
|
206
213
|
const stamp = entry.type === "message" ? message.timestamp : entry.timestamp;
|
|
207
214
|
records.push({
|
|
208
215
|
provider,
|
|
209
216
|
model,
|
|
210
217
|
ts: typeof stamp === "string" ? num(Date.parse(stamp)) : num(stamp),
|
|
211
218
|
cost,
|
|
212
|
-
input
|
|
213
|
-
output
|
|
214
|
-
cacheRead
|
|
215
|
-
cacheWrite
|
|
219
|
+
input,
|
|
220
|
+
output,
|
|
221
|
+
cacheRead,
|
|
222
|
+
cacheWrite,
|
|
216
223
|
requests: 1,
|
|
217
224
|
cwd,
|
|
218
225
|
sessionId,
|