agent-shim 9.0.0 → 9.2.0
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 +386 -326
- package/dist/index.cjs +104 -42
- package/dist/index.mjs +103 -42
- package/dist/types/index.d.ts +26 -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.
|
|
2652
|
+
version: "9.2.0",
|
|
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,
|
|
@@ -4330,15 +4342,40 @@ function parseUnifiedRateLimit(headers) {
|
|
|
4330
4342
|
const representativeClaim = headers[`${UNIFIED_PREFIX}representative-claim`];
|
|
4331
4343
|
const resetAt = epochSecondsToIso(headers[`${UNIFIED_PREFIX}reset`]);
|
|
4332
4344
|
const overageStatus = headers[`${UNIFIED_PREFIX}overage-status`];
|
|
4345
|
+
const overageUtilization = nonNegativeNumber(headers[`${UNIFIED_PREFIX}overage-utilization`]);
|
|
4346
|
+
const overageResetsAt = epochSecondsToIso(headers[`${UNIFIED_PREFIX}overage-reset`]);
|
|
4347
|
+
const overageDisabledReason = headers[`${UNIFIED_PREFIX}overage-disabled-reason`];
|
|
4333
4348
|
return {
|
|
4334
4349
|
...status === void 0 ? {} : { status },
|
|
4335
4350
|
...fiveHour === void 0 ? {} : { fiveHour },
|
|
4336
4351
|
...sevenDay === void 0 ? {} : { sevenDay },
|
|
4337
4352
|
...representativeClaim === void 0 ? {} : { representativeClaim },
|
|
4338
4353
|
...resetAt === void 0 ? {} : { resetAt },
|
|
4339
|
-
...overageStatus === void 0 ? {} : { overageStatus }
|
|
4354
|
+
...overageStatus === void 0 ? {} : { overageStatus },
|
|
4355
|
+
...overageUtilization === void 0 ? {} : { overageUtilization },
|
|
4356
|
+
...overageResetsAt === void 0 ? {} : { overageResetsAt },
|
|
4357
|
+
...overageDisabledReason === void 0 ? {} : { overageDisabledReason }
|
|
4340
4358
|
};
|
|
4341
4359
|
}
|
|
4360
|
+
function overageFactsOf(unified) {
|
|
4361
|
+
const { overageStatus, overageUtilization, overageResetsAt, overageDisabledReason } = unified;
|
|
4362
|
+
return {
|
|
4363
|
+
...overageStatus === void 0 ? {} : { overageStatus },
|
|
4364
|
+
...overageUtilization === void 0 ? {} : { overageUtilization },
|
|
4365
|
+
...overageResetsAt === void 0 ? {} : { overageResetsAt },
|
|
4366
|
+
...overageDisabledReason === void 0 ? {} : { overageDisabledReason }
|
|
4367
|
+
};
|
|
4368
|
+
}
|
|
4369
|
+
function overageWindowOf(unified) {
|
|
4370
|
+
const { overageUtilization: utilization, overageResetsAt: resetsAt, overageStatus: status } = unified;
|
|
4371
|
+
if (utilization === void 0 && resetsAt === void 0 && status === void 0) {
|
|
4372
|
+
return void 0;
|
|
4373
|
+
}
|
|
4374
|
+
return { ...utilization === void 0 ? {} : { utilization }, ...resetsAt === void 0 ? {} : { resetsAt }, ...status === void 0 ? {} : { status } };
|
|
4375
|
+
}
|
|
4376
|
+
function soleOverageWindow(unified) {
|
|
4377
|
+
return unified.fiveHour === void 0 && unified.sevenDay === void 0 ? overageWindowOf(unified) : void 0;
|
|
4378
|
+
}
|
|
4342
4379
|
var MS_PER_SECOND2, UNIFIED_PREFIX;
|
|
4343
4380
|
var init_rateLimit = __esm({
|
|
4344
4381
|
"src/usage/rateLimit.ts"() {
|
|
@@ -4412,7 +4449,8 @@ function quotaWarnings(snapshot, provider, nowMs) {
|
|
|
4412
4449
|
const age = formatAge(nowMs - Date.parse(rateLimit.observedAt));
|
|
4413
4450
|
const windows = [
|
|
4414
4451
|
{ name: "five-hour", window: unified.fiveHour },
|
|
4415
|
-
{ name: "seven-day", window: unified.sevenDay }
|
|
4452
|
+
{ name: "seven-day", window: unified.sevenDay },
|
|
4453
|
+
{ name: "extra-usage", window: soleOverageWindow(unified) }
|
|
4416
4454
|
];
|
|
4417
4455
|
return windows.flatMap(({ name, window }) => {
|
|
4418
4456
|
const effective = window === void 0 ? void 0 : effectiveWindow(window, nowMs);
|
|
@@ -4428,6 +4466,7 @@ var MS_PER_SECOND3, SECONDS_PER_MINUTE, MINUTES_PER_HOUR, HOURS_PER_DAY, WARNING
|
|
|
4428
4466
|
var init_preflight = __esm({
|
|
4429
4467
|
"src/usage/preflight.ts"() {
|
|
4430
4468
|
"use strict";
|
|
4469
|
+
init_rateLimit();
|
|
4431
4470
|
MS_PER_SECOND3 = 1e3;
|
|
4432
4471
|
SECONDS_PER_MINUTE = 60;
|
|
4433
4472
|
MINUTES_PER_HOUR = 60;
|
|
@@ -4436,6 +4475,28 @@ var init_preflight = __esm({
|
|
|
4436
4475
|
}
|
|
4437
4476
|
});
|
|
4438
4477
|
|
|
4478
|
+
// src/usage/quotaFacts.ts
|
|
4479
|
+
function windowFacts(window, nowMs) {
|
|
4480
|
+
if (window?.utilization === void 0 || window.resetsAt === void 0) {
|
|
4481
|
+
return void 0;
|
|
4482
|
+
}
|
|
4483
|
+
return { remaining: Math.max(0, 1 - window.utilization), utilization: window.utilization, hoursUntilReset: Math.max(0, (Date.parse(window.resetsAt) - nowMs) / MS_PER_HOUR) };
|
|
4484
|
+
}
|
|
4485
|
+
function quotaFactsOf(unified, nowMs) {
|
|
4486
|
+
const fiveHour = windowFacts(unified?.fiveHour, nowMs);
|
|
4487
|
+
const sevenDay = windowFacts(unified?.sevenDay, nowMs);
|
|
4488
|
+
const extraUsage = windowFacts(unified === void 0 ? void 0 : soleOverageWindow(unified), nowMs);
|
|
4489
|
+
return { ...fiveHour === void 0 ? {} : { fiveHour }, ...sevenDay === void 0 ? {} : { sevenDay }, ...extraUsage === void 0 ? {} : { extraUsage } };
|
|
4490
|
+
}
|
|
4491
|
+
var MS_PER_HOUR;
|
|
4492
|
+
var init_quotaFacts = __esm({
|
|
4493
|
+
"src/usage/quotaFacts.ts"() {
|
|
4494
|
+
"use strict";
|
|
4495
|
+
init_rateLimit();
|
|
4496
|
+
MS_PER_HOUR = 36e5;
|
|
4497
|
+
}
|
|
4498
|
+
});
|
|
4499
|
+
|
|
4439
4500
|
// src/usage/pick.ts
|
|
4440
4501
|
function unifiedOf(state) {
|
|
4441
4502
|
return state?.rateLimit?.unified;
|
|
@@ -4530,18 +4591,22 @@ function assessIdentity(member, nowMs) {
|
|
|
4530
4591
|
...fiveHourWindow === void 0 || five === void 0 ? [] : [describeWindow("5h", fiveHourWindow, five, nowMs)],
|
|
4531
4592
|
...sevenDayWindow === void 0 || seven === void 0 ? [] : [describeWindow("7d", sevenDayWindow, seven, nowMs)]
|
|
4532
4593
|
];
|
|
4594
|
+
const overageWindow = soleOverageWindow(unified);
|
|
4595
|
+
const overage = overageWindow === void 0 ? void 0 : effectiveWindow(overageWindow, nowMs);
|
|
4596
|
+
const overageReasons = overageWindow === void 0 || overage === void 0 ? [] : [describeWindow("extra usage", overageWindow, overage, nowMs)];
|
|
4533
4597
|
const blockedUntil = Math.max(
|
|
4534
|
-
windowBlockedUntil([five, seven].flatMap((window) => window === void 0 ? [] : [window])) ?? 0,
|
|
4598
|
+
windowBlockedUntil([five, seven, overage].flatMap((window) => window === void 0 ? [] : [window])) ?? 0,
|
|
4535
4599
|
limitBlockedUntil(state, nowMs) ?? 0
|
|
4536
4600
|
);
|
|
4537
4601
|
if (blockedUntil > nowMs) {
|
|
4538
4602
|
if (unified.overageStatus === "allowed") {
|
|
4539
4603
|
return { candidate: { ...base, class: "pay-per-use", reasons: [`plan exhausted until ${new Date(blockedUntil).toISOString()}, continues as extra usage`, ...windowReasons, ...planReasons] } };
|
|
4540
4604
|
}
|
|
4541
|
-
return { candidate: { ...base, class: "ineligible", blockedUntilMs: blockedUntil, reasons: [`refused until ${new Date(blockedUntil).toISOString()} (in ${formatAge(blockedUntil - nowMs)})`, ...windowReasons, ...planReasons] } };
|
|
4605
|
+
return { candidate: { ...base, class: "ineligible", blockedUntilMs: blockedUntil, reasons: [`refused until ${new Date(blockedUntil).toISOString()} (in ${formatAge(blockedUntil - nowMs)})`, ...windowReasons, ...overageReasons, ...planReasons] } };
|
|
4542
4606
|
}
|
|
4543
4607
|
if (plan.kind === "pay-per-use" || fiveHourWindow === void 0 && sevenDayWindow === void 0) {
|
|
4544
|
-
|
|
4608
|
+
const headroom = overage?.utilization === void 0 ? void 0 : Math.max(0, 1 - overage.utilization);
|
|
4609
|
+
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
4610
|
}
|
|
4546
4611
|
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
4612
|
if (basis?.window.utilization === void 0) {
|
|
@@ -4549,7 +4614,7 @@ function assessIdentity(member, nowMs) {
|
|
|
4549
4614
|
}
|
|
4550
4615
|
const remaining = Math.max(0, 1 - basis.window.utilization);
|
|
4551
4616
|
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 /
|
|
4617
|
+
const score = remaining * plan.capacity / (untilResetMs / MS_PER_HOUR2);
|
|
4553
4618
|
const fiveRemaining = five?.utilization === void 0 ? void 0 : Math.max(0, 1 - five.utilization);
|
|
4554
4619
|
const fiveUntil = five?.resetsAtMs === void 0 ? FIVE_HOUR_WINDOW_MS : Math.max(five.resetsAtMs - nowMs, MS_PER_SECOND4);
|
|
4555
4620
|
const burn = windowBurn(member.records, "fiveHour");
|
|
@@ -4565,24 +4630,15 @@ function assessIdentity(member, nowMs) {
|
|
|
4565
4630
|
};
|
|
4566
4631
|
}
|
|
4567
4632
|
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
|
-
};
|
|
4633
|
+
const { fiveHour, sevenDay, extraUsage } = quotaFactsOf(member.snapshot?.providers[ANTHROPIC_PROVIDER]?.rateLimit?.unified, nowMs);
|
|
4579
4634
|
const burn = windowBurn(member.records, "fiveHour");
|
|
4580
4635
|
return {
|
|
4581
|
-
...
|
|
4582
|
-
...
|
|
4583
|
-
...
|
|
4636
|
+
...fiveHour === void 0 ? {} : { fiveHour },
|
|
4637
|
+
...sevenDay === void 0 ? {} : { sevenDay },
|
|
4638
|
+
...extraUsage === void 0 ? {} : { extraUsage },
|
|
4639
|
+
...burn === void 0 ? {} : { burnPerHour: burn * MS_PER_HOUR2 },
|
|
4584
4640
|
resuming,
|
|
4585
|
-
...sticky?.identity === member.identity ? { lastPickHoursAgo: Math.max(0, (nowMs - Date.parse(sticky.at)) /
|
|
4641
|
+
...sticky?.identity === member.identity ? { lastPickHoursAgo: Math.max(0, (nowMs - Date.parse(sticky.at)) / MS_PER_HOUR2) } : {}
|
|
4586
4642
|
};
|
|
4587
4643
|
}
|
|
4588
4644
|
function rankPool(input) {
|
|
@@ -4631,7 +4687,7 @@ function rankPool(input) {
|
|
|
4631
4687
|
return { ...candidate, feasible: false, reasons: [...drySpots, ...candidate.reasons] };
|
|
4632
4688
|
});
|
|
4633
4689
|
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)
|
|
4690
|
+
(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
4691
|
);
|
|
4636
4692
|
const sticky = input.sticky;
|
|
4637
4693
|
const stickyIndex = sticky === void 0 ? -1 : ordered.findIndex((candidate) => candidate.identity === sticky.identity);
|
|
@@ -4656,7 +4712,7 @@ function rankPool(input) {
|
|
|
4656
4712
|
...movedOff === void 0 || pick === void 0 ? {} : { movedOff }
|
|
4657
4713
|
};
|
|
4658
4714
|
}
|
|
4659
|
-
var MS_PER_SECOND4,
|
|
4715
|
+
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
4716
|
var init_pick = __esm({
|
|
4661
4717
|
"src/usage/pick.ts"() {
|
|
4662
4718
|
"use strict";
|
|
@@ -4664,17 +4720,18 @@ var init_pick = __esm({
|
|
|
4664
4720
|
init_plan2();
|
|
4665
4721
|
init_middleware();
|
|
4666
4722
|
init_preflight();
|
|
4723
|
+
init_quotaFacts();
|
|
4667
4724
|
init_rateLimit();
|
|
4668
4725
|
MS_PER_SECOND4 = 1e3;
|
|
4669
|
-
|
|
4726
|
+
MS_PER_HOUR2 = 36e5;
|
|
4670
4727
|
HOURS_PER_DAY2 = 24;
|
|
4671
4728
|
FIVE_HOURS = 5;
|
|
4672
4729
|
PROMPT_CACHE_TTL_HOURS = 1;
|
|
4673
4730
|
PERCENT = 100;
|
|
4674
4731
|
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 *
|
|
4732
|
+
FIVE_HOUR_WINDOW_MS = FIVE_HOURS * MS_PER_HOUR2;
|
|
4733
|
+
SEVEN_DAY_WINDOW_MS = SEVEN_DAYS * HOURS_PER_DAY2 * MS_PER_HOUR2;
|
|
4734
|
+
PROMPT_CACHE_TTL_MS = PROMPT_CACHE_TTL_HOURS * MS_PER_HOUR2;
|
|
4678
4735
|
CLASS_ORDER = { scored: 0, unknown: 1, "pay-per-use": 2, ineligible: 3 };
|
|
4679
4736
|
}
|
|
4680
4737
|
});
|
|
@@ -4895,8 +4952,9 @@ function createUsageStore(deps) {
|
|
|
4895
4952
|
recordRateLimit: (identity, provider, rateLimit) => rewriteSnapshot(identity, (current) => {
|
|
4896
4953
|
const state = current?.providers[provider] ?? {};
|
|
4897
4954
|
const keep = state.rateLimit !== void 0 && state.rateLimit.observedAt.localeCompare(rateLimit.observedAt) > 0;
|
|
4898
|
-
const
|
|
4899
|
-
const
|
|
4955
|
+
const earlier = state.rateLimit?.unified;
|
|
4956
|
+
const carried = rateLimit.unified === void 0 || rateLimit.unified.overageStatus !== void 0 || earlier === void 0 ? void 0 : overageFactsOf(earlier);
|
|
4957
|
+
const merged = carried === void 0 || rateLimit.unified === void 0 ? rateLimit : { ...rateLimit, unified: { ...rateLimit.unified, ...carried } };
|
|
4900
4958
|
return { ...current?.providers, [provider]: { ...state, rateLimit: keep ? state.rateLimit : merged } };
|
|
4901
4959
|
})
|
|
4902
4960
|
};
|
|
@@ -7360,7 +7418,8 @@ function unifiedFromReportedLimits(reported) {
|
|
|
7360
7418
|
return { ...fiveHour === void 0 ? {} : { fiveHour }, ...sevenDay === void 0 ? {} : { sevenDay } };
|
|
7361
7419
|
}
|
|
7362
7420
|
function isAnthropicUsageProbeable(member) {
|
|
7363
|
-
|
|
7421
|
+
const unified = member.snapshot?.providers[ANTHROPIC_PROVIDER]?.rateLimit?.unified;
|
|
7422
|
+
return planOf(member.account ?? member.snapshot?.account).kind === "subscription" && (unified === void 0 || soleOverageWindow(unified) === void 0);
|
|
7364
7423
|
}
|
|
7365
7424
|
function isAnthropicUsageStale(member, nowMs) {
|
|
7366
7425
|
const rateLimit = member.snapshot?.providers[ANTHROPIC_PROVIDER]?.rateLimit;
|
|
@@ -7446,6 +7505,7 @@ var init_anthropicUsageRefresh = __esm({
|
|
|
7446
7505
|
init_middleware();
|
|
7447
7506
|
init_pick();
|
|
7448
7507
|
init_plan2();
|
|
7508
|
+
init_rateLimit();
|
|
7449
7509
|
PERCENT2 = 100;
|
|
7450
7510
|
ANTHROPIC_USAGE_FRESHNESS_MS = FIVE_HOUR_WINDOW_MS / PERCENT2;
|
|
7451
7511
|
NO_PLAN_WINDOWS_FRESHNESS_MS = SEVEN_DAY_WINDOW_MS / PERCENT2;
|
|
@@ -7676,6 +7736,7 @@ __export(index_exports, {
|
|
|
7676
7736
|
OWN_CLI_FILE_NAME: () => OWN_CLI_FILE_NAME,
|
|
7677
7737
|
PROMPT_CACHE_TTL_MS: () => PROMPT_CACHE_TTL_MS,
|
|
7678
7738
|
PlanClassSchema: () => PlanClassSchema,
|
|
7739
|
+
PoolGraphError: () => PoolGraphError,
|
|
7679
7740
|
PoolNameSchema: () => PoolNameSchema,
|
|
7680
7741
|
PoolNotFoundError: () => PoolNotFoundError,
|
|
7681
7742
|
PoolPickReportSchema: () => PoolPickReportSchema,
|
|
@@ -13167,11 +13228,11 @@ function createDoorHealthPublisher(hub, now, pid) {
|
|
|
13167
13228
|
|
|
13168
13229
|
// src/frontdoor/quotaExpiringEvents.ts
|
|
13169
13230
|
init_schema2();
|
|
13170
|
-
var
|
|
13231
|
+
var MS_PER_HOUR3 = 36e5;
|
|
13171
13232
|
var MS_PER_DAY2 = 864e5;
|
|
13172
13233
|
var FIVE_HOUR_WINDOW_HOURS = 5;
|
|
13173
13234
|
var SEVEN_DAY_WINDOW_DAYS = 7;
|
|
13174
|
-
var FIVE_HOUR_WINDOW_MS2 = FIVE_HOUR_WINDOW_HOURS *
|
|
13235
|
+
var FIVE_HOUR_WINDOW_MS2 = FIVE_HOUR_WINDOW_HOURS * MS_PER_HOUR3;
|
|
13175
13236
|
var SEVEN_DAY_WINDOW_MS2 = SEVEN_DAY_WINDOW_DAYS * MS_PER_DAY2;
|
|
13176
13237
|
var FINAL_SPAN_DENOMINATOR = 30;
|
|
13177
13238
|
var QUOTA_EXPIRING_WINDOW_FRACTION = 1 / FINAL_SPAN_DENOMINATOR;
|
|
@@ -15214,6 +15275,7 @@ init_ownCli();
|
|
|
15214
15275
|
OWN_CLI_FILE_NAME,
|
|
15215
15276
|
PROMPT_CACHE_TTL_MS,
|
|
15216
15277
|
PlanClassSchema,
|
|
15278
|
+
PoolGraphError,
|
|
15217
15279
|
PoolNameSchema,
|
|
15218
15280
|
PoolNotFoundError,
|
|
15219
15281
|
PoolPickReportSchema,
|
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.
|
|
2628
|
+
version: "9.2.0",
|
|
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,
|
|
@@ -4304,15 +4316,40 @@ function parseUnifiedRateLimit(headers) {
|
|
|
4304
4316
|
const representativeClaim = headers[`${UNIFIED_PREFIX}representative-claim`];
|
|
4305
4317
|
const resetAt = epochSecondsToIso(headers[`${UNIFIED_PREFIX}reset`]);
|
|
4306
4318
|
const overageStatus = headers[`${UNIFIED_PREFIX}overage-status`];
|
|
4319
|
+
const overageUtilization = nonNegativeNumber(headers[`${UNIFIED_PREFIX}overage-utilization`]);
|
|
4320
|
+
const overageResetsAt = epochSecondsToIso(headers[`${UNIFIED_PREFIX}overage-reset`]);
|
|
4321
|
+
const overageDisabledReason = headers[`${UNIFIED_PREFIX}overage-disabled-reason`];
|
|
4307
4322
|
return {
|
|
4308
4323
|
...status === void 0 ? {} : { status },
|
|
4309
4324
|
...fiveHour === void 0 ? {} : { fiveHour },
|
|
4310
4325
|
...sevenDay === void 0 ? {} : { sevenDay },
|
|
4311
4326
|
...representativeClaim === void 0 ? {} : { representativeClaim },
|
|
4312
4327
|
...resetAt === void 0 ? {} : { resetAt },
|
|
4313
|
-
...overageStatus === void 0 ? {} : { overageStatus }
|
|
4328
|
+
...overageStatus === void 0 ? {} : { overageStatus },
|
|
4329
|
+
...overageUtilization === void 0 ? {} : { overageUtilization },
|
|
4330
|
+
...overageResetsAt === void 0 ? {} : { overageResetsAt },
|
|
4331
|
+
...overageDisabledReason === void 0 ? {} : { overageDisabledReason }
|
|
4314
4332
|
};
|
|
4315
4333
|
}
|
|
4334
|
+
function overageFactsOf(unified) {
|
|
4335
|
+
const { overageStatus, overageUtilization, overageResetsAt, overageDisabledReason } = unified;
|
|
4336
|
+
return {
|
|
4337
|
+
...overageStatus === void 0 ? {} : { overageStatus },
|
|
4338
|
+
...overageUtilization === void 0 ? {} : { overageUtilization },
|
|
4339
|
+
...overageResetsAt === void 0 ? {} : { overageResetsAt },
|
|
4340
|
+
...overageDisabledReason === void 0 ? {} : { overageDisabledReason }
|
|
4341
|
+
};
|
|
4342
|
+
}
|
|
4343
|
+
function overageWindowOf(unified) {
|
|
4344
|
+
const { overageUtilization: utilization, overageResetsAt: resetsAt, overageStatus: status } = unified;
|
|
4345
|
+
if (utilization === void 0 && resetsAt === void 0 && status === void 0) {
|
|
4346
|
+
return void 0;
|
|
4347
|
+
}
|
|
4348
|
+
return { ...utilization === void 0 ? {} : { utilization }, ...resetsAt === void 0 ? {} : { resetsAt }, ...status === void 0 ? {} : { status } };
|
|
4349
|
+
}
|
|
4350
|
+
function soleOverageWindow(unified) {
|
|
4351
|
+
return unified.fiveHour === void 0 && unified.sevenDay === void 0 ? overageWindowOf(unified) : void 0;
|
|
4352
|
+
}
|
|
4316
4353
|
var MS_PER_SECOND2, UNIFIED_PREFIX;
|
|
4317
4354
|
var init_rateLimit = __esm({
|
|
4318
4355
|
"src/usage/rateLimit.ts"() {
|
|
@@ -4386,7 +4423,8 @@ function quotaWarnings(snapshot, provider, nowMs) {
|
|
|
4386
4423
|
const age = formatAge(nowMs - Date.parse(rateLimit.observedAt));
|
|
4387
4424
|
const windows = [
|
|
4388
4425
|
{ name: "five-hour", window: unified.fiveHour },
|
|
4389
|
-
{ name: "seven-day", window: unified.sevenDay }
|
|
4426
|
+
{ name: "seven-day", window: unified.sevenDay },
|
|
4427
|
+
{ name: "extra-usage", window: soleOverageWindow(unified) }
|
|
4390
4428
|
];
|
|
4391
4429
|
return windows.flatMap(({ name, window }) => {
|
|
4392
4430
|
const effective = window === void 0 ? void 0 : effectiveWindow(window, nowMs);
|
|
@@ -4402,6 +4440,7 @@ var MS_PER_SECOND3, SECONDS_PER_MINUTE, MINUTES_PER_HOUR, HOURS_PER_DAY, WARNING
|
|
|
4402
4440
|
var init_preflight = __esm({
|
|
4403
4441
|
"src/usage/preflight.ts"() {
|
|
4404
4442
|
"use strict";
|
|
4443
|
+
init_rateLimit();
|
|
4405
4444
|
MS_PER_SECOND3 = 1e3;
|
|
4406
4445
|
SECONDS_PER_MINUTE = 60;
|
|
4407
4446
|
MINUTES_PER_HOUR = 60;
|
|
@@ -4410,6 +4449,28 @@ var init_preflight = __esm({
|
|
|
4410
4449
|
}
|
|
4411
4450
|
});
|
|
4412
4451
|
|
|
4452
|
+
// src/usage/quotaFacts.ts
|
|
4453
|
+
function windowFacts(window, nowMs) {
|
|
4454
|
+
if (window?.utilization === void 0 || window.resetsAt === void 0) {
|
|
4455
|
+
return void 0;
|
|
4456
|
+
}
|
|
4457
|
+
return { remaining: Math.max(0, 1 - window.utilization), utilization: window.utilization, hoursUntilReset: Math.max(0, (Date.parse(window.resetsAt) - nowMs) / MS_PER_HOUR) };
|
|
4458
|
+
}
|
|
4459
|
+
function quotaFactsOf(unified, nowMs) {
|
|
4460
|
+
const fiveHour = windowFacts(unified?.fiveHour, nowMs);
|
|
4461
|
+
const sevenDay = windowFacts(unified?.sevenDay, nowMs);
|
|
4462
|
+
const extraUsage = windowFacts(unified === void 0 ? void 0 : soleOverageWindow(unified), nowMs);
|
|
4463
|
+
return { ...fiveHour === void 0 ? {} : { fiveHour }, ...sevenDay === void 0 ? {} : { sevenDay }, ...extraUsage === void 0 ? {} : { extraUsage } };
|
|
4464
|
+
}
|
|
4465
|
+
var MS_PER_HOUR;
|
|
4466
|
+
var init_quotaFacts = __esm({
|
|
4467
|
+
"src/usage/quotaFacts.ts"() {
|
|
4468
|
+
"use strict";
|
|
4469
|
+
init_rateLimit();
|
|
4470
|
+
MS_PER_HOUR = 36e5;
|
|
4471
|
+
}
|
|
4472
|
+
});
|
|
4473
|
+
|
|
4413
4474
|
// src/usage/pick.ts
|
|
4414
4475
|
function unifiedOf(state) {
|
|
4415
4476
|
return state?.rateLimit?.unified;
|
|
@@ -4504,18 +4565,22 @@ function assessIdentity(member, nowMs) {
|
|
|
4504
4565
|
...fiveHourWindow === void 0 || five === void 0 ? [] : [describeWindow("5h", fiveHourWindow, five, nowMs)],
|
|
4505
4566
|
...sevenDayWindow === void 0 || seven === void 0 ? [] : [describeWindow("7d", sevenDayWindow, seven, nowMs)]
|
|
4506
4567
|
];
|
|
4568
|
+
const overageWindow = soleOverageWindow(unified);
|
|
4569
|
+
const overage = overageWindow === void 0 ? void 0 : effectiveWindow(overageWindow, nowMs);
|
|
4570
|
+
const overageReasons = overageWindow === void 0 || overage === void 0 ? [] : [describeWindow("extra usage", overageWindow, overage, nowMs)];
|
|
4507
4571
|
const blockedUntil = Math.max(
|
|
4508
|
-
windowBlockedUntil([five, seven].flatMap((window) => window === void 0 ? [] : [window])) ?? 0,
|
|
4572
|
+
windowBlockedUntil([five, seven, overage].flatMap((window) => window === void 0 ? [] : [window])) ?? 0,
|
|
4509
4573
|
limitBlockedUntil(state, nowMs) ?? 0
|
|
4510
4574
|
);
|
|
4511
4575
|
if (blockedUntil > nowMs) {
|
|
4512
4576
|
if (unified.overageStatus === "allowed") {
|
|
4513
4577
|
return { candidate: { ...base, class: "pay-per-use", reasons: [`plan exhausted until ${new Date(blockedUntil).toISOString()}, continues as extra usage`, ...windowReasons, ...planReasons] } };
|
|
4514
4578
|
}
|
|
4515
|
-
return { candidate: { ...base, class: "ineligible", blockedUntilMs: blockedUntil, reasons: [`refused until ${new Date(blockedUntil).toISOString()} (in ${formatAge(blockedUntil - nowMs)})`, ...windowReasons, ...planReasons] } };
|
|
4579
|
+
return { candidate: { ...base, class: "ineligible", blockedUntilMs: blockedUntil, reasons: [`refused until ${new Date(blockedUntil).toISOString()} (in ${formatAge(blockedUntil - nowMs)})`, ...windowReasons, ...overageReasons, ...planReasons] } };
|
|
4516
4580
|
}
|
|
4517
4581
|
if (plan.kind === "pay-per-use" || fiveHourWindow === void 0 && sevenDayWindow === void 0) {
|
|
4518
|
-
|
|
4582
|
+
const headroom = overage?.utilization === void 0 ? void 0 : Math.max(0, 1 - overage.utilization);
|
|
4583
|
+
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
4584
|
}
|
|
4520
4585
|
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
4586
|
if (basis?.window.utilization === void 0) {
|
|
@@ -4523,7 +4588,7 @@ function assessIdentity(member, nowMs) {
|
|
|
4523
4588
|
}
|
|
4524
4589
|
const remaining = Math.max(0, 1 - basis.window.utilization);
|
|
4525
4590
|
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 /
|
|
4591
|
+
const score = remaining * plan.capacity / (untilResetMs / MS_PER_HOUR2);
|
|
4527
4592
|
const fiveRemaining = five?.utilization === void 0 ? void 0 : Math.max(0, 1 - five.utilization);
|
|
4528
4593
|
const fiveUntil = five?.resetsAtMs === void 0 ? FIVE_HOUR_WINDOW_MS : Math.max(five.resetsAtMs - nowMs, MS_PER_SECOND4);
|
|
4529
4594
|
const burn = windowBurn(member.records, "fiveHour");
|
|
@@ -4539,24 +4604,15 @@ function assessIdentity(member, nowMs) {
|
|
|
4539
4604
|
};
|
|
4540
4605
|
}
|
|
4541
4606
|
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
|
-
};
|
|
4607
|
+
const { fiveHour, sevenDay, extraUsage } = quotaFactsOf(member.snapshot?.providers[ANTHROPIC_PROVIDER]?.rateLimit?.unified, nowMs);
|
|
4553
4608
|
const burn = windowBurn(member.records, "fiveHour");
|
|
4554
4609
|
return {
|
|
4555
|
-
...
|
|
4556
|
-
...
|
|
4557
|
-
...
|
|
4610
|
+
...fiveHour === void 0 ? {} : { fiveHour },
|
|
4611
|
+
...sevenDay === void 0 ? {} : { sevenDay },
|
|
4612
|
+
...extraUsage === void 0 ? {} : { extraUsage },
|
|
4613
|
+
...burn === void 0 ? {} : { burnPerHour: burn * MS_PER_HOUR2 },
|
|
4558
4614
|
resuming,
|
|
4559
|
-
...sticky?.identity === member.identity ? { lastPickHoursAgo: Math.max(0, (nowMs - Date.parse(sticky.at)) /
|
|
4615
|
+
...sticky?.identity === member.identity ? { lastPickHoursAgo: Math.max(0, (nowMs - Date.parse(sticky.at)) / MS_PER_HOUR2) } : {}
|
|
4560
4616
|
};
|
|
4561
4617
|
}
|
|
4562
4618
|
function rankPool(input) {
|
|
@@ -4605,7 +4661,7 @@ function rankPool(input) {
|
|
|
4605
4661
|
return { ...candidate, feasible: false, reasons: [...drySpots, ...candidate.reasons] };
|
|
4606
4662
|
});
|
|
4607
4663
|
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)
|
|
4664
|
+
(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
4665
|
);
|
|
4610
4666
|
const sticky = input.sticky;
|
|
4611
4667
|
const stickyIndex = sticky === void 0 ? -1 : ordered.findIndex((candidate) => candidate.identity === sticky.identity);
|
|
@@ -4630,7 +4686,7 @@ function rankPool(input) {
|
|
|
4630
4686
|
...movedOff === void 0 || pick === void 0 ? {} : { movedOff }
|
|
4631
4687
|
};
|
|
4632
4688
|
}
|
|
4633
|
-
var MS_PER_SECOND4,
|
|
4689
|
+
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
4690
|
var init_pick = __esm({
|
|
4635
4691
|
"src/usage/pick.ts"() {
|
|
4636
4692
|
"use strict";
|
|
@@ -4638,17 +4694,18 @@ var init_pick = __esm({
|
|
|
4638
4694
|
init_plan2();
|
|
4639
4695
|
init_middleware();
|
|
4640
4696
|
init_preflight();
|
|
4697
|
+
init_quotaFacts();
|
|
4641
4698
|
init_rateLimit();
|
|
4642
4699
|
MS_PER_SECOND4 = 1e3;
|
|
4643
|
-
|
|
4700
|
+
MS_PER_HOUR2 = 36e5;
|
|
4644
4701
|
HOURS_PER_DAY2 = 24;
|
|
4645
4702
|
FIVE_HOURS = 5;
|
|
4646
4703
|
PROMPT_CACHE_TTL_HOURS = 1;
|
|
4647
4704
|
PERCENT = 100;
|
|
4648
4705
|
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 *
|
|
4706
|
+
FIVE_HOUR_WINDOW_MS = FIVE_HOURS * MS_PER_HOUR2;
|
|
4707
|
+
SEVEN_DAY_WINDOW_MS = SEVEN_DAYS * HOURS_PER_DAY2 * MS_PER_HOUR2;
|
|
4708
|
+
PROMPT_CACHE_TTL_MS = PROMPT_CACHE_TTL_HOURS * MS_PER_HOUR2;
|
|
4652
4709
|
CLASS_ORDER = { scored: 0, unknown: 1, "pay-per-use": 2, ineligible: 3 };
|
|
4653
4710
|
}
|
|
4654
4711
|
});
|
|
@@ -4870,8 +4927,9 @@ function createUsageStore(deps) {
|
|
|
4870
4927
|
recordRateLimit: (identity, provider, rateLimit) => rewriteSnapshot(identity, (current) => {
|
|
4871
4928
|
const state = current?.providers[provider] ?? {};
|
|
4872
4929
|
const keep = state.rateLimit !== void 0 && state.rateLimit.observedAt.localeCompare(rateLimit.observedAt) > 0;
|
|
4873
|
-
const
|
|
4874
|
-
const
|
|
4930
|
+
const earlier = state.rateLimit?.unified;
|
|
4931
|
+
const carried = rateLimit.unified === void 0 || rateLimit.unified.overageStatus !== void 0 || earlier === void 0 ? void 0 : overageFactsOf(earlier);
|
|
4932
|
+
const merged = carried === void 0 || rateLimit.unified === void 0 ? rateLimit : { ...rateLimit, unified: { ...rateLimit.unified, ...carried } };
|
|
4875
4933
|
return { ...current?.providers, [provider]: { ...state, rateLimit: keep ? state.rateLimit : merged } };
|
|
4876
4934
|
})
|
|
4877
4935
|
};
|
|
@@ -7332,7 +7390,8 @@ function unifiedFromReportedLimits(reported) {
|
|
|
7332
7390
|
return { ...fiveHour === void 0 ? {} : { fiveHour }, ...sevenDay === void 0 ? {} : { sevenDay } };
|
|
7333
7391
|
}
|
|
7334
7392
|
function isAnthropicUsageProbeable(member) {
|
|
7335
|
-
|
|
7393
|
+
const unified = member.snapshot?.providers[ANTHROPIC_PROVIDER]?.rateLimit?.unified;
|
|
7394
|
+
return planOf(member.account ?? member.snapshot?.account).kind === "subscription" && (unified === void 0 || soleOverageWindow(unified) === void 0);
|
|
7336
7395
|
}
|
|
7337
7396
|
function isAnthropicUsageStale(member, nowMs) {
|
|
7338
7397
|
const rateLimit = member.snapshot?.providers[ANTHROPIC_PROVIDER]?.rateLimit;
|
|
@@ -7418,6 +7477,7 @@ var init_anthropicUsageRefresh = __esm({
|
|
|
7418
7477
|
init_middleware();
|
|
7419
7478
|
init_pick();
|
|
7420
7479
|
init_plan2();
|
|
7480
|
+
init_rateLimit();
|
|
7421
7481
|
PERCENT2 = 100;
|
|
7422
7482
|
ANTHROPIC_USAGE_FRESHNESS_MS = FIVE_HOUR_WINDOW_MS / PERCENT2;
|
|
7423
7483
|
NO_PLAN_WINDOWS_FRESHNESS_MS = SEVEN_DAY_WINDOW_MS / PERCENT2;
|
|
@@ -12843,11 +12903,11 @@ function createDoorHealthPublisher(hub, now, pid) {
|
|
|
12843
12903
|
|
|
12844
12904
|
// src/frontdoor/quotaExpiringEvents.ts
|
|
12845
12905
|
init_schema2();
|
|
12846
|
-
var
|
|
12906
|
+
var MS_PER_HOUR3 = 36e5;
|
|
12847
12907
|
var MS_PER_DAY2 = 864e5;
|
|
12848
12908
|
var FIVE_HOUR_WINDOW_HOURS = 5;
|
|
12849
12909
|
var SEVEN_DAY_WINDOW_DAYS = 7;
|
|
12850
|
-
var FIVE_HOUR_WINDOW_MS2 = FIVE_HOUR_WINDOW_HOURS *
|
|
12910
|
+
var FIVE_HOUR_WINDOW_MS2 = FIVE_HOUR_WINDOW_HOURS * MS_PER_HOUR3;
|
|
12851
12911
|
var SEVEN_DAY_WINDOW_MS2 = SEVEN_DAY_WINDOW_DAYS * MS_PER_DAY2;
|
|
12852
12912
|
var FINAL_SPAN_DENOMINATOR = 30;
|
|
12853
12913
|
var QUOTA_EXPIRING_WINDOW_FRACTION = 1 / FINAL_SPAN_DENOMINATOR;
|
|
@@ -14889,6 +14949,7 @@ export {
|
|
|
14889
14949
|
OWN_CLI_FILE_NAME,
|
|
14890
14950
|
PROMPT_CACHE_TTL_MS,
|
|
14891
14951
|
PlanClassSchema,
|
|
14952
|
+
PoolGraphError,
|
|
14892
14953
|
PoolNameSchema,
|
|
14893
14954
|
PoolNotFoundError,
|
|
14894
14955
|
PoolPickReportSchema,
|