@anthropic-ai/sdk 0.92.0 → 0.94.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.
Files changed (97) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/client.d.mts +73 -0
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +73 -0
  5. package/client.d.ts.map +1 -1
  6. package/client.js +258 -9
  7. package/client.js.map +1 -1
  8. package/client.mjs +258 -9
  9. package/client.mjs.map +1 -1
  10. package/core/credentials.d.mts +131 -0
  11. package/core/credentials.d.mts.map +1 -0
  12. package/core/credentials.d.ts +131 -0
  13. package/core/credentials.d.ts.map +1 -0
  14. package/core/credentials.js +317 -0
  15. package/core/credentials.js.map +1 -0
  16. package/core/credentials.mjs +277 -0
  17. package/core/credentials.mjs.map +1 -0
  18. package/internal/utils/time.d.mts +3 -0
  19. package/internal/utils/time.d.mts.map +1 -0
  20. package/internal/utils/time.d.ts +3 -0
  21. package/internal/utils/time.d.ts.map +1 -0
  22. package/internal/utils/time.js +8 -0
  23. package/internal/utils/time.js.map +1 -0
  24. package/internal/utils/time.mjs +5 -0
  25. package/internal/utils/time.mjs.map +1 -0
  26. package/lib/credentials/credential-chain.d.mts +39 -0
  27. package/lib/credentials/credential-chain.d.mts.map +1 -0
  28. package/lib/credentials/credential-chain.d.ts +39 -0
  29. package/lib/credentials/credential-chain.d.ts.map +1 -0
  30. package/lib/credentials/credential-chain.js +245 -0
  31. package/lib/credentials/credential-chain.js.map +1 -0
  32. package/lib/credentials/credential-chain.mjs +208 -0
  33. package/lib/credentials/credential-chain.mjs.map +1 -0
  34. package/lib/credentials/identity-token.d.mts +11 -0
  35. package/lib/credentials/identity-token.d.mts.map +1 -0
  36. package/lib/credentials/identity-token.d.ts +11 -0
  37. package/lib/credentials/identity-token.d.ts.map +1 -0
  38. package/lib/credentials/identity-token.js +72 -0
  39. package/lib/credentials/identity-token.js.map +1 -0
  40. package/lib/credentials/identity-token.mjs +35 -0
  41. package/lib/credentials/identity-token.mjs.map +1 -0
  42. package/lib/credentials/oidc-federation.d.mts +40 -0
  43. package/lib/credentials/oidc-federation.d.mts.map +1 -0
  44. package/lib/credentials/oidc-federation.d.ts +40 -0
  45. package/lib/credentials/oidc-federation.d.ts.map +1 -0
  46. package/lib/credentials/oidc-federation.js +82 -0
  47. package/lib/credentials/oidc-federation.js.map +1 -0
  48. package/lib/credentials/oidc-federation.mjs +79 -0
  49. package/lib/credentials/oidc-federation.mjs.map +1 -0
  50. package/lib/credentials/token-cache.d.mts +54 -0
  51. package/lib/credentials/token-cache.d.mts.map +1 -0
  52. package/lib/credentials/token-cache.d.ts +54 -0
  53. package/lib/credentials/token-cache.d.ts.map +1 -0
  54. package/lib/credentials/token-cache.js +112 -0
  55. package/lib/credentials/token-cache.js.map +1 -0
  56. package/lib/credentials/token-cache.mjs +108 -0
  57. package/lib/credentials/token-cache.mjs.map +1 -0
  58. package/lib/credentials/types.d.mts +96 -0
  59. package/lib/credentials/types.d.mts.map +1 -0
  60. package/lib/credentials/types.d.ts +96 -0
  61. package/lib/credentials/types.d.ts.map +1 -0
  62. package/lib/credentials/types.js +266 -0
  63. package/lib/credentials/types.js.map +1 -0
  64. package/lib/credentials/types.mjs +224 -0
  65. package/lib/credentials/types.mjs.map +1 -0
  66. package/lib/credentials/user-oauth.d.mts +21 -0
  67. package/lib/credentials/user-oauth.d.mts.map +1 -0
  68. package/lib/credentials/user-oauth.d.ts +21 -0
  69. package/lib/credentials/user-oauth.d.ts.map +1 -0
  70. package/lib/credentials/user-oauth.js +130 -0
  71. package/lib/credentials/user-oauth.js.map +1 -0
  72. package/lib/credentials/user-oauth.mjs +94 -0
  73. package/lib/credentials/user-oauth.mjs.map +1 -0
  74. package/lib/credentials.d.mts +4 -0
  75. package/lib/credentials.d.mts.map +1 -0
  76. package/lib/credentials.d.ts +4 -0
  77. package/lib/credentials.d.ts.map +1 -0
  78. package/lib/credentials.js +8 -0
  79. package/lib/credentials.js.map +1 -0
  80. package/lib/credentials.mjs +3 -0
  81. package/lib/credentials.mjs.map +1 -0
  82. package/package.json +1 -1
  83. package/src/client.ts +342 -14
  84. package/src/core/credentials.ts +379 -0
  85. package/src/internal/utils/time.ts +4 -0
  86. package/src/lib/credentials/credential-chain.ts +292 -0
  87. package/src/lib/credentials/identity-token.ts +37 -0
  88. package/src/lib/credentials/oidc-federation.ts +140 -0
  89. package/src/lib/credentials/token-cache.ts +130 -0
  90. package/src/lib/credentials/types.ts +295 -0
  91. package/src/lib/credentials/user-oauth.ts +144 -0
  92. package/src/lib/credentials.ts +3 -0
  93. package/src/version.ts +1 -1
  94. package/version.d.mts +1 -1
  95. package/version.d.ts +1 -1
  96. package/version.js +1 -1
  97. package/version.mjs +1 -1
@@ -0,0 +1,277 @@
1
+ import { getPlatformHeaders } from "../internal/detect-platform.mjs";
2
+ import { readEnv } from "../internal/utils.mjs";
3
+ /** Current schema version written to `configs/<profile>.json`. Absent on read ⇒ "1.0". */
4
+ export const CONFIG_FILE_VERSION = '1.0';
5
+ /** Current schema version written to `credentials/<profile>.json`. Absent on read ⇒ "1.0". */
6
+ export const CREDENTIALS_FILE_VERSION = '1.0';
7
+ const PROFILE_NAME_PATTERN = /^[A-Za-z0-9_.-]+$/;
8
+ function validateProfileName(name) {
9
+ if (!name) {
10
+ throw new Error('profile name is empty');
11
+ }
12
+ if (name === '.' || name === '..') {
13
+ throw new Error(`profile name "${name}" is not allowed`);
14
+ }
15
+ if (name.includes('/') || name.includes('\\')) {
16
+ throw new Error(`profile name "${name}" must not contain path separators`);
17
+ }
18
+ if (!PROFILE_NAME_PATTERN.test(name)) {
19
+ throw new Error(`profile name "${name}" contains disallowed characters (allowed: letters, digits, '_', '.', '-')`);
20
+ }
21
+ }
22
+ /**
23
+ * Loads the Anthropic configuration for the given (or active) profile.
24
+ *
25
+ * Returns `null` when running in a browser or no configuration can be resolved.
26
+ * Otherwise, returns the configuration based on the config file and environment variables.
27
+ *
28
+ * **Profile resolution** (first match wins):
29
+ * 1. Explicit `profile` argument
30
+ * 2. `ANTHROPIC_PROFILE` environment variable
31
+ * 3. Contents of `<config_dir>/active_config` file
32
+ * 4. `"default"`
33
+ *
34
+ * **Config resolution:**
35
+ * - If `<config_dir>/configs/<profile>.json` exists, it is loaded and
36
+ * missing fields are filled from environment variables. Values present
37
+ * in the file take precedence — env vars only fill gaps:
38
+ * - `ANTHROPIC_BASE_URL` → `base_url`
39
+ * - `ANTHROPIC_ORGANIZATION_ID` → `organization_id`
40
+ * - `ANTHROPIC_WORKSPACE_ID` → `workspace_id`
41
+ * - `ANTHROPIC_SCOPE` → `authentication.scope`
42
+ * - `ANTHROPIC_FEDERATION_RULE_ID` → `authentication.federation_rule_id` (oidc_federation)
43
+ * - `ANTHROPIC_IDENTITY_TOKEN_FILE` → `authentication.identity_token` (oidc_federation)
44
+ * - `ANTHROPIC_SERVICE_ACCOUNT_ID` → `authentication.service_account_id` (oidc_federation)
45
+ * - If no config file exists, an `oidc_federation` config is synthesized
46
+ * entirely from environment variables when both `ANTHROPIC_FEDERATION_RULE_ID`
47
+ * and `ANTHROPIC_ORGANIZATION_ID` are set.
48
+ */
49
+ export const loadConfig = async (profile) => {
50
+ return (await loadConfigWithSource(profile))?.config ?? null;
51
+ };
52
+ /**
53
+ * Same as {@link loadConfig}, but also reports whether the config was loaded
54
+ * from a profile file on disk (`fromFile: true`) or synthesized entirely from
55
+ * environment variables (`fromFile: false`).
56
+ */
57
+ export const loadConfigWithSource = async (profile) => {
58
+ var _a, _b;
59
+ const rootConfigPath = await getRootConfigPath();
60
+ if (rootConfigPath === null) {
61
+ return null;
62
+ }
63
+ const profileName = profile ?? (await getActiveProfileName());
64
+ if (profileName === null) {
65
+ return null;
66
+ }
67
+ validateProfileName(profileName);
68
+ const fs = await import('node:fs');
69
+ const path = await import('node:path');
70
+ const configPath = path.join(rootConfigPath, 'configs', `${profileName}.json`);
71
+ let configRaw;
72
+ try {
73
+ configRaw = await fs.promises.readFile(configPath, 'utf-8');
74
+ }
75
+ catch (err) {
76
+ if (err?.code !== 'ENOENT') {
77
+ throw new Error(`failed to read config file ${configPath}: ${err}`);
78
+ }
79
+ configRaw = null;
80
+ }
81
+ if (configRaw === null) {
82
+ const organizationId = readEnv('ANTHROPIC_ORGANIZATION_ID');
83
+ const identityTokenFile = readEnv('ANTHROPIC_IDENTITY_TOKEN_FILE');
84
+ const federationRuleId = readEnv('ANTHROPIC_FEDERATION_RULE_ID');
85
+ if (federationRuleId && organizationId) {
86
+ return {
87
+ fromFile: false,
88
+ config: {
89
+ organization_id: organizationId,
90
+ // A defaulted-but-empty CI variable (`ANTHROPIC_WORKSPACE_ID=""`) is
91
+ // treated as unset — readEnv coerces empty to undefined, and the body
92
+ // builder's truthy check skips it — so `"workspace_id": ""` never goes
93
+ // on the wire.
94
+ workspace_id: readEnv('ANTHROPIC_WORKSPACE_ID'),
95
+ base_url: readEnv('ANTHROPIC_BASE_URL'),
96
+ authentication: {
97
+ type: 'oidc_federation',
98
+ federation_rule_id: federationRuleId,
99
+ service_account_id: readEnv('ANTHROPIC_SERVICE_ACCOUNT_ID'),
100
+ identity_token: identityTokenFile ? { source: 'file', path: identityTokenFile } : undefined,
101
+ scope: readEnv('ANTHROPIC_SCOPE'),
102
+ },
103
+ },
104
+ };
105
+ }
106
+ return null;
107
+ }
108
+ let config;
109
+ try {
110
+ config = JSON.parse(configRaw);
111
+ }
112
+ catch (err) {
113
+ throw new Error(`failed to parse config file ${configPath}: ${err}`);
114
+ }
115
+ if (!config.authentication) {
116
+ throw new Error(`config file ${configPath} is missing "authentication"`);
117
+ }
118
+ const authType = config.authentication.type;
119
+ if (authType !== 'oidc_federation' && authType !== 'user_oauth') {
120
+ throw new Error(`authentication.type "${authType}" is not a known authentication type`);
121
+ }
122
+ // File values are authoritative; env vars only fill fields the file left unset.
123
+ config.organization_id ?? (config.organization_id = readEnv('ANTHROPIC_ORGANIZATION_ID'));
124
+ config.workspace_id ?? (config.workspace_id = readEnv('ANTHROPIC_WORKSPACE_ID'));
125
+ config.base_url ?? (config.base_url = readEnv('ANTHROPIC_BASE_URL'));
126
+ (_a = config.authentication).scope ?? (_a.scope = readEnv('ANTHROPIC_SCOPE'));
127
+ if (config.authentication.type === 'oidc_federation') {
128
+ if (!config.authentication.identity_token) {
129
+ const identityTokenFile = readEnv('ANTHROPIC_IDENTITY_TOKEN_FILE');
130
+ if (identityTokenFile) {
131
+ config.authentication.identity_token = {
132
+ source: 'file',
133
+ path: identityTokenFile,
134
+ };
135
+ }
136
+ }
137
+ // Unlike siblings using `??= readEnv()` (which leaves `undefined`), coerce
138
+ // to '' so the type stays `string` (always set). The downstream required
139
+ // check in credential-chain rejects empty, so semantics match but types are
140
+ // cleaner.
141
+ if (!config.authentication.federation_rule_id) {
142
+ config.authentication.federation_rule_id = readEnv('ANTHROPIC_FEDERATION_RULE_ID') ?? '';
143
+ }
144
+ (_b = config.authentication).service_account_id ?? (_b.service_account_id = readEnv('ANTHROPIC_SERVICE_ACCOUNT_ID'));
145
+ }
146
+ return { config, fromFile: true };
147
+ };
148
+ /**
149
+ * Loads the credential material for the active profile.
150
+ *
151
+ * Returns the parsed credentials or `null` when running in a browser or
152
+ * no credentials file can be found.
153
+ *
154
+ * **Profile resolution** (first match wins):
155
+ * 1. `ANTHROPIC_PROFILE` environment variable
156
+ * 2. Contents of `<config_dir>/active_config` file
157
+ * 3. `"default"`
158
+ *
159
+ * **Credentials path resolution** (first match wins):
160
+ * 1. `authentication.credentials_path` from the active profile's config (via {@link loadConfig})
161
+ * 2. `<config_dir>/credentials/<profile>.json`
162
+ */
163
+ export const loadCredentials = async () => {
164
+ const config = await loadConfig();
165
+ const credentialsPath = await getCredentialsPath(config);
166
+ if (!credentialsPath) {
167
+ return null;
168
+ }
169
+ const fs = await import('node:fs');
170
+ let raw;
171
+ try {
172
+ raw = await fs.promises.readFile(credentialsPath, 'utf-8');
173
+ }
174
+ catch (err) {
175
+ if (err?.code !== 'ENOENT') {
176
+ throw new Error(`failed to read credentials file ${credentialsPath}: ${err}`);
177
+ }
178
+ return null;
179
+ }
180
+ let creds;
181
+ try {
182
+ creds = JSON.parse(raw);
183
+ }
184
+ catch (err) {
185
+ throw new Error(`failed to parse credentials file ${credentialsPath}: ${err}`);
186
+ }
187
+ if (creds.type && creds.type !== 'oauth_token') {
188
+ throw new Error(`credentials file ${credentialsPath} has unsupported type "${creds.type}" (want "oauth_token")`);
189
+ }
190
+ return creds;
191
+ };
192
+ /**
193
+ * Resolves the credentials file path for the given config.
194
+ *
195
+ * Uses `authentication.credentials_path` from the config if set, otherwise
196
+ * falls back to `<config_dir>/credentials/<profile>.json`.
197
+ *
198
+ * Returns `null` when running in a browser or the path cannot be resolved.
199
+ */
200
+ export const getCredentialsPath = async (config, profile) => {
201
+ if (config?.authentication.credentials_path) {
202
+ return config.authentication.credentials_path;
203
+ }
204
+ const rootConfigPath = await getRootConfigPath();
205
+ if (!rootConfigPath) {
206
+ return null;
207
+ }
208
+ const profileName = profile ?? (await getActiveProfileName());
209
+ if (!profileName) {
210
+ return null;
211
+ }
212
+ validateProfileName(profileName);
213
+ const path = await import('node:path');
214
+ return path.join(rootConfigPath, 'credentials', `${profileName}.json`);
215
+ };
216
+ const getRootConfigPath = async () => {
217
+ if (!supportsLocalConfigFiles()) {
218
+ return null;
219
+ }
220
+ const path = await import('node:path');
221
+ // ANTHROPIC_CONFIG_DIR is treated as a trusted path: it is set by the
222
+ // process operator, not by remote input, so it is not validated.
223
+ const configDir = readEnv('ANTHROPIC_CONFIG_DIR');
224
+ if (configDir) {
225
+ return configDir;
226
+ }
227
+ const os = getPlatformHeaders()['X-Stainless-OS'];
228
+ if (os === 'Windows') {
229
+ const appData = readEnv('APPDATA');
230
+ if (appData) {
231
+ return path.join(appData, 'Anthropic');
232
+ }
233
+ const userProfile = readEnv('USERPROFILE');
234
+ if (userProfile) {
235
+ return path.join(userProfile, 'AppData', 'Roaming', 'Anthropic');
236
+ }
237
+ // No usable Windows config root — return null so callers fall through to
238
+ // "no config available" rather than silently writing under C:\.
239
+ return null;
240
+ }
241
+ const xdgConfigHome = readEnv('XDG_CONFIG_HOME');
242
+ if (xdgConfigHome) {
243
+ return path.join(xdgConfigHome, 'anthropic');
244
+ }
245
+ const home = readEnv('HOME');
246
+ if (home) {
247
+ return path.join(home, '.config', 'anthropic');
248
+ }
249
+ return null;
250
+ };
251
+ const supportsLocalConfigFiles = () => {
252
+ const runtime = getPlatformHeaders()['X-Stainless-Runtime'];
253
+ return runtime === 'node' || runtime === 'deno';
254
+ };
255
+ const getActiveProfileName = async () => {
256
+ const rootConfigPath = await getRootConfigPath();
257
+ if (!rootConfigPath) {
258
+ return null;
259
+ }
260
+ const profileName = readEnv('ANTHROPIC_PROFILE');
261
+ if (profileName) {
262
+ return profileName;
263
+ }
264
+ const fs = await import('node:fs');
265
+ const path = await import('node:path');
266
+ const filePath = path.join(rootConfigPath, 'active_config');
267
+ try {
268
+ return (await fs.promises.readFile(filePath, 'utf-8')).trim() || 'default';
269
+ }
270
+ catch (err) {
271
+ if (err?.code !== 'ENOENT') {
272
+ throw new Error(`failed to read ${filePath}: ${err}`);
273
+ }
274
+ return 'default';
275
+ }
276
+ };
277
+ //# sourceMappingURL=credentials.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.mjs","sourceRoot":"","sources":["../src/core/credentials.ts"],"names":[],"mappings":"OAAO,EAAE,kBAAkB,EAAE;OACtB,EAAE,OAAO,EAAE;AAElB,0FAA0F;AAC1F,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAC;AACzC,8FAA8F;AAC9F,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,CAAC;AAgE9C,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAEjD,SAAS,mBAAmB,CAAC,IAAY;IACvC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,IAAI,KAAK,GAAG,IAAI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AO,KAAK,MAAM,IAAI,OAAO,KAAK,MAAM,CAAC;AAClD,CAAC,CAAC;AAEF,MAAM,oBAAoB,GAAG,KAAK,IAA4B,EAAE;IAC9D,MAAM,cAAc,GAAG,MAAM,iBAAiB,EAAE,CAAC;IACjD,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACjD,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC;IACnC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC;IACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;IAC5D,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,SAAS,CAAC;IAC7E,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAK,GAA6B,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtD,MAAM,IAAI,KAAK,CAAC,kBAAkB,QAAQ,KAAK,GAAG,EAAE,CAAC,CAAC;QACxD,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Current time as unix epoch seconds. */
2
+ export declare function nowAsSeconds(): number;
3
+ //# sourceMappingURL=time.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.d.mts","sourceRoot":"","sources":["../../src/internal/utils/time.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,wBAAgB,YAAY,IAAI,MAAM,CAErC"}
@@ -0,0 +1,3 @@
1
+ /** Current time as unix epoch seconds. */
2
+ export declare function nowAsSeconds(): number;
3
+ //# sourceMappingURL=time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/internal/utils/time.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,wBAAgB,YAAY,IAAI,MAAM,CAErC"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nowAsSeconds = nowAsSeconds;
4
+ /** Current time as unix epoch seconds. */
5
+ function nowAsSeconds() {
6
+ return Math.floor(Date.now() / 1000);
7
+ }
8
+ //# sourceMappingURL=time.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.js","sourceRoot":"","sources":["../../src/internal/utils/time.ts"],"names":[],"mappings":";;AACA,oCAEC;AAHD,0CAA0C;AAC1C,SAAgB,YAAY;IAC1B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AACvC,CAAC"}
@@ -0,0 +1,5 @@
1
+ /** Current time as unix epoch seconds. */
2
+ export function nowAsSeconds() {
3
+ return Math.floor(Date.now() / 1000);
4
+ }
5
+ //# sourceMappingURL=time.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.mjs","sourceRoot":"","sources":["../../src/internal/utils/time.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,MAAM,UAAU,YAAY;IAC1B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AACvC,CAAC"}
@@ -0,0 +1,39 @@
1
+ import type { Fetch } from "../../internal/builtin-types.mjs";
2
+ import { type AnthropicConfig } from "../../core/credentials.mjs";
3
+ import type { CredentialResult } from "./types.mjs";
4
+ /**
5
+ * Builds a {@link CredentialResult} from an explicit {@link AnthropicConfig}.
6
+ *
7
+ * Use this when constructing a client from an in-memory config object rather
8
+ * than from profile files or environment variables.
9
+ *
10
+ * For `oidc_federation`, `authentication.credentials_path` is optional —
11
+ * if omitted, every call performs a fresh exchange with no on-disk cache.
12
+ * For `user_oauth`, `authentication.credentials_path` is required (it is
13
+ * where the access/refresh tokens live).
14
+ */
15
+ export type ResolverOptions = {
16
+ baseURL: string;
17
+ fetch: Fetch;
18
+ userAgent?: string | undefined;
19
+ onCacheWriteError?: ((err: unknown) => void) | undefined;
20
+ onSafetyWarning?: ((msg: string) => void) | undefined;
21
+ };
22
+ export declare function resolveCredentialsFromConfig(config: AnthropicConfig, options: ResolverOptions): CredentialResult;
23
+ /**
24
+ * Resolves a {@link CredentialResult} from the environment. Returns `null`
25
+ * when no credentials can be resolved.
26
+ *
27
+ * Resolution order:
28
+ *
29
+ * 1. Config file for the active profile (or the explicit `profile` argument)
30
+ * → dispatch on `authentication.type` (`oidc_federation`, `user_oauth`)
31
+ * 2. Environment variables `ANTHROPIC_FEDERATION_RULE_ID` +
32
+ * `ANTHROPIC_ORGANIZATION_ID` (+ identity token) → OIDC federation
33
+ * 3. Nothing matches → `null`
34
+ *
35
+ * Passing `profile` selects `<config_dir>/configs/<profile>.json` directly,
36
+ * skipping `ANTHROPIC_PROFILE` / `active_config` resolution.
37
+ */
38
+ export declare function defaultCredentials(options: ResolverOptions, profile?: string): Promise<CredentialResult | null>;
39
+ //# sourceMappingURL=credential-chain.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential-chain.d.mts","sourceRoot":"","sources":["../../src/lib/credentials/credential-chain.ts"],"names":[],"mappings":"OAAO,KAAK,EAAE,KAAK,EAAE;OAEd,EAIL,KAAK,eAAe,EACrB;OACM,KAAK,EAAuB,gBAAgB,EAAyB;AAY5E;;;;;;;;;;GAUG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,iBAAiB,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACzD,eAAe,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CACvD,CAAC;AAEF,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,eAAe,GACvB,gBAAgB,CAkBlB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,eAAe,EACxB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CA6BlC"}
@@ -0,0 +1,39 @@
1
+ import type { Fetch } from "../../internal/builtin-types.js";
2
+ import { type AnthropicConfig } from "../../core/credentials.js";
3
+ import type { CredentialResult } from "./types.js";
4
+ /**
5
+ * Builds a {@link CredentialResult} from an explicit {@link AnthropicConfig}.
6
+ *
7
+ * Use this when constructing a client from an in-memory config object rather
8
+ * than from profile files or environment variables.
9
+ *
10
+ * For `oidc_federation`, `authentication.credentials_path` is optional —
11
+ * if omitted, every call performs a fresh exchange with no on-disk cache.
12
+ * For `user_oauth`, `authentication.credentials_path` is required (it is
13
+ * where the access/refresh tokens live).
14
+ */
15
+ export type ResolverOptions = {
16
+ baseURL: string;
17
+ fetch: Fetch;
18
+ userAgent?: string | undefined;
19
+ onCacheWriteError?: ((err: unknown) => void) | undefined;
20
+ onSafetyWarning?: ((msg: string) => void) | undefined;
21
+ };
22
+ export declare function resolveCredentialsFromConfig(config: AnthropicConfig, options: ResolverOptions): CredentialResult;
23
+ /**
24
+ * Resolves a {@link CredentialResult} from the environment. Returns `null`
25
+ * when no credentials can be resolved.
26
+ *
27
+ * Resolution order:
28
+ *
29
+ * 1. Config file for the active profile (or the explicit `profile` argument)
30
+ * → dispatch on `authentication.type` (`oidc_federation`, `user_oauth`)
31
+ * 2. Environment variables `ANTHROPIC_FEDERATION_RULE_ID` +
32
+ * `ANTHROPIC_ORGANIZATION_ID` (+ identity token) → OIDC federation
33
+ * 3. Nothing matches → `null`
34
+ *
35
+ * Passing `profile` selects `<config_dir>/configs/<profile>.json` directly,
36
+ * skipping `ANTHROPIC_PROFILE` / `active_config` resolution.
37
+ */
38
+ export declare function defaultCredentials(options: ResolverOptions, profile?: string): Promise<CredentialResult | null>;
39
+ //# sourceMappingURL=credential-chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential-chain.d.ts","sourceRoot":"","sources":["../../src/lib/credentials/credential-chain.ts"],"names":[],"mappings":"OAAO,KAAK,EAAE,KAAK,EAAE;OAEd,EAIL,KAAK,eAAe,EACrB;OACM,KAAK,EAAuB,gBAAgB,EAAyB;AAY5E;;;;;;;;;;GAUG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,iBAAiB,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACzD,eAAe,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CACvD,CAAC;AAEF,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,eAAe,GACvB,gBAAgB,CAkBlB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,eAAe,EACxB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CA6BlC"}