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:
Eyejoker
2026-03-23 22:15:06 +09:00
parent d378598f2e
commit 83b25fb7bd
4 changed files with 181 additions and 218 deletions

View File

@@ -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;