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,131 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
|
|
3
|
+
import { NextResponse } from "next/server";
|
|
4
|
+
import { exec } from "child_process";
|
|
5
|
+
import { promisify } from "util";
|
|
6
|
+
import fs from "fs/promises";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import os from "os";
|
|
9
|
+
|
|
10
|
+
const execAsync = promisify(exec);
|
|
11
|
+
|
|
12
|
+
const getDataDir = () => path.join(os.homedir(), ".local", "share", "kilo");
|
|
13
|
+
const getAuthPath = () => path.join(getDataDir(), "auth.json");
|
|
14
|
+
const getVscodeSettingsPath = () => path.join(os.homedir(), ".config", "Code", "User", "settings.json");
|
|
15
|
+
|
|
16
|
+
const checkInstalled = async () => {
|
|
17
|
+
try {
|
|
18
|
+
const isWindows = os.platform() === "win32";
|
|
19
|
+
const command = isWindows ? "where kilo" : "which kilo";
|
|
20
|
+
const env = isWindows
|
|
21
|
+
? { ...process.env, PATH: `${process.env.APPDATA}\\npm;${process.env.PATH}` }
|
|
22
|
+
: process.env;
|
|
23
|
+
await execAsync(command, { windowsHide: true, env });
|
|
24
|
+
return true;
|
|
25
|
+
} catch {
|
|
26
|
+
try {
|
|
27
|
+
await fs.access(getAuthPath());
|
|
28
|
+
return true;
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const readJson = async (filePath) => {
|
|
36
|
+
try {
|
|
37
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
38
|
+
return JSON.parse(content);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (error.code === "ENOENT") return null;
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const has9RouterConfig = (auth) => {
|
|
46
|
+
if (!auth) return false;
|
|
47
|
+
const entry = auth["openai-compatible"] || auth["9router"];
|
|
48
|
+
if (!entry) return false;
|
|
49
|
+
const baseUrl = entry.baseUrl || entry.baseURL || "";
|
|
50
|
+
return baseUrl.includes("localhost") || baseUrl.includes("127.0.0.1") || baseUrl.includes("9router");
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export async function GET() {
|
|
54
|
+
try {
|
|
55
|
+
const installed = await checkInstalled();
|
|
56
|
+
if (!installed) {
|
|
57
|
+
return NextResponse.json({ installed: false, settings: null, message: "Kilo Code CLI is not installed" });
|
|
58
|
+
}
|
|
59
|
+
const auth = await readJson(getAuthPath());
|
|
60
|
+
return NextResponse.json({
|
|
61
|
+
installed: true,
|
|
62
|
+
settings: { auth: auth ? Object.keys(auth) : [] },
|
|
63
|
+
has9Router: has9RouterConfig(auth),
|
|
64
|
+
authPath: getAuthPath(),
|
|
65
|
+
});
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.log("Error checking kilo settings:", error);
|
|
68
|
+
return NextResponse.json({ error: "Failed to check kilo settings" }, { status: 500 });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function POST(request) {
|
|
73
|
+
try {
|
|
74
|
+
const { baseUrl, apiKey, model } = await request.json();
|
|
75
|
+
if (!baseUrl || !apiKey || !model) {
|
|
76
|
+
return NextResponse.json({ error: "baseUrl, apiKey and model are required" }, { status: 400 });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
await fs.mkdir(getDataDir(), { recursive: true });
|
|
80
|
+
|
|
81
|
+
const normalizedBaseUrl = baseUrl.endsWith("/v1") ? baseUrl : `${baseUrl}/v1`;
|
|
82
|
+
|
|
83
|
+
const auth = (await readJson(getAuthPath())) || {};
|
|
84
|
+
auth["openai-compatible"] = {
|
|
85
|
+
type: "api-key",
|
|
86
|
+
apiKey,
|
|
87
|
+
baseUrl: normalizedBaseUrl,
|
|
88
|
+
model,
|
|
89
|
+
};
|
|
90
|
+
await fs.writeFile(getAuthPath(), JSON.stringify(auth, null, 2));
|
|
91
|
+
|
|
92
|
+
// Best-effort: update VS Code extension settings
|
|
93
|
+
try {
|
|
94
|
+
const vscode = (await readJson(getVscodeSettingsPath())) || {};
|
|
95
|
+
vscode["kilocode.customProvider"] = { name: "9Router", baseURL: normalizedBaseUrl, apiKey };
|
|
96
|
+
vscode["kilocode.defaultModel"] = model;
|
|
97
|
+
await fs.writeFile(getVscodeSettingsPath(), JSON.stringify(vscode, null, 2));
|
|
98
|
+
} catch { /* VS Code settings not writable */ }
|
|
99
|
+
|
|
100
|
+
return NextResponse.json({ success: true, message: "Kilo Code settings applied successfully!", authPath: getAuthPath() });
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.log("Error updating kilo settings:", error);
|
|
103
|
+
return NextResponse.json({ error: "Failed to update kilo settings" }, { status: 500 });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export async function DELETE() {
|
|
108
|
+
try {
|
|
109
|
+
const auth = await readJson(getAuthPath());
|
|
110
|
+
if (!auth) {
|
|
111
|
+
return NextResponse.json({ success: true, message: "No settings file to reset" });
|
|
112
|
+
}
|
|
113
|
+
delete auth["openai-compatible"];
|
|
114
|
+
delete auth["9router"];
|
|
115
|
+
await fs.writeFile(getAuthPath(), JSON.stringify(auth, null, 2));
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
const vscode = await readJson(getVscodeSettingsPath());
|
|
119
|
+
if (vscode) {
|
|
120
|
+
delete vscode["kilocode.customProvider"];
|
|
121
|
+
delete vscode["kilocode.defaultModel"];
|
|
122
|
+
await fs.writeFile(getVscodeSettingsPath(), JSON.stringify(vscode, null, 2));
|
|
123
|
+
}
|
|
124
|
+
} catch { /* ignore */ }
|
|
125
|
+
|
|
126
|
+
return NextResponse.json({ success: true, message: "9Router settings removed from Kilo Code" });
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.log("Error resetting kilo settings:", error);
|
|
129
|
+
return NextResponse.json({ error: "Failed to reset kilo settings" }, { status: 500 });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
|
|
3
|
+
import { NextResponse } from "next/server";
|
|
4
|
+
import { exec } from "child_process";
|
|
5
|
+
import { promisify } from "util";
|
|
6
|
+
import fs from "fs/promises";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import os from "os";
|
|
9
|
+
|
|
10
|
+
const execAsync = promisify(exec);
|
|
11
|
+
|
|
12
|
+
// OpenClaw 2026.5.x writes agents[].model as either a plain string
|
|
13
|
+
// (legacy) or as an object `{ primary, fallbacks }`. Normalize to the
|
|
14
|
+
// string id so downstream consumers can call `.startsWith()` safely.
|
|
15
|
+
const resolveAgentModel = (m) => {
|
|
16
|
+
if (typeof m === "string") return m;
|
|
17
|
+
if (m && typeof m === "object") return m.primary ?? "";
|
|
18
|
+
return "";
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const getOpenClawDir = () => path.join(os.homedir(), ".openclaw");
|
|
22
|
+
const getOpenClawSettingsPath = () => path.join(getOpenClawDir(), "openclaw.json");
|
|
23
|
+
|
|
24
|
+
// Check if openclaw CLI is installed (via which/where or config file exists)
|
|
25
|
+
const checkOpenClawInstalled = async () => {
|
|
26
|
+
try {
|
|
27
|
+
const isWindows = os.platform() === "win32";
|
|
28
|
+
const command = isWindows ? "where openclaw" : "which openclaw";
|
|
29
|
+
// On Windows, inject %APPDATA%\npm into PATH so npm global packages are found
|
|
30
|
+
const env = isWindows
|
|
31
|
+
? { ...process.env, PATH: `${process.env.APPDATA}\\npm;${process.env.PATH}` }
|
|
32
|
+
: process.env;
|
|
33
|
+
await execAsync(command, { windowsHide: true, env });
|
|
34
|
+
return true;
|
|
35
|
+
} catch {
|
|
36
|
+
try {
|
|
37
|
+
await fs.access(getOpenClawSettingsPath());
|
|
38
|
+
return true;
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Read current settings.json
|
|
46
|
+
const readSettings = async () => {
|
|
47
|
+
try {
|
|
48
|
+
const settingsPath = getOpenClawSettingsPath();
|
|
49
|
+
const content = await fs.readFile(settingsPath, "utf-8");
|
|
50
|
+
return JSON.parse(content);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
if (error.code === "ENOENT") return null;
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Check if settings has 9Router config
|
|
58
|
+
const has9RouterConfig = (settings) => {
|
|
59
|
+
if (!settings || !settings.models || !settings.models.providers) return false;
|
|
60
|
+
return !!settings.models.providers["9router"];
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// Read per-agent models.json and return current model id (without "9router/" prefix)
|
|
64
|
+
const readAgentModel = async (agentDir) => {
|
|
65
|
+
try {
|
|
66
|
+
const modelsPath = path.join(agentDir, "models.json");
|
|
67
|
+
const content = await fs.readFile(modelsPath, "utf-8");
|
|
68
|
+
const data = JSON.parse(content);
|
|
69
|
+
const models = data?.providers?.["9router"]?.models;
|
|
70
|
+
return models?.[0]?.id || null;
|
|
71
|
+
} catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// GET - Check openclaw CLI and read current settings
|
|
77
|
+
export async function GET() {
|
|
78
|
+
try {
|
|
79
|
+
const isInstalled = await checkOpenClawInstalled();
|
|
80
|
+
|
|
81
|
+
if (!isInstalled) {
|
|
82
|
+
return NextResponse.json({
|
|
83
|
+
installed: false,
|
|
84
|
+
settings: null,
|
|
85
|
+
message: "Open Claw CLI is not installed",
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const settings = await readSettings();
|
|
90
|
+
|
|
91
|
+
// Enrich agents list with current per-agent model from models.json.
|
|
92
|
+
// Coerce agent.model to its string id when OpenClaw stores it as
|
|
93
|
+
// `{ primary, fallbacks }` so downstream `.startsWith()` calls work.
|
|
94
|
+
const agentList = settings?.agents?.list || [];
|
|
95
|
+
const enrichedAgents = await Promise.all(
|
|
96
|
+
agentList.map(async (agent) => {
|
|
97
|
+
const agentModel = agent.agentDir ? await readAgentModel(agent.agentDir) : null;
|
|
98
|
+
return { ...agent, model: resolveAgentModel(agent.model), currentModel: agentModel };
|
|
99
|
+
})
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
return NextResponse.json({
|
|
103
|
+
installed: true,
|
|
104
|
+
settings,
|
|
105
|
+
agents: enrichedAgents,
|
|
106
|
+
has9Router: has9RouterConfig(settings),
|
|
107
|
+
settingsPath: getOpenClawSettingsPath(),
|
|
108
|
+
});
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.log("Error checking openclaw settings:", error);
|
|
111
|
+
return NextResponse.json({ error: "Failed to check openclaw settings" }, { status: 500 });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Write per-agent models.json
|
|
116
|
+
const writeAgentModels = async (agentDir, model, baseUrl, apiKey) => {
|
|
117
|
+
await fs.mkdir(agentDir, { recursive: true });
|
|
118
|
+
const modelsPath = path.join(agentDir, "models.json");
|
|
119
|
+
let existing = {};
|
|
120
|
+
try {
|
|
121
|
+
const content = await fs.readFile(modelsPath, "utf-8");
|
|
122
|
+
existing = JSON.parse(content);
|
|
123
|
+
} catch { /* No existing */ }
|
|
124
|
+
|
|
125
|
+
if (!existing.providers) existing.providers = {};
|
|
126
|
+
existing.providers["9router"] = {
|
|
127
|
+
baseUrl,
|
|
128
|
+
apiKey: apiKey || "your_api_key",
|
|
129
|
+
api: "openai-completions",
|
|
130
|
+
models: [{ id: model, name: model.split("/").pop() || model }],
|
|
131
|
+
};
|
|
132
|
+
await fs.writeFile(modelsPath, JSON.stringify(existing, null, 2));
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// POST - Update 9Router settings (merge with existing settings)
|
|
136
|
+
export async function POST(request) {
|
|
137
|
+
try {
|
|
138
|
+
// agentModels: { [agentId]: modelId } for per-agent override
|
|
139
|
+
const { baseUrl, apiKey, model, agentModels = {} } = await request.json();
|
|
140
|
+
|
|
141
|
+
if (!baseUrl || !model) {
|
|
142
|
+
return NextResponse.json({ error: "baseUrl and model are required" }, { status: 400 });
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const openclawDir = getOpenClawDir();
|
|
146
|
+
const settingsPath = getOpenClawSettingsPath();
|
|
147
|
+
|
|
148
|
+
await fs.mkdir(openclawDir, { recursive: true });
|
|
149
|
+
|
|
150
|
+
let settings = {};
|
|
151
|
+
try {
|
|
152
|
+
const existingSettings = await fs.readFile(settingsPath, "utf-8");
|
|
153
|
+
settings = JSON.parse(existingSettings);
|
|
154
|
+
} catch { /* No existing settings */ }
|
|
155
|
+
|
|
156
|
+
if (!settings.agents) settings.agents = {};
|
|
157
|
+
if (!settings.agents.defaults) settings.agents.defaults = {};
|
|
158
|
+
if (!settings.agents.defaults.model) settings.agents.defaults.model = {};
|
|
159
|
+
if (!settings.agents.defaults.models) settings.agents.defaults.models = {};
|
|
160
|
+
if (!settings.models) settings.models = {};
|
|
161
|
+
if (!settings.models.providers) settings.models.providers = {};
|
|
162
|
+
|
|
163
|
+
const normalizedBaseUrl = baseUrl.endsWith("/v1") ? baseUrl : `${baseUrl}/v1`;
|
|
164
|
+
const fullModelId = `9router/${model}`;
|
|
165
|
+
|
|
166
|
+
// Remove all old 9router/* entries from agents.defaults.models
|
|
167
|
+
Object.keys(settings.agents.defaults.models)
|
|
168
|
+
.filter((k) => k.startsWith("9router/"))
|
|
169
|
+
.forEach((k) => { delete settings.agents.defaults.models[k]; });
|
|
170
|
+
|
|
171
|
+
// Update default model
|
|
172
|
+
settings.agents.defaults.model.primary = fullModelId;
|
|
173
|
+
|
|
174
|
+
// Collect all unique models (default + per-agent)
|
|
175
|
+
const allModelIds = new Set([model]);
|
|
176
|
+
Object.values(agentModels).forEach((m) => { if (m) allModelIds.add(m); });
|
|
177
|
+
|
|
178
|
+
// Add fresh 9router models to allowlist
|
|
179
|
+
allModelIds.forEach((m) => {
|
|
180
|
+
settings.agents.defaults.models[`9router/${m}`] = {};
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// Remove old 9router model from each agent in agents.list. The
|
|
184
|
+
// model field may be a plain string or `{ primary, fallbacks }`.
|
|
185
|
+
if (settings.agents.list) {
|
|
186
|
+
settings.agents.list = settings.agents.list.map((agent) => {
|
|
187
|
+
if (resolveAgentModel(agent.model).startsWith("9router/")) {
|
|
188
|
+
const { model: _, ...rest } = agent;
|
|
189
|
+
return rest;
|
|
190
|
+
}
|
|
191
|
+
return agent;
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Update models.providers.9router with all models
|
|
196
|
+
settings.models.providers["9router"] = {
|
|
197
|
+
baseUrl: normalizedBaseUrl,
|
|
198
|
+
apiKey: apiKey || "your_api_key",
|
|
199
|
+
api: "openai-completions",
|
|
200
|
+
models: [...allModelIds].map((m) => ({ id: m, name: m.split("/").pop() || m })),
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// Set per-agent model in agents.list and write models.json
|
|
204
|
+
if (settings.agents.list) {
|
|
205
|
+
settings.agents.list = settings.agents.list.map((agent) => {
|
|
206
|
+
const agentModel = agentModels[agent.id];
|
|
207
|
+
if (agentModel) return { ...agent, model: `9router/${agentModel}` };
|
|
208
|
+
return agent;
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// Write per-agent models.json for agents with agentDir
|
|
212
|
+
await Promise.all(
|
|
213
|
+
settings.agents.list.map(async (agent) => {
|
|
214
|
+
if (!agent.agentDir) return;
|
|
215
|
+
const agentModel = agentModels[agent.id];
|
|
216
|
+
const modelToWrite = agentModel || model; // fallback to default
|
|
217
|
+
await writeAgentModels(agent.agentDir, modelToWrite, normalizedBaseUrl, apiKey);
|
|
218
|
+
})
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
await fs.writeFile(settingsPath, JSON.stringify(settings, null, 2));
|
|
223
|
+
|
|
224
|
+
return NextResponse.json({
|
|
225
|
+
success: true,
|
|
226
|
+
message: "Open Claw settings applied successfully!",
|
|
227
|
+
settingsPath,
|
|
228
|
+
});
|
|
229
|
+
} catch (error) {
|
|
230
|
+
console.log("Error updating openclaw settings:", error);
|
|
231
|
+
return NextResponse.json({ error: "Failed to update openclaw settings" }, { status: 500 });
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// DELETE - Remove 9Router settings only (keep other settings)
|
|
236
|
+
export async function DELETE() {
|
|
237
|
+
try {
|
|
238
|
+
const settingsPath = getOpenClawSettingsPath();
|
|
239
|
+
|
|
240
|
+
// Read existing settings
|
|
241
|
+
let settings = {};
|
|
242
|
+
try {
|
|
243
|
+
const existingSettings = await fs.readFile(settingsPath, "utf-8");
|
|
244
|
+
settings = JSON.parse(existingSettings);
|
|
245
|
+
} catch (error) {
|
|
246
|
+
if (error.code === "ENOENT") {
|
|
247
|
+
return NextResponse.json({
|
|
248
|
+
success: true,
|
|
249
|
+
message: "No settings file to reset",
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
throw error;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Remove 9Router from models.providers
|
|
256
|
+
if (settings.models && settings.models.providers) {
|
|
257
|
+
delete settings.models.providers["9router"];
|
|
258
|
+
|
|
259
|
+
// Remove providers object if empty
|
|
260
|
+
if (Object.keys(settings.models.providers).length === 0) {
|
|
261
|
+
delete settings.models.providers;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Remove 9router models from agents.defaults.models allowlist
|
|
266
|
+
if (settings.agents?.defaults?.models) {
|
|
267
|
+
const keysToRemove = Object.keys(settings.agents.defaults.models).filter((k) => k.startsWith("9router/"));
|
|
268
|
+
for (const key of keysToRemove) {
|
|
269
|
+
delete settings.agents.defaults.models[key];
|
|
270
|
+
}
|
|
271
|
+
if (Object.keys(settings.agents.defaults.models).length === 0) {
|
|
272
|
+
delete settings.agents.defaults.models;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Reset agents.defaults.model.primary if it uses 9router
|
|
277
|
+
if (settings.agents?.defaults?.model?.primary?.startsWith("9router/")) {
|
|
278
|
+
delete settings.agents.defaults.model.primary;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Write updated settings
|
|
282
|
+
await fs.writeFile(settingsPath, JSON.stringify(settings, null, 2));
|
|
283
|
+
|
|
284
|
+
return NextResponse.json({
|
|
285
|
+
success: true,
|
|
286
|
+
message: "9Router settings removed successfully",
|
|
287
|
+
});
|
|
288
|
+
} catch (error) {
|
|
289
|
+
console.log("Error resetting openclaw settings:", error);
|
|
290
|
+
return NextResponse.json({ error: "Failed to reset openclaw settings" }, { status: 500 });
|
|
291
|
+
}
|
|
292
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
|
|
3
|
+
import { NextResponse } from "next/server";
|
|
4
|
+
import { exec } from "child_process";
|
|
5
|
+
import { promisify } from "util";
|
|
6
|
+
import fs from "fs/promises";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import os from "os";
|
|
9
|
+
|
|
10
|
+
const execAsync = promisify(exec);
|
|
11
|
+
|
|
12
|
+
const getConfigDir = () => path.join(os.homedir(), ".config", "opencode");
|
|
13
|
+
const getConfigPath = () => path.join(getConfigDir(), "opencode.json");
|
|
14
|
+
|
|
15
|
+
// Check if opencode CLI is installed (via which/where or config file exists)
|
|
16
|
+
const checkOpenCodeInstalled = async () => {
|
|
17
|
+
try {
|
|
18
|
+
const isWindows = os.platform() === "win32";
|
|
19
|
+
const command = isWindows ? "where opencode" : "which opencode";
|
|
20
|
+
const env = isWindows
|
|
21
|
+
? { ...process.env, PATH: `${process.env.APPDATA}\\npm;${process.env.PATH}` }
|
|
22
|
+
: process.env;
|
|
23
|
+
await execAsync(command, { windowsHide: true, env });
|
|
24
|
+
return true;
|
|
25
|
+
} catch {
|
|
26
|
+
try {
|
|
27
|
+
await fs.access(getConfigPath());
|
|
28
|
+
return true;
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const readConfig = async () => {
|
|
36
|
+
try {
|
|
37
|
+
const content = await fs.readFile(getConfigPath(), "utf-8");
|
|
38
|
+
return JSON.parse(content);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (error.code === "ENOENT") return null;
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const has9RouterConfig = (config) => {
|
|
46
|
+
if (!config?.provider) return false;
|
|
47
|
+
return !!config.provider["9router"];
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// GET - Check opencode CLI and read current settings
|
|
51
|
+
export async function GET() {
|
|
52
|
+
try {
|
|
53
|
+
const isInstalled = await checkOpenCodeInstalled();
|
|
54
|
+
|
|
55
|
+
if (!isInstalled) {
|
|
56
|
+
return NextResponse.json({
|
|
57
|
+
installed: false,
|
|
58
|
+
config: null,
|
|
59
|
+
message: "OpenCode CLI is not installed",
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const config = await readConfig();
|
|
64
|
+
const providerConfig = config?.provider?.["9router"];
|
|
65
|
+
const modelMap = providerConfig?.models || {};
|
|
66
|
+
|
|
67
|
+
return NextResponse.json({
|
|
68
|
+
installed: true,
|
|
69
|
+
config,
|
|
70
|
+
has9Router: has9RouterConfig(config),
|
|
71
|
+
configPath: getConfigPath(),
|
|
72
|
+
opencode: {
|
|
73
|
+
models: Object.keys(modelMap),
|
|
74
|
+
activeModel: config?.model?.startsWith("9router/") ? config.model.replace(/^9router\//, "") : null,
|
|
75
|
+
baseURL: providerConfig?.options?.baseURL || null,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.log("Error checking opencode settings:", error);
|
|
80
|
+
return NextResponse.json({ error: "Failed to check opencode settings" }, { status: 500 });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// POST - Apply 9Router as openai-compatible provider (multi-model support)
|
|
85
|
+
export async function POST(request) {
|
|
86
|
+
try {
|
|
87
|
+
const { baseUrl, apiKey, model, models, activeModel, subagentModel } = await request.json();
|
|
88
|
+
|
|
89
|
+
// Accept either `model` (string, legacy) or `models` (array of strings)
|
|
90
|
+
const modelsArray = Array.isArray(models) ? models.slice() : (typeof model === "string" ? [model] : []);
|
|
91
|
+
|
|
92
|
+
if (!baseUrl || modelsArray.length === 0) {
|
|
93
|
+
return NextResponse.json({ error: "baseUrl and at least one model are required" }, { status: 400 });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const configDir = getConfigDir();
|
|
97
|
+
const configPath = getConfigPath();
|
|
98
|
+
|
|
99
|
+
await fs.mkdir(configDir, { recursive: true });
|
|
100
|
+
|
|
101
|
+
// Read existing config or start fresh
|
|
102
|
+
let config = {};
|
|
103
|
+
try {
|
|
104
|
+
const existing = await fs.readFile(configPath, "utf-8");
|
|
105
|
+
config = JSON.parse(existing);
|
|
106
|
+
} catch { /* No existing config */ }
|
|
107
|
+
|
|
108
|
+
const normalizedBaseUrl = baseUrl.endsWith("/v1") ? baseUrl : `${baseUrl}/v1`;
|
|
109
|
+
const keyToUse = apiKey || "sk_9router";
|
|
110
|
+
const effectiveSubagentModel = subagentModel || modelsArray[0];
|
|
111
|
+
|
|
112
|
+
// Ensure provider object
|
|
113
|
+
if (!config.provider) config.provider = {};
|
|
114
|
+
|
|
115
|
+
// Preserve any existing 9router provider entry and its models
|
|
116
|
+
const existingProvider = config.provider["9router"] || { npm: "@ai-sdk/openai-compatible", options: {}, models: {} };
|
|
117
|
+
|
|
118
|
+
// Merge options (overwrite baseURL/apiKey)
|
|
119
|
+
existingProvider.options = {
|
|
120
|
+
...existingProvider.options,
|
|
121
|
+
baseURL: normalizedBaseUrl,
|
|
122
|
+
apiKey: keyToUse,
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// Ensure models map exists
|
|
126
|
+
existingProvider.models = existingProvider.models || {};
|
|
127
|
+
|
|
128
|
+
// Add or update entries for all requested models
|
|
129
|
+
for (const m of modelsArray) {
|
|
130
|
+
if (!m || typeof m !== "string") continue;
|
|
131
|
+
existingProvider.models[m] = { name: m, modalities: { input: ["text", "image"], output: ["text"] } };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Save merged provider back
|
|
135
|
+
config.provider["9router"] = existingProvider;
|
|
136
|
+
|
|
137
|
+
// Set the active model: prefer explicit activeModel, else first of modelsArray
|
|
138
|
+
// If activeModel is explicitly empty string, clear the model
|
|
139
|
+
if (activeModel === "") {
|
|
140
|
+
config.model = "";
|
|
141
|
+
} else {
|
|
142
|
+
const finalActive = activeModel || modelsArray[0];
|
|
143
|
+
if (finalActive) {
|
|
144
|
+
config.model = `9router/${finalActive}`;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Add subagent configuration
|
|
149
|
+
if (!config.agent) config.agent = {};
|
|
150
|
+
config.agent.explorer = {
|
|
151
|
+
description: "Fast explorer subagent for codebase exploration",
|
|
152
|
+
mode: "subagent",
|
|
153
|
+
model: `9router/${effectiveSubagentModel}`,
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
await fs.writeFile(configPath, JSON.stringify(config, null, 2));
|
|
157
|
+
|
|
158
|
+
return NextResponse.json({
|
|
159
|
+
success: true,
|
|
160
|
+
message: "OpenCode settings applied successfully!",
|
|
161
|
+
configPath,
|
|
162
|
+
});
|
|
163
|
+
} catch (error) {
|
|
164
|
+
console.log("Error applying opencode settings:", error);
|
|
165
|
+
return NextResponse.json({ error: "Failed to apply settings" }, { status: 500 });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// PATCH - Update specific settings (e.g., clear active model)
|
|
170
|
+
export async function PATCH(request) {
|
|
171
|
+
try {
|
|
172
|
+
const { clearActiveModel } = await request.json();
|
|
173
|
+
const configPath = getConfigPath();
|
|
174
|
+
|
|
175
|
+
let config = {};
|
|
176
|
+
try {
|
|
177
|
+
const existing = await fs.readFile(configPath, "utf-8");
|
|
178
|
+
config = JSON.parse(existing);
|
|
179
|
+
} catch (error) {
|
|
180
|
+
if (error.code === "ENOENT") {
|
|
181
|
+
return NextResponse.json({ success: true, message: "No config file found" });
|
|
182
|
+
}
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (clearActiveModel === true) {
|
|
187
|
+
// Clear active model but keep models in the list
|
|
188
|
+
if (config.model?.startsWith("9router/")) {
|
|
189
|
+
config.model = "";
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
await fs.writeFile(configPath, JSON.stringify(config, null, 2));
|
|
194
|
+
|
|
195
|
+
return NextResponse.json({
|
|
196
|
+
success: true,
|
|
197
|
+
message: "Settings updated",
|
|
198
|
+
});
|
|
199
|
+
} catch (error) {
|
|
200
|
+
console.log("Error patching opencode settings:", error);
|
|
201
|
+
return NextResponse.json({ error: "Failed to patch settings" }, { status: 500 });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// DELETE - Remove 9Router provider or specific models from config
|
|
206
|
+
export async function DELETE(request) {
|
|
207
|
+
try {
|
|
208
|
+
const { searchParams } = new URL(request.url);
|
|
209
|
+
const modelToRemove = searchParams.get("model");
|
|
210
|
+
const configPath = getConfigPath();
|
|
211
|
+
|
|
212
|
+
let config = {};
|
|
213
|
+
try {
|
|
214
|
+
const existing = await fs.readFile(configPath, "utf-8");
|
|
215
|
+
config = JSON.parse(existing);
|
|
216
|
+
} catch (error) {
|
|
217
|
+
if (error.code === "ENOENT") {
|
|
218
|
+
return NextResponse.json({ success: true, message: "No config file to reset" });
|
|
219
|
+
}
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// If specific model provided, remove just that model
|
|
224
|
+
if (modelToRemove && config.provider?.["9router"]?.models) {
|
|
225
|
+
delete config.provider["9router"].models[modelToRemove];
|
|
226
|
+
|
|
227
|
+
// If no models left, remove the provider
|
|
228
|
+
if (Object.keys(config.provider["9router"].models).length === 0) {
|
|
229
|
+
delete config.provider["9router"];
|
|
230
|
+
if (config.model?.startsWith("9router/")) delete config.model;
|
|
231
|
+
} else if (config.model === `9router/${modelToRemove}`) {
|
|
232
|
+
// If removed model was active, switch to first remaining model
|
|
233
|
+
const remainingModels = Object.keys(config.provider["9router"].models);
|
|
234
|
+
config.model = `9router/${remainingModels[0]}`;
|
|
235
|
+
}
|
|
236
|
+
} else {
|
|
237
|
+
// No specific model - remove entire 9router provider
|
|
238
|
+
if (config.provider) delete config.provider["9router"];
|
|
239
|
+
if (config.model?.startsWith("9router/")) delete config.model;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Remove subagent configuration
|
|
243
|
+
if (config.agent?.explorer?.model?.startsWith("9router/")) {
|
|
244
|
+
delete config.agent.explorer;
|
|
245
|
+
// Clean up empty agent object
|
|
246
|
+
if (Object.keys(config.agent).length === 0) delete config.agent;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
await fs.writeFile(configPath, JSON.stringify(config, null, 2));
|
|
250
|
+
|
|
251
|
+
return NextResponse.json({
|
|
252
|
+
success: true,
|
|
253
|
+
message: modelToRemove ? `Model "${modelToRemove}" removed` : "9Router settings removed from OpenCode",
|
|
254
|
+
});
|
|
255
|
+
} catch (error) {
|
|
256
|
+
console.log("Error resetting opencode settings:", error);
|
|
257
|
+
return NextResponse.json({ error: "Failed to reset opencode settings" }, { status: 500 });
|
|
258
|
+
}
|
|
259
|
+
}
|