opencode-anthropic-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
@@ -699,8 +699,16 @@ function createAccountManagerForProvider(dependencies) {
699
699
  }
700
700
  async applyUsageCache(uuid, usage) {
701
701
  await this.store.mutateAccount(uuid, (account) => {
702
+ const now = Date.now();
703
+ const exhaustedTierResetTimes = [usage.five_hour, usage.seven_day].flatMap((tier) => {
704
+ if (tier == null || tier.utilization < 100 || tier.resets_at == null) {
705
+ return [];
706
+ }
707
+ return [Date.parse(tier.resets_at)];
708
+ }).filter((resetAt) => Number.isFinite(resetAt) && resetAt > now);
702
709
  account.cachedUsage = usage;
703
710
  account.cachedUsageAt = Date.now();
711
+ account.rateLimitResetAt = exhaustedTierResetTimes.length > 0 ? Math.min(...exhaustedTierResetTimes) : void 0;
704
712
  });
705
713
  }
706
714
  async applyProfileCache(uuid, profile) {
@@ -2078,17 +2086,21 @@ function formatDate(timestamp) {
2078
2086
  function getAccountStatus(account) {
2079
2087
  if (account.isAuthDisabled) return "auth-disabled";
2080
2088
  if (!account.enabled) return "disabled";
2081
- if (account.rateLimitResetAt && account.rateLimitResetAt > Date.now()) return "rate-limited";
2082
2089
  if (account.cachedUsage) {
2083
2090
  const now = Date.now();
2084
2091
  const usage = account.cachedUsage;
2092
+ const hasEvaluableUsageTier = [usage.five_hour, usage.seven_day].some((tier) => tier != null);
2085
2093
  const exhaustedTiers = [usage.five_hour, usage.seven_day].filter(
2086
2094
  (tier) => tier && tier.utilization >= 100 && tier.resets_at != null && Date.parse(tier.resets_at) > now
2087
2095
  );
2088
2096
  if (exhaustedTiers.length > 0) {
2089
2097
  return "rate-limited";
2090
2098
  }
2099
+ if (hasEvaluableUsageTier) {
2100
+ return "active";
2101
+ }
2091
2102
  }
2103
+ if (account.rateLimitResetAt && account.rateLimitResetAt > Date.now()) return "rate-limited";
2092
2104
  return "active";
2093
2105
  }
2094
2106
  var STATUS_BADGE = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-anthropic-multi-account",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "OpenCode plugin for Anthropic multi-account management with automatic rate limit switching",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
@@ -39,7 +39,7 @@
39
39
  "directory": "packages/anthropic-multi-account"
40
40
  },
41
41
  "dependencies": {
42
- "opencode-multi-account-core": "^0.2.1",
42
+ "opencode-multi-account-core": "^0.2.2",
43
43
  "opencode-anthropic-auth": "^0.0.13",
44
44
  "valibot": "^1.2.0"
45
45
  },