@fudrouter/fsrouter 0.6.62 → 0.6.63
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/bin/copyJs.js +0 -4
- package/dist/lib/oauth/constants/oauth.js +2 -2
- package/dist/lib/oauth/providers.js +1 -1
- package/dist/routes/providers/[id]/test/testUtils.js +3 -3
- package/dist/shared/constants/models.js +2 -2
- package/dist/sse/handlers/chat.js +10 -10
- package/dist/sse/handlers/embeddings.js +3 -3
- package/dist/sse/handlers/fetch.js +4 -4
- package/dist/sse/handlers/imageGeneration.js +5 -5
- package/dist/sse/handlers/search.js +4 -4
- package/dist/sse/handlers/stt.js +3 -3
- package/dist/sse/handlers/tts.js +4 -4
- package/dist/sse/handlers/videoGeneration.js +4 -4
- package/dist/sse/services/auth.js +2 -2
- package/dist/sse/services/model.js +1 -1
- package/dist/sse/services/tokenRefresh.js +3 -3
- package/open-sse/AGENTS.md +39 -0
- package/open-sse/config/anthropicHeaders.js +87 -0
- package/open-sse/config/appConstants.js +238 -0
- package/open-sse/config/audioRegistry.js +506 -0
- package/open-sse/config/cliFingerprints.js +304 -0
- package/open-sse/config/codexInstructions.js +119 -0
- package/open-sse/config/codexQuotaScopes.js +42 -0
- package/open-sse/config/constants.js +4 -0
- package/open-sse/config/contextEditing.js +68 -0
- package/open-sse/config/credentialLoader.js +83 -0
- package/open-sse/config/defaultThinkingSignature.js +12 -0
- package/open-sse/config/embeddingRegistry.js +264 -0
- package/open-sse/config/errorConfig.js +96 -0
- package/open-sse/config/freeModelCatalog.data.js +121 -0
- package/open-sse/config/freeModelCatalog.js +90 -0
- package/open-sse/config/freeTierCatalog.js +81 -0
- package/open-sse/config/googleTtsLanguages.js +62 -0
- package/open-sse/config/imageParamDefs.js +360 -0
- package/open-sse/config/imageRegistry.js +493 -0
- package/open-sse/config/kiroConstants.js +268 -0
- package/open-sse/config/mediaConfig.js +27 -0
- package/open-sse/config/mediaServiceKinds.js +71 -0
- package/open-sse/config/models.js +13 -0
- package/open-sse/config/moderationRegistry.js +71 -0
- package/open-sse/config/musicRegistry.js +99 -0
- package/open-sse/config/ocrRegistry.js +61 -0
- package/open-sse/config/ollamaModels.js +19 -0
- package/open-sse/config/providerErrorRules.js +114 -0
- package/open-sse/config/providerFieldStrips.js +35 -0
- package/open-sse/config/providerHeaderProfiles.js +191 -0
- package/open-sse/config/providerModels.js +106 -0
- package/open-sse/config/providerRegistry.js +16 -0
- package/open-sse/config/providers.js +19 -0
- package/open-sse/config/registryUtils.js +106 -0
- package/open-sse/config/rerankRegistry.js +177 -0
- package/open-sse/config/runtimeConfig.js +96 -0
- package/open-sse/config/runway.js +39 -0
- package/open-sse/config/searchRegistry.js +153 -0
- package/open-sse/config/toolCloaking.js +199 -0
- package/open-sse/config/ttsModels.js +129 -0
- package/open-sse/config/videoRegistry.js +207 -0
- package/open-sse/executors/adapta-web.js +435 -0
- package/open-sse/executors/antigravity.js +534 -0
- package/open-sse/executors/antigravityUpstreamError.js +13 -0
- package/open-sse/executors/auggie.js +437 -0
- package/open-sse/executors/azure-openai.js +32 -0
- package/open-sse/executors/azure.js +57 -0
- package/open-sse/executors/base.js +181 -0
- package/open-sse/executors/bedrock.js +633 -0
- package/open-sse/executors/blackbox-web.js +578 -0
- package/open-sse/executors/chatgpt-web.js +2042 -0
- package/open-sse/executors/chipotle.js +357 -0
- package/open-sse/executors/claude-web-with-auto-refresh.js +73 -0
- package/open-sse/executors/claude-web.js +586 -0
- package/open-sse/executors/cliproxyapi.js +296 -0
- package/open-sse/executors/cloudflare-ai.js +46 -0
- package/open-sse/executors/codebuddy-cn.js +40 -0
- package/open-sse/executors/codex.js +1324 -0
- package/open-sse/executors/commandCode.js +558 -0
- package/open-sse/executors/commandcode.js +88 -0
- package/open-sse/executors/copilot-m365-connection.js +176 -0
- package/open-sse/executors/copilot-m365-frames.js +192 -0
- package/open-sse/executors/copilot-m365-web.js +299 -0
- package/open-sse/executors/copilot-web.js +580 -0
- package/open-sse/executors/cursor.js +795 -0
- package/open-sse/executors/deepseek-web-with-auto-refresh.js +150 -0
- package/open-sse/executors/deepseek-web.js +875 -0
- package/open-sse/executors/default.js +430 -0
- package/open-sse/executors/devin-cli.js +351 -0
- package/open-sse/executors/doubao-web.js +550 -0
- package/open-sse/executors/duckduckgo-web.js +629 -0
- package/open-sse/executors/forceResponsesUpstream.js +33 -0
- package/open-sse/executors/gemini-business.js +320 -0
- package/open-sse/executors/gemini-cli.js +89 -0
- package/open-sse/executors/gemini-web.js +297 -0
- package/open-sse/executors/github.js +379 -0
- package/open-sse/executors/gitlab.js +569 -0
- package/open-sse/executors/glm.js +361 -0
- package/open-sse/executors/grok-cli.js +119 -0
- package/open-sse/executors/grok-web.js +345 -0
- package/open-sse/executors/huggingchat.js +467 -0
- package/open-sse/executors/iflow.js +108 -0
- package/open-sse/executors/index.js +78 -0
- package/open-sse/executors/inner-ai.js +527 -0
- package/open-sse/executors/kimchi.js +123 -0
- package/open-sse/executors/kimi-web.js +325 -0
- package/open-sse/executors/kimi.js +97 -0
- package/open-sse/executors/kiro.js +503 -0
- package/open-sse/executors/kiroThinking.js +44 -0
- package/open-sse/executors/lmarena.js +395 -0
- package/open-sse/executors/mimo-free.js +167 -0
- package/open-sse/executors/mimocode.js +392 -0
- package/open-sse/executors/ninerouter.js +155 -0
- package/open-sse/executors/nlpcloud.js +438 -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 +581 -0
- package/open-sse/executors/poe-web.js +133 -0
- package/open-sse/executors/pollinations.js +95 -0
- package/open-sse/executors/puter.js +31 -0
- package/open-sse/executors/qoder.js +448 -0
- package/open-sse/executors/qwen-web.js +372 -0
- package/open-sse/executors/qwen.js +129 -0
- package/open-sse/executors/t3-chat-web.js +417 -0
- package/open-sse/executors/theoldllm.js +290 -0
- package/open-sse/executors/trae.js +418 -0
- package/open-sse/executors/v0-vercel-web.js +141 -0
- package/open-sse/executors/venice-web.js +142 -0
- package/open-sse/executors/vertex.js +131 -0
- package/open-sse/executors/vertexMedia.js +236 -0
- package/open-sse/executors/windsurf.js +560 -0
- package/open-sse/executors/xai.js +46 -0
- package/open-sse/executors/xiaomi-tokenplan.js +19 -0
- package/open-sse/executors/yuanbao-web.js +385 -0
- package/open-sse/executors/zed-hosted.js +281 -0
- package/open-sse/executors/zenmux-free.js +247 -0
- package/open-sse/handlers/audioSpeech.js +759 -0
- package/open-sse/handlers/audioTranscription.js +395 -0
- package/open-sse/handlers/audioTranslation.js +181 -0
- package/open-sse/handlers/chatCore/nonStreamingHandler.js +300 -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 +95 -0
- package/open-sse/handlers/chatCore.js +404 -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 +230 -0
- package/open-sse/handlers/imageProviders/_base.js +31 -0
- package/open-sse/handlers/imageProviders/antigravity.js +73 -0
- package/open-sse/handlers/imageProviders/blackForestLabs.js +63 -0
- package/open-sse/handlers/imageProviders/cloudflareAi.js +207 -0
- package/open-sse/handlers/imageProviders/codex.js +217 -0
- package/open-sse/handlers/imageProviders/comfyui.js +25 -0
- package/open-sse/handlers/imageProviders/falAi.js +62 -0
- package/open-sse/handlers/imageProviders/gemini.js +40 -0
- package/open-sse/handlers/imageProviders/huggingface.js +38 -0
- package/open-sse/handlers/imageProviders/index.js +44 -0
- package/open-sse/handlers/imageProviders/leonardo.js +435 -0
- package/open-sse/handlers/imageProviders/nanobanana.js +79 -0
- package/open-sse/handlers/imageProviders/openai.js +61 -0
- package/open-sse/handlers/imageProviders/runwayml.js +72 -0
- package/open-sse/handlers/imageProviders/sdwebui.js +36 -0
- package/open-sse/handlers/imageProviders/stabilityAi.js +59 -0
- package/open-sse/handlers/imageProviders/weavy.js +222 -0
- package/open-sse/handlers/moderations.js +92 -0
- package/open-sse/handlers/ocr.js +89 -0
- package/open-sse/handlers/rerank.js +223 -0
- package/open-sse/handlers/responseSanitizer/reasoning.js +144 -0
- package/open-sse/handlers/responsesHandler.js +99 -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/search.js +1056 -0
- package/open-sse/handlers/sseParser.js +469 -0
- package/open-sse/handlers/sttCore.js +193 -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/handlers/usageExtractor.js +93 -0
- package/open-sse/handlers/videoGenerationCore.js +119 -0
- package/open-sse/handlers/videoProviders/index.js +22 -0
- package/open-sse/handlers/videoProviders/leonardo.js +511 -0
- package/open-sse/handlers/videoProviders/weavy.js +198 -0
- package/open-sse/handlers/webFetch.js +200 -0
- package/open-sse/index.js +79 -0
- package/open-sse/mcp-server/audit.js +283 -0
- package/open-sse/mcp-server/catalog.js +184 -0
- package/open-sse/mcp-server/descriptionCompressor.js +175 -0
- package/open-sse/mcp-server/httpAuthContext.js +32 -0
- package/open-sse/mcp-server/httpTransport.js +229 -0
- package/open-sse/mcp-server/index.js +33 -0
- package/open-sse/mcp-server/mcpCallerIdentity.js +21 -0
- package/open-sse/mcp-server/runtimeHeartbeat.js +110 -0
- package/open-sse/mcp-server/schemas/a2a.js +153 -0
- package/open-sse/mcp-server/schemas/audit.js +17 -0
- package/open-sse/mcp-server/schemas/index.js +166 -0
- package/open-sse/mcp-server/schemas/pickFastestModel.js +90 -0
- package/open-sse/mcp-server/schemas/toolDefinition.js +0 -0
- package/open-sse/mcp-server/schemas/toolSearch.js +32 -0
- package/open-sse/mcp-server/schemas/tools.js +1219 -0
- package/open-sse/mcp-server/scopeEnforcement.js +80 -0
- package/open-sse/mcp-server/server.js +1168 -0
- package/open-sse/mcp-server/toolCardinality.js +78 -0
- package/open-sse/mcp-server/toolSearch/catalog.js +66 -0
- package/open-sse/mcp-server/toolSearch/handler.js +20 -0
- package/open-sse/mcp-server/toolSearch/index.js +10 -0
- package/open-sse/mcp-server/toolSearch/register.js +21 -0
- package/open-sse/mcp-server/toolSearch/search.js +55 -0
- package/open-sse/mcp-server/toolSearch/signature.js +67 -0
- package/open-sse/mcp-server/tools/advancedTools.js +893 -0
- package/open-sse/mcp-server/tools/agentSkillTools.js +69 -0
- package/open-sse/mcp-server/tools/compressionTools.js +309 -0
- package/open-sse/mcp-server/tools/gamificationTools.js +134 -0
- package/open-sse/mcp-server/tools/githubSkillTools.js +102 -0
- package/open-sse/mcp-server/tools/memoryTools.js +118 -0
- package/open-sse/mcp-server/tools/notionTools.js +101 -0
- package/open-sse/mcp-server/tools/obsidianTools.js +307 -0
- package/open-sse/mcp-server/tools/pickFastestModel.js +223 -0
- package/open-sse/mcp-server/tools/pluginTools.js +181 -0
- package/open-sse/mcp-server/tools/poolTools.js +139 -0
- package/open-sse/mcp-server/tools/skillTools.js +113 -0
- package/open-sse/package.json +10 -0
- package/open-sse/providers/REGISTRY_TEMPLATE.js +98 -0
- package/open-sse/providers/capabilities.js +293 -0
- package/open-sse/providers/index.js +51 -0
- package/open-sse/providers/models/helpers.js +20 -0
- package/open-sse/providers/models/namePatterns.js +33 -0
- package/open-sse/providers/models/schema.js +40 -0
- package/open-sse/providers/pricing.js +308 -0
- package/open-sse/providers/registry/alicode-intl.js +30 -0
- package/open-sse/providers/registry/alicode.js +31 -0
- package/open-sse/providers/registry/anthropic.js +37 -0
- package/open-sse/providers/registry/antigravity.js +81 -0
- package/open-sse/providers/registry/assemblyai.js +38 -0
- package/open-sse/providers/registry/aws-polly.js +45 -0
- package/open-sse/providers/registry/azure.js +21 -0
- package/open-sse/providers/registry/black-forest-labs.js +32 -0
- package/open-sse/providers/registry/blackbox.js +41 -0
- package/open-sse/providers/registry/brave-search.js +35 -0
- package/open-sse/providers/registry/byteplus.js +35 -0
- package/open-sse/providers/registry/cartesia.js +36 -0
- package/open-sse/providers/registry/cerebras.js +31 -0
- package/open-sse/providers/registry/chutes.js +24 -0
- package/open-sse/providers/registry/claude.js +87 -0
- package/open-sse/providers/registry/cline.js +51 -0
- package/open-sse/providers/registry/clinepass.js +57 -0
- package/open-sse/providers/registry/cloudflare-ai.js +55 -0
- package/open-sse/providers/registry/codebuddy-cn.js +77 -0
- package/open-sse/providers/registry/codex.js +100 -0
- package/open-sse/providers/registry/cohere.js +27 -0
- package/open-sse/providers/registry/comfyui.js +20 -0
- package/open-sse/providers/registry/commandcode.js +43 -0
- package/open-sse/providers/registry/coqui.js +30 -0
- package/open-sse/providers/registry/cursor.js +58 -0
- package/open-sse/providers/registry/deepgram.js +33 -0
- package/open-sse/providers/registry/deepseek.js +51 -0
- package/open-sse/providers/registry/digitalocean.js +92 -0
- package/open-sse/providers/registry/edge-tts.js +24 -0
- package/open-sse/providers/registry/elevenlabs.js +35 -0
- package/open-sse/providers/registry/exa.js +50 -0
- package/open-sse/providers/registry/fal-ai.js +34 -0
- package/open-sse/providers/registry/featherless.js +34 -0
- package/open-sse/providers/registry/firecrawl.js +34 -0
- package/open-sse/providers/registry/fireworks.js +29 -0
- package/open-sse/providers/registry/gemini-cli.js +58 -0
- package/open-sse/providers/registry/gemini.js +83 -0
- package/open-sse/providers/registry/github.js +88 -0
- package/open-sse/providers/registry/gitlab.js +32 -0
- package/open-sse/providers/registry/glm-cn.js +35 -0
- package/open-sse/providers/registry/glm.js +58 -0
- package/open-sse/providers/registry/google-pse.js +35 -0
- package/open-sse/providers/registry/google-tts.js +24 -0
- package/open-sse/providers/registry/grok-cli.js +86 -0
- package/open-sse/providers/registry/grok-web.js +39 -0
- package/open-sse/providers/registry/groq.js +37 -0
- package/open-sse/providers/registry/huggingface.js +34 -0
- package/open-sse/providers/registry/hyperbolic.js +35 -0
- package/open-sse/providers/registry/ibm-bob.js +27 -0
- package/open-sse/providers/registry/iflow.js +52 -0
- package/open-sse/providers/registry/index.js +210 -0
- package/open-sse/providers/registry/inworld.js +36 -0
- package/open-sse/providers/registry/jina-ai.js +42 -0
- package/open-sse/providers/registry/jina-reader.js +34 -0
- package/open-sse/providers/registry/kilocode.js +51 -0
- package/open-sse/providers/registry/kimchi.js +49 -0
- package/open-sse/providers/registry/kimi-coding.js +65 -0
- package/open-sse/providers/registry/kimi.js +56 -0
- package/open-sse/providers/registry/kiro.js +115 -0
- package/open-sse/providers/registry/linkup.js +34 -0
- package/open-sse/providers/registry/local-device.js +24 -0
- package/open-sse/providers/registry/mimo-free.js +24 -0
- package/open-sse/providers/registry/minimax-cn.js +76 -0
- package/open-sse/providers/registry/minimax.js +83 -0
- package/open-sse/providers/registry/mistral.js +34 -0
- package/open-sse/providers/registry/mmf.js +19 -0
- package/open-sse/providers/registry/nanobanana.js +35 -0
- package/open-sse/providers/registry/nebius.js +27 -0
- package/open-sse/providers/registry/nvidia.js +43 -0
- package/open-sse/providers/registry/ollama-local.js +19 -0
- package/open-sse/providers/registry/ollama.js +36 -0
- package/open-sse/providers/registry/openai.js +84 -0
- package/open-sse/providers/registry/opencode-go.js +41 -0
- package/open-sse/providers/registry/opencode.js +25 -0
- package/open-sse/providers/registry/openrouter.js +60 -0
- package/open-sse/providers/registry/perplexity-agent.js +49 -0
- package/open-sse/providers/registry/perplexity-web.js +33 -0
- package/open-sse/providers/registry/perplexity.js +37 -0
- package/open-sse/providers/registry/playht.js +36 -0
- package/open-sse/providers/registry/qoder.js +54 -0
- package/open-sse/providers/registry/qwen.js +33 -0
- package/open-sse/providers/registry/recraft.js +24 -0
- package/open-sse/providers/registry/runwayml.js +30 -0
- package/open-sse/providers/registry/sdwebui.js +20 -0
- package/open-sse/providers/registry/searchapi.js +35 -0
- package/open-sse/providers/registry/searxng.js +35 -0
- package/open-sse/providers/registry/serper.js +35 -0
- package/open-sse/providers/registry/siliconflow.js +39 -0
- package/open-sse/providers/registry/stability-ai.js +31 -0
- package/open-sse/providers/registry/tavily.js +50 -0
- package/open-sse/providers/registry/together.js +31 -0
- package/open-sse/providers/registry/topaz.js +19 -0
- package/open-sse/providers/registry/tortoise.js +30 -0
- package/open-sse/providers/registry/venice.js +56 -0
- package/open-sse/providers/registry/vercel-ai-gateway.js +41 -0
- package/open-sse/providers/registry/vertex-partner.js +29 -0
- package/open-sse/providers/registry/vertex.js +32 -0
- package/open-sse/providers/registry/volcengine-ark.js +35 -0
- package/open-sse/providers/registry/voyage-ai.js +30 -0
- package/open-sse/providers/registry/xai.js +45 -0
- package/open-sse/providers/registry/xiaomi-mimo.js +46 -0
- package/open-sse/providers/registry/xiaomi-tokenplan.js +63 -0
- package/open-sse/providers/registry/youcom.js +35 -0
- package/open-sse/providers/schema.js +76 -0
- package/open-sse/providers/shared.js +74 -0
- package/open-sse/providers/thinkingLevels.js +48 -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 +50 -0
- package/open-sse/rtk/filters/gitDiff.js +92 -0
- package/open-sse/rtk/filters/gitLog.js +99 -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/headroom.js +215 -0
- package/open-sse/rtk/index.js +155 -0
- package/open-sse/rtk/paleo.js +47 -0
- package/open-sse/rtk/ponytail.js +9 -0
- package/open-sse/rtk/ponytailPrompt.js +52 -0
- package/open-sse/rtk/ponytailPrompts.js +76 -0
- package/open-sse/rtk/pxpipe.js +104 -0
- package/open-sse/rtk/registry.js +38 -0
- package/open-sse/rtk/systemInject.js +98 -0
- package/open-sse/services/accountFallback.js +323 -0
- package/open-sse/services/antigravityHeaders.js +91 -0
- package/open-sse/services/antigravityVersion.js +154 -0
- package/open-sse/services/clinepassModels.js +63 -0
- package/open-sse/services/codexQuotaFetcher.js +312 -0
- package/open-sse/services/codexVerbosity.js +30 -0
- package/open-sse/services/combo/context.js +12 -0
- package/open-sse/services/combo/fingerprintExpansion.js +51 -0
- package/open-sse/services/combo/headroomRanking.js +28 -0
- package/open-sse/services/combo/quotaExhaustionCutoff.js +87 -0
- package/open-sse/services/combo/quotaScoring.js +226 -0
- package/open-sse/services/combo/quotaShareConcurrency.js +25 -0
- package/open-sse/services/combo/quotaShareInflight.js +50 -0
- package/open-sse/services/combo/quotaShareStrategy.js +130 -0
- package/open-sse/services/combo/resolveAutoStrategy.js +231 -0
- package/open-sse/services/combo/responseValidation.js +140 -0
- package/open-sse/services/combo/runtimeUnits.js +195 -0
- package/open-sse/services/combo/sessionStickiness.js +128 -0
- package/open-sse/services/combo/shadowRouting.js +131 -0
- package/open-sse/services/combo/targetExhaustion.js +75 -0
- package/open-sse/services/combo/targetSorters.js +126 -0
- package/open-sse/services/combo/targetTimeoutRunner.js +65 -0
- package/open-sse/services/combo/validateQuality.js +271 -0
- package/open-sse/services/combo.js +571 -0
- package/open-sse/services/comboAgentMiddleware.js +91 -0
- package/open-sse/services/comboConfig.js +153 -0
- package/open-sse/services/comboManifestMetrics.js +10 -0
- package/open-sse/services/comboMetrics.js +278 -0
- package/open-sse/services/compact.js +71 -0
- package/open-sse/services/copilotModels.js +155 -0
- package/open-sse/services/emergencyFallback.js +109 -0
- package/open-sse/services/errorClassifier.js +190 -0
- package/open-sse/services/evalRouting.js +201 -0
- package/open-sse/services/freeWebSearch.js +4 -0
- package/open-sse/services/fusion.js +223 -0
- package/open-sse/services/intentClassifier.js +631 -0
- package/open-sse/services/kimchiModels.js +176 -0
- package/open-sse/services/kiroModels.js +332 -0
- package/open-sse/services/model.js +136 -0
- package/open-sse/services/modelCapabilities.js +5 -0
- package/open-sse/services/modelDeprecation.js +101 -0
- package/open-sse/services/modelFamilyFallback.js +166 -0
- package/open-sse/services/oauthCredentialManager.js +156 -0
- package/open-sse/services/pipeline.js +107 -0
- package/open-sse/services/projectId.js +306 -0
- package/open-sse/services/provider.js +169 -0
- package/open-sse/services/providerCooldownTracker.js +94 -0
- package/open-sse/services/providerDefaultRateLimit.js +11 -0
- package/open-sse/services/proxyAutoSelector.js +24 -0
- package/open-sse/services/qoderModels.js +214 -0
- package/open-sse/services/quotaFetchThrottle.js +103 -0
- package/open-sse/services/quotaMonitor.js +310 -0
- package/open-sse/services/quotaPreflight.js +266 -0
- package/open-sse/services/rateLimitManager/headers.js +56 -0
- package/open-sse/services/rateLimitManager.js +616 -0
- package/open-sse/services/rateLimitSemaphore.js +112 -0
- package/open-sse/services/responsesInputSanitizer.js +99 -0
- package/open-sse/services/slidingWindowLimiter.js +44 -0
- package/open-sse/services/streamRecovery.js +355 -0
- package/open-sse/services/taskAwareRouter.js +227 -0
- package/open-sse/services/taskAwareRouting.js +332 -0
- package/open-sse/services/thinkingBudget.js +247 -0
- package/open-sse/services/tokenRefresh/dedup.js +31 -0
- package/open-sse/services/tokenRefresh/providers.js +624 -0
- package/open-sse/services/tokenRefresh.js +254 -0
- package/open-sse/services/usage/claude.js +147 -0
- package/open-sse/services/usage/codebuddy-cn.js +138 -0
- package/open-sse/services/usage/codex.js +267 -0
- package/open-sse/services/usage/github.js +100 -0
- package/open-sse/services/usage/google.js +241 -0
- package/open-sse/services/usage/grok-cli.js +274 -0
- package/open-sse/services/usage/kiro.js +188 -0
- package/open-sse/services/usage/minimax.js +234 -0
- package/open-sse/services/usage/misc.js +288 -0
- package/open-sse/services/usage/shared.js +70 -0
- package/open-sse/services/usage.js +62 -0
- package/open-sse/services/usageDb.js +2 -0
- package/open-sse/services/webSearchRouting.js +25 -0
- package/open-sse/services/wildcardRouter.js +59 -0
- package/open-sse/shared/clineAuth.js +37 -0
- package/open-sse/shared/machineId.js +19 -0
- package/open-sse/shared/qoder/constants.js +64 -0
- package/open-sse/shared/qoder/cosy.js +175 -0
- package/open-sse/shared/qoder/encoding.js +55 -0
- package/open-sse/transformer/responsesTransformer.js +439 -0
- package/open-sse/transformer/streamToJsonConverter.js +103 -0
- package/open-sse/translator/concerns/chunk.js +11 -0
- package/open-sse/translator/concerns/finishReason.js +63 -0
- package/open-sse/translator/concerns/image.js +124 -0
- package/open-sse/translator/concerns/json.js +5 -0
- package/open-sse/translator/concerns/message.js +7 -0
- package/open-sse/translator/concerns/modality.js +155 -0
- package/open-sse/translator/concerns/paramSupport.js +75 -0
- package/open-sse/translator/concerns/prefetch.js +96 -0
- package/open-sse/translator/concerns/reasoning.js +24 -0
- package/open-sse/translator/concerns/thinking.js +53 -0
- package/open-sse/translator/concerns/thinkingUnified.js +329 -0
- package/open-sse/translator/concerns/toolCall.js +153 -0
- package/open-sse/translator/concerns/usage.js +69 -0
- package/open-sse/translator/formats/claude.js +368 -0
- package/open-sse/translator/formats/gemini.js +380 -0
- package/open-sse/translator/formats/maxTokens.js +34 -0
- package/open-sse/translator/formats/openai.js +134 -0
- package/open-sse/translator/formats/responsesApi.js +141 -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 +252 -0
- package/open-sse/translator/request/antigravity-to-openai.js +242 -0
- package/open-sse/translator/request/claude-to-kiro.js +478 -0
- package/open-sse/translator/request/claude-to-openai.js +263 -0
- package/open-sse/translator/request/gemini-to-openai.js +152 -0
- package/open-sse/translator/request/openai-responses.js +385 -0
- package/open-sse/translator/request/openai-to-claude.js +383 -0
- package/open-sse/translator/request/openai-to-commandcode.js +176 -0
- package/open-sse/translator/request/openai-to-cursor.js +185 -0
- package/open-sse/translator/request/openai-to-gemini.js +442 -0
- package/open-sse/translator/request/openai-to-kiro.js +607 -0
- package/open-sse/translator/request/openai-to-kiro.old.js +278 -0
- package/open-sse/translator/request/openai-to-ollama.js +195 -0
- package/open-sse/translator/request/openai-to-vertex.js +42 -0
- package/open-sse/translator/response/claude-to-openai.js +195 -0
- package/open-sse/translator/response/commandcode-to-openai.js +188 -0
- package/open-sse/translator/response/cursor-to-openai.js +30 -0
- package/open-sse/translator/response/gemini-to-openai.js +147 -0
- package/open-sse/translator/response/kiro-to-claude.js +261 -0
- package/open-sse/translator/response/kiro-to-openai.js +160 -0
- package/open-sse/translator/response/ollama-to-openai.js +134 -0
- package/open-sse/translator/response/openai-responses.js +535 -0
- package/open-sse/translator/response/openai-to-antigravity.js +123 -0
- package/open-sse/translator/response/openai-to-claude.js +265 -0
- package/open-sse/translator/schema/blocks.js +43 -0
- package/open-sse/translator/schema/defaults.js +7 -0
- package/open-sse/translator/schema/finishReasons.js +27 -0
- package/open-sse/translator/schema/index.js +8 -0
- package/open-sse/translator/schema/roles.js +16 -0
- package/open-sse/utils/agentGoalPolicy.js +85 -0
- package/open-sse/utils/aiSdkCompat.js +75 -0
- package/open-sse/utils/bypassHandler.js +298 -0
- package/open-sse/utils/cacheControlPolicy.js +189 -0
- package/open-sse/utils/claudeCloaking.js +155 -0
- package/open-sse/utils/claudeHeaderCache.js +70 -0
- package/open-sse/utils/claudeSignature.js +41 -0
- package/open-sse/utils/clientDetector.js +63 -0
- package/open-sse/utils/codebuddySanitizer.js +96 -0
- package/open-sse/utils/composerToolCalls.js +158 -0
- package/open-sse/utils/cors.js +13 -0
- package/open-sse/utils/cursorChecksum.js +149 -0
- package/open-sse/utils/cursorImages.js +224 -0
- package/open-sse/utils/cursorProtobuf.js +904 -0
- package/open-sse/utils/cursorVersionDetector.js +55 -0
- package/open-sse/utils/debugLog.js +14 -0
- package/open-sse/utils/diagnostics.js +143 -0
- package/open-sse/utils/error.js +164 -0
- package/open-sse/utils/estimateSize.js +33 -0
- package/open-sse/utils/finishReason.js +32 -0
- package/open-sse/utils/flattenToolHistory.js +68 -0
- package/open-sse/utils/headers.js +36 -0
- package/open-sse/utils/heapPressure.js +35 -0
- package/open-sse/utils/jsonToSse.js +125 -0
- package/open-sse/utils/keepaliveThreshold.js +40 -0
- package/open-sse/utils/logger.js +104 -0
- package/open-sse/utils/noThinkingAlias.js +74 -0
- package/open-sse/utils/number.js +7 -0
- package/open-sse/utils/ollamaTransform.js +85 -0
- package/open-sse/utils/opencodeHeaders.js +47 -0
- package/open-sse/utils/progressTracker.js +81 -0
- package/open-sse/utils/providerRequestLogging.js +219 -0
- package/open-sse/utils/proxyFetch.js +369 -0
- package/open-sse/utils/reasoningContentInjector.js +79 -0
- package/open-sse/utils/reasoningFields.js +70 -0
- package/open-sse/utils/requestLogger.js +260 -0
- package/open-sse/utils/responsesInputNormalization.js +92 -0
- package/open-sse/utils/responsesStatePolicy.js +52 -0
- package/open-sse/utils/responsesStreamHelpers.js +49 -0
- package/open-sse/utils/sessionManager.js +240 -0
- package/open-sse/utils/sleep.js +6 -0
- package/open-sse/utils/sse.js +14 -0
- package/open-sse/utils/sseConstants.js +23 -0
- package/open-sse/utils/sseHeartbeat.js +104 -0
- package/open-sse/utils/stream.js +517 -0
- package/open-sse/utils/streamFailureFinalization.js +134 -0
- package/open-sse/utils/streamHandler.js +250 -0
- package/open-sse/utils/streamHelpers.js +137 -0
- package/open-sse/utils/textualToolCall.js +104 -0
- package/open-sse/utils/thinkCloseMarker.js +72 -0
- package/open-sse/utils/thinkTagParser.js +146 -0
- package/open-sse/utils/toolCallArguments.js +12 -0
- package/open-sse/utils/toolDeduper.js +49 -0
- package/open-sse/utils/toolSources.js +31 -0
- package/open-sse/utils/upstreamResponseHeaders.js +25 -0
- package/open-sse/utils/urlSanitize.js +15 -0
- package/open-sse/utils/usageTracking.js +347 -0
- package/package.json +1 -1
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import * as crypto from "node:crypto";
|
|
2
|
+
import * as os from "node:os";
|
|
3
|
+
import { BaseExecutor } from "./base.ts";
|
|
4
|
+
import { createProxyDispatcher } from "../utils/proxyDispatcher.ts";
|
|
5
|
+
import { fetch as undiciFetch } from "undici";
|
|
6
|
+
const BOOTSTRAP_PATH = "/api/free-ai/bootstrap";
|
|
7
|
+
const CHAT_PATH = "/api/free-ai/openai/chat";
|
|
8
|
+
const JWT_REFRESH_BUFFER_MS = 5 * 60 * 1e3;
|
|
9
|
+
const BOOTSTRAP_TIMEOUT_MS = 15e3;
|
|
10
|
+
const COOLDOWN_BASE_MS = 5e3;
|
|
11
|
+
const COOLDOWN_MAX_MS = 6e4;
|
|
12
|
+
const MIMO_SOURCE = "mimocode-cli-free";
|
|
13
|
+
const MIMO_SYSTEM_MARKER = "You are MiMoCode, an interactive CLI tool that helps users with software engineering tasks.";
|
|
14
|
+
function injectSystemMarker(body) {
|
|
15
|
+
const messages = body.messages;
|
|
16
|
+
if (!Array.isArray(messages)) return body;
|
|
17
|
+
const hasMarker = messages.some(
|
|
18
|
+
(m) => m != null && typeof m === "object" && m.role === "system" && typeof m.content === "string" && m.content.includes(MIMO_SYSTEM_MARKER)
|
|
19
|
+
);
|
|
20
|
+
if (hasMarker) return body;
|
|
21
|
+
return { ...body, messages: [{ role: "system", content: MIMO_SYSTEM_MARKER }, ...messages] };
|
|
22
|
+
}
|
|
23
|
+
const USER_AGENTS = [
|
|
24
|
+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36",
|
|
25
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36",
|
|
26
|
+
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36"
|
|
27
|
+
];
|
|
28
|
+
function parseJwtExp(jwt) {
|
|
29
|
+
try {
|
|
30
|
+
const parts = jwt.split(".");
|
|
31
|
+
if (parts.length < 2) return Date.now() + 50 * 60 * 1e3;
|
|
32
|
+
const payload = JSON.parse(Buffer.from(parts[1], "base64url").toString());
|
|
33
|
+
return (payload.exp ?? Math.floor(Date.now() / 1e3) + 3e3) * 1e3;
|
|
34
|
+
} catch {
|
|
35
|
+
return Date.now() + 50 * 60 * 1e3;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function isAccountReady(account) {
|
|
39
|
+
if (account.cooldownUntil > Date.now()) return false;
|
|
40
|
+
if (account.jwt && account.expiresAt - Date.now() > JWT_REFRESH_BUFFER_MS) return true;
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
function getCpuModel() {
|
|
44
|
+
try {
|
|
45
|
+
const cpus = os.cpus();
|
|
46
|
+
if (cpus.length > 0 && cpus[0].model) return cpus[0].model.trim();
|
|
47
|
+
} catch {
|
|
48
|
+
}
|
|
49
|
+
return "unknown-cpu";
|
|
50
|
+
}
|
|
51
|
+
function generateFingerprint(seed) {
|
|
52
|
+
if (seed) return crypto.createHash("sha256").update(seed).digest("hex");
|
|
53
|
+
const hostname = os.hostname();
|
|
54
|
+
const platform = os.platform();
|
|
55
|
+
const arch = os.arch();
|
|
56
|
+
const cpu = getCpuModel();
|
|
57
|
+
let username = "unknown-user";
|
|
58
|
+
try {
|
|
59
|
+
username = os.userInfo().username;
|
|
60
|
+
} catch {
|
|
61
|
+
}
|
|
62
|
+
return crypto.createHash("sha256").update(`${hostname}|${platform}|${arch}|${cpu}|${username}`).digest("hex");
|
|
63
|
+
}
|
|
64
|
+
const bootstrapInflight = /* @__PURE__ */ new Map();
|
|
65
|
+
async function bootstrapJwt(baseUrl, fingerprint, signal, dispatcher) {
|
|
66
|
+
const existing = bootstrapInflight.get(fingerprint);
|
|
67
|
+
if (existing) return existing;
|
|
68
|
+
const url = `${baseUrl}${BOOTSTRAP_PATH}`;
|
|
69
|
+
const controller = new AbortController();
|
|
70
|
+
const timer = setTimeout(() => controller.abort(), BOOTSTRAP_TIMEOUT_MS);
|
|
71
|
+
const onSignal = signal ? () => controller.abort(signal.reason) : null;
|
|
72
|
+
if (signal && onSignal) signal.addEventListener("abort", onSignal, { once: true });
|
|
73
|
+
const promise = (async () => {
|
|
74
|
+
try {
|
|
75
|
+
const resp = dispatcher ? await undiciFetch(url, {
|
|
76
|
+
method: "POST",
|
|
77
|
+
headers: { "Content-Type": "application/json" },
|
|
78
|
+
body: JSON.stringify({ client: fingerprint }),
|
|
79
|
+
signal: controller.signal,
|
|
80
|
+
dispatcher
|
|
81
|
+
}) : await fetch(url, {
|
|
82
|
+
method: "POST",
|
|
83
|
+
headers: { "Content-Type": "application/json" },
|
|
84
|
+
body: JSON.stringify({ client: fingerprint }),
|
|
85
|
+
signal: controller.signal
|
|
86
|
+
});
|
|
87
|
+
if (!resp.ok) {
|
|
88
|
+
const body = await resp.text().catch(() => "");
|
|
89
|
+
throw new Error(`Bootstrap failed: ${resp.status} ${body.slice(0, 200)}`);
|
|
90
|
+
}
|
|
91
|
+
const data = await resp.json();
|
|
92
|
+
if (!data.jwt) throw new Error("Bootstrap response missing jwt field");
|
|
93
|
+
return { jwt: data.jwt, expiresAt: parseJwtExp(data.jwt) };
|
|
94
|
+
} finally {
|
|
95
|
+
clearTimeout(timer);
|
|
96
|
+
if (signal && onSignal) signal.removeEventListener("abort", onSignal);
|
|
97
|
+
bootstrapInflight.delete(fingerprint);
|
|
98
|
+
}
|
|
99
|
+
})();
|
|
100
|
+
bootstrapInflight.set(fingerprint, promise);
|
|
101
|
+
return promise;
|
|
102
|
+
}
|
|
103
|
+
function rewriteModelName(model) {
|
|
104
|
+
const idx = model.lastIndexOf("/");
|
|
105
|
+
return idx >= 0 ? model.slice(idx + 1) : model;
|
|
106
|
+
}
|
|
107
|
+
class MimocodeExecutor extends BaseExecutor {
|
|
108
|
+
accounts = [];
|
|
109
|
+
nextAccountIdx = 0;
|
|
110
|
+
baseUrl;
|
|
111
|
+
proxyUrlMap = /* @__PURE__ */ new Map();
|
|
112
|
+
static encoder = new TextEncoder();
|
|
113
|
+
constructor() {
|
|
114
|
+
super("mimocode", { format: "openai" });
|
|
115
|
+
this.baseUrl = this.getBaseUrls()[0] || "https://api.xiaomimimo.com";
|
|
116
|
+
this.accounts.push({
|
|
117
|
+
fingerprint: generateFingerprint(),
|
|
118
|
+
jwt: "",
|
|
119
|
+
expiresAt: 0,
|
|
120
|
+
cooldownUntil: 0,
|
|
121
|
+
consecutiveFails: 0,
|
|
122
|
+
// #3837/#5521 backward compat: default the per-account proxy to null (not undefined),
|
|
123
|
+
// mirroring the syncAccountsFromCredentials() account builder, so an executor with no
|
|
124
|
+
// accountProxies config still exposes `acct.proxy === null` on every account.
|
|
125
|
+
proxy: null
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
getProxyDispatcher(fingerprint) {
|
|
129
|
+
const proxyUrl = this.proxyUrlMap.get(fingerprint);
|
|
130
|
+
if (!proxyUrl) return void 0;
|
|
131
|
+
return createProxyDispatcher(proxyUrl);
|
|
132
|
+
}
|
|
133
|
+
fetchWithProxy(url, init, fingerprint) {
|
|
134
|
+
const dispatcher = this.getProxyDispatcher(fingerprint);
|
|
135
|
+
if (dispatcher) {
|
|
136
|
+
const undiciFn = undiciFetch;
|
|
137
|
+
return undiciFn(url, { ...init, dispatcher });
|
|
138
|
+
}
|
|
139
|
+
return fetch(url, init);
|
|
140
|
+
}
|
|
141
|
+
syncAccountsFromCredentials(credentials) {
|
|
142
|
+
const psd = credentials?.providerSpecificData;
|
|
143
|
+
const fingerprints = psd?.fingerprints;
|
|
144
|
+
const accountProxies = psd?.accountProxies;
|
|
145
|
+
if (Array.isArray(accountProxies)) {
|
|
146
|
+
for (const entry of accountProxies) {
|
|
147
|
+
if (entry?.fingerprint && entry?.proxy?.host) {
|
|
148
|
+
const {
|
|
149
|
+
type = "socks5",
|
|
150
|
+
host,
|
|
151
|
+
port,
|
|
152
|
+
username,
|
|
153
|
+
password
|
|
154
|
+
} = entry.proxy;
|
|
155
|
+
const resolvedPort = port ?? (type === "socks5" ? 1080 : 8080);
|
|
156
|
+
const auth = username ? `${encodeURIComponent(username)}:${password ? encodeURIComponent(password) : ""}@` : "";
|
|
157
|
+
this.proxyUrlMap.set(entry.fingerprint, `${type}://${auth}${host}:${resolvedPort}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (Array.isArray(fingerprints)) {
|
|
162
|
+
const existing = new Set(this.accounts.map((a) => a.fingerprint));
|
|
163
|
+
for (const fp of fingerprints) {
|
|
164
|
+
if (typeof fp === "string" && !existing.has(fp)) {
|
|
165
|
+
this.accounts.push({
|
|
166
|
+
fingerprint: fp,
|
|
167
|
+
jwt: "",
|
|
168
|
+
expiresAt: 0,
|
|
169
|
+
cooldownUntil: 0,
|
|
170
|
+
consecutiveFails: 0,
|
|
171
|
+
proxy: null
|
|
172
|
+
});
|
|
173
|
+
existing.add(fp);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const proxyMap = Array.isArray(accountProxies) ? new Map(accountProxies.map((ap) => [ap.fingerprint, ap.proxy])) : null;
|
|
178
|
+
for (const acct of this.accounts) {
|
|
179
|
+
if (proxyMap) {
|
|
180
|
+
const entry = proxyMap.get(acct.fingerprint);
|
|
181
|
+
acct.proxy = entry !== void 0 ? entry ?? null : null;
|
|
182
|
+
} else {
|
|
183
|
+
acct.proxy = null;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
async getJwtForAccount(account, signal) {
|
|
188
|
+
if (isAccountReady(account)) return account.jwt;
|
|
189
|
+
const dispatcher = this.getProxyDispatcher(account.fingerprint);
|
|
190
|
+
const result = await bootstrapJwt(this.baseUrl, account.fingerprint, signal, dispatcher);
|
|
191
|
+
account.jwt = result.jwt;
|
|
192
|
+
account.expiresAt = result.expiresAt;
|
|
193
|
+
return account.jwt;
|
|
194
|
+
}
|
|
195
|
+
pickAccount() {
|
|
196
|
+
for (let i = 0; i < this.accounts.length; i++) {
|
|
197
|
+
const idx = (this.nextAccountIdx + i) % this.accounts.length;
|
|
198
|
+
const acct = this.accounts[idx];
|
|
199
|
+
if (isAccountReady(acct)) {
|
|
200
|
+
this.nextAccountIdx = (idx + 1) % this.accounts.length;
|
|
201
|
+
return acct;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const fallbackIdx = this.nextAccountIdx % this.accounts.length;
|
|
205
|
+
this.nextAccountIdx = (this.nextAccountIdx + 1) % this.accounts.length;
|
|
206
|
+
return this.accounts[fallbackIdx];
|
|
207
|
+
}
|
|
208
|
+
markCooldown(account) {
|
|
209
|
+
account.consecutiveFails++;
|
|
210
|
+
const backoff = Math.min(
|
|
211
|
+
COOLDOWN_BASE_MS * Math.pow(2, account.consecutiveFails - 1),
|
|
212
|
+
COOLDOWN_MAX_MS
|
|
213
|
+
);
|
|
214
|
+
account.cooldownUntil = Date.now() + backoff + Math.random() * 1e3;
|
|
215
|
+
}
|
|
216
|
+
markSuccess(account) {
|
|
217
|
+
account.consecutiveFails = 0;
|
|
218
|
+
}
|
|
219
|
+
buildUrl(_model, _stream, _urlIndex = 0, _credentials) {
|
|
220
|
+
return `${this.baseUrl.replace(/\/$/, "")}${CHAT_PATH}`;
|
|
221
|
+
}
|
|
222
|
+
buildHeaders(_credentials, stream = true, _clientHeaders, _model) {
|
|
223
|
+
const headers = {
|
|
224
|
+
"Content-Type": "application/json",
|
|
225
|
+
"X-Mimo-Source": MIMO_SOURCE,
|
|
226
|
+
"User-Agent": USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)]
|
|
227
|
+
};
|
|
228
|
+
if (stream) headers["Accept"] = "text/event-stream, application/json";
|
|
229
|
+
return headers;
|
|
230
|
+
}
|
|
231
|
+
transformRequest(model, body, _stream, _credentials) {
|
|
232
|
+
if (typeof body === "object" && body !== null) {
|
|
233
|
+
const withModel = { ...body, model: rewriteModelName(model) };
|
|
234
|
+
return injectSystemMarker(withModel);
|
|
235
|
+
}
|
|
236
|
+
return body;
|
|
237
|
+
}
|
|
238
|
+
async testConnection(_credentials, _signal, log) {
|
|
239
|
+
try {
|
|
240
|
+
this.syncAccountsFromCredentials(_credentials);
|
|
241
|
+
const account = this.accounts[0];
|
|
242
|
+
const jwt = await this.getJwtForAccount(account, _signal);
|
|
243
|
+
const resp = await this.fetchWithProxy(
|
|
244
|
+
this.buildUrl("mimo-auto", false),
|
|
245
|
+
{
|
|
246
|
+
method: "POST",
|
|
247
|
+
headers: {
|
|
248
|
+
"Content-Type": "application/json",
|
|
249
|
+
Authorization: `Bearer ${jwt}`,
|
|
250
|
+
"X-Mimo-Source": MIMO_SOURCE
|
|
251
|
+
},
|
|
252
|
+
body: JSON.stringify(
|
|
253
|
+
injectSystemMarker({
|
|
254
|
+
model: "mimo-auto",
|
|
255
|
+
messages: [{ role: "user", content: "ping" }],
|
|
256
|
+
stream: false
|
|
257
|
+
})
|
|
258
|
+
),
|
|
259
|
+
signal: _signal ?? void 0
|
|
260
|
+
},
|
|
261
|
+
account.fingerprint
|
|
262
|
+
);
|
|
263
|
+
return resp.status === 200;
|
|
264
|
+
} catch {
|
|
265
|
+
log?.warn?.("MIMOCODE", "testConnection network error");
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
async execute(input) {
|
|
270
|
+
const { model, stream, body, signal, log } = input;
|
|
271
|
+
const encoder = MimocodeExecutor.encoder;
|
|
272
|
+
if (signal?.aborted) {
|
|
273
|
+
return {
|
|
274
|
+
response: new Response(
|
|
275
|
+
encoder.encode(
|
|
276
|
+
JSON.stringify({
|
|
277
|
+
error: { message: "Request aborted", type: "abort", code: "ABORTED" }
|
|
278
|
+
})
|
|
279
|
+
),
|
|
280
|
+
{ status: 499, headers: { "Content-Type": "application/json" } }
|
|
281
|
+
),
|
|
282
|
+
url: this.buildUrl(model, stream),
|
|
283
|
+
headers: this.buildHeaders(input.credentials, stream),
|
|
284
|
+
transformedBody: body
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
const url = this.buildUrl(model, stream);
|
|
288
|
+
const reqBody = this.transformRequest(model, body, stream, input.credentials);
|
|
289
|
+
this.syncAccountsFromCredentials(input.credentials);
|
|
290
|
+
for (let attempt = 0; attempt < this.accounts.length; attempt++) {
|
|
291
|
+
const account = this.pickAccount();
|
|
292
|
+
try {
|
|
293
|
+
const jwt = await this.getJwtForAccount(account, signal);
|
|
294
|
+
const headers = this.buildHeaders(input.credentials, stream);
|
|
295
|
+
headers["Authorization"] = `Bearer ${jwt}`;
|
|
296
|
+
let resp = await this.fetchWithProxy(
|
|
297
|
+
url,
|
|
298
|
+
{
|
|
299
|
+
method: "POST",
|
|
300
|
+
headers,
|
|
301
|
+
body: JSON.stringify(reqBody),
|
|
302
|
+
signal: signal ?? void 0
|
|
303
|
+
},
|
|
304
|
+
account.fingerprint
|
|
305
|
+
);
|
|
306
|
+
if (resp.status === 401 || resp.status === 403) {
|
|
307
|
+
log?.warn?.(
|
|
308
|
+
"MIMOCODE",
|
|
309
|
+
`Auth failed (${resp.status}) on account ${account.fingerprint.slice(0, 8)}\u2026`
|
|
310
|
+
);
|
|
311
|
+
account.jwt = "";
|
|
312
|
+
account.expiresAt = 0;
|
|
313
|
+
account.consecutiveFails = 0;
|
|
314
|
+
const freshJwt = await this.getJwtForAccount(account, signal);
|
|
315
|
+
headers["Authorization"] = `Bearer ${freshJwt}`;
|
|
316
|
+
resp = await this.fetchWithProxy(
|
|
317
|
+
url,
|
|
318
|
+
{
|
|
319
|
+
method: "POST",
|
|
320
|
+
headers,
|
|
321
|
+
body: JSON.stringify(reqBody),
|
|
322
|
+
signal: signal ?? void 0
|
|
323
|
+
},
|
|
324
|
+
account.fingerprint
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
if (resp.status === 429) {
|
|
328
|
+
this.markCooldown(account);
|
|
329
|
+
log?.warn?.(
|
|
330
|
+
"MIMOCODE",
|
|
331
|
+
`Rate limited on account ${account.fingerprint.slice(0, 8)}, trying next\u2026`
|
|
332
|
+
);
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
this.markSuccess(account);
|
|
336
|
+
const respHeaders = {};
|
|
337
|
+
resp.headers.forEach((v, k) => {
|
|
338
|
+
respHeaders[k] = v;
|
|
339
|
+
});
|
|
340
|
+
return {
|
|
341
|
+
response: resp,
|
|
342
|
+
url,
|
|
343
|
+
headers: respHeaders,
|
|
344
|
+
transformedBody: reqBody
|
|
345
|
+
};
|
|
346
|
+
} catch (err) {
|
|
347
|
+
this.markCooldown(account);
|
|
348
|
+
if (attempt === this.accounts.length - 1) {
|
|
349
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
350
|
+
log?.error?.("MIMOCODE", `Executor error: ${msg}`);
|
|
351
|
+
return {
|
|
352
|
+
response: new Response(
|
|
353
|
+
encoder.encode(
|
|
354
|
+
JSON.stringify({
|
|
355
|
+
error: { message: msg, type: "upstream_error", code: "EXECUTOR_ERROR" }
|
|
356
|
+
})
|
|
357
|
+
),
|
|
358
|
+
{ status: 502, headers: { "Content-Type": "application/json" } }
|
|
359
|
+
),
|
|
360
|
+
url,
|
|
361
|
+
headers: this.buildHeaders(input.credentials, stream),
|
|
362
|
+
transformedBody: body
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return {
|
|
368
|
+
response: new Response(
|
|
369
|
+
encoder.encode(
|
|
370
|
+
JSON.stringify({
|
|
371
|
+
error: {
|
|
372
|
+
message: "All accounts exhausted",
|
|
373
|
+
type: "upstream_error",
|
|
374
|
+
code: "NO_ACCOUNTS"
|
|
375
|
+
}
|
|
376
|
+
})
|
|
377
|
+
),
|
|
378
|
+
{ status: 502, headers: { "Content-Type": "application/json" } }
|
|
379
|
+
),
|
|
380
|
+
url,
|
|
381
|
+
headers: this.buildHeaders(input.credentials, stream),
|
|
382
|
+
transformedBody: body
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
var mimocode_default = MimocodeExecutor;
|
|
387
|
+
export {
|
|
388
|
+
MIMO_SYSTEM_MARKER,
|
|
389
|
+
MimocodeExecutor,
|
|
390
|
+
mimocode_default as default,
|
|
391
|
+
generateFingerprint
|
|
392
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseExecutor,
|
|
3
|
+
mergeUpstreamExtraHeaders,
|
|
4
|
+
mergeAbortSignals
|
|
5
|
+
} from "./base.ts";
|
|
6
|
+
import { FETCH_TIMEOUT_MS } from "../config/constants.ts";
|
|
7
|
+
import { buildErrorBody } from "../utils/error.js";
|
|
8
|
+
import { getSupervisor } from '../../../dist/lib/services/registry.js';
|
|
9
|
+
import { getOrCreateApiKey } from '../../../dist/lib/services/apiKey.js';
|
|
10
|
+
const DEFAULT_PORT = 20130;
|
|
11
|
+
const DEFAULT_HOST = "127.0.0.1";
|
|
12
|
+
const HEALTH_CHECK_TIMEOUT_MS = 3e3;
|
|
13
|
+
const NINEROUTER_FALLBACK_HINT = "connection_cooldown";
|
|
14
|
+
const NINEROUTER_FALLBACK_HINT_HEADER = "X-Omni-Fallback-Hint";
|
|
15
|
+
function resolveNineRouterBaseUrl() {
|
|
16
|
+
const host = process.env.NINEROUTER_HOST || DEFAULT_HOST;
|
|
17
|
+
const port = parseInt(process.env.NINEROUTER_PORT || String(DEFAULT_PORT), 10);
|
|
18
|
+
return `http://${host}:${port}`;
|
|
19
|
+
}
|
|
20
|
+
class NineRouterExecutor extends BaseExecutor {
|
|
21
|
+
upstreamBaseUrl;
|
|
22
|
+
constructor(baseUrl) {
|
|
23
|
+
const effectiveBase = baseUrl ?? resolveNineRouterBaseUrl();
|
|
24
|
+
super("9router", {
|
|
25
|
+
id: "9router",
|
|
26
|
+
baseUrl: `${effectiveBase}/v1/chat/completions`,
|
|
27
|
+
headers: { "Content-Type": "application/json" }
|
|
28
|
+
});
|
|
29
|
+
this.upstreamBaseUrl = effectiveBase;
|
|
30
|
+
}
|
|
31
|
+
buildUrl(_model, _stream, _urlIndex = 0, _credentials = null) {
|
|
32
|
+
return `${this.upstreamBaseUrl}/v1/chat/completions`;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Build a 503 service_not_running Response with the fallback hint header.
|
|
36
|
+
* Message goes through buildErrorBody to satisfy hard rule #12 (no raw err.message).
|
|
37
|
+
*/
|
|
38
|
+
buildServiceUnavailableResponse(message) {
|
|
39
|
+
const body = buildErrorBody(503, message);
|
|
40
|
+
body.error.code = "service_not_running";
|
|
41
|
+
return new Response(JSON.stringify(body), {
|
|
42
|
+
status: 503,
|
|
43
|
+
headers: {
|
|
44
|
+
"Content-Type": "application/json",
|
|
45
|
+
[NINEROUTER_FALLBACK_HINT_HEADER]: NINEROUTER_FALLBACK_HINT
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* True when the body matches the Anthropic Messages wire shape.
|
|
51
|
+
* The same heuristic used by CliproxyapiExecutor — see comments there for
|
|
52
|
+
* the reasoning behind each signal.
|
|
53
|
+
*/
|
|
54
|
+
isAnthropicShape(body) {
|
|
55
|
+
if (!body || typeof body !== "object") return false;
|
|
56
|
+
const b = body;
|
|
57
|
+
if (b.system !== void 0) return true;
|
|
58
|
+
if (b.thinking !== void 0) return true;
|
|
59
|
+
if (b.metadata && typeof b.metadata === "object" && b.metadata.user_id !== void 0)
|
|
60
|
+
return true;
|
|
61
|
+
const msgs = b.messages;
|
|
62
|
+
if (Array.isArray(msgs) && msgs.length > 0) {
|
|
63
|
+
const first = msgs[0];
|
|
64
|
+
if (Array.isArray(first?.content)) return true;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
selectEndpoint(body) {
|
|
69
|
+
return this.isAnthropicShape(body) ? "/v1/messages" : "/v1/chat/completions";
|
|
70
|
+
}
|
|
71
|
+
buildHeaders(credentials, stream = true) {
|
|
72
|
+
const key = credentials?.apiKey ?? credentials?.accessToken;
|
|
73
|
+
const headers = { "Content-Type": "application/json" };
|
|
74
|
+
if (key) headers["Authorization"] = `Bearer ${key}`;
|
|
75
|
+
if (stream) headers["Accept"] = "text/event-stream";
|
|
76
|
+
return headers;
|
|
77
|
+
}
|
|
78
|
+
transformRequest(model, body, _stream, _credentials) {
|
|
79
|
+
if (!body || typeof body !== "object") return body;
|
|
80
|
+
const transformed = { ...body };
|
|
81
|
+
if (transformed.model !== model) transformed.model = model;
|
|
82
|
+
return transformed;
|
|
83
|
+
}
|
|
84
|
+
async execute(input) {
|
|
85
|
+
const supervisor = getSupervisor("9router");
|
|
86
|
+
const status = supervisor?.getStatus();
|
|
87
|
+
if (!supervisor || status?.state !== "running") {
|
|
88
|
+
const stateLabel = status?.state ?? "unknown";
|
|
89
|
+
const msg = `9router is not running (state: ${stateLabel})`;
|
|
90
|
+
input.log?.warn?.("9ROUTER", msg);
|
|
91
|
+
return {
|
|
92
|
+
response: this.buildServiceUnavailableResponse(msg),
|
|
93
|
+
url: "",
|
|
94
|
+
headers: {},
|
|
95
|
+
transformedBody: null
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const dynamicPort = status.port;
|
|
99
|
+
const dynamicBaseUrl = `http://127.0.0.1:${dynamicPort}`;
|
|
100
|
+
const apiKey = await getOrCreateApiKey("9router");
|
|
101
|
+
const dynamicCredentials = { ...input.credentials, apiKey };
|
|
102
|
+
const innerModel = input.model.replace(/^9router\//, "");
|
|
103
|
+
const endpoint = this.selectEndpoint(input.body);
|
|
104
|
+
const url = `${dynamicBaseUrl}${endpoint}`;
|
|
105
|
+
const shape = endpoint === "/v1/messages" ? "anthropic" : "openai";
|
|
106
|
+
const headers = this.buildHeaders(dynamicCredentials, input.stream);
|
|
107
|
+
const transformedBody = this.transformRequest(
|
|
108
|
+
innerModel,
|
|
109
|
+
input.body,
|
|
110
|
+
input.stream,
|
|
111
|
+
dynamicCredentials
|
|
112
|
+
);
|
|
113
|
+
mergeUpstreamExtraHeaders(headers, input.upstreamExtraHeaders ?? null);
|
|
114
|
+
const timeoutSignal = AbortSignal.timeout(FETCH_TIMEOUT_MS);
|
|
115
|
+
const combinedSignal = input.signal ? mergeAbortSignals(input.signal, timeoutSignal) : timeoutSignal;
|
|
116
|
+
input.log?.info?.(
|
|
117
|
+
"9ROUTER",
|
|
118
|
+
`\u2192 ${url} (model: ${innerModel}, shape: ${shape}, port: ${dynamicPort})`
|
|
119
|
+
);
|
|
120
|
+
const response = await fetch(url, {
|
|
121
|
+
method: "POST",
|
|
122
|
+
headers,
|
|
123
|
+
body: JSON.stringify(transformedBody),
|
|
124
|
+
signal: combinedSignal
|
|
125
|
+
});
|
|
126
|
+
return { response, url, headers, transformedBody };
|
|
127
|
+
}
|
|
128
|
+
async healthCheck() {
|
|
129
|
+
const start = Date.now();
|
|
130
|
+
try {
|
|
131
|
+
const res = await fetch(`${this.upstreamBaseUrl}/api/health`, {
|
|
132
|
+
signal: AbortSignal.timeout(HEALTH_CHECK_TIMEOUT_MS)
|
|
133
|
+
});
|
|
134
|
+
return {
|
|
135
|
+
ok: res.ok,
|
|
136
|
+
latencyMs: Date.now() - start,
|
|
137
|
+
...!res.ok ? { error: `HTTP ${res.status}` } : {}
|
|
138
|
+
};
|
|
139
|
+
} catch (err) {
|
|
140
|
+
return {
|
|
141
|
+
ok: false,
|
|
142
|
+
latencyMs: Date.now() - start,
|
|
143
|
+
error: err instanceof Error ? err.message : String(err)
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
var ninerouter_default = NineRouterExecutor;
|
|
149
|
+
export {
|
|
150
|
+
NINEROUTER_FALLBACK_HINT,
|
|
151
|
+
NINEROUTER_FALLBACK_HINT_HEADER,
|
|
152
|
+
NineRouterExecutor,
|
|
153
|
+
ninerouter_default as default,
|
|
154
|
+
resolveNineRouterBaseUrl
|
|
155
|
+
};
|