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,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search Response Normalizers
|
|
3
|
+
*
|
|
4
|
+
* Ported from OmniRoute open-sse/handlers/search.ts.
|
|
5
|
+
* Each normalizer maps a provider-specific response into the unified SearchResult shape.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Build a unified SearchResult object. */
|
|
9
|
+
function makeResult(providerId, item, idx, now) {
|
|
10
|
+
const url = item.url || "";
|
|
11
|
+
return {
|
|
12
|
+
title: item.title || "",
|
|
13
|
+
url,
|
|
14
|
+
display_url: url ? url.replace(/^https?:\/\/(www\.)?/, "").split("?")[0] : undefined,
|
|
15
|
+
snippet: item.snippet || "",
|
|
16
|
+
position: idx + 1,
|
|
17
|
+
score: typeof item.score === "number" ? Math.min(1, Math.max(0, item.score)) : null,
|
|
18
|
+
published_at: item.published_at || null,
|
|
19
|
+
favicon_url: item.favicon_url || null,
|
|
20
|
+
content: item.full_text
|
|
21
|
+
? { format: item.text_format || "text", text: item.full_text, length: item.full_text.length }
|
|
22
|
+
: null,
|
|
23
|
+
metadata: {
|
|
24
|
+
author: item.author || null,
|
|
25
|
+
language: null,
|
|
26
|
+
source_type: item.source_type || null,
|
|
27
|
+
image_url: item.image_url || null,
|
|
28
|
+
},
|
|
29
|
+
citation: { provider: providerId, retrieved_at: now, rank: idx + 1 },
|
|
30
|
+
provider_raw: null,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function normalizeSerper(data, _query, searchType) {
|
|
35
|
+
const now = new Date().toISOString();
|
|
36
|
+
const items = searchType === "news" ? data.news : data.organic;
|
|
37
|
+
if (!Array.isArray(items)) return { results: [], totalResults: null };
|
|
38
|
+
const results = items.map((item, idx) =>
|
|
39
|
+
makeResult("serper", { title: item.title, url: item.link, snippet: item.snippet || item.description, published_at: item.date }, idx, now)
|
|
40
|
+
);
|
|
41
|
+
const total = data.searchParameters?.totalResults;
|
|
42
|
+
return { results, totalResults: typeof total === "number" ? total : null };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function normalizeBrave(data, _query, searchType) {
|
|
46
|
+
const now = new Date().toISOString();
|
|
47
|
+
const container = searchType === "news" ? data.news || data : data.web;
|
|
48
|
+
const items = container?.results;
|
|
49
|
+
if (!Array.isArray(items)) return { results: [], totalResults: null };
|
|
50
|
+
const results = items.map((item, idx) =>
|
|
51
|
+
makeResult("brave-search", {
|
|
52
|
+
title: item.title,
|
|
53
|
+
url: item.url,
|
|
54
|
+
snippet: item.description,
|
|
55
|
+
published_at: item.page_age || item.age,
|
|
56
|
+
favicon_url: item.meta_url?.favicon || item.favicon,
|
|
57
|
+
}, idx, now)
|
|
58
|
+
);
|
|
59
|
+
return { results, totalResults: container?.totalCount ?? null };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function normalizePerplexity(data, _query, _searchType) {
|
|
63
|
+
const now = new Date().toISOString();
|
|
64
|
+
const items = data.results;
|
|
65
|
+
if (!Array.isArray(items)) return { results: [], totalResults: null };
|
|
66
|
+
const results = items.map((item, idx) =>
|
|
67
|
+
makeResult("perplexity", { title: item.title, url: item.url, snippet: item.snippet, published_at: item.date || item.last_updated }, idx, now)
|
|
68
|
+
);
|
|
69
|
+
return { results, totalResults: results.length };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function normalizeExa(data, _query, _searchType) {
|
|
73
|
+
const now = new Date().toISOString();
|
|
74
|
+
const items = data.results;
|
|
75
|
+
if (!Array.isArray(items)) return { results: [], totalResults: null };
|
|
76
|
+
const results = items.map((item, idx) =>
|
|
77
|
+
makeResult("exa", {
|
|
78
|
+
title: item.title,
|
|
79
|
+
url: item.url,
|
|
80
|
+
snippet: item.highlights?.[0] || item.text?.slice(0, 300) || "",
|
|
81
|
+
score: item.score,
|
|
82
|
+
published_at: item.publishedDate,
|
|
83
|
+
favicon_url: item.favicon,
|
|
84
|
+
author: item.author,
|
|
85
|
+
image_url: item.image,
|
|
86
|
+
full_text: item.text,
|
|
87
|
+
text_format: "text",
|
|
88
|
+
}, idx, now)
|
|
89
|
+
);
|
|
90
|
+
return { results, totalResults: results.length };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function normalizeTavily(data, _query, _searchType) {
|
|
94
|
+
const now = new Date().toISOString();
|
|
95
|
+
const items = data.results;
|
|
96
|
+
if (!Array.isArray(items)) return { results: [], totalResults: null };
|
|
97
|
+
const results = items.map((item, idx) =>
|
|
98
|
+
makeResult("tavily", {
|
|
99
|
+
title: item.title,
|
|
100
|
+
url: item.url,
|
|
101
|
+
snippet: item.content || "",
|
|
102
|
+
score: item.score,
|
|
103
|
+
published_at: item.published_date,
|
|
104
|
+
full_text: item.raw_content,
|
|
105
|
+
text_format: "text",
|
|
106
|
+
}, idx, now)
|
|
107
|
+
);
|
|
108
|
+
return { results, totalResults: results.length };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function normalizeGooglePse(data, _query, _searchType) {
|
|
112
|
+
const now = new Date().toISOString();
|
|
113
|
+
const items = Array.isArray(data.items) ? data.items : [];
|
|
114
|
+
const results = items.map((item, idx) =>
|
|
115
|
+
makeResult("google-pse", {
|
|
116
|
+
title: item.title,
|
|
117
|
+
url: item.link,
|
|
118
|
+
snippet: item.snippet,
|
|
119
|
+
image_url: item.pagemap?.cse_image?.[0]?.src || item.pagemap?.cse_thumbnail?.[0]?.src || item.pagemap?.metatags?.[0]?.["og:image"],
|
|
120
|
+
}, idx, now)
|
|
121
|
+
);
|
|
122
|
+
const raw = data.searchInformation?.totalResults ?? data.queries?.request?.[0]?.totalResults ?? null;
|
|
123
|
+
const total = typeof raw === "string" ? Number(raw) : raw;
|
|
124
|
+
return { results, totalResults: Number.isFinite(total) ? total : null };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function normalizeLinkup(data, _query, _searchType) {
|
|
128
|
+
const now = new Date().toISOString();
|
|
129
|
+
const items = Array.isArray(data.results) ? data.results : [];
|
|
130
|
+
const results = items.map((item, idx) =>
|
|
131
|
+
makeResult("linkup", {
|
|
132
|
+
title: item.name || item.title,
|
|
133
|
+
url: item.url,
|
|
134
|
+
snippet: item.content || item.snippet || "",
|
|
135
|
+
source_type: item.type || "web",
|
|
136
|
+
image_url: item.image_url || item.imageUrl || null,
|
|
137
|
+
full_text: item.content,
|
|
138
|
+
text_format: "text",
|
|
139
|
+
}, idx, now)
|
|
140
|
+
);
|
|
141
|
+
return { results, totalResults: results.length };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function normalizeSearchApi(data, _query, _searchType) {
|
|
145
|
+
const now = new Date().toISOString();
|
|
146
|
+
const items = Array.isArray(data.organic_results) ? data.organic_results : Array.isArray(data.top_stories) ? data.top_stories : [];
|
|
147
|
+
const results = items.map((item, idx) =>
|
|
148
|
+
makeResult("searchapi", {
|
|
149
|
+
title: item.title,
|
|
150
|
+
url: item.link,
|
|
151
|
+
snippet: item.snippet || item.description || "",
|
|
152
|
+
published_at: item.date || item.published_at,
|
|
153
|
+
favicon_url: item.favicon,
|
|
154
|
+
author: item.source || null,
|
|
155
|
+
image_url: item.thumbnail || null,
|
|
156
|
+
}, idx, now)
|
|
157
|
+
);
|
|
158
|
+
const raw = data.search_information?.total_results;
|
|
159
|
+
const total = typeof raw === "number" ? raw : typeof raw === "string" ? Number(raw) : null;
|
|
160
|
+
return { results, totalResults: Number.isFinite(total) ? total : results.length };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function normalizeYouCom(data, _query, searchType) {
|
|
164
|
+
const now = new Date().toISOString();
|
|
165
|
+
const container = data?.results && typeof data.results === "object" ? data.results : undefined;
|
|
166
|
+
const section = searchType === "news" ? container?.news || [] : container?.web || [];
|
|
167
|
+
const items = Array.isArray(section) ? section : [];
|
|
168
|
+
const results = items.map((item, idx) => {
|
|
169
|
+
const firstSnippet = Array.isArray(item.snippets) ? item.snippets.find((v) => typeof v === "string") : null;
|
|
170
|
+
const livecrawlText = typeof item.markdown === "string" ? item.markdown : typeof item.html === "string" ? item.html : undefined;
|
|
171
|
+
const livecrawlFormat = typeof item.markdown === "string" ? "markdown" : "html";
|
|
172
|
+
return makeResult("youcom", {
|
|
173
|
+
title: item.title,
|
|
174
|
+
url: item.url,
|
|
175
|
+
snippet: typeof firstSnippet === "string" ? firstSnippet : typeof item.description === "string" ? item.description : "",
|
|
176
|
+
published_at: item.page_age,
|
|
177
|
+
favicon_url: item.favicon_url,
|
|
178
|
+
image_url: item.thumbnail_url,
|
|
179
|
+
source_type: searchType,
|
|
180
|
+
full_text: livecrawlText,
|
|
181
|
+
text_format: livecrawlText ? livecrawlFormat : undefined,
|
|
182
|
+
}, idx, now);
|
|
183
|
+
});
|
|
184
|
+
return { results, totalResults: results.length };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function normalizeSearxng(data, _query, _searchType) {
|
|
188
|
+
const now = new Date().toISOString();
|
|
189
|
+
const items = Array.isArray(data.results) ? data.results : [];
|
|
190
|
+
const results = items.map((item, idx) =>
|
|
191
|
+
makeResult("searxng", {
|
|
192
|
+
title: item.title,
|
|
193
|
+
url: item.url,
|
|
194
|
+
snippet: item.content || item.snippet || "",
|
|
195
|
+
published_at: item.publishedDate || item.published_date || null,
|
|
196
|
+
source_type: Array.isArray(item.engines) ? item.engines.join(", ") : item.engine || item.category || null,
|
|
197
|
+
image_url: item.thumbnail || item.img_src || null,
|
|
198
|
+
}, idx, now)
|
|
199
|
+
);
|
|
200
|
+
return { results, totalResults: results.length };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const NORMALIZERS = {
|
|
204
|
+
"serper": normalizeSerper,
|
|
205
|
+
"brave-search": normalizeBrave,
|
|
206
|
+
"perplexity": normalizePerplexity,
|
|
207
|
+
"exa": normalizeExa,
|
|
208
|
+
"tavily": normalizeTavily,
|
|
209
|
+
"google-pse": normalizeGooglePse,
|
|
210
|
+
"linkup": normalizeLinkup,
|
|
211
|
+
"searchapi": normalizeSearchApi,
|
|
212
|
+
"youcom": normalizeYouCom,
|
|
213
|
+
"searxng": normalizeSearxng,
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Dispatch to the appropriate normalizer based on providerId.
|
|
218
|
+
* @returns {{results: Array, totalResults: number|null}}
|
|
219
|
+
*/
|
|
220
|
+
export function normalizeSearchResponse(providerId, data, query, searchType) {
|
|
221
|
+
const fn = NORMALIZERS[providerId];
|
|
222
|
+
return fn ? fn(data, query, searchType) : { results: [], totalResults: null };
|
|
223
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { createErrorResult } from "../utils/error.js";
|
|
3
|
+
import { HTTP_STATUS } from "../config/runtimeConfig.js";
|
|
4
|
+
import { AI_PROVIDERS } from "../../src/shared/constants/providers.js";
|
|
5
|
+
|
|
6
|
+
// Build auth headers from sttConfig + token
|
|
7
|
+
function buildAuthHeaders(cfg, token) {
|
|
8
|
+
if (!token) return {};
|
|
9
|
+
switch (cfg.authHeader) {
|
|
10
|
+
case "bearer": return { "Authorization": `Bearer ${token}` };
|
|
11
|
+
case "token": return { "Authorization": `Token ${token}` };
|
|
12
|
+
case "x-api-key": return { "x-api-key": token };
|
|
13
|
+
case "key": return { "Authorization": `Key ${token}` };
|
|
14
|
+
default: return { "Authorization": `Bearer ${token}` };
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Map browser file MIME / ext → audio MIME for binary formats (deepgram/HF)
|
|
19
|
+
function resolveAudioContentType(file) {
|
|
20
|
+
const t = (file.type || "").toLowerCase();
|
|
21
|
+
if (t.startsWith("audio/")) return t;
|
|
22
|
+
const name = typeof file.name === "string" ? file.name.toLowerCase() : "";
|
|
23
|
+
const ext = name.includes(".") ? name.split(".").pop() : "";
|
|
24
|
+
const map = { mp3: "audio/mpeg", mp4: "audio/mp4", m4a: "audio/mp4", wav: "audio/wav", ogg: "audio/ogg", flac: "audio/flac", webm: "audio/webm", aac: "audio/aac", opus: "audio/opus" };
|
|
25
|
+
return map[ext] || "application/octet-stream";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function upstreamError(res) {
|
|
29
|
+
let txt = "";
|
|
30
|
+
try { txt = await res.text(); } catch {}
|
|
31
|
+
let msg = txt || `Upstream error (${res.status})`;
|
|
32
|
+
try { const j = JSON.parse(txt); msg = j?.error?.message || j?.error || j?.message || msg; } catch {}
|
|
33
|
+
return createErrorResult(res.status, typeof msg === "string" ? msg : JSON.stringify(msg));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Deepgram: raw binary POST + model query param
|
|
37
|
+
async function transcribeDeepgram(cfg, file, model, token, formData) {
|
|
38
|
+
const url = new URL(cfg.baseUrl);
|
|
39
|
+
url.searchParams.set("model", model);
|
|
40
|
+
url.searchParams.set("smart_format", "true");
|
|
41
|
+
url.searchParams.set("punctuate", "true");
|
|
42
|
+
const lang = formData.get("language");
|
|
43
|
+
if (typeof lang === "string" && lang.trim()) url.searchParams.set("language", lang.trim());
|
|
44
|
+
else url.searchParams.set("detect_language", "true");
|
|
45
|
+
|
|
46
|
+
const buf = await file.arrayBuffer();
|
|
47
|
+
const res = await fetch(url, {
|
|
48
|
+
method: "POST",
|
|
49
|
+
headers: { ...buildAuthHeaders(cfg, token), "Content-Type": resolveAudioContentType(file) },
|
|
50
|
+
body: buf,
|
|
51
|
+
});
|
|
52
|
+
if (!res.ok) return upstreamError(res);
|
|
53
|
+
const data = await res.json();
|
|
54
|
+
const text = data.results?.channels?.[0]?.alternatives?.[0]?.transcript ?? "";
|
|
55
|
+
return jsonResponse({ text });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// AssemblyAI: upload → submit → poll (max 120s)
|
|
59
|
+
async function transcribeAssemblyAI(cfg, file, model, token) {
|
|
60
|
+
const auth = buildAuthHeaders(cfg, token);
|
|
61
|
+
const buf = await file.arrayBuffer();
|
|
62
|
+
const up = await fetch("https://api.assemblyai.com/v2/upload", {
|
|
63
|
+
method: "POST", headers: { ...auth, "Content-Type": "application/octet-stream" }, body: buf,
|
|
64
|
+
});
|
|
65
|
+
if (!up.ok) return upstreamError(up);
|
|
66
|
+
const { upload_url } = await up.json();
|
|
67
|
+
|
|
68
|
+
const sub = await fetch(cfg.baseUrl, {
|
|
69
|
+
method: "POST",
|
|
70
|
+
headers: { ...auth, "Content-Type": "application/json" },
|
|
71
|
+
body: JSON.stringify({ audio_url: upload_url, speech_models: [model], language_detection: true }),
|
|
72
|
+
});
|
|
73
|
+
if (!sub.ok) return upstreamError(sub);
|
|
74
|
+
const { id } = await sub.json();
|
|
75
|
+
|
|
76
|
+
const start = Date.now();
|
|
77
|
+
while (Date.now() - start < 120_000) {
|
|
78
|
+
await new Promise((r) => setTimeout(r, 2000));
|
|
79
|
+
const poll = await fetch(`${cfg.baseUrl}/${id}`, { headers: auth });
|
|
80
|
+
if (!poll.ok) continue;
|
|
81
|
+
const r = await poll.json();
|
|
82
|
+
if (r.status === "completed") return jsonResponse({ text: r.text || "" });
|
|
83
|
+
if (r.status === "error") return createErrorResult(500, r.error || "AssemblyAI failed");
|
|
84
|
+
}
|
|
85
|
+
return createErrorResult(504, "AssemblyAI timeout after 120s");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Nvidia NIM: multipart, normalize response
|
|
89
|
+
async function transcribeNvidia(cfg, file, model, token) {
|
|
90
|
+
const fd = new FormData();
|
|
91
|
+
fd.append("file", file, file.name || "audio.wav");
|
|
92
|
+
fd.append("model", model);
|
|
93
|
+
const res = await fetch(cfg.baseUrl, { method: "POST", headers: buildAuthHeaders(cfg, token), body: fd });
|
|
94
|
+
if (!res.ok) return upstreamError(res);
|
|
95
|
+
const data = await res.json();
|
|
96
|
+
return jsonResponse({ text: data.text || data.transcript || "" });
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Gemini: generateContent with inline_data audio + transcription prompt
|
|
100
|
+
async function transcribeGemini(cfg, file, model, token, formData) {
|
|
101
|
+
const buf = await file.arrayBuffer();
|
|
102
|
+
const b64 = Buffer.from(buf).toString("base64");
|
|
103
|
+
const mime = resolveAudioContentType(file);
|
|
104
|
+
const lang = formData.get("language");
|
|
105
|
+
const userPrompt = formData.get("prompt");
|
|
106
|
+
let promptText = userPrompt && typeof userPrompt === "string" && userPrompt.trim()
|
|
107
|
+
? userPrompt.trim()
|
|
108
|
+
: "Generate a transcript of the speech. Return only the transcribed text, no commentary.";
|
|
109
|
+
if (typeof lang === "string" && lang.trim()) promptText += ` Language: ${lang.trim()}.`;
|
|
110
|
+
|
|
111
|
+
const url = `${cfg.baseUrl}/${model}:generateContent?key=${token}`;
|
|
112
|
+
const res = await fetch(url, {
|
|
113
|
+
method: "POST",
|
|
114
|
+
headers: { "Content-Type": "application/json" },
|
|
115
|
+
body: JSON.stringify({
|
|
116
|
+
contents: [{ parts: [{ text: promptText }, { inline_data: { mime_type: mime, data: b64 } }] }],
|
|
117
|
+
}),
|
|
118
|
+
});
|
|
119
|
+
if (!res.ok) return upstreamError(res);
|
|
120
|
+
const data = await res.json();
|
|
121
|
+
const text = data?.candidates?.[0]?.content?.parts?.map((p) => p.text).filter(Boolean).join("") || "";
|
|
122
|
+
return jsonResponse({ text });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// HuggingFace: POST raw binary to {baseUrl}/{model_id}
|
|
126
|
+
async function transcribeHuggingFace(cfg, file, model, token) {
|
|
127
|
+
if (model.includes("..") || model.includes("//")) return createErrorResult(400, "Invalid model ID");
|
|
128
|
+
const url = `${cfg.baseUrl.replace(/\/+$/, "")}/${model}`;
|
|
129
|
+
const buf = await file.arrayBuffer();
|
|
130
|
+
const res = await fetch(url, {
|
|
131
|
+
method: "POST",
|
|
132
|
+
headers: { ...buildAuthHeaders(cfg, token), "Content-Type": resolveAudioContentType(file) },
|
|
133
|
+
body: buf,
|
|
134
|
+
});
|
|
135
|
+
if (!res.ok) return upstreamError(res);
|
|
136
|
+
const data = await res.json();
|
|
137
|
+
return jsonResponse({ text: data.text || "" });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Default: OpenAI/Groq/Whisper-compatible multipart
|
|
141
|
+
async function transcribeOpenAICompatible(cfg, file, model, token, formData) {
|
|
142
|
+
const fd = new FormData();
|
|
143
|
+
fd.append("file", file, file.name || "audio.wav");
|
|
144
|
+
fd.append("model", model);
|
|
145
|
+
for (const k of ["language", "prompt", "response_format", "temperature"]) {
|
|
146
|
+
const v = formData.get(k);
|
|
147
|
+
if (v !== null && v !== undefined && v !== "") fd.append(k, v);
|
|
148
|
+
}
|
|
149
|
+
const res = await fetch(cfg.baseUrl, { method: "POST", headers: buildAuthHeaders(cfg, token), body: fd });
|
|
150
|
+
if (!res.ok) return upstreamError(res);
|
|
151
|
+
const ct = res.headers.get("content-type") || "application/json";
|
|
152
|
+
const txt = await res.text();
|
|
153
|
+
return { success: true, response: new Response(txt, { status: 200, headers: { "Content-Type": ct, "Access-Control-Allow-Origin": "*" } }) };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function jsonResponse(obj) {
|
|
157
|
+
return {
|
|
158
|
+
success: true,
|
|
159
|
+
response: new Response(JSON.stringify(obj), {
|
|
160
|
+
status: 200,
|
|
161
|
+
headers: { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*" },
|
|
162
|
+
}),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* STT core handler — dispatch by sttConfig.format.
|
|
168
|
+
* @returns {Promise<{success, response, status?, error?}>}
|
|
169
|
+
*/
|
|
170
|
+
export async function handleSttCore({ provider, model, formData, credentials }) {
|
|
171
|
+
const file = formData.get("file");
|
|
172
|
+
if (!file) return createErrorResult(HTTP_STATUS.BAD_REQUEST, "Missing required field: file");
|
|
173
|
+
|
|
174
|
+
const cfg = AI_PROVIDERS[provider]?.sttConfig;
|
|
175
|
+
if (!cfg) return createErrorResult(HTTP_STATUS.BAD_REQUEST, `Provider '${provider}' does not support STT`);
|
|
176
|
+
|
|
177
|
+
const token = cfg.authType === "none" ? null : (credentials?.apiKey || credentials?.accessToken);
|
|
178
|
+
if (cfg.authType !== "none" && !token) {
|
|
179
|
+
return createErrorResult(HTTP_STATUS.UNAUTHORIZED, `No credentials for STT provider: ${provider}`);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
try {
|
|
183
|
+
switch (cfg.format) {
|
|
184
|
+
case "deepgram": return await transcribeDeepgram(cfg, file, model, token, formData);
|
|
185
|
+
case "assemblyai": return await transcribeAssemblyAI(cfg, file, model, token);
|
|
186
|
+
case "nvidia-asr": return await transcribeNvidia(cfg, file, model, token);
|
|
187
|
+
case "huggingface-asr": return await transcribeHuggingFace(cfg, file, model, token);
|
|
188
|
+
case "gemini-stt": return await transcribeGemini(cfg, file, model, token, formData);
|
|
189
|
+
default: return await transcribeOpenAICompatible(cfg, file, model, token, formData);
|
|
190
|
+
}
|
|
191
|
+
} catch (err) {
|
|
192
|
+
return createErrorResult(HTTP_STATUS.BAD_GATEWAY, err.message || "STT request failed");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { createErrorResult } from "../utils/error.js";
|
|
3
|
+
import { HTTP_STATUS } from "../config/runtimeConfig.js";
|
|
4
|
+
import { getTtsAdapter, synthesizeViaConfig } from "./ttsProviders/index.js";
|
|
5
|
+
|
|
6
|
+
// Re-export voice fetchers + voices APIs for backward compat with existing routes
|
|
7
|
+
export {
|
|
8
|
+
VOICE_FETCHERS,
|
|
9
|
+
fetchEdgeTtsVoices,
|
|
10
|
+
fetchLocalDeviceVoices,
|
|
11
|
+
fetchElevenLabsVoices,
|
|
12
|
+
} from "./ttsProviders/index.js";
|
|
13
|
+
|
|
14
|
+
// ── Response Formatter (DRY) ───────────────────────────────────
|
|
15
|
+
function createTtsResponse(base64Audio, format, responseFormat) {
|
|
16
|
+
const audioBuffer = Buffer.from(base64Audio, "base64");
|
|
17
|
+
|
|
18
|
+
// JSON format: return base64 encoded audio
|
|
19
|
+
if (responseFormat === "json") {
|
|
20
|
+
return {
|
|
21
|
+
success: true,
|
|
22
|
+
response: new Response(JSON.stringify({ audio: base64Audio, format }), {
|
|
23
|
+
headers: {
|
|
24
|
+
"Content-Type": "application/json",
|
|
25
|
+
"Access-Control-Allow-Origin": "*",
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Binary format (default): return raw audio
|
|
32
|
+
return {
|
|
33
|
+
success: true,
|
|
34
|
+
response: new Response(audioBuffer, {
|
|
35
|
+
headers: {
|
|
36
|
+
"Content-Type": `audio/${format}`,
|
|
37
|
+
"Content-Length": String(audioBuffer.length),
|
|
38
|
+
"Access-Control-Allow-Origin": "*",
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ── Core handler ───────────────────────────────────────────────
|
|
45
|
+
/**
|
|
46
|
+
* Synthesize text to audio. Provider logic lives in `./ttsProviders/{id}.js`
|
|
47
|
+
* or is dispatched generically via `ttsConfig.format`.
|
|
48
|
+
*
|
|
49
|
+
* @returns {Promise<{success, response, status?, error?}>}
|
|
50
|
+
*/
|
|
51
|
+
export async function handleTtsCore({ provider, model, input, credentials, responseFormat = "mp3", language }) {
|
|
52
|
+
if (!input?.trim()) {
|
|
53
|
+
return createErrorResult(HTTP_STATUS.BAD_REQUEST, "Missing required field: input");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
// Special-case adapters (google-tts, edge-tts, local-device, elevenlabs, openai, openrouter, gemini)
|
|
58
|
+
const adapter = getTtsAdapter(provider);
|
|
59
|
+
if (adapter) {
|
|
60
|
+
const result = await adapter.synthesize(input.trim(), model, credentials, responseFormat, { language });
|
|
61
|
+
// Adapter may return a full {success, response} (legacy) or {base64, format}
|
|
62
|
+
if (result.success !== undefined) return result;
|
|
63
|
+
return createTtsResponse(result.base64, result.format, responseFormat);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Generic config-driven (hyperbolic, deepgram, nvidia, huggingface, inworld, cartesia, playht, coqui, tortoise, qwen, ...)
|
|
67
|
+
const result = await synthesizeViaConfig(provider, input.trim(), model, credentials);
|
|
68
|
+
if (result) return createTtsResponse(result.base64, result.format, responseFormat);
|
|
69
|
+
|
|
70
|
+
return createErrorResult(HTTP_STATUS.BAD_REQUEST, `Provider '${provider}' does not support TTS via this route.`);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
return createErrorResult(HTTP_STATUS.BAD_GATEWAY, err.message || "TTS synthesis failed");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Shared TTS helpers
|
|
2
|
+
import { Buffer } from "node:buffer";
|
|
3
|
+
|
|
4
|
+
export const UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36";
|
|
5
|
+
|
|
6
|
+
// Convert upstream Response (binary audio) to { base64, format }
|
|
7
|
+
export async function responseToBase64(res, defaultFormat = "mp3") {
|
|
8
|
+
const buf = await res.arrayBuffer();
|
|
9
|
+
if (buf.byteLength < 100) throw new Error("Upstream returned empty audio");
|
|
10
|
+
const ctype = res.headers.get("content-type") || "";
|
|
11
|
+
let format = defaultFormat;
|
|
12
|
+
if (ctype.includes("wav")) format = "wav";
|
|
13
|
+
else if (ctype.includes("mpeg") || ctype.includes("mp3")) format = "mp3";
|
|
14
|
+
else if (ctype.includes("ogg")) format = "ogg";
|
|
15
|
+
return { base64: Buffer.from(buf).toString("base64"), format };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function throwUpstreamError(res) {
|
|
19
|
+
const text = await res.text().catch(() => "");
|
|
20
|
+
let msg = `Upstream error (${res.status})`;
|
|
21
|
+
try {
|
|
22
|
+
const parsed = JSON.parse(text);
|
|
23
|
+
msg = parsed?.error?.message || parsed?.message || parsed?.detail?.message || (typeof parsed?.detail === "string" ? parsed.detail : null) || text || msg;
|
|
24
|
+
} catch { msg = text || msg; }
|
|
25
|
+
throw new Error(msg);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Parse `model` string as "modelId/voiceId" — match against known model list (longest prefix wins)
|
|
29
|
+
export function parseModelVoice(model, defaultModel = "", defaultVoice = "", knownModels = []) {
|
|
30
|
+
if (!model) return { modelId: defaultModel, voiceId: defaultVoice };
|
|
31
|
+
const known = knownModels.map((m) => m.id || m).filter(Boolean).sort((a, b) => b.length - a.length);
|
|
32
|
+
for (const id of known) {
|
|
33
|
+
if (model === id) return { modelId: id, voiceId: defaultVoice };
|
|
34
|
+
if (model.startsWith(`${id}/`)) return { modelId: id, voiceId: model.slice(id.length + 1) };
|
|
35
|
+
}
|
|
36
|
+
const idx = model.lastIndexOf("/");
|
|
37
|
+
if (idx > 0) return { modelId: model.slice(0, idx), voiceId: model.slice(idx + 1) };
|
|
38
|
+
return { modelId: defaultModel || model, voiceId: defaultVoice || model };
|
|
39
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Microsoft Edge / Bing TTS (no auth) — via Bing translator endpoint
|
|
2
|
+
import { Buffer } from "node:buffer";
|
|
3
|
+
import { UA } from "./_base.js";
|
|
4
|
+
|
|
5
|
+
const REFRESH_MS = 5 * 60 * 1000; // token TTL ~1h, refresh early
|
|
6
|
+
const VOICES_TTL = 24 * 60 * 60 * 1000;
|
|
7
|
+
|
|
8
|
+
const cache = { token: null, tokenTime: 0 };
|
|
9
|
+
let _voicesCache = null;
|
|
10
|
+
let _voicesCacheTime = 0;
|
|
11
|
+
|
|
12
|
+
async function getToken() {
|
|
13
|
+
const now = Date.now();
|
|
14
|
+
if (cache.token && now - cache.tokenTime < REFRESH_MS) return cache.token;
|
|
15
|
+
const res = await fetch("https://www.bing.com/translator", {
|
|
16
|
+
headers: { "User-Agent": UA, "Accept-Language": "vi,en-US;q=0.9,en;q=0.8" },
|
|
17
|
+
});
|
|
18
|
+
if (!res.ok) throw new Error(`Bing translator fetch failed: ${res.status}`);
|
|
19
|
+
const rawCookies = res.headers.getSetCookie?.() || [];
|
|
20
|
+
const cookie = rawCookies.map((c) => c.split(";")[0]).join("; ");
|
|
21
|
+
const html = await res.text();
|
|
22
|
+
const match = html.match(/params_AbusePreventionHelper\s*=\s*\[([^,]+),([^,]+),/);
|
|
23
|
+
if (!match) throw new Error("Failed to parse Bing token");
|
|
24
|
+
cache.token = { key: match[1], token: match[2].replace(/"/g, ""), cookie };
|
|
25
|
+
cache.tokenTime = now;
|
|
26
|
+
return cache.token;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function ttsRequest(text, voiceId, token) {
|
|
30
|
+
const parts = voiceId.split("-");
|
|
31
|
+
const xmlLang = parts.slice(0, 2).join("-");
|
|
32
|
+
const gender = voiceId.toLowerCase().includes("male") ? "Male" : "Female";
|
|
33
|
+
const ssml = `<speak version='1.0' xml:lang='${xmlLang}'><voice xml:lang='${xmlLang}' xml:gender='${gender}' name='${voiceId}'><prosody rate='0.00%'>${text}</prosody></voice></speak>`;
|
|
34
|
+
const body = new URLSearchParams();
|
|
35
|
+
body.append("ssml", ssml);
|
|
36
|
+
body.append("token", token.token);
|
|
37
|
+
body.append("key", token.key);
|
|
38
|
+
return fetch("https://www.bing.com/tfettts?isVertical=1&&IG=1&IID=translator.5023&SFX=1", {
|
|
39
|
+
method: "POST",
|
|
40
|
+
body: body.toString(),
|
|
41
|
+
headers: {
|
|
42
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
43
|
+
"Accept": "*/*",
|
|
44
|
+
"Origin": "https://www.bing.com",
|
|
45
|
+
"Referer": "https://www.bing.com/translator",
|
|
46
|
+
"User-Agent": UA,
|
|
47
|
+
...(token.cookie ? { "Cookie": token.cookie } : {}),
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function fetchEdgeTtsVoices() {
|
|
53
|
+
const now = Date.now();
|
|
54
|
+
if (_voicesCache && now - _voicesCacheTime < VOICES_TTL) return _voicesCache;
|
|
55
|
+
const res = await fetch(
|
|
56
|
+
"https://speech.platform.bing.com/consumer/speech/synthesize/readaloud/voices/list?trustedclienttoken=6A5AA1D4EAFF4E9FB37E23D68491D6F4",
|
|
57
|
+
{ headers: { "User-Agent": UA } }
|
|
58
|
+
);
|
|
59
|
+
if (!res.ok) throw new Error(`Edge TTS voices fetch failed: ${res.status}`);
|
|
60
|
+
const voices = await res.json();
|
|
61
|
+
_voicesCache = voices;
|
|
62
|
+
_voicesCacheTime = now;
|
|
63
|
+
return voices;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default {
|
|
67
|
+
noAuth: true,
|
|
68
|
+
async synthesize(text, model) {
|
|
69
|
+
const voiceId = model || "vi-VN-HoaiMyNeural";
|
|
70
|
+
let token = await getToken();
|
|
71
|
+
let res = await ttsRequest(text, voiceId, token);
|
|
72
|
+
|
|
73
|
+
// 429/403: invalidate cache and retry once
|
|
74
|
+
if (res.status === 429 || res.status === 403) {
|
|
75
|
+
cache.token = null;
|
|
76
|
+
cache.tokenTime = 0;
|
|
77
|
+
token = await getToken();
|
|
78
|
+
res = await ttsRequest(text, voiceId, token);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (!res.ok) {
|
|
82
|
+
const body = await res.text().catch(() => "");
|
|
83
|
+
throw new Error(`Bing TTS failed: ${res.status}${body ? " - " + body : ""}`);
|
|
84
|
+
}
|
|
85
|
+
const buf = await res.arrayBuffer();
|
|
86
|
+
if (buf.byteLength < 1024) throw new Error("Bing TTS returned empty audio");
|
|
87
|
+
return { base64: Buffer.from(buf).toString("base64"), format: "mp3" };
|
|
88
|
+
},
|
|
89
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// ElevenLabs TTS — voice id with optional model_id prefix
|
|
2
|
+
import { Buffer } from "node:buffer";
|
|
3
|
+
|
|
4
|
+
const VOICES_TTL = 24 * 60 * 60 * 1000;
|
|
5
|
+
const _voicesCache = new Map(); // by API key
|
|
6
|
+
|
|
7
|
+
export async function fetchElevenLabsVoices(apiKey) {
|
|
8
|
+
if (!apiKey) throw new Error("ElevenLabs API key required");
|
|
9
|
+
const now = Date.now();
|
|
10
|
+
const cached = _voicesCache.get(apiKey);
|
|
11
|
+
if (cached && now - cached.time < VOICES_TTL) return cached.voices;
|
|
12
|
+
|
|
13
|
+
const res = await fetch("https://api.elevenlabs.io/v1/voices", {
|
|
14
|
+
headers: { "xi-api-key": apiKey, "Content-Type": "application/json" },
|
|
15
|
+
});
|
|
16
|
+
if (!res.ok) throw new Error(`ElevenLabs voices fetch failed: ${res.status}`);
|
|
17
|
+
const data = await res.json();
|
|
18
|
+
// Normalize: derive lang from labels for grouping
|
|
19
|
+
const voices = (data.voices || []).map((v) => ({ ...v, lang: v.labels?.language || "en" }));
|
|
20
|
+
_voicesCache.set(apiKey, { voices, time: now });
|
|
21
|
+
return voices;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default {
|
|
25
|
+
async synthesize(text, model, credentials) {
|
|
26
|
+
if (!credentials?.apiKey) throw new Error("ElevenLabs API key required");
|
|
27
|
+
let modelId = "eleven_flash_v2_5";
|
|
28
|
+
let voiceId = model;
|
|
29
|
+
if (model && model.includes("/")) [modelId, voiceId] = model.split("/");
|
|
30
|
+
|
|
31
|
+
const res = await fetch(`https://api.elevenlabs.io/v1/text-to-speech/${voiceId}`, {
|
|
32
|
+
method: "POST",
|
|
33
|
+
headers: { "xi-api-key": credentials.apiKey, "Content-Type": "application/json" },
|
|
34
|
+
body: JSON.stringify({
|
|
35
|
+
text,
|
|
36
|
+
model_id: modelId,
|
|
37
|
+
voice_settings: { stability: 0.5, similarity_boost: 0.75 },
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
if (!res.ok) {
|
|
41
|
+
const err = await res.json().catch(() => ({}));
|
|
42
|
+
throw new Error(err?.detail?.message || `ElevenLabs TTS failed: ${res.status}`);
|
|
43
|
+
}
|
|
44
|
+
const buf = await res.arrayBuffer();
|
|
45
|
+
if (buf.byteLength < 1024) throw new Error("ElevenLabs TTS returned empty audio");
|
|
46
|
+
return { base64: Buffer.from(buf).toString("base64"), format: "mp3" };
|
|
47
|
+
},
|
|
48
|
+
};
|