@cortexkit/anthropic-auth-core 2.15.0 → 2.15.2
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/holder-registry.d.ts +10 -0
- package/dist/index.js +88 -15
- package/dist/layout-fence.d.ts +2 -2
- package/dist/sticky-routing.d.ts +15 -1
- package/package.json +2 -2
|
@@ -105,12 +105,22 @@ export interface HolderLiveness {
|
|
|
105
105
|
pidAlive(pid: number): boolean;
|
|
106
106
|
/** Undefined or null when it can't be read. */
|
|
107
107
|
incarnation(pid: number): Promise<string | null>;
|
|
108
|
+
/** Wall-clock process start, when the OS can report it. */
|
|
109
|
+
processStartedAtMs?(pid: number): Promise<number | null>;
|
|
108
110
|
/** Wall clock and OS uptime; tests replace both. */
|
|
109
111
|
now?(): number;
|
|
110
112
|
uptime?(): number;
|
|
111
113
|
}
|
|
112
114
|
/** The OS's fixed per-process value for `pid`, or null when none is read. */
|
|
113
115
|
export declare function processIncarnation(pid: number): Promise<string | null>;
|
|
116
|
+
/** OS reads used to obtain a wall-clock process start; tests supply fixtures. */
|
|
117
|
+
export interface ProcessStartReads {
|
|
118
|
+
platform: NodeJS.Platform;
|
|
119
|
+
readFile(path: string): Promise<string>;
|
|
120
|
+
exec(file: string, args: string[]): Promise<string>;
|
|
121
|
+
}
|
|
122
|
+
/** Wall-clock process start, or null if the OS cannot safely report it. */
|
|
123
|
+
export declare function processStartedAtMs(pid: number, reads?: ProcessStartReads): Promise<number | null>;
|
|
114
124
|
/**
|
|
115
125
|
* A process recorded before this boot cannot still be running, even if its
|
|
116
126
|
* pid is alive again. Keep a five-minute margin for clock imprecision, and
|
package/dist/index.js
CHANGED
|
@@ -95,7 +95,7 @@ var VAULT_FAILURE_CLASSES = Object.freeze({
|
|
|
95
95
|
class ClaustrumUnreachableError extends ClaustrumConsumerError {
|
|
96
96
|
reason;
|
|
97
97
|
constructor(reason) {
|
|
98
|
-
super("unavailable", "Claustrum
|
|
98
|
+
super("unavailable", "Claustrum vault could not be reached");
|
|
99
99
|
this.name = "ClaustrumUnreachableError";
|
|
100
100
|
if (reason === "host-accessor-missing" || reason === "host-accessor-failed")
|
|
101
101
|
this.reason = reason;
|
|
@@ -693,7 +693,9 @@ function ioCode(detail) {
|
|
|
693
693
|
var backend;
|
|
694
694
|
var PRIVATE_FILES_UNAVAILABLE_REASON = "native-addon-unavailable";
|
|
695
695
|
function privateFilesUnavailable(cause) {
|
|
696
|
-
return Object.assign(new Error("Windows private-files native addon
|
|
696
|
+
return Object.assign(new Error("Windows private-files native addon could not be loaded", {
|
|
697
|
+
cause
|
|
698
|
+
}), {
|
|
697
699
|
code: "ERR_PRIVATE_FILES_UNAVAILABLE",
|
|
698
700
|
reason: PRIVATE_FILES_UNAVAILABLE_REASON
|
|
699
701
|
});
|
|
@@ -3909,7 +3911,7 @@ class ClaustrumScopedCustody {
|
|
|
3909
3911
|
throw error;
|
|
3910
3912
|
if (classifyVaultFailure(error) === "unreachable")
|
|
3911
3913
|
throw new ClaustrumUnreachableError(error instanceof ClaustrumUnreachableError ? error.reason : undefined);
|
|
3912
|
-
throw new ClaustrumConsumerError("unavailable", "Claustrum scoped operation
|
|
3914
|
+
throw new ClaustrumConsumerError("unavailable", "Claustrum scoped operation failed");
|
|
3913
3915
|
} finally {
|
|
3914
3916
|
removeAbortListener?.();
|
|
3915
3917
|
}
|
|
@@ -29414,7 +29416,9 @@ function createQuotaRefusalResponse(reason, timing, now = Date.now(), options =
|
|
|
29414
29416
|
}).format(timing.resetAt);
|
|
29415
29417
|
const remaining = timing.resetAt === undefined ? 0 : Math.max(0, timing.resetAt - now);
|
|
29416
29418
|
const duration = remaining >= 3600000 ? `${Math.ceil(remaining / 3600000)} h` : `${Math.ceil(remaining / 60000)} min`;
|
|
29417
|
-
const
|
|
29419
|
+
const room = timing.limitName ? `No Claude account has room for this request (${timing.limitName} limit or your quota floor). ` : "";
|
|
29420
|
+
const manualAction = resetTime ? `The earliest reset is ${resetTime} UTC (in ${duration}). Send the message again after ${resetTime} UTC.` : "Reset time is unknown. Check account availability before sending the message again.";
|
|
29421
|
+
const message = options.retry === "manual" || seconds === undefined ? `${room}This turn has stopped. ${manualAction} ${reason}` : timing.limitName && resetTime ? `${room}The earliest reset is ${resetTime} UTC (in ${duration}). Retrying every ${retryMinutes(seconds)}. ${reason}` : `${reason}${retry} ${reset}`;
|
|
29418
29422
|
const response = new Response(JSON.stringify({
|
|
29419
29423
|
type: "error",
|
|
29420
29424
|
error: {
|
|
@@ -29747,6 +29751,13 @@ function stickyQuotaEvidence(input) {
|
|
|
29747
29751
|
return reading2 || confirmed && Object.keys(confirmed).length ? { ...reading2, ...confirmed } : undefined;
|
|
29748
29752
|
}
|
|
29749
29753
|
function stickyQuotaExhaustionInForce(input) {
|
|
29754
|
+
const blocker = quotaBlockerInForce(input, false);
|
|
29755
|
+
return blocker?.resetAt === undefined ? undefined : { ...blocker, resetAt: blocker.resetAt };
|
|
29756
|
+
}
|
|
29757
|
+
function stickyQuotaBlockerInForce(input) {
|
|
29758
|
+
return quotaBlockerInForce(input, true);
|
|
29759
|
+
}
|
|
29760
|
+
function quotaBlockerInForce(input, includeUnknown) {
|
|
29750
29761
|
const now = input.now ?? Date.now();
|
|
29751
29762
|
const quota2 = stickyQuotaEvidence({
|
|
29752
29763
|
quota: input.quota,
|
|
@@ -29759,6 +29770,7 @@ function stickyQuotaExhaustionInForce(input) {
|
|
|
29759
29770
|
return;
|
|
29760
29771
|
const scoped = getScopedQuotaWindowForModel(quota2, input.modelId);
|
|
29761
29772
|
let blocking;
|
|
29773
|
+
let unknown;
|
|
29762
29774
|
for (const [reason, limitName, window2] of [
|
|
29763
29775
|
["model-scoped", `${scoped?.modelName ?? "Model"} weekly`, scoped],
|
|
29764
29776
|
["seven-day", "weekly", quota2.seven_day],
|
|
@@ -29767,19 +29779,24 @@ function stickyQuotaExhaustionInForce(input) {
|
|
|
29767
29779
|
if (!window2 || !Number.isFinite(window2.remainingPercent) || window2.remainingPercent > 0)
|
|
29768
29780
|
continue;
|
|
29769
29781
|
const resetAt = window2.resetsAt ? Date.parse(window2.resetsAt) : NaN;
|
|
29770
|
-
if (!Number.isFinite(resetAt)
|
|
29782
|
+
if (!Number.isFinite(resetAt)) {
|
|
29783
|
+
if (includeUnknown)
|
|
29784
|
+
unknown = { reason, limitName };
|
|
29785
|
+
continue;
|
|
29786
|
+
}
|
|
29787
|
+
if (resetAt <= now)
|
|
29771
29788
|
continue;
|
|
29772
29789
|
if (!blocking || resetAt > blocking.resetAt)
|
|
29773
29790
|
blocking = { resetAt, reason, limitName };
|
|
29774
29791
|
}
|
|
29775
|
-
return blocking;
|
|
29792
|
+
return unknown ?? blocking;
|
|
29776
29793
|
}
|
|
29777
29794
|
function createExhaustedNoRouteResponse(input) {
|
|
29778
29795
|
const now = input.now ?? Date.now();
|
|
29779
|
-
const earliest =
|
|
29796
|
+
const earliest = input.exhausted.filter((row) => row.resetAt !== undefined).sort((a, b) => a.resetAt - b.resetAt)[0];
|
|
29780
29797
|
return createQuotaRefusalResponse("Claude reports every account that could take this request as out of quota.", {
|
|
29781
29798
|
resetAt: earliest?.resetAt,
|
|
29782
|
-
|
|
29799
|
+
limitName: earliest?.limitName ?? input.exhausted[0]?.limitName,
|
|
29783
29800
|
retryAfterSeconds: quotaRefusalRetryAfterSeconds({
|
|
29784
29801
|
resetAt: earliest?.resetAt,
|
|
29785
29802
|
storage: input.storage,
|
|
@@ -31293,6 +31310,55 @@ function processIncarnation(pid) {
|
|
|
31293
31310
|
return macosIncarnation(pid);
|
|
31294
31311
|
return Promise.resolve(null);
|
|
31295
31312
|
}
|
|
31313
|
+
var processStartReads = {
|
|
31314
|
+
platform: process.platform,
|
|
31315
|
+
readFile: (path2) => readFile14(path2, "utf8"),
|
|
31316
|
+
exec: (file, args) => new Promise((resolve18, reject) => {
|
|
31317
|
+
execFile2(file, args, { env: { ...process.env, TZ: "UTC0", LC_ALL: "C" }, timeout: 5000 }, (error, stdout) => error ? reject(error) : resolve18(String(stdout)));
|
|
31318
|
+
})
|
|
31319
|
+
};
|
|
31320
|
+
var clockTicks;
|
|
31321
|
+
async function processStartedAtMs(pid, reads = processStartReads) {
|
|
31322
|
+
if (!Number.isSafeInteger(pid) || pid <= 0)
|
|
31323
|
+
return null;
|
|
31324
|
+
try {
|
|
31325
|
+
if (reads.platform === "darwin") {
|
|
31326
|
+
const text5 = (await reads.exec("ps", ["-o", "lstart=", "-p", String(pid)])).trim();
|
|
31327
|
+
if (!/^\w{3}\s+\w{3}\s+\d{1,2}\s+\d{2}:\d{2}:\d{2}\s+\d{4}$/.test(text5))
|
|
31328
|
+
return null;
|
|
31329
|
+
const start2 = Date.parse(`${text5} GMT`);
|
|
31330
|
+
return Number.isFinite(start2) && start2 >= 0 ? start2 : null;
|
|
31331
|
+
}
|
|
31332
|
+
if (reads.platform !== "linux")
|
|
31333
|
+
return null;
|
|
31334
|
+
const getTicks = async () => {
|
|
31335
|
+
try {
|
|
31336
|
+
const ticks2 = Number((await reads.exec("getconf", ["CLK_TCK"])).trim());
|
|
31337
|
+
if (Number.isFinite(ticks2) && ticks2 > 0)
|
|
31338
|
+
return ticks2;
|
|
31339
|
+
} catch {}
|
|
31340
|
+
return 100;
|
|
31341
|
+
};
|
|
31342
|
+
let ticks;
|
|
31343
|
+
if (reads === processStartReads) {
|
|
31344
|
+
clockTicks ??= getTicks();
|
|
31345
|
+
ticks = await clockTicks;
|
|
31346
|
+
} else
|
|
31347
|
+
ticks = await getTicks();
|
|
31348
|
+
const stat13 = await reads.readFile(`/proc/${pid}/stat`);
|
|
31349
|
+
const end = stat13.lastIndexOf(")");
|
|
31350
|
+
if (end < 0)
|
|
31351
|
+
return null;
|
|
31352
|
+
const startTicks = stat13.slice(end + 1).trim().split(/\s+/)[19];
|
|
31353
|
+
const boot = /^btime\s+(\d+)\s*$/m.exec(await reads.readFile("/proc/stat"))?.[1];
|
|
31354
|
+
if (!startTicks || !/^\d+$/.test(startTicks) || !boot)
|
|
31355
|
+
return null;
|
|
31356
|
+
const start = Number(boot) * 1000 + Number(startTicks) / ticks * 1000;
|
|
31357
|
+
return Number.isFinite(start) && start >= 0 ? start : null;
|
|
31358
|
+
} catch {
|
|
31359
|
+
return null;
|
|
31360
|
+
}
|
|
31361
|
+
}
|
|
31296
31362
|
var defaultLiveness = {
|
|
31297
31363
|
pidAlive,
|
|
31298
31364
|
incarnation: processIncarnation
|
|
@@ -49897,7 +49963,7 @@ async function readArtifact(path2, blockers, malformedIsStale) {
|
|
|
49897
49963
|
} catch (error) {
|
|
49898
49964
|
if (errorCode5(error) === "ENOENT")
|
|
49899
49965
|
return;
|
|
49900
|
-
if (!malformedIsStale())
|
|
49966
|
+
if (!await malformedIsStale())
|
|
49901
49967
|
blockers.push({ kind: "artifact-scan", path: path2, reason: reasonOf(error) });
|
|
49902
49968
|
return;
|
|
49903
49969
|
}
|
|
@@ -49906,20 +49972,25 @@ async function readArtifact(path2, blockers, malformedIsStale) {
|
|
|
49906
49972
|
const startedAt = typeof value === "object" && value !== null ? "startedAt" in value ? value.startedAt : ("registeredAt" in value) ? value.registeredAt : mtimeMs : mtimeMs;
|
|
49907
49973
|
return { value, startedAt, regular };
|
|
49908
49974
|
} catch {
|
|
49909
|
-
if (!malformedIsStale(regular ? mtimeMs : undefined))
|
|
49975
|
+
if (!await malformedIsStale(regular ? mtimeMs : undefined))
|
|
49910
49976
|
blockers.push({ kind: "artifact-scan", path: path2, reason: "invalid" });
|
|
49911
49977
|
return;
|
|
49912
49978
|
}
|
|
49913
49979
|
}
|
|
49914
49980
|
async function preNArtifactBlockers(locations, pidAlive2 = defaultLiveness2.pidAlive, clock = {}, acceptsRelease) {
|
|
49915
49981
|
const exempt = (value) => stamped(value) && (!acceptsRelease || acceptsRelease(value.writer.release));
|
|
49916
|
-
const malformedIsStale = (pid, startedAt) => {
|
|
49982
|
+
const malformedIsStale = async (pid, startedAt) => {
|
|
49917
49983
|
if (pid === undefined)
|
|
49918
49984
|
return false;
|
|
49919
49985
|
if (recordPredatesBoot(startedAt, clock))
|
|
49920
49986
|
return true;
|
|
49921
49987
|
try {
|
|
49922
|
-
|
|
49988
|
+
if (!pidAlive2(pid))
|
|
49989
|
+
return true;
|
|
49990
|
+
if (typeof startedAt !== "number" || !Number.isFinite(startedAt) || startedAt < 0 || startedAt > (clock.now ?? Date.now)())
|
|
49991
|
+
return false;
|
|
49992
|
+
const start = await (clock.processStartedAtMs ?? processStartedAtMs)(pid);
|
|
49993
|
+
return start !== null && Number.isFinite(start) && start > startedAt + 2000;
|
|
49923
49994
|
} catch {
|
|
49924
49995
|
return false;
|
|
49925
49996
|
}
|
|
@@ -49942,11 +50013,11 @@ async function preNArtifactBlockers(locations, pidAlive2 = defaultLiveness2.pidA
|
|
|
49942
50013
|
const { value, startedAt } = record17;
|
|
49943
50014
|
const pid = value?.pid;
|
|
49944
50015
|
if (typeof pid !== "number" || !Number.isSafeInteger(pid) || pid <= 0) {
|
|
49945
|
-
if (!isStale(record17.regular ? startedAt : undefined))
|
|
50016
|
+
if (!await isStale(record17.regular ? startedAt : undefined))
|
|
49946
50017
|
blockers.push({ kind: "artifact-scan", path: path2, reason: "invalid" });
|
|
49947
50018
|
continue;
|
|
49948
50019
|
}
|
|
49949
|
-
if (!
|
|
50020
|
+
if (!await malformedIsStale(pid, record17.regular ? startedAt : undefined))
|
|
49950
50021
|
blockers.push({ kind: "pre-n-artifact", artifact: path2, pid });
|
|
49951
50022
|
}
|
|
49952
50023
|
}
|
|
@@ -49961,7 +50032,7 @@ async function preNArtifactBlockers(locations, pidAlive2 = defaultLiveness2.pidA
|
|
|
49961
50032
|
if (record17 === undefined || exempt(record17.value))
|
|
49962
50033
|
continue;
|
|
49963
50034
|
const pid = Number(match[1]);
|
|
49964
|
-
if (!
|
|
50035
|
+
if (!await malformedIsStale(pid, record17.regular ? record17.startedAt : undefined))
|
|
49965
50036
|
blockers.push({ kind: "pre-n-artifact", artifact: path2, pid });
|
|
49966
50037
|
}
|
|
49967
50038
|
}
|
|
@@ -53035,6 +53106,7 @@ export {
|
|
|
53035
53106
|
stickyRetainRetryHeaders,
|
|
53036
53107
|
stickyQuotaSnapshotIsFresh,
|
|
53037
53108
|
stickyQuotaExhaustionInForce,
|
|
53109
|
+
stickyQuotaBlockerInForce,
|
|
53038
53110
|
stateSubfolderName,
|
|
53039
53111
|
stateRefusalPublicMessage,
|
|
53040
53112
|
stateRefusalCause,
|
|
@@ -53178,6 +53250,7 @@ export {
|
|
|
53178
53250
|
publishNativeEmptyInit,
|
|
53179
53251
|
publishHolderEntryLocked,
|
|
53180
53252
|
processStateLayout,
|
|
53253
|
+
processStartedAtMs,
|
|
53181
53254
|
processIncarnation,
|
|
53182
53255
|
primeStorageFingerprint,
|
|
53183
53256
|
primeMarkerPath,
|
package/dist/layout-fence.d.ts
CHANGED
|
@@ -58,11 +58,11 @@ export declare function defaultPreNArtifactLocations(env?: NodeJS.ProcessEnv, ho
|
|
|
58
58
|
* The fence's check for older versions: an RPC port file or CacheKeep record without the
|
|
59
59
|
* `writer` stamp, whose pid is alive, belongs to a version that registers
|
|
60
60
|
* nothing and blocks. Unreadable or malformed publisher-owned files need a
|
|
61
|
-
* proven dead filename pid, or a readable regular file's pre-boot mtime.
|
|
61
|
+
* proven dead or reused filename pid, or a readable regular file's pre-boot mtime.
|
|
62
62
|
* Other scan failures block. A record from before this boot is stale even
|
|
63
63
|
* if its pid has been reused; missing or untrustworthy times keep blocking.
|
|
64
64
|
*/
|
|
65
|
-
export declare function preNArtifactBlockers(locations: PreNArtifactLocations, pidAlive?: (pid: number) => boolean, clock?: Pick<HolderLiveness, 'now' | 'uptime'>,
|
|
65
|
+
export declare function preNArtifactBlockers(locations: PreNArtifactLocations, pidAlive?: (pid: number) => boolean, clock?: Pick<HolderLiveness, 'now' | 'uptime' | 'processStartedAtMs'>,
|
|
66
66
|
/**
|
|
67
67
|
* When set, a stamped artifact counts as older too unless this accepts its
|
|
68
68
|
* `writer.release`: its writer may be a release below a later fence's
|
package/dist/sticky-routing.d.ts
CHANGED
|
@@ -141,13 +141,27 @@ export declare function stickyQuotaExhaustionInForce(input: {
|
|
|
141
141
|
modelId?: string;
|
|
142
142
|
now?: number;
|
|
143
143
|
}): StickyQuotaExhaustion | undefined;
|
|
144
|
+
export type StickyQuotaBlocker = Omit<StickyQuotaExhaustion, 'resetAt'> & {
|
|
145
|
+
readonly resetAt?: number;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Like stickyQuotaExhaustionInForce, but also report confirmed exhaustion whose
|
|
149
|
+
* reset time is unknown. Callers use it to stop a turn: without a known reset
|
|
150
|
+
* there is nothing to wait for, so the host is not asked to retry later.
|
|
151
|
+
*/
|
|
152
|
+
export declare function stickyQuotaBlockerInForce(input: {
|
|
153
|
+
quota: OAuthQuotaSnapshot | QuotaState | undefined;
|
|
154
|
+
responseHeaders?: Headers;
|
|
155
|
+
modelId?: string;
|
|
156
|
+
now?: number;
|
|
157
|
+
}): StickyQuotaBlocker | undefined;
|
|
144
158
|
/**
|
|
145
159
|
* The quota refusal for a request that no account can take because every
|
|
146
160
|
* account that could is confirmed exhausted (see `stickyQuotaExhaustionInForce`).
|
|
147
161
|
* It names the window that resets first across those accounts.
|
|
148
162
|
*/
|
|
149
163
|
export declare function createExhaustedNoRouteResponse(input: {
|
|
150
|
-
exhausted: readonly
|
|
164
|
+
exhausted: readonly StickyQuotaBlocker[];
|
|
151
165
|
storage?: AccountStorage | null;
|
|
152
166
|
sessionId?: string | null;
|
|
153
167
|
now?: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/anthropic-auth-core",
|
|
3
|
-
"version": "2.15.
|
|
3
|
+
"version": "2.15.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"prepublishOnly": "bun run build"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@cortexkit/common-auth": "0.52.
|
|
34
|
+
"@cortexkit/common-auth": "0.52.1"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@cortexkit/claustrum-client": "0.18.0",
|