From 0981194eed75fab9ace1219a1f2619d1527ad5d3 Mon Sep 17 00:00:00 2001 From: Nelson Pires Date: Sun, 1 Feb 2026 13:30:30 -0300 Subject: [PATCH] feat: Multi-provider Usage Dashboard & Quota Monitoring (#259) * feat(openchamber): persist usage auto-refresh settings Enable a switch to toggle automatic usage refresh Provide input to configure refresh interval in milliseconds Persist changes to desktop settings and server API when changed * feat: add UsageCard component Add a new UsageCard component to display a usage window with title, optional subtitle, and a progress bar Show current usage percentage and a reset time label for the window Render a formatted window label and a compact subtitle for concise UI * feat(usage): add UsagePage UI for quota usage Add a dedicated UsagePage with provider-based usage details Show last updated time and auto-refresh status Handle empty, not configured, and error states with informative banners * feat(usage): add UsageProgressBar component Introduce a new UsageProgressBar component to visualize quota usage Display a gradient fill that changes with critical, warn, or normal tones Expose accessible progress attributes for screen readers * feat(usage): add UsageSidebar component Display quotas for all providers in a scrollable sidebar Refresh quotas with a button and loading indicator Colorize provider rows based on usage status and runtime context * feat: add usage section to Settings Add a new Usage item to the Settings sidebar for desktop and mobile Render UsagePage when the Usage tab is selected in Settings Wire up new UsageSidebar and UsagePage components under usage * feat: add Usage section to sidebar Add new Usage section in the sidebar for API quota monitoring. Display a bar chart icon and description for the Usage item. Monitor and display API quota usage across providers. * feat(desktop): add usage auto-refresh settings Enable automatic refresh for usage data with new settings Store refresh interval in milliseconds for usage updates * feat(persistence): support usageAutoRefresh and usageRefreshIntervalMs Persist usageAutoRefresh in desktop settings Persist usageRefreshIntervalMs in desktop settings Validate types for new fields during sanitizeWebSettings * feat(quota): export providers and utilities Expose QUOTA_PROVIDERS and QUOTA_PROVIDER_MAP for consumers Export QuotaProviderMeta type for user code Make formatting and usage resolution utilities available from quota module * feat(quota): define base quota provider interface Define QuotaProvider interface with id, name, isConfigured, and fetchQuota Expose ProviderResult type in fetchQuota contract * feat: add quota providers index and map Expose QUOTA_PROVIDERS with OpenAI, Google and z.ai Provide QUOTA_PROVIDER_MAP for quick provider lookup by id * feat: add quota utils for percent formatting and tone Add clampPercent to sanitize and clamp numbers to 0-100 Add formatPercent to render '-' for null and 'x%' for values Add resolveUsageTone to categorize percent as safe, warn, or critical * feat: add useQuotaStore for quota data Load usage settings from desktop, VSCode, or API at startup Fetch quotas for all providers in parallel and update loading state Expose lastUpdated timestamp and error state for UI feedback * feat: export quota types from quota module Expose quota-related types in UI type definitions Allow downstream code to import QuotaProviderId and related types Aggregate quota exports under the quota module in index * feat: add quota types for usage providers Add QuotaProviderId and UsageWindow shapes to model quota data Add ProviderUsage, ProviderResult, and related usage mapping for providers * feat: add quota provider endpoints API List available quota providers via GET /api/quota/providers Retrieve quota details for a specific provider with GET /api/quota/:providerId Log errors and return 500 with error message on quota fetch failures * feat: add quota providers discovery and formatting Detect configured quota providers from auth and account files Normalize auth entries to tokens or objects for API usage Expose formatted reset times and remaining window metrics * feat: persist usage settings in UsageSidebar and remove from defaults Load usage settings on mount for the sidebar Persist changes to auto-refresh and refresh interval to server Remove usage settings state and effects from DefaultsSettings * fix(usage): guard auto-select in UsagePage when results empty Guard auto-select in UsagePage when results are empty Prevent unexpected provider selection on initial render * fix(quota): set error state during quota updates Reset error to null when a new quota result is added Set error to the error message on fetch failure or fallback Keep error state alongside results in all update paths --- .../sections/openchamber/DefaultsSettings.tsx | 5 +- .../components/sections/usage/UsageCard.tsx | 39 ++ .../components/sections/usage/UsagePage.tsx | 124 +++++ .../sections/usage/UsageProgressBar.tsx | 32 ++ .../sections/usage/UsageSidebar.tsx | 175 ++++++ .../ui/src/components/views/SettingsView.tsx | 6 + packages/ui/src/constants/sidebar.ts | 10 +- packages/ui/src/lib/desktop.ts | 2 + packages/ui/src/lib/persistence.ts | 6 + packages/ui/src/lib/quota/index.ts | 3 + packages/ui/src/lib/quota/providers/base.ts | 8 + packages/ui/src/lib/quota/providers/index.ts | 20 + packages/ui/src/lib/quota/utils.ts | 33 ++ packages/ui/src/stores/useQuotaStore.ts | 180 +++++++ packages/ui/src/types/index.ts | 7 + packages/ui/src/types/quota.ts | 29 + packages/web/server/index.js | 40 ++ packages/web/server/lib/quota-providers.js | 509 ++++++++++++++++++ 18 files changed, 1225 insertions(+), 3 deletions(-) create mode 100644 packages/ui/src/components/sections/usage/UsageCard.tsx create mode 100644 packages/ui/src/components/sections/usage/UsagePage.tsx create mode 100644 packages/ui/src/components/sections/usage/UsageProgressBar.tsx create mode 100644 packages/ui/src/components/sections/usage/UsageSidebar.tsx create mode 100644 packages/ui/src/lib/quota/index.ts create mode 100644 packages/ui/src/lib/quota/providers/base.ts create mode 100644 packages/ui/src/lib/quota/providers/index.ts create mode 100644 packages/ui/src/lib/quota/utils.ts create mode 100644 packages/ui/src/stores/useQuotaStore.ts create mode 100644 packages/ui/src/types/quota.ts create mode 100644 packages/web/server/lib/quota-providers.js diff --git a/packages/ui/src/components/sections/openchamber/DefaultsSettings.tsx b/packages/ui/src/components/sections/openchamber/DefaultsSettings.tsx index 1e524d47..b34a679e 100644 --- a/packages/ui/src/components/sections/openchamber/DefaultsSettings.tsx +++ b/packages/ui/src/components/sections/openchamber/DefaultsSettings.tsx @@ -125,6 +125,7 @@ export const DefaultsSettings: React.FC = () => { loadSettings(); }, []); + const handleModelChange = React.useCallback(async (providerId: string, modelId: string) => { const newValue = providerId && modelId ? `${providerId}/${modelId}` : undefined; setDefaultModel(newValue); @@ -243,6 +244,7 @@ export const DefaultsSettings: React.FC = () => { } }, [setSettingsAutoCreateWorktree]); + if (isLoading) { return null; } @@ -301,7 +303,7 @@ export const DefaultsSettings: React.FC = () => { - {(parsedModel.providerId || defaultAgent) && ( + {(parsedModel.providerId || defaultAgent) && (
New sessions will start with:{' '} {parsedModel.providerId && ( @@ -315,6 +317,7 @@ export const DefaultsSettings: React.FC = () => {
)} + {!isVSCode && (