@mastra/server 0.0.0-revert-schema-20250416221206 → 0.0.0-safe-stringify-telemetry-20251205024938

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 (276) hide show
  1. package/CHANGELOG.md +4368 -0
  2. package/LICENSE.md +11 -42
  3. package/README.md +45 -137
  4. package/dist/chunk-2PLXW4ZX.cjs +2777 -0
  5. package/dist/chunk-2PLXW4ZX.cjs.map +1 -0
  6. package/dist/chunk-2S4IMB6E.cjs +130 -0
  7. package/dist/chunk-2S4IMB6E.cjs.map +1 -0
  8. package/dist/chunk-3SNGNFUJ.cjs +128 -0
  9. package/dist/chunk-3SNGNFUJ.cjs.map +1 -0
  10. package/dist/{chunk-L7XE5QTW.js → chunk-4QCXUEAT.js} +11 -2
  11. package/dist/chunk-4QCXUEAT.js.map +1 -0
  12. package/dist/{chunk-WTHDCRMY.js → chunk-67GYDFSB.js} +33 -8
  13. package/dist/chunk-67GYDFSB.js.map +1 -0
  14. package/dist/chunk-6N3HC6O4.js +705 -0
  15. package/dist/chunk-6N3HC6O4.js.map +1 -0
  16. package/dist/{chunk-7IWQE76Z.cjs → chunk-6ZR275MD.cjs} +37 -11
  17. package/dist/chunk-6ZR275MD.cjs.map +1 -0
  18. package/dist/{chunk-FV45V6WC.cjs → chunk-7NADHFD2.cjs} +3 -7
  19. package/dist/chunk-7NADHFD2.cjs.map +1 -0
  20. package/dist/chunk-7RGKOGE4.cjs +485 -0
  21. package/dist/chunk-7RGKOGE4.cjs.map +1 -0
  22. package/dist/chunk-ABRFV4XP.js +83 -0
  23. package/dist/chunk-ABRFV4XP.js.map +1 -0
  24. package/dist/{chunk-UV4WTEH4.js → chunk-AHB4JCIQ.js} +55 -15
  25. package/dist/chunk-AHB4JCIQ.js.map +1 -0
  26. package/dist/chunk-AW5BU3RQ.js +192 -0
  27. package/dist/chunk-AW5BU3RQ.js.map +1 -0
  28. package/dist/chunk-BATEJLED.js +124 -0
  29. package/dist/chunk-BATEJLED.js.map +1 -0
  30. package/dist/chunk-CY4TP3FK.js +16 -0
  31. package/dist/chunk-CY4TP3FK.js.map +1 -0
  32. package/dist/chunk-CY6R3HLM.cjs +727 -0
  33. package/dist/chunk-CY6R3HLM.cjs.map +1 -0
  34. package/dist/{chunk-M56ECCHK.cjs → chunk-EP3JQDPD.cjs} +22 -19
  35. package/dist/chunk-EP3JQDPD.cjs.map +1 -0
  36. package/dist/chunk-G4PUALCE.cjs +28 -0
  37. package/dist/chunk-G4PUALCE.cjs.map +1 -0
  38. package/dist/chunk-G5O5SC7R.cjs +19565 -0
  39. package/dist/chunk-G5O5SC7R.cjs.map +1 -0
  40. package/dist/chunk-GU4EWMZB.cjs +769 -0
  41. package/dist/chunk-GU4EWMZB.cjs.map +1 -0
  42. package/dist/chunk-I3C4ODGV.cjs +335 -0
  43. package/dist/chunk-I3C4ODGV.cjs.map +1 -0
  44. package/dist/chunk-IAE7SFBS.js +477 -0
  45. package/dist/chunk-IAE7SFBS.js.map +1 -0
  46. package/dist/chunk-LF2ZLOFP.js +767 -0
  47. package/dist/chunk-LF2ZLOFP.js.map +1 -0
  48. package/dist/{chunk-OPP7H5TW.js → chunk-LLUOPR3J.js} +92 -74
  49. package/dist/chunk-LLUOPR3J.js.map +1 -0
  50. package/dist/chunk-LPM6BBAX.cjs +1043 -0
  51. package/dist/chunk-LPM6BBAX.cjs.map +1 -0
  52. package/dist/{chunk-TRDNDNGQ.js → chunk-MMROOK5J.js} +4 -7
  53. package/dist/chunk-MMROOK5J.js.map +1 -0
  54. package/dist/{chunk-4JINXASC.js → chunk-MYR4PVGN.js} +7 -4
  55. package/dist/chunk-MYR4PVGN.js.map +1 -0
  56. package/dist/chunk-NT5XW5PI.cjs +596 -0
  57. package/dist/chunk-NT5XW5PI.cjs.map +1 -0
  58. package/dist/chunk-O7I5CWRX.cjs +44 -0
  59. package/dist/chunk-O7I5CWRX.cjs.map +1 -0
  60. package/dist/chunk-PBXWFGEH.js +579 -0
  61. package/dist/chunk-PBXWFGEH.js.map +1 -0
  62. package/dist/chunk-PR4QN5HX.js +39 -0
  63. package/dist/chunk-PR4QN5HX.js.map +1 -0
  64. package/dist/chunk-QGNHNNJR.js +909 -0
  65. package/dist/chunk-QGNHNNJR.js.map +1 -0
  66. package/dist/{chunk-3RVHWGWO.js → chunk-QQXMIP6C.js} +49 -22
  67. package/dist/chunk-QQXMIP6C.js.map +1 -0
  68. package/dist/chunk-QU6N55W6.cjs +256 -0
  69. package/dist/chunk-QU6N55W6.cjs.map +1 -0
  70. package/dist/chunk-RE4RPXT2.cjs +18 -0
  71. package/dist/chunk-RE4RPXT2.cjs.map +1 -0
  72. package/dist/chunk-RQK4FQUD.js +1012 -0
  73. package/dist/chunk-RQK4FQUD.js.map +1 -0
  74. package/dist/chunk-S6YZQY4V.cjs +938 -0
  75. package/dist/chunk-S6YZQY4V.cjs.map +1 -0
  76. package/dist/chunk-SHWNNZBL.js +254 -0
  77. package/dist/chunk-SHWNNZBL.js.map +1 -0
  78. package/dist/chunk-SPRRK3P7.cjs +200 -0
  79. package/dist/chunk-SPRRK3P7.cjs.map +1 -0
  80. package/dist/chunk-TOCYBDP2.js +46 -0
  81. package/dist/chunk-TOCYBDP2.js.map +1 -0
  82. package/dist/chunk-TRGAMKHX.cjs +167 -0
  83. package/dist/chunk-TRGAMKHX.cjs.map +1 -0
  84. package/dist/chunk-TRHCWKZ2.js +19529 -0
  85. package/dist/chunk-TRHCWKZ2.js.map +1 -0
  86. package/dist/chunk-VY4ENABS.cjs +135 -0
  87. package/dist/chunk-VY4ENABS.cjs.map +1 -0
  88. package/dist/chunk-X6C7BUWN.cjs +48 -0
  89. package/dist/chunk-X6C7BUWN.cjs.map +1 -0
  90. package/dist/chunk-XN74I6VW.cjs +88 -0
  91. package/dist/chunk-XN74I6VW.cjs.map +1 -0
  92. package/dist/chunk-YWOK4F5A.js +131 -0
  93. package/dist/chunk-YWOK4F5A.js.map +1 -0
  94. package/dist/chunk-ZULZ2752.js +2774 -0
  95. package/dist/chunk-ZULZ2752.js.map +1 -0
  96. package/dist/dist-4MVGNSRL.cjs +1150 -0
  97. package/dist/dist-4MVGNSRL.cjs.map +1 -0
  98. package/dist/dist-FZYCV3VB.cjs +940 -0
  99. package/dist/dist-FZYCV3VB.cjs.map +1 -0
  100. package/dist/dist-G2BYZJOC.cjs +928 -0
  101. package/dist/dist-G2BYZJOC.cjs.map +1 -0
  102. package/dist/dist-P4MXBQ3U.cjs +16 -0
  103. package/dist/dist-P4MXBQ3U.cjs.map +1 -0
  104. package/dist/dist-PQZUVLPC.js +937 -0
  105. package/dist/dist-PQZUVLPC.js.map +1 -0
  106. package/dist/dist-R7WYX6LC.js +925 -0
  107. package/dist/dist-R7WYX6LC.js.map +1 -0
  108. package/dist/dist-RFMYFILX.cjs +764 -0
  109. package/dist/dist-RFMYFILX.cjs.map +1 -0
  110. package/dist/dist-X7XR3M3Z.js +1147 -0
  111. package/dist/dist-X7XR3M3Z.js.map +1 -0
  112. package/dist/dist-XVBSOGFK.js +761 -0
  113. package/dist/dist-XVBSOGFK.js.map +1 -0
  114. package/dist/dist-YREX2TJT.js +3 -0
  115. package/dist/dist-YREX2TJT.js.map +1 -0
  116. package/dist/index.cjs +6 -0
  117. package/dist/index.cjs.map +1 -0
  118. package/dist/index.d.ts +1 -0
  119. package/dist/index.d.ts.map +1 -0
  120. package/dist/index.js +5 -0
  121. package/dist/index.js.map +1 -0
  122. package/dist/server/a2a/protocol.d.ts +8 -0
  123. package/dist/server/a2a/protocol.d.ts.map +1 -0
  124. package/dist/server/a2a/store.cjs +25 -0
  125. package/dist/server/a2a/store.cjs.map +1 -0
  126. package/dist/server/a2a/store.d.ts +14 -0
  127. package/dist/server/a2a/store.d.ts.map +1 -0
  128. package/dist/server/a2a/store.js +23 -0
  129. package/dist/server/a2a/store.js.map +1 -0
  130. package/dist/server/a2a/tasks.d.ts +20 -0
  131. package/dist/server/a2a/tasks.d.ts.map +1 -0
  132. package/dist/server/handlers/a2a.cjs +32 -0
  133. package/dist/server/handlers/a2a.cjs.map +1 -0
  134. package/dist/server/handlers/a2a.d.ts +68 -0
  135. package/dist/server/handlers/a2a.d.ts.map +1 -0
  136. package/dist/server/handlers/a2a.js +3 -0
  137. package/dist/server/handlers/a2a.js.map +1 -0
  138. package/dist/server/handlers/agent-builder.cjs +68 -0
  139. package/dist/server/handlers/agent-builder.cjs.map +1 -0
  140. package/dist/server/handlers/agent-builder.d.ts +94 -0
  141. package/dist/server/handlers/agent-builder.d.ts.map +1 -0
  142. package/dist/server/handlers/agent-builder.js +3 -0
  143. package/dist/server/handlers/agent-builder.js.map +1 -0
  144. package/dist/server/handlers/agents.cjs +65 -7
  145. package/dist/server/handlers/agents.cjs.map +1 -0
  146. package/dist/server/handlers/agents.d.ts +210 -6
  147. package/dist/server/handlers/agents.d.ts.map +1 -0
  148. package/dist/server/handlers/agents.js +3 -1
  149. package/dist/server/handlers/agents.js.map +1 -0
  150. package/dist/server/handlers/error.cjs +4 -2
  151. package/dist/server/handlers/error.cjs.map +1 -0
  152. package/dist/server/handlers/error.d.ts +2 -1
  153. package/dist/server/handlers/error.d.ts.map +1 -0
  154. package/dist/server/handlers/error.js +3 -1
  155. package/dist/server/handlers/error.js.map +1 -0
  156. package/dist/server/handlers/legacyWorkflows.cjs +48 -0
  157. package/dist/server/handlers/legacyWorkflows.cjs.map +1 -0
  158. package/dist/server/handlers/legacyWorkflows.d.ts +59 -0
  159. package/dist/server/handlers/legacyWorkflows.d.ts.map +1 -0
  160. package/dist/server/handlers/legacyWorkflows.js +3 -0
  161. package/dist/server/handlers/legacyWorkflows.js.map +1 -0
  162. package/dist/server/handlers/logs.cjs +6 -4
  163. package/dist/server/handlers/logs.cjs.map +1 -0
  164. package/dist/server/handlers/logs.d.ts +34 -3
  165. package/dist/server/handlers/logs.d.ts.map +1 -0
  166. package/dist/server/handlers/logs.js +3 -1
  167. package/dist/server/handlers/logs.js.map +1 -0
  168. package/dist/server/handlers/memory.cjs +39 -9
  169. package/dist/server/handlers/memory.cjs.map +1 -0
  170. package/dist/server/handlers/memory.d.ts +118 -8
  171. package/dist/server/handlers/memory.d.ts.map +1 -0
  172. package/dist/server/handlers/memory.js +3 -1
  173. package/dist/server/handlers/memory.js.map +1 -0
  174. package/dist/server/handlers/observability.cjs +24 -0
  175. package/dist/server/handlers/observability.cjs.map +1 -0
  176. package/dist/server/handlers/observability.d.ts +49 -0
  177. package/dist/server/handlers/observability.d.ts.map +1 -0
  178. package/dist/server/handlers/observability.js +3 -0
  179. package/dist/server/handlers/observability.js.map +1 -0
  180. package/dist/server/handlers/scores.cjs +32 -0
  181. package/dist/server/handlers/scores.cjs.map +1 -0
  182. package/dist/server/handlers/scores.d.ts +152 -0
  183. package/dist/server/handlers/scores.d.ts.map +1 -0
  184. package/dist/server/handlers/scores.js +3 -0
  185. package/dist/server/handlers/scores.js.map +1 -0
  186. package/dist/server/handlers/telemetry.cjs +9 -3
  187. package/dist/server/handlers/telemetry.cjs.map +1 -0
  188. package/dist/server/handlers/telemetry.d.ts +33 -2
  189. package/dist/server/handlers/telemetry.d.ts.map +1 -0
  190. package/dist/server/handlers/telemetry.js +3 -1
  191. package/dist/server/handlers/telemetry.js.map +1 -0
  192. package/dist/server/handlers/tools.cjs +11 -5
  193. package/dist/server/handlers/tools.cjs.map +1 -0
  194. package/dist/server/handlers/tools.d.ts +25 -4
  195. package/dist/server/handlers/tools.d.ts.map +1 -0
  196. package/dist/server/handlers/tools.js +3 -1
  197. package/dist/server/handlers/tools.js.map +1 -0
  198. package/dist/server/handlers/utils.cjs +8 -2
  199. package/dist/server/handlers/utils.cjs.map +1 -0
  200. package/dist/server/handlers/utils.d.ts +8 -1
  201. package/dist/server/handlers/utils.d.ts.map +1 -0
  202. package/dist/server/handlers/utils.js +3 -1
  203. package/dist/server/handlers/utils.js.map +1 -0
  204. package/dist/server/handlers/vector.cjs +9 -7
  205. package/dist/server/handlers/vector.cjs.map +1 -0
  206. package/dist/server/handlers/vector.d.ts +51 -6
  207. package/dist/server/handlers/vector.d.ts.map +1 -0
  208. package/dist/server/handlers/vector.js +3 -1
  209. package/dist/server/handlers/vector.js.map +1 -0
  210. package/dist/server/handlers/voice.cjs +10 -4
  211. package/dist/server/handlers/voice.cjs.map +1 -0
  212. package/dist/server/handlers/voice.d.ts +41 -3
  213. package/dist/server/handlers/voice.d.ts.map +1 -0
  214. package/dist/server/handlers/voice.js +3 -1
  215. package/dist/server/handlers/voice.js.map +1 -0
  216. package/dist/server/handlers/workflows.cjs +83 -13
  217. package/dist/server/handlers/workflows.cjs.map +1 -0
  218. package/dist/server/handlers/workflows.d.ts +151 -10
  219. package/dist/server/handlers/workflows.d.ts.map +1 -0
  220. package/dist/server/handlers/workflows.js +3 -1
  221. package/dist/server/handlers/workflows.js.map +1 -0
  222. package/dist/server/handlers.cjs +49 -27
  223. package/dist/server/handlers.cjs.map +1 -0
  224. package/dist/server/handlers.d.ts +14 -9
  225. package/dist/server/handlers.d.ts.map +1 -0
  226. package/dist/server/handlers.js +15 -9
  227. package/dist/server/handlers.js.map +1 -0
  228. package/dist/server/http-exception.d.ts +87 -0
  229. package/dist/server/http-exception.d.ts.map +1 -0
  230. package/dist/server/types.d.ts +10 -0
  231. package/dist/server/types.d.ts.map +1 -0
  232. package/dist/server/utils.d.ts +44 -0
  233. package/dist/server/utils.d.ts.map +1 -0
  234. package/dist/token-375W3LEI.cjs +64 -0
  235. package/dist/token-375W3LEI.cjs.map +1 -0
  236. package/dist/token-C3IMNCC4.js +62 -0
  237. package/dist/token-C3IMNCC4.js.map +1 -0
  238. package/dist/token-util-CV3RRG6K.cjs +9 -0
  239. package/dist/token-util-CV3RRG6K.cjs.map +1 -0
  240. package/dist/token-util-E5QO2RCL.js +7 -0
  241. package/dist/token-util-E5QO2RCL.js.map +1 -0
  242. package/package.json +50 -19
  243. package/dist/_tsup-dts-rollup.d.cts +0 -573
  244. package/dist/_tsup-dts-rollup.d.ts +0 -573
  245. package/dist/chunk-2FJURXCL.cjs +0 -213
  246. package/dist/chunk-3AHQ5RGN.js +0 -11
  247. package/dist/chunk-3EJZQ6TQ.js +0 -49
  248. package/dist/chunk-A7DF4ETD.cjs +0 -100
  249. package/dist/chunk-B64YROKU.cjs +0 -317
  250. package/dist/chunk-I6MBOQTH.js +0 -156
  251. package/dist/chunk-JLDXUWK7.cjs +0 -126
  252. package/dist/chunk-PDC4ZBQW.cjs +0 -126
  253. package/dist/chunk-QH6XWSXP.cjs +0 -5579
  254. package/dist/chunk-QN4KF3BH.cjs +0 -18
  255. package/dist/chunk-RBQASTUP.js +0 -203
  256. package/dist/chunk-SKBVVI24.cjs +0 -54
  257. package/dist/chunk-UE27Q3XD.cjs +0 -164
  258. package/dist/chunk-VK6FX47H.js +0 -5576
  259. package/dist/chunk-YANVFOYA.js +0 -120
  260. package/dist/chunk-ZLBRQFDD.cjs +0 -13
  261. package/dist/index.d.cts +0 -1
  262. package/dist/server/handlers/agents.d.cts +0 -6
  263. package/dist/server/handlers/error.d.cts +0 -1
  264. package/dist/server/handlers/logs.d.cts +0 -3
  265. package/dist/server/handlers/memory.d.cts +0 -8
  266. package/dist/server/handlers/network.cjs +0 -22
  267. package/dist/server/handlers/network.d.cts +0 -4
  268. package/dist/server/handlers/network.d.ts +0 -4
  269. package/dist/server/handlers/network.js +0 -1
  270. package/dist/server/handlers/telemetry.d.cts +0 -2
  271. package/dist/server/handlers/tools.d.cts +0 -4
  272. package/dist/server/handlers/utils.d.cts +0 -1
  273. package/dist/server/handlers/vector.d.cts +0 -6
  274. package/dist/server/handlers/voice.d.cts +0 -3
  275. package/dist/server/handlers/workflows.d.cts +0 -10
  276. package/dist/server/handlers.d.cts +0 -9
@@ -0,0 +1,909 @@
1
+ import { getWorkflowInfo, WorkflowRegistry } from './chunk-YWOK4F5A.js';
2
+ import { handleError } from './chunk-CY4TP3FK.js';
3
+ import { HTTPException } from './chunk-MMROOK5J.js';
4
+ import { __export } from './chunk-PR4QN5HX.js';
5
+ import { ReadableStream, TransformStream } from 'stream/web';
6
+
7
+ // src/server/handlers/workflows.ts
8
+ var workflows_exports = {};
9
+ __export(workflows_exports, {
10
+ cancelWorkflowRunHandler: () => cancelWorkflowRunHandler,
11
+ createWorkflowRunHandler: () => createWorkflowRunHandler,
12
+ getWorkflowByIdHandler: () => getWorkflowByIdHandler,
13
+ getWorkflowRunByIdHandler: () => getWorkflowRunByIdHandler,
14
+ getWorkflowRunExecutionResultHandler: () => getWorkflowRunExecutionResultHandler,
15
+ getWorkflowRunsHandler: () => getWorkflowRunsHandler,
16
+ getWorkflowsHandler: () => getWorkflowsHandler,
17
+ observeStreamLegacyWorkflowHandler: () => observeStreamLegacyWorkflowHandler,
18
+ observeStreamVNextWorkflowHandler: () => observeStreamVNextWorkflowHandler,
19
+ observeStreamWorkflowHandler: () => observeStreamWorkflowHandler,
20
+ restartAllActiveWorkflowRunsAsyncHandler: () => restartAllActiveWorkflowRunsAsyncHandler,
21
+ restartAllActiveWorkflowRunsHandler: () => restartAllActiveWorkflowRunsHandler,
22
+ restartAsyncWorkflowHandler: () => restartAsyncWorkflowHandler,
23
+ restartWorkflowHandler: () => restartWorkflowHandler,
24
+ resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
25
+ resumeStreamWorkflowHandler: () => resumeStreamWorkflowHandler,
26
+ resumeWorkflowHandler: () => resumeWorkflowHandler,
27
+ sendWorkflowRunEventHandler: () => sendWorkflowRunEventHandler,
28
+ startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
29
+ startWorkflowRunHandler: () => startWorkflowRunHandler,
30
+ streamLegacyWorkflowHandler: () => streamLegacyWorkflowHandler,
31
+ streamVNextWorkflowHandler: () => streamVNextWorkflowHandler,
32
+ streamWorkflowHandler: () => streamWorkflowHandler,
33
+ timeTravelAsyncWorkflowHandler: () => timeTravelAsyncWorkflowHandler,
34
+ timeTravelStreamWorkflowHandler: () => timeTravelStreamWorkflowHandler,
35
+ timeTravelWorkflowHandler: () => timeTravelWorkflowHandler,
36
+ watchWorkflowHandler: () => watchWorkflowHandler
37
+ });
38
+ async function getWorkflowsHandler({ mastra }) {
39
+ try {
40
+ const workflows = mastra.getWorkflows({ serialized: false });
41
+ const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
42
+ acc[key] = getWorkflowInfo(workflow);
43
+ return acc;
44
+ }, {});
45
+ return _workflows;
46
+ } catch (error) {
47
+ return handleError(error, "Error getting workflows");
48
+ }
49
+ }
50
+ async function getWorkflowsFromSystem({ mastra, workflowId }) {
51
+ const logger = mastra.getLogger();
52
+ if (!workflowId) {
53
+ throw new HTTPException(400, { message: "Workflow ID is required" });
54
+ }
55
+ let workflow;
56
+ workflow = WorkflowRegistry.getWorkflow(workflowId);
57
+ if (!workflow) {
58
+ try {
59
+ workflow = mastra.getWorkflow(workflowId);
60
+ } catch (error) {
61
+ logger.debug("Error getting workflow, searching agents for workflow", error);
62
+ }
63
+ }
64
+ if (!workflow) {
65
+ logger.debug("Workflow not found, searching agents for workflow", { workflowId });
66
+ const agents = mastra.getAgents();
67
+ if (Object.keys(agents || {}).length) {
68
+ for (const [_, agent] of Object.entries(agents)) {
69
+ try {
70
+ const workflows = await agent.getWorkflows();
71
+ if (workflows[workflowId]) {
72
+ workflow = workflows[workflowId];
73
+ break;
74
+ }
75
+ break;
76
+ } catch (error) {
77
+ logger.debug("Error getting workflow from agent", error);
78
+ }
79
+ }
80
+ }
81
+ }
82
+ if (!workflow) {
83
+ throw new HTTPException(404, { message: "Workflow not found" });
84
+ }
85
+ return { workflow };
86
+ }
87
+ async function getWorkflowByIdHandler({ mastra, workflowId }) {
88
+ try {
89
+ if (!workflowId) {
90
+ throw new HTTPException(400, { message: "Workflow ID is required" });
91
+ }
92
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
93
+ if (!workflow) {
94
+ throw new HTTPException(404, { message: "Workflow not found" });
95
+ }
96
+ return getWorkflowInfo(workflow);
97
+ } catch (error) {
98
+ return handleError(error, "Error getting workflow");
99
+ }
100
+ }
101
+ async function getWorkflowRunByIdHandler({
102
+ mastra,
103
+ workflowId,
104
+ runId
105
+ }) {
106
+ try {
107
+ if (!workflowId) {
108
+ throw new HTTPException(400, { message: "Workflow ID is required" });
109
+ }
110
+ if (!runId) {
111
+ throw new HTTPException(400, { message: "Run ID is required" });
112
+ }
113
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
114
+ if (!workflow) {
115
+ throw new HTTPException(404, { message: "Workflow not found" });
116
+ }
117
+ const run = await workflow.getWorkflowRunById(runId);
118
+ if (!run) {
119
+ throw new HTTPException(404, { message: "Workflow run not found" });
120
+ }
121
+ return run;
122
+ } catch (error) {
123
+ return handleError(error, "Error getting workflow run");
124
+ }
125
+ }
126
+ async function getWorkflowRunExecutionResultHandler({
127
+ mastra,
128
+ workflowId,
129
+ runId
130
+ }) {
131
+ try {
132
+ if (!workflowId) {
133
+ throw new HTTPException(400, { message: "Workflow ID is required" });
134
+ }
135
+ if (!runId) {
136
+ throw new HTTPException(400, { message: "Run ID is required" });
137
+ }
138
+ const workflow = mastra.getWorkflow(workflowId);
139
+ if (!workflow) {
140
+ throw new HTTPException(404, { message: "Workflow not found" });
141
+ }
142
+ const executionResult = await workflow.getWorkflowRunExecutionResult(runId);
143
+ if (!executionResult) {
144
+ throw new HTTPException(404, { message: "Workflow run execution result not found" });
145
+ }
146
+ return executionResult;
147
+ } catch (error) {
148
+ return handleError(error, "Error getting workflow run execution result");
149
+ }
150
+ }
151
+ async function createWorkflowRunHandler({
152
+ mastra,
153
+ workflowId,
154
+ runId: prevRunId
155
+ }) {
156
+ try {
157
+ if (!workflowId) {
158
+ throw new HTTPException(400, { message: "Workflow ID is required" });
159
+ }
160
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
161
+ if (!workflow) {
162
+ throw new HTTPException(404, { message: "Workflow not found" });
163
+ }
164
+ const run = await workflow.createRunAsync({ runId: prevRunId });
165
+ return { runId: run.runId };
166
+ } catch (error) {
167
+ return handleError(error, "Error creating workflow run");
168
+ }
169
+ }
170
+ async function startAsyncWorkflowHandler({
171
+ mastra,
172
+ runtimeContext,
173
+ workflowId,
174
+ runId,
175
+ inputData,
176
+ tracingOptions
177
+ }) {
178
+ try {
179
+ if (!workflowId) {
180
+ throw new HTTPException(400, { message: "Workflow ID is required" });
181
+ }
182
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
183
+ if (!workflow) {
184
+ throw new HTTPException(404, { message: "Workflow not found" });
185
+ }
186
+ const _run = await workflow.createRunAsync({ runId });
187
+ const result = await _run.start({
188
+ inputData,
189
+ runtimeContext,
190
+ tracingOptions
191
+ });
192
+ return result;
193
+ } catch (error) {
194
+ return handleError(error, "Error starting async workflow");
195
+ }
196
+ }
197
+ async function startWorkflowRunHandler({
198
+ mastra,
199
+ runtimeContext,
200
+ workflowId,
201
+ runId,
202
+ inputData,
203
+ tracingOptions
204
+ }) {
205
+ try {
206
+ if (!workflowId) {
207
+ throw new HTTPException(400, { message: "Workflow ID is required" });
208
+ }
209
+ if (!runId) {
210
+ throw new HTTPException(400, { message: "runId required to start run" });
211
+ }
212
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
213
+ if (!workflow) {
214
+ throw new HTTPException(404, { message: "Workflow not found" });
215
+ }
216
+ const run = await workflow.getWorkflowRunById(runId);
217
+ if (!run) {
218
+ throw new HTTPException(404, { message: "Workflow run not found" });
219
+ }
220
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
221
+ void _run.start({
222
+ inputData,
223
+ runtimeContext,
224
+ tracingOptions
225
+ });
226
+ return { message: "Workflow run started" };
227
+ } catch (e) {
228
+ return handleError(e, "Error starting workflow run");
229
+ }
230
+ }
231
+ async function watchWorkflowHandler({
232
+ mastra,
233
+ workflowId,
234
+ runId,
235
+ eventType = "watch"
236
+ }) {
237
+ try {
238
+ if (!workflowId) {
239
+ throw new HTTPException(400, { message: "Workflow ID is required" });
240
+ }
241
+ if (!runId) {
242
+ throw new HTTPException(400, { message: "runId required to watch workflow" });
243
+ }
244
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
245
+ if (!workflow) {
246
+ throw new HTTPException(404, { message: "Workflow not found" });
247
+ }
248
+ const run = await workflow.getWorkflowRunById(runId);
249
+ if (!run) {
250
+ throw new HTTPException(404, { message: "Workflow run not found" });
251
+ }
252
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
253
+ let unwatch;
254
+ let asyncRef = null;
255
+ const stream = new ReadableStream({
256
+ start(controller) {
257
+ if (eventType === "watch") {
258
+ unwatch = _run.watch((event) => {
259
+ const { type, payload, eventTimestamp } = event;
260
+ controller.enqueue(JSON.stringify({ type, payload, eventTimestamp, runId }));
261
+ if (asyncRef) {
262
+ clearImmediate(asyncRef);
263
+ asyncRef = null;
264
+ }
265
+ asyncRef = setImmediate(async () => {
266
+ const runDone = payload.workflowState?.status !== "running";
267
+ if (runDone) {
268
+ controller.close();
269
+ unwatch?.();
270
+ }
271
+ });
272
+ }, eventType);
273
+ } else {
274
+ unwatch = _run.watch((event) => {
275
+ const { type, payload } = event;
276
+ controller.enqueue(JSON.stringify({ type, payload, runId }));
277
+ if (asyncRef) {
278
+ clearImmediate(asyncRef);
279
+ asyncRef = null;
280
+ }
281
+ asyncRef = setImmediate(async () => {
282
+ const runDone = type === "workflow-finish";
283
+ if (runDone) {
284
+ controller.close();
285
+ unwatch?.();
286
+ }
287
+ });
288
+ }, eventType);
289
+ }
290
+ },
291
+ cancel() {
292
+ if (asyncRef) {
293
+ clearImmediate(asyncRef);
294
+ asyncRef = null;
295
+ }
296
+ unwatch?.();
297
+ }
298
+ });
299
+ return stream;
300
+ } catch (error) {
301
+ return handleError(error, "Error watching workflow");
302
+ }
303
+ }
304
+ async function streamWorkflowHandler({
305
+ mastra,
306
+ runtimeContext,
307
+ workflowId,
308
+ runId,
309
+ inputData,
310
+ tracingOptions
311
+ }) {
312
+ return streamVNextWorkflowHandler({ mastra, workflowId, runId, inputData, runtimeContext, tracingOptions });
313
+ }
314
+ async function streamLegacyWorkflowHandler({
315
+ mastra,
316
+ runtimeContext,
317
+ workflowId,
318
+ runId,
319
+ inputData,
320
+ tracingOptions
321
+ }) {
322
+ try {
323
+ if (!workflowId) {
324
+ throw new HTTPException(400, { message: "Workflow ID is required" });
325
+ }
326
+ if (!runId) {
327
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
328
+ }
329
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
330
+ if (!workflow) {
331
+ throw new HTTPException(404, { message: "Workflow not found" });
332
+ }
333
+ const serverCache = mastra.getServerCache();
334
+ const run = await workflow.createRunAsync({ runId });
335
+ const result = run.streamLegacy({
336
+ inputData,
337
+ runtimeContext,
338
+ onChunk: async (chunk) => {
339
+ if (serverCache) {
340
+ const cacheKey = runId;
341
+ await serverCache.listPush(cacheKey, chunk);
342
+ }
343
+ },
344
+ tracingOptions
345
+ });
346
+ return result;
347
+ } catch (error) {
348
+ return handleError(error, "Error executing workflow");
349
+ }
350
+ }
351
+ async function observeStreamLegacyWorkflowHandler({
352
+ mastra,
353
+ workflowId,
354
+ runId
355
+ }) {
356
+ try {
357
+ if (!workflowId) {
358
+ throw new HTTPException(400, { message: "Workflow ID is required" });
359
+ }
360
+ if (!runId) {
361
+ throw new HTTPException(400, { message: "runId required to observe workflow stream" });
362
+ }
363
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
364
+ if (!workflow) {
365
+ throw new HTTPException(404, { message: "Workflow not found" });
366
+ }
367
+ const run = await workflow.getWorkflowRunById(runId);
368
+ if (!run) {
369
+ throw new HTTPException(404, { message: "Workflow run not found" });
370
+ }
371
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
372
+ const serverCache = mastra.getServerCache();
373
+ if (!serverCache) {
374
+ throw new HTTPException(500, { message: "Server cache not found" });
375
+ }
376
+ const transformStream = new TransformStream();
377
+ const writer = transformStream.writable.getWriter();
378
+ const cachedRunChunks = await serverCache.listFromTo(runId, 0);
379
+ for (const chunk of cachedRunChunks) {
380
+ await writer.write(chunk);
381
+ }
382
+ writer.releaseLock();
383
+ const result = _run.observeStreamLegacy();
384
+ return result.stream?.pipeThrough(transformStream);
385
+ } catch (error) {
386
+ return handleError(error, "Error observing workflow stream");
387
+ }
388
+ }
389
+ async function observeStreamWorkflowHandler({
390
+ mastra,
391
+ workflowId,
392
+ runId
393
+ }) {
394
+ return observeStreamVNextWorkflowHandler({ mastra, workflowId, runId });
395
+ }
396
+ async function streamVNextWorkflowHandler({
397
+ mastra,
398
+ runtimeContext,
399
+ workflowId,
400
+ runId,
401
+ inputData,
402
+ closeOnSuspend,
403
+ tracingOptions
404
+ }) {
405
+ try {
406
+ if (!workflowId) {
407
+ throw new HTTPException(400, { message: "Workflow ID is required" });
408
+ }
409
+ if (!runId) {
410
+ throw new HTTPException(400, { message: "runId required to stream workflow" });
411
+ }
412
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
413
+ if (!workflow) {
414
+ throw new HTTPException(404, { message: "Workflow not found" });
415
+ }
416
+ const serverCache = mastra.getServerCache();
417
+ const run = await workflow.createRunAsync({ runId });
418
+ const result = run.stream({
419
+ inputData,
420
+ runtimeContext,
421
+ closeOnSuspend,
422
+ tracingOptions
423
+ });
424
+ return result.fullStream.pipeThrough(
425
+ new TransformStream({
426
+ transform(chunk, controller) {
427
+ if (serverCache) {
428
+ const cacheKey = runId;
429
+ serverCache.listPush(cacheKey, chunk).catch(() => {
430
+ });
431
+ }
432
+ controller.enqueue(chunk);
433
+ }
434
+ })
435
+ );
436
+ } catch (error) {
437
+ return handleError(error, "Error streaming workflow");
438
+ }
439
+ }
440
+ async function observeStreamVNextWorkflowHandler({
441
+ mastra,
442
+ workflowId,
443
+ runId
444
+ }) {
445
+ try {
446
+ if (!workflowId) {
447
+ throw new HTTPException(400, { message: "Workflow ID is required" });
448
+ }
449
+ if (!runId) {
450
+ throw new HTTPException(400, { message: "runId required to observe workflow stream" });
451
+ }
452
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
453
+ if (!workflow) {
454
+ throw new HTTPException(404, { message: "Workflow not found" });
455
+ }
456
+ const run = await workflow.getWorkflowRunById(runId);
457
+ if (!run) {
458
+ throw new HTTPException(404, { message: "Workflow run not found" });
459
+ }
460
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
461
+ const serverCache = mastra.getServerCache();
462
+ if (!serverCache) {
463
+ throw new HTTPException(500, { message: "Server cache not found" });
464
+ }
465
+ const cachedRunChunks = await serverCache.listFromTo(runId, 0);
466
+ const combinedStream = new ReadableStream({
467
+ start(controller) {
468
+ const emitCachedChunks = async () => {
469
+ for (const chunk of cachedRunChunks) {
470
+ controller.enqueue(chunk);
471
+ }
472
+ };
473
+ const liveStream = _run.observeStream();
474
+ const reader = liveStream.getReader();
475
+ const pump = async () => {
476
+ try {
477
+ while (true) {
478
+ const { done, value } = await reader.read();
479
+ if (done) {
480
+ controller.close();
481
+ break;
482
+ }
483
+ controller.enqueue(value);
484
+ }
485
+ } catch (error) {
486
+ controller.error(error);
487
+ } finally {
488
+ reader.releaseLock();
489
+ }
490
+ };
491
+ void emitCachedChunks().then(() => {
492
+ void pump();
493
+ }).catch((error) => {
494
+ controller.error(error);
495
+ });
496
+ }
497
+ });
498
+ return combinedStream;
499
+ } catch (error) {
500
+ return handleError(error, "Error observing workflow stream");
501
+ }
502
+ }
503
+ async function resumeAsyncWorkflowHandler({
504
+ mastra,
505
+ workflowId,
506
+ runId,
507
+ body,
508
+ runtimeContext,
509
+ tracingOptions
510
+ }) {
511
+ try {
512
+ if (!workflowId) {
513
+ throw new HTTPException(400, { message: "Workflow ID is required" });
514
+ }
515
+ if (!runId) {
516
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
517
+ }
518
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
519
+ if (!workflow) {
520
+ throw new HTTPException(404, { message: "Workflow not found" });
521
+ }
522
+ const run = await workflow.getWorkflowRunById(runId);
523
+ if (!run) {
524
+ throw new HTTPException(404, { message: "Workflow run not found" });
525
+ }
526
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
527
+ const result = await _run.resume({
528
+ step: body.step,
529
+ resumeData: body.resumeData,
530
+ runtimeContext,
531
+ tracingOptions
532
+ });
533
+ return result;
534
+ } catch (error) {
535
+ return handleError(error, "Error resuming workflow step");
536
+ }
537
+ }
538
+ async function resumeWorkflowHandler({
539
+ mastra,
540
+ workflowId,
541
+ runId,
542
+ body,
543
+ runtimeContext,
544
+ tracingOptions
545
+ }) {
546
+ try {
547
+ if (!workflowId) {
548
+ throw new HTTPException(400, { message: "Workflow ID is required" });
549
+ }
550
+ if (!runId) {
551
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
552
+ }
553
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
554
+ if (!workflow) {
555
+ throw new HTTPException(404, { message: "Workflow not found" });
556
+ }
557
+ const run = await workflow.getWorkflowRunById(runId);
558
+ if (!run) {
559
+ throw new HTTPException(404, { message: "Workflow run not found" });
560
+ }
561
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
562
+ void _run.resume({
563
+ step: body.step,
564
+ resumeData: body.resumeData,
565
+ runtimeContext,
566
+ tracingOptions
567
+ });
568
+ return { message: "Workflow run resumed" };
569
+ } catch (error) {
570
+ return handleError(error, "Error resuming workflow");
571
+ }
572
+ }
573
+ async function resumeStreamWorkflowHandler({
574
+ mastra,
575
+ workflowId,
576
+ runId,
577
+ body,
578
+ runtimeContext,
579
+ tracingOptions
580
+ }) {
581
+ try {
582
+ if (!workflowId) {
583
+ throw new HTTPException(400, { message: "Workflow ID is required" });
584
+ }
585
+ if (!runId) {
586
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
587
+ }
588
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
589
+ if (!workflow) {
590
+ throw new HTTPException(404, { message: "Workflow not found" });
591
+ }
592
+ const run = await workflow.getWorkflowRunById(runId);
593
+ if (!run) {
594
+ throw new HTTPException(404, { message: "Workflow run not found" });
595
+ }
596
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
597
+ const serverCache = mastra.getServerCache();
598
+ const stream = _run.resumeStream({
599
+ step: body.step,
600
+ resumeData: body.resumeData,
601
+ runtimeContext,
602
+ tracingOptions
603
+ }).fullStream.pipeThrough(
604
+ new TransformStream({
605
+ transform(chunk, controller) {
606
+ if (serverCache) {
607
+ const cacheKey = runId;
608
+ serverCache.listPush(cacheKey, chunk).catch(() => {
609
+ });
610
+ }
611
+ controller.enqueue(chunk);
612
+ }
613
+ })
614
+ );
615
+ return stream;
616
+ } catch (error) {
617
+ return handleError(error, "Error resuming workflow");
618
+ }
619
+ }
620
+ async function getWorkflowRunsHandler({
621
+ mastra,
622
+ workflowId,
623
+ fromDate,
624
+ toDate,
625
+ limit,
626
+ offset,
627
+ resourceId
628
+ }) {
629
+ try {
630
+ if (!workflowId) {
631
+ throw new HTTPException(400, { message: "Workflow ID is required" });
632
+ }
633
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
634
+ if (!workflow) {
635
+ throw new HTTPException(404, { message: "Workflow not found" });
636
+ }
637
+ const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
638
+ runs: [],
639
+ total: 0
640
+ };
641
+ return workflowRuns;
642
+ } catch (error) {
643
+ return handleError(error, "Error getting workflow runs");
644
+ }
645
+ }
646
+ async function cancelWorkflowRunHandler({
647
+ mastra,
648
+ workflowId,
649
+ runId
650
+ }) {
651
+ try {
652
+ if (!workflowId) {
653
+ throw new HTTPException(400, { message: "Workflow ID is required" });
654
+ }
655
+ if (!runId) {
656
+ throw new HTTPException(400, { message: "runId required to cancel workflow run" });
657
+ }
658
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
659
+ if (!workflow) {
660
+ throw new HTTPException(404, { message: "Workflow not found" });
661
+ }
662
+ const run = await workflow.getWorkflowRunById(runId);
663
+ if (!run) {
664
+ throw new HTTPException(404, { message: "Workflow run not found" });
665
+ }
666
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
667
+ await _run.cancel();
668
+ return { message: "Workflow run cancelled" };
669
+ } catch (error) {
670
+ return handleError(error, "Error canceling workflow run");
671
+ }
672
+ }
673
+ async function sendWorkflowRunEventHandler({
674
+ mastra,
675
+ workflowId,
676
+ runId,
677
+ event,
678
+ data
679
+ }) {
680
+ try {
681
+ if (!workflowId) {
682
+ throw new HTTPException(400, { message: "Workflow ID is required" });
683
+ }
684
+ if (!runId) {
685
+ throw new HTTPException(400, { message: "runId required to send workflow run event" });
686
+ }
687
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
688
+ if (!workflow) {
689
+ throw new HTTPException(404, { message: "Workflow not found" });
690
+ }
691
+ const run = await workflow.getWorkflowRunById(runId);
692
+ if (!run) {
693
+ throw new HTTPException(404, { message: "Workflow run not found" });
694
+ }
695
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
696
+ await _run.sendEvent(event, data);
697
+ return { message: "Workflow run event sent" };
698
+ } catch (error) {
699
+ return handleError(error, "Error sending workflow run event");
700
+ }
701
+ }
702
+ async function restartAsyncWorkflowHandler({
703
+ mastra,
704
+ workflowId,
705
+ runId,
706
+ runtimeContext,
707
+ tracingOptions
708
+ }) {
709
+ try {
710
+ if (!workflowId) {
711
+ throw new HTTPException(400, { message: "Workflow ID is required" });
712
+ }
713
+ if (!runId) {
714
+ throw new HTTPException(400, { message: "runId required to restart workflow" });
715
+ }
716
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
717
+ if (!workflow) {
718
+ throw new HTTPException(404, { message: "Workflow not found" });
719
+ }
720
+ const run = await workflow.getWorkflowRunById(runId);
721
+ if (!run) {
722
+ throw new HTTPException(404, { message: "Workflow run not found" });
723
+ }
724
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
725
+ const result = await _run.restart({
726
+ runtimeContext,
727
+ tracingOptions
728
+ });
729
+ return result;
730
+ } catch (error) {
731
+ return handleError(error, "Error restarting workflow");
732
+ }
733
+ }
734
+ async function restartWorkflowHandler({
735
+ mastra,
736
+ workflowId,
737
+ runId,
738
+ runtimeContext,
739
+ tracingOptions
740
+ }) {
741
+ try {
742
+ if (!workflowId) {
743
+ throw new HTTPException(400, { message: "Workflow ID is required" });
744
+ }
745
+ if (!runId) {
746
+ throw new HTTPException(400, { message: "runId required to restart workflow" });
747
+ }
748
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
749
+ if (!workflow) {
750
+ throw new HTTPException(404, { message: "Workflow not found" });
751
+ }
752
+ const run = await workflow.getWorkflowRunById(runId);
753
+ if (!run) {
754
+ throw new HTTPException(404, { message: "Workflow run not found" });
755
+ }
756
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
757
+ void _run.restart({
758
+ runtimeContext,
759
+ tracingOptions
760
+ });
761
+ return { message: "Workflow run restarted" };
762
+ } catch (error) {
763
+ return handleError(error, "Error restarting workflow");
764
+ }
765
+ }
766
+ async function restartAllActiveWorkflowRunsAsyncHandler({ mastra, workflowId }) {
767
+ try {
768
+ if (!workflowId) {
769
+ throw new HTTPException(400, { message: "Workflow ID is required" });
770
+ }
771
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
772
+ if (!workflow) {
773
+ throw new HTTPException(404, { message: "Workflow not found" });
774
+ }
775
+ await workflow.restartAllActiveWorkflowRuns();
776
+ return { message: "All active workflow runs restarted" };
777
+ } catch (error) {
778
+ return handleError(error, "Error restarting all active workflow runs");
779
+ }
780
+ }
781
+ async function restartAllActiveWorkflowRunsHandler({ mastra, workflowId }) {
782
+ try {
783
+ if (!workflowId) {
784
+ throw new HTTPException(400, { message: "Workflow ID is required" });
785
+ }
786
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
787
+ if (!workflow) {
788
+ throw new HTTPException(404, { message: "Workflow not found" });
789
+ }
790
+ void workflow.restartAllActiveWorkflowRuns();
791
+ return { message: "All active workflow runs restarted" };
792
+ } catch (error) {
793
+ return handleError(error, "Error restarting all active workflow runs");
794
+ }
795
+ }
796
+ async function timeTravelAsyncWorkflowHandler({
797
+ mastra,
798
+ workflowId,
799
+ runId,
800
+ body,
801
+ runtimeContext,
802
+ tracingOptions
803
+ }) {
804
+ try {
805
+ if (!workflowId) {
806
+ throw new HTTPException(400, { message: "Workflow ID is required" });
807
+ }
808
+ if (!runId) {
809
+ throw new HTTPException(400, { message: "runId required to time travel workflow" });
810
+ }
811
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
812
+ if (!workflow) {
813
+ throw new HTTPException(404, { message: "Workflow not found" });
814
+ }
815
+ const run = await workflow.getWorkflowRunById(runId);
816
+ if (!run) {
817
+ throw new HTTPException(404, { message: "Workflow run not found" });
818
+ }
819
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
820
+ const result = await _run.timeTravel({
821
+ ...body,
822
+ runtimeContext,
823
+ tracingOptions
824
+ });
825
+ return result;
826
+ } catch (error) {
827
+ return handleError(error, "Error time traveling workflow");
828
+ }
829
+ }
830
+ async function timeTravelWorkflowHandler({
831
+ mastra,
832
+ workflowId,
833
+ runId,
834
+ body,
835
+ runtimeContext,
836
+ tracingOptions
837
+ }) {
838
+ try {
839
+ if (!workflowId) {
840
+ throw new HTTPException(400, { message: "Workflow ID is required" });
841
+ }
842
+ if (!runId) {
843
+ throw new HTTPException(400, { message: "runId required to time travel workflow" });
844
+ }
845
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
846
+ if (!workflow) {
847
+ throw new HTTPException(404, { message: "Workflow not found" });
848
+ }
849
+ const run = await workflow.getWorkflowRunById(runId);
850
+ if (!run) {
851
+ throw new HTTPException(404, { message: "Workflow run not found" });
852
+ }
853
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
854
+ void _run.timeTravel({
855
+ ...body,
856
+ runtimeContext,
857
+ tracingOptions
858
+ });
859
+ return { message: "Workflow run time travel started" };
860
+ } catch (error) {
861
+ return handleError(error, "Error time traveling workflow");
862
+ }
863
+ }
864
+ async function timeTravelStreamWorkflowHandler({
865
+ mastra,
866
+ workflowId,
867
+ runId,
868
+ body,
869
+ runtimeContext,
870
+ tracingOptions
871
+ }) {
872
+ try {
873
+ if (!workflowId) {
874
+ throw new HTTPException(400, { message: "Workflow ID is required" });
875
+ }
876
+ if (!runId) {
877
+ throw new HTTPException(400, { message: "runId required to time travel workflow" });
878
+ }
879
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
880
+ if (!workflow) {
881
+ throw new HTTPException(404, { message: "Workflow not found" });
882
+ }
883
+ const run = await workflow.getWorkflowRunById(runId);
884
+ if (!run) {
885
+ throw new HTTPException(404, { message: "Workflow run not found" });
886
+ }
887
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
888
+ const serverCache = mastra.getServerCache();
889
+ const result = _run.timeTravelStream({ ...body, runtimeContext, tracingOptions });
890
+ return result.fullStream.pipeThrough(
891
+ new TransformStream({
892
+ transform(chunk, controller) {
893
+ if (serverCache) {
894
+ const cacheKey = runId;
895
+ serverCache.listPush(cacheKey, chunk).catch(() => {
896
+ });
897
+ }
898
+ controller.enqueue(chunk);
899
+ }
900
+ })
901
+ );
902
+ } catch (error) {
903
+ return handleError(error, "Error resuming workflow");
904
+ }
905
+ }
906
+
907
+ export { cancelWorkflowRunHandler, createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunExecutionResultHandler, getWorkflowRunsHandler, getWorkflowsHandler, observeStreamLegacyWorkflowHandler, observeStreamVNextWorkflowHandler, observeStreamWorkflowHandler, restartAllActiveWorkflowRunsAsyncHandler, restartAllActiveWorkflowRunsHandler, restartAsyncWorkflowHandler, restartWorkflowHandler, resumeAsyncWorkflowHandler, resumeStreamWorkflowHandler, resumeWorkflowHandler, sendWorkflowRunEventHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamLegacyWorkflowHandler, streamVNextWorkflowHandler, streamWorkflowHandler, timeTravelAsyncWorkflowHandler, timeTravelStreamWorkflowHandler, timeTravelWorkflowHandler, watchWorkflowHandler, workflows_exports };
908
+ //# sourceMappingURL=chunk-QGNHNNJR.js.map
909
+ //# sourceMappingURL=chunk-QGNHNNJR.js.map