@mastra/server 1.79.0-alpha.10 → 1.79.0-alpha.11

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 (381) hide show
  1. package/dist/{a2a-CHBSYHxu.js → a2a-BqLB3McP.js} +17 -16
  2. package/dist/a2a-BqLB3McP.js.map +1 -0
  3. package/dist/{a2a-B465DD1u.cjs → a2a-Uood_0DN.cjs} +19 -18
  4. package/dist/a2a-Uood_0DN.cjs.map +1 -0
  5. package/dist/agent-builder-CuBD1tpv.cjs +728 -0
  6. package/dist/agent-builder-CuBD1tpv.cjs.map +1 -0
  7. package/dist/agent-builder-VhM8ADW-.js +627 -0
  8. package/dist/agent-builder-VhM8ADW-.js.map +1 -0
  9. package/dist/{agents-X1E7fW3p.js → agents-BHLTMBff.js} +2 -2
  10. package/dist/{agents-X1E7fW3p.js.map → agents-BHLTMBff.js.map} +1 -1
  11. package/dist/agents-BOWEUKyV.cjs +3127 -0
  12. package/dist/agents-BOWEUKyV.cjs.map +1 -0
  13. package/dist/agents-DRQ3ScbX.js +2828 -0
  14. package/dist/agents-DRQ3ScbX.js.map +1 -0
  15. package/dist/{agents-DoNMSCMt.cjs → agents-T-OIM9IK.cjs} +2 -2
  16. package/dist/{agents-DoNMSCMt.cjs.map → agents-T-OIM9IK.cjs.map} +1 -1
  17. package/dist/{api-schema-manifest-DUseI2VG.cjs → api-schema-manifest-A2qfi54Y.cjs} +4 -4
  18. package/dist/{api-schema-manifest-DUseI2VG.cjs.map → api-schema-manifest-A2qfi54Y.cjs.map} +1 -1
  19. package/dist/{api-schema-manifest-CWRIJP-B.js → api-schema-manifest-Dun5VMRT.js} +3 -3
  20. package/dist/{api-schema-manifest-CWRIJP-B.js.map → api-schema-manifest-Dun5VMRT.js.map} +1 -1
  21. package/dist/{background-tasks-CabImVak.cjs → background-tasks-B3VAKTJh.cjs} +3 -3
  22. package/dist/{background-tasks-CabImVak.cjs.map → background-tasks-B3VAKTJh.cjs.map} +1 -1
  23. package/dist/{background-tasks-oBaLtnCn.js → background-tasks-Du2zYOPl.js} +2 -2
  24. package/dist/{background-tasks-oBaLtnCn.js.map → background-tasks-Du2zYOPl.js.map} +1 -1
  25. package/dist/{builder-registry-DOkLe8ES.js → builder-registry-DLdu9bWH.js} +3 -3
  26. package/dist/{builder-registry-DOkLe8ES.js.map → builder-registry-DLdu9bWH.js.map} +1 -1
  27. package/dist/{builder-registry-D0frV8lQ.cjs → builder-registry-DaFAaMTf.cjs} +3 -3
  28. package/dist/{builder-registry-D0frV8lQ.cjs.map → builder-registry-DaFAaMTf.cjs.map} +1 -1
  29. package/dist/{channels-CBIopVWd.cjs → channels-BnVRmnzK.cjs} +6 -3
  30. package/dist/{channels-CBIopVWd.cjs.map → channels-BnVRmnzK.cjs.map} +1 -1
  31. package/dist/{channels-BOxgHvzI.js → channels-Db-4pXVZ.js} +6 -3
  32. package/dist/{channels-BOxgHvzI.js.map → channels-Db-4pXVZ.js.map} +1 -1
  33. package/dist/conversations-8BWryNlF.js +165 -0
  34. package/dist/conversations-8BWryNlF.js.map +1 -0
  35. package/dist/conversations-C5MkQBB8.cjs +194 -0
  36. package/dist/conversations-C5MkQBB8.cjs.map +1 -0
  37. package/dist/{conversations-Bj5TLNqF.cjs → conversations-DasqEDCF.cjs} +3 -3
  38. package/dist/{conversations-Bj5TLNqF.cjs.map → conversations-DasqEDCF.cjs.map} +1 -1
  39. package/dist/{dist-9c3PXXpk.cjs → dist-B-bEVWlJ.cjs} +4733 -1251
  40. package/dist/dist-B-bEVWlJ.cjs.map +1 -0
  41. package/dist/dist-B3kC8Yd0.cjs +3 -0
  42. package/dist/{dist-CQ3FSKT-.cjs → dist-B9ery9Zw.cjs} +38 -35
  43. package/dist/{dist-CQ3FSKT-.cjs.map → dist-B9ery9Zw.cjs.map} +1 -1
  44. package/dist/{dist-BxMmGD3n.js → dist-BBOnrL_A.js} +10 -12
  45. package/dist/{dist-BxMmGD3n.js.map → dist-BBOnrL_A.js.map} +1 -1
  46. package/dist/{dist-DOWsEmo6.js → dist-BIrQLUV9.js} +20 -20
  47. package/dist/{dist-DOWsEmo6.js.map → dist-BIrQLUV9.js.map} +1 -1
  48. package/dist/dist-BM9J-PTK.js +1 -0
  49. package/dist/{dist-DC1Pewf5.cjs → dist-Bo3GdQwf.cjs} +21 -21
  50. package/dist/{dist-DC1Pewf5.cjs.map → dist-Bo3GdQwf.cjs.map} +1 -1
  51. package/dist/{dist-BwYL7Ykb.js → dist-CREG82cy.js} +37 -34
  52. package/dist/{dist-BwYL7Ykb.js.map → dist-CREG82cy.js.map} +1 -1
  53. package/dist/{dist-rDRetJVY.cjs → dist-CeTLA-e5.cjs} +2 -3
  54. package/dist/{dist-rDRetJVY.cjs.map → dist-CeTLA-e5.cjs.map} +1 -1
  55. package/dist/{dist-CBRJax5e.js → dist-DLld1qjf.js} +25 -31
  56. package/dist/{dist-CBRJax5e.js.map → dist-DLld1qjf.js.map} +1 -1
  57. package/dist/{dist-B_bet8uz.js → dist-DjkPkAzV.js} +2 -3
  58. package/dist/{dist-B_bet8uz.js.map → dist-DjkPkAzV.js.map} +1 -1
  59. package/dist/{dist-UKEksCGq.cjs → dist-DsrJXwic.cjs} +11 -13
  60. package/dist/{dist-UKEksCGq.cjs.map → dist-DsrJXwic.cjs.map} +1 -1
  61. package/dist/{dist-DGCnbhNe.js → dist-k77XQGUn.js} +4493 -1043
  62. package/dist/dist-k77XQGUn.js.map +1 -0
  63. package/dist/{dist-3FPW9nVj.cjs → dist-lT2rqyY9.cjs} +26 -32
  64. package/dist/{dist-3FPW9nVj.cjs.map → dist-lT2rqyY9.cjs.map} +1 -1
  65. package/dist/docs/SKILL.md +1 -1
  66. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  67. package/dist/{dynamic-workflows-Rr_6ac1y.js → dynamic-workflows-CTUO0SFu.js} +3 -3
  68. package/dist/{dynamic-workflows-Rr_6ac1y.js.map → dynamic-workflows-CTUO0SFu.js.map} +1 -1
  69. package/dist/{dynamic-workflows-DXlkr-jK.cjs → dynamic-workflows-HwPX3mcf.cjs} +3 -3
  70. package/dist/{dynamic-workflows-DXlkr-jK.cjs.map → dynamic-workflows-HwPX3mcf.cjs.map} +1 -1
  71. package/dist/{editor-builder-BclcHxN6.cjs → editor-builder-BDtiWw0f.cjs} +2 -2
  72. package/dist/{editor-builder-BclcHxN6.cjs.map → editor-builder-BDtiWw0f.cjs.map} +1 -1
  73. package/dist/{editor-builder-D16kc1P6.js → editor-builder-ClFlGXoX.js} +4 -4
  74. package/dist/{editor-builder-D16kc1P6.js.map → editor-builder-ClFlGXoX.js.map} +1 -1
  75. package/dist/{editor-builder-s9WqPJgA.js → editor-builder-DnLCfqnY.js} +2 -2
  76. package/dist/{editor-builder-s9WqPJgA.js.map → editor-builder-DnLCfqnY.js.map} +1 -1
  77. package/dist/{editor-builder-DXHiPX1A.cjs → editor-builder-DtpP1FtW.cjs} +5 -5
  78. package/dist/{editor-builder-DXHiPX1A.cjs.map → editor-builder-DtpP1FtW.cjs.map} +1 -1
  79. package/dist/{helpers-ElhPeCSK.cjs → helpers-CAcEhq38.cjs} +21 -17
  80. package/dist/{helpers-ElhPeCSK.cjs.map → helpers-CAcEhq38.cjs.map} +1 -1
  81. package/dist/{helpers-DLhX1fqc.js → helpers-vrqddDd5.js} +21 -17
  82. package/dist/{helpers-DLhX1fqc.js.map → helpers-vrqddDd5.js.map} +1 -1
  83. package/dist/index.cjs +1 -1
  84. package/dist/logs-CiSw7r0s.cjs +119 -0
  85. package/dist/logs-CiSw7r0s.cjs.map +1 -0
  86. package/dist/logs-CxfPk-iL.js +96 -0
  87. package/dist/logs-CxfPk-iL.js.map +1 -0
  88. package/dist/mcp-BTdLh6E_.js +274 -0
  89. package/dist/mcp-BTdLh6E_.js.map +1 -0
  90. package/dist/mcp-BYqFR5q-.cjs +339 -0
  91. package/dist/mcp-BYqFR5q-.cjs.map +1 -0
  92. package/dist/memory-BHtTSzvJ.js +1739 -0
  93. package/dist/memory-BHtTSzvJ.js.map +1 -0
  94. package/dist/memory-CwwkVDh1.cjs +1906 -0
  95. package/dist/memory-CwwkVDh1.cjs.map +1 -0
  96. package/dist/observability-BBMCMeT-.cjs +502 -0
  97. package/dist/observability-BBMCMeT-.cjs.map +1 -0
  98. package/dist/observability-ZRgRcvoX.js +431 -0
  99. package/dist/observability-ZRgRcvoX.js.map +1 -0
  100. package/dist/{observability-new-endpoints-BU8JYPfh.js → observability-new-endpoints-fjoZzEtk.js} +10 -9
  101. package/dist/{observability-new-endpoints-BU8JYPfh.js.map → observability-new-endpoints-fjoZzEtk.js.map} +1 -1
  102. package/dist/{observability-new-endpoints-AMp9bnMV.cjs → observability-new-endpoints-tG3-odLa.cjs} +11 -10
  103. package/dist/observability-new-endpoints-tG3-odLa.cjs.map +1 -0
  104. package/dist/plans-CiPgWBhO.cjs +68 -0
  105. package/dist/plans-CiPgWBhO.cjs.map +1 -0
  106. package/dist/plans-DCepEY7n.js +57 -0
  107. package/dist/plans-DCepEY7n.js.map +1 -0
  108. package/dist/{probe-image-size-DBGjhUtJ.cjs → probe-image-size-Alv3gwKl.cjs} +194 -184
  109. package/dist/probe-image-size-Alv3gwKl.cjs.map +1 -0
  110. package/dist/{probe-image-size-Dmoxv93t.js → probe-image-size-BdfbUHxx.js} +158 -148
  111. package/dist/probe-image-size-BdfbUHxx.js.map +1 -0
  112. package/dist/responses-4FwMNxoJ.js +628 -0
  113. package/dist/responses-4FwMNxoJ.js.map +1 -0
  114. package/dist/responses-CCRijwDF.cjs +651 -0
  115. package/dist/responses-CCRijwDF.cjs.map +1 -0
  116. package/dist/{responses-CKNdSRkS.cjs → responses-CfcIc53b.cjs} +2 -2
  117. package/dist/{responses-CKNdSRkS.cjs.map → responses-CfcIc53b.cjs.map} +1 -1
  118. package/dist/{rolldown-runtime-Bd6kNlEP.cjs → rolldown-runtime-BwC_XMyb.cjs} +2 -2
  119. package/dist/{rolldown-runtime-maW3aOIk.js → rolldown-runtime-D3Hj5m0v.js} +2 -2
  120. package/dist/{route-builder-BNZs643f.cjs → route-builder-B2Qhhd7C.cjs} +52 -66
  121. package/dist/route-builder-B2Qhhd7C.cjs.map +1 -0
  122. package/dist/{route-builder-BfQYtclb.js → route-builder-CjkWxv4E.js} +51 -65
  123. package/dist/route-builder-CjkWxv4E.js.map +1 -0
  124. package/dist/{routes-Dl6_kWm7.js → routes-CKfXiwRc.js} +5 -3
  125. package/dist/routes-CKfXiwRc.js.map +1 -0
  126. package/dist/{routes-rwufkyUe.js → routes-D1cP2OeF.js} +26 -26
  127. package/dist/{routes-rwufkyUe.js.map → routes-D1cP2OeF.js.map} +1 -1
  128. package/dist/{routes-DPojsNf1.cjs → routes-bxG4x1MV.cjs} +199 -199
  129. package/dist/{routes-DPojsNf1.cjs.map → routes-bxG4x1MV.cjs.map} +1 -1
  130. package/dist/{routes-BULZI-PU.cjs → routes-jXksmX9G.cjs} +5 -3
  131. package/dist/routes-jXksmX9G.cjs.map +1 -0
  132. package/dist/{schedules-Bj-giFbc.cjs → schedules-CTTTCgbk.cjs} +3 -3
  133. package/dist/{schedules-Bj-giFbc.cjs.map → schedules-CTTTCgbk.cjs.map} +1 -1
  134. package/dist/{schedules-BQYgaz66.js → schedules-DXh37n6-.js} +2 -2
  135. package/dist/{schedules-BQYgaz66.js.map → schedules-DXh37n6-.js.map} +1 -1
  136. package/dist/{schema-e0VHpMt0-C0452jOk.cjs → schema-CzbEIyhE-20gGIWkz.cjs} +83 -88
  137. package/dist/schema-CzbEIyhE-20gGIWkz.cjs.map +1 -0
  138. package/dist/{schema-e0VHpMt0-CVP5Hnxy.js → schema-CzbEIyhE-BsMcj9Ws.js} +82 -87
  139. package/dist/schema-CzbEIyhE-BsMcj9Ws.js.map +1 -0
  140. package/dist/scores-D9UgETt_.js +288 -0
  141. package/dist/scores-D9UgETt_.js.map +1 -0
  142. package/dist/scores-DRdtS7NT.cjs +329 -0
  143. package/dist/scores-DRdtS7NT.cjs.map +1 -0
  144. package/dist/server/a2a/store.cjs +1 -1
  145. package/dist/server/auth/index.cjs +2 -2
  146. package/dist/server/auth/index.js +1 -1
  147. package/dist/server/browser-stream/index.cjs +9 -11
  148. package/dist/server/browser-stream/index.cjs.map +1 -1
  149. package/dist/server/browser-stream/index.js +8 -10
  150. package/dist/server/browser-stream/index.js.map +1 -1
  151. package/dist/server/handlers/a2a.cjs +2 -2
  152. package/dist/server/handlers/a2a.js +1 -2
  153. package/dist/server/handlers/agent-builder.cjs +18 -648
  154. package/dist/server/handlers/agent-builder.js +1 -627
  155. package/dist/server/handlers/agent-controller.cjs +5 -5
  156. package/dist/server/handlers/agent-controller.cjs.map +1 -1
  157. package/dist/server/handlers/agent-controller.js +11 -9
  158. package/dist/server/handlers/agent-controller.js.map +1 -1
  159. package/dist/server/handlers/agent-versions.cjs +15 -8
  160. package/dist/server/handlers/agent-versions.cjs.map +1 -1
  161. package/dist/server/handlers/agent-versions.js +14 -7
  162. package/dist/server/handlers/agent-versions.js.map +1 -1
  163. package/dist/server/handlers/agents.cjs +51 -2860
  164. package/dist/server/handlers/agents.js +1 -2806
  165. package/dist/server/handlers/auth.cjs +14 -12
  166. package/dist/server/handlers/auth.cjs.map +1 -1
  167. package/dist/server/handlers/auth.js +20 -16
  168. package/dist/server/handlers/auth.js.map +1 -1
  169. package/dist/server/handlers/author-enrichment.cjs +1 -1
  170. package/dist/server/handlers/authorship.cjs +1 -1
  171. package/dist/server/handlers/authorship.cjs.map +1 -1
  172. package/dist/server/handlers/background-tasks.cjs +2 -2
  173. package/dist/server/handlers/background-tasks.js +1 -2
  174. package/dist/server/handlers/builder-registry.cjs +2 -2
  175. package/dist/server/handlers/builder-registry.js +1 -2
  176. package/dist/server/handlers/channels.cjs +2 -2
  177. package/dist/server/handlers/channels.js +1 -2
  178. package/dist/server/handlers/conversations.cjs +6 -171
  179. package/dist/server/handlers/conversations.js +1 -162
  180. package/dist/server/handlers/datasets.cjs +2 -2
  181. package/dist/server/handlers/datasets.cjs.map +1 -1
  182. package/dist/server/handlers/datasets.js +1 -1
  183. package/dist/server/handlers/dynamic-workflows.cjs +2 -2
  184. package/dist/server/handlers/dynamic-workflows.js +1 -2
  185. package/dist/server/handlers/editor-builder.cjs +2 -2
  186. package/dist/server/handlers/editor-builder.js +1 -2
  187. package/dist/server/handlers/error.cjs +18 -13
  188. package/dist/server/handlers/error.cjs.map +1 -1
  189. package/dist/server/handlers/error.js +17 -12
  190. package/dist/server/handlers/error.js.map +1 -1
  191. package/dist/server/handlers/favorites-enrichment.cjs +2 -2
  192. package/dist/server/handlers/favorites-enrichment.js +1 -1
  193. package/dist/server/handlers/gateway-memory-client.cjs +1 -1
  194. package/dist/server/handlers/logs.cjs +5 -104
  195. package/dist/server/handlers/logs.js +1 -96
  196. package/dist/server/handlers/mcp-client-versions.cjs +15 -8
  197. package/dist/server/handlers/mcp-client-versions.cjs.map +1 -1
  198. package/dist/server/handlers/mcp-client-versions.js +14 -7
  199. package/dist/server/handlers/mcp-client-versions.js.map +1 -1
  200. package/dist/server/handlers/mcp.cjs +12 -289
  201. package/dist/server/handlers/mcp.js +1 -274
  202. package/dist/server/handlers/memory.cjs +29 -1763
  203. package/dist/server/handlers/memory.js +1 -1731
  204. package/dist/server/handlers/observability-list-query-schemas.cjs +1 -1
  205. package/dist/server/handlers/observability-new-endpoints.cjs +2 -2
  206. package/dist/server/handlers/observability-new-endpoints.js +1 -2
  207. package/dist/server/handlers/observability-shared.cjs +2 -2
  208. package/dist/server/handlers/observability-shared.js +1 -1
  209. package/dist/server/handlers/observability-storage-schemas.cjs +1 -1
  210. package/dist/server/handlers/observability.cjs +14 -445
  211. package/dist/server/handlers/observability.js +3 -429
  212. package/dist/server/handlers/plans.cjs +3 -63
  213. package/dist/server/handlers/plans.js +1 -57
  214. package/dist/server/handlers/processor-providers.cjs +2 -2
  215. package/dist/server/handlers/processor-providers.cjs.map +1 -1
  216. package/dist/server/handlers/processor-providers.js +1 -1
  217. package/dist/server/handlers/processors.cjs +13 -15
  218. package/dist/server/handlers/processors.cjs.map +1 -1
  219. package/dist/server/handlers/processors.js +12 -14
  220. package/dist/server/handlers/processors.js.map +1 -1
  221. package/dist/server/handlers/prompt-block-versions.cjs +15 -8
  222. package/dist/server/handlers/prompt-block-versions.cjs.map +1 -1
  223. package/dist/server/handlers/prompt-block-versions.js +14 -7
  224. package/dist/server/handlers/prompt-block-versions.js.map +1 -1
  225. package/dist/server/handlers/responses.adapter.cjs +1 -1
  226. package/dist/server/handlers/responses.adapter.cjs.map +1 -1
  227. package/dist/server/handlers/responses.cjs +5 -632
  228. package/dist/server/handlers/responses.js +1 -624
  229. package/dist/server/handlers/responses.storage.cjs +2 -2
  230. package/dist/server/handlers/schedules-workflows-shim.cjs +1 -1
  231. package/dist/server/handlers/schedules.cjs +2 -2
  232. package/dist/server/handlers/schedules.js +1 -2
  233. package/dist/server/handlers/scorer-versions.cjs +15 -8
  234. package/dist/server/handlers/scorer-versions.cjs.map +1 -1
  235. package/dist/server/handlers/scorer-versions.js +14 -7
  236. package/dist/server/handlers/scorer-versions.js.map +1 -1
  237. package/dist/server/handlers/scores.cjs +8 -299
  238. package/dist/server/handlers/scores.js +1 -288
  239. package/dist/server/handlers/skills-sh-shared.cjs +1 -1
  240. package/dist/server/handlers/stored-agent-favorites.cjs +4 -4
  241. package/dist/server/handlers/stored-agent-favorites.js +3 -3
  242. package/dist/server/handlers/stored-agents.cjs +19 -13
  243. package/dist/server/handlers/stored-agents.cjs.map +1 -1
  244. package/dist/server/handlers/stored-agents.js +18 -12
  245. package/dist/server/handlers/stored-agents.js.map +1 -1
  246. package/dist/server/handlers/stored-mcp-clients.cjs +8 -6
  247. package/dist/server/handlers/stored-mcp-clients.cjs.map +1 -1
  248. package/dist/server/handlers/stored-mcp-clients.js +7 -5
  249. package/dist/server/handlers/stored-mcp-clients.js.map +1 -1
  250. package/dist/server/handlers/stored-prompt-blocks.cjs +3 -3
  251. package/dist/server/handlers/stored-prompt-blocks.js +2 -2
  252. package/dist/server/handlers/stored-scorers.cjs +3 -3
  253. package/dist/server/handlers/stored-scorers.js +2 -2
  254. package/dist/server/handlers/stored-skill-favorites.cjs +4 -4
  255. package/dist/server/handlers/stored-skill-favorites.js +3 -3
  256. package/dist/server/handlers/stored-skills.cjs +6 -5
  257. package/dist/server/handlers/stored-skills.cjs.map +1 -1
  258. package/dist/server/handlers/stored-skills.js +5 -4
  259. package/dist/server/handlers/stored-skills.js.map +1 -1
  260. package/dist/server/handlers/stored-workspaces.cjs +3 -3
  261. package/dist/server/handlers/stored-workspaces.js +2 -2
  262. package/dist/server/handlers/system.cjs +3 -3
  263. package/dist/server/handlers/system.cjs.map +1 -1
  264. package/dist/server/handlers/system.js +2 -2
  265. package/dist/server/handlers/test-utils.cjs +1 -1
  266. package/dist/server/handlers/tool-providers.cjs +2 -2
  267. package/dist/server/handlers/tool-providers.js +1 -1
  268. package/dist/server/handlers/tool-schema-overrides.cjs +1 -1
  269. package/dist/server/handlers/tools.cjs +7 -267
  270. package/dist/server/handlers/tools.js +1 -257
  271. package/dist/server/handlers/utils.cjs +2 -2
  272. package/dist/server/handlers/utils.js +1 -2
  273. package/dist/server/handlers/validate-agent-instructions.cjs +2 -2
  274. package/dist/server/handlers/validate-agent-instructions.js +1 -1
  275. package/dist/server/handlers/validate-avatar.cjs +2 -2
  276. package/dist/server/handlers/validate-avatar.cjs.map +1 -1
  277. package/dist/server/handlers/validate-avatar.js +1 -1
  278. package/dist/server/handlers/validate-avatar.js.map +1 -1
  279. package/dist/server/handlers/vector.cjs +17 -334
  280. package/dist/server/handlers/vector.js +1 -314
  281. package/dist/server/handlers/version-helpers.cjs +1 -1
  282. package/dist/server/handlers/voice.cjs +9 -35
  283. package/dist/server/handlers/voice.js +1 -23
  284. package/dist/server/handlers/workflow-builder.cjs +2 -2
  285. package/dist/server/handlers/workflow-builder.js +1 -2
  286. package/dist/server/handlers/workflows.cjs +30 -1293
  287. package/dist/server/handlers/workflows.js +1 -1257
  288. package/dist/server/handlers/workspace.cjs +27 -1176
  289. package/dist/server/handlers/workspace.js +1 -1146
  290. package/dist/server/handlers.cjs +33 -33
  291. package/dist/server/handlers.js +17 -17
  292. package/dist/server/schemas/index.cjs +6 -6
  293. package/dist/server/schemas/index.js +3 -3
  294. package/dist/server/server-adapter/index.cjs +5 -5
  295. package/dist/server/server-adapter/index.cjs.map +1 -1
  296. package/dist/server/server-adapter/index.js +4 -4
  297. package/dist/server/server-adapter/index.js.map +1 -1
  298. package/dist/tools-CmFSfDMn.js +256 -0
  299. package/dist/tools-CmFSfDMn.js.map +1 -0
  300. package/dist/tools-SPJtxG9N.cjs +291 -0
  301. package/dist/tools-SPJtxG9N.cjs.map +1 -0
  302. package/dist/{utils-DCgeTrq2.cjs → utils-CF76qzZR.cjs} +12 -17
  303. package/dist/{utils-DCgeTrq2.cjs.map → utils-CF76qzZR.cjs.map} +1 -1
  304. package/dist/{utils-DCAUeb6M.js → utils-aoLN3Wfi.js} +11 -16
  305. package/dist/{utils-DCAUeb6M.js.map → utils-aoLN3Wfi.js.map} +1 -1
  306. package/dist/{utils-Du-EpvDs.cjs → utils-dDLIDg8O.cjs} +2 -2
  307. package/dist/{utils-Du-EpvDs.cjs.map → utils-dDLIDg8O.cjs.map} +1 -1
  308. package/dist/vector-BKDD1kwc.cjs +409 -0
  309. package/dist/vector-BKDD1kwc.cjs.map +1 -0
  310. package/dist/vector-TWv4t-4g.js +314 -0
  311. package/dist/vector-TWv4t-4g.js.map +1 -0
  312. package/dist/voice-BnGwlZ75.cjs +70 -0
  313. package/dist/voice-BnGwlZ75.cjs.map +1 -0
  314. package/dist/voice-DjG8tBAD.js +23 -0
  315. package/dist/voice-DjG8tBAD.js.map +1 -0
  316. package/dist/{workflow-builder-Brj3IArM.cjs → workflow-builder-C9-8ZOWF.cjs} +5 -5
  317. package/dist/{workflow-builder-Brj3IArM.cjs.map → workflow-builder-C9-8ZOWF.cjs.map} +1 -1
  318. package/dist/{workflow-builder-DOa1Vx6w.js → workflow-builder-CjlLoQvo.js} +10 -8
  319. package/dist/{workflow-builder-DOa1Vx6w.js.map → workflow-builder-CjlLoQvo.js.map} +1 -1
  320. package/dist/workflows-DjqeJcdJ.cjs +1446 -0
  321. package/dist/workflows-DjqeJcdJ.cjs.map +1 -0
  322. package/dist/workflows-bb-otd2o.js +1273 -0
  323. package/dist/workflows-bb-otd2o.js.map +1 -0
  324. package/dist/workspace-B6kzp-bo.js +1154 -0
  325. package/dist/workspace-B6kzp-bo.js.map +1 -0
  326. package/dist/workspace-COKR1SxH.cjs +1309 -0
  327. package/dist/workspace-COKR1SxH.cjs.map +1 -0
  328. package/package.json +4 -4
  329. package/dist/a2a-B465DD1u.cjs.map +0 -1
  330. package/dist/a2a-CHBSYHxu.js.map +0 -1
  331. package/dist/dist-9c3PXXpk.cjs.map +0 -1
  332. package/dist/dist-B5OwHWTo.cjs +0 -2294
  333. package/dist/dist-B5OwHWTo.cjs.map +0 -1
  334. package/dist/dist-DGCnbhNe.js.map +0 -1
  335. package/dist/dist-DcoIg_tp.js +0 -2293
  336. package/dist/dist-DcoIg_tp.js.map +0 -1
  337. package/dist/observability-new-endpoints-AMp9bnMV.cjs.map +0 -1
  338. package/dist/probe-image-size-DBGjhUtJ.cjs.map +0 -1
  339. package/dist/probe-image-size-Dmoxv93t.js.map +0 -1
  340. package/dist/route-builder-BNZs643f.cjs.map +0 -1
  341. package/dist/route-builder-BfQYtclb.js.map +0 -1
  342. package/dist/routes-BULZI-PU.cjs.map +0 -1
  343. package/dist/routes-Dl6_kWm7.js.map +0 -1
  344. package/dist/schema-Drf2W04o.js +0 -2
  345. package/dist/schema-EQanefYq.cjs +0 -1
  346. package/dist/schema-e0VHpMt0-C0452jOk.cjs.map +0 -1
  347. package/dist/schema-e0VHpMt0-CVP5Hnxy.js.map +0 -1
  348. package/dist/server/handlers/agent-builder.cjs.map +0 -1
  349. package/dist/server/handlers/agent-builder.js.map +0 -1
  350. package/dist/server/handlers/agents.cjs.map +0 -1
  351. package/dist/server/handlers/agents.js.map +0 -1
  352. package/dist/server/handlers/conversations.cjs.map +0 -1
  353. package/dist/server/handlers/conversations.js.map +0 -1
  354. package/dist/server/handlers/logs.cjs.map +0 -1
  355. package/dist/server/handlers/logs.js.map +0 -1
  356. package/dist/server/handlers/mcp.cjs.map +0 -1
  357. package/dist/server/handlers/mcp.js.map +0 -1
  358. package/dist/server/handlers/memory.cjs.map +0 -1
  359. package/dist/server/handlers/memory.js.map +0 -1
  360. package/dist/server/handlers/observability.cjs.map +0 -1
  361. package/dist/server/handlers/observability.js.map +0 -1
  362. package/dist/server/handlers/plans.cjs.map +0 -1
  363. package/dist/server/handlers/plans.js.map +0 -1
  364. package/dist/server/handlers/responses.cjs.map +0 -1
  365. package/dist/server/handlers/responses.js.map +0 -1
  366. package/dist/server/handlers/scores.cjs.map +0 -1
  367. package/dist/server/handlers/scores.js.map +0 -1
  368. package/dist/server/handlers/tools.cjs.map +0 -1
  369. package/dist/server/handlers/tools.js.map +0 -1
  370. package/dist/server/handlers/vector.cjs.map +0 -1
  371. package/dist/server/handlers/vector.js.map +0 -1
  372. package/dist/server/handlers/voice.cjs.map +0 -1
  373. package/dist/server/handlers/voice.js.map +0 -1
  374. package/dist/server/handlers/workflows.cjs.map +0 -1
  375. package/dist/server/handlers/workflows.js.map +0 -1
  376. package/dist/server/handlers/workspace.cjs.map +0 -1
  377. package/dist/server/handlers/workspace.js.map +0 -1
  378. package/dist/sync-Ai_ZDz7U.js +0 -1700
  379. package/dist/sync-Ai_ZDz7U.js.map +0 -1
  380. package/dist/sync-BrO5MtSe.cjs +0 -1729
  381. package/dist/sync-BrO5MtSe.cjs.map +0 -1
@@ -1,1257 +1 @@
1
- import { r as __exportAll } from "../../rolldown-runtime-maW3aOIk.js";
2
- import { t as HTTPException } from "../../http-exception-CyfxZB6W.js";
3
- import { o as optionalRunIdSchema, u as runIdSchema } from "../../common-Y30XtCyr.js";
4
- import { _ as workflowRunCountsResponseSchema, a as observeWorkflowQuerySchema, b as workflowRunResultSchema, d as streamWorkflowBodySchema, f as timeTravelBodySchema, g as workflowInfoSchema, h as workflowIdPathParams, i as listWorkflowsResponseSchema, l as startAsyncWorkflowBodySchema, m as workflowExecutionResultSchema, n as createWorkflowRunResponseSchema, o as restartBodySchema, p as workflowControlResponseSchema, r as listWorkflowRunsQuerySchema, s as resumeBodySchema, t as createWorkflowRunBodySchema, v as workflowRunPathParams, x as workflowRunsResponseSchema, y as workflowRunResultQuerySchema } from "../../workflows-Dcx4Ib0t.js";
5
- import { Y as streamResponseSchema } from "../../agents-X1E7fW3p.js";
6
- import { n as createRoute } from "../../route-builder-BfQYtclb.js";
7
- import { a as getWorkflowInfo, t as WorkflowRegistry } from "../../utils-DCAUeb6M.js";
8
- import { handleError } from "./error.js";
9
- import { g as MastraFGAPermissions, i as getEffectiveResourceId, m as validateRunOwnership, o as getPublicWorkflowById } from "../../utils-BBJlS81s.js";
10
- import { z } from "zod/v4";
11
- import { createReplayStream } from "@mastra/core/stream";
12
- //#region src/server/handlers/workflows.ts
13
- var workflows_exports = /* @__PURE__ */ __exportAll({
14
- CANCEL_WORKFLOW_RUN_ROUTE: () => CANCEL_WORKFLOW_RUN_ROUTE,
15
- CREATE_WORKFLOW_RUN_ROUTE: () => CREATE_WORKFLOW_RUN_ROUTE,
16
- DELETE_WORKFLOW_RUN_BY_ID_ROUTE: () => DELETE_WORKFLOW_RUN_BY_ID_ROUTE,
17
- EXECUTE_WORKFLOW_STEP_ROUTE: () => EXECUTE_WORKFLOW_STEP_ROUTE,
18
- GET_WORKFLOW_BY_ID_ROUTE: () => GET_WORKFLOW_BY_ID_ROUTE,
19
- GET_WORKFLOW_RUN_BY_ID_ROUTE: () => GET_WORKFLOW_RUN_BY_ID_ROUTE,
20
- LIST_WORKFLOWS_ROUTE: () => LIST_WORKFLOWS_ROUTE,
21
- LIST_WORKFLOW_RUNS_ROUTE: () => LIST_WORKFLOW_RUNS_ROUTE,
22
- LIST_WORKFLOW_RUN_COUNTS_ROUTE: () => LIST_WORKFLOW_RUN_COUNTS_ROUTE,
23
- OBSERVE_STREAM_LEGACY_WORKFLOW_ROUTE: () => OBSERVE_STREAM_LEGACY_WORKFLOW_ROUTE,
24
- OBSERVE_STREAM_WORKFLOW_ROUTE: () => OBSERVE_STREAM_WORKFLOW_ROUTE,
25
- RECEIVE_WORKFLOW_EVENT_ROUTE: () => RECEIVE_WORKFLOW_EVENT_ROUTE,
26
- RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ASYNC_ROUTE: () => RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ASYNC_ROUTE,
27
- RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ROUTE: () => RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ROUTE,
28
- RESTART_ASYNC_WORKFLOW_ROUTE: () => RESTART_ASYNC_WORKFLOW_ROUTE,
29
- RESTART_WORKFLOW_ROUTE: () => RESTART_WORKFLOW_ROUTE,
30
- RESUME_ASYNC_WORKFLOW_ROUTE: () => RESUME_ASYNC_WORKFLOW_ROUTE,
31
- RESUME_NO_WAIT_WORKFLOW_ROUTE: () => RESUME_NO_WAIT_WORKFLOW_ROUTE,
32
- RESUME_STREAM_WORKFLOW_ROUTE: () => RESUME_STREAM_WORKFLOW_ROUTE,
33
- RESUME_WORKFLOW_ROUTE: () => RESUME_WORKFLOW_ROUTE,
34
- START_ASYNC_WORKFLOW_ROUTE: () => START_ASYNC_WORKFLOW_ROUTE,
35
- START_WORKFLOW_RUN_ROUTE: () => START_WORKFLOW_RUN_ROUTE,
36
- STREAM_LEGACY_WORKFLOW_ROUTE: () => STREAM_LEGACY_WORKFLOW_ROUTE,
37
- STREAM_WORKFLOW_ROUTE: () => STREAM_WORKFLOW_ROUTE,
38
- TIME_TRAVEL_ASYNC_WORKFLOW_ROUTE: () => TIME_TRAVEL_ASYNC_WORKFLOW_ROUTE,
39
- TIME_TRAVEL_STREAM_WORKFLOW_ROUTE: () => TIME_TRAVEL_STREAM_WORKFLOW_ROUTE,
40
- TIME_TRAVEL_WORKFLOW_ROUTE: () => TIME_TRAVEL_WORKFLOW_ROUTE,
41
- __setWorkflowRunCountsNow: () => __setWorkflowRunCountsNow
42
- });
43
- /**
44
- * Statuses a run cannot come back from. Streaming one of these runIds again would
45
- * start a fresh execution under the same runId and overwrite its stored snapshot —
46
- * the in-memory de-dupe that protects concurrent streams only covers runs still held
47
- * in the workflow's run map, and a finished run has already been dropped from it.
48
- */
49
- const TERMINAL_RUN_STATUSES = [
50
- "success",
51
- "failed",
52
- "canceled",
53
- "tripwire"
54
- ];
55
- /**
56
- * Runs whose chunks are already being written to the cache in this process,
57
- * keyed by runId. A run has exactly one writer: without this, two concurrent
58
- * requests for the same runId each cache every chunk and the replayed history
59
- * comes back duplicated.
60
- */
61
- const activeRunStreamCachers = /* @__PURE__ */ new Set();
62
- /**
63
- * Cache a run's chunks for later replay and return the stream to hand the client.
64
- *
65
- * The cached history belongs to the run, not to whoever happens to be watching,
66
- * so the caching side is driven by its own reader rather than by the client's
67
- * consumption. If the client disconnects mid-run its branch is cancelled while
68
- * this reader keeps draining, so `/observe` still replays a complete history —
69
- * the failure that makes reconnection necessary is exactly the one the cache has
70
- * to survive. Chunks buffer in the tee while a client lags, bounded by the run's
71
- * own length.
72
- */
73
- function cacheRunStream({ cache, runId, source }) {
74
- if (activeRunStreamCachers.has(runId)) return source;
75
- const [toCache, toClient] = source.tee();
76
- activeRunStreamCachers.add(runId);
77
- (async () => {
78
- const reader = toCache.getReader();
79
- try {
80
- while (true) {
81
- const { done, value } = await reader.read();
82
- if (done) break;
83
- await cache.listPush(runId, value).catch(() => {});
84
- }
85
- } catch {} finally {
86
- reader.releaseLock();
87
- activeRunStreamCachers.delete(runId);
88
- }
89
- })();
90
- return toClient;
91
- }
92
- async function listWorkflowsFromSystem({ mastra, workflowId }) {
93
- const logger = mastra.getLogger();
94
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
95
- let workflow;
96
- workflow = WorkflowRegistry.getWorkflow(workflowId);
97
- if (!workflow) workflow = getPublicWorkflowById(mastra, workflowId);
98
- if (!workflow) {
99
- logger.debug("Workflow not found, searching agents for workflow", { workflowId });
100
- const agents = mastra.listAgents();
101
- if (Object.keys(agents || {}).length) for (const [_, agent] of Object.entries(agents)) try {
102
- const workflows = await agent.listWorkflows();
103
- if (workflows[workflowId]) {
104
- workflow = workflows[workflowId];
105
- break;
106
- }
107
- } catch (error) {
108
- logger.debug("Error getting workflow from agent", error);
109
- }
110
- }
111
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
112
- return { workflow };
113
- }
114
- const LIST_WORKFLOWS_ROUTE = createRoute({
115
- method: "GET",
116
- path: "/workflows",
117
- responseType: "json",
118
- queryParamSchema: z.object({ partial: z.string().optional() }),
119
- responseSchema: listWorkflowsResponseSchema,
120
- summary: "List all workflows",
121
- description: "Returns a list of all available workflows in the system",
122
- tags: ["Workflows"],
123
- requiresAuth: true,
124
- handler: (async ({ mastra, partial, requestContext }) => {
125
- try {
126
- const workflows = mastra.listWorkflows({ serialized: false });
127
- const isPartial = partial === "true";
128
- const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
129
- acc[key] = getWorkflowInfo(workflow, isPartial);
130
- return acc;
131
- }, {});
132
- const fgaProvider = mastra.getServer?.()?.fga;
133
- const user = requestContext?.get("user");
134
- if (fgaProvider) {
135
- if (!user) return {};
136
- const workflowList = Object.entries(_workflows).map(([id, w]) => ({
137
- id,
138
- ...w
139
- }));
140
- const accessible = await fgaProvider.filterAccessible(user, workflowList, "workflow", MastraFGAPermissions.WORKFLOWS_READ);
141
- const accessibleSet = new Set(accessible.map((w) => w.id));
142
- for (const id of Object.keys(_workflows)) if (!accessibleSet.has(id)) delete _workflows[id];
143
- }
144
- return _workflows;
145
- } catch (error) {
146
- return handleError(error, "Error getting workflows");
147
- }
148
- })
149
- });
150
- const RUN_COUNTS_CACHE_TTL_MS = 5e3;
151
- const runCountsCache = /* @__PURE__ */ new WeakMap();
152
- let runCountsNow = () => Date.now();
153
- /** Test seam — lets TTL expiry be tested without wall-clock waits. */
154
- function __setWorkflowRunCountsNow(now) {
155
- runCountsNow = now ?? (() => Date.now());
156
- }
157
- const LIST_WORKFLOW_RUN_COUNTS_ROUTE = createRoute({
158
- method: "GET",
159
- path: "/workflows/run-counts",
160
- responseType: "json",
161
- responseSchema: workflowRunCountsResponseSchema,
162
- summary: "List workflow run counts",
163
- description: "Returns per-workflow counts of currently running and suspended (awaiting resume) runs, keyed by the workflow registry key used in the Mastra config",
164
- tags: ["Workflows"],
165
- requiresAuth: true,
166
- handler: (async ({ mastra, requestContext }) => {
167
- try {
168
- const fgaProvider = mastra.getServer?.()?.fga;
169
- const user = requestContext?.get("user");
170
- if (fgaProvider && !user) return {};
171
- const workflows = mastra.listWorkflows({ serialized: false });
172
- const counts = {};
173
- const workflowIdToRegistryKey = /* @__PURE__ */ new Map();
174
- for (const [registryKey, workflow] of Object.entries(workflows)) {
175
- counts[registryKey] = {
176
- running: 0,
177
- suspended: 0
178
- };
179
- workflowIdToRegistryKey.set(workflow.id, registryKey);
180
- }
181
- const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
182
- const cacheable = !fgaProvider && !effectiveResourceId;
183
- if (cacheable) {
184
- const cached = runCountsCache.get(mastra);
185
- if (cached && runCountsNow() - cached.at < RUN_COUNTS_CACHE_TTL_MS) return cached.value;
186
- }
187
- const storage = mastra.getStorage();
188
- const workflowsStore = storage ? await storage.getStore("workflows") : void 0;
189
- if (workflowsStore) {
190
- const [running, suspended] = await Promise.all([workflowsStore.listWorkflowRuns({
191
- status: "running",
192
- resourceId: effectiveResourceId
193
- }), workflowsStore.listWorkflowRuns({
194
- status: "suspended",
195
- resourceId: effectiveResourceId
196
- })]);
197
- for (const run of running.runs) {
198
- const registryKey = workflowIdToRegistryKey.get(run.workflowName);
199
- const entry = registryKey ? counts[registryKey] : void 0;
200
- if (entry) entry.running++;
201
- }
202
- for (const run of suspended.runs) {
203
- const registryKey = workflowIdToRegistryKey.get(run.workflowName);
204
- const entry = registryKey ? counts[registryKey] : void 0;
205
- if (entry) entry.suspended++;
206
- }
207
- }
208
- if (fgaProvider) {
209
- const workflowList = Object.keys(counts).map((id) => ({ id }));
210
- const accessible = await fgaProvider.filterAccessible(user, workflowList, "workflow", MastraFGAPermissions.WORKFLOWS_READ);
211
- const accessibleSet = new Set(accessible.map((w) => w.id));
212
- for (const id of Object.keys(counts)) if (!accessibleSet.has(id)) delete counts[id];
213
- return counts;
214
- }
215
- if (cacheable) runCountsCache.set(mastra, {
216
- at: runCountsNow(),
217
- value: counts
218
- });
219
- return counts;
220
- } catch (error) {
221
- return handleError(error, "Error getting workflow run counts");
222
- }
223
- })
224
- });
225
- const GET_WORKFLOW_BY_ID_ROUTE = createRoute({
226
- method: "GET",
227
- path: "/workflows/:workflowId",
228
- responseType: "json",
229
- pathParamSchema: workflowIdPathParams,
230
- responseSchema: workflowInfoSchema,
231
- summary: "Get workflow by ID",
232
- description: "Returns details for a specific workflow",
233
- tags: ["Workflows"],
234
- requiresAuth: true,
235
- handler: (async ({ mastra, workflowId }) => {
236
- try {
237
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
238
- const { workflow } = await listWorkflowsFromSystem({
239
- mastra,
240
- workflowId
241
- });
242
- return getWorkflowInfo(workflow, false);
243
- } catch (error) {
244
- return handleError(error, "Error getting workflow");
245
- }
246
- })
247
- });
248
- const LIST_WORKFLOW_RUNS_ROUTE = createRoute({
249
- method: "GET",
250
- path: "/workflows/:workflowId/runs",
251
- responseType: "json",
252
- pathParamSchema: workflowIdPathParams,
253
- queryParamSchema: listWorkflowRunsQuerySchema,
254
- responseSchema: workflowRunsResponseSchema,
255
- summary: "List workflow runs",
256
- description: "Returns a paginated list of execution runs for the specified workflow",
257
- tags: ["Workflows"],
258
- requiresAuth: true,
259
- handler: async ({ mastra, workflowId, fromDate, toDate, page, perPage, limit, offset, resourceId, status, summary, requestContext }) => {
260
- try {
261
- const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
262
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
263
- let finalPage = page;
264
- let finalPerPage = perPage;
265
- if (finalPerPage === void 0 && limit !== void 0) finalPerPage = limit;
266
- if (finalPage === void 0 && offset !== void 0 && finalPerPage !== void 0 && finalPerPage > 0) finalPage = Math.floor(offset / finalPerPage);
267
- if (finalPerPage !== void 0 && (typeof finalPerPage !== "number" || !Number.isInteger(finalPerPage) || finalPerPage <= 0)) throw new HTTPException(400, { message: "perPage must be a positive integer" });
268
- if (finalPage !== void 0 && (!Number.isInteger(finalPage) || finalPage < 0)) throw new HTTPException(400, { message: "page must be a non-negative integer" });
269
- const { workflow } = await listWorkflowsFromSystem({
270
- mastra,
271
- workflowId
272
- });
273
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
274
- const workflowRuns = await workflow.listWorkflowRuns({
275
- fromDate: fromDate ? typeof fromDate === "string" ? new Date(fromDate) : fromDate : void 0,
276
- toDate: toDate ? typeof toDate === "string" ? new Date(toDate) : toDate : void 0,
277
- perPage: finalPerPage,
278
- page: finalPage,
279
- resourceId: effectiveResourceId,
280
- status,
281
- ...summary ? { summary: true } : {}
282
- }) || {
283
- runs: [],
284
- total: 0
285
- };
286
- if (summary) return {
287
- ...workflowRuns,
288
- runs: workflowRuns.runs.map((run) => ({
289
- ...run,
290
- snapshot: toSummarySnapshot(run.snapshot)
291
- }))
292
- };
293
- return workflowRuns;
294
- } catch (error) {
295
- return handleError(error, "Error getting workflow runs");
296
- }
297
- }
298
- });
299
- function toSummarySnapshot(snapshot) {
300
- let parsed;
301
- if (typeof snapshot === "string") try {
302
- parsed = JSON.parse(snapshot);
303
- } catch {
304
- return "";
305
- }
306
- else parsed = snapshot;
307
- if (!parsed || typeof parsed !== "object") return "";
308
- const { status, timestamp } = parsed;
309
- return {
310
- status,
311
- timestamp
312
- };
313
- }
314
- const GET_WORKFLOW_RUN_BY_ID_ROUTE = createRoute({
315
- method: "GET",
316
- path: "/workflows/:workflowId/runs/:runId",
317
- responseType: "json",
318
- pathParamSchema: workflowRunPathParams,
319
- queryParamSchema: workflowRunResultQuerySchema,
320
- responseSchema: workflowRunResultSchema,
321
- summary: "Get workflow run by ID",
322
- description: "Returns a workflow run with metadata and processed execution state. Use the fields query parameter to reduce payload size by requesting only specific fields (e.g., ?fields=result,steps). Available fields: result, error, payload, steps, activeStepsPath, serializedStepGraph. Metadata fields (runId, workflowName, resourceId, createdAt, updatedAt) and status are always included.",
323
- tags: ["Workflows"],
324
- requiresAuth: true,
325
- handler: async ({ mastra, workflowId, runId, fields, withNestedWorkflows, requestContext }) => {
326
- try {
327
- const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
328
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
329
- if (!runId) throw new HTTPException(400, { message: "Run ID is required" });
330
- const { workflow } = await listWorkflowsFromSystem({
331
- mastra,
332
- workflowId
333
- });
334
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
335
- const fieldList = fields ? fields.split(",").map((f) => f.trim()) : void 0;
336
- const run = await workflow.getWorkflowRunById(runId, {
337
- withNestedWorkflows: withNestedWorkflows !== "false",
338
- fields: fieldList
339
- });
340
- if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
341
- await validateRunOwnership(run, effectiveResourceId, mastra);
342
- return run;
343
- } catch (error) {
344
- return handleError(error, "Error getting workflow run");
345
- }
346
- }
347
- });
348
- const DELETE_WORKFLOW_RUN_BY_ID_ROUTE = createRoute({
349
- method: "DELETE",
350
- path: "/workflows/:workflowId/runs/:runId",
351
- responseType: "json",
352
- pathParamSchema: workflowRunPathParams,
353
- responseSchema: workflowControlResponseSchema,
354
- summary: "Delete workflow run by ID",
355
- description: "Deletes a specific workflow run by ID",
356
- tags: ["Workflows"],
357
- requiresAuth: true,
358
- handler: async ({ mastra, workflowId, runId, requestContext }) => {
359
- try {
360
- const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
361
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
362
- if (!runId) throw new HTTPException(400, { message: "Run ID is required" });
363
- const { workflow } = await listWorkflowsFromSystem({
364
- mastra,
365
- workflowId
366
- });
367
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
368
- const run = await workflow.getWorkflowRunById(runId);
369
- if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
370
- await validateRunOwnership(run, effectiveResourceId, mastra);
371
- await workflow.deleteWorkflowRunById(runId);
372
- return { message: "Workflow run deleted" };
373
- } catch (error) {
374
- return handleError(error, "Error deleting workflow run");
375
- }
376
- }
377
- });
378
- const CREATE_WORKFLOW_RUN_ROUTE = createRoute({
379
- method: "POST",
380
- path: "/workflows/:workflowId/create-run",
381
- responseType: "json",
382
- pathParamSchema: workflowIdPathParams,
383
- queryParamSchema: optionalRunIdSchema,
384
- bodySchema: createWorkflowRunBodySchema,
385
- responseSchema: createWorkflowRunResponseSchema,
386
- summary: "Create workflow run",
387
- description: "Creates a new workflow execution instance with an optional custom run ID",
388
- tags: ["Workflows"],
389
- requiresAuth: true,
390
- requiresPermission: ["workflows:write", "workflows:execute"],
391
- handler: async ({ mastra, workflowId, runId, resourceId, disableScorers, requestContext }) => {
392
- try {
393
- const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
394
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
395
- const { workflow } = await listWorkflowsFromSystem({
396
- mastra,
397
- workflowId
398
- });
399
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
400
- if (runId) await validateRunOwnership(await workflow.getWorkflowRunById(runId, { withNestedWorkflows: false }), getEffectiveResourceId(requestContext, void 0), mastra);
401
- return { runId: (await workflow.createRun({
402
- runId,
403
- resourceId: effectiveResourceId,
404
- disableScorers
405
- })).runId };
406
- } catch (error) {
407
- return handleError(error, "Error creating workflow run");
408
- }
409
- }
410
- });
411
- const STREAM_WORKFLOW_ROUTE = createRoute({
412
- method: "POST",
413
- path: "/workflows/:workflowId/stream",
414
- responseType: "stream",
415
- pathParamSchema: workflowIdPathParams,
416
- queryParamSchema: runIdSchema,
417
- bodySchema: streamWorkflowBodySchema,
418
- summary: "Stream workflow execution",
419
- description: "Executes a workflow and streams the results in real-time",
420
- tags: ["Workflows"],
421
- requiresAuth: true,
422
- handler: async ({ mastra, workflowId, runId, resourceId, requestContext, ...params }) => {
423
- try {
424
- const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
425
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
426
- if (!runId) throw new HTTPException(400, { message: "runId required to stream workflow" });
427
- const { workflow } = await listWorkflowsFromSystem({
428
- mastra,
429
- workflowId
430
- });
431
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
432
- const existingRun = await workflow.getWorkflowRunById(runId, { withNestedWorkflows: false });
433
- await validateRunOwnership(existingRun, getEffectiveResourceId(requestContext, void 0), mastra);
434
- if (existingRun && TERMINAL_RUN_STATUSES.includes(existingRun.status)) throw new HTTPException(409, { message: `Workflow run ${runId} already finished with status "${existingRun.status}". Use /observe to read its stream back, or stream a new runId.` });
435
- const serverCache = mastra.getServerCache();
436
- const result = (await workflow.createRun({
437
- runId,
438
- resourceId: effectiveResourceId
439
- })).stream({
440
- ...params,
441
- requestContext
442
- });
443
- if (serverCache) return cacheRunStream({
444
- cache: serverCache,
445
- runId,
446
- source: result.fullStream
447
- });
448
- return result.fullStream;
449
- } catch (error) {
450
- return handleError(error, "Error streaming workflow");
451
- }
452
- }
453
- });
454
- const RESUME_STREAM_WORKFLOW_ROUTE = createRoute({
455
- method: "POST",
456
- path: "/workflows/:workflowId/resume-stream",
457
- responseType: "stream",
458
- pathParamSchema: workflowIdPathParams,
459
- queryParamSchema: runIdSchema,
460
- bodySchema: resumeBodySchema,
461
- responseSchema: streamResponseSchema,
462
- summary: "Resume workflow stream",
463
- description: "Resumes a suspended workflow execution and continues streaming results",
464
- tags: ["Workflows"],
465
- requiresAuth: true,
466
- handler: async ({ mastra, workflowId, runId, requestContext, ...params }) => {
467
- try {
468
- const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
469
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
470
- if (!runId) throw new HTTPException(400, { message: "runId required to resume workflow" });
471
- const { workflow } = await listWorkflowsFromSystem({
472
- mastra,
473
- workflowId
474
- });
475
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
476
- const run = await workflow.getWorkflowRunById(runId);
477
- if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
478
- await validateRunOwnership(run, effectiveResourceId, mastra);
479
- const _run = await workflow.createRun({
480
- runId,
481
- resourceId: run.resourceId
482
- });
483
- const serverCache = mastra.getServerCache();
484
- const resumeResult = _run.resumeStream({
485
- ...params,
486
- requestContext
487
- });
488
- if (serverCache) return cacheRunStream({
489
- cache: serverCache,
490
- runId,
491
- source: resumeResult.fullStream
492
- });
493
- return resumeResult.fullStream;
494
- } catch (error) {
495
- return handleError(error, "Error resuming workflow");
496
- }
497
- }
498
- });
499
- const START_ASYNC_WORKFLOW_ROUTE = createRoute({
500
- method: "POST",
501
- path: "/workflows/:workflowId/start-async",
502
- responseType: "json",
503
- pathParamSchema: workflowIdPathParams,
504
- queryParamSchema: optionalRunIdSchema,
505
- bodySchema: startAsyncWorkflowBodySchema,
506
- responseSchema: workflowExecutionResultSchema,
507
- summary: "Start workflow asynchronously",
508
- description: "Starts a workflow execution asynchronously without streaming results",
509
- tags: ["Workflows"],
510
- requiresAuth: true,
511
- handler: async ({ mastra, workflowId, runId, resourceId, requestContext, ...params }) => {
512
- try {
513
- const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
514
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
515
- const { workflow } = await listWorkflowsFromSystem({
516
- mastra,
517
- workflowId
518
- });
519
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
520
- if (runId) await validateRunOwnership(await workflow.getWorkflowRunById(runId, { withNestedWorkflows: false }), getEffectiveResourceId(requestContext, void 0), mastra);
521
- return await (await workflow.createRun({
522
- runId,
523
- resourceId: effectiveResourceId
524
- })).start({
525
- ...params,
526
- requestContext
527
- });
528
- } catch (error) {
529
- return handleError(error, "Error starting async workflow");
530
- }
531
- }
532
- });
533
- const START_WORKFLOW_RUN_ROUTE = createRoute({
534
- method: "POST",
535
- path: "/workflows/:workflowId/start",
536
- responseType: "json",
537
- pathParamSchema: workflowIdPathParams,
538
- queryParamSchema: runIdSchema,
539
- bodySchema: startAsyncWorkflowBodySchema,
540
- responseSchema: workflowControlResponseSchema,
541
- summary: "Start specific workflow run",
542
- description: "Starts execution of a specific workflow run by ID",
543
- tags: ["Workflows"],
544
- requiresAuth: true,
545
- handler: async ({ mastra, workflowId, runId, requestContext, ...params }) => {
546
- try {
547
- const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
548
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
549
- if (!runId) throw new HTTPException(400, { message: "runId required to start run" });
550
- const { workflow } = await listWorkflowsFromSystem({
551
- mastra,
552
- workflowId
553
- });
554
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
555
- const run = await workflow.getWorkflowRunById(runId);
556
- if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
557
- await validateRunOwnership(run, effectiveResourceId, mastra);
558
- (await workflow.createRun({
559
- runId,
560
- resourceId: run.resourceId
561
- })).start({
562
- ...params,
563
- requestContext
564
- }).catch((error) => {
565
- mastra.getLogger().error("Failed to start workflow run", {
566
- error,
567
- workflowId,
568
- runId
569
- });
570
- });
571
- return { message: "Workflow run started" };
572
- } catch (e) {
573
- return handleError(e, "Error starting workflow run");
574
- }
575
- }
576
- });
577
- const OBSERVE_STREAM_WORKFLOW_ROUTE = createRoute({
578
- method: "POST",
579
- path: "/workflows/:workflowId/observe",
580
- responseType: "stream",
581
- pathParamSchema: workflowIdPathParams,
582
- queryParamSchema: observeWorkflowQuerySchema,
583
- responseSchema: streamResponseSchema,
584
- summary: "Observe workflow stream",
585
- description: "Observes and streams updates from an already running workflow execution. Supports position-based resume with offset for efficient reconnection.",
586
- tags: ["Workflows"],
587
- requiresAuth: true,
588
- handler: async ({ mastra, workflowId, runId, offset, requestContext }) => {
589
- try {
590
- const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
591
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
592
- if (!runId) throw new HTTPException(400, { message: "runId required to observe workflow stream" });
593
- const { workflow } = await listWorkflowsFromSystem({
594
- mastra,
595
- workflowId
596
- });
597
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
598
- const run = await workflow.getWorkflowRunById(runId);
599
- if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
600
- await validateRunOwnership(run, effectiveResourceId, mastra);
601
- const _run = await workflow.createRun({
602
- runId,
603
- resourceId: run.resourceId
604
- });
605
- const serverCache = mastra.getServerCache();
606
- if (!serverCache) throw new HTTPException(500, { message: "Server cache not found" });
607
- const startIndex = offset ?? 0;
608
- return createReplayStream({
609
- history: await serverCache.listFromTo(runId, startIndex),
610
- liveSource: _run.observeStream()
611
- });
612
- } catch (error) {
613
- return handleError(error, "Error observing workflow stream");
614
- }
615
- }
616
- });
617
- const RESUME_ASYNC_WORKFLOW_ROUTE = createRoute({
618
- method: "POST",
619
- path: "/workflows/:workflowId/resume-async",
620
- responseType: "json",
621
- pathParamSchema: workflowIdPathParams,
622
- queryParamSchema: runIdSchema,
623
- bodySchema: resumeBodySchema,
624
- responseSchema: workflowExecutionResultSchema,
625
- summary: "Resume workflow asynchronously",
626
- description: "Resumes a suspended workflow execution asynchronously without streaming",
627
- tags: ["Workflows"],
628
- requiresAuth: true,
629
- handler: async ({ mastra, workflowId, runId, requestContext, ...params }) => {
630
- try {
631
- const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
632
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
633
- if (!runId) throw new HTTPException(400, { message: "runId required to resume workflow" });
634
- const { workflow } = await listWorkflowsFromSystem({
635
- mastra,
636
- workflowId
637
- });
638
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
639
- const run = await workflow.getWorkflowRunById(runId);
640
- if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
641
- await validateRunOwnership(run, effectiveResourceId, mastra);
642
- return await (await workflow.createRun({
643
- runId,
644
- resourceId: run.resourceId
645
- })).resume({
646
- ...params,
647
- requestContext
648
- });
649
- } catch (error) {
650
- return handleError(error, "Error resuming workflow step");
651
- }
652
- }
653
- });
654
- /**
655
- * Fire-and-forget resume: dispatches the resume and returns immediately with the runId,
656
- * without waiting for the workflow to complete. For Inngest-backed workflows this avoids
657
- * the `getRunOutput()` polling race that the awaiting `resume-async` route can hit.
658
- *
659
- * TODO(v2): in Mastra v2 this fire-and-forget behavior should become the behavior of the
660
- * `resume-async` route (and `Run.resumeAsync()`), and this route should be removed. It is
661
- * kept separate in v1 to avoid a breaking change to the existing `resume-async` response
662
- * contract (which returns the full workflow result).
663
- */
664
- const RESUME_NO_WAIT_WORKFLOW_ROUTE = createRoute({
665
- method: "POST",
666
- path: "/workflows/:workflowId/resume-no-wait",
667
- responseType: "json",
668
- pathParamSchema: workflowIdPathParams,
669
- queryParamSchema: runIdSchema,
670
- bodySchema: resumeBodySchema,
671
- responseSchema: createWorkflowRunResponseSchema,
672
- summary: "Resume workflow without waiting",
673
- description: "Resumes a suspended workflow execution without waiting (fire-and-forget) and returns immediately with the runId. The workflow continues executing in the background.",
674
- tags: ["Workflows"],
675
- requiresAuth: true,
676
- handler: async ({ mastra, workflowId, runId, requestContext, ...params }) => {
677
- try {
678
- const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
679
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
680
- if (!runId) throw new HTTPException(400, { message: "runId required to resume workflow" });
681
- const { workflow } = await listWorkflowsFromSystem({
682
- mastra,
683
- workflowId
684
- });
685
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
686
- const run = await workflow.getWorkflowRunById(runId);
687
- if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
688
- await validateRunOwnership(run, effectiveResourceId, mastra);
689
- return await (await workflow.createRun({
690
- runId,
691
- resourceId: run.resourceId
692
- })).resumeAsync({
693
- ...params,
694
- requestContext
695
- });
696
- } catch (error) {
697
- return handleError(error, "Error resuming workflow step");
698
- }
699
- }
700
- });
701
- const RESUME_WORKFLOW_ROUTE = createRoute({
702
- method: "POST",
703
- path: "/workflows/:workflowId/resume",
704
- responseType: "json",
705
- pathParamSchema: workflowIdPathParams,
706
- queryParamSchema: runIdSchema,
707
- bodySchema: resumeBodySchema,
708
- responseSchema: workflowControlResponseSchema,
709
- summary: "Resume workflow",
710
- description: "Resumes a suspended workflow execution from a specific step",
711
- tags: ["Workflows"],
712
- requiresAuth: true,
713
- handler: async ({ mastra, workflowId, runId, requestContext, ...params }) => {
714
- try {
715
- const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
716
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
717
- if (!runId) throw new HTTPException(400, { message: "runId required to resume workflow" });
718
- const { workflow } = await listWorkflowsFromSystem({
719
- mastra,
720
- workflowId
721
- });
722
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
723
- const run = await workflow.getWorkflowRunById(runId);
724
- if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
725
- await validateRunOwnership(run, effectiveResourceId, mastra);
726
- (await workflow.createRun({
727
- runId,
728
- resourceId: run.resourceId
729
- })).resume({
730
- ...params,
731
- requestContext
732
- }).catch((error) => {
733
- mastra.getLogger().error("Failed to resume workflow run", {
734
- error,
735
- workflowId,
736
- runId
737
- });
738
- });
739
- return { message: "Workflow run resumed" };
740
- } catch (error) {
741
- return handleError(error, "Error resuming workflow");
742
- }
743
- }
744
- });
745
- const RESTART_ASYNC_WORKFLOW_ROUTE = createRoute({
746
- method: "POST",
747
- path: "/workflows/:workflowId/restart-async",
748
- responseType: "json",
749
- pathParamSchema: workflowIdPathParams,
750
- queryParamSchema: runIdSchema,
751
- bodySchema: restartBodySchema,
752
- responseSchema: workflowExecutionResultSchema,
753
- summary: "Restart workflow asynchronously",
754
- description: "Restarts an active workflow execution asynchronously",
755
- tags: ["Workflows"],
756
- requiresAuth: true,
757
- handler: async ({ mastra, workflowId, runId, requestContext, ...params }) => {
758
- try {
759
- const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
760
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
761
- if (!runId) throw new HTTPException(400, { message: "runId required to restart workflow" });
762
- const { workflow } = await listWorkflowsFromSystem({
763
- mastra,
764
- workflowId
765
- });
766
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
767
- const run = await workflow.getWorkflowRunById(runId);
768
- if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
769
- await validateRunOwnership(run, effectiveResourceId, mastra);
770
- return await (await workflow.createRun({
771
- runId,
772
- resourceId: run.resourceId
773
- })).restart({
774
- ...params,
775
- requestContext
776
- });
777
- } catch (error) {
778
- return handleError(error, "Error restarting workflow");
779
- }
780
- }
781
- });
782
- const RESTART_WORKFLOW_ROUTE = createRoute({
783
- method: "POST",
784
- path: "/workflows/:workflowId/restart",
785
- responseType: "json",
786
- pathParamSchema: workflowIdPathParams,
787
- queryParamSchema: runIdSchema,
788
- bodySchema: restartBodySchema,
789
- responseSchema: workflowControlResponseSchema,
790
- summary: "Restart workflow",
791
- description: "Restarts an active workflow execution",
792
- tags: ["Workflows"],
793
- requiresAuth: true,
794
- handler: async ({ mastra, workflowId, runId, requestContext, ...params }) => {
795
- try {
796
- const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
797
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
798
- if (!runId) throw new HTTPException(400, { message: "runId required to restart workflow" });
799
- const { workflow } = await listWorkflowsFromSystem({
800
- mastra,
801
- workflowId
802
- });
803
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
804
- const run = await workflow.getWorkflowRunById(runId);
805
- if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
806
- await validateRunOwnership(run, effectiveResourceId, mastra);
807
- (await workflow.createRun({
808
- runId,
809
- resourceId: run.resourceId
810
- })).restart({
811
- ...params,
812
- requestContext
813
- }).catch((error) => {
814
- mastra.getLogger().error("Failed to restart workflow run in background", {
815
- error,
816
- workflowId,
817
- runId
818
- });
819
- });
820
- return { message: "Workflow run restarted" };
821
- } catch (error) {
822
- return handleError(error, "Error restarting workflow");
823
- }
824
- }
825
- });
826
- const RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ASYNC_ROUTE = createRoute({
827
- method: "POST",
828
- path: "/workflows/:workflowId/restart-all-active-workflow-runs-async",
829
- responseType: "json",
830
- pathParamSchema: workflowIdPathParams,
831
- responseSchema: workflowControlResponseSchema,
832
- summary: "Restart all active workflow runs asynchronously",
833
- description: "Restarts all active workflow runs asynchronously",
834
- tags: ["Workflows"],
835
- requiresAuth: true,
836
- handler: async ({ mastra, workflowId, requestContext }) => {
837
- try {
838
- await validateRunOwnership({ resourceId: null }, getEffectiveResourceId(requestContext, void 0), mastra);
839
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
840
- const { workflow } = await listWorkflowsFromSystem({
841
- mastra,
842
- workflowId
843
- });
844
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
845
- await workflow.restartAllActiveWorkflowRuns();
846
- return { message: "All active workflow runs restarted" };
847
- } catch (error) {
848
- return handleError(error, "Error restarting workflow");
849
- }
850
- }
851
- });
852
- const RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ROUTE = createRoute({
853
- method: "POST",
854
- path: "/workflows/:workflowId/restart-all-active-workflow-runs",
855
- responseType: "json",
856
- pathParamSchema: workflowIdPathParams,
857
- responseSchema: workflowControlResponseSchema,
858
- summary: "Restart all active workflow runs",
859
- description: "Restarts all active workflow runs",
860
- tags: ["Workflows"],
861
- requiresAuth: true,
862
- handler: async ({ mastra, workflowId, requestContext }) => {
863
- try {
864
- await validateRunOwnership({ resourceId: null }, getEffectiveResourceId(requestContext, void 0), mastra);
865
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
866
- const { workflow } = await listWorkflowsFromSystem({
867
- mastra,
868
- workflowId
869
- });
870
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
871
- workflow.restartAllActiveWorkflowRuns().catch((error) => {
872
- mastra.getLogger().error("Failed to restart active workflow runs", {
873
- error,
874
- workflowId
875
- });
876
- });
877
- return { message: "All active workflow runs restarted" };
878
- } catch (error) {
879
- return handleError(error, "Error restarting workflow");
880
- }
881
- }
882
- });
883
- const TIME_TRAVEL_ASYNC_WORKFLOW_ROUTE = createRoute({
884
- method: "POST",
885
- path: "/workflows/:workflowId/time-travel-async",
886
- responseType: "json",
887
- pathParamSchema: workflowIdPathParams,
888
- queryParamSchema: runIdSchema,
889
- bodySchema: timeTravelBodySchema,
890
- responseSchema: workflowExecutionResultSchema,
891
- summary: "Time travel workflow asynchronously",
892
- description: "Time travels a workflow run asynchronously without streaming",
893
- tags: ["Workflows"],
894
- requiresAuth: true,
895
- handler: async ({ mastra, workflowId, runId, requestContext, ...params }) => {
896
- try {
897
- const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
898
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
899
- if (!runId) throw new HTTPException(400, { message: "runId required to time travel workflow" });
900
- const { workflow } = await listWorkflowsFromSystem({
901
- mastra,
902
- workflowId
903
- });
904
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
905
- const run = await workflow.getWorkflowRunById(runId);
906
- if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
907
- await validateRunOwnership(run, effectiveResourceId, mastra);
908
- return await (await workflow.createRun({
909
- runId,
910
- resourceId: run.resourceId
911
- })).timeTravel({
912
- ...params,
913
- requestContext
914
- });
915
- } catch (error) {
916
- return handleError(error, "Error time traveling workflow");
917
- }
918
- }
919
- });
920
- const TIME_TRAVEL_WORKFLOW_ROUTE = createRoute({
921
- method: "POST",
922
- path: "/workflows/:workflowId/time-travel",
923
- responseType: "json",
924
- pathParamSchema: workflowIdPathParams,
925
- queryParamSchema: runIdSchema,
926
- bodySchema: timeTravelBodySchema,
927
- responseSchema: workflowControlResponseSchema,
928
- summary: "Time travel workflow",
929
- description: "Time travels a workflow run, starting from a specific step",
930
- tags: ["Workflows"],
931
- requiresAuth: true,
932
- handler: async ({ mastra, workflowId, runId, requestContext, ...params }) => {
933
- try {
934
- const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
935
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
936
- if (!runId) throw new HTTPException(400, { message: "runId required to time travel workflow" });
937
- const { workflow } = await listWorkflowsFromSystem({
938
- mastra,
939
- workflowId
940
- });
941
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
942
- const run = await workflow.getWorkflowRunById(runId);
943
- if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
944
- await validateRunOwnership(run, effectiveResourceId, mastra);
945
- (await workflow.createRun({
946
- runId,
947
- resourceId: run.resourceId
948
- })).timeTravel({
949
- ...params,
950
- requestContext
951
- }).catch((error) => {
952
- mastra.getLogger().error("Failed to time travel workflow run", {
953
- error,
954
- workflowId,
955
- runId
956
- });
957
- });
958
- return { message: "Workflow run time travel started" };
959
- } catch (error) {
960
- return handleError(error, "Error time traveling workflow");
961
- }
962
- }
963
- });
964
- const TIME_TRAVEL_STREAM_WORKFLOW_ROUTE = createRoute({
965
- method: "POST",
966
- path: "/workflows/:workflowId/time-travel-stream",
967
- responseType: "stream",
968
- pathParamSchema: workflowIdPathParams,
969
- queryParamSchema: runIdSchema,
970
- bodySchema: timeTravelBodySchema,
971
- summary: "Time travel workflow stream",
972
- description: "Time travels a workflow run, starting from a specific step, and streams the results in real-time",
973
- tags: ["Workflows"],
974
- requiresAuth: true,
975
- handler: async ({ mastra, workflowId, runId, requestContext, ...params }) => {
976
- try {
977
- const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
978
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
979
- if (!runId) throw new HTTPException(400, { message: "runId required to time travel workflow stream" });
980
- const { workflow } = await listWorkflowsFromSystem({
981
- mastra,
982
- workflowId
983
- });
984
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
985
- const existingRun = await workflow.getWorkflowRunById(runId);
986
- if (!existingRun) throw new HTTPException(404, { message: "Workflow run not found" });
987
- await validateRunOwnership(existingRun, effectiveResourceId, mastra);
988
- const serverCache = mastra.getServerCache();
989
- const result = (await workflow.createRun({
990
- runId,
991
- resourceId: existingRun.resourceId
992
- })).timeTravelStream({
993
- ...params,
994
- requestContext
995
- });
996
- if (serverCache) return cacheRunStream({
997
- cache: serverCache,
998
- runId,
999
- source: result.fullStream
1000
- });
1001
- return result.fullStream;
1002
- } catch (error) {
1003
- return handleError(error, "Error time traveling workflow stream");
1004
- }
1005
- }
1006
- });
1007
- const CANCEL_WORKFLOW_RUN_ROUTE = createRoute({
1008
- method: "POST",
1009
- path: "/workflows/:workflowId/runs/:runId/cancel",
1010
- responseType: "json",
1011
- pathParamSchema: workflowRunPathParams,
1012
- responseSchema: workflowControlResponseSchema,
1013
- summary: "Cancel workflow run",
1014
- description: "Cancels an in-progress workflow execution",
1015
- tags: ["Workflows"],
1016
- requiresAuth: true,
1017
- handler: async ({ mastra, workflowId, runId, requestContext }) => {
1018
- try {
1019
- const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
1020
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
1021
- if (!runId) throw new HTTPException(400, { message: "runId required to cancel workflow run" });
1022
- const { workflow } = await listWorkflowsFromSystem({
1023
- mastra,
1024
- workflowId
1025
- });
1026
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
1027
- const run = await workflow.getWorkflowRunById(runId);
1028
- if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
1029
- await validateRunOwnership(run, effectiveResourceId, mastra);
1030
- await (await workflow.createRun({
1031
- runId,
1032
- resourceId: run.resourceId
1033
- })).cancel();
1034
- return { message: "Workflow run cancelled" };
1035
- } catch (error) {
1036
- return handleError(error, "Error canceling workflow run");
1037
- }
1038
- }
1039
- });
1040
- const STREAM_LEGACY_WORKFLOW_ROUTE = createRoute({
1041
- method: "POST",
1042
- path: "/workflows/:workflowId/stream-legacy",
1043
- responseType: "stream",
1044
- pathParamSchema: workflowIdPathParams,
1045
- queryParamSchema: runIdSchema,
1046
- bodySchema: streamWorkflowBodySchema,
1047
- responseSchema: streamResponseSchema,
1048
- summary: "[DEPRECATED] Stream workflow with legacy format",
1049
- description: "Legacy endpoint for streaming workflow execution. Use /workflows/:workflowId/stream instead.",
1050
- tags: ["Workflows", "Legacy"],
1051
- requiresAuth: true,
1052
- handler: async ({ mastra, workflowId, runId, resourceId, requestContext, ...params }) => {
1053
- try {
1054
- const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
1055
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
1056
- if (!runId) throw new HTTPException(400, { message: "runId required to resume workflow" });
1057
- const { workflow } = await listWorkflowsFromSystem({
1058
- mastra,
1059
- workflowId
1060
- });
1061
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
1062
- const serverCache = mastra.getServerCache();
1063
- if (runId) await validateRunOwnership(await workflow.getWorkflowRunById(runId, { withNestedWorkflows: false }), getEffectiveResourceId(requestContext, void 0), mastra);
1064
- return (await workflow.createRun({
1065
- runId,
1066
- resourceId: effectiveResourceId
1067
- })).streamLegacy({
1068
- ...params,
1069
- requestContext,
1070
- onChunk: async (chunk) => {
1071
- if (serverCache) {
1072
- const cacheKey = runId;
1073
- await serverCache.listPush(cacheKey, chunk);
1074
- }
1075
- }
1076
- }).stream;
1077
- } catch (error) {
1078
- return handleError(error, "Error executing workflow");
1079
- }
1080
- }
1081
- });
1082
- const OBSERVE_STREAM_LEGACY_WORKFLOW_ROUTE = createRoute({
1083
- method: "POST",
1084
- path: "/workflows/:workflowId/observe-stream-legacy",
1085
- responseType: "stream",
1086
- pathParamSchema: workflowIdPathParams,
1087
- queryParamSchema: runIdSchema,
1088
- responseSchema: streamResponseSchema,
1089
- summary: "[DEPRECATED] Observe workflow stream with legacy format",
1090
- description: "Legacy endpoint for observing workflow stream. Use /workflows/:workflowId/observe instead.",
1091
- tags: ["Workflows", "Legacy"],
1092
- requiresAuth: true,
1093
- handler: async ({ mastra, workflowId, runId, requestContext }) => {
1094
- try {
1095
- const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
1096
- if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
1097
- if (!runId) throw new HTTPException(400, { message: "runId required to observe workflow stream" });
1098
- const { workflow } = await listWorkflowsFromSystem({
1099
- mastra,
1100
- workflowId
1101
- });
1102
- if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
1103
- const run = await workflow.getWorkflowRunById(runId);
1104
- if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
1105
- await validateRunOwnership(run, effectiveResourceId, mastra);
1106
- const _run = await workflow.createRun({
1107
- runId,
1108
- resourceId: run.resourceId
1109
- });
1110
- const serverCache = mastra.getServerCache();
1111
- if (!serverCache) throw new HTTPException(500, { message: "Server cache not found" });
1112
- const cachedRunChunks = await serverCache.listFromTo(runId, 0);
1113
- const result = _run.observeStreamLegacy();
1114
- if (!result.stream) throw new HTTPException(500, { message: "Failed to create observe stream" });
1115
- return createReplayStream({
1116
- history: cachedRunChunks,
1117
- liveSource: result.stream
1118
- });
1119
- } catch (error) {
1120
- return handleError(error, "Error observing workflow stream");
1121
- }
1122
- }
1123
- });
1124
- const stepExecutionParentWorkflowSchema = z.lazy(() => z.object({
1125
- workflowId: z.string(),
1126
- runId: z.string(),
1127
- executionPath: z.array(z.number().int().nonnegative()),
1128
- parentWorkflow: stepExecutionParentWorkflowSchema.optional()
1129
- }));
1130
- const stepExecutionBodySchema = z.object({
1131
- stepId: z.string(),
1132
- executionPath: z.array(z.number().int().nonnegative()),
1133
- parentWorkflow: stepExecutionParentWorkflowSchema.optional(),
1134
- stepResults: z.record(z.string(), z.unknown()),
1135
- state: z.record(z.string(), z.unknown()),
1136
- requestContext: z.record(z.string(), z.unknown()),
1137
- input: z.unknown().optional(),
1138
- resumeData: z.unknown().optional(),
1139
- retryCount: z.number().int().nonnegative().optional(),
1140
- foreachIdx: z.number().int().nonnegative().optional(),
1141
- format: z.enum(["legacy", "vnext"]).optional(),
1142
- perStep: z.boolean().optional(),
1143
- validateInputs: z.boolean().optional()
1144
- });
1145
- const strategyByMastra = /* @__PURE__ */ new WeakMap();
1146
- async function getStepStrategy(mastra) {
1147
- let cached = strategyByMastra.get(mastra);
1148
- if (!cached) {
1149
- const { InProcessStrategy } = await import("@mastra/core/worker");
1150
- cached = new InProcessStrategy({ mastra });
1151
- strategyByMastra.set(mastra, cached);
1152
- }
1153
- return cached;
1154
- }
1155
- const EXECUTE_WORKFLOW_STEP_ROUTE = createRoute({
1156
- method: "POST",
1157
- path: "/workflows/:workflowId/runs/:runId/steps/execute",
1158
- responseType: "json",
1159
- pathParamSchema: workflowRunPathParams,
1160
- bodySchema: stepExecutionBodySchema,
1161
- responseSchema: z.unknown(),
1162
- summary: "Execute a workflow step",
1163
- description: "Internal endpoint used by standalone OrchestrationWorker instances to execute workflow steps remotely via HttpRemoteStrategy.",
1164
- tags: ["Workflows", "Worker"],
1165
- requiresAuth: true,
1166
- handler: (async ({ mastra, workflowId, runId, ...body }) => {
1167
- try {
1168
- const candidate = body.requestContext;
1169
- const serverRequestContext = typeof candidate?.get === "function" ? candidate : void 0;
1170
- await validateRunOwnership(await (await mastra.getStorage()?.getStore("workflows"))?.getWorkflowRunById({
1171
- runId,
1172
- workflowName: workflowId
1173
- }), getEffectiveResourceId(serverRequestContext, void 0), mastra);
1174
- return await (await getStepStrategy(mastra)).executeStep({
1175
- workflowId,
1176
- runId,
1177
- stepId: body.stepId,
1178
- executionPath: body.executionPath,
1179
- parentWorkflow: body.parentWorkflow,
1180
- stepResults: body.stepResults,
1181
- state: body.state,
1182
- requestContext: body.requestContext,
1183
- input: body.input,
1184
- resumeData: body.resumeData,
1185
- retryCount: body.retryCount,
1186
- foreachIdx: body.foreachIdx,
1187
- format: body.format,
1188
- perStep: body.perStep,
1189
- validateInputs: body.validateInputs
1190
- });
1191
- } catch (error) {
1192
- return handleError(error, "Error executing workflow step");
1193
- }
1194
- })
1195
- });
1196
- const workflowEventSchema = z.object({
1197
- id: z.string(),
1198
- type: z.string(),
1199
- data: z.unknown(),
1200
- runId: z.string(),
1201
- createdAt: z.string(),
1202
- index: z.number().optional(),
1203
- deliveryAttempt: z.number().optional()
1204
- });
1205
- /**
1206
- * Generic push receive endpoint for workflow events. A push-mode broker
1207
- * (GCP Pub/Sub push subscription, SNS, EventBridge) — or a per-broker adapter
1208
- * that decodes the broker's envelope first — POSTs each event here and the
1209
- * response code tells the broker whether to retry:
1210
- *
1211
- * - 200/204 → ack
1212
- * - 5xx → transient, retry with backoff
1213
- * - 4xx → poison, drop / send to DLQ
1214
- *
1215
- * Auth is enforced through the framework's standard `requiresAuth` flow.
1216
- * Operators MUST configure an `authenticateToken` provider that recognizes
1217
- * whatever credential the broker attaches (e.g. a Google-signed OIDC token
1218
- * for GCP Pub/Sub push). Without an auth provider the endpoint is effectively
1219
- * public — same caveat as `EXECUTE_WORKFLOW_STEP_ROUTE`.
1220
- */
1221
- const RECEIVE_WORKFLOW_EVENT_ROUTE = createRoute({
1222
- method: "POST",
1223
- path: "/workflows/events",
1224
- responseType: "json",
1225
- bodySchema: z.object({ event: workflowEventSchema.passthrough() }),
1226
- responseSchema: z.object({
1227
- ok: z.boolean(),
1228
- retry: z.boolean().optional()
1229
- }),
1230
- summary: "Receive a workflow event from a push-mode broker",
1231
- description: "Push-mode entry point for workflow events. Brokers (GCP Pub/Sub push, SNS, EventBridge) POST each event here; Mastra processes it through the same pipeline as pull-mode workers.",
1232
- tags: ["Workflows", "Worker"],
1233
- requiresAuth: true,
1234
- requiresPermission: ["workflows:write", "workflows:execute"],
1235
- handler: (async ({ mastra, event, requestContext }) => {
1236
- try {
1237
- const workflowName = event.data?.workflowId;
1238
- await validateRunOwnership(await (await mastra.getStorage()?.getStore("workflows"))?.getWorkflowRunById({
1239
- runId: event.runId,
1240
- ...typeof workflowName === "string" ? { workflowName } : {}
1241
- }), getEffectiveResourceId(requestContext, void 0), mastra);
1242
- const rawCreatedAt = event.createdAt;
1243
- const createdAt = rawCreatedAt instanceof Date ? rawCreatedAt : new Date(rawCreatedAt);
1244
- if (Number.isNaN(createdAt.getTime())) throw new HTTPException(400, { message: "Invalid createdAt" });
1245
- return await mastra.handleWorkflowEvent({
1246
- ...event,
1247
- createdAt
1248
- });
1249
- } catch (error) {
1250
- return handleError(error, "Error receiving workflow event");
1251
- }
1252
- })
1253
- });
1254
- //#endregion
1255
- export { CANCEL_WORKFLOW_RUN_ROUTE, CREATE_WORKFLOW_RUN_ROUTE, DELETE_WORKFLOW_RUN_BY_ID_ROUTE, EXECUTE_WORKFLOW_STEP_ROUTE, GET_WORKFLOW_BY_ID_ROUTE, GET_WORKFLOW_RUN_BY_ID_ROUTE, LIST_WORKFLOWS_ROUTE, LIST_WORKFLOW_RUNS_ROUTE, LIST_WORKFLOW_RUN_COUNTS_ROUTE, OBSERVE_STREAM_LEGACY_WORKFLOW_ROUTE, OBSERVE_STREAM_WORKFLOW_ROUTE, RECEIVE_WORKFLOW_EVENT_ROUTE, RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ASYNC_ROUTE, RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ROUTE, RESTART_ASYNC_WORKFLOW_ROUTE, RESTART_WORKFLOW_ROUTE, RESUME_ASYNC_WORKFLOW_ROUTE, RESUME_NO_WAIT_WORKFLOW_ROUTE, RESUME_STREAM_WORKFLOW_ROUTE, RESUME_WORKFLOW_ROUTE, START_ASYNC_WORKFLOW_ROUTE, START_WORKFLOW_RUN_ROUTE, STREAM_LEGACY_WORKFLOW_ROUTE, STREAM_WORKFLOW_ROUTE, TIME_TRAVEL_ASYNC_WORKFLOW_ROUTE, TIME_TRAVEL_STREAM_WORKFLOW_ROUTE, TIME_TRAVEL_WORKFLOW_ROUTE, __setWorkflowRunCountsNow, workflows_exports as t };
1256
-
1257
- //# sourceMappingURL=workflows.js.map
1
+ export { t as CANCEL_WORKFLOW_RUN_ROUTE, n as CREATE_WORKFLOW_RUN_ROUTE, r as DELETE_WORKFLOW_RUN_BY_ID_ROUTE, i as EXECUTE_WORKFLOW_STEP_ROUTE, a as GET_WORKFLOW_BY_ID_ROUTE, o as GET_WORKFLOW_RUN_BY_ID_ROUTE, s as LIST_WORKFLOWS_ROUTE, c as LIST_WORKFLOW_RUNS_ROUTE, l as LIST_WORKFLOW_RUN_COUNTS_ROUTE, u as OBSERVE_STREAM_LEGACY_WORKFLOW_ROUTE, d as OBSERVE_STREAM_WORKFLOW_ROUTE, f as RECEIVE_WORKFLOW_EVENT_ROUTE, p as RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ASYNC_ROUTE, m as RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ROUTE, h as RESTART_ASYNC_WORKFLOW_ROUTE, g as RESTART_WORKFLOW_ROUTE, _ as RESUME_ASYNC_WORKFLOW_ROUTE, v as RESUME_NO_WAIT_WORKFLOW_ROUTE, y as RESUME_STREAM_WORKFLOW_ROUTE, b as RESUME_WORKFLOW_ROUTE, x as START_ASYNC_WORKFLOW_ROUTE, S as START_WORKFLOW_RUN_ROUTE, C as STREAM_LEGACY_WORKFLOW_ROUTE, w as STREAM_WORKFLOW_ROUTE, T as TIME_TRAVEL_ASYNC_WORKFLOW_ROUTE, E as TIME_TRAVEL_STREAM_WORKFLOW_ROUTE, D as TIME_TRAVEL_WORKFLOW_ROUTE, O as __setWorkflowRunCountsNow } from "../../workflows-bb-otd2o.js";