@mastra/server 0.10.13 → 0.10.14

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 (99) hide show
  1. package/dist/_tsup-dts-rollup.d.cts +1078 -0
  2. package/dist/_tsup-dts-rollup.d.ts +1078 -0
  3. package/dist/chunk-2KZFMI6P.cjs +37 -0
  4. package/dist/chunk-2SLFAFTR.cjs +148 -0
  5. package/dist/chunk-4D66QEKC.js +81 -0
  6. package/dist/chunk-5PQQ42EZ.js +320 -0
  7. package/dist/chunk-75ZPJI57.cjs +9 -0
  8. package/dist/chunk-7TP2LX5L.cjs +129 -0
  9. package/dist/chunk-B2PAS2IB.cjs +514 -0
  10. package/dist/chunk-BK4XT6EG.js +270 -0
  11. package/dist/chunk-CCGRCYWJ.cjs +18 -0
  12. package/dist/chunk-CRCR3ZUK.js +142 -0
  13. package/dist/chunk-DN7K6FJK.cjs +251 -0
  14. package/dist/chunk-FRVBFMO2.cjs +128 -0
  15. package/dist/chunk-G7KH752Y.cjs +145 -0
  16. package/dist/chunk-GHC4YV6R.js +504 -0
  17. package/dist/chunk-H7DMHBKY.js +498 -0
  18. package/dist/chunk-JMLYCXMK.cjs +332 -0
  19. package/dist/chunk-KHZKYUNR.js +112 -0
  20. package/dist/chunk-LCM566I4.js +35 -0
  21. package/dist/chunk-LF7P5PLR.js +14 -0
  22. package/dist/chunk-LI436ITD.cjs +2042 -0
  23. package/dist/chunk-LRCAAFUA.js +122 -0
  24. package/dist/chunk-LZ3VJXSO.cjs +278 -0
  25. package/dist/chunk-MEGCYGBU.js +2039 -0
  26. package/dist/chunk-MKLYEKEF.js +241 -0
  27. package/dist/chunk-MLKGABMK.js +7 -0
  28. package/dist/chunk-PZQDCRPV.cjs +16 -0
  29. package/dist/chunk-QGX47B5D.cjs +86 -0
  30. package/dist/chunk-RG473F6Y.js +141 -0
  31. package/dist/chunk-RHSWAXKB.cjs +118 -0
  32. package/dist/chunk-RSEO4XPX.js +16 -0
  33. package/dist/chunk-SDPGVWQJ.cjs +512 -0
  34. package/dist/chunk-WNVFNNWN.js +121 -0
  35. package/dist/index.cjs +2 -0
  36. package/dist/index.d.cts +1 -0
  37. package/dist/index.d.ts +1 -0
  38. package/dist/index.js +1 -0
  39. package/dist/server/handlers/a2a.cjs +30 -0
  40. package/dist/server/handlers/a2a.d.cts +6 -0
  41. package/dist/server/handlers/a2a.d.ts +6 -0
  42. package/dist/server/handlers/a2a.js +1 -0
  43. package/dist/server/handlers/agents.cjs +30 -0
  44. package/dist/server/handlers/agents.d.cts +6 -0
  45. package/dist/server/handlers/agents.d.ts +6 -0
  46. package/dist/server/handlers/agents.js +1 -0
  47. package/dist/server/handlers/error.cjs +10 -0
  48. package/dist/server/handlers/error.d.cts +1 -0
  49. package/dist/server/handlers/error.d.ts +1 -0
  50. package/dist/server/handlers/error.js +1 -0
  51. package/dist/server/handlers/legacyWorkflows.cjs +46 -0
  52. package/dist/server/handlers/legacyWorkflows.d.cts +10 -0
  53. package/dist/server/handlers/legacyWorkflows.d.ts +10 -0
  54. package/dist/server/handlers/legacyWorkflows.js +1 -0
  55. package/dist/server/handlers/logs.cjs +18 -0
  56. package/dist/server/handlers/logs.d.cts +3 -0
  57. package/dist/server/handlers/logs.d.ts +3 -0
  58. package/dist/server/handlers/logs.js +1 -0
  59. package/dist/server/handlers/memory.cjs +38 -0
  60. package/dist/server/handlers/memory.d.cts +8 -0
  61. package/dist/server/handlers/memory.d.ts +8 -0
  62. package/dist/server/handlers/memory.js +1 -0
  63. package/dist/server/handlers/network.cjs +22 -0
  64. package/dist/server/handlers/network.d.cts +4 -0
  65. package/dist/server/handlers/network.d.ts +4 -0
  66. package/dist/server/handlers/network.js +1 -0
  67. package/dist/server/handlers/telemetry.cjs +14 -0
  68. package/dist/server/handlers/telemetry.d.cts +2 -0
  69. package/dist/server/handlers/telemetry.d.ts +2 -0
  70. package/dist/server/handlers/telemetry.js +1 -0
  71. package/dist/server/handlers/tools.cjs +22 -0
  72. package/dist/server/handlers/tools.d.cts +4 -0
  73. package/dist/server/handlers/tools.d.ts +4 -0
  74. package/dist/server/handlers/tools.js +1 -0
  75. package/dist/server/handlers/utils.cjs +10 -0
  76. package/dist/server/handlers/utils.d.cts +1 -0
  77. package/dist/server/handlers/utils.d.ts +1 -0
  78. package/dist/server/handlers/utils.js +1 -0
  79. package/dist/server/handlers/vNextNetwork.cjs +218 -0
  80. package/dist/server/handlers/vNextNetwork.d.cts +6 -0
  81. package/dist/server/handlers/vNextNetwork.d.ts +6 -0
  82. package/dist/server/handlers/vNextNetwork.js +211 -0
  83. package/dist/server/handlers/vector.cjs +30 -0
  84. package/dist/server/handlers/vector.d.cts +6 -0
  85. package/dist/server/handlers/vector.d.ts +6 -0
  86. package/dist/server/handlers/vector.js +1 -0
  87. package/dist/server/handlers/voice.cjs +22 -0
  88. package/dist/server/handlers/voice.d.cts +4 -0
  89. package/dist/server/handlers/voice.d.ts +4 -0
  90. package/dist/server/handlers/voice.js +1 -0
  91. package/dist/server/handlers/workflows.cjs +62 -0
  92. package/dist/server/handlers/workflows.d.cts +14 -0
  93. package/dist/server/handlers/workflows.d.ts +14 -0
  94. package/dist/server/handlers/workflows.js +1 -0
  95. package/dist/server/handlers.cjs +60 -0
  96. package/dist/server/handlers.d.cts +11 -0
  97. package/dist/server/handlers.d.ts +11 -0
  98. package/dist/server/handlers.js +11 -0
  99. package/package.json +2 -2
@@ -0,0 +1,498 @@
1
+ import { stringify, esm_default } from './chunk-MEGCYGBU.js';
2
+ import { handleError } from './chunk-LF7P5PLR.js';
3
+ import { HTTPException } from './chunk-LCM566I4.js';
4
+ import { __export } from './chunk-MLKGABMK.js';
5
+ import { ReadableStream } 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
+ resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
18
+ resumeWorkflowHandler: () => resumeWorkflowHandler,
19
+ sendWorkflowRunEventHandler: () => sendWorkflowRunEventHandler,
20
+ startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
21
+ startWorkflowRunHandler: () => startWorkflowRunHandler,
22
+ streamWorkflowHandler: () => streamWorkflowHandler,
23
+ watchWorkflowHandler: () => watchWorkflowHandler
24
+ });
25
+ function getSteps(steps, path) {
26
+ return Object.entries(steps).reduce((acc, [key, step]) => {
27
+ const fullKey = path ? `${path}.${key}` : key;
28
+ acc[fullKey] = {
29
+ id: step.id,
30
+ description: step.description,
31
+ inputSchema: step.inputSchema ? stringify(esm_default(step.inputSchema)) : void 0,
32
+ outputSchema: step.outputSchema ? stringify(esm_default(step.outputSchema)) : void 0,
33
+ resumeSchema: step.resumeSchema ? stringify(esm_default(step.resumeSchema)) : void 0,
34
+ suspendSchema: step.suspendSchema ? stringify(esm_default(step.suspendSchema)) : void 0,
35
+ isWorkflow: step.component === "WORKFLOW"
36
+ };
37
+ if (step.component === "WORKFLOW" && step.steps) {
38
+ const nestedSteps = getSteps(step.steps, fullKey) || {};
39
+ acc = { ...acc, ...nestedSteps };
40
+ }
41
+ return acc;
42
+ }, {});
43
+ }
44
+ async function getWorkflowsHandler({ mastra }) {
45
+ try {
46
+ const workflows = mastra.getWorkflows({ serialized: false });
47
+ const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
48
+ acc[key] = {
49
+ name: workflow.name,
50
+ description: workflow.description,
51
+ steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
52
+ acc2[key2] = {
53
+ id: step.id,
54
+ description: step.description,
55
+ inputSchema: step.inputSchema ? stringify(esm_default(step.inputSchema)) : void 0,
56
+ outputSchema: step.outputSchema ? stringify(esm_default(step.outputSchema)) : void 0,
57
+ resumeSchema: step.resumeSchema ? stringify(esm_default(step.resumeSchema)) : void 0,
58
+ suspendSchema: step.suspendSchema ? stringify(esm_default(step.suspendSchema)) : void 0
59
+ };
60
+ return acc2;
61
+ }, {}),
62
+ allSteps: getSteps(workflow.steps) || {},
63
+ stepGraph: workflow.serializedStepGraph,
64
+ inputSchema: workflow.inputSchema ? stringify(esm_default(workflow.inputSchema)) : void 0,
65
+ outputSchema: workflow.outputSchema ? stringify(esm_default(workflow.outputSchema)) : void 0
66
+ };
67
+ return acc;
68
+ }, {});
69
+ return _workflows;
70
+ } catch (error) {
71
+ return handleError(error, "Error getting workflows");
72
+ }
73
+ }
74
+ async function getWorkflowsFromSystem({ mastra, workflowId }) {
75
+ const logger = mastra.getLogger();
76
+ if (!workflowId) {
77
+ throw new HTTPException(400, { message: "Workflow ID is required" });
78
+ }
79
+ let workflow;
80
+ try {
81
+ workflow = mastra.getWorkflow(workflowId);
82
+ } catch (error) {
83
+ logger.debug("Error getting workflow, searching agents for workflow", error);
84
+ }
85
+ if (!workflow) {
86
+ logger.debug("Workflow not found, searching agents for workflow", { workflowId });
87
+ const agents = mastra.getAgents();
88
+ if (Object.keys(agents || {}).length) {
89
+ for (const [_, agent] of Object.entries(agents)) {
90
+ try {
91
+ const workflows = await agent.getWorkflows();
92
+ if (workflows[workflowId]) {
93
+ workflow = workflows[workflowId];
94
+ break;
95
+ }
96
+ break;
97
+ } catch (error) {
98
+ logger.debug("Error getting workflow from agent", error);
99
+ }
100
+ }
101
+ }
102
+ }
103
+ if (!workflow) {
104
+ throw new HTTPException(404, { message: "Workflow not found" });
105
+ }
106
+ return { workflow };
107
+ }
108
+ async function getWorkflowByIdHandler({ mastra, workflowId }) {
109
+ try {
110
+ if (!workflowId) {
111
+ throw new HTTPException(400, { message: "Workflow ID is required" });
112
+ }
113
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
114
+ if (!workflow) {
115
+ throw new HTTPException(404, { message: "Workflow not found" });
116
+ }
117
+ return {
118
+ steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
119
+ acc[key] = {
120
+ id: step.id,
121
+ description: step.description,
122
+ inputSchema: step.inputSchema ? stringify(esm_default(step.inputSchema)) : void 0,
123
+ outputSchema: step.outputSchema ? stringify(esm_default(step.outputSchema)) : void 0,
124
+ resumeSchema: step.resumeSchema ? stringify(esm_default(step.resumeSchema)) : void 0,
125
+ suspendSchema: step.suspendSchema ? stringify(esm_default(step.suspendSchema)) : void 0
126
+ };
127
+ return acc;
128
+ }, {}),
129
+ allSteps: getSteps(workflow.steps) || {},
130
+ name: workflow.name,
131
+ description: workflow.description,
132
+ stepGraph: workflow.serializedStepGraph,
133
+ inputSchema: workflow.inputSchema ? stringify(esm_default(workflow.inputSchema)) : void 0,
134
+ outputSchema: workflow.outputSchema ? stringify(esm_default(workflow.outputSchema)) : void 0
135
+ };
136
+ } catch (error) {
137
+ return handleError(error, "Error getting workflow");
138
+ }
139
+ }
140
+ async function getWorkflowRunByIdHandler({
141
+ mastra,
142
+ workflowId,
143
+ runId
144
+ }) {
145
+ try {
146
+ if (!workflowId) {
147
+ throw new HTTPException(400, { message: "Workflow ID is required" });
148
+ }
149
+ if (!runId) {
150
+ throw new HTTPException(400, { message: "Run ID is required" });
151
+ }
152
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
153
+ if (!workflow) {
154
+ throw new HTTPException(404, { message: "Workflow not found" });
155
+ }
156
+ const run = await workflow.getWorkflowRunById(runId);
157
+ if (!run) {
158
+ throw new HTTPException(404, { message: "Workflow run not found" });
159
+ }
160
+ return run;
161
+ } catch (error) {
162
+ return handleError(error, "Error getting workflow run");
163
+ }
164
+ }
165
+ async function getWorkflowRunExecutionResultHandler({
166
+ mastra,
167
+ workflowId,
168
+ runId
169
+ }) {
170
+ try {
171
+ if (!workflowId) {
172
+ throw new HTTPException(400, { message: "Workflow ID is required" });
173
+ }
174
+ if (!runId) {
175
+ throw new HTTPException(400, { message: "Run ID is required" });
176
+ }
177
+ const workflow = mastra.getWorkflow(workflowId);
178
+ if (!workflow) {
179
+ throw new HTTPException(404, { message: "Workflow not found" });
180
+ }
181
+ const executionResult = await workflow.getWorkflowRunExecutionResult(runId);
182
+ if (!executionResult) {
183
+ throw new HTTPException(404, { message: "Workflow run execution result not found" });
184
+ }
185
+ return executionResult;
186
+ } catch (error) {
187
+ return handleError(error, "Error getting workflow run execution result");
188
+ }
189
+ }
190
+ async function createWorkflowRunHandler({
191
+ mastra,
192
+ workflowId,
193
+ runId: prevRunId
194
+ }) {
195
+ try {
196
+ if (!workflowId) {
197
+ throw new HTTPException(400, { message: "Workflow ID is required" });
198
+ }
199
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
200
+ if (!workflow) {
201
+ throw new HTTPException(404, { message: "Workflow not found" });
202
+ }
203
+ const run = await workflow.createRunAsync({ runId: prevRunId });
204
+ return { runId: run.runId };
205
+ } catch (error) {
206
+ return handleError(error, "Error creating workflow run");
207
+ }
208
+ }
209
+ async function startAsyncWorkflowHandler({
210
+ mastra,
211
+ runtimeContext,
212
+ workflowId,
213
+ runId,
214
+ inputData
215
+ }) {
216
+ try {
217
+ if (!workflowId) {
218
+ throw new HTTPException(400, { message: "Workflow ID is required" });
219
+ }
220
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
221
+ if (!workflow) {
222
+ throw new HTTPException(404, { message: "Workflow not found" });
223
+ }
224
+ const _run = await workflow.createRunAsync({ runId });
225
+ const result = await _run.start({
226
+ inputData,
227
+ runtimeContext
228
+ });
229
+ return result;
230
+ } catch (error) {
231
+ return handleError(error, "Error starting async workflow");
232
+ }
233
+ }
234
+ async function startWorkflowRunHandler({
235
+ mastra,
236
+ runtimeContext,
237
+ workflowId,
238
+ runId,
239
+ inputData
240
+ }) {
241
+ try {
242
+ if (!workflowId) {
243
+ throw new HTTPException(400, { message: "Workflow ID is required" });
244
+ }
245
+ if (!runId) {
246
+ throw new HTTPException(400, { message: "runId required to start run" });
247
+ }
248
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
249
+ if (!workflow) {
250
+ throw new HTTPException(404, { message: "Workflow not found" });
251
+ }
252
+ const run = await workflow.getWorkflowRunById(runId);
253
+ if (!run) {
254
+ throw new HTTPException(404, { message: "Workflow run not found" });
255
+ }
256
+ const _run = await workflow.createRunAsync({ runId });
257
+ void _run.start({
258
+ inputData,
259
+ runtimeContext
260
+ });
261
+ return { message: "Workflow run started" };
262
+ } catch (e) {
263
+ return handleError(e, "Error starting workflow run");
264
+ }
265
+ }
266
+ async function watchWorkflowHandler({
267
+ mastra,
268
+ workflowId,
269
+ runId
270
+ }) {
271
+ try {
272
+ if (!workflowId) {
273
+ throw new HTTPException(400, { message: "Workflow ID is required" });
274
+ }
275
+ if (!runId) {
276
+ throw new HTTPException(400, { message: "runId required to watch workflow" });
277
+ }
278
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
279
+ if (!workflow) {
280
+ throw new HTTPException(404, { message: "Workflow not found" });
281
+ }
282
+ const run = await workflow.getWorkflowRunById(runId);
283
+ if (!run) {
284
+ throw new HTTPException(404, { message: "Workflow run not found" });
285
+ }
286
+ const _run = await workflow.createRunAsync({ runId });
287
+ let unwatch;
288
+ let asyncRef = null;
289
+ const stream = new ReadableStream({
290
+ start(controller) {
291
+ unwatch = _run.watch(({ type, payload, eventTimestamp }) => {
292
+ controller.enqueue(JSON.stringify({ type, payload, eventTimestamp, runId }));
293
+ if (asyncRef) {
294
+ clearImmediate(asyncRef);
295
+ asyncRef = null;
296
+ }
297
+ asyncRef = setImmediate(async () => {
298
+ const runDone = payload.workflowState.status !== "running";
299
+ if (runDone) {
300
+ controller.close();
301
+ unwatch?.();
302
+ }
303
+ });
304
+ });
305
+ },
306
+ cancel() {
307
+ unwatch?.();
308
+ }
309
+ });
310
+ return stream;
311
+ } catch (error) {
312
+ return handleError(error, "Error watching workflow");
313
+ }
314
+ }
315
+ async function streamWorkflowHandler({
316
+ mastra,
317
+ runtimeContext,
318
+ workflowId,
319
+ runId,
320
+ inputData
321
+ }) {
322
+ try {
323
+ if (!workflowId) {
324
+ throw new HTTPException(400, { message: "Workflow ID is required" });
325
+ }
326
+ if (!runId) {
327
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
328
+ }
329
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
330
+ if (!workflow) {
331
+ throw new HTTPException(404, { message: "Workflow not found" });
332
+ }
333
+ const run = await workflow.createRunAsync({ runId });
334
+ const result = run.stream({
335
+ inputData,
336
+ runtimeContext
337
+ });
338
+ return result;
339
+ } catch (error) {
340
+ return handleError(error, "Error executing workflow");
341
+ }
342
+ }
343
+ async function resumeAsyncWorkflowHandler({
344
+ mastra,
345
+ workflowId,
346
+ runId,
347
+ body,
348
+ runtimeContext
349
+ }) {
350
+ try {
351
+ if (!workflowId) {
352
+ throw new HTTPException(400, { message: "Workflow ID is required" });
353
+ }
354
+ if (!runId) {
355
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
356
+ }
357
+ if (!body.step) {
358
+ throw new HTTPException(400, { message: "step required to resume workflow" });
359
+ }
360
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
361
+ if (!workflow) {
362
+ throw new HTTPException(404, { message: "Workflow not found" });
363
+ }
364
+ const run = await workflow.getWorkflowRunById(runId);
365
+ if (!run) {
366
+ throw new HTTPException(404, { message: "Workflow run not found" });
367
+ }
368
+ const _run = await workflow.createRunAsync({ runId });
369
+ const result = await _run.resume({
370
+ step: body.step,
371
+ resumeData: body.resumeData,
372
+ runtimeContext
373
+ });
374
+ return result;
375
+ } catch (error) {
376
+ return handleError(error, "Error resuming workflow step");
377
+ }
378
+ }
379
+ async function resumeWorkflowHandler({
380
+ mastra,
381
+ workflowId,
382
+ runId,
383
+ body,
384
+ runtimeContext
385
+ }) {
386
+ try {
387
+ if (!workflowId) {
388
+ throw new HTTPException(400, { message: "Workflow ID is required" });
389
+ }
390
+ if (!runId) {
391
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
392
+ }
393
+ if (!body.step) {
394
+ throw new HTTPException(400, { message: "step required to resume workflow" });
395
+ }
396
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
397
+ if (!workflow) {
398
+ throw new HTTPException(404, { message: "Workflow not found" });
399
+ }
400
+ const run = await workflow.getWorkflowRunById(runId);
401
+ if (!run) {
402
+ throw new HTTPException(404, { message: "Workflow run not found" });
403
+ }
404
+ const _run = await workflow.createRunAsync({ runId });
405
+ void _run.resume({
406
+ step: body.step,
407
+ resumeData: body.resumeData,
408
+ runtimeContext
409
+ });
410
+ return { message: "Workflow run resumed" };
411
+ } catch (error) {
412
+ return handleError(error, "Error resuming workflow");
413
+ }
414
+ }
415
+ async function getWorkflowRunsHandler({
416
+ mastra,
417
+ workflowId,
418
+ fromDate,
419
+ toDate,
420
+ limit,
421
+ offset,
422
+ resourceId
423
+ }) {
424
+ try {
425
+ if (!workflowId) {
426
+ throw new HTTPException(400, { message: "Workflow ID is required" });
427
+ }
428
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
429
+ if (!workflow) {
430
+ throw new HTTPException(404, { message: "Workflow not found" });
431
+ }
432
+ const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
433
+ runs: [],
434
+ total: 0
435
+ };
436
+ return workflowRuns;
437
+ } catch (error) {
438
+ return handleError(error, "Error getting workflow runs");
439
+ }
440
+ }
441
+ async function cancelWorkflowRunHandler({
442
+ mastra,
443
+ workflowId,
444
+ runId
445
+ }) {
446
+ try {
447
+ if (!workflowId) {
448
+ throw new HTTPException(400, { message: "Workflow ID is required" });
449
+ }
450
+ if (!runId) {
451
+ throw new HTTPException(400, { message: "runId required to cancel workflow run" });
452
+ }
453
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
454
+ if (!workflow) {
455
+ throw new HTTPException(404, { message: "Workflow not found" });
456
+ }
457
+ const run = await workflow.getWorkflowRunById(runId);
458
+ if (!run) {
459
+ throw new HTTPException(404, { message: "Workflow run not found" });
460
+ }
461
+ const _run = await workflow.createRunAsync({ runId });
462
+ await _run.cancel();
463
+ return { message: "Workflow run cancelled" };
464
+ } catch (error) {
465
+ return handleError(error, "Error canceling workflow run");
466
+ }
467
+ }
468
+ async function sendWorkflowRunEventHandler({
469
+ mastra,
470
+ workflowId,
471
+ runId,
472
+ event,
473
+ data
474
+ }) {
475
+ try {
476
+ if (!workflowId) {
477
+ throw new HTTPException(400, { message: "Workflow ID is required" });
478
+ }
479
+ if (!runId) {
480
+ throw new HTTPException(400, { message: "runId required to send workflow run event" });
481
+ }
482
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
483
+ if (!workflow) {
484
+ throw new HTTPException(404, { message: "Workflow not found" });
485
+ }
486
+ const run = await workflow.getWorkflowRunById(runId);
487
+ if (!run) {
488
+ throw new HTTPException(404, { message: "Workflow run not found" });
489
+ }
490
+ const _run = await workflow.createRunAsync({ runId });
491
+ await _run.sendEvent(event, data);
492
+ return { message: "Workflow run event sent" };
493
+ } catch (error) {
494
+ return handleError(error, "Error sending workflow run event");
495
+ }
496
+ }
497
+
498
+ export { cancelWorkflowRunHandler, createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunExecutionResultHandler, getWorkflowRunsHandler, getWorkflowsHandler, resumeAsyncWorkflowHandler, resumeWorkflowHandler, sendWorkflowRunEventHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamWorkflowHandler, watchWorkflowHandler, workflows_exports };