@cortexkit/anthropic-auth-core 2.7.0 → 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -28643,8 +28643,18 @@ async function readNativeEnrollmentMode(host, env = process.env, dependencies =
28643
28643
  const paths = getHostClaustrumEnrollmentPaths(host, env);
28644
28644
  const authority = await dependencies.enrollmentAuthority(paths, `anthropic-auth-${host}`);
28645
28645
  assertHostAuthorityStable();
28646
- if (authority === "host")
28646
+ if (authority === "host") {
28647
+ const key = `${host}${"\x00"}hosted`;
28648
+ if (!loggedEnrollmentModes.has(key)) {
28649
+ loggedEnrollmentModes.add(key);
28650
+ logger2.info("enrollment", "Native enrollment mode", {
28651
+ host,
28652
+ mode: "hosted",
28653
+ source: "thalamus"
28654
+ });
28655
+ }
28647
28656
  return "claustrum";
28657
+ }
28648
28658
  if (authority !== "vault")
28649
28659
  closeNativeVaultAuthority(getHostClaustrumEnrollmentPaths(host, env).tokenPath);
28650
28660
  if (authority === "unreadable") {
@@ -32216,6 +32226,8 @@ function createNativeVaultRuntime(options) {
32216
32226
  const generation = owner.generation ?? 0;
32217
32227
  const transportEpoch = insulaTransportEpoch;
32218
32228
  const assertTransport = () => {
32229
+ if (closing || shutdown.signal.aborted)
32230
+ throw new NativeCustodyError("closed");
32219
32231
  assertCustodyOwner(owner, generation);
32220
32232
  if (transportEpoch !== insulaTransportEpoch)
32221
32233
  throw new NativeCustodyError("route-unavailable");
@@ -32233,24 +32245,79 @@ function createNativeVaultRuntime(options) {
32233
32245
  if (!transport)
32234
32246
  return;
32235
32247
  const acquired = acquireInsulaQuotaSource(transport, hosted2 ? hostedInsulaCacheKey : tokenPath);
32248
+ let held;
32236
32249
  try {
32237
32250
  assertTransport();
32238
- if (!insula)
32239
- insula = { ...acquired, owner, generation, transportEpoch };
32240
- else
32251
+ if (!insula) {
32252
+ let released = false;
32253
+ let timer;
32254
+ let unwatch = () => {};
32255
+ held = {
32256
+ source: acquired.source,
32257
+ owner,
32258
+ generation,
32259
+ transportEpoch,
32260
+ release() {
32261
+ if (released)
32262
+ return;
32263
+ released = true;
32264
+ if (timer !== undefined)
32265
+ (options.clearTimeout ?? clearTimeout)(timer);
32266
+ timer = undefined;
32267
+ try {
32268
+ unwatch();
32269
+ } finally {
32270
+ acquired.release();
32271
+ }
32272
+ }
32273
+ };
32274
+ insula = held;
32275
+ const current = held;
32276
+ unwatch = held.source.watch({
32277
+ provider: "claude",
32278
+ setTimeoutImpl: options.setTimeout,
32279
+ clearTimeoutImpl: options.clearTimeout
32280
+ });
32281
+ const schedule2 = () => {
32282
+ if (released || closing || shutdown.signal.aborted)
32283
+ return;
32284
+ timer = (options.setTimeout ?? setTimeout)(() => withDetachedNativeLocks(async () => {
32285
+ timer = undefined;
32286
+ if (released || insula !== current)
32287
+ return;
32288
+ try {
32289
+ assertTransport();
32290
+ } catch {
32291
+ current.release();
32292
+ if (insula === current)
32293
+ insula = undefined;
32294
+ return;
32295
+ }
32296
+ if (current.source.watchMode() !== "watching")
32297
+ await refreshInsula();
32298
+ }).finally(schedule2).catch(() => {}), 60000);
32299
+ timer.unref?.();
32300
+ };
32301
+ schedule2();
32302
+ } else
32241
32303
  acquired.release();
32242
32304
  } catch (error) {
32243
- acquired.release();
32305
+ if (held) {
32306
+ held.release();
32307
+ if (insula === held)
32308
+ insula = undefined;
32309
+ } else
32310
+ acquired.release();
32244
32311
  throw error;
32245
32312
  }
32246
32313
  }
32247
32314
  assertTransport();
32248
- await insula.source.refresh(clock());
32315
+ await insula?.source.refresh(clock());
32249
32316
  } catch {}
32250
32317
  }
32251
32318
  function insulaLookup(accountId) {
32252
32319
  assertHostAuthorityStable();
32253
- if (insula && (insula.owner !== custody || insula.generation !== (custody.generation ?? 0))) {
32320
+ if (insula && (insula.owner !== custody || insula.generation !== (custody.generation ?? 0) || insula.transportEpoch !== insulaTransportEpoch)) {
32254
32321
  insula.release();
32255
32322
  insula = undefined;
32256
32323
  }
@@ -32835,6 +32902,8 @@ function createNativeVaultRuntime(options) {
32835
32902
  close() {
32836
32903
  if (closing)
32837
32904
  return closing;
32905
+ insula?.release();
32906
+ insula = undefined;
32838
32907
  watchers.clear();
32839
32908
  closeRosterWatch();
32840
32909
  schedulePoll();
@@ -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; reading
74
- * it opens a separate short-lived socket and never uses this connection.
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 the vault custody's outage probe and roster watch
28
- * retries. Defaults to the global ones; tests pass their own.
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/anthropic-auth-core",
3
- "version": "2.7.0",
3
+ "version": "2.7.1",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",