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,2880 @@
|
|
|
1
|
+
import { randomUUID } from "crypto";
|
|
2
|
+
/**
|
|
3
|
+
* Image Generation Handler
|
|
4
|
+
*
|
|
5
|
+
* Handles POST /v1/images/generations requests.
|
|
6
|
+
* Proxies to upstream image generation providers using OpenAI-compatible format.
|
|
7
|
+
*
|
|
8
|
+
* Request format (OpenAI-compatible):
|
|
9
|
+
* {
|
|
10
|
+
* "model": "openai/gpt-image-2",
|
|
11
|
+
* "prompt": "a beautiful sunset over mountains",
|
|
12
|
+
* "n": 1,
|
|
13
|
+
* "size": "1024x1024",
|
|
14
|
+
* "quality": "standard", // optional: "standard" | "hd"
|
|
15
|
+
* "response_format": "url" // optional: "url" | "b64_json"
|
|
16
|
+
* }
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { getImageProvider, parseImageModel } from "../config/imageRegistry.ts";
|
|
20
|
+
import { HTTP_STATUS } from "../config/constants.ts";
|
|
21
|
+
import { applyAntigravityClientProfileHeaders } from "../services/antigravityClientProfile.ts";
|
|
22
|
+
import { getAntigravityEnvelopeUserAgent } from "../services/antigravityIdentity.ts";
|
|
23
|
+
import { kieExecutor } from "../executors/kie.ts";
|
|
24
|
+
import { mapImageSize } from "../translator/image/sizeMapper.ts";
|
|
25
|
+
import { getCodexClientVersion, getCodexUserAgent } from "../config/codexClient.ts";
|
|
26
|
+
import { ChatGptWebExecutor } from "../executors/chatgpt-web.ts";
|
|
27
|
+
import { getChatGptImage, findChatGptImageBySha256 } from "../services/chatgptImageCache.ts";
|
|
28
|
+
import { createHash } from "node:crypto";
|
|
29
|
+
import { saveCallLog } from "@/lib/usageDb";
|
|
30
|
+
import { sleep } from "../utils/sleep.ts";
|
|
31
|
+
import {
|
|
32
|
+
getKieErrorMessage,
|
|
33
|
+
getKieErrorStatus,
|
|
34
|
+
isJsonObject,
|
|
35
|
+
parseKieResultJson,
|
|
36
|
+
} from "../utils/kieTask.ts";
|
|
37
|
+
import {
|
|
38
|
+
submitComfyWorkflow,
|
|
39
|
+
pollComfyResult,
|
|
40
|
+
fetchComfyOutput,
|
|
41
|
+
extractComfyOutputFiles,
|
|
42
|
+
} from "../utils/comfyuiClient.ts";
|
|
43
|
+
import { fetchRemoteImage } from "@/shared/network/remoteImageFetch";
|
|
44
|
+
import { FetchTimeoutError, fetchWithTimeout, getConfiguredTimeout } from "@/shared/utils/fetchTimeout";
|
|
45
|
+
import { sanitizeErrorMessage, sanitizeUpstreamDetails } from "../utils/error.ts";
|
|
46
|
+
|
|
47
|
+
// --- Per-provider handlers (extracted to co-located files in PR-#4582-batch) ---
|
|
48
|
+
// Imported locally so internal callers (handleImageGeneration / handleImageEdit)
|
|
49
|
+
// resolve to a real binding. extractMarkdownImageUrls + CHATGPT_WEB_IMAGE_ID_RE
|
|
50
|
+
// are still used by handleImageEdit below, so they are imported (not re-defined).
|
|
51
|
+
import { handleSDWebUIImageGeneration } from "./imageGeneration/providers/sdWebUI.ts";
|
|
52
|
+
import { handleHyperbolicImageGeneration } from "./imageGeneration/providers/hyperbolic.ts";
|
|
53
|
+
import { handleHuggingFaceImageGeneration } from "./imageGeneration/providers/huggingface.ts";
|
|
54
|
+
import { handleComfyUIImageGeneration } from "./imageGeneration/providers/comfyUI.ts";
|
|
55
|
+
import { handleImagen3ImageGeneration } from "./imageGeneration/providers/imagen3.ts";
|
|
56
|
+
import { handleIdeogramImageGeneration } from "./imageGeneration/providers/ideogram.ts";
|
|
57
|
+
import { handleHaiperImageGeneration } from "./imageGeneration/providers/haiper.ts";
|
|
58
|
+
import { handleLeonardoImageGeneration } from "./imageGeneration/providers/leonardo.ts";
|
|
59
|
+
import {
|
|
60
|
+
handleChatGptWebImageGeneration,
|
|
61
|
+
extractMarkdownImageUrls,
|
|
62
|
+
CHATGPT_WEB_IMAGE_ID_RE,
|
|
63
|
+
} from "./imageGeneration/providers/chatgptWeb.ts";
|
|
64
|
+
import { handleNvidiaNimImageGeneration } from "./imageGeneration/providers/nvidiaNim.ts";
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
interface KieImageOptions {
|
|
68
|
+
model: string;
|
|
69
|
+
provider: string;
|
|
70
|
+
providerConfig: {
|
|
71
|
+
baseUrl: string;
|
|
72
|
+
statusUrl?: string;
|
|
73
|
+
};
|
|
74
|
+
body: Record<string, unknown> & {
|
|
75
|
+
prompt?: unknown;
|
|
76
|
+
size?: unknown;
|
|
77
|
+
n?: unknown;
|
|
78
|
+
timeout_ms?: unknown;
|
|
79
|
+
poll_interval_ms?: unknown;
|
|
80
|
+
};
|
|
81
|
+
credentials?: {
|
|
82
|
+
apiKey?: string;
|
|
83
|
+
accessToken?: string;
|
|
84
|
+
} | null;
|
|
85
|
+
log?: {
|
|
86
|
+
info: (scope: string, message: string) => void;
|
|
87
|
+
error: (scope: string, message: string) => void;
|
|
88
|
+
} | null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const OPENAI_IMAGE_TO_IMAGE_MODELS = new Set([
|
|
92
|
+
"black-forest-labs/FLUX.2-max",
|
|
93
|
+
"black-forest-labs/FLUX.2-pro",
|
|
94
|
+
"black-forest-labs/FLUX.2-flex",
|
|
95
|
+
"black-forest-labs/FLUX.2-dev",
|
|
96
|
+
"openai/gpt-image-1.5",
|
|
97
|
+
"Wan-AI/Wan2.6-image",
|
|
98
|
+
"Qwen/Qwen-Image-2.0-Pro",
|
|
99
|
+
"Qwen/Qwen-Image-2.0",
|
|
100
|
+
"google/flash-image-3.1",
|
|
101
|
+
"google/gemini-3-pro-image",
|
|
102
|
+
"flux-kontext-max",
|
|
103
|
+
"flux-kontext",
|
|
104
|
+
"flux-kontext-pro",
|
|
105
|
+
"qwen-image",
|
|
106
|
+
]);
|
|
107
|
+
|
|
108
|
+
const IMAGE_ASPECT_RATIO_PATTERN = /^\d+:\d+$/;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Resolve the upstream images endpoint for a custom (OpenAI-compatible) image
|
|
112
|
+
* provider node (#3205).
|
|
113
|
+
*
|
|
114
|
+
* Custom provider nodes store their base URL the same way the chat path does:
|
|
115
|
+
* in `credentials.providerSpecificData.baseUrl` (e.g. `https://example.com/v1`),
|
|
116
|
+
* NOT as a top-level `credentials.baseUrl`. Older callers may still pass a
|
|
117
|
+
* top-level `baseUrl`, so we honor that as a secondary source. When neither is
|
|
118
|
+
* present we fall back to `fallback` (the built-in Gemini OpenAI endpoint).
|
|
119
|
+
*
|
|
120
|
+
* Resolution order: providerSpecificData.baseUrl → credentials.baseUrl → fallback.
|
|
121
|
+
*
|
|
122
|
+
* A node base URL like `https://example.com/v1` is normalized and the
|
|
123
|
+
* OpenAI-compatible `/images/generations` path appended (mirroring
|
|
124
|
+
* `buildOpenAICompatibleUrl` in services/provider.ts). A node URL that already
|
|
125
|
+
* ends in `/images/generations` is returned as-is (no double-append). The
|
|
126
|
+
* `fallback` value is assumed to already be a complete URL and is returned
|
|
127
|
+
* verbatim.
|
|
128
|
+
*/
|
|
129
|
+
export function resolveImageBaseUrl(
|
|
130
|
+
credentials:
|
|
131
|
+
| { baseUrl?: unknown; providerSpecificData?: { baseUrl?: unknown } | null }
|
|
132
|
+
| null
|
|
133
|
+
| undefined,
|
|
134
|
+
fallback: string,
|
|
135
|
+
endpoint: "generations" | "edits" = "generations"
|
|
136
|
+
): string {
|
|
137
|
+
const psd = credentials?.providerSpecificData;
|
|
138
|
+
const psdBaseUrl =
|
|
139
|
+
psd && typeof psd === "object" && typeof psd.baseUrl === "string" && psd.baseUrl.trim()
|
|
140
|
+
? psd.baseUrl.trim()
|
|
141
|
+
: null;
|
|
142
|
+
const topLevelBaseUrl =
|
|
143
|
+
typeof credentials?.baseUrl === "string" && credentials.baseUrl.trim()
|
|
144
|
+
? credentials.baseUrl.trim()
|
|
145
|
+
: null;
|
|
146
|
+
const nodeBaseUrl = psdBaseUrl || topLevelBaseUrl;
|
|
147
|
+
|
|
148
|
+
if (!nodeBaseUrl) return fallback;
|
|
149
|
+
|
|
150
|
+
// A single configured node serves both image routes: honor a base URL that already
|
|
151
|
+
// points at the requested OpenAI image path, and rewrite one that points at the other
|
|
152
|
+
// image endpoint (e.g. `.../images/generations` requested for edits) (#3214/#3215).
|
|
153
|
+
const suffix = `/images/${endpoint}`;
|
|
154
|
+
// Trim trailing slashes without a backtracking-prone regex (`/\/+$/` is a
|
|
155
|
+
// polynomial-ReDoS pattern on long runs of "/" — CodeQL js/polynomial-redos).
|
|
156
|
+
let normalized = nodeBaseUrl;
|
|
157
|
+
while (normalized.endsWith("/")) normalized = normalized.slice(0, -1);
|
|
158
|
+
if (normalized.endsWith(suffix)) return normalized;
|
|
159
|
+
const stripped = normalized.replace(/\/images\/(?:generations|edits)$/, "");
|
|
160
|
+
return `${stripped}${suffix}`;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function normalizeImageAspectRatio(value: unknown, fallbackSize: unknown): string {
|
|
164
|
+
if (typeof value === "string") {
|
|
165
|
+
const trimmedValue = value.trim();
|
|
166
|
+
if (IMAGE_ASPECT_RATIO_PATTERN.test(trimmedValue)) return trimmedValue;
|
|
167
|
+
}
|
|
168
|
+
return mapImageSize(typeof fallbackSize === "string" ? fallbackSize : null);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function parseJsonOrNull(value: string): unknown | null {
|
|
172
|
+
try {
|
|
173
|
+
return JSON.parse(value);
|
|
174
|
+
} catch {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function sanitizeImageProviderError(errorText: string): unknown {
|
|
180
|
+
const parsed = parseJsonOrNull(errorText);
|
|
181
|
+
if (parsed !== null) {
|
|
182
|
+
return sanitizeUpstreamDetails(parsed) || sanitizeErrorMessage(errorText);
|
|
183
|
+
}
|
|
184
|
+
return sanitizeErrorMessage(errorText);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const BFL_MODEL_ENDPOINTS = {
|
|
188
|
+
"flux-2-max": "/v1/flux-2-max",
|
|
189
|
+
"flux-2-pro": "/v1/flux-2-pro",
|
|
190
|
+
"flux-2-flex": "/v1/flux-2-flex",
|
|
191
|
+
"flux-2-klein-9b": "/v1/flux-2-klein-9b",
|
|
192
|
+
"flux-2-klein-4b": "/v1/flux-2-klein-4b",
|
|
193
|
+
"flux-kontext-pro": "/v1/flux-kontext-pro",
|
|
194
|
+
"flux-kontext-max": "/v1/flux-kontext-max",
|
|
195
|
+
"flux-pro-1.1": "/v1/flux-pro-1.1",
|
|
196
|
+
"flux-pro-1.1-ultra": "/v1/flux-pro-1.1-ultra",
|
|
197
|
+
"flux-dev": "/v1/flux-dev",
|
|
198
|
+
"flux-pro": "/v1/flux-pro",
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const BFL_EDIT_MODELS = new Set([
|
|
202
|
+
"flux-2-max",
|
|
203
|
+
"flux-2-pro",
|
|
204
|
+
"flux-2-flex",
|
|
205
|
+
"flux-kontext-pro",
|
|
206
|
+
"flux-kontext-max",
|
|
207
|
+
]);
|
|
208
|
+
|
|
209
|
+
const BFL_FAILURE_STATUSES = new Set(["Error", "Failed", "Content Moderated", "Request Moderated"]);
|
|
210
|
+
|
|
211
|
+
function formatImageProviderError(err) {
|
|
212
|
+
const sanitized = sanitizeErrorMessage(err);
|
|
213
|
+
const message = (sanitized || "").replace(/^Error:\s*/i, "").trim();
|
|
214
|
+
return message ? `Image provider error: ${message}` : "Image provider error";
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const STABILITY_GENERATION_ENDPOINTS = {
|
|
218
|
+
"sd3.5-large": "/v2beta/stable-image/generate/sd3",
|
|
219
|
+
"sd3.5-large-turbo": "/v2beta/stable-image/generate/sd3",
|
|
220
|
+
"sd3.5-medium": "/v2beta/stable-image/generate/sd3",
|
|
221
|
+
"sd3.5-flash": "/v2beta/stable-image/generate/sd3",
|
|
222
|
+
"stable-image-ultra": "/v2beta/stable-image/generate/ultra",
|
|
223
|
+
"stable-image-core": "/v2beta/stable-image/generate/core",
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const STABILITY_EDIT_ENDPOINTS = {
|
|
227
|
+
inpaint: "/v2beta/stable-image/edit/inpaint",
|
|
228
|
+
outpaint: "/v2beta/stable-image/edit/outpaint",
|
|
229
|
+
erase: "/v2beta/stable-image/edit/erase",
|
|
230
|
+
"search-and-replace": "/v2beta/stable-image/edit/search-and-replace",
|
|
231
|
+
"search-and-recolor": "/v2beta/stable-image/edit/search-and-recolor",
|
|
232
|
+
"remove-background": "/v2beta/stable-image/edit/remove-background",
|
|
233
|
+
"replace-background-and-relight": "/v2beta/stable-image/edit/replace-background-and-relight",
|
|
234
|
+
fast: "/v2beta/stable-image/upscale/fast",
|
|
235
|
+
conservative: "/v2beta/stable-image/upscale/conservative",
|
|
236
|
+
creative: "/v2beta/stable-image/upscale/creative",
|
|
237
|
+
sketch: "/v2beta/stable-image/control/sketch",
|
|
238
|
+
structure: "/v2beta/stable-image/control/structure",
|
|
239
|
+
style: "/v2beta/stable-image/control/style",
|
|
240
|
+
"style-transfer": "/v2beta/stable-image/control/style-transfer",
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const STABILITY_CONTROL_MODELS = new Set(["sketch", "structure", "style", "style-transfer"]);
|
|
244
|
+
|
|
245
|
+
function appendOptionalFormValue(formData, key, value) {
|
|
246
|
+
if (value === undefined || value === null || value === "") return;
|
|
247
|
+
formData.append(key, String(value));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function appendImageFormValue(formData, key, source, filename) {
|
|
251
|
+
formData.append(
|
|
252
|
+
key,
|
|
253
|
+
new Blob([source.buffer], {
|
|
254
|
+
type: source.contentType || "application/octet-stream",
|
|
255
|
+
}),
|
|
256
|
+
filename
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const FAL_PRESET_SIZES = {
|
|
261
|
+
"1024x1024": "square_hd",
|
|
262
|
+
"512x512": "square",
|
|
263
|
+
"1792x1024": "landscape_16_9",
|
|
264
|
+
"1024x1792": "portrait_16_9",
|
|
265
|
+
"1024x768": "landscape_4_3",
|
|
266
|
+
"768x1024": "portrait_4_3",
|
|
267
|
+
"1536x1024": "landscape_3_2",
|
|
268
|
+
"1024x1536": "portrait_3_2",
|
|
269
|
+
"576x1024": "portrait_16_9",
|
|
270
|
+
"1024x576": "landscape_16_9",
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Handle image generation request
|
|
275
|
+
* @param {object} options
|
|
276
|
+
* @param {object} options.body - Request body
|
|
277
|
+
* @param {object} options.credentials - Provider credentials { apiKey, accessToken }
|
|
278
|
+
* @param {object} options.log - Logger
|
|
279
|
+
* @param {string} [options.resolvedProvider] - Pre-resolved provider ID (from route layer custom model resolution)
|
|
280
|
+
*/
|
|
281
|
+
export async function handleImageGeneration({
|
|
282
|
+
body,
|
|
283
|
+
credentials,
|
|
284
|
+
log,
|
|
285
|
+
resolvedProvider = null,
|
|
286
|
+
signal = null,
|
|
287
|
+
clientHeaders = null,
|
|
288
|
+
}) {
|
|
289
|
+
let provider, model;
|
|
290
|
+
|
|
291
|
+
if (resolvedProvider) {
|
|
292
|
+
// Provider was already resolved by the route layer (custom model from DB)
|
|
293
|
+
// Extract model name from the full "provider/model" string
|
|
294
|
+
provider = resolvedProvider;
|
|
295
|
+
const modelStr = body.model || "";
|
|
296
|
+
model = modelStr.startsWith(provider + "/") ? modelStr.slice(provider.length + 1) : modelStr;
|
|
297
|
+
} else {
|
|
298
|
+
// Standard path: resolve from built-in image registry
|
|
299
|
+
const parsed = parseImageModel(body.model);
|
|
300
|
+
provider = parsed.provider;
|
|
301
|
+
model = parsed.model;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (!provider) {
|
|
305
|
+
return {
|
|
306
|
+
success: false,
|
|
307
|
+
status: 400,
|
|
308
|
+
error: `Invalid image model: ${body.model}. Use format: provider/model`,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const providerConfig = getImageProvider(provider);
|
|
313
|
+
|
|
314
|
+
// For custom models without a built-in provider config, use OpenAI-compatible handler
|
|
315
|
+
// with a synthetic config based on the provider's credentials
|
|
316
|
+
if (!providerConfig) {
|
|
317
|
+
if (!resolvedProvider) {
|
|
318
|
+
return {
|
|
319
|
+
success: false,
|
|
320
|
+
status: 400,
|
|
321
|
+
error: `Unknown image provider: ${provider}`,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Custom model: use OpenAI-compatible format with provider's base URL
|
|
326
|
+
// The credentials were already resolved by the route layer
|
|
327
|
+
if (log) {
|
|
328
|
+
log.info("IMAGE", `Custom model ${provider}/${model} — using OpenAI-compatible handler`);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const syntheticConfig = {
|
|
332
|
+
id: provider,
|
|
333
|
+
// #3205: custom OpenAI-compatible nodes store their base URL in
|
|
334
|
+
// credentials.providerSpecificData.baseUrl (same as the chat path —
|
|
335
|
+
// see executors/default.ts:buildUrl / services/provider.ts:buildProviderUrl).
|
|
336
|
+
// Previously only the (always-absent) top-level credentials.baseUrl was
|
|
337
|
+
// read, so every custom image node fell back to the Gemini endpoint and
|
|
338
|
+
// returned "Please pass a valid API key".
|
|
339
|
+
baseUrl: resolveImageBaseUrl(
|
|
340
|
+
credentials,
|
|
341
|
+
`https://generativelanguage.googleapis.com/v1beta/openai/images/generations`
|
|
342
|
+
),
|
|
343
|
+
authType: "apikey",
|
|
344
|
+
authHeader: "bearer",
|
|
345
|
+
format: "openai",
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
return handleOpenAIImageGeneration({
|
|
349
|
+
model,
|
|
350
|
+
provider,
|
|
351
|
+
providerConfig: syntheticConfig,
|
|
352
|
+
body,
|
|
353
|
+
credentials,
|
|
354
|
+
log,
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (providerConfig.format === "gemini-image") {
|
|
359
|
+
return handleGeminiImageGeneration({ model, providerConfig, body, credentials, log });
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if (providerConfig.format === "imagen3") {
|
|
363
|
+
return handleImagen3ImageGeneration({
|
|
364
|
+
model,
|
|
365
|
+
provider,
|
|
366
|
+
providerConfig,
|
|
367
|
+
body,
|
|
368
|
+
credentials,
|
|
369
|
+
log,
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if (providerConfig.format === "hyperbolic") {
|
|
374
|
+
return handleHyperbolicImageGeneration({
|
|
375
|
+
model,
|
|
376
|
+
provider,
|
|
377
|
+
providerConfig,
|
|
378
|
+
body,
|
|
379
|
+
credentials,
|
|
380
|
+
log,
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (providerConfig.format === "huggingface-image") {
|
|
385
|
+
return handleHuggingFaceImageGeneration({
|
|
386
|
+
model,
|
|
387
|
+
provider,
|
|
388
|
+
providerConfig,
|
|
389
|
+
body,
|
|
390
|
+
credentials,
|
|
391
|
+
log,
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (providerConfig.format === "fal-ai") {
|
|
396
|
+
return handleFalAIImageGeneration({
|
|
397
|
+
model,
|
|
398
|
+
provider,
|
|
399
|
+
providerConfig,
|
|
400
|
+
body,
|
|
401
|
+
credentials,
|
|
402
|
+
log,
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
if (providerConfig.format === "stability-ai") {
|
|
407
|
+
return handleStabilityAIImageGeneration({
|
|
408
|
+
model,
|
|
409
|
+
provider,
|
|
410
|
+
providerConfig,
|
|
411
|
+
body,
|
|
412
|
+
credentials,
|
|
413
|
+
log,
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (providerConfig.format === "black-forest-labs") {
|
|
418
|
+
return handleBlackForestLabsImageGeneration({
|
|
419
|
+
model,
|
|
420
|
+
provider,
|
|
421
|
+
providerConfig,
|
|
422
|
+
body,
|
|
423
|
+
credentials,
|
|
424
|
+
log,
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
if (providerConfig.format === "recraft") {
|
|
429
|
+
return handleRecraftImageGeneration({
|
|
430
|
+
model,
|
|
431
|
+
provider,
|
|
432
|
+
providerConfig,
|
|
433
|
+
body,
|
|
434
|
+
credentials,
|
|
435
|
+
log,
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if (providerConfig.format === "topaz") {
|
|
440
|
+
return handleTopazImageGeneration({
|
|
441
|
+
model,
|
|
442
|
+
provider,
|
|
443
|
+
providerConfig,
|
|
444
|
+
body,
|
|
445
|
+
credentials,
|
|
446
|
+
log,
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (providerConfig.format === "chatgpt-web") {
|
|
451
|
+
return handleChatGptWebImageGeneration({
|
|
452
|
+
model,
|
|
453
|
+
provider,
|
|
454
|
+
body,
|
|
455
|
+
credentials,
|
|
456
|
+
log,
|
|
457
|
+
signal,
|
|
458
|
+
clientHeaders,
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
if (providerConfig.format === "nanobanana") {
|
|
463
|
+
return handleNanoBananaImageGeneration({
|
|
464
|
+
model,
|
|
465
|
+
provider,
|
|
466
|
+
providerConfig,
|
|
467
|
+
body,
|
|
468
|
+
credentials,
|
|
469
|
+
log,
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
if (providerConfig.format === "kie-image") {
|
|
474
|
+
return handleKieImageGeneration({
|
|
475
|
+
model,
|
|
476
|
+
provider,
|
|
477
|
+
providerConfig,
|
|
478
|
+
body,
|
|
479
|
+
credentials,
|
|
480
|
+
log,
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
if (providerConfig.format === "sdwebui") {
|
|
485
|
+
return handleSDWebUIImageGeneration({ model, provider, providerConfig, body, log });
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
if (providerConfig.format === "comfyui") {
|
|
489
|
+
return handleComfyUIImageGeneration({ model, provider, providerConfig, body, log });
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
if (providerConfig.format === "codex-responses") {
|
|
493
|
+
return handleCodexImageGeneration({
|
|
494
|
+
model,
|
|
495
|
+
provider,
|
|
496
|
+
providerConfig,
|
|
497
|
+
body,
|
|
498
|
+
credentials,
|
|
499
|
+
log,
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
if (providerConfig.format === "haiper-image") {
|
|
504
|
+
return handleHaiperImageGeneration({ model, provider, providerConfig, body, credentials, log });
|
|
505
|
+
}
|
|
506
|
+
if (providerConfig.format === "leonardo-image") {
|
|
507
|
+
return handleLeonardoImageGeneration({
|
|
508
|
+
model,
|
|
509
|
+
provider,
|
|
510
|
+
providerConfig,
|
|
511
|
+
body,
|
|
512
|
+
credentials,
|
|
513
|
+
log,
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
if (providerConfig.format === "ideogram-image") {
|
|
517
|
+
return handleIdeogramImageGeneration({
|
|
518
|
+
model,
|
|
519
|
+
provider,
|
|
520
|
+
providerConfig,
|
|
521
|
+
body,
|
|
522
|
+
credentials,
|
|
523
|
+
log,
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
if (providerConfig.format === "nvidia-nim") {
|
|
528
|
+
return handleNvidiaNimImageGeneration({
|
|
529
|
+
model,
|
|
530
|
+
provider,
|
|
531
|
+
providerConfig,
|
|
532
|
+
body,
|
|
533
|
+
credentials,
|
|
534
|
+
log,
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
return handleOpenAIImageGeneration({ model, provider, providerConfig, body, credentials, log });
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
function normalizeKieImageResult(recordData: unknown): string[] {
|
|
542
|
+
const record = isJsonObject(recordData) ? recordData : {};
|
|
543
|
+
const data = isJsonObject(record.data) ? record.data : {};
|
|
544
|
+
const response = isJsonObject(data.response) ? data.response : {};
|
|
545
|
+
const resultJson = parseKieResultJson(recordData);
|
|
546
|
+
const urls = new Set<string>();
|
|
547
|
+
|
|
548
|
+
const add = (val: unknown) => {
|
|
549
|
+
if (typeof val === "string" && val.startsWith("http")) urls.add(val);
|
|
550
|
+
if (Array.isArray(val)) {
|
|
551
|
+
val.forEach((v) => {
|
|
552
|
+
if (typeof v === "string" && v.startsWith("http")) urls.add(v);
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
// Check resultJson (common in Market API)
|
|
558
|
+
add(resultJson?.resultUrls);
|
|
559
|
+
add(resultJson?.imageUrls);
|
|
560
|
+
add(resultJson?.resultUrl);
|
|
561
|
+
add(resultJson?.imageUrl);
|
|
562
|
+
|
|
563
|
+
// Check data.response (common in 4o-image API)
|
|
564
|
+
add(response.resultUrls);
|
|
565
|
+
add(response.resultUrl);
|
|
566
|
+
|
|
567
|
+
// Check direct data fields
|
|
568
|
+
add(data.resultImageUrls);
|
|
569
|
+
add(data.resultImageUrl);
|
|
570
|
+
add(data.url);
|
|
571
|
+
|
|
572
|
+
return Array.from(urls);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
async function handleKieImageGeneration({
|
|
576
|
+
model,
|
|
577
|
+
provider,
|
|
578
|
+
providerConfig,
|
|
579
|
+
body,
|
|
580
|
+
credentials,
|
|
581
|
+
log,
|
|
582
|
+
}: KieImageOptions) {
|
|
583
|
+
const startTime = Date.now();
|
|
584
|
+
const token = credentials?.apiKey || credentials?.accessToken;
|
|
585
|
+
const timeoutMs = normalizePositiveNumber(body.timeout_ms, 300000);
|
|
586
|
+
const pollIntervalMs = normalizePositiveNumber(body.poll_interval_ms, 2500);
|
|
587
|
+
const prompt = typeof body.prompt === "string" ? body.prompt : String(body.prompt ?? "");
|
|
588
|
+
const size = typeof body.size === "string" ? body.size : undefined;
|
|
589
|
+
|
|
590
|
+
if (!token) {
|
|
591
|
+
return saveImageErrorResult({
|
|
592
|
+
provider,
|
|
593
|
+
model,
|
|
594
|
+
status: 401,
|
|
595
|
+
startTime,
|
|
596
|
+
error: "KIE API key is required",
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// Check if model is a Market model (unified API)
|
|
601
|
+
const fullRegistry = getImageProvider(provider);
|
|
602
|
+
const modelEntry = fullRegistry?.models?.find((m) => m.id === model);
|
|
603
|
+
const isMarket = modelEntry?.isMarket || model.includes("/");
|
|
604
|
+
|
|
605
|
+
const { imageUrl } = extractImageInputs(body);
|
|
606
|
+
let baseUrl = "";
|
|
607
|
+
let payload: Record<string, unknown> = {};
|
|
608
|
+
|
|
609
|
+
if (isMarket) {
|
|
610
|
+
// Unified Market API endpoint
|
|
611
|
+
baseUrl = `${providerConfig.baseUrl.replace(/\/$/, "")}/api/v1/jobs/createTask`;
|
|
612
|
+
const input: Record<string, unknown> = {
|
|
613
|
+
prompt,
|
|
614
|
+
aspect_ratio: mapImageSize(size, "1:1"),
|
|
615
|
+
};
|
|
616
|
+
if (imageUrl) {
|
|
617
|
+
input.image_url = imageUrl;
|
|
618
|
+
}
|
|
619
|
+
payload = {
|
|
620
|
+
model,
|
|
621
|
+
input,
|
|
622
|
+
};
|
|
623
|
+
} else {
|
|
624
|
+
// Legacy/Direct endpoint
|
|
625
|
+
const modelPath = model.replace("-t2i", "").replace("-i2i", "");
|
|
626
|
+
baseUrl = providerConfig.baseUrl.includes(model)
|
|
627
|
+
? providerConfig.baseUrl
|
|
628
|
+
: `https://api.kie.ai/api/v1/${modelPath}/generate`;
|
|
629
|
+
|
|
630
|
+
payload = {
|
|
631
|
+
prompt,
|
|
632
|
+
size: mapImageSize(size, "1:1"),
|
|
633
|
+
nVariants: body.n || 1,
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
if (log) {
|
|
638
|
+
const promptPreview = String(body.prompt ?? "").slice(0, 60);
|
|
639
|
+
log.info(
|
|
640
|
+
"IMAGE",
|
|
641
|
+
`${provider}/${model} (${isMarket ? "market" : "direct"}) | prompt: "${promptPreview}..."`
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
try {
|
|
646
|
+
const endpoint = isMarket ? "/api/v1/jobs/createTask" : new URL(baseUrl).pathname;
|
|
647
|
+
const createBaseUrl = isMarket ? providerConfig.baseUrl : baseUrl.replace(endpoint, "");
|
|
648
|
+
const createData = await kieExecutor.createTask({
|
|
649
|
+
baseUrl: createBaseUrl,
|
|
650
|
+
token,
|
|
651
|
+
payload,
|
|
652
|
+
endpoint,
|
|
653
|
+
});
|
|
654
|
+
const taskId = createData?.data?.taskId || createData?.taskId;
|
|
655
|
+
|
|
656
|
+
if (!taskId) {
|
|
657
|
+
const errorMessage =
|
|
658
|
+
createData?.msg ||
|
|
659
|
+
createData?.message ||
|
|
660
|
+
createData?.error ||
|
|
661
|
+
"KIE image generation did not return taskId";
|
|
662
|
+
if (log) {
|
|
663
|
+
log.error("IMAGE", `KIE createTask failed: ${JSON.stringify(createData)}`);
|
|
664
|
+
}
|
|
665
|
+
return saveImageErrorResult({
|
|
666
|
+
provider,
|
|
667
|
+
model,
|
|
668
|
+
status: 502,
|
|
669
|
+
startTime,
|
|
670
|
+
error: errorMessage,
|
|
671
|
+
requestBody: payload,
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// Use statusUrl from providerConfig if available, fallback to dynamic derivation
|
|
676
|
+
const statusUrl = isMarket
|
|
677
|
+
? `${providerConfig.baseUrl.replace(/\/$/, "")}/api/v1/jobs/recordInfo`
|
|
678
|
+
: providerConfig.statusUrl && !providerConfig.statusUrl.includes("jobs/recordInfo")
|
|
679
|
+
? providerConfig.statusUrl
|
|
680
|
+
: baseUrl.replace(/\/generate$/, "/record-info");
|
|
681
|
+
|
|
682
|
+
const { data: recordData, state } = await kieExecutor.pollTask({
|
|
683
|
+
statusUrl,
|
|
684
|
+
taskId: String(taskId),
|
|
685
|
+
token,
|
|
686
|
+
timeoutMs,
|
|
687
|
+
pollIntervalMs,
|
|
688
|
+
});
|
|
689
|
+
|
|
690
|
+
if (state === "success") {
|
|
691
|
+
if (log) {
|
|
692
|
+
log.info("IMAGE", `KIE poll success for task ${taskId}`);
|
|
693
|
+
}
|
|
694
|
+
const urls = normalizeKieImageResult(recordData);
|
|
695
|
+
const images = urls.map((url: string) => ({ url, revised_prompt: prompt }));
|
|
696
|
+
|
|
697
|
+
return saveImageSuccessResult({
|
|
698
|
+
provider,
|
|
699
|
+
model,
|
|
700
|
+
startTime,
|
|
701
|
+
requestBody: payload,
|
|
702
|
+
responseBody: { images_count: images.length },
|
|
703
|
+
images,
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
const record = isJsonObject(recordData) ? recordData : {};
|
|
708
|
+
const recordDataBody = isJsonObject(record.data) ? record.data : {};
|
|
709
|
+
const errorMessage =
|
|
710
|
+
recordDataBody.errorMessage ||
|
|
711
|
+
recordDataBody.failMsg ||
|
|
712
|
+
record.msg ||
|
|
713
|
+
"KIE image task failed";
|
|
714
|
+
|
|
715
|
+
if (log) {
|
|
716
|
+
log.error("IMAGE", `KIE poll failed for task ${taskId}: ${JSON.stringify(recordData)}`);
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
return saveImageErrorResult({
|
|
720
|
+
provider,
|
|
721
|
+
model,
|
|
722
|
+
status: 502,
|
|
723
|
+
startTime,
|
|
724
|
+
error: String(errorMessage),
|
|
725
|
+
requestBody: payload,
|
|
726
|
+
});
|
|
727
|
+
} catch (err: unknown) {
|
|
728
|
+
return saveImageErrorResult({
|
|
729
|
+
provider,
|
|
730
|
+
model,
|
|
731
|
+
status: getKieErrorStatus(err, 502),
|
|
732
|
+
startTime,
|
|
733
|
+
error: `Image provider error: ${getKieErrorMessage(err, "KIE image generation failed")}`,
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Handle Gemini-format image generation (Antigravity / Nano Banana)
|
|
739
|
+
* Uses Gemini's generateContent API with responseModalities: ["TEXT", "IMAGE"]
|
|
740
|
+
*/
|
|
741
|
+
async function handleGeminiImageGeneration({ model, providerConfig, body, credentials, log }) {
|
|
742
|
+
const startTime = Date.now();
|
|
743
|
+
const url = providerConfig.baseUrl;
|
|
744
|
+
const provider = "antigravity";
|
|
745
|
+
const credentialRecord = credentials || {};
|
|
746
|
+
const token = credentialRecord.accessToken || credentialRecord.apiKey;
|
|
747
|
+
const providerSpecificData = credentialRecord.providerSpecificData;
|
|
748
|
+
const providerSpecificProjectId =
|
|
749
|
+
providerSpecificData && typeof providerSpecificData === "object"
|
|
750
|
+
? (providerSpecificData as Record<string, unknown>).projectId
|
|
751
|
+
: null;
|
|
752
|
+
const credentialProjectId =
|
|
753
|
+
typeof credentialRecord.projectId === "string" ? credentialRecord.projectId.trim() : "";
|
|
754
|
+
const providerProjectId =
|
|
755
|
+
typeof providerSpecificProjectId === "string" ? providerSpecificProjectId.trim() : "";
|
|
756
|
+
const projectId = credentialProjectId || providerProjectId || null;
|
|
757
|
+
const candidateCount =
|
|
758
|
+
typeof body.n === "number" && Number.isFinite(body.n) && body.n > 0 ? Math.floor(body.n) : 1;
|
|
759
|
+
const promptText = typeof body.prompt === "string" ? body.prompt : String(body.prompt ?? "");
|
|
760
|
+
|
|
761
|
+
// Summarized request for call log
|
|
762
|
+
const logRequestBody = {
|
|
763
|
+
model: body.model,
|
|
764
|
+
prompt: promptText.slice(0, 200),
|
|
765
|
+
size: body.size || "default",
|
|
766
|
+
n: candidateCount,
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
if (!projectId || typeof projectId !== "string") {
|
|
770
|
+
return saveImageErrorResult({
|
|
771
|
+
provider,
|
|
772
|
+
model,
|
|
773
|
+
status: 400,
|
|
774
|
+
startTime,
|
|
775
|
+
error:
|
|
776
|
+
"Missing Google projectId for Antigravity account. Please reconnect OAuth in Providers so OmniRoute can fetch your Cloud Code project.",
|
|
777
|
+
requestBody: logRequestBody,
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
const antigravityBody = {
|
|
782
|
+
project: projectId,
|
|
783
|
+
requestId: `image_gen/${Date.now()}/${randomUUID()}/0`,
|
|
784
|
+
request: {
|
|
785
|
+
contents: [
|
|
786
|
+
{
|
|
787
|
+
role: "user",
|
|
788
|
+
parts: [{ text: promptText }],
|
|
789
|
+
},
|
|
790
|
+
],
|
|
791
|
+
generationConfig: {
|
|
792
|
+
candidateCount,
|
|
793
|
+
imageConfig: {
|
|
794
|
+
aspectRatio: normalizeImageAspectRatio(body.aspect_ratio, body.size),
|
|
795
|
+
},
|
|
796
|
+
},
|
|
797
|
+
},
|
|
798
|
+
model,
|
|
799
|
+
userAgent: getAntigravityEnvelopeUserAgent(credentialRecord),
|
|
800
|
+
requestType: "image_gen",
|
|
801
|
+
};
|
|
802
|
+
|
|
803
|
+
const headers = {
|
|
804
|
+
"Content-Type": "application/json",
|
|
805
|
+
Authorization: `Bearer ${token}`,
|
|
806
|
+
};
|
|
807
|
+
applyAntigravityClientProfileHeaders(headers, credentialRecord, antigravityBody);
|
|
808
|
+
delete headers["x-goog-user-project"];
|
|
809
|
+
|
|
810
|
+
if (log) {
|
|
811
|
+
const promptPreview = promptText.slice(0, 60);
|
|
812
|
+
log.info(
|
|
813
|
+
"IMAGE",
|
|
814
|
+
`antigravity/${model} (gemini) | prompt: "${promptPreview}..." | format: gemini-image`
|
|
815
|
+
);
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
try {
|
|
819
|
+
const response = await fetch(url, {
|
|
820
|
+
method: "POST",
|
|
821
|
+
headers,
|
|
822
|
+
body: JSON.stringify(antigravityBody),
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
if (!response.ok) {
|
|
826
|
+
const errorText = await response.text();
|
|
827
|
+
const safeError = sanitizeImageProviderError(errorText);
|
|
828
|
+
const safeErrorLog =
|
|
829
|
+
typeof safeError === "string" ? safeError : JSON.stringify(safeError ?? {});
|
|
830
|
+
if (log) {
|
|
831
|
+
log.error("IMAGE", `antigravity error ${response.status}: ${safeErrorLog.slice(0, 200)}`);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
saveCallLog({
|
|
835
|
+
method: "POST",
|
|
836
|
+
path: "/v1/images/generations",
|
|
837
|
+
status: response.status,
|
|
838
|
+
model: `antigravity/${model}`,
|
|
839
|
+
provider,
|
|
840
|
+
duration: Date.now() - startTime,
|
|
841
|
+
error: safeErrorLog.slice(0, 500),
|
|
842
|
+
requestBody: logRequestBody,
|
|
843
|
+
}).catch(() => {});
|
|
844
|
+
|
|
845
|
+
return { success: false, status: response.status, error: safeError };
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
const data = await response.json();
|
|
849
|
+
const responseBody = data.response || data;
|
|
850
|
+
|
|
851
|
+
// Extract image data from Antigravity's wrapped Gemini response.
|
|
852
|
+
const images = [];
|
|
853
|
+
const candidates = responseBody.candidates || [];
|
|
854
|
+
for (const candidate of candidates) {
|
|
855
|
+
const parts = candidate.content?.parts || [];
|
|
856
|
+
for (const part of parts) {
|
|
857
|
+
if (part.inlineData) {
|
|
858
|
+
images.push({
|
|
859
|
+
b64_json: part.inlineData.data,
|
|
860
|
+
revised_prompt: parts.find((p) => p.text)?.text || promptText,
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
saveCallLog({
|
|
867
|
+
method: "POST",
|
|
868
|
+
path: "/v1/images/generations",
|
|
869
|
+
status: 200,
|
|
870
|
+
model: `antigravity/${model}`,
|
|
871
|
+
provider,
|
|
872
|
+
duration: Date.now() - startTime,
|
|
873
|
+
tokens: { prompt_tokens: 0, completion_tokens: 0 },
|
|
874
|
+
requestBody: logRequestBody,
|
|
875
|
+
responseBody: { images_count: images.length },
|
|
876
|
+
}).catch(() => {});
|
|
877
|
+
|
|
878
|
+
return {
|
|
879
|
+
success: true,
|
|
880
|
+
data: {
|
|
881
|
+
created: Math.floor(Date.now() / 1000),
|
|
882
|
+
data: images,
|
|
883
|
+
},
|
|
884
|
+
};
|
|
885
|
+
} catch (err) {
|
|
886
|
+
if (log) {
|
|
887
|
+
log.error("IMAGE", `antigravity fetch error: ${err.message}`);
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
saveCallLog({
|
|
891
|
+
method: "POST",
|
|
892
|
+
path: "/v1/images/generations",
|
|
893
|
+
status: 502,
|
|
894
|
+
model: `antigravity/${model}`,
|
|
895
|
+
provider,
|
|
896
|
+
duration: Date.now() - startTime,
|
|
897
|
+
error: err.message,
|
|
898
|
+
requestBody: logRequestBody,
|
|
899
|
+
}).catch(() => {});
|
|
900
|
+
|
|
901
|
+
return {
|
|
902
|
+
success: false,
|
|
903
|
+
status: 502,
|
|
904
|
+
error: `Image provider error: ${sanitizeErrorMessage((err as Error).message || err)}`,
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
/**
|
|
910
|
+
* Handle OpenAI-compatible image generation (standard providers + Nebius fallback)
|
|
911
|
+
*/
|
|
912
|
+
async function handleOpenAIImageGeneration({
|
|
913
|
+
model,
|
|
914
|
+
provider,
|
|
915
|
+
providerConfig,
|
|
916
|
+
body,
|
|
917
|
+
credentials,
|
|
918
|
+
log,
|
|
919
|
+
}) {
|
|
920
|
+
const startTime = Date.now();
|
|
921
|
+
|
|
922
|
+
// Summarized request for call log
|
|
923
|
+
const logRequestBody = {
|
|
924
|
+
model: body.model,
|
|
925
|
+
prompt:
|
|
926
|
+
typeof body.prompt === "string"
|
|
927
|
+
? body.prompt.slice(0, 200)
|
|
928
|
+
: String(body.prompt ?? "").slice(0, 200),
|
|
929
|
+
size: body.size || "default",
|
|
930
|
+
n: body.n || 1,
|
|
931
|
+
quality: body.quality || undefined,
|
|
932
|
+
};
|
|
933
|
+
|
|
934
|
+
// Build upstream request (OpenAI-compatible format)
|
|
935
|
+
const upstreamBody: Record<string, unknown> = {
|
|
936
|
+
model: model,
|
|
937
|
+
prompt: body.prompt,
|
|
938
|
+
};
|
|
939
|
+
|
|
940
|
+
// Pass optional parameters
|
|
941
|
+
if (body.n !== undefined) upstreamBody.n = body.n;
|
|
942
|
+
if (body.size !== undefined) upstreamBody.size = body.size;
|
|
943
|
+
if (body.quality !== undefined) upstreamBody.quality = body.quality;
|
|
944
|
+
if (body.response_format !== undefined) upstreamBody.response_format = body.response_format;
|
|
945
|
+
if (body.style !== undefined) upstreamBody.style = body.style;
|
|
946
|
+
|
|
947
|
+
const { imageUrl } = extractImageInputs(body);
|
|
948
|
+
if (imageUrl && OPENAI_IMAGE_TO_IMAGE_MODELS.has(model)) {
|
|
949
|
+
upstreamBody.image_url = imageUrl;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
// Build headers
|
|
953
|
+
const headers = {
|
|
954
|
+
"Content-Type": "application/json",
|
|
955
|
+
};
|
|
956
|
+
|
|
957
|
+
const token = credentials.apiKey || credentials.accessToken;
|
|
958
|
+
if (providerConfig.authHeader === "bearer") {
|
|
959
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
960
|
+
} else if (providerConfig.authHeader === "x-api-key") {
|
|
961
|
+
headers["x-api-key"] = token;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
if (log) {
|
|
965
|
+
const promptPreview =
|
|
966
|
+
typeof body.prompt === "string"
|
|
967
|
+
? body.prompt.slice(0, 60)
|
|
968
|
+
: String(body.prompt ?? "").slice(0, 60);
|
|
969
|
+
log.info(
|
|
970
|
+
"IMAGE",
|
|
971
|
+
`${provider}/${model} | prompt: "${promptPreview}..." | size: ${body.size || "default"}`
|
|
972
|
+
);
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
const requestBody = JSON.stringify(upstreamBody);
|
|
976
|
+
|
|
977
|
+
// Try primary URL
|
|
978
|
+
let result = await fetchImageEndpoint(
|
|
979
|
+
providerConfig.baseUrl,
|
|
980
|
+
headers,
|
|
981
|
+
requestBody,
|
|
982
|
+
provider,
|
|
983
|
+
log
|
|
984
|
+
);
|
|
985
|
+
|
|
986
|
+
// Fallback for providers with fallbackUrl (e.g., Nebius)
|
|
987
|
+
if (
|
|
988
|
+
!result.success &&
|
|
989
|
+
providerConfig.fallbackUrl &&
|
|
990
|
+
[404, 410, 502, 503].includes(result.status)
|
|
991
|
+
) {
|
|
992
|
+
if (log) {
|
|
993
|
+
log.info("IMAGE", `${provider}: primary URL failed (${result.status}), trying fallback...`);
|
|
994
|
+
}
|
|
995
|
+
result = await fetchImageEndpoint(
|
|
996
|
+
providerConfig.fallbackUrl,
|
|
997
|
+
headers,
|
|
998
|
+
requestBody,
|
|
999
|
+
provider,
|
|
1000
|
+
log
|
|
1001
|
+
);
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
// Save call log after result is determined
|
|
1005
|
+
saveCallLog({
|
|
1006
|
+
method: "POST",
|
|
1007
|
+
path: "/v1/images/generations",
|
|
1008
|
+
status: result.status || (result.success ? 200 : 502),
|
|
1009
|
+
model: `${provider}/${model}`,
|
|
1010
|
+
provider,
|
|
1011
|
+
duration: Date.now() - startTime,
|
|
1012
|
+
tokens: { prompt_tokens: 0, completion_tokens: 0 },
|
|
1013
|
+
error: result.success
|
|
1014
|
+
? null
|
|
1015
|
+
: typeof result.error === "string"
|
|
1016
|
+
? result.error.slice(0, 500)
|
|
1017
|
+
: null,
|
|
1018
|
+
requestBody: logRequestBody,
|
|
1019
|
+
responseBody: result.success ? { images_count: result.data?.data?.length || 0 } : null,
|
|
1020
|
+
}).catch(() => {});
|
|
1021
|
+
|
|
1022
|
+
return result;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
/**
|
|
1026
|
+
* OpenAI-compatible image *edit* forwarder for custom providers (#3214 / #3215).
|
|
1027
|
+
*
|
|
1028
|
+
* Mirrors `handleOpenAIImageGeneration` but posts multipart/form-data to the node's
|
|
1029
|
+
* `/images/edits` endpoint and returns the upstream OpenAI-compatible response. Kept
|
|
1030
|
+
* separate from the chatgpt-web edit flow, which continues a saved conversation node
|
|
1031
|
+
* rather than forwarding a stateless edit. The fetch helper leaves Content-Type unset so
|
|
1032
|
+
* `fetch` derives the multipart boundary from the FormData body.
|
|
1033
|
+
*/
|
|
1034
|
+
export async function handleOpenAIImageEdit({
|
|
1035
|
+
model,
|
|
1036
|
+
provider,
|
|
1037
|
+
credentials,
|
|
1038
|
+
prompt,
|
|
1039
|
+
imageBytes,
|
|
1040
|
+
imageMime,
|
|
1041
|
+
size,
|
|
1042
|
+
responseFormat,
|
|
1043
|
+
n = 1,
|
|
1044
|
+
log,
|
|
1045
|
+
}: {
|
|
1046
|
+
model: string;
|
|
1047
|
+
provider: string;
|
|
1048
|
+
credentials:
|
|
1049
|
+
| {
|
|
1050
|
+
apiKey?: string;
|
|
1051
|
+
accessToken?: string;
|
|
1052
|
+
baseUrl?: unknown;
|
|
1053
|
+
providerSpecificData?: { baseUrl?: unknown } | null;
|
|
1054
|
+
}
|
|
1055
|
+
| null
|
|
1056
|
+
| undefined;
|
|
1057
|
+
prompt: string;
|
|
1058
|
+
imageBytes: Buffer;
|
|
1059
|
+
imageMime?: string | null;
|
|
1060
|
+
size?: string | null;
|
|
1061
|
+
responseFormat?: string | null;
|
|
1062
|
+
n?: number;
|
|
1063
|
+
log?: { info: (tag: string, message: string) => void } | null;
|
|
1064
|
+
}) {
|
|
1065
|
+
const startTime = Date.now();
|
|
1066
|
+
const url = resolveImageBaseUrl(
|
|
1067
|
+
credentials,
|
|
1068
|
+
`https://generativelanguage.googleapis.com/v1beta/openai/images/edits`,
|
|
1069
|
+
"edits"
|
|
1070
|
+
);
|
|
1071
|
+
|
|
1072
|
+
// Build the multipart body as a Buffer with an explicit boundary instead of a global
|
|
1073
|
+
// `FormData`. In production `globalThis.fetch` is patched with node_modules/undici's fetch,
|
|
1074
|
+
// whose `FormData` class differs from `globalThis.FormData` — passing a native FormData
|
|
1075
|
+
// makes undici serialize it as the string "[object FormData]" (text/plain), dropping every
|
|
1076
|
+
// field (including `model`, which reaches the upstream empty). A Buffer body is accepted
|
|
1077
|
+
// verbatim by any fetch implementation. (#3273)
|
|
1078
|
+
const boundary = `----OmniRouteImageEdit${randomUUID().replace(/-/g, "")}`;
|
|
1079
|
+
const CRLF = "\r\n";
|
|
1080
|
+
const partBuffers: Buffer[] = [];
|
|
1081
|
+
const appendField = (name: string, value: string) => {
|
|
1082
|
+
partBuffers.push(
|
|
1083
|
+
Buffer.from(
|
|
1084
|
+
`--${boundary}${CRLF}Content-Disposition: form-data; name="${name}"${CRLF}${CRLF}${value}${CRLF}`
|
|
1085
|
+
)
|
|
1086
|
+
);
|
|
1087
|
+
};
|
|
1088
|
+
appendField("model", model);
|
|
1089
|
+
appendField("prompt", prompt);
|
|
1090
|
+
if (size) appendField("size", size);
|
|
1091
|
+
if (responseFormat) appendField("response_format", responseFormat);
|
|
1092
|
+
appendField("n", String(n || 1));
|
|
1093
|
+
partBuffers.push(
|
|
1094
|
+
Buffer.from(
|
|
1095
|
+
`--${boundary}${CRLF}Content-Disposition: form-data; name="image"; filename="image.png"${CRLF}` +
|
|
1096
|
+
`Content-Type: ${imageMime || "image/png"}${CRLF}${CRLF}`
|
|
1097
|
+
)
|
|
1098
|
+
);
|
|
1099
|
+
partBuffers.push(imageBytes);
|
|
1100
|
+
partBuffers.push(Buffer.from(`${CRLF}--${boundary}--${CRLF}`));
|
|
1101
|
+
const multipartBody = Buffer.concat(partBuffers);
|
|
1102
|
+
|
|
1103
|
+
const headers: Record<string, string> = {
|
|
1104
|
+
"Content-Type": `multipart/form-data; boundary=${boundary}`,
|
|
1105
|
+
};
|
|
1106
|
+
const token = credentials?.apiKey || credentials?.accessToken;
|
|
1107
|
+
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
1108
|
+
|
|
1109
|
+
if (log) {
|
|
1110
|
+
log.info("IMAGE", `${provider}/${model} (edit) | prompt: "${prompt.slice(0, 60)}..." -> ${url}`);
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
const result = await fetchImageEndpoint(
|
|
1114
|
+
url,
|
|
1115
|
+
headers,
|
|
1116
|
+
multipartBody as unknown as BodyInit,
|
|
1117
|
+
provider,
|
|
1118
|
+
log
|
|
1119
|
+
);
|
|
1120
|
+
|
|
1121
|
+
saveCallLog({
|
|
1122
|
+
method: "POST",
|
|
1123
|
+
path: "/v1/images/edits",
|
|
1124
|
+
status: result.status || (result.success ? 200 : 502),
|
|
1125
|
+
model: `${provider}/${model}`,
|
|
1126
|
+
provider,
|
|
1127
|
+
duration: Date.now() - startTime,
|
|
1128
|
+
tokens: { prompt_tokens: 0, completion_tokens: 0 },
|
|
1129
|
+
error: result.success
|
|
1130
|
+
? null
|
|
1131
|
+
: typeof result.error === "string"
|
|
1132
|
+
? result.error.slice(0, 500)
|
|
1133
|
+
: null,
|
|
1134
|
+
requestBody: { model, prompt: prompt.slice(0, 200), size: size || "default", n: n || 1 },
|
|
1135
|
+
responseBody: result.success ? { images_count: result.data?.data?.length || 0 } : null,
|
|
1136
|
+
}).catch(() => {});
|
|
1137
|
+
|
|
1138
|
+
return result;
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
export async function handleImageEdit({
|
|
1142
|
+
provider,
|
|
1143
|
+
model,
|
|
1144
|
+
body,
|
|
1145
|
+
imageBytes,
|
|
1146
|
+
credentials,
|
|
1147
|
+
log,
|
|
1148
|
+
signal = null,
|
|
1149
|
+
clientHeaders = null,
|
|
1150
|
+
}: {
|
|
1151
|
+
provider: string;
|
|
1152
|
+
model: string;
|
|
1153
|
+
body: Record<string, any>;
|
|
1154
|
+
imageBytes: Buffer;
|
|
1155
|
+
imageMime?: string; // accepted for symmetry with route layer; not used
|
|
1156
|
+
credentials: any;
|
|
1157
|
+
log: any;
|
|
1158
|
+
signal?: AbortSignal | null;
|
|
1159
|
+
clientHeaders?: Record<string, string> | null;
|
|
1160
|
+
}) {
|
|
1161
|
+
const startTime = Date.now();
|
|
1162
|
+
const prompt = typeof body.prompt === "string" ? body.prompt.trim() : "";
|
|
1163
|
+
if (!prompt) {
|
|
1164
|
+
return saveImageErrorResult({
|
|
1165
|
+
provider,
|
|
1166
|
+
model,
|
|
1167
|
+
status: 400,
|
|
1168
|
+
startTime,
|
|
1169
|
+
error: "Prompt is required for image edit",
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
if (!credentials?.apiKey) {
|
|
1174
|
+
return saveImageErrorResult({
|
|
1175
|
+
provider,
|
|
1176
|
+
model,
|
|
1177
|
+
status: 401,
|
|
1178
|
+
startTime,
|
|
1179
|
+
error: "ChatGPT Web credentials missing session cookie",
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
const imageHash = createHash("sha256").update(imageBytes).digest("hex");
|
|
1184
|
+
const cached = findChatGptImageBySha256(imageHash);
|
|
1185
|
+
|
|
1186
|
+
const wantsBase64 = body.response_format === "b64_json";
|
|
1187
|
+
const requestBody = {
|
|
1188
|
+
model,
|
|
1189
|
+
prompt: prompt.slice(0, 500),
|
|
1190
|
+
size: body.size || undefined,
|
|
1191
|
+
image_hash: imageHash.slice(0, 16),
|
|
1192
|
+
image_bytes: imageBytes.length,
|
|
1193
|
+
cached_match: Boolean(cached?.entry.context),
|
|
1194
|
+
};
|
|
1195
|
+
|
|
1196
|
+
if (!cached?.entry.context) {
|
|
1197
|
+
// chatgpt-web's image_gen tool can only edit an image when we continue
|
|
1198
|
+
// the original conversation node. If we never generated this image (or
|
|
1199
|
+
// its 30-minute TTL elapsed), there's no node to continue. Return a
|
|
1200
|
+
// clear, actionable error — much better than silently spawning an
|
|
1201
|
+
// unrelated image and confusing the user.
|
|
1202
|
+
log?.warn?.(
|
|
1203
|
+
"IMAGE",
|
|
1204
|
+
`chatgpt-web edit: no cached match for sha256=${imageHash.slice(0, 16)} (bytes=${imageBytes.length}); returning 400`
|
|
1205
|
+
);
|
|
1206
|
+
return saveImageErrorResult({
|
|
1207
|
+
provider,
|
|
1208
|
+
model,
|
|
1209
|
+
status: 400,
|
|
1210
|
+
startTime,
|
|
1211
|
+
error:
|
|
1212
|
+
"chatgpt-web image edit only works for images recently generated through this OmniRoute instance " +
|
|
1213
|
+
"(cache window: 30 minutes). Re-generate the image and try the edit immediately, or disable image-edit " +
|
|
1214
|
+
"in your client to use plain chat-completion edit prompts instead.",
|
|
1215
|
+
requestBody,
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
// Build a synthetic chat thread that surfaces the cached image URL on
|
|
1220
|
+
// the assistant turn. The executor's parseOpenAIMessages picks up the
|
|
1221
|
+
// URL, findCachedImageContext resolves it to {conversationId,
|
|
1222
|
+
// parentMessageId}, and looksLikeImageEditRequest fires on the user
|
|
1223
|
+
// prompt — together producing a continuation request that actually
|
|
1224
|
+
// edits the saved image.
|
|
1225
|
+
//
|
|
1226
|
+
// The synthetic user prompt is anchored with both an edit verb AND an
|
|
1227
|
+
// image-gen verb so the executor's heuristics fire regardless of what
|
|
1228
|
+
// wording the caller used ("now make it brighter", "tweak this", ...):
|
|
1229
|
+
// - looksLikeImageEditRequest: matches "edit" + "image" within 120 chars
|
|
1230
|
+
// - looksLikeImageGenRequest: matches "generate" + "image" within 40 chars
|
|
1231
|
+
// Either match alone would set forImageGen, but covering both is cheap
|
|
1232
|
+
// insurance for prompts that don't fit common phrasings.
|
|
1233
|
+
const messages: Array<{ role: string; content: string }> = [
|
|
1234
|
+
{
|
|
1235
|
+
role: "assistant",
|
|
1236
|
+
// The base URL is irrelevant — only the path is parsed by
|
|
1237
|
+
// CACHED_IMAGE_URL_RE in the executor's findCachedImageContext.
|
|
1238
|
+
content: ``,
|
|
1239
|
+
},
|
|
1240
|
+
{
|
|
1241
|
+
role: "user",
|
|
1242
|
+
content: `Edit the image and generate the new image: ${prompt}`,
|
|
1243
|
+
},
|
|
1244
|
+
];
|
|
1245
|
+
|
|
1246
|
+
const executor = new ChatGptWebExecutor();
|
|
1247
|
+
const result = await executor.execute({
|
|
1248
|
+
model,
|
|
1249
|
+
body: { messages },
|
|
1250
|
+
stream: false,
|
|
1251
|
+
credentials,
|
|
1252
|
+
signal,
|
|
1253
|
+
log,
|
|
1254
|
+
clientHeaders,
|
|
1255
|
+
});
|
|
1256
|
+
|
|
1257
|
+
const responseText = await result.response.text();
|
|
1258
|
+
if (result.response.status >= 400) {
|
|
1259
|
+
return saveImageErrorResult({
|
|
1260
|
+
provider,
|
|
1261
|
+
model,
|
|
1262
|
+
status: result.response.status,
|
|
1263
|
+
startTime,
|
|
1264
|
+
error: responseText,
|
|
1265
|
+
requestBody,
|
|
1266
|
+
});
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
let content = "";
|
|
1270
|
+
try {
|
|
1271
|
+
const json = JSON.parse(responseText);
|
|
1272
|
+
content = String(json?.choices?.[0]?.message?.content || "");
|
|
1273
|
+
} catch {
|
|
1274
|
+
content = responseText;
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
const urls = extractMarkdownImageUrls(content);
|
|
1278
|
+
if (urls.length === 0) {
|
|
1279
|
+
return saveImageErrorResult({
|
|
1280
|
+
provider,
|
|
1281
|
+
model,
|
|
1282
|
+
status: 502,
|
|
1283
|
+
startTime,
|
|
1284
|
+
error: `ChatGPT Web edit completed without returning image markdown: ${content.slice(0, 300)}`,
|
|
1285
|
+
requestBody,
|
|
1286
|
+
});
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
const images: Array<{ url?: string; b64_json?: string }> = [];
|
|
1290
|
+
for (const url of urls) {
|
|
1291
|
+
if (!wantsBase64) {
|
|
1292
|
+
images.push({ url });
|
|
1293
|
+
continue;
|
|
1294
|
+
}
|
|
1295
|
+
const id = url.match(CHATGPT_WEB_IMAGE_ID_RE)?.[1];
|
|
1296
|
+
const cachedNew = id ? getChatGptImage(id) : null;
|
|
1297
|
+
if (!cachedNew) {
|
|
1298
|
+
return saveImageErrorResult({
|
|
1299
|
+
provider,
|
|
1300
|
+
model,
|
|
1301
|
+
status: 502,
|
|
1302
|
+
startTime,
|
|
1303
|
+
error: "ChatGPT Web image bytes expired before b64_json conversion",
|
|
1304
|
+
requestBody,
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
images.push({ b64_json: cachedNew.bytes.toString("base64") });
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
return saveImageSuccessResult({
|
|
1311
|
+
provider,
|
|
1312
|
+
model,
|
|
1313
|
+
startTime,
|
|
1314
|
+
requestBody,
|
|
1315
|
+
responseBody: { images_count: images.length, edit_match: Boolean(cached?.entry.context) },
|
|
1316
|
+
images,
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
async function handleFalAIImageGeneration({
|
|
1321
|
+
model,
|
|
1322
|
+
provider,
|
|
1323
|
+
providerConfig,
|
|
1324
|
+
body,
|
|
1325
|
+
credentials,
|
|
1326
|
+
log,
|
|
1327
|
+
}) {
|
|
1328
|
+
const startTime = Date.now();
|
|
1329
|
+
const token = credentials.apiKey || credentials.accessToken;
|
|
1330
|
+
const { imageUrl, imageUrls } = extractImageInputs(body);
|
|
1331
|
+
const upstreamBody: Record<string, unknown> = {
|
|
1332
|
+
prompt: body.prompt,
|
|
1333
|
+
sync_mode: body.sync_mode ?? true,
|
|
1334
|
+
};
|
|
1335
|
+
|
|
1336
|
+
if (body.n !== undefined) upstreamBody.num_images = Number(body.n) || 1;
|
|
1337
|
+
if (body.negative_prompt) upstreamBody.negative_prompt = body.negative_prompt;
|
|
1338
|
+
if (body.seed !== undefined) upstreamBody.seed = body.seed;
|
|
1339
|
+
if (body.style) upstreamBody.style = normalizeRecraftStyle(body.style);
|
|
1340
|
+
|
|
1341
|
+
const outputFormat = normalizeRequestedImageFormat(body, "png");
|
|
1342
|
+
if (outputFormat) upstreamBody.output_format = outputFormat;
|
|
1343
|
+
|
|
1344
|
+
if (model.includes("flux-pro/v1.1") && !model.includes("ultra")) {
|
|
1345
|
+
upstreamBody.image_size = mapFalImageSize(body.size, "landscape_4_3");
|
|
1346
|
+
} else if (
|
|
1347
|
+
model.includes("bytedance/") ||
|
|
1348
|
+
model.includes("stable-diffusion") ||
|
|
1349
|
+
model.includes("ideogram") ||
|
|
1350
|
+
model.includes("recraft/v3")
|
|
1351
|
+
) {
|
|
1352
|
+
upstreamBody.image_size = mapFalImageSize(body.size, "square_hd");
|
|
1353
|
+
} else {
|
|
1354
|
+
upstreamBody.aspect_ratio = body.aspect_ratio || mapFalAspectRatio(body.size, "1:1");
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
if (body.quality === "hd" && model.includes("ultra")) {
|
|
1358
|
+
upstreamBody.raw = true;
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
if (imageUrl && model.includes("flux-pro/v1.1-ultra")) {
|
|
1362
|
+
upstreamBody.image_url = imageUrl;
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
if (imageUrls.length > 0 && model.includes("ideogram")) {
|
|
1366
|
+
upstreamBody.image_urls = imageUrls;
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
if (log) {
|
|
1370
|
+
const promptPreview = String(body.prompt ?? "").slice(0, 60);
|
|
1371
|
+
log.info("IMAGE", `${provider}/${model} (fal-ai) | prompt: "${promptPreview}..."`);
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
try {
|
|
1375
|
+
const response = await fetch(`${providerConfig.baseUrl.replace(/\/$/, "")}/${model}`, {
|
|
1376
|
+
method: "POST",
|
|
1377
|
+
headers: {
|
|
1378
|
+
"Content-Type": "application/json",
|
|
1379
|
+
Authorization: `Key ${token}`,
|
|
1380
|
+
},
|
|
1381
|
+
body: JSON.stringify(upstreamBody),
|
|
1382
|
+
});
|
|
1383
|
+
|
|
1384
|
+
if (!response.ok) {
|
|
1385
|
+
const errorText = await response.text();
|
|
1386
|
+
if (log)
|
|
1387
|
+
log.error("IMAGE", `${provider} error ${response.status}: ${errorText.slice(0, 200)}`);
|
|
1388
|
+
return saveImageErrorResult({
|
|
1389
|
+
provider,
|
|
1390
|
+
model,
|
|
1391
|
+
status: response.status,
|
|
1392
|
+
startTime,
|
|
1393
|
+
error: errorText,
|
|
1394
|
+
requestBody: upstreamBody,
|
|
1395
|
+
});
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
const payload = await response.json();
|
|
1399
|
+
const images = await normalizeProviderImagePayload(payload, body, log);
|
|
1400
|
+
return saveImageSuccessResult({
|
|
1401
|
+
provider,
|
|
1402
|
+
model,
|
|
1403
|
+
startTime,
|
|
1404
|
+
requestBody: upstreamBody,
|
|
1405
|
+
responseBody: { images_count: images.length },
|
|
1406
|
+
created: payload.created,
|
|
1407
|
+
images,
|
|
1408
|
+
});
|
|
1409
|
+
} catch (err) {
|
|
1410
|
+
if (log) log.error("IMAGE", `${provider} fetch error: ${err.message}`);
|
|
1411
|
+
return saveImageErrorResult({
|
|
1412
|
+
provider,
|
|
1413
|
+
model,
|
|
1414
|
+
status: 502,
|
|
1415
|
+
startTime,
|
|
1416
|
+
error: `Image provider error: ${sanitizeErrorMessage((err as Error).message || err)}`,
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
async function handleStabilityAIImageGeneration({
|
|
1422
|
+
model,
|
|
1423
|
+
provider,
|
|
1424
|
+
providerConfig,
|
|
1425
|
+
body,
|
|
1426
|
+
credentials,
|
|
1427
|
+
log,
|
|
1428
|
+
}) {
|
|
1429
|
+
const startTime = Date.now();
|
|
1430
|
+
const token = credentials.apiKey || credentials.accessToken;
|
|
1431
|
+
const endpoint = STABILITY_GENERATION_ENDPOINTS[model] || STABILITY_EDIT_ENDPOINTS[model];
|
|
1432
|
+
|
|
1433
|
+
if (!endpoint) {
|
|
1434
|
+
return {
|
|
1435
|
+
success: false,
|
|
1436
|
+
status: 400,
|
|
1437
|
+
error: `Unsupported Stability AI image model: ${model}`,
|
|
1438
|
+
};
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
const { imageUrl, maskUrl } = extractImageInputs(body);
|
|
1442
|
+
const upstreamBody: Record<string, unknown> = {
|
|
1443
|
+
output_format:
|
|
1444
|
+
model === "remove-background"
|
|
1445
|
+
? normalizeRequestedImageFormat(body, "png", ["png", "webp"])
|
|
1446
|
+
: normalizeRequestedImageFormat(body, "png"),
|
|
1447
|
+
};
|
|
1448
|
+
const formData = new FormData();
|
|
1449
|
+
|
|
1450
|
+
appendOptionalFormValue(formData, "output_format", upstreamBody.output_format);
|
|
1451
|
+
if (body.prompt) {
|
|
1452
|
+
upstreamBody.prompt = body.prompt;
|
|
1453
|
+
appendOptionalFormValue(formData, "prompt", body.prompt);
|
|
1454
|
+
}
|
|
1455
|
+
if (body.negative_prompt) {
|
|
1456
|
+
upstreamBody.negative_prompt = body.negative_prompt;
|
|
1457
|
+
appendOptionalFormValue(formData, "negative_prompt", body.negative_prompt);
|
|
1458
|
+
}
|
|
1459
|
+
if (body.seed !== undefined) {
|
|
1460
|
+
upstreamBody.seed = body.seed;
|
|
1461
|
+
appendOptionalFormValue(formData, "seed", body.seed);
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
try {
|
|
1465
|
+
if (STABILITY_GENERATION_ENDPOINTS[model]) {
|
|
1466
|
+
if (model.startsWith("sd3.5")) {
|
|
1467
|
+
upstreamBody.model = model;
|
|
1468
|
+
appendOptionalFormValue(formData, "model", model);
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
if (imageUrl) {
|
|
1472
|
+
const imageSource = await resolveImageSource(imageUrl);
|
|
1473
|
+
upstreamBody.mode = "image-to-image";
|
|
1474
|
+
appendOptionalFormValue(formData, "mode", "image-to-image");
|
|
1475
|
+
upstreamBody.image = imageSource.base64;
|
|
1476
|
+
appendImageFormValue(formData, "image", imageSource, "image");
|
|
1477
|
+
if (body.strength !== undefined) {
|
|
1478
|
+
upstreamBody.strength = body.strength;
|
|
1479
|
+
appendOptionalFormValue(formData, "strength", body.strength);
|
|
1480
|
+
}
|
|
1481
|
+
} else {
|
|
1482
|
+
upstreamBody.mode = "text-to-image";
|
|
1483
|
+
appendOptionalFormValue(formData, "mode", "text-to-image");
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
if (!model.startsWith("sd3.5") || !imageUrl) {
|
|
1487
|
+
const aspectRatio = body.aspect_ratio || mapImageSize(body.size);
|
|
1488
|
+
upstreamBody.aspect_ratio = aspectRatio;
|
|
1489
|
+
appendOptionalFormValue(formData, "aspect_ratio", aspectRatio);
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
if (body.style_preset) {
|
|
1493
|
+
upstreamBody.style_preset = body.style_preset;
|
|
1494
|
+
appendOptionalFormValue(formData, "style_preset", body.style_preset);
|
|
1495
|
+
}
|
|
1496
|
+
} else {
|
|
1497
|
+
if (imageUrl) {
|
|
1498
|
+
const imageSource = await resolveImageSource(imageUrl);
|
|
1499
|
+
upstreamBody.image = imageSource.base64;
|
|
1500
|
+
appendImageFormValue(formData, "image", imageSource, "image");
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
if (maskUrl && shouldIncludeStabilityMask(model)) {
|
|
1504
|
+
const maskSource = await resolveImageSource(maskUrl);
|
|
1505
|
+
upstreamBody.mask = maskSource.base64;
|
|
1506
|
+
appendImageFormValue(formData, "mask", maskSource, "mask");
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
if (body.search_prompt) {
|
|
1510
|
+
upstreamBody.search_prompt = body.search_prompt;
|
|
1511
|
+
appendOptionalFormValue(formData, "search_prompt", body.search_prompt);
|
|
1512
|
+
}
|
|
1513
|
+
if (body.grow_mask !== undefined) {
|
|
1514
|
+
upstreamBody.grow_mask = body.grow_mask;
|
|
1515
|
+
appendOptionalFormValue(formData, "grow_mask", body.grow_mask);
|
|
1516
|
+
}
|
|
1517
|
+
if (body.control_strength !== undefined) {
|
|
1518
|
+
upstreamBody.control_strength = body.control_strength;
|
|
1519
|
+
appendOptionalFormValue(formData, "control_strength", body.control_strength);
|
|
1520
|
+
}
|
|
1521
|
+
if (body.creativity !== undefined) {
|
|
1522
|
+
upstreamBody.creativity = body.creativity;
|
|
1523
|
+
appendOptionalFormValue(formData, "creativity", body.creativity);
|
|
1524
|
+
}
|
|
1525
|
+
if (body.left !== undefined) {
|
|
1526
|
+
upstreamBody.left = body.left;
|
|
1527
|
+
appendOptionalFormValue(formData, "left", body.left);
|
|
1528
|
+
}
|
|
1529
|
+
if (body.right !== undefined) {
|
|
1530
|
+
upstreamBody.right = body.right;
|
|
1531
|
+
appendOptionalFormValue(formData, "right", body.right);
|
|
1532
|
+
}
|
|
1533
|
+
if (body.up !== undefined) {
|
|
1534
|
+
upstreamBody.up = body.up;
|
|
1535
|
+
appendOptionalFormValue(formData, "up", body.up);
|
|
1536
|
+
}
|
|
1537
|
+
if (body.down !== undefined) {
|
|
1538
|
+
upstreamBody.down = body.down;
|
|
1539
|
+
appendOptionalFormValue(formData, "down", body.down);
|
|
1540
|
+
}
|
|
1541
|
+
if (body.style_preset) {
|
|
1542
|
+
upstreamBody.style_preset = body.style_preset;
|
|
1543
|
+
appendOptionalFormValue(formData, "style_preset", body.style_preset);
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
if (STABILITY_CONTROL_MODELS.has(model) && !upstreamBody.prompt) {
|
|
1547
|
+
upstreamBody.prompt = body.prompt || "";
|
|
1548
|
+
appendOptionalFormValue(formData, "prompt", body.prompt || "");
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
if (log) {
|
|
1553
|
+
const promptPreview = String(body.prompt ?? "").slice(0, 60);
|
|
1554
|
+
log.info("IMAGE", `${provider}/${model} (stability-ai) | prompt: "${promptPreview}..."`);
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1557
|
+
const response = await fetch(`${providerConfig.baseUrl.replace(/\/$/, "")}${endpoint}`, {
|
|
1558
|
+
method: "POST",
|
|
1559
|
+
headers: {
|
|
1560
|
+
Accept: "application/json",
|
|
1561
|
+
Authorization: `Bearer ${token}`,
|
|
1562
|
+
},
|
|
1563
|
+
body: formData,
|
|
1564
|
+
});
|
|
1565
|
+
|
|
1566
|
+
if (!response.ok) {
|
|
1567
|
+
const errorText = await response.text();
|
|
1568
|
+
if (log)
|
|
1569
|
+
log.error("IMAGE", `${provider} error ${response.status}: ${errorText.slice(0, 200)}`);
|
|
1570
|
+
return saveImageErrorResult({
|
|
1571
|
+
provider,
|
|
1572
|
+
model,
|
|
1573
|
+
status: response.status,
|
|
1574
|
+
startTime,
|
|
1575
|
+
error: errorText,
|
|
1576
|
+
requestBody: upstreamBody,
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
const contentType = response.headers.get("content-type") || "";
|
|
1581
|
+
let payload;
|
|
1582
|
+
if (contentType.includes("application/json")) {
|
|
1583
|
+
payload = await response.json();
|
|
1584
|
+
} else {
|
|
1585
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
1586
|
+
payload = { image: buffer.toString("base64") };
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
const images = await normalizeProviderImagePayload(payload, body, log);
|
|
1590
|
+
return saveImageSuccessResult({
|
|
1591
|
+
provider,
|
|
1592
|
+
model,
|
|
1593
|
+
startTime,
|
|
1594
|
+
requestBody: upstreamBody,
|
|
1595
|
+
responseBody: { images_count: images.length },
|
|
1596
|
+
created: payload.created,
|
|
1597
|
+
images,
|
|
1598
|
+
});
|
|
1599
|
+
} catch (err) {
|
|
1600
|
+
if (log) log.error("IMAGE", `${provider} fetch error: ${err.message}`);
|
|
1601
|
+
return saveImageErrorResult({
|
|
1602
|
+
provider,
|
|
1603
|
+
model,
|
|
1604
|
+
status: 502,
|
|
1605
|
+
startTime,
|
|
1606
|
+
error: `Image provider error: ${sanitizeErrorMessage((err as Error).message || err)}`,
|
|
1607
|
+
});
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
async function handleBlackForestLabsImageGeneration({
|
|
1612
|
+
model,
|
|
1613
|
+
provider,
|
|
1614
|
+
providerConfig,
|
|
1615
|
+
body,
|
|
1616
|
+
credentials,
|
|
1617
|
+
log,
|
|
1618
|
+
}) {
|
|
1619
|
+
const startTime = Date.now();
|
|
1620
|
+
const token = credentials.apiKey || credentials.accessToken;
|
|
1621
|
+
const endpoint = BFL_MODEL_ENDPOINTS[model];
|
|
1622
|
+
|
|
1623
|
+
if (!endpoint) {
|
|
1624
|
+
return {
|
|
1625
|
+
success: false,
|
|
1626
|
+
status: 400,
|
|
1627
|
+
error: `Unsupported Black Forest Labs image model: ${model}`,
|
|
1628
|
+
};
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
const { imageUrl, maskUrl } = extractImageInputs(body);
|
|
1632
|
+
const upstreamBody: Record<string, unknown> = {
|
|
1633
|
+
prompt: body.prompt,
|
|
1634
|
+
output_format: normalizeRequestedImageFormat(body, "png"),
|
|
1635
|
+
};
|
|
1636
|
+
|
|
1637
|
+
try {
|
|
1638
|
+
if (BFL_EDIT_MODELS.has(model) && imageUrl) {
|
|
1639
|
+
upstreamBody.input_image = (await resolveImageSource(imageUrl)).base64;
|
|
1640
|
+
} else if (imageUrl && isHttpUrl(imageUrl)) {
|
|
1641
|
+
upstreamBody.image_url = imageUrl;
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
if (maskUrl && (model === "flux-pro-1.0-fill" || model === "flux-kontext-pro")) {
|
|
1645
|
+
upstreamBody.mask = (await resolveImageSource(maskUrl)).base64;
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1648
|
+
if (model === "flux-kontext-pro" || model === "flux-kontext-max") {
|
|
1649
|
+
upstreamBody.aspect_ratio = body.aspect_ratio || mapImageSize(body.size);
|
|
1650
|
+
} else if (typeof body.size === "string" && body.size.includes("x")) {
|
|
1651
|
+
const { width, height } = parseSizeToDimensions(body.size, 1024);
|
|
1652
|
+
upstreamBody.width = width;
|
|
1653
|
+
upstreamBody.height = height;
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
if (body.seed !== undefined) upstreamBody.seed = body.seed;
|
|
1657
|
+
if (body.n !== undefined && model.includes("ultra"))
|
|
1658
|
+
upstreamBody.num_images = Number(body.n) || 1;
|
|
1659
|
+
if (body.quality === "hd" && model.includes("ultra")) upstreamBody.raw = true;
|
|
1660
|
+
if (body.left !== undefined) upstreamBody.left = body.left;
|
|
1661
|
+
if (body.right !== undefined) upstreamBody.right = body.right;
|
|
1662
|
+
if (body.top !== undefined) upstreamBody.top = body.top;
|
|
1663
|
+
if (body.bottom !== undefined) upstreamBody.bottom = body.bottom;
|
|
1664
|
+
if (body.steps !== undefined) upstreamBody.steps = body.steps;
|
|
1665
|
+
if (body.guidance !== undefined) upstreamBody.guidance = body.guidance;
|
|
1666
|
+
if (body.grow_mask !== undefined) upstreamBody.grow_mask = body.grow_mask;
|
|
1667
|
+
if (body.safety_tolerance !== undefined) upstreamBody.safety_tolerance = body.safety_tolerance;
|
|
1668
|
+
|
|
1669
|
+
if (log) {
|
|
1670
|
+
const promptPreview = String(body.prompt ?? "").slice(0, 60);
|
|
1671
|
+
log.info("IMAGE", `${provider}/${model} (black-forest-labs) | prompt: "${promptPreview}..."`);
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
const response = await fetch(`${providerConfig.baseUrl.replace(/\/$/, "")}${endpoint}`, {
|
|
1675
|
+
method: "POST",
|
|
1676
|
+
headers: {
|
|
1677
|
+
"Content-Type": "application/json",
|
|
1678
|
+
Accept: "application/json",
|
|
1679
|
+
"x-key": token,
|
|
1680
|
+
},
|
|
1681
|
+
body: JSON.stringify(upstreamBody),
|
|
1682
|
+
});
|
|
1683
|
+
|
|
1684
|
+
if (!response.ok) {
|
|
1685
|
+
const errorText = await response.text();
|
|
1686
|
+
if (log)
|
|
1687
|
+
log.error("IMAGE", `${provider} error ${response.status}: ${errorText.slice(0, 200)}`);
|
|
1688
|
+
return saveImageErrorResult({
|
|
1689
|
+
provider,
|
|
1690
|
+
model,
|
|
1691
|
+
status: response.status,
|
|
1692
|
+
startTime,
|
|
1693
|
+
error: errorText,
|
|
1694
|
+
requestBody: upstreamBody,
|
|
1695
|
+
});
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
const initialPayload = await response.json();
|
|
1699
|
+
const finalPayload = initialPayload.polling_url
|
|
1700
|
+
? await pollBlackForestLabsResult({
|
|
1701
|
+
pollingUrl: initialPayload.polling_url,
|
|
1702
|
+
token,
|
|
1703
|
+
body,
|
|
1704
|
+
log,
|
|
1705
|
+
})
|
|
1706
|
+
: initialPayload;
|
|
1707
|
+
|
|
1708
|
+
const images = await normalizeProviderImagePayload(finalPayload, body, log);
|
|
1709
|
+
return saveImageSuccessResult({
|
|
1710
|
+
provider,
|
|
1711
|
+
model,
|
|
1712
|
+
startTime,
|
|
1713
|
+
requestBody: upstreamBody,
|
|
1714
|
+
responseBody: { images_count: images.length },
|
|
1715
|
+
created: finalPayload.created,
|
|
1716
|
+
images,
|
|
1717
|
+
});
|
|
1718
|
+
} catch (err) {
|
|
1719
|
+
if (log) log.error("IMAGE", `${provider} fetch error: ${err.message}`);
|
|
1720
|
+
return saveImageErrorResult({
|
|
1721
|
+
provider,
|
|
1722
|
+
model,
|
|
1723
|
+
status: 502,
|
|
1724
|
+
startTime,
|
|
1725
|
+
error: `Image provider error: ${sanitizeErrorMessage((err as Error).message || err)}`,
|
|
1726
|
+
});
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
async function handleRecraftImageGeneration({
|
|
1731
|
+
model,
|
|
1732
|
+
provider,
|
|
1733
|
+
providerConfig,
|
|
1734
|
+
body,
|
|
1735
|
+
credentials,
|
|
1736
|
+
log,
|
|
1737
|
+
}) {
|
|
1738
|
+
const startTime = Date.now();
|
|
1739
|
+
const token = credentials.apiKey || credentials.accessToken;
|
|
1740
|
+
const upstreamBody: Record<string, unknown> = {
|
|
1741
|
+
model,
|
|
1742
|
+
prompt: body.prompt,
|
|
1743
|
+
};
|
|
1744
|
+
|
|
1745
|
+
if (body.n !== undefined) upstreamBody.n = body.n;
|
|
1746
|
+
if (body.size !== undefined) upstreamBody.size = body.size;
|
|
1747
|
+
if (body.response_format !== undefined) upstreamBody.response_format = body.response_format;
|
|
1748
|
+
if (body.style !== undefined) upstreamBody.style = body.style;
|
|
1749
|
+
|
|
1750
|
+
if (log) {
|
|
1751
|
+
const promptPreview = String(body.prompt ?? "").slice(0, 60);
|
|
1752
|
+
log.info("IMAGE", `${provider}/${model} (recraft) | prompt: "${promptPreview}..."`);
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
try {
|
|
1756
|
+
const response = await fetch(
|
|
1757
|
+
`${providerConfig.baseUrl.replace(/\/$/, "")}/v1/images/generations`,
|
|
1758
|
+
{
|
|
1759
|
+
method: "POST",
|
|
1760
|
+
headers: {
|
|
1761
|
+
"Content-Type": "application/json",
|
|
1762
|
+
Authorization: `Bearer ${token}`,
|
|
1763
|
+
},
|
|
1764
|
+
body: JSON.stringify(upstreamBody),
|
|
1765
|
+
}
|
|
1766
|
+
);
|
|
1767
|
+
|
|
1768
|
+
if (!response.ok) {
|
|
1769
|
+
const errorText = await response.text();
|
|
1770
|
+
if (log)
|
|
1771
|
+
log.error("IMAGE", `${provider} error ${response.status}: ${errorText.slice(0, 200)}`);
|
|
1772
|
+
return saveImageErrorResult({
|
|
1773
|
+
provider,
|
|
1774
|
+
model,
|
|
1775
|
+
status: response.status,
|
|
1776
|
+
startTime,
|
|
1777
|
+
error: errorText,
|
|
1778
|
+
requestBody: upstreamBody,
|
|
1779
|
+
});
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
const payload = await response.json();
|
|
1783
|
+
const images = await normalizeProviderImagePayload(payload, body, log);
|
|
1784
|
+
return saveImageSuccessResult({
|
|
1785
|
+
provider,
|
|
1786
|
+
model,
|
|
1787
|
+
startTime,
|
|
1788
|
+
requestBody: upstreamBody,
|
|
1789
|
+
responseBody: { images_count: images.length },
|
|
1790
|
+
created: payload.created,
|
|
1791
|
+
images,
|
|
1792
|
+
});
|
|
1793
|
+
} catch (err) {
|
|
1794
|
+
if (log) log.error("IMAGE", `${provider} fetch error: ${err.message}`);
|
|
1795
|
+
return saveImageErrorResult({
|
|
1796
|
+
provider,
|
|
1797
|
+
model,
|
|
1798
|
+
status: 502,
|
|
1799
|
+
startTime,
|
|
1800
|
+
error: `Image provider error: ${sanitizeErrorMessage((err as Error).message || err)}`,
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1805
|
+
async function handleTopazImageGeneration({
|
|
1806
|
+
model,
|
|
1807
|
+
provider,
|
|
1808
|
+
providerConfig,
|
|
1809
|
+
body,
|
|
1810
|
+
credentials,
|
|
1811
|
+
log,
|
|
1812
|
+
}) {
|
|
1813
|
+
const startTime = Date.now();
|
|
1814
|
+
const token = credentials.apiKey || credentials.accessToken;
|
|
1815
|
+
const { imageUrl } = extractImageInputs(body);
|
|
1816
|
+
|
|
1817
|
+
if (!imageUrl) {
|
|
1818
|
+
return {
|
|
1819
|
+
success: false,
|
|
1820
|
+
status: 400,
|
|
1821
|
+
error: `Topaz model ${model} requires an input image`,
|
|
1822
|
+
};
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
try {
|
|
1826
|
+
const imageSource = await resolveImageSource(imageUrl);
|
|
1827
|
+
const formData = new FormData();
|
|
1828
|
+
const blob = new Blob([imageSource.buffer], { type: imageSource.contentType || "image/png" });
|
|
1829
|
+
formData.append("image", blob, "image.png");
|
|
1830
|
+
|
|
1831
|
+
if (typeof body.size === "string" && body.size.includes("x")) {
|
|
1832
|
+
const { width, height } = parseSizeToDimensions(body.size, 1024);
|
|
1833
|
+
formData.append("output_width", String(width));
|
|
1834
|
+
formData.append("output_height", String(height));
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
if (log) {
|
|
1838
|
+
const promptPreview = String(body.prompt ?? "enhance image").slice(0, 60);
|
|
1839
|
+
log.info("IMAGE", `${provider}/${model} (topaz) | prompt: "${promptPreview}..."`);
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
const response = await fetch(`${providerConfig.baseUrl.replace(/\/$/, "")}/image/v1/enhance`, {
|
|
1843
|
+
method: "POST",
|
|
1844
|
+
headers: {
|
|
1845
|
+
Accept: "image/jpeg",
|
|
1846
|
+
"X-API-Key": token,
|
|
1847
|
+
},
|
|
1848
|
+
body: formData,
|
|
1849
|
+
});
|
|
1850
|
+
|
|
1851
|
+
if (!response.ok) {
|
|
1852
|
+
const errorText = await response.text();
|
|
1853
|
+
if (log)
|
|
1854
|
+
log.error("IMAGE", `${provider} error ${response.status}: ${errorText.slice(0, 200)}`);
|
|
1855
|
+
return saveImageErrorResult({
|
|
1856
|
+
provider,
|
|
1857
|
+
model,
|
|
1858
|
+
status: response.status,
|
|
1859
|
+
startTime,
|
|
1860
|
+
error: errorText,
|
|
1861
|
+
});
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
const contentType = response.headers.get("content-type") || "image/jpeg";
|
|
1865
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
1866
|
+
const base64 = buffer.toString("base64");
|
|
1867
|
+
const wantsBase64 = body.response_format === "b64_json";
|
|
1868
|
+
const images = [
|
|
1869
|
+
wantsBase64
|
|
1870
|
+
? { b64_json: base64, revised_prompt: body.prompt }
|
|
1871
|
+
: { url: `data:${contentType};base64,${base64}`, revised_prompt: body.prompt },
|
|
1872
|
+
];
|
|
1873
|
+
|
|
1874
|
+
return saveImageSuccessResult({
|
|
1875
|
+
provider,
|
|
1876
|
+
model,
|
|
1877
|
+
startTime,
|
|
1878
|
+
responseBody: { images_count: images.length },
|
|
1879
|
+
images,
|
|
1880
|
+
});
|
|
1881
|
+
} catch (err) {
|
|
1882
|
+
if (log) log.error("IMAGE", `${provider} fetch error: ${err.message}`);
|
|
1883
|
+
return saveImageErrorResult({
|
|
1884
|
+
provider,
|
|
1885
|
+
model,
|
|
1886
|
+
status: 502,
|
|
1887
|
+
startTime,
|
|
1888
|
+
error: `Image provider error: ${sanitizeErrorMessage((err as Error).message || err)}`,
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
async function pollBlackForestLabsResult({ pollingUrl, token, body, log }) {
|
|
1894
|
+
const timeoutMs = normalizePositiveNumber(body.timeout_ms, 300000);
|
|
1895
|
+
const pollIntervalMs = normalizePositiveNumber(body.poll_interval_ms, 1500);
|
|
1896
|
+
const deadline = Date.now() + timeoutMs;
|
|
1897
|
+
|
|
1898
|
+
while (Date.now() < deadline) {
|
|
1899
|
+
const response = await fetch(pollingUrl, {
|
|
1900
|
+
method: "GET",
|
|
1901
|
+
headers: {
|
|
1902
|
+
"x-key": token,
|
|
1903
|
+
},
|
|
1904
|
+
});
|
|
1905
|
+
|
|
1906
|
+
if (!response.ok) {
|
|
1907
|
+
const errorText = await response.text();
|
|
1908
|
+
throw new Error(`BFL polling failed (${response.status}): ${errorText}`);
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
const payload = await response.json();
|
|
1912
|
+
const status = payload?.status;
|
|
1913
|
+
|
|
1914
|
+
if (status === "Ready") {
|
|
1915
|
+
return payload;
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
if (BFL_FAILURE_STATUSES.has(status)) {
|
|
1919
|
+
throw new Error(`BFL image generation failed: ${status}`);
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
if (log) {
|
|
1923
|
+
log.info("IMAGE", `black-forest-labs polling status: ${String(status || "Pending")}`);
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
await sleep(pollIntervalMs);
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
throw new Error(`BFL polling timed out after ${timeoutMs}ms`);
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
function extractImageInputs(body) {
|
|
1933
|
+
const imageUrls = [];
|
|
1934
|
+
const seen = new Set();
|
|
1935
|
+
|
|
1936
|
+
const pushCandidate = (candidate) => {
|
|
1937
|
+
if (typeof candidate !== "string") return;
|
|
1938
|
+
const trimmed = candidate.trim();
|
|
1939
|
+
if (!trimmed || seen.has(trimmed)) return;
|
|
1940
|
+
seen.add(trimmed);
|
|
1941
|
+
imageUrls.push(trimmed);
|
|
1942
|
+
};
|
|
1943
|
+
|
|
1944
|
+
pushCandidate(body?.image_url);
|
|
1945
|
+
pushCandidate(body?.image);
|
|
1946
|
+
|
|
1947
|
+
if (Array.isArray(body?.imageUrls)) {
|
|
1948
|
+
for (const candidate of body.imageUrls) pushCandidate(candidate);
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
if (Array.isArray(body?.image_urls)) {
|
|
1952
|
+
for (const candidate of body.image_urls) pushCandidate(candidate);
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
if (Array.isArray(body?.messages)) {
|
|
1956
|
+
for (const msg of body.messages) {
|
|
1957
|
+
if (!Array.isArray(msg?.content)) continue;
|
|
1958
|
+
for (const part of msg.content) {
|
|
1959
|
+
if (part?.type === "image_url") {
|
|
1960
|
+
pushCandidate(part?.image_url?.url);
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1966
|
+
return {
|
|
1967
|
+
imageUrl: imageUrls[0] || null,
|
|
1968
|
+
imageUrls,
|
|
1969
|
+
maskUrl:
|
|
1970
|
+
typeof body?.mask_url === "string"
|
|
1971
|
+
? body.mask_url
|
|
1972
|
+
: typeof body?.mask === "string"
|
|
1973
|
+
? body.mask
|
|
1974
|
+
: null,
|
|
1975
|
+
};
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
async function resolveImageSource(source) {
|
|
1979
|
+
if (typeof source !== "string" || source.trim().length === 0) {
|
|
1980
|
+
throw new Error("Invalid image source");
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1983
|
+
const trimmed = source.trim();
|
|
1984
|
+
const dataUriMatch = /^data:([^;]+);base64,(.+)$/i.exec(trimmed);
|
|
1985
|
+
if (dataUriMatch) {
|
|
1986
|
+
const [, contentType, base64] = dataUriMatch;
|
|
1987
|
+
return {
|
|
1988
|
+
buffer: Buffer.from(base64, "base64"),
|
|
1989
|
+
base64,
|
|
1990
|
+
contentType,
|
|
1991
|
+
};
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
if (isHttpUrl(trimmed)) {
|
|
1995
|
+
const remoteImage = await fetchRemoteImage(trimmed);
|
|
1996
|
+
return {
|
|
1997
|
+
buffer: remoteImage.buffer,
|
|
1998
|
+
base64: remoteImage.buffer.toString("base64"),
|
|
1999
|
+
contentType: remoteImage.contentType,
|
|
2000
|
+
};
|
|
2001
|
+
}
|
|
2002
|
+
|
|
2003
|
+
return {
|
|
2004
|
+
buffer: Buffer.from(trimmed, "base64"),
|
|
2005
|
+
base64: trimmed,
|
|
2006
|
+
contentType: "application/octet-stream",
|
|
2007
|
+
};
|
|
2008
|
+
}
|
|
2009
|
+
|
|
2010
|
+
function parseSizeToDimensions(size, fallback = 1024) {
|
|
2011
|
+
if (typeof size !== "string" || !size.includes("x")) {
|
|
2012
|
+
return { width: fallback, height: fallback };
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
const [widthRaw, heightRaw] = size.split("x");
|
|
2016
|
+
const width = Number(widthRaw);
|
|
2017
|
+
const height = Number(heightRaw);
|
|
2018
|
+
return {
|
|
2019
|
+
width: Number.isFinite(width) && width > 0 ? width : fallback,
|
|
2020
|
+
height: Number.isFinite(height) && height > 0 ? height : fallback,
|
|
2021
|
+
};
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
function normalizeRequestedImageFormat(
|
|
2025
|
+
body,
|
|
2026
|
+
fallback = "png",
|
|
2027
|
+
allowedFormats = ["jpeg", "png", "webp"]
|
|
2028
|
+
) {
|
|
2029
|
+
const formatCandidate =
|
|
2030
|
+
typeof body?.output_format === "string"
|
|
2031
|
+
? body.output_format.toLowerCase()
|
|
2032
|
+
: typeof body?.response_format === "string" &&
|
|
2033
|
+
!["url", "b64_json"].includes(body.response_format.toLowerCase())
|
|
2034
|
+
? body.response_format.toLowerCase()
|
|
2035
|
+
: fallback;
|
|
2036
|
+
|
|
2037
|
+
if (allowedFormats.includes(formatCandidate)) {
|
|
2038
|
+
return formatCandidate;
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
return fallback;
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
function mapFalImageSize(size, fallback = "square_hd") {
|
|
2045
|
+
if (typeof size !== "string") return fallback;
|
|
2046
|
+
if (FAL_PRESET_SIZES[size]) return FAL_PRESET_SIZES[size];
|
|
2047
|
+
if (size.includes("x")) {
|
|
2048
|
+
const { width, height } = parseSizeToDimensions(size, 1024);
|
|
2049
|
+
return { width, height };
|
|
2050
|
+
}
|
|
2051
|
+
return fallback;
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
function mapFalAspectRatio(size, fallback = "1:1") {
|
|
2055
|
+
if (!size) return fallback;
|
|
2056
|
+
return mapImageSize(size);
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
function normalizeRecraftStyle(style) {
|
|
2060
|
+
if (style === "vivid") return "digital_illustration";
|
|
2061
|
+
if (style === "natural") return "realistic_image";
|
|
2062
|
+
return style;
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2065
|
+
function shouldIncludeStabilityMask(model) {
|
|
2066
|
+
return new Set([
|
|
2067
|
+
"inpaint",
|
|
2068
|
+
"erase",
|
|
2069
|
+
"search-and-replace",
|
|
2070
|
+
"search-and-recolor",
|
|
2071
|
+
"replace-background-and-relight",
|
|
2072
|
+
]).has(model);
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
async function normalizeProviderImagePayload(payload, body, log) {
|
|
2076
|
+
const candidates = [];
|
|
2077
|
+
|
|
2078
|
+
const pushCandidate = (value) => {
|
|
2079
|
+
if (value === undefined || value === null) return;
|
|
2080
|
+
candidates.push(value);
|
|
2081
|
+
};
|
|
2082
|
+
|
|
2083
|
+
if (Array.isArray(payload?.data)) {
|
|
2084
|
+
for (const item of payload.data) pushCandidate(item);
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2087
|
+
if (Array.isArray(payload?.images)) {
|
|
2088
|
+
for (const item of payload.images) pushCandidate(item);
|
|
2089
|
+
}
|
|
2090
|
+
|
|
2091
|
+
if (payload?.image) pushCandidate({ b64_json: payload.image });
|
|
2092
|
+
if (payload?.url) pushCandidate({ url: payload.url });
|
|
2093
|
+
if (payload?.sample) pushCandidate({ url: payload.sample });
|
|
2094
|
+
if (payload?.result?.sample) pushCandidate({ url: payload.result.sample });
|
|
2095
|
+
if (Array.isArray(payload?.result?.images)) {
|
|
2096
|
+
for (const item of payload.result.images) pushCandidate(item);
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
const normalized = [];
|
|
2100
|
+
for (const candidate of candidates) {
|
|
2101
|
+
const item = await normalizeProviderImageCandidate(candidate, body);
|
|
2102
|
+
if (item) normalized.push(item);
|
|
2103
|
+
}
|
|
2104
|
+
|
|
2105
|
+
if (normalized.length === 0 && log) {
|
|
2106
|
+
log.warn(
|
|
2107
|
+
"IMAGE",
|
|
2108
|
+
`Provider returned no recognizable image payload: ${JSON.stringify(payload).slice(0, 240)}`
|
|
2109
|
+
);
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
return normalized;
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
async function normalizeProviderImageCandidate(candidate, body) {
|
|
2116
|
+
const wantsBase64 = body?.response_format === "b64_json";
|
|
2117
|
+
let url = null;
|
|
2118
|
+
let b64 = null;
|
|
2119
|
+
|
|
2120
|
+
if (typeof candidate === "string") {
|
|
2121
|
+
const dataUriMatch = /^data:[^;]+;base64,(.+)$/i.exec(candidate);
|
|
2122
|
+
if (dataUriMatch) {
|
|
2123
|
+
b64 = dataUriMatch[1];
|
|
2124
|
+
} else if (isHttpUrl(candidate)) {
|
|
2125
|
+
url = candidate;
|
|
2126
|
+
} else {
|
|
2127
|
+
b64 = candidate;
|
|
2128
|
+
}
|
|
2129
|
+
} else if (candidate && typeof candidate === "object") {
|
|
2130
|
+
url =
|
|
2131
|
+
firstString(candidate.url, candidate.image_url, candidate.sample, candidate.file_url) || null;
|
|
2132
|
+
b64 =
|
|
2133
|
+
firstString(candidate.b64_json, candidate.image, candidate.base64, candidate.data) || null;
|
|
2134
|
+
}
|
|
2135
|
+
|
|
2136
|
+
if (wantsBase64 && !b64 && url) {
|
|
2137
|
+
b64 = (await resolveImageSource(url)).base64;
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
if (url && !wantsBase64) {
|
|
2141
|
+
return { url, revised_prompt: body?.prompt };
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
if (b64) {
|
|
2145
|
+
return { b64_json: b64, revised_prompt: body?.prompt };
|
|
2146
|
+
}
|
|
2147
|
+
|
|
2148
|
+
if (url) {
|
|
2149
|
+
return { url, revised_prompt: body?.prompt };
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
return null;
|
|
2153
|
+
}
|
|
2154
|
+
|
|
2155
|
+
function firstString(...values) {
|
|
2156
|
+
for (const value of values) {
|
|
2157
|
+
if (typeof value === "string" && value.length > 0) return value;
|
|
2158
|
+
}
|
|
2159
|
+
return null;
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
function isHttpUrl(value) {
|
|
2163
|
+
return typeof value === "string" && /^https?:\/\//i.test(value);
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
/**
|
|
2167
|
+
* Codex image generation — translate GPT-Image-style /v1/images/generations
|
|
2168
|
+
* request into a /v1/responses call with the `image_generation` hosted tool,
|
|
2169
|
+
* parse the SSE stream, and return the base64 PNG in OpenAI image response shape.
|
|
2170
|
+
*
|
|
2171
|
+
* Requires ChatGPT OAuth credentials (Codex provider connection). The hosted
|
|
2172
|
+
* image_generation tool is only served upstream under ChatGPT auth; API-key
|
|
2173
|
+
* users will receive a 400 from OpenAI.
|
|
2174
|
+
*/
|
|
2175
|
+
export function extractImageGenerationCalls(
|
|
2176
|
+
sseText: string
|
|
2177
|
+
): Array<{ b64: string; revisedPrompt: string | null }> {
|
|
2178
|
+
const results: Array<{ b64: string; revisedPrompt: string | null }> = [];
|
|
2179
|
+
const lines = String(sseText || "").split("\n");
|
|
2180
|
+
for (const line of lines) {
|
|
2181
|
+
const trimmed = line.trim();
|
|
2182
|
+
if (!trimmed.startsWith("data:")) continue;
|
|
2183
|
+
const payload = trimmed.slice(5).trim();
|
|
2184
|
+
if (!payload || payload === "[DONE]") continue;
|
|
2185
|
+
let evt: Record<string, unknown>;
|
|
2186
|
+
try {
|
|
2187
|
+
evt = JSON.parse(payload) as Record<string, unknown>;
|
|
2188
|
+
} catch {
|
|
2189
|
+
continue;
|
|
2190
|
+
}
|
|
2191
|
+
if (evt?.type !== "response.output_item.done") continue;
|
|
2192
|
+
const item = evt.item as Record<string, unknown> | undefined;
|
|
2193
|
+
if (!item || item.type !== "image_generation_call") continue;
|
|
2194
|
+
const result = typeof item.result === "string" ? item.result : "";
|
|
2195
|
+
if (!result) continue;
|
|
2196
|
+
const revisedPrompt = typeof item.revised_prompt === "string" ? item.revised_prompt : null;
|
|
2197
|
+
results.push({ b64: result, revisedPrompt });
|
|
2198
|
+
}
|
|
2199
|
+
return results;
|
|
2200
|
+
}
|
|
2201
|
+
|
|
2202
|
+
// The image_generation hosted tool accepts { "auto" | "low" | "medium" | "high" }
|
|
2203
|
+
// for `quality`. Legacy image clients often send "standard" / "hd". Map those values
|
|
2204
|
+
// so OpenWebUI's quality dropdown doesn't silently get rejected upstream.
|
|
2205
|
+
function mapLegacyImageQualityToImageTool(value: string): string {
|
|
2206
|
+
const normalized = value.toLowerCase();
|
|
2207
|
+
if (normalized === "standard") return "medium";
|
|
2208
|
+
if (normalized === "hd") return "high";
|
|
2209
|
+
return normalized;
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
async function handleCodexImageGeneration({
|
|
2213
|
+
model,
|
|
2214
|
+
provider,
|
|
2215
|
+
providerConfig,
|
|
2216
|
+
body,
|
|
2217
|
+
credentials,
|
|
2218
|
+
log,
|
|
2219
|
+
}) {
|
|
2220
|
+
const startTime = Date.now();
|
|
2221
|
+
const prompt = typeof body.prompt === "string" ? body.prompt : "";
|
|
2222
|
+
if (!prompt.trim()) {
|
|
2223
|
+
return saveImageErrorResult({
|
|
2224
|
+
provider,
|
|
2225
|
+
model,
|
|
2226
|
+
status: 400,
|
|
2227
|
+
startTime,
|
|
2228
|
+
error: "Prompt is required for Codex image generation",
|
|
2229
|
+
});
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
const requestedCount =
|
|
2233
|
+
Number.isInteger(body.n) && (body.n as number) > 0 ? (body.n as number) : 1;
|
|
2234
|
+
if (log && requestedCount > 1) {
|
|
2235
|
+
log.warn(
|
|
2236
|
+
"IMAGE",
|
|
2237
|
+
`Codex hosted image_generation returns one image per call; requested n=${requestedCount} will fan out in parallel`
|
|
2238
|
+
);
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2241
|
+
const token = credentials?.accessToken || credentials?.apiKey;
|
|
2242
|
+
if (!token) {
|
|
2243
|
+
return saveImageErrorResult({
|
|
2244
|
+
provider,
|
|
2245
|
+
model,
|
|
2246
|
+
status: 401,
|
|
2247
|
+
startTime,
|
|
2248
|
+
error: "Codex credentials missing accessToken — reconnect the Codex provider",
|
|
2249
|
+
});
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2252
|
+
const workspaceId =
|
|
2253
|
+
credentials?.providerSpecificData &&
|
|
2254
|
+
typeof credentials.providerSpecificData === "object" &&
|
|
2255
|
+
!Array.isArray(credentials.providerSpecificData)
|
|
2256
|
+
? (credentials.providerSpecificData as Record<string, unknown>).workspaceId
|
|
2257
|
+
: undefined;
|
|
2258
|
+
|
|
2259
|
+
// Forward size/quality from the GPT-Image-style body into the hosted tool so
|
|
2260
|
+
// OpenWebUI's size/quality selectors actually take effect. Everything else
|
|
2261
|
+
// (model, n, background, moderation, output_compression) is left to the
|
|
2262
|
+
// Codex backend's defaults — today that's `gpt-image-2`.
|
|
2263
|
+
const toolConfig: Record<string, unknown> = { type: "image_generation", output_format: "png" };
|
|
2264
|
+
if (typeof body.size === "string" && body.size.trim()) {
|
|
2265
|
+
toolConfig.size = body.size.trim();
|
|
2266
|
+
}
|
|
2267
|
+
if (typeof body.quality === "string" && body.quality.trim()) {
|
|
2268
|
+
toolConfig.quality = mapLegacyImageQualityToImageTool(body.quality.trim());
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
const upstreamBody: Record<string, unknown> = {
|
|
2272
|
+
model,
|
|
2273
|
+
instructions:
|
|
2274
|
+
"You must call the image_generation tool exactly once to fulfill the user's request. Do not add narration.",
|
|
2275
|
+
input: [
|
|
2276
|
+
{
|
|
2277
|
+
role: "user",
|
|
2278
|
+
content: [{ type: "input_text", text: prompt }],
|
|
2279
|
+
},
|
|
2280
|
+
],
|
|
2281
|
+
tools: [toolConfig],
|
|
2282
|
+
stream: true,
|
|
2283
|
+
store: false,
|
|
2284
|
+
};
|
|
2285
|
+
|
|
2286
|
+
const headers: Record<string, string> = {
|
|
2287
|
+
"Content-Type": "application/json",
|
|
2288
|
+
Accept: "text/event-stream",
|
|
2289
|
+
Authorization: `Bearer ${token}`,
|
|
2290
|
+
Version: getCodexClientVersion(),
|
|
2291
|
+
"User-Agent": getCodexUserAgent(),
|
|
2292
|
+
originator: "codex_cli_rs",
|
|
2293
|
+
};
|
|
2294
|
+
if (typeof workspaceId === "string" && workspaceId) {
|
|
2295
|
+
headers["chatgpt-account-id"] = workspaceId;
|
|
2296
|
+
headers["session_id"] = workspaceId;
|
|
2297
|
+
}
|
|
2298
|
+
|
|
2299
|
+
if (log) {
|
|
2300
|
+
log.info(
|
|
2301
|
+
"IMAGE",
|
|
2302
|
+
`${provider}/${model} (codex-responses) | prompt: "${prompt.slice(0, 60)}..."`
|
|
2303
|
+
);
|
|
2304
|
+
}
|
|
2305
|
+
|
|
2306
|
+
const fetchOneImage = async () => {
|
|
2307
|
+
let response: Response;
|
|
2308
|
+
try {
|
|
2309
|
+
response = await fetch(providerConfig.baseUrl, {
|
|
2310
|
+
method: "POST",
|
|
2311
|
+
headers,
|
|
2312
|
+
body: JSON.stringify(upstreamBody),
|
|
2313
|
+
});
|
|
2314
|
+
} catch (err) {
|
|
2315
|
+
if (log) log.error("IMAGE", `${provider} fetch error: ${(err as Error).message}`);
|
|
2316
|
+
return {
|
|
2317
|
+
ok: false as const,
|
|
2318
|
+
error: {
|
|
2319
|
+
provider,
|
|
2320
|
+
model,
|
|
2321
|
+
status: 502,
|
|
2322
|
+
startTime,
|
|
2323
|
+
error: `Image provider error: ${(err as Error).message}`,
|
|
2324
|
+
requestBody: upstreamBody,
|
|
2325
|
+
},
|
|
2326
|
+
};
|
|
2327
|
+
}
|
|
2328
|
+
|
|
2329
|
+
if (!response.ok) {
|
|
2330
|
+
const errorText = await response.text();
|
|
2331
|
+
if (log)
|
|
2332
|
+
log.error("IMAGE", `${provider} error ${response.status}: ${errorText.slice(0, 200)}`);
|
|
2333
|
+
return {
|
|
2334
|
+
ok: false as const,
|
|
2335
|
+
error: {
|
|
2336
|
+
provider,
|
|
2337
|
+
model,
|
|
2338
|
+
status: response.status,
|
|
2339
|
+
startTime,
|
|
2340
|
+
error: errorText,
|
|
2341
|
+
requestBody: upstreamBody,
|
|
2342
|
+
},
|
|
2343
|
+
};
|
|
2344
|
+
}
|
|
2345
|
+
|
|
2346
|
+
const rawSSE = await response.text();
|
|
2347
|
+
const items = extractImageGenerationCalls(rawSSE);
|
|
2348
|
+
if (items.length === 0) {
|
|
2349
|
+
return {
|
|
2350
|
+
ok: false as const,
|
|
2351
|
+
error: {
|
|
2352
|
+
provider,
|
|
2353
|
+
model,
|
|
2354
|
+
status: 502,
|
|
2355
|
+
startTime,
|
|
2356
|
+
error:
|
|
2357
|
+
"Codex completed without producing an image_generation_call — the model may have declined the tool",
|
|
2358
|
+
requestBody: upstreamBody,
|
|
2359
|
+
},
|
|
2360
|
+
};
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2363
|
+
return { ok: true as const, items };
|
|
2364
|
+
};
|
|
2365
|
+
|
|
2366
|
+
const imageResults = await Promise.all(
|
|
2367
|
+
Array.from({ length: requestedCount }, () => fetchOneImage())
|
|
2368
|
+
);
|
|
2369
|
+
|
|
2370
|
+
const collected: Array<{ b64_json: string; revised_prompt?: string }> = [];
|
|
2371
|
+
for (const imageResult of imageResults) {
|
|
2372
|
+
if (!imageResult.ok) return saveImageErrorResult(imageResult.error);
|
|
2373
|
+
for (const item of imageResult.items) {
|
|
2374
|
+
collected.push({
|
|
2375
|
+
b64_json: item.b64,
|
|
2376
|
+
...(item.revisedPrompt ? { revised_prompt: item.revisedPrompt } : {}),
|
|
2377
|
+
});
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2380
|
+
|
|
2381
|
+
const wantsUrl = body.response_format !== "b64_json";
|
|
2382
|
+
const data = wantsUrl
|
|
2383
|
+
? collected.map((item) => ({
|
|
2384
|
+
url: `data:image/png;base64,${item.b64_json}`,
|
|
2385
|
+
...(item.revised_prompt ? { revised_prompt: item.revised_prompt } : {}),
|
|
2386
|
+
}))
|
|
2387
|
+
: collected;
|
|
2388
|
+
|
|
2389
|
+
return saveImageSuccessResult({
|
|
2390
|
+
provider,
|
|
2391
|
+
model,
|
|
2392
|
+
startTime,
|
|
2393
|
+
requestBody: upstreamBody,
|
|
2394
|
+
responseBody: { images_count: data.length },
|
|
2395
|
+
images: data,
|
|
2396
|
+
});
|
|
2397
|
+
}
|
|
2398
|
+
|
|
2399
|
+
export function saveImageSuccessResult({
|
|
2400
|
+
provider,
|
|
2401
|
+
model,
|
|
2402
|
+
startTime,
|
|
2403
|
+
requestBody = null,
|
|
2404
|
+
responseBody = null,
|
|
2405
|
+
created = null,
|
|
2406
|
+
images,
|
|
2407
|
+
}) {
|
|
2408
|
+
saveCallLog({
|
|
2409
|
+
method: "POST",
|
|
2410
|
+
path: "/v1/images/generations",
|
|
2411
|
+
status: 200,
|
|
2412
|
+
model: `${provider}/${model}`,
|
|
2413
|
+
provider,
|
|
2414
|
+
duration: Date.now() - startTime,
|
|
2415
|
+
requestBody,
|
|
2416
|
+
responseBody,
|
|
2417
|
+
}).catch(() => {});
|
|
2418
|
+
|
|
2419
|
+
return {
|
|
2420
|
+
success: true,
|
|
2421
|
+
data: {
|
|
2422
|
+
created: created || Math.floor(Date.now() / 1000),
|
|
2423
|
+
data: images,
|
|
2424
|
+
},
|
|
2425
|
+
};
|
|
2426
|
+
}
|
|
2427
|
+
|
|
2428
|
+
export function saveImageErrorResult({ provider, model, status, startTime, error, requestBody = null }) {
|
|
2429
|
+
saveCallLog({
|
|
2430
|
+
method: "POST",
|
|
2431
|
+
path: "/v1/images/generations",
|
|
2432
|
+
status,
|
|
2433
|
+
model: `${provider}/${model}`,
|
|
2434
|
+
provider,
|
|
2435
|
+
duration: Date.now() - startTime,
|
|
2436
|
+
error: typeof error === "string" ? error.slice(0, 500) : String(error).slice(0, 500),
|
|
2437
|
+
requestBody,
|
|
2438
|
+
}).catch(() => {});
|
|
2439
|
+
|
|
2440
|
+
return {
|
|
2441
|
+
success: false,
|
|
2442
|
+
status,
|
|
2443
|
+
error,
|
|
2444
|
+
};
|
|
2445
|
+
}
|
|
2446
|
+
|
|
2447
|
+
/**
|
|
2448
|
+
* Fetch a single image endpoint and normalize response
|
|
2449
|
+
*/
|
|
2450
|
+
async function fetchImageEndpoint(url, headers, body, provider, log) {
|
|
2451
|
+
try {
|
|
2452
|
+
let response;
|
|
2453
|
+
try {
|
|
2454
|
+
response = await fetchWithTimeout(url, {
|
|
2455
|
+
method: "POST",
|
|
2456
|
+
headers,
|
|
2457
|
+
body,
|
|
2458
|
+
timeoutMs: getConfiguredTimeout(),
|
|
2459
|
+
});
|
|
2460
|
+
} catch (err: unknown) {
|
|
2461
|
+
const isAbortError =
|
|
2462
|
+
typeof err === "object" &&
|
|
2463
|
+
err !== null &&
|
|
2464
|
+
"name" in err &&
|
|
2465
|
+
(err as { name?: unknown }).name === "AbortError";
|
|
2466
|
+
if (err instanceof FetchTimeoutError || isAbortError) {
|
|
2467
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
2468
|
+
if (log) {
|
|
2469
|
+
log.error("IMAGE", `${provider} fetch error: ${message}`);
|
|
2470
|
+
}
|
|
2471
|
+
return {
|
|
2472
|
+
success: false,
|
|
2473
|
+
status: 504,
|
|
2474
|
+
error: `Image provider error: ${sanitizeErrorMessage(message || err)}`,
|
|
2475
|
+
};
|
|
2476
|
+
}
|
|
2477
|
+
throw err;
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
if (!response.ok) {
|
|
2481
|
+
const errorText = await response.text();
|
|
2482
|
+
if (log) {
|
|
2483
|
+
log.error("IMAGE", `${provider} error ${response.status}: ${errorText.slice(0, 200)}`);
|
|
2484
|
+
}
|
|
2485
|
+
return {
|
|
2486
|
+
success: false,
|
|
2487
|
+
status: response.status,
|
|
2488
|
+
error: errorText,
|
|
2489
|
+
};
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2492
|
+
const data = await response.json();
|
|
2493
|
+
|
|
2494
|
+
// Normalize response to OpenAI format
|
|
2495
|
+
return {
|
|
2496
|
+
success: true,
|
|
2497
|
+
data: {
|
|
2498
|
+
created: data.created || Math.floor(Date.now() / 1000),
|
|
2499
|
+
data: data.data || [],
|
|
2500
|
+
},
|
|
2501
|
+
};
|
|
2502
|
+
} catch (err: unknown) {
|
|
2503
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
2504
|
+
if (log) {
|
|
2505
|
+
log.error("IMAGE", `${provider} fetch error: ${message}`);
|
|
2506
|
+
}
|
|
2507
|
+
return {
|
|
2508
|
+
success: false,
|
|
2509
|
+
status: 502,
|
|
2510
|
+
error: `Image provider error: ${sanitizeErrorMessage(message || err)}`,
|
|
2511
|
+
};
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
|
|
2515
|
+
/**
|
|
2516
|
+
* Handle Hyperbolic image generation
|
|
2517
|
+
* Uses { model_name, prompt, height, width } and returns { images: [{ image: base64 }] }
|
|
2518
|
+
*/
|
|
2519
|
+
async function handleNanoBananaImageGeneration({
|
|
2520
|
+
model,
|
|
2521
|
+
provider,
|
|
2522
|
+
providerConfig,
|
|
2523
|
+
body,
|
|
2524
|
+
credentials,
|
|
2525
|
+
log,
|
|
2526
|
+
}) {
|
|
2527
|
+
const startTime = Date.now();
|
|
2528
|
+
const token = credentials.apiKey || credentials.accessToken;
|
|
2529
|
+
|
|
2530
|
+
// Route to pro URL for "nanobanana-pro" model
|
|
2531
|
+
const isPro = model === "nanobanana-pro";
|
|
2532
|
+
const submitUrl = isPro && providerConfig.proUrl ? providerConfig.proUrl : providerConfig.baseUrl;
|
|
2533
|
+
const statusUrl = providerConfig.statusUrl;
|
|
2534
|
+
|
|
2535
|
+
const aspectRatio =
|
|
2536
|
+
typeof body.aspectRatio === "string"
|
|
2537
|
+
? body.aspectRatio
|
|
2538
|
+
: typeof body.aspect_ratio === "string"
|
|
2539
|
+
? body.aspect_ratio
|
|
2540
|
+
: mapImageSize(body.size);
|
|
2541
|
+
|
|
2542
|
+
let resolution =
|
|
2543
|
+
typeof body.resolution === "string"
|
|
2544
|
+
? body.resolution
|
|
2545
|
+
: inferResolutionFromSize(body.size) || "1K";
|
|
2546
|
+
if (body.quality === "hd" && resolution === "1K") {
|
|
2547
|
+
resolution = "2K";
|
|
2548
|
+
}
|
|
2549
|
+
|
|
2550
|
+
const upstreamBody = isPro
|
|
2551
|
+
? {
|
|
2552
|
+
prompt: body.prompt,
|
|
2553
|
+
resolution,
|
|
2554
|
+
aspectRatio,
|
|
2555
|
+
...(Array.isArray(body.imageUrls) ? { imageUrls: body.imageUrls } : {}),
|
|
2556
|
+
}
|
|
2557
|
+
: {
|
|
2558
|
+
prompt: body.prompt,
|
|
2559
|
+
type:
|
|
2560
|
+
Array.isArray(body.imageUrls) && body.imageUrls.length > 0
|
|
2561
|
+
? "IMAGETOIAMGE"
|
|
2562
|
+
: "TEXTTOIAMGE",
|
|
2563
|
+
numImages: Number.isFinite(body.n) ? Math.max(1, Number(body.n)) : 1,
|
|
2564
|
+
image_size: aspectRatio,
|
|
2565
|
+
...(Array.isArray(body.imageUrls) ? { imageUrls: body.imageUrls } : {}),
|
|
2566
|
+
};
|
|
2567
|
+
|
|
2568
|
+
if (log) {
|
|
2569
|
+
const promptPreview = String(body.prompt ?? "").slice(0, 60);
|
|
2570
|
+
log.info(
|
|
2571
|
+
"IMAGE",
|
|
2572
|
+
`${provider}/${model} (nanobanana ${isPro ? "pro" : "flash"}) | prompt: "${promptPreview}..."`
|
|
2573
|
+
);
|
|
2574
|
+
}
|
|
2575
|
+
|
|
2576
|
+
try {
|
|
2577
|
+
const submitResp = await fetch(submitUrl, {
|
|
2578
|
+
method: "POST",
|
|
2579
|
+
headers: {
|
|
2580
|
+
"Content-Type": "application/json",
|
|
2581
|
+
Authorization: `Bearer ${token}`,
|
|
2582
|
+
},
|
|
2583
|
+
body: JSON.stringify(upstreamBody),
|
|
2584
|
+
});
|
|
2585
|
+
|
|
2586
|
+
if (!submitResp.ok) {
|
|
2587
|
+
const errorText = await submitResp.text();
|
|
2588
|
+
if (log) {
|
|
2589
|
+
log.error(
|
|
2590
|
+
"IMAGE",
|
|
2591
|
+
`${provider} submit error ${submitResp.status}: ${errorText.slice(0, 200)}`
|
|
2592
|
+
);
|
|
2593
|
+
}
|
|
2594
|
+
|
|
2595
|
+
saveCallLog({
|
|
2596
|
+
method: "POST",
|
|
2597
|
+
path: "/v1/images/generations",
|
|
2598
|
+
status: submitResp.status,
|
|
2599
|
+
model: `${provider}/${model}`,
|
|
2600
|
+
provider,
|
|
2601
|
+
duration: Date.now() - startTime,
|
|
2602
|
+
error: errorText.slice(0, 500),
|
|
2603
|
+
}).catch(() => {});
|
|
2604
|
+
|
|
2605
|
+
return { success: false, status: submitResp.status, error: errorText };
|
|
2606
|
+
}
|
|
2607
|
+
|
|
2608
|
+
const submitData = await submitResp.json();
|
|
2609
|
+
|
|
2610
|
+
// Backward compatibility: handle providers returning image payload synchronously
|
|
2611
|
+
const hasSyncPayload =
|
|
2612
|
+
Boolean(submitData?.image) ||
|
|
2613
|
+
Array.isArray(submitData?.images) ||
|
|
2614
|
+
Array.isArray(submitData?.data) ||
|
|
2615
|
+
Boolean(submitData?.data?.[0]?.url) ||
|
|
2616
|
+
Boolean(submitData?.data?.[0]?.b64_json);
|
|
2617
|
+
|
|
2618
|
+
if (hasSyncPayload) {
|
|
2619
|
+
const syncResult = normalizeNanoBananaSyncPayload(submitData, body.prompt);
|
|
2620
|
+
saveCallLog({
|
|
2621
|
+
method: "POST",
|
|
2622
|
+
path: "/v1/images/generations",
|
|
2623
|
+
status: 200,
|
|
2624
|
+
model: `${provider}/${model}`,
|
|
2625
|
+
provider,
|
|
2626
|
+
duration: Date.now() - startTime,
|
|
2627
|
+
responseBody: { images_count: syncResult.data?.length || 0, mode: "sync" },
|
|
2628
|
+
}).catch(() => {});
|
|
2629
|
+
return {
|
|
2630
|
+
success: true,
|
|
2631
|
+
data: { created: Math.floor(Date.now() / 1000), data: syncResult.data },
|
|
2632
|
+
};
|
|
2633
|
+
}
|
|
2634
|
+
|
|
2635
|
+
const taskId = submitData?.data?.taskId || submitData?.taskId;
|
|
2636
|
+
if (!taskId) {
|
|
2637
|
+
const errorText = `NanoBanana submit did not return taskId: ${JSON.stringify(submitData).slice(0, 400)}`;
|
|
2638
|
+
saveCallLog({
|
|
2639
|
+
method: "POST",
|
|
2640
|
+
path: "/v1/images/generations",
|
|
2641
|
+
status: 502,
|
|
2642
|
+
model: `${provider}/${model}`,
|
|
2643
|
+
provider,
|
|
2644
|
+
duration: Date.now() - startTime,
|
|
2645
|
+
error: errorText,
|
|
2646
|
+
}).catch(() => {});
|
|
2647
|
+
return { success: false, status: 502, error: errorText };
|
|
2648
|
+
}
|
|
2649
|
+
|
|
2650
|
+
if (!statusUrl) {
|
|
2651
|
+
const errorText = "NanoBanana statusUrl is not configured";
|
|
2652
|
+
saveCallLog({
|
|
2653
|
+
method: "POST",
|
|
2654
|
+
path: "/v1/images/generations",
|
|
2655
|
+
status: 500,
|
|
2656
|
+
model: `${provider}/${model}`,
|
|
2657
|
+
provider,
|
|
2658
|
+
duration: Date.now() - startTime,
|
|
2659
|
+
error: errorText,
|
|
2660
|
+
}).catch(() => {});
|
|
2661
|
+
return { success: false, status: 500, error: errorText };
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
const timeoutMs = normalizePositiveNumber(
|
|
2665
|
+
body.timeout_ms,
|
|
2666
|
+
normalizePositiveNumber(process.env.NANOBANANA_POLL_TIMEOUT_MS, 120000)
|
|
2667
|
+
);
|
|
2668
|
+
const pollIntervalMs = normalizePositiveNumber(
|
|
2669
|
+
body.poll_interval_ms,
|
|
2670
|
+
normalizePositiveNumber(process.env.NANOBANANA_POLL_INTERVAL_MS, 2500)
|
|
2671
|
+
);
|
|
2672
|
+
|
|
2673
|
+
let lastTaskData = null;
|
|
2674
|
+
const deadline = Date.now() + timeoutMs;
|
|
2675
|
+
|
|
2676
|
+
while (Date.now() < deadline) {
|
|
2677
|
+
const pollResp = await fetch(`${statusUrl}?taskId=${encodeURIComponent(taskId)}`, {
|
|
2678
|
+
method: "GET",
|
|
2679
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
2680
|
+
});
|
|
2681
|
+
|
|
2682
|
+
if (!pollResp.ok) {
|
|
2683
|
+
const errorText = await pollResp.text();
|
|
2684
|
+
if (log) {
|
|
2685
|
+
log.error(
|
|
2686
|
+
"IMAGE",
|
|
2687
|
+
`${provider} poll error ${pollResp.status}: ${errorText.slice(0, 200)}`
|
|
2688
|
+
);
|
|
2689
|
+
}
|
|
2690
|
+
return { success: false, status: pollResp.status, error: errorText };
|
|
2691
|
+
}
|
|
2692
|
+
|
|
2693
|
+
const pollData = await pollResp.json();
|
|
2694
|
+
const taskData = pollData?.data || pollData;
|
|
2695
|
+
lastTaskData = taskData;
|
|
2696
|
+
|
|
2697
|
+
const successFlag = Number(taskData?.successFlag);
|
|
2698
|
+
if (successFlag === 1) {
|
|
2699
|
+
const normalized = await normalizeNanoBananaTaskResult(taskData, body, log);
|
|
2700
|
+
|
|
2701
|
+
saveCallLog({
|
|
2702
|
+
method: "POST",
|
|
2703
|
+
path: "/v1/images/generations",
|
|
2704
|
+
status: 200,
|
|
2705
|
+
model: `${provider}/${model}`,
|
|
2706
|
+
provider,
|
|
2707
|
+
duration: Date.now() - startTime,
|
|
2708
|
+
responseBody: { images_count: normalized.length, mode: "async", taskId },
|
|
2709
|
+
}).catch(() => {});
|
|
2710
|
+
|
|
2711
|
+
return {
|
|
2712
|
+
success: true,
|
|
2713
|
+
data: {
|
|
2714
|
+
created: Math.floor(Date.now() / 1000),
|
|
2715
|
+
data: normalized,
|
|
2716
|
+
},
|
|
2717
|
+
};
|
|
2718
|
+
}
|
|
2719
|
+
|
|
2720
|
+
if (successFlag === 2 || successFlag === 3) {
|
|
2721
|
+
const errorText =
|
|
2722
|
+
taskData?.errorMessage || `NanoBanana task failed (successFlag=${String(successFlag)})`;
|
|
2723
|
+
|
|
2724
|
+
saveCallLog({
|
|
2725
|
+
method: "POST",
|
|
2726
|
+
path: "/v1/images/generations",
|
|
2727
|
+
status: 502,
|
|
2728
|
+
model: `${provider}/${model}`,
|
|
2729
|
+
provider,
|
|
2730
|
+
duration: Date.now() - startTime,
|
|
2731
|
+
error: errorText.slice(0, 500),
|
|
2732
|
+
responseBody: { taskId, successFlag, errorCode: taskData?.errorCode ?? null },
|
|
2733
|
+
}).catch(() => {});
|
|
2734
|
+
|
|
2735
|
+
return { success: false, status: 502, error: errorText };
|
|
2736
|
+
}
|
|
2737
|
+
|
|
2738
|
+
await sleep(pollIntervalMs);
|
|
2739
|
+
}
|
|
2740
|
+
|
|
2741
|
+
const timeoutError = `NanoBanana task timeout after ${timeoutMs}ms (taskId=${taskId}, successFlag=${String(lastTaskData?.successFlag ?? "unknown")})`;
|
|
2742
|
+
saveCallLog({
|
|
2743
|
+
method: "POST",
|
|
2744
|
+
path: "/v1/images/generations",
|
|
2745
|
+
status: 504,
|
|
2746
|
+
model: `${provider}/${model}`,
|
|
2747
|
+
provider,
|
|
2748
|
+
duration: Date.now() - startTime,
|
|
2749
|
+
error: timeoutError,
|
|
2750
|
+
responseBody: { taskId, lastSuccessFlag: lastTaskData?.successFlag ?? null },
|
|
2751
|
+
}).catch(() => {});
|
|
2752
|
+
|
|
2753
|
+
return { success: false, status: 504, error: timeoutError };
|
|
2754
|
+
} catch (err) {
|
|
2755
|
+
if (log) log.error("IMAGE", `${provider} fetch error: ${err.message}`);
|
|
2756
|
+
saveCallLog({
|
|
2757
|
+
method: "POST",
|
|
2758
|
+
path: "/v1/images/generations",
|
|
2759
|
+
status: 502,
|
|
2760
|
+
model: `${provider}/${model}`,
|
|
2761
|
+
provider,
|
|
2762
|
+
duration: Date.now() - startTime,
|
|
2763
|
+
error: err.message,
|
|
2764
|
+
}).catch(() => {});
|
|
2765
|
+
return {
|
|
2766
|
+
success: false,
|
|
2767
|
+
status: 502,
|
|
2768
|
+
error: `Image provider error: ${sanitizeErrorMessage((err as Error).message || err)}`,
|
|
2769
|
+
};
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
|
|
2773
|
+
function normalizeNanoBananaSyncPayload(data, prompt) {
|
|
2774
|
+
const images = [];
|
|
2775
|
+
|
|
2776
|
+
if (data.image) {
|
|
2777
|
+
images.push({ b64_json: data.image, revised_prompt: prompt });
|
|
2778
|
+
} else if (Array.isArray(data.images)) {
|
|
2779
|
+
for (const img of data.images) {
|
|
2780
|
+
images.push({
|
|
2781
|
+
b64_json: typeof img === "string" ? img : img?.image || img?.data,
|
|
2782
|
+
revised_prompt: prompt,
|
|
2783
|
+
});
|
|
2784
|
+
}
|
|
2785
|
+
} else if (Array.isArray(data.data)) {
|
|
2786
|
+
for (const img of data.data) {
|
|
2787
|
+
if (!img) continue;
|
|
2788
|
+
images.push(img);
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
|
|
2792
|
+
return { data: images.filter(Boolean) };
|
|
2793
|
+
}
|
|
2794
|
+
|
|
2795
|
+
async function normalizeNanoBananaTaskResult(taskData, body, log) {
|
|
2796
|
+
const response = taskData?.response || {};
|
|
2797
|
+
|
|
2798
|
+
const urlCandidates = [
|
|
2799
|
+
response?.resultImageUrl,
|
|
2800
|
+
response?.originImageUrl,
|
|
2801
|
+
taskData?.resultImageUrl,
|
|
2802
|
+
taskData?.originImageUrl,
|
|
2803
|
+
].filter((v) => typeof v === "string" && v.length > 0);
|
|
2804
|
+
|
|
2805
|
+
if (Array.isArray(response?.resultImageUrls)) {
|
|
2806
|
+
for (const u of response.resultImageUrls) {
|
|
2807
|
+
if (typeof u === "string" && u.length > 0) urlCandidates.push(u);
|
|
2808
|
+
}
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2811
|
+
const b64Candidates = [
|
|
2812
|
+
response?.resultImageBase64,
|
|
2813
|
+
response?.resultImage,
|
|
2814
|
+
taskData?.resultImageBase64,
|
|
2815
|
+
taskData?.resultImage,
|
|
2816
|
+
].filter((v) => typeof v === "string" && v.length > 0);
|
|
2817
|
+
|
|
2818
|
+
if (Array.isArray(response?.resultImageBase64List)) {
|
|
2819
|
+
for (const b64 of response.resultImageBase64List) {
|
|
2820
|
+
if (typeof b64 === "string" && b64.length > 0) b64Candidates.push(b64);
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
|
|
2824
|
+
const wantsBase64 = body.response_format === "b64_json";
|
|
2825
|
+
|
|
2826
|
+
if (wantsBase64) {
|
|
2827
|
+
if (b64Candidates.length > 0) {
|
|
2828
|
+
return b64Candidates.map((b64) => ({ b64_json: b64, revised_prompt: body.prompt }));
|
|
2829
|
+
}
|
|
2830
|
+
|
|
2831
|
+
if (urlCandidates.length > 0) {
|
|
2832
|
+
const firstUrl = urlCandidates[0];
|
|
2833
|
+
const remoteImage = await fetchRemoteImage(firstUrl);
|
|
2834
|
+
const base64 = remoteImage.buffer.toString("base64");
|
|
2835
|
+
return [{ b64_json: base64, revised_prompt: body.prompt }];
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
|
|
2839
|
+
if (urlCandidates.length > 0) {
|
|
2840
|
+
return urlCandidates.map((url) => ({ url, revised_prompt: body.prompt }));
|
|
2841
|
+
}
|
|
2842
|
+
|
|
2843
|
+
if (b64Candidates.length > 0) {
|
|
2844
|
+
return b64Candidates.map((b64) => ({ b64_json: b64, revised_prompt: body.prompt }));
|
|
2845
|
+
}
|
|
2846
|
+
|
|
2847
|
+
if (log) {
|
|
2848
|
+
log.warn(
|
|
2849
|
+
"IMAGE",
|
|
2850
|
+
`NanoBanana task completed without image payload: ${JSON.stringify(taskData).slice(0, 240)}`
|
|
2851
|
+
);
|
|
2852
|
+
}
|
|
2853
|
+
|
|
2854
|
+
return [];
|
|
2855
|
+
}
|
|
2856
|
+
|
|
2857
|
+
function inferResolutionFromSize(size) {
|
|
2858
|
+
if (typeof size !== "string") return null;
|
|
2859
|
+
const [wRaw, hRaw] = size.split("x");
|
|
2860
|
+
const width = Number(wRaw);
|
|
2861
|
+
const height = Number(hRaw);
|
|
2862
|
+
if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0) return null;
|
|
2863
|
+
|
|
2864
|
+
const longestSide = Math.max(width, height);
|
|
2865
|
+
if (longestSide <= 1024) return "1K";
|
|
2866
|
+
if (longestSide <= 2048) return "2K";
|
|
2867
|
+
return "4K";
|
|
2868
|
+
}
|
|
2869
|
+
|
|
2870
|
+
function normalizePositiveNumber(value, fallback) {
|
|
2871
|
+
const n = Number(value);
|
|
2872
|
+
if (!Number.isFinite(n) || n <= 0) return fallback;
|
|
2873
|
+
return Math.floor(n);
|
|
2874
|
+
}
|
|
2875
|
+
|
|
2876
|
+
/**
|
|
2877
|
+
* Handle SD WebUI image generation (local, no auth)
|
|
2878
|
+
* POST {baseUrl} with { prompt, negative_prompt, width, height, steps }
|
|
2879
|
+
* Response: { images: ["base64..."] }
|
|
2880
|
+
*/
|