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,555 @@
|
|
|
1
|
+
import { BaseExecutor } from "./base.js";
|
|
2
|
+
import { proxyAwareFetch } from "../utils/proxyFetch.js";
|
|
3
|
+
import { PROVIDERS } from "../config/providers.js";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
|
|
6
|
+
const WS_BASE_URL = "https://server.codeium.com";
|
|
7
|
+
const WS_SERVICE = "exa.language_server_pb.LanguageServerService";
|
|
8
|
+
const WS_METHOD_CHAT = "GetChatMessage";
|
|
9
|
+
const WS_CHAT_URL = `${WS_BASE_URL}/${WS_SERVICE}/${WS_METHOD_CHAT}`;
|
|
10
|
+
|
|
11
|
+
const WS_IDE_NAME = "windsurf";
|
|
12
|
+
const WS_IDE_VERSION = "3.14.0";
|
|
13
|
+
const WS_EXT_VERSION = "3.14.0";
|
|
14
|
+
const WS_LOCALE = "en-US";
|
|
15
|
+
|
|
16
|
+
const MODEL_ALIAS_MAP = {
|
|
17
|
+
|
|
18
|
+
"swe-1.6-fast": "swe-1-6-fast",
|
|
19
|
+
"swe-1.6": "swe-1-6",
|
|
20
|
+
"swe-1.5-fast": "swe-1-5-fast",
|
|
21
|
+
"swe-1.5": "swe-1-5",
|
|
22
|
+
|
|
23
|
+
"claude-opus-4.7-max": "claude-opus-4-7-max",
|
|
24
|
+
"claude-opus-4.7-xhigh": "claude-opus-4-7-xhigh",
|
|
25
|
+
"claude-opus-4.7-high": "claude-opus-4-7-high",
|
|
26
|
+
"claude-opus-4.7-medium": "claude-opus-4-7-medium",
|
|
27
|
+
"claude-opus-4.7-low": "claude-opus-4-7-low",
|
|
28
|
+
"claude-opus-4.7-review": "opus-4-7-review",
|
|
29
|
+
|
|
30
|
+
"claude-sonnet-4.6-thinking-1m": "claude-sonnet-4-6-thinking-1m",
|
|
31
|
+
"claude-sonnet-4.6-1m": "claude-sonnet-4-6-1m",
|
|
32
|
+
"claude-sonnet-4.6-thinking": "claude-sonnet-4-6-thinking",
|
|
33
|
+
"claude-sonnet-4.6": "claude-sonnet-4-6",
|
|
34
|
+
"claude-opus-4.6-thinking": "claude-opus-4-6-thinking",
|
|
35
|
+
"claude-opus-4.6": "claude-opus-4-6",
|
|
36
|
+
|
|
37
|
+
"claude-opus-4.5-thinking": "MODEL_CLAUDE_4_5_OPUS_THINKING",
|
|
38
|
+
"claude-opus-4.5": "MODEL_CLAUDE_4_5_OPUS",
|
|
39
|
+
"claude-sonnet-4.5-thinking": "MODEL_PRIVATE_3",
|
|
40
|
+
"claude-sonnet-4.5": "MODEL_PRIVATE_2",
|
|
41
|
+
"claude-haiku-4.5": "MODEL_PRIVATE_11",
|
|
42
|
+
|
|
43
|
+
"gpt-5.5-xhigh-fast": "gpt-5-5-xhigh-priority",
|
|
44
|
+
"gpt-5.5-high-fast": "gpt-5-5-high-priority",
|
|
45
|
+
"gpt-5.5-medium-fast": "gpt-5-5-medium-priority",
|
|
46
|
+
"gpt-5.5-low-fast": "gpt-5-5-low-priority",
|
|
47
|
+
"gpt-5.5-none-fast": "gpt-5-5-none-priority",
|
|
48
|
+
"gpt-5.5-xhigh": "gpt-5-5-xhigh",
|
|
49
|
+
"gpt-5.5-high": "gpt-5-5-high",
|
|
50
|
+
"gpt-5.5-medium": "gpt-5-5-medium",
|
|
51
|
+
"gpt-5.5-low": "gpt-5-5-low",
|
|
52
|
+
"gpt-5.5-none": "gpt-5-5-none",
|
|
53
|
+
"gpt-5.5-review": "gpt-5-5-review",
|
|
54
|
+
"gpt-5.5": "gpt-5-5-medium",
|
|
55
|
+
|
|
56
|
+
"gpt-5.4-xhigh-fast": "gpt-5-4-xhigh-priority",
|
|
57
|
+
"gpt-5.4-high-fast": "gpt-5-4-high-priority",
|
|
58
|
+
"gpt-5.4-medium-fast": "gpt-5-4-medium-priority",
|
|
59
|
+
"gpt-5.4-low-fast": "gpt-5-4-low-priority",
|
|
60
|
+
"gpt-5.4-none-fast": "gpt-5-4-none-priority",
|
|
61
|
+
"gpt-5.4-xhigh": "gpt-5-4-xhigh",
|
|
62
|
+
"gpt-5.4-high": "gpt-5-4-high",
|
|
63
|
+
"gpt-5.4-medium": "gpt-5-4-medium",
|
|
64
|
+
"gpt-5.4-low": "gpt-5-4-low",
|
|
65
|
+
"gpt-5.4-none": "gpt-5-4-none",
|
|
66
|
+
"gpt-5.4-mini-xhigh": "gpt-5-4-mini-xhigh",
|
|
67
|
+
"gpt-5.4-mini-high": "gpt-5-4-mini-high",
|
|
68
|
+
"gpt-5.4-mini-medium": "gpt-5-4-mini-medium",
|
|
69
|
+
"gpt-5.4-mini-low": "gpt-5-4-mini-low",
|
|
70
|
+
"gpt-5.4": "gpt-5-4-medium",
|
|
71
|
+
|
|
72
|
+
"gpt-5.3-codex-xhigh-fast": "gpt-5-3-codex-xhigh-priority",
|
|
73
|
+
"gpt-5.3-codex-high-fast": "gpt-5-3-codex-high-priority",
|
|
74
|
+
"gpt-5.3-codex-medium-fast": "gpt-5-3-codex-medium-priority",
|
|
75
|
+
"gpt-5.3-codex-low-fast": "gpt-5-3-codex-low-priority",
|
|
76
|
+
"gpt-5.3-codex-xhigh": "gpt-5-3-codex-xhigh",
|
|
77
|
+
"gpt-5.3-codex-high": "gpt-5-3-codex-high",
|
|
78
|
+
"gpt-5.3-codex-medium": "gpt-5-3-codex-medium",
|
|
79
|
+
"gpt-5.3-codex-low": "gpt-5-3-codex-low",
|
|
80
|
+
"gpt-5.3-codex": "gpt-5-3-codex-medium",
|
|
81
|
+
|
|
82
|
+
"gpt-5.2-xhigh": "MODEL_GPT_5_2_XHIGH",
|
|
83
|
+
"gpt-5.2-high": "MODEL_GPT_5_2_HIGH",
|
|
84
|
+
"gpt-5.2-medium": "MODEL_GPT_5_2_MEDIUM",
|
|
85
|
+
"gpt-5.2-low": "MODEL_GPT_5_2_LOW",
|
|
86
|
+
"gpt-5.2-none": "MODEL_GPT_5_2_NONE",
|
|
87
|
+
"gpt-5.2": "MODEL_GPT_5_2_MEDIUM",
|
|
88
|
+
|
|
89
|
+
"gpt-5": "gpt-5",
|
|
90
|
+
|
|
91
|
+
"gpt-4.1": "MODEL_CHAT_GPT_4_1_2025_04_14",
|
|
92
|
+
"gpt-4.1-mini": "gpt-4.1-mini",
|
|
93
|
+
"gpt-4o": "MODEL_CHAT_GPT_4O_2024_08_06",
|
|
94
|
+
|
|
95
|
+
"gemini-3.1-pro-high": "gemini-3-1-pro-high",
|
|
96
|
+
"gemini-3.1-pro-low": "gemini-3-1-pro-low",
|
|
97
|
+
"gemini-3.1-pro": "gemini-3-1-pro-high",
|
|
98
|
+
"gemini-3.0-flash-high": "MODEL_GOOGLE_GEMINI_3_0_FLASH_HIGH",
|
|
99
|
+
"gemini-3.0-flash-medium": "MODEL_GOOGLE_GEMINI_3_0_FLASH_MEDIUM",
|
|
100
|
+
"gemini-3.0-flash-low": "MODEL_GOOGLE_GEMINI_3_0_FLASH_LOW",
|
|
101
|
+
"gemini-3.0-flash-minimal": "MODEL_GOOGLE_GEMINI_3_0_FLASH_MINIMAL",
|
|
102
|
+
"gemini-3.0-flash": "MODEL_GOOGLE_GEMINI_3_0_FLASH_HIGH",
|
|
103
|
+
"gemini-2.5-pro": "MODEL_GOOGLE_GEMINI_2_5_PRO",
|
|
104
|
+
|
|
105
|
+
"deepseek-v4": "deepseek-v4",
|
|
106
|
+
"kimi-k2.6": "kimi-k2-6",
|
|
107
|
+
"kimi-k2.5": "kimi-k2-5",
|
|
108
|
+
"glm-5.1": "glm-5-1",
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export function resolveWsModelId(model) {
|
|
112
|
+
return MODEL_ALIAS_MAP[model] ?? model;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function encodeVarint(value) {
|
|
116
|
+
const bytes = [];
|
|
117
|
+
let v = value >>> 0;
|
|
118
|
+
while (v > 0x7f) {
|
|
119
|
+
bytes.push((v & 0x7f) | 0x80);
|
|
120
|
+
v >>>= 7;
|
|
121
|
+
}
|
|
122
|
+
bytes.push(v & 0x7f);
|
|
123
|
+
return new Uint8Array(bytes);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function concatBytes(arrays) {
|
|
127
|
+
const total = arrays.reduce((n, a) => n + a.length, 0);
|
|
128
|
+
const out = new Uint8Array(total);
|
|
129
|
+
let off = 0;
|
|
130
|
+
for (const a of arrays) {
|
|
131
|
+
out.set(a, off);
|
|
132
|
+
off += a.length;
|
|
133
|
+
}
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const TEXT_ENC = new TextEncoder();
|
|
138
|
+
const TEXT_DEC = new TextDecoder();
|
|
139
|
+
|
|
140
|
+
function encodeField(fieldNum, payload) {
|
|
141
|
+
const tag = encodeVarint((fieldNum << 3) | 2);
|
|
142
|
+
const len = encodeVarint(payload.length);
|
|
143
|
+
return concatBytes([tag, len, payload]);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function encodeString(fieldNum, value) {
|
|
147
|
+
return encodeField(fieldNum, TEXT_ENC.encode(value));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function encodeMessage(fieldNum, msg) {
|
|
151
|
+
return encodeField(fieldNum, msg);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function buildMetadata(apiKey, sessionId) {
|
|
155
|
+
return concatBytes([
|
|
156
|
+
encodeString(1, apiKey),
|
|
157
|
+
encodeString(2, WS_IDE_NAME),
|
|
158
|
+
encodeString(3, WS_IDE_VERSION),
|
|
159
|
+
encodeString(4, WS_EXT_VERSION),
|
|
160
|
+
encodeString(5, sessionId),
|
|
161
|
+
encodeString(6, WS_LOCALE),
|
|
162
|
+
]);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function buildModelOrAlias(model) {
|
|
166
|
+
return encodeString(1, model);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function buildChatMessage(msg) {
|
|
170
|
+
const parts = [encodeString(1, msg.role), encodeString(2, msg.content)];
|
|
171
|
+
if (msg.toolCallId) parts.push(encodeString(3, msg.toolCallId));
|
|
172
|
+
return concatBytes(parts);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function buildGetChatMessageRequest(apiKey, model, messages) {
|
|
176
|
+
const sessionId = randomUUID();
|
|
177
|
+
const cascadeId = randomUUID();
|
|
178
|
+
|
|
179
|
+
const parts = [
|
|
180
|
+
encodeMessage(1, buildMetadata(apiKey, sessionId)),
|
|
181
|
+
encodeString(2, cascadeId),
|
|
182
|
+
encodeMessage(3, buildModelOrAlias(model)),
|
|
183
|
+
];
|
|
184
|
+
|
|
185
|
+
for (const msg of messages) {
|
|
186
|
+
parts.push(encodeMessage(4, buildChatMessage(msg)));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return concatBytes(parts);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function grpcWebFrame(payload) {
|
|
193
|
+
const frame = new Uint8Array(5 + payload.length);
|
|
194
|
+
frame[0] = 0x00;
|
|
195
|
+
const view = new DataView(frame.buffer);
|
|
196
|
+
view.setUint32(1, payload.length, false);
|
|
197
|
+
frame.set(payload, 5);
|
|
198
|
+
return frame;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function readVarint(buf, offset) {
|
|
202
|
+
let result = 0;
|
|
203
|
+
let shift = 0;
|
|
204
|
+
while (offset < buf.length) {
|
|
205
|
+
const b = buf[offset++];
|
|
206
|
+
result |= (b & 0x7f) << shift;
|
|
207
|
+
if ((b & 0x80) === 0) break;
|
|
208
|
+
shift += 7;
|
|
209
|
+
}
|
|
210
|
+
return [result >>> 0, offset];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function decodeStringField(buf, targetField) {
|
|
214
|
+
let offset = 0;
|
|
215
|
+
while (offset < buf.length) {
|
|
216
|
+
let tag;
|
|
217
|
+
[tag, offset] = readVarint(buf, offset);
|
|
218
|
+
const fieldNum = tag >>> 3;
|
|
219
|
+
const wireType = tag & 0x07;
|
|
220
|
+
if (wireType === 2) {
|
|
221
|
+
let len;
|
|
222
|
+
[len, offset] = readVarint(buf, offset);
|
|
223
|
+
const payload = buf.slice(offset, offset + len);
|
|
224
|
+
offset += len;
|
|
225
|
+
if (fieldNum === targetField) return TEXT_DEC.decode(payload);
|
|
226
|
+
} else if (wireType === 0) {
|
|
227
|
+
let v;
|
|
228
|
+
[v, offset] = readVarint(buf, offset);
|
|
229
|
+
} else if (wireType === 1) {
|
|
230
|
+
offset += 8;
|
|
231
|
+
} else if (wireType === 5) {
|
|
232
|
+
offset += 4;
|
|
233
|
+
} else {
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function decodeDoneChunk(buf) {
|
|
241
|
+
|
|
242
|
+
let offset = 0;
|
|
243
|
+
let usageBytes = null;
|
|
244
|
+
while (offset < buf.length) {
|
|
245
|
+
let tag;
|
|
246
|
+
[tag, offset] = readVarint(buf, offset);
|
|
247
|
+
const fieldNum = tag >>> 3;
|
|
248
|
+
const wireType = tag & 0x07;
|
|
249
|
+
if (wireType === 2) {
|
|
250
|
+
let len;
|
|
251
|
+
[len, offset] = readVarint(buf, offset);
|
|
252
|
+
if (fieldNum === 1) usageBytes = buf.slice(offset, offset + len);
|
|
253
|
+
offset += len;
|
|
254
|
+
} else if (wireType === 0) {
|
|
255
|
+
let v;
|
|
256
|
+
[v, offset] = readVarint(buf, offset);
|
|
257
|
+
} else {
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (!usageBytes) return [0, 0];
|
|
262
|
+
let promptTokens = 0;
|
|
263
|
+
let completionTokens = 0;
|
|
264
|
+
offset = 0;
|
|
265
|
+
while (offset < usageBytes.length) {
|
|
266
|
+
let tag;
|
|
267
|
+
[tag, offset] = readVarint(usageBytes, offset);
|
|
268
|
+
const fieldNum = tag >>> 3;
|
|
269
|
+
const wireType = tag & 0x07;
|
|
270
|
+
if (wireType === 0) {
|
|
271
|
+
let v;
|
|
272
|
+
[v, offset] = readVarint(usageBytes, offset);
|
|
273
|
+
if (fieldNum === 1) promptTokens = v;
|
|
274
|
+
else if (fieldNum === 2) completionTokens = v;
|
|
275
|
+
} else if (wireType === 2) {
|
|
276
|
+
let len;
|
|
277
|
+
[len, offset] = readVarint(usageBytes, offset);
|
|
278
|
+
offset += len;
|
|
279
|
+
} else {
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return [promptTokens, completionTokens];
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function decodeCompletionChunk(buf) {
|
|
287
|
+
let offset = 0;
|
|
288
|
+
while (offset < buf.length) {
|
|
289
|
+
let tag;
|
|
290
|
+
[tag, offset] = readVarint(buf, offset);
|
|
291
|
+
const fieldNum = tag >>> 3;
|
|
292
|
+
const wireType = tag & 0x07;
|
|
293
|
+
|
|
294
|
+
if (wireType === 2) {
|
|
295
|
+
let len;
|
|
296
|
+
[len, offset] = readVarint(buf, offset);
|
|
297
|
+
const payload = buf.slice(offset, offset + len);
|
|
298
|
+
offset += len;
|
|
299
|
+
|
|
300
|
+
if (fieldNum === 1) {
|
|
301
|
+
const text = decodeStringField(payload, 1);
|
|
302
|
+
if (text !== null) return { kind: "content", text };
|
|
303
|
+
} else if (fieldNum === 3) {
|
|
304
|
+
const usage = decodeDoneChunk(payload);
|
|
305
|
+
return { kind: "done", promptTokens: usage[0], completionTokens: usage[1] };
|
|
306
|
+
} else if (fieldNum === 4) {
|
|
307
|
+
const msg = decodeStringField(payload, 1);
|
|
308
|
+
return { kind: "error", message: msg ?? "unknown windsurf error" };
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
} else if (wireType === 0) {
|
|
312
|
+
let v;
|
|
313
|
+
[v, offset] = readVarint(buf, offset);
|
|
314
|
+
} else if (wireType === 1) {
|
|
315
|
+
offset += 8;
|
|
316
|
+
} else if (wireType === 5) {
|
|
317
|
+
offset += 4;
|
|
318
|
+
} else {
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return { kind: "unknown" };
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function openAIMessagesToWs(messages) {
|
|
326
|
+
const out = [];
|
|
327
|
+
for (const m of messages) {
|
|
328
|
+
const role = String(m.role || "user");
|
|
329
|
+
let content = "";
|
|
330
|
+
if (typeof m.content === "string") {
|
|
331
|
+
content = m.content;
|
|
332
|
+
} else if (Array.isArray(m.content)) {
|
|
333
|
+
for (const part of m.content) {
|
|
334
|
+
if (part && typeof part === "object" && part.type === "text") {
|
|
335
|
+
content += String(part.text || "");
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
out.push({ role, content, toolCallId: m.tool_call_id });
|
|
340
|
+
}
|
|
341
|
+
return out;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export class WindsurfExecutor extends BaseExecutor {
|
|
345
|
+
constructor() {
|
|
346
|
+
super("windsurf", PROVIDERS.windsurf || { id: "windsurf", baseUrl: WS_CHAT_URL });
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
buildUrl() {
|
|
350
|
+
return WS_CHAT_URL;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
buildHeaders(credentials, stream = true) {
|
|
354
|
+
const token = credentials?.accessToken || credentials?.apiKey || "";
|
|
355
|
+
return {
|
|
356
|
+
"Content-Type": "application/grpc-web+proto",
|
|
357
|
+
Accept: "application/grpc-web+proto",
|
|
358
|
+
|
|
359
|
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
360
|
+
"User-Agent": `windsurf/${WS_IDE_VERSION}`,
|
|
361
|
+
"X-Grpc-Web": "1",
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
transformRequest() {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
async execute({ model, body, stream, credentials, signal, log, upstreamExtraHeaders, proxyOptions = null }) {
|
|
370
|
+
const apiKey = credentials?.accessToken || credentials?.apiKey || "";
|
|
371
|
+
const wsModel = resolveWsModelId(model);
|
|
372
|
+
|
|
373
|
+
const b = body ?? {};
|
|
374
|
+
const rawMessages = Array.isArray(b.messages) ? b.messages : [];
|
|
375
|
+
let wsMessages = openAIMessagesToWs(rawMessages);
|
|
376
|
+
if (wsMessages.length === 0) {
|
|
377
|
+
wsMessages.push({ role: "user", content: "" });
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const protoPayload = buildGetChatMessageRequest(apiKey, wsModel, wsMessages);
|
|
381
|
+
const framedPayload = grpcWebFrame(protoPayload);
|
|
382
|
+
|
|
383
|
+
const url = this.buildUrl();
|
|
384
|
+
const headers = this.buildHeaders(credentials);
|
|
385
|
+
if (upstreamExtraHeaders) Object.assign(headers, upstreamExtraHeaders);
|
|
386
|
+
|
|
387
|
+
log?.debug?.("WS", `Windsurf → ${wsModel} (${wsMessages.length} messages)`);
|
|
388
|
+
|
|
389
|
+
const upstream = await proxyAwareFetch(url, {
|
|
390
|
+
method: "POST",
|
|
391
|
+
headers,
|
|
392
|
+
body: framedPayload,
|
|
393
|
+
signal,
|
|
394
|
+
}, proxyOptions);
|
|
395
|
+
|
|
396
|
+
if (!upstream.ok && upstream.status !== 200) {
|
|
397
|
+
return { response: upstream, url, headers, transformedBody: protoPayload };
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const sseResponse = this.transformToSSE(upstream, model);
|
|
401
|
+
return { response: sseResponse, url, headers, transformedBody: protoPayload };
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
transformToSSE(upstream, model) {
|
|
405
|
+
const responseId = `chatcmpl-ws-${Date.now()}`;
|
|
406
|
+
const created = Math.floor(Date.now() / 1000);
|
|
407
|
+
const executor = this;
|
|
408
|
+
|
|
409
|
+
const sseStream = new ReadableStream({
|
|
410
|
+
async start(controller) {
|
|
411
|
+
const enc = new TextEncoder();
|
|
412
|
+
let roleEmitted = false;
|
|
413
|
+
let totalText = "";
|
|
414
|
+
let promptTokens = 0;
|
|
415
|
+
let completionTokens = 0;
|
|
416
|
+
let hadError = null;
|
|
417
|
+
|
|
418
|
+
const emit = (data) => controller.enqueue(enc.encode(data));
|
|
419
|
+
|
|
420
|
+
try {
|
|
421
|
+
let pending = new Uint8Array(0);
|
|
422
|
+
const reader = upstream.body?.getReader();
|
|
423
|
+
|
|
424
|
+
const handleFrame = (flag, payload) => {
|
|
425
|
+
if (flag === 0x80) {
|
|
426
|
+
|
|
427
|
+
const trailer = TEXT_DEC.decode(payload);
|
|
428
|
+
const statusMatch = /grpc-status:\s*(\d+)/i.exec(trailer);
|
|
429
|
+
if (statusMatch && statusMatch[1] !== "0") {
|
|
430
|
+
const msgMatch = /grpc-message:\s*(.+)/i.exec(trailer);
|
|
431
|
+
hadError = msgMatch
|
|
432
|
+
? decodeURIComponent(msgMatch[1].trim())
|
|
433
|
+
: `gRPC status ${statusMatch[1]}`;
|
|
434
|
+
}
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
if (flag !== 0x00) return;
|
|
438
|
+
|
|
439
|
+
const chunk = executor.constructor.decodeCompletionChunk
|
|
440
|
+
? executor.constructor.decodeCompletionChunk(payload)
|
|
441
|
+
: decodeCompletionChunk(payload);
|
|
442
|
+
|
|
443
|
+
if (chunk.kind === "content" && chunk.text) {
|
|
444
|
+
totalText += chunk.text;
|
|
445
|
+
if (!roleEmitted) {
|
|
446
|
+
emit(`data: ${JSON.stringify({
|
|
447
|
+
id: responseId, object: "chat.completion.chunk", created, model,
|
|
448
|
+
choices: [{ index: 0, delta: { role: "assistant", content: "" }, finish_reason: null }],
|
|
449
|
+
})}\n\n`);
|
|
450
|
+
roleEmitted = true;
|
|
451
|
+
}
|
|
452
|
+
emit(`data: ${JSON.stringify({
|
|
453
|
+
id: responseId, object: "chat.completion.chunk", created, model,
|
|
454
|
+
choices: [{ index: 0, delta: { content: chunk.text }, finish_reason: null }],
|
|
455
|
+
})}\n\n`);
|
|
456
|
+
} else if (chunk.kind === "done") {
|
|
457
|
+
promptTokens = chunk.promptTokens;
|
|
458
|
+
completionTokens = chunk.completionTokens;
|
|
459
|
+
} else if (chunk.kind === "error") {
|
|
460
|
+
hadError = chunk.message;
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
const drainFrames = () => {
|
|
465
|
+
let offset = 0;
|
|
466
|
+
while (offset + 5 <= pending.length) {
|
|
467
|
+
const flag = pending[offset];
|
|
468
|
+
const len =
|
|
469
|
+
(pending[offset + 1] << 24) |
|
|
470
|
+
(pending[offset + 2] << 16) |
|
|
471
|
+
(pending[offset + 3] << 8) |
|
|
472
|
+
pending[offset + 4];
|
|
473
|
+
if (len < 0 || offset + 5 + len > pending.length) break;
|
|
474
|
+
handleFrame(flag, pending.slice(offset + 5, offset + 5 + len));
|
|
475
|
+
offset += 5 + len;
|
|
476
|
+
}
|
|
477
|
+
if (offset > 0) pending = pending.slice(offset);
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
if (reader) {
|
|
481
|
+
try {
|
|
482
|
+
while (true) {
|
|
483
|
+
const { done, value } = await reader.read();
|
|
484
|
+
if (done) break;
|
|
485
|
+
if (!value) continue;
|
|
486
|
+
pending = pending.length === 0 ? value : concatBytes([pending, value]);
|
|
487
|
+
drainFrames();
|
|
488
|
+
}
|
|
489
|
+
} finally {
|
|
490
|
+
reader.releaseLock();
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
drainFrames();
|
|
494
|
+
|
|
495
|
+
if (hadError) {
|
|
496
|
+
emit(`data: ${JSON.stringify({
|
|
497
|
+
error: { message: hadError, type: "windsurf_error", code: "upstream_error" },
|
|
498
|
+
})}\n\n`);
|
|
499
|
+
emit("data: [DONE]\n\n");
|
|
500
|
+
controller.close();
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
if (!roleEmitted && totalText) {
|
|
505
|
+
emit(`data: ${JSON.stringify({
|
|
506
|
+
id: responseId, object: "chat.completion.chunk", created, model,
|
|
507
|
+
choices: [{ index: 0, delta: { role: "assistant", content: "" }, finish_reason: null }],
|
|
508
|
+
})}\n\n`);
|
|
509
|
+
emit(`data: ${JSON.stringify({
|
|
510
|
+
id: responseId, object: "chat.completion.chunk", created, model,
|
|
511
|
+
choices: [{ index: 0, delta: { content: totalText }, finish_reason: null }],
|
|
512
|
+
})}\n\n`);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
const finishPayload = {
|
|
516
|
+
id: responseId, object: "chat.completion.chunk", created, model,
|
|
517
|
+
choices: [{ index: 0, delta: {}, finish_reason: "stop" }],
|
|
518
|
+
};
|
|
519
|
+
if (promptTokens > 0 || completionTokens > 0) {
|
|
520
|
+
finishPayload.usage = {
|
|
521
|
+
prompt_tokens: promptTokens,
|
|
522
|
+
completion_tokens: completionTokens,
|
|
523
|
+
total_tokens: promptTokens + completionTokens,
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
emit(`data: ${JSON.stringify(finishPayload)}\n\n`);
|
|
527
|
+
emit("data: [DONE]\n\n");
|
|
528
|
+
} catch (err) {
|
|
529
|
+
const msg = err?.message ? String(err.message) : String(err);
|
|
530
|
+
emit(`data: ${JSON.stringify({
|
|
531
|
+
error: { message: `Windsurf stream error: ${msg}`, type: "windsurf_error" },
|
|
532
|
+
})}\n\n`);
|
|
533
|
+
emit("data: [DONE]\n\n");
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
controller.close();
|
|
537
|
+
},
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
return new Response(sseStream, {
|
|
541
|
+
status: 200,
|
|
542
|
+
headers: {
|
|
543
|
+
"Content-Type": "text/event-stream",
|
|
544
|
+
"Cache-Control": "no-cache",
|
|
545
|
+
Connection: "keep-alive",
|
|
546
|
+
},
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
async refreshCredentials() {
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
export default WindsurfExecutor;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DefaultExecutor } from "./default.js";
|
|
2
|
+
import { resolveXiaomiTokenplanBaseUrl } from "../config/providers.js";
|
|
3
|
+
|
|
4
|
+
export class XiaomiTokenplanExecutor extends DefaultExecutor {
|
|
5
|
+
constructor() {
|
|
6
|
+
super("xiaomi-tokenplan");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
buildUrl(model, stream, urlIndex = 0, credentials = null) {
|
|
10
|
+
const baseUrl = resolveXiaomiTokenplanBaseUrl(credentials);
|
|
11
|
+
if (credentials?.runtimeTransport?.format === "claude") {
|
|
12
|
+
return `${baseUrl.replace(/\/v1\/?$/, "")}/anthropic/v1/messages`;
|
|
13
|
+
}
|
|
14
|
+
return `${baseUrl}/chat/completions`;
|
|
15
|
+
}
|
|
16
|
+
}
|