cartethyia 2.7.8 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +3 -3
- package/README.md +29 -59
- package/dist/dashboard/assets/BannedPage-Cc0vKpMG.js +1 -0
- package/dist/dashboard/assets/BannedPage-Cc0vKpMG.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolDetailPage-BRWKPQPf.js → CliToolDetailPage-Bqj2aa1T.js} +1 -1
- package/dist/dashboard/assets/CliToolDetailPage-Bqj2aa1T.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolsPage-BP-Y5iHN.js → CliToolsPage-CXsaOAO2.js} +1 -1
- package/dist/dashboard/assets/CliToolsPage-CXsaOAO2.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-BeLpJ4ma.js +1 -0
- package/dist/dashboard/assets/CombosPage-BeLpJ4ma.js.gz +0 -0
- package/dist/dashboard/assets/ConsoleLogPage-DnV0uZ3m.js +1 -0
- package/dist/dashboard/assets/ConsoleLogPage-DnV0uZ3m.js.gz +0 -0
- package/dist/dashboard/assets/CustomizationPage-CBxAjo63.js +1 -0
- package/dist/dashboard/assets/CustomizationPage-CBxAjo63.js.gz +0 -0
- package/dist/dashboard/assets/HealthEventsModal-B5yEE0k6.js +1 -0
- package/dist/dashboard/assets/HealthEventsModal-B5yEE0k6.js.gz +0 -0
- package/dist/dashboard/assets/{InjectSystemPromptPanel-Cv-2Ol_K.js → InjectSystemPromptPanel-BWFLECmz.js} +2 -2
- package/dist/dashboard/assets/InjectSystemPromptPanel-BWFLECmz.js.gz +0 -0
- package/dist/dashboard/assets/{LoginPage-bKfz_b1K.js → LoginPage-CgoPc5B9.js} +1 -1
- package/dist/dashboard/assets/LoginPage-CgoPc5B9.js.gz +0 -0
- package/dist/dashboard/assets/{ModelPicker-B-WQxx_H.js → ModelPicker-D9bFQern.js} +1 -1
- package/dist/dashboard/assets/ModelPicker-D9bFQern.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-B_p4tL8k.js +1 -0
- package/dist/dashboard/assets/OverviewPage-B_p4tL8k.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-rs5E2rxv.js +8 -0
- package/dist/dashboard/assets/ProviderDetailPage-rs5E2rxv.js.gz +0 -0
- package/dist/dashboard/assets/ProviderIcon-D_0PiZtg.js +1 -0
- package/dist/dashboard/assets/ProviderIcon-D_0PiZtg.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-CLI2bJTK.js +1 -0
- package/dist/dashboard/assets/ProvidersPage-CLI2bJTK.js.gz +0 -0
- package/dist/dashboard/assets/{ProxyPage-emlTuxz6.js → ProxyPage-BwNC_-Cx.js} +1 -1
- package/dist/dashboard/assets/ProxyPage-BwNC_-Cx.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-DA-a1iSN.js +1 -0
- package/dist/dashboard/assets/QuotaPage-DA-a1iSN.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-CctTga2C.js +1 -0
- package/dist/dashboard/assets/SettingsPage-CctTga2C.js.gz +0 -0
- package/dist/dashboard/assets/{SetupPage-CUZrKs9r.js → SetupPage-febLU4r1.js} +1 -1
- package/dist/dashboard/assets/SetupPage-febLU4r1.js.gz +0 -0
- package/dist/dashboard/assets/{StudioPage-jWmUdDpy.js → StudioPage-M6fvR5Wz.js} +1 -1
- package/dist/dashboard/assets/StudioPage-M6fvR5Wz.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-nyeuRqz9.js +56 -0
- package/dist/dashboard/assets/UsagePage-nyeuRqz9.js.gz +0 -0
- package/dist/dashboard/assets/api-keys-BFOlvrJC.js +1 -0
- package/dist/dashboard/assets/api-keys-BFOlvrJC.js.gz +0 -0
- package/dist/dashboard/assets/app-Dx2QgsNj.css +2 -0
- package/dist/dashboard/assets/app-Dx2QgsNj.css.gz +0 -0
- package/dist/dashboard/assets/{assert-CidQVoNo.js → assert-CqTLw5e7.js} +1 -1
- package/dist/dashboard/assets/assert-CqTLw5e7.js.gz +0 -0
- package/dist/dashboard/assets/{badge-DyI_mJfi.js → badge-C83EqLB0.js} +1 -1
- package/dist/dashboard/assets/badge-C83EqLB0.js.gz +0 -0
- package/dist/dashboard/assets/ban-durations-B58FyRxC.js +1 -0
- package/dist/dashboard/assets/ban-durations-B58FyRxC.js.gz +0 -0
- package/dist/dashboard/assets/{banner-B-yXtCqb.js → banner-D1xn7pIe.js} +1 -1
- package/dist/dashboard/assets/banner-D1xn7pIe.js.gz +0 -0
- package/dist/dashboard/assets/brand/bansos_page.webp +0 -0
- package/dist/dashboard/assets/brand/denia_bansos.webp +0 -0
- package/dist/dashboard/assets/brand/favicon.webp +0 -0
- package/dist/dashboard/assets/brand/login_register.webp +0 -0
- package/dist/dashboard/assets/brand/login_register_initial.webp +0 -0
- package/dist/dashboard/assets/brand/og_bansos.webp +0 -0
- package/dist/dashboard/assets/brand/og_image.webp +0 -0
- package/dist/dashboard/assets/brand/sidebar_ico.webp +0 -0
- package/dist/dashboard/assets/{card-_HwAEqFF.js → card-DU3Lq5Lm.js} +1 -1
- package/dist/dashboard/assets/card-DU3Lq5Lm.js.gz +0 -0
- package/dist/dashboard/assets/cli-tools-Dw1U_drK.js +1 -0
- package/dist/dashboard/assets/cli-tools-Dw1U_drK.js.gz +0 -0
- package/dist/dashboard/assets/{clipboard-button-ByjCk0o9.js → clipboard-button-CEL5Sg_J.js} +1 -1
- package/dist/dashboard/assets/clipboard-button-CEL5Sg_J.js.gz +0 -0
- package/dist/dashboard/assets/{dialog-BZhOlfz-.js → dialog-BjFR5UHy.js} +1 -1
- package/dist/dashboard/assets/dialog-BjFR5UHy.js.gz +0 -0
- package/dist/dashboard/assets/{drawer-BADqIRYP.js → drawer-HvBW0AjI.js} +1 -1
- package/dist/dashboard/assets/drawer-HvBW0AjI.js.gz +0 -0
- package/dist/dashboard/assets/entry-BSu3gFlt.js +4 -0
- package/dist/dashboard/assets/entry-BSu3gFlt.js.gz +0 -0
- package/dist/dashboard/assets/{entry-COaC-irN.js → entry-CECVELyy.js} +1 -1
- package/dist/dashboard/assets/entry-CECVELyy.js.gz +0 -0
- package/dist/dashboard/assets/entry-DYYofQ7W.js +1 -0
- package/dist/dashboard/assets/entry-DYYofQ7W.js.gz +0 -0
- package/dist/dashboard/assets/{formatters-DcHJyRiu.js → formatters-DLW4i8zK.js} +1 -1
- package/dist/dashboard/assets/formatters-DLW4i8zK.js.gz +0 -0
- package/dist/dashboard/assets/{index-CgKmFngv.js → index-1-fCqe64.js} +2 -2
- package/dist/dashboard/assets/index-1-fCqe64.js.gz +0 -0
- package/dist/dashboard/assets/{inline-B2BirKry.js → inline-DGvU2oLK.js} +1 -1
- package/dist/dashboard/assets/inline-DGvU2oLK.js.gz +0 -0
- package/dist/dashboard/assets/{input-D-qV9dKY.js → input-iNnO1X2K.js} +1 -1
- package/dist/dashboard/assets/input-iNnO1X2K.js.gz +0 -0
- package/dist/dashboard/assets/{layout-B7tVWhtV.js → layout-0q8UGypb.js} +1 -1
- package/dist/dashboard/assets/layout-0q8UGypb.js.gz +0 -0
- package/dist/dashboard/assets/{list-row-CtkGE3bF.js → list-row-C0w2bQjJ.js} +1 -1
- package/dist/dashboard/assets/list-row-C0w2bQjJ.js.gz +0 -0
- package/dist/dashboard/assets/{live-DGizF06-.js → live-M5aJ_xCa.js} +1 -1
- package/dist/dashboard/assets/live-M5aJ_xCa.js.gz +0 -0
- package/dist/dashboard/assets/{mutation-GU7XdEjz.js → mutation-BQ0ccH_A.js} +1 -1
- package/dist/dashboard/assets/mutation-BQ0ccH_A.js.gz +0 -0
- package/dist/dashboard/assets/{network-C9UE-bOr.js → network-BKeQGT3K.js} +1 -1
- package/dist/dashboard/assets/network-BKeQGT3K.js.gz +0 -0
- package/dist/dashboard/assets/{numbers-BnAd22a_.js → numbers-CivAk3da.js} +1 -1
- package/dist/dashboard/assets/numbers-CivAk3da.js.gz +0 -0
- package/dist/dashboard/assets/{pagination-BAywyMzS.js → pagination-CpzvI5ep.js} +1 -1
- package/dist/dashboard/assets/pagination-CpzvI5ep.js.gz +0 -0
- package/dist/dashboard/assets/providers/devin.svg +9 -0
- package/dist/dashboard/assets/providers/devin.svg.gz +0 -0
- package/dist/dashboard/assets/providers/windsurf.svg +10 -0
- package/dist/dashboard/assets/providers/windsurf.svg.gz +0 -0
- package/dist/dashboard/assets/providers/zro.svg +3 -0
- package/dist/dashboard/assets/providers/zro.svg.gz +0 -0
- package/dist/dashboard/assets/{query-keys-YSoQOUh6.js → query-keys-IKLh0YFd.js} +1 -1
- package/dist/dashboard/assets/query-keys-IKLh0YFd.js.gz +0 -0
- package/dist/dashboard/assets/quota-DiPD6UKH.js +1 -0
- package/dist/dashboard/assets/quota-DiPD6UKH.js.gz +0 -0
- package/dist/dashboard/assets/routing-BFQX2VBc.js +1 -0
- package/dist/dashboard/assets/routing-BFQX2VBc.js.gz +0 -0
- package/dist/dashboard/assets/{select-BCOcv8WK.js → select-CXbck0jG.js} +2 -2
- package/dist/dashboard/assets/select-CXbck0jG.js.gz +0 -0
- package/dist/dashboard/assets/settings-C_XvMHh9.js +1 -0
- package/dist/dashboard/assets/settings-C_XvMHh9.js.gz +0 -0
- package/dist/dashboard/assets/{stack-ByKt3Q1g.js → stack-DggRiCxE.js} +1 -1
- package/dist/dashboard/assets/stack-DggRiCxE.js.gz +0 -0
- package/dist/dashboard/assets/{state-DXbGTx7N.js → state-ClFzfbYp.js} +1 -1
- package/dist/dashboard/assets/state-ClFzfbYp.js.gz +0 -0
- package/dist/dashboard/assets/story/25817331.webp +0 -0
- package/dist/dashboard/assets/story/Shorekeeper.webp +0 -0
- package/dist/dashboard/assets/story/cartethyia-god.webp +0 -0
- package/dist/dashboard/assets/story/fleurdelys_plus.webp +0 -0
- package/dist/dashboard/assets/story/jinhsi-blossom.webp +0 -0
- package/dist/dashboard/assets/story/phrolova-a.webp +0 -0
- package/dist/dashboard/assets/story/requestdeniawokkjpg.webp +0 -0
- package/dist/dashboard/assets/story/wuthering-waves-hiyuki-aemeath-hiyuki-rover.webp +0 -0
- package/dist/dashboard/assets/{switch-ZeTsW623.js → switch-CTIFxKqS.js} +1 -1
- package/dist/dashboard/assets/switch-CTIFxKqS.js.gz +0 -0
- package/dist/dashboard/assets/{useMutation-CbCP4w1o.js → useMutation-BClG3yWj.js} +1 -1
- package/dist/dashboard/assets/useMutation-BClG3yWj.js.gz +0 -0
- package/dist/dashboard/console-backgrounds.webp +0 -0
- package/dist/dashboard/console-backgrounds_initial.webp +0 -0
- package/dist/dashboard/donation/qris-risun-marke.webp +0 -0
- package/dist/dashboard/index.html +3 -3
- package/dist/dashboard/index.html.gz +0 -0
- package/dist/dashboard/precompressed-assets.json +59 -56
- package/migrations/full-postgres/0044_add_models_warning_metadata.sql +10 -0
- package/migrations/full-postgres/0045_migrate_workbuddy_to_codebuddy.sql +156 -0
- package/migrations/full-postgres/0046_add_accounts_quota_plan_fetched_at.sql +7 -0
- package/migrations/lite-sqlite3/0044_add_models_warning_metadata.sql +11 -0
- package/migrations/lite-sqlite3/0045_migrate_workbuddy_to_codebuddy.sql +156 -0
- package/migrations/lite-sqlite3/0046_add_accounts_quota_plan_fetched_at.sql +4 -0
- package/package.json +1 -1
- package/src/boot/app.ts +10 -13
- package/src/boot/dependencies.ts +12 -4
- package/src/boot/flush.ts +20 -0
- package/src/boot/lifecycle.ts +7 -5
- package/src/config/cooldowns.ts +1 -1
- package/src/config/routing.ts +26 -0
- package/src/config/spec-metadata.ts +72 -0
- package/src/config/spec.ts +20 -6
- package/src/console/api-keys/contracts.ts +12 -1
- package/src/console/api-keys/routes.ts +50 -31
- package/src/console/auth/account-reset.ts +7 -9
- package/src/console/backup/contracts.ts +4 -0
- package/src/console/backup/export-endpoint.ts +7 -5
- package/src/console/cli-tools/service.ts +6 -12
- package/src/console/console-router-guards.ts +23 -16
- package/src/console/console-router.ts +7 -0
- package/src/console/dashboard-assets.ts +5 -5
- package/src/console/domain-registration.ts +27 -2
- package/src/console/inferhub/normalize.ts +24 -28
- package/src/console/inferhub/types.ts +3 -0
- package/src/console/ip-bans/routes.ts +93 -0
- package/src/console/observability/store.ts +0 -53
- package/src/console/providers/catalog/catalog-projections.ts +5 -2
- package/src/console/providers/catalog/contracts.ts +123 -0
- package/src/console/providers/catalog/discover-constants.ts +6 -0
- package/src/console/providers/catalog/model-operations.ts +122 -10
- package/src/console/providers/catalog/provider-operations.ts +116 -8
- package/src/console/providers/catalog/public-model-store.ts +0 -0
- package/src/console/providers/catalog/routes.ts +65 -4
- package/src/console/providers/catalog/store-helpers.ts +30 -1
- package/src/console/providers/catalog/store.ts +249 -4
- package/src/console/quota/account-quota-global.ts +97 -19
- package/src/console/quota/account-quota-shared.ts +49 -0
- package/src/console/quota/account-quota-tenant.ts +6 -18
- package/src/console/quota/native-identity.ts +2 -0
- package/src/console/quota/quota-view.ts +19 -3
- package/src/console/routing/pools/operations.ts +31 -46
- package/src/console/settings/contracts.ts +18 -0
- package/src/console/settings/store.ts +32 -0
- package/src/console/shared/errors.ts +33 -6
- package/src/console/system-prompt/contracts.ts +0 -1
- package/src/main.ts +3 -3
- package/src/network/pool/byte-accounting.ts +3 -2
- package/src/network/pool/selector.ts +182 -39
- package/src/network/pool-cooldown-store.ts +89 -14
- package/src/network/pool-health.ts +49 -61
- package/src/network/rate-limit-verdict.ts +1 -1
- package/src/network/ssrf.ts +6 -6
- package/src/observability/event-log.ts +7 -361
- package/src/observability/event-query.ts +18 -4
- package/src/observability/performance-metrics.ts +9 -0
- package/src/observability/runtime-metrics.ts +14 -9
- package/src/observability/telemetry-buffer.ts +15 -25
- package/src/observability/telemetry-reconciliation.ts +9 -37
- package/src/observability/telemetry-row.ts +125 -0
- package/src/persistence/db-mode.ts +4 -1
- package/src/persistence/dialect.ts +30 -0
- package/src/persistence/migrate.ts +6 -3
- package/src/persistence/schema.ts +28 -2
- package/src/persistence/ttl-cache.ts +20 -2
- package/src/protocol/codecs.ts +1 -1
- package/src/protocol/dsml.ts +35 -87
- package/src/protocol/gateway-error.ts +1 -0
- package/src/protocol/markup-stream-parser.ts +195 -0
- package/src/protocol/reasoning-text.ts +19 -0
- package/src/protocol/reasoning.ts +1 -1
- package/src/protocol/request/chat.ts +14 -14
- package/src/protocol/request/gemini.ts +8 -2
- package/src/protocol/request/messages.ts +4 -5
- package/src/protocol/response/chat.ts +12 -20
- package/src/protocol/response/gemini.ts +6 -1
- package/src/protocol/response/omp-tool-call-markup.ts +43 -86
- package/src/protocol/response/responses.ts +18 -2
- package/src/protocol/sse-decoder.ts +25 -8
- package/src/protocol/stop-reason.ts +23 -1
- package/src/protocol/stream-error-frames.ts +13 -3
- package/src/protocol/think-split.ts +112 -0
- package/src/protocol/translation/dialect/qwen.ts +26 -58
- package/src/protocol/translation/quirks.ts +1 -1
- package/src/protocol/translation/tool-repair.ts +2 -2
- package/src/protocol/upstream/send-claude-messages.ts +15 -4
- package/src/protocol/upstream-parsing.ts +1 -1
- package/src/providers/adapters/compatible-adapter.ts +78 -17
- package/src/providers/authentication/oauth-client.ts +1 -1
- package/src/providers/authentication/oauth-device-flow.ts +98 -8
- package/src/providers/authentication/oauth-refresh-service.ts +153 -59
- package/src/providers/configured-provider.ts +148 -0
- package/src/providers/default-registry.ts +117 -27
- package/src/providers/discovery/discovery-types.ts +12 -0
- package/src/providers/discovery/probe-phases.ts +74 -33
- package/src/providers/discovery/probing-service.ts +293 -165
- package/src/providers/integrations/alibabacp/alibabacp-models.ts +1 -2
- package/src/providers/integrations/{dashscope-models.ts → alibabacp/dashscope-models.ts} +2 -2
- package/src/providers/integrations/antigravity/antigravity-protocol.ts +121 -2
- package/src/providers/integrations/antigravity/antigravity.ts +13 -2
- package/src/providers/integrations/buddy/buddy-catalog-shared.ts +72 -34
- package/src/providers/integrations/buddy/buddy-chat-shared.ts +191 -35
- package/src/providers/integrations/buddy/buddy-checkin.ts +17 -39
- package/src/providers/integrations/buddy/buddy-conversation-headers.ts +2 -2
- package/src/providers/integrations/buddy/buddy-discovery-shared.ts +5 -5
- package/src/providers/integrations/buddy/buddy-identity.ts +89 -6
- package/src/providers/integrations/buddy/buddy-media.ts +4 -5
- package/src/providers/integrations/buddy/buddy-oauth-shared.ts +2 -2
- package/src/providers/integrations/buddy/buddy-quota-shared.ts +1 -1
- package/src/providers/integrations/buddy/buddy-usage-shared.ts +1 -3
- package/src/providers/integrations/buddy/capabilities.ts +6 -43
- package/src/providers/integrations/buddy/codebuddy/cn-catalog.ts +2 -1
- package/src/providers/integrations/buddy/codebuddy/cn-provider.ts +23 -1
- package/src/providers/integrations/buddy/codebuddy/provider.ts +6 -2
- package/src/providers/integrations/buddy/codebuddy/shared.ts +38 -27
- package/src/providers/integrations/claude/claude-quota.ts +14 -17
- package/src/providers/integrations/cline/cline.ts +2 -2
- package/src/providers/integrations/commandcode/quota.ts +22 -28
- package/src/providers/integrations/cursor/cursor-auth.ts +0 -8
- package/src/providers/integrations/cursor/cursor-catalog.ts +2 -0
- package/src/providers/integrations/cursor/cursor-exec.ts +745 -0
- package/src/providers/integrations/cursor/cursor-http2.ts +2 -0
- package/src/providers/integrations/cursor/cursor-request.ts +35 -20
- package/src/providers/integrations/cursor/cursor-shared.ts +26 -5
- package/src/providers/integrations/cursor/cursor.ts +139 -70
- package/src/providers/integrations/cursor/protocol/messages.ts +22 -29
- package/src/providers/integrations/cursor/protocol/protobuf-schema.ts +37 -0
- package/src/providers/integrations/cursor/protocol/tool-canonical.ts +26 -100
- package/src/providers/integrations/devin/devin-auth.ts +353 -0
- package/src/providers/integrations/devin/devin-catalog.ts +207 -0
- package/src/providers/integrations/devin/devin-http.ts +91 -0
- package/src/providers/integrations/devin/devin-quota.ts +214 -0
- package/src/providers/integrations/devin/devin-shared.ts +111 -0
- package/src/providers/integrations/devin/devin.ts +539 -0
- package/src/providers/integrations/devin/protocol/devin-proto.ts +558 -0
- package/src/providers/integrations/devin/protocol/framing.ts +124 -0
- package/src/providers/integrations/factory/factory-oauth.ts +17 -44
- package/src/providers/integrations/factory/factory.ts +2 -2
- package/src/providers/integrations/freebuff/assets/official-system-manager.txt +88 -0
- package/src/providers/integrations/freebuff/assets/official-system-worker.txt +57 -0
- package/src/providers/integrations/freebuff/assets/official-tools.json +1070 -0
- package/src/providers/integrations/freebuff/freebuff-catalog.ts +120 -0
- package/src/providers/integrations/freebuff/freebuff-constants.ts +1233 -0
- package/src/providers/integrations/freebuff/freebuff-discovery.ts +108 -0
- package/src/providers/integrations/freebuff/freebuff-oauth.ts +240 -0
- package/src/providers/integrations/freebuff/freebuff-quota.ts +260 -0
- package/src/providers/integrations/freebuff/freebuff-virtual.ts +89 -0
- package/src/providers/integrations/freebuff/freebuff.ts +682 -0
- package/src/providers/integrations/freepi/freepi-catalog.ts +60 -0
- package/src/providers/integrations/freepi/freepi-discovery.ts +82 -0
- package/src/providers/integrations/freepi/freepi-headers.ts +21 -0
- package/src/providers/integrations/freepi/freepi-oauth.ts +142 -0
- package/src/providers/integrations/freepi/freepi-protocol.ts +242 -0
- package/src/providers/integrations/freepi/freepi-quota.ts +126 -0
- package/src/providers/integrations/freepi/freepi-realm.ts +35 -0
- package/src/providers/integrations/freepi/freepi.ts +292 -0
- package/src/providers/integrations/gemini.ts +2 -2
- package/src/providers/integrations/grok/grok-oauth.ts +48 -45
- package/src/providers/integrations/grok/grok-ratelimit-store.ts +10 -17
- package/src/providers/integrations/grok/grok-turn-index.ts +11 -16
- package/src/providers/integrations/hermes/hermes-oauth.ts +94 -0
- package/src/providers/integrations/{hermes.ts → hermes/hermes.ts} +13 -21
- package/src/providers/integrations/hermes/index.ts +2 -0
- package/src/providers/integrations/kiro/kiro-catalog.ts +17 -1
- package/src/providers/integrations/kiro/kiro-discovery.ts +10 -12
- package/src/providers/integrations/kiro/kiro-quota.ts +8 -4
- package/src/providers/integrations/kiro/kiro.ts +15 -19
- package/src/providers/integrations/ollamacloud/index.ts +2 -0
- package/src/providers/integrations/{ollamacloud-models.ts → ollamacloud/models.ts} +2 -2
- package/src/providers/integrations/{ollamacloud-quota.ts → ollamacloud/quota.ts} +3 -3
- package/src/providers/integrations/opencode/fingerprint.ts +1 -1
- package/src/providers/integrations/opencode/opencode-go-quota.ts +2 -8
- package/src/providers/integrations/perch/perch-catalog.ts +105 -0
- package/src/providers/integrations/perch/perch-credential.ts +25 -0
- package/src/providers/integrations/perch/perch-oauth.ts +170 -0
- package/src/providers/integrations/perch/perch-protocol.ts +208 -0
- package/src/providers/integrations/perch/perch-quota.ts +123 -0
- package/src/providers/integrations/perch/perch-realm.ts +82 -0
- package/src/providers/integrations/perch/perch-system-prompt.ts +13 -0
- package/src/providers/integrations/perch/perch.ts +305 -0
- package/src/providers/integrations/perch/saffron-system-prompt.txt +8 -0
- package/src/providers/integrations/qoder/chat-proto.ts +328 -328
- package/src/providers/integrations/qoder/claim-qoder-credits.ts +19 -60
- package/src/providers/integrations/qoder/qoder-adapter.ts +90 -40
- package/src/providers/integrations/qoder/qoder-auth.ts +101 -29
- package/src/providers/integrations/qoder/qoder-cache.ts +32 -0
- package/src/providers/integrations/qoder/qoder-catalog.ts +26 -6
- package/src/providers/integrations/qoder/qoder-chat.ts +7 -21
- package/src/providers/integrations/qoder/qoder-checkin.ts +6 -6
- package/src/providers/integrations/qoder/qoder-grpc.ts +210 -7
- package/src/providers/integrations/qoder/qoder-ide.ts +5 -108
- package/src/providers/integrations/qoder/qoder-identity-cache.ts +184 -0
- package/src/providers/integrations/qoder/qoder-native-identity-store.ts +83 -18
- package/src/providers/integrations/qoder/qoder-realm.ts +9 -6
- package/src/providers/integrations/qoder/qoder-umid.ts +109 -342
- package/src/providers/integrations/qoder/qoder-virtual.ts +33 -1
- package/src/providers/integrations/qoder/qoder.ts +3 -7
- package/src/providers/integrations/trae/trae-catalog.ts +9 -14
- package/src/providers/integrations/trae/trae-headers.ts +36 -11
- package/src/providers/integrations/trae/trae-oauth.ts +14 -17
- package/src/providers/integrations/trae/trae-protocol.ts +12 -11
- package/src/providers/integrations/trae/trae-quota.ts +96 -36
- package/src/providers/integrations/trae/trae-realm.ts +74 -15
- package/src/providers/integrations/trae/trae.ts +99 -26
- package/src/providers/integrations/zcode-start-plan/provider.ts +226 -23
- package/src/providers/integrations/zcode-start-plan/quota.ts +19 -2
- package/src/providers/integrations/zro/zro.ts +204 -0
- package/src/providers/operations/account-error-classification.ts +235 -278
- package/src/providers/operations/account-health-service.ts +273 -26
- package/src/providers/operations/account-refresh-status.ts +269 -0
- package/src/providers/operations/account-tier.ts +66 -0
- package/src/providers/operations/client-version-resolver.ts +1 -1
- package/src/providers/operations/client-versions.ts +42 -150
- package/src/providers/operations/cooldown-rules.ts +56 -0
- package/src/providers/operations/{model-catalog-cache.ts → provider-caches.ts} +68 -16
- package/src/providers/operations/provider-catalog-seeder.ts +4 -0
- package/src/providers/operations/provider-catalog-service.ts +1 -1
- package/src/providers/operations/provider-credential-service.ts +102 -32
- package/src/providers/operations/provider-rules/github.ts +48 -0
- package/src/providers/operations/provider-rules/grok.ts +33 -0
- package/src/providers/operations/provider-rules/inception.ts +49 -0
- package/src/providers/operations/provider-rules/index.ts +32 -0
- package/src/providers/operations/provider-rules/perch.ts +37 -0
- package/src/providers/operations/provider-rules/qoder.ts +70 -0
- package/src/providers/operations/provider-rules/trae.ts +81 -0
- package/src/providers/provider-contracts.ts +33 -2
- package/src/providers/{provider-credential-resolver.ts → provider-credentials.ts} +40 -3
- package/src/providers/provider-metadata.ts +99 -14
- package/src/providers/provider-model-definition.ts +36 -0
- package/src/providers/provider-probe.ts +15 -1
- package/src/providers/provider-registry.ts +42 -33
- package/src/providers/quota/quota-limit-windows.ts +16 -5
- package/src/providers/quota/quota-support.ts +1 -1
- package/src/providers/quota/quota-window-parser.ts +90 -18
- package/src/providers/quota/refresh.ts +96 -18
- package/src/security/abuse.ts +71 -0
- package/src/security/api-key-auth-cache.ts +1 -1
- package/src/security/api-key-auth.ts +6 -2
- package/src/transport/dispatch/attempt-finalize.ts +14 -13
- package/src/transport/dispatch/attempt-loop.ts +71 -17
- package/src/transport/dispatch/generation.ts +2 -8
- package/src/transport/dispatch/native-shared.ts +25 -0
- package/src/transport/dispatch/proxy-request.ts +9 -46
- package/src/transport/dispatch/responses-compact.ts +2 -8
- package/src/transport/dispatch/streaming/finalize.ts +9 -6
- package/src/transport/dispatch/streaming/stream.ts +9 -36
- package/src/transport/dispatch/systemone.ts +2 -8
- package/src/transport/dispatch/token-count.ts +2 -6
- package/src/transport/dispatch/upstream.ts +67 -1
- package/src/transport/drain-endpoint.ts +31 -4
- package/src/transport/failure-policy.ts +129 -37
- package/src/transport/guards/body-policy.ts +7 -1
- package/src/transport/guards/error-lifecycle.ts +13 -1
- package/src/transport/guards/request-context.ts +22 -14
- package/src/transport/request/preparer.ts +81 -71
- package/src/transport/routing/bounded-lru.ts +14 -0
- package/src/transport/routing/drain-reserve.ts +129 -0
- package/src/transport/routing/plan-gate.ts +7 -1
- package/src/transport/routing/round-robin.ts +60 -0
- package/src/transport/routing/route-catalog.ts +123 -111
- package/src/transport/routing/route-model.ts +51 -9
- package/src/transport/routing/router.ts +418 -33
- package/src/transport/surface/adapters.ts +11 -2
- package/src/transport/surface/chat/adapter.ts +2 -2
- package/src/transport/surface/chat/encode.ts +47 -4
- package/src/transport/surface/chat/parse.ts +2 -12
- package/src/transport/surface/completion.ts +44 -33
- package/src/transport/surface/content-parts.ts +21 -0
- package/src/transport/surface/messages/adapter.ts +9 -2
- package/src/transport/surface/messages/encode.ts +11 -3
- package/src/transport/surface/messages/parse.ts +2 -1
- package/src/transport/surface/messages/stream.ts +33 -17
- package/src/transport/surface/responses/encode.ts +34 -6
- package/src/transport/surface/responses/parse.ts +3 -11
- package/src/workers/daily-checkin.ts +1 -1
- package/src/workers/quota-refresh-sweep.ts +1 -1
- package/src/workers/scheduler.ts +22 -4
- package/dist/dashboard/assets/BannedPage-DeIbIiBU.js +0 -1
- package/dist/dashboard/assets/BannedPage-DeIbIiBU.js.gz +0 -0
- package/dist/dashboard/assets/CliToolDetailPage-BRWKPQPf.js.gz +0 -0
- package/dist/dashboard/assets/CliToolsPage-BP-Y5iHN.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-B7JHozVa.js +0 -1
- package/dist/dashboard/assets/CombosPage-B7JHozVa.js.gz +0 -0
- package/dist/dashboard/assets/ConsoleLogPage-GX7iGGcu.js +0 -1
- package/dist/dashboard/assets/ConsoleLogPage-GX7iGGcu.js.gz +0 -0
- package/dist/dashboard/assets/CustomizationPage-HVonbGEa.js +0 -1
- package/dist/dashboard/assets/CustomizationPage-HVonbGEa.js.gz +0 -0
- package/dist/dashboard/assets/HealthEventsModal-xaut4OJ9.js +0 -1
- package/dist/dashboard/assets/HealthEventsModal-xaut4OJ9.js.gz +0 -0
- package/dist/dashboard/assets/InjectSystemPromptPanel-Cv-2Ol_K.js.gz +0 -0
- package/dist/dashboard/assets/LoginPage-bKfz_b1K.js.gz +0 -0
- package/dist/dashboard/assets/ModelPicker-B-WQxx_H.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-Z9pJZFo8.js +0 -1
- package/dist/dashboard/assets/OverviewPage-Z9pJZFo8.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-CMeDBxR1.js +0 -7
- package/dist/dashboard/assets/ProviderDetailPage-CMeDBxR1.js.gz +0 -0
- package/dist/dashboard/assets/ProviderIcon-jjqXJDA3.js +0 -1
- package/dist/dashboard/assets/ProviderIcon-jjqXJDA3.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-BXPdOpG4.js +0 -1
- package/dist/dashboard/assets/ProvidersPage-BXPdOpG4.js.gz +0 -0
- package/dist/dashboard/assets/ProxyPage-emlTuxz6.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-CMJKNYWb.js +0 -1
- package/dist/dashboard/assets/QuotaPage-CMJKNYWb.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-BSy7EwGo.js +0 -1
- package/dist/dashboard/assets/SettingsPage-BSy7EwGo.js.gz +0 -0
- package/dist/dashboard/assets/SetupPage-CUZrKs9r.js.gz +0 -0
- package/dist/dashboard/assets/StudioPage-jWmUdDpy.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-5F9tGVGG.js +0 -56
- package/dist/dashboard/assets/UsagePage-5F9tGVGG.js.gz +0 -0
- package/dist/dashboard/assets/api-keys-KvX83mRe.js +0 -1
- package/dist/dashboard/assets/api-keys-KvX83mRe.js.gz +0 -0
- package/dist/dashboard/assets/app-BEsU8hKs.css +0 -2
- package/dist/dashboard/assets/app-BEsU8hKs.css.gz +0 -0
- package/dist/dashboard/assets/assert-CidQVoNo.js.gz +0 -0
- package/dist/dashboard/assets/badge-DyI_mJfi.js.gz +0 -0
- package/dist/dashboard/assets/banner-B-yXtCqb.js.gz +0 -0
- package/dist/dashboard/assets/brand/bansos_page.png +0 -0
- package/dist/dashboard/assets/brand/denia_bansos.jpg +0 -0
- package/dist/dashboard/assets/brand/favicon.jpg +0 -0
- package/dist/dashboard/assets/brand/login_register.jpg +0 -0
- package/dist/dashboard/assets/brand/login_register_initial.jpg +0 -0
- package/dist/dashboard/assets/brand/og_bansos.jpg +0 -0
- package/dist/dashboard/assets/brand/og_image.jpg +0 -0
- package/dist/dashboard/assets/brand/sidebar_ico.jpg +0 -0
- package/dist/dashboard/assets/card-_HwAEqFF.js.gz +0 -0
- package/dist/dashboard/assets/cli-tools-Bwv5-zGZ.js +0 -1
- package/dist/dashboard/assets/cli-tools-Bwv5-zGZ.js.gz +0 -0
- package/dist/dashboard/assets/clipboard-button-ByjCk0o9.js.gz +0 -0
- package/dist/dashboard/assets/dialog-BZhOlfz-.js.gz +0 -0
- package/dist/dashboard/assets/drawer-BADqIRYP.js.gz +0 -0
- package/dist/dashboard/assets/entry-COaC-irN.js.gz +0 -0
- package/dist/dashboard/assets/entry-Ca7LSCet.js +0 -4
- package/dist/dashboard/assets/entry-Ca7LSCet.js.gz +0 -0
- package/dist/dashboard/assets/entry-PDd27uCd.js +0 -1
- package/dist/dashboard/assets/entry-PDd27uCd.js.gz +0 -0
- package/dist/dashboard/assets/formatters-DcHJyRiu.js.gz +0 -0
- package/dist/dashboard/assets/index-CgKmFngv.js.gz +0 -0
- package/dist/dashboard/assets/inline-B2BirKry.js.gz +0 -0
- package/dist/dashboard/assets/input-D-qV9dKY.js.gz +0 -0
- package/dist/dashboard/assets/layout-B7tVWhtV.js.gz +0 -0
- package/dist/dashboard/assets/list-row-CtkGE3bF.js.gz +0 -0
- package/dist/dashboard/assets/live-DGizF06-.js.gz +0 -0
- package/dist/dashboard/assets/minimize-2-BTmMTK4o.js +0 -1
- package/dist/dashboard/assets/minimize-2-BTmMTK4o.js.gz +0 -0
- package/dist/dashboard/assets/mutation-GU7XdEjz.js.gz +0 -0
- package/dist/dashboard/assets/network-C9UE-bOr.js.gz +0 -0
- package/dist/dashboard/assets/numbers-BnAd22a_.js.gz +0 -0
- package/dist/dashboard/assets/pagination-BAywyMzS.js.gz +0 -0
- package/dist/dashboard/assets/query-keys-YSoQOUh6.js.gz +0 -0
- package/dist/dashboard/assets/quota-DJ1QlAOq.js +0 -1
- package/dist/dashboard/assets/quota-DJ1QlAOq.js.gz +0 -0
- package/dist/dashboard/assets/routing-fnCsxgNO.js +0 -1
- package/dist/dashboard/assets/routing-fnCsxgNO.js.gz +0 -0
- package/dist/dashboard/assets/select-BCOcv8WK.js.gz +0 -0
- package/dist/dashboard/assets/settings-BxslsErn.js +0 -1
- package/dist/dashboard/assets/settings-BxslsErn.js.gz +0 -0
- package/dist/dashboard/assets/stack-ByKt3Q1g.js.gz +0 -0
- package/dist/dashboard/assets/state-DXbGTx7N.js.gz +0 -0
- package/dist/dashboard/assets/switch-ZeTsW623.js.gz +0 -0
- package/dist/dashboard/assets/useMutation-CbCP4w1o.js.gz +0 -0
- package/dist/dashboard/console-backgrounds.jpg +0 -0
- package/dist/dashboard/console-backgrounds_initial.jpg +0 -0
- package/dist/dashboard/donation/qris-risun-marke.png +0 -0
- package/src/providers/bundled-discovery-providers.ts +0 -98
- package/src/providers/configured-openai-providers.ts +0 -120
- package/src/providers/integrations/buddy/turing-device-token.ts +0 -262
- package/src/providers/integrations/buddy/workbuddy/cn-oauth.ts +0 -30
- package/src/providers/integrations/buddy/workbuddy/cn-provider.ts +0 -58
- package/src/providers/integrations/buddy/workbuddy/oauth.ts +0 -31
- package/src/providers/integrations/buddy/workbuddy/provider.ts +0 -209
- package/src/providers/integrations/buddy/workbuddy/quota.ts +0 -161
- package/src/providers/integrations/buddy/workbuddy/shared.ts +0 -285
- package/src/providers/operations/model-discovery-cache.ts +0 -34
- package/src/providers/operations/probe-fetch.ts +0 -15
- package/src/providers/operations/provider-version-cache.ts +0 -30
- package/src/providers/provider-capabilities.ts +0 -33
- package/src/providers/provider-credential-envelope.ts +0 -43
- /package/dist/dashboard/assets/{app-CTxoqyYB.js → app-DIXLjojg.js} +0 -0
- /package/dist/dashboard/assets/{app-CTxoqyYB.js.gz → app-DIXLjojg.js.gz} +0 -0
|
@@ -262,11 +262,30 @@ export function jsonCompletion(
|
|
|
262
262
|
};
|
|
263
263
|
const terminal = events.findLast((event) => event.type === "terminal");
|
|
264
264
|
if (terminal?.type === "terminal" && terminal.state === "failed") {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
265
|
+
const raw = isRecord(terminal.stop_details) ? terminal.stop_details : undefined;
|
|
266
|
+
const errorMessage =
|
|
267
|
+
typeof raw?.["message"] === "string" && raw["message"].length > 0
|
|
268
|
+
? raw["message"]
|
|
269
|
+
: "The upstream response failed";
|
|
270
|
+
// A failed terminal returns an error response, not a completion with a
|
|
271
|
+
// finish_reason: the client must be able to tell the refusal/limit from a
|
|
272
|
+
// finished answer. OpenAI error responses carry no `choices`.
|
|
273
|
+
const errorResult: JsonObject = {
|
|
274
|
+
id,
|
|
275
|
+
object: "chat.completion",
|
|
276
|
+
created,
|
|
277
|
+
model,
|
|
278
|
+
usage,
|
|
279
|
+
error: {
|
|
280
|
+
type: "server_error",
|
|
281
|
+
code: terminal.stop_reason ?? "provider_error",
|
|
282
|
+
...(typeof raw?.["status"] === "number" ? { status: raw["status"] } : {}),
|
|
283
|
+
message: errorMessage,
|
|
284
|
+
},
|
|
269
285
|
};
|
|
286
|
+
const serviceTier = options.service_tier ?? options.serviceTier;
|
|
287
|
+
if (serviceTier !== undefined) errorResult.service_tier = serviceTier;
|
|
288
|
+
return errorResult;
|
|
270
289
|
}
|
|
271
290
|
const serviceTier = options.service_tier ?? options.serviceTier;
|
|
272
291
|
if (serviceTier !== undefined) result.service_tier = serviceTier;
|
|
@@ -482,6 +501,30 @@ export class ChatStreamEncoder extends SurfaceStreamEncoder<CanonicalEvent, Json
|
|
|
482
501
|
if (event.type === "terminal") {
|
|
483
502
|
this.terminalState = event.state;
|
|
484
503
|
this.terminalReason = finishReason(event.stop_reason);
|
|
504
|
+
// A failed terminal is a real failure: emit an error frame with the
|
|
505
|
+
// upstream's message instead of a `finish_reason: "error"` chunk. The
|
|
506
|
+
// client receives the reason (rate limit, quota, upstream error) rather
|
|
507
|
+
// than a bare "error" word it has to guess at. `stop_details` carries
|
|
508
|
+
// the failure details when the adapter set them; otherwise the stop
|
|
509
|
+
// reason is the only signal.
|
|
510
|
+
if (event.state === "failed") {
|
|
511
|
+
const raw = isRecord(event.stop_details) ? event.stop_details : undefined;
|
|
512
|
+
const message =
|
|
513
|
+
typeof raw?.["message"] === "string" && raw["message"].length > 0
|
|
514
|
+
? raw["message"]
|
|
515
|
+
: "The upstream response failed";
|
|
516
|
+
this.emittedAny = true;
|
|
517
|
+
return [
|
|
518
|
+
{
|
|
519
|
+
error: {
|
|
520
|
+
type: "server_error",
|
|
521
|
+
code: event.stop_reason ?? "provider_error",
|
|
522
|
+
...(typeof raw?.["status"] === "number" ? { status: raw["status"] } : {}),
|
|
523
|
+
message,
|
|
524
|
+
},
|
|
525
|
+
},
|
|
526
|
+
];
|
|
527
|
+
}
|
|
485
528
|
if (!this.cancelled && event.state !== "aborted" && event.usage)
|
|
486
529
|
this.finalUsage = usageToChatWire(event.usage);
|
|
487
530
|
const usage = this.cancelled || event.state === "aborted" ? null : this.finalUsage;
|
|
@@ -2,7 +2,7 @@ import type { CanonicalMessage, ContentPart, GenerationControls } from "../../..
|
|
|
2
2
|
import type { SurfaceInput } from "../adapters";
|
|
3
3
|
import { isRecord } from "../../../protocol/codecs";
|
|
4
4
|
import { asNumber } from "../../../shared/coerce";
|
|
5
|
-
import { textPart, normalizeInlineFile } from "../content-parts";
|
|
5
|
+
import { decodeWireBody, textPart, normalizeInlineFile } from "../content-parts";
|
|
6
6
|
import { SERVICE_TIERS } from "../dialects";
|
|
7
7
|
import { readNumber, readString } from "../../../protocol/codecs";
|
|
8
8
|
import type { OpenAiUsage } from "../../../providers/provider-usage";
|
|
@@ -61,18 +61,8 @@ function isSurfaceInput(value: unknown): value is SurfaceInput {
|
|
|
61
61
|
return isRecord(value) && "body" in value && "path" in value && typeof value.path === "string";
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
export function decodeBody(value: unknown): unknown {
|
|
65
|
-
if (value instanceof Uint8Array) {
|
|
66
|
-
return JSON.parse(new TextDecoder().decode(value)) as unknown;
|
|
67
|
-
}
|
|
68
|
-
if (typeof value === "string") {
|
|
69
|
-
return JSON.parse(value) as unknown;
|
|
70
|
-
}
|
|
71
|
-
return value;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
64
|
export function requestBody(input: unknown): unknown {
|
|
75
|
-
return
|
|
65
|
+
return decodeWireBody(isSurfaceInput(input) ? input.body : input);
|
|
76
66
|
}
|
|
77
67
|
|
|
78
68
|
function nonNegativeNumber(value: unknown): number | undefined {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { GatewayError } from "../../protocol/gateway-error";
|
|
2
2
|
import type { CanonicalEvent, CanonicalRequest, GenerationControls } from "../../protocol/canonical-model";
|
|
3
|
-
import
|
|
3
|
+
import { parseReasoningIntent } from "./dialects";
|
|
4
4
|
import type { SurfaceAdapter, SurfaceInput, SurfaceOutput } from "./adapters";
|
|
5
5
|
import { eventText } from "./adapters";
|
|
6
6
|
import { isRecord } from "../../protocol/codecs";
|
|
7
7
|
import { textPart } from "./content-parts";
|
|
8
8
|
import { usageToChatWire, type OpenAiUsage } from "../../providers/provider-usage";
|
|
9
|
+
import { completionFinishReason } from "../../protocol/stop-reason";
|
|
9
10
|
import { TEXT_ENCODER } from "../../protocol/sse-frame";
|
|
10
11
|
import { SurfaceStreamEncoder } from "./stream-frame";
|
|
11
12
|
|
|
@@ -35,24 +36,24 @@ function textPrompts(value: unknown): string[] {
|
|
|
35
36
|
return value.flatMap((prompt) => (typeof prompt === "string" ? [prompt] : []));
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Completion's wire stop reason from a terminal event (or `null` when no
|
|
41
|
+
* terminal has been seen). Both the sync adapter and the streaming encoder
|
|
42
|
+
* derive it through the shared canonical stop-reason mapping so the two
|
|
43
|
+
* halves of the completion surface cannot drift.
|
|
44
|
+
*/
|
|
45
|
+
function completionStopReason(terminal: CanonicalEvent | undefined): string | null {
|
|
40
46
|
if (terminal?.type !== "terminal") return null;
|
|
41
|
-
|
|
42
|
-
if (terminal.stop_reason === "content_filter") return "content_filter";
|
|
43
|
-
if (terminal.state === "complete" || terminal.stop_reason === "stop") return "stop";
|
|
44
|
-
return null;
|
|
47
|
+
return completionFinishReason(terminal.stop_reason, terminal.state);
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
/**
|
|
48
51
|
* Completion wire usage. Delegates to the chat builder (same wire family), so
|
|
49
52
|
* completion responses carry cache/reasoning details, not just the three totals.
|
|
50
53
|
*/
|
|
51
|
-
function
|
|
52
|
-
const terminal = [...events].reverse().find((event) => event.type === "terminal");
|
|
54
|
+
function completionUsage(terminal: CanonicalEvent | undefined, usageEvent: CanonicalEvent | undefined): OpenAiUsage | undefined {
|
|
53
55
|
const record = terminal?.type === "terminal" ? terminal.usage : undefined;
|
|
54
|
-
const
|
|
55
|
-
const source = record ?? (event?.type === "usage" ? event.usage : undefined);
|
|
56
|
+
const source = record ?? (usageEvent?.type === "usage" ? usageEvent.usage : undefined);
|
|
56
57
|
if (!source) return undefined;
|
|
57
58
|
return usageToChatWire(source);
|
|
58
59
|
}
|
|
@@ -103,6 +104,31 @@ export class CompletionStreamEncoder extends SurfaceStreamEncoder<CanonicalEvent
|
|
|
103
104
|
push(event: CanonicalEvent): Record<string, unknown>[] {
|
|
104
105
|
if (event.type === "terminal") this.terminalEvent = event;
|
|
105
106
|
if (event.type === "usage") this.usageEvent = event;
|
|
107
|
+
if (event.type === "terminal" && event.state === "failed") {
|
|
108
|
+
// A failed terminal is a real failure: emit an error object instead of
|
|
109
|
+
// a completion with a null finish_reason. The client receives the
|
|
110
|
+
// upstream's message (rate limit, quota, error) rather than a silent
|
|
111
|
+
// empty completion.
|
|
112
|
+
const raw = isRecord(event.stop_details) ? event.stop_details : undefined;
|
|
113
|
+
const message =
|
|
114
|
+
typeof raw?.["message"] === "string" && raw["message"].length > 0
|
|
115
|
+
? raw["message"]
|
|
116
|
+
: "The upstream response failed";
|
|
117
|
+
return [
|
|
118
|
+
{
|
|
119
|
+
id: this.id,
|
|
120
|
+
object: "text_completion",
|
|
121
|
+
created: this.created,
|
|
122
|
+
model: this.options.model ?? "",
|
|
123
|
+
error: {
|
|
124
|
+
type: "server_error",
|
|
125
|
+
code: event.stop_reason ?? "provider_error",
|
|
126
|
+
...(typeof raw?.["status"] === "number" ? { status: raw["status"] } : {}),
|
|
127
|
+
message,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
];
|
|
131
|
+
}
|
|
106
132
|
const text = eventText(event);
|
|
107
133
|
if (text === undefined) {
|
|
108
134
|
if (event.type !== "terminal") return [];
|
|
@@ -116,22 +142,12 @@ export class CompletionStreamEncoder extends SurfaceStreamEncoder<CanonicalEvent
|
|
|
116
142
|
|
|
117
143
|
/** The wire stop reason from the terminal event seen so far. */
|
|
118
144
|
private stopReason(): string | null {
|
|
119
|
-
|
|
120
|
-
if (terminal?.type !== "terminal") return null;
|
|
121
|
-
if (terminal.stop_reason === "length") return "length";
|
|
122
|
-
if (terminal.stop_reason === "content_filter") return "content_filter";
|
|
123
|
-
if (terminal.state === "complete" || terminal.stop_reason === "stop") return "stop";
|
|
124
|
-
return null;
|
|
145
|
+
return completionStopReason(this.terminalEvent);
|
|
125
146
|
}
|
|
126
147
|
|
|
127
148
|
/** The wire usage from the terminal event, else the last usage event. */
|
|
128
149
|
private usage(): OpenAiUsage | undefined {
|
|
129
|
-
|
|
130
|
-
const record = terminal?.type === "terminal" ? terminal.usage : undefined;
|
|
131
|
-
const event = this.usageEvent;
|
|
132
|
-
const source = record ?? (event?.type === "usage" ? event.usage : undefined);
|
|
133
|
-
if (!source) return undefined;
|
|
134
|
-
return usageToChatWire(source);
|
|
150
|
+
return completionUsage(this.terminalEvent, this.usageEvent);
|
|
135
151
|
}
|
|
136
152
|
|
|
137
153
|
finish(): Record<string, unknown>[] {
|
|
@@ -180,14 +196,7 @@ class CompletionAdapter implements SurfaceAdapter {
|
|
|
180
196
|
if (typeof value.logprobs === "boolean") controls.logprobs = value.logprobs;
|
|
181
197
|
if (typeof value.stop === "string" || (Array.isArray(value.stop) && value.stop.every((item) => typeof item === "string")))
|
|
182
198
|
controls.stop = value.stop as string | readonly string[];
|
|
183
|
-
const
|
|
184
|
-
const reasoningEfforts = new Set<NonNullable<ReasoningIntent["effort"]>>([
|
|
185
|
-
"none", "minimal", "low", "medium", "high", "xhigh", "max",
|
|
186
|
-
]);
|
|
187
|
-
const reasoning =
|
|
188
|
-
typeof requestedReasoning === "string" && reasoningEfforts.has(requestedReasoning as NonNullable<ReasoningIntent["effort"]>)
|
|
189
|
-
? { effort: requestedReasoning as NonNullable<ReasoningIntent["effort"]> }
|
|
190
|
-
: undefined;
|
|
199
|
+
const reasoning = parseReasoningIntent(value);
|
|
191
200
|
const cacheKey = value.prompt_cache_key;
|
|
192
201
|
const cacheHint =
|
|
193
202
|
(typeof cacheKey === "string" && cacheKey.length > 0) || value.cache_control === "auto"
|
|
@@ -211,8 +220,10 @@ class CompletionAdapter implements SurfaceAdapter {
|
|
|
211
220
|
|
|
212
221
|
encodeOutput(events: readonly CanonicalEvent[], options: CompletionEncodingOptions = {}): SurfaceOutput {
|
|
213
222
|
const model = modelFor(events, options);
|
|
214
|
-
const
|
|
215
|
-
const
|
|
223
|
+
const terminal = [...events].reverse().find((event) => event.type === "terminal");
|
|
224
|
+
const usageEvent = [...events].reverse().find((event) => event.type === "usage");
|
|
225
|
+
const reason = completionStopReason(terminal);
|
|
226
|
+
const responseUsage = completionUsage(terminal, usageEvent);
|
|
216
227
|
const response = {
|
|
217
228
|
id: options.response_id ?? `cmpl-${crypto.randomUUID()}`,
|
|
218
229
|
object: "text_completion",
|
|
@@ -6,6 +6,27 @@ export function textPart(text: string): ContentPart {
|
|
|
6
6
|
return { kind: "text", text };
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Decodes a wire body value into its parsed JSON form.
|
|
11
|
+
*
|
|
12
|
+
* Every surface parser receives bodies in the same three shapes — raw bytes,
|
|
13
|
+
* an already-decoded string, or an object handed in directly (surface
|
|
14
|
+
* detection and tests pass objects without a wire round-trip). Bytes and
|
|
15
|
+
* strings are parsed as JSON; anything else passes through unchanged. The
|
|
16
|
+
* `SyntaxError` thrown on malformed JSON propagates to the same
|
|
17
|
+
* error-normalization path on every surface, so one shared decoder keeps the
|
|
18
|
+
* four surfaces' wire-read convention identical.
|
|
19
|
+
*/
|
|
20
|
+
export function decodeWireBody(value: unknown): unknown {
|
|
21
|
+
if (value instanceof Uint8Array) {
|
|
22
|
+
return JSON.parse(new TextDecoder().decode(value)) as unknown;
|
|
23
|
+
}
|
|
24
|
+
if (typeof value === "string") {
|
|
25
|
+
return JSON.parse(value) as unknown;
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
|
|
9
30
|
/**
|
|
10
31
|
* Fields a raw file/document block may carry, normalized across every origin
|
|
11
32
|
* vocabulary (OpenAI Chat `file`, OpenAI Responses `input_file`, Anthropic
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
import { CANONICAL_REASONING_EFFORTS, parseReasoningIntent, parseToolChoice } from "../dialects";
|
|
18
18
|
import { groupedBlocks, startModel, stopData } from "./encode";
|
|
19
19
|
import { finiteNumber, stringValue } from "../../../protocol/codecs";
|
|
20
|
+
import { ANTHROPIC_DEFAULT_MAX_TOKENS } from "../../../protocol/request/messages";
|
|
20
21
|
import { usageToMessagesWire } from "../../../providers/provider-usage";
|
|
21
22
|
|
|
22
23
|
export class MessagesAdapter implements SurfaceAdapter {
|
|
@@ -39,7 +40,7 @@ export class MessagesAdapter implements SurfaceAdapter {
|
|
|
39
40
|
const headers = options.headers ?? supplied.headers;
|
|
40
41
|
if (!stringValue(body.model)) throw new Error("Messages request requires model");
|
|
41
42
|
if (!Array.isArray(body.messages)) throw new Error("Messages request requires messages[]");
|
|
42
|
-
const maxTokens = body.max_tokens ?? body.maxTokens;
|
|
43
|
+
const maxTokens = body.max_tokens ?? body.maxTokens ?? ANTHROPIC_DEFAULT_MAX_TOKENS;
|
|
43
44
|
if (!finiteNumber(maxTokens) || !Number.isInteger(maxTokens) || maxTokens <= 0)
|
|
44
45
|
throw new Error("Messages request requires positive integer max_tokens");
|
|
45
46
|
const declaredSystem = systemBlocks(body.system);
|
|
@@ -152,10 +153,16 @@ export class MessagesAdapter implements SurfaceAdapter {
|
|
|
152
153
|
: data.reason;
|
|
153
154
|
const usage = usageToMessagesWire(data.usage);
|
|
154
155
|
if (data.failed) {
|
|
156
|
+
const errorEvent = [...events]
|
|
157
|
+
.reverse()
|
|
158
|
+
.find((event): event is Extract<CanonicalEvent, { type: "error" }> => event.type === "error");
|
|
155
159
|
return {
|
|
156
160
|
id: responseId,
|
|
157
161
|
type: "error",
|
|
158
|
-
error: {
|
|
162
|
+
error: {
|
|
163
|
+
type: "server_error",
|
|
164
|
+
message: errorEvent?.message ?? "The upstream response failed",
|
|
165
|
+
},
|
|
159
166
|
};
|
|
160
167
|
}
|
|
161
168
|
return {
|
|
@@ -207,11 +207,14 @@ export function groupedBlocks(events: readonly CanonicalEvent[]): {
|
|
|
207
207
|
previousReasoningText,
|
|
208
208
|
nextText,
|
|
209
209
|
);
|
|
210
|
-
|
|
210
|
+
// A thinking block splits only on a strong boundary (a real paragraph
|
|
211
|
+
// break). Copilot streams one thought as many items; treating every
|
|
212
|
+
// identity change as a new block painted dozens of tiny thinking blocks.
|
|
213
|
+
if (reasoningSummaryHasBoundary(previousReasoningIdentity, identity) && separator === "\n\n") {
|
|
211
214
|
next.thinking = `${separator}${nextText}`;
|
|
212
215
|
blocks.push(next);
|
|
213
216
|
} else {
|
|
214
|
-
previous.thinking = `${String(previous.thinking ?? "")}${nextText}`;
|
|
217
|
+
previous.thinking = `${String(previous.thinking ?? "")}${separator}${nextText}`;
|
|
215
218
|
}
|
|
216
219
|
previousReasoningIdentity = identity;
|
|
217
220
|
previousReasoningText = nextText;
|
|
@@ -264,7 +267,12 @@ export function stopData(events: readonly CanonicalEvent[]): {
|
|
|
264
267
|
const usageEvent = [...events]
|
|
265
268
|
.reverse()
|
|
266
269
|
.find((event): event is Extract<CanonicalEvent, { type: "usage" }> => event.type === "usage");
|
|
267
|
-
|
|
270
|
+
// A failed terminal — `failed`, or `aborted` (upstream stream error) —
|
|
271
|
+
// marks the response as failed. An explicit canonical `error` event before
|
|
272
|
+
// the terminal also fails it: the upstream declared a failure even when the
|
|
273
|
+
// terminal state alone does not.
|
|
274
|
+
const hasErrorEvent = events.some((event) => event.type === "error");
|
|
275
|
+
const failed = terminal?.state === "failed" || (terminal?.state === "aborted" && hasErrorEvent);
|
|
268
276
|
let reason: string | null;
|
|
269
277
|
if (terminal?.stop_reason !== undefined) reason = mapStopReason(terminal.stop_reason);
|
|
270
278
|
else reason = terminal?.state === "complete" ? "end_turn" : null;
|
|
@@ -50,7 +50,8 @@ export interface MessagesStreamEvent extends MessagesWireObject {
|
|
|
50
50
|
| "content_block_delta"
|
|
51
51
|
| "content_block_stop"
|
|
52
52
|
| "message_delta"
|
|
53
|
-
| "message_stop"
|
|
53
|
+
| "message_stop"
|
|
54
|
+
| "error";
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
function contentArray(value: unknown, label: string): unknown[] {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { CanonicalEvent, UsageRecord } from "../../../protocol/canonical-model";
|
|
2
2
|
import {
|
|
3
|
-
reasoningSummaryHasBoundary,
|
|
4
3
|
reasoningSummaryIdentity,
|
|
5
4
|
reasoningSummarySeparator,
|
|
6
5
|
type ReasoningSummaryIdentity,
|
|
@@ -62,6 +61,7 @@ export class MessagesStreamEncoder extends SurfaceStreamEncoder<CanonicalEvent,
|
|
|
62
61
|
private droppedUnnamedToolCalls = 0;
|
|
63
62
|
private usage: UsageRecord | undefined;
|
|
64
63
|
private failed = false;
|
|
64
|
+
private errorMessage: string | undefined;
|
|
65
65
|
private stopReason: string | null = null;
|
|
66
66
|
private readonly responseId: string;
|
|
67
67
|
private readonly model: string;
|
|
@@ -199,6 +199,7 @@ export class MessagesStreamEncoder extends SurfaceStreamEncoder<CanonicalEvent,
|
|
|
199
199
|
// inevitable terminal push throw, producing a second error frame
|
|
200
200
|
// after message_stop (which Anthropic never sends).
|
|
201
201
|
this.failed = true;
|
|
202
|
+
if (this.errorMessage === undefined) this.errorMessage = event.message;
|
|
202
203
|
return out;
|
|
203
204
|
}
|
|
204
205
|
if (event.type === "content_delta") {
|
|
@@ -247,11 +248,7 @@ export class MessagesStreamEncoder extends SurfaceStreamEncoder<CanonicalEvent,
|
|
|
247
248
|
summary,
|
|
248
249
|
)
|
|
249
250
|
: "";
|
|
250
|
-
if (
|
|
251
|
-
blockType === "thinking" &&
|
|
252
|
-
reasoningSummaryHasBoundary(this.openReasoningIdentity, identity) &&
|
|
253
|
-
this.openBlock?.type === blockType
|
|
254
|
-
) {
|
|
251
|
+
if (blockType === "thinking" && separator === "\n\n" && this.openBlock?.type === blockType) {
|
|
255
252
|
out.push({ type: "content_block_stop", index: this.openBlock.index });
|
|
256
253
|
this.openBlock = undefined;
|
|
257
254
|
}
|
|
@@ -401,18 +398,25 @@ export class MessagesStreamEncoder extends SurfaceStreamEncoder<CanonicalEvent,
|
|
|
401
398
|
resetToolCallTracker(this.tools);
|
|
402
399
|
const finalUsage = usageToMessagesWire(this.usage);
|
|
403
400
|
if (this.failed) {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
401
|
+
// The stream is closing on an upstream failure, not a normal end. A
|
|
402
|
+
// `message_stop` here would hide the failure from the client (it
|
|
403
|
+
// reads a clean stop), so emit the error event instead — matching the
|
|
404
|
+
// semantic the non-streaming encoder uses for `failed` terminals.
|
|
405
|
+
return [
|
|
406
|
+
{
|
|
407
|
+
type: "error",
|
|
408
|
+
error: {
|
|
409
|
+
type: "server_error",
|
|
410
|
+
message: this.errorMessage ?? "The upstream response failed",
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
];
|
|
415
414
|
}
|
|
415
|
+
out.push({
|
|
416
|
+
type: "message_delta",
|
|
417
|
+
delta: { stop_reason: this.stopReason, stop_sequence: null },
|
|
418
|
+
usage: finalUsage,
|
|
419
|
+
});
|
|
416
420
|
out.push({ type: "message_stop" });
|
|
417
421
|
this.finished = true;
|
|
418
422
|
return out;
|
|
@@ -446,6 +450,18 @@ export class MessagesStreamEncoder extends SurfaceStreamEncoder<CanonicalEvent,
|
|
|
446
450
|
];
|
|
447
451
|
}
|
|
448
452
|
if (this.finished) return [];
|
|
453
|
+
if (this.failed) {
|
|
454
|
+
this.finished = true;
|
|
455
|
+
return [
|
|
456
|
+
{
|
|
457
|
+
type: "error",
|
|
458
|
+
error: {
|
|
459
|
+
type: "server_error",
|
|
460
|
+
message: this.errorMessage ?? "The upstream response failed",
|
|
461
|
+
},
|
|
462
|
+
},
|
|
463
|
+
];
|
|
464
|
+
}
|
|
449
465
|
const out: MessagesStreamEvent[] = [];
|
|
450
466
|
out.push(...this.closeOpenBlock());
|
|
451
467
|
out.push(...this.flushToolCalls(true));
|
|
@@ -54,6 +54,7 @@ export class ResponsesEventEncoder extends SurfaceStreamEncoder<CanonicalEvent,
|
|
|
54
54
|
private inputSequence = -Infinity;
|
|
55
55
|
private started = false;
|
|
56
56
|
private terminal = false;
|
|
57
|
+
private hasError = false;
|
|
57
58
|
private responseModel: string | undefined;
|
|
58
59
|
private systemFingerprint: string | undefined;
|
|
59
60
|
private usage: UsageRecord | undefined;
|
|
@@ -624,21 +625,33 @@ export class ResponsesEventEncoder extends SurfaceStreamEncoder<CanonicalEvent,
|
|
|
624
625
|
state: "complete" | "failed" | "aborted",
|
|
625
626
|
stopReason?: CanonicalStopReason,
|
|
626
627
|
usage?: UsageRecord,
|
|
628
|
+
stopDetails?: unknown,
|
|
627
629
|
): ResponsesWireEvent[] {
|
|
628
630
|
if (this.terminal)
|
|
629
631
|
throw new ResponsesLifecycleError("Responses stream has more than one terminal event");
|
|
630
632
|
if (usage !== undefined) this.usage = usage;
|
|
631
633
|
const events = this.closeAll();
|
|
632
|
-
|
|
634
|
+
// An upstream error event before an `aborted` terminal is a failure, not
|
|
635
|
+
// an incomplete response: the client must see `response.failed` rather
|
|
636
|
+
// than `response.incomplete` (the same distinction the Messages encoder
|
|
637
|
+
// applies in `stopData`).
|
|
638
|
+
const effectiveState = state === "aborted" && this.hasError ? "failed" : state;
|
|
639
|
+
const status = terminalResponseStatus(effectiveState);
|
|
633
640
|
const response = this.responseObject(status.status);
|
|
634
641
|
const incompleteReason =
|
|
635
642
|
status.status === "incomplete" ? incompleteResponseReason(stopReason) : undefined;
|
|
636
643
|
if (incompleteReason !== undefined) response.incomplete_details = { reason: incompleteReason };
|
|
637
|
-
if (
|
|
644
|
+
if (effectiveState === "failed") {
|
|
645
|
+
const raw = isRecord(stopDetails) ? stopDetails : undefined;
|
|
646
|
+
const message =
|
|
647
|
+
typeof raw?.["message"] === "string" && raw["message"].length > 0
|
|
648
|
+
? raw["message"]
|
|
649
|
+
: "The upstream response failed";
|
|
638
650
|
response.error = {
|
|
639
651
|
type: "server_error",
|
|
640
652
|
code: stopReason ?? "provider_error",
|
|
641
|
-
|
|
653
|
+
...(typeof raw?.["status"] === "number" ? { status: raw["status"] } : {}),
|
|
654
|
+
message,
|
|
642
655
|
};
|
|
643
656
|
}
|
|
644
657
|
events.push(this.emit(status.event, { response }));
|
|
@@ -652,8 +665,19 @@ export class ResponsesEventEncoder extends SurfaceStreamEncoder<CanonicalEvent,
|
|
|
652
665
|
`Canonical sequence_number must increase monotonically: ${event.sequence_number}`,
|
|
653
666
|
);
|
|
654
667
|
this.inputSequence = event.sequence_number;
|
|
655
|
-
if (this.terminal)
|
|
668
|
+
if (this.terminal) {
|
|
669
|
+
// `usage` after terminal is legitimate: several upstreams stream it in
|
|
670
|
+
// a trailing chunk after the finish-reason chunk (Qoder gRPC does). The
|
|
671
|
+
// canonical contract allows it, and dropping it here would either throw a
|
|
672
|
+
// false `invalid_lifecycle` (recording a failed attempt for a response
|
|
673
|
+
// the client already received complete) or lose the usage. Any *other*
|
|
674
|
+
// event after terminal is a genuine lifecycle violation.
|
|
675
|
+
if (event.type === "usage") {
|
|
676
|
+
this.usage = event.usage;
|
|
677
|
+
return [];
|
|
678
|
+
}
|
|
656
679
|
throw new ResponsesLifecycleError("Canonical event arrived after terminal Responses event");
|
|
680
|
+
}
|
|
657
681
|
if (event.type === "response_start") {
|
|
658
682
|
if (event.system_fingerprint !== undefined)
|
|
659
683
|
this.systemFingerprint = event.system_fingerprint;
|
|
@@ -688,12 +712,16 @@ export class ResponsesEventEncoder extends SurfaceStreamEncoder<CanonicalEvent,
|
|
|
688
712
|
return events;
|
|
689
713
|
}
|
|
690
714
|
if (event.type === "keepalive") return events.concat(this.emit("response.keepalive"));
|
|
691
|
-
if (event.type === "error")
|
|
715
|
+
if (event.type === "error") {
|
|
716
|
+
this.hasError = true;
|
|
692
717
|
return events.concat(
|
|
693
718
|
this.emit("response.error", { category: event.category, message: event.message }),
|
|
694
719
|
);
|
|
720
|
+
}
|
|
695
721
|
if (event.type === "terminal")
|
|
696
|
-
return events.concat(
|
|
722
|
+
return events.concat(
|
|
723
|
+
this.processTerminal(event.state, event.stop_reason, event.usage, event.stop_details),
|
|
724
|
+
);
|
|
697
725
|
throw new ResponsesLifecycleError(`Unsupported canonical event type: ${event.type}`);
|
|
698
726
|
}
|
|
699
727
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CanonicalMessage, CanonicalRequest, ContentPart, GenerationControls, ToolDefinition } from "../../../protocol/canonical-model";
|
|
2
2
|
import { isRecord } from "../../../protocol/codecs";
|
|
3
|
-
import { textPart, normalizeInlineFile } from "../content-parts";
|
|
3
|
+
import { decodeWireBody, textPart, normalizeInlineFile } from "../content-parts";
|
|
4
4
|
import {
|
|
5
5
|
isServiceTier,
|
|
6
6
|
parseReasoningIntent,
|
|
@@ -66,23 +66,15 @@ export function hasOwn(value: Record<string, unknown>, key: string): boolean {
|
|
|
66
66
|
return Object.hasOwn(value, key);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
function parseJsonBody(value: unknown): unknown {
|
|
70
|
-
if (value instanceof Uint8Array) {
|
|
71
|
-
return JSON.parse(new TextDecoder().decode(value)) as unknown;
|
|
72
|
-
}
|
|
73
|
-
if (typeof value === "string") return JSON.parse(value) as unknown;
|
|
74
|
-
return value;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
69
|
export function unwrapBody(input: unknown): unknown {
|
|
78
70
|
if (
|
|
79
71
|
isRecord(input) &&
|
|
80
72
|
hasOwn(input, "body") &&
|
|
81
73
|
(hasOwn(input, "headers") || hasOwn(input, "path"))
|
|
82
74
|
) {
|
|
83
|
-
return
|
|
75
|
+
return decodeWireBody(input.body);
|
|
84
76
|
}
|
|
85
|
-
return
|
|
77
|
+
return decodeWireBody(input);
|
|
86
78
|
}
|
|
87
79
|
|
|
88
80
|
/**
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// inside the account loop (B-02) so the boot graph stays clean — this runs
|
|
5
5
|
// as a ride-along with the quota sweep, not at startup.
|
|
6
6
|
//
|
|
7
|
-
//
|
|
7
|
+
// CodeBuddy grants a free credit package once per calendar day. This
|
|
8
8
|
// claims it for every stored account and logs one line per account, so an
|
|
9
9
|
// operator can confirm each account got its daily login credit.
|
|
10
10
|
//
|
|
@@ -265,7 +265,7 @@ function quotaPhrase(outcome: QuotaRefreshOutcome): string {
|
|
|
265
265
|
* nothing to report.
|
|
266
266
|
*
|
|
267
267
|
* Only providers that expose the check-in route appear here at all: the sweep
|
|
268
|
-
* skips the rest, and `daily unsupported` on every non-
|
|
268
|
+
* skips the rest, and `daily unsupported` on every non-CodeBuddy account is
|
|
269
269
|
* pure noise. The routine "nothing to claim today" states collapse to one
|
|
270
270
|
* short phrase so the line stays scannable; only a real grant or a failure
|
|
271
271
|
* carries detail.
|
package/src/workers/scheduler.ts
CHANGED
|
@@ -28,6 +28,19 @@ export interface ScheduledTask {
|
|
|
28
28
|
* and foreground sharing one tick.
|
|
29
29
|
*/
|
|
30
30
|
readonly deferWhenBusy?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* True when this task must NOT be gated by the process-wide `busy` latch
|
|
33
|
+
* (one maintenance task at a time per process).
|
|
34
|
+
*
|
|
35
|
+
* The gate exists so sweeps that contend for the same rows/files never run
|
|
36
|
+
* at once. A task that only does independent network reads (client-version
|
|
37
|
+
* discovery) has nothing to contend over — and a heavy sweep that runs
|
|
38
|
+
* nearly continuously (quota-refresh on a large account set) otherwise
|
|
39
|
+
* starves every rarer task on the same gate: a 30-minute monitor skipped at
|
|
40
|
+
* its single initial tick is not retried for another 30 minutes. Opt-in;
|
|
41
|
+
* side-effecting sweeps must not set it.
|
|
42
|
+
*/
|
|
43
|
+
readonly skipGate?: boolean;
|
|
31
44
|
/**
|
|
32
45
|
* Whether this task's work is SHARED across the fleet, so only one process
|
|
33
46
|
* should run it per interval.
|
|
@@ -321,7 +334,10 @@ export class ScheduledTaskRegistry {
|
|
|
321
334
|
// handles, and the same single core. Queuing the skipped tick would mean
|
|
322
335
|
// every task fires at once once the blocker finishes, which is the burst
|
|
323
336
|
// this rule exists to prevent.
|
|
324
|
-
|
|
337
|
+
// `skipGate` tasks (independent network reads) are exempt: they have no
|
|
338
|
+
// shared state to contend over, and gating them starves rare tasks when a
|
|
339
|
+
// heavy sweep runs nearly continuously.
|
|
340
|
+
if (this.busy !== undefined && task.skipGate !== true) return;
|
|
325
341
|
// G-03: a foreground-deferring task waits out foreground activity (bounded)
|
|
326
342
|
// before latching the shared gate. The gate is NOT latched during the wait,
|
|
327
343
|
// so the re-check below is required: a different task can claim the gate
|
|
@@ -329,9 +345,9 @@ export class ScheduledTaskRegistry {
|
|
|
329
345
|
if (task.deferWhenBusy === true) {
|
|
330
346
|
await deferForForeground(this.now, (ms) => new Promise((r) => setTimeout(r, ms)));
|
|
331
347
|
}
|
|
332
|
-
if (this.running.has(task.name) || this.busy !== undefined) return;
|
|
348
|
+
if (this.running.has(task.name) || (this.busy !== undefined && task.skipGate !== true)) return;
|
|
333
349
|
this.running.add(task.name);
|
|
334
|
-
this.busy = task.name;
|
|
350
|
+
if (task.skipGate !== true) this.busy = task.name;
|
|
335
351
|
let lease: Awaited<ReturnType<MaintenanceLeaseStore["tryAcquire"]>> | undefined;
|
|
336
352
|
try {
|
|
337
353
|
// The gate above is latched before this await so a concurrent tick cannot
|
|
@@ -409,7 +425,9 @@ export class ScheduledTaskRegistry {
|
|
|
409
425
|
} finally {
|
|
410
426
|
this.inFlight.delete(done);
|
|
411
427
|
this.running.delete(task.name);
|
|
412
|
-
|
|
428
|
+
// Only clear the shared gate if THIS task held it — a `skipGate` task
|
|
429
|
+
// never latches it and must not release another task's latch.
|
|
430
|
+
if (this.busy === task.name) this.busy = undefined;
|
|
413
431
|
}
|
|
414
432
|
}
|
|
415
433
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./jsx-runtime-CXUMngI_.js";import{at as t,t as n}from"./entry-Ca7LSCet.js";var r=e();function i(){return(0,r.jsx)(n,{title:`Access Restricted`,description:`Security policy lockout or untrusted origin address`,icon:(0,r.jsx)(t,{size:24}),logoClassName:`bg-red bg-none`,children:(0,r.jsxs)(`div`,{className:`rounded-panel border border-inner-border bg-surface-2 p-7 text-caption leading-relaxed text-text-secondary`,children:[(0,r.jsx)(`strong`,{className:`block text-text-primary mb-2`,children:`HTTP 403 Forbidden`}),`This client IP has been temporarily locked out due to repeated invalid credential attempts or untrusted proxy headers.`]})})}export{i as default};
|
|
Binary file
|
|
Binary file
|
|
Binary file
|