@cortexkit/anthropic-auth-core 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/cachekeep.d.ts +5 -0
- package/dist/custom-headers.d.ts +9 -0
- package/dist/gateway.d.ts +188 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +16419 -15061
- package/dist/internal-types/fs/canonical-file-path.d.ts +17 -0
- package/dist/internal-types/fs/index.d.ts +1 -0
- package/dist/internal-types/settings/edit.d.ts +1 -0
- package/dist/internal-types/settings/handle.d.ts +2 -1
- package/dist/internal-types/settings/index.d.ts +1 -0
- package/dist/internal-types/settings/update.d.ts +14 -0
- package/dist/native-account-runtime.d.ts +21 -0
- package/dist/native-runtime-settings.d.ts +25 -6
- package/dist/native-runtime.d.ts +2 -2
- package/dist/native-settings-write.d.ts +4 -16
- package/dist/oauth-origin.d.ts +47 -4
- package/dist/pool-store.d.ts +7 -0
- package/dist/relay-location.d.ts +109 -0
- package/dist/relay.d.ts +18 -2
- package/dist/settings-definition.d.ts +38 -0
- package/dist/settings-host-import.d.ts +18 -4
- package/dist/settings-mode.d.ts +22 -0
- package/dist/settings-move-run.d.ts +60 -1
- package/dist/settings-move-source.d.ts +4 -1
- package/dist/settings-move-sources.d.ts +15 -6
- package/dist/settings-protection-copy.d.ts +7 -1
- package/dist/settings-service.d.ts +81 -37
- package/dist/settings-start.d.ts +46 -6
- package/package.json +2 -2
- package/schema/anthropic-auth.schema.json +9 -0
package/dist/cachekeep.d.ts
CHANGED
|
@@ -199,6 +199,11 @@ export declare class CacheKeepManager {
|
|
|
199
199
|
/** Memory-only settings projection; omitted by hosts that still use legacy settings. */
|
|
200
200
|
resolveSettings?: (storage: AccountStorage, model?: string) => AccountStorage;
|
|
201
201
|
fetchImpl?: typeof fetch;
|
|
202
|
+
/**
|
|
203
|
+
* The fetch for one target's warm, when it depends on the target (for
|
|
204
|
+
* example the gateway of the target's own runtime). Wins over fetchImpl.
|
|
205
|
+
*/
|
|
206
|
+
fetchForTarget?: (target: Readonly<CacheKeepTarget>) => typeof fetch;
|
|
202
207
|
billingRequest?: (target: CacheKeepTarget, attempt: CacheKeepPrewarmAttempt) => AnthropicBillingRequest | undefined;
|
|
203
208
|
now?: () => number;
|
|
204
209
|
prewarmTimeoutMs?: number;
|
package/dist/custom-headers.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
export declare const ANTHROPIC_CUSTOM_HEADERS_ENV = "ANTHROPIC_CUSTOM_HEADERS";
|
|
2
|
+
/**
|
|
3
|
+
* Builds headers from name/value pairs under the same rules as
|
|
4
|
+
* ANTHROPIC_CUSTOM_HEADERS: protected headers are refused. It is stricter
|
|
5
|
+
* about form, because the pairs come from a settings file rather than a
|
|
6
|
+
* shell: each name must be a valid header token, each value a string with no
|
|
7
|
+
* line breaks, and no name may repeat in another letter case. Throws
|
|
8
|
+
* TypeError on the first problem; the message never includes a value.
|
|
9
|
+
*/
|
|
10
|
+
export declare function customHeadersFromEntries(entries: Iterable<readonly [string, unknown]>): Headers;
|
|
2
11
|
export declare function parseCustomHeaders(raw: string | undefined): Headers;
|
|
3
12
|
export declare function applyCustomHeaders(headers: Headers, raw?: string | undefined): Headers;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The user's own gateway for Claude sign-in (OAuth) model requests.
|
|
3
|
+
*
|
|
4
|
+
* Claude OAuth tokens normally go only to https://api.anthropic.com (see
|
|
5
|
+
* oauth-origin.ts). A user can name one gateway in their own settings file
|
|
6
|
+
* (`gateway_url`, `gateway_headers`); model requests (`POST …/v1/messages`)
|
|
7
|
+
* then go there instead. The value is read only from the user settings file:
|
|
8
|
+
* never from a project file, a provider `baseURL` or an environment
|
|
9
|
+
* variable, because those can come from a repository the user opened.
|
|
10
|
+
*
|
|
11
|
+
* Header values are secrets the user gave to their gateway. They are kept
|
|
12
|
+
* only in memory, added to gateway requests, and never logged, dumped or
|
|
13
|
+
* shown: Status shows header names only.
|
|
14
|
+
*/
|
|
15
|
+
export interface ClaudeGateway {
|
|
16
|
+
/** Scheme, host and port, for example `https://gw.example.com`. */
|
|
17
|
+
readonly origin: string;
|
|
18
|
+
/** Path prefix without a trailing slash, or `''` for none. */
|
|
19
|
+
readonly pathPrefix: string;
|
|
20
|
+
/** Header names and values to add to every gateway request. */
|
|
21
|
+
readonly headers: readonly (readonly [string, string])[];
|
|
22
|
+
}
|
|
23
|
+
/** What Status may show about a gateway: no header values. */
|
|
24
|
+
export interface ClaudeGatewayStatus {
|
|
25
|
+
readonly origin: string;
|
|
26
|
+
readonly pathPrefix: string;
|
|
27
|
+
readonly headerNames: readonly string[];
|
|
28
|
+
}
|
|
29
|
+
export type ClaudeGatewayParse = {
|
|
30
|
+
readonly ok: true;
|
|
31
|
+
readonly gateway: ClaudeGateway | undefined;
|
|
32
|
+
} | {
|
|
33
|
+
readonly ok: false;
|
|
34
|
+
readonly problem: 'gateway_url' | 'gateway_headers';
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Validates the two gateway settings together. An empty `gateway_url` means
|
|
38
|
+
* no gateway; headers without a URL are still validated so a mistake shows
|
|
39
|
+
* up before the URL is added. Any problem makes the whole gateway invalid.
|
|
40
|
+
*/
|
|
41
|
+
export declare function parseClaudeGateway(url: string, headers: Readonly<Record<string, string>>): ClaudeGatewayParse;
|
|
42
|
+
/** Status view of a gateway: origin, path prefix and header names only. */
|
|
43
|
+
export declare function claudeGatewayStatus(gateway: ClaudeGateway | undefined): ClaudeGatewayStatus | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* True when `url` is inside the gateway: same scheme, host and port, and a
|
|
46
|
+
* path equal to the prefix or below it.
|
|
47
|
+
*/
|
|
48
|
+
export declare function isClaudeGatewayUrl(url: URL, gateway: ClaudeGateway): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Where a model request goes through the gateway, or undefined when `url` is
|
|
51
|
+
* not a model request the gateway takes. A model request URL is a URL on
|
|
52
|
+
* `https://api.anthropic.com`, or inside the gateway, whose path ends in
|
|
53
|
+
* `/messages` once repeated and trailing slashes are collapsed; a provider
|
|
54
|
+
* base URL can add a path or another version segment in front of it. It
|
|
55
|
+
* always goes to `<gateway prefix>/v1/messages` with its query
|
|
56
|
+
* (`?beta=true`) kept. A path with `.` or `..` segments, other Anthropic
|
|
57
|
+
* endpoints and other hosts are left alone, so the OAuth destination check
|
|
58
|
+
* still decides them without the gateway.
|
|
59
|
+
*/
|
|
60
|
+
export declare function claudeGatewayModelUrl(url: string | URL, gateway: ClaudeGateway): URL | undefined;
|
|
61
|
+
/** Adds the gateway headers to a request's headers. */
|
|
62
|
+
export declare function applyClaudeGatewayHeaders(headers: Headers, gateway: ClaudeGateway): Headers;
|
|
63
|
+
/** Records a gateway's header names and values as secrets. */
|
|
64
|
+
export declare function rememberClaudeGatewaySecrets(gateway: ClaudeGateway | undefined): void;
|
|
65
|
+
/** True for a configured gateway header name; its value must not be dumped. */
|
|
66
|
+
export declare function isClaudeGatewaySecretHeader(name: string): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Every gateway header value configured in this process, for provider-error
|
|
69
|
+
* redaction of sends that cannot tell which gateway they used.
|
|
70
|
+
*/
|
|
71
|
+
export declare function claudeGatewaySecretValues(): string[];
|
|
72
|
+
/** The header values one gateway send carries, for provider-error redaction. */
|
|
73
|
+
export declare function claudeGatewayHeaderValues(gateway: ClaudeGateway | undefined): string[];
|
|
74
|
+
/**
|
|
75
|
+
* Logs once per gateway destination that the configured relay is not used: the
|
|
76
|
+
* gateway takes model requests, and nothing falls back to the relay or to
|
|
77
|
+
* api.anthropic.com.
|
|
78
|
+
*/
|
|
79
|
+
export declare function warnClaudeGatewayRelayIgnored(gateway: ClaudeGateway): void;
|
|
80
|
+
type ProxyEnvironment = Readonly<Record<string, string | undefined>>;
|
|
81
|
+
/**
|
|
82
|
+
* Fixed text for refusing a plain-http gateway send that a proxy setting
|
|
83
|
+
* would carry. It names no value: the variables may hold credentials.
|
|
84
|
+
*/
|
|
85
|
+
export declare const CLAUDE_GATEWAY_PROXY_REFUSAL = "Gateway refused: a proxy setting would carry plain-http requests";
|
|
86
|
+
/**
|
|
87
|
+
* True when a plain-http request to `origin` would go through a proxy.
|
|
88
|
+
*
|
|
89
|
+
* Bun's fetch sends a plain-http request through `HTTP_PROXY` or
|
|
90
|
+
* `http_proxy`, and fetch has no per-request way to turn that off. A
|
|
91
|
+
* repository's `.env` can set those variables, so a proxy it names would
|
|
92
|
+
* receive the OAuth bearer, the gateway headers and the conversation in
|
|
93
|
+
* clear text. (An https gateway is only tunnelled through a proxy, and TLS
|
|
94
|
+
* still checks the gateway's certificate, so it is not affected.)
|
|
95
|
+
*
|
|
96
|
+
* Measured on Bun 1.3.14: `HTTP_PROXY` and `http_proxy` apply to http URLs,
|
|
97
|
+
* and any non-empty value counts, even one that is not a URL. `ALL_PROXY`,
|
|
98
|
+
* `all_proxy`, `HTTPS_PROXY` and `https_proxy` do not apply to http URLs.
|
|
99
|
+
* `no_proxy`, when non-empty, is used in place of `NO_PROXY`; it is a comma
|
|
100
|
+
* list whose entries are trimmed, and `*`, the exact host (`[::1]` for IPv6,
|
|
101
|
+
* any letter case) and `host:port` with the URL's own explicit port exempt the
|
|
102
|
+
* host. Bun also exempts some host suffixes.
|
|
103
|
+
*
|
|
104
|
+
* Pi's host may run on Node instead. Measured on Node 26.10: fetch ignores
|
|
105
|
+
* every proxy variable unless `NODE_USE_ENV_PROXY=1` is set at start. With it,
|
|
106
|
+
* `HTTP_PROXY` and `http_proxy` apply to http URLs, and a set `no_proxy` is
|
|
107
|
+
* used in place of `NO_PROXY` even when it is empty: `no_proxy=` beside
|
|
108
|
+
* `NO_PROXY=*` still sends through the proxy, where Bun would not.
|
|
109
|
+
*
|
|
110
|
+
* The two runtimes disagree, so the host counts as exempt only when every
|
|
111
|
+
* set `no_proxy` and `NO_PROXY` exempts it, and a set but empty one exempts
|
|
112
|
+
* nothing. Suffix entries are never accepted. This check can therefore only
|
|
113
|
+
* refuse more than either runtime would proxy, never less.
|
|
114
|
+
*/
|
|
115
|
+
export declare function claudeGatewayProxyApplies(origin: string, env?: ProxyEnvironment): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Logs once per gateway destination that its plain-http sends are refused
|
|
118
|
+
* because a proxy setting would carry them. Names no variable value.
|
|
119
|
+
*/
|
|
120
|
+
export declare function warnClaudeGatewayProxyRefused(gateway: ClaudeGateway): void;
|
|
121
|
+
/** Why a gateway named in the settings file is not used. */
|
|
122
|
+
export type ClaudeGatewayIgnored = 'not-default-location' | 'account-home-unknown';
|
|
123
|
+
/** The Status line for an ignored gateway; it names no value. */
|
|
124
|
+
export declare function claudeGatewayIgnoredNote(reason: ClaudeGatewayIgnored): string;
|
|
125
|
+
/**
|
|
126
|
+
* The Status lines about the gateway: why a configured gateway is ignored,
|
|
127
|
+
* or that its plain-http sends are refused because of a proxy setting.
|
|
128
|
+
* They name no header or environment value.
|
|
129
|
+
*/
|
|
130
|
+
export declare function claudeGatewayStatusNotes(ignored: ClaudeGatewayIgnored | undefined, gateway: ClaudeGatewayStatus | null | undefined, env?: ProxyEnvironment): string[];
|
|
131
|
+
/** Runs one program and returns its standard output. */
|
|
132
|
+
export type AccountLookupRun = (file: string, args: readonly string[], env: Readonly<Record<string, string>>) => Promise<string>;
|
|
133
|
+
export interface AccountSettingsFileDependencies {
|
|
134
|
+
readonly platform: NodeJS.Platform;
|
|
135
|
+
readonly uid: number | undefined;
|
|
136
|
+
readonly run: AccountLookupRun;
|
|
137
|
+
readonly readFile: (path: string) => Promise<string>;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Looks up the settings file the gateway is honoured from, without reading
|
|
141
|
+
* the environment: the default location under the operating system
|
|
142
|
+
* account's own home (POSIX, from the account database for the process's
|
|
143
|
+
* user id) or its roaming AppData folder (Windows, from the user's registry).
|
|
144
|
+
* Undefined when the lookup fails.
|
|
145
|
+
*/
|
|
146
|
+
export declare function lookupGatewaySettingsFile(dependencies: AccountSettingsFileDependencies): Promise<string | undefined>;
|
|
147
|
+
/**
|
|
148
|
+
* Looks up the operating system account's home folder without reading the
|
|
149
|
+
* environment, the same way as lookupGatewaySettingsFile: on POSIX from the
|
|
150
|
+
* account database for the process's user id, on Windows the profile folder
|
|
151
|
+
* the registry records for the process account's SID (the folder
|
|
152
|
+
* `%USERPROFILE%` normally names), or else the signed-in user's volatile
|
|
153
|
+
* environment key. Undefined when the lookup fails.
|
|
154
|
+
*/
|
|
155
|
+
export declare function lookupAccountHome(dependencies: AccountSettingsFileDependencies): Promise<string | undefined>;
|
|
156
|
+
/** How long a failed account-home lookup is trusted before it is retried. */
|
|
157
|
+
export declare const ACCOUNT_HOME_RETRY_MS = 60000;
|
|
158
|
+
/**
|
|
159
|
+
* Caches an account-home lookup: a found home for the life of the process,
|
|
160
|
+
* a failure only for `retryMs`. The first lookup is awaited by whoever asks
|
|
161
|
+
* first. After a failure, callers get undefined at once and a retry starts
|
|
162
|
+
* in the background once `retryMs` has passed, so a slow or failing lookup
|
|
163
|
+
* never holds a request.
|
|
164
|
+
*/
|
|
165
|
+
export declare function createAccountHomeCache(lookup: () => Promise<string | undefined>, options?: {
|
|
166
|
+
now?: () => number;
|
|
167
|
+
retryMs?: number;
|
|
168
|
+
}): () => Promise<string | undefined>;
|
|
169
|
+
/**
|
|
170
|
+
* The operating system account's home folder (see lookupAccountHome). HOME,
|
|
171
|
+
* USERPROFILE and the XDG variables never choose it. A found home is kept for
|
|
172
|
+
* the process; a failed lookup is retried in the background after
|
|
173
|
+
* ACCOUNT_HOME_RETRY_MS. Undefined while the home cannot be found.
|
|
174
|
+
*/
|
|
175
|
+
export declare function accountHome(): Promise<string | undefined>;
|
|
176
|
+
/**
|
|
177
|
+
* The settings file the gateway is honoured from (see
|
|
178
|
+
* lookupGatewaySettingsFile). Environment variables (HOME, USERPROFILE,
|
|
179
|
+
* APPDATA, XDG_CONFIG_HOME, ANTHROPIC_AUTH_SETTINGS_FILE) never choose it, so
|
|
180
|
+
* an environment a project can influence cannot point the gateway at another
|
|
181
|
+
* file. `os.userInfo()` is not used: under Bun its home follows HOME. The
|
|
182
|
+
* lookup runs once per process, when settings are first read, never on a
|
|
183
|
+
* request. Undefined when the account's home cannot be found.
|
|
184
|
+
*/
|
|
185
|
+
export declare function gatewaySettingsFile(): Promise<string | undefined>;
|
|
186
|
+
/** True when `file` is the gateway settings file, compared as real paths. */
|
|
187
|
+
export declare function isGatewaySettingsFile(file: string, expected: string | undefined): Promise<boolean>;
|
|
188
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export * from './constants.ts';
|
|
|
19
19
|
export * from './custom-headers.ts';
|
|
20
20
|
export * from './dump.ts';
|
|
21
21
|
export * from './fast.ts';
|
|
22
|
+
export * from './gateway.ts';
|
|
22
23
|
export * from './holder-registry.ts';
|
|
23
24
|
export * from './host-paths.ts';
|
|
24
25
|
export * from './host-retry.ts';
|
|
@@ -99,6 +100,7 @@ export * from './quota-manager.ts';
|
|
|
99
100
|
export * from './quota-refusal.ts';
|
|
100
101
|
export * from './quotas.ts';
|
|
101
102
|
export * from './relay.ts';
|
|
103
|
+
export * from './relay-location.ts';
|
|
102
104
|
export * from './relocation-guard.ts';
|
|
103
105
|
export * from './request-abort.ts';
|
|
104
106
|
export * from './request-gzip.ts';
|