@mastra/server 0.0.0-tool-call-parts-20250630193309 → 0.0.0-tsconfig-compile-20250703214351

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 (61) hide show
  1. package/dist/_tsup-dts-rollup.d.cts +20 -3
  2. package/dist/_tsup-dts-rollup.d.ts +20 -3
  3. package/dist/{chunk-OCWPVYNI.cjs → chunk-2KZFMI6P.cjs} +1 -0
  4. package/dist/{chunk-VPNDC2DI.cjs → chunk-2SLFAFTR.cjs} +12 -12
  5. package/dist/{chunk-QLG2PFHE.js → chunk-4D66QEKC.js} +2 -2
  6. package/dist/{chunk-E2LP4J6K.js → chunk-5PQQ42EZ.js} +7 -7
  7. package/dist/{chunk-BNEY4P4P.cjs → chunk-7TP2LX5L.cjs} +16 -16
  8. package/dist/{chunk-L3VURYKY.cjs → chunk-B2PAS2IB.cjs} +134 -55
  9. package/dist/{chunk-2BCWG3EZ.js → chunk-BK4XT6EG.js} +4 -4
  10. package/dist/{chunk-57CJTIPW.cjs → chunk-CCGRCYWJ.cjs} +2 -2
  11. package/dist/{chunk-C7564HUT.js → chunk-CRCR3ZUK.js} +3 -3
  12. package/dist/{chunk-RQ2Z56EC.cjs → chunk-DN7K6FJK.cjs} +34 -34
  13. package/dist/{chunk-Z3PTO2AK.cjs → chunk-FRVBFMO2.cjs} +15 -15
  14. package/dist/{chunk-B4MQFJ7G.cjs → chunk-G7KH752Y.cjs} +5 -5
  15. package/dist/{chunk-72LOJGUV.js → chunk-H7DMHBKY.js} +88 -11
  16. package/dist/{chunk-NGHSYB5B.cjs → chunk-JMLYCXMK.cjs} +36 -36
  17. package/dist/{chunk-R5VGYBV6.js → chunk-KHZKYUNR.js} +3 -3
  18. package/dist/{chunk-NYN7KFXL.js → chunk-LCM566I4.js} +1 -0
  19. package/dist/chunk-LF7P5PLR.js +14 -0
  20. package/dist/{chunk-EWLR2PNT.js → chunk-LRCAAFUA.js} +3 -3
  21. package/dist/{chunk-EP3XVEVC.cjs → chunk-LZ3VJXSO.cjs} +14 -14
  22. package/dist/{chunk-XUIJ7WRT.js → chunk-MKLYEKEF.js} +3 -3
  23. package/dist/chunk-PZQDCRPV.cjs +16 -0
  24. package/dist/{chunk-IMBY5XUG.cjs → chunk-QGX47B5D.cjs} +7 -7
  25. package/dist/{chunk-BFOA2QQY.js → chunk-RG473F6Y.js} +2 -2
  26. package/dist/{chunk-WJY57THV.cjs → chunk-RHSWAXKB.cjs} +22 -22
  27. package/dist/{chunk-H5PTF3Y4.js → chunk-RSEO4XPX.js} +1 -1
  28. package/dist/{chunk-55DOQLP6.js → chunk-WNVFNNWN.js} +2 -2
  29. package/dist/server/handlers/agents.cjs +7 -7
  30. package/dist/server/handlers/agents.js +1 -1
  31. package/dist/server/handlers/error.cjs +2 -2
  32. package/dist/server/handlers/error.js +1 -1
  33. package/dist/server/handlers/legacyWorkflows.cjs +11 -11
  34. package/dist/server/handlers/legacyWorkflows.js +1 -1
  35. package/dist/server/handlers/logs.cjs +4 -4
  36. package/dist/server/handlers/logs.js +1 -1
  37. package/dist/server/handlers/memory.cjs +9 -9
  38. package/dist/server/handlers/memory.js +1 -1
  39. package/dist/server/handlers/network.cjs +5 -5
  40. package/dist/server/handlers/network.js +1 -1
  41. package/dist/server/handlers/telemetry.cjs +3 -3
  42. package/dist/server/handlers/telemetry.js +1 -1
  43. package/dist/server/handlers/tools.cjs +5 -5
  44. package/dist/server/handlers/tools.js +1 -1
  45. package/dist/server/handlers/utils.cjs +2 -2
  46. package/dist/server/handlers/utils.js +1 -1
  47. package/dist/server/handlers/vNextNetwork.cjs +18 -18
  48. package/dist/server/handlers/vNextNetwork.js +3 -3
  49. package/dist/server/handlers/vector.cjs +7 -7
  50. package/dist/server/handlers/vector.js +1 -1
  51. package/dist/server/handlers/voice.cjs +5 -5
  52. package/dist/server/handlers/voice.js +1 -1
  53. package/dist/server/handlers/workflows.cjs +21 -13
  54. package/dist/server/handlers/workflows.d.cts +2 -0
  55. package/dist/server/handlers/workflows.d.ts +2 -0
  56. package/dist/server/handlers/workflows.js +1 -1
  57. package/dist/server/handlers.cjs +20 -20
  58. package/dist/server/handlers.js +10 -10
  59. package/package.json +5 -5
  60. package/dist/chunk-64U3UDTH.cjs +0 -13
  61. package/dist/chunk-M5ABIP7D.js +0 -11
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunk57CJTIPW_cjs = require('./chunk-57CJTIPW.cjs');
4
- var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
5
- var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
3
+ var chunkCCGRCYWJ_cjs = require('./chunk-CCGRCYWJ.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
 
8
8
  // src/server/handlers/memory.ts
@@ -25,11 +25,11 @@ async function getMemoryFromContext({
25
25
  }) {
26
26
  const agent = agentId ? mastra.getAgent(agentId) : null;
27
27
  if (agentId && !agent) {
28
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
28
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Agent not found" });
29
29
  }
30
30
  const network = networkId ? mastra.vnext_getNetwork(networkId) : null;
31
31
  if (networkId && !network) {
32
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Network not found" });
32
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Network not found" });
33
33
  }
34
34
  if (agent) {
35
35
  return agent?.getMemory() || mastra.getMemory();
@@ -52,7 +52,7 @@ async function getMemoryStatusHandler({
52
52
  }
53
53
  return { result: true };
54
54
  } catch (error) {
55
- return chunk64U3UDTH_cjs.handleError(error, "Error getting memory status");
55
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting memory status");
56
56
  }
57
57
  }
58
58
  async function getThreadsHandler({
@@ -65,13 +65,13 @@ async function getThreadsHandler({
65
65
  try {
66
66
  const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
67
67
  if (!memory) {
68
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
68
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
69
69
  }
70
- chunk57CJTIPW_cjs.validateBody({ resourceId });
70
+ chunkCCGRCYWJ_cjs.validateBody({ resourceId });
71
71
  const threads = await memory.getThreadsByResourceId({ resourceId });
72
72
  return threads;
73
73
  } catch (error) {
74
- return chunk64U3UDTH_cjs.handleError(error, "Error getting threads");
74
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting threads");
75
75
  }
76
76
  }
77
77
  async function getThreadByIdHandler({
@@ -82,18 +82,18 @@ async function getThreadByIdHandler({
82
82
  runtimeContext
83
83
  }) {
84
84
  try {
85
- chunk57CJTIPW_cjs.validateBody({ threadId });
85
+ chunkCCGRCYWJ_cjs.validateBody({ threadId });
86
86
  const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
87
87
  if (!memory) {
88
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
88
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
89
89
  }
90
90
  const thread = await memory.getThreadById({ threadId });
91
91
  if (!thread) {
92
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
92
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Thread not found" });
93
93
  }
94
94
  return thread;
95
95
  } catch (error) {
96
- return chunk64U3UDTH_cjs.handleError(error, "Error getting thread");
96
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting thread");
97
97
  }
98
98
  }
99
99
  async function saveMessagesHandler({
@@ -106,13 +106,13 @@ async function saveMessagesHandler({
106
106
  try {
107
107
  const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
108
108
  if (!memory) {
109
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
109
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
110
110
  }
111
111
  if (!body?.messages) {
112
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Messages are required" });
112
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Messages are required" });
113
113
  }
114
114
  if (!Array.isArray(body.messages)) {
115
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Messages should be an array" });
115
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Messages should be an array" });
116
116
  }
117
117
  const processedMessages = body.messages.map((message) => ({
118
118
  ...message,
@@ -122,7 +122,7 @@ async function saveMessagesHandler({
122
122
  const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });
123
123
  return result;
124
124
  } catch (error) {
125
- return chunk64U3UDTH_cjs.handleError(error, "Error saving messages");
125
+ return chunkPZQDCRPV_cjs.handleError(error, "Error saving messages");
126
126
  }
127
127
  }
128
128
  async function createThreadHandler({
@@ -135,9 +135,9 @@ async function createThreadHandler({
135
135
  try {
136
136
  const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
137
137
  if (!memory) {
138
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
138
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
139
139
  }
140
- chunk57CJTIPW_cjs.validateBody({ resourceId: body?.resourceId });
140
+ chunkCCGRCYWJ_cjs.validateBody({ resourceId: body?.resourceId });
141
141
  const result = await memory.createThread({
142
142
  resourceId: body?.resourceId,
143
143
  title: body?.title,
@@ -146,7 +146,7 @@ async function createThreadHandler({
146
146
  });
147
147
  return result;
148
148
  } catch (error) {
149
- return chunk64U3UDTH_cjs.handleError(error, "Error saving thread to memory");
149
+ return chunkPZQDCRPV_cjs.handleError(error, "Error saving thread to memory");
150
150
  }
151
151
  }
152
152
  async function updateThreadHandler({
@@ -160,17 +160,17 @@ async function updateThreadHandler({
160
160
  try {
161
161
  const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
162
162
  if (!body) {
163
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Body is required" });
163
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Body is required" });
164
164
  }
165
165
  const { title, metadata, resourceId } = body;
166
166
  const updatedAt = /* @__PURE__ */ new Date();
167
- chunk57CJTIPW_cjs.validateBody({ threadId });
167
+ chunkCCGRCYWJ_cjs.validateBody({ threadId });
168
168
  if (!memory) {
169
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
169
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
170
170
  }
171
171
  const thread = await memory.getThreadById({ threadId });
172
172
  if (!thread) {
173
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
173
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Thread not found" });
174
174
  }
175
175
  const updatedThread = {
176
176
  ...thread,
@@ -183,7 +183,7 @@ async function updateThreadHandler({
183
183
  const result = await memory.saveThread({ thread: updatedThread });
184
184
  return result;
185
185
  } catch (error) {
186
- return chunk64U3UDTH_cjs.handleError(error, "Error updating thread");
186
+ return chunkPZQDCRPV_cjs.handleError(error, "Error updating thread");
187
187
  }
188
188
  }
189
189
  async function deleteThreadHandler({
@@ -194,19 +194,19 @@ async function deleteThreadHandler({
194
194
  runtimeContext
195
195
  }) {
196
196
  try {
197
- chunk57CJTIPW_cjs.validateBody({ threadId });
197
+ chunkCCGRCYWJ_cjs.validateBody({ threadId });
198
198
  const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
199
199
  if (!memory) {
200
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
200
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
201
201
  }
202
202
  const thread = await memory.getThreadById({ threadId });
203
203
  if (!thread) {
204
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
204
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Thread not found" });
205
205
  }
206
206
  await memory.deleteThread(threadId);
207
207
  return { result: "Thread deleted" };
208
208
  } catch (error) {
209
- return chunk64U3UDTH_cjs.handleError(error, "Error deleting thread");
209
+ return chunkPZQDCRPV_cjs.handleError(error, "Error deleting thread");
210
210
  }
211
211
  }
212
212
  async function getMessagesHandler({
@@ -218,17 +218,17 @@ async function getMessagesHandler({
218
218
  runtimeContext
219
219
  }) {
220
220
  if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
221
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Invalid limit: must be a positive integer" });
221
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Invalid limit: must be a positive integer" });
222
222
  }
223
223
  try {
224
- chunk57CJTIPW_cjs.validateBody({ threadId });
224
+ chunkCCGRCYWJ_cjs.validateBody({ threadId });
225
225
  const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
226
226
  if (!memory) {
227
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
227
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
228
228
  }
229
229
  const thread = await memory.getThreadById({ threadId });
230
230
  if (!thread) {
231
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
231
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Thread not found" });
232
232
  }
233
233
  const result = await memory.query({
234
234
  threadId,
@@ -236,7 +236,7 @@ async function getMessagesHandler({
236
236
  });
237
237
  return { messages: result.messages, uiMessages: result.uiMessages };
238
238
  } catch (error) {
239
- return chunk64U3UDTH_cjs.handleError(error, "Error getting messages");
239
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting messages");
240
240
  }
241
241
  }
242
242
 
@@ -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,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 };