opencode-anthropic-multi-account 0.2.1 → 0.2.3

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 +21 -3
  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) {
@@ -1105,6 +1113,9 @@ var MAX_RESOLVE_ATTEMPTS = 10;
1105
1113
  var SERVER_RETRY_BASE_MS = 1e3;
1106
1114
  var SERVER_RETRY_MAX_MS = 4e3;
1107
1115
  var PERMANENT_AUTH_FAILURE_STATUSES = /* @__PURE__ */ new Set([400, 401, 403]);
1116
+ function isAbortError(error) {
1117
+ return error instanceof Error && error.name === "AbortError";
1118
+ }
1108
1119
  function createExecutorForProvider(providerName, dependencies) {
1109
1120
  const {
1110
1121
  handleRateLimitResponse: handleRateLimitResponse2,
@@ -1137,6 +1148,7 @@ function createExecutorForProvider(providerName, dependencies) {
1137
1148
  runtime = await runtimeFactory.getRuntime(accountUuid);
1138
1149
  response = await runtime.fetch(input, init);
1139
1150
  } catch (error) {
1151
+ if (isAbortError(error)) throw error;
1140
1152
  if (await handleRuntimeFetchFailure(manager, runtimeFactory, client, account, error)) {
1141
1153
  continue;
1142
1154
  }
@@ -1154,6 +1166,7 @@ function createExecutorForProvider(providerName, dependencies) {
1154
1166
  try {
1155
1167
  serverResponse = await runtime.fetch(input, init);
1156
1168
  } catch (error) {
1169
+ if (isAbortError(error)) throw error;
1157
1170
  if (await handleRuntimeFetchFailure(manager, runtimeFactory, client, account, error)) {
1158
1171
  authFailureDuringServerRetry = true;
1159
1172
  break;
@@ -1182,6 +1195,7 @@ function createExecutorForProvider(providerName, dependencies) {
1182
1195
  return retryResponse;
1183
1196
  }
1184
1197
  } catch (error) {
1198
+ if (isAbortError(error)) throw error;
1185
1199
  if (await handleRuntimeFetchFailure(manager, runtimeFactory, client, account, error)) {
1186
1200
  continue;
1187
1201
  }
@@ -2019,11 +2033,11 @@ function getUsageSummary(account) {
2019
2033
  const parts = [];
2020
2034
  const { five_hour, seven_day } = account.cachedUsage;
2021
2035
  if (five_hour) {
2022
- const reset = five_hour.utilization >= 100 && five_hour.resets_at ? ` (resets ${formatTimeRemaining(five_hour.resets_at)})` : "";
2036
+ const reset = five_hour.resets_at ? ` (resets ${formatTimeRemaining(five_hour.resets_at)})` : "";
2023
2037
  parts.push(`5h: ${five_hour.utilization.toFixed(0)}%${reset}`);
2024
2038
  }
2025
2039
  if (seven_day) {
2026
- const reset = seven_day.utilization >= 100 && seven_day.resets_at ? ` (resets ${formatTimeRemaining(seven_day.resets_at)})` : "";
2040
+ const reset = seven_day.resets_at ? ` (resets ${formatTimeRemaining(seven_day.resets_at)})` : "";
2027
2041
  parts.push(`7d: ${seven_day.utilization.toFixed(0)}%${reset}`);
2028
2042
  }
2029
2043
  return parts.length > 0 ? parts.join(", ") : "no data";
@@ -2078,17 +2092,21 @@ function formatDate(timestamp) {
2078
2092
  function getAccountStatus(account) {
2079
2093
  if (account.isAuthDisabled) return "auth-disabled";
2080
2094
  if (!account.enabled) return "disabled";
2081
- if (account.rateLimitResetAt && account.rateLimitResetAt > Date.now()) return "rate-limited";
2082
2095
  if (account.cachedUsage) {
2083
2096
  const now = Date.now();
2084
2097
  const usage = account.cachedUsage;
2098
+ const hasEvaluableUsageTier = [usage.five_hour, usage.seven_day].some((tier) => tier != null);
2085
2099
  const exhaustedTiers = [usage.five_hour, usage.seven_day].filter(
2086
2100
  (tier) => tier && tier.utilization >= 100 && tier.resets_at != null && Date.parse(tier.resets_at) > now
2087
2101
  );
2088
2102
  if (exhaustedTiers.length > 0) {
2089
2103
  return "rate-limited";
2090
2104
  }
2105
+ if (hasEvaluableUsageTier) {
2106
+ return "active";
2107
+ }
2091
2108
  }
2109
+ if (account.rateLimitResetAt && account.rateLimitResetAt > Date.now()) return "rate-limited";
2092
2110
  return "active";
2093
2111
  }
2094
2112
  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.3",
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.3",
43
43
  "opencode-anthropic-auth": "^0.0.13",
44
44
  "valibot": "^1.2.0"
45
45
  },