@bastani/pi-ai 0.9.28-alpha.4 → 0.9.28
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/CHANGELOG.md +51 -0
- package/README.md +2 -0
- package/dist/auth/helpers.d.ts +6 -0
- package/dist/auth/helpers.d.ts.map +1 -1
- package/dist/auth/helpers.js +24 -13
- package/dist/auth/helpers.js.map +1 -1
- package/dist/auth/resolve.d.ts +15 -3
- package/dist/auth/resolve.d.ts.map +1 -1
- package/dist/auth/resolve.js +23 -3
- package/dist/auth/resolve.js.map +1 -1
- package/dist/auth/types.d.ts +11 -0
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +4 -14
- package/dist/models.js.map +1 -1
- package/dist/providers/data/.manifest.json +1 -1
- package/dist/providers/data/mistral.json +1 -1
- package/dist/providers/data/opencode-go.json +1 -1
- package/dist/providers/data/opencode.json +1 -1
- package/dist/providers/data/openrouter.json +1 -1
- package/dist/providers/data/radius.json +1 -1
- package/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/providers/openai-decisions.js +2 -2
- package/dist/providers/openai-decisions.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,57 @@ This package is a Bastani fork of `@earendil-works/pi-ai`. Upstream history at t
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.9.28] - 2026-10-08
|
|
8
|
+
|
|
9
|
+
### Breaking Changes
|
|
10
|
+
|
|
11
|
+
- Stream functions must return `AssistantMessageEventStream`, for example from `createAssistantMessageEventStream()`. Plain `EventStream` subclasses are no longer assignable to this response stream type.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- Added `ApiKeyAuth.borrowCredentialsFrom` and `sharedApiKeyAuth()`, which let a provider without a login of its own reuse the stored API key of the first listed provider that has one, then fall back to its environment variables. A borrowing provider has no stored credential of its own, and stored OAuth credentials of the listed providers are skipped.
|
|
16
|
+
- Added `openaiApiProvider()` (`openai-api`) and `anthropicApiProvider()` (`anthropic-api`): API-key-only twins of `openai` and `anthropic` that list the same chat models under their own provider ID, so a subscription login on the source provider no longer displaces the API key.
|
|
17
|
+
- Added Claude Haiku 5.5 with adaptive thinking, `xhigh`/`max` effort, prompt-length pricing tiers, and mid-conversation effort, system-message, and tool changes. Bedrock supports adaptive thinking, native `xhigh`, thinking block binding, and prompt caching for Haiku 5.5.
|
|
18
|
+
- Added optional `durationMs` to assistant messages and tool results. Assistant response streams measure elapsed time with a monotonic clock, preserving existing measurements and leaving deferred results untimed.
|
|
19
|
+
- Added `LoginOptions.agentName` for apps to identify themselves during OpenAI ChatGPT and Codex browser login.
|
|
20
|
+
- Added OpenAI's Decisions classifier API and the `openai/gpt-6-luna` classifier, available with an API key but not Sign in with ChatGPT credentials.
|
|
21
|
+
- Added optional `images` to classifier contexts. Unsupported models and classifier APIs return an error result instead of ignoring images.
|
|
22
|
+
- Added Azure Foundry Chat Completions and `azure/deepseek-v4-pro`, with Azure endpoint resolution, deployment-name mapping, and supported reasoning efforts.
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
|
|
26
|
+
- `openai-decisions` no longer has a login or stored credential of its own. It reuses the API key stored for `openai-api`, then the one stored for `openai`, then `OPENAI_API_KEY`; a ChatGPT sign-in on `openai` is skipped.
|
|
27
|
+
- Moved the GPT-6 Luna Decisions classifier to the `openai-decisions` provider (`openaiDecisionsProvider()`), with its own API-key credential. The `openai` provider no longer lists classifiers.
|
|
28
|
+
- The faux provider compares prompt-cache prefixes message by message without changing simulated usage counts.
|
|
29
|
+
- Renamed the Azure provider to `azure`, retaining the `azure-openai-responses` API ID and compatibility with the former provider name and exports.
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
|
|
33
|
+
- Fixed Kimi K3 cost estimates on Moonshot providers to use official pricing without cache-write charges.
|
|
34
|
+
- Fixed Magistral models retaining Mistral's `prompt_mode` reasoning controls when catalog metadata advertises effort levels.
|
|
35
|
+
- Fixed failed lazy API setup messages using the failure time instead of the request start as their timestamp.
|
|
36
|
+
- Fixed prompt-length pricing tiers being lost when generating model catalogs from AI Gateway, OpenRouter, and models.dev.
|
|
37
|
+
- Corrected the Claude Sonnet 5.5 fallback catalog's cache-read rate to the official $0.10 per million tokens.
|
|
38
|
+
- Fixed Bedrock Claude Haiku 5.5 requests sending unsupported caller temperature settings.
|
|
39
|
+
- Reduced context-limit request failures by estimating new input at 3.5 characters per token when calculating output limits.
|
|
40
|
+
- Fixed transient `server_busy`, `servers are currently busy`, and Mistral `finish_reason: "error"` responses ending the turn instead of being retried.
|
|
41
|
+
- Fixed Anthropic browser login when port 53692 is reserved or in use by falling back to a free loopback port. Copy-code login remains available for headless use.
|
|
42
|
+
- Fixed Codex requests ignoring caller and model overrides for `originator` and `User-Agent` headers; authentication headers remain authoritative.
|
|
43
|
+
- Fixed the selected reasoning effort not reaching OpenAI GPT models on Bedrock Converse. GPT-oss effort is clamped to `low`, `medium`, or `high`; Astra keeps its existing payload.
|
|
44
|
+
- Fixed Radius models disabled by an organization still appearing in the catalog. Fetched or cached gateway catalogs now replace the bundled defaults, including empty catalogs.
|
|
45
|
+
- Fixed OpenAI Decisions accepting unknown choices or out-of-range probabilities, confidence, and scores as successful answers, and failing to return error results when request hooks or fetch throw null or undefined.
|
|
46
|
+
- Retry transient HTTP/2 errors containing "pending stream has been canceled".
|
|
47
|
+
|
|
48
|
+
## [0.9.28-alpha.5] - 2026-10-08
|
|
49
|
+
|
|
50
|
+
### Added
|
|
51
|
+
|
|
52
|
+
- Added `ApiKeyAuth.borrowCredentialsFrom` and `sharedApiKeyAuth()`, which let a provider without a login of its own reuse the stored API key of the first listed provider that has one, then fall back to its environment variables. A borrowing provider has no stored credential of its own, and stored OAuth credentials of the listed providers are skipped.
|
|
53
|
+
|
|
54
|
+
### Changed
|
|
55
|
+
|
|
56
|
+
- `openai-decisions` no longer has a login or stored credential of its own. It reuses the API key stored for `openai-api`, then the one stored for `openai`, then `OPENAI_API_KEY`; a ChatGPT sign-in on `openai` is skipped.
|
|
57
|
+
|
|
7
58
|
## [0.9.28-alpha.4] - 2026-10-07
|
|
8
59
|
|
|
9
60
|
### Breaking Changes
|
package/README.md
CHANGED
|
@@ -404,6 +404,8 @@ if (modelAuth) {
|
|
|
404
404
|
|
|
405
405
|
Both overloads resolve credentials, refresh expired OAuth when necessary, and may return an auth-derived `apiKey`, `headers`, or `baseUrl`. `getAuth()` resolves `undefined` for unconfigured providers and rejects with `ModelsError` when something is actually broken (`"oauth"`: token refresh failed, credential preserved for re-login; `"auth"`: key resolution or credential store failure). Request paths surface the same failures as stream errors.
|
|
406
406
|
|
|
407
|
+
A provider can reuse other providers' stored API keys instead of offering its own login. List their IDs in `ApiKeyAuth.borrowCredentialsFrom`, or build the auth with `sharedApiKeyAuth(name, envVars, providerIds)`. The provider then has no stored credential of its own: the first listed provider with a stored API key supplies it, in the order given. Stored OAuth credentials are skipped, and the environment variables apply when none qualifies. `openai-decisions` uses this with `['openai-api', 'openai']`.
|
|
408
|
+
|
|
407
409
|
`getAuth()`, `checkAuth()`, `getAvailable()`, login, and logout accept optional caller cancellation through their existing options or interaction objects and remain unbounded when no signal is supplied. Provider `login`, `ApiKeyAuth.check`, `ApiKeyAuth.resolve`, and `OAuthAuth.refresh` implementations always receive a concrete signal and must honor it for blocking work.
|
|
408
410
|
|
|
409
411
|
### Transforming Request Headers
|
package/dist/auth/helpers.d.ts
CHANGED
|
@@ -6,6 +6,12 @@ import type { ApiKeyAuth, OAuthAuth } from "./types.ts";
|
|
|
6
6
|
* write their own `ApiKeyAuth`.
|
|
7
7
|
*/
|
|
8
8
|
export declare function envApiKeyAuth(name: string, envVars: readonly string[]): ApiKeyAuth;
|
|
9
|
+
/**
|
|
10
|
+
* Api-key auth without a `login` of its own. It reuses the stored api key of
|
|
11
|
+
* the first provider in `borrowCredentialsFrom` that has one, then falls back
|
|
12
|
+
* to the first set env var.
|
|
13
|
+
*/
|
|
14
|
+
export declare function sharedApiKeyAuth(name: string, envVars: readonly string[], borrowCredentialsFrom: readonly string[]): ApiKeyAuth;
|
|
9
15
|
/**
|
|
10
16
|
* Wraps a dynamically imported `OAuthAuth` so provider definitions can
|
|
11
17
|
* advertise OAuth without importing the implementation. The flow loads on
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/auth/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/auth/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAiBxD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,UAAU,CAWlF;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,qBAAqB,EAAE,SAAS,MAAM,EAAE,GACtC,UAAU,CAEZ;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,IAAI,EAAE,MAAM,OAAO,CAAC,SAAS,CAAC,CAAC;CAC/B,GAAG,SAAS,CAeZ"}
|
package/dist/auth/helpers.js
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
function resolveStoredKeyOrEnv(envVars) {
|
|
2
|
+
return async ({ ctx, credential, signal }) => {
|
|
3
|
+
signal.throwIfAborted();
|
|
4
|
+
if (credential?.key) {
|
|
5
|
+
return { auth: { apiKey: credential.key }, env: credential.env, source: "stored credential" };
|
|
6
|
+
}
|
|
7
|
+
for (const envVar of envVars) {
|
|
8
|
+
const value = await ctx.env(envVar);
|
|
9
|
+
signal.throwIfAborted();
|
|
10
|
+
if (value)
|
|
11
|
+
return { auth: { apiKey: value }, source: envVar };
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
1
16
|
/**
|
|
2
17
|
* Standard api-key auth: a stored credential key wins, otherwise the first
|
|
3
18
|
* set env var resolves. Includes a `login` that prompts for the key.
|
|
@@ -13,21 +28,17 @@ export function envApiKeyAuth(name, envVars) {
|
|
|
13
28
|
interaction.signal.throwIfAborted();
|
|
14
29
|
return { type: "api_key", key };
|
|
15
30
|
},
|
|
16
|
-
resolve:
|
|
17
|
-
signal.throwIfAborted();
|
|
18
|
-
if (credential?.key) {
|
|
19
|
-
return { auth: { apiKey: credential.key }, env: credential.env, source: "stored credential" };
|
|
20
|
-
}
|
|
21
|
-
for (const envVar of envVars) {
|
|
22
|
-
const value = await ctx.env(envVar);
|
|
23
|
-
signal.throwIfAborted();
|
|
24
|
-
if (value)
|
|
25
|
-
return { auth: { apiKey: value }, source: envVar };
|
|
26
|
-
}
|
|
27
|
-
return undefined;
|
|
28
|
-
},
|
|
31
|
+
resolve: resolveStoredKeyOrEnv(envVars),
|
|
29
32
|
};
|
|
30
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Api-key auth without a `login` of its own. It reuses the stored api key of
|
|
36
|
+
* the first provider in `borrowCredentialsFrom` that has one, then falls back
|
|
37
|
+
* to the first set env var.
|
|
38
|
+
*/
|
|
39
|
+
export function sharedApiKeyAuth(name, envVars, borrowCredentialsFrom) {
|
|
40
|
+
return { name, borrowCredentialsFrom, resolve: resolveStoredKeyOrEnv(envVars) };
|
|
41
|
+
}
|
|
31
42
|
/**
|
|
32
43
|
* Wraps a dynamically imported `OAuthAuth` so provider definitions can
|
|
33
44
|
* advertise OAuth without importing the implementation. The flow loads on
|
package/dist/auth/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/auth/helpers.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/auth/helpers.ts"],"names":[],"mappings":"AAEA,SAAS,qBAAqB,CAAC,OAA0B;IACxD,OAAO,KAAK,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE;QAC5C,MAAM,CAAC,cAAc,EAAE,CAAC;QACxB,IAAI,UAAU,EAAE,GAAG,EAAE,CAAC;YACrB,OAAO,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,GAAG,EAAE,EAAE,GAAG,EAAE,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC;QAC/F,CAAC;QACD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC9B,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACpC,MAAM,CAAC,cAAc,EAAE,CAAC;YACxB,IAAI,KAAK;gBAAE,OAAO,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QAC/D,CAAC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,OAA0B;IACrE,OAAO;QACN,IAAI;QACJ,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE;YAC5B,WAAW,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;YACpC,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,EAAE,IAA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":["import type { ApiKeyAuth, OAuthAuth } from \"./types.ts\";\n\nfunction resolveStoredKeyOrEnv(envVars: readonly string[]): ApiKeyAuth[\"resolve\"] {\n\treturn async ({ ctx, credential, signal }) => {\n\t\tsignal.throwIfAborted();\n\t\tif (credential?.key) {\n\t\t\treturn { auth: { apiKey: credential.key }, env: credential.env, source: \"stored credential\" };\n\t\t}\n\t\tfor (const envVar of envVars) {\n\t\t\tconst value = await ctx.env(envVar);\n\t\t\tsignal.throwIfAborted();\n\t\t\tif (value) return { auth: { apiKey: value }, source: envVar };\n\t\t}\n\t\treturn undefined;\n\t};\n}\n\n/**\n * Standard api-key auth: a stored credential key wins, otherwise the first\n * set env var resolves. Includes a `login` that prompts for the key.\n * Providers with non-standard resolution (provider env, ambient files, IAM)\n * write their own `ApiKeyAuth`.\n */\nexport function envApiKeyAuth(name: string, envVars: readonly string[]): ApiKeyAuth {\n\treturn {\n\t\tname,\n\t\tlogin: async (interaction) => {\n\t\t\tinteraction.signal.throwIfAborted();\n\t\t\tconst key = await interaction.prompt({ type: \"secret\", message: `Enter ${name}` });\n\t\t\tinteraction.signal.throwIfAborted();\n\t\t\treturn { type: \"api_key\", key };\n\t\t},\n\t\tresolve: resolveStoredKeyOrEnv(envVars),\n\t};\n}\n\n/**\n * Api-key auth without a `login` of its own. It reuses the stored api key of\n * the first provider in `borrowCredentialsFrom` that has one, then falls back\n * to the first set env var.\n */\nexport function sharedApiKeyAuth(\n\tname: string,\n\tenvVars: readonly string[],\n\tborrowCredentialsFrom: readonly string[],\n): ApiKeyAuth {\n\treturn { name, borrowCredentialsFrom, resolve: resolveStoredKeyOrEnv(envVars) };\n}\n\n/**\n * Wraps a dynamically imported `OAuthAuth` so provider definitions can\n * advertise OAuth without importing the implementation. The flow loads on\n * first `login`/`refresh`/`toAuth` call; callers keep Node-only flow code out\n * of bundles by loading through a bundler-opaque dynamic import (variable\n * specifier, see the bedrock lazy wrapper).\n */\nexport function lazyOAuth(input: {\n\tname: string;\n\tisSubscription?: boolean;\n\tloginLabel?: string;\n\tusesCallbackServer?: boolean;\n\tload: () => Promise<OAuthAuth>;\n}): OAuthAuth {\n\tlet promise: Promise<OAuthAuth> | undefined;\n\tconst loaded = () => {\n\t\tpromise ??= input.load();\n\t\treturn promise;\n\t};\n\treturn {\n\t\tname: input.name,\n\t\tisSubscription: input.isSubscription,\n\t\tloginLabel: input.loginLabel,\n\t\tusesCallbackServer: input.usesCallbackServer,\n\t\tlogin: async (interaction, options) => (await loaded()).login(interaction, options),\n\t\trefresh: async (credential, signal) => (await loaded()).refresh(credential, signal),\n\t\ttoAuth: async (credential) => (await loaded()).toAuth(credential),\n\t};\n}\n"]}
|
package/dist/auth/resolve.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ProviderEnv } from "../types.ts";
|
|
2
2
|
export { ModelsError, type ModelsErrorCode } from "../utils/models-error.ts";
|
|
3
|
-
import type { AuthContext, AuthResult, CredentialStore, OAuthAuth, OAuthCredential, ProviderAuth } from "./types.ts";
|
|
3
|
+
import type { AuthContext, AuthResult, Credential, CredentialStore, OAuthAuth, OAuthCredential, ProviderAuth } from "./types.ts";
|
|
4
4
|
/** Bound for pre-transport request-auth work: credential read, OAuth refresh, and toAuth. */
|
|
5
5
|
export declare const REQUEST_AUTH_PREPARATION_TIMEOUT_MS = 15000;
|
|
6
6
|
/** Source-neutral diagnostic when pre-transport request auth exceeds {@link REQUEST_AUTH_PREPARATION_TIMEOUT_MS}. */
|
|
@@ -15,8 +15,9 @@ export interface AuthResolutionOverrides {
|
|
|
15
15
|
/**
|
|
16
16
|
* Auth resolution shared by all operations in a `Models` collection.
|
|
17
17
|
* A stored credential owns the provider: ambient/env is consulted only when
|
|
18
|
-
* nothing is stored.
|
|
19
|
-
*
|
|
18
|
+
* nothing is stored. A provider that borrows credentials reads only its
|
|
19
|
+
* lenders' (see `readProviderCredential`). No silent env fallback after a failed
|
|
20
|
+
* refresh or for a credential type without a matching handler.
|
|
20
21
|
*/
|
|
21
22
|
export declare function resolveProviderAuth(provider: {
|
|
22
23
|
id: string;
|
|
@@ -24,4 +25,15 @@ export declare function resolveProviderAuth(provider: {
|
|
|
24
25
|
}, credentials: CredentialStore, authContext: AuthContext, overrides?: AuthResolutionOverrides): Promise<AuthResult | undefined>;
|
|
25
26
|
/** Cancellation stops waiting for the credential lock, not an already started token rotation. */
|
|
26
27
|
export declare function refreshStoredOAuthCredential(credentials: CredentialStore, providerId: string, oauth: OAuthAuth, needsRefresh: (credential: OAuthCredential) => boolean, signal: AbortSignal): Promise<OAuthCredential | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* The stored credential that supplies auth for `provider`. A provider that
|
|
30
|
+
* declares `apiKey.borrowCredentialsFrom` has no credential of its own: it
|
|
31
|
+
* uses the first usable api-key credential among those providers. Any other
|
|
32
|
+
* provider uses its own. Shared by request auth and availability checks so
|
|
33
|
+
* both agree on which credential applies.
|
|
34
|
+
*/
|
|
35
|
+
export declare function readProviderCredential(credentials: CredentialStore, provider: {
|
|
36
|
+
id: string;
|
|
37
|
+
auth: ProviderAuth;
|
|
38
|
+
}, signal: AbortSignal): Promise<Credential | undefined>;
|
|
27
39
|
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/auth/resolve.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/auth/resolve.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C,OAAO,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE7E,OAAO,KAAK,EAGX,WAAW,EACX,UAAU,EACV,UAAU,EACV,eAAe,EACf,SAAS,EACT,eAAe,EACf,YAAY,EACZ,MAAM,YAAY,CAAC;AAEpB,6FAA6F;AAC7F,eAAO,MAAM,mCAAmC,QAAS,CAAC;AAE1D,qHAAqH;AACrH,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED,MAAM,WAAW,uBAAuB;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,WAAW,CAAC;IAClB,kFAAkF;IAClF,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAClC,QAAQ,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,YAAY,CAAA;CAAE,EAC5C,WAAW,EAAE,eAAe,EAC5B,WAAW,EAAE,WAAW,EACxB,SAAS,CAAC,EAAE,uBAAuB,GACjC,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAwBjC;AA6DD,iGAAiG;AACjG,wBAAsB,4BAA4B,CACjD,WAAW,EAAE,eAAe,EAC5B,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,SAAS,EAChB,YAAY,EAAE,CAAC,UAAU,EAAE,eAAe,KAAK,OAAO,EACtD,MAAM,EAAE,WAAW,GACjB,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CA+BtC;AAiDD;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC3C,WAAW,EAAE,eAAe,EAC5B,QAAQ,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,YAAY,CAAA;CAAE,EAC5C,MAAM,EAAE,WAAW,GACjB,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAQjC"}
|
package/dist/auth/resolve.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { normalizeProviderId } from "../provider-id.js";
|
|
1
2
|
import { operationSignal, raceWithAbortSignal } from "../utils/abort.js";
|
|
2
3
|
import { ModelsError } from "../utils/models-error.js";
|
|
3
4
|
export { ModelsError } from "../utils/models-error.js";
|
|
@@ -10,8 +11,9 @@ export function requestAuthTimeoutMessage(providerId) {
|
|
|
10
11
|
/**
|
|
11
12
|
* Auth resolution shared by all operations in a `Models` collection.
|
|
12
13
|
* A stored credential owns the provider: ambient/env is consulted only when
|
|
13
|
-
* nothing is stored.
|
|
14
|
-
*
|
|
14
|
+
* nothing is stored. A provider that borrows credentials reads only its
|
|
15
|
+
* lenders' (see `readProviderCredential`). No silent env fallback after a failed
|
|
16
|
+
* refresh or for a credential type without a matching handler.
|
|
15
17
|
*/
|
|
16
18
|
export function resolveProviderAuth(provider, credentials, authContext, overrides) {
|
|
17
19
|
const caller = operationSignal(overrides?.signal);
|
|
@@ -42,7 +44,7 @@ async function resolveProviderAuthWithSignal(provider, credentials, authContext,
|
|
|
42
44
|
env: overrides.env,
|
|
43
45
|
}, signal);
|
|
44
46
|
}
|
|
45
|
-
const stored = await
|
|
47
|
+
const stored = await readProviderCredential(credentials, provider, signal);
|
|
46
48
|
if (stored) {
|
|
47
49
|
if (stored.type === "oauth" && provider.auth.oauth) {
|
|
48
50
|
return resolveStoredOAuth(credentials, provider.id, provider.auth.oauth, stored, signal, overrides?.minOAuthValidityMs);
|
|
@@ -135,6 +137,24 @@ async function resolveApiKey(authContext, apiKey, providerId, credential, signal
|
|
|
135
137
|
throw new ModelsError("auth", `API key auth failed for provider ${providerId}`, { cause: error });
|
|
136
138
|
}
|
|
137
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* The stored credential that supplies auth for `provider`. A provider that
|
|
142
|
+
* declares `apiKey.borrowCredentialsFrom` has no credential of its own: it
|
|
143
|
+
* uses the first usable api-key credential among those providers. Any other
|
|
144
|
+
* provider uses its own. Shared by request auth and availability checks so
|
|
145
|
+
* both agree on which credential applies.
|
|
146
|
+
*/
|
|
147
|
+
export async function readProviderCredential(credentials, provider, signal) {
|
|
148
|
+
const lenders = provider.auth.apiKey?.borrowCredentialsFrom;
|
|
149
|
+
if (!lenders)
|
|
150
|
+
return readCredential(credentials, provider.id, signal);
|
|
151
|
+
for (const sourceId of lenders) {
|
|
152
|
+
const borrowed = await readCredential(credentials, normalizeProviderId(sourceId), signal);
|
|
153
|
+
if (borrowed?.type === "api_key" && borrowed.key)
|
|
154
|
+
return borrowed;
|
|
155
|
+
}
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
138
158
|
async function readCredential(credentials, providerId, signal) {
|
|
139
159
|
try {
|
|
140
160
|
const credential = await credentials.read(providerId, { signal });
|
package/dist/auth/resolve.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/auth/resolve.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,WAAW,EAAwB,MAAM,0BAA0B,CAAC;AAc7E,6FAA6F;AAC7F,MAAM,CAAC,MAAM,mCAAmC,GAAG,MAAM,CAAC;AAE1D,qHAAqH;AACrH,MAAM,UAAU,yBAAyB,CAAC,UAAkB;IAC3D,OAAO,wCAAwC,UAAU,yDAAyD,CAAC;AACpH,CAAC;AAUD;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAClC,QAA4C,EAC5C,WAA4B,EAC5B,WAAwB,EACxB,SAAmC;IAEnC,MAAM,MAAM,GAAG,eAAe,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,IAAI,eAAe,EAAE,CAAC;IACtC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;QAC7B,OAAO,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC,EAAE,mCAAmC,CAAC,CAAC;IACxC,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IACzD,MAAM,SAAS,GAAG,6BAA6B,CAC9C,QAAQ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CAAC,CACnG,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,IAAI,WAAW,CAAC,MAAM,EAAE,oCAAoC,UAAU,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACnG,CAAC;AACF,CAAC","sourcesContent":["import type { ProviderEnv } from \"../types.ts\";\nimport { operationSignal, raceWithAbortSignal } from \"../utils/abort.ts\";\nimport { ModelsError } from \"../utils/models-error.ts\";\n\nexport { ModelsError, type ModelsErrorCode } from \"../utils/models-error.ts\";\n\nimport type {\n\tApiKeyAuth,\n\tApiKeyCredential,\n\tAuthContext,\n\tAuthResult,\n\tCredential,\n\tCredentialStore,\n\tOAuthAuth,\n\tOAuthCredential,\n\tProviderAuth,\n} from \"./types.ts\";\n\n/** Bound for pre-transport request-auth work: credential read, OAuth refresh, and toAuth. */\nexport const REQUEST_AUTH_PREPARATION_TIMEOUT_MS = 15_000;\n\n/** Source-neutral diagnostic when pre-transport request auth exceeds {@link REQUEST_AUTH_PREPARATION_TIMEOUT_MS}. */\nexport function requestAuthTimeoutMessage(providerId: string): string {\n\treturn `Request authentication timed out for ${providerId}. Check the provider's credential source and try again.`;\n}\n\nexport interface AuthResolutionOverrides {\n\tapiKey?: string;\n\tenv?: ProviderEnv;\n\t/** Require this much remaining OAuth-token validity; defaults to five minutes. */\n\tminOAuthValidityMs?: number;\n\tsignal?: AbortSignal;\n}\n\n/**\n * Auth resolution shared by all operations in a `Models` collection.\n * A stored credential owns the provider: ambient/env is consulted only when\n * nothing is stored. No silent env fallback after a failed refresh or for a\n * credential type without a matching handler.\n */\nexport function resolveProviderAuth(\n\tprovider: { id: string; auth: ProviderAuth },\n\tcredentials: CredentialStore,\n\tauthContext: AuthContext,\n\toverrides?: AuthResolutionOverrides,\n): Promise<AuthResult | undefined> {\n\tconst caller = operationSignal(overrides?.signal);\n\tconst timeout = new AbortController();\n\tconst timer = setTimeout(() => {\n\t\ttimeout.abort();\n\t}, REQUEST_AUTH_PREPARATION_TIMEOUT_MS);\n\tconst signal = AbortSignal.any([caller, timeout.signal]);\n\tconst operation = resolveProviderAuthWithSignal(\n\t\tprovider,\n\t\tcredentials,\n\t\tauthContext,\n\t\t{ ...overrides, signal },\n\t\tsignal,\n\t);\n\treturn raceWithAbortSignal(operation, signal)\n\t\t.catch((error: unknown) => {\n\t\t\tif (timeout.signal.aborted && !caller.aborted) {\n\t\t\t\tthrow new ModelsError(\"auth\", requestAuthTimeoutMessage(provider.id));\n\t\t\t}\n\t\t\tthrow error;\n\t\t})\n\t\t.finally(() => {\n\t\t\tclearTimeout(timer);\n\t\t});\n}\n\nasync function resolveProviderAuthWithSignal(\n\tprovider: { id: string; auth: ProviderAuth },\n\tcredentials: CredentialStore,\n\tauthContext: AuthContext,\n\toverrides: AuthResolutionOverrides | undefined,\n\tsignal: AbortSignal,\n): Promise<AuthResult | undefined> {\n\tsignal.throwIfAborted();\n\tconst requestAuthContext = overrides?.env ? overlayEnvAuthContext(authContext, overrides.env) : authContext;\n\n\tif (overrides?.apiKey !== undefined && provider.auth.apiKey) {\n\t\treturn resolveApiKey(\n\t\t\trequestAuthContext,\n\t\t\tprovider.auth.apiKey,\n\t\t\tprovider.id,\n\t\t\t{\n\t\t\t\ttype: \"api_key\",\n\t\t\t\tkey: overrides.apiKey,\n\t\t\t\tenv: overrides.env,\n\t\t\t},\n\t\t\tsignal,\n\t\t);\n\t}\n\n\tconst stored = await readCredential(credentials, provider.id, signal);\n\tif (stored) {\n\t\tif (stored.type === \"oauth\" && provider.auth.oauth) {\n\t\t\treturn resolveStoredOAuth(\n\t\t\t\tcredentials,\n\t\t\t\tprovider.id,\n\t\t\t\tprovider.auth.oauth,\n\t\t\t\tstored,\n\t\t\t\tsignal,\n\t\t\t\toverrides?.minOAuthValidityMs,\n\t\t\t);\n\t\t}\n\t\tif (stored.type === \"api_key\" && provider.auth.apiKey) {\n\t\t\tconst credential = overrides?.env ? { ...stored, env: { ...stored.env, ...overrides.env } } : stored;\n\t\t\treturn resolveApiKey(requestAuthContext, provider.auth.apiKey, provider.id, credential, signal);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t// Ambient (env vars, AWS profiles, ADC files).\n\treturn provider.auth.apiKey\n\t\t? resolveApiKey(requestAuthContext, provider.auth.apiKey, provider.id, undefined, signal)\n\t\t: undefined;\n}\n\nfunction overlayEnvAuthContext(base: AuthContext, env: ProviderEnv): AuthContext {\n\treturn {\n\t\tenv: async (name) => env[name] || (await base.env(name)),\n\t\tfileExists: (path) => base.fileExists(path),\n\t};\n}\n\nconst DEFAULT_OAUTH_MINIMUM_VALIDITY_MS = 5 * 60 * 1000;\nconst DEFAULT_OAUTH_REFRESH_TIMEOUT_MS = 60_000;\n\n/** Cancellation stops waiting for the credential lock, not an already started token rotation. */\nexport async function refreshStoredOAuthCredential(\n\tcredentials: CredentialStore,\n\tproviderId: string,\n\toauth: OAuthAuth,\n\tneedsRefresh: (credential: OAuthCredential) => boolean,\n\tsignal: AbortSignal,\n): Promise<OAuthCredential | undefined> {\n\tlet post: Credential | undefined;\n\tconst lockWait = new AbortController();\n\tconst cancelLockWait = () => lockWait.abort(signal.reason);\n\tsignal.addEventListener(\"abort\", cancelLockWait, { once: true });\n\tif (signal.aborted) cancelLockWait();\n\ttry {\n\t\tpost = await credentials.modify(\n\t\t\tproviderId,\n\t\t\tasync (current) => {\n\t\t\t\tsignal.removeEventListener(\"abort\", cancelLockWait);\n\t\t\t\tsignal.throwIfAborted();\n\t\t\t\tif (current?.type !== \"oauth\") return undefined;\n\t\t\t\tif (!needsRefresh(current)) return undefined;\n\t\t\t\ttry {\n\t\t\t\t\tconst refreshSignal = AbortSignal.timeout(DEFAULT_OAUTH_REFRESH_TIMEOUT_MS);\n\t\t\t\t\treturn await raceWithAbortSignal(oauth.refresh(current, refreshSignal), refreshSignal);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthrow new ModelsError(\"oauth\", `OAuth refresh failed for ${providerId}`, { cause: error });\n\t\t\t\t}\n\t\t\t},\n\t\t\t{ signal: lockWait.signal },\n\t\t);\n\t} catch (error) {\n\t\tif (error instanceof ModelsError) throw error;\n\t\tsignal.throwIfAborted();\n\t\tthrow new ModelsError(\"auth\", `Credential store modify failed for ${providerId}`, { cause: error });\n\t} finally {\n\t\tsignal.removeEventListener(\"abort\", cancelLockWait);\n\t}\n\treturn post?.type === \"oauth\" ? post : undefined;\n}\n\n/** Refresh expiring tokens under the credential-store lock and persist rotation before releasing it. */\nasync function resolveStoredOAuth(\n\tcredentials: CredentialStore,\n\tproviderId: string,\n\toauth: OAuthAuth,\n\tstored: OAuthCredential,\n\tsignal: AbortSignal,\n\tminOAuthValidityMs?: number,\n): Promise<AuthResult | undefined> {\n\tconst minimumValidityMs = Math.max(DEFAULT_OAUTH_MINIMUM_VALIDITY_MS, minOAuthValidityMs ?? 0);\n\tconst expiresSoon = (credential: OAuthCredential) => Date.now() + minimumValidityMs >= credential.expires;\n\tlet credential = stored;\n\n\tif (expiresSoon(credential)) {\n\t\t// Optimistic check said expired; the authoritative check runs under the lock.\n\t\tconst post = await refreshStoredOAuthCredential(credentials, providerId, oauth, expiresSoon, signal);\n\t\tif (!post) return undefined;\n\t\tcredential = post;\n\t\t// The normal five-minute window triggers a refresh but does not impose a\n\t\t// provider contract. Explicit callers (such as bearer-token export) do\n\t\t// require the requested minimum after the refresh.\n\t\tif (minOAuthValidityMs !== undefined && expiresSoon(credential)) {\n\t\t\tthrow new ModelsError(\"oauth\", `OAuth refresh returned a token that expires too soon for ${providerId}`);\n\t\t}\n\t}\n\n\ttry {\n\t\treturn { auth: await oauth.toAuth(credential), source: \"OAuth\" };\n\t} catch (error) {\n\t\tthrow new ModelsError(\"oauth\", `OAuth auth derivation failed for ${providerId}`, { cause: error });\n\t}\n}\n\nasync function resolveApiKey(\n\tauthContext: AuthContext,\n\tapiKey: ApiKeyAuth,\n\tproviderId: string,\n\tcredential: ApiKeyCredential | undefined,\n\tsignal: AbortSignal,\n): Promise<AuthResult | undefined> {\n\ttry {\n\t\treturn await apiKey.resolve({ ctx: authContext, credential, signal });\n\t} catch (error) {\n\t\tthrow new ModelsError(\"auth\", `API key auth failed for provider ${providerId}`, { cause: error });\n\t}\n}\n\nasync function readCredential(\n\tcredentials: CredentialStore,\n\tproviderId: string,\n\tsignal: AbortSignal,\n): Promise<Credential | undefined> {\n\ttry {\n\t\tconst credential = await credentials.read(providerId, { signal });\n\t\treturn (\n\t\t\tcredential ??\n\t\t\t(providerId === \"azure\" ? await credentials.read(\"azure-openai-responses\", { signal }) : undefined)\n\t\t);\n\t} catch (error) {\n\t\tthrow new ModelsError(\"auth\", `Credential store read failed for ${providerId}`, { cause: error });\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/auth/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,WAAW,EAAwB,MAAM,0BAA0B,CAAC;AAc7E,6FAA6F;AAC7F,MAAM,CAAC,MAAM,mCAAmC,GAAG,MAAM,CAAC;AAE1D,qHAAqH;AACrH,MAAM,UAAU,yBAAyB,CAAC,UAAkB;IAC3D,OAAO,wCAAwC,UAAU,yDAAyD,CAAC;AACpH,CAAC;AAUD;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAClC,QAA4C,EAC5C,WAA4B,EAC5B,WAAwB,EACxB,SAAmC;IAEnC,MAAM,MAAM,GAAG,eAAe,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,IAAI,eAAe,EAAE,CAAC;IACtC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;QAC7B,OAAO,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC,EAAE,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AAI,CAAC,OAAO;QAAE,OAAO,cAAc,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IACtE,KAAK,MAAM,QAAQ,IAAI,OAAO,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,WAAW,EAAE,mBAAmB,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;QAC1F,IAAI,QAAQ,EAAE,IAAI,KAAK,SAAS,IAAI,QAAQ,CAAC,GAAG;YAAE,OAAO,QAAQ,CAAC;IACnE,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,KAAK,UAAU,cAAc,CAC5B,WAA4B,EAC5B,UAAkB,EAClB,MAAmB;IAEnB,IAAI,CAAC;QACJ,MAAM,UAAU,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QAClE,OAAO,CACN,UAAU;YACV,CAAC,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,WAAW,CAAC,IAAI,CAAC,wBAAwB,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CACnG,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,IAAI,WAAW,CAAC,MAAM,EAAE,oCAAoC,UAAU,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACnG,CAAC;AACF,CAAC","sourcesContent":["import { normalizeProviderId } from \"../provider-id.ts\";\nimport type { ProviderEnv } from \"../types.ts\";\nimport { operationSignal, raceWithAbortSignal } from \"../utils/abort.ts\";\nimport { ModelsError } from \"../utils/models-error.ts\";\n\nexport { ModelsError, type ModelsErrorCode } from \"../utils/models-error.ts\";\n\nimport type {\n\tApiKeyAuth,\n\tApiKeyCredential,\n\tAuthContext,\n\tAuthResult,\n\tCredential,\n\tCredentialStore,\n\tOAuthAuth,\n\tOAuthCredential,\n\tProviderAuth,\n} from \"./types.ts\";\n\n/** Bound for pre-transport request-auth work: credential read, OAuth refresh, and toAuth. */\nexport const REQUEST_AUTH_PREPARATION_TIMEOUT_MS = 15_000;\n\n/** Source-neutral diagnostic when pre-transport request auth exceeds {@link REQUEST_AUTH_PREPARATION_TIMEOUT_MS}. */\nexport function requestAuthTimeoutMessage(providerId: string): string {\n\treturn `Request authentication timed out for ${providerId}. Check the provider's credential source and try again.`;\n}\n\nexport interface AuthResolutionOverrides {\n\tapiKey?: string;\n\tenv?: ProviderEnv;\n\t/** Require this much remaining OAuth-token validity; defaults to five minutes. */\n\tminOAuthValidityMs?: number;\n\tsignal?: AbortSignal;\n}\n\n/**\n * Auth resolution shared by all operations in a `Models` collection.\n * A stored credential owns the provider: ambient/env is consulted only when\n * nothing is stored. A provider that borrows credentials reads only its\n * lenders' (see `readProviderCredential`). No silent env fallback after a failed\n * refresh or for a credential type without a matching handler.\n */\nexport function resolveProviderAuth(\n\tprovider: { id: string; auth: ProviderAuth },\n\tcredentials: CredentialStore,\n\tauthContext: AuthContext,\n\toverrides?: AuthResolutionOverrides,\n): Promise<AuthResult | undefined> {\n\tconst caller = operationSignal(overrides?.signal);\n\tconst timeout = new AbortController();\n\tconst timer = setTimeout(() => {\n\t\ttimeout.abort();\n\t}, REQUEST_AUTH_PREPARATION_TIMEOUT_MS);\n\tconst signal = AbortSignal.any([caller, timeout.signal]);\n\tconst operation = resolveProviderAuthWithSignal(\n\t\tprovider,\n\t\tcredentials,\n\t\tauthContext,\n\t\t{ ...overrides, signal },\n\t\tsignal,\n\t);\n\treturn raceWithAbortSignal(operation, signal)\n\t\t.catch((error: unknown) => {\n\t\t\tif (timeout.signal.aborted && !caller.aborted) {\n\t\t\t\tthrow new ModelsError(\"auth\", requestAuthTimeoutMessage(provider.id));\n\t\t\t}\n\t\t\tthrow error;\n\t\t})\n\t\t.finally(() => {\n\t\t\tclearTimeout(timer);\n\t\t});\n}\n\nasync function resolveProviderAuthWithSignal(\n\tprovider: { id: string; auth: ProviderAuth },\n\tcredentials: CredentialStore,\n\tauthContext: AuthContext,\n\toverrides: AuthResolutionOverrides | undefined,\n\tsignal: AbortSignal,\n): Promise<AuthResult | undefined> {\n\tsignal.throwIfAborted();\n\tconst requestAuthContext = overrides?.env ? overlayEnvAuthContext(authContext, overrides.env) : authContext;\n\n\tif (overrides?.apiKey !== undefined && provider.auth.apiKey) {\n\t\treturn resolveApiKey(\n\t\t\trequestAuthContext,\n\t\t\tprovider.auth.apiKey,\n\t\t\tprovider.id,\n\t\t\t{\n\t\t\t\ttype: \"api_key\",\n\t\t\t\tkey: overrides.apiKey,\n\t\t\t\tenv: overrides.env,\n\t\t\t},\n\t\t\tsignal,\n\t\t);\n\t}\n\n\tconst stored = await readProviderCredential(credentials, provider, signal);\n\tif (stored) {\n\t\tif (stored.type === \"oauth\" && provider.auth.oauth) {\n\t\t\treturn resolveStoredOAuth(\n\t\t\t\tcredentials,\n\t\t\t\tprovider.id,\n\t\t\t\tprovider.auth.oauth,\n\t\t\t\tstored,\n\t\t\t\tsignal,\n\t\t\t\toverrides?.minOAuthValidityMs,\n\t\t\t);\n\t\t}\n\t\tif (stored.type === \"api_key\" && provider.auth.apiKey) {\n\t\t\tconst credential = overrides?.env ? { ...stored, env: { ...stored.env, ...overrides.env } } : stored;\n\t\t\treturn resolveApiKey(requestAuthContext, provider.auth.apiKey, provider.id, credential, signal);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t// Ambient (env vars, AWS profiles, ADC files).\n\treturn provider.auth.apiKey\n\t\t? resolveApiKey(requestAuthContext, provider.auth.apiKey, provider.id, undefined, signal)\n\t\t: undefined;\n}\n\nfunction overlayEnvAuthContext(base: AuthContext, env: ProviderEnv): AuthContext {\n\treturn {\n\t\tenv: async (name) => env[name] || (await base.env(name)),\n\t\tfileExists: (path) => base.fileExists(path),\n\t};\n}\n\nconst DEFAULT_OAUTH_MINIMUM_VALIDITY_MS = 5 * 60 * 1000;\nconst DEFAULT_OAUTH_REFRESH_TIMEOUT_MS = 60_000;\n\n/** Cancellation stops waiting for the credential lock, not an already started token rotation. */\nexport async function refreshStoredOAuthCredential(\n\tcredentials: CredentialStore,\n\tproviderId: string,\n\toauth: OAuthAuth,\n\tneedsRefresh: (credential: OAuthCredential) => boolean,\n\tsignal: AbortSignal,\n): Promise<OAuthCredential | undefined> {\n\tlet post: Credential | undefined;\n\tconst lockWait = new AbortController();\n\tconst cancelLockWait = () => lockWait.abort(signal.reason);\n\tsignal.addEventListener(\"abort\", cancelLockWait, { once: true });\n\tif (signal.aborted) cancelLockWait();\n\ttry {\n\t\tpost = await credentials.modify(\n\t\t\tproviderId,\n\t\t\tasync (current) => {\n\t\t\t\tsignal.removeEventListener(\"abort\", cancelLockWait);\n\t\t\t\tsignal.throwIfAborted();\n\t\t\t\tif (current?.type !== \"oauth\") return undefined;\n\t\t\t\tif (!needsRefresh(current)) return undefined;\n\t\t\t\ttry {\n\t\t\t\t\tconst refreshSignal = AbortSignal.timeout(DEFAULT_OAUTH_REFRESH_TIMEOUT_MS);\n\t\t\t\t\treturn await raceWithAbortSignal(oauth.refresh(current, refreshSignal), refreshSignal);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthrow new ModelsError(\"oauth\", `OAuth refresh failed for ${providerId}`, { cause: error });\n\t\t\t\t}\n\t\t\t},\n\t\t\t{ signal: lockWait.signal },\n\t\t);\n\t} catch (error) {\n\t\tif (error instanceof ModelsError) throw error;\n\t\tsignal.throwIfAborted();\n\t\tthrow new ModelsError(\"auth\", `Credential store modify failed for ${providerId}`, { cause: error });\n\t} finally {\n\t\tsignal.removeEventListener(\"abort\", cancelLockWait);\n\t}\n\treturn post?.type === \"oauth\" ? post : undefined;\n}\n\n/** Refresh expiring tokens under the credential-store lock and persist rotation before releasing it. */\nasync function resolveStoredOAuth(\n\tcredentials: CredentialStore,\n\tproviderId: string,\n\toauth: OAuthAuth,\n\tstored: OAuthCredential,\n\tsignal: AbortSignal,\n\tminOAuthValidityMs?: number,\n): Promise<AuthResult | undefined> {\n\tconst minimumValidityMs = Math.max(DEFAULT_OAUTH_MINIMUM_VALIDITY_MS, minOAuthValidityMs ?? 0);\n\tconst expiresSoon = (credential: OAuthCredential) => Date.now() + minimumValidityMs >= credential.expires;\n\tlet credential = stored;\n\n\tif (expiresSoon(credential)) {\n\t\t// Optimistic check said expired; the authoritative check runs under the lock.\n\t\tconst post = await refreshStoredOAuthCredential(credentials, providerId, oauth, expiresSoon, signal);\n\t\tif (!post) return undefined;\n\t\tcredential = post;\n\t\t// The normal five-minute window triggers a refresh but does not impose a\n\t\t// provider contract. Explicit callers (such as bearer-token export) do\n\t\t// require the requested minimum after the refresh.\n\t\tif (minOAuthValidityMs !== undefined && expiresSoon(credential)) {\n\t\t\tthrow new ModelsError(\"oauth\", `OAuth refresh returned a token that expires too soon for ${providerId}`);\n\t\t}\n\t}\n\n\ttry {\n\t\treturn { auth: await oauth.toAuth(credential), source: \"OAuth\" };\n\t} catch (error) {\n\t\tthrow new ModelsError(\"oauth\", `OAuth auth derivation failed for ${providerId}`, { cause: error });\n\t}\n}\n\nasync function resolveApiKey(\n\tauthContext: AuthContext,\n\tapiKey: ApiKeyAuth,\n\tproviderId: string,\n\tcredential: ApiKeyCredential | undefined,\n\tsignal: AbortSignal,\n): Promise<AuthResult | undefined> {\n\ttry {\n\t\treturn await apiKey.resolve({ ctx: authContext, credential, signal });\n\t} catch (error) {\n\t\tthrow new ModelsError(\"auth\", `API key auth failed for provider ${providerId}`, { cause: error });\n\t}\n}\n\n/**\n * The stored credential that supplies auth for `provider`. A provider that\n * declares `apiKey.borrowCredentialsFrom` has no credential of its own: it\n * uses the first usable api-key credential among those providers. Any other\n * provider uses its own. Shared by request auth and availability checks so\n * both agree on which credential applies.\n */\nexport async function readProviderCredential(\n\tcredentials: CredentialStore,\n\tprovider: { id: string; auth: ProviderAuth },\n\tsignal: AbortSignal,\n): Promise<Credential | undefined> {\n\tconst lenders = provider.auth.apiKey?.borrowCredentialsFrom;\n\tif (!lenders) return readCredential(credentials, provider.id, signal);\n\tfor (const sourceId of lenders) {\n\t\tconst borrowed = await readCredential(credentials, normalizeProviderId(sourceId), signal);\n\t\tif (borrowed?.type === \"api_key\" && borrowed.key) return borrowed;\n\t}\n\treturn undefined;\n}\n\nasync function readCredential(\n\tcredentials: CredentialStore,\n\tproviderId: string,\n\tsignal: AbortSignal,\n): Promise<Credential | undefined> {\n\ttry {\n\t\tconst credential = await credentials.read(providerId, { signal });\n\t\treturn (\n\t\t\tcredential ??\n\t\t\t(providerId === \"azure\" ? await credentials.read(\"azure-openai-responses\", { signal }) : undefined)\n\t\t);\n\t} catch (error) {\n\t\tthrow new ModelsError(\"auth\", `Credential store read failed for ${providerId}`, { cause: error });\n\t}\n}\n"]}
|
package/dist/auth/types.d.ts
CHANGED
|
@@ -172,6 +172,17 @@ export interface ApiKeyAuth {
|
|
|
172
172
|
name: string;
|
|
173
173
|
/** Interactive setup (prompt for key/provider env). Absent = ambient-only. */
|
|
174
174
|
login?(interaction: ProviderAuthInteraction): Promise<ApiKeyCredential>;
|
|
175
|
+
/**
|
|
176
|
+
* Provider ids whose stored api-key credentials this provider reuses, in
|
|
177
|
+
* precedence order. A borrowing provider has no stored credential of its
|
|
178
|
+
* own; anything stored under its id is ignored. The first
|
|
179
|
+
* listed provider with a stored api-key credential that has a key is passed
|
|
180
|
+
* to `resolve()` as `credential`; stored OAuth credentials and key-less
|
|
181
|
+
* api-key credentials are skipped. When none qualifies, `resolve()` runs
|
|
182
|
+
* without a credential, so ambient sources (env vars) still apply. Pair with
|
|
183
|
+
* an absent `login`.
|
|
184
|
+
*/
|
|
185
|
+
borrowCredentialsFrom?: readonly string[];
|
|
175
186
|
/**
|
|
176
187
|
* Optional side-effect-free availability check. Use this when `resolve()` may
|
|
177
188
|
* execute commands or perform other request-time work. Missing means Models
|
package/dist/auth/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot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U,CAAC,EAAE,MAAM,CAAC;IAEpB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B,KAAK,CAAC,WAAW,EAAE,uBAAuB,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAE9F;;;OAGG;IACH,OAAO,CAAC,UAAU,EAAE,eAAe,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAEpF;;;;OAIG;IACH,MAAM,CAAC,UAAU,EAAE,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;CACxD;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC5B,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,KAAK,CAAC,EAAE,SAAS,CAAC;CAClB"}
|
package/dist/auth/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/auth/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ProviderEnv, ProviderHeaders } from \"../types.ts\";\n\n/**\n * Request auth for a single model request. If a value cannot be expressed as\n * `apiKey`, `headers`, or `baseUrl`, it is provider config, not auth.\n */\nexport interface ModelAuth {\n\tapiKey?: string;\n\theaders?: ProviderHeaders;\n\tbaseUrl?: string;\n}\n\n/**\n * Stored api-key credential. `env` holds provider-scoped environment/config\n * values such as Cloudflare account/gateway ids.\n */\nexport interface ApiKeyCredential {\n\ttype: \"api_key\";\n\tkey?: string;\n\tenv?: ProviderEnv;\n}\n\n/** OAuth token data returned by extension compatibility flows. */\nexport interface OAuthCredentials {\n\trefresh: string;\n\taccess: string;\n\texpires: number;\n\t[key: string]: unknown;\n}\n\n/** Stored canonical OAuth credential. */\nexport interface OAuthCredential extends OAuthCredentials {\n\ttype: \"oauth\";\n}\n\n/** One type-tagged credential per provider — the shape of today's auth.json. */\nexport type Credential = ApiKeyCredential | OAuthCredential;\n\n/** Non-secret credential metadata for account/status enumeration. */\nexport interface CredentialInfo {\n\tproviderId: string;\n\ttype: Credential[\"type\"];\n}\n\n/** Optional cancellation for public auth and credential operations. */\nexport interface AuthOperationOptions {\n\tsignal?: AbortSignal;\n}\n\n/**\n * App-owned credential storage, keyed by `Provider.id`, one credential per\n * provider. `modify` is the only write path, so every mutation is a\n * serialized read-modify-write; `Models.getAuth()` runs OAuth refresh inside\n * `modify` so concurrent requests cannot double-refresh a rotated token. The\n * app persists a credential after login via\n * `modify(provider.id, async () => credential)`. Login/logout orchestration\n * is app-owned.\n *\n * Error semantics: `read` resolves `undefined` for missing entries. Methods\n * reject only on storage failure; `Models` wraps such rejections in\n * `ModelsError` with code \"auth\". Best-effort stores that serve an in-memory\n * view and record persistence errors internally (like coding-agent's\n * AuthStorage) are valid implementations.\n */\nexport interface CredentialStore {\n\t/**\n\t * Read the stored credential, possibly expired. Display/status use;\n\t * resolved request auth comes from `Models.getAuth()`.\n\t */\n\tread(providerId: string, options?: AuthOperationOptions): Promise<Credential | undefined>;\n\n\t/**\n\t * List stored credential metadata without resolving or exposing secrets.\n\t * Implementations must not execute configured API-key commands while listing.\n\t */\n\tlist(options?: AuthOperationOptions): Promise<readonly CredentialInfo[]>;\n\n\t/**\n\t * Serialized write — the only write path. `fn` sees the current credential\n\t * because correct writes (refresh, login-during-refresh) depend on it;\n\t * return the new credential, or undefined to leave the entry unchanged.\n\t * Mutual exclusion per provider id, cross-process too where the backing\n\t * store supports it (e.g. a file lock). Resolves with the post-write\n\t * credential. Rejections from `fn` propagate.\n\t */\n\tmodify(\n\t\tproviderId: string,\n\t\tfn: (current: Credential | undefined) => Promise<Credential | undefined>,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<Credential | undefined>;\n\n\t/** Remove a credential (logout). Implementations serialize this against `modify`. */\n\tdelete(providerId: string, options?: AuthOperationOptions): Promise<void>;\n}\n\n/** Environment access for auth resolution. Injectable for tests and browsers. */\nexport interface AuthContext {\n\tenv(name: string): Promise<string | undefined>;\n\t/** Check whether a file exists. Supports a leading `~`. Always false in browsers. */\n\tfileExists(path: string): Promise<boolean>;\n}\n\n/** Result of resolving auth for a model. */\nexport interface AuthResult {\n\tauth: ModelAuth;\n\t/** Provider-scoped environment/config values resolved from credentials and ambient context. */\n\tenv?: ProviderEnv;\n\t/** Human-readable label for status UI: \"ANTHROPIC_API_KEY\", \"OAuth\", \"~/.aws/credentials\". */\n\tsource?: string;\n}\n\nexport interface AuthCheck {\n\tsource?: string;\n\ttype: \"api_key\" | \"oauth\";\n}\n\nexport type AuthType = \"api_key\" | \"oauth\";\n\n/**\n * Prompt shown to the user during login. `signal` lets the flow cancel a\n * pending prompt when an out-of-band event resolves the step, e.g. a\n * `manual_code` prompt raced against a callback server, aborted when the\n * callback wins.\n */\nexport type AuthPrompt = { signal?: AbortSignal } & (\n\t| { type: \"text\"; message: string; placeholder?: string }\n\t| { type: \"secret\"; message: string; placeholder?: string }\n\t| { type: \"select\"; message: string; options: readonly { id: string; label: string; description?: string }[] }\n\t| { type: \"manual_code\"; message: string; placeholder?: string }\n);\n\nexport interface AuthInfoLink {\n\turl: string;\n\tlabel?: string;\n}\n\nexport type AuthEvent =\n\t| { type: \"info\"; message: string; links?: readonly AuthInfoLink[] }\n\t| { type: \"auth_url\"; url: string; instructions?: string }\n\t| {\n\t\t\ttype: \"device_code\";\n\t\t\tuserCode: string;\n\t\t\tverificationUri: string;\n\t\t\tintervalSeconds?: number;\n\t\t\texpiresInSeconds?: number;\n\t }\n\t| { type: \"progress\"; message: string };\n\n/**\n * Login interaction callbacks serving both api-key and OAuth flows.\n *\n * `prompt()` returns the entered/selected string (`select` returns the option\n * id). Rejects on cancel/abort. `signal` aborts the whole login flow;\n * per-prompt cancellation uses `AuthPrompt.signal`.\n */\nexport interface AuthInteraction {\n\tsignal?: AbortSignal;\n\n\tprompt(prompt: AuthPrompt): Promise<string>;\n\tnotify(event: AuthEvent): void;\n}\n\n/** Normalized interaction passed to provider login implementations. */\nexport type ProviderAuthInteraction = AuthInteraction & { signal: AbortSignal };\n\n/**\n * Api-key auth: stored key/provider env plus ambient sources (env vars, AWS\n * profiles, ADC files). Ambient-only providers omit `login`.\n */\nexport interface ApiKeyAuth {\n\t/** Display name, e.g. \"Anthropic API key\". */\n\tname: string;\n\n\t/** Interactive setup (prompt for key/provider env). Absent = ambient-only. */\n\tlogin?(interaction: ProviderAuthInteraction): Promise<ApiKeyCredential>;\n\n\t/**\n\t * Optional side-effect-free availability check. Use this when `resolve()` may\n\t * execute commands or perform other request-time work. Missing means Models\n\t * checks availability by resolving auth.\n\t */\n\tcheck?(input: {\n\t\tctx: AuthContext;\n\t\tcredential?: ApiKeyCredential;\n\t\tsignal: AbortSignal;\n\t}): Promise<AuthCheck | undefined>;\n\n\t/**\n\t * Resolve auth from the stored credential and/or ambient sources, merging\n\t * per field (`credential.key ?? env(\"...\")`, `credential.env?.NAME ?? env(\"...\")`).\n\t * undefined = not configured. Resolution is provider-scoped; model-specific\n\t * endpoint preparation happens after auth has been resolved.\n\t */\n\tresolve(input: {\n\t\tctx: AuthContext;\n\t\tcredential?: ApiKeyCredential;\n\t\tsignal: AbortSignal;\n\t}): Promise<AuthResult | undefined>;\n}\n\n/** App context supplied to provider login flows. */\nexport interface LoginOptions {\n\t/** Stable UUID for this installation, created lazily by the app. */\n\tgetDeviceId?: () => string;\n\t/** App name used for OpenAI's agent name hint and Codex browser login originator. */\n\tagentName?: string;\n}\n\n/**\n * OAuth auth. The `refresh`/`toAuth` split lets `Models` own the locked\n * refresh pattern: `refresh` produces a credential, `toAuth` derives request\n * auth from whatever credential ends up stored.\n */\nexport interface OAuthAuth {\n\t/** Display name, e.g. \"Anthropic (Claude Pro/Max)\". */\n\tname: string;\n\n\t/** Whether access through this auth method is backed by a provider subscription. */\n\tisSubscription?: boolean;\n\n\t/** Selector label for the OAuth login option, e.g. \"Sign in with SuperGrok or X Premium\". */\n\tloginLabel?: string;\n\n\tusesCallbackServer?: boolean;\n\n\tlogin(interaction: ProviderAuthInteraction, options?: LoginOptions): Promise<OAuthCredential>;\n\n\t/**\n\t * Exchange the refresh token. Network call; throws on failure\n\t * (invalid_grant etc.). `Models` runs this under the store lock.\n\t */\n\trefresh(credential: OAuthCredential, signal: AbortSignal): Promise<OAuthCredential>;\n\n\t/**\n\t * Side-effect-free derivation of request auth from a valid credential.\n\t * Covers per-credential baseUrl (GitHub Copilot). Async so lazy wrappers\n\t * can load the implementation on first use.\n\t */\n\ttoAuth(credential: OAuthCredential): Promise<ModelAuth>;\n}\n\n/**\n * Provider auth. At least one of `apiKey`/`oauth` must be present: even\n * ambient-credential providers and keyless local servers provide `apiKey`\n * auth whose `resolve()` reports whether the provider is configured.\n */\nexport interface ProviderAuth {\n\tapiKey?: ApiKeyAuth;\n\toauth?: OAuthAuth;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/auth/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ProviderEnv, ProviderHeaders } from \"../types.ts\";\n\n/**\n * Request auth for a single model request. If a value cannot be expressed as\n * `apiKey`, `headers`, or `baseUrl`, it is provider config, not auth.\n */\nexport interface ModelAuth {\n\tapiKey?: string;\n\theaders?: ProviderHeaders;\n\tbaseUrl?: string;\n}\n\n/**\n * Stored api-key credential. `env` holds provider-scoped environment/config\n * values such as Cloudflare account/gateway ids.\n */\nexport interface ApiKeyCredential {\n\ttype: \"api_key\";\n\tkey?: string;\n\tenv?: ProviderEnv;\n}\n\n/** OAuth token data returned by extension compatibility flows. */\nexport interface OAuthCredentials {\n\trefresh: string;\n\taccess: string;\n\texpires: number;\n\t[key: string]: unknown;\n}\n\n/** Stored canonical OAuth credential. */\nexport interface OAuthCredential extends OAuthCredentials {\n\ttype: \"oauth\";\n}\n\n/** One type-tagged credential per provider — the shape of today's auth.json. */\nexport type Credential = ApiKeyCredential | OAuthCredential;\n\n/** Non-secret credential metadata for account/status enumeration. */\nexport interface CredentialInfo {\n\tproviderId: string;\n\ttype: Credential[\"type\"];\n}\n\n/** Optional cancellation for public auth and credential operations. */\nexport interface AuthOperationOptions {\n\tsignal?: AbortSignal;\n}\n\n/**\n * App-owned credential storage, keyed by `Provider.id`, one credential per\n * provider. `modify` is the only write path, so every mutation is a\n * serialized read-modify-write; `Models.getAuth()` runs OAuth refresh inside\n * `modify` so concurrent requests cannot double-refresh a rotated token. The\n * app persists a credential after login via\n * `modify(provider.id, async () => credential)`. Login/logout orchestration\n * is app-owned.\n *\n * Error semantics: `read` resolves `undefined` for missing entries. Methods\n * reject only on storage failure; `Models` wraps such rejections in\n * `ModelsError` with code \"auth\". Best-effort stores that serve an in-memory\n * view and record persistence errors internally (like coding-agent's\n * AuthStorage) are valid implementations.\n */\nexport interface CredentialStore {\n\t/**\n\t * Read the stored credential, possibly expired. Display/status use;\n\t * resolved request auth comes from `Models.getAuth()`.\n\t */\n\tread(providerId: string, options?: AuthOperationOptions): Promise<Credential | undefined>;\n\n\t/**\n\t * List stored credential metadata without resolving or exposing secrets.\n\t * Implementations must not execute configured API-key commands while listing.\n\t */\n\tlist(options?: AuthOperationOptions): Promise<readonly CredentialInfo[]>;\n\n\t/**\n\t * Serialized write — the only write path. `fn` sees the current credential\n\t * because correct writes (refresh, login-during-refresh) depend on it;\n\t * return the new credential, or undefined to leave the entry unchanged.\n\t * Mutual exclusion per provider id, cross-process too where the backing\n\t * store supports it (e.g. a file lock). Resolves with the post-write\n\t * credential. Rejections from `fn` propagate.\n\t */\n\tmodify(\n\t\tproviderId: string,\n\t\tfn: (current: Credential | undefined) => Promise<Credential | undefined>,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<Credential | undefined>;\n\n\t/** Remove a credential (logout). Implementations serialize this against `modify`. */\n\tdelete(providerId: string, options?: AuthOperationOptions): Promise<void>;\n}\n\n/** Environment access for auth resolution. Injectable for tests and browsers. */\nexport interface AuthContext {\n\tenv(name: string): Promise<string | undefined>;\n\t/** Check whether a file exists. Supports a leading `~`. Always false in browsers. */\n\tfileExists(path: string): Promise<boolean>;\n}\n\n/** Result of resolving auth for a model. */\nexport interface AuthResult {\n\tauth: ModelAuth;\n\t/** Provider-scoped environment/config values resolved from credentials and ambient context. */\n\tenv?: ProviderEnv;\n\t/** Human-readable label for status UI: \"ANTHROPIC_API_KEY\", \"OAuth\", \"~/.aws/credentials\". */\n\tsource?: string;\n}\n\nexport interface AuthCheck {\n\tsource?: string;\n\ttype: \"api_key\" | \"oauth\";\n}\n\nexport type AuthType = \"api_key\" | \"oauth\";\n\n/**\n * Prompt shown to the user during login. `signal` lets the flow cancel a\n * pending prompt when an out-of-band event resolves the step, e.g. a\n * `manual_code` prompt raced against a callback server, aborted when the\n * callback wins.\n */\nexport type AuthPrompt = { signal?: AbortSignal } & (\n\t| { type: \"text\"; message: string; placeholder?: string }\n\t| { type: \"secret\"; message: string; placeholder?: string }\n\t| { type: \"select\"; message: string; options: readonly { id: string; label: string; description?: string }[] }\n\t| { type: \"manual_code\"; message: string; placeholder?: string }\n);\n\nexport interface AuthInfoLink {\n\turl: string;\n\tlabel?: string;\n}\n\nexport type AuthEvent =\n\t| { type: \"info\"; message: string; links?: readonly AuthInfoLink[] }\n\t| { type: \"auth_url\"; url: string; instructions?: string }\n\t| {\n\t\t\ttype: \"device_code\";\n\t\t\tuserCode: string;\n\t\t\tverificationUri: string;\n\t\t\tintervalSeconds?: number;\n\t\t\texpiresInSeconds?: number;\n\t }\n\t| { type: \"progress\"; message: string };\n\n/**\n * Login interaction callbacks serving both api-key and OAuth flows.\n *\n * `prompt()` returns the entered/selected string (`select` returns the option\n * id). Rejects on cancel/abort. `signal` aborts the whole login flow;\n * per-prompt cancellation uses `AuthPrompt.signal`.\n */\nexport interface AuthInteraction {\n\tsignal?: AbortSignal;\n\n\tprompt(prompt: AuthPrompt): Promise<string>;\n\tnotify(event: AuthEvent): void;\n}\n\n/** Normalized interaction passed to provider login implementations. */\nexport type ProviderAuthInteraction = AuthInteraction & { signal: AbortSignal };\n\n/**\n * Api-key auth: stored key/provider env plus ambient sources (env vars, AWS\n * profiles, ADC files). Ambient-only providers omit `login`.\n */\nexport interface ApiKeyAuth {\n\t/** Display name, e.g. \"Anthropic API key\". */\n\tname: string;\n\n\t/** Interactive setup (prompt for key/provider env). Absent = ambient-only. */\n\tlogin?(interaction: ProviderAuthInteraction): Promise<ApiKeyCredential>;\n\n\t/**\n\t * Provider ids whose stored api-key credentials this provider reuses, in\n\t * precedence order. A borrowing provider has no stored credential of its\n\t * own; anything stored under its id is ignored. The first\n\t * listed provider with a stored api-key credential that has a key is passed\n\t * to `resolve()` as `credential`; stored OAuth credentials and key-less\n\t * api-key credentials are skipped. When none qualifies, `resolve()` runs\n\t * without a credential, so ambient sources (env vars) still apply. Pair with\n\t * an absent `login`.\n\t */\n\tborrowCredentialsFrom?: readonly string[];\n\n\t/**\n\t * Optional side-effect-free availability check. Use this when `resolve()` may\n\t * execute commands or perform other request-time work. Missing means Models\n\t * checks availability by resolving auth.\n\t */\n\tcheck?(input: {\n\t\tctx: AuthContext;\n\t\tcredential?: ApiKeyCredential;\n\t\tsignal: AbortSignal;\n\t}): Promise<AuthCheck | undefined>;\n\n\t/**\n\t * Resolve auth from the stored credential and/or ambient sources, merging\n\t * per field (`credential.key ?? env(\"...\")`, `credential.env?.NAME ?? env(\"...\")`).\n\t * undefined = not configured. Resolution is provider-scoped; model-specific\n\t * endpoint preparation happens after auth has been resolved.\n\t */\n\tresolve(input: {\n\t\tctx: AuthContext;\n\t\tcredential?: ApiKeyCredential;\n\t\tsignal: AbortSignal;\n\t}): Promise<AuthResult | undefined>;\n}\n\n/** App context supplied to provider login flows. */\nexport interface LoginOptions {\n\t/** Stable UUID for this installation, created lazily by the app. */\n\tgetDeviceId?: () => string;\n\t/** App name used for OpenAI's agent name hint and Codex browser login originator. */\n\tagentName?: string;\n}\n\n/**\n * OAuth auth. The `refresh`/`toAuth` split lets `Models` own the locked\n * refresh pattern: `refresh` produces a credential, `toAuth` derives request\n * auth from whatever credential ends up stored.\n */\nexport interface OAuthAuth {\n\t/** Display name, e.g. \"Anthropic (Claude Pro/Max)\". */\n\tname: string;\n\n\t/** Whether access through this auth method is backed by a provider subscription. */\n\tisSubscription?: boolean;\n\n\t/** Selector label for the OAuth login option, e.g. \"Sign in with SuperGrok or X Premium\". */\n\tloginLabel?: string;\n\n\tusesCallbackServer?: boolean;\n\n\tlogin(interaction: ProviderAuthInteraction, options?: LoginOptions): Promise<OAuthCredential>;\n\n\t/**\n\t * Exchange the refresh token. Network call; throws on failure\n\t * (invalid_grant etc.). `Models` runs this under the store lock.\n\t */\n\trefresh(credential: OAuthCredential, signal: AbortSignal): Promise<OAuthCredential>;\n\n\t/**\n\t * Side-effect-free derivation of request auth from a valid credential.\n\t * Covers per-credential baseUrl (GitHub Copilot). Async so lazy wrappers\n\t * can load the implementation on first use.\n\t */\n\ttoAuth(credential: OAuthCredential): Promise<ModelAuth>;\n}\n\n/**\n * Provider auth. At least one of `apiKey`/`oauth` must be present: even\n * ambient-credential providers and keyless local servers provide `apiKey`\n * auth whose `resolve()` reports whether the provider is configured.\n */\nexport interface ProviderAuth {\n\tapiKey?: ApiKeyAuth;\n\toauth?: OAuthAuth;\n}\n"]}
|
package/dist/models.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,KAAK,uBAAuB,
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,KAAK,uBAAuB,EAK5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACX,SAAS,EACT,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,UAAU,EACV,QAAQ,EACR,UAAU,EACV,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAuB,KAAK,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEjG,OAAO,KAAK,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AAgB,kBAAkB,CAAC,IAAI,SAAS,GAAG,EAClD,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,KAAK,EAAE,kBAAkB,GACvB,kBAAkB,CAgBpB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,QAAQ,GAAG,IAAI,GAAG,SAAS,EAAE,CAAC,EAAE,QAAQ,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAGtG"}
|
package/dist/models.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { lazyStream } from "./api/lazy.js";
|
|
2
2
|
import { defaultProviderAuthContext as defaultAuthContext } from "./auth/context.js";
|
|
3
3
|
import { InMemoryCredentialStore } from "./auth/credential-store.js";
|
|
4
|
-
import { ModelsError, refreshStoredOAuthCredential, resolveProviderAuth, } from "./auth/resolve.js";
|
|
4
|
+
import { ModelsError, readProviderCredential, refreshStoredOAuthCredential, resolveProviderAuth, } from "./auth/resolve.js";
|
|
5
5
|
import { InMemoryModelsStore } from "./models-store.js";
|
|
6
6
|
import { normalizeProviderId } from "./provider-id.js";
|
|
7
7
|
import { operationSignal, raceWithAbortSignal } from "./utils/abort.js";
|
|
@@ -214,7 +214,7 @@ class ModelsImpl {
|
|
|
214
214
|
let storedCredential;
|
|
215
215
|
let credentialError;
|
|
216
216
|
try {
|
|
217
|
-
storedCredential = await this.
|
|
217
|
+
storedCredential = await readProviderCredential(this.credentials, provider, signal);
|
|
218
218
|
}
|
|
219
219
|
catch (error) {
|
|
220
220
|
credentialError = error;
|
|
@@ -275,16 +275,6 @@ class ModelsImpl {
|
|
|
275
275
|
return undefined;
|
|
276
276
|
return { type: "api_key", key: result.auth.apiKey, env: result.env };
|
|
277
277
|
}
|
|
278
|
-
async readCredential(providerId, signal) {
|
|
279
|
-
try {
|
|
280
|
-
const credential = await this.credentials.read(providerId, { signal });
|
|
281
|
-
return (credential ??
|
|
282
|
-
(providerId === "azure" ? await this.credentials.read("azure-openai-responses", { signal }) : undefined));
|
|
283
|
-
}
|
|
284
|
-
catch (error) {
|
|
285
|
-
throw new ModelsError("auth", `Credential store read failed for ${providerId}`, { cause: error });
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
278
|
async checkProviderAuth(provider, credential, signal) {
|
|
289
279
|
if (credential?.type === "oauth") {
|
|
290
280
|
return provider.auth.oauth ? { source: "OAuth", type: "oauth" } : undefined;
|
|
@@ -315,7 +305,7 @@ class ModelsImpl {
|
|
|
315
305
|
const provider = this.providers.get(providerId);
|
|
316
306
|
if (!provider)
|
|
317
307
|
return undefined;
|
|
318
|
-
return this.checkProviderAuth(provider, await this.
|
|
308
|
+
return this.checkProviderAuth(provider, await readProviderCredential(this.credentials, provider, signal), signal);
|
|
319
309
|
})();
|
|
320
310
|
return raceWithAbortSignal(check, signal);
|
|
321
311
|
}
|
|
@@ -325,7 +315,7 @@ class ModelsImpl {
|
|
|
325
315
|
? [this.getProvider(providerId)].filter((entry) => entry !== undefined)
|
|
326
316
|
: this.getProviders();
|
|
327
317
|
const checks = await Promise.all(providers.map(async (provider) => {
|
|
328
|
-
const credential = await this.
|
|
318
|
+
const credential = await readProviderCredential(this.credentials, provider, signal);
|
|
329
319
|
return { provider, credential, auth: await this.checkProviderAuth(provider, credential, signal) };
|
|
330
320
|
}));
|
|
331
321
|
return checks.filter((entry) => entry.auth !== undefined);
|