Repository navigation
Commit 27d5682
feat(ai): show running $ spend — per-run cost + credits left in the response bar
M5/bet-#2 ("turn BYO-key into a trust weapon"). The response bar has always had
a slot for credits, but agent.js hands back `credits: null` because nothing ever
told it. The gateway now emits a final `levelcode` SSE frame (thin.ly #367) with
what the turn cost and what's left, in retail micro-$.
- openaiCompat: parse the gateway's namespaced `levelcode` frame into
usage.{cost_micros, credits_remaining_micros}. It carries no `choices`, and no
other provider sends it, so this is inert everywhere else.
- agent.js: accumulate the RUN's cost across turns and keep the latest balance;
report both on agentDone (and in the 🐛 debug line next to cacheRead).
- chat.html: render money, not a count. The bar previously did
`String(credits) + ' credits'`, which would have printed "9876543 credits" for
a micro-$ figure. Now: `· $0.02 · $9.88 left`.
`money()` floors sub-cent turns at "<$0.01" rather than rounding to "$0.00" —
with prompt caching live, sub-cent turns are common and "$0.00" reads as
free/broken.
BYOK runs send neither figure, so the bar is unchanged there — this is a
gateway-only affordance.
All 5 extension test files pass.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 7dc2f10 commit 27d5682
3 files changed
Lines changed: 39 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
474 | 474 | | |
475 | 475 | | |
476 | 476 | | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
477 | 480 | | |
478 | 481 | | |
479 | 482 | | |
| |||
578 | 581 | | |
579 | 582 | | |
580 | 583 | | |
581 | | - | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
582 | 589 | | |
583 | 590 | | |
584 | 591 | | |
| |||
695 | 702 | | |
696 | 703 | | |
697 | 704 | | |
698 | | - | |
699 | | - | |
700 | | - | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
701 | 713 | | |
702 | 714 | | |
703 | 715 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1863 | 1863 | | |
1864 | 1864 | | |
1865 | 1865 | | |
1866 | | - | |
1867 | | - | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
1868 | 1876 | | |
1869 | 1877 | | |
1870 | 1878 | | |
| |||
1880 | 1888 | | |
1881 | 1889 | | |
1882 | 1890 | | |
1883 | | - | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
1884 | 1895 | | |
1885 | 1896 | | |
1886 | 1897 | | |
| |||
2288 | 2299 | | |
2289 | 2300 | | |
2290 | 2301 | | |
2291 | | - | |
| 2302 | + | |
2292 | 2303 | | |
2293 | 2304 | | |
2294 | 2305 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
210 | 218 | | |
211 | 219 | | |
212 | 220 | | |
| |||
0 commit comments