@cortexkit/pi-anthropic-auth 2.2.7 → 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.
- package/dist/native.js +19 -4
- package/dist/transport.js +9 -23
- 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
|
-
|
|
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
|
-
|
|
344
|
+
closeRuntime(entry);
|
|
332
345
|
}
|
|
333
|
-
|
|
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/dist/transport.js
CHANGED
|
@@ -1,30 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import { createAnthropicOAuthFetch, requireAnthropicOAuthOrigin, } from '@cortexkit/anthropic-auth-core';
|
|
2
|
+
// Pi keeps its own refusal wording; Core supplies the origin rule itself.
|
|
3
|
+
const PI_OAUTH_ORIGIN = {
|
|
4
|
+
refusal: (reason) => new Error(reason === 'unparseable'
|
|
5
|
+
? 'Native OAuth requires the official Anthropic HTTPS origin'
|
|
6
|
+
: 'Native OAuth requires the official Anthropic HTTPS origin without URL userinfo'),
|
|
7
|
+
};
|
|
2
8
|
/** Model base URLs and remembered cache-warm URLs must send OAuth tokens only to Anthropic’s HTTPS server. */
|
|
3
9
|
export function requirePiOAuthOrigin(value) {
|
|
4
|
-
|
|
5
|
-
try {
|
|
6
|
-
url = new URL(value);
|
|
7
|
-
}
|
|
8
|
-
catch {
|
|
9
|
-
throw new Error('Native OAuth requires the official Anthropic HTTPS origin');
|
|
10
|
-
}
|
|
11
|
-
if (url.protocol !== 'https:' ||
|
|
12
|
-
url.origin !== ANTHROPIC_ORIGIN ||
|
|
13
|
-
url.username ||
|
|
14
|
-
url.password)
|
|
15
|
-
throw new Error('Native OAuth requires the official Anthropic HTTPS origin without URL userinfo');
|
|
16
|
-
return url;
|
|
10
|
+
return requireAnthropicOAuthOrigin(value, PI_OAUTH_ORIGIN);
|
|
17
11
|
}
|
|
18
12
|
export function buildPiOAuthMessagesUrl(baseUrl) {
|
|
19
13
|
return new URL('/v1/messages?beta=true', requirePiOAuthOrigin(baseUrl));
|
|
20
14
|
}
|
|
21
15
|
/** Reject redirects rather than letting an approved OAuth destination forward the request. */
|
|
22
|
-
export const fetchPiOAuth =
|
|
23
|
-
requirePiOAuthOrigin(input instanceof Request ? input.url : String(input));
|
|
24
|
-
return fetch(input, { ...init, redirect: 'error' });
|
|
25
|
-
}, {
|
|
26
|
-
preconnect: (...args) => {
|
|
27
|
-
requirePiOAuthOrigin(String(args[0]));
|
|
28
|
-
return fetch.preconnect(...args);
|
|
29
|
-
},
|
|
30
|
-
});
|
|
16
|
+
export const fetchPiOAuth = createAnthropicOAuthFetch(PI_OAUTH_ORIGIN);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/pi-anthropic-auth",
|
|
3
|
-
"version": "2.
|
|
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.
|
|
39
|
+
"@cortexkit/anthropic-auth-core": "2.3.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@earendil-works/pi-ai": ">=0.86.1 <2",
|