@cortexkit/pi-anthropic-auth 2.2.8 → 2.3.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.
Files changed (2) hide show
  1. package/dist/native.js +19 -4
  2. package/package.json +2 -2
package/dist/native.js CHANGED
@@ -30,6 +30,18 @@ function requestPolicy(routeId, modelId) {
30
30
  }
31
31
  const runtimes = new Map();
32
32
  const RUNTIME_LIMIT = 16;
33
+ const closingRuntimes = new Map();
34
+ function closeRuntime(entry) {
35
+ const closing = entry.runtime.close();
36
+ const pending = closingRuntimes.get(entry.storagePath) ?? new Set();
37
+ closingRuntimes.set(entry.storagePath, pending);
38
+ pending.add(closing);
39
+ void closing.then(() => {
40
+ pending.delete(closing);
41
+ if (!pending.size)
42
+ closingRuntimes.delete(entry.storagePath);
43
+ }, () => { });
44
+ }
33
45
  function runtimeCacheKey(storagePath) {
34
46
  const enrollment = getHostClaustrumEnrollmentPaths('pi');
35
47
  return JSON.stringify([
@@ -316,19 +328,22 @@ export function getPiNativeRuntime(storagePath = getPiAccountStoragePath(), opti
316
328
  const oldest = runtimes.keys().next().value;
317
329
  if (oldest === undefined)
318
330
  break;
319
- void runtimes.get(oldest)?.runtime.close();
331
+ const evicted = runtimes.get(oldest);
332
+ if (evicted)
333
+ closeRuntime(evicted);
320
334
  runtimes.delete(oldest);
321
335
  }
322
336
  runtimes.set(key, { contextKey, storagePath: resolve(storagePath), runtime });
323
337
  return runtime;
324
338
  }
325
339
  export function closePiNativeRuntime(storagePath = getPiAccountStoragePath()) {
326
- const closing = [];
327
340
  for (const [key, entry] of runtimes) {
328
341
  if (entry.storagePath !== resolve(storagePath))
329
342
  continue;
330
343
  runtimes.delete(key);
331
- closing.push(entry.runtime.close());
344
+ closeRuntime(entry);
332
345
  }
333
- return Promise.all(closing).then(() => { });
346
+ // Eviction removes cache entries before their quota drain finishes. Shutdown
347
+ // must also join those closes, not only the runtimes still in the cache.
348
+ return Promise.all(closingRuntimes.get(resolve(storagePath)) ?? []).then(() => { });
334
349
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/pi-anthropic-auth",
3
- "version": "2.2.8",
3
+ "version": "2.3.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -36,7 +36,7 @@
36
36
  "prepublishOnly": "bun run build"
37
37
  },
38
38
  "dependencies": {
39
- "@cortexkit/anthropic-auth-core": "2.2.8"
39
+ "@cortexkit/anthropic-auth-core": "2.3.0"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@earendil-works/pi-ai": ">=0.86.1 <2",