@mastra/server 0.0.0-fix-message-embedding-20250506021742 → 0.0.0-fix-generate-title-20250616171351

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 (85) hide show
  1. package/README.md +48 -135
  2. package/dist/_tsup-dts-rollup.d.cts +296 -100
  3. package/dist/_tsup-dts-rollup.d.ts +296 -100
  4. package/dist/{chunk-5JNVY6DU.js → chunk-2HXKRRNS.js} +7 -5
  5. package/dist/{chunk-Y3SV5XK4.js → chunk-4O23XCE5.js} +94 -13
  6. package/dist/{chunk-4JINXASC.js → chunk-55DOQLP6.js} +5 -4
  7. package/dist/{chunk-QN4KF3BH.cjs → chunk-57CJTIPW.cjs} +2 -2
  8. package/dist/{chunk-ZLBRQFDD.cjs → chunk-64U3UDTH.cjs} +2 -2
  9. package/dist/{chunk-2FJURXCL.cjs → chunk-6TJSHFCJ.cjs} +44 -36
  10. package/dist/chunk-75ZPJI57.cjs +9 -0
  11. package/dist/chunk-ASKESBJW.cjs +2004 -0
  12. package/dist/{chunk-AMVOS7YB.cjs → chunk-B4MQFJ7G.cjs} +12 -8
  13. package/dist/{chunk-BPL2CBLV.js → chunk-BFOA2QQY.js} +8 -4
  14. package/dist/{chunk-M56ECCHK.cjs → chunk-BNEY4P4P.cjs} +20 -19
  15. package/dist/{chunk-QJ3AHN64.js → chunk-C7564HUT.js} +4 -3
  16. package/dist/chunk-C75ZRJKD.cjs +270 -0
  17. package/dist/{chunk-3XTEV33Q.js → chunk-CLYX4KLH.js} +54 -51
  18. package/dist/{chunk-55HTWX4C.cjs → chunk-CMMOIUFC.cjs} +40 -19
  19. package/dist/{chunk-Q6SHQECN.js → chunk-CP55EVBK.js} +24 -4
  20. package/dist/chunk-FRXZL32L.cjs +471 -0
  21. package/dist/chunk-GHC4YV6R.js +504 -0
  22. package/dist/{chunk-L7XE5QTW.js → chunk-H5PTF3Y4.js} +1 -1
  23. package/dist/{chunk-RBQASTUP.js → chunk-I7KJZNX5.js} +14 -6
  24. package/dist/chunk-IMBY5XUG.cjs +86 -0
  25. package/dist/{chunk-IQTNZSFP.js → chunk-JKTNRUKY.js} +194 -49
  26. package/dist/{chunk-3AHQ5RGN.js → chunk-M5ABIP7D.js} +1 -1
  27. package/dist/chunk-MLKGABMK.js +7 -0
  28. package/dist/{chunk-D3G23FP3.cjs → chunk-NGURCFEJ.cjs} +24 -22
  29. package/dist/{chunk-TRDNDNGQ.js → chunk-NYN7KFXL.js} +1 -7
  30. package/dist/{chunk-FV45V6WC.cjs → chunk-OCWPVYNI.cjs} +0 -7
  31. package/dist/chunk-QLG2PFHE.js +81 -0
  32. package/dist/chunk-SDPGVWQJ.cjs +512 -0
  33. package/dist/chunk-TGJMNUYJ.js +2001 -0
  34. package/dist/{chunk-5YGDYMRB.cjs → chunk-VPNDC2DI.cjs} +14 -13
  35. package/dist/chunk-WE32JG64.cjs +332 -0
  36. package/dist/server/handlers/a2a.cjs +30 -0
  37. package/dist/server/handlers/a2a.d.cts +6 -0
  38. package/dist/server/handlers/a2a.d.ts +6 -0
  39. package/dist/server/handlers/a2a.js +1 -0
  40. package/dist/server/handlers/agents.cjs +7 -7
  41. package/dist/server/handlers/agents.js +1 -1
  42. package/dist/server/handlers/error.cjs +2 -2
  43. package/dist/server/handlers/error.js +1 -1
  44. package/dist/server/handlers/legacyWorkflows.cjs +46 -0
  45. package/dist/server/handlers/legacyWorkflows.d.cts +10 -0
  46. package/dist/server/handlers/legacyWorkflows.d.ts +10 -0
  47. package/dist/server/handlers/legacyWorkflows.js +1 -0
  48. package/dist/server/handlers/logs.cjs +4 -4
  49. package/dist/server/handlers/logs.js +1 -1
  50. package/dist/server/handlers/memory.cjs +9 -9
  51. package/dist/server/handlers/memory.js +1 -1
  52. package/dist/server/handlers/network.cjs +5 -5
  53. package/dist/server/handlers/network.js +1 -1
  54. package/dist/server/handlers/telemetry.cjs +3 -3
  55. package/dist/server/handlers/telemetry.js +1 -1
  56. package/dist/server/handlers/tools.cjs +5 -5
  57. package/dist/server/handlers/tools.js +1 -1
  58. package/dist/server/handlers/utils.cjs +2 -2
  59. package/dist/server/handlers/utils.js +1 -1
  60. package/dist/server/handlers/vector.cjs +7 -7
  61. package/dist/server/handlers/vector.js +1 -1
  62. package/dist/server/handlers/voice.cjs +8 -4
  63. package/dist/server/handlers/voice.d.cts +1 -0
  64. package/dist/server/handlers/voice.d.ts +1 -0
  65. package/dist/server/handlers/voice.js +1 -1
  66. package/dist/server/handlers/workflows.cjs +21 -13
  67. package/dist/server/handlers/workflows.d.cts +4 -2
  68. package/dist/server/handlers/workflows.d.ts +4 -2
  69. package/dist/server/handlers/workflows.js +1 -1
  70. package/dist/server/handlers.cjs +32 -27
  71. package/dist/server/handlers.d.cts +2 -1
  72. package/dist/server/handlers.d.ts +2 -1
  73. package/dist/server/handlers.js +11 -10
  74. package/package.json +13 -12
  75. package/dist/chunk-3EJZQ6TQ.js +0 -49
  76. package/dist/chunk-4BIX6GMY.cjs +0 -189
  77. package/dist/chunk-5SWCVTNL.cjs +0 -5579
  78. package/dist/chunk-CHFORQ7J.cjs +0 -329
  79. package/dist/chunk-FOXHTOQZ.cjs +0 -324
  80. package/dist/chunk-OMN3UI6X.js +0 -5576
  81. package/dist/chunk-SKBVVI24.cjs +0 -54
  82. package/dist/server/handlers/vNextWorkflows.cjs +0 -46
  83. package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
  84. package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
  85. package/dist/server/handlers/vNextWorkflows.js +0 -1
@@ -0,0 +1,471 @@
1
+ 'use strict';
2
+
3
+ var chunkASKESBJW_cjs = require('./chunk-ASKESBJW.cjs');
4
+ var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
5
+ var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
6
+ var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
7
+ var web = require('stream/web');
8
+ var di = require('@mastra/core/di');
9
+
10
+ // src/server/handlers/workflows.ts
11
+ var workflows_exports = {};
12
+ chunk75ZPJI57_cjs.__export(workflows_exports, {
13
+ createWorkflowRunHandler: () => createWorkflowRunHandler,
14
+ getWorkflowByIdHandler: () => getWorkflowByIdHandler,
15
+ getWorkflowRunByIdHandler: () => getWorkflowRunByIdHandler,
16
+ getWorkflowRunExecutionResultHandler: () => getWorkflowRunExecutionResultHandler,
17
+ getWorkflowRunsHandler: () => getWorkflowRunsHandler,
18
+ getWorkflowsHandler: () => getWorkflowsHandler,
19
+ resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
20
+ resumeWorkflowHandler: () => resumeWorkflowHandler,
21
+ startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
22
+ startWorkflowRunHandler: () => startWorkflowRunHandler,
23
+ streamWorkflowHandler: () => streamWorkflowHandler,
24
+ watchWorkflowHandler: () => watchWorkflowHandler
25
+ });
26
+ async function getWorkflowsHandler({ mastra }) {
27
+ try {
28
+ const workflows = mastra.getWorkflows({ serialized: false });
29
+ const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
30
+ acc[key] = {
31
+ name: workflow.name,
32
+ description: workflow.description,
33
+ steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
34
+ acc2[key2] = {
35
+ id: step.id,
36
+ description: step.description,
37
+ inputSchema: step.inputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(step.inputSchema)) : void 0,
38
+ outputSchema: step.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(step.outputSchema)) : void 0,
39
+ resumeSchema: step.resumeSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(step.resumeSchema)) : void 0,
40
+ suspendSchema: step.suspendSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(step.suspendSchema)) : void 0
41
+ };
42
+ return acc2;
43
+ }, {}),
44
+ stepGraph: workflow.serializedStepGraph,
45
+ inputSchema: workflow.inputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(workflow.inputSchema)) : void 0,
46
+ outputSchema: workflow.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(workflow.outputSchema)) : void 0
47
+ };
48
+ return acc;
49
+ }, {});
50
+ return _workflows;
51
+ } catch (error) {
52
+ throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error getting workflows" });
53
+ }
54
+ }
55
+ async function getWorkflowsFromSystem({ mastra, workflowId }) {
56
+ const logger = mastra.getLogger();
57
+ if (!workflowId) {
58
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
59
+ }
60
+ let workflow;
61
+ try {
62
+ workflow = mastra.getWorkflow(workflowId);
63
+ } catch (error) {
64
+ logger.debug("Error getting workflow, searching agents for workflow", error);
65
+ }
66
+ if (!workflow) {
67
+ logger.debug("Workflow not found, searching agents for workflow", { workflowId });
68
+ const agents = mastra.getAgents();
69
+ if (Object.keys(agents || {}).length) {
70
+ for (const [_, agent] of Object.entries(agents)) {
71
+ try {
72
+ const workflows = await agent.getWorkflows();
73
+ if (workflows[workflowId]) {
74
+ workflow = workflows[workflowId];
75
+ break;
76
+ }
77
+ break;
78
+ } catch (error) {
79
+ logger.debug("Error getting workflow from agent", error);
80
+ }
81
+ }
82
+ }
83
+ }
84
+ if (!workflow) {
85
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
86
+ }
87
+ return { workflow };
88
+ }
89
+ async function getWorkflowByIdHandler({ mastra, workflowId }) {
90
+ try {
91
+ if (!workflowId) {
92
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
93
+ }
94
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
95
+ if (!workflow) {
96
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
97
+ }
98
+ return {
99
+ steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
100
+ acc[key] = {
101
+ id: step.id,
102
+ description: step.description,
103
+ inputSchema: step.inputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(step.inputSchema)) : void 0,
104
+ outputSchema: step.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(step.outputSchema)) : void 0,
105
+ resumeSchema: step.resumeSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(step.resumeSchema)) : void 0,
106
+ suspendSchema: step.suspendSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(step.suspendSchema)) : void 0
107
+ };
108
+ return acc;
109
+ }, {}),
110
+ name: workflow.name,
111
+ description: workflow.description,
112
+ stepGraph: workflow.serializedStepGraph,
113
+ inputSchema: workflow.inputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(workflow.inputSchema)) : void 0,
114
+ outputSchema: workflow.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(workflow.outputSchema)) : void 0
115
+ };
116
+ } catch (error) {
117
+ throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error getting workflow" });
118
+ }
119
+ }
120
+ async function getWorkflowRunByIdHandler({
121
+ mastra,
122
+ workflowId,
123
+ runId
124
+ }) {
125
+ try {
126
+ if (!workflowId) {
127
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
128
+ }
129
+ if (!runId) {
130
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Run ID is required" });
131
+ }
132
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
133
+ if (!workflow) {
134
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
135
+ }
136
+ const run = await workflow.getWorkflowRunById(runId);
137
+ if (!run) {
138
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
139
+ }
140
+ return run;
141
+ } catch (error) {
142
+ throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error getting workflow run" });
143
+ }
144
+ }
145
+ async function getWorkflowRunExecutionResultHandler({
146
+ mastra,
147
+ workflowId,
148
+ runId
149
+ }) {
150
+ try {
151
+ if (!workflowId) {
152
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
153
+ }
154
+ if (!runId) {
155
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Run ID is required" });
156
+ }
157
+ const workflow = mastra.getWorkflow(workflowId);
158
+ if (!workflow) {
159
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
160
+ }
161
+ const executionResult = await workflow.getWorkflowRunExecutionResult(runId);
162
+ if (!executionResult) {
163
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run execution result not found" });
164
+ }
165
+ return executionResult;
166
+ } catch (error) {
167
+ throw new chunkOCWPVYNI_cjs.HTTPException(500, {
168
+ message: error?.message || "Error getting workflow run execution result"
169
+ });
170
+ }
171
+ }
172
+ async function createWorkflowRunHandler({
173
+ mastra,
174
+ workflowId,
175
+ runId: prevRunId
176
+ }) {
177
+ try {
178
+ if (!workflowId) {
179
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
180
+ }
181
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
182
+ if (!workflow) {
183
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
184
+ }
185
+ const run = workflow.createRun({ runId: prevRunId });
186
+ return { runId: run.runId };
187
+ } catch (error) {
188
+ throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error creating workflow run" });
189
+ }
190
+ }
191
+ async function startAsyncWorkflowHandler({
192
+ mastra,
193
+ runtimeContext: payloadRuntimeContext,
194
+ workflowId,
195
+ runId,
196
+ inputData
197
+ }) {
198
+ try {
199
+ if (!workflowId) {
200
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
201
+ }
202
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
203
+ if (!workflow) {
204
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
205
+ }
206
+ let runtimeContext;
207
+ if (payloadRuntimeContext) {
208
+ runtimeContext = new di.RuntimeContext();
209
+ Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
210
+ runtimeContext.set(key, value);
211
+ });
212
+ }
213
+ const _run = workflow.createRun({ runId });
214
+ const result = await _run.start({
215
+ inputData,
216
+ runtimeContext
217
+ });
218
+ return result;
219
+ } catch (error) {
220
+ throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error executing workflow" });
221
+ }
222
+ }
223
+ async function startWorkflowRunHandler({
224
+ mastra,
225
+ runtimeContext: payloadRuntimeContext,
226
+ workflowId,
227
+ runId,
228
+ inputData
229
+ }) {
230
+ try {
231
+ if (!workflowId) {
232
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
233
+ }
234
+ if (!runId) {
235
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to start run" });
236
+ }
237
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
238
+ if (!workflow) {
239
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
240
+ }
241
+ const run = await workflow.getWorkflowRunById(runId);
242
+ if (!run) {
243
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
244
+ }
245
+ let runtimeContext;
246
+ if (payloadRuntimeContext) {
247
+ runtimeContext = new di.RuntimeContext();
248
+ Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
249
+ runtimeContext.set(key, value);
250
+ });
251
+ }
252
+ const _run = workflow.createRun({ runId });
253
+ void _run.start({
254
+ inputData,
255
+ runtimeContext
256
+ });
257
+ return { message: "Workflow run started" };
258
+ } catch (e) {
259
+ return chunk64U3UDTH_cjs.handleError(e, "Error starting workflow run");
260
+ }
261
+ }
262
+ async function watchWorkflowHandler({
263
+ mastra,
264
+ workflowId,
265
+ runId
266
+ }) {
267
+ try {
268
+ if (!workflowId) {
269
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
270
+ }
271
+ if (!runId) {
272
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to watch workflow" });
273
+ }
274
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
275
+ if (!workflow) {
276
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
277
+ }
278
+ const run = await workflow.getWorkflowRunById(runId);
279
+ if (!run) {
280
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
281
+ }
282
+ const _run = workflow.createRun({ runId });
283
+ let unwatch;
284
+ let asyncRef = null;
285
+ const stream = new web.ReadableStream({
286
+ start(controller) {
287
+ unwatch = _run.watch(({ type, payload, eventTimestamp }) => {
288
+ controller.enqueue(JSON.stringify({ type, payload, eventTimestamp, runId }));
289
+ if (asyncRef) {
290
+ clearImmediate(asyncRef);
291
+ asyncRef = null;
292
+ }
293
+ asyncRef = setImmediate(async () => {
294
+ const runDone = payload.workflowState.status !== "running";
295
+ if (runDone) {
296
+ controller.close();
297
+ unwatch?.();
298
+ }
299
+ });
300
+ });
301
+ },
302
+ cancel() {
303
+ unwatch?.();
304
+ }
305
+ });
306
+ return stream;
307
+ } catch (error) {
308
+ return chunk64U3UDTH_cjs.handleError(error, "Error watching workflow");
309
+ }
310
+ }
311
+ async function streamWorkflowHandler({
312
+ mastra,
313
+ runtimeContext: payloadRuntimeContext,
314
+ workflowId,
315
+ runId,
316
+ inputData
317
+ }) {
318
+ try {
319
+ if (!workflowId) {
320
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
321
+ }
322
+ if (!runId) {
323
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to resume workflow" });
324
+ }
325
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
326
+ if (!workflow) {
327
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
328
+ }
329
+ let runtimeContext;
330
+ if (payloadRuntimeContext) {
331
+ runtimeContext = new di.RuntimeContext();
332
+ Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
333
+ runtimeContext.set(key, value);
334
+ });
335
+ }
336
+ const run = workflow.createRun({ runId });
337
+ const result = run.stream({
338
+ inputData,
339
+ runtimeContext
340
+ });
341
+ return result;
342
+ } catch (error) {
343
+ return chunk64U3UDTH_cjs.handleError(error, "Error executing workflow");
344
+ }
345
+ }
346
+ async function resumeAsyncWorkflowHandler({
347
+ mastra,
348
+ workflowId,
349
+ runId,
350
+ body,
351
+ runtimeContext: payloadRuntimeContext
352
+ }) {
353
+ try {
354
+ if (!workflowId) {
355
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
356
+ }
357
+ if (!runId) {
358
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to resume workflow" });
359
+ }
360
+ if (!body.step) {
361
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "step required to resume workflow" });
362
+ }
363
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
364
+ if (!workflow) {
365
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
366
+ }
367
+ const run = await workflow.getWorkflowRunById(runId);
368
+ if (!run) {
369
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
370
+ }
371
+ let runtimeContext;
372
+ if (payloadRuntimeContext) {
373
+ runtimeContext = new di.RuntimeContext();
374
+ Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
375
+ runtimeContext.set(key, value);
376
+ });
377
+ }
378
+ const _run = workflow.createRun({ runId });
379
+ const result = await _run.resume({
380
+ step: body.step,
381
+ resumeData: body.resumeData,
382
+ runtimeContext
383
+ });
384
+ return result;
385
+ } catch (error) {
386
+ return chunk64U3UDTH_cjs.handleError(error, "Error resuming workflow step");
387
+ }
388
+ }
389
+ async function resumeWorkflowHandler({
390
+ mastra,
391
+ workflowId,
392
+ runId,
393
+ body,
394
+ runtimeContext: payloadRuntimeContext
395
+ }) {
396
+ try {
397
+ if (!workflowId) {
398
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
399
+ }
400
+ if (!runId) {
401
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to resume workflow" });
402
+ }
403
+ if (!body.step) {
404
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "step required to resume workflow" });
405
+ }
406
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
407
+ if (!workflow) {
408
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
409
+ }
410
+ const run = await workflow.getWorkflowRunById(runId);
411
+ if (!run) {
412
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
413
+ }
414
+ let runtimeContext;
415
+ if (payloadRuntimeContext) {
416
+ runtimeContext = new di.RuntimeContext();
417
+ Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
418
+ runtimeContext.set(key, value);
419
+ });
420
+ }
421
+ const _run = workflow.createRun({ runId });
422
+ void _run.resume({
423
+ step: body.step,
424
+ resumeData: body.resumeData,
425
+ runtimeContext
426
+ });
427
+ return { message: "Workflow run resumed" };
428
+ } catch (error) {
429
+ return chunk64U3UDTH_cjs.handleError(error, "Error resuming workflow");
430
+ }
431
+ }
432
+ async function getWorkflowRunsHandler({
433
+ mastra,
434
+ workflowId,
435
+ fromDate,
436
+ toDate,
437
+ limit,
438
+ offset,
439
+ resourceId
440
+ }) {
441
+ try {
442
+ if (!workflowId) {
443
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
444
+ }
445
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
446
+ if (!workflow) {
447
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
448
+ }
449
+ const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
450
+ runs: [],
451
+ total: 0
452
+ };
453
+ return workflowRuns;
454
+ } catch (error) {
455
+ return chunk64U3UDTH_cjs.handleError(error, "Error getting workflow runs");
456
+ }
457
+ }
458
+
459
+ exports.createWorkflowRunHandler = createWorkflowRunHandler;
460
+ exports.getWorkflowByIdHandler = getWorkflowByIdHandler;
461
+ exports.getWorkflowRunByIdHandler = getWorkflowRunByIdHandler;
462
+ exports.getWorkflowRunExecutionResultHandler = getWorkflowRunExecutionResultHandler;
463
+ exports.getWorkflowRunsHandler = getWorkflowRunsHandler;
464
+ exports.getWorkflowsHandler = getWorkflowsHandler;
465
+ exports.resumeAsyncWorkflowHandler = resumeAsyncWorkflowHandler;
466
+ exports.resumeWorkflowHandler = resumeWorkflowHandler;
467
+ exports.startAsyncWorkflowHandler = startAsyncWorkflowHandler;
468
+ exports.startWorkflowRunHandler = startWorkflowRunHandler;
469
+ exports.streamWorkflowHandler = streamWorkflowHandler;
470
+ exports.watchWorkflowHandler = watchWorkflowHandler;
471
+ exports.workflows_exports = workflows_exports;