opencode-codex-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.
- package/dist/index.js +21 -3
- 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) {
|
|
@@ -1104,6 +1112,9 @@ var MAX_RESOLVE_ATTEMPTS = 10;
|
|
|
1104
1112
|
var SERVER_RETRY_BASE_MS = 1e3;
|
|
1105
1113
|
var SERVER_RETRY_MAX_MS = 4e3;
|
|
1106
1114
|
var PERMANENT_AUTH_FAILURE_STATUSES = /* @__PURE__ */ new Set([400, 401, 403]);
|
|
1115
|
+
function isAbortError(error) {
|
|
1116
|
+
return error instanceof Error && error.name === "AbortError";
|
|
1117
|
+
}
|
|
1107
1118
|
function createExecutorForProvider(providerName, dependencies) {
|
|
1108
1119
|
const {
|
|
1109
1120
|
handleRateLimitResponse: handleRateLimitResponse2,
|
|
@@ -1136,6 +1147,7 @@ function createExecutorForProvider(providerName, dependencies) {
|
|
|
1136
1147
|
runtime = await runtimeFactory.getRuntime(accountUuid);
|
|
1137
1148
|
response = await runtime.fetch(input, init);
|
|
1138
1149
|
} catch (error) {
|
|
1150
|
+
if (isAbortError(error)) throw error;
|
|
1139
1151
|
if (await handleRuntimeFetchFailure(manager, runtimeFactory, client, account, error)) {
|
|
1140
1152
|
continue;
|
|
1141
1153
|
}
|
|
@@ -1153,6 +1165,7 @@ function createExecutorForProvider(providerName, dependencies) {
|
|
|
1153
1165
|
try {
|
|
1154
1166
|
serverResponse = await runtime.fetch(input, init);
|
|
1155
1167
|
} catch (error) {
|
|
1168
|
+
if (isAbortError(error)) throw error;
|
|
1156
1169
|
if (await handleRuntimeFetchFailure(manager, runtimeFactory, client, account, error)) {
|
|
1157
1170
|
authFailureDuringServerRetry = true;
|
|
1158
1171
|
break;
|
|
@@ -1181,6 +1194,7 @@ function createExecutorForProvider(providerName, dependencies) {
|
|
|
1181
1194
|
return retryResponse;
|
|
1182
1195
|
}
|
|
1183
1196
|
} catch (error) {
|
|
1197
|
+
if (isAbortError(error)) throw error;
|
|
1184
1198
|
if (await handleRuntimeFetchFailure(manager, runtimeFactory, client, account, error)) {
|
|
1185
1199
|
continue;
|
|
1186
1200
|
}
|
|
@@ -2345,11 +2359,11 @@ function getUsageSummary(account) {
|
|
|
2345
2359
|
const parts = [];
|
|
2346
2360
|
const { five_hour, seven_day } = parsed.output;
|
|
2347
2361
|
if (five_hour) {
|
|
2348
|
-
const reset = five_hour.
|
|
2362
|
+
const reset = five_hour.resets_at ? ` (resets ${formatTimeRemaining(five_hour.resets_at)})` : "";
|
|
2349
2363
|
parts.push(`5h: ${five_hour.utilization.toFixed(0)}%${reset}`);
|
|
2350
2364
|
}
|
|
2351
2365
|
if (seven_day) {
|
|
2352
|
-
const reset = seven_day.
|
|
2366
|
+
const reset = seven_day.resets_at ? ` (resets ${formatTimeRemaining(seven_day.resets_at)})` : "";
|
|
2353
2367
|
parts.push(`7d: ${seven_day.utilization.toFixed(0)}%${reset}`);
|
|
2354
2368
|
}
|
|
2355
2369
|
return parts.length > 0 ? parts.join(", ") : "no usage data";
|
|
@@ -2407,17 +2421,21 @@ function formatDate(timestamp) {
|
|
|
2407
2421
|
function getAccountStatus(account) {
|
|
2408
2422
|
if (account.isAuthDisabled) return "auth-disabled";
|
|
2409
2423
|
if (!account.enabled) return "disabled";
|
|
2410
|
-
if (account.rateLimitResetAt && account.rateLimitResetAt > Date.now()) return "rate-limited";
|
|
2411
2424
|
if (account.cachedUsage) {
|
|
2412
2425
|
const now = Date.now();
|
|
2413
2426
|
const usage = account.cachedUsage;
|
|
2427
|
+
const hasEvaluableUsageTier = [usage.five_hour, usage.seven_day].some((tier) => tier != null);
|
|
2414
2428
|
const exhaustedTiers = [usage.five_hour, usage.seven_day].filter(
|
|
2415
2429
|
(tier) => tier && tier.utilization >= 100 && tier.resets_at != null && Date.parse(tier.resets_at) > now
|
|
2416
2430
|
);
|
|
2417
2431
|
if (exhaustedTiers.length > 0) {
|
|
2418
2432
|
return "rate-limited";
|
|
2419
2433
|
}
|
|
2434
|
+
if (hasEvaluableUsageTier) {
|
|
2435
|
+
return "active";
|
|
2436
|
+
}
|
|
2420
2437
|
}
|
|
2438
|
+
if (account.rateLimitResetAt && account.rateLimitResetAt > Date.now()) return "rate-limited";
|
|
2421
2439
|
return "active";
|
|
2422
2440
|
}
|
|
2423
2441
|
var STATUS_BADGE = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-codex-multi-account",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
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.
|
|
43
|
+
"opencode-multi-account-core": "^0.2.3",
|
|
44
44
|
"valibot": "^1.2.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|