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,967 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { Badge, Button } from "@/shared/components";
|
|
5
|
+
import { getModelsByProviderId } from "@/shared/constants/models";
|
|
6
|
+
import { isAnthropicCompatibleProvider, isOpenAICompatibleProvider } from "@/shared/constants/providers";
|
|
7
|
+
|
|
8
|
+
const STORAGE_KEYS = {
|
|
9
|
+
sessions: "basic-chat.sessions",
|
|
10
|
+
activeSessionId: "basic-chat.activeSessionId",
|
|
11
|
+
activeProviderId: "basic-chat.activeProviderId",
|
|
12
|
+
draft: "basic-chat.draft",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function createId() {
|
|
16
|
+
if (globalThis.crypto?.randomUUID) return globalThis.crypto.randomUUID();
|
|
17
|
+
return `chat_${Date.now()}_${Math.random().toString(16).slice(2)}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function safeParse(value, fallback) {
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(value);
|
|
23
|
+
} catch {
|
|
24
|
+
return fallback;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function textValue(value) {
|
|
29
|
+
if (typeof value === "string") return value;
|
|
30
|
+
if (value == null) return "";
|
|
31
|
+
if (Array.isArray(value)) return value.map(textValue).filter(Boolean).join(" ");
|
|
32
|
+
if (typeof value === "object") {
|
|
33
|
+
if (typeof value.message === "string") return value.message;
|
|
34
|
+
if (typeof value.error === "string") return value.error;
|
|
35
|
+
try {
|
|
36
|
+
return JSON.stringify(value);
|
|
37
|
+
} catch {
|
|
38
|
+
return String(value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return String(value);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function humanize(value = "") {
|
|
45
|
+
return String(value)
|
|
46
|
+
.replace(/[-_]/g, " ")
|
|
47
|
+
.replace(/\b\w/g, (char) => char.toUpperCase())
|
|
48
|
+
.trim() || "Unknown";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function formatRelativeTime(value) {
|
|
52
|
+
if (!value) return "Now";
|
|
53
|
+
const time = new Date(value).getTime();
|
|
54
|
+
if (Number.isNaN(time)) return "Now";
|
|
55
|
+
const diffMinutes = Math.max(1, Math.round((Date.now() - time) / 60000));
|
|
56
|
+
if (diffMinutes < 60) return `${diffMinutes}m`;
|
|
57
|
+
const diffHours = Math.round(diffMinutes / 60);
|
|
58
|
+
if (diffHours < 24) return `${diffHours}h`;
|
|
59
|
+
return `${Math.round(diffHours / 24)}d`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function makeSessionTitle(text = "") {
|
|
63
|
+
const normalized = textValue(text).replace(/\s+/g, " ").trim();
|
|
64
|
+
if (!normalized) return "New chat";
|
|
65
|
+
return normalized.length > 52 ? `${normalized.slice(0, 52).trimEnd()}…` : normalized;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function buildUserContent(message) {
|
|
69
|
+
const text = textValue(message.content).trim();
|
|
70
|
+
const attachments = Array.isArray(message.attachments) ? message.attachments : [];
|
|
71
|
+
|
|
72
|
+
if (attachments.length === 0) return text;
|
|
73
|
+
|
|
74
|
+
const content = [];
|
|
75
|
+
if (text) content.push({ type: "text", text });
|
|
76
|
+
|
|
77
|
+
for (const attachment of attachments) {
|
|
78
|
+
if (attachment?.dataUrl) {
|
|
79
|
+
content.push({ type: "image_url", image_url: { url: attachment.dataUrl } });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return content.length > 0 ? content : text;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function readAssistantText(chunk) {
|
|
87
|
+
if (!chunk || typeof chunk !== "object") return "";
|
|
88
|
+
const choice = chunk.choices?.[0];
|
|
89
|
+
const delta = choice?.delta || {};
|
|
90
|
+
const pieces = [delta.content, choice?.message?.content, chunk.output_text, chunk.text]
|
|
91
|
+
.map(textValue)
|
|
92
|
+
.filter(Boolean);
|
|
93
|
+
return pieces[0] || "";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function fileToDataUrl(file) {
|
|
97
|
+
return await new Promise((resolve, reject) => {
|
|
98
|
+
const reader = new FileReader();
|
|
99
|
+
reader.onload = () => resolve(String(reader.result || ""));
|
|
100
|
+
reader.onerror = () => reject(reader.error || new Error("Failed to read file"));
|
|
101
|
+
reader.readAsDataURL(file);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function cloneSession(session) {
|
|
106
|
+
return {
|
|
107
|
+
...session,
|
|
108
|
+
messages: Array.isArray(session.messages) ? session.messages.map((message) => ({ ...message })) : [],
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function getProviderLabel(connection) {
|
|
113
|
+
return connection?.name || humanize(connection?.provider || connection?.id || "provider");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function normalizeStaticModel(model, connection) {
|
|
117
|
+
if (!model?.id) return null;
|
|
118
|
+
return {
|
|
119
|
+
id: `${connection.provider}/${model.id}`,
|
|
120
|
+
requestModel: `${connection.provider}/${model.id}`,
|
|
121
|
+
name: model.name || model.id,
|
|
122
|
+
providerId: connection.provider,
|
|
123
|
+
providerName: getProviderLabel(connection),
|
|
124
|
+
source: "static",
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function normalizeLiveModel(model, connection) {
|
|
129
|
+
const rawId = typeof model === "string" ? model : model?.id || model?.name || model?.model || "";
|
|
130
|
+
if (!rawId) return null;
|
|
131
|
+
|
|
132
|
+
const displayName = typeof model === "string"
|
|
133
|
+
? model
|
|
134
|
+
: model?.name || model?.displayName || rawId;
|
|
135
|
+
|
|
136
|
+
let requestModel = rawId;
|
|
137
|
+
const isCompatible = isOpenAICompatibleProvider(connection.provider) || isAnthropicCompatibleProvider(connection.provider);
|
|
138
|
+
if (isCompatible && !rawId.includes("/")) {
|
|
139
|
+
requestModel = `${connection.provider}/${rawId}`;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
id: requestModel,
|
|
144
|
+
requestModel,
|
|
145
|
+
name: displayName,
|
|
146
|
+
providerId: connection.provider,
|
|
147
|
+
providerName: getProviderLabel(connection),
|
|
148
|
+
source: "live",
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function parseProviderModelsPayload(data) {
|
|
153
|
+
if (Array.isArray(data?.models)) return data.models;
|
|
154
|
+
if (Array.isArray(data?.data)) return data.data;
|
|
155
|
+
if (Array.isArray(data?.results)) return data.results;
|
|
156
|
+
if (Array.isArray(data)) return data;
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function dedupeModels(models) {
|
|
161
|
+
const map = new Map();
|
|
162
|
+
for (const model of models) {
|
|
163
|
+
if (!model?.id) continue;
|
|
164
|
+
if (!map.has(model.id)) map.set(model.id, model);
|
|
165
|
+
}
|
|
166
|
+
return Array.from(map.values());
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export default function BasicChatPageClient() {
|
|
170
|
+
const [providerGroups, setProviderGroups] = useState([]);
|
|
171
|
+
const [loadingData, setLoadingData] = useState(true);
|
|
172
|
+
const [loadError, setLoadError] = useState("");
|
|
173
|
+
const [sessions, setSessions] = useState(() => {
|
|
174
|
+
if (typeof window === "undefined") return [];
|
|
175
|
+
try {
|
|
176
|
+
const saved = safeParse(globalThis.localStorage.getItem(STORAGE_KEYS.sessions), []);
|
|
177
|
+
return Array.isArray(saved) ? saved.map((session) => ({
|
|
178
|
+
...session,
|
|
179
|
+
messages: Array.isArray(session.messages) ? session.messages : [],
|
|
180
|
+
})) : [];
|
|
181
|
+
} catch { return []; }
|
|
182
|
+
});
|
|
183
|
+
const [activeSessionId, setActiveSessionId] = useState(() => {
|
|
184
|
+
if (typeof window === "undefined") return "";
|
|
185
|
+
return globalThis.localStorage.getItem(STORAGE_KEYS.activeSessionId) || "";
|
|
186
|
+
});
|
|
187
|
+
const [activeProviderId, setActiveProviderId] = useState(() => {
|
|
188
|
+
if (typeof window === "undefined") return "";
|
|
189
|
+
return globalThis.localStorage.getItem(STORAGE_KEYS.activeProviderId) || "";
|
|
190
|
+
});
|
|
191
|
+
const [activeModelId, setActiveModelId] = useState("");
|
|
192
|
+
const [draft, setDraft] = useState(() => {
|
|
193
|
+
if (typeof window === "undefined") return "";
|
|
194
|
+
return globalThis.localStorage.getItem(STORAGE_KEYS.draft) || "";
|
|
195
|
+
});
|
|
196
|
+
const [attachments, setAttachments] = useState([]);
|
|
197
|
+
const [isSending, setIsSending] = useState(false);
|
|
198
|
+
const [streamingMessageId, setStreamingMessageId] = useState("");
|
|
199
|
+
const [streamingText, setStreamingText] = useState("");
|
|
200
|
+
const [isHydrated, setIsHydrated] = useState(false);
|
|
201
|
+
const [modelMenuOpen, setModelMenuOpen] = useState(false);
|
|
202
|
+
const [historyOpen, setHistoryOpen] = useState(false);
|
|
203
|
+
const fileInputRef = useRef(null);
|
|
204
|
+
const abortRef = useRef(null);
|
|
205
|
+
const initializedRef = useRef(false);
|
|
206
|
+
const modelMenuRef = useRef(null);
|
|
207
|
+
const historyMenuRef = useRef(null);
|
|
208
|
+
|
|
209
|
+
useEffect(() => {
|
|
210
|
+
setIsHydrated(true);
|
|
211
|
+
}, []);
|
|
212
|
+
|
|
213
|
+
useEffect(() => {
|
|
214
|
+
let cancelled = false;
|
|
215
|
+
|
|
216
|
+
async function loadData() {
|
|
217
|
+
setLoadingData(true);
|
|
218
|
+
setLoadError("");
|
|
219
|
+
|
|
220
|
+
try {
|
|
221
|
+
const providersRes = await fetch("/api/providers", { cache: "no-store" });
|
|
222
|
+
const providersData = await providersRes.json().catch(() => ({}));
|
|
223
|
+
const connections = Array.isArray(providersData.connections)
|
|
224
|
+
? providersData.connections.filter((connection) => connection?.isActive !== false)
|
|
225
|
+
: [];
|
|
226
|
+
|
|
227
|
+
if (connections.length === 0) {
|
|
228
|
+
if (!cancelled) {
|
|
229
|
+
setProviderGroups([]);
|
|
230
|
+
setLoadError("No providers connected yet.");
|
|
231
|
+
}
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const providerMap = new Map();
|
|
236
|
+
|
|
237
|
+
for (const connection of connections) {
|
|
238
|
+
const providerId = connection.provider || connection.id;
|
|
239
|
+
const providerName = getProviderLabel(connection);
|
|
240
|
+
const providerType = isOpenAICompatibleProvider(providerId)
|
|
241
|
+
? "openai-compatible"
|
|
242
|
+
: isAnthropicCompatibleProvider(providerId)
|
|
243
|
+
? "anthropic-compatible"
|
|
244
|
+
: providerId;
|
|
245
|
+
|
|
246
|
+
if (!providerMap.has(providerId)) {
|
|
247
|
+
providerMap.set(providerId, {
|
|
248
|
+
providerId,
|
|
249
|
+
providerName,
|
|
250
|
+
providerType,
|
|
251
|
+
connections: [],
|
|
252
|
+
models: [],
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const group = providerMap.get(providerId);
|
|
257
|
+
group.providerName = group.providerName || providerName;
|
|
258
|
+
group.providerType = group.providerType || providerType;
|
|
259
|
+
group.connections.push(connection);
|
|
260
|
+
|
|
261
|
+
const staticModels = getModelsByProviderId(providerId)
|
|
262
|
+
.map((model) => normalizeStaticModel(model, connection))
|
|
263
|
+
.filter(Boolean);
|
|
264
|
+
group.models.push(...staticModels);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const liveResults = await Promise.all(
|
|
268
|
+
connections.map(async (connection) => {
|
|
269
|
+
try {
|
|
270
|
+
const response = await fetch(`/api/providers/${connection.id}/models`, { cache: "no-store" });
|
|
271
|
+
const data = await response.json().catch(() => ({}));
|
|
272
|
+
if (!response.ok) return { connection, models: [] };
|
|
273
|
+
const models = parseProviderModelsPayload(data)
|
|
274
|
+
.map((model) => normalizeLiveModel(model, connection))
|
|
275
|
+
.filter(Boolean);
|
|
276
|
+
return { connection, models };
|
|
277
|
+
} catch {
|
|
278
|
+
return { connection, models: [] };
|
|
279
|
+
}
|
|
280
|
+
})
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
for (const result of liveResults) {
|
|
284
|
+
const providerId = result.connection.provider || result.connection.id;
|
|
285
|
+
const group = providerMap.get(providerId);
|
|
286
|
+
if (!group) continue;
|
|
287
|
+
group.models.push(...result.models);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const normalized = Array.from(providerMap.values())
|
|
291
|
+
.map((group) => ({
|
|
292
|
+
...group,
|
|
293
|
+
models: dedupeModels(group.models).sort((a, b) => a.name.localeCompare(b.name)),
|
|
294
|
+
}))
|
|
295
|
+
.filter((group) => group.models.length > 0)
|
|
296
|
+
.sort((a, b) => a.providerName.localeCompare(b.providerName));
|
|
297
|
+
|
|
298
|
+
if (!cancelled) {
|
|
299
|
+
setProviderGroups(normalized);
|
|
300
|
+
if (normalized.length === 0) {
|
|
301
|
+
setLoadError("Providers connected but no models available.");
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
} catch (error) {
|
|
305
|
+
if (!cancelled) {
|
|
306
|
+
setLoadError(textValue(error?.message) || "Failed to load providers/models.");
|
|
307
|
+
setProviderGroups([]);
|
|
308
|
+
}
|
|
309
|
+
} finally {
|
|
310
|
+
if (!cancelled) setLoadingData(false);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
loadData();
|
|
315
|
+
return () => {
|
|
316
|
+
cancelled = true;
|
|
317
|
+
};
|
|
318
|
+
}, []);
|
|
319
|
+
|
|
320
|
+
useEffect(() => {
|
|
321
|
+
const handleClickOutside = (event) => {
|
|
322
|
+
if (modelMenuRef.current && !modelMenuRef.current.contains(event.target)) {
|
|
323
|
+
setModelMenuOpen(false);
|
|
324
|
+
}
|
|
325
|
+
if (historyMenuRef.current && !historyMenuRef.current.contains(event.target)) {
|
|
326
|
+
setHistoryOpen(false);
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
331
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
332
|
+
}, []);
|
|
333
|
+
|
|
334
|
+
const modelIndex = useMemo(() => {
|
|
335
|
+
const map = new Map();
|
|
336
|
+
for (const group of providerGroups) {
|
|
337
|
+
for (const model of group.models) {
|
|
338
|
+
map.set(model.id, {
|
|
339
|
+
...model,
|
|
340
|
+
providerId: group.providerId,
|
|
341
|
+
providerName: group.providerName,
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return map;
|
|
346
|
+
}, [providerGroups]);
|
|
347
|
+
|
|
348
|
+
const activeProviderGroup = useMemo(() => {
|
|
349
|
+
return providerGroups.find((group) => group.providerId === activeProviderId) || providerGroups[0] || null;
|
|
350
|
+
}, [providerGroups, activeProviderId]);
|
|
351
|
+
|
|
352
|
+
const activeModel = useMemo(() => {
|
|
353
|
+
if (activeModelId && modelIndex.has(activeModelId)) return modelIndex.get(activeModelId);
|
|
354
|
+
if (activeSessionId) {
|
|
355
|
+
const session = sessions.find((item) => item.id === activeSessionId);
|
|
356
|
+
if (session?.modelId && modelIndex.has(session.modelId)) return modelIndex.get(session.modelId);
|
|
357
|
+
}
|
|
358
|
+
return activeProviderGroup?.models?.[0] || null;
|
|
359
|
+
}, [activeModelId, modelIndex, activeProviderGroup, sessions, activeSessionId]);
|
|
360
|
+
|
|
361
|
+
const currentSession = useMemo(() => sessions.find((session) => session.id === activeSessionId) || null, [sessions, activeSessionId]);
|
|
362
|
+
const currentMessages = currentSession?.messages || [];
|
|
363
|
+
const sessionItems = useMemo(() => [...sessions].sort((a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()), [sessions]);
|
|
364
|
+
const canSend = !isSending && !!activeModel && (draft.trim().length > 0 || attachments.length > 0);
|
|
365
|
+
|
|
366
|
+
useEffect(() => {
|
|
367
|
+
if (!isHydrated) return;
|
|
368
|
+
try {
|
|
369
|
+
globalThis.localStorage.setItem(STORAGE_KEYS.sessions, JSON.stringify(sessions));
|
|
370
|
+
globalThis.localStorage.setItem(STORAGE_KEYS.activeSessionId, activeSessionId);
|
|
371
|
+
globalThis.localStorage.setItem(STORAGE_KEYS.activeProviderId, activeProviderId);
|
|
372
|
+
globalThis.localStorage.setItem(STORAGE_KEYS.draft, draft);
|
|
373
|
+
} catch {
|
|
374
|
+
// Ignore storage errors.
|
|
375
|
+
}
|
|
376
|
+
}, [isHydrated, sessions, activeSessionId, activeProviderId, draft]);
|
|
377
|
+
|
|
378
|
+
useEffect(() => {
|
|
379
|
+
if (!isHydrated || loadingData || initializedRef.current) return;
|
|
380
|
+
if (providerGroups.length === 0) return;
|
|
381
|
+
|
|
382
|
+
const savedProvider = providerGroups.find((group) => group.providerId === activeProviderId) || providerGroups[0];
|
|
383
|
+
const savedModel = activeModelId && modelIndex.has(activeModelId)
|
|
384
|
+
? modelIndex.get(activeModelId)
|
|
385
|
+
: savedProvider.models[0];
|
|
386
|
+
|
|
387
|
+
if (sessions.length > 0) {
|
|
388
|
+
const session = sessions.find((item) => item.id === activeSessionId) || sessions[0];
|
|
389
|
+
const sessionModel = session?.modelId && modelIndex.has(session.modelId)
|
|
390
|
+
? modelIndex.get(session.modelId)
|
|
391
|
+
: savedModel;
|
|
392
|
+
initializedRef.current = true;
|
|
393
|
+
setActiveSessionId(session.id);
|
|
394
|
+
setActiveProviderId(sessionModel?.providerId || savedProvider.providerId);
|
|
395
|
+
setActiveModelId(sessionModel?.id || savedModel.id);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const session = {
|
|
400
|
+
id: createId(),
|
|
401
|
+
title: "New chat",
|
|
402
|
+
providerId: savedProvider.providerId,
|
|
403
|
+
providerName: savedProvider.providerName,
|
|
404
|
+
modelId: savedModel.id,
|
|
405
|
+
modelName: savedModel.name,
|
|
406
|
+
createdAt: new Date().toISOString(),
|
|
407
|
+
updatedAt: new Date().toISOString(),
|
|
408
|
+
messages: [],
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
initializedRef.current = true;
|
|
412
|
+
setSessions([session]);
|
|
413
|
+
setActiveSessionId(session.id);
|
|
414
|
+
setActiveProviderId(savedProvider.providerId);
|
|
415
|
+
setActiveModelId(savedModel.id);
|
|
416
|
+
}, [isHydrated, loadingData, providerGroups, modelIndex, sessions, activeSessionId, activeProviderId, activeModelId]);
|
|
417
|
+
|
|
418
|
+
const updateSession = (sessionId, updater) => {
|
|
419
|
+
setSessions((prev) => prev.map((session) => (session.id === sessionId ? updater(cloneSession(session)) : session)));
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
const ensureSessionForModel = (model) => {
|
|
423
|
+
if (!model) return null;
|
|
424
|
+
return {
|
|
425
|
+
id: createId(),
|
|
426
|
+
title: "New chat",
|
|
427
|
+
providerId: model.providerId,
|
|
428
|
+
providerName: model.providerName,
|
|
429
|
+
modelId: model.id,
|
|
430
|
+
modelName: model.name,
|
|
431
|
+
createdAt: new Date().toISOString(),
|
|
432
|
+
updatedAt: new Date().toISOString(),
|
|
433
|
+
messages: [],
|
|
434
|
+
};
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
const handleNewChat = () => {
|
|
438
|
+
if (!activeModel) return;
|
|
439
|
+
const session = ensureSessionForModel(activeModel);
|
|
440
|
+
if (!session) return;
|
|
441
|
+
setSessions((prev) => [session, ...prev]);
|
|
442
|
+
setActiveSessionId(session.id);
|
|
443
|
+
setActiveProviderId(session.providerId);
|
|
444
|
+
setActiveModelId(session.modelId);
|
|
445
|
+
setDraft("");
|
|
446
|
+
setAttachments([]);
|
|
447
|
+
setStreamingMessageId("");
|
|
448
|
+
setStreamingText("");
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
const handleSelectSession = (sessionId) => {
|
|
452
|
+
const session = sessions.find((item) => item.id === sessionId);
|
|
453
|
+
if (!session) return;
|
|
454
|
+
setActiveSessionId(sessionId);
|
|
455
|
+
setActiveProviderId(session.providerId || activeProviderId);
|
|
456
|
+
setActiveModelId(session.modelId || activeModelId);
|
|
457
|
+
setHistoryOpen(false);
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
const handleDeleteCurrentChat = () => {
|
|
461
|
+
if (!activeSessionId) return;
|
|
462
|
+
const nextSessions = sessions.filter((session) => session.id !== activeSessionId);
|
|
463
|
+
const fallback = nextSessions[0] || null;
|
|
464
|
+
setSessions(nextSessions);
|
|
465
|
+
if (fallback) {
|
|
466
|
+
setActiveSessionId(fallback.id);
|
|
467
|
+
setActiveProviderId(fallback.providerId);
|
|
468
|
+
setActiveModelId(fallback.modelId);
|
|
469
|
+
} else {
|
|
470
|
+
setActiveSessionId("");
|
|
471
|
+
setActiveProviderId("");
|
|
472
|
+
setActiveModelId("");
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
const handleSelectProvider = (providerId) => {
|
|
477
|
+
const group = providerGroups.find((item) => item.providerId === providerId);
|
|
478
|
+
if (!group || group.models.length === 0) return;
|
|
479
|
+
const nextModel = group.models[0];
|
|
480
|
+
|
|
481
|
+
const current = sessions.find((session) => session.id === activeSessionId);
|
|
482
|
+
if (current && current.messages.length > 0) {
|
|
483
|
+
const session = ensureSessionForModel(nextModel);
|
|
484
|
+
if (!session) return;
|
|
485
|
+
setSessions((prev) => [session, ...prev]);
|
|
486
|
+
setActiveSessionId(session.id);
|
|
487
|
+
} else if (current) {
|
|
488
|
+
setSessions((prev) => prev.map((item) => (item.id === current.id ? {
|
|
489
|
+
...item,
|
|
490
|
+
providerId: group.providerId,
|
|
491
|
+
providerName: group.providerName,
|
|
492
|
+
modelId: nextModel.id,
|
|
493
|
+
modelName: nextModel.name,
|
|
494
|
+
} : item)));
|
|
495
|
+
setActiveSessionId(current.id);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
setActiveProviderId(group.providerId);
|
|
499
|
+
setActiveModelId(nextModel.id);
|
|
500
|
+
setModelMenuOpen(false);
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
const handleSelectModel = (modelId) => {
|
|
504
|
+
const model = modelIndex.get(modelId);
|
|
505
|
+
if (!model) return;
|
|
506
|
+
|
|
507
|
+
const current = sessions.find((session) => session.id === activeSessionId);
|
|
508
|
+
if (current && current.messages.length > 0) {
|
|
509
|
+
const session = ensureSessionForModel(model);
|
|
510
|
+
if (!session) return;
|
|
511
|
+
setSessions((prev) => [session, ...prev]);
|
|
512
|
+
setActiveSessionId(session.id);
|
|
513
|
+
} else if (current) {
|
|
514
|
+
setSessions((prev) => prev.map((item) => (item.id === current.id ? {
|
|
515
|
+
...item,
|
|
516
|
+
providerId: model.providerId,
|
|
517
|
+
providerName: model.providerName,
|
|
518
|
+
modelId: model.id,
|
|
519
|
+
modelName: model.name,
|
|
520
|
+
} : item)));
|
|
521
|
+
setActiveSessionId(current.id);
|
|
522
|
+
} else {
|
|
523
|
+
const session = ensureSessionForModel(model);
|
|
524
|
+
if (!session) return;
|
|
525
|
+
setSessions((prev) => [session, ...prev]);
|
|
526
|
+
setActiveSessionId(session.id);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
setActiveProviderId(model.providerId);
|
|
530
|
+
setActiveModelId(model.id);
|
|
531
|
+
setModelMenuOpen(false);
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
const handleAttachFiles = async (event) => {
|
|
535
|
+
const files = Array.from(event.target.files || []);
|
|
536
|
+
if (files.length === 0) return;
|
|
537
|
+
|
|
538
|
+
const images = files.filter((file) => file.type.startsWith("image/"));
|
|
539
|
+
if (images.length === 0) {
|
|
540
|
+
event.target.value = "";
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
const converted = await Promise.all(images.map(async (file) => ({
|
|
545
|
+
id: createId(),
|
|
546
|
+
name: file.name,
|
|
547
|
+
type: file.type,
|
|
548
|
+
size: file.size,
|
|
549
|
+
dataUrl: await fileToDataUrl(file),
|
|
550
|
+
})));
|
|
551
|
+
|
|
552
|
+
setAttachments((prev) => [...prev, ...converted]);
|
|
553
|
+
event.target.value = "";
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
const removeAttachment = (attachmentId) => {
|
|
557
|
+
setAttachments((prev) => prev.filter((attachment) => attachment.id !== attachmentId));
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
const handleStop = () => {
|
|
561
|
+
abortRef.current?.abort();
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
const finalizeSessionTitle = (sessionId, titleSeed) => {
|
|
565
|
+
const title = makeSessionTitle(titleSeed);
|
|
566
|
+
updateSession(sessionId, (session) => ({
|
|
567
|
+
...session,
|
|
568
|
+
title: session.title === "New chat" ? title : session.title,
|
|
569
|
+
updatedAt: new Date().toISOString(),
|
|
570
|
+
}));
|
|
571
|
+
};
|
|
572
|
+
|
|
573
|
+
const sendMessage = async () => {
|
|
574
|
+
const model = activeModel || activeProviderGroup?.models?.[0] || null;
|
|
575
|
+
if (!model) return;
|
|
576
|
+
|
|
577
|
+
const userText = draft.trim();
|
|
578
|
+
if (!userText && attachments.length === 0) return;
|
|
579
|
+
|
|
580
|
+
let sessionId = activeSessionId;
|
|
581
|
+
let session = sessions.find((item) => item.id === sessionId);
|
|
582
|
+
if (!session) {
|
|
583
|
+
session = ensureSessionForModel(model);
|
|
584
|
+
if (!session) return;
|
|
585
|
+
sessionId = session.id;
|
|
586
|
+
setSessions((prev) => [session, ...prev]);
|
|
587
|
+
setActiveSessionId(sessionId);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
const userMessage = {
|
|
591
|
+
id: createId(),
|
|
592
|
+
role: "user",
|
|
593
|
+
content: userText,
|
|
594
|
+
attachments: attachments.map((attachment) => ({
|
|
595
|
+
id: attachment.id,
|
|
596
|
+
name: attachment.name,
|
|
597
|
+
type: attachment.type,
|
|
598
|
+
dataUrl: attachment.dataUrl,
|
|
599
|
+
})),
|
|
600
|
+
createdAt: new Date().toISOString(),
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
const assistantMessageId = createId();
|
|
604
|
+
const assistantMessage = {
|
|
605
|
+
id: assistantMessageId,
|
|
606
|
+
role: "assistant",
|
|
607
|
+
content: "",
|
|
608
|
+
createdAt: new Date().toISOString(),
|
|
609
|
+
status: "streaming",
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
const nextMessages = [...(session.messages || []), userMessage, assistantMessage];
|
|
613
|
+
setSessions((prev) => prev.map((item) => (item.id === sessionId ? {
|
|
614
|
+
...item,
|
|
615
|
+
providerId: model.providerId,
|
|
616
|
+
providerName: model.providerName,
|
|
617
|
+
modelId: model.id,
|
|
618
|
+
modelName: model.name,
|
|
619
|
+
messages: nextMessages,
|
|
620
|
+
updatedAt: new Date().toISOString(),
|
|
621
|
+
title: item.title === "New chat" ? makeSessionTitle(userText) : item.title,
|
|
622
|
+
} : item)));
|
|
623
|
+
setDraft("");
|
|
624
|
+
setAttachments([]);
|
|
625
|
+
setIsSending(true);
|
|
626
|
+
setStreamingMessageId(assistantMessageId);
|
|
627
|
+
setStreamingText("");
|
|
628
|
+
abortRef.current?.abort();
|
|
629
|
+
abortRef.current = new AbortController();
|
|
630
|
+
|
|
631
|
+
const requestMessages = nextMessages
|
|
632
|
+
.filter((message) => !(message.role === "assistant" && message.id === assistantMessageId))
|
|
633
|
+
.map((message) => ({
|
|
634
|
+
role: message.role,
|
|
635
|
+
content: message.role === "user" ? buildUserContent(message) : message.content,
|
|
636
|
+
}));
|
|
637
|
+
|
|
638
|
+
try {
|
|
639
|
+
const response = await fetch("/api/dashboard/chat/completions", {
|
|
640
|
+
method: "POST",
|
|
641
|
+
headers: {
|
|
642
|
+
"Content-Type": "application/json",
|
|
643
|
+
Accept: "text/event-stream",
|
|
644
|
+
},
|
|
645
|
+
body: JSON.stringify({
|
|
646
|
+
model: model.requestModel || model.id,
|
|
647
|
+
messages: requestMessages,
|
|
648
|
+
stream: true,
|
|
649
|
+
}),
|
|
650
|
+
signal: abortRef.current.signal,
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
if (!response.ok) {
|
|
654
|
+
const errorData = await response.json().catch(() => ({}));
|
|
655
|
+
throw new Error(textValue(errorData.error || errorData.message || `Request failed (${response.status})`));
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
const reader = response.body?.getReader();
|
|
659
|
+
if (!reader) {
|
|
660
|
+
const data = await response.json().catch(() => ({}));
|
|
661
|
+
const fallbackText = textValue(data?.choices?.[0]?.message?.content || data?.output_text || data?.error || data?.message || "");
|
|
662
|
+
updateSession(sessionId, (currentSession) => ({
|
|
663
|
+
...currentSession,
|
|
664
|
+
messages: currentSession.messages.map((message) => (message.id === assistantMessageId ? { ...message, content: fallbackText, status: "done" } : message)),
|
|
665
|
+
updatedAt: new Date().toISOString(),
|
|
666
|
+
}));
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
const decoder = new TextDecoder();
|
|
671
|
+
let buffer = "";
|
|
672
|
+
let assistantText = "";
|
|
673
|
+
|
|
674
|
+
while (true) {
|
|
675
|
+
const { value, done } = await reader.read();
|
|
676
|
+
if (done) break;
|
|
677
|
+
|
|
678
|
+
buffer += decoder.decode(value, { stream: true });
|
|
679
|
+
const lines = buffer.split(/\r?\n/);
|
|
680
|
+
buffer = lines.pop() || "";
|
|
681
|
+
|
|
682
|
+
for (const line of lines) {
|
|
683
|
+
const trimmed = line.trim();
|
|
684
|
+
if (!trimmed.startsWith("data:")) continue;
|
|
685
|
+
|
|
686
|
+
const payload = trimmed.slice(5).trim();
|
|
687
|
+
if (!payload || payload === "[DONE]") continue;
|
|
688
|
+
|
|
689
|
+
try {
|
|
690
|
+
const chunk = JSON.parse(payload);
|
|
691
|
+
const text = readAssistantText(chunk);
|
|
692
|
+
if (!text) continue;
|
|
693
|
+
|
|
694
|
+
assistantText += text;
|
|
695
|
+
setStreamingText(assistantText);
|
|
696
|
+
updateSession(sessionId, (currentSession) => ({
|
|
697
|
+
...currentSession,
|
|
698
|
+
messages: currentSession.messages.map((message) => (message.id === assistantMessageId ? { ...message, content: assistantText, status: "streaming" } : message)),
|
|
699
|
+
updatedAt: new Date().toISOString(),
|
|
700
|
+
}));
|
|
701
|
+
} catch {
|
|
702
|
+
// Ignore malformed chunks.
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
updateSession(sessionId, (currentSession) => ({
|
|
708
|
+
...currentSession,
|
|
709
|
+
messages: currentSession.messages.map((message) => (message.id === assistantMessageId ? { ...message, content: assistantText || message.content, status: "done" } : message)),
|
|
710
|
+
updatedAt: new Date().toISOString(),
|
|
711
|
+
}));
|
|
712
|
+
finalizeSessionTitle(sessionId, userText);
|
|
713
|
+
} catch (error) {
|
|
714
|
+
if (error.name !== "AbortError") {
|
|
715
|
+
const errorText = textValue(error?.message || error);
|
|
716
|
+
updateSession(sessionId, (currentSession) => ({
|
|
717
|
+
...currentSession,
|
|
718
|
+
messages: currentSession.messages.map((message) => (message.id === assistantMessageId ? { ...message, content: message.content || `Error: ${errorText}`, status: "error" } : message)),
|
|
719
|
+
updatedAt: new Date().toISOString(),
|
|
720
|
+
}));
|
|
721
|
+
setLoadError(errorText || "Failed to send message.");
|
|
722
|
+
}
|
|
723
|
+
} finally {
|
|
724
|
+
setIsSending(false);
|
|
725
|
+
setStreamingMessageId("");
|
|
726
|
+
setStreamingText("");
|
|
727
|
+
abortRef.current = null;
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
const handleKeyDown = (event) => {
|
|
732
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
733
|
+
event.preventDefault();
|
|
734
|
+
if (canSend) sendMessage();
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
const modelLabel = activeModel ? `${activeModel.name}` : "Select model";
|
|
739
|
+
const modelSubLabel = activeModel ? activeModel.requestModel : "Choose from connected providers";
|
|
740
|
+
|
|
741
|
+
return (
|
|
742
|
+
<div className="relative flex-1 flex flex-col h-full min-h-0 min-w-0 bg-[#212121] text-white overflow-hidden">
|
|
743
|
+
<div className="relative mx-auto flex flex-1 h-full min-h-0 w-full max-w-4xl flex-col">
|
|
744
|
+
<div className="flex shrink-0 items-center justify-between gap-3 px-4 py-3 lg:px-6">
|
|
745
|
+
<div ref={modelMenuRef} className="relative">
|
|
746
|
+
<button
|
|
747
|
+
type="button"
|
|
748
|
+
onClick={() => setModelMenuOpen((value) => !value)}
|
|
749
|
+
className="flex items-center gap-3 rounded-2xl border border-white/10 bg-white/5 px-4 py-3 text-left transition hover:bg-white/8"
|
|
750
|
+
>
|
|
751
|
+
<div className="min-w-0">
|
|
752
|
+
<div className="flex items-center gap-2">
|
|
753
|
+
<span className="text-sm font-semibold text-white">{modelLabel}</span>
|
|
754
|
+
<span className="material-symbols-outlined text-[18px] text-white/70">expand_more</span>
|
|
755
|
+
</div>
|
|
756
|
+
<p className="truncate text-xs text-white/55">{modelSubLabel}</p>
|
|
757
|
+
</div>
|
|
758
|
+
</button>
|
|
759
|
+
|
|
760
|
+
{modelMenuOpen ? (
|
|
761
|
+
<div className="absolute left-0 top-[calc(100%+10px)] z-30 w-[min(520px,calc(100vw-2rem))] overflow-hidden rounded-[20px] border border-white/10 bg-[#262626] shadow-2xl shadow-black/50">
|
|
762
|
+
<div className="border-b border-white/10 px-4 py-3">
|
|
763
|
+
<p className="text-xs uppercase tracking-[0.22em] text-white/45">Models</p>
|
|
764
|
+
<p className="text-sm text-white/75">Only from connected providers</p>
|
|
765
|
+
</div>
|
|
766
|
+
<div className="max-h-[60vh] overflow-y-auto p-2 custom-scrollbar">
|
|
767
|
+
{providerGroups.map((group) => (
|
|
768
|
+
<div key={group.providerId} className="mb-2 rounded-[16px] border border-white/10 bg-black/20 p-2">
|
|
769
|
+
<div className="flex items-center justify-between px-2 py-2">
|
|
770
|
+
<p className="text-sm font-semibold text-white">{group.providerName}</p>
|
|
771
|
+
<Badge size="sm" variant="default">{group.models.length}</Badge>
|
|
772
|
+
</div>
|
|
773
|
+
<div className="grid gap-2 sm:grid-cols-2">
|
|
774
|
+
{group.models.map((model) => {
|
|
775
|
+
const isActive = model.id === activeModelId;
|
|
776
|
+
return (
|
|
777
|
+
<button
|
|
778
|
+
key={model.id}
|
|
779
|
+
type="button"
|
|
780
|
+
onClick={() => handleSelectModel(model.id)}
|
|
781
|
+
className={`rounded-[14px] border px-3 py-3 text-left transition ${isActive ? "border-blue-400/40 bg-blue-500/15" : "border-white/10 bg-white/5 hover:bg-white/8"}`}
|
|
782
|
+
>
|
|
783
|
+
<div className="flex items-start justify-between gap-3">
|
|
784
|
+
<div className="min-w-0">
|
|
785
|
+
<p className="truncate text-sm font-medium text-white">{model.name}</p>
|
|
786
|
+
<p className="truncate text-[11px] text-white/45">{model.requestModel}</p>
|
|
787
|
+
</div>
|
|
788
|
+
{isActive ? <span className="material-symbols-outlined text-[18px] text-blue-300">check_circle</span> : null}
|
|
789
|
+
</div>
|
|
790
|
+
</button>
|
|
791
|
+
);
|
|
792
|
+
})}
|
|
793
|
+
</div>
|
|
794
|
+
</div>
|
|
795
|
+
))}
|
|
796
|
+
</div>
|
|
797
|
+
</div>
|
|
798
|
+
) : null}
|
|
799
|
+
</div>
|
|
800
|
+
|
|
801
|
+
<div className="flex items-center gap-2">
|
|
802
|
+
<button
|
|
803
|
+
type="button"
|
|
804
|
+
onClick={() => setHistoryOpen((value) => !value)}
|
|
805
|
+
className="rounded-2xl border border-white/10 bg-white/5 px-4 py-3 text-sm text-white/80 transition hover:bg-white/8"
|
|
806
|
+
>
|
|
807
|
+
History
|
|
808
|
+
</button>
|
|
809
|
+
<Button variant="ghost" size="sm" icon="delete" onClick={handleDeleteCurrentChat} disabled={!activeSessionId || sessions.length === 0}>
|
|
810
|
+
Clear
|
|
811
|
+
</Button>
|
|
812
|
+
</div>
|
|
813
|
+
</div>
|
|
814
|
+
|
|
815
|
+
{historyOpen ? (
|
|
816
|
+
<div ref={historyMenuRef} className="absolute right-4 top-[72px] z-20 w-[min(360px,calc(100vw-2rem))] rounded-[20px] border border-white/10 bg-[#262626] p-2 shadow-2xl shadow-black/50 lg:right-6">
|
|
817
|
+
<div className="px-3 py-2">
|
|
818
|
+
<p className="text-xs uppercase tracking-[0.22em] text-white/45">Recent chats</p>
|
|
819
|
+
</div>
|
|
820
|
+
<div className="max-h-[48vh] space-y-2 overflow-y-auto p-1 custom-scrollbar">
|
|
821
|
+
{sessionItems.length === 0 ? (
|
|
822
|
+
<div className="rounded-[16px] border border-dashed border-white/10 bg-white/5 p-4 text-sm text-white/55">
|
|
823
|
+
No conversations yet.
|
|
824
|
+
</div>
|
|
825
|
+
) : sessionItems.map((session) => {
|
|
826
|
+
const isActive = session.id === activeSessionId;
|
|
827
|
+
const latestMessage = [...(session.messages || [])].reverse().find((message) => message.role === "user") || session.messages?.[0];
|
|
828
|
+
return (
|
|
829
|
+
<button
|
|
830
|
+
key={session.id}
|
|
831
|
+
type="button"
|
|
832
|
+
onClick={() => handleSelectSession(session.id)}
|
|
833
|
+
className={`w-full rounded-[16px] border px-3 py-3 text-left transition ${isActive ? "border-blue-400/40 bg-blue-500/15" : "border-white/10 bg-white/5 hover:bg-white/8"}`}
|
|
834
|
+
>
|
|
835
|
+
<div className="flex items-start justify-between gap-3">
|
|
836
|
+
<div className="min-w-0 flex-1">
|
|
837
|
+
<p className="truncate text-sm font-medium text-white">{session.title}</p>
|
|
838
|
+
<p className="mt-1 truncate text-xs text-white/50">{textValue(latestMessage?.content) || "Empty chat"}</p>
|
|
839
|
+
</div>
|
|
840
|
+
<span className="text-[10px] text-white/40 shrink-0">{formatRelativeTime(session.updatedAt)}</span>
|
|
841
|
+
</div>
|
|
842
|
+
</button>
|
|
843
|
+
);
|
|
844
|
+
})}
|
|
845
|
+
</div>
|
|
846
|
+
</div>
|
|
847
|
+
) : null}
|
|
848
|
+
|
|
849
|
+
{loadError ? (
|
|
850
|
+
<div className="mt-4 rounded-[18px] border border-rose-500/20 bg-rose-500/10 px-4 py-3 text-rose-100">
|
|
851
|
+
<div className="flex items-start gap-3">
|
|
852
|
+
<span className="material-symbols-outlined text-[20px]">error</span>
|
|
853
|
+
<p className="text-sm leading-6">{loadError}</p>
|
|
854
|
+
</div>
|
|
855
|
+
</div>
|
|
856
|
+
) : null}
|
|
857
|
+
|
|
858
|
+
<div className="flex flex-1 flex-col min-h-0">
|
|
859
|
+
<div className="flex-1 overflow-y-auto py-4 custom-scrollbar">
|
|
860
|
+
{currentMessages.length === 0 ? (
|
|
861
|
+
<div className="flex min-h-[50vh] items-center justify-center px-4 text-center">
|
|
862
|
+
<div className="max-w-xl space-y-4">
|
|
863
|
+
<div className="mx-auto flex size-16 items-center justify-center rounded-[20px] border border-white/10 bg-white/5 text-white/80">
|
|
864
|
+
<span className="material-symbols-outlined text-[30px]">chat</span>
|
|
865
|
+
</div>
|
|
866
|
+
<div className="space-y-2">
|
|
867
|
+
<h2 className="text-2xl font-semibold text-white">Start a conversation</h2>
|
|
868
|
+
<p className="text-sm leading-6 text-white/60">
|
|
869
|
+
Simple chat interface to interact with any AI model from connected providers. Select a model and start chatting!
|
|
870
|
+
</p>
|
|
871
|
+
</div>
|
|
872
|
+
</div>
|
|
873
|
+
</div>
|
|
874
|
+
) : null}
|
|
875
|
+
|
|
876
|
+
<div className="mx-auto flex w-full max-w-3xl flex-col gap-4 px-4">
|
|
877
|
+
{currentMessages.map((message) => {
|
|
878
|
+
const isUser = message.role === "user";
|
|
879
|
+
const isAssistant = message.role === "assistant";
|
|
880
|
+
const isStreaming = isAssistant && message.id === streamingMessageId && message.status === "streaming";
|
|
881
|
+
const content = textValue(message.content) || (isAssistant ? streamingText : "");
|
|
882
|
+
|
|
883
|
+
return (
|
|
884
|
+
<div key={message.id} className={`flex w-full ${isUser ? "justify-end" : "justify-start"} mb-6`}>
|
|
885
|
+
<div className={`max-w-[min(88%,42rem)] ${isUser ? "rounded-3xl bg-[#2f2f2f] px-5 py-3.5 text-white" : "text-white/90"}`}>
|
|
886
|
+
<div className="mb-1 flex items-center justify-between gap-3">
|
|
887
|
+
<span className="text-xs font-semibold">{isUser ? "You" : activeModel?.name || "Assistant"}</span>
|
|
888
|
+
</div>
|
|
889
|
+
|
|
890
|
+
{message.attachments?.length ? (
|
|
891
|
+
<div className="mb-3 grid grid-cols-2 gap-2 sm:grid-cols-3 mt-2">
|
|
892
|
+
{message.attachments.map((attachment) => (
|
|
893
|
+
<a key={attachment.id} href={attachment.dataUrl} target="_blank" rel="noreferrer" className="overflow-hidden rounded-[18px] border border-white/10 bg-black/20">
|
|
894
|
+
<img src={attachment.dataUrl} alt={attachment.name} className="h-28 w-full object-cover" />
|
|
895
|
+
</a>
|
|
896
|
+
))}
|
|
897
|
+
</div>
|
|
898
|
+
) : null}
|
|
899
|
+
|
|
900
|
+
<div className="whitespace-pre-wrap break-words text-[15px] leading-7">
|
|
901
|
+
{content}
|
|
902
|
+
{isAssistant && isStreaming && !streamingText ? <span className="inline-block animate-pulse">▋</span> : null}
|
|
903
|
+
</div>
|
|
904
|
+
</div>
|
|
905
|
+
</div>
|
|
906
|
+
);
|
|
907
|
+
})}
|
|
908
|
+
</div>
|
|
909
|
+
</div>
|
|
910
|
+
|
|
911
|
+
<div className="shrink-0 pt-2">
|
|
912
|
+
{attachments.length > 0 ? (
|
|
913
|
+
<div className="mx-auto mb-3 flex w-full max-w-3xl flex-wrap gap-2 px-4">
|
|
914
|
+
{attachments.map((attachment) => (
|
|
915
|
+
<div key={attachment.id} className="flex items-center gap-2 rounded-full border border-white/10 bg-white/5 px-3 py-2">
|
|
916
|
+
<span className="text-xs text-white/80 max-w-[12rem] truncate">{attachment.name}</span>
|
|
917
|
+
<button type="button" onClick={() => removeAttachment(attachment.id)} className="text-white/55 hover:text-white" aria-label="Remove attachment">
|
|
918
|
+
<span className="material-symbols-outlined text-[18px]">close</span>
|
|
919
|
+
</button>
|
|
920
|
+
</div>
|
|
921
|
+
))}
|
|
922
|
+
</div>
|
|
923
|
+
) : null}
|
|
924
|
+
|
|
925
|
+
<div className="mx-auto w-full max-w-3xl px-4 pb-2">
|
|
926
|
+
<div className="rounded-[26px] bg-[#2f2f2f] px-3 pt-3 pb-2 shadow-[0_0_15px_rgba(0,0,0,0.10)] ring-1 ring-white/5">
|
|
927
|
+
<textarea
|
|
928
|
+
value={draft}
|
|
929
|
+
onChange={(event) => setDraft(event.target.value)}
|
|
930
|
+
onKeyDown={handleKeyDown}
|
|
931
|
+
placeholder="Message AI"
|
|
932
|
+
rows={1}
|
|
933
|
+
className="w-full resize-none bg-transparent px-2 text-[15px] leading-6 text-white outline-none placeholder:text-white/40 custom-scrollbar max-h-[25vh] overflow-y-auto"
|
|
934
|
+
/>
|
|
935
|
+
|
|
936
|
+
<div className="mt-2 flex items-center justify-between gap-3">
|
|
937
|
+
<div className="flex items-center gap-2">
|
|
938
|
+
<button type="button" onClick={() => fileInputRef.current?.click()} disabled={!activeModel || loadingData} className="p-2 text-white/50 hover:text-white transition rounded-full hover:bg-white/5">
|
|
939
|
+
<span className="material-symbols-outlined text-[20px]">attach_file</span>
|
|
940
|
+
</button>
|
|
941
|
+
<input ref={fileInputRef} type="file" accept="image/*" multiple className="hidden" onChange={handleAttachFiles} />
|
|
942
|
+
<span className="text-xs font-medium text-white/30 truncate max-w-[120px]">{activeModel ? activeModel.name : "No model"}</span>
|
|
943
|
+
</div>
|
|
944
|
+
|
|
945
|
+
<div className="flex items-center gap-2">
|
|
946
|
+
{isSending ? (
|
|
947
|
+
<button type="button" onClick={handleStop} className="p-2 text-white bg-white/10 hover:bg-white/20 transition rounded-full h-8 w-8 flex items-center justify-center">
|
|
948
|
+
<span className="material-symbols-outlined text-[16px]">stop</span>
|
|
949
|
+
</button>
|
|
950
|
+
) : null}
|
|
951
|
+
<button onClick={sendMessage} disabled={!canSend} className={`h-8 w-8 rounded-full flex items-center justify-center transition ${canSend ? 'bg-white text-black hover:opacity-90' : 'bg-white/10 text-white/30 cursor-not-allowed'}`}>
|
|
952
|
+
<span className="material-symbols-outlined text-[16px]">arrow_upward</span>
|
|
953
|
+
</button>
|
|
954
|
+
</div>
|
|
955
|
+
</div>
|
|
956
|
+
</div>
|
|
957
|
+
</div>
|
|
958
|
+
</div>
|
|
959
|
+
|
|
960
|
+
<p className="mx-auto mt-2 max-w-3xl px-4 pb-4 text-center text-[11px] text-white/30">
|
|
961
|
+
Model list is filtered from connected providers.
|
|
962
|
+
</p>
|
|
963
|
+
</div>
|
|
964
|
+
</div>
|
|
965
|
+
</div>
|
|
966
|
+
);
|
|
967
|
+
}
|