@ap3x/ai 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +28 -0
- package/dist/api-registry.d.ts +23 -0
- package/dist/api-registry.d.ts.map +1 -0
- package/dist/auth/config-dir.d.ts +25 -0
- package/dist/auth/config-dir.d.ts.map +1 -0
- package/dist/auth/github-copilot.d.ts +74 -0
- package/dist/auth/github-copilot.d.ts.map +1 -0
- package/dist/auth/index.d.ts +10 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/jwt.d.ts +32 -0
- package/dist/auth/jwt.d.ts.map +1 -0
- package/dist/auth/oauth-flow.d.ts +84 -0
- package/dist/auth/oauth-flow.d.ts.map +1 -0
- package/dist/auth/pkce.d.ts +20 -0
- package/dist/auth/pkce.d.ts.map +1 -0
- package/dist/auth/providers.d.ts +33 -0
- package/dist/auth/providers.d.ts.map +1 -0
- package/dist/auth/storage.d.ts +55 -0
- package/dist/auth/storage.d.ts.map +1 -0
- package/dist/auth/types.d.ts +88 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/unified.d.ts +29 -0
- package/dist/auth/unified.d.ts.map +1 -0
- package/dist/env-api-keys.d.ts +16 -0
- package/dist/env-api-keys.d.ts.map +1 -0
- package/dist/event-stream.d.ts +33 -0
- package/dist/event-stream.d.ts.map +1 -0
- package/dist/generate-object.d.ts +63 -0
- package/dist/generate-object.d.ts.map +1 -0
- package/dist/images-models.d.ts +114 -0
- package/dist/images-models.d.ts.map +1 -0
- package/dist/images-registry.d.ts +23 -0
- package/dist/images-registry.d.ts.map +1 -0
- package/dist/images-schema.d.ts +21 -0
- package/dist/images-schema.d.ts.map +1 -0
- package/dist/images.d.ts +13 -0
- package/dist/images.d.ts.map +1 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15656 -0
- package/dist/models/amazon-bedrock.models.generated.d.ts +1858 -0
- package/dist/models/amazon-bedrock.models.generated.d.ts.map +1 -0
- package/dist/models/ant-ling.models.generated.d.ts +86 -0
- package/dist/models/ant-ling.models.generated.d.ts.map +1 -0
- package/dist/models/anthropic.models.generated.d.ts +450 -0
- package/dist/models/anthropic.models.generated.d.ts.map +1 -0
- package/dist/models/azure-openai-responses.models.generated.d.ts +804 -0
- package/dist/models/azure-openai-responses.models.generated.d.ts.map +1 -0
- package/dist/models/cerebras.models.generated.d.ts +66 -0
- package/dist/models/cerebras.models.generated.d.ts.map +1 -0
- package/dist/models/cloudflare-ai-gateway.models.generated.d.ts +786 -0
- package/dist/models/cloudflare-ai-gateway.models.generated.d.ts.map +1 -0
- package/dist/models/cloudflare-workers-ai.models.generated.d.ts +302 -0
- package/dist/models/cloudflare-workers-ai.models.generated.d.ts.map +1 -0
- package/dist/models/deepseek.models.generated.d.ts +63 -0
- package/dist/models/deepseek.models.generated.d.ts.map +1 -0
- package/dist/models/fireworks.models.generated.d.ts +381 -0
- package/dist/models/fireworks.models.generated.d.ts.map +1 -0
- package/dist/models/github-copilot.models.generated.d.ts +698 -0
- package/dist/models/github-copilot.models.generated.d.ts.map +1 -0
- package/dist/models/google-vertex.models.generated.d.ts +202 -0
- package/dist/models/google-vertex.models.generated.d.ts.map +1 -0
- package/dist/models/google.models.generated.d.ts +351 -0
- package/dist/models/google.models.generated.d.ts.map +1 -0
- package/dist/models/groq.models.generated.d.ts +128 -0
- package/dist/models/groq.models.generated.d.ts.map +1 -0
- package/dist/models/huggingface.models.generated.d.ts +63 -0
- package/dist/models/huggingface.models.generated.d.ts.map +1 -0
- package/dist/models/kimi-coding.models.generated.d.ts +63 -0
- package/dist/models/kimi-coding.models.generated.d.ts.map +1 -0
- package/dist/models/minimax-cn.models.generated.d.ts +54 -0
- package/dist/models/minimax-cn.models.generated.d.ts.map +1 -0
- package/dist/models/minimax.models.generated.d.ts +54 -0
- package/dist/models/minimax.models.generated.d.ts.map +1 -0
- package/dist/models/mistral.models.generated.d.ts +513 -0
- package/dist/models/mistral.models.generated.d.ts.map +1 -0
- package/dist/models/moonshotai-cn.models.generated.d.ts +234 -0
- package/dist/models/moonshotai-cn.models.generated.d.ts.map +1 -0
- package/dist/models/moonshotai.models.generated.d.ts +234 -0
- package/dist/models/moonshotai.models.generated.d.ts.map +1 -0
- package/dist/models/nvidia.models.generated.d.ts +563 -0
- package/dist/models/nvidia.models.generated.d.ts.map +1 -0
- package/dist/models/openai.models.generated.d.ts +827 -0
- package/dist/models/openai.models.generated.d.ts.map +1 -0
- package/dist/models/opencode.models.generated.d.ts +69 -0
- package/dist/models/opencode.models.generated.d.ts.map +1 -0
- package/dist/models/openrouter.models.generated.d.ts +87 -0
- package/dist/models/openrouter.models.generated.d.ts.map +1 -0
- package/dist/models/together.models.generated.d.ts +598 -0
- package/dist/models/together.models.generated.d.ts.map +1 -0
- package/dist/models/vercel-ai-gateway.models.generated.d.ts +63 -0
- package/dist/models/vercel-ai-gateway.models.generated.d.ts.map +1 -0
- package/dist/models/xai.models.generated.d.ts +157 -0
- package/dist/models/xai.models.generated.d.ts.map +1 -0
- package/dist/models/xiaomi-token-plan-ams.models.generated.d.ts +108 -0
- package/dist/models/xiaomi-token-plan-ams.models.generated.d.ts.map +1 -0
- package/dist/models/xiaomi-token-plan-cn.models.generated.d.ts +108 -0
- package/dist/models/xiaomi-token-plan-cn.models.generated.d.ts.map +1 -0
- package/dist/models/xiaomi-token-plan-sgp.models.generated.d.ts +108 -0
- package/dist/models/xiaomi-token-plan-sgp.models.generated.d.ts.map +1 -0
- package/dist/models/xiaomi.models.generated.d.ts +129 -0
- package/dist/models/xiaomi.models.generated.d.ts.map +1 -0
- package/dist/models/zai-coding-cn.models.generated.d.ts +153 -0
- package/dist/models/zai-coding-cn.models.generated.d.ts.map +1 -0
- package/dist/models/zai.models.generated.d.ts +153 -0
- package/dist/models/zai.models.generated.d.ts.map +1 -0
- package/dist/models.d.ts +10734 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock.d.ts +173 -0
- package/dist/providers/amazon-bedrock.d.ts.map +1 -0
- package/dist/providers/anthropic.d.ts +25 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/azure-openai-responses.d.ts +17 -0
- package/dist/providers/azure-openai-responses.d.ts.map +1 -0
- package/dist/providers/cloudflare.d.ts +13 -0
- package/dist/providers/cloudflare.d.ts.map +1 -0
- package/dist/providers/faux-images.d.ts +41 -0
- package/dist/providers/faux-images.d.ts.map +1 -0
- package/dist/providers/faux.d.ts +61 -0
- package/dist/providers/faux.d.ts.map +1 -0
- package/dist/providers/github-copilot-headers.d.ts +14 -0
- package/dist/providers/github-copilot-headers.d.ts.map +1 -0
- package/dist/providers/google-images.d.ts +14 -0
- package/dist/providers/google-images.d.ts.map +1 -0
- package/dist/providers/google-shared.d.ts +53 -0
- package/dist/providers/google-shared.d.ts.map +1 -0
- package/dist/providers/google-vertex.d.ts +48 -0
- package/dist/providers/google-vertex.d.ts.map +1 -0
- package/dist/providers/google.d.ts +47 -0
- package/dist/providers/google.d.ts.map +1 -0
- package/dist/providers/mistral.d.ts +67 -0
- package/dist/providers/mistral.d.ts.map +1 -0
- package/dist/providers/openai-codex-responses.d.ts +17 -0
- package/dist/providers/openai-codex-responses.d.ts.map +1 -0
- package/dist/providers/openai-completions.d.ts +69 -0
- package/dist/providers/openai-completions.d.ts.map +1 -0
- package/dist/providers/openai-images.d.ts +17 -0
- package/dist/providers/openai-images.d.ts.map +1 -0
- package/dist/providers/openai-prompt-cache.d.ts +8 -0
- package/dist/providers/openai-prompt-cache.d.ts.map +1 -0
- package/dist/providers/openai-responses-shared.d.ts +128 -0
- package/dist/providers/openai-responses-shared.d.ts.map +1 -0
- package/dist/providers/openai-responses.d.ts +63 -0
- package/dist/providers/openai-responses.d.ts.map +1 -0
- package/dist/providers/provider-runtime.d.ts +34 -0
- package/dist/providers/provider-runtime.d.ts.map +1 -0
- package/dist/providers/register-builtins.d.ts +11 -0
- package/dist/providers/register-builtins.d.ts.map +1 -0
- package/dist/providers/register-images.d.ts +8 -0
- package/dist/providers/register-images.d.ts.map +1 -0
- package/dist/providers/request-dispatch.d.ts +52 -0
- package/dist/providers/request-dispatch.d.ts.map +1 -0
- package/dist/providers/simple-options.d.ts +42 -0
- package/dist/providers/simple-options.d.ts.map +1 -0
- package/dist/providers/tool-call-id.d.ts +46 -0
- package/dist/providers/tool-call-id.d.ts.map +1 -0
- package/dist/providers/transform-messages.d.ts +22 -0
- package/dist/providers/transform-messages.d.ts.map +1 -0
- package/dist/stream.d.ts +18 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/types.d.ts +448 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/abort-signals.d.ts +16 -0
- package/dist/utils/abort-signals.d.ts.map +1 -0
- package/dist/utils/estimate.d.ts +35 -0
- package/dist/utils/estimate.d.ts.map +1 -0
- package/dist/utils/hash.d.ts +7 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/json-parse.d.ts +16 -0
- package/dist/utils/json-parse.d.ts.map +1 -0
- package/dist/utils/node-http-proxy.d.ts +34 -0
- package/dist/utils/node-http-proxy.d.ts.map +1 -0
- package/dist/utils/overflow.d.ts +25 -0
- package/dist/utils/overflow.d.ts.map +1 -0
- package/dist/utils/sanitize-unicode.d.ts +9 -0
- package/dist/utils/sanitize-unicode.d.ts.map +1 -0
- package/dist/utils/sse.d.ts +21 -0
- package/dist/utils/sse.d.ts.map +1 -0
- package/dist/validation.d.ts +31 -0
- package/dist/validation.d.ts.map +1 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AP3X
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @ap3x/ai
|
|
2
|
+
|
|
3
|
+
One typed interface over many LLM providers: streaming, tool calling, and a shared model catalog, so provider choice stays a config value rather than a rewrite.
|
|
4
|
+
|
|
5
|
+
Part of [AP3X](https://github.com/AP3X-Dev/AP3X) — a TypeScript multi-agent framework.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @ap3x/ai
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## What's inside
|
|
14
|
+
|
|
15
|
+
- **Providers** — OpenAI (completions + responses), Anthropic, Google, Amazon Bedrock, Azure OpenAI, GitHub Copilot, OpenRouter, Vercel AI Gateway, Mistral, and more.
|
|
16
|
+
- **Streaming** — incremental text and tool-call deltas with partial-JSON recovery.
|
|
17
|
+
- **Tool calling** — TypeBox schemas in, validated and coerced arguments out, with provider-specific tool-call id rules handled in one place.
|
|
18
|
+
- **Auth** — API keys from the environment, plus OAuth device/browser flows for subscription backends.
|
|
19
|
+
- **Model catalog** — `MODELS` / `getModel` with generated per-provider catalogs and a runtime refresh seam.
|
|
20
|
+
- **Transport** — retry, timeout, and proxy handling shared across providers.
|
|
21
|
+
|
|
22
|
+
## Documentation
|
|
23
|
+
|
|
24
|
+
See the [AP3X repository](https://github.com/AP3X-Dev/AP3X) for architecture notes, the full package map, and examples.
|
|
25
|
+
|
|
26
|
+
## License
|
|
27
|
+
|
|
28
|
+
MIT
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Api, ApiProvider, AssistantMessageEventStream, Context, Model, SimpleStreamOptions, StreamOptions } from "./types";
|
|
2
|
+
export type { ApiProvider } from "./types";
|
|
3
|
+
/** Non-generic full-stream signature stored in the registry. */
|
|
4
|
+
export type ApiStreamFunction = (model: Model<Api>, context: Context, options?: StreamOptions) => AssistantMessageEventStream;
|
|
5
|
+
/** Non-generic simple-stream signature stored in the registry. */
|
|
6
|
+
export type ApiStreamSimpleFunction = (model: Model<Api>, context: Context, options?: SimpleStreamOptions) => AssistantMessageEventStream;
|
|
7
|
+
export interface ApiProviderInternal {
|
|
8
|
+
api: Api;
|
|
9
|
+
stream: ApiStreamFunction;
|
|
10
|
+
streamSimple: ApiStreamSimpleFunction;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Register a provider under its `api` id. Stored functions are wrapped with an
|
|
14
|
+
* api-mismatch guard. An optional `sourceId` tags the registration so a batch
|
|
15
|
+
* of registrations can later be removed together.
|
|
16
|
+
*/
|
|
17
|
+
export declare function registerApiProvider<TApi extends Api, TOptions extends StreamOptions>(provider: ApiProvider<TApi, TOptions>, sourceId?: string): void;
|
|
18
|
+
export declare function getApiProvider(api: Api): ApiProviderInternal | undefined;
|
|
19
|
+
export declare function getApiProviders(): ApiProviderInternal[];
|
|
20
|
+
/** Remove every provider tagged with the given `sourceId`. */
|
|
21
|
+
export declare function unregisterApiProviders(sourceId: string): void;
|
|
22
|
+
export declare function clearApiProviders(): void;
|
|
23
|
+
//# sourceMappingURL=api-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-registry.d.ts","sourceRoot":"","sources":["../src/api-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,GAAG,EACH,WAAW,EACX,2BAA2B,EAC3B,OAAO,EACP,KAAK,EACL,mBAAmB,EAEnB,aAAa,EACd,MAAM,SAAS,CAAC;AAEjB,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,gEAAgE;AAChE,MAAM,MAAM,iBAAiB,GAAG,CAC9B,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EACjB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,aAAa,KACpB,2BAA2B,CAAC;AAEjC,kEAAkE;AAClE,MAAM,MAAM,uBAAuB,GAAG,CACpC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EACjB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,mBAAmB,KAC1B,2BAA2B,CAAC;AAEjC,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,GAAG,CAAC;IACT,MAAM,EAAE,iBAAiB,CAAC;IAC1B,YAAY,EAAE,uBAAuB,CAAC;CACvC;AAmCD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,SAAS,GAAG,EAAE,QAAQ,SAAS,aAAa,EAClF,QAAQ,EAAE,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,EACrC,QAAQ,CAAC,EAAE,MAAM,GAChB,IAAI,CASN;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,mBAAmB,GAAG,SAAS,CAExE;AAED,wBAAgB,eAAe,IAAI,mBAAmB,EAAE,CAEvD;AAED,8DAA8D;AAC9D,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAM7D;AAED,wBAAgB,iBAAiB,IAAI,IAAI,CAExC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the AP3X config directory. Precedence: the `AP3X_CONFIG_DIR` env
|
|
3
|
+
* override, then `~/.ap3x`. Node builtins are imported lazily so browser/bundler
|
|
4
|
+
* builds don't pull them in unless the resolver is actually called.
|
|
5
|
+
*/
|
|
6
|
+
/** Synchronous node-fs accessor. Throws when builtins haven't been loaded yet. */
|
|
7
|
+
declare function nodeFs(): {
|
|
8
|
+
mkdirSync: typeof import("node:fs").mkdirSync;
|
|
9
|
+
readFileSync: typeof import("node:fs").readFileSync;
|
|
10
|
+
writeFileSync: typeof import("node:fs").writeFileSync;
|
|
11
|
+
renameSync: typeof import("node:fs").renameSync;
|
|
12
|
+
rmSync: typeof import("node:fs").rmSync;
|
|
13
|
+
existsSync: typeof import("node:fs").existsSync;
|
|
14
|
+
};
|
|
15
|
+
/** Load the node builtins the auth layer needs. Safe to call repeatedly. */
|
|
16
|
+
export declare function ensureNodeBuiltins(): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Resolve the AP3X config directory path. `AP3X_CONFIG_DIR` overrides the
|
|
19
|
+
* default `~/.ap3x`. Requires {@link ensureNodeBuiltins} to have run.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveConfigDir(): string;
|
|
22
|
+
/** Join a path segment under the resolved config dir. */
|
|
23
|
+
export declare function configPath(...segments: string[]): string;
|
|
24
|
+
export { nodeFs };
|
|
25
|
+
//# sourceMappingURL=config-dir.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-dir.d.ts","sourceRoot":"","sources":["../../src/auth/config-dir.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAgCH,kFAAkF;AAClF,iBAAS,MAAM,IAAI;IACjB,SAAS,EAAE,cAAc,SAAS,EAAE,SAAS,CAAC;IAC9C,YAAY,EAAE,cAAc,SAAS,EAAE,YAAY,CAAC;IACpD,aAAa,EAAE,cAAc,SAAS,EAAE,aAAa,CAAC;IACtD,UAAU,EAAE,cAAc,SAAS,EAAE,UAAU,CAAC;IAChD,MAAM,EAAE,cAAc,SAAS,EAAE,MAAM,CAAC;IACxC,UAAU,EAAE,cAAc,SAAS,EAAE,UAAU,CAAC;CACjD,CAmBA;AAED,4EAA4E;AAC5E,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAGxD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAOzC;AAED,yDAAyD;AACzD,wBAAgB,UAAU,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAGxD;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { AuthStorage } from "./storage";
|
|
2
|
+
import type { FetchLike, OAuthProviderConfig, OAuthToken, ResolvedAuth } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* The client-identity headers the Copilot service expects on both the token
|
|
5
|
+
* exchange and every subsequent API call. They advertise a Copilot-enabled
|
|
6
|
+
* editor/plugin and a registered integration id — vendor protocol constants.
|
|
7
|
+
*/
|
|
8
|
+
export declare const COPILOT_EDITOR_HEADERS: Record<string, string>;
|
|
9
|
+
/** The API version pin Copilot expects via `X-GitHub-Api-Version`. */
|
|
10
|
+
export declare const COPILOT_API_VERSION = "2026-06-01";
|
|
11
|
+
/**
|
|
12
|
+
* Full static header set for an authenticated Copilot API request: the bearer
|
|
13
|
+
* plus the editor-identity headers and the API-version pin.
|
|
14
|
+
*/
|
|
15
|
+
export declare function copilotApiHeaders(copilotBearer: string): Record<string, string>;
|
|
16
|
+
/**
|
|
17
|
+
* The Copilot token-exchange endpoint for a GitHub domain. For the default
|
|
18
|
+
* `github.com` this is `https://api.github.com/copilot_internal/v2/token`; an
|
|
19
|
+
* enterprise domain (e.g. `acme.ghe.com`) resolves to its `api.` host.
|
|
20
|
+
*/
|
|
21
|
+
export declare function copilotTokenEndpoint(enterpriseDomain?: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Derive the Copilot API base URL embedded in a minted bearer. The bearer is a
|
|
24
|
+
* `;`-delimited list of `key=value` pairs; `proxy-ep` names the proxy host
|
|
25
|
+
* (e.g. `proxy.individual.githubcopilot.com`), whose `api.` sibling is the base
|
|
26
|
+
* URL. Returns `null` when the token carries no `proxy-ep`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getCopilotBaseUrlFromToken(token: string): string | null;
|
|
29
|
+
/**
|
|
30
|
+
* Resolve the Copilot API base URL, preferring the endpoint encoded in the
|
|
31
|
+
* bearer, then an enterprise host, then the individual-account default.
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolveCopilotBaseUrl(bearer?: string, enterpriseDomain?: string): string;
|
|
34
|
+
/** Result of the GitHub -> Copilot token exchange. */
|
|
35
|
+
export interface CopilotTokenExchange {
|
|
36
|
+
/** The short-lived Copilot API bearer. */
|
|
37
|
+
token: string;
|
|
38
|
+
/** Epoch milliseconds at which the bearer expires. */
|
|
39
|
+
expiresAt: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Exchange a durable GitHub OAuth token for a short-lived Copilot API bearer.
|
|
43
|
+
* GitHub authenticates the request with the GitHub token as a Bearer and
|
|
44
|
+
* returns `{ token, expires_at }` (expiry in epoch seconds).
|
|
45
|
+
*/
|
|
46
|
+
export declare function exchangeGitHubCopilotToken(githubToken: string, options?: {
|
|
47
|
+
fetchImpl?: FetchLike;
|
|
48
|
+
enterpriseDomain?: string;
|
|
49
|
+
signal?: AbortSignal;
|
|
50
|
+
}): Promise<CopilotTokenExchange>;
|
|
51
|
+
export interface ResolveCopilotAuthOptions {
|
|
52
|
+
/** Storage used to cache the minted Copilot bearer to its expiry. */
|
|
53
|
+
storage: AuthStorage;
|
|
54
|
+
/** Provider OAuth config supplying the refresh-skew window. */
|
|
55
|
+
config: Pick<OAuthProviderConfig, "refreshSkewSeconds">;
|
|
56
|
+
/** Clock, injectable for tests. */
|
|
57
|
+
now: () => number;
|
|
58
|
+
/** Injectable fetch for the token exchange (no real network in tests). */
|
|
59
|
+
fetchImpl?: FetchLike;
|
|
60
|
+
/** Optional enterprise domain the account is homed on. */
|
|
61
|
+
enterpriseDomain?: string;
|
|
62
|
+
signal?: AbortSignal;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Resolve usable Copilot auth from a stored GitHub Copilot credential: mint (or
|
|
66
|
+
* reuse a cached) Copilot bearer, then return the bearer plus the required
|
|
67
|
+
* client headers and the per-account base URL.
|
|
68
|
+
*
|
|
69
|
+
* The minted bearer is cached back to `storage` keyed to the provider, with the
|
|
70
|
+
* GitHub token preserved in `refreshToken`, so a second resolution within the
|
|
71
|
+
* bearer's lifetime reuses it instead of re-exchanging.
|
|
72
|
+
*/
|
|
73
|
+
export declare function resolveGitHubCopilotAuth(stored: OAuthToken, options: ResolveCopilotAuthOptions): Promise<ResolvedAuth>;
|
|
74
|
+
//# sourceMappingURL=github-copilot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-copilot.d.ts","sourceRoot":"","sources":["../../src/auth/github-copilot.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAiBxF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAKzD,CAAC;AAEF,sEAAsE;AACtE,eAAO,MAAM,mBAAmB,eAAe,CAAC;AAKhD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAM/E;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,CAGtE;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAOvE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,CAQxF;AAED,sDAAsD;AACtD,MAAM,WAAW,oBAAoB;IACnC,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;CACnB;AAWD;;;;GAIG;AACH,wBAAsB,0BAA0B,CAC9C,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE;IACP,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,WAAW,CAAC;CACjB,GACL,OAAO,CAAC,oBAAoB,CAAC,CA8B/B;AA6BD,MAAM,WAAW,yBAAyB;IACxC,qEAAqE;IACrE,OAAO,EAAE,WAAW,CAAC;IACrB,+DAA+D;IAC/D,MAAM,EAAE,IAAI,CAAC,mBAAmB,EAAE,oBAAoB,CAAC,CAAC;IACxD,mCAAmC;IACnC,GAAG,EAAE,MAAM,MAAM,CAAC;IAClB,0EAA0E;IAC1E,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,0DAA0D;IAC1D,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;;;;;GAQG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,YAAY,CAAC,CA4BvB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { configPath, ensureNodeBuiltins, resolveConfigDir } from "./config-dir";
|
|
2
|
+
export { base64UrlEncode, deriveCodeChallenge, generateCodeVerifier, generatePkcePair, generateState, type PkcePair, } from "./pkce";
|
|
3
|
+
export { decodeJwtPayload, extractChatgptAccountId, resolveChatgptAccountId } from "./jwt";
|
|
4
|
+
export { AuthStorage } from "./storage";
|
|
5
|
+
export { clientIdEnvVar, getOAuthProviderConfig, hasOAuthConfig, isPlaceholderClientId, type OAuthProviderConfigOverrides, oauthProviders, } from "./providers";
|
|
6
|
+
export { type AuthorizeUrlResult, buildAuthorizationUrl, type DevicePollOptions, exchangeAuthorizationCode, isTokenExpired, parseAuthorizationInput, pollDeviceToken, refreshAccessToken, startDeviceAuthorization, } from "./oauth-flow";
|
|
7
|
+
export { COPILOT_API_VERSION, COPILOT_EDITOR_HEADERS, copilotApiHeaders, copilotTokenEndpoint, type CopilotTokenExchange, exchangeGitHubCopilotToken, getCopilotBaseUrlFromToken, type ResolveCopilotAuthOptions, resolveCopilotBaseUrl, resolveGitHubCopilotAuth, } from "./github-copilot";
|
|
8
|
+
export { getApiKeyAndHeaders, type ResolveAuthOptions } from "./unified";
|
|
9
|
+
export type { FetchLike, OAuthGrantType, OAuthProviderConfig, OAuthToken, ResolvedAuth, } from "./types";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGhF,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EAChB,aAAa,EACb,KAAK,QAAQ,GACd,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,OAAO,CAAC;AAG3F,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGxC,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,cAAc,EACd,qBAAqB,EACrB,KAAK,4BAA4B,EACjC,cAAc,GACf,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,KAAK,kBAAkB,EACvB,qBAAqB,EACrB,KAAK,iBAAiB,EACtB,yBAAyB,EACzB,cAAc,EACd,uBAAuB,EACvB,eAAe,EACf,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EACjB,oBAAoB,EACpB,KAAK,oBAAoB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,KAAK,yBAAyB,EAC9B,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,mBAAmB,EAAE,KAAK,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAGzE,YAAY,EACV,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,UAAU,EACV,YAAY,GACb,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal JWT payload decoding for OAuth id_tokens.
|
|
3
|
+
*
|
|
4
|
+
* NO signature verification is performed: the id_token is received directly from
|
|
5
|
+
* the provider's token endpoint over TLS, so its authenticity is already
|
|
6
|
+
* established by the transport. We only need to read claims out of the payload.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Decode a JWT's payload (the middle, dot-delimited segment) into a plain
|
|
10
|
+
* object. Total function: returns `undefined` on any malformed input rather than
|
|
11
|
+
* throwing.
|
|
12
|
+
*/
|
|
13
|
+
export declare function decodeJwtPayload(jwt: string): Record<string, unknown> | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Extract the ChatGPT account id from an OIDC id_token. The canonical location
|
|
16
|
+
* is the namespaced auth claim `"https://api.openai.com/auth".chatgpt_account_id`;
|
|
17
|
+
* fall back to a top-level `chatgpt_account_id`, then `account_id`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function extractChatgptAccountId(idToken: string): string | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the ChatGPT account id from a token set, preferring the ACCESS token —
|
|
22
|
+
* the Codex access token is itself a JWT carrying the `chatgpt_account_id` auth
|
|
23
|
+
* claim — and only then falling back to the id_token. Reading solely the
|
|
24
|
+
* id_token silently drops the required `chatgpt-account-id` header whenever the
|
|
25
|
+
* provider returns the claim on the access token but omits the id_token (e.g. on
|
|
26
|
+
* refresh). Returns `undefined` only when neither token carries the id.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveChatgptAccountId(tokens: {
|
|
29
|
+
accessToken?: string;
|
|
30
|
+
idToken?: string;
|
|
31
|
+
}): string | undefined;
|
|
32
|
+
//# sourceMappingURL=jwt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../src/auth/jwt.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAaH;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAejF;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAiB3E;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,MAAM,GAAG,SAAS,CAUrB"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type PkcePair } from "./pkce";
|
|
2
|
+
import type { FetchLike, OAuthProviderConfig, OAuthToken } from "./types";
|
|
3
|
+
/** Device-authorization response shape. */
|
|
4
|
+
interface DeviceCodeResponse {
|
|
5
|
+
device_code: string;
|
|
6
|
+
user_code: string;
|
|
7
|
+
verification_uri: string;
|
|
8
|
+
verification_uri_complete?: string;
|
|
9
|
+
expires_in: number;
|
|
10
|
+
interval?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface AuthorizeUrlResult {
|
|
13
|
+
url: string;
|
|
14
|
+
pkce: PkcePair;
|
|
15
|
+
state: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Build the authorization URL for the authorization-code + PKCE flow, returning
|
|
19
|
+
* the URL plus the PKCE pair and `state` the caller must retain to complete the
|
|
20
|
+
* exchange.
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildAuthorizationUrl(config: OAuthProviderConfig): AuthorizeUrlResult;
|
|
23
|
+
/**
|
|
24
|
+
* Parse a manually pasted OAuth authorization value into a `{ code, state }`
|
|
25
|
+
* pair. Accepts a full redirect URL, a bare code, a `code#state` fragment, or a
|
|
26
|
+
* `code=...&state=...` query fragment — the remote-browser paste fallback used
|
|
27
|
+
* when a loopback callback cannot be reached (headless / remote sign-in). Total
|
|
28
|
+
* function: an empty/whitespace input yields `{}`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseAuthorizationInput(input: string): {
|
|
31
|
+
code?: string;
|
|
32
|
+
state?: string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Exchange an authorization code (with the matching PKCE verifier) for a token
|
|
36
|
+
* set at the provider's token endpoint.
|
|
37
|
+
*/
|
|
38
|
+
export declare function exchangeAuthorizationCode(config: OAuthProviderConfig, params: {
|
|
39
|
+
code: string;
|
|
40
|
+
verifier: string;
|
|
41
|
+
}, options?: {
|
|
42
|
+
fetchImpl?: FetchLike;
|
|
43
|
+
now?: () => number;
|
|
44
|
+
signal?: AbortSignal;
|
|
45
|
+
}): Promise<OAuthToken>;
|
|
46
|
+
/** Begin a device-authorization flow; returns the device + user codes. */
|
|
47
|
+
export declare function startDeviceAuthorization(config: OAuthProviderConfig, options?: {
|
|
48
|
+
fetchImpl?: FetchLike;
|
|
49
|
+
signal?: AbortSignal;
|
|
50
|
+
}): Promise<DeviceCodeResponse>;
|
|
51
|
+
export interface DevicePollOptions {
|
|
52
|
+
fetchImpl?: FetchLike;
|
|
53
|
+
now?: () => number;
|
|
54
|
+
signal?: AbortSignal;
|
|
55
|
+
/** Sleep helper (ms). Default: setTimeout. Injectable for tests. */
|
|
56
|
+
sleep?: (ms: number) => Promise<void>;
|
|
57
|
+
/** Override the poll interval (seconds). Defaults to device response value. */
|
|
58
|
+
intervalSeconds?: number;
|
|
59
|
+
/** Optional callback fired before each poll attempt. */
|
|
60
|
+
onPoll?: (attempt: number) => void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Poll the token endpoint for a device-code grant until it resolves, the user
|
|
64
|
+
* denies, or it expires. Honors `authorization_pending` (keep polling),
|
|
65
|
+
* `slow_down` (back off), and terminal errors.
|
|
66
|
+
*/
|
|
67
|
+
export declare function pollDeviceToken(config: OAuthProviderConfig, device: DeviceCodeResponse, options?: DevicePollOptions): Promise<OAuthToken>;
|
|
68
|
+
/**
|
|
69
|
+
* Exchange a refresh token for a new access token at the token endpoint.
|
|
70
|
+
*
|
|
71
|
+
* `previous` lets the caller carry forward identity fields (refresh token,
|
|
72
|
+
* account id, id_token) that a refresh response commonly omits, so a refreshed
|
|
73
|
+
* token stays fully usable.
|
|
74
|
+
*/
|
|
75
|
+
export declare function refreshAccessToken(config: OAuthProviderConfig, refreshToken: string, options?: {
|
|
76
|
+
fetchImpl?: FetchLike;
|
|
77
|
+
now?: () => number;
|
|
78
|
+
signal?: AbortSignal;
|
|
79
|
+
previous?: Pick<OAuthToken, "accountId" | "idToken">;
|
|
80
|
+
}): Promise<OAuthToken>;
|
|
81
|
+
/** Whether a token is expired or within the configured refresh skew window. */
|
|
82
|
+
export declare function isTokenExpired(token: OAuthToken, config: Pick<OAuthProviderConfig, "refreshSkewSeconds">, now?: number): boolean;
|
|
83
|
+
export {};
|
|
84
|
+
//# sourceMappingURL=oauth-flow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-flow.d.ts","sourceRoot":"","sources":["../../src/auth/oauth-flow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAmC,MAAM,QAAQ,CAAC;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAoB1E,2CAA2C;AAC3C,UAAU,kBAAkB;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AA6ED,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,mBAAmB,GAAG,kBAAkB,CAkBrF;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CA4BxF;AAED;;;GAGG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,mBAAmB,EAC3B,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,EAC1C,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,SAAS,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,GAChF,OAAO,CAAC,UAAU,CAAC,CAiBrB;AAED,0EAA0E;AAC1E,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,mBAAmB,EAC3B,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,SAAS,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,GAC5D,OAAO,CAAC,kBAAkB,CAAC,CAY7B;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,oEAAoE;IACpE,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,+EAA+E;IAC/E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,wDAAwD;IACxD,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAWD;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,mBAAmB,EAC3B,MAAM,EAAE,kBAAkB,EAC1B,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,UAAU,CAAC,CAwErB;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,mBAAmB,EAC3B,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE;IACP,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,QAAQ,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,WAAW,GAAG,SAAS,CAAC,CAAC;CACjD,GACL,OAAO,CAAC,UAAU,CAAC,CAqBrB;AAED,+EAA+E;AAC/E,wBAAgB,cAAc,CAC5B,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,IAAI,CAAC,mBAAmB,EAAE,oBAAoB,CAAC,EACvD,GAAG,GAAE,MAAmB,GACvB,OAAO,CAIT"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** A PKCE code_verifier / code_challenge pair (S256). */
|
|
2
|
+
export interface PkcePair {
|
|
3
|
+
verifier: string;
|
|
4
|
+
challenge: string;
|
|
5
|
+
method: "S256";
|
|
6
|
+
}
|
|
7
|
+
/** RFC 7636 base64url: base64 with `+/` → `-_` and no `=` padding. */
|
|
8
|
+
export declare function base64UrlEncode(bytes: Buffer): string;
|
|
9
|
+
/**
|
|
10
|
+
* Generate a PKCE code_verifier: a high-entropy, URL-safe string. RFC 7636
|
|
11
|
+
* requires 43–128 chars; 32 random bytes base64url-encoded yields 43 chars.
|
|
12
|
+
*/
|
|
13
|
+
export declare function generateCodeVerifier(byteLength?: number): string;
|
|
14
|
+
/** Derive the S256 code_challenge from a verifier: base64url(SHA-256(verifier)). */
|
|
15
|
+
export declare function deriveCodeChallenge(verifier: string): string;
|
|
16
|
+
/** Generate a complete S256 PKCE pair. */
|
|
17
|
+
export declare function generatePkcePair(byteLength?: number): PkcePair;
|
|
18
|
+
/** Generate an opaque, URL-safe `state` value for CSRF protection. */
|
|
19
|
+
export declare function generateState(byteLength?: number): string;
|
|
20
|
+
//# sourceMappingURL=pkce.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pkce.d.ts","sourceRoot":"","sources":["../../src/auth/pkce.ts"],"names":[],"mappings":"AAEA,yDAAyD;AACzD,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,sEAAsE;AACtE,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,SAAK,GAAG,MAAM,CAE5D;AAED,oFAAoF;AACpF,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED,0CAA0C;AAC1C,wBAAgB,gBAAgB,CAAC,UAAU,SAAK,GAAG,QAAQ,CAG1D;AAED,sEAAsE;AACtE,wBAAgB,aAAa,CAAC,UAAU,SAAK,GAAG,MAAM,CAErD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Provider } from "../types";
|
|
2
|
+
import type { OAuthProviderConfig } from "./types";
|
|
3
|
+
/** The env var that overrides a provider's client id. */
|
|
4
|
+
export declare function clientIdEnvVar(provider: Provider): string;
|
|
5
|
+
/**
|
|
6
|
+
* Whether `clientId` is an AP3X-invented, non-functional placeholder for this
|
|
7
|
+
* provider (the `ap3x-<provider>-oauth` default) — as opposed to a vendor
|
|
8
|
+
* protocol value or a user-configured id. Callers use this to turn a raw
|
|
9
|
+
* vendor error into an actionable "set the env var" message; a real configured
|
|
10
|
+
* id never matches.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isPlaceholderClientId(provider: Provider, clientId: string): boolean;
|
|
13
|
+
export interface OAuthProviderConfigOverrides {
|
|
14
|
+
clientId?: string;
|
|
15
|
+
authorizationUrl?: string;
|
|
16
|
+
deviceAuthorizationUrl?: string;
|
|
17
|
+
tokenUrl?: string;
|
|
18
|
+
scopes?: string[];
|
|
19
|
+
redirectUri?: string;
|
|
20
|
+
refreshSkewSeconds?: number;
|
|
21
|
+
}
|
|
22
|
+
/** Provider slugs AP3X ships an OAuth config for. */
|
|
23
|
+
export declare function oauthProviders(): Provider[];
|
|
24
|
+
/** Whether a provider has a built-in OAuth config. */
|
|
25
|
+
export declare function hasOAuthConfig(provider: Provider): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Build the effective OAuth config for a provider, resolving the client id from
|
|
28
|
+
* (in precedence order) the explicit override, the
|
|
29
|
+
* `AP3X_<PROVIDER>_OAUTH_CLIENT_ID` env var, then the AP3X placeholder default.
|
|
30
|
+
* Returns `undefined` for providers without an OAuth config.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getOAuthProviderConfig(provider: Provider, overrides?: OAuthProviderConfigOverrides): OAuthProviderConfig | undefined;
|
|
33
|
+
//# sourceMappingURL=providers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../src/auth/providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AA8BnD,yDAAyD;AACzD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAKzD;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEnF;AAyED,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,qDAAqD;AACrD,wBAAgB,cAAc,IAAI,QAAQ,EAAE,CAE3C;AAED,sDAAsD;AACtD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAE1D;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,QAAQ,EAClB,SAAS,GAAE,4BAAiC,GAC3C,mBAAmB,GAAG,SAAS,CAejC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Provider } from "../types";
|
|
2
|
+
import type { OAuthToken } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Persists OAuth tokens per provider under the AP3X config dir
|
|
5
|
+
* (`~/.ap3x/oauth.json` by default; `AP3X_CONFIG_DIR` overrides). All methods
|
|
6
|
+
* are async because they lazily load node builtins.
|
|
7
|
+
*
|
|
8
|
+
* An in-memory backing store can be injected for tests / non-node runtimes.
|
|
9
|
+
*/
|
|
10
|
+
export declare class AuthStorage {
|
|
11
|
+
/** Optional in-memory store; when set, the filesystem is never touched. */
|
|
12
|
+
private readonly memory;
|
|
13
|
+
/**
|
|
14
|
+
* Per-key serialization chains. A key's tasks run strictly one-at-a-time so a
|
|
15
|
+
* read→modify→write is never interleaved: {@link modify} serializes per
|
|
16
|
+
* provider (single-flight refresh) and the low-level file mutations serialize
|
|
17
|
+
* on {@link AuthStorage.FILE_LOCK} so the shared `readAll`/`writeAll` cycle is
|
|
18
|
+
* atomic across providers (no last-write-wins clobber).
|
|
19
|
+
*/
|
|
20
|
+
private readonly chains;
|
|
21
|
+
/** Reserved chain key that serializes every whole-file mutation. */
|
|
22
|
+
private static readonly FILE_LOCK;
|
|
23
|
+
constructor(options?: {
|
|
24
|
+
inMemory?: boolean;
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Run `task` after every previously enqueued task for `key` has settled,
|
|
28
|
+
* serializing access. The returned promise mirrors `task`'s own outcome; the
|
|
29
|
+
* stored chain tail swallows results so one failure never wedges the queue.
|
|
30
|
+
*/
|
|
31
|
+
private enqueue;
|
|
32
|
+
/** A purely in-memory storage, for tests and ephemeral sessions. */
|
|
33
|
+
static inMemory(): AuthStorage;
|
|
34
|
+
private get path();
|
|
35
|
+
private readAll;
|
|
36
|
+
private writeAll;
|
|
37
|
+
/** Read the token set for a provider, or `undefined` when none is stored. */
|
|
38
|
+
read(provider: Provider): Promise<OAuthToken | undefined>;
|
|
39
|
+
/** Persist (replacing) the token set for a provider. */
|
|
40
|
+
write(provider: Provider, token: OAuthToken): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Serialize a read-modify-write of one provider's token. The mutator receives
|
|
43
|
+
* the token re-read *under the lock* and returns the token to persist and
|
|
44
|
+
* return; returning the same instance (or `undefined`) skips the write. This
|
|
45
|
+
* enables a double-checked refresh: N concurrent expired resolves queue on the
|
|
46
|
+
* provider, exactly one refreshes + persists, and every later waiter re-reads
|
|
47
|
+
* the freshly refreshed token and reuses it — no duplicate refresh, no clobber.
|
|
48
|
+
*/
|
|
49
|
+
modify(provider: Provider, mutator: (current: OAuthToken | undefined) => Promise<OAuthToken | undefined> | OAuthToken | undefined): Promise<OAuthToken | undefined>;
|
|
50
|
+
/** Remove a provider's stored token. */
|
|
51
|
+
clear(provider: Provider): Promise<void>;
|
|
52
|
+
/** Remove every stored token. */
|
|
53
|
+
clearAll(): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/auth/storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAO1C;;;;;;GAMG;AACH,qBAAa,WAAW;IACtB,2EAA2E;IAC3E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsC;IAE7D;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuC;IAE9D,oEAAoE;IACpE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAwB;gBAE7C,OAAO,GAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAO;IAIhD;;;;OAIG;IACH,OAAO,CAAC,OAAO;IAaf,oEAAoE;IACpE,MAAM,CAAC,QAAQ,IAAI,WAAW;IAI9B,OAAO,KAAK,IAAI,GAEf;YAEa,OAAO;YAkBP,QAAQ;IAsBtB,6EAA6E;IACvE,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAM/D,wDAAwD;IAClD,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAQjE;;;;;;;OAOG;IACG,MAAM,CACV,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,CACP,OAAO,EAAE,UAAU,GAAG,SAAS,KAC5B,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,GAAG,UAAU,GAAG,SAAS,GAC5D,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAWlC,wCAAwC;IAClC,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAc9C,iCAAiC;IAC3B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAWhC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Provider } from "../types";
|
|
2
|
+
/** Injectable fetch so tests can mock token / device endpoints. */
|
|
3
|
+
export type FetchLike = (input: string | URL, init?: {
|
|
4
|
+
method?: string;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
body?: string;
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
}) => Promise<{
|
|
9
|
+
ok: boolean;
|
|
10
|
+
status: number;
|
|
11
|
+
statusText?: string;
|
|
12
|
+
json: () => Promise<unknown>;
|
|
13
|
+
text: () => Promise<string>;
|
|
14
|
+
}>;
|
|
15
|
+
/** How a provider negotiates an OAuth grant. */
|
|
16
|
+
export type OAuthGrantType = "authorization-code" | "device-code";
|
|
17
|
+
/**
|
|
18
|
+
* Static, per-provider OAuth configuration. Client IDs are AP3X-owned
|
|
19
|
+
* placeholders by default and MUST be overridable via settings/env — AP3X never
|
|
20
|
+
* ships another vendor's registered client id.
|
|
21
|
+
*/
|
|
22
|
+
export interface OAuthProviderConfig {
|
|
23
|
+
/** Provider slug this config authenticates (e.g. "anthropic"). */
|
|
24
|
+
provider: Provider;
|
|
25
|
+
/** Which grant flow this provider uses. */
|
|
26
|
+
grantType: OAuthGrantType;
|
|
27
|
+
/** Authorization endpoint (authorization-code flow). */
|
|
28
|
+
authorizationUrl?: string;
|
|
29
|
+
/** Device-authorization endpoint (device-code flow). */
|
|
30
|
+
deviceAuthorizationUrl?: string;
|
|
31
|
+
/** Token endpoint (both flows). */
|
|
32
|
+
tokenUrl: string;
|
|
33
|
+
/** OAuth client id. AP3X placeholder default; override via env/settings. */
|
|
34
|
+
clientId: string;
|
|
35
|
+
/** Requested scopes. */
|
|
36
|
+
scopes: string[];
|
|
37
|
+
/** Redirect URI for the authorization-code flow. */
|
|
38
|
+
redirectUri?: string;
|
|
39
|
+
/** Treat a token as expired this many seconds before its real expiry. */
|
|
40
|
+
refreshSkewSeconds?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Wire format for POSTs to the token / device endpoints (code exchange,
|
|
43
|
+
* refresh, device authorization). Most OAuth token endpoints accept
|
|
44
|
+
* `application/x-www-form-urlencoded` (the default when omitted); a few —
|
|
45
|
+
* notably Anthropic's `platform.claude.com` token endpoint — require a JSON
|
|
46
|
+
* body and reject form-encoding. Per-provider so the flow logic stays generic.
|
|
47
|
+
*/
|
|
48
|
+
tokenRequestFormat?: "form" | "json";
|
|
49
|
+
/**
|
|
50
|
+
* Extra provider-specific query params appended verbatim to the authorization
|
|
51
|
+
* URL (e.g. ChatGPT's `id_token_add_organizations`, `codex_cli_simplified_flow`,
|
|
52
|
+
* `originator`). Kept generic so the flow logic stays provider-agnostic.
|
|
53
|
+
*/
|
|
54
|
+
extraAuthParams?: Record<string, string>;
|
|
55
|
+
}
|
|
56
|
+
/** A persisted OAuth token set for one provider. */
|
|
57
|
+
export interface OAuthToken {
|
|
58
|
+
accessToken: string;
|
|
59
|
+
refreshToken?: string;
|
|
60
|
+
/** Epoch milliseconds at which `accessToken` expires; omitted = never. */
|
|
61
|
+
expiresAt?: number;
|
|
62
|
+
tokenType?: string;
|
|
63
|
+
scope?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Account identifier carried alongside the token (e.g. ChatGPT's
|
|
66
|
+
* `chatgpt_account_id`, decoded from the id_token). Sent as a per-provider
|
|
67
|
+
* header by the unified auth seam when present.
|
|
68
|
+
*/
|
|
69
|
+
accountId?: string;
|
|
70
|
+
/** The raw OIDC id_token JWT, retained for account-id extraction / debugging. */
|
|
71
|
+
idToken?: string;
|
|
72
|
+
}
|
|
73
|
+
/** Result of resolving auth for a model: a single header set to send. */
|
|
74
|
+
export interface ResolvedAuth {
|
|
75
|
+
/** Authentication mode that produced the headers. */
|
|
76
|
+
mode: "oauth" | "api-key" | "none";
|
|
77
|
+
/** Headers to merge onto the provider request. */
|
|
78
|
+
headers: Record<string, string>;
|
|
79
|
+
/** The raw bearer/api-key value, exposed for providers that build their own headers. */
|
|
80
|
+
apiKey?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Per-account base URL derived during resolution, when the credential encodes
|
|
83
|
+
* one (e.g. a GitHub Copilot bearer names its API proxy endpoint). Callers may
|
|
84
|
+
* apply it over the model's catalog default; absent means use the default.
|
|
85
|
+
*/
|
|
86
|
+
baseUrl?: string;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/auth/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,mEAAmE;AACnE,MAAM,MAAM,SAAS,GAAG,CACtB,KAAK,EAAE,MAAM,GAAG,GAAG,EACnB,IAAI,CAAC,EAAE;IACL,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,KACE,OAAO,CAAC;IACX,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7B,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7B,CAAC,CAAC;AAEH,gDAAgD;AAChD,MAAM,MAAM,cAAc,GAAG,oBAAoB,GAAG,aAAa,CAAC;AAElE;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,kEAAkE;IAClE,QAAQ,EAAE,QAAQ,CAAC;IACnB,2CAA2C;IAC3C,SAAS,EAAE,cAAc,CAAC;IAC1B,wDAAwD;IACxD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,wDAAwD;IACxD,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,CAAC;IACjB,wBAAwB;IACxB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,oDAAoD;IACpD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yEAAyE;IACzE,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrC;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C;AAED,oDAAoD;AACpD,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iFAAiF;IACjF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,yEAAyE;AACzE,MAAM,WAAW,YAAY;IAC3B,qDAAqD;IACrD,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;IACnC,kDAAkD;IAClD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,wFAAwF;IACxF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Api, Model } from "../types";
|
|
2
|
+
import { type OAuthProviderConfigOverrides } from "./providers";
|
|
3
|
+
import { AuthStorage } from "./storage";
|
|
4
|
+
import type { FetchLike, ResolvedAuth } from "./types";
|
|
5
|
+
export interface ResolveAuthOptions {
|
|
6
|
+
/** Storage backing OAuth tokens. Defaults to the on-disk AuthStorage. */
|
|
7
|
+
storage?: AuthStorage;
|
|
8
|
+
/** Injectable fetch for the refresh call. */
|
|
9
|
+
fetchImpl?: FetchLike;
|
|
10
|
+
/** Clock, injectable for tests. */
|
|
11
|
+
now?: () => number;
|
|
12
|
+
/** Per-provider OAuth config overrides (client id, endpoints, scopes). */
|
|
13
|
+
oauthOverrides?: OAuthProviderConfigOverrides;
|
|
14
|
+
/** An explicit API key (e.g. from StreamOptions) takes precedence over env. */
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The unified auth seam (#38): given a model, return the headers a provider call
|
|
20
|
+
* should send. Resolution order per provider:
|
|
21
|
+
* 1. A stored OAuth token (auto-refreshed if expired/near-expiry).
|
|
22
|
+
* 2. An explicit API key, then an environment API key.
|
|
23
|
+
* 3. `none` when nothing is configured.
|
|
24
|
+
*
|
|
25
|
+
* OAuth refresh goes through the injectable `fetchImpl` and persists the new
|
|
26
|
+
* token via `storage`, so a provider call transparently receives a fresh bearer.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getApiKeyAndHeaders<TApi extends Api>(model: Model<TApi>, options?: ResolveAuthOptions): Promise<ResolvedAuth>;
|
|
29
|
+
//# sourceMappingURL=unified.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unified.d.ts","sourceRoot":"","sources":["../../src/auth/unified.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAY,MAAM,UAAU,CAAC;AAGrD,OAAO,EAAE,KAAK,4BAA4B,EAA0B,MAAM,aAAa,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAc,YAAY,EAAE,MAAM,SAAS,CAAC;AAqBnE,MAAM,WAAW,kBAAkB;IACjC,yEAAyE;IACzE,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,6CAA6C;IAC7C,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,mCAAmC;IACnC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,0EAA0E;IAC1E,cAAc,CAAC,EAAE,4BAA4B,CAAC;IAC9C,+EAA+E;IAC/E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,SAAS,GAAG,EACxD,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,YAAY,CAAC,CA8DvB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { KnownProvider } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Return the env var names actually set for the provider, or `undefined` when
|
|
4
|
+
* none are. Reports only explicit API-key variables (not ambient credentials).
|
|
5
|
+
*/
|
|
6
|
+
export declare function findEnvKeys(provider: KnownProvider): string[] | undefined;
|
|
7
|
+
export declare function findEnvKeys(provider: string): string[] | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Resolve an API key for a provider from the environment. Returns the value of
|
|
10
|
+
* the first set env var, or the sentinel `"<authenticated>"` for providers that
|
|
11
|
+
* authenticate via ambient credentials (Vertex ADC, AWS for Bedrock).
|
|
12
|
+
* Providers that require OAuth tokens are not resolved here.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getEnvApiKey(provider: KnownProvider): string | undefined;
|
|
15
|
+
export declare function getEnvApiKey(provider: string): string | undefined;
|
|
16
|
+
//# sourceMappingURL=env-api-keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-api-keys.d.ts","sourceRoot":"","sources":["../src/env-api-keys.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AA6F7C;;;GAGG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,aAAa,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC;AAC3E,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC;AAQpE;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,aAAa,GAAG,MAAM,GAAG,SAAS,CAAC;AAC1E,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC"}
|