Skip to content

feat(tui): add balance status item#1970

Open
MoriTang wants to merge 7 commits into
Hmbown:mainfrom
MoriTang:feat/balance-status-item
Open

feat(tui): add balance status item#1970
MoriTang wants to merge 7 commits into
Hmbown:mainfrom
MoriTang:feat/balance-status-item

Conversation

@MoriTang
Copy link
Copy Markdown

@MoriTang MoriTang commented May 24, 2026

Summary

支持底部状态栏自定义配置([statusline]),显示 API 余额等实时信息 #1551

Adds a DeepSeek account balance chip to the footer status bar. The balance
is fetched from GET /user/balance once per turn completion and displayed
alongside 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

Area Description
StatusItem::Balance New variant with key/label/description/hint
pricing.rs BalanceResponse / BalanceInfo deserialization structs
tui/ui.rs fetch_deepseek_balance() — async HTTP fetch using the configured API key
tui/footer_ui.rs footer_balance_spans() — formats balance with currency-appropriate precision
tui/widgets/footer.rs FooterProps.balance field, left-cluster rendering in the footer widget
tui/views/status_picker.rs StatusPickerView::new(active, provider) filters rows by is_available_for
config.rs default_footer() excludes Balance (provider-specific); it must be opted in via /statusline

Provider gating

  • Fetch triggers only for Deepseek / DeepseekCN providers
  • StatusItem::is_available_for() returns false for Balance on all other providers
  • The /statusline picker filters unavailable items so non-DeepSeek users never see the toggle

Tests

New tests in pricing.rs, ui/tests.rs, config.rs, and status_picker.rs:

  • BalanceResponse JSON deserialization (3 cases)
  • 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_from with/without Balance in items (2 cases)
  • is_available_for across all known providers (1 case)
  • Picker row filtering for non-DeepSeek provider (1 case)

No regressions: 191 tests in the impacted modules pass.

Testing

  • cargo test --all-features
  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features

Checklist

  • Updated docs or comments as needed
  • Added or updated tests where relevant
  • Verified TUI behavior manually if UI changes

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crates/tui/src/tui/ui.rs Outdated
Comment thread crates/tui/src/tui/footer_ui.rs Outdated
Comment thread crates/tui/src/tui/footer_ui.rs
@MoriTang MoriTang changed the title Feat/balance status item feat(tui): add balance status item May 24, 2026
@MoriTang MoriTang mentioned this pull request May 25, 2026
6 tasks
@Hmbown
Copy link
Copy Markdown
Owner

Hmbown commented May 27, 2026

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 tui-core and restructures workspace crates (5342 deletions) — both #1970 and #2257 will conflict heavily on crates/tui/src/**, but #2257's rebase is recoverable; #1970's is not. Superseded by #2257: yes — recommend closing #1970 in favor of #2257.

@Hmbown
Copy link
Copy Markdown
Owner

Hmbown commented May 27, 2026

@MoriTang — appreciation for the original balance feature. After the v0.8.45 → v0.8.46 series, this branch is now 264 files behind main and the rebase has become impractical. PR #2257 (HUQIANTAO) explicitly carries this work — rebased to v0.8.47, fixed 3 clippy warnings, reordered Balance after Cost, and your 6 balance unit tests are still there. So your design + tests are alive in #2257.

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.

@MoriTang
Copy link
Copy Markdown
Author

@MoriTang — appreciation for the original balance feature. After the v0.8.45 → v0.8.46 series, this branch is now 264 files behind main and the rebase has become impractical. PR #2257 (HUQIANTAO) explicitly carries this work — rebased to v0.8.47, fixed 3 clippy warnings, reordered Balance after Cost, and your 6 balance unit tests are still there. So your design + tests are alive in #2257.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants