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,714 @@
|
|
|
1
|
+
import { getProviderConnectionById, updateProviderConnection } from "@/lib/localDb";
|
|
2
|
+
import { resolveConnectionProxyConfig } from "@/lib/network/connectionProxy";
|
|
3
|
+
import { testProxyUrl } from "@/lib/network/proxyTest";
|
|
4
|
+
import { isOpenAICompatibleProvider, isAnthropicCompatibleProvider } from "@/shared/constants/providers";
|
|
5
|
+
import { PROVIDER_ENDPOINTS } from "@/shared/constants/config";
|
|
6
|
+
import { getDefaultModel } from "open-sse/config/providerModels.js";
|
|
7
|
+
import { resolveOllamaLocalHost } from "open-sse/config/providers.js";
|
|
8
|
+
import {
|
|
9
|
+
refreshProviderCredentials,
|
|
10
|
+
shouldRefreshCredentials,
|
|
11
|
+
} from "open-sse/services/oauthCredentialManager.js";
|
|
12
|
+
import {
|
|
13
|
+
GEMINI_CONFIG,
|
|
14
|
+
ANTIGRAVITY_CONFIG,
|
|
15
|
+
KIRO_CONFIG,
|
|
16
|
+
QWEN_CONFIG,
|
|
17
|
+
CLAUDE_CONFIG,
|
|
18
|
+
CLINE_CONFIG,
|
|
19
|
+
KILOCODE_CONFIG,
|
|
20
|
+
CODEBUDDY_CONFIG,
|
|
21
|
+
} from "@/lib/oauth/constants/oauth";
|
|
22
|
+
import { buildClineHeaders } from "@/shared/utils/clineAuth";
|
|
23
|
+
|
|
24
|
+
// OAuth provider test endpoints
|
|
25
|
+
const OAUTH_TEST_CONFIG = {
|
|
26
|
+
claude: { checkExpiry: true, refreshable: true },
|
|
27
|
+
codex: {
|
|
28
|
+
url: "https://chatgpt.com/backend-api/codex/responses",
|
|
29
|
+
method: "POST",
|
|
30
|
+
authHeader: "Authorization",
|
|
31
|
+
authPrefix: "Bearer ",
|
|
32
|
+
extraHeaders: { "Content-Type": "application/json", "originator": "codex_cli_rs", "User-Agent": "codex_cli_rs/0.136.0" },
|
|
33
|
+
// Minimal invalid body — triggers fast 400 without consuming quota
|
|
34
|
+
body: JSON.stringify({ model: "gpt-5.3-codex", input: [], stream: false, store: false }),
|
|
35
|
+
// 400 (bad request) means auth succeeded; only 401/403 means token is bad
|
|
36
|
+
acceptStatuses: [400],
|
|
37
|
+
refreshable: true,
|
|
38
|
+
},
|
|
39
|
+
"gemini-cli": {
|
|
40
|
+
url: "https://www.googleapis.com/oauth2/v1/userinfo?alt=json",
|
|
41
|
+
method: "GET",
|
|
42
|
+
authHeader: "Authorization",
|
|
43
|
+
authPrefix: "Bearer ",
|
|
44
|
+
refreshable: true,
|
|
45
|
+
},
|
|
46
|
+
antigravity: {
|
|
47
|
+
url: "https://www.googleapis.com/oauth2/v1/userinfo?alt=json",
|
|
48
|
+
method: "GET",
|
|
49
|
+
authHeader: "Authorization",
|
|
50
|
+
authPrefix: "Bearer ",
|
|
51
|
+
refreshable: true,
|
|
52
|
+
},
|
|
53
|
+
github: {
|
|
54
|
+
url: "https://api.github.com/user",
|
|
55
|
+
method: "GET",
|
|
56
|
+
authHeader: "Authorization",
|
|
57
|
+
authPrefix: "Bearer ",
|
|
58
|
+
extraHeaders: { "User-Agent": "9Router", "Accept": "application/vnd.github+json" },
|
|
59
|
+
},
|
|
60
|
+
iflow: {
|
|
61
|
+
// iFlow getUserInfo requires accessToken as query param, not header
|
|
62
|
+
buildUrl: (token) => `https://iflow.cn/api/oauth/getUserInfo?accessToken=${encodeURIComponent(token)}`,
|
|
63
|
+
method: "GET",
|
|
64
|
+
noAuth: true,
|
|
65
|
+
},
|
|
66
|
+
qwen: { checkExpiry: true, refreshable: true },
|
|
67
|
+
kiro: { checkExpiry: true, refreshable: true },
|
|
68
|
+
qoder: {
|
|
69
|
+
// Test by hitting Qoder's userinfo endpoint with the device token.
|
|
70
|
+
// refreshable: false because the device-flow refresh endpoint returns
|
|
71
|
+
// 403 for our flow (users re-login when expired). No checkExpiry —
|
|
72
|
+
// we want the actual URL probe to run so revoked tokens surface.
|
|
73
|
+
url: "https://openapi.qoder.sh/api/v1/userinfo",
|
|
74
|
+
method: "GET",
|
|
75
|
+
authHeader: "Authorization",
|
|
76
|
+
authPrefix: "Bearer ",
|
|
77
|
+
refreshable: false,
|
|
78
|
+
},
|
|
79
|
+
"kimi-coding": { checkExpiry: true, refreshable: false },
|
|
80
|
+
cursor: { tokenExists: true },
|
|
81
|
+
kilocode: {
|
|
82
|
+
url: `${KILOCODE_CONFIG.apiBaseUrl}/api/profile`,
|
|
83
|
+
method: "GET",
|
|
84
|
+
authHeader: "Authorization",
|
|
85
|
+
authPrefix: "Bearer ",
|
|
86
|
+
},
|
|
87
|
+
cline: { refreshable: true },
|
|
88
|
+
gitlab: {
|
|
89
|
+
// Test by hitting the GitLab user API — requires api or read_user scope
|
|
90
|
+
url: "https://gitlab.com/api/v4/user",
|
|
91
|
+
method: "GET",
|
|
92
|
+
authHeader: "Authorization",
|
|
93
|
+
authPrefix: "Bearer ",
|
|
94
|
+
},
|
|
95
|
+
codebuddy: { tokenExists: true },
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
async function probeClineAccessToken(accessToken) {
|
|
99
|
+
const res = await fetch("https://api.cline.bot/api/v1/users/me", {
|
|
100
|
+
method: "GET",
|
|
101
|
+
headers: buildClineHeaders(accessToken, {
|
|
102
|
+
Accept: "application/json",
|
|
103
|
+
}),
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
return res;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function refreshOAuthToken(connection) {
|
|
110
|
+
const provider = connection.provider;
|
|
111
|
+
const refreshToken = connection.refreshToken;
|
|
112
|
+
if (!refreshToken) return null;
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
if (provider === "gemini-cli" || provider === "antigravity") {
|
|
116
|
+
const config = provider === "gemini-cli" ? GEMINI_CONFIG : ANTIGRAVITY_CONFIG;
|
|
117
|
+
const response = await fetch("https://oauth2.googleapis.com/token", {
|
|
118
|
+
method: "POST",
|
|
119
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
120
|
+
body: new URLSearchParams({
|
|
121
|
+
client_id: config.clientId,
|
|
122
|
+
client_secret: config.clientSecret,
|
|
123
|
+
grant_type: "refresh_token",
|
|
124
|
+
refresh_token: refreshToken,
|
|
125
|
+
}),
|
|
126
|
+
});
|
|
127
|
+
if (!response.ok) return null;
|
|
128
|
+
const data = await response.json();
|
|
129
|
+
return { accessToken: data.access_token, expiresIn: data.expires_in, refreshToken: data.refresh_token || refreshToken };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (provider === "codex") {
|
|
133
|
+
return await refreshProviderCredentials(provider, connection, console);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (provider === "claude") {
|
|
137
|
+
const response = await fetch(CLAUDE_CONFIG.tokenUrl, {
|
|
138
|
+
method: "POST",
|
|
139
|
+
headers: { "Content-Type": "application/json", "Accept": "application/json" },
|
|
140
|
+
body: JSON.stringify({
|
|
141
|
+
grant_type: "refresh_token",
|
|
142
|
+
refresh_token: refreshToken,
|
|
143
|
+
client_id: CLAUDE_CONFIG.clientId,
|
|
144
|
+
}),
|
|
145
|
+
});
|
|
146
|
+
if (!response.ok) return null;
|
|
147
|
+
const data = await response.json();
|
|
148
|
+
return { accessToken: data.access_token, expiresIn: data.expires_in, refreshToken: data.refresh_token || refreshToken };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (provider === "kiro") {
|
|
152
|
+
const psd = connection.providerSpecificData || {};
|
|
153
|
+
const clientId = psd.clientId || connection.clientId;
|
|
154
|
+
const clientSecret = psd.clientSecret || connection.clientSecret;
|
|
155
|
+
const region = psd.region || connection.region;
|
|
156
|
+
if (clientId && clientSecret) {
|
|
157
|
+
const endpoint = `https://oidc.${region || "us-east-1"}.amazonaws.com/token`;
|
|
158
|
+
const response = await fetch(endpoint, {
|
|
159
|
+
method: "POST",
|
|
160
|
+
headers: { "Content-Type": "application/json" },
|
|
161
|
+
body: JSON.stringify({ clientId, clientSecret, refreshToken, grantType: "refresh_token" }),
|
|
162
|
+
});
|
|
163
|
+
if (!response.ok) return null;
|
|
164
|
+
const data = await response.json();
|
|
165
|
+
return { accessToken: data.accessToken, expiresIn: data.expiresIn || 3600, refreshToken: data.refreshToken || refreshToken };
|
|
166
|
+
}
|
|
167
|
+
const response = await fetch(KIRO_CONFIG.socialRefreshUrl, {
|
|
168
|
+
method: "POST",
|
|
169
|
+
headers: { "Content-Type": "application/json", "User-Agent": "kiro-cli/1.0.0" },
|
|
170
|
+
body: JSON.stringify({ refreshToken }),
|
|
171
|
+
});
|
|
172
|
+
if (!response.ok) return null;
|
|
173
|
+
const data = await response.json();
|
|
174
|
+
return { accessToken: data.accessToken, expiresIn: data.expiresIn || 3600, refreshToken: data.refreshToken || refreshToken };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (provider === "qwen") {
|
|
178
|
+
const response = await fetch(QWEN_CONFIG.tokenUrl, {
|
|
179
|
+
method: "POST",
|
|
180
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json" },
|
|
181
|
+
body: new URLSearchParams({
|
|
182
|
+
grant_type: "refresh_token",
|
|
183
|
+
refresh_token: refreshToken,
|
|
184
|
+
client_id: QWEN_CONFIG.clientId,
|
|
185
|
+
}),
|
|
186
|
+
});
|
|
187
|
+
if (!response.ok) return null;
|
|
188
|
+
const data = await response.json();
|
|
189
|
+
return { accessToken: data.access_token, expiresIn: data.expires_in, refreshToken: data.refresh_token || refreshToken };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (provider === "cline") {
|
|
193
|
+
const response = await fetch(CLINE_CONFIG.refreshUrl, {
|
|
194
|
+
method: "POST",
|
|
195
|
+
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
|
196
|
+
body: JSON.stringify({
|
|
197
|
+
refreshToken,
|
|
198
|
+
grantType: "refresh_token",
|
|
199
|
+
clientType: "extension",
|
|
200
|
+
}),
|
|
201
|
+
});
|
|
202
|
+
if (!response.ok) return null;
|
|
203
|
+
const payload = await response.json();
|
|
204
|
+
const data = payload?.data || payload;
|
|
205
|
+
const expiresIn = data?.expiresAt
|
|
206
|
+
? Math.max(1, Math.floor((new Date(data.expiresAt).getTime() - Date.now()) / 1000))
|
|
207
|
+
: 3600;
|
|
208
|
+
return {
|
|
209
|
+
accessToken: data?.accessToken,
|
|
210
|
+
expiresIn,
|
|
211
|
+
refreshToken: data?.refreshToken || refreshToken,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (provider === "codebuddy") {
|
|
216
|
+
const response = await fetch(CODEBUDDY_CONFIG.refreshUrl, {
|
|
217
|
+
method: "POST",
|
|
218
|
+
headers: {
|
|
219
|
+
"Content-Type": "application/json",
|
|
220
|
+
Accept: "application/json",
|
|
221
|
+
"User-Agent": CODEBUDDY_CONFIG.userAgent,
|
|
222
|
+
"X-Requested-With": "XMLHttpRequest",
|
|
223
|
+
"X-Domain": CODEBUDDY_CONFIG.domain,
|
|
224
|
+
"X-Refresh-Token": refreshToken,
|
|
225
|
+
"X-Auth-Refresh-Source": "plugin",
|
|
226
|
+
"X-Product": "SaaS",
|
|
227
|
+
},
|
|
228
|
+
body: "{}",
|
|
229
|
+
});
|
|
230
|
+
if (!response.ok) return null;
|
|
231
|
+
const payload = await response.json();
|
|
232
|
+
const data = payload?.data || payload;
|
|
233
|
+
const accessToken = data?.accessToken || data?.access_token;
|
|
234
|
+
if (!accessToken) return null;
|
|
235
|
+
return {
|
|
236
|
+
accessToken,
|
|
237
|
+
expiresIn: data?.expiresIn || data?.expires_in || 86400,
|
|
238
|
+
refreshToken: data?.refreshToken || data?.refresh_token || refreshToken,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return null;
|
|
243
|
+
} catch (err) {
|
|
244
|
+
console.log(`Error refreshing ${provider} token:`, err.message);
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function isTokenExpired(connection) {
|
|
250
|
+
return shouldRefreshCredentials(connection.provider, connection);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async function testOAuthConnection(connection, effectiveProxy = null) {
|
|
254
|
+
const config = OAUTH_TEST_CONFIG[connection.provider];
|
|
255
|
+
if (!config) return { valid: false, error: "Provider test not supported", refreshed: false };
|
|
256
|
+
if (!connection.accessToken) return { valid: false, error: "No access token", refreshed: false };
|
|
257
|
+
|
|
258
|
+
// Cursor uses protobuf API - can only verify token exists, not test endpoint
|
|
259
|
+
if (config.tokenExists) {
|
|
260
|
+
return { valid: true, error: null, refreshed: false, newTokens: null };
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
let accessToken = connection.accessToken;
|
|
264
|
+
let refreshed = false;
|
|
265
|
+
let newTokens = null;
|
|
266
|
+
|
|
267
|
+
const tokenExpired = isTokenExpired(connection);
|
|
268
|
+
if (config.refreshable && tokenExpired && connection.refreshToken) {
|
|
269
|
+
const tokens = await refreshOAuthToken(connection);
|
|
270
|
+
if (tokens) {
|
|
271
|
+
accessToken = tokens.accessToken;
|
|
272
|
+
refreshed = true;
|
|
273
|
+
newTokens = tokens;
|
|
274
|
+
} else {
|
|
275
|
+
return { valid: false, error: "Token expired and refresh failed", refreshed: false };
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (config.checkExpiry) {
|
|
280
|
+
if (refreshed) return { valid: true, error: null, refreshed, newTokens };
|
|
281
|
+
if (tokenExpired) return { valid: false, error: "Token expired", refreshed: false };
|
|
282
|
+
return { valid: true, error: null, refreshed: false, newTokens: null };
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (connection.provider === "cline") {
|
|
286
|
+
const tryProbe = async (token) => {
|
|
287
|
+
const res = await probeClineAccessToken(token);
|
|
288
|
+
if (res.ok) return { valid: true, error: null, refreshed, newTokens };
|
|
289
|
+
if (res.status === 401) return { valid: false, error: "Token invalid or revoked", refreshed };
|
|
290
|
+
if (res.status === 403) return { valid: false, error: "Access denied", refreshed };
|
|
291
|
+
return { valid: false, error: `API returned ${res.status}`, refreshed };
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
const initial = await tryProbe(accessToken);
|
|
295
|
+
if (initial.valid || initial.error !== "Token invalid or revoked" || !connection.refreshToken) {
|
|
296
|
+
return initial;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const tokens = await refreshOAuthToken(connection);
|
|
300
|
+
if (!tokens?.accessToken) {
|
|
301
|
+
return { valid: false, error: "Token invalid or revoked", refreshed: false };
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
refreshed = true;
|
|
305
|
+
newTokens = tokens;
|
|
306
|
+
accessToken = tokens.accessToken;
|
|
307
|
+
return await tryProbe(accessToken);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
try {
|
|
311
|
+
const testUrl = config.buildUrl ? config.buildUrl(accessToken) : config.url;
|
|
312
|
+
const headers = config.noAuth
|
|
313
|
+
? { ...config.extraHeaders }
|
|
314
|
+
: { [config.authHeader]: `${config.authPrefix}${accessToken}`, ...config.extraHeaders };
|
|
315
|
+
const fetchOpts = { method: config.method, headers };
|
|
316
|
+
if (config.body) fetchOpts.body = config.body;
|
|
317
|
+
const res = await fetchWithConnectionProxy(testUrl, fetchOpts, effectiveProxy);
|
|
318
|
+
|
|
319
|
+
const accepted = res.ok || (config.acceptStatuses && config.acceptStatuses.includes(res.status));
|
|
320
|
+
if (accepted) return { valid: true, error: null, refreshed, newTokens };
|
|
321
|
+
|
|
322
|
+
if (res.status === 401 && config.refreshable && !refreshed && connection.refreshToken) {
|
|
323
|
+
const tokens = await refreshOAuthToken(connection);
|
|
324
|
+
if (tokens) {
|
|
325
|
+
const retryUrl = config.buildUrl ? config.buildUrl(tokens.accessToken) : testUrl;
|
|
326
|
+
const retryHeaders = config.noAuth
|
|
327
|
+
? { ...config.extraHeaders }
|
|
328
|
+
: { [config.authHeader]: `${config.authPrefix}${tokens.accessToken}`, ...config.extraHeaders };
|
|
329
|
+
const retryOpts = { method: config.method, headers: retryHeaders };
|
|
330
|
+
if (config.body) retryOpts.body = config.body;
|
|
331
|
+
const retryRes = await fetchWithConnectionProxy(retryUrl, retryOpts, effectiveProxy);
|
|
332
|
+
const retryAccepted = retryRes.ok || (config.acceptStatuses && config.acceptStatuses.includes(retryRes.status));
|
|
333
|
+
if (retryAccepted) return { valid: true, error: null, refreshed: true, newTokens: tokens };
|
|
334
|
+
}
|
|
335
|
+
return { valid: false, error: "Token invalid or revoked", refreshed: false };
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (res.status === 401) return { valid: false, error: "Token invalid or revoked", refreshed };
|
|
339
|
+
if (res.status === 403) return { valid: false, error: "Access denied", refreshed };
|
|
340
|
+
return { valid: false, error: `API returned ${res.status}`, refreshed };
|
|
341
|
+
} catch (err) {
|
|
342
|
+
return { valid: false, error: err.message, refreshed };
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
async function fetchWithConnectionProxy(url, options = {}, effectiveProxy = null) {
|
|
347
|
+
// Vercel relay: forward via relay URL
|
|
348
|
+
if (effectiveProxy?.vercelRelayUrl) {
|
|
349
|
+
const { proxyAwareFetch } = await import("open-sse/utils/proxyFetch.js");
|
|
350
|
+
return proxyAwareFetch(url, options, {
|
|
351
|
+
vercelRelayUrl: effectiveProxy.vercelRelayUrl,
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (!effectiveProxy?.connectionProxyEnabled || !effectiveProxy?.connectionProxyUrl) {
|
|
356
|
+
return fetch(url, options);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const { proxyAwareFetch } = await import("open-sse/utils/proxyFetch.js");
|
|
360
|
+
return proxyAwareFetch(url, options, {
|
|
361
|
+
connectionProxyEnabled: true,
|
|
362
|
+
connectionProxyUrl: effectiveProxy.connectionProxyUrl,
|
|
363
|
+
connectionNoProxy: effectiveProxy.connectionNoProxy || "",
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
async function testApiKeyConnection(connection, effectiveProxy = null) {
|
|
368
|
+
if (isOpenAICompatibleProvider(connection.provider)) {
|
|
369
|
+
const modelsBase = connection.providerSpecificData?.baseUrl;
|
|
370
|
+
if (!modelsBase) return { valid: false, error: "Missing base URL" };
|
|
371
|
+
try {
|
|
372
|
+
const res = await fetchWithConnectionProxy(`${modelsBase.replace(/\/$/, "")}/models`, {
|
|
373
|
+
headers: { "Authorization": `Bearer ${connection.apiKey}` },
|
|
374
|
+
}, effectiveProxy);
|
|
375
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key or base URL" };
|
|
376
|
+
} catch (err) {
|
|
377
|
+
return { valid: false, error: err.message };
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
if (isAnthropicCompatibleProvider(connection.provider)) {
|
|
382
|
+
let modelsBase = connection.providerSpecificData?.baseUrl;
|
|
383
|
+
if (!modelsBase) return { valid: false, error: "Missing base URL" };
|
|
384
|
+
try {
|
|
385
|
+
modelsBase = modelsBase.replace(/\/$/, "");
|
|
386
|
+
if (modelsBase.endsWith("/messages")) modelsBase = modelsBase.slice(0, -9);
|
|
387
|
+
const res = await fetchWithConnectionProxy(`${modelsBase}/models`, {
|
|
388
|
+
headers: { "x-api-key": connection.apiKey, "anthropic-version": "2023-06-01", "Authorization": `Bearer ${connection.apiKey}` },
|
|
389
|
+
}, effectiveProxy);
|
|
390
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key or base URL" };
|
|
391
|
+
} catch (err) {
|
|
392
|
+
return { valid: false, error: err.message };
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
try {
|
|
397
|
+
switch (connection.provider) {
|
|
398
|
+
case "cloudflare-ai": {
|
|
399
|
+
const psd = connection.providerSpecificData || {};
|
|
400
|
+
const accountId = psd.accountId;
|
|
401
|
+
if (!accountId) return { valid: false, error: "Missing Account ID" };
|
|
402
|
+
const url = `https://api.cloudflare.com/client/v4/accounts/${accountId}/ai/v1/chat/completions`;
|
|
403
|
+
const res = await fetchWithConnectionProxy(url, {
|
|
404
|
+
method: "POST",
|
|
405
|
+
headers: { "Authorization": `Bearer ${connection.apiKey}`, "Content-Type": "application/json" },
|
|
406
|
+
body: JSON.stringify({ model: getDefaultModel("cloudflare-ai"), messages: [{ role: "user", content: "test" }], max_tokens: 1 }),
|
|
407
|
+
}, effectiveProxy);
|
|
408
|
+
const valid = res.status !== 401 && res.status !== 403 && res.status !== 404;
|
|
409
|
+
return { valid, error: valid ? null : "Invalid API token or Account ID" };
|
|
410
|
+
}
|
|
411
|
+
case "azure": {
|
|
412
|
+
const psd = connection.providerSpecificData || {};
|
|
413
|
+
const endpoint = (psd.azureEndpoint || "").replace(/\/$/, "");
|
|
414
|
+
const deployment = psd.deployment || "gpt-4";
|
|
415
|
+
const apiVersion = psd.apiVersion || "2024-10-01-preview";
|
|
416
|
+
const url = `${endpoint}/openai/deployments/${deployment}/chat/completions?api-version=${apiVersion}`;
|
|
417
|
+
const headers = { "api-key": connection.apiKey, "Content-Type": "application/json" };
|
|
418
|
+
if (psd.organization) headers["OpenAI-Organization"] = psd.organization;
|
|
419
|
+
const res = await fetchWithConnectionProxy(url, {
|
|
420
|
+
method: "POST", headers,
|
|
421
|
+
body: JSON.stringify({ messages: [{ role: "user", content: "test" }], max_completion_tokens: 1 }),
|
|
422
|
+
}, effectiveProxy);
|
|
423
|
+
const valid = res.status !== 401 && res.status !== 403;
|
|
424
|
+
return { valid, error: valid ? null : "Invalid API key or Azure configuration" };
|
|
425
|
+
}
|
|
426
|
+
case "openai": {
|
|
427
|
+
const res = await fetchWithConnectionProxy("https://api.openai.com/v1/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
|
|
428
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
429
|
+
}
|
|
430
|
+
case "vercel-ai-gateway": {
|
|
431
|
+
const res = await fetchWithConnectionProxy("https://ai-gateway.vercel.sh/v1/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
|
|
432
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
433
|
+
}
|
|
434
|
+
case "anthropic": {
|
|
435
|
+
const res = await fetchWithConnectionProxy("https://api.anthropic.com/v1/messages", {
|
|
436
|
+
method: "POST",
|
|
437
|
+
headers: { "x-api-key": connection.apiKey, "anthropic-version": "2023-06-01", "content-type": "application/json" },
|
|
438
|
+
body: JSON.stringify({ model: "claude-3-haiku-20240307", max_tokens: 1, messages: [{ role: "user", content: "test" }] }),
|
|
439
|
+
}, effectiveProxy);
|
|
440
|
+
const valid = res.status !== 401;
|
|
441
|
+
return { valid, error: valid ? null : "Invalid API key" };
|
|
442
|
+
}
|
|
443
|
+
case "gemini": {
|
|
444
|
+
const res = await fetchWithConnectionProxy(`https://generativelanguage.googleapis.com/v1/models?key=${connection.apiKey}`, {}, effectiveProxy);
|
|
445
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
446
|
+
}
|
|
447
|
+
case "openrouter": {
|
|
448
|
+
const res = await fetchWithConnectionProxy("https://openrouter.ai/api/v1/auth/key", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
|
|
449
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
450
|
+
}
|
|
451
|
+
case "glm": {
|
|
452
|
+
const res = await fetchWithConnectionProxy("https://api.z.ai/api/anthropic/v1/messages", {
|
|
453
|
+
method: "POST",
|
|
454
|
+
headers: { "x-api-key": connection.apiKey, "anthropic-version": "2023-06-01", "content-type": "application/json" },
|
|
455
|
+
body: JSON.stringify({ model: "glm-4.7", max_tokens: 1, messages: [{ role: "user", content: "test" }] }),
|
|
456
|
+
}, effectiveProxy);
|
|
457
|
+
const valid = res.status !== 401 && res.status !== 403;
|
|
458
|
+
return { valid, error: valid ? null : "Invalid API key" };
|
|
459
|
+
}
|
|
460
|
+
case "glm-cn": {
|
|
461
|
+
const res = await fetchWithConnectionProxy("https://open.bigmodel.cn/api/coding/paas/v4/chat/completions", {
|
|
462
|
+
method: "POST",
|
|
463
|
+
headers: { "Authorization": `Bearer ${connection.apiKey}`, "content-type": "application/json" },
|
|
464
|
+
body: JSON.stringify({ model: "glm-4.7", max_tokens: 1, messages: [{ role: "user", content: "test" }] }),
|
|
465
|
+
}, effectiveProxy);
|
|
466
|
+
const valid = res.status !== 401 && res.status !== 403;
|
|
467
|
+
return { valid, error: valid ? null : "Invalid API key" };
|
|
468
|
+
}
|
|
469
|
+
case "minimax":
|
|
470
|
+
case "minimax-cn": {
|
|
471
|
+
const endpoints = { minimax: "https://api.minimax.io/anthropic/v1/messages", "minimax-cn": "https://api.minimaxi.com/anthropic/v1/messages" };
|
|
472
|
+
const res = await fetchWithConnectionProxy(endpoints[connection.provider], {
|
|
473
|
+
method: "POST",
|
|
474
|
+
headers: { "x-api-key": connection.apiKey, "anthropic-version": "2023-06-01", "content-type": "application/json" },
|
|
475
|
+
body: JSON.stringify({ model: "minimax-m2", max_tokens: 1, messages: [{ role: "user", content: "test" }] }),
|
|
476
|
+
}, effectiveProxy);
|
|
477
|
+
const valid = res.status !== 401 && res.status !== 403;
|
|
478
|
+
return { valid, error: valid ? null : "Invalid API key" };
|
|
479
|
+
}
|
|
480
|
+
case "kimi": {
|
|
481
|
+
const res = await fetchWithConnectionProxy("https://api.kimi.com/coding/v1/messages", {
|
|
482
|
+
method: "POST",
|
|
483
|
+
headers: { "x-api-key": connection.apiKey, "anthropic-version": "2023-06-01", "content-type": "application/json" },
|
|
484
|
+
body: JSON.stringify({ model: "kimi-latest", max_tokens: 1, messages: [{ role: "user", content: "test" }] }),
|
|
485
|
+
}, effectiveProxy);
|
|
486
|
+
const valid = res.status !== 401 && res.status !== 403;
|
|
487
|
+
return { valid, error: valid ? null : "Invalid API key" };
|
|
488
|
+
}
|
|
489
|
+
case "alicode":
|
|
490
|
+
case "alicode-intl": {
|
|
491
|
+
// Aliyun Coding Plan uses OpenAI-compatible API
|
|
492
|
+
const aliBaseUrl = connection.provider === "alicode-intl"
|
|
493
|
+
? "https://coding-intl.dashscope.aliyuncs.com/v1/chat/completions"
|
|
494
|
+
: "https://coding.dashscope.aliyuncs.com/v1/chat/completions";
|
|
495
|
+
const res = await fetchWithConnectionProxy(aliBaseUrl, {
|
|
496
|
+
method: "POST",
|
|
497
|
+
headers: { "Authorization": `Bearer ${connection.apiKey}`, "content-type": "application/json" },
|
|
498
|
+
body: JSON.stringify({ model: getDefaultModel(connection.provider), max_tokens: 1, messages: [{ role: "user", content: "test" }] }),
|
|
499
|
+
}, effectiveProxy);
|
|
500
|
+
const valid = res.status !== 401 && res.status !== 403;
|
|
501
|
+
return { valid, error: valid ? null : "Invalid API key" };
|
|
502
|
+
}
|
|
503
|
+
case "volcengine-ark":
|
|
504
|
+
case "byteplus": {
|
|
505
|
+
const res = await fetchWithConnectionProxy(PROVIDER_ENDPOINTS[connection.provider], {
|
|
506
|
+
method: "POST",
|
|
507
|
+
headers: { "Authorization": `Bearer ${connection.apiKey}`, "content-type": "application/json" },
|
|
508
|
+
body: JSON.stringify({ model: getDefaultModel(connection.provider), max_tokens: 1, messages: [{ role: "user", content: "test" }] }),
|
|
509
|
+
}, effectiveProxy);
|
|
510
|
+
const valid = res.status !== 401 && res.status !== 403;
|
|
511
|
+
return { valid, error: valid ? null : "Invalid API key" };
|
|
512
|
+
}
|
|
513
|
+
case "deepseek": {
|
|
514
|
+
const res = await fetchWithConnectionProxy("https://api.deepseek.com/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
|
|
515
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
516
|
+
}
|
|
517
|
+
case "groq": {
|
|
518
|
+
const res = await fetchWithConnectionProxy("https://api.groq.com/openai/v1/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
|
|
519
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
520
|
+
}
|
|
521
|
+
case "mistral": {
|
|
522
|
+
const res = await fetchWithConnectionProxy("https://api.mistral.ai/v1/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
|
|
523
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
524
|
+
}
|
|
525
|
+
case "xai": {
|
|
526
|
+
const res = await fetchWithConnectionProxy("https://api.x.ai/v1/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
|
|
527
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
528
|
+
}
|
|
529
|
+
case "nvidia": {
|
|
530
|
+
const res = await fetchWithConnectionProxy("https://integrate.api.nvidia.com/v1/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
|
|
531
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
532
|
+
}
|
|
533
|
+
case "perplexity": {
|
|
534
|
+
const res = await fetchWithConnectionProxy("https://api.perplexity.ai/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
|
|
535
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
536
|
+
}
|
|
537
|
+
case "together": {
|
|
538
|
+
const res = await fetchWithConnectionProxy("https://api.together.xyz/v1/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
|
|
539
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
540
|
+
}
|
|
541
|
+
case "fireworks": {
|
|
542
|
+
const res = await fetchWithConnectionProxy("https://api.fireworks.ai/inference/v1/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
|
|
543
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
544
|
+
}
|
|
545
|
+
case "cerebras": {
|
|
546
|
+
const res = await fetchWithConnectionProxy("https://api.cerebras.ai/v1/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
|
|
547
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
548
|
+
}
|
|
549
|
+
case "cohere": {
|
|
550
|
+
const res = await fetchWithConnectionProxy("https://api.cohere.ai/v1/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
|
|
551
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
552
|
+
}
|
|
553
|
+
case "nebius": {
|
|
554
|
+
const res = await fetchWithConnectionProxy("https://api.studio.nebius.ai/v1/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
|
|
555
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
556
|
+
}
|
|
557
|
+
case "siliconflow": {
|
|
558
|
+
const res = await fetchWithConnectionProxy("https://api.siliconflow.cn/v1/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
|
|
559
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
560
|
+
}
|
|
561
|
+
case "hyperbolic": {
|
|
562
|
+
const res = await fetchWithConnectionProxy("https://api.hyperbolic.xyz/v1/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
|
|
563
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
564
|
+
}
|
|
565
|
+
case "ollama": {
|
|
566
|
+
const res = await fetch("https://ollama.com/api/tags", { headers: { Authorization: `Bearer ${connection.apiKey}` } });
|
|
567
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
568
|
+
}
|
|
569
|
+
case "ollama-local": {
|
|
570
|
+
const host = resolveOllamaLocalHost(connection);
|
|
571
|
+
const res = await fetch(`${host}/api/tags`);
|
|
572
|
+
return { valid: res.ok, error: res.ok ? null : `Ollama not reachable at ${host}` };
|
|
573
|
+
}
|
|
574
|
+
case "deepgram": {
|
|
575
|
+
const res = await fetchWithConnectionProxy("https://api.deepgram.com/v1/projects", { headers: { Authorization: `Token ${connection.apiKey}` } }, effectiveProxy);
|
|
576
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
577
|
+
}
|
|
578
|
+
case "assemblyai": {
|
|
579
|
+
const res = await fetchWithConnectionProxy("https://api.assemblyai.com/v1/account", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
|
|
580
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
581
|
+
}
|
|
582
|
+
case "nanobanana": {
|
|
583
|
+
const res = await fetchWithConnectionProxy("https://api.nanobananaapi.ai/v1/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
|
|
584
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
585
|
+
}
|
|
586
|
+
case "fal-ai": {
|
|
587
|
+
const res = await fetchWithConnectionProxy("https://api.fal.ai/v1/models?limit=1", { headers: { Authorization: `Key ${connection.apiKey}` } }, effectiveProxy);
|
|
588
|
+
const valid = res.status !== 401 && res.status !== 403;
|
|
589
|
+
return { valid, error: valid ? null : "Invalid API key" };
|
|
590
|
+
}
|
|
591
|
+
case "chutes": {
|
|
592
|
+
const res = await fetchWithConnectionProxy("https://llm.chutes.ai/v1/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
|
|
593
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
594
|
+
}
|
|
595
|
+
case "grok-web": {
|
|
596
|
+
const token = connection.apiKey.startsWith("sso=") ? connection.apiKey.slice(4) : connection.apiKey;
|
|
597
|
+
const randomHex = (n) => Array.from(crypto.getRandomValues(new Uint8Array(n)), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
598
|
+
const statsigId = Buffer.from("e:TypeError: Cannot read properties of null (reading 'children')").toString("base64");
|
|
599
|
+
const res = await fetchWithConnectionProxy("https://grok.com/rest/app-chat/conversations/new", {
|
|
600
|
+
method: "POST",
|
|
601
|
+
headers: {
|
|
602
|
+
Accept: "*/*", "Content-Type": "application/json",
|
|
603
|
+
Cookie: `sso=${token}`, Origin: "https://grok.com", Referer: "https://grok.com/",
|
|
604
|
+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36",
|
|
605
|
+
"x-statsig-id": statsigId, "x-xai-request-id": crypto.randomUUID(),
|
|
606
|
+
traceparent: `00-${randomHex(16)}-${randomHex(8)}-00`,
|
|
607
|
+
},
|
|
608
|
+
body: JSON.stringify({ temporary: true, modelName: "grok-4", message: "ping", fileAttachments: [], imageAttachments: [], disableSearch: false, enableImageGeneration: false, sendFinalMetadata: true }),
|
|
609
|
+
}, effectiveProxy);
|
|
610
|
+
const valid = res.status !== 401 && res.status !== 403;
|
|
611
|
+
return { valid, error: valid ? null : "Invalid SSO cookie" };
|
|
612
|
+
}
|
|
613
|
+
case "perplexity-web": {
|
|
614
|
+
let sessionToken = connection.apiKey;
|
|
615
|
+
if (sessionToken.startsWith("__Secure-next-auth.session-token=")) sessionToken = sessionToken.slice("__Secure-next-auth.session-token=".length);
|
|
616
|
+
const res = await fetchWithConnectionProxy("https://www.perplexity.ai/api/auth/session", {
|
|
617
|
+
method: "GET",
|
|
618
|
+
headers: {
|
|
619
|
+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36",
|
|
620
|
+
Cookie: `__Secure-next-auth.session-token=${sessionToken}`,
|
|
621
|
+
},
|
|
622
|
+
}, effectiveProxy);
|
|
623
|
+
if (!res.ok) return { valid: false, error: "Invalid session cookie" };
|
|
624
|
+
const data = await res.json().catch(() => null);
|
|
625
|
+
const valid = !!(data && data.user);
|
|
626
|
+
return { valid, error: valid ? null : "Session expired — re-paste cookie" };
|
|
627
|
+
}
|
|
628
|
+
case "opencode-go": {
|
|
629
|
+
const res = await fetchWithConnectionProxy("https://opencode.ai/zen/go/v1/chat/completions", {
|
|
630
|
+
method: "POST",
|
|
631
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${connection.apiKey}` },
|
|
632
|
+
body: JSON.stringify({ model: getDefaultModel("opencode-go"), messages: [{ role: "user", content: "ping" }], max_tokens: 1, stream: false }),
|
|
633
|
+
}, effectiveProxy);
|
|
634
|
+
const valid = res.status !== 401 && res.status !== 403;
|
|
635
|
+
return { valid, error: valid ? null : "Invalid API key" };
|
|
636
|
+
}
|
|
637
|
+
case "xiaomi-mimo":
|
|
638
|
+
case "xiaomi-tokenplan": {
|
|
639
|
+
const baseUrls = { "xiaomi-mimo": "https://api.xiaomimimo.com/v1", "xiaomi-tokenplan": "https://token-plan-sgp.xiaomimimo.com/v1" };
|
|
640
|
+
const res = await fetchWithConnectionProxy(`${baseUrls[connection.provider]}/models`, {
|
|
641
|
+
headers: { Authorization: `Bearer ${connection.apiKey}` },
|
|
642
|
+
}, effectiveProxy);
|
|
643
|
+
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
|
644
|
+
}
|
|
645
|
+
default:
|
|
646
|
+
return { valid: false, error: "Provider test not supported" };
|
|
647
|
+
}
|
|
648
|
+
} catch (err) {
|
|
649
|
+
return { valid: false, error: err.message };
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* Test a single connection by ID, update DB, and return result.
|
|
655
|
+
*/
|
|
656
|
+
export async function testSingleConnection(id) {
|
|
657
|
+
const connection = await getProviderConnectionById(id);
|
|
658
|
+
if (!connection) return { valid: false, error: "Connection not found", latencyMs: 0, testedAt: new Date().toISOString() };
|
|
659
|
+
|
|
660
|
+
const effectiveProxy = await resolveConnectionProxyConfig(connection.providerSpecificData || {});
|
|
661
|
+
|
|
662
|
+
if (effectiveProxy.connectionProxyEnabled && effectiveProxy.connectionProxyUrl && !effectiveProxy.vercelRelayUrl) {
|
|
663
|
+
const proxyResult = await testProxyUrl({ proxyUrl: effectiveProxy.connectionProxyUrl });
|
|
664
|
+
if (!proxyResult.ok) {
|
|
665
|
+
const proxyError = proxyResult.error || `Proxy test failed with status ${proxyResult.status}`;
|
|
666
|
+
await updateProviderConnection(id, {
|
|
667
|
+
testStatus: "error",
|
|
668
|
+
lastError: proxyError,
|
|
669
|
+
lastErrorAt: new Date().toISOString(),
|
|
670
|
+
});
|
|
671
|
+
return { valid: false, error: proxyError, latencyMs: 0, testedAt: new Date().toISOString() };
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
const start = Date.now();
|
|
676
|
+
let result;
|
|
677
|
+
|
|
678
|
+
if (connection.authType === "apikey" || connection.authType === "cookie") {
|
|
679
|
+
result = await testApiKeyConnection(connection, effectiveProxy);
|
|
680
|
+
} else {
|
|
681
|
+
result = await testOAuthConnection(connection, effectiveProxy);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
const latencyMs = Date.now() - start;
|
|
685
|
+
|
|
686
|
+
const updateData = {
|
|
687
|
+
testStatus: result.valid ? "active" : "error",
|
|
688
|
+
lastError: result.valid ? null : result.error,
|
|
689
|
+
lastErrorAt: result.valid ? null : new Date().toISOString(),
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
if (result.refreshed && result.newTokens) {
|
|
693
|
+
if (result.newTokens.accessToken) updateData.accessToken = result.newTokens.accessToken;
|
|
694
|
+
if (result.newTokens.refreshToken) updateData.refreshToken = result.newTokens.refreshToken;
|
|
695
|
+
if (result.newTokens.idToken) updateData.idToken = result.newTokens.idToken;
|
|
696
|
+
if (result.newTokens.lastRefreshAt) updateData.lastRefreshAt = result.newTokens.lastRefreshAt;
|
|
697
|
+
if (result.newTokens.expiresIn) updateData.expiresIn = result.newTokens.expiresIn;
|
|
698
|
+
if (result.newTokens.expiresIn) {
|
|
699
|
+
updateData.expiresAt = new Date(Date.now() + result.newTokens.expiresIn * 1000).toISOString();
|
|
700
|
+
} else if (result.newTokens.expiresAt) {
|
|
701
|
+
updateData.expiresAt = result.newTokens.expiresAt;
|
|
702
|
+
}
|
|
703
|
+
if (result.newTokens.providerSpecificData) {
|
|
704
|
+
updateData.providerSpecificData = {
|
|
705
|
+
...(connection.providerSpecificData || {}),
|
|
706
|
+
...result.newTokens.providerSpecificData,
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
await updateProviderConnection(id, updateData);
|
|
712
|
+
|
|
713
|
+
return { valid: result.valid, error: result.error, refreshed: !!result.refreshed, latencyMs, testedAt: new Date().toISOString() };
|
|
714
|
+
}
|