mayura 0.1.0-dev.0

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 (1116) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +8 -0
  3. package/README.md +55 -0
  4. package/lib/adapter-code-docker/dist/index.d.ts +65 -0
  5. package/lib/adapter-code-docker/dist/index.d.ts.map +1 -0
  6. package/lib/adapter-code-docker/dist/index.js +228 -0
  7. package/lib/adapter-code-docker/dist/index.js.map +1 -0
  8. package/lib/adapter-code-docker/image/Dockerfile +12 -0
  9. package/lib/adapter-code-docker/package.json +5 -0
  10. package/lib/adapter-code-docker/src/index.ts +244 -0
  11. package/lib/adapter-code-quickjs/dist/index.d.ts +40 -0
  12. package/lib/adapter-code-quickjs/dist/index.d.ts.map +1 -0
  13. package/lib/adapter-code-quickjs/dist/index.js +169 -0
  14. package/lib/adapter-code-quickjs/dist/index.js.map +1 -0
  15. package/lib/adapter-code-quickjs/dist/worker.d.ts +2 -0
  16. package/lib/adapter-code-quickjs/dist/worker.d.ts.map +1 -0
  17. package/lib/adapter-code-quickjs/dist/worker.js +164 -0
  18. package/lib/adapter-code-quickjs/dist/worker.js.map +1 -0
  19. package/lib/adapter-code-quickjs/package.json +5 -0
  20. package/lib/adapter-code-quickjs/src/index.ts +174 -0
  21. package/lib/adapter-code-quickjs/src/worker.ts +142 -0
  22. package/lib/adapter-mcp/dist/index.d.ts +29 -0
  23. package/lib/adapter-mcp/dist/index.d.ts.map +1 -0
  24. package/lib/adapter-mcp/dist/index.js +54 -0
  25. package/lib/adapter-mcp/dist/index.js.map +1 -0
  26. package/lib/adapter-mcp/package.json +5 -0
  27. package/lib/adapter-mcp/src/index.ts +82 -0
  28. package/lib/artifacts/dist/contracts.d.ts +139 -0
  29. package/lib/artifacts/dist/contracts.d.ts.map +1 -0
  30. package/lib/artifacts/dist/contracts.js +2 -0
  31. package/lib/artifacts/dist/contracts.js.map +1 -0
  32. package/lib/artifacts/dist/index.d.ts +3 -0
  33. package/lib/artifacts/dist/index.d.ts.map +1 -0
  34. package/lib/artifacts/dist/index.js +2 -0
  35. package/lib/artifacts/dist/index.js.map +1 -0
  36. package/lib/artifacts/dist/local-store.d.ts +3 -0
  37. package/lib/artifacts/dist/local-store.d.ts.map +1 -0
  38. package/lib/artifacts/dist/local-store.js +922 -0
  39. package/lib/artifacts/dist/local-store.js.map +1 -0
  40. package/lib/artifacts/package.json +5 -0
  41. package/lib/artifacts/src/contracts.ts +159 -0
  42. package/lib/artifacts/src/index.ts +26 -0
  43. package/lib/artifacts/src/local-store.ts +816 -0
  44. package/lib/cli/dist/application.d.ts +85 -0
  45. package/lib/cli/dist/application.d.ts.map +1 -0
  46. package/lib/cli/dist/application.js +116 -0
  47. package/lib/cli/dist/application.js.map +1 -0
  48. package/lib/cli/dist/bin.d.ts +3 -0
  49. package/lib/cli/dist/bin.d.ts.map +1 -0
  50. package/lib/cli/dist/bin.js +394 -0
  51. package/lib/cli/dist/bin.js.map +1 -0
  52. package/lib/cli/dist/dev.d.ts +21 -0
  53. package/lib/cli/dist/dev.d.ts.map +1 -0
  54. package/lib/cli/dist/dev.js +205 -0
  55. package/lib/cli/dist/dev.js.map +1 -0
  56. package/lib/cli/dist/index.d.ts +72 -0
  57. package/lib/cli/dist/index.d.ts.map +1 -0
  58. package/lib/cli/dist/index.js +423 -0
  59. package/lib/cli/dist/index.js.map +1 -0
  60. package/lib/cli/dist/interactive.d.ts +19 -0
  61. package/lib/cli/dist/interactive.d.ts.map +1 -0
  62. package/lib/cli/dist/interactive.js +163 -0
  63. package/lib/cli/dist/interactive.js.map +1 -0
  64. package/lib/cli/dist/operations.d.ts +215 -0
  65. package/lib/cli/dist/operations.d.ts.map +1 -0
  66. package/lib/cli/dist/operations.js +580 -0
  67. package/lib/cli/dist/operations.js.map +1 -0
  68. package/lib/cli/dist/output.d.ts +29 -0
  69. package/lib/cli/dist/output.d.ts.map +1 -0
  70. package/lib/cli/dist/output.js +244 -0
  71. package/lib/cli/dist/output.js.map +1 -0
  72. package/lib/cli/dist/providers.d.ts +54 -0
  73. package/lib/cli/dist/providers.d.ts.map +1 -0
  74. package/lib/cli/dist/providers.js +96 -0
  75. package/lib/cli/dist/providers.js.map +1 -0
  76. package/lib/cli/package.json +5 -0
  77. package/lib/cli/src/application.ts +109 -0
  78. package/lib/cli/src/bin.ts +261 -0
  79. package/lib/cli/src/dev.ts +139 -0
  80. package/lib/cli/src/index.ts +386 -0
  81. package/lib/cli/src/interactive.ts +132 -0
  82. package/lib/cli/src/operations.ts +458 -0
  83. package/lib/cli/src/output.ts +205 -0
  84. package/lib/cli/src/providers.ts +102 -0
  85. package/lib/cli/starters/approval-workflow/Dockerfile +20 -0
  86. package/lib/cli/starters/approval-workflow/README.md +102 -0
  87. package/lib/cli/starters/approval-workflow/compose.yaml +33 -0
  88. package/lib/cli/starters/approval-workflow/dot-dockerignore +7 -0
  89. package/lib/cli/starters/approval-workflow/dot-env.example +41 -0
  90. package/lib/cli/starters/approval-workflow/dot-github/workflows/ci.yml +13 -0
  91. package/lib/cli/starters/approval-workflow/dot-gitignore +10 -0
  92. package/lib/cli/starters/approval-workflow/mayura.project.json +16 -0
  93. package/lib/cli/starters/approval-workflow/package.json +30 -0
  94. package/lib/cli/starters/approval-workflow/src/app.ts +19 -0
  95. package/lib/cli/starters/approval-workflow/src/auth.ts +68 -0
  96. package/lib/cli/starters/approval-workflow/src/config.ts +107 -0
  97. package/lib/cli/starters/approval-workflow/src/dev.ts +59 -0
  98. package/lib/cli/starters/approval-workflow/src/intake.ts +104 -0
  99. package/lib/cli/starters/approval-workflow/src/model.ts +33 -0
  100. package/lib/cli/starters/approval-workflow/src/server.ts +56 -0
  101. package/lib/cli/starters/approval-workflow/src/services.ts +26 -0
  102. package/lib/cli/starters/approval-workflow/src/token.ts +6 -0
  103. package/lib/cli/starters/approval-workflow/src/worker.ts +18 -0
  104. package/lib/cli/starters/approval-workflow/src/workflow.ts +100 -0
  105. package/lib/cli/starters/approval-workflow/test/refunds.test.ts +140 -0
  106. package/lib/cli/starters/approval-workflow/tsconfig.json +20 -0
  107. package/lib/cli/starters/event-automation/Dockerfile +21 -0
  108. package/lib/cli/starters/event-automation/README.md +150 -0
  109. package/lib/cli/starters/event-automation/compose.yaml +41 -0
  110. package/lib/cli/starters/event-automation/dot-dockerignore +7 -0
  111. package/lib/cli/starters/event-automation/dot-env.example +51 -0
  112. package/lib/cli/starters/event-automation/dot-github/workflows/ci.yml +13 -0
  113. package/lib/cli/starters/event-automation/dot-gitignore +10 -0
  114. package/lib/cli/starters/event-automation/mayura.project.json +17 -0
  115. package/lib/cli/starters/event-automation/package.json +32 -0
  116. package/lib/cli/starters/event-automation/src/app.ts +19 -0
  117. package/lib/cli/starters/event-automation/src/auth.ts +61 -0
  118. package/lib/cli/starters/event-automation/src/config.ts +138 -0
  119. package/lib/cli/starters/event-automation/src/dev.ts +54 -0
  120. package/lib/cli/starters/event-automation/src/ingress.ts +129 -0
  121. package/lib/cli/starters/event-automation/src/mcp.ts +139 -0
  122. package/lib/cli/starters/event-automation/src/model.ts +33 -0
  123. package/lib/cli/starters/event-automation/src/send-sample.ts +29 -0
  124. package/lib/cli/starters/event-automation/src/server.ts +58 -0
  125. package/lib/cli/starters/event-automation/src/services.ts +54 -0
  126. package/lib/cli/starters/event-automation/src/signing.ts +30 -0
  127. package/lib/cli/starters/event-automation/src/token.ts +7 -0
  128. package/lib/cli/starters/event-automation/src/tracker/main.ts +18 -0
  129. package/lib/cli/starters/event-automation/src/tracker/mcp-server.ts +145 -0
  130. package/lib/cli/starters/event-automation/src/tracker/samples.ts +19 -0
  131. package/lib/cli/starters/event-automation/src/tracker/tickets.ts +54 -0
  132. package/lib/cli/starters/event-automation/src/tracker-tools.ts +38 -0
  133. package/lib/cli/starters/event-automation/src/triage.ts +151 -0
  134. package/lib/cli/starters/event-automation/src/worker.ts +19 -0
  135. package/lib/cli/starters/event-automation/src/workflows.ts +57 -0
  136. package/lib/cli/starters/event-automation/test/automation.test.ts +200 -0
  137. package/lib/cli/starters/event-automation/tsconfig.json +20 -0
  138. package/lib/cli/starters/research-team/Dockerfile +22 -0
  139. package/lib/cli/starters/research-team/README.md +189 -0
  140. package/lib/cli/starters/research-team/compose.yaml +38 -0
  141. package/lib/cli/starters/research-team/dot-dockerignore +7 -0
  142. package/lib/cli/starters/research-team/dot-env.example +49 -0
  143. package/lib/cli/starters/research-team/dot-github/workflows/ci.yml +13 -0
  144. package/lib/cli/starters/research-team/dot-gitignore +10 -0
  145. package/lib/cli/starters/research-team/mayura.project.json +22 -0
  146. package/lib/cli/starters/research-team/package.json +30 -0
  147. package/lib/cli/starters/research-team/src/app.ts +19 -0
  148. package/lib/cli/starters/research-team/src/auth.ts +56 -0
  149. package/lib/cli/starters/research-team/src/config.ts +170 -0
  150. package/lib/cli/starters/research-team/src/desk.ts +124 -0
  151. package/lib/cli/starters/research-team/src/dev.ts +58 -0
  152. package/lib/cli/starters/research-team/src/library/corpus.ts +76 -0
  153. package/lib/cli/starters/research-team/src/library/index.ts +109 -0
  154. package/lib/cli/starters/research-team/src/model.ts +33 -0
  155. package/lib/cli/starters/research-team/src/server.ts +69 -0
  156. package/lib/cli/starters/research-team/src/services.ts +48 -0
  157. package/lib/cli/starters/research-team/src/team.ts +173 -0
  158. package/lib/cli/starters/research-team/src/telemetry.ts +95 -0
  159. package/lib/cli/starters/research-team/src/token.ts +6 -0
  160. package/lib/cli/starters/research-team/src/worker.ts +21 -0
  161. package/lib/cli/starters/research-team/src/workflow.ts +197 -0
  162. package/lib/cli/starters/research-team/test/research.test.ts +271 -0
  163. package/lib/cli/starters/research-team/tsconfig.json +20 -0
  164. package/lib/cli/starters/support-agent/Dockerfile +21 -0
  165. package/lib/cli/starters/support-agent/README.md +128 -0
  166. package/lib/cli/starters/support-agent/compose.yaml +33 -0
  167. package/lib/cli/starters/support-agent/dot-dockerignore +7 -0
  168. package/lib/cli/starters/support-agent/dot-env.example +44 -0
  169. package/lib/cli/starters/support-agent/dot-github/workflows/ci.yml +13 -0
  170. package/lib/cli/starters/support-agent/dot-gitignore +10 -0
  171. package/lib/cli/starters/support-agent/mayura.project.json +18 -0
  172. package/lib/cli/starters/support-agent/package.json +43 -0
  173. package/lib/cli/starters/support-agent/src/app.ts +19 -0
  174. package/lib/cli/starters/support-agent/src/assistant.ts +313 -0
  175. package/lib/cli/starters/support-agent/src/auth.ts +69 -0
  176. package/lib/cli/starters/support-agent/src/config.ts +120 -0
  177. package/lib/cli/starters/support-agent/src/dev.ts +115 -0
  178. package/lib/cli/starters/support-agent/src/guardrails.ts +71 -0
  179. package/lib/cli/starters/support-agent/src/model.ts +33 -0
  180. package/lib/cli/starters/support-agent/src/orders.ts +62 -0
  181. package/lib/cli/starters/support-agent/src/returns.ts +86 -0
  182. package/lib/cli/starters/support-agent/src/server.ts +72 -0
  183. package/lib/cli/starters/support-agent/src/services.ts +32 -0
  184. package/lib/cli/starters/support-agent/src/session.ts +55 -0
  185. package/lib/cli/starters/support-agent/src/token.ts +9 -0
  186. package/lib/cli/starters/support-agent/src/worker.ts +19 -0
  187. package/lib/cli/starters/support-agent/test/support.test.ts +263 -0
  188. package/lib/cli/starters/support-agent/tsconfig.json +20 -0
  189. package/lib/cli/starters/support-agent/web/index.html +12 -0
  190. package/lib/cli/starters/support-agent/web/src/App.tsx +43 -0
  191. package/lib/cli/starters/support-agent/web/src/components/chat.tsx +161 -0
  192. package/lib/cli/starters/support-agent/web/src/components/ui/button.tsx +33 -0
  193. package/lib/cli/starters/support-agent/web/src/components/ui/primitives.tsx +48 -0
  194. package/lib/cli/starters/support-agent/web/src/env.d.ts +1 -0
  195. package/lib/cli/starters/support-agent/web/src/lib/api.ts +56 -0
  196. package/lib/cli/starters/support-agent/web/src/lib/utils.ts +4 -0
  197. package/lib/cli/starters/support-agent/web/src/main.tsx +6 -0
  198. package/lib/cli/starters/support-agent/web/src/styles.css +86 -0
  199. package/lib/cli/starters/support-agent/web/tsconfig.json +9 -0
  200. package/lib/cli/starters/support-agent/web/vite.config.ts +13 -0
  201. package/lib/cli/templates/basic-agent.ts +10 -0
  202. package/lib/cli/templates/capability-policy.ts +18 -0
  203. package/lib/cli/templates/code-mode-workflow.ts +34 -0
  204. package/lib/cli/templates/durable-approval.ts +25 -0
  205. package/lib/cli/templates/guarded-streaming-app.ts +23 -0
  206. package/lib/cli/templates/native-memory.ts +15 -0
  207. package/lib/cli/templates/parallel-research.ts +21 -0
  208. package/lib/cli/templates/typed-tool-runner.ts +15 -0
  209. package/lib/client/dist/forms.d.ts +77 -0
  210. package/lib/client/dist/forms.d.ts.map +1 -0
  211. package/lib/client/dist/forms.js +282 -0
  212. package/lib/client/dist/forms.js.map +1 -0
  213. package/lib/client/dist/headless.d.ts +84 -0
  214. package/lib/client/dist/headless.d.ts.map +1 -0
  215. package/lib/client/dist/headless.js +376 -0
  216. package/lib/client/dist/headless.js.map +1 -0
  217. package/lib/client/dist/index.d.ts +266 -0
  218. package/lib/client/dist/index.d.ts.map +1 -0
  219. package/lib/client/dist/index.js +814 -0
  220. package/lib/client/dist/index.js.map +1 -0
  221. package/lib/client/dist/workflows.d.ts +128 -0
  222. package/lib/client/dist/workflows.d.ts.map +1 -0
  223. package/lib/client/dist/workflows.js +379 -0
  224. package/lib/client/dist/workflows.js.map +1 -0
  225. package/lib/client/package.json +5 -0
  226. package/lib/client/src/forms.ts +215 -0
  227. package/lib/client/src/headless.ts +265 -0
  228. package/lib/client/src/index.ts +646 -0
  229. package/lib/client/src/workflows.ts +307 -0
  230. package/lib/client-react/dist/components.d.ts +70 -0
  231. package/lib/client-react/dist/components.d.ts.map +1 -0
  232. package/lib/client-react/dist/components.js +173 -0
  233. package/lib/client-react/dist/components.js.map +1 -0
  234. package/lib/client-react/dist/index.d.ts +29 -0
  235. package/lib/client-react/dist/index.d.ts.map +1 -0
  236. package/lib/client-react/dist/index.js +57 -0
  237. package/lib/client-react/dist/index.js.map +1 -0
  238. package/lib/client-react/package.json +5 -0
  239. package/lib/client-react/src/components.ts +183 -0
  240. package/lib/client-react/src/index.ts +70 -0
  241. package/lib/code-mode/dist/index.d.ts +142 -0
  242. package/lib/code-mode/dist/index.d.ts.map +1 -0
  243. package/lib/code-mode/dist/index.js +498 -0
  244. package/lib/code-mode/dist/index.js.map +1 -0
  245. package/lib/code-mode/package.json +5 -0
  246. package/lib/code-mode/src/index.ts +605 -0
  247. package/lib/code-mode-workflows/dist/index.d.ts +51 -0
  248. package/lib/code-mode-workflows/dist/index.d.ts.map +1 -0
  249. package/lib/code-mode-workflows/dist/index.js +231 -0
  250. package/lib/code-mode-workflows/dist/index.js.map +1 -0
  251. package/lib/code-mode-workflows/package.json +5 -0
  252. package/lib/code-mode-workflows/src/index.ts +259 -0
  253. package/lib/context/dist/assemble.d.ts +11 -0
  254. package/lib/context/dist/assemble.d.ts.map +1 -0
  255. package/lib/context/dist/assemble.js +265 -0
  256. package/lib/context/dist/assemble.js.map +1 -0
  257. package/lib/context/dist/cache.d.ts +53 -0
  258. package/lib/context/dist/cache.d.ts.map +1 -0
  259. package/lib/context/dist/cache.js +147 -0
  260. package/lib/context/dist/cache.js.map +1 -0
  261. package/lib/context/dist/contracts.d.ts +145 -0
  262. package/lib/context/dist/contracts.d.ts.map +1 -0
  263. package/lib/context/dist/contracts.js +2 -0
  264. package/lib/context/dist/contracts.js.map +1 -0
  265. package/lib/context/dist/index.d.ts +4 -0
  266. package/lib/context/dist/index.d.ts.map +1 -0
  267. package/lib/context/dist/index.js +3 -0
  268. package/lib/context/dist/index.js.map +1 -0
  269. package/lib/context/package.json +5 -0
  270. package/lib/context/src/assemble.ts +205 -0
  271. package/lib/context/src/cache.ts +143 -0
  272. package/lib/context/src/contracts.ts +124 -0
  273. package/lib/context/src/index.ts +3 -0
  274. package/lib/core/dist/budget.d.ts +85 -0
  275. package/lib/core/dist/budget.d.ts.map +1 -0
  276. package/lib/core/dist/budget.js +328 -0
  277. package/lib/core/dist/budget.js.map +1 -0
  278. package/lib/core/dist/contracts.d.ts +156 -0
  279. package/lib/core/dist/contracts.d.ts.map +1 -0
  280. package/lib/core/dist/contracts.js +13 -0
  281. package/lib/core/dist/contracts.js.map +1 -0
  282. package/lib/core/dist/errors.d.ts +17 -0
  283. package/lib/core/dist/errors.d.ts.map +1 -0
  284. package/lib/core/dist/errors.js +22 -0
  285. package/lib/core/dist/errors.js.map +1 -0
  286. package/lib/core/dist/event-stream.d.ts +26 -0
  287. package/lib/core/dist/event-stream.d.ts.map +1 -0
  288. package/lib/core/dist/event-stream.js +116 -0
  289. package/lib/core/dist/event-stream.js.map +1 -0
  290. package/lib/core/dist/host.d.ts +7 -0
  291. package/lib/core/dist/host.d.ts.map +1 -0
  292. package/lib/core/dist/host.js +7 -0
  293. package/lib/core/dist/host.js.map +1 -0
  294. package/lib/core/dist/index.d.ts +8 -0
  295. package/lib/core/dist/index.d.ts.map +1 -0
  296. package/lib/core/dist/index.js +7 -0
  297. package/lib/core/dist/index.js.map +1 -0
  298. package/lib/core/dist/json.d.ts +18 -0
  299. package/lib/core/dist/json.d.ts.map +1 -0
  300. package/lib/core/dist/json.js +100 -0
  301. package/lib/core/dist/json.js.map +1 -0
  302. package/lib/core/dist/lifecycle.d.ts +45 -0
  303. package/lib/core/dist/lifecycle.d.ts.map +1 -0
  304. package/lib/core/dist/lifecycle.js +114 -0
  305. package/lib/core/dist/lifecycle.js.map +1 -0
  306. package/lib/core/dist/local-guards.d.ts +4 -0
  307. package/lib/core/dist/local-guards.d.ts.map +1 -0
  308. package/lib/core/dist/local-guards.js +47 -0
  309. package/lib/core/dist/local-guards.js.map +1 -0
  310. package/lib/core/dist/managed-guards.d.ts +44 -0
  311. package/lib/core/dist/managed-guards.d.ts.map +1 -0
  312. package/lib/core/dist/managed-guards.js +146 -0
  313. package/lib/core/dist/managed-guards.js.map +1 -0
  314. package/lib/core/dist/schema.d.ts +36 -0
  315. package/lib/core/dist/schema.d.ts.map +1 -0
  316. package/lib/core/dist/schema.js +24 -0
  317. package/lib/core/dist/schema.js.map +1 -0
  318. package/lib/core/package.json +5 -0
  319. package/lib/core/src/budget.ts +366 -0
  320. package/lib/core/src/contracts.ts +107 -0
  321. package/lib/core/src/errors.ts +33 -0
  322. package/lib/core/src/event-stream.ts +87 -0
  323. package/lib/core/src/host.ts +6 -0
  324. package/lib/core/src/index.ts +7 -0
  325. package/lib/core/src/json.ts +81 -0
  326. package/lib/core/src/lifecycle.ts +133 -0
  327. package/lib/core/src/local-guards.ts +37 -0
  328. package/lib/core/src/managed-guards.ts +154 -0
  329. package/lib/core/src/schema.ts +43 -0
  330. package/lib/exporter-otlp/dist/contracts.d.ts +112 -0
  331. package/lib/exporter-otlp/dist/contracts.d.ts.map +1 -0
  332. package/lib/exporter-otlp/dist/contracts.js +2 -0
  333. package/lib/exporter-otlp/dist/contracts.js.map +1 -0
  334. package/lib/exporter-otlp/dist/index.d.ts +5 -0
  335. package/lib/exporter-otlp/dist/index.d.ts.map +1 -0
  336. package/lib/exporter-otlp/dist/index.js +4 -0
  337. package/lib/exporter-otlp/dist/index.js.map +1 -0
  338. package/lib/exporter-otlp/dist/otlp-http-json.d.ts +4 -0
  339. package/lib/exporter-otlp/dist/otlp-http-json.d.ts.map +1 -0
  340. package/lib/exporter-otlp/dist/otlp-http-json.js +286 -0
  341. package/lib/exporter-otlp/dist/otlp-http-json.js.map +1 -0
  342. package/lib/exporter-otlp/dist/run-traces.d.ts +15 -0
  343. package/lib/exporter-otlp/dist/run-traces.d.ts.map +1 -0
  344. package/lib/exporter-otlp/dist/run-traces.js +114 -0
  345. package/lib/exporter-otlp/dist/run-traces.js.map +1 -0
  346. package/lib/exporter-otlp/dist/signals.d.ts +4 -0
  347. package/lib/exporter-otlp/dist/signals.d.ts.map +1 -0
  348. package/lib/exporter-otlp/dist/signals.js +330 -0
  349. package/lib/exporter-otlp/dist/signals.js.map +1 -0
  350. package/lib/exporter-otlp/package.json +5 -0
  351. package/lib/exporter-otlp/src/contracts.ts +119 -0
  352. package/lib/exporter-otlp/src/index.ts +23 -0
  353. package/lib/exporter-otlp/src/otlp-http-json.ts +189 -0
  354. package/lib/exporter-otlp/src/run-traces.ts +86 -0
  355. package/lib/exporter-otlp/src/signals.ts +185 -0
  356. package/lib/guardrails/dist/agent-guard.d.ts +9 -0
  357. package/lib/guardrails/dist/agent-guard.d.ts.map +1 -0
  358. package/lib/guardrails/dist/agent-guard.js +23 -0
  359. package/lib/guardrails/dist/agent-guard.js.map +1 -0
  360. package/lib/guardrails/dist/auxiliary-helpers.d.ts +63 -0
  361. package/lib/guardrails/dist/auxiliary-helpers.d.ts.map +1 -0
  362. package/lib/guardrails/dist/auxiliary-helpers.js +147 -0
  363. package/lib/guardrails/dist/auxiliary-helpers.js.map +1 -0
  364. package/lib/guardrails/dist/auxiliary.d.ts +51 -0
  365. package/lib/guardrails/dist/auxiliary.d.ts.map +1 -0
  366. package/lib/guardrails/dist/auxiliary.js +230 -0
  367. package/lib/guardrails/dist/auxiliary.js.map +1 -0
  368. package/lib/guardrails/dist/batches.d.ts +18 -0
  369. package/lib/guardrails/dist/batches.d.ts.map +1 -0
  370. package/lib/guardrails/dist/batches.js +160 -0
  371. package/lib/guardrails/dist/batches.js.map +1 -0
  372. package/lib/guardrails/dist/disclosure.d.ts +30 -0
  373. package/lib/guardrails/dist/disclosure.d.ts.map +1 -0
  374. package/lib/guardrails/dist/disclosure.js +109 -0
  375. package/lib/guardrails/dist/disclosure.js.map +1 -0
  376. package/lib/guardrails/dist/helpers.d.ts +20 -0
  377. package/lib/guardrails/dist/helpers.d.ts.map +1 -0
  378. package/lib/guardrails/dist/helpers.js +72 -0
  379. package/lib/guardrails/dist/helpers.js.map +1 -0
  380. package/lib/guardrails/dist/index.d.ts +9 -0
  381. package/lib/guardrails/dist/index.d.ts.map +1 -0
  382. package/lib/guardrails/dist/index.js +9 -0
  383. package/lib/guardrails/dist/index.js.map +1 -0
  384. package/lib/guardrails/dist/managed.d.ts +18 -0
  385. package/lib/guardrails/dist/managed.d.ts.map +1 -0
  386. package/lib/guardrails/dist/managed.js +67 -0
  387. package/lib/guardrails/dist/managed.js.map +1 -0
  388. package/lib/guardrails/dist/pipeline.d.ts +55 -0
  389. package/lib/guardrails/dist/pipeline.d.ts.map +1 -0
  390. package/lib/guardrails/dist/pipeline.js +201 -0
  391. package/lib/guardrails/dist/pipeline.js.map +1 -0
  392. package/lib/guardrails/package.json +5 -0
  393. package/lib/guardrails/src/agent-guard.ts +22 -0
  394. package/lib/guardrails/src/auxiliary-helpers.ts +146 -0
  395. package/lib/guardrails/src/auxiliary.ts +202 -0
  396. package/lib/guardrails/src/batches.ts +130 -0
  397. package/lib/guardrails/src/disclosure.ts +92 -0
  398. package/lib/guardrails/src/helpers.ts +67 -0
  399. package/lib/guardrails/src/index.ts +8 -0
  400. package/lib/guardrails/src/managed.ts +64 -0
  401. package/lib/guardrails/src/pipeline.ts +185 -0
  402. package/lib/helpers/dist/concurrency.d.ts +25 -0
  403. package/lib/helpers/dist/concurrency.d.ts.map +1 -0
  404. package/lib/helpers/dist/concurrency.js +106 -0
  405. package/lib/helpers/dist/concurrency.js.map +1 -0
  406. package/lib/helpers/dist/configuration.d.ts +42 -0
  407. package/lib/helpers/dist/configuration.d.ts.map +1 -0
  408. package/lib/helpers/dist/configuration.js +119 -0
  409. package/lib/helpers/dist/configuration.js.map +1 -0
  410. package/lib/helpers/dist/control.d.ts +61 -0
  411. package/lib/helpers/dist/control.d.ts.map +1 -0
  412. package/lib/helpers/dist/control.js +220 -0
  413. package/lib/helpers/dist/control.js.map +1 -0
  414. package/lib/helpers/dist/credentials.d.ts +42 -0
  415. package/lib/helpers/dist/credentials.d.ts.map +1 -0
  416. package/lib/helpers/dist/credentials.js +126 -0
  417. package/lib/helpers/dist/credentials.js.map +1 -0
  418. package/lib/helpers/dist/data.d.ts +30 -0
  419. package/lib/helpers/dist/data.d.ts.map +1 -0
  420. package/lib/helpers/dist/data.js +90 -0
  421. package/lib/helpers/dist/data.js.map +1 -0
  422. package/lib/helpers/dist/index.d.ts +6 -0
  423. package/lib/helpers/dist/index.d.ts.map +1 -0
  424. package/lib/helpers/dist/index.js +6 -0
  425. package/lib/helpers/dist/index.js.map +1 -0
  426. package/lib/helpers/package.json +5 -0
  427. package/lib/helpers/src/concurrency.ts +92 -0
  428. package/lib/helpers/src/configuration.ts +131 -0
  429. package/lib/helpers/src/control.ts +231 -0
  430. package/lib/helpers/src/credentials.ts +113 -0
  431. package/lib/helpers/src/data.ts +105 -0
  432. package/lib/helpers/src/index.ts +5 -0
  433. package/lib/memory/dist/contracts.d.ts +146 -0
  434. package/lib/memory/dist/contracts.d.ts.map +1 -0
  435. package/lib/memory/dist/contracts.js +2 -0
  436. package/lib/memory/dist/contracts.js.map +1 -0
  437. package/lib/memory/dist/index.d.ts +10 -0
  438. package/lib/memory/dist/index.d.ts.map +1 -0
  439. package/lib/memory/dist/index.js +316 -0
  440. package/lib/memory/dist/index.js.map +1 -0
  441. package/lib/memory/dist/native.d.ts +157 -0
  442. package/lib/memory/dist/native.d.ts.map +1 -0
  443. package/lib/memory/dist/native.js +664 -0
  444. package/lib/memory/dist/native.js.map +1 -0
  445. package/lib/memory/dist/validation.d.ts +21 -0
  446. package/lib/memory/dist/validation.d.ts.map +1 -0
  447. package/lib/memory/dist/validation.js +123 -0
  448. package/lib/memory/dist/validation.js.map +1 -0
  449. package/lib/memory/dist/vectors.d.ts +40 -0
  450. package/lib/memory/dist/vectors.d.ts.map +1 -0
  451. package/lib/memory/dist/vectors.js +134 -0
  452. package/lib/memory/dist/vectors.js.map +1 -0
  453. package/lib/memory/package.json +5 -0
  454. package/lib/memory/src/contracts.ts +113 -0
  455. package/lib/memory/src/index.ts +241 -0
  456. package/lib/memory/src/native.ts +568 -0
  457. package/lib/memory/src/validation.ts +103 -0
  458. package/lib/memory/src/vectors.ts +121 -0
  459. package/lib/memory-remote/dist/index.d.ts +91 -0
  460. package/lib/memory-remote/dist/index.d.ts.map +1 -0
  461. package/lib/memory-remote/dist/index.js +434 -0
  462. package/lib/memory-remote/dist/index.js.map +1 -0
  463. package/lib/memory-remote/package.json +5 -0
  464. package/lib/memory-remote/src/index.ts +367 -0
  465. package/lib/observability/dist/contracts.d.ts +102 -0
  466. package/lib/observability/dist/contracts.d.ts.map +1 -0
  467. package/lib/observability/dist/contracts.js +2 -0
  468. package/lib/observability/dist/contracts.js.map +1 -0
  469. package/lib/observability/dist/index.d.ts +5 -0
  470. package/lib/observability/dist/index.d.ts.map +1 -0
  471. package/lib/observability/dist/index.js +4 -0
  472. package/lib/observability/dist/index.js.map +1 -0
  473. package/lib/observability/dist/observer.d.ts +4 -0
  474. package/lib/observability/dist/observer.d.ts.map +1 -0
  475. package/lib/observability/dist/observer.js +354 -0
  476. package/lib/observability/dist/observer.js.map +1 -0
  477. package/lib/observability/dist/validation.d.ts +6 -0
  478. package/lib/observability/dist/validation.d.ts.map +1 -0
  479. package/lib/observability/dist/validation.js +203 -0
  480. package/lib/observability/dist/validation.js.map +1 -0
  481. package/lib/observability/package.json +5 -0
  482. package/lib/observability/src/contracts.ts +85 -0
  483. package/lib/observability/src/index.ts +4 -0
  484. package/lib/observability/src/observer.ts +246 -0
  485. package/lib/observability/src/validation.ts +132 -0
  486. package/lib/provider-anthropic/dist/index.d.ts +19 -0
  487. package/lib/provider-anthropic/dist/index.d.ts.map +1 -0
  488. package/lib/provider-anthropic/dist/index.js +342 -0
  489. package/lib/provider-anthropic/dist/index.js.map +1 -0
  490. package/lib/provider-anthropic/package.json +5 -0
  491. package/lib/provider-anthropic/src/index.ts +317 -0
  492. package/lib/provider-openai/dist/index.d.ts +77 -0
  493. package/lib/provider-openai/dist/index.d.ts.map +1 -0
  494. package/lib/provider-openai/dist/index.js +577 -0
  495. package/lib/provider-openai/dist/index.js.map +1 -0
  496. package/lib/provider-openai/package.json +5 -0
  497. package/lib/provider-openai/src/index.ts +459 -0
  498. package/lib/runtime/dist/agent.d.ts +63 -0
  499. package/lib/runtime/dist/agent.d.ts.map +1 -0
  500. package/lib/runtime/dist/agent.js +134 -0
  501. package/lib/runtime/dist/agent.js.map +1 -0
  502. package/lib/runtime/dist/composition.d.ts +21 -0
  503. package/lib/runtime/dist/composition.d.ts.map +1 -0
  504. package/lib/runtime/dist/composition.js +54 -0
  505. package/lib/runtime/dist/composition.js.map +1 -0
  506. package/lib/runtime/dist/event-buffer.d.ts +18 -0
  507. package/lib/runtime/dist/event-buffer.d.ts.map +1 -0
  508. package/lib/runtime/dist/event-buffer.js +66 -0
  509. package/lib/runtime/dist/event-buffer.js.map +1 -0
  510. package/lib/runtime/dist/hook-execution.d.ts +40 -0
  511. package/lib/runtime/dist/hook-execution.d.ts.map +1 -0
  512. package/lib/runtime/dist/hook-execution.js +186 -0
  513. package/lib/runtime/dist/hook-execution.js.map +1 -0
  514. package/lib/runtime/dist/hooks.d.ts +178 -0
  515. package/lib/runtime/dist/hooks.d.ts.map +1 -0
  516. package/lib/runtime/dist/hooks.js +120 -0
  517. package/lib/runtime/dist/hooks.js.map +1 -0
  518. package/lib/runtime/dist/index.d.ts +6 -0
  519. package/lib/runtime/dist/index.d.ts.map +1 -0
  520. package/lib/runtime/dist/index.js +6 -0
  521. package/lib/runtime/dist/index.js.map +1 -0
  522. package/lib/runtime/dist/managed-guards.d.ts +27 -0
  523. package/lib/runtime/dist/managed-guards.d.ts.map +1 -0
  524. package/lib/runtime/dist/managed-guards.js +183 -0
  525. package/lib/runtime/dist/managed-guards.js.map +1 -0
  526. package/lib/runtime/dist/permits.d.ts +9 -0
  527. package/lib/runtime/dist/permits.d.ts.map +1 -0
  528. package/lib/runtime/dist/permits.js +77 -0
  529. package/lib/runtime/dist/permits.js.map +1 -0
  530. package/lib/runtime/dist/response.d.ts +8 -0
  531. package/lib/runtime/dist/response.d.ts.map +1 -0
  532. package/lib/runtime/dist/response.js +83 -0
  533. package/lib/runtime/dist/response.js.map +1 -0
  534. package/lib/runtime/dist/router.d.ts +51 -0
  535. package/lib/runtime/dist/router.d.ts.map +1 -0
  536. package/lib/runtime/dist/router.js +181 -0
  537. package/lib/runtime/dist/router.js.map +1 -0
  538. package/lib/runtime/dist/runtime.d.ts +98 -0
  539. package/lib/runtime/dist/runtime.d.ts.map +1 -0
  540. package/lib/runtime/dist/runtime.js +945 -0
  541. package/lib/runtime/dist/runtime.js.map +1 -0
  542. package/lib/runtime/dist/stream.d.ts +25 -0
  543. package/lib/runtime/dist/stream.d.ts.map +1 -0
  544. package/lib/runtime/dist/stream.js +226 -0
  545. package/lib/runtime/dist/stream.js.map +1 -0
  546. package/lib/runtime/package.json +5 -0
  547. package/lib/runtime/src/agent.ts +167 -0
  548. package/lib/runtime/src/composition.ts +63 -0
  549. package/lib/runtime/src/event-buffer.ts +55 -0
  550. package/lib/runtime/src/hook-execution.ts +188 -0
  551. package/lib/runtime/src/hooks.ts +227 -0
  552. package/lib/runtime/src/index.ts +5 -0
  553. package/lib/runtime/src/managed-guards.ts +176 -0
  554. package/lib/runtime/src/permits.ts +65 -0
  555. package/lib/runtime/src/response.ts +68 -0
  556. package/lib/runtime/src/router.ts +178 -0
  557. package/lib/runtime/src/runtime.ts +909 -0
  558. package/lib/runtime/src/stream.ts +130 -0
  559. package/lib/sdk/dist/index.d.ts +5 -0
  560. package/lib/sdk/dist/index.d.ts.map +1 -0
  561. package/lib/sdk/dist/index.js +5 -0
  562. package/lib/sdk/dist/index.js.map +1 -0
  563. package/lib/sdk/package.json +5 -0
  564. package/lib/sdk/src/index.ts +4 -0
  565. package/lib/server/dist/index.d.ts +343 -0
  566. package/lib/server/dist/index.d.ts.map +1 -0
  567. package/lib/server/dist/index.js +1356 -0
  568. package/lib/server/dist/index.js.map +1 -0
  569. package/lib/server/dist/inspector-bundle.d.ts +6 -0
  570. package/lib/server/dist/inspector-bundle.d.ts.map +1 -0
  571. package/lib/server/dist/inspector-bundle.js +6 -0
  572. package/lib/server/dist/inspector-bundle.js.map +1 -0
  573. package/lib/server/dist/inspector.d.ts +3 -0
  574. package/lib/server/dist/inspector.d.ts.map +1 -0
  575. package/lib/server/dist/inspector.js +27 -0
  576. package/lib/server/dist/inspector.js.map +1 -0
  577. package/lib/server/package.json +5 -0
  578. package/lib/server/src/index.ts +1033 -0
  579. package/lib/server/src/inspector-bundle.ts +5 -0
  580. package/lib/server/src/inspector.ts +27 -0
  581. package/lib/server-node/dist/hardening.d.ts +19 -0
  582. package/lib/server-node/dist/hardening.d.ts.map +1 -0
  583. package/lib/server-node/dist/hardening.js +79 -0
  584. package/lib/server-node/dist/hardening.js.map +1 -0
  585. package/lib/server-node/dist/index.d.ts +18 -0
  586. package/lib/server-node/dist/index.d.ts.map +1 -0
  587. package/lib/server-node/dist/index.js +53 -0
  588. package/lib/server-node/dist/index.js.map +1 -0
  589. package/lib/server-node/dist/probe.d.ts +13 -0
  590. package/lib/server-node/dist/probe.d.ts.map +1 -0
  591. package/lib/server-node/dist/probe.js +44 -0
  592. package/lib/server-node/dist/probe.js.map +1 -0
  593. package/lib/server-node/dist/production.d.ts +32 -0
  594. package/lib/server-node/dist/production.d.ts.map +1 -0
  595. package/lib/server-node/dist/production.js +125 -0
  596. package/lib/server-node/dist/production.js.map +1 -0
  597. package/lib/server-node/package.json +5 -0
  598. package/lib/server-node/src/hardening.ts +79 -0
  599. package/lib/server-node/src/index.ts +58 -0
  600. package/lib/server-node/src/probe.ts +36 -0
  601. package/lib/server-node/src/production.ts +116 -0
  602. package/lib/storage/dist/index.d.ts +4 -0
  603. package/lib/storage/dist/index.d.ts.map +1 -0
  604. package/lib/storage/dist/index.js +5 -0
  605. package/lib/storage/dist/index.js.map +1 -0
  606. package/lib/storage/package.json +5 -0
  607. package/lib/storage/src/index.ts +5 -0
  608. package/lib/storage-contracts/dist/contracts.d.ts +69 -0
  609. package/lib/storage-contracts/dist/contracts.d.ts.map +1 -0
  610. package/lib/storage-contracts/dist/contracts.js +15 -0
  611. package/lib/storage-contracts/dist/contracts.js.map +1 -0
  612. package/lib/storage-contracts/dist/durable-budget-contracts.d.ts +110 -0
  613. package/lib/storage-contracts/dist/durable-budget-contracts.d.ts.map +1 -0
  614. package/lib/storage-contracts/dist/durable-budget-contracts.js +430 -0
  615. package/lib/storage-contracts/dist/durable-budget-contracts.js.map +1 -0
  616. package/lib/storage-contracts/dist/execution-wait-contracts.d.ts +74 -0
  617. package/lib/storage-contracts/dist/execution-wait-contracts.d.ts.map +1 -0
  618. package/lib/storage-contracts/dist/execution-wait-contracts.js +159 -0
  619. package/lib/storage-contracts/dist/execution-wait-contracts.js.map +1 -0
  620. package/lib/storage-contracts/dist/index.d.ts +18 -0
  621. package/lib/storage-contracts/dist/index.d.ts.map +1 -0
  622. package/lib/storage-contracts/dist/index.js +18 -0
  623. package/lib/storage-contracts/dist/index.js.map +1 -0
  624. package/lib/storage-contracts/dist/memory-contracts.d.ts +208 -0
  625. package/lib/storage-contracts/dist/memory-contracts.d.ts.map +1 -0
  626. package/lib/storage-contracts/dist/memory-contracts.js +350 -0
  627. package/lib/storage-contracts/dist/memory-contracts.js.map +1 -0
  628. package/lib/storage-contracts/dist/scheduled-workflow-contracts.d.ts +171 -0
  629. package/lib/storage-contracts/dist/scheduled-workflow-contracts.d.ts.map +1 -0
  630. package/lib/storage-contracts/dist/scheduled-workflow-contracts.js +2 -0
  631. package/lib/storage-contracts/dist/scheduled-workflow-contracts.js.map +1 -0
  632. package/lib/storage-contracts/dist/scheduler-contracts.d.ts +133 -0
  633. package/lib/storage-contracts/dist/scheduler-contracts.d.ts.map +1 -0
  634. package/lib/storage-contracts/dist/scheduler-contracts.js +2 -0
  635. package/lib/storage-contracts/dist/scheduler-contracts.js.map +1 -0
  636. package/lib/storage-contracts/dist/submission-journal.d.ts +21 -0
  637. package/lib/storage-contracts/dist/submission-journal.d.ts.map +1 -0
  638. package/lib/storage-contracts/dist/submission-journal.js +51 -0
  639. package/lib/storage-contracts/dist/submission-journal.js.map +1 -0
  640. package/lib/storage-contracts/dist/workflow-format2.d.ts +54 -0
  641. package/lib/storage-contracts/dist/workflow-format2.d.ts.map +1 -0
  642. package/lib/storage-contracts/dist/workflow-format2.js +398 -0
  643. package/lib/storage-contracts/dist/workflow-format2.js.map +1 -0
  644. package/lib/storage-contracts/dist/workflow-format3.d.ts +20 -0
  645. package/lib/storage-contracts/dist/workflow-format3.d.ts.map +1 -0
  646. package/lib/storage-contracts/dist/workflow-format3.js +309 -0
  647. package/lib/storage-contracts/dist/workflow-format3.js.map +1 -0
  648. package/lib/storage-contracts/dist/workflow-format4.d.ts +48 -0
  649. package/lib/storage-contracts/dist/workflow-format4.d.ts.map +1 -0
  650. package/lib/storage-contracts/dist/workflow-format4.js +132 -0
  651. package/lib/storage-contracts/dist/workflow-format4.js.map +1 -0
  652. package/lib/storage-contracts/dist/workflow-format5.d.ts +94 -0
  653. package/lib/storage-contracts/dist/workflow-format5.d.ts.map +1 -0
  654. package/lib/storage-contracts/dist/workflow-format5.js +365 -0
  655. package/lib/storage-contracts/dist/workflow-format5.js.map +1 -0
  656. package/lib/storage-contracts/dist/workflow-graph-contracts.d.ts +69 -0
  657. package/lib/storage-contracts/dist/workflow-graph-contracts.d.ts.map +1 -0
  658. package/lib/storage-contracts/dist/workflow-graph-contracts.js +2 -0
  659. package/lib/storage-contracts/dist/workflow-graph-contracts.js.map +1 -0
  660. package/lib/storage-contracts/dist/workflow-graph-discovery.d.ts +45 -0
  661. package/lib/storage-contracts/dist/workflow-graph-discovery.d.ts.map +1 -0
  662. package/lib/storage-contracts/dist/workflow-graph-discovery.js +101 -0
  663. package/lib/storage-contracts/dist/workflow-graph-discovery.js.map +1 -0
  664. package/lib/storage-contracts/dist/workflow-loop-format1.d.ts +52 -0
  665. package/lib/storage-contracts/dist/workflow-loop-format1.d.ts.map +1 -0
  666. package/lib/storage-contracts/dist/workflow-loop-format1.js +134 -0
  667. package/lib/storage-contracts/dist/workflow-loop-format1.js.map +1 -0
  668. package/lib/storage-contracts/dist/workflow-saga-format1.d.ts +52 -0
  669. package/lib/storage-contracts/dist/workflow-saga-format1.d.ts.map +1 -0
  670. package/lib/storage-contracts/dist/workflow-saga-format1.js +235 -0
  671. package/lib/storage-contracts/dist/workflow-saga-format1.js.map +1 -0
  672. package/lib/storage-contracts/dist/workflow-tree-contracts.d.ts +428 -0
  673. package/lib/storage-contracts/dist/workflow-tree-contracts.d.ts.map +1 -0
  674. package/lib/storage-contracts/dist/workflow-tree-contracts.js +151 -0
  675. package/lib/storage-contracts/dist/workflow-tree-contracts.js.map +1 -0
  676. package/lib/storage-contracts/dist/workflow-tree-discovery.d.ts +38 -0
  677. package/lib/storage-contracts/dist/workflow-tree-discovery.d.ts.map +1 -0
  678. package/lib/storage-contracts/dist/workflow-tree-discovery.js +57 -0
  679. package/lib/storage-contracts/dist/workflow-tree-discovery.js.map +1 -0
  680. package/lib/storage-contracts/package.json +5 -0
  681. package/lib/storage-contracts/src/contracts.ts +73 -0
  682. package/lib/storage-contracts/src/durable-budget-contracts.ts +266 -0
  683. package/lib/storage-contracts/src/execution-wait-contracts.ts +169 -0
  684. package/lib/storage-contracts/src/index.ts +17 -0
  685. package/lib/storage-contracts/src/memory-contracts.ts +322 -0
  686. package/lib/storage-contracts/src/scheduled-workflow-contracts.ts +88 -0
  687. package/lib/storage-contracts/src/scheduler-contracts.ts +68 -0
  688. package/lib/storage-contracts/src/submission-journal.ts +50 -0
  689. package/lib/storage-contracts/src/workflow-format2.ts +288 -0
  690. package/lib/storage-contracts/src/workflow-format3.ts +201 -0
  691. package/lib/storage-contracts/src/workflow-format4.ts +96 -0
  692. package/lib/storage-contracts/src/workflow-format5.ts +375 -0
  693. package/lib/storage-contracts/src/workflow-graph-contracts.ts +44 -0
  694. package/lib/storage-contracts/src/workflow-graph-discovery.ts +107 -0
  695. package/lib/storage-contracts/src/workflow-loop-format1.ts +102 -0
  696. package/lib/storage-contracts/src/workflow-saga-format1.ts +165 -0
  697. package/lib/storage-contracts/src/workflow-tree-contracts.ts +191 -0
  698. package/lib/storage-contracts/src/workflow-tree-discovery.ts +39 -0
  699. package/lib/storage-postgres/dist/index.d.ts +2 -0
  700. package/lib/storage-postgres/dist/index.d.ts.map +1 -0
  701. package/lib/storage-postgres/dist/index.js +2 -0
  702. package/lib/storage-postgres/dist/index.js.map +1 -0
  703. package/lib/storage-postgres/dist/postgres.d.ts +8 -0
  704. package/lib/storage-postgres/dist/postgres.d.ts.map +1 -0
  705. package/lib/storage-postgres/dist/postgres.js +233 -0
  706. package/lib/storage-postgres/dist/postgres.js.map +1 -0
  707. package/lib/storage-postgres/package.json +5 -0
  708. package/lib/storage-postgres/src/index.ts +1 -0
  709. package/lib/storage-postgres/src/postgres.ts +222 -0
  710. package/lib/storage-sql/dist/aggregate-session.d.ts +31 -0
  711. package/lib/storage-sql/dist/aggregate-session.d.ts.map +1 -0
  712. package/lib/storage-sql/dist/aggregate-session.js +78 -0
  713. package/lib/storage-sql/dist/aggregate-session.js.map +1 -0
  714. package/lib/storage-sql/dist/contracts.d.ts +2 -0
  715. package/lib/storage-sql/dist/contracts.d.ts.map +1 -0
  716. package/lib/storage-sql/dist/contracts.js +3 -0
  717. package/lib/storage-sql/dist/contracts.js.map +1 -0
  718. package/lib/storage-sql/dist/durable-budget-database.d.ts +33 -0
  719. package/lib/storage-sql/dist/durable-budget-database.d.ts.map +1 -0
  720. package/lib/storage-sql/dist/durable-budget-database.js +191 -0
  721. package/lib/storage-sql/dist/durable-budget-database.js.map +1 -0
  722. package/lib/storage-sql/dist/durable-budget-state.d.ts +24 -0
  723. package/lib/storage-sql/dist/durable-budget-state.d.ts.map +1 -0
  724. package/lib/storage-sql/dist/durable-budget-state.js +211 -0
  725. package/lib/storage-sql/dist/durable-budget-state.js.map +1 -0
  726. package/lib/storage-sql/dist/durable-budget-validation.d.ts +5 -0
  727. package/lib/storage-sql/dist/durable-budget-validation.d.ts.map +1 -0
  728. package/lib/storage-sql/dist/durable-budget-validation.js +22 -0
  729. package/lib/storage-sql/dist/durable-budget-validation.js.map +1 -0
  730. package/lib/storage-sql/dist/execution-completions.d.ts +12 -0
  731. package/lib/storage-sql/dist/execution-completions.d.ts.map +1 -0
  732. package/lib/storage-sql/dist/execution-completions.js +60 -0
  733. package/lib/storage-sql/dist/execution-completions.js.map +1 -0
  734. package/lib/storage-sql/dist/execution-wait-database.d.ts +22 -0
  735. package/lib/storage-sql/dist/execution-wait-database.d.ts.map +1 -0
  736. package/lib/storage-sql/dist/execution-wait-database.js +288 -0
  737. package/lib/storage-sql/dist/execution-wait-database.js.map +1 -0
  738. package/lib/storage-sql/dist/execution-wait-validation.d.ts +8 -0
  739. package/lib/storage-sql/dist/execution-wait-validation.d.ts.map +1 -0
  740. package/lib/storage-sql/dist/execution-wait-validation.js +125 -0
  741. package/lib/storage-sql/dist/execution-wait-validation.js.map +1 -0
  742. package/lib/storage-sql/dist/host.d.ts +22 -0
  743. package/lib/storage-sql/dist/host.d.ts.map +1 -0
  744. package/lib/storage-sql/dist/host.js +21 -0
  745. package/lib/storage-sql/dist/host.js.map +1 -0
  746. package/lib/storage-sql/dist/memory-database.d.ts +24 -0
  747. package/lib/storage-sql/dist/memory-database.d.ts.map +1 -0
  748. package/lib/storage-sql/dist/memory-database.js +359 -0
  749. package/lib/storage-sql/dist/memory-database.js.map +1 -0
  750. package/lib/storage-sql/dist/scheduled-database.d.ts +74 -0
  751. package/lib/storage-sql/dist/scheduled-database.d.ts.map +1 -0
  752. package/lib/storage-sql/dist/scheduled-database.js +1152 -0
  753. package/lib/storage-sql/dist/scheduled-database.js.map +1 -0
  754. package/lib/storage-sql/dist/scheduled-validation.d.ts +9 -0
  755. package/lib/storage-sql/dist/scheduled-validation.d.ts.map +1 -0
  756. package/lib/storage-sql/dist/scheduled-validation.js +200 -0
  757. package/lib/storage-sql/dist/scheduled-validation.js.map +1 -0
  758. package/lib/storage-sql/dist/scheduler-contracts.d.ts +2 -0
  759. package/lib/storage-sql/dist/scheduler-contracts.d.ts.map +1 -0
  760. package/lib/storage-sql/dist/scheduler-contracts.js +3 -0
  761. package/lib/storage-sql/dist/scheduler-contracts.js.map +1 -0
  762. package/lib/storage-sql/dist/scheduler-database.d.ts +55 -0
  763. package/lib/storage-sql/dist/scheduler-database.d.ts.map +1 -0
  764. package/lib/storage-sql/dist/scheduler-database.js +655 -0
  765. package/lib/storage-sql/dist/scheduler-database.js.map +1 -0
  766. package/lib/storage-sql/dist/scheduler-validation.d.ts +22 -0
  767. package/lib/storage-sql/dist/scheduler-validation.d.ts.map +1 -0
  768. package/lib/storage-sql/dist/scheduler-validation.js +201 -0
  769. package/lib/storage-sql/dist/scheduler-validation.js.map +1 -0
  770. package/lib/storage-sql/dist/validation.d.ts +14 -0
  771. package/lib/storage-sql/dist/validation.d.ts.map +1 -0
  772. package/lib/storage-sql/dist/validation.js +106 -0
  773. package/lib/storage-sql/dist/validation.js.map +1 -0
  774. package/lib/storage-sql/dist/workflow-graph-discovery-index.d.ts +7 -0
  775. package/lib/storage-sql/dist/workflow-graph-discovery-index.d.ts.map +1 -0
  776. package/lib/storage-sql/dist/workflow-graph-discovery-index.js +55 -0
  777. package/lib/storage-sql/dist/workflow-graph-discovery-index.js.map +1 -0
  778. package/lib/storage-sql/dist/workflow-graph-discovery-validation.d.ts +5 -0
  779. package/lib/storage-sql/dist/workflow-graph-discovery-validation.d.ts.map +1 -0
  780. package/lib/storage-sql/dist/workflow-graph-discovery-validation.js +22 -0
  781. package/lib/storage-sql/dist/workflow-graph-discovery-validation.js.map +1 -0
  782. package/lib/storage-sql/dist/workflow-tree-database.d.ts +270 -0
  783. package/lib/storage-sql/dist/workflow-tree-database.d.ts.map +1 -0
  784. package/lib/storage-sql/dist/workflow-tree-database.js +1692 -0
  785. package/lib/storage-sql/dist/workflow-tree-database.js.map +1 -0
  786. package/lib/storage-sql/dist/workflow-tree-discovery-validation.d.ts +5 -0
  787. package/lib/storage-sql/dist/workflow-tree-discovery-validation.d.ts.map +1 -0
  788. package/lib/storage-sql/dist/workflow-tree-discovery-validation.js +15 -0
  789. package/lib/storage-sql/dist/workflow-tree-discovery-validation.js.map +1 -0
  790. package/lib/storage-sql/dist/workflow-tree-validation.d.ts +9 -0
  791. package/lib/storage-sql/dist/workflow-tree-validation.d.ts.map +1 -0
  792. package/lib/storage-sql/dist/workflow-tree-validation.js +576 -0
  793. package/lib/storage-sql/dist/workflow-tree-validation.js.map +1 -0
  794. package/lib/storage-sql/package.json +5 -0
  795. package/lib/storage-sql/src/aggregate-session.ts +72 -0
  796. package/lib/storage-sql/src/contracts.ts +2 -0
  797. package/lib/storage-sql/src/durable-budget-database.ts +180 -0
  798. package/lib/storage-sql/src/durable-budget-state.ts +155 -0
  799. package/lib/storage-sql/src/durable-budget-validation.ts +23 -0
  800. package/lib/storage-sql/src/execution-completions.ts +58 -0
  801. package/lib/storage-sql/src/execution-wait-database.ts +219 -0
  802. package/lib/storage-sql/src/execution-wait-validation.ts +108 -0
  803. package/lib/storage-sql/src/host.ts +21 -0
  804. package/lib/storage-sql/src/memory-database.ts +320 -0
  805. package/lib/storage-sql/src/scheduled-database.ts +811 -0
  806. package/lib/storage-sql/src/scheduled-validation.ts +89 -0
  807. package/lib/storage-sql/src/scheduler-contracts.ts +2 -0
  808. package/lib/storage-sql/src/scheduler-database.ts +475 -0
  809. package/lib/storage-sql/src/scheduler-validation.ts +112 -0
  810. package/lib/storage-sql/src/validation.ts +104 -0
  811. package/lib/storage-sql/src/workflow-graph-discovery-index.ts +60 -0
  812. package/lib/storage-sql/src/workflow-graph-discovery-validation.ts +21 -0
  813. package/lib/storage-sql/src/workflow-tree-database.ts +450 -0
  814. package/lib/storage-sql/src/workflow-tree-discovery-validation.ts +13 -0
  815. package/lib/storage-sql/src/workflow-tree-validation.ts +166 -0
  816. package/lib/storage-sqlite/dist/backup.d.ts +24 -0
  817. package/lib/storage-sqlite/dist/backup.d.ts.map +1 -0
  818. package/lib/storage-sqlite/dist/backup.js +84 -0
  819. package/lib/storage-sqlite/dist/backup.js.map +1 -0
  820. package/lib/storage-sqlite/dist/index.d.ts +4 -0
  821. package/lib/storage-sqlite/dist/index.d.ts.map +1 -0
  822. package/lib/storage-sqlite/dist/index.js +4 -0
  823. package/lib/storage-sqlite/dist/index.js.map +1 -0
  824. package/lib/storage-sqlite/dist/migrations.d.ts +6 -0
  825. package/lib/storage-sqlite/dist/migrations.d.ts.map +1 -0
  826. package/lib/storage-sqlite/dist/migrations.js +50 -0
  827. package/lib/storage-sqlite/dist/migrations.js.map +1 -0
  828. package/lib/storage-sqlite/dist/sqlite-database.d.ts +36 -0
  829. package/lib/storage-sqlite/dist/sqlite-database.d.ts.map +1 -0
  830. package/lib/storage-sqlite/dist/sqlite-database.js +179 -0
  831. package/lib/storage-sqlite/dist/sqlite-database.js.map +1 -0
  832. package/lib/storage-sqlite/dist/sqlite-worker.d.ts +2 -0
  833. package/lib/storage-sqlite/dist/sqlite-worker.d.ts.map +1 -0
  834. package/lib/storage-sqlite/dist/sqlite-worker.js +95 -0
  835. package/lib/storage-sqlite/dist/sqlite-worker.js.map +1 -0
  836. package/lib/storage-sqlite/dist/sqlite.d.ts +7 -0
  837. package/lib/storage-sqlite/dist/sqlite.d.ts.map +1 -0
  838. package/lib/storage-sqlite/dist/sqlite.js +78 -0
  839. package/lib/storage-sqlite/dist/sqlite.js.map +1 -0
  840. package/lib/storage-sqlite/package.json +5 -0
  841. package/lib/storage-sqlite/src/backup.ts +58 -0
  842. package/lib/storage-sqlite/src/index.ts +3 -0
  843. package/lib/storage-sqlite/src/migrations.ts +46 -0
  844. package/lib/storage-sqlite/src/sqlite-database.ts +172 -0
  845. package/lib/storage-sqlite/src/sqlite-worker.ts +52 -0
  846. package/lib/storage-sqlite/src/sqlite.ts +72 -0
  847. package/lib/testing/dist/index.d.ts +10 -0
  848. package/lib/testing/dist/index.d.ts.map +1 -0
  849. package/lib/testing/dist/index.js +24 -0
  850. package/lib/testing/dist/index.js.map +1 -0
  851. package/lib/testing/package.json +5 -0
  852. package/lib/testing/src/index.ts +26 -0
  853. package/lib/tools/dist/batch.d.ts +71 -0
  854. package/lib/tools/dist/batch.d.ts.map +1 -0
  855. package/lib/tools/dist/batch.js +542 -0
  856. package/lib/tools/dist/batch.js.map +1 -0
  857. package/lib/tools/dist/budget-binding.d.ts +18 -0
  858. package/lib/tools/dist/budget-binding.d.ts.map +1 -0
  859. package/lib/tools/dist/budget-binding.js +65 -0
  860. package/lib/tools/dist/budget-binding.js.map +1 -0
  861. package/lib/tools/dist/context.d.ts +17 -0
  862. package/lib/tools/dist/context.d.ts.map +1 -0
  863. package/lib/tools/dist/context.js +52 -0
  864. package/lib/tools/dist/context.js.map +1 -0
  865. package/lib/tools/dist/host.d.ts +3 -0
  866. package/lib/tools/dist/host.d.ts.map +1 -0
  867. package/lib/tools/dist/host.js +3 -0
  868. package/lib/tools/dist/host.js.map +1 -0
  869. package/lib/tools/dist/index.d.ts +79 -0
  870. package/lib/tools/dist/index.d.ts.map +1 -0
  871. package/lib/tools/dist/index.js +462 -0
  872. package/lib/tools/dist/index.js.map +1 -0
  873. package/lib/tools/package.json +5 -0
  874. package/lib/tools/src/batch.ts +496 -0
  875. package/lib/tools/src/budget-binding.ts +63 -0
  876. package/lib/tools/src/context.ts +56 -0
  877. package/lib/tools/src/host.ts +2 -0
  878. package/lib/tools/src/index.ts +479 -0
  879. package/lib/workflows/dist/agents.d.ts +24 -0
  880. package/lib/workflows/dist/agents.d.ts.map +1 -0
  881. package/lib/workflows/dist/agents.js +55 -0
  882. package/lib/workflows/dist/agents.js.map +1 -0
  883. package/lib/workflows/dist/children-coordinator.d.ts +58 -0
  884. package/lib/workflows/dist/children-coordinator.d.ts.map +1 -0
  885. package/lib/workflows/dist/children-coordinator.js +148 -0
  886. package/lib/workflows/dist/children-coordinator.js.map +1 -0
  887. package/lib/workflows/dist/children-definition.d.ts +43 -0
  888. package/lib/workflows/dist/children-definition.d.ts.map +1 -0
  889. package/lib/workflows/dist/children-definition.js +74 -0
  890. package/lib/workflows/dist/children-definition.js.map +1 -0
  891. package/lib/workflows/dist/children-discovery.d.ts +20 -0
  892. package/lib/workflows/dist/children-discovery.d.ts.map +1 -0
  893. package/lib/workflows/dist/children-discovery.js +103 -0
  894. package/lib/workflows/dist/children-discovery.js.map +1 -0
  895. package/lib/workflows/dist/children-runtime.d.ts +72 -0
  896. package/lib/workflows/dist/children-runtime.d.ts.map +1 -0
  897. package/lib/workflows/dist/children-runtime.js +600 -0
  898. package/lib/workflows/dist/children-runtime.js.map +1 -0
  899. package/lib/workflows/dist/children.d.ts +9 -0
  900. package/lib/workflows/dist/children.d.ts.map +1 -0
  901. package/lib/workflows/dist/children.js +6 -0
  902. package/lib/workflows/dist/children.js.map +1 -0
  903. package/lib/workflows/dist/composite-fleet.d.ts +87 -0
  904. package/lib/workflows/dist/composite-fleet.d.ts.map +1 -0
  905. package/lib/workflows/dist/composite-fleet.js +259 -0
  906. package/lib/workflows/dist/composite-fleet.js.map +1 -0
  907. package/lib/workflows/dist/composite-host.d.ts +45 -0
  908. package/lib/workflows/dist/composite-host.d.ts.map +1 -0
  909. package/lib/workflows/dist/composite-host.js +132 -0
  910. package/lib/workflows/dist/composite-host.js.map +1 -0
  911. package/lib/workflows/dist/composites.d.ts +4 -0
  912. package/lib/workflows/dist/composites.d.ts.map +1 -0
  913. package/lib/workflows/dist/composites.js +3 -0
  914. package/lib/workflows/dist/composites.js.map +1 -0
  915. package/lib/workflows/dist/definition.d.ts +61 -0
  916. package/lib/workflows/dist/definition.d.ts.map +1 -0
  917. package/lib/workflows/dist/definition.js +112 -0
  918. package/lib/workflows/dist/definition.js.map +1 -0
  919. package/lib/workflows/dist/drain.d.ts +21 -0
  920. package/lib/workflows/dist/drain.d.ts.map +1 -0
  921. package/lib/workflows/dist/drain.js +53 -0
  922. package/lib/workflows/dist/drain.js.map +1 -0
  923. package/lib/workflows/dist/ephemeral.d.ts +24 -0
  924. package/lib/workflows/dist/ephemeral.d.ts.map +1 -0
  925. package/lib/workflows/dist/ephemeral.js +122 -0
  926. package/lib/workflows/dist/ephemeral.js.map +1 -0
  927. package/lib/workflows/dist/fleet-control.d.ts +129 -0
  928. package/lib/workflows/dist/fleet-control.d.ts.map +1 -0
  929. package/lib/workflows/dist/fleet-control.js +356 -0
  930. package/lib/workflows/dist/fleet-control.js.map +1 -0
  931. package/lib/workflows/dist/graph-coordinator.d.ts +60 -0
  932. package/lib/workflows/dist/graph-coordinator.d.ts.map +1 -0
  933. package/lib/workflows/dist/graph-coordinator.js +266 -0
  934. package/lib/workflows/dist/graph-coordinator.js.map +1 -0
  935. package/lib/workflows/dist/graph-definition.d.ts +40 -0
  936. package/lib/workflows/dist/graph-definition.d.ts.map +1 -0
  937. package/lib/workflows/dist/graph-definition.js +58 -0
  938. package/lib/workflows/dist/graph-definition.js.map +1 -0
  939. package/lib/workflows/dist/graph-discovery.d.ts +27 -0
  940. package/lib/workflows/dist/graph-discovery.d.ts.map +1 -0
  941. package/lib/workflows/dist/graph-discovery.js +165 -0
  942. package/lib/workflows/dist/graph-discovery.js.map +1 -0
  943. package/lib/workflows/dist/graphs.d.ts +55 -0
  944. package/lib/workflows/dist/graphs.d.ts.map +1 -0
  945. package/lib/workflows/dist/graphs.js +10 -0
  946. package/lib/workflows/dist/graphs.js.map +1 -0
  947. package/lib/workflows/dist/hook-relay.d.ts +67 -0
  948. package/lib/workflows/dist/hook-relay.d.ts.map +1 -0
  949. package/lib/workflows/dist/hook-relay.js +157 -0
  950. package/lib/workflows/dist/hook-relay.js.map +1 -0
  951. package/lib/workflows/dist/index.d.ts +16 -0
  952. package/lib/workflows/dist/index.d.ts.map +1 -0
  953. package/lib/workflows/dist/index.js +15 -0
  954. package/lib/workflows/dist/index.js.map +1 -0
  955. package/lib/workflows/dist/leadership.d.ts +33 -0
  956. package/lib/workflows/dist/leadership.d.ts.map +1 -0
  957. package/lib/workflows/dist/leadership.js +109 -0
  958. package/lib/workflows/dist/leadership.js.map +1 -0
  959. package/lib/workflows/dist/lifecycle-definition.d.ts +89 -0
  960. package/lib/workflows/dist/lifecycle-definition.d.ts.map +1 -0
  961. package/lib/workflows/dist/lifecycle-definition.js +137 -0
  962. package/lib/workflows/dist/lifecycle-definition.js.map +1 -0
  963. package/lib/workflows/dist/lifecycle-fleet.d.ts +90 -0
  964. package/lib/workflows/dist/lifecycle-fleet.d.ts.map +1 -0
  965. package/lib/workflows/dist/lifecycle-fleet.js +406 -0
  966. package/lib/workflows/dist/lifecycle-fleet.js.map +1 -0
  967. package/lib/workflows/dist/lifecycle-host.d.ts +44 -0
  968. package/lib/workflows/dist/lifecycle-host.d.ts.map +1 -0
  969. package/lib/workflows/dist/lifecycle-host.js +133 -0
  970. package/lib/workflows/dist/lifecycle-host.js.map +1 -0
  971. package/lib/workflows/dist/lifecycle-human-transport.d.ts +67 -0
  972. package/lib/workflows/dist/lifecycle-human-transport.d.ts.map +1 -0
  973. package/lib/workflows/dist/lifecycle-human-transport.js +149 -0
  974. package/lib/workflows/dist/lifecycle-human-transport.js.map +1 -0
  975. package/lib/workflows/dist/lifecycle-runtime.d.ts +115 -0
  976. package/lib/workflows/dist/lifecycle-runtime.d.ts.map +1 -0
  977. package/lib/workflows/dist/lifecycle-runtime.js +831 -0
  978. package/lib/workflows/dist/lifecycle-runtime.js.map +1 -0
  979. package/lib/workflows/dist/lifecycle.d.ts +10 -0
  980. package/lib/workflows/dist/lifecycle.d.ts.map +1 -0
  981. package/lib/workflows/dist/lifecycle.js +7 -0
  982. package/lib/workflows/dist/lifecycle.js.map +1 -0
  983. package/lib/workflows/dist/loop-definition.d.ts +46 -0
  984. package/lib/workflows/dist/loop-definition.d.ts.map +1 -0
  985. package/lib/workflows/dist/loop-definition.js +55 -0
  986. package/lib/workflows/dist/loop-definition.js.map +1 -0
  987. package/lib/workflows/dist/loop-runtime.d.ts +47 -0
  988. package/lib/workflows/dist/loop-runtime.d.ts.map +1 -0
  989. package/lib/workflows/dist/loop-runtime.js +358 -0
  990. package/lib/workflows/dist/loop-runtime.js.map +1 -0
  991. package/lib/workflows/dist/loops.d.ts +6 -0
  992. package/lib/workflows/dist/loops.d.ts.map +1 -0
  993. package/lib/workflows/dist/loops.js +4 -0
  994. package/lib/workflows/dist/loops.js.map +1 -0
  995. package/lib/workflows/dist/migration-service.d.ts +55 -0
  996. package/lib/workflows/dist/migration-service.d.ts.map +1 -0
  997. package/lib/workflows/dist/migration-service.js +73 -0
  998. package/lib/workflows/dist/migration-service.js.map +1 -0
  999. package/lib/workflows/dist/migration.d.ts +123 -0
  1000. package/lib/workflows/dist/migration.d.ts.map +1 -0
  1001. package/lib/workflows/dist/migration.js +217 -0
  1002. package/lib/workflows/dist/migration.js.map +1 -0
  1003. package/lib/workflows/dist/operator-transports.d.ts +265 -0
  1004. package/lib/workflows/dist/operator-transports.d.ts.map +1 -0
  1005. package/lib/workflows/dist/operator-transports.js +404 -0
  1006. package/lib/workflows/dist/operator-transports.js.map +1 -0
  1007. package/lib/workflows/dist/reconciliation.d.ts +25 -0
  1008. package/lib/workflows/dist/reconciliation.d.ts.map +1 -0
  1009. package/lib/workflows/dist/reconciliation.js +109 -0
  1010. package/lib/workflows/dist/reconciliation.js.map +1 -0
  1011. package/lib/workflows/dist/runtime.d.ts +65 -0
  1012. package/lib/workflows/dist/runtime.d.ts.map +1 -0
  1013. package/lib/workflows/dist/runtime.js +492 -0
  1014. package/lib/workflows/dist/runtime.js.map +1 -0
  1015. package/lib/workflows/dist/saga-definition.d.ts +46 -0
  1016. package/lib/workflows/dist/saga-definition.d.ts.map +1 -0
  1017. package/lib/workflows/dist/saga-definition.js +71 -0
  1018. package/lib/workflows/dist/saga-definition.js.map +1 -0
  1019. package/lib/workflows/dist/saga-runtime.d.ts +51 -0
  1020. package/lib/workflows/dist/saga-runtime.d.ts.map +1 -0
  1021. package/lib/workflows/dist/saga-runtime.js +499 -0
  1022. package/lib/workflows/dist/saga-runtime.js.map +1 -0
  1023. package/lib/workflows/dist/sagas.d.ts +6 -0
  1024. package/lib/workflows/dist/sagas.d.ts.map +1 -0
  1025. package/lib/workflows/dist/sagas.js +4 -0
  1026. package/lib/workflows/dist/sagas.js.map +1 -0
  1027. package/lib/workflows/dist/scheduled-helpers.d.ts +53 -0
  1028. package/lib/workflows/dist/scheduled-helpers.d.ts.map +1 -0
  1029. package/lib/workflows/dist/scheduled-helpers.js +230 -0
  1030. package/lib/workflows/dist/scheduled-helpers.js.map +1 -0
  1031. package/lib/workflows/dist/scheduled.d.ts +116 -0
  1032. package/lib/workflows/dist/scheduled.d.ts.map +1 -0
  1033. package/lib/workflows/dist/scheduled.js +781 -0
  1034. package/lib/workflows/dist/scheduled.js.map +1 -0
  1035. package/lib/workflows/dist/traces.d.ts +158 -0
  1036. package/lib/workflows/dist/traces.d.ts.map +1 -0
  1037. package/lib/workflows/dist/traces.js +366 -0
  1038. package/lib/workflows/dist/traces.js.map +1 -0
  1039. package/lib/workflows/dist/versions.d.ts +57 -0
  1040. package/lib/workflows/dist/versions.d.ts.map +1 -0
  1041. package/lib/workflows/dist/versions.js +87 -0
  1042. package/lib/workflows/dist/versions.js.map +1 -0
  1043. package/lib/workflows/dist/worker.d.ts +51 -0
  1044. package/lib/workflows/dist/worker.d.ts.map +1 -0
  1045. package/lib/workflows/dist/worker.js +143 -0
  1046. package/lib/workflows/dist/worker.js.map +1 -0
  1047. package/lib/workflows/package.json +5 -0
  1048. package/lib/workflows/src/agents.ts +65 -0
  1049. package/lib/workflows/src/children-coordinator.ts +50 -0
  1050. package/lib/workflows/src/children-definition.ts +88 -0
  1051. package/lib/workflows/src/children-discovery.ts +32 -0
  1052. package/lib/workflows/src/children-runtime.ts +169 -0
  1053. package/lib/workflows/src/children.ts +12 -0
  1054. package/lib/workflows/src/composite-fleet.ts +155 -0
  1055. package/lib/workflows/src/composite-host.ts +67 -0
  1056. package/lib/workflows/src/composites.ts +6 -0
  1057. package/lib/workflows/src/definition.ts +113 -0
  1058. package/lib/workflows/src/drain.ts +56 -0
  1059. package/lib/workflows/src/ephemeral.ts +124 -0
  1060. package/lib/workflows/src/fleet-control.ts +326 -0
  1061. package/lib/workflows/src/graph-coordinator.ts +223 -0
  1062. package/lib/workflows/src/graph-definition.ts +70 -0
  1063. package/lib/workflows/src/graph-discovery.ts +145 -0
  1064. package/lib/workflows/src/graphs.ts +56 -0
  1065. package/lib/workflows/src/hook-relay.ts +177 -0
  1066. package/lib/workflows/src/index.ts +27 -0
  1067. package/lib/workflows/src/leadership.ts +102 -0
  1068. package/lib/workflows/src/lifecycle-definition.ts +194 -0
  1069. package/lib/workflows/src/lifecycle-fleet.ts +346 -0
  1070. package/lib/workflows/src/lifecycle-host.ts +109 -0
  1071. package/lib/workflows/src/lifecycle-human-transport.ts +170 -0
  1072. package/lib/workflows/src/lifecycle-runtime.ts +673 -0
  1073. package/lib/workflows/src/lifecycle.ts +59 -0
  1074. package/lib/workflows/src/loop-definition.ts +62 -0
  1075. package/lib/workflows/src/loop-runtime.ts +260 -0
  1076. package/lib/workflows/src/loops.ts +7 -0
  1077. package/lib/workflows/src/migration-service.ts +83 -0
  1078. package/lib/workflows/src/migration.ts +242 -0
  1079. package/lib/workflows/src/operator-transports.ts +439 -0
  1080. package/lib/workflows/src/reconciliation.ts +121 -0
  1081. package/lib/workflows/src/runtime.ts +348 -0
  1082. package/lib/workflows/src/saga-definition.ts +104 -0
  1083. package/lib/workflows/src/saga-runtime.ts +406 -0
  1084. package/lib/workflows/src/sagas.ts +24 -0
  1085. package/lib/workflows/src/scheduled-helpers.ts +214 -0
  1086. package/lib/workflows/src/scheduled.ts +707 -0
  1087. package/lib/workflows/src/traces.ts +381 -0
  1088. package/lib/workflows/src/versions.ts +114 -0
  1089. package/lib/workflows/src/worker.ts +115 -0
  1090. package/lib/workstream/dist/executions.d.ts +34 -0
  1091. package/lib/workstream/dist/executions.d.ts.map +1 -0
  1092. package/lib/workstream/dist/executions.js +344 -0
  1093. package/lib/workstream/dist/executions.js.map +1 -0
  1094. package/lib/workstream/dist/humans.d.ts +76 -0
  1095. package/lib/workstream/dist/humans.d.ts.map +1 -0
  1096. package/lib/workstream/dist/humans.js +273 -0
  1097. package/lib/workstream/dist/humans.js.map +1 -0
  1098. package/lib/workstream/dist/index.d.ts +61 -0
  1099. package/lib/workstream/dist/index.d.ts.map +1 -0
  1100. package/lib/workstream/dist/index.js +310 -0
  1101. package/lib/workstream/dist/index.js.map +1 -0
  1102. package/lib/workstream/dist/timers.d.ts +41 -0
  1103. package/lib/workstream/dist/timers.d.ts.map +1 -0
  1104. package/lib/workstream/dist/timers.js +240 -0
  1105. package/lib/workstream/dist/timers.js.map +1 -0
  1106. package/lib/workstream/dist/webhooks.d.ts +69 -0
  1107. package/lib/workstream/dist/webhooks.d.ts.map +1 -0
  1108. package/lib/workstream/dist/webhooks.js +313 -0
  1109. package/lib/workstream/dist/webhooks.js.map +1 -0
  1110. package/lib/workstream/package.json +5 -0
  1111. package/lib/workstream/src/executions.ts +253 -0
  1112. package/lib/workstream/src/humans.ts +323 -0
  1113. package/lib/workstream/src/index.ts +279 -0
  1114. package/lib/workstream/src/timers.ts +212 -0
  1115. package/lib/workstream/src/webhooks.ts +180 -0
  1116. package/package.json +281 -0
@@ -0,0 +1,909 @@
1
+ import {
2
+ assertPositiveInteger, Budget, freezeJson, jsonValue, MayuraError, publicError, validate,
3
+ type BudgetTicket, type BudgetBundle, type Reservation, type ManagedGuardDefinition, type ExecutionEvidence, type ExecutionReceipt, type Guard, type InferInput, type InferOutput, type JsonValue, type ModelMessage, type ModelRequest,
4
+ type Outcome, type Permissions, type RunHandle, type Schema, type Scope,
5
+ } from '@mayura/core';
6
+ import { readManagedGuardDefinition } from '@mayura/core/host';
7
+ import { invokeTool, type AnyTool } from '@mayura/tools';
8
+ import { bindToolBudgetTicket } from '@mayura/tools/host';
9
+ import { assertAgent, isIdentifier, type AgentDefinition, type AgentGuard } from './agent.js';
10
+ import { EventBuffer } from './event-buffer.js';
11
+ import { modelCost, modelFailureCost, modelResponse } from './response.js';
12
+ import { createBatcher, createFieldExtractor } from './stream.js';
13
+ import { childGateway, isAgentTool, type ChildOptions } from './composition.js';
14
+ import { OperationPermits } from './permits.js';
15
+ import { evaluateManagedGuard } from './managed-guards.js';
16
+ import { readHookDefinition, type ControlHookStage, type HookEvent, type HookEvents, type TerminalHookStage } from './hooks.js';
17
+ import { evaluateHook, evaluateObserver } from './hook-execution.js';
18
+
19
+ /** All bounds are finite; model/token/cost declarations do not turn trusted callbacks into a sandbox. */
20
+ export interface RuntimeLimits {
21
+ readonly maxSteps?: number;
22
+ readonly maxModelCalls?: number;
23
+ readonly maxToolCalls?: number;
24
+ /** Actual required lifecycle callback admissions, separate from model/tool charges. */
25
+ readonly maxHookCalls?: number;
26
+ readonly maxDurationMs?: number;
27
+ readonly maxInputBytes?: number;
28
+ readonly maxOutputBytes?: number;
29
+ readonly maxContextBytes?: number;
30
+ readonly maxOutputTokens?: number;
31
+ readonly maxCostMicros?: number;
32
+ readonly maxEventRetention?: number;
33
+ /** Concurrent root admissions; descendants have separate bounded capacity. */
34
+ readonly maxConcurrentRuns?: number;
35
+ readonly maxDescendantRuns?: number;
36
+ readonly maxDepth?: number;
37
+ readonly maxConcurrentOperations?: number;
38
+ }
39
+ export interface SpeculationBranch<I extends Schema, O extends Schema> {
40
+ readonly id: string;
41
+ readonly agent: AgentDefinition<I, O>;
42
+ readonly input: InferInput<I>;
43
+ readonly permissions: Permissions;
44
+ readonly limits?: RuntimeLimits;
45
+ /** The assumptions this branch depends on; their digest is recorded and passed to `verify`. */
46
+ readonly assumptions: JsonValue;
47
+ }
48
+ export interface SpeculationOptions<I extends Schema, O extends Schema> {
49
+ /** 1–8 branches with unique ids. */
50
+ readonly branches: readonly SpeculationBranch<I, O>[];
51
+ /** Re-check current inputs, scope and policy before promotion. Only an exact `true` promotes; errors and timeouts do not. */
52
+ readonly verify: (candidate: { readonly branchId: string; readonly assumptionsDigest: string; readonly output: InferOutput<O> }) => boolean | Promise<boolean>;
53
+ /** Deadline for each `verify` call (default 5000 ms, maximum 30000). */
54
+ readonly verifyTimeoutMs?: number;
55
+ }
56
+ export interface SpeculationResult<T> {
57
+ readonly status: 'promoted' | 'none';
58
+ readonly branchId?: string;
59
+ readonly output?: T;
60
+ readonly assumptionsDigest?: string;
61
+ readonly branches: readonly { readonly id: string; readonly runId: string; readonly status: Outcome<unknown>['status']; readonly assumptionsDigest: string; readonly verified: boolean }[];
62
+ }
63
+
64
+ export interface RuntimeOptions {
65
+ readonly profile: 'ephemeral';
66
+ readonly permissions?: Permissions;
67
+ readonly scope?: Scope;
68
+ readonly limits?: RuntimeLimits;
69
+ }
70
+ export interface Runtime {
71
+ readonly profile: 'ephemeral';
72
+ submit<I extends Schema, O extends Schema>(agent: AgentDefinition<I, O>, options: { readonly input: InferInput<I> }): RunHandle<InferOutput<O>>;
73
+ spawn<I extends Schema, O extends Schema>(parent: RunHandle<unknown>, agent: AgentDefinition<I, O>, options: ChildOptions & { readonly input: InferInput<I> }): RunHandle<InferOutput<O>>;
74
+ inspect(handle: RunHandle<unknown>): RunInspection;
75
+ /**
76
+ * Run isolated speculative child branches under the parent's shared budget and promote at most one. Branches may
77
+ * not hold write, host, delegation or memory-mutation grants; losing and unverified branches are cancelled.
78
+ */
79
+ speculate<I extends Schema, O extends Schema>(parent: RunHandle<unknown>, options: SpeculationOptions<I, O>): Promise<SpeculationResult<InferOutput<O>>>;
80
+ /** Stop admissions, request cancellation, and wait for accepted runs to reach a terminal outcome. */
81
+ close(): Promise<void>;
82
+ }
83
+
84
+ const defaults: Required<RuntimeLimits> = Object.freeze({
85
+ maxSteps: 16, maxModelCalls: 16, maxToolCalls: 64, maxHookCalls: 128, maxDurationMs: 60_000,
86
+ maxInputBytes: 1_048_576, maxOutputBytes: 1_048_576, maxContextBytes: 2_097_152,
87
+ maxOutputTokens: 4_096, maxCostMicros: 0, maxEventRetention: 256, maxConcurrentRuns: 32,
88
+ maxDescendantRuns: 64, maxDepth: 8, maxConcurrentOperations: 32,
89
+ });
90
+
91
+ function limitsFor(options: RuntimeLimits | undefined): Required<RuntimeLimits> {
92
+ const result = { ...defaults, ...options };
93
+ if (Object.keys(result).some((key) => !(key in defaults))) throw new MayuraError('INVALID_CONFIG', 'Unknown runtime limit.');
94
+ for (const [key, value] of Object.entries(result)) {
95
+ // Zero is meaningful for cost and tool calls (an agent with no tools makes none); every other limit is positive.
96
+ if (key === 'maxCostMicros' || key === 'maxToolCalls') {
97
+ if (!Number.isSafeInteger(value) || value < 0) throw new MayuraError('INVALID_CONFIG', `${key} must be a non-negative safe integer.`);
98
+ } else assertPositiveInteger(value, key);
99
+ }
100
+ if (result.maxDurationMs > 2_147_483_647 || !Number.isSafeInteger(result.maxModelCalls + result.maxToolCalls)) {
101
+ throw new MayuraError('INVALID_CONFIG', 'Runtime limits exceed the supported counter or timer range.');
102
+ }
103
+ if (result.maxDepth > 32 || result.maxDescendantRuns > 1023 || result.maxConcurrentOperations > 1024
104
+ || result.maxConcurrentRuns > 1024 || result.maxModelCalls > 4096 || result.maxToolCalls > 4096 || result.maxHookCalls > 4096) {
105
+ throw new MayuraError('INVALID_CONFIG', 'Runtime tree or operation limits exceed supported bounds.');
106
+ }
107
+ return Object.freeze(result);
108
+ }
109
+
110
+ /** Race cooperative async work against cancellation; retained rejection handlers prevent late unhandled failures. */
111
+ async function cancellable<T>(operation: () => PromiseLike<T> | T, signal: AbortSignal): Promise<T> {
112
+ if (signal.aborted) throw signal.reason;
113
+ return await new Promise<T>((resolve, reject) => {
114
+ const abort = (): void => { cleanup(); reject(signal.reason); };
115
+ const cleanup = (): void => { signal.removeEventListener('abort', abort); };
116
+ signal.addEventListener('abort', abort, { once: true });
117
+ Promise.resolve().then(() => {
118
+ if (signal.aborted) throw signal.reason;
119
+ return operation();
120
+ }).then((value) => { cleanup(); resolve(value); }, (error: unknown) => { cleanup(); reject(error); });
121
+ if (signal.aborted) abort();
122
+ });
123
+ }
124
+
125
+ function outcomeFor(error: unknown): Outcome<never> {
126
+ const safe = publicError(error, 'MODEL_FAILED');
127
+ const status = safe.code === 'CANCELLED' ? 'cancelled'
128
+ : ['PERMISSION_DENIED', 'BUDGET_EXCEEDED', 'GUARD_BLOCKED', 'GUARD_UNAVAILABLE'].includes(safe.code) ? 'blocked'
129
+ : 'failed';
130
+ return Object.freeze({ status, error: Object.freeze(safe) });
131
+ }
132
+
133
+
134
+ export interface RunInspection {
135
+ readonly id: string;
136
+ readonly rootId: string;
137
+ readonly parentId?: string;
138
+ readonly agentId: string;
139
+ readonly status: 'running' | Outcome<unknown>['status'];
140
+ readonly budget: ReturnType<Budget['snapshot']>;
141
+ readonly runs: readonly { readonly id: string; readonly parentId?: string; readonly agentId: string; readonly status: 'running' | Outcome<unknown>['status'] }[];
142
+ readonly evidence: readonly ExecutionEvidence[];
143
+ }
144
+ type Failure = Exclude<Outcome<never>, { readonly status: 'succeeded' }>;
145
+ interface ObserveOptions { readonly signal?: AbortSignal; readonly terminal?: boolean }
146
+ interface RunState {
147
+ readonly id: string;
148
+ readonly events: EventBuffer;
149
+ /** This run's awaited control hooks; also used by children for beforeDelegate. */
150
+ control(event: HookEvent, step: number | null, signal?: AbortSignal): Promise<Failure | undefined>;
151
+ /** This run's observers; a mandatory failure is returned, never thrown. Also used by children for afterDelegate. */
152
+ observe(event: HookEvent, step: number | null, options?: ObserveOptions): Promise<Failure | undefined>;
153
+ readonly agent: AgentDefinition;
154
+ readonly parent: RunState | undefined;
155
+ readonly root: RunState;
156
+ readonly depth: number;
157
+ readonly deadline: number;
158
+ readonly limits: Required<RuntimeLimits>;
159
+ readonly permissions: Permissions;
160
+ readonly budget: Budget;
161
+ readonly operations: OperationPermits;
162
+ readonly controller: AbortController;
163
+ readonly handle: RunHandle<unknown>;
164
+ readonly children: RunState[];
165
+ /** A speculative branch: awaited by its parent, but its failure or cancellation never becomes the parent's outcome. */
166
+ readonly speculative: boolean;
167
+ readonly receipts: Map<string, ExecutionReceipt>;
168
+ accepting: boolean;
169
+ status: 'running' | Outcome<unknown>['status'];
170
+ descendants: number;
171
+ modelCalls: number;
172
+ toolCalls: number;
173
+ hookCalls: number;
174
+ heldModelCalls: number;
175
+ heldToolCalls: number;
176
+ readonly bundles: Set<CallBundle>;
177
+ }
178
+ function permissionsFor(supplied: Permissions | undefined, required = false): Permissions {
179
+ const allow = supplied?.allow ?? (required ? undefined : []);
180
+ if (!Array.isArray(allow) || allow.length > 4096 || allow.some((grant) => typeof grant !== 'string' || grant.length === 0 || grant.length > 256)) {
181
+ throw new MayuraError('INVALID_CONFIG', 'Permissions must be an explicit list of bounded capability names.');
182
+ }
183
+ return Object.freeze({ allow: Object.freeze([...new Set(allow)]) });
184
+ }
185
+ function ancestors(state: RunState): RunState[] {
186
+ const path: RunState[] = [];
187
+ for (let current: RunState | undefined = state; current; current = current.parent) path.push(current);
188
+ return path;
189
+ }
190
+ function subtree(state: RunState): RunState[] { return [state, ...state.children.flatMap(subtree)]; }
191
+ function evidenceFor(state: RunState): readonly ExecutionEvidence[] {
192
+ return Object.freeze(subtree(state).flatMap((run) => [...run.receipts.values()].map((receipt) => Object.freeze({ runId: run.id, receipt }))));
193
+ }
194
+ /** Preserve known late evidence when a stale cancellation snapshot still says unknown. */
195
+ function record(state: RunState, receipt: ExecutionReceipt): void {
196
+ const old = state.receipts.get(receipt.callId);
197
+ const execution = old && ['succeeded', 'failed'].includes(old.execution) && !['succeeded', 'failed'].includes(receipt.execution)
198
+ ? old.execution : receipt.execution;
199
+ state.receipts.set(receipt.callId, Object.freeze({ ...receipt, execution }));
200
+ }
201
+ function checkCalls(state: RunState, kind: 'model' | 'tool', count: number): void {
202
+ for (const current of ancestors(state)) {
203
+ const remaining = kind === 'model' ? current.limits.maxModelCalls - current.modelCalls - current.heldModelCalls
204
+ : current.limits.maxToolCalls - current.toolCalls - current.heldToolCalls;
205
+ if (count > remaining) throw new MayuraError('LIMIT_EXCEEDED', 'An ancestor execution-call limit was reached.');
206
+ }
207
+ }
208
+ interface CallTicket { readonly ticket: BudgetTicket; readonly kind: 'model' | 'tool'; counted: boolean; cancelled: boolean }
209
+ interface CallBundle { readonly entries: readonly CallTicket[]; close(): void }
210
+
211
+ /** Internal atomic projection: only freshly-created primitive records reach the core commit. */
212
+ function reserveCalls(state: RunState, operations: readonly { readonly kind: 'model' | 'tool'; readonly maxCostMicros: number }[]): CallBundle {
213
+ const path = ancestors(state);
214
+ const modelCount = operations.filter(operation => operation.kind === 'model').length;
215
+ const toolCount = operations.length - modelCount;
216
+ checkCalls(state, 'model', modelCount); checkCalls(state, 'tool', toolCount);
217
+ const bundleId = crypto.randomUUID();
218
+ const bundle: BudgetBundle = state.budget.reserveBundle(operations.map((operation, index) => ({ id: `${state.id}/${bundleId}/${index}`, maxCostMicros: operation.maxCostMicros })));
219
+ // No application callback, await, hook or logger occurs between the two ledger projections.
220
+ for (const account of path) { account.heldModelCalls += modelCount; account.heldToolCalls += toolCount; }
221
+ const entries = operations.map((operation, index): CallTicket => ({ ticket: bundle.tickets[index]!, kind: operation.kind, counted: false, cancelled: false }));
222
+ let closed = false;
223
+ const result: CallBundle = { entries, close: () => {
224
+ if (closed) return;
225
+ bundle.close();
226
+ for (const entry of entries) if (!entry.counted) {
227
+ for (const account of path) { if (entry.kind === 'model') account.heldModelCalls--; else account.heldToolCalls--; }
228
+ entry.cancelled = true;
229
+ }
230
+ closed = true; state.bundles.delete(result);
231
+ } };
232
+ state.bundles.add(result); return result;
233
+ }
234
+
235
+ /** Only runtime-owned records reach this transition; model dispatch and tool attempts differ deliberately. */
236
+ function consumeCall(state: RunState, entry: CallTicket, kind: 'model'): Reservation;
237
+ function consumeCall(state: RunState, entry: CallTicket, kind: 'tool'): void;
238
+ function consumeCall(state: RunState, entry: CallTicket, kind: 'model' | 'tool'): Reservation | void {
239
+ if (entry.kind !== kind || entry.counted || entry.cancelled) throw new MayuraError('CONFLICT', 'The runtime invocation was already consumed, cancelled or has the wrong kind.');
240
+ const reservation = kind === 'model' ? entry.ticket.start() : undefined;
241
+ for (const account of ancestors(state)) {
242
+ if (kind === 'model') { account.heldModelCalls--; account.modelCalls++; }
243
+ else { account.heldToolCalls--; account.toolCalls++; }
244
+ }
245
+ entry.counted = true; return reservation;
246
+ }
247
+
248
+ const violationBoundary: Record<ControlHookStage, HookEvents['onViolation']['boundary']> = {
249
+ beforeExecution: 'execution', beforeStep: 'execution', beforeModelCall: 'model', beforeToolCall: 'tool', beforeDelegate: 'delegate', beforeOutputRelease: 'output',
250
+ };
251
+ function canonicalJson(value: JsonValue): string {
252
+ if (value === null || typeof value !== 'object') return JSON.stringify(value);
253
+ if (Array.isArray(value)) return `[${value.map(canonicalJson).join(',')}]`;
254
+ return `{${Object.keys(value).sort().map(key => `${JSON.stringify(key)}:${canonicalJson(value[key]!)}`).join(',')}}`;
255
+ }
256
+ function terminalView(stage: TerminalHookStage, outcome: Outcome<unknown>): HookEvent<TerminalHookStage> {
257
+ return Object.freeze({ stage, status: outcome.status, ...(outcome.status === 'succeeded' ? {} : { error: Object.freeze({ code: outcome.error.code }) }) });
258
+ }
259
+
260
+ /** Process-local structured concurrency. No restart recovery or hard callback isolation is promised. */
261
+ export function createRuntime(options: RuntimeOptions): Runtime {
262
+ if (options.profile !== 'ephemeral') throw new MayuraError('UNSUPPORTED_PROFILE', 'Only the explicit ephemeral profile is supported by this runtime.');
263
+ const rootLimits = limitsFor(options.limits);
264
+ const rootPermissions = permissionsFor(options.permissions);
265
+ const suppliedScope = options.scope ?? { principalId: 'local', projectId: 'default' };
266
+ if (!isIdentifier(suppliedScope.principalId) || !isIdentifier(suppliedScope.projectId)) {
267
+ throw new MayuraError('INVALID_CONFIG', 'Scope requires bounded principal and project identifiers.');
268
+ }
269
+ const scope: Scope = Object.freeze({ principalId: suppliedScope.principalId, projectId: suppliedScope.projectId });
270
+ const active = new Map<string, RunHandle<unknown>>();
271
+ const states = new WeakMap<object, RunState>();
272
+ const operations = new OperationPermits(rootLimits.maxConcurrentOperations, Math.min(65536, rootLimits.maxConcurrentRuns * (rootLimits.maxDescendantRuns + 1)));
273
+ let activeRoots = 0;
274
+ let closed = false;
275
+ const lookup = (handle: RunHandle<unknown>): RunState => {
276
+ const state = states.get(handle);
277
+ if (!state) throw new MayuraError('PERMISSION_DENIED', 'A genuine handle from this runtime is required.');
278
+ return state;
279
+ };
280
+ const admitChild = <I extends Schema, O extends Schema>(
281
+ parent: RunState, agent: AgentDefinition<I, O>, input: unknown, child: ChildOptions, inputAdmitted = false, signal?: AbortSignal, speculative = false,
282
+ ): RunHandle<InferOutput<O>> => {
283
+ if (Date.now() >= parent.deadline && !parent.controller.signal.aborted) parent.controller.abort(new MayuraError('TIMEOUT', 'The parent deadline elapsed.'));
284
+ if (closed || !parent.accepting || parent.status !== 'running' || parent.controller.signal.aborted || signal?.aborted) {
285
+ throw new MayuraError('CONFLICT', 'The parent no longer accepts child execution.');
286
+ }
287
+ assertAgent(agent);
288
+ if (!parent.permissions.allow.includes('agent:delegate')) throw new MayuraError('PERMISSION_DENIED', 'Child delegation is not authorized.');
289
+ const path = ancestors(parent);
290
+ if (path.some((item) => item.agent === agent || item.agent.id === agent.id)) throw new MayuraError('CONFLICT', 'Recursive agent ancestry is not supported.');
291
+ if (path.some((item) => item.descendants >= item.limits.maxDescendantRuns) || parent.depth + 1 > parent.limits.maxDepth) {
292
+ throw new MayuraError('LIMIT_EXCEEDED', 'The descendant or depth limit was reached.');
293
+ }
294
+ const limits = limitsFor({ ...parent.limits, ...child.limits });
295
+ if (limits.maxConcurrentRuns !== parent.limits.maxConcurrentRuns) throw new MayuraError('INVALID_CONFIG', 'maxConcurrentRuns controls root admission only.');
296
+ if (parent.depth + 1 > limits.maxDepth) throw new MayuraError('LIMIT_EXCEEDED', 'The child depth ceiling was reached.');
297
+ if (Object.entries(limits).some(([key, value]) => value > parent.limits[key as keyof RuntimeLimits])) {
298
+ throw new MayuraError('INVALID_CONFIG', 'Child limits cannot exceed parent ceilings.');
299
+ }
300
+ const requested = permissionsFor(child.permissions, true);
301
+ const permissions = permissionsFor({ allow: requested.allow.filter((grant) => parent.permissions.allow.includes(grant)) });
302
+ return start(agent, input, limits, permissions, parent, inputAdmitted, signal, speculative);
303
+ };
304
+
305
+ const start = <I extends Schema, O extends Schema>(
306
+ agent: AgentDefinition<I, O>, suppliedInput: unknown, limits: Required<RuntimeLimits>, permissions: Permissions,
307
+ parent?: RunState, inputAdmitted = false, externalSignal?: AbortSignal, speculative = false,
308
+ ): RunHandle<InferOutput<O>> => {
309
+ if (closed) throw new MayuraError('CONFLICT', 'Runtime is closed and cannot accept new runs.');
310
+ assertAgent(agent);
311
+ if (!parent && activeRoots >= rootLimits.maxConcurrentRuns) throw new MayuraError('LIMIT_EXCEEDED', 'The runtime concurrent-root limit is reached.');
312
+ let input: JsonValue;
313
+ try { input = freezeJson(jsonValue(suppliedInput, { maxBytes: limits.maxInputBytes })); }
314
+ catch { throw new MayuraError('INVALID_INPUT', 'Submitted input must satisfy the JSON and size limits.'); }
315
+ const id = crypto.randomUUID();
316
+ const controller = new AbortController();
317
+ const events = new EventBuffer(id, limits.maxEventRetention);
318
+ const budget = parent ? parent.budget.fork({ id, maxCostMicros: limits.maxCostMicros, maxCalls: limits.maxModelCalls + limits.maxToolCalls })
319
+ : new Budget(limits.maxCostMicros, limits.maxModelCalls + limits.maxToolCalls);
320
+ const grants = new Set(permissions.allow);
321
+ const tools = new Map(agent.tools.map((tool) => [tool.id, tool]));
322
+ const callIds = new Set<string>();
323
+ let terminal = false;
324
+ let settle!: (result: Outcome<InferOutput<O>>) => void;
325
+ const result = new Promise<Outcome<InferOutput<O>>>((resolve) => { settle = resolve; });
326
+ const deadline = Math.min(Date.now() + limits.maxDurationMs, parent?.deadline ?? Infinity);
327
+ const timer = setTimeout(() => {
328
+ if (!terminal) controller.abort(new MayuraError('TIMEOUT', 'The run deadline elapsed; no new work will be dispatched.'));
329
+ }, Math.max(0, deadline - Date.now()));
330
+ const handle: RunHandle<InferOutput<O>> = Object.freeze({
331
+ id, profile: 'ephemeral', result: () => result,
332
+ observe: (observerOptions?: { readonly after?: number; readonly signal?: AbortSignal }) => events.observe(observerOptions),
333
+ cancel: () => { if (!terminal && !controller.signal.aborted) controller.abort(new MayuraError('CANCELLED', 'Run cancellation was requested.')); },
334
+ });
335
+ const runOperations = (parent?.operations ?? operations).fork(limits.maxConcurrentOperations);
336
+ const state = { id, events, agent, parent, depth: parent ? parent.depth + 1 : 0, deadline, limits, permissions, budget, operations: runOperations, controller,
337
+ handle, children: [], speculative, receipts: new Map(), accepting: true, status: 'running', descendants: 0, modelCalls: 0, toolCalls: 0, hookCalls: 0,
338
+ heldModelCalls: 0, heldToolCalls: 0, bundles: new Set() } as unknown as RunState;
339
+ Object.defineProperty(state, 'root', { value: parent?.root ?? state });
340
+ const relayParent = (): void => { if (!controller.signal.aborted) controller.abort(parent?.controller.signal.reason); };
341
+ const relayExternal = (): void => { if (!controller.signal.aborted) controller.abort(new MayuraError('CANCELLED', 'The composing invocation was cancelled.')); };
342
+ parent?.controller.signal.addEventListener('abort', relayParent, { once: true });
343
+ externalSignal?.addEventListener('abort', relayExternal, { once: true });
344
+ if (parent?.controller.signal.aborted) relayParent();
345
+ if (externalSignal?.aborted) relayExternal();
346
+ // Closing admissions never releases unknown charges; callback settlement remains valid.
347
+ controller.signal.addEventListener('abort', () => {
348
+ state.accepting = false; budget.close(); for (const bundle of state.bundles) bundle.close();
349
+ }, { once: true });
350
+ if (parent) {
351
+ parent.children.push(state); for (const item of ancestors(parent)) item.descendants++;
352
+ parent.events.emit('delegate.started', { childRunId: id, childAgentId: agent.id });
353
+ }
354
+ else activeRoots++;
355
+ states.set(handle, state);
356
+ active.set(id, handle);
357
+ const checkCancelled = (signal: AbortSignal = controller.signal): void => {
358
+ if (Date.now() >= deadline && !controller.signal.aborted) controller.abort(new MayuraError('TIMEOUT', 'The run deadline elapsed.'));
359
+ if (controller.signal.aborted) throw controller.signal.reason;
360
+ if (signal.aborted) throw signal.reason;
361
+ };
362
+ const managed = (checks: readonly AgentGuard[]) => checks.flatMap(check => {
363
+ const descriptor = readManagedGuardDefinition(check);
364
+ return descriptor ? [{ handle: check as ManagedGuardDefinition, descriptor }] : [];
365
+ });
366
+ const requiredChecks = (checks: readonly AgentGuard[]) => {
367
+ const definitions = managed(checks);
368
+ for (const { descriptor } of definitions) if (!grants.has(`model:${descriptor.model.id}`)) {
369
+ throw new MayuraError('PERMISSION_DENIED', 'A required managed guard model destination is not authorized.');
370
+ }
371
+ return definitions;
372
+ };
373
+ const operationBundle = (kind: 'model' | 'tool', maxCostMicros: number): CallBundle => {
374
+ const definitions = requiredChecks(agent.guards.output);
375
+ return reserveCalls(state, [{ kind, maxCostMicros }, ...definitions.map(({ descriptor }) => ({ kind: 'model' as const, maxCostMicros: descriptor.model.maxCostMicros }))]);
376
+ };
377
+ /** Runs the guards and returns the content to use: the original, or what local guards rewrote it to. */
378
+ const guard = async (checks: readonly AgentGuard[], value: JsonValue, boundary: 'input' | 'output', callId: string, held?: readonly CallTicket[], signal: AbortSignal = controller.signal): Promise<JsonValue> => {
379
+ try { return await guardChecks(checks, value, boundary, callId, held, signal); }
380
+ catch (error) {
381
+ if (error instanceof MayuraError && error.code === 'GUARD_BLOCKED') {
382
+ await observe(Object.freeze({ stage: 'onViolation', source: 'guard', boundary, code: 'GUARD_BLOCKED', callId }), null, { signal });
383
+ }
384
+ throw error;
385
+ }
386
+ };
387
+ /**
388
+ * Guard `value`; if a guard rewrote it, validate the rewrite against `schema` again so a rewrite can never hand on a
389
+ * value its boundary would have refused. Returns the frozen content to use.
390
+ */
391
+ const guarded = async (checks: readonly AgentGuard[], value: JsonValue, schema: Schema, boundary: 'input' | 'output', callId: string,
392
+ maxBytes: number, held?: readonly CallTicket[], signal: AbortSignal = controller.signal): Promise<JsonValue> => {
393
+ const result = await guard(checks, value, boundary, callId, held, signal);
394
+ if (result === value) return value;
395
+ const revalidated = await cancellable(() => runOperations.run(signal, async () => {
396
+ checkCancelled(signal); return await validate(schema, result, boundary, { maxBytes });
397
+ }), signal);
398
+ return freezeJson(jsonValue(revalidated, { maxBytes }));
399
+ };
400
+ const guardChecks = async (checks: readonly AgentGuard[], value: JsonValue, boundary: 'input' | 'output', callId: string, held?: readonly CallTicket[], signal: AbortSignal = controller.signal): Promise<JsonValue> => {
401
+ checkCancelled(signal);
402
+ const definitions = managed(checks);
403
+ const local = checks.filter(check => !readManagedGuardDefinition(check)) as readonly Guard[];
404
+ // Local guards run in declared order, each on the content the one before it allowed or rewrote.
405
+ let current = value;
406
+ for (const check of local) {
407
+ type Checked = { readonly decision: 'allow' | 'block' } | { readonly decision: 'rewrite'; readonly value: JsonValue };
408
+ const verdict = await cancellable(() => runOperations.run(signal, async (): Promise<Checked> => {
409
+ try {
410
+ checkCancelled(signal);
411
+ const raw = await check.check(current, Object.freeze({ runId: id, callId, scope, signal, boundary }));
412
+ // Read adapter-owned properties inside the redaction boundary; do not retain a mutable verdict.
413
+ const decision = raw?.decision;
414
+ if (decision === 'allow' || decision === 'block') return { decision } as const;
415
+ if (decision === 'rewrite') return { decision, value: freezeJson(jsonValue((raw as { value: JsonValue }).value, { maxBytes: limits.maxOutputBytes })) } as const;
416
+ throw new Error();
417
+ }
418
+ catch { throw new MayuraError('GUARD_UNAVAILABLE', 'A required guard could not complete its check.'); }
419
+ }), signal);
420
+ checkCancelled(signal);
421
+ if (verdict.decision === 'block') throw new MayuraError('GUARD_BLOCKED', 'A required guard withheld this content.');
422
+ if (verdict.decision === 'rewrite') current = verdict.value;
423
+ }
424
+ if (definitions.length === 0) return current;
425
+ requiredChecks(checks);
426
+ const owned = held === undefined ? reserveCalls(state, definitions.map(({ descriptor }) => ({ kind: 'model' as const, maxCostMicros: descriptor.model.maxCostMicros }))) : undefined;
427
+ const entries = held ?? owned!.entries;
428
+ try {
429
+ if (entries.length !== definitions.length) throw new MayuraError('CONFLICT', 'Required guard reservations do not match this barrier.');
430
+ const results = await cancellable(() => Promise.allSettled(definitions.map(({ descriptor }, index) => {
431
+ const entry = entries[index]!;
432
+ const metadata = { purpose: 'guardrail', modelId: descriptor.model.id, checkId: descriptor.id, checkVersion: descriptor.version, boundary, callId } as const;
433
+ return evaluateManagedGuard({ descriptor, candidate: current,
434
+ context: Object.freeze({ runId: id, callId, scope, signal, boundary }), limits, operations: runOperations,
435
+ assertActive: () => checkCancelled(signal),
436
+ start: () => {
437
+ checkCancelled(signal);
438
+ if (!grants.has(`model:${descriptor.model.id}`)) throw new MayuraError('PERMISSION_DENIED', 'The managed guard model destination is not authorized.');
439
+ return consumeCall(state, entry, 'model');
440
+ },
441
+ onStarted: () => { events.emit('model.started', { ...metadata, modelCall: state.modelCalls }); },
442
+ onCompleted: (decision: 'allow' | 'block') => { events.emit('model.completed', { ...metadata, response: 'final', decision }); },
443
+ });
444
+ })), signal);
445
+ const rejected = results.find(result => result.status === 'rejected');
446
+ if (rejected?.status === 'rejected') throw rejected.reason;
447
+ checkCancelled(signal);
448
+ } finally { owned?.close(); }
449
+ return current;
450
+ };
451
+
452
+ const preflight = async (tool: AnyTool, rawInput: JsonValue, signal: AbortSignal = controller.signal): Promise<void> => {
453
+ checkCancelled(signal);
454
+ const required = [`tool:${tool.id}`, ...tool.capabilities, ...(tool.effects === 'none' ? [] : [`effect:${tool.effects}`])];
455
+ if (required.some((grant) => !grants.has(grant))) {
456
+ await observe(Object.freeze({ stage: 'onViolation', source: 'permission', boundary: 'tool', code: 'PERMISSION_DENIED' }), null, { signal });
457
+ throw new MayuraError('PERMISSION_DENIED', 'The requested tool is not authorized.');
458
+ }
459
+ await cancellable(() => runOperations.run(signal, async () => {
460
+ checkCancelled(signal);
461
+ return await validate(tool.input, rawInput, 'input', { maxBytes: limits.maxInputBytes });
462
+ }), signal);
463
+ checkCancelled(signal);
464
+ };
465
+
466
+ const control = async (event: HookEvent, step: number | null, signal: AbortSignal = controller.signal): Promise<Failure | undefined> => {
467
+ for (const handle of agent.hooks) {
468
+ if (handle.stage !== event.stage) continue;
469
+ checkCancelled(signal);
470
+ const descriptor = readHookDefinition(handle)!;
471
+ const invocationId = crypto.randomUUID();
472
+ const metadata = { hookId: handle.id, hookVersion: handle.version, stage: handle.stage, invocationId, step: step ?? 0, attempt: 1 };
473
+ const failure = await evaluateHook({ descriptor, event,
474
+ context: Object.freeze({ runId: id, rootId: state.root.id, ...(parent ? { parentId: parent.id } : {}),
475
+ agentId: agent.id, scope, invocationId, hookId: handle.id, hookVersion: handle.version, step, attempt: 1 }),
476
+ signal, operations: runOperations, assertActive: () => checkCancelled(signal),
477
+ onStarted: () => {
478
+ checkCancelled(signal);
479
+ const path = ancestors(state);
480
+ if (path.some(account => account.hookCalls >= account.limits.maxHookCalls)) {
481
+ throw new MayuraError('LIMIT_EXCEEDED', 'An ancestor lifecycle-hook call limit was reached.');
482
+ }
483
+ // No callback/await between the ancestor check and historical admission.
484
+ for (const account of path) account.hookCalls++;
485
+ events.emit('hook.started', metadata);
486
+ },
487
+ onCompleted: status => events.emit('hook.completed', { ...metadata, status }),
488
+ preflight,
489
+ invoke: (tool, input, callId, actionSignal) => invokeRunTool(tool, input, callId, step ?? 0, actionSignal, false),
490
+ allocateCallId: index => {
491
+ const callId = `hook:${invocationId}:${index}`;
492
+ if (callIds.has(callId)) throw new MayuraError('CONFLICT', 'Hook invocation identifiers must be unique.');
493
+ callIds.add(callId); return callId;
494
+ },
495
+ });
496
+ if (failure) {
497
+ if (failure.status === 'blocked' && failure.error.code === 'GUARD_BLOCKED') {
498
+ const callId = event.stage === 'beforeToolCall' ? event.proposal.callId : event.stage === 'beforeOutputRelease' ? event.callId : undefined;
499
+ await observe(Object.freeze({ stage: 'onViolation', source: 'hook', boundary: violationBoundary[event.stage as ControlHookStage],
500
+ code: 'GUARD_BLOCKED', ...(callId === undefined ? {} : { callId }) }), step, { signal });
501
+ }
502
+ return failure;
503
+ }
504
+ }
505
+ checkCancelled(signal); return undefined;
506
+ };
507
+
508
+ const observe = async (event: HookEvent, step: number | null, options: ObserveOptions = {}): Promise<Failure | undefined> => {
509
+ let failure: Failure | undefined;
510
+ for (const handle of agent.hooks) {
511
+ if (handle.stage !== event.stage) continue;
512
+ const descriptor = readHookDefinition(handle)!;
513
+ // Terminal observers run after this run's signal and budget closed; they get a deadline-only signal.
514
+ const signal = options.terminal ? new AbortController().signal : options.signal ?? controller.signal;
515
+ const invocationId = crypto.randomUUID();
516
+ const metadata = { hookId: handle.id, hookVersion: handle.version, stage: handle.stage, invocationId, step: step ?? 0, attempt: 1 };
517
+ const status = await evaluateObserver({ descriptor, event, signal, operations: runOperations,
518
+ context: Object.freeze({ runId: id, rootId: state.root.id, ...(parent ? { parentId: parent.id } : {}),
519
+ agentId: agent.id, scope, invocationId, hookId: handle.id, hookVersion: handle.version, step, attempt: 1 }),
520
+ onStarted: () => {
521
+ const path = ancestors(state);
522
+ if (path.some(account => account.hookCalls >= account.limits.maxHookCalls)) {
523
+ throw new MayuraError('LIMIT_EXCEEDED', 'An ancestor lifecycle-hook call limit was reached.');
524
+ }
525
+ for (const account of path) account.hookCalls++;
526
+ events.emit('hook.started', metadata);
527
+ },
528
+ onCompleted: completion => events.emit('hook.completed', { ...metadata, status: completion }),
529
+ });
530
+ if (status === 'failed' && descriptor.mandatory && !failure) {
531
+ failure = Object.freeze({ status: 'blocked', error: Object.freeze({ code: 'GUARD_UNAVAILABLE', message: 'A mandatory lifecycle observer could not complete.' }) });
532
+ }
533
+ }
534
+ return failure;
535
+ };
536
+ state.control = control; state.observe = observe;
537
+
538
+ /** Ordinary proposals and hook actions share the same broker, exact account and output barriers. */
539
+ const invokeRunTool = async (tool: AnyTool, rawInput: JsonValue, callId: string, step: number,
540
+ signal: AbortSignal = controller.signal, withHooks = true): Promise<Outcome<JsonValue>> => {
541
+ checkCancelled(signal);
542
+ // Model envelopes are validated JSON but not frozen. Do not expose their live history
543
+ // objects to callbacks or let a proposal hook rewrite the later executor's arguments.
544
+ const input = freezeJson(jsonValue(rawInput, { maxBytes: limits.maxInputBytes }));
545
+ const toolBundle = operationBundle('tool', tool.costMicros);
546
+ try {
547
+ if (withHooks) {
548
+ const failure = await control(Object.freeze({ stage: 'beforeToolCall', phase: 'proposal',
549
+ proposal: Object.freeze({ callId, toolId: tool.id, input }) }), step, signal);
550
+ if (failure) return failure;
551
+ }
552
+ checkCancelled(signal);
553
+ consumeCall(state, toolBundle.entries[0]!, 'tool');
554
+ events.emit('tool.started', { callId, toolId: tool.id });
555
+ let outcome = await invokeTool(tool, input, {
556
+ runId: id, callId, scope, signal, permissions, budget,
557
+ budgetBinding: bindToolBudgetTicket(tool, toolBundle.entries[0]!.ticket, { budget, runId: id, callId, scope, signal }),
558
+ maxOutputBytes: limits.maxOutputBytes,
559
+ acquireCallback: (callbackSignal: AbortSignal) => runOperations.acquire(callbackSignal),
560
+ onExecutionReceipt: async receipt => { record(state, receipt); },
561
+ ...(isAgentTool(tool) ? {
562
+ contextBindings: [childGateway.bind(Object.freeze({
563
+ spawn: (childAgent: AgentDefinition, childInput: unknown, childOptions: ChildOptions, childSignal: AbortSignal) =>
564
+ admitChild(state, childAgent, childInput, childOptions, true, childSignal),
565
+ }))],
566
+ } : { acquireExecution: (executionSignal: AbortSignal) => runOperations.acquire(executionSignal) }),
567
+ });
568
+ if (outcome.receipt) record(state, outcome.status === 'succeeded'
569
+ ? Object.freeze({ ...outcome.receipt, disclosure: 'withheld' as const }) : outcome.receipt);
570
+ if (outcome.status === 'cancelled' && signal.aborted && signal.reason instanceof MayuraError && signal.reason.code === 'TIMEOUT') {
571
+ outcome = { ...outcome, status: 'failed', error: publicError(signal.reason) };
572
+ }
573
+ if (outcome.status !== 'succeeded') {
574
+ const completion = { callId, toolId: tool.id, status: outcome.status,
575
+ ...(outcome.receipt ? { execution: outcome.receipt.execution, disclosure: outcome.receipt.disclosure } : {}) };
576
+ events.emit('tool.completed', completion);
577
+ // The tool already failed; an observer failure cannot make the outcome worse or better.
578
+ if (withHooks) await observe(Object.freeze({ stage: 'afterToolCall', step, ...completion }), step, { signal });
579
+ return outcome;
580
+ }
581
+ let toolOutput = freezeJson(jsonValue(outcome.output, { maxBytes: limits.maxOutputBytes }));
582
+ let failure: Exclude<Outcome<never>, { status: 'succeeded' }> | undefined;
583
+ let observed = false;
584
+ try {
585
+ // A rewritten tool result (for example redacted) is what the model sees, validated again by the tool's schema.
586
+ toolOutput = await guarded(agent.guards.output, toolOutput, tool.output, 'output', callId, limits.maxOutputBytes, toolBundle.entries.slice(1), signal);
587
+ if (withHooks) failure = await control(Object.freeze({ stage: 'beforeOutputRelease', source: 'tool', callId,
588
+ toolId: tool.id, candidate: toolOutput }), step, signal);
589
+ // Observe the real released outcome before it enters model history; a mandatory failure withholds it.
590
+ if (withHooks && !failure) {
591
+ observed = true;
592
+ failure = await observe(Object.freeze({ stage: 'afterToolCall', step, callId, toolId: tool.id, status: 'succeeded',
593
+ execution: 'succeeded', disclosure: 'released' }), step, { signal });
594
+ }
595
+ if (!failure) checkCancelled(signal);
596
+ } catch (error) { failure = outcomeFor(error) as Exclude<Outcome<never>, { status: 'succeeded' }>; }
597
+ if (failure) {
598
+ events.emit('tool.completed', { callId, toolId: tool.id, status: failure.status, execution: 'succeeded', disclosure: 'withheld' });
599
+ if (withHooks && !observed) await observe(Object.freeze({ stage: 'afterToolCall', step, callId, toolId: tool.id, status: failure.status,
600
+ execution: 'succeeded', disclosure: 'withheld' }), step, { signal });
601
+ const receipt = outcome.receipt ? Object.freeze({ ...outcome.receipt, disclosure: 'withheld' as const }) : undefined;
602
+ if (receipt) record(state, receipt);
603
+ // An uncertain hook action owns the primary failure receipt. The original known
604
+ // success remains withheld in the run-qualified evidence rather than replacing it.
605
+ return { ...failure, ...(!failure.receipt && receipt ? { receipt } : {}) };
606
+ }
607
+ if (outcome.receipt) record(state, outcome.receipt);
608
+ events.emit('tool.completed', { callId, toolId: tool.id, status: 'succeeded', execution: 'succeeded', disclosure: 'released' });
609
+ return Object.freeze({ ...outcome, output: toolOutput });
610
+ } finally { toolBundle.close(); }
611
+ };
612
+
613
+ const execute = async (): Promise<Outcome<InferOutput<O>>> => {
614
+ events.emit('run.started', { profile: 'ephemeral', rootId: state.root.id, agentId: agent.id, ...(parent ? { parentId: parent.id } : {}) });
615
+ checkCancelled();
616
+ if (parent) {
617
+ // The parent's own hooks decide delegation, in the parent's context and under its hook ceiling.
618
+ const delegateFailure = await parent.control(Object.freeze({ stage: 'beforeDelegate', childRunId: id, childAgentId: agent.id, input }), null, controller.signal);
619
+ if (delegateFailure) return delegateFailure;
620
+ }
621
+ const validated = inputAdmitted ? input : await cancellable(() => runOperations.run(controller.signal, async () => {
622
+ checkCancelled(); return await validate(agent.input, input, 'input', { maxBytes: limits.maxInputBytes });
623
+ }), controller.signal);
624
+ const approvedInput = await guarded(agent.guards.input, freezeJson(jsonValue(validated, { maxBytes: limits.maxInputBytes })), agent.input, 'input', 'input', limits.maxInputBytes);
625
+ const inputFailure = await control(Object.freeze({ stage: 'beforeExecution', input: approvedInput }), null);
626
+ if (inputFailure) return inputFailure;
627
+ const messages: ModelMessage[] = [{ role: 'user', content: approvedInput }];
628
+ let continuation: JsonValue | undefined;
629
+ /**
630
+ * Consume a streamed model call. Only the configured string field of the final output is released, in batches,
631
+ * each after the batch guards allow it; the returned complete response is then handled exactly like `generate`.
632
+ * Batch guards run directly rather than through operation permits: this code already holds the model call's
633
+ * permit, and a nested acquisition could wait on itself.
634
+ */
635
+ const streamModel = async (request: ModelRequest, step: number, modelCall: number): Promise<unknown> => {
636
+ const policy = agent.stream!; const extractor = createFieldExtractor(policy.field);
637
+ const batcher = createBatcher(policy.batch?.minChars, policy.batch?.maxChars);
638
+ let released = ''; let withheld = false; let index = 0; let response: unknown; let received = 0;
639
+ const release = async (batches: readonly string[]): Promise<void> => {
640
+ for (const batch of batches) {
641
+ if (withheld || batch.length === 0) return;
642
+ // Guards run in order on the batch with already released context; a guard may rewrite the batch (for
643
+ // example to redact it), and the next guard sees the rewrite. Context before the batch is never changed.
644
+ const context = released.slice(-512); let text = batch; let blocked = false;
645
+ for (const check of policy.guards) {
646
+ let verdict: { readonly decision?: unknown; readonly value?: unknown } | undefined;
647
+ try { verdict = await cancellable(async () => check.check(context + text, Object.freeze({ runId: id, callId: `model.${modelCall}.stream`, scope, signal: controller.signal, boundary: 'output' as const })), controller.signal); }
648
+ catch { blocked = true; break; }
649
+ checkCancelled();
650
+ if (verdict?.decision === 'allow') continue;
651
+ // A rewrite must keep the released context unchanged and return the rest as bounded text.
652
+ if (verdict?.decision === 'rewrite' && typeof verdict.value === 'string' && verdict.value.startsWith(context) && verdict.value.length - context.length <= 4_096) {
653
+ text = verdict.value.slice(context.length); continue;
654
+ }
655
+ blocked = true; break;
656
+ }
657
+ if (blocked) {
658
+ withheld = true; events.emit('output.withheld', { step, modelCall });
659
+ await observe(Object.freeze({ stage: 'onViolation', source: 'guard', boundary: 'output', code: 'GUARD_BLOCKED', callId: `model.${modelCall}.stream` }), step);
660
+ return;
661
+ }
662
+ if (text.length === 0) continue;
663
+ released += text; events.emit('output.delta', { step, modelCall, index: index++, text });
664
+ }
665
+ };
666
+ for await (const event of agent.model.stream!(request)) {
667
+ checkCancelled();
668
+ if (response !== undefined) throw new MayuraError('MODEL_FAILED', 'The model stream continued after its response.');
669
+ if (event?.type === 'output.delta' && typeof event.text === 'string') {
670
+ received += event.text.length;
671
+ if (received > limits.maxOutputBytes) throw new MayuraError('MODEL_FAILED', 'The model stream exceeded the output bound.');
672
+ if (!withheld && !extractor.done) await release(batcher.push(extractor.feed(event.text)));
673
+ } else if (event?.type === 'response') response = event.response;
674
+ else throw new MayuraError('MODEL_FAILED', 'The model stream produced an invalid event.');
675
+ }
676
+ if (response === undefined) throw new MayuraError('MODEL_FAILED', 'The model stream ended without a response.');
677
+ // The tail is released only for a final answer; a tool-call response releases nothing further.
678
+ if ((response as { type?: unknown }).type === 'final' && !withheld) await release(batcher.flush());
679
+ return response;
680
+ };
681
+ type StepResult = { readonly done: false } | { readonly done: true; readonly outcome: Outcome<InferOutput<O>> };
682
+ const runStep = async (step: number): Promise<StepResult> => {
683
+ const stepFailure = await control(Object.freeze({ stage: 'beforeStep', step }), step);
684
+ if (stepFailure) return { done: true, outcome: stepFailure };
685
+ if (!grants.has(`model:${agent.model.id}`)) {
686
+ await observe(Object.freeze({ stage: 'onViolation', source: 'permission', boundary: 'model', code: 'PERMISSION_DENIED' }), step);
687
+ throw new MayuraError('PERMISSION_DENIED', 'The model adapter is not authorized.');
688
+ }
689
+ checkCalls(state, 'model', 1);
690
+ // Freeze a bounded copy: a provider cannot mutate history or the tool registry between checks.
691
+ const snapshot = freezeJson(jsonValue(messages, { maxBytes: limits.maxContextBytes })) as unknown as readonly ModelMessage[];
692
+ const modelTools = agent.tools.map((tool) => Object.freeze({ id: tool.id, description: tool.description,
693
+ ...(tool.inputJsonSchema === undefined ? {} : { inputJsonSchema: freezeJson(jsonValue(tool.inputJsonSchema)) as typeof tool.inputJsonSchema }),
694
+ }));
695
+ const requestData = freezeJson(jsonValue({ instructions: agent.instructions, messages: snapshot, tools: modelTools, ...(continuation === undefined ? {} : { continuation }) }, { maxBytes: limits.maxContextBytes })) as unknown as Omit<ModelRequest, 'signal' | 'maxOutputTokens'>;
696
+ const primaryBundle = operationBundle('model', agent.model.maxCostMicros);
697
+ try {
698
+ // A content-only projection: private instructions and provider continuation never
699
+ // enter hook context. These immutable fields are the same ones sent to the adapter.
700
+ const modelFailure = await control(Object.freeze({ stage: 'beforeModelCall', purpose: 'primary', modelId: agent.model.id,
701
+ request: Object.freeze({ messages: requestData.messages, tools: requestData.tools, maxOutputTokens: limits.maxOutputTokens }) }), step);
702
+ if (modelFailure) return { done: true, outcome: modelFailure };
703
+ const rawResponse = await cancellable(() => runOperations.run(controller.signal, async () => {
704
+ checkCancelled();
705
+ const reservation = consumeCall(state, primaryBundle.entries[0]!, 'model');
706
+ events.emit('model.started', { step, modelCall: state.modelCalls });
707
+ let raw;
708
+ const modelRequest = Object.freeze({ ...requestData, signal: controller.signal, maxOutputTokens: limits.maxOutputTokens });
709
+ try { raw = agent.stream && agent.model.stream ? await streamModel(modelRequest, step, state.modelCalls) : await agent.model.generate(modelRequest); }
710
+ catch (error) {
711
+ const cost = modelFailureCost(error);
712
+ if (cost !== undefined) reservation.settle(cost);
713
+ throw new MayuraError('MODEL_FAILED', 'The model adapter failed to produce a response.');
714
+ }
715
+ // Account independently validated usage even when the content envelope is malformed.
716
+ // The callback may complete after cooperative cancellation; it cannot re-open disclosure.
717
+ reservation.settle(modelCost(raw));
718
+ return raw;
719
+ }), controller.signal);
720
+ checkCancelled();
721
+ const response = modelResponse(rawResponse, limits.maxOutputBytes, limits.maxToolCalls);
722
+ continuation = response.continuation === undefined ? undefined : freezeJson(jsonValue(response.continuation, { maxBytes: limits.maxContextBytes }));
723
+ events.emit('model.completed', { step, response: response.type });
724
+ const modelObserved = await observe(Object.freeze({ stage: 'afterModelCall', step, modelId: agent.model.id, response: response.type,
725
+ toolCalls: response.type === 'final' ? 0 : response.calls.length }), step);
726
+ if (modelObserved) return { done: true, outcome: modelObserved };
727
+ if (response.type === 'final') {
728
+ const output = await cancellable(() => runOperations.run(controller.signal, async () => {
729
+ checkCancelled(); return await validate(agent.output, response.output, 'output', { maxBytes: limits.maxOutputBytes });
730
+ }), controller.signal);
731
+ const callId = `model.${state.modelCalls}`;
732
+ const approvedOutput = await guarded(agent.guards.output, freezeJson(jsonValue(output, { maxBytes: limits.maxOutputBytes })), agent.output, 'output', callId,
733
+ limits.maxOutputBytes, primaryBundle.entries.slice(1));
734
+ const outputFailure = await control(Object.freeze({ stage: 'beforeOutputRelease', source: 'agent',
735
+ callId, candidate: approvedOutput }), step);
736
+ if (outputFailure) return { done: true, outcome: outputFailure };
737
+ checkCancelled();
738
+ return { done: true, outcome: Object.freeze({ status: 'succeeded' as const, output: approvedOutput as InferOutput<O> }) };
739
+ }
740
+ // A validated tool proposal has no final candidate; these holds cannot fund a later invocation.
741
+ primaryBundle.close();
742
+ checkCalls(state, 'tool', response.calls.length);
743
+ // Preflight every proposed grant/schema/identity before the first effect. Money/call
744
+ // holds are per dispatch and include its required checks, not every future batch member.
745
+ let batchCost = 0;
746
+ for (const call of response.calls) {
747
+ if (callIds.has(call.id)) throw new MayuraError('CONFLICT', 'Tool call identifiers must be unique within a run.');
748
+ const tool = tools.get(call.toolId);
749
+ if (!tool) throw new MayuraError('NOT_FOUND', 'The model requested an unregistered tool.');
750
+ await preflight(tool, call.input);
751
+ batchCost += tool.costMicros;
752
+ if (!Number.isSafeInteger(batchCost)) throw new MayuraError('BUDGET_EXCEEDED', 'Tool batch cost exceeds supported accounting bounds.');
753
+ }
754
+ const ledger = budget.snapshot();
755
+ if (typeof ledger.spentMicros !== 'number' || batchCost > limits.maxCostMicros - ledger.spentMicros - ledger.reservedMicros) {
756
+ throw new MayuraError('BUDGET_EXCEEDED', 'The complete tool batch cannot be admitted within the budget.');
757
+ }
758
+ for (const call of response.calls) callIds.add(call.id);
759
+ messages.push({ role: 'assistant', calls: response.calls });
760
+ for (const call of response.calls) {
761
+ const outcome = await invokeRunTool(tools.get(call.toolId)!, call.input, call.id, step);
762
+ if (outcome.status !== 'succeeded') return { done: true, outcome };
763
+ messages.push({ role: 'tool', callId: call.id, toolId: call.toolId, result: outcome.output });
764
+ }
765
+ return { done: false };
766
+ } finally { primaryBundle.close(); }
767
+ };
768
+ const finishStep = async (step: number, result: 'tool_calls' | 'final' | 'stopped'): Promise<Failure | undefined> => {
769
+ const failure = await observe(Object.freeze({ stage: 'afterStep', step, result }), step);
770
+ events.emit('step.completed', { step, result });
771
+ return failure;
772
+ };
773
+ for (let step = 0; step < limits.maxSteps; step++) {
774
+ checkCancelled();
775
+ events.emit('step.started', { step });
776
+ let result: StepResult;
777
+ try { result = await runStep(step); }
778
+ catch (error) { await finishStep(step, 'stopped'); throw error; }
779
+ const observed = await finishStep(step, !result.done ? 'tool_calls' : result.outcome.status === 'succeeded' ? 'final' : 'stopped');
780
+ // A mandatory afterStep failure stops a continuing step and withholds a final output; it never masks an earlier failure.
781
+ if (observed && (!result.done || result.outcome.status === 'succeeded')) return observed;
782
+ if (result.done) return result.outcome;
783
+ }
784
+ throw new MayuraError('LIMIT_EXCEEDED', 'The agent step limit was reached.');
785
+ };
786
+
787
+
788
+ queueMicrotask(() => {
789
+ void execute().catch(outcomeFor).then(async (candidate) => {
790
+ state.accepting = false;
791
+ // Accepted descendants remain required even if the parent's model has already finished.
792
+ if (candidate.status !== 'succeeded' && !controller.signal.aborted) {
793
+ controller.abort(new MayuraError('CANCELLED', 'Parent execution ended before its required children.'));
794
+ }
795
+ const settled = await Promise.all(state.children.map((child) => child.handle.result()));
796
+ const children = settled.filter((_, index) => !state.children[index]!.speculative);
797
+ let outcome: Outcome<InferOutput<O>> = candidate;
798
+ if (outcome.status === 'succeeded' && controller.signal.aborted) outcome = outcomeFor(controller.signal.reason);
799
+ const unknown = children.find((child) => child.status === 'outcome_unknown');
800
+ const failed = children.find((child) => child.status !== 'succeeded');
801
+ if (unknown) outcome = unknown;
802
+ else if (failed && (outcome.status === 'succeeded' || outcome.error.code === 'TOOL_FAILED')) outcome = failed;
803
+ if (agent.hooks.length > 0) {
804
+ const stage: TerminalHookStage = outcome.status === 'succeeded' ? 'afterExecution' : outcome.status === 'cancelled' ? 'onCancel'
805
+ : outcome.status === 'blocked' ? 'onBlocked' : 'onError';
806
+ const terminalFailure = await observe(terminalView(stage, outcome), null, { terminal: true });
807
+ // Only a mandatory afterExecution can change the outcome: it withholds a successful output.
808
+ if (terminalFailure && outcome.status === 'succeeded') outcome = terminalFailure;
809
+ await observe(terminalView('onFinally', outcome), null, { terminal: true });
810
+ }
811
+ if (parent && parent.agent.hooks.length > 0) {
812
+ const delegated = await parent.observe(Object.freeze({ stage: 'afterDelegate', childRunId: id, childAgentId: agent.id, status: outcome.status }), null, { terminal: true });
813
+ if (delegated && outcome.status === 'succeeded') outcome = delegated;
814
+ }
815
+ if (state.children.length > 0 || agent.hooks.length > 0) outcome = { ...outcome, evidence: evidenceFor(state) };
816
+ terminal = true;
817
+ state.status = outcome.status;
818
+ for (const bundle of state.bundles) bundle.close();
819
+ budget.close();
820
+ clearTimeout(timer);
821
+ parent?.controller.signal.removeEventListener('abort', relayParent);
822
+ externalSignal?.removeEventListener('abort', relayExternal);
823
+ events.emit('run.completed', { status: outcome.status, ...budget.snapshot() });
824
+ events.finish();
825
+ parent?.events.emit('delegate.completed', { childRunId: id, status: outcome.status });
826
+ active.delete(id);
827
+ if (!parent) activeRoots--;
828
+ settle(Object.freeze(outcome));
829
+ });
830
+ });
831
+ return handle;
832
+ };
833
+ return Object.freeze({
834
+ profile: 'ephemeral',
835
+ submit: <I extends Schema, O extends Schema>(agent: AgentDefinition<I, O>, submission: { readonly input: InferInput<I> }) =>
836
+ start(agent, submission.input, rootLimits, rootPermissions),
837
+ spawn: <I extends Schema, O extends Schema>(parent: RunHandle<unknown>, agent: AgentDefinition<I, O>, submission: ChildOptions & { readonly input: InferInput<I> }) =>
838
+ admitChild(lookup(parent), agent, submission.input, submission),
839
+ speculate: async <I extends Schema, O extends Schema>(parentHandle: RunHandle<unknown>, speculation: SpeculationOptions<I, O>): Promise<SpeculationResult<InferOutput<O>>> => {
840
+ const parent = lookup(parentHandle);
841
+ const branches = speculation?.branches; const verify = speculation?.verify;
842
+ const verifyTimeoutMs = speculation?.verifyTimeoutMs ?? 5_000;
843
+ if (!Array.isArray(branches) || branches.length < 1 || branches.length > 8 || typeof verify !== 'function'
844
+ || !Number.isSafeInteger(verifyTimeoutMs) || verifyTimeoutMs < 1 || verifyTimeoutMs > 30_000
845
+ || new Set(branches.map(branch => branch?.id)).size !== branches.length || branches.some(branch => !isIdentifier(branch?.id))) {
846
+ throw new MayuraError('INVALID_CONFIG', 'Speculation needs 1–8 uniquely identified branches, a verify function and a bounded verify deadline.');
847
+ }
848
+ const prepared = await Promise.all(branches.map(async branch => {
849
+ const permissions = permissionsFor(branch.permissions, true);
850
+ // No speculative external writes, host execution, further delegation or durable memory promotion.
851
+ if (permissions.allow.some(grant => grant === 'agent:delegate' || (grant.startsWith('effect:') && grant !== 'effect:read')
852
+ || (grant.startsWith('memory:') && grant !== 'memory:read'))) {
853
+ throw new MayuraError('PERMISSION_DENIED', 'Speculative branches cannot hold write, host, delegation or memory-mutation grants.');
854
+ }
855
+ let assumptions: JsonValue;
856
+ try { assumptions = freezeJson(jsonValue(branch.assumptions, { maxBytes: 65_536 })); }
857
+ catch { throw new MayuraError('INVALID_INPUT', 'Branch assumptions must be bounded plain JSON.'); }
858
+ const bytes = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(`mayura:speculation-assumptions:v1\0${canonicalJson(assumptions)}`));
859
+ return { branch, permissions, digest: [...new Uint8Array(bytes)].map(byte => byte.toString(16).padStart(2, '0')).join('') };
860
+ }));
861
+ const handles: RunHandle<InferOutput<O>>[] = [];
862
+ try {
863
+ for (const { branch, permissions } of prepared) {
864
+ handles.push(admitChild(parent, branch.agent, branch.input, { permissions, ...(branch.limits ? { limits: branch.limits } : {}) }, false, undefined, true));
865
+ }
866
+ } catch (error) { for (const handle of handles) handle.cancel(); throw error; }
867
+ const outcomes = new Map<number, Outcome<InferOutput<O>>>(); const verified = new Set<number>();
868
+ let winner: number | undefined;
869
+ const pending = new Map(handles.map((handle, index) => [index, handle.result().then(outcome => ({ index, outcome }))]));
870
+ while (pending.size > 0 && winner === undefined) {
871
+ const { index, outcome } = await Promise.race(pending.values());
872
+ pending.delete(index); outcomes.set(index, outcome);
873
+ if (outcome.status !== 'succeeded') continue;
874
+ let accepted = false;
875
+ try {
876
+ accepted = await new Promise<boolean>((resolve, reject) => {
877
+ const timer = setTimeout(() => resolve(false), verifyTimeoutMs);
878
+ Promise.resolve().then(() => verify(Object.freeze({ branchId: prepared[index]!.branch.id, assumptionsDigest: prepared[index]!.digest, output: outcome.output })))
879
+ .then(value => { clearTimeout(timer); resolve(value === true); }, error => { clearTimeout(timer); reject(error); });
880
+ });
881
+ } catch { accepted = false; }
882
+ if (accepted) { verified.add(index); winner = index; }
883
+ }
884
+ for (const [index, handle] of handles.entries()) if (index !== winner && !outcomes.has(index)) handle.cancel();
885
+ for (const [index, promise] of pending) outcomes.set(index, (await promise).outcome);
886
+ const promoted = winner === undefined ? undefined : outcomes.get(winner);
887
+ return Object.freeze({
888
+ status: winner === undefined ? 'none' as const : 'promoted' as const,
889
+ ...(winner === undefined || promoted?.status !== 'succeeded' ? {} : { branchId: prepared[winner]!.branch.id, output: promoted.output, assumptionsDigest: prepared[winner]!.digest }),
890
+ branches: Object.freeze(prepared.map(({ branch, digest }, index) => Object.freeze({ id: branch.id, runId: handles[index]!.id,
891
+ status: outcomes.get(index)!.status, assumptionsDigest: digest, verified: verified.has(index) }))),
892
+ });
893
+ },
894
+ inspect: (handle: RunHandle<unknown>): RunInspection => {
895
+ const state = lookup(handle);
896
+ return Object.freeze({ id: state.id, rootId: state.root.id, ...(state.parent ? { parentId: state.parent.id } : {}),
897
+ agentId: state.agent.id, status: state.status, budget: state.budget.snapshot(),
898
+ runs: Object.freeze(subtree(state).map((run) => Object.freeze({ id: run.id, ...(run.parent ? { parentId: run.parent.id } : {}), agentId: run.agent.id, status: run.status }))),
899
+ evidence: evidenceFor(state),
900
+ });
901
+ },
902
+ close: async (): Promise<void> => {
903
+ closed = true;
904
+ const runs = [...active.values()];
905
+ for (const run of runs) run.cancel();
906
+ await Promise.all(runs.map((run) => run.result()));
907
+ },
908
+ });
909
+ }