mayura 0.1.0-dev.0 → 1.0.0-rc.2

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 (578) hide show
  1. package/README.md +152 -35
  2. package/docs/README.md +82 -0
  3. package/docs/ai-agents.md +73 -0
  4. package/docs/cli/dev.md +111 -0
  5. package/docs/cli/init.md +192 -0
  6. package/docs/cli/operations.md +235 -0
  7. package/docs/cli/overview.md +129 -0
  8. package/docs/cli/run.md +182 -0
  9. package/docs/concepts/agent.md +197 -0
  10. package/docs/concepts/costs-and-budgets.md +177 -0
  11. package/docs/concepts/outcomes.md +154 -0
  12. package/docs/concepts/permissions.md +155 -0
  13. package/docs/concepts/runtime.md +172 -0
  14. package/docs/concepts/tools.md +202 -0
  15. package/docs/concepts/workflows.md +134 -0
  16. package/docs/guides/approvals-and-human-input.md +278 -0
  17. package/docs/guides/artifacts.md +123 -0
  18. package/docs/guides/child-agents.md +158 -0
  19. package/docs/guides/code-mode.md +233 -0
  20. package/docs/guides/deployment.md +644 -0
  21. package/docs/guides/durable-workflows.md +463 -0
  22. package/docs/guides/guardrails.md +205 -0
  23. package/docs/guides/helpers.md +176 -0
  24. package/docs/guides/lifecycle-hooks.md +187 -0
  25. package/docs/guides/mcp.md +123 -0
  26. package/docs/guides/memory-and-context.md +293 -0
  27. package/docs/guides/model-providers.md +371 -0
  28. package/docs/guides/model-routing.md +138 -0
  29. package/docs/guides/observability.md +238 -0
  30. package/docs/guides/operator-console.md +140 -0
  31. package/docs/guides/react.md +276 -0
  32. package/docs/guides/sagas-and-loops.md +212 -0
  33. package/docs/guides/server-and-client.md +559 -0
  34. package/docs/guides/skills.md +152 -0
  35. package/docs/guides/storage.md +251 -0
  36. package/docs/guides/streaming.md +146 -0
  37. package/docs/guides/terminal.md +166 -0
  38. package/docs/guides/testing.md +220 -0
  39. package/docs/guides/vision.md +155 -0
  40. package/docs/guides/webhooks.md +172 -0
  41. package/docs/guides/workflow-composition.md +141 -0
  42. package/docs/guides/workflow-operations.md +269 -0
  43. package/docs/installation.md +90 -0
  44. package/docs/introduction.md +74 -0
  45. package/docs/project/credits.md +78 -0
  46. package/docs/project/security.md +178 -0
  47. package/docs/project/support.md +91 -0
  48. package/docs/project/versioning.md +122 -0
  49. package/docs/quickstart.md +190 -0
  50. package/docs/reference/entry-points.md +146 -0
  51. package/lib/adapter-code-docker/dist/index.d.ts +8 -1
  52. package/lib/adapter-code-docker/dist/index.d.ts.map +1 -1
  53. package/lib/adapter-code-docker/dist/index.js +64 -67
  54. package/lib/adapter-code-docker/dist/index.js.map +1 -1
  55. package/lib/adapter-code-docker/dist/options.d.ts +15 -0
  56. package/lib/adapter-code-docker/dist/options.d.ts.map +1 -0
  57. package/lib/adapter-code-docker/dist/options.js +56 -0
  58. package/lib/adapter-code-docker/dist/options.js.map +1 -0
  59. package/lib/adapter-code-docker/image/Dockerfile +4 -2
  60. package/lib/adapter-code-docker/package.json +1 -1
  61. package/lib/adapter-code-docker/src/index.ts +63 -65
  62. package/lib/adapter-code-docker/src/options.ts +51 -0
  63. package/lib/adapter-code-quickjs/dist/index.d.ts +16 -4
  64. package/lib/adapter-code-quickjs/dist/index.d.ts.map +1 -1
  65. package/lib/adapter-code-quickjs/dist/index.js +94 -50
  66. package/lib/adapter-code-quickjs/dist/index.js.map +1 -1
  67. package/lib/adapter-code-quickjs/dist/worker-command.d.ts +27 -0
  68. package/lib/adapter-code-quickjs/dist/worker-command.d.ts.map +1 -0
  69. package/lib/adapter-code-quickjs/dist/worker-command.js +66 -0
  70. package/lib/adapter-code-quickjs/dist/worker-command.js.map +1 -0
  71. package/lib/adapter-code-quickjs/dist/worker.js +421 -104
  72. package/lib/adapter-code-quickjs/dist/worker.js.map +1 -1
  73. package/lib/adapter-code-quickjs/package.json +1 -1
  74. package/lib/adapter-code-quickjs/src/index.ts +88 -44
  75. package/lib/adapter-code-quickjs/src/worker-command.ts +68 -0
  76. package/lib/adapter-code-quickjs/src/worker.ts +315 -89
  77. package/lib/adapter-mcp/package.json +1 -1
  78. package/lib/artifacts/dist/contracts.d.ts +6 -2
  79. package/lib/artifacts/dist/contracts.d.ts.map +1 -1
  80. package/lib/artifacts/dist/contracts.js.map +1 -1
  81. package/lib/artifacts/dist/index.d.ts +1 -0
  82. package/lib/artifacts/dist/index.d.ts.map +1 -1
  83. package/lib/artifacts/dist/index.js +1 -0
  84. package/lib/artifacts/dist/index.js.map +1 -1
  85. package/lib/artifacts/dist/local-store.d.ts.map +1 -1
  86. package/lib/artifacts/dist/local-store.js +4 -7
  87. package/lib/artifacts/dist/local-store.js.map +1 -1
  88. package/lib/artifacts/dist/media.d.ts +11 -0
  89. package/lib/artifacts/dist/media.d.ts.map +1 -0
  90. package/lib/artifacts/dist/media.js +18 -0
  91. package/lib/artifacts/dist/media.js.map +1 -0
  92. package/lib/artifacts/package.json +1 -1
  93. package/lib/artifacts/src/contracts.ts +6 -2
  94. package/lib/artifacts/src/index.ts +1 -0
  95. package/lib/artifacts/src/local-store.ts +5 -7
  96. package/lib/artifacts/src/media.ts +20 -0
  97. package/lib/cli/dist/agent-guide.d.ts +10 -0
  98. package/lib/cli/dist/agent-guide.d.ts.map +1 -0
  99. package/lib/cli/dist/agent-guide.js +48 -0
  100. package/lib/cli/dist/agent-guide.js.map +1 -0
  101. package/lib/cli/dist/application.d.ts +24 -0
  102. package/lib/cli/dist/application.d.ts.map +1 -1
  103. package/lib/cli/dist/application.js +21 -0
  104. package/lib/cli/dist/application.js.map +1 -1
  105. package/lib/cli/dist/bin.js +26 -6
  106. package/lib/cli/dist/bin.js.map +1 -1
  107. package/lib/cli/dist/dev.d.ts.map +1 -1
  108. package/lib/cli/dist/dev.js +7 -1
  109. package/lib/cli/dist/dev.js.map +1 -1
  110. package/lib/cli/dist/index.d.ts +3 -3
  111. package/lib/cli/dist/index.d.ts.map +1 -1
  112. package/lib/cli/dist/index.js +19 -9
  113. package/lib/cli/dist/index.js.map +1 -1
  114. package/lib/cli/dist/interactive.d.ts.map +1 -1
  115. package/lib/cli/dist/interactive.js +52 -11
  116. package/lib/cli/dist/interactive.js.map +1 -1
  117. package/lib/cli/dist/operations.d.ts +25 -2
  118. package/lib/cli/dist/operations.d.ts.map +1 -1
  119. package/lib/cli/dist/operations.js +125 -12
  120. package/lib/cli/dist/operations.js.map +1 -1
  121. package/lib/cli/dist/output.d.ts.map +1 -1
  122. package/lib/cli/dist/output.js +3 -0
  123. package/lib/cli/dist/output.js.map +1 -1
  124. package/lib/cli/dist/providers.d.ts +34 -4
  125. package/lib/cli/dist/providers.d.ts.map +1 -1
  126. package/lib/cli/dist/providers.js +26 -5
  127. package/lib/cli/dist/providers.js.map +1 -1
  128. package/lib/cli/package.json +1 -1
  129. package/lib/cli/src/agent-guide.ts +47 -0
  130. package/lib/cli/src/application.ts +24 -0
  131. package/lib/cli/src/bin.ts +22 -5
  132. package/lib/cli/src/dev.ts +5 -1
  133. package/lib/cli/src/index.ts +18 -10
  134. package/lib/cli/src/interactive.ts +44 -12
  135. package/lib/cli/src/operations.ts +82 -12
  136. package/lib/cli/src/output.ts +3 -0
  137. package/lib/cli/src/providers.ts +45 -10
  138. package/lib/cli/starters/approval-workflow/dot-env.example +11 -0
  139. package/lib/cli/starters/approval-workflow/package.json +1 -2
  140. package/lib/cli/starters/approval-workflow/src/config.ts +25 -7
  141. package/lib/cli/starters/approval-workflow/src/intake.ts +1 -2
  142. package/lib/cli/starters/approval-workflow/src/model.ts +11 -4
  143. package/lib/cli/starters/approval-workflow/src/workflow.ts +1 -2
  144. package/lib/cli/starters/cli-agent/README.md +121 -0
  145. package/lib/cli/starters/cli-agent/dot-env.example +37 -0
  146. package/lib/cli/starters/cli-agent/dot-github/workflows/ci.yml +13 -0
  147. package/lib/cli/starters/cli-agent/dot-gitignore +10 -0
  148. package/lib/cli/starters/cli-agent/mayura.project.json +15 -0
  149. package/lib/cli/starters/cli-agent/package.json +28 -0
  150. package/lib/cli/starters/cli-agent/skills/release-notes/SKILL.md +18 -0
  151. package/lib/cli/starters/cli-agent/skills/release-notes/references/example.md +12 -0
  152. package/lib/cli/starters/cli-agent/src/assistant.ts +124 -0
  153. package/lib/cli/starters/cli-agent/src/cli.ts +72 -0
  154. package/lib/cli/starters/cli-agent/src/config.ts +117 -0
  155. package/lib/cli/starters/cli-agent/src/model.ts +34 -0
  156. package/lib/cli/starters/cli-agent/src/workspace.ts +170 -0
  157. package/lib/cli/starters/cli-agent/test/assistant.test.ts +205 -0
  158. package/lib/cli/starters/cli-agent/tsconfig.json +20 -0
  159. package/lib/cli/starters/event-automation/README.md +4 -3
  160. package/lib/cli/starters/event-automation/dot-env.example +11 -0
  161. package/lib/cli/starters/event-automation/package.json +1 -2
  162. package/lib/cli/starters/event-automation/src/config.ts +25 -7
  163. package/lib/cli/starters/event-automation/src/ingress.ts +3 -5
  164. package/lib/cli/starters/event-automation/src/model.ts +11 -4
  165. package/lib/cli/starters/event-automation/src/send-sample.ts +1 -1
  166. package/lib/cli/starters/event-automation/src/tracker/main.ts +1 -1
  167. package/lib/cli/starters/event-automation/src/tracker/mcp-server.ts +1 -1
  168. package/lib/cli/starters/event-automation/src/tracker/tickets.ts +1 -1
  169. package/lib/cli/starters/event-automation/src/tracker-tools.ts +1 -1
  170. package/lib/cli/starters/event-automation/src/triage.ts +15 -22
  171. package/lib/cli/starters/event-automation/src/workflows.ts +1 -1
  172. package/lib/cli/starters/event-automation/test/automation.test.ts +3 -3
  173. package/lib/cli/starters/research-team/README.md +2 -2
  174. package/lib/cli/starters/research-team/dot-env.example +11 -0
  175. package/lib/cli/starters/research-team/package.json +1 -2
  176. package/lib/cli/starters/research-team/src/config.ts +25 -7
  177. package/lib/cli/starters/research-team/src/desk.ts +1 -2
  178. package/lib/cli/starters/research-team/src/library/index.ts +1 -2
  179. package/lib/cli/starters/research-team/src/model.ts +11 -4
  180. package/lib/cli/starters/research-team/src/services.ts +1 -1
  181. package/lib/cli/starters/research-team/src/team.ts +1 -2
  182. package/lib/cli/starters/research-team/src/workflow.ts +45 -59
  183. package/lib/cli/starters/support-agent/dot-env.example +11 -0
  184. package/lib/cli/starters/support-agent/package.json +1 -2
  185. package/lib/cli/starters/support-agent/src/assistant.ts +5 -5
  186. package/lib/cli/starters/support-agent/src/config.ts +25 -7
  187. package/lib/cli/starters/support-agent/src/guardrails.ts +3 -1
  188. package/lib/cli/starters/support-agent/src/model.ts +11 -4
  189. package/lib/cli/starters/support-agent/src/returns.ts +1 -2
  190. package/lib/cli/starters/support-agent/test/support.test.ts +25 -1
  191. package/lib/cli/templates/basic-agent.ts +1 -2
  192. package/lib/cli/templates/capability-policy.ts +1 -2
  193. package/lib/cli/templates/code-mode-workflow.ts +1 -1
  194. package/lib/cli/templates/durable-approval.ts +1 -1
  195. package/lib/cli/templates/parallel-research.ts +1 -2
  196. package/lib/cli/templates/typed-tool-runner.ts +1 -2
  197. package/lib/client/dist/forms.d.ts.map +1 -1
  198. package/lib/client/dist/forms.js +3 -4
  199. package/lib/client/dist/forms.js.map +1 -1
  200. package/lib/client/dist/headless.d.ts +3 -1
  201. package/lib/client/dist/headless.d.ts.map +1 -1
  202. package/lib/client/dist/headless.js +10 -6
  203. package/lib/client/dist/headless.js.map +1 -1
  204. package/lib/client/dist/index.d.ts +95 -6
  205. package/lib/client/dist/index.d.ts.map +1 -1
  206. package/lib/client/dist/index.js +397 -124
  207. package/lib/client/dist/index.js.map +1 -1
  208. package/lib/client/dist/workflows.d.ts +1 -1
  209. package/lib/client/dist/workflows.d.ts.map +1 -1
  210. package/lib/client/dist/workflows.js +7 -6
  211. package/lib/client/dist/workflows.js.map +1 -1
  212. package/lib/client/package.json +1 -1
  213. package/lib/client/src/forms.ts +3 -4
  214. package/lib/client/src/headless.ts +13 -7
  215. package/lib/client/src/index.ts +344 -74
  216. package/lib/client/src/workflows.ts +8 -7
  217. package/lib/client-react/package.json +1 -1
  218. package/lib/code-mode/dist/index.d.ts +32 -1
  219. package/lib/code-mode/dist/index.d.ts.map +1 -1
  220. package/lib/code-mode/dist/index.js +289 -221
  221. package/lib/code-mode/dist/index.js.map +1 -1
  222. package/lib/code-mode/package.json +1 -1
  223. package/lib/code-mode/src/index.ts +288 -184
  224. package/lib/code-mode-workflows/package.json +1 -1
  225. package/lib/context/package.json +1 -1
  226. package/lib/core/dist/budget.d.ts.map +1 -1
  227. package/lib/core/dist/budget.js +17 -2
  228. package/lib/core/dist/budget.js.map +1 -1
  229. package/lib/core/dist/contracts.d.ts +57 -0
  230. package/lib/core/dist/contracts.d.ts.map +1 -1
  231. package/lib/core/dist/contracts.js +36 -0
  232. package/lib/core/dist/contracts.js.map +1 -1
  233. package/lib/core/dist/destination.d.ts +12 -0
  234. package/lib/core/dist/destination.d.ts.map +1 -0
  235. package/lib/core/dist/destination.js +37 -0
  236. package/lib/core/dist/destination.js.map +1 -0
  237. package/lib/core/dist/event-stream.d.ts +1 -1
  238. package/lib/core/dist/event-stream.d.ts.map +1 -1
  239. package/lib/core/dist/event-stream.js +7 -0
  240. package/lib/core/dist/event-stream.js.map +1 -1
  241. package/lib/core/dist/host.d.ts +3 -0
  242. package/lib/core/dist/host.d.ts.map +1 -1
  243. package/lib/core/dist/host.js +3 -0
  244. package/lib/core/dist/host.js.map +1 -1
  245. package/lib/core/dist/index.d.ts +2 -0
  246. package/lib/core/dist/index.d.ts.map +1 -1
  247. package/lib/core/dist/index.js +2 -0
  248. package/lib/core/dist/index.js.map +1 -1
  249. package/lib/core/dist/media.d.ts +98 -0
  250. package/lib/core/dist/media.d.ts.map +1 -0
  251. package/lib/core/dist/media.js +227 -0
  252. package/lib/core/dist/media.js.map +1 -0
  253. package/lib/core/dist/model-schema.d.ts +37 -0
  254. package/lib/core/dist/model-schema.d.ts.map +1 -0
  255. package/lib/core/dist/model-schema.js +154 -0
  256. package/lib/core/dist/model-schema.js.map +1 -0
  257. package/lib/core/package.json +1 -1
  258. package/lib/core/src/budget.ts +17 -2
  259. package/lib/core/src/contracts.ts +71 -3
  260. package/lib/core/src/destination.ts +33 -0
  261. package/lib/core/src/event-stream.ts +5 -1
  262. package/lib/core/src/host.ts +3 -0
  263. package/lib/core/src/index.ts +2 -0
  264. package/lib/core/src/media.ts +228 -0
  265. package/lib/core/src/model-schema.ts +129 -0
  266. package/lib/exporter-otlp/dist/otlp-http-json.js +1 -1
  267. package/lib/exporter-otlp/dist/otlp-http-json.js.map +1 -1
  268. package/lib/exporter-otlp/dist/signals.js +2 -2
  269. package/lib/exporter-otlp/dist/signals.js.map +1 -1
  270. package/lib/exporter-otlp/package.json +1 -1
  271. package/lib/exporter-otlp/src/otlp-http-json.ts +1 -1
  272. package/lib/exporter-otlp/src/signals.ts +2 -2
  273. package/lib/guardrails/package.json +1 -1
  274. package/lib/helpers/package.json +1 -1
  275. package/lib/memory/dist/index.js +1 -1
  276. package/lib/memory/dist/index.js.map +1 -1
  277. package/lib/memory/dist/native.d.ts.map +1 -1
  278. package/lib/memory/dist/native.js +4 -3
  279. package/lib/memory/dist/native.js.map +1 -1
  280. package/lib/memory/package.json +1 -1
  281. package/lib/memory/src/index.ts +1 -1
  282. package/lib/memory/src/native.ts +4 -3
  283. package/lib/memory-remote/package.json +1 -1
  284. package/lib/observability/package.json +1 -1
  285. package/lib/provider-anthropic/dist/index.d.ts +36 -3
  286. package/lib/provider-anthropic/dist/index.d.ts.map +1 -1
  287. package/lib/provider-anthropic/dist/index.js +128 -78
  288. package/lib/provider-anthropic/dist/index.js.map +1 -1
  289. package/lib/provider-anthropic/package.json +1 -1
  290. package/lib/provider-anthropic/src/index.ts +152 -76
  291. package/lib/provider-openai/dist/index.d.ts +71 -4
  292. package/lib/provider-openai/dist/index.d.ts.map +1 -1
  293. package/lib/provider-openai/dist/index.js +259 -96
  294. package/lib/provider-openai/dist/index.js.map +1 -1
  295. package/lib/provider-openai/package.json +1 -1
  296. package/lib/provider-openai/src/index.ts +282 -84
  297. package/lib/runtime/dist/agent.d.ts +18 -1
  298. package/lib/runtime/dist/agent.d.ts.map +1 -1
  299. package/lib/runtime/dist/agent.js +59 -3
  300. package/lib/runtime/dist/agent.js.map +1 -1
  301. package/lib/runtime/dist/composition.d.ts.map +1 -1
  302. package/lib/runtime/dist/composition.js +2 -1
  303. package/lib/runtime/dist/composition.js.map +1 -1
  304. package/lib/runtime/dist/hooks.d.ts +15 -3
  305. package/lib/runtime/dist/hooks.d.ts.map +1 -1
  306. package/lib/runtime/dist/hooks.js.map +1 -1
  307. package/lib/runtime/dist/index.d.ts +1 -1
  308. package/lib/runtime/dist/index.d.ts.map +1 -1
  309. package/lib/runtime/dist/index.js.map +1 -1
  310. package/lib/runtime/dist/response.d.ts +7 -1
  311. package/lib/runtime/dist/response.d.ts.map +1 -1
  312. package/lib/runtime/dist/response.js +23 -2
  313. package/lib/runtime/dist/response.js.map +1 -1
  314. package/lib/runtime/dist/router.d.ts +10 -3
  315. package/lib/runtime/dist/router.d.ts.map +1 -1
  316. package/lib/runtime/dist/router.js +45 -8
  317. package/lib/runtime/dist/router.js.map +1 -1
  318. package/lib/runtime/dist/runtime.d.ts +9 -1
  319. package/lib/runtime/dist/runtime.d.ts.map +1 -1
  320. package/lib/runtime/dist/runtime.js +50 -22
  321. package/lib/runtime/dist/runtime.js.map +1 -1
  322. package/lib/runtime/package.json +1 -1
  323. package/lib/runtime/src/agent.ts +69 -3
  324. package/lib/runtime/src/composition.ts +2 -1
  325. package/lib/runtime/src/hooks.ts +10 -4
  326. package/lib/runtime/src/index.ts +1 -1
  327. package/lib/runtime/src/response.ts +20 -2
  328. package/lib/runtime/src/router.ts +43 -10
  329. package/lib/runtime/src/runtime.ts +58 -27
  330. package/lib/sdk/dist/index.d.ts +9 -1
  331. package/lib/sdk/dist/index.d.ts.map +1 -1
  332. package/lib/sdk/dist/index.js +9 -1
  333. package/lib/sdk/dist/index.js.map +1 -1
  334. package/lib/sdk/package.json +1 -1
  335. package/lib/sdk/src/index.ts +9 -1
  336. package/lib/server/dist/index.d.ts +201 -3
  337. package/lib/server/dist/index.d.ts.map +1 -1
  338. package/lib/server/dist/index.js +701 -149
  339. package/lib/server/dist/index.js.map +1 -1
  340. package/lib/server/dist/inspector-bundle.d.ts +1 -1
  341. package/lib/server/dist/inspector-bundle.d.ts.map +1 -1
  342. package/lib/server/dist/inspector-bundle.js +4 -4
  343. package/lib/server/dist/inspector-bundle.js.map +1 -1
  344. package/lib/server/package.json +1 -1
  345. package/lib/server/src/index.ts +611 -135
  346. package/lib/server/src/inspector-bundle.ts +4 -4
  347. package/lib/server-node/dist/hardening.d.ts +1 -1
  348. package/lib/server-node/dist/hardening.d.ts.map +1 -1
  349. package/lib/server-node/dist/hardening.js +4 -2
  350. package/lib/server-node/dist/hardening.js.map +1 -1
  351. package/lib/server-node/dist/index.d.ts +2 -1
  352. package/lib/server-node/dist/index.d.ts.map +1 -1
  353. package/lib/server-node/dist/index.js.map +1 -1
  354. package/lib/server-node/dist/probe.js +2 -2
  355. package/lib/server-node/dist/probe.js.map +1 -1
  356. package/lib/server-node/dist/production.d.ts +8 -1
  357. package/lib/server-node/dist/production.d.ts.map +1 -1
  358. package/lib/server-node/dist/production.js +15 -2
  359. package/lib/server-node/dist/production.js.map +1 -1
  360. package/lib/server-node/package.json +1 -1
  361. package/lib/server-node/src/hardening.ts +5 -3
  362. package/lib/server-node/src/index.ts +2 -1
  363. package/lib/server-node/src/probe.ts +2 -2
  364. package/lib/server-node/src/production.ts +23 -3
  365. package/lib/skills/dist/index.d.ts +81 -0
  366. package/lib/skills/dist/index.d.ts.map +1 -0
  367. package/lib/skills/dist/index.js +311 -0
  368. package/lib/skills/dist/index.js.map +1 -0
  369. package/lib/skills/package.json +5 -0
  370. package/lib/skills/src/index.ts +260 -0
  371. package/lib/storage/dist/index.d.ts +1 -1
  372. package/lib/storage/dist/index.d.ts.map +1 -1
  373. package/lib/storage/dist/index.js.map +1 -1
  374. package/lib/storage/package.json +1 -1
  375. package/lib/storage/src/index.ts +1 -1
  376. package/lib/storage-contracts/dist/contracts.d.ts +12 -5
  377. package/lib/storage-contracts/dist/contracts.d.ts.map +1 -1
  378. package/lib/storage-contracts/dist/contracts.js +24 -6
  379. package/lib/storage-contracts/dist/contracts.js.map +1 -1
  380. package/lib/storage-contracts/dist/index.d.ts +2 -0
  381. package/lib/storage-contracts/dist/index.d.ts.map +1 -1
  382. package/lib/storage-contracts/dist/index.js +2 -0
  383. package/lib/storage-contracts/dist/index.js.map +1 -1
  384. package/lib/storage-contracts/dist/memory-contracts.js +1 -1
  385. package/lib/storage-contracts/dist/memory-contracts.js.map +1 -1
  386. package/lib/storage-contracts/dist/run-records.d.ts +100 -0
  387. package/lib/storage-contracts/dist/run-records.d.ts.map +1 -0
  388. package/lib/storage-contracts/dist/run-records.js +464 -0
  389. package/lib/storage-contracts/dist/run-records.js.map +1 -0
  390. package/lib/storage-contracts/dist/schema-digest.d.ts +17 -0
  391. package/lib/storage-contracts/dist/schema-digest.d.ts.map +1 -0
  392. package/lib/storage-contracts/dist/schema-digest.js +94 -0
  393. package/lib/storage-contracts/dist/schema-digest.js.map +1 -0
  394. package/lib/storage-contracts/dist/submission-journal.js +1 -1
  395. package/lib/storage-contracts/dist/submission-journal.js.map +1 -1
  396. package/lib/storage-contracts/dist/workflow-format5.d.ts +30 -2
  397. package/lib/storage-contracts/dist/workflow-format5.d.ts.map +1 -1
  398. package/lib/storage-contracts/dist/workflow-format5.js +57 -5
  399. package/lib/storage-contracts/dist/workflow-format5.js.map +1 -1
  400. package/lib/storage-contracts/package.json +1 -1
  401. package/lib/storage-contracts/src/contracts.ts +29 -5
  402. package/lib/storage-contracts/src/index.ts +2 -0
  403. package/lib/storage-contracts/src/memory-contracts.ts +1 -1
  404. package/lib/storage-contracts/src/run-records.ts +365 -0
  405. package/lib/storage-contracts/src/schema-digest.ts +71 -0
  406. package/lib/storage-contracts/src/submission-journal.ts +1 -1
  407. package/lib/storage-contracts/src/workflow-format5.ts +70 -6
  408. package/lib/storage-postgres/dist/index.d.ts +1 -1
  409. package/lib/storage-postgres/dist/index.d.ts.map +1 -1
  410. package/lib/storage-postgres/dist/index.js.map +1 -1
  411. package/lib/storage-postgres/dist/postgres.d.ts +15 -0
  412. package/lib/storage-postgres/dist/postgres.d.ts.map +1 -1
  413. package/lib/storage-postgres/dist/postgres.js +18 -7
  414. package/lib/storage-postgres/dist/postgres.js.map +1 -1
  415. package/lib/storage-postgres/package.json +1 -1
  416. package/lib/storage-postgres/src/index.ts +1 -1
  417. package/lib/storage-postgres/src/postgres.ts +34 -8
  418. package/lib/storage-sql/dist/aggregate-session.js +1 -1
  419. package/lib/storage-sql/dist/aggregate-session.js.map +1 -1
  420. package/lib/storage-sql/dist/scheduled-database.js +1 -1
  421. package/lib/storage-sql/dist/scheduled-database.js.map +1 -1
  422. package/lib/storage-sql/dist/workflow-tree-validation.js +1 -1
  423. package/lib/storage-sql/dist/workflow-tree-validation.js.map +1 -1
  424. package/lib/storage-sql/package.json +1 -1
  425. package/lib/storage-sql/src/aggregate-session.ts +1 -1
  426. package/lib/storage-sql/src/scheduled-database.ts +1 -1
  427. package/lib/storage-sql/src/workflow-tree-validation.ts +1 -1
  428. package/lib/storage-sqlite/dist/sqlite-database.js +4 -4
  429. package/lib/storage-sqlite/dist/sqlite-database.js.map +1 -1
  430. package/lib/storage-sqlite/dist/sqlite-worker.js +2 -2
  431. package/lib/storage-sqlite/dist/sqlite-worker.js.map +1 -1
  432. package/lib/storage-sqlite/dist/sqlite.js +1 -1
  433. package/lib/storage-sqlite/dist/sqlite.js.map +1 -1
  434. package/lib/storage-sqlite/package.json +1 -1
  435. package/lib/storage-sqlite/src/sqlite-database.ts +4 -4
  436. package/lib/storage-sqlite/src/sqlite-worker.ts +2 -2
  437. package/lib/storage-sqlite/src/sqlite.ts +1 -1
  438. package/lib/terminal/dist/index.d.ts +92 -0
  439. package/lib/terminal/dist/index.d.ts.map +1 -0
  440. package/lib/terminal/dist/index.js +397 -0
  441. package/lib/terminal/dist/index.js.map +1 -0
  442. package/lib/terminal/package.json +5 -0
  443. package/lib/terminal/src/index.ts +273 -0
  444. package/lib/testing/dist/index.d.ts +44 -1
  445. package/lib/testing/dist/index.d.ts.map +1 -1
  446. package/lib/testing/dist/index.js +63 -10
  447. package/lib/testing/dist/index.js.map +1 -1
  448. package/lib/testing/package.json +1 -1
  449. package/lib/testing/src/index.ts +83 -10
  450. package/lib/tools/dist/index.d.ts +32 -4
  451. package/lib/tools/dist/index.d.ts.map +1 -1
  452. package/lib/tools/dist/index.js +64 -11
  453. package/lib/tools/dist/index.js.map +1 -1
  454. package/lib/tools/package.json +1 -1
  455. package/lib/tools/src/index.ts +74 -13
  456. package/lib/workflows/dist/abandoned.d.ts +15 -0
  457. package/lib/workflows/dist/abandoned.d.ts.map +1 -0
  458. package/lib/workflows/dist/abandoned.js +33 -0
  459. package/lib/workflows/dist/abandoned.js.map +1 -0
  460. package/lib/workflows/dist/agent-step.d.ts +83 -0
  461. package/lib/workflows/dist/agent-step.d.ts.map +1 -0
  462. package/lib/workflows/dist/agent-step.js +161 -0
  463. package/lib/workflows/dist/agent-step.js.map +1 -0
  464. package/lib/workflows/dist/children-runtime.js +8 -8
  465. package/lib/workflows/dist/children-runtime.js.map +1 -1
  466. package/lib/workflows/dist/composite-fleet.js +2 -2
  467. package/lib/workflows/dist/composite-fleet.js.map +1 -1
  468. package/lib/workflows/dist/composite-host.d.ts.map +1 -1
  469. package/lib/workflows/dist/composite-host.js +26 -2
  470. package/lib/workflows/dist/composite-host.js.map +1 -1
  471. package/lib/workflows/dist/hook-relay.js +2 -2
  472. package/lib/workflows/dist/hook-relay.js.map +1 -1
  473. package/lib/workflows/dist/index.d.ts +1 -1
  474. package/lib/workflows/dist/index.d.ts.map +1 -1
  475. package/lib/workflows/dist/index.js.map +1 -1
  476. package/lib/workflows/dist/leadership.js +3 -3
  477. package/lib/workflows/dist/leadership.js.map +1 -1
  478. package/lib/workflows/dist/lifecycle-definition.d.ts +26 -4
  479. package/lib/workflows/dist/lifecycle-definition.d.ts.map +1 -1
  480. package/lib/workflows/dist/lifecycle-definition.js +31 -6
  481. package/lib/workflows/dist/lifecycle-definition.js.map +1 -1
  482. package/lib/workflows/dist/lifecycle-fleet.d.ts.map +1 -1
  483. package/lib/workflows/dist/lifecycle-fleet.js +9 -11
  484. package/lib/workflows/dist/lifecycle-fleet.js.map +1 -1
  485. package/lib/workflows/dist/lifecycle-host.d.ts.map +1 -1
  486. package/lib/workflows/dist/lifecycle-host.js +26 -2
  487. package/lib/workflows/dist/lifecycle-host.js.map +1 -1
  488. package/lib/workflows/dist/lifecycle-human-transport.d.ts +22 -2
  489. package/lib/workflows/dist/lifecycle-human-transport.d.ts.map +1 -1
  490. package/lib/workflows/dist/lifecycle-human-transport.js +115 -33
  491. package/lib/workflows/dist/lifecycle-human-transport.js.map +1 -1
  492. package/lib/workflows/dist/lifecycle-runtime.d.ts +62 -1
  493. package/lib/workflows/dist/lifecycle-runtime.d.ts.map +1 -1
  494. package/lib/workflows/dist/lifecycle-runtime.js +268 -64
  495. package/lib/workflows/dist/lifecycle-runtime.js.map +1 -1
  496. package/lib/workflows/dist/lifecycle.d.ts +6 -4
  497. package/lib/workflows/dist/lifecycle.d.ts.map +1 -1
  498. package/lib/workflows/dist/lifecycle.js +2 -0
  499. package/lib/workflows/dist/lifecycle.js.map +1 -1
  500. package/lib/workflows/dist/loop-runtime.d.ts.map +1 -1
  501. package/lib/workflows/dist/loop-runtime.js +38 -26
  502. package/lib/workflows/dist/loop-runtime.js.map +1 -1
  503. package/lib/workflows/dist/migration.d.ts +1 -1
  504. package/lib/workflows/dist/migration.d.ts.map +1 -1
  505. package/lib/workflows/dist/migration.js +3 -3
  506. package/lib/workflows/dist/migration.js.map +1 -1
  507. package/lib/workflows/dist/operator-transports.d.ts +24 -2
  508. package/lib/workflows/dist/operator-transports.d.ts.map +1 -1
  509. package/lib/workflows/dist/operator-transports.js +49 -3
  510. package/lib/workflows/dist/operator-transports.js.map +1 -1
  511. package/lib/workflows/dist/runtime.d.ts.map +1 -1
  512. package/lib/workflows/dist/runtime.js +34 -22
  513. package/lib/workflows/dist/runtime.js.map +1 -1
  514. package/lib/workflows/dist/saga-runtime.d.ts.map +1 -1
  515. package/lib/workflows/dist/saga-runtime.js +44 -30
  516. package/lib/workflows/dist/saga-runtime.js.map +1 -1
  517. package/lib/workflows/dist/scheduled-helpers.d.ts.map +1 -1
  518. package/lib/workflows/dist/scheduled-helpers.js +3 -3
  519. package/lib/workflows/dist/scheduled-helpers.js.map +1 -1
  520. package/lib/workflows/dist/storage-failure.d.ts +16 -0
  521. package/lib/workflows/dist/storage-failure.d.ts.map +1 -0
  522. package/lib/workflows/dist/storage-failure.js +38 -0
  523. package/lib/workflows/dist/storage-failure.js.map +1 -0
  524. package/lib/workflows/dist/sweep-position.d.ts +22 -0
  525. package/lib/workflows/dist/sweep-position.d.ts.map +1 -0
  526. package/lib/workflows/dist/sweep-position.js +45 -0
  527. package/lib/workflows/dist/sweep-position.js.map +1 -0
  528. package/lib/workflows/dist/traces.js +2 -2
  529. package/lib/workflows/dist/traces.js.map +1 -1
  530. package/lib/workflows/dist/worker.d.ts +31 -0
  531. package/lib/workflows/dist/worker.d.ts.map +1 -1
  532. package/lib/workflows/dist/worker.js +94 -0
  533. package/lib/workflows/dist/worker.js.map +1 -1
  534. package/lib/workflows/package.json +1 -1
  535. package/lib/workflows/src/abandoned.ts +32 -0
  536. package/lib/workflows/src/agent-step.ts +199 -0
  537. package/lib/workflows/src/children-runtime.ts +8 -8
  538. package/lib/workflows/src/composite-fleet.ts +2 -2
  539. package/lib/workflows/src/composite-host.ts +21 -3
  540. package/lib/workflows/src/hook-relay.ts +2 -2
  541. package/lib/workflows/src/index.ts +2 -1
  542. package/lib/workflows/src/leadership.ts +3 -3
  543. package/lib/workflows/src/lifecycle-definition.ts +50 -9
  544. package/lib/workflows/src/lifecycle-fleet.ts +7 -8
  545. package/lib/workflows/src/lifecycle-host.ts +21 -5
  546. package/lib/workflows/src/lifecycle-human-transport.ts +110 -26
  547. package/lib/workflows/src/lifecycle-runtime.ts +270 -60
  548. package/lib/workflows/src/lifecycle.ts +7 -0
  549. package/lib/workflows/src/loop-runtime.ts +34 -25
  550. package/lib/workflows/src/migration.ts +2 -2
  551. package/lib/workflows/src/operator-transports.ts +48 -4
  552. package/lib/workflows/src/runtime.ts +28 -22
  553. package/lib/workflows/src/saga-runtime.ts +38 -28
  554. package/lib/workflows/src/scheduled-helpers.ts +3 -3
  555. package/lib/workflows/src/storage-failure.ts +37 -0
  556. package/lib/workflows/src/sweep-position.ts +52 -0
  557. package/lib/workflows/src/traces.ts +2 -2
  558. package/lib/workflows/src/worker.ts +79 -1
  559. package/lib/workstream/dist/humans.d.ts +7 -3
  560. package/lib/workstream/dist/humans.d.ts.map +1 -1
  561. package/lib/workstream/dist/humans.js +13 -2
  562. package/lib/workstream/dist/humans.js.map +1 -1
  563. package/lib/workstream/dist/index.js +2 -2
  564. package/lib/workstream/dist/index.js.map +1 -1
  565. package/lib/workstream/dist/timers.js +2 -2
  566. package/lib/workstream/dist/timers.js.map +1 -1
  567. package/lib/workstream/dist/webhooks.d.ts +6 -2
  568. package/lib/workstream/dist/webhooks.d.ts.map +1 -1
  569. package/lib/workstream/dist/webhooks.js +17 -7
  570. package/lib/workstream/dist/webhooks.js.map +1 -1
  571. package/lib/workstream/package.json +1 -1
  572. package/lib/workstream/src/humans.ts +15 -5
  573. package/lib/workstream/src/index.ts +2 -2
  574. package/lib/workstream/src/timers.ts +2 -2
  575. package/lib/workstream/src/webhooks.ts +21 -8
  576. package/llms-full.txt +9766 -0
  577. package/llms.txt +92 -0
  578. package/package.json +18 -6
@@ -1,7 +1,8 @@
1
1
  import { freezeJson, jsonValue, MayuraError, validate } from '../../core/dist/index.js';
2
2
  import { StorageError, assertWorkflowSagaStateMatchesManifest, initialWorkflowSagaState, workflowSagaState } from '../../storage-contracts/dist/index.js';
3
3
  import { digest, resolveBinding } from './definition.js';
4
- import { createWorkflowLifecycleRuntime } from './lifecycle-runtime.js';
4
+ import { createSubmission, workflowStorageFailure } from './storage-failure.js';
5
+ import { createWorkflowLifecycleRuntime, submitWorkflowLifecycleUnder, unknownWorkflowPolicy, workflowPolicyDigest, workflowPolicySettings } from './lifecycle-runtime.js';
5
6
  import { assertWorkflowSaga, sagaManifest } from './saga-definition.js';
6
7
  import { assertMigrationAllowed, assertWorkflowMigration, migrationCommand, migrationEvent, nodeFingerprint, planWorkflowMigration } from './migration.js';
7
8
  const hashPattern = /^[a-f0-9]{64}$/;
@@ -13,9 +14,7 @@ async function storageCall(operation) {
13
14
  return await operation();
14
15
  }
15
16
  catch (error) {
16
- if (error instanceof StorageError && error.code === 'CONFLICT')
17
- throw error;
18
- throw new MayuraError('STORAGE_UNAVAILABLE', 'Workflow saga storage is unavailable; inspect current state before retrying.');
17
+ throw workflowStorageFailure(error, 'workflow saga run');
19
18
  }
20
19
  }
21
20
  function decoded(record) {
@@ -68,14 +67,22 @@ export function createWorkflowSagaRuntime(options) {
68
67
  }
69
68
  const lifecycle = createWorkflowLifecycleRuntime(options);
70
69
  const scopeKey = digest('mayura:scope:v1', scope);
71
- const policy = digest('mayura:workflow-saga-policy:v1', { scope, permissions: [...options.permissions.allow].sort(),
72
- policyVersion: options.policyVersion, maxCostMicros: options.maxCostMicros, maxOutputBytes,
73
- approvalTtlMs: options.approvalTtlMs ?? 3_600_000 });
70
+ // Index n of `settings` and of `policies` is the same policy the lifecycle runtime knows at index n.
71
+ const settings = workflowPolicySettings(options);
72
+ const policies = settings.map(entry => workflowPolicyDigest('mayura:workflow-saga-policy:v1', scope, entry));
73
+ const policy = policies[0];
74
+ /** Index of the policy a saga was started with; its later children and limits keep that policy. */
75
+ const pinnedIndex = (state) => {
76
+ const index = policies.indexOf(state.policy);
77
+ if (index < 0)
78
+ throw unknownWorkflowPolicy();
79
+ return index;
80
+ };
74
81
  let closed = false;
75
82
  const ensureOpen = () => { if (closed)
76
83
  throw new MayuraError('CANCELLED', 'Workflow saga runtime is closed.'); };
77
84
  let pendingCallbacks = 0;
78
- const boundedValidate = async (schema, value, boundary) => {
85
+ const boundedValidate = async (schema, value, boundary, maxBytes = maxOutputBytes) => {
79
86
  if (pendingCallbacks >= maxPendingCallbacks)
80
87
  throw new MayuraError('LIMIT_EXCEEDED', 'Saga callback capacity is full.');
81
88
  pendingCallbacks += 1;
@@ -84,20 +91,21 @@ export function createWorkflowSagaRuntime(options) {
84
91
  released = true;
85
92
  pendingCallbacks -= 1;
86
93
  } };
87
- const validation = Promise.resolve().then(() => validate(schema, value, boundary, { maxBytes: maxOutputBytes }));
94
+ const validation = Promise.resolve().then(() => validate(schema, value, boundary, { maxBytes }));
88
95
  void validation.then(release, release);
89
96
  let timer;
90
97
  try {
91
98
  const checked = await Promise.race([validation,
92
99
  new Promise((_resolve, reject) => { timer = setTimeout(() => reject(new MayuraError('TIMEOUT', 'Saga schema validation timed out.')), callbackTimeoutMs); })]);
93
- return jsonValue(checked, { maxBytes: maxOutputBytes });
100
+ return jsonValue(checked, { maxBytes });
94
101
  }
95
102
  finally {
96
103
  if (timer !== undefined)
97
104
  clearTimeout(timer);
98
105
  }
99
106
  };
100
- const load = async (id) => {
107
+ /** `anyPolicy` admits operator controls (pause, resume, cancel, migrate) on a saga whose settings are not listed. */
108
+ const load = async (id, anyPolicy = false) => {
101
109
  ensureOpen();
102
110
  if (typeof id !== 'string' || !hashPattern.test(id))
103
111
  throw new MayuraError('INVALID_INPUT', 'A workflow saga run ID is required.');
@@ -107,14 +115,16 @@ export function createWorkflowSagaRuntime(options) {
107
115
  if (record.scope !== scopeKey || record.id !== id)
108
116
  throw new MayuraError('CONFLICT', 'Stored saga identity does not match its requested scope.');
109
117
  const state = decoded(record);
110
- if (state.policy !== policy)
111
- throw new MayuraError('CONFLICT', 'Stored saga policy does not match this runtime.');
118
+ if (!anyPolicy)
119
+ pinnedIndex(state);
112
120
  return record;
113
121
  };
114
- const verify = (definition, record, state) => {
115
- if (record.definitionHash !== definition.digest || state.definition !== definition.digest || state.policy !== policy) {
116
- throw new MayuraError('CONFLICT', 'Workflow saga definition or policy does not match persisted state.');
122
+ const verify = (definition, record, state, anyPolicy = false) => {
123
+ if (record.definitionHash !== definition.digest || state.definition !== definition.digest) {
124
+ throw new MayuraError('CONFLICT', 'Workflow saga definition does not match persisted state.');
117
125
  }
126
+ if (!anyPolicy)
127
+ pinnedIndex(state);
118
128
  try {
119
129
  assertWorkflowSagaStateMatchesManifest(state, sagaManifest(definition));
120
130
  }
@@ -124,9 +134,9 @@ export function createWorkflowSagaRuntime(options) {
124
134
  };
125
135
  const save = (record, state, type, data = {}) => storageCall(() => store.update({ scope: scopeKey, id: record.id, expectedVersion: record.version,
126
136
  state: jsonValue(state), events: [{ type, data }] }));
127
- const mutate = async (id, transition, type, data = {}) => {
137
+ const mutate = async (id, transition, type, data = {}, anyPolicy = false) => {
128
138
  for (let attempt = 0; attempt < 32; attempt++) {
129
- const record = await load(id);
139
+ const record = await load(id, anyPolicy);
130
140
  const state = decoded(record);
131
141
  const paused = state.status === 'paused';
132
142
  if (!transition(state))
@@ -138,7 +148,7 @@ export function createWorkflowSagaRuntime(options) {
138
148
  return await save(record, state, type, data);
139
149
  }
140
150
  catch (error) {
141
- if (!(error instanceof StorageError) || error.code !== 'CONFLICT')
151
+ if (!(error instanceof StorageError) || error.storageCode !== 'CONFLICT')
142
152
  throw error;
143
153
  }
144
154
  }
@@ -163,7 +173,7 @@ export function createWorkflowSagaRuntime(options) {
163
173
  const workflow = phase === 'forward' ? step.forward : step.compensation.workflow;
164
174
  const binding = phase === 'forward' ? step.input : step.compensation.input;
165
175
  const input = resolveBinding(binding, state.input, outputs(state));
166
- return lifecycle.submit(workflow, { input, idempotencyKey: childKey(runId, step.id, phase) });
176
+ return submitWorkflowLifecycleUnder(lifecycle, pinnedIndex(state), workflow, { input, idempotencyKey: childKey(runId, step.id, phase) });
167
177
  };
168
178
  const run = async (definition, id) => {
169
179
  assertWorkflowSaga(definition);
@@ -179,7 +189,7 @@ export function createWorkflowSagaRuntime(options) {
179
189
  if (!step) {
180
190
  let output;
181
191
  try {
182
- output = await boundedValidate(definition.output, resolveBinding(definition.result, state.input, outputs(state)), 'output');
192
+ output = await boundedValidate(definition.output, resolveBinding(definition.result, state.input, outputs(state)), 'output', settings[pinnedIndex(state)].maxOutputBytes);
183
193
  }
184
194
  catch (error) {
185
195
  if (!(error instanceof MayuraError) || !['INVALID_INPUT', 'INVALID_OUTPUT'].includes(error.code))
@@ -379,9 +389,9 @@ export function createWorkflowSagaRuntime(options) {
379
389
  const input = await boundedValidate(definition.input, raw, 'input');
380
390
  const state = initialWorkflowSagaState(sagaManifest(definition), input, definition.digest, policy, options.maxCostMicros);
381
391
  const id = digest('mayura:workflow-saga-run-id:v1', { scope: scopeKey, submissionKey: command.idempotencyKey });
382
- const created = await storageCall(() => store.create({ scope: scopeKey, id,
392
+ const created = await createSubmission(() => store.create({ scope: scopeKey, id,
383
393
  idempotencyKey: `saga:${command.idempotencyKey}`, definitionHash: definition.digest,
384
- state: jsonValue(state), events: [{ type: 'saga.run.created', data: {} }] }));
394
+ state: jsonValue(state), events: [{ type: 'saga.run.created', data: {} }] }), 'workflow saga run');
385
395
  verify(definition, created.record, decoded(created.record));
386
396
  return snapshot(created.record);
387
397
  },
@@ -395,26 +405,29 @@ export function createWorkflowSagaRuntime(options) {
395
405
  throw new MayuraError('CONFLICT', 'A terminal saga cannot be paused.');
396
406
  state.status = 'paused';
397
407
  return true;
398
- }, 'saga.run.paused')),
408
+ }, 'saga.run.paused', {}, true)),
399
409
  resume: async (id) => snapshot(await mutate(id, state => {
400
410
  if (state.status !== 'paused')
401
411
  throw new MayuraError('CONFLICT', 'Only a paused saga can be resumed.');
402
412
  const compensating = Object.values(state.steps).some(step => ['failed', 'compensation_waiting', 'compensated', 'compensation_failed'].includes(step.status));
403
413
  state.status = compensating ? 'compensating' : 'running';
404
414
  return true;
405
- }, 'saga.run.resumed')),
415
+ }, 'saga.run.resumed', {}, true)),
406
416
  migrate: async (migration, command) => {
407
417
  ensureOpen();
408
418
  assertWorkflowMigration(migration);
409
419
  assertWorkflowSaga(migration.from);
410
420
  assertWorkflowSaga(migration.to);
411
421
  const { id, actorId, commandId, dryRun = false } = migrationCommand(command);
412
- const record = await load(id);
422
+ // A reviewed migration is the explicit way to move a saga onto the current settings, whichever it started under.
423
+ const record = await load(id, true);
413
424
  const state = decoded(record);
414
- verify(migration.from, record, state);
425
+ verify(migration.from, record, state, true);
415
426
  const preconditions = [];
416
427
  if (state.status !== 'paused')
417
428
  preconditions.push({ node: '*', reason: `The saga is ${state.status}; pause it before migrating.` });
429
+ if (state.spentMicros > options.maxCostMicros)
430
+ preconditions.push({ node: '*', reason: 'The saga already spent more than the current maxCostMicros.' });
418
431
  if (Object.values(state.steps).some(step => ['failed', 'compensation_waiting', 'compensated', 'compensation_failed'].includes(step.status))) {
419
432
  preconditions.push({ node: '*', reason: 'The saga is compensating; only a saga in its forward phase can migrate.' });
420
433
  }
@@ -449,7 +462,8 @@ export function createWorkflowSagaRuntime(options) {
449
462
  carried[entry.target] = entry.action === 'keep' || entry.action === 'accept' ? state.steps[entry.source] : fresh.steps[entry.target];
450
463
  const steps = Object.fromEntries(toManifest.steps.map(step => [step.id, carried[step.id]]));
451
464
  const cursor = toManifest.steps.findIndex(step => steps[step.id].status !== 'succeeded');
452
- const next = { ...state, definition: migration.to.digest, steps, cursor: cursor < 0 ? toManifest.steps.length : cursor,
465
+ const next = { ...state, definition: migration.to.digest, policy, maxCostMicros: options.maxCostMicros,
466
+ steps, cursor: cursor < 0 ? toManifest.steps.length : cursor,
453
467
  spentMicros: Object.values(steps).reduce((sum, step) => sum + step.forwardSpentMicros + step.compensationSpentMicros, 0) };
454
468
  try {
455
469
  assertWorkflowSagaStateMatchesManifest(workflowSagaState({ id, state: jsonValue(next) }), toManifest);
@@ -465,7 +479,7 @@ export function createWorkflowSagaRuntime(options) {
465
479
  return freezeJson(jsonValue({ plan, snapshot: snapshot(migrated) }));
466
480
  },
467
481
  cancel: async (id) => {
468
- let record = await load(id);
482
+ let record = await load(id, true);
469
483
  const state = decoded(record);
470
484
  if (terminalSagaStatuses.has(state.status))
471
485
  return snapshot(record);
@@ -486,7 +500,7 @@ export function createWorkflowSagaRuntime(options) {
486
500
  }
487
501
  current.status = 'cancelled';
488
502
  return true;
489
- }, 'saga.run.cancelled');
503
+ }, 'saga.run.cancelled', {}, true);
490
504
  return snapshot(record);
491
505
  },
492
506
  close: () => { if (!closed) {
@@ -1 +1 @@
1
- {"version":3,"file":"saga-runtime.js","sourceRoot":"","sources":["../src/saga-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAoD,MAAM,cAAc,CAAC;AAE9H,OAAO,EAAE,YAAY,EAAE,sCAAsC,EAAE,wBAAwB,EAAE,iBAAiB,EACR,MAAM,2BAA2B,CAAC;AACpI,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,8BAA8B,EACiC,MAAM,wBAAwB,CAAC;AACvG,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAA+C,MAAM,sBAAsB,CAAC;AACrH,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,cAAc,EAAE,eAAe,EAAE,qBAAqB,EAC5B,MAAM,gBAAgB,CAAC;AAoC7H,MAAM,WAAW,GAAG,gBAAgB,CAAC;AACrC,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAqB,CAAC,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,qBAAqB,EAAE,WAAW,CAAC,CAAC,CAAC;AACrI,MAAM,eAAe,GAAG,CAAC,QAAmC,EAAW,EAAE,CAAC,QAAQ,CAAC,MAAM,KAAK,WAAW,CAAC;AAC1G,MAAM,aAAa,GAAG,CAAC,QAAmC,EAAW,EAAE,CACrE,CAAC,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAE/F,KAAK,UAA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AC;QAAC,CAAC,CAAC,CAAC;QACnE,KAAK,EAAE,KAAK,EAAC,OAAO,EAAC,EAAE,GAAG,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC;KACzG,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { freezeJson, jsonValue, MayuraError, validate, type InferInput, type JsonObject, type JsonValue } from '@mayura/core';\nimport type { WorkflowDrainOptions, WorkflowDrainReport } from './drain.js';\nimport { StorageError, assertWorkflowSagaStateMatchesManifest, initialWorkflowSagaState, workflowSagaState,\n type StoredRecord, type WorkflowSagaState, type WorkflowSagaStatus, type WorkflowSagaStepState } from '@mayura/storage-contracts';\nimport { digest, resolveBinding } from './definition.js';\nimport { createWorkflowLifecycleRuntime, type WorkflowLifecycleRuntime,\n type WorkflowLifecycleRuntimeOptions, type WorkflowLifecycleSnapshot } from './lifecycle-runtime.js';\nimport { assertWorkflowSaga, sagaManifest, type AnyWorkflowSaga, type WorkflowSagaStep } from './saga-definition.js';\nimport { assertMigrationAllowed, assertWorkflowMigration, migrationCommand, migrationEvent, nodeFingerprint, planWorkflowMigration,\n type MigrationBlocker, type MigrationCommand, type WorkflowMigration, type WorkflowMigrationResult } from './migration.js';\n\nexport interface WorkflowSagaRuntimeOptions extends WorkflowLifecycleRuntimeOptions {}\n\nexport interface WorkflowSagaSnapshot {\n readonly id: string;\n readonly version: number;\n readonly status: WorkflowSagaStatus;\n readonly cursor: number;\n readonly steps: Readonly<Record<string, Readonly<WorkflowSagaStepState>>>;\n readonly output: JsonValue;\n readonly budget: { readonly spentMicros: number; readonly maxCostMicros: number };\n}\n\nexport interface WorkflowSagaRuntime {\n readonly profile: 'saga-v1';\n /** Child runtime used to inspect, approve, or answer the currently linked lifecycle run. */\n readonly lifecycle: WorkflowLifecycleRuntime;\n submit<D extends AnyWorkflowSaga>(definition: D, command: { readonly input: InferInput<D['input']>; readonly idempotencyKey: string }): Promise<WorkflowSagaSnapshot>;\n inspect(id: string): Promise<WorkflowSagaSnapshot>;\n events(id: string, after?: number): ReturnType<WorkflowSagaRuntimeOptions['store']['events']>;\n runUntilSettled(definition: AnyWorkflowSaga, id: string): Promise<WorkflowSagaSnapshot>;\n /** Quiescent operator pause: no further child is started or driven; the linked child keeps its own state. */\n pause(id: string): Promise<WorkflowSagaSnapshot>;\n resume(id: string): Promise<WorkflowSagaSnapshot>;\n /**\n * Plan (dryRun) or apply a reviewed migration of a paused saga in its forward phase. A step whose linked child is still\n * running keeps it only if the child already runs the target's child definition: migrate the child first.\n */\n migrate(migration: WorkflowMigration<AnyWorkflowSaga, AnyWorkflowSaga>, command: MigrationCommand): Promise<WorkflowMigrationResult<WorkflowSagaSnapshot>>;\n cancel(id: string): Promise<WorkflowSagaSnapshot>;\n close(): void;\n /** Let admitted child effects settle within the deadline, then close. */\n drain(options?: WorkflowDrainOptions): Promise<WorkflowDrainReport>;\n}\n\nconst hashPattern = /^[a-f0-9]{64}$/;\nconst terminalSagaStatuses = new Set<WorkflowSagaStatus>(['succeeded', 'failed', 'compensated', 'compensation_failed', 'cancelled']);\nconst successfulChild = (snapshot: WorkflowLifecycleSnapshot): boolean => snapshot.status === 'succeeded';\nconst terminalChild = (snapshot: WorkflowLifecycleSnapshot): boolean =>\n ['succeeded', 'failed', 'blocked', 'cancelled', 'outcome_unknown'].includes(snapshot.status);\n\nasync function storageCall<T>(operation: () => Promise<T>): Promise<T> {\n try { return await operation(); }\n catch (error) {\n if (error instanceof StorageError && error.code === 'CONFLICT') throw error;\n throw new MayuraError('STORAGE_UNAVAILABLE', 'Workflow saga storage is unavailable; inspect current state before retrying.');\n }\n}\n\nfunction decoded(record: StoredRecord): WorkflowSagaState {\n try { return workflowSagaState(record); }\n catch { throw new MayuraError('CONFLICT', 'Stored workflow saga state failed integrity validation.'); }\n}\n\nfunction snapshot(record: StoredRecord): WorkflowSagaSnapshot {\n const state = decoded(record);\n return freezeJson(jsonValue({ id: record.id, version: record.version, status: state.status, cursor: state.cursor,\n steps: state.steps, output: state.output, budget: { spentMicros: state.spentMicros,\n maxCostMicros: state.maxCostMicros } })) as unknown as WorkflowSagaSnapshot;\n}\n\nfunction outputs(state: WorkflowSagaState): Record<string, JsonValue> {\n return Object.fromEntries(Object.entries(state.steps).filter(([, step]) =>\n ['succeeded', 'compensation_waiting', 'compensated', 'compensation_failed'].includes(step.status))\n .map(([id, step]) => [id, step.output]));\n}\n\nfunction childKey(sagaRunId: string, stepId: string, phase: 'forward' | 'compensation'): string {\n return digest('mayura:workflow-saga-child:v1', { sagaRunId, stepId, phase });\n}\n\n/**\n * Durable saga coordinator built from format-5 lifecycle children.\n * The generic aggregate API cannot atomically write a child and its saga link; the\n * stable child key makes replay after that narrow crash window converge safely.\n */\nexport function createWorkflowSagaRuntime(options: WorkflowSagaRuntimeOptions): WorkflowSagaRuntime {\n const store = options.store;\n const scope = Object.freeze({ principalId: options.scope?.principalId, projectId: options.scope?.projectId });\n if ([scope.principalId, scope.projectId, options.policyVersion].some(value =>\n typeof value !== 'string' || value.length < 1 || value.length > 128)) {\n throw new MayuraError('INVALID_CONFIG', 'Workflow saga scope and policy version are required.');\n }\n if (!Array.isArray(options.permissions?.allow) || options.permissions.allow.length > 4_096\n || options.permissions.allow.some(grant => typeof grant !== 'string' || grant.length < 1 || grant.length > 256)) {\n throw new MayuraError('INVALID_CONFIG', 'Workflow saga permissions must be bounded explicit grants.');\n }\n if (!Number.isSafeInteger(options.maxCostMicros) || options.maxCostMicros < 0) {\n throw new MayuraError('INVALID_CONFIG', 'A bounded saga cost is required.');\n }\n const maxOutputBytes = options.maxOutputBytes ?? 1_048_576;\n const callbackTimeoutMs = options.callbackTimeoutMs ?? 30_000;\n const maxPendingCallbacks = options.maxPendingCallbacks ?? 32;\n if (!Number.isSafeInteger(maxOutputBytes) || maxOutputBytes < 1 || !Number.isSafeInteger(callbackTimeoutMs) || callbackTimeoutMs < 1) {\n throw new MayuraError('INVALID_CONFIG', 'Saga callback and output bounds must be positive integers.');\n }\n if (!Number.isSafeInteger(maxPendingCallbacks) || maxPendingCallbacks < 1 || maxPendingCallbacks > 128) {\n throw new MayuraError('INVALID_CONFIG', 'maxPendingCallbacks must be an integer from 1 through 128.');\n }\n const lifecycle = createWorkflowLifecycleRuntime(options);\n const scopeKey = digest('mayura:scope:v1', scope);\n const policy = digest('mayura:workflow-saga-policy:v1', { scope, permissions: [...options.permissions.allow].sort(),\n policyVersion: options.policyVersion, maxCostMicros: options.maxCostMicros, maxOutputBytes,\n approvalTtlMs: options.approvalTtlMs ?? 3_600_000 });\n let closed = false;\n const ensureOpen = (): void => { if (closed) throw new MayuraError('CANCELLED', 'Workflow saga runtime is closed.'); };\n let pendingCallbacks = 0;\n const boundedValidate = async (schema: AnyWorkflowSaga['input'] | AnyWorkflowSaga['output'], value: unknown,\n boundary: 'input' | 'output'): Promise<JsonValue> => {\n if (pendingCallbacks >= maxPendingCallbacks) throw new MayuraError('LIMIT_EXCEEDED', 'Saga callback capacity is full.');\n pendingCallbacks += 1; let released = false;\n const release = (): void => { if (!released) { released = true; pendingCallbacks -= 1; } };\n const validation = Promise.resolve().then(() => validate(schema, value, boundary, { maxBytes: maxOutputBytes }));\n void validation.then(release, release);\n let timer: ReturnType<typeof setTimeout> | undefined;\n try {\n const checked = await Promise.race([validation,\n new Promise<never>((_resolve, reject) => { timer = setTimeout(() => reject(new MayuraError('TIMEOUT', 'Saga schema validation timed out.')), callbackTimeoutMs); })]);\n return jsonValue(checked, { maxBytes: maxOutputBytes });\n } finally { if (timer !== undefined) clearTimeout(timer); }\n };\n const load = async (id: string): Promise<StoredRecord> => {\n ensureOpen();\n if (typeof id !== 'string' || !hashPattern.test(id)) throw new MayuraError('INVALID_INPUT', 'A workflow saga run ID is required.');\n const record = await storageCall(() => store.read(scopeKey, id));\n if (!record) throw new MayuraError('NOT_FOUND', 'Workflow saga run was not found in this scope.');\n if (record.scope !== scopeKey || record.id !== id) throw new MayuraError('CONFLICT', 'Stored saga identity does not match its requested scope.');\n const state = decoded(record);\n if (state.policy !== policy) throw new MayuraError('CONFLICT', 'Stored saga policy does not match this runtime.');\n return record;\n };\n const verify = (definition: AnyWorkflowSaga, record: StoredRecord, state: WorkflowSagaState): void => {\n if (record.definitionHash !== definition.digest || state.definition !== definition.digest || state.policy !== policy) {\n throw new MayuraError('CONFLICT', 'Workflow saga definition or policy does not match persisted state.');\n }\n try { assertWorkflowSagaStateMatchesManifest(state, sagaManifest(definition)); }\n catch { throw new MayuraError('CONFLICT', 'Workflow saga state does not match its persisted definition.'); }\n };\n const save = (record: StoredRecord, state: WorkflowSagaState, type: string, data: JsonObject = {}): Promise<StoredRecord> =>\n storageCall(() => store.update({ scope: scopeKey, id: record.id, expectedVersion: record.version,\n state: jsonValue(state) as JsonObject, events: [{ type, data }] }));\n const mutate = async (id: string, transition: (state: WorkflowSagaState) => boolean, type: string,\n data: JsonObject = {}): Promise<StoredRecord> => {\n for (let attempt = 0; attempt < 32; attempt++) {\n const record = await load(id); const state = decoded(record); const paused = state.status === 'paused';\n if (!transition(state)) return record;\n // Progress recorded while paused (a child settling) never un-pauses the saga; only a terminal outcome replaces it.\n if (paused && !terminalSagaStatuses.has(state.status) && type !== 'saga.run.resumed') state.status = 'paused';\n try { return await save(record, state, type, data); }\n catch (error) { if (!(error instanceof StorageError) || error.code !== 'CONFLICT') throw error; }\n }\n throw new MayuraError('CONFLICT', 'Workflow saga contention exceeded the bounded retry limit.');\n };\n const recordChild = (state: WorkflowSagaState, stepId: string, phase: 'forward' | 'compensation',\n child: WorkflowLifecycleSnapshot): void => {\n const step = state.steps[stepId]!;\n if (phase === 'forward') { step.forwardRunId = child.id; step.forwardSpentMicros = child.budget.spentMicros; }\n else { step.compensationRunId = child.id; step.compensationSpentMicros = child.budget.spentMicros; }\n state.spentMicros = Object.values(state.steps).reduce((sum, item) =>\n sum + item.forwardSpentMicros + item.compensationSpentMicros, 0);\n if (!Number.isSafeInteger(state.spentMicros) || state.spentMicros > state.maxCostMicros) {\n throw new MayuraError('LIMIT_EXCEEDED', 'Workflow saga exceeded its persisted cost ceiling.');\n }\n };\n const submitChild = async (runId: string, step: WorkflowSagaStep, phase: 'forward' | 'compensation',\n state: WorkflowSagaState): Promise<WorkflowLifecycleSnapshot> => {\n const workflow = phase === 'forward' ? step.forward : step.compensation!.workflow;\n const binding = phase === 'forward' ? step.input : step.compensation!.input;\n const input = resolveBinding(binding, state.input, outputs(state));\n return lifecycle.submit(workflow, { input, idempotencyKey: childKey(runId, step.id, phase) });\n };\n\n const run = async (definition: AnyWorkflowSaga, id: string): Promise<WorkflowSagaSnapshot> => {\n assertWorkflowSaga(definition);\n for (let wave = 0; wave < definition.steps.length * 2 + 4; wave++) {\n let record = await load(id); let state = decoded(record); verify(definition, record, state);\n if (terminalSagaStatuses.has(state.status) || state.status === 'paused') return snapshot(record);\n if (state.status === 'running' || state.status === 'waiting') {\n const index = state.cursor; const step = definition.steps[index];\n if (!step) {\n let output: JsonValue;\n try { output = await boundedValidate(definition.output,\n resolveBinding(definition.result, state.input, outputs(state)), 'output'); }\n catch (error) {\n if (!(error instanceof MayuraError) || !['INVALID_INPUT', 'INVALID_OUTPUT'].includes(error.code)) throw error;\n state.status = 'compensating'; state.cursor = definition.steps.length;\n await save(record, state, 'saga.output.rejected'); continue;\n }\n state.output = output; state.status = 'succeeded';\n record = await save(record, state, 'saga.run.succeeded'); return snapshot(record);\n }\n const persisted = state.steps[step.id]!;\n let child: WorkflowLifecycleSnapshot;\n if (persisted.forwardRunId === null) {\n try { child = await submitChild(id, step, 'forward', state); }\n catch (error) {\n if (!(error instanceof MayuraError) || !['INVALID_INPUT', 'INVALID_OUTPUT'].includes(error.code)) throw error;\n await mutate(id, current => { const target = current.steps[step.id]!;\n if (target.status !== 'pending') return false;\n target.status = 'failed';\n for (let next = index + 1; next < definition.steps.length; next++) current.steps[definition.steps[next]!.id]!.status = 'skipped';\n current.status = 'compensating'; current.cursor = index; return true;\n }, 'saga.forward.rejected', { stepId: step.id });\n continue;\n }\n record = await mutate(id, current => { const target = current.steps[step.id]!;\n if (target.forwardRunId !== null) return false;\n recordChild(current, step.id, 'forward', child); target.status = 'forward_waiting';\n current.status = 'running'; return true;\n }, 'saga.forward.linked', { stepId: step.id, childRunId: child.id });\n state = decoded(record); child = await lifecycle.inspect(state.steps[step.id]!.forwardRunId!);\n } else child = await lifecycle.inspect(persisted.forwardRunId);\n child = await lifecycle.runUntilSettled(step.forward, child.id);\n if (!terminalChild(child)) {\n record = await mutate(id, current => { const target = current.steps[step.id]!;\n if (target.forwardRunId !== child.id || terminalSagaStatuses.has(current.status)) return false;\n recordChild(current, step.id, 'forward', child); target.status = 'forward_waiting';\n current.status = child.status === 'waiting' ? 'waiting' : 'running'; return true;\n }, 'saga.forward.waiting', { stepId: step.id, childRunId: child.id });\n return snapshot(record);\n }\n if (successfulChild(child)) {\n record = await mutate(id, current => { const target = current.steps[step.id]!;\n if (target.forwardRunId !== child.id || target.status === 'succeeded') return false;\n recordChild(current, step.id, 'forward', child); target.output = child.output; target.status = 'succeeded';\n current.cursor = index + 1; current.status = 'running'; return true;\n }, 'saga.forward.succeeded', { stepId: step.id, childRunId: child.id });\n continue;\n }\n record = await mutate(id, current => { const target = current.steps[step.id]!;\n if (target.forwardRunId !== child.id || target.status === 'failed') return false;\n recordChild(current, step.id, 'forward', child); target.status = 'failed';\n for (let next = index + 1; next < definition.steps.length; next++) current.steps[definition.steps[next]!.id]!.status = 'skipped';\n current.cursor = index; current.status = 'compensating'; return true;\n }, 'saga.forward.failed', { stepId: step.id, childRunId: child.id, childStatus: child.status });\n continue;\n }\n\n if (state.status === 'compensating') {\n let index = state.cursor - 1;\n while (index >= 0) {\n const candidate = definition.steps[index]!; const persisted = state.steps[candidate.id]!;\n if (persisted.status === 'succeeded' && candidate.compensation) break;\n index -= 1;\n }\n if (index < 0) {\n const compensated = Object.values(state.steps).some(step => step.status === 'compensated');\n state.status = compensated ? 'compensated' : 'failed'; state.cursor = 0;\n record = await save(record, state, compensated ? 'saga.run.compensated' : 'saga.run.failed');\n return snapshot(record);\n }\n const step = definition.steps[index]!; const persisted = state.steps[step.id]!;\n let child: WorkflowLifecycleSnapshot;\n if (persisted.compensationRunId === null) {\n try { child = await submitChild(id, step, 'compensation', state); }\n catch (error) {\n if (!(error instanceof MayuraError) || !['INVALID_INPUT', 'INVALID_OUTPUT'].includes(error.code)) throw error;\n record = await mutate(id, current => { const target = current.steps[step.id]!;\n if (target.status !== 'succeeded') return false;\n target.status = 'compensation_failed'; current.status = 'compensation_failed'; current.cursor = index; return true;\n }, 'saga.compensation.rejected', { stepId: step.id });\n return snapshot(record);\n }\n record = await mutate(id, current => { const target = current.steps[step.id]!;\n if (target.compensationRunId !== null) return false;\n recordChild(current, step.id, 'compensation', child); target.status = 'compensation_waiting';\n current.status = 'compensating'; current.cursor = index + 1; return true;\n }, 'saga.compensation.linked', { stepId: step.id, childRunId: child.id });\n state = decoded(record); child = await lifecycle.inspect(state.steps[step.id]!.compensationRunId!);\n } else child = await lifecycle.inspect(persisted.compensationRunId);\n child = await lifecycle.runUntilSettled(step.compensation!.workflow, child.id);\n if (!terminalChild(child)) {\n record = await mutate(id, current => { const target = current.steps[step.id]!;\n if (target.compensationRunId !== child.id || terminalSagaStatuses.has(current.status)) return false;\n recordChild(current, step.id, 'compensation', child); target.status = 'compensation_waiting';\n current.status = 'compensating'; current.cursor = index + 1; return true;\n }, 'saga.compensation.waiting', { stepId: step.id, childRunId: child.id });\n return snapshot(record);\n }\n if (successfulChild(child)) {\n await mutate(id, current => { const target = current.steps[step.id]!;\n if (target.compensationRunId !== child.id || target.status === 'compensated') return false;\n recordChild(current, step.id, 'compensation', child); target.status = 'compensated';\n current.status = 'compensating'; current.cursor = index; return true;\n }, 'saga.compensation.succeeded', { stepId: step.id, childRunId: child.id });\n continue;\n }\n record = await mutate(id, current => { const target = current.steps[step.id]!;\n if (target.compensationRunId !== child.id || target.status === 'compensation_failed') return false;\n recordChild(current, step.id, 'compensation', child); target.status = 'compensation_failed';\n current.status = 'compensation_failed'; current.cursor = index; return true;\n }, 'saga.compensation.failed', { stepId: step.id, childRunId: child.id, childStatus: child.status });\n return snapshot(record);\n }\n }\n return snapshot(await load(id));\n };\n\n return Object.freeze<WorkflowSagaRuntime>({\n profile: 'saga-v1', lifecycle,\n submit: async (definition, command) => {\n ensureOpen(); assertWorkflowSaga(definition);\n if (definition.maxCostMicros > options.maxCostMicros) throw new MayuraError('LIMIT_EXCEEDED', 'Saga static cost exceeds its runtime ceiling.');\n if (typeof command.idempotencyKey !== 'string' || command.idempotencyKey.length < 1 || command.idempotencyKey.length > 128) {\n throw new MayuraError('INVALID_INPUT', 'A bounded saga submission key is required.');\n }\n const raw = freezeJson(jsonValue(command.input, { maxBytes: maxOutputBytes }));\n const input = await boundedValidate(definition.input, raw, 'input');\n const state = initialWorkflowSagaState(sagaManifest(definition), input, definition.digest, policy, options.maxCostMicros);\n const id = digest('mayura:workflow-saga-run-id:v1', { scope: scopeKey, submissionKey: command.idempotencyKey });\n const created = await storageCall(() => store.create({ scope: scopeKey, id,\n idempotencyKey: `saga:${command.idempotencyKey}`, definitionHash: definition.digest,\n state: jsonValue(state) as JsonObject, events: [{ type: 'saga.run.created', data: {} }] }));\n verify(definition, created.record, decoded(created.record)); return snapshot(created.record);\n },\n inspect: async id => snapshot(await load(id)),\n events: (id, after = 0) => { ensureOpen(); return storageCall(() => store.events(scopeKey, id, after)); },\n runUntilSettled: run,\n pause: async id => snapshot(await mutate(id, state => {\n if (state.status === 'paused') return false;\n if (terminalSagaStatuses.has(state.status)) throw new MayuraError('CONFLICT', 'A terminal saga cannot be paused.');\n state.status = 'paused'; return true;\n }, 'saga.run.paused')),\n resume: async id => snapshot(await mutate(id, state => {\n if (state.status !== 'paused') throw new MayuraError('CONFLICT', 'Only a paused saga can be resumed.');\n const compensating = Object.values(state.steps).some(step => ['failed', 'compensation_waiting', 'compensated', 'compensation_failed'].includes(step.status));\n state.status = compensating ? 'compensating' : 'running'; return true;\n }, 'saga.run.resumed')),\n migrate: async (migration, command) => {\n ensureOpen(); assertWorkflowMigration(migration); assertWorkflowSaga(migration.from); assertWorkflowSaga(migration.to);\n const { id, actorId, commandId, dryRun = false } = migrationCommand(command);\n const record = await load(id); const state = decoded(record); verify(migration.from, record, state);\n const preconditions: MigrationBlocker[] = [];\n if (state.status !== 'paused') preconditions.push({ node: '*', reason: `The saga is ${state.status}; pause it before migrating.` });\n if (Object.values(state.steps).some(step => ['failed', 'compensation_waiting', 'compensated', 'compensation_failed'].includes(step.status))) {\n preconditions.push({ node: '*', reason: 'The saga is compensating; only a saga in its forward phase can migrate.' });\n }\n // A running linked child is compared by the definition it is actually pinned to (possibly already migrated).\n const linked = new Map<string, string>();\n for (const [stepId, step] of Object.entries(state.steps)) if (step.status === 'forward_waiting' && step.forwardRunId) {\n const child = await storageCall(() => store.read(scopeKey, step.forwardRunId!));\n if (!child) throw new MayuraError('CONFLICT', 'A linked saga child run is missing.');\n linked.set(stepId, child.definitionHash);\n }\n const nodes = (definition: AnyWorkflowSaga, effective: boolean) => sagaManifest(definition).steps.map((step, index, all) => {\n const forward = effective && linked.has(step.id) ? { ...step.forward, definitionHash: linked.get(step.id)! } : step.forward;\n return { id: step.id, kind: 'saga-step', dependsOn: index === 0 ? [] : [all[index - 1]!.id], fingerprint: nodeFingerprint({ ...step, forward } as unknown as Record<string, unknown>) };\n });\n const statusFor = (status: string): string => status === 'forward_waiting' ? 'running' : status;\n const plan = planWorkflowMigration({ migration, format: 'saga-v1', runId: id, fromDigest: migration.from.digest, toDigest: migration.to.digest,\n from: nodes(migration.from, true), to: nodes(migration.to, false),\n steps: Object.entries(state.steps).map(([step, value]) => ({ id: step, status: statusFor(value.status) })),\n preconditions: [...preconditions, ...Object.entries(state.steps).filter(([stepId, step]) => (step.forwardSpentMicros + step.compensationSpentMicros) > 0\n && !sagaManifest(migration.to).steps.some(target => target.id === stepId || migration.renames[target.id] === stepId))\n .map(([stepId]) => ({ node: stepId, reason: `Step \"${stepId}\" already spent budget; removing it would drop recorded spend.` }))] });\n if (dryRun) return freezeJson(jsonValue({ plan })) as unknown as WorkflowMigrationResult<WorkflowSagaSnapshot>;\n assertMigrationAllowed(plan);\n const toManifest = sagaManifest(migration.to);\n const fresh = initialWorkflowSagaState(toManifest, state.input, migration.to.digest, policy, options.maxCostMicros);\n const carried: Record<string, WorkflowSagaStepState> = {};\n for (const entry of plan.entries) if (entry.target) carried[entry.target] = entry.action === 'keep' || entry.action === 'accept' ? state.steps[entry.source!]! : fresh.steps[entry.target]!;\n const steps = Object.fromEntries(toManifest.steps.map(step => [step.id, carried[step.id]!]));\n const cursor = toManifest.steps.findIndex(step => steps[step.id]!.status !== 'succeeded');\n const next: WorkflowSagaState = { ...state, definition: migration.to.digest, steps, cursor: cursor < 0 ? toManifest.steps.length : cursor,\n spentMicros: Object.values(steps).reduce((sum, step) => sum + step.forwardSpentMicros + step.compensationSpentMicros, 0) };\n try { assertWorkflowSagaStateMatchesManifest(workflowSagaState({ id, state: jsonValue(next) as JsonObject }), toManifest); }\n catch { throw new MayuraError('CONFLICT', 'Migration refused: the migrated saga state does not satisfy the new definition.'); }\n if (typeof store.migrate !== 'function') throw new MayuraError('UNSUPPORTED_PROFILE', 'This store cannot migrate in-flight workflow runs.');\n const migrated = await storageCall(() => store.migrate!({ scope: scopeKey, id, expectedVersion: record.version, expectedDefinitionHash: migration.from.digest,\n definitionHash: migration.to.digest, state: jsonValue(next) as JsonObject, events: [migrationEvent(plan, actorId, commandId) as { type: string; data: JsonObject }] }));\n verify(migration.to, migrated, decoded(migrated));\n return freezeJson(jsonValue({ plan, snapshot: snapshot(migrated) })) as unknown as WorkflowMigrationResult<WorkflowSagaSnapshot>;\n },\n cancel: async id => {\n let record = await load(id); const state = decoded(record);\n if (terminalSagaStatuses.has(state.status)) return snapshot(record);\n const activeEntry = Object.entries(state.steps).find(([, step]) => step.status === 'forward_waiting' || step.status === 'compensation_waiting');\n const active = activeEntry?.[1]; const activeStepId = activeEntry?.[0];\n const childRunId = active?.status === 'forward_waiting' ? active.forwardRunId : active?.compensationRunId;\n const child = childRunId ? await lifecycle.cancel(childRunId) : undefined;\n record = await mutate(id, current => {\n if (terminalSagaStatuses.has(current.status)) return false;\n if (child && active && activeStepId) {\n const phase = active.status === 'forward_waiting' ? 'forward' : 'compensation';\n const target = current.steps[activeStepId];\n const linked = phase === 'forward' ? target?.forwardRunId : target?.compensationRunId;\n if (linked === child.id) recordChild(current, activeStepId, phase, child);\n }\n current.status = 'cancelled'; return true;\n }, 'saga.run.cancelled');\n return snapshot(record);\n },\n close: () => { if (!closed) { closed = true; lifecycle.close(); } },\n drain: async options => { const report = await lifecycle.drain(options); closed = true; return report; },\n });\n}\n"]}
1
+ {"version":3,"file":"saga-runtime.js","sourceRoot":"","sources":["../src/saga-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAoD,MAAM,cAAc,CAAC;AAE9H,OAAO,EAAE,YAAY,EAAE,sCAAsC,EAAE,wBAAwB,EAAE,iBAAiB,EACR,MAAM,2BAA2B,CAAC;AACpI,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,8BAA8B,EAAE,4BAA4B,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,sBAAsB,EACnC,MAAM,wBAAwB,CAAC;AACtI,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAA+C,MAAM,sBAAsB,CAAC;AACrH,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,cAAc,EAAE,eAAe,EAAE,qBAAqB,EAC5B,MAAM,gBAAgB,CAAC;AAoC7H,MAAM,WAAW,GAAG,gBAAgB,CAAC;AACrC,MAAM,oBAAoB,GAAG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C,CAAC,CAAC;KACzG,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { freezeJson, jsonValue, MayuraError, validate, type InferInput, type JsonObject, type JsonValue } from '@mayura/core';\nimport type { WorkflowDrainOptions, WorkflowDrainReport } from './drain.js';\nimport { StorageError, assertWorkflowSagaStateMatchesManifest, initialWorkflowSagaState, workflowSagaState,\n type StoredRecord, type WorkflowSagaState, type WorkflowSagaStatus, type WorkflowSagaStepState } from '@mayura/storage-contracts';\nimport { digest, resolveBinding } from './definition.js';\nimport { createSubmission, workflowStorageFailure } from './storage-failure.js';\nimport { createWorkflowLifecycleRuntime, submitWorkflowLifecycleUnder, unknownWorkflowPolicy, workflowPolicyDigest, workflowPolicySettings,\n type WorkflowLifecycleRuntime, type WorkflowLifecycleRuntimeOptions, type WorkflowLifecycleSnapshot } from './lifecycle-runtime.js';\nimport { assertWorkflowSaga, sagaManifest, type AnyWorkflowSaga, type WorkflowSagaStep } from './saga-definition.js';\nimport { assertMigrationAllowed, assertWorkflowMigration, migrationCommand, migrationEvent, nodeFingerprint, planWorkflowMigration,\n type MigrationBlocker, type MigrationCommand, type WorkflowMigration, type WorkflowMigrationResult } from './migration.js';\n\nexport interface WorkflowSagaRuntimeOptions extends WorkflowLifecycleRuntimeOptions {}\n\nexport interface WorkflowSagaSnapshot {\n readonly id: string;\n readonly version: number;\n readonly status: WorkflowSagaStatus;\n readonly cursor: number;\n readonly steps: Readonly<Record<string, Readonly<WorkflowSagaStepState>>>;\n readonly output: JsonValue;\n readonly budget: { readonly spentMicros: number; readonly maxCostMicros: number };\n}\n\nexport interface WorkflowSagaRuntime {\n readonly profile: 'saga-v1';\n /** Child runtime used to inspect, approve, or answer the currently linked lifecycle run. */\n readonly lifecycle: WorkflowLifecycleRuntime;\n submit<D extends AnyWorkflowSaga>(definition: D, command: { readonly input: InferInput<D['input']>; readonly idempotencyKey: string }): Promise<WorkflowSagaSnapshot>;\n inspect(id: string): Promise<WorkflowSagaSnapshot>;\n events(id: string, after?: number): ReturnType<WorkflowSagaRuntimeOptions['store']['events']>;\n runUntilSettled(definition: AnyWorkflowSaga, id: string): Promise<WorkflowSagaSnapshot>;\n /** Quiescent operator pause: no further child is started or driven; the linked child keeps its own state. */\n pause(id: string): Promise<WorkflowSagaSnapshot>;\n resume(id: string): Promise<WorkflowSagaSnapshot>;\n /**\n * Plan (dryRun) or apply a reviewed migration of a paused saga in its forward phase. A step whose linked child is still\n * running keeps it only if the child already runs the target's child definition: migrate the child first.\n */\n migrate(migration: WorkflowMigration<AnyWorkflowSaga, AnyWorkflowSaga>, command: MigrationCommand): Promise<WorkflowMigrationResult<WorkflowSagaSnapshot>>;\n cancel(id: string): Promise<WorkflowSagaSnapshot>;\n close(): void;\n /** Let admitted child effects settle within the deadline, then close. */\n drain(options?: WorkflowDrainOptions): Promise<WorkflowDrainReport>;\n}\n\nconst hashPattern = /^[a-f0-9]{64}$/;\nconst terminalSagaStatuses = new Set<WorkflowSagaStatus>(['succeeded', 'failed', 'compensated', 'compensation_failed', 'cancelled']);\nconst successfulChild = (snapshot: WorkflowLifecycleSnapshot): boolean => snapshot.status === 'succeeded';\nconst terminalChild = (snapshot: WorkflowLifecycleSnapshot): boolean =>\n ['succeeded', 'failed', 'blocked', 'cancelled', 'outcome_unknown'].includes(snapshot.status);\n\nasync function storageCall<T>(operation: () => Promise<T>): Promise<T> {\n try { return await operation(); }\n catch (error) {\n throw workflowStorageFailure(error, 'workflow saga run');\n }\n}\n\nfunction decoded(record: StoredRecord): WorkflowSagaState {\n try { return workflowSagaState(record); }\n catch { throw new MayuraError('CONFLICT', 'Stored workflow saga state failed integrity validation.'); }\n}\n\nfunction snapshot(record: StoredRecord): WorkflowSagaSnapshot {\n const state = decoded(record);\n return freezeJson(jsonValue({ id: record.id, version: record.version, status: state.status, cursor: state.cursor,\n steps: state.steps, output: state.output, budget: { spentMicros: state.spentMicros,\n maxCostMicros: state.maxCostMicros } })) as unknown as WorkflowSagaSnapshot;\n}\n\nfunction outputs(state: WorkflowSagaState): Record<string, JsonValue> {\n return Object.fromEntries(Object.entries(state.steps).filter(([, step]) =>\n ['succeeded', 'compensation_waiting', 'compensated', 'compensation_failed'].includes(step.status))\n .map(([id, step]) => [id, step.output]));\n}\n\nfunction childKey(sagaRunId: string, stepId: string, phase: 'forward' | 'compensation'): string {\n return digest('mayura:workflow-saga-child:v1', { sagaRunId, stepId, phase });\n}\n\n/**\n * Durable saga coordinator built from format-5 lifecycle children.\n * The generic aggregate API cannot atomically write a child and its saga link; the\n * stable child key makes replay after that narrow crash window converge safely.\n */\nexport function createWorkflowSagaRuntime(options: WorkflowSagaRuntimeOptions): WorkflowSagaRuntime {\n const store = options.store;\n const scope = Object.freeze({ principalId: options.scope?.principalId, projectId: options.scope?.projectId });\n if ([scope.principalId, scope.projectId, options.policyVersion].some(value =>\n typeof value !== 'string' || value.length < 1 || value.length > 128)) {\n throw new MayuraError('INVALID_CONFIG', 'Workflow saga scope and policy version are required.');\n }\n if (!Array.isArray(options.permissions?.allow) || options.permissions.allow.length > 4_096\n || options.permissions.allow.some(grant => typeof grant !== 'string' || grant.length < 1 || grant.length > 256)) {\n throw new MayuraError('INVALID_CONFIG', 'Workflow saga permissions must be bounded explicit grants.');\n }\n if (!Number.isSafeInteger(options.maxCostMicros) || options.maxCostMicros < 0) {\n throw new MayuraError('INVALID_CONFIG', 'A bounded saga cost is required.');\n }\n const maxOutputBytes = options.maxOutputBytes ?? 1_048_576;\n const callbackTimeoutMs = options.callbackTimeoutMs ?? 30_000;\n const maxPendingCallbacks = options.maxPendingCallbacks ?? 32;\n if (!Number.isSafeInteger(maxOutputBytes) || maxOutputBytes < 1 || !Number.isSafeInteger(callbackTimeoutMs) || callbackTimeoutMs < 1) {\n throw new MayuraError('INVALID_CONFIG', 'Saga callback and output bounds must be positive integers.');\n }\n if (!Number.isSafeInteger(maxPendingCallbacks) || maxPendingCallbacks < 1 || maxPendingCallbacks > 128) {\n throw new MayuraError('INVALID_CONFIG', 'maxPendingCallbacks must be an integer from 1 through 128.');\n }\n const lifecycle = createWorkflowLifecycleRuntime(options);\n const scopeKey = digest('mayura:scope:v1', scope);\n // Index n of `settings` and of `policies` is the same policy the lifecycle runtime knows at index n.\n const settings = workflowPolicySettings(options);\n const policies = settings.map(entry => workflowPolicyDigest('mayura:workflow-saga-policy:v1', scope, entry));\n const policy = policies[0]!;\n /** Index of the policy a saga was started with; its later children and limits keep that policy. */\n const pinnedIndex = (state: WorkflowSagaState): number => {\n const index = policies.indexOf(state.policy); if (index < 0) throw unknownWorkflowPolicy(); return index;\n };\n let closed = false;\n const ensureOpen = (): void => { if (closed) throw new MayuraError('CANCELLED', 'Workflow saga runtime is closed.'); };\n let pendingCallbacks = 0;\n const boundedValidate = async (schema: AnyWorkflowSaga['input'] | AnyWorkflowSaga['output'], value: unknown,\n boundary: 'input' | 'output', maxBytes = maxOutputBytes): Promise<JsonValue> => {\n if (pendingCallbacks >= maxPendingCallbacks) throw new MayuraError('LIMIT_EXCEEDED', 'Saga callback capacity is full.');\n pendingCallbacks += 1; let released = false;\n const release = (): void => { if (!released) { released = true; pendingCallbacks -= 1; } };\n const validation = Promise.resolve().then(() => validate(schema, value, boundary, { maxBytes }));\n void validation.then(release, release);\n let timer: ReturnType<typeof setTimeout> | undefined;\n try {\n const checked = await Promise.race([validation,\n new Promise<never>((_resolve, reject) => { timer = setTimeout(() => reject(new MayuraError('TIMEOUT', 'Saga schema validation timed out.')), callbackTimeoutMs); })]);\n return jsonValue(checked, { maxBytes });\n } finally { if (timer !== undefined) clearTimeout(timer); }\n };\n /** `anyPolicy` admits operator controls (pause, resume, cancel, migrate) on a saga whose settings are not listed. */\n const load = async (id: string, anyPolicy = false): Promise<StoredRecord> => {\n ensureOpen();\n if (typeof id !== 'string' || !hashPattern.test(id)) throw new MayuraError('INVALID_INPUT', 'A workflow saga run ID is required.');\n const record = await storageCall(() => store.read(scopeKey, id));\n if (!record) throw new MayuraError('NOT_FOUND', 'Workflow saga run was not found in this scope.');\n if (record.scope !== scopeKey || record.id !== id) throw new MayuraError('CONFLICT', 'Stored saga identity does not match its requested scope.');\n const state = decoded(record);\n if (!anyPolicy) pinnedIndex(state);\n return record;\n };\n const verify = (definition: AnyWorkflowSaga, record: StoredRecord, state: WorkflowSagaState, anyPolicy = false): void => {\n if (record.definitionHash !== definition.digest || state.definition !== definition.digest) {\n throw new MayuraError('CONFLICT', 'Workflow saga definition does not match persisted state.');\n }\n if (!anyPolicy) pinnedIndex(state);\n try { assertWorkflowSagaStateMatchesManifest(state, sagaManifest(definition)); }\n catch { throw new MayuraError('CONFLICT', 'Workflow saga state does not match its persisted definition.'); }\n };\n const save = (record: StoredRecord, state: WorkflowSagaState, type: string, data: JsonObject = {}): Promise<StoredRecord> =>\n storageCall(() => store.update({ scope: scopeKey, id: record.id, expectedVersion: record.version,\n state: jsonValue(state) as JsonObject, events: [{ type, data }] }));\n const mutate = async (id: string, transition: (state: WorkflowSagaState) => boolean, type: string,\n data: JsonObject = {}, anyPolicy = false): Promise<StoredRecord> => {\n for (let attempt = 0; attempt < 32; attempt++) {\n const record = await load(id, anyPolicy); const state = decoded(record); const paused = state.status === 'paused';\n if (!transition(state)) return record;\n // Progress recorded while paused (a child settling) never un-pauses the saga; only a terminal outcome replaces it.\n if (paused && !terminalSagaStatuses.has(state.status) && type !== 'saga.run.resumed') state.status = 'paused';\n try { return await save(record, state, type, data); }\n catch (error) { if (!(error instanceof StorageError) || error.storageCode !== 'CONFLICT') throw error; }\n }\n throw new MayuraError('CONFLICT', 'Workflow saga contention exceeded the bounded retry limit.');\n };\n const recordChild = (state: WorkflowSagaState, stepId: string, phase: 'forward' | 'compensation',\n child: WorkflowLifecycleSnapshot): void => {\n const step = state.steps[stepId]!;\n if (phase === 'forward') { step.forwardRunId = child.id; step.forwardSpentMicros = child.budget.spentMicros; }\n else { step.compensationRunId = child.id; step.compensationSpentMicros = child.budget.spentMicros; }\n state.spentMicros = Object.values(state.steps).reduce((sum, item) =>\n sum + item.forwardSpentMicros + item.compensationSpentMicros, 0);\n if (!Number.isSafeInteger(state.spentMicros) || state.spentMicros > state.maxCostMicros) {\n throw new MayuraError('LIMIT_EXCEEDED', 'Workflow saga exceeded its persisted cost ceiling.');\n }\n };\n const submitChild = async (runId: string, step: WorkflowSagaStep, phase: 'forward' | 'compensation',\n state: WorkflowSagaState): Promise<WorkflowLifecycleSnapshot> => {\n const workflow = phase === 'forward' ? step.forward : step.compensation!.workflow;\n const binding = phase === 'forward' ? step.input : step.compensation!.input;\n const input = resolveBinding(binding, state.input, outputs(state));\n return submitWorkflowLifecycleUnder(lifecycle, pinnedIndex(state), workflow, { input, idempotencyKey: childKey(runId, step.id, phase) });\n };\n\n const run = async (definition: AnyWorkflowSaga, id: string): Promise<WorkflowSagaSnapshot> => {\n assertWorkflowSaga(definition);\n for (let wave = 0; wave < definition.steps.length * 2 + 4; wave++) {\n let record = await load(id); let state = decoded(record); verify(definition, record, state);\n if (terminalSagaStatuses.has(state.status) || state.status === 'paused') return snapshot(record);\n if (state.status === 'running' || state.status === 'waiting') {\n const index = state.cursor; const step = definition.steps[index];\n if (!step) {\n let output: JsonValue;\n try { output = await boundedValidate(definition.output,\n resolveBinding(definition.result, state.input, outputs(state)), 'output', settings[pinnedIndex(state)]!.maxOutputBytes); }\n catch (error) {\n if (!(error instanceof MayuraError) || !['INVALID_INPUT', 'INVALID_OUTPUT'].includes(error.code)) throw error;\n state.status = 'compensating'; state.cursor = definition.steps.length;\n await save(record, state, 'saga.output.rejected'); continue;\n }\n state.output = output; state.status = 'succeeded';\n record = await save(record, state, 'saga.run.succeeded'); return snapshot(record);\n }\n const persisted = state.steps[step.id]!;\n let child: WorkflowLifecycleSnapshot;\n if (persisted.forwardRunId === null) {\n try { child = await submitChild(id, step, 'forward', state); }\n catch (error) {\n if (!(error instanceof MayuraError) || !['INVALID_INPUT', 'INVALID_OUTPUT'].includes(error.code)) throw error;\n await mutate(id, current => { const target = current.steps[step.id]!;\n if (target.status !== 'pending') return false;\n target.status = 'failed';\n for (let next = index + 1; next < definition.steps.length; next++) current.steps[definition.steps[next]!.id]!.status = 'skipped';\n current.status = 'compensating'; current.cursor = index; return true;\n }, 'saga.forward.rejected', { stepId: step.id });\n continue;\n }\n record = await mutate(id, current => { const target = current.steps[step.id]!;\n if (target.forwardRunId !== null) return false;\n recordChild(current, step.id, 'forward', child); target.status = 'forward_waiting';\n current.status = 'running'; return true;\n }, 'saga.forward.linked', { stepId: step.id, childRunId: child.id });\n state = decoded(record); child = await lifecycle.inspect(state.steps[step.id]!.forwardRunId!);\n } else child = await lifecycle.inspect(persisted.forwardRunId);\n child = await lifecycle.runUntilSettled(step.forward, child.id);\n if (!terminalChild(child)) {\n record = await mutate(id, current => { const target = current.steps[step.id]!;\n if (target.forwardRunId !== child.id || terminalSagaStatuses.has(current.status)) return false;\n recordChild(current, step.id, 'forward', child); target.status = 'forward_waiting';\n current.status = child.status === 'waiting' ? 'waiting' : 'running'; return true;\n }, 'saga.forward.waiting', { stepId: step.id, childRunId: child.id });\n return snapshot(record);\n }\n if (successfulChild(child)) {\n record = await mutate(id, current => { const target = current.steps[step.id]!;\n if (target.forwardRunId !== child.id || target.status === 'succeeded') return false;\n recordChild(current, step.id, 'forward', child); target.output = child.output; target.status = 'succeeded';\n current.cursor = index + 1; current.status = 'running'; return true;\n }, 'saga.forward.succeeded', { stepId: step.id, childRunId: child.id });\n continue;\n }\n record = await mutate(id, current => { const target = current.steps[step.id]!;\n if (target.forwardRunId !== child.id || target.status === 'failed') return false;\n recordChild(current, step.id, 'forward', child); target.status = 'failed';\n for (let next = index + 1; next < definition.steps.length; next++) current.steps[definition.steps[next]!.id]!.status = 'skipped';\n current.cursor = index; current.status = 'compensating'; return true;\n }, 'saga.forward.failed', { stepId: step.id, childRunId: child.id, childStatus: child.status });\n continue;\n }\n\n if (state.status === 'compensating') {\n let index = state.cursor - 1;\n while (index >= 0) {\n const candidate = definition.steps[index]!; const persisted = state.steps[candidate.id]!;\n if (persisted.status === 'succeeded' && candidate.compensation) break;\n index -= 1;\n }\n if (index < 0) {\n const compensated = Object.values(state.steps).some(step => step.status === 'compensated');\n state.status = compensated ? 'compensated' : 'failed'; state.cursor = 0;\n record = await save(record, state, compensated ? 'saga.run.compensated' : 'saga.run.failed');\n return snapshot(record);\n }\n const step = definition.steps[index]!; const persisted = state.steps[step.id]!;\n let child: WorkflowLifecycleSnapshot;\n if (persisted.compensationRunId === null) {\n try { child = await submitChild(id, step, 'compensation', state); }\n catch (error) {\n if (!(error instanceof MayuraError) || !['INVALID_INPUT', 'INVALID_OUTPUT'].includes(error.code)) throw error;\n record = await mutate(id, current => { const target = current.steps[step.id]!;\n if (target.status !== 'succeeded') return false;\n target.status = 'compensation_failed'; current.status = 'compensation_failed'; current.cursor = index; return true;\n }, 'saga.compensation.rejected', { stepId: step.id });\n return snapshot(record);\n }\n record = await mutate(id, current => { const target = current.steps[step.id]!;\n if (target.compensationRunId !== null) return false;\n recordChild(current, step.id, 'compensation', child); target.status = 'compensation_waiting';\n current.status = 'compensating'; current.cursor = index + 1; return true;\n }, 'saga.compensation.linked', { stepId: step.id, childRunId: child.id });\n state = decoded(record); child = await lifecycle.inspect(state.steps[step.id]!.compensationRunId!);\n } else child = await lifecycle.inspect(persisted.compensationRunId);\n child = await lifecycle.runUntilSettled(step.compensation!.workflow, child.id);\n if (!terminalChild(child)) {\n record = await mutate(id, current => { const target = current.steps[step.id]!;\n if (target.compensationRunId !== child.id || terminalSagaStatuses.has(current.status)) return false;\n recordChild(current, step.id, 'compensation', child); target.status = 'compensation_waiting';\n current.status = 'compensating'; current.cursor = index + 1; return true;\n }, 'saga.compensation.waiting', { stepId: step.id, childRunId: child.id });\n return snapshot(record);\n }\n if (successfulChild(child)) {\n await mutate(id, current => { const target = current.steps[step.id]!;\n if (target.compensationRunId !== child.id || target.status === 'compensated') return false;\n recordChild(current, step.id, 'compensation', child); target.status = 'compensated';\n current.status = 'compensating'; current.cursor = index; return true;\n }, 'saga.compensation.succeeded', { stepId: step.id, childRunId: child.id });\n continue;\n }\n record = await mutate(id, current => { const target = current.steps[step.id]!;\n if (target.compensationRunId !== child.id || target.status === 'compensation_failed') return false;\n recordChild(current, step.id, 'compensation', child); target.status = 'compensation_failed';\n current.status = 'compensation_failed'; current.cursor = index; return true;\n }, 'saga.compensation.failed', { stepId: step.id, childRunId: child.id, childStatus: child.status });\n return snapshot(record);\n }\n }\n return snapshot(await load(id));\n };\n\n return Object.freeze<WorkflowSagaRuntime>({\n profile: 'saga-v1', lifecycle,\n submit: async (definition, command) => {\n ensureOpen(); assertWorkflowSaga(definition);\n if (definition.maxCostMicros > options.maxCostMicros) throw new MayuraError('LIMIT_EXCEEDED', 'Saga static cost exceeds its runtime ceiling.');\n if (typeof command.idempotencyKey !== 'string' || command.idempotencyKey.length < 1 || command.idempotencyKey.length > 128) {\n throw new MayuraError('INVALID_INPUT', 'A bounded saga submission key is required.');\n }\n const raw = freezeJson(jsonValue(command.input, { maxBytes: maxOutputBytes }));\n const input = await boundedValidate(definition.input, raw, 'input');\n const state = initialWorkflowSagaState(sagaManifest(definition), input, definition.digest, policy, options.maxCostMicros);\n const id = digest('mayura:workflow-saga-run-id:v1', { scope: scopeKey, submissionKey: command.idempotencyKey });\n const created = await createSubmission(() => store.create({ scope: scopeKey, id,\n idempotencyKey: `saga:${command.idempotencyKey}`, definitionHash: definition.digest,\n state: jsonValue(state) as JsonObject, events: [{ type: 'saga.run.created', data: {} }] }), 'workflow saga run');\n verify(definition, created.record, decoded(created.record)); return snapshot(created.record);\n },\n inspect: async id => snapshot(await load(id)),\n events: (id, after = 0) => { ensureOpen(); return storageCall(() => store.events(scopeKey, id, after)); },\n runUntilSettled: run,\n pause: async id => snapshot(await mutate(id, state => {\n if (state.status === 'paused') return false;\n if (terminalSagaStatuses.has(state.status)) throw new MayuraError('CONFLICT', 'A terminal saga cannot be paused.');\n state.status = 'paused'; return true;\n }, 'saga.run.paused', {}, true)),\n resume: async id => snapshot(await mutate(id, state => {\n if (state.status !== 'paused') throw new MayuraError('CONFLICT', 'Only a paused saga can be resumed.');\n const compensating = Object.values(state.steps).some(step => ['failed', 'compensation_waiting', 'compensated', 'compensation_failed'].includes(step.status));\n state.status = compensating ? 'compensating' : 'running'; return true;\n }, 'saga.run.resumed', {}, true)),\n migrate: async (migration, command) => {\n ensureOpen(); assertWorkflowMigration(migration); assertWorkflowSaga(migration.from); assertWorkflowSaga(migration.to);\n const { id, actorId, commandId, dryRun = false } = migrationCommand(command);\n // A reviewed migration is the explicit way to move a saga onto the current settings, whichever it started under.\n const record = await load(id, true); const state = decoded(record); verify(migration.from, record, state, true);\n const preconditions: MigrationBlocker[] = [];\n if (state.status !== 'paused') preconditions.push({ node: '*', reason: `The saga is ${state.status}; pause it before migrating.` });\n if (state.spentMicros > options.maxCostMicros) preconditions.push({ node: '*', reason: 'The saga already spent more than the current maxCostMicros.' });\n if (Object.values(state.steps).some(step => ['failed', 'compensation_waiting', 'compensated', 'compensation_failed'].includes(step.status))) {\n preconditions.push({ node: '*', reason: 'The saga is compensating; only a saga in its forward phase can migrate.' });\n }\n // A running linked child is compared by the definition it is actually pinned to (possibly already migrated).\n const linked = new Map<string, string>();\n for (const [stepId, step] of Object.entries(state.steps)) if (step.status === 'forward_waiting' && step.forwardRunId) {\n const child = await storageCall(() => store.read(scopeKey, step.forwardRunId!));\n if (!child) throw new MayuraError('CONFLICT', 'A linked saga child run is missing.');\n linked.set(stepId, child.definitionHash);\n }\n const nodes = (definition: AnyWorkflowSaga, effective: boolean) => sagaManifest(definition).steps.map((step, index, all) => {\n const forward = effective && linked.has(step.id) ? { ...step.forward, definitionHash: linked.get(step.id)! } : step.forward;\n return { id: step.id, kind: 'saga-step', dependsOn: index === 0 ? [] : [all[index - 1]!.id], fingerprint: nodeFingerprint({ ...step, forward } as unknown as Record<string, unknown>) };\n });\n const statusFor = (status: string): string => status === 'forward_waiting' ? 'running' : status;\n const plan = planWorkflowMigration({ migration, format: 'saga-v1', runId: id, fromDigest: migration.from.digest, toDigest: migration.to.digest,\n from: nodes(migration.from, true), to: nodes(migration.to, false),\n steps: Object.entries(state.steps).map(([step, value]) => ({ id: step, status: statusFor(value.status) })),\n preconditions: [...preconditions, ...Object.entries(state.steps).filter(([stepId, step]) => (step.forwardSpentMicros + step.compensationSpentMicros) > 0\n && !sagaManifest(migration.to).steps.some(target => target.id === stepId || migration.renames[target.id] === stepId))\n .map(([stepId]) => ({ node: stepId, reason: `Step \"${stepId}\" already spent budget; removing it would drop recorded spend.` }))] });\n if (dryRun) return freezeJson(jsonValue({ plan })) as unknown as WorkflowMigrationResult<WorkflowSagaSnapshot>;\n assertMigrationAllowed(plan);\n const toManifest = sagaManifest(migration.to);\n const fresh = initialWorkflowSagaState(toManifest, state.input, migration.to.digest, policy, options.maxCostMicros);\n const carried: Record<string, WorkflowSagaStepState> = {};\n for (const entry of plan.entries) if (entry.target) carried[entry.target] = entry.action === 'keep' || entry.action === 'accept' ? state.steps[entry.source!]! : fresh.steps[entry.target]!;\n const steps = Object.fromEntries(toManifest.steps.map(step => [step.id, carried[step.id]!]));\n const cursor = toManifest.steps.findIndex(step => steps[step.id]!.status !== 'succeeded');\n const next: WorkflowSagaState = { ...state, definition: migration.to.digest, policy, maxCostMicros: options.maxCostMicros,\n steps, cursor: cursor < 0 ? toManifest.steps.length : cursor,\n spentMicros: Object.values(steps).reduce((sum, step) => sum + step.forwardSpentMicros + step.compensationSpentMicros, 0) };\n try { assertWorkflowSagaStateMatchesManifest(workflowSagaState({ id, state: jsonValue(next) as JsonObject }), toManifest); }\n catch { throw new MayuraError('CONFLICT', 'Migration refused: the migrated saga state does not satisfy the new definition.'); }\n if (typeof store.migrate !== 'function') throw new MayuraError('UNSUPPORTED_PROFILE', 'This store cannot migrate in-flight workflow runs.');\n const migrated = await storageCall(() => store.migrate!({ scope: scopeKey, id, expectedVersion: record.version, expectedDefinitionHash: migration.from.digest,\n definitionHash: migration.to.digest, state: jsonValue(next) as JsonObject, events: [migrationEvent(plan, actorId, commandId) as { type: string; data: JsonObject }] }));\n verify(migration.to, migrated, decoded(migrated));\n return freezeJson(jsonValue({ plan, snapshot: snapshot(migrated) })) as unknown as WorkflowMigrationResult<WorkflowSagaSnapshot>;\n },\n cancel: async id => {\n let record = await load(id, true); const state = decoded(record);\n if (terminalSagaStatuses.has(state.status)) return snapshot(record);\n const activeEntry = Object.entries(state.steps).find(([, step]) => step.status === 'forward_waiting' || step.status === 'compensation_waiting');\n const active = activeEntry?.[1]; const activeStepId = activeEntry?.[0];\n const childRunId = active?.status === 'forward_waiting' ? active.forwardRunId : active?.compensationRunId;\n const child = childRunId ? await lifecycle.cancel(childRunId) : undefined;\n record = await mutate(id, current => {\n if (terminalSagaStatuses.has(current.status)) return false;\n if (child && active && activeStepId) {\n const phase = active.status === 'forward_waiting' ? 'forward' : 'compensation';\n const target = current.steps[activeStepId];\n const linked = phase === 'forward' ? target?.forwardRunId : target?.compensationRunId;\n if (linked === child.id) recordChild(current, activeStepId, phase, child);\n }\n current.status = 'cancelled'; return true;\n }, 'saga.run.cancelled', {}, true);\n return snapshot(record);\n },\n close: () => { if (!closed) { closed = true; lifecycle.close(); } },\n drain: async options => { const report = await lifecycle.drain(options); closed = true; return report; },\n });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"scheduled-helpers.d.ts","sourceRoot":"","sources":["../src/scheduled-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EAC2B,aAAa,EAAE,kBAAkB,EACjE,KAAK,KAAK,EAAE,KAAK,SAAS,EAAE,KAAK,yBAAyB,EAAE,KAAK,gBAAgB,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAC7I,KAAK,0BAA0B,EAChC,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OA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G,WAAW,EAAE,CAYhF;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,CAG3G"}
@@ -16,7 +16,7 @@ const storageCodes = new Set(['INVALID_INPUT', 'CONFLICT', 'NOT_FOUND', 'STORAGE
16
16
  /** Preserve only stable storage codes; never copy adapter messages or inspect exception getters. */
17
17
  /** Fixed storage answer when an approval expired before admission: final for that call, and a new review is needed. */
18
18
  export const reviewExpiredMessage = 'The approval expired; request a new review before admission.';
19
- export const isReviewExpired = (error) => error instanceof StorageError && error.code === 'CONFLICT' && error.message === reviewExpiredMessage;
19
+ export const isReviewExpired = (error) => error instanceof StorageError && error.storageCode === 'CONFLICT' && error.message === reviewExpiredMessage;
20
20
  export async function scheduledStorage(operation, timeoutMs = 10_000, signal) {
21
21
  try {
22
22
  return await scheduledCallback(operation, timeoutMs, signal ?? new AbortController().signal);
@@ -25,7 +25,7 @@ export async function scheduledStorage(operation, timeoutMs = 10_000, signal) {
25
25
  let code = 'STORAGE_UNAVAILABLE';
26
26
  let refusal;
27
27
  try {
28
- const own = error instanceof StorageError ? Object.getOwnPropertyDescriptor(error, 'code') : undefined;
28
+ const own = error instanceof StorageError ? Object.getOwnPropertyDescriptor(error, 'storageCode') : undefined;
29
29
  if (own && 'value' in own && storageCodes.has(own.value))
30
30
  code = own.value;
31
31
  // A migration refusal is fixed storage text plus step ids; it is the reviewer's answer, so it is kept verbatim.
@@ -39,7 +39,7 @@ export async function scheduledStorage(operation, timeoutMs = 10_000, signal) {
39
39
  }
40
40
  }
41
41
  export function isStorageCode(error, code) {
42
- return error instanceof StorageError && error.code === code;
42
+ return error instanceof StorageError && error.storageCode === code;
43
43
  }
44
44
  /** One bounded callback window. Late results/rejections are handled without further admission. */
45
45
  export async function scheduledCallback(operation, timeoutMs, signal) {