@mastra/server 0.0.0-playground-studio-cloud-20251031080052 → 0.0.0-playground-studio-again-20251114100107

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 (149) hide show
  1. package/CHANGELOG.md +685 -3
  2. package/README.md +1 -1
  3. package/dist/{chunk-7HCPO76Z.js → chunk-2IS5WICF.js} +4505 -1017
  4. package/dist/chunk-2IS5WICF.js.map +1 -0
  5. package/dist/{chunk-SPRRK3P7.cjs → chunk-2YZH5PH6.cjs} +47 -47
  6. package/dist/chunk-2YZH5PH6.cjs.map +1 -0
  7. package/dist/{chunk-BATEJLED.js → chunk-3AMNUUZF.js} +20 -20
  8. package/dist/chunk-3AMNUUZF.js.map +1 -0
  9. package/dist/{chunk-AW5BU3RQ.js → chunk-3F52QCI4.js} +40 -40
  10. package/dist/chunk-3F52QCI4.js.map +1 -0
  11. package/dist/{chunk-7NADHFD2.cjs → chunk-64ITUOXI.cjs} +2 -2
  12. package/dist/chunk-64ITUOXI.cjs.map +1 -0
  13. package/dist/{chunk-MMROOK5J.js → chunk-6QWQZI4Q.js} +2 -2
  14. package/dist/{chunk-7NADHFD2.cjs.map → chunk-6QWQZI4Q.js.map} +1 -1
  15. package/dist/{chunk-ABRFV4XP.js → chunk-73PAWDM5.js} +13 -13
  16. package/dist/chunk-73PAWDM5.js.map +1 -0
  17. package/dist/{chunk-2S4IMB6E.cjs → chunk-A24TSVEZ.cjs} +39 -39
  18. package/dist/chunk-A24TSVEZ.cjs.map +1 -0
  19. package/dist/{chunk-QQXMIP6C.js → chunk-B3Z6J745.js} +17 -17
  20. package/dist/chunk-B3Z6J745.js.map +1 -0
  21. package/dist/{chunk-G4PUALCE.cjs → chunk-BTWIR2B7.cjs} +4 -4
  22. package/dist/{chunk-G4PUALCE.cjs.map → chunk-BTWIR2B7.cjs.map} +1 -1
  23. package/dist/{chunk-KSFLUEWV.js → chunk-D7T74TVR.js} +4 -5
  24. package/dist/chunk-D7T74TVR.js.map +1 -0
  25. package/dist/{chunk-YSHNCC6F.cjs → chunk-EHACNWDL.cjs} +169 -201
  26. package/dist/chunk-EHACNWDL.cjs.map +1 -0
  27. package/dist/{chunk-MN2TZQ7I.js → chunk-FPBYKMIS.js} +13 -13
  28. package/dist/chunk-FPBYKMIS.js.map +1 -0
  29. package/dist/{chunk-3SNGNFUJ.cjs → chunk-GLAZTMX3.cjs} +37 -37
  30. package/dist/chunk-GLAZTMX3.cjs.map +1 -0
  31. package/dist/{chunk-KDUHLUK4.cjs → chunk-ID6JYDNL.cjs} +4387 -896
  32. package/dist/chunk-ID6JYDNL.cjs.map +1 -0
  33. package/dist/{chunk-TRGAMKHX.cjs → chunk-KF3RI45U.cjs} +46 -41
  34. package/dist/chunk-KF3RI45U.cjs.map +1 -0
  35. package/dist/{chunk-K5T5A3AL.cjs → chunk-KJIDZQRA.cjs} +14 -14
  36. package/dist/chunk-KJIDZQRA.cjs.map +1 -0
  37. package/dist/{chunk-MYR4PVGN.js → chunk-KWH5QBXP.js} +4 -4
  38. package/dist/{chunk-MYR4PVGN.js.map → chunk-KWH5QBXP.js.map} +1 -1
  39. package/dist/{chunk-AHB4JCIQ.js → chunk-ND5OKOMT.js} +31 -26
  40. package/dist/chunk-ND5OKOMT.js.map +1 -0
  41. package/dist/{chunk-XN74I6VW.cjs → chunk-PPMIB3FQ.cjs} +20 -20
  42. package/dist/chunk-PPMIB3FQ.cjs.map +1 -0
  43. package/dist/{chunk-EP3JQDPD.cjs → chunk-S54HNARD.cjs} +18 -18
  44. package/dist/{chunk-EP3JQDPD.cjs.map → chunk-S54HNARD.cjs.map} +1 -1
  45. package/dist/{chunk-4QCXUEAT.js → chunk-SZIFSF4T.js} +3 -3
  46. package/dist/{chunk-4QCXUEAT.js.map → chunk-SZIFSF4T.js.map} +1 -1
  47. package/dist/{chunk-Y7SH5ZKM.cjs → chunk-U7GLIXYO.cjs} +157 -172
  48. package/dist/chunk-U7GLIXYO.cjs.map +1 -0
  49. package/dist/{chunk-CY4TP3FK.js → chunk-UXGQZUYZ.js} +3 -3
  50. package/dist/{chunk-CY4TP3FK.js.map → chunk-UXGQZUYZ.js.map} +1 -1
  51. package/dist/{chunk-RE4RPXT2.cjs → chunk-V5WWQN7P.cjs} +4 -4
  52. package/dist/{chunk-RE4RPXT2.cjs.map → chunk-V5WWQN7P.cjs.map} +1 -1
  53. package/dist/{chunk-OGK26QPW.js → chunk-V6JYJS7O.js} +109 -123
  54. package/dist/chunk-V6JYJS7O.js.map +1 -0
  55. package/dist/{chunk-CJFKRVED.cjs → chunk-W2KMU354.cjs} +4 -5
  56. package/dist/chunk-W2KMU354.cjs.map +1 -0
  57. package/dist/{chunk-B7QWVGQQ.cjs → chunk-X3MICMI2.cjs} +140 -249
  58. package/dist/chunk-X3MICMI2.cjs.map +1 -0
  59. package/dist/{chunk-6VPAV4ZV.js → chunk-Z2O5YVHY.js} +134 -165
  60. package/dist/chunk-Z2O5YVHY.js.map +1 -0
  61. package/dist/{chunk-ZLBL4NQC.js → chunk-ZJ6KEY6H.js} +67 -174
  62. package/dist/chunk-ZJ6KEY6H.js.map +1 -0
  63. package/dist/server/handlers/a2a.cjs +7 -7
  64. package/dist/server/handlers/a2a.d.ts +10 -10
  65. package/dist/server/handlers/a2a.d.ts.map +1 -1
  66. package/dist/server/handlers/a2a.js +1 -1
  67. package/dist/server/handlers/agent-builder.cjs +31 -19
  68. package/dist/server/handlers/agent-builder.d.ts +38 -47
  69. package/dist/server/handlers/agent-builder.d.ts.map +1 -1
  70. package/dist/server/handlers/agent-builder.js +1 -1
  71. package/dist/server/handlers/agents.cjs +25 -29
  72. package/dist/server/handlers/agents.d.ts +41 -55
  73. package/dist/server/handlers/agents.d.ts.map +1 -1
  74. package/dist/server/handlers/agents.js +1 -1
  75. package/dist/server/handlers/error.cjs +2 -2
  76. package/dist/server/handlers/error.js +1 -1
  77. package/dist/server/handlers/logs.cjs +7 -7
  78. package/dist/server/handlers/logs.d.ts +3 -3
  79. package/dist/server/handlers/logs.d.ts.map +1 -1
  80. package/dist/server/handlers/logs.js +1 -1
  81. package/dist/server/handlers/memory.cjs +19 -23
  82. package/dist/server/handlers/memory.d.ts +30 -35
  83. package/dist/server/handlers/memory.d.ts.map +1 -1
  84. package/dist/server/handlers/memory.js +1 -1
  85. package/dist/server/handlers/observability.cjs +8 -8
  86. package/dist/server/handlers/observability.d.ts +12 -12
  87. package/dist/server/handlers/observability.d.ts.map +1 -1
  88. package/dist/server/handlers/observability.js +1 -1
  89. package/dist/server/handlers/scores.cjs +11 -11
  90. package/dist/server/handlers/scores.d.ts +24 -24
  91. package/dist/server/handlers/scores.d.ts.map +1 -1
  92. package/dist/server/handlers/scores.js +1 -1
  93. package/dist/server/handlers/tools.cjs +7 -7
  94. package/dist/server/handlers/tools.d.ts +8 -8
  95. package/dist/server/handlers/tools.d.ts.map +1 -1
  96. package/dist/server/handlers/tools.js +1 -1
  97. package/dist/server/handlers/utils.cjs +3 -3
  98. package/dist/server/handlers/utils.js +1 -1
  99. package/dist/server/handlers/vector.cjs +7 -7
  100. package/dist/server/handlers/vector.js +1 -1
  101. package/dist/server/handlers/voice.cjs +5 -5
  102. package/dist/server/handlers/voice.d.ts +6 -6
  103. package/dist/server/handlers/voice.js +1 -1
  104. package/dist/server/handlers/workflows.cjs +21 -29
  105. package/dist/server/handlers/workflows.d.ts +27 -36
  106. package/dist/server/handlers/workflows.d.ts.map +1 -1
  107. package/dist/server/handlers/workflows.js +1 -1
  108. package/dist/server/handlers.cjs +23 -28
  109. package/dist/server/handlers.d.ts +0 -1
  110. package/dist/server/handlers.d.ts.map +1 -1
  111. package/dist/server/handlers.js +11 -12
  112. package/dist/server/http-exception.d.ts +0 -5
  113. package/dist/server/http-exception.d.ts.map +1 -1
  114. package/dist/server/utils.d.ts +3 -2
  115. package/dist/server/utils.d.ts.map +1 -1
  116. package/package.json +13 -8
  117. package/dist/chunk-2S4IMB6E.cjs.map +0 -1
  118. package/dist/chunk-3SNGNFUJ.cjs.map +0 -1
  119. package/dist/chunk-6VPAV4ZV.js.map +0 -1
  120. package/dist/chunk-7HCPO76Z.js.map +0 -1
  121. package/dist/chunk-ABRFV4XP.js.map +0 -1
  122. package/dist/chunk-AHB4JCIQ.js.map +0 -1
  123. package/dist/chunk-AW5BU3RQ.js.map +0 -1
  124. package/dist/chunk-B7QWVGQQ.cjs.map +0 -1
  125. package/dist/chunk-BATEJLED.js.map +0 -1
  126. package/dist/chunk-CJFKRVED.cjs.map +0 -1
  127. package/dist/chunk-I3C4ODGV.cjs +0 -335
  128. package/dist/chunk-I3C4ODGV.cjs.map +0 -1
  129. package/dist/chunk-K5T5A3AL.cjs.map +0 -1
  130. package/dist/chunk-KDUHLUK4.cjs.map +0 -1
  131. package/dist/chunk-KSFLUEWV.js.map +0 -1
  132. package/dist/chunk-LLUOPR3J.js +0 -323
  133. package/dist/chunk-LLUOPR3J.js.map +0 -1
  134. package/dist/chunk-MMROOK5J.js.map +0 -1
  135. package/dist/chunk-MN2TZQ7I.js.map +0 -1
  136. package/dist/chunk-OGK26QPW.js.map +0 -1
  137. package/dist/chunk-QQXMIP6C.js.map +0 -1
  138. package/dist/chunk-SPRRK3P7.cjs.map +0 -1
  139. package/dist/chunk-TRGAMKHX.cjs.map +0 -1
  140. package/dist/chunk-XN74I6VW.cjs.map +0 -1
  141. package/dist/chunk-Y7SH5ZKM.cjs.map +0 -1
  142. package/dist/chunk-YSHNCC6F.cjs.map +0 -1
  143. package/dist/chunk-ZLBL4NQC.js.map +0 -1
  144. package/dist/server/handlers/legacyWorkflows.cjs +0 -48
  145. package/dist/server/handlers/legacyWorkflows.cjs.map +0 -1
  146. package/dist/server/handlers/legacyWorkflows.d.ts +0 -59
  147. package/dist/server/handlers/legacyWorkflows.d.ts.map +0 -1
  148. package/dist/server/handlers/legacyWorkflows.js +0 -3
  149. package/dist/server/handlers/legacyWorkflows.js.map +0 -1
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var chunkG4PUALCE_cjs = require('./chunk-G4PUALCE.cjs');
4
- var chunkRE4RPXT2_cjs = require('./chunk-RE4RPXT2.cjs');
5
- var chunk7NADHFD2_cjs = require('./chunk-7NADHFD2.cjs');
3
+ var chunkBTWIR2B7_cjs = require('./chunk-BTWIR2B7.cjs');
4
+ var chunkV5WWQN7P_cjs = require('./chunk-V5WWQN7P.cjs');
5
+ var chunk64ITUOXI_cjs = require('./chunk-64ITUOXI.cjs');
6
6
  var chunkO7I5CWRX_cjs = require('./chunk-O7I5CWRX.cjs');
7
- var agent = require('@mastra/core/agent');
7
+ var di = require('@mastra/core/di');
8
8
  var utils = require('@mastra/core/utils');
9
9
 
10
10
  // src/server/handlers/memory.ts
@@ -15,34 +15,43 @@ chunkO7I5CWRX_cjs.__export(memory_exports, {
15
15
  deleteThreadHandler: () => deleteThreadHandler,
16
16
  getMemoryConfigHandler: () => getMemoryConfigHandler,
17
17
  getMemoryStatusHandler: () => getMemoryStatusHandler,
18
- getMessagesHandler: () => getMessagesHandler,
19
- getMessagesPaginatedHandler: () => getMessagesPaginatedHandler,
18
+ getTextContent: () => getTextContent,
20
19
  getThreadByIdHandler: () => getThreadByIdHandler,
21
- getThreadsHandler: () => getThreadsHandler,
22
- getThreadsPaginatedHandler: () => getThreadsPaginatedHandler,
23
20
  getWorkingMemoryHandler: () => getWorkingMemoryHandler,
21
+ listMessagesHandler: () => listMessagesHandler,
22
+ listThreadsHandler: () => listThreadsHandler,
24
23
  saveMessagesHandler: () => saveMessagesHandler,
25
24
  searchMemoryHandler: () => searchMemoryHandler,
26
25
  updateThreadHandler: () => updateThreadHandler,
27
26
  updateWorkingMemoryHandler: () => updateWorkingMemoryHandler
28
27
  });
28
+ function getTextContent(message) {
29
+ if (typeof message.content === "string") {
30
+ return message.content;
31
+ }
32
+ if (message.content && typeof message.content === "object" && "parts" in message.content) {
33
+ const textPart = message.content.parts.find((p) => p.type === "text");
34
+ return textPart?.text || "";
35
+ }
36
+ return "";
37
+ }
29
38
  async function getMemoryFromContext({
30
39
  mastra,
31
40
  agentId,
32
- runtimeContext
41
+ requestContext
33
42
  }) {
34
43
  const logger = mastra.getLogger();
35
44
  let agent;
36
45
  if (agentId) {
37
46
  try {
38
- agent = mastra.getAgent(agentId);
47
+ agent = mastra.getAgentById(agentId);
39
48
  } catch (error) {
40
49
  logger.debug("Error getting agent from mastra, searching agents for agent", error);
41
50
  }
42
51
  }
43
52
  if (agentId && !agent) {
44
53
  logger.debug("Agent not found, searching agents for agent", { agentId });
45
- const agents = mastra.getAgents();
54
+ const agents = mastra.listAgents();
46
55
  if (Object.keys(agents || {}).length) {
47
56
  for (const [_, ag] of Object.entries(agents)) {
48
57
  try {
@@ -57,140 +66,113 @@ async function getMemoryFromContext({
57
66
  }
58
67
  }
59
68
  if (!agent) {
60
- throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Agent not found" });
69
+ throw new chunk64ITUOXI_cjs.HTTPException(404, { message: "Agent not found" });
61
70
  }
62
71
  }
63
72
  if (agent) {
64
73
  return await agent?.getMemory({
65
- runtimeContext
66
- }) || mastra.getMemory();
74
+ requestContext: requestContext ?? new di.RequestContext()
75
+ });
67
76
  }
68
- return mastra.getMemory();
69
77
  }
70
78
  async function getMemoryStatusHandler({
71
79
  mastra,
72
80
  agentId,
73
- runtimeContext
81
+ requestContext
74
82
  }) {
75
83
  try {
76
- const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
84
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
77
85
  if (!memory) {
78
86
  return { result: false };
79
87
  }
80
88
  return { result: true };
81
89
  } catch (error) {
82
- return chunkRE4RPXT2_cjs.handleError(error, "Error getting memory status");
90
+ return chunkV5WWQN7P_cjs.handleError(error, "Error getting memory status");
83
91
  }
84
92
  }
85
93
  async function getMemoryConfigHandler({
86
94
  mastra,
87
95
  agentId,
88
- runtimeContext
96
+ requestContext
89
97
  }) {
90
98
  try {
91
- const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
99
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
92
100
  if (!memory) {
93
- throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
101
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
94
102
  }
95
103
  const config = memory.getMergedThreadConfig({});
96
104
  return { config };
97
105
  } catch (error) {
98
- return chunkRE4RPXT2_cjs.handleError(error, "Error getting memory configuration");
99
- }
100
- }
101
- async function getThreadsHandler({
102
- mastra,
103
- agentId,
104
- resourceId,
105
- runtimeContext,
106
- orderBy,
107
- sortDirection
108
- }) {
109
- try {
110
- const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
111
- if (!memory) {
112
- throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
113
- }
114
- chunkG4PUALCE_cjs.validateBody({ resourceId });
115
- const threads = await memory.getThreadsByResourceId({
116
- resourceId,
117
- orderBy,
118
- sortDirection
119
- });
120
- return threads;
121
- } catch (error) {
122
- return chunkRE4RPXT2_cjs.handleError(error, "Error getting threads");
106
+ return chunkV5WWQN7P_cjs.handleError(error, "Error getting memory configuration");
123
107
  }
124
108
  }
125
- async function getThreadsPaginatedHandler({
109
+ async function listThreadsHandler({
126
110
  mastra,
127
111
  agentId,
128
112
  resourceId,
129
- runtimeContext,
113
+ requestContext,
130
114
  page,
131
115
  perPage,
132
- orderBy,
133
- sortDirection
116
+ orderBy
134
117
  }) {
135
118
  try {
136
- const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
119
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
137
120
  if (!memory) {
138
- throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
121
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
139
122
  }
140
- chunkG4PUALCE_cjs.validateBody({ resourceId });
141
- const result = await memory.getThreadsByResourceIdPaginated({
123
+ chunkBTWIR2B7_cjs.validateBody({ resourceId });
124
+ const result = await memory.listThreadsByResourceId({
142
125
  resourceId,
143
126
  page,
144
127
  perPage,
145
- orderBy,
146
- sortDirection
128
+ orderBy
147
129
  });
148
130
  return result;
149
131
  } catch (error) {
150
- return chunkRE4RPXT2_cjs.handleError(error, "Error getting paginated threads");
132
+ return chunkV5WWQN7P_cjs.handleError(error, "Error listing threads");
151
133
  }
152
134
  }
153
135
  async function getThreadByIdHandler({
154
136
  mastra,
155
137
  agentId,
156
138
  threadId,
157
- runtimeContext
139
+ requestContext
158
140
  }) {
159
141
  try {
160
- chunkG4PUALCE_cjs.validateBody({ threadId });
161
- const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
142
+ chunkBTWIR2B7_cjs.validateBody({ threadId });
143
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
162
144
  if (!memory) {
163
- throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
145
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
164
146
  }
165
147
  const thread = await memory.getThreadById({ threadId });
166
148
  if (!thread) {
167
- throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Thread not found" });
149
+ throw new chunk64ITUOXI_cjs.HTTPException(404, { message: "Thread not found" });
168
150
  }
169
151
  return thread;
170
152
  } catch (error) {
171
- return chunkRE4RPXT2_cjs.handleError(error, "Error getting thread");
153
+ return chunkV5WWQN7P_cjs.handleError(error, "Error getting thread");
172
154
  }
173
155
  }
174
156
  async function saveMessagesHandler({
175
157
  mastra,
176
158
  agentId,
177
159
  body,
178
- runtimeContext
160
+ requestContext
179
161
  }) {
180
162
  try {
181
- const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
163
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
182
164
  if (!memory) {
183
- throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
165
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
184
166
  }
185
167
  if (!body?.messages) {
186
- throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Messages are required" });
168
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Messages are required" });
187
169
  }
188
170
  if (!Array.isArray(body.messages)) {
189
- throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Messages should be an array" });
171
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Messages should be an array" });
190
172
  }
191
173
  const invalidMessages = body.messages.filter((message) => !message.threadId || !message.resourceId);
192
174
  if (invalidMessages.length > 0) {
193
- throw new chunk7NADHFD2_cjs.HTTPException(400, {
175
+ throw new chunk64ITUOXI_cjs.HTTPException(400, {
194
176
  message: `All messages must have threadId and resourceId fields. Found ${invalidMessages.length} invalid message(s).`
195
177
  });
196
178
  }
@@ -202,21 +184,21 @@ async function saveMessagesHandler({
202
184
  const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });
203
185
  return result;
204
186
  } catch (error) {
205
- return chunkRE4RPXT2_cjs.handleError(error, "Error saving messages");
187
+ return chunkV5WWQN7P_cjs.handleError(error, "Error saving messages");
206
188
  }
207
189
  }
208
190
  async function createThreadHandler({
209
191
  mastra,
210
192
  agentId,
211
193
  body,
212
- runtimeContext
194
+ requestContext
213
195
  }) {
214
196
  try {
215
- const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
197
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
216
198
  if (!memory) {
217
- throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
199
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
218
200
  }
219
- chunkG4PUALCE_cjs.validateBody({ resourceId: body?.resourceId });
201
+ chunkBTWIR2B7_cjs.validateBody({ resourceId: body?.resourceId });
220
202
  const result = await memory.createThread({
221
203
  resourceId: body?.resourceId,
222
204
  title: body?.title,
@@ -225,7 +207,7 @@ async function createThreadHandler({
225
207
  });
226
208
  return result;
227
209
  } catch (error) {
228
- return chunkRE4RPXT2_cjs.handleError(error, "Error saving thread to memory");
210
+ return chunkV5WWQN7P_cjs.handleError(error, "Error saving thread to memory");
229
211
  }
230
212
  }
231
213
  async function updateThreadHandler({
@@ -233,22 +215,22 @@ async function updateThreadHandler({
233
215
  agentId,
234
216
  threadId,
235
217
  body,
236
- runtimeContext
218
+ requestContext
237
219
  }) {
238
220
  try {
239
- const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
221
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
240
222
  if (!body) {
241
- throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Body is required" });
223
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Body is required" });
242
224
  }
243
225
  const { title, metadata, resourceId } = body;
244
226
  const updatedAt = /* @__PURE__ */ new Date();
245
- chunkG4PUALCE_cjs.validateBody({ threadId });
227
+ chunkBTWIR2B7_cjs.validateBody({ threadId });
246
228
  if (!memory) {
247
- throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
229
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
248
230
  }
249
231
  const thread = await memory.getThreadById({ threadId });
250
232
  if (!thread) {
251
- throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Thread not found" });
233
+ throw new chunk64ITUOXI_cjs.HTTPException(404, { message: "Thread not found" });
252
234
  }
253
235
  const updatedThread = {
254
236
  ...thread,
@@ -261,82 +243,68 @@ async function updateThreadHandler({
261
243
  const result = await memory.saveThread({ thread: updatedThread });
262
244
  return result;
263
245
  } catch (error) {
264
- return chunkRE4RPXT2_cjs.handleError(error, "Error updating thread");
246
+ return chunkV5WWQN7P_cjs.handleError(error, "Error updating thread");
265
247
  }
266
248
  }
267
249
  async function deleteThreadHandler({
268
250
  mastra,
269
251
  agentId,
270
252
  threadId,
271
- runtimeContext
253
+ requestContext
272
254
  }) {
273
255
  try {
274
- chunkG4PUALCE_cjs.validateBody({ threadId });
275
- const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
256
+ chunkBTWIR2B7_cjs.validateBody({ threadId });
257
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
276
258
  if (!memory) {
277
- throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
259
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
278
260
  }
279
261
  const thread = await memory.getThreadById({ threadId });
280
262
  if (!thread) {
281
- throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Thread not found" });
263
+ throw new chunk64ITUOXI_cjs.HTTPException(404, { message: "Thread not found" });
282
264
  }
283
265
  await memory.deleteThread(threadId);
284
266
  return { result: "Thread deleted" };
285
267
  } catch (error) {
286
- return chunkRE4RPXT2_cjs.handleError(error, "Error deleting thread");
268
+ return chunkV5WWQN7P_cjs.handleError(error, "Error deleting thread");
287
269
  }
288
270
  }
289
- async function getMessagesPaginatedHandler({
290
- mastra,
291
- threadId,
292
- resourceId,
293
- selectBy,
294
- format
295
- }) {
296
- try {
297
- chunkG4PUALCE_cjs.validateBody({ threadId });
298
- const storage = mastra.getStorage();
299
- if (!storage) {
300
- throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Storage is not initialized" });
301
- }
302
- const thread = await storage.getThreadById({ threadId });
303
- if (!thread) {
304
- throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Thread not found" });
305
- }
306
- const result = await storage.getMessagesPaginated({ threadId, resourceId, selectBy, format });
307
- return result;
308
- } catch (error) {
309
- return chunkRE4RPXT2_cjs.handleError(error, "Error getting messages");
310
- }
311
- }
312
- async function getMessagesHandler({
271
+ async function listMessagesHandler({
313
272
  mastra,
314
273
  agentId,
315
274
  threadId,
316
- limit,
317
- runtimeContext
275
+ resourceId,
276
+ perPage,
277
+ page,
278
+ orderBy,
279
+ include,
280
+ filter,
281
+ requestContext
318
282
  }) {
319
- if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
320
- throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Invalid limit: must be a positive integer" });
321
- }
322
283
  try {
323
- chunkG4PUALCE_cjs.validateBody({ threadId });
324
- const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
284
+ chunkBTWIR2B7_cjs.validateBody({ threadId });
285
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
325
286
  if (!memory) {
326
- throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
287
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
288
+ }
289
+ if (!threadId) {
290
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "No threadId found" });
327
291
  }
328
292
  const thread = await memory.getThreadById({ threadId });
329
293
  if (!thread) {
330
- throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Thread not found" });
294
+ throw new chunk64ITUOXI_cjs.HTTPException(404, { message: "Thread not found" });
331
295
  }
332
- const result = await memory.query({
296
+ const result = await memory.recall({
333
297
  threadId,
334
- ...limit && { selectBy: { last: limit } }
298
+ resourceId,
299
+ perPage,
300
+ page,
301
+ orderBy,
302
+ include,
303
+ filter
335
304
  });
336
- const uiMessages = agent.convertMessages(result.messagesV2).to("AIV5.UI");
337
- return { messages: result.messages, uiMessages, legacyMessages: result.uiMessages };
305
+ return result;
338
306
  } catch (error) {
339
- return chunkRE4RPXT2_cjs.handleError(error, "Error getting messages");
307
+ return chunkV5WWQN7P_cjs.handleError(error, "Error getting messages");
340
308
  }
341
309
  }
342
310
  async function getWorkingMemoryHandler({
@@ -344,14 +312,14 @@ async function getWorkingMemoryHandler({
344
312
  agentId,
345
313
  threadId,
346
314
  resourceId,
347
- runtimeContext,
315
+ requestContext,
348
316
  memoryConfig
349
317
  }) {
350
318
  try {
351
- const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
352
- chunkG4PUALCE_cjs.validateBody({ threadId });
319
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
320
+ chunkBTWIR2B7_cjs.validateBody({ threadId });
353
321
  if (!memory) {
354
- throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
322
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
355
323
  }
356
324
  const thread = await memory.getThreadById({ threadId });
357
325
  const threadExists = !!thread;
@@ -362,7 +330,7 @@ async function getWorkingMemoryHandler({
362
330
  const source = config.workingMemory?.scope !== "thread" && resourceId ? "resource" : "thread";
363
331
  return { workingMemory, source, workingMemoryTemplate, threadExists };
364
332
  } catch (error) {
365
- return chunkRE4RPXT2_cjs.handleError(error, "Error getting working memory");
333
+ return chunkV5WWQN7P_cjs.handleError(error, "Error getting working memory");
366
334
  }
367
335
  }
368
336
  async function updateWorkingMemoryHandler({
@@ -370,47 +338,52 @@ async function updateWorkingMemoryHandler({
370
338
  agentId,
371
339
  threadId,
372
340
  body,
373
- runtimeContext
341
+ requestContext
374
342
  }) {
375
343
  try {
376
- chunkG4PUALCE_cjs.validateBody({ threadId });
377
- const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
344
+ chunkBTWIR2B7_cjs.validateBody({ threadId });
345
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
378
346
  const { resourceId, memoryConfig, workingMemory } = body;
379
347
  if (!memory) {
380
- throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
348
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
381
349
  }
382
350
  const thread = await memory.getThreadById({ threadId });
383
351
  if (!thread) {
384
- throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Thread not found" });
352
+ throw new chunk64ITUOXI_cjs.HTTPException(404, { message: "Thread not found" });
385
353
  }
386
354
  await memory.updateWorkingMemory({ threadId, resourceId, workingMemory, memoryConfig });
387
355
  return { success: true };
388
356
  } catch (error) {
389
- return chunkRE4RPXT2_cjs.handleError(error, "Error updating working memory");
357
+ return chunkV5WWQN7P_cjs.handleError(error, "Error updating working memory");
390
358
  }
391
359
  }
392
360
  async function deleteMessagesHandler({
393
361
  mastra,
394
362
  agentId,
395
363
  messageIds,
396
- runtimeContext
364
+ requestContext
397
365
  }) {
398
366
  try {
399
367
  if (messageIds === void 0 || messageIds === null) {
400
- throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "messageIds is required" });
368
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "messageIds is required" });
401
369
  }
402
- const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
370
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
403
371
  if (!memory) {
404
- throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
372
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
405
373
  }
406
- await memory.deleteMessages(messageIds);
407
- let count = 1;
374
+ let normalizedIds;
408
375
  if (Array.isArray(messageIds)) {
409
- count = messageIds.length;
410
- }
376
+ normalizedIds = messageIds;
377
+ } else if (typeof messageIds === "string") {
378
+ normalizedIds = [messageIds];
379
+ } else {
380
+ normalizedIds = [messageIds];
381
+ }
382
+ await memory.deleteMessages(normalizedIds);
383
+ const count = Array.isArray(messageIds) ? messageIds.length : 1;
411
384
  return { success: true, message: `${count} message${count === 1 ? "" : "s"} deleted successfully` };
412
385
  } catch (error) {
413
- return chunkRE4RPXT2_cjs.handleError(error, "Error deleting messages");
386
+ return chunkV5WWQN7P_cjs.handleError(error, "Error deleting messages");
414
387
  }
415
388
  }
416
389
  async function searchMemoryHandler({
@@ -420,14 +393,14 @@ async function searchMemoryHandler({
420
393
  resourceId,
421
394
  threadId,
422
395
  limit = 20,
423
- runtimeContext,
396
+ requestContext,
424
397
  memoryConfig
425
398
  }) {
426
399
  try {
427
- chunkG4PUALCE_cjs.validateBody({ searchQuery, resourceId });
428
- const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
400
+ chunkBTWIR2B7_cjs.validateBody({ searchQuery, resourceId });
401
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
429
402
  if (!memory) {
430
- throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
403
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
431
404
  }
432
405
  const config = memory.getMergedThreadConfig(memoryConfig || {});
433
406
  const hasSemanticRecall = !!config?.semanticRecall;
@@ -435,10 +408,10 @@ async function searchMemoryHandler({
435
408
  if (threadId && !resourceScope) {
436
409
  const thread = await memory.getThreadById({ threadId });
437
410
  if (!thread) {
438
- throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Thread not found" });
411
+ throw new chunk64ITUOXI_cjs.HTTPException(404, { message: "Thread not found" });
439
412
  }
440
413
  if (thread.resourceId !== resourceId) {
441
- throw new chunk7NADHFD2_cjs.HTTPException(403, { message: "Thread does not belong to the specified resource" });
414
+ throw new chunk64ITUOXI_cjs.HTTPException(403, { message: "Thread does not belong to the specified resource" });
442
415
  }
443
416
  }
444
417
  const searchResults = [];
@@ -455,8 +428,13 @@ async function searchMemoryHandler({
455
428
  }
456
429
  }
457
430
  if (!threadId) {
458
- const threads2 = await memory.getThreadsByResourceId({ resourceId });
459
- if (threads2.length === 0) {
431
+ const { threads } = await memory.listThreadsByResourceId({
432
+ resourceId,
433
+ page: 0,
434
+ perPage: 1,
435
+ orderBy: { field: "updatedAt", direction: "DESC" }
436
+ });
437
+ if (threads.length === 0) {
460
438
  return {
461
439
  results: [],
462
440
  count: 0,
@@ -465,7 +443,7 @@ async function searchMemoryHandler({
465
443
  searchType: hasSemanticRecall ? "semantic" : "text"
466
444
  };
467
445
  }
468
- threadId = threads2[0].id;
446
+ threadId = threads[0].id;
469
447
  }
470
448
  const beforeRange = typeof config.semanticRecall === `boolean` ? 2 : typeof config.semanticRecall?.messageRange === `number` ? config.semanticRecall.messageRange : config.semanticRecall?.messageRange.before || 2;
471
449
  const afterRange = typeof config.semanticRecall === `boolean` ? 2 : typeof config.semanticRecall?.messageRange === `number` ? config.semanticRecall.messageRange : config.semanticRecall?.messageRange.after || 2;
@@ -476,19 +454,27 @@ async function searchMemoryHandler({
476
454
  { messageRange: 0, topK: 2, scope: "resource" }
477
455
  ) : { ...config.semanticRecall, messageRange: 0 };
478
456
  }
479
- const result = await memory.rememberMessages({
457
+ const threadConfig = memory.getMergedThreadConfig(config || {});
458
+ if (!threadConfig.lastMessages && !threadConfig.semanticRecall) {
459
+ return { results: [], count: 0, query: searchQuery };
460
+ }
461
+ const result = await memory.recall({
480
462
  threadId,
481
463
  resourceId,
482
- vectorMessageSearch: searchQuery,
483
- config
464
+ perPage: threadConfig.lastMessages,
465
+ threadConfig: config,
466
+ vectorSearchString: threadConfig.semanticRecall && searchQuery ? searchQuery : void 0
484
467
  });
485
- const threads = await memory.getThreadsByResourceId({ resourceId });
486
- const threadMap = new Map(threads.map((t) => [t.id, t]));
487
- for (const msg of result.messagesV2) {
488
- const content = typeof msg.content.content === `string` ? msg.content.content : msg.content.parts?.map((p) => p.type === "text" ? p.text : "").join(" ") || "";
468
+ const threadIds = Array.from(
469
+ new Set(result.messages.map((m) => m.threadId || threadId).filter(Boolean))
470
+ );
471
+ const fetched = await Promise.all(threadIds.map((id) => memory.getThreadById({ threadId: id })));
472
+ const threadMap = new Map(fetched.filter(Boolean).map((t) => [t.id, t]));
473
+ for (const msg of result.messages) {
474
+ const content = getTextContent(msg);
489
475
  const msgThreadId = msg.threadId || threadId;
490
476
  const thread = threadMap.get(msgThreadId);
491
- const threadMessages = (await memory.query({ threadId: msgThreadId })).uiMessages;
477
+ const threadMessages = (await memory.recall({ threadId: msgThreadId })).messages;
492
478
  const messageIndex = threadMessages.findIndex((m) => m.id === msg.id);
493
479
  const searchResult = {
494
480
  id: msg.id,
@@ -503,13 +489,13 @@ async function searchMemoryHandler({
503
489
  before: threadMessages.slice(Math.max(0, messageIndex - beforeRange), messageIndex).map((m) => ({
504
490
  id: m.id,
505
491
  role: m.role,
506
- content: m.content,
492
+ content: getTextContent(m),
507
493
  createdAt: m.createdAt || /* @__PURE__ */ new Date()
508
494
  })),
509
495
  after: threadMessages.slice(messageIndex + 1, messageIndex + afterRange + 1).map((m) => ({
510
496
  id: m.id,
511
497
  role: m.role,
512
- content: m.content,
498
+ content: getTextContent(m),
513
499
  createdAt: m.createdAt || /* @__PURE__ */ new Date()
514
500
  }))
515
501
  };
@@ -525,7 +511,7 @@ async function searchMemoryHandler({
525
511
  searchType: hasSemanticRecall ? "semantic" : "text"
526
512
  };
527
513
  } catch (error) {
528
- return chunkRE4RPXT2_cjs.handleError(error, "Error searching memory");
514
+ return chunkV5WWQN7P_cjs.handleError(error, "Error searching memory");
529
515
  }
530
516
  }
531
517
 
@@ -534,16 +520,15 @@ exports.deleteMessagesHandler = deleteMessagesHandler;
534
520
  exports.deleteThreadHandler = deleteThreadHandler;
535
521
  exports.getMemoryConfigHandler = getMemoryConfigHandler;
536
522
  exports.getMemoryStatusHandler = getMemoryStatusHandler;
537
- exports.getMessagesHandler = getMessagesHandler;
538
- exports.getMessagesPaginatedHandler = getMessagesPaginatedHandler;
523
+ exports.getTextContent = getTextContent;
539
524
  exports.getThreadByIdHandler = getThreadByIdHandler;
540
- exports.getThreadsHandler = getThreadsHandler;
541
- exports.getThreadsPaginatedHandler = getThreadsPaginatedHandler;
542
525
  exports.getWorkingMemoryHandler = getWorkingMemoryHandler;
526
+ exports.listMessagesHandler = listMessagesHandler;
527
+ exports.listThreadsHandler = listThreadsHandler;
543
528
  exports.memory_exports = memory_exports;
544
529
  exports.saveMessagesHandler = saveMessagesHandler;
545
530
  exports.searchMemoryHandler = searchMemoryHandler;
546
531
  exports.updateThreadHandler = updateThreadHandler;
547
532
  exports.updateWorkingMemoryHandler = updateWorkingMemoryHandler;
548
- //# sourceMappingURL=chunk-Y7SH5ZKM.cjs.map
549
- //# sourceMappingURL=chunk-Y7SH5ZKM.cjs.map
533
+ //# sourceMappingURL=chunk-U7GLIXYO.cjs.map
534
+ //# sourceMappingURL=chunk-U7GLIXYO.cjs.map