@mastra/server 0.0.0-fix-ai-sdk-dependency-20251124104209 → 0.0.0-fix-backport-setserver-20251201151948

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