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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (578) hide show
  1. package/README.md +152 -35
  2. package/docs/README.md +82 -0
  3. package/docs/ai-agents.md +73 -0
  4. package/docs/cli/dev.md +111 -0
  5. package/docs/cli/init.md +192 -0
  6. package/docs/cli/operations.md +235 -0
  7. package/docs/cli/overview.md +129 -0
  8. package/docs/cli/run.md +182 -0
  9. package/docs/concepts/agent.md +197 -0
  10. package/docs/concepts/costs-and-budgets.md +177 -0
  11. package/docs/concepts/outcomes.md +154 -0
  12. package/docs/concepts/permissions.md +155 -0
  13. package/docs/concepts/runtime.md +172 -0
  14. package/docs/concepts/tools.md +202 -0
  15. package/docs/concepts/workflows.md +134 -0
  16. package/docs/guides/approvals-and-human-input.md +278 -0
  17. package/docs/guides/artifacts.md +123 -0
  18. package/docs/guides/child-agents.md +158 -0
  19. package/docs/guides/code-mode.md +233 -0
  20. package/docs/guides/deployment.md +644 -0
  21. package/docs/guides/durable-workflows.md +463 -0
  22. package/docs/guides/guardrails.md +205 -0
  23. package/docs/guides/helpers.md +176 -0
  24. package/docs/guides/lifecycle-hooks.md +187 -0
  25. package/docs/guides/mcp.md +123 -0
  26. package/docs/guides/memory-and-context.md +293 -0
  27. package/docs/guides/model-providers.md +371 -0
  28. package/docs/guides/model-routing.md +138 -0
  29. package/docs/guides/observability.md +238 -0
  30. package/docs/guides/operator-console.md +140 -0
  31. package/docs/guides/react.md +276 -0
  32. package/docs/guides/sagas-and-loops.md +212 -0
  33. package/docs/guides/server-and-client.md +559 -0
  34. package/docs/guides/skills.md +152 -0
  35. package/docs/guides/storage.md +251 -0
  36. package/docs/guides/streaming.md +146 -0
  37. package/docs/guides/terminal.md +166 -0
  38. package/docs/guides/testing.md +220 -0
  39. package/docs/guides/vision.md +155 -0
  40. package/docs/guides/webhooks.md +172 -0
  41. package/docs/guides/workflow-composition.md +141 -0
  42. package/docs/guides/workflow-operations.md +269 -0
  43. package/docs/installation.md +90 -0
  44. package/docs/introduction.md +74 -0
  45. package/docs/project/credits.md +78 -0
  46. package/docs/project/security.md +178 -0
  47. package/docs/project/support.md +91 -0
  48. package/docs/project/versioning.md +122 -0
  49. package/docs/quickstart.md +190 -0
  50. package/docs/reference/entry-points.md +146 -0
  51. package/lib/adapter-code-docker/dist/index.d.ts +8 -1
  52. package/lib/adapter-code-docker/dist/index.d.ts.map +1 -1
  53. package/lib/adapter-code-docker/dist/index.js +64 -67
  54. package/lib/adapter-code-docker/dist/index.js.map +1 -1
  55. package/lib/adapter-code-docker/dist/options.d.ts +15 -0
  56. package/lib/adapter-code-docker/dist/options.d.ts.map +1 -0
  57. package/lib/adapter-code-docker/dist/options.js +56 -0
  58. package/lib/adapter-code-docker/dist/options.js.map +1 -0
  59. package/lib/adapter-code-docker/image/Dockerfile +4 -2
  60. package/lib/adapter-code-docker/package.json +1 -1
  61. package/lib/adapter-code-docker/src/index.ts +63 -65
  62. package/lib/adapter-code-docker/src/options.ts +51 -0
  63. package/lib/adapter-code-quickjs/dist/index.d.ts +16 -4
  64. package/lib/adapter-code-quickjs/dist/index.d.ts.map +1 -1
  65. package/lib/adapter-code-quickjs/dist/index.js +94 -50
  66. package/lib/adapter-code-quickjs/dist/index.js.map +1 -1
  67. package/lib/adapter-code-quickjs/dist/worker-command.d.ts +27 -0
  68. package/lib/adapter-code-quickjs/dist/worker-command.d.ts.map +1 -0
  69. package/lib/adapter-code-quickjs/dist/worker-command.js +66 -0
  70. package/lib/adapter-code-quickjs/dist/worker-command.js.map +1 -0
  71. package/lib/adapter-code-quickjs/dist/worker.js +421 -104
  72. package/lib/adapter-code-quickjs/dist/worker.js.map +1 -1
  73. package/lib/adapter-code-quickjs/package.json +1 -1
  74. package/lib/adapter-code-quickjs/src/index.ts +88 -44
  75. package/lib/adapter-code-quickjs/src/worker-command.ts +68 -0
  76. package/lib/adapter-code-quickjs/src/worker.ts +315 -89
  77. package/lib/adapter-mcp/package.json +1 -1
  78. package/lib/artifacts/dist/contracts.d.ts +6 -2
  79. package/lib/artifacts/dist/contracts.d.ts.map +1 -1
  80. package/lib/artifacts/dist/contracts.js.map +1 -1
  81. package/lib/artifacts/dist/index.d.ts +1 -0
  82. package/lib/artifacts/dist/index.d.ts.map +1 -1
  83. package/lib/artifacts/dist/index.js +1 -0
  84. package/lib/artifacts/dist/index.js.map +1 -1
  85. package/lib/artifacts/dist/local-store.d.ts.map +1 -1
  86. package/lib/artifacts/dist/local-store.js +4 -7
  87. package/lib/artifacts/dist/local-store.js.map +1 -1
  88. package/lib/artifacts/dist/media.d.ts +11 -0
  89. package/lib/artifacts/dist/media.d.ts.map +1 -0
  90. package/lib/artifacts/dist/media.js +18 -0
  91. package/lib/artifacts/dist/media.js.map +1 -0
  92. package/lib/artifacts/package.json +1 -1
  93. package/lib/artifacts/src/contracts.ts +6 -2
  94. package/lib/artifacts/src/index.ts +1 -0
  95. package/lib/artifacts/src/local-store.ts +5 -7
  96. package/lib/artifacts/src/media.ts +20 -0
  97. package/lib/cli/dist/agent-guide.d.ts +10 -0
  98. package/lib/cli/dist/agent-guide.d.ts.map +1 -0
  99. package/lib/cli/dist/agent-guide.js +48 -0
  100. package/lib/cli/dist/agent-guide.js.map +1 -0
  101. package/lib/cli/dist/application.d.ts +24 -0
  102. package/lib/cli/dist/application.d.ts.map +1 -1
  103. package/lib/cli/dist/application.js +21 -0
  104. package/lib/cli/dist/application.js.map +1 -1
  105. package/lib/cli/dist/bin.js +26 -6
  106. package/lib/cli/dist/bin.js.map +1 -1
  107. package/lib/cli/dist/dev.d.ts.map +1 -1
  108. package/lib/cli/dist/dev.js +7 -1
  109. package/lib/cli/dist/dev.js.map +1 -1
  110. package/lib/cli/dist/index.d.ts +3 -3
  111. package/lib/cli/dist/index.d.ts.map +1 -1
  112. package/lib/cli/dist/index.js +19 -9
  113. package/lib/cli/dist/index.js.map +1 -1
  114. package/lib/cli/dist/interactive.d.ts.map +1 -1
  115. package/lib/cli/dist/interactive.js +52 -11
  116. package/lib/cli/dist/interactive.js.map +1 -1
  117. package/lib/cli/dist/operations.d.ts +25 -2
  118. package/lib/cli/dist/operations.d.ts.map +1 -1
  119. package/lib/cli/dist/operations.js +125 -12
  120. package/lib/cli/dist/operations.js.map +1 -1
  121. package/lib/cli/dist/output.d.ts.map +1 -1
  122. package/lib/cli/dist/output.js +3 -0
  123. package/lib/cli/dist/output.js.map +1 -1
  124. package/lib/cli/dist/providers.d.ts +34 -4
  125. package/lib/cli/dist/providers.d.ts.map +1 -1
  126. package/lib/cli/dist/providers.js +26 -5
  127. package/lib/cli/dist/providers.js.map +1 -1
  128. package/lib/cli/package.json +1 -1
  129. package/lib/cli/src/agent-guide.ts +47 -0
  130. package/lib/cli/src/application.ts +24 -0
  131. package/lib/cli/src/bin.ts +22 -5
  132. package/lib/cli/src/dev.ts +5 -1
  133. package/lib/cli/src/index.ts +18 -10
  134. package/lib/cli/src/interactive.ts +44 -12
  135. package/lib/cli/src/operations.ts +82 -12
  136. package/lib/cli/src/output.ts +3 -0
  137. package/lib/cli/src/providers.ts +45 -10
  138. package/lib/cli/starters/approval-workflow/dot-env.example +11 -0
  139. package/lib/cli/starters/approval-workflow/package.json +1 -2
  140. package/lib/cli/starters/approval-workflow/src/config.ts +25 -7
  141. package/lib/cli/starters/approval-workflow/src/intake.ts +1 -2
  142. package/lib/cli/starters/approval-workflow/src/model.ts +11 -4
  143. package/lib/cli/starters/approval-workflow/src/workflow.ts +1 -2
  144. package/lib/cli/starters/cli-agent/README.md +121 -0
  145. package/lib/cli/starters/cli-agent/dot-env.example +37 -0
  146. package/lib/cli/starters/cli-agent/dot-github/workflows/ci.yml +13 -0
  147. package/lib/cli/starters/cli-agent/dot-gitignore +10 -0
  148. package/lib/cli/starters/cli-agent/mayura.project.json +15 -0
  149. package/lib/cli/starters/cli-agent/package.json +28 -0
  150. package/lib/cli/starters/cli-agent/skills/release-notes/SKILL.md +18 -0
  151. package/lib/cli/starters/cli-agent/skills/release-notes/references/example.md +12 -0
  152. package/lib/cli/starters/cli-agent/src/assistant.ts +124 -0
  153. package/lib/cli/starters/cli-agent/src/cli.ts +72 -0
  154. package/lib/cli/starters/cli-agent/src/config.ts +117 -0
  155. package/lib/cli/starters/cli-agent/src/model.ts +34 -0
  156. package/lib/cli/starters/cli-agent/src/workspace.ts +170 -0
  157. package/lib/cli/starters/cli-agent/test/assistant.test.ts +205 -0
  158. package/lib/cli/starters/cli-agent/tsconfig.json +20 -0
  159. package/lib/cli/starters/event-automation/README.md +4 -3
  160. package/lib/cli/starters/event-automation/dot-env.example +11 -0
  161. package/lib/cli/starters/event-automation/package.json +1 -2
  162. package/lib/cli/starters/event-automation/src/config.ts +25 -7
  163. package/lib/cli/starters/event-automation/src/ingress.ts +3 -5
  164. package/lib/cli/starters/event-automation/src/model.ts +11 -4
  165. package/lib/cli/starters/event-automation/src/send-sample.ts +1 -1
  166. package/lib/cli/starters/event-automation/src/tracker/main.ts +1 -1
  167. package/lib/cli/starters/event-automation/src/tracker/mcp-server.ts +1 -1
  168. package/lib/cli/starters/event-automation/src/tracker/tickets.ts +1 -1
  169. package/lib/cli/starters/event-automation/src/tracker-tools.ts +1 -1
  170. package/lib/cli/starters/event-automation/src/triage.ts +15 -22
  171. package/lib/cli/starters/event-automation/src/workflows.ts +1 -1
  172. package/lib/cli/starters/event-automation/test/automation.test.ts +3 -3
  173. package/lib/cli/starters/research-team/README.md +2 -2
  174. package/lib/cli/starters/research-team/dot-env.example +11 -0
  175. package/lib/cli/starters/research-team/package.json +1 -2
  176. package/lib/cli/starters/research-team/src/config.ts +25 -7
  177. package/lib/cli/starters/research-team/src/desk.ts +1 -2
  178. package/lib/cli/starters/research-team/src/library/index.ts +1 -2
  179. package/lib/cli/starters/research-team/src/model.ts +11 -4
  180. package/lib/cli/starters/research-team/src/services.ts +1 -1
  181. package/lib/cli/starters/research-team/src/team.ts +1 -2
  182. package/lib/cli/starters/research-team/src/workflow.ts +45 -59
  183. package/lib/cli/starters/support-agent/dot-env.example +11 -0
  184. package/lib/cli/starters/support-agent/package.json +1 -2
  185. package/lib/cli/starters/support-agent/src/assistant.ts +5 -5
  186. package/lib/cli/starters/support-agent/src/config.ts +25 -7
  187. package/lib/cli/starters/support-agent/src/guardrails.ts +3 -1
  188. package/lib/cli/starters/support-agent/src/model.ts +11 -4
  189. package/lib/cli/starters/support-agent/src/returns.ts +1 -2
  190. package/lib/cli/starters/support-agent/test/support.test.ts +25 -1
  191. package/lib/cli/templates/basic-agent.ts +1 -2
  192. package/lib/cli/templates/capability-policy.ts +1 -2
  193. package/lib/cli/templates/code-mode-workflow.ts +1 -1
  194. package/lib/cli/templates/durable-approval.ts +1 -1
  195. package/lib/cli/templates/parallel-research.ts +1 -2
  196. package/lib/cli/templates/typed-tool-runner.ts +1 -2
  197. package/lib/client/dist/forms.d.ts.map +1 -1
  198. package/lib/client/dist/forms.js +3 -4
  199. package/lib/client/dist/forms.js.map +1 -1
  200. package/lib/client/dist/headless.d.ts +3 -1
  201. package/lib/client/dist/headless.d.ts.map +1 -1
  202. package/lib/client/dist/headless.js +10 -6
  203. package/lib/client/dist/headless.js.map +1 -1
  204. package/lib/client/dist/index.d.ts +95 -6
  205. package/lib/client/dist/index.d.ts.map +1 -1
  206. package/lib/client/dist/index.js +397 -124
  207. package/lib/client/dist/index.js.map +1 -1
  208. package/lib/client/dist/workflows.d.ts +1 -1
  209. package/lib/client/dist/workflows.d.ts.map +1 -1
  210. package/lib/client/dist/workflows.js +7 -6
  211. package/lib/client/dist/workflows.js.map +1 -1
  212. package/lib/client/package.json +1 -1
  213. package/lib/client/src/forms.ts +3 -4
  214. package/lib/client/src/headless.ts +13 -7
  215. package/lib/client/src/index.ts +344 -74
  216. package/lib/client/src/workflows.ts +8 -7
  217. package/lib/client-react/package.json +1 -1
  218. package/lib/code-mode/dist/index.d.ts +32 -1
  219. package/lib/code-mode/dist/index.d.ts.map +1 -1
  220. package/lib/code-mode/dist/index.js +289 -221
  221. package/lib/code-mode/dist/index.js.map +1 -1
  222. package/lib/code-mode/package.json +1 -1
  223. package/lib/code-mode/src/index.ts +288 -184
  224. package/lib/code-mode-workflows/package.json +1 -1
  225. package/lib/context/package.json +1 -1
  226. package/lib/core/dist/budget.d.ts.map +1 -1
  227. package/lib/core/dist/budget.js +17 -2
  228. package/lib/core/dist/budget.js.map +1 -1
  229. package/lib/core/dist/contracts.d.ts +57 -0
  230. package/lib/core/dist/contracts.d.ts.map +1 -1
  231. package/lib/core/dist/contracts.js +36 -0
  232. package/lib/core/dist/contracts.js.map +1 -1
  233. package/lib/core/dist/destination.d.ts +12 -0
  234. package/lib/core/dist/destination.d.ts.map +1 -0
  235. package/lib/core/dist/destination.js +37 -0
  236. package/lib/core/dist/destination.js.map +1 -0
  237. package/lib/core/dist/event-stream.d.ts +1 -1
  238. package/lib/core/dist/event-stream.d.ts.map +1 -1
  239. package/lib/core/dist/event-stream.js +7 -0
  240. package/lib/core/dist/event-stream.js.map +1 -1
  241. package/lib/core/dist/host.d.ts +3 -0
  242. package/lib/core/dist/host.d.ts.map +1 -1
  243. package/lib/core/dist/host.js +3 -0
  244. package/lib/core/dist/host.js.map +1 -1
  245. package/lib/core/dist/index.d.ts +2 -0
  246. package/lib/core/dist/index.d.ts.map +1 -1
  247. package/lib/core/dist/index.js +2 -0
  248. package/lib/core/dist/index.js.map +1 -1
  249. package/lib/core/dist/media.d.ts +98 -0
  250. package/lib/core/dist/media.d.ts.map +1 -0
  251. package/lib/core/dist/media.js +227 -0
  252. package/lib/core/dist/media.js.map +1 -0
  253. package/lib/core/dist/model-schema.d.ts +37 -0
  254. package/lib/core/dist/model-schema.d.ts.map +1 -0
  255. package/lib/core/dist/model-schema.js +154 -0
  256. package/lib/core/dist/model-schema.js.map +1 -0
  257. package/lib/core/package.json +1 -1
  258. package/lib/core/src/budget.ts +17 -2
  259. package/lib/core/src/contracts.ts +71 -3
  260. package/lib/core/src/destination.ts +33 -0
  261. package/lib/core/src/event-stream.ts +5 -1
  262. package/lib/core/src/host.ts +3 -0
  263. package/lib/core/src/index.ts +2 -0
  264. package/lib/core/src/media.ts +228 -0
  265. package/lib/core/src/model-schema.ts +129 -0
  266. package/lib/exporter-otlp/dist/otlp-http-json.js +1 -1
  267. package/lib/exporter-otlp/dist/otlp-http-json.js.map +1 -1
  268. package/lib/exporter-otlp/dist/signals.js +2 -2
  269. package/lib/exporter-otlp/dist/signals.js.map +1 -1
  270. package/lib/exporter-otlp/package.json +1 -1
  271. package/lib/exporter-otlp/src/otlp-http-json.ts +1 -1
  272. package/lib/exporter-otlp/src/signals.ts +2 -2
  273. package/lib/guardrails/package.json +1 -1
  274. package/lib/helpers/package.json +1 -1
  275. package/lib/memory/dist/index.js +1 -1
  276. package/lib/memory/dist/index.js.map +1 -1
  277. package/lib/memory/dist/native.d.ts.map +1 -1
  278. package/lib/memory/dist/native.js +4 -3
  279. package/lib/memory/dist/native.js.map +1 -1
  280. package/lib/memory/package.json +1 -1
  281. package/lib/memory/src/index.ts +1 -1
  282. package/lib/memory/src/native.ts +4 -3
  283. package/lib/memory-remote/package.json +1 -1
  284. package/lib/observability/package.json +1 -1
  285. package/lib/provider-anthropic/dist/index.d.ts +36 -3
  286. package/lib/provider-anthropic/dist/index.d.ts.map +1 -1
  287. package/lib/provider-anthropic/dist/index.js +128 -78
  288. package/lib/provider-anthropic/dist/index.js.map +1 -1
  289. package/lib/provider-anthropic/package.json +1 -1
  290. package/lib/provider-anthropic/src/index.ts +152 -76
  291. package/lib/provider-openai/dist/index.d.ts +71 -4
  292. package/lib/provider-openai/dist/index.d.ts.map +1 -1
  293. package/lib/provider-openai/dist/index.js +259 -96
  294. package/lib/provider-openai/dist/index.js.map +1 -1
  295. package/lib/provider-openai/package.json +1 -1
  296. package/lib/provider-openai/src/index.ts +282 -84
  297. package/lib/runtime/dist/agent.d.ts +18 -1
  298. package/lib/runtime/dist/agent.d.ts.map +1 -1
  299. package/lib/runtime/dist/agent.js +59 -3
  300. package/lib/runtime/dist/agent.js.map +1 -1
  301. package/lib/runtime/dist/composition.d.ts.map +1 -1
  302. package/lib/runtime/dist/composition.js +2 -1
  303. package/lib/runtime/dist/composition.js.map +1 -1
  304. package/lib/runtime/dist/hooks.d.ts +15 -3
  305. package/lib/runtime/dist/hooks.d.ts.map +1 -1
  306. package/lib/runtime/dist/hooks.js.map +1 -1
  307. package/lib/runtime/dist/index.d.ts +1 -1
  308. package/lib/runtime/dist/index.d.ts.map +1 -1
  309. package/lib/runtime/dist/index.js.map +1 -1
  310. package/lib/runtime/dist/response.d.ts +7 -1
  311. package/lib/runtime/dist/response.d.ts.map +1 -1
  312. package/lib/runtime/dist/response.js +23 -2
  313. package/lib/runtime/dist/response.js.map +1 -1
  314. package/lib/runtime/dist/router.d.ts +10 -3
  315. package/lib/runtime/dist/router.d.ts.map +1 -1
  316. package/lib/runtime/dist/router.js +45 -8
  317. package/lib/runtime/dist/router.js.map +1 -1
  318. package/lib/runtime/dist/runtime.d.ts +9 -1
  319. package/lib/runtime/dist/runtime.d.ts.map +1 -1
  320. package/lib/runtime/dist/runtime.js +50 -22
  321. package/lib/runtime/dist/runtime.js.map +1 -1
  322. package/lib/runtime/package.json +1 -1
  323. package/lib/runtime/src/agent.ts +69 -3
  324. package/lib/runtime/src/composition.ts +2 -1
  325. package/lib/runtime/src/hooks.ts +10 -4
  326. package/lib/runtime/src/index.ts +1 -1
  327. package/lib/runtime/src/response.ts +20 -2
  328. package/lib/runtime/src/router.ts +43 -10
  329. package/lib/runtime/src/runtime.ts +58 -27
  330. package/lib/sdk/dist/index.d.ts +9 -1
  331. package/lib/sdk/dist/index.d.ts.map +1 -1
  332. package/lib/sdk/dist/index.js +9 -1
  333. package/lib/sdk/dist/index.js.map +1 -1
  334. package/lib/sdk/package.json +1 -1
  335. package/lib/sdk/src/index.ts +9 -1
  336. package/lib/server/dist/index.d.ts +201 -3
  337. package/lib/server/dist/index.d.ts.map +1 -1
  338. package/lib/server/dist/index.js +701 -149
  339. package/lib/server/dist/index.js.map +1 -1
  340. package/lib/server/dist/inspector-bundle.d.ts +1 -1
  341. package/lib/server/dist/inspector-bundle.d.ts.map +1 -1
  342. package/lib/server/dist/inspector-bundle.js +4 -4
  343. package/lib/server/dist/inspector-bundle.js.map +1 -1
  344. package/lib/server/package.json +1 -1
  345. package/lib/server/src/index.ts +611 -135
  346. package/lib/server/src/inspector-bundle.ts +4 -4
  347. package/lib/server-node/dist/hardening.d.ts +1 -1
  348. package/lib/server-node/dist/hardening.d.ts.map +1 -1
  349. package/lib/server-node/dist/hardening.js +4 -2
  350. package/lib/server-node/dist/hardening.js.map +1 -1
  351. package/lib/server-node/dist/index.d.ts +2 -1
  352. package/lib/server-node/dist/index.d.ts.map +1 -1
  353. package/lib/server-node/dist/index.js.map +1 -1
  354. package/lib/server-node/dist/probe.js +2 -2
  355. package/lib/server-node/dist/probe.js.map +1 -1
  356. package/lib/server-node/dist/production.d.ts +8 -1
  357. package/lib/server-node/dist/production.d.ts.map +1 -1
  358. package/lib/server-node/dist/production.js +15 -2
  359. package/lib/server-node/dist/production.js.map +1 -1
  360. package/lib/server-node/package.json +1 -1
  361. package/lib/server-node/src/hardening.ts +5 -3
  362. package/lib/server-node/src/index.ts +2 -1
  363. package/lib/server-node/src/probe.ts +2 -2
  364. package/lib/server-node/src/production.ts +23 -3
  365. package/lib/skills/dist/index.d.ts +81 -0
  366. package/lib/skills/dist/index.d.ts.map +1 -0
  367. package/lib/skills/dist/index.js +311 -0
  368. package/lib/skills/dist/index.js.map +1 -0
  369. package/lib/skills/package.json +5 -0
  370. package/lib/skills/src/index.ts +260 -0
  371. package/lib/storage/dist/index.d.ts +1 -1
  372. package/lib/storage/dist/index.d.ts.map +1 -1
  373. package/lib/storage/dist/index.js.map +1 -1
  374. package/lib/storage/package.json +1 -1
  375. package/lib/storage/src/index.ts +1 -1
  376. package/lib/storage-contracts/dist/contracts.d.ts +12 -5
  377. package/lib/storage-contracts/dist/contracts.d.ts.map +1 -1
  378. package/lib/storage-contracts/dist/contracts.js +24 -6
  379. package/lib/storage-contracts/dist/contracts.js.map +1 -1
  380. package/lib/storage-contracts/dist/index.d.ts +2 -0
  381. package/lib/storage-contracts/dist/index.d.ts.map +1 -1
  382. package/lib/storage-contracts/dist/index.js +2 -0
  383. package/lib/storage-contracts/dist/index.js.map +1 -1
  384. package/lib/storage-contracts/dist/memory-contracts.js +1 -1
  385. package/lib/storage-contracts/dist/memory-contracts.js.map +1 -1
  386. package/lib/storage-contracts/dist/run-records.d.ts +100 -0
  387. package/lib/storage-contracts/dist/run-records.d.ts.map +1 -0
  388. package/lib/storage-contracts/dist/run-records.js +464 -0
  389. package/lib/storage-contracts/dist/run-records.js.map +1 -0
  390. package/lib/storage-contracts/dist/schema-digest.d.ts +17 -0
  391. package/lib/storage-contracts/dist/schema-digest.d.ts.map +1 -0
  392. package/lib/storage-contracts/dist/schema-digest.js +94 -0
  393. package/lib/storage-contracts/dist/schema-digest.js.map +1 -0
  394. package/lib/storage-contracts/dist/submission-journal.js +1 -1
  395. package/lib/storage-contracts/dist/submission-journal.js.map +1 -1
  396. package/lib/storage-contracts/dist/workflow-format5.d.ts +30 -2
  397. package/lib/storage-contracts/dist/workflow-format5.d.ts.map +1 -1
  398. package/lib/storage-contracts/dist/workflow-format5.js +57 -5
  399. package/lib/storage-contracts/dist/workflow-format5.js.map +1 -1
  400. package/lib/storage-contracts/package.json +1 -1
  401. package/lib/storage-contracts/src/contracts.ts +29 -5
  402. package/lib/storage-contracts/src/index.ts +2 -0
  403. package/lib/storage-contracts/src/memory-contracts.ts +1 -1
  404. package/lib/storage-contracts/src/run-records.ts +365 -0
  405. package/lib/storage-contracts/src/schema-digest.ts +71 -0
  406. package/lib/storage-contracts/src/submission-journal.ts +1 -1
  407. package/lib/storage-contracts/src/workflow-format5.ts +70 -6
  408. package/lib/storage-postgres/dist/index.d.ts +1 -1
  409. package/lib/storage-postgres/dist/index.d.ts.map +1 -1
  410. package/lib/storage-postgres/dist/index.js.map +1 -1
  411. package/lib/storage-postgres/dist/postgres.d.ts +15 -0
  412. package/lib/storage-postgres/dist/postgres.d.ts.map +1 -1
  413. package/lib/storage-postgres/dist/postgres.js +18 -7
  414. package/lib/storage-postgres/dist/postgres.js.map +1 -1
  415. package/lib/storage-postgres/package.json +1 -1
  416. package/lib/storage-postgres/src/index.ts +1 -1
  417. package/lib/storage-postgres/src/postgres.ts +34 -8
  418. package/lib/storage-sql/dist/aggregate-session.js +1 -1
  419. package/lib/storage-sql/dist/aggregate-session.js.map +1 -1
  420. package/lib/storage-sql/dist/scheduled-database.js +1 -1
  421. package/lib/storage-sql/dist/scheduled-database.js.map +1 -1
  422. package/lib/storage-sql/dist/workflow-tree-validation.js +1 -1
  423. package/lib/storage-sql/dist/workflow-tree-validation.js.map +1 -1
  424. package/lib/storage-sql/package.json +1 -1
  425. package/lib/storage-sql/src/aggregate-session.ts +1 -1
  426. package/lib/storage-sql/src/scheduled-database.ts +1 -1
  427. package/lib/storage-sql/src/workflow-tree-validation.ts +1 -1
  428. package/lib/storage-sqlite/dist/sqlite-database.js +4 -4
  429. package/lib/storage-sqlite/dist/sqlite-database.js.map +1 -1
  430. package/lib/storage-sqlite/dist/sqlite-worker.js +2 -2
  431. package/lib/storage-sqlite/dist/sqlite-worker.js.map +1 -1
  432. package/lib/storage-sqlite/dist/sqlite.js +1 -1
  433. package/lib/storage-sqlite/dist/sqlite.js.map +1 -1
  434. package/lib/storage-sqlite/package.json +1 -1
  435. package/lib/storage-sqlite/src/sqlite-database.ts +4 -4
  436. package/lib/storage-sqlite/src/sqlite-worker.ts +2 -2
  437. package/lib/storage-sqlite/src/sqlite.ts +1 -1
  438. package/lib/terminal/dist/index.d.ts +92 -0
  439. package/lib/terminal/dist/index.d.ts.map +1 -0
  440. package/lib/terminal/dist/index.js +397 -0
  441. package/lib/terminal/dist/index.js.map +1 -0
  442. package/lib/terminal/package.json +5 -0
  443. package/lib/terminal/src/index.ts +273 -0
  444. package/lib/testing/dist/index.d.ts +44 -1
  445. package/lib/testing/dist/index.d.ts.map +1 -1
  446. package/lib/testing/dist/index.js +63 -10
  447. package/lib/testing/dist/index.js.map +1 -1
  448. package/lib/testing/package.json +1 -1
  449. package/lib/testing/src/index.ts +83 -10
  450. package/lib/tools/dist/index.d.ts +32 -4
  451. package/lib/tools/dist/index.d.ts.map +1 -1
  452. package/lib/tools/dist/index.js +64 -11
  453. package/lib/tools/dist/index.js.map +1 -1
  454. package/lib/tools/package.json +1 -1
  455. package/lib/tools/src/index.ts +74 -13
  456. package/lib/workflows/dist/abandoned.d.ts +15 -0
  457. package/lib/workflows/dist/abandoned.d.ts.map +1 -0
  458. package/lib/workflows/dist/abandoned.js +33 -0
  459. package/lib/workflows/dist/abandoned.js.map +1 -0
  460. package/lib/workflows/dist/agent-step.d.ts +83 -0
  461. package/lib/workflows/dist/agent-step.d.ts.map +1 -0
  462. package/lib/workflows/dist/agent-step.js +161 -0
  463. package/lib/workflows/dist/agent-step.js.map +1 -0
  464. package/lib/workflows/dist/children-runtime.js +8 -8
  465. package/lib/workflows/dist/children-runtime.js.map +1 -1
  466. package/lib/workflows/dist/composite-fleet.js +2 -2
  467. package/lib/workflows/dist/composite-fleet.js.map +1 -1
  468. package/lib/workflows/dist/composite-host.d.ts.map +1 -1
  469. package/lib/workflows/dist/composite-host.js +26 -2
  470. package/lib/workflows/dist/composite-host.js.map +1 -1
  471. package/lib/workflows/dist/hook-relay.js +2 -2
  472. package/lib/workflows/dist/hook-relay.js.map +1 -1
  473. package/lib/workflows/dist/index.d.ts +1 -1
  474. package/lib/workflows/dist/index.d.ts.map +1 -1
  475. package/lib/workflows/dist/index.js.map +1 -1
  476. package/lib/workflows/dist/leadership.js +3 -3
  477. package/lib/workflows/dist/leadership.js.map +1 -1
  478. package/lib/workflows/dist/lifecycle-definition.d.ts +26 -4
  479. package/lib/workflows/dist/lifecycle-definition.d.ts.map +1 -1
  480. package/lib/workflows/dist/lifecycle-definition.js +31 -6
  481. package/lib/workflows/dist/lifecycle-definition.js.map +1 -1
  482. package/lib/workflows/dist/lifecycle-fleet.d.ts.map +1 -1
  483. package/lib/workflows/dist/lifecycle-fleet.js +9 -11
  484. package/lib/workflows/dist/lifecycle-fleet.js.map +1 -1
  485. package/lib/workflows/dist/lifecycle-host.d.ts.map +1 -1
  486. package/lib/workflows/dist/lifecycle-host.js +26 -2
  487. package/lib/workflows/dist/lifecycle-host.js.map +1 -1
  488. package/lib/workflows/dist/lifecycle-human-transport.d.ts +22 -2
  489. package/lib/workflows/dist/lifecycle-human-transport.d.ts.map +1 -1
  490. package/lib/workflows/dist/lifecycle-human-transport.js +115 -33
  491. package/lib/workflows/dist/lifecycle-human-transport.js.map +1 -1
  492. package/lib/workflows/dist/lifecycle-runtime.d.ts +62 -1
  493. package/lib/workflows/dist/lifecycle-runtime.d.ts.map +1 -1
  494. package/lib/workflows/dist/lifecycle-runtime.js +268 -64
  495. package/lib/workflows/dist/lifecycle-runtime.js.map +1 -1
  496. package/lib/workflows/dist/lifecycle.d.ts +6 -4
  497. package/lib/workflows/dist/lifecycle.d.ts.map +1 -1
  498. package/lib/workflows/dist/lifecycle.js +2 -0
  499. package/lib/workflows/dist/lifecycle.js.map +1 -1
  500. package/lib/workflows/dist/loop-runtime.d.ts.map +1 -1
  501. package/lib/workflows/dist/loop-runtime.js +38 -26
  502. package/lib/workflows/dist/loop-runtime.js.map +1 -1
  503. package/lib/workflows/dist/migration.d.ts +1 -1
  504. package/lib/workflows/dist/migration.d.ts.map +1 -1
  505. package/lib/workflows/dist/migration.js +3 -3
  506. package/lib/workflows/dist/migration.js.map +1 -1
  507. package/lib/workflows/dist/operator-transports.d.ts +24 -2
  508. package/lib/workflows/dist/operator-transports.d.ts.map +1 -1
  509. package/lib/workflows/dist/operator-transports.js +49 -3
  510. package/lib/workflows/dist/operator-transports.js.map +1 -1
  511. package/lib/workflows/dist/runtime.d.ts.map +1 -1
  512. package/lib/workflows/dist/runtime.js +34 -22
  513. package/lib/workflows/dist/runtime.js.map +1 -1
  514. package/lib/workflows/dist/saga-runtime.d.ts.map +1 -1
  515. package/lib/workflows/dist/saga-runtime.js +44 -30
  516. package/lib/workflows/dist/saga-runtime.js.map +1 -1
  517. package/lib/workflows/dist/scheduled-helpers.d.ts.map +1 -1
  518. package/lib/workflows/dist/scheduled-helpers.js +3 -3
  519. package/lib/workflows/dist/scheduled-helpers.js.map +1 -1
  520. package/lib/workflows/dist/storage-failure.d.ts +16 -0
  521. package/lib/workflows/dist/storage-failure.d.ts.map +1 -0
  522. package/lib/workflows/dist/storage-failure.js +38 -0
  523. package/lib/workflows/dist/storage-failure.js.map +1 -0
  524. package/lib/workflows/dist/sweep-position.d.ts +22 -0
  525. package/lib/workflows/dist/sweep-position.d.ts.map +1 -0
  526. package/lib/workflows/dist/sweep-position.js +45 -0
  527. package/lib/workflows/dist/sweep-position.js.map +1 -0
  528. package/lib/workflows/dist/traces.js +2 -2
  529. package/lib/workflows/dist/traces.js.map +1 -1
  530. package/lib/workflows/dist/worker.d.ts +31 -0
  531. package/lib/workflows/dist/worker.d.ts.map +1 -1
  532. package/lib/workflows/dist/worker.js +94 -0
  533. package/lib/workflows/dist/worker.js.map +1 -1
  534. package/lib/workflows/package.json +1 -1
  535. package/lib/workflows/src/abandoned.ts +32 -0
  536. package/lib/workflows/src/agent-step.ts +199 -0
  537. package/lib/workflows/src/children-runtime.ts +8 -8
  538. package/lib/workflows/src/composite-fleet.ts +2 -2
  539. package/lib/workflows/src/composite-host.ts +21 -3
  540. package/lib/workflows/src/hook-relay.ts +2 -2
  541. package/lib/workflows/src/index.ts +2 -1
  542. package/lib/workflows/src/leadership.ts +3 -3
  543. package/lib/workflows/src/lifecycle-definition.ts +50 -9
  544. package/lib/workflows/src/lifecycle-fleet.ts +7 -8
  545. package/lib/workflows/src/lifecycle-host.ts +21 -5
  546. package/lib/workflows/src/lifecycle-human-transport.ts +110 -26
  547. package/lib/workflows/src/lifecycle-runtime.ts +270 -60
  548. package/lib/workflows/src/lifecycle.ts +7 -0
  549. package/lib/workflows/src/loop-runtime.ts +34 -25
  550. package/lib/workflows/src/migration.ts +2 -2
  551. package/lib/workflows/src/operator-transports.ts +48 -4
  552. package/lib/workflows/src/runtime.ts +28 -22
  553. package/lib/workflows/src/saga-runtime.ts +38 -28
  554. package/lib/workflows/src/scheduled-helpers.ts +3 -3
  555. package/lib/workflows/src/storage-failure.ts +37 -0
  556. package/lib/workflows/src/sweep-position.ts +52 -0
  557. package/lib/workflows/src/traces.ts +2 -2
  558. package/lib/workflows/src/worker.ts +79 -1
  559. package/lib/workstream/dist/humans.d.ts +7 -3
  560. package/lib/workstream/dist/humans.d.ts.map +1 -1
  561. package/lib/workstream/dist/humans.js +13 -2
  562. package/lib/workstream/dist/humans.js.map +1 -1
  563. package/lib/workstream/dist/index.js +2 -2
  564. package/lib/workstream/dist/index.js.map +1 -1
  565. package/lib/workstream/dist/timers.js +2 -2
  566. package/lib/workstream/dist/timers.js.map +1 -1
  567. package/lib/workstream/dist/webhooks.d.ts +6 -2
  568. package/lib/workstream/dist/webhooks.d.ts.map +1 -1
  569. package/lib/workstream/dist/webhooks.js +17 -7
  570. package/lib/workstream/dist/webhooks.js.map +1 -1
  571. package/lib/workstream/package.json +1 -1
  572. package/lib/workstream/src/humans.ts +15 -5
  573. package/lib/workstream/src/index.ts +2 -2
  574. package/lib/workstream/src/timers.ts +2 -2
  575. package/lib/workstream/src/webhooks.ts +21 -8
  576. package/llms-full.txt +9766 -0
  577. package/llms.txt +92 -0
  578. package/package.json +18 -6
@@ -0,0 +1,154 @@
1
+ ---
2
+ title: "Outcomes and errors"
3
+ description: "Every run ends with one outcome: succeeded, failed, blocked, cancelled or outcome_unknown. What each means and what to do."
4
+ ---
5
+
6
+ Every run ends with exactly one outcome. `run.result()` resolves to it and does not throw when a run fails, so you
7
+ handle success and failure with one `switch`. Only a successful outcome has an `output`; every other outcome has an
8
+ `error` with a stable `code` and a safe `message`. One status needs special care: `outcome_unknown` means Mayura cannot
9
+ tell whether an external change happened, and you must check before retrying.
10
+
11
+ ## Handle an outcome
12
+
13
+ ```ts
14
+ const run = runtime.submit(agent, { input: { message: 'Cancel my order A-1001' } });
15
+ const outcome = await run.result();
16
+
17
+ switch (outcome.status) {
18
+ case 'succeeded':
19
+ console.log(outcome.output);
20
+ break;
21
+ case 'blocked':
22
+ case 'failed':
23
+ case 'cancelled':
24
+ console.warn(outcome.status, outcome.error.code, outcome.error.message);
25
+ break;
26
+ case 'outcome_unknown':
27
+ // A change may or may not have happened. Check the other system before doing anything again.
28
+ await flagForReview(run.id, runtime.inspect(run).evidence);
29
+ break;
30
+ }
31
+ ```
32
+
33
+ ## Statuses
34
+
35
+ | Status | Meaning | What to do |
36
+ | --- | --- | --- |
37
+ | `succeeded` | The run finished, and its output passed its schema and every output guard. | Use `outcome.output`. |
38
+ | `failed` | Something went wrong: invalid data, a model or tool error, a limit or a timeout. Nothing uncertain happened outside. | Read `error.code`. Fix the cause, or retry if the cause was temporary. |
39
+ | `blocked` | The run was stopped on purpose: a missing permission, the budget, or a guard or hook said no. | Don't retry as is. Grant the permission, raise the budget, or accept the refusal. |
40
+ | `cancelled` | You, `runtime.close()` or a parent run cancelled it. | Nothing, unless you want to submit again. |
41
+ | `outcome_unknown` | An external change may have happened, and Mayura cannot confirm it did or did not. | Reconcile before retrying (see below). |
42
+
43
+ Codes and statuses go together like this:
44
+
45
+ - `blocked`: `PERMISSION_DENIED`, `BUDGET_EXCEEDED`, `GUARD_BLOCKED`, `GUARD_UNAVAILABLE`.
46
+ - `cancelled`: `CANCELLED`.
47
+ - `outcome_unknown`: `OUTCOME_UNKNOWN`.
48
+ - `failed`: everything else, for example `INVALID_INPUT`, `INVALID_OUTPUT`, `MODEL_FAILED`, `TOOL_FAILED`,
49
+ `LIMIT_EXCEEDED`, `TIMEOUT` and `NOT_FOUND`.
50
+
51
+ A parent run takes on a child run's result when it is worse: if any child is `outcome_unknown`, so is the parent.
52
+
53
+ You will meet a few other statuses elsewhere. `runtime.inspect()` reports `running` for a run in progress. A call in a
54
+ [tool batch](./tools.md) can be `skipped` or `waiting`. Workflows have statuses of their own, described in
55
+ [Workflows](./workflows.md).
56
+
57
+ ## Errors
58
+
59
+ All public errors are `MayuraError` instances with a `code` and a `message`. `toJSON()` returns just those two fields,
60
+ so they are safe to log and send to a client.
61
+
62
+ Errors reach you in two ways:
63
+
64
+ - **Thrown** when you misuse the API: an invalid definition, an invalid runtime option, or a run that cannot start.
65
+ These are mistakes to fix in code.
66
+ - **Returned** in the outcome for everything that happens during a run.
67
+
68
+ ```ts
69
+ import { MayuraError, createRuntime } from 'mayura';
70
+
71
+ try {
72
+ createRuntime({ profile: 'ephemeral', limits: { maxSteps: 0 } });
73
+ } catch (error) {
74
+ if (error instanceof MayuraError) console.error(error.code); // INVALID_CONFIG
75
+ else throw error;
76
+ }
77
+ ```
78
+
79
+ Messages never contain the text of an exception your tool or a provider threw, or anything a guard saw. A tool that
80
+ throws `new Error('db password rejected')` is reported as `TOOL_FAILED` with a generic message. Log details inside
81
+ your tool if you need them. The one exception is `ToolRefusal`, whose reason you wrote on purpose.
82
+
83
+ ## Error codes
84
+
85
+ | Code | Meaning |
86
+ | --- | --- |
87
+ | `INVALID_CONFIG` | A definition, option or limit is invalid. Usually thrown when you define or create something. |
88
+ | `INVALID_INPUT` | Input did not match its schema or size limit: the run's input, or a tool's input from the model. |
89
+ | `INVALID_OUTPUT` | The model's final answer or a tool's result did not match its schema. |
90
+ | `INVALID_JSON` | A value is not plain JSON, or is too large or too deeply nested. |
91
+ | `PERMISSION_DENIED` | The model, tool, effect or capability was not allowed. |
92
+ | `BUDGET_EXCEEDED` | A call did not fit in the cost budget, or reported more than its ceiling. |
93
+ | `LIMIT_EXCEEDED` | A count or size limit was reached: steps, calls, depth, concurrent runs. |
94
+ | `CANCELLED` | The work was cancelled. |
95
+ | `TIMEOUT` | A deadline passed: the run's `maxDurationMs` or a tool's `timeoutMs`. |
96
+ | `TOOL_FAILED` | A tool threw (for a tool with `effects: 'none'`), refused with `ToolRefusal`, or a child agent did not succeed. |
97
+ | `MODEL_FAILED` | The model call failed. The message says why: refused credentials, a rate limit, the provider unavailable or too slow, a rejected request, a refusal, or an unusable answer. See [Model providers](../guides/model-providers.md). |
98
+ | `GUARD_BLOCKED` | A guard or hook blocked the content or the action. |
99
+ | `GUARD_UNAVAILABLE` | A guard or required hook could not decide, for example because it threw or timed out. |
100
+ | `OUTCOME_UNKNOWN` | An external effect may have happened and could not be confirmed. |
101
+ | `UNSUPPORTED_PROFILE` | `createRuntime` was given a profile other than `ephemeral`. |
102
+ | `NOT_FOUND` | Something requested does not exist, for example a tool the model asked for that the agent does not have. |
103
+ | `CONFLICT` | The request conflicts with current state: a closed runtime, a reused id, a record changed meanwhile. |
104
+ | `STORAGE_UNAVAILABLE` | Storage could not be reached. |
105
+ | `INTEGRITY_VIOLATION` | Stored or packaged data failed an integrity check. |
106
+
107
+ Storage adapters report their own failures as `StorageError`, a `MayuraError` whose `code` is one of the codes above
108
+ and whose `storageCode` names the exact storage condition, such as `STORE_CLOSED`. See
109
+ [Storage](../guides/storage.md#errors).
110
+
111
+ ## Retries
112
+
113
+ Mayura never retries a run or a tool call by itself. Whether a retry is safe depends on the error:
114
+
115
+ - `failed` with `MODEL_FAILED` for a rate limit, an unavailable provider or a timeout, or with `TIMEOUT`, is usually
116
+ temporary: submit the run again. Refused credentials or a rejected request repeat until you fix the configuration.
117
+ `BUDGET_EXCEEDED` messages give the call's cost and what the budget had left. To fail over between model
118
+ providers inside one run, use a model router; see [Model routing](../guides/model-routing.md).
119
+ - `failed` with `INVALID_OUTPUT` means the model answered in the wrong shape. A retry may work; if it keeps
120
+ happening, tighten the instructions or the provider's output schema.
121
+ - `blocked` repeats until you change something: a permission, the budget, or the content a guard blocked.
122
+ - `outcome_unknown` must not be retried blindly.
123
+
124
+ For retrying your own operations inside a tool, `retry` from `mayura/helpers` asks you to state that the operation is
125
+ `idempotent` or `read-only` before it allows more than one attempt. See [Helpers](../guides/helpers.md).
126
+
127
+ ## Reconciling outcome_unknown
128
+
129
+ `outcome_unknown` means a tool that changes things outside (`effects` of `write` or `host`) started, and then
130
+ something went wrong before Mayura got a clear answer: the tool threw, timed out, was cancelled mid-call, or reported
131
+ a cost it could not settle. The payment may have been taken, or not. The email may have been sent, or not.
132
+
133
+ Retrying could do the change twice, so Mayura stops and tells you. To resolve it:
134
+
135
+ 1. Find the call. `runtime.inspect(run).evidence` lists each tool call with its run id, call id, tool id and whether
136
+ it ran: `not_started`, `succeeded`, `failed` or `unknown`.
137
+ 2. Check the other system. If your tool used `runId` and `callId` as an idempotency key, look the operation up by
138
+ that key.
139
+ 3. Act on what you find: continue if it happened, submit again if it did not.
140
+
141
+ You can make this rare. Return structured results for ordinary answers instead of throwing, throw `ToolRefusal` when
142
+ nothing happened yet, and make write tools idempotent so a repeat is harmless. See [Tools](./tools.md).
143
+
144
+ The in-memory runtime loses its evidence when the process exits. Durable workflows store each call's record before
145
+ and after it runs, so an interrupted call can be found and reconciled after a restart. See
146
+ [Durable workflows](../guides/durable-workflows.md) and [Workflow operations](../guides/workflow-operations.md).
147
+
148
+ ## Related
149
+
150
+ - [Runtime](./runtime.md)
151
+ - [Tools](./tools.md)
152
+ - [Permissions](./permissions.md)
153
+ - [Costs and budgets](./costs-and-budgets.md)
154
+ - [Guardrails](../guides/guardrails.md)
@@ -0,0 +1,155 @@
1
+ ---
2
+ title: "Permissions"
3
+ description: "Explicit allow-lists decide which models, tools, effects and capabilities a run may use. Nothing is allowed by default."
4
+ ---
5
+
6
+ Permissions decide what a run may do. They are an explicit allow-list of strings, such as `model:openai.responses`,
7
+ `tool:orders.lookup` and `effect:write`, that you give the runtime. Anything not on the list is denied, including the
8
+ model itself. Instructions, user input, tool results and the model's own requests can never add to the list, so a
9
+ prompt injection cannot give an agent new authority.
10
+
11
+ ## A first allow-list
12
+
13
+ ```ts
14
+ import { createRuntime } from 'mayura';
15
+
16
+ const runtime = createRuntime({
17
+ profile: 'ephemeral',
18
+ permissions: {
19
+ allow: [
20
+ 'model:openai.responses', // call this model adapter
21
+ 'tool:orders.lookup', // call this tool
22
+ 'tool:orders.refund',
23
+ 'effect:read', // tools that read outside state
24
+ 'effect:write', // tools that change outside state
25
+ 'payments:refund', // a capability orders.refund declares
26
+ ],
27
+ },
28
+ scope: { principalId: 'customer-42', projectId: 'shop' },
29
+ limits: { maxCostMicros: 100_000 },
30
+ });
31
+ ```
32
+
33
+ If a run needs something it was not given, it ends as `blocked` with `PERMISSION_DENIED`, before the model or tool is
34
+ called.
35
+
36
+ ## What each grant means
37
+
38
+ | Grant | Allows | Example |
39
+ | --- | --- | --- |
40
+ | `model:<adapter id>` | Calling that model adapter. Checked before every model call. | `model:openai.responses`, `model:anthropic.messages`, `model:scripted` |
41
+ | `tool:<tool id>` | Calling that tool. | `tool:orders.lookup` |
42
+ | `effect:read` | Calling tools with `effects: 'read'`. | |
43
+ | `effect:write` | Calling tools with `effects: 'write'`. | |
44
+ | `effect:host` | Calling tools with `effects: 'host'`. | |
45
+ | any capability name | Calling tools that declare that capability. | `payments:refund`, `email:send` |
46
+
47
+ A tool call needs all of these at once: `tool:<id>`, every name in the tool's `capabilities`, and `effect:<effects>`
48
+ unless its effects are `'none'`. So `effect:write` alone lets nothing run; it only matters together with a
49
+ `tool:` grant.
50
+
51
+ | Tool | Grants a run needs |
52
+ | --- | --- |
53
+ | `math.add`, `effects: 'none'`, no capabilities | `tool:math.add` |
54
+ | `orders.lookup`, `effects: 'read'` | `tool:orders.lookup`, `effect:read` |
55
+ | `orders.refund`, `effects: 'write'`, capabilities `['payments:refund']` | `tool:orders.refund`, `effect:write`, `payments:refund` |
56
+
57
+ Capability names are yours to invent. Parts of Mayura declare their own, for example `agent:delegate` for calling
58
+ child agents and `skills:read` for the skills tools.
59
+
60
+ For a model router, the grant is the router's own id, and it covers every route. A model-backed guard needs
61
+ `model:<id>` for the model it calls.
62
+
63
+ ## Rules
64
+
65
+ - Grants are exact strings. There are no wildcards: `tool:*` or `tool:orders.*` match nothing.
66
+ - There is no deny list. Leave a grant out to deny it.
67
+ - Grants are case-sensitive. At most 4096 grants per list, each up to 256 characters. Duplicates are ignored.
68
+ - The list is fixed when you create the runtime. Create a runtime per request if permissions differ per user.
69
+
70
+ ## Scope
71
+
72
+ `scope` says who a run acts for: `{ principalId, projectId }`. It is not a permission; it is identity. Mayura passes it
73
+ to every tool (`context.scope`), guard and hook, so your code can limit what it reads and writes to that user and
74
+ project:
75
+
76
+ ```ts
77
+ import { defineTool, z } from 'mayura';
78
+
79
+ export const myOrder = defineTool({
80
+ id: 'orders.mine',
81
+ version: '1',
82
+ description: 'Look up one of the signed-in customer\'s orders. Returns found=false otherwise.',
83
+ input: z.object({ orderId: z.string() }),
84
+ output: z.object({ found: z.boolean(), status: z.string().nullable() }),
85
+ effects: 'read',
86
+ capabilities: [],
87
+ execute: async ({ orderId }, context) => {
88
+ const order = await db.findOrder(orderId, { ownerId: context.scope.principalId });
89
+ return order ? { found: true, status: order.status } : { found: false, status: null };
90
+ },
91
+ });
92
+ ```
93
+
94
+ Treat "not yours" and "does not exist" the same, so a tool never confirms that someone else's record exists. The
95
+ default scope is `{ principalId: 'local', projectId: 'default' }`. When a runtime serves many users, set the scope from
96
+ your authenticated user, never from the model or the request body.
97
+
98
+ ## Child agents get less, never more
99
+
100
+ An agent can call another agent through `agentAsTool`. The child runs with the permissions you list for it,
101
+ **intersected** with the parent's: a grant the parent does not hold is dropped. The child's limits cannot exceed the
102
+ parent's, and its cost counts against the parent's budget.
103
+
104
+ ```ts
105
+ import { agentAsTool } from 'mayura';
106
+
107
+ export const askResearcher = agentAsTool(researcher, {
108
+ id: 'research.ask',
109
+ description: 'Ask the research agent a question. Returns its findings.',
110
+ permissions: { allow: ['model:openai.responses', 'tool:web.search', 'effect:read'] },
111
+ limits: { maxSteps: 6, maxCostMicros: 50_000 },
112
+ });
113
+ ```
114
+
115
+ For the parent agent to use `askResearcher`, its runtime must allow:
116
+
117
+ - `tool:research.ask` and `agent:delegate`, to call the child at all;
118
+ - `model:openai.responses`, `tool:web.search` and `effect:read`, because the child only keeps grants the parent has.
119
+
120
+ `runtime.spawn()` follows the same rules. Speculative branches (`runtime.speculate()`) are stricter still: they may
121
+ not hold `effect:write`, `effect:host`, `agent:delegate` or memory write grants. See
122
+ [Child agents](../guides/child-agents.md).
123
+
124
+ ## Workflows
125
+
126
+ A workflow runtime takes its own `permissions` list, and each tool step is checked with the same rule as above. When
127
+ you run an agent as a step of a durable workflow with `agentAsDurableWorkflow`, there are two lists:
128
+
129
+ - the workflow's list must allow the step itself: `tool:<agent id>.agent`, `agent:durable`, `effect:host` and
130
+ `model:<model id>`;
131
+ - the `permissions` option of `agentAsDurableWorkflow` is what the agent may do inside the step. It is not intersected
132
+ with the workflow's list, so grant there only what that agent needs.
133
+
134
+ See [Workflows](./workflows.md) and [Durable workflows](../guides/durable-workflows.md).
135
+
136
+ ## Other permission lists
137
+
138
+ Some parts of Mayura check separate lists with their own names. A memory store takes its own `permissions`, with names
139
+ such as `memory:read` and `memory:write` (see [Memory and context](../guides/memory-and-context.md)). The HTTP server
140
+ gives each access token capabilities such as `runs:submit` and `workflows:read` (see
141
+ [Server and client](../guides/server-and-client.md)). These do not mix with a runtime's grants.
142
+
143
+ ## Good to know
144
+
145
+ - Permissions control what Mayura will call. They do not sandbox a tool's own code, which runs in your process.
146
+ - Instructions like "never refund more than $50" are advice to the model, not rules. Enforce such limits in the tool,
147
+ in a guard, or with a separate capability.
148
+
149
+ ## Related
150
+
151
+ - [Tools](./tools.md)
152
+ - [Runtime](./runtime.md)
153
+ - [Outcomes and errors](./outcomes.md)
154
+ - [Guardrails](../guides/guardrails.md)
155
+ - [Security](../project/security.md)
@@ -0,0 +1,172 @@
1
+ ---
2
+ title: "Runtime"
3
+ description: "Create a runtime, submit agents, watch their events, cancel them and read their outcome, costs and evidence."
4
+ ---
5
+
6
+ A runtime runs agents. You create it with `createRuntime`, telling it what runs may do (permissions), who they act for
7
+ (scope) and how far they may go (limits). Then you `submit` an agent with its input and get a handle to the run. One
8
+ runtime can run many agents and many runs at once; usually you create one per process, or one per request when
9
+ permissions or scope differ per user.
10
+
11
+ ## Submit a run
12
+
13
+ ```ts
14
+ import { createRuntime } from 'mayura';
15
+
16
+ const runtime = createRuntime({
17
+ profile: 'ephemeral',
18
+ permissions: { allow: ['model:openai.responses', 'tool:orders.lookup', 'effect:read'] },
19
+ scope: { principalId: 'customer-42', projectId: 'shop' },
20
+ limits: { maxCostMicros: 100_000, maxDurationMs: 30_000 },
21
+ });
22
+
23
+ try {
24
+ const run = runtime.submit(supportAgent, { input: { message: 'Where is order A-1001?' } });
25
+
26
+ for await (const event of run.observe()) {
27
+ console.log(event.sequence, event.type, event.metadata);
28
+ }
29
+
30
+ const outcome = await run.result();
31
+ if (outcome.status === 'succeeded') console.log(outcome.output);
32
+ else console.error(outcome.status, outcome.error.code, outcome.error.message);
33
+
34
+ console.log(runtime.inspect(run).budget); // { spentMicros, reservedMicros, calls }
35
+ } finally {
36
+ await runtime.close();
37
+ }
38
+ ```
39
+
40
+ ## Options
41
+
42
+ | Option | Default | What it is |
43
+ | --- | --- | --- |
44
+ | `profile` | required | Must be `'ephemeral'`. Anything else throws `UNSUPPORTED_PROFILE`. |
45
+ | `permissions` | `{ allow: [] }` | What runs may use. Nothing is allowed by default. See [Permissions](./permissions.md). |
46
+ | `scope` | `{ principalId: 'local', projectId: 'default' }` | Who runs act for. Tools, guards and hooks receive it. |
47
+ | `limits` | see below | Ceilings for every run. |
48
+
49
+ `ephemeral` means the runtime keeps everything in memory. Runs, events and costs are lost when the process exits, and
50
+ a run interrupted by a crash is not resumed. For work that must survive restarts, use
51
+ [durable workflows](../guides/durable-workflows.md).
52
+
53
+ `scope.principalId` and `scope.projectId` must start with a letter or digit and may contain letters, digits, `.`,
54
+ `_`, `/` and `-`, up to 128 characters. Use an internal user id, not an email address.
55
+
56
+ ## Limits
57
+
58
+ Each submitted run gets its own counters and its own cost budget, checked against these limits. `maxConcurrentRuns`
59
+ and `maxConcurrentOperations` also apply to the runtime as a whole. Child runs count against their parent's limits.
60
+
61
+ | Limit | Default | What it bounds |
62
+ | --- | --- | --- |
63
+ | `maxSteps` | `16` | Model turns in one run. Reaching it fails the run with `LIMIT_EXCEEDED`. |
64
+ | `maxModelCalls` | `16` | Model calls, including model-backed guards. |
65
+ | `maxToolCalls` | `64` | Tool calls. `0` is allowed. |
66
+ | `maxHookCalls` | `128` | Lifecycle hook calls. |
67
+ | `maxDurationMs` | `60000` | Wall-clock time for the run. |
68
+ | `maxInputBytes` | `1048576` | Size of the submitted input and of each tool input. |
69
+ | `maxOutputBytes` | `1048576` | Size of the final output and of each tool output. |
70
+ | `maxContextBytes` | `2097152` | Size of the conversation sent to the model, without media. |
71
+ | `maxMediaBytes` | `20971520` | All images and PDFs in one run, with the input and from tools. See [Vision](../guides/vision.md). |
72
+ | `maxOutputTokens` | `4096` | Output tokens the model may generate per call. |
73
+ | `maxCostMicros` | `0` | Total cost of the run, in micros. See [Costs and budgets](./costs-and-budgets.md). |
74
+ | `maxEventRetention` | `256` | Events kept in memory per run for `observe()`. |
75
+ | `maxConcurrentRuns` | `32` | Top-level runs in progress at once. |
76
+ | `maxDescendantRuns` | `64` | Child runs one run may start, counting their children. |
77
+ | `maxDepth` | `8` | How deep child runs may nest. |
78
+ | `maxConcurrentOperations` | `32` | Model calls, tool calls, validations and guards in progress at once. |
79
+
80
+ Every limit except `maxCostMicros` and `maxToolCalls` must be a positive integer. An unknown limit name throws
81
+ `INVALID_CONFIG`.
82
+
83
+ `maxCostMicros` defaults to 0, so a paid model is refused until you set it. Only free models (for example the
84
+ scripted test model, whose calls cost 0) work without it.
85
+
86
+ ## The run handle
87
+
88
+ `runtime.submit(agent, { input })` returns a `RunHandle` right away; the run starts on its own.
89
+
90
+ | Member | What it does |
91
+ | --- | --- |
92
+ | `id` | The run's id. |
93
+ | `result()` | A promise of the run's outcome. It never rejects for a failed run; check `status`. Call it as often as you like. |
94
+ | `observe(options?)` | An async iterable of the run's events. Ends when the run ends. |
95
+ | `cancel()` | Asks the run to stop. Safe to call more than once. |
96
+
97
+ `submit` itself throws only when the run cannot start at all: the input is not plain JSON or is larger than
98
+ `maxInputBytes` (`INVALID_INPUT`), `maxConcurrentRuns` runs are in progress (`LIMIT_EXCEEDED`), or the runtime is
99
+ closed (`CONFLICT`). Everything after that, including invalid input for the agent's schema, arrives as the outcome.
100
+
101
+ ## Events
102
+
103
+ Every event has `runId`, a `sequence` number that increases by one, a `timestamp`, a `type` and a small `metadata`
104
+ object (ids, counts and statuses, never prompts or secrets).
105
+
106
+ | Type | When |
107
+ | --- | --- |
108
+ | `run.started` | The run began. |
109
+ | `step.started`, `step.completed` | A model turn began or ended. |
110
+ | `model.started`, `model.completed` | A model call began or returned. |
111
+ | `tool.started`, `tool.completed` | A tool call began or ended, with its status. |
112
+ | `hook.started`, `hook.completed` | A lifecycle hook ran. |
113
+ | `delegate.started`, `delegate.completed` | A child run began or ended. |
114
+ | `output.delta`, `output.withheld` | A streamed batch of text was released, or streaming stopped. |
115
+ | `events.gap` | Older events were dropped before you read them. |
116
+ | `run.completed` | The run ended, with its status and cost totals. |
117
+
118
+ Events are kept in a buffer of `maxEventRetention` entries. If you start observing late, or read slower than the run
119
+ writes, the oldest events may be gone; you then get one `events.gap` event with the missing range instead of silence.
120
+ Pass `after: sequence` to resume after an event you already saw, and `signal` to stop observing. Observing never
121
+ changes the run, and stopping observation does not cancel it.
122
+
123
+ ## Cancel a run
124
+
125
+ `run.cancel()` stops the run from starting new model calls, tool calls or child runs, and the outcome becomes
126
+ `cancelled`. Work already in progress is told through its `AbortSignal`; a tool that already sent a request may still
127
+ complete it. In that case the call is `outcome_unknown`, and so is the run. See [Outcomes and errors](./outcomes.md).
128
+
129
+ When `maxDurationMs` passes, the run is stopped the same way and fails with `TIMEOUT`.
130
+
131
+ ## Inspect a run
132
+
133
+ `runtime.inspect(handle)` returns a snapshot of a run and its children, while it runs or after:
134
+
135
+ - `status`: `running` or the final status.
136
+ - `budget`: `spentMicros`, `reservedMicros` (cost held for calls in progress or with unknown cost) and `calls`.
137
+ - `runs`: the run and every child run, with ids, agent ids and statuses.
138
+ - `evidence`: for each tool call, whether it ran (`not_started`, `succeeded`, `failed` or `unknown`) and whether its
139
+ result was released to the model.
140
+
141
+ ## Child runs and speculation
142
+
143
+ Two methods start runs under a running parent, sharing its budget and limits:
144
+
145
+ - `runtime.spawn(parent, agent, { input, permissions, limits })` starts a child run. The child gets only the
146
+ permissions you list that the parent also has, and its limits cannot exceed the parent's. The parent needs
147
+ `agent:delegate`. Most apps use `agentAsTool` instead, so the model decides when to delegate.
148
+ - `runtime.speculate(parent, { branches, verify })` runs 1 to 8 read-only branches at once and keeps at most one
149
+ result, the first that your `verify` function accepts.
150
+
151
+ Both are covered in [Child agents](../guides/child-agents.md).
152
+
153
+ ## Close the runtime
154
+
155
+ `await runtime.close()` stops accepting runs, cancels the runs in progress and waits until each has an outcome.
156
+ Call it when your process shuts down, or in a `finally` block in scripts and tests.
157
+
158
+ ## Good to know
159
+
160
+ - Limits are enforced between steps and at every call. Your own code in tools and hooks is not interrupted by force;
161
+ it must respect `context.signal`.
162
+ - A runtime's permissions and scope are fixed when you create it. For per-user authority, create a runtime per user
163
+ or request; it is cheap.
164
+ - For a runtime behind HTTP, with authentication and a client, see [Server and client](../guides/server-and-client.md).
165
+
166
+ ## Related
167
+
168
+ - [Agents](./agent.md)
169
+ - [Outcomes and errors](./outcomes.md)
170
+ - [Permissions](./permissions.md)
171
+ - [Costs and budgets](./costs-and-budgets.md)
172
+ - [Observability](../guides/observability.md)