@cortexkit/anthropic-auth-core 2.10.0 → 2.11.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/billing.d.ts +7 -0
- package/dist/cachekeep.d.ts +18 -2
- package/dist/constants.d.ts +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +487 -112
- package/dist/internal-types/commands/builtins.d.ts +20 -1
- package/dist/internal-types/commands/index.d.ts +1 -1
- package/dist/internal-types/commands/menu.d.ts +6 -1
- package/dist/internal-types/fs/refresh-file-lock.d.ts +11 -0
- package/dist/internal-types/fs/with-lock.d.ts +2 -0
- package/dist/internal-types/routing-accessor/index.d.ts +33 -5
- package/dist/internal-types/setup/command-error.d.ts +1 -1
- package/dist/internal-types/setup/types.d.ts +4 -0
- package/dist/routing-relay.d.ts +36 -0
- package/dist/routing-reports.d.ts +7 -0
- package/dist/sticky-routing.d.ts +2 -0
- package/dist/stream-completion.d.ts +3 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1343,16 +1343,16 @@ import { ClaustrumCredentialError as ClaustrumCredentialError5 } from "@cortexki
|
|
|
1343
1343
|
// ../../node_modules/@cortexkit/common-auth/dist/claustrum/enrollment.js
|
|
1344
1344
|
import { createHash, randomBytes, randomUUID as randomUUID4 } from "node:crypto";
|
|
1345
1345
|
import { constants as fsConstants } from "node:fs";
|
|
1346
|
-
import { chmod, mkdir as mkdir3, open as open4, readFile as readFile3, realpath, rename as rename4, stat as stat3, unlink as
|
|
1347
|
-
import { basename, dirname as dirname5, extname, isAbsolute, join as join4, resolve as resolve7 } from "node:path";
|
|
1346
|
+
import { chmod, mkdir as mkdir3, open as open4, readFile as readFile3, realpath, rename as rename4, stat as stat3, unlink as unlink3 } from "node:fs/promises";
|
|
1347
|
+
import { basename as basename2, dirname as dirname5, extname, isAbsolute, join as join4, resolve as resolve7 } from "node:path";
|
|
1348
1348
|
import { ClaustrumCredentialError as ClaustrumCredentialError3, ClaustrumClient as ClaustrumWireClient, writeEnrollmentTokenFile } from "@cortexkit/claustrum-client";
|
|
1349
1349
|
|
|
1350
1350
|
// ../../node_modules/@cortexkit/common-auth/dist/fs/file-read-cache.js
|
|
1351
1351
|
import { lstat as lstat2, stat } from "node:fs/promises";
|
|
1352
1352
|
import { resolve as resolve4 } from "node:path";
|
|
1353
|
-
async function identity(path,
|
|
1353
|
+
async function identity(path, probe) {
|
|
1354
1354
|
try {
|
|
1355
|
-
const metadata = await (
|
|
1355
|
+
const metadata = await probe(path);
|
|
1356
1356
|
return metadata.isFile() ? metadata : undefined;
|
|
1357
1357
|
} catch (error) {
|
|
1358
1358
|
return error.code === "ENOENT" ? "absent" : undefined;
|
|
@@ -1365,15 +1365,15 @@ function sameIdentity(left, right) {
|
|
|
1365
1365
|
}
|
|
1366
1366
|
|
|
1367
1367
|
class FileReadCache {
|
|
1368
|
-
#
|
|
1368
|
+
#probe;
|
|
1369
1369
|
#entries = new Map;
|
|
1370
1370
|
constructor(options = {}) {
|
|
1371
|
-
this.#
|
|
1371
|
+
this.#probe = options.followSymlinks ? (path) => (options.stat ?? stat)(path) : (path) => (options.lstat ?? lstat2)(path);
|
|
1372
1372
|
}
|
|
1373
1373
|
async read(paths, read, validateHit) {
|
|
1374
1374
|
const resolvedPaths = paths.map((path) => resolve4(path));
|
|
1375
1375
|
const key = JSON.stringify(resolvedPaths);
|
|
1376
|
-
const probed = await Promise.all(resolvedPaths.map((path) => identity(path, this.#
|
|
1376
|
+
const probed = await Promise.all(resolvedPaths.map((path) => identity(path, this.#probe)));
|
|
1377
1377
|
const identities = probed.every((entry) => entry !== undefined) ? probed : undefined;
|
|
1378
1378
|
const cached = this.#entries.get(key);
|
|
1379
1379
|
if (identities && cached && identities.every((entry, index) => {
|
|
@@ -1500,8 +1500,8 @@ var WRITER_LOCK_CONSTANTS = Object.freeze({
|
|
|
1500
1500
|
});
|
|
1501
1501
|
// ../../node_modules/@cortexkit/common-auth/dist/fs/refresh-file-lock.js
|
|
1502
1502
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
1503
|
-
import { link, lstat as lstat3, mkdir as mkdir2, open as open3, readFile as readFile2, rename as rename3, rm as rm2, stat as stat2 } from "node:fs/promises";
|
|
1504
|
-
import { dirname as dirname4, join as join3 } from "node:path";
|
|
1503
|
+
import { link, lstat as lstat3, mkdir as mkdir2, open as open3, readdir, readFile as readFile2, rename as rename3, rm as rm2, stat as stat2, unlink as unlink2 } from "node:fs/promises";
|
|
1504
|
+
import { basename, dirname as dirname4, join as join3 } from "node:path";
|
|
1505
1505
|
|
|
1506
1506
|
// ../../node_modules/@cortexkit/common-auth/dist/fs/lock-record.js
|
|
1507
1507
|
import { resolve as resolve5 } from "node:path";
|
|
@@ -1662,6 +1662,88 @@ async function writeExclusiveText(path, text) {
|
|
|
1662
1662
|
await handle.close();
|
|
1663
1663
|
}
|
|
1664
1664
|
}
|
|
1665
|
+
var STAGING_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
1666
|
+
var STAGING_SWEEP_MIN_AGE_MS = 10 * 60000;
|
|
1667
|
+
var STAGING_SWEEP_MAX_CANDIDATES = 256;
|
|
1668
|
+
var STAGING_SWEEP_MAX_BYTES = 4096;
|
|
1669
|
+
var sweptLockPaths = new Set;
|
|
1670
|
+
var pendingStagingSweeps = new Set;
|
|
1671
|
+
var stagingSweepTestHooks;
|
|
1672
|
+
function isStagingName(name, lockName) {
|
|
1673
|
+
const prefix = `${lockName}.`;
|
|
1674
|
+
const suffix = ".tmp";
|
|
1675
|
+
if (!name.startsWith(prefix) || !name.endsWith(suffix))
|
|
1676
|
+
return false;
|
|
1677
|
+
return STAGING_UUID.test(name.slice(prefix.length, -suffix.length));
|
|
1678
|
+
}
|
|
1679
|
+
function sameStagingFile(a, b) {
|
|
1680
|
+
return a.dev === b.dev && a.ino === b.ino && a.size === b.size && a.mtimeMs === b.mtimeMs && a.birthtimeMs === b.birthtimeMs;
|
|
1681
|
+
}
|
|
1682
|
+
async function readStagedOwner(path) {
|
|
1683
|
+
const before = await lstat3(path);
|
|
1684
|
+
if (!before.isFile() || before.isSymbolicLink())
|
|
1685
|
+
return;
|
|
1686
|
+
if (before.size > STAGING_SWEEP_MAX_BYTES)
|
|
1687
|
+
return;
|
|
1688
|
+
const handle = await open3(path, "r");
|
|
1689
|
+
let text;
|
|
1690
|
+
try {
|
|
1691
|
+
if (!sameStagingFile(before, await handle.stat()))
|
|
1692
|
+
return;
|
|
1693
|
+
text = await handle.readFile("utf8");
|
|
1694
|
+
} finally {
|
|
1695
|
+
await handle.close();
|
|
1696
|
+
}
|
|
1697
|
+
let record2;
|
|
1698
|
+
try {
|
|
1699
|
+
record2 = JSON.parse(text);
|
|
1700
|
+
} catch {
|
|
1701
|
+
return;
|
|
1702
|
+
}
|
|
1703
|
+
if (!record2 || typeof record2 !== "object" || Array.isArray(record2))
|
|
1704
|
+
return;
|
|
1705
|
+
const keys = Object.keys(record2).sort();
|
|
1706
|
+
if (keys.length !== 2 || keys[0] !== "expiresAt" || keys[1] !== "ownerId")
|
|
1707
|
+
return;
|
|
1708
|
+
const { ownerId, expiresAt } = record2;
|
|
1709
|
+
if (typeof ownerId !== "string" || !STAGING_UUID.test(ownerId))
|
|
1710
|
+
return;
|
|
1711
|
+
if (typeof expiresAt !== "number" || !Number.isFinite(expiresAt))
|
|
1712
|
+
return;
|
|
1713
|
+
return { identity: before, expiresAt };
|
|
1714
|
+
}
|
|
1715
|
+
async function sweepAbandonedStaging(lockPath, ttlMs, now) {
|
|
1716
|
+
const directory = dirname4(lockPath);
|
|
1717
|
+
const lockName = basename(lockPath);
|
|
1718
|
+
const hooks = stagingSweepTestHooks;
|
|
1719
|
+
const names = await (hooks?.readdir ?? readdir)(directory);
|
|
1720
|
+
const candidates = names.filter((name) => isStagingName(name, lockName)).slice(0, STAGING_SWEEP_MAX_CANDIDATES);
|
|
1721
|
+
const marginMs = Math.max(Number.isFinite(ttlMs) ? ttlMs : 0, STAGING_SWEEP_MIN_AGE_MS);
|
|
1722
|
+
for (const name of candidates) {
|
|
1723
|
+
const path = join3(directory, name);
|
|
1724
|
+
try {
|
|
1725
|
+
if (now() - (await lstat3(path)).mtimeMs < marginMs)
|
|
1726
|
+
continue;
|
|
1727
|
+
const staged = await readStagedOwner(path);
|
|
1728
|
+
if (!staged || !(staged.expiresAt < now() - marginMs))
|
|
1729
|
+
continue;
|
|
1730
|
+
if (hooks?.beforeUnlink)
|
|
1731
|
+
await hooks.beforeUnlink(path);
|
|
1732
|
+
const current = await readStagedOwner(path);
|
|
1733
|
+
if (!current || !sameStagingFile(staged.identity, current.identity) || !(current.expiresAt < now() - marginMs))
|
|
1734
|
+
continue;
|
|
1735
|
+
await (hooks?.unlink ?? unlink2)(path);
|
|
1736
|
+
} catch {}
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
function startStagingSweep(lockPath, ttlMs, now) {
|
|
1740
|
+
if (sweptLockPaths.has(lockPath))
|
|
1741
|
+
return;
|
|
1742
|
+
sweptLockPaths.add(lockPath);
|
|
1743
|
+
const sweep = Promise.resolve().then(() => sweepAbandonedStaging(lockPath, ttlMs, now)).catch(() => {});
|
|
1744
|
+
pendingStagingSweeps.add(sweep);
|
|
1745
|
+
sweep.finally(() => pendingStagingSweeps.delete(sweep));
|
|
1746
|
+
}
|
|
1665
1747
|
var setRefreshLockRenewalTimeout = globalThis.setTimeout.bind(globalThis);
|
|
1666
1748
|
var clearRefreshLockRenewalTimeout = globalThis.clearTimeout.bind(globalThis);
|
|
1667
1749
|
function isLostMarkerRaceError(error) {
|
|
@@ -2350,6 +2432,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
2350
2432
|
return null;
|
|
2351
2433
|
}
|
|
2352
2434
|
scheduleRenewal();
|
|
2435
|
+
startStagingSweep(lockPath, options.ttlMs, now);
|
|
2353
2436
|
return {
|
|
2354
2437
|
ownerId,
|
|
2355
2438
|
whenLost: () => lostPromise,
|
|
@@ -2413,17 +2496,15 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
2413
2496
|
removalConfirmed = true;
|
|
2414
2497
|
}, deadline);
|
|
2415
2498
|
changingRecordError = undefined;
|
|
2416
|
-
if (markerAcquired) {
|
|
2417
|
-
|
|
2418
|
-
throw new PrivateFileError(lockPath, "release-not-confirmed", {
|
|
2419
|
-
code: "EIO"
|
|
2420
|
-
});
|
|
2421
|
-
releaseConfirmed = removalConfirmed;
|
|
2499
|
+
if (markerAcquired && removalConfirmed) {
|
|
2500
|
+
releaseConfirmed = true;
|
|
2422
2501
|
return;
|
|
2423
2502
|
}
|
|
2424
|
-
if (
|
|
2425
|
-
|
|
2426
|
-
|
|
2503
|
+
if (!markerAcquired) {
|
|
2504
|
+
if (signal?.aborted)
|
|
2505
|
+
return;
|
|
2506
|
+
await recoverStaleEvictionMarker(deadline);
|
|
2507
|
+
}
|
|
2427
2508
|
} catch (error) {
|
|
2428
2509
|
const changingRecord = windowsPrivateFiles && (isChangingLockCreate(error) || isWindowsAccessDeniedRead(error, [
|
|
2429
2510
|
lockPath,
|
|
@@ -2453,6 +2534,9 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
2453
2534
|
throw changingRecordError ?? removalError ?? new PrivateFileError(lockPath, "release-not-confirmed", {
|
|
2454
2535
|
code: "ETIMEDOUT"
|
|
2455
2536
|
});
|
|
2537
|
+
createLogger("fs").warn("File lock release deadline expired", {
|
|
2538
|
+
lockPath
|
|
2539
|
+
});
|
|
2456
2540
|
}
|
|
2457
2541
|
};
|
|
2458
2542
|
}
|
|
@@ -2609,7 +2693,7 @@ function connectClaustrumEnrollmentClient(options) {
|
|
|
2609
2693
|
}
|
|
2610
2694
|
function getClaustrumEnrollmentPaths(tokenPath) {
|
|
2611
2695
|
const extension = extname(tokenPath) || ".json";
|
|
2612
|
-
const stem =
|
|
2696
|
+
const stem = basename2(tokenPath, extname(tokenPath));
|
|
2613
2697
|
return {
|
|
2614
2698
|
statePath: join4(dirname5(tokenPath), `${stem}-state${extension}`),
|
|
2615
2699
|
tokenPath
|
|
@@ -2864,7 +2948,7 @@ async function writeStateAtomic(path, state, ancestorOptions = {}) {
|
|
|
2864
2948
|
}
|
|
2865
2949
|
if (windowsPrivateFiles)
|
|
2866
2950
|
return writePrivateAtomic(path, bytes);
|
|
2867
|
-
const temporary = join4(parent, `.${
|
|
2951
|
+
const temporary = join4(parent, `.${basename2(path)}.${process.pid}.${randomUUID4()}.tmp`);
|
|
2868
2952
|
let descriptor;
|
|
2869
2953
|
let created = false;
|
|
2870
2954
|
try {
|
|
@@ -2880,7 +2964,7 @@ async function writeStateAtomic(path, state, ancestorOptions = {}) {
|
|
|
2880
2964
|
} finally {
|
|
2881
2965
|
await descriptor?.close().catch(() => {});
|
|
2882
2966
|
if (created)
|
|
2883
|
-
await
|
|
2967
|
+
await unlink3(temporary).catch(() => {});
|
|
2884
2968
|
}
|
|
2885
2969
|
}
|
|
2886
2970
|
var enrollmentStatusCache = new FileReadCache;
|
|
@@ -3162,7 +3246,7 @@ class ClaustrumEnrollmentManager {
|
|
|
3162
3246
|
}
|
|
3163
3247
|
if (refusal.code === UNSUPPORTED_ENROLLMENT_CODE) {
|
|
3164
3248
|
await lock.assertOwned();
|
|
3165
|
-
await
|
|
3249
|
+
await unlink3(this.#paths.statePath).catch((cause) => {
|
|
3166
3250
|
if (cause.code !== "ENOENT")
|
|
3167
3251
|
throw cause;
|
|
3168
3252
|
});
|
|
@@ -3254,7 +3338,7 @@ async function resetClaustrumEnrollmentState(paths, proposedName) {
|
|
|
3254
3338
|
if (state.phase === "pending")
|
|
3255
3339
|
return "refused-pending";
|
|
3256
3340
|
await lock.assertOwned();
|
|
3257
|
-
await
|
|
3341
|
+
await unlink3(paths.statePath);
|
|
3258
3342
|
return "reset";
|
|
3259
3343
|
} finally {
|
|
3260
3344
|
await lock.release();
|
|
@@ -3262,7 +3346,7 @@ async function resetClaustrumEnrollmentState(paths, proposedName) {
|
|
|
3262
3346
|
}
|
|
3263
3347
|
async function removeIfPresent(path) {
|
|
3264
3348
|
try {
|
|
3265
|
-
await
|
|
3349
|
+
await unlink3(path);
|
|
3266
3350
|
return true;
|
|
3267
3351
|
} catch (error) {
|
|
3268
3352
|
if (error.code === "ENOENT")
|
|
@@ -6206,7 +6290,7 @@ class ClaustrumConsumer {
|
|
|
6206
6290
|
// ../../node_modules/@cortexkit/common-auth/dist/claustrum/hub.js
|
|
6207
6291
|
import { createHash as createHash3 } from "node:crypto";
|
|
6208
6292
|
import { channel as channel2 } from "node:diagnostics_channel";
|
|
6209
|
-
import { readdir, stat as stat5 } from "node:fs/promises";
|
|
6293
|
+
import { readdir as readdir2, stat as stat5 } from "node:fs/promises";
|
|
6210
6294
|
import { dirname as dirname6, join as join5, resolve as resolve10 } from "node:path";
|
|
6211
6295
|
var sharedRosters = new Map;
|
|
6212
6296
|
var FILE_ID = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
@@ -6854,7 +6938,7 @@ class ClaustrumDiscoveryHub {
|
|
|
6854
6938
|
const name = `${entry.provider}.json`;
|
|
6855
6939
|
const candidates = [join5(this.#generationDirectory, name)];
|
|
6856
6940
|
try {
|
|
6857
|
-
for (const key of await
|
|
6941
|
+
for (const key of await readdir2(this.#generationDirectory))
|
|
6858
6942
|
if (key !== this.#key && FINGERPRINT.test(key))
|
|
6859
6943
|
candidates.push(join5(this.#generationDirectory, key, name));
|
|
6860
6944
|
} catch {}
|
|
@@ -7308,6 +7392,28 @@ function selectionFor(answer, candidates) {
|
|
|
7308
7392
|
}
|
|
7309
7393
|
return { candidate };
|
|
7310
7394
|
}
|
|
7395
|
+
function refusalFor(value) {
|
|
7396
|
+
if (!isObject(value))
|
|
7397
|
+
return;
|
|
7398
|
+
const code = value.code;
|
|
7399
|
+
if (code !== "account_limit_exhausted" && code !== "account_selection_refused" && code !== "account_selection_final") {
|
|
7400
|
+
return;
|
|
7401
|
+
}
|
|
7402
|
+
const refused = { code };
|
|
7403
|
+
const routingCode = value.routing_code;
|
|
7404
|
+
if (typeof routingCode === "string" && /^[a-z0-9._-]{1,64}$/.test(routingCode)) {
|
|
7405
|
+
refused.routingCode = routingCode;
|
|
7406
|
+
}
|
|
7407
|
+
const retryAfterSecs = value.retry_after_secs;
|
|
7408
|
+
if (typeof retryAfterSecs === "number" && Number.isFinite(retryAfterSecs) && retryAfterSecs >= 0) {
|
|
7409
|
+
refused.retryAfterSecs = retryAfterSecs;
|
|
7410
|
+
}
|
|
7411
|
+
const resetsAtMs = value.resets_at_ms;
|
|
7412
|
+
if (typeof resetsAtMs === "number" && Number.isSafeInteger(resetsAtMs) && resetsAtMs > 0) {
|
|
7413
|
+
refused.resetsAtMs = resetsAtMs;
|
|
7414
|
+
}
|
|
7415
|
+
return { refused };
|
|
7416
|
+
}
|
|
7311
7417
|
async function askRouting(input) {
|
|
7312
7418
|
let timer;
|
|
7313
7419
|
try {
|
|
@@ -7317,8 +7423,8 @@ async function askRouting(input) {
|
|
|
7317
7423
|
const accountFor = handle.accountFor;
|
|
7318
7424
|
if (typeof accountFor !== "function")
|
|
7319
7425
|
return;
|
|
7320
|
-
const requested = input.deadlineMs ??
|
|
7321
|
-
const deadlineMs = Number.isNaN(requested) ?
|
|
7426
|
+
const requested = input.deadlineMs ?? 1500;
|
|
7427
|
+
const deadlineMs = Number.isNaN(requested) ? 1500 : Math.min(2000, Math.max(1, requested));
|
|
7322
7428
|
const expired = new Promise((resolve11) => {
|
|
7323
7429
|
timer = setTimeout(() => resolve11(undefined), deadlineMs);
|
|
7324
7430
|
timer.unref();
|
|
@@ -7331,10 +7437,15 @@ async function askRouting(input) {
|
|
|
7331
7437
|
if (typeof cap === "number" && Number.isFinite(cap)) {
|
|
7332
7438
|
request2.hold_wait_max_s = Math.max(0, Math.floor(cap));
|
|
7333
7439
|
}
|
|
7440
|
+
if (input.refusals === true)
|
|
7441
|
+
request2.refusals = true;
|
|
7334
7442
|
const pending = accountFor.call(handle, request2, { deadlineMs });
|
|
7335
7443
|
if (!isObject(pending) || typeof pending.then !== "function")
|
|
7336
7444
|
return;
|
|
7337
7445
|
const answer = await Promise.race([pending, expired]);
|
|
7446
|
+
if (input.refusals === true && isObject(answer) && "refused" in answer) {
|
|
7447
|
+
return refusalFor(answer.refused);
|
|
7448
|
+
}
|
|
7338
7449
|
return selectionFor(answer, input.candidates);
|
|
7339
7450
|
} catch {
|
|
7340
7451
|
return;
|
|
@@ -7443,6 +7554,17 @@ function reportRouting(input) {
|
|
|
7443
7554
|
};
|
|
7444
7555
|
break;
|
|
7445
7556
|
}
|
|
7557
|
+
case "credential_refused": {
|
|
7558
|
+
const { credentialId, providerCode } = input;
|
|
7559
|
+
if (!isNonEmptyString(credentialId) || typeof providerCode !== "string" || !/^[a-z0-9._-]{1,64}$/.test(providerCode))
|
|
7560
|
+
return;
|
|
7561
|
+
payload = {
|
|
7562
|
+
...identity2,
|
|
7563
|
+
outcome: "credential_refused",
|
|
7564
|
+
provider_code: providerCode
|
|
7565
|
+
};
|
|
7566
|
+
break;
|
|
7567
|
+
}
|
|
7446
7568
|
default:
|
|
7447
7569
|
return;
|
|
7448
7570
|
}
|
|
@@ -7843,11 +7965,17 @@ async function confirmEnrollmentAccess(client, status, tokenPath, configuredGran
|
|
|
7843
7965
|
grantCommand: `ck auth grant --principal ${shellArgument(`enrolled:${status.approvedName}`)} --selector-kind ${grant.selector.exact === undefined ? "category" : "exact"} --selector ${shellArgument(grant.selector.exact ?? grant.selector.category)} --operation ${grant.operation}`
|
|
7844
7966
|
}
|
|
7845
7967
|
}));
|
|
7968
|
+
const access = {
|
|
7969
|
+
grants,
|
|
7970
|
+
...status.requestedGrantsStatus !== undefined && {
|
|
7971
|
+
requestedGrantsStatus: status.requestedGrantsStatus
|
|
7972
|
+
}
|
|
7973
|
+
};
|
|
7846
7974
|
if (status.requestedGrantsStatus === "dropped")
|
|
7847
|
-
return { state: "older-vault"
|
|
7975
|
+
return { ...access, state: "older-vault" };
|
|
7848
7976
|
try {
|
|
7849
7977
|
if (!client.listScoped)
|
|
7850
|
-
return { state: "unconfirmed"
|
|
7978
|
+
return { ...access, state: "unconfirmed" };
|
|
7851
7979
|
const { token } = await readClaustrumEnrollmentToken(tokenPath);
|
|
7852
7980
|
const inventory = await client.listScoped(token);
|
|
7853
7981
|
const confirmed = grants.map((entry) => ({
|
|
@@ -7855,6 +7983,7 @@ async function confirmEnrollmentAccess(client, status, tokenPath, configuredGran
|
|
|
7855
7983
|
reachableLogins: inventory.rows.filter((row) => row.operations.includes(entry.grant.operation) && (entry.grant.selector.exact !== undefined ? row.id === entry.grant.selector.exact : row.categories.includes(entry.grant.selector.category))).length
|
|
7856
7984
|
}));
|
|
7857
7985
|
return {
|
|
7986
|
+
...access,
|
|
7858
7987
|
state: confirmed.every((entry) => entry.reachableLogins > 0) ? "reachable" : confirmed.some((entry) => entry.reachableLogins > 0) ? "partial" : "no-logins",
|
|
7859
7988
|
grants: confirmed.map((entry) => {
|
|
7860
7989
|
if (entry.reachableLogins === 0)
|
|
@@ -7864,10 +7993,12 @@ async function confirmEnrollmentAccess(client, status, tokenPath, configuredGran
|
|
|
7864
7993
|
})
|
|
7865
7994
|
};
|
|
7866
7995
|
} catch {
|
|
7867
|
-
return { state: "unconfirmed"
|
|
7996
|
+
return { ...access, state: "unconfirmed" };
|
|
7868
7997
|
}
|
|
7869
7998
|
}
|
|
7870
|
-
function enrollmentAccessLines(access) {
|
|
7999
|
+
function enrollmentAccessLines(access, grantFallback = "setup") {
|
|
8000
|
+
if (grantFallback === "plugin" && access.requestedGrantsStatus !== "sent")
|
|
8001
|
+
return [];
|
|
7871
8002
|
const lines = [];
|
|
7872
8003
|
const remedy = access.grants.some((entry) => entry.grantCommand) ? "run:" : "check ck auth status for the approved name before granting access.";
|
|
7873
8004
|
if (access.state === "older-vault")
|
|
@@ -7931,8 +8062,9 @@ var OUTCOME_TEXT = {
|
|
|
7931
8062
|
"not-enrolled": "not connected",
|
|
7932
8063
|
unknown: "unknown, check with ck auth status"
|
|
7933
8064
|
};
|
|
7934
|
-
function setupEnrollmentLine({ host, outcome, access }) {
|
|
7935
|
-
|
|
8065
|
+
function setupEnrollmentLine({ host, outcome, access }, grantFallback = "setup") {
|
|
8066
|
+
const lines = access ? enrollmentAccessLines(access, grantFallback) : [];
|
|
8067
|
+
return `${HOST_LABELS[host]}: ${OUTCOME_TEXT[outcome]}${lines.length ? ` — ${lines.join(`
|
|
7936
8068
|
`)}` : ""}`;
|
|
7937
8069
|
}
|
|
7938
8070
|
var recordedEnrollment = new WeakMap;
|
|
@@ -8477,7 +8609,7 @@ function approveCommand(requestId, name) {
|
|
|
8477
8609
|
async function connectSetupHost(plugin, host, io, terminal, fence) {
|
|
8478
8610
|
if (hasVaultHost())
|
|
8479
8611
|
throw new Error(VAULT_HOST_CONNECT_REFUSAL);
|
|
8480
|
-
const { name, displayName, requestedGrants, paths: input } = plugin.vault.hosts[host];
|
|
8612
|
+
const { name, displayName, requestedGrants, grantFallback, paths: input } = plugin.vault.hosts[host];
|
|
8481
8613
|
const paths = hostEnrollmentPaths(input);
|
|
8482
8614
|
await fence();
|
|
8483
8615
|
const client = await (io.connect ?? connectClaustrumEnrollmentClient)({
|
|
@@ -8506,7 +8638,7 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
|
|
|
8506
8638
|
printLine(terminal, `Already connected as ${initial.approvedName ?? initial.proposedName}.`);
|
|
8507
8639
|
const access = await confirmEnrollmentAccess(client, initial, paths.tokenPath, requestedGrants);
|
|
8508
8640
|
if (access)
|
|
8509
|
-
for (const line of enrollmentAccessLines(access))
|
|
8641
|
+
for (const line of enrollmentAccessLines(access, grantFallback))
|
|
8510
8642
|
printLine(terminal, line);
|
|
8511
8643
|
return access;
|
|
8512
8644
|
}
|
|
@@ -8522,7 +8654,7 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
|
|
|
8522
8654
|
printLine(terminal, `Connected ${host} to Claustrum.`);
|
|
8523
8655
|
const access = await confirmEnrollmentAccess(client, status, paths.tokenPath, requestedGrants);
|
|
8524
8656
|
if (access)
|
|
8525
|
-
for (const line of enrollmentAccessLines(access))
|
|
8657
|
+
for (const line of enrollmentAccessLines(access, grantFallback))
|
|
8526
8658
|
printLine(terminal, line);
|
|
8527
8659
|
return access;
|
|
8528
8660
|
}
|
|
@@ -8731,8 +8863,8 @@ import { applyEdits, createScanner, findNodeAtLocation, modify, parse as parse2,
|
|
|
8731
8863
|
|
|
8732
8864
|
// ../../node_modules/@cortexkit/common-auth/dist/setup/config-write.js
|
|
8733
8865
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
8734
|
-
import { mkdir as mkdir4, open as open5, rename as rename5, stat as stat7, unlink as
|
|
8735
|
-
import { basename as
|
|
8866
|
+
import { mkdir as mkdir4, open as open5, rename as rename5, stat as stat7, unlink as unlink4 } from "node:fs/promises";
|
|
8867
|
+
import { basename as basename3, dirname as dirname7, join as join7 } from "node:path";
|
|
8736
8868
|
import { setTimeout as delay2 } from "node:timers/promises";
|
|
8737
8869
|
async function writeHostConfigAtomic(file, content, options = {}) {
|
|
8738
8870
|
const windows = (options.platform ?? process.platform) === "win32";
|
|
@@ -8747,7 +8879,7 @@ async function writeHostConfigAtomic(file, content, options = {}) {
|
|
|
8747
8879
|
throw error;
|
|
8748
8880
|
}
|
|
8749
8881
|
}
|
|
8750
|
-
const stage = join7(parent, `.${
|
|
8882
|
+
const stage = join7(parent, `.${basename3(file)}.${(options.stageName ?? randomUUID5)()}.tmp`);
|
|
8751
8883
|
let created = false;
|
|
8752
8884
|
try {
|
|
8753
8885
|
const handle = await open5(stage, "wx", mode ?? 438);
|
|
@@ -8777,7 +8909,7 @@ async function writeHostConfigAtomic(file, content, options = {}) {
|
|
|
8777
8909
|
}
|
|
8778
8910
|
} finally {
|
|
8779
8911
|
if (created)
|
|
8780
|
-
await
|
|
8912
|
+
await unlink4(stage).catch(() => {});
|
|
8781
8913
|
}
|
|
8782
8914
|
}
|
|
8783
8915
|
|
|
@@ -8972,6 +9104,8 @@ function validatePlugin(plugin) {
|
|
|
8972
9104
|
throw new Error("Setup requires lowercase vault names containing only letters, digits and dashes.");
|
|
8973
9105
|
if (host.requestedGrants !== undefined && !validEnrollmentRequestedGrants(host.requestedGrants))
|
|
8974
9106
|
throw new Error("invalid Claustrum enrollment requested grants");
|
|
9107
|
+
if (host.grantFallback !== undefined && host.grantFallback !== "setup" && host.grantFallback !== "plugin")
|
|
9108
|
+
throw new Error("invalid Claustrum enrollment grant fallback");
|
|
8975
9109
|
}
|
|
8976
9110
|
}
|
|
8977
9111
|
async function enrollmentReport(plugin, hosts, recorded, recordedAccess) {
|
|
@@ -9162,7 +9296,7 @@ ${write.content}`);
|
|
|
9162
9296
|
const report2 = await enrollmentReport(plugin, hosts, enrollment, enrollmentAccess);
|
|
9163
9297
|
recordSetupEnrollment(error, report2);
|
|
9164
9298
|
for (const entry of report2)
|
|
9165
|
-
printLine(terminal, setupEnrollmentLine(entry));
|
|
9299
|
+
printLine(terminal, setupEnrollmentLine(entry, plugin.vault.hosts[entry.host].grantFallback));
|
|
9166
9300
|
} catch {}
|
|
9167
9301
|
throw error;
|
|
9168
9302
|
}
|
|
@@ -9787,6 +9921,7 @@ var CCH_SALT = "59cf53e54c78";
|
|
|
9787
9921
|
var CCH_POSITIONS = [4, 7, 20];
|
|
9788
9922
|
var CLAUDE_CODE_VERSION = "2.1.302";
|
|
9789
9923
|
var CLAUDE_CODE_ENTRYPOINT = "cli";
|
|
9924
|
+
var CLAUDE_CODE_ACCEPT_ENCODING = "gzip, deflate, br, zstd";
|
|
9790
9925
|
var CLAUDE_CODE_STAINLESS_PACKAGE_VERSION = "0.128.0";
|
|
9791
9926
|
var CLAUDE_CODE_STAINLESS_RUNTIME_VERSION = "v26.3.0";
|
|
9792
9927
|
var CLAUDE_CODE_GZIPS_REQUEST_BODIES = true;
|
|
@@ -11653,7 +11788,7 @@ function isSseCandidateFrame(frame) {
|
|
|
11653
11788
|
|
|
11654
11789
|
// src/stream-completion.ts
|
|
11655
11790
|
var timings = new WeakMap;
|
|
11656
|
-
function copyStreamResponseTiming(source, target, sent, timingSource = "physical_fetch") {
|
|
11791
|
+
function copyStreamResponseTiming(source, target, sent, timingSource = "physical_fetch", bodySizes) {
|
|
11657
11792
|
const timing = timings.get(source);
|
|
11658
11793
|
if (timing)
|
|
11659
11794
|
timings.set(target, timing);
|
|
@@ -11662,7 +11797,8 @@ function copyStreamResponseTiming(source, target, sent, timingSource = "physical
|
|
|
11662
11797
|
sent,
|
|
11663
11798
|
headers: performance.now(),
|
|
11664
11799
|
contentLength: responseHeaders(target.headers)["content-length"],
|
|
11665
|
-
source: timingSource
|
|
11800
|
+
source: timingSource,
|
|
11801
|
+
bodySizes
|
|
11666
11802
|
});
|
|
11667
11803
|
return target;
|
|
11668
11804
|
}
|
|
@@ -11682,6 +11818,10 @@ function responseHeaders(headers) {
|
|
|
11682
11818
|
}
|
|
11683
11819
|
return result;
|
|
11684
11820
|
}
|
|
11821
|
+
function bodyByteCounts(input) {
|
|
11822
|
+
const { encoded_body_bytes, decoded_body_bytes } = input ?? {};
|
|
11823
|
+
return typeof encoded_body_bytes === "number" && Number.isSafeInteger(encoded_body_bytes) && encoded_body_bytes >= 0 && typeof decoded_body_bytes === "number" && Number.isSafeInteger(decoded_body_bytes) && decoded_body_bytes >= 0 ? { encoded_body_bytes, decoded_body_bytes } : {};
|
|
11824
|
+
}
|
|
11685
11825
|
function safeIncompleteStreamDiagnostics(input) {
|
|
11686
11826
|
const count = (value) => Number.isSafeInteger(value) && value >= 0 ? value : 0;
|
|
11687
11827
|
return {
|
|
@@ -11689,6 +11829,7 @@ function safeIncompleteStreamDiagnostics(input) {
|
|
|
11689
11829
|
get: (name) => input.response_headers[name] ?? null
|
|
11690
11830
|
}),
|
|
11691
11831
|
response_bytes: count(input.response_bytes),
|
|
11832
|
+
...bodyByteCounts(input),
|
|
11692
11833
|
sse_events: count(input.sse_events),
|
|
11693
11834
|
...input.send_to_headers_ms !== undefined ? { send_to_headers_ms: count(input.send_to_headers_ms) } : {},
|
|
11694
11835
|
...input.timing_source === "physical_fetch" || input.timing_source === "credential_scope" ? { timing_source: input.timing_source } : {},
|
|
@@ -11745,6 +11886,7 @@ function createAnthropicStreamCompletion(response) {
|
|
|
11745
11886
|
const diagnostics = {
|
|
11746
11887
|
response_headers: headers,
|
|
11747
11888
|
response_bytes: bytes,
|
|
11889
|
+
...bodyByteCounts(timing?.bodySizes?.()),
|
|
11748
11890
|
sse_events: events,
|
|
11749
11891
|
...timing ? {
|
|
11750
11892
|
send_to_headers_ms: Math.max(0, Math.round(timing.headers - timing.sent)),
|
|
@@ -11895,7 +12037,7 @@ function detachReport(report2) {
|
|
|
11895
12037
|
} catch {}
|
|
11896
12038
|
}, 0).unref?.();
|
|
11897
12039
|
}
|
|
11898
|
-
function identity2(input) {
|
|
12040
|
+
function identity2({ cacheWarming: _, ...input }) {
|
|
11899
12041
|
return {
|
|
11900
12042
|
...input,
|
|
11901
12043
|
kind: "billing",
|
|
@@ -11924,11 +12066,21 @@ function createAnthropicBillingObserver(input, status, headers, sse = headers.ge
|
|
|
11924
12066
|
const measured = anthropicBillingUsage(rawUsage);
|
|
11925
12067
|
if (!finalUsage)
|
|
11926
12068
|
delete measured.usage.output;
|
|
12069
|
+
const outcome = failed ? "failed" : !finalUsage ? "cut" : "completed";
|
|
12070
|
+
let cache = failed ? undefined : base.cache;
|
|
12071
|
+
if (outcome === "completed" && !cache?.warming && input.cacheWarming) {
|
|
12072
|
+
let warming;
|
|
12073
|
+
try {
|
|
12074
|
+
warming = input.cacheWarming();
|
|
12075
|
+
} catch {}
|
|
12076
|
+
if (warming)
|
|
12077
|
+
cache = { ...cache, warming };
|
|
12078
|
+
}
|
|
11927
12079
|
detachReport({
|
|
11928
12080
|
...base,
|
|
11929
|
-
cache
|
|
12081
|
+
cache,
|
|
11930
12082
|
providerResponseId,
|
|
11931
|
-
outcome
|
|
12083
|
+
outcome,
|
|
11932
12084
|
...measured
|
|
11933
12085
|
});
|
|
11934
12086
|
};
|
|
@@ -12883,11 +13035,11 @@ import {
|
|
|
12883
13035
|
realpath as realpath2,
|
|
12884
13036
|
rename as rename7,
|
|
12885
13037
|
stat as stat9,
|
|
12886
|
-
unlink as
|
|
13038
|
+
unlink as unlink5
|
|
12887
13039
|
} from "node:fs/promises";
|
|
12888
13040
|
import { homedir as homedir4 } from "node:os";
|
|
12889
13041
|
import {
|
|
12890
|
-
basename as
|
|
13042
|
+
basename as basename5,
|
|
12891
13043
|
dirname as dirname11,
|
|
12892
13044
|
extname as extname2,
|
|
12893
13045
|
isAbsolute as isAbsolute3,
|
|
@@ -13298,7 +13450,7 @@ function connectClaustrumEnrollmentClient2(options = {}) {
|
|
|
13298
13450
|
}
|
|
13299
13451
|
function getClaustrumEnrollmentPaths2(tokenPath) {
|
|
13300
13452
|
const extension = extname2(tokenPath) || ".json";
|
|
13301
|
-
const stem =
|
|
13453
|
+
const stem = basename5(tokenPath, extname2(tokenPath));
|
|
13302
13454
|
return {
|
|
13303
13455
|
statePath: join12(dirname11(tokenPath), `${stem}-state${extension}`),
|
|
13304
13456
|
tokenPath
|
|
@@ -13455,7 +13607,7 @@ async function writeStateAtomic2(path2, state, beforeRename) {
|
|
|
13455
13607
|
if (Buffer.byteLength(bytes) > ENROLLMENT_FILE_MAX_BYTES2) {
|
|
13456
13608
|
throw new Error("Claustrum enrollment state is too large");
|
|
13457
13609
|
}
|
|
13458
|
-
const temporary = join12(parent, `.${
|
|
13610
|
+
const temporary = join12(parent, `.${basename5(path2)}.${process.pid}.${randomUUID8()}.tmp`);
|
|
13459
13611
|
let descriptor;
|
|
13460
13612
|
try {
|
|
13461
13613
|
const nativeCreated = await createWindowsOwnerOnly(temporary, bytes);
|
|
@@ -13470,17 +13622,17 @@ async function writeStateAtomic2(path2, state, beforeRename) {
|
|
|
13470
13622
|
await rename7(temporary, path2);
|
|
13471
13623
|
} finally {
|
|
13472
13624
|
await descriptor?.close().catch(() => {});
|
|
13473
|
-
await
|
|
13625
|
+
await unlink5(temporary).catch(() => {});
|
|
13474
13626
|
}
|
|
13475
13627
|
}
|
|
13476
13628
|
async function writeTokenAtomic(path2, value, writeTokenFile, beforeRename) {
|
|
13477
|
-
const staged = join12(dirname11(path2), `.${
|
|
13629
|
+
const staged = join12(dirname11(path2), `.${basename5(path2)}.${process.pid}.${randomUUID8()}.tmp`);
|
|
13478
13630
|
try {
|
|
13479
13631
|
await writeTokenFile(staged, value);
|
|
13480
13632
|
await beforeRename();
|
|
13481
13633
|
await rename7(staged, path2);
|
|
13482
13634
|
} finally {
|
|
13483
|
-
await
|
|
13635
|
+
await unlink5(staged).catch(() => {});
|
|
13484
13636
|
}
|
|
13485
13637
|
}
|
|
13486
13638
|
async function readClaustrumEnrollmentStatus2(paths, proposedName = CLAUSTRUM_OPENCODE_ENROLLMENT_NAME, ownership = {}) {
|
|
@@ -13763,7 +13915,7 @@ async function resetClaustrumEnrollmentState2(paths, proposedName) {
|
|
|
13763
13915
|
if (state.phase === "pending")
|
|
13764
13916
|
return "refused-pending";
|
|
13765
13917
|
await lock.assertOwned();
|
|
13766
|
-
await
|
|
13918
|
+
await unlink5(paths.statePath);
|
|
13767
13919
|
return "reset";
|
|
13768
13920
|
} finally {
|
|
13769
13921
|
await lock.release();
|
|
@@ -15042,10 +15194,10 @@ import { createHash as createHash8, randomBytes as randomBytes4 } from "node:cry
|
|
|
15042
15194
|
import {
|
|
15043
15195
|
lstat as lstat5,
|
|
15044
15196
|
mkdir as mkdir7,
|
|
15045
|
-
readdir as
|
|
15197
|
+
readdir as readdir3,
|
|
15046
15198
|
readFile as readFile6,
|
|
15047
15199
|
rename as rename8,
|
|
15048
|
-
unlink as
|
|
15200
|
+
unlink as unlink6,
|
|
15049
15201
|
writeFile as writeFile2
|
|
15050
15202
|
} from "node:fs/promises";
|
|
15051
15203
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
@@ -15133,7 +15285,7 @@ async function writeDumpFile(path2, contents) {
|
|
|
15133
15285
|
if (error.code === "EEXIST")
|
|
15134
15286
|
continue;
|
|
15135
15287
|
if (created)
|
|
15136
|
-
await
|
|
15288
|
+
await unlink6(partialPath).catch(() => {});
|
|
15137
15289
|
throw error;
|
|
15138
15290
|
}
|
|
15139
15291
|
}
|
|
@@ -15153,7 +15305,7 @@ async function sweepDumpDirectory(options) {
|
|
|
15153
15305
|
if (dumpDirStats.isSymbolicLink())
|
|
15154
15306
|
return emptyResult;
|
|
15155
15307
|
const protectedPaths = new Set((options.protectedPaths ?? []).map((path2) => resolve12(path2)));
|
|
15156
|
-
const entries = await
|
|
15308
|
+
const entries = await readdir3(dumpDir, { withFileTypes: true });
|
|
15157
15309
|
const files = [];
|
|
15158
15310
|
await Promise.all(entries.map(async (entry) => {
|
|
15159
15311
|
if (!entry.isFile())
|
|
@@ -15182,7 +15334,7 @@ async function sweepDumpDirectory(options) {
|
|
|
15182
15334
|
let freedBytes = 0;
|
|
15183
15335
|
const removeFile = async (file) => {
|
|
15184
15336
|
try {
|
|
15185
|
-
await
|
|
15337
|
+
await unlink6(file.path);
|
|
15186
15338
|
totalBytes -= file.size;
|
|
15187
15339
|
freedBytes += file.size;
|
|
15188
15340
|
removed += 1;
|
|
@@ -15359,7 +15511,7 @@ async function loadLatestDumpBody(input) {
|
|
|
15359
15511
|
const dumpDir = getDumpDirectory();
|
|
15360
15512
|
let names;
|
|
15361
15513
|
try {
|
|
15362
|
-
names = await
|
|
15514
|
+
names = await readdir3(dumpDir);
|
|
15363
15515
|
} catch {
|
|
15364
15516
|
return;
|
|
15365
15517
|
}
|
|
@@ -17695,6 +17847,7 @@ function cacheKeepSentCredentials(headers) {
|
|
|
17695
17847
|
}
|
|
17696
17848
|
var PLANNED_UNPRICED_MAIN_IDLE_MS = 60 * 60000;
|
|
17697
17849
|
var PLANNED_UNPRICED_SUBAGENT_IDLE_MS = 30 * 60000;
|
|
17850
|
+
var WARMING_RECORD_LIMIT = 4096;
|
|
17698
17851
|
|
|
17699
17852
|
class CacheKeepWarmRefusal extends Error {
|
|
17700
17853
|
reason;
|
|
@@ -17709,6 +17862,7 @@ class CacheKeepManager2 {
|
|
|
17709
17862
|
targets = new Map;
|
|
17710
17863
|
immediateTargets = new Map;
|
|
17711
17864
|
stoppedSessions = new Map;
|
|
17865
|
+
warmingRecords = new Map;
|
|
17712
17866
|
timer = null;
|
|
17713
17867
|
dueTimer = null;
|
|
17714
17868
|
tickPromise = null;
|
|
@@ -17817,6 +17971,28 @@ class CacheKeepManager2 {
|
|
|
17817
17971
|
hasPlannedTarget(id) {
|
|
17818
17972
|
return this.targets.get(id)?.policyState?.planned === true;
|
|
17819
17973
|
}
|
|
17974
|
+
warming(id) {
|
|
17975
|
+
const target = this.targets.get(id);
|
|
17976
|
+
if (target && (this.options.now?.() ?? Date.now()) < target.cacheExpiresAt)
|
|
17977
|
+
return { on: true };
|
|
17978
|
+
const record5 = this.warmingRecords.get(id);
|
|
17979
|
+
if (!record5)
|
|
17980
|
+
return;
|
|
17981
|
+
return isCacheWarmStopReason(record5.stopReason) ? { on: false, stopReason: record5.stopReason } : { on: false };
|
|
17982
|
+
}
|
|
17983
|
+
recordWarmingOff(id) {
|
|
17984
|
+
this.setWarmingRecord(id, {});
|
|
17985
|
+
}
|
|
17986
|
+
setWarmingRecord(id, record5) {
|
|
17987
|
+
this.warmingRecords.delete(id);
|
|
17988
|
+
this.warmingRecords.set(id, record5);
|
|
17989
|
+
while (this.warmingRecords.size > WARMING_RECORD_LIMIT) {
|
|
17990
|
+
const oldest = this.warmingRecords.keys().next();
|
|
17991
|
+
if (oldest.done)
|
|
17992
|
+
break;
|
|
17993
|
+
this.warmingRecords.delete(oldest.value);
|
|
17994
|
+
}
|
|
17995
|
+
}
|
|
17820
17996
|
updateSubagent(id, isSubagent) {
|
|
17821
17997
|
const target = this.targets.get(id);
|
|
17822
17998
|
if (!target || target.isSubagent === isSubagent)
|
|
@@ -18022,6 +18198,8 @@ class CacheKeepManager2 {
|
|
|
18022
18198
|
}
|
|
18023
18199
|
reportStop(target, reason, at) {
|
|
18024
18200
|
const state = target.policyState;
|
|
18201
|
+
if (!target.sourceWarm)
|
|
18202
|
+
this.setWarmingRecord(target.id, { stopReason: reportStopReason(reason) });
|
|
18025
18203
|
if (target.sourceWarm || !state?.hasWarmed || this.reportedStops.has(state))
|
|
18026
18204
|
return;
|
|
18027
18205
|
if (reportSessionCacheWarmStopped(state.ownerSessionId, {
|
|
@@ -18107,12 +18285,22 @@ class CacheKeepManager2 {
|
|
|
18107
18285
|
return retire("unsupported");
|
|
18108
18286
|
if (!policy && (input.retained?.policyState?.planned || previous?.policyState?.planned))
|
|
18109
18287
|
return retire("session-ended");
|
|
18110
|
-
|
|
18288
|
+
const sessionId = input.sessionId;
|
|
18289
|
+
const keptOff = () => {
|
|
18290
|
+
if (!previous && !input.sourceWarm)
|
|
18291
|
+
this.recordWarmingOff(sessionId);
|
|
18292
|
+
};
|
|
18293
|
+
if (policy?.ttl === "none" || policy?.keep_warm === "off") {
|
|
18294
|
+
if (policy.keep_warm === "off")
|
|
18295
|
+
keptOff();
|
|
18111
18296
|
return retire("unsupported");
|
|
18297
|
+
}
|
|
18112
18298
|
if (!planned && !isCacheKeepPersistentlyEnabled(input.storage)) {
|
|
18299
|
+
keptOff();
|
|
18113
18300
|
return refuse("cachekeep disabled", "disabled");
|
|
18114
18301
|
}
|
|
18115
18302
|
if (!planned && input.cacheMode !== "hybrid") {
|
|
18303
|
+
keptOff();
|
|
18116
18304
|
return refuse("cache mode is not hybrid", "not-hybrid");
|
|
18117
18305
|
}
|
|
18118
18306
|
bodyBytes = Buffer.byteLength(input.bodyText, "utf8");
|
|
@@ -18153,6 +18341,7 @@ class CacheKeepManager2 {
|
|
|
18153
18341
|
if (this.targets.has(input.sessionId))
|
|
18154
18342
|
this.targets.delete(input.sessionId);
|
|
18155
18343
|
this.stoppedSessions.delete(input.sessionId);
|
|
18344
|
+
this.warmingRecords.delete(input.sessionId);
|
|
18156
18345
|
const headers = {};
|
|
18157
18346
|
input.headers.forEach((value, key) => {
|
|
18158
18347
|
headers[key] = value;
|
|
@@ -18664,7 +18853,7 @@ import {
|
|
|
18664
18853
|
link as link2,
|
|
18665
18854
|
lstat as lstat13,
|
|
18666
18855
|
mkdir as mkdir11,
|
|
18667
|
-
readdir as
|
|
18856
|
+
readdir as readdir4,
|
|
18668
18857
|
readFile as readFile12,
|
|
18669
18858
|
rename as rename12,
|
|
18670
18859
|
rm as rm7,
|
|
@@ -18680,7 +18869,7 @@ import { randomUUID as randomUUID15 } from "node:crypto";
|
|
|
18680
18869
|
import { readFileSync as readFileSync2 } from "node:fs";
|
|
18681
18870
|
import { lstat as lstat12, mkdir as mkdir10, readFile as readFile11 } from "node:fs/promises";
|
|
18682
18871
|
import { uptime } from "node:os";
|
|
18683
|
-
import { basename as
|
|
18872
|
+
import { basename as basename10, dirname as dirname17, join as join20 } from "node:path";
|
|
18684
18873
|
|
|
18685
18874
|
// src/native-lock-observer.ts
|
|
18686
18875
|
import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
|
|
@@ -18723,17 +18912,17 @@ function observeNativeLocks(acquire, observer) {
|
|
|
18723
18912
|
|
|
18724
18913
|
// src/native-vault-paths.ts
|
|
18725
18914
|
import { createHash as createHash18 } from "node:crypto";
|
|
18726
|
-
import { basename as
|
|
18915
|
+
import { basename as basename9, dirname as dirname15, join as join17 } from "node:path";
|
|
18727
18916
|
|
|
18728
18917
|
// src/pool-paths.ts
|
|
18729
18918
|
import { createHash as createHash17 } from "node:crypto";
|
|
18730
18919
|
import { realpath as realpath3 } from "node:fs/promises";
|
|
18731
|
-
import { basename as
|
|
18920
|
+
import { basename as basename8, dirname as dirname14, join as join16, resolve as resolve13 } from "node:path";
|
|
18732
18921
|
|
|
18733
18922
|
// src/sticky-routing.ts
|
|
18734
18923
|
import { createHash as createHash16, randomUUID as randomUUID13 } from "node:crypto";
|
|
18735
18924
|
import { mkdir as mkdir9, readFile as readFile8, rename as rename11, rm as rm6, stat as stat10, writeFile as writeFile3 } from "node:fs/promises";
|
|
18736
|
-
import { basename as
|
|
18925
|
+
import { basename as basename7, dirname as dirname13, join as join15 } from "node:path";
|
|
18737
18926
|
|
|
18738
18927
|
// src/native-vault-seed.ts
|
|
18739
18928
|
import { lstat as lstat7, readFile as readFile7 } from "node:fs/promises";
|
|
@@ -22726,7 +22915,7 @@ var nativeQuotaCodec = {
|
|
|
22726
22915
|
import { randomUUID as randomUUID12 } from "node:crypto";
|
|
22727
22916
|
import { constants as constants2 } from "node:fs";
|
|
22728
22917
|
import { lstat as lstat6, mkdir as mkdir8, open as open8, rename as rename10, rm as rm5 } from "node:fs/promises";
|
|
22729
|
-
import { basename as
|
|
22918
|
+
import { basename as basename6, dirname as dirname12, isAbsolute as isAbsolute4, join as join14 } from "node:path";
|
|
22730
22919
|
import { types as utilTypes5 } from "node:util";
|
|
22731
22920
|
|
|
22732
22921
|
// src/pool-binding.ts
|
|
@@ -23336,7 +23525,7 @@ async function writeNativeRuntimeOutcome(path2, storageId, change, hooks, firstI
|
|
|
23336
23525
|
assertTransitions(current, next, firstIdentity);
|
|
23337
23526
|
const bytes = `${JSON.stringify(next, null, 2)}
|
|
23338
23527
|
`;
|
|
23339
|
-
const stage = join14(dirname12(path2), `${
|
|
23528
|
+
const stage = join14(dirname12(path2), `${basename6(path2)}.native-runtime.${randomUUID12()}.partial`);
|
|
23340
23529
|
let ownsStage = false;
|
|
23341
23530
|
try {
|
|
23342
23531
|
const nativeCreated = await createWindowsOwnerOnly(stage, bytes);
|
|
@@ -24875,7 +25064,7 @@ function stickyRetainRetryHeaders(upstream, now = Date.now()) {
|
|
|
24875
25064
|
return headers;
|
|
24876
25065
|
}
|
|
24877
25066
|
function getStickyRoutingStatePath(accountStoragePath) {
|
|
24878
|
-
const name =
|
|
25067
|
+
const name = basename7(accountStoragePath);
|
|
24879
25068
|
const stem = name.endsWith(".json") ? name.slice(0, -5) : name;
|
|
24880
25069
|
return join15(dirname13(accountStoragePath), `${stem}-routing-state.json`);
|
|
24881
25070
|
}
|
|
@@ -25313,7 +25502,7 @@ class StickySessionRouter {
|
|
|
25313
25502
|
storage: input.storage,
|
|
25314
25503
|
now: this.now()
|
|
25315
25504
|
}) > 0) : undefined;
|
|
25316
|
-
const selected = preferred ?? this.selectCandidate({ ...input, candidates, state });
|
|
25505
|
+
const selected = input.routingAccountId ? candidates.find((row) => row.accountId === input.routingAccountId) : preferred ?? this.selectCandidate({ ...input, candidates, state });
|
|
25317
25506
|
if (!selected) {
|
|
25318
25507
|
if (current && !input.preserveOnNoCandidate) {
|
|
25319
25508
|
delete state.assignments[key];
|
|
@@ -25370,10 +25559,10 @@ async function canonicalPath(path2) {
|
|
|
25370
25559
|
const parent = dirname14(absolute);
|
|
25371
25560
|
if (parent === absolute)
|
|
25372
25561
|
return absolute;
|
|
25373
|
-
return join16(await canonicalPath(parent),
|
|
25562
|
+
return join16(await canonicalPath(parent), basename8(absolute));
|
|
25374
25563
|
}
|
|
25375
25564
|
function sibling(path2, legacyName, name, suffix) {
|
|
25376
|
-
return
|
|
25565
|
+
return basename8(path2) === legacyName ? join16(dirname14(path2), name) : `${path2}.${suffix}.json`;
|
|
25377
25566
|
}
|
|
25378
25567
|
async function resolveNativePoolPaths(legacyConfig = getAccountStoragePath(), legacyState = getAccountStatePath(legacyConfig), layout) {
|
|
25379
25568
|
const [sourceConfig, sourceState] = await Promise.all([
|
|
@@ -25423,7 +25612,7 @@ async function resolveNativePoolPaths(legacyConfig = getAccountStoragePath(), le
|
|
|
25423
25612
|
|
|
25424
25613
|
// src/native-vault-paths.ts
|
|
25425
25614
|
function sibling2(path2, expected, name, suffix) {
|
|
25426
|
-
return
|
|
25615
|
+
return basename9(path2) === expected ? join17(dirname15(path2), name) : path2.replace(/(?:\.json)?$/, `.${suffix}.json`);
|
|
25427
25616
|
}
|
|
25428
25617
|
function nativeVaultPaths(local, layout = stateLayoutOfPaths(local)) {
|
|
25429
25618
|
const config = sibling2(local.legacyConfig, "anthropic-auth.json", "anthropic-auth-vault-settings.json", "vault-settings");
|
|
@@ -25694,7 +25883,7 @@ class StateLayoutLockStack {
|
|
|
25694
25883
|
|
|
25695
25884
|
// src/state-layout-record.ts
|
|
25696
25885
|
import { randomUUID as randomUUID14 } from "node:crypto";
|
|
25697
|
-
import { lstat as lstat9, readFile as readFile10, unlink as
|
|
25886
|
+
import { lstat as lstat9, readFile as readFile10, unlink as unlink7 } from "node:fs/promises";
|
|
25698
25887
|
import { join as join18 } from "node:path";
|
|
25699
25888
|
var RELOCATION_ROLES = [
|
|
25700
25889
|
"localPoolState",
|
|
@@ -25915,7 +26104,7 @@ async function publishStateLayoutRecord(record11, guard, fs3) {
|
|
|
25915
26104
|
if (outcome === "skipped")
|
|
25916
26105
|
throw new Error(`anthropic-auth could not publish ${path2}`);
|
|
25917
26106
|
} catch (error) {
|
|
25918
|
-
await
|
|
26107
|
+
await unlink7(stage).catch(() => {});
|
|
25919
26108
|
throw error;
|
|
25920
26109
|
}
|
|
25921
26110
|
await fs3.syncDirectory(record11.sub);
|
|
@@ -26264,9 +26453,9 @@ function nativeHolderDatasetFiles(paths) {
|
|
|
26264
26453
|
].sort();
|
|
26265
26454
|
}
|
|
26266
26455
|
function isDestinationShapedDirectory(dir) {
|
|
26267
|
-
const name =
|
|
26456
|
+
const name = basename10(dir);
|
|
26268
26457
|
const parent = dirname17(dir);
|
|
26269
|
-
return (name === "opencode" || /^opencode-[0-9a-f]{16}$/.test(name)) &&
|
|
26458
|
+
return (name === "opencode" || /^opencode-[0-9a-f]{16}$/.test(name)) && basename10(parent) === "anthropic-auth" && basename10(dirname17(parent)) === "cortexkit";
|
|
26270
26459
|
}
|
|
26271
26460
|
function openCodeHolderKind(env = process.env) {
|
|
26272
26461
|
return env.OPENCODE_ANTHROPIC_AUTH_FILE?.trim() || env.OPENCODE_ANTHROPIC_AUTH_STATE_FILE?.trim() ? "explicit" : "legacy";
|
|
@@ -26833,7 +27022,7 @@ class CacheKeepSessionRegistry {
|
|
|
26833
27022
|
async recordPaths() {
|
|
26834
27023
|
return (await Promise.all(this.directories.map(async (directory) => {
|
|
26835
27024
|
try {
|
|
26836
|
-
return (await
|
|
27025
|
+
return (await readdir4(directory)).filter((name) => name.endsWith(".json")).map((name) => join21(directory, name));
|
|
26837
27026
|
} catch {
|
|
26838
27027
|
return [];
|
|
26839
27028
|
}
|
|
@@ -26919,7 +27108,7 @@ class CacheKeepSessionRegistry {
|
|
|
26919
27108
|
// src/cachekeep-store.ts
|
|
26920
27109
|
import { createHash as createHash20, randomUUID as randomUUID17 } from "node:crypto";
|
|
26921
27110
|
import { constants as constants3 } from "node:fs";
|
|
26922
|
-
import { lstat as lstat14, mkdir as mkdir12, open as open10, readdir as
|
|
27111
|
+
import { lstat as lstat14, mkdir as mkdir12, open as open10, readdir as readdir5, rm as rm8, writeFile as writeFile5 } from "node:fs/promises";
|
|
26923
27112
|
import { tmpdir as tmpdir7 } from "node:os";
|
|
26924
27113
|
import { join as join22 } from "node:path";
|
|
26925
27114
|
import { promisify } from "node:util";
|
|
@@ -27072,7 +27261,7 @@ class CacheKeepStore {
|
|
|
27072
27261
|
let directory = this.directory;
|
|
27073
27262
|
const firstLoad = !this.legacyLoadAttempted;
|
|
27074
27263
|
this.legacyLoadAttempted = true;
|
|
27075
|
-
if (!this.options.host && firstLoad && (await
|
|
27264
|
+
if (!this.options.host && firstLoad && (await readdir5(directory)).length === 0) {
|
|
27076
27265
|
const legacy = legacyCacheKeepStoreDirectory(this.options.storageId, this.options.legacyRoot ?? this.options.root);
|
|
27077
27266
|
try {
|
|
27078
27267
|
await lstat14(legacy);
|
|
@@ -27086,7 +27275,7 @@ class CacheKeepStore {
|
|
|
27086
27275
|
let restored = 0;
|
|
27087
27276
|
let dropped = 0;
|
|
27088
27277
|
try {
|
|
27089
|
-
for (const name of (await
|
|
27278
|
+
for (const name of (await readdir5(directory)).sort()) {
|
|
27090
27279
|
if (!FILE.test(name) && !TEMP.test(name))
|
|
27091
27280
|
continue;
|
|
27092
27281
|
const release2 = claim ? await claim(name.slice(0, 64)) : undefined;
|
|
@@ -27240,7 +27429,7 @@ class CacheKeepStore {
|
|
|
27240
27429
|
this.latest.clear();
|
|
27241
27430
|
this.lastWrite.clear();
|
|
27242
27431
|
this.enqueue(async () => {
|
|
27243
|
-
for (const name of await
|
|
27432
|
+
for (const name of await readdir5(this.directory))
|
|
27244
27433
|
if (FILE.test(name) || TEMP.test(name))
|
|
27245
27434
|
await rm8(join22(this.directory, name), { force: true });
|
|
27246
27435
|
});
|
|
@@ -37086,7 +37275,7 @@ function relayGeneration(input) {
|
|
|
37086
37275
|
}
|
|
37087
37276
|
// src/native-host-auth-write.ts
|
|
37088
37277
|
import { randomUUID as randomUUID21 } from "node:crypto";
|
|
37089
|
-
import { lstat as lstat16, open as open12, rename as rename13, unlink as
|
|
37278
|
+
import { lstat as lstat16, open as open12, rename as rename13, unlink as unlink8 } from "node:fs/promises";
|
|
37090
37279
|
import { dirname as dirname19, isAbsolute as isAbsolute6, join as join23 } from "node:path";
|
|
37091
37280
|
class NativeHostAuthWriteError extends Error {
|
|
37092
37281
|
code;
|
|
@@ -37170,7 +37359,7 @@ async function writeNativeHostAuth(input, hooks = {}) {
|
|
|
37170
37359
|
await barrier(beforeRename, "hook-failed");
|
|
37171
37360
|
await barrier(processFence, "process-fence-refused");
|
|
37172
37361
|
if (removingFile) {
|
|
37173
|
-
await
|
|
37362
|
+
await unlink8(authPath);
|
|
37174
37363
|
effect = outcome;
|
|
37175
37364
|
await barrier(afterUnlink, "hook-failed", effect);
|
|
37176
37365
|
} else {
|
|
@@ -37200,7 +37389,7 @@ async function writeNativeHostAuth(input, hooks = {}) {
|
|
|
37200
37389
|
try {
|
|
37201
37390
|
const current = await lstat16(stage);
|
|
37202
37391
|
if (current.dev === ownedStage.dev && current.ino === ownedStage.ino)
|
|
37203
|
-
await
|
|
37392
|
+
await unlink8(stage);
|
|
37204
37393
|
} catch {}
|
|
37205
37394
|
}
|
|
37206
37395
|
}
|
|
@@ -37208,7 +37397,7 @@ async function writeNativeHostAuth(input, hooks = {}) {
|
|
|
37208
37397
|
|
|
37209
37398
|
// src/native-migration.ts
|
|
37210
37399
|
import { createHash as createHash25 } from "node:crypto";
|
|
37211
|
-
import { lstat as lstat17, mkdir as mkdir13, unlink as
|
|
37400
|
+
import { lstat as lstat17, mkdir as mkdir13, unlink as unlink9 } from "node:fs/promises";
|
|
37212
37401
|
import { dirname as dirname20, isAbsolute as isAbsolute7 } from "node:path";
|
|
37213
37402
|
class NativeMigrationError extends Error {
|
|
37214
37403
|
code;
|
|
@@ -37637,7 +37826,7 @@ async function retire(input, journal, assertOwned, hooks) {
|
|
|
37637
37826
|
await requireUnchangedNativeMigrationSource(snapshot);
|
|
37638
37827
|
await input.processFence();
|
|
37639
37828
|
await assertOwned();
|
|
37640
|
-
await
|
|
37829
|
+
await unlink9(snapshot.path);
|
|
37641
37830
|
await hooks.onStep?.(`after:retire:${snapshot.role}`);
|
|
37642
37831
|
}
|
|
37643
37832
|
return advanceNativeMigration(input.paths, "committed", "retired", {
|
|
@@ -40465,7 +40654,7 @@ function placeholderSecret(integrationID) {
|
|
|
40465
40654
|
// ../../node_modules/@cortexkit/common-auth/dist/pi-slot/slot.js
|
|
40466
40655
|
import { createHash as createHash26 } from "node:crypto";
|
|
40467
40656
|
import { constants as constants5 } from "node:fs";
|
|
40468
|
-
import { lstat as lstat18, mkdir as mkdir15, open as open13, unlink as
|
|
40657
|
+
import { lstat as lstat18, mkdir as mkdir15, open as open13, unlink as unlink10 } from "node:fs/promises";
|
|
40469
40658
|
import { dirname as dirname21, resolve as resolve16 } from "node:path";
|
|
40470
40659
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
40471
40660
|
|
|
@@ -40944,7 +41133,7 @@ function createPiSlot(options, onStep, hooks) {
|
|
|
40944
41133
|
}
|
|
40945
41134
|
async function deleteStash(assertLock) {
|
|
40946
41135
|
assertLock();
|
|
40947
|
-
await
|
|
41136
|
+
await unlink10(stashPath);
|
|
40948
41137
|
await syncDir(dirname21(stashPath));
|
|
40949
41138
|
onStep?.("stash-deleted");
|
|
40950
41139
|
}
|
|
@@ -41145,7 +41334,7 @@ function createAnthropicOAuthFetch(options = {}) {
|
|
|
41145
41334
|
// src/prime.ts
|
|
41146
41335
|
import { createHash as createHash27 } from "node:crypto";
|
|
41147
41336
|
import { realpathSync as realpathSync3 } from "node:fs";
|
|
41148
|
-
import { mkdir as mkdir16, readdir as
|
|
41337
|
+
import { mkdir as mkdir16, readdir as readdir6, rm as rm9, stat as stat12, writeFile as writeFile6 } from "node:fs/promises";
|
|
41149
41338
|
import { tmpdir as tmpdir8 } from "node:os";
|
|
41150
41339
|
import { join as join25, resolve as resolve18 } from "node:path";
|
|
41151
41340
|
var CLAUDE_PRIME_COMMAND_NAME = "claude-prime";
|
|
@@ -41687,7 +41876,7 @@ class PrimeManager {
|
|
|
41687
41876
|
}
|
|
41688
41877
|
async readMarkerNames(dir) {
|
|
41689
41878
|
try {
|
|
41690
|
-
return await
|
|
41879
|
+
return await readdir6(dir);
|
|
41691
41880
|
} catch (error) {
|
|
41692
41881
|
if (error.code === "ENOENT")
|
|
41693
41882
|
return [];
|
|
@@ -41712,7 +41901,7 @@ class PrimeManager {
|
|
|
41712
41901
|
const dir = this.markerDir(accountFingerprint);
|
|
41713
41902
|
const prefix = `${encodeURIComponent(accountId2)}-`;
|
|
41714
41903
|
try {
|
|
41715
|
-
return (await
|
|
41904
|
+
return (await readdir6(dir)).some((entry2) => entry2.startsWith(prefix));
|
|
41716
41905
|
} catch (error) {
|
|
41717
41906
|
if (error.code === "ENOENT")
|
|
41718
41907
|
return false;
|
|
@@ -41824,7 +42013,7 @@ class PrimeManager {
|
|
|
41824
42013
|
async sweepMarkerDirectory(dir, now) {
|
|
41825
42014
|
let entries;
|
|
41826
42015
|
try {
|
|
41827
|
-
entries = await
|
|
42016
|
+
entries = await readdir6(dir);
|
|
41828
42017
|
} catch {
|
|
41829
42018
|
return 0;
|
|
41830
42019
|
}
|
|
@@ -41858,7 +42047,7 @@ import {
|
|
|
41858
42047
|
chmod as chmod3,
|
|
41859
42048
|
lstat as lstat19,
|
|
41860
42049
|
mkdir as mkdir17,
|
|
41861
|
-
readdir as
|
|
42050
|
+
readdir as readdir7,
|
|
41862
42051
|
readFile as readFile13,
|
|
41863
42052
|
rename as rename14,
|
|
41864
42053
|
rm as rm10,
|
|
@@ -42085,7 +42274,7 @@ class QuotaHeaderFeedRegistry {
|
|
|
42085
42274
|
const leaseMs = this.options.leaseMs ?? QUOTA_HEADER_FEED_LEASE_MS;
|
|
42086
42275
|
let names2;
|
|
42087
42276
|
try {
|
|
42088
|
-
names2 = await
|
|
42277
|
+
names2 = await readdir7(directory);
|
|
42089
42278
|
} catch {
|
|
42090
42279
|
return;
|
|
42091
42280
|
}
|
|
@@ -42112,7 +42301,7 @@ class QuotaHeaderFeedRegistry {
|
|
|
42112
42301
|
const leaseMs = this.options.leaseMs ?? QUOTA_HEADER_FEED_LEASE_MS;
|
|
42113
42302
|
let names2;
|
|
42114
42303
|
try {
|
|
42115
|
-
names2 = (await
|
|
42304
|
+
names2 = (await readdir7(directory)).filter((name) => name.endsWith(".json"));
|
|
42116
42305
|
} catch {
|
|
42117
42306
|
return [];
|
|
42118
42307
|
}
|
|
@@ -42300,7 +42489,7 @@ function buildClaudeQuotaSummary(input) {
|
|
|
42300
42489
|
}
|
|
42301
42490
|
// src/request-gzip.ts
|
|
42302
42491
|
import { mkdir as mkdir18, readFile as readFile14, rename as rename15, rm as rm11, writeFile as writeFile8 } from "node:fs/promises";
|
|
42303
|
-
import { basename as
|
|
42492
|
+
import { basename as basename11, dirname as dirname23, join as join27 } from "node:path";
|
|
42304
42493
|
import { promisify as promisify2 } from "node:util";
|
|
42305
42494
|
import { gzip as gzip2 } from "node:zlib";
|
|
42306
42495
|
var gzipAsync = promisify2(gzip2);
|
|
@@ -42446,7 +42635,7 @@ function getRequestGzipLatch(path2) {
|
|
|
42446
42635
|
function getRequestGzipLatchPath(accountStoragePath, layout = LEGACY_STATE_LAYOUT) {
|
|
42447
42636
|
if (layout.kind === "state-home")
|
|
42448
42637
|
return stateHomeFilePaths(layout.dir).requestGzip;
|
|
42449
|
-
const name =
|
|
42638
|
+
const name = basename11(accountStoragePath);
|
|
42450
42639
|
const stem = name.endsWith(".json") ? name.slice(0, -5) : name;
|
|
42451
42640
|
return join27(dirname23(accountStoragePath), `${stem}-request-gzip.json`);
|
|
42452
42641
|
}
|
|
@@ -42671,6 +42860,185 @@ function peekRoutingAccount(input) {
|
|
|
42671
42860
|
}
|
|
42672
42861
|
return;
|
|
42673
42862
|
}
|
|
42863
|
+
// src/routing-reports.ts
|
|
42864
|
+
var ROUTING_POOL_NAME = /^[a-z0-9._-]{1,64}$/;
|
|
42865
|
+
function reportRoutingResponse(sessionId, subject, headers, status, modelId, served = status < 400, quotaFor) {
|
|
42866
|
+
Promise.resolve().then(async () => {
|
|
42867
|
+
if (!subject.accountIdentity || typeof Reflect.get(globalThis, Symbol.for("cortexkit.routing")) !== "function")
|
|
42868
|
+
return;
|
|
42869
|
+
const identity4 = {
|
|
42870
|
+
sessionId,
|
|
42871
|
+
accountId: subject.accountIdentity,
|
|
42872
|
+
...subject.credentialId ? { credentialId: subject.credentialId } : {}
|
|
42873
|
+
};
|
|
42874
|
+
const reports = [];
|
|
42875
|
+
if (served && status < 400) {
|
|
42876
|
+
const rateHeaders = {};
|
|
42877
|
+
headers.forEach((value, name) => {
|
|
42878
|
+
if (name.toLowerCase().startsWith("anthropic-ratelimit-"))
|
|
42879
|
+
rateHeaders[name.toLowerCase()] = value;
|
|
42880
|
+
});
|
|
42881
|
+
reports.push({ ...identity4, outcome: "served", headers: rateHeaders });
|
|
42882
|
+
}
|
|
42883
|
+
const quota2 = status === 429 ? quotaExhaustionFromHeaders(headers, modelId) : undefined;
|
|
42884
|
+
if (quota2) {
|
|
42885
|
+
for (const [window2, reading2] of [
|
|
42886
|
+
["5h", quota2.five_hour],
|
|
42887
|
+
["7d", quota2.seven_day]
|
|
42888
|
+
]) {
|
|
42889
|
+
if (reading2)
|
|
42890
|
+
reports.push({
|
|
42891
|
+
...identity4,
|
|
42892
|
+
outcome: "exhausted",
|
|
42893
|
+
window: window2,
|
|
42894
|
+
...reading2.resetsAt ? { resetsAt: Date.parse(reading2.resetsAt) } : {}
|
|
42895
|
+
});
|
|
42896
|
+
}
|
|
42897
|
+
}
|
|
42898
|
+
for (const report2 of reports)
|
|
42899
|
+
reportRouting(report2);
|
|
42900
|
+
if (quota2?.scoped?.length) {
|
|
42901
|
+
const stored = await quotaFor?.();
|
|
42902
|
+
const scoped = getScopedQuotaWindowForModel({
|
|
42903
|
+
scoped: stored?.scoped?.filter((row) => row.id.startsWith("claude-weekly-scoped-"))
|
|
42904
|
+
}, modelId);
|
|
42905
|
+
const pool = (scoped?.modelId ?? scoped?.modelName)?.trim().toLowerCase();
|
|
42906
|
+
if (!pool || !ROUTING_POOL_NAME.test(pool))
|
|
42907
|
+
return;
|
|
42908
|
+
for (const reading2 of quota2.scoped)
|
|
42909
|
+
reportRouting({
|
|
42910
|
+
...identity4,
|
|
42911
|
+
outcome: "exhausted",
|
|
42912
|
+
window: "7d",
|
|
42913
|
+
pool,
|
|
42914
|
+
...reading2.resetsAt ? { resetsAt: Date.parse(reading2.resetsAt) } : {}
|
|
42915
|
+
});
|
|
42916
|
+
}
|
|
42917
|
+
}).catch(() => {});
|
|
42918
|
+
}
|
|
42919
|
+
|
|
42920
|
+
// src/routing-relay.ts
|
|
42921
|
+
var ROUTING_HOLD_LIMIT_MS = 15 * 60000 + 20000;
|
|
42922
|
+
function routingCandidates(accounts) {
|
|
42923
|
+
return accounts.filter((account) => account.type === "oauth" && nativeAccountCanServe(account));
|
|
42924
|
+
}
|
|
42925
|
+
function routingChoiceMatches(choice, account) {
|
|
42926
|
+
return account.accountIdentity === choice.account_id && (account.credentialId ?? "local") === choice.credential_id;
|
|
42927
|
+
}
|
|
42928
|
+
|
|
42929
|
+
class RoutingRefusalError extends Error {
|
|
42930
|
+
code;
|
|
42931
|
+
retryAfterSecs;
|
|
42932
|
+
status;
|
|
42933
|
+
constructor(refusal2, now = Date.now()) {
|
|
42934
|
+
super(refusal2.code === "account_selection_final" ? "Shared routing refused an account for this request." : "Shared routing has no account for this request right now.");
|
|
42935
|
+
this.name = "RoutingRefusalError";
|
|
42936
|
+
this.code = refusal2.code;
|
|
42937
|
+
this.status = refusal2.code === "account_selection_final" ? 403 : 429;
|
|
42938
|
+
this.retryAfterSecs = this.status === 429 ? refusal2.retryAfterSecs ?? (refusal2.resetsAtMs === undefined ? undefined : Math.max(0, Math.ceil((refusal2.resetsAtMs - now) / 1000))) : undefined;
|
|
42939
|
+
}
|
|
42940
|
+
response() {
|
|
42941
|
+
return new Response(JSON.stringify({
|
|
42942
|
+
type: "error",
|
|
42943
|
+
error: {
|
|
42944
|
+
type: this.status === 429 ? "rate_limit_error" : "permission_error",
|
|
42945
|
+
code: this.code,
|
|
42946
|
+
message: this.message
|
|
42947
|
+
}
|
|
42948
|
+
}), {
|
|
42949
|
+
status: this.status,
|
|
42950
|
+
headers: {
|
|
42951
|
+
"content-type": "application/json",
|
|
42952
|
+
...this.retryAfterSecs === undefined ? {} : { "retry-after": String(this.retryAfterSecs) }
|
|
42953
|
+
}
|
|
42954
|
+
});
|
|
42955
|
+
}
|
|
42956
|
+
}
|
|
42957
|
+
function createRoutingRelay(quotaFor) {
|
|
42958
|
+
const overridden = new Set;
|
|
42959
|
+
const admissions = new Map;
|
|
42960
|
+
const silenced = new Set;
|
|
42961
|
+
const override = (sessionId, reason) => {
|
|
42962
|
+
if (admissions.delete(sessionId)) {
|
|
42963
|
+
if (silenced.size >= 512) {
|
|
42964
|
+
const first = silenced.values().next();
|
|
42965
|
+
if (!first.done)
|
|
42966
|
+
silenced.delete(first.value);
|
|
42967
|
+
}
|
|
42968
|
+
silenced.add(sessionId);
|
|
42969
|
+
}
|
|
42970
|
+
if (overridden.has(sessionId))
|
|
42971
|
+
return;
|
|
42972
|
+
if (overridden.size >= 512) {
|
|
42973
|
+
const first = overridden.values().next();
|
|
42974
|
+
if (!first.done)
|
|
42975
|
+
overridden.delete(first.value);
|
|
42976
|
+
}
|
|
42977
|
+
overridden.add(sessionId);
|
|
42978
|
+
logger2.debug("routing-relay", "Using local account choice", {
|
|
42979
|
+
sessionId,
|
|
42980
|
+
reason
|
|
42981
|
+
});
|
|
42982
|
+
};
|
|
42983
|
+
return {
|
|
42984
|
+
override,
|
|
42985
|
+
shouldReport(sessionId) {
|
|
42986
|
+
return !silenced.has(sessionId);
|
|
42987
|
+
},
|
|
42988
|
+
admitted(sessionId, subject) {
|
|
42989
|
+
const choice = admissions.get(sessionId);
|
|
42990
|
+
return !!choice && routingChoiceMatches(choice, subject);
|
|
42991
|
+
},
|
|
42992
|
+
policy(sessionId, account, snapshot, modelId) {
|
|
42993
|
+
const choice = admissions.get(sessionId);
|
|
42994
|
+
return choice && routingChoiceMatches(choice, account) && nativeAccountCanServe(account) ? { status: "allowed" } : nativeAccountPolicy(account, snapshot, modelId);
|
|
42995
|
+
},
|
|
42996
|
+
async accountFor(sessionId, modelId, candidates) {
|
|
42997
|
+
admissions.delete(sessionId);
|
|
42998
|
+
silenced.delete(sessionId);
|
|
42999
|
+
const result = await askRouting({
|
|
43000
|
+
sessionId,
|
|
43001
|
+
provider: "anthropic",
|
|
43002
|
+
modelId,
|
|
43003
|
+
deadlineMs: 2000,
|
|
43004
|
+
refusals: true,
|
|
43005
|
+
candidates: candidates.flatMap((row) => row.accountIdentity ? [
|
|
43006
|
+
{
|
|
43007
|
+
accountId: row.accountIdentity,
|
|
43008
|
+
credentialId: row.credentialId ?? "local"
|
|
43009
|
+
}
|
|
43010
|
+
] : [])
|
|
43011
|
+
});
|
|
43012
|
+
if (!result) {
|
|
43013
|
+
override(sessionId, "no valid answer within routing deadline");
|
|
43014
|
+
return null;
|
|
43015
|
+
}
|
|
43016
|
+
if ("refused" in result)
|
|
43017
|
+
throw new RoutingRefusalError(result.refused);
|
|
43018
|
+
const choice = {
|
|
43019
|
+
account_id: result.candidate.accountId,
|
|
43020
|
+
credential_id: result.candidate.credentialId,
|
|
43021
|
+
...result.hold && result.hold.retry_after_ms > 0 ? {
|
|
43022
|
+
hold: {
|
|
43023
|
+
retry_after_ms: Math.min(result.hold.retry_after_ms, ROUTING_HOLD_LIMIT_MS)
|
|
43024
|
+
}
|
|
43025
|
+
} : {}
|
|
43026
|
+
};
|
|
43027
|
+
if (admissions.size >= 512) {
|
|
43028
|
+
const first = admissions.keys().next();
|
|
43029
|
+
if (!first.done)
|
|
43030
|
+
admissions.delete(first.value);
|
|
43031
|
+
}
|
|
43032
|
+
admissions.set(sessionId, choice);
|
|
43033
|
+
return choice;
|
|
43034
|
+
},
|
|
43035
|
+
report(sessionId, subject, headers, status, modelId, served = status < 400) {
|
|
43036
|
+
if (silenced.has(sessionId))
|
|
43037
|
+
return;
|
|
43038
|
+
reportRoutingResponse(sessionId, subject, headers, status, modelId, served, quotaFor ? () => quotaFor(subject) : undefined);
|
|
43039
|
+
}
|
|
43040
|
+
};
|
|
43041
|
+
}
|
|
42674
43042
|
// src/start.ts
|
|
42675
43043
|
var CLAUDE_START_COMMAND_NAME = "claude-start";
|
|
42676
43044
|
var START_STATUS_TITLE = "## Claude Lane Start Status";
|
|
@@ -42704,14 +43072,14 @@ function executeLaneStartCommand(input) {
|
|
|
42704
43072
|
};
|
|
42705
43073
|
}
|
|
42706
43074
|
// src/state-layout-decision.ts
|
|
42707
|
-
import { mkdir as mkdir19, readdir as
|
|
43075
|
+
import { mkdir as mkdir19, readdir as readdir10 } from "node:fs/promises";
|
|
42708
43076
|
import { homedir as homedir8 } from "node:os";
|
|
42709
|
-
import { basename as
|
|
43077
|
+
import { basename as basename14, dirname as dirname25, join as join31 } from "node:path";
|
|
42710
43078
|
|
|
42711
43079
|
// src/layout-fence.ts
|
|
42712
|
-
import { open as open14, readdir as
|
|
43080
|
+
import { open as open14, readdir as readdir8 } from "node:fs/promises";
|
|
42713
43081
|
import { homedir as homedir6 } from "node:os";
|
|
42714
|
-
import { basename as
|
|
43082
|
+
import { basename as basename12, join as join28, resolve as resolve19 } from "node:path";
|
|
42715
43083
|
var STATE_PATH_OVERRIDE_VARIABLES = [
|
|
42716
43084
|
"OPENCODE_ANTHROPIC_AUTH_FILE",
|
|
42717
43085
|
"OPENCODE_ANTHROPIC_AUTH_STATE_FILE",
|
|
@@ -42813,7 +43181,7 @@ function defaultPreNArtifactLocations(env = process.env, home = homedir6()) {
|
|
|
42813
43181
|
}
|
|
42814
43182
|
async function listDir(dir, blockers) {
|
|
42815
43183
|
try {
|
|
42816
|
-
return await
|
|
43184
|
+
return await readdir8(dir);
|
|
42817
43185
|
} catch (error) {
|
|
42818
43186
|
if (errorCode5(error) === "ENOENT")
|
|
42819
43187
|
return [];
|
|
@@ -42896,7 +43264,7 @@ async function preNArtifactBlockers(locations, pidAlive2 = defaultLiveness2.pidA
|
|
|
42896
43264
|
function describeFenceBlocker(blocker) {
|
|
42897
43265
|
switch (blocker.kind) {
|
|
42898
43266
|
case "holder":
|
|
42899
|
-
return `pid ${blocker.pid ?? "unknown"} (${blocker.role ?? "unknown role"}) in ${
|
|
43267
|
+
return `pid ${blocker.pid ?? "unknown"} (${blocker.role ?? "unknown role"}) in ${basename12(blocker.holderFile)} uses ${blocker.file ?? "an unreadable file list"}`;
|
|
42900
43268
|
case "holder-file":
|
|
42901
43269
|
return `${blocker.holderFile} can't be read (${blocker.reason})`;
|
|
42902
43270
|
case "pre-n-artifact":
|
|
@@ -42910,8 +43278,8 @@ function describeFenceBlocker(blocker) {
|
|
|
42910
43278
|
|
|
42911
43279
|
// src/state-layout-move.ts
|
|
42912
43280
|
import { randomUUID as randomUUID23 } from "node:crypto";
|
|
42913
|
-
import { lstat as lstat20, readdir as
|
|
42914
|
-
import { basename as
|
|
43281
|
+
import { lstat as lstat20, readdir as readdir9, readFile as readFile15, stat as stat14, unlink as unlink11 } from "node:fs/promises";
|
|
43282
|
+
import { basename as basename13, dirname as dirname24, join as join29, sep as sep2 } from "node:path";
|
|
42915
43283
|
var ACCOUNT_FILE = "anthropic-auth.json";
|
|
42916
43284
|
var ACCOUNT_STATE_FILE = "anthropic-auth-state.json";
|
|
42917
43285
|
var LAYOUT_LOCK_NAME = "runtime-layout";
|
|
@@ -43213,7 +43581,7 @@ async function removeOwnStaging(path2) {
|
|
|
43213
43581
|
try {
|
|
43214
43582
|
const info = await lstat20(path2);
|
|
43215
43583
|
if (info.isFile())
|
|
43216
|
-
await
|
|
43584
|
+
await unlink11(path2);
|
|
43217
43585
|
} catch (error) {
|
|
43218
43586
|
if (errorCode6(error) !== "ENOENT")
|
|
43219
43587
|
throw error;
|
|
@@ -43265,7 +43633,7 @@ async function movePreconditionFailure(dataset, platform) {
|
|
|
43265
43633
|
if (platform !== "win32" && typeof process.getuid === "function" && info.uid !== process.getuid())
|
|
43266
43634
|
return `${path2} belongs to another user`;
|
|
43267
43635
|
}
|
|
43268
|
-
if (dirname24(slot.from) !== dataset.oldDir ||
|
|
43636
|
+
if (dirname24(slot.from) !== dataset.oldDir || basename13(slot.from) !== basename13(slot.configured))
|
|
43269
43637
|
return `${slot.configured} resolves to ${slot.from}, not to a file of its own in the config folder`;
|
|
43270
43638
|
const fromExists = await exists3(slot.from);
|
|
43271
43639
|
anyOld ||= fromExists;
|
|
@@ -43409,7 +43777,7 @@ async function rollbackPreparing(record13, dataset, ctx) {
|
|
|
43409
43777
|
continue;
|
|
43410
43778
|
await owned2(ctx, { kind: "unlink", path: file.to }, expectDigest(file.to, file.sha256));
|
|
43411
43779
|
}
|
|
43412
|
-
for (const name of await
|
|
43780
|
+
for (const name of await readdir9(dataset.sub))
|
|
43413
43781
|
if (isLayoutRecordStage(name, attempt))
|
|
43414
43782
|
await removeOwnStaging(join29(dataset.sub, name));
|
|
43415
43783
|
await stateLayoutStep(ctx, "rollback:destination-removed");
|
|
@@ -44418,7 +44786,7 @@ async function oldFolderTransition(old, recordedMovingJournal) {
|
|
|
44418
44786
|
}
|
|
44419
44787
|
let names2;
|
|
44420
44788
|
try {
|
|
44421
|
-
names2 = await
|
|
44789
|
+
names2 = await readdir10(dirname25(journal));
|
|
44422
44790
|
} catch (error) {
|
|
44423
44791
|
if (error?.code === "ENOENT")
|
|
44424
44792
|
return false;
|
|
@@ -44431,7 +44799,7 @@ async function oldFolderTransition(old, recordedMovingJournal) {
|
|
|
44431
44799
|
return false;
|
|
44432
44800
|
}
|
|
44433
44801
|
}
|
|
44434
|
-
return names2.some((name) => isMovingJournalName(
|
|
44802
|
+
return names2.some((name) => isMovingJournalName(basename14(journal), name));
|
|
44435
44803
|
}
|
|
44436
44804
|
async function recordedMovingJournal(journal, identity4, options) {
|
|
44437
44805
|
try {
|
|
@@ -45064,6 +45432,8 @@ export {
|
|
|
45064
45432
|
runPiCommandMenu,
|
|
45065
45433
|
runNativeMigration,
|
|
45066
45434
|
runNativeCustodyActivation,
|
|
45435
|
+
routingChoiceMatches,
|
|
45436
|
+
routingCandidates,
|
|
45067
45437
|
restoreLegacyLayout,
|
|
45068
45438
|
resolveStateHomeTarget,
|
|
45069
45439
|
resolveNativePoolPaths,
|
|
@@ -45089,6 +45459,7 @@ export {
|
|
|
45089
45459
|
requestCacheLifetimeMs,
|
|
45090
45460
|
reportSessionCacheWarmStopped,
|
|
45091
45461
|
reportSessionCacheTouch,
|
|
45462
|
+
reportRoutingResponse,
|
|
45092
45463
|
reportRouting,
|
|
45093
45464
|
reportAnthropicBillingFailure,
|
|
45094
45465
|
renameWithWindowsSharingRetry,
|
|
@@ -45374,6 +45745,7 @@ export {
|
|
|
45374
45745
|
createStringPatch,
|
|
45375
45746
|
createStickyNoRouteResponse,
|
|
45376
45747
|
createSseFramer,
|
|
45748
|
+
createRoutingRelay,
|
|
45377
45749
|
createRelocationGuard,
|
|
45378
45750
|
createRelayPatch,
|
|
45379
45751
|
createQuotaRefusalResponse,
|
|
@@ -45483,9 +45855,11 @@ export {
|
|
|
45483
45855
|
SERVER_FALLBACK_USAGE_SIGNATURE_PREFIX,
|
|
45484
45856
|
SERVER_FALLBACK_USAGE_MARKER_TEXT,
|
|
45485
45857
|
SECRET_KEY_EXACT2 as SECRET_KEY_EXACT,
|
|
45858
|
+
RoutingRefusalError,
|
|
45486
45859
|
RequestGzipLatch,
|
|
45487
45860
|
RelocatedError,
|
|
45488
45861
|
ROUTING_MODES,
|
|
45862
|
+
ROUTING_HOLD_LIMIT_MS,
|
|
45489
45863
|
RESTORE_LEGACY_COMMAND,
|
|
45490
45864
|
REQUIRED_BETAS,
|
|
45491
45865
|
RELOCATION_MOVE_ENABLED,
|
|
@@ -45632,6 +46006,7 @@ export {
|
|
|
45632
46006
|
CLAUDE_CODE_FULL_AGENT_BETAS,
|
|
45633
46007
|
CLAUDE_CODE_ENTRYPOINT,
|
|
45634
46008
|
CLAUDE_CODE_DEFAULT_BETAS,
|
|
46009
|
+
CLAUDE_CODE_ACCEPT_ENCODING,
|
|
45635
46010
|
CLAUDE_CACHE_KEEP_COMMAND_NAME,
|
|
45636
46011
|
CLAUDE_ACCOUNT_COMMAND_NAME,
|
|
45637
46012
|
CCH_SALT,
|