@cortexkit/pi-anthropic-auth 2.2.7 → 2.2.8

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/transport.js +9 -23
  2. package/package.json +2 -2
package/dist/transport.js CHANGED
@@ -1,30 +1,16 @@
1
- const ANTHROPIC_ORIGIN = 'https://api.anthropic.com';
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
- let url;
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 = Object.assign(async (input, init) => {
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.2.7",
3
+ "version": "2.2.8",
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.7"
39
+ "@cortexkit/anthropic-auth-core": "2.2.8"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@earendil-works/pi-ai": ">=0.86.1 <2",