feat(webui): add subscription tier and quota visualization
Backend:
This commit is contained in:
25
CLAUDE.md
25
CLAUDE.md
@@ -134,6 +134,7 @@ public/
|
||||
- **src/server.js**: Express server exposing Anthropic-compatible endpoints (`/v1/messages`, `/v1/models`, `/health`, `/account-limits`) and mounting WebUI
|
||||
- **src/webui/index.js**: WebUI backend handling API routes (`/api/*`) for config, accounts, and logs
|
||||
- **src/cloudcode/**: Cloud Code API client with retry/failover logic, streaming and non-streaming support
|
||||
- `model-api.js`: Model listing, quota retrieval (`getModelQuotas()`), and subscription tier detection (`getSubscriptionTier()`)
|
||||
- **src/account-manager/**: Multi-account pool with sticky selection, rate limit handling, and automatic cooldown
|
||||
- **src/auth/**: Authentication including Google OAuth, token extraction, database access, and auto-rebuild of native modules
|
||||
- **src/format/**: Format conversion between Anthropic and Google Generative AI formats
|
||||
@@ -148,6 +149,17 @@ public/
|
||||
- Session ID derived from first user message hash for cache continuity
|
||||
- Account state persisted to `~/.config/antigravity-proxy/accounts.json`
|
||||
|
||||
**Account Data Model:**
|
||||
Each account object in `accounts.json` contains:
|
||||
- **Basic Info**: `email`, `source` (oauth/manual/database), `enabled`, `lastUsed`
|
||||
- **Credentials**: `refreshToken` (OAuth) or `apiKey` (manual)
|
||||
- **Subscription**: `{ tier, projectId, detectedAt }` - automatically detected via `loadCodeAssist` API
|
||||
- `tier`: 'free' | 'pro' | 'ultra' (detected from `paidTier` or `currentTier`)
|
||||
- **Quota**: `{ models: {}, lastChecked }` - model-specific quota cache
|
||||
- `models[modelId]`: `{ remainingFraction, resetTime }` from `fetchAvailableModels` API
|
||||
- **Rate Limits**: `modelRateLimits[modelId]` - temporary rate limit state (in-memory during runtime)
|
||||
- **Validity**: `isInvalid`, `invalidReason` - tracks accounts needing re-authentication
|
||||
|
||||
**Prompt Caching:**
|
||||
- Cache is organization-scoped (requires same account + session ID)
|
||||
- Session ID is SHA256 hash of first user message content (stable across turns)
|
||||
@@ -183,11 +195,13 @@ public/
|
||||
- **Architecture**: Single Page Application (SPA) with dynamic view loading
|
||||
- **State Management**: Alpine.store for global state (accounts, settings, logs)
|
||||
- **Features**:
|
||||
- Real-time dashboard with Chart.js visualization
|
||||
- Real-time dashboard with Chart.js visualization and subscription tier distribution
|
||||
- Account list with tier badges (Ultra/Pro/Free) and quota progress bars
|
||||
- OAuth flow handling via popup window
|
||||
- Live log streaming via Server-Sent Events (SSE)
|
||||
- Config editor for both Proxy and Claude CLI (`~/.claude/settings.json`)
|
||||
- **Security**: Optional password protection via `WEBUI_PASSWORD` env var
|
||||
- **Smart Refresh**: Client-side polling with ±20% jitter and tab visibility detection (3x slower when hidden)
|
||||
|
||||
## Testing Notes
|
||||
|
||||
@@ -223,6 +237,12 @@ public/
|
||||
- `sleep(ms)` - Promise-based delay
|
||||
- `isNetworkError(error)` - Check if error is a transient network error
|
||||
|
||||
**Data Persistence:**
|
||||
- Subscription and quota data are automatically fetched when `/account-limits` is called
|
||||
- Updated data is saved to `accounts.json` asynchronously (non-blocking)
|
||||
- On server restart, accounts load with last known subscription/quota state
|
||||
- Quota is refreshed on each WebUI poll (default: 30s with jitter)
|
||||
|
||||
**Logger:** Structured logging via `src/utils/logger.js`:
|
||||
- `logger.info(msg)` - Standard info (blue)
|
||||
- `logger.success(msg)` - Success messages (green)
|
||||
@@ -239,6 +259,9 @@ public/
|
||||
- `/api/claude/config` - Claude CLI settings
|
||||
- `/api/logs/stream` - SSE endpoint for real-time logs
|
||||
- `/api/auth/url` - Generate Google OAuth URL
|
||||
- `/account-limits` - Fetch account quotas and subscription data
|
||||
- Returns: `{ accounts: [{ email, subscription: { tier, projectId }, limits: {...} }], models: [...] }`
|
||||
- Query params: `?format=table` (ASCII table) or `?includeHistory=true` (adds usage stats)
|
||||
|
||||
## Maintenance
|
||||
|
||||
|
||||
Reference in New Issue
Block a user