deepline 0.3.88 → 0.3.90

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 (280) hide show
  1. package/contracts/install-commands.json +29 -0
  2. package/dist/bundling-sources/sdk/src/client.ts +652 -39
  3. package/dist/bundling-sources/sdk/src/config.ts +77 -0
  4. package/dist/bundling-sources/sdk/src/http.ts +76 -30
  5. package/dist/bundling-sources/sdk/src/index.ts +10 -0
  6. package/dist/bundling-sources/sdk/src/monitor-fleet-contract.ts +1 -1
  7. package/dist/bundling-sources/sdk/src/pagination.ts +25 -0
  8. package/dist/bundling-sources/sdk/src/play.ts +15 -1
  9. package/dist/bundling-sources/sdk/src/plays/bundle-play-file.ts +3 -3
  10. package/dist/bundling-sources/sdk/src/release.ts +16 -9
  11. package/dist/bundling-sources/sdk/src/types.ts +106 -4
  12. package/dist/bundling-sources/shared_libs/integration-contracts/AGENTS.md +9 -0
  13. package/dist/bundling-sources/shared_libs/integration-contracts/README.md +3 -0
  14. package/dist/bundling-sources/shared_libs/integration-contracts/index.ts +2 -0
  15. package/dist/bundling-sources/shared_libs/monitors/analytics-install-guides.ts +77 -0
  16. package/dist/bundling-sources/shared_libs/monitors/analytics-public.ts +10 -0
  17. package/dist/bundling-sources/shared_libs/monitors/billing/charges.ts +125 -0
  18. package/dist/bundling-sources/shared_libs/monitors/billing/policy-builders.ts +686 -0
  19. package/dist/bundling-sources/shared_libs/monitors/billing/pricing.ts +54 -0
  20. package/dist/bundling-sources/shared_libs/monitors/billing/public-pricing.ts +72 -0
  21. package/dist/bundling-sources/shared_libs/monitors/billing/session.ts +45 -0
  22. package/dist/bundling-sources/shared_libs/monitors/billing/state.ts +454 -0
  23. package/dist/bundling-sources/shared_libs/monitors/billing/tamradar.ts +260 -0
  24. package/dist/bundling-sources/shared_libs/monitors/billing/types.ts +215 -0
  25. package/dist/bundling-sources/shared_libs/monitors/callback-security.ts +333 -0
  26. package/dist/bundling-sources/shared_libs/monitors/cursor-page.ts +42 -0
  27. package/dist/bundling-sources/shared_libs/monitors/deactivation-reasons.ts +16 -0
  28. package/dist/bundling-sources/shared_libs/monitors/framework-managed-payload-fields.ts +71 -0
  29. package/dist/bundling-sources/shared_libs/monitors/generated/provider-monitor-callback-admission-targets.ts +16 -0
  30. package/dist/bundling-sources/shared_libs/monitors/http-error-response.ts +270 -0
  31. package/dist/bundling-sources/shared_libs/monitors/inbound-publish-key.ts +39 -0
  32. package/dist/bundling-sources/shared_libs/monitors/inbound-queue.ts +82 -0
  33. package/dist/bundling-sources/shared_libs/monitors/inventory-reconciliation.ts +59 -0
  34. package/dist/bundling-sources/shared_libs/monitors/lifecycle-notifications.ts +471 -0
  35. package/dist/bundling-sources/shared_libs/monitors/org-monitor-limits.ts +1 -1
  36. package/dist/bundling-sources/shared_libs/monitors/package.json +36 -0
  37. package/dist/bundling-sources/shared_libs/monitors/provider-callback-verification.ts +1125 -0
  38. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-batch-operation.ts +305 -0
  39. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-capability.ts +964 -0
  40. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-consumer-health.ts +56 -0
  41. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-errors.ts +131 -0
  42. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-identity-claims.ts +535 -0
  43. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-legacy-aliases.ts +16 -0
  44. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-priority-execution.ts +56 -0
  45. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-public-aliases.ts +28 -0
  46. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-runtime-read-eligibility.ts +38 -0
  47. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-state.ts +122 -0
  48. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-status.ts +10 -0
  49. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-upstream-identity.ts +112 -0
  50. package/dist/bundling-sources/shared_libs/monitors/provider-webhook-monitor-runtime.ts +300 -0
  51. package/dist/bundling-sources/shared_libs/monitors/quickstart-prompts.ts +22 -0
  52. package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-dead-letter.ts +245 -0
  53. package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-message.ts +38 -0
  54. package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-queue-ack-probe.ts +94 -0
  55. package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-queue-delivery.ts +60 -0
  56. package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-queue.ts +60 -0
  57. package/dist/bundling-sources/shared_libs/monitors/snitcher-install-validation.ts +93 -0
  58. package/dist/bundling-sources/shared_libs/monitors/snitcher-ip2company.ts +332 -0
  59. package/dist/bundling-sources/shared_libs/monitors/snitcher-radar.ts +221 -0
  60. package/dist/bundling-sources/shared_libs/monitors/starter-templates.ts +105 -0
  61. package/dist/bundling-sources/shared_libs/monitors/tracking-provider-guidance.ts +73 -0
  62. package/dist/bundling-sources/shared_libs/monitors/tracking-provider-integrations.ts +81 -0
  63. package/dist/bundling-sources/shared_libs/monitors/tsconfig.json +10 -0
  64. package/dist/bundling-sources/shared_libs/observability/build-context.ts +13 -0
  65. package/dist/bundling-sources/shared_libs/observability/log-metadata.ts +160 -0
  66. package/dist/bundling-sources/shared_libs/observability/request-context.ts +68 -0
  67. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +654 -0
  68. package/dist/bundling-sources/shared_libs/observability/scheduled-work-manual.ts +35 -0
  69. package/dist/bundling-sources/shared_libs/observability/scheduled-work.ts +5 -0
  70. package/dist/bundling-sources/shared_libs/play-data-plane/neon-constants.ts +9 -0
  71. package/dist/bundling-sources/shared_libs/play-data-plane/r2.ts +272 -0
  72. package/dist/bundling-sources/shared_libs/play-runtime/activity-observation.ts +6 -11
  73. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +135 -12
  74. package/dist/bundling-sources/shared_libs/play-runtime/async-operation.ts +66 -1
  75. package/dist/bundling-sources/shared_libs/play-runtime/async-play-invocation.ts +77 -0
  76. package/dist/bundling-sources/shared_libs/play-runtime/bounceban-batching.ts +137 -0
  77. package/dist/bundling-sources/shared_libs/play-runtime/checkpoint-boundaries.ts +70 -0
  78. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +1159 -166
  79. package/dist/bundling-sources/shared_libs/play-runtime/coordinator-headers.ts +1 -32
  80. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +103 -0
  81. package/dist/bundling-sources/shared_libs/play-runtime/daytona-payload-contract.ts +68 -0
  82. package/dist/bundling-sources/shared_libs/play-runtime/daytona-sandbox-janitor.ts +103 -0
  83. package/dist/bundling-sources/shared_libs/play-runtime/daytona-sandbox-reaper.ts +725 -0
  84. package/dist/bundling-sources/shared_libs/play-runtime/default-batch-strategies.ts +20 -1
  85. package/dist/bundling-sources/shared_libs/play-runtime/durable-call-cache.ts +29 -0
  86. package/dist/bundling-sources/shared_libs/play-runtime/execution-capabilities.ts +29 -0
  87. package/dist/bundling-sources/shared_libs/play-runtime/execution-gateway-invocation-fence.ts +442 -0
  88. package/dist/bundling-sources/shared_libs/play-runtime/execution-protocol.ts +7 -1
  89. package/dist/bundling-sources/shared_libs/play-runtime/fixture-behavior.ts +18 -0
  90. package/dist/bundling-sources/shared_libs/play-runtime/governor/app-runtime-rate-state-backend.ts +9 -0
  91. package/dist/bundling-sources/shared_libs/play-runtime/governor/policy.ts +1 -1
  92. package/dist/bundling-sources/shared_libs/play-runtime/governor/rate-state-backend.ts +1 -1
  93. package/dist/bundling-sources/shared_libs/play-runtime/integration-operation-reader-fence/contracts.ts +66 -0
  94. package/dist/bundling-sources/shared_libs/play-runtime/integration-operation-reader-fence/job.ts +145 -0
  95. package/dist/bundling-sources/shared_libs/play-runtime/integration-operation-reader-fence/ports.ts +21 -0
  96. package/dist/bundling-sources/shared_libs/play-runtime/integration-operation-reader-fence/postgres-store.ts +170 -0
  97. package/dist/bundling-sources/shared_libs/play-runtime/internal-bootstrap-token.ts +1322 -0
  98. package/dist/bundling-sources/shared_libs/play-runtime/internal-step-ids.ts +2 -2
  99. package/dist/bundling-sources/shared_libs/play-runtime/lane-retirement-gate.ts +189 -0
  100. package/dist/bundling-sources/shared_libs/play-runtime/launch-source-policy.ts +112 -0
  101. package/dist/bundling-sources/shared_libs/play-runtime/map-execution-frame.ts +8 -0
  102. package/dist/bundling-sources/shared_libs/play-runtime/perf-trace.ts +127 -0
  103. package/dist/bundling-sources/shared_libs/play-runtime/play-artifact-runtime-contract.ts +5 -0
  104. package/dist/bundling-sources/shared_libs/play-runtime/play-run-recovery-policy.ts +24 -1
  105. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/admission/contracts.ts +56 -0
  106. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/admission/index.ts +13 -0
  107. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/admission/job.ts +41 -0
  108. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/admission/ports.ts +17 -0
  109. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/admission/postgres-adapter.ts +54 -0
  110. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/contracts.ts +114 -0
  111. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/engine-suspension.ts +108 -0
  112. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/index.ts +36 -0
  113. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/job.ts +97 -0
  114. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/ports.ts +104 -0
  115. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/postgres-fence-adapter.ts +263 -0
  116. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/worker-terminal-projection.ts +64 -0
  117. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/projection/contracts.ts +29 -0
  118. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/projection/gateway-adapter.ts +56 -0
  119. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/projection/index.ts +15 -0
  120. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/projection/job.ts +65 -0
  121. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/projection/ports.ts +17 -0
  122. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/contracts.ts +42 -0
  123. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/index.ts +17 -0
  124. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/job.ts +142 -0
  125. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/ports.ts +42 -0
  126. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/postgres-adapter.ts +102 -0
  127. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/terminal/contracts.ts +60 -0
  128. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/terminal/index.ts +16 -0
  129. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/terminal/job.ts +78 -0
  130. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/terminal/ports.ts +54 -0
  131. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/terminal/postgres-adapter.ts +71 -0
  132. package/dist/bundling-sources/shared_libs/play-runtime/play-runtime-batching-registry.ts +4 -0
  133. package/dist/bundling-sources/shared_libs/play-runtime/play-runtime-semantics.ts +28 -0
  134. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +4 -0
  135. package/dist/bundling-sources/shared_libs/play-runtime/receipt-status.ts +5 -8
  136. package/dist/bundling-sources/shared_libs/play-runtime/run-failure.ts +23 -2
  137. package/dist/bundling-sources/shared_libs/play-runtime/run-identity.ts +168 -0
  138. package/dist/bundling-sources/shared_libs/play-runtime/run-snapshot-stream.ts +1 -1
  139. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +90 -13
  140. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-payload-transport.ts +6 -12
  141. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-start-admission.ts +68 -0
  142. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona.ts +21 -0
  143. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/bundle.ts +0 -1
  144. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/runtime-sandbox-reconciliation.ts +14 -43
  145. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +67 -213
  146. package/dist/bundling-sources/shared_libs/play-runtime/runtime-authority.ts +201 -0
  147. package/dist/bundling-sources/shared_libs/play-runtime/runtime-capacity-policy.ts +20 -0
  148. package/dist/bundling-sources/shared_libs/play-runtime/runtime-contract.ts +6 -0
  149. package/dist/bundling-sources/shared_libs/play-runtime/runtime-env.ts +12 -0
  150. package/dist/bundling-sources/shared_libs/play-runtime/runtime-operation-contract.ts +67 -0
  151. package/dist/bundling-sources/shared_libs/play-runtime/runtime-release-environment.ts +2 -0
  152. package/dist/bundling-sources/shared_libs/play-runtime/runtime-sandbox-contract.ts +68 -0
  153. package/dist/bundling-sources/shared_libs/play-runtime/runtime-scheduler-topology.ts +38 -2
  154. package/dist/bundling-sources/shared_libs/play-runtime/runtime-telemetry.ts +108 -0
  155. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/contract.ts +4 -0
  156. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/runner-backend-adapter.ts +3 -0
  157. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +37 -1
  158. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-deadline-reconciliation.ts +88 -0
  159. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-play-deploy-task.ts +124 -0
  160. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-play-run-task.ts +68 -0
  161. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-pool.ts +193 -0
  162. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-queue-lifecycle.ts +269 -0
  163. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-queue-suffix.ts +73 -0
  164. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +6642 -0
  165. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-shared.ts +897 -0
  166. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-worker-metrics.ts +120 -0
  167. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-worker-required-env.ts +76 -0
  168. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd.ts +476 -0
  169. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/gateway-heavy-request-admission.ts +47 -0
  170. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/gateway-progress-registry.ts +147 -0
  171. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/index.ts +27 -0
  172. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/lazy.ts +50 -0
  173. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/play-run-recovery.ts +98 -0
  174. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-budget-state.ts +260 -0
  175. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-pool.ts +1416 -0
  176. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +1255 -0
  177. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-state.ts +942 -0
  178. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +14636 -0
  179. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/receipt-gateway.ts +888 -0
  180. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-ledger-outbox-recovery.ts +355 -0
  181. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-terminal-transition.ts +46 -0
  182. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runner-push.ts +60 -0
  183. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-api-origin.ts +33 -0
  184. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-receipt-gateway-health.ts +64 -0
  185. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +835 -0
  186. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-ledger-reconciliation.ts +1218 -0
  187. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-operation.ts +207 -0
  188. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-scheduler-schema.ts +10 -0
  189. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/scheduler-capacity.ts +123 -0
  190. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/scheduler-launch-read-observability.ts +78 -0
  191. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/submit-admission.ts +169 -0
  192. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/terminal-contract.ts +20 -0
  193. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/worker-queue-metrics.ts +34 -0
  194. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/worker-resource-metrics.ts +249 -0
  195. package/dist/bundling-sources/shared_libs/play-runtime/sheet-attempt-sql.ts +7 -0
  196. package/dist/bundling-sources/shared_libs/play-runtime/step-progress.ts +296 -0
  197. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/native-batch.ts +3 -3
  198. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/runtime-step-receipts-adapter.ts +20 -1
  199. package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +60 -15
  200. package/dist/bundling-sources/shared_libs/play-runtime/tool-execution-outcome.ts +20 -0
  201. package/dist/bundling-sources/shared_libs/play-runtime/tool-http-errors.ts +1 -1
  202. package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +1 -1
  203. package/dist/bundling-sources/shared_libs/play-runtime/transient-service-error.ts +12 -0
  204. package/dist/bundling-sources/shared_libs/play-runtime/vercel-protection.ts +14 -1
  205. package/dist/bundling-sources/shared_libs/play-runtime/work-receipt-storage-contract.ts +165 -0
  206. package/dist/bundling-sources/shared_libs/play-runtime/work-receipts.ts +15 -23
  207. package/dist/bundling-sources/shared_libs/play-runtime/workflow-executor-auth.ts +169 -0
  208. package/dist/bundling-sources/shared_libs/play-runtime/zerobounce-batching.ts +122 -0
  209. package/dist/bundling-sources/shared_libs/plays/artifact-types.ts +8 -3
  210. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +454 -17
  211. package/dist/bundling-sources/shared_libs/plays/bundling/index.ts +19 -4
  212. package/dist/bundling-sources/shared_libs/plays/contracts.ts +8 -14
  213. package/dist/bundling-sources/shared_libs/plays/core.ts +11 -6
  214. package/dist/bundling-sources/shared_libs/plays/deployment-status.ts +1 -1
  215. package/dist/bundling-sources/shared_libs/plays/docflow-binding-owner.ts +16 -11
  216. package/dist/bundling-sources/shared_libs/plays/docflow.ts +1 -1
  217. package/dist/bundling-sources/shared_libs/plays/email-status.ts +1 -1
  218. package/dist/bundling-sources/shared_libs/plays/play-grep-search.ts +39 -0
  219. package/dist/bundling-sources/shared_libs/plays/resolve-static-pipeline.ts +1 -1
  220. package/dist/bundling-sources/shared_libs/plays/share/copy.ts +271 -0
  221. package/dist/bundling-sources/shared_libs/plays/share/metrics.ts +140 -0
  222. package/dist/bundling-sources/shared_libs/plays/share/public-read-model.ts +86 -0
  223. package/dist/bundling-sources/shared_libs/plays/share/seo-quality.ts +181 -0
  224. package/dist/bundling-sources/shared_libs/plays/share/static-pipeline-summary.ts +658 -0
  225. package/dist/bundling-sources/shared_libs/plays/share/types.ts +197 -0
  226. package/dist/bundling-sources/shared_libs/plays/slack-hitl-timeout-error.ts +37 -0
  227. package/dist/bundling-sources/shared_libs/plays/slug.ts +115 -0
  228. package/dist/bundling-sources/shared_libs/plays/static-pipeline.ts +50 -15
  229. package/dist/bundling-sources/shared_libs/plays/tool-category-descriptions.ts +2 -2
  230. package/dist/bundling-sources/shared_libs/plays/tool-result-types.ts +1 -1
  231. package/dist/bundling-sources/shared_libs/product-notifications/catalog.ts +877 -0
  232. package/dist/bundling-sources/shared_libs/product-notifications/configuration-draft.ts +456 -0
  233. package/dist/bundling-sources/shared_libs/product-notifications/configuration.ts +566 -0
  234. package/dist/bundling-sources/shared_libs/product-notifications/content.ts +28 -0
  235. package/dist/bundling-sources/shared_libs/product-notifications/default-policy.ts +60 -0
  236. package/dist/bundling-sources/shared_libs/product-notifications/email.ts +246 -0
  237. package/dist/bundling-sources/shared_libs/product-notifications/evaluation.ts +280 -0
  238. package/dist/bundling-sources/shared_libs/product-notifications/events.ts +433 -0
  239. package/dist/bundling-sources/shared_libs/product-notifications/legacy-slack.ts +80 -0
  240. package/dist/bundling-sources/shared_libs/product-notifications/overflow.ts +18 -0
  241. package/dist/bundling-sources/shared_libs/product-notifications/rolling-limit.ts +24 -0
  242. package/dist/bundling-sources/shared_libs/product-notifications/slack-delivery.ts +624 -0
  243. package/dist/bundling-sources/shared_libs/product-notifications/slack-payload.ts +140 -0
  244. package/dist/bundling-sources/shared_libs/product-notifications/slack-transport.ts +75 -0
  245. package/dist/bundling-sources/shared_libs/product-notifications/workspace.ts +38 -0
  246. package/dist/bundling-sources/shared_libs/runtime-env.ts +12 -0
  247. package/dist/bundling-sources/shared_libs/security/email-blacklist.ts +42 -0
  248. package/dist/bundling-sources/shared_libs/security/header-safe-env.ts +35 -0
  249. package/dist/bundling-sources/shared_libs/security/internal-actor.ts +50 -0
  250. package/dist/bundling-sources/shared_libs/security/secret-redaction.ts +267 -0
  251. package/dist/bundling-sources/shared_libs/security/slack-sanitize.ts +133 -0
  252. package/dist/cli/getting-started.d.mts +52 -0
  253. package/dist/cli/getting-started.d.ts +52 -0
  254. package/dist/cli/getting-started.js +65 -0
  255. package/dist/cli/getting-started.mjs +36 -0
  256. package/dist/cli/index.d.mts +9 -0
  257. package/dist/cli/index.d.ts +9 -0
  258. package/dist/cli/index.js +1611 -453
  259. package/dist/cli/index.mjs +1596 -447
  260. package/dist/{compiler-manifest-Dbov16F7.d.mts → compiler-manifest-BaJfE-5H.d.mts} +136 -10
  261. package/dist/{compiler-manifest-Dbov16F7.d.ts → compiler-manifest-BaJfE-5H.d.ts} +136 -10
  262. package/dist/index.d.mts +910 -155
  263. package/dist/index.d.ts +910 -155
  264. package/dist/index.js +550 -64
  265. package/dist/index.mjs +550 -64
  266. package/dist/install-integrity.json +193 -4
  267. package/dist/monitor-fleet-contract.d.mts +138 -0
  268. package/dist/monitor-fleet-contract.d.ts +138 -0
  269. package/dist/monitor-fleet-contract.js +404 -0
  270. package/dist/monitor-fleet-contract.mjs +367 -0
  271. package/dist/plays/bundle-play-file.d.mts +8 -3
  272. package/dist/plays/bundle-play-file.d.ts +8 -3
  273. package/dist/plays/bundle-play-file.mjs +100 -20
  274. package/dist/release.d.mts +255 -0
  275. package/dist/release.d.ts +255 -0
  276. package/dist/release.js +215 -0
  277. package/dist/release.mjs +188 -0
  278. package/package.json +23 -4
  279. /package/dist/bundling-sources/shared_libs/{integrations/bettercontact-execution-policy.ts → integration-contracts/bettercontact/execution-policy.ts} +0 -0
  280. /package/dist/bundling-sources/shared_libs/{integrations/theirstack-execution-policy.ts → integration-contracts/theirstack/execution-policy.ts} +0 -0
@@ -0,0 +1,888 @@
1
+ /**
2
+ * Runtime receipt gateway dispatch.
3
+ *
4
+ * This is THE receipt data plane for play runners: every runtime step receipt
5
+ * read/write from a runner crosses HTTP to a co-located gateway process that
6
+ * holds the runtime Postgres (PlanetScale) pool. There is exactly one receipt
7
+ * backend — runners have no direct-Postgres receipt path and no app runtime
8
+ * API fallback (see apps/play-runner/src/entry.ts).
9
+ *
10
+ * The module is transport-agnostic on the database side so the production
11
+ * gateway (apps/runtime-receipt-gateway/index.ts, pooled `pg` against
12
+ * PlanetScale) and tests (PGlite) run the identical dispatch, scope checks,
13
+ * and payload sanitization.
14
+ */
15
+ import {
16
+ LEGACY_RUNTIME_RECEIPT_WIRE_FORMAT,
17
+ LEGACY_RUNTIME_RECEIPT_WIRE_HEADER,
18
+ runtimeReceiptCompletionResponse,
19
+ type LegacyRuntimeReceiptWireFormat,
20
+ } from '../runtime-contract';
21
+ import type {
22
+ RuntimeReceiptAction,
23
+ RuntimeReceiptFailure,
24
+ RuntimeReceiptLease,
25
+ } from '../runtime-actions';
26
+ import {
27
+ redactLedgerString,
28
+ sanitizeRuntimeReceiptPayload,
29
+ } from '../ledger-safe-payload';
30
+ import {
31
+ claimPostgresSchedulerReceipt,
32
+ claimPostgresSchedulerReceipts,
33
+ completePostgresSchedulerReceipt,
34
+ completePostgresSchedulerReceipts,
35
+ failPostgresSchedulerReceipt,
36
+ failPostgresSchedulerReceipts,
37
+ getPostgresSchedulerReceipt,
38
+ getPostgresSchedulerReceipts,
39
+ heartbeatPostgresSchedulerReceipts,
40
+ markPostgresSchedulerReceiptsQueued,
41
+ markPostgresSchedulerReceiptsRunning,
42
+ releasePostgresSchedulerReceipt,
43
+ skipPostgresSchedulerReceipt,
44
+ upsertPostgresSchedulerObservation,
45
+ } from '../scheduler-backends/postgres';
46
+ import { normalizePlayDocflowNodeIoState } from '../docflow-node-io';
47
+ import type { DocflowObservationStatus } from '../docflow-observation';
48
+ import {
49
+ isRuntimeSchedulerCapacityError,
50
+ runtimeSchedulerCapacityRetryAfterMs,
51
+ type RuntimeSchedulerQueryClient,
52
+ } from '../scheduler-backends/postgres-pool';
53
+ import { transientServiceUnavailableDetail } from '../transient-service-error';
54
+ import { isRuntimePostgresAdmissionCapacityError } from '../runtime-postgres-admission';
55
+ import { normalizeToolExecutionFailure } from '../../plays/tool-execution-error';
56
+
57
+ type RuntimeReceiptActionWithOptionalScope<
58
+ TAction extends RuntimeReceiptAction = RuntimeReceiptAction,
59
+ > = TAction extends RuntimeReceiptAction
60
+ ? Omit<TAction, 'playName' | 'runId'> & {
61
+ playName?: string;
62
+ runId?: string;
63
+ }
64
+ : never;
65
+
66
+ export type ReceiptGatewayActionBody = RuntimeReceiptActionWithOptionalScope;
67
+
68
+ /**
69
+ * Canonical set of actions the receipt gateway dispatcher accepts. The
70
+ * production gateway transport (`apps/runtime-receipt-gateway/index.ts`) must
71
+ * gate inbound requests against THIS constant rather than a hand-copied list so
72
+ * a new dispatcher action (e.g. `observe_docflow_node`) is admitted without a
73
+ * separate allowlist edit. `observe_docflow_node` (ADR 0016 rule 2) rides the
74
+ * same durable receipt wire as the receipt actions.
75
+ */
76
+ export const RECEIPT_GATEWAY_ACTIONS = new Set<string>([
77
+ 'get_runtime_step_receipt',
78
+ 'get_runtime_step_receipts',
79
+ 'claim_runtime_step_receipt',
80
+ 'claim_runtime_step_receipts',
81
+ 'mark_runtime_step_receipts_running',
82
+ 'mark_runtime_step_receipts_queued',
83
+ 'complete_runtime_step_receipt',
84
+ 'complete_runtime_step_receipts',
85
+ 'release_runtime_step_receipt',
86
+ 'fail_runtime_step_receipt',
87
+ 'fail_runtime_step_receipts',
88
+ 'heartbeat_runtime_step_receipts',
89
+ 'skip_runtime_step_receipt',
90
+ 'observe_docflow_node',
91
+ ]);
92
+
93
+ /** Run/play scope already proven by the transport's executor-token auth. */
94
+ export type ReceiptGatewayScope = {
95
+ orgId: string;
96
+ playName: string;
97
+ runId: string;
98
+ };
99
+
100
+ export type ExecutionGatewayBypassDecision = {
101
+ token: string;
102
+ source: 'launch' | 'env' | 'none';
103
+ };
104
+
105
+ /**
106
+ * Select the Vercel protection-bypass token the execution gateway attaches when
107
+ * proxying a runtime-control request to the (possibly protected) app.
108
+ *
109
+ * Precedence matches the worker's `buildPostgresSchedulerRunnerContext`: the
110
+ * launch-pinned, request-scoped token first, then the gateway's own env as a
111
+ * fallback. Returns an empty token with source `none` when neither is present.
112
+ * The source is logged in the gateway request trail so a protection 307 can be
113
+ * attributed to its credential origin without another blind CI cycle.
114
+ *
115
+ * The Daytona sandbox holds NO bypass credential (stripped by
116
+ * `remoteRuntimeContextForDaytona`), so the gateway is the sole hop that can
117
+ * attach it before the request reaches a protected Vercel preview. Without the
118
+ * env fallback, a launch row that never captured the token (or a re-dispatched
119
+ * child/retry that dropped it) reaches Vercel Deployment Protection bare and
120
+ * 307s to SSO.
121
+ */
122
+ export function resolveExecutionGatewayBypassToken(
123
+ launchToken: string | null | undefined,
124
+ envToken: string | null | undefined,
125
+ ): ExecutionGatewayBypassDecision {
126
+ const fromLaunch = launchToken?.trim();
127
+ if (fromLaunch) return { token: fromLaunch, source: 'launch' };
128
+ const fromEnv = envToken?.trim();
129
+ if (fromEnv) return { token: fromEnv, source: 'env' };
130
+ return { token: '', source: 'none' };
131
+ }
132
+
133
+ /**
134
+ * Attach a header-only Vercel automation bypass to a gateway-to-app request.
135
+ * A gateway is a server-to-server hop and must never request a bypass cookie:
136
+ * Vercel responds with a redirect in order to establish that cookie, while the
137
+ * runner intentionally refuses redirects on its runtime-control plane.
138
+ */
139
+ export function applyExecutionGatewayBypassHeader(
140
+ headers: Headers,
141
+ bypass: ExecutionGatewayBypassDecision,
142
+ ): void {
143
+ headers.delete('x-vercel-set-bypass-cookie');
144
+ if (bypass.token) {
145
+ headers.set('x-vercel-protection-bypass', bypass.token);
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Detect an execution-gateway self-proxy: the launch row's runtime API base
151
+ * pointing back at the gateway's own public host. Forwarding would loop (every
152
+ * hop re-authenticates, strips the bypass header, and re-enters the proxy), so
153
+ * the gateway must refuse loudly instead. `ownHost` is the Host header of the
154
+ * inbound request — Fly presents the app's public hostname there.
155
+ */
156
+ export function isExecutionGatewaySelfProxy(
157
+ upstreamUrl: string,
158
+ ownHost: string | null | undefined,
159
+ ): boolean {
160
+ const normalizedOwnHost = ownHost?.trim().toLowerCase();
161
+ if (!normalizedOwnHost) return false;
162
+ try {
163
+ return new URL(upstreamUrl).host.toLowerCase() === normalizedOwnHost;
164
+ } catch {
165
+ return false;
166
+ }
167
+ }
168
+
169
+ export function receiptGatewayJsonResponse(
170
+ body: unknown,
171
+ init: ResponseInit = {},
172
+ ): Response {
173
+ const headers = new Headers(init.headers);
174
+ headers.set('content-type', 'application/json');
175
+ headers.set(
176
+ LEGACY_RUNTIME_RECEIPT_WIRE_HEADER,
177
+ String(LEGACY_RUNTIME_RECEIPT_WIRE_FORMAT),
178
+ );
179
+ return new Response(JSON.stringify(body), { ...init, headers });
180
+ }
181
+
182
+ export type RuntimeGatewayFailureContext = {
183
+ action?: string | null;
184
+ operation?: 'receipt' | 'runtime_sheet' | 'runtime_durability';
185
+ };
186
+
187
+ export function receiptGatewayFailureResponse(
188
+ error: unknown,
189
+ context: RuntimeGatewayFailureContext = {},
190
+ ): Response {
191
+ const operationLabel =
192
+ context.operation === 'runtime_sheet'
193
+ ? 'Runtime Sheet persistence'
194
+ : context.operation === 'runtime_durability'
195
+ ? 'Runtime durability operation'
196
+ : 'Work Receipt persistence';
197
+ if (isRuntimePostgresAdmissionCapacityError(error)) {
198
+ return receiptGatewayJsonResponse(
199
+ {
200
+ error: `${operationLabel} is waiting for database capacity.`,
201
+ code: 'runtime_postgres_admission_backpressure',
202
+ retryable: true,
203
+ retry_after_ms: 1_000,
204
+ detail: error.message,
205
+ ...(context.action ? { action: context.action } : {}),
206
+ },
207
+ {
208
+ status: 503,
209
+ headers: {
210
+ 'retry-after': '1',
211
+ 'x-deepline-error-code': 'runtime_postgres_admission_backpressure',
212
+ },
213
+ },
214
+ );
215
+ }
216
+ if (isRuntimeSchedulerCapacityError(error)) {
217
+ const retryAfterMs = runtimeSchedulerCapacityRetryAfterMs(error);
218
+ return receiptGatewayJsonResponse(
219
+ {
220
+ error: `${operationLabel} delayed.`,
221
+ code: 'scheduler_capacity',
222
+ retry_after_ms: retryAfterMs,
223
+ detail: error.message,
224
+ ...(context.action ? { action: context.action } : {}),
225
+ },
226
+ {
227
+ status: 503,
228
+ headers: {
229
+ 'retry-after': String(Math.max(1, Math.ceil(retryAfterMs / 1_000))),
230
+ 'x-deepline-error-code': 'scheduler_capacity',
231
+ },
232
+ },
233
+ );
234
+ }
235
+
236
+ const detail =
237
+ redactLedgerString(error instanceof Error ? error.message : error) ??
238
+ 'Unknown runtime gateway failure.';
239
+ const headerDetail = detail.replace(/[\r\n]+/g, ' ').slice(0, 500);
240
+ const unavailableDetail = transientServiceUnavailableDetail(error);
241
+ if (unavailableDetail) {
242
+ return receiptGatewayJsonResponse(
243
+ {
244
+ error: `${operationLabel} dependency is temporarily unavailable.`,
245
+ code: 'upstream_service_unavailable',
246
+ retryable: true,
247
+ detail: unavailableDetail,
248
+ ...(context.action ? { action: context.action } : {}),
249
+ },
250
+ {
251
+ status: 503,
252
+ headers: {
253
+ 'retry-after': '1',
254
+ 'x-deepline-error-code': 'upstream_service_unavailable',
255
+ 'x-deepline-error-detail': unavailableDetail
256
+ .replace(/[\r\n]+/g, ' ')
257
+ .slice(0, 500),
258
+ },
259
+ },
260
+ );
261
+ }
262
+ const failure =
263
+ context.operation === 'runtime_sheet'
264
+ ? {
265
+ error: 'Runtime Sheet persistence failed.',
266
+ code: 'runtime_sheet_persistence_failed',
267
+ }
268
+ : context.operation === 'runtime_durability'
269
+ ? {
270
+ error: 'Runtime durability operation failed.',
271
+ code: 'runtime_durability_internal',
272
+ }
273
+ : {
274
+ error: 'Work Receipt persistence failed.',
275
+ code: 'work_receipt_persistence_failed',
276
+ };
277
+ return receiptGatewayJsonResponse(
278
+ {
279
+ ...failure,
280
+ retryable: false,
281
+ detail,
282
+ ...(context.action ? { action: context.action } : {}),
283
+ },
284
+ {
285
+ status: 500,
286
+ // Surface the underlying failure on a header so the gateway request log
287
+ // (which only reads response headers, never the body) can print WHY a
288
+ // 500 happened. Without this a connect/query failure is an opaque
289
+ // `status: 500, errorCode: null` line.
290
+ headers: {
291
+ 'x-deepline-error-code': failure.code,
292
+ 'x-deepline-error-detail': headerDetail,
293
+ },
294
+ },
295
+ );
296
+ }
297
+
298
+ function requireReceiptScope(
299
+ scope: ReceiptGatewayScope,
300
+ body: ReceiptGatewayActionBody,
301
+ ): Response | null {
302
+ if (!scope.orgId || !scope.playName || !scope.runId) {
303
+ return receiptGatewayJsonResponse(
304
+ { error: 'Executor token is missing org/run/play scope.' },
305
+ { status: 403 },
306
+ );
307
+ }
308
+ if (body.playName !== scope.playName) {
309
+ return receiptGatewayJsonResponse(
310
+ { error: 'Receipt request playName does not match executor token.' },
311
+ { status: 403 },
312
+ );
313
+ }
314
+ if (body.runId && body.runId !== scope.runId) {
315
+ console.warn('[runtime-receipt-gateway.scope_mismatch]', {
316
+ action: body.action ?? 'unknown',
317
+ tokenRunId: scope.runId,
318
+ requestRunId: body.runId,
319
+ });
320
+ return receiptGatewayJsonResponse(
321
+ { error: 'Receipt request runId does not match executor token.' },
322
+ { status: 403 },
323
+ );
324
+ }
325
+ return null;
326
+ }
327
+
328
+ function requireSameRunReceipts(
329
+ runId: string,
330
+ receipts: unknown,
331
+ ): Response | null {
332
+ if (!Array.isArray(receipts)) {
333
+ return receiptGatewayJsonResponse(
334
+ { error: 'receipts must be an array.' },
335
+ { status: 400 },
336
+ );
337
+ }
338
+ const invalid = receipts.find(
339
+ (receipt) =>
340
+ !receipt ||
341
+ typeof receipt !== 'object' ||
342
+ (receipt as { runId?: unknown }).runId !== runId,
343
+ );
344
+ return invalid
345
+ ? receiptGatewayJsonResponse(
346
+ { error: 'Receipt runId does not match executor token scope.' },
347
+ { status: 403 },
348
+ )
349
+ : null;
350
+ }
351
+
352
+ function receiptKey(value: unknown): string | Response {
353
+ const key = typeof value === 'string' ? value.trim() : '';
354
+ return (
355
+ key ||
356
+ receiptGatewayJsonResponse(
357
+ { error: 'Receipt key is required.' },
358
+ { status: 400 },
359
+ )
360
+ );
361
+ }
362
+
363
+ function receiptKeys(value: unknown): Array<string> | Response {
364
+ if (!Array.isArray(value)) {
365
+ return receiptGatewayJsonResponse(
366
+ { error: 'keys must be an array.' },
367
+ { status: 400 },
368
+ );
369
+ }
370
+ const keys = value.map((key) => (typeof key === 'string' ? key.trim() : ''));
371
+ if (keys.some((key) => !key)) {
372
+ return receiptGatewayJsonResponse(
373
+ { error: 'All receipt keys must be non-empty strings.' },
374
+ { status: 400 },
375
+ );
376
+ }
377
+ return keys;
378
+ }
379
+
380
+ export type ReceiptGatewayDispatcher = (
381
+ scope: ReceiptGatewayScope,
382
+ body: unknown,
383
+ options?: ReceiptGatewayDispatchOptions,
384
+ ) => Promise<Response>;
385
+
386
+ export type ReceiptGatewayDispatchOptions = {
387
+ /** Legacy response presentation only; never an admission range. */
388
+ wireFormat?: LegacyRuntimeReceiptWireFormat;
389
+ validateKeys?: (keys: readonly string[]) => Response | null;
390
+ onRead?: (input: {
391
+ action: 'get_runtime_step_receipt' | 'get_runtime_step_receipts';
392
+ keys: readonly string[];
393
+ receipts: readonly unknown[];
394
+ }) => void;
395
+ onClaim?: (input: {
396
+ action: 'claim_runtime_step_receipt' | 'claim_runtime_step_receipts';
397
+ receipts: readonly unknown[];
398
+ forceRefresh: boolean;
399
+ }) => void;
400
+ };
401
+
402
+ async function injectReceiptCompletionFailure(input: {
403
+ client: RuntimeSchedulerQueryClient;
404
+ orgId: string;
405
+ key: string;
406
+ runId: string;
407
+ schema?: string;
408
+ }): Promise<void> {
409
+ const options = { schema: input.schema, orgId: input.orgId };
410
+ const current = await getPostgresSchedulerReceipt(
411
+ input.client,
412
+ { key: input.key },
413
+ options,
414
+ );
415
+ if (current?.status !== 'running' || current.runId !== input.runId) {
416
+ throw new Error(
417
+ `Cannot inject receipt completion failure for ${input.key}: expected a running receipt owned by ${input.runId}.`,
418
+ );
419
+ }
420
+ const failed = await failPostgresSchedulerReceipt(
421
+ input.client,
422
+ {
423
+ key: input.key,
424
+ runId: input.runId,
425
+ runAttempt: current.leaseOwnerAttempt,
426
+ leaseId: current.leaseId,
427
+ error: 'Injected runtime test fault: receipt_complete_write_fail.',
428
+ failureKind: 'repairable',
429
+ },
430
+ options,
431
+ );
432
+ if (failed?.status !== 'failed' || failed.failureKind !== 'repairable') {
433
+ throw new Error(
434
+ `Failed to install repairable receipt completion fault for ${input.key}.`,
435
+ );
436
+ }
437
+ }
438
+
439
+ export function createReceiptGatewayDispatcher(input: {
440
+ withClient: <T>(
441
+ fn: (client: RuntimeSchedulerQueryClient) => Promise<T>,
442
+ ) => Promise<T>;
443
+ schema?: string;
444
+ consumeReceiptCompleteFault?: (runId: string) => boolean | Promise<boolean>;
445
+ }): ReceiptGatewayDispatcher {
446
+ return async (scope, rawBody, dispatchOptions = {}) => {
447
+ if (!rawBody || typeof rawBody !== 'object') {
448
+ return receiptGatewayJsonResponse(
449
+ { error: 'Receipt gateway action body is required.' },
450
+ { status: 400 },
451
+ );
452
+ }
453
+ const body = rawBody as ReceiptGatewayActionBody;
454
+ const scopeError = requireReceiptScope(scope, body);
455
+ if (scopeError) return scopeError;
456
+ const runId = String(body.runId || scope.runId);
457
+ const wireFormat = dispatchOptions.wireFormat ?? 3;
458
+ // Org scope is proven by the executor token at the transport (production:
459
+ // apps/runtime-receipt-gateway/index.ts passes auth.orgId here). The
460
+ // (org_id, k) composite-key receipt functions require it, so thread it
461
+ // through identically for the test/PGlite dispatch to match production.
462
+ const options = { schema: input.schema, orgId: scope.orgId };
463
+
464
+ return await input.withClient(async (client) => {
465
+ switch (body.action) {
466
+ case 'get_runtime_step_receipt': {
467
+ const key = receiptKey(body.key);
468
+ if (key instanceof Response) return key;
469
+ const keyScopeError = dispatchOptions.validateKeys?.([key]);
470
+ if (keyScopeError) return keyScopeError;
471
+ const receipt = await getPostgresSchedulerReceipt(
472
+ client,
473
+ { key },
474
+ options,
475
+ );
476
+ dispatchOptions.onRead?.({
477
+ action: body.action,
478
+ keys: [key],
479
+ receipts: [receipt],
480
+ });
481
+ return receiptGatewayJsonResponse(receipt);
482
+ }
483
+ case 'get_runtime_step_receipts': {
484
+ const keys = receiptKeys(body.keys);
485
+ if (keys instanceof Response) return keys;
486
+ const keyScopeError = dispatchOptions.validateKeys?.(keys);
487
+ if (keyScopeError) return keyScopeError;
488
+ const receipts = await getPostgresSchedulerReceipts(
489
+ client,
490
+ { keys },
491
+ options,
492
+ );
493
+ dispatchOptions.onRead?.({
494
+ action: body.action,
495
+ keys,
496
+ receipts,
497
+ });
498
+ return receiptGatewayJsonResponse(receipts);
499
+ }
500
+ case 'claim_runtime_step_receipt': {
501
+ const key = receiptKey(body.key);
502
+ if (key instanceof Response) return key;
503
+ const keyScopeError = dispatchOptions.validateKeys?.([key]);
504
+ if (keyScopeError) return keyScopeError;
505
+ const receipt = await claimPostgresSchedulerReceipt(
506
+ client,
507
+ {
508
+ key,
509
+ ...(typeof body.leaseId === 'string'
510
+ ? { leaseId: body.leaseId }
511
+ : {}),
512
+ runId,
513
+ runAttempt:
514
+ typeof body.runAttempt === 'number' ? body.runAttempt : null,
515
+ leaseAware: body.leaseAware === true,
516
+ reclaimRunning: body.reclaimRunning === true,
517
+ forceRefresh: body.forceRefresh === true,
518
+ forceFailedRefresh: body.forceFailedRefresh === true,
519
+ },
520
+ options,
521
+ );
522
+ dispatchOptions.onClaim?.({
523
+ action: body.action,
524
+ receipts: [receipt],
525
+ forceRefresh: body.forceRefresh === true,
526
+ });
527
+ return receiptGatewayJsonResponse(receipt);
528
+ }
529
+ case 'claim_runtime_step_receipts': {
530
+ const keys = receiptKeys(body.keys);
531
+ if (keys instanceof Response) return keys;
532
+ const keyScopeError = dispatchOptions.validateKeys?.(keys);
533
+ if (keyScopeError) return keyScopeError;
534
+ const receipts = await claimPostgresSchedulerReceipts(
535
+ client,
536
+ {
537
+ keys,
538
+ ...(Array.isArray(body.leaseIds)
539
+ ? { leaseIds: body.leaseIds as string[] }
540
+ : {}),
541
+ runId,
542
+ runAttempt:
543
+ typeof body.runAttempt === 'number' ? body.runAttempt : null,
544
+ leaseAware: body.leaseAware === true,
545
+ reclaimRunning: body.reclaimRunning === true,
546
+ forceRefresh: body.forceRefresh === true,
547
+ forceFailedRefresh: body.forceFailedRefresh === true,
548
+ },
549
+ options,
550
+ );
551
+ dispatchOptions.onClaim?.({
552
+ action: body.action,
553
+ receipts,
554
+ forceRefresh: body.forceRefresh === true,
555
+ });
556
+ return receiptGatewayJsonResponse(receipts);
557
+ }
558
+ case 'mark_runtime_step_receipts_running': {
559
+ const sameRunError = requireSameRunReceipts(runId, body.receipts);
560
+ if (sameRunError) return sameRunError;
561
+ return receiptGatewayJsonResponse(
562
+ await markPostgresSchedulerReceiptsRunning(
563
+ client,
564
+ { receipts: body.receipts as RuntimeReceiptLease[] },
565
+ options,
566
+ ),
567
+ );
568
+ }
569
+ case 'mark_runtime_step_receipts_queued': {
570
+ const sameRunError = requireSameRunReceipts(runId, body.receipts);
571
+ if (sameRunError) return sameRunError;
572
+ return receiptGatewayJsonResponse(
573
+ await markPostgresSchedulerReceiptsQueued(
574
+ client,
575
+ { receipts: body.receipts as RuntimeReceiptLease[] },
576
+ options,
577
+ ),
578
+ );
579
+ }
580
+ case 'complete_runtime_step_receipt': {
581
+ const key = receiptKey(body.key);
582
+ if (key instanceof Response) return key;
583
+ if (await input.consumeReceiptCompleteFault?.(runId)) {
584
+ await injectReceiptCompletionFailure({
585
+ client,
586
+ orgId: scope.orgId,
587
+ key,
588
+ runId,
589
+ schema: input.schema,
590
+ });
591
+ return receiptGatewayJsonResponse(
592
+ {
593
+ error:
594
+ 'Injected runtime test fault: receipt_complete_write_fail.',
595
+ code: 'runtime_test_fault',
596
+ },
597
+ { status: 409 },
598
+ );
599
+ }
600
+ return receiptGatewayJsonResponse(
601
+ runtimeReceiptCompletionResponse(
602
+ wireFormat,
603
+ await completePostgresSchedulerReceipt(
604
+ client,
605
+ {
606
+ key,
607
+ runId,
608
+ runAttempt:
609
+ typeof body.runAttempt === 'number'
610
+ ? body.runAttempt
611
+ : null,
612
+ leaseId:
613
+ typeof body.leaseId === 'string' ? body.leaseId : null,
614
+ output: sanitizeRuntimeReceiptPayload(body.output ?? null),
615
+ returnOutput: wireFormat < 3,
616
+ },
617
+ options,
618
+ ),
619
+ ),
620
+ );
621
+ }
622
+ case 'complete_runtime_step_receipts': {
623
+ const sameRunError = requireSameRunReceipts(runId, body.receipts);
624
+ if (sameRunError) return sameRunError;
625
+ const keys = receiptKeys(
626
+ (body.receipts as Array<Record<string, unknown>>).map(
627
+ (receipt) => receipt.key,
628
+ ),
629
+ );
630
+ if (keys instanceof Response) return keys;
631
+ const completions = body.receipts.map((receipt, index) => ({
632
+ key: keys[index]!,
633
+ runId,
634
+ runAttempt:
635
+ typeof receipt.runAttempt === 'number'
636
+ ? receipt.runAttempt
637
+ : null,
638
+ leaseId:
639
+ typeof receipt.leaseId === 'string' ? receipt.leaseId : null,
640
+ output: sanitizeRuntimeReceiptPayload(receipt.output ?? null),
641
+ }));
642
+ if (await input.consumeReceiptCompleteFault?.(runId)) {
643
+ const [skippedReceipt, ...siblingReceipts] = completions;
644
+ if (siblingReceipts.length > 0) {
645
+ await completePostgresSchedulerReceipts(
646
+ client,
647
+ {
648
+ receipts: siblingReceipts,
649
+ returnOutput: wireFormat < 3,
650
+ },
651
+ options,
652
+ );
653
+ }
654
+ if (skippedReceipt) {
655
+ await injectReceiptCompletionFailure({
656
+ client,
657
+ orgId: scope.orgId,
658
+ key: skippedReceipt.key,
659
+ runId,
660
+ schema: input.schema,
661
+ });
662
+ }
663
+ return receiptGatewayJsonResponse(
664
+ {
665
+ error:
666
+ 'Injected runtime test fault: receipt_complete_write_fail.',
667
+ code: 'runtime_test_fault',
668
+ },
669
+ { status: 409 },
670
+ );
671
+ }
672
+ return receiptGatewayJsonResponse(
673
+ (
674
+ await completePostgresSchedulerReceipts(
675
+ client,
676
+ {
677
+ receipts: completions,
678
+ returnOutput: wireFormat < 3,
679
+ },
680
+ options,
681
+ )
682
+ ).map((receipt) =>
683
+ runtimeReceiptCompletionResponse(wireFormat, receipt),
684
+ ),
685
+ );
686
+ }
687
+ case 'release_runtime_step_receipt': {
688
+ const key = receiptKey(body.key);
689
+ if (key instanceof Response) return key;
690
+ return receiptGatewayJsonResponse(
691
+ await releasePostgresSchedulerReceipt(
692
+ client,
693
+ {
694
+ key,
695
+ runId,
696
+ runAttempt:
697
+ typeof body.runAttempt === 'number' ? body.runAttempt : null,
698
+ leaseId: typeof body.leaseId === 'string' ? body.leaseId : null,
699
+ },
700
+ options,
701
+ ),
702
+ );
703
+ }
704
+ case 'fail_runtime_step_receipt': {
705
+ const key = receiptKey(body.key);
706
+ if (key instanceof Response) return key;
707
+ const errorPayload = normalizeToolExecutionFailure(body.errorPayload);
708
+ return receiptGatewayJsonResponse(
709
+ await failPostgresSchedulerReceipt(
710
+ client,
711
+ {
712
+ key,
713
+ runId,
714
+ runAttempt:
715
+ typeof body.runAttempt === 'number' ? body.runAttempt : null,
716
+ leaseId: typeof body.leaseId === 'string' ? body.leaseId : null,
717
+ error: redactLedgerString(body.error) ?? '',
718
+ ...(errorPayload ? { errorPayload } : {}),
719
+ failureKind:
720
+ body.failureKind === 'repairable' ? 'repairable' : 'terminal',
721
+ },
722
+ options,
723
+ ),
724
+ );
725
+ }
726
+ case 'fail_runtime_step_receipts': {
727
+ const sameRunError = requireSameRunReceipts(runId, body.receipts);
728
+ if (sameRunError) return sameRunError;
729
+ const keys = receiptKeys(
730
+ (body.receipts as Array<Record<string, unknown>>).map(
731
+ (receipt) => receipt.key,
732
+ ),
733
+ );
734
+ if (keys instanceof Response) return keys;
735
+ return receiptGatewayJsonResponse(
736
+ await failPostgresSchedulerReceipts(
737
+ client,
738
+ {
739
+ receipts: (body.receipts as RuntimeReceiptFailure[]).map(
740
+ (receipt, index) => {
741
+ const errorPayload = normalizeToolExecutionFailure(
742
+ receipt.errorPayload,
743
+ );
744
+ return {
745
+ key: keys[index]!,
746
+ runId,
747
+ runAttempt:
748
+ typeof receipt.runAttempt === 'number'
749
+ ? receipt.runAttempt
750
+ : null,
751
+ leaseId:
752
+ typeof receipt.leaseId === 'string'
753
+ ? receipt.leaseId
754
+ : null,
755
+ error: redactLedgerString(receipt.error) ?? '',
756
+ ...(errorPayload ? { errorPayload } : {}),
757
+ failureKind:
758
+ receipt.failureKind === 'repairable'
759
+ ? 'repairable'
760
+ : 'terminal',
761
+ };
762
+ },
763
+ ),
764
+ },
765
+ options,
766
+ ),
767
+ );
768
+ }
769
+ case 'heartbeat_runtime_step_receipts': {
770
+ const keys = receiptKeys(body.keys);
771
+ if (keys instanceof Response) return keys;
772
+ return receiptGatewayJsonResponse(
773
+ await heartbeatPostgresSchedulerReceipts(
774
+ client,
775
+ {
776
+ keys,
777
+ runId,
778
+ runAttempt:
779
+ typeof body.runAttempt === 'number' ? body.runAttempt : null,
780
+ ...(Array.isArray(body.leaseIds)
781
+ ? {
782
+ leaseIds: body.leaseIds.map((leaseId) =>
783
+ String(leaseId ?? ''),
784
+ ),
785
+ }
786
+ : { leaseId: String(body.leaseId ?? '') }),
787
+ },
788
+ options,
789
+ ),
790
+ );
791
+ }
792
+ case 'skip_runtime_step_receipt': {
793
+ const key = receiptKey(body.key);
794
+ if (key instanceof Response) return key;
795
+ return receiptGatewayJsonResponse(
796
+ await skipPostgresSchedulerReceipt(
797
+ client,
798
+ {
799
+ key,
800
+ runId,
801
+ runAttempt:
802
+ typeof body.runAttempt === 'number' ? body.runAttempt : null,
803
+ leaseId: typeof body.leaseId === 'string' ? body.leaseId : null,
804
+ output: sanitizeRuntimeReceiptPayload(body.output ?? null),
805
+ },
806
+ options,
807
+ ),
808
+ );
809
+ }
810
+ case 'observe_docflow_node': {
811
+ // ADR 0016 rule 2: durable per-node-invocation observation on the
812
+ // same wire receipts use. The play body fires this fire-and-forget,
813
+ // so the gateway persists on a best-effort basis and never gates
814
+ // execution. Previews are re-normalized (bounded) as defense in depth
815
+ // — the wrapper already caps them.
816
+ const nodeId =
817
+ typeof body.nodeId === 'string' ? body.nodeId.trim() : '';
818
+ const status = body.status;
819
+ if (
820
+ !nodeId ||
821
+ (status !== 'started' &&
822
+ status !== 'completed' &&
823
+ status !== 'failed')
824
+ ) {
825
+ return receiptGatewayJsonResponse(
826
+ { error: 'Observation requires a nodeId and a valid status.' },
827
+ { status: 400 },
828
+ );
829
+ }
830
+ const attempt =
831
+ typeof body.attempt === 'number' && Number.isFinite(body.attempt)
832
+ ? Math.max(0, Math.trunc(body.attempt))
833
+ : 0;
834
+ const invocationSeq =
835
+ typeof body.invocationSeq === 'number' &&
836
+ Number.isFinite(body.invocationSeq)
837
+ ? Math.max(0, Math.trunc(body.invocationSeq))
838
+ : 0;
839
+ const io = normalizePlayDocflowNodeIoState({
840
+ attempt,
841
+ ...(typeof body.invocationId === 'string'
842
+ ? { invocationId: body.invocationId }
843
+ : {}),
844
+ inputs: body.inputs,
845
+ outputs: body.outputs,
846
+ inputsTruncated: body.inputsTruncated === true,
847
+ outputsTruncated: body.outputsTruncated === true,
848
+ ...(typeof body.error === 'string' ? { error: body.error } : {}),
849
+ });
850
+ await upsertPostgresSchedulerObservation(
851
+ client,
852
+ {
853
+ runId,
854
+ attempt,
855
+ nodeId,
856
+ invocationSeq,
857
+ invocationId:
858
+ typeof body.invocationId === 'string'
859
+ ? body.invocationId
860
+ : null,
861
+ status: status as DocflowObservationStatus,
862
+ inputs: io?.inputs ?? null,
863
+ outputs: io?.outputs ?? null,
864
+ inputsTruncated: io?.inputsTruncated === true,
865
+ outputsTruncated: io?.outputsTruncated === true,
866
+ error: io?.error ?? null,
867
+ at:
868
+ typeof body.at === 'number' && Number.isFinite(body.at)
869
+ ? body.at
870
+ : Date.now(),
871
+ },
872
+ options,
873
+ );
874
+ return receiptGatewayJsonResponse({ ok: true });
875
+ }
876
+ default:
877
+ return receiptGatewayJsonResponse(
878
+ {
879
+ error: 'Unsupported receipt gateway action.',
880
+ action: body.action,
881
+ playName: scope.playName,
882
+ },
883
+ { status: 400 },
884
+ );
885
+ }
886
+ });
887
+ };
888
+ }