@mastra/server 0.0.0-default-storage-virtual-file-20250410035748 → 0.0.0-dynamic-model-router-20251009231604

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 (277) hide show
  1. package/CHANGELOG.md +3969 -0
  2. package/LICENSE.md +15 -0
  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-3Q7FKRVX.cjs +682 -0
  9. package/dist/chunk-3Q7FKRVX.cjs.map +1 -0
  10. package/dist/chunk-3SNGNFUJ.cjs +128 -0
  11. package/dist/chunk-3SNGNFUJ.cjs.map +1 -0
  12. package/dist/{chunk-L7XE5QTW.js → chunk-4QCXUEAT.js} +11 -2
  13. package/dist/chunk-4QCXUEAT.js.map +1 -0
  14. package/dist/chunk-5BNQIYQN.js +189 -0
  15. package/dist/chunk-5BNQIYQN.js.map +1 -0
  16. package/dist/{chunk-DVPP5S6I.js → chunk-67GYDFSB.js} +35 -10
  17. package/dist/chunk-67GYDFSB.js.map +1 -0
  18. package/dist/{chunk-CWSDZEZG.cjs → chunk-6ZR275MD.cjs} +39 -13
  19. package/dist/chunk-6ZR275MD.cjs.map +1 -0
  20. package/dist/{chunk-FV45V6WC.cjs → chunk-7NADHFD2.cjs} +3 -7
  21. package/dist/chunk-7NADHFD2.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-YNSGUC2O.js → chunk-AHB4JCIQ.js} +58 -14
  25. package/dist/chunk-AHB4JCIQ.js.map +1 -0
  26. package/dist/chunk-BATEJLED.js +124 -0
  27. package/dist/chunk-BATEJLED.js.map +1 -0
  28. package/dist/chunk-CY4TP3FK.js +16 -0
  29. package/dist/chunk-CY4TP3FK.js.map +1 -0
  30. package/dist/chunk-DB63UMTV.js +660 -0
  31. package/dist/chunk-DB63UMTV.js.map +1 -0
  32. package/dist/{chunk-M56ECCHK.cjs → chunk-EP3JQDPD.cjs} +22 -19
  33. package/dist/chunk-EP3JQDPD.cjs.map +1 -0
  34. package/dist/chunk-FZNS32WJ.js +46 -0
  35. package/dist/chunk-FZNS32WJ.js.map +1 -0
  36. package/dist/chunk-G4PUALCE.cjs +28 -0
  37. package/dist/chunk-G4PUALCE.cjs.map +1 -0
  38. package/dist/chunk-GU4EWMZB.cjs +769 -0
  39. package/dist/chunk-GU4EWMZB.cjs.map +1 -0
  40. package/dist/chunk-HKW2536J.js +17477 -0
  41. package/dist/chunk-HKW2536J.js.map +1 -0
  42. package/dist/chunk-HPXAM2PG.js +477 -0
  43. package/dist/chunk-HPXAM2PG.js.map +1 -0
  44. package/dist/chunk-I3C4ODGV.cjs +335 -0
  45. package/dist/chunk-I3C4ODGV.cjs.map +1 -0
  46. package/dist/chunk-KJJA7GPJ.cjs +17513 -0
  47. package/dist/chunk-KJJA7GPJ.cjs.map +1 -0
  48. package/dist/chunk-LF2ZLOFP.js +767 -0
  49. package/dist/chunk-LF2ZLOFP.js.map +1 -0
  50. package/dist/{chunk-ILW7XYNJ.js → chunk-LLUOPR3J.js} +99 -72
  51. package/dist/chunk-LLUOPR3J.js.map +1 -0
  52. package/dist/chunk-LNT5N7XW.cjs +197 -0
  53. package/dist/chunk-LNT5N7XW.cjs.map +1 -0
  54. package/dist/chunk-LPM6BBAX.cjs +1043 -0
  55. package/dist/chunk-LPM6BBAX.cjs.map +1 -0
  56. package/dist/chunk-LV66LYKV.js +662 -0
  57. package/dist/chunk-LV66LYKV.js.map +1 -0
  58. package/dist/{chunk-TRDNDNGQ.js → chunk-MMROOK5J.js} +4 -7
  59. package/dist/chunk-MMROOK5J.js.map +1 -0
  60. package/dist/chunk-MQDBNHBT.cjs +680 -0
  61. package/dist/chunk-MQDBNHBT.cjs.map +1 -0
  62. package/dist/{chunk-4JINXASC.js → chunk-MYR4PVGN.js} +7 -4
  63. package/dist/chunk-MYR4PVGN.js.map +1 -0
  64. package/dist/chunk-O7I5CWRX.cjs +44 -0
  65. package/dist/chunk-O7I5CWRX.cjs.map +1 -0
  66. package/dist/chunk-OYL5TBJW.cjs +48 -0
  67. package/dist/chunk-OYL5TBJW.cjs.map +1 -0
  68. package/dist/chunk-PR4QN5HX.js +39 -0
  69. package/dist/chunk-PR4QN5HX.js.map +1 -0
  70. package/dist/{chunk-3RVHWGWO.js → chunk-QQXMIP6C.js} +49 -22
  71. package/dist/chunk-QQXMIP6C.js.map +1 -0
  72. package/dist/chunk-RE4RPXT2.cjs +18 -0
  73. package/dist/chunk-RE4RPXT2.cjs.map +1 -0
  74. package/dist/chunk-RQK4FQUD.js +1012 -0
  75. package/dist/chunk-RQK4FQUD.js.map +1 -0
  76. package/dist/chunk-SIW6CYO3.js +254 -0
  77. package/dist/chunk-SIW6CYO3.js.map +1 -0
  78. package/dist/chunk-TOP25AIO.cjs +485 -0
  79. package/dist/chunk-TOP25AIO.cjs.map +1 -0
  80. package/dist/chunk-TRGAMKHX.cjs +167 -0
  81. package/dist/chunk-TRGAMKHX.cjs.map +1 -0
  82. package/dist/chunk-VY4ENABS.cjs +135 -0
  83. package/dist/chunk-VY4ENABS.cjs.map +1 -0
  84. package/dist/chunk-WHABYJRY.js +551 -0
  85. package/dist/chunk-WHABYJRY.js.map +1 -0
  86. package/dist/chunk-XN74I6VW.cjs +88 -0
  87. package/dist/chunk-XN74I6VW.cjs.map +1 -0
  88. package/dist/chunk-XVPBGW6Y.cjs +256 -0
  89. package/dist/chunk-XVPBGW6Y.cjs.map +1 -0
  90. package/dist/chunk-YJU744I4.cjs +568 -0
  91. package/dist/chunk-YJU744I4.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 +57 -7
  145. package/dist/server/handlers/agents.cjs.map +1 -0
  146. package/dist/server/handlers/agents.d.ts +204 -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 +117 -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 +251 -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 +47 -13
  217. package/dist/server/handlers/workflows.cjs.map +1 -0
  218. package/dist/server/handlers/workflows.d.ts +91 -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-53CFGXUO.cjs +64 -0
  235. package/dist/token-53CFGXUO.cjs.map +1 -0
  236. package/dist/token-WAEKDUVY.js +62 -0
  237. package/dist/token-WAEKDUVY.js.map +1 -0
  238. package/dist/token-util-LY37VCIN.js +7 -0
  239. package/dist/token-util-LY37VCIN.js.map +1 -0
  240. package/dist/token-util-S4A355II.cjs +9 -0
  241. package/dist/token-util-S4A355II.cjs.map +1 -0
  242. package/package.json +43 -19
  243. package/LICENSE +0 -44
  244. package/dist/_tsup-dts-rollup.d.cts +0 -564
  245. package/dist/_tsup-dts-rollup.d.ts +0 -564
  246. package/dist/chunk-2FJURXCL.cjs +0 -213
  247. package/dist/chunk-2JQC6JWP.js +0 -46
  248. package/dist/chunk-2YONKUWB.js +0 -117
  249. package/dist/chunk-3AHQ5RGN.js +0 -11
  250. package/dist/chunk-4C3EPMMF.cjs +0 -122
  251. package/dist/chunk-5JOF627H.cjs +0 -123
  252. package/dist/chunk-A7DF4ETD.cjs +0 -100
  253. package/dist/chunk-BMA2ORRT.js +0 -152
  254. package/dist/chunk-GV52BII2.cjs +0 -160
  255. package/dist/chunk-QH6XWSXP.cjs +0 -5579
  256. package/dist/chunk-QN4KF3BH.cjs +0 -18
  257. package/dist/chunk-RBQASTUP.js +0 -203
  258. package/dist/chunk-VB7KH62D.cjs +0 -51
  259. package/dist/chunk-VK6FX47H.js +0 -5576
  260. package/dist/chunk-X37I6GZT.cjs +0 -308
  261. package/dist/chunk-ZLBRQFDD.cjs +0 -13
  262. package/dist/index.d.cts +0 -1
  263. package/dist/server/handlers/agents.d.cts +0 -6
  264. package/dist/server/handlers/error.d.cts +0 -1
  265. package/dist/server/handlers/logs.d.cts +0 -3
  266. package/dist/server/handlers/memory.d.cts +0 -8
  267. package/dist/server/handlers/network.cjs +0 -22
  268. package/dist/server/handlers/network.d.cts +0 -4
  269. package/dist/server/handlers/network.d.ts +0 -4
  270. package/dist/server/handlers/network.js +0 -1
  271. package/dist/server/handlers/telemetry.d.cts +0 -2
  272. package/dist/server/handlers/tools.d.cts +0 -4
  273. package/dist/server/handlers/utils.d.cts +0 -1
  274. package/dist/server/handlers/vector.d.cts +0 -6
  275. package/dist/server/handlers/voice.d.cts +0 -3
  276. package/dist/server/handlers/workflows.d.cts +0 -10
  277. package/dist/server/handlers.d.cts +0 -9
@@ -0,0 +1,660 @@
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
+ observeStreamVNextWorkflowHandler: () => observeStreamVNextWorkflowHandler,
18
+ observeStreamWorkflowHandler: () => observeStreamWorkflowHandler,
19
+ resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
20
+ resumeStreamWorkflowHandler: () => resumeStreamWorkflowHandler,
21
+ resumeWorkflowHandler: () => resumeWorkflowHandler,
22
+ sendWorkflowRunEventHandler: () => sendWorkflowRunEventHandler,
23
+ startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
24
+ startWorkflowRunHandler: () => startWorkflowRunHandler,
25
+ streamVNextWorkflowHandler: () => streamVNextWorkflowHandler,
26
+ streamWorkflowHandler: () => streamWorkflowHandler,
27
+ watchWorkflowHandler: () => watchWorkflowHandler
28
+ });
29
+ async function getWorkflowsHandler({ mastra }) {
30
+ try {
31
+ const workflows = mastra.getWorkflows({ serialized: false });
32
+ const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
33
+ acc[key] = getWorkflowInfo(workflow);
34
+ return acc;
35
+ }, {});
36
+ return _workflows;
37
+ } catch (error) {
38
+ return handleError(error, "Error getting workflows");
39
+ }
40
+ }
41
+ async function getWorkflowsFromSystem({ mastra, workflowId }) {
42
+ const logger = mastra.getLogger();
43
+ if (!workflowId) {
44
+ throw new HTTPException(400, { message: "Workflow ID is required" });
45
+ }
46
+ let workflow;
47
+ workflow = WorkflowRegistry.getWorkflow(workflowId);
48
+ if (!workflow) {
49
+ try {
50
+ workflow = mastra.getWorkflow(workflowId);
51
+ } catch (error) {
52
+ logger.debug("Error getting workflow, searching agents for workflow", error);
53
+ }
54
+ }
55
+ if (!workflow) {
56
+ logger.debug("Workflow not found, searching agents for workflow", { workflowId });
57
+ const agents = mastra.getAgents();
58
+ if (Object.keys(agents || {}).length) {
59
+ for (const [_, agent] of Object.entries(agents)) {
60
+ try {
61
+ const workflows = await agent.getWorkflows();
62
+ if (workflows[workflowId]) {
63
+ workflow = workflows[workflowId];
64
+ break;
65
+ }
66
+ break;
67
+ } catch (error) {
68
+ logger.debug("Error getting workflow from agent", error);
69
+ }
70
+ }
71
+ }
72
+ }
73
+ if (!workflow) {
74
+ throw new HTTPException(404, { message: "Workflow not found" });
75
+ }
76
+ return { workflow };
77
+ }
78
+ async function getWorkflowByIdHandler({ mastra, workflowId }) {
79
+ try {
80
+ if (!workflowId) {
81
+ throw new HTTPException(400, { message: "Workflow ID is required" });
82
+ }
83
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
84
+ if (!workflow) {
85
+ throw new HTTPException(404, { message: "Workflow not found" });
86
+ }
87
+ return getWorkflowInfo(workflow);
88
+ } catch (error) {
89
+ return handleError(error, "Error getting workflow");
90
+ }
91
+ }
92
+ async function getWorkflowRunByIdHandler({
93
+ mastra,
94
+ workflowId,
95
+ runId
96
+ }) {
97
+ try {
98
+ if (!workflowId) {
99
+ throw new HTTPException(400, { message: "Workflow ID is required" });
100
+ }
101
+ if (!runId) {
102
+ throw new HTTPException(400, { message: "Run ID is required" });
103
+ }
104
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
105
+ if (!workflow) {
106
+ throw new HTTPException(404, { message: "Workflow not found" });
107
+ }
108
+ const run = await workflow.getWorkflowRunById(runId);
109
+ if (!run) {
110
+ throw new HTTPException(404, { message: "Workflow run not found" });
111
+ }
112
+ return run;
113
+ } catch (error) {
114
+ return handleError(error, "Error getting workflow run");
115
+ }
116
+ }
117
+ async function getWorkflowRunExecutionResultHandler({
118
+ mastra,
119
+ workflowId,
120
+ runId
121
+ }) {
122
+ try {
123
+ if (!workflowId) {
124
+ throw new HTTPException(400, { message: "Workflow ID is required" });
125
+ }
126
+ if (!runId) {
127
+ throw new HTTPException(400, { message: "Run ID is required" });
128
+ }
129
+ const workflow = mastra.getWorkflow(workflowId);
130
+ if (!workflow) {
131
+ throw new HTTPException(404, { message: "Workflow not found" });
132
+ }
133
+ const executionResult = await workflow.getWorkflowRunExecutionResult(runId);
134
+ if (!executionResult) {
135
+ throw new HTTPException(404, { message: "Workflow run execution result not found" });
136
+ }
137
+ return executionResult;
138
+ } catch (error) {
139
+ return handleError(error, "Error getting workflow run execution result");
140
+ }
141
+ }
142
+ async function createWorkflowRunHandler({
143
+ mastra,
144
+ workflowId,
145
+ runId: prevRunId
146
+ }) {
147
+ try {
148
+ if (!workflowId) {
149
+ throw new HTTPException(400, { message: "Workflow ID is required" });
150
+ }
151
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
152
+ if (!workflow) {
153
+ throw new HTTPException(404, { message: "Workflow not found" });
154
+ }
155
+ const run = await workflow.createRunAsync({ runId: prevRunId });
156
+ return { runId: run.runId };
157
+ } catch (error) {
158
+ return handleError(error, "Error creating workflow run");
159
+ }
160
+ }
161
+ async function startAsyncWorkflowHandler({
162
+ mastra,
163
+ runtimeContext,
164
+ workflowId,
165
+ runId,
166
+ inputData,
167
+ tracingOptions
168
+ }) {
169
+ try {
170
+ if (!workflowId) {
171
+ throw new HTTPException(400, { message: "Workflow ID is required" });
172
+ }
173
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
174
+ if (!workflow) {
175
+ throw new HTTPException(404, { message: "Workflow not found" });
176
+ }
177
+ const _run = await workflow.createRunAsync({ runId });
178
+ const result = await _run.start({
179
+ inputData,
180
+ runtimeContext,
181
+ tracingOptions
182
+ });
183
+ return result;
184
+ } catch (error) {
185
+ return handleError(error, "Error starting async workflow");
186
+ }
187
+ }
188
+ async function startWorkflowRunHandler({
189
+ mastra,
190
+ runtimeContext,
191
+ workflowId,
192
+ runId,
193
+ inputData,
194
+ tracingOptions
195
+ }) {
196
+ try {
197
+ if (!workflowId) {
198
+ throw new HTTPException(400, { message: "Workflow ID is required" });
199
+ }
200
+ if (!runId) {
201
+ throw new HTTPException(400, { message: "runId required to start run" });
202
+ }
203
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
204
+ if (!workflow) {
205
+ throw new HTTPException(404, { message: "Workflow not found" });
206
+ }
207
+ const run = await workflow.getWorkflowRunById(runId);
208
+ if (!run) {
209
+ throw new HTTPException(404, { message: "Workflow run not found" });
210
+ }
211
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
212
+ void _run.start({
213
+ inputData,
214
+ runtimeContext,
215
+ tracingOptions
216
+ });
217
+ return { message: "Workflow run started" };
218
+ } catch (e) {
219
+ return handleError(e, "Error starting workflow run");
220
+ }
221
+ }
222
+ async function watchWorkflowHandler({
223
+ mastra,
224
+ workflowId,
225
+ runId,
226
+ eventType = "watch"
227
+ }) {
228
+ try {
229
+ if (!workflowId) {
230
+ throw new HTTPException(400, { message: "Workflow ID is required" });
231
+ }
232
+ if (!runId) {
233
+ throw new HTTPException(400, { message: "runId required to watch workflow" });
234
+ }
235
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
236
+ if (!workflow) {
237
+ throw new HTTPException(404, { message: "Workflow not found" });
238
+ }
239
+ const run = await workflow.getWorkflowRunById(runId);
240
+ if (!run) {
241
+ throw new HTTPException(404, { message: "Workflow run not found" });
242
+ }
243
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
244
+ let unwatch;
245
+ let asyncRef = null;
246
+ const stream = new ReadableStream({
247
+ start(controller) {
248
+ unwatch = _run.watch((event) => {
249
+ const { type, payload, eventTimestamp } = event;
250
+ controller.enqueue(JSON.stringify({ type, payload, eventTimestamp, runId }));
251
+ if (asyncRef) {
252
+ clearImmediate(asyncRef);
253
+ asyncRef = null;
254
+ }
255
+ asyncRef = setImmediate(async () => {
256
+ const runDone = eventType === "watch" ? payload.workflowState.status !== "running" : type === "finish";
257
+ if (runDone) {
258
+ controller.close();
259
+ unwatch?.();
260
+ }
261
+ });
262
+ }, eventType);
263
+ },
264
+ cancel() {
265
+ if (asyncRef) {
266
+ clearImmediate(asyncRef);
267
+ asyncRef = null;
268
+ }
269
+ unwatch?.();
270
+ }
271
+ });
272
+ return stream;
273
+ } catch (error) {
274
+ return handleError(error, "Error watching workflow");
275
+ }
276
+ }
277
+ async function streamWorkflowHandler({
278
+ mastra,
279
+ runtimeContext,
280
+ workflowId,
281
+ runId,
282
+ inputData,
283
+ tracingOptions
284
+ }) {
285
+ try {
286
+ if (!workflowId) {
287
+ throw new HTTPException(400, { message: "Workflow ID is required" });
288
+ }
289
+ if (!runId) {
290
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
291
+ }
292
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
293
+ if (!workflow) {
294
+ throw new HTTPException(404, { message: "Workflow not found" });
295
+ }
296
+ const serverCache = mastra.getServerCache();
297
+ const run = await workflow.createRunAsync({ runId });
298
+ const result = run.stream({
299
+ inputData,
300
+ runtimeContext,
301
+ onChunk: async (chunk) => {
302
+ if (serverCache) {
303
+ const cacheKey = runId;
304
+ await serverCache.listPush(cacheKey, chunk);
305
+ }
306
+ },
307
+ tracingOptions
308
+ });
309
+ return result;
310
+ } catch (error) {
311
+ return handleError(error, "Error executing workflow");
312
+ }
313
+ }
314
+ async function observeStreamWorkflowHandler({
315
+ mastra,
316
+ workflowId,
317
+ runId
318
+ }) {
319
+ try {
320
+ if (!workflowId) {
321
+ throw new HTTPException(400, { message: "Workflow ID is required" });
322
+ }
323
+ if (!runId) {
324
+ throw new HTTPException(400, { message: "runId required to observe workflow stream" });
325
+ }
326
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
327
+ if (!workflow) {
328
+ throw new HTTPException(404, { message: "Workflow not found" });
329
+ }
330
+ const run = await workflow.getWorkflowRunById(runId);
331
+ if (!run) {
332
+ throw new HTTPException(404, { message: "Workflow run not found" });
333
+ }
334
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
335
+ const serverCache = mastra.getServerCache();
336
+ if (!serverCache) {
337
+ throw new HTTPException(500, { message: "Server cache not found" });
338
+ }
339
+ const transformStream = new TransformStream();
340
+ const writer = transformStream.writable.getWriter();
341
+ const cachedRunChunks = await serverCache.listFromTo(runId, 0);
342
+ for (const chunk of cachedRunChunks) {
343
+ await writer.write(chunk);
344
+ }
345
+ writer.releaseLock();
346
+ const result = _run.observeStream();
347
+ return result.stream?.pipeThrough(transformStream);
348
+ } catch (error) {
349
+ return handleError(error, "Error observing workflow stream");
350
+ }
351
+ }
352
+ async function streamVNextWorkflowHandler({
353
+ mastra,
354
+ runtimeContext,
355
+ workflowId,
356
+ runId,
357
+ inputData,
358
+ closeOnSuspend,
359
+ tracingOptions
360
+ }) {
361
+ try {
362
+ if (!workflowId) {
363
+ throw new HTTPException(400, { message: "Workflow ID is required" });
364
+ }
365
+ if (!runId) {
366
+ throw new HTTPException(400, { message: "runId required to stream workflow" });
367
+ }
368
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
369
+ if (!workflow) {
370
+ throw new HTTPException(404, { message: "Workflow not found" });
371
+ }
372
+ const serverCache = mastra.getServerCache();
373
+ const run = await workflow.createRunAsync({ runId });
374
+ const result = run.streamVNext({
375
+ inputData,
376
+ runtimeContext,
377
+ closeOnSuspend,
378
+ onChunk: async (chunk) => {
379
+ if (serverCache) {
380
+ const cacheKey = runId;
381
+ await serverCache.listPush(cacheKey, chunk);
382
+ }
383
+ },
384
+ tracingOptions
385
+ });
386
+ return result;
387
+ } catch (error) {
388
+ return handleError(error, "Error streaming workflow");
389
+ }
390
+ }
391
+ async function observeStreamVNextWorkflowHandler({
392
+ mastra,
393
+ workflowId,
394
+ runId
395
+ }) {
396
+ try {
397
+ if (!workflowId) {
398
+ throw new HTTPException(400, { message: "Workflow ID is required" });
399
+ }
400
+ if (!runId) {
401
+ throw new HTTPException(400, { message: "runId required to observe workflow stream" });
402
+ }
403
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
404
+ if (!workflow) {
405
+ throw new HTTPException(404, { message: "Workflow not found" });
406
+ }
407
+ const run = await workflow.getWorkflowRunById(runId);
408
+ if (!run) {
409
+ throw new HTTPException(404, { message: "Workflow run not found" });
410
+ }
411
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
412
+ const serverCache = mastra.getServerCache();
413
+ if (!serverCache) {
414
+ throw new HTTPException(500, { message: "Server cache not found" });
415
+ }
416
+ const cachedRunChunks = await serverCache.listFromTo(runId, 0);
417
+ const combinedStream = new ReadableStream({
418
+ start(controller) {
419
+ const emitCachedChunks = async () => {
420
+ for (const chunk of cachedRunChunks) {
421
+ controller.enqueue(chunk);
422
+ }
423
+ };
424
+ const liveStream = _run.observeStreamVNext();
425
+ const reader = liveStream.getReader();
426
+ const pump = async () => {
427
+ try {
428
+ while (true) {
429
+ const { done, value } = await reader.read();
430
+ if (done) {
431
+ controller.close();
432
+ break;
433
+ }
434
+ controller.enqueue(value);
435
+ }
436
+ } catch (error) {
437
+ controller.error(error);
438
+ } finally {
439
+ reader.releaseLock();
440
+ }
441
+ };
442
+ void emitCachedChunks().then(() => {
443
+ void pump();
444
+ }).catch((error) => {
445
+ controller.error(error);
446
+ });
447
+ }
448
+ });
449
+ return combinedStream;
450
+ } catch (error) {
451
+ return handleError(error, "Error observing workflow stream");
452
+ }
453
+ }
454
+ async function resumeAsyncWorkflowHandler({
455
+ mastra,
456
+ workflowId,
457
+ runId,
458
+ body,
459
+ runtimeContext,
460
+ tracingOptions
461
+ }) {
462
+ try {
463
+ if (!workflowId) {
464
+ throw new HTTPException(400, { message: "Workflow ID is required" });
465
+ }
466
+ if (!runId) {
467
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
468
+ }
469
+ if (!body.step) {
470
+ throw new HTTPException(400, { message: "step required to resume workflow" });
471
+ }
472
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
473
+ if (!workflow) {
474
+ throw new HTTPException(404, { message: "Workflow not found" });
475
+ }
476
+ const run = await workflow.getWorkflowRunById(runId);
477
+ if (!run) {
478
+ throw new HTTPException(404, { message: "Workflow run not found" });
479
+ }
480
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
481
+ const result = await _run.resume({
482
+ step: body.step,
483
+ resumeData: body.resumeData,
484
+ runtimeContext,
485
+ tracingOptions
486
+ });
487
+ return result;
488
+ } catch (error) {
489
+ return handleError(error, "Error resuming workflow step");
490
+ }
491
+ }
492
+ async function resumeWorkflowHandler({
493
+ mastra,
494
+ workflowId,
495
+ runId,
496
+ body,
497
+ runtimeContext,
498
+ tracingOptions
499
+ }) {
500
+ try {
501
+ if (!workflowId) {
502
+ throw new HTTPException(400, { message: "Workflow ID is required" });
503
+ }
504
+ if (!runId) {
505
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
506
+ }
507
+ if (!body.step) {
508
+ throw new HTTPException(400, { message: "step required to resume workflow" });
509
+ }
510
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
511
+ if (!workflow) {
512
+ throw new HTTPException(404, { message: "Workflow not found" });
513
+ }
514
+ const run = await workflow.getWorkflowRunById(runId);
515
+ if (!run) {
516
+ throw new HTTPException(404, { message: "Workflow run not found" });
517
+ }
518
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
519
+ void _run.resume({
520
+ step: body.step,
521
+ resumeData: body.resumeData,
522
+ runtimeContext,
523
+ tracingOptions
524
+ });
525
+ return { message: "Workflow run resumed" };
526
+ } catch (error) {
527
+ return handleError(error, "Error resuming workflow");
528
+ }
529
+ }
530
+ async function resumeStreamWorkflowHandler({
531
+ mastra,
532
+ workflowId,
533
+ runId,
534
+ body,
535
+ runtimeContext,
536
+ tracingOptions
537
+ }) {
538
+ try {
539
+ if (!workflowId) {
540
+ throw new HTTPException(400, { message: "Workflow ID is required" });
541
+ }
542
+ if (!runId) {
543
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
544
+ }
545
+ if (!body.step) {
546
+ throw new HTTPException(400, { message: "step required to resume workflow" });
547
+ }
548
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
549
+ if (!workflow) {
550
+ throw new HTTPException(404, { message: "Workflow not found" });
551
+ }
552
+ const run = await workflow.getWorkflowRunById(runId);
553
+ if (!run) {
554
+ throw new HTTPException(404, { message: "Workflow run not found" });
555
+ }
556
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
557
+ const serverCache = mastra.getServerCache();
558
+ const stream = _run.resumeStreamVNext({
559
+ step: body.step,
560
+ resumeData: body.resumeData,
561
+ runtimeContext,
562
+ tracingOptions,
563
+ onChunk: async (chunk) => {
564
+ if (serverCache) {
565
+ const cacheKey = runId;
566
+ await serverCache.listPush(cacheKey, chunk);
567
+ }
568
+ }
569
+ });
570
+ return stream;
571
+ } catch (error) {
572
+ return handleError(error, "Error resuming workflow");
573
+ }
574
+ }
575
+ async function getWorkflowRunsHandler({
576
+ mastra,
577
+ workflowId,
578
+ fromDate,
579
+ toDate,
580
+ limit,
581
+ offset,
582
+ resourceId
583
+ }) {
584
+ try {
585
+ if (!workflowId) {
586
+ throw new HTTPException(400, { message: "Workflow ID is required" });
587
+ }
588
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
589
+ if (!workflow) {
590
+ throw new HTTPException(404, { message: "Workflow not found" });
591
+ }
592
+ const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
593
+ runs: [],
594
+ total: 0
595
+ };
596
+ return workflowRuns;
597
+ } catch (error) {
598
+ return handleError(error, "Error getting workflow runs");
599
+ }
600
+ }
601
+ async function cancelWorkflowRunHandler({
602
+ mastra,
603
+ workflowId,
604
+ runId
605
+ }) {
606
+ try {
607
+ if (!workflowId) {
608
+ throw new HTTPException(400, { message: "Workflow ID is required" });
609
+ }
610
+ if (!runId) {
611
+ throw new HTTPException(400, { message: "runId required to cancel workflow run" });
612
+ }
613
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
614
+ if (!workflow) {
615
+ throw new HTTPException(404, { message: "Workflow not found" });
616
+ }
617
+ const run = await workflow.getWorkflowRunById(runId);
618
+ if (!run) {
619
+ throw new HTTPException(404, { message: "Workflow run not found" });
620
+ }
621
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
622
+ await _run.cancel();
623
+ return { message: "Workflow run cancelled" };
624
+ } catch (error) {
625
+ return handleError(error, "Error canceling workflow run");
626
+ }
627
+ }
628
+ async function sendWorkflowRunEventHandler({
629
+ mastra,
630
+ workflowId,
631
+ runId,
632
+ event,
633
+ data
634
+ }) {
635
+ try {
636
+ if (!workflowId) {
637
+ throw new HTTPException(400, { message: "Workflow ID is required" });
638
+ }
639
+ if (!runId) {
640
+ throw new HTTPException(400, { message: "runId required to send workflow run event" });
641
+ }
642
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
643
+ if (!workflow) {
644
+ throw new HTTPException(404, { message: "Workflow not found" });
645
+ }
646
+ const run = await workflow.getWorkflowRunById(runId);
647
+ if (!run) {
648
+ throw new HTTPException(404, { message: "Workflow run not found" });
649
+ }
650
+ const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
651
+ await _run.sendEvent(event, data);
652
+ return { message: "Workflow run event sent" };
653
+ } catch (error) {
654
+ return handleError(error, "Error sending workflow run event");
655
+ }
656
+ }
657
+
658
+ export { cancelWorkflowRunHandler, createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunExecutionResultHandler, getWorkflowRunsHandler, getWorkflowsHandler, observeStreamVNextWorkflowHandler, observeStreamWorkflowHandler, resumeAsyncWorkflowHandler, resumeStreamWorkflowHandler, resumeWorkflowHandler, sendWorkflowRunEventHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamVNextWorkflowHandler, streamWorkflowHandler, watchWorkflowHandler, workflows_exports };
659
+ //# sourceMappingURL=chunk-DB63UMTV.js.map
660
+ //# sourceMappingURL=chunk-DB63UMTV.js.map