cartethyia 2.7.4 → 2.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (595) hide show
  1. package/.env.example +5 -0
  2. package/README.md +18 -6
  3. package/dist/dashboard/assets/BannedPage-B1N603cM.js +1 -0
  4. package/dist/dashboard/assets/BannedPage-B1N603cM.js.gz +0 -0
  5. package/dist/dashboard/assets/CliToolDetailPage-9q4_4NoK.js +3 -0
  6. package/dist/dashboard/assets/CliToolDetailPage-9q4_4NoK.js.gz +0 -0
  7. package/dist/dashboard/assets/CliToolsPage-DwshGtK-.js +1 -0
  8. package/dist/dashboard/assets/CliToolsPage-DwshGtK-.js.gz +0 -0
  9. package/dist/dashboard/assets/CombosPage-D762MIkp.js +1 -0
  10. package/dist/dashboard/assets/CombosPage-D762MIkp.js.gz +0 -0
  11. package/dist/dashboard/assets/ConsoleLogPage-KRYjHZsX.js +1 -0
  12. package/dist/dashboard/assets/ConsoleLogPage-KRYjHZsX.js.gz +0 -0
  13. package/dist/dashboard/assets/CustomizationPage-DXsxk5uM.js +1 -0
  14. package/dist/dashboard/assets/CustomizationPage-DXsxk5uM.js.gz +0 -0
  15. package/dist/dashboard/assets/HealthEventsModal-BEjAjD4F.js +1 -0
  16. package/dist/dashboard/assets/HealthEventsModal-BEjAjD4F.js.gz +0 -0
  17. package/dist/dashboard/assets/InjectSystemPromptPanel-d5v3K_Yc.js +899 -0
  18. package/dist/dashboard/assets/InjectSystemPromptPanel-d5v3K_Yc.js.gz +0 -0
  19. package/dist/dashboard/assets/LoginPage-Ccv4tjNS.js +1 -0
  20. package/dist/dashboard/assets/LoginPage-Ccv4tjNS.js.gz +0 -0
  21. package/dist/dashboard/assets/{ModelPicker-BMS2t8BA.js → ModelPicker-C6WlpU5E.js} +1 -1
  22. package/dist/dashboard/assets/ModelPicker-C6WlpU5E.js.gz +0 -0
  23. package/dist/dashboard/assets/OverviewPage-DN9fYNWA.js +1 -0
  24. package/dist/dashboard/assets/OverviewPage-DN9fYNWA.js.gz +0 -0
  25. package/dist/dashboard/assets/ProviderDetailPage-BY0ieUgz.js +5 -0
  26. package/dist/dashboard/assets/ProviderDetailPage-BY0ieUgz.js.gz +0 -0
  27. package/dist/dashboard/assets/ProviderIcon-jjqXJDA3.js +1 -0
  28. package/dist/dashboard/assets/ProviderIcon-jjqXJDA3.js.gz +0 -0
  29. package/dist/dashboard/assets/ProvidersPage-DNsbfea2.js +1 -0
  30. package/dist/dashboard/assets/ProvidersPage-DNsbfea2.js.gz +0 -0
  31. package/dist/dashboard/assets/{ProxyPage-lsrx7NYg.js → ProxyPage-DxjvUzSD.js} +1 -1
  32. package/dist/dashboard/assets/ProxyPage-DxjvUzSD.js.gz +0 -0
  33. package/dist/dashboard/assets/QuotaPage-OaHScjpX.js +1 -0
  34. package/dist/dashboard/assets/QuotaPage-OaHScjpX.js.gz +0 -0
  35. package/dist/dashboard/assets/SettingsPage-BW4AKj2H.js +1 -0
  36. package/dist/dashboard/assets/SettingsPage-BW4AKj2H.js.gz +0 -0
  37. package/dist/dashboard/assets/SetupPage-44BZrxFC.js +1 -0
  38. package/dist/dashboard/assets/SetupPage-44BZrxFC.js.gz +0 -0
  39. package/dist/dashboard/assets/{StudioPage-Cq5tW7hW.js → StudioPage-DRPavCdU.js} +4 -4
  40. package/dist/dashboard/assets/StudioPage-DRPavCdU.js.gz +0 -0
  41. package/dist/dashboard/assets/ToolIcon-CfeLA-Z_.js +1 -0
  42. package/dist/dashboard/assets/ToolIcon-CfeLA-Z_.js.gz +0 -0
  43. package/dist/dashboard/assets/UsagePage-B7M7LvMM.js +56 -0
  44. package/dist/dashboard/assets/UsagePage-B7M7LvMM.js.gz +0 -0
  45. package/dist/dashboard/assets/api-keys-KvX83mRe.js +1 -0
  46. package/dist/dashboard/assets/api-keys-KvX83mRe.js.gz +0 -0
  47. package/dist/dashboard/assets/app-DRnQLhsc.js +9 -0
  48. package/dist/dashboard/assets/app-DRnQLhsc.js.gz +0 -0
  49. package/dist/dashboard/assets/app-mweRcsKp.css +2 -0
  50. package/dist/dashboard/assets/app-mweRcsKp.css.gz +0 -0
  51. package/dist/dashboard/assets/assert-CidQVoNo.js +1 -0
  52. package/dist/dashboard/assets/assert-CidQVoNo.js.gz +0 -0
  53. package/dist/dashboard/assets/{badge-D9CS6dZk.js → badge-BaX2GTrn.js} +1 -1
  54. package/dist/dashboard/assets/badge-BaX2GTrn.js.gz +0 -0
  55. package/dist/dashboard/assets/{banner-DympBNq4.js → banner-DFH4Bkte.js} +1 -1
  56. package/dist/dashboard/assets/banner-DFH4Bkte.js.gz +0 -0
  57. package/dist/dashboard/assets/brand/login_register.jpg +0 -0
  58. package/dist/dashboard/assets/brand/login_register_initial.jpg +0 -0
  59. package/dist/dashboard/assets/brand/og_bansos.jpg +0 -0
  60. package/dist/dashboard/assets/brand/og_image.jpg +0 -0
  61. package/dist/dashboard/assets/{card-ibRWU_uT.js → card-CxDw0lK6.js} +1 -1
  62. package/dist/dashboard/assets/card-CxDw0lK6.js.gz +0 -0
  63. package/dist/dashboard/assets/chevron-left-Bf6CaTSJ.js +1 -0
  64. package/dist/dashboard/assets/chevron-left-Bf6CaTSJ.js.gz +0 -0
  65. package/dist/dashboard/assets/circle-question-mark-Cz4un8sH.js +1 -0
  66. package/dist/dashboard/assets/circle-question-mark-Cz4un8sH.js.gz +0 -0
  67. package/dist/dashboard/assets/cli-tools-Bwv5-zGZ.js +1 -0
  68. package/dist/dashboard/assets/cli-tools-Bwv5-zGZ.js.gz +0 -0
  69. package/dist/dashboard/assets/{clipboard-button-DJm-9pz7.js → clipboard-button-DfS1ntiq.js} +1 -1
  70. package/dist/dashboard/assets/clipboard-button-DfS1ntiq.js.gz +0 -0
  71. package/dist/dashboard/assets/dialog-BK-NRr5u.js +1 -0
  72. package/dist/dashboard/assets/dialog-BK-NRr5u.js.gz +0 -0
  73. package/dist/dashboard/assets/{drawer-CqGYeOrd.js → drawer-QqPul6sC.js} +1 -1
  74. package/dist/dashboard/assets/drawer-QqPul6sC.js.gz +0 -0
  75. package/dist/dashboard/assets/entry-BMlYJVFj.js +1 -0
  76. package/dist/dashboard/assets/entry-BMlYJVFj.js.gz +0 -0
  77. package/dist/dashboard/assets/entry-D6WvojeD.js +4 -0
  78. package/dist/dashboard/assets/entry-D6WvojeD.js.gz +0 -0
  79. package/dist/dashboard/assets/entry-Dmx7gBiN.js +1 -0
  80. package/dist/dashboard/assets/entry-Dmx7gBiN.js.gz +0 -0
  81. package/dist/dashboard/assets/{formatters-D-MTJxMr.js → formatters-u7JPB5BX.js} +1 -1
  82. package/dist/dashboard/assets/formatters-u7JPB5BX.js.gz +0 -0
  83. package/dist/dashboard/assets/house-h9AZlJuT.js +1 -0
  84. package/dist/dashboard/assets/house-h9AZlJuT.js.gz +0 -0
  85. package/dist/dashboard/assets/{index-DBNPOfhV.js → index-Ko4dLRnV.js} +2 -2
  86. package/dist/dashboard/assets/index-Ko4dLRnV.js.gz +0 -0
  87. package/dist/dashboard/assets/{inline-BT0zntEr.js → inline-CHJQwxLa.js} +1 -1
  88. package/dist/dashboard/assets/inline-CHJQwxLa.js.gz +0 -0
  89. package/dist/dashboard/assets/{input-Da2ZViWg.js → input-BlmlizVV.js} +1 -1
  90. package/dist/dashboard/assets/input-BlmlizVV.js.gz +0 -0
  91. package/dist/dashboard/assets/{layout-BXNeLw6M.js → layout-Bz93I-yE.js} +1 -1
  92. package/dist/dashboard/assets/layout-Bz93I-yE.js.gz +0 -0
  93. package/dist/dashboard/assets/{list-row-BycOrrIV.js → list-row-Ml16KCfu.js} +1 -1
  94. package/dist/dashboard/assets/list-row-Ml16KCfu.js.gz +0 -0
  95. package/dist/dashboard/assets/live-7_QpnYGu.js +1 -0
  96. package/dist/dashboard/assets/live-7_QpnYGu.js.gz +0 -0
  97. package/dist/dashboard/assets/{mutation-Rr0TIvcj.js → mutation-GU7XdEjz.js} +1 -1
  98. package/dist/dashboard/assets/mutation-GU7XdEjz.js.gz +0 -0
  99. package/dist/dashboard/assets/network-CuMDaTzT.js +1 -0
  100. package/dist/dashboard/assets/network-CuMDaTzT.js.gz +0 -0
  101. package/dist/dashboard/assets/numbers-CoqpaDMx.js +2 -0
  102. package/dist/dashboard/assets/numbers-CoqpaDMx.js.gz +0 -0
  103. package/dist/dashboard/assets/pagination-B5aOoweZ.js +1 -0
  104. package/dist/dashboard/assets/pagination-B5aOoweZ.js.gz +0 -0
  105. package/dist/dashboard/assets/providers/zai.webp +0 -0
  106. package/dist/dashboard/assets/providers/zcode.webp +0 -0
  107. package/dist/dashboard/assets/{query-keys-BloKtaXJ.js → query-keys-YSoQOUh6.js} +1 -1
  108. package/dist/dashboard/assets/{query-keys-BloKtaXJ.js.gz → query-keys-YSoQOUh6.js.gz} +0 -0
  109. package/dist/dashboard/assets/quota-DJ1QlAOq.js +1 -0
  110. package/dist/dashboard/assets/quota-DJ1QlAOq.js.gz +0 -0
  111. package/dist/dashboard/assets/routing-fnCsxgNO.js +1 -0
  112. package/dist/dashboard/assets/routing-fnCsxgNO.js.gz +0 -0
  113. package/dist/dashboard/assets/{select-BIYIBkMU.js → select-BHqpd-bg.js} +2 -2
  114. package/dist/dashboard/assets/select-BHqpd-bg.js.gz +0 -0
  115. package/dist/dashboard/assets/settings-BxslsErn.js +1 -0
  116. package/dist/dashboard/assets/settings-BxslsErn.js.gz +0 -0
  117. package/dist/dashboard/assets/shield-BMQNxORh.js +1 -0
  118. package/dist/dashboard/assets/shield-BMQNxORh.js.gz +0 -0
  119. package/dist/dashboard/assets/{stack-DfgnFDWY.js → stack-j7cXjgYX.js} +1 -1
  120. package/dist/dashboard/assets/stack-j7cXjgYX.js.gz +0 -0
  121. package/dist/dashboard/assets/{state-CkfdYWel.js → state-DHmEnLa2.js} +1 -1
  122. package/dist/dashboard/assets/state-DHmEnLa2.js.gz +0 -0
  123. package/dist/dashboard/assets/{switch-SYm237HG.js → switch-DmZcyTIC.js} +1 -1
  124. package/dist/dashboard/assets/switch-DmZcyTIC.js.gz +0 -0
  125. package/dist/dashboard/assets/{useMutation-BQqCRNIi.js → useMutation-CbCP4w1o.js} +1 -1
  126. package/dist/dashboard/assets/useMutation-CbCP4w1o.js.gz +0 -0
  127. package/dist/dashboard/console-backgrounds.jpg +0 -0
  128. package/dist/dashboard/console-backgrounds_initial.jpg +0 -0
  129. package/dist/dashboard/index.html +2 -2
  130. package/dist/dashboard/index.html.gz +0 -0
  131. package/dist/dashboard/precompressed-assets.json +60 -59
  132. package/migrations/full-postgres/0036_system_prompt_presets_refs.sql +10 -0
  133. package/migrations/full-postgres/0037_share_concurrency_scope.sql +3 -0
  134. package/migrations/full-postgres/0038_add_accounts_quota_snapshot.sql +7 -0
  135. package/migrations/full-postgres/0039_add_telemetry_provider_model_indexes.sql +13 -0
  136. package/migrations/full-postgres/0040_add_models_dialect.sql +3 -0
  137. package/migrations/full-postgres/0041_add_daily_checkin_ledger_account_fk.sql +7 -0
  138. package/migrations/full-postgres/0042_add_telemetry_degenerate_stop.sql +14 -0
  139. package/migrations/lite-sqlite3/0036_system_prompt_presets_refs.sql +14 -0
  140. package/migrations/lite-sqlite3/0037_share_concurrency_scope.sql +3 -0
  141. package/migrations/lite-sqlite3/0038_add_accounts_quota_snapshot.sql +4 -0
  142. package/migrations/lite-sqlite3/0039_add_telemetry_provider_model_indexes.sql +6 -0
  143. package/migrations/lite-sqlite3/0040_add_models_dialect.sql +3 -0
  144. package/migrations/lite-sqlite3/0041_add_daily_checkin_ledger_account_fk.sql +26 -0
  145. package/migrations/lite-sqlite3/0042_add_telemetry_degenerate_stop.sql +12 -0
  146. package/package.json +4 -6
  147. package/scripts/cli/update.ts +15 -41
  148. package/src/boot/app.ts +58 -2
  149. package/src/boot/dependencies.ts +794 -732
  150. package/src/boot/lifecycle.ts +11 -12
  151. package/src/config/cooldowns.ts +34 -55
  152. package/src/config/network.ts +1 -1
  153. package/src/config/package-paths.ts +1 -1
  154. package/src/config/providers.ts +19 -14
  155. package/src/config/resources.ts +0 -5
  156. package/src/config/runtime.ts +2 -5
  157. package/src/config/spec.ts +33 -6
  158. package/src/config/usage.ts +27 -0
  159. package/src/console/api-keys/ban-constants.ts +38 -0
  160. package/src/console/api-keys/contracts.ts +71 -62
  161. package/src/console/api-keys/routes.ts +56 -24
  162. package/src/console/auth/access.ts +4 -4
  163. package/src/console/auth/account-reset.ts +1 -1
  164. package/src/console/auth/audit-recorder.ts +1 -1
  165. package/src/console/auth/lockout.ts +7 -3
  166. package/src/console/auth/row-coercion.ts +57 -12
  167. package/src/console/auth/session-resolver.ts +1 -1
  168. package/src/console/auth/session-service.ts +8 -2
  169. package/src/console/auth/session.ts +37 -31
  170. package/src/console/auth/setup-service.ts +4 -3
  171. package/src/console/auth/user-store.ts +1 -1
  172. package/src/console/backup/9router-map.ts +0 -3
  173. package/src/console/backup/contracts.ts +9 -9
  174. package/src/console/backup/export-endpoint.ts +5 -6
  175. package/src/console/backup/nine-router.ts +1 -7
  176. package/src/console/backup/routes.ts +29 -33
  177. package/src/console/backup/service.ts +468 -468
  178. package/src/console/backup/store.ts +47 -29
  179. package/src/console/backup/validate.ts +11 -1
  180. package/src/console/cli-tools/contracts.ts +43 -299
  181. package/src/console/cli-tools/fs-ops.ts +29 -0
  182. package/src/console/cli-tools/injectors/claude.ts +3 -3
  183. package/src/console/cli-tools/injectors/codex.ts +181 -181
  184. package/src/console/cli-tools/injectors/driver.ts +150 -247
  185. package/src/console/cli-tools/injectors/kilo.ts +146 -21
  186. package/src/console/cli-tools/injectors/opencode.ts +176 -153
  187. package/src/console/cli-tools/routes.ts +7 -1
  188. package/src/console/cli-tools/service.ts +8 -7
  189. package/src/console/cli-tools/store.ts +2 -2
  190. package/src/console/console-router.ts +32 -0
  191. package/src/console/dashboard-assets.ts +9 -9
  192. package/src/console/domain-registration.ts +16 -2
  193. package/src/console/inferhub/client.ts +0 -7
  194. package/src/console/inferhub/key-store.ts +1 -1
  195. package/src/console/inferhub/normalize.ts +2 -2
  196. package/src/console/inferhub/routes.ts +1 -1
  197. package/src/console/inferhub/types.ts +1 -1
  198. package/src/console/observability/contracts.ts +7 -1
  199. package/src/console/observability/live.ts +31 -18
  200. package/src/console/observability/logs.ts +1 -1
  201. package/src/console/observability/sse.ts +62 -8
  202. package/src/console/observability/store.ts +23 -4
  203. package/src/console/providers/catalog/catalog-projections.ts +1 -1
  204. package/src/console/providers/catalog/contracts.ts +39 -0
  205. package/src/console/providers/catalog/model-operations.ts +1 -1
  206. package/src/console/providers/catalog/provider-operations.ts +95 -17
  207. package/src/console/providers/catalog/public-model-store.ts +0 -0
  208. package/src/console/providers/catalog/routes.ts +27 -3
  209. package/src/console/providers/catalog/store.ts +147 -8
  210. package/src/console/providers/detail/routes.ts +1 -1
  211. package/src/console/providers/oauth/callback-listener.ts +100 -18
  212. package/src/console/providers/oauth/routes.ts +92 -13
  213. package/src/console/quota/account-quota-global.ts +41 -3
  214. package/src/console/quota/account-quota-shared.ts +10 -3
  215. package/src/console/quota/account-quota-tenant.ts +259 -66
  216. package/src/console/quota/daily-growth-job.ts +308 -0
  217. package/src/console/quota/native-identity.ts +2 -2
  218. package/src/console/quota/quota-view.ts +1 -1
  219. package/src/console/remote-support/routes.ts +1 -1
  220. package/src/console/remote-support/service.ts +2 -2
  221. package/src/console/routing/model/contracts.ts +1 -1
  222. package/src/console/routing/pools/contracts.ts +2 -2
  223. package/src/console/routing/pools/import-parse.ts +3 -3
  224. package/src/console/routing/pools/relay-deploy.ts +3 -3
  225. package/src/console/settings/contracts.ts +29 -2
  226. package/src/console/settings/store.ts +20 -0
  227. package/src/console/share/share-router.ts +100 -32
  228. package/src/console/share/share-stats.ts +11 -13
  229. package/src/console/share/share-usage.ts +1 -1
  230. package/src/console/shared/errors.ts +2 -2
  231. package/src/console/shared/object.ts +18 -0
  232. package/src/console/shared/read-through-cache.ts +4 -4
  233. package/src/console/shared/transaction.ts +14 -0
  234. package/src/console/system-prompt/contracts.ts +89 -12
  235. package/src/console/system-prompt/routes.ts +98 -45
  236. package/src/console/updates/apply-update.ts +244 -0
  237. package/src/console/updates/routes.ts +252 -97
  238. package/src/main.ts +11 -5
  239. package/src/network/http2-bidi.ts +1 -1
  240. package/src/network/ip-utils.ts +298 -0
  241. package/src/network/outbound-fetch.ts +1 -1
  242. package/src/network/pool/agent.ts +7 -6
  243. package/src/network/pool/byte-accounting.ts +1 -1
  244. package/src/network/pool/resolver.ts +16 -12
  245. package/src/network/pool/selector.ts +150 -136
  246. package/src/network/pool-health-machine.ts +1 -1
  247. package/src/network/rate-limit-verdict.ts +1 -1
  248. package/src/network/retry.ts +1 -1
  249. package/src/network/ssrf.ts +20 -71
  250. package/src/observability/event-log.ts +9 -2
  251. package/src/observability/event-query.ts +61 -291
  252. package/src/observability/log-sanitize.ts +1 -1
  253. package/src/observability/metrics.ts +4 -4
  254. package/src/observability/payload-capture.ts +6 -5
  255. package/src/observability/payload-store.ts +1 -1
  256. package/src/observability/runtime-metrics.ts +1 -1
  257. package/src/observability/telemetry-buffer.ts +19 -3
  258. package/src/observability/telemetry-reconciliation.ts +3 -3
  259. package/src/observability/token-speed.ts +1 -1
  260. package/src/persistence/connection-url.ts +1 -1
  261. package/src/persistence/db-handle.ts +1 -1
  262. package/src/persistence/db-pg.ts +2 -2
  263. package/src/persistence/db-sqlite.ts +3 -3
  264. package/src/persistence/dialect.ts +5 -1
  265. package/src/persistence/readiness.ts +1 -1
  266. package/src/persistence/redis.ts +1 -1
  267. package/src/persistence/schema.ts +121 -40
  268. package/src/persistence/shared-cache.ts +2 -2
  269. package/src/persistence/sort-order.ts +1 -1
  270. package/src/persistence/stores/api-key-store.ts +29 -2
  271. package/src/persistence/stores/share-store.ts +20 -8
  272. package/src/persistence/system-prompt-store.ts +63 -18
  273. package/src/persistence/tenant-preferences.ts +1 -1
  274. package/src/persistence/ttl-cache.ts +3 -3
  275. package/src/persistence/usage-flush.ts +7 -2
  276. package/src/protocol/canonical-model.ts +1 -1
  277. package/src/protocol/codecs.ts +6 -10
  278. package/src/protocol/dsml.ts +8 -125
  279. package/src/protocol/image-clamp.ts +2 -2
  280. package/src/protocol/reasoning-text.ts +1 -1
  281. package/src/protocol/reasoning.ts +7 -52
  282. package/src/protocol/registry.ts +50 -15
  283. package/src/protocol/request/chat.ts +46 -19
  284. package/src/protocol/request/codex.ts +1 -1
  285. package/src/protocol/request/messages.ts +46 -14
  286. package/src/protocol/request/responses.ts +19 -10
  287. package/src/protocol/response/chat.ts +25 -10
  288. package/src/protocol/response/codex.ts +1 -1
  289. package/src/protocol/response/messages.ts +1 -1
  290. package/src/protocol/response/omp-tool-call-markup.ts +1 -1
  291. package/src/protocol/response/responses.ts +1 -1
  292. package/src/protocol/sse-decoder.ts +50 -1
  293. package/src/protocol/stop-reason.ts +2 -2
  294. package/src/protocol/think-split.ts +347 -0
  295. package/src/protocol/translation/attachment-integrity.ts +3 -3
  296. package/src/protocol/translation/cache-controls.ts +8 -20
  297. package/src/protocol/translation/capabilities.ts +6 -6
  298. package/src/protocol/translation/dialect/deepseek.ts +10 -0
  299. package/src/protocol/translation/dialect/inband.ts +39 -0
  300. package/src/protocol/translation/dialect/model-thinking.ts +89 -0
  301. package/src/protocol/translation/dialect/qwen.ts +114 -0
  302. package/src/protocol/translation/dialect/resolver.ts +83 -0
  303. package/src/protocol/translation/dialect/rules.ts +93 -0
  304. package/src/protocol/translation/dialect/thinking-ladder.ts +245 -0
  305. package/src/protocol/translation/dialect/types.ts +58 -0
  306. package/src/protocol/translation/quirks.ts +18 -4
  307. package/src/protocol/translation/thinking.ts +12 -252
  308. package/src/protocol/translation/tool-id.ts +3 -3
  309. package/src/protocol/translation/tool-repair.ts +1 -1
  310. package/src/protocol/upstream/post-json.ts +6 -1
  311. package/src/providers/adapters/compatible-adapter.ts +71 -4
  312. package/src/providers/authentication/jwt-validator.ts +0 -5
  313. package/src/providers/authentication/oauth-client.ts +254 -253
  314. package/src/providers/authentication/oauth-flow-store.ts +42 -7
  315. package/src/providers/bundled-discovery-providers.ts +6 -30
  316. package/src/providers/configured-openai-providers.ts +82 -97
  317. package/src/providers/default-registry.ts +35 -37
  318. package/src/providers/discovery/catalog/catalog-format.ts +13 -2
  319. package/src/providers/discovery/discovery-types.ts +0 -1
  320. package/src/providers/discovery/openai-model-discovery.ts +2 -2
  321. package/src/providers/discovery/probe-phases.ts +48 -13
  322. package/src/providers/discovery/probing-service.ts +6 -8
  323. package/src/providers/integrations/agentrouter/agentrouter.ts +12 -2
  324. package/src/providers/integrations/antigravity/antigravity-oauth.ts +0 -1
  325. package/src/providers/integrations/antigravity/antigravity-protocol.ts +88 -28
  326. package/src/providers/integrations/antigravity/antigravity-quota.ts +18 -6
  327. package/src/providers/integrations/antigravity/antigravity.ts +22 -13
  328. package/src/providers/integrations/buddy/buddy-catalog-shared.ts +1 -1
  329. package/src/providers/integrations/buddy/buddy-chat-shared.ts +20 -4
  330. package/src/providers/integrations/buddy/buddy-cli-headers.ts +19 -52
  331. package/src/providers/integrations/buddy/buddy-identity.ts +86 -0
  332. package/src/providers/integrations/buddy/buddy-oauth-shared.ts +1 -1
  333. package/src/providers/integrations/buddy/codebuddy/cn-provider.ts +1 -2
  334. package/src/providers/integrations/buddy/codebuddy/provider.ts +4 -15
  335. package/src/providers/integrations/buddy/codebuddy/shared.ts +30 -9
  336. package/src/providers/integrations/buddy/workbuddy/provider.ts +5 -9
  337. package/src/providers/integrations/buddy/workbuddy/shared.ts +21 -3
  338. package/src/providers/integrations/claude/claude-cch.ts +148 -148
  339. package/src/providers/integrations/claude/fallback-credit.ts +3 -7
  340. package/src/providers/integrations/cline/cline.ts +1 -1
  341. package/src/providers/integrations/codex/codex-device-code.ts +101 -101
  342. package/src/providers/integrations/codex/codex-oauth.ts +0 -1
  343. package/src/providers/integrations/commandcode/commandcode.ts +75 -115
  344. package/src/providers/integrations/commandcode/quota.ts +131 -51
  345. package/src/providers/integrations/cursor/cursor-http2.ts +0 -3
  346. package/src/providers/integrations/cursor/cursor-quota.ts +2 -6
  347. package/src/providers/integrations/cursor/cursor-request.ts +0 -87
  348. package/src/providers/integrations/cursor/cursor-shared.ts +0 -4
  349. package/src/providers/integrations/cursor/cursor.ts +35 -3
  350. package/src/providers/integrations/cursor/protocol/framing.ts +0 -56
  351. package/src/providers/integrations/cursor/protocol/messages.ts +0 -96
  352. package/src/providers/integrations/factory/factory.ts +9 -9
  353. package/src/providers/integrations/github/github-discovery.ts +70 -12
  354. package/src/providers/integrations/github/github-oauth.ts +184 -14
  355. package/src/providers/integrations/github/github.ts +134 -26
  356. package/src/providers/integrations/grok/grok-oauth.ts +261 -261
  357. package/src/providers/integrations/grok/grok-quota-frame.ts +1 -1
  358. package/src/providers/integrations/grok/grok-quota.ts +16 -7
  359. package/src/providers/integrations/grok/grok-ratelimit-store.ts +0 -5
  360. package/src/providers/integrations/grok/grok-ratelimit.ts +3 -0
  361. package/src/providers/integrations/grok/grok.ts +86 -36
  362. package/src/providers/integrations/kilo/kilo-oauth.ts +1 -1
  363. package/src/providers/integrations/kiro/kiro-cache.ts +31 -0
  364. package/src/providers/integrations/kiro/kiro-catalog.ts +31 -5
  365. package/src/providers/integrations/kiro/kiro-discovery.ts +47 -43
  366. package/src/providers/integrations/kiro/kiro-machine-id.ts +6 -3
  367. package/src/providers/integrations/kiro/kiro-oauth.ts +523 -255
  368. package/src/providers/integrations/kiro/kiro-quota.ts +35 -47
  369. package/src/providers/integrations/kiro/kiro-request.ts +8 -11
  370. package/src/providers/integrations/kiro/kiro-stream.ts +13 -0
  371. package/src/providers/integrations/kiro/kiro.ts +80 -68
  372. package/src/providers/integrations/muse/muse-oauth.ts +0 -1
  373. package/src/providers/integrations/muse/muse-quota.ts +0 -4
  374. package/src/providers/integrations/opencode/fingerprint.ts +7 -5
  375. package/src/providers/integrations/opencode/provider.ts +17 -24
  376. package/src/providers/integrations/qoder/qoder-catalog.ts +94 -11
  377. package/src/providers/integrations/qoder/qoder-oauth.ts +165 -25
  378. package/src/providers/integrations/qoder/qoder-quota.ts +48 -6
  379. package/src/providers/integrations/qoder/qoder-realm.ts +10 -31
  380. package/src/providers/integrations/qoder/qoder-sse.ts +159 -0
  381. package/src/providers/integrations/qoder/qoder-umid.ts +21 -25
  382. package/src/providers/integrations/qoder/qoder-virtual.ts +12 -0
  383. package/src/providers/integrations/qoder/qoder.ts +422 -71
  384. package/src/providers/integrations/shared/connect.ts +0 -54
  385. package/src/providers/integrations/shared/hash.ts +15 -0
  386. package/src/providers/integrations/shared/session-cache.ts +136 -0
  387. package/src/providers/integrations/trae/trae-cache.ts +7 -87
  388. package/src/providers/integrations/trae/trae-catalog.ts +1 -6
  389. package/src/providers/integrations/trae/trae-protocol.ts +17 -8
  390. package/src/providers/integrations/trae/trae-realm.ts +0 -7
  391. package/src/providers/integrations/trae/trae.ts +51 -8
  392. package/src/providers/integrations/xai/xai-oauth.ts +5 -5
  393. package/src/providers/integrations/zcode-start-plan/gifts.ts +265 -0
  394. package/src/providers/integrations/zcode-start-plan/oauth.ts +154 -0
  395. package/src/providers/integrations/zcode-start-plan/provider.ts +131 -0
  396. package/src/providers/integrations/zcode-start-plan/quota.ts +152 -0
  397. package/src/providers/integrations/zcode-start-plan/zcode_prompt.json +10 -0
  398. package/src/providers/operations/account-error-classification.ts +198 -133
  399. package/src/providers/operations/account-health-service.ts +31 -39
  400. package/src/providers/operations/account-reset-service.ts +58 -1
  401. package/src/providers/operations/byok-wire-profile.ts +19 -15
  402. package/src/providers/operations/cli-platform.ts +31 -5
  403. package/src/providers/operations/client-version-resolver.ts +4 -6
  404. package/src/providers/operations/client-versions.ts +10 -7
  405. package/src/providers/operations/provider-catalog-seeder.ts +2 -0
  406. package/src/providers/operations/provider-catalog-service.ts +18 -2
  407. package/src/providers/operations/provider-credential-service.ts +19 -2
  408. package/src/providers/provider-contracts.ts +18 -7
  409. package/src/providers/provider-metadata.ts +17 -2
  410. package/src/providers/provider-model-definition.ts +22 -1
  411. package/src/providers/provider-probe.ts +4 -2
  412. package/src/providers/provider-usage.ts +50 -19
  413. package/src/providers/quota/cache.ts +29 -0
  414. package/src/providers/quota/quota-contracts.ts +4 -0
  415. package/src/providers/quota/refresh.ts +27 -4
  416. package/src/providers/quota/snapshot.ts +94 -0
  417. package/src/providers/search/search-provider.ts +1 -3
  418. package/src/providers/search/search-providers.ts +2 -1
  419. package/src/security/abuse.ts +4 -4
  420. package/src/security/admission/service.ts +13 -6
  421. package/src/security/admission/ttl.ts +61 -61
  422. package/src/security/api-key-auth.ts +17 -3
  423. package/src/security/client-router-fingerprint.ts +4 -4
  424. package/src/security/credential-codec.ts +3 -3
  425. package/src/security/csrf.ts +2 -2
  426. package/src/security/ip-boundary.ts +16 -189
  427. package/src/security/model-access-rule.ts +1 -1
  428. package/src/security/outbound-headers.ts +18 -0
  429. package/src/shared/invoke-guard.ts +47 -0
  430. package/src/transport/contracts.ts +13 -4
  431. package/src/transport/dispatch/attempt-finalize.ts +70 -22
  432. package/src/transport/dispatch/attempt-loop.ts +22 -0
  433. package/src/transport/dispatch/capture-policy.ts +34 -37
  434. package/src/transport/dispatch/empty-stream.ts +23 -20
  435. package/src/transport/dispatch/generation.ts +25 -45
  436. package/src/transport/dispatch/native-shared.ts +127 -0
  437. package/src/transport/dispatch/proxy-request.ts +3 -1
  438. package/src/transport/dispatch/responses-compact.ts +25 -46
  439. package/src/transport/dispatch/streaming/encoder.ts +18 -72
  440. package/src/transport/dispatch/streaming/finalize.ts +2 -2
  441. package/src/transport/dispatch/streaming/stream.ts +7 -3
  442. package/src/transport/dispatch/streaming/thinking-loop.ts +1 -1
  443. package/src/transport/dispatch/systemone.ts +20 -48
  444. package/src/transport/dispatch/token-count.ts +41 -38
  445. package/src/transport/dispatch/websearch.ts +19 -45
  446. package/src/transport/drain-endpoint.ts +1 -1
  447. package/src/transport/failure-policy.ts +21 -1
  448. package/src/transport/guards/auth-guard.ts +0 -6
  449. package/src/transport/guards/body-policy.ts +3 -3
  450. package/src/transport/guards/error-lifecycle.ts +4 -0
  451. package/src/transport/guards/headroom-guard.ts +1 -1
  452. package/src/transport/guards/pipeline.ts +1 -1
  453. package/src/transport/guards/request-context.ts +12 -17
  454. package/src/transport/request/preparer.ts +286 -7
  455. package/src/transport/request/rtk/compress-request.ts +3 -3
  456. package/src/transport/request/rtk/rtk-constants.ts +2 -2
  457. package/src/transport/request/rtk/rtk-filters.ts +8 -8
  458. package/src/transport/request/state.ts +7 -13
  459. package/src/transport/request/system-prompt-injection.ts +74 -11
  460. package/src/transport/request/tenant-preferences.ts +22 -0
  461. package/src/transport/routing/candidate-index.ts +2 -2
  462. package/src/transport/routing/round-robin.ts +1 -1
  463. package/src/transport/routing/route-catalog.ts +17 -18
  464. package/src/transport/routing/route-model.ts +126 -33
  465. package/src/transport/routing/router.ts +159 -37
  466. package/src/transport/shutdown-notice.ts +2 -2
  467. package/src/transport/surface/adapters.ts +3 -3
  468. package/src/transport/surface/chat/encode.ts +7 -7
  469. package/src/transport/surface/chat/parse.ts +7 -7
  470. package/src/transport/surface/completion.ts +2 -2
  471. package/src/transport/surface/content-parts.ts +1 -1
  472. package/src/transport/surface/dialects.ts +2 -2
  473. package/src/transport/surface/messages/parse.ts +3 -3
  474. package/src/transport/surface/reasoning-summary.ts +9 -14
  475. package/src/transport/surface/responses/adapter.ts +1 -1
  476. package/src/transport/surface/responses/errors.ts +0 -9
  477. package/src/transport/vision-handoff-cache.ts +58 -0
  478. package/src/transport/vision-handoff.ts +431 -0
  479. package/src/workers/account-identity-sweep.ts +2 -2
  480. package/src/workers/buddy-growth-tasks.ts +392 -346
  481. package/src/workers/daily-checkin.ts +102 -49
  482. package/src/workers/maintenance-lease.ts +2 -35
  483. package/src/workers/oauth-refresh-sweep.ts +8 -1
  484. package/src/workers/quota-refresh-sweep.ts +120 -82
  485. package/src/workers/scheduler.ts +67 -4
  486. package/src/workers/sweep-runner.ts +24 -5
  487. package/src/workers/zcode-gift-claim.ts +108 -0
  488. package/dist/dashboard/assets/AccountCooldown-Bjo92Qat.js +0 -1
  489. package/dist/dashboard/assets/AccountCooldown-Bjo92Qat.js.gz +0 -0
  490. package/dist/dashboard/assets/BannedPage-ChG5svFb.js +0 -1
  491. package/dist/dashboard/assets/BannedPage-ChG5svFb.js.gz +0 -0
  492. package/dist/dashboard/assets/CliToolDetailPage-BIcWQun7.js +0 -1
  493. package/dist/dashboard/assets/CliToolDetailPage-BIcWQun7.js.gz +0 -0
  494. package/dist/dashboard/assets/CliToolsPage-Bf2VelDe.js +0 -1
  495. package/dist/dashboard/assets/CliToolsPage-Bf2VelDe.js.gz +0 -0
  496. package/dist/dashboard/assets/CombosPage-DCgm5g6g.js +0 -1
  497. package/dist/dashboard/assets/CombosPage-DCgm5g6g.js.gz +0 -0
  498. package/dist/dashboard/assets/ConsoleLogPage-a8mD0QF1.js +0 -1
  499. package/dist/dashboard/assets/ConsoleLogPage-a8mD0QF1.js.gz +0 -0
  500. package/dist/dashboard/assets/CustomizationPage-ggeMSjte.js +0 -1
  501. package/dist/dashboard/assets/CustomizationPage-ggeMSjte.js.gz +0 -0
  502. package/dist/dashboard/assets/HealthEventsModal-DzSWzE_j.js +0 -1
  503. package/dist/dashboard/assets/HealthEventsModal-DzSWzE_j.js.gz +0 -0
  504. package/dist/dashboard/assets/LoginPage-U6AKaJcF.js +0 -1
  505. package/dist/dashboard/assets/LoginPage-U6AKaJcF.js.gz +0 -0
  506. package/dist/dashboard/assets/ModelPicker-BMS2t8BA.js.gz +0 -0
  507. package/dist/dashboard/assets/OverviewPage-D2D4IiHl.js +0 -1
  508. package/dist/dashboard/assets/OverviewPage-D2D4IiHl.js.gz +0 -0
  509. package/dist/dashboard/assets/ProviderDetailPage-CrNf7j_X.js +0 -5
  510. package/dist/dashboard/assets/ProviderDetailPage-CrNf7j_X.js.gz +0 -0
  511. package/dist/dashboard/assets/ProviderIcon-FB6yS4v1.js +0 -1
  512. package/dist/dashboard/assets/ProviderIcon-FB6yS4v1.js.gz +0 -0
  513. package/dist/dashboard/assets/ProvidersPage-BSDbquc1.js +0 -1
  514. package/dist/dashboard/assets/ProvidersPage-BSDbquc1.js.gz +0 -0
  515. package/dist/dashboard/assets/ProxyPage-lsrx7NYg.js.gz +0 -0
  516. package/dist/dashboard/assets/QuotaPage-L0skzML8.js +0 -1
  517. package/dist/dashboard/assets/QuotaPage-L0skzML8.js.gz +0 -0
  518. package/dist/dashboard/assets/SettingsPage-CmAbjRHW.js +0 -1
  519. package/dist/dashboard/assets/SettingsPage-CmAbjRHW.js.gz +0 -0
  520. package/dist/dashboard/assets/SetupPage-f0DE1h0-.js +0 -1
  521. package/dist/dashboard/assets/SetupPage-f0DE1h0-.js.gz +0 -0
  522. package/dist/dashboard/assets/SortableList-ClzpwyET.js +0 -1
  523. package/dist/dashboard/assets/SortableList-ClzpwyET.js.gz +0 -0
  524. package/dist/dashboard/assets/StudioPage-Cq5tW7hW.js.gz +0 -0
  525. package/dist/dashboard/assets/ToolIcon-K1ckcDKg.js +0 -1
  526. package/dist/dashboard/assets/ToolIcon-K1ckcDKg.js.gz +0 -0
  527. package/dist/dashboard/assets/UsagePage-Dfc9rWQn.js +0 -56
  528. package/dist/dashboard/assets/UsagePage-Dfc9rWQn.js.gz +0 -0
  529. package/dist/dashboard/assets/api-keys-C38iXoO4.js +0 -1
  530. package/dist/dashboard/assets/api-keys-C38iXoO4.js.gz +0 -0
  531. package/dist/dashboard/assets/app-BayTTy01.js +0 -9
  532. package/dist/dashboard/assets/app-BayTTy01.js.gz +0 -0
  533. package/dist/dashboard/assets/app-a159k0ub.css +0 -2
  534. package/dist/dashboard/assets/app-a159k0ub.css.gz +0 -0
  535. package/dist/dashboard/assets/assert-DbRA8EG2.js +0 -15
  536. package/dist/dashboard/assets/assert-DbRA8EG2.js.gz +0 -0
  537. package/dist/dashboard/assets/badge-D9CS6dZk.js.gz +0 -0
  538. package/dist/dashboard/assets/banner-DympBNq4.js.gz +0 -0
  539. package/dist/dashboard/assets/card-ibRWU_uT.js.gz +0 -0
  540. package/dist/dashboard/assets/cli-tools-63qBGaRw.js +0 -1
  541. package/dist/dashboard/assets/cli-tools-63qBGaRw.js.gz +0 -0
  542. package/dist/dashboard/assets/clipboard-button-DJm-9pz7.js.gz +0 -0
  543. package/dist/dashboard/assets/dialog-8fiE6tec.js +0 -1
  544. package/dist/dashboard/assets/dialog-8fiE6tec.js.gz +0 -0
  545. package/dist/dashboard/assets/drawer-CqGYeOrd.js.gz +0 -0
  546. package/dist/dashboard/assets/entry-BSAsYsmV.js +0 -1
  547. package/dist/dashboard/assets/entry-BSAsYsmV.js.gz +0 -0
  548. package/dist/dashboard/assets/entry-CiIQULZD.js +0 -4
  549. package/dist/dashboard/assets/entry-CiIQULZD.js.gz +0 -0
  550. package/dist/dashboard/assets/entry-Daz0lJ-W.js +0 -1
  551. package/dist/dashboard/assets/entry-Daz0lJ-W.js.gz +0 -0
  552. package/dist/dashboard/assets/formatters-D-MTJxMr.js.gz +0 -0
  553. package/dist/dashboard/assets/github-badge-CPK47xQx.js +0 -1
  554. package/dist/dashboard/assets/github-badge-CPK47xQx.js.gz +0 -0
  555. package/dist/dashboard/assets/index-DBNPOfhV.js.gz +0 -0
  556. package/dist/dashboard/assets/inline-BT0zntEr.js.gz +0 -0
  557. package/dist/dashboard/assets/input-Da2ZViWg.js.gz +0 -0
  558. package/dist/dashboard/assets/layout-BXNeLw6M.js.gz +0 -0
  559. package/dist/dashboard/assets/list-row-BycOrrIV.js.gz +0 -0
  560. package/dist/dashboard/assets/live-DCQNZpF7.js +0 -1
  561. package/dist/dashboard/assets/live-DCQNZpF7.js.gz +0 -0
  562. package/dist/dashboard/assets/mutation-Rr0TIvcj.js.gz +0 -0
  563. package/dist/dashboard/assets/network-9Yj2ZyLo.js +0 -1
  564. package/dist/dashboard/assets/network-9Yj2ZyLo.js.gz +0 -0
  565. package/dist/dashboard/assets/numbers-CEagj6ZZ.js +0 -2
  566. package/dist/dashboard/assets/numbers-CEagj6ZZ.js.gz +0 -0
  567. package/dist/dashboard/assets/providers/zai-coding-plan.svg +0 -6
  568. package/dist/dashboard/assets/providers/zai-coding-plan.svg.gz +0 -0
  569. package/dist/dashboard/assets/quota-Caw7wqci.js +0 -1
  570. package/dist/dashboard/assets/quota-Caw7wqci.js.gz +0 -0
  571. package/dist/dashboard/assets/routing-CO9zCUus.js +0 -1
  572. package/dist/dashboard/assets/routing-CO9zCUus.js.gz +0 -0
  573. package/dist/dashboard/assets/select-BIYIBkMU.js.gz +0 -0
  574. package/dist/dashboard/assets/settings-jS3-PNSA.js +0 -1
  575. package/dist/dashboard/assets/settings-jS3-PNSA.js.gz +0 -0
  576. package/dist/dashboard/assets/stack-DfgnFDWY.js.gz +0 -0
  577. package/dist/dashboard/assets/state-CkfdYWel.js.gz +0 -0
  578. package/dist/dashboard/assets/stream-retry-5QnVuSSo.js +0 -1
  579. package/dist/dashboard/assets/stream-retry-5QnVuSSo.js.gz +0 -0
  580. package/dist/dashboard/assets/switch-SYm237HG.js.gz +0 -0
  581. package/dist/dashboard/assets/useMutation-BQqCRNIi.js.gz +0 -0
  582. package/src/console/cli-tools/injectors/cline.ts +0 -110
  583. package/src/console/cli-tools/injectors/copilot.ts +0 -108
  584. package/src/console/cli-tools/injectors/cowork.ts +0 -64
  585. package/src/console/cli-tools/injectors/deepseek-tui.ts +0 -85
  586. package/src/console/cli-tools/injectors/droid.ts +0 -96
  587. package/src/console/cli-tools/injectors/grok-build.ts +0 -70
  588. package/src/console/cli-tools/injectors/hermes.ts +0 -101
  589. package/src/console/cli-tools/injectors/jcode.ts +0 -115
  590. package/src/console/cli-tools/injectors/openclaw.ts +0 -161
  591. package/src/network/response-headers.ts +0 -39
  592. package/src/protocol/response/dsml.ts +0 -38
  593. package/src/providers/integrations/xiaomi-mimo/think-stream.ts +0 -229
  594. /package/dist/dashboard/assets/brand/{og_bansos.webp → og_bansos_initial.webp} +0 -0
  595. /package/dist/dashboard/assets/brand/{og_image.webp → og_image_initial.webp} +0 -0
@@ -96,7 +96,8 @@ interface AntigravityModelWireProfile {
96
96
 
97
97
  /**
98
98
  * `maxOutputTokens` the backend enforces per wire id (captured from the real
99
- * `antigravity/hub` client). Claude on `daily-cloudcode-pa` rejects
99
+ * `antigravity/hub` client and verified live against `fetchAvailableModels`
100
+ * on 2026-11-03). Claude on `daily-cloudcode-pa` rejects
100
101
  * `maxOutputTokens > 64000` with a `400 Request contains an invalid argument`
101
102
  * regardless of the thinking budget; Gemini SKUs accept their discovered
102
103
  * output ceiling. Keyed by the routed upstream wire id (post effort-routing),
@@ -106,22 +107,75 @@ interface AntigravityModelWireProfile {
106
107
  const ANTIGRAVITY_MODEL_WIRE_PROFILES: Readonly<
107
108
  Record<string, AntigravityModelWireProfile>
108
109
  > = Object.freeze({
109
- // Anthropic on Antigravity caps at 64000 output tokens.
110
- "claude-opus-4-6-thinking": { maxOutputTokens: 64000 },
111
- "claude-sonnet-4-6": { maxOutputTokens: 64000 },
112
- // Gemini effort-routed wire ids (real deployment names).
113
- "gemini-3-flash-agent": {
114
- modelEnum: "MODEL_PLACEHOLDER_M132",
110
+ // Anthropic on Antigravity caps at 64000 output tokens (verified live).
111
+ "claude-opus-4-6-thinking": {
112
+ modelEnum: "MODEL_PLACEHOLDER_M26",
113
+ maxOutputTokens: 64000,
114
+ },
115
+ "claude-sonnet-4-6": {
116
+ modelEnum: "MODEL_PLACEHOLDER_M35",
117
+ maxOutputTokens: 64000,
118
+ },
119
+ // Gemini SKUs, as the live roster publishes them (2026-11-03).
120
+ "gemini-2.5-flash": {
121
+ modelEnum: "MODEL_GOOGLE_GEMINI_2_5_FLASH",
122
+ maxOutputTokens: 65535,
123
+ },
124
+ "gemini-2.5-flash-thinking": {
125
+ modelEnum: "MODEL_GOOGLE_GEMINI_2_5_FLASH_THINKING",
126
+ maxOutputTokens: 65535,
127
+ },
128
+ "gemini-2.5-flash-lite": {
129
+ modelEnum: "MODEL_GOOGLE_GEMINI_2_5_FLASH_LITE",
130
+ maxOutputTokens: 65535,
131
+ },
132
+ "gemini-2.5-pro": {
133
+ modelEnum: "MODEL_GOOGLE_GEMINI_2_5_PRO",
134
+ maxOutputTokens: 65535,
135
+ },
136
+ "gemini-3-flash": {
137
+ modelEnum: "MODEL_PLACEHOLDER_M18",
115
138
  maxOutputTokens: 65536,
116
139
  },
117
- "gemini-3.1-pro-low": {
118
- modelEnum: "MODEL_PLACEHOLDER_M36",
140
+ "gemini-3.1-flash-lite": {
141
+ modelEnum: "MODEL_PLACEHOLDER_M50",
119
142
  maxOutputTokens: 65535,
120
143
  },
121
- "gemini-pro-agent": {
122
- modelEnum: "MODEL_PLACEHOLDER_M16",
144
+ "gemini-3.1-flash-image": {
145
+ modelEnum: "MODEL_PLACEHOLDER_M21",
146
+ maxOutputTokens: 65536,
147
+ },
148
+ "gemini-3.5-flash-lite": {
149
+ modelEnum: "MODEL_PLACEHOLDER_M198",
123
150
  maxOutputTokens: 65535,
124
151
  },
152
+ // Gemini 3.8 Flash effort tiers (real deployment names).
153
+ "gemini-3.8-flash-low": {
154
+ modelEnum: "MODEL_PLACEHOLDER_M320",
155
+ maxOutputTokens: 65536,
156
+ },
157
+ "gemini-3.8-flash-medium": {
158
+ modelEnum: "MODEL_PLACEHOLDER_M319",
159
+ maxOutputTokens: 65536,
160
+ },
161
+ "gemini-3.8-flash-high": {
162
+ modelEnum: "MODEL_PLACEHOLDER_M318",
163
+ maxOutputTokens: 65536,
164
+ },
165
+ "gemini-3.8-flash-tiered": {
166
+ modelEnum: "MODEL_PLACEHOLDER_M322",
167
+ maxOutputTokens: 65536,
168
+ },
169
+ // GPT-OSS via Antigravity (verified live).
170
+ "gpt-oss-120b-medium": {
171
+ modelEnum: "MODEL_OPENAI_GPT_OSS_120B_MEDIUM",
172
+ maxOutputTokens: 32768,
173
+ },
174
+ // Tab (laptop-class) preview SKU.
175
+ "tab_flash_lite_preview": {
176
+ modelEnum: "MODEL_PLACEHOLDER_M19",
177
+ maxOutputTokens: 4096,
178
+ },
125
179
  });
126
180
 
127
181
  export function getAntigravityModelWireProfile(
@@ -257,8 +311,6 @@ export function normalizeAntigravityToolSchemas(request: CanonicalRequest): Cano
257
311
  const lastGoodEndpoints = new Map<string, string>();
258
312
  const LAST_GOOD_ENDPOINT_MAX = 256;
259
313
 
260
- const DEFAULT_ORDER_INDEX = Number.MAX_SAFE_INTEGER;
261
-
262
314
  /**
263
315
  * Records the endpoint that just served a successful turn. Call this with the
264
316
  * `endpoint` reported by empty-stream recovery (or the URL that produced a
@@ -301,18 +353,6 @@ export function orderAntigravityEndpoints(
301
353
  return [sticky, ...endpoints.slice(0, index), ...endpoints.slice(index + 1)];
302
354
  }
303
355
 
304
- /**
305
- * Position of `endpoint` in the caller's own endpoint order, used to log a
306
- * failover without the caller re-deriving the list.
307
- */
308
- export function antigravityEndpointOrderIndex(
309
- endpoints: readonly string[],
310
- endpoint: string,
311
- ): number {
312
- const index = endpoints.indexOf(endpoint);
313
- return index < 0 ? DEFAULT_ORDER_INDEX : index;
314
- }
315
-
316
356
  // Model discovery (`v1internal:fetchAvailableModels`) — live catalog.
317
357
 
318
358
  const ANTIGRAVITY_DISCOVERY_PATH = "/v1internal:fetchAvailableModels";
@@ -412,6 +452,7 @@ export async function discoverAntigravityModels(
412
452
  readonly baseUrl?: string;
413
453
  readonly fetcher?: typeof fetch;
414
454
  readonly signal?: AbortSignal;
455
+ readonly projectId?: string;
415
456
  } = {},
416
457
  ): Promise<readonly ModelDefinition[] | null> {
417
458
  const fetcher = options.fetcher ?? fetch;
@@ -433,7 +474,10 @@ export async function discoverAntigravityModels(
433
474
  "content-type": "application/json",
434
475
  "user-agent": getAntigravityUserAgent(),
435
476
  },
436
- body: "{}",
477
+ // The reference client always sends the resolved project
478
+ // (`cloudCodeMainService.js`); the live backend accepts both, but the
479
+ // project is required for billing-gated endpoints.
480
+ body: JSON.stringify(options.projectId === undefined ? {} : { project: options.projectId }),
437
481
  signal,
438
482
  });
439
483
  if (!response.ok) continue;
@@ -503,9 +547,16 @@ export function applySkipThoughtSignatureBypass(
503
547
  * Sending the Gemini shape makes the backend treat the call as a different
504
548
  * client and refuse to enroll the account, which the operator sees as
505
549
  * "You do not have a valid license of this product".
550
+ *
551
+ * The reference client (`cloudCodeMainService.js`) sends the full product
552
+ * identity: `ideName`, `ideType`, and `ideVersion`. `ideType` alone was
553
+ * accepted live, but the full shape is the captured wire and avoids any
554
+ * client-class gating on the control plane.
506
555
  */
507
556
  export const ANTIGRAVITY_LOAD_CODE_ASSIST_METADATA = Object.freeze({
557
+ ideName: "antigravity",
508
558
  ideType: "ANTIGRAVITY",
559
+ ideVersion: getAntigravityVersion(),
509
560
  });
510
561
 
511
562
  const projectIdCache = new Map<string, string>();
@@ -584,7 +635,9 @@ const FREE_TIER_ID = "free-tier";
584
635
  const ONBOARD_USER_PATH = "/v1internal:onboardUser";
585
636
  const ONBOARD_OPERATIONS_PATH = "/v1internal";
586
637
  const ONBOARD_TIMEOUT_MS = 30_000;
587
- const ONBOARD_POLL_INTERVAL_MS = 1_000;
638
+ // Reference client (`cloudCodeMainService.js`) polls the operation every
639
+ // 500ms (`gXa = 500`).
640
+ const ONBOARD_POLL_INTERVAL_MS = 500;
588
641
 
589
642
  /** Thrown when an account cannot be enrolled in the Antigravity free tier. */
590
643
  export class AntigravityProvisioningError extends Error {
@@ -713,6 +766,9 @@ async function onboardUser(
713
766
  if (left <= 0) throw new AntigravityProvisioningError("onboardUser timed out");
714
767
  return left;
715
768
  };
769
+ const projectId = extractProjectId(
770
+ await loadCodeAssist(fetcher, base, accessToken, signal),
771
+ );
716
772
  let operation = await cloudCodeAssistCall(
717
773
  fetcher,
718
774
  base,
@@ -720,7 +776,11 @@ async function onboardUser(
720
776
  ONBOARD_USER_PATH,
721
777
  {
722
778
  method: "POST",
723
- body: { tierId: FREE_TIER_ID, metadata: ANTIGRAVITY_LOAD_CODE_ASSIST_METADATA },
779
+ body: {
780
+ tierId: FREE_TIER_ID,
781
+ ...(projectId === undefined ? {} : { cloudaicompanionProject: projectId }),
782
+ metadata: ANTIGRAVITY_LOAD_CODE_ASSIST_METADATA,
783
+ },
724
784
  },
725
785
  signal,
726
786
  );
@@ -118,9 +118,6 @@ function keepWorse(
118
118
  return candidateRemaining < currentRemaining ? candidate : current;
119
119
  }
120
120
 
121
- /** Total the upstream's fractional allowance is normalized against. */
122
- const QUOTA_TOTAL = 1000;
123
-
124
121
  /** Builds a window from a `remainingFraction` + `resetTime` pair. */
125
122
  function fractionWindow(
126
123
  kind: string,
@@ -129,9 +126,8 @@ function fractionWindow(
129
126
  resetsAt: string | null,
130
127
  ): ProviderQuotaWindow {
131
128
  const fraction = Math.min(1, Math.max(0, remainingFraction));
132
- const used = QUOTA_TOTAL - Math.round(QUOTA_TOTAL * fraction);
133
129
  return {
134
- ...percentWindow(kind, label, (1 - fraction) * 100, resetsAt, used, QUOTA_TOTAL, "independent"),
130
+ ...percentWindow(kind, label, (1 - fraction) * 100, resetsAt, null, null, "independent"),
135
131
  recurring: true,
136
132
  };
137
133
  }
@@ -316,7 +312,23 @@ export async function fetchAntigravityQuota(
316
312
  ...(project === undefined ? {} : { project }),
317
313
  }),
318
314
  );
319
- windows.push(...parseModelQuotas(models));
315
+ // The summary endpoint already covers a family with a weekly window; the
316
+ // per-model windows are a subset of that same allowance, so rendering
317
+ // both doubles every row the operator sees. Per-model windows stay as a
318
+ // fallback when the summary was unavailable, so a family still reports
319
+ // something.
320
+ const summaryLabels = windows.map((window) => window.label.toLowerCase());
321
+ // Model family key → the summary family label it falls under.
322
+ const summaryLabelForModel = (key: string): string =>
323
+ key === "google" ? "gemini" : "claude";
324
+ const modelWindows = parseModelQuotas(models);
325
+ windows.push(
326
+ ...modelWindows.filter((window) => {
327
+ const familyKey = window.kind.split(":")[0] ?? "";
328
+ const summaryLabel = summaryLabelForModel(familyKey);
329
+ return !summaryLabels.some((label) => label.includes(summaryLabel));
330
+ }),
331
+ );
320
332
  plan = plan ?? text(models.tier) ?? text(models.plan);
321
333
  break;
322
334
  } catch {
@@ -94,22 +94,26 @@ export const ANTIGRAVITY_MODELS: readonly ModelDefinition[] = [
94
94
  antigravityModel("claude-opus-4-6", 250_000, 64_000, true),
95
95
  antigravityModel("claude-sonnet-5-5", 1_000_000, 128_000, true),
96
96
  antigravityModel("claude-opus-5-5", 1_000_000, 128_000, true),
97
- // Gemini text SKUs, as the Antigravity roster publishes them.
98
- antigravityModel("gemini-2.5-flash", 1_000_000, 66_000, true),
99
- antigravityModel("gemini-2.5-flash-thinking", 1_000_000, 66_000, true),
100
- antigravityModel("gemini-3-flash", 1_000_000, 66_000, true),
101
- antigravityModel("gemini-3.1-flash-lite", 1_000_000, 66_000, true),
102
- antigravityModel("gemini-2.5-flash-lite", 1_000_000, 66_000, true),
103
- antigravityModel("gemini-3.5-flash-lite", 1_000_000, 66_000, true),
104
- antigravityModel("gemini-3.8-flash", 1_000_000, 66_000, true),
97
+ // Gemini text SKUs, as the Antigravity roster publishes them (verified live
98
+ // 2026-11-03): Gemini SKUs ceiling at 65535/65536 output tokens.
99
+ antigravityModel("gemini-2.5-flash", 1_000_000, 65_535, true),
100
+ antigravityModel("gemini-2.5-flash-thinking", 1_000_000, 65_535, true),
101
+ antigravityModel("gemini-2.5-flash-lite", 1_000_000, 65_535, true),
102
+ antigravityModel("gemini-2.5-pro", 1_000_000, 65_535, true),
103
+ antigravityModel("gemini-3-flash", 1_000_000, 65_536, true),
104
+ antigravityModel("gemini-3.1-flash-lite", 1_000_000, 65_535, true),
105
+ antigravityModel("gemini-3.5-flash-lite", 1_000_000, 65_535, true),
106
+ antigravityModel("gemini-3.8-flash", 1_000_000, 65_536, true),
105
107
  antigravityModel("gemini-4-argon", 1_000_000, 65_536, true),
106
108
  antigravityModel("gemini-4-carbon", 1_000_000, 65_536, true),
107
109
  // Tab (laptop-class) preview SKU.
108
110
  antigravityModel("tab_flash_lite_preview", 16_000, 4_000, true),
109
111
  // Gemini image generation. `gemini-3-pro-image` uses the same catalog
110
112
  // limits/capabilities as the existing `gemini-3.1-flash-image` row.
111
- antigravityModel("gemini-3.1-flash-image", 200_000, 64_000, false, true),
112
- antigravityModel("gemini-3-pro-image", 200_000, 64_000, false, true),
113
+ antigravityModel("gemini-3.1-flash-image", 65_536, 65_536, false, true),
114
+ antigravityModel("gemini-3-pro-image", 65_536, 65_536, false, true),
115
+ // GPT-OSS via Antigravity (verified live 2026-11-03).
116
+ antigravityModel("gpt-oss-120b", 131_072, 32_768, true),
113
117
  ];
114
118
 
115
119
  function normalizeAntigravityGrounding(data: unknown, maxResults: number): readonly WebSearchResult[] {
@@ -758,7 +762,7 @@ export class AntigravitySessionStore {
758
762
  * `"-" + (sha256(first-user-text)[0:8] & INT63 | random <9e18)`.
759
763
  * A positive or hyphenated-UUID value here is a one-glance synthetic signal.
760
764
  */
761
- export function signedAntigravitySessionId(seed?: string): string {
765
+ function signedAntigravitySessionId(seed?: string): string {
762
766
  if (seed !== undefined && /^-?\d+$/.test(seed)) return seed;
763
767
  const text = seed !== undefined && seed.length > 0 ? seed : randomUUID();
764
768
  const head = BigInt(`0x${createHash("sha256").update(text).digest("hex").slice(0, 8)}`);
@@ -769,7 +773,7 @@ export function signedAntigravitySessionId(seed?: string): string {
769
773
  }
770
774
 
771
775
  /** Thinking budget per wire model, matching the client's effort tiers. */
772
- export function antigravityThinkingBudget(modelId: string): number | undefined {
776
+ function antigravityThinkingBudget(modelId: string): number | undefined {
773
777
  if (!modelId.includes("claude") && !modelId.includes("gemini-3")) return undefined;
774
778
  if (modelId.endsWith("-low")) return 1_000;
775
779
  if (modelId.endsWith("-medium")) return 4_000;
@@ -777,8 +781,13 @@ export function antigravityThinkingBudget(modelId: string): number | undefined {
777
781
  return modelId.includes("3.1-pro") ? 10_001 : 10_000;
778
782
  }
779
783
 
784
+ // Original reference instruction (captured from the Antigravity client):
785
+ // "You are Antigravity, a powerful agentic AI coding assistant designed by the Google Deepmind team working on Advanced Agentic Coding.You are pair programming with a USER to solve their coding task. The task may require creating a new codebase, modifying or debugging an existing codebase, or simply answering a question.**Absolute paths only****Proactiveness**"
786
+ // Generalized to a neutral identity so the gateway does not impersonate the
787
+ // vendor's branded assistant. The brand-specific wording is kept above for
788
+ // reference; re-enable it if an upstream behavior ever depends on it.
780
789
  const ANTIGRAVITY_SYSTEM_INSTRUCTION =
781
- "You are Antigravity, a powerful agentic AI coding assistant designed by the Google Deepmind team working on Advanced Agentic Coding.You are pair programming with a USER to solve their coding task. The task may require creating a new codebase, modifying or debugging an existing codebase, or simply answering a question.**Absolute paths only****Proactiveness**";
790
+ "You are a helpful assistant.";
782
791
 
783
792
  /**
784
793
  * Restatement appended as a trailing user turn when a Gemini route carries a
@@ -160,7 +160,7 @@ export function makeBuddyCnImageModels(
160
160
  * plan rather than about the model. A pro account serves all six. The pill is
161
161
  * therefore a hint about a free account, and a dispatch is what settles it.
162
162
  *
163
- * @see `.skills/cartethyia-reverse-engineering/references/codebuddy-dispatch-headers.md`
163
+ * @see `documentation/research/codebuddy/2026-10-19-codebuddy-chat-dispatch-headers.md`
164
164
  */
165
165
  export const BUDDY_PRO_ONLY_MODEL_IDS: ReadonlySet<string> = new Set([
166
166
  "primary-model",
@@ -168,10 +168,11 @@ export function normalizeBuddyToolNames(payload: Record<string, unknown>): void
168
168
  * Both realms have a "let the backend choose" id, and the reference rewrites
169
169
  * `auto` onto it before anything downstream keys on the name — so eligibility,
170
170
  * cooldowns and the catalog all see one id. CN's is `default`; intl's is
171
- * `default-model`.
171
+ * `default-model` (confirmed from live CLI session logs, which send
172
+ * `model=default-model` for the intl auto path).
172
173
  */
173
174
  const BUDDY_AUTO_TARGET: Readonly<Record<"intl" | "cn", string>> = {
174
- intl: "auto",
175
+ intl: "default-model",
175
176
  cn: "default",
176
177
  };
177
178
 
@@ -348,8 +349,8 @@ const DSH_MINIMAL_PATTERN = buddyTemplatePattern("You are a helpful software eng
348
349
  const DSH_DIRECT_PATTERN = buddyTemplatePattern("You are DeepSeek Harness");
349
350
  const DSH_WEB_GUI_PATTERN = buddyTemplatePattern("DeepSeek Harness Web GUI");
350
351
 
351
- /** The identity DSH role prompts are rewritten to; matches the donor gateway. */
352
- const DSH_WORKBUDDY_IDENTITY = "You are WorkBuddy, a powerful AI assistant";
352
+ /** The identity DSH role prompts are rewritten to; neutral and minimal. */
353
+ const DSH_WORKBUDDY_IDENTITY = "You are a helpful assistant";
353
354
 
354
355
  /**
355
356
  * Rewrites DeepSeek Harness role identities in one message's text back to the
@@ -425,6 +426,20 @@ export const clineReasoningReplayPrepares: readonly ((
425
426
  },
426
427
  ];
427
428
 
429
+ /**
430
+ * The reference injects `cache_retention` on every chat body: `long` by
431
+ * default, `short` when prompt caching for 1h is disabled
432
+ * (`CODEBUDDY_DISABLE_PROMPT_CACHING_1H`). Matching the client keeps the
433
+ * upstream's prompt-caching behavior and price on the same path the CLI uses.
434
+ */
435
+ function injectBuddyCacheRetention(payload: Record<string, unknown>): void {
436
+ if (payload["cache_retention"] !== undefined) return;
437
+ const disabled =
438
+ process.env.CODEBUDDY_DISABLE_PROMPT_CACHING_1H?.trim() === "1" ||
439
+ process.env.CODEBUDDY_DISABLE_PROMPT_CACHING_1H?.trim().toLowerCase() === "true";
440
+ payload["cache_retention"] = disabled ? "short" : "long";
441
+ }
442
+
428
443
  /**
429
444
  * Payload prefix shared by the buddy pre-payload hooks: force `stream=true`,
430
445
  * apply the provider's DeepSeek thinking contract, opt `reasoning_summary` in
@@ -437,6 +452,7 @@ export function buddyPrePayloadCommon(
437
452
  context?: ProviderDispatchContext,
438
453
  ): void {
439
454
  injectBuddyPromptCacheKey(payload, request, context);
455
+ injectBuddyCacheRetention(payload);
440
456
  // `auto` and `default-model` are the same upstream model under two names, and
441
457
  // the reference resolves one to the other everywhere — catalog, eligibility,
442
458
  // cooldown keys. Treating them as two independent rows meant a client that
@@ -3,51 +3,19 @@
3
3
  *
4
4
  * Everything here comes from the two reference gateways, which agree: the
5
5
  * desktop product sends conversation/tracing headers and a device token, while
6
- * the CLI sends the agent envelope plus the OpenAI Node SDK fingerprint. The
7
- * CLI still drops the browser *transport* headers (`origin`, `referer`,
8
- * `accept-language`) and the device token, but keeps the request-shape markers
9
- * (`x-requested-with`, `x-codebuddy-request`) the reference sends on every call
10
- * regardless of transport — see the CLI branches in each provider's
11
- * `*-shared.ts`.
6
+ * the CLI sends the agent envelope. The CLI still drops the browser *transport*
7
+ * headers (`origin`, `referer`, `accept-language`) and the device token, but
8
+ * keeps the request-shape markers (`x-requested-with`, `x-codebuddy-request`)
9
+ * the reference sends on every call regardless of transport — see the CLI
10
+ * branches in each provider's `*-shared.ts`.
12
11
  *
13
- * The SDK fingerprint is pinned, not host-derived. Both references pin a fixed
14
- * set (codebuddy2api pins Linux/x64/v24.21.0); this gateway pins the macOS set
15
- * instead, so every CLI dispatch presents one consistent client fingerprint no
16
- * matter which machine the gateway runs on. A host-derived fingerprint would
17
- * advertise whatever OS the process happens to run under — a value no upstream
18
- * risk model has seen for this client brand, and an easy outlier to key on.
12
+ * The CLI's cloud chat transport is axios (`RestOperations`), not the OpenAI
13
+ * Node SDK, so it sends **no** `x-stainless-*` fingerprint. The reference's
14
+ * chat request helper sets only `Content-Type`, `Accept`, and `Authorization`
15
+ * before the conversation/agent/identity headers are injected; the stainless
16
+ * set belongs to the SDK-backed secondary clients, not to CodeBuddy chat.
19
17
  */
20
18
 
21
- /** OpenAI Node SDK 6.25.0 `x-stainless-*` fingerprint; both references agree. */
22
- const STAINLESS_PACKAGE_VERSION = "6.25.0";
23
-
24
- /**
25
- * The pinned Node runtime the fingerprint claims. Held constant across
26
- * dispatches: a drifting `process.version` would advertise a different Node
27
- * build per deployment, which is not what one installed client looks like.
28
- */
29
- const STAINLESS_RUNTIME_VERSION = "v24.21.0";
30
-
31
- /**
32
- * The SDK fingerprint headers.
33
- *
34
- * `x-stainless-timeout` is in the hub only and `x-stainless-retry-count` is in
35
- * both; the SDK sends both, so both go out. The OS/arch pair is the pinned
36
- * macOS fingerprint rather than this process's host.
37
- */
38
- export function buddyStainlessHeaders(): Record<string, string> {
39
- return {
40
- "x-stainless-lang": "js",
41
- "x-stainless-package-version": STAINLESS_PACKAGE_VERSION,
42
- "x-stainless-os": "MacOS",
43
- "x-stainless-arch": "x64",
44
- "x-stainless-runtime": "node",
45
- "x-stainless-runtime-version": STAINLESS_RUNTIME_VERSION,
46
- "x-stainless-retry-count": "0",
47
- "x-stainless-timeout": "1200",
48
- };
49
- }
50
-
51
19
  /**
52
20
  * The trace family the CLI carries as a child span.
53
21
  *
@@ -69,13 +37,18 @@ export function buddyCliTraceHeaders(
69
37
  /**
70
38
  * The full CLI identity envelope, minus what each caller already supplies.
71
39
  *
72
- * The caller keeps ownership of `User-Agent`, `X-IDE-*`, `X-Domain`, and the
73
- * conversation family, because those vary by provider and realm: only the
74
- * headers that are the same for every CLI dispatch are built here.
40
+ * The caller keeps ownership of `User-Agent`, `X-IDE-*`, `X-Domain`, the
41
+ * conversation family, and the OAuth identity headers; only the headers that
42
+ * are the same for every CLI dispatch are built here.
43
+ *
44
+ * No `x-stainless-*` fingerprint: the CLI's chat transport is axios, not the
45
+ * OpenAI Node SDK. `X-Private-Data` is added by the caller only when the
46
+ * dispatch is actually private — the reference never sends it as `false`.
75
47
  */
76
48
  export function buddyCliHeaders(args: {
77
49
  readonly userId: string;
78
50
  readonly enterpriseId?: string | undefined;
51
+ readonly privateData?: boolean;
79
52
  }): Record<string, string> {
80
53
  const enterpriseId =
81
54
  args.enterpriseId !== undefined && args.enterpriseId.trim().length > 0
@@ -89,12 +62,7 @@ export function buddyCliHeaders(args: {
89
62
  // of the three, so "other" is the honest value rather than a guess.
90
63
  "X-Agent-Runtime": "other",
91
64
  "X-User-Id": args.userId,
92
- // The reference sends the flag either way, `true` only for an enterprise
93
- // id. A personal account stays `false`; an enterprise account flips to
94
- // `true` and names the enterprise, because the two travel together — a
95
- // `true` with no id, or an id under `false`, is a combination no real
96
- // client produces.
97
- "X-Private-Data": enterpriseId === undefined ? "false" : "true",
65
+ ...(args.privateData === true ? { "X-Private-Data": "true" } : {}),
98
66
  ...(enterpriseId === undefined
99
67
  ? {}
100
68
  : {
@@ -104,6 +72,5 @@ export function buddyCliHeaders(args: {
104
72
  // reads both.
105
73
  "X-Tenant-Id": enterpriseId,
106
74
  }),
107
- ...buddyStainlessHeaders(),
108
75
  };
109
76
  }
@@ -1,6 +1,8 @@
1
1
  import type { ProviderDispatchContext } from "../../provider-contracts";
2
2
  import { createHash } from "node:crypto";
3
3
  import { decodeJwtPayload } from "../../authentication/oauth-flow-store";
4
+ import { buddyAccountUid } from "./buddy-oauth-shared";
5
+ import type { CanonicalRequest } from "../../../protocol/canonical-model";
4
6
 
5
7
  /**
6
8
  * Which upstream client a buddy provider presents itself as.
@@ -41,8 +43,17 @@ export function resolveBuddyIdentity(
41
43
  * The reference CLI sends the literal `anonymous` when it has no uid rather
42
44
  * than omitting the header, so an unauthenticated dispatch still looks like a
43
45
  * client rather than like a caller that forgot a header.
46
+ *
47
+ * When the credential carries a JWT, the `sub` claim is the upstream uid and
48
+ * wins over the gateway's internal account id — the two can differ after an
49
+ * import, and the channel check keys on the upstream identity. Opaque API keys
50
+ * carry no identity, so the internal account id is the fallback.
44
51
  */
45
52
  export function buddyUserId(context?: ProviderDispatchContext): string {
53
+ const secret = context?.credential?.secret;
54
+ const token = secret ? new TextDecoder().decode(secret).trim() : "";
55
+ const uid = buddyAccountUid(token);
56
+ if (uid !== undefined) return uid;
46
57
  const accountId = context?.credential.account_id;
47
58
  return accountId !== undefined && accountId.length > 0 ? accountId : "anonymous";
48
59
  }
@@ -142,3 +153,78 @@ export function materializeBuddyDeviceBinding(
142
153
  const derived = createHash("sha256").update(`wb2a:qimei36:${accountId}`).digest("hex").slice(0, 32);
143
154
  return { ...(authState ?? {}), qimei36: derived };
144
155
  }
156
+
157
+ /**
158
+ * The OAuth identity header family the reference ships on every cloud API call
159
+ * (`runIdentityHeaders`): `X-User-Id` plus the base64 `X-Userinfo` envelope and
160
+ * the auth-method / id-source markers.
161
+ *
162
+ * The JWT `sub` is the uid; the base64 envelope mirrors the reference exactly:
163
+ * `{ uin, owner_uin?, id_source?, token_source? }` — one leg per identity
164
+ * field that exists, so a personal account sends `{uin}` while an enterprise
165
+ * account adds `owner_uin`. `X-Auth-Method` / `X-Id-Source` are only sent when
166
+ * the operator pinned them in `auth_state` (there is no reliable source to
167
+ * invent them from). An opaque API key carries no uid and yields nothing.
168
+ */
169
+ export function buddyOAuthIdentityHeaders(
170
+ context?: ProviderDispatchContext,
171
+ ): Record<string, string> {
172
+ const secret = context?.credential?.secret;
173
+ const token = secret ? new TextDecoder().decode(secret).trim() : "";
174
+ const uid = buddyAccountUid(token) ?? context?.credential.account_id ?? "";
175
+ if (uid.length === 0) return {};
176
+ const enterpriseId = buddyEnterprise(context);
177
+ const state = context?.credential.auth_state;
178
+ const idSource =
179
+ typeof state?.["idSource"] === "string" && (state["idSource"] as string).trim().length > 0
180
+ ? (state["idSource"] as string).trim()
181
+ : undefined;
182
+ const method =
183
+ typeof state?.["authMethod"] === "string" && (state["authMethod"] as string).trim().length > 0
184
+ ? (state["authMethod"] as string).trim()
185
+ : undefined;
186
+ const headers: Record<string, string> = { "X-User-Id": uid };
187
+ if (method !== undefined) headers["X-Auth-Method"] = method;
188
+ if (idSource !== undefined) headers["X-Id-Source"] = idSource;
189
+ if (enterpriseId !== undefined || idSource !== undefined || method !== undefined) {
190
+ const info: Record<string, string> = { uin: uid };
191
+ if (enterpriseId !== undefined) info["owner_uin"] = enterpriseId;
192
+ if (idSource !== undefined) info["id_source"] = idSource;
193
+ if (method !== undefined) info["token_source"] = method;
194
+ headers["X-Userinfo"] = Buffer.from(JSON.stringify(info), "utf-8").toString("base64");
195
+ }
196
+ return headers;
197
+ }
198
+
199
+ /**
200
+ * Whether this dispatch is in the reference's private-data mode. The CLI only
201
+ * sends `X-Private-Data: true` while the session is private; otherwise the
202
+ * header is deleted, never sent as `false`. The gateway has no session-level
203
+ * private flag, so the operator pins one per account in `auth_state.privateData`.
204
+ */
205
+ export function buddyPrivateData(context?: ProviderDispatchContext): boolean {
206
+ return context?.credential.auth_state?.["privateData"] === true;
207
+ }
208
+
209
+ /**
210
+ * The effective agent purpose for one dispatch, matching the reference's
211
+ * `getEffectiveAgentPurpose` behavior as closely as the gateway can:
212
+ *
213
+ * - `PERSONAL_AGENT_ROLE` set → `person_agent` (same env the CLI reads);
214
+ * - otherwise an inbound `x-agent-purpose` header is preserved (the caller
215
+ * already stated a purpose — same shape the reference passes through);
216
+ * - otherwise the header is omitted. The reference does not invent `conversation`.
217
+ */
218
+ export function buddyAgentPurpose(
219
+ context?: ProviderDispatchContext,
220
+ request?: CanonicalRequest,
221
+ ): string | undefined {
222
+ if (process.env.PERSONAL_AGENT_ROLE && process.env.PERSONAL_AGENT_ROLE.trim().length > 0) {
223
+ return "person_agent";
224
+ }
225
+ const inbound = context?.request_headers?.["x-agent-purpose"]?.trim();
226
+ if (inbound !== undefined && inbound.length > 0) return inbound;
227
+ const fromRequest = request?.metadata?.["agent_purpose"];
228
+ if (typeof fromRequest === "string" && fromRequest.trim().length > 0) return fromRequest.trim();
229
+ return undefined;
230
+ }
@@ -120,7 +120,7 @@ export function buddyAccountUid(accessToken: string): string | undefined {
120
120
  * Falls back to `undefined` when the token carries no usable identity, letting
121
121
  * the console keep the operator-supplied label.
122
122
  */
123
- export function buddyAccountLabel(accessToken: string): string | undefined {
123
+ function buddyAccountLabel(accessToken: string): string | undefined {
124
124
  const claims = decodeJwtPayload(accessToken);
125
125
  if (!claims) return undefined;
126
126
  const email = nonEmptyTrimmedString(claims.email) ?? nonEmptyTrimmedString(claims.preferred_username);
@@ -48,8 +48,7 @@ function isAgentPromptText(text: string): boolean {
48
48
  );
49
49
  }
50
50
 
51
- const CODEBUDDY_CN_NEUTRAL_PROMPT =
52
- "You are a helpful AI assistant that helps with software engineering tasks.";
51
+ const CODEBUDDY_CN_NEUTRAL_PROMPT = "You are a helpful assistant.";
53
52
 
54
53
  function flattenContent(content: unknown): string {
55
54
  if (typeof content === "string") return content;
@@ -51,22 +51,11 @@ export const CODEBUDDY_BASE_URL = providerBaseUrl("cb");
51
51
  *
52
52
  * The wire contract is that the request *opens* with a `system` turn (code
53
53
  * `11128`); the gateway replaces any caller `system`/`developer` turn with this
54
- * fixed prompt. The text is the CodeBuddy CLI's own leading prompt — the same
55
- * one the reference client (and the donor gateway's `prepend` prompt mode)
56
- * sends — so a proxied request is byte-faithful to an official client rather
57
- * than a neutral stand-in.
58
- *
59
- * Keeping the official identity is forward-compatible: the upstream is not
60
- * observed to validate this text today, but a proxy that claims the real
61
- * client's identity cannot be caught out if it starts to. A previous neutral
62
- * persona ("You are a pragmatic and direct software engineering assistant…")
63
- * worked, but diverged from every request the official CLI emits.
54
+ * fixed prompt. Deliberately neutral: a simple helpful-assistant persona with
55
+ * no client/CLI branding, kept minimal so the text reads naturally to any
56
+ * model and does not advertise a channel identity upstream.
64
57
  */
65
- export const CODEBUDDY_SYSTEM_PROMPT =
66
- "You are CodeBuddy Code.\n\n" +
67
- "You are an interactive CLI tool that helps users with software engineering tasks. " +
68
- "Use the instructions below and the tools available to you to assist the user. " +
69
- "Your main goal is to follow the USER's instructions at each message, denoted by the <user_query> tag.";
58
+ export const CODEBUDDY_SYSTEM_PROMPT = "You are a helpful assistant.";
70
59
 
71
60
  function codeBuddyIntlPrePayload(
72
61
  payload: Record<string, unknown>,