@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,295 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getProviderEnvValue2
|
|
3
|
+
} from "./account-limits-cache-b23sbrke.js";
|
|
4
|
+
import {
|
|
5
|
+
OAuthTokenResponseSchema2
|
|
6
|
+
} from "./account-limits-cache-b0x2sfya.js";
|
|
7
|
+
import {
|
|
8
|
+
parseAuthorizationInput2
|
|
9
|
+
} from "./account-limits-cache-d1ypzqzp.js";
|
|
10
|
+
import {
|
|
11
|
+
oauthSuccessHtml2,
|
|
12
|
+
oauthErrorHtml2
|
|
13
|
+
} from "./account-limits-cache-8vzx8k6r.js";
|
|
14
|
+
import {
|
|
15
|
+
registerOAuthFlow2
|
|
16
|
+
} from "./account-limits-cache-v4n30az2.js";
|
|
17
|
+
import {
|
|
18
|
+
generatePKCE2
|
|
19
|
+
} from "./account-limits-cache-tc38g0ca.js";
|
|
20
|
+
|
|
21
|
+
// src/auth/oauth/anthropic.ts
|
|
22
|
+
import { createServer } from "node:http";
|
|
23
|
+
import { Value } from "typebox/value";
|
|
24
|
+
var decode = (s) => atob(s);
|
|
25
|
+
var CLIENT_ID = decode("OWQxYzI1MGEtZTYxYi00NGQ5LTg4ZWQtNTk0NGQxOTYyZjVl");
|
|
26
|
+
var AUTHORIZE_URL = "https://claude.ai/oauth/authorize";
|
|
27
|
+
var TOKEN_URL = "https://platform.claude.com/v1/oauth/token";
|
|
28
|
+
var CALLBACK_HOST = getProviderEnvValue2("NYTE_OAUTH_CALLBACK_HOST") || "127.0.0.1";
|
|
29
|
+
var CALLBACK_PORT = 53692;
|
|
30
|
+
var CALLBACK_PATH = "/callback";
|
|
31
|
+
var REDIRECT_URI = `http://localhost:${CALLBACK_PORT}${CALLBACK_PATH}`;
|
|
32
|
+
var COPY_CODE_REDIRECT_URI = "https://platform.claude.com/oauth/code/callback";
|
|
33
|
+
var SCOPES = "org:create_api_key user:profile user:inference user:sessions:claude_code user:mcp_servers user:file_upload";
|
|
34
|
+
function formatErrorDetails(cause) {
|
|
35
|
+
if (cause instanceof Error) {
|
|
36
|
+
const details = [`${cause.name}: ${cause.message}`];
|
|
37
|
+
if ("code" in cause && cause.code)
|
|
38
|
+
details.push(`code=${String(cause.code)}`);
|
|
39
|
+
if ("errno" in cause && cause.errno !== undefined)
|
|
40
|
+
details.push(`errno=${String(cause.errno)}`);
|
|
41
|
+
if (cause.cause !== undefined) {
|
|
42
|
+
details.push(`cause=${formatErrorDetails(cause.cause)}`);
|
|
43
|
+
}
|
|
44
|
+
if (cause.stack) {
|
|
45
|
+
details.push(`stack=${cause.stack}`);
|
|
46
|
+
}
|
|
47
|
+
return details.join("; ");
|
|
48
|
+
}
|
|
49
|
+
return String(cause);
|
|
50
|
+
}
|
|
51
|
+
async function startCallbackServer(expectedState) {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
let settleWait;
|
|
54
|
+
const waitForCodePromise = new Promise((resolveWait, rejectWait) => {
|
|
55
|
+
let settled = false;
|
|
56
|
+
settleWait = (value) => {
|
|
57
|
+
if (settled)
|
|
58
|
+
return;
|
|
59
|
+
settled = true;
|
|
60
|
+
if (value instanceof Error)
|
|
61
|
+
rejectWait(value);
|
|
62
|
+
else
|
|
63
|
+
resolveWait(value);
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
waitForCodePromise.catch(() => {
|
|
67
|
+
return;
|
|
68
|
+
});
|
|
69
|
+
const server = createServer((req, res) => {
|
|
70
|
+
try {
|
|
71
|
+
const url = new URL(req.url || "", "http://localhost");
|
|
72
|
+
if (req.method !== "GET" || url.pathname !== CALLBACK_PATH) {
|
|
73
|
+
res.writeHead(404, { "Content-Type": "text/html; charset=utf-8" });
|
|
74
|
+
res.end(oauthErrorHtml2("Nyte is not listening on this path. Run the login command again to retry."));
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const code = url.searchParams.get("code");
|
|
78
|
+
const state = url.searchParams.get("state");
|
|
79
|
+
const error = url.searchParams.get("error");
|
|
80
|
+
if (state !== expectedState) {
|
|
81
|
+
res.writeHead(400, { "Content-Type": "text/html; charset=utf-8" });
|
|
82
|
+
res.end(oauthErrorHtml2("The callback's state did not match this login attempt, so Nyte ignored it."));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (error) {
|
|
86
|
+
const description = url.searchParams.get("error_description") ?? error;
|
|
87
|
+
res.writeHead(400, { "Content-Type": "text/html; charset=utf-8" });
|
|
88
|
+
res.end(oauthErrorHtml2("Anthropic sent back an error instead of a code. Run the login command again to retry.", `Error: ${description}`));
|
|
89
|
+
settleWait?.(new Error(`Anthropic authorization failed: ${description}`));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (!code) {
|
|
93
|
+
res.writeHead(400, { "Content-Type": "text/html; charset=utf-8" });
|
|
94
|
+
res.end(oauthErrorHtml2("The callback arrived without a code, so Nyte could not finish sign-in."));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
98
|
+
res.end(oauthSuccessHtml2({ provider: "Anthropic" }));
|
|
99
|
+
settleWait?.({ code, state });
|
|
100
|
+
} catch {
|
|
101
|
+
res.writeHead(500, { "Content-Type": "text/plain; charset=utf-8" });
|
|
102
|
+
res.end("Internal error");
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
server.on("error", (err) => {
|
|
106
|
+
reject(err);
|
|
107
|
+
});
|
|
108
|
+
server.listen(CALLBACK_PORT, CALLBACK_HOST, () => {
|
|
109
|
+
resolve({
|
|
110
|
+
server,
|
|
111
|
+
redirectUri: REDIRECT_URI,
|
|
112
|
+
cancelWait: () => {
|
|
113
|
+
settleWait?.(null);
|
|
114
|
+
},
|
|
115
|
+
failWait: (error) => {
|
|
116
|
+
settleWait?.(error);
|
|
117
|
+
},
|
|
118
|
+
waitForCode: () => waitForCodePromise
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
async function postJson(url, body, signal) {
|
|
124
|
+
const response = await fetch(url, {
|
|
125
|
+
method: "POST",
|
|
126
|
+
headers: {
|
|
127
|
+
"Content-Type": "application/json",
|
|
128
|
+
Accept: "application/json"
|
|
129
|
+
},
|
|
130
|
+
body: JSON.stringify(body),
|
|
131
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(30000)])
|
|
132
|
+
});
|
|
133
|
+
const responseBody = await response.text();
|
|
134
|
+
if (!response.ok) {
|
|
135
|
+
throw new Error(`HTTP request failed. status=${response.status}; url=${url}; body=${responseBody}`);
|
|
136
|
+
}
|
|
137
|
+
return responseBody;
|
|
138
|
+
}
|
|
139
|
+
async function exchangeAuthorizationCode(code, state, verifier, redirectUri, signal) {
|
|
140
|
+
let responseBody;
|
|
141
|
+
try {
|
|
142
|
+
responseBody = await postJson(TOKEN_URL, {
|
|
143
|
+
grant_type: "authorization_code",
|
|
144
|
+
client_id: CLIENT_ID,
|
|
145
|
+
code,
|
|
146
|
+
state,
|
|
147
|
+
redirect_uri: redirectUri,
|
|
148
|
+
code_verifier: verifier
|
|
149
|
+
}, signal);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
throw new Error(`Token exchange request failed. url=${TOKEN_URL}; redirect_uri=${redirectUri}; response_type=authorization_code; details=${formatErrorDetails(error)}`);
|
|
152
|
+
}
|
|
153
|
+
let tokenData;
|
|
154
|
+
try {
|
|
155
|
+
tokenData = JSON.parse(responseBody);
|
|
156
|
+
} catch (error) {
|
|
157
|
+
throw new Error(`Token exchange returned invalid JSON. url=${TOKEN_URL}; body=${responseBody}; details=${formatErrorDetails(error)}`);
|
|
158
|
+
}
|
|
159
|
+
if (!Value.Check(OAuthTokenResponseSchema2, tokenData)) {
|
|
160
|
+
throw new Error(`Token exchange returned an incomplete token response. url=${TOKEN_URL}`);
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
type: "oauth",
|
|
164
|
+
refresh: tokenData.refresh_token,
|
|
165
|
+
access: tokenData.access_token,
|
|
166
|
+
expires: Date.now() + tokenData.expires_in * 1000 - 5 * 60 * 1000
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
async function loginAnthropic(interaction, method) {
|
|
170
|
+
const { verifier, challenge } = await generatePKCE2();
|
|
171
|
+
const redirectUri = method === "copy_code" ? COPY_CODE_REDIRECT_URI : REDIRECT_URI;
|
|
172
|
+
const server = method === "browser" ? await startCallbackServer(verifier).catch(() => {
|
|
173
|
+
return;
|
|
174
|
+
}) : undefined;
|
|
175
|
+
const manualAbort = new AbortController;
|
|
176
|
+
const onAbort = () => {
|
|
177
|
+
server?.failWait(new Error("Login cancelled"));
|
|
178
|
+
manualAbort.abort();
|
|
179
|
+
server?.server.close();
|
|
180
|
+
};
|
|
181
|
+
interaction.signal.addEventListener("abort", onAbort, { once: true });
|
|
182
|
+
if (interaction.signal.aborted)
|
|
183
|
+
onAbort();
|
|
184
|
+
let manualInput;
|
|
185
|
+
let manualError;
|
|
186
|
+
try {
|
|
187
|
+
if (interaction.signal.aborted)
|
|
188
|
+
throw new Error("Login cancelled");
|
|
189
|
+
const authParams = new URLSearchParams({
|
|
190
|
+
code: "true",
|
|
191
|
+
client_id: CLIENT_ID,
|
|
192
|
+
response_type: "code",
|
|
193
|
+
redirect_uri: redirectUri,
|
|
194
|
+
scope: SCOPES,
|
|
195
|
+
code_challenge: challenge,
|
|
196
|
+
code_challenge_method: "S256",
|
|
197
|
+
state: verifier
|
|
198
|
+
});
|
|
199
|
+
interaction.notify({
|
|
200
|
+
type: "auth_url",
|
|
201
|
+
url: `${AUTHORIZE_URL}?${authParams.toString()}`,
|
|
202
|
+
instructions: method === "copy_code" ? "Complete login in your browser, then copy the code Anthropic shows and paste it here." : "Complete login in your browser. If the browser is on another machine, paste the final redirect URL here."
|
|
203
|
+
});
|
|
204
|
+
const manualPromise = interaction.prompt({
|
|
205
|
+
type: "manual_code",
|
|
206
|
+
message: method === "copy_code" ? "Paste the code Anthropic shows after you sign in:" : "Complete login in your browser, or paste the authorization code / redirect URL here:",
|
|
207
|
+
placeholder: method === "copy_code" ? "code#state" : REDIRECT_URI,
|
|
208
|
+
signal: manualAbort.signal
|
|
209
|
+
}).then((input) => {
|
|
210
|
+
manualInput = input;
|
|
211
|
+
server?.cancelWait();
|
|
212
|
+
}).catch((error) => {
|
|
213
|
+
manualError = error instanceof Error ? error : new Error(String(error));
|
|
214
|
+
server?.cancelWait();
|
|
215
|
+
});
|
|
216
|
+
const result = await server?.waitForCode();
|
|
217
|
+
if (!result)
|
|
218
|
+
await manualPromise;
|
|
219
|
+
if (interaction.signal.aborted)
|
|
220
|
+
throw new Error("Login cancelled");
|
|
221
|
+
if (manualError)
|
|
222
|
+
throw manualError;
|
|
223
|
+
const parsed = result ?? parseAuthorizationInput2(manualInput ?? "");
|
|
224
|
+
if (parsed.state && parsed.state !== verifier)
|
|
225
|
+
throw new Error("OAuth state mismatch");
|
|
226
|
+
if (!parsed.code)
|
|
227
|
+
throw new Error("Missing authorization code");
|
|
228
|
+
interaction.notify({
|
|
229
|
+
type: "progress",
|
|
230
|
+
message: "Exchanging authorization code for tokens..."
|
|
231
|
+
});
|
|
232
|
+
return exchangeAuthorizationCode(parsed.code, parsed.state ?? verifier, verifier, redirectUri, interaction.signal);
|
|
233
|
+
} finally {
|
|
234
|
+
interaction.signal.removeEventListener("abort", onAbort);
|
|
235
|
+
manualAbort.abort();
|
|
236
|
+
server?.server.close();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
async function refreshAnthropicToken(refreshToken, signal) {
|
|
240
|
+
let responseBody;
|
|
241
|
+
try {
|
|
242
|
+
responseBody = await postJson(TOKEN_URL, {
|
|
243
|
+
grant_type: "refresh_token",
|
|
244
|
+
client_id: CLIENT_ID,
|
|
245
|
+
refresh_token: refreshToken
|
|
246
|
+
}, signal);
|
|
247
|
+
} catch (error) {
|
|
248
|
+
throw new Error(`Anthropic token refresh request failed. url=${TOKEN_URL}; details=${formatErrorDetails(error)}`);
|
|
249
|
+
}
|
|
250
|
+
let data;
|
|
251
|
+
try {
|
|
252
|
+
data = JSON.parse(responseBody);
|
|
253
|
+
} catch (error) {
|
|
254
|
+
throw new Error(`Anthropic token refresh returned invalid JSON. url=${TOKEN_URL}; body=${responseBody}; details=${formatErrorDetails(error)}`);
|
|
255
|
+
}
|
|
256
|
+
if (!Value.Check(OAuthTokenResponseSchema2, data)) {
|
|
257
|
+
throw new Error(`Anthropic token refresh returned an incomplete token response. url=${TOKEN_URL}`);
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
type: "oauth",
|
|
261
|
+
refresh: data.refresh_token,
|
|
262
|
+
access: data.access_token,
|
|
263
|
+
expires: Date.now() + data.expires_in * 1000 - 5 * 60 * 1000
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
var anthropicOAuth2 = {
|
|
267
|
+
name: "Anthropic (Claude Pro/Max)",
|
|
268
|
+
isSubscription: true,
|
|
269
|
+
async login(interaction) {
|
|
270
|
+
if (interaction.signal.aborted)
|
|
271
|
+
throw new Error("Login cancelled");
|
|
272
|
+
const method = interaction.browser === "host" ? "browser" : interaction.browser === "elsewhere" ? "copy_code" : await interaction.prompt({
|
|
273
|
+
type: "select",
|
|
274
|
+
message: "Select Anthropic login method:",
|
|
275
|
+
options: [
|
|
276
|
+
{ id: "browser", label: "Browser login (default)" },
|
|
277
|
+
{ id: "copy_code", label: "Copy code login (headless)" }
|
|
278
|
+
],
|
|
279
|
+
signal: interaction.signal
|
|
280
|
+
});
|
|
281
|
+
if (interaction.signal.aborted)
|
|
282
|
+
throw new Error("Login cancelled");
|
|
283
|
+
if (method !== "browser" && method !== "copy_code") {
|
|
284
|
+
throw new Error(`Unknown Anthropic login method: ${method}`);
|
|
285
|
+
}
|
|
286
|
+
return loginAnthropic(interaction, method);
|
|
287
|
+
},
|
|
288
|
+
refresh: (credential, signal) => refreshAnthropicToken(credential.refresh, signal),
|
|
289
|
+
async toAuth(credential) {
|
|
290
|
+
return { apiKey: credential.access };
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
registerOAuthFlow2("anthropic", anthropicOAuth2);
|
|
294
|
+
|
|
295
|
+
export { anthropicOAuth2 };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
sleep2
|
|
3
|
+
} from "./account-limits-cache-j2bt392s.js";
|
|
4
|
+
|
|
5
|
+
// src/auth/oauth/device-code.ts
|
|
6
|
+
var CANCEL_MESSAGE = "Login cancelled";
|
|
7
|
+
var TIMEOUT_MESSAGE = "Device flow timed out";
|
|
8
|
+
var SLOW_DOWN_TIMEOUT_MESSAGE = "Device flow timed out after one or more slow_down responses. This is often caused by clock drift in WSL or VM environments. Please sync or restart the VM clock and try again.";
|
|
9
|
+
var MINIMUM_INTERVAL_MS = 1000;
|
|
10
|
+
var DEFAULT_POLL_INTERVAL_SECONDS = 5;
|
|
11
|
+
var SLOW_DOWN_INTERVAL_INCREMENT_MS = 5000;
|
|
12
|
+
function abortableSleep3(ms, signal, cancelMessage) {
|
|
13
|
+
return sleep2(ms, signal, () => new Error(cancelMessage));
|
|
14
|
+
}
|
|
15
|
+
async function pollOAuthDeviceCodeFlow2(options) {
|
|
16
|
+
const deadline = options.expiresInSeconds !== undefined ? Date.now() + options.expiresInSeconds * 1000 : Number.POSITIVE_INFINITY;
|
|
17
|
+
let intervalMs = Math.max(MINIMUM_INTERVAL_MS, Math.floor((options.intervalSeconds ?? DEFAULT_POLL_INTERVAL_SECONDS) * 1000));
|
|
18
|
+
let slowDownResponses = 0;
|
|
19
|
+
if (options.waitBeforeFirstPoll) {
|
|
20
|
+
const remainingMs = deadline - Date.now();
|
|
21
|
+
if (remainingMs > 0) {
|
|
22
|
+
await abortableSleep3(Math.min(intervalMs, remainingMs), options.signal, CANCEL_MESSAGE);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
while (Date.now() < deadline) {
|
|
26
|
+
if (options.signal.aborted) {
|
|
27
|
+
throw new Error(CANCEL_MESSAGE);
|
|
28
|
+
}
|
|
29
|
+
const result = await options.poll();
|
|
30
|
+
if (result.status === "complete") {
|
|
31
|
+
return result.value;
|
|
32
|
+
}
|
|
33
|
+
if (result.status === "failed") {
|
|
34
|
+
throw new Error(result.message);
|
|
35
|
+
}
|
|
36
|
+
if (result.status === "slow_down") {
|
|
37
|
+
slowDownResponses += 1;
|
|
38
|
+
intervalMs = result.intervalSeconds !== undefined && Number.isFinite(result.intervalSeconds) && result.intervalSeconds > 0 ? Math.max(MINIMUM_INTERVAL_MS, Math.floor(result.intervalSeconds * 1000)) : Math.max(MINIMUM_INTERVAL_MS, intervalMs + SLOW_DOWN_INTERVAL_INCREMENT_MS);
|
|
39
|
+
}
|
|
40
|
+
const remainingMs = deadline - Date.now();
|
|
41
|
+
if (remainingMs <= 0) {
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
await abortableSleep3(Math.min(intervalMs, remainingMs), options.signal, CANCEL_MESSAGE);
|
|
45
|
+
}
|
|
46
|
+
throw new Error(slowDownResponses > 0 ? SLOW_DOWN_TIMEOUT_MESSAGE : TIMEOUT_MESSAGE);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { abortableSleep3, pollOAuthDeviceCodeFlow2 };
|