@cortexkit/opencode-anthropic-auth 2.12.0 → 2.13.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/cli.js +1 -1
- package/dist/index-e91y2kqv.js +47 -0
- package/dist/index.js +1 -1
- package/dist/oauth-destination.d.ts +35 -12
- package/dist/transform.d.ts +2 -1
- package/dist/v2/adapter.d.ts +12 -2
- package/dist/v2/server.js +13 -13
- package/package.json +2 -2
- package/dist/index-z31s2mjs.js +0 -47
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as a}from"./index-
|
|
1
|
+
import{u as a}from"./index-e91y2kqv.js";import"./index-6q2f3m0v.js";import"./index-77sph3hf.js";import"./index-427t44z7.js";import"./index-0btjtgy5.js";import"./index-27dah13x.js";import"./index-dpxaxyck.js";export{a as AnthropicAuthPlugin};
|
|
@@ -1,18 +1,25 @@
|
|
|
1
|
+
import { type ClaudeGateway } from '@cortexkit/anthropic-auth-core';
|
|
1
2
|
/**
|
|
2
3
|
* Test-only escape hatch for the OAuth destination rule.
|
|
3
4
|
*
|
|
4
5
|
* End-to-end suites run a real OpenCode process against a local mock of the
|
|
5
|
-
* Anthropic API, so they need OAuth sends to reach a loopback server.
|
|
6
|
-
*
|
|
7
|
-
* `
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
6
|
+
* Anthropic API, so they need OAuth sends to reach a loopback server. Test
|
|
7
|
+
* code sets the server's exact origin (for example `http://127.0.0.1:43123`)
|
|
8
|
+
* on `globalThis` under this symbol, from a test preload or a test-only
|
|
9
|
+
* plugin loaded before this one; it is then allowed in addition to
|
|
10
|
+
* api.anthropic.com. Only an `http://` or `https://` origin on 127.0.0.1,
|
|
11
|
+
* [::1] or localhost, with an explicit port and no user name, password, path,
|
|
12
|
+
* query or fragment, is accepted; any other value is ignored, so OAuth stays
|
|
13
|
+
* limited to api.anthropic.com.
|
|
14
|
+
*
|
|
15
|
+
* It is deliberately not an environment variable: OpenCode started from
|
|
16
|
+
* source loads a `.env` file from the working directory, so an opened
|
|
17
|
+
* repository could set one. Only code already running in the process can set
|
|
18
|
+
* this symbol. ANTHROPIC_BASE_URL never widens the rule. It is not a user
|
|
19
|
+
* setting and is deliberately left out of the public documentation.
|
|
13
20
|
*/
|
|
14
|
-
export declare const
|
|
15
|
-
/** The accepted loopback origin from
|
|
21
|
+
export declare const TEST_OAUTH_LOOPBACK_ORIGIN_KEY: unique symbol;
|
|
22
|
+
/** The accepted loopback origin from TEST_OAUTH_LOOPBACK_ORIGIN_KEY, if any. */
|
|
16
23
|
export declare function testOAuthLoopbackOrigin(): string | undefined;
|
|
17
24
|
/**
|
|
18
25
|
* Throws AnthropicOAuthOriginError unless an OAuth token may be sent to
|
|
@@ -24,12 +31,28 @@ export declare function testOAuthLoopbackOrigin(): string | undefined;
|
|
|
24
31
|
* `bun run` (from source) loads a `.env` file from the working directory, so
|
|
25
32
|
* an opened repository could set the variable. An OAuth token therefore goes
|
|
26
33
|
* only to api.anthropic.com whatever the variable says.
|
|
34
|
+
*
|
|
35
|
+
* Pass `gateway` only for a model request: it is the user's gateway from
|
|
36
|
+
* their own settings file (NativeAccountRuntime.getClaudeGateway), never a
|
|
37
|
+
* value taken from provider configuration or the environment.
|
|
27
38
|
*/
|
|
28
|
-
export declare function requireOAuthDestination(url: string): URL;
|
|
39
|
+
export declare function requireOAuthDestination(url: string, gateway?: ClaudeGateway): URL;
|
|
29
40
|
/** True when an OAuth token may be sent to `url`. */
|
|
30
|
-
export declare function isAllowedOAuthDestination(url: string): boolean;
|
|
41
|
+
export declare function isAllowedOAuthDestination(url: string, gateway?: ClaudeGateway): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Undefined when an OAuth token may be sent to `url`; otherwise the fixed
|
|
44
|
+
* refusal text, which never includes the URL or any credential. A gateway
|
|
45
|
+
* send refused because a proxy setting would carry it gets its own text.
|
|
46
|
+
*/
|
|
47
|
+
export declare function oauthDestinationRefusal(url: string, gateway?: ClaudeGateway): string | undefined;
|
|
31
48
|
/**
|
|
32
49
|
* Fetch for OAuth sends: rechecks the destination on every call and refuses
|
|
33
50
|
* redirects.
|
|
34
51
|
*/
|
|
35
52
|
export declare const fetchOAuth: typeof fetch;
|
|
53
|
+
/**
|
|
54
|
+
* Fetch for OAuth model requests: like fetchOAuth, but a model request goes
|
|
55
|
+
* to the user's gateway with its headers when one is set. See
|
|
56
|
+
* createClaudeModelFetch.
|
|
57
|
+
*/
|
|
58
|
+
export declare function fetchOAuthModel(gateway: ClaudeGateway | undefined | (() => ClaudeGateway | undefined)): typeof fetch;
|
package/dist/transform.d.ts
CHANGED
|
@@ -47,7 +47,8 @@ export declare function prefixToolNames(parsed: Record<string, unknown>, options
|
|
|
47
47
|
export declare function stripToolPrefix(text: string, toolNameMap?: ToolNameMap): string;
|
|
48
48
|
/**
|
|
49
49
|
* Check if TLS verification should be skipped for custom API endpoints.
|
|
50
|
-
* Only effective when ANTHROPIC_BASE_URL is also set
|
|
50
|
+
* Only effective when ANTHROPIC_BASE_URL is also set, and only on API-key
|
|
51
|
+
* routes: Claude OAuth sends always check certificates.
|
|
51
52
|
*/
|
|
52
53
|
export declare function isInsecure(): boolean;
|
|
53
54
|
/**
|
package/dist/v2/adapter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AnthropicBillingRequest, AnthropicOAuthOriginError, type ClaudeCodeIdentity, type RequestGzipLatch, stateRefusalCause, TrailingAssistantHistoryError } from '@cortexkit/anthropic-auth-core';
|
|
1
|
+
import { type AnthropicBillingRequest, AnthropicOAuthOriginError, type ClaudeCodeIdentity, type ClaudeGateway, type RequestGzipLatch, stateRefusalCause, TrailingAssistantHistoryError } from '@cortexkit/anthropic-auth-core';
|
|
2
2
|
import type { AccountRequest, AttemptOutcome, ChooseAccountInput, ChooseAccountResult, HeaderEdits, HostError, LimitSignal, OpenCode2AuthAdapter, RequestScope, SameAccountRetryInput, SameAccountRetryResult, Transport } from '@cortexkit/common-auth/opencode2';
|
|
3
3
|
import { EffortMarkerCorrelationError } from '../effort-history';
|
|
4
4
|
import { createStrippedStream, rewriteRequestBody } from '../transform';
|
|
@@ -63,6 +63,13 @@ export type NativeAnthropicAuthorization<P> = {
|
|
|
63
63
|
readonly headers?: HeaderEdits;
|
|
64
64
|
readonly provenance: P;
|
|
65
65
|
readonly dispatch?: NativeAnthropicDispatch;
|
|
66
|
+
/**
|
|
67
|
+
* The user's gateway from their own settings file, read once when this
|
|
68
|
+
* send was authorized. A model request goes there directly instead of
|
|
69
|
+
* api.anthropic.com, whatever `dispatch` says; any other request uses
|
|
70
|
+
* `dispatch`.
|
|
71
|
+
*/
|
|
72
|
+
readonly gateway?: ClaudeGateway;
|
|
66
73
|
} | {
|
|
67
74
|
readonly route: 'api';
|
|
68
75
|
/**
|
|
@@ -192,7 +199,10 @@ export interface NativeAnthropicSource<Q, P> {
|
|
|
192
199
|
/** Response observers for an OAuth response. */
|
|
193
200
|
readonly responseOptions?: (input: NativeAnthropicResponseContext<P>) => NativeAnthropicResponseOptions | undefined;
|
|
194
201
|
/** Quota carried by the upstream response headers, read once per response. */
|
|
195
|
-
readonly quotaFromHeaders?: (headers: Headers, input: NativeAnthropicResponseContext<P>
|
|
202
|
+
readonly quotaFromHeaders?: (headers: Headers, input: NativeAnthropicResponseContext<P> & {
|
|
203
|
+
/** Background cache requests harvest quota without reporting turn routing. */
|
|
204
|
+
readonly reportRouting?: boolean;
|
|
205
|
+
}) => Q | undefined;
|
|
196
206
|
/**
|
|
197
207
|
* Classifies an error response before its body streams. `body()` reads a
|
|
198
208
|
* copy, so the host still receives the body.
|