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,32 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const os = require("os");
|
|
4
|
+
|
|
5
|
+
const APP_NAME = "9router";
|
|
6
|
+
|
|
7
|
+
function defaultDir() {
|
|
8
|
+
if (process.platform === "win32") {
|
|
9
|
+
return path.join(process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming"), APP_NAME);
|
|
10
|
+
}
|
|
11
|
+
return path.join(os.homedir(), `.${APP_NAME}`);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getDataDir() {
|
|
15
|
+
const configured = process.env.DATA_DIR;
|
|
16
|
+
if (!configured) return defaultDir();
|
|
17
|
+
try {
|
|
18
|
+
fs.mkdirSync(configured, { recursive: true });
|
|
19
|
+
return configured;
|
|
20
|
+
} catch (e) {
|
|
21
|
+
if (e?.code === "EACCES" || e?.code === "EPERM") {
|
|
22
|
+
console.warn(`[DATA_DIR] '${configured}' not writable → fallback ~/.${APP_NAME}`);
|
|
23
|
+
return defaultDir();
|
|
24
|
+
}
|
|
25
|
+
throw e;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const DATA_DIR = getDataDir();
|
|
30
|
+
const MITM_DIR = path.join(DATA_DIR, "mitm");
|
|
31
|
+
|
|
32
|
+
module.exports = { DATA_DIR, MITM_DIR };
|
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
const https = require("https");
|
|
2
|
+
const http2 = require("http2");
|
|
3
|
+
const tls = require("tls");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const dns = require("dns");
|
|
7
|
+
const { promisify } = require("util");
|
|
8
|
+
const { execSync } = require("child_process");
|
|
9
|
+
const { log, err, dumpRequest, createResponseDumper, clearDumpDir } = require("./logger");
|
|
10
|
+
const { IS_DEV, LSOF_BIN, TARGET_HOSTS, URL_PATTERNS, MODEL_SYNONYMS, MODEL_PATTERNS, MODEL_NO_MAP, getToolForHost } = require("./config");
|
|
11
|
+
const { DATA_DIR, MITM_DIR } = require("./paths");
|
|
12
|
+
const { getCertForDomain } = require("./cert/generate");
|
|
13
|
+
const { getMitmAlias } = require("./dbReader");
|
|
14
|
+
const { applyAntigravityIdeVersionOverride } = require("./antigravityIdeVersion");
|
|
15
|
+
const LOCAL_PORT = 443;
|
|
16
|
+
const IS_WIN = process.platform === "win32";
|
|
17
|
+
const ENABLE_FILE_LOG = IS_DEV;
|
|
18
|
+
|
|
19
|
+
// Clear stale dump files on every MITM start (prevents unbounded disk usage)
|
|
20
|
+
clearDumpDir();
|
|
21
|
+
const INTERNAL_REQUEST_HEADER = { name: "x-request-source", value: "local" };
|
|
22
|
+
|
|
23
|
+
// Host rewrite for upstream forward: PROD cloudcode-pa is rate-limited (429),
|
|
24
|
+
// daily-cloudcode-pa (dev endpoint) accepts same body+token. Same trick as open-sse.
|
|
25
|
+
const HOST_REWRITE = {
|
|
26
|
+
"cloudcode-pa.googleapis.com": "daily-cloudcode-pa.googleapis.com",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const handlers = {
|
|
30
|
+
antigravity: require("./handlers/antigravity"),
|
|
31
|
+
copilot: require("./handlers/copilot"),
|
|
32
|
+
kiro: require("./handlers/kiro"),
|
|
33
|
+
cursor: require("./handlers/cursor"),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// ── SSL / SNI ─────────────────────────────────────────────────
|
|
37
|
+
|
|
38
|
+
const certCache = new Map();
|
|
39
|
+
let rootCAPem;
|
|
40
|
+
|
|
41
|
+
function sniCallback(servername, cb) {
|
|
42
|
+
try {
|
|
43
|
+
if (certCache.has(servername)) return cb(null, certCache.get(servername));
|
|
44
|
+
const certData = getCertForDomain(servername);
|
|
45
|
+
if (!certData) return cb(new Error(`Failed to generate cert for ${servername}`));
|
|
46
|
+
const ctx = require("tls").createSecureContext({
|
|
47
|
+
key: certData.key,
|
|
48
|
+
cert: `${certData.cert}\n${rootCAPem}`
|
|
49
|
+
});
|
|
50
|
+
certCache.set(servername, ctx);
|
|
51
|
+
cb(null, ctx);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
err(`SNI error for ${servername}: ${e.message}`);
|
|
54
|
+
cb(e);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let sslOptions;
|
|
59
|
+
try {
|
|
60
|
+
const rootKey = fs.readFileSync(path.join(MITM_DIR, "rootCA.key"));
|
|
61
|
+
const rootCert = fs.readFileSync(path.join(MITM_DIR, "rootCA.crt"));
|
|
62
|
+
rootCAPem = rootCert.toString("utf8");
|
|
63
|
+
sslOptions = { key: rootKey, cert: rootCert, SNICallback: sniCallback };
|
|
64
|
+
} catch (e) {
|
|
65
|
+
err(`Root CA not found: ${e.message}`);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ── Helpers ───────────────────────────────────────────────────
|
|
70
|
+
|
|
71
|
+
const cachedTargetIPs = {};
|
|
72
|
+
const CACHE_TTL_MS = 5 * 60 * 1000;
|
|
73
|
+
|
|
74
|
+
async function resolveTargetIP(hostname) {
|
|
75
|
+
const cached = cachedTargetIPs[hostname];
|
|
76
|
+
if (cached && Date.now() - cached.ts < CACHE_TTL_MS) return cached.ip;
|
|
77
|
+
const resolver = new dns.Resolver();
|
|
78
|
+
resolver.setServers(["8.8.8.8"]);
|
|
79
|
+
const resolve4 = promisify(resolver.resolve4.bind(resolver));
|
|
80
|
+
const addresses = await resolve4(hostname);
|
|
81
|
+
cachedTargetIPs[hostname] = { ip: addresses[0], ts: Date.now() };
|
|
82
|
+
return cachedTargetIPs[hostname].ip;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function collectBodyRaw(req) {
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
const chunks = [];
|
|
88
|
+
req.on("data", chunk => chunks.push(chunk));
|
|
89
|
+
req.on("end", () => resolve(Buffer.concat(chunks)));
|
|
90
|
+
req.on("error", reject);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Extract model from URL path (Gemini), body (OpenAI/Anthropic), or Kiro conversationState
|
|
95
|
+
function extractModel(url, body) {
|
|
96
|
+
const urlMatch = url.match(/\/models\/([^/:]+)/);
|
|
97
|
+
if (urlMatch) return urlMatch[1];
|
|
98
|
+
|
|
99
|
+
// Skip parsing if body is binary (AWS EventStream, Protocol Buffers, etc.)
|
|
100
|
+
if (isBinaryData(body)) return null;
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
const parsed = JSON.parse(body.toString());
|
|
104
|
+
if (parsed.conversationState) {
|
|
105
|
+
return parsed.conversationState.currentMessage?.userInputMessage?.modelId || null;
|
|
106
|
+
}
|
|
107
|
+
return parsed.model || null;
|
|
108
|
+
} catch { return null; }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Detect binary data vs JSON text
|
|
112
|
+
function isBinaryData(buffer) {
|
|
113
|
+
if (!buffer || buffer.length === 0) return false;
|
|
114
|
+
// AWS EventStream signature: first 4 bytes = frame length (big-endian uint32)
|
|
115
|
+
// Check for non-printable chars in first 100 bytes (common in binary protocols)
|
|
116
|
+
const sample = buffer.slice(0, Math.min(100, buffer.length));
|
|
117
|
+
let nonPrintable = 0;
|
|
118
|
+
for (let i = 0; i < sample.length; i++) {
|
|
119
|
+
const byte = sample[i];
|
|
120
|
+
// Count non-ASCII printable chars (excluding whitespace)
|
|
121
|
+
if (byte < 0x20 && byte !== 0x09 && byte !== 0x0A && byte !== 0x0D) {
|
|
122
|
+
nonPrintable++;
|
|
123
|
+
}
|
|
124
|
+
if (byte > 0x7E) nonPrintable++;
|
|
125
|
+
}
|
|
126
|
+
// If >30% non-printable, treat as binary
|
|
127
|
+
return (nonPrintable / sample.length) > 0.3;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function getMappedModel(tool, model) {
|
|
131
|
+
if (!model) return null;
|
|
132
|
+
try {
|
|
133
|
+
const aliases = getMitmAlias(tool);
|
|
134
|
+
if (!aliases) return null;
|
|
135
|
+
// Normalize via synonym map (e.g., public AG names -> backend model ids)
|
|
136
|
+
const normalizedModel = String(model).replace(/^models\//, "");
|
|
137
|
+
const lookup = MODEL_SYNONYMS?.[tool]?.[normalizedModel] || normalizedModel;
|
|
138
|
+
if (aliases[lookup]) return aliases[lookup];
|
|
139
|
+
// Prefix match fallback
|
|
140
|
+
const prefixKey = Object.keys(aliases).find(k => k && aliases[k] && (lookup.startsWith(k) || k.startsWith(lookup)));
|
|
141
|
+
if (prefixKey) return aliases[prefixKey];
|
|
142
|
+
// Pattern fallback: catches AG renamed variants (e.g. deprecated pro IDs → gemini-pro-agent)
|
|
143
|
+
const patterns = MODEL_PATTERNS?.[tool] || [];
|
|
144
|
+
for (const { match, alias } of patterns) {
|
|
145
|
+
if (match.test(lookup) && aliases[alias]) return aliases[alias];
|
|
146
|
+
}
|
|
147
|
+
return null;
|
|
148
|
+
} catch { return null; }
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Forward request to real upstream.
|
|
153
|
+
* Optional onResponse(rawBuffer) callback — if provided, tees the response
|
|
154
|
+
* so it's both forwarded to client AND passed to the callback for inspection.
|
|
155
|
+
* Also tees full stream into a dump file when ENABLE_FILE_LOG is on.
|
|
156
|
+
*/
|
|
157
|
+
async function passthrough(req, res, bodyBuffer, onResponse) {
|
|
158
|
+
const originalHost = (req.headers.host || TARGET_HOSTS[0]).split(":")[0];
|
|
159
|
+
// Only rewrite host for chat endpoints — daily-cloudcode-pa rejects auth/login requests
|
|
160
|
+
const isChatEndpoint = req.url.includes(":generateContent") || req.url.includes(":streamGenerateContent");
|
|
161
|
+
const targetHost = isChatEndpoint ? (HOST_REWRITE[originalHost] || originalHost) : originalHost;
|
|
162
|
+
const dumper = ENABLE_FILE_LOG ? createResponseDumper(req, "passthrough") : null;
|
|
163
|
+
|
|
164
|
+
const tool = getToolForHost(req.headers.host);
|
|
165
|
+
const versionOverride = tool === "antigravity"
|
|
166
|
+
? applyAntigravityIdeVersionOverride(bodyBuffer, req.headers)
|
|
167
|
+
: { bodyBuffer, headers: req.headers };
|
|
168
|
+
const bodyForForwarding = versionOverride.bodyBuffer;
|
|
169
|
+
const headersForForwarding = { ...versionOverride.headers, host: targetHost };
|
|
170
|
+
if (bodyForForwarding !== bodyBuffer) {
|
|
171
|
+
headersForForwarding["content-length"] = String(bodyForForwarding.length);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// ALPN negotiate: try HTTP/2 first (like browsers/mitmweb), fallback HTTP/1.1
|
|
175
|
+
try {
|
|
176
|
+
const proto = await negotiateAlpn(targetHost);
|
|
177
|
+
if (proto === "h2") {
|
|
178
|
+
return await passthroughHttp2(req, res, bodyForForwarding, headersForForwarding, targetHost, onResponse, dumper);
|
|
179
|
+
}
|
|
180
|
+
} catch (e) {
|
|
181
|
+
err(`[mitm] ALPN negotiate failed: ${e.message}, fallback to HTTP/1.1`);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return passthroughHttps(req, res, bodyForForwarding, headersForForwarding, targetHost, onResponse, dumper);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// ── ALPN negotiation cache ────────────────────────────────────
|
|
188
|
+
const alpnCache = new Map(); // host → "h2" | "http/1.1"
|
|
189
|
+
async function negotiateAlpn(host) {
|
|
190
|
+
if (alpnCache.has(host)) return alpnCache.get(host);
|
|
191
|
+
const ip = await resolveTargetIP(host);
|
|
192
|
+
return new Promise((resolve, reject) => {
|
|
193
|
+
const socket = tls.connect({
|
|
194
|
+
host: ip, port: 443, servername: host,
|
|
195
|
+
ALPNProtocols: ["h2", "http/1.1"], rejectUnauthorized: false,
|
|
196
|
+
}, () => {
|
|
197
|
+
const proto = socket.alpnProtocol || "http/1.1";
|
|
198
|
+
alpnCache.set(host, proto);
|
|
199
|
+
log(`🔗 [mitm] ALPN ${host} → ${proto}`);
|
|
200
|
+
socket.end();
|
|
201
|
+
resolve(proto);
|
|
202
|
+
});
|
|
203
|
+
socket.once("error", reject);
|
|
204
|
+
socket.setTimeout(5000, () => { socket.destroy(new Error("ALPN timeout")); });
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// HTTP/2 passthrough using node:http2 native
|
|
209
|
+
async function passthroughHttp2(req, res, bodyBuffer, headers, targetHost, onResponse, dumper) {
|
|
210
|
+
const targetIP = await resolveTargetIP(targetHost);
|
|
211
|
+
// HTTP/2 pseudo-headers required; strip HTTP/1.1-only headers
|
|
212
|
+
const h2Headers = {};
|
|
213
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
214
|
+
const lk = k.toLowerCase();
|
|
215
|
+
if (lk === "host" || lk === "connection" || lk === "keep-alive" ||
|
|
216
|
+
lk === "transfer-encoding" || lk === "upgrade" || lk === "proxy-connection") continue;
|
|
217
|
+
h2Headers[lk] = v;
|
|
218
|
+
}
|
|
219
|
+
h2Headers[":method"] = req.method;
|
|
220
|
+
h2Headers[":path"] = req.url;
|
|
221
|
+
h2Headers[":scheme"] = "https";
|
|
222
|
+
h2Headers[":authority"] = targetHost;
|
|
223
|
+
|
|
224
|
+
return new Promise((resolve) => {
|
|
225
|
+
const client = http2.connect(`https://${targetHost}`, {
|
|
226
|
+
createConnection: () => tls.connect({
|
|
227
|
+
host: targetIP, port: 443, servername: targetHost,
|
|
228
|
+
ALPNProtocols: ["h2"], rejectUnauthorized: false,
|
|
229
|
+
}),
|
|
230
|
+
});
|
|
231
|
+
client.once("error", (e) => {
|
|
232
|
+
err(`[mitm] http2 client error: ${e.message}`);
|
|
233
|
+
if (dumper) { dumper.writeChunk(`\n[ERROR h2] ${e.message}\n`); dumper.end(); }
|
|
234
|
+
if (!res.headersSent) res.writeHead(502);
|
|
235
|
+
if (!res.writableEnded) res.end("Bad Gateway");
|
|
236
|
+
try { client.close(); } catch {}
|
|
237
|
+
resolve();
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const stream = client.request(h2Headers, { endStream: bodyBuffer.length === 0 });
|
|
241
|
+
if (bodyBuffer.length > 0) stream.end(bodyBuffer);
|
|
242
|
+
|
|
243
|
+
stream.once("response", (responseHeaders) => {
|
|
244
|
+
const status = responseHeaders[":status"];
|
|
245
|
+
// Filter pseudo-headers + connection-specific
|
|
246
|
+
const outHeaders = {};
|
|
247
|
+
for (const [k, v] of Object.entries(responseHeaders)) {
|
|
248
|
+
if (k.startsWith(":")) continue;
|
|
249
|
+
if (k === "connection" || k === "keep-alive" || k === "transfer-encoding") continue;
|
|
250
|
+
outHeaders[k] = v;
|
|
251
|
+
}
|
|
252
|
+
res.writeHead(status, outHeaders);
|
|
253
|
+
if (dumper) dumper.writeHeader(status, outHeaders);
|
|
254
|
+
|
|
255
|
+
const chunks = [];
|
|
256
|
+
stream.on("data", chunk => {
|
|
257
|
+
if (dumper) dumper.writeChunk(chunk);
|
|
258
|
+
if (onResponse) chunks.push(chunk);
|
|
259
|
+
res.write(chunk);
|
|
260
|
+
});
|
|
261
|
+
stream.on("end", () => {
|
|
262
|
+
if (dumper) dumper.end();
|
|
263
|
+
if (!res.writableEnded) res.end();
|
|
264
|
+
if (onResponse) try { onResponse(Buffer.concat(chunks), outHeaders); } catch {}
|
|
265
|
+
try { client.close(); } catch {}
|
|
266
|
+
resolve();
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
stream.once("error", (e) => {
|
|
270
|
+
err(`[mitm] http2 stream error: ${e.message}`);
|
|
271
|
+
if (dumper) { dumper.writeChunk(`\n[ERROR h2-stream] ${e.message}\n`); dumper.end(); }
|
|
272
|
+
if (!res.headersSent) res.writeHead(502);
|
|
273
|
+
if (!res.writableEnded) res.end();
|
|
274
|
+
try { client.close(); } catch {}
|
|
275
|
+
resolve();
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Fallback: raw https.request HTTP/1.1 with custom DNS (bypasses /etc/hosts MITM loop)
|
|
281
|
+
async function passthroughHttps(req, res, bodyBuffer, headers, targetHost, onResponse, dumper) {
|
|
282
|
+
const targetIP = await resolveTargetIP(targetHost);
|
|
283
|
+
const forwardReq = https.request({
|
|
284
|
+
hostname: targetIP,
|
|
285
|
+
port: 443,
|
|
286
|
+
path: req.url,
|
|
287
|
+
method: req.method,
|
|
288
|
+
headers,
|
|
289
|
+
servername: targetHost,
|
|
290
|
+
rejectUnauthorized: false
|
|
291
|
+
}, (forwardRes) => {
|
|
292
|
+
res.writeHead(forwardRes.statusCode, forwardRes.headers);
|
|
293
|
+
if (dumper) dumper.writeHeader(forwardRes.statusCode, forwardRes.headers);
|
|
294
|
+
|
|
295
|
+
if (!onResponse && !dumper) {
|
|
296
|
+
forwardRes.pipe(res);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const chunks = [];
|
|
301
|
+
forwardRes.on("data", chunk => {
|
|
302
|
+
if (dumper) dumper.writeChunk(chunk);
|
|
303
|
+
if (onResponse) chunks.push(chunk);
|
|
304
|
+
res.write(chunk);
|
|
305
|
+
});
|
|
306
|
+
forwardRes.on("end", () => {
|
|
307
|
+
if (dumper) dumper.end();
|
|
308
|
+
res.end();
|
|
309
|
+
if (onResponse) try { onResponse(Buffer.concat(chunks), forwardRes.headers); } catch { /* ignore */ }
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
forwardReq.on("error", (e) => {
|
|
314
|
+
err(`Passthrough error: ${e.message}`);
|
|
315
|
+
if (dumper) { dumper.writeChunk(`\n[ERROR] ${e.message}\n`); dumper.end(); }
|
|
316
|
+
if (!res.headersSent) res.writeHead(502);
|
|
317
|
+
res.end("Bad Gateway");
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
if (bodyBuffer.length > 0) forwardReq.write(bodyBuffer);
|
|
321
|
+
forwardReq.end();
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// ── Request handler ───────────────────────────────────────────
|
|
325
|
+
|
|
326
|
+
const server = https.createServer(sslOptions, async (req, res) => {
|
|
327
|
+
try {
|
|
328
|
+
if (req.url === "/_mitm_health") {
|
|
329
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
330
|
+
res.end(JSON.stringify({ ok: true, pid: process.pid }));
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const bodyBuffer = await collectBodyRaw(req);
|
|
335
|
+
if (ENABLE_FILE_LOG) dumpRequest(req, bodyBuffer, "raw");
|
|
336
|
+
|
|
337
|
+
// Anti-loop: skip requests from 9Router
|
|
338
|
+
if (req.headers[INTERNAL_REQUEST_HEADER.name] === INTERNAL_REQUEST_HEADER.value) {
|
|
339
|
+
return passthrough(req, res, bodyBuffer);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const tool = getToolForHost(req.headers.host);
|
|
343
|
+
if (!tool) return passthrough(req, res, bodyBuffer);
|
|
344
|
+
|
|
345
|
+
const patterns = URL_PATTERNS[tool] || [];
|
|
346
|
+
const isChat = patterns.some(p => req.url.includes(p));
|
|
347
|
+
if (!isChat) return passthrough(req, res, bodyBuffer);
|
|
348
|
+
|
|
349
|
+
// Cursor uses binary proto — model extraction not possible at this layer.
|
|
350
|
+
// Delegate directly to handler which decodes proto internally.
|
|
351
|
+
if (tool === "cursor") {
|
|
352
|
+
return handlers[tool].intercept(req, res, bodyBuffer, null, passthrough);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const model = extractModel(req.url, bodyBuffer);
|
|
356
|
+
|
|
357
|
+
// Intentional passthrough: some models must never be re-routed (e.g. Antigravity
|
|
358
|
+
// tab-autocomplete) so latency-critical inline completion stays native. Silent — this
|
|
359
|
+
// is by design, not a leak, and fires per keystroke. See MODEL_NO_MAP in config.js.
|
|
360
|
+
if (model && (MODEL_NO_MAP[tool] || []).some((re) => re.test(model))) {
|
|
361
|
+
return passthrough(req, res, bodyBuffer);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const mappedModel = getMappedModel(tool, model);
|
|
365
|
+
if (!mappedModel) {
|
|
366
|
+
return passthrough(req, res, bodyBuffer);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return handlers[tool].intercept(req, res, bodyBuffer, mappedModel, passthrough);
|
|
370
|
+
} catch (e) {
|
|
371
|
+
err(`Unhandled error: ${e.message}`);
|
|
372
|
+
if (!res.headersSent) res.writeHead(500, { "Content-Type": "application/json" });
|
|
373
|
+
res.end(JSON.stringify({ error: { message: e.message, type: "mitm_error" } }));
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
// Kill only processes LISTENING on LOCAL_PORT (not outbound connections)
|
|
378
|
+
function killPort(port) {
|
|
379
|
+
try {
|
|
380
|
+
let pidList = [];
|
|
381
|
+
if (IS_WIN) {
|
|
382
|
+
const psCmd = `powershell -NonInteractive -WindowStyle Hidden -Command ` +
|
|
383
|
+
`"Get-NetTCPConnection -LocalPort ${port} -State Listen -ErrorAction SilentlyContinue | Select-Object -ExpandProperty OwningProcess"`;
|
|
384
|
+
const out = execSync(psCmd, { encoding: "utf-8", windowsHide: true }).trim();
|
|
385
|
+
if (!out) return;
|
|
386
|
+
pidList = out.split(/\r?\n/).map(s => s.trim()).filter(p => p && Number(p) !== process.pid && Number(p) > 4);
|
|
387
|
+
} else {
|
|
388
|
+
const out = execSync(`${LSOF_BIN} -nP -iTCP:${port} -sTCP:LISTEN -t`, { encoding: "utf-8", windowsHide: true }).trim();
|
|
389
|
+
if (!out) return;
|
|
390
|
+
pidList = out.split("\n").filter(p => p && Number(p) !== process.pid);
|
|
391
|
+
}
|
|
392
|
+
if (pidList.length === 0) return;
|
|
393
|
+
pidList.forEach(pid => {
|
|
394
|
+
try {
|
|
395
|
+
if (IS_WIN) execSync(`taskkill /F /PID ${pid}`, { windowsHide: true });
|
|
396
|
+
else process.kill(Number(pid), "SIGKILL");
|
|
397
|
+
} catch (e) {
|
|
398
|
+
err(`Failed to kill PID ${pid}: ${e.message}`);
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
log(`Killed ${pidList.length} process(es) on port ${port}`);
|
|
402
|
+
} catch (e) {
|
|
403
|
+
if (e.status !== 1) throw e;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
try {
|
|
408
|
+
killPort(LOCAL_PORT);
|
|
409
|
+
} catch (e) {
|
|
410
|
+
err(`Cannot kill process on port ${LOCAL_PORT}: ${e.message}`);
|
|
411
|
+
process.exit(1);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
server.listen(LOCAL_PORT, () => log(`🚀 Server ready on :${LOCAL_PORT}`));
|
|
415
|
+
|
|
416
|
+
server.on("error", (e) => {
|
|
417
|
+
if (e.code === "EADDRINUSE") err(`Port ${LOCAL_PORT} already in use`);
|
|
418
|
+
else if (e.code === "EACCES") err(`Permission denied for port ${LOCAL_PORT}`);
|
|
419
|
+
else err(e.message);
|
|
420
|
+
process.exit(1);
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
const { removeAllDNSEntriesSync } = require("./dns/dnsConfig");
|
|
424
|
+
let isShuttingDown = false;
|
|
425
|
+
const shutdown = () => {
|
|
426
|
+
if (isShuttingDown) return;
|
|
427
|
+
isShuttingDown = true;
|
|
428
|
+
// Strip tool hosts from /etc/hosts so other apps aren't broken after exit
|
|
429
|
+
removeAllDNSEntriesSync();
|
|
430
|
+
const forceExit = setTimeout(() => process.exit(0), 1500);
|
|
431
|
+
server.close(() => { clearTimeout(forceExit); process.exit(0); });
|
|
432
|
+
};
|
|
433
|
+
process.on("SIGTERM", shutdown);
|
|
434
|
+
process.on("SIGINT", shutdown);
|
|
435
|
+
if (process.platform === "win32") process.on("SIGBREAK", shutdown);
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const { exec, execSync } = require("child_process");
|
|
2
|
+
|
|
3
|
+
const IS_WIN = process.platform === "win32";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Detect if current Windows process has admin rights (no UAC popup needed).
|
|
7
|
+
* Uses `net session` which only succeeds when elevated.
|
|
8
|
+
*/
|
|
9
|
+
function isAdmin() {
|
|
10
|
+
if (IS_WIN) {
|
|
11
|
+
try {
|
|
12
|
+
execSync("net session >nul 2>&1", { windowsHide: true, stdio: "ignore" });
|
|
13
|
+
return true;
|
|
14
|
+
} catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Quote a string safely for PowerShell single-quoted literal.
|
|
23
|
+
*/
|
|
24
|
+
function quotePs(value) {
|
|
25
|
+
return `'${String(value).replace(/'/g, "''")}'`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Run PowerShell script — escalated via UAC popup if not already admin.
|
|
30
|
+
* Returns Promise resolving on exit code 0, rejecting otherwise.
|
|
31
|
+
*
|
|
32
|
+
* IMPORTANT: each call triggers ONE UAC popup. Batch multiple admin tasks
|
|
33
|
+
* into a single script string to minimize popups.
|
|
34
|
+
*/
|
|
35
|
+
function runElevatedPowerShell(script) {
|
|
36
|
+
if (!IS_WIN) return Promise.reject(new Error("Windows-only"));
|
|
37
|
+
|
|
38
|
+
const encoded = Buffer.from(script, "utf16le").toString("base64");
|
|
39
|
+
|
|
40
|
+
// If already admin, run directly — zero popup
|
|
41
|
+
if (isAdmin()) {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
exec(
|
|
44
|
+
`powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand ${encoded}`,
|
|
45
|
+
{ windowsHide: true },
|
|
46
|
+
(error, stdout, stderr) => {
|
|
47
|
+
if (error) reject(new Error(stderr || error.message));
|
|
48
|
+
else resolve(stdout);
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Not admin — wrap with Start-Process -Verb RunAs (UAC popup)
|
|
55
|
+
const wrapper = `
|
|
56
|
+
$proc = Start-Process powershell -ArgumentList @(
|
|
57
|
+
'-NoProfile','-NonInteractive','-ExecutionPolicy','Bypass',
|
|
58
|
+
'-WindowStyle','Hidden','-EncodedCommand','${encoded}'
|
|
59
|
+
) -Verb RunAs -Wait -PassThru -WindowStyle Hidden;
|
|
60
|
+
if ($proc.ExitCode -ne 0) { throw "Elevated command exited with code $($proc.ExitCode)" }
|
|
61
|
+
`;
|
|
62
|
+
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
exec(
|
|
65
|
+
`powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command ${quotePs(wrapper)}`,
|
|
66
|
+
{ windowsHide: true },
|
|
67
|
+
(error, stdout, stderr) => {
|
|
68
|
+
if (error) {
|
|
69
|
+
const msg = stderr || error.message;
|
|
70
|
+
if (msg.includes("canceled by the user") || msg.includes("operation was canceled")) {
|
|
71
|
+
reject(new Error("User canceled UAC prompt"));
|
|
72
|
+
} else {
|
|
73
|
+
reject(new Error(msg));
|
|
74
|
+
}
|
|
75
|
+
} else resolve(stdout);
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = { isAdmin, runElevatedPowerShell, quotePs };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Database Models - Export all from localDb
|
|
2
|
+
export {
|
|
3
|
+
getProviderConnections,
|
|
4
|
+
getProviderConnectionById,
|
|
5
|
+
createProviderConnection,
|
|
6
|
+
updateProviderConnection,
|
|
7
|
+
deleteProviderConnection,
|
|
8
|
+
getProviderNodes,
|
|
9
|
+
getProviderNodeById,
|
|
10
|
+
createProviderNode,
|
|
11
|
+
updateProviderNode,
|
|
12
|
+
deleteProviderNode,
|
|
13
|
+
getProxyPools,
|
|
14
|
+
getProxyPoolById,
|
|
15
|
+
createProxyPool,
|
|
16
|
+
updateProxyPool,
|
|
17
|
+
deleteProxyPool,
|
|
18
|
+
deleteProviderConnectionsByProvider,
|
|
19
|
+
getCombos,
|
|
20
|
+
getComboById,
|
|
21
|
+
getComboByName,
|
|
22
|
+
createCombo,
|
|
23
|
+
updateCombo,
|
|
24
|
+
deleteCombo,
|
|
25
|
+
getModelAliases,
|
|
26
|
+
setModelAlias,
|
|
27
|
+
deleteModelAlias,
|
|
28
|
+
getCustomModels,
|
|
29
|
+
addCustomModel,
|
|
30
|
+
deleteCustomModel,
|
|
31
|
+
getMitmAlias,
|
|
32
|
+
setMitmAliasAll,
|
|
33
|
+
getApiKeys,
|
|
34
|
+
createApiKey,
|
|
35
|
+
deleteApiKey,
|
|
36
|
+
validateApiKey,
|
|
37
|
+
isCloudEnabled,
|
|
38
|
+
} from "../lib/localDb.js";
|