@certalis/agent-smith 0.1.2 → 0.1.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/bin.js +59 -19
- package/dist/server.js +59 -19
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -4453,6 +4453,9 @@ class BaseProvider {
|
|
|
4453
4453
|
isWeeklyBucket(_bucket) {
|
|
4454
4454
|
return false;
|
|
4455
4455
|
}
|
|
4456
|
+
isFiveHourBucket(_bucket) {
|
|
4457
|
+
return false;
|
|
4458
|
+
}
|
|
4456
4459
|
getClientSessionId(headers2) {
|
|
4457
4460
|
return headers2.get("x-claude-code-session-id");
|
|
4458
4461
|
}
|
|
@@ -4690,6 +4693,9 @@ var init_provider = __esm(() => {
|
|
|
4690
4693
|
isWeeklyBucket(bucket) {
|
|
4691
4694
|
return bucket.startsWith("unified7d");
|
|
4692
4695
|
}
|
|
4696
|
+
isFiveHourBucket(bucket) {
|
|
4697
|
+
return bucket === "unified5h";
|
|
4698
|
+
}
|
|
4693
4699
|
prepareHeaders(headers2, account2) {
|
|
4694
4700
|
const newHeaders = new Headers(headers2);
|
|
4695
4701
|
deleteClientCredentialHeaders(newHeaders);
|
|
@@ -5627,6 +5633,9 @@ var init_provider4 = __esm(() => {
|
|
|
5627
5633
|
isWeeklyBucket(bucket) {
|
|
5628
5634
|
return bucket === "unified7d";
|
|
5629
5635
|
}
|
|
5636
|
+
isFiveHourBucket(bucket) {
|
|
5637
|
+
return bucket === "unified5h";
|
|
5638
|
+
}
|
|
5630
5639
|
supportsWebSocket(upstreamPath) {
|
|
5631
5640
|
return upstreamPath === "/responses";
|
|
5632
5641
|
}
|
|
@@ -7102,7 +7111,7 @@ function enrollmentPage() {
|
|
|
7102
7111
|
<div class="avatar ok">${icon("check")}</div>
|
|
7103
7112
|
<h1 tabindex="-1">Subscription connected</h1>
|
|
7104
7113
|
<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>
|
|
7114
|
+
<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
7115
|
</section>
|
|
7107
7116
|
<section class="card" id="step-error" hidden>
|
|
7108
7117
|
<div class="avatar err">${icon("alert")}</div>
|
|
@@ -8173,6 +8182,50 @@ var init_background_tasks = __esm(() => {
|
|
|
8173
8182
|
backgroundTasks = new Set;
|
|
8174
8183
|
});
|
|
8175
8184
|
|
|
8185
|
+
// ../../packages/proxy/src/seat-usage.ts
|
|
8186
|
+
function liveUtilization(window2, now) {
|
|
8187
|
+
if (window2.utilization === null)
|
|
8188
|
+
return 0;
|
|
8189
|
+
const windowOpen = window2.resetAt === null ? isCurrentQuotaWindow(window2, now) : window2.resetAt > now;
|
|
8190
|
+
return windowOpen ? window2.utilization : 0;
|
|
8191
|
+
}
|
|
8192
|
+
function isAheadOfWeeklyPace(window2, now) {
|
|
8193
|
+
if (window2.resetAt === null || window2.resetAt <= now)
|
|
8194
|
+
return false;
|
|
8195
|
+
const elapsedShareOfWeek = 1 - (window2.resetAt - now) / WEEK_MS;
|
|
8196
|
+
return liveUtilization(window2, now) > elapsedShareOfWeek;
|
|
8197
|
+
}
|
|
8198
|
+
function highestUtilization(windows, now) {
|
|
8199
|
+
return Math.max(0, ...windows.map(([, window2]) => liveUtilization(window2, now)));
|
|
8200
|
+
}
|
|
8201
|
+
function seatUsage(provider, account2, model, now) {
|
|
8202
|
+
const buckets = provider.quotaBucketsFor(model);
|
|
8203
|
+
const windows = Object.entries(account2.quota_state?.windows ?? {}).filter(([bucket]) => buckets?.includes(bucket) ?? true);
|
|
8204
|
+
const weekly = windows.filter(([bucket]) => provider.isWeeklyBucket(bucket));
|
|
8205
|
+
const fiveHour = windows.filter(([bucket]) => provider.isFiveHourBucket(bucket));
|
|
8206
|
+
return {
|
|
8207
|
+
aheadOfWeeklyPace: weekly.some(([, window2]) => isAheadOfWeeklyPace(window2, now)),
|
|
8208
|
+
fiveHour: highestUtilization(fiveHour, now),
|
|
8209
|
+
weekly: highestUtilization(weekly, now)
|
|
8210
|
+
};
|
|
8211
|
+
}
|
|
8212
|
+
function soonestWeeklyReset(provider, account2, now) {
|
|
8213
|
+
const resets = Object.entries(account2.quota_state?.windows ?? {}).filter(([bucket, window2]) => provider.isWeeklyBucket(bucket) && window2.resetAt !== null && window2.resetAt > now).map(([, window2]) => window2.resetAt);
|
|
8214
|
+
return Math.min(...resets, Number.POSITIVE_INFINITY);
|
|
8215
|
+
}
|
|
8216
|
+
function compareSeatUsage(provider, model, now) {
|
|
8217
|
+
return (left, right) => {
|
|
8218
|
+
const a = seatUsage(provider, left, model, now);
|
|
8219
|
+
const b = seatUsage(provider, right, model, now);
|
|
8220
|
+
return Number(a.aheadOfWeeklyPace) - Number(b.aheadOfWeeklyPace) || a.fiveHour - b.fiveHour || a.weekly - b.weekly || soonestWeeklyReset(provider, left, now) - soonestWeeklyReset(provider, right, now);
|
|
8221
|
+
};
|
|
8222
|
+
}
|
|
8223
|
+
var WEEK_MS;
|
|
8224
|
+
var init_seat_usage = __esm(() => {
|
|
8225
|
+
init_src();
|
|
8226
|
+
WEEK_MS = 7 * 24 * 60 * 60 * 1000;
|
|
8227
|
+
});
|
|
8228
|
+
|
|
8176
8229
|
// ../../packages/proxy/src/team-router.ts
|
|
8177
8230
|
import { createHash as createHash2 } from "crypto";
|
|
8178
8231
|
function isRecord5(value) {
|
|
@@ -8231,7 +8284,7 @@ class TeamRouter {
|
|
|
8231
8284
|
}
|
|
8232
8285
|
if (!config.distributionEnabled || !key)
|
|
8233
8286
|
return eligible;
|
|
8234
|
-
const selected = this.
|
|
8287
|
+
const selected = this.leastUsedPriorityAccount(eligible, compareSeatUsage(provider, request2.model, now), store?.countConversationPinsByAccount(now - PIN_TTL_MS));
|
|
8235
8288
|
this.touchPin(key, selected.id, now, store);
|
|
8236
8289
|
return [
|
|
8237
8290
|
selected,
|
|
@@ -8277,18 +8330,10 @@ class TeamRouter {
|
|
|
8277
8330
|
return persistedCounts.get(accountId) ?? 0;
|
|
8278
8331
|
return [...this.pins.values()].filter((pin) => pin.accountId === accountId).length;
|
|
8279
8332
|
}
|
|
8280
|
-
|
|
8333
|
+
leastUsedPriorityAccount(accounts, byUsage, persistedCounts) {
|
|
8281
8334
|
const priority = Math.min(...accounts.map((account2) => account2.priority ?? 0));
|
|
8282
8335
|
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];
|
|
8336
|
+
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
8337
|
}
|
|
8293
8338
|
removeExpiredPins(now, store) {
|
|
8294
8339
|
for (const [key, pin] of this.pins) {
|
|
@@ -8304,6 +8349,7 @@ class TeamRouter {
|
|
|
8304
8349
|
}
|
|
8305
8350
|
var MAX_OPENING_BYTES, PIN_TTL_MS;
|
|
8306
8351
|
var init_team_router = __esm(() => {
|
|
8352
|
+
init_seat_usage();
|
|
8307
8353
|
MAX_OPENING_BYTES = 64 * 1024;
|
|
8308
8354
|
PIN_TTL_MS = 30 * 24 * 60 * 60 * 1000;
|
|
8309
8355
|
});
|
|
@@ -8351,13 +8397,6 @@ function getSoonestQuotaReset(meta, ctx, now = Date.now()) {
|
|
|
8351
8397
|
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
8398
|
return resets.length > 0 ? Math.min(...resets) : null;
|
|
8353
8399
|
}
|
|
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
8400
|
function selectRevalidationProbe(accounts, ctx, now) {
|
|
8362
8401
|
const probes = ctx.quotaProbeAt;
|
|
8363
8402
|
const lastProbeAt = probes?.get(ctx.providerName);
|
|
@@ -8390,6 +8429,7 @@ function selectAccountsForRequest(meta, ctx, teamRequest, options) {
|
|
|
8390
8429
|
var QUOTA_PROBE_INTERVAL_MS = 60000;
|
|
8391
8430
|
var init_account_selector = __esm(() => {
|
|
8392
8431
|
init_src();
|
|
8432
|
+
init_seat_usage();
|
|
8393
8433
|
init_team_router();
|
|
8394
8434
|
});
|
|
8395
8435
|
|
package/dist/server.js
CHANGED
|
@@ -1386,6 +1386,9 @@ class BaseProvider {
|
|
|
1386
1386
|
isWeeklyBucket(_bucket) {
|
|
1387
1387
|
return false;
|
|
1388
1388
|
}
|
|
1389
|
+
isFiveHourBucket(_bucket) {
|
|
1390
|
+
return false;
|
|
1391
|
+
}
|
|
1389
1392
|
getClientSessionId(headers2) {
|
|
1390
1393
|
return headers2.get("x-claude-code-session-id");
|
|
1391
1394
|
}
|
|
@@ -1623,6 +1626,9 @@ var init_provider = __esm(() => {
|
|
|
1623
1626
|
isWeeklyBucket(bucket) {
|
|
1624
1627
|
return bucket.startsWith("unified7d");
|
|
1625
1628
|
}
|
|
1629
|
+
isFiveHourBucket(bucket) {
|
|
1630
|
+
return bucket === "unified5h";
|
|
1631
|
+
}
|
|
1626
1632
|
prepareHeaders(headers2, account2) {
|
|
1627
1633
|
const newHeaders = new Headers(headers2);
|
|
1628
1634
|
deleteClientCredentialHeaders(newHeaders);
|
|
@@ -2560,6 +2566,9 @@ var init_provider4 = __esm(() => {
|
|
|
2560
2566
|
isWeeklyBucket(bucket) {
|
|
2561
2567
|
return bucket === "unified7d";
|
|
2562
2568
|
}
|
|
2569
|
+
isFiveHourBucket(bucket) {
|
|
2570
|
+
return bucket === "unified5h";
|
|
2571
|
+
}
|
|
2563
2572
|
supportsWebSocket(upstreamPath) {
|
|
2564
2573
|
return upstreamPath === "/responses";
|
|
2565
2574
|
}
|
|
@@ -7101,7 +7110,7 @@ function enrollmentPage() {
|
|
|
7101
7110
|
<div class="avatar ok">${icon("check")}</div>
|
|
7102
7111
|
<h1 tabindex="-1">Subscription connected</h1>
|
|
7103
7112
|
<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>
|
|
7113
|
+
<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
7114
|
</section>
|
|
7106
7115
|
<section class="card" id="step-error" hidden>
|
|
7107
7116
|
<div class="avatar err">${icon("alert")}</div>
|
|
@@ -8172,6 +8181,50 @@ var init_background_tasks = __esm(() => {
|
|
|
8172
8181
|
backgroundTasks = new Set;
|
|
8173
8182
|
});
|
|
8174
8183
|
|
|
8184
|
+
// ../../packages/proxy/src/seat-usage.ts
|
|
8185
|
+
function liveUtilization(window2, now) {
|
|
8186
|
+
if (window2.utilization === null)
|
|
8187
|
+
return 0;
|
|
8188
|
+
const windowOpen = window2.resetAt === null ? isCurrentQuotaWindow(window2, now) : window2.resetAt > now;
|
|
8189
|
+
return windowOpen ? window2.utilization : 0;
|
|
8190
|
+
}
|
|
8191
|
+
function isAheadOfWeeklyPace(window2, now) {
|
|
8192
|
+
if (window2.resetAt === null || window2.resetAt <= now)
|
|
8193
|
+
return false;
|
|
8194
|
+
const elapsedShareOfWeek = 1 - (window2.resetAt - now) / WEEK_MS;
|
|
8195
|
+
return liveUtilization(window2, now) > elapsedShareOfWeek;
|
|
8196
|
+
}
|
|
8197
|
+
function highestUtilization(windows, now) {
|
|
8198
|
+
return Math.max(0, ...windows.map(([, window2]) => liveUtilization(window2, now)));
|
|
8199
|
+
}
|
|
8200
|
+
function seatUsage(provider, account2, model, now) {
|
|
8201
|
+
const buckets = provider.quotaBucketsFor(model);
|
|
8202
|
+
const windows = Object.entries(account2.quota_state?.windows ?? {}).filter(([bucket]) => buckets?.includes(bucket) ?? true);
|
|
8203
|
+
const weekly = windows.filter(([bucket]) => provider.isWeeklyBucket(bucket));
|
|
8204
|
+
const fiveHour = windows.filter(([bucket]) => provider.isFiveHourBucket(bucket));
|
|
8205
|
+
return {
|
|
8206
|
+
aheadOfWeeklyPace: weekly.some(([, window2]) => isAheadOfWeeklyPace(window2, now)),
|
|
8207
|
+
fiveHour: highestUtilization(fiveHour, now),
|
|
8208
|
+
weekly: highestUtilization(weekly, now)
|
|
8209
|
+
};
|
|
8210
|
+
}
|
|
8211
|
+
function soonestWeeklyReset(provider, account2, now) {
|
|
8212
|
+
const resets = Object.entries(account2.quota_state?.windows ?? {}).filter(([bucket, window2]) => provider.isWeeklyBucket(bucket) && window2.resetAt !== null && window2.resetAt > now).map(([, window2]) => window2.resetAt);
|
|
8213
|
+
return Math.min(...resets, Number.POSITIVE_INFINITY);
|
|
8214
|
+
}
|
|
8215
|
+
function compareSeatUsage(provider, model, now) {
|
|
8216
|
+
return (left, right) => {
|
|
8217
|
+
const a = seatUsage(provider, left, model, now);
|
|
8218
|
+
const b = seatUsage(provider, right, model, now);
|
|
8219
|
+
return Number(a.aheadOfWeeklyPace) - Number(b.aheadOfWeeklyPace) || a.fiveHour - b.fiveHour || a.weekly - b.weekly || soonestWeeklyReset(provider, left, now) - soonestWeeklyReset(provider, right, now);
|
|
8220
|
+
};
|
|
8221
|
+
}
|
|
8222
|
+
var WEEK_MS;
|
|
8223
|
+
var init_seat_usage = __esm(() => {
|
|
8224
|
+
init_src();
|
|
8225
|
+
WEEK_MS = 7 * 24 * 60 * 60 * 1000;
|
|
8226
|
+
});
|
|
8227
|
+
|
|
8175
8228
|
// ../../packages/proxy/src/team-router.ts
|
|
8176
8229
|
import { createHash as createHash2 } from "crypto";
|
|
8177
8230
|
function isRecord5(value) {
|
|
@@ -8230,7 +8283,7 @@ class TeamRouter {
|
|
|
8230
8283
|
}
|
|
8231
8284
|
if (!config.distributionEnabled || !key)
|
|
8232
8285
|
return eligible;
|
|
8233
|
-
const selected = this.
|
|
8286
|
+
const selected = this.leastUsedPriorityAccount(eligible, compareSeatUsage(provider, request2.model, now), store?.countConversationPinsByAccount(now - PIN_TTL_MS));
|
|
8234
8287
|
this.touchPin(key, selected.id, now, store);
|
|
8235
8288
|
return [
|
|
8236
8289
|
selected,
|
|
@@ -8276,18 +8329,10 @@ class TeamRouter {
|
|
|
8276
8329
|
return persistedCounts.get(accountId) ?? 0;
|
|
8277
8330
|
return [...this.pins.values()].filter((pin) => pin.accountId === accountId).length;
|
|
8278
8331
|
}
|
|
8279
|
-
|
|
8332
|
+
leastUsedPriorityAccount(accounts, byUsage, persistedCounts) {
|
|
8280
8333
|
const priority = Math.min(...accounts.map((account2) => account2.priority ?? 0));
|
|
8281
8334
|
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];
|
|
8335
|
+
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
8336
|
}
|
|
8292
8337
|
removeExpiredPins(now, store) {
|
|
8293
8338
|
for (const [key, pin] of this.pins) {
|
|
@@ -8303,6 +8348,7 @@ class TeamRouter {
|
|
|
8303
8348
|
}
|
|
8304
8349
|
var MAX_OPENING_BYTES, PIN_TTL_MS;
|
|
8305
8350
|
var init_team_router = __esm(() => {
|
|
8351
|
+
init_seat_usage();
|
|
8306
8352
|
MAX_OPENING_BYTES = 64 * 1024;
|
|
8307
8353
|
PIN_TTL_MS = 30 * 24 * 60 * 60 * 1000;
|
|
8308
8354
|
});
|
|
@@ -8350,13 +8396,6 @@ function getSoonestQuotaReset(meta, ctx, now = Date.now()) {
|
|
|
8350
8396
|
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
8397
|
return resets.length > 0 ? Math.min(...resets) : null;
|
|
8352
8398
|
}
|
|
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
8399
|
function selectRevalidationProbe(accounts, ctx, now) {
|
|
8361
8400
|
const probes = ctx.quotaProbeAt;
|
|
8362
8401
|
const lastProbeAt = probes?.get(ctx.providerName);
|
|
@@ -8389,6 +8428,7 @@ function selectAccountsForRequest(meta, ctx, teamRequest, options) {
|
|
|
8389
8428
|
var QUOTA_PROBE_INTERVAL_MS = 60000;
|
|
8390
8429
|
var init_account_selector = __esm(() => {
|
|
8391
8430
|
init_src();
|
|
8431
|
+
init_seat_usage();
|
|
8392
8432
|
init_team_router();
|
|
8393
8433
|
});
|
|
8394
8434
|
|
package/package.json
CHANGED