@nyte-ai/ai 0.0.0-stage → 0.0.18
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 +170 -2
- package/THIRD-PARTY-NOTICES.md +800 -0
- package/dist/chunks/account-limits-cache-031vfpt3.js +37 -0
- package/dist/chunks/account-limits-cache-09vs98g6.js +41 -0
- package/dist/chunks/account-limits-cache-0af5gqeg.js +15 -0
- package/dist/chunks/account-limits-cache-0yd6bde8.js +103 -0
- package/dist/chunks/account-limits-cache-1jv43fhh.js +22 -0
- package/dist/chunks/account-limits-cache-3ykqmnj5.js +88 -0
- package/dist/chunks/account-limits-cache-4b8ckwqw.js +293 -0
- package/dist/chunks/account-limits-cache-4fn5w63p.js +295 -0
- package/dist/chunks/account-limits-cache-4hptgd2h.js +49 -0
- package/dist/chunks/account-limits-cache-53e64mhx.js +417 -0
- package/dist/chunks/account-limits-cache-5jdhn0e1.js +562 -0
- package/dist/chunks/account-limits-cache-5rx2pfm5.js +8 -0
- package/dist/chunks/account-limits-cache-5ygxyyss.js +19 -0
- package/dist/chunks/account-limits-cache-6250ykn6.js +21 -0
- package/dist/chunks/account-limits-cache-6x05n06z.js +49 -0
- package/dist/chunks/account-limits-cache-736tdyme.js +6 -0
- package/dist/chunks/account-limits-cache-75smws02.js +213 -0
- package/dist/chunks/account-limits-cache-7z9s8j16.js +139 -0
- package/dist/chunks/account-limits-cache-8137j3zp.js +37 -0
- package/dist/chunks/account-limits-cache-8qzk56vj.js +160 -0
- package/dist/chunks/account-limits-cache-8s8bz4dr.js +36 -0
- package/dist/chunks/account-limits-cache-8vzx8k6r.js +166 -0
- package/dist/chunks/account-limits-cache-8wfqg73s.js +135 -0
- package/dist/chunks/account-limits-cache-90c9c2eb.js +50 -0
- package/dist/chunks/account-limits-cache-9wqk28n5.js +25 -0
- package/dist/chunks/account-limits-cache-a1jyaq00.js +56 -0
- package/dist/chunks/account-limits-cache-a558rjbg.js +138 -0
- package/dist/chunks/account-limits-cache-a55e14fr.js +70 -0
- package/dist/chunks/account-limits-cache-a6cgeagz.js +77 -0
- package/dist/chunks/account-limits-cache-ag5b8dja.js +38 -0
- package/dist/chunks/account-limits-cache-b0x2sfya.js +45 -0
- package/dist/chunks/account-limits-cache-b23sbrke.js +26 -0
- package/dist/chunks/account-limits-cache-b4edaybk.js +8 -0
- package/dist/chunks/account-limits-cache-bsknrh6t.js +74 -0
- package/dist/chunks/account-limits-cache-c7v93krb.js +235 -0
- package/dist/chunks/account-limits-cache-csbxvam7.js +12 -0
- package/dist/chunks/account-limits-cache-cw7q7vfy.js +293 -0
- package/dist/chunks/account-limits-cache-d1ypzqzp.js +27 -0
- package/dist/chunks/account-limits-cache-d2a51dka.js +17 -0
- package/dist/chunks/account-limits-cache-dejeygdt.js +114 -0
- package/dist/chunks/account-limits-cache-eejm0vth.js +11 -0
- package/dist/chunks/account-limits-cache-ehy0ze2b.js +33 -0
- package/dist/chunks/account-limits-cache-emg5b4hj.js +53 -0
- package/dist/chunks/account-limits-cache-eqwweapz.js +6 -0
- package/dist/chunks/account-limits-cache-eyx1jcxc.js +8 -0
- package/dist/chunks/account-limits-cache-f9z00x8c.js +36 -0
- package/dist/chunks/account-limits-cache-fbkaq46e.js +113 -0
- package/dist/chunks/account-limits-cache-fdwad56n.js +399 -0
- package/dist/chunks/account-limits-cache-fht68jp2.js +22 -0
- package/dist/chunks/account-limits-cache-fp03ztsw.js +17 -0
- package/dist/chunks/account-limits-cache-fsktnetm.js +69 -0
- package/dist/chunks/account-limits-cache-fvadc36m.js +110 -0
- package/dist/chunks/account-limits-cache-ghe9ne4j.js +69 -0
- package/dist/chunks/account-limits-cache-gknnm1kv.js +13 -0
- package/dist/chunks/account-limits-cache-gqsrbky9.js +40 -0
- package/dist/chunks/account-limits-cache-gr671dr2.js +0 -0
- package/dist/chunks/account-limits-cache-gs8a3fhw.js +32 -0
- package/dist/chunks/account-limits-cache-gsa5tzck.js +37 -0
- package/dist/chunks/account-limits-cache-h92bzz1j.js +235 -0
- package/dist/chunks/account-limits-cache-hemxtapd.js +142 -0
- package/dist/chunks/account-limits-cache-hj1h48sc.js +92 -0
- package/dist/chunks/account-limits-cache-hj3ek3ty.js +128 -0
- package/dist/chunks/account-limits-cache-hwehc67r.js +509 -0
- package/dist/chunks/account-limits-cache-hyzn1jmk.js +46 -0
- package/dist/chunks/account-limits-cache-j2bt392s.js +63 -0
- package/dist/chunks/account-limits-cache-k0pkzhbx.js +74 -0
- package/dist/chunks/account-limits-cache-kjx405q0.js +277 -0
- package/dist/chunks/account-limits-cache-ks1sjym9.js +37 -0
- package/dist/chunks/account-limits-cache-me1x57bs.js +89 -0
- package/dist/chunks/account-limits-cache-n3yk6g5c.js +314 -0
- package/dist/chunks/account-limits-cache-nbhht7xz.js +72 -0
- package/dist/chunks/account-limits-cache-nbkyhs6v.js +42 -0
- package/dist/chunks/account-limits-cache-nn9jebsj.js +26 -0
- package/dist/chunks/account-limits-cache-nxkprk3g.js +13 -0
- package/dist/chunks/account-limits-cache-nyy770yd.js +38 -0
- package/dist/chunks/account-limits-cache-pfa86y8e.js +45 -0
- package/dist/chunks/account-limits-cache-pfr14mcn.js +59 -0
- package/dist/chunks/account-limits-cache-q1ebtvet.js +8 -0
- package/dist/chunks/account-limits-cache-q63mc41j.js +51 -0
- package/dist/chunks/account-limits-cache-re8hpzwn.js +104 -0
- package/dist/chunks/account-limits-cache-rz8p1g5y.js +9 -0
- package/dist/chunks/account-limits-cache-skbfmzqe.js +7 -0
- package/dist/chunks/account-limits-cache-tc38g0ca.js +20 -0
- package/dist/chunks/account-limits-cache-v4n30az2.js +24 -0
- package/dist/chunks/account-limits-cache-vwgfz727.js +281 -0
- package/dist/chunks/account-limits-cache-x9fvb3s5.js +8 -0
- package/dist/chunks/account-limits-cache-xds88kxd.js +209 -0
- package/dist/chunks/account-limits-cache-xz65wyd1.js +428 -0
- package/dist/chunks/account-limits-cache-ydq8p8qp.js +39 -0
- package/dist/chunks/account-limits-cache-ykbqsvv6.js +134 -0
- package/dist/chunks/account-limits-cache-za42x8a3.js +25 -0
- package/dist/chunks/account-limits-cache-zcbkmrvy.js +79 -0
- package/dist/chunks/account-limits-cache-zgzptd0z.js +62 -0
- package/dist/chunks/account-limits-cache-zn01kscn.js +252 -0
- package/dist/chunks/account-limits-cache-zpjmeyt0.js +113 -0
- package/dist/chunks/account-limits-cache-zqdb4yh4.js +8 -0
- package/dist/src/account-limits-cache.d.ts +16 -0
- package/dist/src/account-limits-cache.js +7 -0
- package/dist/src/api/anthropic-client.d.ts +25 -0
- package/dist/src/api/anthropic-client.js +30 -0
- package/dist/src/api/anthropic-convert.d.ts +17 -0
- package/dist/src/api/anthropic-convert.js +14 -0
- package/dist/src/api/anthropic-events.d.ts +101 -0
- package/dist/src/api/anthropic-events.js +11 -0
- package/dist/src/api/anthropic-messages.d.ts +88 -0
- package/dist/src/api/anthropic-messages.js +578 -0
- package/dist/src/api/anthropic-messages.lazy.d.ts +2 -0
- package/dist/src/api/anthropic-messages.lazy.js +11 -0
- package/dist/src/api/assistant-stream.d.ts +23 -0
- package/dist/src/api/assistant-stream.js +15 -0
- package/dist/src/api/claude-code.d.ts +12 -0
- package/dist/src/api/claude-code.js +12 -0
- package/dist/src/api/cloudflare.d.ts +8 -0
- package/dist/src/api/cloudflare.js +11 -0
- package/dist/src/api/constrained-sampling.d.ts +24 -0
- package/dist/src/api/constrained-sampling.js +16 -0
- package/dist/src/api/deferred.d.ts +7 -0
- package/dist/src/api/deferred.js +10 -0
- package/dist/src/api/github-copilot-headers.d.ts +15 -0
- package/dist/src/api/github-copilot-headers.js +12 -0
- package/dist/src/api/google-generative-ai.d.ts +22 -0
- package/dist/src/api/google-generative-ai.js +583 -0
- package/dist/src/api/google-generative-ai.lazy.d.ts +2 -0
- package/dist/src/api/google-generative-ai.lazy.js +11 -0
- package/dist/src/api/lazy.d.ts +18 -0
- package/dist/src/api/lazy.js +12 -0
- package/dist/src/api/openai-codex-compact.d.ts +14 -0
- package/dist/src/api/openai-codex-compact.js +389 -0
- package/dist/src/api/openai-codex-compaction-error.d.ts +7 -0
- package/dist/src/api/openai-codex-compaction-error.js +6 -0
- package/dist/src/api/openai-codex-protocol.d.ts +125 -0
- package/dist/src/api/openai-codex-protocol.js +48 -0
- package/dist/src/api/openai-codex-responses.d.ts +4 -0
- package/dist/src/api/openai-codex-responses.js +175 -0
- package/dist/src/api/openai-codex-responses.lazy.d.ts +2 -0
- package/dist/src/api/openai-codex-responses.lazy.js +11 -0
- package/dist/src/api/openai-codex-websocket.d.ts +13 -0
- package/dist/src/api/openai-codex-websocket.js +37 -0
- package/dist/src/api/openai-codex-wire.d.ts +44 -0
- package/dist/src/api/openai-codex-wire.js +34 -0
- package/dist/src/api/openai-compact.d.ts +9 -0
- package/dist/src/api/openai-compact.js +12 -0
- package/dist/src/api/openai-completions-convert.d.ts +58 -0
- package/dist/src/api/openai-completions-convert.js +21 -0
- package/dist/src/api/openai-completions-params.d.ts +29 -0
- package/dist/src/api/openai-completions-params.js +20 -0
- package/dist/src/api/openai-completions-reasoning.d.ts +54 -0
- package/dist/src/api/openai-completions-reasoning.js +22 -0
- package/dist/src/api/openai-completions.d.ts +22 -0
- package/dist/src/api/openai-completions.js +484 -0
- package/dist/src/api/openai-completions.lazy.d.ts +5 -0
- package/dist/src/api/openai-completions.lazy.js +11 -0
- package/dist/src/api/openai-prompt-cache.d.ts +1 -0
- package/dist/src/api/openai-prompt-cache.js +6 -0
- package/dist/src/api/openai-responses-convert.d.ts +58 -0
- package/dist/src/api/openai-responses-convert.js +16 -0
- package/dist/src/api/openai-responses-events.d.ts +379 -0
- package/dist/src/api/openai-responses-events.js +12 -0
- package/dist/src/api/openai-responses-stream.d.ts +36 -0
- package/dist/src/api/openai-responses-stream.js +25 -0
- package/dist/src/api/openai-responses.d.ts +18 -0
- package/dist/src/api/openai-responses.js +276 -0
- package/dist/src/api/openai-responses.lazy.d.ts +2 -0
- package/dist/src/api/openai-responses.lazy.js +11 -0
- package/dist/src/api/simple-options.d.ts +17 -0
- package/dist/src/api/simple-options.js +18 -0
- package/dist/src/api/token-count.d.ts +5 -0
- package/dist/src/api/token-count.js +8 -0
- package/dist/src/api/transform-messages.d.ts +9 -0
- package/dist/src/api/transform-messages.js +6 -0
- package/dist/src/api-options.d.ts +27 -0
- package/dist/src/api-options.js +0 -0
- package/dist/src/auth/context.d.ts +11 -0
- package/dist/src/auth/context.js +6 -0
- package/dist/src/auth/credential-store.d.ts +17 -0
- package/dist/src/auth/credential-store.js +7 -0
- package/dist/src/auth/helpers.d.ts +24 -0
- package/dist/src/auth/helpers.js +8 -0
- package/dist/src/auth/oauth/anthropic.d.ts +7 -0
- package/dist/src/auth/oauth/anthropic.js +12 -0
- package/dist/src/auth/oauth/authorization-input.d.ts +14 -0
- package/dist/src/auth/oauth/authorization-input.js +6 -0
- package/dist/src/auth/oauth/device-code.d.ts +29 -0
- package/dist/src/auth/oauth/device-code.js +9 -0
- package/dist/src/auth/oauth/github-copilot.d.ts +23 -0
- package/dist/src/auth/oauth/github-copilot.js +12 -0
- package/dist/src/auth/oauth/load.d.ts +14 -0
- package/dist/src/auth/oauth/load.js +10 -0
- package/dist/src/auth/oauth/oauth-page.d.ts +13 -0
- package/dist/src/auth/oauth/oauth-page.js +8 -0
- package/dist/src/auth/oauth/openai-codex.d.ts +10 -0
- package/dist/src/auth/oauth/openai-codex.js +18 -0
- package/dist/src/auth/oauth/pkce.d.ts +12 -0
- package/dist/src/auth/oauth/pkce.js +6 -0
- package/dist/src/auth/resolve.d.ts +38 -0
- package/dist/src/auth/resolve.js +12 -0
- package/dist/src/auth/store.d.ts +29 -0
- package/dist/src/auth/store.js +10 -0
- package/dist/src/auth/types.d.ts +291 -0
- package/dist/src/auth/types.js +8 -0
- package/dist/src/auth/verify.d.ts +13 -0
- package/dist/src/auth/verify.js +7 -0
- package/dist/src/bun-oauth.d.ts +2 -0
- package/dist/src/bun-oauth.js +25 -0
- package/dist/src/env-api-keys.d.ts +32 -0
- package/dist/src/env-api-keys.js +27 -0
- package/dist/src/file-models-store.d.ts +18 -0
- package/dist/src/file-models-store.js +9 -0
- package/dist/src/index.d.ts +62 -0
- package/dist/src/index.js +372 -0
- package/dist/src/model-capabilities.d.ts +21 -0
- package/dist/src/model-capabilities.js +14 -0
- package/dist/src/model-pricing.d.ts +6 -0
- package/dist/src/model-pricing.js +10 -0
- package/dist/src/model-variants.d.ts +21 -0
- package/dist/src/model-variants.js +19 -0
- package/dist/src/models-refresh.d.ts +27 -0
- package/dist/src/models-refresh.js +9 -0
- package/dist/src/models-store.d.ts +31 -0
- package/dist/src/models-store.js +6 -0
- package/dist/src/models-types.d.ts +206 -0
- package/dist/src/models-types.js +0 -0
- package/dist/src/models.d.ts +7 -0
- package/dist/src/models.js +44 -0
- package/dist/src/prompt-cache.d.ts +5 -0
- package/dist/src/prompt-cache.js +9 -0
- package/dist/src/provider.d.ts +23 -0
- package/dist/src/provider.js +14 -0
- package/dist/src/providers/account-limits.d.ts +13 -0
- package/dist/src/providers/account-limits.js +8 -0
- package/dist/src/providers/anthropic-limits.d.ts +9 -0
- package/dist/src/providers/anthropic-limits.js +10 -0
- package/dist/src/providers/anthropic.d.ts +2 -0
- package/dist/src/providers/anthropic.js +25 -0
- package/dist/src/providers/github-copilot-catalog.d.ts +5 -0
- package/dist/src/providers/github-copilot-catalog.js +7 -0
- package/dist/src/providers/github-copilot.d.ts +2 -0
- package/dist/src/providers/github-copilot.js +23 -0
- package/dist/src/providers/nyte-catalog.d.ts +15 -0
- package/dist/src/providers/nyte-catalog.js +63 -0
- package/dist/src/providers/openai-codex-limits.d.ts +8 -0
- package/dist/src/providers/openai-codex-limits.js +14 -0
- package/dist/src/providers/openai-codex.d.ts +2 -0
- package/dist/src/providers/openai-codex.js +23 -0
- package/dist/src/providers/openai.d.ts +2 -0
- package/dist/src/providers/openai.js +19 -0
- package/dist/src/providers/opencode-go.d.ts +5 -0
- package/dist/src/providers/opencode-go.js +22 -0
- package/dist/src/providers/opencode-headers.d.ts +5 -0
- package/dist/src/providers/opencode-headers.js +6 -0
- package/dist/src/providers/opencode.d.ts +14 -0
- package/dist/src/providers/opencode.js +23 -0
- package/dist/src/providers/openrouter.d.ts +2 -0
- package/dist/src/providers/openrouter.js +19 -0
- package/dist/src/providers/vercel-ai-gateway.d.ts +3 -0
- package/dist/src/providers/vercel-ai-gateway.js +19 -0
- package/dist/src/session-resources.d.ts +9 -0
- package/dist/src/session-resources.js +10 -0
- package/dist/src/types.d.ts +210 -0
- package/dist/src/types.js +1 -0
- package/dist/src/utils/abort.d.ts +12 -0
- package/dist/src/utils/abort.js +10 -0
- package/dist/src/utils/deferred-tools.d.ts +11 -0
- package/dist/src/utils/deferred-tools.js +6 -0
- package/dist/src/utils/diagnostics.d.ts +11 -0
- package/dist/src/utils/diagnostics.js +12 -0
- package/dist/src/utils/error-body.d.ts +26 -0
- package/dist/src/utils/error-body.js +10 -0
- package/dist/src/utils/estimate.d.ts +20 -0
- package/dist/src/utils/estimate.js +14 -0
- package/dist/src/utils/event-stream.d.ts +22 -0
- package/dist/src/utils/event-stream.js +11 -0
- package/dist/src/utils/failure.d.ts +49 -0
- package/dist/src/utils/failure.js +10 -0
- package/dist/src/utils/fifo-queue.d.ts +11 -0
- package/dist/src/utils/fifo-queue.js +6 -0
- package/dist/src/utils/hash.d.ts +5 -0
- package/dist/src/utils/hash.js +6 -0
- package/dist/src/utils/headers.d.ts +12 -0
- package/dist/src/utils/headers.js +14 -0
- package/dist/src/utils/json-parse.d.ts +33 -0
- package/dist/src/utils/json-parse.js +12 -0
- package/dist/src/utils/node-http-proxy.d.ts +6 -0
- package/dist/src/utils/node-http-proxy.js +9 -0
- package/dist/src/utils/nyte-home.d.ts +2 -0
- package/dist/src/utils/nyte-home.js +6 -0
- package/dist/src/utils/nyte-user-agent.d.ts +1 -0
- package/dist/src/utils/nyte-user-agent.js +6 -0
- package/dist/src/utils/overflow.d.ts +18 -0
- package/dist/src/utils/overflow.js +9 -0
- package/dist/src/utils/provider-env.d.ts +9 -0
- package/dist/src/utils/provider-env.js +6 -0
- package/dist/src/utils/provider-retry.d.ts +22 -0
- package/dist/src/utils/provider-retry.js +9 -0
- package/dist/src/utils/retry.d.ts +66 -0
- package/dist/src/utils/retry.js +18 -0
- package/dist/src/utils/sanitize-unicode.d.ts +24 -0
- package/dist/src/utils/sanitize-unicode.js +6 -0
- package/dist/src/utils/sse.d.ts +21 -0
- package/dist/src/utils/sse.js +6 -0
- package/dist/src/utils/text.d.ts +5 -0
- package/dist/src/utils/text.js +10 -0
- package/dist/src/utils/transcript.d.ts +5 -0
- package/dist/src/utils/transcript.js +36 -0
- package/dist/src/utils/typebox-helpers.d.ts +19 -0
- package/dist/src/utils/typebox-helpers.js +6 -0
- package/dist/src/utils/uuid.d.ts +2 -0
- package/dist/src/utils/uuid.js +6 -0
- package/dist/src/utils/validation.d.ts +13 -0
- package/dist/src/utils/validation.js +8 -0
- package/package.json +152 -3
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Codex (ChatGPT OAuth) flow: browser login races a localhost callback
|
|
3
|
+
* server on port 1455 against a manual paste prompt; device-code login covers
|
|
4
|
+
* headless boxes via the shared RFC 8628 poller. Node-only (node:crypto,
|
|
5
|
+
* node:http) and loaded lazily so browser builds never pull those in.
|
|
6
|
+
*/
|
|
7
|
+
import { type OAuthAuth } from "../types.ts";
|
|
8
|
+
export declare const ORIGINATOR = "nyte";
|
|
9
|
+
export declare function getAccountId(accessToken: string): string | null;
|
|
10
|
+
export declare const openaiCodexOAuth: OAuthAuth;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ORIGINATOR2,
|
|
3
|
+
getAccountId2,
|
|
4
|
+
openaiCodexOAuth2
|
|
5
|
+
} from "../../../chunks/account-limits-cache-xz65wyd1.js";
|
|
6
|
+
import"../../../chunks/account-limits-cache-d1ypzqzp.js";
|
|
7
|
+
import"../../../chunks/account-limits-cache-8vzx8k6r.js";
|
|
8
|
+
import"../../../chunks/account-limits-cache-tc38g0ca.js";
|
|
9
|
+
import"../../../chunks/account-limits-cache-b0x2sfya.js";
|
|
10
|
+
import"../../../chunks/account-limits-cache-v4n30az2.js";
|
|
11
|
+
import"../../../chunks/account-limits-cache-4hptgd2h.js";
|
|
12
|
+
import"../../../chunks/account-limits-cache-j2bt392s.js";
|
|
13
|
+
import"../../../chunks/account-limits-cache-b23sbrke.js";
|
|
14
|
+
export {
|
|
15
|
+
ORIGINATOR2 as ORIGINATOR,
|
|
16
|
+
getAccountId2 as getAccountId,
|
|
17
|
+
openaiCodexOAuth2 as openaiCodexOAuth
|
|
18
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PKCE utilities using the Web Crypto API, so the same code runs in Node 20+
|
|
3
|
+
* and browsers.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Generate PKCE code verifier and challenge.
|
|
7
|
+
* Uses Web Crypto API for cross-platform compatibility.
|
|
8
|
+
*/
|
|
9
|
+
export declare function generatePKCE(): Promise<{
|
|
10
|
+
verifier: string;
|
|
11
|
+
challenge: string;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider auth resolution: explicit overrides first, then the stored
|
|
3
|
+
* credential (OAuth refreshed under the store lock with double-checked
|
|
4
|
+
* expiry), then ambient sources. Storage and refresh failures surface as
|
|
5
|
+
* `ModelsError` with a code the caller can branch on.
|
|
6
|
+
*/
|
|
7
|
+
import type { ProviderEnv } from "../types.ts";
|
|
8
|
+
import type { AuthContext, AuthResult, CredentialStore, ProviderAuth } from "./types.ts";
|
|
9
|
+
export type ModelsErrorCode = "model_source" | "model_validation" | "provider" | "stream" | "auth" | "oauth";
|
|
10
|
+
export interface AuthResolutionOverrides {
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
env?: ProviderEnv;
|
|
13
|
+
/** Require this much remaining OAuth-token validity; defaults to five minutes. */
|
|
14
|
+
minOAuthValidityMs?: number;
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
}
|
|
17
|
+
export declare class ModelsError extends Error {
|
|
18
|
+
readonly code: ModelsErrorCode;
|
|
19
|
+
constructor(code: ModelsErrorCode, message: string, options?: {
|
|
20
|
+
cause?: unknown;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Auth resolution shared by the `Models` and `ImagesModels` collections.
|
|
25
|
+
* A stored credential owns the provider: ambient/env is consulted only when
|
|
26
|
+
* nothing is stored. No silent env fallback after a failed refresh or for a
|
|
27
|
+
* credential type without a matching handler.
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveProviderAuth(provider: {
|
|
30
|
+
id: string;
|
|
31
|
+
auth: ProviderAuth;
|
|
32
|
+
}, credentials: CredentialStore, authContext: AuthContext, overrides?: AuthResolutionOverrides): Promise<AuthResult | undefined>;
|
|
33
|
+
/**
|
|
34
|
+
* Cap on one token refresh. Every refresh runs inside `CredentialStore.modify`,
|
|
35
|
+
* so this is also how long a refresh can hold the credential lock other clients
|
|
36
|
+
* are waiting on.
|
|
37
|
+
*/
|
|
38
|
+
export declare const DEFAULT_OAUTH_REFRESH_TIMEOUT_MS = 15000;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ModelsError2,
|
|
3
|
+
resolveProviderAuth2,
|
|
4
|
+
DEFAULT_OAUTH_REFRESH_TIMEOUT_MS2
|
|
5
|
+
} from "../../chunks/account-limits-cache-7z9s8j16.js";
|
|
6
|
+
import"../../chunks/account-limits-cache-9wqk28n5.js";
|
|
7
|
+
import"../../chunks/account-limits-cache-j2bt392s.js";
|
|
8
|
+
export {
|
|
9
|
+
DEFAULT_OAUTH_REFRESH_TIMEOUT_MS2 as DEFAULT_OAUTH_REFRESH_TIMEOUT_MS,
|
|
10
|
+
ModelsError2 as ModelsError,
|
|
11
|
+
resolveProviderAuth2 as resolveProviderAuth
|
|
12
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AuthOperationOptions, CredentialAccounts, CredentialInfo, CredentialStore } from "./types.ts";
|
|
2
|
+
export declare function defaultAuthPath(): string;
|
|
3
|
+
/**
|
|
4
|
+
* File-backed credential store. The file is created 0600 under a 0700
|
|
5
|
+
* directory. Storage failures reject instead of resolving empty, so a file
|
|
6
|
+
* that cannot be read is never replaced by one that drops its credentials.
|
|
7
|
+
*/
|
|
8
|
+
export declare class FileCredentialStore implements CredentialStore {
|
|
9
|
+
private readonly path;
|
|
10
|
+
private readonly lockPath;
|
|
11
|
+
constructor(path?: string);
|
|
12
|
+
/** Entries stay `unknown` so an unreadable credential survives another provider's write. */
|
|
13
|
+
private load;
|
|
14
|
+
/**
|
|
15
|
+
* Publish by rename so a concurrent reader never observes a half-written file. An advisory
|
|
16
|
+
* lock cannot make the held check and the rename one step; the check keeps a holder that
|
|
17
|
+
* already lost its lock from overwriting the current owner.
|
|
18
|
+
*/
|
|
19
|
+
private save;
|
|
20
|
+
private withLock;
|
|
21
|
+
read(providerId: string, options?: AuthOperationOptions): Promise<CredentialAccounts | undefined>;
|
|
22
|
+
list(options?: AuthOperationOptions): Promise<readonly CredentialInfo[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Persists a credential `fn` produced even when the caller stopped waiting: a refresh rotates
|
|
25
|
+
* the token the stored one replaces, so dropping it would leave a spent credential on disk.
|
|
26
|
+
*/
|
|
27
|
+
modify(providerId: string, fn: (current: CredentialAccounts | undefined) => Promise<CredentialAccounts | undefined>, options?: AuthOperationOptions): Promise<CredentialAccounts | undefined>;
|
|
28
|
+
delete(providerId: string, options?: AuthOperationOptions): Promise<void>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defaultAuthPath2,
|
|
3
|
+
FileCredentialStore2
|
|
4
|
+
} from "../../chunks/account-limits-cache-c7v93krb.js";
|
|
5
|
+
import"../../chunks/account-limits-cache-b0x2sfya.js";
|
|
6
|
+
import"../../chunks/account-limits-cache-rz8p1g5y.js";
|
|
7
|
+
export {
|
|
8
|
+
FileCredentialStore2 as FileCredentialStore,
|
|
9
|
+
defaultAuthPath2 as defaultAuthPath
|
|
10
|
+
};
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import type { ProviderEnv, ProviderHeaders } from "../types.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Request auth for a single model request. If a value cannot be expressed as
|
|
5
|
+
* `apiKey`, `headers`, or `baseUrl`, it is provider config, not auth.
|
|
6
|
+
*/
|
|
7
|
+
export interface ModelAuth {
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
headers?: ProviderHeaders;
|
|
10
|
+
baseUrl?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Stored api-key credential. `env` holds provider-scoped environment/config
|
|
14
|
+
* values such as Cloudflare account/gateway ids.
|
|
15
|
+
*/
|
|
16
|
+
export interface ApiKeyCredential {
|
|
17
|
+
type: "api_key";
|
|
18
|
+
key?: string;
|
|
19
|
+
env?: ProviderEnv;
|
|
20
|
+
}
|
|
21
|
+
/** Stored OAuth credential. */
|
|
22
|
+
export interface OAuthCredential {
|
|
23
|
+
type: "oauth";
|
|
24
|
+
refresh: string;
|
|
25
|
+
access: string;
|
|
26
|
+
expires: number;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
/** An OAuth token endpoint's answer to a code exchange or a refresh. */
|
|
30
|
+
export interface OAuthTokenResponse {
|
|
31
|
+
access_token: string;
|
|
32
|
+
refresh_token: string;
|
|
33
|
+
expires_in: number;
|
|
34
|
+
}
|
|
35
|
+
export declare const OAuthTokenResponseSchema: Type.TUnsafe<OAuthTokenResponse>;
|
|
36
|
+
/** One type-tagged credential for a stored account. */
|
|
37
|
+
export type Credential = ApiKeyCredential | OAuthCredential;
|
|
38
|
+
/** A named provider account. Its local id stays stable across token refreshes. */
|
|
39
|
+
export interface CredentialAccount {
|
|
40
|
+
readonly id: string;
|
|
41
|
+
readonly label: string;
|
|
42
|
+
readonly credential: Credential;
|
|
43
|
+
}
|
|
44
|
+
/** A provider's accounts and explicit selection, mutated together under the store lock. */
|
|
45
|
+
export interface CredentialAccounts {
|
|
46
|
+
readonly active: string | null;
|
|
47
|
+
readonly accounts: readonly CredentialAccount[];
|
|
48
|
+
}
|
|
49
|
+
/** Non-secret credential metadata for account/status enumeration. */
|
|
50
|
+
export interface CredentialInfo {
|
|
51
|
+
providerId: string;
|
|
52
|
+
id: string;
|
|
53
|
+
label: string;
|
|
54
|
+
type: Credential["type"];
|
|
55
|
+
active: boolean;
|
|
56
|
+
}
|
|
57
|
+
/** Parse persisted accounts and migrate a previous single credential at the storage boundary. */
|
|
58
|
+
export declare function readCredentialAccounts(value: unknown): CredentialAccounts | undefined;
|
|
59
|
+
/** Optional cancellation for public auth and credential operations. */
|
|
60
|
+
export interface AuthOperationOptions {
|
|
61
|
+
signal?: AbortSignal;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* App-owned account storage, keyed by `Provider.id`. `modify` is the only write path, so every mutation is a
|
|
65
|
+
* serialized read-modify-write; `Models.getAuth()` runs OAuth refresh inside
|
|
66
|
+
* `modify` so concurrent requests cannot double-refresh a rotated token. The
|
|
67
|
+
* app appends and selects a completed login inside `modify`. Login/logout orchestration
|
|
68
|
+
* is app-owned.
|
|
69
|
+
*
|
|
70
|
+
* Error semantics: `read` resolves `undefined` for missing entries. Methods
|
|
71
|
+
* reject only on storage failure; `Models` wraps such rejections in
|
|
72
|
+
* `ModelsError` with code "auth". Best-effort stores that serve an in-memory
|
|
73
|
+
* view and record persistence errors internally (like coding-agent's
|
|
74
|
+
* AuthStorage) are valid implementations.
|
|
75
|
+
*/
|
|
76
|
+
export interface CredentialStore {
|
|
77
|
+
/**
|
|
78
|
+
* Read stored accounts, including possibly expired credentials. Display/status use;
|
|
79
|
+
* resolved request auth comes from `Models.getAuth()`.
|
|
80
|
+
*/
|
|
81
|
+
read(providerId: string, options?: AuthOperationOptions): Promise<CredentialAccounts | undefined>;
|
|
82
|
+
/**
|
|
83
|
+
* List stored credential metadata without resolving or exposing secrets.
|
|
84
|
+
* Implementations must not execute configured API-key commands while listing.
|
|
85
|
+
*/
|
|
86
|
+
list(options?: AuthOperationOptions): Promise<readonly CredentialInfo[]>;
|
|
87
|
+
/**
|
|
88
|
+
* Serialized write, the only write path. `fn` sees the current accounts
|
|
89
|
+
* because correct writes (refresh, login-during-refresh) depend on it;
|
|
90
|
+
* return the new collection, or undefined to leave the entry unchanged.
|
|
91
|
+
* Mutual exclusion per provider id, cross-process too where the backing
|
|
92
|
+
* store supports it (e.g. a file lock). Resolves with the post-write
|
|
93
|
+
* collection. Rejections from `fn` propagate. A collection `fn` returned is
|
|
94
|
+
* stored even when the operation aborts afterwards, because a refresh has
|
|
95
|
+
* already rotated the token the stored one replaces.
|
|
96
|
+
* An empty account collection removes the provider entry atomically.
|
|
97
|
+
*/
|
|
98
|
+
modify(providerId: string, fn: (current: CredentialAccounts | undefined) => Promise<CredentialAccounts | undefined>, options?: AuthOperationOptions): Promise<CredentialAccounts | undefined>;
|
|
99
|
+
/** Remove every account for a provider. Implementations serialize this against `modify`. */
|
|
100
|
+
delete(providerId: string, options?: AuthOperationOptions): Promise<void>;
|
|
101
|
+
}
|
|
102
|
+
/** Environment access for auth resolution. Injectable for tests and browsers. */
|
|
103
|
+
export interface AuthContext {
|
|
104
|
+
env(name: string): Promise<string | undefined>;
|
|
105
|
+
/** Check whether a file exists. Supports a leading `~`. Always false in browsers. */
|
|
106
|
+
fileExists(path: string): Promise<boolean>;
|
|
107
|
+
}
|
|
108
|
+
/** Result of resolving auth for a model. */
|
|
109
|
+
export interface AuthResult {
|
|
110
|
+
auth: ModelAuth;
|
|
111
|
+
/** Local stored-account id captured for this request; absent for ambient or explicit auth. */
|
|
112
|
+
accountId?: string;
|
|
113
|
+
/** Provider-scoped environment/config values resolved from credentials and ambient context. */
|
|
114
|
+
env?: ProviderEnv;
|
|
115
|
+
/** Human-readable label for status UI: "ANTHROPIC_API_KEY", "OAuth", "~/.aws/credentials". */
|
|
116
|
+
source?: string;
|
|
117
|
+
}
|
|
118
|
+
export interface AuthCheck {
|
|
119
|
+
source?: string;
|
|
120
|
+
type: "api_key" | "oauth";
|
|
121
|
+
}
|
|
122
|
+
export type AuthType = "api_key" | "oauth";
|
|
123
|
+
/**
|
|
124
|
+
* Prompt shown to the user during login. `signal` lets the flow cancel a
|
|
125
|
+
* pending prompt when an out-of-band event resolves the step, e.g. a
|
|
126
|
+
* `manual_code` prompt raced against a callback server, aborted when the
|
|
127
|
+
* callback wins.
|
|
128
|
+
*/
|
|
129
|
+
export type AuthPrompt = {
|
|
130
|
+
signal?: AbortSignal;
|
|
131
|
+
} & ({
|
|
132
|
+
type: "text";
|
|
133
|
+
message: string;
|
|
134
|
+
placeholder?: string;
|
|
135
|
+
} | {
|
|
136
|
+
type: "secret";
|
|
137
|
+
message: string;
|
|
138
|
+
placeholder?: string;
|
|
139
|
+
} | {
|
|
140
|
+
type: "select";
|
|
141
|
+
message: string;
|
|
142
|
+
options: readonly {
|
|
143
|
+
id: string;
|
|
144
|
+
label: string;
|
|
145
|
+
description?: string;
|
|
146
|
+
}[];
|
|
147
|
+
} | {
|
|
148
|
+
type: "manual_code";
|
|
149
|
+
message: string;
|
|
150
|
+
placeholder?: string;
|
|
151
|
+
});
|
|
152
|
+
export interface AuthInfoLink {
|
|
153
|
+
url: string;
|
|
154
|
+
label?: string;
|
|
155
|
+
}
|
|
156
|
+
export type AuthEvent = {
|
|
157
|
+
type: "info";
|
|
158
|
+
message: string;
|
|
159
|
+
links?: readonly AuthInfoLink[];
|
|
160
|
+
} | {
|
|
161
|
+
type: "auth_url";
|
|
162
|
+
url: string;
|
|
163
|
+
instructions?: string;
|
|
164
|
+
} | {
|
|
165
|
+
type: "device_code";
|
|
166
|
+
userCode: string;
|
|
167
|
+
verificationUri: string;
|
|
168
|
+
intervalSeconds?: number;
|
|
169
|
+
expiresInSeconds?: number;
|
|
170
|
+
/** Shown with the code for as long as the code is; a later event never replaces it. */
|
|
171
|
+
instructions?: string;
|
|
172
|
+
} | {
|
|
173
|
+
type: "progress";
|
|
174
|
+
message: string;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Login interaction callbacks serving both api-key and OAuth flows.
|
|
178
|
+
*
|
|
179
|
+
* `prompt()` returns the entered/selected string (`select` returns the option
|
|
180
|
+
* id). Rejects on cancel/abort. `signal` aborts the whole login flow;
|
|
181
|
+
* per-prompt cancellation uses `AuthPrompt.signal`.
|
|
182
|
+
*/
|
|
183
|
+
export interface AuthInteraction {
|
|
184
|
+
signal?: AbortSignal;
|
|
185
|
+
browser?: "host" | "elsewhere" | undefined;
|
|
186
|
+
prompt(prompt: AuthPrompt): Promise<string>;
|
|
187
|
+
notify(event: AuthEvent): void;
|
|
188
|
+
}
|
|
189
|
+
/** Normalized interaction passed to provider login implementations. */
|
|
190
|
+
export type ProviderAuthInteraction = AuthInteraction & {
|
|
191
|
+
signal: AbortSignal;
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* Api-key auth: stored key/provider env plus ambient sources (env vars, AWS
|
|
195
|
+
* profiles, ADC files). Ambient-only providers omit `login`.
|
|
196
|
+
*/
|
|
197
|
+
export interface ApiKeyAuth {
|
|
198
|
+
/** Display name, e.g. "Anthropic API key". */
|
|
199
|
+
name: string;
|
|
200
|
+
/** Interactive setup (prompt for key/provider env). Absent = ambient-only. */
|
|
201
|
+
login?(interaction: ProviderAuthInteraction): Promise<ApiKeyCredential>;
|
|
202
|
+
/**
|
|
203
|
+
* Optional side-effect-free availability check. Use this when `resolve()` may
|
|
204
|
+
* execute commands or perform other request-time work. Missing means Models
|
|
205
|
+
* checks availability by resolving auth.
|
|
206
|
+
*/
|
|
207
|
+
check?(input: {
|
|
208
|
+
ctx: AuthContext;
|
|
209
|
+
credential?: ApiKeyCredential;
|
|
210
|
+
signal: AbortSignal;
|
|
211
|
+
}): Promise<AuthCheck | undefined>;
|
|
212
|
+
/**
|
|
213
|
+
* Resolve auth from the stored credential and/or ambient sources, merging
|
|
214
|
+
* per field (`credential.key ?? env("...")`, `credential.env?.NAME ?? env("...")`).
|
|
215
|
+
* undefined = not configured. Resolution is provider-scoped; model-specific
|
|
216
|
+
* endpoint preparation happens after auth has been resolved.
|
|
217
|
+
*/
|
|
218
|
+
resolve(input: {
|
|
219
|
+
ctx: AuthContext;
|
|
220
|
+
credential?: ApiKeyCredential;
|
|
221
|
+
signal: AbortSignal;
|
|
222
|
+
}): Promise<AuthResult | undefined>;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* OAuth auth. The `refresh`/`toAuth` split lets `Models` own the locked
|
|
226
|
+
* refresh pattern: `refresh` produces a credential, `toAuth` derives request
|
|
227
|
+
* auth from whatever credential ends up stored.
|
|
228
|
+
*/
|
|
229
|
+
export interface OAuthAuth {
|
|
230
|
+
/** Display name, e.g. "Anthropic (Claude Pro/Max)". */
|
|
231
|
+
name: string;
|
|
232
|
+
/** Whether access through this auth method is backed by a provider subscription. */
|
|
233
|
+
isSubscription?: boolean;
|
|
234
|
+
/** Selector label for the OAuth login option, e.g. "Sign in with SuperGrok or X Premium". */
|
|
235
|
+
loginLabel?: string;
|
|
236
|
+
/** Availability of externally managed OAuth, without refreshing or importing its credentials. */
|
|
237
|
+
check?(input: {
|
|
238
|
+
ctx: AuthContext;
|
|
239
|
+
signal: AbortSignal;
|
|
240
|
+
}): Promise<AuthCheck | undefined>;
|
|
241
|
+
login(interaction: ProviderAuthInteraction): Promise<OAuthCredential>;
|
|
242
|
+
/**
|
|
243
|
+
* Exchange the refresh token. Network call; throws on failure
|
|
244
|
+
* (invalid_grant etc.). `Models` runs this under the store lock.
|
|
245
|
+
*/
|
|
246
|
+
refresh(credential: OAuthCredential, signal: AbortSignal): Promise<OAuthCredential>;
|
|
247
|
+
/**
|
|
248
|
+
* Side-effect-free derivation of request auth from a valid credential.
|
|
249
|
+
* Covers per-credential baseUrl (GitHub Copilot). Async so lazy wrappers
|
|
250
|
+
* can load the implementation on first use.
|
|
251
|
+
*/
|
|
252
|
+
toAuth(credential: OAuthCredential): Promise<ModelAuth>;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Provider auth. At least one of `apiKey`/`oauth` must be present: even
|
|
256
|
+
* ambient-credential providers and keyless local servers provide `apiKey`
|
|
257
|
+
* auth whose `resolve()` reports whether the provider is configured.
|
|
258
|
+
*/
|
|
259
|
+
export interface ProviderAuth {
|
|
260
|
+
apiKey?: ApiKeyAuth;
|
|
261
|
+
oauth?: OAuthAuth;
|
|
262
|
+
/**
|
|
263
|
+
* Prove resolved auth against the provider with one cheap, non-generating
|
|
264
|
+
* request. Network failures may throw; `Models.verifyAuth()` reports them as
|
|
265
|
+
* `unreachable`. Results must not carry secret material.
|
|
266
|
+
*/
|
|
267
|
+
verify?(input: {
|
|
268
|
+
auth: ModelAuth;
|
|
269
|
+
ctx: AuthContext;
|
|
270
|
+
signal: AbortSignal;
|
|
271
|
+
}): Promise<ProviderAuthVerification>;
|
|
272
|
+
}
|
|
273
|
+
export type AuthVerification = {
|
|
274
|
+
readonly ok: true;
|
|
275
|
+
readonly source: string;
|
|
276
|
+
/** False when a credential is present but no provider request proved it. */
|
|
277
|
+
readonly verified: boolean;
|
|
278
|
+
readonly detail?: string;
|
|
279
|
+
} | {
|
|
280
|
+
readonly ok: false;
|
|
281
|
+
readonly reason: "unconfigured" | "rejected" | "unreachable";
|
|
282
|
+
readonly message: string;
|
|
283
|
+
};
|
|
284
|
+
/** A provider's verdict; `Models.verifyAuth()` adds the credential source. */
|
|
285
|
+
export type ProviderAuthVerification = {
|
|
286
|
+
readonly ok: true;
|
|
287
|
+
readonly verified?: false;
|
|
288
|
+
readonly detail?: string;
|
|
289
|
+
} | Extract<AuthVerification, {
|
|
290
|
+
ok: false;
|
|
291
|
+
}>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ProviderHeaders } from "../types.ts";
|
|
2
|
+
import type { ProviderAuthVerification } from "./types.ts";
|
|
3
|
+
/**
|
|
4
|
+
* GET an authenticated endpoint and read the credential verdict from its
|
|
5
|
+
* status: 2xx accepts, 401/403 rejects, anything else leaves it unproven.
|
|
6
|
+
*/
|
|
7
|
+
export declare function verifyWithRequest(input: {
|
|
8
|
+
provider: string;
|
|
9
|
+
url: string;
|
|
10
|
+
headers: ProviderHeaders;
|
|
11
|
+
signal: AbortSignal;
|
|
12
|
+
detail?: (body: unknown) => string | undefined;
|
|
13
|
+
}): Promise<ProviderAuthVerification>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import"../chunks/account-limits-cache-b23sbrke.js";
|
|
2
|
+
import"../chunks/account-limits-cache-b0x2sfya.js";
|
|
3
|
+
import"../chunks/account-limits-cache-d1ypzqzp.js";
|
|
4
|
+
import"../chunks/account-limits-cache-8vzx8k6r.js";
|
|
5
|
+
import {
|
|
6
|
+
registerOAuthFlow2
|
|
7
|
+
} from "../chunks/account-limits-cache-v4n30az2.js";
|
|
8
|
+
import"../chunks/account-limits-cache-tc38g0ca.js";
|
|
9
|
+
import {
|
|
10
|
+
anthropicOAuth2
|
|
11
|
+
} from "../chunks/account-limits-cache-4fn5w63p.js";
|
|
12
|
+
import"../chunks/account-limits-cache-j2bt392s.js";
|
|
13
|
+
import"../chunks/account-limits-cache-4hptgd2h.js";
|
|
14
|
+
import {
|
|
15
|
+
openaiCodexOAuth2
|
|
16
|
+
} from "../chunks/account-limits-cache-xz65wyd1.js";
|
|
17
|
+
|
|
18
|
+
// src/bun-oauth.ts
|
|
19
|
+
function registerBunOAuthFlows() {
|
|
20
|
+
registerOAuthFlow2("anthropic", anthropicOAuth2);
|
|
21
|
+
registerOAuthFlow2("openaiCodex", openaiCodexOAuth2);
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
registerBunOAuthFlows
|
|
25
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API-key discovery from environment variables, per provider. Reports which
|
|
3
|
+
* variables are set (`findEnvKeys`) and resolves the key a request may use
|
|
4
|
+
* (`getEnvApiKey`); ANTHROPIC_AUTH_TOKEN is reported but never returned as an
|
|
5
|
+
* API key because requests must send it as a bearer token.
|
|
6
|
+
*/
|
|
7
|
+
import type { KnownProvider, ProviderEnv } from "./types.ts";
|
|
8
|
+
export declare const ANTHROPIC_AUTH_TOKEN_ENV = "ANTHROPIC_AUTH_TOKEN";
|
|
9
|
+
export declare const ANTHROPIC_OAUTH_TOKEN_ENV = "ANTHROPIC_OAUTH_TOKEN";
|
|
10
|
+
export declare const ANTHROPIC_API_KEY_ENV = "ANTHROPIC_API_KEY";
|
|
11
|
+
export declare const ANTHROPIC_FEDERATION_RULE_ID_ENV = "ANTHROPIC_FEDERATION_RULE_ID";
|
|
12
|
+
export declare const ANTHROPIC_ORGANIZATION_ID_ENV = "ANTHROPIC_ORGANIZATION_ID";
|
|
13
|
+
export declare const ANTHROPIC_SERVICE_ACCOUNT_ID_ENV = "ANTHROPIC_SERVICE_ACCOUNT_ID";
|
|
14
|
+
export declare const ANTHROPIC_IDENTITY_TOKEN_FILE_ENV = "ANTHROPIC_IDENTITY_TOKEN_FILE";
|
|
15
|
+
export declare const ANTHROPIC_WORKSPACE_ID_ENV = "ANTHROPIC_WORKSPACE_ID";
|
|
16
|
+
export declare const ANTHROPIC_ENV_KEYS: readonly ["ANTHROPIC_AUTH_TOKEN", "ANTHROPIC_OAUTH_TOKEN", "ANTHROPIC_API_KEY"];
|
|
17
|
+
/**
|
|
18
|
+
* Find configured environment variables that can provide an API key for a provider.
|
|
19
|
+
*
|
|
20
|
+
* This only reports actual API key variables. It intentionally excludes ambient
|
|
21
|
+
* credential sources such as AWS profiles, AWS IAM credentials, and Google
|
|
22
|
+
* Application Default Credentials.
|
|
23
|
+
*/
|
|
24
|
+
export declare function findEnvKeys(provider: KnownProvider, env?: ProviderEnv): string[] | undefined;
|
|
25
|
+
export declare function findEnvKeys(provider: string, env?: ProviderEnv): string[] | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Get API key for provider from known environment variables, e.g. OPENAI_API_KEY.
|
|
28
|
+
*
|
|
29
|
+
* Will not return API keys for providers that require OAuth tokens.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getEnvApiKey(provider: KnownProvider, env?: ProviderEnv): string | undefined;
|
|
32
|
+
export declare function getEnvApiKey(provider: string, env?: ProviderEnv): string | undefined;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ANTHROPIC_AUTH_TOKEN_ENV2,
|
|
3
|
+
ANTHROPIC_OAUTH_TOKEN_ENV2,
|
|
4
|
+
ANTHROPIC_API_KEY_ENV2,
|
|
5
|
+
ANTHROPIC_FEDERATION_RULE_ID_ENV2,
|
|
6
|
+
ANTHROPIC_ORGANIZATION_ID_ENV2,
|
|
7
|
+
ANTHROPIC_SERVICE_ACCOUNT_ID_ENV2,
|
|
8
|
+
ANTHROPIC_IDENTITY_TOKEN_FILE_ENV2,
|
|
9
|
+
ANTHROPIC_WORKSPACE_ID_ENV2,
|
|
10
|
+
ANTHROPIC_ENV_KEYS2,
|
|
11
|
+
findEnvKeys2,
|
|
12
|
+
getEnvApiKey2
|
|
13
|
+
} from "../chunks/account-limits-cache-hyzn1jmk.js";
|
|
14
|
+
import"../chunks/account-limits-cache-b23sbrke.js";
|
|
15
|
+
export {
|
|
16
|
+
ANTHROPIC_API_KEY_ENV2 as ANTHROPIC_API_KEY_ENV,
|
|
17
|
+
ANTHROPIC_AUTH_TOKEN_ENV2 as ANTHROPIC_AUTH_TOKEN_ENV,
|
|
18
|
+
ANTHROPIC_ENV_KEYS2 as ANTHROPIC_ENV_KEYS,
|
|
19
|
+
ANTHROPIC_FEDERATION_RULE_ID_ENV2 as ANTHROPIC_FEDERATION_RULE_ID_ENV,
|
|
20
|
+
ANTHROPIC_IDENTITY_TOKEN_FILE_ENV2 as ANTHROPIC_IDENTITY_TOKEN_FILE_ENV,
|
|
21
|
+
ANTHROPIC_OAUTH_TOKEN_ENV2 as ANTHROPIC_OAUTH_TOKEN_ENV,
|
|
22
|
+
ANTHROPIC_ORGANIZATION_ID_ENV2 as ANTHROPIC_ORGANIZATION_ID_ENV,
|
|
23
|
+
ANTHROPIC_SERVICE_ACCOUNT_ID_ENV2 as ANTHROPIC_SERVICE_ACCOUNT_ID_ENV,
|
|
24
|
+
ANTHROPIC_WORKSPACE_ID_ENV2 as ANTHROPIC_WORKSPACE_ID_ENV,
|
|
25
|
+
findEnvKeys2 as findEnvKeys,
|
|
26
|
+
getEnvApiKey2 as getEnvApiKey
|
|
27
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ModelsStore, ModelsStoreEntry, ModelsStoreOperationOptions } from "./models-store.ts";
|
|
2
|
+
export declare function defaultModelsStorePath(): string;
|
|
3
|
+
/**
|
|
4
|
+
* A catalog cache, not secrets: unreadable content reads as empty and heals
|
|
5
|
+
* on the next write. A malformed provider entry is ignored until a hosted
|
|
6
|
+
* refresh replaces it. A legacy pre-filtered entry serves its models without
|
|
7
|
+
* validators, so the next refresh fetches the full catalog.
|
|
8
|
+
*/
|
|
9
|
+
export declare class FileModelsStore implements ModelsStore {
|
|
10
|
+
private readonly path;
|
|
11
|
+
constructor(path?: string);
|
|
12
|
+
private load;
|
|
13
|
+
private rawCatalogs;
|
|
14
|
+
private save;
|
|
15
|
+
read(providerId: string, options?: ModelsStoreOperationOptions): Promise<ModelsStoreEntry | undefined>;
|
|
16
|
+
write(providerId: string, entry: ModelsStoreEntry, options?: ModelsStoreOperationOptions): Promise<void>;
|
|
17
|
+
delete(providerId: string, options?: ModelsStoreOperationOptions): Promise<void>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defaultModelsStorePath2,
|
|
3
|
+
FileModelsStore2
|
|
4
|
+
} from "../chunks/account-limits-cache-a55e14fr.js";
|
|
5
|
+
import"../chunks/account-limits-cache-rz8p1g5y.js";
|
|
6
|
+
export {
|
|
7
|
+
FileModelsStore2 as FileModelsStore,
|
|
8
|
+
defaultModelsStorePath2 as defaultModelsStorePath
|
|
9
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nyte-ai/ai: the provider layer. Side-effect free: provider factories and API
|
|
3
|
+
* implementations are exported explicitly below; nothing registers globally.
|
|
4
|
+
*/
|
|
5
|
+
export type { Static, TSchema } from "typebox";
|
|
6
|
+
export { Type } from "typebox";
|
|
7
|
+
export type { AnthropicEffort, AnthropicOptions, AnthropicThinkingDisplay, } from "./api/anthropic-messages.ts";
|
|
8
|
+
export * from "./api/deferred.ts";
|
|
9
|
+
export type { GoogleOptions } from "./api/google-generative-ai.ts";
|
|
10
|
+
export * from "./api/lazy.ts";
|
|
11
|
+
export { OpenAICodexCompactionError } from "./api/openai-codex-compaction-error.ts";
|
|
12
|
+
export type { OpenAICodexCompactResult } from "./api/openai-codex-compact.ts";
|
|
13
|
+
export type { OpenAICodexResponsesOptions } from "./api/openai-codex-protocol.ts";
|
|
14
|
+
export type { OpenAICompletionsOptions } from "./api/openai-completions-params.ts";
|
|
15
|
+
export type { OpenAIResponsesOptions } from "./api/openai-responses.ts";
|
|
16
|
+
export type { OpenAICompactResult } from "./api/openai-compact.ts";
|
|
17
|
+
export * from "./auth/context.ts";
|
|
18
|
+
export * from "./auth/credential-store.ts";
|
|
19
|
+
export * from "./auth/helpers.ts";
|
|
20
|
+
export * from "./auth/types.ts";
|
|
21
|
+
export { defaultAuthPath, FileCredentialStore } from "./auth/store.ts";
|
|
22
|
+
export { defaultModelsStorePath, FileModelsStore } from "./file-models-store.ts";
|
|
23
|
+
export { ModelsError, resolveProviderAuth, type AuthResolutionOverrides, type ModelsErrorCode, } from "./auth/resolve.ts";
|
|
24
|
+
export { anthropicOAuth } from "./auth/oauth/anthropic.ts";
|
|
25
|
+
export { githubCopilotOAuth, type GitHubCopilotOAuthOptions } from "./auth/oauth/github-copilot.ts";
|
|
26
|
+
export { getAccountId, openaiCodexOAuth } from "./auth/oauth/openai-codex.ts";
|
|
27
|
+
export { loadAnthropicOAuth, loadOpenAICodexOAuth } from "./auth/oauth/load.ts";
|
|
28
|
+
export { oauthErrorHtml, oauthSuccessHtml } from "./auth/oauth/oauth-page.ts";
|
|
29
|
+
export { generatePKCE } from "./auth/oauth/pkce.ts";
|
|
30
|
+
export { abortableSleep, pollOAuthDeviceCodeFlow, type OAuthDeviceCodePollOptions, type OAuthDeviceCodePollResult, } from "./auth/oauth/device-code.ts";
|
|
31
|
+
export * from "./env-api-keys.ts";
|
|
32
|
+
export * from "./models.ts";
|
|
33
|
+
export { getFastModeCostMultiplier } from "./model-pricing.ts";
|
|
34
|
+
export { baseModel, FAST_MODEL_SUFFIX, fastModelId, providerIdentity, supportsFastMode, withFastVariants, } from "./model-variants.ts";
|
|
35
|
+
export * from "./models-store.ts";
|
|
36
|
+
export * from "./prompt-cache.ts";
|
|
37
|
+
export * from "./session-resources.ts";
|
|
38
|
+
export * from "./types.ts";
|
|
39
|
+
export type { ApiOptionsMap, ApiStreamOptions } from "./api-options.ts";
|
|
40
|
+
export * from "./utils/diagnostics.ts";
|
|
41
|
+
export * from "./utils/estimate.ts";
|
|
42
|
+
export * from "./utils/event-stream.ts";
|
|
43
|
+
export * from "./utils/json-parse.ts";
|
|
44
|
+
export * from "./utils/failure.ts";
|
|
45
|
+
export * from "./utils/overflow.ts";
|
|
46
|
+
export * from "./utils/retry.ts";
|
|
47
|
+
export { contentText, getSystemMessageText, renderSystemMessageUpdate } from "./utils/text.ts";
|
|
48
|
+
export * from "./utils/transcript.ts";
|
|
49
|
+
export * from "./utils/typebox-helpers.ts";
|
|
50
|
+
export { uuidv7 } from "./utils/uuid.ts";
|
|
51
|
+
export * from "./utils/validation.ts";
|
|
52
|
+
export { anthropicProvider } from "./providers/anthropic.ts";
|
|
53
|
+
export { createNyteModels, defaultModelPerProvider, nyteProviders, } from "./providers/nyte-catalog.ts";
|
|
54
|
+
export { githubCopilotProvider } from "./providers/github-copilot.ts";
|
|
55
|
+
export { opencodeGoProvider } from "./providers/opencode-go.ts";
|
|
56
|
+
export { opencodeProvider } from "./providers/opencode.ts";
|
|
57
|
+
export { openaiProvider } from "./providers/openai.ts";
|
|
58
|
+
export { openaiCodexProvider } from "./providers/openai-codex.ts";
|
|
59
|
+
export { fetchOpenAICodexAccountLimits } from "./providers/openai-codex-limits.ts";
|
|
60
|
+
export { fetchAnthropicAccountLimits } from "./providers/anthropic-limits.ts";
|
|
61
|
+
export { openrouterProvider } from "./providers/openrouter.ts";
|
|
62
|
+
export { vercelAiGatewayProvider } from "./providers/vercel-ai-gateway.ts";
|