cartethyia 2.5.3 → 2.5.6
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 +13 -4
- package/README.md +2 -2
- package/dist/dashboard/assets/{BannedPage-hfCzi-Ux.js → BannedPage-CADDq4IU.js} +1 -1
- package/dist/dashboard/assets/BannedPage-CADDq4IU.js.gz +0 -0
- package/dist/dashboard/assets/CliToolDetailPage-_z1hID7E.js +1 -0
- package/dist/dashboard/assets/CliToolDetailPage-_z1hID7E.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolsPage-DEDyKBlC.js → CliToolsPage-DuO1Z7dq.js} +1 -1
- package/dist/dashboard/assets/CliToolsPage-DuO1Z7dq.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-DNEPi3xU.js +1 -0
- package/dist/dashboard/assets/CombosPage-DNEPi3xU.js.gz +0 -0
- package/dist/dashboard/assets/{ConsoleLogPage-bsLuZmYH.js → ConsoleLogPage-BVdpfiz1.js} +1 -1
- package/dist/dashboard/assets/ConsoleLogPage-BVdpfiz1.js.gz +0 -0
- package/dist/dashboard/assets/{CustomizationPage-_UWhwziJ.js → CustomizationPage-BR5HHvbi.js} +1 -1
- package/dist/dashboard/assets/CustomizationPage-BR5HHvbi.js.gz +0 -0
- package/dist/dashboard/assets/HealthEventsModal-mUfcknqm.js +1 -0
- package/dist/dashboard/assets/HealthEventsModal-mUfcknqm.js.gz +0 -0
- package/dist/dashboard/assets/{LoginPage-DDVIfZGW.js → LoginPage-V5faV9V2.js} +1 -1
- package/dist/dashboard/assets/LoginPage-V5faV9V2.js.gz +0 -0
- package/dist/dashboard/assets/ModelPicker-C7pDb41R.js +1 -0
- package/dist/dashboard/assets/ModelPicker-C7pDb41R.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-BDu20Jdx.js +1 -0
- package/dist/dashboard/assets/OverviewPage-BDu20Jdx.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-Dllr_aFO.js +3 -0
- package/dist/dashboard/assets/ProviderDetailPage-Dllr_aFO.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-uPiGVTTK.js +1 -0
- package/dist/dashboard/assets/ProvidersPage-uPiGVTTK.js.gz +0 -0
- package/dist/dashboard/assets/ProxyPage-BaUkO-4O.js +7 -0
- package/dist/dashboard/assets/ProxyPage-BaUkO-4O.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-o0IFAsFb.js +1 -0
- package/dist/dashboard/assets/QuotaPage-o0IFAsFb.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-CYWqbXjp.js +1 -0
- package/dist/dashboard/assets/SettingsPage-CYWqbXjp.js.gz +0 -0
- package/dist/dashboard/assets/{SetupPage-D6pmQ86L.js → SetupPage-UB690SE2.js} +1 -1
- package/dist/dashboard/assets/SetupPage-UB690SE2.js.gz +0 -0
- package/dist/dashboard/assets/{SortableList-DWvKiuSl.js → SortableList-BLujdX7N.js} +1 -1
- package/dist/dashboard/assets/SortableList-BLujdX7N.js.gz +0 -0
- package/dist/dashboard/assets/{StudioPage-CmkUrgdj.js → StudioPage-D5C2raAc.js} +3 -3
- package/dist/dashboard/assets/StudioPage-D5C2raAc.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-8uIcxa1W.js +56 -0
- package/dist/dashboard/assets/UsagePage-8uIcxa1W.js.gz +0 -0
- package/dist/dashboard/assets/api-keys-DQYLQxpW.js +1 -0
- package/dist/dashboard/assets/api-keys-DQYLQxpW.js.gz +0 -0
- package/dist/dashboard/assets/app-CX_Z8cMs.css +2 -0
- package/dist/dashboard/assets/app-CX_Z8cMs.css.gz +0 -0
- package/dist/dashboard/assets/{assert-NHwYq95t.js → assert-C9FD_JwJ.js} +1 -1
- package/dist/dashboard/assets/assert-C9FD_JwJ.js.gz +0 -0
- package/dist/dashboard/assets/{badge-6uzDDvqs.js → badge-CR72dasT.js} +1 -1
- package/dist/dashboard/assets/badge-CR72dasT.js.gz +0 -0
- package/dist/dashboard/assets/{banner-4_WNg2WZ.js → banner-CI9_eSfO.js} +1 -1
- package/dist/dashboard/assets/banner-CI9_eSfO.js.gz +0 -0
- package/dist/dashboard/assets/{card--AtFedAq.js → card-DS7CQEsO.js} +1 -1
- package/dist/dashboard/assets/card-DS7CQEsO.js.gz +0 -0
- package/dist/dashboard/assets/{cli-tools-B3e7dx3N.js → cli-tools-CNqzrfdb.js} +1 -1
- package/dist/dashboard/assets/cli-tools-CNqzrfdb.js.gz +0 -0
- package/dist/dashboard/assets/{clipboard-button-NreUx6c8.js → clipboard-button-611pSsaX.js} +1 -1
- package/dist/dashboard/assets/clipboard-button-611pSsaX.js.gz +0 -0
- package/dist/dashboard/assets/{fingerprint-pattern-BWuHtbW4.js → concurrency-BDF0ok7y.js} +1 -1
- package/dist/dashboard/assets/concurrency-BDF0ok7y.js.gz +0 -0
- package/dist/dashboard/assets/database-Dz9N3zGd.js +1 -0
- package/dist/dashboard/assets/database-Dz9N3zGd.js.gz +0 -0
- package/dist/dashboard/assets/dialog-k37exjNt.js +1 -0
- package/dist/dashboard/assets/dialog-k37exjNt.js.gz +0 -0
- package/dist/dashboard/assets/drawer-CX7N8ucR.js +1 -0
- package/dist/dashboard/assets/drawer-CX7N8ucR.js.gz +0 -0
- package/dist/dashboard/assets/entry-B9Xvtnfj.js +1 -0
- package/dist/dashboard/assets/entry-B9Xvtnfj.js.gz +0 -0
- package/dist/dashboard/assets/entry-CTP8AyiS.js +1 -0
- package/dist/dashboard/assets/entry-CTP8AyiS.js.gz +0 -0
- package/dist/dashboard/assets/entry-DxBHnauy.js +4 -0
- package/dist/dashboard/assets/entry-DxBHnauy.js.gz +0 -0
- package/dist/dashboard/assets/{github-badge-D_eM3IgG.js → github-badge-sltk1qUi.js} +1 -1
- package/dist/dashboard/assets/github-badge-sltk1qUi.js.gz +0 -0
- package/dist/dashboard/assets/{index-BydyKaDz.js → index-CmxZr14F.js} +2 -2
- package/dist/dashboard/assets/index-CmxZr14F.js.gz +0 -0
- package/dist/dashboard/assets/{inline-BcNGF8Gr.js → inline-BhY2sSnO.js} +1 -1
- package/dist/dashboard/assets/inline-BhY2sSnO.js.gz +0 -0
- package/dist/dashboard/assets/{input-BG41et9G.js → input-V1umFiBk.js} +1 -1
- package/dist/dashboard/assets/input-V1umFiBk.js.gz +0 -0
- package/dist/dashboard/assets/layout-BBOYycyS.js +1 -0
- package/dist/dashboard/assets/layout-BBOYycyS.js.gz +0 -0
- package/dist/dashboard/assets/{list-row-Gh_W4OR_.js → list-row-1zzZYM0B.js} +1 -1
- package/dist/dashboard/assets/list-row-1zzZYM0B.js.gz +0 -0
- package/dist/dashboard/assets/{live-BJGYRBnR.js → live-BivGfuUs.js} +1 -1
- package/dist/dashboard/assets/live-BivGfuUs.js.gz +0 -0
- package/dist/dashboard/assets/model-bans-CmffjLuG.js +1 -0
- package/dist/dashboard/assets/model-bans-CmffjLuG.js.gz +0 -0
- package/dist/dashboard/assets/{mutation-BkoLM5Ba.js → mutation-46P0oWMe.js} +1 -1
- package/dist/dashboard/assets/mutation-46P0oWMe.js.gz +0 -0
- package/dist/dashboard/assets/numbers-DkfMR5Qs.js +2 -0
- package/dist/dashboard/assets/numbers-DkfMR5Qs.js.gz +0 -0
- package/dist/dashboard/assets/{query-keys-D7wX2vM5.js → query-keys-BFhGpwR1.js} +1 -1
- package/dist/dashboard/assets/query-keys-BFhGpwR1.js.gz +0 -0
- package/dist/dashboard/assets/{routing-CcusqXA7.js → routing-CAb4F37R.js} +1 -1
- package/dist/dashboard/assets/routing-CAb4F37R.js.gz +0 -0
- package/dist/dashboard/assets/{select-BO6h8yNv.js → select-BYR_5K2c.js} +2 -2
- package/dist/dashboard/assets/select-BYR_5K2c.js.gz +0 -0
- package/dist/dashboard/assets/{settings-mpmXTgUa.js → settings-DNX9sydi.js} +1 -1
- package/dist/dashboard/assets/settings-DNX9sydi.js.gz +0 -0
- package/dist/dashboard/assets/{stack-DwLmjUFK.js → stack-BHTfXdz_.js} +1 -1
- package/dist/dashboard/assets/stack-BHTfXdz_.js.gz +0 -0
- package/dist/dashboard/assets/{state-DYdQmdAl.js → state-mPDRlQkl.js} +1 -1
- package/dist/dashboard/assets/state-mPDRlQkl.js.gz +0 -0
- package/dist/dashboard/assets/switch-DOmJxg7H.js +1 -0
- package/dist/dashboard/assets/switch-DOmJxg7H.js.gz +0 -0
- package/dist/dashboard/assets/terminal-0_IjPWTk.js +1 -0
- package/dist/dashboard/assets/terminal-0_IjPWTk.js.gz +0 -0
- package/dist/dashboard/assets/tokens-COzario9.js +1 -0
- package/dist/dashboard/assets/tokens-COzario9.js.gz +0 -0
- package/dist/dashboard/assets/use-modal-focus-By7oJoGd.js +1 -0
- package/dist/dashboard/assets/use-modal-focus-By7oJoGd.js.gz +0 -0
- package/dist/dashboard/assets/{useMutation-w4u4CVue.js → useMutation-Dem0lXQj.js} +1 -1
- package/dist/dashboard/assets/useMutation-Dem0lXQj.js.gz +0 -0
- package/dist/dashboard/assets/zap-C4EeVW4q.js +1 -0
- package/dist/dashboard/assets/zap-C4EeVW4q.js.gz +0 -0
- package/dist/dashboard/donation/qris-risun-marke.png +0 -0
- package/dist/dashboard/index.html +1 -1
- package/dist/dashboard/index.html.gz +0 -0
- package/dist/dashboard/precompressed-assets.json +57 -57
- package/migrations/README.md +52 -52
- package/migrations/lite-sqlite3/0000_baseline.sql +2 -2
- package/package.json +96 -95
- package/scripts/cli/admin.ts +125 -0
- package/scripts/cli/autostart.ts +237 -0
- package/scripts/cli/{ui/background.ts → background.ts} +1 -1
- package/scripts/cli/{command/console-menu.ts → console-menu.ts} +275 -248
- package/scripts/cli/doctor.ts +37 -0
- package/scripts/cli/{support/env.ts → env.ts} +99 -99
- package/scripts/cli/{gateway/spawn.ts → gateway.ts} +112 -24
- package/scripts/cli/instance.ts +224 -0
- package/scripts/cli/main.ts +88 -18
- package/scripts/cli/{support/platform.ts → platform.ts} +64 -64
- package/scripts/cli/port.ts +100 -0
- package/scripts/cli/{support/services.ts → services.ts} +88 -88
- package/scripts/cli/{command/setup.ts → setup.ts} +35 -34
- package/scripts/cli/{command/start.ts → start.ts} +10 -5
- package/scripts/cli/{support/startup-signal.ts → startup-signal.ts} +23 -23
- package/scripts/cli/tray/index.ts +62 -12
- package/scripts/cli/{command/tray.ts → tray.ts} +208 -208
- package/scripts/cli/update.ts +40 -0
- package/scripts/cli/version.ts +67 -0
- package/scripts/cli/{ui/wordmark.ts → wordmark.ts} +58 -58
- package/src/boot/app.ts +11 -7
- package/src/boot/dependencies.ts +50 -19
- package/src/boot/timeout.ts +2 -13
- package/src/config/cooldowns.ts +186 -138
- package/src/config/network.ts +8 -14
- package/src/config/providers.ts +7 -10
- package/src/config/runtime.ts +76 -76
- package/src/config/security.ts +15 -0
- package/src/config/spec.ts +52 -7
- package/src/config/telemetry.ts +26 -0
- package/src/config/timeouts.ts +0 -6
- package/src/console/admin/model-abuse/contracts.ts +28 -6
- package/src/console/admin/model-abuse/routes.ts +56 -3
- package/src/console/api-keys/bucket-spend.ts +15 -4
- package/src/console/api-keys/contracts.ts +410 -414
- package/src/console/api-keys/routes.ts +881 -880
- package/src/console/auth/credentials.ts +3 -3
- package/src/console/auth/setup-service.ts +2 -2
- package/src/console/backup/contracts.ts +15 -2
- package/src/console/backup/export-endpoint.ts +6 -2
- package/src/console/backup/nine-router.ts +2 -5
- package/src/console/backup/service.ts +4 -0
- package/src/console/backup/store.ts +192 -29
- package/src/console/backup/validate.ts +3 -45
- package/src/console/cli-tools/fs-ops.ts +487 -487
- package/src/console/console-router-guards.ts +1 -1
- package/src/console/console-router.ts +8 -0
- package/src/console/data-management/contracts.ts +100 -0
- package/src/console/data-management/operations.ts +234 -0
- package/src/console/data-management/routes.ts +103 -0
- package/src/console/domain-registration.ts +45 -1
- package/src/console/observability/contracts.ts +524 -485
- package/src/console/observability/live.ts +22 -0
- package/src/console/observability/store.ts +1138 -1018
- package/src/console/observability/usage-dimensions.ts +4 -4
- package/src/console/providers/catalog/catalog-projections.ts +6 -7
- package/src/console/providers/catalog/contracts.ts +6 -0
- package/src/console/providers/catalog/model-operations.ts +5 -2
- package/src/console/providers/catalog/provider-operations.ts +24 -4
- package/src/console/providers/catalog/public-model-store.ts +8 -11
- package/src/console/providers/catalog/routes.ts +7 -0
- package/src/console/providers/catalog/store.ts +1553 -1532
- package/src/console/providers/oauth/routes.ts +8 -12
- package/src/console/quota/account-quota-shared.ts +52 -39
- package/src/console/quota/account-quota-tenant.ts +6 -6
- package/src/console/quota/quota-view.ts +1 -1
- package/src/console/quota/refresh.ts +441 -429
- package/src/console/remote-support/contracts.ts +61 -0
- package/src/console/remote-support/routes.ts +65 -0
- package/src/console/remote-support/service.ts +207 -0
- package/src/console/response-compression.ts +0 -3
- package/src/console/routing/pools/import-parse.ts +206 -0
- package/src/console/routing/pools/operations.ts +543 -501
- package/src/console/routing/pools/probe-result.ts +3 -2
- package/src/console/routing/pools/probe-verdict.ts +132 -132
- package/src/console/routing/pools/routes.ts +181 -164
- package/src/console/routing/pools/store.ts +8 -8
- package/src/console/settings/contracts.ts +95 -2
- package/src/console/settings/store.ts +81 -3
- package/src/console/shared/cursor.ts +8 -8
- package/src/console/shared/errors.ts +1 -3
- package/src/console/updates/routes.ts +16 -0
- package/src/main.ts +10 -0
- package/src/network/http2-bidi.ts +2 -4
- package/src/network/pool/agent.ts +478 -478
- package/src/network/pool/selector.ts +5 -4
- package/src/network/retry.ts +1 -2
- package/src/network/ssrf.ts +5 -4
- package/src/observability/event-compaction.ts +317 -0
- package/src/observability/event-day-index.ts +440 -0
- package/src/observability/event-log.ts +155 -6
- package/src/observability/logger.ts +6 -6
- package/src/observability/payload-capture.ts +158 -33
- package/src/observability/payload-store.ts +82 -61
- package/src/observability/redaction.ts +5 -6
- package/src/observability/request-notify.ts +43 -0
- package/src/observability/telemetry-status.ts +8 -9
- package/src/observability/token-speed.ts +5 -4
- package/src/persistence/db-mode.ts +7 -7
- package/src/persistence/health-event-flush.ts +36 -0
- package/src/persistence/readiness.ts +1 -1
- package/src/persistence/schema.ts +75 -29
- package/src/persistence/shared-cache.ts +1 -2
- package/src/persistence/stores/api-key-store.ts +18 -6
- package/src/persistence/stores/share-store.ts +4 -3
- package/src/persistence/stores/telemetry-store.ts +33 -11
- package/src/protocol/canonical-model.ts +11 -3
- package/src/protocol/codecs.ts +139 -6
- package/src/protocol/gateway-error.ts +6 -4
- package/src/protocol/image-clamp.ts +19 -1
- package/src/protocol/registry.ts +8 -0
- package/src/protocol/request/chat.ts +21 -1
- package/src/protocol/request/codex.ts +10 -1
- package/src/protocol/request/gemini.ts +9 -2
- package/src/protocol/request/messages.ts +18 -7
- package/src/protocol/request/responses.ts +9 -1
- package/src/protocol/response/chat.ts +34 -4
- package/src/protocol/response/codex.ts +7 -4
- package/src/protocol/response/dsml.ts +140 -28
- package/src/protocol/response/responses.ts +11 -5
- package/src/protocol/stream-error-frames.ts +4 -5
- package/src/providers/adapters/compatible-adapter.ts +3 -0
- package/src/providers/authentication/jwt-validator.ts +9 -10
- package/src/providers/authentication/oauth-refresh-service.ts +9 -11
- package/src/providers/bundled-discovery-providers.ts +122 -119
- package/src/providers/configured-openai-providers.ts +4 -4
- package/src/providers/default-registry.ts +5 -4
- package/src/providers/discovery/catalog/catalog-blob.ts +18 -18
- package/src/providers/discovery/catalog/catalog-format.ts +3 -6
- package/src/providers/discovery/models-dev-catalog.ts +354 -354
- package/src/providers/discovery/openai-model-discovery.ts +5 -0
- package/src/providers/discovery/openrouter-free-roster.ts +15 -17
- package/src/providers/discovery/probe-phases.ts +4 -4
- package/src/providers/discovery/probe-wire.ts +6 -13
- package/src/providers/discovery/probing-service.ts +1117 -1045
- package/src/providers/integrations/alibabacp/alibabacp.ts +1 -1
- package/src/providers/integrations/antigravity/antigravity-quota.ts +5 -7
- package/src/providers/integrations/buddy/buddy-chat-shared.ts +23 -2
- package/src/providers/integrations/buddy/buddy-checkin.ts +1 -4
- package/src/providers/integrations/buddy/buddy-cli-headers.ts +23 -6
- package/src/providers/integrations/buddy/buddy-conversation-headers.ts +0 -1
- package/src/providers/integrations/buddy/buddy-identity.ts +52 -0
- package/src/providers/integrations/buddy/buddy-media.ts +2 -2
- package/src/providers/integrations/buddy/buddy-usage-store.ts +3 -4
- package/src/providers/integrations/buddy/codebuddy/quota.ts +2 -13
- package/src/providers/integrations/buddy/codebuddy/shared.ts +118 -115
- package/src/providers/integrations/buddy/workbuddy/quota.ts +0 -11
- package/src/providers/integrations/buddy/workbuddy/shared.ts +5 -2
- package/src/providers/integrations/claude/claude.ts +608 -608
- package/src/providers/integrations/cline/cline-quota.ts +27 -20
- package/src/providers/integrations/cline/cline.ts +537 -539
- package/src/providers/integrations/codex/codex-headers.ts +25 -39
- package/src/providers/integrations/codex/codex-oauth.ts +1 -1
- package/src/providers/integrations/codex/codex.ts +2 -29
- package/src/providers/integrations/commandcode/commandcode.ts +674 -675
- package/src/providers/integrations/commandcode/discovery.ts +117 -116
- package/src/providers/integrations/cursor/cursor-auth.ts +418 -418
- package/src/providers/integrations/cursor/cursor-quota.ts +309 -0
- package/src/providers/integrations/cursor/cursor-request.ts +616 -471
- package/src/providers/integrations/cursor/cursor-session-manager.ts +319 -281
- package/src/providers/integrations/cursor/cursor.ts +1333 -960
- package/src/providers/integrations/cursor/protocol/messages.ts +25 -0
- package/src/providers/integrations/factory/factory-models.ts +3 -5
- package/src/providers/integrations/factory/factory.ts +8 -1
- package/src/providers/integrations/gemini.ts +6 -1
- package/src/providers/integrations/grok/grok-install-id.ts +2 -3
- package/src/providers/integrations/grok/grok-quota.ts +279 -177
- package/src/providers/integrations/grok/grok-ratelimit-store.ts +73 -0
- package/src/providers/integrations/grok/grok-ratelimit.ts +218 -0
- package/src/providers/integrations/grok/grok.ts +6 -7
- package/src/providers/integrations/hermes.ts +14 -18
- package/src/providers/integrations/kiro/kiro-discovery.ts +1 -1
- package/src/providers/integrations/kiro/kiro.ts +1 -1
- package/src/providers/integrations/mistral.ts +6 -6
- package/src/providers/integrations/opencode/fingerprint.ts +3 -3
- package/src/providers/integrations/opencode/provider.ts +19 -20
- package/src/providers/integrations/qoder/qoder-catalog.ts +450 -450
- package/src/providers/integrations/qoder/qoder-oauth.ts +388 -310
- package/src/providers/integrations/qoder/qoder-quota.ts +192 -0
- package/src/providers/integrations/qoder/qoder.ts +884 -865
- package/src/providers/integrations/shared/connect.ts +6 -6
- package/src/providers/integrations/trae/trae-catalog.ts +1 -2
- package/src/providers/integrations/trae/trae-quota.ts +384 -0
- package/src/providers/integrations/trae/trae.ts +2 -2
- package/src/providers/integrations/zcode/oauth.ts +6 -1
- package/src/providers/operations/account-health-service.ts +75 -27
- package/src/providers/operations/account-reset-service.ts +1 -1
- package/src/providers/operations/client-versions.ts +6 -6
- package/src/providers/operations/custom-cli-headers.ts +3 -4
- package/src/providers/operations/provider-catalog-seeder.ts +95 -95
- package/src/providers/operations/provider-catalog-service.ts +3 -4
- package/src/providers/provider-contracts.ts +7 -0
- package/src/providers/provider-metadata.ts +10 -8
- package/src/providers/provider-registry.ts +6 -7
- package/src/providers/provider-usage.ts +1 -1
- package/src/providers/quota/quota-support.ts +8 -0
- package/src/security/abuse.ts +15 -10
- package/src/security/access-control.ts +144 -146
- package/src/security/admission/contracts.ts +11 -0
- package/src/security/admission/in-memory-store.ts +4 -3
- package/src/security/admission/lease-sweep.ts +6 -6
- package/src/security/admission/reasons.ts +5 -1
- package/src/security/admission/redis-store.ts +211 -210
- package/src/security/admission/service.ts +4 -0
- package/src/security/api-key-auth.ts +27 -17
- package/src/security/ip-boundary.ts +155 -15
- package/src/security/model-abuse.ts +366 -94
- package/src/security/outbound-headers.ts +3 -4
- package/src/shared/sleep.ts +4 -0
- package/src/transport/dispatch/attempt-finalize.ts +47 -5
- package/src/transport/dispatch/attempt-loop.ts +531 -530
- package/src/transport/dispatch/generation.ts +6 -0
- package/src/transport/dispatch/proxy-request.ts +24 -1
- package/src/transport/dispatch/ratelimit-capture.ts +37 -0
- package/src/transport/dispatch/stream-bridge.ts +1 -3
- package/src/transport/dispatch/streaming/finalize.ts +1 -1
- package/src/transport/dispatch/streaming/stream.ts +19 -6
- package/src/transport/dispatch/upstream.ts +9 -0
- package/src/transport/failure-policy.ts +162 -8
- package/src/transport/guards/auth-guard.ts +7 -4
- package/src/transport/guards/concurrency-guard.ts +0 -5
- package/src/transport/guards/error-lifecycle.ts +13 -6
- package/src/transport/guards/pipeline.ts +15 -3
- package/src/transport/guards/request-context.ts +8 -2
- package/src/transport/request/inflight.ts +5 -6
- package/src/transport/request/preparer.ts +9 -8
- package/src/transport/request/state.ts +21 -8
- package/src/transport/request/tenant-preferences.ts +60 -0
- package/src/transport/routing/admission.ts +4 -0
- package/src/transport/routing/route-catalog.ts +65 -10
- package/src/transport/routing/route-model.ts +46 -14
- package/src/transport/routing/router.ts +21 -14
- package/src/transport/surface/completion.ts +2 -3
- package/src/transport/surface/dialects.ts +5 -6
- package/src/transport/surface/responses/encode.ts +38 -0
- package/src/transport/surface/responses/parse.ts +4 -0
- package/src/transport/translation/capabilities.ts +2 -3
- package/src/transport/translation/quirks.ts +3 -3
- package/src/workers/buddy-growth-tasks.ts +5 -10
- package/src/workers/daily-checkin.ts +17 -23
- package/src/workers/quota-refresh-sweep.ts +26 -26
- package/dist/dashboard/assets/BannedPage-hfCzi-Ux.js.gz +0 -0
- package/dist/dashboard/assets/CliToolDetailPage-DLGqYEwI.js +0 -1
- package/dist/dashboard/assets/CliToolDetailPage-DLGqYEwI.js.gz +0 -0
- package/dist/dashboard/assets/CliToolsPage-DEDyKBlC.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-CfuYiQ8Z.js +0 -1
- package/dist/dashboard/assets/CombosPage-CfuYiQ8Z.js.gz +0 -0
- package/dist/dashboard/assets/ConsoleLogPage-bsLuZmYH.js.gz +0 -0
- package/dist/dashboard/assets/CustomizationPage-_UWhwziJ.js.gz +0 -0
- package/dist/dashboard/assets/HealthEventsModal-Cjfc5WFS.js +0 -1
- package/dist/dashboard/assets/HealthEventsModal-Cjfc5WFS.js.gz +0 -0
- package/dist/dashboard/assets/LoginPage-DDVIfZGW.js.gz +0 -0
- package/dist/dashboard/assets/ModelPicker-CWkTUtpX.js +0 -1
- package/dist/dashboard/assets/ModelPicker-CWkTUtpX.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-B53YYMng.js +0 -1
- package/dist/dashboard/assets/OverviewPage-B53YYMng.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-B0KaAQf0.js +0 -3
- package/dist/dashboard/assets/ProviderDetailPage-B0KaAQf0.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-Dx31DgIO.js +0 -1
- package/dist/dashboard/assets/ProvidersPage-Dx31DgIO.js.gz +0 -0
- package/dist/dashboard/assets/ProxyPage-BpnR4kXT.js +0 -7
- package/dist/dashboard/assets/ProxyPage-BpnR4kXT.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-BpOQCnun.js +0 -1
- package/dist/dashboard/assets/QuotaPage-BpOQCnun.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-DV1eo2J_.js +0 -1
- package/dist/dashboard/assets/SettingsPage-DV1eo2J_.js.gz +0 -0
- package/dist/dashboard/assets/SetupPage-D6pmQ86L.js.gz +0 -0
- package/dist/dashboard/assets/SortableList-DWvKiuSl.js.gz +0 -0
- package/dist/dashboard/assets/StudioPage-CmkUrgdj.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-B47uOydr.js +0 -56
- package/dist/dashboard/assets/UsagePage-B47uOydr.js.gz +0 -0
- package/dist/dashboard/assets/api-keys-uNywYlfv.js +0 -1
- package/dist/dashboard/assets/api-keys-uNywYlfv.js.gz +0 -0
- package/dist/dashboard/assets/app-DxivpfYG.css +0 -2
- package/dist/dashboard/assets/app-DxivpfYG.css.gz +0 -0
- package/dist/dashboard/assets/assert-NHwYq95t.js.gz +0 -0
- package/dist/dashboard/assets/badge-6uzDDvqs.js.gz +0 -0
- package/dist/dashboard/assets/banner-4_WNg2WZ.js.gz +0 -0
- package/dist/dashboard/assets/card--AtFedAq.js.gz +0 -0
- package/dist/dashboard/assets/cli-tools-B3e7dx3N.js.gz +0 -0
- package/dist/dashboard/assets/clipboard-button-NreUx6c8.js.gz +0 -0
- package/dist/dashboard/assets/dialog-BtpsJU98.js +0 -1
- package/dist/dashboard/assets/dialog-BtpsJU98.js.gz +0 -0
- package/dist/dashboard/assets/download-A0SW9OCW.js +0 -1
- package/dist/dashboard/assets/download-A0SW9OCW.js.gz +0 -0
- package/dist/dashboard/assets/drawer-WwwtzihF.js +0 -1
- package/dist/dashboard/assets/drawer-WwwtzihF.js.gz +0 -0
- package/dist/dashboard/assets/entry-CkryrIea.js +0 -4
- package/dist/dashboard/assets/entry-CkryrIea.js.gz +0 -0
- package/dist/dashboard/assets/entry-TJIye_jT.js +0 -1
- package/dist/dashboard/assets/entry-TJIye_jT.js.gz +0 -0
- package/dist/dashboard/assets/entry-jy9_4-Ke.js +0 -1
- package/dist/dashboard/assets/entry-jy9_4-Ke.js.gz +0 -0
- package/dist/dashboard/assets/fingerprint-pattern-BWuHtbW4.js.gz +0 -0
- package/dist/dashboard/assets/github-badge-D_eM3IgG.js.gz +0 -0
- package/dist/dashboard/assets/index-BydyKaDz.js.gz +0 -0
- package/dist/dashboard/assets/inline-BcNGF8Gr.js.gz +0 -0
- package/dist/dashboard/assets/input-BG41et9G.js.gz +0 -0
- package/dist/dashboard/assets/layout-C8mer_Ak.js +0 -1
- package/dist/dashboard/assets/layout-C8mer_Ak.js.gz +0 -0
- package/dist/dashboard/assets/list-row-Gh_W4OR_.js.gz +0 -0
- package/dist/dashboard/assets/live-BJGYRBnR.js.gz +0 -0
- package/dist/dashboard/assets/model-bans-DeVLDA7I.js +0 -1
- package/dist/dashboard/assets/model-bans-DeVLDA7I.js.gz +0 -0
- package/dist/dashboard/assets/mutation-BkoLM5Ba.js.gz +0 -0
- package/dist/dashboard/assets/numbers-Bs4LOOuf.js +0 -2
- package/dist/dashboard/assets/numbers-Bs4LOOuf.js.gz +0 -0
- package/dist/dashboard/assets/query-keys-D7wX2vM5.js.gz +0 -0
- package/dist/dashboard/assets/routing-CcusqXA7.js.gz +0 -0
- package/dist/dashboard/assets/select-BO6h8yNv.js.gz +0 -0
- package/dist/dashboard/assets/settings-mpmXTgUa.js.gz +0 -0
- package/dist/dashboard/assets/sparkles-BRaRUxAU.js +0 -1
- package/dist/dashboard/assets/sparkles-BRaRUxAU.js.gz +0 -0
- package/dist/dashboard/assets/stack-DwLmjUFK.js.gz +0 -0
- package/dist/dashboard/assets/state-DYdQmdAl.js.gz +0 -0
- package/dist/dashboard/assets/switch-CidSfbG7.js +0 -1
- package/dist/dashboard/assets/switch-CidSfbG7.js.gz +0 -0
- package/dist/dashboard/assets/terminal-Bd4ee8TA.js +0 -1
- package/dist/dashboard/assets/terminal-Bd4ee8TA.js.gz +0 -0
- package/dist/dashboard/assets/tokens-DDxMbSRL.js +0 -1
- package/dist/dashboard/assets/tokens-DDxMbSRL.js.gz +0 -0
- package/dist/dashboard/assets/use-presence-BSZEBx7U.js +0 -1
- package/dist/dashboard/assets/use-presence-BSZEBx7U.js.gz +0 -0
- package/dist/dashboard/assets/useMutation-w4u4CVue.js.gz +0 -0
- package/scripts/cli/command/admin.ts +0 -65
- package/scripts/cli/command/doctor.ts +0 -257
- package/scripts/cli/command/update.ts +0 -23
- package/scripts/cli/gateway/drain-token.ts +0 -78
- package/scripts/cli/gateway/instance-lock.ts +0 -105
- package/scripts/cli/gateway/stop.ts +0 -51
- package/scripts/cli/support/bun.ts +0 -27
- package/scripts/cli/support/version.ts +0 -37
- /package/dist/dashboard/assets/{app-CafWtVXA.js → app-BIt446yE.js} +0 -0
- /package/dist/dashboard/assets/{app-CafWtVXA.js.gz → app-BIt446yE.js.gz} +0 -0
- /package/scripts/cli/{ui/prompt.ts → prompt.ts} +0 -0
|
@@ -1,675 +1,674 @@
|
|
|
1
|
-
// Factory-blocked (Phase C4): proprietary `{threadId, config, params}`
|
|
2
|
-
// envelope with NDJSON stream transform — non-OpenAI wire; stays bespoke.
|
|
3
|
-
import { GatewayError } from "../../../protocol/gateway-error";
|
|
4
|
-
import { canContainToolResult, joinTextParts, toolCallParts, toolResultParts } from "../../../protocol/canonical-model";
|
|
5
|
-
import {
|
|
6
|
-
classifyUpstreamError,
|
|
7
|
-
extractUpstreamMessage,
|
|
8
|
-
upstreamErrorIdentifier,
|
|
9
|
-
} from "../../../transport/failure-policy";
|
|
10
|
-
import { createApiKeyAdapter } from "../../configured-provider";
|
|
11
|
-
import type { CanonicalEvent, CanonicalRequest, CanonicalStopReason, ContentPart } from "../../../protocol/canonical-model";
|
|
12
|
-
import { isRecord, readNumber, readString, resolveImageSource, splitDataUrl } from "../../../protocol/codecs";
|
|
13
|
-
import { usageFromProvider } from "../../provider-usage";
|
|
14
|
-
import { readCredentialSecret, type ProviderDispatchTarget, type ProviderAdapter, type ProviderDispatchContext } from "../../provider-contracts";
|
|
15
|
-
import { providerBaseUrl } from "../../provider-metadata";
|
|
16
|
-
import { defineModel } from "../../provider-model-definition";
|
|
17
|
-
import type { ModelDefinition } from "../../provider-model-definition";
|
|
18
|
-
import {
|
|
19
|
-
getCommandCodeVersion,
|
|
20
|
-
} from "../../operations/client-versions";
|
|
21
|
-
import { MimoThinkSplitter } from "../xiaomi-mimo/think-stream";
|
|
22
|
-
export const COMMANDCODE_PROVIDER_ID = "commandcode" as const;
|
|
23
|
-
export const COMMANDCODE_BASE_URL = providerBaseUrl("commandcode");
|
|
24
|
-
/** The three routes the Provider API serves, one per wire family. */
|
|
25
|
-
export const COMMANDCODE_CHAT_PATH = "/chat/completions" as const;
|
|
26
|
-
export const COMMANDCODE_RESPONSES_PATH = "/responses" as const;
|
|
27
|
-
export const COMMANDCODE_MESSAGES_PATH = "/messages" as const;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Command Code's roster, as the Provider API publishes it.
|
|
31
|
-
*
|
|
32
|
-
* Generated from the live `/provider/v1/models` listing (95 rows). Each row
|
|
33
|
-
* carries the wire that serves it and the context window the API states, which
|
|
34
|
-
* is the whole point:
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
defineModel({ id: "MiniMaxAI/MiniMax-M2.
|
|
48
|
-
defineModel({ id: "MiniMaxAI/MiniMax-
|
|
49
|
-
defineModel({ id: "
|
|
50
|
-
defineModel({ id: "Qwen/Qwen3.6-
|
|
51
|
-
defineModel({ id: "Qwen/Qwen3.
|
|
52
|
-
defineModel({ id: "Qwen/Qwen3.7-
|
|
53
|
-
defineModel({ id: "Qwen/Qwen3.7-
|
|
54
|
-
defineModel({ id: "Qwen/Qwen3.
|
|
55
|
-
defineModel({ id: "Qwen/Qwen3.8-
|
|
56
|
-
defineModel({ id: "Qwen/Qwen3.8-
|
|
57
|
-
defineModel({ id: "Qwen/Qwen3.8-Max", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "
|
|
58
|
-
defineModel({ id: "Qwen/Qwen3.8-Max-
|
|
59
|
-
defineModel({ id: "Qwen/Qwen3.8-
|
|
60
|
-
defineModel({ id: "
|
|
61
|
-
defineModel({ id: "claude-fable-5", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "messages", endpoint: "/messages", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
62
|
-
defineModel({ id: "claude-
|
|
63
|
-
defineModel({ id: "claude-haiku-
|
|
64
|
-
defineModel({ id: "claude-
|
|
65
|
-
defineModel({ id: "claude-opus-4-
|
|
66
|
-
defineModel({ id: "claude-opus-
|
|
67
|
-
defineModel({ id: "claude-opus-5", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "messages", endpoint: "/messages", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
68
|
-
defineModel({ id: "claude-
|
|
69
|
-
defineModel({ id: "claude-sonnet-
|
|
70
|
-
defineModel({ id: "claude-sonnet-5", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "messages", endpoint: "/messages", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
71
|
-
defineModel({ id: "
|
|
72
|
-
defineModel({ id: "deepseek/deepseek-v4-flash", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "
|
|
73
|
-
defineModel({ id: "deepseek/deepseek-v4-flash-
|
|
74
|
-
defineModel({ id: "deepseek/deepseek-v4-
|
|
75
|
-
defineModel({ id: "deepseek/deepseek-v4-
|
|
76
|
-
defineModel({ id: "deepseek/deepseek-v4.1-flash", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
77
|
-
defineModel({ id: "
|
|
78
|
-
defineModel({ id: "google/gemini-3.
|
|
79
|
-
defineModel({ id: "google/gemini-3.5-flash", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
80
|
-
defineModel({ id: "google/gemini-3.
|
|
81
|
-
defineModel({ id: "google/gemini-3.
|
|
82
|
-
defineModel({ id: "google/gemini-3.
|
|
83
|
-
defineModel({ id: "google/gemini-
|
|
84
|
-
defineModel({ id: "
|
|
85
|
-
defineModel({ id: "gpt-5.
|
|
86
|
-
defineModel({ id: "gpt-5.4", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 400000, reasoning: true, toolCall: true, vision: true }),
|
|
87
|
-
defineModel({ id: "gpt-5.
|
|
88
|
-
defineModel({ id: "gpt-5.
|
|
89
|
-
defineModel({ id: "gpt-5.6-
|
|
90
|
-
defineModel({ id: "gpt-5.6-
|
|
91
|
-
defineModel({ id: "gpt-
|
|
92
|
-
defineModel({ id: "gpt-6-
|
|
93
|
-
defineModel({ id: "gpt-6-
|
|
94
|
-
defineModel({ id: "gpt-6-sol", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1050000, reasoning: true, toolCall: true, vision: true }),
|
|
95
|
-
defineModel({ id: "
|
|
96
|
-
defineModel({ id: "
|
|
97
|
-
defineModel({ id: "
|
|
98
|
-
defineModel({ id: "meta/muse-spark-1.
|
|
99
|
-
defineModel({ id: "meta/muse-spark-1.2", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1048576, reasoning: true, toolCall: true, vision: true }),
|
|
100
|
-
defineModel({ id: "meta/muse-spark-1.
|
|
101
|
-
defineModel({ id: "meta/muse-spark-1.3", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1048576, reasoning: true, toolCall: true, vision: true }),
|
|
102
|
-
defineModel({ id: "meta/muse-spark-
|
|
103
|
-
defineModel({ id: "meta/muse-
|
|
104
|
-
defineModel({ id: "
|
|
105
|
-
defineModel({ id: "minimax/minimax-m3.1-flash-preview", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
106
|
-
defineModel({ id: "
|
|
107
|
-
defineModel({ id: "
|
|
108
|
-
defineModel({ id: "moonshotai/Kimi-K2.
|
|
109
|
-
defineModel({ id: "moonshotai/Kimi-K2.
|
|
110
|
-
defineModel({ id: "moonshotai/Kimi-K2.7-Code", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx:
|
|
111
|
-
defineModel({ id: "moonshotai/Kimi-
|
|
112
|
-
defineModel({ id: "
|
|
113
|
-
defineModel({ id: "nvidia/nemotron-3-
|
|
114
|
-
defineModel({ id: "
|
|
115
|
-
defineModel({ id: "
|
|
116
|
-
defineModel({ id: "
|
|
117
|
-
defineModel({ id: "
|
|
118
|
-
defineModel({ id: "stealth/
|
|
119
|
-
defineModel({ id: "
|
|
120
|
-
defineModel({ id: "stepfun/Step-3.
|
|
121
|
-
defineModel({ id: "stepfun/Step-
|
|
122
|
-
defineModel({ id: "
|
|
123
|
-
defineModel({ id: "tencent/
|
|
124
|
-
defineModel({ id: "
|
|
125
|
-
defineModel({ id: "thinkingmachines/inkling", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx:
|
|
126
|
-
defineModel({ id: "
|
|
127
|
-
defineModel({ id: "xai/grok-4.
|
|
128
|
-
defineModel({ id: "xai/grok-4.
|
|
129
|
-
defineModel({ id: "
|
|
130
|
-
defineModel({ id: "xiaomi/mimo-v2.5", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
131
|
-
defineModel({ id: "xiaomi/mimo-v2.
|
|
132
|
-
defineModel({ id: "xiaomi/mimo-v2.6-
|
|
133
|
-
defineModel({ id: "xiaomi/mimo-v2.6-pro", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1048576, reasoning: true, toolCall: true, vision: true }),
|
|
134
|
-
defineModel({ id: "
|
|
135
|
-
defineModel({ id: "z-ai/glm-5.3-
|
|
136
|
-
defineModel({ id: "
|
|
137
|
-
defineModel({ id: "zai-org/GLM-5", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 200000, reasoning: true, toolCall: true, vision: true }),
|
|
138
|
-
defineModel({ id: "zai-org/GLM-5.
|
|
139
|
-
defineModel({ id: "zai-org/GLM-5.2", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
140
|
-
defineModel({ id: "zai-org/GLM-5.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
*
|
|
151
|
-
* - `
|
|
152
|
-
* -
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
* -
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
.
|
|
162
|
-
.
|
|
163
|
-
.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
const
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
//
|
|
211
|
-
//
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
.
|
|
236
|
-
.
|
|
237
|
-
.
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
"
|
|
275
|
-
"
|
|
276
|
-
"
|
|
277
|
-
"
|
|
278
|
-
|
|
279
|
-
]);
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
"
|
|
283
|
-
"
|
|
284
|
-
"
|
|
285
|
-
"
|
|
286
|
-
"
|
|
287
|
-
"
|
|
288
|
-
"
|
|
289
|
-
"
|
|
290
|
-
"
|
|
291
|
-
"
|
|
292
|
-
"
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
if (
|
|
303
|
-
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
if (key
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
out["
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
const
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
if (request.
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
if (
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
//
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
//
|
|
362
|
-
//
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
//
|
|
371
|
-
//
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
"x-
|
|
405
|
-
"x-
|
|
406
|
-
"x-
|
|
407
|
-
"
|
|
408
|
-
"
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
if (
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
if (split.
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
const
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
{ type: "tool_call_delta", sequence_number: seqBase, call_id: id,
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
if (
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
const
|
|
472
|
-
const
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
const
|
|
478
|
-
const
|
|
479
|
-
const
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
const
|
|
495
|
-
const
|
|
496
|
-
const
|
|
497
|
-
|
|
498
|
-
errorObject["
|
|
499
|
-
errorObject["
|
|
500
|
-
|
|
501
|
-
event["
|
|
502
|
-
event["
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
value
|
|
509
|
-
|
|
510
|
-
);
|
|
511
|
-
const
|
|
512
|
-
|
|
513
|
-
extractUpstreamMessage(
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
classification.
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
...(
|
|
522
|
-
...(
|
|
523
|
-
...(classification.
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
const
|
|
537
|
-
const
|
|
538
|
-
|
|
539
|
-
let
|
|
540
|
-
let
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
const
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
};
|
|
552
|
-
signal.
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
//
|
|
575
|
-
//
|
|
576
|
-
//
|
|
577
|
-
|
|
578
|
-
(ev
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
if (rest.
|
|
597
|
-
if (
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
//
|
|
617
|
-
//
|
|
618
|
-
//
|
|
619
|
-
//
|
|
620
|
-
//
|
|
621
|
-
//
|
|
622
|
-
//
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
"x-
|
|
632
|
-
"x-
|
|
633
|
-
"x-
|
|
634
|
-
"
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
readonly
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
}
|
|
1
|
+
// Factory-blocked (Phase C4): proprietary `{threadId, config, params}`
|
|
2
|
+
// envelope with NDJSON stream transform — non-OpenAI wire; stays bespoke.
|
|
3
|
+
import { GatewayError } from "../../../protocol/gateway-error";
|
|
4
|
+
import { canContainToolResult, joinTextParts, toolCallParts, toolResultParts } from "../../../protocol/canonical-model";
|
|
5
|
+
import {
|
|
6
|
+
classifyUpstreamError,
|
|
7
|
+
extractUpstreamMessage,
|
|
8
|
+
upstreamErrorIdentifier,
|
|
9
|
+
} from "../../../transport/failure-policy";
|
|
10
|
+
import { createApiKeyAdapter } from "../../configured-provider";
|
|
11
|
+
import type { CanonicalEvent, CanonicalRequest, CanonicalStopReason, ContentPart } from "../../../protocol/canonical-model";
|
|
12
|
+
import { isRecord, readNumber, readString, resolveImageSource, splitDataUrl } from "../../../protocol/codecs";
|
|
13
|
+
import { usageFromProvider } from "../../provider-usage";
|
|
14
|
+
import { readCredentialSecret, type ProviderDispatchTarget, type ProviderAdapter, type ProviderDispatchContext } from "../../provider-contracts";
|
|
15
|
+
import { providerBaseUrl } from "../../provider-metadata";
|
|
16
|
+
import { defineModel } from "../../provider-model-definition";
|
|
17
|
+
import type { ModelDefinition } from "../../provider-model-definition";
|
|
18
|
+
import {
|
|
19
|
+
getCommandCodeVersion,
|
|
20
|
+
} from "../../operations/client-versions";
|
|
21
|
+
import { MimoThinkSplitter } from "../xiaomi-mimo/think-stream";
|
|
22
|
+
export const COMMANDCODE_PROVIDER_ID = "commandcode" as const;
|
|
23
|
+
export const COMMANDCODE_BASE_URL = providerBaseUrl("commandcode");
|
|
24
|
+
/** The three routes the Provider API serves, one per wire family. */
|
|
25
|
+
export const COMMANDCODE_CHAT_PATH = "/chat/completions" as const;
|
|
26
|
+
export const COMMANDCODE_RESPONSES_PATH = "/responses" as const;
|
|
27
|
+
export const COMMANDCODE_MESSAGES_PATH = "/messages" as const;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Command Code's roster, as the Provider API publishes it.
|
|
31
|
+
*
|
|
32
|
+
* Generated from the live `/provider/v1/models` listing (95 rows). Each row
|
|
33
|
+
* carries the wire that serves it and the context window the API states, which
|
|
34
|
+
* is the whole point: dispatch is per-row, and every `claude-*` id is served on
|
|
35
|
+
* `/messages` only — filed as chat, it could never be dispatched.
|
|
36
|
+
*
|
|
37
|
+
* `vision: true` on every row is the catalog's own declaration for this
|
|
38
|
+
* provider; a model that rejects an image answers for itself.
|
|
39
|
+
*
|
|
40
|
+
* This is the offline seed. It is superseded by `discoverCommandCodeModels`
|
|
41
|
+
* whenever a fetch succeeds, and `seedBundledModels` prunes any row this list
|
|
42
|
+
* stops declaring — so an id Command Code retires disappears on the next boot
|
|
43
|
+
* rather than lingering as a card that can only ever fail.
|
|
44
|
+
*/
|
|
45
|
+
export const COMMANDCODE_MODELS: readonly ModelDefinition[] = [
|
|
46
|
+
defineModel({ id: "MiniMaxAI/MiniMax-M2.5", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 200000, reasoning: true, toolCall: true, vision: true }),
|
|
47
|
+
defineModel({ id: "MiniMaxAI/MiniMax-M2.7", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 200000, reasoning: true, toolCall: true, vision: true }),
|
|
48
|
+
defineModel({ id: "MiniMaxAI/MiniMax-M3", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
49
|
+
defineModel({ id: "Qwen/Qwen3.6-Max-Preview", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 200000, reasoning: true, toolCall: true, vision: true }),
|
|
50
|
+
defineModel({ id: "Qwen/Qwen3.6-Plus", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 200000, reasoning: true, toolCall: true, vision: true }),
|
|
51
|
+
defineModel({ id: "Qwen/Qwen3.7-Flash", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
52
|
+
defineModel({ id: "Qwen/Qwen3.7-Max", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
53
|
+
defineModel({ id: "Qwen/Qwen3.7-Plus", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
54
|
+
defineModel({ id: "Qwen/Qwen3.8-27B", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 262144, reasoning: true, toolCall: true, vision: true }),
|
|
55
|
+
defineModel({ id: "Qwen/Qwen3.8-Flash", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "chat", endpoint: "/chat/completions", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
56
|
+
defineModel({ id: "Qwen/Qwen3.8-Max", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
57
|
+
defineModel({ id: "Qwen/Qwen3.8-Max-0902", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "chat", endpoint: "/chat/completions", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
58
|
+
defineModel({ id: "Qwen/Qwen3.8-Max-Prime", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
59
|
+
defineModel({ id: "Qwen/Qwen3.8-Omni-Flash", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
60
|
+
defineModel({ id: "claude-fable-5", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "messages", endpoint: "/messages", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
61
|
+
defineModel({ id: "claude-fable-5-1", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "messages", endpoint: "/messages", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
62
|
+
defineModel({ id: "claude-haiku-4-5-20251001", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "messages", endpoint: "/messages", ctx: 200000, reasoning: true, toolCall: true, vision: true }),
|
|
63
|
+
defineModel({ id: "claude-haiku-5-5", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "messages", endpoint: "/messages", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
64
|
+
defineModel({ id: "claude-opus-4-7", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "messages", endpoint: "/messages", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
65
|
+
defineModel({ id: "claude-opus-4-8", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "messages", endpoint: "/messages", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
66
|
+
defineModel({ id: "claude-opus-5", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "messages", endpoint: "/messages", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
67
|
+
defineModel({ id: "claude-opus-5-5", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "messages", endpoint: "/messages", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
68
|
+
defineModel({ id: "claude-sonnet-4-6", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "messages", endpoint: "/messages", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
69
|
+
defineModel({ id: "claude-sonnet-5", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "messages", endpoint: "/messages", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
70
|
+
defineModel({ id: "claude-sonnet-5-5", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "messages", endpoint: "/messages", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
71
|
+
defineModel({ id: "deepseek/deepseek-v4-flash", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
72
|
+
defineModel({ id: "deepseek/deepseek-v4-flash-fast", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "chat", endpoint: "/chat/completions", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
73
|
+
defineModel({ id: "deepseek/deepseek-v4-flash-vision-exp", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
74
|
+
defineModel({ id: "deepseek/deepseek-v4-pro", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
75
|
+
defineModel({ id: "deepseek/deepseek-v4.1-flash", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
76
|
+
defineModel({ id: "deepseek/deepseek-v4.1-flash-fast", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
77
|
+
defineModel({ id: "google/gemini-3.1-flash-lite", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
78
|
+
defineModel({ id: "google/gemini-3.5-flash", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
79
|
+
defineModel({ id: "google/gemini-3.5-flash-lite", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
80
|
+
defineModel({ id: "google/gemini-3.6-flash", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
81
|
+
defineModel({ id: "google/gemini-3.7-flash", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "chat", endpoint: "/chat/completions", ctx: 1048576, reasoning: true, toolCall: true, vision: true }),
|
|
82
|
+
defineModel({ id: "google/gemini-3.8-flash", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
83
|
+
defineModel({ id: "google/gemini-4-argon", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
84
|
+
defineModel({ id: "gpt-5.3-codex", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 400000, reasoning: true, toolCall: true, vision: true }),
|
|
85
|
+
defineModel({ id: "gpt-5.4", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 400000, reasoning: true, toolCall: true, vision: true }),
|
|
86
|
+
defineModel({ id: "gpt-5.4-mini", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 400000, reasoning: true, toolCall: true, vision: true }),
|
|
87
|
+
defineModel({ id: "gpt-5.5", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 400000, reasoning: true, toolCall: true, vision: true }),
|
|
88
|
+
defineModel({ id: "gpt-5.6-luna", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1050000, reasoning: true, toolCall: true, vision: true }),
|
|
89
|
+
defineModel({ id: "gpt-5.6-sol", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1050000, reasoning: true, toolCall: true, vision: true }),
|
|
90
|
+
defineModel({ id: "gpt-5.6-terra", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1050000, reasoning: true, toolCall: true, vision: true }),
|
|
91
|
+
defineModel({ id: "gpt-6-astra", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1050000, reasoning: true, toolCall: true, vision: true }),
|
|
92
|
+
defineModel({ id: "gpt-6-luna", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1050000, reasoning: true, toolCall: true, vision: true }),
|
|
93
|
+
defineModel({ id: "gpt-6-sol", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1050000, reasoning: true, toolCall: true, vision: true }),
|
|
94
|
+
defineModel({ id: "gpt-6.1-sol", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1050000, reasoning: true, toolCall: true, vision: true }),
|
|
95
|
+
defineModel({ id: "inclusionai/ling-3.1-flash", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "chat", endpoint: "/chat/completions", ctx: 262144, reasoning: true, toolCall: true, vision: true }),
|
|
96
|
+
defineModel({ id: "meituan/LongCat-2.0", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "chat", endpoint: "/chat/completions", ctx: 1048576, reasoning: true, toolCall: true, vision: true }),
|
|
97
|
+
defineModel({ id: "meta/muse-spark-1.1", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1048576, reasoning: true, toolCall: true, vision: true }),
|
|
98
|
+
defineModel({ id: "meta/muse-spark-1.2", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1048576, reasoning: true, toolCall: true, vision: true }),
|
|
99
|
+
defineModel({ id: "meta/muse-spark-1.2-contributor", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1048576, reasoning: true, toolCall: true, vision: true }),
|
|
100
|
+
defineModel({ id: "meta/muse-spark-1.3", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1048576, reasoning: true, toolCall: true, vision: true }),
|
|
101
|
+
defineModel({ id: "meta/muse-spark-1.3-contributor", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1048576, reasoning: true, toolCall: true, vision: true }),
|
|
102
|
+
defineModel({ id: "meta/muse-spark-open", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1048576, reasoning: true, toolCall: true, vision: true }),
|
|
103
|
+
defineModel({ id: "meta/muse-wonder-1.0", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1048576, reasoning: true, toolCall: true, vision: true }),
|
|
104
|
+
defineModel({ id: "minimax/minimax-m3.1-flash-preview", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
105
|
+
defineModel({ id: "minimax/minimax-m3.1-flash-preview:free", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
106
|
+
defineModel({ id: "mistral/mistral-large-4", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 524288, reasoning: true, toolCall: true, vision: true }),
|
|
107
|
+
defineModel({ id: "moonshotai/Kimi-K2.5", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 256000, reasoning: true, toolCall: true, vision: true }),
|
|
108
|
+
defineModel({ id: "moonshotai/Kimi-K2.6", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 256000, reasoning: true, toolCall: true, vision: true }),
|
|
109
|
+
defineModel({ id: "moonshotai/Kimi-K2.7-Code", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 256000, reasoning: true, toolCall: true, vision: true }),
|
|
110
|
+
defineModel({ id: "moonshotai/Kimi-K2.7-Code-Highspeed", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 262000, reasoning: true, toolCall: true, vision: true }),
|
|
111
|
+
defineModel({ id: "moonshotai/Kimi-K3", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
112
|
+
defineModel({ id: "nvidia/nemotron-3-ultra-550b-a55b", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
113
|
+
defineModel({ id: "nvidia/nemotron-3.5-super-vl", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 262144, reasoning: true, toolCall: true, vision: true }),
|
|
114
|
+
defineModel({ id: "poolside/laguna-s-2.1-free", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 256000, reasoning: true, toolCall: true, vision: true }),
|
|
115
|
+
defineModel({ id: "reflection/beam:free", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1048576, reasoning: true, toolCall: true, vision: true }),
|
|
116
|
+
defineModel({ id: "sakana/fugu-ultra", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
117
|
+
defineModel({ id: "stealth/cat-jam:free", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1048576, reasoning: true, toolCall: true, vision: true }),
|
|
118
|
+
defineModel({ id: "stealth/glyph-cluster:free", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 256000, reasoning: true, toolCall: true, vision: true }),
|
|
119
|
+
defineModel({ id: "stepfun/Step-3.5-Flash", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 262144, reasoning: true, toolCall: true, vision: true }),
|
|
120
|
+
defineModel({ id: "stepfun/Step-3.7-Flash", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 256000, reasoning: true, toolCall: true, vision: true }),
|
|
121
|
+
defineModel({ id: "stepfun/Step-5-Preview", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
122
|
+
defineModel({ id: "tencent/hy3-paid", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 262144, reasoning: true, toolCall: true, vision: true }),
|
|
123
|
+
defineModel({ id: "tencent/hy4-preview", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "chat", endpoint: "/chat/completions", ctx: 1048576, reasoning: true, toolCall: true, vision: true }),
|
|
124
|
+
defineModel({ id: "thinkingmachines/inkling", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 256000, reasoning: true, toolCall: true, vision: true }),
|
|
125
|
+
defineModel({ id: "thinkingmachines/inkling-small", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
126
|
+
defineModel({ id: "xai/grok-4.5", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 500000, reasoning: true, toolCall: true, vision: true }),
|
|
127
|
+
defineModel({ id: "xai/grok-4.6", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 500000, reasoning: true, toolCall: true, vision: true }),
|
|
128
|
+
defineModel({ id: "xai/grok-4.7", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 500000, reasoning: true, toolCall: true, vision: true }),
|
|
129
|
+
defineModel({ id: "xiaomi/mimo-v2.5", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
130
|
+
defineModel({ id: "xiaomi/mimo-v2.5-pro", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
131
|
+
defineModel({ id: "xiaomi/mimo-v2.6-flash", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1048576, reasoning: true, toolCall: true, vision: true }),
|
|
132
|
+
defineModel({ id: "xiaomi/mimo-v2.6-pro", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1048576, reasoning: true, toolCall: true, vision: true }),
|
|
133
|
+
defineModel({ id: "xiaomi/mimo-v2.6-pro-ultraspeed", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1048576, reasoning: true, toolCall: true, vision: true }),
|
|
134
|
+
defineModel({ id: "z-ai/glm-5.3-flash", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "chat", endpoint: "/chat/completions", ctx: 1048576, reasoning: true, toolCall: true, vision: true }),
|
|
135
|
+
defineModel({ id: "z-ai/glm-5.3-flashx", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
136
|
+
defineModel({ id: "zai-org/GLM-5", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 200000, reasoning: true, toolCall: true, vision: true }),
|
|
137
|
+
defineModel({ id: "zai-org/GLM-5.1", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 200000, reasoning: true, toolCall: true, vision: true }),
|
|
138
|
+
defineModel({ id: "zai-org/GLM-5.2", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
139
|
+
defineModel({ id: "zai-org/GLM-5.2-Fast", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
140
|
+
defineModel({ id: "zai-org/GLM-5.3", providerId: COMMANDCODE_PROVIDER_ID, wireFamily: "responses", endpoint: "/responses", ctx: 1000000, reasoning: true, toolCall: true, vision: true }),
|
|
141
|
+
];
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
// CommandCode provider constants.
|
|
145
|
+
|
|
146
|
+
const COMMANDCODE_DEFAULT_MAX_TOKENS = 4096;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The `/alpha/generate` wire, as the CLI client sends it:
|
|
150
|
+
* - `params.system` is a top-level string; system turns never enter `messages`
|
|
151
|
+
* - every `content` is an array of blocks, never a string
|
|
152
|
+
* - an assistant tool call is `{type:"tool-call", toolCallId, toolName, input}`
|
|
153
|
+
* and is preceded by a reasoning block, which the upstream requires
|
|
154
|
+
* - a tool result is its own `role:"tool"` turn, not text glued into the user turn
|
|
155
|
+
* - an image is `{type:"image", image, mimeType}`
|
|
156
|
+
*/
|
|
157
|
+
function toolResultValue(content: readonly ContentPart[] | string): string {
|
|
158
|
+
if (typeof content === "string") return content;
|
|
159
|
+
return content
|
|
160
|
+
.filter((part) => part.kind === "text")
|
|
161
|
+
.map((part) => part.text)
|
|
162
|
+
.filter((text) => text.length > 0)
|
|
163
|
+
.join("\n");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function imageBlock(payload: unknown): Record<string, unknown> | undefined {
|
|
167
|
+
const source = resolveImageSource(payload);
|
|
168
|
+
if (source?.url === undefined) return undefined;
|
|
169
|
+
const inline = splitDataUrl(source.url);
|
|
170
|
+
return { type: "image", image: source.url, ...(inline ? { mimeType: inline.mediaType } : {}) };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function contentBlocks(parts: readonly ContentPart[]): Array<Record<string, unknown>> {
|
|
174
|
+
const blocks: Array<Record<string, unknown>> = [];
|
|
175
|
+
for (const part of parts) {
|
|
176
|
+
if (part.kind === "text") {
|
|
177
|
+
if (part.text.length > 0) blocks.push({ type: "text", text: part.text });
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
if (part.kind === "image") {
|
|
181
|
+
const block = imageBlock(part.payload);
|
|
182
|
+
if (block) blocks.push(block);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return blocks.length > 0 ? blocks : [{ type: "text", text: "" }];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function parsedInput(value: unknown): unknown {
|
|
189
|
+
if (typeof value !== "string") return value ?? {};
|
|
190
|
+
try {
|
|
191
|
+
return JSON.parse(value);
|
|
192
|
+
} catch {
|
|
193
|
+
return {};
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function convertMessages(messages: CanonicalRequest["messages"]): {
|
|
198
|
+
messages: Array<Record<string, unknown>>;
|
|
199
|
+
system?: string;
|
|
200
|
+
} {
|
|
201
|
+
const out: Array<Record<string, unknown>> = [];
|
|
202
|
+
const systemTexts: string[] = [];
|
|
203
|
+
for (const message of messages) {
|
|
204
|
+
if (message.role === "system" || message.role === "developer") {
|
|
205
|
+
const text = joinTextParts(message.content);
|
|
206
|
+
if (text.length > 0) systemTexts.push(text);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
// Answers live in `tool` turns or in `user` turns (the Messages ledger
|
|
210
|
+
// re-homes them). Each result is its own `role:"tool"` turn: flattening
|
|
211
|
+
// them into the user turn as prose left the tool call unanswered.
|
|
212
|
+
if (canContainToolResult(message) && toolResultParts(message).length > 0) {
|
|
213
|
+
for (const result of toolResultParts(message)) {
|
|
214
|
+
out.push({
|
|
215
|
+
role: "tool",
|
|
216
|
+
content: [
|
|
217
|
+
{
|
|
218
|
+
type: "tool-result",
|
|
219
|
+
toolCallId: result.call_id,
|
|
220
|
+
toolName: "",
|
|
221
|
+
output: { type: "text", value: toolResultValue(result.content) },
|
|
222
|
+
},
|
|
223
|
+
],
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
const remainder = contentBlocks(message.content.filter((part) => part.kind !== "toolResult"));
|
|
227
|
+
if (remainder.some((block) => block["text"] !== "")) out.push({ role: "user", content: remainder });
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
if (message.role === "assistant") {
|
|
231
|
+
const blocks: Array<Record<string, unknown>> = [];
|
|
232
|
+
const calls = toolCallParts(message);
|
|
233
|
+
const reasoning = message.content
|
|
234
|
+
.filter((part) => part.kind === "reasoning")
|
|
235
|
+
.map((part) => part.summary ?? "")
|
|
236
|
+
.filter((text) => text.length > 0)
|
|
237
|
+
.join("");
|
|
238
|
+
if (reasoning.length > 0 || calls.length > 0) {
|
|
239
|
+
blocks.push({ type: "reasoning", text: reasoning.length > 0 ? reasoning : " " });
|
|
240
|
+
}
|
|
241
|
+
const text = joinTextParts(message.content);
|
|
242
|
+
if (text.length > 0) blocks.push({ type: "text", text });
|
|
243
|
+
for (const call of calls) {
|
|
244
|
+
blocks.push({
|
|
245
|
+
type: "tool-call",
|
|
246
|
+
toolCallId: call.call_id,
|
|
247
|
+
toolName: call.name,
|
|
248
|
+
input: parsedInput(call.arguments),
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
out.push({ role: "assistant", content: blocks.length > 0 ? blocks : [{ type: "text", text: "" }] });
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
out.push({ role: "user", content: contentBlocks(message.content) });
|
|
255
|
+
}
|
|
256
|
+
const system = systemTexts.join("\n\n");
|
|
257
|
+
return system.length > 0 ? { messages: out, system } : { messages: out };
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Whether a tool schema needs Gemini's normalized form.
|
|
262
|
+
*
|
|
263
|
+
* The client rewrites a schema for `google/gemini-*` because the gateway can
|
|
264
|
+
* turn nullable type arrays into `any_of` with sibling fields, which Vertex
|
|
265
|
+
* rejects. This provider routes Gemini over the same Provider API, so the same
|
|
266
|
+
* rewrite applies.
|
|
267
|
+
*/
|
|
268
|
+
export function isGeminiModelId(modelId: string): boolean {
|
|
269
|
+
return modelId.startsWith("google/gemini-");
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const SCHEMA_MAP_FIELDS = new Set([
|
|
273
|
+
"$defs",
|
|
274
|
+
"definitions",
|
|
275
|
+
"dependentSchemas",
|
|
276
|
+
"patternProperties",
|
|
277
|
+
"properties",
|
|
278
|
+
]);
|
|
279
|
+
const SCHEMA_ARRAY_FIELDS = new Set(["allOf", "anyOf", "oneOf", "prefixItems"]);
|
|
280
|
+
const SCHEMA_VALUE_FIELDS = new Set([
|
|
281
|
+
"additionalItems",
|
|
282
|
+
"additionalProperties",
|
|
283
|
+
"contains",
|
|
284
|
+
"contentSchema",
|
|
285
|
+
"else",
|
|
286
|
+
"if",
|
|
287
|
+
"items",
|
|
288
|
+
"not",
|
|
289
|
+
"propertyNames",
|
|
290
|
+
"then",
|
|
291
|
+
"unevaluatedItems",
|
|
292
|
+
"unevaluatedProperties",
|
|
293
|
+
]);
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* A schema Gemini's transport accepts: a single type plus `nullable`, with null
|
|
297
|
+
* defaults dropped. Genuine multi-type unions and `required` are left alone —
|
|
298
|
+
* only the nullable-array spelling is what Vertex rejects.
|
|
299
|
+
*/
|
|
300
|
+
export function geminiSafeSchema(value: unknown): unknown {
|
|
301
|
+
if (Array.isArray(value)) return value.map(geminiSafeSchema);
|
|
302
|
+
if (!isRecord(value)) return value;
|
|
303
|
+
const out: Record<string, unknown> = {};
|
|
304
|
+
for (const [key, raw] of Object.entries(value)) {
|
|
305
|
+
if (key === "default" && raw === null) continue;
|
|
306
|
+
if (SCHEMA_MAP_FIELDS.has(key) && isRecord(raw)) {
|
|
307
|
+
out[key] = Object.fromEntries(
|
|
308
|
+
Object.entries(raw).map(([name, child]) => [name, geminiSafeSchema(child)]),
|
|
309
|
+
);
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
out[key] = SCHEMA_ARRAY_FIELDS.has(key) || SCHEMA_VALUE_FIELDS.has(key)
|
|
313
|
+
? geminiSafeSchema(raw)
|
|
314
|
+
: raw;
|
|
315
|
+
}
|
|
316
|
+
// A nullable type array becomes one type plus `nullable`.
|
|
317
|
+
if (Array.isArray(out["type"])) {
|
|
318
|
+
const types = out["type"].filter((entry): entry is string => typeof entry === "string");
|
|
319
|
+
const withoutNull = types.filter((entry) => entry !== "null");
|
|
320
|
+
if (types.length !== withoutNull.length && withoutNull.length > 0) {
|
|
321
|
+
out["type"] = withoutNull.length === 1 ? withoutNull[0] : withoutNull;
|
|
322
|
+
out["nullable"] = true;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return out;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export function buildRequest(
|
|
329
|
+
modelId: string,
|
|
330
|
+
request: { messages: CanonicalRequest["messages"]; tools: { readonly name: string; readonly description: string | undefined; readonly jsonSchema: unknown }[]; maxOutputTokens: number | null; temperature: number | null; topP: number | null; reasoningEffort: string | null },
|
|
331
|
+
threadId: string,
|
|
332
|
+
systemExtra?: string,
|
|
333
|
+
): Record<string, unknown> {
|
|
334
|
+
const { messages, system: systemFromMessages } = convertMessages(request.messages);
|
|
335
|
+
const systemCombined = systemExtra ? (systemFromMessages ? `${systemExtra}\n${systemFromMessages}` : systemExtra) : systemFromMessages;
|
|
336
|
+
const params: Record<string, unknown> = {
|
|
337
|
+
model: modelId,
|
|
338
|
+
messages,
|
|
339
|
+
stream: true,
|
|
340
|
+
max_tokens: request.maxOutputTokens ?? COMMANDCODE_DEFAULT_MAX_TOKENS,
|
|
341
|
+
temperature: request.temperature ?? 0.3,
|
|
342
|
+
};
|
|
343
|
+
if (request.topP !== null) params["top_p"] = request.topP;
|
|
344
|
+
if (request.reasoningEffort !== null && request.reasoningEffort !== "none") {
|
|
345
|
+
params["reasoning_effort"] = request.reasoningEffort;
|
|
346
|
+
}
|
|
347
|
+
if (systemCombined) params["system"] = systemCombined;
|
|
348
|
+
if (request.tools.length > 0) {
|
|
349
|
+
params["tools"] = request.tools.map((tool) => ({
|
|
350
|
+
// `type: "function"` is part of the envelope. The reference client sends
|
|
351
|
+
// it on every tool, and a tool without it is not recognised as callable.
|
|
352
|
+
type: "function",
|
|
353
|
+
name: tool.name,
|
|
354
|
+
description: tool.description ?? undefined,
|
|
355
|
+
input_schema: isGeminiModelId(modelId) ? geminiSafeSchema(tool.jsonSchema) : tool.jsonSchema,
|
|
356
|
+
}));
|
|
357
|
+
}
|
|
358
|
+
return {
|
|
359
|
+
threadId,
|
|
360
|
+
// The client sends these three as `null`, not `""` / absent. `memory` was
|
|
361
|
+
// an empty string and `taste`/`skills` were missing entirely; the envelope
|
|
362
|
+
// is validated, so an absent field is not the same as a null one.
|
|
363
|
+
memory: null,
|
|
364
|
+
taste: null,
|
|
365
|
+
skills: null,
|
|
366
|
+
config: {
|
|
367
|
+
workingDir: "",
|
|
368
|
+
date: new Date().toISOString().slice(0, 10),
|
|
369
|
+
// The client reports the real runtime: `linux-x64, Node.js v24.0.0`.
|
|
370
|
+
// An empty string is a blank attribution field the upstream never sees
|
|
371
|
+
// filled, which is indistinguishable from a client that did not report.
|
|
372
|
+
environment: `${process.platform}-${process.arch}, Node.js ${process.version}`,
|
|
373
|
+
structure: [],
|
|
374
|
+
isGitRepo: false,
|
|
375
|
+
currentBranch: "",
|
|
376
|
+
mainBranch: "",
|
|
377
|
+
gitStatus: "",
|
|
378
|
+
recentCommits: [],
|
|
379
|
+
},
|
|
380
|
+
params,
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* The identity headers Command Code's own client sends.
|
|
386
|
+
*
|
|
387
|
+
* `x-cli-environment` is `production`, not `cli` — that is the value the client
|
|
388
|
+
* sends, and the pair is what identifies the surface to the gateway.
|
|
389
|
+
*
|
|
390
|
+
* `x-project-slug` and `x-taste-learning` were simply absent. Both are
|
|
391
|
+
* attribution fields the client always sends; the slug is derived from the
|
|
392
|
+
* working directory the same way the client derives it.
|
|
393
|
+
*
|
|
394
|
+
* `x-session-id` is sent only when a session exists. The client omits it rather
|
|
395
|
+
* than inventing one, and a value minted per request would attribute every
|
|
396
|
+
* call to a different session.
|
|
397
|
+
*/
|
|
398
|
+
export async function headers(sessionId: string, token: string): Promise<Record<string, string>> {
|
|
399
|
+
return {
|
|
400
|
+
"content-type": "application/json",
|
|
401
|
+
accept: "text/event-stream",
|
|
402
|
+
authorization: `Bearer ${token}`,
|
|
403
|
+
"x-command-code-version": getCommandCodeVersion(),
|
|
404
|
+
"x-cli-environment": "production",
|
|
405
|
+
"x-taste-learning": "true",
|
|
406
|
+
"x-project-slug": "cartethyia",
|
|
407
|
+
"user-agent": "cli",
|
|
408
|
+
...(sessionId.length > 0 ? { "x-session-id": sessionId } : {}),
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
type StreamState = { toolIndexById: Map<string, number>; nextToolIndex: number; finishReason: string | undefined; usage: Record<string, unknown> | undefined; think: MimoThinkSplitter };
|
|
414
|
+
|
|
415
|
+
export function ccMapFinishReason(reason: string): CanonicalStopReason {
|
|
416
|
+
return reason === "length" ? "length" : reason === "tool_calls" ? "tool_use" : reason === "content_filter" ? "content_filter" : "stop";
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
export function transformLine(line: string, state: StreamState, seqBase: number): CanonicalEvent[] {
|
|
420
|
+
let event: Record<string, unknown>;
|
|
421
|
+
try {
|
|
422
|
+
event = JSON.parse(line) as Record<string, unknown>;
|
|
423
|
+
} catch {
|
|
424
|
+
return [];
|
|
425
|
+
}
|
|
426
|
+
const type = readString(event, "type");
|
|
427
|
+
if (!type) return [];
|
|
428
|
+
if (type === "reasoning-delta") {
|
|
429
|
+
const text = readString(event, "text") || readString(event, "delta");
|
|
430
|
+
return text ? [{ type: "content_delta", sequence_number: seqBase, content: { kind: "reasoning", payload: null, summary: text } } as CanonicalEvent] : [];
|
|
431
|
+
}
|
|
432
|
+
if (type === "text-delta") {
|
|
433
|
+
const text = readString(event, "text") || readString(event, "delta");
|
|
434
|
+
if (!text) return [];
|
|
435
|
+
const split = state.think.push(text);
|
|
436
|
+
const events: CanonicalEvent[] = [];
|
|
437
|
+
if (split.reasoning) events.push({ type: "content_delta", sequence_number: seqBase, content: { kind: "reasoning", payload: null, summary: split.reasoning } } as CanonicalEvent);
|
|
438
|
+
if (split.text) events.push({ type: "content_delta", sequence_number: seqBase, content: { kind: "text", text: split.text } } as CanonicalEvent);
|
|
439
|
+
return events;
|
|
440
|
+
}
|
|
441
|
+
if (type === "tool-input-start") {
|
|
442
|
+
const id = readString(event, "id") || readString(event, "toolCallId");
|
|
443
|
+
if (!id || state.toolIndexById.has(id)) return [];
|
|
444
|
+
state.toolIndexById.set(id, state.nextToolIndex++);
|
|
445
|
+
return [{ type: "tool_call_delta", sequence_number: seqBase, call_id: id, name: readString(event, "toolName") ?? "", arguments_delta: "" } as CanonicalEvent];
|
|
446
|
+
}
|
|
447
|
+
if (type === "tool-input-delta") {
|
|
448
|
+
const id = readString(event, "id") || readString(event, "toolCallId");
|
|
449
|
+
const delta = readString(event, "delta") || readString(event, "inputTextDelta");
|
|
450
|
+
if (!id || !delta || !state.toolIndexById.has(id)) return [];
|
|
451
|
+
return [{ type: "tool_call_delta", sequence_number: seqBase, call_id: id, arguments_delta: delta } as CanonicalEvent];
|
|
452
|
+
}
|
|
453
|
+
if (type === "tool-call") {
|
|
454
|
+
const id = readString(event, "toolCallId");
|
|
455
|
+
if (!id || state.toolIndexById.has(id)) return [];
|
|
456
|
+
state.toolIndexById.set(id, state.nextToolIndex++);
|
|
457
|
+
const input = typeof event["input"] === "string" ? (event["input"] as string) : JSON.stringify(event["input"] ?? {});
|
|
458
|
+
return [
|
|
459
|
+
{ type: "tool_call_delta", sequence_number: seqBase, call_id: id, name: readString(event, "toolName") ?? "", arguments_delta: "" } as CanonicalEvent,
|
|
460
|
+
{ type: "tool_call_delta", sequence_number: seqBase + 1, call_id: id, arguments_delta: input } as CanonicalEvent,
|
|
461
|
+
];
|
|
462
|
+
}
|
|
463
|
+
if (type === "finish-step") {
|
|
464
|
+
const reason = readString(event, "finishReason");
|
|
465
|
+
if (reason) state.finishReason = reason;
|
|
466
|
+
if (typeof event["usage"] === "object" && event["usage"] !== null && !Array.isArray(event["usage"])) state.usage = event["usage"] as Record<string, unknown>;
|
|
467
|
+
return [];
|
|
468
|
+
}
|
|
469
|
+
if (type === "finish") {
|
|
470
|
+
const reason = state.finishReason ?? readString(event, "finishReason") ?? "stop";
|
|
471
|
+
const canonicalReason = ccMapFinishReason(reason);
|
|
472
|
+
const events: CanonicalEvent[] = [
|
|
473
|
+
{ type: "terminal", sequence_number: seqBase, state: "complete", stop_reason: canonicalReason, provider_stop_reason: reason } as CanonicalEvent,
|
|
474
|
+
];
|
|
475
|
+
if (state.usage) {
|
|
476
|
+
const prompt = readNumber(state.usage, "promptTokens") ?? readNumber(state.usage, "inputTokens") ?? 0;
|
|
477
|
+
const completion = readNumber(state.usage, "completionTokens") ?? readNumber(state.usage, "outputTokens") ?? 0;
|
|
478
|
+
const total = readNumber(state.usage, "totalTokens") ?? prompt + completion;
|
|
479
|
+
const cached = readNumber(state.usage, "cachedTokens") ?? readNumber(state.usage, "cacheReadTokens") ?? 0;
|
|
480
|
+
const usageRecord = usageFromProvider({
|
|
481
|
+
input_tokens: prompt,
|
|
482
|
+
output_tokens: completion,
|
|
483
|
+
total_tokens: total,
|
|
484
|
+
cached_tokens: cached,
|
|
485
|
+
cache_creation_input_tokens: readNumber(state.usage, "cacheWriteTokens") ?? undefined,
|
|
486
|
+
} as unknown as Record<string, unknown>);
|
|
487
|
+
// Append usage to terminal
|
|
488
|
+
(events[0] as unknown as Record<string, unknown>)["usage"] = usageRecord;
|
|
489
|
+
}
|
|
490
|
+
return events;
|
|
491
|
+
}
|
|
492
|
+
if (type === "error") {
|
|
493
|
+
const raw = event["error"] ?? event["message"] ?? event;
|
|
494
|
+
const errorObject = isRecord(raw) ? raw : event;
|
|
495
|
+
const identifier = upstreamErrorIdentifier(raw) ?? upstreamErrorIdentifier(event);
|
|
496
|
+
const providerStatus = [
|
|
497
|
+
errorObject["status"],
|
|
498
|
+
errorObject["statusCode"],
|
|
499
|
+
errorObject["code"],
|
|
500
|
+
event["status"],
|
|
501
|
+
event["statusCode"],
|
|
502
|
+
event["code"],
|
|
503
|
+
].find(
|
|
504
|
+
(value): value is number =>
|
|
505
|
+
typeof value === "number" &&
|
|
506
|
+
Number.isFinite(value) &&
|
|
507
|
+
value >= 400 &&
|
|
508
|
+
value < 600,
|
|
509
|
+
);
|
|
510
|
+
const classification = classifyUpstreamError(providerStatus, identifier);
|
|
511
|
+
const message =
|
|
512
|
+
extractUpstreamMessage(raw) ||
|
|
513
|
+
extractUpstreamMessage(event) ||
|
|
514
|
+
"Command Code stream error";
|
|
515
|
+
throw new GatewayError(
|
|
516
|
+
classification.code,
|
|
517
|
+
classification.status,
|
|
518
|
+
message.slice(0, 500),
|
|
519
|
+
{
|
|
520
|
+
...(providerStatus === undefined ? {} : { providerStatus }),
|
|
521
|
+
...(identifier ? { providerCode: identifier } : {}),
|
|
522
|
+
...(classification.credentialEvidence ? { credentialEvidence: true } : {}),
|
|
523
|
+
...(classification.rateLimitScope
|
|
524
|
+
? { rateLimitScope: classification.rateLimitScope }
|
|
525
|
+
: {}),
|
|
526
|
+
},
|
|
527
|
+
classification.origin,
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
return [];
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/** NDJSON transform — beta-style simple loop + signal-aware read for abort/timeout propagation. */
|
|
534
|
+
export async function* transformNdjson(body: ReadableStream<Uint8Array>, signal: AbortSignal): AsyncIterable<CanonicalEvent> {
|
|
535
|
+
const reader = body.getReader();
|
|
536
|
+
const decoder = new TextDecoder();
|
|
537
|
+
const state: StreamState = { toolIndexById: new Map(), nextToolIndex: 0, finishReason: undefined, usage: undefined, think: new MimoThinkSplitter() };
|
|
538
|
+
let buffer = "";
|
|
539
|
+
let hasTerminal = false;
|
|
540
|
+
let seq = 1;
|
|
541
|
+
// initial response_start
|
|
542
|
+
yield { type: "response_start", sequence_number: seq++, model: "commandcode" } as CanonicalEvent;
|
|
543
|
+
|
|
544
|
+
const readWithAbort = (): Promise<{ done: boolean; value?: Uint8Array }> => {
|
|
545
|
+
if (signal.aborted) throw new GatewayError("transport_closed", 499, "Command Code stream aborted");
|
|
546
|
+
const { promise, resolve, reject } = Promise.withResolvers<{ done: boolean; value?: Uint8Array }>() as unknown as { promise: Promise<{ done: boolean; value?: Uint8Array }>; resolve: (v: unknown) => void; reject: (e: unknown) => void };
|
|
547
|
+
const onAbort = (): void => {
|
|
548
|
+
if (signal.aborted) reject(new GatewayError("transport_closed", 499, "Command Code stream aborted"));
|
|
549
|
+
else reject(new GatewayError("platform_unavailable", 502, "Command Code stream error", {}, "upstream"));
|
|
550
|
+
};
|
|
551
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
552
|
+
void reader.read().then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
|
|
553
|
+
return promise;
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
try {
|
|
557
|
+
while (true) {
|
|
558
|
+
const { done, value } = await readWithAbort();
|
|
559
|
+
if (done) break;
|
|
560
|
+
buffer += decoder.decode(value, { stream: true });
|
|
561
|
+
let nl = buffer.indexOf("\n");
|
|
562
|
+
while (nl !== -1) {
|
|
563
|
+
const line = buffer.slice(0, nl).trim();
|
|
564
|
+
buffer = buffer.slice(nl + 1);
|
|
565
|
+
if (line) {
|
|
566
|
+
let evs: CanonicalEvent[] = [];
|
|
567
|
+
try {
|
|
568
|
+
evs = transformLine(line, state, seq);
|
|
569
|
+
} catch (e) {
|
|
570
|
+
throw e;
|
|
571
|
+
}
|
|
572
|
+
for (const ev of evs) {
|
|
573
|
+
// Strictly increasing per line, in emission order: the Responses
|
|
574
|
+
// surface throws on any non-monotonic sequence mid-stream, after
|
|
575
|
+
// partial bytes are already flushed. No special-casing for
|
|
576
|
+
// dual-event lines — order is order.
|
|
577
|
+
(ev as unknown as Record<string, unknown>)["sequence_number"] = seq++;
|
|
578
|
+
if (ev.type === "terminal") hasTerminal = true;
|
|
579
|
+
yield ev;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
nl = buffer.indexOf("\n");
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
buffer += decoder.decode();
|
|
586
|
+
const tail = buffer.trim();
|
|
587
|
+
if (tail) {
|
|
588
|
+
for (const ev of transformLine(tail, state, seq)) {
|
|
589
|
+
if (ev.type === "terminal") hasTerminal = true;
|
|
590
|
+
(ev as unknown as Record<string, unknown>)["sequence_number"] = seq++;
|
|
591
|
+
yield ev;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
const rest = state.think.flush();
|
|
595
|
+
if (rest.reasoning) yield { type: "content_delta", sequence_number: seq++, content: { kind: "reasoning", payload: null, summary: rest.reasoning } } as CanonicalEvent;
|
|
596
|
+
if (rest.text) yield { type: "content_delta", sequence_number: seq++, content: { kind: "text", text: rest.text } } as CanonicalEvent;
|
|
597
|
+
if (!hasTerminal) {
|
|
598
|
+
// NDJSON ended with no terminal envelope: truncated, never complete.
|
|
599
|
+
yield { type: "terminal", sequence_number: seq++, state: "failed", stop_reason: ccMapFinishReason(state.finishReason ?? "stop"), provider_stop_reason: state.finishReason ?? "stop" } as CanonicalEvent;
|
|
600
|
+
}
|
|
601
|
+
} finally {
|
|
602
|
+
try {
|
|
603
|
+
reader.releaseLock?.();
|
|
604
|
+
} catch {
|
|
605
|
+
// Best-effort reader unlock during stream cleanup.
|
|
606
|
+
}
|
|
607
|
+
void reader.cancel().catch(() => {});
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// CommandCode model catalog.
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
// ProviderAdapter — the Provider API serves three wires, so dispatch is the
|
|
616
|
+
// shared OpenAI-compatible adapter rather than one bespoke NDJSON reader.
|
|
617
|
+
//
|
|
618
|
+
// `/provider/v1` answers `/chat/completions`, `/responses` and `/messages`, and
|
|
619
|
+
// the model row states which one serves it. The bespoke `/alpha/generate`
|
|
620
|
+
// envelope is the CLI's own surface and stays reachable through
|
|
621
|
+
// `buildRequest` for callers that still speak it, while routing follows the
|
|
622
|
+
// wire each model row declares rather than forcing every model onto it.
|
|
623
|
+
|
|
624
|
+
interface CommandCodeAdapterOptions {
|
|
625
|
+
readonly fetch?: typeof fetch;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
function commandCodeIdentityHeaders(_token: string): Record<string, string> {
|
|
629
|
+
return {
|
|
630
|
+
"x-command-code-version": getCommandCodeVersion(),
|
|
631
|
+
"x-cli-environment": "production",
|
|
632
|
+
"x-taste-learning": "true",
|
|
633
|
+
"x-project-slug": "cartethyia",
|
|
634
|
+
"user-agent": "cli",
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
function providerApiAdapter(options: CommandCodeAdapterOptions): ProviderAdapter {
|
|
639
|
+
return createApiKeyAdapter(
|
|
640
|
+
{
|
|
641
|
+
provider_id: COMMANDCODE_PROVIDER_ID,
|
|
642
|
+
base_url: COMMANDCODE_BASE_URL,
|
|
643
|
+
endpoint_paths_by_wire_family: {
|
|
644
|
+
chat: COMMANDCODE_CHAT_PATH,
|
|
645
|
+
responses: COMMANDCODE_RESPONSES_PATH,
|
|
646
|
+
messages: COMMANDCODE_MESSAGES_PATH,
|
|
647
|
+
},
|
|
648
|
+
buildExtraHeaders: async (context: ProviderDispatchContext) =>
|
|
649
|
+
commandCodeIdentityHeaders(await readCredentialSecret(context.credential, "Command Code bearer token is required")),
|
|
650
|
+
},
|
|
651
|
+
options.fetch,
|
|
652
|
+
);
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
class CommandCodeAdapter implements ProviderAdapter {
|
|
656
|
+
readonly provider_id = COMMANDCODE_PROVIDER_ID;
|
|
657
|
+
private readonly inner: ProviderAdapter;
|
|
658
|
+
|
|
659
|
+
constructor(options: CommandCodeAdapterOptions = {}) {
|
|
660
|
+
this.inner = providerApiAdapter(options);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
dispatch(
|
|
664
|
+
request: CanonicalRequest,
|
|
665
|
+
candidate: ProviderDispatchTarget,
|
|
666
|
+
context: ProviderDispatchContext,
|
|
667
|
+
): AsyncIterable<CanonicalEvent> {
|
|
668
|
+
return this.inner.dispatch(request, candidate, context);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
export function createCommandCodeAdapter(options: CommandCodeAdapterOptions = {}): ProviderAdapter {
|
|
673
|
+
return new CommandCodeAdapter(options);
|
|
674
|
+
}
|