Replace direct token decryption with getValidAccessToken call to
enable automatic token expiration check and refresh. This fixes
authentication_error when fetching OAuth usage data with expired
access tokens.
Add OAuth usage visualization for Claude OAuth accounts while maintaining
existing Setup Token session window display. Accounts show different UI
based on authorization type detected via scopes.
Changes:
- Add loadClaudeUsage() for async OAuth usage data loading
- Add isClaudeOAuth() to detect auth type (checks user:profile + user:inference scopes)
- Add OAuth helpers: formatClaudeUsagePercent, getClaudeUsageWidth,
getClaudeUsageBarClass, formatClaudeRemaining
- Display three OAuth windows (5h, 7d, 7d-Opus) for OAuth accounts
- Maintain original session window display for Setup Token accounts
- Color-coded progress bars (blue < 60%, yellow 60-90%, red >= 90%)
- Update tooltip with OAuth documentation
- Remove duplicate Claude fallback branch
- Apply to desktop and mobile views
Add dedicated API endpoint to fetch Claude account OAuth usage data
asynchronously, improving user experience by eliminating the need for
multiple page refreshes to view session window statistics.
Backend changes:
- Add GET /admin/claude-accounts/usage endpoint for batch fetching
- Implement fetchOAuthUsage() to call Claude API /api/oauth/usage
- Add buildClaudeUsageSnapshot() to construct frontend data structure
- Add updateClaudeUsageSnapshot() to persist data to Redis
- Add _toNumberOrNull() helper for safe type conversion
- Update getAllAccounts() to return claudeUsage from Redis cache
Data structure:
- Store three window types: 5h, 7d, 7d-Opus
- Track utilization percentage and reset timestamps
- Calculate remaining seconds for each window
Performance optimizations:
- Concurrent batch requests using Promise.allSettled
- Graceful error handling per account
- Non-blocking async execution