feat: Add (z.ai) plan usage tracking in the sidebar #6298
+251
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When using LLM providers with quota limits (like zai-coding-plan), users have no visibility into their remaining quota or when it resets. This makes it difficult to track usage and avoid unexpected service interruptions.
Solution
Added plan usage display to the TUI sidebar that shows:
Implementation
Core abstraction (
src/provider/plan-usage.ts)Generic
PlanUsageinterface that all providers implement:Features:
registerProvider(id, handler)getPercentage(),formatResetTime()Provider implementation (
src/provider/plan-usage/zai.ts)/api/monitor/usage/quota/limitendpointTOKENS_LIMIT(ignores time-based limits)zai-coding-planhandlerUI integration (
sidebar.tsx)Adding support for other providers
The pattern uses side-effect imports. The core module imports provider modules, which register themselves on load.
Step 1: Add import to
src/provider/plan-usage.ts:Step 2: Create
src/provider/plan-usage/your-provider.ts:The handler receives:
token- API key from authbaseURL- Provider's base URL from configtimeout- Request timeout in ms (default 5000)And returns: