opencode-multi-account-core 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 +14 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -712,8 +712,16 @@ function createAccountManagerForProvider(dependencies) {
|
|
|
712
712
|
}
|
|
713
713
|
async applyUsageCache(uuid, usage) {
|
|
714
714
|
await this.store.mutateAccount(uuid, (account) => {
|
|
715
|
+
const now = Date.now();
|
|
716
|
+
const exhaustedTierResetTimes = [usage.five_hour, usage.seven_day].flatMap((tier) => {
|
|
717
|
+
if (tier == null || tier.utilization < 100 || tier.resets_at == null) {
|
|
718
|
+
return [];
|
|
719
|
+
}
|
|
720
|
+
return [Date.parse(tier.resets_at)];
|
|
721
|
+
}).filter((resetAt) => Number.isFinite(resetAt) && resetAt > now);
|
|
715
722
|
account.cachedUsage = usage;
|
|
716
723
|
account.cachedUsageAt = Date.now();
|
|
724
|
+
account.rateLimitResetAt = exhaustedTierResetTimes.length > 0 ? Math.min(...exhaustedTierResetTimes) : void 0;
|
|
717
725
|
});
|
|
718
726
|
}
|
|
719
727
|
async applyProfileCache(uuid, profile) {
|
|
@@ -1118,6 +1126,9 @@ var MAX_RESOLVE_ATTEMPTS = 10;
|
|
|
1118
1126
|
var SERVER_RETRY_BASE_MS = 1e3;
|
|
1119
1127
|
var SERVER_RETRY_MAX_MS = 4e3;
|
|
1120
1128
|
var PERMANENT_AUTH_FAILURE_STATUSES = /* @__PURE__ */ new Set([400, 401, 403]);
|
|
1129
|
+
function isAbortError(error) {
|
|
1130
|
+
return error instanceof Error && error.name === "AbortError";
|
|
1131
|
+
}
|
|
1121
1132
|
function createExecutorForProvider(providerName, dependencies) {
|
|
1122
1133
|
const {
|
|
1123
1134
|
handleRateLimitResponse,
|
|
@@ -1150,6 +1161,7 @@ function createExecutorForProvider(providerName, dependencies) {
|
|
|
1150
1161
|
runtime = await runtimeFactory.getRuntime(accountUuid);
|
|
1151
1162
|
response = await runtime.fetch(input, init);
|
|
1152
1163
|
} catch (error) {
|
|
1164
|
+
if (isAbortError(error)) throw error;
|
|
1153
1165
|
if (await handleRuntimeFetchFailure(manager, runtimeFactory, client, account, error)) {
|
|
1154
1166
|
continue;
|
|
1155
1167
|
}
|
|
@@ -1167,6 +1179,7 @@ function createExecutorForProvider(providerName, dependencies) {
|
|
|
1167
1179
|
try {
|
|
1168
1180
|
serverResponse = await runtime.fetch(input, init);
|
|
1169
1181
|
} catch (error) {
|
|
1182
|
+
if (isAbortError(error)) throw error;
|
|
1170
1183
|
if (await handleRuntimeFetchFailure(manager, runtimeFactory, client, account, error)) {
|
|
1171
1184
|
authFailureDuringServerRetry = true;
|
|
1172
1185
|
break;
|
|
@@ -1195,6 +1208,7 @@ function createExecutorForProvider(providerName, dependencies) {
|
|
|
1195
1208
|
return retryResponse;
|
|
1196
1209
|
}
|
|
1197
1210
|
} catch (error) {
|
|
1211
|
+
if (isAbortError(error)) throw error;
|
|
1198
1212
|
if (await handleRuntimeFetchFailure(manager, runtimeFactory, client, account, error)) {
|
|
1199
1213
|
continue;
|
|
1200
1214
|
}
|