@mastra/server 0.0.0-remove-cloud-span-transform-20250425214156 → 0.0.0-remove-unused-model-providers-api-20251030210744

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 (268) hide show
  1. package/CHANGELOG.md +4230 -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-5JNVY6DU.js → chunk-2XD2KQEK.js} +57 -17
  9. package/dist/chunk-2XD2KQEK.js.map +1 -0
  10. package/dist/chunk-36CWLQQT.js +192 -0
  11. package/dist/chunk-36CWLQQT.js.map +1 -0
  12. package/dist/chunk-4BKR6543.cjs +19504 -0
  13. package/dist/chunk-4BKR6543.cjs.map +1 -0
  14. package/dist/{chunk-L7XE5QTW.js → chunk-4QCXUEAT.js} +11 -2
  15. package/dist/chunk-4QCXUEAT.js.map +1 -0
  16. package/dist/chunk-4YFT3JFJ.js +19463 -0
  17. package/dist/chunk-4YFT3JFJ.js.map +1 -0
  18. package/dist/chunk-6562SOHJ.js +130 -0
  19. package/dist/chunk-6562SOHJ.js.map +1 -0
  20. package/dist/chunk-6IGZKIRM.cjs +200 -0
  21. package/dist/chunk-6IGZKIRM.cjs.map +1 -0
  22. package/dist/{chunk-Q6SHQECN.js → chunk-74ZF4DII.js} +47 -13
  23. package/dist/chunk-74ZF4DII.js.map +1 -0
  24. package/dist/chunk-7KNKINQE.js +83 -0
  25. package/dist/chunk-7KNKINQE.js.map +1 -0
  26. package/dist/chunk-7MCHFMDF.js +665 -0
  27. package/dist/chunk-7MCHFMDF.js.map +1 -0
  28. package/dist/{chunk-FV45V6WC.cjs → chunk-7NADHFD2.cjs} +3 -7
  29. package/dist/chunk-7NADHFD2.cjs.map +1 -0
  30. package/dist/chunk-7YHMDEQ6.cjs +128 -0
  31. package/dist/chunk-7YHMDEQ6.cjs.map +1 -0
  32. package/dist/chunk-BATEJLED.js +124 -0
  33. package/dist/chunk-BATEJLED.js.map +1 -0
  34. package/dist/chunk-BMOVKZO7.cjs +167 -0
  35. package/dist/chunk-BMOVKZO7.cjs.map +1 -0
  36. package/dist/chunk-CXVOX4WB.js +508 -0
  37. package/dist/chunk-CXVOX4WB.js.map +1 -0
  38. package/dist/chunk-CY4TP3FK.js +16 -0
  39. package/dist/chunk-CY4TP3FK.js.map +1 -0
  40. package/dist/{chunk-M56ECCHK.cjs → chunk-EP3JQDPD.cjs} +22 -19
  41. package/dist/chunk-EP3JQDPD.cjs.map +1 -0
  42. package/dist/chunk-G4PUALCE.cjs +28 -0
  43. package/dist/chunk-G4PUALCE.cjs.map +1 -0
  44. package/dist/chunk-GQRJOUV7.js +797 -0
  45. package/dist/chunk-GQRJOUV7.js.map +1 -0
  46. package/dist/chunk-HLIRV42R.cjs +685 -0
  47. package/dist/chunk-HLIRV42R.cjs.map +1 -0
  48. package/dist/chunk-LPM6BBAX.cjs +1043 -0
  49. package/dist/chunk-LPM6BBAX.cjs.map +1 -0
  50. package/dist/chunk-LROVQBIB.cjs +524 -0
  51. package/dist/chunk-LROVQBIB.cjs.map +1 -0
  52. package/dist/chunk-LZKJT7QP.cjs +799 -0
  53. package/dist/chunk-LZKJT7QP.cjs.map +1 -0
  54. package/dist/{chunk-TRDNDNGQ.js → chunk-MMROOK5J.js} +4 -7
  55. package/dist/chunk-MMROOK5J.js.map +1 -0
  56. package/dist/{chunk-4JINXASC.js → chunk-MYR4PVGN.js} +7 -4
  57. package/dist/chunk-MYR4PVGN.js.map +1 -0
  58. package/dist/chunk-O7I5CWRX.cjs +44 -0
  59. package/dist/chunk-O7I5CWRX.cjs.map +1 -0
  60. package/dist/chunk-OEW3R7V4.js +477 -0
  61. package/dist/chunk-OEW3R7V4.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-PUYDRTPG.cjs +720 -0
  65. package/dist/chunk-PUYDRTPG.cjs.map +1 -0
  66. package/dist/chunk-QU6N55W6.cjs +256 -0
  67. package/dist/chunk-QU6N55W6.cjs.map +1 -0
  68. package/dist/chunk-RE4RPXT2.cjs +18 -0
  69. package/dist/chunk-RE4RPXT2.cjs.map +1 -0
  70. package/dist/chunk-RQK4FQUD.js +1012 -0
  71. package/dist/chunk-RQK4FQUD.js.map +1 -0
  72. package/dist/chunk-S4IOWSI3.js +698 -0
  73. package/dist/chunk-S4IOWSI3.js.map +1 -0
  74. package/dist/chunk-SED4H2GJ.cjs +485 -0
  75. package/dist/chunk-SED4H2GJ.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-TOCYBDP2.js +46 -0
  79. package/dist/chunk-TOCYBDP2.js.map +1 -0
  80. package/dist/chunk-WH5RPLO4.cjs +88 -0
  81. package/dist/chunk-WH5RPLO4.cjs.map +1 -0
  82. package/dist/chunk-X6C7BUWN.cjs +48 -0
  83. package/dist/chunk-X6C7BUWN.cjs.map +1 -0
  84. package/dist/chunk-YNGDJJOH.cjs +134 -0
  85. package/dist/chunk-YNGDJJOH.cjs.map +1 -0
  86. package/dist/chunk-ZULZ2752.js +2774 -0
  87. package/dist/chunk-ZULZ2752.js.map +1 -0
  88. package/dist/dist-4MVGNSRL.cjs +1150 -0
  89. package/dist/dist-4MVGNSRL.cjs.map +1 -0
  90. package/dist/dist-FZYCV3VB.cjs +940 -0
  91. package/dist/dist-FZYCV3VB.cjs.map +1 -0
  92. package/dist/dist-G2BYZJOC.cjs +928 -0
  93. package/dist/dist-G2BYZJOC.cjs.map +1 -0
  94. package/dist/dist-P4MXBQ3U.cjs +16 -0
  95. package/dist/dist-P4MXBQ3U.cjs.map +1 -0
  96. package/dist/dist-PQZUVLPC.js +937 -0
  97. package/dist/dist-PQZUVLPC.js.map +1 -0
  98. package/dist/dist-R7WYX6LC.js +925 -0
  99. package/dist/dist-R7WYX6LC.js.map +1 -0
  100. package/dist/dist-RFMYFILX.cjs +764 -0
  101. package/dist/dist-RFMYFILX.cjs.map +1 -0
  102. package/dist/dist-X7XR3M3Z.js +1147 -0
  103. package/dist/dist-X7XR3M3Z.js.map +1 -0
  104. package/dist/dist-XVBSOGFK.js +761 -0
  105. package/dist/dist-XVBSOGFK.js.map +1 -0
  106. package/dist/dist-YREX2TJT.js +3 -0
  107. package/dist/dist-YREX2TJT.js.map +1 -0
  108. package/dist/index.cjs +6 -0
  109. package/dist/index.cjs.map +1 -0
  110. package/dist/index.d.ts +1 -0
  111. package/dist/index.d.ts.map +1 -0
  112. package/dist/index.js +5 -0
  113. package/dist/index.js.map +1 -0
  114. package/dist/server/a2a/protocol.d.ts +8 -0
  115. package/dist/server/a2a/protocol.d.ts.map +1 -0
  116. package/dist/server/a2a/store.cjs +25 -0
  117. package/dist/server/a2a/store.cjs.map +1 -0
  118. package/dist/server/a2a/store.d.ts +14 -0
  119. package/dist/server/a2a/store.d.ts.map +1 -0
  120. package/dist/server/a2a/store.js +23 -0
  121. package/dist/server/a2a/store.js.map +1 -0
  122. package/dist/server/a2a/tasks.d.ts +20 -0
  123. package/dist/server/a2a/tasks.d.ts.map +1 -0
  124. package/dist/server/handlers/a2a.cjs +32 -0
  125. package/dist/server/handlers/a2a.cjs.map +1 -0
  126. package/dist/server/handlers/a2a.d.ts +68 -0
  127. package/dist/server/handlers/a2a.d.ts.map +1 -0
  128. package/dist/server/handlers/a2a.js +3 -0
  129. package/dist/server/handlers/a2a.js.map +1 -0
  130. package/dist/server/handlers/agent-builder.cjs +88 -0
  131. package/dist/server/handlers/agent-builder.cjs.map +1 -0
  132. package/dist/server/handlers/agent-builder.d.ts +110 -0
  133. package/dist/server/handlers/agent-builder.d.ts.map +1 -0
  134. package/dist/server/handlers/agent-builder.js +3 -0
  135. package/dist/server/handlers/agent-builder.js.map +1 -0
  136. package/dist/server/handlers/agents.cjs +60 -10
  137. package/dist/server/handlers/agents.cjs.map +1 -0
  138. package/dist/server/handlers/agents.d.ts +195 -6
  139. package/dist/server/handlers/agents.d.ts.map +1 -0
  140. package/dist/server/handlers/agents.js +3 -1
  141. package/dist/server/handlers/agents.js.map +1 -0
  142. package/dist/server/handlers/error.cjs +4 -2
  143. package/dist/server/handlers/error.cjs.map +1 -0
  144. package/dist/server/handlers/error.d.ts +2 -1
  145. package/dist/server/handlers/error.d.ts.map +1 -0
  146. package/dist/server/handlers/error.js +3 -1
  147. package/dist/server/handlers/error.js.map +1 -0
  148. package/dist/server/handlers/logs.cjs +9 -7
  149. package/dist/server/handlers/logs.cjs.map +1 -0
  150. package/dist/server/handlers/logs.d.ts +34 -3
  151. package/dist/server/handlers/logs.d.ts.map +1 -0
  152. package/dist/server/handlers/logs.js +3 -1
  153. package/dist/server/handlers/logs.js.map +1 -0
  154. package/dist/server/handlers/memory.cjs +36 -10
  155. package/dist/server/handlers/memory.cjs.map +1 -0
  156. package/dist/server/handlers/memory.d.ts +115 -8
  157. package/dist/server/handlers/memory.d.ts.map +1 -0
  158. package/dist/server/handlers/memory.js +3 -1
  159. package/dist/server/handlers/memory.js.map +1 -0
  160. package/dist/server/handlers/observability.cjs +24 -0
  161. package/dist/server/handlers/observability.cjs.map +1 -0
  162. package/dist/server/handlers/observability.d.ts +49 -0
  163. package/dist/server/handlers/observability.d.ts.map +1 -0
  164. package/dist/server/handlers/observability.js +3 -0
  165. package/dist/server/handlers/observability.js.map +1 -0
  166. package/dist/server/handlers/scores.cjs +32 -0
  167. package/dist/server/handlers/scores.cjs.map +1 -0
  168. package/dist/server/handlers/scores.d.ts +152 -0
  169. package/dist/server/handlers/scores.d.ts.map +1 -0
  170. package/dist/server/handlers/scores.js +3 -0
  171. package/dist/server/handlers/scores.js.map +1 -0
  172. package/dist/server/handlers/tools.cjs +12 -6
  173. package/dist/server/handlers/tools.cjs.map +1 -0
  174. package/dist/server/handlers/tools.d.ts +25 -4
  175. package/dist/server/handlers/tools.d.ts.map +1 -0
  176. package/dist/server/handlers/tools.js +3 -1
  177. package/dist/server/handlers/tools.js.map +1 -0
  178. package/dist/server/handlers/utils.cjs +8 -2
  179. package/dist/server/handlers/utils.cjs.map +1 -0
  180. package/dist/server/handlers/utils.d.ts +8 -1
  181. package/dist/server/handlers/utils.d.ts.map +1 -0
  182. package/dist/server/handlers/utils.js +3 -1
  183. package/dist/server/handlers/utils.js.map +1 -0
  184. package/dist/server/handlers/vector.cjs +9 -7
  185. package/dist/server/handlers/vector.cjs.map +1 -0
  186. package/dist/server/handlers/vector.d.ts +51 -6
  187. package/dist/server/handlers/vector.d.ts.map +1 -0
  188. package/dist/server/handlers/vector.js +3 -1
  189. package/dist/server/handlers/vector.js.map +1 -0
  190. package/dist/server/handlers/voice.cjs +10 -4
  191. package/dist/server/handlers/voice.cjs.map +1 -0
  192. package/dist/server/handlers/voice.d.ts +41 -3
  193. package/dist/server/handlers/voice.d.ts.map +1 -0
  194. package/dist/server/handlers/voice.js +3 -1
  195. package/dist/server/handlers/voice.js.map +1 -0
  196. package/dist/server/handlers/workflows.cjs +57 -15
  197. package/dist/server/handlers/workflows.cjs.map +1 -0
  198. package/dist/server/handlers/workflows.d.ts +97 -10
  199. package/dist/server/handlers/workflows.d.ts.map +1 -0
  200. package/dist/server/handlers/workflows.js +3 -1
  201. package/dist/server/handlers/workflows.js.map +1 -0
  202. package/dist/server/handlers.cjs +37 -30
  203. package/dist/server/handlers.cjs.map +1 -0
  204. package/dist/server/handlers.d.ts +12 -10
  205. package/dist/server/handlers.d.ts.map +1 -0
  206. package/dist/server/handlers.js +13 -10
  207. package/dist/server/handlers.js.map +1 -0
  208. package/dist/server/http-exception.d.ts +87 -0
  209. package/dist/server/http-exception.d.ts.map +1 -0
  210. package/dist/server/types.d.ts +10 -0
  211. package/dist/server/types.d.ts.map +1 -0
  212. package/dist/server/utils.d.ts +44 -0
  213. package/dist/server/utils.d.ts.map +1 -0
  214. package/dist/token-375W3LEI.cjs +64 -0
  215. package/dist/token-375W3LEI.cjs.map +1 -0
  216. package/dist/token-C3IMNCC4.js +62 -0
  217. package/dist/token-C3IMNCC4.js.map +1 -0
  218. package/dist/token-util-CV3RRG6K.cjs +9 -0
  219. package/dist/token-util-CV3RRG6K.cjs.map +1 -0
  220. package/dist/token-util-E5QO2RCL.js +7 -0
  221. package/dist/token-util-E5QO2RCL.js.map +1 -0
  222. package/package.json +43 -19
  223. package/dist/_tsup-dts-rollup.d.cts +0 -648
  224. package/dist/_tsup-dts-rollup.d.ts +0 -648
  225. package/dist/chunk-2FJURXCL.cjs +0 -213
  226. package/dist/chunk-3AHQ5RGN.js +0 -11
  227. package/dist/chunk-3EJZQ6TQ.js +0 -49
  228. package/dist/chunk-55HTWX4C.cjs +0 -93
  229. package/dist/chunk-5SWCVTNL.cjs +0 -5579
  230. package/dist/chunk-7IWQE76Z.cjs +0 -139
  231. package/dist/chunk-B66WVPGJ.js +0 -297
  232. package/dist/chunk-D3G23FP3.cjs +0 -126
  233. package/dist/chunk-FPIWDH5Y.cjs +0 -126
  234. package/dist/chunk-HCOPJZ4A.cjs +0 -164
  235. package/dist/chunk-LFOBHRFO.js +0 -305
  236. package/dist/chunk-OMN3UI6X.js +0 -5576
  237. package/dist/chunk-QN4KF3BH.cjs +0 -18
  238. package/dist/chunk-R4J7XQYU.js +0 -156
  239. package/dist/chunk-RBQASTUP.js +0 -203
  240. package/dist/chunk-RE6YL32K.js +0 -120
  241. package/dist/chunk-SKBVVI24.cjs +0 -54
  242. package/dist/chunk-TZK63M5N.cjs +0 -317
  243. package/dist/chunk-WTHDCRMY.js +0 -135
  244. package/dist/chunk-ZHNKYTNS.cjs +0 -309
  245. package/dist/chunk-ZLBRQFDD.cjs +0 -13
  246. package/dist/index.d.cts +0 -1
  247. package/dist/server/handlers/agents.d.cts +0 -6
  248. package/dist/server/handlers/error.d.cts +0 -1
  249. package/dist/server/handlers/logs.d.cts +0 -3
  250. package/dist/server/handlers/memory.d.cts +0 -8
  251. package/dist/server/handlers/network.cjs +0 -22
  252. package/dist/server/handlers/network.d.cts +0 -4
  253. package/dist/server/handlers/network.d.ts +0 -4
  254. package/dist/server/handlers/network.js +0 -1
  255. package/dist/server/handlers/telemetry.cjs +0 -14
  256. package/dist/server/handlers/telemetry.d.cts +0 -2
  257. package/dist/server/handlers/telemetry.d.ts +0 -2
  258. package/dist/server/handlers/telemetry.js +0 -1
  259. package/dist/server/handlers/tools.d.cts +0 -4
  260. package/dist/server/handlers/utils.d.cts +0 -1
  261. package/dist/server/handlers/vNextWorkflows.cjs +0 -46
  262. package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
  263. package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
  264. package/dist/server/handlers/vNextWorkflows.js +0 -1
  265. package/dist/server/handlers/vector.d.cts +0 -6
  266. package/dist/server/handlers/voice.d.cts +0 -3
  267. package/dist/server/handlers/workflows.d.cts +0 -10
  268. package/dist/server/handlers.d.cts +0 -10
@@ -0,0 +1,698 @@
1
+ import { getWorkflowInfo, WorkflowRegistry } from './chunk-6562SOHJ.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
+ listWorkflowRunsHandler: () => listWorkflowRunsHandler,
16
+ listWorkflowsHandler: () => listWorkflowsHandler,
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 listWorkflowsHandler({ mastra }) {
32
+ try {
33
+ const workflows = mastra.listWorkflows({ 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 listWorkflowsFromSystem({ 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.listAgents();
60
+ if (Object.keys(agents || {}).length) {
61
+ for (const [_, agent] of Object.entries(agents)) {
62
+ try {
63
+ const workflows = await agent.listWorkflows();
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 listWorkflowsFromSystem({ 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 listWorkflowsFromSystem({ 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 listWorkflowsFromSystem({ 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
+ requestContext,
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 listWorkflowsFromSystem({ 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
+ requestContext,
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
+ requestContext,
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 listWorkflowsFromSystem({ 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
+ requestContext,
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 listWorkflowsFromSystem({ 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
+ requestContext,
300
+ workflowId,
301
+ runId,
302
+ inputData,
303
+ tracingOptions
304
+ }) {
305
+ return streamVNextWorkflowHandler({ mastra, workflowId, runId, inputData, requestContext, tracingOptions });
306
+ }
307
+ async function streamLegacyWorkflowHandler({
308
+ mastra,
309
+ requestContext,
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 listWorkflowsFromSystem({ 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
+ requestContext,
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 listWorkflowsFromSystem({ 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
+ requestContext,
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 listWorkflowsFromSystem({ 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
+ requestContext,
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 listWorkflowsFromSystem({ 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
+ requestContext,
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 listWorkflowsFromSystem({ 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
+ requestContext,
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
+ requestContext,
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 listWorkflowsFromSystem({ 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
+ requestContext,
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
+ requestContext,
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 listWorkflowsFromSystem({ 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
+ requestContext,
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 listWorkflowRunsHandler({
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 listWorkflowsFromSystem({ mastra, workflowId });
627
+ if (!workflow) {
628
+ throw new HTTPException(404, { message: "Workflow not found" });
629
+ }
630
+ const workflowRuns = await workflow.listWorkflowRuns({ 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 listWorkflowsFromSystem({ 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 listWorkflowsFromSystem({ 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, listWorkflowRunsHandler, listWorkflowsHandler, observeStreamLegacyWorkflowHandler, observeStreamVNextWorkflowHandler, observeStreamWorkflowHandler, resumeAsyncWorkflowHandler, resumeStreamWorkflowHandler, resumeWorkflowHandler, sendWorkflowRunEventHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamLegacyWorkflowHandler, streamVNextWorkflowHandler, streamWorkflowHandler, watchWorkflowHandler, workflows_exports };
697
+ //# sourceMappingURL=chunk-S4IOWSI3.js.map
698
+ //# sourceMappingURL=chunk-S4IOWSI3.js.map