@mastra/server 0.0.0-taofeeqInngest-20250603090617 → 0.0.0-transpile-packages-20250724123433

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