Commit 1b4f50b
committed
fix(stats): track ImageGen / VideoGen costs in usage insights (#13)
Before this, only chat LLM calls flowed through `recordUsage()`. The
ImageGen and VideoGen tools wrote to the content library but never
reported to the global stats file, so:
- `franklin insights` undercounted total 30-day spend by the exact
amount spent on image + video generation.
- The "Top models" breakdown never surfaced `openai/gpt-image-1`,
`bytedance/seedance-2.0`, `xai/grok-imagine-video`, etc. even when
they were the dominant cost in a session.
- Monthly projections in insights were similarly low.
On successful generation each tool now fires a fire-and-forget
`recordUsage(model, 0, 0, costUsd, 0)`. Input/output tokens stay at 0
because image/video models don't bill by token; the cost is pulled
from the live gateway catalog via `findModel` + `estimateCostUsd`, the
same path the AskUser cost preview uses. When the catalog lookup fails
the tools fall back to hardcoded estimates so stats still get an
entry (under-approximate rather than missing).
The stats write is intentionally fire-and-forget and error-swallowing:
a `~/.blockrun/stats.json` write failure must not turn a paid generation
into a user-visible error.
Scope is deliberately small — only the two tools, +33 lines, zero
schema or behavior change to the existing tracker / insights engine.
Any record already written by chat flows continues to work unchanged.1 parent f8570ce commit 1b4f50b
2 files changed
Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
360 | 362 | | |
361 | 363 | | |
362 | 364 | | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
363 | 379 | | |
364 | 380 | | |
365 | 381 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| |||
351 | 353 | | |
352 | 354 | | |
353 | 355 | | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
354 | 371 | | |
355 | 372 | | |
356 | 373 | | |
| |||
0 commit comments