swayrouter 1.0.0
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/.env.example +43 -0
- package/CHANGELOG.md +132 -0
- package/LICENSE +30 -0
- package/README.id.md +633 -0
- package/README.md +628 -0
- package/cli/cli.js +388 -0
- package/cli/package.json +4 -0
- package/cli/src/cli/commands/xaiVideo.js +280 -0
- package/cli/src/cli/tray/SwayAvatar.svg +20 -0
- package/cli/src/cli/tray/autostart.js +351 -0
- package/cli/src/cli/tray/icon.ico +0 -0
- package/cli/src/cli/tray/icon.png +0 -0
- package/cli/src/cli/tray/tray.js +258 -0
- package/cli/src/cli/tray/tray.ps1 +129 -0
- package/cli/src/cli/tray/trayHost.js +157 -0
- package/cli/src/cli/tray/trayWin.js +83 -0
- package/cli/src/cli/utils/display.js +123 -0
- package/cli/src/cli/utils/input.js +138 -0
- package/cli/src/runtime/discover.js +153 -0
- package/cli/src/runtime/lifecycle.js +333 -0
- package/cli/src/runtime/runMenu.js +250 -0
- package/cli/src/runtime/uiAdapters.js +12 -0
- package/cli/src/runtime/update.js +130 -0
- package/dashboard/dist/assets/CliTools-Ch3gKuNw.js +24 -0
- package/dashboard/dist/assets/Combo-BBCldjWi.js +1 -0
- package/dashboard/dist/assets/ConsoleLog-wywAYcPT.js +6 -0
- package/dashboard/dist/assets/Dashboard-DxzyF41b.js +1 -0
- package/dashboard/dist/assets/Header-C_9Su9BF.js +1 -0
- package/dashboard/dist/assets/Keys-D0ufgcsc.js +1 -0
- package/dashboard/dist/assets/Login-BeKpipS_.js +1 -0
- package/dashboard/dist/assets/ManageApiKey-CVXsmW2B.js +1 -0
- package/dashboard/dist/assets/OAuthCallback-D_UZYcF6.js +1 -0
- package/dashboard/dist/assets/Provider-BU7JfTqm.js +4 -0
- package/dashboard/dist/assets/ProviderModelAccordion-BAifkfVR.js +1 -0
- package/dashboard/dist/assets/Proxy-CU15VJ--.js +1 -0
- package/dashboard/dist/assets/QuotaMonitor-HzGK7bcc.js +1 -0
- package/dashboard/dist/assets/Settings-Dt4y2dC0.js +1 -0
- package/dashboard/dist/assets/Setup-DSDUwU7N.js +1 -0
- package/dashboard/dist/assets/StatusBadge-1nAOyHU2.js +1 -0
- package/dashboard/dist/assets/SwayChat-Bup7up6D.js +10 -0
- package/dashboard/dist/assets/Usage-eWnrPQ_v.js +4 -0
- package/dashboard/dist/assets/accordion-DOOPDDgt.js +1 -0
- package/dashboard/dist/assets/admin-extras-api-CCdu5TFM.js +1 -0
- package/dashboard/dist/assets/api-keys-api-ifAC2Ok3.js +1 -0
- package/dashboard/dist/assets/card-CC0Omjcv.js +1 -0
- package/dashboard/dist/assets/chatStudio-C0zPz_Z_.js +2 -0
- package/dashboard/dist/assets/checkbox-7SZBrmbN.js +1 -0
- package/dashboard/dist/assets/connections-api-_N54UD3S.js +1 -0
- package/dashboard/dist/assets/copy-button-qBvM6H9z.js +1 -0
- package/dashboard/dist/assets/currency-api-SV9CBf5e.js +1 -0
- package/dashboard/dist/assets/flip-button-BGgkjtl0.js +1 -0
- package/dashboard/dist/assets/frame-cUiti6Lq.js +1 -0
- package/dashboard/dist/assets/icons-vendor-CUx7SB5V.js +541 -0
- package/dashboard/dist/assets/index-B6j-9zHy.js +10 -0
- package/dashboard/dist/assets/index-C-_l0yYz.css +1 -0
- package/dashboard/dist/assets/live-mode-CHShLY4E.js +1 -0
- package/dashboard/dist/assets/markdown-vendor-BY8e1gQ8.js +29 -0
- package/dashboard/dist/assets/motion-vendor-g5fpGzmJ.js +9 -0
- package/dashboard/dist/assets/oauth-callback-CqYQzyd7.js +1 -0
- package/dashboard/dist/assets/query-vendor-DVevaSVS.js +1 -0
- package/dashboard/dist/assets/react-vendor-xnYrwzsL.js +61 -0
- package/dashboard/dist/assets/ripple-button-l8aMiVVG.js +1 -0
- package/dashboard/dist/assets/segmented-CqmEnQjZ.js +1 -0
- package/dashboard/dist/assets/select-D8pUtMXp.js +1 -0
- package/dashboard/dist/assets/skeleton-7uJDiIXe.js +1 -0
- package/dashboard/dist/assets/table-D0M60Tu1.js +1 -0
- package/dashboard/dist/assets/tabs-C6YkuulG.js +1 -0
- package/dashboard/dist/assets/tunnel-api-DDPsBaDV.js +1 -0
- package/dashboard/dist/assets/ui-vendor-BuM9f2NY.js +17 -0
- package/dashboard/dist/image2/SwayAvatar.svg +20 -0
- package/dashboard/dist/index.html +32 -0
- package/dashboard/dist/logo/avatar.svg +1 -0
- package/dashboard/dist/logo/sway.svg +20 -0
- package/dashboard/dist/logo/swaychat.svg +20 -0
- package/dashboard/dist/providers/SwayCustom.svg +19 -0
- package/dashboard/dist/providers/alicode.svg +12 -0
- package/dashboard/dist/providers/anthropic.svg +11 -0
- package/dashboard/dist/providers/antigravity.svg +3 -0
- package/dashboard/dist/providers/azure.svg +5 -0
- package/dashboard/dist/providers/baidu.svg +3 -0
- package/dashboard/dist/providers/blackbox.svg +5 -0
- package/dashboard/dist/providers/byteplus.svg +3 -0
- package/dashboard/dist/providers/cerebras.svg +4 -0
- package/dashboard/dist/providers/chutes.svg +4 -0
- package/dashboard/dist/providers/claude.svg +3 -0
- package/dashboard/dist/providers/cline.svg +11 -0
- package/dashboard/dist/providers/cloudflare-ai.svg +4 -0
- package/dashboard/dist/providers/codebuddy.svg +11 -0
- package/dashboard/dist/providers/codex.svg +10 -0
- package/dashboard/dist/providers/commandcode.svg +3 -0
- package/dashboard/dist/providers/cursor.svg +3 -0
- package/dashboard/dist/providers/deepseek.svg +10 -0
- package/dashboard/dist/providers/featherless.svg +3 -0
- package/dashboard/dist/providers/fireworks.svg +3 -0
- package/dashboard/dist/providers/gemini.svg +3 -0
- package/dashboard/dist/providers/geminicli.svg +11 -0
- package/dashboard/dist/providers/github.svg +3 -0
- package/dashboard/dist/providers/grok.svg +3 -0
- package/dashboard/dist/providers/groq.svg +3 -0
- package/dashboard/dist/providers/hermesagent.svg +1 -0
- package/dashboard/dist/providers/kilocode.svg +15 -0
- package/dashboard/dist/providers/kimchi.svg +3 -0
- package/dashboard/dist/providers/kimi.svg +4 -0
- package/dashboard/dist/providers/kiro.svg +10 -0
- package/dashboard/dist/providers/meta.svg +3 -0
- package/dashboard/dist/providers/mimo.svg +10 -0
- package/dashboard/dist/providers/minimax.svg +3 -0
- package/dashboard/dist/providers/mistral.svg +3 -0
- package/dashboard/dist/providers/morph.svg +3 -0
- package/dashboard/dist/providers/nebius.svg +4 -0
- package/dashboard/dist/providers/nvidia.svg +3 -0
- package/dashboard/dist/providers/ollama.svg +3 -0
- package/dashboard/dist/providers/omp.svg +5 -0
- package/dashboard/dist/providers/openai.svg +3 -0
- package/dashboard/dist/providers/opencode.svg +3 -0
- package/dashboard/dist/providers/openrouter.svg +3 -0
- package/dashboard/dist/providers/perplexity.svg +3 -0
- package/dashboard/dist/providers/poolside.svg +36 -0
- package/dashboard/dist/providers/qoder.svg +11 -0
- package/dashboard/dist/providers/sumopod.svg +3 -0
- package/dashboard/dist/providers/tencent.svg +5 -0
- package/dashboard/dist/providers/together.svg +12 -0
- package/dashboard/dist/providers/trae.svg +3 -0
- package/dashboard/dist/providers/venice.svg +4 -0
- package/dashboard/dist/providers/vercel.svg +3 -0
- package/dashboard/dist/providers/vertex.svg +17 -0
- package/dashboard/dist/providers/windsurf.svg +10 -0
- package/dashboard/dist/providers/zai.svg +3 -0
- package/dashboard/tsconfig.json +13 -0
- package/package.json +87 -0
- package/src/config/appConstants.js +153 -0
- package/src/config/defaultThinkingSignature.js +7 -0
- package/src/config/errorConfig.js +117 -0
- package/src/config/grokCli.js +9 -0
- package/src/config/kiroConstants.js +235 -0
- package/src/config/mediaConfig.js +20 -0
- package/src/config/ollamaModels.js +18 -0
- package/src/config/providerModels.js +109 -0
- package/src/config/providers.js +17 -0
- package/src/config/runtimeConfig.js +84 -0
- package/src/dashboardGuard.js +254 -0
- package/src/executors/antigravity.js +389 -0
- package/src/executors/azure.js +49 -0
- package/src/executors/base.js +225 -0
- package/src/executors/codebuddy-cn.js +23 -0
- package/src/executors/codebuddy-intl.js +60 -0
- package/src/executors/codex.js +436 -0
- package/src/executors/commandcode.js +83 -0
- package/src/executors/cursor.js +1075 -0
- package/src/executors/default.js +294 -0
- package/src/executors/gemini-cli.js +88 -0
- package/src/executors/github.js +393 -0
- package/src/executors/grok-cli.js +510 -0
- package/src/executors/grok-web.js +342 -0
- package/src/executors/index.js +86 -0
- package/src/executors/kimchi.js +116 -0
- package/src/executors/kiro.js +1155 -0
- package/src/executors/ollama-local.js +14 -0
- package/src/executors/opencode-go.js +47 -0
- package/src/executors/opencode.js +31 -0
- package/src/executors/qoder.js +433 -0
- package/src/executors/trae.js +318 -0
- package/src/executors/vertex.js +151 -0
- package/src/executors/windsurf.js +555 -0
- package/src/executors/xiaomi-tokenplan.js +16 -0
- package/src/handlers/chatCore/nonStreamingHandler.js +370 -0
- package/src/handlers/chatCore/requestDetail.js +130 -0
- package/src/handlers/chatCore/sseToJsonHandler.js +318 -0
- package/src/handlers/chatCore/streamingHandler.js +250 -0
- package/src/handlers/chatCore.js +652 -0
- package/src/lib/auth/dashboardSession.js +83 -0
- package/src/lib/auth/loginLimiter.js +99 -0
- package/src/lib/cache/ttlCache.js +153 -0
- package/src/lib/consoleLogBuffer.js +127 -0
- package/src/lib/dataDir.js +45 -0
- package/src/lib/db/adapters/betterSqliteAdapter.js +36 -0
- package/src/lib/db/adapters/bunSqliteAdapter.js +47 -0
- package/src/lib/db/adapters/nodeSqliteAdapter.js +65 -0
- package/src/lib/db/adapters/runtimeHelpers.js +23 -0
- package/src/lib/db/adapters/sqljsAdapter.js +103 -0
- package/src/lib/db/backup.js +75 -0
- package/src/lib/db/driver.js +110 -0
- package/src/lib/db/helpers/jsonCol.js +18 -0
- package/src/lib/db/helpers/kvStore.js +48 -0
- package/src/lib/db/helpers/metaStore.js +32 -0
- package/src/lib/db/index.js +473 -0
- package/src/lib/db/migrate.js +267 -0
- package/src/lib/db/migrations/001-initial.js +12 -0
- package/src/lib/db/migrations/002-prune-headroom-pxpipe-settings.js +32 -0
- package/src/lib/db/migrations/004-request-details-trace-id.js +12 -0
- package/src/lib/db/migrations/005-request-details-payload-capture.js +11 -0
- package/src/lib/db/migrations/007-headroom-readd-settings.js +35 -0
- package/src/lib/db/migrations/008-account-model-locks.js +22 -0
- package/src/lib/db/migrations/009-warp-pool-lifecycle.js +5 -0
- package/src/lib/db/migrations/010-api-key-file-permissions.js +7 -0
- package/src/lib/db/migrations/011-remove-upstream-user-agent-profile.js +41 -0
- package/src/lib/db/migrations/012-remove-headroom-settings.js +33 -0
- package/src/lib/db/migrations/013-default-fill-first-routing.js +20 -0
- package/src/lib/db/migrations/014-normalize-fill-first-routing.js +37 -0
- package/src/lib/db/migrations/015-remove-ip-ban-tables.js +8 -0
- package/src/lib/db/migrations/016-prune-legacy-codebuddy-intl-models.js +25 -0
- package/src/lib/db/migrations/index.js +20 -0
- package/src/lib/db/nineRouterMigration.js +785 -0
- package/src/lib/db/paths.js +23 -0
- package/src/lib/db/repos/accountModelLocksRepo.js +74 -0
- package/src/lib/db/repos/aliasRepo.js +108 -0
- package/src/lib/db/repos/apiKeysRepo.js +204 -0
- package/src/lib/db/repos/combosRepo.js +85 -0
- package/src/lib/db/repos/connectionsRepo.js +522 -0
- package/src/lib/db/repos/disabledModelsRepo.js +63 -0
- package/src/lib/db/repos/nodesRepo.js +127 -0
- package/src/lib/db/repos/pricingRepo.js +108 -0
- package/src/lib/db/repos/proxyPoolsRepo.js +104 -0
- package/src/lib/db/repos/requestDetailsRepo.js +345 -0
- package/src/lib/db/repos/settingsRepo.js +135 -0
- package/src/lib/db/repos/usageRepo.js +1335 -0
- package/src/lib/db/schema.js +179 -0
- package/src/lib/db/version.js +32 -0
- package/src/lib/db/writeBehind.js +174 -0
- package/src/lib/disabledModelsDb.js +3 -0
- package/src/lib/env.ts +175 -0
- package/src/lib/errors/publicError.js +18 -0
- package/src/lib/grokBuildConfig.js +243 -0
- package/src/lib/guardRequest.js +51 -0
- package/src/lib/localDb.js +21 -0
- package/src/lib/mcp/stdioSseBridge.js +174 -0
- package/src/lib/network/connectionProxy.js +200 -0
- package/src/lib/network/proxyTest.js +158 -0
- package/src/lib/network/proxyUrl.js +76 -0
- package/src/lib/network/relay.js +71 -0
- package/src/lib/oauth/constants/oauth.js +152 -0
- package/src/lib/oauth/constants/xai.js +43 -0
- package/src/lib/oauth/kiroExternalIdp.js +167 -0
- package/src/lib/oauth/providerHelpers.js +90 -0
- package/src/lib/oauth/providers/_shared.js +12 -0
- package/src/lib/oauth/providers/antigravity.js +126 -0
- package/src/lib/oauth/providers/claude.js +60 -0
- package/src/lib/oauth/providers/cline.js +62 -0
- package/src/lib/oauth/providers/clinepass.js +62 -0
- package/src/lib/oauth/providers/codebuddy-cn.js +75 -0
- package/src/lib/oauth/providers/codebuddy-intl.js +73 -0
- package/src/lib/oauth/providers/codex.js +72 -0
- package/src/lib/oauth/providers/cursor.js +18 -0
- package/src/lib/oauth/providers/gemini-cli.js +84 -0
- package/src/lib/oauth/providers/github.js +96 -0
- package/src/lib/oauth/providers/grok-cli.js +123 -0
- package/src/lib/oauth/providers/index.js +233 -0
- package/src/lib/oauth/providers/kilocode.js +60 -0
- package/src/lib/oauth/providers/kimchi.js +79 -0
- package/src/lib/oauth/providers/kimi.js +79 -0
- package/src/lib/oauth/providers/kiro.js +147 -0
- package/src/lib/oauth/providers/qoder.js +90 -0
- package/src/lib/oauth/providers/trae.js +244 -0
- package/src/lib/oauth/providers/windsurf.js +123 -0
- package/src/lib/oauth/providers/xai.js +95 -0
- package/src/lib/oauth/providers.js +16 -0
- package/src/lib/oauth/services/cursor.js +132 -0
- package/src/lib/oauth/services/kiro.js +351 -0
- package/src/lib/oauth/services/oauth.js +135 -0
- package/src/lib/oauth/services/qoder.js +151 -0
- package/src/lib/oauth/services/xai.js +204 -0
- package/src/lib/oauth/utils/ideDetect.js +55 -0
- package/src/lib/oauth/utils/pkce.js +25 -0
- package/src/lib/oauth/utils/server.js +732 -0
- package/src/lib/oauth/utils/ui.js +43 -0
- package/src/lib/providerNormalization.js +40 -0
- package/src/lib/qoder/constants.js +1 -0
- package/src/lib/requestDetailsDb.js +3 -0
- package/src/lib/resourceProfile.ts +124 -0
- package/src/lib/runtimeSecrets.ts +130 -0
- package/src/lib/security/payloadCapture.js +87 -0
- package/src/lib/tunnel/cloudflare/cloudflared.js +436 -0
- package/src/lib/tunnel/cloudflare/config.js +8 -0
- package/src/lib/tunnel/cloudflare/healthCheck.js +37 -0
- package/src/lib/tunnel/cloudflare/manager.js +149 -0
- package/src/lib/tunnel/cloudflare/pid.js +31 -0
- package/src/lib/tunnel/cloudflare/publicUrl.js +41 -0
- package/src/lib/tunnel/cloudflare/requirements.js +12 -0
- package/src/lib/tunnel/index.js +26 -0
- package/src/lib/tunnel/shared/dnsResolver.js +16 -0
- package/src/lib/tunnel/shared/internetCheck.js +30 -0
- package/src/lib/tunnel/shared/state.js +45 -0
- package/src/lib/tunnel/shared/watchdogConfig.js +6 -0
- package/src/lib/update/installer.js +52 -0
- package/src/lib/update/version.js +116 -0
- package/src/lib/usageDb.js +6 -0
- package/src/lib/usageRefresh.js +88 -0
- package/src/lifecycle/appLifecycle.ts +99 -0
- package/src/models.js +36 -0
- package/src/next/headers.js +12 -0
- package/src/next/server.js +74 -0
- package/src/observability/metrics.js +439 -0
- package/src/observability/tracing.js +107 -0
- package/src/open-sse-index.js +70 -0
- package/src/providers/capabilities.js +299 -0
- package/src/providers/display.ts +142 -0
- package/src/providers/index.js +27 -0
- package/src/providers/models/helpers.js +19 -0
- package/src/providers/models/namePatterns.js +27 -0
- package/src/providers/models/schema.js +32 -0
- package/src/providers/pricing.js +248 -0
- package/src/providers/registry/agentrouter.js +52 -0
- package/src/providers/registry/alicode-intl.js +32 -0
- package/src/providers/registry/alicode.js +33 -0
- package/src/providers/registry/alims-intl.js +30 -0
- package/src/providers/registry/anthropic.js +29 -0
- package/src/providers/registry/antigravity.js +139 -0
- package/src/providers/registry/azure.js +23 -0
- package/src/providers/registry/baidu.js +35 -0
- package/src/providers/registry/blackbox.js +41 -0
- package/src/providers/registry/byteplus.js +36 -0
- package/src/providers/registry/cerebras.js +33 -0
- package/src/providers/registry/chutes.js +26 -0
- package/src/providers/registry/claude.js +80 -0
- package/src/providers/registry/cline.js +53 -0
- package/src/providers/registry/clinepass.js +62 -0
- package/src/providers/registry/cloudflare-ai.js +84 -0
- package/src/providers/registry/codebuddy-cn.js +95 -0
- package/src/providers/registry/codebuddy-intl.js +91 -0
- package/src/providers/registry/codex.js +145 -0
- package/src/providers/registry/commandcode.js +45 -0
- package/src/providers/registry/cursor.js +61 -0
- package/src/providers/registry/deepseek.js +55 -0
- package/src/providers/registry/featherless.js +36 -0
- package/src/providers/registry/fireworks.js +34 -0
- package/src/providers/registry/gemini-cli.js +59 -0
- package/src/providers/registry/gemini.js +76 -0
- package/src/providers/registry/github.js +131 -0
- package/src/providers/registry/glm-cn.js +35 -0
- package/src/providers/registry/glm.js +58 -0
- package/src/providers/registry/grok-cli.js +87 -0
- package/src/providers/registry/grok-web.js +41 -0
- package/src/providers/registry/groq.js +38 -0
- package/src/providers/registry/index.js +77 -0
- package/src/providers/registry/kilo-gateway.js +34 -0
- package/src/providers/registry/kilocode.js +48 -0
- package/src/providers/registry/kimchi.js +49 -0
- package/src/providers/registry/kimi.js +82 -0
- package/src/providers/registry/kiro.js +132 -0
- package/src/providers/registry/meta.js +34 -0
- package/src/providers/registry/minimax-cn.js +90 -0
- package/src/providers/registry/minimax.js +90 -0
- package/src/providers/registry/mistral.js +36 -0
- package/src/providers/registry/morph.js +31 -0
- package/src/providers/registry/nebius.js +26 -0
- package/src/providers/registry/nvidia.js +55 -0
- package/src/providers/registry/ollama-local.js +18 -0
- package/src/providers/registry/ollama.js +38 -0
- package/src/providers/registry/openai.js +114 -0
- package/src/providers/registry/opencode-go.js +41 -0
- package/src/providers/registry/opencode.js +26 -0
- package/src/providers/registry/openrouter.js +36 -0
- package/src/providers/registry/perplexity.js +56 -0
- package/src/providers/registry/poolside.js +30 -0
- package/src/providers/registry/qoder.js +58 -0
- package/src/providers/registry/sumopod.js +84 -0
- package/src/providers/registry/tencent.js +29 -0
- package/src/providers/registry/together.js +38 -0
- package/src/providers/registry/trae.js +71 -0
- package/src/providers/registry/venice.js +69 -0
- package/src/providers/registry/vercel-ai-gateway.js +37 -0
- package/src/providers/registry/vertex-partner.js +31 -0
- package/src/providers/registry/vertex.js +33 -0
- package/src/providers/registry/windsurf.js +129 -0
- package/src/providers/registry/xai.js +46 -0
- package/src/providers/registry/xiaomi-mimo.js +66 -0
- package/src/providers/registry/xiaomi-tokenplan.js +58 -0
- package/src/providers/registryEntry.js +3 -0
- package/src/providers/schema.js +33 -0
- package/src/providers/shared.js +114 -0
- package/src/providers/thinkingLevels.js +49 -0
- package/src/routes/api/auth/login/route.js +82 -0
- package/src/routes/api/auth/logout/route.js +9 -0
- package/src/routes/api/auth/reset-password/route.js +12 -0
- package/src/routes/api/auth/status/route.js +33 -0
- package/src/routes/api/auth/verify-password/route.js +39 -0
- package/src/routes/api/chat/tools/curl/route.js +100 -0
- package/src/routes/api/chat/tools/router/route.js +215 -0
- package/src/routes/api/chat/tools/search/route.js +362 -0
- package/src/routes/api/chat/tools/shell/route.js +228 -0
- package/src/routes/api/cli-tools/all-statuses/route.js +37 -0
- package/src/routes/api/cli-tools/claude-settings/route.js +261 -0
- package/src/routes/api/cli-tools/codex-settings/route.js +220 -0
- package/src/routes/api/cli-tools/cowork-mcp-registry/route.js +80 -0
- package/src/routes/api/cli-tools/cowork-mcp-tools/route.js +96 -0
- package/src/routes/api/cli-tools/cowork-settings/route.js +380 -0
- package/src/routes/api/cli-tools/grok-build-settings/route.js +152 -0
- package/src/routes/api/cli-tools/hermes-settings/route.js +169 -0
- package/src/routes/api/cli-tools/kilo-settings/route.js +131 -0
- package/src/routes/api/cli-tools/model-mappings/route.js +43 -0
- package/src/routes/api/cli-tools/omp-settings/route.js +266 -0
- package/src/routes/api/cli-tools/opencode-settings/route.js +243 -0
- package/src/routes/api/combos/[id]/route.js +73 -0
- package/src/routes/api/combos/route.js +43 -0
- package/src/routes/api/health/live/route.js +7 -0
- package/src/routes/api/health/ready/route.js +19 -0
- package/src/routes/api/health/route.js +17 -0
- package/src/routes/api/inflight/stream/route.js +24 -0
- package/src/routes/api/init/route.js +3 -0
- package/src/routes/api/keys/[id]/route.js +71 -0
- package/src/routes/api/keys/route.js +41 -0
- package/src/routes/api/logs/route.js +19 -0
- package/src/routes/api/mcp/[plugin]/message/route.js +23 -0
- package/src/routes/api/mcp/[plugin]/sse/route.js +35 -0
- package/src/routes/api/models/availability/route.js +104 -0
- package/src/routes/api/models/custom/route.js +58 -0
- package/src/routes/api/models/disabled/route.js +47 -0
- package/src/routes/api/models/route.js +64 -0
- package/src/routes/api/models/test/ping.js +236 -0
- package/src/routes/api/models/test/route.js +14 -0
- package/src/routes/api/oauth/[provider]/[action]/route.js +491 -0
- package/src/routes/api/oauth/codex/bulk-import/route.js +105 -0
- package/src/routes/api/oauth/codex/import-token/route.js +82 -0
- package/src/routes/api/oauth/cursor/auto-import/route.js +250 -0
- package/src/routes/api/oauth/cursor/import/route.js +86 -0
- package/src/routes/api/oauth/kiro/api-key/route.js +60 -0
- package/src/routes/api/oauth/kiro/auto-import/route.js +120 -0
- package/src/routes/api/oauth/kiro/import/route.js +72 -0
- package/src/routes/api/oauth/kiro/import-cli-proxy/route.js +42 -0
- package/src/routes/api/oauth/kiro/social-authorize/route.js +40 -0
- package/src/routes/api/oauth/kiro/social-exchange/route.js +62 -0
- package/src/routes/api/pricing/route.js +96 -0
- package/src/routes/api/provider-nodes/[id]/route.js +106 -0
- package/src/routes/api/provider-nodes/route.js +110 -0
- package/src/routes/api/provider-nodes/validate/route.js +197 -0
- package/src/routes/api/providers/[id]/models/route.js +716 -0
- package/src/routes/api/providers/[id]/route.js +195 -0
- package/src/routes/api/providers/[id]/test/route.js +27 -0
- package/src/routes/api/providers/[id]/test/testUtils.js +912 -0
- package/src/routes/api/providers/[id]/test-models/route.js +211 -0
- package/src/routes/api/providers/catalog/route.js +58 -0
- package/src/routes/api/providers/client/route.js +133 -0
- package/src/routes/api/providers/counts/route.js +43 -0
- package/src/routes/api/providers/kilo/free-models/route.js +58 -0
- package/src/routes/api/providers/route.js +361 -0
- package/src/routes/api/providers/suggested-models/filters.js +24 -0
- package/src/routes/api/providers/suggested-models/route.js +34 -0
- package/src/routes/api/providers/test-batch/route.js +145 -0
- package/src/routes/api/providers/validate/route.js +633 -0
- package/src/routes/api/proxy-pools/[id]/route.js +129 -0
- package/src/routes/api/proxy-pools/[id]/test/route.js +64 -0
- package/src/routes/api/proxy-pools/cloudflare-deploy/route.js +183 -0
- package/src/routes/api/proxy-pools/route.js +85 -0
- package/src/routes/api/proxy-pools/vercel-deploy/route.js +181 -0
- package/src/routes/api/settings/currency/route.js +29 -0
- package/src/routes/api/settings/database/path/route.js +8 -0
- package/src/routes/api/settings/database/route.js +89 -0
- package/src/routes/api/settings/migrate-9router/route.js +81 -0
- package/src/routes/api/settings/require-login/route.js +14 -0
- package/src/routes/api/settings/route.js +186 -0
- package/src/routes/api/shutdown/route.js +25 -0
- package/src/routes/api/tags/route.js +17 -0
- package/src/routes/api/translator/console-logs/route.js +28 -0
- package/src/routes/api/translator/console-logs/stream/route.js +95 -0
- package/src/routes/api/tunnel/disable/route.js +18 -0
- package/src/routes/api/tunnel/enable/route.js +32 -0
- package/src/routes/api/tunnel/status/route.js +23 -0
- package/src/routes/api/update/route.js +42 -0
- package/src/routes/api/usage/[connectionId]/codex-reset-credits/route.js +169 -0
- package/src/routes/api/usage/[connectionId]/route.js +222 -0
- package/src/routes/api/usage/chart/route.js +27 -0
- package/src/routes/api/usage/history/route.js +94 -0
- package/src/routes/api/usage/logs/route.js +14 -0
- package/src/routes/api/usage/providers/route.js +36 -0
- package/src/routes/api/usage/request-details/route.js +61 -0
- package/src/routes/api/usage/request-logs/route.js +15 -0
- package/src/routes/api/usage/stats/route.js +23 -0
- package/src/routes/api/usage/stream/route.js +78 -0
- package/src/routes/api/v1/api/chat/route.js +36 -0
- package/src/routes/api/v1/chat/completions/route.js +28 -0
- package/src/routes/api/v1/images/edits/route.js +70 -0
- package/src/routes/api/v1/images/generations/route.js +50 -0
- package/src/routes/api/v1/images/imageValidation.js +45 -0
- package/src/routes/api/v1/messages/count_tokens/route.js +87 -0
- package/src/routes/api/v1/messages/route.js +26 -0
- package/src/routes/api/v1/models/route.js +440 -0
- package/src/routes/api/v1/responses/compact/route.js +34 -0
- package/src/routes/api/v1/responses/route.js +26 -0
- package/src/routes/api/v1/route.js +1 -0
- package/src/routes/api/version/route.js +11 -0
- package/src/routes/table.js +1141 -0
- package/src/rtk/applyFilter.js +13 -0
- package/src/rtk/autodetect.js +104 -0
- package/src/rtk/caveman.js +6 -0
- package/src/rtk/cavemanPrompts.js +107 -0
- package/src/rtk/constants.js +51 -0
- package/src/rtk/filters/buildOutput.js +120 -0
- package/src/rtk/filters/dedupLog.js +43 -0
- package/src/rtk/filters/find.js +47 -0
- package/src/rtk/filters/gitDiff.js +90 -0
- package/src/rtk/filters/gitLog.js +88 -0
- package/src/rtk/filters/gitStatus.js +101 -0
- package/src/rtk/filters/grep.js +45 -0
- package/src/rtk/filters/ls.js +73 -0
- package/src/rtk/filters/readNumbered.js +22 -0
- package/src/rtk/filters/searchList.js +49 -0
- package/src/rtk/filters/smartTruncate.js +13 -0
- package/src/rtk/filters/tree.js +28 -0
- package/src/rtk/index.js +143 -0
- package/src/rtk/ponytail.js +6 -0
- package/src/rtk/ponytailPrompt.js +49 -0
- package/src/rtk/systemInject.js +89 -0
- package/src/server.ts +474 -0
- package/src/services/accountFallback.js +241 -0
- package/src/services/accountPool.js +389 -0
- package/src/services/capacityAdapter.js +140 -0
- package/src/services/cliModelMapping.js +84 -0
- package/src/services/clinepassModels.js +60 -0
- package/src/services/codebuddyModels.js +250 -0
- package/src/services/combo.js +482 -0
- package/src/services/copilotModels.js +126 -0
- package/src/services/currencyRate.js +56 -0
- package/src/services/cursorModels.js +197 -0
- package/src/services/grokCliModels.js +130 -0
- package/src/services/kimchiModels.js +175 -0
- package/src/services/kiroModels.js +246 -0
- package/src/services/model.js +83 -0
- package/src/services/oauthCredentialManager.js +153 -0
- package/src/services/projectId.js +240 -0
- package/src/services/provider.js +145 -0
- package/src/services/qoderModels.js +274 -0
- package/src/services/tokenRefresh/dedup.js +70 -0
- package/src/services/tokenRefresh/providers.js +626 -0
- package/src/services/tokenRefresh.js +274 -0
- package/src/services/usage/claude.js +134 -0
- package/src/services/usage/codebuddy-cn.js +212 -0
- package/src/services/usage/codex.js +193 -0
- package/src/services/usage/deepseek.js +103 -0
- package/src/services/usage/github.js +94 -0
- package/src/services/usage/google.js +218 -0
- package/src/services/usage/grok-cli.js +368 -0
- package/src/services/usage/grokCliQuotaFrame.js +170 -0
- package/src/services/usage/kimi.js +185 -0
- package/src/services/usage/kiro.js +172 -0
- package/src/services/usage/minimax.js +215 -0
- package/src/services/usage/misc.js +264 -0
- package/src/services/usage/shared.js +59 -0
- package/src/services/usage.js +56 -0
- package/src/shared/clineAuth.js +37 -0
- package/src/shared/constants/config.js +80 -0
- package/src/shared/constants/coworkPlugins.js +69 -0
- package/src/shared/constants/models.js +41 -0
- package/src/shared/constants/providers.js +128 -0
- package/src/shared/constants/providersDisplay.js +1 -0
- package/src/shared/qoder/constants.js +50 -0
- package/src/shared/qoder/cosy.js +134 -0
- package/src/shared/qoder/encoding.js +36 -0
- package/src/shared/services/initializeApp.js +226 -0
- package/src/shared/services/quotaAutoPing.js +310 -0
- package/src/shared/utils/apiKey.js +65 -0
- package/src/shared/utils/clineAuth.js +1 -0
- package/src/shared/utils/index.js +3 -0
- package/src/shared/utils/machineId.js +60 -0
- package/src/shared/utils/ssrfGuard.js +280 -0
- package/src/sse/handlers/chat.js +426 -0
- package/src/sse/oauthLease.js +32 -0
- package/src/sse/recovery.js +235 -0
- package/src/sse/services/auth.js +489 -0
- package/src/sse/services/backgroundTokenRefresh.js +173 -0
- package/src/sse/services/model.js +129 -0
- package/src/sse/services/requestCancellation.js +4 -0
- package/src/sse/services/tokenRefresh.js +264 -0
- package/src/sse/utils/logger.js +142 -0
- package/src/staticServe.ts +95 -0
- package/src/transformer/streamToJsonConverter.js +87 -0
- package/src/translator/canonical.js +81 -0
- package/src/translator/concerns/chunk.js +9 -0
- package/src/translator/concerns/compatFallback.js +147 -0
- package/src/translator/concerns/finishReason.js +59 -0
- package/src/translator/concerns/image.js +105 -0
- package/src/translator/concerns/json.js +4 -0
- package/src/translator/concerns/kiroConversation.js +428 -0
- package/src/translator/concerns/message.js +5 -0
- package/src/translator/concerns/modality.js +134 -0
- package/src/translator/concerns/paramSupport.js +97 -0
- package/src/translator/concerns/prefetch.js +86 -0
- package/src/translator/concerns/reasoning.js +18 -0
- package/src/translator/concerns/thinking.js +40 -0
- package/src/translator/concerns/thinkingUnified.js +319 -0
- package/src/translator/concerns/toolCall.js +134 -0
- package/src/translator/concerns/usage.js +61 -0
- package/src/translator/detection.js +42 -0
- package/src/translator/formats/claude.js +323 -0
- package/src/translator/formats/gemini.js +366 -0
- package/src/translator/formats/maxTokens.js +19 -0
- package/src/translator/formats/openai.js +116 -0
- package/src/translator/formats/responsesApi.js +117 -0
- package/src/translator/formats.js +28 -0
- package/src/translator/index.js +237 -0
- package/src/translator/request/antigravity-to-openai.js +217 -0
- package/src/translator/request/claude-to-kiro.js +288 -0
- package/src/translator/request/claude-to-openai.js +199 -0
- package/src/translator/request/gemini-to-openai.js +142 -0
- package/src/translator/request/openai-responses.js +373 -0
- package/src/translator/request/openai-to-claude.js +260 -0
- package/src/translator/request/openai-to-commandcode.js +161 -0
- package/src/translator/request/openai-to-cursor.js +175 -0
- package/src/translator/request/openai-to-gemini.js +422 -0
- package/src/translator/request/openai-to-kiro.js +360 -0
- package/src/translator/request/openai-to-ollama.js +152 -0
- package/src/translator/request/openai-to-vertex.js +36 -0
- package/src/translator/response/claude-to-openai.js +185 -0
- package/src/translator/response/commandcode-to-openai.js +164 -0
- package/src/translator/response/cursor-to-openai.js +18 -0
- package/src/translator/response/gemini-to-openai.js +127 -0
- package/src/translator/response/kiro-to-claude.js +230 -0
- package/src/translator/response/kiro-to-openai.js +136 -0
- package/src/translator/response/ollama-to-openai.js +106 -0
- package/src/translator/response/openai-responses.js +534 -0
- package/src/translator/response/openai-to-antigravity.js +107 -0
- package/src/translator/response/openai-to-claude.js +231 -0
- package/src/translator/schema/blocks.js +40 -0
- package/src/translator/schema/defaults.js +3 -0
- package/src/translator/schema/finishReasons.js +22 -0
- package/src/translator/schema/index.js +7 -0
- package/src/translator/schema/roles.js +12 -0
- package/src/transport/requestBoundary.ts +223 -0
- package/src/transport/routerAdmission.ts +380 -0
- package/src/types/provider.ts +59 -0
- package/src/utils/bypassHandler.js +272 -0
- package/src/utils/claudeCloaking.js +10 -0
- package/src/utils/claudeSignature.js +35 -0
- package/src/utils/clientDetector.js +183 -0
- package/src/utils/cursorChecksum.js +104 -0
- package/src/utils/cursorProtobuf.js +801 -0
- package/src/utils/debugLog.js +12 -0
- package/src/utils/error.js +120 -0
- package/src/utils/inflight.js +127 -0
- package/src/utils/kiroSessionReplay.js +139 -0
- package/src/utils/ollamaTransform.js +83 -0
- package/src/utils/proxyFetch.js +308 -0
- package/src/utils/reasoningContentInjector.js +71 -0
- package/src/utils/requestLogger.js +272 -0
- package/src/utils/responsesStreamHelpers.js +46 -0
- package/src/utils/sessionManager.js +205 -0
- package/src/utils/sse.js +13 -0
- package/src/utils/sseConstants.js +21 -0
- package/src/utils/stream.js +511 -0
- package/src/utils/streamHandler.js +256 -0
- package/src/utils/streamHelpers.js +113 -0
- package/src/utils/toolDeduper.js +44 -0
- package/src/utils/usageTracking.js +329 -0
- package/tsconfig.json +45 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { getComboByName, getCustomModels, getProviderNodes } from "@/lib/localDb";
|
|
2
|
+
import { parseModel as parseModelCore, getModelInfoCore } from "../../services/model.js";
|
|
3
|
+
import REGISTRY from "../../providers/registry/index.js";
|
|
4
|
+
|
|
5
|
+
const LOCAL_PROVIDER_ALIASES = {
|
|
6
|
+
xmtp: "xiaomi-tokenplan",
|
|
7
|
+
"xiaomi-tokenplan": "xiaomi-tokenplan",
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const RESERVED_PROVIDER_PREFIXES = new Set(Object.keys(LOCAL_PROVIDER_ALIASES));
|
|
11
|
+
for (const entry of REGISTRY) {
|
|
12
|
+
RESERVED_PROVIDER_PREFIXES.add(entry.id);
|
|
13
|
+
if (entry.alias) RESERVED_PROVIDER_PREFIXES.add(entry.alias);
|
|
14
|
+
for (const alias of entry.aliases || []) RESERVED_PROVIDER_PREFIXES.add(alias);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function parseModel(modelStr) {
|
|
18
|
+
const parsed = parseModelCore(modelStr);
|
|
19
|
+
if (parsed?.providerAlias && LOCAL_PROVIDER_ALIASES[parsed.providerAlias]) {
|
|
20
|
+
return { ...parsed, provider: LOCAL_PROVIDER_ALIASES[parsed.providerAlias] };
|
|
21
|
+
}
|
|
22
|
+
return parsed;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function normalizeModelKey(value) {
|
|
26
|
+
return String(value || "")
|
|
27
|
+
.trim()
|
|
28
|
+
.replace(/^(?:clinepass|cline-pass)\//i, "")
|
|
29
|
+
.toLowerCase();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function getCustomModelCapabilities(providerAlias, provider, model) {
|
|
33
|
+
try {
|
|
34
|
+
const aliases = new Set(
|
|
35
|
+
[providerAlias, provider]
|
|
36
|
+
.filter(Boolean)
|
|
37
|
+
.map((value) => String(value).trim().toLowerCase()),
|
|
38
|
+
);
|
|
39
|
+
if (aliases.size === 0) return null;
|
|
40
|
+
|
|
41
|
+
const customModels = await getCustomModels();
|
|
42
|
+
const match = customModels.find((entry) => (
|
|
43
|
+
aliases.has(String(entry?.providerAlias || "").trim().toLowerCase()) &&
|
|
44
|
+
normalizeModelKey(entry?.id) === normalizeModelKey(model)
|
|
45
|
+
));
|
|
46
|
+
return match?.capabilities && typeof match.capabilities === "object"
|
|
47
|
+
? match.capabilities
|
|
48
|
+
: null;
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function buildModelInfo({ providerAlias, provider, model }) {
|
|
55
|
+
const capabilities = await getCustomModelCapabilities(providerAlias, provider, model);
|
|
56
|
+
return {
|
|
57
|
+
provider,
|
|
58
|
+
model,
|
|
59
|
+
...(capabilities ? { modelCapabilities: capabilities } : {}),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function getModelInfo(modelStr) {
|
|
64
|
+
const parsed = parseModel(modelStr);
|
|
65
|
+
|
|
66
|
+
if (!parsed.isAlias) {
|
|
67
|
+
|
|
68
|
+
if (!RESERVED_PROVIDER_PREFIXES.has(parsed.providerAlias)) {
|
|
69
|
+
const openaiNodes = await getProviderNodes({ type: "openai-compatible" });
|
|
70
|
+
const matchedOpenAI = openaiNodes.find((node) => node.prefix === parsed.providerAlias);
|
|
71
|
+
if (matchedOpenAI) {
|
|
72
|
+
return buildModelInfo({
|
|
73
|
+
providerAlias: parsed.providerAlias,
|
|
74
|
+
provider: matchedOpenAI.id,
|
|
75
|
+
model: parsed.model,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const anthropicNodes = await getProviderNodes({ type: "anthropic-compatible" });
|
|
80
|
+
const matchedAnthropic = anthropicNodes.find((node) => node.prefix === parsed.providerAlias);
|
|
81
|
+
if (matchedAnthropic) {
|
|
82
|
+
return buildModelInfo({
|
|
83
|
+
providerAlias: parsed.providerAlias,
|
|
84
|
+
provider: matchedAnthropic.id,
|
|
85
|
+
model: parsed.model,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const embeddingNodes = await getProviderNodes({ type: "custom-embedding" });
|
|
90
|
+
const matchedEmbedding = embeddingNodes.find((node) => node.prefix === parsed.providerAlias);
|
|
91
|
+
if (matchedEmbedding) {
|
|
92
|
+
return buildModelInfo({
|
|
93
|
+
providerAlias: parsed.providerAlias,
|
|
94
|
+
provider: matchedEmbedding.id,
|
|
95
|
+
model: parsed.model,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return buildModelInfo({
|
|
100
|
+
providerAlias: parsed.providerAlias,
|
|
101
|
+
provider: parsed.provider,
|
|
102
|
+
model: parsed.model,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const combo = await getComboByName(parsed.model);
|
|
107
|
+
if (combo) {
|
|
108
|
+
|
|
109
|
+
return { provider: null, model: parsed.model };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const info = await getModelInfoCore(modelStr);
|
|
113
|
+
return buildModelInfo({
|
|
114
|
+
providerAlias: parsed.providerAlias || info.provider,
|
|
115
|
+
provider: info.provider,
|
|
116
|
+
model: info.model,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export async function getComboModels(modelStr) {
|
|
121
|
+
|
|
122
|
+
if (modelStr.includes("/")) return null;
|
|
123
|
+
|
|
124
|
+
const combo = await getComboByName(modelStr);
|
|
125
|
+
if (combo && combo.models && combo.models.length > 0) {
|
|
126
|
+
return combo.models;
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import * as log from "../utils/logger.js";
|
|
2
|
+
import { updateProviderConnection } from "../../lib/localDb.js";
|
|
3
|
+
import {
|
|
4
|
+
getProjectIdForConnection,
|
|
5
|
+
invalidateProjectId,
|
|
6
|
+
removeConnection,
|
|
7
|
+
} from "../../services/projectId.js";
|
|
8
|
+
import {
|
|
9
|
+
TOKEN_EXPIRY_BUFFER_MS as BUFFER_MS,
|
|
10
|
+
refreshAccessToken as _refreshAccessToken,
|
|
11
|
+
refreshClaudeOAuthToken as _refreshClaudeOAuthToken,
|
|
12
|
+
refreshGoogleToken as _refreshGoogleToken,
|
|
13
|
+
refreshCodexToken as _refreshCodexToken,
|
|
14
|
+
refreshGitHubToken as _refreshGitHubToken,
|
|
15
|
+
refreshCopilotToken as _refreshCopilotToken,
|
|
16
|
+
getAccessToken as _getAccessToken,
|
|
17
|
+
refreshTokenByProvider as _refreshTokenByProvider,
|
|
18
|
+
formatProviderCredentials as _formatProviderCredentials,
|
|
19
|
+
getAllAccessTokens as _getAllAccessTokens,
|
|
20
|
+
refreshKiroToken as _refreshKiroToken,
|
|
21
|
+
getRefreshLeadMs as _getRefreshLeadMs
|
|
22
|
+
} from "../../services/tokenRefresh.js";
|
|
23
|
+
import {
|
|
24
|
+
refreshProviderCredentials as _refreshProviderCredentials,
|
|
25
|
+
shouldRefreshCredentials as _shouldRefreshCredentials,
|
|
26
|
+
} from "../../services/oauthCredentialManager.js";
|
|
27
|
+
|
|
28
|
+
export const TOKEN_EXPIRY_BUFFER_MS = BUFFER_MS;
|
|
29
|
+
|
|
30
|
+
export const refreshAccessToken = (provider, refreshToken, credentials) =>
|
|
31
|
+
_refreshAccessToken(provider, refreshToken, credentials, log);
|
|
32
|
+
|
|
33
|
+
export const refreshClaudeOAuthToken = (refreshToken) =>
|
|
34
|
+
_refreshClaudeOAuthToken(refreshToken, log);
|
|
35
|
+
|
|
36
|
+
export const refreshGoogleToken = (refreshToken, clientId, clientSecret) =>
|
|
37
|
+
_refreshGoogleToken(refreshToken, clientId, clientSecret, log);
|
|
38
|
+
|
|
39
|
+
export const refreshCodexToken = (refreshToken) =>
|
|
40
|
+
_refreshCodexToken(refreshToken, log);
|
|
41
|
+
|
|
42
|
+
export const refreshGitHubToken = (refreshToken) =>
|
|
43
|
+
_refreshGitHubToken(refreshToken, log);
|
|
44
|
+
|
|
45
|
+
export const refreshCopilotToken = (githubAccessToken) =>
|
|
46
|
+
_refreshCopilotToken(githubAccessToken, log);
|
|
47
|
+
|
|
48
|
+
export const refreshKiroToken = (refreshToken, providerSpecificData) =>
|
|
49
|
+
_refreshKiroToken(refreshToken, providerSpecificData, log);
|
|
50
|
+
|
|
51
|
+
export const getAccessToken = (provider, credentials) =>
|
|
52
|
+
_getAccessToken(provider, credentials, log);
|
|
53
|
+
|
|
54
|
+
export const refreshTokenByProvider = (provider, credentials) =>
|
|
55
|
+
_refreshTokenByProvider(provider, credentials, log);
|
|
56
|
+
|
|
57
|
+
export const formatProviderCredentials = (provider, credentials) =>
|
|
58
|
+
_formatProviderCredentials(provider, credentials, log);
|
|
59
|
+
|
|
60
|
+
export const getAllAccessTokens = (userInfo) =>
|
|
61
|
+
_getAllAccessTokens(userInfo, log);
|
|
62
|
+
|
|
63
|
+
export const shouldRefreshCredentials = (provider, credentials) =>
|
|
64
|
+
_shouldRefreshCredentials(provider, credentials);
|
|
65
|
+
|
|
66
|
+
export function releaseConnection(connectionId) {
|
|
67
|
+
if (!connectionId) return;
|
|
68
|
+
removeConnection(connectionId);
|
|
69
|
+
log.debug("TOKEN_REFRESH", "Released connection resources", { connectionId });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function toExpiresAt(expiresIn) {
|
|
73
|
+
return new Date(Date.now() + expiresIn * 1000).toISOString();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function normalizeExpiresAt(expiresAt) {
|
|
77
|
+
if (!expiresAt) return null;
|
|
78
|
+
const date = new Date(expiresAt);
|
|
79
|
+
if (!Number.isFinite(date.getTime())) return null;
|
|
80
|
+
return date.toISOString();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function needsProjectId(provider) {
|
|
84
|
+
return provider === "antigravity" || provider === "gemini-cli";
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function _refreshProjectId(provider, connectionId, accessToken) {
|
|
88
|
+
if (!needsProjectId(provider) || !connectionId || !accessToken) return;
|
|
89
|
+
|
|
90
|
+
invalidateProjectId(connectionId);
|
|
91
|
+
|
|
92
|
+
getProjectIdForConnection(connectionId, accessToken)
|
|
93
|
+
.then((projectId) => {
|
|
94
|
+
if (!projectId) return;
|
|
95
|
+
updateProviderCredentials(connectionId, { projectId }).catch((err) => {
|
|
96
|
+
log.debug("TOKEN_REFRESH", "Failed to persist refreshed projectId", {
|
|
97
|
+
connectionId,
|
|
98
|
+
error: err?.message ?? err,
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
})
|
|
102
|
+
.catch((err) => {
|
|
103
|
+
log.debug("TOKEN_REFRESH", "Failed to fetch projectId after token refresh", {
|
|
104
|
+
connectionId,
|
|
105
|
+
error: err?.message ?? err,
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export async function updateProviderCredentials(connectionId, newCredentials) {
|
|
111
|
+
try {
|
|
112
|
+
const updates = {};
|
|
113
|
+
|
|
114
|
+
if (newCredentials.accessToken) updates.accessToken = newCredentials.accessToken;
|
|
115
|
+
if (newCredentials.refreshToken) updates.refreshToken = newCredentials.refreshToken;
|
|
116
|
+
if (newCredentials.idToken) updates.idToken = newCredentials.idToken;
|
|
117
|
+
if (newCredentials.lastRefreshAt) updates.lastRefreshAt = newCredentials.lastRefreshAt;
|
|
118
|
+
if (newCredentials.expiresAt) updates.expiresAt = newCredentials.expiresAt;
|
|
119
|
+
if (newCredentials.expiresIn) {
|
|
120
|
+
updates.expiresAt = toExpiresAt(newCredentials.expiresIn);
|
|
121
|
+
updates.expiresIn = newCredentials.expiresIn;
|
|
122
|
+
} else if (newCredentials.expiresAt) {
|
|
123
|
+
const expiresAt = normalizeExpiresAt(newCredentials.expiresAt);
|
|
124
|
+
if (expiresAt) {
|
|
125
|
+
updates.expiresAt = expiresAt;
|
|
126
|
+
updates.expiresIn = Math.max(1, Math.floor((new Date(expiresAt).getTime() - Date.now()) / 1000));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (newCredentials.providerSpecificData) {
|
|
130
|
+
updates.providerSpecificData = {
|
|
131
|
+
...(newCredentials.existingProviderSpecificData || {}),
|
|
132
|
+
...newCredentials.providerSpecificData,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
if (newCredentials.copilotToken || newCredentials.copilotTokenExpiresAt) {
|
|
136
|
+
updates.providerSpecificData = {
|
|
137
|
+
...(updates.providerSpecificData || newCredentials.existingProviderSpecificData || {}),
|
|
138
|
+
...(newCredentials.copilotToken ? { copilotToken: newCredentials.copilotToken } : {}),
|
|
139
|
+
...(newCredentials.copilotTokenExpiresAt ? { copilotTokenExpiresAt: newCredentials.copilotTokenExpiresAt } : {}),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
if (newCredentials.projectId) updates.projectId = newCredentials.projectId;
|
|
143
|
+
if (Object.prototype.hasOwnProperty.call(newCredentials, "testStatus")) {
|
|
144
|
+
updates.testStatus = newCredentials.testStatus;
|
|
145
|
+
}
|
|
146
|
+
if (Object.prototype.hasOwnProperty.call(newCredentials, "lastError")) {
|
|
147
|
+
updates.lastError = newCredentials.lastError;
|
|
148
|
+
}
|
|
149
|
+
if (Object.prototype.hasOwnProperty.call(newCredentials, "lastErrorAt")) {
|
|
150
|
+
updates.lastErrorAt = newCredentials.lastErrorAt;
|
|
151
|
+
}
|
|
152
|
+
if (Object.prototype.hasOwnProperty.call(newCredentials, "errorCode")) {
|
|
153
|
+
updates.errorCode = newCredentials.errorCode;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const result = await updateProviderConnection(connectionId, updates);
|
|
157
|
+
log.info("TOKEN_REFRESH", "Credentials updated in localDb", {
|
|
158
|
+
connectionId,
|
|
159
|
+
success: !!result
|
|
160
|
+
});
|
|
161
|
+
return !!result;
|
|
162
|
+
} catch (error) {
|
|
163
|
+
log.error("TOKEN_REFRESH", "Error updating credentials in localDb", {
|
|
164
|
+
connectionId,
|
|
165
|
+
error: error.message,
|
|
166
|
+
});
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export async function checkAndRefreshToken(provider, credentials, options = {}) {
|
|
172
|
+
let creds = { ...credentials };
|
|
173
|
+
if (!creds.connectionId && creds.id) {
|
|
174
|
+
creds.connectionId = creds.id;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const force = options?.force === true;
|
|
178
|
+
|
|
179
|
+
if (force || _shouldRefreshCredentials(provider, creds)) {
|
|
180
|
+
const expiresAt = creds.expiresAt ? new Date(creds.expiresAt).getTime() : null;
|
|
181
|
+
const remaining = expiresAt ? expiresAt - Date.now() : null;
|
|
182
|
+
const refreshLead = _getRefreshLeadMs(provider);
|
|
183
|
+
|
|
184
|
+
log.info("TOKEN_REFRESH", "Refreshing provider credentials proactively", {
|
|
185
|
+
provider,
|
|
186
|
+
expiresIn: remaining === null ? null : Math.round(remaining / 1000),
|
|
187
|
+
refreshLeadMs: refreshLead,
|
|
188
|
+
lastRefreshAt: creds.lastRefreshAt || null,
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const newCreds = await _refreshProviderCredentials(provider, creds, log);
|
|
192
|
+
if (newCreds?.accessToken || newCreds?.apiKey || newCreds?.copilotToken) {
|
|
193
|
+
const mergedCreds = {
|
|
194
|
+
...newCreds,
|
|
195
|
+
existingProviderSpecificData: creds.providerSpecificData,
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
await updateProviderCredentials(creds.connectionId, mergedCreds);
|
|
199
|
+
|
|
200
|
+
creds = {
|
|
201
|
+
...creds,
|
|
202
|
+
...newCreds,
|
|
203
|
+
expiresAt: newCreds.expiresIn
|
|
204
|
+
? toExpiresAt(newCreds.expiresIn)
|
|
205
|
+
: normalizeExpiresAt(newCreds.expiresAt) || newCreds.expiresAt || creds.expiresAt,
|
|
206
|
+
providerSpecificData: newCreds.providerSpecificData
|
|
207
|
+
? { ...creds.providerSpecificData, ...newCreds.providerSpecificData }
|
|
208
|
+
: creds.providerSpecificData,
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
_refreshProjectId(provider, creds.connectionId, creds.accessToken);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (provider === "github") {
|
|
216
|
+
const copilotToken = creds.providerSpecificData?.copilotToken;
|
|
217
|
+
const copilotExpiresAt = creds.providerSpecificData?.copilotTokenExpiresAt
|
|
218
|
+
? creds.providerSpecificData.copilotTokenExpiresAt * 1000
|
|
219
|
+
: 0;
|
|
220
|
+
const now = Date.now();
|
|
221
|
+
const remaining = copilotExpiresAt - now;
|
|
222
|
+
|
|
223
|
+
if (!copilotToken || remaining < TOKEN_EXPIRY_BUFFER_MS) {
|
|
224
|
+
log.info("TOKEN_REFRESH", "Copilot token expiring soon or missing, refreshing proactively", {
|
|
225
|
+
provider,
|
|
226
|
+
expiresIn: copilotToken ? Math.round(remaining / 1000) : "missing",
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
const copilotTokenResult = await refreshCopilotToken(creds.accessToken);
|
|
230
|
+
if (copilotTokenResult) {
|
|
231
|
+
const updatedSpecific = {
|
|
232
|
+
...creds.providerSpecificData,
|
|
233
|
+
copilotToken: copilotTokenResult.token,
|
|
234
|
+
copilotTokenExpiresAt: copilotTokenResult.expiresAt,
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
await updateProviderCredentials(creds.connectionId, {
|
|
238
|
+
providerSpecificData: updatedSpecific,
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
creds.providerSpecificData = updatedSpecific;
|
|
242
|
+
creds.copilotToken = copilotTokenResult.token;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return creds;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export async function refreshGitHubAndCopilotTokens(credentials) {
|
|
251
|
+
const newGitHubCreds = await refreshGitHubToken(credentials.refreshToken);
|
|
252
|
+
if (!newGitHubCreds?.accessToken) return newGitHubCreds;
|
|
253
|
+
|
|
254
|
+
const copilotToken = await refreshCopilotToken(newGitHubCreds.accessToken);
|
|
255
|
+
if (!copilotToken) return newGitHubCreds;
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
...newGitHubCreds,
|
|
259
|
+
providerSpecificData: {
|
|
260
|
+
copilotToken: copilotToken.token,
|
|
261
|
+
copilotTokenExpiresAt: copilotToken.expiresAt,
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
const LOG_LEVELS = {
|
|
2
|
+
DEBUG: 0,
|
|
3
|
+
INFO: 1,
|
|
4
|
+
WARN: 2,
|
|
5
|
+
ERROR: 3
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const LEVEL = LOG_LEVELS[process.env.LOG_LEVEL?.toUpperCase?.()] ?? LOG_LEVELS.INFO;
|
|
9
|
+
const ANSI = {
|
|
10
|
+
reset: "\x1b[0m",
|
|
11
|
+
dim: "\x1b[2m",
|
|
12
|
+
cyan: "\x1b[36m",
|
|
13
|
+
green: "\x1b[32m",
|
|
14
|
+
yellow: "\x1b[33m",
|
|
15
|
+
red: "\x1b[31m",
|
|
16
|
+
magenta: "\x1b[35m",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const USE_COLOR = process.env.NO_COLOR === undefined
|
|
20
|
+
&& (process.env.FORCE_COLOR === "1" || process.stdout?.isTTY === true);
|
|
21
|
+
|
|
22
|
+
function color(value, code) {
|
|
23
|
+
return USE_COLOR ? `${code}${value}${ANSI.reset}` : value;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function formatTime() {
|
|
27
|
+
return new Date().toLocaleTimeString("en-US", { hour12: false });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function formatLine(tag, label, message) {
|
|
31
|
+
const tagText = tag ? color(tag, ANSI.cyan) : "--";
|
|
32
|
+
const labelColors = {
|
|
33
|
+
START: ANSI.green,
|
|
34
|
+
FETCH: ANSI.cyan,
|
|
35
|
+
RESPONSE: ANSI.green,
|
|
36
|
+
RETRY: ANSI.yellow,
|
|
37
|
+
DONE: ANSI.green,
|
|
38
|
+
WARN: ANSI.yellow,
|
|
39
|
+
ERROR: ANSI.red,
|
|
40
|
+
FALLBACK: ANSI.magenta,
|
|
41
|
+
LOCK: ANSI.yellow,
|
|
42
|
+
DEBUG: ANSI.dim,
|
|
43
|
+
};
|
|
44
|
+
const labelText = labelColors[label] ? color(label, labelColors[label]) : label;
|
|
45
|
+
return `[${formatTime()}] ${tagText} ${labelText} ${message}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const REQ_TAGS = ["R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8"];
|
|
49
|
+
let tagCursor = 0;
|
|
50
|
+
|
|
51
|
+
export function nextTag() {
|
|
52
|
+
const tag = REQ_TAGS[tagCursor % REQ_TAGS.length];
|
|
53
|
+
tagCursor++;
|
|
54
|
+
return tag;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function tagForSession(seed) {
|
|
58
|
+
if (!seed) return nextTag();
|
|
59
|
+
let h = 0;
|
|
60
|
+
for (let i = 0; i < seed.length; i++) h = (h * 31 + seed.charCodeAt(i)) | 0;
|
|
61
|
+
return REQ_TAGS[Math.abs(h) % REQ_TAGS.length];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function line(tag, symbol, message) {
|
|
65
|
+
if (LEVEL > LOG_LEVELS.INFO) return;
|
|
66
|
+
console.log(formatLine(tag, symbol, message));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function errorLine(tag, symbol, message) {
|
|
70
|
+
console.log(formatLine(tag, symbol, message));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function fmtThink(intent) {
|
|
74
|
+
if (!intent || !intent.mode) return null;
|
|
75
|
+
if (intent.mode === "none") return "off";
|
|
76
|
+
if (intent.mode === "auto") return "auto";
|
|
77
|
+
if (intent.mode === "budget") {
|
|
78
|
+
const k = intent.budget >= 1000 ? `${Math.round(intent.budget / 1000)}k` : `${intent.budget}`;
|
|
79
|
+
return k;
|
|
80
|
+
}
|
|
81
|
+
if (intent.mode === "level") return intent.level;
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function formatData(data) {
|
|
86
|
+
if (!data) return "";
|
|
87
|
+
if (typeof data === "string") return data;
|
|
88
|
+
try {
|
|
89
|
+
return JSON.stringify(data);
|
|
90
|
+
} catch {
|
|
91
|
+
return String(data);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function debug(tag, message, data) {
|
|
96
|
+
if (LEVEL <= LOG_LEVELS.DEBUG) {
|
|
97
|
+
const dataStr = data ? ` ${formatData(data)}` : "";
|
|
98
|
+
console.log(`[${formatTime()}] DEBUG [${tag}] ${message}${dataStr}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function info(tag, message, data) {
|
|
103
|
+
if (LEVEL <= LOG_LEVELS.INFO) {
|
|
104
|
+
const dataStr = data ? ` ${formatData(data)}` : "";
|
|
105
|
+
console.log(`[${formatTime()}] INFO [${tag}] ${message}${dataStr}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function warn(tag, message, data) {
|
|
110
|
+
if (LEVEL <= LOG_LEVELS.WARN) {
|
|
111
|
+
const dataStr = data ? ` ${formatData(data)}` : "";
|
|
112
|
+
console.warn(`[${formatTime()}] WARN [${tag}] ${message}${dataStr}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function error(tag, message, data) {
|
|
117
|
+
if (LEVEL <= LOG_LEVELS.ERROR) {
|
|
118
|
+
const dataStr = data ? ` ${formatData(data)}` : "";
|
|
119
|
+
console.log(`[${formatTime()}] ERROR [${tag}] ${message}${dataStr}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function request(method, path, extra) {
|
|
124
|
+
const dataStr = extra ? ` ${formatData(extra)}` : "";
|
|
125
|
+
console.log(`\x1b[36m[${formatTime()}] REQUEST ${method} ${path}${dataStr}\x1b[0m`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function response(status, duration, extra) {
|
|
129
|
+
const label = status < 400 ? "RESPONSE" : "RESPONSE_ERROR";
|
|
130
|
+
const dataStr = extra ? ` ${formatData(extra)}` : "";
|
|
131
|
+
console.log(`[${formatTime()}] ${label} ${status} (${duration}ms)${dataStr}`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function stream(event, data) {
|
|
135
|
+
const dataStr = data ? ` ${formatData(data)}` : "";
|
|
136
|
+
console.log(`[${formatTime()}] STREAM ${event}${dataStr}`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function maskKey(key) {
|
|
140
|
+
if (!key || key.length < 8) return "***";
|
|
141
|
+
return `${key.slice(0, 4)}...${key.slice(-4)}`;
|
|
142
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { extname, join, normalize, sep } from "node:path";
|
|
3
|
+
|
|
4
|
+
function resolveDashboardDist(): string {
|
|
5
|
+
const candidates = [
|
|
6
|
+
join(import.meta.dir, "..", "dashboard", "dist"),
|
|
7
|
+
join(process.cwd(), "dashboard", "dist"),
|
|
8
|
+
join(process.cwd(), "dist-binary", "dashboard", "dist"),
|
|
9
|
+
];
|
|
10
|
+
return candidates.find((candidate) => existsSync(candidate)) || candidates[0]!;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const DIST_DIR = resolveDashboardDist();
|
|
14
|
+
const INDEX_HTML = join(DIST_DIR, "index.html");
|
|
15
|
+
|
|
16
|
+
const CONTENT_TYPES: Record<string, string> = {
|
|
17
|
+
".html": "text/html; charset=utf-8",
|
|
18
|
+
".js": "text/javascript; charset=utf-8",
|
|
19
|
+
".mjs": "text/javascript; charset=utf-8",
|
|
20
|
+
".css": "text/css; charset=utf-8",
|
|
21
|
+
".json": "application/json; charset=utf-8",
|
|
22
|
+
".svg": "image/svg+xml",
|
|
23
|
+
".png": "image/png",
|
|
24
|
+
".jpg": "image/jpeg",
|
|
25
|
+
".jpeg": "image/jpeg",
|
|
26
|
+
".gif": "image/gif",
|
|
27
|
+
".webp": "image/webp",
|
|
28
|
+
".ico": "image/x-icon",
|
|
29
|
+
".txt": "text/plain; charset=utf-8",
|
|
30
|
+
".woff": "font/woff",
|
|
31
|
+
".woff2": "font/woff2",
|
|
32
|
+
".ttf": "font/ttf",
|
|
33
|
+
".wasm": "application/wasm",
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const API_PREFIXES = ["/api", "/v1", "/codex", "/responses", "/health", "/version", "/metrics"];
|
|
37
|
+
|
|
38
|
+
function isApiPath(pathname: string): boolean {
|
|
39
|
+
return API_PREFIXES.some((p) => pathname === p || pathname.startsWith(`${p}/`));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function serveFile(filePath: string, request: Request): Response {
|
|
43
|
+
const stat = statSync(filePath);
|
|
44
|
+
const type = CONTENT_TYPES[extname(filePath).toLowerCase()] || "application/octet-stream";
|
|
45
|
+
|
|
46
|
+
const since = request.headers.get("if-modified-since");
|
|
47
|
+
if (since) {
|
|
48
|
+
const sinceMs = Date.parse(since);
|
|
49
|
+
if (!Number.isNaN(sinceMs) && Math.floor(stat.mtimeMs / 1000) * 1000 <= sinceMs) {
|
|
50
|
+
return new Response(null, { status: 304 });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const body = readFileSync(filePath);
|
|
55
|
+
const isImmutable = filePath.includes(`${sep}assets${sep}`);
|
|
56
|
+
return new Response(body, {
|
|
57
|
+
headers: {
|
|
58
|
+
"content-type": type,
|
|
59
|
+
"cache-control": isImmutable ? "public, max-age=31536000, immutable" : "no-cache",
|
|
60
|
+
"last-modified": stat.mtime.toUTCString(),
|
|
61
|
+
"x-content-type-options": "nosniff",
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function tryServeDashboard(request: Request): Response | null {
|
|
67
|
+
if (!existsSync(DIST_DIR)) return null;
|
|
68
|
+
|
|
69
|
+
const url = new URL(request.url);
|
|
70
|
+
let pathname: string;
|
|
71
|
+
try {
|
|
72
|
+
pathname = decodeURIComponent(url.pathname);
|
|
73
|
+
} catch {
|
|
74
|
+
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (isApiPath(pathname)) return null;
|
|
79
|
+
if (pathname.includes("..")) return null;
|
|
80
|
+
|
|
81
|
+
const filePath = normalize(join(DIST_DIR, pathname));
|
|
82
|
+
|
|
83
|
+
if (filePath !== DIST_DIR && !filePath.startsWith(DIST_DIR + sep)) return null;
|
|
84
|
+
|
|
85
|
+
if (existsSync(filePath) && statSync(filePath).isFile()) {
|
|
86
|
+
return serveFile(filePath, request);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!extname(pathname)) {
|
|
90
|
+
if (existsSync(INDEX_HTML)) return serveFile(INDEX_HTML, request);
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return null;
|
|
95
|
+
}
|