@gajae-code/ai 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2644 -0
- package/README.md +1181 -0
- package/dist/types/api-registry.d.ts +30 -0
- package/dist/types/auth-broker/client.d.ts +66 -0
- package/dist/types/auth-broker/index.d.ts +5 -0
- package/dist/types/auth-broker/refresher.d.ts +25 -0
- package/dist/types/auth-broker/remote-store.d.ts +96 -0
- package/dist/types/auth-broker/server.d.ts +32 -0
- package/dist/types/auth-broker/types.d.ts +105 -0
- package/dist/types/auth-broker/wire-schemas.d.ts +412 -0
- package/dist/types/auth-gateway/http.d.ts +39 -0
- package/dist/types/auth-gateway/index.d.ts +3 -0
- package/dist/types/auth-gateway/server.d.ts +17 -0
- package/dist/types/auth-gateway/types.d.ts +115 -0
- package/dist/types/auth-storage.d.ts +641 -0
- package/dist/types/cli.d.ts +2 -0
- package/dist/types/index.d.ts +49 -0
- package/dist/types/model-cache.d.ts +17 -0
- package/dist/types/model-manager.d.ts +62 -0
- package/dist/types/model-thinking.d.ts +71 -0
- package/dist/types/models.d.ts +12 -0
- package/dist/types/provider-details.d.ts +24 -0
- package/dist/types/provider-models/bundled-references.d.ts +4 -0
- package/dist/types/provider-models/descriptors.d.ts +48 -0
- package/dist/types/provider-models/google.d.ts +20 -0
- package/dist/types/provider-models/index.d.ts +5 -0
- package/dist/types/provider-models/ollama.d.ts +7 -0
- package/dist/types/provider-models/openai-compat.d.ts +237 -0
- package/dist/types/provider-models/special.d.ts +16 -0
- package/dist/types/providers/amazon-bedrock.d.ts +36 -0
- package/dist/types/providers/anthropic-messages-server-schema.d.ts +450 -0
- package/dist/types/providers/anthropic-messages-server.d.ts +17 -0
- package/dist/types/providers/anthropic.d.ts +188 -0
- package/dist/types/providers/aws-credentials.d.ts +43 -0
- package/dist/types/providers/aws-eventstream.d.ts +38 -0
- package/dist/types/providers/aws-sigv4.d.ts +55 -0
- package/dist/types/providers/azure-openai-responses.d.ts +15 -0
- package/dist/types/providers/cursor/gen/agent_pb.d.ts +13022 -0
- package/dist/types/providers/cursor.d.ts +42 -0
- package/dist/types/providers/error-message.d.ts +27 -0
- package/dist/types/providers/github-copilot-headers.d.ts +40 -0
- package/dist/types/providers/gitlab-duo.d.ts +27 -0
- package/dist/types/providers/google-auth.d.ts +24 -0
- package/dist/types/providers/google-gemini-cli.d.ts +72 -0
- package/dist/types/providers/google-gemini-headers.d.ts +18 -0
- package/dist/types/providers/google-shared.d.ts +163 -0
- package/dist/types/providers/google-types.d.ts +138 -0
- package/dist/types/providers/google-vertex.d.ts +7 -0
- package/dist/types/providers/google.d.ts +4 -0
- package/dist/types/providers/grammar.d.ts +1 -0
- package/dist/types/providers/kimi.d.ts +27 -0
- package/dist/types/providers/mock.d.ts +175 -0
- package/dist/types/providers/ollama.d.ts +6 -0
- package/dist/types/providers/openai-anthropic-shim.d.ts +31 -0
- package/dist/types/providers/openai-chat-server-schema.d.ts +814 -0
- package/dist/types/providers/openai-chat-server.d.ts +16 -0
- package/dist/types/providers/openai-codex/constants.d.ts +26 -0
- package/dist/types/providers/openai-codex/request-transformer.d.ts +49 -0
- package/dist/types/providers/openai-codex/response-handler.d.ts +17 -0
- package/dist/types/providers/openai-codex-responses.d.ts +67 -0
- package/dist/types/providers/openai-completions-compat.d.ts +25 -0
- package/dist/types/providers/openai-completions.d.ts +33 -0
- package/dist/types/providers/openai-responses-server-schema.d.ts +392 -0
- package/dist/types/providers/openai-responses-server.d.ts +17 -0
- package/dist/types/providers/openai-responses-shared.d.ts +89 -0
- package/dist/types/providers/openai-responses.d.ts +32 -0
- package/dist/types/providers/pi-native-client.d.ts +13 -0
- package/dist/types/providers/pi-native-server.d.ts +68 -0
- package/dist/types/providers/register-builtins.d.ts +31 -0
- package/dist/types/providers/synthetic.d.ts +26 -0
- package/dist/types/providers/transform-messages.d.ts +12 -0
- package/dist/types/providers/vision-guard.d.ts +8 -0
- package/dist/types/rate-limit-utils.d.ts +19 -0
- package/dist/types/stream.d.ts +24 -0
- package/dist/types/types.d.ts +746 -0
- package/dist/types/usage/claude.d.ts +3 -0
- package/dist/types/usage/gemini.d.ts +2 -0
- package/dist/types/usage/github-copilot.d.ts +7 -0
- package/dist/types/usage/google-antigravity.d.ts +2 -0
- package/dist/types/usage/kimi.d.ts +2 -0
- package/dist/types/usage/minimax-code.d.ts +2 -0
- package/dist/types/usage/openai-codex.d.ts +3 -0
- package/dist/types/usage/shared.d.ts +1 -0
- package/dist/types/usage/zai.d.ts +2 -0
- package/dist/types/usage.d.ts +258 -0
- package/dist/types/utils/abort.d.ts +19 -0
- package/dist/types/utils/anthropic-auth.d.ts +31 -0
- package/dist/types/utils/discovery/antigravity.d.ts +61 -0
- package/dist/types/utils/discovery/codex.d.ts +38 -0
- package/dist/types/utils/discovery/cursor.d.ts +23 -0
- package/dist/types/utils/discovery/gemini.d.ts +25 -0
- package/dist/types/utils/discovery/index.d.ts +4 -0
- package/dist/types/utils/discovery/openai-compatible.d.ts +72 -0
- package/dist/types/utils/event-stream.d.ts +28 -0
- package/dist/types/utils/fireworks-model-id.d.ts +10 -0
- package/dist/types/utils/foundry.d.ts +1 -0
- package/dist/types/utils/h2-fetch.d.ts +22 -0
- package/dist/types/utils/http-inspector.d.ts +31 -0
- package/dist/types/utils/idle-iterator.d.ts +67 -0
- package/dist/types/utils/json-parse.d.ts +10 -0
- package/dist/types/utils/oauth/alibaba-coding-plan.d.ts +18 -0
- package/dist/types/utils/oauth/anthropic.d.ts +22 -0
- package/dist/types/utils/oauth/api-key-login.d.ts +35 -0
- package/dist/types/utils/oauth/api-key-validation.d.ts +27 -0
- package/dist/types/utils/oauth/callback-server.d.ts +57 -0
- package/dist/types/utils/oauth/cerebras.d.ts +1 -0
- package/dist/types/utils/oauth/cloudflare-ai-gateway.d.ts +18 -0
- package/dist/types/utils/oauth/cursor.d.ts +15 -0
- package/dist/types/utils/oauth/deepseek.d.ts +10 -0
- package/dist/types/utils/oauth/firepass.d.ts +1 -0
- package/dist/types/utils/oauth/fireworks.d.ts +1 -0
- package/dist/types/utils/oauth/github-copilot.d.ts +38 -0
- package/dist/types/utils/oauth/gitlab-duo.d.ts +3 -0
- package/dist/types/utils/oauth/google-antigravity.d.ts +11 -0
- package/dist/types/utils/oauth/google-gemini-cli.d.ts +10 -0
- package/dist/types/utils/oauth/google-oauth-shared.d.ts +28 -0
- package/dist/types/utils/oauth/huggingface.d.ts +19 -0
- package/dist/types/utils/oauth/index.d.ts +38 -0
- package/dist/types/utils/oauth/kagi.d.ts +17 -0
- package/dist/types/utils/oauth/kilo.d.ts +5 -0
- package/dist/types/utils/oauth/kimi.d.ts +21 -0
- package/dist/types/utils/oauth/litellm.d.ts +18 -0
- package/dist/types/utils/oauth/lm-studio.d.ts +17 -0
- package/dist/types/utils/oauth/minimax-code.d.ts +28 -0
- package/dist/types/utils/oauth/moonshot.d.ts +1 -0
- package/dist/types/utils/oauth/nanogpt.d.ts +1 -0
- package/dist/types/utils/oauth/nvidia.d.ts +18 -0
- package/dist/types/utils/oauth/ollama-cloud.d.ts +2 -0
- package/dist/types/utils/oauth/ollama.d.ts +18 -0
- package/dist/types/utils/oauth/openai-codex.d.ts +21 -0
- package/dist/types/utils/oauth/opencode.d.ts +18 -0
- package/dist/types/utils/oauth/parallel.d.ts +17 -0
- package/dist/types/utils/oauth/perplexity.d.ts +9 -0
- package/dist/types/utils/oauth/pkce.d.ts +8 -0
- package/dist/types/utils/oauth/qianfan.d.ts +17 -0
- package/dist/types/utils/oauth/qwen-portal.d.ts +19 -0
- package/dist/types/utils/oauth/synthetic.d.ts +1 -0
- package/dist/types/utils/oauth/tavily.d.ts +17 -0
- package/dist/types/utils/oauth/together.d.ts +1 -0
- package/dist/types/utils/oauth/types.d.ts +44 -0
- package/dist/types/utils/oauth/venice.d.ts +18 -0
- package/dist/types/utils/oauth/vercel-ai-gateway.d.ts +18 -0
- package/dist/types/utils/oauth/vllm.d.ts +16 -0
- package/dist/types/utils/oauth/xiaomi.d.ts +19 -0
- package/dist/types/utils/oauth/zai.d.ts +18 -0
- package/dist/types/utils/oauth/zenmux.d.ts +1 -0
- package/dist/types/utils/overflow.d.ts +54 -0
- package/dist/types/utils/parse-bind.d.ts +23 -0
- package/dist/types/utils/provider-response.d.ts +3 -0
- package/dist/types/utils/retry-after.d.ts +3 -0
- package/dist/types/utils/retry.d.ts +26 -0
- package/dist/types/utils/schema/adapt.d.ts +24 -0
- package/dist/types/utils/schema/compatibility.d.ts +30 -0
- package/dist/types/utils/schema/dereference.d.ts +11 -0
- package/dist/types/utils/schema/draft.d.ts +10 -0
- package/dist/types/utils/schema/equality.d.ts +4 -0
- package/dist/types/utils/schema/fields.d.ts +49 -0
- package/dist/types/utils/schema/index.d.ts +13 -0
- package/dist/types/utils/schema/json-schema-validator.d.ts +12 -0
- package/dist/types/utils/schema/meta-validator.d.ts +2 -0
- package/dist/types/utils/schema/normalize.d.ts +93 -0
- package/dist/types/utils/schema/spill.d.ts +8 -0
- package/dist/types/utils/schema/stamps.d.ts +25 -0
- package/dist/types/utils/schema/types.d.ts +4 -0
- package/dist/types/utils/schema/wire.d.ts +54 -0
- package/dist/types/utils/schema/zod-decontaminate.d.ts +31 -0
- package/dist/types/utils/sse-debug.d.ts +10 -0
- package/dist/types/utils/tool-call-healing.d.ts +71 -0
- package/dist/types/utils/tool-choice.d.ts +50 -0
- package/dist/types/utils/validation.d.ts +17 -0
- package/dist/types/utils.d.ts +28 -0
- package/package.json +146 -0
- package/src/api-registry.ts +96 -0
- package/src/auth-broker/client.ts +358 -0
- package/src/auth-broker/index.ts +5 -0
- package/src/auth-broker/refresher.ts +127 -0
- package/src/auth-broker/remote-store.ts +623 -0
- package/src/auth-broker/server.ts +644 -0
- package/src/auth-broker/types.ts +127 -0
- package/src/auth-broker/wire-schemas.ts +200 -0
- package/src/auth-gateway/http.ts +194 -0
- package/src/auth-gateway/index.ts +3 -0
- package/src/auth-gateway/server.ts +717 -0
- package/src/auth-gateway/types.ts +134 -0
- package/src/auth-storage.ts +4104 -0
- package/src/cli.ts +262 -0
- package/src/index.ts +54 -0
- package/src/model-cache.ts +129 -0
- package/src/model-manager.ts +450 -0
- package/src/model-thinking.ts +691 -0
- package/src/models.json +73853 -0
- package/src/models.json.d.ts +9 -0
- package/src/models.ts +56 -0
- package/src/prompts/turn-aborted-guidance.md +4 -0
- package/src/provider-details.ts +90 -0
- package/src/provider-models/bundled-references.ts +38 -0
- package/src/provider-models/descriptors.ts +308 -0
- package/src/provider-models/google.ts +91 -0
- package/src/provider-models/index.ts +5 -0
- package/src/provider-models/ollama.ts +153 -0
- package/src/provider-models/openai-compat.ts +2275 -0
- package/src/provider-models/special.ts +67 -0
- package/src/providers/amazon-bedrock.ts +849 -0
- package/src/providers/anthropic-messages-server-schema.ts +229 -0
- package/src/providers/anthropic-messages-server.ts +677 -0
- package/src/providers/anthropic.ts +2696 -0
- package/src/providers/aws-credentials.ts +501 -0
- package/src/providers/aws-eventstream.ts +185 -0
- package/src/providers/aws-sigv4.ts +218 -0
- package/src/providers/azure-openai-responses.ts +337 -0
- package/src/providers/cursor/gen/agent_pb.ts +15274 -0
- package/src/providers/cursor/proto/agent.proto +3526 -0
- package/src/providers/cursor/proto/buf.gen.yaml +6 -0
- package/src/providers/cursor/proto/buf.yaml +17 -0
- package/src/providers/cursor.ts +2561 -0
- package/src/providers/error-message.ts +21 -0
- package/src/providers/github-copilot-headers.ts +140 -0
- package/src/providers/gitlab-duo.ts +372 -0
- package/src/providers/google-auth.ts +252 -0
- package/src/providers/google-gemini-cli.ts +795 -0
- package/src/providers/google-gemini-headers.ts +41 -0
- package/src/providers/google-shared.ts +902 -0
- package/src/providers/google-types.ts +167 -0
- package/src/providers/google-vertex.ts +88 -0
- package/src/providers/google.ts +41 -0
- package/src/providers/grammar.ts +70 -0
- package/src/providers/kimi.ts +52 -0
- package/src/providers/mock.ts +500 -0
- package/src/providers/ollama.ts +544 -0
- package/src/providers/openai-anthropic-shim.ts +138 -0
- package/src/providers/openai-chat-server-schema.ts +243 -0
- package/src/providers/openai-chat-server.ts +628 -0
- package/src/providers/openai-codex/constants.ts +43 -0
- package/src/providers/openai-codex/request-transformer.ts +161 -0
- package/src/providers/openai-codex/response-handler.ts +81 -0
- package/src/providers/openai-codex-responses.ts +2598 -0
- package/src/providers/openai-completions-compat.ts +279 -0
- package/src/providers/openai-completions.ts +1853 -0
- package/src/providers/openai-responses-server-schema.ts +290 -0
- package/src/providers/openai-responses-server.ts +1183 -0
- package/src/providers/openai-responses-shared.ts +800 -0
- package/src/providers/openai-responses.ts +621 -0
- package/src/providers/pi-native-client.ts +228 -0
- package/src/providers/pi-native-server.ts +210 -0
- package/src/providers/register-builtins.ts +412 -0
- package/src/providers/synthetic.ts +50 -0
- package/src/providers/transform-messages.ts +309 -0
- package/src/providers/vision-guard.ts +31 -0
- package/src/rate-limit-utils.ts +84 -0
- package/src/stream.ts +895 -0
- package/src/types.ts +884 -0
- package/src/usage/claude.ts +431 -0
- package/src/usage/gemini.ts +250 -0
- package/src/usage/github-copilot.ts +421 -0
- package/src/usage/google-antigravity.ts +201 -0
- package/src/usage/kimi.ts +271 -0
- package/src/usage/minimax-code.ts +31 -0
- package/src/usage/openai-codex.ts +503 -0
- package/src/usage/shared.ts +10 -0
- package/src/usage/zai.ts +247 -0
- package/src/usage.ts +183 -0
- package/src/utils/abort.ts +51 -0
- package/src/utils/anthropic-auth.ts +87 -0
- package/src/utils/discovery/antigravity.ts +261 -0
- package/src/utils/discovery/codex.ts +371 -0
- package/src/utils/discovery/cursor.ts +306 -0
- package/src/utils/discovery/gemini.ts +248 -0
- package/src/utils/discovery/index.ts +4 -0
- package/src/utils/discovery/openai-compatible.ts +224 -0
- package/src/utils/event-stream.ts +142 -0
- package/src/utils/fireworks-model-id.ts +30 -0
- package/src/utils/foundry.ts +8 -0
- package/src/utils/h2-fetch.ts +60 -0
- package/src/utils/http-inspector.ts +176 -0
- package/src/utils/idle-iterator.ts +250 -0
- package/src/utils/json-parse.ts +148 -0
- package/src/utils/oauth/alibaba-coding-plan.ts +59 -0
- package/src/utils/oauth/anthropic.ts +200 -0
- package/src/utils/oauth/api-key-login.ts +87 -0
- package/src/utils/oauth/api-key-validation.ts +92 -0
- package/src/utils/oauth/callback-server.ts +276 -0
- package/src/utils/oauth/cerebras.ts +16 -0
- package/src/utils/oauth/cloudflare-ai-gateway.ts +48 -0
- package/src/utils/oauth/cursor.ts +157 -0
- package/src/utils/oauth/deepseek.ts +53 -0
- package/src/utils/oauth/firepass.ts +24 -0
- package/src/utils/oauth/fireworks.ts +15 -0
- package/src/utils/oauth/github-copilot.ts +362 -0
- package/src/utils/oauth/gitlab-duo.ts +123 -0
- package/src/utils/oauth/google-antigravity.ts +200 -0
- package/src/utils/oauth/google-gemini-cli.ts +256 -0
- package/src/utils/oauth/google-oauth-shared.ts +110 -0
- package/src/utils/oauth/huggingface.ts +62 -0
- package/src/utils/oauth/index.ts +444 -0
- package/src/utils/oauth/kagi.ts +47 -0
- package/src/utils/oauth/kilo.ts +87 -0
- package/src/utils/oauth/kimi.ts +254 -0
- package/src/utils/oauth/litellm.ts +47 -0
- package/src/utils/oauth/lm-studio.ts +38 -0
- package/src/utils/oauth/minimax-code.ts +78 -0
- package/src/utils/oauth/moonshot.ts +16 -0
- package/src/utils/oauth/nanogpt.ts +15 -0
- package/src/utils/oauth/nvidia.ts +70 -0
- package/src/utils/oauth/oauth.html +199 -0
- package/src/utils/oauth/ollama-cloud.ts +28 -0
- package/src/utils/oauth/ollama.ts +47 -0
- package/src/utils/oauth/openai-codex.ts +299 -0
- package/src/utils/oauth/opencode.ts +49 -0
- package/src/utils/oauth/parallel.ts +46 -0
- package/src/utils/oauth/perplexity.ts +206 -0
- package/src/utils/oauth/pkce.ts +18 -0
- package/src/utils/oauth/qianfan.ts +58 -0
- package/src/utils/oauth/qwen-portal.ts +60 -0
- package/src/utils/oauth/synthetic.ts +16 -0
- package/src/utils/oauth/tavily.ts +46 -0
- package/src/utils/oauth/together.ts +16 -0
- package/src/utils/oauth/types.ts +94 -0
- package/src/utils/oauth/venice.ts +59 -0
- package/src/utils/oauth/vercel-ai-gateway.ts +47 -0
- package/src/utils/oauth/vllm.ts +40 -0
- package/src/utils/oauth/xiaomi.ts +137 -0
- package/src/utils/oauth/zai.ts +60 -0
- package/src/utils/oauth/zenmux.ts +15 -0
- package/src/utils/overflow.ts +137 -0
- package/src/utils/parse-bind.ts +54 -0
- package/src/utils/provider-response.ts +30 -0
- package/src/utils/retry-after.ts +110 -0
- package/src/utils/retry.ts +54 -0
- package/src/utils/schema/CONSTRAINTS.md +164 -0
- package/src/utils/schema/adapt.ts +36 -0
- package/src/utils/schema/compatibility.ts +435 -0
- package/src/utils/schema/dereference.ts +98 -0
- package/src/utils/schema/draft.ts +341 -0
- package/src/utils/schema/equality.ts +97 -0
- package/src/utils/schema/fields.ts +190 -0
- package/src/utils/schema/index.ts +13 -0
- package/src/utils/schema/json-schema-validator.ts +577 -0
- package/src/utils/schema/meta-validator.ts +167 -0
- package/src/utils/schema/normalize.ts +1588 -0
- package/src/utils/schema/spill.ts +43 -0
- package/src/utils/schema/stamps.ts +97 -0
- package/src/utils/schema/types.ts +11 -0
- package/src/utils/schema/wire.ts +213 -0
- package/src/utils/schema/zod-decontaminate.ts +331 -0
- package/src/utils/sse-debug.ts +289 -0
- package/src/utils/tool-call-healing.ts +271 -0
- package/src/utils/tool-choice.ts +99 -0
- package/src/utils/validation.ts +1019 -0
- package/src/utils.ts +166 -0
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// High-level API
|
|
3
|
+
// ============================================================================
|
|
4
|
+
import type {
|
|
5
|
+
OAuthCredentials,
|
|
6
|
+
OAuthProvider,
|
|
7
|
+
OAuthProviderId,
|
|
8
|
+
OAuthProviderInfo,
|
|
9
|
+
OAuthProviderInterface,
|
|
10
|
+
} from "./types";
|
|
11
|
+
|
|
12
|
+
const builtInOAuthProviders: OAuthProviderInfo[] = [
|
|
13
|
+
{
|
|
14
|
+
id: "anthropic",
|
|
15
|
+
name: "Anthropic (Claude Pro/Max)",
|
|
16
|
+
available: true,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: "alibaba-coding-plan",
|
|
20
|
+
name: "Alibaba Coding Plan",
|
|
21
|
+
available: true,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
id: "openai-codex",
|
|
25
|
+
name: "ChatGPT Plus/Pro (Codex Subscription)",
|
|
26
|
+
available: true,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: "openai-codex-device",
|
|
30
|
+
name: "ChatGPT Plus/Pro (Codex, headless/device)",
|
|
31
|
+
available: true,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: "gitlab-duo",
|
|
35
|
+
name: "GitLab Duo",
|
|
36
|
+
available: true,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: "kimi-code",
|
|
40
|
+
name: "Kimi Code",
|
|
41
|
+
available: true,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: "kilo",
|
|
45
|
+
name: "Kilo Gateway",
|
|
46
|
+
available: true,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: "kagi",
|
|
50
|
+
name: "Kagi",
|
|
51
|
+
available: true,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: "cerebras",
|
|
55
|
+
name: "Cerebras",
|
|
56
|
+
available: true,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: "deepseek",
|
|
60
|
+
name: "DeepSeek",
|
|
61
|
+
available: true,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: "fireworks",
|
|
65
|
+
name: "Fireworks",
|
|
66
|
+
available: true,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: "firepass",
|
|
70
|
+
name: "Fire Pass (Fireworks Kimi K2.6 Turbo subscription)",
|
|
71
|
+
available: true,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: "github-copilot",
|
|
75
|
+
name: "GitHub Copilot",
|
|
76
|
+
available: true,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: "google-gemini-cli",
|
|
80
|
+
name: "Google Cloud Code Assist (Gemini CLI)",
|
|
81
|
+
available: true,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: "google-antigravity",
|
|
85
|
+
name: "Antigravity (Gemini 3, Claude, GPT-OSS)",
|
|
86
|
+
available: true,
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
id: "cursor",
|
|
90
|
+
name: "Cursor (Claude, GPT, etc.)",
|
|
91
|
+
available: true,
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: "litellm",
|
|
95
|
+
name: "LiteLLM",
|
|
96
|
+
available: true,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
id: "lm-studio",
|
|
100
|
+
name: "LM Studio (Local OpenAI-compatible)",
|
|
101
|
+
available: true,
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
id: "ollama",
|
|
105
|
+
name: "Ollama (Local OpenAI-compatible)",
|
|
106
|
+
available: true,
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: "ollama-cloud",
|
|
110
|
+
name: "Ollama Cloud",
|
|
111
|
+
available: true,
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
id: "huggingface",
|
|
115
|
+
name: "Hugging Face Inference",
|
|
116
|
+
available: true,
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
id: "synthetic",
|
|
120
|
+
name: "Synthetic",
|
|
121
|
+
available: true,
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
id: "tavily",
|
|
125
|
+
name: "Tavily",
|
|
126
|
+
available: true,
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
id: "together",
|
|
130
|
+
name: "Together",
|
|
131
|
+
available: true,
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
id: "xiaomi",
|
|
135
|
+
name: "Xiaomi MiMo",
|
|
136
|
+
available: true,
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
id: "opencode-zen",
|
|
140
|
+
name: "OpenCode Zen",
|
|
141
|
+
available: true,
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
id: "opencode-go",
|
|
145
|
+
name: "OpenCode Go",
|
|
146
|
+
available: true,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
id: "zai",
|
|
150
|
+
name: "Z.AI (GLM Coding Plan)",
|
|
151
|
+
available: true,
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
id: "minimax-code",
|
|
155
|
+
name: "MiniMax Coding Plan (International)",
|
|
156
|
+
available: true,
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
id: "minimax-code-cn",
|
|
160
|
+
name: "MiniMax Coding Plan (China)",
|
|
161
|
+
available: true,
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
id: "moonshot",
|
|
165
|
+
name: "Moonshot (Kimi API)",
|
|
166
|
+
available: true,
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
id: "nanogpt",
|
|
170
|
+
name: "NanoGPT",
|
|
171
|
+
available: true,
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
id: "parallel",
|
|
175
|
+
name: "Parallel",
|
|
176
|
+
available: true,
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
id: "perplexity",
|
|
180
|
+
name: "Perplexity (Pro/Max)",
|
|
181
|
+
available: true,
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
id: "nvidia",
|
|
185
|
+
name: "NVIDIA",
|
|
186
|
+
available: true,
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
id: "qwen-portal",
|
|
190
|
+
name: "Qwen Portal",
|
|
191
|
+
available: true,
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
id: "qianfan",
|
|
195
|
+
name: "Qianfan",
|
|
196
|
+
available: true,
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
id: "venice",
|
|
200
|
+
name: "Venice",
|
|
201
|
+
available: true,
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
id: "zenmux",
|
|
205
|
+
name: "ZenMux",
|
|
206
|
+
available: true,
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
id: "vllm",
|
|
210
|
+
name: "vLLM (Local OpenAI-compatible)",
|
|
211
|
+
available: true,
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
id: "cloudflare-ai-gateway",
|
|
215
|
+
name: "Cloudflare AI Gateway",
|
|
216
|
+
available: true,
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
id: "vercel-ai-gateway",
|
|
220
|
+
name: "Vercel AI Gateway",
|
|
221
|
+
available: true,
|
|
222
|
+
},
|
|
223
|
+
];
|
|
224
|
+
|
|
225
|
+
const customOAuthProviders = new Map<string, OAuthProviderInterface>();
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Register a custom OAuth provider.
|
|
229
|
+
*/
|
|
230
|
+
export function registerOAuthProvider(provider: OAuthProviderInterface): void {
|
|
231
|
+
customOAuthProviders.set(provider.id, provider);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Get a custom OAuth provider by ID.
|
|
236
|
+
*/
|
|
237
|
+
export function getOAuthProvider(id: OAuthProviderId): OAuthProviderInterface | undefined {
|
|
238
|
+
return customOAuthProviders.get(id);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Remove all custom OAuth providers registered by a source.
|
|
243
|
+
*/
|
|
244
|
+
export function unregisterOAuthProviders(sourceId: string): void {
|
|
245
|
+
for (const [id, provider] of customOAuthProviders.entries()) {
|
|
246
|
+
if (provider.sourceId === sourceId) {
|
|
247
|
+
customOAuthProviders.delete(id);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Refresh token for any OAuth provider.
|
|
254
|
+
* Saves the new credentials and returns the new access token.
|
|
255
|
+
*/
|
|
256
|
+
export async function refreshOAuthToken(
|
|
257
|
+
provider: OAuthProvider,
|
|
258
|
+
credentials: OAuthCredentials,
|
|
259
|
+
): Promise<OAuthCredentials> {
|
|
260
|
+
if (!credentials) {
|
|
261
|
+
throw new Error(`No OAuth credentials found for ${provider}`);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
let newCredentials: OAuthCredentials;
|
|
265
|
+
switch (provider) {
|
|
266
|
+
case "anthropic": {
|
|
267
|
+
const { refreshAnthropicToken } = await import("./anthropic");
|
|
268
|
+
newCredentials = await refreshAnthropicToken(credentials.refresh);
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
case "github-copilot": {
|
|
272
|
+
const { refreshGitHubCopilotToken } = await import("./github-copilot");
|
|
273
|
+
newCredentials = await refreshGitHubCopilotToken(credentials.refresh, credentials.enterpriseUrl);
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
case "google-gemini-cli": {
|
|
277
|
+
const { refreshGoogleCloudToken } = await import("./google-gemini-cli");
|
|
278
|
+
if (!credentials.projectId) {
|
|
279
|
+
throw new Error("Google Cloud credentials missing projectId");
|
|
280
|
+
}
|
|
281
|
+
newCredentials = await refreshGoogleCloudToken(credentials.refresh, credentials.projectId);
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
case "google-antigravity": {
|
|
285
|
+
const { refreshAntigravityToken } = await import("./google-antigravity");
|
|
286
|
+
if (!credentials.projectId) {
|
|
287
|
+
throw new Error("Antigravity credentials missing projectId");
|
|
288
|
+
}
|
|
289
|
+
newCredentials = await refreshAntigravityToken(credentials.refresh, credentials.projectId);
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
case "openai-codex":
|
|
293
|
+
case "openai-codex-device": {
|
|
294
|
+
const { refreshOpenAICodexToken } = await import("./openai-codex");
|
|
295
|
+
newCredentials = await refreshOpenAICodexToken(credentials.refresh);
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
case "kimi-code": {
|
|
299
|
+
const { refreshKimiToken } = await import("./kimi");
|
|
300
|
+
newCredentials = await refreshKimiToken(credentials.refresh);
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
case "gitlab-duo": {
|
|
304
|
+
const { refreshGitLabDuoToken } = await import("./gitlab-duo");
|
|
305
|
+
newCredentials = await refreshGitLabDuoToken(credentials);
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
case "cursor": {
|
|
309
|
+
const { refreshCursorToken } = await import("./cursor");
|
|
310
|
+
newCredentials = await refreshCursorToken(credentials.refresh);
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
case "kilo":
|
|
314
|
+
case "perplexity":
|
|
315
|
+
case "huggingface":
|
|
316
|
+
case "opencode-zen":
|
|
317
|
+
case "opencode-go":
|
|
318
|
+
case "cerebras":
|
|
319
|
+
case "fireworks":
|
|
320
|
+
case "firepass":
|
|
321
|
+
case "nvidia":
|
|
322
|
+
case "nanogpt":
|
|
323
|
+
case "synthetic":
|
|
324
|
+
case "together":
|
|
325
|
+
case "litellm":
|
|
326
|
+
case "lm-studio":
|
|
327
|
+
case "ollama":
|
|
328
|
+
case "ollama-cloud":
|
|
329
|
+
case "xiaomi":
|
|
330
|
+
case "zai":
|
|
331
|
+
case "qianfan":
|
|
332
|
+
case "venice":
|
|
333
|
+
case "minimax-code":
|
|
334
|
+
case "minimax-code-cn":
|
|
335
|
+
case "moonshot":
|
|
336
|
+
case "kagi":
|
|
337
|
+
case "cloudflare-ai-gateway":
|
|
338
|
+
case "vercel-ai-gateway":
|
|
339
|
+
case "qwen-portal":
|
|
340
|
+
case "zenmux":
|
|
341
|
+
case "vllm":
|
|
342
|
+
// API keys / static bearer tokens don't expire, return as-is
|
|
343
|
+
newCredentials = credentials;
|
|
344
|
+
break;
|
|
345
|
+
default:
|
|
346
|
+
throw new Error(`Unknown OAuth provider: ${provider}`);
|
|
347
|
+
}
|
|
348
|
+
return newCredentials;
|
|
349
|
+
}
|
|
350
|
+
function getPerplexityJwtExpiryMs(token: string): number | undefined {
|
|
351
|
+
const parts = token.split(".");
|
|
352
|
+
if (parts.length !== 3) return undefined;
|
|
353
|
+
const payload = parts[1];
|
|
354
|
+
if (!payload) return undefined;
|
|
355
|
+
try {
|
|
356
|
+
const decoded = JSON.parse(Buffer.from(payload, "base64url").toString("utf8")) as { exp?: unknown };
|
|
357
|
+
if (typeof decoded.exp !== "number" || !Number.isFinite(decoded.exp)) return undefined;
|
|
358
|
+
return decoded.exp * 1000 - 5 * 60_000;
|
|
359
|
+
} catch {
|
|
360
|
+
return undefined;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Build API-key bytes for a provider from an already-fresh OAuth credential.
|
|
366
|
+
*
|
|
367
|
+
* Refresh is owned by AuthStorage. This helper deliberately refuses expired
|
|
368
|
+
* credentials so it cannot POST broker redaction sentinels to upstream token
|
|
369
|
+
* endpoints as a side channel.
|
|
370
|
+
*
|
|
371
|
+
* For providers that need credential metadata at request time, returns
|
|
372
|
+
* JSON-encoded credentials plus expiry metadata for diagnostics/edge guards.
|
|
373
|
+
* @returns API key string, or null if no credentials
|
|
374
|
+
* @throws Error if the credential is expired and must be refreshed upstream
|
|
375
|
+
*/
|
|
376
|
+
export async function getOAuthApiKey(
|
|
377
|
+
provider: OAuthProvider,
|
|
378
|
+
credentials: Record<string, OAuthCredentials>,
|
|
379
|
+
): Promise<{ newCredentials: OAuthCredentials; apiKey: string } | null> {
|
|
380
|
+
let creds = credentials[provider];
|
|
381
|
+
if (!creds) {
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (provider === "perplexity") {
|
|
386
|
+
// Perplexity JWTs usually omit `exp` (server-side sessions). Trust the JWT
|
|
387
|
+
// claim when present; otherwise treat the credential as non-expiring rather
|
|
388
|
+
// than honoring a stale stored `expires` (older logins wrote loginTime+1h).
|
|
389
|
+
const NEVER_EXPIRES = 8.64e15;
|
|
390
|
+
const normalizedExpires =
|
|
391
|
+
creds.expires > 0 && creds.expires < 10_000_000_000 ? creds.expires * 1000 : creds.expires;
|
|
392
|
+
const jwtExpiry = getPerplexityJwtExpiryMs(creds.access);
|
|
393
|
+
const expires = jwtExpiry ?? Math.max(normalizedExpires, NEVER_EXPIRES);
|
|
394
|
+
if (expires !== creds.expires) {
|
|
395
|
+
creds = { ...creds, expires };
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
// Refresh is the sole responsibility of `AuthStorage` (which calls
|
|
399
|
+
// `refreshOAuthToken` directly with broker-aware single-flighting). If we
|
|
400
|
+
// reach here with an expired credential, the outer pipeline failed to
|
|
401
|
+
// refresh before this call OR the refresh slot is the broker sentinel —
|
|
402
|
+
// either way, posting the credential to a provider endpoint would only
|
|
403
|
+
// trigger a `__remote__`-against-real-provider failure that gets classified
|
|
404
|
+
// as `invalid_grant` and disables the row. Refuse loudly instead.
|
|
405
|
+
if (Date.now() >= creds.expires) {
|
|
406
|
+
if (provider === "perplexity") {
|
|
407
|
+
const jwtExpiry = getPerplexityJwtExpiryMs(creds.access);
|
|
408
|
+
if (jwtExpiry && Date.now() < jwtExpiry) {
|
|
409
|
+
const fallbackCredentials = { ...creds, expires: jwtExpiry };
|
|
410
|
+
return { newCredentials: fallbackCredentials, apiKey: fallbackCredentials.access };
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
throw new Error(
|
|
414
|
+
`OAuth credential for ${provider} is expired and must be refreshed via AuthStorage before getOAuthApiKey is called`,
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
// For providers that need request-time credential metadata, return JSON.
|
|
418
|
+
const needsStructuredApiKey =
|
|
419
|
+
provider === "github-copilot" || provider === "google-gemini-cli" || provider === "google-antigravity";
|
|
420
|
+
const apiKey = needsStructuredApiKey
|
|
421
|
+
? JSON.stringify({
|
|
422
|
+
token: creds.access,
|
|
423
|
+
enterpriseUrl: creds.enterpriseUrl,
|
|
424
|
+
projectId: creds.projectId,
|
|
425
|
+
refreshToken: creds.refresh,
|
|
426
|
+
expiresAt: creds.expires,
|
|
427
|
+
email: creds.email,
|
|
428
|
+
accountId: creds.accountId,
|
|
429
|
+
})
|
|
430
|
+
: creds.access;
|
|
431
|
+
return { newCredentials: creds, apiKey };
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Get list of OAuth providers.
|
|
436
|
+
*/
|
|
437
|
+
export function getOAuthProviders(): OAuthProviderInfo[] {
|
|
438
|
+
const customProviders = Array.from(customOAuthProviders.values(), provider => ({
|
|
439
|
+
id: provider.id,
|
|
440
|
+
name: provider.name,
|
|
441
|
+
available: true,
|
|
442
|
+
}));
|
|
443
|
+
return [...builtInOAuthProviders, ...customProviders];
|
|
444
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kagi login flow.
|
|
3
|
+
*
|
|
4
|
+
* Kagi web search uses an API key from the account settings page.
|
|
5
|
+
* This is an API key flow:
|
|
6
|
+
* 1. Open browser to Kagi API settings
|
|
7
|
+
* 2. User copies API key
|
|
8
|
+
* 3. User pastes key into CLI
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { OAuthController } from "./types";
|
|
12
|
+
|
|
13
|
+
const AUTH_URL = "https://kagi.com/settings/api";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Login to Kagi.
|
|
17
|
+
*
|
|
18
|
+
* Opens browser to API settings and prompts user to paste their API key.
|
|
19
|
+
* Returns the API key directly (not OAuthCredentials - this isn't OAuth).
|
|
20
|
+
*/
|
|
21
|
+
export async function loginKagi(options: OAuthController): Promise<string> {
|
|
22
|
+
if (!options.onPrompt) {
|
|
23
|
+
throw new Error("Kagi login requires onPrompt callback");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
options.onAuth?.({
|
|
27
|
+
url: AUTH_URL,
|
|
28
|
+
instructions:
|
|
29
|
+
"Copy your Kagi Search API key from Kagi API settings. Search API access is beta-only; if unavailable, email support@kagi.com.",
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const apiKey = await options.onPrompt({
|
|
33
|
+
message: "Paste your Kagi API key",
|
|
34
|
+
placeholder: "KG_...",
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (options.signal?.aborted) {
|
|
38
|
+
throw new Error("Login cancelled");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const trimmed = apiKey.trim();
|
|
42
|
+
if (!trimmed) {
|
|
43
|
+
throw new Error("API key is required");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return trimmed;
|
|
47
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { OAuthController, OAuthCredentials } from "./types";
|
|
2
|
+
|
|
3
|
+
const KILO_DEVICE_AUTH_BASE_URL = "https://api.kilo.ai/api/device-auth";
|
|
4
|
+
const POLL_INTERVAL_MS = 5000;
|
|
5
|
+
const ONE_YEAR_MS = 365 * 24 * 60 * 60 * 1000;
|
|
6
|
+
|
|
7
|
+
interface KiloDeviceAuthCodeResponse {
|
|
8
|
+
code?: string;
|
|
9
|
+
verificationUrl?: string;
|
|
10
|
+
expiresIn?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface KiloDeviceAuthPollResponse {
|
|
14
|
+
status?: string;
|
|
15
|
+
token?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Login with Kilo Gateway OAuth (device code flow).
|
|
20
|
+
*/
|
|
21
|
+
export async function loginKilo(callbacks: OAuthController): Promise<OAuthCredentials> {
|
|
22
|
+
const initiateResponse = await fetch(`${KILO_DEVICE_AUTH_BASE_URL}/codes`, {
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: { "Content-Type": "application/json" },
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (!initiateResponse.ok) {
|
|
28
|
+
if (initiateResponse.status === 429) {
|
|
29
|
+
throw new Error("Too many pending authorization requests. Please try again later.");
|
|
30
|
+
}
|
|
31
|
+
throw new Error(`Failed to initiate device authorization: ${initiateResponse.status}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const initiateData = (await initiateResponse.json()) as KiloDeviceAuthCodeResponse;
|
|
35
|
+
const userCode = initiateData.code;
|
|
36
|
+
const verificationUrl = initiateData.verificationUrl;
|
|
37
|
+
const expiresInSeconds = initiateData.expiresIn;
|
|
38
|
+
if (!userCode || !verificationUrl || typeof expiresInSeconds !== "number" || expiresInSeconds <= 0) {
|
|
39
|
+
throw new Error("Kilo device authorization response missing required fields");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
callbacks.onAuth?.({
|
|
43
|
+
url: verificationUrl,
|
|
44
|
+
instructions: `Enter code: ${userCode}`,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const deadline = Date.now() + expiresInSeconds * 1000;
|
|
48
|
+
while (Date.now() < deadline) {
|
|
49
|
+
if (callbacks.signal?.aborted) {
|
|
50
|
+
throw new Error("Login cancelled");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const pollResponse = await fetch(`${KILO_DEVICE_AUTH_BASE_URL}/codes/${encodeURIComponent(userCode)}`);
|
|
54
|
+
if (pollResponse.status === 202) {
|
|
55
|
+
await Bun.sleep(POLL_INTERVAL_MS);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (pollResponse.status === 403) {
|
|
59
|
+
throw new Error("Authorization was denied");
|
|
60
|
+
}
|
|
61
|
+
if (pollResponse.status === 410) {
|
|
62
|
+
throw new Error("Authorization code expired. Please try again.");
|
|
63
|
+
}
|
|
64
|
+
if (!pollResponse.ok) {
|
|
65
|
+
throw new Error(`Failed to poll device authorization: ${pollResponse.status}`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const pollData = (await pollResponse.json()) as KiloDeviceAuthPollResponse;
|
|
69
|
+
if (pollData.status === "approved" && pollData.token) {
|
|
70
|
+
return {
|
|
71
|
+
refresh: "",
|
|
72
|
+
access: pollData.token,
|
|
73
|
+
expires: Date.now() + ONE_YEAR_MS,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (pollData.status === "denied") {
|
|
77
|
+
throw new Error("Authorization was denied");
|
|
78
|
+
}
|
|
79
|
+
if (pollData.status === "expired") {
|
|
80
|
+
throw new Error("Authorization code expired. Please try again.");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
await Bun.sleep(POLL_INTERVAL_MS);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
throw new Error("Authentication timed out. Please try again.");
|
|
87
|
+
}
|