@mastra/server 0.0.0-tool-call-parts-20250630193309 → 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 (72) hide show
  1. package/LICENSE.md +11 -42
  2. package/dist/_tsup-dts-rollup.d.cts +142 -14
  3. package/dist/_tsup-dts-rollup.d.ts +142 -14
  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-QLG2PFHE.js → chunk-4D66QEKC.js} +2 -2
  7. package/dist/{chunk-E2LP4J6K.js → chunk-5PQQ42EZ.js} +7 -7
  8. package/dist/{chunk-BNEY4P4P.cjs → chunk-7TP2LX5L.cjs} +16 -16
  9. package/dist/{chunk-L3VURYKY.cjs → chunk-B2PAS2IB.cjs} +134 -55
  10. package/dist/{chunk-2BCWG3EZ.js → chunk-BK4XT6EG.js} +4 -4
  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-Z3PTO2AK.cjs → chunk-FRVBFMO2.cjs} +15 -15
  15. package/dist/{chunk-XUIJ7WRT.js → chunk-G4L7OMCA.js} +84 -5
  16. package/dist/{chunk-B4MQFJ7G.cjs → chunk-G7KH752Y.cjs} +5 -5
  17. package/dist/{chunk-72LOJGUV.js → chunk-H7DMHBKY.js} +88 -11
  18. package/dist/{chunk-NGHSYB5B.cjs → chunk-JMLYCXMK.cjs} +36 -36
  19. package/dist/{chunk-R5VGYBV6.js → chunk-KHZKYUNR.js} +3 -3
  20. package/dist/{chunk-NYN7KFXL.js → chunk-LCM566I4.js} +1 -0
  21. package/dist/chunk-LF7P5PLR.js +14 -0
  22. package/dist/{chunk-EWLR2PNT.js → chunk-LRCAAFUA.js} +3 -3
  23. package/dist/{chunk-EP3XVEVC.cjs → chunk-LZ3VJXSO.cjs} +14 -14
  24. package/dist/chunk-PZQDCRPV.cjs +16 -0
  25. package/dist/{chunk-IMBY5XUG.cjs → chunk-QGX47B5D.cjs} +7 -7
  26. package/dist/{chunk-BFOA2QQY.js → chunk-RG473F6Y.js} +2 -2
  27. package/dist/{chunk-WJY57THV.cjs → chunk-RHSWAXKB.cjs} +22 -22
  28. package/dist/{chunk-H5PTF3Y4.js → chunk-RSEO4XPX.js} +1 -1
  29. package/dist/chunk-VULESSU5.js +149 -0
  30. package/dist/{chunk-55DOQLP6.js → chunk-WNVFNNWN.js} +2 -2
  31. package/dist/{chunk-RQ2Z56EC.cjs → chunk-Z75RYULP.cjs} +117 -35
  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 +21 -9
  41. package/dist/server/handlers/memory.d.cts +3 -0
  42. package/dist/server/handlers/memory.d.ts +3 -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/scores.cjs +30 -0
  47. package/dist/server/handlers/scores.d.cts +6 -0
  48. package/dist/server/handlers/scores.d.ts +6 -0
  49. package/dist/server/handlers/scores.js +1 -0
  50. package/dist/server/handlers/telemetry.cjs +3 -3
  51. package/dist/server/handlers/telemetry.js +1 -1
  52. package/dist/server/handlers/tools.cjs +5 -5
  53. package/dist/server/handlers/tools.js +1 -1
  54. package/dist/server/handlers/utils.cjs +2 -2
  55. package/dist/server/handlers/utils.js +1 -1
  56. package/dist/server/handlers/vNextNetwork.cjs +18 -18
  57. package/dist/server/handlers/vNextNetwork.js +3 -3
  58. package/dist/server/handlers/vector.cjs +7 -7
  59. package/dist/server/handlers/vector.js +1 -1
  60. package/dist/server/handlers/voice.cjs +5 -5
  61. package/dist/server/handlers/voice.js +1 -1
  62. package/dist/server/handlers/workflows.cjs +21 -13
  63. package/dist/server/handlers/workflows.d.cts +2 -0
  64. package/dist/server/handlers/workflows.d.ts +2 -0
  65. package/dist/server/handlers/workflows.js +1 -1
  66. package/dist/server/handlers.cjs +28 -23
  67. package/dist/server/handlers.d.cts +3 -2
  68. package/dist/server/handlers.d.ts +3 -2
  69. package/dist/server/handlers.js +11 -10
  70. package/package.json +8 -7
  71. package/dist/chunk-64U3UDTH.cjs +0 -13
  72. package/dist/chunk-M5ABIP7D.js +0 -11
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkLI436ITD_cjs = require('./chunk-LI436ITD.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');
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
 
@@ -34,14 +34,14 @@ 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,
@@ -50,7 +50,7 @@ async function getToolByIdHandler({ tools, toolId }) {
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,8 @@
1
- import { validateBody } from './chunk-H5PTF3Y4.js';
2
- import { handleError } from './chunk-M5ABIP7D.js';
3
- import { HTTPException } from './chunk-NYN7KFXL.js';
1
+ import { validateBody } from './chunk-RSEO4XPX.js';
2
+ import { handleError } from './chunk-LF7P5PLR.js';
3
+ import { HTTPException } from './chunk-LCM566I4.js';
4
4
  import { __export } from './chunk-MLKGABMK.js';
5
+ import { generateEmptyFromSchema } from '@mastra/core';
5
6
 
6
7
  // src/server/handlers/memory.ts
7
8
  var memory_exports = {};
@@ -10,10 +11,13 @@ __export(memory_exports, {
10
11
  deleteThreadHandler: () => deleteThreadHandler,
11
12
  getMemoryStatusHandler: () => getMemoryStatusHandler,
12
13
  getMessagesHandler: () => getMessagesHandler,
14
+ getMessagesPaginatedHandler: () => getMessagesPaginatedHandler,
13
15
  getThreadByIdHandler: () => getThreadByIdHandler,
14
16
  getThreadsHandler: () => getThreadsHandler,
17
+ getWorkingMemoryHandler: () => getWorkingMemoryHandler,
15
18
  saveMessagesHandler: () => saveMessagesHandler,
16
- updateThreadHandler: () => updateThreadHandler
19
+ updateThreadHandler: () => updateThreadHandler,
20
+ updateWorkingMemoryHandler: () => updateWorkingMemoryHandler
17
21
  });
18
22
  async function getMemoryFromContext({
19
23
  mastra,
@@ -207,6 +211,29 @@ async function deleteThreadHandler({
207
211
  return handleError(error, "Error deleting thread");
208
212
  }
209
213
  }
214
+ async function getMessagesPaginatedHandler({
215
+ mastra,
216
+ threadId,
217
+ resourceId,
218
+ selectBy,
219
+ format
220
+ }) {
221
+ try {
222
+ validateBody({ threadId });
223
+ const storage = mastra.getStorage();
224
+ if (!storage) {
225
+ throw new HTTPException(400, { message: "Storage is not initialized" });
226
+ }
227
+ const thread = await storage.getThreadById({ threadId });
228
+ if (!thread) {
229
+ throw new HTTPException(404, { message: "Thread not found" });
230
+ }
231
+ const result = await storage.getMessagesPaginated({ threadId, resourceId, selectBy, format });
232
+ return result;
233
+ } catch (error) {
234
+ return handleError(error, "Error getting messages");
235
+ }
236
+ }
210
237
  async function getMessagesHandler({
211
238
  mastra,
212
239
  agentId,
@@ -237,5 +264,57 @@ async function getMessagesHandler({
237
264
  return handleError(error, "Error getting messages");
238
265
  }
239
266
  }
267
+ async function getWorkingMemoryHandler({
268
+ mastra,
269
+ agentId,
270
+ threadId,
271
+ resourceId,
272
+ networkId,
273
+ runtimeContext,
274
+ memoryConfig
275
+ }) {
276
+ try {
277
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
278
+ validateBody({ threadId });
279
+ if (!memory) {
280
+ throw new HTTPException(400, { message: "Memory is not initialized" });
281
+ }
282
+ const thread = await memory.getThreadById({ threadId });
283
+ const threadExists = !!thread;
284
+ const template = await memory.getWorkingMemoryTemplate({ memoryConfig });
285
+ const workingMemoryTemplate = template?.format === "json" ? { ...template, content: JSON.stringify(generateEmptyFromSchema(template.content)) } : template;
286
+ const workingMemory = await memory.getWorkingMemory({ threadId, resourceId, memoryConfig });
287
+ const config = memory.getMergedThreadConfig(memoryConfig || {});
288
+ const source = config.workingMemory?.scope === "resource" && resourceId ? "resource" : "thread";
289
+ return { workingMemory, source, workingMemoryTemplate, threadExists };
290
+ } catch (error) {
291
+ return handleError(error, "Error getting working memory");
292
+ }
293
+ }
294
+ async function updateWorkingMemoryHandler({
295
+ mastra,
296
+ agentId,
297
+ threadId,
298
+ body,
299
+ networkId,
300
+ runtimeContext
301
+ }) {
302
+ try {
303
+ validateBody({ threadId });
304
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
305
+ const { resourceId, memoryConfig, workingMemory } = body;
306
+ if (!memory) {
307
+ throw new HTTPException(400, { message: "Memory is not initialized" });
308
+ }
309
+ const thread = await memory.getThreadById({ threadId });
310
+ if (!thread) {
311
+ throw new HTTPException(404, { message: "Thread not found" });
312
+ }
313
+ await memory.updateWorkingMemory({ threadId, resourceId, workingMemory, memoryConfig });
314
+ return { success: true };
315
+ } catch (error) {
316
+ return handleError(error, "Error updating working memory");
317
+ }
318
+ }
240
319
 
241
- export { createThreadHandler, deleteThreadHandler, getMemoryStatusHandler, getMessagesHandler, getThreadByIdHandler, getThreadsHandler, memory_exports, saveMessagesHandler, updateThreadHandler };
320
+ export { createThreadHandler, deleteThreadHandler, getMemoryStatusHandler, getMessagesHandler, getMessagesPaginatedHandler, getThreadByIdHandler, getThreadsHandler, getWorkingMemoryHandler, memory_exports, saveMessagesHandler, updateThreadHandler, updateWorkingMemoryHandler };
@@ -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,12 +1,13 @@
1
1
  import { stringify, esm_default } from './chunk-MEGCYGBU.js';
2
- import { handleError } from './chunk-M5ABIP7D.js';
3
- import { HTTPException } from './chunk-NYN7KFXL.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,
@@ -15,11 +16,31 @@ __export(workflows_exports, {
15
16
  getWorkflowsHandler: () => getWorkflowsHandler,
16
17
  resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
17
18
  resumeWorkflowHandler: () => resumeWorkflowHandler,
19
+ sendWorkflowRunEventHandler: () => sendWorkflowRunEventHandler,
18
20
  startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
19
21
  startWorkflowRunHandler: () => startWorkflowRunHandler,
20
22
  streamWorkflowHandler: () => streamWorkflowHandler,
21
23
  watchWorkflowHandler: () => watchWorkflowHandler
22
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
+ }
23
44
  async function getWorkflowsHandler({ mastra }) {
24
45
  try {
25
46
  const workflows = mastra.getWorkflows({ serialized: false });
@@ -38,6 +59,7 @@ async function getWorkflowsHandler({ mastra }) {
38
59
  };
39
60
  return acc2;
40
61
  }, {}),
62
+ allSteps: getSteps(workflow.steps) || {},
41
63
  stepGraph: workflow.serializedStepGraph,
42
64
  inputSchema: workflow.inputSchema ? stringify(esm_default(workflow.inputSchema)) : void 0,
43
65
  outputSchema: workflow.outputSchema ? stringify(esm_default(workflow.outputSchema)) : void 0
@@ -46,7 +68,7 @@ async function getWorkflowsHandler({ mastra }) {
46
68
  }, {});
47
69
  return _workflows;
48
70
  } catch (error) {
49
- throw new HTTPException(500, { message: error?.message || "Error getting workflows" });
71
+ return handleError(error, "Error getting workflows");
50
72
  }
51
73
  }
52
74
  async function getWorkflowsFromSystem({ mastra, workflowId }) {
@@ -104,6 +126,7 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
104
126
  };
105
127
  return acc;
106
128
  }, {}),
129
+ allSteps: getSteps(workflow.steps) || {},
107
130
  name: workflow.name,
108
131
  description: workflow.description,
109
132
  stepGraph: workflow.serializedStepGraph,
@@ -111,7 +134,7 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
111
134
  outputSchema: workflow.outputSchema ? stringify(esm_default(workflow.outputSchema)) : void 0
112
135
  };
113
136
  } catch (error) {
114
- throw new HTTPException(500, { message: error?.message || "Error getting workflow" });
137
+ return handleError(error, "Error getting workflow");
115
138
  }
116
139
  }
117
140
  async function getWorkflowRunByIdHandler({
@@ -136,7 +159,7 @@ async function getWorkflowRunByIdHandler({
136
159
  }
137
160
  return run;
138
161
  } catch (error) {
139
- throw new HTTPException(500, { message: error?.message || "Error getting workflow run" });
162
+ return handleError(error, "Error getting workflow run");
140
163
  }
141
164
  }
142
165
  async function getWorkflowRunExecutionResultHandler({
@@ -161,9 +184,7 @@ async function getWorkflowRunExecutionResultHandler({
161
184
  }
162
185
  return executionResult;
163
186
  } catch (error) {
164
- throw new HTTPException(500, {
165
- message: error?.message || "Error getting workflow run execution result"
166
- });
187
+ return handleError(error, "Error getting workflow run execution result");
167
188
  }
168
189
  }
169
190
  async function createWorkflowRunHandler({
@@ -182,7 +203,7 @@ async function createWorkflowRunHandler({
182
203
  const run = await workflow.createRunAsync({ runId: prevRunId });
183
204
  return { runId: run.runId };
184
205
  } catch (error) {
185
- throw new HTTPException(500, { message: error?.message || "Error creating workflow run" });
206
+ return handleError(error, "Error creating workflow run");
186
207
  }
187
208
  }
188
209
  async function startAsyncWorkflowHandler({
@@ -207,7 +228,7 @@ async function startAsyncWorkflowHandler({
207
228
  });
208
229
  return result;
209
230
  } catch (error) {
210
- throw new HTTPException(500, { message: error?.message || "Error executing workflow" });
231
+ return handleError(error, "Error starting async workflow");
211
232
  }
212
233
  }
213
234
  async function startWorkflowRunHandler({
@@ -417,5 +438,61 @@ async function getWorkflowRunsHandler({
417
438
  return handleError(error, "Error getting workflow runs");
418
439
  }
419
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
+ }
420
497
 
421
- export { createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunExecutionResultHandler, 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 };
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkLI436ITD_cjs = require('./chunk-LI436ITD.cjs');
4
- var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
5
- var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
4
+ var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
5
+ var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
6
6
  var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
7
7
  var web = require('stream/web');
8
8
 
@@ -48,17 +48,17 @@ async function getLegacyWorkflowsHandler({ mastra }) {
48
48
  }, {});
49
49
  return _workflows;
50
50
  } catch (error) {
51
- throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error getting workflows" });
51
+ return chunkPZQDCRPV_cjs.handleError(error, "error getting workflows");
52
52
  }
53
53
  }
54
54
  async function getLegacyWorkflowByIdHandler({ mastra, workflowId }) {
55
55
  try {
56
56
  if (!workflowId) {
57
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
57
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
58
58
  }
59
59
  const workflow = mastra.legacy_getWorkflow(workflowId);
60
60
  if (!workflow) {
61
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
61
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
62
62
  }
63
63
  return {
64
64
  stepGraph: workflow.stepGraph,
@@ -80,7 +80,7 @@ async function getLegacyWorkflowByIdHandler({ mastra, workflowId }) {
80
80
  }, {})
81
81
  };
82
82
  } catch (error) {
83
- throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error getting workflow" });
83
+ return chunkPZQDCRPV_cjs.handleError(error, "error getting workflow by id");
84
84
  }
85
85
  }
86
86
  async function startAsyncLegacyWorkflowHandler({
@@ -92,11 +92,11 @@ async function startAsyncLegacyWorkflowHandler({
92
92
  }) {
93
93
  try {
94
94
  if (!workflowId) {
95
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
95
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
96
96
  }
97
97
  const workflow = mastra.legacy_getWorkflow(workflowId);
98
98
  if (!workflow) {
99
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
99
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
100
100
  }
101
101
  if (!runId) {
102
102
  const newRun = workflow.createRun();
@@ -108,7 +108,7 @@ async function startAsyncLegacyWorkflowHandler({
108
108
  }
109
109
  const run = workflow.getMemoryRun(runId);
110
110
  if (!run) {
111
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
111
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
112
112
  }
113
113
  const result = await run.start({
114
114
  triggerData,
@@ -116,7 +116,7 @@ async function startAsyncLegacyWorkflowHandler({
116
116
  });
117
117
  return result;
118
118
  } catch (error) {
119
- throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error executing workflow" });
119
+ return chunkPZQDCRPV_cjs.handleError(error, "error starting workflow");
120
120
  }
121
121
  }
122
122
  async function getLegacyWorkflowRunHandler({
@@ -126,22 +126,22 @@ async function getLegacyWorkflowRunHandler({
126
126
  }) {
127
127
  try {
128
128
  if (!workflowId) {
129
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
129
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
130
130
  }
131
131
  if (!runId) {
132
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Run ID is required" });
132
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Run ID is required" });
133
133
  }
134
134
  const workflow = mastra.legacy_getWorkflow(workflowId);
135
135
  if (!workflow) {
136
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
136
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
137
137
  }
138
138
  const run = await workflow.getRun(runId);
139
139
  if (!run) {
140
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
140
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
141
141
  }
142
142
  return run;
143
143
  } catch (error) {
144
- throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error getting workflow run" });
144
+ return chunkPZQDCRPV_cjs.handleError(error, "error getting workflow run");
145
145
  }
146
146
  }
147
147
  async function createLegacyWorkflowRunHandler({
@@ -151,16 +151,16 @@ async function createLegacyWorkflowRunHandler({
151
151
  }) {
152
152
  try {
153
153
  if (!workflowId) {
154
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
154
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
155
155
  }
156
156
  const workflow = mastra.legacy_getWorkflow(workflowId);
157
157
  if (!workflow) {
158
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
158
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
159
159
  }
160
160
  const newRun = workflow.createRun({ runId: prevRunId });
161
161
  return { runId: newRun.runId };
162
162
  } catch (error) {
163
- throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error creating workflow run" });
163
+ return chunkPZQDCRPV_cjs.handleError(error, "error creating workflow run");
164
164
  }
165
165
  }
166
166
  async function startLegacyWorkflowRunHandler({
@@ -172,15 +172,15 @@ async function startLegacyWorkflowRunHandler({
172
172
  }) {
173
173
  try {
174
174
  if (!workflowId) {
175
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
175
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
176
176
  }
177
177
  if (!runId) {
178
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to start run" });
178
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to start run" });
179
179
  }
180
180
  const workflow = mastra.legacy_getWorkflow(workflowId);
181
181
  const run = workflow.getMemoryRun(runId);
182
182
  if (!run) {
183
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
183
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
184
184
  }
185
185
  void run.start({
186
186
  triggerData,
@@ -188,7 +188,7 @@ async function startLegacyWorkflowRunHandler({
188
188
  });
189
189
  return { message: "Workflow run started" };
190
190
  } catch (e) {
191
- return chunk64U3UDTH_cjs.handleError(e, "Error starting workflow run");
191
+ return chunkPZQDCRPV_cjs.handleError(e, "Error starting workflow run");
192
192
  }
193
193
  }
194
194
  async function watchLegacyWorkflowHandler({
@@ -198,15 +198,15 @@ async function watchLegacyWorkflowHandler({
198
198
  }) {
199
199
  try {
200
200
  if (!workflowId) {
201
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
201
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
202
202
  }
203
203
  if (!runId) {
204
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to watch workflow" });
204
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to watch workflow" });
205
205
  }
206
206
  const workflow = mastra.legacy_getWorkflow(workflowId);
207
207
  const run = workflow.getMemoryRun(runId);
208
208
  if (!run) {
209
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
209
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
210
210
  }
211
211
  let unwatch;
212
212
  let asyncRef = null;
@@ -234,7 +234,7 @@ async function watchLegacyWorkflowHandler({
234
234
  });
235
235
  return stream;
236
236
  } catch (error) {
237
- return chunk64U3UDTH_cjs.handleError(error, "Error watching workflow");
237
+ return chunkPZQDCRPV_cjs.handleError(error, "Error watching workflow");
238
238
  }
239
239
  }
240
240
  async function resumeAsyncLegacyWorkflowHandler({
@@ -246,15 +246,15 @@ async function resumeAsyncLegacyWorkflowHandler({
246
246
  }) {
247
247
  try {
248
248
  if (!workflowId) {
249
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
249
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
250
250
  }
251
251
  if (!runId) {
252
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to resume workflow" });
252
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to resume workflow" });
253
253
  }
254
254
  const workflow = mastra.legacy_getWorkflow(workflowId);
255
255
  const run = workflow.getMemoryRun(runId);
256
256
  if (!run) {
257
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
257
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
258
258
  }
259
259
  const result = await run.resume({
260
260
  stepId: body.stepId,
@@ -263,7 +263,7 @@ async function resumeAsyncLegacyWorkflowHandler({
263
263
  });
264
264
  return result;
265
265
  } catch (error) {
266
- return chunk64U3UDTH_cjs.handleError(error, "Error resuming workflow step");
266
+ return chunkPZQDCRPV_cjs.handleError(error, "Error resuming workflow step");
267
267
  }
268
268
  }
269
269
  async function resumeLegacyWorkflowHandler({
@@ -275,15 +275,15 @@ async function resumeLegacyWorkflowHandler({
275
275
  }) {
276
276
  try {
277
277
  if (!workflowId) {
278
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
278
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
279
279
  }
280
280
  if (!runId) {
281
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to resume workflow" });
281
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to resume workflow" });
282
282
  }
283
283
  const workflow = mastra.legacy_getWorkflow(workflowId);
284
284
  const run = workflow.getMemoryRun(runId);
285
285
  if (!run) {
286
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
286
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
287
287
  }
288
288
  void run.resume({
289
289
  stepId: body.stepId,
@@ -292,7 +292,7 @@ async function resumeLegacyWorkflowHandler({
292
292
  });
293
293
  return { message: "Workflow run resumed" };
294
294
  } catch (error) {
295
- return chunk64U3UDTH_cjs.handleError(error, "Error resuming workflow");
295
+ return chunkPZQDCRPV_cjs.handleError(error, "Error resuming workflow");
296
296
  }
297
297
  }
298
298
  async function getLegacyWorkflowRunsHandler({
@@ -306,7 +306,7 @@ async function getLegacyWorkflowRunsHandler({
306
306
  }) {
307
307
  try {
308
308
  if (!workflowId) {
309
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
309
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
310
310
  }
311
311
  const workflow = mastra.legacy_getWorkflow(workflowId);
312
312
  const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
@@ -315,7 +315,7 @@ async function getLegacyWorkflowRunsHandler({
315
315
  };
316
316
  return workflowRuns;
317
317
  } catch (error) {
318
- return chunk64U3UDTH_cjs.handleError(error, "Error getting workflow runs");
318
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting workflow runs");
319
319
  }
320
320
  }
321
321