blackriver-gateway 3.8.46
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 +2070 -0
- package/@omniroute/opencode-plugin/LICENSE +21 -0
- package/@omniroute/opencode-plugin/README.md +296 -0
- package/@omniroute/opencode-plugin/package-lock.json +1930 -0
- package/@omniroute/opencode-plugin/package.json +73 -0
- package/@omniroute/opencode-plugin/src/index.ts +4685 -0
- package/@omniroute/opencode-plugin/src/logger.ts +74 -0
- package/@omniroute/opencode-plugin/src/naming.ts +301 -0
- package/@omniroute/opencode-plugin/tsconfig.json +20 -0
- package/@omniroute/opencode-plugin/tsup.config.ts +20 -0
- package/@omniroute/opencode-provider/LICENSE +21 -0
- package/@omniroute/opencode-provider/README.md +156 -0
- package/@omniroute/opencode-provider/package-lock.json +1514 -0
- package/@omniroute/opencode-provider/package.json +63 -0
- package/@omniroute/opencode-provider/src/index.ts +908 -0
- package/@omniroute/opencode-provider/tsconfig.json +20 -0
- package/@omniroute/opencode-provider/tsup.config.ts +18 -0
- package/LICENSE +22 -0
- package/README.md +1265 -0
- package/bin/_ops-common.sh +70 -0
- package/bin/cli/CONVENTIONS.md +224 -0
- package/bin/cli/README.md +146 -0
- package/bin/cli/api-commands/agent-skills.mjs +70 -0
- package/bin/cli/api-commands/agentbridge.mjs +155 -0
- package/bin/cli/api-commands/api-keys.mjs +42 -0
- package/bin/cli/api-commands/audio.mjs +40 -0
- package/bin/cli/api-commands/chat.mjs +58 -0
- package/bin/cli/api-commands/cli-tools.mjs +361 -0
- package/bin/cli/api-commands/cloud.mjs +81 -0
- package/bin/cli/api-commands/combos.mjs +69 -0
- package/bin/cli/api-commands/compression.mjs +128 -0
- package/bin/cli/api-commands/embedded-services.mjs +202 -0
- package/bin/cli/api-commands/embeddings.mjs +42 -0
- package/bin/cli/api-commands/fallback.mjs +49 -0
- package/bin/cli/api-commands/images.mjs +42 -0
- package/bin/cli/api-commands/memory.mjs +251 -0
- package/bin/cli/api-commands/messages.mjs +40 -0
- package/bin/cli/api-commands/models.mjs +89 -0
- package/bin/cli/api-commands/moderations.mjs +24 -0
- package/bin/cli/api-commands/oauth.mjs +114 -0
- package/bin/cli/api-commands/playground.mjs +83 -0
- package/bin/cli/api-commands/pricing.mjs +44 -0
- package/bin/cli/api-commands/provider-nodes.mjs +62 -0
- package/bin/cli/api-commands/providers.mjs +148 -0
- package/bin/cli/api-commands/quota.mjs +154 -0
- package/bin/cli/api-commands/registry.mjs +75 -0
- package/bin/cli/api-commands/rerank.mjs +24 -0
- package/bin/cli/api-commands/responses.mjs +24 -0
- package/bin/cli/api-commands/settings.mjs +228 -0
- package/bin/cli/api-commands/system.mjs +320 -0
- package/bin/cli/api-commands/telemetry.mjs +26 -0
- package/bin/cli/api-commands/traffic-inspector.mjs +307 -0
- package/bin/cli/api-commands/translator.mjs +65 -0
- package/bin/cli/api-commands/usage.mjs +117 -0
- package/bin/cli/api.mjs +269 -0
- package/bin/cli/commands/a2a.mjs +323 -0
- package/bin/cli/commands/audit.mjs +203 -0
- package/bin/cli/commands/autostart.mjs +57 -0
- package/bin/cli/commands/backup.mjs +469 -0
- package/bin/cli/commands/batches.mjs +235 -0
- package/bin/cli/commands/cache.mjs +102 -0
- package/bin/cli/commands/chat.mjs +162 -0
- package/bin/cli/commands/cloud.mjs +233 -0
- package/bin/cli/commands/combo.mjs +361 -0
- package/bin/cli/commands/completion.mjs +346 -0
- package/bin/cli/commands/compression.mjs +247 -0
- package/bin/cli/commands/config.mjs +351 -0
- package/bin/cli/commands/configure.mjs +180 -0
- package/bin/cli/commands/connect.mjs +132 -0
- package/bin/cli/commands/context-eng.mjs +182 -0
- package/bin/cli/commands/contexts.mjs +271 -0
- package/bin/cli/commands/cost.mjs +144 -0
- package/bin/cli/commands/dashboard.mjs +65 -0
- package/bin/cli/commands/doctor.mjs +527 -0
- package/bin/cli/commands/env.mjs +100 -0
- package/bin/cli/commands/eval.mjs +278 -0
- package/bin/cli/commands/files.mjs +144 -0
- package/bin/cli/commands/health.mjs +123 -0
- package/bin/cli/commands/keys.mjs +599 -0
- package/bin/cli/commands/launch-codex.mjs +201 -0
- package/bin/cli/commands/launch.mjs +155 -0
- package/bin/cli/commands/login.mjs +192 -0
- package/bin/cli/commands/logs.mjs +183 -0
- package/bin/cli/commands/mcp.mjs +273 -0
- package/bin/cli/commands/memory.mjs +244 -0
- package/bin/cli/commands/models.mjs +92 -0
- package/bin/cli/commands/nodes.mjs +177 -0
- package/bin/cli/commands/oauth.mjs +258 -0
- package/bin/cli/commands/oneproxy.mjs +120 -0
- package/bin/cli/commands/open.mjs +75 -0
- package/bin/cli/commands/openapi.mjs +168 -0
- package/bin/cli/commands/plugin.mjs +219 -0
- package/bin/cli/commands/policy.mjs +216 -0
- package/bin/cli/commands/pricing.mjs +123 -0
- package/bin/cli/commands/provider-cmd.mjs +18 -0
- package/bin/cli/commands/providers.mjs +706 -0
- package/bin/cli/commands/quota.mjs +100 -0
- package/bin/cli/commands/redis.mjs +294 -0
- package/bin/cli/commands/registry.mjs +162 -0
- package/bin/cli/commands/repl.mjs +19 -0
- package/bin/cli/commands/reset-encrypted-columns.mjs +88 -0
- package/bin/cli/commands/resilience.mjs +208 -0
- package/bin/cli/commands/restart.mjs +25 -0
- package/bin/cli/commands/runtime.mjs +98 -0
- package/bin/cli/commands/serve.mjs +426 -0
- package/bin/cli/commands/sessions.mjs +108 -0
- package/bin/cli/commands/setup-aider.mjs +146 -0
- package/bin/cli/commands/setup-claude.mjs +219 -0
- package/bin/cli/commands/setup-cline.mjs +160 -0
- package/bin/cli/commands/setup-codex.mjs +387 -0
- package/bin/cli/commands/setup-continue.mjs +173 -0
- package/bin/cli/commands/setup-crush.mjs +148 -0
- package/bin/cli/commands/setup-cursor.mjs +108 -0
- package/bin/cli/commands/setup-goose.mjs +150 -0
- package/bin/cli/commands/setup-kilo.mjs +178 -0
- package/bin/cli/commands/setup-open-code.mjs +398 -0
- package/bin/cli/commands/setup-opencode.mjs +129 -0
- package/bin/cli/commands/setup-qwen.mjs +156 -0
- package/bin/cli/commands/setup-roo.mjs +172 -0
- package/bin/cli/commands/setup.mjs +211 -0
- package/bin/cli/commands/simulate.mjs +125 -0
- package/bin/cli/commands/skills.mjs +373 -0
- package/bin/cli/commands/status.mjs +95 -0
- package/bin/cli/commands/stop.mjs +96 -0
- package/bin/cli/commands/stream.mjs +166 -0
- package/bin/cli/commands/sync.mjs +230 -0
- package/bin/cli/commands/tags.mjs +116 -0
- package/bin/cli/commands/telemetry.mjs +74 -0
- package/bin/cli/commands/test-provider.mjs +242 -0
- package/bin/cli/commands/tokens.mjs +118 -0
- package/bin/cli/commands/translator.mjs +131 -0
- package/bin/cli/commands/tray.mjs +36 -0
- package/bin/cli/commands/tunnel.mjs +347 -0
- package/bin/cli/commands/update.mjs +194 -0
- package/bin/cli/commands/usage.mjs +331 -0
- package/bin/cli/commands/webhooks.mjs +196 -0
- package/bin/cli/contexts.mjs +60 -0
- package/bin/cli/data-dir.mjs +59 -0
- package/bin/cli/encryption.mjs +67 -0
- package/bin/cli/i18n.mjs +106 -0
- package/bin/cli/io.mjs +83 -0
- package/bin/cli/locales/ar.json +32 -0
- package/bin/cli/locales/az.json +32 -0
- package/bin/cli/locales/bg.json +32 -0
- package/bin/cli/locales/bn.json +5 -0
- package/bin/cli/locales/cs.json +32 -0
- package/bin/cli/locales/da.json +32 -0
- package/bin/cli/locales/de.json +32 -0
- package/bin/cli/locales/en.json +1289 -0
- package/bin/cli/locales/es.json +32 -0
- package/bin/cli/locales/fa.json +32 -0
- package/bin/cli/locales/fi.json +32 -0
- package/bin/cli/locales/fr.json +32 -0
- package/bin/cli/locales/gu.json +5 -0
- package/bin/cli/locales/he.json +5 -0
- package/bin/cli/locales/hi.json +32 -0
- package/bin/cli/locales/hu.json +32 -0
- package/bin/cli/locales/id.json +32 -0
- package/bin/cli/locales/in.json +5 -0
- package/bin/cli/locales/it.json +32 -0
- package/bin/cli/locales/ja.json +32 -0
- package/bin/cli/locales/ko.json +32 -0
- package/bin/cli/locales/mr.json +5 -0
- package/bin/cli/locales/ms.json +5 -0
- package/bin/cli/locales/nl.json +32 -0
- package/bin/cli/locales/no.json +32 -0
- package/bin/cli/locales/phi.json +5 -0
- package/bin/cli/locales/pl.json +32 -0
- package/bin/cli/locales/pt-BR.json +1286 -0
- package/bin/cli/locales/pt.json +32 -0
- package/bin/cli/locales/ro.json +32 -0
- package/bin/cli/locales/ru.json +32 -0
- package/bin/cli/locales/sk.json +32 -0
- package/bin/cli/locales/sv.json +32 -0
- package/bin/cli/locales/sw.json +5 -0
- package/bin/cli/locales/ta.json +5 -0
- package/bin/cli/locales/te.json +5 -0
- package/bin/cli/locales/th.json +32 -0
- package/bin/cli/locales/tr.json +32 -0
- package/bin/cli/locales/uk-UA.json +32 -0
- package/bin/cli/locales/ur.json +5 -0
- package/bin/cli/locales/vi.json +32 -0
- package/bin/cli/locales/zh-CN.json +1262 -0
- package/bin/cli/output.mjs +200 -0
- package/bin/cli/plugins.mjs +90 -0
- package/bin/cli/program.mjs +40 -0
- package/bin/cli/provider-catalog.mjs +175 -0
- package/bin/cli/provider-store.mjs +312 -0
- package/bin/cli/provider-test.mjs +181 -0
- package/bin/cli/runtime/index.mjs +19 -0
- package/bin/cli/runtime/magicBytes.mjs +47 -0
- package/bin/cli/runtime/nativeDeps.mjs +137 -0
- package/bin/cli/runtime/processSupervisor.mjs +136 -0
- package/bin/cli/runtime/sqliteRuntime.mjs +129 -0
- package/bin/cli/runtime/supervisorPolicy.mjs +56 -0
- package/bin/cli/runtime/trayRuntime.ts +94 -0
- package/bin/cli/runtime.mjs +61 -0
- package/bin/cli/schemas/output-schemas.mjs +56 -0
- package/bin/cli/scripts/generate-locales.mjs +911 -0
- package/bin/cli/settings-store.mjs +45 -0
- package/bin/cli/spinner.mjs +30 -0
- package/bin/cli/sqlite.mjs +158 -0
- package/bin/cli/tray/autostart.mjs +410 -0
- package/bin/cli/tray/autostart.ts +18 -0
- package/bin/cli/tray/icon.png +0 -0
- package/bin/cli/tray/index.mjs +28 -0
- package/bin/cli/tray/tray.ps1 +99 -0
- package/bin/cli/tray/tray.ts +186 -0
- package/bin/cli/tray/traySystray.mjs +135 -0
- package/bin/cli/tray/trayWin.ts +91 -0
- package/bin/cli/tray/trayWindows.mjs +75 -0
- package/bin/cli/tui/Dashboard.jsx +70 -0
- package/bin/cli/tui/EvalWatch.jsx +171 -0
- package/bin/cli/tui/InterfaceMenu.jsx +55 -0
- package/bin/cli/tui/OAuthFlow.jsx +193 -0
- package/bin/cli/tui/ProvidersTestAll.jsx +190 -0
- package/bin/cli/tui/Repl.jsx +392 -0
- package/bin/cli/tui/session.mjs +54 -0
- package/bin/cli/tui/tabs/Combos.jsx +47 -0
- package/bin/cli/tui/tabs/Cost.jsx +52 -0
- package/bin/cli/tui/tabs/Health.jsx +53 -0
- package/bin/cli/tui/tabs/Keys.jsx +48 -0
- package/bin/cli/tui/tabs/Logs.jsx +60 -0
- package/bin/cli/tui/tabs/Overview.jsx +80 -0
- package/bin/cli/tui/tabs/Providers.jsx +48 -0
- package/bin/cli/tui-components/CodeBlock.jsx +15 -0
- package/bin/cli/tui-components/ConfirmDialog.jsx +40 -0
- package/bin/cli/tui-components/DataTable.jsx +50 -0
- package/bin/cli/tui-components/HeaderSwr.jsx +25 -0
- package/bin/cli/tui-components/KeyMaskedDisplay.jsx +12 -0
- package/bin/cli/tui-components/MarkdownView.jsx +13 -0
- package/bin/cli/tui-components/MenuSelect.jsx +38 -0
- package/bin/cli/tui-components/MultilineInput.jsx +18 -0
- package/bin/cli/tui-components/ProgressBar.jsx +15 -0
- package/bin/cli/tui-components/Sparkline.jsx +15 -0
- package/bin/cli/tui-components/StatusBadge.jsx +17 -0
- package/bin/cli/tui-components/TokenCounter.jsx +18 -0
- package/bin/cli/tui-components/theme.jsx +11 -0
- package/bin/cli/utils/cliToken.mjs +22 -0
- package/bin/cli/utils/clipboard.mjs +35 -0
- package/bin/cli/utils/environment.mjs +50 -0
- package/bin/cli/utils/pid.mjs +110 -0
- package/bin/cli/utils/storageKeyProvision.mjs +31 -0
- package/bin/cold-start-bench.sh +82 -0
- package/bin/mcp-server.mjs +71 -0
- package/bin/nodeRuntimeSupport.mjs +84 -0
- package/bin/omniroute.mjs +237 -0
- package/bin/reset-password.mjs +137 -0
- package/bin/restore-data.sh +64 -0
- package/bin/restore-policies.sh +77 -0
- package/bin/rollback.sh +102 -0
- package/bin/snapshot-data.sh +61 -0
- package/open-sse/config/agyModels.ts +157 -0
- package/open-sse/config/anthropicHeaders.ts +127 -0
- package/open-sse/config/antigravityModelAliases.ts +309 -0
- package/open-sse/config/antigravityUpstream.ts +20 -0
- package/open-sse/config/audioRegistry.ts +547 -0
- package/open-sse/config/azureAi.ts +49 -0
- package/open-sse/config/bedrock.ts +196 -0
- package/open-sse/config/cliFingerprints.ts +405 -0
- package/open-sse/config/codexClient.ts +49 -0
- package/open-sse/config/codexIdentity.ts +87 -0
- package/open-sse/config/codexInstructions.ts +122 -0
- package/open-sse/config/codexQuotaScopes.ts +87 -0
- package/open-sse/config/constants.ts +281 -0
- package/open-sse/config/contextEditing.ts +156 -0
- package/open-sse/config/credentialLoader.ts +123 -0
- package/open-sse/config/datarobot.ts +69 -0
- package/open-sse/config/defaultThinkingSignature.ts +8 -0
- package/open-sse/config/embeddingRegistry.ts +434 -0
- package/open-sse/config/errorConfig.ts +201 -0
- package/open-sse/config/freeModelCatalog.data.ts +467 -0
- package/open-sse/config/freeModelCatalog.ts +142 -0
- package/open-sse/config/freeTierCatalog.ts +101 -0
- package/open-sse/config/geminiRateLimits.json +34 -0
- package/open-sse/config/glmProvider.ts +488 -0
- package/open-sse/config/imageRegistry.ts +752 -0
- package/open-sse/config/maritalk.ts +18 -0
- package/open-sse/config/mediaServiceKinds.ts +70 -0
- package/open-sse/config/moderationRegistry.ts +89 -0
- package/open-sse/config/musicRegistry.ts +115 -0
- package/open-sse/config/oci.ts +44 -0
- package/open-sse/config/ocrRegistry.ts +82 -0
- package/open-sse/config/ollamaModels.ts +28 -0
- package/open-sse/config/providerErrorRules.ts +218 -0
- package/open-sse/config/providerFieldStrips.ts +42 -0
- package/open-sse/config/providerHeaderProfiles.ts +188 -0
- package/open-sse/config/providerModels.ts +199 -0
- package/open-sse/config/providerPluginManifest.ts +186 -0
- package/open-sse/config/providerPluginManifestRegistry.ts +31 -0
- package/open-sse/config/providerPluginManifestUrl.ts +26 -0
- package/open-sse/config/providerRegistry.ts +257 -0
- package/open-sse/config/providers/index.ts +377 -0
- package/open-sse/config/providers/registry/adapta-web/index.ts +20 -0
- package/open-sse/config/providers/registry/agentrouter/index.ts +24 -0
- package/open-sse/config/providers/registry/agy/index.ts +28 -0
- package/open-sse/config/providers/registry/ai21/index.ts +13 -0
- package/open-sse/config/providers/registry/aimlapi/index.ts +21 -0
- package/open-sse/config/providers/registry/alibaba/cn/index.ts +15 -0
- package/open-sse/config/providers/registry/alibaba/index.ts +15 -0
- package/open-sse/config/providers/registry/anthropic/index.ts +52 -0
- package/open-sse/config/providers/registry/antigravity/index.ts +28 -0
- package/open-sse/config/providers/registry/api-airforce/index.ts +57 -0
- package/open-sse/config/providers/registry/auggie/index.ts +38 -0
- package/open-sse/config/providers/registry/bai/index.ts +14 -0
- package/open-sse/config/providers/registry/baichuan/index.ts +20 -0
- package/open-sse/config/providers/registry/baidu/index.ts +31 -0
- package/open-sse/config/providers/registry/bailian-coding-plan/index.ts +27 -0
- package/open-sse/config/providers/registry/baseten/index.ts +13 -0
- package/open-sse/config/providers/registry/bazaarlink/index.ts +48 -0
- package/open-sse/config/providers/registry/bedrock/index.ts +49 -0
- package/open-sse/config/providers/registry/blackbox/index.ts +25 -0
- package/open-sse/config/providers/registry/blackbox/web/index.ts +19 -0
- package/open-sse/config/providers/registry/bluesminds/index.ts +39 -0
- package/open-sse/config/providers/registry/byteplus/index.ts +21 -0
- package/open-sse/config/providers/registry/bytez/index.ts +17 -0
- package/open-sse/config/providers/registry/cerebras/index.ts +16 -0
- package/open-sse/config/providers/registry/charm-hyper/index.ts +14 -0
- package/open-sse/config/providers/registry/chatgpt-web/index.ts +23 -0
- package/open-sse/config/providers/registry/chipotle/index.ts +14 -0
- package/open-sse/config/providers/registry/chutes/index.ts +12 -0
- package/open-sse/config/providers/registry/claude/index.ts +102 -0
- package/open-sse/config/providers/registry/claude/web/index.ts +16 -0
- package/open-sse/config/providers/registry/cline/index.ts +45 -0
- package/open-sse/config/providers/registry/clinepass/index.ts +47 -0
- package/open-sse/config/providers/registry/cloudflare-ai/index.ts +33 -0
- package/open-sse/config/providers/registry/codebuddy-cn/index.ts +151 -0
- package/open-sse/config/providers/registry/codestral/index.ts +13 -0
- package/open-sse/config/providers/registry/codex/index.ts +115 -0
- package/open-sse/config/providers/registry/cohere/index.ts +28 -0
- package/open-sse/config/providers/registry/command-code/index.ts +143 -0
- package/open-sse/config/providers/registry/copilot-m365-web/index.ts +12 -0
- package/open-sse/config/providers/registry/copilot-web/index.ts +16 -0
- package/open-sse/config/providers/registry/coze/index.ts +12 -0
- package/open-sse/config/providers/registry/crof/index.ts +38 -0
- package/open-sse/config/providers/registry/cursor/index.ts +111 -0
- package/open-sse/config/providers/registry/databricks/index.ts +13 -0
- package/open-sse/config/providers/registry/deepinfra/index.ts +13 -0
- package/open-sse/config/providers/registry/deepseek/index.ts +15 -0
- package/open-sse/config/providers/registry/deepseek/web/index.ts +35 -0
- package/open-sse/config/providers/registry/devin-cli/index.ts +68 -0
- package/open-sse/config/providers/registry/dgrid/index.ts +15 -0
- package/open-sse/config/providers/registry/dify/index.ts +12 -0
- package/open-sse/config/providers/registry/digitalocean/index.ts +11 -0
- package/open-sse/config/providers/registry/dit/index.ts +41 -0
- package/open-sse/config/providers/registry/doubao/index.ts +28 -0
- package/open-sse/config/providers/registry/doubao/web/index.ts +15 -0
- package/open-sse/config/providers/registry/duckduckgo-web/index.ts +19 -0
- package/open-sse/config/providers/registry/factory/index.ts +33 -0
- package/open-sse/config/providers/registry/featherless-ai/index.ts +13 -0
- package/open-sse/config/providers/registry/fireworks/index.ts +35 -0
- package/open-sse/config/providers/registry/freeaiapikey/index.ts +38 -0
- package/open-sse/config/providers/registry/freemodel-dev/index.ts +19 -0
- package/open-sse/config/providers/registry/friendliai/index.ts +16 -0
- package/open-sse/config/providers/registry/galadriel/index.ts +13 -0
- package/open-sse/config/providers/registry/gemini/index.ts +63 -0
- package/open-sse/config/providers/registry/gemini/web/index.ts +16 -0
- package/open-sse/config/providers/registry/gigachat/index.ts +13 -0
- package/open-sse/config/providers/registry/github/index.ts +161 -0
- package/open-sse/config/providers/registry/github/models/index.ts +38 -0
- package/open-sse/config/providers/registry/gitlab-duo/index.ts +29 -0
- package/open-sse/config/providers/registry/gitlawb/gmi/index.ts +19 -0
- package/open-sse/config/providers/registry/gitlawb/index.ts +18 -0
- package/open-sse/config/providers/registry/glhf/index.ts +12 -0
- package/open-sse/config/providers/registry/glm/cn/index.ts +17 -0
- package/open-sse/config/providers/registry/glm/index.ts +16 -0
- package/open-sse/config/providers/registry/glm/t/index.ts +16 -0
- package/open-sse/config/providers/registry/grok-cli/index.ts +32 -0
- package/open-sse/config/providers/registry/grok-web/index.ts +18 -0
- package/open-sse/config/providers/registry/groq/index.ts +25 -0
- package/open-sse/config/providers/registry/hackclub/index.ts +19 -0
- package/open-sse/config/providers/registry/haiper/index.ts +15 -0
- package/open-sse/config/providers/registry/hcnsec/index.ts +11 -0
- package/open-sse/config/providers/registry/heroku/index.ts +13 -0
- package/open-sse/config/providers/registry/huggingchat/index.ts +143 -0
- package/open-sse/config/providers/registry/huggingface/index.ts +20 -0
- package/open-sse/config/providers/registry/hyperbolic/index.ts +21 -0
- package/open-sse/config/providers/registry/ideogram/index.ts +15 -0
- package/open-sse/config/providers/registry/iflytek/index.ts +21 -0
- package/open-sse/config/providers/registry/inclusionai/index.ts +12 -0
- package/open-sse/config/providers/registry/inference-net/index.ts +13 -0
- package/open-sse/config/providers/registry/inner-ai/index.ts +43 -0
- package/open-sse/config/providers/registry/kenari/index.ts +14 -0
- package/open-sse/config/providers/registry/kie/index.ts +27 -0
- package/open-sse/config/providers/registry/kilo-gateway/index.ts +21 -0
- package/open-sse/config/providers/registry/kilocode/index.ts +43 -0
- package/open-sse/config/providers/registry/kimi/coding/index.ts +17 -0
- package/open-sse/config/providers/registry/kimi/coding-apikey/index.ts +9 -0
- package/open-sse/config/providers/registry/kimi/index.ts +17 -0
- package/open-sse/config/providers/registry/kimi/web/index.ts +27 -0
- package/open-sse/config/providers/registry/kiro/index.ts +50 -0
- package/open-sse/config/providers/registry/kluster/index.ts +12 -0
- package/open-sse/config/providers/registry/lambda-ai/index.ts +13 -0
- package/open-sse/config/providers/registry/leonardo/index.ts +15 -0
- package/open-sse/config/providers/registry/liquid/index.ts +12 -0
- package/open-sse/config/providers/registry/llamagate/index.ts +13 -0
- package/open-sse/config/providers/registry/llm7/index.ts +27 -0
- package/open-sse/config/providers/registry/longcat/index.ts +24 -0
- package/open-sse/config/providers/registry/maritalk/index.ts +13 -0
- package/open-sse/config/providers/registry/meta-llama/index.ts +13 -0
- package/open-sse/config/providers/registry/mimocode/index.ts +16 -0
- package/open-sse/config/providers/registry/minimax/cn/index.ts +24 -0
- package/open-sse/config/providers/registry/minimax/index.ts +24 -0
- package/open-sse/config/providers/registry/mistral/index.ts +18 -0
- package/open-sse/config/providers/registry/modal/index.ts +12 -0
- package/open-sse/config/providers/registry/modelscope/index.ts +24 -0
- package/open-sse/config/providers/registry/monsterapi/index.ts +17 -0
- package/open-sse/config/providers/registry/moonshot/index.ts +13 -0
- package/open-sse/config/providers/registry/morph/index.ts +13 -0
- package/open-sse/config/providers/registry/muse-spark-web/index.ts +24 -0
- package/open-sse/config/providers/registry/nanogpt/index.ts +13 -0
- package/open-sse/config/providers/registry/nebius/index.ts +9 -0
- package/open-sse/config/providers/registry/nlpcloud/index.ts +19 -0
- package/open-sse/config/providers/registry/nous-research/index.ts +15 -0
- package/open-sse/config/providers/registry/novita/index.ts +15 -0
- package/open-sse/config/providers/registry/nscale/index.ts +13 -0
- package/open-sse/config/providers/registry/nube/index.ts +17 -0
- package/open-sse/config/providers/registry/nvidia/index.ts +36 -0
- package/open-sse/config/providers/registry/ollama-cloud/index.ts +27 -0
- package/open-sse/config/providers/registry/openadapter/index.ts +25 -0
- package/open-sse/config/providers/registry/openai/index.ts +43 -0
- package/open-sse/config/providers/registry/opencode/go/index.ts +61 -0
- package/open-sse/config/providers/registry/opencode/index.ts +51 -0
- package/open-sse/config/providers/registry/opencode/zen/index.ts +98 -0
- package/open-sse/config/providers/registry/openrouter/index.ts +17 -0
- package/open-sse/config/providers/registry/orcarouter/index.ts +87 -0
- package/open-sse/config/providers/registry/ovhcloud/index.ts +13 -0
- package/open-sse/config/providers/registry/perplexity/index.ts +22 -0
- package/open-sse/config/providers/registry/perplexity/web/index.ts +23 -0
- package/open-sse/config/providers/registry/pioneer/index.ts +41 -0
- package/open-sse/config/providers/registry/pollinations/index.ts +51 -0
- package/open-sse/config/providers/registry/predibase/index.ts +13 -0
- package/open-sse/config/providers/registry/publicai/index.ts +13 -0
- package/open-sse/config/providers/registry/puter/index.ts +70 -0
- package/open-sse/config/providers/registry/qianfan/index.ts +18 -0
- package/open-sse/config/providers/registry/qiniu/index.ts +15 -0
- package/open-sse/config/providers/registry/qoder/index.ts +37 -0
- package/open-sse/config/providers/registry/qwen/index.ts +25 -0
- package/open-sse/config/providers/registry/qwen/web/index.ts +24 -0
- package/open-sse/config/providers/registry/reka/index.ts +18 -0
- package/open-sse/config/providers/registry/requesty/index.ts +11 -0
- package/open-sse/config/providers/registry/sambanova/index.ts +13 -0
- package/open-sse/config/providers/registry/scaleway/index.ts +20 -0
- package/open-sse/config/providers/registry/sensenova/index.ts +27 -0
- package/open-sse/config/providers/registry/siliconflow/index.ts +84 -0
- package/open-sse/config/providers/registry/snowflake/index.ts +13 -0
- package/open-sse/config/providers/registry/sparkdesk/index.ts +20 -0
- package/open-sse/config/providers/registry/stepfun/index.ts +20 -0
- package/open-sse/config/providers/registry/sumopod/index.ts +15 -0
- package/open-sse/config/providers/registry/suno/index.ts +18 -0
- package/open-sse/config/providers/registry/synthetic/index.ts +21 -0
- package/open-sse/config/providers/registry/t3-web/index.ts +45 -0
- package/open-sse/config/providers/registry/tencent/index.ts +25 -0
- package/open-sse/config/providers/registry/theoldllm/index.ts +51 -0
- package/open-sse/config/providers/registry/together/index.ts +20 -0
- package/open-sse/config/providers/registry/tokenrouter/index.ts +44 -0
- package/open-sse/config/providers/registry/trae/index.ts +24 -0
- package/open-sse/config/providers/registry/udio/index.ts +12 -0
- package/open-sse/config/providers/registry/uncloseai/index.ts +19 -0
- package/open-sse/config/providers/registry/upstage/index.ts +13 -0
- package/open-sse/config/providers/registry/v0-vercel/index.ts +13 -0
- package/open-sse/config/providers/registry/venice/index.ts +13 -0
- package/open-sse/config/providers/registry/veoaifree-web/index.ts +15 -0
- package/open-sse/config/providers/registry/vercel-ai-gateway/index.ts +13 -0
- package/open-sse/config/providers/registry/vertex/index.ts +33 -0
- package/open-sse/config/providers/registry/vertex/partner/index.ts +22 -0
- package/open-sse/config/providers/registry/volcengine/index.ts +13 -0
- package/open-sse/config/providers/registry/wafer/index.ts +19 -0
- package/open-sse/config/providers/registry/wandb/index.ts +13 -0
- package/open-sse/config/providers/registry/windsurf/index.ts +119 -0
- package/open-sse/config/providers/registry/x5lab/index.ts +15 -0
- package/open-sse/config/providers/registry/xai/index.ts +18 -0
- package/open-sse/config/providers/registry/xiaomi-mimo/index.ts +13 -0
- package/open-sse/config/providers/registry/yi/index.ts +12 -0
- package/open-sse/config/providers/registry/yuanbao-web/index.ts +37 -0
- package/open-sse/config/providers/registry/zai/index.ts +28 -0
- package/open-sse/config/providers/registry/zed-hosted/index.ts +35 -0
- package/open-sse/config/providers/registry/zenmux/index.ts +87 -0
- package/open-sse/config/providers/registry/zenmux-free/index.ts +40 -0
- package/open-sse/config/providers/shared.ts +766 -0
- package/open-sse/config/registryUtils.ts +134 -0
- package/open-sse/config/rerankRegistry.ts +196 -0
- package/open-sse/config/runway.ts +39 -0
- package/open-sse/config/sap.ts +58 -0
- package/open-sse/config/searchRegistry.ts +317 -0
- package/open-sse/config/toolCloaking.ts +253 -0
- package/open-sse/config/videoRegistry.ts +229 -0
- package/open-sse/config/watsonx.ts +43 -0
- package/open-sse/executors/adapta-web.ts +564 -0
- package/open-sse/executors/antigravity/sseCollect.ts +148 -0
- package/open-sse/executors/antigravity.ts +1716 -0
- package/open-sse/executors/antigravityUpstreamError.ts +25 -0
- package/open-sse/executors/auggie.ts +573 -0
- package/open-sse/executors/azure-openai.ts +48 -0
- package/open-sse/executors/base/headers.ts +93 -0
- package/open-sse/executors/base/reasoningEffort.ts +160 -0
- package/open-sse/executors/base.ts +1315 -0
- package/open-sse/executors/bedrock.ts +714 -0
- package/open-sse/executors/blackbox-web.ts +708 -0
- package/open-sse/executors/chatgpt-web/models.ts +133 -0
- package/open-sse/executors/chatgpt-web.ts +3107 -0
- package/open-sse/executors/chatgptWebErrors.ts +18 -0
- package/open-sse/executors/chatgptWebTools.ts +127 -0
- package/open-sse/executors/chipotle.ts +432 -0
- package/open-sse/executors/claude-web/payload.ts +230 -0
- package/open-sse/executors/claude-web-with-auto-refresh.ts +117 -0
- package/open-sse/executors/claude-web.ts +833 -0
- package/open-sse/executors/claudeIdentity.ts +445 -0
- package/open-sse/executors/cliproxyapi.ts +466 -0
- package/open-sse/executors/cloudflare-ai.ts +97 -0
- package/open-sse/executors/codebuddy-cn.ts +53 -0
- package/open-sse/executors/codex/quota.ts +114 -0
- package/open-sse/executors/codex/tools.ts +165 -0
- package/open-sse/executors/codex.ts +1270 -0
- package/open-sse/executors/commandCode.ts +716 -0
- package/open-sse/executors/copilot-m365-connection.ts +271 -0
- package/open-sse/executors/copilot-m365-frames.ts +279 -0
- package/open-sse/executors/copilot-m365-web.ts +341 -0
- package/open-sse/executors/copilot-web.ts +722 -0
- package/open-sse/executors/cursor/composer.ts +53 -0
- package/open-sse/executors/cursor/prompt.ts +75 -0
- package/open-sse/executors/cursor.ts +1465 -0
- package/open-sse/executors/deepseek-web/stream-format.ts +44 -0
- package/open-sse/executors/deepseek-web-with-auto-refresh.ts +184 -0
- package/open-sse/executors/deepseek-web.ts +1123 -0
- package/open-sse/executors/default/urlNormalizers.ts +64 -0
- package/open-sse/executors/default.ts +873 -0
- package/open-sse/executors/devin-cli.ts +470 -0
- package/open-sse/executors/doubao-web.ts +665 -0
- package/open-sse/executors/duckduckgo-web/challenge.ts +151 -0
- package/open-sse/executors/duckduckgo-web.ts +782 -0
- package/open-sse/executors/firecrawl-fetch.ts +177 -0
- package/open-sse/executors/forceResponsesUpstream.ts +60 -0
- package/open-sse/executors/gemini-business.ts +446 -0
- package/open-sse/executors/gemini-web.ts +413 -0
- package/open-sse/executors/github.ts +376 -0
- package/open-sse/executors/gitlab.ts +793 -0
- package/open-sse/executors/gitlabResponses.ts +191 -0
- package/open-sse/executors/glm.ts +520 -0
- package/open-sse/executors/grok-cli.ts +253 -0
- package/open-sse/executors/grok-web/native-tools.ts +182 -0
- package/open-sse/executors/grok-web/text-cleanup.ts +137 -0
- package/open-sse/executors/grok-web/tool-bridge.ts +666 -0
- package/open-sse/executors/grok-web/types.ts +47 -0
- package/open-sse/executors/grok-web.ts +883 -0
- package/open-sse/executors/huggingchat/jsonlStream.ts +221 -0
- package/open-sse/executors/huggingchat.ts +593 -0
- package/open-sse/executors/index.ts +232 -0
- package/open-sse/executors/inner-ai.ts +764 -0
- package/open-sse/executors/jina-reader-fetch.ts +119 -0
- package/open-sse/executors/kie.ts +109 -0
- package/open-sse/executors/kimi-web.ts +455 -0
- package/open-sse/executors/kimi.ts +133 -0
- package/open-sse/executors/kiro/eventstream.ts +192 -0
- package/open-sse/executors/kiro.ts +821 -0
- package/open-sse/executors/kiroThinking.ts +116 -0
- package/open-sse/executors/lmarena.ts +511 -0
- package/open-sse/executors/mimocode.ts +560 -0
- package/open-sse/executors/muse-spark-web/response-parser.ts +383 -0
- package/open-sse/executors/muse-spark-web.ts +928 -0
- package/open-sse/executors/ninerouter.ts +212 -0
- package/open-sse/executors/nlpcloud.ts +546 -0
- package/open-sse/executors/opencode.ts +336 -0
- package/open-sse/executors/perplexity-web/protocol.ts +503 -0
- package/open-sse/executors/perplexity-web.ts +545 -0
- package/open-sse/executors/poe-web.ts +158 -0
- package/open-sse/executors/pollinations.ts +119 -0
- package/open-sse/executors/puter.ts +59 -0
- package/open-sse/executors/qoder.ts +416 -0
- package/open-sse/executors/qwen-web.ts +474 -0
- package/open-sse/executors/t3-chat-web.ts +582 -0
- package/open-sse/executors/tavily-fetch.ts +103 -0
- package/open-sse/executors/theoldllm.ts +354 -0
- package/open-sse/executors/tinyfish-fetch.ts +131 -0
- package/open-sse/executors/trae.ts +481 -0
- package/open-sse/executors/v0-vercel-web.ts +164 -0
- package/open-sse/executors/venice-web.ts +165 -0
- package/open-sse/executors/veoaifree-web.ts +397 -0
- package/open-sse/executors/vertex.ts +208 -0
- package/open-sse/executors/vertexMedia.ts +341 -0
- package/open-sse/executors/windsurf.ts +706 -0
- package/open-sse/executors/xai.ts +94 -0
- package/open-sse/executors/yuanbao-web.ts +504 -0
- package/open-sse/executors/zed-hosted.ts +364 -0
- package/open-sse/executors/zenmux-free.ts +283 -0
- package/open-sse/handlers/audioSpeech.ts +1060 -0
- package/open-sse/handlers/audioTranscription.ts +554 -0
- package/open-sse/handlers/audioTranslation.ts +135 -0
- package/open-sse/handlers/chatCore/attemptLogging.ts +210 -0
- package/open-sse/handlers/chatCore/backgroundRedirect.ts +41 -0
- package/open-sse/handlers/chatCore/cacheUsageMeta.ts +65 -0
- package/open-sse/handlers/chatCore/cavemanOutputAnalytics.ts +47 -0
- package/open-sse/handlers/chatCore/claudeClassifierCompat.ts +99 -0
- package/open-sse/handlers/chatCore/claudeEffortVariant.ts +62 -0
- package/open-sse/handlers/chatCore/claudeMessageTypes.ts +15 -0
- package/open-sse/handlers/chatCore/claudeSystemRole.ts +48 -0
- package/open-sse/handlers/chatCore/claudeToolDefaults.ts +27 -0
- package/open-sse/handlers/chatCore/claudeUpstreamMessages.ts +143 -0
- package/open-sse/handlers/chatCore/clientUsageBuffer.ts +54 -0
- package/open-sse/handlers/chatCore/clineResponseEnvelope.ts +25 -0
- package/open-sse/handlers/chatCore/codexFailover.ts +41 -0
- package/open-sse/handlers/chatCore/codexQuota.ts +85 -0
- package/open-sse/handlers/chatCore/comboContextCache.ts +63 -0
- package/open-sse/handlers/chatCore/compressionAnalyticsWrite.ts +149 -0
- package/open-sse/handlers/chatCore/compressionCacheStats.ts +53 -0
- package/open-sse/handlers/chatCore/compressionComboPredicates.ts +41 -0
- package/open-sse/handlers/chatCore/compressionSettings.ts +35 -0
- package/open-sse/handlers/chatCore/compressionUsageReceipt.ts +27 -0
- package/open-sse/handlers/chatCore/contextEditingTelemetry.ts +40 -0
- package/open-sse/handlers/chatCore/cooldownClassification.ts +26 -0
- package/open-sse/handlers/chatCore/executionCredentials.ts +72 -0
- package/open-sse/handlers/chatCore/executorClientHeaders.ts +36 -0
- package/open-sse/handlers/chatCore/executorHelpers.ts +151 -0
- package/open-sse/handlers/chatCore/executorProxy.ts +117 -0
- package/open-sse/handlers/chatCore/failureUsage.ts +41 -0
- package/open-sse/handlers/chatCore/gamificationEvent.ts +28 -0
- package/open-sse/handlers/chatCore/headers.ts +65 -0
- package/open-sse/handlers/chatCore/idempotency.ts +65 -0
- package/open-sse/handlers/chatCore/jsonBodyToSse.ts +161 -0
- package/open-sse/handlers/chatCore/keyHealth.ts +113 -0
- package/open-sse/handlers/chatCore/logTruncation.ts +93 -0
- package/open-sse/handlers/chatCore/memoryExtraction.ts +131 -0
- package/open-sse/handlers/chatCore/memorySkillsInjection.ts +165 -0
- package/open-sse/handlers/chatCore/nonStreamingJsonResponse.ts +16 -0
- package/open-sse/handlers/chatCore/nonStreamingResponseBody.ts +155 -0
- package/open-sse/handlers/chatCore/nonStreamingResponseHeaders.ts +46 -0
- package/open-sse/handlers/chatCore/nonStreamingResponseParse.ts +135 -0
- package/open-sse/handlers/chatCore/nonStreamingSse.ts +171 -0
- package/open-sse/handlers/chatCore/nonStreamingUsageStats.ts +90 -0
- package/open-sse/handlers/chatCore/outputStyleTelemetry.ts +53 -0
- package/open-sse/handlers/chatCore/passthroughHelpers.ts +83 -0
- package/open-sse/handlers/chatCore/passthroughToolNames.ts +65 -0
- package/open-sse/handlers/chatCore/pluginOnRequest.ts +65 -0
- package/open-sse/handlers/chatCore/pluginOnResponse.ts +34 -0
- package/open-sse/handlers/chatCore/postCallGuardrailContext.ts +47 -0
- package/open-sse/handlers/chatCore/quotaShareConsumption.ts +41 -0
- package/open-sse/handlers/chatCore/requestFormat.ts +111 -0
- package/open-sse/handlers/chatCore/requestSetup.ts +51 -0
- package/open-sse/handlers/chatCore/responseHeaders.ts +138 -0
- package/open-sse/handlers/chatCore/sanitization.ts +63 -0
- package/open-sse/handlers/chatCore/semanticCache.ts +98 -0
- package/open-sse/handlers/chatCore/semanticCacheStore.ts +73 -0
- package/open-sse/handlers/chatCore/serviceTier.ts +70 -0
- package/open-sse/handlers/chatCore/skillsFormat.ts +33 -0
- package/open-sse/handlers/chatCore/stageTrace.ts +30 -0
- package/open-sse/handlers/chatCore/streamErrorResult.ts +58 -0
- package/open-sse/handlers/chatCore/streamFinalize.ts +48 -0
- package/open-sse/handlers/chatCore/streamingCost.ts +37 -0
- package/open-sse/handlers/chatCore/streamingPipeline.ts +99 -0
- package/open-sse/handlers/chatCore/streamingQuotaShare.ts +54 -0
- package/open-sse/handlers/chatCore/streamingResponseHeaders.ts +39 -0
- package/open-sse/handlers/chatCore/streamingSemanticCacheStore.ts +95 -0
- package/open-sse/handlers/chatCore/streamingUsageStats.ts +79 -0
- package/open-sse/handlers/chatCore/targetFormat.ts +34 -0
- package/open-sse/handlers/chatCore/telemetryHelpers.ts +78 -0
- package/open-sse/handlers/chatCore/upstreamBody.ts +168 -0
- package/open-sse/handlers/chatCore/upstreamExecuteHeaders.ts +71 -0
- package/open-sse/handlers/chatCore/upstreamTimeouts.ts +158 -0
- package/open-sse/handlers/chatCore.ts +4452 -0
- package/open-sse/handlers/embeddings.ts +378 -0
- package/open-sse/handlers/imageGeneration/providers/chatgptWeb.ts +187 -0
- package/open-sse/handlers/imageGeneration/providers/comfyUI.ts +116 -0
- package/open-sse/handlers/imageGeneration/providers/haiper.ts +120 -0
- package/open-sse/handlers/imageGeneration/providers/huggingface.ts +90 -0
- package/open-sse/handlers/imageGeneration/providers/hyperbolic.ts +100 -0
- package/open-sse/handlers/imageGeneration/providers/ideogram.ts +96 -0
- package/open-sse/handlers/imageGeneration/providers/imagen3.ts +136 -0
- package/open-sse/handlers/imageGeneration/providers/leonardo.ts +140 -0
- package/open-sse/handlers/imageGeneration/providers/nvidiaNim.ts +286 -0
- package/open-sse/handlers/imageGeneration/providers/sdWebUI.ts +94 -0
- package/open-sse/handlers/imageGeneration.ts +2880 -0
- package/open-sse/handlers/moderations.ts +82 -0
- package/open-sse/handlers/musicGeneration.ts +640 -0
- package/open-sse/handlers/ocr.ts +79 -0
- package/open-sse/handlers/rerank.ts +210 -0
- package/open-sse/handlers/responseSanitizer/reasoning.ts +149 -0
- package/open-sse/handlers/responseSanitizer.ts +1086 -0
- package/open-sse/handlers/responseTranslator.ts +640 -0
- package/open-sse/handlers/responsesHandler.ts +92 -0
- package/open-sse/handlers/search.ts +1545 -0
- package/open-sse/handlers/sseParser.ts +825 -0
- package/open-sse/handlers/usageExtractor.ts +93 -0
- package/open-sse/handlers/videoGeneration/googleFlow.ts +219 -0
- package/open-sse/handlers/videoGeneration/googleFlowHandler.ts +145 -0
- package/open-sse/handlers/videoGeneration.ts +1264 -0
- package/open-sse/handlers/webFetch.ts +130 -0
- package/open-sse/index.ts +170 -0
- package/open-sse/lib/deepseek-pow-solver.cjs +3 -0
- package/open-sse/lib/deepseek-pow.ts +189 -0
- package/open-sse/lib/sha3_wasm_bg.wasm +0 -0
- package/open-sse/mcp-server/README.md +611 -0
- package/open-sse/mcp-server/audit.ts +478 -0
- package/open-sse/mcp-server/catalog.ts +290 -0
- package/open-sse/mcp-server/descriptionCompressor.ts +243 -0
- package/open-sse/mcp-server/httpAuthContext.ts +42 -0
- package/open-sse/mcp-server/httpTransport.ts +306 -0
- package/open-sse/mcp-server/index.ts +19 -0
- package/open-sse/mcp-server/mcpCallerIdentity.ts +53 -0
- package/open-sse/mcp-server/runtimeHeartbeat.ts +162 -0
- package/open-sse/mcp-server/schemas/a2a.ts +203 -0
- package/open-sse/mcp-server/schemas/audit.ts +121 -0
- package/open-sse/mcp-server/schemas/index.ts +116 -0
- package/open-sse/mcp-server/schemas/pickFastestModel.ts +110 -0
- package/open-sse/mcp-server/schemas/toolDefinition.ts +31 -0
- package/open-sse/mcp-server/schemas/toolSearch.ts +37 -0
- package/open-sse/mcp-server/schemas/tools.ts +1481 -0
- package/open-sse/mcp-server/scopeEnforcement.ts +135 -0
- package/open-sse/mcp-server/server.ts +1370 -0
- package/open-sse/mcp-server/toolCardinality.ts +254 -0
- package/open-sse/mcp-server/toolSearch/catalog.ts +98 -0
- package/open-sse/mcp-server/toolSearch/handler.ts +18 -0
- package/open-sse/mcp-server/toolSearch/index.ts +5 -0
- package/open-sse/mcp-server/toolSearch/register.ts +36 -0
- package/open-sse/mcp-server/toolSearch/search.ts +96 -0
- package/open-sse/mcp-server/toolSearch/signature.ts +92 -0
- package/open-sse/mcp-server/tools/advancedTools.ts +1119 -0
- package/open-sse/mcp-server/tools/agentSkillTools.ts +83 -0
- package/open-sse/mcp-server/tools/compressionTools.ts +451 -0
- package/open-sse/mcp-server/tools/gamificationTools.ts +148 -0
- package/open-sse/mcp-server/tools/githubSkillTools.ts +141 -0
- package/open-sse/mcp-server/tools/memoryTools.ts +137 -0
- package/open-sse/mcp-server/tools/notionTools.ts +106 -0
- package/open-sse/mcp-server/tools/obsidianTools.ts +327 -0
- package/open-sse/mcp-server/tools/pickFastestModel.ts +293 -0
- package/open-sse/mcp-server/tools/pluginTools.ts +216 -0
- package/open-sse/mcp-server/tools/poolTools.ts +205 -0
- package/open-sse/mcp-server/tools/skillTools.ts +119 -0
- package/open-sse/package.json +17 -0
- package/open-sse/services/AGENTS.md +78 -0
- package/open-sse/services/accountFallback.ts +1863 -0
- package/open-sse/services/accountSelector.ts +80 -0
- package/open-sse/services/accountSemaphore.ts +367 -0
- package/open-sse/services/antigravity429Engine.ts +178 -0
- package/open-sse/services/antigravityClientProfile.ts +167 -0
- package/open-sse/services/antigravityCredits.ts +68 -0
- package/open-sse/services/antigravityHeaderScrub.ts +75 -0
- package/open-sse/services/antigravityHeaders.ts +121 -0
- package/open-sse/services/antigravityIdentity.ts +127 -0
- package/open-sse/services/antigravityObfuscation.ts +64 -0
- package/open-sse/services/antigravityProjectBootstrap.ts +145 -0
- package/open-sse/services/antigravityQuotaFamily.ts +56 -0
- package/open-sse/services/antigravityVersion.ts +163 -0
- package/open-sse/services/apiKeyRotator.ts +385 -0
- package/open-sse/services/autoCombo/autoPrefix.ts +61 -0
- package/open-sse/services/autoCombo/builtinCatalog.ts +126 -0
- package/open-sse/services/autoCombo/complexityRouter.ts +111 -0
- package/open-sse/services/autoCombo/engine.ts +314 -0
- package/open-sse/services/autoCombo/index.ts +18 -0
- package/open-sse/services/autoCombo/modePacks.ts +105 -0
- package/open-sse/services/autoCombo/modelFamily.ts +95 -0
- package/open-sse/services/autoCombo/paidModelFilter.ts +44 -0
- package/open-sse/services/autoCombo/persistence.ts +124 -0
- package/open-sse/services/autoCombo/pipelineRouter.ts +418 -0
- package/open-sse/services/autoCombo/providerDiversity.ts +170 -0
- package/open-sse/services/autoCombo/providerRegistryAccessor.ts +9 -0
- package/open-sse/services/autoCombo/requestControls.ts +80 -0
- package/open-sse/services/autoCombo/routerStrategy.ts +375 -0
- package/open-sse/services/autoCombo/scoring.ts +242 -0
- package/open-sse/services/autoCombo/selfHealing.ts +167 -0
- package/open-sse/services/autoCombo/speedRanking.ts +327 -0
- package/open-sse/services/autoCombo/suffixComposition.ts +147 -0
- package/open-sse/services/autoCombo/taskFitness.ts +407 -0
- package/open-sse/services/autoCombo/virtualFactory.ts +446 -0
- package/open-sse/services/autoRefreshDaemon.ts +206 -0
- package/open-sse/services/backgroundTaskDetector.ts +263 -0
- package/open-sse/services/bailianQuotaFetcher.ts +333 -0
- package/open-sse/services/batchProcessor.ts +914 -0
- package/open-sse/services/bedrock.ts +160 -0
- package/open-sse/services/browserBackedChat.ts +849 -0
- package/open-sse/services/browserPool.ts +501 -0
- package/open-sse/services/ccBridgeTransforms.ts +581 -0
- package/open-sse/services/ccWireImageBuiltins.ts +26 -0
- package/open-sse/services/chatgptImageCache.ts +143 -0
- package/open-sse/services/chatgptTlsClient.ts +628 -0
- package/open-sse/services/claudeAdaptiveThinking.ts +52 -0
- package/open-sse/services/claudeCodeCCH.ts +49 -0
- package/open-sse/services/claudeCodeCompatible.ts +1198 -0
- package/open-sse/services/claudeCodeCompatibleBeta.ts +23 -0
- package/open-sse/services/claudeCodeCompatibleThinkingDisplay.ts +34 -0
- package/open-sse/services/claudeCodeConstraints.ts +144 -0
- package/open-sse/services/claudeCodeExtraRemap.ts +18 -0
- package/open-sse/services/claudeCodeFingerprint.ts +46 -0
- package/open-sse/services/claudeCodeObfuscation.ts +116 -0
- package/open-sse/services/claudeCodeToolRemapper.ts +339 -0
- package/open-sse/services/claudeHaikuConstraints.ts +88 -0
- package/open-sse/services/claudeTlsClient.ts +590 -0
- package/open-sse/services/claudeTurnstileSolver.ts +206 -0
- package/open-sse/services/claudeUsageCooldown.ts +51 -0
- package/open-sse/services/claudeWebAutoRefresh.ts +224 -0
- package/open-sse/services/clinepassModels.ts +76 -0
- package/open-sse/services/cloudCodeHeaders.ts +41 -0
- package/open-sse/services/cloudCodeThinking.ts +71 -0
- package/open-sse/services/codeAssistSubscription.ts +83 -0
- package/open-sse/services/codexQuotaFetcher.ts +523 -0
- package/open-sse/services/codexUsageQuotas.ts +270 -0
- package/open-sse/services/codexVerbosity.ts +59 -0
- package/open-sse/services/combo/applyStrategyOrdering.ts +226 -0
- package/open-sse/services/combo/autoConfig.ts +62 -0
- package/open-sse/services/combo/autoStrategy.ts +475 -0
- package/open-sse/services/combo/comboCompatFallback.ts +82 -0
- package/open-sse/services/combo/comboCooldownRetry.ts +237 -0
- package/open-sse/services/combo/comboData.ts +24 -0
- package/open-sse/services/combo/comboPredicates.ts +211 -0
- package/open-sse/services/combo/comboSetup.ts +135 -0
- package/open-sse/services/combo/comboStructure.ts +766 -0
- package/open-sse/services/combo/concurrencyCaps.ts +76 -0
- package/open-sse/services/combo/context.ts +46 -0
- package/open-sse/services/combo/fingerprintExpansion.ts +105 -0
- package/open-sse/services/combo/headroomRanking.ts +91 -0
- package/open-sse/services/combo/providerWildcard.ts +253 -0
- package/open-sse/services/combo/quotaExhaustionCutoff.ts +140 -0
- package/open-sse/services/combo/quotaScoring.ts +311 -0
- package/open-sse/services/combo/quotaShareConcurrency.ts +74 -0
- package/open-sse/services/combo/quotaShareInflight.ts +133 -0
- package/open-sse/services/combo/quotaShareStrategy.ts +349 -0
- package/open-sse/services/combo/quotaStrategies.ts +647 -0
- package/open-sse/services/combo/resolveAutoStrategy.ts +334 -0
- package/open-sse/services/combo/responseValidation.ts +206 -0
- package/open-sse/services/combo/rrState.ts +98 -0
- package/open-sse/services/combo/runtimeUnits.ts +269 -0
- package/open-sse/services/combo/sessionStickiness.ts +301 -0
- package/open-sse/services/combo/shadowRouting.ts +179 -0
- package/open-sse/services/combo/targetExhaustion.ts +160 -0
- package/open-sse/services/combo/targetSorters.ts +174 -0
- package/open-sse/services/combo/targetTimeoutRunner.ts +91 -0
- package/open-sse/services/combo/types.ts +175 -0
- package/open-sse/services/combo/validateQuality.ts +445 -0
- package/open-sse/services/combo.ts +3085 -0
- package/open-sse/services/comboAgentMiddleware.ts +214 -0
- package/open-sse/services/comboConfig.ts +248 -0
- package/open-sse/services/comboManifestMetrics.ts +13 -0
- package/open-sse/services/comboMetrics.ts +480 -0
- package/open-sse/services/compression/adaptiveCompression/computeTarget.ts +31 -0
- package/open-sse/services/compression/adaptiveCompression/ladder.ts +59 -0
- package/open-sse/services/compression/adaptiveCompression/resolveAdaptivePlan.ts +104 -0
- package/open-sse/services/compression/adaptiveCompression/types.ts +61 -0
- package/open-sse/services/compression/aggressive.ts +204 -0
- package/open-sse/services/compression/bodyAdapter.ts +354 -0
- package/open-sse/services/compression/cacheAwareConfig.ts +60 -0
- package/open-sse/services/compression/cachingAware.ts +130 -0
- package/open-sse/services/compression/caveman.ts +602 -0
- package/open-sse/services/compression/cavemanRules.ts +432 -0
- package/open-sse/services/compression/deriveDefaultPlan.ts +59 -0
- package/open-sse/services/compression/diffHelper.ts +219 -0
- package/open-sse/services/compression/engineBreakdown.ts +29 -0
- package/open-sse/services/compression/engineCatalog.ts +91 -0
- package/open-sse/services/compression/engines/cavemanAdapter.ts +454 -0
- package/open-sse/services/compression/engines/ccr/ccrQuery.ts +110 -0
- package/open-sse/services/compression/engines/ccr/index.ts +460 -0
- package/open-sse/services/compression/engines/headroom/encoderComparison.ts +72 -0
- package/open-sse/services/compression/engines/headroom/gcf/decode_generic.ts +711 -0
- package/open-sse/services/compression/engines/headroom/gcf/generic.ts +332 -0
- package/open-sse/services/compression/engines/headroom/gcf/index.ts +9 -0
- package/open-sse/services/compression/engines/headroom/gcf/scalar.ts +336 -0
- package/open-sse/services/compression/engines/headroom/index.ts +286 -0
- package/open-sse/services/compression/engines/headroom/smartcrusher.ts +255 -0
- package/open-sse/services/compression/engines/headroom/tabular.ts +263 -0
- package/open-sse/services/compression/engines/headroom/toon.ts +43 -0
- package/open-sse/services/compression/engines/index.ts +42 -0
- package/open-sse/services/compression/engines/ionizer/index.ts +124 -0
- package/open-sse/services/compression/engines/ionizer/sample.ts +200 -0
- package/open-sse/services/compression/engines/llm/index.ts +346 -0
- package/open-sse/services/compression/engines/llmlingua/constants.ts +55 -0
- package/open-sse/services/compression/engines/llmlingua/index.ts +474 -0
- package/open-sse/services/compression/engines/llmlingua/modelStore.ts +67 -0
- package/open-sse/services/compression/engines/llmlingua/onnxWorker.ts +117 -0
- package/open-sse/services/compression/engines/llmlingua/ultraEntry.ts +109 -0
- package/open-sse/services/compression/engines/llmlingua/worker.ts +373 -0
- package/open-sse/services/compression/engines/mcpAccessibility/collapseRepeated.ts +121 -0
- package/open-sse/services/compression/engines/mcpAccessibility/constants.ts +63 -0
- package/open-sse/services/compression/engines/mcpAccessibility/index.ts +52 -0
- package/open-sse/services/compression/engines/readLifecycle/index.ts +299 -0
- package/open-sse/services/compression/engines/registry.ts +87 -0
- package/open-sse/services/compression/engines/relevance/configSchema.ts +63 -0
- package/open-sse/services/compression/engines/relevance/index.ts +185 -0
- package/open-sse/services/compression/engines/relevance/scorer.ts +85 -0
- package/open-sse/services/compression/engines/rtk/codeStripper.ts +145 -0
- package/open-sse/services/compression/engines/rtk/commandDetector.ts +482 -0
- package/open-sse/services/compression/engines/rtk/configSchema.ts +117 -0
- package/open-sse/services/compression/engines/rtk/deduplicator.ts +37 -0
- package/open-sse/services/compression/engines/rtk/discover.ts +150 -0
- package/open-sse/services/compression/engines/rtk/filterLoader.ts +245 -0
- package/open-sse/services/compression/engines/rtk/filterSchema.ts +207 -0
- package/open-sse/services/compression/engines/rtk/filters/aws.json +34 -0
- package/open-sse/services/compression/engines/rtk/filters/biome.json +35 -0
- package/open-sse/services/compression/engines/rtk/filters/build-eslint.json +37 -0
- package/open-sse/services/compression/engines/rtk/filters/build-typescript.json +33 -0
- package/open-sse/services/compression/engines/rtk/filters/build-vite.json +41 -0
- package/open-sse/services/compression/engines/rtk/filters/build-webpack.json +34 -0
- package/open-sse/services/compression/engines/rtk/filters/bundle-install.json +35 -0
- package/open-sse/services/compression/engines/rtk/filters/composer.json +81 -0
- package/open-sse/services/compression/engines/rtk/filters/curl.json +34 -0
- package/open-sse/services/compression/engines/rtk/filters/df.json +34 -0
- package/open-sse/services/compression/engines/rtk/filters/docker-build.json +78 -0
- package/open-sse/services/compression/engines/rtk/filters/docker-logs.json +42 -0
- package/open-sse/services/compression/engines/rtk/filters/docker-ps.json +33 -0
- package/open-sse/services/compression/engines/rtk/filters/dotnet.json +47 -0
- package/open-sse/services/compression/engines/rtk/filters/du.json +33 -0
- package/open-sse/services/compression/engines/rtk/filters/error-stacktrace.json +41 -0
- package/open-sse/services/compression/engines/rtk/filters/gcloud.json +34 -0
- package/open-sse/services/compression/engines/rtk/filters/generic-output.json +32 -0
- package/open-sse/services/compression/engines/rtk/filters/gh.json +98 -0
- package/open-sse/services/compression/engines/rtk/filters/git-branch.json +45 -0
- package/open-sse/services/compression/engines/rtk/filters/git-diff.json +33 -0
- package/open-sse/services/compression/engines/rtk/filters/git-log.json +33 -0
- package/open-sse/services/compression/engines/rtk/filters/git-status.json +40 -0
- package/open-sse/services/compression/engines/rtk/filters/golangci-lint.json +34 -0
- package/open-sse/services/compression/engines/rtk/filters/gradle.json +47 -0
- package/open-sse/services/compression/engines/rtk/filters/json-output.json +40 -0
- package/open-sse/services/compression/engines/rtk/filters/kubectl.json +99 -0
- package/open-sse/services/compression/engines/rtk/filters/make.json +38 -0
- package/open-sse/services/compression/engines/rtk/filters/mypy.json +34 -0
- package/open-sse/services/compression/engines/rtk/filters/npm-audit.json +43 -0
- package/open-sse/services/compression/engines/rtk/filters/npm-install.json +41 -0
- package/open-sse/services/compression/engines/rtk/filters/nx.json +34 -0
- package/open-sse/services/compression/engines/rtk/filters/pip.json +41 -0
- package/open-sse/services/compression/engines/rtk/filters/playwright.json +42 -0
- package/open-sse/services/compression/engines/rtk/filters/poetry-install.json +35 -0
- package/open-sse/services/compression/engines/rtk/filters/prettier.json +40 -0
- package/open-sse/services/compression/engines/rtk/filters/ps.json +34 -0
- package/open-sse/services/compression/engines/rtk/filters/rsync.json +33 -0
- package/open-sse/services/compression/engines/rtk/filters/rubocop.json +34 -0
- package/open-sse/services/compression/engines/rtk/filters/ruff.json +40 -0
- package/open-sse/services/compression/engines/rtk/filters/shell-find.json +33 -0
- package/open-sse/services/compression/engines/rtk/filters/shell-grep.json +37 -0
- package/open-sse/services/compression/engines/rtk/filters/shell-ls.json +33 -0
- package/open-sse/services/compression/engines/rtk/filters/ssh.json +43 -0
- package/open-sse/services/compression/engines/rtk/filters/systemctl-status.json +43 -0
- package/open-sse/services/compression/engines/rtk/filters/terraform-plan.json +34 -0
- package/open-sse/services/compression/engines/rtk/filters/test-cargo.json +42 -0
- package/open-sse/services/compression/engines/rtk/filters/test-go.json +41 -0
- package/open-sse/services/compression/engines/rtk/filters/test-jest.json +43 -0
- package/open-sse/services/compression/engines/rtk/filters/test-pytest.json +41 -0
- package/open-sse/services/compression/engines/rtk/filters/test-vitest.json +43 -0
- package/open-sse/services/compression/engines/rtk/filters/tofu-plan.json +34 -0
- package/open-sse/services/compression/engines/rtk/filters/turbo.json +34 -0
- package/open-sse/services/compression/engines/rtk/filters/uv-sync.json +35 -0
- package/open-sse/services/compression/engines/rtk/filters/wget.json +34 -0
- package/open-sse/services/compression/engines/rtk/grouper.ts +99 -0
- package/open-sse/services/compression/engines/rtk/index.ts +706 -0
- package/open-sse/services/compression/engines/rtk/learn.ts +290 -0
- package/open-sse/services/compression/engines/rtk/lineFilter.ts +178 -0
- package/open-sse/services/compression/engines/rtk/rawOutput.ts +208 -0
- package/open-sse/services/compression/engines/rtk/renderers/gitDiff.ts +39 -0
- package/open-sse/services/compression/engines/rtk/renderers/index.ts +50 -0
- package/open-sse/services/compression/engines/rtk/renderers/structuredTable.ts +96 -0
- package/open-sse/services/compression/engines/rtk/renderers/terraformPlan.ts +40 -0
- package/open-sse/services/compression/engines/rtk/renderers/testGreen.ts +70 -0
- package/open-sse/services/compression/engines/rtk/renderers/types.ts +13 -0
- package/open-sse/services/compression/engines/rtk/smartTruncate.ts +67 -0
- package/open-sse/services/compression/engines/rtk/splitCompositeCommand.ts +111 -0
- package/open-sse/services/compression/engines/rtk/verify.ts +107 -0
- package/open-sse/services/compression/engines/session-dedup/fuzzy.ts +153 -0
- package/open-sse/services/compression/engines/session-dedup/index.ts +435 -0
- package/open-sse/services/compression/engines/types.ts +77 -0
- package/open-sse/services/compression/entrypointWrap.ts +43 -0
- package/open-sse/services/compression/eval/aggregate.ts +62 -0
- package/open-sse/services/compression/eval/corpus.ts +45 -0
- package/open-sse/services/compression/eval/costMeter.ts +31 -0
- package/open-sse/services/compression/eval/executorModelClient.ts +44 -0
- package/open-sse/services/compression/eval/fidelityCheck.ts +61 -0
- package/open-sse/services/compression/eval/grader.ts +27 -0
- package/open-sse/services/compression/eval/judge.ts +68 -0
- package/open-sse/services/compression/eval/report.ts +44 -0
- package/open-sse/services/compression/eval/runner.ts +135 -0
- package/open-sse/services/compression/eval/savings.ts +30 -0
- package/open-sse/services/compression/eval/seedCorpus.ts +60 -0
- package/open-sse/services/compression/eval/types.ts +65 -0
- package/open-sse/services/compression/fidelityGate.ts +124 -0
- package/open-sse/services/compression/fidelityGateStep.ts +44 -0
- package/open-sse/services/compression/hardBudget.ts +196 -0
- package/open-sse/services/compression/harness/benchmark.ts +318 -0
- package/open-sse/services/compression/harness/budgetGate.ts +62 -0
- package/open-sse/services/compression/harness/index.ts +52 -0
- package/open-sse/services/compression/harness/measure.ts +98 -0
- package/open-sse/services/compression/harness/replay.ts +72 -0
- package/open-sse/services/compression/harness/runner.ts +58 -0
- package/open-sse/services/compression/index.ts +165 -0
- package/open-sse/services/compression/languageDetector.ts +51 -0
- package/open-sse/services/compression/lite.ts +241 -0
- package/open-sse/services/compression/messageContent.ts +89 -0
- package/open-sse/services/compression/outputMode.ts +175 -0
- package/open-sse/services/compression/outputStyles/apply.ts +135 -0
- package/open-sse/services/compression/outputStyles/backCompat.ts +29 -0
- package/open-sse/services/compression/outputStyles/catalog.ts +76 -0
- package/open-sse/services/compression/outputStyles/telemetry.ts +50 -0
- package/open-sse/services/compression/pipelineEngineBreaker.ts +139 -0
- package/open-sse/services/compression/pipelineGuards.ts +45 -0
- package/open-sse/services/compression/planResolution.ts +128 -0
- package/open-sse/services/compression/prefixFreeze.ts +124 -0
- package/open-sse/services/compression/preservation.ts +0 -0
- package/open-sse/services/compression/preserveSystemPromptMode.ts +72 -0
- package/open-sse/services/compression/progressiveAging.ts +145 -0
- package/open-sse/services/compression/quantumLock/index.ts +17 -0
- package/open-sse/services/compression/quantumLock/quantumLock.ts +58 -0
- package/open-sse/services/compression/quantumLock/quantumLockStep.ts +72 -0
- package/open-sse/services/compression/quantumLock/quantumPatterns.ts +80 -0
- package/open-sse/services/compression/quantumLock/strategyWrap.ts +72 -0
- package/open-sse/services/compression/resolveCompressionPlan.ts +28 -0
- package/open-sse/services/compression/resultMemo.ts +83 -0
- package/open-sse/services/compression/riskGate/index.ts +3 -0
- package/open-sse/services/compression/riskGate/riskGate.ts +136 -0
- package/open-sse/services/compression/riskGate/riskGateStep.ts +115 -0
- package/open-sse/services/compression/riskGate/riskPatterns.ts +61 -0
- package/open-sse/services/compression/riskGate/strategyWrap.ts +44 -0
- package/open-sse/services/compression/ruleLoader.ts +273 -0
- package/open-sse/services/compression/rules/_schema.json +31 -0
- package/open-sse/services/compression/rules/de/context.json +38 -0
- package/open-sse/services/compression/rules/de/dedup.json +38 -0
- package/open-sse/services/compression/rules/de/filler.json +70 -0
- package/open-sse/services/compression/rules/de/structural.json +30 -0
- package/open-sse/services/compression/rules/de/ultra.json +107 -0
- package/open-sse/services/compression/rules/en/context.json +88 -0
- package/open-sse/services/compression/rules/en/dedup.json +38 -0
- package/open-sse/services/compression/rules/en/filler.json +129 -0
- package/open-sse/services/compression/rules/en/structural.json +102 -0
- package/open-sse/services/compression/rules/en/ultra.json +107 -0
- package/open-sse/services/compression/rules/es/context.json +87 -0
- package/open-sse/services/compression/rules/es/dedup.json +38 -0
- package/open-sse/services/compression/rules/es/filler.json +110 -0
- package/open-sse/services/compression/rules/es/structural.json +105 -0
- package/open-sse/services/compression/rules/es/ultra.json +107 -0
- package/open-sse/services/compression/rules/fr/context.json +38 -0
- package/open-sse/services/compression/rules/fr/dedup.json +38 -0
- package/open-sse/services/compression/rules/fr/filler.json +70 -0
- package/open-sse/services/compression/rules/fr/structural.json +30 -0
- package/open-sse/services/compression/rules/fr/ultra.json +107 -0
- package/open-sse/services/compression/rules/id/context.json +113 -0
- package/open-sse/services/compression/rules/id/dedup.json +38 -0
- package/open-sse/services/compression/rules/id/filler.json +138 -0
- package/open-sse/services/compression/rules/id/structural.json +111 -0
- package/open-sse/services/compression/rules/id/ultra.json +252 -0
- package/open-sse/services/compression/rules/ja/context.json +38 -0
- package/open-sse/services/compression/rules/ja/dedup.json +38 -0
- package/open-sse/services/compression/rules/ja/filler.json +70 -0
- package/open-sse/services/compression/rules/ja/structural.json +30 -0
- package/open-sse/services/compression/rules/ja/ultra.json +86 -0
- package/open-sse/services/compression/rules/pt-BR/context.json +69 -0
- package/open-sse/services/compression/rules/pt-BR/dedup.json +51 -0
- package/open-sse/services/compression/rules/pt-BR/filler.json +151 -0
- package/open-sse/services/compression/rules/pt-BR/structural.json +78 -0
- package/open-sse/services/compression/rules/pt-BR/ultra.json +192 -0
- package/open-sse/services/compression/rules/zh/dedup.json +38 -0
- package/open-sse/services/compression/rules/zh/filler.json +54 -0
- package/open-sse/services/compression/rules/zh/ultra.json +55 -0
- package/open-sse/services/compression/stackedStepCore.ts +87 -0
- package/open-sse/services/compression/stats.ts +59 -0
- package/open-sse/services/compression/strategySelector.ts +1007 -0
- package/open-sse/services/compression/summarizer.ts +244 -0
- package/open-sse/services/compression/toolResultCompressor.ts +283 -0
- package/open-sse/services/compression/types.ts +479 -0
- package/open-sse/services/compression/ultra.ts +321 -0
- package/open-sse/services/compression/ultraHeuristic.ts +157 -0
- package/open-sse/services/compression/validation.ts +432 -0
- package/open-sse/services/contextHandoff.ts +770 -0
- package/open-sse/services/contextManager.ts +617 -0
- package/open-sse/services/credentialGate.ts +84 -0
- package/open-sse/services/crofUsageFetcher.ts +182 -0
- package/open-sse/services/cursorSessionManager.ts +208 -0
- package/open-sse/services/deepseekQuotaFetcher.ts +244 -0
- package/open-sse/services/deviceTracker.ts +307 -0
- package/open-sse/services/emergencyFallback.ts +162 -0
- package/open-sse/services/errorClassifier.ts +198 -0
- package/open-sse/services/evalRouting.ts +276 -0
- package/open-sse/services/freeWebSearch.ts +154 -0
- package/open-sse/services/fusion.ts +337 -0
- package/open-sse/services/geminiRateLimitTracker.ts +145 -0
- package/open-sse/services/geminiThoughtSignatureStore.ts +329 -0
- package/open-sse/services/genericQuotaFetcher.ts +215 -0
- package/open-sse/services/gigachatAuth.ts +113 -0
- package/open-sse/services/githubCopilotModels.ts +162 -0
- package/open-sse/services/gpt5SamplingGuard.ts +81 -0
- package/open-sse/services/grokTlsClient.ts +607 -0
- package/open-sse/services/hfModelSuggestions.ts +63 -0
- package/open-sse/services/inAppLoginService.ts +256 -0
- package/open-sse/services/intentClassifier.ts +665 -0
- package/open-sse/services/ipFilter.ts +340 -0
- package/open-sse/services/keyGroupAuth.ts +84 -0
- package/open-sse/services/kiroModels.ts +195 -0
- package/open-sse/services/manifestAdapter.ts +134 -0
- package/open-sse/services/mimoThinking.ts +54 -0
- package/open-sse/services/model.ts +738 -0
- package/open-sse/services/modelCapabilities.ts +5 -0
- package/open-sse/services/modelDeprecation.ts +173 -0
- package/open-sse/services/modelFamilyFallback.ts +240 -0
- package/open-sse/services/modelStrip.ts +60 -0
- package/open-sse/services/modelscopePolicy.ts +97 -0
- package/open-sse/services/opencodeOllamaUsage.ts +562 -0
- package/open-sse/services/opencodeQuotaFetcher.ts +351 -0
- package/open-sse/services/payloadRules.ts +474 -0
- package/open-sse/services/perplexityTlsClient.ts +593 -0
- package/open-sse/services/pipeline.ts +189 -0
- package/open-sse/services/provider.ts +460 -0
- package/open-sse/services/providerCooldownTracker.ts +198 -0
- package/open-sse/services/providerCostData.ts +52 -0
- package/open-sse/services/providerDefaultRateLimit.ts +94 -0
- package/open-sse/services/providerRequestDefaults.ts +88 -0
- package/open-sse/services/proxyAutoSelector.ts +58 -0
- package/open-sse/services/qoderCli.ts +987 -0
- package/open-sse/services/qoderCliResolve.ts +111 -0
- package/open-sse/services/quotaFetchThrottle.ts +118 -0
- package/open-sse/services/quotaMonitor.ts +377 -0
- package/open-sse/services/quotaPreflight.ts +349 -0
- package/open-sse/services/qwenThinking.ts +44 -0
- package/open-sse/services/rateLimitManager/headers.ts +94 -0
- package/open-sse/services/rateLimitManager.ts +945 -0
- package/open-sse/services/rateLimitSemaphore.ts +231 -0
- package/open-sse/services/reasoningCache.ts +514 -0
- package/open-sse/services/reasoningTokenBuffer.ts +50 -0
- package/open-sse/services/refreshSerializer.ts +131 -0
- package/open-sse/services/requestDedup.ts +127 -0
- package/open-sse/services/responseModelEcho.ts +79 -0
- package/open-sse/services/responsesInputSanitizer.ts +145 -0
- package/open-sse/services/retryAfterJson.ts +44 -0
- package/open-sse/services/roleNormalizer.ts +283 -0
- package/open-sse/services/searchCache.ts +150 -0
- package/open-sse/services/sessionManager.ts +380 -0
- package/open-sse/services/sessionPool/fingerprintRotator.ts +126 -0
- package/open-sse/services/sessionPool/index.ts +28 -0
- package/open-sse/services/sessionPool/poolRegistry.ts +93 -0
- package/open-sse/services/sessionPool/session.ts +119 -0
- package/open-sse/services/sessionPool/sessionFactory.ts +57 -0
- package/open-sse/services/sessionPool/sessionPool.ts +326 -0
- package/open-sse/services/sessionPool/types.ts +100 -0
- package/open-sse/services/sessionPool/webExecutorWrapper.ts +132 -0
- package/open-sse/services/signatureCache.ts +189 -0
- package/open-sse/services/slidingWindowLimiter.ts +84 -0
- package/open-sse/services/specificityDetector.ts +89 -0
- package/open-sse/services/specificityRules.ts +257 -0
- package/open-sse/services/specificityTypes.ts +43 -0
- package/open-sse/services/streamRecovery.ts +545 -0
- package/open-sse/services/systemPrompt.ts +187 -0
- package/open-sse/services/systemTransforms.ts +532 -0
- package/open-sse/services/taskAwareRouter.ts +326 -0
- package/open-sse/services/taskAwareRouting.ts +553 -0
- package/open-sse/services/thinkingBudget.ts +391 -0
- package/open-sse/services/tierConfig.ts +124 -0
- package/open-sse/services/tierDefaults.json +26 -0
- package/open-sse/services/tierResolver.ts +144 -0
- package/open-sse/services/tierTypes.ts +40 -0
- package/open-sse/services/tlsClientProxy.ts +30 -0
- package/open-sse/services/tokenExtractionConfig.ts +398 -0
- package/open-sse/services/tokenLimitCounter.ts +342 -0
- package/open-sse/services/tokenRefresh.ts +2180 -0
- package/open-sse/services/toolLatencyTracker.ts +89 -0
- package/open-sse/services/toolLimitDetector.ts +87 -0
- package/open-sse/services/toolSchemaSanitizer.ts +165 -0
- package/open-sse/services/usage/antigravity.ts +794 -0
- package/open-sse/services/usage/claude.ts +216 -0
- package/open-sse/services/usage/codebuddy-cn.ts +199 -0
- package/open-sse/services/usage/codex.ts +75 -0
- package/open-sse/services/usage/cursor.ts +161 -0
- package/open-sse/services/usage/glm.ts +220 -0
- package/open-sse/services/usage/kimi.ts +209 -0
- package/open-sse/services/usage/kiro.ts +243 -0
- package/open-sse/services/usage/minimax.ts +346 -0
- package/open-sse/services/usage/quota.ts +85 -0
- package/open-sse/services/usage/scalars.ts +75 -0
- package/open-sse/services/usage.ts +1058 -0
- package/open-sse/services/volumeDetector.ts +224 -0
- package/open-sse/services/webSearchFallback.ts +246 -0
- package/open-sse/services/webSearchRouting.ts +68 -0
- package/open-sse/services/webSessionPoolHealth.ts +287 -0
- package/open-sse/services/wildcardRouter.ts +136 -0
- package/open-sse/services/workflowFSM.ts +340 -0
- package/open-sse/shared/zedAuth.ts +535 -0
- package/open-sse/transformer/responsesTransformer.ts +667 -0
- package/open-sse/translator/bootstrap.ts +27 -0
- package/open-sse/translator/deepseekWebTools.ts +486 -0
- package/open-sse/translator/formats.ts +12 -0
- package/open-sse/translator/helpers/claudeHelper.ts +563 -0
- package/open-sse/translator/helpers/geminiHelper.ts +657 -0
- package/open-sse/translator/helpers/geminiToolsSanitizer.ts +255 -0
- package/open-sse/translator/helpers/jsonUtil.ts +18 -0
- package/open-sse/translator/helpers/maxTokensHelper.ts +21 -0
- package/open-sse/translator/helpers/openaiHelper.ts +244 -0
- package/open-sse/translator/helpers/responsesApiHelper.ts +9 -0
- package/open-sse/translator/helpers/schemaCoercion.ts +408 -0
- package/open-sse/translator/helpers/toolCallHelper.ts +224 -0
- package/open-sse/translator/helpers/toolCallShim.ts +113 -0
- package/open-sse/translator/image/sizeMapper.ts +22 -0
- package/open-sse/translator/index.ts +614 -0
- package/open-sse/translator/paramSupport.ts +70 -0
- package/open-sse/translator/registry.ts +41 -0
- package/open-sse/translator/request/antigravity-to-openai.ts +357 -0
- package/open-sse/translator/request/claude-to-gemini.ts +236 -0
- package/open-sse/translator/request/claude-to-openai.ts +534 -0
- package/open-sse/translator/request/gemini-to-openai.ts +193 -0
- package/open-sse/translator/request/openai-responses/helpers.ts +69 -0
- package/open-sse/translator/request/openai-responses/toResponses.ts +357 -0
- package/open-sse/translator/request/openai-responses.ts +533 -0
- package/open-sse/translator/request/openai-to-claude/thinkingBudget.ts +89 -0
- package/open-sse/translator/request/openai-to-claude/toolResultAdjacency.ts +106 -0
- package/open-sse/translator/request/openai-to-claude.ts +747 -0
- package/open-sse/translator/request/openai-to-cursor.ts +226 -0
- package/open-sse/translator/request/openai-to-gemini/helpers.ts +142 -0
- package/open-sse/translator/request/openai-to-gemini.ts +753 -0
- package/open-sse/translator/request/openai-to-kiro/messageHelpers.ts +109 -0
- package/open-sse/translator/request/openai-to-kiro.ts +889 -0
- package/open-sse/translator/response/claude-to-openai.ts +327 -0
- package/open-sse/translator/response/cursor-to-openai.ts +30 -0
- package/open-sse/translator/response/gemini-to-claude.ts +199 -0
- package/open-sse/translator/response/gemini-to-openai.ts +765 -0
- package/open-sse/translator/response/kiro-to-openai.ts +211 -0
- package/open-sse/translator/response/openai-responses/pureHelpers.ts +92 -0
- package/open-sse/translator/response/openai-responses.ts +1011 -0
- package/open-sse/translator/response/openai-to-antigravity.ts +145 -0
- package/open-sse/translator/response/openai-to-claude.ts +289 -0
- package/open-sse/translator/response/openai-to-gemini-sse.ts +431 -0
- package/open-sse/translator/webTools.ts +531 -0
- package/open-sse/tsconfig.json +25 -0
- package/open-sse/types.d.ts +139 -0
- package/open-sse/utils/agentGoalPolicy.ts +112 -0
- package/open-sse/utils/aiSdkCompat.ts +179 -0
- package/open-sse/utils/anthropicHost.ts +25 -0
- package/open-sse/utils/awsSigV4.ts +139 -0
- package/open-sse/utils/bypassHandler.ts +300 -0
- package/open-sse/utils/cacheControlPolicy.ts +374 -0
- package/open-sse/utils/claudeCodeMetaRequests.ts +87 -0
- package/open-sse/utils/clinepassEnvelope.ts +59 -0
- package/open-sse/utils/comfyuiClient.ts +126 -0
- package/open-sse/utils/composerToolCalls.ts +307 -0
- package/open-sse/utils/cors.ts +13 -0
- package/open-sse/utils/cursorAgentProtobuf/wire.ts +143 -0
- package/open-sse/utils/cursorAgentProtobuf.ts +1400 -0
- package/open-sse/utils/cursorChecksum.ts +139 -0
- package/open-sse/utils/cursorImages.ts +354 -0
- package/open-sse/utils/cursorVersionDetector.ts +74 -0
- package/open-sse/utils/diagnostics.ts +288 -0
- package/open-sse/utils/earlyStreamKeepalive.ts +228 -0
- package/open-sse/utils/error.ts +515 -0
- package/open-sse/utils/estimateSize.ts +35 -0
- package/open-sse/utils/finishReason.ts +36 -0
- package/open-sse/utils/flattenToolHistory.ts +116 -0
- package/open-sse/utils/headers.ts +61 -0
- package/open-sse/utils/heapPressure.ts +81 -0
- package/open-sse/utils/jsonToSse.ts +127 -0
- package/open-sse/utils/keepaliveThreshold.ts +62 -0
- package/open-sse/utils/kieTask.ts +127 -0
- package/open-sse/utils/kiroSanitizer.ts +127 -0
- package/open-sse/utils/logger.ts +190 -0
- package/open-sse/utils/networkProxy.ts +75 -0
- package/open-sse/utils/noThinkingAlias.ts +153 -0
- package/open-sse/utils/number.ts +4 -0
- package/open-sse/utils/ollamaTransform.ts +122 -0
- package/open-sse/utils/opencodeHeaders.ts +98 -0
- package/open-sse/utils/passthroughTailProcessor.ts +299 -0
- package/open-sse/utils/progressTracker.ts +112 -0
- package/open-sse/utils/providerRequestLogging.ts +272 -0
- package/open-sse/utils/proxyDispatcher.ts +507 -0
- package/open-sse/utils/proxyDispatcherCache.ts +124 -0
- package/open-sse/utils/proxyFallback.ts +418 -0
- package/open-sse/utils/proxyFamily.ts +24 -0
- package/open-sse/utils/proxyFamilyResolve.ts +39 -0
- package/open-sse/utils/proxyFetch.ts +666 -0
- package/open-sse/utils/publicCreds.ts +215 -0
- package/open-sse/utils/reasoningContentInjector.ts +73 -0
- package/open-sse/utils/reasoningFields.ts +72 -0
- package/open-sse/utils/requestLogger.ts +386 -0
- package/open-sse/utils/responsesInputNormalization.ts +94 -0
- package/open-sse/utils/responsesStatePolicy.ts +75 -0
- package/open-sse/utils/responsesStreamHelpers.ts +166 -0
- package/open-sse/utils/setupPolyfill.ts +33 -0
- package/open-sse/utils/sha3-512.ts +164 -0
- package/open-sse/utils/sleep.ts +9 -0
- package/open-sse/utils/socksConnectorWithFamily.ts +89 -0
- package/open-sse/utils/sseHeartbeat.ts +119 -0
- package/open-sse/utils/stream.ts +2791 -0
- package/open-sse/utils/streamFailureFinalization.ts +174 -0
- package/open-sse/utils/streamHandler.ts +680 -0
- package/open-sse/utils/streamHelpers.ts +460 -0
- package/open-sse/utils/streamPayloadCollector.ts +700 -0
- package/open-sse/utils/streamReadiness.ts +385 -0
- package/open-sse/utils/streamReadinessPolicy.ts +132 -0
- package/open-sse/utils/textualToolCall.ts +112 -0
- package/open-sse/utils/thinkCloseMarker.ts +77 -0
- package/open-sse/utils/thinkTagParser.ts +146 -0
- package/open-sse/utils/tlsClient.ts +243 -0
- package/open-sse/utils/toolCallArguments.ts +32 -0
- package/open-sse/utils/toolSources.ts +69 -0
- package/open-sse/utils/upstreamResponseHeaders.ts +47 -0
- package/open-sse/utils/urlSanitize.ts +24 -0
- package/open-sse/utils/usageTracking.ts +596 -0
- package/package.json +393 -0
- package/scripts/build/build-next-isolated.mjs +322 -0
- package/scripts/build/colocateOptionals.mjs +144 -0
- package/scripts/build/native-binary-compat.mjs +167 -0
- package/scripts/build/postinstall.mjs +357 -0
- package/scripts/build/postinstallSupport.mjs +45 -0
- package/scripts/build/runtime-env.mjs +140 -0
- package/scripts/build/sync-env.mjs +3 -0
- package/scripts/check/check-supported-node-runtime.ts +20 -0
- package/scripts/dev/responses-ws-proxy.mjs +907 -0
- package/scripts/dev/sync-env.mjs +362 -0
- package/scripts/dev/tls-options.mjs +92 -0
- package/scripts/postinstall.mjs +27 -0
- package/src/domain/assessment/assessor.ts +206 -0
- package/src/domain/assessment/categorizer.ts +118 -0
- package/src/domain/assessment/index.ts +24 -0
- package/src/domain/assessment/migration.ts +111 -0
- package/src/domain/assessment/selfHealer.ts +261 -0
- package/src/domain/assessment/types.ts +361 -0
- package/src/domain/comboResolver.ts +106 -0
- package/src/domain/configAudit.ts +285 -0
- package/src/domain/connectionModelRules.ts +82 -0
- package/src/domain/costRules.ts +631 -0
- package/src/domain/degradation.ts +253 -0
- package/src/domain/fallbackPolicy.ts +160 -0
- package/src/domain/lockoutPolicy.ts +208 -0
- package/src/domain/modelAvailability.ts +41 -0
- package/src/domain/omnirouteResponseMeta.ts +202 -0
- package/src/domain/pipeline.ts +307 -0
- package/src/domain/policyEngine.ts +195 -0
- package/src/domain/prompts.ts +103 -0
- package/src/domain/providerExpiration.ts +255 -0
- package/src/domain/quotaCache.ts +553 -0
- package/src/domain/responses.ts +139 -0
- package/src/domain/tagRouter.ts +64 -0
- package/src/domain/types.ts +123 -0
- package/src/lib/a2a/README.md +748 -0
- package/src/lib/a2a/routingLogger.ts +67 -0
- package/src/lib/a2a/skills/costAnalysis.ts +162 -0
- package/src/lib/a2a/skills/healthReport.ts +155 -0
- package/src/lib/a2a/skills/listCapabilities.ts +72 -0
- package/src/lib/a2a/skills/providerDiscovery.ts +202 -0
- package/src/lib/a2a/skills/quotaManagement.ts +121 -0
- package/src/lib/a2a/skills/smartRouting.ts +89 -0
- package/src/lib/a2a/streaming.ts +149 -0
- package/src/lib/a2a/taskExecution.ts +64 -0
- package/src/lib/a2a/taskManager.ts +240 -0
- package/src/lib/accessTokens/scopes.ts +51 -0
- package/src/lib/acp/index.ts +11 -0
- package/src/lib/acp/manager.ts +202 -0
- package/src/lib/acp/registry.ts +384 -0
- package/src/lib/agentSkills/catalog.ts +256 -0
- package/src/lib/agentSkills/cliRegistryParser.ts +242 -0
- package/src/lib/agentSkills/generator.ts +367 -0
- package/src/lib/agentSkills/openapiParser.ts +201 -0
- package/src/lib/agentSkills/schemas.ts +36 -0
- package/src/lib/agentSkills/types.ts +101 -0
- package/src/lib/api/comboErrorResponse.ts +80 -0
- package/src/lib/api/errorResponse.ts +54 -0
- package/src/lib/api/modelTestRunner.ts +390 -0
- package/src/lib/api/proxyRegistryRouteHandlers.ts +142 -0
- package/src/lib/api/requireCliToolsAuth.ts +5 -0
- package/src/lib/api/requireManagementAuth.ts +118 -0
- package/src/lib/api/serverErrorMessage.ts +36 -0
- package/src/lib/apiBridgeServer.ts +233 -0
- package/src/lib/apiKeyExposure.ts +19 -0
- package/src/lib/arenaEloSync.ts +564 -0
- package/src/lib/audit/activityIcons.ts +69 -0
- package/src/lib/audit/highLevelActions.ts +57 -0
- package/src/lib/audit/timeline.ts +132 -0
- package/src/lib/auth/managementPassword.ts +117 -0
- package/src/lib/batches/costEstimator.ts +130 -0
- package/src/lib/batches/csvToJsonl.ts +248 -0
- package/src/lib/batches/dispatch.ts +53 -0
- package/src/lib/batches/retryFailed.ts +77 -0
- package/src/lib/batches/schemas.ts +38 -0
- package/src/lib/batches/types.ts +78 -0
- package/src/lib/batches/validateJsonl.ts +154 -0
- package/src/lib/benchmarks.ts +33 -0
- package/src/lib/build-profile/featureDisabled.ts +23 -0
- package/src/lib/cacheControlSettings.ts +25 -0
- package/src/lib/cacheLayer.ts +220 -0
- package/src/lib/catalog/openrouterCatalog.ts +177 -0
- package/src/lib/cli-helper/claudeProfileAutoSync.ts +92 -0
- package/src/lib/cli-helper/codexProfileAutoSync.ts +80 -0
- package/src/lib/cli-helper/config-generator/claude.ts +25 -0
- package/src/lib/cli-helper/config-generator/cline.ts +23 -0
- package/src/lib/cli-helper/config-generator/codex.ts +34 -0
- package/src/lib/cli-helper/config-generator/continue.ts +37 -0
- package/src/lib/cli-helper/config-generator/hermes-agent.ts +210 -0
- package/src/lib/cli-helper/config-generator/hermes.ts +47 -0
- package/src/lib/cli-helper/config-generator/hermesHome.ts +40 -0
- package/src/lib/cli-helper/config-generator/index.ts +124 -0
- package/src/lib/cli-helper/config-generator/kilocode.ts +23 -0
- package/src/lib/cli-helper/config-generator/opencode.ts +443 -0
- package/src/lib/cli-helper/doctor/checks.ts +41 -0
- package/src/lib/cli-helper/log-streamer.ts +78 -0
- package/src/lib/cli-helper/tool-detector.ts +165 -0
- package/src/lib/cliTools/batchStatusCache.ts +47 -0
- package/src/lib/cliTools/checkToolConfigStatus.ts +112 -0
- package/src/lib/cloudAgent/agents/codex.ts +148 -0
- package/src/lib/cloudAgent/agents/cursor.ts +205 -0
- package/src/lib/cloudAgent/agents/devin.ts +137 -0
- package/src/lib/cloudAgent/agents/jules.ts +354 -0
- package/src/lib/cloudAgent/api.ts +86 -0
- package/src/lib/cloudAgent/baseAgent.ts +98 -0
- package/src/lib/cloudAgent/credentials.ts +89 -0
- package/src/lib/cloudAgent/db.ts +145 -0
- package/src/lib/cloudAgent/index.ts +8 -0
- package/src/lib/cloudAgent/julesApi.ts +7 -0
- package/src/lib/cloudAgent/registry.ts +29 -0
- package/src/lib/cloudAgent/types.ts +90 -0
- package/src/lib/cloudSync.stub.ts +31 -0
- package/src/lib/cloudSync.ts +210 -0
- package/src/lib/cloudflaredTunnel.ts +933 -0
- package/src/lib/combos/autoPromote.ts +92 -0
- package/src/lib/combos/builderDraft.ts +242 -0
- package/src/lib/combos/builderOptions.ts +681 -0
- package/src/lib/combos/compositeTiers.ts +200 -0
- package/src/lib/combos/controlCenter.ts +271 -0
- package/src/lib/combos/intelligentRouting.ts +192 -0
- package/src/lib/combos/steps.ts +322 -0
- package/src/lib/combos/testHealth.ts +190 -0
- package/src/lib/compliance/index.ts +637 -0
- package/src/lib/compliance/noLog.ts +86 -0
- package/src/lib/compliance/providerAudit.ts +98 -0
- package/src/lib/compression/judgeModelClient.ts +43 -0
- package/src/lib/config/hotReload.ts +115 -0
- package/src/lib/config/runtimeSettings.ts +551 -0
- package/src/lib/consoleInterceptor.ts +136 -0
- package/src/lib/container.ts +122 -0
- package/src/lib/contextWindowResolver.ts +147 -0
- package/src/lib/copilot/codegraphKnowledge.ts +229 -0
- package/src/lib/copilot/engine.ts +372 -0
- package/src/lib/copilot/systemPrompt.ts +189 -0
- package/src/lib/copilot/tools.ts +415 -0
- package/src/lib/credentialHealth/cache.ts +206 -0
- package/src/lib/credentialHealth/scheduler.ts +328 -0
- package/src/lib/dataPaths.ts +122 -0
- package/src/lib/db/AGENTS.md +70 -0
- package/src/lib/db/_rowTypes.ts +45 -0
- package/src/lib/db/accessTokens.ts +183 -0
- package/src/lib/db/adapters/betterSqliteAdapter.ts +58 -0
- package/src/lib/db/adapters/driverFactory.ts +98 -0
- package/src/lib/db/adapters/nodeSqliteAdapter.ts +60 -0
- package/src/lib/db/adapters/nodeSqliteShared.ts +148 -0
- package/src/lib/db/adapters/sqljsAdapter.ts +232 -0
- package/src/lib/db/adapters/types.ts +34 -0
- package/src/lib/db/agentBridgeBypass.ts +81 -0
- package/src/lib/db/agentBridgeMappings.ts +47 -0
- package/src/lib/db/agentBridgeState.ts +115 -0
- package/src/lib/db/apiKeyColumnFallbacks.ts +47 -0
- package/src/lib/db/apiKeyContextSources.ts +107 -0
- package/src/lib/db/apiKeyGroups.ts +318 -0
- package/src/lib/db/apiKeyUsageLimitFields.ts +65 -0
- package/src/lib/db/apiKeys/modelPermissions.ts +122 -0
- package/src/lib/db/apiKeys/rowParsers.ts +161 -0
- package/src/lib/db/apiKeys/types.ts +21 -0
- package/src/lib/db/apiKeys.ts +1492 -0
- package/src/lib/db/backup.ts +708 -0
- package/src/lib/db/batches.ts +450 -0
- package/src/lib/db/callLogStats.ts +235 -0
- package/src/lib/db/caseMapping.ts +80 -0
- package/src/lib/db/cleanup.ts +584 -0
- package/src/lib/db/cliToolState.ts +159 -0
- package/src/lib/db/comboForecast.ts +119 -0
- package/src/lib/db/combos.ts +339 -0
- package/src/lib/db/commandCodeAuth.ts +209 -0
- package/src/lib/db/compression.ts +780 -0
- package/src/lib/db/compressionAnalytics.ts +661 -0
- package/src/lib/db/compressionCacheStats.ts +112 -0
- package/src/lib/db/compressionCombos.ts +491 -0
- package/src/lib/db/compressionRunTelemetry.ts +126 -0
- package/src/lib/db/contextHandoffs.ts +233 -0
- package/src/lib/db/core.ts +1520 -0
- package/src/lib/db/creditBalance.ts +92 -0
- package/src/lib/db/databaseSettings.ts +309 -0
- package/src/lib/db/detailedLogs.ts +170 -0
- package/src/lib/db/discovery.ts +97 -0
- package/src/lib/db/discoveryResults.ts +176 -0
- package/src/lib/db/domainState.ts +630 -0
- package/src/lib/db/encryption.ts +327 -0
- package/src/lib/db/evals.ts +786 -0
- package/src/lib/db/featureFlags.ts +82 -0
- package/src/lib/db/files.ts +170 -0
- package/src/lib/db/freeProxies.ts +360 -0
- package/src/lib/db/gamification.ts +613 -0
- package/src/lib/db/healthCheck.ts +565 -0
- package/src/lib/db/inspectorCustomHosts.ts +88 -0
- package/src/lib/db/inspectorSessions.ts +161 -0
- package/src/lib/db/jsonMigration.ts +321 -0
- package/src/lib/db/memoryVec.ts +138 -0
- package/src/lib/db/middleware.ts +239 -0
- package/src/lib/db/migrationRunner/constants.ts +118 -0
- package/src/lib/db/migrationRunner.ts +1069 -0
- package/src/lib/db/migrations/001_initial_schema.sql +226 -0
- package/src/lib/db/migrations/002_mcp_a2a_tables.sql +95 -0
- package/src/lib/db/migrations/003_provider_node_custom_paths.sql +5 -0
- package/src/lib/db/migrations/004_proxy_registry.sql +31 -0
- package/src/lib/db/migrations/005_combo_agent_fields.sql +19 -0
- package/src/lib/db/migrations/006_detailed_request_logs.sql +42 -0
- package/src/lib/db/migrations/007_search_request_type.sql +4 -0
- package/src/lib/db/migrations/008_registered_keys.sql +65 -0
- package/src/lib/db/migrations/009_requested_model.sql +9 -0
- package/src/lib/db/migrations/010_model_combo_mappings.sql +19 -0
- package/src/lib/db/migrations/011_webhooks.sql +15 -0
- package/src/lib/db/migrations/012_fix_token_input_cache_tokens.sql +15 -0
- package/src/lib/db/migrations/013_quota_snapshots.sql +19 -0
- package/src/lib/db/migrations/014_unified_log_artifacts.sql +15 -0
- package/src/lib/db/migrations/015_create_memories.sql +22 -0
- package/src/lib/db/migrations/016_create_skills.sql +37 -0
- package/src/lib/db/migrations/017_version_manager_upstream_proxy.sql +56 -0
- package/src/lib/db/migrations/018_call_logs_detailed_tokens.sql +6 -0
- package/src/lib/db/migrations/019_context_handoffs.sql +28 -0
- package/src/lib/db/migrations/020_combo_sort_order.sql +16 -0
- package/src/lib/db/migrations/021_combo_call_log_targets.sql +5 -0
- package/src/lib/db/migrations/022_add_memory_fts5.sql +33 -0
- package/src/lib/db/migrations/023_fix_memory_fts_uuid.sql +55 -0
- package/src/lib/db/migrations/024_create_sync_tokens.sql +15 -0
- package/src/lib/db/migrations/025_call_logs_summary_storage.sql +145 -0
- package/src/lib/db/migrations/027_skill_mode_and_metadata.sql +10 -0
- package/src/lib/db/migrations/028_create_files_and_batches.sql +51 -0
- package/src/lib/db/migrations/029_provider_connection_max_concurrent.sql +10 -0
- package/src/lib/db/migrations/030_create_eval_runs.sql +28 -0
- package/src/lib/db/migrations/031_create_eval_suites.sql +27 -0
- package/src/lib/db/migrations/032_apikey_lifecycle.sql +24 -0
- package/src/lib/db/migrations/033_create_reasoning_cache.sql +27 -0
- package/src/lib/db/migrations/034_compression_settings.sql +10 -0
- package/src/lib/db/migrations/035_standard_compression_config.sql +9 -0
- package/src/lib/db/migrations/036_aggressive_compression.sql +4 -0
- package/src/lib/db/migrations/037_ultra_compression.sql +6 -0
- package/src/lib/db/migrations/038_compression_analytics.sql +13 -0
- package/src/lib/db/migrations/039_compression_cache_stats.sql +15 -0
- package/src/lib/db/migrations/040_oneproxy_proxy_fields.sql +24 -0
- package/src/lib/db/migrations/041_compression_receipts.sql +18 -0
- package/src/lib/db/migrations/042_compression_combos.sql +43 -0
- package/src/lib/db/migrations/043_default_compression_combo_pipeline.sql +12 -0
- package/src/lib/db/migrations/044_usage_history_api_key_backfill.sql +27 -0
- package/src/lib/db/migrations/045_compression_tokens.sql +4 -0
- package/src/lib/db/migrations/046_database_settings.sql +44 -0
- package/src/lib/db/migrations/047_aggregation_tables.sql +44 -0
- package/src/lib/db/migrations/048_summary_indexes.sql +29 -0
- package/src/lib/db/migrations/049_compression_analytics_indexes.sql +10 -0
- package/src/lib/db/migrations/050_session_account_affinity.sql +11 -0
- package/src/lib/db/migrations/051_hot_path_db_indexes.sql +10 -0
- package/src/lib/db/migrations/052_api_key_combo_throttle.sql +4 -0
- package/src/lib/db/migrations/053_remove_status_from_files.sql +2 -0
- package/src/lib/db/migrations/054_usage_history_service_tier.sql +4 -0
- package/src/lib/db/migrations/056_mcp_accessibility_compression.sql +8 -0
- package/src/lib/db/migrations/057_provider_connection_quota_window_thresholds.sql +14 -0
- package/src/lib/db/migrations/058_command_code_auth_sessions.sql +19 -0
- package/src/lib/db/migrations/059_manifest_routing.sql +21 -0
- package/src/lib/db/migrations/060_create_gamification.sql +94 -0
- package/src/lib/db/migrations/061_cloud_agent_credentials.sql +9 -0
- package/src/lib/db/migrations/062_usage_history_combo_strategy.sql +4 -0
- package/src/lib/db/migrations/063_add_last_model_to_handoffs.sql +7 -0
- package/src/lib/db/migrations/064_create_session_model_history.sql +19 -0
- package/src/lib/db/migrations/065_middleware_hooks.sql +45 -0
- package/src/lib/db/migrations/066_api_key_groups.sql +47 -0
- package/src/lib/db/migrations/067_relay_proxies.sql +56 -0
- package/src/lib/db/migrations/068_free_proxies.sql +52 -0
- package/src/lib/db/migrations/069_webhook_deliveries.sql +15 -0
- package/src/lib/db/migrations/070_webhooks_kind_metadata.sql +3 -0
- package/src/lib/db/migrations/071_services.sql +19 -0
- package/src/lib/db/migrations/072_free_proxies_fk.sql +27 -0
- package/src/lib/db/migrations/073_per_model_token_limits.sql +61 -0
- package/src/lib/db/migrations/074_discovery_results.sql +20 -0
- package/src/lib/db/migrations/075_api_key_self_service_usage_scopes.sql +51 -0
- package/src/lib/db/migrations/076_create_plugins.sql +31 -0
- package/src/lib/db/migrations/077_api_key_stream_default_mode.sql +3 -0
- package/src/lib/db/migrations/078_quota_consumption.sql +24 -0
- package/src/lib/db/migrations/079_provider_plans.sql +19 -0
- package/src/lib/db/migrations/080_agent_bridge.sql +24 -0
- package/src/lib/db/migrations/081_inspector_custom_hosts.sql +11 -0
- package/src/lib/db/migrations/082_inspector_sessions.sql +18 -0
- package/src/lib/db/migrations/083_memory_vec.sql +26 -0
- package/src/lib/db/migrations/084_playground_presets.sql +15 -0
- package/src/lib/db/migrations/085_quota_pools.sql +39 -0
- package/src/lib/db/migrations/086_api_key_allowed_quotas.sql +8 -0
- package/src/lib/db/migrations/087_quota_pool_connections.sql +21 -0
- package/src/lib/db/migrations/088_quota_groups.sql +28 -0
- package/src/lib/db/migrations/089_add_disable_non_public_to_api_keys.sql +3 -0
- package/src/lib/db/migrations/090_plugin_metrics.sql +9 -0
- package/src/lib/db/migrations/091_plugin_analytics.sql +23 -0
- package/src/lib/db/migrations/092_api_key_context_sources.sql +13 -0
- package/src/lib/db/migrations/093_proxy_enable_toggles.sql +17 -0
- package/src/lib/db/migrations/094_per_key_proxy_toggles.sql +12 -0
- package/src/lib/db/migrations/095_provider_node_custom_headers.sql +5 -0
- package/src/lib/db/migrations/096_sync_context_cache_protection.sql +9 -0
- package/src/lib/db/migrations/097_model_intelligence.sql +25 -0
- package/src/lib/db/migrations/098_clear_semantic_cache_for_key_isolation.sql +4 -0
- package/src/lib/db/migrations/099_proxy_family.sql +5 -0
- package/src/lib/db/migrations/100_cli_access_tokens.sql +18 -0
- package/src/lib/db/migrations/101_api_key_usage_limits.sql +4 -0
- package/src/lib/db/migrations/102_compression_engines_map.sql +5 -0
- package/src/lib/db/migrations/103_strip_legacy_combo_config_keys.sql +54 -0
- package/src/lib/db/migrations/104_normalize_database_cache_size.sql +10 -0
- package/src/lib/db/migrations/105_usage_history_endpoint.sql +6 -0
- package/src/lib/db/migrations/106_quota_allocation_model_caps.sql +32 -0
- package/src/lib/db/migrations/107_quota_combos_quota_share_strategy.sql +25 -0
- package/src/lib/db/migrations/108_provider_quota_reset_events.sql +26 -0
- package/src/lib/db/migrations/109_call_logs_correlation_id.sql +2 -0
- package/src/lib/db/migrations/110_model_context_overrides.sql +17 -0
- package/src/lib/db/migrations/111_memory_typed_decay.sql +10 -0
- package/src/lib/db/migrations/112_batch_item_checkpoints.sql +18 -0
- package/src/lib/db/migrations/113_provider_node_icon_url.sql +5 -0
- package/src/lib/db/migrations/114_mux_service_seed.sql +12 -0
- package/src/lib/db/migrations/115_bifrost_service.sql +9 -0
- package/src/lib/db/migrations/116_call_logs_reasoning_source.sql +13 -0
- package/src/lib/db/migrations/117_proxy_pool_rotation.sql +53 -0
- package/src/lib/db/modelComboMappings.ts +255 -0
- package/src/lib/db/modelContextOverrides.ts +133 -0
- package/src/lib/db/modelIntelligence.ts +232 -0
- package/src/lib/db/models/aliases.ts +61 -0
- package/src/lib/db/models/compat.ts +249 -0
- package/src/lib/db/models/mitmAlias.ts +32 -0
- package/src/lib/db/models/shared.ts +19 -0
- package/src/lib/db/models.ts +936 -0
- package/src/lib/db/notion.ts +48 -0
- package/src/lib/db/obsidian.ts +283 -0
- package/src/lib/db/oneproxy.ts +293 -0
- package/src/lib/db/optimizationSettings.ts +284 -0
- package/src/lib/db/playgroundPresets.ts +167 -0
- package/src/lib/db/pluginMetrics.ts +88 -0
- package/src/lib/db/plugins.ts +280 -0
- package/src/lib/db/prompts.ts +302 -0
- package/src/lib/db/providerLimits.ts +131 -0
- package/src/lib/db/providerNodeSelect.ts +48 -0
- package/src/lib/db/providerPlans.ts +149 -0
- package/src/lib/db/providerStats.ts +68 -0
- package/src/lib/db/providers/columns.ts +116 -0
- package/src/lib/db/providers/nodes.ts +169 -0
- package/src/lib/db/providers/rateLimit.ts +198 -0
- package/src/lib/db/providers.ts +803 -0
- package/src/lib/db/proxies/mappers.ts +181 -0
- package/src/lib/db/proxies/types.ts +78 -0
- package/src/lib/db/proxies.ts +1176 -0
- package/src/lib/db/proxyLogs.ts +35 -0
- package/src/lib/db/quotaConsumption.ts +274 -0
- package/src/lib/db/quotaGroups.ts +147 -0
- package/src/lib/db/quotaModelCaps.ts +128 -0
- package/src/lib/db/quotaPools.ts +548 -0
- package/src/lib/db/quotaResetEvents.ts +334 -0
- package/src/lib/db/quotaSnapshots.ts +209 -0
- package/src/lib/db/readCache.ts +202 -0
- package/src/lib/db/reasoningCache.ts +276 -0
- package/src/lib/db/recovery.ts +33 -0
- package/src/lib/db/registeredKeys.ts +532 -0
- package/src/lib/db/relayProxies.ts +364 -0
- package/src/lib/db/schemaColumns.ts +226 -0
- package/src/lib/db/secrets.ts +28 -0
- package/src/lib/db/semanticCache.ts +117 -0
- package/src/lib/db/serviceModels.ts +79 -0
- package/src/lib/db/sessionAccountAffinity.ts +212 -0
- package/src/lib/db/settings/cacheMetrics.ts +235 -0
- package/src/lib/db/settings/lkgp.ts +49 -0
- package/src/lib/db/settings/pricing.ts +254 -0
- package/src/lib/db/settings/shared.ts +9 -0
- package/src/lib/db/settings.ts +661 -0
- package/src/lib/db/skills.ts +62 -0
- package/src/lib/db/stateReset.ts +30 -0
- package/src/lib/db/stats.ts +71 -0
- package/src/lib/db/syncTokens.ts +163 -0
- package/src/lib/db/tierConfig.ts +88 -0
- package/src/lib/db/tokenLimits.ts +295 -0
- package/src/lib/db/upstreamProxy.ts +247 -0
- package/src/lib/db/usageAnalytics/sources.ts +208 -0
- package/src/lib/db/usageAnalytics.ts +723 -0
- package/src/lib/db/usageLogs.ts +94 -0
- package/src/lib/db/usageSummary.ts +18 -0
- package/src/lib/db/vacuumScheduler.ts +326 -0
- package/src/lib/db/versionManager.ts +377 -0
- package/src/lib/db/webSessionDedup.ts +57 -0
- package/src/lib/db/webhookDeliveries.ts +77 -0
- package/src/lib/db/webhooks.ts +178 -0
- package/src/lib/discovery/index.ts +137 -0
- package/src/lib/display/names.ts +73 -0
- package/src/lib/display/useProviderNodeMap.ts +68 -0
- package/src/lib/docsI18nPath.ts +33 -0
- package/src/lib/docsSanitizer.ts +42 -0
- package/src/lib/embeddings/familyGuard.ts +24 -0
- package/src/lib/embeddings/service.ts +288 -0
- package/src/lib/env/runtimeEnv.ts +166 -0
- package/src/lib/evals/evalRunner/builtinSuites.ts +676 -0
- package/src/lib/evals/evalRunner.ts +301 -0
- package/src/lib/evals/runtime.ts +311 -0
- package/src/lib/events/eventBus.ts +148 -0
- package/src/lib/events/types.ts +181 -0
- package/src/lib/freeProviderRankings.ts +340 -0
- package/src/lib/freeProxyProviders/index.ts +24 -0
- package/src/lib/freeProxyProviders/iplocate.ts +107 -0
- package/src/lib/freeProxyProviders/oneproxy.ts +127 -0
- package/src/lib/freeProxyProviders/proxifly.ts +143 -0
- package/src/lib/freeProxyProviders/types.ts +33 -0
- package/src/lib/freeProxyProviders/webshare.ts +148 -0
- package/src/lib/gamification/antiCheat.ts +160 -0
- package/src/lib/gamification/badges.ts +542 -0
- package/src/lib/gamification/events.ts +187 -0
- package/src/lib/gamification/index.ts +37 -0
- package/src/lib/gamification/invites.ts +127 -0
- package/src/lib/gamification/leaderboard.ts +64 -0
- package/src/lib/gamification/notifications.ts +118 -0
- package/src/lib/gamification/servers.ts +179 -0
- package/src/lib/gamification/sharing.ts +56 -0
- package/src/lib/gamification/streaks.ts +164 -0
- package/src/lib/gamification/xp.ts +152 -0
- package/src/lib/gracefulShutdown.ts +151 -0
- package/src/lib/guardrails/base.ts +65 -0
- package/src/lib/guardrails/index.ts +4 -0
- package/src/lib/guardrails/piiMasker.ts +208 -0
- package/src/lib/guardrails/promptInjection.ts +285 -0
- package/src/lib/guardrails/registry.ts +282 -0
- package/src/lib/guardrails/visionBridge.ts +237 -0
- package/src/lib/guardrails/visionBridgeHelpers.ts +499 -0
- package/src/lib/guardrails/visionBridgeRouter.ts +271 -0
- package/src/lib/headroom/detect.ts +214 -0
- package/src/lib/headroom/process.ts +177 -0
- package/src/lib/idempotencyLayer.ts +105 -0
- package/src/lib/images/imageRouteModel.ts +168 -0
- package/src/lib/initCloudSync.ts +52 -0
- package/src/lib/inspector/agentBridgeMaintenanceApi.ts +70 -0
- package/src/lib/inspector/captureState.ts +90 -0
- package/src/lib/inspector/configPortability.ts +86 -0
- package/src/lib/inspector/harExport.ts +188 -0
- package/src/lib/inspector/matchesTrafficFilter.ts +37 -0
- package/src/lib/inspector/secretMask.ts +6 -0
- package/src/lib/inspector/tproxyCaptureApi.ts +60 -0
- package/src/lib/ipUtils.ts +94 -0
- package/src/lib/jobs/budgetResetJob.ts +40 -0
- package/src/lib/jobs/reasoningCacheCleanupJob.ts +40 -0
- package/src/lib/localDb.ts +797 -0
- package/src/lib/localHealthCheck.ts +267 -0
- package/src/lib/logEnv.ts +164 -0
- package/src/lib/logPayloads.ts +110 -0
- package/src/lib/logRotation.ts +206 -0
- package/src/lib/machineToken.ts +53 -0
- package/src/lib/memory/cache.ts +76 -0
- package/src/lib/memory/embedding/cache.ts +77 -0
- package/src/lib/memory/embedding/index.ts +281 -0
- package/src/lib/memory/embedding/remote.ts +95 -0
- package/src/lib/memory/embedding/staticPotion.ts +253 -0
- package/src/lib/memory/embedding/transformersLocal.ts +153 -0
- package/src/lib/memory/embedding/types.ts +40 -0
- package/src/lib/memory/extraction.ts +195 -0
- package/src/lib/memory/injection.ts +211 -0
- package/src/lib/memory/qdrant.ts +521 -0
- package/src/lib/memory/reindex.ts +102 -0
- package/src/lib/memory/retrieval/scoring.ts +104 -0
- package/src/lib/memory/retrieval.ts +1072 -0
- package/src/lib/memory/schemas.ts +39 -0
- package/src/lib/memory/settings.ts +184 -0
- package/src/lib/memory/store.ts +621 -0
- package/src/lib/memory/summarization.ts +202 -0
- package/src/lib/memory/typedDecay.ts +245 -0
- package/src/lib/memory/types.ts +45 -0
- package/src/lib/memory/vectorStore.ts +425 -0
- package/src/lib/memory/verify.ts +56 -0
- package/src/lib/middleware/cliTokenAuth.ts +91 -0
- package/src/lib/middleware/registry.ts +432 -0
- package/src/lib/middleware/types.ts +129 -0
- package/src/lib/modelAliasSeed.ts +82 -0
- package/src/lib/modelCapabilities.ts +481 -0
- package/src/lib/modelMetadataRegistry.ts +574 -0
- package/src/lib/modelsDevSync/transform.ts +279 -0
- package/src/lib/modelsDevSync.ts +677 -0
- package/src/lib/monitoring/comboHealthAutopilot.ts +494 -0
- package/src/lib/monitoring/observability.ts +336 -0
- package/src/lib/monitoring/providerHealthAutopilot.ts +743 -0
- package/src/lib/monitoring/providerHealthMatrix.ts +621 -0
- package/src/lib/ngrokTunnel.ts +142 -0
- package/src/lib/notion/api.ts +247 -0
- package/src/lib/oauth/codexDeviceFlow.ts +316 -0
- package/src/lib/oauth/config/index.ts +31 -0
- package/src/lib/oauth/connectionPersistence.ts +114 -0
- package/src/lib/oauth/constants/oauth.ts +494 -0
- package/src/lib/oauth/credentialBlob.ts +105 -0
- package/src/lib/oauth/deviceFlowTickets.ts +110 -0
- package/src/lib/oauth/gitlab.ts +103 -0
- package/src/lib/oauth/pasteCredentials.ts +51 -0
- package/src/lib/oauth/providers/agy.ts +15 -0
- package/src/lib/oauth/providers/antigravity.ts +159 -0
- package/src/lib/oauth/providers/claude.ts +170 -0
- package/src/lib/oauth/providers/cline.ts +91 -0
- package/src/lib/oauth/providers/codebuddy-cn.ts +123 -0
- package/src/lib/oauth/providers/codex.ts +214 -0
- package/src/lib/oauth/providers/cursor.ts +15 -0
- package/src/lib/oauth/providers/github.ts +89 -0
- package/src/lib/oauth/providers/gitlab-duo.ts +124 -0
- package/src/lib/oauth/providers/grok-cli.ts +155 -0
- package/src/lib/oauth/providers/index.ts +59 -0
- package/src/lib/oauth/providers/kilocode.ts +77 -0
- package/src/lib/oauth/providers/kimi-coding.ts +135 -0
- package/src/lib/oauth/providers/kiro.ts +185 -0
- package/src/lib/oauth/providers/qoder.ts +81 -0
- package/src/lib/oauth/providers/qwen.ts +82 -0
- package/src/lib/oauth/providers/trae.ts +78 -0
- package/src/lib/oauth/providers/windsurf.ts +64 -0
- package/src/lib/oauth/providers/zed-hosted.ts +89 -0
- package/src/lib/oauth/providers/zed.ts +35 -0
- package/src/lib/oauth/providers.ts +278 -0
- package/src/lib/oauth/services/codexImport.ts +222 -0
- package/src/lib/oauth/services/cursor.ts +219 -0
- package/src/lib/oauth/services/kiro.ts +441 -0
- package/src/lib/oauth/utils/agyAuthImport.ts +259 -0
- package/src/lib/oauth/utils/banner.ts +62 -0
- package/src/lib/oauth/utils/claudeAuthFile.ts +334 -0
- package/src/lib/oauth/utils/claudeAuthImport.ts +259 -0
- package/src/lib/oauth/utils/claudeAuthZipExtract.ts +5 -0
- package/src/lib/oauth/utils/cliProxyAuthImport.ts +142 -0
- package/src/lib/oauth/utils/codexAuthFile.ts +352 -0
- package/src/lib/oauth/utils/codexAuthImport.ts +294 -0
- package/src/lib/oauth/utils/codexAuthZipExtract.ts +5 -0
- package/src/lib/oauth/utils/jsonZipExtract.ts +89 -0
- package/src/lib/oauth/utils/pkce.ts +37 -0
- package/src/lib/oauth/utils/server.ts +122 -0
- package/src/lib/oauth/utils/ui.ts +47 -0
- package/src/lib/obsidian/api.ts +390 -0
- package/src/lib/obsidianSync.ts +110 -0
- package/src/lib/oneproxyRotator.ts +19 -0
- package/src/lib/oneproxySync.ts +182 -0
- package/src/lib/piiSanitizer.ts +416 -0
- package/src/lib/playground/codeExport.ts +408 -0
- package/src/lib/playground/promptImprover.ts +147 -0
- package/src/lib/playground/streamMetrics.ts +61 -0
- package/src/lib/playground/types.ts +114 -0
- package/src/lib/plugins/devMode.ts +65 -0
- package/src/lib/plugins/doctor.ts +138 -0
- package/src/lib/plugins/errors.ts +38 -0
- package/src/lib/plugins/hooks.ts +322 -0
- package/src/lib/plugins/index.ts +72 -0
- package/src/lib/plugins/loader.ts +326 -0
- package/src/lib/plugins/logger.ts +50 -0
- package/src/lib/plugins/manager.ts +579 -0
- package/src/lib/plugins/manifest.ts +213 -0
- package/src/lib/plugins/marketplace.ts +202 -0
- package/src/lib/plugins/pluginWorker.ts +246 -0
- package/src/lib/plugins/sandbox.ts +29 -0
- package/src/lib/plugins/scanner.ts +110 -0
- package/src/lib/plugins/sdk.ts +88 -0
- package/src/lib/plugins/signing.ts +34 -0
- package/src/lib/plugins/testRunner.ts +95 -0
- package/src/lib/plugins/watcher.ts +90 -0
- package/src/lib/pricingSync.ts +456 -0
- package/src/lib/promptCache/index.ts +1 -0
- package/src/lib/promptCache/prefixAnalyzer.ts +81 -0
- package/src/lib/providerModels/cursorAgent.ts +166 -0
- package/src/lib/providerModels/geminiModelsParser.ts +91 -0
- package/src/lib/providerModels/managedAvailableModels.ts +165 -0
- package/src/lib/providerModels/managedModelImport.ts +349 -0
- package/src/lib/providerModels/modelDiscovery.ts +151 -0
- package/src/lib/providers/catalog.ts +246 -0
- package/src/lib/providers/claudeExtraUsage.ts +160 -0
- package/src/lib/providers/claudeFastMode.ts +75 -0
- package/src/lib/providers/codexConnectionDefaults.ts +85 -0
- package/src/lib/providers/codexFastTier.ts +210 -0
- package/src/lib/providers/imageValidation.ts +160 -0
- package/src/lib/providers/managedAvailableModels.ts +21 -0
- package/src/lib/providers/modelListingCapability.ts +26 -0
- package/src/lib/providers/nvidiaValidationModel.ts +24 -0
- package/src/lib/providers/requestDefaults.ts +318 -0
- package/src/lib/providers/serviceKindIndex.ts +0 -0
- package/src/lib/providers/staticModels.ts +170 -0
- package/src/lib/providers/validation/anthropicFormat.ts +319 -0
- package/src/lib/providers/validation/audioMiscProviders.ts +582 -0
- package/src/lib/providers/validation/cloudProviders.ts +669 -0
- package/src/lib/providers/validation/cozeError.ts +56 -0
- package/src/lib/providers/validation/directChatProbe.ts +47 -0
- package/src/lib/providers/validation/embeddingProviders.ts +143 -0
- package/src/lib/providers/validation/headers.ts +122 -0
- package/src/lib/providers/validation/metaAi.ts +117 -0
- package/src/lib/providers/validation/openaiFormat.ts +500 -0
- package/src/lib/providers/validation/searchProviders.ts +199 -0
- package/src/lib/providers/validation/transport.ts +109 -0
- package/src/lib/providers/validation/urlHelpers.ts +114 -0
- package/src/lib/providers/validation/webProvidersA.ts +808 -0
- package/src/lib/providers/validation/webProvidersB.ts +536 -0
- package/src/lib/providers/validation.ts +772 -0
- package/src/lib/providers/webCookieAuth.ts +157 -0
- package/src/lib/providers/xai/thinking.ts +127 -0
- package/src/lib/providers/xai/translators/claude.ts +368 -0
- package/src/lib/providers/xai/translators/gemini.ts +371 -0
- package/src/lib/providers/xai/translators/openai-chat.ts +310 -0
- package/src/lib/providers/xai/translators/openai-responses.ts +77 -0
- package/src/lib/proxyEgress.ts +388 -0
- package/src/lib/proxyHealth/decision.ts +77 -0
- package/src/lib/proxyHealth/scheduler.ts +207 -0
- package/src/lib/proxyHealth/statusPolicy.ts +41 -0
- package/src/lib/proxyHealth.ts +173 -0
- package/src/lib/proxyLogger.ts +240 -0
- package/src/lib/proxyRelay/cloudflareWorkerScript.ts +107 -0
- package/src/lib/quota/QuotaStore.ts +23 -0
- package/src/lib/quota/accountBuckets.ts +225 -0
- package/src/lib/quota/burnRate.ts +111 -0
- package/src/lib/quota/connectionProvider.ts +32 -0
- package/src/lib/quota/connectionRecovery.ts +303 -0
- package/src/lib/quota/dimensions.ts +61 -0
- package/src/lib/quota/enforce.ts +401 -0
- package/src/lib/quota/fairShare.ts +186 -0
- package/src/lib/quota/planRegistry.ts +107 -0
- package/src/lib/quota/planResolver.ts +78 -0
- package/src/lib/quota/quotaCombos.ts +414 -0
- package/src/lib/quota/quotaKey.ts +202 -0
- package/src/lib/quota/quotaModelNaming.ts +84 -0
- package/src/lib/quota/redisQuotaStore.ts +352 -0
- package/src/lib/quota/saturationSignals.ts +559 -0
- package/src/lib/quota/spendRecorder.ts +131 -0
- package/src/lib/quota/sqliteQuotaStore.ts +282 -0
- package/src/lib/quota/storeFactory.ts +124 -0
- package/src/lib/quota/types.ts +94 -0
- package/src/lib/resilience/modelLockoutSettings.ts +95 -0
- package/src/lib/resilience/settings/normalize.ts +359 -0
- package/src/lib/resilience/settings/types.ts +182 -0
- package/src/lib/resilience/settings.ts +386 -0
- package/src/lib/runtime/ports.ts +32 -0
- package/src/lib/search/executeWebSearch.ts +270 -0
- package/src/lib/security/localEndpoints.ts +82 -0
- package/src/lib/semanticCache.ts +377 -0
- package/src/lib/services/ServiceSupervisor.ts +243 -0
- package/src/lib/services/apiKey.ts +40 -0
- package/src/lib/services/bootstrap.ts +133 -0
- package/src/lib/services/embedPath.ts +19 -0
- package/src/lib/services/embedWsProxy.ts +285 -0
- package/src/lib/services/healthCheck.ts +79 -0
- package/src/lib/services/htmlRewriter.ts +185 -0
- package/src/lib/services/installers/bifrost.ts +145 -0
- package/src/lib/services/installers/cliproxy.ts +116 -0
- package/src/lib/services/installers/mux.ts +178 -0
- package/src/lib/services/installers/ninerouter.stub.ts +17 -0
- package/src/lib/services/installers/ninerouter.ts +157 -0
- package/src/lib/services/installers/utils.ts +167 -0
- package/src/lib/services/modelSync.ts +105 -0
- package/src/lib/services/portProbe.ts +104 -0
- package/src/lib/services/registry.ts +42 -0
- package/src/lib/services/reverseProxy.ts +180 -0
- package/src/lib/services/ringBuffer.ts +91 -0
- package/src/lib/services/types.ts +50 -0
- package/src/lib/settingsCache.ts +62 -0
- package/src/lib/skills/a2a.ts +34 -0
- package/src/lib/skills/builtin/browser.ts +22 -0
- package/src/lib/skills/builtins.ts +493 -0
- package/src/lib/skills/custom.ts +41 -0
- package/src/lib/skills/executor.ts +196 -0
- package/src/lib/skills/githubCollector.ts +426 -0
- package/src/lib/skills/hybrid.ts +67 -0
- package/src/lib/skills/injection.ts +307 -0
- package/src/lib/skills/interception.ts +343 -0
- package/src/lib/skills/providerSettings.ts +14 -0
- package/src/lib/skills/registry.ts +398 -0
- package/src/lib/skills/sandbox.ts +178 -0
- package/src/lib/skills/schemas.ts +43 -0
- package/src/lib/skills/skillssh.ts +73 -0
- package/src/lib/skills/types.ts +61 -0
- package/src/lib/source.ts +7 -0
- package/src/lib/spend/batchWriter.ts +208 -0
- package/src/lib/sseTextTransform.ts +346 -0
- package/src/lib/streamingPiiTransform.ts +350 -0
- package/src/lib/sync/bundle.ts +208 -0
- package/src/lib/sync/tokens.ts +107 -0
- package/src/lib/system/autoUpdate.ts +400 -0
- package/src/lib/system/globalPackagePath.ts +49 -0
- package/src/lib/system/versionCheck.ts +163 -0
- package/src/lib/tailscaleTunnel.ts +1201 -0
- package/src/lib/tokenHealthCheck.ts +829 -0
- package/src/lib/toolPolicy.ts +150 -0
- package/src/lib/translator/streamTransform.ts +27 -0
- package/src/lib/translatorEvents.ts +40 -0
- package/src/lib/usage/aggregateHistory.ts +212 -0
- package/src/lib/usage/apiKeySelfService.ts +420 -0
- package/src/lib/usage/apiKeyUsageLimits.ts +578 -0
- package/src/lib/usage/callLogArtifacts.ts +337 -0
- package/src/lib/usage/callLogs/format.ts +129 -0
- package/src/lib/usage/callLogs.ts +928 -0
- package/src/lib/usage/callLogsBoundedQueries.ts +42 -0
- package/src/lib/usage/codexResetCredits.ts +355 -0
- package/src/lib/usage/comboForecast.ts +441 -0
- package/src/lib/usage/comboHealth.ts +545 -0
- package/src/lib/usage/comboHealthDashboard.ts +109 -0
- package/src/lib/usage/comboScoringInspector.ts +416 -0
- package/src/lib/usage/completedRequestDetails.ts +103 -0
- package/src/lib/usage/costCalculator.ts +279 -0
- package/src/lib/usage/fetcher.ts +483 -0
- package/src/lib/usage/flatRateProviders.ts +59 -0
- package/src/lib/usage/internalUsageCommand.ts +788 -0
- package/src/lib/usage/migrations.ts +471 -0
- package/src/lib/usage/pendingRequestScope.ts +26 -0
- package/src/lib/usage/providerLimits/quotaNormalize.ts +72 -0
- package/src/lib/usage/providerLimits.ts +997 -0
- package/src/lib/usage/providerWindowCosts.ts +571 -0
- package/src/lib/usage/resilienceExplain.ts +468 -0
- package/src/lib/usage/routeExplain.ts +747 -0
- package/src/lib/usage/tokenAccounting.ts +212 -0
- package/src/lib/usage/usageEvents.ts +91 -0
- package/src/lib/usage/usageHistory/helpers.ts +85 -0
- package/src/lib/usage/usageHistory.ts +916 -0
- package/src/lib/usage/usageStats.ts +581 -0
- package/src/lib/usageAnalytics.ts +372 -0
- package/src/lib/usageDb.ts +38 -0
- package/src/lib/versionManager/binaryManager.ts +240 -0
- package/src/lib/versionManager/healthMonitor.ts +71 -0
- package/src/lib/versionManager/index.ts +155 -0
- package/src/lib/versionManager/processManager.ts +155 -0
- package/src/lib/versionManager/releaseChecker.ts +98 -0
- package/src/lib/vscode/familyFirstModelIds.ts +92 -0
- package/src/lib/vscode/modelPresentation.ts +132 -0
- package/src/lib/vscode/reasoningMetadata.ts +183 -0
- package/src/lib/vscode/serviceTierVariants.ts +202 -0
- package/src/lib/vscode/tokenizedRequest.ts +79 -0
- package/src/lib/webhookDispatcher.ts +221 -0
- package/src/lib/webhooks/eventDescriptions.ts +76 -0
- package/src/lib/webhooks/integrations/discord.ts +49 -0
- package/src/lib/webhooks/integrations/slack.ts +45 -0
- package/src/lib/webhooks/integrations/telegram.ts +67 -0
- package/src/lib/ws/handshake.ts +129 -0
- package/src/lib/zed-oauth/confirmedAccounts.ts +38 -0
- package/src/lib/zed-oauth/credentialFingerprint.ts +23 -0
- package/src/lib/zed-oauth/dockerDetect.ts +38 -0
- package/src/lib/zed-oauth/importUtils.ts +46 -0
- package/src/lib/zed-oauth/keychain-reader.stub.ts +28 -0
- package/src/lib/zed-oauth/keychain-reader.ts +231 -0
- package/src/mitm/_internal/bypass.cjs +170 -0
- package/src/mitm/_internal/forwardTarget.cjs +55 -0
- package/src/mitm/_internal/ingest.cjs +82 -0
- package/src/mitm/cert/generate.ts +41 -0
- package/src/mitm/cert/install.stub.ts +23 -0
- package/src/mitm/cert/install.ts +440 -0
- package/src/mitm/dataDir.ts +41 -0
- package/src/mitm/detection/antigravity.ts +33 -0
- package/src/mitm/detection/claudeCode.ts +25 -0
- package/src/mitm/detection/codex.ts +25 -0
- package/src/mitm/detection/copilot.ts +39 -0
- package/src/mitm/detection/cursor.ts +31 -0
- package/src/mitm/detection/index.ts +53 -0
- package/src/mitm/detection/kiro.ts +30 -0
- package/src/mitm/detection/openCode.ts +32 -0
- package/src/mitm/detection/zed.ts +26 -0
- package/src/mitm/dns/dnsConfig.ts +242 -0
- package/src/mitm/dns/provision.ts +92 -0
- package/src/mitm/handlers/antigravity.ts +192 -0
- package/src/mitm/handlers/base.ts +333 -0
- package/src/mitm/handlers/claudeCode.ts +56 -0
- package/src/mitm/handlers/codex.ts +55 -0
- package/src/mitm/handlers/copilot.ts +55 -0
- package/src/mitm/handlers/cursor.ts +55 -0
- package/src/mitm/handlers/kiro.ts +58 -0
- package/src/mitm/handlers/openCode.ts +55 -0
- package/src/mitm/handlers/trae.ts +24 -0
- package/src/mitm/handlers/zed.ts +55 -0
- package/src/mitm/inspector/agentBridgeHook.ts +137 -0
- package/src/mitm/inspector/buffer.ts +201 -0
- package/src/mitm/inspector/contextKey.ts +98 -0
- package/src/mitm/inspector/conversationNormalizer.ts +393 -0
- package/src/mitm/inspector/diagnostics.ts +67 -0
- package/src/mitm/inspector/httpProxyServer.ts +272 -0
- package/src/mitm/inspector/kindDetector.ts +87 -0
- package/src/mitm/inspector/llmMetadataExtractor.ts +183 -0
- package/src/mitm/inspector/pricing.ts +57 -0
- package/src/mitm/inspector/processAttribution.ts +107 -0
- package/src/mitm/inspector/sseMerger.ts +316 -0
- package/src/mitm/inspector/systemProxyConfig.ts +316 -0
- package/src/mitm/inspector/types.ts +112 -0
- package/src/mitm/manager.runtime.ts +5 -0
- package/src/mitm/manager.stub.ts +44 -0
- package/src/mitm/manager.ts +762 -0
- package/src/mitm/maskSecrets.ts +31 -0
- package/src/mitm/passthrough.ts +76 -0
- package/src/mitm/sanitizeHeaders.ts +61 -0
- package/src/mitm/server.cjs +786 -0
- package/src/mitm/socketTimeouts.ts +24 -0
- package/src/mitm/systemCommands.ts +280 -0
- package/src/mitm/targets/antigravity.ts +85 -0
- package/src/mitm/targets/claudeCode.ts +37 -0
- package/src/mitm/targets/codex.ts +30 -0
- package/src/mitm/targets/copilot.ts +32 -0
- package/src/mitm/targets/cursor.ts +33 -0
- package/src/mitm/targets/index.ts +75 -0
- package/src/mitm/targets/kiro.ts +64 -0
- package/src/mitm/targets/openCode.ts +34 -0
- package/src/mitm/targets/trae.ts +32 -0
- package/src/mitm/targets/zed.ts +32 -0
- package/src/mitm/tproxy/caTrust.ts +120 -0
- package/src/mitm/tproxy/captureManager.ts +118 -0
- package/src/mitm/tproxy/captureMode.ts +226 -0
- package/src/mitm/tproxy/commands.ts +122 -0
- package/src/mitm/tproxy/dynamicCert.ts +119 -0
- package/src/mitm/tproxy/native/README.md +55 -0
- package/src/mitm/tproxy/native/binding.gyp +9 -0
- package/src/mitm/tproxy/native/transparent.c +147 -0
- package/src/mitm/tproxy/setup.ts +68 -0
- package/src/mitm/tproxy/tlsCapture.ts +368 -0
- package/src/mitm/tproxy/transparentSocket.ts +131 -0
- package/src/mitm/types.ts +75 -0
- package/src/mitm/upstreamTrust.ts +40 -0
- package/src/models/index.ts +29 -0
- package/src/server/auth/loginGuard.ts +130 -0
- package/src/server/authz/accessScopes.ts +62 -0
- package/src/server/authz/accessTokenAuth.ts +67 -0
- package/src/server/authz/assertAuth.ts +88 -0
- package/src/server/authz/classify.ts +135 -0
- package/src/server/authz/context.ts +44 -0
- package/src/server/authz/csrf.ts +85 -0
- package/src/server/authz/headers.ts +76 -0
- package/src/server/authz/peerStamp.ts +99 -0
- package/src/server/authz/pipeline.ts +370 -0
- package/src/server/authz/policies/clientApi.ts +72 -0
- package/src/server/authz/policies/management.ts +298 -0
- package/src/server/authz/policies/public.ts +9 -0
- package/src/server/authz/routeGuard.ts +233 -0
- package/src/server/authz/types.ts +77 -0
- package/src/server/cors/origins.ts +172 -0
- package/src/server/origin/publicOrigin.ts +270 -0
- package/src/server/ws/liveServer.ts +630 -0
- package/src/server/ws/liveServerAllowList.ts +106 -0
- package/src/server/ws/types.ts +57 -0
- package/src/shared/components/Avatar.tsx +81 -0
- package/src/shared/components/Badge.tsx +68 -0
- package/src/shared/components/Breadcrumbs.tsx +103 -0
- package/src/shared/components/Button.tsx +85 -0
- package/src/shared/components/Card.tsx +141 -0
- package/src/shared/components/Checkbox.tsx +38 -0
- package/src/shared/components/CloudSyncStatus.tsx +104 -0
- package/src/shared/components/Collapsible.tsx +93 -0
- package/src/shared/components/CollapsibleSection.tsx +66 -0
- package/src/shared/components/ColumnToggle.tsx +100 -0
- package/src/shared/components/CommandPalette.tsx +375 -0
- package/src/shared/components/ConsoleLogViewer.tsx +326 -0
- package/src/shared/components/CursorAuthModal.tsx +198 -0
- package/src/shared/components/DataTable.tsx +195 -0
- package/src/shared/components/DegradationBadge.tsx +41 -0
- package/src/shared/components/DistributeProxiesButton.tsx +74 -0
- package/src/shared/components/EmptyState.tsx +121 -0
- package/src/shared/components/ErrorPageScaffold.tsx +91 -0
- package/src/shared/components/FilterBar.tsx +197 -0
- package/src/shared/components/Footer.tsx +169 -0
- package/src/shared/components/Header.tsx +284 -0
- package/src/shared/components/InfoTooltip.tsx +34 -0
- package/src/shared/components/Input.tsx +155 -0
- package/src/shared/components/KiroAuthModal.tsx +425 -0
- package/src/shared/components/KiroOAuthWrapper.tsx +116 -0
- package/src/shared/components/KiroSocialOAuthModal.tsx +202 -0
- package/src/shared/components/LanguageSelector.tsx +106 -0
- package/src/shared/components/LinkifiedText.tsx +30 -0
- package/src/shared/components/Loading.tsx +128 -0
- package/src/shared/components/LocaleAutoDetect.tsx +43 -0
- package/src/shared/components/MaintenanceBanner.tsx +87 -0
- package/src/shared/components/ManualConfigModal.tsx +51 -0
- package/src/shared/components/Modal.tsx +240 -0
- package/src/shared/components/ModelRoutingSection.tsx +323 -0
- package/src/shared/components/ModelSelectModal.tsx +618 -0
- package/src/shared/components/MonacoEditor.tsx +23 -0
- package/src/shared/components/NavigationProgress.tsx +105 -0
- package/src/shared/components/NoAuthAccountCard.tsx +539 -0
- package/src/shared/components/NoAuthProviderCard.tsx +40 -0
- package/src/shared/components/NoAuthProviderToggle.tsx +36 -0
- package/src/shared/components/NotificationToast.tsx +206 -0
- package/src/shared/components/OAuthModal.tsx +992 -0
- package/src/shared/components/OmniRouteLogo.tsx +86 -0
- package/src/shared/components/PresetSlider.tsx +64 -0
- package/src/shared/components/PricingModal.tsx +211 -0
- package/src/shared/components/ProviderIcon.tsx +263 -0
- package/src/shared/components/ProviderTestSlideOver.tsx +560 -0
- package/src/shared/components/ProxyConfigModal.tsx +781 -0
- package/src/shared/components/ProxyLogDetail.tsx +192 -0
- package/src/shared/components/ProxyLogger.tsx +573 -0
- package/src/shared/components/PwaRegister.tsx +22 -0
- package/src/shared/components/RequestLoggerDetail.tsx +797 -0
- package/src/shared/components/RequestLoggerV2.tsx +1628 -0
- package/src/shared/components/RiskNoticeModal.tsx +81 -0
- package/src/shared/components/SegmentedControl.tsx +69 -0
- package/src/shared/components/Select.tsx +110 -0
- package/src/shared/components/Sidebar.tsx +726 -0
- package/src/shared/components/SkillsConceptCard.tsx +84 -0
- package/src/shared/components/SystemMonitor.tsx +179 -0
- package/src/shared/components/Textarea.tsx +29 -0
- package/src/shared/components/ThemeProvider.tsx +14 -0
- package/src/shared/components/ThemeToggle.tsx +52 -0
- package/src/shared/components/Toggle.tsx +102 -0
- package/src/shared/components/TokenHealthBadge.tsx +113 -0
- package/src/shared/components/Tooltip.tsx +193 -0
- package/src/shared/components/TraeAuthModal.tsx +334 -0
- package/src/shared/components/UsageAnalytics.tsx +414 -0
- package/src/shared/components/UsageStats.tsx +693 -0
- package/src/shared/components/analytics/ApiKeyFilterDropdown.tsx +205 -0
- package/src/shared/components/analytics/CustomRangePicker.tsx +195 -0
- package/src/shared/components/analytics/TimeRangeSelector.tsx +49 -0
- package/src/shared/components/analytics/chartColors.ts +12 -0
- package/src/shared/components/analytics/charts.tsx +1023 -0
- package/src/shared/components/analytics/index.tsx +28 -0
- package/src/shared/components/analytics/rechartsCore.tsx +85 -0
- package/src/shared/components/analytics/rechartsDonuts.tsx +195 -0
- package/src/shared/components/analytics/rechartsUsageCharts.tsx +312 -0
- package/src/shared/components/cli/CliComparisonCard.tsx +82 -0
- package/src/shared/components/cli/CliConceptCard.tsx +58 -0
- package/src/shared/components/cli/CliToolCard.tsx +152 -0
- package/src/shared/components/cli/index.ts +8 -0
- package/src/shared/components/compression/CompressionPipelineEditor.tsx +175 -0
- package/src/shared/components/compression/EngineConfigForm.tsx +78 -0
- package/src/shared/components/compression/EngineConfigPage.tsx +411 -0
- package/src/shared/components/compression/compressionPipelineModel.ts +78 -0
- package/src/shared/components/docs/APIReference.stories.tsx +35 -0
- package/src/shared/components/docs/APIReference.tsx +83 -0
- package/src/shared/components/docs/Callout.stories.tsx +40 -0
- package/src/shared/components/docs/Callout.tsx +38 -0
- package/src/shared/components/docs/CodeBlock.stories.tsx +25 -0
- package/src/shared/components/docs/CodeBlock.tsx +52 -0
- package/src/shared/components/docs/DocsBreadcrumbs.stories.tsx +20 -0
- package/src/shared/components/docs/DocsBreadcrumbs.tsx +46 -0
- package/src/shared/components/docs/DocsSidebar.stories.tsx +31 -0
- package/src/shared/components/docs/DocsSidebar.tsx +77 -0
- package/src/shared/components/docs/DocsThemeProvider.tsx +21 -0
- package/src/shared/components/docs/Tabs.stories.tsx +26 -0
- package/src/shared/components/docs/Tabs.tsx +50 -0
- package/src/shared/components/docs/tokens.ts +38 -0
- package/src/shared/components/flow/FlowCanvas.tsx +151 -0
- package/src/shared/components/flow/StatusDot.tsx +36 -0
- package/src/shared/components/flow/edgeStyles.ts +32 -0
- package/src/shared/components/index.tsx +49 -0
- package/src/shared/components/layouts/AuthLayout.tsx +28 -0
- package/src/shared/components/layouts/DashboardLayout.tsx +131 -0
- package/src/shared/components/layouts/index.tsx +3 -0
- package/src/shared/components/lobeProviderIcons.ts +488 -0
- package/src/shared/components/logTableStyles.ts +7 -0
- package/src/shared/components/modelSelectModalHelpers.ts +75 -0
- package/src/shared/components/oauthBlobSubmit.ts +42 -0
- package/src/shared/components/proxyAssignment.ts +40 -0
- package/src/shared/components/requestLoggerPreferences.ts +44 -0
- package/src/shared/components/requestLoggerSignature.ts +56 -0
- package/src/shared/constants/agentSkills.ts +457 -0
- package/src/shared/constants/antigravityClientProfile.ts +29 -0
- package/src/shared/constants/apiKeyPolicyScopes.ts +5 -0
- package/src/shared/constants/appConfig.ts +12 -0
- package/src/shared/constants/batch.ts +1 -0
- package/src/shared/constants/batchEndpoints.ts +11 -0
- package/src/shared/constants/bodySize.ts +39 -0
- package/src/shared/constants/cliCompatProviders.ts +88 -0
- package/src/shared/constants/cliTools.ts +862 -0
- package/src/shared/constants/clientIdentityProfiles.ts +89 -0
- package/src/shared/constants/colors.ts +147 -0
- package/src/shared/constants/comboConfigMode.ts +9 -0
- package/src/shared/constants/config.ts +44 -0
- package/src/shared/constants/dashboardCsrf.ts +1 -0
- package/src/shared/constants/endpointCategories.ts +133 -0
- package/src/shared/constants/errorCodes.ts +245 -0
- package/src/shared/constants/featureFlagDefinitions.ts +495 -0
- package/src/shared/constants/headers.ts +16 -0
- package/src/shared/constants/homeWidgets.ts +5 -0
- package/src/shared/constants/index.ts +4 -0
- package/src/shared/constants/managementScopes.ts +31 -0
- package/src/shared/constants/mcpScopes.ts +78 -0
- package/src/shared/constants/mitmToolHosts.ts +31 -0
- package/src/shared/constants/modal.ts +5 -0
- package/src/shared/constants/modelCompat.ts +9 -0
- package/src/shared/constants/modelSpecs.ts +607 -0
- package/src/shared/constants/models.ts +40 -0
- package/src/shared/constants/openRouterPreset.ts +11 -0
- package/src/shared/constants/pricing/default-pricing.ts +16 -0
- package/src/shared/constants/pricing/frontier-labs.ts +386 -0
- package/src/shared/constants/pricing/inference-hosts.ts +208 -0
- package/src/shared/constants/pricing/oauth-subscriptions.ts +599 -0
- package/src/shared/constants/pricing/regional.ts +168 -0
- package/src/shared/constants/pricing/shared-tiers.ts +162 -0
- package/src/shared/constants/pricing.ts +40 -0
- package/src/shared/constants/providers/apikey/enterprise-cloud.ts +214 -0
- package/src/shared/constants/providers/apikey/frontier-labs.ts +253 -0
- package/src/shared/constants/providers/apikey/gateways.ts +662 -0
- package/src/shared/constants/providers/apikey/index.ts +21 -0
- package/src/shared/constants/providers/apikey/inference-hosts.ts +328 -0
- package/src/shared/constants/providers/apikey/regional.ts +372 -0
- package/src/shared/constants/providers/apikey/specialty-media.ts +266 -0
- package/src/shared/constants/providers/audio.ts +71 -0
- package/src/shared/constants/providers/cloud-agent.ts +36 -0
- package/src/shared/constants/providers/local.ts +162 -0
- package/src/shared/constants/providers/noauth.ts +123 -0
- package/src/shared/constants/providers/oauth.ts +231 -0
- package/src/shared/constants/providers/search.ts +125 -0
- package/src/shared/constants/providers/system.ts +16 -0
- package/src/shared/constants/providers/upstream-proxy.ts +36 -0
- package/src/shared/constants/providers/web-cookie.ts +364 -0
- package/src/shared/constants/providers.ts +449 -0
- package/src/shared/constants/publicApiRoutes.ts +62 -0
- package/src/shared/constants/responsesPreviousResponseId.ts +5 -0
- package/src/shared/constants/routingStrategies.ts +216 -0
- package/src/shared/constants/selfServiceScopes.ts +20 -0
- package/src/shared/constants/serviceKinds.ts +34 -0
- package/src/shared/constants/sidebarGroupVisibility.ts +31 -0
- package/src/shared/constants/sidebarVisibility/sections.ts +769 -0
- package/src/shared/constants/sidebarVisibility/types.ts +161 -0
- package/src/shared/constants/sidebarVisibility.ts +291 -0
- package/src/shared/constants/spawnCapablePrefixes.ts +35 -0
- package/src/shared/constants/statusColors.ts +17 -0
- package/src/shared/constants/upstreamHeaders.ts +42 -0
- package/src/shared/constants/visionBridgeDefaults.ts +88 -0
- package/src/shared/constants/visionModels.ts +68 -0
- package/src/shared/contracts/quota.ts +138 -0
- package/src/shared/hooks/cli/useToolBatchStatuses.ts +54 -0
- package/src/shared/hooks/index.ts +3 -0
- package/src/shared/hooks/useCopyToClipboard.ts +38 -0
- package/src/shared/hooks/useDisplayBaseUrl.ts +49 -0
- package/src/shared/hooks/useElectron.ts +197 -0
- package/src/shared/hooks/useTheme.ts +59 -0
- package/src/shared/http/apiErrorMessage.ts +19 -0
- package/src/shared/lib/persistLocale.ts +19 -0
- package/src/shared/middleware/bodySizeGuard.ts +97 -0
- package/src/shared/middleware/chatBodyAdmission.ts +161 -0
- package/src/shared/middleware/correlationId.ts +43 -0
- package/src/shared/network/outboundUrlGuard.ts +276 -0
- package/src/shared/network/remoteImageFetch.ts +182 -0
- package/src/shared/network/safeOutboundFetch.ts +372 -0
- package/src/shared/providers/webSessionCredentials.ts +308 -0
- package/src/shared/reasoning/effortStandardization.ts +124 -0
- package/src/shared/schemas/agentBridge.ts +37 -0
- package/src/shared/schemas/cliCatalog.ts +66 -0
- package/src/shared/schemas/inspector.ts +47 -0
- package/src/shared/schemas/memory.ts +142 -0
- package/src/shared/schemas/playground.ts +67 -0
- package/src/shared/schemas/qdrant.ts +39 -0
- package/src/shared/schemas/quota.ts +61 -0
- package/src/shared/schemas/searchTools.ts +39 -0
- package/src/shared/schemas/validation.ts +154 -0
- package/src/shared/services/apiKeyResolver.ts +44 -0
- package/src/shared/services/backupService.ts +233 -0
- package/src/shared/services/claudeCliConfig.ts +17 -0
- package/src/shared/services/cliRuntime.ts +1099 -0
- package/src/shared/services/cloudSyncScheduler.ts +135 -0
- package/src/shared/services/droidCustomModels.ts +118 -0
- package/src/shared/services/initializeCloudSync.ts +31 -0
- package/src/shared/services/loginShellPath.ts +87 -0
- package/src/shared/services/modelSyncScheduler.ts +225 -0
- package/src/shared/services/opencodeConfig.ts +140 -0
- package/src/shared/services/providerLimitsSyncScheduler.ts +72 -0
- package/src/shared/types/cliBatchStatus.ts +18 -0
- package/src/shared/types/index.ts +3 -0
- package/src/shared/types/pagination.ts +61 -0
- package/src/shared/types/utilization.ts +405 -0
- package/src/shared/utils/a11yAudit.ts +140 -0
- package/src/shared/utils/api.ts +112 -0
- package/src/shared/utils/apiAuth.ts +354 -0
- package/src/shared/utils/apiKey.ts +92 -0
- package/src/shared/utils/apiKeyPolicy.ts +680 -0
- package/src/shared/utils/apiResponse.ts +79 -0
- package/src/shared/utils/bulkApiKeyParser.ts +113 -0
- package/src/shared/utils/circuitBreaker.ts +611 -0
- package/src/shared/utils/classify429.ts +253 -0
- package/src/shared/utils/cliCompat.ts +5 -0
- package/src/shared/utils/clineAuth.ts +62 -0
- package/src/shared/utils/clipboard.ts +49 -0
- package/src/shared/utils/cloud.ts +41 -0
- package/src/shared/utils/cn.ts +12 -0
- package/src/shared/utils/codexBaseUrl.ts +32 -0
- package/src/shared/utils/codexConfig.ts +30 -0
- package/src/shared/utils/compressionHeaderEcho.ts +59 -0
- package/src/shared/utils/cors.ts +24 -0
- package/src/shared/utils/costEstimator.ts +126 -0
- package/src/shared/utils/dashboardCsrf.ts +196 -0
- package/src/shared/utils/featureFlags.ts +113 -0
- package/src/shared/utils/fetchError.ts +26 -0
- package/src/shared/utils/fetchTimeout.ts +78 -0
- package/src/shared/utils/formatting.ts +183 -0
- package/src/shared/utils/freeModels.ts +112 -0
- package/src/shared/utils/index.ts +39 -0
- package/src/shared/utils/inputSanitizer.ts +339 -0
- package/src/shared/utils/linkify.ts +54 -0
- package/src/shared/utils/logRedaction.ts +108 -0
- package/src/shared/utils/logger.ts +173 -0
- package/src/shared/utils/machine.ts +5 -0
- package/src/shared/utils/machineId.ts +167 -0
- package/src/shared/utils/maskEmail.ts +77 -0
- package/src/shared/utils/modelCatalogSearch.ts +84 -0
- package/src/shared/utils/noAuthProviders.ts +79 -0
- package/src/shared/utils/nodeRuntimeSupport.ts +112 -0
- package/src/shared/utils/parseApiKeys.ts +41 -0
- package/src/shared/utils/providerDisplayLabel.ts +41 -0
- package/src/shared/utils/providerHints.ts +73 -0
- package/src/shared/utils/providerModelAliases.ts +68 -0
- package/src/shared/utils/rateLimiter.ts +243 -0
- package/src/shared/utils/releaseNotes.ts +53 -0
- package/src/shared/utils/requestId.ts +102 -0
- package/src/shared/utils/requestTelemetry.ts +189 -0
- package/src/shared/utils/requestTimeout.ts +64 -0
- package/src/shared/utils/resolveOmniRouteBaseUrl.ts +24 -0
- package/src/shared/utils/runtimeTimeouts.ts +257 -0
- package/src/shared/utils/secretsValidator.ts +135 -0
- package/src/shared/utils/secureRandom.ts +66 -0
- package/src/shared/utils/serviceTierLabels.ts +42 -0
- package/src/shared/utils/shuffleDeck.ts +147 -0
- package/src/shared/utils/sidebarRouteMatch.ts +43 -0
- package/src/shared/utils/streamTracker.ts +187 -0
- package/src/shared/utils/structuredLogger.ts +219 -0
- package/src/shared/utils/tiktokenCounter.ts +21 -0
- package/src/shared/utils/turkishText.ts +66 -0
- package/src/shared/utils/upstreamError.ts +112 -0
- package/src/shared/validation/compressionConfigSchemas.ts +234 -0
- package/src/shared/validation/freeProxySchemas.ts +111 -0
- package/src/shared/validation/helpers.ts +117 -0
- package/src/shared/validation/oneproxySchemas.ts +14 -0
- package/src/shared/validation/providerSchema.ts +51 -0
- package/src/shared/validation/providerSpecificData.ts +354 -0
- package/src/shared/validation/schemas/apiV1.ts +297 -0
- package/src/shared/validation/schemas/auth.ts +200 -0
- package/src/shared/validation/schemas/cli.ts +86 -0
- package/src/shared/validation/schemas/cloud.ts +53 -0
- package/src/shared/validation/schemas/combo.ts +373 -0
- package/src/shared/validation/schemas/evals.ts +86 -0
- package/src/shared/validation/schemas/gemini.ts +59 -0
- package/src/shared/validation/schemas/keys.ts +144 -0
- package/src/shared/validation/schemas/misc.ts +203 -0
- package/src/shared/validation/schemas/payloadRules.ts +64 -0
- package/src/shared/validation/schemas/pricing.ts +40 -0
- package/src/shared/validation/schemas/provider.ts +430 -0
- package/src/shared/validation/schemas/proxy.ts +243 -0
- package/src/shared/validation/schemas/routing.ts +88 -0
- package/src/shared/validation/schemas/settings.ts +267 -0
- package/src/shared/validation/schemas/translator.ts +44 -0
- package/src/shared/validation/schemas.ts +18 -0
- package/src/shared/validation/settingsSchemas.ts +396 -0
- package/src/sse/handlers/chat.ts +1750 -0
- package/src/sse/handlers/chatHelpers.ts +859 -0
- package/src/sse/handlers/requestBody.ts +24 -0
- package/src/sse/handlers/resolveRoutingModel.ts +17 -0
- package/src/sse/services/auth.ts +2446 -0
- package/src/sse/services/cooldownAwareRetry.ts +162 -0
- package/src/sse/services/model.ts +254 -0
- package/src/sse/services/noAuthProviderSettings.ts +18 -0
- package/src/sse/services/noAuthProxyResolution.ts +111 -0
- package/src/sse/services/sessionAffinityPin.ts +247 -0
- package/src/sse/services/streamState.ts +218 -0
- package/src/sse/services/tokenRefresh.ts +275 -0
- package/src/sse/utils/logger.ts +37 -0
- package/src/types/databaseSettings.ts +124 -0
- package/src/types/global.d.ts +122 -0
- package/src/types/index.ts +10 -0
- package/src/types/provider.ts +9 -0
- package/src/types/sqljs.d.ts +32 -0
|
@@ -0,0 +1,1716 @@
|
|
|
1
|
+
import crypto, { randomUUID } from "crypto";
|
|
2
|
+
import {
|
|
3
|
+
BaseExecutor,
|
|
4
|
+
mergeAbortSignals,
|
|
5
|
+
mergeUpstreamExtraHeaders,
|
|
6
|
+
type ExecuteInput,
|
|
7
|
+
type ExecutorLog,
|
|
8
|
+
type ProviderCredentials,
|
|
9
|
+
} from "./base.ts";
|
|
10
|
+
import { applyFingerprint, isCliCompatEnabled } from "../config/cliFingerprints.ts";
|
|
11
|
+
import { buildAntigravityUpstreamError } from "./antigravityUpstreamError.ts";
|
|
12
|
+
import {
|
|
13
|
+
PROVIDERS,
|
|
14
|
+
OAUTH_ENDPOINTS,
|
|
15
|
+
HTTP_STATUS,
|
|
16
|
+
STREAM_READINESS_TIMEOUT_MS,
|
|
17
|
+
ANTIGRAVITY_PRE_RESPONSE_TIMEOUT_CODE,
|
|
18
|
+
} from "../config/constants.ts";
|
|
19
|
+
import { scrubProxyAndFingerprintHeaders } from "../services/antigravityHeaderScrub.ts";
|
|
20
|
+
import {
|
|
21
|
+
antigravityNativeOAuthUserAgent,
|
|
22
|
+
antigravityUserAgent,
|
|
23
|
+
} from "../services/antigravityHeaders.ts";
|
|
24
|
+
import { classify429, decide429, type Decision } from "../services/antigravity429Engine.ts";
|
|
25
|
+
import {
|
|
26
|
+
injectCreditsField,
|
|
27
|
+
shouldRetryWithCredits,
|
|
28
|
+
shouldUseCreditsFirst,
|
|
29
|
+
getCreditsMode,
|
|
30
|
+
handleCreditsFailure,
|
|
31
|
+
} from "../services/antigravityCredits.ts";
|
|
32
|
+
import { persistCreditBalance, getAllPersistedCreditBalances } from "@/lib/db/creditBalance";
|
|
33
|
+
import { setConnectionRateLimitUntil } from "@/lib/db/providers";
|
|
34
|
+
import { getMitmAlias } from "@/lib/db/models";
|
|
35
|
+
import { obfuscateSensitiveWords } from "../services/antigravityObfuscation.ts";
|
|
36
|
+
import { resolveAntigravityVersion } from "../services/antigravityVersion.ts";
|
|
37
|
+
import { ensureAntigravityProjectAssigned } from "../services/antigravityProjectBootstrap.ts";
|
|
38
|
+
import {
|
|
39
|
+
resolveAntigravityModelId,
|
|
40
|
+
getAntigravityModelFallbacks,
|
|
41
|
+
} from "../config/antigravityModelAliases.ts";
|
|
42
|
+
import { cloakAntigravityToolPayload } from "../config/toolCloaking.ts";
|
|
43
|
+
import {
|
|
44
|
+
shouldStripCloudCodeThinking,
|
|
45
|
+
stripCloudCodeThinkingConfig,
|
|
46
|
+
} from "../services/cloudCodeThinking.ts";
|
|
47
|
+
import { buildGeminiTools } from "../translator/helpers/geminiToolsSanitizer.ts";
|
|
48
|
+
import { DEFAULT_SAFETY_SETTINGS } from "../translator/helpers/geminiHelper.ts";
|
|
49
|
+
import {
|
|
50
|
+
type AntigravityCollectedStream,
|
|
51
|
+
processAntigravitySSEText,
|
|
52
|
+
flushAntigravitySSEText,
|
|
53
|
+
} from "./antigravity/sseCollect.ts";
|
|
54
|
+
// processAntigravitySSEPayload re-exported for external importers (tests).
|
|
55
|
+
export { processAntigravitySSEPayload } from "./antigravity/sseCollect.ts";
|
|
56
|
+
import {
|
|
57
|
+
applyAntigravityClientProfileHeaders,
|
|
58
|
+
removeHeaderCaseInsensitive,
|
|
59
|
+
} from "../services/antigravityClientProfile.ts";
|
|
60
|
+
import {
|
|
61
|
+
generateAntigravityRequestId,
|
|
62
|
+
getAntigravityEnvelopeUserAgent,
|
|
63
|
+
getAntigravitySessionId,
|
|
64
|
+
} from "../services/antigravityIdentity.ts";
|
|
65
|
+
import * as prl from "../utils/providerRequestLogging.ts";
|
|
66
|
+
|
|
67
|
+
const MAX_RETRY_AFTER_MS = 60_000;
|
|
68
|
+
const LONG_RETRY_THRESHOLD_MS = 60_000;
|
|
69
|
+
const CREDITS_EXHAUSTED_TTL_MS = 5 * 60 * 60 * 1000; // 5 hours
|
|
70
|
+
// Cap for transient 5xx backoff — shorter than the 429 cap to avoid long stalls on
|
|
71
|
+
// infra hiccups ("Agent execution terminated", "high traffic", capacity errors).
|
|
72
|
+
const ANTIGRAVITY_TRANSIENT_RETRY_MAX_MS = 15_000;
|
|
73
|
+
|
|
74
|
+
const ANTIGRAVITY_TRANSIENT_ERROR_PATTERNS: RegExp[] = [
|
|
75
|
+
/high\s+traffic/i,
|
|
76
|
+
/agent\s+(execution\s+)?terminated\s+due\s+to\s+error/i,
|
|
77
|
+
/capacity/i,
|
|
78
|
+
/temporarily\s+unavailable/i,
|
|
79
|
+
/timeout/i,
|
|
80
|
+
/stream\s+(ended|closed|terminated|interrupted)/i,
|
|
81
|
+
/empty\s+response/i,
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
const ANTIGRAVITY_TRANSIENT_STATUSES = new Set([
|
|
85
|
+
HTTP_STATUS.SERVER_ERROR,
|
|
86
|
+
HTTP_STATUS.BAD_GATEWAY,
|
|
87
|
+
HTTP_STATUS.SERVICE_UNAVAILABLE,
|
|
88
|
+
HTTP_STATUS.GATEWAY_TIMEOUT,
|
|
89
|
+
]);
|
|
90
|
+
// The upstream API uses plain model IDs (no -high/-low suffix).
|
|
91
|
+
// Tier suffixes were speculative and caused 404 for gemini-3.x models — the
|
|
92
|
+
// bare-Pro→Low normalization was retired (the set stayed empty, making the guard
|
|
93
|
+
// dead code). Only keep models that are live-proven via streamGenerateContent.
|
|
94
|
+
|
|
95
|
+
interface AntigravityContent {
|
|
96
|
+
role: string;
|
|
97
|
+
parts: unknown[];
|
|
98
|
+
[key: string]: unknown;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
type AntigravityCredentials = ProviderCredentials & {
|
|
102
|
+
projectId?: string | null;
|
|
103
|
+
expiresIn?: number;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
type AntigravityChunkContent = Record<string, unknown> & {
|
|
107
|
+
role?: string;
|
|
108
|
+
parts?: Array<
|
|
109
|
+
Record<string, unknown> & {
|
|
110
|
+
text?: unknown;
|
|
111
|
+
functionCall?: Record<string, unknown>;
|
|
112
|
+
functionResponse?: unknown;
|
|
113
|
+
thought?: unknown;
|
|
114
|
+
thoughtSignature?: unknown;
|
|
115
|
+
}
|
|
116
|
+
>;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
type AntigravityCreditEntry = {
|
|
120
|
+
creditType?: string;
|
|
121
|
+
creditAmount?: string;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
function getChunkedOrFixedBody(bodyStr: string, stream: boolean): BodyInit {
|
|
125
|
+
if (stream) {
|
|
126
|
+
return new ReadableStream(
|
|
127
|
+
{
|
|
128
|
+
async start(controller) {
|
|
129
|
+
controller.enqueue(new TextEncoder().encode(bodyStr));
|
|
130
|
+
controller.close();
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
{ highWaterMark: 16384 }
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
return bodyStr;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function cloneAntigravityRequestBody(body: unknown): unknown {
|
|
140
|
+
if (!body || typeof body !== "object") {
|
|
141
|
+
return body;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
try {
|
|
145
|
+
return structuredClone(body);
|
|
146
|
+
} catch {
|
|
147
|
+
return JSON.parse(JSON.stringify(body));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function serializeAntigravityRequest(
|
|
152
|
+
provider: string,
|
|
153
|
+
headers: Record<string, string>,
|
|
154
|
+
body: unknown
|
|
155
|
+
): { headers: Record<string, string>; bodyString: string } {
|
|
156
|
+
const serializedBody = cloneAntigravityRequestBody(body);
|
|
157
|
+
|
|
158
|
+
if (!isCliCompatEnabled(provider)) {
|
|
159
|
+
return { headers, bodyString: JSON.stringify(serializedBody) };
|
|
160
|
+
}
|
|
161
|
+
return applyFingerprint(provider, { ...headers }, serializedBody);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
type AntigravityRequestEnvelope = Record<string, unknown> & {
|
|
165
|
+
project: string;
|
|
166
|
+
model?: string;
|
|
167
|
+
userAgent: "antigravity" | "jetski";
|
|
168
|
+
requestType: "agent" | "image_gen";
|
|
169
|
+
requestId: string;
|
|
170
|
+
request: Record<string, unknown>;
|
|
171
|
+
enabledCreditTypes?: string[];
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
class AntigravityPreResponseTimeoutError extends Error {
|
|
175
|
+
code = ANTIGRAVITY_PRE_RESPONSE_TIMEOUT_CODE;
|
|
176
|
+
status = HTTP_STATUS.GATEWAY_TIMEOUT;
|
|
177
|
+
|
|
178
|
+
constructor(timeoutMs: number, url: string) {
|
|
179
|
+
super(`Antigravity upstream did not return response headers within ${timeoutMs}ms: ${url}`);
|
|
180
|
+
this.name = "TimeoutError";
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function getAbortErrorCode(error: unknown): string | null {
|
|
185
|
+
if (!error || typeof error !== "object") return null;
|
|
186
|
+
const value = (error as { code?: unknown }).code;
|
|
187
|
+
return typeof value === "string" ? value : null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function isAntigravityPreResponseTimeout(error: unknown): boolean {
|
|
191
|
+
return getAbortErrorCode(error) === ANTIGRAVITY_PRE_RESPONSE_TIMEOUT_CODE;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Per-account GOOGLE_ONE_AI credits-exhausted tracker.
|
|
196
|
+
* Key: accountId (OAuth subject / email). Value: expiry timestamp.
|
|
197
|
+
* When credits hit 0 we skip the credit retry for CREDITS_EXHAUSTED_TTL_MS.
|
|
198
|
+
*/
|
|
199
|
+
const MAX_CREDITS_EXHAUSTED_ENTRIES = 50;
|
|
200
|
+
const creditsExhaustedUntil = new Map<string, number>();
|
|
201
|
+
|
|
202
|
+
const _creditsExhaustedSweep = setInterval(() => {
|
|
203
|
+
const now = Date.now();
|
|
204
|
+
for (const [key, until] of creditsExhaustedUntil) {
|
|
205
|
+
if (now >= until) creditsExhaustedUntil.delete(key);
|
|
206
|
+
}
|
|
207
|
+
}, 60_000);
|
|
208
|
+
if (typeof _creditsExhaustedSweep === "object" && "unref" in _creditsExhaustedSweep) {
|
|
209
|
+
(_creditsExhaustedSweep as { unref?: () => void }).unref?.();
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const MAX_CREDIT_BALANCE_ENTRIES = 50;
|
|
213
|
+
const CREDIT_BALANCE_TTL_MS = 5 * 60 * 1000;
|
|
214
|
+
const creditBalanceCache = new Map<string, { balance: number; updatedAt: number }>();
|
|
215
|
+
let creditCacheHydrated = false;
|
|
216
|
+
|
|
217
|
+
function hydrateCreditCacheFromDb(): void {
|
|
218
|
+
if (creditCacheHydrated) return;
|
|
219
|
+
creditCacheHydrated = true;
|
|
220
|
+
try {
|
|
221
|
+
const persisted = getAllPersistedCreditBalances();
|
|
222
|
+
for (const [accountId, balance] of persisted) {
|
|
223
|
+
if (!creditBalanceCache.has(accountId)) {
|
|
224
|
+
creditBalanceCache.set(accountId, { balance, updatedAt: Date.now() });
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
} catch {}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function evictStaleCreditBalanceEntries(): void {
|
|
231
|
+
const now = Date.now();
|
|
232
|
+
for (const [key, entry] of creditBalanceCache) {
|
|
233
|
+
if (now - entry.updatedAt > CREDIT_BALANCE_TTL_MS) {
|
|
234
|
+
creditBalanceCache.delete(key);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
while (creditBalanceCache.size > MAX_CREDIT_BALANCE_ENTRIES) {
|
|
238
|
+
const oldestKey = creditBalanceCache.keys().next().value;
|
|
239
|
+
if (oldestKey !== undefined) creditBalanceCache.delete(oldestKey);
|
|
240
|
+
else break;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const _creditBalanceSweep = setInterval(evictStaleCreditBalanceEntries, 60_000);
|
|
245
|
+
if (typeof _creditBalanceSweep === "object" && "unref" in _creditBalanceSweep) {
|
|
246
|
+
(_creditBalanceSweep as { unref?: () => void }).unref?.();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export function getAntigravityRemainingCredits(accountId: string): number | null {
|
|
250
|
+
hydrateCreditCacheFromDb();
|
|
251
|
+
const entry = creditBalanceCache.get(accountId);
|
|
252
|
+
if (!entry) return null;
|
|
253
|
+
if (Date.now() - entry.updatedAt > CREDIT_BALANCE_TTL_MS) {
|
|
254
|
+
creditBalanceCache.delete(accountId);
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
return entry.balance;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export function updateAntigravityRemainingCredits(accountId: string, balance: number): void {
|
|
261
|
+
if (creditBalanceCache.size >= MAX_CREDIT_BALANCE_ENTRIES && !creditBalanceCache.has(accountId)) {
|
|
262
|
+
const oldestKey = creditBalanceCache.keys().next().value;
|
|
263
|
+
if (oldestKey !== undefined) creditBalanceCache.delete(oldestKey);
|
|
264
|
+
}
|
|
265
|
+
creditBalanceCache.set(accountId, { balance, updatedAt: Date.now() });
|
|
266
|
+
try {
|
|
267
|
+
persistCreditBalance(accountId, balance);
|
|
268
|
+
} catch {}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function isCreditsExhausted(accountId: string): boolean {
|
|
272
|
+
const until = creditsExhaustedUntil.get(accountId);
|
|
273
|
+
if (!until) return false;
|
|
274
|
+
if (Date.now() >= until) {
|
|
275
|
+
creditsExhaustedUntil.delete(accountId);
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
return true;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function markCreditsExhausted(accountId: string): void {
|
|
282
|
+
if (
|
|
283
|
+
creditsExhaustedUntil.size >= MAX_CREDITS_EXHAUSTED_ENTRIES &&
|
|
284
|
+
!creditsExhaustedUntil.has(accountId)
|
|
285
|
+
) {
|
|
286
|
+
const now = Date.now();
|
|
287
|
+
for (const [key, until] of creditsExhaustedUntil) {
|
|
288
|
+
if (now >= until) {
|
|
289
|
+
creditsExhaustedUntil.delete(key);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (creditsExhaustedUntil.size >= MAX_CREDITS_EXHAUSTED_ENTRIES) {
|
|
293
|
+
const oldestKey = creditsExhaustedUntil.keys().next().value;
|
|
294
|
+
if (oldestKey !== undefined) creditsExhaustedUntil.delete(oldestKey);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
creditsExhaustedUntil.set(accountId, Date.now() + CREDITS_EXHAUSTED_TTL_MS);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Persist a quota-exhausted cooldown to the DB for `connectionId` so that
|
|
302
|
+
* cross-request and post-restart routing skips this connection until the
|
|
303
|
+
* cooldown expires. Exported for unit testing. @internal
|
|
304
|
+
*/
|
|
305
|
+
export function markConnectionQuotaExhausted(connectionId: string, retryAfterMs: number): void {
|
|
306
|
+
try {
|
|
307
|
+
setConnectionRateLimitUntil(connectionId, Date.now() + retryAfterMs);
|
|
308
|
+
} catch {
|
|
309
|
+
// DB write failure must never crash the request path
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Accumulate one Antigravity SSE `data:` payload into `collected`. Exported for unit
|
|
315
|
+
* tests (the markdown / candidate-parts extraction branches). @internal
|
|
316
|
+
*/
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Strip provider prefixes (e.g. "antigravity/model" → "model").
|
|
320
|
+
* Ensures the model name sent to the upstream API never contains a routing prefix.
|
|
321
|
+
*
|
|
322
|
+
* `modelIdOverride` (#3786): when the per-request Pro-family fallback chain forces a
|
|
323
|
+
* specific upstream id, pass it here. It is an ALREADY-RESOLVED upstream id, so it bypasses
|
|
324
|
+
* the MITM/static alias resolution and is used verbatim (after prefix stripping).
|
|
325
|
+
*/
|
|
326
|
+
async function cleanModelName(model: string, modelIdOverride?: string): Promise<string> {
|
|
327
|
+
if (modelIdOverride) {
|
|
328
|
+
return modelIdOverride.includes("/") ? modelIdOverride.split("/").pop()! : modelIdOverride;
|
|
329
|
+
}
|
|
330
|
+
if (!model) return model;
|
|
331
|
+
const stripped = model.includes("/") ? model.split("/").pop()! : model;
|
|
332
|
+
let clean = stripped;
|
|
333
|
+
|
|
334
|
+
// 1. Check dynamic MITM aliases first (authoritative after first sync).
|
|
335
|
+
// Built during model sync — contains ONLY currently-available models.
|
|
336
|
+
// Obsolete/removed models are automatically excluded.
|
|
337
|
+
try {
|
|
338
|
+
const mitmAliases = await getMitmAlias("antigravity");
|
|
339
|
+
if (mitmAliases && typeof mitmAliases === "object") {
|
|
340
|
+
const aliases = mitmAliases as Record<string, unknown>;
|
|
341
|
+
const raw = aliases[stripped];
|
|
342
|
+
// Only honor string aliases; corrupted/non-string DB values fall through
|
|
343
|
+
// to the static alias resolution below (never return undefined here).
|
|
344
|
+
if (typeof raw === "string" && raw) {
|
|
345
|
+
// Strip the "antigravity/" prefix if present; use the raw model ID otherwise.
|
|
346
|
+
const PREFIX = "antigravity/";
|
|
347
|
+
clean = raw.startsWith(PREFIX) ? raw.slice(PREFIX.length) : raw;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
} catch {
|
|
351
|
+
// DB not available (build phase, transient error) — fall through to static aliases
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// 2. Fall back to static aliases if MITM didn't resolve
|
|
355
|
+
if (clean === stripped) {
|
|
356
|
+
clean = resolveAntigravityModelId(clean);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return clean;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function attachToolNameMap<T>(payload: T, toolNameMap: Map<string, string> | null): T {
|
|
363
|
+
if (!toolNameMap?.size || !payload || typeof payload !== "object") {
|
|
364
|
+
return payload;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const copy = Array.isArray(payload) ? ([...payload] as T) : ({ ...(payload as object) } as T);
|
|
368
|
+
Object.defineProperty(copy, "_toolNameMap", {
|
|
369
|
+
value: toolNameMap,
|
|
370
|
+
enumerable: false,
|
|
371
|
+
configurable: true,
|
|
372
|
+
writable: true,
|
|
373
|
+
});
|
|
374
|
+
return copy;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function getRequestTargetModel(body: Record<string, unknown>): string {
|
|
378
|
+
const target = body.model;
|
|
379
|
+
return typeof target === "string" && target.length > 0 ? target : "unknown";
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Hard ceiling on `generationConfig.maxOutputTokens` for Antigravity Cloud Code.
|
|
384
|
+
*
|
|
385
|
+
* Ports decolua/9router#779 (lukmanfauzie): VS Code GitHub Copilot Chat in
|
|
386
|
+
* Agent mode regularly requests 32K–65K output tokens, which the Antigravity
|
|
387
|
+
* backend rejects with HTTP 400 "Invalid Argument". 16384 matches the
|
|
388
|
+
* upstream-accepted ceiling confirmed via successful 200 OK runs with
|
|
389
|
+
* claude-sonnet-4-6 and gemini-3.1-pro-high across both Ask and Agent modes.
|
|
390
|
+
*/
|
|
391
|
+
export const MAX_ANTIGRAVITY_OUTPUT_TOKENS = 16384;
|
|
392
|
+
|
|
393
|
+
function applyAntigravityGenerationDefaults(request: Record<string, unknown>): void {
|
|
394
|
+
const generationConfig =
|
|
395
|
+
request.generationConfig && typeof request.generationConfig === "object"
|
|
396
|
+
? (request.generationConfig as Record<string, unknown>)
|
|
397
|
+
: {};
|
|
398
|
+
|
|
399
|
+
if (generationConfig.topK === undefined) {
|
|
400
|
+
generationConfig.topK = 40;
|
|
401
|
+
}
|
|
402
|
+
if (generationConfig.topP === undefined) {
|
|
403
|
+
generationConfig.topP = 1.0;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const thinkingConfig =
|
|
407
|
+
generationConfig.thinkingConfig && typeof generationConfig.thinkingConfig === "object"
|
|
408
|
+
? (generationConfig.thinkingConfig as Record<string, unknown>)
|
|
409
|
+
: null;
|
|
410
|
+
const thinkingBudget = Number(thinkingConfig?.thinkingBudget);
|
|
411
|
+
const maxOutputTokens = Number(generationConfig.maxOutputTokens);
|
|
412
|
+
if (
|
|
413
|
+
Number.isFinite(thinkingBudget) &&
|
|
414
|
+
thinkingBudget > 0 &&
|
|
415
|
+
(!Number.isFinite(maxOutputTokens) || maxOutputTokens <= thinkingBudget)
|
|
416
|
+
) {
|
|
417
|
+
generationConfig.maxOutputTokens = Math.floor(thinkingBudget) + 1;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// Final cap (after the thinkingBudget bump may have raised the value):
|
|
421
|
+
// GitHub Copilot Agent envelopes commonly carry oversized maxOutputTokens
|
|
422
|
+
// (32K–65K) that trigger upstream 400 "Invalid Argument". Clamp silently
|
|
423
|
+
// — the cap is provider-driven, not client-driven, and only matters when
|
|
424
|
+
// the request would otherwise be rejected outright.
|
|
425
|
+
const finalMax = Number(generationConfig.maxOutputTokens);
|
|
426
|
+
if (Number.isFinite(finalMax) && finalMax > MAX_ANTIGRAVITY_OUTPUT_TOKENS) {
|
|
427
|
+
generationConfig.maxOutputTokens = MAX_ANTIGRAVITY_OUTPUT_TOKENS;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
request.generationConfig = generationConfig;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// Test-only export so the unit suite can exercise the cap logic in isolation
|
|
434
|
+
// without spinning up the full executor.
|
|
435
|
+
export const __test_applyAntigravityGenerationDefaults = applyAntigravityGenerationDefaults;
|
|
436
|
+
|
|
437
|
+
function asRecord(value: unknown): Record<string, unknown> | null {
|
|
438
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
439
|
+
? (value as Record<string, unknown>)
|
|
440
|
+
: null;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function sanitizeAntigravityGeminiRequest(
|
|
444
|
+
request: Record<string, unknown>
|
|
445
|
+
): Record<string, unknown> {
|
|
446
|
+
const clean: Record<string, unknown> = {};
|
|
447
|
+
|
|
448
|
+
if (Array.isArray(request.contents)) {
|
|
449
|
+
clean.contents = request.contents;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
if (asRecord(request.systemInstruction)) {
|
|
453
|
+
clean.systemInstruction = request.systemInstruction;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
clean.generationConfig = asRecord(request.generationConfig)
|
|
457
|
+
? { ...(request.generationConfig as Record<string, unknown>) }
|
|
458
|
+
: {};
|
|
459
|
+
|
|
460
|
+
const geminiTools = buildGeminiTools(request.tools);
|
|
461
|
+
if (geminiTools) {
|
|
462
|
+
clean.tools = geminiTools;
|
|
463
|
+
clean.toolConfig = { functionCallingConfig: { mode: "VALIDATED" } };
|
|
464
|
+
} else if (asRecord(request.toolConfig)) {
|
|
465
|
+
clean.toolConfig = request.toolConfig;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
if (typeof request.sessionId === "string") {
|
|
469
|
+
clean.sessionId = request.sessionId;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// #5003: preserve safetySettings through the Claude-path whitelist so the all-OFF
|
|
473
|
+
// default (or a caller-supplied value) actually reaches Google Cloud Code. Without
|
|
474
|
+
// this the field is dropped and Google applies its own safety defaults that
|
|
475
|
+
// false-flag benign technical prompts as `prohibited_content`.
|
|
476
|
+
if (Array.isArray(request.safetySettings)) {
|
|
477
|
+
clean.safetySettings = request.safetySettings;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
return clean;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Ported from decolua/9router#2321 (anki1kr): Vertex AI (used by Antigravity for
|
|
485
|
+
* Claude-branded models) rejects a conversation ending on an assistant turn —
|
|
486
|
+
* "This model does not support assistant message prefill" — so the request must
|
|
487
|
+
* always end on a user turn. Upstream patched `openaiToClaudeRequestForAntigravity`
|
|
488
|
+
* (dead code here, zero callers — see `open-sse/translator/request/openai-to-claude.ts`);
|
|
489
|
+
* this relocates the same strip to the LIVE Antigravity dispatch path, where Claude
|
|
490
|
+
* requests are converted to Gemini `contents` (assistant role is `"model"`, not
|
|
491
|
+
* `"assistant"`). Mirrors the trailing-strip pop-loop already used for Mistral
|
|
492
|
+
* (#3396), Copilot (#5802), and the CC-bridge in `claudeCodeCompatible.ts`.
|
|
493
|
+
*
|
|
494
|
+
* Scoped strictly to the Claude path by the caller (`isClaude` branch only) — native
|
|
495
|
+
* Gemini models via Antigravity must be unaffected, since Vertex-Claude is the only
|
|
496
|
+
* documented rejection surface.
|
|
497
|
+
*
|
|
498
|
+
* Guard: never strip `contents` down to empty — an empty `contents` array is itself
|
|
499
|
+
* an invalid request, so at least one entry (even a lone trailing "model" turn) is
|
|
500
|
+
* always preserved.
|
|
501
|
+
*/
|
|
502
|
+
function stripTrailingAntigravityAssistantTurn(
|
|
503
|
+
request: Record<string, unknown>
|
|
504
|
+
): Record<string, unknown> {
|
|
505
|
+
const contents = request.contents;
|
|
506
|
+
if (!Array.isArray(contents) || contents.length === 0) {
|
|
507
|
+
return request;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
while (
|
|
511
|
+
contents.length > 1 &&
|
|
512
|
+
(contents[contents.length - 1] as AntigravityContent)?.role === "model"
|
|
513
|
+
) {
|
|
514
|
+
contents.pop();
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
return request;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// Test-only export so the unit suite can exercise the strip logic directly.
|
|
521
|
+
export const __test_stripTrailingAntigravityAssistantTurn = stripTrailingAntigravityAssistantTurn;
|
|
522
|
+
|
|
523
|
+
export class AntigravityExecutor extends BaseExecutor {
|
|
524
|
+
constructor() {
|
|
525
|
+
super("antigravity", PROVIDERS.antigravity);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
buildUrl(model: string, _stream: boolean, urlIndex = 0): string {
|
|
529
|
+
void model;
|
|
530
|
+
const baseUrls = this.getBaseUrls();
|
|
531
|
+
const baseUrl = baseUrls[urlIndex] || baseUrls[0];
|
|
532
|
+
// Always use streaming endpoint — the non-streaming `generateContent` causes
|
|
533
|
+
// upstream 400 errors for some models (e.g. gpt-oss-120b-medium) because the
|
|
534
|
+
// Cloud Code API internally converts to OpenAI format and injects
|
|
535
|
+
// stream_options without setting stream=true. chatCore already handles
|
|
536
|
+
// SSE→JSON conversion for non-streaming client requests.
|
|
537
|
+
return `${baseUrl}/v1internal:streamGenerateContent?alt=sse`;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
buildHeaders(credentials: AntigravityCredentials, _stream = true): Record<string, string> {
|
|
541
|
+
const raw = {
|
|
542
|
+
"Content-Type": "application/json",
|
|
543
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
544
|
+
"User-Agent": antigravityUserAgent(),
|
|
545
|
+
Accept: "text/event-stream",
|
|
546
|
+
"X-OmniRoute-Source": "omniroute",
|
|
547
|
+
};
|
|
548
|
+
// Scrub proxy/fingerprint headers that reveal non-native traffic
|
|
549
|
+
return scrubProxyAndFingerprintHeaders(raw);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
async transformRequest(
|
|
553
|
+
model: string,
|
|
554
|
+
body: unknown,
|
|
555
|
+
_stream: boolean,
|
|
556
|
+
credentials: AntigravityCredentials,
|
|
557
|
+
modelIdOverride?: string
|
|
558
|
+
): Promise<AntigravityRequestEnvelope | Response> {
|
|
559
|
+
// Project ID resolution: prefer OAuth-stored projectId over incoming body.project
|
|
560
|
+
// to avoid stale/wrong client-side values causing 404/403 from Cloud Code endpoints.
|
|
561
|
+
// Opt-in escape hatch: set OMNIROUTER_ALLOW_BODY_PROJECT_OVERRIDE=1.
|
|
562
|
+
const normalizeProjectId = (value: unknown): string | null => {
|
|
563
|
+
if (typeof value !== "string") return null;
|
|
564
|
+
const trimmedValue = value.trim();
|
|
565
|
+
return trimmedValue ? trimmedValue : null;
|
|
566
|
+
};
|
|
567
|
+
const bodyRecord = asRecord(body) ?? {};
|
|
568
|
+
const bodyProjectId = normalizeProjectId(bodyRecord.project);
|
|
569
|
+
const credentialsProjectId = normalizeProjectId(credentials?.projectId);
|
|
570
|
+
const providerSpecificProjectId = normalizeProjectId(
|
|
571
|
+
(credentials?.providerSpecificData as Record<string, unknown> | undefined)?.projectId
|
|
572
|
+
);
|
|
573
|
+
const allowBodyProjectOverride = process.env.OMNIROUTE_ALLOW_BODY_PROJECT_OVERRIDE === "1";
|
|
574
|
+
|
|
575
|
+
// Default: prefer OAuth-stored projectId over incoming body.project to avoid
|
|
576
|
+
// stale/wrong client-side values causing 404/403 from Cloud Code endpoints.
|
|
577
|
+
// Opt-in escape hatch: set OMNIROUTE_ALLOW_BODY_PROJECT_OVERRIDE=1.
|
|
578
|
+
let projectId =
|
|
579
|
+
allowBodyProjectOverride && bodyProjectId
|
|
580
|
+
? bodyProjectId
|
|
581
|
+
: credentialsProjectId || providerSpecificProjectId || bodyProjectId;
|
|
582
|
+
|
|
583
|
+
// Auto-discover a missing projectId via loadCodeAssist before failing (#2334/#2541).
|
|
584
|
+
// A freshly re-added Antigravity account can have an empty stored projectId even when
|
|
585
|
+
// its Google account already owns a Cloud Code project (the OAuth-time loadCodeAssist
|
|
586
|
+
// returned empty/transiently failed). Mirror the Cloud Code bootstrap to recover it
|
|
587
|
+
// here — the helper memoizes per access-token, so this is a one-time round-trip.
|
|
588
|
+
if (!projectId && credentials?.accessToken) {
|
|
589
|
+
const discovered = await ensureAntigravityProjectAssigned(credentials.accessToken);
|
|
590
|
+
if (discovered) projectId = discovered;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
if (!projectId) {
|
|
594
|
+
// (#489) Return a structured error instead of throwing — gives the client a clear signal
|
|
595
|
+
// to show a "Reconnect OAuth" prompt rather than an opaque "Internal Server Error".
|
|
596
|
+
const errorMsg =
|
|
597
|
+
"Missing Google projectId for Antigravity account. Auto-discovery via loadCodeAssist " +
|
|
598
|
+
"found no Cloud Code project. Please reconnect OAuth in Providers → Antigravity (and " +
|
|
599
|
+
"ensure the Google account has completed Gemini Code Assist onboarding).";
|
|
600
|
+
const errorBody = {
|
|
601
|
+
error: {
|
|
602
|
+
message: errorMsg,
|
|
603
|
+
type: "oauth_missing_project_id",
|
|
604
|
+
code: "missing_project_id",
|
|
605
|
+
},
|
|
606
|
+
};
|
|
607
|
+
const resp = new Response(JSON.stringify(errorBody), {
|
|
608
|
+
status: 422,
|
|
609
|
+
headers: { "Content-Type": "application/json" },
|
|
610
|
+
});
|
|
611
|
+
// Returning a Response object signals the executor to stop and forward it
|
|
612
|
+
return resp as unknown as never;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// Validate projectId is non-empty and not just whitespace
|
|
616
|
+
const trimmedProjectId = typeof projectId === "string" ? projectId.trim() : projectId;
|
|
617
|
+
if (!trimmedProjectId) {
|
|
618
|
+
const resp = new Response(
|
|
619
|
+
JSON.stringify({
|
|
620
|
+
error: {
|
|
621
|
+
message:
|
|
622
|
+
"Invalid (empty) Google projectId for Antigravity account. " +
|
|
623
|
+
"Please reconnect OAuth in Providers → Antigravity.",
|
|
624
|
+
type: "oauth_missing_project_id",
|
|
625
|
+
code: "missing_project_id",
|
|
626
|
+
},
|
|
627
|
+
}),
|
|
628
|
+
{ status: 422, headers: { "Content-Type": "application/json" } }
|
|
629
|
+
);
|
|
630
|
+
return resp as unknown as never;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
const upstreamModel = await cleanModelName(model, modelIdOverride);
|
|
634
|
+
const isClaude = upstreamModel.toLowerCase().includes("claude");
|
|
635
|
+
const baseBody = bodyRecord;
|
|
636
|
+
const normalizedBody = shouldStripCloudCodeThinking(this.provider, upstreamModel)
|
|
637
|
+
? stripCloudCodeThinkingConfig(baseBody)
|
|
638
|
+
: baseBody;
|
|
639
|
+
const normalizedRequest = asRecord(normalizedBody.request);
|
|
640
|
+
const rawContents = Array.isArray(normalizedRequest?.contents)
|
|
641
|
+
? normalizedRequest.contents
|
|
642
|
+
: [];
|
|
643
|
+
|
|
644
|
+
// Fix contents for Gemini-compatible Cloud Code requests via Antigravity.
|
|
645
|
+
// Claude-branded Antigravity models use the same streamGenerateContent schema.
|
|
646
|
+
const normalizedContents: AntigravityContent[] =
|
|
647
|
+
rawContents.map((content): AntigravityContent => {
|
|
648
|
+
const c = content as AntigravityChunkContent;
|
|
649
|
+
let role = typeof c.role === "string" ? c.role : "user";
|
|
650
|
+
if (c.parts?.some((p) => p.functionResponse)) {
|
|
651
|
+
role = "user";
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
const hasFunctionCall = c.parts?.some((p) => p.functionCall) || false;
|
|
655
|
+
|
|
656
|
+
const parts =
|
|
657
|
+
c.parts?.filter((p) => {
|
|
658
|
+
if (typeof p.text === "string" && p.text === "") return false;
|
|
659
|
+
if (p.functionCall && !p.functionCall.name) return false;
|
|
660
|
+
|
|
661
|
+
// Only strip if it's NOT our bypass sentinel.
|
|
662
|
+
// Antigravity models (like Gemini) need this sentinel to bypass 400 errors.
|
|
663
|
+
return (
|
|
664
|
+
!p.thought &&
|
|
665
|
+
(hasFunctionCall ||
|
|
666
|
+
!p.thoughtSignature ||
|
|
667
|
+
p.thoughtSignature === "skip_thought_signature_validator")
|
|
668
|
+
);
|
|
669
|
+
}) || [];
|
|
670
|
+
return { ...c, role, parts };
|
|
671
|
+
}) || [];
|
|
672
|
+
|
|
673
|
+
const contents: AntigravityContent[] = [];
|
|
674
|
+
for (const c of normalizedContents) {
|
|
675
|
+
if (!Array.isArray(c.parts) || c.parts.length === 0) continue;
|
|
676
|
+
if (contents.length > 0 && contents[contents.length - 1].role === c.role) {
|
|
677
|
+
contents[contents.length - 1].parts.push(...c.parts);
|
|
678
|
+
} else {
|
|
679
|
+
contents.push(c);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
const rawTransformedRequest = {
|
|
684
|
+
...normalizedRequest,
|
|
685
|
+
...(contents.length > 0 && { contents }),
|
|
686
|
+
sessionId: getAntigravitySessionId(
|
|
687
|
+
credentials,
|
|
688
|
+
typeof normalizedRequest?.sessionId === "string" ? normalizedRequest.sessionId : undefined
|
|
689
|
+
),
|
|
690
|
+
// #5003: default to all-OFF safety for parity with the native Gemini paths
|
|
691
|
+
// (claude-to-gemini / openai-to-gemini both default to DEFAULT_SAFETY_SETTINGS).
|
|
692
|
+
// Previously this was `undefined`, which JSON.stringify drops, so Google Cloud Code
|
|
693
|
+
// applied its server-side defaults that false-flag benign technical prompts as
|
|
694
|
+
// `prohibited_content` (HTTP 200 + blocked body → terminal combo failover).
|
|
695
|
+
safetySettings: normalizedRequest?.safetySettings ?? DEFAULT_SAFETY_SETTINGS,
|
|
696
|
+
toolConfig:
|
|
697
|
+
Array.isArray(normalizedRequest?.tools) && normalizedRequest.tools.length > 0
|
|
698
|
+
? { functionCallingConfig: { mode: "VALIDATED" } }
|
|
699
|
+
: normalizedRequest?.toolConfig,
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
const transformedRequest = isClaude
|
|
703
|
+
? stripTrailingAntigravityAssistantTurn(sanitizeAntigravityGeminiRequest(rawTransformedRequest))
|
|
704
|
+
: rawTransformedRequest;
|
|
705
|
+
|
|
706
|
+
// Obfuscate sensitive client names in user content (e.g. "OpenCode", "Cursor")
|
|
707
|
+
const requestContents = transformedRequest.contents;
|
|
708
|
+
if (Array.isArray(requestContents)) {
|
|
709
|
+
for (const msg of requestContents) {
|
|
710
|
+
if (Array.isArray(msg.parts)) {
|
|
711
|
+
for (const part of msg.parts) {
|
|
712
|
+
if (typeof part.text === "string") {
|
|
713
|
+
part.text = obfuscateSensitiveWords(part.text);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
applyAntigravityGenerationDefaults(transformedRequest);
|
|
721
|
+
|
|
722
|
+
const {
|
|
723
|
+
project: _project,
|
|
724
|
+
model: _model,
|
|
725
|
+
userAgent: _userAgent,
|
|
726
|
+
requestType: _requestType,
|
|
727
|
+
requestId: _requestId,
|
|
728
|
+
request: _request,
|
|
729
|
+
// #1944: output_config (and the legacy output_format) are Anthropic/Claude-Code-only
|
|
730
|
+
// fields. Google's Cloud Code envelope rejects unknown top-level fields with a 400
|
|
731
|
+
// ("Invalid JSON payload received. Unknown name \"output_config\""), which broke every
|
|
732
|
+
// Claude model served via Antigravity. Drop them so they never reach the envelope.
|
|
733
|
+
output_config: _outputConfig,
|
|
734
|
+
output_format: _outputFormat,
|
|
735
|
+
// #1926: the unified thinking adapter can also set Claude/OpenAI-native thinking fields
|
|
736
|
+
// at the body root. Google rejects them with `400 Bad input: oneOf at '/' not met`
|
|
737
|
+
// (or `Unknown name "thinking"`), breaking every reasoning/thinking model served via
|
|
738
|
+
// Antigravity (e.g. claude-opus-4-x-thinking). Strip the whole thinking family too.
|
|
739
|
+
thinking: _thinking,
|
|
740
|
+
reasoning_effort: _reasoningEffort,
|
|
741
|
+
reasoning: _reasoning,
|
|
742
|
+
enable_thinking: _enableThinking,
|
|
743
|
+
thinking_budget: _thinkingBudget,
|
|
744
|
+
...passthroughFields
|
|
745
|
+
} = normalizedBody;
|
|
746
|
+
|
|
747
|
+
const requestType = _requestType === "image_gen" ? "image_gen" : "agent";
|
|
748
|
+
const envelope: AntigravityRequestEnvelope = {
|
|
749
|
+
project: projectId,
|
|
750
|
+
requestId: generateAntigravityRequestId(),
|
|
751
|
+
request: transformedRequest,
|
|
752
|
+
model: upstreamModel,
|
|
753
|
+
userAgent: getAntigravityEnvelopeUserAgent(credentials),
|
|
754
|
+
requestType,
|
|
755
|
+
...passthroughFields,
|
|
756
|
+
};
|
|
757
|
+
|
|
758
|
+
if (requestType === "agent" && envelope.enabledCreditTypes === undefined) {
|
|
759
|
+
envelope.enabledCreditTypes = ["GOOGLE_ONE_AI"];
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
return envelope;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
async refreshCredentials(
|
|
766
|
+
credentials: AntigravityCredentials,
|
|
767
|
+
log?: ExecutorLog | null
|
|
768
|
+
): Promise<AntigravityCredentials | null> {
|
|
769
|
+
if (!credentials.refreshToken) return null;
|
|
770
|
+
|
|
771
|
+
try {
|
|
772
|
+
const bodyParams: Record<string, string> = {
|
|
773
|
+
grant_type: "refresh_token",
|
|
774
|
+
refresh_token: credentials.refreshToken,
|
|
775
|
+
};
|
|
776
|
+
// Only include non-empty client_id/client_secret — Google OAuth rejects
|
|
777
|
+
// empty params which raw URLSearchParams produces (buildFormParams semantics).
|
|
778
|
+
if (this.config.clientId) bodyParams.client_id = this.config.clientId;
|
|
779
|
+
if (this.config.clientSecret) bodyParams.client_secret = this.config.clientSecret;
|
|
780
|
+
|
|
781
|
+
const response = await fetch(OAUTH_ENDPOINTS.google.token, {
|
|
782
|
+
method: "POST",
|
|
783
|
+
headers: {
|
|
784
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
785
|
+
Accept: "application/json",
|
|
786
|
+
"User-Agent": antigravityNativeOAuthUserAgent(),
|
|
787
|
+
},
|
|
788
|
+
body: new URLSearchParams(bodyParams),
|
|
789
|
+
});
|
|
790
|
+
|
|
791
|
+
if (!response.ok) {
|
|
792
|
+
// Detect unrecoverable token (invalid_grant = revoked / expired refresh token)
|
|
793
|
+
try {
|
|
794
|
+
const errorBody = (await response.json()) as Record<string, unknown>;
|
|
795
|
+
if (errorBody.error === "invalid_grant") {
|
|
796
|
+
log?.error?.("TOKEN", "Antigravity refresh token revoked. Re-authentication required.");
|
|
797
|
+
return { error: "unrecoverable_refresh_error" } as unknown as AntigravityCredentials;
|
|
798
|
+
}
|
|
799
|
+
} catch {
|
|
800
|
+
// not JSON — fall through
|
|
801
|
+
}
|
|
802
|
+
return null;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
const tokens = (await response.json()) as Record<string, unknown>;
|
|
806
|
+
log?.info?.("TOKEN", "Antigravity refreshed");
|
|
807
|
+
|
|
808
|
+
return {
|
|
809
|
+
accessToken: typeof tokens.access_token === "string" ? tokens.access_token : undefined,
|
|
810
|
+
refreshToken:
|
|
811
|
+
typeof tokens.refresh_token === "string" && tokens.refresh_token
|
|
812
|
+
? tokens.refresh_token
|
|
813
|
+
: credentials.refreshToken,
|
|
814
|
+
expiresIn: typeof tokens.expires_in === "number" ? tokens.expires_in : undefined,
|
|
815
|
+
projectId: credentials.projectId,
|
|
816
|
+
// Preserve providerSpecificData so a projectId stored there survives the refresh
|
|
817
|
+
// (the onCredentialsRefreshed DB write) instead of being dropped → 422 (#2480).
|
|
818
|
+
providerSpecificData: credentials.providerSpecificData,
|
|
819
|
+
};
|
|
820
|
+
} catch (error) {
|
|
821
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
822
|
+
log?.error?.("TOKEN", `Antigravity refresh error: ${message}`);
|
|
823
|
+
return null;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
generateSessionId(): string {
|
|
828
|
+
return `-${parseInt(randomUUID().replace(/-/g, "").substring(0, 8), 16) % 9_000_000_000_000_000_000}`;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
parseRetryHeaders(headers: Headers | null | undefined): number | null {
|
|
832
|
+
if (!headers?.get) return null;
|
|
833
|
+
|
|
834
|
+
const retryAfter = headers.get("retry-after");
|
|
835
|
+
if (retryAfter) {
|
|
836
|
+
const seconds = parseInt(retryAfter, 10);
|
|
837
|
+
if (!isNaN(seconds) && seconds > 0) return seconds * 1000;
|
|
838
|
+
|
|
839
|
+
const date = new Date(retryAfter);
|
|
840
|
+
if (!isNaN(date.getTime())) {
|
|
841
|
+
const diff = date.getTime() - Date.now();
|
|
842
|
+
return diff > 0 ? diff : null;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
const resetAfter = headers.get("x-ratelimit-reset-after");
|
|
847
|
+
if (resetAfter) {
|
|
848
|
+
const seconds = parseInt(resetAfter, 10);
|
|
849
|
+
if (!isNaN(seconds) && seconds > 0) return seconds * 1000;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
const resetTimestamp = headers.get("x-ratelimit-reset");
|
|
853
|
+
if (resetTimestamp) {
|
|
854
|
+
const ts = parseInt(resetTimestamp, 10) * 1000;
|
|
855
|
+
const diff = ts - Date.now();
|
|
856
|
+
return diff > 0 ? diff : null;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
return null;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
// Parse retry time from Antigravity error message body
|
|
863
|
+
// Format: "Your quota will reset after 2h7m23s" or "Resets in 160h27m24s" or
|
|
864
|
+
// "1h30m" or "45m" or "30s". The optional plural ("resets in") must match too (#1308).
|
|
865
|
+
parseRetryFromErrorMessage(errorMessage: unknown): number | null {
|
|
866
|
+
if (!errorMessage || typeof errorMessage !== "string") return null;
|
|
867
|
+
|
|
868
|
+
const match = errorMessage.match(/resets? (?:after|in) (\d+h)?(\d+m)?(\d+s)?/i);
|
|
869
|
+
if (!match) return null;
|
|
870
|
+
|
|
871
|
+
let totalMs = 0;
|
|
872
|
+
if (match[1]) totalMs += parseInt(match[1]) * 3600 * 1000; // hours
|
|
873
|
+
if (match[2]) totalMs += parseInt(match[2]) * 60 * 1000; // minutes
|
|
874
|
+
if (match[3]) totalMs += parseInt(match[3]) * 1000; // seconds
|
|
875
|
+
|
|
876
|
+
// "reset after 0s" = burst/RPM limit, not quota exhaustion.
|
|
877
|
+
// Return a minimum backoff so the auto-retry loop handles it
|
|
878
|
+
// instead of falling through to the 24h exhaustion classifier.
|
|
879
|
+
if (totalMs === 0) return 2_000; // 2s minimum burst-limit backoff
|
|
880
|
+
|
|
881
|
+
return totalMs;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
/**
|
|
885
|
+
* Flatten an Antigravity error JSON + raw body text into a single string so
|
|
886
|
+
* isTransientAntigravityError can match against body patterns.
|
|
887
|
+
*/
|
|
888
|
+
extractErrorMessage(errorJson: unknown, bodyText = ""): string {
|
|
889
|
+
const candidates: string[] = [];
|
|
890
|
+
if (errorJson && typeof errorJson === "object") {
|
|
891
|
+
const obj = errorJson as Record<string, unknown>;
|
|
892
|
+
const errField = obj.error;
|
|
893
|
+
if (errField && typeof errField === "object") {
|
|
894
|
+
const msg = (errField as Record<string, unknown>).message;
|
|
895
|
+
if (typeof msg === "string") candidates.push(msg);
|
|
896
|
+
else if (msg != null) candidates.push(JSON.stringify(msg));
|
|
897
|
+
} else if (typeof errField === "string") {
|
|
898
|
+
candidates.push(errField);
|
|
899
|
+
}
|
|
900
|
+
if (typeof obj.message === "string") candidates.push(obj.message);
|
|
901
|
+
}
|
|
902
|
+
if (bodyText) candidates.push(bodyText);
|
|
903
|
+
return candidates.filter(Boolean).join("\n");
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* Return true when a status + error message combination should be retried
|
|
908
|
+
* with exponential backoff instead of immediately failing-over to the next URL.
|
|
909
|
+
* 429 is always transient. Transient 5xx statuses (500/502/503/504) are also
|
|
910
|
+
* retried when the body contains a known capacity/traffic/agent pattern.
|
|
911
|
+
*/
|
|
912
|
+
isTransientAntigravityError(status: number, message: string): boolean {
|
|
913
|
+
if (status === HTTP_STATUS.RATE_LIMITED) return true;
|
|
914
|
+
if (ANTIGRAVITY_TRANSIENT_STATUSES.has(status)) return true;
|
|
915
|
+
return ANTIGRAVITY_TRANSIENT_ERROR_PATTERNS.some((p) => p.test(message || ""));
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
/**
|
|
919
|
+
* Collect an SSE streaming response into a single non-streaming JSON response.
|
|
920
|
+
* Parses Gemini-format SSE chunks and assembles text content + usage into one
|
|
921
|
+
* OpenAI-format chat.completion payload.
|
|
922
|
+
*/
|
|
923
|
+
collectStreamToResponse(
|
|
924
|
+
response: Response,
|
|
925
|
+
model: string,
|
|
926
|
+
url: string,
|
|
927
|
+
headers: Record<string, string>,
|
|
928
|
+
transformedBody: Record<string, unknown>,
|
|
929
|
+
log?: ExecutorLog | null,
|
|
930
|
+
signal?: AbortSignal | null
|
|
931
|
+
) {
|
|
932
|
+
if (!response.body) {
|
|
933
|
+
return Promise.resolve({ response, url, headers, transformedBody });
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
const reader = response.body.getReader();
|
|
937
|
+
const decoder = new TextDecoder();
|
|
938
|
+
const logger = log || undefined;
|
|
939
|
+
|
|
940
|
+
const SSE_COLLECT_TIMEOUT_MS = 120_000;
|
|
941
|
+
|
|
942
|
+
const collect = async () => {
|
|
943
|
+
const collected: AntigravityCollectedStream = {
|
|
944
|
+
textContent: "",
|
|
945
|
+
finishReason: "stop",
|
|
946
|
+
toolCalls: [],
|
|
947
|
+
usage: null,
|
|
948
|
+
remainingCredits: null,
|
|
949
|
+
};
|
|
950
|
+
const partialLine = { value: "" };
|
|
951
|
+
let timedOut = false;
|
|
952
|
+
const timeout = AbortSignal.timeout(SSE_COLLECT_TIMEOUT_MS);
|
|
953
|
+
try {
|
|
954
|
+
while (true) {
|
|
955
|
+
if (signal?.aborted) throw new Error("Request aborted during SSE collection");
|
|
956
|
+
const { done, value } = await Promise.race([
|
|
957
|
+
reader.read(),
|
|
958
|
+
new Promise<never>((_, reject) =>
|
|
959
|
+
timeout.addEventListener(
|
|
960
|
+
"abort",
|
|
961
|
+
() => reject(new Error("SSE collection timed out")),
|
|
962
|
+
{ once: true }
|
|
963
|
+
)
|
|
964
|
+
),
|
|
965
|
+
]);
|
|
966
|
+
if (done) break;
|
|
967
|
+
processAntigravitySSEText(
|
|
968
|
+
decoder.decode(value, { stream: true }),
|
|
969
|
+
partialLine,
|
|
970
|
+
collected,
|
|
971
|
+
logger
|
|
972
|
+
);
|
|
973
|
+
}
|
|
974
|
+
} catch (err) {
|
|
975
|
+
const msg = err?.message || String(err);
|
|
976
|
+
timedOut = msg.includes("timed out");
|
|
977
|
+
log?.warn?.("SSE_COLLECT", `Error collecting SSE stream: ${msg}`);
|
|
978
|
+
// Cancel the stream to prevent locking the socket in Undici pool
|
|
979
|
+
try {
|
|
980
|
+
reader.releaseLock();
|
|
981
|
+
} catch (_) {}
|
|
982
|
+
try {
|
|
983
|
+
response.body?.cancel().catch(() => {});
|
|
984
|
+
} catch (_) {}
|
|
985
|
+
} finally {
|
|
986
|
+
try {
|
|
987
|
+
reader.releaseLock();
|
|
988
|
+
} catch (_) {}
|
|
989
|
+
}
|
|
990
|
+
processAntigravitySSEText(decoder.decode(), partialLine, collected, logger);
|
|
991
|
+
flushAntigravitySSEText(partialLine, collected, logger);
|
|
992
|
+
|
|
993
|
+
const result = {
|
|
994
|
+
id: `chatcmpl-${Date.now()}-${crypto.randomUUID().slice(0, 8)}`,
|
|
995
|
+
object: "chat.completion",
|
|
996
|
+
created: Math.floor(Date.now() / 1000),
|
|
997
|
+
model,
|
|
998
|
+
choices: [
|
|
999
|
+
{
|
|
1000
|
+
index: 0,
|
|
1001
|
+
message:
|
|
1002
|
+
collected.toolCalls.length > 0
|
|
1003
|
+
? {
|
|
1004
|
+
role: "assistant",
|
|
1005
|
+
content: collected.textContent || null,
|
|
1006
|
+
tool_calls: collected.toolCalls,
|
|
1007
|
+
}
|
|
1008
|
+
: { role: "assistant", content: collected.textContent },
|
|
1009
|
+
finish_reason: timedOut
|
|
1010
|
+
? "length"
|
|
1011
|
+
: collected.toolCalls.length > 0
|
|
1012
|
+
? "tool_calls"
|
|
1013
|
+
: collected.finishReason,
|
|
1014
|
+
},
|
|
1015
|
+
],
|
|
1016
|
+
...(collected.usage && { usage: collected.usage }),
|
|
1017
|
+
// Expose credit balance for upstream consumers (usage service, dashboard)
|
|
1018
|
+
...(collected.remainingCredits && { _remainingCredits: collected.remainingCredits }),
|
|
1019
|
+
};
|
|
1020
|
+
|
|
1021
|
+
const syntheticStatus = timedOut ? 504 : response.status;
|
|
1022
|
+
const syntheticResponse = new Response(JSON.stringify(result), {
|
|
1023
|
+
status: syntheticStatus,
|
|
1024
|
+
statusText: timedOut ? "Gateway Timeout" : response.statusText,
|
|
1025
|
+
headers: [["Content-Type", "application/json"]],
|
|
1026
|
+
});
|
|
1027
|
+
|
|
1028
|
+
return { response: syntheticResponse, url, headers, transformedBody };
|
|
1029
|
+
};
|
|
1030
|
+
|
|
1031
|
+
return collect();
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
/**
|
|
1035
|
+
* #3786 — Drive the per-request Pro-family upstream-id FALLBACK CHAIN.
|
|
1036
|
+
*
|
|
1037
|
+
* The upstream silently renamed the Gemini 3.1 Pro-high id (HTTP 400 on the old id) and the
|
|
1038
|
+
* live id cannot be known from static analysis (competitor proxies disagree). When the
|
|
1039
|
+
* resolved upstream id has a fallback chain (see ANTIGRAVITY_PRO_FALLBACK_CHAINS) we try the
|
|
1040
|
+
* requested id first and, ONLY on a 400, retry the next candidate until one succeeds (2xx)
|
|
1041
|
+
* or the chain is exhausted — then the original 400 surfaces (sanitized, hard rule #12).
|
|
1042
|
+
*
|
|
1043
|
+
* Off the happy path entirely: a model with no chain, or whose first id is not a 400, makes
|
|
1044
|
+
* exactly the same single call as before (zero extra upstream requests).
|
|
1045
|
+
*/
|
|
1046
|
+
async execute(input: ExecuteInput) {
|
|
1047
|
+
await resolveAntigravityVersion();
|
|
1048
|
+
|
|
1049
|
+
// Look up the chain by the NORMALLY-resolved upstream id (honours MITM/static aliases).
|
|
1050
|
+
// If a MITM alias remapped the id away from a known Pro tier, no chain applies → fast path.
|
|
1051
|
+
const resolvedUpstreamId = await cleanModelName(input.model);
|
|
1052
|
+
const chain = getAntigravityModelFallbacks(resolvedUpstreamId);
|
|
1053
|
+
|
|
1054
|
+
if (chain.length <= 1) {
|
|
1055
|
+
// No fallback chain (flash, claude, plain pro, unknown) → single attempt, unchanged.
|
|
1056
|
+
return this.executeOnce(input);
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
let firstResult: Awaited<ReturnType<AntigravityExecutor["executeOnce"]>> | null = null;
|
|
1060
|
+
for (let i = 0; i < chain.length; i++) {
|
|
1061
|
+
const candidate = chain[i];
|
|
1062
|
+
const result = await this.executeOnce(input, candidate);
|
|
1063
|
+
|
|
1064
|
+
// Success (or any non-400) on a candidate → return immediately.
|
|
1065
|
+
if (result.response.status !== HTTP_STATUS.BAD_REQUEST) {
|
|
1066
|
+
return result;
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
// Remember the FIRST 400 so the exhausted-chain case surfaces the original error.
|
|
1070
|
+
if (i === 0) firstResult = result;
|
|
1071
|
+
|
|
1072
|
+
const isLast = i === chain.length - 1;
|
|
1073
|
+
if (!isLast) {
|
|
1074
|
+
input.log?.debug?.(
|
|
1075
|
+
"AG_PRO_FALLBACK",
|
|
1076
|
+
`400 on "${candidate}" — retrying with next Pro candidate "${chain[i + 1]}"`
|
|
1077
|
+
);
|
|
1078
|
+
continue;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
// Chain exhausted: surface the FIRST candidate's sanitized 400.
|
|
1082
|
+
input.log?.warn?.(
|
|
1083
|
+
"AG_PRO_FALLBACK",
|
|
1084
|
+
`Pro fallback chain exhausted (all ${chain.length} candidates 400'd) for "${resolvedUpstreamId}"`
|
|
1085
|
+
);
|
|
1086
|
+
return firstResult ?? result;
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
// Unreachable (loop always returns), but keeps the type checker happy.
|
|
1090
|
+
return firstResult ?? this.executeOnce(input);
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
/**
|
|
1094
|
+
* #3786 — Run the request once for a SINGLE resolved upstream model id. The Pro-family
|
|
1095
|
+
* fallback chain in `execute()` calls this per candidate (`modelIdOverride`), retrying the
|
|
1096
|
+
* next id on a 400. `modelIdOverride === undefined` is the normal (non-chain) path and
|
|
1097
|
+
* preserves the prior behavior exactly. Returns the executor result plus the upstream
|
|
1098
|
+
* status of the first response so `execute()` can decide whether to fall through. @internal
|
|
1099
|
+
*/
|
|
1100
|
+
private async executeOnce(
|
|
1101
|
+
{ model, body, stream, credentials, signal, log, upstreamExtraHeaders }: ExecuteInput,
|
|
1102
|
+
modelIdOverride?: string
|
|
1103
|
+
) {
|
|
1104
|
+
await resolveAntigravityVersion();
|
|
1105
|
+
const fallbackCount = this.getFallbackCount();
|
|
1106
|
+
let lastError = null;
|
|
1107
|
+
let lastStatus = 0;
|
|
1108
|
+
const MAX_AUTO_RETRIES = 3;
|
|
1109
|
+
const retryAttemptsByUrl: Record<number, number> = {}; // Track retry attempts per URL
|
|
1110
|
+
|
|
1111
|
+
// Always stream upstream — buildUrl always returns the streaming endpoint.
|
|
1112
|
+
// For non-streaming clients, we collect the SSE below and return a synthetic
|
|
1113
|
+
// non-streaming Response so chatCore's non-streaming path stays unchanged.
|
|
1114
|
+
const upstreamStream = true;
|
|
1115
|
+
|
|
1116
|
+
// Account ID for credits tracking.
|
|
1117
|
+
// Use connectionId as the stable cache key — it's available in both the executor
|
|
1118
|
+
// (via credentials.connectionId) and the usage fetcher (via connection.id).
|
|
1119
|
+
// The email-based key was unreliable because email isn't always on the credentials object.
|
|
1120
|
+
const accountId: string = credentials?.connectionId || "unknown";
|
|
1121
|
+
|
|
1122
|
+
// Resolve credits mode once per execute() call. "always" injects
|
|
1123
|
+
// enabledCreditTypes: ["GOOGLE_ONE_AI"] on the first request so the
|
|
1124
|
+
// preflight normal call is skipped entirely.
|
|
1125
|
+
const creditsMode = getCreditsMode();
|
|
1126
|
+
const useCreditsFirst = shouldUseCreditsFirst(credentials?.accessToken || "", creditsMode);
|
|
1127
|
+
|
|
1128
|
+
const fetchWithReadinessTimeout = async (
|
|
1129
|
+
url: string,
|
|
1130
|
+
init: RequestInit,
|
|
1131
|
+
timeoutMs = STREAM_READINESS_TIMEOUT_MS
|
|
1132
|
+
): Promise<Response> => {
|
|
1133
|
+
const boundedTimeoutMs = Math.max(0, Math.floor(timeoutMs));
|
|
1134
|
+
if (boundedTimeoutMs <= 0) {
|
|
1135
|
+
return fetch(url, init);
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
const timeoutController = new AbortController();
|
|
1139
|
+
let timeoutId: ReturnType<typeof setTimeout> | null = setTimeout(() => {
|
|
1140
|
+
timeoutController.abort(new AntigravityPreResponseTimeoutError(boundedTimeoutMs, url));
|
|
1141
|
+
}, boundedTimeoutMs);
|
|
1142
|
+
|
|
1143
|
+
const existingSignal = init.signal instanceof AbortSignal ? init.signal : null;
|
|
1144
|
+
const combinedSignal = existingSignal
|
|
1145
|
+
? mergeAbortSignals(existingSignal, timeoutController.signal)
|
|
1146
|
+
: timeoutController.signal;
|
|
1147
|
+
|
|
1148
|
+
try {
|
|
1149
|
+
return await fetch(url, { ...init, signal: combinedSignal });
|
|
1150
|
+
} catch (error) {
|
|
1151
|
+
if (
|
|
1152
|
+
timeoutController.signal.aborted &&
|
|
1153
|
+
isAntigravityPreResponseTimeout(timeoutController.signal.reason)
|
|
1154
|
+
) {
|
|
1155
|
+
throw timeoutController.signal.reason;
|
|
1156
|
+
}
|
|
1157
|
+
throw error;
|
|
1158
|
+
} finally {
|
|
1159
|
+
if (timeoutId) {
|
|
1160
|
+
clearTimeout(timeoutId);
|
|
1161
|
+
timeoutId = null;
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
};
|
|
1165
|
+
|
|
1166
|
+
for (let urlIndex = 0; urlIndex < fallbackCount; urlIndex++) {
|
|
1167
|
+
const url = this.buildUrl(model, upstreamStream, urlIndex);
|
|
1168
|
+
const headers = this.buildHeaders(credentials, upstreamStream);
|
|
1169
|
+
mergeUpstreamExtraHeaders(headers, upstreamExtraHeaders);
|
|
1170
|
+
const transformed = await this.transformRequest(
|
|
1171
|
+
model,
|
|
1172
|
+
body,
|
|
1173
|
+
upstreamStream,
|
|
1174
|
+
credentials,
|
|
1175
|
+
modelIdOverride
|
|
1176
|
+
);
|
|
1177
|
+
let requestToolNameMap: Map<string, string> | null = null;
|
|
1178
|
+
|
|
1179
|
+
if (transformed instanceof Response) {
|
|
1180
|
+
return { response: transformed, url, headers, transformedBody: body };
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
let transformedBody: Record<string, unknown> = transformed;
|
|
1184
|
+
|
|
1185
|
+
if (transformedBody && typeof transformedBody === "object") {
|
|
1186
|
+
const cloaked = cloakAntigravityToolPayload(transformedBody);
|
|
1187
|
+
transformedBody = cloaked.body;
|
|
1188
|
+
requestToolNameMap = cloaked.toolNameMap;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
// Credits-first: inject GOOGLE_ONE_AI upfront so we never try the normal
|
|
1192
|
+
// quota path. If credits are exhausted / disabled shouldUseCreditsFirst()
|
|
1193
|
+
// returns false and we fall back to the legacy retry-on-429 flow.
|
|
1194
|
+
if (useCreditsFirst) {
|
|
1195
|
+
transformedBody = injectCreditsField(transformedBody);
|
|
1196
|
+
log?.debug?.("AG_CREDITS", "Credits-first enabled (ANTIGRAVITY_CREDITS=always)");
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
// Initialize retry counter for this URL
|
|
1200
|
+
if (!retryAttemptsByUrl[urlIndex]) {
|
|
1201
|
+
retryAttemptsByUrl[urlIndex] = 0;
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
try {
|
|
1205
|
+
const serializedRequest = serializeAntigravityRequest(
|
|
1206
|
+
this.provider,
|
|
1207
|
+
headers,
|
|
1208
|
+
transformedBody
|
|
1209
|
+
);
|
|
1210
|
+
let finalHeaders = serializedRequest.headers;
|
|
1211
|
+
const capture = (h: Record<string, string>, s: string) =>
|
|
1212
|
+
prl.captureCurrentProviderBody(url, h, s, log);
|
|
1213
|
+
const clientProfile = applyAntigravityClientProfileHeaders(
|
|
1214
|
+
finalHeaders,
|
|
1215
|
+
credentials,
|
|
1216
|
+
transformedBody
|
|
1217
|
+
);
|
|
1218
|
+
|
|
1219
|
+
log?.debug?.(
|
|
1220
|
+
"TELEMETRY",
|
|
1221
|
+
`[Antigravity] Execute - URL: ${url}, Model: ${model}, Target: ${getRequestTargetModel(transformedBody)}, RetryAttempt: ${retryAttemptsByUrl[urlIndex]}`
|
|
1222
|
+
);
|
|
1223
|
+
|
|
1224
|
+
// Dump outgoing headers (mask Authorization) and envelope shape for debugging
|
|
1225
|
+
if (log?.debug) {
|
|
1226
|
+
const safeHeaders = { ...finalHeaders };
|
|
1227
|
+
if (safeHeaders["Authorization"]) safeHeaders["Authorization"] = "Bearer ***";
|
|
1228
|
+
log.debug("AG_REQUEST_HEADERS", JSON.stringify(safeHeaders));
|
|
1229
|
+
|
|
1230
|
+
const envelope = transformedBody as Record<string, unknown>;
|
|
1231
|
+
const requestInner = envelope.request as Record<string, unknown> | undefined;
|
|
1232
|
+
log.debug(
|
|
1233
|
+
"AG_REQUEST_ENVELOPE",
|
|
1234
|
+
JSON.stringify({
|
|
1235
|
+
fieldOrder: Object.keys(envelope),
|
|
1236
|
+
project: envelope.project,
|
|
1237
|
+
requestId: envelope.requestId,
|
|
1238
|
+
model: envelope.model,
|
|
1239
|
+
userAgent: envelope.userAgent,
|
|
1240
|
+
requestType: envelope.requestType,
|
|
1241
|
+
enabledCreditTypes: envelope.enabledCreditTypes,
|
|
1242
|
+
clientProfile,
|
|
1243
|
+
sessionId: requestInner?.sessionId,
|
|
1244
|
+
generationConfig: requestInner?.generationConfig,
|
|
1245
|
+
})
|
|
1246
|
+
);
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
await capture(finalHeaders, serializedRequest.bodyString);
|
|
1250
|
+
let response = await fetchWithReadinessTimeout(url, {
|
|
1251
|
+
method: "POST",
|
|
1252
|
+
headers: finalHeaders,
|
|
1253
|
+
body: getChunkedOrFixedBody(serializedRequest.bodyString, stream),
|
|
1254
|
+
...(stream ? { duplex: "half" } : {}),
|
|
1255
|
+
signal,
|
|
1256
|
+
});
|
|
1257
|
+
|
|
1258
|
+
if (response.status === HTTP_STATUS.FORBIDDEN && finalHeaders["x-goog-user-project"]) {
|
|
1259
|
+
const retryHeaders = { ...finalHeaders };
|
|
1260
|
+
removeHeaderCaseInsensitive(retryHeaders, "x-goog-user-project");
|
|
1261
|
+
log?.debug?.("RETRY", "403 with x-goog-user-project, retrying once without it");
|
|
1262
|
+
await capture(retryHeaders, serializedRequest.bodyString);
|
|
1263
|
+
response = await fetchWithReadinessTimeout(url, {
|
|
1264
|
+
method: "POST",
|
|
1265
|
+
headers: retryHeaders,
|
|
1266
|
+
body: getChunkedOrFixedBody(serializedRequest.bodyString, stream),
|
|
1267
|
+
...(stream ? { duplex: "half" } : {}),
|
|
1268
|
+
signal,
|
|
1269
|
+
});
|
|
1270
|
+
finalHeaders = retryHeaders;
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
if (!response.ok) {
|
|
1274
|
+
log?.warn?.(
|
|
1275
|
+
"TELEMETRY",
|
|
1276
|
+
`[Antigravity] Error Response - URL: ${url}, Status: ${response.status}, Model: ${model}`
|
|
1277
|
+
);
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
// Parse retry time for 429/503 responses
|
|
1281
|
+
let retryMs: number | null = null;
|
|
1282
|
+
|
|
1283
|
+
if (
|
|
1284
|
+
response.status === HTTP_STATUS.RATE_LIMITED ||
|
|
1285
|
+
response.status === HTTP_STATUS.SERVICE_UNAVAILABLE
|
|
1286
|
+
) {
|
|
1287
|
+
// Try to get retry time from headers first
|
|
1288
|
+
retryMs = this.parseRetryHeaders(response.headers);
|
|
1289
|
+
|
|
1290
|
+
// If no retry time in headers, try to parse from error message body
|
|
1291
|
+
if (!retryMs) {
|
|
1292
|
+
try {
|
|
1293
|
+
const errorBody = await response.clone().text();
|
|
1294
|
+
const errorJson = JSON.parse(errorBody);
|
|
1295
|
+
let errorMessage = errorJson?.error?.message || errorJson?.message || "";
|
|
1296
|
+
if (errorJson?.error?.details && Array.isArray(errorJson.error.details)) {
|
|
1297
|
+
for (const detail of errorJson.error.details) {
|
|
1298
|
+
if (detail?.reason) {
|
|
1299
|
+
errorMessage += ` ${detail.reason}`;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
// 1. Try to parse explicit retry time from message
|
|
1305
|
+
const parsedRetryMs = this.parseRetryFromErrorMessage(errorMessage);
|
|
1306
|
+
|
|
1307
|
+
// 2. Classify 429 (pass header-parsed retry hint as fallback
|
|
1308
|
+
// signal — multi-hour Retry-After upgrades rate_limited to
|
|
1309
|
+
// quota_exhausted so the GOOGLE_ONE_AI credits retry fires).
|
|
1310
|
+
const effectiveRetryHintMs = retryMs ?? parsedRetryMs ?? null;
|
|
1311
|
+
const category = classify429(errorMessage);
|
|
1312
|
+
|
|
1313
|
+
// 3. Decide final retry time BEFORE the credits retry so that
|
|
1314
|
+
// full_quota_exhausted can skip the credits attempt entirely
|
|
1315
|
+
// (avoids ~41s hold on an already-exhausted account) and
|
|
1316
|
+
// persist the cooldown to DB for post-restart routing.
|
|
1317
|
+
const decision: Decision = decide429(category, parsedRetryMs);
|
|
1318
|
+
retryMs = decision.retryAfterMs;
|
|
1319
|
+
log?.debug?.(
|
|
1320
|
+
"AG_429",
|
|
1321
|
+
`Category: ${category}, Decision: ${decision.kind} — ${decision.reason}`
|
|
1322
|
+
);
|
|
1323
|
+
|
|
1324
|
+
if (decision.kind === "full_quota_exhausted" && retryMs) {
|
|
1325
|
+
markConnectionQuotaExhausted(accountId, retryMs);
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
const creditsAlreadyInjected =
|
|
1329
|
+
(transformedBody as { enabledCreditTypes?: unknown }).enabledCreditTypes != null;
|
|
1330
|
+
|
|
1331
|
+
if (category === "quota_exhausted" && creditsAlreadyInjected) {
|
|
1332
|
+
handleCreditsFailure(credentials?.accessToken || "");
|
|
1333
|
+
log?.warn?.("AG_CREDITS", "Credits-first request 429'd — credits likely exhausted");
|
|
1334
|
+
markCreditsExhausted(accountId);
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
if (
|
|
1338
|
+
category === "quota_exhausted" &&
|
|
1339
|
+
decision.kind !== "full_quota_exhausted" &&
|
|
1340
|
+
!creditsAlreadyInjected &&
|
|
1341
|
+
shouldRetryWithCredits(credentials?.accessToken || "", creditsMode !== "off")
|
|
1342
|
+
) {
|
|
1343
|
+
log?.info?.("AG_CREDITS", "Retrying with Google One AI credits");
|
|
1344
|
+
const creditsBody = injectCreditsField(transformedBody);
|
|
1345
|
+
const serializedCreditsRequest = serializeAntigravityRequest(
|
|
1346
|
+
this.provider,
|
|
1347
|
+
headers,
|
|
1348
|
+
creditsBody
|
|
1349
|
+
);
|
|
1350
|
+
const finalCreditsHeaders = serializedCreditsRequest.headers;
|
|
1351
|
+
try {
|
|
1352
|
+
await capture(finalCreditsHeaders, serializedCreditsRequest.bodyString);
|
|
1353
|
+
const creditsResp = await fetchWithReadinessTimeout(url, {
|
|
1354
|
+
method: "POST",
|
|
1355
|
+
headers: finalCreditsHeaders,
|
|
1356
|
+
body: getChunkedOrFixedBody(serializedCreditsRequest.bodyString, stream),
|
|
1357
|
+
...(stream ? { duplex: "half" } : {}),
|
|
1358
|
+
signal,
|
|
1359
|
+
});
|
|
1360
|
+
if (creditsResp.ok || creditsResp.status !== HTTP_STATUS.RATE_LIMITED) {
|
|
1361
|
+
log?.info?.("AG_CREDITS", `Credits retry succeeded: ${creditsResp.status}`);
|
|
1362
|
+
if (!stream) {
|
|
1363
|
+
const collected = await this.collectStreamToResponse(
|
|
1364
|
+
creditsResp,
|
|
1365
|
+
model,
|
|
1366
|
+
url,
|
|
1367
|
+
finalCreditsHeaders,
|
|
1368
|
+
creditsBody,
|
|
1369
|
+
log,
|
|
1370
|
+
signal
|
|
1371
|
+
);
|
|
1372
|
+
// Parse _remainingCredits from the synthetic response and cache
|
|
1373
|
+
try {
|
|
1374
|
+
const syntheticJson = await collected.response.clone().json();
|
|
1375
|
+
const rc = syntheticJson?._remainingCredits;
|
|
1376
|
+
if (Array.isArray(rc)) {
|
|
1377
|
+
const googleCredit = rc.find((c) => c.creditType === "GOOGLE_ONE_AI");
|
|
1378
|
+
if (googleCredit) {
|
|
1379
|
+
const balance = parseInt(googleCredit.creditAmount, 10);
|
|
1380
|
+
if (!isNaN(balance))
|
|
1381
|
+
updateAntigravityRemainingCredits(accountId, balance);
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
} catch {
|
|
1385
|
+
/**/
|
|
1386
|
+
}
|
|
1387
|
+
return {
|
|
1388
|
+
...collected,
|
|
1389
|
+
transformedBody: attachToolNameMap(creditsBody, requestToolNameMap),
|
|
1390
|
+
};
|
|
1391
|
+
}
|
|
1392
|
+
return {
|
|
1393
|
+
response: creditsResp,
|
|
1394
|
+
url,
|
|
1395
|
+
headers: finalCreditsHeaders,
|
|
1396
|
+
transformedBody: attachToolNameMap(creditsBody, requestToolNameMap),
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
// Credit retry also 429'd
|
|
1401
|
+
handleCreditsFailure(credentials?.accessToken || "");
|
|
1402
|
+
log?.warn?.("AG_CREDITS", "Credits retry also 429'd");
|
|
1403
|
+
|
|
1404
|
+
// Also mark in our legacy exhaustion map to avoid retrying other routes
|
|
1405
|
+
markCreditsExhausted(accountId);
|
|
1406
|
+
} catch (creditsErr) {
|
|
1407
|
+
handleCreditsFailure(credentials?.accessToken || "");
|
|
1408
|
+
log?.warn?.("AG_CREDITS", `Credits retry failed: ${creditsErr}`);
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
} catch (e) {
|
|
1412
|
+
// Ignore parse errors, will fall back to exponential backoff
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
// Bounded short-retry: a non-null retryAfterMs ≤ 60s covers nearly every
|
|
1417
|
+
// 429 (decide429 returns 2s/5s/60s defaults), so this branch MUST share the
|
|
1418
|
+
// per-URL attempt counter. Without the bound a persistent 429 loops forever
|
|
1419
|
+
// on the same endpoint/account (urlIndex-- cancels the loop's urlIndex++) and
|
|
1420
|
+
// never returns the 429 to the account-fallback layer in chat.ts.
|
|
1421
|
+
if (
|
|
1422
|
+
retryMs &&
|
|
1423
|
+
retryMs <= LONG_RETRY_THRESHOLD_MS &&
|
|
1424
|
+
retryAttemptsByUrl[urlIndex] < MAX_AUTO_RETRIES
|
|
1425
|
+
) {
|
|
1426
|
+
retryAttemptsByUrl[urlIndex]++;
|
|
1427
|
+
const effectiveRetryMs = Math.min(retryMs, MAX_RETRY_AFTER_MS);
|
|
1428
|
+
log?.debug?.(
|
|
1429
|
+
"RETRY",
|
|
1430
|
+
`${response.status} retry ${retryAttemptsByUrl[urlIndex]}/${MAX_AUTO_RETRIES} with Retry-After: ${Math.ceil(effectiveRetryMs / 1000)}s, waiting...`
|
|
1431
|
+
);
|
|
1432
|
+
await new Promise((resolve) => setTimeout(resolve, effectiveRetryMs));
|
|
1433
|
+
urlIndex--;
|
|
1434
|
+
continue;
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
// Auto retry for 429 (no Retry-After) or transient 5xx errors.
|
|
1438
|
+
// For 5xx we read the body to detect known transient patterns
|
|
1439
|
+
// ("Agent execution terminated due to error", "high traffic", "capacity").
|
|
1440
|
+
if ((!retryMs || retryMs === 0) && retryAttemptsByUrl[urlIndex] < MAX_AUTO_RETRIES) {
|
|
1441
|
+
let shouldAutoRetry = response.status === HTTP_STATUS.RATE_LIMITED;
|
|
1442
|
+
if (!shouldAutoRetry && ANTIGRAVITY_TRANSIENT_STATUSES.has(response.status)) {
|
|
1443
|
+
try {
|
|
1444
|
+
const errBody = await response.clone().text();
|
|
1445
|
+
let errJson: unknown = null;
|
|
1446
|
+
try {
|
|
1447
|
+
errJson = errBody ? JSON.parse(errBody) : null;
|
|
1448
|
+
} catch {
|
|
1449
|
+
// non-JSON body — fall through to pattern match against raw text
|
|
1450
|
+
}
|
|
1451
|
+
const errMsg = this.extractErrorMessage(errJson, errBody);
|
|
1452
|
+
shouldAutoRetry = this.isTransientAntigravityError(response.status, errMsg);
|
|
1453
|
+
} catch {
|
|
1454
|
+
// ignore body read errors
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
if (shouldAutoRetry) {
|
|
1458
|
+
retryAttemptsByUrl[urlIndex]++;
|
|
1459
|
+
// Exponential backoff: 2s, 4s, 8s… capped per-status
|
|
1460
|
+
const cap =
|
|
1461
|
+
response.status === HTTP_STATUS.RATE_LIMITED
|
|
1462
|
+
? MAX_RETRY_AFTER_MS
|
|
1463
|
+
: ANTIGRAVITY_TRANSIENT_RETRY_MAX_MS;
|
|
1464
|
+
const backoffMs = Math.min(1000 * 2 ** retryAttemptsByUrl[urlIndex], cap);
|
|
1465
|
+
log?.debug?.(
|
|
1466
|
+
"RETRY",
|
|
1467
|
+
`${response.status} transient auto retry ${retryAttemptsByUrl[urlIndex]}/${MAX_AUTO_RETRIES} after ${backoffMs / 1000}s`
|
|
1468
|
+
);
|
|
1469
|
+
await new Promise((resolve) => setTimeout(resolve, backoffMs));
|
|
1470
|
+
urlIndex--;
|
|
1471
|
+
continue;
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
log?.debug?.(
|
|
1476
|
+
"RETRY",
|
|
1477
|
+
`${response.status}, Retry-After ${retryMs ? `too long (${Math.ceil(retryMs / 1000)}s)` : "missing"}, trying fallback`
|
|
1478
|
+
);
|
|
1479
|
+
lastStatus = response.status;
|
|
1480
|
+
|
|
1481
|
+
if (urlIndex + 1 < fallbackCount) {
|
|
1482
|
+
continue;
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
if (this.shouldRetry(response.status, urlIndex)) {
|
|
1487
|
+
log?.debug?.("RETRY", `${response.status} on ${url}, trying fallback ${urlIndex + 1}`);
|
|
1488
|
+
lastStatus = response.status;
|
|
1489
|
+
continue;
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
// If we have a 429 with long retry time, embed it in response body
|
|
1493
|
+
if (
|
|
1494
|
+
response.status === HTTP_STATUS.RATE_LIMITED &&
|
|
1495
|
+
retryMs &&
|
|
1496
|
+
retryMs > LONG_RETRY_THRESHOLD_MS
|
|
1497
|
+
) {
|
|
1498
|
+
try {
|
|
1499
|
+
const respBody = await response.clone().text();
|
|
1500
|
+
let obj;
|
|
1501
|
+
try {
|
|
1502
|
+
obj = JSON.parse(respBody);
|
|
1503
|
+
} catch {
|
|
1504
|
+
obj = {};
|
|
1505
|
+
}
|
|
1506
|
+
obj.retryAfterMs = retryMs;
|
|
1507
|
+
const modifiedBody = JSON.stringify(obj);
|
|
1508
|
+
const modifiedResponse = new Response(modifiedBody, {
|
|
1509
|
+
status: response.status,
|
|
1510
|
+
headers: response.headers,
|
|
1511
|
+
});
|
|
1512
|
+
return {
|
|
1513
|
+
response: modifiedResponse,
|
|
1514
|
+
url,
|
|
1515
|
+
headers: finalHeaders,
|
|
1516
|
+
transformedBody: attachToolNameMap(transformedBody, requestToolNameMap),
|
|
1517
|
+
};
|
|
1518
|
+
} catch (err) {
|
|
1519
|
+
log?.warn?.("RETRY", `Failed to embed retryAfterMs: ${err}`);
|
|
1520
|
+
// Fall back to original response
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
// For non-streaming clients, collect the SSE stream and return a synthetic
|
|
1525
|
+
// non-streaming Response so chatCore doesn't need to handle SSE conversion.
|
|
1526
|
+
if (!stream) {
|
|
1527
|
+
// #3229: surface a real upstream error instead of masking a 4xx/5xx as an
|
|
1528
|
+
// empty `chat.completion` envelope (collectStreamToResponse synthesizes a
|
|
1529
|
+
// success-shaped body when the upstream returned no SSE data).
|
|
1530
|
+
if (!response.ok) {
|
|
1531
|
+
const rawBody = await response
|
|
1532
|
+
.clone()
|
|
1533
|
+
.text()
|
|
1534
|
+
.catch(() => "");
|
|
1535
|
+
const errorBody = buildAntigravityUpstreamError(
|
|
1536
|
+
response.status,
|
|
1537
|
+
response.statusText,
|
|
1538
|
+
rawBody
|
|
1539
|
+
);
|
|
1540
|
+
return {
|
|
1541
|
+
response: new Response(JSON.stringify(errorBody), {
|
|
1542
|
+
status: response.status,
|
|
1543
|
+
headers: { "Content-Type": "application/json" },
|
|
1544
|
+
}),
|
|
1545
|
+
url,
|
|
1546
|
+
headers: finalHeaders,
|
|
1547
|
+
transformedBody: attachToolNameMap(transformedBody, requestToolNameMap),
|
|
1548
|
+
};
|
|
1549
|
+
}
|
|
1550
|
+
const collected = await this.collectStreamToResponse(
|
|
1551
|
+
response,
|
|
1552
|
+
model,
|
|
1553
|
+
url,
|
|
1554
|
+
finalHeaders,
|
|
1555
|
+
transformedBody,
|
|
1556
|
+
log,
|
|
1557
|
+
signal
|
|
1558
|
+
);
|
|
1559
|
+
// When credits were injected (credits-first or credits-retry), the
|
|
1560
|
+
// synthetic body contains _remainingCredits — mirror it into the
|
|
1561
|
+
// balance cache so the dashboard stays fresh.
|
|
1562
|
+
try {
|
|
1563
|
+
const syntheticJson = await collected.response.clone().json();
|
|
1564
|
+
const rc = syntheticJson?._remainingCredits;
|
|
1565
|
+
if (Array.isArray(rc)) {
|
|
1566
|
+
const googleCredit = rc.find(
|
|
1567
|
+
(c: { creditType?: string }) => c?.creditType === "GOOGLE_ONE_AI"
|
|
1568
|
+
);
|
|
1569
|
+
if (googleCredit) {
|
|
1570
|
+
const balance = parseInt(googleCredit.creditAmount, 10);
|
|
1571
|
+
if (!isNaN(balance)) updateAntigravityRemainingCredits(accountId, balance);
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
} catch {
|
|
1575
|
+
/* balance cache is best-effort */
|
|
1576
|
+
}
|
|
1577
|
+
return {
|
|
1578
|
+
...collected,
|
|
1579
|
+
transformedBody: attachToolNameMap(transformedBody, requestToolNameMap),
|
|
1580
|
+
};
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
// Streaming path: wrap the response body in a pass-through TransformStream
|
|
1584
|
+
// that extracts remainingCredits from the final SSE chunk(s) without
|
|
1585
|
+
// consuming the stream. The client receives the unmodified SSE data.
|
|
1586
|
+
if (response.body) {
|
|
1587
|
+
// If the downstream client aborts, cancel the upstream fetch body immediately
|
|
1588
|
+
// to release the socket back to the Undici agent pool and prevent memory leaks.
|
|
1589
|
+
if (signal) {
|
|
1590
|
+
const abortHandler = () => {
|
|
1591
|
+
try {
|
|
1592
|
+
response.body?.cancel().catch(() => {});
|
|
1593
|
+
} catch (_) {}
|
|
1594
|
+
};
|
|
1595
|
+
if (signal.aborted) {
|
|
1596
|
+
abortHandler();
|
|
1597
|
+
} else {
|
|
1598
|
+
signal.addEventListener("abort", abortHandler, { once: true });
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
let sseBuffer = "";
|
|
1603
|
+
const decoder = new TextDecoder(); // Singleton for correct streaming decode
|
|
1604
|
+
const MAX_BUFFER_SIZE = 16 * 1024; // Limit to prevent OOM on large streams
|
|
1605
|
+
|
|
1606
|
+
const passThrough = new TransformStream(
|
|
1607
|
+
{
|
|
1608
|
+
transform(chunk, controller) {
|
|
1609
|
+
controller.enqueue(chunk);
|
|
1610
|
+
// Accumulate text to scan for remainingCredits
|
|
1611
|
+
try {
|
|
1612
|
+
const text = decoder.decode(chunk, { stream: true });
|
|
1613
|
+
sseBuffer += text;
|
|
1614
|
+
// Limit buffer size to prevent unbounded growth
|
|
1615
|
+
// Truncate only after a complete newline to avoid splitting SSE lines mid-payload
|
|
1616
|
+
if (sseBuffer.length > MAX_BUFFER_SIZE) {
|
|
1617
|
+
const lastNewline = sseBuffer.lastIndexOf(
|
|
1618
|
+
"\n",
|
|
1619
|
+
sseBuffer.length - MAX_BUFFER_SIZE
|
|
1620
|
+
);
|
|
1621
|
+
if (lastNewline !== -1) {
|
|
1622
|
+
sseBuffer = sseBuffer.slice(lastNewline + 1);
|
|
1623
|
+
} else {
|
|
1624
|
+
// No newline found in discard region — buffer contains an incomplete SSE line.
|
|
1625
|
+
// Discard it entirely to avoid returning malformed data; the remainingCredits
|
|
1626
|
+
// parser won't find valid data in a truncated line anyway.
|
|
1627
|
+
sseBuffer = "";
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
} catch {
|
|
1631
|
+
/* decoding best-effort */
|
|
1632
|
+
}
|
|
1633
|
+
},
|
|
1634
|
+
flush() {
|
|
1635
|
+
// Final decode for any remaining bytes
|
|
1636
|
+
try {
|
|
1637
|
+
const text = decoder.decode(); // Flush pending bytes
|
|
1638
|
+
sseBuffer += text;
|
|
1639
|
+
} catch {
|
|
1640
|
+
/* decoding best-effort */
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
// Parse the accumulated SSE data for remainingCredits
|
|
1644
|
+
try {
|
|
1645
|
+
const lines = sseBuffer.split("\n");
|
|
1646
|
+
for (const line of lines) {
|
|
1647
|
+
const trimmed = line.trim();
|
|
1648
|
+
if (!trimmed.startsWith("data:")) continue;
|
|
1649
|
+
const payload = trimmed.slice(5).trim();
|
|
1650
|
+
if (!payload || payload === "[DONE]") continue;
|
|
1651
|
+
try {
|
|
1652
|
+
const parsed = JSON.parse(payload);
|
|
1653
|
+
if (Array.isArray(parsed?.remainingCredits)) {
|
|
1654
|
+
const googleCredit = parsed.remainingCredits.find((c: unknown) => {
|
|
1655
|
+
const credit = asRecord(c);
|
|
1656
|
+
return credit?.creditType === "GOOGLE_ONE_AI";
|
|
1657
|
+
}) as AntigravityCreditEntry | undefined;
|
|
1658
|
+
if (googleCredit) {
|
|
1659
|
+
const balance = parseInt(String(googleCredit.creditAmount ?? ""), 10);
|
|
1660
|
+
if (!isNaN(balance)) {
|
|
1661
|
+
updateAntigravityRemainingCredits(accountId, balance);
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
} catch {
|
|
1666
|
+
/* skip malformed lines */
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
} catch {
|
|
1670
|
+
/* credits extraction is best-effort */
|
|
1671
|
+
}
|
|
1672
|
+
sseBuffer = "";
|
|
1673
|
+
},
|
|
1674
|
+
},
|
|
1675
|
+
{ highWaterMark: 16384 },
|
|
1676
|
+
{ highWaterMark: 16384 }
|
|
1677
|
+
);
|
|
1678
|
+
const tappedBody = response.body.pipeThrough(passThrough);
|
|
1679
|
+
const tappedResponse = new Response(tappedBody, {
|
|
1680
|
+
status: response.status,
|
|
1681
|
+
statusText: response.statusText,
|
|
1682
|
+
headers: response.headers,
|
|
1683
|
+
});
|
|
1684
|
+
return {
|
|
1685
|
+
response: tappedResponse,
|
|
1686
|
+
url,
|
|
1687
|
+
headers: finalHeaders,
|
|
1688
|
+
transformedBody: attachToolNameMap(transformedBody, requestToolNameMap),
|
|
1689
|
+
};
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
return {
|
|
1693
|
+
response,
|
|
1694
|
+
url,
|
|
1695
|
+
headers: finalHeaders,
|
|
1696
|
+
transformedBody: attachToolNameMap(transformedBody, requestToolNameMap),
|
|
1697
|
+
};
|
|
1698
|
+
} catch (error) {
|
|
1699
|
+
lastError = error;
|
|
1700
|
+
log?.error?.(
|
|
1701
|
+
"TELEMETRY",
|
|
1702
|
+
`[Antigravity] Network/Fetch Error - URL: ${url}, Model: ${model}, Error: ${error instanceof Error ? error.message : String(error)}`
|
|
1703
|
+
);
|
|
1704
|
+
if (urlIndex + 1 < fallbackCount) {
|
|
1705
|
+
log?.debug?.("RETRY", `Error on ${url}, trying fallback ${urlIndex + 1}`);
|
|
1706
|
+
continue;
|
|
1707
|
+
}
|
|
1708
|
+
throw error;
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
throw lastError || new Error(`All ${fallbackCount} URLs failed with status ${lastStatus}`);
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1716
|
+
export default AntigravityExecutor;
|