cartethyia 2.7.3 → 2.7.5
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 +2 -0
- package/README.md +17 -5
- package/dist/dashboard/assets/{BannedPage-2TJD37Hb.js → BannedPage-Cj15GsMp.js} +1 -1
- package/dist/dashboard/assets/BannedPage-Cj15GsMp.js.gz +0 -0
- package/dist/dashboard/assets/ClaimGiftsButton-D83pBJ6J.js +1 -0
- package/dist/dashboard/assets/ClaimGiftsButton-D83pBJ6J.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolDetailPage-xefJNRmJ.js → CliToolDetailPage-DZKmVuJN.js} +1 -1
- package/dist/dashboard/assets/CliToolDetailPage-DZKmVuJN.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolsPage-Rj9iHQ3F.js → CliToolsPage-BIccZmeL.js} +1 -1
- package/dist/dashboard/assets/CliToolsPage-BIccZmeL.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-DEEKkYD-.js +1 -0
- package/dist/dashboard/assets/CombosPage-DEEKkYD-.js.gz +0 -0
- package/dist/dashboard/assets/ConsoleLogPage-D5rol2j2.js +1 -0
- package/dist/dashboard/assets/ConsoleLogPage-D5rol2j2.js.gz +0 -0
- package/dist/dashboard/assets/CustomizationPage-BKj_r0rp.js +1 -0
- package/dist/dashboard/assets/CustomizationPage-BKj_r0rp.js.gz +0 -0
- package/dist/dashboard/assets/InjectSystemPromptPanel-B5nZvmf0.js +656 -0
- package/dist/dashboard/assets/InjectSystemPromptPanel-B5nZvmf0.js.gz +0 -0
- package/dist/dashboard/assets/{LoginPage-C4w7vea-.js → LoginPage-DkXb6dx-.js} +1 -1
- package/dist/dashboard/assets/LoginPage-DkXb6dx-.js.gz +0 -0
- package/dist/dashboard/assets/{ModelPicker-BtPcAfot.js → ModelPicker-DnQPSIA8.js} +1 -1
- package/dist/dashboard/assets/ModelPicker-DnQPSIA8.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-Ci2wQKUz.js +1 -0
- package/dist/dashboard/assets/OverviewPage-Ci2wQKUz.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-odlgYrOg.js +5 -0
- package/dist/dashboard/assets/ProviderDetailPage-odlgYrOg.js.gz +0 -0
- package/dist/dashboard/assets/ProviderIcon-EfeloBn4.js +1 -0
- package/dist/dashboard/assets/ProviderIcon-EfeloBn4.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-CqFBQEB8.js +1 -0
- package/dist/dashboard/assets/ProvidersPage-CqFBQEB8.js.gz +0 -0
- package/dist/dashboard/assets/ProxyPage-5SnUSy3j.js +9 -0
- package/dist/dashboard/assets/ProxyPage-5SnUSy3j.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-CmnMDzhP.js +1 -0
- package/dist/dashboard/assets/QuotaPage-CmnMDzhP.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-BJtRZ4qD.js +1 -0
- package/dist/dashboard/assets/SettingsPage-BJtRZ4qD.js.gz +0 -0
- package/dist/dashboard/assets/{SetupPage-BQS0Rx_u.js → SetupPage-WTa0sktC.js} +1 -1
- package/dist/dashboard/assets/SetupPage-WTa0sktC.js.gz +0 -0
- package/dist/dashboard/assets/{StudioPage-TP7voAQ0.js → StudioPage-BfAb5-o_.js} +3 -3
- package/dist/dashboard/assets/StudioPage-BfAb5-o_.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-BNzeZ2Vk.js +56 -0
- package/dist/dashboard/assets/UsagePage-BNzeZ2Vk.js.gz +0 -0
- package/dist/dashboard/assets/api-keys-l29JROPv.js +1 -0
- package/dist/dashboard/assets/api-keys-l29JROPv.js.gz +0 -0
- package/dist/dashboard/assets/app--PJWq8_C.css +2 -0
- package/dist/dashboard/assets/app--PJWq8_C.css.gz +0 -0
- package/dist/dashboard/assets/{assert-C0YYuZJ4.js → assert-C0K-c4eo.js} +1 -1
- package/dist/dashboard/assets/assert-C0K-c4eo.js.gz +0 -0
- package/dist/dashboard/assets/{badge-B_DMpMJN.js → badge-DfbhQU4k.js} +1 -1
- package/dist/dashboard/assets/badge-DfbhQU4k.js.gz +0 -0
- package/dist/dashboard/assets/{banner-DMrMPmth.js → banner-BllT4LcF.js} +1 -1
- package/dist/dashboard/assets/banner-BllT4LcF.js.gz +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/{card-Be5Uzamx.js → card-CtkX66Wd.js} +1 -1
- package/dist/dashboard/assets/card-CtkX66Wd.js.gz +0 -0
- package/dist/dashboard/assets/chevron-left-Bf6CaTSJ.js +1 -0
- package/dist/dashboard/assets/chevron-left-Bf6CaTSJ.js.gz +0 -0
- package/dist/dashboard/assets/{cli-tools-muFRphDu.js → cli-tools-CQXVMn4P.js} +1 -1
- package/dist/dashboard/assets/cli-tools-CQXVMn4P.js.gz +0 -0
- package/dist/dashboard/assets/{clipboard-button-DOfrVmsi.js → clipboard-button-BQqBQd2n.js} +1 -1
- package/dist/dashboard/assets/clipboard-button-BQqBQd2n.js.gz +0 -0
- package/dist/dashboard/assets/{dialog-C9omdjQt.js → dialog-BEK7KP0H.js} +1 -1
- package/dist/dashboard/assets/dialog-BEK7KP0H.js.gz +0 -0
- package/dist/dashboard/assets/{drawer-Bm8WKaGY.js → drawer-BrTEZ8zu.js} +1 -1
- package/dist/dashboard/assets/drawer-BrTEZ8zu.js.gz +0 -0
- package/dist/dashboard/assets/entry-CHWxbS56.js +1 -0
- package/dist/dashboard/assets/entry-CHWxbS56.js.gz +0 -0
- package/dist/dashboard/assets/{entry-q5HwZ8nN.js → entry-EBHJ3DrE.js} +1 -1
- package/dist/dashboard/assets/entry-EBHJ3DrE.js.gz +0 -0
- package/dist/dashboard/assets/entry-LCS85hiq.js +4 -0
- package/dist/dashboard/assets/entry-LCS85hiq.js.gz +0 -0
- package/dist/dashboard/assets/{formatters-BTScrQpe.js → formatters-BAACA727.js} +1 -1
- package/dist/dashboard/assets/formatters-BAACA727.js.gz +0 -0
- package/dist/dashboard/assets/{github-badge-Orjuzemr.js → github-badge-YSCE4UC2.js} +1 -1
- package/dist/dashboard/assets/github-badge-YSCE4UC2.js.gz +0 -0
- package/dist/dashboard/assets/{index-cPrX5vn6.js → index-FQlj0HUT.js} +2 -2
- package/dist/dashboard/assets/index-FQlj0HUT.js.gz +0 -0
- package/dist/dashboard/assets/{inline-Dvux8w-0.js → inline-C4gU5iOL.js} +1 -1
- package/dist/dashboard/assets/inline-C4gU5iOL.js.gz +0 -0
- package/dist/dashboard/assets/{input-CU1Rgf3p.js → input-BHHX_Tmm.js} +1 -1
- package/dist/dashboard/assets/input-BHHX_Tmm.js.gz +0 -0
- package/dist/dashboard/assets/{layout-C_7A6H55.js → layout-CajrYUnD.js} +1 -1
- package/dist/dashboard/assets/{layout-C_7A6H55.js.gz → layout-CajrYUnD.js.gz} +0 -0
- package/dist/dashboard/assets/{list-row-CzFvogbj.js → list-row-Bx2I7XUe.js} +1 -1
- package/dist/dashboard/assets/list-row-Bx2I7XUe.js.gz +0 -0
- package/dist/dashboard/assets/live-DNNqRbj2.js +1 -0
- package/dist/dashboard/assets/live-DNNqRbj2.js.gz +0 -0
- package/dist/dashboard/assets/minimize-2-BTmMTK4o.js +1 -0
- package/dist/dashboard/assets/minimize-2-BTmMTK4o.js.gz +0 -0
- package/dist/dashboard/assets/{mutation-JJGQm8TD.js → mutation-Rr0TIvcj.js} +1 -1
- package/dist/dashboard/assets/mutation-Rr0TIvcj.js.gz +0 -0
- package/dist/dashboard/assets/network-C5UBACrJ.js +1 -0
- package/dist/dashboard/assets/network-C5UBACrJ.js.gz +0 -0
- package/dist/dashboard/assets/numbers-CUWAZK4J.js +2 -0
- package/dist/dashboard/assets/numbers-CUWAZK4J.js.gz +0 -0
- package/dist/dashboard/assets/pagination-Xsi9Qx04.js +1 -0
- package/dist/dashboard/assets/pagination-Xsi9Qx04.js.gz +0 -0
- package/dist/dashboard/assets/{query-keys-CLaNz8Xz.js → query-keys-BloKtaXJ.js} +1 -1
- package/dist/dashboard/assets/query-keys-BloKtaXJ.js.gz +0 -0
- package/dist/dashboard/assets/quota-DvQbD_sr.js +1 -0
- package/dist/dashboard/assets/quota-DvQbD_sr.js.gz +0 -0
- package/dist/dashboard/assets/{routing-BEH32QOC.js → routing-in0f_IfK.js} +1 -1
- package/dist/dashboard/assets/routing-in0f_IfK.js.gz +0 -0
- package/dist/dashboard/assets/{select-B3iTetHN.js → select-BLULNqTp.js} +2 -2
- package/dist/dashboard/assets/select-BLULNqTp.js.gz +0 -0
- package/dist/dashboard/assets/settings-CcGczj6I.js +1 -0
- package/dist/dashboard/assets/settings-CcGczj6I.js.gz +0 -0
- package/dist/dashboard/assets/shield-BMQNxORh.js +1 -0
- package/dist/dashboard/assets/shield-BMQNxORh.js.gz +0 -0
- package/dist/dashboard/assets/{stack-KrOrm7JZ.js → stack-D2lIR0tg.js} +1 -1
- package/dist/dashboard/assets/stack-D2lIR0tg.js.gz +0 -0
- package/dist/dashboard/assets/{state-DLS7IDMy.js → state-DTARjfiW.js} +1 -1
- package/dist/dashboard/assets/state-DTARjfiW.js.gz +0 -0
- package/dist/dashboard/assets/{switch-42ItvbAs.js → switch-c0oPSnqW.js} +1 -1
- package/dist/dashboard/assets/switch-c0oPSnqW.js.gz +0 -0
- package/dist/dashboard/assets/{useMutation-Dmnfh1Ue.js → useMutation-m8WGNPrz.js} +1 -1
- package/dist/dashboard/assets/useMutation-m8WGNPrz.js.gz +0 -0
- package/dist/dashboard/console-backgrounds.jpg +0 -0
- package/dist/dashboard/console-backgrounds_initial.jpg +0 -0
- package/dist/dashboard/index.html +2 -2
- package/dist/dashboard/index.html.gz +0 -0
- package/dist/dashboard/precompressed-assets.json +59 -57
- package/migrations/full-postgres/0027_qoder_identity_genuine_seed.sql +9 -10
- package/migrations/full-postgres/0032_add_provider_pool_accounts.sql +53 -0
- package/migrations/full-postgres/0033_add_api_key_ban.sql +9 -0
- package/migrations/full-postgres/0034_add_api_key_ban_until.sql +7 -0
- package/migrations/full-postgres/0035_align_pool_account_status_enum.sql +21 -0
- package/migrations/full-postgres/0036_system_prompt_presets_refs.sql +10 -0
- package/migrations/full-postgres/0037_share_concurrency_scope.sql +3 -0
- package/migrations/full-postgres/0038_add_accounts_quota_snapshot.sql +7 -0
- package/migrations/full-postgres/0039_add_telemetry_provider_model_indexes.sql +13 -0
- package/migrations/full-postgres/0040_add_models_dialect.sql +3 -0
- package/migrations/full-postgres/0041_add_daily_checkin_ledger_account_fk.sql +7 -0
- package/migrations/lite-sqlite3/0027_qoder_identity_genuine_seed.sql +9 -10
- package/migrations/lite-sqlite3/0032_add_provider_pool_accounts.sql +44 -0
- package/migrations/lite-sqlite3/0033_add_api_key_ban.sql +8 -0
- package/migrations/lite-sqlite3/0034_add_api_key_ban_until.sql +5 -0
- package/migrations/lite-sqlite3/0035_align_pool_account_status_enum.sql +6 -0
- package/migrations/lite-sqlite3/0036_system_prompt_presets_refs.sql +14 -0
- package/migrations/lite-sqlite3/0037_share_concurrency_scope.sql +3 -0
- package/migrations/lite-sqlite3/0038_add_accounts_quota_snapshot.sql +4 -0
- package/migrations/lite-sqlite3/0039_add_telemetry_provider_model_indexes.sql +6 -0
- package/migrations/lite-sqlite3/0040_add_models_dialect.sql +3 -0
- package/migrations/lite-sqlite3/0041_add_daily_checkin_ledger_account_fk.sql +26 -0
- package/package.json +4 -5
- package/scripts/cli/update.ts +15 -41
- package/src/boot/app.ts +67 -10
- package/src/boot/dependencies.ts +786 -732
- package/src/boot/lifecycle.ts +11 -12
- package/src/config/cooldowns.ts +34 -55
- package/src/config/network.ts +8 -4
- package/src/config/package-paths.ts +1 -1
- package/src/config/providers.ts +13 -14
- package/src/config/resources.ts +0 -5
- package/src/config/runtime.ts +2 -5
- package/src/config/spec.ts +26 -6
- package/src/console/api-keys/ban-constants.ts +38 -0
- package/src/console/api-keys/contracts.ts +92 -31
- package/src/console/api-keys/routes.ts +131 -6
- package/src/console/audit/routes.ts +3 -3
- package/src/console/auth/access.ts +4 -4
- package/src/console/auth/account-reset.ts +5 -5
- package/src/console/auth/audit-recorder.ts +1 -1
- package/src/console/auth/lockout.ts +7 -3
- package/src/console/auth/row-coercion.ts +57 -12
- package/src/console/auth/session-resolver.ts +1 -1
- package/src/console/auth/session-service.ts +8 -2
- package/src/console/auth/session.ts +40 -34
- package/src/console/auth/setup-service.ts +4 -3
- package/src/console/auth/user-store.ts +1 -1
- package/src/console/backup/9router-map.ts +0 -3
- package/src/console/backup/contracts.ts +11 -9
- package/src/console/backup/export-endpoint.ts +11 -12
- package/src/console/backup/nine-router.ts +1 -7
- package/src/console/backup/routes.ts +32 -36
- package/src/console/backup/service.ts +468 -468
- package/src/console/backup/store.ts +47 -29
- package/src/console/backup/validate.ts +11 -1
- package/src/console/cli-tools/contracts.ts +7 -7
- package/src/console/cli-tools/injectors/cline.ts +110 -110
- package/src/console/cli-tools/injectors/codex.ts +181 -181
- package/src/console/cli-tools/injectors/copilot.ts +108 -108
- package/src/console/cli-tools/injectors/driver.ts +247 -247
- package/src/console/cli-tools/injectors/jcode.ts +115 -115
- package/src/console/cli-tools/injectors/openclaw.ts +161 -161
- package/src/console/cli-tools/injectors/opencode.ts +153 -153
- package/src/console/cli-tools/routes.ts +4 -4
- package/src/console/cli-tools/service.ts +1 -1
- package/src/console/cli-tools/store.ts +2 -2
- package/src/console/console-router-guards.ts +2 -2
- package/src/console/console-router.ts +36 -4
- package/src/console/dashboard-assets.ts +9 -9
- package/src/console/data-management/routes.ts +3 -3
- package/src/console/domain-registration.ts +18 -4
- package/src/console/inferhub/client.ts +0 -7
- package/src/console/inferhub/key-store.ts +1 -1
- package/src/console/inferhub/normalize.ts +2 -2
- package/src/console/inferhub/routes.ts +1 -1
- package/src/console/inferhub/types.ts +1 -1
- package/src/console/observability/contracts.ts +5 -1
- package/src/console/observability/live.ts +34 -21
- package/src/console/observability/logs.ts +4 -4
- package/src/console/observability/performance.ts +3 -3
- package/src/console/observability/routes.ts +3 -3
- package/src/console/observability/sse.ts +62 -8
- package/src/console/observability/store.ts +36 -20
- package/src/console/providers/catalog/catalog-projections.ts +1 -1
- package/src/console/providers/catalog/contracts.ts +82 -22
- package/src/console/providers/catalog/model-operations.ts +1 -1
- package/src/console/providers/catalog/provider-operations.ts +110 -17
- package/src/console/providers/catalog/public-model-store.ts +0 -0
- package/src/console/providers/catalog/routes.ts +30 -6
- package/src/console/providers/catalog/store-helpers.ts +349 -326
- package/src/console/providers/catalog/store.ts +1662 -1292
- package/src/console/providers/detail/routes.ts +4 -4
- package/src/console/providers/oauth/callback-listener.ts +100 -18
- package/src/console/providers/oauth/routes.ts +95 -16
- package/src/console/quota/account-quota-global.ts +41 -3
- package/src/console/quota/account-quota-shared.ts +10 -3
- package/src/console/quota/account-quota-tenant.ts +285 -67
- package/src/console/quota/account-test-egress.ts +4 -4
- package/src/console/quota/daily-growth-job.ts +308 -0
- package/src/console/quota/native-identity.ts +2 -2
- package/src/console/quota/quota-view.ts +1 -1
- package/src/console/remote-support/routes.ts +1 -1
- package/src/console/remote-support/service.ts +2 -2
- package/src/console/routing/model/contracts.ts +1 -1
- package/src/console/routing/model/routes.ts +3 -3
- package/src/console/routing/pools/contracts.ts +13 -10
- package/src/console/routing/pools/import-parse.ts +3 -3
- package/src/console/routing/pools/operations.ts +14 -7
- package/src/console/routing/pools/probe-verdict.ts +8 -3
- package/src/console/routing/pools/relay-deploy.ts +12 -12
- package/src/console/routing/pools/routes.ts +3 -3
- package/src/console/routing/pools/store.ts +21 -1
- package/src/console/settings/contracts.ts +29 -2
- package/src/console/settings/routes.ts +3 -3
- package/src/console/settings/store.ts +20 -0
- package/src/console/share/share-router.ts +112 -44
- package/src/console/share/share-stats.ts +109 -39
- package/src/console/share/share-usage.ts +1 -1
- package/src/console/shared/errors.ts +2 -2
- package/src/console/shared/object.ts +18 -0
- package/src/console/shared/read-through-cache.ts +42 -6
- package/src/console/shared/transaction.ts +14 -0
- package/src/console/system-prompt/contracts.ts +89 -12
- package/src/console/system-prompt/routes.ts +98 -45
- package/src/console/updates/apply-update.ts +244 -0
- package/src/console/updates/routes.ts +256 -98
- package/src/main.ts +11 -5
- package/src/network/http2-bidi.ts +1 -1
- package/src/network/ip-utils.ts +298 -0
- package/src/network/outbound-fetch.ts +76 -5
- package/src/network/pool/agent.ts +7 -6
- package/src/network/pool/byte-accounting.ts +1 -1
- package/src/network/pool/resolver.ts +55 -51
- package/src/network/pool/selector.ts +150 -136
- package/src/network/pool-cooldown-store.ts +71 -16
- package/src/network/pool-health-machine.ts +22 -2
- package/src/network/rate-limit-verdict.ts +68 -0
- package/src/network/retry.ts +1 -1
- package/src/network/ssrf.ts +24 -75
- package/src/observability/event-log.ts +2 -2
- package/src/observability/event-query.ts +286 -214
- package/src/observability/log-sanitize.ts +1 -1
- package/src/observability/metrics.ts +4 -4
- package/src/observability/payload-capture.ts +6 -5
- package/src/observability/payload-store.ts +1 -1
- package/src/observability/runtime-metrics.ts +1 -1
- package/src/observability/telemetry-buffer.ts +12 -3
- package/src/observability/telemetry-reconciliation.ts +3 -3
- package/src/observability/telemetry-status.ts +1 -1
- package/src/observability/token-speed.ts +1 -1
- package/src/persistence/connection-url.ts +1 -1
- package/src/persistence/db-handle.ts +1 -1
- package/src/persistence/db-pg.ts +2 -2
- package/src/persistence/db-sqlite.ts +10 -5
- package/src/persistence/dialect.ts +5 -1
- package/src/persistence/readiness.ts +19 -7
- package/src/persistence/redis.ts +1 -1
- package/src/persistence/schema.ts +177 -45
- package/src/persistence/shared-cache.ts +2 -2
- package/src/persistence/sort-order.ts +1 -1
- package/src/persistence/stores/api-key-store.ts +109 -4
- package/src/persistence/stores/share-store.ts +20 -8
- package/src/persistence/stores/telemetry-store.ts +1 -1
- package/src/persistence/system-prompt-store.ts +63 -18
- package/src/persistence/tenant-preferences.ts +1 -1
- package/src/persistence/ttl-cache.ts +3 -3
- package/src/persistence/usage-flush.ts +7 -2
- package/src/protocol/canonical-model.ts +1 -1
- package/src/protocol/codecs.ts +12 -16
- package/src/protocol/dsml.ts +3 -49
- package/src/protocol/gateway-error.ts +6 -3
- package/src/protocol/image-clamp.ts +2 -2
- package/src/protocol/image-generation.ts +2 -2
- package/src/protocol/reasoning-text.ts +1 -1
- package/src/protocol/reasoning.ts +7 -52
- package/src/protocol/registry.ts +50 -15
- package/src/protocol/request/chat.ts +46 -19
- package/src/protocol/request/codex.ts +1 -1
- package/src/protocol/request/messages.ts +46 -14
- package/src/protocol/request/responses.ts +19 -10
- package/src/protocol/response/chat.ts +27 -12
- package/src/protocol/response/codex.ts +2 -2
- package/src/protocol/response/gemini.ts +1 -1
- package/src/protocol/response/messages.ts +6 -6
- package/src/protocol/response/omp-tool-call-markup.ts +1 -1
- package/src/protocol/response/responses.ts +3 -3
- package/src/protocol/sse-decoder.ts +64 -4
- package/src/protocol/stop-reason.ts +2 -2
- package/src/protocol/think-split.ts +347 -0
- package/src/protocol/translation/attachment-integrity.ts +3 -3
- package/src/protocol/translation/cache-controls.ts +8 -20
- package/src/protocol/translation/capabilities.ts +8 -8
- package/src/protocol/translation/dialect/deepseek.ts +10 -0
- package/src/protocol/translation/dialect/inband.ts +39 -0
- package/src/protocol/translation/dialect/model-thinking.ts +89 -0
- package/src/protocol/translation/dialect/qwen.ts +114 -0
- package/src/protocol/translation/dialect/resolver.ts +83 -0
- package/src/protocol/translation/dialect/rules.ts +93 -0
- package/src/protocol/translation/dialect/thinking-ladder.ts +245 -0
- package/src/protocol/translation/dialect/types.ts +58 -0
- package/src/protocol/translation/quirks.ts +18 -4
- package/src/protocol/translation/thinking.ts +12 -252
- package/src/protocol/translation/tool-id.ts +3 -3
- package/src/protocol/translation/tool-repair.ts +1 -1
- package/src/protocol/upstream/post-json.ts +6 -1
- package/src/protocol/upstream/send-claude-messages.ts +3 -3
- package/src/providers/adapters/base-adapter.ts +1 -1
- package/src/providers/adapters/compatible-adapter.ts +44 -5
- package/src/providers/authentication/jwt-validator.ts +0 -5
- package/src/providers/authentication/oauth-client.ts +254 -253
- package/src/providers/authentication/oauth-flow-store.ts +42 -7
- package/src/providers/authentication/oauth-refresh-service.ts +2 -2
- package/src/providers/bundled-discovery-providers.ts +6 -30
- package/src/providers/configured-openai-providers.ts +82 -97
- package/src/providers/configured-provider.ts +1 -1
- package/src/providers/default-registry.ts +23 -35
- package/src/providers/discovery/catalog/catalog-format.ts +13 -2
- package/src/providers/discovery/discovery-types.ts +0 -1
- package/src/providers/discovery/openai-model-discovery.ts +2 -2
- package/src/providers/discovery/probe-phases.ts +50 -15
- package/src/providers/discovery/probing-service.ts +18 -20
- package/src/providers/integrations/agentrouter/agentrouter.ts +14 -5
- package/src/providers/integrations/alibabacp/alibabacp.ts +2 -2
- package/src/providers/integrations/anthropic.ts +4 -11
- package/src/providers/integrations/antigravity/antigravity-oauth.ts +0 -1
- package/src/providers/integrations/antigravity/antigravity-protocol.ts +0 -14
- package/src/providers/integrations/antigravity/antigravity.ts +15 -26
- package/src/providers/integrations/buddy/buddy-catalog-shared.ts +2 -2
- package/src/providers/integrations/buddy/buddy-chat-shared.ts +20 -4
- package/src/providers/integrations/buddy/buddy-cli-headers.ts +19 -52
- package/src/providers/integrations/buddy/buddy-discovery-shared.ts +37 -6
- package/src/providers/integrations/buddy/buddy-identity.ts +108 -1
- package/src/providers/integrations/buddy/buddy-media.ts +16 -16
- package/src/providers/integrations/buddy/buddy-oauth-shared.ts +1 -1
- package/src/providers/integrations/buddy/codebuddy/cn-provider.ts +1 -2
- package/src/providers/integrations/buddy/codebuddy/provider.ts +5 -16
- package/src/providers/integrations/buddy/codebuddy/shared.ts +30 -9
- package/src/providers/integrations/buddy/workbuddy/provider.ts +6 -10
- package/src/providers/integrations/buddy/workbuddy/shared.ts +21 -3
- package/src/providers/integrations/claude/claude-betas.ts +1 -1
- package/src/providers/integrations/claude/claude-cch.ts +148 -148
- package/src/providers/integrations/claude/claude-credentials.ts +1 -1
- package/src/providers/integrations/claude/claude-slow-lane-retry.ts +1 -1
- package/src/providers/integrations/claude/claude.ts +3 -10
- package/src/providers/integrations/claude/fallback-credit.ts +3 -7
- package/src/providers/integrations/cline/cline.ts +2 -2
- package/src/providers/integrations/cloudflareai/cloudflareai.ts +4 -7
- package/src/providers/integrations/codex/codex-device-code.ts +101 -101
- package/src/providers/integrations/codex/codex-errors.ts +1 -1
- package/src/providers/integrations/codex/codex-oauth.ts +0 -1
- package/src/providers/integrations/codex/codex.ts +14 -15
- package/src/providers/integrations/commandcode/commandcode.ts +76 -116
- package/src/providers/integrations/commandcode/quota.ts +132 -48
- package/src/providers/integrations/cursor/cursor-http2.ts +11 -14
- package/src/providers/integrations/cursor/cursor-quota.ts +2 -6
- package/src/providers/integrations/cursor/cursor-request.ts +0 -87
- package/src/providers/integrations/cursor/cursor-shared.ts +0 -4
- package/src/providers/integrations/cursor/cursor.ts +53 -20
- package/src/providers/integrations/cursor/protocol/framing.ts +0 -56
- package/src/providers/integrations/cursor/protocol/messages.ts +0 -96
- package/src/providers/integrations/factory/factory.ts +13 -13
- package/src/providers/integrations/gemini.ts +11 -11
- package/src/providers/integrations/github/github-discovery.ts +55 -10
- package/src/providers/integrations/github/github-oauth.ts +6 -5
- package/src/providers/integrations/github/github.ts +47 -20
- package/src/providers/integrations/grok/grok-oauth.ts +261 -261
- package/src/providers/integrations/grok/grok-quota-frame.ts +1 -1
- package/src/providers/integrations/grok/grok-quota.ts +16 -7
- package/src/providers/integrations/grok/grok-ratelimit-store.ts +0 -5
- package/src/providers/integrations/grok/grok-ratelimit.ts +3 -0
- package/src/providers/integrations/grok/grok.ts +88 -42
- package/src/providers/integrations/inferhub.ts +4 -11
- package/src/providers/integrations/kilo/kilo-oauth.ts +1 -1
- package/src/providers/integrations/kimi/kimi.ts +4 -11
- package/src/providers/integrations/kiro/kiro-cache.ts +31 -0
- package/src/providers/integrations/kiro/kiro-catalog.ts +31 -5
- package/src/providers/integrations/kiro/kiro-discovery.ts +47 -43
- package/src/providers/integrations/kiro/kiro-machine-id.ts +6 -3
- package/src/providers/integrations/kiro/kiro-oauth.ts +523 -255
- package/src/providers/integrations/kiro/kiro-quota.ts +35 -47
- package/src/providers/integrations/kiro/kiro-request.ts +8 -11
- package/src/providers/integrations/kiro/kiro-stream.ts +13 -0
- package/src/providers/integrations/kiro/kiro.ts +91 -78
- package/src/providers/integrations/muse/muse-oauth.ts +0 -1
- package/src/providers/integrations/muse/muse-quota.ts +0 -4
- package/src/providers/integrations/muse/muse.ts +6 -9
- package/src/providers/integrations/opencode/fingerprint.ts +7 -5
- package/src/providers/integrations/opencode/provider.ts +17 -24
- package/src/providers/integrations/perplexity.ts +2 -2
- package/src/providers/integrations/qoder/qoder-catalog.ts +132 -17
- package/src/providers/integrations/qoder/qoder-checkin.ts +26 -8
- package/src/providers/integrations/qoder/qoder-native-identity-store.ts +9 -8
- package/src/providers/integrations/qoder/qoder-oauth.ts +165 -25
- package/src/providers/integrations/qoder/qoder-quota.ts +48 -6
- package/src/providers/integrations/qoder/qoder-realm.ts +22 -28
- package/src/providers/integrations/qoder/qoder-sse.ts +159 -0
- package/src/providers/integrations/qoder/qoder-umid.ts +33 -38
- package/src/providers/integrations/qoder/qoder-virtual.ts +14 -2
- package/src/providers/integrations/qoder/qoder.ts +521 -63
- package/src/providers/integrations/shared/connect.ts +0 -54
- package/src/providers/integrations/shared/hash.ts +15 -0
- package/src/providers/integrations/shared/session-cache.ts +136 -0
- package/src/providers/integrations/tokenharbor.ts +2 -2
- package/src/providers/integrations/trae/trae-cache.ts +7 -87
- package/src/providers/integrations/trae/trae-catalog.ts +1 -6
- package/src/providers/integrations/trae/trae-protocol.ts +17 -8
- package/src/providers/integrations/trae/trae-realm.ts +0 -7
- package/src/providers/integrations/trae/trae.ts +59 -19
- package/src/providers/integrations/xai/xai-oauth.ts +5 -5
- package/src/providers/integrations/zcode/oauth.ts +1 -1
- package/src/providers/integrations/zcode-start-plan/gifts.ts +265 -0
- package/src/providers/integrations/zcode-start-plan/oauth.ts +154 -0
- package/src/providers/integrations/zcode-start-plan/provider.ts +131 -0
- package/src/providers/integrations/zcode-start-plan/quota.ts +152 -0
- package/src/providers/integrations/zcode-start-plan/zcode_prompt.json +10 -0
- package/src/providers/operations/account-error-classification.ts +131 -116
- package/src/providers/operations/account-health-service.ts +31 -39
- package/src/providers/operations/account-reset-service.ts +58 -1
- package/src/providers/operations/cli-platform.ts +31 -5
- package/src/providers/operations/client-version-resolver.ts +4 -6
- package/src/providers/operations/client-versions.ts +10 -7
- package/src/providers/operations/provider-catalog-seeder.ts +2 -0
- package/src/providers/operations/provider-catalog-service.ts +22 -6
- package/src/providers/operations/provider-credential-service.ts +35 -6
- package/src/providers/operations/upstream-deadline.ts +3 -3
- package/src/providers/provider-contracts.ts +65 -10
- package/src/providers/provider-credential-resolver.ts +1 -1
- package/src/providers/provider-metadata.ts +17 -2
- package/src/providers/provider-model-definition.ts +22 -1
- package/src/providers/provider-probe.ts +4 -2
- package/src/providers/provider-registry.ts +4 -4
- package/src/providers/provider-usage.ts +81 -16
- package/src/providers/quota/cache.ts +29 -0
- package/src/providers/quota/quota-contracts.ts +28 -10
- package/src/providers/quota/refresh.ts +29 -6
- package/src/providers/quota/snapshot.ts +94 -0
- package/src/providers/search/search-provider.ts +6 -8
- package/src/providers/search/search-providers.ts +2 -1
- package/src/security/abuse.ts +8 -8
- package/src/security/admission/reasons.ts +17 -17
- package/src/security/admission/service.ts +2 -2
- package/src/security/admission/ttl.ts +61 -61
- package/src/security/api-key-auth.ts +20 -8
- package/src/security/client-router-fingerprint.ts +4 -4
- package/src/security/credential-codec.ts +3 -3
- package/src/security/csrf.ts +2 -2
- package/src/security/ip-boundary.ts +16 -189
- package/src/security/model-access-rule.ts +1 -1
- package/src/security/outbound-headers.ts +18 -0
- package/src/shared/coerce.ts +19 -0
- package/src/shared/invoke-guard.ts +47 -0
- package/src/transport/contracts.ts +13 -4
- package/src/transport/dispatch/attempt-finalize.ts +5 -4
- package/src/transport/dispatch/attempt-loop.ts +10 -7
- package/src/transport/dispatch/capture-policy.ts +34 -37
- package/src/transport/dispatch/empty-stream.ts +28 -25
- package/src/transport/dispatch/generation.ts +33 -53
- package/src/transport/dispatch/leases.ts +8 -8
- package/src/transport/dispatch/native-shared.ts +127 -0
- package/src/transport/dispatch/proxy-request.ts +10 -8
- package/src/transport/dispatch/responses-compact.ts +35 -56
- package/src/transport/dispatch/retry-policy.ts +4 -67
- package/src/transport/dispatch/stream-bridge.ts +1 -1
- package/src/transport/dispatch/streaming/encoder.ts +18 -72
- package/src/transport/dispatch/streaming/finalize.ts +11 -10
- package/src/transport/dispatch/streaming/stream.ts +7 -3
- package/src/transport/dispatch/streaming/thinking-loop.ts +1 -1
- package/src/transport/dispatch/systemone.ts +27 -55
- package/src/transport/dispatch/token-count.ts +49 -46
- package/src/transport/dispatch/websearch.ts +24 -50
- package/src/transport/drain-endpoint.ts +3 -3
- package/src/transport/failure-policy.ts +19 -6
- package/src/transport/guards/auth-guard.ts +6 -11
- package/src/transport/guards/body-policy.ts +7 -7
- package/src/transport/guards/error-lifecycle.ts +18 -3
- package/src/transport/guards/guard-errors.ts +7 -3
- package/src/transport/guards/headroom-guard.ts +2 -2
- package/src/transport/guards/pipeline.ts +7 -7
- package/src/transport/guards/readiness-guard.ts +16 -2
- package/src/transport/guards/request-context.ts +15 -20
- package/src/transport/request/preparer.ts +306 -27
- package/src/transport/request/rtk/compress-request.ts +3 -3
- package/src/transport/request/rtk/rtk-constants.ts +2 -2
- package/src/transport/request/rtk/rtk-filters.ts +8 -8
- package/src/transport/request/state.ts +5 -20
- package/src/transport/request/system-prompt-injection.ts +74 -11
- package/src/transport/request/tenant-preferences.ts +22 -0
- package/src/transport/routing/candidate-index.ts +2 -2
- package/src/transport/routing/round-robin.ts +1 -1
- package/src/transport/routing/route-catalog.ts +113 -19
- package/src/transport/routing/route-model.ts +131 -38
- package/src/transport/routing/router.ts +154 -39
- package/src/transport/shutdown-notice.ts +21 -9
- package/src/transport/surface/adapters.ts +3 -3
- package/src/transport/surface/chat/encode.ts +7 -7
- package/src/transport/surface/chat/parse.ts +7 -7
- package/src/transport/surface/completion.ts +3 -3
- package/src/transport/surface/content-parts.ts +1 -1
- package/src/transport/surface/dialects.ts +2 -2
- package/src/transport/surface/messages/encode.ts +1 -1
- package/src/transport/surface/messages/parse.ts +3 -3
- package/src/transport/surface/responses/adapter.ts +1 -1
- package/src/transport/surface/responses/errors.ts +0 -9
- package/src/transport/vision-handoff-cache.ts +58 -0
- package/src/transport/vision-handoff.ts +376 -0
- package/src/workers/account-identity-sweep.ts +2 -2
- package/src/workers/buddy-growth-tasks.ts +392 -346
- package/src/workers/daily-checkin.ts +102 -49
- package/src/workers/maintenance-lease.ts +2 -35
- package/src/workers/oauth-refresh-sweep.ts +8 -1
- package/src/workers/quota-refresh-sweep.ts +120 -82
- package/src/workers/scheduler.ts +67 -4
- package/src/workers/sweep-runner.ts +24 -5
- package/src/workers/zcode-gift-claim.ts +108 -0
- package/dist/dashboard/assets/AccountCooldown-Bjo92Qat.js +0 -1
- package/dist/dashboard/assets/AccountCooldown-Bjo92Qat.js.gz +0 -0
- package/dist/dashboard/assets/BannedPage-2TJD37Hb.js.gz +0 -0
- package/dist/dashboard/assets/CliToolDetailPage-xefJNRmJ.js.gz +0 -0
- package/dist/dashboard/assets/CliToolsPage-Rj9iHQ3F.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-JEbYJFxw.js +0 -1
- package/dist/dashboard/assets/CombosPage-JEbYJFxw.js.gz +0 -0
- package/dist/dashboard/assets/ConsoleLogPage-C3xx_inM.js +0 -1
- package/dist/dashboard/assets/ConsoleLogPage-C3xx_inM.js.gz +0 -0
- package/dist/dashboard/assets/CustomizationPage-Dw306gJU.js +0 -1
- package/dist/dashboard/assets/CustomizationPage-Dw306gJU.js.gz +0 -0
- package/dist/dashboard/assets/HealthEventsModal-jaBo1TWV.js +0 -1
- package/dist/dashboard/assets/HealthEventsModal-jaBo1TWV.js.gz +0 -0
- package/dist/dashboard/assets/LoginPage-C4w7vea-.js.gz +0 -0
- package/dist/dashboard/assets/ModelPicker-BtPcAfot.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-CGC5gNs1.js +0 -1
- package/dist/dashboard/assets/OverviewPage-CGC5gNs1.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-DQcthNGt.js +0 -4
- package/dist/dashboard/assets/ProviderDetailPage-DQcthNGt.js.gz +0 -0
- package/dist/dashboard/assets/ProviderIcon-FB6yS4v1.js +0 -1
- package/dist/dashboard/assets/ProviderIcon-FB6yS4v1.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-0OsXRGXe.js +0 -1
- package/dist/dashboard/assets/ProvidersPage-0OsXRGXe.js.gz +0 -0
- package/dist/dashboard/assets/ProxyPage-DdPc8slb.js +0 -9
- package/dist/dashboard/assets/ProxyPage-DdPc8slb.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-Ci5O4BnH.js +0 -1
- package/dist/dashboard/assets/QuotaPage-Ci5O4BnH.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-CDZjTt87.js +0 -1
- package/dist/dashboard/assets/SettingsPage-CDZjTt87.js.gz +0 -0
- package/dist/dashboard/assets/SetupPage-BQS0Rx_u.js.gz +0 -0
- package/dist/dashboard/assets/SortableList-BAL5npBC.js +0 -1
- package/dist/dashboard/assets/SortableList-BAL5npBC.js.gz +0 -0
- package/dist/dashboard/assets/StudioPage-TP7voAQ0.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-Cj_fEzhg.js +0 -56
- package/dist/dashboard/assets/UsagePage-Cj_fEzhg.js.gz +0 -0
- package/dist/dashboard/assets/api-keys-MbI7e7rt.js +0 -1
- package/dist/dashboard/assets/api-keys-MbI7e7rt.js.gz +0 -0
- package/dist/dashboard/assets/app-B2vyPoII.css +0 -2
- package/dist/dashboard/assets/app-B2vyPoII.css.gz +0 -0
- package/dist/dashboard/assets/assert-C0YYuZJ4.js.gz +0 -0
- package/dist/dashboard/assets/badge-B_DMpMJN.js.gz +0 -0
- package/dist/dashboard/assets/banner-DMrMPmth.js.gz +0 -0
- package/dist/dashboard/assets/card-Be5Uzamx.js.gz +0 -0
- package/dist/dashboard/assets/cli-tools-muFRphDu.js.gz +0 -0
- package/dist/dashboard/assets/clipboard-button-DOfrVmsi.js.gz +0 -0
- package/dist/dashboard/assets/dialog-C9omdjQt.js.gz +0 -0
- package/dist/dashboard/assets/drawer-Bm8WKaGY.js.gz +0 -0
- package/dist/dashboard/assets/entry-DS90gUks.js +0 -1
- package/dist/dashboard/assets/entry-DS90gUks.js.gz +0 -0
- package/dist/dashboard/assets/entry-j40LJotO.js +0 -4
- package/dist/dashboard/assets/entry-j40LJotO.js.gz +0 -0
- package/dist/dashboard/assets/entry-q5HwZ8nN.js.gz +0 -0
- package/dist/dashboard/assets/formatters-BTScrQpe.js.gz +0 -0
- package/dist/dashboard/assets/github-badge-Orjuzemr.js.gz +0 -0
- package/dist/dashboard/assets/index-cPrX5vn6.js.gz +0 -0
- package/dist/dashboard/assets/inline-Dvux8w-0.js.gz +0 -0
- package/dist/dashboard/assets/input-CU1Rgf3p.js.gz +0 -0
- package/dist/dashboard/assets/list-row-CzFvogbj.js.gz +0 -0
- package/dist/dashboard/assets/live-KaG15HLQ.js +0 -1
- package/dist/dashboard/assets/live-KaG15HLQ.js.gz +0 -0
- package/dist/dashboard/assets/minimize-2-D-MN8W8a.js +0 -1
- package/dist/dashboard/assets/minimize-2-D-MN8W8a.js.gz +0 -0
- package/dist/dashboard/assets/mutation-JJGQm8TD.js.gz +0 -0
- package/dist/dashboard/assets/numbers-BNDZnsUE.js +0 -2
- package/dist/dashboard/assets/numbers-BNDZnsUE.js.gz +0 -0
- package/dist/dashboard/assets/query-keys-CLaNz8Xz.js.gz +0 -0
- package/dist/dashboard/assets/quota-DZGyp0N5.js +0 -1
- package/dist/dashboard/assets/quota-DZGyp0N5.js.gz +0 -0
- package/dist/dashboard/assets/routing-BEH32QOC.js.gz +0 -0
- package/dist/dashboard/assets/select-B3iTetHN.js.gz +0 -0
- package/dist/dashboard/assets/settings-Dt3Eqbnq.js +0 -1
- package/dist/dashboard/assets/settings-Dt3Eqbnq.js.gz +0 -0
- package/dist/dashboard/assets/stack-KrOrm7JZ.js.gz +0 -0
- package/dist/dashboard/assets/state-DLS7IDMy.js.gz +0 -0
- package/dist/dashboard/assets/stream-retry-5QnVuSSo.js +0 -1
- package/dist/dashboard/assets/stream-retry-5QnVuSSo.js.gz +0 -0
- package/dist/dashboard/assets/switch-42ItvbAs.js.gz +0 -0
- package/dist/dashboard/assets/useMutation-Dmnfh1Ue.js.gz +0 -0
- package/src/network/response-headers.ts +0 -39
- package/src/protocol/response/dsml.ts +0 -38
- package/src/providers/integrations/xiaomi-mimo/think-stream.ts +0 -229
- /package/dist/dashboard/assets/{app-wvwCi4Eh.js → app-Bgd3zANQ.js} +0 -0
- /package/dist/dashboard/assets/{app-wvwCi4Eh.js.gz → app-Bgd3zANQ.js.gz} +0 -0
- /package/dist/dashboard/assets/brand/{og_bansos.webp → og_bansos_initial.webp} +0 -0
- /package/dist/dashboard/assets/brand/{og_image.webp → og_image_initial.webp} +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// Kiro (
|
|
1
|
+
// Kiro (Kiro Control Plane) quota.
|
|
2
2
|
//
|
|
3
|
-
// Billing lives on
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
3
|
+
// Billing lives on the Kiro control-plane (management) service — in the
|
|
4
|
+
// 1.4.62 build `GetUsageLimits` is `GET /Get-Usage-Limits` on
|
|
5
|
+
// `https://management.{region}.kiro.dev`. The legacy `codewhisperer.*` /
|
|
6
|
+
// `q.*` AWS usage surfaces are no longer used.
|
|
7
7
|
//
|
|
8
8
|
// The account's region and profile matter here for the same reason they matter
|
|
9
9
|
// at dispatch: the request is scoped to them, and an account-bound credential
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
// device here and another at dispatch is the shape this gateway exists to avoid.
|
|
16
16
|
|
|
17
17
|
import type {
|
|
18
|
-
FetchLike,
|
|
19
18
|
ProviderQuotaResult,
|
|
20
19
|
ProviderQuotaWindow,
|
|
21
20
|
} from "../../quota/quota-contracts";
|
|
@@ -35,9 +34,16 @@ import {
|
|
|
35
34
|
} from "../../operations/client-versions";
|
|
36
35
|
import { machineIdForAuthState } from "./kiro-machine-id";
|
|
37
36
|
import { resolveKiroProfileArn } from "./kiro-profile";
|
|
37
|
+
import { AWS_REGION_PATTERN, KIRO_DEFAULT_REGION, KIRO_MANAGEMENT_HOST_TEMPLATE } from "./kiro-catalog";
|
|
38
38
|
|
|
39
|
-
/**
|
|
40
|
-
|
|
39
|
+
/**
|
|
40
|
+
* The fetcher shape this module needs: a plain callable. `FetchLike` from the
|
|
41
|
+
* quota contracts is the global `typeof fetch` (which carries extra callable
|
|
42
|
+
* properties like `preconnect`), and the OAuth client passes its narrower
|
|
43
|
+
* structural `FetchLike` here — so accept the common callable shape instead of
|
|
44
|
+
* either full type.
|
|
45
|
+
*/
|
|
46
|
+
type KiroFetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
41
47
|
|
|
42
48
|
interface KiroQuotaAuth {
|
|
43
49
|
readonly region: string;
|
|
@@ -50,7 +56,7 @@ interface KiroQuotaAuth {
|
|
|
50
56
|
function quotaAuth(context: QuotaCollectionContext | undefined): KiroQuotaAuth {
|
|
51
57
|
const raw = context?.auth_state ?? {};
|
|
52
58
|
const regionRaw = typeof raw["region"] === "string" ? raw["region"].trim() : "";
|
|
53
|
-
const region = AWS_REGION_PATTERN.test(regionRaw) ? regionRaw :
|
|
59
|
+
const region = AWS_REGION_PATTERN.test(regionRaw) ? regionRaw : KIRO_DEFAULT_REGION;
|
|
54
60
|
const authMethod = typeof raw["authMethod"] === "string" ? raw["authMethod"] : "builder-id";
|
|
55
61
|
// The usage surface is profile-scoped and refuses a request without the field,
|
|
56
62
|
// exactly as generation does, so it scopes to the same value generation does:
|
|
@@ -72,13 +78,13 @@ function usageHeaders(credential: string, auth: KiroQuotaAuth): Record<string, s
|
|
|
72
78
|
connection: "close",
|
|
73
79
|
"amz-sdk-request": "attempt=1; max=1",
|
|
74
80
|
"amz-sdk-invocation-id": crypto.randomUUID(),
|
|
75
|
-
"x-amzn-kiro-agent-mode": "vibe",
|
|
76
|
-
"x-amzn-codewhisperer-optout": "true",
|
|
77
81
|
"x-amz-user-agent": buildKiroAmzUserAgent(version, auth.machineId),
|
|
78
82
|
"user-agent": buildKiroRuntimeUserAgent(version, auth.machineId),
|
|
83
|
+
"x-kiro-machineid": auth.machineId,
|
|
79
84
|
};
|
|
80
|
-
if (auth.authMethod === "api_key") headers["
|
|
81
|
-
else if (auth.authMethod === "external_idp") headers["
|
|
85
|
+
if (auth.authMethod === "api_key") headers["TokenType"] = "API_KEY";
|
|
86
|
+
else if (auth.authMethod === "external_idp") headers["TokenType"] = "EXTERNAL_IDP";
|
|
87
|
+
else if (auth.authMethod === "idc") headers["TokenType"] = "SSO_OIDC";
|
|
82
88
|
return headers;
|
|
83
89
|
}
|
|
84
90
|
|
|
@@ -127,11 +133,18 @@ function parseUsage(payload: unknown): ProviderQuotaResult {
|
|
|
127
133
|
}
|
|
128
134
|
}
|
|
129
135
|
const subscription = record(root["subscriptionInfo"]);
|
|
136
|
+
// The bundle asks with `isEmailRequired: true`, and the upstream then reports
|
|
137
|
+
// the account's email in `userInfo.email`. That is the only identity a social/
|
|
138
|
+
// imported token exposes (the access token itself is opaque, not a JWT), so it
|
|
139
|
+
// becomes the suggested account label for the refresh sweep to adopt.
|
|
140
|
+
const userInfo = record(root["userInfo"]);
|
|
141
|
+
const email = text(userInfo?.["email"]);
|
|
130
142
|
return {
|
|
131
143
|
source: "kiro",
|
|
132
144
|
plan: text(subscription?.["subscriptionTitle"]) ?? "Kiro",
|
|
133
145
|
windows,
|
|
134
146
|
error: null,
|
|
147
|
+
...(email === null ? {} : { accountLabel: email }),
|
|
135
148
|
};
|
|
136
149
|
}
|
|
137
150
|
|
|
@@ -144,7 +157,7 @@ function parseUsage(payload: unknown): ProviderQuotaResult {
|
|
|
144
157
|
*/
|
|
145
158
|
export async function fetchKiroQuota(
|
|
146
159
|
credential: string,
|
|
147
|
-
fetcher:
|
|
160
|
+
fetcher: KiroFetchLike,
|
|
148
161
|
context?: QuotaCollectionContext,
|
|
149
162
|
): Promise<ProviderQuotaResult> {
|
|
150
163
|
const token = credential.trim();
|
|
@@ -156,43 +169,18 @@ export async function fetchKiroQuota(
|
|
|
156
169
|
origin: "AI_EDITOR",
|
|
157
170
|
resourceType: "AGENTIC_REQUEST",
|
|
158
171
|
});
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
172
|
+
// The 1.4.62 client sends the profile in the query (`GetUsageLimitsCommand`
|
|
173
|
+
// with `{origin, profileArn, resourceType, isEmailRequired}`). Without it the
|
|
174
|
+
// upstream answers 400 `Invalid profileArn.` — and there is no POST surface;
|
|
175
|
+
// the legacy `codewhisperer.*`/`q.*` AWS usage paths are gone.
|
|
176
|
+
if (auth.profileArn.length > 0) query.set("profileArn", auth.profileArn);
|
|
164
177
|
|
|
165
|
-
|
|
166
|
-
// travels in the POST body only: the GET form rejects it in the query with
|
|
167
|
-
// `400`, which is what a freshly imported account was failing its test on.
|
|
178
|
+
const managementHost = KIRO_MANAGEMENT_HOST_TEMPLATE.replace("{region}", auth.region);
|
|
168
179
|
const attempts: readonly { readonly name: string; readonly run: () => Promise<Response> }[] = [
|
|
169
180
|
{
|
|
170
|
-
name: "
|
|
171
|
-
run: () =>
|
|
172
|
-
fetcher(`https://codewhisperer.us-east-1.amazonaws.com/getUsageLimits?${query.toString()}`, {
|
|
173
|
-
method: "GET",
|
|
174
|
-
headers,
|
|
175
|
-
signal: AbortSignal.timeout(15_000),
|
|
176
|
-
}),
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
name: "codewhisperer-post",
|
|
180
|
-
run: () =>
|
|
181
|
-
fetcher("https://codewhisperer.us-east-1.amazonaws.com", {
|
|
182
|
-
method: "POST",
|
|
183
|
-
headers: {
|
|
184
|
-
...headers,
|
|
185
|
-
"content-type": "application/x-amz-json-1.0",
|
|
186
|
-
"x-amz-target": "AmazonCodeWhispererService.GetUsageLimits",
|
|
187
|
-
},
|
|
188
|
-
body: usageBody,
|
|
189
|
-
signal: AbortSignal.timeout(15_000),
|
|
190
|
-
}),
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
name: "q-get",
|
|
181
|
+
name: "management-get",
|
|
194
182
|
run: () =>
|
|
195
|
-
fetcher(
|
|
183
|
+
fetcher(`${managementHost}/Get-Usage-Limits?${query.toString()}`, {
|
|
196
184
|
method: "GET",
|
|
197
185
|
headers,
|
|
198
186
|
signal: AbortSignal.timeout(15_000),
|
|
@@ -55,15 +55,10 @@ interface KiroToolSpecification {
|
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
/** The checkpoint the upstream keys its prompt cache on. */
|
|
59
|
-
interface KiroCachePoint {
|
|
60
|
-
readonly cachePoint: { readonly type: "default" };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
58
|
/** One entry of `currentMessage.userInputMessage.userInputMessageContext`. */
|
|
64
59
|
interface KiroUserInputContext {
|
|
65
60
|
readonly toolResults?: readonly KiroToolResult[];
|
|
66
|
-
readonly tools?: readonly
|
|
61
|
+
readonly tools?: readonly KiroToolSpecification[];
|
|
67
62
|
}
|
|
68
63
|
|
|
69
64
|
interface KiroToolResult {
|
|
@@ -111,6 +106,8 @@ export interface KiroConversationError {
|
|
|
111
106
|
/** Options the adapter supplies that are not part of the canonical request. */
|
|
112
107
|
export interface KiroWireRequestOptions {
|
|
113
108
|
readonly conversationId: string;
|
|
109
|
+
/** Root conversation id; defaults to `conversationId`, mirroring the client's `rootConversationId ?? conversationId`. */
|
|
110
|
+
readonly rootConversationId?: string | undefined;
|
|
114
111
|
readonly modelId: string;
|
|
115
112
|
readonly profileArn: string;
|
|
116
113
|
/** Reasoning effort the routed model advertises, already validated by the adapter. */
|
|
@@ -176,6 +173,10 @@ export function buildKiroWireRequest(
|
|
|
176
173
|
agentContinuationId: randomUUID(),
|
|
177
174
|
chatTriggerType: "MANUAL",
|
|
178
175
|
conversationId: options.conversationId,
|
|
176
|
+
// The client always sends the root conversation id, defaulting to the
|
|
177
|
+
// conversation id when the conversation is self-rooted (1.4.62 bundle:
|
|
178
|
+
// `rootConversationId: A ?? S`).
|
|
179
|
+
rootConversationId: options.rootConversationId ?? options.conversationId,
|
|
179
180
|
currentMessage: { userInputMessage: currentMessage },
|
|
180
181
|
history,
|
|
181
182
|
},
|
|
@@ -197,8 +198,7 @@ export function buildKiroWireRequest(
|
|
|
197
198
|
* This text is deliberately the *only* thing the opening turn carries besides
|
|
198
199
|
* the caller's own words, because it is the prefix the upstream caches: every
|
|
199
200
|
* request in a conversation repeats it byte-for-byte on that same turn. A value
|
|
200
|
-
* that changes per request belongs on the current turn instead
|
|
201
|
-
* `buildCurrentTimeLine`.
|
|
201
|
+
* that changes per request belongs on the current turn instead.
|
|
202
202
|
*/
|
|
203
203
|
function buildStablePrefix(request: CanonicalRequest, options: KiroWireRequestOptions): string {
|
|
204
204
|
const parts: string[] = [];
|
|
@@ -221,9 +221,6 @@ function buildStablePrefix(request: CanonicalRequest, options: KiroWireRequestOp
|
|
|
221
221
|
* prefix differ on every request, so the upstream could never reuse the cached
|
|
222
222
|
* one and the whole conversation would be re-read each turn.
|
|
223
223
|
*/
|
|
224
|
-
export function buildCurrentTimeLine(now: Date = new Date()): string {
|
|
225
|
-
return `[Context: Current time is ${now.toISOString()}]`;
|
|
226
|
-
}
|
|
227
224
|
|
|
228
225
|
/** The marker the upstream reads to enable thinking with a budget. */
|
|
229
226
|
export function buildThinkingMarker(budget: number): string {
|
|
@@ -132,6 +132,10 @@ export class KiroStreamDecoder {
|
|
|
132
132
|
|
|
133
133
|
const eventType = event.headers[":event-type"] ?? "";
|
|
134
134
|
switch (eventType) {
|
|
135
|
+
// First frame of a stream; carries only an empty conversation id. Nothing
|
|
136
|
+
// to emit (observed live 2026-11-02: `{"conversationId":""}`).
|
|
137
|
+
case "initial-response":
|
|
138
|
+
return { deltas: [] };
|
|
135
139
|
case "assistantResponseEvent":
|
|
136
140
|
return { deltas: this.#textDeltas(readString(event.payload, "content")) };
|
|
137
141
|
case "reasoningContentEvent":
|
|
@@ -303,6 +307,13 @@ function readString(payload: string | null, key: string): string {
|
|
|
303
307
|
*
|
|
304
308
|
* The upstream has sent this payload as a bare string, as `{text}`, and as
|
|
305
309
|
* `{content}` across versions; all three are accepted rather than picking one.
|
|
310
|
+
*
|
|
311
|
+
* One shape must NOT be read as text: `{redactedContent:"…"}`. That is an
|
|
312
|
+
* encrypted envelope (observed live 2026-11-02: base64 → `.KTR~~<base64url-
|
|
313
|
+
* JSON>` → `{"encryptionRegion":null,"mintedAtMs":…,"modelHash":"…","slots":
|
|
314
|
+
* [],"v":1}`) whose content the upstream never exposes. Emitting it as
|
|
315
|
+
* reasoning would leak a blob that is not reasoning, so it is treated as no
|
|
316
|
+
* text at all.
|
|
306
317
|
*/
|
|
307
318
|
function readReasoning(payload: string | null): string {
|
|
308
319
|
const parsed = parsePayload(payload);
|
|
@@ -311,6 +322,8 @@ function readReasoning(payload: string | null): string {
|
|
|
311
322
|
if (typeof value === "string") return value;
|
|
312
323
|
if (value !== null && typeof value === "object") {
|
|
313
324
|
const record = value as Record<string, unknown>;
|
|
325
|
+
// Redacted envelope: not reasoning text; never surface it.
|
|
326
|
+
if (typeof record.redactedContent === "string") return "";
|
|
314
327
|
if (typeof record.text === "string") return record.text;
|
|
315
328
|
if (typeof record.content === "string") return record.content;
|
|
316
329
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Kiro (CodeWhisperer) adapter.
|
|
1
|
+
// Kiro (CodeWhisperer / Kiro Runtime) adapter.
|
|
2
2
|
//
|
|
3
3
|
// Kiro does not speak a chat-shaped protocol: a request is a `conversationState`
|
|
4
4
|
// ledger, and the answer is an AWS EventStream binary frame sequence. The
|
|
@@ -7,19 +7,21 @@
|
|
|
7
7
|
//
|
|
8
8
|
// Two upstream behaviours drive the header and endpoint logic:
|
|
9
9
|
//
|
|
10
|
-
// * There is exactly one generation surface, `
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
10
|
+
// * There is exactly one generation surface, `https://runtime.{region}.kiro.dev`
|
|
11
|
+
// (the Kiro runtime service). The legacy `q.{region}.amazonaws.com` /
|
|
12
|
+
// `codewhisperer.*` AWS hosts are what older Kiro builds used; the 1.4.62
|
|
13
|
+
// IDE ships `KiroRuntimeService` clients against the runtime host, and
|
|
14
|
+
// reaching for the legacy hosts is actively harmful: an account that has
|
|
15
|
+
// just been refused would immediately probe other service entries with the
|
|
16
|
+
// same token, which is the shape of credential probing rather than of a
|
|
17
|
+
// client retrying. A refusal is reported, never replayed onto another host.
|
|
17
18
|
// * Every request carries a device identity (`KiroIDE-{version}-{machineId}`
|
|
18
|
-
// in the User-Agent
|
|
19
|
-
// accounts lets one TCP session carry
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
// constant or a per-request
|
|
19
|
+
// in the User-Agent and `x-kiro-machineid` as a header) and closes its
|
|
20
|
+
// connection. A connection reused across accounts lets one TCP session carry
|
|
21
|
+
// several tokens that each claim to be a different machine — the strongest
|
|
22
|
+
// possible evidence of sharing. An account whose machine id cannot be
|
|
23
|
+
// derived is refused rather than dispatched with a constant or a per-request
|
|
24
|
+
// random value.
|
|
23
25
|
//
|
|
24
26
|
// The profile ARN is never manufactured: an account that resolved none sends
|
|
25
27
|
// none. The shared placeholder belongs to the vendor's own account and the
|
|
@@ -27,6 +29,7 @@
|
|
|
27
29
|
|
|
28
30
|
import type {
|
|
29
31
|
CanonicalEvent,
|
|
32
|
+
CanonicalMessage,
|
|
30
33
|
CanonicalRequest,
|
|
31
34
|
CanonicalStopReason,
|
|
32
35
|
UsageRecord,
|
|
@@ -48,9 +51,17 @@ import {
|
|
|
48
51
|
type KiroWireRequest,
|
|
49
52
|
} from "./kiro-request";
|
|
50
53
|
import { machineIdForAuthState } from "./kiro-machine-id";
|
|
54
|
+
import { estimateKiroSessionCache } from "./kiro-cache";
|
|
55
|
+
import { applyCacheMode } from "../../provider-usage";
|
|
51
56
|
import { resolveKiroProfileArn } from "./kiro-profile";
|
|
52
|
-
import {
|
|
53
|
-
|
|
57
|
+
import {
|
|
58
|
+
AWS_REGION_PATTERN,
|
|
59
|
+
KIRO_DEFAULT_REGION,
|
|
60
|
+
kiroContextWindow,
|
|
61
|
+
KIRO_GENERATE_PATH,
|
|
62
|
+
KIRO_RUNTIME_HOST_TEMPLATE,
|
|
63
|
+
} from "./kiro-catalog";
|
|
64
|
+
import { resolveInboundSessionId } from "../../operations/session-resolution";
|
|
54
65
|
import { KiroStreamDecoder, isKiroTruncationReason, type KiroUsage } from "./kiro-stream";
|
|
55
66
|
|
|
56
67
|
/** Provider id this adapter registers under. */
|
|
@@ -70,9 +81,6 @@ interface KiroAuthState {
|
|
|
70
81
|
readonly machineId?: string;
|
|
71
82
|
}
|
|
72
83
|
|
|
73
|
-
/** AWS region shape, checked before a region is interpolated into a URL. */
|
|
74
|
-
const AWS_REGION_PATTERN = /^[a-z]{2}-[a-z]+-\d{1,2}$/;
|
|
75
|
-
|
|
76
84
|
interface KiroAdapterOptions {
|
|
77
85
|
readonly fetch?: typeof fetch;
|
|
78
86
|
}
|
|
@@ -83,7 +91,7 @@ function readAuthState(context: ProviderDispatchContext): KiroAuthState | undefi
|
|
|
83
91
|
if (raw === undefined) return undefined;
|
|
84
92
|
const authMethod = typeof raw["authMethod"] === "string" ? raw["authMethod"] : undefined;
|
|
85
93
|
if (authMethod === undefined) return undefined;
|
|
86
|
-
const region = typeof raw["region"] === "string" && raw["region"].trim().length > 0 ? raw["region"].trim() :
|
|
94
|
+
const region = typeof raw["region"] === "string" && raw["region"].trim().length > 0 ? raw["region"].trim() : KIRO_DEFAULT_REGION;
|
|
87
95
|
const profileArn = typeof raw["profileArn"] === "string" && raw["profileArn"].trim().length > 0 ? raw["profileArn"].trim() : undefined;
|
|
88
96
|
const machineId = typeof raw["machineId"] === "string" && raw["machineId"].trim().length > 0 ? raw["machineId"].trim() : undefined;
|
|
89
97
|
return {
|
|
@@ -121,35 +129,6 @@ function resolveKiroConversationId(
|
|
|
121
129
|
);
|
|
122
130
|
}
|
|
123
131
|
|
|
124
|
-
/**
|
|
125
|
-
* The field the upstream keys its prompt cache on.
|
|
126
|
-
*
|
|
127
|
-
* A stable `conversationId` is not enough: the upstream ignores `cache_control`
|
|
128
|
-
* entirely unless `metadata.user_id` is present, and then recomputes the whole
|
|
129
|
-
* prompt on every turn. The value follows the shape the real client sends, and
|
|
130
|
-
* its session id is the same one the conversation already uses, so turns of one
|
|
131
|
-
* conversation hit and a different conversation does not.
|
|
132
|
-
*/
|
|
133
|
-
function withKiroCacheKey(
|
|
134
|
-
payload: Record<string, unknown>,
|
|
135
|
-
request: CanonicalRequest,
|
|
136
|
-
context: ProviderDispatchContext,
|
|
137
|
-
): Record<string, unknown> {
|
|
138
|
-
const existing = (payload.metadata as { user_id?: unknown } | undefined)?.user_id;
|
|
139
|
-
if (typeof existing === "string" && existing.length > 0) return payload;
|
|
140
|
-
const sessionId = resolvePromptCacheKey(request, context) ?? resolveKiroConversationId(request, context);
|
|
141
|
-
return {
|
|
142
|
-
...payload,
|
|
143
|
-
metadata: {
|
|
144
|
-
user_id: JSON.stringify({
|
|
145
|
-
device_id: resolveAccountMachineId(context),
|
|
146
|
-
account_uuid: "",
|
|
147
|
-
session_id: sessionId,
|
|
148
|
-
}),
|
|
149
|
-
},
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
|
|
153
132
|
/**
|
|
154
133
|
* The profile ARN this request carries, or `""` when it carries none.
|
|
155
134
|
*
|
|
@@ -180,8 +159,8 @@ function resolveAccountMachineId(context: ProviderDispatchContext): string {
|
|
|
180
159
|
|
|
181
160
|
/** Region validated before interpolation into an endpoint URL. */
|
|
182
161
|
function safeRegion(authState: KiroAuthState | undefined): string {
|
|
183
|
-
const region = authState?.region ??
|
|
184
|
-
return AWS_REGION_PATTERN.test(region) ? region :
|
|
162
|
+
const region = authState?.region ?? KIRO_DEFAULT_REGION;
|
|
163
|
+
return AWS_REGION_PATTERN.test(region) ? region : KIRO_DEFAULT_REGION;
|
|
185
164
|
}
|
|
186
165
|
|
|
187
166
|
/**
|
|
@@ -191,9 +170,30 @@ function safeRegion(authState: KiroAuthState | undefined): string {
|
|
|
191
170
|
* replayed onto another service entry.
|
|
192
171
|
*/
|
|
193
172
|
export function kiroEndpoint(authState: KiroAuthState | undefined): string {
|
|
194
|
-
|
|
173
|
+
const host = KIRO_RUNTIME_HOST_TEMPLATE.replace("{region}", safeRegion(authState));
|
|
174
|
+
return `${host}${KIRO_GENERATE_PATH}`;
|
|
195
175
|
}
|
|
196
176
|
|
|
177
|
+
/**
|
|
178
|
+
* AWS JSON 1.0 target for the runtime generation operation. The service name
|
|
179
|
+
* and operation are what the 1.4.62 client sends in `x-amz-target` (it is a
|
|
180
|
+
* Smithy `awsJson1_0` client with serviceTarget `KiroRuntimeService`).
|
|
181
|
+
*/
|
|
182
|
+
export const KIRO_RUNTIME_AWS_JSON_TARGET = "KiroRuntimeService.GenerateAssistantResponse" as const;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Maps an auth method onto the `TokenType` header the 1.4.62 client sends.
|
|
186
|
+
*
|
|
187
|
+
* Observed map (`qje`): `api_key → API_KEY`, `external_idp → EXTERNAL_IDP`,
|
|
188
|
+
* `idc → SSO_OIDC`, `machine_token → KIRO_MACHINE_TOKEN`. Google/GitHub/
|
|
189
|
+
* Builder-ID sessions send no `TokenType` header.
|
|
190
|
+
*/
|
|
191
|
+
const KIRO_TOKEN_TYPE: Readonly<Record<string, string>> = {
|
|
192
|
+
api_key: "API_KEY",
|
|
193
|
+
external_idp: "EXTERNAL_IDP",
|
|
194
|
+
idc: "SSO_OIDC",
|
|
195
|
+
};
|
|
196
|
+
|
|
197
197
|
/**
|
|
198
198
|
* Builds the request headers.
|
|
199
199
|
*
|
|
@@ -206,37 +206,37 @@ export function kiroEndpoint(authState: KiroAuthState | undefined): string {
|
|
|
206
206
|
* * `x-amzn-codewhisperer-optout` — the observed client opts out of data
|
|
207
207
|
* collection on every generation request.
|
|
208
208
|
* * `x-amzn-kiro-agent-mode` — the agent mode the observed client declares.
|
|
209
|
-
* * `
|
|
210
|
-
*
|
|
209
|
+
* * `TokenType` — an API key or enterprise token is labelled so the upstream
|
|
210
|
+
* can tell it apart from an OAuth access token.
|
|
211
211
|
*/
|
|
212
212
|
export function kiroHeaders(
|
|
213
213
|
secret: string,
|
|
214
214
|
authState: KiroAuthState | undefined,
|
|
215
215
|
machineId: string,
|
|
216
|
+
agentMode: string,
|
|
216
217
|
): Record<string, string> {
|
|
217
218
|
const authMethod = authState?.authMethod;
|
|
218
219
|
const version = getKiroVersion();
|
|
219
220
|
const headers: Record<string, string> = {
|
|
220
|
-
"content-type": "application/json",
|
|
221
|
+
"content-type": "application/x-amz-json-1.0",
|
|
221
222
|
accept: KIRO_STREAM_ACCEPT,
|
|
222
223
|
connection: "close",
|
|
224
|
+
"x-amz-target": KIRO_RUNTIME_AWS_JSON_TARGET,
|
|
223
225
|
"x-amzn-codewhisperer-optout": "true",
|
|
224
|
-
"x-amzn-kiro-agent-mode":
|
|
226
|
+
"x-amzn-kiro-agent-mode": agentMode,
|
|
227
|
+
"x-kiro-machineid": machineId,
|
|
225
228
|
"amz-sdk-request": "attempt=1; max=3",
|
|
226
229
|
"amz-sdk-invocation-id": crypto.randomUUID(),
|
|
227
230
|
"user-agent": buildKiroUserAgent(version, machineId),
|
|
228
231
|
"x-amz-user-agent": buildKiroAmzUserAgent(version, machineId),
|
|
229
232
|
authorization: `Bearer ${secret}`,
|
|
230
233
|
};
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
headers["tokentype"] = "EXTERNAL_IDP";
|
|
235
|
-
} else {
|
|
236
|
-
headers["x-amz-sso-bearer"] = secret;
|
|
234
|
+
const tokenType = authMethod === undefined ? undefined : KIRO_TOKEN_TYPE[authMethod];
|
|
235
|
+
if (tokenType !== undefined) {
|
|
236
|
+
headers["TokenType"] = tokenType;
|
|
237
237
|
}
|
|
238
238
|
if (authState?.profileArn !== undefined && authState.profileArn.length > 0) {
|
|
239
|
-
headers["x-amzn-
|
|
239
|
+
headers["x-amzn-kiro-profile-arn"] = authState.profileArn;
|
|
240
240
|
}
|
|
241
241
|
return headers;
|
|
242
242
|
}
|
|
@@ -257,11 +257,17 @@ export function kiroHeaders(
|
|
|
257
257
|
* estimate: the upstream never says how long its own answer was, so the emitted
|
|
258
258
|
* text is counted at the usual ~4 characters per token.
|
|
259
259
|
*/
|
|
260
|
-
function kiroUsage(
|
|
260
|
+
function kiroUsage(
|
|
261
|
+
usage: KiroUsage,
|
|
262
|
+
modelId: string,
|
|
263
|
+
outputText: string,
|
|
264
|
+
messages?: readonly CanonicalMessage[],
|
|
265
|
+
sessionId?: string,
|
|
266
|
+
): UsageRecord {
|
|
261
267
|
const cacheRead = usage.cacheReadTokens ?? 0;
|
|
262
268
|
const cacheWrite = usage.cacheWriteTokens ?? 0;
|
|
263
269
|
const [input, output] = kiroTokenCounts(usage, modelId, outputText);
|
|
264
|
-
|
|
270
|
+
const record: UsageRecord = {
|
|
265
271
|
input_tokens: input,
|
|
266
272
|
cached_input_tokens: cacheRead > 0 ? cacheRead : "unavailable",
|
|
267
273
|
cache_write_tokens: cacheWrite > 0 ? cacheWrite : "unavailable",
|
|
@@ -275,6 +281,10 @@ function kiroUsage(usage: KiroUsage, modelId: string, outputText: string): Usage
|
|
|
275
281
|
total_tokens: input + output,
|
|
276
282
|
...(usage.credits === undefined ? {} : { credit_used: usage.credits }),
|
|
277
283
|
};
|
|
284
|
+
// The runtime never reports cache hits; close the gap with our own history.
|
|
285
|
+
// A genuine ( >0) report conserves the complete record. Then the operator's
|
|
286
|
+
// cache mode decides whether a hit makes the whole input count as cached.
|
|
287
|
+
return applyCacheMode(estimateKiroSessionCache(record, sessionId, messages));
|
|
278
288
|
}
|
|
279
289
|
|
|
280
290
|
/**
|
|
@@ -344,7 +354,7 @@ class KiroAdapter implements ProviderAdapter {
|
|
|
344
354
|
? new TextDecoder().decode(context.credential.secret).trim()
|
|
345
355
|
: "";
|
|
346
356
|
if (secret.length === 0) {
|
|
347
|
-
throw new GatewayError("authentication_failed", 401, "Missing Kiro credential", {
|
|
357
|
+
throw new GatewayError("authentication_failed", 401, "Missing Kiro credential (request {requestId}). Wrong key, right door — check the credential 🔑", {
|
|
348
358
|
providerId: KIRO_PROVIDER_ID,
|
|
349
359
|
});
|
|
350
360
|
}
|
|
@@ -370,6 +380,7 @@ class KiroAdapter implements ProviderAdapter {
|
|
|
370
380
|
: (request.reasoning?.budget_tokens ?? kiroThinkingBudgetForEffort(requestedEffort));
|
|
371
381
|
const built = buildKiroWireRequest(request, {
|
|
372
382
|
conversationId: resolveKiroConversationId(request, context),
|
|
383
|
+
rootConversationId: resolveKiroConversationId(request, context),
|
|
373
384
|
modelId,
|
|
374
385
|
profileArn: resolveProfileArn(context),
|
|
375
386
|
...(effortPath === undefined || effort === undefined ? {} : { effortPath, effort }),
|
|
@@ -381,12 +392,13 @@ class KiroAdapter implements ProviderAdapter {
|
|
|
381
392
|
throw new GatewayError(
|
|
382
393
|
"invalid_request",
|
|
383
394
|
400,
|
|
384
|
-
"Kiro cannot accept this conversation",
|
|
395
|
+
"Kiro cannot accept this conversation (request {requestId}). Check the shape of what you sent — then resend 🪞",
|
|
385
396
|
{ providerId: KIRO_PROVIDER_ID, problems: built.error.problems },
|
|
386
397
|
);
|
|
387
398
|
}
|
|
388
399
|
const fetchFn = (context.outbound_fetch as unknown as typeof fetch | undefined) ?? this.#fetch;
|
|
389
|
-
const
|
|
400
|
+
const builtPayload = { ...built.value.payload, agentMode: "vibe" };
|
|
401
|
+
const body = JSON.stringify(builtPayload);
|
|
390
402
|
const machineId = resolveAccountMachineId(context);
|
|
391
403
|
const response = await this.#send(
|
|
392
404
|
fetchFn,
|
|
@@ -398,12 +410,12 @@ class KiroAdapter implements ProviderAdapter {
|
|
|
398
410
|
machineId,
|
|
399
411
|
);
|
|
400
412
|
if (!response.body) {
|
|
401
|
-
throw new GatewayError("platform_unavailable", 502, "Kiro returned an empty body", {
|
|
413
|
+
throw new GatewayError("platform_unavailable", 502, "Kiro returned an empty body (request {requestId}). The upstream came back empty-handed — retry 🌙", {
|
|
402
414
|
providerId: KIRO_PROVIDER_ID,
|
|
403
415
|
}, "upstream");
|
|
404
416
|
}
|
|
405
417
|
|
|
406
|
-
yield* this.#stream(response.body, built.value, request);
|
|
418
|
+
yield* this.#stream(response.body, built.value, request, context);
|
|
407
419
|
}
|
|
408
420
|
|
|
409
421
|
/**
|
|
@@ -427,20 +439,20 @@ class KiroAdapter implements ProviderAdapter {
|
|
|
427
439
|
try {
|
|
428
440
|
response = await fetchFn(url, {
|
|
429
441
|
method: "POST",
|
|
430
|
-
headers: kiroHeaders(secret, authState, machineId),
|
|
442
|
+
headers: kiroHeaders(secret, authState, machineId, "vibe"),
|
|
431
443
|
body,
|
|
432
444
|
signal: context.abort_signal,
|
|
433
445
|
});
|
|
434
446
|
} catch (error) {
|
|
435
447
|
if (error instanceof Error && error.name === "AbortError") {
|
|
436
|
-
throw new GatewayError("transport_closed", 499, "request was cancelled", {
|
|
448
|
+
throw new GatewayError("transport_closed", 499, "The request was cancelled (request {requestId}). Send it again whenever ready 🙃", {
|
|
437
449
|
providerId: KIRO_PROVIDER_ID,
|
|
438
450
|
});
|
|
439
451
|
}
|
|
440
452
|
throw new GatewayError(
|
|
441
453
|
"transport_unavailable",
|
|
442
454
|
502,
|
|
443
|
-
`Kiro transport failed: ${error instanceof Error ? error.message : String(error)}
|
|
455
|
+
`Kiro transport failed (request {requestId}): ${error instanceof Error ? error.message : String(error)}. The connection ghosted us — come back in a moment 👻`,
|
|
444
456
|
{ providerId: KIRO_PROVIDER_ID },
|
|
445
457
|
"network",
|
|
446
458
|
);
|
|
@@ -460,6 +472,7 @@ class KiroAdapter implements ProviderAdapter {
|
|
|
460
472
|
stream: ReadableStream<Uint8Array>,
|
|
461
473
|
built: KiroWireRequest,
|
|
462
474
|
request: CanonicalRequest,
|
|
475
|
+
context: ProviderDispatchContext,
|
|
463
476
|
): AsyncIterable<CanonicalEvent> {
|
|
464
477
|
const decoder = new KiroStreamDecoder();
|
|
465
478
|
const reader = stream.getReader();
|
|
@@ -484,7 +497,7 @@ class KiroAdapter implements ProviderAdapter {
|
|
|
484
497
|
throw new GatewayError(
|
|
485
498
|
"platform_unavailable",
|
|
486
499
|
502,
|
|
487
|
-
"Kiro EventStream exceeded the buffer bound",
|
|
500
|
+
"Kiro EventStream exceeded the buffer bound (request {requestId}). The upstream sent more than we can hold — retry 🌙",
|
|
488
501
|
{ providerId: KIRO_PROVIDER_ID },
|
|
489
502
|
"upstream",
|
|
490
503
|
);
|
|
@@ -497,7 +510,7 @@ class KiroAdapter implements ProviderAdapter {
|
|
|
497
510
|
throw new GatewayError(
|
|
498
511
|
"platform_unavailable",
|
|
499
512
|
502,
|
|
500
|
-
`Kiro EventStream is corrupt: ${decoded.failure.detail}
|
|
513
|
+
`Kiro EventStream is corrupt: ${decoded.failure.detail} (request {requestId}). The upstream sent something we can't read — retry 🌙`,
|
|
501
514
|
{ providerId: KIRO_PROVIDER_ID, reason: decoded.failure.reason },
|
|
502
515
|
"upstream",
|
|
503
516
|
);
|
|
@@ -506,7 +519,7 @@ class KiroAdapter implements ProviderAdapter {
|
|
|
506
519
|
for (const message of decoded.messages) {
|
|
507
520
|
const outcome = decoder.decode(message);
|
|
508
521
|
if (outcome.failure !== undefined) {
|
|
509
|
-
throw new GatewayError("platform_unavailable", 502, outcome.failure.message
|
|
522
|
+
throw new GatewayError("platform_unavailable", 502, `${outcome.failure.message} (request {requestId}). The upstream came back empty-handed — retry 🌙`, {
|
|
510
523
|
providerId: KIRO_PROVIDER_ID,
|
|
511
524
|
}, "upstream");
|
|
512
525
|
}
|
|
@@ -578,14 +591,14 @@ class KiroAdapter implements ProviderAdapter {
|
|
|
578
591
|
await reader.cancel().catch(() => undefined);
|
|
579
592
|
if (error instanceof GatewayError) throw error;
|
|
580
593
|
if (error instanceof Error && error.name === "AbortError") {
|
|
581
|
-
throw new GatewayError("transport_closed", 499, "request was cancelled", {
|
|
594
|
+
throw new GatewayError("transport_closed", 499, "The request was cancelled (request {requestId}). Send it again whenever ready 🙃", {
|
|
582
595
|
providerId: KIRO_PROVIDER_ID,
|
|
583
596
|
});
|
|
584
597
|
}
|
|
585
598
|
throw new GatewayError(
|
|
586
599
|
"platform_unavailable",
|
|
587
600
|
502,
|
|
588
|
-
`Kiro stream failed: ${error instanceof Error ? error.message : String(error)}
|
|
601
|
+
`Kiro stream failed (request {requestId}): ${error instanceof Error ? error.message : String(error)}. The upstream came back empty-handed — retry 🌙`,
|
|
589
602
|
{ providerId: KIRO_PROVIDER_ID },
|
|
590
603
|
"upstream",
|
|
591
604
|
);
|
|
@@ -593,7 +606,7 @@ class KiroAdapter implements ProviderAdapter {
|
|
|
593
606
|
reader.releaseLock();
|
|
594
607
|
}
|
|
595
608
|
|
|
596
|
-
const finalUsage = kiroUsage(usage, request.model, outputText);
|
|
609
|
+
const finalUsage = kiroUsage(usage, request.model, outputText, request.messages, resolveKiroConversationId(request, context));
|
|
597
610
|
yield {
|
|
598
611
|
type: "usage",
|
|
599
612
|
sequence_number: sequence++,
|
|
@@ -10,8 +10,6 @@ import {
|
|
|
10
10
|
} from "./muse-oauth";
|
|
11
11
|
import { parseMuseCodeCredential } from "./muse";
|
|
12
12
|
|
|
13
|
-
const SOURCE = "api.meta.ai/muse-code/key";
|
|
14
|
-
|
|
15
13
|
interface MuseSubscriptionWindow {
|
|
16
14
|
used_percent?: unknown;
|
|
17
15
|
usedPercent?: unknown;
|
|
@@ -132,5 +130,3 @@ export async function fetchMuseQuota(
|
|
|
132
130
|
error: null,
|
|
133
131
|
};
|
|
134
132
|
}
|
|
135
|
-
|
|
136
|
-
export { SOURCE as MUSE_QUOTA_SOURCE };
|