@mastra/server 0.0.0-cli-debug-2-20250611100354 → 0.0.0-cloudflare-deployer-dont-install-deps-20250714111754

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 (70) hide show
  1. package/LICENSE.md +11 -42
  2. package/dist/_tsup-dts-rollup.d.cts +275 -28
  3. package/dist/_tsup-dts-rollup.d.ts +275 -28
  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-3CNDE7QY.cjs +308 -0
  7. package/dist/{chunk-QLG2PFHE.js → chunk-4D66QEKC.js} +2 -2
  8. package/dist/{chunk-TEZOEGR4.js → chunk-5PQQ42EZ.js} +8 -8
  9. package/dist/{chunk-BNEY4P4P.cjs → chunk-7TP2LX5L.cjs} +16 -16
  10. package/dist/chunk-B2PAS2IB.cjs +514 -0
  11. package/dist/{chunk-6F2H7Y45.js → chunk-BK4XT6EG.js} +29 -14
  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-TJO277H7.cjs → chunk-FRVBFMO2.cjs} +20 -20
  15. package/dist/{chunk-B4MQFJ7G.cjs → chunk-G7KH752Y.cjs} +5 -5
  16. package/dist/{chunk-7IBZ4L35.js → chunk-H7DMHBKY.js} +181 -27
  17. package/dist/{chunk-UZ7FJ66C.cjs → chunk-JMLYCXMK.cjs} +43 -43
  18. package/dist/{chunk-CP55EVBK.js → chunk-KHZKYUNR.js} +15 -11
  19. package/dist/{chunk-I7KJZNX5.js → chunk-KOHWJYJT.js} +110 -25
  20. package/dist/{chunk-NYN7KFXL.js → chunk-LCM566I4.js} +1 -0
  21. package/dist/chunk-LF7P5PLR.js +14 -0
  22. package/dist/{chunk-XUGQSVZ4.cjs → chunk-LI436ITD.cjs} +107 -69
  23. package/dist/{chunk-HYP7B2TL.js → chunk-LRCAAFUA.js} +4 -4
  24. package/dist/{chunk-JEWNMAYQ.cjs → chunk-LZ3VJXSO.cjs} +43 -28
  25. package/dist/{chunk-WKWHYFX4.js → chunk-MEGCYGBU.js} +108 -70
  26. package/dist/chunk-PZQDCRPV.cjs +16 -0
  27. package/dist/{chunk-IMBY5XUG.cjs → chunk-QGX47B5D.cjs} +7 -7
  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-55DOQLP6.js → chunk-WNVFNNWN.js} +2 -2
  32. package/dist/server/handlers/agents.cjs +7 -7
  33. package/dist/server/handlers/agents.js +1 -1
  34. package/dist/server/handlers/error.cjs +2 -2
  35. package/dist/server/handlers/error.js +1 -1
  36. package/dist/server/handlers/legacyWorkflows.cjs +11 -11
  37. package/dist/server/handlers/legacyWorkflows.js +1 -1
  38. package/dist/server/handlers/logs.cjs +4 -4
  39. package/dist/server/handlers/logs.js +1 -1
  40. package/dist/server/handlers/memory.cjs +17 -9
  41. package/dist/server/handlers/memory.d.cts +2 -0
  42. package/dist/server/handlers/memory.d.ts +2 -0
  43. package/dist/server/handlers/memory.js +1 -1
  44. package/dist/server/handlers/network.cjs +5 -5
  45. package/dist/server/handlers/network.js +1 -1
  46. package/dist/server/handlers/telemetry.cjs +3 -3
  47. package/dist/server/handlers/telemetry.js +1 -1
  48. package/dist/server/handlers/tools.cjs +5 -5
  49. package/dist/server/handlers/tools.js +1 -1
  50. package/dist/server/handlers/utils.cjs +2 -2
  51. package/dist/server/handlers/utils.js +1 -1
  52. package/dist/server/handlers/vNextNetwork.cjs +218 -0
  53. package/dist/server/handlers/vNextNetwork.d.cts +6 -0
  54. package/dist/server/handlers/vNextNetwork.d.ts +6 -0
  55. package/dist/server/handlers/vNextNetwork.js +211 -0
  56. package/dist/server/handlers/vector.cjs +7 -7
  57. package/dist/server/handlers/vector.js +1 -1
  58. package/dist/server/handlers/voice.cjs +5 -5
  59. package/dist/server/handlers/voice.js +1 -1
  60. package/dist/server/handlers/workflows.cjs +24 -12
  61. package/dist/server/handlers/workflows.d.cts +3 -0
  62. package/dist/server/handlers/workflows.d.ts +3 -0
  63. package/dist/server/handlers/workflows.js +1 -1
  64. package/dist/server/handlers.cjs +20 -20
  65. package/dist/server/handlers.js +10 -10
  66. package/package.json +11 -12
  67. package/dist/chunk-64U3UDTH.cjs +0 -13
  68. package/dist/chunk-6TJSHFCJ.cjs +0 -221
  69. package/dist/chunk-JKF6PRPU.cjs +0 -357
  70. package/dist/chunk-M5ABIP7D.js +0 -11
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var chunkXUGQSVZ4_cjs = require('./chunk-XUGQSVZ4.cjs');
4
- var chunk57CJTIPW_cjs = require('./chunk-57CJTIPW.cjs');
5
- var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
6
- var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
3
+ var chunkLI436ITD_cjs = require('./chunk-LI436ITD.cjs');
4
+ var chunkCCGRCYWJ_cjs = require('./chunk-CCGRCYWJ.cjs');
5
+ var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
6
+ var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
7
7
  var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
8
8
  var tools = require('@mastra/core/tools');
9
9
 
@@ -25,8 +25,8 @@ async function getToolsHandler({ tools }) {
25
25
  const tool = _tool;
26
26
  acc[id] = {
27
27
  ...tool,
28
- inputSchema: tool.inputSchema ? chunkXUGQSVZ4_cjs.stringify(chunkXUGQSVZ4_cjs.esm_default(tool.inputSchema)) : void 0,
29
- outputSchema: tool.outputSchema ? chunkXUGQSVZ4_cjs.stringify(chunkXUGQSVZ4_cjs.esm_default(tool.outputSchema)) : void 0
28
+ inputSchema: tool.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(tool.inputSchema)) : void 0,
29
+ outputSchema: tool.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(tool.outputSchema)) : void 0
30
30
  };
31
31
  return acc;
32
32
  },
@@ -34,23 +34,23 @@ async function getToolsHandler({ tools }) {
34
34
  );
35
35
  return serializedTools;
36
36
  } catch (error) {
37
- return chunk64U3UDTH_cjs.handleError(error, "Error getting tools");
37
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting tools");
38
38
  }
39
39
  }
40
40
  async function getToolByIdHandler({ tools, toolId }) {
41
41
  try {
42
42
  const tool = Object.values(tools || {}).find((tool2) => tool2.id === toolId);
43
43
  if (!tool) {
44
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Tool not found" });
44
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Tool not found" });
45
45
  }
46
46
  const serializedTool = {
47
47
  ...tool,
48
- inputSchema: tool.inputSchema ? chunkXUGQSVZ4_cjs.stringify(chunkXUGQSVZ4_cjs.esm_default(tool.inputSchema)) : void 0,
49
- outputSchema: tool.outputSchema ? chunkXUGQSVZ4_cjs.stringify(chunkXUGQSVZ4_cjs.esm_default(tool.outputSchema)) : void 0
48
+ inputSchema: tool.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(tool.inputSchema)) : void 0,
49
+ outputSchema: tool.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(tool.outputSchema)) : void 0
50
50
  };
51
51
  return serializedTool;
52
52
  } catch (error) {
53
- return chunk64U3UDTH_cjs.handleError(error, "Error getting tool");
53
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting tool");
54
54
  }
55
55
  }
56
56
  function executeToolHandler(tools$1) {
@@ -63,16 +63,16 @@ function executeToolHandler(tools$1) {
63
63
  }) => {
64
64
  try {
65
65
  if (!toolId) {
66
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Tool ID is required" });
66
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Tool ID is required" });
67
67
  }
68
68
  const tool = Object.values(tools$1 || {}).find((tool2) => tool2.id === toolId);
69
69
  if (!tool) {
70
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Tool not found" });
70
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Tool not found" });
71
71
  }
72
72
  if (!tool?.execute) {
73
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Tool is not executable" });
73
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Tool is not executable" });
74
74
  }
75
- chunk57CJTIPW_cjs.validateBody({ data });
75
+ chunkCCGRCYWJ_cjs.validateBody({ data });
76
76
  if (tools.isVercelTool(tool)) {
77
77
  const result2 = await tool.execute(data);
78
78
  return result2;
@@ -85,7 +85,7 @@ function executeToolHandler(tools$1) {
85
85
  });
86
86
  return result;
87
87
  } catch (error) {
88
- return chunk64U3UDTH_cjs.handleError(error, "Error executing tool");
88
+ return chunkPZQDCRPV_cjs.handleError(error, "Error executing tool");
89
89
  }
90
90
  };
91
91
  }
@@ -99,15 +99,15 @@ async function executeAgentToolHandler({
99
99
  try {
100
100
  const agent = agentId ? mastra.getAgent(agentId) : null;
101
101
  if (!agent) {
102
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Tool not found" });
102
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Tool not found" });
103
103
  }
104
104
  const agentTools = await agent.getTools({ runtimeContext });
105
105
  const tool = Object.values(agentTools || {}).find((tool2) => tool2.id === toolId);
106
106
  if (!tool) {
107
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Tool not found" });
107
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Tool not found" });
108
108
  }
109
109
  if (!tool?.execute) {
110
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Tool is not executable" });
110
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Tool is not executable" });
111
111
  }
112
112
  const result = await tool.execute({
113
113
  context: data,
@@ -117,7 +117,7 @@ async function executeAgentToolHandler({
117
117
  });
118
118
  return result;
119
119
  } catch (error) {
120
- return chunk64U3UDTH_cjs.handleError(error, "Error executing tool");
120
+ return chunkPZQDCRPV_cjs.handleError(error, "Error executing tool");
121
121
  }
122
122
  }
123
123
 
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
4
- var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
3
+ var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
4
+ var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
5
5
  var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
6
6
 
7
7
  // src/server/handlers/telemetry.ts
@@ -15,13 +15,13 @@ async function getTelemetryHandler({ mastra, body }) {
15
15
  const telemetry = mastra.getTelemetry();
16
16
  const storage = mastra.getStorage();
17
17
  if (!telemetry) {
18
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Telemetry is not initialized" });
18
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Telemetry is not initialized" });
19
19
  }
20
20
  if (!storage) {
21
21
  return [];
22
22
  }
23
23
  if (!body) {
24
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Body is required" });
24
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Body is required" });
25
25
  }
26
26
  const { name, scope, page, perPage, attribute, fromDate, toDate } = body;
27
27
  const attributes = attribute ? Object.fromEntries(
@@ -41,7 +41,7 @@ async function getTelemetryHandler({ mastra, body }) {
41
41
  });
42
42
  return traces;
43
43
  } catch (error2) {
44
- return chunk64U3UDTH_cjs.handleError(error2, "Error getting telemetry");
44
+ return chunkPZQDCRPV_cjs.handleError(error2, "Error getting telemetry");
45
45
  }
46
46
  }
47
47
  async function storeTelemetryHandler({ mastra, body }) {
@@ -1,24 +1,46 @@
1
- import { stringify, esm_default } from './chunk-WKWHYFX4.js';
2
- import { handleError } from './chunk-M5ABIP7D.js';
3
- import { HTTPException } from './chunk-NYN7KFXL.js';
1
+ import { stringify, esm_default } from './chunk-MEGCYGBU.js';
2
+ import { handleError } from './chunk-LF7P5PLR.js';
3
+ import { HTTPException } from './chunk-LCM566I4.js';
4
4
  import { __export } from './chunk-MLKGABMK.js';
5
5
  import { ReadableStream } from 'stream/web';
6
6
 
7
7
  // src/server/handlers/workflows.ts
8
8
  var workflows_exports = {};
9
9
  __export(workflows_exports, {
10
+ cancelWorkflowRunHandler: () => cancelWorkflowRunHandler,
10
11
  createWorkflowRunHandler: () => createWorkflowRunHandler,
11
12
  getWorkflowByIdHandler: () => getWorkflowByIdHandler,
12
13
  getWorkflowRunByIdHandler: () => getWorkflowRunByIdHandler,
14
+ getWorkflowRunExecutionResultHandler: () => getWorkflowRunExecutionResultHandler,
13
15
  getWorkflowRunsHandler: () => getWorkflowRunsHandler,
14
16
  getWorkflowsHandler: () => getWorkflowsHandler,
15
17
  resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
16
18
  resumeWorkflowHandler: () => resumeWorkflowHandler,
19
+ sendWorkflowRunEventHandler: () => sendWorkflowRunEventHandler,
17
20
  startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
18
21
  startWorkflowRunHandler: () => startWorkflowRunHandler,
19
22
  streamWorkflowHandler: () => streamWorkflowHandler,
20
23
  watchWorkflowHandler: () => watchWorkflowHandler
21
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
+ }
22
44
  async function getWorkflowsHandler({ mastra }) {
23
45
  try {
24
46
  const workflows = mastra.getWorkflows({ serialized: false });
@@ -37,6 +59,7 @@ async function getWorkflowsHandler({ mastra }) {
37
59
  };
38
60
  return acc2;
39
61
  }, {}),
62
+ allSteps: getSteps(workflow.steps) || {},
40
63
  stepGraph: workflow.serializedStepGraph,
41
64
  inputSchema: workflow.inputSchema ? stringify(esm_default(workflow.inputSchema)) : void 0,
42
65
  outputSchema: workflow.outputSchema ? stringify(esm_default(workflow.outputSchema)) : void 0
@@ -45,15 +68,49 @@ async function getWorkflowsHandler({ mastra }) {
45
68
  }, {});
46
69
  return _workflows;
47
70
  } catch (error) {
48
- throw new HTTPException(500, { message: error?.message || "Error getting workflows" });
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" });
49
105
  }
106
+ return { workflow };
50
107
  }
51
108
  async function getWorkflowByIdHandler({ mastra, workflowId }) {
52
109
  try {
53
110
  if (!workflowId) {
54
111
  throw new HTTPException(400, { message: "Workflow ID is required" });
55
112
  }
56
- const workflow = mastra.getWorkflow(workflowId);
113
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
57
114
  if (!workflow) {
58
115
  throw new HTTPException(404, { message: "Workflow not found" });
59
116
  }
@@ -69,6 +126,7 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
69
126
  };
70
127
  return acc;
71
128
  }, {}),
129
+ allSteps: getSteps(workflow.steps) || {},
72
130
  name: workflow.name,
73
131
  description: workflow.description,
74
132
  stepGraph: workflow.serializedStepGraph,
@@ -76,7 +134,7 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
76
134
  outputSchema: workflow.outputSchema ? stringify(esm_default(workflow.outputSchema)) : void 0
77
135
  };
78
136
  } catch (error) {
79
- throw new HTTPException(500, { message: error?.message || "Error getting workflow" });
137
+ return handleError(error, "Error getting workflow");
80
138
  }
81
139
  }
82
140
  async function getWorkflowRunByIdHandler({
@@ -91,7 +149,7 @@ async function getWorkflowRunByIdHandler({
91
149
  if (!runId) {
92
150
  throw new HTTPException(400, { message: "Run ID is required" });
93
151
  }
94
- const workflow = mastra.getWorkflow(workflowId);
152
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
95
153
  if (!workflow) {
96
154
  throw new HTTPException(404, { message: "Workflow not found" });
97
155
  }
@@ -101,7 +159,32 @@ async function getWorkflowRunByIdHandler({
101
159
  }
102
160
  return run;
103
161
  } catch (error) {
104
- throw new HTTPException(500, { message: error?.message || "Error getting workflow run" });
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");
105
188
  }
106
189
  }
107
190
  async function createWorkflowRunHandler({
@@ -113,14 +196,14 @@ async function createWorkflowRunHandler({
113
196
  if (!workflowId) {
114
197
  throw new HTTPException(400, { message: "Workflow ID is required" });
115
198
  }
116
- const workflow = mastra.getWorkflow(workflowId);
199
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
117
200
  if (!workflow) {
118
201
  throw new HTTPException(404, { message: "Workflow not found" });
119
202
  }
120
- const run = workflow.createRun({ runId: prevRunId });
203
+ const run = await workflow.createRunAsync({ runId: prevRunId });
121
204
  return { runId: run.runId };
122
205
  } catch (error) {
123
- throw new HTTPException(500, { message: error?.message || "Error creating workflow run" });
206
+ return handleError(error, "Error creating workflow run");
124
207
  }
125
208
  }
126
209
  async function startAsyncWorkflowHandler({
@@ -134,18 +217,18 @@ async function startAsyncWorkflowHandler({
134
217
  if (!workflowId) {
135
218
  throw new HTTPException(400, { message: "Workflow ID is required" });
136
219
  }
137
- const workflow = mastra.getWorkflow(workflowId);
220
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
138
221
  if (!workflow) {
139
222
  throw new HTTPException(404, { message: "Workflow not found" });
140
223
  }
141
- const _run = workflow.createRun({ runId });
224
+ const _run = await workflow.createRunAsync({ runId });
142
225
  const result = await _run.start({
143
226
  inputData,
144
227
  runtimeContext
145
228
  });
146
229
  return result;
147
230
  } catch (error) {
148
- throw new HTTPException(500, { message: error?.message || "Error executing workflow" });
231
+ return handleError(error, "Error starting async workflow");
149
232
  }
150
233
  }
151
234
  async function startWorkflowRunHandler({
@@ -162,12 +245,15 @@ async function startWorkflowRunHandler({
162
245
  if (!runId) {
163
246
  throw new HTTPException(400, { message: "runId required to start run" });
164
247
  }
165
- const workflow = mastra.getWorkflow(workflowId);
248
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
249
+ if (!workflow) {
250
+ throw new HTTPException(404, { message: "Workflow not found" });
251
+ }
166
252
  const run = await workflow.getWorkflowRunById(runId);
167
253
  if (!run) {
168
254
  throw new HTTPException(404, { message: "Workflow run not found" });
169
255
  }
170
- const _run = workflow.createRun({ runId });
256
+ const _run = await workflow.createRunAsync({ runId });
171
257
  void _run.start({
172
258
  inputData,
173
259
  runtimeContext
@@ -189,12 +275,15 @@ async function watchWorkflowHandler({
189
275
  if (!runId) {
190
276
  throw new HTTPException(400, { message: "runId required to watch workflow" });
191
277
  }
192
- const workflow = mastra.getWorkflow(workflowId);
278
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
279
+ if (!workflow) {
280
+ throw new HTTPException(404, { message: "Workflow not found" });
281
+ }
193
282
  const run = await workflow.getWorkflowRunById(runId);
194
283
  if (!run) {
195
284
  throw new HTTPException(404, { message: "Workflow run not found" });
196
285
  }
197
- const _run = workflow.createRun({ runId });
286
+ const _run = await workflow.createRunAsync({ runId });
198
287
  let unwatch;
199
288
  let asyncRef = null;
200
289
  const stream = new ReadableStream({
@@ -223,7 +312,7 @@ async function watchWorkflowHandler({
223
312
  return handleError(error, "Error watching workflow");
224
313
  }
225
314
  }
226
- function streamWorkflowHandler({
315
+ async function streamWorkflowHandler({
227
316
  mastra,
228
317
  runtimeContext,
229
318
  workflowId,
@@ -237,11 +326,11 @@ function streamWorkflowHandler({
237
326
  if (!runId) {
238
327
  throw new HTTPException(400, { message: "runId required to resume workflow" });
239
328
  }
240
- const workflow = mastra.getWorkflow(workflowId);
329
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
241
330
  if (!workflow) {
242
331
  throw new HTTPException(404, { message: "Workflow not found" });
243
332
  }
244
- const run = workflow.createRun({ runId });
333
+ const run = await workflow.createRunAsync({ runId });
245
334
  const result = run.stream({
246
335
  inputData,
247
336
  runtimeContext
@@ -268,12 +357,15 @@ async function resumeAsyncWorkflowHandler({
268
357
  if (!body.step) {
269
358
  throw new HTTPException(400, { message: "step required to resume workflow" });
270
359
  }
271
- const workflow = mastra.getWorkflow(workflowId);
360
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
361
+ if (!workflow) {
362
+ throw new HTTPException(404, { message: "Workflow not found" });
363
+ }
272
364
  const run = await workflow.getWorkflowRunById(runId);
273
365
  if (!run) {
274
366
  throw new HTTPException(404, { message: "Workflow run not found" });
275
367
  }
276
- const _run = workflow.createRun({ runId });
368
+ const _run = await workflow.createRunAsync({ runId });
277
369
  const result = await _run.resume({
278
370
  step: body.step,
279
371
  resumeData: body.resumeData,
@@ -301,12 +393,15 @@ async function resumeWorkflowHandler({
301
393
  if (!body.step) {
302
394
  throw new HTTPException(400, { message: "step required to resume workflow" });
303
395
  }
304
- const workflow = mastra.getWorkflow(workflowId);
396
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
397
+ if (!workflow) {
398
+ throw new HTTPException(404, { message: "Workflow not found" });
399
+ }
305
400
  const run = await workflow.getWorkflowRunById(runId);
306
401
  if (!run) {
307
402
  throw new HTTPException(404, { message: "Workflow run not found" });
308
403
  }
309
- const _run = workflow.createRun({ runId });
404
+ const _run = await workflow.createRunAsync({ runId });
310
405
  void _run.resume({
311
406
  step: body.step,
312
407
  resumeData: body.resumeData,
@@ -330,7 +425,10 @@ async function getWorkflowRunsHandler({
330
425
  if (!workflowId) {
331
426
  throw new HTTPException(400, { message: "Workflow ID is required" });
332
427
  }
333
- const workflow = mastra.getWorkflow(workflowId);
428
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
429
+ if (!workflow) {
430
+ throw new HTTPException(404, { message: "Workflow not found" });
431
+ }
334
432
  const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
335
433
  runs: [],
336
434
  total: 0
@@ -340,5 +438,61 @@ async function getWorkflowRunsHandler({
340
438
  return handleError(error, "Error getting workflow runs");
341
439
  }
342
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
+ }
343
497
 
344
- export { createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunsHandler, getWorkflowsHandler, resumeAsyncWorkflowHandler, resumeWorkflowHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamWorkflowHandler, watchWorkflowHandler, workflows_exports };
498
+ export { cancelWorkflowRunHandler, createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunExecutionResultHandler, getWorkflowRunsHandler, getWorkflowsHandler, resumeAsyncWorkflowHandler, resumeWorkflowHandler, sendWorkflowRunEventHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamWorkflowHandler, watchWorkflowHandler, workflows_exports };