Commit b92213c
committed
telegram: wire daily token budget into production flow
The DailyTokenBudget feature was fully implemented (SetDailyTokenBudget,
CheckDailyBudget, config parsing, tests) but never called from production
code. This commit wires it in:
1. telegramCmd: Call bot.SetDailyTokenBudget during startup when
cfg.DailyTokenBudget > 0 (0 = unlimited, the default)
2. handleChatMessage — pre-flight check: Before creating the agent,
call CheckDailyBudget(1) to detect if the budget is already
exhausted, avoiding a wasted API call. Sends a clear error message.
3. handleChatMessage — post-run billing: After agent.RunWithMessages,
bill actual input+output tokens via CheckDailyBudget. If exceeded,
logs a warning and sends a notification to the chat but still
delivers the response (the API call already happened).
Docs: update TELEGRAM.md to describe pre-flight + post-run billing.1 parent 834491f commit b92213c
2 files changed
Lines changed: 42 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
71 | 77 | | |
72 | 78 | | |
73 | 79 | | |
| |||
434 | 440 | | |
435 | 441 | | |
436 | 442 | | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
437 | 458 | | |
438 | 459 | | |
439 | 460 | | |
| |||
584 | 605 | | |
585 | 606 | | |
586 | 607 | | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
587 | 624 | | |
588 | 625 | | |
589 | 626 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
91 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
92 | 95 | | |
93 | 96 | | |
94 | 97 | | |
| |||
0 commit comments