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,130 @@
|
|
|
1
|
+
// OpenAI helper functions for translator
|
|
2
|
+
|
|
3
|
+
// Valid OpenAI content block types
|
|
4
|
+
export const VALID_OPENAI_CONTENT_TYPES = ["text", "image_url", "image", "input_audio", "audio_url"];
|
|
5
|
+
export const VALID_OPENAI_MESSAGE_TYPES = ["text", "image_url", "image", "tool_calls", "tool_result"];
|
|
6
|
+
|
|
7
|
+
// Filter messages to OpenAI standard format
|
|
8
|
+
// Remove: thinking, redacted_thinking, signature, and other non-OpenAI blocks
|
|
9
|
+
export function filterToOpenAIFormat(body) {
|
|
10
|
+
if (!body.messages || !Array.isArray(body.messages)) return body;
|
|
11
|
+
|
|
12
|
+
body.messages = body.messages.map(msg => {
|
|
13
|
+
// Normalize developer role to system (many providers don't support developer)
|
|
14
|
+
if (msg.role === "developer") msg = { ...msg, role: "system" };
|
|
15
|
+
|
|
16
|
+
// Keep tool messages as-is (OpenAI format)
|
|
17
|
+
if (msg.role === "tool") return msg;
|
|
18
|
+
|
|
19
|
+
// Keep assistant messages with tool_calls as-is
|
|
20
|
+
if (msg.role === "assistant" && msg.tool_calls) return msg;
|
|
21
|
+
|
|
22
|
+
// Handle string content
|
|
23
|
+
if (typeof msg.content === "string") return msg;
|
|
24
|
+
|
|
25
|
+
// Handle array content
|
|
26
|
+
if (Array.isArray(msg.content)) {
|
|
27
|
+
const filteredContent = [];
|
|
28
|
+
|
|
29
|
+
for (const block of msg.content) {
|
|
30
|
+
// Skip thinking blocks
|
|
31
|
+
if (block.type === "thinking" || block.type === "redacted_thinking") continue;
|
|
32
|
+
|
|
33
|
+
// Only keep valid OpenAI content types
|
|
34
|
+
if (VALID_OPENAI_CONTENT_TYPES.includes(block.type)) {
|
|
35
|
+
// Remove signature field if exists
|
|
36
|
+
const { signature, cache_control, ...cleanBlock } = block;
|
|
37
|
+
filteredContent.push(cleanBlock);
|
|
38
|
+
} else if (block.type === "tool_use") {
|
|
39
|
+
// Convert tool_use to tool_calls format (handled separately)
|
|
40
|
+
continue;
|
|
41
|
+
} else if (block.type === "tool_result") {
|
|
42
|
+
// Keep tool_result but clean it
|
|
43
|
+
const { signature, cache_control, ...cleanBlock } = block;
|
|
44
|
+
filteredContent.push(cleanBlock);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// If all content was filtered, add empty text
|
|
49
|
+
if (filteredContent.length === 0) {
|
|
50
|
+
filteredContent.push({ type: "text", text: "" });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return { ...msg, content: filteredContent };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return msg;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Filter out messages with only empty text (but NEVER filter tool messages)
|
|
60
|
+
body.messages = body.messages.filter(msg => {
|
|
61
|
+
// Always keep tool messages
|
|
62
|
+
if (msg.role === "tool") return true;
|
|
63
|
+
// Always keep assistant messages with tool_calls
|
|
64
|
+
if (msg.role === "assistant" && msg.tool_calls) return true;
|
|
65
|
+
|
|
66
|
+
if (typeof msg.content === "string") return msg.content.trim() !== "";
|
|
67
|
+
if (Array.isArray(msg.content)) {
|
|
68
|
+
return msg.content.some(b =>
|
|
69
|
+
(b.type === "text" && b.text?.trim()) ||
|
|
70
|
+
b.type !== "text"
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Remove empty tools array (some providers like QWEN reject it)
|
|
77
|
+
if (body.tools && Array.isArray(body.tools) && body.tools.length === 0) {
|
|
78
|
+
delete body.tools;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Normalize tools to OpenAI format (from Claude, Gemini, etc.)
|
|
82
|
+
if (body.tools && Array.isArray(body.tools) && body.tools.length > 0) {
|
|
83
|
+
body.tools = body.tools.map(tool => {
|
|
84
|
+
// Already OpenAI format
|
|
85
|
+
if (tool.type === "function" && tool.function) return tool;
|
|
86
|
+
|
|
87
|
+
// Claude format: {name, description, input_schema}
|
|
88
|
+
if (tool.name && (tool.input_schema || tool.description)) {
|
|
89
|
+
return {
|
|
90
|
+
type: "function",
|
|
91
|
+
function: {
|
|
92
|
+
name: tool.name,
|
|
93
|
+
description: String(tool.description || ""),
|
|
94
|
+
parameters: tool.input_schema || { type: "object", properties: {} }
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Gemini format: {functionDeclarations: [{name, description, parameters}]}
|
|
100
|
+
if (tool.functionDeclarations && Array.isArray(tool.functionDeclarations)) {
|
|
101
|
+
return tool.functionDeclarations.map(fn => ({
|
|
102
|
+
type: "function",
|
|
103
|
+
function: {
|
|
104
|
+
name: fn.name,
|
|
105
|
+
description: String(fn.description || ""),
|
|
106
|
+
parameters: fn.parameters || { type: "object", properties: {} }
|
|
107
|
+
}
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return tool;
|
|
112
|
+
}).flat();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Normalize tool_choice to OpenAI format
|
|
116
|
+
if (body.tool_choice && typeof body.tool_choice === "object") {
|
|
117
|
+
const choice = body.tool_choice;
|
|
118
|
+
// Claude format: {type: "auto|any|tool", name?: "..."}
|
|
119
|
+
if (choice.type === "auto") {
|
|
120
|
+
body.tool_choice = "auto";
|
|
121
|
+
} else if (choice.type === "any") {
|
|
122
|
+
body.tool_choice = "required";
|
|
123
|
+
} else if (choice.type === "tool" && choice.name) {
|
|
124
|
+
body.tool_choice = { type: "function", function: { name: choice.name } };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return body;
|
|
129
|
+
}
|
|
130
|
+
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize Responses API input to array format.
|
|
3
|
+
* Accepts string or array, returns array of message items.
|
|
4
|
+
* An empty array is treated like an empty string — providers require at least one user
|
|
5
|
+
* message, so we inject a placeholder rather than forwarding an empty messages[].
|
|
6
|
+
* @param {string|Array} input - raw input from Responses API body
|
|
7
|
+
* @returns {Array|null} normalized array or null if invalid
|
|
8
|
+
*/
|
|
9
|
+
export function normalizeResponsesInput(input) {
|
|
10
|
+
if (typeof input === "string") {
|
|
11
|
+
const text = input.trim() === "" ? "..." : input;
|
|
12
|
+
return [{ type: "message", role: "user", content: [{ type: "input_text", text }] }];
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(input)) {
|
|
15
|
+
// Empty input[] would produce messages:[] which all providers reject (#389)
|
|
16
|
+
if (input.length === 0) {
|
|
17
|
+
return [{ type: "message", role: "user", content: [{ type: "input_text", text: "..." }] }];
|
|
18
|
+
}
|
|
19
|
+
return input;
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Convert OpenAI Responses API format to standard chat completions format
|
|
26
|
+
* Responses API uses: { input: [...], instructions: "..." }
|
|
27
|
+
* Chat API uses: { messages: [...] }
|
|
28
|
+
*/
|
|
29
|
+
export function convertResponsesApiFormat(body) {
|
|
30
|
+
if (!body.input) return body;
|
|
31
|
+
|
|
32
|
+
const result = { ...body };
|
|
33
|
+
result.messages = [];
|
|
34
|
+
|
|
35
|
+
// Convert instructions to system message
|
|
36
|
+
if (body.instructions) {
|
|
37
|
+
result.messages.push({ role: "system", content: body.instructions });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Group items by conversation turn
|
|
41
|
+
let currentAssistantMsg = null;
|
|
42
|
+
let pendingToolCalls = [];
|
|
43
|
+
let pendingToolResults = [];
|
|
44
|
+
|
|
45
|
+
const inputItems = normalizeResponsesInput(body.input);
|
|
46
|
+
if (!inputItems) return body;
|
|
47
|
+
|
|
48
|
+
for (const item of inputItems) {
|
|
49
|
+
// Determine item type - Droid CLI sends role-based items without 'type' field
|
|
50
|
+
// Fallback: if no type but has role property, treat as message
|
|
51
|
+
const itemType = item.type || (item.role ? "message" : null);
|
|
52
|
+
|
|
53
|
+
if (itemType === "message") {
|
|
54
|
+
// Flush any pending assistant message with tool calls
|
|
55
|
+
if (currentAssistantMsg) {
|
|
56
|
+
result.messages.push(currentAssistantMsg);
|
|
57
|
+
currentAssistantMsg = null;
|
|
58
|
+
}
|
|
59
|
+
// Flush pending tool results
|
|
60
|
+
if (pendingToolResults.length > 0) {
|
|
61
|
+
for (const tr of pendingToolResults) {
|
|
62
|
+
result.messages.push(tr);
|
|
63
|
+
}
|
|
64
|
+
pendingToolResults = [];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Convert content: input_text → text, output_text → text, input_image → image_url
|
|
68
|
+
const content = Array.isArray(item.content)
|
|
69
|
+
? item.content.map(c => {
|
|
70
|
+
if (c.type === "input_text") return { type: "text", text: c.text };
|
|
71
|
+
if (c.type === "output_text") return { type: "text", text: c.text };
|
|
72
|
+
if (c.type === "input_image") {
|
|
73
|
+
const url = c.image_url || c.file_id || "";
|
|
74
|
+
return { type: "image_url", image_url: { url, detail: c.detail || "auto" } };
|
|
75
|
+
}
|
|
76
|
+
return c;
|
|
77
|
+
})
|
|
78
|
+
: item.content;
|
|
79
|
+
result.messages.push({ role: item.role, content });
|
|
80
|
+
}
|
|
81
|
+
else if (itemType === "function_call") {
|
|
82
|
+
// Start or append to assistant message with tool_calls
|
|
83
|
+
if (!currentAssistantMsg) {
|
|
84
|
+
currentAssistantMsg = {
|
|
85
|
+
role: "assistant",
|
|
86
|
+
content: null,
|
|
87
|
+
tool_calls: []
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// Skip items with empty/missing name — upstream APIs reject nameless tool calls (#444)
|
|
91
|
+
if (!item.name || typeof item.name !== "string" || item.name.trim() === "") continue;
|
|
92
|
+
currentAssistantMsg.tool_calls.push({
|
|
93
|
+
id: item.call_id,
|
|
94
|
+
type: "function",
|
|
95
|
+
function: {
|
|
96
|
+
name: item.name,
|
|
97
|
+
arguments: item.arguments
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
else if (itemType === "function_call_output") {
|
|
102
|
+
// Flush assistant message first if exists
|
|
103
|
+
if (currentAssistantMsg) {
|
|
104
|
+
result.messages.push(currentAssistantMsg);
|
|
105
|
+
currentAssistantMsg = null;
|
|
106
|
+
}
|
|
107
|
+
// Add tool result
|
|
108
|
+
pendingToolResults.push({
|
|
109
|
+
role: "tool",
|
|
110
|
+
tool_call_id: item.call_id,
|
|
111
|
+
content: typeof item.output === "string" ? item.output : JSON.stringify(item.output)
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
else if (itemType === "reasoning") {
|
|
115
|
+
// Skip reasoning items - they are for display only
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Flush remaining
|
|
121
|
+
if (currentAssistantMsg) {
|
|
122
|
+
result.messages.push(currentAssistantMsg);
|
|
123
|
+
}
|
|
124
|
+
if (pendingToolResults.length > 0) {
|
|
125
|
+
for (const tr of pendingToolResults) {
|
|
126
|
+
result.messages.push(tr);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Cleanup Responses API specific fields
|
|
131
|
+
delete result.input;
|
|
132
|
+
delete result.instructions;
|
|
133
|
+
delete result.include;
|
|
134
|
+
delete result.prompt_cache_key;
|
|
135
|
+
delete result.store;
|
|
136
|
+
delete result.reasoning;
|
|
137
|
+
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// Tool call helper functions for translator
|
|
2
|
+
|
|
3
|
+
// Anthropic tool_use.id must match: ^[a-zA-Z0-9_-]+$
|
|
4
|
+
const TOOL_ID_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
|
5
|
+
|
|
6
|
+
// Generate deterministic tool call ID from position + tool name (cache-friendly)
|
|
7
|
+
export function generateToolCallId(msgIndex = 0, tcIndex = 0, toolName = "") {
|
|
8
|
+
const name = toolName ? `_${toolName.replace(/[^a-zA-Z0-9_-]/g, "")}` : "";
|
|
9
|
+
return `call_msg${msgIndex}_tc${tcIndex}${name}`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Sanitize ID to match Anthropic pattern: keep only alphanumeric, underscore, hyphen
|
|
13
|
+
function sanitizeToolId(id) {
|
|
14
|
+
if (!id || typeof id !== "string") return null;
|
|
15
|
+
const sanitized = id.replace(/[^a-zA-Z0-9_-]/g, "");
|
|
16
|
+
return sanitized.length > 0 ? sanitized : null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Ensure all tool_calls have valid id field and arguments is string (some providers require it)
|
|
20
|
+
export function ensureToolCallIds(body) {
|
|
21
|
+
if (!body.messages || !Array.isArray(body.messages)) return body;
|
|
22
|
+
|
|
23
|
+
for (let i = 0; i < body.messages.length; i++) {
|
|
24
|
+
const msg = body.messages[i];
|
|
25
|
+
if (msg.role === "assistant" && msg.tool_calls && Array.isArray(msg.tool_calls)) {
|
|
26
|
+
for (let j = 0; j < msg.tool_calls.length; j++) {
|
|
27
|
+
const tc = msg.tool_calls[j];
|
|
28
|
+
// Validate or regenerate ID for Anthropic compatibility
|
|
29
|
+
if (!tc.id || !TOOL_ID_PATTERN.test(tc.id)) {
|
|
30
|
+
const sanitized = sanitizeToolId(tc.id);
|
|
31
|
+
tc.id = sanitized || generateToolCallId(i, j, tc.function?.name);
|
|
32
|
+
}
|
|
33
|
+
if (!tc.type) {
|
|
34
|
+
tc.type = "function";
|
|
35
|
+
}
|
|
36
|
+
// Ensure arguments is JSON string, not object
|
|
37
|
+
if (tc.function?.arguments && typeof tc.function.arguments !== "string") {
|
|
38
|
+
tc.function.arguments = JSON.stringify(tc.function.arguments);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Validate tool_call_id in tool messages (role: "tool")
|
|
44
|
+
if (msg.role === "tool" && msg.tool_call_id && !TOOL_ID_PATTERN.test(msg.tool_call_id)) {
|
|
45
|
+
const sanitized = sanitizeToolId(msg.tool_call_id);
|
|
46
|
+
msg.tool_call_id = sanitized || generateToolCallId(i, 0);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Also validate tool_use blocks in content (Claude format)
|
|
50
|
+
if (Array.isArray(msg.content)) {
|
|
51
|
+
for (let k = 0; k < msg.content.length; k++) {
|
|
52
|
+
const block = msg.content[k];
|
|
53
|
+
if (block.type === "tool_use" && block.id && !TOOL_ID_PATTERN.test(block.id)) {
|
|
54
|
+
const sanitized = sanitizeToolId(block.id);
|
|
55
|
+
block.id = sanitized || generateToolCallId(i, k, block.name);
|
|
56
|
+
}
|
|
57
|
+
// Validate tool_use_id in tool_result blocks
|
|
58
|
+
if (block.type === "tool_result" && block.tool_use_id && !TOOL_ID_PATTERN.test(block.tool_use_id)) {
|
|
59
|
+
const sanitized = sanitizeToolId(block.tool_use_id);
|
|
60
|
+
block.tool_use_id = sanitized || generateToolCallId(i, k);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return body;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Get tool_call ids from assistant message (OpenAI format: tool_calls, Claude format: tool_use in content)
|
|
70
|
+
export function getToolCallIds(msg) {
|
|
71
|
+
if (msg.role !== "assistant") return [];
|
|
72
|
+
|
|
73
|
+
const ids = [];
|
|
74
|
+
|
|
75
|
+
// OpenAI format: tool_calls array
|
|
76
|
+
if (msg.tool_calls && Array.isArray(msg.tool_calls)) {
|
|
77
|
+
for (const tc of msg.tool_calls) {
|
|
78
|
+
if (tc.id) ids.push(tc.id);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Claude format: tool_use blocks in content
|
|
83
|
+
if (Array.isArray(msg.content)) {
|
|
84
|
+
for (const block of msg.content) {
|
|
85
|
+
if (block.type === "tool_use" && block.id) {
|
|
86
|
+
ids.push(block.id);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return ids;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Check if user message has tool_result for given ids (OpenAI format: role=tool, Claude format: tool_result in content)
|
|
95
|
+
export function hasToolResults(msg, toolCallIds) {
|
|
96
|
+
if (!msg || !toolCallIds.length) return false;
|
|
97
|
+
|
|
98
|
+
// OpenAI format: role = "tool" with tool_call_id
|
|
99
|
+
if (msg.role === "tool" && msg.tool_call_id) {
|
|
100
|
+
return toolCallIds.includes(msg.tool_call_id);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Claude format: tool_result blocks in user message content
|
|
104
|
+
if (msg.role === "user" && Array.isArray(msg.content)) {
|
|
105
|
+
for (const block of msg.content) {
|
|
106
|
+
if (block.type === "tool_result" && toolCallIds.includes(block.tool_use_id)) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Fix missing tool responses - insert empty tool_result if assistant has tool_use but next message has no tool_result
|
|
116
|
+
export function fixMissingToolResponses(body) {
|
|
117
|
+
if (!body.messages || !Array.isArray(body.messages)) return body;
|
|
118
|
+
|
|
119
|
+
const newMessages = [];
|
|
120
|
+
|
|
121
|
+
for (let i = 0; i < body.messages.length; i++) {
|
|
122
|
+
const msg = body.messages[i];
|
|
123
|
+
const nextMsg = body.messages[i + 1];
|
|
124
|
+
|
|
125
|
+
newMessages.push(msg);
|
|
126
|
+
|
|
127
|
+
// Check if this is assistant with tool_calls/tool_use
|
|
128
|
+
const toolCallIds = getToolCallIds(msg);
|
|
129
|
+
if (toolCallIds.length === 0) continue;
|
|
130
|
+
|
|
131
|
+
// Check if next message has tool_result
|
|
132
|
+
if (nextMsg && !hasToolResults(nextMsg, toolCallIds)) {
|
|
133
|
+
// Insert tool responses for each tool_call
|
|
134
|
+
for (const id of toolCallIds) {
|
|
135
|
+
// OpenAI format: role = "tool"
|
|
136
|
+
newMessages.push({
|
|
137
|
+
role: "tool",
|
|
138
|
+
tool_call_id: id,
|
|
139
|
+
content: ""
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
body.messages = newMessages;
|
|
146
|
+
return body;
|
|
147
|
+
}
|
|
148
|
+
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { FORMATS } from "./formats.js";
|
|
2
|
+
import { ensureToolCallIds, fixMissingToolResponses } from "./helpers/toolCallHelper.js";
|
|
3
|
+
import { prepareClaudeRequest } from "./helpers/claudeHelper.js";
|
|
4
|
+
import { cloakClaudeTools } from "../utils/claudeCloaking.js";
|
|
5
|
+
import { filterToOpenAIFormat } from "./helpers/openaiHelper.js";
|
|
6
|
+
import { normalizeThinkingConfig } from "../services/provider.js";
|
|
7
|
+
import { AntigravityExecutor } from "../executors/antigravity.js";
|
|
8
|
+
|
|
9
|
+
// Registry for translators
|
|
10
|
+
const requestRegistry = new Map();
|
|
11
|
+
const responseRegistry = new Map();
|
|
12
|
+
|
|
13
|
+
// Track initialization state
|
|
14
|
+
let initialized = false;
|
|
15
|
+
|
|
16
|
+
// Register translator
|
|
17
|
+
export function register(from, to, requestFn, responseFn) {
|
|
18
|
+
const key = `${from}:${to}`;
|
|
19
|
+
if (requestFn) {
|
|
20
|
+
requestRegistry.set(key, requestFn);
|
|
21
|
+
}
|
|
22
|
+
if (responseFn) {
|
|
23
|
+
responseRegistry.set(key, responseFn);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Lazy load translators (called once on first use)
|
|
28
|
+
function ensureInitialized() {
|
|
29
|
+
if (initialized) return;
|
|
30
|
+
initialized = true;
|
|
31
|
+
|
|
32
|
+
// Request translators - sync require pattern for bundler
|
|
33
|
+
require("./request/claude-to-openai.js");
|
|
34
|
+
require("./request/openai-to-claude.js");
|
|
35
|
+
require("./request/gemini-to-openai.js");
|
|
36
|
+
require("./request/openai-to-gemini.js");
|
|
37
|
+
require("./request/openai-to-vertex.js");
|
|
38
|
+
require("./request/antigravity-to-openai.js");
|
|
39
|
+
require("./request/openai-responses.js");
|
|
40
|
+
require("./request/openai-to-kiro.js");
|
|
41
|
+
require("./request/openai-to-cursor.js");
|
|
42
|
+
require("./request/openai-to-ollama.js");
|
|
43
|
+
require("./request/openai-to-commandcode.js");
|
|
44
|
+
|
|
45
|
+
// Response translators
|
|
46
|
+
require("./response/claude-to-openai.js");
|
|
47
|
+
require("./response/openai-to-claude.js");
|
|
48
|
+
require("./response/gemini-to-openai.js");
|
|
49
|
+
require("./response/openai-to-antigravity.js");
|
|
50
|
+
require("./response/openai-responses.js");
|
|
51
|
+
require("./response/kiro-to-openai.js");
|
|
52
|
+
require("./response/cursor-to-openai.js");
|
|
53
|
+
require("./response/ollama-to-openai.js");
|
|
54
|
+
require("./response/commandcode-to-openai.js");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Strip specific content types from messages (explicit opt-in via strip[] in PROVIDER_MODELS)
|
|
58
|
+
function stripContentTypes(body, stripList = []) {
|
|
59
|
+
if (!stripList.length || !body.messages || !Array.isArray(body.messages)) return;
|
|
60
|
+
const imageTypes = new Set(["image_url", "image"]);
|
|
61
|
+
const audioTypes = new Set(["audio_url", "input_audio"]);
|
|
62
|
+
const shouldStrip = (type) => {
|
|
63
|
+
if (imageTypes.has(type)) return stripList.includes("image");
|
|
64
|
+
if (audioTypes.has(type)) return stripList.includes("audio");
|
|
65
|
+
return false;
|
|
66
|
+
};
|
|
67
|
+
for (const msg of body.messages) {
|
|
68
|
+
if (!Array.isArray(msg.content)) continue;
|
|
69
|
+
msg.content = msg.content.filter(part => !shouldStrip(part.type));
|
|
70
|
+
if (msg.content.length === 0) msg.content = "";
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Translate request: source -> openai -> target
|
|
75
|
+
export function translateRequest(sourceFormat, targetFormat, model, body, stream = true, credentials = null, provider = null, reqLogger = null, stripList = [], connectionId = null, clientTool = null) {
|
|
76
|
+
ensureInitialized();
|
|
77
|
+
let result = body;
|
|
78
|
+
|
|
79
|
+
// Strip explicit content types (opt-in via strip[] in PROVIDER_MODELS entry)
|
|
80
|
+
stripContentTypes(result, stripList);
|
|
81
|
+
|
|
82
|
+
// Normalize thinking config: remove if lastMessage is not user
|
|
83
|
+
normalizeThinkingConfig(result);
|
|
84
|
+
|
|
85
|
+
// Always ensure tool_calls have id (some providers require it)
|
|
86
|
+
ensureToolCallIds(result);
|
|
87
|
+
|
|
88
|
+
// Fix missing tool responses (insert empty tool_result if needed)
|
|
89
|
+
fixMissingToolResponses(result);
|
|
90
|
+
|
|
91
|
+
// If same format, skip translation steps
|
|
92
|
+
if (sourceFormat !== targetFormat) {
|
|
93
|
+
// Step 1: source -> openai (if source is not openai)
|
|
94
|
+
if (sourceFormat !== FORMATS.OPENAI) {
|
|
95
|
+
const toOpenAI = requestRegistry.get(`${sourceFormat}:${FORMATS.OPENAI}`);
|
|
96
|
+
if (toOpenAI) {
|
|
97
|
+
result = toOpenAI(model, result, stream, credentials);
|
|
98
|
+
// Log OpenAI intermediate format
|
|
99
|
+
reqLogger?.logOpenAIRequest?.(result);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Step 2: openai -> target (if target is not openai)
|
|
104
|
+
if (targetFormat !== FORMATS.OPENAI) {
|
|
105
|
+
const fromOpenAI = requestRegistry.get(`${FORMATS.OPENAI}:${targetFormat}`);
|
|
106
|
+
if (fromOpenAI) {
|
|
107
|
+
result = fromOpenAI(model, result, stream, credentials);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Always normalize to clean OpenAI format when target is OpenAI
|
|
113
|
+
// This handles hybrid requests (e.g., OpenAI messages + Claude tools)
|
|
114
|
+
if (targetFormat === FORMATS.OPENAI) {
|
|
115
|
+
result = filterToOpenAIFormat(result);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Final step: prepare request for Claude format endpoints
|
|
119
|
+
if (targetFormat === FORMATS.CLAUDE) {
|
|
120
|
+
const apiKey = credentials?.accessToken || credentials?.apiKey || null;
|
|
121
|
+
result = prepareClaudeRequest(result, provider, apiKey, connectionId);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Claude cloaking: rename client tools with _cc suffix (anti-ban)
|
|
125
|
+
// Only for claude provider (not anthropic-compatible-*) with OAuth token
|
|
126
|
+
if (provider === "claude") {
|
|
127
|
+
const apiKey = credentials?.accessToken || credentials?.apiKey || null;
|
|
128
|
+
if (apiKey?.includes("sk-ant-oat")) {
|
|
129
|
+
const { body: cloakedBody, toolNameMap } = cloakClaudeTools(result);
|
|
130
|
+
result = cloakedBody;
|
|
131
|
+
if (toolNameMap?.size > 0) {
|
|
132
|
+
result._toolNameMap = toolNameMap;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Antigravity cloaking disabled
|
|
138
|
+
// if (provider === FORMATS.ANTIGRAVITY && body.userAgent !== FORMATS.ANTIGRAVITY) {
|
|
139
|
+
// const { cloakedBody, toolNameMap } = AntigravityExecutor.cloakTools(result);
|
|
140
|
+
// result = cloakedBody;
|
|
141
|
+
// if (toolNameMap?.size > 0) {
|
|
142
|
+
// result._toolNameMap = toolNameMap;
|
|
143
|
+
// }
|
|
144
|
+
// }
|
|
145
|
+
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Translate response chunk: target -> openai -> source
|
|
150
|
+
export function translateResponse(targetFormat, sourceFormat, chunk, state) {
|
|
151
|
+
ensureInitialized();
|
|
152
|
+
// If same format, return as-is
|
|
153
|
+
if (sourceFormat === targetFormat) {
|
|
154
|
+
return [chunk];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
let results = [chunk];
|
|
158
|
+
let openaiResults = null; // Store OpenAI intermediate results
|
|
159
|
+
|
|
160
|
+
// Step 1: target -> openai (if target is not openai)
|
|
161
|
+
if (targetFormat !== FORMATS.OPENAI) {
|
|
162
|
+
const toOpenAI = responseRegistry.get(`${targetFormat}:${FORMATS.OPENAI}`);
|
|
163
|
+
if (toOpenAI) {
|
|
164
|
+
results = [];
|
|
165
|
+
const converted = toOpenAI(chunk, state);
|
|
166
|
+
if (converted) {
|
|
167
|
+
results = Array.isArray(converted) ? converted : [converted];
|
|
168
|
+
openaiResults = results; // Store OpenAI intermediate
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Step 2: openai -> source (if source is not openai)
|
|
174
|
+
if (sourceFormat !== FORMATS.OPENAI) {
|
|
175
|
+
const fromOpenAI = responseRegistry.get(`${FORMATS.OPENAI}:${sourceFormat}`);
|
|
176
|
+
if (fromOpenAI) {
|
|
177
|
+
const finalResults = [];
|
|
178
|
+
for (const r of results) {
|
|
179
|
+
const converted = fromOpenAI(r, state);
|
|
180
|
+
if (converted) {
|
|
181
|
+
finalResults.push(...(Array.isArray(converted) ? converted : [converted]));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
results = finalResults;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Attach OpenAI intermediate results for logging
|
|
189
|
+
if (openaiResults && sourceFormat !== FORMATS.OPENAI && targetFormat !== FORMATS.OPENAI) {
|
|
190
|
+
results._openaiIntermediate = openaiResults;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return results;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Check if translation needed
|
|
197
|
+
export function needsTranslation(sourceFormat, targetFormat) {
|
|
198
|
+
return sourceFormat !== targetFormat;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Initialize state for streaming response based on format
|
|
202
|
+
export function initState(sourceFormat) {
|
|
203
|
+
// Base state for all formats
|
|
204
|
+
const base = {
|
|
205
|
+
messageId: null,
|
|
206
|
+
model: null,
|
|
207
|
+
textBlockStarted: false,
|
|
208
|
+
thinkingBlockStarted: false,
|
|
209
|
+
inThinkingBlock: false,
|
|
210
|
+
currentBlockIndex: null,
|
|
211
|
+
toolCalls: new Map(),
|
|
212
|
+
finishReason: null,
|
|
213
|
+
finishReasonSent: false,
|
|
214
|
+
usage: null,
|
|
215
|
+
contentBlockIndex: -1
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// Add openai-responses specific fields
|
|
219
|
+
if (sourceFormat === FORMATS.OPENAI_RESPONSES) {
|
|
220
|
+
return {
|
|
221
|
+
...base,
|
|
222
|
+
seq: 0,
|
|
223
|
+
responseId: `resp_${Date.now()}`,
|
|
224
|
+
created: Math.floor(Date.now() / 1000),
|
|
225
|
+
started: false,
|
|
226
|
+
msgTextBuf: {},
|
|
227
|
+
msgItemAdded: {},
|
|
228
|
+
msgContentAdded: {},
|
|
229
|
+
msgItemDone: {},
|
|
230
|
+
reasoningId: "",
|
|
231
|
+
reasoningIndex: -1,
|
|
232
|
+
reasoningBuf: "",
|
|
233
|
+
reasoningPartAdded: false,
|
|
234
|
+
reasoningDone: false,
|
|
235
|
+
inThinking: false,
|
|
236
|
+
funcArgsBuf: {},
|
|
237
|
+
funcNames: {},
|
|
238
|
+
funcCallIds: {},
|
|
239
|
+
funcArgsDone: {},
|
|
240
|
+
funcItemDone: {},
|
|
241
|
+
completedSent: false
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return base;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Initialize all translators (kept for backward compatibility)
|
|
249
|
+
export function initTranslators() {
|
|
250
|
+
ensureInitialized();
|
|
251
|
+
}
|