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,612 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState, useEffect, useCallback } from "react";
|
|
4
|
+
import { DndContext, closestCenter, KeyboardSensor, PointerSensor, useSensor, useSensors } from "@dnd-kit/core";
|
|
5
|
+
import { arrayMove, SortableContext, sortableKeyboardCoordinates, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
|
|
6
|
+
import { CSS } from "@dnd-kit/utilities";
|
|
7
|
+
import { restrictToVerticalAxis, restrictToParentElement } from "@dnd-kit/modifiers";
|
|
8
|
+
import { Card, Button, Modal, Input, CardSkeleton, ModelSelectModal, Toggle, ConfirmModal, Pagination } from "@/shared/components";
|
|
9
|
+
import { useCopyToClipboard } from "@/shared/hooks/useCopyToClipboard";
|
|
10
|
+
import { isOpenAICompatibleProvider, isAnthropicCompatibleProvider } from "@/shared/constants/providers";
|
|
11
|
+
|
|
12
|
+
// Validate combo name: only a-z, A-Z, 0-9, -, _
|
|
13
|
+
const VALID_NAME_REGEX = /^[a-zA-Z0-9_.\-]+$/;
|
|
14
|
+
const COMBOS_DEFAULT_PAGE_SIZE = 20;
|
|
15
|
+
|
|
16
|
+
export default function CombosPage() {
|
|
17
|
+
const [combos, setCombos] = useState([]);
|
|
18
|
+
const [loading, setLoading] = useState(true);
|
|
19
|
+
const [showCreateModal, setShowCreateModal] = useState(false);
|
|
20
|
+
const [editingCombo, setEditingCombo] = useState(null);
|
|
21
|
+
const [activeProviders, setActiveProviders] = useState([]);
|
|
22
|
+
const [comboStrategies, setComboStrategies] = useState({});
|
|
23
|
+
const [confirmState, setConfirmState] = useState(null);
|
|
24
|
+
const [page, setPage] = useState(1);
|
|
25
|
+
const [pageSize, setPageSize] = useState(COMBOS_DEFAULT_PAGE_SIZE);
|
|
26
|
+
const { copied, copy } = useCopyToClipboard();
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
fetchData();
|
|
30
|
+
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
31
|
+
|
|
32
|
+
const fetchData = async () => {
|
|
33
|
+
try {
|
|
34
|
+
const [combosRes, providersRes, settingsRes] = await Promise.all([
|
|
35
|
+
fetch("/api/combos"),
|
|
36
|
+
fetch("/api/providers"),
|
|
37
|
+
fetch("/api/settings"),
|
|
38
|
+
]);
|
|
39
|
+
const combosData = await combosRes.json();
|
|
40
|
+
const providersData = await providersRes.json();
|
|
41
|
+
const settingsData = settingsRes.ok ? await settingsRes.json() : {};
|
|
42
|
+
|
|
43
|
+
// Only LLM combos here — webSearch/webFetch combos belong to media-providers/web
|
|
44
|
+
if (combosRes.ok) setCombos((combosData.combos || []).filter(c => !c.kind));
|
|
45
|
+
if (providersRes.ok) {
|
|
46
|
+
setActiveProviders(providersData.connections || []);
|
|
47
|
+
}
|
|
48
|
+
setComboStrategies(settingsData.comboStrategies || {});
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.log("Error fetching data:", error);
|
|
51
|
+
} finally {
|
|
52
|
+
setLoading(false);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const handleCreate = async (data) => {
|
|
57
|
+
try {
|
|
58
|
+
const res = await fetch("/api/combos", {
|
|
59
|
+
method: "POST",
|
|
60
|
+
headers: { "Content-Type": "application/json" },
|
|
61
|
+
body: JSON.stringify(data),
|
|
62
|
+
});
|
|
63
|
+
if (res.ok) {
|
|
64
|
+
await fetchData();
|
|
65
|
+
setShowCreateModal(false);
|
|
66
|
+
} else {
|
|
67
|
+
const err = await res.json();
|
|
68
|
+
alert(err.error || "Failed to create combo");
|
|
69
|
+
}
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.log("Error creating combo:", error);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const handleUpdate = async (id, data) => {
|
|
76
|
+
try {
|
|
77
|
+
const res = await fetch(`/api/combos/${id}`, {
|
|
78
|
+
method: "PUT",
|
|
79
|
+
headers: { "Content-Type": "application/json" },
|
|
80
|
+
body: JSON.stringify(data),
|
|
81
|
+
});
|
|
82
|
+
if (res.ok) {
|
|
83
|
+
await fetchData();
|
|
84
|
+
setEditingCombo(null);
|
|
85
|
+
} else {
|
|
86
|
+
const err = await res.json();
|
|
87
|
+
alert(err.error || "Failed to update combo");
|
|
88
|
+
}
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.log("Error updating combo:", error);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const handleDelete = async (id) => {
|
|
95
|
+
setConfirmState({
|
|
96
|
+
title: "Delete Combo",
|
|
97
|
+
message: "Delete this combo?",
|
|
98
|
+
onConfirm: async () => {
|
|
99
|
+
setConfirmState(null);
|
|
100
|
+
try {
|
|
101
|
+
const res = await fetch(`/api/combos/${id}`, { method: "DELETE" });
|
|
102
|
+
if (res.ok) {
|
|
103
|
+
setCombos(combos.filter(c => c.id !== id));
|
|
104
|
+
}
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.log("Error deleting combo:", error);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const handleToggleRoundRobin = async (comboName, enabled) => {
|
|
113
|
+
try {
|
|
114
|
+
const updated = { ...comboStrategies };
|
|
115
|
+
if (enabled) {
|
|
116
|
+
updated[comboName] = { fallbackStrategy: "round-robin" };
|
|
117
|
+
} else {
|
|
118
|
+
delete updated[comboName];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
await fetch("/api/settings", {
|
|
122
|
+
method: "PATCH",
|
|
123
|
+
headers: { "Content-Type": "application/json" },
|
|
124
|
+
body: JSON.stringify({ comboStrategies: updated }),
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
setComboStrategies(updated);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
console.log("Error updating combo strategy:", error);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
useEffect(() => {
|
|
134
|
+
setPage((current) => Math.min(current, Math.max(1, Math.ceil(combos.length / pageSize))));
|
|
135
|
+
}, [combos.length, pageSize]);
|
|
136
|
+
|
|
137
|
+
const totalPages = Math.max(1, Math.ceil(combos.length / pageSize));
|
|
138
|
+
const activePage = Math.min(page, totalPages);
|
|
139
|
+
const paginatedCombos = combos.slice(
|
|
140
|
+
(activePage - 1) * pageSize,
|
|
141
|
+
activePage * pageSize
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
if (loading) {
|
|
145
|
+
return (
|
|
146
|
+
<div className="flex flex-col gap-6">
|
|
147
|
+
<CardSkeleton />
|
|
148
|
+
<CardSkeleton />
|
|
149
|
+
</div>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<div className="flex min-w-0 flex-col gap-6 px-1 sm:px-0">
|
|
155
|
+
{/* Header */}
|
|
156
|
+
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
|
157
|
+
<div className="min-w-0">
|
|
158
|
+
<h1 className="text-2xl font-semibold">Combos</h1>
|
|
159
|
+
<p className="text-sm text-text-muted mt-1">
|
|
160
|
+
Create model combos with fallback support
|
|
161
|
+
</p>
|
|
162
|
+
</div>
|
|
163
|
+
<Button icon="add" onClick={() => setShowCreateModal(true)} className="w-full sm:w-auto">
|
|
164
|
+
Create Combo
|
|
165
|
+
</Button>
|
|
166
|
+
</div>
|
|
167
|
+
|
|
168
|
+
{/* Combos List */}
|
|
169
|
+
{combos.length === 0 ? (
|
|
170
|
+
<Card>
|
|
171
|
+
<div className="text-center py-12">
|
|
172
|
+
<div className="inline-flex items-center justify-center w-16 h-16 rounded-full bg-primary/10 text-primary mb-4">
|
|
173
|
+
<span className="material-symbols-outlined text-[32px]">layers</span>
|
|
174
|
+
</div>
|
|
175
|
+
<p className="text-text-main font-medium mb-1">No combos yet</p>
|
|
176
|
+
<p className="text-sm text-text-muted mb-4">Create model combos with fallback support</p>
|
|
177
|
+
<Button icon="add" onClick={() => setShowCreateModal(true)} className="w-full sm:w-auto">
|
|
178
|
+
Create Combo
|
|
179
|
+
</Button>
|
|
180
|
+
</div>
|
|
181
|
+
</Card>
|
|
182
|
+
) : (
|
|
183
|
+
<div className="flex flex-col gap-4">
|
|
184
|
+
{paginatedCombos.map((combo) => (
|
|
185
|
+
<ComboCard
|
|
186
|
+
key={combo.id}
|
|
187
|
+
combo={combo}
|
|
188
|
+
copied={copied}
|
|
189
|
+
onCopy={copy}
|
|
190
|
+
onEdit={() => setEditingCombo(combo)}
|
|
191
|
+
onDelete={() => handleDelete(combo.id)}
|
|
192
|
+
roundRobinEnabled={comboStrategies[combo.name]?.fallbackStrategy === "round-robin"}
|
|
193
|
+
onToggleRoundRobin={(enabled) => handleToggleRoundRobin(combo.name, enabled)}
|
|
194
|
+
/>
|
|
195
|
+
))}
|
|
196
|
+
<Pagination
|
|
197
|
+
currentPage={activePage}
|
|
198
|
+
pageSize={pageSize}
|
|
199
|
+
totalItems={combos.length}
|
|
200
|
+
onPageChange={setPage}
|
|
201
|
+
onPageSizeChange={(size) => {
|
|
202
|
+
setPageSize(size);
|
|
203
|
+
setPage(1);
|
|
204
|
+
}}
|
|
205
|
+
/>
|
|
206
|
+
</div>
|
|
207
|
+
)}
|
|
208
|
+
|
|
209
|
+
{/* Create Modal - Use key to force remount and reset state */}
|
|
210
|
+
<ComboFormModal
|
|
211
|
+
key="create"
|
|
212
|
+
isOpen={showCreateModal}
|
|
213
|
+
onClose={() => setShowCreateModal(false)}
|
|
214
|
+
onSave={handleCreate}
|
|
215
|
+
activeProviders={activeProviders}
|
|
216
|
+
/>
|
|
217
|
+
|
|
218
|
+
{/* Edit Modal - Use key to force remount and reset state */}
|
|
219
|
+
<ComboFormModal
|
|
220
|
+
key={editingCombo?.id || "new"}
|
|
221
|
+
isOpen={!!editingCombo}
|
|
222
|
+
combo={editingCombo}
|
|
223
|
+
onClose={() => setEditingCombo(null)}
|
|
224
|
+
onSave={(data) => handleUpdate(editingCombo.id, data)}
|
|
225
|
+
activeProviders={activeProviders}
|
|
226
|
+
/>
|
|
227
|
+
|
|
228
|
+
{/* Confirm Delete Modal */}
|
|
229
|
+
<ConfirmModal
|
|
230
|
+
isOpen={!!confirmState}
|
|
231
|
+
onClose={() => setConfirmState(null)}
|
|
232
|
+
onConfirm={confirmState?.onConfirm}
|
|
233
|
+
title={confirmState?.title || "Confirm"}
|
|
234
|
+
message={confirmState?.message}
|
|
235
|
+
variant="danger"
|
|
236
|
+
/>
|
|
237
|
+
</div>
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function ComboCard({ combo, copied, onCopy, onEdit, onDelete, roundRobinEnabled, onToggleRoundRobin }) {
|
|
242
|
+
return (
|
|
243
|
+
<Card padding="sm" className="group">
|
|
244
|
+
<div className="flex min-w-0 flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
|
245
|
+
<div className="flex min-w-0 flex-1 items-start gap-3 sm:items-center">
|
|
246
|
+
<div className="size-8 rounded-lg bg-primary/10 flex items-center justify-center shrink-0">
|
|
247
|
+
<span className="material-symbols-outlined text-primary text-[18px]">layers</span>
|
|
248
|
+
</div>
|
|
249
|
+
<div className="min-w-0 flex-1">
|
|
250
|
+
<code className="block truncate font-mono text-sm font-medium">{combo.name}</code>
|
|
251
|
+
<div className="mt-1 flex min-w-0 flex-wrap items-center gap-1">
|
|
252
|
+
{combo.models.length === 0 ? (
|
|
253
|
+
<span className="text-xs text-text-muted italic">No models</span>
|
|
254
|
+
) : (
|
|
255
|
+
combo.models.slice(0, 3).map((model, index) => (
|
|
256
|
+
<code key={index} className="max-w-full truncate rounded bg-black/5 px-1.5 py-0.5 font-mono text-[10px] text-text-muted dark:bg-white/5 sm:max-w-[220px]">
|
|
257
|
+
{model}
|
|
258
|
+
</code>
|
|
259
|
+
))
|
|
260
|
+
)}
|
|
261
|
+
{combo.models.length > 3 && (
|
|
262
|
+
<span className="text-[10px] text-text-muted">+{combo.models.length - 3} more</span>
|
|
263
|
+
)}
|
|
264
|
+
</div>
|
|
265
|
+
</div>
|
|
266
|
+
</div>
|
|
267
|
+
|
|
268
|
+
{/* Actions */}
|
|
269
|
+
<div className="flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center sm:gap-3 sm:shrink-0">
|
|
270
|
+
{/* Round Robin Toggle — always visible */}
|
|
271
|
+
<div className="flex items-center justify-between gap-1.5 rounded-lg bg-black/[0.02] px-2 py-1.5 dark:bg-white/[0.02] sm:justify-start sm:bg-transparent sm:px-0 sm:py-0 sm:dark:bg-transparent">
|
|
272
|
+
<span className="text-xs text-text-muted font-medium">Round Robin</span>
|
|
273
|
+
<Toggle
|
|
274
|
+
size="sm"
|
|
275
|
+
checked={roundRobinEnabled}
|
|
276
|
+
onChange={onToggleRoundRobin}
|
|
277
|
+
/>
|
|
278
|
+
</div>
|
|
279
|
+
|
|
280
|
+
<div className="grid grid-cols-3 gap-1 sm:flex">
|
|
281
|
+
<button
|
|
282
|
+
onClick={(e) => { e.stopPropagation(); onCopy(combo.name, `combo-${combo.id}`); }}
|
|
283
|
+
className="flex flex-col items-center rounded px-2 py-1 text-text-muted transition-colors hover:bg-black/5 hover:text-primary dark:hover:bg-white/5"
|
|
284
|
+
title="Copy combo name"
|
|
285
|
+
>
|
|
286
|
+
<span className="material-symbols-outlined text-[18px]">
|
|
287
|
+
{copied === `combo-${combo.id}` ? "check" : "content_copy"}
|
|
288
|
+
</span>
|
|
289
|
+
<span className="text-[10px] leading-tight">Copy</span>
|
|
290
|
+
</button>
|
|
291
|
+
<button
|
|
292
|
+
onClick={onEdit}
|
|
293
|
+
className="flex flex-col items-center rounded px-2 py-1 text-text-muted transition-colors hover:bg-black/5 hover:text-primary dark:hover:bg-white/5"
|
|
294
|
+
title="Edit"
|
|
295
|
+
>
|
|
296
|
+
<span className="material-symbols-outlined text-[18px]">edit</span>
|
|
297
|
+
<span className="text-[10px] leading-tight">Edit</span>
|
|
298
|
+
</button>
|
|
299
|
+
<button
|
|
300
|
+
onClick={onDelete}
|
|
301
|
+
className="flex flex-col items-center rounded px-2 py-1 text-red-500 transition-colors hover:bg-red-500/10"
|
|
302
|
+
title="Delete"
|
|
303
|
+
>
|
|
304
|
+
<span className="material-symbols-outlined text-[18px]">delete</span>
|
|
305
|
+
<span className="text-[10px] leading-tight">Delete</span>
|
|
306
|
+
</button>
|
|
307
|
+
</div>
|
|
308
|
+
</div>
|
|
309
|
+
</div>
|
|
310
|
+
</Card>
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function ModelItem({ id, index, model, isFirst, isLast, onEdit, onMoveUp, onMoveDown, onRemove }) {
|
|
315
|
+
const { attributes, listeners, setNodeRef, transform, isDragging } = useSortable({ id });
|
|
316
|
+
const style = {
|
|
317
|
+
transform: CSS.Transform.toString(transform),
|
|
318
|
+
// no transition — prevents the CSS settle animation fighting React's re-render on drop
|
|
319
|
+
opacity: isDragging ? 0.4 : 1,
|
|
320
|
+
zIndex: isDragging ? 999 : undefined,
|
|
321
|
+
};
|
|
322
|
+
const [editing, setEditing] = useState(false);
|
|
323
|
+
const [draft, setDraft] = useState(model);
|
|
324
|
+
const commit = () => {
|
|
325
|
+
const trimmed = draft.trim();
|
|
326
|
+
if (trimmed && trimmed !== model) onEdit(trimmed);
|
|
327
|
+
else setDraft(model);
|
|
328
|
+
setEditing(false);
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
const handleKeyDown = (e) => {
|
|
332
|
+
if (e.key === "Enter") commit();
|
|
333
|
+
if (e.key === "Escape") { setDraft(model); setEditing(false); }
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
return (
|
|
337
|
+
<div
|
|
338
|
+
ref={setNodeRef}
|
|
339
|
+
style={style}
|
|
340
|
+
className={`group flex min-w-0 items-center gap-1.5 rounded-md px-2 py-1 bg-black/[0.02] hover:bg-black/[0.04] dark:bg-white/[0.02] dark:hover:bg-white/[0.04] transition-colors ${isDragging ? "shadow-md ring-1 ring-primary/30" : ""}`}
|
|
341
|
+
>
|
|
342
|
+
{/* Drag handle */}
|
|
343
|
+
<button
|
|
344
|
+
{...attributes}
|
|
345
|
+
{...listeners}
|
|
346
|
+
type="button"
|
|
347
|
+
className="cursor-grab touch-none p-0.5 rounded text-text-muted hover:text-primary active:cursor-grabbing shrink-0"
|
|
348
|
+
title="Drag to reorder"
|
|
349
|
+
>
|
|
350
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
|
|
351
|
+
<circle cx="9" cy="4" r="2"/><circle cx="15" cy="4" r="2"/>
|
|
352
|
+
<circle cx="9" cy="12" r="2"/><circle cx="15" cy="12" r="2"/>
|
|
353
|
+
<circle cx="9" cy="20" r="2"/><circle cx="15" cy="20" r="2"/>
|
|
354
|
+
</svg>
|
|
355
|
+
</button>
|
|
356
|
+
|
|
357
|
+
{/* Index badge */}
|
|
358
|
+
<span className="text-[10px] font-medium text-text-muted w-3 text-center shrink-0">{index + 1}</span>
|
|
359
|
+
|
|
360
|
+
{/* Inline editable model value */}
|
|
361
|
+
{editing ? (
|
|
362
|
+
<input
|
|
363
|
+
autoFocus
|
|
364
|
+
value={draft}
|
|
365
|
+
onChange={(e) => setDraft(e.target.value)}
|
|
366
|
+
onBlur={commit}
|
|
367
|
+
onKeyDown={handleKeyDown}
|
|
368
|
+
className="min-w-0 flex-1 rounded border border-primary/40 bg-white px-1.5 py-0.5 font-mono text-xs text-text-main outline-none dark:bg-black/20"
|
|
369
|
+
/>
|
|
370
|
+
) : (
|
|
371
|
+
<div
|
|
372
|
+
className="min-w-0 flex-1 cursor-text truncate rounded px-1.5 py-0.5 font-mono text-xs text-text-main hover:bg-black/5 dark:hover:bg-white/5"
|
|
373
|
+
onClick={() => setEditing(true)}
|
|
374
|
+
title="Click to edit"
|
|
375
|
+
>
|
|
376
|
+
{model}
|
|
377
|
+
</div>
|
|
378
|
+
)}
|
|
379
|
+
|
|
380
|
+
{/* Priority arrows */}
|
|
381
|
+
<div className="flex shrink-0 items-center gap-0.5">
|
|
382
|
+
<button
|
|
383
|
+
onClick={onMoveUp}
|
|
384
|
+
disabled={isFirst}
|
|
385
|
+
className={`p-0.5 rounded ${isFirst ? "text-text-muted/20 cursor-not-allowed" : "text-text-muted hover:text-primary hover:bg-black/5 dark:hover:bg-white/5"}`}
|
|
386
|
+
title="Move up"
|
|
387
|
+
>
|
|
388
|
+
<span className="material-symbols-outlined text-[12px]">arrow_upward</span>
|
|
389
|
+
</button>
|
|
390
|
+
<button
|
|
391
|
+
onClick={onMoveDown}
|
|
392
|
+
disabled={isLast}
|
|
393
|
+
className={`p-0.5 rounded ${isLast ? "text-text-muted/20 cursor-not-allowed" : "text-text-muted hover:text-primary hover:bg-black/5 dark:hover:bg-white/5"}`}
|
|
394
|
+
title="Move down"
|
|
395
|
+
>
|
|
396
|
+
<span className="material-symbols-outlined text-[12px]">arrow_downward</span>
|
|
397
|
+
</button>
|
|
398
|
+
</div>
|
|
399
|
+
|
|
400
|
+
{/* Remove */}
|
|
401
|
+
<button
|
|
402
|
+
onClick={onRemove}
|
|
403
|
+
className="p-0.5 hover:bg-red-500/10 rounded text-text-muted hover:text-red-500 transition-all"
|
|
404
|
+
title="Remove"
|
|
405
|
+
>
|
|
406
|
+
<span className="material-symbols-outlined text-[12px]">close</span>
|
|
407
|
+
</button>
|
|
408
|
+
</div>
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function ComboFormModal({ isOpen, combo, onClose, onSave, activeProviders, kindFilter = null }) {
|
|
413
|
+
// Initialize state with combo values - key prop on parent handles reset on remount
|
|
414
|
+
const [name, setName] = useState(combo?.name || "");
|
|
415
|
+
const [models, setModels] = useState(combo?.models || []);
|
|
416
|
+
const [showModelSelect, setShowModelSelect] = useState(false);
|
|
417
|
+
const [saving, setSaving] = useState(false);
|
|
418
|
+
const [nameError, setNameError] = useState("");
|
|
419
|
+
const [modelAliases, setModelAliases] = useState({});
|
|
420
|
+
|
|
421
|
+
const sensors = useSensors(
|
|
422
|
+
useSensor(PointerSensor, { activationConstraint: { distance: 5 } }),
|
|
423
|
+
useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates })
|
|
424
|
+
);
|
|
425
|
+
|
|
426
|
+
// Use stable index-based IDs so duplicates and similar names are handled correctly
|
|
427
|
+
const modelItems = models.map((model, i) => ({ uid: `item-${i}`, model }));
|
|
428
|
+
|
|
429
|
+
const handleDragEnd = (event) => {
|
|
430
|
+
const { active, over } = event;
|
|
431
|
+
if (over && active.id !== over.id) {
|
|
432
|
+
const oldIndex = modelItems.findIndex((m) => m.uid === active.id);
|
|
433
|
+
const newIndex = modelItems.findIndex((m) => m.uid === over.id);
|
|
434
|
+
if (oldIndex !== -1 && newIndex !== -1) {
|
|
435
|
+
setModels((prev) => arrayMove(prev, oldIndex, newIndex));
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
const fetchModalData = async () => {
|
|
441
|
+
try {
|
|
442
|
+
const aliasesRes = await fetch("/api/models/alias");
|
|
443
|
+
if (!aliasesRes.ok) return;
|
|
444
|
+
const aliasesData = await aliasesRes.json();
|
|
445
|
+
setModelAliases(aliasesData.aliases || {});
|
|
446
|
+
} catch (error) {
|
|
447
|
+
console.error("Error fetching modal data:", error);
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
useEffect(() => {
|
|
452
|
+
if (isOpen) fetchModalData();
|
|
453
|
+
}, [isOpen]);
|
|
454
|
+
|
|
455
|
+
const validateName = (value) => {
|
|
456
|
+
if (!value.trim()) {
|
|
457
|
+
setNameError("Name is required");
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
if (!VALID_NAME_REGEX.test(value)) {
|
|
461
|
+
setNameError("Only letters, numbers, -, _ and . allowed");
|
|
462
|
+
return false;
|
|
463
|
+
}
|
|
464
|
+
setNameError("");
|
|
465
|
+
return true;
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
const handleNameChange = (e) => {
|
|
469
|
+
const value = e.target.value;
|
|
470
|
+
setName(value);
|
|
471
|
+
if (value) validateName(value);
|
|
472
|
+
else setNameError("");
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
const handleAddModel = (model) => {
|
|
476
|
+
if (!models.includes(model.value)) {
|
|
477
|
+
setModels([...models, model.value]);
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
const handleDeselectModel = (model) => {
|
|
482
|
+
setModels(models.filter((m) => m !== model.value));
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
const handleRemoveModel = (index) => {
|
|
486
|
+
setModels(models.filter((_, i) => i !== index));
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
const handleMoveUp = (index) => {
|
|
490
|
+
if (index === 0) return;
|
|
491
|
+
const newModels = [...models];
|
|
492
|
+
[newModels[index - 1], newModels[index]] = [newModels[index], newModels[index - 1]];
|
|
493
|
+
setModels(newModels);
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
const handleMoveDown = (index) => {
|
|
497
|
+
if (index === models.length - 1) return;
|
|
498
|
+
const newModels = [...models];
|
|
499
|
+
[newModels[index], newModels[index + 1]] = [newModels[index + 1], newModels[index]];
|
|
500
|
+
setModels(newModels);
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
const handleSave = async () => {
|
|
504
|
+
if (!validateName(name)) return;
|
|
505
|
+
setSaving(true);
|
|
506
|
+
await onSave({ name: name.trim(), models });
|
|
507
|
+
setSaving(false);
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
const isEdit = !!combo;
|
|
511
|
+
|
|
512
|
+
return (
|
|
513
|
+
<>
|
|
514
|
+
<Modal
|
|
515
|
+
isOpen={isOpen}
|
|
516
|
+
onClose={onClose}
|
|
517
|
+
title={isEdit ? "Edit Combo" : "Create Combo"}
|
|
518
|
+
>
|
|
519
|
+
<div className="flex flex-col gap-3">
|
|
520
|
+
{/* Name */}
|
|
521
|
+
<div>
|
|
522
|
+
<Input
|
|
523
|
+
label="Combo Name"
|
|
524
|
+
value={name}
|
|
525
|
+
onChange={handleNameChange}
|
|
526
|
+
placeholder="my-combo"
|
|
527
|
+
error={nameError}
|
|
528
|
+
/>
|
|
529
|
+
<p className="text-[10px] text-text-muted mt-0.5">
|
|
530
|
+
Only letters, numbers, -, _ and . allowed
|
|
531
|
+
</p>
|
|
532
|
+
</div>
|
|
533
|
+
|
|
534
|
+
{/* Models */}
|
|
535
|
+
<div>
|
|
536
|
+
<label className="text-sm font-medium mb-1.5 block">Models</label>
|
|
537
|
+
|
|
538
|
+
{models.length === 0 ? (
|
|
539
|
+
<div className="text-center py-4 border border-dashed border-black/10 dark:border-white/10 rounded-lg bg-black/[0.01] dark:bg-white/[0.01]">
|
|
540
|
+
<span className="material-symbols-outlined text-text-muted text-xl mb-1">layers</span>
|
|
541
|
+
<p className="text-xs text-text-muted">No models added yet</p>
|
|
542
|
+
</div>
|
|
543
|
+
) : (
|
|
544
|
+
<DndContext sensors={sensors} collisionDetection={closestCenter} onDragEnd={handleDragEnd} modifiers={[restrictToVerticalAxis, restrictToParentElement]}>
|
|
545
|
+
<SortableContext items={modelItems.map((m) => m.uid)} strategy={verticalListSortingStrategy}>
|
|
546
|
+
<div className="flex max-h-[55vh] min-w-0 flex-col gap-1 overflow-y-auto sm:max-h-[350px]">
|
|
547
|
+
{modelItems.map(({ uid, model }, index) => (
|
|
548
|
+
<ModelItem
|
|
549
|
+
key={uid}
|
|
550
|
+
id={uid}
|
|
551
|
+
index={index}
|
|
552
|
+
model={model}
|
|
553
|
+
isFirst={index === 0}
|
|
554
|
+
isLast={index === modelItems.length - 1}
|
|
555
|
+
onEdit={(newVal) => {
|
|
556
|
+
const updated = [...models];
|
|
557
|
+
updated[index] = newVal;
|
|
558
|
+
setModels(updated);
|
|
559
|
+
}}
|
|
560
|
+
onMoveUp={() => handleMoveUp(index)}
|
|
561
|
+
onMoveDown={() => handleMoveDown(index)}
|
|
562
|
+
onRemove={() => handleRemoveModel(index)}
|
|
563
|
+
/>
|
|
564
|
+
))}
|
|
565
|
+
</div>
|
|
566
|
+
</SortableContext>
|
|
567
|
+
</DndContext>
|
|
568
|
+
)}
|
|
569
|
+
|
|
570
|
+
{/* Add Model button */}
|
|
571
|
+
<button
|
|
572
|
+
onClick={() => setShowModelSelect(true)}
|
|
573
|
+
className="w-full mt-2 py-2 border border-dashed border-black/10 dark:border-white/10 rounded-lg text-xs text-primary font-medium hover:text-primary hover:border-primary/50 transition-colors flex items-center justify-center gap-1"
|
|
574
|
+
>
|
|
575
|
+
<span className="material-symbols-outlined text-[16px]">add</span>
|
|
576
|
+
Add Model
|
|
577
|
+
</button>
|
|
578
|
+
</div>
|
|
579
|
+
|
|
580
|
+
{/* Actions */}
|
|
581
|
+
<div className="flex flex-col gap-2 pt-1 sm:flex-row">
|
|
582
|
+
<Button onClick={onClose} variant="ghost" fullWidth size="sm">
|
|
583
|
+
Cancel
|
|
584
|
+
</Button>
|
|
585
|
+
<Button
|
|
586
|
+
onClick={handleSave}
|
|
587
|
+
fullWidth
|
|
588
|
+
size="sm"
|
|
589
|
+
disabled={!name.trim() || !!nameError || saving}
|
|
590
|
+
>
|
|
591
|
+
{saving ? "Saving..." : isEdit ? "Save" : "Create"}
|
|
592
|
+
</Button>
|
|
593
|
+
</div>
|
|
594
|
+
</div>
|
|
595
|
+
</Modal>
|
|
596
|
+
|
|
597
|
+
{/* Model Select Modal */}
|
|
598
|
+
<ModelSelectModal
|
|
599
|
+
isOpen={showModelSelect}
|
|
600
|
+
onClose={() => setShowModelSelect(false)}
|
|
601
|
+
onSelect={handleAddModel}
|
|
602
|
+
onDeselect={handleDeselectModel}
|
|
603
|
+
activeProviders={activeProviders}
|
|
604
|
+
modelAliases={modelAliases}
|
|
605
|
+
title="Add Model to Combo"
|
|
606
|
+
kindFilter={kindFilter}
|
|
607
|
+
addedModelValues={models}
|
|
608
|
+
closeOnSelect={false}
|
|
609
|
+
/>
|
|
610
|
+
</>
|
|
611
|
+
);
|
|
612
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState, useEffect, useRef } from "react";
|
|
4
|
+
import { Card, Button } from "@/shared/components";
|
|
5
|
+
import { CONSOLE_LOG_CONFIG } from "@/shared/constants/config";
|
|
6
|
+
|
|
7
|
+
const LOG_LEVEL_COLORS = {
|
|
8
|
+
LOG: "text-green-400",
|
|
9
|
+
INFO: "text-blue-400",
|
|
10
|
+
WARN: "text-yellow-400",
|
|
11
|
+
ERROR: "text-red-400",
|
|
12
|
+
DEBUG: "text-purple-400",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function colorLine(line) {
|
|
16
|
+
const match = line.match(/\[(\w+)\]/g);
|
|
17
|
+
const levelTag = match ? match[1]?.replace(/\[|\]/g, "") : null;
|
|
18
|
+
const color = LOG_LEVEL_COLORS[levelTag] || "text-green-400";
|
|
19
|
+
return <span className={color}>{line}</span>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default function ConsoleLogClient() {
|
|
23
|
+
const [logs, setLogs] = useState([]);
|
|
24
|
+
const [connected, setConnected] = useState(false);
|
|
25
|
+
const logRef = useRef(null);
|
|
26
|
+
|
|
27
|
+
const handleClear = async () => {
|
|
28
|
+
try {
|
|
29
|
+
await fetch("/api/translator/console-logs", { method: "DELETE" });
|
|
30
|
+
// UI cleared via SSE "clear" event
|
|
31
|
+
} catch (err) {
|
|
32
|
+
console.error("Failed to clear console logs:", err);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const es = new EventSource("/api/translator/console-logs/stream");
|
|
38
|
+
|
|
39
|
+
es.onopen = () => setConnected(true);
|
|
40
|
+
|
|
41
|
+
es.onmessage = (e) => {
|
|
42
|
+
const msg = JSON.parse(e.data);
|
|
43
|
+
if (msg.type === "init") {
|
|
44
|
+
setLogs(msg.logs.slice(-CONSOLE_LOG_CONFIG.maxLines));
|
|
45
|
+
} else if (msg.type === "line") {
|
|
46
|
+
setLogs((prev) => {
|
|
47
|
+
const next = [...prev, msg.line];
|
|
48
|
+
return next.length > CONSOLE_LOG_CONFIG.maxLines ? next.slice(-CONSOLE_LOG_CONFIG.maxLines) : next;
|
|
49
|
+
});
|
|
50
|
+
} else if (msg.type === "clear") {
|
|
51
|
+
setLogs([]);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
es.onerror = () => setConnected(false);
|
|
56
|
+
|
|
57
|
+
return () => es.close();
|
|
58
|
+
}, []);
|
|
59
|
+
|
|
60
|
+
// Auto-scroll to bottom on new logs
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (!logRef.current) return;
|
|
63
|
+
logRef.current.scrollTop = logRef.current.scrollHeight;
|
|
64
|
+
}, [logs]);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<div className="">
|
|
68
|
+
<Card>
|
|
69
|
+
<div className="flex items-center justify-end px-4 pt-3 pb-2">
|
|
70
|
+
<Button size="sm" variant="outline" icon="delete" onClick={handleClear}>
|
|
71
|
+
Clear
|
|
72
|
+
</Button>
|
|
73
|
+
</div>
|
|
74
|
+
<div
|
|
75
|
+
ref={logRef}
|
|
76
|
+
className="bg-black rounded-b-lg p-4 text-xs font-mono h-[calc(100vh-220px)] overflow-y-auto"
|
|
77
|
+
>
|
|
78
|
+
{logs.length === 0 ? (
|
|
79
|
+
<span className="text-text-muted">No console logs yet.</span>
|
|
80
|
+
) : (
|
|
81
|
+
<div className="space-y-0.5">
|
|
82
|
+
{logs.map((line, i) => (
|
|
83
|
+
<div key={i}>{colorLine(line)}</div>
|
|
84
|
+
))}
|
|
85
|
+
</div>
|
|
86
|
+
)}
|
|
87
|
+
</div>
|
|
88
|
+
</Card>
|
|
89
|
+
</div>
|
|
90
|
+
);
|
|
91
|
+
}
|