feat(usage): expanded daily stats with detailed token breakdown (#385)

* feat(usage): expanded daily stats with detailed token breakdown

* feat(usage): separate cache read and cache write in daily trend table
This commit is contained in:
Desmond Zhang
2026-05-02 10:36:33 +10:00
committed by GitHub
parent acf4e225e6
commit 018053db19
14 changed files with 88 additions and 46 deletions
@@ -409,15 +409,14 @@ export async function usageStats(ctx: any) {
const d = new Date(now)
d.setDate(d.getDate() - i)
const key = d.toISOString().slice(0, 10)
dayMap.set(key, { date: key, tokens: 0, cache: 0, sessions: 0, cost: 0 })
dayMap.set(key, { date: key, input_tokens: 0, output_tokens: 0, cache_read_tokens: 0, cache_write_tokens: 0, sessions: 0, errors: 0, cost: 0 })
}
for (const d of [...local.by_day, ...hermes.by_day]) {
const existing = dayMap.get(d.date)
if (existing) {
existing.tokens += d.tokens
existing.cache += d.cache
existing.sessions += d.sessions
existing.cost += d.cost
existing.input_tokens += d.input_tokens; existing.output_tokens += d.output_tokens
existing.cache_read_tokens += d.cache_read_tokens; existing.cache_write_tokens += d.cache_write_tokens
existing.sessions += d.sessions; existing.errors += d.errors; existing.cost += d.cost
}
}