feat(tui): add balance status item#1970
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a DeepSeek account balance display in the TUI footer. Key changes include the implementation of background fetching for balance information after each turn completion, localized strings for the balance prefix, and updates to the footer rendering logic to include the new balance chip. Additionally, the status picker was enhanced with provider-specific filtering and scrolling capabilities. Review feedback suggests adding a timeout to the background HTTP client to prevent stalled tasks, displaying the balance even when it is zero to notify users of empty accounts, and improving the currency symbol mapping to handle future currency additions more robustly.
|
Independent review: Reviewed the feature against #2257 with a real merge sim (#1970 has 264-file conflicts against current main; #2257 is rebased cleanly).
v0.8.48 (#2256) compatibility: PR #2256 deletes |
|
@MoriTang — appreciation for the original balance feature. After the v0.8.45 → v0.8.46 series, this branch is now 264 files behind One specific call to confirm: #2257 currently suppresses the balance display when balance is zero (reverted on reviewer feedback). Your original #1970 shows zero. If you have a strong opinion on which UX is right — particularly for free-tier users who'd want to see "0 / out of credits" rather than silence — flag it on #2257 and we'll honor it before merge. Otherwise: thanks for showing up first. Your stamp is on this feature regardless of which PR ships. |
I think hide zero is OK. Thanks for carried my commits. |
Summary
支持底部状态栏自定义配置([statusline]),显示 API 余额等实时信息 #1551
Adds a DeepSeek account balance chip to the footer status bar. The balance
is fetched from
GET /user/balanceonce per turn completion and displayedalongside mode, model, and session cost.
Non-DeepSeek providers never see the Balance toggle — the picker and default
footer both hide it behind
StatusItem::is_available_for(provider).Changes
StatusItem::Balancepricing.rsBalanceResponse/BalanceInfodeserialization structstui/ui.rsfetch_deepseek_balance()— async HTTP fetch using the configured API keytui/footer_ui.rsfooter_balance_spans()— formats balance with currency-appropriate precisiontui/widgets/footer.rsFooterProps.balancefield, left-cluster rendering in the footer widgettui/views/status_picker.rsStatusPickerView::new(active, provider)filters rows byis_available_forconfig.rsdefault_footer()excludes Balance (provider-specific); it must be opted in via/statuslineProvider gating
Deepseek/DeepseekCNprovidersStatusItem::is_available_for()returnsfalsefor Balance on all other providers/statuslinepicker filters unavailable items so non-DeepSeek users never see the toggleTests
New tests in
pricing.rs,ui/tests.rs,config.rs, andstatus_picker.rs:total_balance_f64()parsing — valid / empty / invalid (3 cases)footer_balance_spans()— empty cell, zero, CNY, USD, large-amount rounding, unknown currency (6 cases)render_footer_fromwith/without Balance in items (2 cases)is_available_foracross all known providers (1 case)No regressions: 191 tests in the impacted modules pass.
Testing
cargo test --all-featurescargo fmt --all -- --checkcargo clippy --all-targets --all-featuresChecklist