@mastra/server 0.0.0-default-storage-virtual-file-20250410035748 → 0.0.0-expose-more-playground-ui-20250501175749

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 (44) hide show
  1. package/{LICENSE → LICENSE.md} +3 -1
  2. package/dist/_tsup-dts-rollup.d.cts +123 -33
  3. package/dist/_tsup-dts-rollup.d.ts +123 -33
  4. package/dist/{chunk-2JQC6JWP.js → chunk-3EJZQ6TQ.js} +4 -1
  5. package/dist/{chunk-GV52BII2.cjs → chunk-4BIX6GMY.cjs} +63 -34
  6. package/dist/{chunk-A7DF4ETD.cjs → chunk-55HTWX4C.cjs} +2 -9
  7. package/dist/{chunk-YNSGUC2O.js → chunk-5JNVY6DU.js} +8 -4
  8. package/dist/{chunk-QH6XWSXP.cjs → chunk-5SWCVTNL.cjs} +38 -38
  9. package/dist/{chunk-5JOF627H.cjs → chunk-5YGDYMRB.cjs} +54 -30
  10. package/dist/{chunk-CWSDZEZG.cjs → chunk-7IWQE76Z.cjs} +2 -2
  11. package/dist/chunk-AELYAUEE.cjs +316 -0
  12. package/dist/{chunk-4C3EPMMF.cjs → chunk-D3G23FP3.cjs} +12 -8
  13. package/dist/{chunk-X37I6GZT.cjs → chunk-EVCC233P.cjs} +29 -16
  14. package/dist/chunk-JPB6RPGB.js +304 -0
  15. package/dist/{chunk-ILW7XYNJ.js → chunk-M3YJLWTU.js} +23 -10
  16. package/dist/{chunk-VK6FX47H.js → chunk-OMN3UI6X.js} +38 -38
  17. package/dist/{chunk-3RVHWGWO.js → chunk-Q6SHQECN.js} +2 -9
  18. package/dist/{chunk-2YONKUWB.js → chunk-QJ3AHN64.js} +54 -30
  19. package/dist/{chunk-VB7KH62D.cjs → chunk-SKBVVI24.cjs} +4 -1
  20. package/dist/{chunk-DVPP5S6I.js → chunk-WTHDCRMY.js} +2 -2
  21. package/dist/{chunk-BMA2ORRT.js → chunk-Y3SV5XK4.js} +61 -32
  22. package/dist/server/handlers/agents.cjs +7 -7
  23. package/dist/server/handlers/agents.js +1 -1
  24. package/dist/server/handlers/logs.cjs +4 -4
  25. package/dist/server/handlers/logs.js +1 -1
  26. package/dist/server/handlers/network.cjs +5 -5
  27. package/dist/server/handlers/network.js +1 -1
  28. package/dist/server/handlers/telemetry.cjs +3 -3
  29. package/dist/server/handlers/telemetry.js +1 -1
  30. package/dist/server/handlers/tools.cjs +5 -5
  31. package/dist/server/handlers/tools.js +1 -1
  32. package/dist/server/handlers/vNextWorkflows.cjs +46 -0
  33. package/dist/server/handlers/vNextWorkflows.d.cts +10 -0
  34. package/dist/server/handlers/vNextWorkflows.d.ts +10 -0
  35. package/dist/server/handlers/vNextWorkflows.js +1 -0
  36. package/dist/server/handlers/voice.cjs +4 -4
  37. package/dist/server/handlers/voice.js +1 -1
  38. package/dist/server/handlers/workflows.cjs +11 -11
  39. package/dist/server/handlers/workflows.js +1 -1
  40. package/dist/server/handlers.cjs +19 -14
  41. package/dist/server/handlers.d.cts +1 -0
  42. package/dist/server/handlers.d.ts +1 -0
  43. package/dist/server/handlers.js +8 -7
  44. package/package.json +6 -6
@@ -0,0 +1,304 @@
1
+ import { stringify, esm_default } from './chunk-OMN3UI6X.js';
2
+ import { handleError } from './chunk-3AHQ5RGN.js';
3
+ import { __export, HTTPException } from './chunk-TRDNDNGQ.js';
4
+ import { ReadableStream } from 'node:stream/web';
5
+
6
+ // src/server/handlers/vNextWorkflows.ts
7
+ var vNextWorkflows_exports = {};
8
+ __export(vNextWorkflows_exports, {
9
+ createVNextWorkflowRunHandler: () => createVNextWorkflowRunHandler,
10
+ getVNextWorkflowByIdHandler: () => getVNextWorkflowByIdHandler,
11
+ getVNextWorkflowRunHandler: () => getVNextWorkflowRunHandler,
12
+ getVNextWorkflowRunsHandler: () => getVNextWorkflowRunsHandler,
13
+ getVNextWorkflowsHandler: () => getVNextWorkflowsHandler,
14
+ resumeAsyncVNextWorkflowHandler: () => resumeAsyncVNextWorkflowHandler,
15
+ resumeVNextWorkflowHandler: () => resumeVNextWorkflowHandler,
16
+ startAsyncVNextWorkflowHandler: () => startAsyncVNextWorkflowHandler,
17
+ startVNextWorkflowRunHandler: () => startVNextWorkflowRunHandler,
18
+ watchVNextWorkflowHandler: () => watchVNextWorkflowHandler
19
+ });
20
+ async function getVNextWorkflowsHandler({ mastra }) {
21
+ try {
22
+ const workflows = mastra.vnext_getWorkflows({ serialized: false });
23
+ const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
24
+ acc[key] = {
25
+ name: workflow.name,
26
+ steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
27
+ acc2[key2] = {
28
+ id: step.id,
29
+ description: step.description,
30
+ inputSchema: step.inputSchema ? stringify(esm_default(step.inputSchema)) : void 0,
31
+ outputSchema: step.outputSchema ? stringify(esm_default(step.outputSchema)) : void 0,
32
+ resumeSchema: step.resumeSchema ? stringify(esm_default(step.resumeSchema)) : void 0,
33
+ suspendSchema: step.suspendSchema ? stringify(esm_default(step.suspendSchema)) : void 0
34
+ };
35
+ return acc2;
36
+ }, {}),
37
+ stepGraph: workflow.serializedStepGraph,
38
+ inputSchema: workflow.inputSchema ? stringify(esm_default(workflow.inputSchema)) : void 0,
39
+ outputSchema: workflow.outputSchema ? stringify(esm_default(workflow.outputSchema)) : void 0
40
+ };
41
+ return acc;
42
+ }, {});
43
+ return _workflows;
44
+ } catch (error) {
45
+ throw new HTTPException(500, { message: error?.message || "Error getting workflows" });
46
+ }
47
+ }
48
+ async function getVNextWorkflowByIdHandler({ mastra, workflowId }) {
49
+ try {
50
+ if (!workflowId) {
51
+ throw new HTTPException(400, { message: "Workflow ID is required" });
52
+ }
53
+ const workflow = mastra.vnext_getWorkflow(workflowId);
54
+ if (!workflow) {
55
+ throw new HTTPException(404, { message: "Workflow not found" });
56
+ }
57
+ return {
58
+ steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
59
+ acc[key] = {
60
+ id: step.id,
61
+ description: step.description,
62
+ inputSchema: step.inputSchema ? stringify(esm_default(step.inputSchema)) : void 0,
63
+ outputSchema: step.outputSchema ? stringify(esm_default(step.outputSchema)) : void 0,
64
+ resumeSchema: step.resumeSchema ? stringify(esm_default(step.resumeSchema)) : void 0,
65
+ suspendSchema: step.suspendSchema ? stringify(esm_default(step.suspendSchema)) : void 0
66
+ };
67
+ return acc;
68
+ }, {}),
69
+ name: workflow.name,
70
+ stepGraph: workflow.serializedStepGraph,
71
+ inputSchema: workflow.inputSchema ? stringify(esm_default(workflow.inputSchema)) : void 0,
72
+ outputSchema: workflow.outputSchema ? stringify(esm_default(workflow.outputSchema)) : void 0
73
+ };
74
+ } catch (error) {
75
+ throw new HTTPException(500, { message: error?.message || "Error getting workflow" });
76
+ }
77
+ }
78
+ async function getVNextWorkflowRunHandler({
79
+ mastra,
80
+ workflowId,
81
+ runId
82
+ }) {
83
+ try {
84
+ if (!workflowId) {
85
+ throw new HTTPException(400, { message: "Workflow ID is required" });
86
+ }
87
+ if (!runId) {
88
+ throw new HTTPException(400, { message: "Run ID is required" });
89
+ }
90
+ const workflow = mastra.vnext_getWorkflow(workflowId);
91
+ if (!workflow) {
92
+ throw new HTTPException(404, { message: "Workflow not found" });
93
+ }
94
+ const run = await workflow.getWorkflowRun(runId);
95
+ if (!run) {
96
+ throw new HTTPException(404, { message: "Workflow run not found" });
97
+ }
98
+ return run;
99
+ } catch (error) {
100
+ throw new HTTPException(500, { message: error?.message || "Error getting workflow run" });
101
+ }
102
+ }
103
+ async function createVNextWorkflowRunHandler({
104
+ mastra,
105
+ workflowId,
106
+ runId: prevRunId
107
+ }) {
108
+ try {
109
+ if (!workflowId) {
110
+ throw new HTTPException(400, { message: "Workflow ID is required" });
111
+ }
112
+ const workflow = mastra.vnext_getWorkflow(workflowId);
113
+ if (!workflow) {
114
+ throw new HTTPException(404, { message: "Workflow not found" });
115
+ }
116
+ const run = workflow.createRun({ runId: prevRunId });
117
+ return { runId: run.runId };
118
+ } catch (error) {
119
+ throw new HTTPException(500, { message: error?.message || "Error creating workflow run" });
120
+ }
121
+ }
122
+ async function startAsyncVNextWorkflowHandler({
123
+ mastra,
124
+ runtimeContext,
125
+ workflowId,
126
+ runId,
127
+ inputData
128
+ }) {
129
+ try {
130
+ if (!workflowId) {
131
+ throw new HTTPException(400, { message: "Workflow ID is required" });
132
+ }
133
+ const workflow = mastra.vnext_getWorkflow(workflowId);
134
+ if (!workflow) {
135
+ throw new HTTPException(404, { message: "Workflow not found" });
136
+ }
137
+ const _run = workflow.createRun({ runId });
138
+ const result = await _run.start({
139
+ inputData,
140
+ runtimeContext
141
+ });
142
+ return result;
143
+ } catch (error) {
144
+ throw new HTTPException(500, { message: error?.message || "Error executing workflow" });
145
+ }
146
+ }
147
+ async function startVNextWorkflowRunHandler({
148
+ mastra,
149
+ runtimeContext,
150
+ workflowId,
151
+ runId,
152
+ inputData
153
+ }) {
154
+ try {
155
+ if (!workflowId) {
156
+ throw new HTTPException(400, { message: "Workflow ID is required" });
157
+ }
158
+ if (!runId) {
159
+ throw new HTTPException(400, { message: "runId required to start run" });
160
+ }
161
+ const workflow = mastra.vnext_getWorkflow(workflowId);
162
+ const run = await workflow.getWorkflowRun(runId);
163
+ if (!run) {
164
+ throw new HTTPException(404, { message: "Workflow run not found" });
165
+ }
166
+ const _run = workflow.createRun({ runId });
167
+ await _run.start({
168
+ inputData,
169
+ runtimeContext
170
+ });
171
+ return { message: "Workflow run started" };
172
+ } catch (e) {
173
+ return handleError(e, "Error starting workflow run");
174
+ }
175
+ }
176
+ async function watchVNextWorkflowHandler({
177
+ mastra,
178
+ workflowId,
179
+ runId
180
+ }) {
181
+ try {
182
+ if (!workflowId) {
183
+ throw new HTTPException(400, { message: "Workflow ID is required" });
184
+ }
185
+ if (!runId) {
186
+ throw new HTTPException(400, { message: "runId required to watch workflow" });
187
+ }
188
+ const workflow = mastra.vnext_getWorkflow(workflowId);
189
+ const run = await workflow.getWorkflowRun(runId);
190
+ if (!run) {
191
+ throw new HTTPException(404, { message: "Workflow run not found" });
192
+ }
193
+ const _run = workflow.createRun({ runId });
194
+ let unwatch;
195
+ let asyncRef = null;
196
+ const stream = new ReadableStream({
197
+ start(controller) {
198
+ unwatch = _run.watch(({ type, payload, eventTimestamp }) => {
199
+ controller.enqueue(JSON.stringify({ type, payload, eventTimestamp, runId }));
200
+ if (asyncRef) {
201
+ clearImmediate(asyncRef);
202
+ asyncRef = null;
203
+ }
204
+ asyncRef = setImmediate(async () => {
205
+ const runDone = payload.workflowState.status !== "running";
206
+ if (runDone) {
207
+ controller.close();
208
+ unwatch?.();
209
+ }
210
+ });
211
+ });
212
+ },
213
+ cancel() {
214
+ unwatch?.();
215
+ }
216
+ });
217
+ return stream;
218
+ } catch (error) {
219
+ return handleError(error, "Error watching workflow");
220
+ }
221
+ }
222
+ async function resumeAsyncVNextWorkflowHandler({
223
+ mastra,
224
+ workflowId,
225
+ runId,
226
+ body,
227
+ runtimeContext
228
+ }) {
229
+ try {
230
+ if (!workflowId) {
231
+ throw new HTTPException(400, { message: "Workflow ID is required" });
232
+ }
233
+ if (!runId) {
234
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
235
+ }
236
+ if (!body.step) {
237
+ throw new HTTPException(400, { message: "step required to resume workflow" });
238
+ }
239
+ const workflow = mastra.vnext_getWorkflow(workflowId);
240
+ const run = await workflow.getWorkflowRun(runId);
241
+ if (!run) {
242
+ throw new HTTPException(404, { message: "Workflow run not found" });
243
+ }
244
+ const _run = workflow.createRun({ runId });
245
+ const result = await _run.resume({
246
+ step: body.step,
247
+ resumeData: body.resumeData,
248
+ runtimeContext
249
+ });
250
+ return result;
251
+ } catch (error) {
252
+ return handleError(error, "Error resuming workflow step");
253
+ }
254
+ }
255
+ async function resumeVNextWorkflowHandler({
256
+ mastra,
257
+ workflowId,
258
+ runId,
259
+ body,
260
+ runtimeContext
261
+ }) {
262
+ try {
263
+ if (!workflowId) {
264
+ throw new HTTPException(400, { message: "Workflow ID is required" });
265
+ }
266
+ if (!runId) {
267
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
268
+ }
269
+ if (!body.step) {
270
+ throw new HTTPException(400, { message: "step required to resume workflow" });
271
+ }
272
+ const workflow = mastra.vnext_getWorkflow(workflowId);
273
+ const run = await workflow.getWorkflowRun(runId);
274
+ if (!run) {
275
+ throw new HTTPException(404, { message: "Workflow run not found" });
276
+ }
277
+ const _run = workflow.createRun({ runId });
278
+ await _run.resume({
279
+ step: body.step,
280
+ resumeData: body.resumeData,
281
+ runtimeContext
282
+ });
283
+ return { message: "Workflow run resumed" };
284
+ } catch (error) {
285
+ return handleError(error, "Error resuming workflow");
286
+ }
287
+ }
288
+ async function getVNextWorkflowRunsHandler({ mastra, workflowId }) {
289
+ try {
290
+ if (!workflowId) {
291
+ throw new HTTPException(400, { message: "Workflow ID is required" });
292
+ }
293
+ const workflow = mastra.vnext_getWorkflow(workflowId);
294
+ const workflowRuns = await workflow.getWorkflowRuns() || {
295
+ runs: [],
296
+ total: 0
297
+ };
298
+ return workflowRuns;
299
+ } catch (error) {
300
+ return handleError(error, "Error getting workflow runs");
301
+ }
302
+ }
303
+
304
+ export { createVNextWorkflowRunHandler, getVNextWorkflowByIdHandler, getVNextWorkflowRunHandler, getVNextWorkflowRunsHandler, getVNextWorkflowsHandler, resumeAsyncVNextWorkflowHandler, resumeVNextWorkflowHandler, startAsyncVNextWorkflowHandler, startVNextWorkflowRunHandler, vNextWorkflows_exports, watchVNextWorkflowHandler };
@@ -1,4 +1,4 @@
1
- import { stringify, esm_default } from './chunk-VK6FX47H.js';
1
+ import { stringify, esm_default } from './chunk-OMN3UI6X.js';
2
2
  import { handleError } from './chunk-3AHQ5RGN.js';
3
3
  import { __export, HTTPException } from './chunk-TRDNDNGQ.js';
4
4
  import { ReadableStream } from 'node:stream/web';
@@ -32,7 +32,9 @@ async function getWorkflowsHandler({ mastra }) {
32
32
  steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
33
33
  const _step = step;
34
34
  acc2[key2] = {
35
- ..._step,
35
+ id: _step.id,
36
+ description: _step.description,
37
+ workflowId: _step.workflowId,
36
38
  inputSchema: _step.inputSchema ? stringify(esm_default(_step.inputSchema)) : void 0,
37
39
  outputSchema: _step.outputSchema ? stringify(esm_default(_step.outputSchema)) : void 0
38
40
  };
@@ -65,7 +67,9 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
65
67
  steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
66
68
  const _step = step;
67
69
  acc[key] = {
68
- ..._step,
70
+ id: _step.id,
71
+ description: _step.description,
72
+ workflowId: _step.workflowId,
69
73
  inputSchema: _step.inputSchema ? stringify(esm_default(_step.inputSchema)) : void 0,
70
74
  outputSchema: _step.outputSchema ? stringify(esm_default(_step.outputSchema)) : void 0
71
75
  };
@@ -78,6 +82,7 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
78
82
  }
79
83
  async function startAsyncWorkflowHandler({
80
84
  mastra,
85
+ runtimeContext,
81
86
  workflowId,
82
87
  runId,
83
88
  triggerData
@@ -93,7 +98,8 @@ async function startAsyncWorkflowHandler({
93
98
  if (!runId) {
94
99
  const { start } = workflow.createRun();
95
100
  const result2 = await start({
96
- triggerData
101
+ triggerData,
102
+ runtimeContext
97
103
  });
98
104
  return result2;
99
105
  }
@@ -102,7 +108,8 @@ async function startAsyncWorkflowHandler({
102
108
  throw new HTTPException(404, { message: "Workflow run not found" });
103
109
  }
104
110
  const result = await run.start({
105
- triggerData
111
+ triggerData,
112
+ runtimeContext
106
113
  });
107
114
  return result;
108
115
  } catch (error) {
@@ -155,6 +162,7 @@ async function createRunHandler({
155
162
  }
156
163
  async function startWorkflowRunHandler({
157
164
  mastra,
165
+ runtimeContext,
158
166
  workflowId,
159
167
  runId,
160
168
  triggerData
@@ -172,7 +180,8 @@ async function startWorkflowRunHandler({
172
180
  throw new HTTPException(404, { message: "Workflow run not found" });
173
181
  }
174
182
  await run.start({
175
- triggerData
183
+ triggerData,
184
+ runtimeContext
176
185
  });
177
186
  return { message: "Workflow run started" };
178
187
  } catch (e) {
@@ -227,7 +236,8 @@ async function resumeAsyncWorkflowHandler({
227
236
  mastra,
228
237
  workflowId,
229
238
  runId,
230
- body
239
+ body,
240
+ runtimeContext
231
241
  }) {
232
242
  try {
233
243
  if (!workflowId) {
@@ -243,7 +253,8 @@ async function resumeAsyncWorkflowHandler({
243
253
  }
244
254
  const result = await run.resume({
245
255
  stepId: body.stepId,
246
- context: body.context
256
+ context: body.context,
257
+ runtimeContext
247
258
  });
248
259
  return result;
249
260
  } catch (error) {
@@ -254,7 +265,8 @@ async function resumeWorkflowHandler({
254
265
  mastra,
255
266
  workflowId,
256
267
  runId,
257
- body
268
+ body,
269
+ runtimeContext
258
270
  }) {
259
271
  try {
260
272
  if (!workflowId) {
@@ -270,7 +282,8 @@ async function resumeWorkflowHandler({
270
282
  }
271
283
  await run.resume({
272
284
  stepId: body.stepId,
273
- context: body.context
285
+ context: body.context,
286
+ runtimeContext
274
287
  });
275
288
  return { message: "Workflow run resumed" };
276
289
  } catch (error) {