feat: Claude usage API + multi-account dashboard display
- Replace expect/CLI hack with direct HTTP API call (GET api.anthropic.com/api/oauth/usage with OAuth token) - Add fetchAllClaudeUsage() for per-token usage fetching - Export getAllTokens() from token-rotation for usage queries - Dashboard shows each account separately (Claude1⚡, Claude2) with ⚡ for active token, 🚫 for rate-limited
This commit is contained in:
@@ -29,7 +29,10 @@ export function initTokenRotation(): void {
|
||||
const single = process.env.CLAUDE_CODE_OAUTH_TOKEN;
|
||||
|
||||
const raw = multi
|
||||
? multi.split(',').map((t) => t.trim()).filter(Boolean)
|
||||
? multi
|
||||
.split(',')
|
||||
.map((t) => t.trim())
|
||||
.filter(Boolean)
|
||||
: single
|
||||
? [single]
|
||||
: [];
|
||||
@@ -99,6 +102,18 @@ export function getTokenCount(): number {
|
||||
return tokens.length;
|
||||
}
|
||||
|
||||
/** Get all configured tokens (masked for display, raw for API calls). */
|
||||
export function getAllTokens(): { index: number; token: string; masked: string; isActive: boolean; isRateLimited: boolean }[] {
|
||||
const now = Date.now();
|
||||
return tokens.map((t, i) => ({
|
||||
index: i,
|
||||
token: t.token,
|
||||
masked: `${t.token.slice(0, 20)}...${t.token.slice(-4)}`,
|
||||
isActive: i === currentIndex,
|
||||
isRateLimited: Boolean(t.rateLimitedUntil && t.rateLimitedUntil > now),
|
||||
}));
|
||||
}
|
||||
|
||||
/** Diagnostic info. */
|
||||
export function getTokenRotationInfo(): {
|
||||
total: number;
|
||||
|
||||
Reference in New Issue
Block a user