wyxrouter 0.4.71
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 +222 -0
- package/LICENSE +21 -0
- package/README.md +96 -0
- package/README.zh-CN.md +1311 -0
- package/assets/pixel-router-2d.png +0 -0
- package/cli/LICENSE +42 -0
- package/cli/README.md +125 -0
- package/cli/app/package.json +58 -0
- package/cli/cli.js +806 -0
- package/cli/package.json +48 -0
- package/i18n/README.ja-JP.md +1209 -0
- package/i18n/README.ru.md +1311 -0
- package/i18n/README.vi.md +1310 -0
- package/i18n/README.zh-CN.md +1306 -0
- package/images/9router.png +0 -0
- package/jsconfig.json +12 -0
- package/next.config.mjs +71 -0
- package/open-sse/config/appConstants.js +203 -0
- package/open-sse/config/codexInstructions.js +119 -0
- package/open-sse/config/constants.js +4 -0
- package/open-sse/config/defaultThinkingSignature.js +12 -0
- package/open-sse/config/errorConfig.js +85 -0
- package/open-sse/config/googleTtsLanguages.js +62 -0
- package/open-sse/config/kiroConstants.js +322 -0
- package/open-sse/config/models.js +13 -0
- package/open-sse/config/ollamaModels.js +19 -0
- package/open-sse/config/providerModels.js +944 -0
- package/open-sse/config/providers.js +458 -0
- package/open-sse/config/runtimeConfig.js +72 -0
- package/open-sse/config/ttsModels.js +129 -0
- package/open-sse/executors/antigravity.js +504 -0
- package/open-sse/executors/azure.js +57 -0
- package/open-sse/executors/base.js +185 -0
- package/open-sse/executors/codex.js +469 -0
- package/open-sse/executors/commandcode.js +88 -0
- package/open-sse/executors/cursor.js +795 -0
- package/open-sse/executors/default.js +497 -0
- package/open-sse/executors/gemini-cli.js +89 -0
- package/open-sse/executors/github.js +379 -0
- package/open-sse/executors/grok-web.js +345 -0
- package/open-sse/executors/iflow.js +108 -0
- package/open-sse/executors/index.js +75 -0
- package/open-sse/executors/kiro.js +508 -0
- package/open-sse/executors/ollama-local.js +14 -0
- package/open-sse/executors/opencode-go.js +41 -0
- package/open-sse/executors/opencode.js +32 -0
- package/open-sse/executors/perplexity-web.js +507 -0
- package/open-sse/executors/qoder.js +450 -0
- package/open-sse/executors/qwen.js +129 -0
- package/open-sse/executors/vertex.js +131 -0
- package/open-sse/executors/xiaomi-tokenplan.js +19 -0
- package/open-sse/handlers/chatCore/nonStreamingHandler.js +230 -0
- package/open-sse/handlers/chatCore/requestDetail.js +102 -0
- package/open-sse/handlers/chatCore/sseToJsonHandler.js +231 -0
- package/open-sse/handlers/chatCore/streamingHandler.js +103 -0
- package/open-sse/handlers/chatCore.js +287 -0
- package/open-sse/handlers/embeddingProviders/_base.js +4 -0
- package/open-sse/handlers/embeddingProviders/gemini.js +54 -0
- package/open-sse/handlers/embeddingProviders/index.js +23 -0
- package/open-sse/handlers/embeddingProviders/openai.js +39 -0
- package/open-sse/handlers/embeddingProviders/openaiCompatNode.js +13 -0
- package/open-sse/handlers/embeddingsCore.js +126 -0
- package/open-sse/handlers/fetch/index.js +237 -0
- package/open-sse/handlers/imageGenerationCore.js +189 -0
- package/open-sse/handlers/imageProviders/_base.js +31 -0
- package/open-sse/handlers/imageProviders/blackForestLabs.js +43 -0
- package/open-sse/handlers/imageProviders/cloudflareAi.js +178 -0
- package/open-sse/handlers/imageProviders/codex.js +198 -0
- package/open-sse/handlers/imageProviders/comfyui.js +8 -0
- package/open-sse/handlers/imageProviders/falAi.js +41 -0
- package/open-sse/handlers/imageProviders/gemini.js +25 -0
- package/open-sse/handlers/imageProviders/huggingface.js +22 -0
- package/open-sse/handlers/imageProviders/index.js +40 -0
- package/open-sse/handlers/imageProviders/nanobanana.js +58 -0
- package/open-sse/handlers/imageProviders/openai.js +40 -0
- package/open-sse/handlers/imageProviders/runwayml.js +47 -0
- package/open-sse/handlers/imageProviders/sdwebui.js +17 -0
- package/open-sse/handlers/imageProviders/stabilityAi.js +34 -0
- package/open-sse/handlers/responsesHandler.js +103 -0
- package/open-sse/handlers/search/callers.js +371 -0
- package/open-sse/handlers/search/chatSearch.js +409 -0
- package/open-sse/handlers/search/index.js +201 -0
- package/open-sse/handlers/search/normalizers.js +223 -0
- package/open-sse/handlers/sttCore.js +194 -0
- package/open-sse/handlers/ttsCore.js +74 -0
- package/open-sse/handlers/ttsProviders/_base.js +39 -0
- package/open-sse/handlers/ttsProviders/edgeTts.js +89 -0
- package/open-sse/handlers/ttsProviders/elevenlabs.js +48 -0
- package/open-sse/handlers/ttsProviders/gemini.js +117 -0
- package/open-sse/handlers/ttsProviders/genericFormats.js +169 -0
- package/open-sse/handlers/ttsProviders/googleTts.js +54 -0
- package/open-sse/handlers/ttsProviders/index.js +50 -0
- package/open-sse/handlers/ttsProviders/localDevice.js +87 -0
- package/open-sse/handlers/ttsProviders/minimax.js +59 -0
- package/open-sse/handlers/ttsProviders/openai.js +30 -0
- package/open-sse/handlers/ttsProviders/openrouter.js +70 -0
- package/open-sse/index.js +82 -0
- package/open-sse/rtk/applyFilter.js +15 -0
- package/open-sse/rtk/autodetect.js +111 -0
- package/open-sse/rtk/caveman.js +100 -0
- package/open-sse/rtk/cavemanPrompts.js +78 -0
- package/open-sse/rtk/constants.js +55 -0
- package/open-sse/rtk/filters/buildOutput.js +127 -0
- package/open-sse/rtk/filters/dedupLog.js +44 -0
- package/open-sse/rtk/filters/find.js +49 -0
- package/open-sse/rtk/filters/gitDiff.js +92 -0
- package/open-sse/rtk/filters/gitStatus.js +117 -0
- package/open-sse/rtk/filters/grep.js +48 -0
- package/open-sse/rtk/filters/ls.js +79 -0
- package/open-sse/rtk/filters/readNumbered.js +27 -0
- package/open-sse/rtk/filters/searchList.js +52 -0
- package/open-sse/rtk/filters/smartTruncate.js +15 -0
- package/open-sse/rtk/filters/tree.js +32 -0
- package/open-sse/rtk/index.js +155 -0
- package/open-sse/rtk/registry.js +38 -0
- package/open-sse/services/accountFallback.js +238 -0
- package/open-sse/services/combo.js +198 -0
- package/open-sse/services/compact.js +71 -0
- package/open-sse/services/kiroModels.js +332 -0
- package/open-sse/services/model.js +261 -0
- package/open-sse/services/oauthCredentialManager.js +151 -0
- package/open-sse/services/projectId.js +306 -0
- package/open-sse/services/provider.js +356 -0
- package/open-sse/services/qoderModels.js +214 -0
- package/open-sse/services/tokenRefresh.js +939 -0
- package/open-sse/services/usage.js +1496 -0
- package/open-sse/transformer/responsesTransformer.js +439 -0
- package/open-sse/transformer/streamToJsonConverter.js +103 -0
- package/open-sse/translator/formats.js +36 -0
- package/open-sse/translator/helpers/claudeHelper.js +216 -0
- package/open-sse/translator/helpers/geminiHelper.js +372 -0
- package/open-sse/translator/helpers/imageHelper.js +34 -0
- package/open-sse/translator/helpers/maxTokensHelper.js +27 -0
- package/open-sse/translator/helpers/openaiHelper.js +130 -0
- package/open-sse/translator/helpers/responsesApiHelper.js +139 -0
- package/open-sse/translator/helpers/toolCallHelper.js +148 -0
- package/open-sse/translator/index.js +251 -0
- package/open-sse/translator/request/antigravity-to-openai.js +229 -0
- package/open-sse/translator/request/claude-to-openai.js +232 -0
- package/open-sse/translator/request/gemini-to-openai.js +147 -0
- package/open-sse/translator/request/openai-responses.js +318 -0
- package/open-sse/translator/request/openai-to-claude.js +401 -0
- package/open-sse/translator/request/openai-to-commandcode.js +170 -0
- package/open-sse/translator/request/openai-to-cursor.js +183 -0
- package/open-sse/translator/request/openai-to-gemini.js +470 -0
- package/open-sse/translator/request/openai-to-kiro.js +629 -0
- package/open-sse/translator/request/openai-to-kiro.old.js +278 -0
- package/open-sse/translator/request/openai-to-ollama.js +192 -0
- package/open-sse/translator/request/openai-to-vertex.js +42 -0
- package/open-sse/translator/response/claude-to-openai.js +206 -0
- package/open-sse/translator/response/commandcode-to-openai.js +197 -0
- package/open-sse/translator/response/cursor-to-openai.js +30 -0
- package/open-sse/translator/response/gemini-to-openai.js +245 -0
- package/open-sse/translator/response/kiro-to-openai.js +195 -0
- package/open-sse/translator/response/ollama-to-openai.js +152 -0
- package/open-sse/translator/response/openai-responses.js +590 -0
- package/open-sse/translator/response/openai-to-antigravity.js +122 -0
- package/open-sse/translator/response/openai-to-claude.js +266 -0
- package/open-sse/utils/bypassHandler.js +298 -0
- package/open-sse/utils/claudeCloaking.js +155 -0
- package/open-sse/utils/claudeHeaderCache.js +70 -0
- package/open-sse/utils/clientDetector.js +63 -0
- package/open-sse/utils/cursorChecksum.js +149 -0
- package/open-sse/utils/cursorProtobuf.js +904 -0
- package/open-sse/utils/debugLog.js +14 -0
- package/open-sse/utils/error.js +147 -0
- package/open-sse/utils/ollamaTransform.js +85 -0
- package/open-sse/utils/proxyFetch.js +368 -0
- package/open-sse/utils/reasoningContentInjector.js +79 -0
- package/open-sse/utils/requestLogger.js +260 -0
- package/open-sse/utils/responsesStreamHelpers.js +49 -0
- package/open-sse/utils/sessionManager.js +82 -0
- package/open-sse/utils/stream.js +462 -0
- package/open-sse/utils/streamHandler.js +250 -0
- package/open-sse/utils/streamHelpers.js +122 -0
- package/open-sse/utils/toolDeduper.js +49 -0
- package/open-sse/utils/usageTracking.js +347 -0
- package/package.json +100 -0
- package/postcss.config.mjs +12 -0
- package/public/favicon.svg +11 -0
- package/public/file.svg +1 -0
- package/public/globe.svg +1 -0
- package/public/i18n/literals/ar.json +195 -0
- package/public/i18n/literals/bn.json +195 -0
- package/public/i18n/literals/cs.json +195 -0
- package/public/i18n/literals/da.json +195 -0
- package/public/i18n/literals/de.json +195 -0
- package/public/i18n/literals/el.json +195 -0
- package/public/i18n/literals/es.json +195 -0
- package/public/i18n/literals/fi.json +195 -0
- package/public/i18n/literals/fr.json +195 -0
- package/public/i18n/literals/he.json +195 -0
- package/public/i18n/literals/hi.json +195 -0
- package/public/i18n/literals/hu.json +195 -0
- package/public/i18n/literals/id.json +195 -0
- package/public/i18n/literals/it.json +195 -0
- package/public/i18n/literals/ja.json +195 -0
- package/public/i18n/literals/ko.json +195 -0
- package/public/i18n/literals/nl.json +195 -0
- package/public/i18n/literals/no.json +195 -0
- package/public/i18n/literals/pl.json +195 -0
- package/public/i18n/literals/pt-BR.json +195 -0
- package/public/i18n/literals/pt-PT.json +195 -0
- package/public/i18n/literals/ro.json +195 -0
- package/public/i18n/literals/ru.json +195 -0
- package/public/i18n/literals/sv.json +195 -0
- package/public/i18n/literals/th.json +195 -0
- package/public/i18n/literals/tl.json +195 -0
- package/public/i18n/literals/tr.json +195 -0
- package/public/i18n/literals/uk.json +195 -0
- package/public/i18n/literals/ur.json +195 -0
- package/public/i18n/literals/vi.json +195 -0
- package/public/i18n/literals/zh-CN.json +772 -0
- package/public/i18n/literals/zh-TW.json +195 -0
- package/public/icons/discord.svg +4 -0
- package/public/icons/icon-192.svg +4 -0
- package/public/icons/icon-512.svg +4 -0
- package/public/next.svg +1 -0
- package/public/providers/alicode-intl.png +0 -0
- package/public/providers/alicode.png +0 -0
- package/public/providers/amp.png +0 -0
- package/public/providers/anthropic-m.png +0 -0
- package/public/providers/anthropic.png +0 -0
- package/public/providers/antigravity.png +0 -0
- package/public/providers/assemblyai.png +0 -0
- package/public/providers/aws-polly.png +0 -0
- package/public/providers/azure.png +0 -0
- package/public/providers/black-forest-labs.png +0 -0
- package/public/providers/blackbox.png +0 -0
- package/public/providers/brave-search.png +0 -0
- package/public/providers/byteplus.png +0 -0
- package/public/providers/cartesia.png +0 -0
- package/public/providers/cerebras.png +0 -0
- package/public/providers/chutes.png +0 -0
- package/public/providers/claude.png +0 -0
- package/public/providers/cline.png +0 -0
- package/public/providers/cloudflare-ai.png +0 -0
- package/public/providers/codebuddy.svg +37 -0
- package/public/providers/codex.png +0 -0
- package/public/providers/cohere.png +0 -0
- package/public/providers/comfyui.png +0 -0
- package/public/providers/commandcode.png +0 -0
- package/public/providers/continue.png +0 -0
- package/public/providers/copilot.png +0 -0
- package/public/providers/coqui.png +0 -0
- package/public/providers/cursor.png +0 -0
- package/public/providers/deepgram.png +0 -0
- package/public/providers/deepseek-tui.png +0 -0
- package/public/providers/deepseek.png +0 -0
- package/public/providers/droid.png +0 -0
- package/public/providers/edge-tts.png +0 -0
- package/public/providers/elevenlabs.png +0 -0
- package/public/providers/exa.png +0 -0
- package/public/providers/fal-ai.png +0 -0
- package/public/providers/firecrawl.png +0 -0
- package/public/providers/fireworks.png +0 -0
- package/public/providers/gemini-cli.png +0 -0
- package/public/providers/gemini.png +0 -0
- package/public/providers/github.png +0 -0
- package/public/providers/glm-cn.png +0 -0
- package/public/providers/glm.png +0 -0
- package/public/providers/google-pse.png +0 -0
- package/public/providers/google-tts.png +0 -0
- package/public/providers/grok-web.png +0 -0
- package/public/providers/groq.png +0 -0
- package/public/providers/hermes.png +0 -0
- package/public/providers/huggingface.png +0 -0
- package/public/providers/hyperbolic.png +0 -0
- package/public/providers/iflow.png +0 -0
- package/public/providers/inworld.png +0 -0
- package/public/providers/jcode.png +0 -0
- package/public/providers/jina-ai.png +0 -0
- package/public/providers/jina-reader.png +0 -0
- package/public/providers/kilocode.png +0 -0
- package/public/providers/kimi-coding.png +0 -0
- package/public/providers/kimi.png +0 -0
- package/public/providers/kiro.png +0 -0
- package/public/providers/linkup.png +0 -0
- package/public/providers/local-device.png +0 -0
- package/public/providers/minimax-cn.png +0 -0
- package/public/providers/minimax.png +0 -0
- package/public/providers/mistral.png +0 -0
- package/public/providers/nanobanana.png +0 -0
- package/public/providers/nebius.png +0 -0
- package/public/providers/nvidia.png +0 -0
- package/public/providers/oai-cc.png +0 -0
- package/public/providers/oai-r.png +0 -0
- package/public/providers/ollama-local.png +0 -0
- package/public/providers/ollama.png +0 -0
- package/public/providers/openai.png +0 -0
- package/public/providers/openclaw.png +0 -0
- package/public/providers/opencode-go.png +0 -0
- package/public/providers/opencode.png +0 -0
- package/public/providers/openrouter.png +0 -0
- package/public/providers/perplexity-web.png +0 -0
- package/public/providers/perplexity.png +0 -0
- package/public/providers/playht.png +0 -0
- package/public/providers/qoder.png +0 -0
- package/public/providers/qwen.png +0 -0
- package/public/providers/recraft.png +0 -0
- package/public/providers/roo.png +0 -0
- package/public/providers/runwayml.png +0 -0
- package/public/providers/sdwebui.png +0 -0
- package/public/providers/searchapi.png +0 -0
- package/public/providers/searxng.png +0 -0
- package/public/providers/serper.png +0 -0
- package/public/providers/siliconflow.png +0 -0
- package/public/providers/stability-ai.png +0 -0
- package/public/providers/tavily.png +0 -0
- package/public/providers/together.png +0 -0
- package/public/providers/topaz.png +0 -0
- package/public/providers/tortoise.png +0 -0
- package/public/providers/vertex-partner.png +0 -0
- package/public/providers/vertex.png +0 -0
- package/public/providers/volcengine-ark.png +0 -0
- package/public/providers/voyage-ai.png +0 -0
- package/public/providers/xai.png +0 -0
- package/public/providers/xiaomi-mimo.png +0 -0
- package/public/providers/xiaomi-tokenplan.png +0 -0
- package/public/providers/youcom.png +0 -0
- package/public/sw.js +22 -0
- package/public/vercel.svg +1 -0
- package/public/window.svg +1 -0
- package/scripts/compact-request-details.mjs +71 -0
- package/scripts/import-codex-gptjson.mjs +342 -0
- package/scripts/start-standalone.mjs +25 -0
- package/scripts/translate-readme.js +201 -0
- package/src/app/(dashboard)/dashboard/automation/page.js +294 -0
- package/src/app/(dashboard)/dashboard/basic-chat/BasicChatPageClient.js +967 -0
- package/src/app/(dashboard)/dashboard/basic-chat/page.js +5 -0
- package/src/app/(dashboard)/dashboard/cli-tools/CLIToolsPageClient.js +66 -0
- package/src/app/(dashboard)/dashboard/cli-tools/[toolId]/ToolDetailClient.js +173 -0
- package/src/app/(dashboard)/dashboard/cli-tools/[toolId]/page.js +11 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/AntigravityToolCard.js +481 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/ApiKeySelect.js +66 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/BaseUrlSelect.js +174 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/ClaudeToolCard.js +390 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/ClineToolCard.js +301 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/CodexToolCard.js +458 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/CopilotToolCard.js +323 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/CoworkToolCard.js +640 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/DeepSeekTuiToolCard.js +338 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/DefaultToolCard.js +271 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/DroidToolCard.js +410 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/EndpointPresetControl.js +128 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/HermesToolCard.js +317 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/JcodeToolCard.js +380 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/KiloToolCard.js +275 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/MitmLinkCard.js +40 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/MitmServerCard.js +329 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/MitmToolCard.js +318 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/OpenClawToolCard.js +388 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/OpenCodeToolCard.js +500 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/ToolSummaryCard.js +39 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/cliEndpointMatch.js +13 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/index.js +19 -0
- package/src/app/(dashboard)/dashboard/cli-tools/page.js +7 -0
- package/src/app/(dashboard)/dashboard/combos/page.js +612 -0
- package/src/app/(dashboard)/dashboard/console-log/ConsoleLogClient.js +91 -0
- package/src/app/(dashboard)/dashboard/console-log/page.js +8 -0
- package/src/app/(dashboard)/dashboard/endpoint/EndpointPageClient.js +1555 -0
- package/src/app/(dashboard)/dashboard/endpoint/page.js +7 -0
- package/src/app/(dashboard)/dashboard/media-providers/[kind]/[id]/page.js +1903 -0
- package/src/app/(dashboard)/dashboard/media-providers/[kind]/page.js +289 -0
- package/src/app/(dashboard)/dashboard/media-providers/combo/[id]/page.js +410 -0
- package/src/app/(dashboard)/dashboard/media-providers/web/page.js +209 -0
- package/src/app/(dashboard)/dashboard/mitm/MitmPageClient.js +117 -0
- package/src/app/(dashboard)/dashboard/mitm/page.js +5 -0
- package/src/app/(dashboard)/dashboard/page.js +7 -0
- package/src/app/(dashboard)/dashboard/profile/page.js +1140 -0
- package/src/app/(dashboard)/dashboard/providers/[id]/AddApiKeyModal.js +389 -0
- package/src/app/(dashboard)/dashboard/providers/[id]/AddCustomModelModal.js +125 -0
- package/src/app/(dashboard)/dashboard/providers/[id]/CompatibleModelsSection.js +250 -0
- package/src/app/(dashboard)/dashboard/providers/[id]/ConnectionRow.js +299 -0
- package/src/app/(dashboard)/dashboard/providers/[id]/CooldownTimer.js +42 -0
- package/src/app/(dashboard)/dashboard/providers/[id]/EditCompatibleNodeModal.js +161 -0
- package/src/app/(dashboard)/dashboard/providers/[id]/ModelRow.js +95 -0
- package/src/app/(dashboard)/dashboard/providers/[id]/PassthroughModelsSection.js +183 -0
- package/src/app/(dashboard)/dashboard/providers/[id]/page.js +2053 -0
- package/src/app/(dashboard)/dashboard/providers/[id]/page.new.js +1724 -0
- package/src/app/(dashboard)/dashboard/providers/components/ConnectionsCard.js +497 -0
- package/src/app/(dashboard)/dashboard/providers/components/ModelAvailabilityBadge.js +185 -0
- package/src/app/(dashboard)/dashboard/providers/components/ModelsCard.js +294 -0
- package/src/app/(dashboard)/dashboard/providers/new/page.js +220 -0
- package/src/app/(dashboard)/dashboard/providers/page.js +1365 -0
- package/src/app/(dashboard)/dashboard/proxy-pools/page.js +1092 -0
- package/src/app/(dashboard)/dashboard/quota/page.js +11 -0
- package/src/app/(dashboard)/dashboard/skills/page.js +112 -0
- package/src/app/(dashboard)/dashboard/translator/page.js +303 -0
- package/src/app/(dashboard)/dashboard/usage/components/OverviewCards.js +35 -0
- package/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/ProviderLimitCard.js +185 -0
- package/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/QuotaProgressBar.js +127 -0
- package/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/QuotaTable.js +259 -0
- package/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/index.js +1394 -0
- package/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/utils.js +244 -0
- package/src/app/(dashboard)/dashboard/usage/components/ProviderTopology.js +327 -0
- package/src/app/(dashboard)/dashboard/usage/components/RequestDetailsTab.js +433 -0
- package/src/app/(dashboard)/dashboard/usage/components/UsageChart.js +141 -0
- package/src/app/(dashboard)/dashboard/usage/components/UsageTable.js +247 -0
- package/src/app/(dashboard)/dashboard/usage/page.js +75 -0
- package/src/app/(dashboard)/layout.js +6 -0
- package/src/app/api/auth/login/route.js +76 -0
- package/src/app/api/auth/logout/route.js +12 -0
- package/src/app/api/auth/oidc/callback/route.js +87 -0
- package/src/app/api/auth/oidc/start/route.js +52 -0
- package/src/app/api/auth/oidc/test/route.js +84 -0
- package/src/app/api/auth/status/route.js +45 -0
- package/src/app/api/cli-tools/all-statuses/route.js +46 -0
- package/src/app/api/cli-tools/antigravity-mitm/alias/route.js +53 -0
- package/src/app/api/cli-tools/antigravity-mitm/route.js +202 -0
- package/src/app/api/cli-tools/claude-settings/route.js +203 -0
- package/src/app/api/cli-tools/cline-settings/route.js +133 -0
- package/src/app/api/cli-tools/codex-gateway/accounts/route.js +16 -0
- package/src/app/api/cli-tools/codex-settings/route.js +239 -0
- package/src/app/api/cli-tools/copilot-settings/route.js +148 -0
- package/src/app/api/cli-tools/cowork-mcp-registry/route.js +77 -0
- package/src/app/api/cli-tools/cowork-mcp-tools/route.js +95 -0
- package/src/app/api/cli-tools/cowork-settings/route.js +412 -0
- package/src/app/api/cli-tools/deepseek-tui-settings/route.js +164 -0
- package/src/app/api/cli-tools/droid-settings/route.js +213 -0
- package/src/app/api/cli-tools/hermes-settings/route.js +175 -0
- package/src/app/api/cli-tools/jcode-settings/route.js +216 -0
- package/src/app/api/cli-tools/kilo-settings/route.js +131 -0
- package/src/app/api/cli-tools/openclaw-settings/route.js +292 -0
- package/src/app/api/cli-tools/opencode-settings/route.js +259 -0
- package/src/app/api/combos/[id]/route.js +81 -0
- package/src/app/api/combos/route.js +48 -0
- package/src/app/api/health/route.js +15 -0
- package/src/app/api/init/route.js +4 -0
- package/src/app/api/keys/[id]/route.js +58 -0
- package/src/app/api/keys/route.js +42 -0
- package/src/app/api/locale/route.js +30 -0
- package/src/app/api/mcp/[plugin]/message/route.js +21 -0
- package/src/app/api/mcp/[plugin]/sse/route.js +37 -0
- package/src/app/api/media-providers/tts/deepgram/voices/route.js +65 -0
- package/src/app/api/media-providers/tts/elevenlabs/voices/route.js +71 -0
- package/src/app/api/media-providers/tts/inworld/voices/route.js +61 -0
- package/src/app/api/media-providers/tts/minimax/voices/route.js +113 -0
- package/src/app/api/media-providers/tts/voices/route.js +99 -0
- package/src/app/api/models/alias/route.js +53 -0
- package/src/app/api/models/availability/route.js +103 -0
- package/src/app/api/models/custom/route.js +48 -0
- package/src/app/api/models/disabled/route.js +50 -0
- package/src/app/api/models/route.js +64 -0
- package/src/app/api/models/test/ping.js +191 -0
- package/src/app/api/models/test/route.js +14 -0
- package/src/app/api/oauth/[provider]/[action]/route.js +343 -0
- package/src/app/api/oauth/codebuddy/bulk-import/[jobId]/cancel/route.js +19 -0
- package/src/app/api/oauth/codebuddy/bulk-import/[jobId]/manual/[workerId]/route.js +30 -0
- package/src/app/api/oauth/codebuddy/bulk-import/[jobId]/route.js +23 -0
- package/src/app/api/oauth/codebuddy/bulk-import/latest/route.js +25 -0
- package/src/app/api/oauth/codebuddy/bulk-import/route.js +49 -0
- package/src/app/api/oauth/codebuddy/quota-cookie/route.js +133 -0
- package/src/app/api/oauth/codex/import-token/route.js +96 -0
- package/src/app/api/oauth/cursor/auto-import/route.js +258 -0
- package/src/app/api/oauth/cursor/import/route.js +100 -0
- package/src/app/api/oauth/gitlab/pat/route.js +62 -0
- package/src/app/api/oauth/iflow/cookie/route.js +137 -0
- package/src/app/api/oauth/kiro/auto-import/route.js +85 -0
- package/src/app/api/oauth/kiro/bulk-import/[jobId]/cancel/route.js +18 -0
- package/src/app/api/oauth/kiro/bulk-import/[jobId]/manual/[workerId]/route.js +29 -0
- package/src/app/api/oauth/kiro/bulk-import/[jobId]/route.js +22 -0
- package/src/app/api/oauth/kiro/bulk-import/latest/route.js +25 -0
- package/src/app/api/oauth/kiro/bulk-import/route.js +49 -0
- package/src/app/api/oauth/kiro/import/route.js +110 -0
- package/src/app/api/oauth/kiro/social-authorize/route.js +27 -0
- package/src/app/api/oauth/kiro/social-exchange/route.js +41 -0
- package/src/app/api/pricing/route.js +134 -0
- package/src/app/api/provider-nodes/[id]/route.js +101 -0
- package/src/app/api/provider-nodes/route.js +104 -0
- package/src/app/api/provider-nodes/validate/route.js +201 -0
- package/src/app/api/providers/[id]/models/route.js +526 -0
- package/src/app/api/providers/[id]/route.js +189 -0
- package/src/app/api/providers/[id]/test/route.js +23 -0
- package/src/app/api/providers/[id]/test/testUtils.js +714 -0
- package/src/app/api/providers/[id]/test-models/route.js +66 -0
- package/src/app/api/providers/client/route.js +126 -0
- package/src/app/api/providers/kilo/free-models/route.js +55 -0
- package/src/app/api/providers/route.js +206 -0
- package/src/app/api/providers/suggested-models/filters.js +20 -0
- package/src/app/api/providers/suggested-models/route.js +32 -0
- package/src/app/api/providers/test-batch/route.js +131 -0
- package/src/app/api/providers/validate/route.js +637 -0
- package/src/app/api/proxy-pools/[id]/route.js +123 -0
- package/src/app/api/proxy-pools/[id]/test/route.js +70 -0
- package/src/app/api/proxy-pools/cloudflare-deploy/route.js +145 -0
- package/src/app/api/proxy-pools/deno-deploy/route.js +175 -0
- package/src/app/api/proxy-pools/route.js +93 -0
- package/src/app/api/proxy-pools/vercel-deploy/route.js +142 -0
- package/src/app/api/settings/database/route.js +36 -0
- package/src/app/api/settings/proxy-test/route.js +23 -0
- package/src/app/api/settings/require-login/route.js +15 -0
- package/src/app/api/settings/route.js +100 -0
- package/src/app/api/shutdown/route.js +24 -0
- package/src/app/api/tags/route.js +18 -0
- package/src/app/api/translator/console-logs/route.js +24 -0
- package/src/app/api/translator/console-logs/stream/route.js +79 -0
- package/src/app/api/translator/load/route.js +45 -0
- package/src/app/api/translator/save/route.js +44 -0
- package/src/app/api/translator/send/route.js +94 -0
- package/src/app/api/translator/translate/route.js +90 -0
- package/src/app/api/tunnel/disable/route.js +12 -0
- package/src/app/api/tunnel/enable/route.js +16 -0
- package/src/app/api/tunnel/status/route.js +13 -0
- package/src/app/api/tunnel/tailscale-check/route.js +50 -0
- package/src/app/api/tunnel/tailscale-disable/route.js +12 -0
- package/src/app/api/tunnel/tailscale-enable/route.js +12 -0
- package/src/app/api/tunnel/tailscale-install/route.js +72 -0
- package/src/app/api/usage/[connectionId]/route.js +188 -0
- package/src/app/api/usage/chart/route.js +21 -0
- package/src/app/api/usage/history/route.js +12 -0
- package/src/app/api/usage/logs/route.js +12 -0
- package/src/app/api/usage/providers/route.js +42 -0
- package/src/app/api/usage/request-details/route.js +57 -0
- package/src/app/api/usage/request-logs/route.js +13 -0
- package/src/app/api/usage/stats/route.js +23 -0
- package/src/app/api/usage/stream/route.js +79 -0
- package/src/app/api/v1/api/chat/route.js +37 -0
- package/src/app/api/v1/audio/speech/route.js +16 -0
- package/src/app/api/v1/audio/transcriptions/route.js +19 -0
- package/src/app/api/v1/audio/voices/route.js +68 -0
- package/src/app/api/v1/chat/completions/route.js +35 -0
- package/src/app/api/v1/embeddings/route.js +21 -0
- package/src/app/api/v1/images/generations/route.js +16 -0
- package/src/app/api/v1/messages/count_tokens/route.js +52 -0
- package/src/app/api/v1/messages/route.js +36 -0
- package/src/app/api/v1/models/[kind]/route.js +55 -0
- package/src/app/api/v1/models/info/route.js +110 -0
- package/src/app/api/v1/models/route.js +451 -0
- package/src/app/api/v1/responses/compact/route.js +37 -0
- package/src/app/api/v1/responses/route.js +30 -0
- package/src/app/api/v1/route.js +1 -0
- package/src/app/api/v1/search/route.js +21 -0
- package/src/app/api/v1/web/fetch/route.js +21 -0
- package/src/app/api/v1beta/models/[...path]/route.js +328 -0
- package/src/app/api/v1beta/models/route.js +44 -0
- package/src/app/api/version/route.js +45 -0
- package/src/app/api/version/shutdown/route.js +15 -0
- package/src/app/api/version/update/route.js +21 -0
- package/src/app/callback/page.js +148 -0
- package/src/app/dashboard/settings/pricing/page.js +173 -0
- package/src/app/favicon.ico +0 -0
- package/src/app/globals.css +496 -0
- package/src/app/landing/components/AnimatedBackground.js +57 -0
- package/src/app/landing/components/Features.js +133 -0
- package/src/app/landing/components/FlowAnimation.js +175 -0
- package/src/app/landing/components/Footer.js +61 -0
- package/src/app/landing/components/GetStarted.js +97 -0
- package/src/app/landing/components/HeroSection.js +47 -0
- package/src/app/landing/components/HowItWorks.js +66 -0
- package/src/app/landing/components/Navigation.js +72 -0
- package/src/app/landing/page.js +106 -0
- package/src/app/layout.js +49 -0
- package/src/app/login/page.js +197 -0
- package/src/app/manifest.js +30 -0
- package/src/app/page.js +5 -0
- package/src/dashboardGuard.js +242 -0
- package/src/i18n/RuntimeI18nProvider.js +27 -0
- package/src/i18n/config.js +146 -0
- package/src/i18n/runtime.js +162 -0
- package/src/lib/appUpdater.js +200 -0
- package/src/lib/auth/dashboardSession.js +68 -0
- package/src/lib/auth/loginLimiter.js +52 -0
- package/src/lib/auth/oidc.js +234 -0
- package/src/lib/consoleLogBuffer.js +79 -0
- package/src/lib/dataDir.js +29 -0
- package/src/lib/db/adapters/betterSqliteAdapter.js +55 -0
- package/src/lib/db/adapters/bunSqliteAdapter.js +63 -0
- package/src/lib/db/adapters/nodeSqliteAdapter.js +84 -0
- package/src/lib/db/adapters/sqljsAdapter.js +115 -0
- package/src/lib/db/backup.js +35 -0
- package/src/lib/db/driver.js +85 -0
- package/src/lib/db/helpers/jsonCol.js +9 -0
- package/src/lib/db/helpers/kvStore.js +39 -0
- package/src/lib/db/helpers/metaStore.js +22 -0
- package/src/lib/db/index.js +171 -0
- package/src/lib/db/migrate.js +286 -0
- package/src/lib/db/migrations/001-initial.js +14 -0
- package/src/lib/db/migrations/index.js +10 -0
- package/src/lib/db/paths.js +18 -0
- package/src/lib/db/repos/aliasRepo.js +62 -0
- package/src/lib/db/repos/apiKeysRepo.js +75 -0
- package/src/lib/db/repos/combosRepo.js +73 -0
- package/src/lib/db/repos/connectionsRepo.js +226 -0
- package/src/lib/db/repos/disabledModelsRepo.js +56 -0
- package/src/lib/db/repos/nodesRepo.js +95 -0
- package/src/lib/db/repos/pricingRepo.js +108 -0
- package/src/lib/db/repos/proxyPoolsRepo.js +103 -0
- package/src/lib/db/repos/requestDetailsRepo.js +259 -0
- package/src/lib/db/repos/settingsRepo.js +104 -0
- package/src/lib/db/repos/usageRepo.js +731 -0
- package/src/lib/db/schema.js +157 -0
- package/src/lib/db/version.js +21 -0
- package/src/lib/disabledModelsDb.js +4 -0
- package/src/lib/localDb.js +21 -0
- package/src/lib/mcp/stdioSseBridge.js +198 -0
- package/src/lib/mitmAliasCache.js +46 -0
- package/src/lib/network/connectionProxy.js +160 -0
- package/src/lib/network/initOutboundProxy.js +25 -0
- package/src/lib/network/outboundProxy.js +68 -0
- package/src/lib/network/proxyTest.js +91 -0
- package/src/lib/oauth/constants/oauth.js +284 -0
- package/src/lib/oauth/constants/xai.js +61 -0
- package/src/lib/oauth/providers.js +1506 -0
- package/src/lib/oauth/services/antigravity.js +321 -0
- package/src/lib/oauth/services/claude.js +136 -0
- package/src/lib/oauth/services/codebuddyBulkImportManager.js +454 -0
- package/src/lib/oauth/services/codex.js +144 -0
- package/src/lib/oauth/services/cursor.js +179 -0
- package/src/lib/oauth/services/gemini.js +240 -0
- package/src/lib/oauth/services/github.js +225 -0
- package/src/lib/oauth/services/iflow.js +202 -0
- package/src/lib/oauth/services/index.js +17 -0
- package/src/lib/oauth/services/kiro.js +334 -0
- package/src/lib/oauth/services/kiroBulkImportManager.js +778 -0
- package/src/lib/oauth/services/kiroConnections.js +93 -0
- package/src/lib/oauth/services/kiroGoogleAutomation.js +1136 -0
- package/src/lib/oauth/services/oauth.js +157 -0
- package/src/lib/oauth/services/openai.js +123 -0
- package/src/lib/oauth/services/qoder.js +216 -0
- package/src/lib/oauth/services/qwen.js +170 -0
- package/src/lib/oauth/services/xai.js +238 -0
- package/src/lib/oauth/utils/banner.js +63 -0
- package/src/lib/oauth/utils/pkce.js +39 -0
- package/src/lib/oauth/utils/server.js +415 -0
- package/src/lib/oauth/utils/ui.js +48 -0
- package/src/lib/providerNormalization.js +45 -0
- package/src/lib/qoder/constants.js +64 -0
- package/src/lib/qoder/cosy.js +175 -0
- package/src/lib/qoder/encoding.js +55 -0
- package/src/lib/requestDetailsDb.js +4 -0
- package/src/lib/tunnel/cloudflare/cloudflared.js +449 -0
- package/src/lib/tunnel/cloudflare/config.js +9 -0
- package/src/lib/tunnel/cloudflare/healthCheck.js +29 -0
- package/src/lib/tunnel/cloudflare/manager.js +151 -0
- package/src/lib/tunnel/cloudflare/pid.js +23 -0
- package/src/lib/tunnel/index.js +48 -0
- package/src/lib/tunnel/shared/dnsResolver.js +17 -0
- package/src/lib/tunnel/shared/internetCheck.js +26 -0
- package/src/lib/tunnel/shared/state.js +41 -0
- package/src/lib/tunnel/shared/watchdogConfig.js +8 -0
- package/src/lib/tunnel/tailscale/config.js +7 -0
- package/src/lib/tunnel/tailscale/healthCheck.js +29 -0
- package/src/lib/tunnel/tailscale/manager.js +129 -0
- package/src/lib/tunnel/tailscale/tailscale.js +790 -0
- package/src/lib/updater/updater.js +235 -0
- package/src/lib/usage/fetcher.js +208 -0
- package/src/lib/usageDb.js +7 -0
- package/src/mitm/antigravityIdeVersion.js +50 -0
- package/src/mitm/cert/generate.js +32 -0
- package/src/mitm/cert/install.js +269 -0
- package/src/mitm/cert/rootCA.js +173 -0
- package/src/mitm/config.js +87 -0
- package/src/mitm/dbReader.js +22 -0
- package/src/mitm/dns/dnsConfig.js +266 -0
- package/src/mitm/handlers/antigravity.js +33 -0
- package/src/mitm/handlers/base.js +226 -0
- package/src/mitm/handlers/copilot.js +35 -0
- package/src/mitm/handlers/cursor.js +15 -0
- package/src/mitm/handlers/kiro.js +526 -0
- package/src/mitm/logger.js +106 -0
- package/src/mitm/manager.js +851 -0
- package/src/mitm/paths.js +32 -0
- package/src/mitm/server.js +435 -0
- package/src/mitm/winElevated.js +81 -0
- package/src/models/index.js +38 -0
- package/src/proxy.js +5 -0
- package/src/shared/components/AddCustomEmbeddingModal.js +183 -0
- package/src/shared/components/Avatar.js +88 -0
- package/src/shared/components/Badge.js +54 -0
- package/src/shared/components/BulkAccountAutomationModal.js +508 -0
- package/src/shared/components/Button.js +56 -0
- package/src/shared/components/Card.js +116 -0
- package/src/shared/components/ChangelogModal.js +97 -0
- package/src/shared/components/CodeBuddyQuotaCookieModal.js +109 -0
- package/src/shared/components/ComboFormModal.js +176 -0
- package/src/shared/components/CursorAuthModal.js +212 -0
- package/src/shared/components/DonateModal.js +136 -0
- package/src/shared/components/Drawer.js +82 -0
- package/src/shared/components/EditConnectionModal.js +286 -0
- package/src/shared/components/Footer.js +132 -0
- package/src/shared/components/GitLabAuthModal.js +194 -0
- package/src/shared/components/Header.js +380 -0
- package/src/shared/components/HeaderLanguage.js +46 -0
- package/src/shared/components/HeaderMenu.js +126 -0
- package/src/shared/components/IFlowCookieModal.js +132 -0
- package/src/shared/components/Input.js +65 -0
- package/src/shared/components/KiroAuthModal.js +1171 -0
- package/src/shared/components/KiroOAuthWrapper.js +149 -0
- package/src/shared/components/KiroSocialOAuthModal.js +205 -0
- package/src/shared/components/LanguageSwitcher.js +190 -0
- package/src/shared/components/Loading.js +75 -0
- package/src/shared/components/ManualConfigModal.js +44 -0
- package/src/shared/components/McpMarketplaceModal.js +255 -0
- package/src/shared/components/Modal.js +146 -0
- package/src/shared/components/ModelSelectModal.js +537 -0
- package/src/shared/components/NineRemoteButton.js +23 -0
- package/src/shared/components/NineRemotePromoModal.js +99 -0
- package/src/shared/components/NoAuthProxyCard.js +86 -0
- package/src/shared/components/OAuthModal.js +682 -0
- package/src/shared/components/Pagination.js +150 -0
- package/src/shared/components/PricingModal.js +208 -0
- package/src/shared/components/ProviderIcon.js +63 -0
- package/src/shared/components/ProviderInfoCard.js +82 -0
- package/src/shared/components/RequestLogger.js +121 -0
- package/src/shared/components/SegmentedControl.js +48 -0
- package/src/shared/components/Select.js +67 -0
- package/src/shared/components/Sidebar.js +441 -0
- package/src/shared/components/ThemeProvider.js +15 -0
- package/src/shared/components/ThemeToggle.js +42 -0
- package/src/shared/components/Toggle.js +69 -0
- package/src/shared/components/Tooltip.js +25 -0
- package/src/shared/components/UsageStats.js +505 -0
- package/src/shared/components/index.js +46 -0
- package/src/shared/components/layouts/AuthLayout.js +29 -0
- package/src/shared/components/layouts/DashboardLayout.js +104 -0
- package/src/shared/components/layouts/index.js +4 -0
- package/src/shared/constants/cliTools.js +397 -0
- package/src/shared/constants/colors.js +77 -0
- package/src/shared/constants/config.js +99 -0
- package/src/shared/constants/coworkPlugins.js +75 -0
- package/src/shared/constants/index.js +4 -0
- package/src/shared/constants/locales.js +36 -0
- package/src/shared/constants/mitmToolHosts.js +12 -0
- package/src/shared/constants/models.js +38 -0
- package/src/shared/constants/pricing.js +303 -0
- package/src/shared/constants/providers.js +289 -0
- package/src/shared/constants/skills.js +78 -0
- package/src/shared/constants/ttsProviders.js +138 -0
- package/src/shared/hooks/index.js +2 -0
- package/src/shared/hooks/useCopyToClipboard.js +43 -0
- package/src/shared/hooks/useTheme.js +60 -0
- package/src/shared/services/bootstrap.js +12 -0
- package/src/shared/services/initializeApp.js +268 -0
- package/src/shared/utils/api.js +93 -0
- package/src/shared/utils/apiKey.js +98 -0
- package/src/shared/utils/clineAuth.js +37 -0
- package/src/shared/utils/cn.js +11 -0
- package/src/shared/utils/connectionStatus.js +162 -0
- package/src/shared/utils/index.js +40 -0
- package/src/shared/utils/machine.js +6 -0
- package/src/shared/utils/machineId.js +66 -0
- package/src/shared/utils/providerModelsFetcher.js +30 -0
- package/src/sse/handlers/chat.js +261 -0
- package/src/sse/handlers/embeddings.js +141 -0
- package/src/sse/handlers/fetch.js +213 -0
- package/src/sse/handlers/imageGeneration.js +142 -0
- package/src/sse/handlers/search.js +206 -0
- package/src/sse/handlers/stt.js +88 -0
- package/src/sse/handlers/tts.js +114 -0
- package/src/sse/services/auth.js +346 -0
- package/src/sse/services/codexGateway.js +215 -0
- package/src/sse/services/model.js +99 -0
- package/src/sse/services/tokenRefresh.js +319 -0
- package/src/sse/utils/logger.js +75 -0
- package/src/store/headerSearchStore.js +19 -0
- package/src/store/index.js +6 -0
- package/src/store/notificationStore.js +45 -0
- package/src/store/providerStore.js +55 -0
- package/src/store/settingsStore.js +51 -0
- package/src/store/themeStore.js +54 -0
- package/src/store/userStore.js +20 -0
- package/start.sh +4 -0
|
@@ -0,0 +1,682 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState, useEffect, useRef, useCallback } from "react";
|
|
4
|
+
import PropTypes from "prop-types";
|
|
5
|
+
import { Modal, Button, Input } from "@/shared/components";
|
|
6
|
+
import { useCopyToClipboard } from "@/shared/hooks/useCopyToClipboard";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* OAuth Modal Component
|
|
10
|
+
* - Localhost: Auto callback via popup message
|
|
11
|
+
* - Remote: Manual paste callback URL
|
|
12
|
+
*/
|
|
13
|
+
export default function OAuthModal({ isOpen, provider, providerInfo, onSuccess, onClose, oauthMeta, idcConfig }) {
|
|
14
|
+
const [step, setStep] = useState("waiting"); // waiting | input | success | error
|
|
15
|
+
const [authData, setAuthData] = useState(null);
|
|
16
|
+
const [callbackUrl, setCallbackUrl] = useState("");
|
|
17
|
+
const [error, setError] = useState(null);
|
|
18
|
+
const [isDeviceCode, setIsDeviceCode] = useState(false);
|
|
19
|
+
const [deviceData, setDeviceData] = useState(null);
|
|
20
|
+
const [polling, setPolling] = useState(false);
|
|
21
|
+
const popupRef = useRef(null);
|
|
22
|
+
const pollingAbortRef = useRef(false);
|
|
23
|
+
const { copied, copy } = useCopyToClipboard();
|
|
24
|
+
|
|
25
|
+
// State for client-only values to avoid hydration mismatch
|
|
26
|
+
const [isLocalhost, setIsLocalhost] = useState(false);
|
|
27
|
+
const [placeholderUrl, setPlaceholderUrl] = useState("/callback?code=...");
|
|
28
|
+
const callbackProcessedRef = useRef(false);
|
|
29
|
+
|
|
30
|
+
// Detect if running on localhost (client-side only)
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (typeof window !== "undefined") {
|
|
33
|
+
setIsLocalhost(
|
|
34
|
+
window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1"
|
|
35
|
+
);
|
|
36
|
+
setPlaceholderUrl(`${window.location.origin}/callback?code=...`);
|
|
37
|
+
}
|
|
38
|
+
}, []);
|
|
39
|
+
|
|
40
|
+
// Define all useCallback hooks BEFORE the useEffects that reference them
|
|
41
|
+
|
|
42
|
+
// Exchange tokens
|
|
43
|
+
const exchangeTokens = useCallback(async (code, state) => {
|
|
44
|
+
if (!authData) return;
|
|
45
|
+
try {
|
|
46
|
+
const res = await fetch(`/api/oauth/${provider}/exchange`, {
|
|
47
|
+
method: "POST",
|
|
48
|
+
headers: { "Content-Type": "application/json" },
|
|
49
|
+
body: JSON.stringify({
|
|
50
|
+
code,
|
|
51
|
+
redirectUri: authData.redirectUri,
|
|
52
|
+
codeVerifier: authData.codeVerifier,
|
|
53
|
+
state,
|
|
54
|
+
...(oauthMeta ? { meta: oauthMeta } : {}),
|
|
55
|
+
}),
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const data = await res.json();
|
|
59
|
+
if (!res.ok) throw new Error(data.error);
|
|
60
|
+
|
|
61
|
+
setStep("success");
|
|
62
|
+
onSuccess?.();
|
|
63
|
+
} catch (err) {
|
|
64
|
+
setError(err.message);
|
|
65
|
+
setStep("error");
|
|
66
|
+
}
|
|
67
|
+
}, [authData, provider, onSuccess]);
|
|
68
|
+
|
|
69
|
+
const completeXaiManualCode = useCallback(async (code) => {
|
|
70
|
+
if (!authData?.state) return;
|
|
71
|
+
try {
|
|
72
|
+
const res = await fetch("/api/oauth/xai/manual-code", {
|
|
73
|
+
method: "POST",
|
|
74
|
+
headers: { "Content-Type": "application/json" },
|
|
75
|
+
body: JSON.stringify({ code, state: authData.state }),
|
|
76
|
+
});
|
|
77
|
+
const data = await res.json();
|
|
78
|
+
if (!res.ok) throw new Error(data.error);
|
|
79
|
+
|
|
80
|
+
setStep("success");
|
|
81
|
+
onSuccess?.();
|
|
82
|
+
} catch (err) {
|
|
83
|
+
setError(err.message);
|
|
84
|
+
setStep("error");
|
|
85
|
+
}
|
|
86
|
+
}, [authData, onSuccess]);
|
|
87
|
+
|
|
88
|
+
// Poll for device code token
|
|
89
|
+
const startPolling = useCallback(async (deviceCode, codeVerifier, interval, extraData, deadlineMs) => {
|
|
90
|
+
pollingAbortRef.current = false;
|
|
91
|
+
setPolling(true);
|
|
92
|
+
// Honor the upstream's expires_in when supplied (qoder sets 300s) so we
|
|
93
|
+
// don't time out earlier than the device code itself. Default 120s
|
|
94
|
+
// matches the prior behavior for providers that don't surface a value.
|
|
95
|
+
const startedAt = Date.now();
|
|
96
|
+
const deadline = startedAt + (Number.isFinite(deadlineMs) && deadlineMs > 0 ? deadlineMs : 120_000);
|
|
97
|
+
|
|
98
|
+
while (Date.now() < deadline) {
|
|
99
|
+
// Check if polling should be aborted
|
|
100
|
+
if (pollingAbortRef.current) {
|
|
101
|
+
console.log("[OAuthModal] Polling aborted");
|
|
102
|
+
setPolling(false);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
await new Promise((r) => setTimeout(r, interval * 1000));
|
|
107
|
+
|
|
108
|
+
// Check again after sleep
|
|
109
|
+
if (pollingAbortRef.current) {
|
|
110
|
+
console.log("[OAuthModal] Polling aborted after sleep");
|
|
111
|
+
setPolling(false);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
const res = await fetch(`/api/oauth/${provider}/poll`, {
|
|
117
|
+
method: "POST",
|
|
118
|
+
headers: { "Content-Type": "application/json" },
|
|
119
|
+
body: JSON.stringify({ deviceCode, codeVerifier, extraData }),
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const data = await res.json();
|
|
123
|
+
|
|
124
|
+
if (data.success) {
|
|
125
|
+
pollingAbortRef.current = true; // Stop polling immediately
|
|
126
|
+
setStep("success");
|
|
127
|
+
setPolling(false);
|
|
128
|
+
onSuccess?.();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (data.error === "expired_token" || data.error === "access_denied") {
|
|
133
|
+
throw new Error(data.errorDescription || data.error);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (data.error === "slow_down") {
|
|
137
|
+
interval = Math.min(interval + 5, 30);
|
|
138
|
+
}
|
|
139
|
+
} catch (err) {
|
|
140
|
+
setError(err.message);
|
|
141
|
+
setStep("error");
|
|
142
|
+
setPolling(false);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
setError("Authorization timeout");
|
|
148
|
+
setStep("error");
|
|
149
|
+
setPolling(false);
|
|
150
|
+
}, [provider, onSuccess]);
|
|
151
|
+
|
|
152
|
+
// Start OAuth flow
|
|
153
|
+
const startOAuthFlow = useCallback(async () => {
|
|
154
|
+
if (!provider) return;
|
|
155
|
+
try {
|
|
156
|
+
setError(null);
|
|
157
|
+
|
|
158
|
+
// Device code flow providers
|
|
159
|
+
const deviceCodeProviders = ["github", "qwen", "kiro", "kimi-coding", "kilocode", "codebuddy", "qoder"];
|
|
160
|
+
if (deviceCodeProviders.includes(provider)) {
|
|
161
|
+
setIsDeviceCode(true);
|
|
162
|
+
setStep("waiting");
|
|
163
|
+
|
|
164
|
+
const deviceCodeUrl = new URL(`/api/oauth/${provider}/device-code`, window.location.origin);
|
|
165
|
+
if (provider === "kiro" && idcConfig?.startUrl) {
|
|
166
|
+
deviceCodeUrl.searchParams.set("start_url", idcConfig.startUrl);
|
|
167
|
+
if (idcConfig.region) {
|
|
168
|
+
deviceCodeUrl.searchParams.set("region", idcConfig.region);
|
|
169
|
+
}
|
|
170
|
+
deviceCodeUrl.searchParams.set("auth_method", "idc");
|
|
171
|
+
}
|
|
172
|
+
const res = await fetch(deviceCodeUrl.toString());
|
|
173
|
+
const data = await res.json();
|
|
174
|
+
if (!res.ok) throw new Error(data.error);
|
|
175
|
+
|
|
176
|
+
setDeviceData(data);
|
|
177
|
+
|
|
178
|
+
// Auto-open verification URL in new tab
|
|
179
|
+
const verifyUrl = data.verification_uri_complete || data.verification_uri;
|
|
180
|
+
if (verifyUrl) window.open(verifyUrl, "_blank", "noopener,noreferrer");
|
|
181
|
+
|
|
182
|
+
// Pass extraData for Kiro (contains _clientId, _clientSecret) and
|
|
183
|
+
// Qoder (contains _qoderMachineId / _qoderNonce — needed so mapTokens
|
|
184
|
+
// can persist the machine id alongside the token).
|
|
185
|
+
const extraData = provider === "kiro"
|
|
186
|
+
? {
|
|
187
|
+
_clientId: data._clientId,
|
|
188
|
+
_clientSecret: data._clientSecret,
|
|
189
|
+
_region: data._region,
|
|
190
|
+
_authMethod: data._authMethod,
|
|
191
|
+
_startUrl: data._startUrl,
|
|
192
|
+
}
|
|
193
|
+
: provider === "qoder"
|
|
194
|
+
? {
|
|
195
|
+
_qoderNonce: data._qoderNonce,
|
|
196
|
+
_qoderMachineId: data._qoderMachineId,
|
|
197
|
+
_qoderVerifier: data.codeVerifier,
|
|
198
|
+
}
|
|
199
|
+
: null;
|
|
200
|
+
startPolling(
|
|
201
|
+
data.device_code,
|
|
202
|
+
data.codeVerifier,
|
|
203
|
+
data.interval || 5,
|
|
204
|
+
extraData,
|
|
205
|
+
// Use the upstream's expires_in if present so we don't time out
|
|
206
|
+
// before the device code itself (qoder gives 300s).
|
|
207
|
+
Number.isFinite(data.expires_in) && data.expires_in > 0
|
|
208
|
+
? data.expires_in * 1000
|
|
209
|
+
: undefined,
|
|
210
|
+
);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Authorization code flow - build redirect URI (some providers require fixed ports)
|
|
215
|
+
const appPort = window.location.port || (window.location.protocol === "https:" ? "443" : "80");
|
|
216
|
+
let redirectUri;
|
|
217
|
+
if (provider === "codex") {
|
|
218
|
+
redirectUri = "http://localhost:1455/auth/callback";
|
|
219
|
+
} else if (provider === "xai") {
|
|
220
|
+
redirectUri = "http://127.0.0.1:56121/callback";
|
|
221
|
+
} else {
|
|
222
|
+
redirectUri = `http://localhost:${appPort}/callback`;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Build authorize URL first to get codeVerifier/state for codex server-side mode
|
|
226
|
+
const authorizeUrl = new URL(`/api/oauth/${provider}/authorize`, window.location.origin);
|
|
227
|
+
authorizeUrl.searchParams.set("redirect_uri", redirectUri);
|
|
228
|
+
if (oauthMeta) {
|
|
229
|
+
Object.entries(oauthMeta).forEach(([k, v]) => { if (v) authorizeUrl.searchParams.set(k, v); });
|
|
230
|
+
}
|
|
231
|
+
const res = await fetch(authorizeUrl.toString());
|
|
232
|
+
const data = await res.json();
|
|
233
|
+
if (!res.ok) throw new Error(data.error);
|
|
234
|
+
|
|
235
|
+
// Codex: start proxy with server-side session (auto-exchange) + fallback to channels
|
|
236
|
+
let codexProxyActive = false;
|
|
237
|
+
let codexServerSide = false;
|
|
238
|
+
if (provider === "codex") {
|
|
239
|
+
try {
|
|
240
|
+
const proxyUrl = new URL(`/api/oauth/codex/start-proxy`, window.location.origin);
|
|
241
|
+
proxyUrl.searchParams.set("app_port", appPort);
|
|
242
|
+
proxyUrl.searchParams.set("state", data.state);
|
|
243
|
+
proxyUrl.searchParams.set("code_verifier", data.codeVerifier);
|
|
244
|
+
proxyUrl.searchParams.set("redirect_uri", redirectUri);
|
|
245
|
+
const proxyRes = await fetch(proxyUrl.toString());
|
|
246
|
+
const proxyData = await proxyRes.json();
|
|
247
|
+
codexProxyActive = proxyData.success;
|
|
248
|
+
codexServerSide = !!proxyData.serverSide;
|
|
249
|
+
} catch {
|
|
250
|
+
codexProxyActive = false;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// xAI: same fixed-port server-side proxy pattern as codex (port 56121)
|
|
255
|
+
let xaiProxyActive = false;
|
|
256
|
+
let xaiServerSide = false;
|
|
257
|
+
if (provider === "xai") {
|
|
258
|
+
try {
|
|
259
|
+
const proxyUrl = new URL(`/api/oauth/xai/start-proxy`, window.location.origin);
|
|
260
|
+
proxyUrl.searchParams.set("app_port", appPort);
|
|
261
|
+
proxyUrl.searchParams.set("state", data.state);
|
|
262
|
+
proxyUrl.searchParams.set("code_verifier", data.codeVerifier);
|
|
263
|
+
proxyUrl.searchParams.set("redirect_uri", redirectUri);
|
|
264
|
+
const proxyRes = await fetch(proxyUrl.toString());
|
|
265
|
+
const proxyData = await proxyRes.json();
|
|
266
|
+
xaiProxyActive = proxyData.success;
|
|
267
|
+
xaiServerSide = !!proxyData.serverSide;
|
|
268
|
+
if (!xaiProxyActive && proxyData.reason === "port_busy") {
|
|
269
|
+
throw new Error("Port 56121 in use; close the conflicting process and retry");
|
|
270
|
+
}
|
|
271
|
+
} catch (e) {
|
|
272
|
+
if (e?.message) throw e;
|
|
273
|
+
xaiProxyActive = false;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
setAuthData({ ...data, redirectUri, codexServerSide, xaiServerSide });
|
|
278
|
+
|
|
279
|
+
if (provider === "codex" && codexProxyActive) {
|
|
280
|
+
// Proxy active: callback will be handled server-side (auto-exchange) or via channels (fallback)
|
|
281
|
+
setStep("waiting");
|
|
282
|
+
popupRef.current = window.open(data.authUrl, "oauth_popup", "width=600,height=700");
|
|
283
|
+
if (!popupRef.current) {
|
|
284
|
+
setStep("input");
|
|
285
|
+
}
|
|
286
|
+
} else if (provider === "xai" && xaiProxyActive) {
|
|
287
|
+
setStep("waiting");
|
|
288
|
+
popupRef.current = window.open(data.authUrl, "oauth_popup", "width=600,height=700");
|
|
289
|
+
if (!popupRef.current) {
|
|
290
|
+
setStep("input");
|
|
291
|
+
}
|
|
292
|
+
} else if (!isLocalhost || provider === "codex" || provider === "xai") {
|
|
293
|
+
// Non-localhost or proxy failed: manual input mode
|
|
294
|
+
setStep("input");
|
|
295
|
+
window.open(data.authUrl, "_blank");
|
|
296
|
+
} else {
|
|
297
|
+
// Localhost (non-Codex/xAI): Open popup and wait for message
|
|
298
|
+
setStep("waiting");
|
|
299
|
+
popupRef.current = window.open(data.authUrl, "oauth_popup", "width=600,height=700");
|
|
300
|
+
if (!popupRef.current) {
|
|
301
|
+
setStep("input");
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
} catch (err) {
|
|
305
|
+
setError(err.message);
|
|
306
|
+
setStep("error");
|
|
307
|
+
}
|
|
308
|
+
}, [provider, isLocalhost, startPolling, oauthMeta, idcConfig]);
|
|
309
|
+
|
|
310
|
+
// Reset state and start OAuth when modal opens
|
|
311
|
+
useEffect(() => {
|
|
312
|
+
if (isOpen && provider) {
|
|
313
|
+
setAuthData(null);
|
|
314
|
+
setCallbackUrl("");
|
|
315
|
+
setError(null);
|
|
316
|
+
setIsDeviceCode(false);
|
|
317
|
+
setDeviceData(null);
|
|
318
|
+
setPolling(false);
|
|
319
|
+
pollingAbortRef.current = false;
|
|
320
|
+
startOAuthFlow();
|
|
321
|
+
} else if (!isOpen) {
|
|
322
|
+
// Abort polling and cleanup proxy when modal closes
|
|
323
|
+
pollingAbortRef.current = true;
|
|
324
|
+
if (provider === "codex") {
|
|
325
|
+
fetch("/api/oauth/codex/stop-proxy").catch(() => {});
|
|
326
|
+
} else if (provider === "xai") {
|
|
327
|
+
fetch("/api/oauth/xai/stop-proxy").catch(() => {});
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}, [isOpen, provider, startOAuthFlow]);
|
|
331
|
+
|
|
332
|
+
// Fixed-port server-side mode: poll status (proxy auto-exchanges + saves DB)
|
|
333
|
+
useEffect(() => {
|
|
334
|
+
const pollProvider = authData?.codexServerSide ? "codex" : authData?.xaiServerSide ? "xai" : null;
|
|
335
|
+
if (!pollProvider || !authData?.state) return;
|
|
336
|
+
if (callbackProcessedRef.current) return;
|
|
337
|
+
let cancelled = false;
|
|
338
|
+
const POLL_INTERVAL_MS = 1500;
|
|
339
|
+
const MAX_ATTEMPTS = 200; // ~5 minutes
|
|
340
|
+
let attempts = 0;
|
|
341
|
+
|
|
342
|
+
const tick = async () => {
|
|
343
|
+
if (cancelled || callbackProcessedRef.current) return;
|
|
344
|
+
attempts += 1;
|
|
345
|
+
try {
|
|
346
|
+
const res = await fetch(`/api/oauth/${pollProvider}/poll-status?state=${encodeURIComponent(authData.state)}`);
|
|
347
|
+
const data = await res.json();
|
|
348
|
+
if (cancelled || callbackProcessedRef.current) return;
|
|
349
|
+
if (data.status === "done") {
|
|
350
|
+
callbackProcessedRef.current = true;
|
|
351
|
+
setStep("success");
|
|
352
|
+
onSuccess?.();
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
if (data.status === "error") {
|
|
356
|
+
callbackProcessedRef.current = true;
|
|
357
|
+
setError(data.error || "Authentication failed");
|
|
358
|
+
setStep("error");
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
} catch {
|
|
362
|
+
// Network error, keep polling
|
|
363
|
+
}
|
|
364
|
+
if (attempts >= MAX_ATTEMPTS) {
|
|
365
|
+
callbackProcessedRef.current = true;
|
|
366
|
+
setError("Authentication timeout");
|
|
367
|
+
setStep("error");
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
setTimeout(tick, POLL_INTERVAL_MS);
|
|
371
|
+
};
|
|
372
|
+
setTimeout(tick, POLL_INTERVAL_MS);
|
|
373
|
+
return () => { cancelled = true; };
|
|
374
|
+
}, [authData, onSuccess]);
|
|
375
|
+
|
|
376
|
+
// Listen for OAuth callback via multiple methods
|
|
377
|
+
useEffect(() => {
|
|
378
|
+
if (!authData) return;
|
|
379
|
+
callbackProcessedRef.current = false; // Reset when authData changes
|
|
380
|
+
|
|
381
|
+
// Handler for callback data - only process once
|
|
382
|
+
const handleCallback = async (data) => {
|
|
383
|
+
if (callbackProcessedRef.current) return; // Already processed
|
|
384
|
+
|
|
385
|
+
const { code, state, error: callbackError, errorDescription } = data;
|
|
386
|
+
|
|
387
|
+
if (callbackError) {
|
|
388
|
+
callbackProcessedRef.current = true;
|
|
389
|
+
setError(errorDescription || callbackError);
|
|
390
|
+
setStep("error");
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (code) {
|
|
395
|
+
callbackProcessedRef.current = true;
|
|
396
|
+
await exchangeTokens(code, state);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
// Method 1: postMessage from popup
|
|
401
|
+
const handleMessage = (event) => {
|
|
402
|
+
// Allow messages from same origin or localhost (any port)
|
|
403
|
+
const isLocalhost = event.origin.includes("localhost") || event.origin.includes("127.0.0.1");
|
|
404
|
+
const isSameOrigin = event.origin === window.location.origin;
|
|
405
|
+
if (!isLocalhost && !isSameOrigin) return;
|
|
406
|
+
|
|
407
|
+
if (event.data?.type === "oauth_callback") {
|
|
408
|
+
handleCallback(event.data.data);
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
window.addEventListener("message", handleMessage);
|
|
412
|
+
|
|
413
|
+
// Method 2: BroadcastChannel
|
|
414
|
+
let channel;
|
|
415
|
+
try {
|
|
416
|
+
channel = new BroadcastChannel("oauth_callback");
|
|
417
|
+
channel.onmessage = (event) => handleCallback(event.data);
|
|
418
|
+
} catch (e) {
|
|
419
|
+
console.log("BroadcastChannel not supported");
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// Method 3: localStorage event
|
|
423
|
+
const handleStorage = (event) => {
|
|
424
|
+
if (event.key === "oauth_callback" && event.newValue) {
|
|
425
|
+
try {
|
|
426
|
+
const data = JSON.parse(event.newValue);
|
|
427
|
+
handleCallback(data);
|
|
428
|
+
localStorage.removeItem("oauth_callback");
|
|
429
|
+
} catch (e) {
|
|
430
|
+
console.log("Failed to parse localStorage data");
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
window.addEventListener("storage", handleStorage);
|
|
435
|
+
|
|
436
|
+
// Also check localStorage on mount (in case callback already happened)
|
|
437
|
+
try {
|
|
438
|
+
const stored = localStorage.getItem("oauth_callback");
|
|
439
|
+
if (stored) {
|
|
440
|
+
const data = JSON.parse(stored);
|
|
441
|
+
if (data.timestamp && Date.now() - data.timestamp < 30000) {
|
|
442
|
+
handleCallback(data);
|
|
443
|
+
}
|
|
444
|
+
localStorage.removeItem("oauth_callback");
|
|
445
|
+
}
|
|
446
|
+
} catch {
|
|
447
|
+
// localStorage may be unavailable or data may be malformed - ignore silently
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
return () => {
|
|
451
|
+
window.removeEventListener("message", handleMessage);
|
|
452
|
+
window.removeEventListener("storage", handleStorage);
|
|
453
|
+
if (channel) channel.close();
|
|
454
|
+
};
|
|
455
|
+
}, [authData, exchangeTokens]);
|
|
456
|
+
|
|
457
|
+
// Handle manual URL input
|
|
458
|
+
const handleManualSubmit = async () => {
|
|
459
|
+
try {
|
|
460
|
+
setError(null);
|
|
461
|
+
|
|
462
|
+
const input = callbackUrl.trim();
|
|
463
|
+
|
|
464
|
+
// Detect raw JWT access token (starts with eyJ) — skip URL parsing
|
|
465
|
+
if (input.startsWith("eyJ") && input.includes(".")) {
|
|
466
|
+
await exchangeTokens(input, null);
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
if (provider === "xai" && input && !input.includes("://") && !input.includes("?") && !input.includes("code=")) {
|
|
471
|
+
await completeXaiManualCode(input);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
const url = new URL(input);
|
|
476
|
+
const code = url.searchParams.get("code");
|
|
477
|
+
const state = url.searchParams.get("state");
|
|
478
|
+
const errorParam = url.searchParams.get("error");
|
|
479
|
+
|
|
480
|
+
if (errorParam) {
|
|
481
|
+
throw new Error(url.searchParams.get("error_description") || errorParam);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
if (!code) {
|
|
485
|
+
throw new Error(provider === "xai" ? "Paste the callback URL or copied xAI code" : "No authorization code found in URL");
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
await exchangeTokens(code, state);
|
|
489
|
+
} catch (err) {
|
|
490
|
+
setError(err.message);
|
|
491
|
+
setStep("error");
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
// Clear session on modal close + cleanup proxy
|
|
496
|
+
const handleClose = useCallback(() => {
|
|
497
|
+
if (provider === "codex") {
|
|
498
|
+
fetch("/api/oauth/codex/stop-proxy").catch(() => {});
|
|
499
|
+
} else if (provider === "xai") {
|
|
500
|
+
fetch("/api/oauth/xai/stop-proxy").catch(() => {});
|
|
501
|
+
}
|
|
502
|
+
onClose();
|
|
503
|
+
}, [onClose, provider]);
|
|
504
|
+
|
|
505
|
+
if (!provider || !providerInfo) return null;
|
|
506
|
+
const isXaiProvider = provider === "xai";
|
|
507
|
+
const deviceLoginUrl = deviceData?.verification_uri_complete || deviceData?.verification_uri || "";
|
|
508
|
+
const modalTitle = isXaiProvider ? "Connect Grok Build OAuth" : `Connect ${providerInfo.name}`;
|
|
509
|
+
const manualPlaceholder = isXaiProvider
|
|
510
|
+
? "http://127.0.0.1:56121/callback?code=... or copied code"
|
|
511
|
+
: placeholderUrl;
|
|
512
|
+
|
|
513
|
+
return (
|
|
514
|
+
<Modal isOpen={isOpen} title={modalTitle} onClose={handleClose} size="lg">
|
|
515
|
+
<div className="flex flex-col gap-4">
|
|
516
|
+
{/* Waiting + Manual Input combined (non-device-code) */}
|
|
517
|
+
{(step === "waiting" || step === "input") && !isDeviceCode && (
|
|
518
|
+
<>
|
|
519
|
+
{/* Option A: Auto via popup */}
|
|
520
|
+
<div className="flex items-center gap-2 px-3 py-2 border border-border rounded-lg bg-sidebar/50">
|
|
521
|
+
<span className="material-symbols-outlined text-base text-primary animate-spin">
|
|
522
|
+
progress_activity
|
|
523
|
+
</span>
|
|
524
|
+
<span className="text-sm">
|
|
525
|
+
{isXaiProvider ? "Waiting for Grok Build OAuth…" : "Waiting for popup authorization…"}
|
|
526
|
+
</span>
|
|
527
|
+
</div>
|
|
528
|
+
|
|
529
|
+
{/* Divider */}
|
|
530
|
+
<div className="flex items-center gap-3 my-1">
|
|
531
|
+
<div className="flex-1 h-px bg-border" />
|
|
532
|
+
<span className="text-xs text-text-muted uppercase tracking-wider">Or paste callback URL manually</span>
|
|
533
|
+
<div className="flex-1 h-px bg-border" />
|
|
534
|
+
</div>
|
|
535
|
+
|
|
536
|
+
{/* Option B: Manual paste */}
|
|
537
|
+
<div className="space-y-4">
|
|
538
|
+
<div>
|
|
539
|
+
<p className="text-sm font-medium mb-2">
|
|
540
|
+
Step 1: Open this {isXaiProvider ? "Grok Build OAuth URL" : "URL"} in your browser
|
|
541
|
+
</p>
|
|
542
|
+
<div className="flex gap-2">
|
|
543
|
+
<Input value={authData?.authUrl || ""} readOnly className="flex-1 font-mono text-xs" />
|
|
544
|
+
<Button variant="secondary" icon={copied === "auth_url" ? "check" : "content_copy"} onClick={() => copy(authData?.authUrl, "auth_url")} disabled={!authData?.authUrl}>
|
|
545
|
+
Copy
|
|
546
|
+
</Button>
|
|
547
|
+
</div>
|
|
548
|
+
</div>
|
|
549
|
+
|
|
550
|
+
<div>
|
|
551
|
+
<p className="text-sm font-medium mb-2">
|
|
552
|
+
Step 2: Paste the {provider === "xai" ? "callback URL or copied code" : "callback URL"} here
|
|
553
|
+
</p>
|
|
554
|
+
<p className="text-xs text-text-muted mb-2">
|
|
555
|
+
{provider === "xai"
|
|
556
|
+
? "If xAI shows a code instead of redirecting, paste that code here."
|
|
557
|
+
: "After authorization, copy the full URL from your browser."}
|
|
558
|
+
</p>
|
|
559
|
+
<Input
|
|
560
|
+
value={callbackUrl}
|
|
561
|
+
onChange={(e) => setCallbackUrl(e.target.value)}
|
|
562
|
+
placeholder={manualPlaceholder}
|
|
563
|
+
className="font-mono text-xs"
|
|
564
|
+
/>
|
|
565
|
+
</div>
|
|
566
|
+
</div>
|
|
567
|
+
|
|
568
|
+
<div className="flex gap-2">
|
|
569
|
+
<Button onClick={handleManualSubmit} fullWidth disabled={!callbackUrl}>
|
|
570
|
+
Connect
|
|
571
|
+
</Button>
|
|
572
|
+
<Button onClick={handleClose} variant="ghost" fullWidth>
|
|
573
|
+
Cancel
|
|
574
|
+
</Button>
|
|
575
|
+
</div>
|
|
576
|
+
</>
|
|
577
|
+
)}
|
|
578
|
+
|
|
579
|
+
{/* Device Code Flow - Waiting */}
|
|
580
|
+
{step === "waiting" && isDeviceCode && deviceData && (
|
|
581
|
+
<>
|
|
582
|
+
<div className="text-center py-4">
|
|
583
|
+
<p className="text-sm text-text-muted mb-4">
|
|
584
|
+
Visit the login URL below and authorize:
|
|
585
|
+
</p>
|
|
586
|
+
<div className="bg-sidebar p-4 rounded-lg mb-4">
|
|
587
|
+
<p className="text-xs text-text-muted mb-1">Login URL</p>
|
|
588
|
+
<div className="flex items-center gap-2">
|
|
589
|
+
<code className="flex-1 text-sm break-all">{deviceLoginUrl}</code>
|
|
590
|
+
<Button
|
|
591
|
+
size="sm"
|
|
592
|
+
variant="ghost"
|
|
593
|
+
icon={copied === "login_url" ? "check" : "content_copy"}
|
|
594
|
+
onClick={() => copy(deviceLoginUrl, "login_url")}
|
|
595
|
+
disabled={!deviceLoginUrl}
|
|
596
|
+
/>
|
|
597
|
+
<Button
|
|
598
|
+
size="sm"
|
|
599
|
+
variant="ghost"
|
|
600
|
+
icon="open_in_new"
|
|
601
|
+
onClick={() => window.open(deviceLoginUrl, "_blank", "noopener,noreferrer")}
|
|
602
|
+
disabled={!deviceLoginUrl}
|
|
603
|
+
>
|
|
604
|
+
Open
|
|
605
|
+
</Button>
|
|
606
|
+
</div>
|
|
607
|
+
</div>
|
|
608
|
+
<div className="bg-primary/10 p-4 rounded-lg">
|
|
609
|
+
<p className="text-xs text-text-muted mb-1">Your Code</p>
|
|
610
|
+
<div className="flex items-center justify-center gap-2">
|
|
611
|
+
<p className="text-2xl font-mono font-bold text-primary">{deviceData.user_code}</p>
|
|
612
|
+
<Button
|
|
613
|
+
size="sm"
|
|
614
|
+
variant="ghost"
|
|
615
|
+
icon={copied === "user_code" ? "check" : "content_copy"}
|
|
616
|
+
onClick={() => copy(deviceData.user_code, "user_code")}
|
|
617
|
+
/>
|
|
618
|
+
</div>
|
|
619
|
+
</div>
|
|
620
|
+
</div>
|
|
621
|
+
{polling && (
|
|
622
|
+
<div className="flex items-center justify-center gap-2 text-sm text-text-muted">
|
|
623
|
+
<span className="material-symbols-outlined animate-spin">progress_activity</span>
|
|
624
|
+
Waiting for authorization...
|
|
625
|
+
</div>
|
|
626
|
+
)}
|
|
627
|
+
</>
|
|
628
|
+
)}
|
|
629
|
+
|
|
630
|
+
{/* Success Step */}
|
|
631
|
+
{step === "success" && (
|
|
632
|
+
<div className="text-center py-6">
|
|
633
|
+
<div className="size-16 mx-auto mb-4 rounded-full bg-green-100 dark:bg-green-900/30 flex items-center justify-center">
|
|
634
|
+
<span className="material-symbols-outlined text-3xl text-green-600">check_circle</span>
|
|
635
|
+
</div>
|
|
636
|
+
<h3 className="text-lg font-semibold mb-2">Connected Successfully!</h3>
|
|
637
|
+
<p className="text-sm text-text-muted mb-4">
|
|
638
|
+
Your {providerInfo.name} account has been connected.
|
|
639
|
+
</p>
|
|
640
|
+
<Button onClick={handleClose} fullWidth>
|
|
641
|
+
Done
|
|
642
|
+
</Button>
|
|
643
|
+
</div>
|
|
644
|
+
)}
|
|
645
|
+
|
|
646
|
+
{/* Error Step */}
|
|
647
|
+
{step === "error" && (
|
|
648
|
+
<div className="text-center py-6">
|
|
649
|
+
<div className="size-16 mx-auto mb-4 rounded-full bg-red-100 dark:bg-red-900/30 flex items-center justify-center">
|
|
650
|
+
<span className="material-symbols-outlined text-3xl text-red-600">error</span>
|
|
651
|
+
</div>
|
|
652
|
+
<h3 className="text-lg font-semibold mb-2">Connection Failed</h3>
|
|
653
|
+
<p className="text-sm text-red-600 mb-4">{error}</p>
|
|
654
|
+
<div className="flex gap-2">
|
|
655
|
+
<Button onClick={startOAuthFlow} variant="secondary" fullWidth>
|
|
656
|
+
Try Again
|
|
657
|
+
</Button>
|
|
658
|
+
<Button onClick={handleClose} variant="ghost" fullWidth>
|
|
659
|
+
Cancel
|
|
660
|
+
</Button>
|
|
661
|
+
</div>
|
|
662
|
+
</div>
|
|
663
|
+
)}
|
|
664
|
+
</div>
|
|
665
|
+
</Modal>
|
|
666
|
+
);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
OAuthModal.propTypes = {
|
|
670
|
+
isOpen: PropTypes.bool.isRequired,
|
|
671
|
+
provider: PropTypes.string,
|
|
672
|
+
providerInfo: PropTypes.shape({ name: PropTypes.string }),
|
|
673
|
+
onSuccess: PropTypes.func,
|
|
674
|
+
onClose: PropTypes.func.isRequired,
|
|
675
|
+
/** Extra metadata passed to /authorize and /exchange (e.g. gitlab clientId/baseUrl) */
|
|
676
|
+
oauthMeta: PropTypes.object,
|
|
677
|
+
/** Optional Kiro IDC config for AWS IAM Identity Center device flow */
|
|
678
|
+
idcConfig: PropTypes.shape({
|
|
679
|
+
startUrl: PropTypes.string,
|
|
680
|
+
region: PropTypes.string,
|
|
681
|
+
}),
|
|
682
|
+
};
|