@mastra/server 0.0.0-commonjs-20250414101718

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