@opengeni/worker-bundle 2.0.1 → 2.0.2-canary.38686408778001

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 (379) hide show
  1. package/dist/activities/agent-run-admission.d.ts +1 -12
  2. package/dist/activities/agent-turn/admission.d.ts +88 -10
  3. package/dist/activities/agent-turn/agent-build.d.ts +14 -3
  4. package/dist/activities/agent-turn/claim.d.ts +4 -1
  5. package/dist/activities/agent-turn/claude-core.d.ts +195 -0
  6. package/dist/activities/agent-turn/code-search.d.ts +60 -0
  7. package/dist/activities/agent-turn/codex-capacity.d.ts +3 -0
  8. package/dist/activities/agent-turn/codex-core-capacity.d.ts +37 -0
  9. package/dist/activities/agent-turn/codex-core-claim.d.ts +40 -0
  10. package/dist/activities/agent-turn/codex-core-errors.d.ts +102 -0
  11. package/dist/activities/agent-turn/codex-core-failover.d.ts +15 -0
  12. package/dist/activities/agent-turn/codex-core-requests.d.ts +28 -0
  13. package/dist/activities/agent-turn/codex-core-settlement.d.ts +77 -0
  14. package/dist/activities/agent-turn/codex-credit-policy.d.ts +30 -0
  15. package/dist/activities/agent-turn/codex-plan-entitlement.d.ts +105 -0
  16. package/dist/activities/agent-turn/codex-usage-policy.d.ts +2 -0
  17. package/dist/activities/agent-turn/codex.d.ts +2 -19
  18. package/dist/activities/agent-turn/compaction-interruption.d.ts +32 -0
  19. package/dist/activities/agent-turn/compaction-prep.d.ts +30 -1
  20. package/dist/activities/agent-turn/credential-leases.d.ts +64 -37
  21. package/dist/activities/agent-turn/credential-restriction.d.ts +3 -0
  22. package/dist/activities/agent-turn/errors.d.ts +172 -28
  23. package/dist/activities/agent-turn/failure-settlement.d.ts +10 -43
  24. package/dist/activities/agent-turn/final-reply.d.ts +18 -0
  25. package/dist/activities/agent-turn/finalization-monitor.d.ts +7 -2
  26. package/dist/activities/agent-turn/finalization.d.ts +2 -0
  27. package/dist/activities/agent-turn/github-repository-bindings.d.ts +2 -0
  28. package/dist/activities/agent-turn/governance-model.d.ts +13 -1
  29. package/dist/activities/agent-turn/history-sink.d.ts +3 -1
  30. package/dist/activities/agent-turn/history.d.ts +2 -0
  31. package/dist/activities/agent-turn/input-wait-reply.d.ts +76 -0
  32. package/dist/activities/agent-turn/meaningful-output.d.ts +9 -0
  33. package/dist/activities/agent-turn/media-artifacts.d.ts +5 -3
  34. package/dist/activities/agent-turn/model-call-admission.d.ts +15 -0
  35. package/dist/activities/agent-turn/model-usage.d.ts +56 -14
  36. package/dist/activities/agent-turn/model-wire-dispatch.d.ts +15 -0
  37. package/dist/activities/agent-turn/optional-repositories.d.ts +59 -0
  38. package/dist/activities/agent-turn/prompt-tool-availability.d.ts +17 -0
  39. package/dist/activities/agent-turn/provider-dispatch-barrier.d.ts +12 -1
  40. package/dist/activities/agent-turn/provider-recovery-copy.d.ts +24 -0
  41. package/dist/activities/agent-turn/provider-recovery-metrics.d.ts +18 -0
  42. package/dist/activities/agent-turn/provider-recovery-policy.d.ts +6 -0
  43. package/dist/activities/agent-turn/quiescence.d.ts +6 -7
  44. package/dist/activities/agent-turn/recovery-warning.d.ts +6 -5
  45. package/dist/activities/agent-turn/refresh-credentials.d.ts +6 -0
  46. package/dist/activities/agent-turn/run-credentials.d.ts +9 -5
  47. package/dist/activities/agent-turn/run.d.ts +27 -2
  48. package/dist/activities/agent-turn/sandbox-establish.d.ts +1 -0
  49. package/dist/activities/agent-turn/sandbox-provision.d.ts +25 -1
  50. package/dist/activities/agent-turn/sandbox-route.d.ts +3 -0
  51. package/dist/activities/agent-turn/sandbox-runtime.d.ts +1 -1
  52. package/dist/activities/agent-turn/secret-resolver.d.ts +64 -0
  53. package/dist/activities/agent-turn/session-title.d.ts +60 -3
  54. package/dist/activities/agent-turn/session-usage-custody.d.ts +66 -0
  55. package/dist/activities/agent-turn/skill-checkout.d.ts +25 -6
  56. package/dist/activities/agent-turn/skill-read.d.ts +70 -2
  57. package/dist/activities/agent-turn/skill-search.d.ts +2 -0
  58. package/dist/activities/agent-turn/skill-tools.d.ts +41 -4
  59. package/dist/activities/agent-turn/skill-transfer.d.ts +18 -6
  60. package/dist/activities/agent-turn/stream-attempt.d.ts +6 -3
  61. package/dist/activities/agent-turn/subscription-capacity-arming.d.ts +41 -0
  62. package/dist/activities/agent-turn/subscription-core-capacity.d.ts +86 -0
  63. package/dist/activities/agent-turn/subscription-core-failover.d.ts +69 -0
  64. package/dist/activities/agent-turn/subscription-core-placed.d.ts +14 -0
  65. package/dist/activities/agent-turn/subscription-core-requests.d.ts +109 -0
  66. package/dist/activities/agent-turn/subscription-core-settlement.d.ts +112 -0
  67. package/dist/activities/agent-turn/subscription-lease.d.ts +44 -0
  68. package/dist/activities/agent-turn/subscription-serving-capacity.d.ts +6 -0
  69. package/dist/activities/agent-turn/subscription-serving-catalog.d.ts +13 -0
  70. package/dist/activities/agent-turn/subscription-serving-claim.d.ts +30 -0
  71. package/dist/activities/agent-turn/subscription-serving-providers.d.ts +2 -0
  72. package/dist/activities/agent-turn/tool-environment.d.ts +30 -6
  73. package/dist/activities/agent-turn/tool-policy.d.ts +55 -3
  74. package/dist/activities/agent-turn/turn-context.d.ts +104 -5
  75. package/dist/activities/agent-turn/web-search.d.ts +57 -0
  76. package/dist/activities/agent-turn/xai-core.d.ts +96 -0
  77. package/dist/activities/automations.d.ts +3 -1
  78. package/dist/activities/browser-deadline-checkpoint.d.ts +34 -0
  79. package/dist/activities/capabilities.d.ts +8 -20
  80. package/dist/activities/codemode-dispatcher.d.ts +20 -3
  81. package/dist/activities/codex-capacity.d.ts +1 -56
  82. package/dist/activities/codex-image-generation.d.ts +49 -3
  83. package/dist/activities/common.d.ts +3 -1
  84. package/dist/activities/context-compaction.d.ts +41 -2
  85. package/dist/activities/environment.d.ts +1 -19
  86. package/dist/activities/gmail-files.d.ts +50 -0
  87. package/dist/activities/goals.d.ts +1 -9
  88. package/dist/activities/incident-telemetry-authority.d.ts +5 -2
  89. package/dist/activities/incident-telemetry-preflight.d.ts +10 -3
  90. package/dist/activities/knowledge-indexing.d.ts +19 -0
  91. package/dist/activities/mcp-account-routes.d.ts +2 -21
  92. package/dist/activities/model-call-fact-reconciler.d.ts +34 -0
  93. package/dist/activities/open-suffix-resume.d.ts +15 -0
  94. package/dist/activities/parent-wake.d.ts +17 -12
  95. package/dist/activities/programmatic-approvals.d.ts +10 -0
  96. package/dist/activities/requester-unavailable-receipt.d.ts +8 -0
  97. package/dist/activities/retained-screenshots.d.ts +7 -2
  98. package/dist/activities/run-credential-renewal.d.ts +1 -0
  99. package/dist/activities/run-credentials.d.ts +16 -4
  100. package/dist/activities/run-input.d.ts +17 -0
  101. package/dist/activities/sandbox-lease.d.ts +132 -12
  102. package/dist/activities/scheduled-tasks.d.ts +4 -35
  103. package/dist/activities/session-archive.d.ts +58 -0
  104. package/dist/activities/session-state.d.ts +15 -3
  105. package/dist/activities/session-storage.d.ts +44 -0
  106. package/dist/activities/subscription-core-claude-waits.d.ts +2 -0
  107. package/dist/activities/subscription-core-codex-quota.d.ts +25 -0
  108. package/dist/activities/subscription-core-codex-waits.d.ts +153 -0
  109. package/dist/activities/subscription-core-image-operation.d.ts +29 -0
  110. package/dist/activities/subscription-core-usage-recheck.d.ts +49 -0
  111. package/dist/activities/subscription-core-wait-bindings.d.ts +3 -0
  112. package/dist/activities/subscription-core-xai-quota.d.ts +30 -0
  113. package/dist/activities/subscription-core-xai-waits.d.ts +2 -0
  114. package/dist/activities/types.d.ts +68 -5
  115. package/dist/activities/video-generation-admission.d.ts +2 -8
  116. package/dist/activities/video-generation-credential.d.ts +15 -12
  117. package/dist/activities/video-generation-subscription-core.d.ts +70 -0
  118. package/dist/activities/workspace-capture.d.ts +2 -0
  119. package/dist/activities/workspace-credential-provider.d.ts +47 -0
  120. package/dist/activities/xai-auth.d.ts +6 -18
  121. package/dist/activities/xai-image-generation.d.ts +22 -6
  122. package/dist/{activities-control-QA6OLRQY.js → activities-control-NTXZHYET.js} +1552 -2876
  123. package/dist/activities-control-NTXZHYET.js.map +1 -0
  124. package/dist/activities-control.d.ts +64 -4
  125. package/dist/{activities-turn-YVVKCGAK.js → activities-turn-RKRI5GY4.js} +9238 -4392
  126. package/dist/activities-turn-RKRI5GY4.js.map +1 -0
  127. package/dist/activities.d.ts +64 -4
  128. package/dist/artifact-materializer-entry.js +104 -35
  129. package/dist/artifact-materializer-entry.js.map +1 -1
  130. package/dist/artifact-outbox-entry.js +132 -61
  131. package/dist/artifact-outbox-entry.js.map +1 -1
  132. package/dist/browser-deadline-checkpoint-contract.d.ts +2 -0
  133. package/dist/{chunk-GDCLDKSH.js → chunk-24GP3BX5.js} +79 -72
  134. package/dist/chunk-24GP3BX5.js.map +1 -0
  135. package/dist/{chunk-RAMNYSAW.js → chunk-4ER3YXOT.js} +22 -4
  136. package/dist/chunk-4ER3YXOT.js.map +1 -0
  137. package/dist/{chunk-I7HKKMUJ.js → chunk-5NNS4327.js} +734 -58
  138. package/dist/chunk-5NNS4327.js.map +1 -0
  139. package/dist/{chunk-M3NVMF2V.js → chunk-7BIHFUGB.js} +2293 -3956
  140. package/dist/chunk-7BIHFUGB.js.map +1 -0
  141. package/dist/chunk-MVESOYFC.js +3746 -0
  142. package/dist/chunk-MVESOYFC.js.map +1 -0
  143. package/dist/chunk-NQDVJ6RI.js +2823 -0
  144. package/dist/chunk-NQDVJ6RI.js.map +1 -0
  145. package/dist/chunk-O7UPBWXK.js +79 -0
  146. package/dist/chunk-O7UPBWXK.js.map +1 -0
  147. package/dist/chunk-W2QSM5HR.js +414 -0
  148. package/dist/chunk-W2QSM5HR.js.map +1 -0
  149. package/dist/chunk-ZN3XJR33.js +227 -0
  150. package/dist/chunk-ZN3XJR33.js.map +1 -0
  151. package/dist/editable-artifact-outbox-dispatcher.d.ts +12 -1
  152. package/dist/editable-artifact-outbox-service.d.ts +3 -1
  153. package/dist/host-export-pump.d.ts +3 -1
  154. package/dist/host-export.d.ts +2 -2
  155. package/dist/host-export.js +1 -1
  156. package/dist/http.d.ts +1 -1
  157. package/dist/index.d.ts +49 -48
  158. package/dist/index.js +835 -256
  159. package/dist/index.js.map +1 -1
  160. package/dist/internal-maintenance.d.ts +63 -0
  161. package/dist/maintenance-cadence.d.ts +43 -0
  162. package/dist/observability-metrics.d.ts +293 -24
  163. package/dist/onepassword-vault-provider.d.ts +7 -0
  164. package/dist/parent-wake-PCLH7A3Y.js +24 -0
  165. package/dist/parent-wake-PCLH7A3Y.js.map +1 -0
  166. package/dist/personal-github-git-credentials.d.ts +1 -1
  167. package/dist/readiness-checks.d.ts +39 -0
  168. package/dist/retained-process-retry.d.ts +7 -0
  169. package/dist/sandbox-lease-BJYU72N3.js +84 -0
  170. package/dist/sandbox-lease-BJYU72N3.js.map +1 -0
  171. package/dist/sandbox-reaper-contract.d.ts +25 -0
  172. package/dist/sandbox-resume.d.ts +72 -4
  173. package/dist/sandbox-routing.d.ts +4 -2
  174. package/dist/session-event-fanout.d.ts +6 -0
  175. package/dist/site-auth-maintenance-WK3MR2PV.js +12 -0
  176. package/dist/site-auth-maintenance-WK3MR2PV.js.map +1 -0
  177. package/dist/telemetry-scheduler.d.ts +14 -0
  178. package/dist/temporal-runtime-logger.d.ts +22 -0
  179. package/dist/turn-task-queue-reader.d.ts +18 -0
  180. package/dist/turn-worker-activity-telemetry.d.ts +47 -0
  181. package/dist/worker-service-lifecycle.d.ts +12 -0
  182. package/dist/workflow-bundle.js +468 -71
  183. package/dist/workflows/activities.d.ts +1 -1
  184. package/dist/workflows/browser-deadline-checkpoint.d.ts +10 -0
  185. package/dist/workflows/sandbox-reaper.d.ts +10 -1
  186. package/dist/workflows/scheduled-tasks.d.ts +4 -0
  187. package/dist/workflows/session-storage.d.ts +2 -0
  188. package/dist/workflows/session.d.ts +36 -0
  189. package/dist/workflows/site-auth-maintenance.d.ts +2 -1
  190. package/dist/workflows/workflow-wake.d.ts +14 -3
  191. package/dist/workflows.d.ts +3 -1
  192. package/package.json +26 -20
  193. package/src/activities/agent-run-admission.ts +1 -82
  194. package/src/activities/agent-turn/admission.ts +175 -24
  195. package/src/activities/agent-turn/agent-build.ts +226 -145
  196. package/src/activities/agent-turn/claim.ts +363 -64
  197. package/src/activities/agent-turn/claude-core.ts +587 -0
  198. package/src/activities/agent-turn/code-search.ts +275 -0
  199. package/src/activities/agent-turn/codex-capacity.ts +30 -757
  200. package/src/activities/agent-turn/codex-core-capacity.ts +190 -0
  201. package/src/activities/agent-turn/codex-core-claim.ts +83 -0
  202. package/src/activities/agent-turn/codex-core-errors.ts +308 -0
  203. package/src/activities/agent-turn/codex-core-failover.ts +73 -0
  204. package/src/activities/agent-turn/codex-core-requests.ts +86 -0
  205. package/src/activities/agent-turn/codex-core-settlement.ts +263 -0
  206. package/src/activities/agent-turn/codex-credit-policy.ts +247 -0
  207. package/src/activities/agent-turn/codex-plan-entitlement.ts +254 -0
  208. package/src/activities/agent-turn/codex-usage-policy.ts +2 -0
  209. package/src/activities/agent-turn/codex.ts +8 -76
  210. package/src/activities/agent-turn/compaction-interruption.ts +56 -0
  211. package/src/activities/agent-turn/compaction-prep.ts +249 -36
  212. package/src/activities/agent-turn/credential-leases.ts +269 -214
  213. package/src/activities/agent-turn/credential-restriction.ts +14 -0
  214. package/src/activities/agent-turn/errors.ts +1134 -82
  215. package/src/activities/agent-turn/failure-settlement.ts +879 -886
  216. package/src/activities/agent-turn/final-reply.ts +46 -0
  217. package/src/activities/agent-turn/finalization-monitor.ts +17 -5
  218. package/src/activities/agent-turn/finalization.ts +107 -88
  219. package/src/activities/agent-turn/github-repository-bindings.ts +3 -1
  220. package/src/activities/agent-turn/governance-model.ts +90 -22
  221. package/src/activities/agent-turn/history-sink.ts +26 -4
  222. package/src/activities/agent-turn/history.ts +25 -5
  223. package/src/activities/agent-turn/input-wait-reply.ts +139 -0
  224. package/src/activities/agent-turn/knowledge-source-tools.ts +2 -0
  225. package/src/activities/agent-turn/meaningful-output.ts +44 -0
  226. package/src/activities/agent-turn/media-artifacts.ts +3 -1
  227. package/src/activities/agent-turn/model-call-admission.ts +94 -0
  228. package/src/activities/agent-turn/model-usage.ts +299 -233
  229. package/src/activities/agent-turn/model-wire-dispatch.ts +27 -0
  230. package/src/activities/agent-turn/optional-repositories.ts +224 -0
  231. package/src/activities/agent-turn/prompt-tool-availability.ts +27 -0
  232. package/src/activities/agent-turn/provider-dispatch-barrier.ts +22 -0
  233. package/src/activities/agent-turn/provider-recovery-copy.ts +76 -0
  234. package/src/activities/agent-turn/provider-recovery-metrics.ts +64 -0
  235. package/src/activities/agent-turn/provider-recovery-policy.ts +25 -0
  236. package/src/activities/agent-turn/quiescence.ts +7 -7
  237. package/src/activities/agent-turn/recovery-warning.ts +6 -8
  238. package/src/activities/agent-turn/refresh-credentials.ts +44 -0
  239. package/src/activities/agent-turn/run-credentials.ts +124 -76
  240. package/src/activities/agent-turn/run.ts +501 -112
  241. package/src/activities/agent-turn/sandbox-establish.ts +152 -75
  242. package/src/activities/agent-turn/sandbox-provision.ts +54 -1
  243. package/src/activities/agent-turn/sandbox-route.ts +4 -1
  244. package/src/activities/agent-turn/sandbox-runtime.ts +319 -11
  245. package/src/activities/agent-turn/secret-resolver.ts +155 -0
  246. package/src/activities/agent-turn/session-title.ts +177 -12
  247. package/src/activities/agent-turn/session-usage-custody.ts +170 -0
  248. package/src/activities/agent-turn/skill-checkout.ts +111 -24
  249. package/src/activities/agent-turn/skill-install.ts +1 -1
  250. package/src/activities/agent-turn/skill-read.ts +374 -28
  251. package/src/activities/agent-turn/skill-save.ts +35 -7
  252. package/src/activities/agent-turn/skill-search.ts +9 -0
  253. package/src/activities/agent-turn/skill-selection.ts +4 -0
  254. package/src/activities/agent-turn/skill-tools.ts +208 -21
  255. package/src/activities/agent-turn/skill-transfer.ts +68 -23
  256. package/src/activities/agent-turn/stream-attempt.ts +599 -110
  257. package/src/activities/agent-turn/subscription-capacity-arming.ts +81 -0
  258. package/src/activities/agent-turn/subscription-core-capacity.ts +439 -0
  259. package/src/activities/agent-turn/subscription-core-failover.ts +229 -0
  260. package/src/activities/agent-turn/subscription-core-placed.ts +37 -0
  261. package/src/activities/agent-turn/subscription-core-requests.ts +271 -0
  262. package/src/activities/agent-turn/subscription-core-settlement.ts +234 -0
  263. package/src/activities/agent-turn/subscription-lease.ts +140 -0
  264. package/src/activities/agent-turn/subscription-serving-capacity.ts +195 -0
  265. package/src/activities/agent-turn/subscription-serving-catalog.ts +71 -0
  266. package/src/activities/agent-turn/subscription-serving-claim.ts +178 -0
  267. package/src/activities/agent-turn/subscription-serving-providers.ts +15 -0
  268. package/src/activities/agent-turn/tool-environment.ts +384 -292
  269. package/src/activities/agent-turn/tool-policy.ts +104 -4
  270. package/src/activities/agent-turn/tool-result-spill.ts +1 -0
  271. package/src/activities/agent-turn/turn-context.ts +124 -8
  272. package/src/activities/agent-turn/web-search.ts +431 -0
  273. package/src/activities/agent-turn/xai-core.ts +301 -0
  274. package/src/activities/automations.ts +81 -6
  275. package/src/activities/browser-deadline-checkpoint.ts +297 -0
  276. package/src/activities/capabilities.ts +53 -213
  277. package/src/activities/codemode-dispatcher.ts +236 -14
  278. package/src/activities/codex-capacity.ts +27 -380
  279. package/src/activities/codex-image-generation.ts +252 -42
  280. package/src/activities/common.ts +12 -0
  281. package/src/activities/connector-attachments.ts +3 -1
  282. package/src/activities/context-compaction.ts +162 -21
  283. package/src/activities/environment.ts +18 -106
  284. package/src/activities/gmail-files.ts +108 -0
  285. package/src/activities/goals.ts +120 -204
  286. package/src/activities/image-generation-operation.ts +1 -1
  287. package/src/activities/incident-telemetry-authority.ts +80 -50
  288. package/src/activities/incident-telemetry-preflight.ts +27 -15
  289. package/src/activities/knowledge-indexing.ts +287 -17
  290. package/src/activities/knowledge-source-sync.ts +10 -0
  291. package/src/activities/mcp-account-routes.ts +2 -124
  292. package/src/activities/model-call-fact-reconciler.ts +112 -0
  293. package/src/activities/open-suffix-resume.ts +122 -88
  294. package/src/activities/parent-wake.ts +89 -21
  295. package/src/activities/programmatic-approvals.ts +26 -0
  296. package/src/activities/requester-unavailable-receipt.ts +14 -0
  297. package/src/activities/retained-screenshots.ts +135 -24
  298. package/src/activities/run-credential-renewal.ts +13 -1
  299. package/src/activities/run-credentials.ts +61 -19
  300. package/src/activities/run-input.ts +116 -9
  301. package/src/activities/sandbox-lease.ts +1615 -73
  302. package/src/activities/scheduled-tasks.ts +758 -141
  303. package/src/activities/session-archive.ts +382 -0
  304. package/src/activities/session-state.ts +219 -10
  305. package/src/activities/session-storage.ts +124 -0
  306. package/src/activities/site-auth-maintenance.ts +5 -2
  307. package/src/activities/subscription-core-claude-waits.ts +49 -0
  308. package/src/activities/subscription-core-codex-quota.ts +46 -0
  309. package/src/activities/subscription-core-codex-waits.ts +488 -0
  310. package/src/activities/subscription-core-image-operation.ts +126 -0
  311. package/src/activities/subscription-core-usage-recheck.ts +146 -0
  312. package/src/activities/subscription-core-wait-bindings.ts +12 -0
  313. package/src/activities/subscription-core-xai-quota.ts +85 -0
  314. package/src/activities/subscription-core-xai-waits.ts +48 -0
  315. package/src/activities/types.ts +85 -9
  316. package/src/activities/video-generation-admission.ts +1 -36
  317. package/src/activities/video-generation-credential.ts +38 -56
  318. package/src/activities/video-generation-reconciliation.ts +150 -131
  319. package/src/activities/video-generation-subscription-core.ts +180 -0
  320. package/src/activities/workspace-capture.ts +13 -2
  321. package/src/activities/workspace-credential-provider.ts +302 -0
  322. package/src/activities/xai-auth.ts +34 -112
  323. package/src/activities/xai-image-generation.ts +84 -36
  324. package/src/activities-control.ts +8 -0
  325. package/src/activities-turn.ts +5 -0
  326. package/src/activities.ts +17 -0
  327. package/src/activity-services.ts +29 -4
  328. package/src/browser-deadline-checkpoint-contract.ts +5 -0
  329. package/src/editable-artifact-hint-broker.ts +3 -0
  330. package/src/editable-artifact-materializer-service.ts +79 -38
  331. package/src/editable-artifact-materializer-subprocess.ts +47 -2
  332. package/src/editable-artifact-outbox-dispatcher.ts +107 -46
  333. package/src/editable-artifact-outbox-service.ts +55 -25
  334. package/src/github-rest-mcp.ts +1 -1
  335. package/src/host-export-pump.ts +26 -4
  336. package/src/host-export.ts +4 -1
  337. package/src/http.ts +4 -2
  338. package/src/index.ts +222 -282
  339. package/src/internal-maintenance.ts +347 -0
  340. package/src/maintenance-cadence.ts +156 -0
  341. package/src/observability-metrics.ts +1173 -73
  342. package/src/onepassword-vault-provider.ts +11 -0
  343. package/src/personal-github-git-credentials.ts +3 -1
  344. package/src/pr-review-credentials.ts +1 -1
  345. package/src/readiness-checks.ts +113 -0
  346. package/src/retained-process-retry.ts +36 -0
  347. package/src/sandbox-reaper-contract.ts +33 -0
  348. package/src/sandbox-resume.ts +444 -73
  349. package/src/sandbox-routing.ts +230 -75
  350. package/src/session-event-fanout.ts +23 -0
  351. package/src/telemetry-scheduler.ts +53 -0
  352. package/src/temporal-runtime-logger.ts +44 -0
  353. package/src/turn-task-queue-reader.ts +110 -0
  354. package/src/turn-worker-activity-telemetry.ts +209 -0
  355. package/src/worker-service-lifecycle.ts +54 -1
  356. package/src/workflows/activities.ts +16 -1
  357. package/src/workflows/browser-deadline-checkpoint.ts +55 -0
  358. package/src/workflows/file-upload-reaper.ts +2 -0
  359. package/src/workflows/sandbox-reaper.ts +88 -0
  360. package/src/workflows/scheduled-tasks.ts +26 -13
  361. package/src/workflows/session-storage.ts +19 -0
  362. package/src/workflows/session.ts +238 -33
  363. package/src/workflows/site-auth-maintenance.ts +2 -1
  364. package/src/workflows/workflow-wake.ts +26 -4
  365. package/src/workflows.ts +7 -0
  366. package/dist/activities/agent-turn/xai-capacity.d.ts +0 -2
  367. package/dist/activities/codex-fleet-shadow.d.ts +0 -74
  368. package/dist/activities/codex-rotation.d.ts +0 -200
  369. package/dist/activities/xai-quota.d.ts +0 -3
  370. package/dist/activities-control-QA6OLRQY.js.map +0 -1
  371. package/dist/activities-turn-YVVKCGAK.js.map +0 -1
  372. package/dist/chunk-GDCLDKSH.js.map +0 -1
  373. package/dist/chunk-I7HKKMUJ.js.map +0 -1
  374. package/dist/chunk-M3NVMF2V.js.map +0 -1
  375. package/dist/chunk-RAMNYSAW.js.map +0 -1
  376. package/src/activities/agent-turn/xai-capacity.ts +0 -257
  377. package/src/activities/codex-fleet-shadow.ts +0 -306
  378. package/src/activities/codex-rotation.ts +0 -685
  379. package/src/activities/xai-quota.ts +0 -35
@@ -1,12 +1 @@
1
- import { type Settings } from "@opengeni/config";
2
- import type { ControlActivityServices } from "./types.js";
3
- export type AgentRunAdmissionDenial = "insufficient_credits" | "monthly_model_cost_limit" | "monthly_agent_run_limit";
4
- /** One worker-side admission boundary for service-authored agent runs. */
5
- export declare function agentRunAdmissionDenial(services: Pick<ControlActivityServices, "db" | "entitlements"> & {
6
- settings: Settings;
7
- }, input: {
8
- accountId: string;
9
- workspaceId: string;
10
- model: string;
11
- requestedAgentRuns: number;
12
- }): Promise<AgentRunAdmissionDenial | null>;
1
+ export { agentRunAdmissionDenial, type AgentRunAdmissionDenial } from "@opengeni/core";
@@ -1,19 +1,12 @@
1
1
  import { resolveTurnExecutionPolicyV1, type Settings } from "@opengeni/config";
2
2
  import type { TurnActivityServices as ActivityServices } from "../types.js";
3
- import { type SessionEvent, type SessionTurn, type ToolAuthNeededPayload, type TurnExecutionPolicyV1, type XaiProviderAccountAuthoritySnapshotV1 } from "@opengeni/contracts";
3
+ import { type AllowanceExhaustedRefusal, type SessionEvent, type SessionUsageLimitReachedRefusal, type SessionTurn, type ToolAuthNeededPayload, type TurnExecutionPolicyV1 } from "@opengeni/contracts";
4
4
  export declare class WorkspaceHumanInputDisabledError extends Error {
5
5
  constructor(kind: "resume" | "interruption");
6
6
  }
7
7
  export declare function assertWorkspaceHumanInputAllowed(enabled: boolean, kind: "resume" | "interruption", attempted: boolean): void;
8
8
  /** Broad personal lookup is allowed only for a direct human/API command. */
9
9
  export declare function credentialSubjectIdForTurnInitiator(turn: Pick<SessionTurn, "source" | "initiator" | "initiatorContext">): string | undefined;
10
- export declare function xaiCatalogReadinessAuthority(turn: {
11
- initiatingHumanSubjectId: string | null;
12
- xaiProviderAccountAuthoritySnapshot: XaiProviderAccountAuthoritySnapshotV1;
13
- }, directCredentialSubjectId: string | undefined): {
14
- subjectId: string;
15
- authoritySnapshot: XaiProviderAccountAuthoritySnapshotV1;
16
- } | null;
17
10
  /**
18
11
  * Direct authenticated-human work is the persisted human source with subject
19
12
  * authority and no inherited agent or legacy provenance. Use this complete
@@ -62,6 +55,91 @@ export declare function stableInteractionInterventionUuid(namespace: string, ses
62
55
  */
63
56
  export declare class BudgetExhaustedError extends Error {
64
57
  readonly serializedRunState: string | null;
65
- constructor(message: string, serializedRunState: string | null);
58
+ readonly allowance: AllowanceRefusal | null;
59
+ /** A reached per-task usage limit: its own stop marker, never credits. */
60
+ readonly sessionUsageLimit: SessionUsageLimitReachedRefusal | null;
61
+ constructor(message: string, serializedRunState: string | null, allowance?: AllowanceRefusal | null,
62
+ /** A reached per-task usage limit: its own stop marker, never credits. */
63
+ sessionUsageLimit?: SessionUsageLimitReachedRefusal | null);
64
+ }
65
+ /** The task's root usage limit is reached: a recoverable non-failure stop. */
66
+ export declare class SessionUsageLimitReachedError extends Error {
67
+ readonly refusal: SessionUsageLimitReachedRefusal;
68
+ readonly code = "session_usage_limit_reached";
69
+ constructor(refusal: SessionUsageLimitReachedRefusal);
66
70
  }
67
- export declare function ensureRunAllowed(settings: Settings, db: ActivityServices["db"], accountId: string, workspaceId: string, isExternallyBilledTurn: boolean, entitlements?: ActivityServices["entitlements"], chargesOpenGeniCredits?: boolean, countsTowardTokenCap?: boolean): Promise<void>;
71
+ /**
72
+ * The terminal events of a usage-limit stop: a completed (non-failed) turn
73
+ * with its own `segmentLimit` and the typed refusal, then an idle session.
74
+ * Deliberately no `usage.exhausted` (an allowance/webhook contract) and no
75
+ * `budget_exhausted` marker, so no client offers "Add credits".
76
+ */
77
+ export declare function sessionUsageLimitStopEvents(refusal: SessionUsageLimitReachedRefusal, extra?: {
78
+ detail?: string;
79
+ }): ({
80
+ type: "turn.completed";
81
+ payload: {
82
+ status?: never;
83
+ output: string;
84
+ segmentLimit: "session_usage_limit";
85
+ detail?: string;
86
+ sessionUsageLimit: {
87
+ code: "session_usage_limit_reached";
88
+ basis: "model_api_equivalent_v1";
89
+ rootSessionId: string;
90
+ limitMicros: number;
91
+ usedMicros: number;
92
+ message: string;
93
+ };
94
+ };
95
+ } | {
96
+ type: "session.status.changed";
97
+ payload: {
98
+ status: string;
99
+ };
100
+ })[];
101
+ /**
102
+ * Refuse a new model request once the task's root usage limit is reached.
103
+ * Reads the latest durable counter; a read failure throws
104
+ * `SessionUsageLimitUnavailableError` (never treated as unlimited).
105
+ */
106
+ export declare function ensureSessionUsageLimitAllows(db: ActivityServices["db"], input: {
107
+ accountId: string;
108
+ workspaceId: string;
109
+ sessionId: string;
110
+ }): Promise<void>;
111
+ /**
112
+ * The task usage limit alone, for a paid request that has no allowance
113
+ * boundary of its own (the Codex remote compaction request). A reached limit
114
+ * becomes the same typed between-request stop as any other call; an
115
+ * unreadable state still throws `SessionUsageLimitUnavailableError`.
116
+ */
117
+ export declare function ensureSessionUsageLimitAllowsBetweenModelCalls(db: ActivityServices["db"], input: {
118
+ accountId: string;
119
+ workspaceId: string;
120
+ sessionId: string;
121
+ }): Promise<void>;
122
+ export type AllowanceRefusal = AllowanceExhaustedRefusal;
123
+ /** Account allowance exhaustion is recoverable state, never a provider failure. */
124
+ export declare class AllowanceExhaustedError extends Error {
125
+ readonly refusal: AllowanceRefusal;
126
+ readonly code = "allowance_exhausted";
127
+ constructor(refusal: AllowanceRefusal);
128
+ }
129
+ /** Revalidate between paid calls without replaying provider work or reserving credits. */
130
+ export declare function ensureRunAllowedBetweenModelCalls(input: {
131
+ settings: Settings;
132
+ db: ActivityServices["db"];
133
+ accountId: string;
134
+ workspaceId: string;
135
+ isExternallyBilledTurn: boolean;
136
+ entitlements?: ActivityServices["entitlements"];
137
+ chargesOpenGeniCredits: boolean;
138
+ countsTowardTokenCap: boolean;
139
+ initiatingHumanSubjectId: string | null;
140
+ modelId?: string;
141
+ /** The session whose task root usage limit gates this request. */
142
+ sessionId?: string;
143
+ serializedRunState?: () => string | null;
144
+ }): Promise<number | undefined>;
145
+ export declare function ensureRunAllowed(settings: Settings, db: ActivityServices["db"], accountId: string, workspaceId: string, isExternallyBilledTurn: boolean, entitlements?: ActivityServices["entitlements"], chargesOpenGeniCredits?: boolean, countsTowardTokenCap?: boolean, initiatingHumanSubjectId?: string | null, modelId?: string, sessionId?: string): Promise<number | undefined>;
@@ -1,4 +1,4 @@
1
- import { type AttemptConnectorActionBinding, type BuildAgentOptions, type ConnectorActionPolicyHooks, type SandboxFileDownload } from "@opengeni/runtime";
1
+ import { type AgentPromptToolAvailability, type AttemptConnectorActionBinding, type BuildAgentOptions, type ConnectorActionPolicyHooks, type SandboxFileDownload } from "@opengeni/runtime";
2
2
  import { type Settings } from "@opengeni/config";
3
3
  import { type CodexRequestContext } from "@opengeni/codex";
4
4
  import type { TurnActivityServices as ActivityServices, RunAgentTurnInput } from "../types.js";
@@ -9,9 +9,12 @@ import type { GovernanceModelOk } from "./governance-model.js";
9
9
  import type { CompactionPrepOk } from "./compaction-prep.js";
10
10
  import type { runtimeResourcesForTurn } from "./file-resources.js";
11
11
  import type { sandboxArtifactRuntimeAdmission } from "./sandbox-route.js";
12
- import type { loadWorkspaceEnvironmentForRunWithCredentials, sandboxEnvironmentForRun } from "../environment.js";
12
+ import type { sandboxEnvironmentForRun } from "../environment.js";
13
13
  import type { AttemptIdentityState, EventingState, ProviderTurnState, SandboxRuntimeState } from "./turn-context.js";
14
+ import { type AttemptVaultAccess } from "./secret-resolver.js";
14
15
  export type BuildTurnAgentDeps = {
16
+ /** Connected-vault providers and the shared read budget for this attempt. */
17
+ vaultAccess: AttemptVaultAccess;
15
18
  skillCatalog: NonNullable<BuildAgentOptions["skillCatalog"]>;
16
19
  mcpServers: Settings["mcpServers"];
17
20
  input: RunAgentTurnInput;
@@ -43,14 +46,15 @@ export type BuildTurnAgentDeps = {
43
46
  supportsImageInput: GovernanceModelOk["supportsImageInput"];
44
47
  agentHumanInputEnabled: GovernanceModelOk["agentHumanInputEnabled"];
45
48
  workspaceAgentInstructions: GovernanceModelOk["workspaceAgentInstructions"];
49
+ workspaceAgentIdentity: GovernanceModelOk["workspaceAgentIdentity"];
46
50
  workspaceGovernance: GovernanceModelOk["workspaceGovernance"];
47
51
  structuredWorkspacePolicyActive: GovernanceModelOk["structuredWorkspacePolicyActive"];
52
+ workspaceCreditModelsAllowed: GovernanceModelOk["workspaceCreditModelsAllowed"];
48
53
  workspaceMemory: GovernanceModelOk["workspaceMemory"];
49
54
  rigVersion: GovernanceModelOk["rigVersion"];
50
55
  rigName: GovernanceModelOk["rigName"];
51
56
  buildCompanyBrainContributionReceiptFor: GovernanceModelOk["buildCompanyBrainContributionReceiptFor"];
52
57
  promptCacheKey: CompactionPrepOk["promptCacheKey"];
53
- workspaceVariableSet: Awaited<ReturnType<typeof loadWorkspaceEnvironmentForRunWithCredentials>>;
54
58
  runtimeResources: ReturnType<typeof runtimeResourcesForTurn>;
55
59
  sandboxEnvironment: Record<string, string>;
56
60
  sandboxArtifactRuntime: ReturnType<typeof sandboxArtifactRuntimeAdmission>;
@@ -63,6 +67,13 @@ export type BuildTurnAgentDeps = {
63
67
  connectorActionPolicy: ConnectorActionPolicyHooks;
64
68
  trigger: ClaimTurnOk["trigger"];
65
69
  preparationIndependentToolNames: readonly string[];
70
+ /** The attempt's tool catalog includes the Jev-backed code_search tool. */
71
+ codeSearchAvailable: boolean;
72
+ /**
73
+ * Frozen clause availability for the modular instructions; undefined for
74
+ * sessions without an agent configuration. Rendering input only.
75
+ */
76
+ promptToolAvailability?: AgentPromptToolAvailability | undefined;
66
77
  videoGenerationAcceptancesByCallId: Map<string, {
67
78
  operationId: string;
68
79
  requestDigest: string;
@@ -1,3 +1,4 @@
1
+ import { type ServingAttempt } from "./subscription-serving-claim.js";
1
2
  import { getSessionEvent, getHumanInputResumeForEvent, getInteractionInterventionResumeForEvent, requireSession, type ApiIntegrationRuntime, type SessionTurnForExecution } from "@opengeni/db";
2
3
  import { type Settings } from "@opengeni/config";
3
4
  import { currentActivityContext } from "../streaming.js";
@@ -38,8 +39,10 @@ export type ClaimTurnOk = {
38
39
  credentialSubjectId: string | undefined;
39
40
  fileAuthoritySubjectId: string | null;
40
41
  capabilitySettings: Settings;
41
- codexAppsCredentialId: string | null;
42
+ /** The core Codex Apps designation (enabled Codex cutover only). */
43
+ codexAppsCoreConnectionId?: string | null;
42
44
  turnExecutionPolicy: TurnExecutionPolicyV1;
45
+ servingAttempt?: ServingAttempt;
43
46
  trigger: NonNullable<Awaited<ReturnType<typeof getSessionEvent>>>;
44
47
  humanInputResume: Awaited<ReturnType<typeof getHumanInputResumeForEvent>>;
45
48
  interactionInterventionResume: Awaited<ReturnType<typeof getInteractionInterventionResumeForEvent>>;
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Claude on the shared subscription core (design 5.3, Claude track C1a): the
3
+ * provider-neutral chat placement and request custody bound to Claude, and
4
+ * the turn's route. The route is `core` only after the Claude drained cutover
5
+ * commits its receipt (C3); the legacy Claude path is deleted (C4), so any
6
+ * other route fails closed.
7
+ */
8
+ import { type Database, type SubscriptionCoreClaudeTokenSnapshot } from "@opengeni/db";
9
+ import { type Settings } from "@opengeni/config";
10
+ import type { PreparedUsageRequest } from "@opengeni/runtime";
11
+ import type { CapacityPhaseDeps, CapacityPhaseOutcome } from "./codex-capacity.js";
12
+ import type { ClaudeTurnLease } from "./credential-leases.js";
13
+ import { type CoreTurnPlacementProvider } from "./subscription-core-capacity.js";
14
+ import { type CoreResponseInspector, type CoreSubscriptionRequests } from "./subscription-core-requests.js";
15
+ import { type CoreRefusalBinding } from "./subscription-core-settlement.js";
16
+ import type { SubscriptionCoreTurn } from "./turn-context.js";
17
+ import { type CoreCodexWakeServices } from "../subscription-core-codex-waits.js";
18
+ /** Claude's chat placement on the shared core. */
19
+ export declare const CLAUDE_CORE_TURN_PROVIDER: CoreTurnPlacementProvider;
20
+ /**
21
+ * The Claude capacity phase by the Claude route: `core` places on the shared
22
+ * core; `maintenance` and `legacy` (no committed receipt) fail closed, since
23
+ * the legacy Claude selection is deleted.
24
+ */
25
+ export declare function selectClaudeTurnCapacityByRoute(deps: CapacityPhaseDeps): Promise<CapacityPhaseOutcome>;
26
+ /** One attempt's Claude request custody on the core (unknown outcomes are never replayed). */
27
+ export declare function createCoreClaudeRequests(db: Database, core: SubscriptionCoreTurn, ref: {
28
+ connectionId: string;
29
+ holderId: string;
30
+ generation: number;
31
+ }, execution: {
32
+ attemptId: string;
33
+ executionGeneration: number;
34
+ }, lane: "main" | "title"): {
35
+ reserve(request: import("./subscription-core-requests.js").SubscriptionCoreRequestIdentity): Promise<void>;
36
+ observe(request: import("./subscription-core-requests.js").SubscriptionCoreRequestSettlement): Promise<void>;
37
+ checkpoint(): Promise<void>;
38
+ canRecover(): boolean;
39
+ hasUnknownOutcome(): boolean;
40
+ unknownIsOwnAndSettled(): boolean;
41
+ admissionRefused(): boolean;
42
+ lastResponseReceivedAt(): Date | null;
43
+ };
44
+ export type ClaudeCoreRequestAuthorization = {
45
+ /** The current bearer (the shared resolver refreshes a stale one first). */
46
+ getToken: () => Promise<SubscriptionCoreClaudeTokenSnapshot>;
47
+ /**
48
+ * After a 401 on a bearer of `generation`: the turn's one forced refresh
49
+ * under the connection's refresh lock, shared by every request of the
50
+ * attempt, and its bearer only when the generation advanced past the
51
+ * refused one (null: surface the refusal).
52
+ */
53
+ renewAfterUnauthorized: (generation: number) => Promise<SubscriptionCoreClaudeTokenSnapshot | null>;
54
+ /** The dispatch fence every physical request passes before its reservation. */
55
+ assertDispatch: () => Promise<void>;
56
+ /**
57
+ * A main-lane request with a bearer of `generation` was admitted: the
58
+ * refusal settlement fences its health write on that generation. Main-lane
59
+ * requests are sequential, so at settlement it is the refused request's;
60
+ * session-title requests (their own lane) never move it.
61
+ */
62
+ mainLaneAdmitted: (generation: number) => void;
63
+ /**
64
+ * A response's usage headers, made with a bearer of `generation`, as a
65
+ * quota observation of the leased connection (`decodeQuota`), recorded in
66
+ * order and best effort; `core.quota` joins them.
67
+ */
68
+ observeResponse: (response: Response, generation: number, upstreamModelId?: string) => void;
69
+ };
70
+ /**
71
+ * Materialization and refresh for a core-placed Claude turn: the bearer comes
72
+ * from the shared core resolver under the exact accepted turn and this
73
+ * attempt's live core lease, and both request lanes (the agent's and the
74
+ * session title's) are created on the turn. `upstreamModelIds` lists the
75
+ * deployment's Claude models, so a family limit in a response's usage
76
+ * headers cools each of them.
77
+ */
78
+ export declare function buildClaudeCoreRequestAuthorization(input: {
79
+ db: Database;
80
+ settings: Settings;
81
+ core: SubscriptionCoreTurn;
82
+ lease: ClaudeTurnLease;
83
+ execution: {
84
+ attemptId: string;
85
+ executionGeneration: number;
86
+ };
87
+ upstreamModelIds: readonly string[];
88
+ }): ClaudeCoreRequestAuthorization;
89
+ /**
90
+ * The prefix of the bearer a core-placed Claude turn's capability settings
91
+ * carry instead of the live one: each core request's custody sets the real
92
+ * bearer, so a request that bypasses custody is refused upstream rather than
93
+ * spending the account unreserved.
94
+ */
95
+ export declare const CLAUDE_CORE_SETTINGS_PLACEHOLDER_TOKEN = "sk-ant-oat01-opengeni-core-custody-only";
96
+ /**
97
+ * The placeholder bearer of one connection at one credential version. It is
98
+ * unique per connection and version because the settings' key also scopes
99
+ * stored hosted web searches when the account has no UUID (a setup token):
100
+ * one shared placeholder would replay one account's encrypted search results
101
+ * to another, which Anthropic rejects. A refresh moves the version, which,
102
+ * like a rotated live token on the legacy path, only costs a readable replay.
103
+ */
104
+ export declare function claudeCoreSettingsPlaceholderToken(connectionId: string, credentialVersion: number): string;
105
+ /**
106
+ * The Claude credential a core-placed turn's capability settings carry: the
107
+ * account identity with the connection's placeholder bearer, never the live
108
+ * token or any refresh material.
109
+ */
110
+ export declare function claudeCoreSettingsCredential(token: SubscriptionCoreClaudeTokenSnapshot, connectionId: string): string;
111
+ /** The scope a Claude product model id names (its prefix). */
112
+ export declare function claudeCoreModelScope(productModelId: string): "organization" | "workspace";
113
+ /** The upstream model ids of the deployment's Claude subscription catalog. */
114
+ export declare function claudeSubscriptionUpstreamModelIds(settings: Pick<Settings, "modelProvidersJson">): string[];
115
+ /** The Claude subscription provider ids of the deployment's catalog. */
116
+ export declare function claudeSubscriptionProviderIds(settings: Pick<Settings, "modelProvidersJson">): ReadonlySet<string>;
117
+ /**
118
+ * The outcome of a streamed Claude response, read from its event names as
119
+ * the body passes: a `message_delta` (the model's final stop reason) or
120
+ * `message_stop` means the model answered, even when the reader stops right
121
+ * after it; an `error` event before any content block whose type is an
122
+ * overload or rate limit is a refusal (reported with HTTP 200); any other
123
+ * stream error (a timeout or conflict, as their HTTP statuses) and anything
124
+ * else that ends or stops early is unknown. A body that is not a stream is
125
+ * a response once it ends.
126
+ */
127
+ export declare function claudeResponseInspector(response: Response): CoreResponseInspector;
128
+ /**
129
+ * The Anthropic transport's per-request preparation for a core-placed Claude
130
+ * turn (through `withClaudeUsageObserver`): each physical request carries the
131
+ * core bearer, is fenced and reserved on its lane as the last step before the
132
+ * fetch, and settles from its response. A 401 renews the bearer through the
133
+ * turn's one forced refresh and retries the same request on the same
134
+ * connection as a new reservation, only when the generation advanced.
135
+ * `observe` receives every response with the generation of the bearer that
136
+ * made it (its usage headers become quota observations of the connection).
137
+ */
138
+ export declare function claudeCoreRequestPreparer(input: {
139
+ authorization: ClaudeCoreRequestAuthorization;
140
+ lane: CoreSubscriptionRequests;
141
+ /** The agent's lane (not the session title's): admissions move the refusal fence. */
142
+ mainLane: boolean;
143
+ nextRequestId: () => string;
144
+ providerIds: ReadonlySet<string>;
145
+ observe?: (response: Response, generation: number, upstreamModelId?: string) => void;
146
+ }): (providerId: string, headers: Headers) => Promise<Headers | PreparedUsageRequest>;
147
+ /**
148
+ * The terminal unknown-outcome failure of a core Claude turn, or null: an
149
+ * earlier or own request whose outcome is unknown is never replayed
150
+ * automatically.
151
+ */
152
+ export declare function claudeCoreRequestOutcomeUnknown(error: unknown, core: Pick<SubscriptionCoreTurn, "requests">): (Error & {
153
+ code: string;
154
+ }) | null;
155
+ /**
156
+ * Claude's in-turn failover and refusal settlement on the core (C1b) for a
157
+ * turn of `productModelId`: a 401 after the turn's one forced refresh is a
158
+ * sign-in quarantine, a 429 cools that model of the connection, and both
159
+ * re-place the same turn within the shared bound; 529 (overload) and 403
160
+ * (fatal) record nothing and never move the turn to another account.
161
+ * A 429 without the accepted model is not settled (null): it never widens
162
+ * into a whole-connection exhaustion.
163
+ *
164
+ * The transport already spent the turn's one forced refresh before a 401
165
+ * reaches settlement (`refreshedBeforeRefusal`), so the plan never asks for
166
+ * a second one: a refused bearer is a sign-in quarantine.
167
+ */
168
+ export declare function claudeCoreRefusal(productModelId: string | undefined): CoreRefusalBinding;
169
+ /**
170
+ * Joins a core Claude turn's usage-header observations so far, under its
171
+ * still-held lease: one that ended a stored exhaustion is a capacity change
172
+ * for the account's Claude waiters, delivered once per joined chain (the
173
+ * refusal settlement and finalization may both join it). Never throws. The
174
+ * queued writes are awaited in full (nothing may be released while one is
175
+ * queued); the wake delivery is bounded like a finalizer step, and the
176
+ * capacity outbox remains its backstop. A cancellation signal detaches only
177
+ * the wake, never the queued writes.
178
+ */
179
+ export declare function joinCoreClaudeObservations(services: CoreCodexWakeServices, core: SubscriptionCoreTurn, options?: {
180
+ signal?: AbortSignal | undefined;
181
+ wakeTimeoutMs?: number;
182
+ }): Promise<void>;
183
+ /**
184
+ * Finalization of a core Claude turn before its lease is released: the
185
+ * turn's usage-header observations are joined first
186
+ * (`joinCoreClaudeObservations`), then the shared finalization step runs.
187
+ * Claude declares an exact cache lifetime, so that step leaves the binding's
188
+ * cache clock alone: the clock moves when each request is reserved, never at
189
+ * finalization. Best effort.
190
+ */
191
+ export declare function finalizeCoreClaudeTurn(input: CoreCodexWakeServices & {
192
+ core: SubscriptionCoreTurn;
193
+ lease: ClaudeTurnLease;
194
+ signal?: AbortSignal | undefined;
195
+ }): Promise<void>;
@@ -0,0 +1,60 @@
1
+ import type { AttemptToolDefinition } from "@opengeni/codemode";
2
+ import { type Settings } from "@opengeni/config";
3
+ import { JevCircuitBreaker, type CodeSearchWorkspace } from "@opengeni/jev";
4
+ import type { Observability } from "@opengeni/observability";
5
+ import { type SandboxChannelAService } from "@opengeni/runtime/sandbox";
6
+ /**
7
+ * One breaker per worker process. Repeated Jev outages (including an exhausted
8
+ * account) make `code_search` calls on this worker fail at once for a cooldown
9
+ * instead of each running a full retry cycle. The breaker never changes which
10
+ * tools a turn is offered: the tool list and instructions are the start of the
11
+ * model's cached prompt, and sessions move between workers whose breakers
12
+ * disagree.
13
+ */
14
+ export declare const codeSearchCircuitBreaker: JevCircuitBreaker;
15
+ type CodeSearchChannel = Pick<SandboxChannelAService, "codeSearchRipgrep" | "codeSearchPathKinds" | "fsRead">;
16
+ /** Adapt the turn's sandbox or Connected Machine to the code search engine. */
17
+ export declare function codeSearchWorkspaceFromChannel(channel: CodeSearchChannel): CodeSearchWorkspace;
18
+ /** Jev work done by one completed `code_search` call, for per-workspace usage records. */
19
+ export type CodeSearchUsage = {
20
+ operationId: string;
21
+ jevRequests: number;
22
+ jevInputTokens: number;
23
+ jevCostUsd: number;
24
+ };
25
+ /**
26
+ * The model-facing `code_search` tool. Jev scores candidates inside the worker;
27
+ * the sandbox only runs read-only ripgrep and file reads, so the Jev key never
28
+ * leaves this process. A Jev failure is reported to the model instead of
29
+ * degrading to keyword-only ranking, which lowered answer quality in testing.
30
+ */
31
+ export declare function createCodeSearchAttemptToolDefinition(input: {
32
+ settings: Pick<Settings, "jevApiKey" | "jevBaseUrl" | "jevModel" | "jevRequestTimeoutMs">;
33
+ apiKey: string;
34
+ workspace: () => Promise<CodeSearchWorkspace>;
35
+ observability: Observability;
36
+ /** Records Jev usage against the workspace. Failures are logged, never surfaced. */
37
+ recordUsage?: (usage: CodeSearchUsage) => Promise<void>;
38
+ breaker?: JevCircuitBreaker;
39
+ fetch?: typeof fetch;
40
+ }): AttemptToolDefinition;
41
+ /**
42
+ * The `code_search` definition for one turn, or none. It is offered only when
43
+ * the session's frozen decision and the deployment enable it, a usable Jev key
44
+ * exists, and the turn has compute that can run its POSIX shell commands (not
45
+ * a Windows Connected Machine). Every input is durable, so the tool list stays
46
+ * the same from turn to turn and on every worker. Transient Jev health never
47
+ * hides the tool; the breaker only refuses calls.
48
+ */
49
+ export declare function codeSearchToolDefinitions(input: {
50
+ enabled: boolean;
51
+ settings: Pick<Settings, "jevApiKey" | "jevBaseUrl" | "jevModel" | "jevRequestTimeoutMs">;
52
+ backend: Settings["sandboxBackend"];
53
+ /** The turn's Connected Machine workspace root, when a machine is primary. */
54
+ machineWorkspaceRoot?: string | null;
55
+ observability: Observability;
56
+ workspace: () => Promise<CodeSearchWorkspace>;
57
+ recordUsage?: (usage: CodeSearchUsage) => Promise<void>;
58
+ breaker?: JevCircuitBreaker;
59
+ }): AttemptToolDefinition[];
60
+ export {};
@@ -37,4 +37,7 @@ export type CapacityPhaseOutcome = {
37
37
  } | {
38
38
  ok: true;
39
39
  };
40
+ export type CodexCutoverState = "not_configured" | "disabled" | "enabled";
41
+ /** Missing or disabled cutover state is maintenance, never legacy routing. */
42
+ export declare function codexCutoverDisposition(state: CodexCutoverState): "core" | "fail_closed";
40
43
  export declare function selectCodexTurnCapacity(deps: CapacityPhaseDeps): Promise<CapacityPhaseOutcome>;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Codex chat-turn placement on the shared subscription core (M3 PR 1,
3
+ * inventory EP-T01..T05): the provider-neutral placement
4
+ * (`subscription-core-capacity.ts`) bound to Codex, under the names M3
5
+ * shipped. Reached only when the organization's Codex cutover row is
6
+ * enabled; missing or disabled cutover state fails closed.
7
+ */
8
+ import { assertModelConnectionAllowsTurn, type CodexCredentialTokenSnapshot, type Database } from "@opengeni/db";
9
+ import type { Settings } from "@opengeni/config";
10
+ import { type CoreCodexWakeServices } from "../subscription-core-codex-waits.js";
11
+ import type { CapacityPhaseDeps, CapacityPhaseOutcome } from "./codex-capacity.js";
12
+ import type { CodexTurnLease } from "./credential-leases.js";
13
+ import { type CoreTurnPlacementProvider } from "./subscription-core-capacity.js";
14
+ import type { CodexSubscriptionCoreTurn, ProviderTurnState } from "./turn-context.js";
15
+ export declare function isCoreCodexSourceDisconnectedError(error: unknown): boolean;
16
+ /** Codex's chat placement on the shared core. */
17
+ export declare const CODEX_CORE_TURN_PROVIDER: CoreTurnPlacementProvider;
18
+ /** Lifecycle disappearance is not an auth refusal or an ordinary account pause. */
19
+ export declare function assertCoreCodexSourceConnected(db: Database, core: CodexSubscriptionCoreTurn): Promise<void>;
20
+ /**
21
+ * The turn's model-connection check. A shared-core placement already
22
+ * enforced the connection's model allowlist, entitlement exclusions and the
23
+ * workspace model policy in the same transaction as its lease; the legacy
24
+ * check reads legacy rows and must never see a core connection id.
25
+ */
26
+ export declare function assertTurnModelConnection(db: Database, providerTurn: Pick<ProviderTurnState, "codexSubscriptionCore"> & Partial<Pick<ProviderTurnState, "xaiSubscriptionCore" | "claudeSubscriptionCore">>, input: Parameters<typeof assertModelConnectionAllowsTurn>[1]): Promise<void>;
27
+ /**
28
+ * The bearer resolver for a core-placed turn (EP-T03): the same snapshot
29
+ * shape as the legacy resolver, but every read and refresh goes through the
30
+ * exact accepted turn and this attempt's live core lease. A lost lease marks
31
+ * the local holder lost, so dispatch stops with the ordinary lease-loss error.
32
+ */
33
+ export declare function buildCoreCodexRequestTokenResolver(db: Database, settings: Settings, core: CodexSubscriptionCoreTurn, lease: CodexTurnLease, wake?: Pick<CoreCodexWakeServices, "signalCodexCapacityWorkflow">): {
34
+ getToken: () => Promise<CodexCredentialTokenSnapshot>;
35
+ refresh: () => Promise<CodexCredentialTokenSnapshot>;
36
+ };
37
+ export declare function selectCoreCodexTurnCapacity(deps: CapacityPhaseDeps): Promise<CapacityPhaseOutcome>;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Claim-time Codex cutover handling (M3 PR 1). An organization whose Codex
3
+ * cutover row exists (enabled or disabled) must not have its turns read the
4
+ * legacy Codex tables at claim: not the active-credential flag for its Codex
5
+ * turns, and not the legacy Codex Apps designation for any turn.
6
+ */
7
+ import { type Database } from "@opengeni/db";
8
+ export type ClaimCodexCutoverState = "not_configured" | "disabled" | "enabled";
9
+ /** Same bound as the legacy active-credential read it stands in for. */
10
+ export declare const CLAIM_CODEX_CUTOVER_READ_ATTEMPTS = 3;
11
+ export declare const CLAIM_CODEX_CUTOVER_READ_RETRY_MS = 50;
12
+ /**
13
+ * Read the account's Codex cutover row. Only a thrown (transient) read is
14
+ * retried; a returned state is authoritative. Persistent failure surfaces
15
+ * the error rather than guessing a state.
16
+ */
17
+ export declare function readClaimCodexCutoverState(db: Database, input: {
18
+ accountId: string;
19
+ workspaceId: string;
20
+ }, options?: {
21
+ attempts?: number;
22
+ retryMs?: number;
23
+ }): Promise<ClaimCodexCutoverState>;
24
+ /** The stored shared-core lease-busy chain, ignoring anything malformed. */
25
+ export declare function readSubscriptionLeaseBusyChain(metadata: Record<string, unknown> | null | undefined): {
26
+ startedAt: number;
27
+ executionGeneration: number;
28
+ } | undefined;
29
+ /**
30
+ * Only an enabled cutover resolves the core Codex Apps designation; a
31
+ * disabled row resolves none (maintenance, fail closed).
32
+ */
33
+ export declare function claimMayResolveCoreCodexApps(input: {
34
+ codexConnectedAppsEnabled: boolean;
35
+ cutover: ClaimCodexCutoverState;
36
+ }): boolean;
37
+ /**
38
+ * Only an enabled cutover installs Codex; the core decides availability at placement.
39
+ */
40
+ export declare function claimCodexActiveFromCutover(cutover: ClaimCodexCutoverState): boolean;
@@ -0,0 +1,102 @@
1
+ import { type WaitReason } from "@opengeni/subscriptions";
2
+ /** Typed, user-readable failure for a turn on the shared subscription core. */
3
+ export type SubscriptionCoreCodexFailurePayload = {
4
+ error: string;
5
+ code: "subscription_capacity_unavailable" | "subscription_lease_busy" | "subscription_core_unsupported" | "subscription_core_cutover_disabled" | "subscription_account_refused" | "subscription_failover_exhausted";
6
+ retryable: boolean;
7
+ detail?: string;
8
+ /** Placement wait reason when `code` is `subscription_capacity_unavailable`. */
9
+ waitReason?: WaitReason;
10
+ /** Refusal class when `code` is `subscription_account_refused`. */
11
+ refusal?: SubscriptionCoreAccountRefusal;
12
+ /** ISO time the earliest known capacity returns, when placement knows it. */
13
+ resetsAt?: string;
14
+ /**
15
+ * Refusals this turn took, and the per-turn refusal bound, when `code` is
16
+ * `subscription_failover_exhausted` (refusals, not switches: the turn
17
+ * switched accounts `maxRefusals - 1` times before the last refusal).
18
+ */
19
+ refusals?: number;
20
+ maxRefusals?: number;
21
+ /** Combined model/provider changes and refusals, not a refusal count. */
22
+ failoverSteps?: number;
23
+ maxFailoverSteps?: number;
24
+ };
25
+ /** The provider-neutral name of the core turn failure payload. */
26
+ export type SubscriptionCoreFailurePayload = SubscriptionCoreCodexFailurePayload;
27
+ /** A typed core turn failure (the class keeps its M3 name; it serves every provider). */
28
+ export declare class SubscriptionCoreCodexTurnError extends Error {
29
+ readonly payload: SubscriptionCoreCodexFailurePayload;
30
+ readonly code: SubscriptionCoreCodexFailurePayload["code"];
31
+ /**
32
+ * The provider name its copy used. In-process only, never part of the
33
+ * payload, so a follow-up failure for the same turn (an exhausted lease-busy
34
+ * chain) names the same provider without the settlement naming providers.
35
+ */
36
+ readonly displayName: string;
37
+ constructor(payload: SubscriptionCoreCodexFailurePayload, displayName?: string);
38
+ }
39
+ /**
40
+ * The `codex.capacity.waiting` payload for a turn parked on a core waiter
41
+ * (M3 PR 2a): the legacy event shape with the core wait reason and the
42
+ * earliest known reset.
43
+ */
44
+ export declare function subscriptionCoreCapacityWaitPayload(reason: WaitReason, earliestResetAt: Date | null, displayName?: string): Record<string, unknown>;
45
+ /** The per-turn failover bound was reached; the session stays usable. */
46
+ export declare function subscriptionCoreFailoverExhaustedFailure(refusals: number, maxRefusals: number, displayName?: string): SubscriptionCoreCodexTurnError;
47
+ export declare function subscriptionCoreServingFailoverExhaustedFailure(steps: number, limit: number): SubscriptionCoreCodexTurnError;
48
+ /**
49
+ * The capacity wait the core decided, as a typed terminal failure. PR 2a
50
+ * parks waits on a durable core waiter instead; this remains for callers that
51
+ * cannot wait.
52
+ */
53
+ export declare function subscriptionCoreCapacityFailure(reason: WaitReason, earliestResetAt: Date | null, displayName?: string): SubscriptionCoreCodexTurnError;
54
+ /**
55
+ * An older attempt of this same turn still holds its lease until expiry, or
56
+ * (`binding_conflict`) the session's account changed while this placement
57
+ * was deciding. Both retry the same way; only the copy differs.
58
+ */
59
+ export declare function subscriptionCoreLeaseBusyFailure(leasedUntil: Date | null, cause?: "binding_conflict", displayName?: string): SubscriptionCoreCodexTurnError;
60
+ /** Most extra delay added after the older lease's expiry, so retries spread out. */
61
+ export declare const SUBSCRIPTION_CORE_LEASE_BUSY_JITTER_MS = 5000;
62
+ /**
63
+ * When a redispatched attempt should retry after finding an older attempt's
64
+ * live lease: just after that lease expires (plus jitter), never later than
65
+ * one lease TTL, and never sooner than one second.
66
+ */
67
+ export declare function subscriptionCoreLeaseBusyDelayMs(resetsAt: string | undefined, now: number, jitterSample: number, ttlMs?: number): number;
68
+ /**
69
+ * How long one turn may keep finding an older attempt's live lease: about
70
+ * three lease TTLs of wall-clock time since the first such recovery. Lease
71
+ * renewal is not fenced on the turn's current attempt, so a superseded attempt
72
+ * that keeps heartbeating would otherwise hold the turn forever.
73
+ */
74
+ export declare const SUBSCRIPTION_CORE_LEASE_BUSY_MAX_MS: number;
75
+ /**
76
+ * The consecutive lease-busy chain after this attempt: it continues only when
77
+ * the immediately previous execution generation recorded it. A stored start
78
+ * in the future (clock skew or a bad write) is clamped to now so it can never
79
+ * disable the bound.
80
+ */
81
+ export declare function subscriptionCoreLeaseBusyChain(stored: {
82
+ startedAt: number;
83
+ executionGeneration: number;
84
+ } | undefined, executionGeneration: number, now: number): {
85
+ startedAt: number;
86
+ executionGeneration: number;
87
+ exhausted: boolean;
88
+ };
89
+ /** The lease-busy chain lasted too long: stop with readable copy. */
90
+ export declare function subscriptionCoreLeaseBusyExhaustedFailure(displayName?: string): SubscriptionCoreCodexTurnError;
91
+ export type SubscriptionCoreAccountRefusal = "sign_in" | "forbidden" | "entitlement" | "access_lost";
92
+ /**
93
+ * A definitive refusal from the leased account (revoked sign-in, 403, or a
94
+ * plan that does not include the model). Health and quarantine of the
95
+ * connection arrive with PR 2; until then the turn stops with readable copy
96
+ * and the session stays usable.
97
+ */
98
+ export declare function subscriptionCoreAccountRefusedFailure(refusal: SubscriptionCoreAccountRefusal, displayName?: string): SubscriptionCoreCodexTurnError;
99
+ /** A Codex consumer that has not moved to the core yet (PR 2) must not read legacy tables. */
100
+ export declare function subscriptionCoreUnsupportedFailure(consumer: string, displayName?: string): SubscriptionCoreCodexTurnError;
101
+ /** The organization's cutover row for the provider exists but is switched off. */
102
+ export declare function subscriptionCoreCutoverDisabledFailure(displayName?: string): SubscriptionCoreCodexTurnError;