opencode-codex-multi-account 0.2.1 → 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.
Files changed (2) hide show
  1. package/dist/index.js +13 -1
  2. package/package.json +2 -2
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) {
@@ -2407,17 +2415,21 @@ function formatDate(timestamp) {
2407
2415
  function getAccountStatus(account) {
2408
2416
  if (account.isAuthDisabled) return "auth-disabled";
2409
2417
  if (!account.enabled) return "disabled";
2410
- if (account.rateLimitResetAt && account.rateLimitResetAt > Date.now()) return "rate-limited";
2411
2418
  if (account.cachedUsage) {
2412
2419
  const now = Date.now();
2413
2420
  const usage = account.cachedUsage;
2421
+ const hasEvaluableUsageTier = [usage.five_hour, usage.seven_day].some((tier) => tier != null);
2414
2422
  const exhaustedTiers = [usage.five_hour, usage.seven_day].filter(
2415
2423
  (tier) => tier && tier.utilization >= 100 && tier.resets_at != null && Date.parse(tier.resets_at) > now
2416
2424
  );
2417
2425
  if (exhaustedTiers.length > 0) {
2418
2426
  return "rate-limited";
2419
2427
  }
2428
+ if (hasEvaluableUsageTier) {
2429
+ return "active";
2430
+ }
2420
2431
  }
2432
+ if (account.rateLimitResetAt && account.rateLimitResetAt > Date.now()) return "rate-limited";
2421
2433
  return "active";
2422
2434
  }
2423
2435
  var STATUS_BADGE = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-codex-multi-account",
3
- "version": "0.2.1",
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.1",
43
+ "opencode-multi-account-core": "^0.2.2",
44
44
  "valibot": "^1.2.0"
45
45
  },
46
46
  "devDependencies": {