agent-shim 9.1.0 → 9.2.1
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/cli.cjs +391 -327
- package/dist/index.cjs +107 -43
- package/dist/index.mjs +107 -43
- package/dist/types/index.d.ts +19 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -770,6 +770,18 @@ function matchBranch(pattern, branch, detached = false) {
|
|
|
770
770
|
}
|
|
771
771
|
return (0, import_picomatch2.default)(pattern, { dot: true, nocase: false })(branch);
|
|
772
772
|
}
|
|
773
|
+
function windowValues(prefix, windows) {
|
|
774
|
+
const values = {};
|
|
775
|
+
for (const name of ["fiveHour", "sevenDay", "extraUsage"]) {
|
|
776
|
+
const facts = windows?.[name];
|
|
777
|
+
if (facts !== void 0) {
|
|
778
|
+
values[`${prefix}.${name}.remaining`] = facts.remaining;
|
|
779
|
+
values[`${prefix}.${name}.utilization`] = facts.utilization;
|
|
780
|
+
values[`${prefix}.${name}.hoursUntilReset`] = facts.hoursUntilReset;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
return values;
|
|
784
|
+
}
|
|
773
785
|
function resolversOf(context) {
|
|
774
786
|
const pool = context.pool;
|
|
775
787
|
const values = {
|
|
@@ -778,8 +790,7 @@ function resolversOf(context) {
|
|
|
778
790
|
...context.fact?.totalSizeBytes === void 0 ? {} : { "entry.totalSizeBytes": context.fact.totalSizeBytes },
|
|
779
791
|
...context.branch === void 0 ? {} : { "repo.branch": context.branch },
|
|
780
792
|
"repo.detached": context.branchDetached ?? false,
|
|
781
|
-
...
|
|
782
|
-
...pool?.sevenDay === void 0 ? {} : { "quota.sevenDay.remaining": pool.sevenDay.remaining, "quota.sevenDay.utilization": pool.sevenDay.utilization, "quota.sevenDay.hoursUntilReset": pool.sevenDay.hoursUntilReset },
|
|
793
|
+
...windowValues("quota", pool),
|
|
783
794
|
...pool?.burnPerHour === void 0 ? {} : { "quota.burnPerHour": pool.burnPerHour },
|
|
784
795
|
...pool?.resuming === void 0 ? {} : { "session.resuming": pool.resuming },
|
|
785
796
|
...pool?.lastPickHoursAgo === void 0 ? {} : { "session.lastPickHoursAgo": pool.lastPickHoursAgo },
|
|
@@ -790,12 +801,7 @@ function resolversOf(context) {
|
|
|
790
801
|
...context.request?.maxTokens === void 0 ? {} : { "request.maxTokens": context.request.maxTokens },
|
|
791
802
|
...context.request?.isCountTokens === void 0 ? {} : { "request.isCountTokens": context.request.isCountTokens },
|
|
792
803
|
...context.providerQuota === void 0 ? {} : Object.fromEntries(
|
|
793
|
-
Object.entries(context.providerQuota).flatMap(
|
|
794
|
-
([name, windows]) => [
|
|
795
|
-
...windows.fiveHour === void 0 ? [] : [["provider." + name + ".fiveHour.remaining", windows.fiveHour.remaining], ["provider." + name + ".fiveHour.utilization", windows.fiveHour.utilization], ["provider." + name + ".fiveHour.hoursUntilReset", windows.fiveHour.hoursUntilReset]],
|
|
796
|
-
...windows.sevenDay === void 0 ? [] : [["provider." + name + ".sevenDay.remaining", windows.sevenDay.remaining], ["provider." + name + ".sevenDay.utilization", windows.sevenDay.utilization], ["provider." + name + ".sevenDay.hoursUntilReset", windows.sevenDay.hoursUntilReset]]
|
|
797
|
-
]
|
|
798
|
-
)
|
|
804
|
+
Object.entries(context.providerQuota).flatMap(([name, windows]) => Object.entries(windowValues("provider." + name, windows)))
|
|
799
805
|
)
|
|
800
806
|
};
|
|
801
807
|
return {
|
|
@@ -2643,7 +2649,7 @@ var init_package = __esm({
|
|
|
2643
2649
|
"package.json"() {
|
|
2644
2650
|
package_default = {
|
|
2645
2651
|
name: "agent-shim",
|
|
2646
|
-
version: "9.1
|
|
2652
|
+
version: "9.2.1",
|
|
2647
2653
|
description: "A profile manager and launcher for Claude Code that lets one person run multiple logins from one machine while controlling what gets shared between them.",
|
|
2648
2654
|
license: "MIT",
|
|
2649
2655
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -4096,7 +4102,13 @@ var init_schema2 = __esm({
|
|
|
4096
4102
|
/** When the binding window resets. */
|
|
4097
4103
|
resetAt: InstantSchema.optional(),
|
|
4098
4104
|
/** Whether usage beyond the plan (extra usage) is available: `allowed` or `rejected`. */
|
|
4099
|
-
overageStatus: import_zod7.z.string().optional()
|
|
4105
|
+
overageStatus: import_zod7.z.string().optional(),
|
|
4106
|
+
/** The fraction of the extra-usage allowance used, as the upstream reports it (0 to 1). An account with no plan windows, such as an Enterprise one, is metered by this alone. */
|
|
4107
|
+
overageUtilization: import_zod7.z.number().nonnegative().optional(),
|
|
4108
|
+
/** When the extra-usage allowance resets. */
|
|
4109
|
+
overageResetsAt: InstantSchema.optional(),
|
|
4110
|
+
/** Why extra usage is unavailable, as the upstream names it (`out_of_credits`, for one). */
|
|
4111
|
+
overageDisabledReason: import_zod7.z.string().optional()
|
|
4100
4112
|
});
|
|
4101
4113
|
RateLimitStateSchema = import_zod7.z.strictObject({
|
|
4102
4114
|
observedAt: InstantSchema,
|
|
@@ -4256,7 +4268,11 @@ var init_account = __esm({
|
|
|
4256
4268
|
|
|
4257
4269
|
// src/usage/plan.ts
|
|
4258
4270
|
function planOf(account) {
|
|
4259
|
-
const
|
|
4271
|
+
const userTier = account?.userRateLimitTier;
|
|
4272
|
+
if (userTier !== void 0 && ZERO_TIER.test(userTier)) {
|
|
4273
|
+
return { kind: "pay-per-use", tier: userTier };
|
|
4274
|
+
}
|
|
4275
|
+
const tier = account?.organizationRateLimitTier ?? userTier;
|
|
4260
4276
|
const tierField = tier === void 0 ? {} : { tier };
|
|
4261
4277
|
if (tier === void 0) {
|
|
4262
4278
|
return { kind: "subscription", capacity: 1, recognised: false };
|
|
@@ -4330,15 +4346,40 @@ function parseUnifiedRateLimit(headers) {
|
|
|
4330
4346
|
const representativeClaim = headers[`${UNIFIED_PREFIX}representative-claim`];
|
|
4331
4347
|
const resetAt = epochSecondsToIso(headers[`${UNIFIED_PREFIX}reset`]);
|
|
4332
4348
|
const overageStatus = headers[`${UNIFIED_PREFIX}overage-status`];
|
|
4349
|
+
const overageUtilization = nonNegativeNumber(headers[`${UNIFIED_PREFIX}overage-utilization`]);
|
|
4350
|
+
const overageResetsAt = epochSecondsToIso(headers[`${UNIFIED_PREFIX}overage-reset`]);
|
|
4351
|
+
const overageDisabledReason = headers[`${UNIFIED_PREFIX}overage-disabled-reason`];
|
|
4333
4352
|
return {
|
|
4334
4353
|
...status === void 0 ? {} : { status },
|
|
4335
4354
|
...fiveHour === void 0 ? {} : { fiveHour },
|
|
4336
4355
|
...sevenDay === void 0 ? {} : { sevenDay },
|
|
4337
4356
|
...representativeClaim === void 0 ? {} : { representativeClaim },
|
|
4338
4357
|
...resetAt === void 0 ? {} : { resetAt },
|
|
4339
|
-
...overageStatus === void 0 ? {} : { overageStatus }
|
|
4358
|
+
...overageStatus === void 0 ? {} : { overageStatus },
|
|
4359
|
+
...overageUtilization === void 0 ? {} : { overageUtilization },
|
|
4360
|
+
...overageResetsAt === void 0 ? {} : { overageResetsAt },
|
|
4361
|
+
...overageDisabledReason === void 0 ? {} : { overageDisabledReason }
|
|
4340
4362
|
};
|
|
4341
4363
|
}
|
|
4364
|
+
function overageFactsOf(unified) {
|
|
4365
|
+
const { overageStatus, overageUtilization, overageResetsAt, overageDisabledReason } = unified;
|
|
4366
|
+
return {
|
|
4367
|
+
...overageStatus === void 0 ? {} : { overageStatus },
|
|
4368
|
+
...overageUtilization === void 0 ? {} : { overageUtilization },
|
|
4369
|
+
...overageResetsAt === void 0 ? {} : { overageResetsAt },
|
|
4370
|
+
...overageDisabledReason === void 0 ? {} : { overageDisabledReason }
|
|
4371
|
+
};
|
|
4372
|
+
}
|
|
4373
|
+
function overageWindowOf(unified) {
|
|
4374
|
+
const { overageUtilization: utilization, overageResetsAt: resetsAt, overageStatus: status } = unified;
|
|
4375
|
+
if (utilization === void 0 && resetsAt === void 0 && status === void 0) {
|
|
4376
|
+
return void 0;
|
|
4377
|
+
}
|
|
4378
|
+
return { ...utilization === void 0 ? {} : { utilization }, ...resetsAt === void 0 ? {} : { resetsAt }, ...status === void 0 ? {} : { status } };
|
|
4379
|
+
}
|
|
4380
|
+
function soleOverageWindow(unified) {
|
|
4381
|
+
return unified.fiveHour === void 0 && unified.sevenDay === void 0 ? overageWindowOf(unified) : void 0;
|
|
4382
|
+
}
|
|
4342
4383
|
var MS_PER_SECOND2, UNIFIED_PREFIX;
|
|
4343
4384
|
var init_rateLimit = __esm({
|
|
4344
4385
|
"src/usage/rateLimit.ts"() {
|
|
@@ -4412,7 +4453,8 @@ function quotaWarnings(snapshot, provider, nowMs) {
|
|
|
4412
4453
|
const age = formatAge(nowMs - Date.parse(rateLimit.observedAt));
|
|
4413
4454
|
const windows = [
|
|
4414
4455
|
{ name: "five-hour", window: unified.fiveHour },
|
|
4415
|
-
{ name: "seven-day", window: unified.sevenDay }
|
|
4456
|
+
{ name: "seven-day", window: unified.sevenDay },
|
|
4457
|
+
{ name: "extra-usage", window: soleOverageWindow(unified) }
|
|
4416
4458
|
];
|
|
4417
4459
|
return windows.flatMap(({ name, window }) => {
|
|
4418
4460
|
const effective = window === void 0 ? void 0 : effectiveWindow(window, nowMs);
|
|
@@ -4428,6 +4470,7 @@ var MS_PER_SECOND3, SECONDS_PER_MINUTE, MINUTES_PER_HOUR, HOURS_PER_DAY, WARNING
|
|
|
4428
4470
|
var init_preflight = __esm({
|
|
4429
4471
|
"src/usage/preflight.ts"() {
|
|
4430
4472
|
"use strict";
|
|
4473
|
+
init_rateLimit();
|
|
4431
4474
|
MS_PER_SECOND3 = 1e3;
|
|
4432
4475
|
SECONDS_PER_MINUTE = 60;
|
|
4433
4476
|
MINUTES_PER_HOUR = 60;
|
|
@@ -4436,6 +4479,28 @@ var init_preflight = __esm({
|
|
|
4436
4479
|
}
|
|
4437
4480
|
});
|
|
4438
4481
|
|
|
4482
|
+
// src/usage/quotaFacts.ts
|
|
4483
|
+
function windowFacts(window, nowMs) {
|
|
4484
|
+
if (window?.utilization === void 0 || window.resetsAt === void 0) {
|
|
4485
|
+
return void 0;
|
|
4486
|
+
}
|
|
4487
|
+
return { remaining: Math.max(0, 1 - window.utilization), utilization: window.utilization, hoursUntilReset: Math.max(0, (Date.parse(window.resetsAt) - nowMs) / MS_PER_HOUR) };
|
|
4488
|
+
}
|
|
4489
|
+
function quotaFactsOf(unified, nowMs) {
|
|
4490
|
+
const fiveHour = windowFacts(unified?.fiveHour, nowMs);
|
|
4491
|
+
const sevenDay = windowFacts(unified?.sevenDay, nowMs);
|
|
4492
|
+
const extraUsage = windowFacts(unified === void 0 ? void 0 : soleOverageWindow(unified), nowMs);
|
|
4493
|
+
return { ...fiveHour === void 0 ? {} : { fiveHour }, ...sevenDay === void 0 ? {} : { sevenDay }, ...extraUsage === void 0 ? {} : { extraUsage } };
|
|
4494
|
+
}
|
|
4495
|
+
var MS_PER_HOUR;
|
|
4496
|
+
var init_quotaFacts = __esm({
|
|
4497
|
+
"src/usage/quotaFacts.ts"() {
|
|
4498
|
+
"use strict";
|
|
4499
|
+
init_rateLimit();
|
|
4500
|
+
MS_PER_HOUR = 36e5;
|
|
4501
|
+
}
|
|
4502
|
+
});
|
|
4503
|
+
|
|
4439
4504
|
// src/usage/pick.ts
|
|
4440
4505
|
function unifiedOf(state) {
|
|
4441
4506
|
return state?.rateLimit?.unified;
|
|
@@ -4530,18 +4595,22 @@ function assessIdentity(member, nowMs) {
|
|
|
4530
4595
|
...fiveHourWindow === void 0 || five === void 0 ? [] : [describeWindow("5h", fiveHourWindow, five, nowMs)],
|
|
4531
4596
|
...sevenDayWindow === void 0 || seven === void 0 ? [] : [describeWindow("7d", sevenDayWindow, seven, nowMs)]
|
|
4532
4597
|
];
|
|
4598
|
+
const overageWindow = soleOverageWindow(unified);
|
|
4599
|
+
const overage = overageWindow === void 0 ? void 0 : effectiveWindow(overageWindow, nowMs);
|
|
4600
|
+
const overageReasons = overageWindow === void 0 || overage === void 0 ? [] : [describeWindow("extra usage", overageWindow, overage, nowMs)];
|
|
4533
4601
|
const blockedUntil = Math.max(
|
|
4534
|
-
windowBlockedUntil([five, seven].flatMap((window) => window === void 0 ? [] : [window])) ?? 0,
|
|
4602
|
+
windowBlockedUntil([five, seven, overage].flatMap((window) => window === void 0 ? [] : [window])) ?? 0,
|
|
4535
4603
|
limitBlockedUntil(state, nowMs) ?? 0
|
|
4536
4604
|
);
|
|
4537
4605
|
if (blockedUntil > nowMs) {
|
|
4538
4606
|
if (unified.overageStatus === "allowed") {
|
|
4539
4607
|
return { candidate: { ...base, class: "pay-per-use", reasons: [`plan exhausted until ${new Date(blockedUntil).toISOString()}, continues as extra usage`, ...windowReasons, ...planReasons] } };
|
|
4540
4608
|
}
|
|
4541
|
-
return { candidate: { ...base, class: "ineligible", blockedUntilMs: blockedUntil, reasons: [`refused until ${new Date(blockedUntil).toISOString()} (in ${formatAge(blockedUntil - nowMs)})`, ...windowReasons, ...planReasons] } };
|
|
4609
|
+
return { candidate: { ...base, class: "ineligible", blockedUntilMs: blockedUntil, reasons: [`refused until ${new Date(blockedUntil).toISOString()} (in ${formatAge(blockedUntil - nowMs)})`, ...windowReasons, ...overageReasons, ...planReasons] } };
|
|
4542
4610
|
}
|
|
4543
4611
|
if (plan.kind === "pay-per-use" || fiveHourWindow === void 0 && sevenDayWindow === void 0) {
|
|
4544
|
-
|
|
4612
|
+
const headroom = overage?.utilization === void 0 ? void 0 : Math.max(0, 1 - overage.utilization);
|
|
4613
|
+
return { candidate: { ...base, class: "pay-per-use", ...headroom === void 0 ? {} : { headroom }, reasons: [...plan.kind === "pay-per-use" ? planReasons : ["no plan windows reported, so usage bills as extra usage"], ...overageReasons] } };
|
|
4545
4614
|
}
|
|
4546
4615
|
const basis = seven?.utilization !== void 0 ? { window: seven, windowMs: SEVEN_DAY_WINDOW_MS } : five?.utilization !== void 0 ? { window: five, windowMs: FIVE_HOUR_WINDOW_MS } : void 0;
|
|
4547
4616
|
if (basis?.window.utilization === void 0) {
|
|
@@ -4549,7 +4618,7 @@ function assessIdentity(member, nowMs) {
|
|
|
4549
4618
|
}
|
|
4550
4619
|
const remaining = Math.max(0, 1 - basis.window.utilization);
|
|
4551
4620
|
const untilResetMs = basis.window.resetsAtMs === void 0 ? basis.windowMs : Math.max(basis.window.resetsAtMs - nowMs, MS_PER_SECOND4);
|
|
4552
|
-
const score = remaining * plan.capacity / (untilResetMs /
|
|
4621
|
+
const score = remaining * plan.capacity / (untilResetMs / MS_PER_HOUR2);
|
|
4553
4622
|
const fiveRemaining = five?.utilization === void 0 ? void 0 : Math.max(0, 1 - five.utilization);
|
|
4554
4623
|
const fiveUntil = five?.resetsAtMs === void 0 ? FIVE_HOUR_WINDOW_MS : Math.max(five.resetsAtMs - nowMs, MS_PER_SECOND4);
|
|
4555
4624
|
const burn = windowBurn(member.records, "fiveHour");
|
|
@@ -4565,24 +4634,15 @@ function assessIdentity(member, nowMs) {
|
|
|
4565
4634
|
};
|
|
4566
4635
|
}
|
|
4567
4636
|
function poolFactsOf(member, nowMs, resuming, sticky) {
|
|
4568
|
-
const
|
|
4569
|
-
const window = (which) => {
|
|
4570
|
-
const raw = unified?.[which];
|
|
4571
|
-
if (raw?.utilization === void 0) {
|
|
4572
|
-
return void 0;
|
|
4573
|
-
}
|
|
4574
|
-
if (raw.resetsAt === void 0) {
|
|
4575
|
-
return void 0;
|
|
4576
|
-
}
|
|
4577
|
-
return { remaining: Math.max(0, 1 - raw.utilization), utilization: raw.utilization, hoursUntilReset: Math.max(0, (Date.parse(raw.resetsAt) - nowMs) / MS_PER_HOUR) };
|
|
4578
|
-
};
|
|
4637
|
+
const { fiveHour, sevenDay, extraUsage } = quotaFactsOf(member.snapshot?.providers[ANTHROPIC_PROVIDER]?.rateLimit?.unified, nowMs);
|
|
4579
4638
|
const burn = windowBurn(member.records, "fiveHour");
|
|
4580
4639
|
return {
|
|
4581
|
-
...
|
|
4582
|
-
...
|
|
4583
|
-
...
|
|
4640
|
+
...fiveHour === void 0 ? {} : { fiveHour },
|
|
4641
|
+
...sevenDay === void 0 ? {} : { sevenDay },
|
|
4642
|
+
...extraUsage === void 0 ? {} : { extraUsage },
|
|
4643
|
+
...burn === void 0 ? {} : { burnPerHour: burn * MS_PER_HOUR2 },
|
|
4584
4644
|
resuming,
|
|
4585
|
-
...sticky?.identity === member.identity ? { lastPickHoursAgo: Math.max(0, (nowMs - Date.parse(sticky.at)) /
|
|
4645
|
+
...sticky?.identity === member.identity ? { lastPickHoursAgo: Math.max(0, (nowMs - Date.parse(sticky.at)) / MS_PER_HOUR2) } : {}
|
|
4586
4646
|
};
|
|
4587
4647
|
}
|
|
4588
4648
|
function rankPool(input) {
|
|
@@ -4631,7 +4691,7 @@ function rankPool(input) {
|
|
|
4631
4691
|
return { ...candidate, feasible: false, reasons: [...drySpots, ...candidate.reasons] };
|
|
4632
4692
|
});
|
|
4633
4693
|
const ordered = input.preference === "listed" ? [...candidates] : [...candidates].sort(
|
|
4634
|
-
(left, right) => CLASS_ORDER[left.class] - CLASS_ORDER[right.class] || Number(left.policyDemoted ?? false) - Number(right.policyDemoted ?? false) || Number(right.feasible) - Number(left.feasible) || (right.score ?? 0) - (left.score ?? 0) || left.identity.localeCompare(right.identity)
|
|
4694
|
+
(left, right) => CLASS_ORDER[left.class] - CLASS_ORDER[right.class] || Number(left.policyDemoted ?? false) - Number(right.policyDemoted ?? false) || Number(right.feasible) - Number(left.feasible) || (right.headroom ?? 1) - (left.headroom ?? 1) || (right.score ?? 0) - (left.score ?? 0) || left.identity.localeCompare(right.identity)
|
|
4635
4695
|
);
|
|
4636
4696
|
const sticky = input.sticky;
|
|
4637
4697
|
const stickyIndex = sticky === void 0 ? -1 : ordered.findIndex((candidate) => candidate.identity === sticky.identity);
|
|
@@ -4656,7 +4716,7 @@ function rankPool(input) {
|
|
|
4656
4716
|
...movedOff === void 0 || pick === void 0 ? {} : { movedOff }
|
|
4657
4717
|
};
|
|
4658
4718
|
}
|
|
4659
|
-
var MS_PER_SECOND4,
|
|
4719
|
+
var MS_PER_SECOND4, MS_PER_HOUR2, HOURS_PER_DAY2, FIVE_HOURS, PROMPT_CACHE_TTL_HOURS, PERCENT, SEVEN_DAYS, FIVE_HOUR_WINDOW_MS, SEVEN_DAY_WINDOW_MS, PROMPT_CACHE_TTL_MS, CLASS_ORDER;
|
|
4660
4720
|
var init_pick = __esm({
|
|
4661
4721
|
"src/usage/pick.ts"() {
|
|
4662
4722
|
"use strict";
|
|
@@ -4664,17 +4724,18 @@ var init_pick = __esm({
|
|
|
4664
4724
|
init_plan2();
|
|
4665
4725
|
init_middleware();
|
|
4666
4726
|
init_preflight();
|
|
4727
|
+
init_quotaFacts();
|
|
4667
4728
|
init_rateLimit();
|
|
4668
4729
|
MS_PER_SECOND4 = 1e3;
|
|
4669
|
-
|
|
4730
|
+
MS_PER_HOUR2 = 36e5;
|
|
4670
4731
|
HOURS_PER_DAY2 = 24;
|
|
4671
4732
|
FIVE_HOURS = 5;
|
|
4672
4733
|
PROMPT_CACHE_TTL_HOURS = 1;
|
|
4673
4734
|
PERCENT = 100;
|
|
4674
4735
|
SEVEN_DAYS = 7;
|
|
4675
|
-
FIVE_HOUR_WINDOW_MS = FIVE_HOURS *
|
|
4676
|
-
SEVEN_DAY_WINDOW_MS = SEVEN_DAYS * HOURS_PER_DAY2 *
|
|
4677
|
-
PROMPT_CACHE_TTL_MS = PROMPT_CACHE_TTL_HOURS *
|
|
4736
|
+
FIVE_HOUR_WINDOW_MS = FIVE_HOURS * MS_PER_HOUR2;
|
|
4737
|
+
SEVEN_DAY_WINDOW_MS = SEVEN_DAYS * HOURS_PER_DAY2 * MS_PER_HOUR2;
|
|
4738
|
+
PROMPT_CACHE_TTL_MS = PROMPT_CACHE_TTL_HOURS * MS_PER_HOUR2;
|
|
4678
4739
|
CLASS_ORDER = { scored: 0, unknown: 1, "pay-per-use": 2, ineligible: 3 };
|
|
4679
4740
|
}
|
|
4680
4741
|
});
|
|
@@ -4895,8 +4956,9 @@ function createUsageStore(deps) {
|
|
|
4895
4956
|
recordRateLimit: (identity, provider, rateLimit) => rewriteSnapshot(identity, (current) => {
|
|
4896
4957
|
const state = current?.providers[provider] ?? {};
|
|
4897
4958
|
const keep = state.rateLimit !== void 0 && state.rateLimit.observedAt.localeCompare(rateLimit.observedAt) > 0;
|
|
4898
|
-
const
|
|
4899
|
-
const
|
|
4959
|
+
const earlier = state.rateLimit?.unified;
|
|
4960
|
+
const carried = rateLimit.unified === void 0 || rateLimit.unified.overageStatus !== void 0 || earlier === void 0 ? void 0 : overageFactsOf(earlier);
|
|
4961
|
+
const merged = carried === void 0 || rateLimit.unified === void 0 ? rateLimit : { ...rateLimit, unified: { ...rateLimit.unified, ...carried } };
|
|
4900
4962
|
return { ...current?.providers, [provider]: { ...state, rateLimit: keep ? state.rateLimit : merged } };
|
|
4901
4963
|
})
|
|
4902
4964
|
};
|
|
@@ -7360,7 +7422,8 @@ function unifiedFromReportedLimits(reported) {
|
|
|
7360
7422
|
return { ...fiveHour === void 0 ? {} : { fiveHour }, ...sevenDay === void 0 ? {} : { sevenDay } };
|
|
7361
7423
|
}
|
|
7362
7424
|
function isAnthropicUsageProbeable(member) {
|
|
7363
|
-
|
|
7425
|
+
const unified = member.snapshot?.providers[ANTHROPIC_PROVIDER]?.rateLimit?.unified;
|
|
7426
|
+
return planOf(member.account ?? member.snapshot?.account).kind === "subscription" && (unified === void 0 || soleOverageWindow(unified) === void 0);
|
|
7364
7427
|
}
|
|
7365
7428
|
function isAnthropicUsageStale(member, nowMs) {
|
|
7366
7429
|
const rateLimit = member.snapshot?.providers[ANTHROPIC_PROVIDER]?.rateLimit;
|
|
@@ -7446,6 +7509,7 @@ var init_anthropicUsageRefresh = __esm({
|
|
|
7446
7509
|
init_middleware();
|
|
7447
7510
|
init_pick();
|
|
7448
7511
|
init_plan2();
|
|
7512
|
+
init_rateLimit();
|
|
7449
7513
|
PERCENT2 = 100;
|
|
7450
7514
|
ANTHROPIC_USAGE_FRESHNESS_MS = FIVE_HOUR_WINDOW_MS / PERCENT2;
|
|
7451
7515
|
NO_PLAN_WINDOWS_FRESHNESS_MS = SEVEN_DAY_WINDOW_MS / PERCENT2;
|
|
@@ -13168,11 +13232,11 @@ function createDoorHealthPublisher(hub, now, pid) {
|
|
|
13168
13232
|
|
|
13169
13233
|
// src/frontdoor/quotaExpiringEvents.ts
|
|
13170
13234
|
init_schema2();
|
|
13171
|
-
var
|
|
13235
|
+
var MS_PER_HOUR3 = 36e5;
|
|
13172
13236
|
var MS_PER_DAY2 = 864e5;
|
|
13173
13237
|
var FIVE_HOUR_WINDOW_HOURS = 5;
|
|
13174
13238
|
var SEVEN_DAY_WINDOW_DAYS = 7;
|
|
13175
|
-
var FIVE_HOUR_WINDOW_MS2 = FIVE_HOUR_WINDOW_HOURS *
|
|
13239
|
+
var FIVE_HOUR_WINDOW_MS2 = FIVE_HOUR_WINDOW_HOURS * MS_PER_HOUR3;
|
|
13176
13240
|
var SEVEN_DAY_WINDOW_MS2 = SEVEN_DAY_WINDOW_DAYS * MS_PER_DAY2;
|
|
13177
13241
|
var FINAL_SPAN_DENOMINATOR = 30;
|
|
13178
13242
|
var QUOTA_EXPIRING_WINDOW_FRACTION = 1 / FINAL_SPAN_DENOMINATOR;
|
package/dist/index.mjs
CHANGED
|
@@ -750,6 +750,18 @@ function matchBranch(pattern, branch, detached = false) {
|
|
|
750
750
|
}
|
|
751
751
|
return picomatch2(pattern, { dot: true, nocase: false })(branch);
|
|
752
752
|
}
|
|
753
|
+
function windowValues(prefix, windows) {
|
|
754
|
+
const values = {};
|
|
755
|
+
for (const name of ["fiveHour", "sevenDay", "extraUsage"]) {
|
|
756
|
+
const facts = windows?.[name];
|
|
757
|
+
if (facts !== void 0) {
|
|
758
|
+
values[`${prefix}.${name}.remaining`] = facts.remaining;
|
|
759
|
+
values[`${prefix}.${name}.utilization`] = facts.utilization;
|
|
760
|
+
values[`${prefix}.${name}.hoursUntilReset`] = facts.hoursUntilReset;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
return values;
|
|
764
|
+
}
|
|
753
765
|
function resolversOf(context) {
|
|
754
766
|
const pool = context.pool;
|
|
755
767
|
const values = {
|
|
@@ -758,8 +770,7 @@ function resolversOf(context) {
|
|
|
758
770
|
...context.fact?.totalSizeBytes === void 0 ? {} : { "entry.totalSizeBytes": context.fact.totalSizeBytes },
|
|
759
771
|
...context.branch === void 0 ? {} : { "repo.branch": context.branch },
|
|
760
772
|
"repo.detached": context.branchDetached ?? false,
|
|
761
|
-
...
|
|
762
|
-
...pool?.sevenDay === void 0 ? {} : { "quota.sevenDay.remaining": pool.sevenDay.remaining, "quota.sevenDay.utilization": pool.sevenDay.utilization, "quota.sevenDay.hoursUntilReset": pool.sevenDay.hoursUntilReset },
|
|
773
|
+
...windowValues("quota", pool),
|
|
763
774
|
...pool?.burnPerHour === void 0 ? {} : { "quota.burnPerHour": pool.burnPerHour },
|
|
764
775
|
...pool?.resuming === void 0 ? {} : { "session.resuming": pool.resuming },
|
|
765
776
|
...pool?.lastPickHoursAgo === void 0 ? {} : { "session.lastPickHoursAgo": pool.lastPickHoursAgo },
|
|
@@ -770,12 +781,7 @@ function resolversOf(context) {
|
|
|
770
781
|
...context.request?.maxTokens === void 0 ? {} : { "request.maxTokens": context.request.maxTokens },
|
|
771
782
|
...context.request?.isCountTokens === void 0 ? {} : { "request.isCountTokens": context.request.isCountTokens },
|
|
772
783
|
...context.providerQuota === void 0 ? {} : Object.fromEntries(
|
|
773
|
-
Object.entries(context.providerQuota).flatMap(
|
|
774
|
-
([name, windows]) => [
|
|
775
|
-
...windows.fiveHour === void 0 ? [] : [["provider." + name + ".fiveHour.remaining", windows.fiveHour.remaining], ["provider." + name + ".fiveHour.utilization", windows.fiveHour.utilization], ["provider." + name + ".fiveHour.hoursUntilReset", windows.fiveHour.hoursUntilReset]],
|
|
776
|
-
...windows.sevenDay === void 0 ? [] : [["provider." + name + ".sevenDay.remaining", windows.sevenDay.remaining], ["provider." + name + ".sevenDay.utilization", windows.sevenDay.utilization], ["provider." + name + ".sevenDay.hoursUntilReset", windows.sevenDay.hoursUntilReset]]
|
|
777
|
-
]
|
|
778
|
-
)
|
|
784
|
+
Object.entries(context.providerQuota).flatMap(([name, windows]) => Object.entries(windowValues("provider." + name, windows)))
|
|
779
785
|
)
|
|
780
786
|
};
|
|
781
787
|
return {
|
|
@@ -2619,7 +2625,7 @@ var init_package = __esm({
|
|
|
2619
2625
|
"package.json"() {
|
|
2620
2626
|
package_default = {
|
|
2621
2627
|
name: "agent-shim",
|
|
2622
|
-
version: "9.1
|
|
2628
|
+
version: "9.2.1",
|
|
2623
2629
|
description: "A profile manager and launcher for Claude Code that lets one person run multiple logins from one machine while controlling what gets shared between them.",
|
|
2624
2630
|
license: "MIT",
|
|
2625
2631
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -4070,7 +4076,13 @@ var init_schema2 = __esm({
|
|
|
4070
4076
|
/** When the binding window resets. */
|
|
4071
4077
|
resetAt: InstantSchema.optional(),
|
|
4072
4078
|
/** Whether usage beyond the plan (extra usage) is available: `allowed` or `rejected`. */
|
|
4073
|
-
overageStatus: z7.string().optional()
|
|
4079
|
+
overageStatus: z7.string().optional(),
|
|
4080
|
+
/** The fraction of the extra-usage allowance used, as the upstream reports it (0 to 1). An account with no plan windows, such as an Enterprise one, is metered by this alone. */
|
|
4081
|
+
overageUtilization: z7.number().nonnegative().optional(),
|
|
4082
|
+
/** When the extra-usage allowance resets. */
|
|
4083
|
+
overageResetsAt: InstantSchema.optional(),
|
|
4084
|
+
/** Why extra usage is unavailable, as the upstream names it (`out_of_credits`, for one). */
|
|
4085
|
+
overageDisabledReason: z7.string().optional()
|
|
4074
4086
|
});
|
|
4075
4087
|
RateLimitStateSchema = z7.strictObject({
|
|
4076
4088
|
observedAt: InstantSchema,
|
|
@@ -4231,7 +4243,11 @@ var init_account = __esm({
|
|
|
4231
4243
|
// src/usage/plan.ts
|
|
4232
4244
|
import { z as z8 } from "zod";
|
|
4233
4245
|
function planOf(account) {
|
|
4234
|
-
const
|
|
4246
|
+
const userTier = account?.userRateLimitTier;
|
|
4247
|
+
if (userTier !== void 0 && ZERO_TIER.test(userTier)) {
|
|
4248
|
+
return { kind: "pay-per-use", tier: userTier };
|
|
4249
|
+
}
|
|
4250
|
+
const tier = account?.organizationRateLimitTier ?? userTier;
|
|
4235
4251
|
const tierField = tier === void 0 ? {} : { tier };
|
|
4236
4252
|
if (tier === void 0) {
|
|
4237
4253
|
return { kind: "subscription", capacity: 1, recognised: false };
|
|
@@ -4304,15 +4320,40 @@ function parseUnifiedRateLimit(headers) {
|
|
|
4304
4320
|
const representativeClaim = headers[`${UNIFIED_PREFIX}representative-claim`];
|
|
4305
4321
|
const resetAt = epochSecondsToIso(headers[`${UNIFIED_PREFIX}reset`]);
|
|
4306
4322
|
const overageStatus = headers[`${UNIFIED_PREFIX}overage-status`];
|
|
4323
|
+
const overageUtilization = nonNegativeNumber(headers[`${UNIFIED_PREFIX}overage-utilization`]);
|
|
4324
|
+
const overageResetsAt = epochSecondsToIso(headers[`${UNIFIED_PREFIX}overage-reset`]);
|
|
4325
|
+
const overageDisabledReason = headers[`${UNIFIED_PREFIX}overage-disabled-reason`];
|
|
4307
4326
|
return {
|
|
4308
4327
|
...status === void 0 ? {} : { status },
|
|
4309
4328
|
...fiveHour === void 0 ? {} : { fiveHour },
|
|
4310
4329
|
...sevenDay === void 0 ? {} : { sevenDay },
|
|
4311
4330
|
...representativeClaim === void 0 ? {} : { representativeClaim },
|
|
4312
4331
|
...resetAt === void 0 ? {} : { resetAt },
|
|
4313
|
-
...overageStatus === void 0 ? {} : { overageStatus }
|
|
4332
|
+
...overageStatus === void 0 ? {} : { overageStatus },
|
|
4333
|
+
...overageUtilization === void 0 ? {} : { overageUtilization },
|
|
4334
|
+
...overageResetsAt === void 0 ? {} : { overageResetsAt },
|
|
4335
|
+
...overageDisabledReason === void 0 ? {} : { overageDisabledReason }
|
|
4314
4336
|
};
|
|
4315
4337
|
}
|
|
4338
|
+
function overageFactsOf(unified) {
|
|
4339
|
+
const { overageStatus, overageUtilization, overageResetsAt, overageDisabledReason } = unified;
|
|
4340
|
+
return {
|
|
4341
|
+
...overageStatus === void 0 ? {} : { overageStatus },
|
|
4342
|
+
...overageUtilization === void 0 ? {} : { overageUtilization },
|
|
4343
|
+
...overageResetsAt === void 0 ? {} : { overageResetsAt },
|
|
4344
|
+
...overageDisabledReason === void 0 ? {} : { overageDisabledReason }
|
|
4345
|
+
};
|
|
4346
|
+
}
|
|
4347
|
+
function overageWindowOf(unified) {
|
|
4348
|
+
const { overageUtilization: utilization, overageResetsAt: resetsAt, overageStatus: status } = unified;
|
|
4349
|
+
if (utilization === void 0 && resetsAt === void 0 && status === void 0) {
|
|
4350
|
+
return void 0;
|
|
4351
|
+
}
|
|
4352
|
+
return { ...utilization === void 0 ? {} : { utilization }, ...resetsAt === void 0 ? {} : { resetsAt }, ...status === void 0 ? {} : { status } };
|
|
4353
|
+
}
|
|
4354
|
+
function soleOverageWindow(unified) {
|
|
4355
|
+
return unified.fiveHour === void 0 && unified.sevenDay === void 0 ? overageWindowOf(unified) : void 0;
|
|
4356
|
+
}
|
|
4316
4357
|
var MS_PER_SECOND2, UNIFIED_PREFIX;
|
|
4317
4358
|
var init_rateLimit = __esm({
|
|
4318
4359
|
"src/usage/rateLimit.ts"() {
|
|
@@ -4386,7 +4427,8 @@ function quotaWarnings(snapshot, provider, nowMs) {
|
|
|
4386
4427
|
const age = formatAge(nowMs - Date.parse(rateLimit.observedAt));
|
|
4387
4428
|
const windows = [
|
|
4388
4429
|
{ name: "five-hour", window: unified.fiveHour },
|
|
4389
|
-
{ name: "seven-day", window: unified.sevenDay }
|
|
4430
|
+
{ name: "seven-day", window: unified.sevenDay },
|
|
4431
|
+
{ name: "extra-usage", window: soleOverageWindow(unified) }
|
|
4390
4432
|
];
|
|
4391
4433
|
return windows.flatMap(({ name, window }) => {
|
|
4392
4434
|
const effective = window === void 0 ? void 0 : effectiveWindow(window, nowMs);
|
|
@@ -4402,6 +4444,7 @@ var MS_PER_SECOND3, SECONDS_PER_MINUTE, MINUTES_PER_HOUR, HOURS_PER_DAY, WARNING
|
|
|
4402
4444
|
var init_preflight = __esm({
|
|
4403
4445
|
"src/usage/preflight.ts"() {
|
|
4404
4446
|
"use strict";
|
|
4447
|
+
init_rateLimit();
|
|
4405
4448
|
MS_PER_SECOND3 = 1e3;
|
|
4406
4449
|
SECONDS_PER_MINUTE = 60;
|
|
4407
4450
|
MINUTES_PER_HOUR = 60;
|
|
@@ -4410,6 +4453,28 @@ var init_preflight = __esm({
|
|
|
4410
4453
|
}
|
|
4411
4454
|
});
|
|
4412
4455
|
|
|
4456
|
+
// src/usage/quotaFacts.ts
|
|
4457
|
+
function windowFacts(window, nowMs) {
|
|
4458
|
+
if (window?.utilization === void 0 || window.resetsAt === void 0) {
|
|
4459
|
+
return void 0;
|
|
4460
|
+
}
|
|
4461
|
+
return { remaining: Math.max(0, 1 - window.utilization), utilization: window.utilization, hoursUntilReset: Math.max(0, (Date.parse(window.resetsAt) - nowMs) / MS_PER_HOUR) };
|
|
4462
|
+
}
|
|
4463
|
+
function quotaFactsOf(unified, nowMs) {
|
|
4464
|
+
const fiveHour = windowFacts(unified?.fiveHour, nowMs);
|
|
4465
|
+
const sevenDay = windowFacts(unified?.sevenDay, nowMs);
|
|
4466
|
+
const extraUsage = windowFacts(unified === void 0 ? void 0 : soleOverageWindow(unified), nowMs);
|
|
4467
|
+
return { ...fiveHour === void 0 ? {} : { fiveHour }, ...sevenDay === void 0 ? {} : { sevenDay }, ...extraUsage === void 0 ? {} : { extraUsage } };
|
|
4468
|
+
}
|
|
4469
|
+
var MS_PER_HOUR;
|
|
4470
|
+
var init_quotaFacts = __esm({
|
|
4471
|
+
"src/usage/quotaFacts.ts"() {
|
|
4472
|
+
"use strict";
|
|
4473
|
+
init_rateLimit();
|
|
4474
|
+
MS_PER_HOUR = 36e5;
|
|
4475
|
+
}
|
|
4476
|
+
});
|
|
4477
|
+
|
|
4413
4478
|
// src/usage/pick.ts
|
|
4414
4479
|
function unifiedOf(state) {
|
|
4415
4480
|
return state?.rateLimit?.unified;
|
|
@@ -4504,18 +4569,22 @@ function assessIdentity(member, nowMs) {
|
|
|
4504
4569
|
...fiveHourWindow === void 0 || five === void 0 ? [] : [describeWindow("5h", fiveHourWindow, five, nowMs)],
|
|
4505
4570
|
...sevenDayWindow === void 0 || seven === void 0 ? [] : [describeWindow("7d", sevenDayWindow, seven, nowMs)]
|
|
4506
4571
|
];
|
|
4572
|
+
const overageWindow = soleOverageWindow(unified);
|
|
4573
|
+
const overage = overageWindow === void 0 ? void 0 : effectiveWindow(overageWindow, nowMs);
|
|
4574
|
+
const overageReasons = overageWindow === void 0 || overage === void 0 ? [] : [describeWindow("extra usage", overageWindow, overage, nowMs)];
|
|
4507
4575
|
const blockedUntil = Math.max(
|
|
4508
|
-
windowBlockedUntil([five, seven].flatMap((window) => window === void 0 ? [] : [window])) ?? 0,
|
|
4576
|
+
windowBlockedUntil([five, seven, overage].flatMap((window) => window === void 0 ? [] : [window])) ?? 0,
|
|
4509
4577
|
limitBlockedUntil(state, nowMs) ?? 0
|
|
4510
4578
|
);
|
|
4511
4579
|
if (blockedUntil > nowMs) {
|
|
4512
4580
|
if (unified.overageStatus === "allowed") {
|
|
4513
4581
|
return { candidate: { ...base, class: "pay-per-use", reasons: [`plan exhausted until ${new Date(blockedUntil).toISOString()}, continues as extra usage`, ...windowReasons, ...planReasons] } };
|
|
4514
4582
|
}
|
|
4515
|
-
return { candidate: { ...base, class: "ineligible", blockedUntilMs: blockedUntil, reasons: [`refused until ${new Date(blockedUntil).toISOString()} (in ${formatAge(blockedUntil - nowMs)})`, ...windowReasons, ...planReasons] } };
|
|
4583
|
+
return { candidate: { ...base, class: "ineligible", blockedUntilMs: blockedUntil, reasons: [`refused until ${new Date(blockedUntil).toISOString()} (in ${formatAge(blockedUntil - nowMs)})`, ...windowReasons, ...overageReasons, ...planReasons] } };
|
|
4516
4584
|
}
|
|
4517
4585
|
if (plan.kind === "pay-per-use" || fiveHourWindow === void 0 && sevenDayWindow === void 0) {
|
|
4518
|
-
|
|
4586
|
+
const headroom = overage?.utilization === void 0 ? void 0 : Math.max(0, 1 - overage.utilization);
|
|
4587
|
+
return { candidate: { ...base, class: "pay-per-use", ...headroom === void 0 ? {} : { headroom }, reasons: [...plan.kind === "pay-per-use" ? planReasons : ["no plan windows reported, so usage bills as extra usage"], ...overageReasons] } };
|
|
4519
4588
|
}
|
|
4520
4589
|
const basis = seven?.utilization !== void 0 ? { window: seven, windowMs: SEVEN_DAY_WINDOW_MS } : five?.utilization !== void 0 ? { window: five, windowMs: FIVE_HOUR_WINDOW_MS } : void 0;
|
|
4521
4590
|
if (basis?.window.utilization === void 0) {
|
|
@@ -4523,7 +4592,7 @@ function assessIdentity(member, nowMs) {
|
|
|
4523
4592
|
}
|
|
4524
4593
|
const remaining = Math.max(0, 1 - basis.window.utilization);
|
|
4525
4594
|
const untilResetMs = basis.window.resetsAtMs === void 0 ? basis.windowMs : Math.max(basis.window.resetsAtMs - nowMs, MS_PER_SECOND4);
|
|
4526
|
-
const score = remaining * plan.capacity / (untilResetMs /
|
|
4595
|
+
const score = remaining * plan.capacity / (untilResetMs / MS_PER_HOUR2);
|
|
4527
4596
|
const fiveRemaining = five?.utilization === void 0 ? void 0 : Math.max(0, 1 - five.utilization);
|
|
4528
4597
|
const fiveUntil = five?.resetsAtMs === void 0 ? FIVE_HOUR_WINDOW_MS : Math.max(five.resetsAtMs - nowMs, MS_PER_SECOND4);
|
|
4529
4598
|
const burn = windowBurn(member.records, "fiveHour");
|
|
@@ -4539,24 +4608,15 @@ function assessIdentity(member, nowMs) {
|
|
|
4539
4608
|
};
|
|
4540
4609
|
}
|
|
4541
4610
|
function poolFactsOf(member, nowMs, resuming, sticky) {
|
|
4542
|
-
const
|
|
4543
|
-
const window = (which) => {
|
|
4544
|
-
const raw = unified?.[which];
|
|
4545
|
-
if (raw?.utilization === void 0) {
|
|
4546
|
-
return void 0;
|
|
4547
|
-
}
|
|
4548
|
-
if (raw.resetsAt === void 0) {
|
|
4549
|
-
return void 0;
|
|
4550
|
-
}
|
|
4551
|
-
return { remaining: Math.max(0, 1 - raw.utilization), utilization: raw.utilization, hoursUntilReset: Math.max(0, (Date.parse(raw.resetsAt) - nowMs) / MS_PER_HOUR) };
|
|
4552
|
-
};
|
|
4611
|
+
const { fiveHour, sevenDay, extraUsage } = quotaFactsOf(member.snapshot?.providers[ANTHROPIC_PROVIDER]?.rateLimit?.unified, nowMs);
|
|
4553
4612
|
const burn = windowBurn(member.records, "fiveHour");
|
|
4554
4613
|
return {
|
|
4555
|
-
...
|
|
4556
|
-
...
|
|
4557
|
-
...
|
|
4614
|
+
...fiveHour === void 0 ? {} : { fiveHour },
|
|
4615
|
+
...sevenDay === void 0 ? {} : { sevenDay },
|
|
4616
|
+
...extraUsage === void 0 ? {} : { extraUsage },
|
|
4617
|
+
...burn === void 0 ? {} : { burnPerHour: burn * MS_PER_HOUR2 },
|
|
4558
4618
|
resuming,
|
|
4559
|
-
...sticky?.identity === member.identity ? { lastPickHoursAgo: Math.max(0, (nowMs - Date.parse(sticky.at)) /
|
|
4619
|
+
...sticky?.identity === member.identity ? { lastPickHoursAgo: Math.max(0, (nowMs - Date.parse(sticky.at)) / MS_PER_HOUR2) } : {}
|
|
4560
4620
|
};
|
|
4561
4621
|
}
|
|
4562
4622
|
function rankPool(input) {
|
|
@@ -4605,7 +4665,7 @@ function rankPool(input) {
|
|
|
4605
4665
|
return { ...candidate, feasible: false, reasons: [...drySpots, ...candidate.reasons] };
|
|
4606
4666
|
});
|
|
4607
4667
|
const ordered = input.preference === "listed" ? [...candidates] : [...candidates].sort(
|
|
4608
|
-
(left, right) => CLASS_ORDER[left.class] - CLASS_ORDER[right.class] || Number(left.policyDemoted ?? false) - Number(right.policyDemoted ?? false) || Number(right.feasible) - Number(left.feasible) || (right.score ?? 0) - (left.score ?? 0) || left.identity.localeCompare(right.identity)
|
|
4668
|
+
(left, right) => CLASS_ORDER[left.class] - CLASS_ORDER[right.class] || Number(left.policyDemoted ?? false) - Number(right.policyDemoted ?? false) || Number(right.feasible) - Number(left.feasible) || (right.headroom ?? 1) - (left.headroom ?? 1) || (right.score ?? 0) - (left.score ?? 0) || left.identity.localeCompare(right.identity)
|
|
4609
4669
|
);
|
|
4610
4670
|
const sticky = input.sticky;
|
|
4611
4671
|
const stickyIndex = sticky === void 0 ? -1 : ordered.findIndex((candidate) => candidate.identity === sticky.identity);
|
|
@@ -4630,7 +4690,7 @@ function rankPool(input) {
|
|
|
4630
4690
|
...movedOff === void 0 || pick === void 0 ? {} : { movedOff }
|
|
4631
4691
|
};
|
|
4632
4692
|
}
|
|
4633
|
-
var MS_PER_SECOND4,
|
|
4693
|
+
var MS_PER_SECOND4, MS_PER_HOUR2, HOURS_PER_DAY2, FIVE_HOURS, PROMPT_CACHE_TTL_HOURS, PERCENT, SEVEN_DAYS, FIVE_HOUR_WINDOW_MS, SEVEN_DAY_WINDOW_MS, PROMPT_CACHE_TTL_MS, CLASS_ORDER;
|
|
4634
4694
|
var init_pick = __esm({
|
|
4635
4695
|
"src/usage/pick.ts"() {
|
|
4636
4696
|
"use strict";
|
|
@@ -4638,17 +4698,18 @@ var init_pick = __esm({
|
|
|
4638
4698
|
init_plan2();
|
|
4639
4699
|
init_middleware();
|
|
4640
4700
|
init_preflight();
|
|
4701
|
+
init_quotaFacts();
|
|
4641
4702
|
init_rateLimit();
|
|
4642
4703
|
MS_PER_SECOND4 = 1e3;
|
|
4643
|
-
|
|
4704
|
+
MS_PER_HOUR2 = 36e5;
|
|
4644
4705
|
HOURS_PER_DAY2 = 24;
|
|
4645
4706
|
FIVE_HOURS = 5;
|
|
4646
4707
|
PROMPT_CACHE_TTL_HOURS = 1;
|
|
4647
4708
|
PERCENT = 100;
|
|
4648
4709
|
SEVEN_DAYS = 7;
|
|
4649
|
-
FIVE_HOUR_WINDOW_MS = FIVE_HOURS *
|
|
4650
|
-
SEVEN_DAY_WINDOW_MS = SEVEN_DAYS * HOURS_PER_DAY2 *
|
|
4651
|
-
PROMPT_CACHE_TTL_MS = PROMPT_CACHE_TTL_HOURS *
|
|
4710
|
+
FIVE_HOUR_WINDOW_MS = FIVE_HOURS * MS_PER_HOUR2;
|
|
4711
|
+
SEVEN_DAY_WINDOW_MS = SEVEN_DAYS * HOURS_PER_DAY2 * MS_PER_HOUR2;
|
|
4712
|
+
PROMPT_CACHE_TTL_MS = PROMPT_CACHE_TTL_HOURS * MS_PER_HOUR2;
|
|
4652
4713
|
CLASS_ORDER = { scored: 0, unknown: 1, "pay-per-use": 2, ineligible: 3 };
|
|
4653
4714
|
}
|
|
4654
4715
|
});
|
|
@@ -4870,8 +4931,9 @@ function createUsageStore(deps) {
|
|
|
4870
4931
|
recordRateLimit: (identity, provider, rateLimit) => rewriteSnapshot(identity, (current) => {
|
|
4871
4932
|
const state = current?.providers[provider] ?? {};
|
|
4872
4933
|
const keep = state.rateLimit !== void 0 && state.rateLimit.observedAt.localeCompare(rateLimit.observedAt) > 0;
|
|
4873
|
-
const
|
|
4874
|
-
const
|
|
4934
|
+
const earlier = state.rateLimit?.unified;
|
|
4935
|
+
const carried = rateLimit.unified === void 0 || rateLimit.unified.overageStatus !== void 0 || earlier === void 0 ? void 0 : overageFactsOf(earlier);
|
|
4936
|
+
const merged = carried === void 0 || rateLimit.unified === void 0 ? rateLimit : { ...rateLimit, unified: { ...rateLimit.unified, ...carried } };
|
|
4875
4937
|
return { ...current?.providers, [provider]: { ...state, rateLimit: keep ? state.rateLimit : merged } };
|
|
4876
4938
|
})
|
|
4877
4939
|
};
|
|
@@ -7332,7 +7394,8 @@ function unifiedFromReportedLimits(reported) {
|
|
|
7332
7394
|
return { ...fiveHour === void 0 ? {} : { fiveHour }, ...sevenDay === void 0 ? {} : { sevenDay } };
|
|
7333
7395
|
}
|
|
7334
7396
|
function isAnthropicUsageProbeable(member) {
|
|
7335
|
-
|
|
7397
|
+
const unified = member.snapshot?.providers[ANTHROPIC_PROVIDER]?.rateLimit?.unified;
|
|
7398
|
+
return planOf(member.account ?? member.snapshot?.account).kind === "subscription" && (unified === void 0 || soleOverageWindow(unified) === void 0);
|
|
7336
7399
|
}
|
|
7337
7400
|
function isAnthropicUsageStale(member, nowMs) {
|
|
7338
7401
|
const rateLimit = member.snapshot?.providers[ANTHROPIC_PROVIDER]?.rateLimit;
|
|
@@ -7418,6 +7481,7 @@ var init_anthropicUsageRefresh = __esm({
|
|
|
7418
7481
|
init_middleware();
|
|
7419
7482
|
init_pick();
|
|
7420
7483
|
init_plan2();
|
|
7484
|
+
init_rateLimit();
|
|
7421
7485
|
PERCENT2 = 100;
|
|
7422
7486
|
ANTHROPIC_USAGE_FRESHNESS_MS = FIVE_HOUR_WINDOW_MS / PERCENT2;
|
|
7423
7487
|
NO_PLAN_WINDOWS_FRESHNESS_MS = SEVEN_DAY_WINDOW_MS / PERCENT2;
|
|
@@ -12843,11 +12907,11 @@ function createDoorHealthPublisher(hub, now, pid) {
|
|
|
12843
12907
|
|
|
12844
12908
|
// src/frontdoor/quotaExpiringEvents.ts
|
|
12845
12909
|
init_schema2();
|
|
12846
|
-
var
|
|
12910
|
+
var MS_PER_HOUR3 = 36e5;
|
|
12847
12911
|
var MS_PER_DAY2 = 864e5;
|
|
12848
12912
|
var FIVE_HOUR_WINDOW_HOURS = 5;
|
|
12849
12913
|
var SEVEN_DAY_WINDOW_DAYS = 7;
|
|
12850
|
-
var FIVE_HOUR_WINDOW_MS2 = FIVE_HOUR_WINDOW_HOURS *
|
|
12914
|
+
var FIVE_HOUR_WINDOW_MS2 = FIVE_HOUR_WINDOW_HOURS * MS_PER_HOUR3;
|
|
12851
12915
|
var SEVEN_DAY_WINDOW_MS2 = SEVEN_DAY_WINDOW_DAYS * MS_PER_DAY2;
|
|
12852
12916
|
var FINAL_SPAN_DENOMINATOR = 30;
|
|
12853
12917
|
var QUOTA_EXPIRING_WINDOW_FRACTION = 1 / FINAL_SPAN_DENOMINATOR;
|