opencode-codex-multi-account 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -698,8 +698,16 @@ function createAccountManagerForProvider(dependencies) {
698
698
  }
699
699
  async applyUsageCache(uuid, usage) {
700
700
  await this.store.mutateAccount(uuid, (account) => {
701
+ const now = Date.now();
702
+ const exhaustedTierResetTimes = [usage.five_hour, usage.seven_day].flatMap((tier) => {
703
+ if (tier == null || tier.utilization < 100 || tier.resets_at == null) {
704
+ return [];
705
+ }
706
+ return [Date.parse(tier.resets_at)];
707
+ }).filter((resetAt) => Number.isFinite(resetAt) && resetAt > now);
701
708
  account.cachedUsage = usage;
702
709
  account.cachedUsageAt = Date.now();
710
+ account.rateLimitResetAt = exhaustedTierResetTimes.length > 0 ? Math.min(...exhaustedTierResetTimes) : void 0;
703
711
  });
704
712
  }
705
713
  async applyProfileCache(uuid, profile) {
@@ -2345,11 +2353,11 @@ function getUsageSummary(account) {
2345
2353
  const parts = [];
2346
2354
  const { five_hour, seven_day } = parsed.output;
2347
2355
  if (five_hour) {
2348
- const reset = five_hour.resets_at ? ` (resets ${formatTimeRemaining(five_hour.resets_at)})` : "";
2356
+ const reset = five_hour.utilization >= 100 && five_hour.resets_at ? ` (resets ${formatTimeRemaining(five_hour.resets_at)})` : "";
2349
2357
  parts.push(`5h: ${five_hour.utilization.toFixed(0)}%${reset}`);
2350
2358
  }
2351
2359
  if (seven_day) {
2352
- const reset = seven_day.resets_at ? ` (resets ${formatTimeRemaining(seven_day.resets_at)})` : "";
2360
+ const reset = seven_day.utilization >= 100 && seven_day.resets_at ? ` (resets ${formatTimeRemaining(seven_day.resets_at)})` : "";
2353
2361
  parts.push(`7d: ${seven_day.utilization.toFixed(0)}%${reset}`);
2354
2362
  }
2355
2363
  return parts.length > 0 ? parts.join(", ") : "no usage data";
@@ -2407,6 +2415,20 @@ function formatDate(timestamp) {
2407
2415
  function getAccountStatus(account) {
2408
2416
  if (account.isAuthDisabled) return "auth-disabled";
2409
2417
  if (!account.enabled) return "disabled";
2418
+ if (account.cachedUsage) {
2419
+ const now = Date.now();
2420
+ const usage = account.cachedUsage;
2421
+ const hasEvaluableUsageTier = [usage.five_hour, usage.seven_day].some((tier) => tier != null);
2422
+ const exhaustedTiers = [usage.five_hour, usage.seven_day].filter(
2423
+ (tier) => tier && tier.utilization >= 100 && tier.resets_at != null && Date.parse(tier.resets_at) > now
2424
+ );
2425
+ if (exhaustedTiers.length > 0) {
2426
+ return "rate-limited";
2427
+ }
2428
+ if (hasEvaluableUsageTier) {
2429
+ return "active";
2430
+ }
2431
+ }
2410
2432
  if (account.rateLimitResetAt && account.rateLimitResetAt > Date.now()) return "rate-limited";
2411
2433
  return "active";
2412
2434
  }
@@ -2440,7 +2462,7 @@ async function showAuthMenu(accounts) {
2440
2462
  while (true) {
2441
2463
  const subtitle = `${accounts.length} account(s) registered`;
2442
2464
  const result = await select(items, {
2443
- message: "Claude Multi-Auth",
2465
+ message: "Codex Multi-Auth",
2444
2466
  subtitle
2445
2467
  });
2446
2468
  if (!result) return { type: "cancel" };
@@ -2527,8 +2549,8 @@ function printUsageEntry(name, entry, isLast) {
2527
2549
  return;
2528
2550
  }
2529
2551
  const bar = createProgressBar(entry.utilization);
2530
- const reset = formatResetTime(entry.resets_at);
2531
- console.log(` ${connector} ${name.padEnd(16)} ${bar}${reset}`);
2552
+ const resetInfo = entry.utilization >= 100 && entry.resets_at ? formatResetTime(entry.resets_at) : "";
2553
+ console.log(` ${connector} ${name.padEnd(16)} ${bar}${resetInfo}`);
2532
2554
  }
2533
2555
  function printQuotaReport(account, usage) {
2534
2556
  const label = getAccountLabel(account);
@@ -3110,6 +3132,9 @@ var AccountRuntimeFactory = class {
3110
3132
  };
3111
3133
 
3112
3134
  // src/index.ts
3135
+ function formatResetTime2(resetAt) {
3136
+ return formatWaitTime(new Date(resetAt).getTime() - Date.now());
3137
+ }
3113
3138
  var CodexMultiAuthPlugin = async (ctx) => {
3114
3139
  const { client } = ctx;
3115
3140
  await loadConfig();
@@ -3147,6 +3172,19 @@ var CodexMultiAuthPlugin = async (ctx) => {
3147
3172
  const remaining = formatWaitTime(account.rateLimitResetAt - Date.now());
3148
3173
  statusParts.push(`RATE LIMITED (resets in ${remaining})`);
3149
3174
  }
3175
+ if (account.cachedUsage) {
3176
+ const usage2 = account.cachedUsage;
3177
+ const exhaustedTiers = [
3178
+ { name: "5-hour", tier: usage2.five_hour },
3179
+ { name: "7-day", tier: usage2.seven_day }
3180
+ ].filter(({ tier }) => tier && tier.utilization >= 100);
3181
+ exhaustedTiers.forEach(({ name, tier }) => {
3182
+ if (tier && tier.resets_at) {
3183
+ const resetTime = formatResetTime2(tier.resets_at);
3184
+ statusParts.push(`USAGE EXHAUSTED (${name}, resets ${resetTime})`);
3185
+ }
3186
+ });
3187
+ }
3150
3188
  lines.push(
3151
3189
  `- **${label}**${marker}: ${statusParts.join(" | ")} | ${usage}`
3152
3190
  );
@@ -13,6 +13,8 @@ export type AuthMenuAction = {
13
13
  type: "cancel";
14
14
  };
15
15
  export type AccountAction = "back" | "toggle" | "delete" | "retry-auth" | "cancel";
16
+ type AccountStatus = "active" | "rate-limited" | "auth-disabled" | "disabled";
17
+ export declare function getAccountStatus(account: ManagedAccount): AccountStatus;
16
18
  export declare function showAuthMenu(accounts: ManagedAccount[]): Promise<AuthMenuAction>;
17
19
  export declare function showManageAccounts(accounts: ManagedAccount[]): Promise<{
18
20
  action: AccountAction;
@@ -23,3 +25,4 @@ export declare function showStrategySelect(current: AccountSelectionStrategy): P
23
25
  export type AuthMethod = "browser" | "headless";
24
26
  export declare function showMethodSelect(): Promise<AuthMethod | null>;
25
27
  export declare function printQuotaError(account: ManagedAccount, error: string): void;
28
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-codex-multi-account",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "OpenCode plugin for Codex (OpenAI) multi-account management with automatic rate limit switching",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
@@ -40,7 +40,7 @@
40
40
  "directory": "packages/codex-multi-account"
41
41
  },
42
42
  "dependencies": {
43
- "opencode-multi-account-core": "^0.2.0",
43
+ "opencode-multi-account-core": "^0.2.2",
44
44
  "valibot": "^1.2.0"
45
45
  },
46
46
  "devDependencies": {