@cortexkit/anthropic-auth-core 2.7.0 → 2.7.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/index.js +79 -11
- package/dist/native-custody.d.ts +7 -2
- package/dist/native-vault-runtime.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -17062,7 +17062,7 @@ class CacheKeepManager2 {
|
|
|
17062
17062
|
}
|
|
17063
17063
|
track(input) {
|
|
17064
17064
|
const now = this.options.now?.() ?? Date.now();
|
|
17065
|
-
const acceptedAt = input.acceptedAt ?? now;
|
|
17065
|
+
const acceptedAt = input.acceptedAt ?? input.retained?.lastTouchAt ?? now;
|
|
17066
17066
|
if (input.retained && input.retained.cacheExpiresAt <= now)
|
|
17067
17067
|
return { tracked: false, reason: "cache expired" };
|
|
17068
17068
|
let bodyBytes;
|
|
@@ -17102,7 +17102,7 @@ class CacheKeepManager2 {
|
|
|
17102
17102
|
this.removeTarget(previous, reason, now);
|
|
17103
17103
|
return refuse(reason, reason);
|
|
17104
17104
|
};
|
|
17105
|
-
if (input.retained && (planned || isCacheKeepAlways(input.storage)) &&
|
|
17105
|
+
if (input.retained && (planned || isCacheKeepAlways(input.storage)) && input.retained.policyState?.needsRealRequest)
|
|
17106
17106
|
return retire("unsupported");
|
|
17107
17107
|
if (!policy && (input.retained?.policyState?.planned || previous?.policyState?.planned))
|
|
17108
17108
|
return retire("session-ended");
|
|
@@ -17189,8 +17189,7 @@ class CacheKeepManager2 {
|
|
|
17189
17189
|
lastRealRequestAt: acceptedAt,
|
|
17190
17190
|
warmsSinceLastRealRequest: 0,
|
|
17191
17191
|
warmCostSoFar: 0,
|
|
17192
|
-
hasWarmed: previous?.policyState?.hasWarmed ?? false
|
|
17193
|
-
...input.retained && { needsRealRequest: true }
|
|
17192
|
+
hasWarmed: input.retained ? false : previous?.policyState?.hasWarmed ?? false
|
|
17194
17193
|
},
|
|
17195
17194
|
...input.sourceWarm === true && { sourceWarm: true }
|
|
17196
17195
|
});
|
|
@@ -28643,8 +28642,18 @@ async function readNativeEnrollmentMode(host, env = process.env, dependencies =
|
|
|
28643
28642
|
const paths = getHostClaustrumEnrollmentPaths(host, env);
|
|
28644
28643
|
const authority = await dependencies.enrollmentAuthority(paths, `anthropic-auth-${host}`);
|
|
28645
28644
|
assertHostAuthorityStable();
|
|
28646
|
-
if (authority === "host")
|
|
28645
|
+
if (authority === "host") {
|
|
28646
|
+
const key = `${host}${"\x00"}hosted`;
|
|
28647
|
+
if (!loggedEnrollmentModes.has(key)) {
|
|
28648
|
+
loggedEnrollmentModes.add(key);
|
|
28649
|
+
logger2.info("enrollment", "Native enrollment mode", {
|
|
28650
|
+
host,
|
|
28651
|
+
mode: "hosted",
|
|
28652
|
+
source: "thalamus"
|
|
28653
|
+
});
|
|
28654
|
+
}
|
|
28647
28655
|
return "claustrum";
|
|
28656
|
+
}
|
|
28648
28657
|
if (authority !== "vault")
|
|
28649
28658
|
closeNativeVaultAuthority(getHostClaustrumEnrollmentPaths(host, env).tokenPath);
|
|
28650
28659
|
if (authority === "unreadable") {
|
|
@@ -32216,6 +32225,8 @@ function createNativeVaultRuntime(options) {
|
|
|
32216
32225
|
const generation = owner.generation ?? 0;
|
|
32217
32226
|
const transportEpoch = insulaTransportEpoch;
|
|
32218
32227
|
const assertTransport = () => {
|
|
32228
|
+
if (closing || shutdown.signal.aborted)
|
|
32229
|
+
throw new NativeCustodyError("closed");
|
|
32219
32230
|
assertCustodyOwner(owner, generation);
|
|
32220
32231
|
if (transportEpoch !== insulaTransportEpoch)
|
|
32221
32232
|
throw new NativeCustodyError("route-unavailable");
|
|
@@ -32233,24 +32244,79 @@ function createNativeVaultRuntime(options) {
|
|
|
32233
32244
|
if (!transport)
|
|
32234
32245
|
return;
|
|
32235
32246
|
const acquired = acquireInsulaQuotaSource(transport, hosted2 ? hostedInsulaCacheKey : tokenPath);
|
|
32247
|
+
let held;
|
|
32236
32248
|
try {
|
|
32237
32249
|
assertTransport();
|
|
32238
|
-
if (!insula)
|
|
32239
|
-
|
|
32240
|
-
|
|
32250
|
+
if (!insula) {
|
|
32251
|
+
let released = false;
|
|
32252
|
+
let timer;
|
|
32253
|
+
let unwatch = () => {};
|
|
32254
|
+
held = {
|
|
32255
|
+
source: acquired.source,
|
|
32256
|
+
owner,
|
|
32257
|
+
generation,
|
|
32258
|
+
transportEpoch,
|
|
32259
|
+
release() {
|
|
32260
|
+
if (released)
|
|
32261
|
+
return;
|
|
32262
|
+
released = true;
|
|
32263
|
+
if (timer !== undefined)
|
|
32264
|
+
(options.clearTimeout ?? clearTimeout)(timer);
|
|
32265
|
+
timer = undefined;
|
|
32266
|
+
try {
|
|
32267
|
+
unwatch();
|
|
32268
|
+
} finally {
|
|
32269
|
+
acquired.release();
|
|
32270
|
+
}
|
|
32271
|
+
}
|
|
32272
|
+
};
|
|
32273
|
+
insula = held;
|
|
32274
|
+
const current = held;
|
|
32275
|
+
unwatch = held.source.watch({
|
|
32276
|
+
provider: "claude",
|
|
32277
|
+
setTimeoutImpl: options.setTimeout,
|
|
32278
|
+
clearTimeoutImpl: options.clearTimeout
|
|
32279
|
+
});
|
|
32280
|
+
const schedule2 = () => {
|
|
32281
|
+
if (released || closing || shutdown.signal.aborted)
|
|
32282
|
+
return;
|
|
32283
|
+
timer = (options.setTimeout ?? setTimeout)(() => withDetachedNativeLocks(async () => {
|
|
32284
|
+
timer = undefined;
|
|
32285
|
+
if (released || insula !== current)
|
|
32286
|
+
return;
|
|
32287
|
+
try {
|
|
32288
|
+
assertTransport();
|
|
32289
|
+
} catch {
|
|
32290
|
+
current.release();
|
|
32291
|
+
if (insula === current)
|
|
32292
|
+
insula = undefined;
|
|
32293
|
+
return;
|
|
32294
|
+
}
|
|
32295
|
+
if (current.source.watchMode() !== "watching")
|
|
32296
|
+
await refreshInsula();
|
|
32297
|
+
}).finally(schedule2).catch(() => {}), 60000);
|
|
32298
|
+
timer.unref?.();
|
|
32299
|
+
};
|
|
32300
|
+
schedule2();
|
|
32301
|
+
} else
|
|
32241
32302
|
acquired.release();
|
|
32242
32303
|
} catch (error) {
|
|
32243
|
-
|
|
32304
|
+
if (held) {
|
|
32305
|
+
held.release();
|
|
32306
|
+
if (insula === held)
|
|
32307
|
+
insula = undefined;
|
|
32308
|
+
} else
|
|
32309
|
+
acquired.release();
|
|
32244
32310
|
throw error;
|
|
32245
32311
|
}
|
|
32246
32312
|
}
|
|
32247
32313
|
assertTransport();
|
|
32248
|
-
await insula
|
|
32314
|
+
await insula?.source.refresh(clock());
|
|
32249
32315
|
} catch {}
|
|
32250
32316
|
}
|
|
32251
32317
|
function insulaLookup(accountId) {
|
|
32252
32318
|
assertHostAuthorityStable();
|
|
32253
|
-
if (insula && (insula.owner !== custody || insula.generation !== (custody.generation ?? 0))) {
|
|
32319
|
+
if (insula && (insula.owner !== custody || insula.generation !== (custody.generation ?? 0) || insula.transportEpoch !== insulaTransportEpoch)) {
|
|
32254
32320
|
insula.release();
|
|
32255
32321
|
insula = undefined;
|
|
32256
32322
|
}
|
|
@@ -32835,6 +32901,8 @@ function createNativeVaultRuntime(options) {
|
|
|
32835
32901
|
close() {
|
|
32836
32902
|
if (closing)
|
|
32837
32903
|
return closing;
|
|
32904
|
+
insula?.release();
|
|
32905
|
+
insula = undefined;
|
|
32838
32906
|
watchers.clear();
|
|
32839
32907
|
closeRosterWatch();
|
|
32840
32908
|
schedulePoll();
|
package/dist/native-custody.d.ts
CHANGED
|
@@ -6,6 +6,11 @@
|
|
|
6
6
|
export interface NativeInsulaUsageTransport {
|
|
7
7
|
connectionFile: string;
|
|
8
8
|
getUsage(): Promise<unknown>;
|
|
9
|
+
/** Hold usage.watch open; older/custom transports can omit push support. */
|
|
10
|
+
watchUsage?(onNotice: (body: Uint8Array) => void): {
|
|
11
|
+
stop(): void;
|
|
12
|
+
readonly closed: Promise<void>;
|
|
13
|
+
};
|
|
9
14
|
}
|
|
10
15
|
/** Claustrum IPC operations for listing accounts, reading tokens, reporting rejection, and closing the connection. */
|
|
11
16
|
export interface NativeCustodyClient {
|
|
@@ -70,8 +75,8 @@ export interface NativeCustodyClient {
|
|
|
70
75
|
}): NativeScopedWatchHandle;
|
|
71
76
|
/**
|
|
72
77
|
* How to read insula's background quota cache on the same daemon. Present
|
|
73
|
-
* when the connection was made with connectClaustrumScopedClient;
|
|
74
|
-
*
|
|
78
|
+
* when the connection was made with connectClaustrumScopedClient; reads and
|
|
79
|
+
* watches use separate sockets and never use this connection.
|
|
75
80
|
*/
|
|
76
81
|
insula?: NativeInsulaUsageTransport;
|
|
77
82
|
}
|
|
@@ -24,8 +24,8 @@ export interface NativeVaultRuntimeOptions {
|
|
|
24
24
|
now?: () => number;
|
|
25
25
|
onLockEvent?: (event: NativeLockEvent) => void;
|
|
26
26
|
/**
|
|
27
|
-
* Timer functions for
|
|
28
|
-
*
|
|
27
|
+
* Timer functions for custody probes, watch retries and Insula's minute
|
|
28
|
+
* watchdog. Defaults to the global ones; tests pass their own.
|
|
29
29
|
*/
|
|
30
30
|
setTimeout?: typeof globalThis.setTimeout;
|
|
31
31
|
clearTimeout?: typeof globalThis.clearTimeout;
|