@cortexkit/opencode-anthropic-auth 2.11.4 → 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/index.js CHANGED
@@ -1 +1 @@
1
- import{u as a}from"./index-sqmwhrzx.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
+ 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. Setting
6
- * this variable to that server's exact origin (for example
7
- * `http://127.0.0.1:43123`) allows it in addition to api.anthropic.com. Only
8
- * an `http://` or `https://` origin on 127.0.0.1, [::1] or localhost, with an
9
- * explicit port and no user name, password, path, query or fragment, is
10
- * accepted; any other value is ignored, so OAuth stays limited to
11
- * api.anthropic.com. ANTHROPIC_BASE_URL never widens the rule. It is not a
12
- * user setting and is deliberately left out of the public documentation.
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 TEST_OAUTH_LOOPBACK_ORIGIN_ENV = "ANTHROPIC_AUTH_TEST_OAUTH_LOOPBACK_ORIGIN";
15
- /** The accepted loopback origin from TEST_OAUTH_LOOPBACK_ORIGIN_ENV, if any. */
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;
@@ -19,6 +19,7 @@ export interface NativeLocalSetupOptions {
19
19
  preflight?: NativeMigrationPreflight;
20
20
  skipMigration?: boolean;
21
21
  beforeCommit?: () => Promise<void>;
22
+ reportSettings?: (message: string) => void;
22
23
  }
23
24
  export declare const SEPARATE_HOST_LOGIN_NOTICE = "OpenCode's separate Anthropic login is not used. Add that account through /claude Accounts if needed, or remove the separate login from OpenCode.";
24
25
  export declare function requireNativeLocalEnrollment(hosts: readonly HarnessKind[], env: NodeJS.ProcessEnv): Promise<void>;
@@ -46,5 +47,7 @@ export declare function fingerprintNativeLocalPlan(plan: NativeLocalPlan, env: N
46
47
  export declare function planNativeLocalSetup(host: HarnessKind, options: NativeLocalSetupOptions, generation2: boolean): Promise<NativeLocalPlan>;
47
48
  export declare function revalidateNativeLocalPlan(plan: NativeLocalPlan, options: NativeLocalSetupOptions): Promise<void>;
48
49
  export declare function installAbsentNativePlaceholder(plan: Pick<NativeLocalPlan, 'paths' | 'slot'>, options: NativeLocalSetupOptions): Promise<void>;
50
+ /** Route raw, deferred settings after credential commit without starting the settings move. */
51
+ export declare function writeNativeLocalSetupSettings(host: HarnessKind, plan: NativeSetupPaths, options: NativeLocalSetupOptions, settings: Readonly<Record<string, unknown>>): Promise<import("@cortexkit/anthropic-auth-core").NativeSetupSettingsResult>;
49
52
  /** Transfer local credentials while hosts are stopped, before telling the user to restart. */
50
53
  export declare function migrateNativeLocalForHost(host: HarnessKind, options: NativeLocalSetupOptions): Promise<void>;
@@ -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
  /**
@@ -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>) => Q | undefined;
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.