@certalis/agent-smith 0.1.2 → 0.1.4
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/bin.js +54 -21
- package/dist/post-processor.worker.js +3 -0
- package/dist/server.js +54 -21
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -705,6 +705,9 @@ function quotaThresholdFor(account, bucket, fleetThreshold) {
|
|
|
705
705
|
function isCurrentQuotaWindow(window, now) {
|
|
706
706
|
return (window.resetAt === null || window.resetAt > now) && now - window.seenAt <= QUOTA_STALE_MS;
|
|
707
707
|
}
|
|
708
|
+
function isOpenQuotaWindow(window, now) {
|
|
709
|
+
return window.resetAt === null ? isCurrentQuotaWindow(window, now) : window.resetAt > now;
|
|
710
|
+
}
|
|
708
711
|
var QUOTA_STALE_MS;
|
|
709
712
|
var init_quota = __esm(() => {
|
|
710
713
|
QUOTA_STALE_MS = 30 * 60000;
|
|
@@ -4453,6 +4456,9 @@ class BaseProvider {
|
|
|
4453
4456
|
isWeeklyBucket(_bucket) {
|
|
4454
4457
|
return false;
|
|
4455
4458
|
}
|
|
4459
|
+
isFiveHourBucket(_bucket) {
|
|
4460
|
+
return false;
|
|
4461
|
+
}
|
|
4456
4462
|
getClientSessionId(headers2) {
|
|
4457
4463
|
return headers2.get("x-claude-code-session-id");
|
|
4458
4464
|
}
|
|
@@ -4690,6 +4696,9 @@ var init_provider = __esm(() => {
|
|
|
4690
4696
|
isWeeklyBucket(bucket) {
|
|
4691
4697
|
return bucket.startsWith("unified7d");
|
|
4692
4698
|
}
|
|
4699
|
+
isFiveHourBucket(bucket) {
|
|
4700
|
+
return bucket === "unified5h";
|
|
4701
|
+
}
|
|
4693
4702
|
prepareHeaders(headers2, account2) {
|
|
4694
4703
|
const newHeaders = new Headers(headers2);
|
|
4695
4704
|
deleteClientCredentialHeaders(newHeaders);
|
|
@@ -5627,6 +5636,9 @@ var init_provider4 = __esm(() => {
|
|
|
5627
5636
|
isWeeklyBucket(bucket) {
|
|
5628
5637
|
return bucket === "unified7d";
|
|
5629
5638
|
}
|
|
5639
|
+
isFiveHourBucket(bucket) {
|
|
5640
|
+
return bucket === "unified5h";
|
|
5641
|
+
}
|
|
5630
5642
|
supportsWebSocket(upstreamPath) {
|
|
5631
5643
|
return upstreamPath === "/responses";
|
|
5632
5644
|
}
|
|
@@ -7102,7 +7114,7 @@ function enrollmentPage() {
|
|
|
7102
7114
|
<div class="avatar ok">${icon("check")}</div>
|
|
7103
7115
|
<h1 tabindex="-1">Subscription connected</h1>
|
|
7104
7116
|
<p class="lead"><strong id="connected-account"></strong> is now part of the shared agents pool. You can close this page.</p>
|
|
7105
|
-
<div class="aside"><strong>
|
|
7117
|
+
<div class="aside"><strong>Changed your mind?</strong> Disconnect removes this account's saved authorization and pool membership. It stays available for 24 hours while this page is open; it does not sign you out of Claude or cancel your subscription.<button class="button secondary" id="disconnect" type="button">Disconnect</button></div>
|
|
7106
7118
|
</section>
|
|
7107
7119
|
<section class="card" id="step-error" hidden>
|
|
7108
7120
|
<div class="avatar err">${icon("alert")}</div>
|
|
@@ -8173,6 +8185,40 @@ var init_background_tasks = __esm(() => {
|
|
|
8173
8185
|
backgroundTasks = new Set;
|
|
8174
8186
|
});
|
|
8175
8187
|
|
|
8188
|
+
// ../../packages/proxy/src/seat-usage.ts
|
|
8189
|
+
function liveUtilization(window2, now) {
|
|
8190
|
+
if (window2.utilization === null)
|
|
8191
|
+
return 0;
|
|
8192
|
+
return isOpenQuotaWindow(window2, now) ? window2.utilization : 0;
|
|
8193
|
+
}
|
|
8194
|
+
function highestUtilization(windows, now) {
|
|
8195
|
+
return Math.max(0, ...windows.map(([, window2]) => liveUtilization(window2, now)));
|
|
8196
|
+
}
|
|
8197
|
+
function seatUsage(provider, account2, model, now) {
|
|
8198
|
+
const buckets = provider.quotaBucketsFor(model);
|
|
8199
|
+
const windows = Object.entries(account2.quota_state?.windows ?? {}).filter(([bucket]) => buckets?.includes(bucket) ?? true);
|
|
8200
|
+
const weekly = windows.filter(([bucket]) => provider.isWeeklyBucket(bucket));
|
|
8201
|
+
const fiveHour = windows.filter(([bucket]) => provider.isFiveHourBucket(bucket));
|
|
8202
|
+
return {
|
|
8203
|
+
fiveHour: highestUtilization(fiveHour, now),
|
|
8204
|
+
weekly: highestUtilization(weekly, now)
|
|
8205
|
+
};
|
|
8206
|
+
}
|
|
8207
|
+
function soonestWeeklyReset(provider, account2, now) {
|
|
8208
|
+
const resets = Object.entries(account2.quota_state?.windows ?? {}).filter(([bucket, window2]) => provider.isWeeklyBucket(bucket) && window2.resetAt !== null && window2.resetAt > now).map(([, window2]) => window2.resetAt);
|
|
8209
|
+
return Math.min(...resets, Number.POSITIVE_INFINITY);
|
|
8210
|
+
}
|
|
8211
|
+
function compareSeatUsage(provider, model, now) {
|
|
8212
|
+
return (left, right) => {
|
|
8213
|
+
const a = seatUsage(provider, left, model, now);
|
|
8214
|
+
const b = seatUsage(provider, right, model, now);
|
|
8215
|
+
return a.fiveHour - b.fiveHour || a.weekly - b.weekly || soonestWeeklyReset(provider, left, now) - soonestWeeklyReset(provider, right, now);
|
|
8216
|
+
};
|
|
8217
|
+
}
|
|
8218
|
+
var init_seat_usage = __esm(() => {
|
|
8219
|
+
init_src();
|
|
8220
|
+
});
|
|
8221
|
+
|
|
8176
8222
|
// ../../packages/proxy/src/team-router.ts
|
|
8177
8223
|
import { createHash as createHash2 } from "crypto";
|
|
8178
8224
|
function isRecord5(value) {
|
|
@@ -8231,7 +8277,7 @@ class TeamRouter {
|
|
|
8231
8277
|
}
|
|
8232
8278
|
if (!config.distributionEnabled || !key)
|
|
8233
8279
|
return eligible;
|
|
8234
|
-
const selected = this.
|
|
8280
|
+
const selected = this.leastUsedPriorityAccount(eligible, compareSeatUsage(provider, request2.model, now), store?.countConversationPinsByAccount(now - PIN_TTL_MS));
|
|
8235
8281
|
this.touchPin(key, selected.id, now, store);
|
|
8236
8282
|
return [
|
|
8237
8283
|
selected,
|
|
@@ -8277,18 +8323,10 @@ class TeamRouter {
|
|
|
8277
8323
|
return persistedCounts.get(accountId) ?? 0;
|
|
8278
8324
|
return [...this.pins.values()].filter((pin) => pin.accountId === accountId).length;
|
|
8279
8325
|
}
|
|
8280
|
-
|
|
8326
|
+
leastUsedPriorityAccount(accounts, byUsage, persistedCounts) {
|
|
8281
8327
|
const priority = Math.min(...accounts.map((account2) => account2.priority ?? 0));
|
|
8282
8328
|
const tier = accounts.filter((account2) => (account2.priority ?? 0) === priority);
|
|
8283
|
-
return [...tier].sort((left, right) =>
|
|
8284
|
-
const activeDifference = this.activePins(left.id, persistedCounts) - this.activePins(right.id, persistedCounts);
|
|
8285
|
-
if (activeDifference !== 0)
|
|
8286
|
-
return activeDifference;
|
|
8287
|
-
const inFlightDifference = (this.inFlight.get(left.id) ?? 0) - (this.inFlight.get(right.id) ?? 0);
|
|
8288
|
-
if (inFlightDifference !== 0)
|
|
8289
|
-
return inFlightDifference;
|
|
8290
|
-
return left.name.localeCompare(right.name);
|
|
8291
|
-
})[0];
|
|
8329
|
+
return [...tier].sort((left, right) => byUsage(left, right) || this.activePins(left.id, persistedCounts) - this.activePins(right.id, persistedCounts) || (this.inFlight.get(left.id) ?? 0) - (this.inFlight.get(right.id) ?? 0) || left.name.localeCompare(right.name))[0];
|
|
8292
8330
|
}
|
|
8293
8331
|
removeExpiredPins(now, store) {
|
|
8294
8332
|
for (const [key, pin] of this.pins) {
|
|
@@ -8304,6 +8342,7 @@ class TeamRouter {
|
|
|
8304
8342
|
}
|
|
8305
8343
|
var MAX_OPENING_BYTES, PIN_TTL_MS;
|
|
8306
8344
|
var init_team_router = __esm(() => {
|
|
8345
|
+
init_seat_usage();
|
|
8307
8346
|
MAX_OPENING_BYTES = 64 * 1024;
|
|
8308
8347
|
PIN_TTL_MS = 30 * 24 * 60 * 60 * 1000;
|
|
8309
8348
|
});
|
|
@@ -8311,7 +8350,7 @@ var init_team_router = __esm(() => {
|
|
|
8311
8350
|
// ../../packages/proxy/src/handlers/account-selector.ts
|
|
8312
8351
|
function isQuotaBlocking(provider, account2, bucket, window2, fleetThreshold, now, model, maxUsage) {
|
|
8313
8352
|
const threshold = Math.min(quotaThresholdFor(account2, bucket, fleetThreshold), maxUsage ?? Number.POSITIVE_INFINITY);
|
|
8314
|
-
return (provider.quotaBucketsFor(model)?.includes(bucket) ?? true) && isCurrentQuotaWindow(window2, now) && (window2.status === "rejected" || window2.utilization !== null && window2.utilization >= threshold);
|
|
8353
|
+
return (provider.quotaBucketsFor(model)?.includes(bucket) ?? true) && (maxUsage === undefined ? isCurrentQuotaWindow(window2, now) : isOpenQuotaWindow(window2, now)) && (window2.status === "rejected" || window2.utilization !== null && window2.utilization >= threshold);
|
|
8315
8354
|
}
|
|
8316
8355
|
function pooledMaxUsage(account2, ctx) {
|
|
8317
8356
|
const teamRouting = ctx.runtime.teamRouting;
|
|
@@ -8351,13 +8390,6 @@ function getSoonestQuotaReset(meta, ctx, now = Date.now()) {
|
|
|
8351
8390
|
const resets = ctx.dbOps.getAvailableAccountsByProvider(ctx.providerName).flatMap((account2) => Object.entries(account2.quota_state?.windows ?? {}).map(([bucket, window2]) => ({ account: account2, bucket, window: window2 }))).filter(({ account: account2, bucket, window: window2 }) => window2.resetAt !== null && window2.resetAt > now && isQuotaBlocking(ctx.provider, account2, bucket, window2, ctx.runtime.quotaThreshold, now, meta.model, pooledMaxUsage(account2, ctx))).map(({ window: window2 }) => window2.resetAt);
|
|
8352
8391
|
return resets.length > 0 ? Math.min(...resets) : null;
|
|
8353
8392
|
}
|
|
8354
|
-
function soonestWeeklyReset(provider, account2, now) {
|
|
8355
|
-
const windows = account2.quota_state?.windows ?? {};
|
|
8356
|
-
const resets = Object.entries(windows).filter(([name, window2]) => {
|
|
8357
|
-
return provider.isWeeklyBucket(name) && window2.resetAt !== null && window2.resetAt > now;
|
|
8358
|
-
}).map(([, window2]) => window2.resetAt);
|
|
8359
|
-
return Math.min(...resets, Number.POSITIVE_INFINITY);
|
|
8360
|
-
}
|
|
8361
8393
|
function selectRevalidationProbe(accounts, ctx, now) {
|
|
8362
8394
|
const probes = ctx.quotaProbeAt;
|
|
8363
8395
|
const lastProbeAt = probes?.get(ctx.providerName);
|
|
@@ -8390,6 +8422,7 @@ function selectAccountsForRequest(meta, ctx, teamRequest, options) {
|
|
|
8390
8422
|
var QUOTA_PROBE_INTERVAL_MS = 60000;
|
|
8391
8423
|
var init_account_selector = __esm(() => {
|
|
8392
8424
|
init_src();
|
|
8425
|
+
init_seat_usage();
|
|
8393
8426
|
init_team_router();
|
|
8394
8427
|
});
|
|
8395
8428
|
|
|
@@ -9588,7 +9621,7 @@ async function classifyUpstreamResponse(input, upstream) {
|
|
|
9588
9621
|
retryAfterMs: perMinuteRetryAfterMs
|
|
9589
9622
|
};
|
|
9590
9623
|
}
|
|
9591
|
-
if (isRateLimited) {
|
|
9624
|
+
if (isRateLimited && !response.ok) {
|
|
9592
9625
|
return response.status === 429 ? {
|
|
9593
9626
|
discard: discardUpstreamResponse(state),
|
|
9594
9627
|
forward,
|
|
@@ -704,6 +704,9 @@ function quotaThresholdFor(account, bucket, fleetThreshold) {
|
|
|
704
704
|
function isCurrentQuotaWindow(window, now) {
|
|
705
705
|
return (window.resetAt === null || window.resetAt > now) && now - window.seenAt <= QUOTA_STALE_MS;
|
|
706
706
|
}
|
|
707
|
+
function isOpenQuotaWindow(window, now) {
|
|
708
|
+
return window.resetAt === null ? isCurrentQuotaWindow(window, now) : window.resetAt > now;
|
|
709
|
+
}
|
|
707
710
|
var QUOTA_STALE_MS;
|
|
708
711
|
var init_quota = __esm(() => {
|
|
709
712
|
QUOTA_STALE_MS = 30 * 60000;
|
package/dist/server.js
CHANGED
|
@@ -704,6 +704,9 @@ function quotaThresholdFor(account, bucket, fleetThreshold) {
|
|
|
704
704
|
function isCurrentQuotaWindow(window, now) {
|
|
705
705
|
return (window.resetAt === null || window.resetAt > now) && now - window.seenAt <= QUOTA_STALE_MS;
|
|
706
706
|
}
|
|
707
|
+
function isOpenQuotaWindow(window, now) {
|
|
708
|
+
return window.resetAt === null ? isCurrentQuotaWindow(window, now) : window.resetAt > now;
|
|
709
|
+
}
|
|
707
710
|
var QUOTA_STALE_MS;
|
|
708
711
|
var init_quota = __esm(() => {
|
|
709
712
|
QUOTA_STALE_MS = 30 * 60000;
|
|
@@ -1386,6 +1389,9 @@ class BaseProvider {
|
|
|
1386
1389
|
isWeeklyBucket(_bucket) {
|
|
1387
1390
|
return false;
|
|
1388
1391
|
}
|
|
1392
|
+
isFiveHourBucket(_bucket) {
|
|
1393
|
+
return false;
|
|
1394
|
+
}
|
|
1389
1395
|
getClientSessionId(headers2) {
|
|
1390
1396
|
return headers2.get("x-claude-code-session-id");
|
|
1391
1397
|
}
|
|
@@ -1623,6 +1629,9 @@ var init_provider = __esm(() => {
|
|
|
1623
1629
|
isWeeklyBucket(bucket) {
|
|
1624
1630
|
return bucket.startsWith("unified7d");
|
|
1625
1631
|
}
|
|
1632
|
+
isFiveHourBucket(bucket) {
|
|
1633
|
+
return bucket === "unified5h";
|
|
1634
|
+
}
|
|
1626
1635
|
prepareHeaders(headers2, account2) {
|
|
1627
1636
|
const newHeaders = new Headers(headers2);
|
|
1628
1637
|
deleteClientCredentialHeaders(newHeaders);
|
|
@@ -2560,6 +2569,9 @@ var init_provider4 = __esm(() => {
|
|
|
2560
2569
|
isWeeklyBucket(bucket) {
|
|
2561
2570
|
return bucket === "unified7d";
|
|
2562
2571
|
}
|
|
2572
|
+
isFiveHourBucket(bucket) {
|
|
2573
|
+
return bucket === "unified5h";
|
|
2574
|
+
}
|
|
2563
2575
|
supportsWebSocket(upstreamPath) {
|
|
2564
2576
|
return upstreamPath === "/responses";
|
|
2565
2577
|
}
|
|
@@ -7101,7 +7113,7 @@ function enrollmentPage() {
|
|
|
7101
7113
|
<div class="avatar ok">${icon("check")}</div>
|
|
7102
7114
|
<h1 tabindex="-1">Subscription connected</h1>
|
|
7103
7115
|
<p class="lead"><strong id="connected-account"></strong> is now part of the shared agents pool. You can close this page.</p>
|
|
7104
|
-
<div class="aside"><strong>
|
|
7116
|
+
<div class="aside"><strong>Changed your mind?</strong> Disconnect removes this account's saved authorization and pool membership. It stays available for 24 hours while this page is open; it does not sign you out of Claude or cancel your subscription.<button class="button secondary" id="disconnect" type="button">Disconnect</button></div>
|
|
7105
7117
|
</section>
|
|
7106
7118
|
<section class="card" id="step-error" hidden>
|
|
7107
7119
|
<div class="avatar err">${icon("alert")}</div>
|
|
@@ -8172,6 +8184,40 @@ var init_background_tasks = __esm(() => {
|
|
|
8172
8184
|
backgroundTasks = new Set;
|
|
8173
8185
|
});
|
|
8174
8186
|
|
|
8187
|
+
// ../../packages/proxy/src/seat-usage.ts
|
|
8188
|
+
function liveUtilization(window2, now) {
|
|
8189
|
+
if (window2.utilization === null)
|
|
8190
|
+
return 0;
|
|
8191
|
+
return isOpenQuotaWindow(window2, now) ? window2.utilization : 0;
|
|
8192
|
+
}
|
|
8193
|
+
function highestUtilization(windows, now) {
|
|
8194
|
+
return Math.max(0, ...windows.map(([, window2]) => liveUtilization(window2, now)));
|
|
8195
|
+
}
|
|
8196
|
+
function seatUsage(provider, account2, model, now) {
|
|
8197
|
+
const buckets = provider.quotaBucketsFor(model);
|
|
8198
|
+
const windows = Object.entries(account2.quota_state?.windows ?? {}).filter(([bucket]) => buckets?.includes(bucket) ?? true);
|
|
8199
|
+
const weekly = windows.filter(([bucket]) => provider.isWeeklyBucket(bucket));
|
|
8200
|
+
const fiveHour = windows.filter(([bucket]) => provider.isFiveHourBucket(bucket));
|
|
8201
|
+
return {
|
|
8202
|
+
fiveHour: highestUtilization(fiveHour, now),
|
|
8203
|
+
weekly: highestUtilization(weekly, now)
|
|
8204
|
+
};
|
|
8205
|
+
}
|
|
8206
|
+
function soonestWeeklyReset(provider, account2, now) {
|
|
8207
|
+
const resets = Object.entries(account2.quota_state?.windows ?? {}).filter(([bucket, window2]) => provider.isWeeklyBucket(bucket) && window2.resetAt !== null && window2.resetAt > now).map(([, window2]) => window2.resetAt);
|
|
8208
|
+
return Math.min(...resets, Number.POSITIVE_INFINITY);
|
|
8209
|
+
}
|
|
8210
|
+
function compareSeatUsage(provider, model, now) {
|
|
8211
|
+
return (left, right) => {
|
|
8212
|
+
const a = seatUsage(provider, left, model, now);
|
|
8213
|
+
const b = seatUsage(provider, right, model, now);
|
|
8214
|
+
return a.fiveHour - b.fiveHour || a.weekly - b.weekly || soonestWeeklyReset(provider, left, now) - soonestWeeklyReset(provider, right, now);
|
|
8215
|
+
};
|
|
8216
|
+
}
|
|
8217
|
+
var init_seat_usage = __esm(() => {
|
|
8218
|
+
init_src();
|
|
8219
|
+
});
|
|
8220
|
+
|
|
8175
8221
|
// ../../packages/proxy/src/team-router.ts
|
|
8176
8222
|
import { createHash as createHash2 } from "crypto";
|
|
8177
8223
|
function isRecord5(value) {
|
|
@@ -8230,7 +8276,7 @@ class TeamRouter {
|
|
|
8230
8276
|
}
|
|
8231
8277
|
if (!config.distributionEnabled || !key)
|
|
8232
8278
|
return eligible;
|
|
8233
|
-
const selected = this.
|
|
8279
|
+
const selected = this.leastUsedPriorityAccount(eligible, compareSeatUsage(provider, request2.model, now), store?.countConversationPinsByAccount(now - PIN_TTL_MS));
|
|
8234
8280
|
this.touchPin(key, selected.id, now, store);
|
|
8235
8281
|
return [
|
|
8236
8282
|
selected,
|
|
@@ -8276,18 +8322,10 @@ class TeamRouter {
|
|
|
8276
8322
|
return persistedCounts.get(accountId) ?? 0;
|
|
8277
8323
|
return [...this.pins.values()].filter((pin) => pin.accountId === accountId).length;
|
|
8278
8324
|
}
|
|
8279
|
-
|
|
8325
|
+
leastUsedPriorityAccount(accounts, byUsage, persistedCounts) {
|
|
8280
8326
|
const priority = Math.min(...accounts.map((account2) => account2.priority ?? 0));
|
|
8281
8327
|
const tier = accounts.filter((account2) => (account2.priority ?? 0) === priority);
|
|
8282
|
-
return [...tier].sort((left, right) =>
|
|
8283
|
-
const activeDifference = this.activePins(left.id, persistedCounts) - this.activePins(right.id, persistedCounts);
|
|
8284
|
-
if (activeDifference !== 0)
|
|
8285
|
-
return activeDifference;
|
|
8286
|
-
const inFlightDifference = (this.inFlight.get(left.id) ?? 0) - (this.inFlight.get(right.id) ?? 0);
|
|
8287
|
-
if (inFlightDifference !== 0)
|
|
8288
|
-
return inFlightDifference;
|
|
8289
|
-
return left.name.localeCompare(right.name);
|
|
8290
|
-
})[0];
|
|
8328
|
+
return [...tier].sort((left, right) => byUsage(left, right) || this.activePins(left.id, persistedCounts) - this.activePins(right.id, persistedCounts) || (this.inFlight.get(left.id) ?? 0) - (this.inFlight.get(right.id) ?? 0) || left.name.localeCompare(right.name))[0];
|
|
8291
8329
|
}
|
|
8292
8330
|
removeExpiredPins(now, store) {
|
|
8293
8331
|
for (const [key, pin] of this.pins) {
|
|
@@ -8303,6 +8341,7 @@ class TeamRouter {
|
|
|
8303
8341
|
}
|
|
8304
8342
|
var MAX_OPENING_BYTES, PIN_TTL_MS;
|
|
8305
8343
|
var init_team_router = __esm(() => {
|
|
8344
|
+
init_seat_usage();
|
|
8306
8345
|
MAX_OPENING_BYTES = 64 * 1024;
|
|
8307
8346
|
PIN_TTL_MS = 30 * 24 * 60 * 60 * 1000;
|
|
8308
8347
|
});
|
|
@@ -8310,7 +8349,7 @@ var init_team_router = __esm(() => {
|
|
|
8310
8349
|
// ../../packages/proxy/src/handlers/account-selector.ts
|
|
8311
8350
|
function isQuotaBlocking(provider, account2, bucket, window2, fleetThreshold, now, model, maxUsage) {
|
|
8312
8351
|
const threshold = Math.min(quotaThresholdFor(account2, bucket, fleetThreshold), maxUsage ?? Number.POSITIVE_INFINITY);
|
|
8313
|
-
return (provider.quotaBucketsFor(model)?.includes(bucket) ?? true) && isCurrentQuotaWindow(window2, now) && (window2.status === "rejected" || window2.utilization !== null && window2.utilization >= threshold);
|
|
8352
|
+
return (provider.quotaBucketsFor(model)?.includes(bucket) ?? true) && (maxUsage === undefined ? isCurrentQuotaWindow(window2, now) : isOpenQuotaWindow(window2, now)) && (window2.status === "rejected" || window2.utilization !== null && window2.utilization >= threshold);
|
|
8314
8353
|
}
|
|
8315
8354
|
function pooledMaxUsage(account2, ctx) {
|
|
8316
8355
|
const teamRouting = ctx.runtime.teamRouting;
|
|
@@ -8350,13 +8389,6 @@ function getSoonestQuotaReset(meta, ctx, now = Date.now()) {
|
|
|
8350
8389
|
const resets = ctx.dbOps.getAvailableAccountsByProvider(ctx.providerName).flatMap((account2) => Object.entries(account2.quota_state?.windows ?? {}).map(([bucket, window2]) => ({ account: account2, bucket, window: window2 }))).filter(({ account: account2, bucket, window: window2 }) => window2.resetAt !== null && window2.resetAt > now && isQuotaBlocking(ctx.provider, account2, bucket, window2, ctx.runtime.quotaThreshold, now, meta.model, pooledMaxUsage(account2, ctx))).map(({ window: window2 }) => window2.resetAt);
|
|
8351
8390
|
return resets.length > 0 ? Math.min(...resets) : null;
|
|
8352
8391
|
}
|
|
8353
|
-
function soonestWeeklyReset(provider, account2, now) {
|
|
8354
|
-
const windows = account2.quota_state?.windows ?? {};
|
|
8355
|
-
const resets = Object.entries(windows).filter(([name, window2]) => {
|
|
8356
|
-
return provider.isWeeklyBucket(name) && window2.resetAt !== null && window2.resetAt > now;
|
|
8357
|
-
}).map(([, window2]) => window2.resetAt);
|
|
8358
|
-
return Math.min(...resets, Number.POSITIVE_INFINITY);
|
|
8359
|
-
}
|
|
8360
8392
|
function selectRevalidationProbe(accounts, ctx, now) {
|
|
8361
8393
|
const probes = ctx.quotaProbeAt;
|
|
8362
8394
|
const lastProbeAt = probes?.get(ctx.providerName);
|
|
@@ -8389,6 +8421,7 @@ function selectAccountsForRequest(meta, ctx, teamRequest, options) {
|
|
|
8389
8421
|
var QUOTA_PROBE_INTERVAL_MS = 60000;
|
|
8390
8422
|
var init_account_selector = __esm(() => {
|
|
8391
8423
|
init_src();
|
|
8424
|
+
init_seat_usage();
|
|
8392
8425
|
init_team_router();
|
|
8393
8426
|
});
|
|
8394
8427
|
|
|
@@ -9587,7 +9620,7 @@ async function classifyUpstreamResponse(input, upstream) {
|
|
|
9587
9620
|
retryAfterMs: perMinuteRetryAfterMs
|
|
9588
9621
|
};
|
|
9589
9622
|
}
|
|
9590
|
-
if (isRateLimited) {
|
|
9623
|
+
if (isRateLimited && !response.ok) {
|
|
9591
9624
|
return response.status === 429 ? {
|
|
9592
9625
|
discard: discardUpstreamResponse(state),
|
|
9593
9626
|
forward,
|
package/package.json
CHANGED