Commit 458a302
committed
Add a live token estimate to the composer
Token usage was only ever shown after a response finished (per-message and
per-session cost). Now the composer shows a running estimate — draft tokens
recomputed on every keystroke (cheap, just the current text), context
tokens (system prompt + conversation so far) memoized separately so it only
recalculates when the conversation itself changes, not on every keystroke
in a long chat. Reuses the existing estimateTokens/estimateMessagesTokens
heuristic already powering context compaction, so the number is consistent
with when the app decides to fold older messages away.1 parent 1f6b45c commit 458a302
2 files changed
Lines changed: 24 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
368 | 369 | | |
369 | 370 | | |
370 | 371 | | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
371 | 376 | | |
372 | 377 | | |
373 | 378 | | |
| |||
736 | 741 | | |
737 | 742 | | |
738 | 743 | | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
739 | 748 | | |
740 | 749 | | |
741 | 750 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
| 78 | + | |
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
| |||
1407 | 1409 | | |
1408 | 1410 | | |
1409 | 1411 | | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
1410 | 1420 | | |
1411 | 1421 | | |
1412 | 1422 | | |
| |||
2379 | 2389 | | |
2380 | 2390 | | |
2381 | 2391 | | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
2382 | 2397 | | |
2383 | 2398 | | |
2384 | 2399 | | |
| |||
0 commit comments