@mastra/server 0.0.0-agui-20250501191909 → 0.0.0-ai-v5-20250625014956

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 (86) hide show
  1. package/README.md +48 -135
  2. package/dist/_tsup-dts-rollup.d.cts +303 -94
  3. package/dist/_tsup-dts-rollup.d.ts +303 -94
  4. package/dist/{chunk-5JNVY6DU.js → chunk-2HXKRRNS.js} +7 -5
  5. package/dist/{chunk-JPB6RPGB.js → chunk-3CSC35VL.js} +163 -46
  6. package/dist/{chunk-4JINXASC.js → chunk-55DOQLP6.js} +5 -4
  7. package/dist/{chunk-QN4KF3BH.cjs → chunk-57CJTIPW.cjs} +2 -2
  8. package/dist/{chunk-ZLBRQFDD.cjs → chunk-64U3UDTH.cjs} +2 -2
  9. package/dist/chunk-75ZPJI57.cjs +9 -0
  10. package/dist/chunk-ASKESBJW.cjs +2004 -0
  11. package/dist/chunk-B36R2PHA.js +504 -0
  12. package/dist/{chunk-7IWQE76Z.cjs → chunk-B4MQFJ7G.cjs} +16 -10
  13. package/dist/{chunk-WTHDCRMY.js → chunk-BFOA2QQY.js} +12 -6
  14. package/dist/{chunk-M56ECCHK.cjs → chunk-BNEY4P4P.cjs} +20 -19
  15. package/dist/{chunk-M3YJLWTU.js → chunk-CLYX4KLH.js} +63 -52
  16. package/dist/{chunk-RBQASTUP.js → chunk-EKDOJJMG.js} +26 -6
  17. package/dist/{chunk-L7XE5QTW.js → chunk-H5PTF3Y4.js} +1 -1
  18. package/dist/chunk-IMBY5XUG.cjs +86 -0
  19. package/dist/chunk-LFA7KZS6.cjs +276 -0
  20. package/dist/{chunk-3AHQ5RGN.js → chunk-M5ABIP7D.js} +1 -1
  21. package/dist/chunk-MLKGABMK.js +7 -0
  22. package/dist/{chunk-2FJURXCL.cjs → chunk-NDAWJCUJ.cjs} +56 -36
  23. package/dist/{chunk-D3G23FP3.cjs → chunk-NGURCFEJ.cjs} +24 -22
  24. package/dist/{chunk-TRDNDNGQ.js → chunk-NYN7KFXL.js} +1 -7
  25. package/dist/{chunk-FV45V6WC.cjs → chunk-OCWPVYNI.cjs} +0 -7
  26. package/dist/chunk-QLG2PFHE.js +81 -0
  27. package/dist/{chunk-5YGDYMRB.cjs → chunk-QOHBG2JI.cjs} +22 -19
  28. package/dist/{chunk-Q6SHQECN.js → chunk-R5VGYBV6.js} +34 -10
  29. package/dist/{chunk-QJ3AHN64.js → chunk-SAR3AYOK.js} +12 -9
  30. package/dist/chunk-T7WA465P.cjs +512 -0
  31. package/dist/chunk-TGJMNUYJ.js +2001 -0
  32. package/dist/{chunk-Y3SV5XK4.js → chunk-WC7U7A6Y.js} +104 -17
  33. package/dist/chunk-WE32JG64.cjs +332 -0
  34. package/dist/chunk-WJY57THV.cjs +118 -0
  35. package/dist/chunk-XUTX4CAB.cjs +435 -0
  36. package/dist/server/handlers/a2a.cjs +30 -0
  37. package/dist/server/handlers/a2a.d.cts +6 -0
  38. package/dist/server/handlers/a2a.d.ts +6 -0
  39. package/dist/server/handlers/a2a.js +1 -0
  40. package/dist/server/handlers/agents.cjs +7 -7
  41. package/dist/server/handlers/agents.js +1 -1
  42. package/dist/server/handlers/error.cjs +2 -2
  43. package/dist/server/handlers/error.js +1 -1
  44. package/dist/server/handlers/legacyWorkflows.cjs +46 -0
  45. package/dist/server/handlers/legacyWorkflows.d.cts +10 -0
  46. package/dist/server/handlers/legacyWorkflows.d.ts +10 -0
  47. package/dist/server/handlers/legacyWorkflows.js +1 -0
  48. package/dist/server/handlers/logs.cjs +4 -4
  49. package/dist/server/handlers/logs.js +1 -1
  50. package/dist/server/handlers/memory.cjs +9 -9
  51. package/dist/server/handlers/memory.js +1 -1
  52. package/dist/server/handlers/network.cjs +5 -5
  53. package/dist/server/handlers/network.js +1 -1
  54. package/dist/server/handlers/telemetry.cjs +3 -3
  55. package/dist/server/handlers/telemetry.js +1 -1
  56. package/dist/server/handlers/tools.cjs +5 -5
  57. package/dist/server/handlers/tools.js +1 -1
  58. package/dist/server/handlers/utils.cjs +2 -2
  59. package/dist/server/handlers/utils.js +1 -1
  60. package/dist/server/handlers/vector.cjs +7 -7
  61. package/dist/server/handlers/vector.js +1 -1
  62. package/dist/server/handlers/voice.cjs +8 -4
  63. package/dist/server/handlers/voice.d.cts +1 -0
  64. package/dist/server/handlers/voice.d.ts +1 -0
  65. package/dist/server/handlers/voice.js +1 -1
  66. package/dist/server/handlers/workflows.cjs +21 -13
  67. package/dist/server/handlers/workflows.d.cts +4 -2
  68. package/dist/server/handlers/workflows.d.ts +4 -2
  69. package/dist/server/handlers/workflows.js +1 -1
  70. package/dist/server/handlers.cjs +32 -27
  71. package/dist/server/handlers.d.cts +2 -1
  72. package/dist/server/handlers.d.ts +2 -1
  73. package/dist/server/handlers.js +11 -10
  74. package/package.json +13 -12
  75. package/dist/chunk-3EJZQ6TQ.js +0 -49
  76. package/dist/chunk-4BIX6GMY.cjs +0 -189
  77. package/dist/chunk-55HTWX4C.cjs +0 -93
  78. package/dist/chunk-5SWCVTNL.cjs +0 -5579
  79. package/dist/chunk-AELYAUEE.cjs +0 -316
  80. package/dist/chunk-EVCC233P.cjs +0 -321
  81. package/dist/chunk-OMN3UI6X.js +0 -5576
  82. package/dist/chunk-SKBVVI24.cjs +0 -54
  83. package/dist/server/handlers/vNextWorkflows.cjs +0 -46
  84. package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
  85. package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
  86. package/dist/server/handlers/vNextWorkflows.js +0 -1
@@ -0,0 +1,276 @@
1
+ 'use strict';
2
+
3
+ var chunkASKESBJW_cjs = require('./chunk-ASKESBJW.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');
7
+ var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
8
+ var agent = require('@mastra/core/agent');
9
+ var runtimeContext = require('@mastra/core/runtime-context');
10
+
11
+ // src/server/handlers/agents.ts
12
+ var agents_exports = {};
13
+ chunk75ZPJI57_cjs.__export(agents_exports, {
14
+ generateHandler: () => generateHandler,
15
+ getAgentByIdHandler: () => getAgentByIdHandler,
16
+ getAgentsHandler: () => getAgentsHandler,
17
+ getEvalsByAgentIdHandler: () => getEvalsByAgentIdHandler,
18
+ getLiveEvalsByAgentIdHandler: () => getLiveEvalsByAgentIdHandler,
19
+ streamGenerateHandler: () => streamGenerateHandler
20
+ });
21
+ async function getAgentsHandler({ mastra, runtimeContext }) {
22
+ try {
23
+ const agents = mastra.getAgents();
24
+ const serializedAgentsMap = await Promise.all(
25
+ Object.entries(agents).map(async ([id, agent]) => {
26
+ const instructions = await agent.getInstructions({ runtimeContext });
27
+ const tools = await agent.getTools({ runtimeContext });
28
+ const llm = await agent.getLLM({ runtimeContext });
29
+ const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext });
30
+ const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext });
31
+ const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
32
+ const _tool = tool;
33
+ acc[key] = {
34
+ ..._tool,
35
+ inputSchema: _tool.inputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(_tool.inputSchema)) : void 0,
36
+ outputSchema: _tool.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(_tool.outputSchema)) : void 0
37
+ };
38
+ return acc;
39
+ }, {});
40
+ let serializedAgentWorkflows = {};
41
+ if ("getWorkflows" in agent) {
42
+ const logger = mastra.getLogger();
43
+ try {
44
+ const workflows = await agent.getWorkflows({ runtimeContext });
45
+ serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
46
+ return {
47
+ ...acc,
48
+ [key]: {
49
+ name: workflow.name
50
+ }
51
+ };
52
+ }, {});
53
+ } catch (error) {
54
+ logger.error("Error getting workflows for agent", { agentName: agent.name, error });
55
+ }
56
+ }
57
+ return {
58
+ id,
59
+ name: agent.name,
60
+ instructions,
61
+ tools: serializedAgentTools,
62
+ workflows: serializedAgentWorkflows,
63
+ provider: llm?.getProvider(),
64
+ modelId: llm?.getModelId(),
65
+ defaultGenerateOptions,
66
+ defaultStreamOptions
67
+ };
68
+ })
69
+ );
70
+ const serializedAgents = serializedAgentsMap.reduce((acc, { id, ...rest }) => {
71
+ acc[id] = rest;
72
+ return acc;
73
+ }, {});
74
+ return serializedAgents;
75
+ } catch (error) {
76
+ return chunk64U3UDTH_cjs.handleError(error, "Error getting agents");
77
+ }
78
+ }
79
+ async function getAgentByIdHandler({
80
+ mastra,
81
+ runtimeContext,
82
+ agentId,
83
+ isPlayground = false
84
+ }) {
85
+ try {
86
+ const agent = mastra.getAgent(agentId);
87
+ if (!agent) {
88
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
89
+ }
90
+ const tools = await agent.getTools({ runtimeContext });
91
+ const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
92
+ const _tool = tool;
93
+ acc[key] = {
94
+ ..._tool,
95
+ inputSchema: _tool.inputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(_tool.inputSchema)) : void 0,
96
+ outputSchema: _tool.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(_tool.outputSchema)) : void 0
97
+ };
98
+ return acc;
99
+ }, {});
100
+ let serializedAgentWorkflows = {};
101
+ if ("getWorkflows" in agent) {
102
+ const logger = mastra.getLogger();
103
+ try {
104
+ const workflows = await agent.getWorkflows({ runtimeContext });
105
+ serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
106
+ return {
107
+ ...acc,
108
+ [key]: {
109
+ name: workflow.name,
110
+ steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
111
+ return {
112
+ ...acc2,
113
+ [key2]: {
114
+ id: step.id,
115
+ description: step.description
116
+ }
117
+ };
118
+ }, {})
119
+ }
120
+ };
121
+ }, {});
122
+ } catch (error) {
123
+ logger.error("Error getting workflows for agent", { agentName: agent.name, error });
124
+ }
125
+ }
126
+ let proxyRuntimeContext = runtimeContext;
127
+ if (isPlayground) {
128
+ proxyRuntimeContext = new Proxy(runtimeContext, {
129
+ get(target, prop) {
130
+ if (prop === "get") {
131
+ return function(key) {
132
+ const value = target.get(key);
133
+ return value ?? `<${key}>`;
134
+ };
135
+ }
136
+ return Reflect.get(target, prop);
137
+ }
138
+ });
139
+ }
140
+ const instructions = await agent.getInstructions({ runtimeContext: proxyRuntimeContext });
141
+ const llm = await agent.getLLM({ runtimeContext });
142
+ const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext: proxyRuntimeContext });
143
+ const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext: proxyRuntimeContext });
144
+ return {
145
+ name: agent.name,
146
+ instructions,
147
+ tools: serializedAgentTools,
148
+ workflows: serializedAgentWorkflows,
149
+ provider: llm?.getProvider(),
150
+ modelId: llm?.getModelId(),
151
+ defaultGenerateOptions,
152
+ defaultStreamOptions
153
+ };
154
+ } catch (error) {
155
+ return chunk64U3UDTH_cjs.handleError(error, "Error getting agent");
156
+ }
157
+ }
158
+ async function getEvalsByAgentIdHandler({
159
+ mastra,
160
+ runtimeContext,
161
+ agentId
162
+ }) {
163
+ try {
164
+ const agent = mastra.getAgent(agentId);
165
+ const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
166
+ const instructions = await agent.getInstructions({ runtimeContext });
167
+ return {
168
+ id: agentId,
169
+ name: agent.name,
170
+ instructions,
171
+ evals
172
+ };
173
+ } catch (error) {
174
+ return chunk64U3UDTH_cjs.handleError(error, "Error getting test evals");
175
+ }
176
+ }
177
+ async function getLiveEvalsByAgentIdHandler({
178
+ mastra,
179
+ runtimeContext,
180
+ agentId
181
+ }) {
182
+ try {
183
+ const agent = mastra.getAgent(agentId);
184
+ const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
185
+ const instructions = await agent.getInstructions({ runtimeContext });
186
+ return {
187
+ id: agentId,
188
+ name: agent.name,
189
+ instructions,
190
+ evals
191
+ };
192
+ } catch (error) {
193
+ return chunk64U3UDTH_cjs.handleError(error, "Error getting live evals");
194
+ }
195
+ }
196
+ async function generateHandler({
197
+ mastra,
198
+ runtimeContext: runtimeContext$1,
199
+ agentId,
200
+ body
201
+ }) {
202
+ try {
203
+ const agent = mastra.getAgent(agentId);
204
+ if (!agent) {
205
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
206
+ }
207
+ const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
208
+ const finalResourceId = resourceId ?? resourceid;
209
+ const finalRuntimeContext = new runtimeContext.RuntimeContext([
210
+ ...Array.from(runtimeContext$1.entries()),
211
+ ...Array.from(Object.entries(agentRuntimeContext ?? {}))
212
+ ]);
213
+ chunk57CJTIPW_cjs.validateBody({ messages });
214
+ const result = await agent.generate(messages, {
215
+ ...rest,
216
+ // @ts-expect-error TODO fix types
217
+ resourceId: finalResourceId,
218
+ runtimeContext: finalRuntimeContext
219
+ });
220
+ return result;
221
+ } catch (error) {
222
+ return chunk64U3UDTH_cjs.handleError(error, "Error generating from agent");
223
+ }
224
+ }
225
+ async function streamGenerateHandler({
226
+ mastra,
227
+ runtimeContext: runtimeContext$1,
228
+ agentId,
229
+ body
230
+ }) {
231
+ try {
232
+ const agent$1 = mastra.getAgent(agentId);
233
+ if (!agent$1) {
234
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
235
+ }
236
+ const { messages, resourceId, runtimeContext: agentRuntimeContext, ...rest } = body;
237
+ const finalRuntimeContext = new runtimeContext.RuntimeContext([
238
+ ...Array.from(runtimeContext$1.entries()),
239
+ ...Array.from(Object.entries(agentRuntimeContext ?? {}))
240
+ ]);
241
+ chunk57CJTIPW_cjs.validateBody({ messages });
242
+ const streamResult = await agent$1.stream(messages, {
243
+ ...rest,
244
+ // @ts-expect-error TODO fix types
245
+ resourceId,
246
+ runtimeContext: finalRuntimeContext
247
+ });
248
+ const headers = {
249
+ "Transfer-Encoding": "chunked"
250
+ };
251
+ if (rest.output) {
252
+ return streamResult.toTextStreamResponse({ headers });
253
+ }
254
+ const useV4Compat = mastra.getAiSdkCompatMode() === "v4";
255
+ const uiMessageStream = streamResult.toUIMessageStreamResponse({
256
+ headers,
257
+ sendReasoning: true,
258
+ sendSources: true,
259
+ onError: (error) => {
260
+ return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
261
+ }
262
+ });
263
+ const streamResponse = useV4Compat ? agent.createV4CompatibleResponse(uiMessageStream.body) : uiMessageStream;
264
+ return streamResponse;
265
+ } catch (error) {
266
+ throw new chunkOCWPVYNI_cjs.HTTPException(error?.status ?? 500, { message: error?.message ?? "Error streaming from agent" });
267
+ }
268
+ }
269
+
270
+ exports.agents_exports = agents_exports;
271
+ exports.generateHandler = generateHandler;
272
+ exports.getAgentByIdHandler = getAgentByIdHandler;
273
+ exports.getAgentsHandler = getAgentsHandler;
274
+ exports.getEvalsByAgentIdHandler = getEvalsByAgentIdHandler;
275
+ exports.getLiveEvalsByAgentIdHandler = getLiveEvalsByAgentIdHandler;
276
+ exports.streamGenerateHandler = streamGenerateHandler;
@@ -1,4 +1,4 @@
1
- import { HTTPException } from './chunk-TRDNDNGQ.js';
1
+ import { HTTPException } from './chunk-NYN7KFXL.js';
2
2
 
3
3
  // src/server/handlers/error.ts
4
4
  function handleError(error, defaultMessage) {
@@ -0,0 +1,7 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ export { __export };
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var chunkQN4KF3BH_cjs = require('./chunk-QN4KF3BH.cjs');
4
- var chunkZLBRQFDD_cjs = require('./chunk-ZLBRQFDD.cjs');
5
- var chunkFV45V6WC_cjs = require('./chunk-FV45V6WC.cjs');
3
+ var chunk57CJTIPW_cjs = require('./chunk-57CJTIPW.cjs');
4
+ var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
5
+ var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
6
+ var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
6
7
 
7
8
  // src/server/handlers/memory.ts
8
9
  var memory_exports = {};
9
- chunkFV45V6WC_cjs.__export(memory_exports, {
10
+ chunk75ZPJI57_cjs.__export(memory_exports, {
10
11
  createThreadHandler: () => createThreadHandler,
11
12
  deleteThreadHandler: () => deleteThreadHandler,
12
13
  getMemoryStatusHandler: () => getMemoryStatusHandler,
@@ -22,7 +23,7 @@ function getMemoryFromContext({
22
23
  }) {
23
24
  const agent = agentId ? mastra.getAgent(agentId) : null;
24
25
  if (agentId && !agent) {
25
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Agent not found" });
26
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
26
27
  }
27
28
  const memory = agent?.getMemory?.() || mastra.getMemory();
28
29
  return memory;
@@ -35,7 +36,7 @@ async function getMemoryStatusHandler({ mastra, agentId }) {
35
36
  }
36
37
  return { result: true };
37
38
  } catch (error) {
38
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting memory status");
39
+ return chunk64U3UDTH_cjs.handleError(error, "Error getting memory status");
39
40
  }
40
41
  }
41
42
  async function getThreadsHandler({
@@ -46,13 +47,13 @@ async function getThreadsHandler({
46
47
  try {
47
48
  const memory = getMemoryFromContext({ mastra, agentId });
48
49
  if (!memory) {
49
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
50
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
50
51
  }
51
- chunkQN4KF3BH_cjs.validateBody({ resourceId });
52
+ chunk57CJTIPW_cjs.validateBody({ resourceId });
52
53
  const threads = await memory.getThreadsByResourceId({ resourceId });
53
54
  return threads;
54
55
  } catch (error) {
55
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting threads");
56
+ return chunk64U3UDTH_cjs.handleError(error, "Error getting threads");
56
57
  }
57
58
  }
58
59
  async function getThreadByIdHandler({
@@ -61,18 +62,18 @@ async function getThreadByIdHandler({
61
62
  threadId
62
63
  }) {
63
64
  try {
64
- chunkQN4KF3BH_cjs.validateBody({ threadId });
65
+ chunk57CJTIPW_cjs.validateBody({ threadId });
65
66
  const memory = getMemoryFromContext({ mastra, agentId });
66
67
  if (!memory) {
67
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
68
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
68
69
  }
69
70
  const thread = await memory.getThreadById({ threadId });
70
71
  if (!thread) {
71
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Thread not found" });
72
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
72
73
  }
73
74
  return thread;
74
75
  } catch (error) {
75
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting thread");
76
+ return chunk64U3UDTH_cjs.handleError(error, "Error getting thread");
76
77
  }
77
78
  }
78
79
  async function saveMessagesHandler({
@@ -83,13 +84,13 @@ async function saveMessagesHandler({
83
84
  try {
84
85
  const memory = getMemoryFromContext({ mastra, agentId });
85
86
  if (!memory) {
86
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
87
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
87
88
  }
88
89
  if (!body?.messages) {
89
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Messages are required" });
90
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Messages are required" });
90
91
  }
91
92
  if (!Array.isArray(body.messages)) {
92
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Messages should be an array" });
93
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Messages should be an array" });
93
94
  }
94
95
  const processedMessages = body.messages.map((message) => ({
95
96
  ...message,
@@ -99,7 +100,7 @@ async function saveMessagesHandler({
99
100
  const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });
100
101
  return result;
101
102
  } catch (error) {
102
- return chunkZLBRQFDD_cjs.handleError(error, "Error saving messages");
103
+ return chunk64U3UDTH_cjs.handleError(error, "Error saving messages");
103
104
  }
104
105
  }
105
106
  async function createThreadHandler({
@@ -110,9 +111,9 @@ async function createThreadHandler({
110
111
  try {
111
112
  const memory = getMemoryFromContext({ mastra, agentId });
112
113
  if (!memory) {
113
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
114
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
114
115
  }
115
- chunkQN4KF3BH_cjs.validateBody({ resourceId: body?.resourceId });
116
+ chunk57CJTIPW_cjs.validateBody({ resourceId: body?.resourceId });
116
117
  const result = await memory.createThread({
117
118
  resourceId: body?.resourceId,
118
119
  title: body?.title,
@@ -121,7 +122,7 @@ async function createThreadHandler({
121
122
  });
122
123
  return result;
123
124
  } catch (error) {
124
- return chunkZLBRQFDD_cjs.handleError(error, "Error saving thread to memory");
125
+ return chunk64U3UDTH_cjs.handleError(error, "Error saving thread to memory");
125
126
  }
126
127
  }
127
128
  async function updateThreadHandler({
@@ -133,17 +134,17 @@ async function updateThreadHandler({
133
134
  try {
134
135
  const memory = getMemoryFromContext({ mastra, agentId });
135
136
  if (!body) {
136
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Body is required" });
137
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Body is required" });
137
138
  }
138
139
  const { title, metadata, resourceId } = body;
139
140
  const updatedAt = /* @__PURE__ */ new Date();
140
- chunkQN4KF3BH_cjs.validateBody({ threadId });
141
+ chunk57CJTIPW_cjs.validateBody({ threadId });
141
142
  if (!memory) {
142
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
143
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
143
144
  }
144
145
  const thread = await memory.getThreadById({ threadId });
145
146
  if (!thread) {
146
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Thread not found" });
147
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
147
148
  }
148
149
  const updatedThread = {
149
150
  ...thread,
@@ -156,7 +157,7 @@ async function updateThreadHandler({
156
157
  const result = await memory.saveThread({ thread: updatedThread });
157
158
  return result;
158
159
  } catch (error) {
159
- return chunkZLBRQFDD_cjs.handleError(error, "Error updating thread");
160
+ return chunk64U3UDTH_cjs.handleError(error, "Error updating thread");
160
161
  }
161
162
  }
162
163
  async function deleteThreadHandler({
@@ -165,40 +166,59 @@ async function deleteThreadHandler({
165
166
  threadId
166
167
  }) {
167
168
  try {
168
- chunkQN4KF3BH_cjs.validateBody({ threadId });
169
+ chunk57CJTIPW_cjs.validateBody({ threadId });
169
170
  const memory = getMemoryFromContext({ mastra, agentId });
170
171
  if (!memory) {
171
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
172
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
172
173
  }
173
174
  const thread = await memory.getThreadById({ threadId });
174
175
  if (!thread) {
175
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Thread not found" });
176
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
176
177
  }
177
178
  await memory.deleteThread(threadId);
178
179
  return { result: "Thread deleted" };
179
180
  } catch (error) {
180
- return chunkZLBRQFDD_cjs.handleError(error, "Error deleting thread");
181
+ return chunk64U3UDTH_cjs.handleError(error, "Error deleting thread");
181
182
  }
182
183
  }
183
184
  async function getMessagesHandler({
184
185
  mastra,
185
186
  agentId,
186
- threadId
187
+ threadId,
188
+ limit,
189
+ format
187
190
  }) {
191
+ if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
192
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Invalid limit: must be a positive integer" });
193
+ }
188
194
  try {
189
- chunkQN4KF3BH_cjs.validateBody({ threadId });
195
+ chunk57CJTIPW_cjs.validateBody({ threadId });
190
196
  const memory = getMemoryFromContext({ mastra, agentId });
191
197
  if (!memory) {
192
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
198
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
193
199
  }
194
200
  const thread = await memory.getThreadById({ threadId });
195
201
  if (!thread) {
196
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Thread not found" });
202
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
197
203
  }
198
- const result = await memory.query({ threadId });
199
- return result;
204
+ const result = await memory.query({
205
+ threadId,
206
+ ...limit && { selectBy: { last: limit } }
207
+ });
208
+ let useV4Format = false;
209
+ if (format === "aiv4") {
210
+ useV4Format = true;
211
+ } else if (format === "aiv5") {
212
+ useV4Format = false;
213
+ } else {
214
+ useV4Format = mastra.getAiSdkCompatMode() === "v4";
215
+ }
216
+ if (useV4Format) {
217
+ return { messages: result.messages, uiMessages: result.uiMessagesV4 };
218
+ }
219
+ return { messages: result.messages, uiMessages: result.uiMessages };
200
220
  } catch (error) {
201
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting messages");
221
+ return chunk64U3UDTH_cjs.handleError(error, "Error getting messages");
202
222
  }
203
223
  }
204
224
 
@@ -1,14 +1,15 @@
1
1
  'use strict';
2
2
 
3
- var chunk5SWCVTNL_cjs = require('./chunk-5SWCVTNL.cjs');
4
- var chunkQN4KF3BH_cjs = require('./chunk-QN4KF3BH.cjs');
5
- var chunkZLBRQFDD_cjs = require('./chunk-ZLBRQFDD.cjs');
6
- var chunkFV45V6WC_cjs = require('./chunk-FV45V6WC.cjs');
3
+ var chunkASKESBJW_cjs = require('./chunk-ASKESBJW.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');
7
+ var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
7
8
  var tools = require('@mastra/core/tools');
8
9
 
9
10
  // src/server/handlers/tools.ts
10
11
  var tools_exports = {};
11
- chunkFV45V6WC_cjs.__export(tools_exports, {
12
+ chunk75ZPJI57_cjs.__export(tools_exports, {
12
13
  executeAgentToolHandler: () => executeAgentToolHandler,
13
14
  executeToolHandler: () => executeToolHandler,
14
15
  getToolByIdHandler: () => getToolByIdHandler,
@@ -24,8 +25,8 @@ async function getToolsHandler({ tools }) {
24
25
  const tool = _tool;
25
26
  acc[id] = {
26
27
  ...tool,
27
- inputSchema: tool.inputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(tool.inputSchema)) : void 0,
28
- outputSchema: tool.outputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(tool.outputSchema)) : void 0
28
+ inputSchema: tool.inputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(tool.inputSchema)) : void 0,
29
+ outputSchema: tool.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(tool.outputSchema)) : void 0
29
30
  };
30
31
  return acc;
31
32
  },
@@ -33,23 +34,23 @@ async function getToolsHandler({ tools }) {
33
34
  );
34
35
  return serializedTools;
35
36
  } catch (error) {
36
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting tools");
37
+ return chunk64U3UDTH_cjs.handleError(error, "Error getting tools");
37
38
  }
38
39
  }
39
40
  async function getToolByIdHandler({ tools, toolId }) {
40
41
  try {
41
42
  const tool = Object.values(tools || {}).find((tool2) => tool2.id === toolId);
42
43
  if (!tool) {
43
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Tool not found" });
44
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Tool not found" });
44
45
  }
45
46
  const serializedTool = {
46
47
  ...tool,
47
- inputSchema: tool.inputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(tool.inputSchema)) : void 0,
48
- outputSchema: tool.outputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(tool.outputSchema)) : void 0
48
+ inputSchema: tool.inputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(tool.inputSchema)) : void 0,
49
+ outputSchema: tool.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(tool.outputSchema)) : void 0
49
50
  };
50
51
  return serializedTool;
51
52
  } catch (error) {
52
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting tool");
53
+ return chunk64U3UDTH_cjs.handleError(error, "Error getting tool");
53
54
  }
54
55
  }
55
56
  function executeToolHandler(tools$1) {
@@ -62,16 +63,16 @@ function executeToolHandler(tools$1) {
62
63
  }) => {
63
64
  try {
64
65
  if (!toolId) {
65
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Tool ID is required" });
66
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Tool ID is required" });
66
67
  }
67
68
  const tool = Object.values(tools$1 || {}).find((tool2) => tool2.id === toolId);
68
69
  if (!tool) {
69
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Tool not found" });
70
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Tool not found" });
70
71
  }
71
72
  if (!tool?.execute) {
72
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Tool is not executable" });
73
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Tool is not executable" });
73
74
  }
74
- chunkQN4KF3BH_cjs.validateBody({ data });
75
+ chunk57CJTIPW_cjs.validateBody({ data });
75
76
  if (tools.isVercelTool(tool)) {
76
77
  const result2 = await tool.execute(data);
77
78
  return result2;
@@ -84,7 +85,7 @@ function executeToolHandler(tools$1) {
84
85
  });
85
86
  return result;
86
87
  } catch (error) {
87
- return chunkZLBRQFDD_cjs.handleError(error, "Error executing tool");
88
+ return chunk64U3UDTH_cjs.handleError(error, "Error executing tool");
88
89
  }
89
90
  };
90
91
  }
@@ -98,14 +99,15 @@ async function executeAgentToolHandler({
98
99
  try {
99
100
  const agent = agentId ? mastra.getAgent(agentId) : null;
100
101
  if (!agent) {
101
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Tool not found" });
102
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Tool not found" });
102
103
  }
103
- const tool = Object.values(agent?.tools || {}).find((tool2) => tool2.id === toolId);
104
+ const agentTools = await agent.getTools({ runtimeContext });
105
+ const tool = Object.values(agentTools || {}).find((tool2) => tool2.id === toolId);
104
106
  if (!tool) {
105
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Tool not found" });
107
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Tool not found" });
106
108
  }
107
109
  if (!tool?.execute) {
108
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Tool is not executable" });
110
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Tool is not executable" });
109
111
  }
110
112
  const result = await tool.execute({
111
113
  context: data,
@@ -115,7 +117,7 @@ async function executeAgentToolHandler({
115
117
  });
116
118
  return result;
117
119
  } catch (error) {
118
- return chunkZLBRQFDD_cjs.handleError(error, "Error executing tool");
120
+ return chunk64U3UDTH_cjs.handleError(error, "Error executing tool");
119
121
  }
120
122
  }
121
123
 
@@ -1,9 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
1
  // src/server/http-exception.ts
8
2
  var HTTPException = class extends Error {
9
3
  res;
@@ -37,4 +31,4 @@ var HTTPException = class extends Error {
37
31
  }
38
32
  };
39
33
 
40
- export { HTTPException, __export };
34
+ export { HTTPException };
@@ -1,11 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var __defProp = Object.defineProperty;
4
- var __export = (target, all) => {
5
- for (var name in all)
6
- __defProp(target, name, { get: all[name], enumerable: true });
7
- };
8
-
9
3
  // src/server/http-exception.ts
10
4
  var HTTPException = class extends Error {
11
5
  res;
@@ -40,4 +34,3 @@ var HTTPException = class extends Error {
40
34
  };
41
35
 
42
36
  exports.HTTPException = HTTPException;
43
- exports.__export = __export;