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,247 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState, useEffect, useCallback, useMemo, Fragment } from "react";
|
|
4
|
+
import PropTypes from "prop-types";
|
|
5
|
+
import Card from "@/shared/components/Card";
|
|
6
|
+
import Badge from "@/shared/components/Badge";
|
|
7
|
+
|
|
8
|
+
const fmt = (n) => new Intl.NumberFormat().format(n || 0);
|
|
9
|
+
const fmtCost = (n) => `$${(n || 0).toFixed(2)}`;
|
|
10
|
+
|
|
11
|
+
function fmtTime(iso) {
|
|
12
|
+
if (!iso) return "Never";
|
|
13
|
+
const diffMins = Math.floor((Date.now() - new Date(iso)) / 60000);
|
|
14
|
+
if (diffMins < 1) return "Just now";
|
|
15
|
+
if (diffMins < 60) return `${diffMins}m ago`;
|
|
16
|
+
if (diffMins < 1440) return `${Math.floor(diffMins / 60)}h ago`;
|
|
17
|
+
return new Date(iso).toLocaleDateString();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function SortIcon({ field, currentSort, currentOrder }) {
|
|
21
|
+
if (currentSort !== field) return <span className="ml-1 opacity-20">↕</span>;
|
|
22
|
+
return <span className="ml-1">{currentOrder === "asc" ? "↑" : "↓"}</span>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
SortIcon.propTypes = {
|
|
26
|
+
field: PropTypes.string.isRequired,
|
|
27
|
+
currentSort: PropTypes.string.isRequired,
|
|
28
|
+
currentOrder: PropTypes.string.isRequired,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Render 3 token or cost cells based on viewMode
|
|
33
|
+
*/
|
|
34
|
+
function ValueCells({ item, viewMode, isSummary = false }) {
|
|
35
|
+
if (viewMode === "tokens") {
|
|
36
|
+
return (
|
|
37
|
+
<>
|
|
38
|
+
<td className="px-6 py-3 text-right text-text-muted">
|
|
39
|
+
{isSummary && item.promptTokens === undefined ? "—" : fmt(item.promptTokens)}
|
|
40
|
+
</td>
|
|
41
|
+
<td className="px-6 py-3 text-right text-text-muted">
|
|
42
|
+
{isSummary && item.completionTokens === undefined ? "—" : fmt(item.completionTokens)}
|
|
43
|
+
</td>
|
|
44
|
+
<td className="px-6 py-3 text-right font-medium">
|
|
45
|
+
{fmt(item.totalTokens)}
|
|
46
|
+
</td>
|
|
47
|
+
</>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
return (
|
|
51
|
+
<>
|
|
52
|
+
<td className="px-6 py-3 text-right text-text-muted">
|
|
53
|
+
{isSummary && item.inputCost === undefined ? "—" : fmtCost(item.inputCost)}
|
|
54
|
+
</td>
|
|
55
|
+
<td className="px-6 py-3 text-right text-text-muted">
|
|
56
|
+
{isSummary && item.outputCost === undefined ? "—" : fmtCost(item.outputCost)}
|
|
57
|
+
</td>
|
|
58
|
+
<td className="px-6 py-3 text-right font-medium text-warning">
|
|
59
|
+
{fmtCost(item.totalCost || item.cost)}
|
|
60
|
+
</td>
|
|
61
|
+
</>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
ValueCells.propTypes = {
|
|
66
|
+
item: PropTypes.object.isRequired,
|
|
67
|
+
viewMode: PropTypes.string.isRequired,
|
|
68
|
+
isSummary: PropTypes.bool,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Reusable sortable usage table with expandable group rows.
|
|
73
|
+
*
|
|
74
|
+
* @param {object} props
|
|
75
|
+
* @param {string} props.title - Table title
|
|
76
|
+
* @param {Array} props.columns - Column definitions [{field, label}]
|
|
77
|
+
* @param {Array} props.groupedData - Grouped data from groupDataByKey
|
|
78
|
+
* @param {string} props.tableType - Table type key for sort URL params
|
|
79
|
+
* @param {string} props.sortBy - Current sort field
|
|
80
|
+
* @param {string} props.sortOrder - Current sort order
|
|
81
|
+
* @param {function} props.onToggleSort - Sort toggle handler
|
|
82
|
+
* @param {string} props.viewMode - "tokens" or "costs"
|
|
83
|
+
* @param {string} props.storageKey - localStorage key for expanded state
|
|
84
|
+
* @param {function} props.renderGroupLabel - Render group summary first cell content
|
|
85
|
+
* @param {function} props.renderDetailCells - Render detail row custom cells (before value cells)
|
|
86
|
+
* @param {function} props.renderSummaryCells - Render summary row cells after group label (placeholder cols)
|
|
87
|
+
* @param {string} props.emptyMessage - Empty state message
|
|
88
|
+
*/
|
|
89
|
+
export default function UsageTable({
|
|
90
|
+
title,
|
|
91
|
+
columns,
|
|
92
|
+
groupedData,
|
|
93
|
+
tableType,
|
|
94
|
+
sortBy,
|
|
95
|
+
sortOrder,
|
|
96
|
+
onToggleSort,
|
|
97
|
+
viewMode,
|
|
98
|
+
storageKey,
|
|
99
|
+
renderDetailCells,
|
|
100
|
+
renderSummaryCells,
|
|
101
|
+
emptyMessage,
|
|
102
|
+
}) {
|
|
103
|
+
const [expanded, setExpanded] = useState(new Set());
|
|
104
|
+
|
|
105
|
+
// Load expanded state from localStorage
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
try {
|
|
108
|
+
const saved = localStorage.getItem(storageKey);
|
|
109
|
+
if (saved) setExpanded(new Set(JSON.parse(saved)));
|
|
110
|
+
} catch (e) {
|
|
111
|
+
console.error(`Failed to load ${storageKey}:`, e);
|
|
112
|
+
}
|
|
113
|
+
}, [storageKey]);
|
|
114
|
+
|
|
115
|
+
// Save expanded state to localStorage
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
try {
|
|
118
|
+
localStorage.setItem(storageKey, JSON.stringify([...expanded]));
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.error(`Failed to save ${storageKey}:`, e);
|
|
121
|
+
}
|
|
122
|
+
}, [expanded, storageKey]);
|
|
123
|
+
|
|
124
|
+
const toggleGroup = useCallback((groupKey) => {
|
|
125
|
+
setExpanded((prev) => {
|
|
126
|
+
const next = new Set(prev);
|
|
127
|
+
next.has(groupKey) ? next.delete(groupKey) : next.add(groupKey);
|
|
128
|
+
return next;
|
|
129
|
+
});
|
|
130
|
+
}, []);
|
|
131
|
+
|
|
132
|
+
const valueColumns = useMemo(() => {
|
|
133
|
+
if (viewMode === "tokens") {
|
|
134
|
+
return [
|
|
135
|
+
{ field: "promptTokens", label: "Input Tokens" },
|
|
136
|
+
{ field: "completionTokens", label: "Output Tokens" },
|
|
137
|
+
{ field: "totalTokens", label: "Total Tokens" },
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
return [
|
|
141
|
+
{ field: "promptTokens", label: "Input Cost" },
|
|
142
|
+
{ field: "completionTokens", label: "Output Cost" },
|
|
143
|
+
{ field: "cost", label: "Total Cost" },
|
|
144
|
+
];
|
|
145
|
+
}, [viewMode]);
|
|
146
|
+
|
|
147
|
+
const totalColSpan = columns.length + valueColumns.length;
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<Card className="overflow-hidden">
|
|
151
|
+
<div className="p-4 border-b border-border bg-bg-subtle/50">
|
|
152
|
+
<h3 className="font-semibold">{title}</h3>
|
|
153
|
+
</div>
|
|
154
|
+
<div className="overflow-x-auto">
|
|
155
|
+
<table className="w-full text-sm text-left">
|
|
156
|
+
<thead className="bg-bg-subtle/30 text-text-muted uppercase text-xs">
|
|
157
|
+
<tr>
|
|
158
|
+
{columns.map((col) => (
|
|
159
|
+
<th
|
|
160
|
+
key={col.field}
|
|
161
|
+
className={`px-6 py-3 cursor-pointer hover:bg-bg-subtle/50 ${col.align === "right" ? "text-right" : ""}`}
|
|
162
|
+
onClick={() => onToggleSort(tableType, col.field)}
|
|
163
|
+
>
|
|
164
|
+
{col.label}{" "}
|
|
165
|
+
<SortIcon field={col.field} currentSort={sortBy} currentOrder={sortOrder} />
|
|
166
|
+
</th>
|
|
167
|
+
))}
|
|
168
|
+
{valueColumns.map((col) => (
|
|
169
|
+
<th
|
|
170
|
+
key={col.field}
|
|
171
|
+
className="px-6 py-3 text-right cursor-pointer hover:bg-bg-subtle/50"
|
|
172
|
+
onClick={() => onToggleSort(tableType, col.field)}
|
|
173
|
+
>
|
|
174
|
+
{col.label}{" "}
|
|
175
|
+
<SortIcon field={col.field} currentSort={sortBy} currentOrder={sortOrder} />
|
|
176
|
+
</th>
|
|
177
|
+
))}
|
|
178
|
+
</tr>
|
|
179
|
+
</thead>
|
|
180
|
+
<tbody className="divide-y divide-border">
|
|
181
|
+
{groupedData.map((group) => (
|
|
182
|
+
<Fragment key={group.groupKey}>
|
|
183
|
+
{/* Group summary row */}
|
|
184
|
+
<tr
|
|
185
|
+
className="group-summary cursor-pointer hover:bg-bg-subtle/50 transition-colors"
|
|
186
|
+
onClick={() => toggleGroup(group.groupKey)}
|
|
187
|
+
>
|
|
188
|
+
<td className="px-6 py-3">
|
|
189
|
+
<div className="flex items-center gap-2">
|
|
190
|
+
<span className={`material-symbols-outlined text-[18px] text-text-muted transition-transform ${expanded.has(group.groupKey) ? "rotate-90" : ""}`}>
|
|
191
|
+
chevron_right
|
|
192
|
+
</span>
|
|
193
|
+
<span className={`font-medium transition-colors ${group.summary.pending > 0 ? "text-primary" : ""}`}>
|
|
194
|
+
{group.groupKey}
|
|
195
|
+
</span>
|
|
196
|
+
</div>
|
|
197
|
+
</td>
|
|
198
|
+
{renderSummaryCells(group)}
|
|
199
|
+
<ValueCells item={group.summary} viewMode={viewMode} isSummary />
|
|
200
|
+
</tr>
|
|
201
|
+
{/* Detail rows */}
|
|
202
|
+
{expanded.has(group.groupKey) && group.items.map((item) => (
|
|
203
|
+
<tr
|
|
204
|
+
key={`detail-${item.key}`}
|
|
205
|
+
className="group-detail hover:bg-bg-subtle/20 transition-colors"
|
|
206
|
+
>
|
|
207
|
+
{renderDetailCells(item)}
|
|
208
|
+
<ValueCells item={item} viewMode={viewMode} />
|
|
209
|
+
</tr>
|
|
210
|
+
))}
|
|
211
|
+
</Fragment>
|
|
212
|
+
))}
|
|
213
|
+
{groupedData.length === 0 && (
|
|
214
|
+
<tr>
|
|
215
|
+
<td colSpan={totalColSpan} className="px-6 py-8 text-center text-text-muted">
|
|
216
|
+
{emptyMessage}
|
|
217
|
+
</td>
|
|
218
|
+
</tr>
|
|
219
|
+
)}
|
|
220
|
+
</tbody>
|
|
221
|
+
</table>
|
|
222
|
+
</div>
|
|
223
|
+
</Card>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
UsageTable.propTypes = {
|
|
228
|
+
title: PropTypes.string.isRequired,
|
|
229
|
+
columns: PropTypes.arrayOf(PropTypes.shape({
|
|
230
|
+
field: PropTypes.string.isRequired,
|
|
231
|
+
label: PropTypes.string.isRequired,
|
|
232
|
+
align: PropTypes.string,
|
|
233
|
+
})).isRequired,
|
|
234
|
+
groupedData: PropTypes.array.isRequired,
|
|
235
|
+
tableType: PropTypes.string.isRequired,
|
|
236
|
+
sortBy: PropTypes.string.isRequired,
|
|
237
|
+
sortOrder: PropTypes.string.isRequired,
|
|
238
|
+
onToggleSort: PropTypes.func.isRequired,
|
|
239
|
+
viewMode: PropTypes.string.isRequired,
|
|
240
|
+
storageKey: PropTypes.string.isRequired,
|
|
241
|
+
renderDetailCells: PropTypes.func.isRequired,
|
|
242
|
+
renderSummaryCells: PropTypes.func.isRequired,
|
|
243
|
+
emptyMessage: PropTypes.string.isRequired,
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
// Re-export utilities for use in UsageStats orchestrator
|
|
247
|
+
export { fmt, fmtCost, fmtTime };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Suspense, useState } from "react";
|
|
4
|
+
import { useSearchParams, useRouter } from "next/navigation";
|
|
5
|
+
import { UsageStats, RequestLogger, CardSkeleton, SegmentedControl } from "@/shared/components";
|
|
6
|
+
import RequestDetailsTab from "./components/RequestDetailsTab";
|
|
7
|
+
|
|
8
|
+
const PERIODS = [
|
|
9
|
+
{ value: "today", label: "Today" },
|
|
10
|
+
{ value: "24h", label: "24h" },
|
|
11
|
+
{ value: "7d", label: "7D" },
|
|
12
|
+
{ value: "30d", label: "30D" },
|
|
13
|
+
{ value: "60d", label: "60D" },
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
export default function UsagePage() {
|
|
17
|
+
return (
|
|
18
|
+
<Suspense fallback={<CardSkeleton />}>
|
|
19
|
+
<UsageContent />
|
|
20
|
+
</Suspense>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function UsageContent() {
|
|
25
|
+
const searchParams = useSearchParams();
|
|
26
|
+
const router = useRouter();
|
|
27
|
+
|
|
28
|
+
const [period, setPeriod] = useState("today");
|
|
29
|
+
|
|
30
|
+
const tabFromUrl = searchParams.get("tab");
|
|
31
|
+
const activeTab = tabFromUrl && ["overview", "logs", "details"].includes(tabFromUrl)
|
|
32
|
+
? tabFromUrl
|
|
33
|
+
: "overview";
|
|
34
|
+
|
|
35
|
+
const handleTabChange = (value) => {
|
|
36
|
+
if (value === activeTab) return;
|
|
37
|
+
const params = new URLSearchParams(searchParams);
|
|
38
|
+
params.set("tab", value);
|
|
39
|
+
router.push(`/dashboard/usage?${params.toString()}`, { scroll: false });
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div className="flex min-w-0 flex-col gap-6 px-1 sm:px-0">
|
|
44
|
+
{/* Tabs + period selector on same row */}
|
|
45
|
+
<div className="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
|
|
46
|
+
<SegmentedControl
|
|
47
|
+
options={[
|
|
48
|
+
{ value: "overview", label: "Overview" },
|
|
49
|
+
{ value: "details", label: "Details" },
|
|
50
|
+
]}
|
|
51
|
+
value={activeTab}
|
|
52
|
+
onChange={handleTabChange}
|
|
53
|
+
className="w-full sm:w-auto"
|
|
54
|
+
/>
|
|
55
|
+
{activeTab === "overview" && (
|
|
56
|
+
<SegmentedControl
|
|
57
|
+
options={PERIODS}
|
|
58
|
+
value={period}
|
|
59
|
+
onChange={setPeriod}
|
|
60
|
+
size="sm"
|
|
61
|
+
className="w-full sm:w-auto"
|
|
62
|
+
/>
|
|
63
|
+
)}
|
|
64
|
+
</div>
|
|
65
|
+
|
|
66
|
+
{activeTab === "overview" && (
|
|
67
|
+
<Suspense fallback={<CardSkeleton />}>
|
|
68
|
+
<UsageStats period={period} setPeriod={setPeriod} hidePeriodSelector />
|
|
69
|
+
</Suspense>
|
|
70
|
+
)}
|
|
71
|
+
{activeTab === "logs" && <RequestLogger />}
|
|
72
|
+
{activeTab === "details" && <RequestDetailsTab />}
|
|
73
|
+
</div>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import { getSettings } from "@/lib/localDb";
|
|
3
|
+
import bcrypt from "bcryptjs";
|
|
4
|
+
import { cookies } from "next/headers";
|
|
5
|
+
import { setDashboardAuthCookie } from "@/lib/auth/dashboardSession";
|
|
6
|
+
import { isOidcConfigured } from "@/lib/auth/oidc";
|
|
7
|
+
import { checkLock, recordFail, recordSuccess, getClientIp } from "@/lib/auth/loginLimiter";
|
|
8
|
+
|
|
9
|
+
const RESET_HINT = "Forgot password? Reset to default via 9Router CLI → Settings → Reset Password to Default.";
|
|
10
|
+
|
|
11
|
+
function isTunnelRequest(request, settings) {
|
|
12
|
+
const host = (request.headers.get("host") || "").split(":")[0].toLowerCase();
|
|
13
|
+
const tunnelHost = settings.tunnelUrl ? new URL(settings.tunnelUrl).hostname.toLowerCase() : "";
|
|
14
|
+
const tailscaleHost = settings.tailscaleUrl ? new URL(settings.tailscaleUrl).hostname.toLowerCase() : "";
|
|
15
|
+
return (tunnelHost && host === tunnelHost) || (tailscaleHost && host === tailscaleHost);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function POST(request) {
|
|
19
|
+
try {
|
|
20
|
+
const ip = getClientIp(request);
|
|
21
|
+
const lock = checkLock(ip);
|
|
22
|
+
if (lock.locked) {
|
|
23
|
+
return NextResponse.json(
|
|
24
|
+
{ error: `Too many failed attempts. Try again in ${lock.retryAfter}s. ${RESET_HINT}`, retryAfter: lock.retryAfter, resetHint: RESET_HINT },
|
|
25
|
+
{ status: 429, headers: { "Retry-After": String(lock.retryAfter) } }
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const { password } = await request.json();
|
|
30
|
+
const settings = await getSettings();
|
|
31
|
+
|
|
32
|
+
// Block login via tunnel/tailscale if dashboard access is disabled
|
|
33
|
+
if (isTunnelRequest(request, settings) && settings.tunnelDashboardAccess !== true) {
|
|
34
|
+
return NextResponse.json({ error: "Dashboard access via tunnel is disabled" }, { status: 403 });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Default password is '123456' if not set
|
|
38
|
+
const storedHash = settings.password;
|
|
39
|
+
|
|
40
|
+
if (settings.authMode === "oidc" && isOidcConfigured(settings)) {
|
|
41
|
+
return NextResponse.json({ error: "Password login is disabled. Use OIDC sign in." }, { status: 403 });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let isValid = false;
|
|
45
|
+
if (storedHash) {
|
|
46
|
+
isValid = await bcrypt.compare(password, storedHash);
|
|
47
|
+
} else {
|
|
48
|
+
// Use env var or default
|
|
49
|
+
const initialPassword = process.env.INITIAL_PASSWORD || "123456";
|
|
50
|
+
isValid = password === initialPassword;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (isValid) {
|
|
54
|
+
recordSuccess(ip);
|
|
55
|
+
const cookieStore = await cookies();
|
|
56
|
+
await setDashboardAuthCookie(cookieStore, request);
|
|
57
|
+
|
|
58
|
+
return NextResponse.json({ success: true });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const { remainingBeforeLock } = recordFail(ip);
|
|
62
|
+
const postLock = checkLock(ip);
|
|
63
|
+
if (postLock.locked) {
|
|
64
|
+
return NextResponse.json(
|
|
65
|
+
{ error: `Too many failed attempts. Try again in ${postLock.retryAfter}s. ${RESET_HINT}`, retryAfter: postLock.retryAfter, resetHint: RESET_HINT },
|
|
66
|
+
{ status: 429, headers: { "Retry-After": String(postLock.retryAfter) } }
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
return NextResponse.json(
|
|
70
|
+
{ error: `Invalid password. ${remainingBeforeLock} attempt(s) left before lockout.`, remainingBeforeLock },
|
|
71
|
+
{ status: 401 }
|
|
72
|
+
);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
return NextResponse.json({ error: error.message }, { status: 500 });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import { cookies } from "next/headers";
|
|
3
|
+
import { clearDashboardAuthCookie } from "@/lib/auth/dashboardSession";
|
|
4
|
+
|
|
5
|
+
export async function POST() {
|
|
6
|
+
const cookieStore = await cookies();
|
|
7
|
+
clearDashboardAuthCookie(cookieStore);
|
|
8
|
+
cookieStore.delete("oidc_state");
|
|
9
|
+
cookieStore.delete("oidc_nonce");
|
|
10
|
+
cookieStore.delete("oidc_code_verifier");
|
|
11
|
+
return NextResponse.json({ success: true });
|
|
12
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import { cookies } from "next/headers";
|
|
3
|
+
import {
|
|
4
|
+
exchangeOidcCode,
|
|
5
|
+
fetchOidcDiscovery,
|
|
6
|
+
getOidcRuntimeConfig,
|
|
7
|
+
getPublicOrigin,
|
|
8
|
+
pickOidcDisplayName,
|
|
9
|
+
pickOidcEmail,
|
|
10
|
+
verifyOidcIdToken,
|
|
11
|
+
} from "@/lib/auth/oidc";
|
|
12
|
+
import { setDashboardAuthCookie } from "@/lib/auth/dashboardSession";
|
|
13
|
+
|
|
14
|
+
function clearOidcCookies(cookieStore) {
|
|
15
|
+
cookieStore.delete("oidc_state");
|
|
16
|
+
cookieStore.delete("oidc_nonce");
|
|
17
|
+
cookieStore.delete("oidc_code_verifier");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function GET(request) {
|
|
21
|
+
const url = new URL(request.url);
|
|
22
|
+
const error = url.searchParams.get("error");
|
|
23
|
+
if (error) {
|
|
24
|
+
return NextResponse.redirect(new URL(`/login?error=${encodeURIComponent(error)}`, getPublicOrigin(request)));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const code = url.searchParams.get("code");
|
|
28
|
+
const state = url.searchParams.get("state");
|
|
29
|
+
if (!code || !state) {
|
|
30
|
+
return NextResponse.redirect(new URL("/login?error=oidc_missing_code", getPublicOrigin(request)));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const cookieStore = await cookies();
|
|
34
|
+
const storedState = cookieStore.get("oidc_state")?.value;
|
|
35
|
+
const storedNonce = cookieStore.get("oidc_nonce")?.value;
|
|
36
|
+
const codeVerifier = cookieStore.get("oidc_code_verifier")?.value;
|
|
37
|
+
|
|
38
|
+
if (!storedState || !storedNonce || !codeVerifier || storedState !== state) {
|
|
39
|
+
clearOidcCookies(cookieStore);
|
|
40
|
+
return NextResponse.redirect(new URL("/login?error=oidc_invalid_state", getPublicOrigin(request)));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const config = await getOidcRuntimeConfig();
|
|
45
|
+
if (!config) {
|
|
46
|
+
clearOidcCookies(cookieStore);
|
|
47
|
+
return NextResponse.redirect(new URL("/login?error=oidc_not_configured", getPublicOrigin(request)));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const discovery = await fetchOidcDiscovery(config.issuerUrl);
|
|
51
|
+
const discoveredIssuer = discovery.issuer || config.issuerUrl;
|
|
52
|
+
const redirectUri = `${getPublicOrigin(request)}/api/auth/oidc/callback`;
|
|
53
|
+
const tokenData = await exchangeOidcCode({
|
|
54
|
+
tokenEndpoint: discovery.token_endpoint,
|
|
55
|
+
clientId: config.clientId,
|
|
56
|
+
clientSecret: config.clientSecret,
|
|
57
|
+
code,
|
|
58
|
+
redirectUri,
|
|
59
|
+
codeVerifier,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (!tokenData.id_token) {
|
|
63
|
+
throw new Error("OIDC provider did not return an id_token");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const payload = await verifyOidcIdToken({
|
|
67
|
+
idToken: tokenData.id_token,
|
|
68
|
+
issuer: discoveredIssuer,
|
|
69
|
+
audience: config.clientId,
|
|
70
|
+
jwksUri: discovery.jwks_uri,
|
|
71
|
+
nonce: storedNonce,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
clearOidcCookies(cookieStore);
|
|
75
|
+
await setDashboardAuthCookie(cookieStore, request, {
|
|
76
|
+
oidc: true,
|
|
77
|
+
oidcSub: payload.sub || null,
|
|
78
|
+
oidcEmail: pickOidcEmail(payload) || null,
|
|
79
|
+
oidcName: pickOidcDisplayName(payload),
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return NextResponse.redirect(new URL("/dashboard", getPublicOrigin(request)));
|
|
83
|
+
} catch (error) {
|
|
84
|
+
clearOidcCookies(cookieStore);
|
|
85
|
+
return NextResponse.redirect(new URL(`/login?error=${encodeURIComponent(error.message || "oidc_callback_failed")}`, getPublicOrigin(request)));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import { cookies } from "next/headers";
|
|
3
|
+
import {
|
|
4
|
+
buildOidcAuthorizationUrl,
|
|
5
|
+
createOidcNonce,
|
|
6
|
+
createOidcState,
|
|
7
|
+
createPkcePair,
|
|
8
|
+
fetchOidcDiscovery,
|
|
9
|
+
getOidcRuntimeConfig,
|
|
10
|
+
getPublicOrigin,
|
|
11
|
+
} from "@/lib/auth/oidc";
|
|
12
|
+
import { shouldUseSecureCookie } from "@/lib/auth/dashboardSession";
|
|
13
|
+
|
|
14
|
+
export async function GET(request) {
|
|
15
|
+
try {
|
|
16
|
+
const config = await getOidcRuntimeConfig();
|
|
17
|
+
if (!config) {
|
|
18
|
+
return NextResponse.redirect(new URL("/login?error=oidc_not_configured", getPublicOrigin(request)));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const discovery = await fetchOidcDiscovery(config.issuerUrl);
|
|
22
|
+
const state = createOidcState();
|
|
23
|
+
const nonce = createOidcNonce();
|
|
24
|
+
const { verifier, challenge } = createPkcePair();
|
|
25
|
+
const redirectUri = `${getPublicOrigin(request)}/api/auth/oidc/callback`;
|
|
26
|
+
const authUrl = buildOidcAuthorizationUrl({
|
|
27
|
+
authorizationEndpoint: discovery.authorization_endpoint,
|
|
28
|
+
clientId: config.clientId,
|
|
29
|
+
redirectUri,
|
|
30
|
+
scopes: config.scopes,
|
|
31
|
+
state,
|
|
32
|
+
nonce,
|
|
33
|
+
codeChallenge: challenge,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const cookieStore = await cookies();
|
|
37
|
+
const baseOptions = {
|
|
38
|
+
httpOnly: true,
|
|
39
|
+
secure: shouldUseSecureCookie(request),
|
|
40
|
+
sameSite: "lax",
|
|
41
|
+
path: "/",
|
|
42
|
+
maxAge: 10 * 60,
|
|
43
|
+
};
|
|
44
|
+
cookieStore.set("oidc_state", state, baseOptions);
|
|
45
|
+
cookieStore.set("oidc_nonce", nonce, baseOptions);
|
|
46
|
+
cookieStore.set("oidc_code_verifier", verifier, baseOptions);
|
|
47
|
+
|
|
48
|
+
return NextResponse.redirect(authUrl);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
return NextResponse.redirect(new URL(`/login?error=${encodeURIComponent(error.message || "oidc_start_failed")}`, getPublicOrigin(request)));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import { cookies } from "next/headers";
|
|
3
|
+
import { getSettings } from "@/lib/localDb";
|
|
4
|
+
import { fetchOidcDiscovery, getPublicOrigin, probeOidcClientSecret } from "@/lib/auth/oidc";
|
|
5
|
+
import { verifyDashboardAuthToken } from "@/lib/auth/dashboardSession";
|
|
6
|
+
|
|
7
|
+
async function canAccessTestRoute() {
|
|
8
|
+
const settings = await getSettings();
|
|
9
|
+
if (settings.requireLogin === false) return true;
|
|
10
|
+
|
|
11
|
+
const cookieStore = await cookies();
|
|
12
|
+
const token = cookieStore.get("auth_token")?.value;
|
|
13
|
+
return await verifyDashboardAuthToken(token);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function POST(request) {
|
|
17
|
+
try {
|
|
18
|
+
if (!(await canAccessTestRoute())) {
|
|
19
|
+
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const body = await request.json().catch(() => ({}));
|
|
23
|
+
const settings = await getSettings();
|
|
24
|
+
|
|
25
|
+
const issuerUrl = String(body.issuerUrl || settings.oidcIssuerUrl || "").trim();
|
|
26
|
+
const clientId = String(body.clientId || settings.oidcClientId || "").trim();
|
|
27
|
+
const scopes = String(body.scopes || settings.oidcScopes || "openid profile email").trim() || "openid profile email";
|
|
28
|
+
const clientSecret = String(
|
|
29
|
+
Object.prototype.hasOwnProperty.call(body, "clientSecret")
|
|
30
|
+
? body.clientSecret
|
|
31
|
+
: settings.oidcClientSecret || ""
|
|
32
|
+
).trim();
|
|
33
|
+
|
|
34
|
+
if (!issuerUrl) {
|
|
35
|
+
return NextResponse.json({ error: "Issuer URL is required" }, { status: 400 });
|
|
36
|
+
}
|
|
37
|
+
if (!clientId) {
|
|
38
|
+
return NextResponse.json({ error: "Client ID is required" }, { status: 400 });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const discovery = await fetchOidcDiscovery(issuerUrl);
|
|
42
|
+
const redirectUri = `${getPublicOrigin(request)}/api/auth/oidc/callback`;
|
|
43
|
+
const secretProbe = await probeOidcClientSecret({
|
|
44
|
+
tokenEndpoint: discovery.token_endpoint,
|
|
45
|
+
clientId,
|
|
46
|
+
clientSecret,
|
|
47
|
+
redirectUri,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (secretProbe.tested && secretProbe.valid === false) {
|
|
51
|
+
return NextResponse.json({
|
|
52
|
+
ok: false,
|
|
53
|
+
discoveryOk: true,
|
|
54
|
+
clientSecretTested: true,
|
|
55
|
+
clientSecretValid: false,
|
|
56
|
+
issuerUrl,
|
|
57
|
+
clientId,
|
|
58
|
+
scopes,
|
|
59
|
+
redirectUri,
|
|
60
|
+
authorizationEndpoint: discovery.authorization_endpoint || "",
|
|
61
|
+
tokenEndpoint: discovery.token_endpoint || "",
|
|
62
|
+
jwksUri: discovery.jwks_uri || "",
|
|
63
|
+
error: `Discovery loaded, but the client secret is not valid: ${secretProbe.message}`,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return NextResponse.json({
|
|
68
|
+
ok: true,
|
|
69
|
+
discoveryOk: true,
|
|
70
|
+
clientSecretTested: secretProbe.tested,
|
|
71
|
+
clientSecretValid: secretProbe.valid,
|
|
72
|
+
issuerUrl,
|
|
73
|
+
clientId,
|
|
74
|
+
scopes,
|
|
75
|
+
redirectUri,
|
|
76
|
+
authorizationEndpoint: discovery.authorization_endpoint || "",
|
|
77
|
+
tokenEndpoint: discovery.token_endpoint || "",
|
|
78
|
+
jwksUri: discovery.jwks_uri || "",
|
|
79
|
+
message: secretProbe.message,
|
|
80
|
+
});
|
|
81
|
+
} catch (error) {
|
|
82
|
+
return NextResponse.json({ error: error.message || "OIDC test failed" }, { status: 500 });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import { cookies } from "next/headers";
|
|
3
|
+
import { getSettings } from "@/lib/localDb";
|
|
4
|
+
import { isOidcConfigured } from "@/lib/auth/oidc";
|
|
5
|
+
import { getDashboardAuthSession } from "@/lib/auth/dashboardSession";
|
|
6
|
+
|
|
7
|
+
export async function GET() {
|
|
8
|
+
try {
|
|
9
|
+
const settings = await getSettings();
|
|
10
|
+
const cookieStore = await cookies();
|
|
11
|
+
const session = await getDashboardAuthSession(cookieStore.get("auth_token")?.value);
|
|
12
|
+
const requireLogin = settings.requireLogin !== false;
|
|
13
|
+
const authMode = settings.authMode || "password";
|
|
14
|
+
const oidcName = String(session?.oidcName || "").trim();
|
|
15
|
+
const oidcEmail = String(session?.oidcEmail || "").trim();
|
|
16
|
+
const displayName = oidcName || oidcEmail || (session?.oidc ? "OIDC user" : "Password user");
|
|
17
|
+
const loginMethod = session?.oidc ? "OIDC" : "Password";
|
|
18
|
+
|
|
19
|
+
return NextResponse.json({
|
|
20
|
+
requireLogin,
|
|
21
|
+
authMode,
|
|
22
|
+
oidcConfigured: isOidcConfigured(settings),
|
|
23
|
+
oidcLoginLabel: (settings.oidcLoginLabel || "Sign in with OIDC").trim() || "Sign in with OIDC",
|
|
24
|
+
hasPassword: !!settings.password,
|
|
25
|
+
displayName,
|
|
26
|
+
loginMethod,
|
|
27
|
+
oidcName: oidcName || null,
|
|
28
|
+
oidcEmail: oidcEmail || null,
|
|
29
|
+
oidcLogin: !!session?.oidc,
|
|
30
|
+
});
|
|
31
|
+
} catch {
|
|
32
|
+
return NextResponse.json({
|
|
33
|
+
requireLogin: true,
|
|
34
|
+
authMode: "password",
|
|
35
|
+
oidcConfigured: false,
|
|
36
|
+
oidcLoginLabel: "Sign in with OIDC",
|
|
37
|
+
hasPassword: false,
|
|
38
|
+
displayName: "Password user",
|
|
39
|
+
loginMethod: "Password",
|
|
40
|
+
oidcName: null,
|
|
41
|
+
oidcEmail: null,
|
|
42
|
+
oidcLogin: false,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|