@mastra/server 0.0.0-fix-message-embedding-20250506021742 → 0.0.0-fix-generate-title-20250616171351

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 (85) hide show
  1. package/README.md +48 -135
  2. package/dist/_tsup-dts-rollup.d.cts +296 -100
  3. package/dist/_tsup-dts-rollup.d.ts +296 -100
  4. package/dist/{chunk-5JNVY6DU.js → chunk-2HXKRRNS.js} +7 -5
  5. package/dist/{chunk-Y3SV5XK4.js → chunk-4O23XCE5.js} +94 -13
  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-2FJURXCL.cjs → chunk-6TJSHFCJ.cjs} +44 -36
  10. package/dist/chunk-75ZPJI57.cjs +9 -0
  11. package/dist/chunk-ASKESBJW.cjs +2004 -0
  12. package/dist/{chunk-AMVOS7YB.cjs → chunk-B4MQFJ7G.cjs} +12 -8
  13. package/dist/{chunk-BPL2CBLV.js → chunk-BFOA2QQY.js} +8 -4
  14. package/dist/{chunk-M56ECCHK.cjs → chunk-BNEY4P4P.cjs} +20 -19
  15. package/dist/{chunk-QJ3AHN64.js → chunk-C7564HUT.js} +4 -3
  16. package/dist/chunk-C75ZRJKD.cjs +270 -0
  17. package/dist/{chunk-3XTEV33Q.js → chunk-CLYX4KLH.js} +54 -51
  18. package/dist/{chunk-55HTWX4C.cjs → chunk-CMMOIUFC.cjs} +40 -19
  19. package/dist/{chunk-Q6SHQECN.js → chunk-CP55EVBK.js} +24 -4
  20. package/dist/chunk-FRXZL32L.cjs +471 -0
  21. package/dist/chunk-GHC4YV6R.js +504 -0
  22. package/dist/{chunk-L7XE5QTW.js → chunk-H5PTF3Y4.js} +1 -1
  23. package/dist/{chunk-RBQASTUP.js → chunk-I7KJZNX5.js} +14 -6
  24. package/dist/chunk-IMBY5XUG.cjs +86 -0
  25. package/dist/{chunk-IQTNZSFP.js → chunk-JKTNRUKY.js} +194 -49
  26. package/dist/{chunk-3AHQ5RGN.js → chunk-M5ABIP7D.js} +1 -1
  27. package/dist/chunk-MLKGABMK.js +7 -0
  28. package/dist/{chunk-D3G23FP3.cjs → chunk-NGURCFEJ.cjs} +24 -22
  29. package/dist/{chunk-TRDNDNGQ.js → chunk-NYN7KFXL.js} +1 -7
  30. package/dist/{chunk-FV45V6WC.cjs → chunk-OCWPVYNI.cjs} +0 -7
  31. package/dist/chunk-QLG2PFHE.js +81 -0
  32. package/dist/chunk-SDPGVWQJ.cjs +512 -0
  33. package/dist/chunk-TGJMNUYJ.js +2001 -0
  34. package/dist/{chunk-5YGDYMRB.cjs → chunk-VPNDC2DI.cjs} +14 -13
  35. package/dist/chunk-WE32JG64.cjs +332 -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-5SWCVTNL.cjs +0 -5579
  78. package/dist/chunk-CHFORQ7J.cjs +0 -329
  79. package/dist/chunk-FOXHTOQZ.cjs +0 -324
  80. package/dist/chunk-OMN3UI6X.js +0 -5576
  81. package/dist/chunk-SKBVVI24.cjs +0 -54
  82. package/dist/server/handlers/vNextWorkflows.cjs +0 -46
  83. package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
  84. package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
  85. package/dist/server/handlers/vNextWorkflows.js +0 -1
@@ -1,7 +1,9 @@
1
- import { stringify, esm_default } from './chunk-OMN3UI6X.js';
2
- import { validateBody } from './chunk-L7XE5QTW.js';
3
- import { handleError } from './chunk-3AHQ5RGN.js';
4
- import { __export, HTTPException } from './chunk-TRDNDNGQ.js';
1
+ import { stringify, esm_default } from './chunk-TGJMNUYJ.js';
2
+ import { validateBody } from './chunk-H5PTF3Y4.js';
3
+ import { handleError } from './chunk-M5ABIP7D.js';
4
+ import { HTTPException } from './chunk-NYN7KFXL.js';
5
+ import { __export } from './chunk-MLKGABMK.js';
6
+ import { RuntimeContext } from '@mastra/core/runtime-context';
5
7
 
6
8
  // src/server/handlers/agents.ts
7
9
  var agents_exports = {};
@@ -30,13 +32,33 @@ async function getAgentsHandler({ mastra, runtimeContext }) {
30
32
  };
31
33
  return acc;
32
34
  }, {});
35
+ let serializedAgentWorkflows = {};
36
+ if ("getWorkflows" in agent) {
37
+ const logger = mastra.getLogger();
38
+ try {
39
+ const workflows = await agent.getWorkflows({ runtimeContext });
40
+ serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
41
+ return {
42
+ ...acc,
43
+ [key]: {
44
+ name: workflow.name
45
+ }
46
+ };
47
+ }, {});
48
+ } catch (error) {
49
+ logger.error("Error getting workflows for agent", { agentName: agent.name, error });
50
+ }
51
+ }
33
52
  return {
34
53
  id,
35
54
  name: agent.name,
36
55
  instructions,
37
56
  tools: serializedAgentTools,
57
+ workflows: serializedAgentWorkflows,
38
58
  provider: llm?.getProvider(),
39
- modelId: llm?.getModelId()
59
+ modelId: llm?.getModelId(),
60
+ defaultGenerateOptions: agent.getDefaultGenerateOptions(),
61
+ defaultStreamOptions: agent.getDefaultStreamOptions()
40
62
  };
41
63
  })
42
64
  );
@@ -52,7 +74,8 @@ async function getAgentsHandler({ mastra, runtimeContext }) {
52
74
  async function getAgentByIdHandler({
53
75
  mastra,
54
76
  runtimeContext,
55
- agentId
77
+ agentId,
78
+ isPlayground = false
56
79
  }) {
57
80
  try {
58
81
  const agent = mastra.getAgent(agentId);
@@ -69,14 +92,57 @@ async function getAgentByIdHandler({
69
92
  };
70
93
  return acc;
71
94
  }, {});
72
- const instructions = await agent.getInstructions({ runtimeContext });
95
+ let serializedAgentWorkflows = {};
96
+ if ("getWorkflows" in agent) {
97
+ const logger = mastra.getLogger();
98
+ try {
99
+ const workflows = await agent.getWorkflows({ runtimeContext });
100
+ serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
101
+ return {
102
+ ...acc,
103
+ [key]: {
104
+ name: workflow.name,
105
+ steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
106
+ return {
107
+ ...acc2,
108
+ [key2]: {
109
+ id: step.id,
110
+ description: step.description
111
+ }
112
+ };
113
+ }, {})
114
+ }
115
+ };
116
+ }, {});
117
+ } catch (error) {
118
+ logger.error("Error getting workflows for agent", { agentName: agent.name, error });
119
+ }
120
+ }
121
+ let proxyRuntimeContext = runtimeContext;
122
+ if (isPlayground) {
123
+ proxyRuntimeContext = new Proxy(runtimeContext, {
124
+ get(target, prop) {
125
+ if (prop === "get") {
126
+ return function(key) {
127
+ const value = target.get(key);
128
+ return value ?? `<${key}>`;
129
+ };
130
+ }
131
+ return Reflect.get(target, prop);
132
+ }
133
+ });
134
+ }
135
+ const instructions = await agent.getInstructions({ runtimeContext: proxyRuntimeContext });
73
136
  const llm = await agent.getLLM({ runtimeContext });
74
137
  return {
75
138
  name: agent.name,
76
139
  instructions,
77
140
  tools: serializedAgentTools,
141
+ workflows: serializedAgentWorkflows,
78
142
  provider: llm?.getProvider(),
79
- modelId: llm?.getModelId()
143
+ modelId: llm?.getModelId(),
144
+ defaultGenerateOptions: agent.getDefaultGenerateOptions(),
145
+ defaultStreamOptions: agent.getDefaultStreamOptions()
80
146
  };
81
147
  } catch (error) {
82
148
  return handleError(error, "Error getting agent");
@@ -131,14 +197,18 @@ async function generateHandler({
131
197
  if (!agent) {
132
198
  throw new HTTPException(404, { message: "Agent not found" });
133
199
  }
134
- const { messages, resourceId, resourceid, ...rest } = body;
200
+ const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
135
201
  const finalResourceId = resourceId ?? resourceid;
202
+ const finalRuntimeContext = new RuntimeContext([
203
+ ...Array.from(runtimeContext.entries()),
204
+ ...Array.from(Object.entries(agentRuntimeContext ?? {}))
205
+ ]);
136
206
  validateBody({ messages });
137
207
  const result = await agent.generate(messages, {
138
208
  ...rest,
139
209
  // @ts-expect-error TODO fix types
140
210
  resourceId: finalResourceId,
141
- runtimeContext
211
+ runtimeContext: finalRuntimeContext
142
212
  });
143
213
  return result;
144
214
  } catch (error) {
@@ -156,20 +226,31 @@ async function streamGenerateHandler({
156
226
  if (!agent) {
157
227
  throw new HTTPException(404, { message: "Agent not found" });
158
228
  }
159
- const { messages, resourceId, resourceid, ...rest } = body;
229
+ const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
160
230
  const finalResourceId = resourceId ?? resourceid;
231
+ const finalRuntimeContext = new RuntimeContext([
232
+ ...Array.from(runtimeContext.entries()),
233
+ ...Array.from(Object.entries(agentRuntimeContext ?? {}))
234
+ ]);
161
235
  validateBody({ messages });
162
236
  const streamResult = await agent.stream(messages, {
163
237
  ...rest,
164
238
  // @ts-expect-error TODO fix types
165
239
  resourceId: finalResourceId,
166
- runtimeContext
240
+ runtimeContext: finalRuntimeContext
167
241
  });
168
- const streamResponse = rest.output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
242
+ const streamResponse = rest.output ? streamResult.toTextStreamResponse({
243
+ headers: {
244
+ "Transfer-Encoding": "chunked"
245
+ }
246
+ }) : streamResult.toDataStreamResponse({
169
247
  sendUsage: true,
170
248
  sendReasoning: true,
171
249
  getErrorMessage: (error) => {
172
250
  return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
251
+ },
252
+ headers: {
253
+ "Transfer-Encoding": "chunked"
173
254
  }
174
255
  });
175
256
  return streamResponse;
@@ -1,5 +1,6 @@
1
- import { handleError } from './chunk-3AHQ5RGN.js';
2
- import { __export, HTTPException } from './chunk-TRDNDNGQ.js';
1
+ import { handleError } from './chunk-M5ABIP7D.js';
2
+ import { HTTPException } from './chunk-NYN7KFXL.js';
3
+ import { __export } from './chunk-MLKGABMK.js';
3
4
 
4
5
  // src/server/handlers/vector.ts
5
6
  var vector_exports = {};
@@ -90,7 +91,7 @@ async function describeIndex({
90
91
  throw new HTTPException(400, { message: "Index name is required" });
91
92
  }
92
93
  const vector = getVector(mastra, vectorName);
93
- const stats = await vector.describeIndex(indexName);
94
+ const stats = await vector.describeIndex({ indexName });
94
95
  return {
95
96
  dimension: stats.dimension,
96
97
  count: stats.count,
@@ -110,7 +111,7 @@ async function deleteIndex({
110
111
  throw new HTTPException(400, { message: "Index name is required" });
111
112
  }
112
113
  const vector = getVector(mastra, vectorName);
113
- await vector.deleteIndex(indexName);
114
+ await vector.deleteIndex({ indexName });
114
115
  return { success: true };
115
116
  } catch (error) {
116
117
  return handleError(error, "Error deleting index");
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkFV45V6WC_cjs = require('./chunk-FV45V6WC.cjs');
3
+ var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
4
4
 
5
5
  // src/server/handlers/utils.ts
6
6
  function validateBody(body) {
@@ -11,7 +11,7 @@ function validateBody(body) {
11
11
  return acc;
12
12
  }, {});
13
13
  if (Object.keys(errorResponse).length > 0) {
14
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: Object.values(errorResponse)[0] });
14
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: Object.values(errorResponse)[0] });
15
15
  }
16
16
  }
17
17
 
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var chunkFV45V6WC_cjs = require('./chunk-FV45V6WC.cjs');
3
+ var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
4
4
 
5
5
  // src/server/handlers/error.ts
6
6
  function handleError(error, defaultMessage) {
7
7
  const apiError = error;
8
- throw new chunkFV45V6WC_cjs.HTTPException(apiError.status || 500, {
8
+ throw new chunkOCWPVYNI_cjs.HTTPException(apiError.status || 500, {
9
9
  message: apiError.message || defaultMessage
10
10
  });
11
11
  }
@@ -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,47 @@ 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
187
189
  }) {
190
+ if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
191
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Invalid limit: must be a positive integer" });
192
+ }
188
193
  try {
189
- chunkQN4KF3BH_cjs.validateBody({ threadId });
194
+ chunk57CJTIPW_cjs.validateBody({ threadId });
190
195
  const memory = getMemoryFromContext({ mastra, agentId });
191
196
  if (!memory) {
192
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
197
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
193
198
  }
194
199
  const thread = await memory.getThreadById({ threadId });
195
200
  if (!thread) {
196
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Thread not found" });
201
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
197
202
  }
198
- const result = await memory.query({ threadId });
199
- return result;
203
+ const result = await memory.query({
204
+ threadId,
205
+ ...limit && { selectBy: { last: limit } }
206
+ });
207
+ return { messages: result.messages, uiMessages: result.uiMessages };
200
208
  } catch (error) {
201
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting messages");
209
+ return chunk64U3UDTH_cjs.handleError(error, "Error getting messages");
202
210
  }
203
211
  }
204
212
 
@@ -0,0 +1,9 @@
1
+ 'use strict';
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
+ exports.__export = __export;