@mastra/server 0.0.0-redis-cloud-transporter-20250508194049 → 0.0.0-refactor-agent-information-for-recomposable-ui-20251112151814

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 (270) hide show
  1. package/CHANGELOG.md +4878 -0
  2. package/LICENSE.md +11 -42
  3. package/README.md +1 -6
  4. package/dist/chunk-2IS5WICF.js +23036 -0
  5. package/dist/chunk-2IS5WICF.js.map +1 -0
  6. package/dist/chunk-2PLXW4ZX.cjs +2777 -0
  7. package/dist/chunk-2PLXW4ZX.cjs.map +1 -0
  8. package/dist/chunk-2YZH5PH6.cjs +200 -0
  9. package/dist/chunk-2YZH5PH6.cjs.map +1 -0
  10. package/dist/chunk-3AMNUUZF.js +124 -0
  11. package/dist/chunk-3AMNUUZF.js.map +1 -0
  12. package/dist/chunk-3F52QCI4.js +192 -0
  13. package/dist/chunk-3F52QCI4.js.map +1 -0
  14. package/dist/chunk-4JF5WXPL.js +502 -0
  15. package/dist/chunk-4JF5WXPL.js.map +1 -0
  16. package/dist/{chunk-FV45V6WC.cjs → chunk-64ITUOXI.cjs} +3 -7
  17. package/dist/chunk-64ITUOXI.cjs.map +1 -0
  18. package/dist/{chunk-TRDNDNGQ.js → chunk-6QWQZI4Q.js} +4 -7
  19. package/dist/chunk-6QWQZI4Q.js.map +1 -0
  20. package/dist/chunk-73PAWDM5.js +83 -0
  21. package/dist/chunk-73PAWDM5.js.map +1 -0
  22. package/dist/chunk-A24TSVEZ.cjs +130 -0
  23. package/dist/chunk-A24TSVEZ.cjs.map +1 -0
  24. package/dist/chunk-A2NPD5N6.cjs +517 -0
  25. package/dist/chunk-A2NPD5N6.cjs.map +1 -0
  26. package/dist/chunk-B3Z6J745.js +122 -0
  27. package/dist/chunk-B3Z6J745.js.map +1 -0
  28. package/dist/chunk-BTWIR2B7.cjs +28 -0
  29. package/dist/chunk-BTWIR2B7.cjs.map +1 -0
  30. package/dist/chunk-D7T74TVR.js +129 -0
  31. package/dist/chunk-D7T74TVR.js.map +1 -0
  32. package/dist/chunk-EHACNWDL.cjs +681 -0
  33. package/dist/chunk-EHACNWDL.cjs.map +1 -0
  34. package/dist/chunk-FPBYKMIS.js +477 -0
  35. package/dist/chunk-FPBYKMIS.js.map +1 -0
  36. package/dist/chunk-GLAZTMX3.cjs +128 -0
  37. package/dist/chunk-GLAZTMX3.cjs.map +1 -0
  38. package/dist/chunk-GU4EWMZB.cjs +769 -0
  39. package/dist/chunk-GU4EWMZB.cjs.map +1 -0
  40. package/dist/chunk-ID6JYDNL.cjs +23075 -0
  41. package/dist/chunk-ID6JYDNL.cjs.map +1 -0
  42. package/dist/chunk-KF3RI45U.cjs +172 -0
  43. package/dist/chunk-KF3RI45U.cjs.map +1 -0
  44. package/dist/chunk-KJIDZQRA.cjs +485 -0
  45. package/dist/chunk-KJIDZQRA.cjs.map +1 -0
  46. package/dist/{chunk-4JINXASC.js → chunk-KWH5QBXP.js} +7 -4
  47. package/dist/chunk-KWH5QBXP.js.map +1 -0
  48. package/dist/chunk-LF2ZLOFP.js +767 -0
  49. package/dist/chunk-LF2ZLOFP.js.map +1 -0
  50. package/dist/chunk-LPM6BBAX.cjs +1043 -0
  51. package/dist/chunk-LPM6BBAX.cjs.map +1 -0
  52. package/dist/chunk-ND5OKOMT.js +165 -0
  53. package/dist/chunk-ND5OKOMT.js.map +1 -0
  54. package/dist/chunk-O7I5CWRX.cjs +44 -0
  55. package/dist/chunk-O7I5CWRX.cjs.map +1 -0
  56. package/dist/chunk-PPMIB3FQ.cjs +88 -0
  57. package/dist/chunk-PPMIB3FQ.cjs.map +1 -0
  58. package/dist/chunk-PR4QN5HX.js +39 -0
  59. package/dist/chunk-PR4QN5HX.js.map +1 -0
  60. package/dist/chunk-QU6N55W6.cjs +256 -0
  61. package/dist/chunk-QU6N55W6.cjs.map +1 -0
  62. package/dist/chunk-RQK4FQUD.js +1012 -0
  63. package/dist/chunk-RQK4FQUD.js.map +1 -0
  64. package/dist/{chunk-M56ECCHK.cjs → chunk-S54HNARD.cjs} +22 -19
  65. package/dist/chunk-S54HNARD.cjs.map +1 -0
  66. package/dist/chunk-SHWNNZBL.js +254 -0
  67. package/dist/chunk-SHWNNZBL.js.map +1 -0
  68. package/dist/{chunk-L7XE5QTW.js → chunk-SZIFSF4T.js} +11 -2
  69. package/dist/chunk-SZIFSF4T.js.map +1 -0
  70. package/dist/chunk-TOCYBDP2.js +46 -0
  71. package/dist/chunk-TOCYBDP2.js.map +1 -0
  72. package/dist/chunk-UXGQZUYZ.js +16 -0
  73. package/dist/chunk-UXGQZUYZ.js.map +1 -0
  74. package/dist/chunk-V5WWQN7P.cjs +18 -0
  75. package/dist/chunk-V5WWQN7P.cjs.map +1 -0
  76. package/dist/chunk-W2KMU354.cjs +133 -0
  77. package/dist/chunk-W2KMU354.cjs.map +1 -0
  78. package/dist/chunk-X3MICMI2.cjs +620 -0
  79. package/dist/chunk-X3MICMI2.cjs.map +1 -0
  80. package/dist/chunk-X6C7BUWN.cjs +48 -0
  81. package/dist/chunk-X6C7BUWN.cjs.map +1 -0
  82. package/dist/chunk-Z2O5YVHY.js +661 -0
  83. package/dist/chunk-Z2O5YVHY.js.map +1 -0
  84. package/dist/chunk-ZJ6KEY6H.js +600 -0
  85. package/dist/chunk-ZJ6KEY6H.js.map +1 -0
  86. package/dist/chunk-ZULZ2752.js +2774 -0
  87. package/dist/chunk-ZULZ2752.js.map +1 -0
  88. package/dist/dist-4MVGNSRL.cjs +1150 -0
  89. package/dist/dist-4MVGNSRL.cjs.map +1 -0
  90. package/dist/dist-FZYCV3VB.cjs +940 -0
  91. package/dist/dist-FZYCV3VB.cjs.map +1 -0
  92. package/dist/dist-G2BYZJOC.cjs +928 -0
  93. package/dist/dist-G2BYZJOC.cjs.map +1 -0
  94. package/dist/dist-P4MXBQ3U.cjs +16 -0
  95. package/dist/dist-P4MXBQ3U.cjs.map +1 -0
  96. package/dist/dist-PQZUVLPC.js +937 -0
  97. package/dist/dist-PQZUVLPC.js.map +1 -0
  98. package/dist/dist-R7WYX6LC.js +925 -0
  99. package/dist/dist-R7WYX6LC.js.map +1 -0
  100. package/dist/dist-RFMYFILX.cjs +764 -0
  101. package/dist/dist-RFMYFILX.cjs.map +1 -0
  102. package/dist/dist-X7XR3M3Z.js +1147 -0
  103. package/dist/dist-X7XR3M3Z.js.map +1 -0
  104. package/dist/dist-XVBSOGFK.js +761 -0
  105. package/dist/dist-XVBSOGFK.js.map +1 -0
  106. package/dist/dist-YREX2TJT.js +3 -0
  107. package/dist/dist-YREX2TJT.js.map +1 -0
  108. package/dist/index.cjs +6 -0
  109. package/dist/index.cjs.map +1 -0
  110. package/dist/index.d.ts +1 -0
  111. package/dist/index.d.ts.map +1 -0
  112. package/dist/index.js +5 -0
  113. package/dist/index.js.map +1 -0
  114. package/dist/server/a2a/protocol.d.ts +8 -0
  115. package/dist/server/a2a/protocol.d.ts.map +1 -0
  116. package/dist/server/a2a/store.cjs +25 -0
  117. package/dist/server/a2a/store.cjs.map +1 -0
  118. package/dist/server/a2a/store.d.ts +14 -0
  119. package/dist/server/a2a/store.d.ts.map +1 -0
  120. package/dist/server/a2a/store.js +23 -0
  121. package/dist/server/a2a/store.js.map +1 -0
  122. package/dist/server/a2a/tasks.d.ts +20 -0
  123. package/dist/server/a2a/tasks.d.ts.map +1 -0
  124. package/dist/server/handlers/a2a.cjs +32 -0
  125. package/dist/server/handlers/a2a.cjs.map +1 -0
  126. package/dist/server/handlers/a2a.d.ts +68 -0
  127. package/dist/server/handlers/a2a.d.ts.map +1 -0
  128. package/dist/server/handlers/a2a.js +3 -0
  129. package/dist/server/handlers/a2a.js.map +1 -0
  130. package/dist/server/handlers/agent-builder.cjs +80 -0
  131. package/dist/server/handlers/agent-builder.cjs.map +1 -0
  132. package/dist/server/handlers/agent-builder.d.ts +85 -0
  133. package/dist/server/handlers/agent-builder.d.ts.map +1 -0
  134. package/dist/server/handlers/agent-builder.js +3 -0
  135. package/dist/server/handlers/agent-builder.js.map +1 -0
  136. package/dist/server/handlers/agents.cjs +60 -10
  137. package/dist/server/handlers/agents.cjs.map +1 -0
  138. package/dist/server/handlers/agents.d.ts +194 -6
  139. package/dist/server/handlers/agents.d.ts.map +1 -0
  140. package/dist/server/handlers/agents.js +3 -1
  141. package/dist/server/handlers/agents.js.map +1 -0
  142. package/dist/server/handlers/error.cjs +4 -2
  143. package/dist/server/handlers/error.cjs.map +1 -0
  144. package/dist/server/handlers/error.d.ts +2 -1
  145. package/dist/server/handlers/error.d.ts.map +1 -0
  146. package/dist/server/handlers/error.js +3 -1
  147. package/dist/server/handlers/error.js.map +1 -0
  148. package/dist/server/handlers/logs.cjs +9 -7
  149. package/dist/server/handlers/logs.cjs.map +1 -0
  150. package/dist/server/handlers/logs.d.ts +34 -3
  151. package/dist/server/handlers/logs.d.ts.map +1 -0
  152. package/dist/server/handlers/logs.js +3 -1
  153. package/dist/server/handlers/logs.js.map +1 -0
  154. package/dist/server/handlers/memory.cjs +34 -12
  155. package/dist/server/handlers/memory.cjs.map +1 -0
  156. package/dist/server/handlers/memory.d.ts +112 -8
  157. package/dist/server/handlers/memory.d.ts.map +1 -0
  158. package/dist/server/handlers/memory.js +3 -1
  159. package/dist/server/handlers/memory.js.map +1 -0
  160. package/dist/server/handlers/observability.cjs +24 -0
  161. package/dist/server/handlers/observability.cjs.map +1 -0
  162. package/dist/server/handlers/observability.d.ts +49 -0
  163. package/dist/server/handlers/observability.d.ts.map +1 -0
  164. package/dist/server/handlers/observability.js +3 -0
  165. package/dist/server/handlers/observability.js.map +1 -0
  166. package/dist/server/handlers/scores.cjs +32 -0
  167. package/dist/server/handlers/scores.cjs.map +1 -0
  168. package/dist/server/handlers/scores.d.ts +152 -0
  169. package/dist/server/handlers/scores.d.ts.map +1 -0
  170. package/dist/server/handlers/scores.js +3 -0
  171. package/dist/server/handlers/scores.js.map +1 -0
  172. package/dist/server/handlers/tools.cjs +12 -6
  173. package/dist/server/handlers/tools.cjs.map +1 -0
  174. package/dist/server/handlers/tools.d.ts +25 -4
  175. package/dist/server/handlers/tools.d.ts.map +1 -0
  176. package/dist/server/handlers/tools.js +3 -1
  177. package/dist/server/handlers/tools.js.map +1 -0
  178. package/dist/server/handlers/utils.cjs +8 -2
  179. package/dist/server/handlers/utils.cjs.map +1 -0
  180. package/dist/server/handlers/utils.d.ts +8 -1
  181. package/dist/server/handlers/utils.d.ts.map +1 -0
  182. package/dist/server/handlers/utils.js +3 -1
  183. package/dist/server/handlers/utils.js.map +1 -0
  184. package/dist/server/handlers/vector.cjs +9 -7
  185. package/dist/server/handlers/vector.cjs.map +1 -0
  186. package/dist/server/handlers/vector.d.ts +51 -6
  187. package/dist/server/handlers/vector.d.ts.map +1 -0
  188. package/dist/server/handlers/vector.js +3 -1
  189. package/dist/server/handlers/vector.js.map +1 -0
  190. package/dist/server/handlers/voice.cjs +10 -4
  191. package/dist/server/handlers/voice.cjs.map +1 -0
  192. package/dist/server/handlers/voice.d.ts +41 -3
  193. package/dist/server/handlers/voice.d.ts.map +1 -0
  194. package/dist/server/handlers/voice.js +3 -1
  195. package/dist/server/handlers/voice.js.map +1 -0
  196. package/dist/server/handlers/workflows.cjs +50 -16
  197. package/dist/server/handlers/workflows.cjs.map +1 -0
  198. package/dist/server/handlers/workflows.d.ts +88 -10
  199. package/dist/server/handlers/workflows.d.ts.map +1 -0
  200. package/dist/server/handlers/workflows.js +3 -1
  201. package/dist/server/handlers/workflows.js.map +1 -0
  202. package/dist/server/handlers.cjs +37 -30
  203. package/dist/server/handlers.cjs.map +1 -0
  204. package/dist/server/handlers.d.ts +12 -10
  205. package/dist/server/handlers.d.ts.map +1 -0
  206. package/dist/server/handlers.js +13 -10
  207. package/dist/server/handlers.js.map +1 -0
  208. package/dist/server/http-exception.d.ts +82 -0
  209. package/dist/server/http-exception.d.ts.map +1 -0
  210. package/dist/server/types.d.ts +10 -0
  211. package/dist/server/types.d.ts.map +1 -0
  212. package/dist/server/utils.d.ts +45 -0
  213. package/dist/server/utils.d.ts.map +1 -0
  214. package/dist/token-375W3LEI.cjs +64 -0
  215. package/dist/token-375W3LEI.cjs.map +1 -0
  216. package/dist/token-C3IMNCC4.js +62 -0
  217. package/dist/token-C3IMNCC4.js.map +1 -0
  218. package/dist/token-util-CV3RRG6K.cjs +9 -0
  219. package/dist/token-util-CV3RRG6K.cjs.map +1 -0
  220. package/dist/token-util-E5QO2RCL.js +7 -0
  221. package/dist/token-util-E5QO2RCL.js.map +1 -0
  222. package/package.json +46 -19
  223. package/dist/_tsup-dts-rollup.d.cts +0 -670
  224. package/dist/_tsup-dts-rollup.d.ts +0 -670
  225. package/dist/chunk-2FJURXCL.cjs +0 -213
  226. package/dist/chunk-3AHQ5RGN.js +0 -11
  227. package/dist/chunk-3EJZQ6TQ.js +0 -49
  228. package/dist/chunk-3XTEV33Q.js +0 -317
  229. package/dist/chunk-55HTWX4C.cjs +0 -93
  230. package/dist/chunk-5JNVY6DU.js +0 -120
  231. package/dist/chunk-5SWCVTNL.cjs +0 -5579
  232. package/dist/chunk-5YGDYMRB.cjs +0 -147
  233. package/dist/chunk-6Q7UXAYJ.cjs +0 -198
  234. package/dist/chunk-AMVOS7YB.cjs +0 -141
  235. package/dist/chunk-BPL2CBLV.js +0 -137
  236. package/dist/chunk-CHFORQ7J.cjs +0 -329
  237. package/dist/chunk-D3G23FP3.cjs +0 -126
  238. package/dist/chunk-GVBJ5I2S.js +0 -190
  239. package/dist/chunk-M2RXDCPV.cjs +0 -324
  240. package/dist/chunk-OMN3UI6X.js +0 -5576
  241. package/dist/chunk-OWNA6I2H.js +0 -312
  242. package/dist/chunk-Q6SHQECN.js +0 -88
  243. package/dist/chunk-QJ3AHN64.js +0 -141
  244. package/dist/chunk-QN4KF3BH.cjs +0 -18
  245. package/dist/chunk-RBQASTUP.js +0 -203
  246. package/dist/chunk-SKBVVI24.cjs +0 -54
  247. package/dist/chunk-ZLBRQFDD.cjs +0 -13
  248. package/dist/index.d.cts +0 -1
  249. package/dist/server/handlers/agents.d.cts +0 -6
  250. package/dist/server/handlers/error.d.cts +0 -1
  251. package/dist/server/handlers/logs.d.cts +0 -3
  252. package/dist/server/handlers/memory.d.cts +0 -8
  253. package/dist/server/handlers/network.cjs +0 -22
  254. package/dist/server/handlers/network.d.cts +0 -4
  255. package/dist/server/handlers/network.d.ts +0 -4
  256. package/dist/server/handlers/network.js +0 -1
  257. package/dist/server/handlers/telemetry.cjs +0 -14
  258. package/dist/server/handlers/telemetry.d.cts +0 -2
  259. package/dist/server/handlers/telemetry.d.ts +0 -2
  260. package/dist/server/handlers/telemetry.js +0 -1
  261. package/dist/server/handlers/tools.d.cts +0 -4
  262. package/dist/server/handlers/utils.d.cts +0 -1
  263. package/dist/server/handlers/vNextWorkflows.cjs +0 -46
  264. package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
  265. package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
  266. package/dist/server/handlers/vNextWorkflows.js +0 -1
  267. package/dist/server/handlers/vector.d.cts +0 -6
  268. package/dist/server/handlers/voice.d.cts +0 -3
  269. package/dist/server/handlers/workflows.d.cts +0 -10
  270. package/dist/server/handlers.d.cts +0 -10
@@ -0,0 +1,502 @@
1
+ import { validateBody } from './chunk-SZIFSF4T.js';
2
+ import { handleError } from './chunk-UXGQZUYZ.js';
3
+ import { HTTPException } from './chunk-6QWQZI4Q.js';
4
+ import { __export } from './chunk-PR4QN5HX.js';
5
+ import { RequestContext } from '@mastra/core/di';
6
+ import { generateEmptyFromSchema } from '@mastra/core/utils';
7
+
8
+ // src/server/handlers/memory.ts
9
+ var memory_exports = {};
10
+ __export(memory_exports, {
11
+ createThreadHandler: () => createThreadHandler,
12
+ deleteMessagesHandler: () => deleteMessagesHandler,
13
+ deleteThreadHandler: () => deleteThreadHandler,
14
+ getMemoryConfigHandler: () => getMemoryConfigHandler,
15
+ getMemoryStatusHandler: () => getMemoryStatusHandler,
16
+ getThreadByIdHandler: () => getThreadByIdHandler,
17
+ getWorkingMemoryHandler: () => getWorkingMemoryHandler,
18
+ listMessagesHandler: () => listMessagesHandler,
19
+ listThreadsHandler: () => listThreadsHandler,
20
+ saveMessagesHandler: () => saveMessagesHandler,
21
+ searchMemoryHandler: () => searchMemoryHandler,
22
+ updateThreadHandler: () => updateThreadHandler,
23
+ updateWorkingMemoryHandler: () => updateWorkingMemoryHandler
24
+ });
25
+ async function getMemoryFromContext({
26
+ mastra,
27
+ agentId,
28
+ requestContext
29
+ }) {
30
+ const logger = mastra.getLogger();
31
+ let agent;
32
+ if (agentId) {
33
+ try {
34
+ agent = mastra.getAgentById(agentId);
35
+ } catch (error) {
36
+ logger.debug("Error getting agent from mastra, searching agents for agent", error);
37
+ }
38
+ }
39
+ if (agentId && !agent) {
40
+ logger.debug("Agent not found, searching agents for agent", { agentId });
41
+ const agents = mastra.listAgents();
42
+ if (Object.keys(agents || {}).length) {
43
+ for (const [_, ag] of Object.entries(agents)) {
44
+ try {
45
+ const agents2 = await ag.listAgents();
46
+ if (agents2[agentId]) {
47
+ agent = agents2[agentId];
48
+ break;
49
+ }
50
+ } catch (error) {
51
+ logger.debug("Error getting agent from agent", error);
52
+ }
53
+ }
54
+ }
55
+ if (!agent) {
56
+ throw new HTTPException(404, { message: "Agent not found" });
57
+ }
58
+ }
59
+ if (agent) {
60
+ return await agent?.getMemory({
61
+ requestContext: requestContext ?? new RequestContext()
62
+ });
63
+ }
64
+ }
65
+ async function getMemoryStatusHandler({
66
+ mastra,
67
+ agentId,
68
+ requestContext
69
+ }) {
70
+ try {
71
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
72
+ if (!memory) {
73
+ return { result: false };
74
+ }
75
+ return { result: true };
76
+ } catch (error) {
77
+ return handleError(error, "Error getting memory status");
78
+ }
79
+ }
80
+ async function getMemoryConfigHandler({
81
+ mastra,
82
+ agentId,
83
+ requestContext
84
+ }) {
85
+ try {
86
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
87
+ if (!memory) {
88
+ throw new HTTPException(400, { message: "Memory is not initialized" });
89
+ }
90
+ const config = memory.getMergedThreadConfig({});
91
+ return { config };
92
+ } catch (error) {
93
+ return handleError(error, "Error getting memory configuration");
94
+ }
95
+ }
96
+ async function listThreadsHandler({
97
+ mastra,
98
+ agentId,
99
+ resourceId,
100
+ requestContext,
101
+ page,
102
+ perPage,
103
+ orderBy
104
+ }) {
105
+ try {
106
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
107
+ if (!memory) {
108
+ throw new HTTPException(400, { message: "Memory is not initialized" });
109
+ }
110
+ validateBody({ resourceId });
111
+ const result = await memory.listThreadsByResourceId({
112
+ resourceId,
113
+ page,
114
+ perPage,
115
+ orderBy
116
+ });
117
+ return result;
118
+ } catch (error) {
119
+ return handleError(error, "Error listing threads");
120
+ }
121
+ }
122
+ async function getThreadByIdHandler({
123
+ mastra,
124
+ agentId,
125
+ threadId,
126
+ requestContext
127
+ }) {
128
+ try {
129
+ validateBody({ threadId });
130
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
131
+ if (!memory) {
132
+ throw new HTTPException(400, { message: "Memory is not initialized" });
133
+ }
134
+ const thread = await memory.getThreadById({ threadId });
135
+ if (!thread) {
136
+ throw new HTTPException(404, { message: "Thread not found" });
137
+ }
138
+ return thread;
139
+ } catch (error) {
140
+ return handleError(error, "Error getting thread");
141
+ }
142
+ }
143
+ async function saveMessagesHandler({
144
+ mastra,
145
+ agentId,
146
+ body,
147
+ requestContext
148
+ }) {
149
+ try {
150
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
151
+ if (!memory) {
152
+ throw new HTTPException(400, { message: "Memory is not initialized" });
153
+ }
154
+ if (!body?.messages) {
155
+ throw new HTTPException(400, { message: "Messages are required" });
156
+ }
157
+ if (!Array.isArray(body.messages)) {
158
+ throw new HTTPException(400, { message: "Messages should be an array" });
159
+ }
160
+ const invalidMessages = body.messages.filter((message) => !message.threadId || !message.resourceId);
161
+ if (invalidMessages.length > 0) {
162
+ throw new HTTPException(400, {
163
+ message: `All messages must have threadId and resourceId fields. Found ${invalidMessages.length} invalid message(s).`
164
+ });
165
+ }
166
+ const processedMessages = body.messages.map((message) => ({
167
+ ...message,
168
+ id: message.id || memory.generateId(),
169
+ createdAt: message.createdAt ? new Date(message.createdAt) : /* @__PURE__ */ new Date()
170
+ }));
171
+ const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });
172
+ return result;
173
+ } catch (error) {
174
+ return handleError(error, "Error saving messages");
175
+ }
176
+ }
177
+ async function createThreadHandler({
178
+ mastra,
179
+ agentId,
180
+ body,
181
+ requestContext
182
+ }) {
183
+ try {
184
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
185
+ if (!memory) {
186
+ throw new HTTPException(400, { message: "Memory is not initialized" });
187
+ }
188
+ validateBody({ resourceId: body?.resourceId });
189
+ const result = await memory.createThread({
190
+ resourceId: body?.resourceId,
191
+ title: body?.title,
192
+ metadata: body?.metadata,
193
+ threadId: body?.threadId
194
+ });
195
+ return result;
196
+ } catch (error) {
197
+ return handleError(error, "Error saving thread to memory");
198
+ }
199
+ }
200
+ async function updateThreadHandler({
201
+ mastra,
202
+ agentId,
203
+ threadId,
204
+ body,
205
+ requestContext
206
+ }) {
207
+ try {
208
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
209
+ if (!body) {
210
+ throw new HTTPException(400, { message: "Body is required" });
211
+ }
212
+ const { title, metadata, resourceId } = body;
213
+ const updatedAt = /* @__PURE__ */ new Date();
214
+ validateBody({ threadId });
215
+ if (!memory) {
216
+ throw new HTTPException(400, { message: "Memory is not initialized" });
217
+ }
218
+ const thread = await memory.getThreadById({ threadId });
219
+ if (!thread) {
220
+ throw new HTTPException(404, { message: "Thread not found" });
221
+ }
222
+ const updatedThread = {
223
+ ...thread,
224
+ title: title || thread.title,
225
+ metadata: metadata || thread.metadata,
226
+ resourceId: resourceId || thread.resourceId,
227
+ createdAt: thread.createdAt,
228
+ updatedAt
229
+ };
230
+ const result = await memory.saveThread({ thread: updatedThread });
231
+ return result;
232
+ } catch (error) {
233
+ return handleError(error, "Error updating thread");
234
+ }
235
+ }
236
+ async function deleteThreadHandler({
237
+ mastra,
238
+ agentId,
239
+ threadId,
240
+ requestContext
241
+ }) {
242
+ try {
243
+ validateBody({ threadId });
244
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
245
+ if (!memory) {
246
+ throw new HTTPException(400, { message: "Memory is not initialized" });
247
+ }
248
+ const thread = await memory.getThreadById({ threadId });
249
+ if (!thread) {
250
+ throw new HTTPException(404, { message: "Thread not found" });
251
+ }
252
+ await memory.deleteThread(threadId);
253
+ return { result: "Thread deleted" };
254
+ } catch (error) {
255
+ return handleError(error, "Error deleting thread");
256
+ }
257
+ }
258
+ async function listMessagesHandler({
259
+ mastra,
260
+ agentId,
261
+ threadId,
262
+ resourceId,
263
+ perPage,
264
+ page,
265
+ orderBy,
266
+ include,
267
+ filter,
268
+ requestContext
269
+ }) {
270
+ try {
271
+ validateBody({ threadId });
272
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
273
+ if (!memory) {
274
+ throw new HTTPException(400, { message: "Memory is not initialized" });
275
+ }
276
+ if (!threadId) {
277
+ throw new HTTPException(400, { message: "No threadId found" });
278
+ }
279
+ const thread = await memory.getThreadById({ threadId });
280
+ if (!thread) {
281
+ throw new HTTPException(404, { message: "Thread not found" });
282
+ }
283
+ const result = await memory.recall({
284
+ threadId,
285
+ resourceId,
286
+ perPage,
287
+ page,
288
+ orderBy,
289
+ include,
290
+ filter
291
+ });
292
+ return result;
293
+ } catch (error) {
294
+ return handleError(error, "Error getting messages");
295
+ }
296
+ }
297
+ async function getWorkingMemoryHandler({
298
+ mastra,
299
+ agentId,
300
+ threadId,
301
+ resourceId,
302
+ requestContext,
303
+ memoryConfig
304
+ }) {
305
+ try {
306
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
307
+ validateBody({ threadId });
308
+ if (!memory) {
309
+ throw new HTTPException(400, { message: "Memory is not initialized" });
310
+ }
311
+ const thread = await memory.getThreadById({ threadId });
312
+ const threadExists = !!thread;
313
+ const template = await memory.getWorkingMemoryTemplate({ memoryConfig });
314
+ const workingMemoryTemplate = template?.format === "json" ? { ...template, content: JSON.stringify(generateEmptyFromSchema(template.content)) } : template;
315
+ const workingMemory = await memory.getWorkingMemory({ threadId, resourceId, memoryConfig });
316
+ const config = memory.getMergedThreadConfig(memoryConfig || {});
317
+ const source = config.workingMemory?.scope !== "thread" && resourceId ? "resource" : "thread";
318
+ return { workingMemory, source, workingMemoryTemplate, threadExists };
319
+ } catch (error) {
320
+ return handleError(error, "Error getting working memory");
321
+ }
322
+ }
323
+ async function updateWorkingMemoryHandler({
324
+ mastra,
325
+ agentId,
326
+ threadId,
327
+ body,
328
+ requestContext
329
+ }) {
330
+ try {
331
+ validateBody({ threadId });
332
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
333
+ const { resourceId, memoryConfig, workingMemory } = body;
334
+ if (!memory) {
335
+ throw new HTTPException(400, { message: "Memory is not initialized" });
336
+ }
337
+ const thread = await memory.getThreadById({ threadId });
338
+ if (!thread) {
339
+ throw new HTTPException(404, { message: "Thread not found" });
340
+ }
341
+ await memory.updateWorkingMemory({ threadId, resourceId, workingMemory, memoryConfig });
342
+ return { success: true };
343
+ } catch (error) {
344
+ return handleError(error, "Error updating working memory");
345
+ }
346
+ }
347
+ async function deleteMessagesHandler({
348
+ mastra,
349
+ agentId,
350
+ messageIds,
351
+ requestContext
352
+ }) {
353
+ try {
354
+ if (messageIds === void 0 || messageIds === null) {
355
+ throw new HTTPException(400, { message: "messageIds is required" });
356
+ }
357
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
358
+ if (!memory) {
359
+ throw new HTTPException(400, { message: "Memory is not initialized" });
360
+ }
361
+ await memory.deleteMessages(messageIds);
362
+ let count = 1;
363
+ if (Array.isArray(messageIds)) {
364
+ count = messageIds.length;
365
+ }
366
+ return { success: true, message: `${count} message${count === 1 ? "" : "s"} deleted successfully` };
367
+ } catch (error) {
368
+ return handleError(error, "Error deleting messages");
369
+ }
370
+ }
371
+ async function searchMemoryHandler({
372
+ mastra,
373
+ agentId,
374
+ searchQuery,
375
+ resourceId,
376
+ threadId,
377
+ limit = 20,
378
+ requestContext,
379
+ memoryConfig
380
+ }) {
381
+ try {
382
+ validateBody({ searchQuery, resourceId });
383
+ const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
384
+ if (!memory) {
385
+ throw new HTTPException(400, { message: "Memory is not initialized" });
386
+ }
387
+ const config = memory.getMergedThreadConfig(memoryConfig || {});
388
+ const hasSemanticRecall = !!config?.semanticRecall;
389
+ const resourceScope = typeof config?.semanticRecall === "object" ? config?.semanticRecall?.scope !== "thread" : true;
390
+ if (threadId && !resourceScope) {
391
+ const thread = await memory.getThreadById({ threadId });
392
+ if (!thread) {
393
+ throw new HTTPException(404, { message: "Thread not found" });
394
+ }
395
+ if (thread.resourceId !== resourceId) {
396
+ throw new HTTPException(403, { message: "Thread does not belong to the specified resource" });
397
+ }
398
+ }
399
+ const searchResults = [];
400
+ if (threadId && !resourceScope) {
401
+ const thread = await memory.getThreadById({ threadId });
402
+ if (!thread) {
403
+ return {
404
+ results: [],
405
+ count: 0,
406
+ query: searchQuery,
407
+ searchScope: resourceScope ? "resource" : "thread",
408
+ searchType: hasSemanticRecall ? "semantic" : "text"
409
+ };
410
+ }
411
+ }
412
+ if (!threadId) {
413
+ const { threads } = await memory.listThreadsByResourceId({
414
+ resourceId,
415
+ page: 0,
416
+ perPage: 1,
417
+ orderBy: { field: "updatedAt", direction: "DESC" }
418
+ });
419
+ if (threads.length === 0) {
420
+ return {
421
+ results: [],
422
+ count: 0,
423
+ query: searchQuery,
424
+ searchScope: resourceScope ? "resource" : "thread",
425
+ searchType: hasSemanticRecall ? "semantic" : "text"
426
+ };
427
+ }
428
+ threadId = threads[0].id;
429
+ }
430
+ const beforeRange = typeof config.semanticRecall === `boolean` ? 2 : typeof config.semanticRecall?.messageRange === `number` ? config.semanticRecall.messageRange : config.semanticRecall?.messageRange.before || 2;
431
+ const afterRange = typeof config.semanticRecall === `boolean` ? 2 : typeof config.semanticRecall?.messageRange === `number` ? config.semanticRecall.messageRange : config.semanticRecall?.messageRange.after || 2;
432
+ if (resourceScope && config.semanticRecall) {
433
+ config.semanticRecall = typeof config.semanticRecall === `boolean` ? (
434
+ // make message range 0 so we can highlight the matches in search, message range will include other messages, not the matching ones
435
+ // and we add prev/next messages in a special section on each message anyway
436
+ { messageRange: 0, topK: 2, scope: "resource" }
437
+ ) : { ...config.semanticRecall, messageRange: 0 };
438
+ }
439
+ const threadConfig = memory.getMergedThreadConfig(config || {});
440
+ if (!threadConfig.lastMessages && !threadConfig.semanticRecall) {
441
+ return { results: [], count: 0, query: searchQuery };
442
+ }
443
+ const result = await memory.recall({
444
+ threadId,
445
+ resourceId,
446
+ perPage: threadConfig.lastMessages,
447
+ threadConfig: config,
448
+ vectorSearchString: threadConfig.semanticRecall && searchQuery ? searchQuery : void 0
449
+ });
450
+ const threadIds = Array.from(
451
+ new Set(result.messages.map((m) => m.threadId || threadId).filter(Boolean))
452
+ );
453
+ const fetched = await Promise.all(threadIds.map((id) => memory.getThreadById({ threadId: id })));
454
+ const threadMap = new Map(fetched.filter(Boolean).map((t) => [t.id, t]));
455
+ for (const msg of result.messages) {
456
+ const content = typeof msg.content.content === `string` ? msg.content.content : msg.content.parts?.map((p) => p.type === "text" ? p.text : "").join(" ") || "";
457
+ const msgThreadId = msg.threadId || threadId;
458
+ const thread = threadMap.get(msgThreadId);
459
+ const threadMessages = (await memory.recall({ threadId: msgThreadId })).messages;
460
+ const messageIndex = threadMessages.findIndex((m) => m.id === msg.id);
461
+ const searchResult = {
462
+ id: msg.id,
463
+ role: msg.role,
464
+ content,
465
+ createdAt: msg.createdAt,
466
+ threadId: msgThreadId,
467
+ threadTitle: thread?.title || msgThreadId
468
+ };
469
+ if (messageIndex !== -1) {
470
+ searchResult.context = {
471
+ before: threadMessages.slice(Math.max(0, messageIndex - beforeRange), messageIndex).map((m) => ({
472
+ id: m.id,
473
+ role: m.role,
474
+ content: m.content,
475
+ createdAt: m.createdAt || /* @__PURE__ */ new Date()
476
+ })),
477
+ after: threadMessages.slice(messageIndex + 1, messageIndex + afterRange + 1).map((m) => ({
478
+ id: m.id,
479
+ role: m.role,
480
+ content: m.content,
481
+ createdAt: m.createdAt || /* @__PURE__ */ new Date()
482
+ }))
483
+ };
484
+ }
485
+ searchResults.push(searchResult);
486
+ }
487
+ const sortedResults = searchResults.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()).slice(0, limit);
488
+ return {
489
+ results: sortedResults,
490
+ count: sortedResults.length,
491
+ query: searchQuery,
492
+ searchScope: resourceScope ? "resource" : "thread",
493
+ searchType: hasSemanticRecall ? "semantic" : "text"
494
+ };
495
+ } catch (error) {
496
+ return handleError(error, "Error searching memory");
497
+ }
498
+ }
499
+
500
+ export { createThreadHandler, deleteMessagesHandler, deleteThreadHandler, getMemoryConfigHandler, getMemoryStatusHandler, getThreadByIdHandler, getWorkingMemoryHandler, listMessagesHandler, listThreadsHandler, memory_exports, saveMessagesHandler, searchMemoryHandler, updateThreadHandler, updateWorkingMemoryHandler };
501
+ //# sourceMappingURL=chunk-4JF5WXPL.js.map
502
+ //# sourceMappingURL=chunk-4JF5WXPL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server/handlers/memory.ts"],"names":["agents"],"mappings":";;;;;;;;AAAA,IAAA,cAAA,GAAA;AAAA,QAAA,CAAA,cAAA,EAAA;AAAA,EAAA,mBAAA,EAAA,MAAA,mBAAA;AAAA,EAAA,qBAAA,EAAA,MAAA,qBAAA;AAAA,EAAA,mBAAA,EAAA,MAAA,mBAAA;AAAA,EAAA,sBAAA,EAAA,MAAA,sBAAA;AAAA,EAAA,sBAAA,EAAA,MAAA,sBAAA;AAAA,EAAA,oBAAA,EAAA,MAAA,oBAAA;AAAA,EAAA,uBAAA,EAAA,MAAA,uBAAA;AAAA,EAAA,mBAAA,EA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,CAAM,CAAA,EAAG,KAAK,CAAA;AAEjB,IAAA,OAAO;AAAA,MACL,OAAA,EAAS,aAAA;AAAA,MACT,OAAO,aAAA,CAAc,MAAA;AAAA,MACrB,KAAA,EAAO,WAAA;AAAA,MACP,WAAA,EAAa,gBAAgB,UAAA,GAAa,QAAA;AAAA,MAC1C,UAAA,EAAY,oBAAoB,UAAA,GAAa;AAAA,KAC/C;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,WAAA,CAAY,OAAO,wBAAwB,CAAA;AAAA,EACpD;AACF","file":"chunk-4JF5WXPL.js","sourcesContent":["import type { MastraDBMessage } from '@mastra/core/agent';\nimport { RequestContext } from '@mastra/core/di';\nimport type { MastraMemory } from '@mastra/core/memory';\nimport type { StorageListMessagesInput, StorageOrderBy } from '@mastra/core/storage';\nimport { generateEmptyFromSchema } from '@mastra/core/utils';\nimport { HTTPException } from '../http-exception';\nimport type { Context } from '../types';\n\nimport { handleError } from './error';\nimport { validateBody } from './utils';\n\ninterface MemoryContext extends Context {\n agentId?: string;\n resourceId?: string;\n threadId?: string;\n requestContext?: RequestContext;\n}\n\nasync function getMemoryFromContext({\n mastra,\n agentId,\n requestContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'requestContext'>): Promise<MastraMemory | null | undefined> {\n const logger = mastra.getLogger();\n let agent;\n if (agentId) {\n try {\n agent = mastra.getAgentById(agentId);\n } catch (error) {\n logger.debug('Error getting agent from mastra, searching agents for agent', error);\n }\n }\n if (agentId && !agent) {\n logger.debug('Agent not found, searching agents for agent', { agentId });\n const agents = mastra.listAgents();\n if (Object.keys(agents || {}).length) {\n for (const [_, ag] of Object.entries(agents)) {\n try {\n const agents = await ag.listAgents();\n\n if (agents[agentId]) {\n agent = agents[agentId];\n break;\n }\n } catch (error) {\n logger.debug('Error getting agent from agent', error);\n }\n }\n }\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n }\n\n if (agent) {\n return await agent?.getMemory({\n requestContext: requestContext ?? new RequestContext(),\n });\n }\n}\n\n// Memory handlers\nexport async function getMemoryStatusHandler({\n mastra,\n agentId,\n requestContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'requestContext'>) {\n try {\n const memory = await getMemoryFromContext({ mastra, agentId, requestContext });\n\n if (!memory) {\n return { result: false };\n }\n\n return { result: true };\n } catch (error) {\n return handleError(error, 'Error getting memory status');\n }\n}\n\nexport async function getMemoryConfigHandler({\n mastra,\n agentId,\n requestContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'requestContext'>) {\n try {\n const memory = await getMemoryFromContext({ mastra, agentId, requestContext });\n\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n // Get the merged configuration (defaults + custom)\n const config = memory.getMergedThreadConfig({});\n\n return { config };\n } catch (error) {\n return handleError(error, 'Error getting memory configuration');\n }\n}\n\nexport async function listThreadsHandler({\n mastra,\n agentId,\n resourceId,\n requestContext,\n page,\n perPage,\n orderBy,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'resourceId' | 'requestContext'> & {\n page: number;\n perPage: number | false;\n orderBy?: StorageOrderBy;\n}) {\n try {\n const memory = await getMemoryFromContext({ mastra, agentId, requestContext });\n\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n validateBody({ resourceId });\n\n const result = await memory.listThreadsByResourceId({\n resourceId: resourceId!,\n page,\n perPage,\n orderBy,\n });\n return result;\n } catch (error) {\n return handleError(error, 'Error listing threads');\n }\n}\n\nexport async function getThreadByIdHandler({\n mastra,\n agentId,\n threadId,\n requestContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'threadId' | 'requestContext'>) {\n try {\n validateBody({ threadId });\n\n const memory = await getMemoryFromContext({ mastra, agentId, requestContext });\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n const thread = await memory.getThreadById({ threadId: threadId! });\n if (!thread) {\n throw new HTTPException(404, { message: 'Thread not found' });\n }\n\n return thread;\n } catch (error) {\n return handleError(error, 'Error getting thread');\n }\n}\n\nexport async function saveMessagesHandler({\n mastra,\n agentId,\n body,\n requestContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'requestContext'> & {\n body: {\n messages: Parameters<MastraMemory['saveMessages']>[0]['messages'];\n };\n}) {\n try {\n const memory = await getMemoryFromContext({ mastra, agentId, requestContext });\n\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n if (!body?.messages) {\n throw new HTTPException(400, { message: 'Messages are required' });\n }\n\n if (!Array.isArray(body.messages)) {\n throw new HTTPException(400, { message: 'Messages should be an array' });\n }\n\n // Validate that all messages have threadId and resourceId\n const invalidMessages = body.messages.filter(message => !message.threadId || !message.resourceId);\n if (invalidMessages.length > 0) {\n throw new HTTPException(400, {\n message: `All messages must have threadId and resourceId fields. Found ${invalidMessages.length} invalid message(s).`,\n });\n }\n\n const processedMessages = body.messages.map(message => ({\n ...message,\n id: message.id || memory.generateId(),\n createdAt: message.createdAt ? new Date(message.createdAt) : new Date(),\n }));\n\n const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });\n return result;\n } catch (error) {\n return handleError(error, 'Error saving messages');\n }\n}\n\nexport async function createThreadHandler({\n mastra,\n agentId,\n body,\n requestContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'requestContext'> & {\n body?: Omit<Parameters<MastraMemory['createThread']>[0], 'resourceId'> & { resourceId?: string };\n}) {\n try {\n const memory = await getMemoryFromContext({ mastra, agentId, requestContext });\n\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n validateBody({ resourceId: body?.resourceId });\n\n const result = await memory.createThread({\n resourceId: body?.resourceId!,\n title: body?.title,\n metadata: body?.metadata,\n threadId: body?.threadId,\n });\n return result;\n } catch (error) {\n return handleError(error, 'Error saving thread to memory');\n }\n}\n\nexport async function updateThreadHandler({\n mastra,\n agentId,\n threadId,\n body,\n requestContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'threadId' | 'requestContext'> & {\n body?: Parameters<MastraMemory['saveThread']>[0]['thread'];\n}) {\n try {\n const memory = await getMemoryFromContext({ mastra, agentId, requestContext });\n\n if (!body) {\n throw new HTTPException(400, { message: 'Body is required' });\n }\n\n const { title, metadata, resourceId } = body;\n const updatedAt = new Date();\n\n validateBody({ threadId });\n\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n const thread = await memory.getThreadById({ threadId: threadId! });\n if (!thread) {\n throw new HTTPException(404, { message: 'Thread not found' });\n }\n\n const updatedThread = {\n ...thread,\n title: title || thread.title,\n metadata: metadata || thread.metadata,\n resourceId: resourceId || thread.resourceId,\n createdAt: thread.createdAt,\n updatedAt,\n };\n\n const result = await memory.saveThread({ thread: updatedThread });\n return result;\n } catch (error) {\n return handleError(error, 'Error updating thread');\n }\n}\n\nexport async function deleteThreadHandler({\n mastra,\n agentId,\n threadId,\n requestContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'threadId' | 'requestContext'>) {\n try {\n validateBody({ threadId });\n\n const memory = await getMemoryFromContext({ mastra, agentId, requestContext });\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n const thread = await memory.getThreadById({ threadId: threadId! });\n if (!thread) {\n throw new HTTPException(404, { message: 'Thread not found' });\n }\n\n await memory.deleteThread(threadId!);\n return { result: 'Thread deleted' };\n } catch (error) {\n return handleError(error, 'Error deleting thread');\n }\n}\n\nexport async function listMessagesHandler({\n mastra,\n agentId,\n threadId,\n resourceId,\n perPage,\n page,\n orderBy,\n include,\n filter,\n requestContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'threadId' | 'requestContext'> &\n Omit<StorageListMessagesInput, 'threadId'>) {\n try {\n validateBody({ threadId });\n\n const memory = await getMemoryFromContext({ mastra, agentId, requestContext });\n\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n if (!threadId) {\n throw new HTTPException(400, { message: 'No threadId found' });\n }\n\n const thread = await memory.getThreadById({ threadId: threadId });\n if (!thread) {\n throw new HTTPException(404, { message: 'Thread not found' });\n }\n\n const result = await memory.recall({\n threadId: threadId,\n resourceId,\n perPage,\n page,\n orderBy,\n include,\n filter,\n });\n return result;\n } catch (error) {\n return handleError(error, 'Error getting messages');\n }\n}\n\n/**\n * Handler to get the working memory for a thread (optionally resource-scoped).\n * @returns workingMemory - the working memory for the thread\n * @returns source - thread or resource\n */\nexport async function getWorkingMemoryHandler({\n mastra,\n agentId,\n threadId,\n resourceId,\n requestContext,\n memoryConfig,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'threadId' | 'requestContext'> & {\n resourceId?: Parameters<MastraMemory['getWorkingMemory']>[0]['resourceId'];\n memoryConfig?: Parameters<MastraMemory['getWorkingMemory']>[0]['memoryConfig'];\n}) {\n try {\n const memory = await getMemoryFromContext({ mastra, agentId, requestContext });\n validateBody({ threadId });\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n const thread = await memory.getThreadById({ threadId: threadId! });\n const threadExists = !!thread;\n const template = await memory.getWorkingMemoryTemplate({ memoryConfig });\n const workingMemoryTemplate =\n template?.format === 'json'\n ? { ...template, content: JSON.stringify(generateEmptyFromSchema(template.content)) }\n : template;\n const workingMemory = await memory.getWorkingMemory({ threadId: threadId!, resourceId, memoryConfig });\n const config = memory.getMergedThreadConfig(memoryConfig || {});\n const source = config.workingMemory?.scope !== 'thread' && resourceId ? 'resource' : 'thread';\n return { workingMemory, source, workingMemoryTemplate, threadExists };\n } catch (error) {\n return handleError(error, 'Error getting working memory');\n }\n}\n\n/**\n * Handler to update the working memory for a thread (optionally resource-scoped).\n * @param threadId - the thread id\n * @param body - the body containing the working memory to update and the resource id (optional)\n */\nexport async function updateWorkingMemoryHandler({\n mastra,\n agentId,\n threadId,\n body,\n requestContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'threadId' | 'requestContext'> & {\n body: Omit<Parameters<MastraMemory['updateWorkingMemory']>[0], 'threadId'>;\n}) {\n try {\n validateBody({ threadId });\n const memory = await getMemoryFromContext({ mastra, agentId, requestContext });\n const { resourceId, memoryConfig, workingMemory } = body;\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n const thread = await memory.getThreadById({ threadId: threadId! });\n if (!thread) {\n throw new HTTPException(404, { message: 'Thread not found' });\n }\n\n await memory.updateWorkingMemory({ threadId: threadId!, resourceId, workingMemory, memoryConfig });\n return { success: true };\n } catch (error) {\n return handleError(error, 'Error updating working memory');\n }\n}\n\ninterface SearchResult {\n id: string;\n role: string;\n content: any;\n createdAt: Date;\n threadId?: string;\n threadTitle?: string;\n score?: number;\n context?: {\n before?: SearchResult[];\n after?: SearchResult[];\n };\n}\n\ninterface SearchResponse {\n results: SearchResult[];\n count: number;\n query: string;\n searchScope?: string;\n searchType?: string;\n}\n\n/**\n * Handler to delete one or more messages.\n * @param messageIds - Can be a single ID, array of IDs, or objects with ID property\n */\nexport async function deleteMessagesHandler({\n mastra,\n agentId,\n messageIds,\n requestContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'requestContext'> & {\n messageIds: string | string[] | { id: string } | { id: string }[];\n}) {\n try {\n if (messageIds === undefined || messageIds === null) {\n throw new HTTPException(400, { message: 'messageIds is required' });\n }\n\n const memory = await getMemoryFromContext({ mastra, agentId, requestContext });\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n // Delete the messages - let the memory method handle validation\n await memory.deleteMessages(messageIds as any);\n\n // Count messages for response\n let count = 1;\n if (Array.isArray(messageIds)) {\n count = messageIds.length;\n }\n\n return { success: true, message: `${count} message${count === 1 ? '' : 's'} deleted successfully` };\n } catch (error) {\n return handleError(error, 'Error deleting messages');\n }\n}\n\nexport async function searchMemoryHandler({\n mastra,\n agentId,\n searchQuery,\n resourceId,\n threadId,\n limit = 20,\n requestContext,\n memoryConfig,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'requestContext'> & {\n searchQuery: string;\n resourceId: string;\n threadId?: string;\n limit?: number;\n memoryConfig?: any;\n}): Promise<SearchResponse | ReturnType<typeof handleError>> {\n try {\n validateBody({ searchQuery, resourceId });\n\n const memory = await getMemoryFromContext({ mastra, agentId, requestContext });\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n // Get memory configuration first to check scope\n const config = memory.getMergedThreadConfig(memoryConfig || {});\n const hasSemanticRecall = !!config?.semanticRecall;\n const resourceScope =\n typeof config?.semanticRecall === 'object' ? config?.semanticRecall?.scope !== 'thread' : true;\n\n // Only validate thread ownership if we're in thread scope\n if (threadId && !resourceScope) {\n const thread = await memory.getThreadById({ threadId });\n if (!thread) {\n throw new HTTPException(404, { message: 'Thread not found' });\n }\n if (thread.resourceId !== resourceId) {\n throw new HTTPException(403, { message: 'Thread does not belong to the specified resource' });\n }\n }\n\n const searchResults: SearchResult[] = [];\n\n // If threadId is provided and scope is thread-based, check if the thread exists\n if (threadId && !resourceScope) {\n const thread = await memory.getThreadById({ threadId });\n if (!thread) {\n // Thread doesn't exist yet (new unsaved thread) - return empty results\n return {\n results: [],\n count: 0,\n query: searchQuery,\n searchScope: resourceScope ? 'resource' : 'thread',\n searchType: hasSemanticRecall ? 'semantic' : 'text',\n };\n }\n }\n\n // If no threadId provided, get one from the resource\n if (!threadId) {\n const { threads } = await memory.listThreadsByResourceId({\n resourceId,\n page: 0,\n perPage: 1,\n orderBy: { field: 'updatedAt', direction: 'DESC' },\n });\n\n if (threads.length === 0) {\n return {\n results: [],\n count: 0,\n query: searchQuery,\n searchScope: resourceScope ? 'resource' : 'thread',\n searchType: hasSemanticRecall ? 'semantic' : 'text',\n };\n }\n\n // Use first thread - Memory class will handle scope internally\n threadId = threads[0]!.id;\n }\n\n const beforeRange =\n typeof config.semanticRecall === `boolean`\n ? 2\n : typeof config.semanticRecall?.messageRange === `number`\n ? config.semanticRecall.messageRange\n : config.semanticRecall?.messageRange.before || 2;\n const afterRange =\n typeof config.semanticRecall === `boolean`\n ? 2\n : typeof config.semanticRecall?.messageRange === `number`\n ? config.semanticRecall.messageRange\n : config.semanticRecall?.messageRange.after || 2;\n\n if (resourceScope && config.semanticRecall) {\n config.semanticRecall =\n typeof config.semanticRecall === `boolean`\n ? // make message range 0 so we can highlight the matches in search, message range will include other messages, not the matching ones\n // and we add prev/next messages in a special section on each message anyway\n { messageRange: 0, topK: 2, scope: 'resource' }\n : { ...config.semanticRecall, messageRange: 0 };\n }\n\n // Single call to recall - just like the agent does\n // The Memory class handles scope (thread vs resource) internally\n const threadConfig = memory.getMergedThreadConfig(config || {});\n if (!threadConfig.lastMessages && !threadConfig.semanticRecall) {\n return { results: [], count: 0, query: searchQuery };\n }\n\n const result = await memory.recall({\n threadId,\n resourceId,\n perPage: threadConfig.lastMessages,\n threadConfig: config,\n vectorSearchString: threadConfig.semanticRecall && searchQuery ? searchQuery : undefined,\n });\n\n // Get all threads to build context and show which thread each message is from\n // Fetch threads by IDs from the actual messages to avoid truncation\n const threadIds = Array.from(\n new Set(result.messages.map((m: MastraDBMessage) => m.threadId || threadId!).filter(Boolean)),\n );\n const fetched = await Promise.all(threadIds.map((id: string) => memory.getThreadById({ threadId: id })));\n const threadMap = new Map(fetched.filter(Boolean).map(t => [t!.id, t!]));\n\n // Process each message in the results\n for (const msg of result.messages) {\n const content =\n typeof msg.content.content === `string`\n ? msg.content.content\n : msg.content.parts?.map((p: any) => (p.type === 'text' ? p.text : '')).join(' ') || '';\n\n const msgThreadId = msg.threadId || threadId;\n const thread = threadMap.get(msgThreadId);\n\n // Get thread messages for context\n const threadMessages = (await memory.recall({ threadId: msgThreadId })).messages;\n const messageIndex = threadMessages.findIndex(m => m.id === msg.id);\n\n const searchResult: SearchResult = {\n id: msg.id,\n role: msg.role,\n content,\n createdAt: msg.createdAt,\n threadId: msgThreadId,\n threadTitle: thread?.title || msgThreadId,\n };\n\n if (messageIndex !== -1) {\n searchResult.context = {\n before: threadMessages.slice(Math.max(0, messageIndex - beforeRange), messageIndex).map(m => ({\n id: m.id,\n role: m.role,\n content: m.content,\n createdAt: m.createdAt || new Date(),\n })),\n after: threadMessages.slice(messageIndex + 1, messageIndex + afterRange + 1).map(m => ({\n id: m.id,\n role: m.role,\n content: m.content,\n createdAt: m.createdAt || new Date(),\n })),\n };\n }\n\n searchResults.push(searchResult);\n }\n\n // Sort by date (newest first) and limit\n const sortedResults = searchResults\n .sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime())\n .slice(0, limit);\n\n return {\n results: sortedResults,\n count: sortedResults.length,\n query: searchQuery,\n searchScope: resourceScope ? 'resource' : 'thread',\n searchType: hasSemanticRecall ? 'semantic' : 'text',\n };\n } catch (error) {\n return handleError(error, 'Error searching memory');\n }\n}\n"]}
@@ -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;
@@ -19,6 +13,7 @@ var HTTPException = class extends Error {
19
13
  super(options?.message, { cause: options?.cause });
20
14
  this.res = options?.res;
21
15
  this.status = status;
16
+ this.stack = options?.stack || this.stack;
22
17
  }
23
18
  /**
24
19
  * Returns the response object associated with the exception.
@@ -40,4 +35,5 @@ var HTTPException = class extends Error {
40
35
  };
41
36
 
42
37
  exports.HTTPException = HTTPException;
43
- exports.__export = __export;
38
+ //# sourceMappingURL=chunk-64ITUOXI.cjs.map
39
+ //# sourceMappingURL=chunk-64ITUOXI.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server/http-exception.ts"],"names":[],"mappings":";;;AA0GO,IAAM,aAAA,GAAN,cAA4B,KAAA,CAAM;AAAA,EAC9B,GAAA;AAAA,EACA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,WAAA,CAAY,MAAA,GAAqB,GAAA,EAAK,OAAA,EAAgC;AACpE,IAAA,KAAA,CAAM,SAAS,OAAA,EAAS,EAAE,KAAA,EAAO,OAAA,EAAS,OAAO,CAAA;AACjD,IAAA,IAAA,CAAK,MAAM,OAAA,EAAS,GAAA;AACpB,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,KAAA,GAAQ,OAAA,EAAS,KAAA,IAAS,IAAA,CAAK,KAAA;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAA,GAAwB;AACtB,IAAA,IAAI,KAAK,GAAA,EAAK;AACZ,MAAA,MAAM,WAAA,GAAc,IAAI,QAAA,CAAS,IAAA,CAAK,IAAI,IAAA,EAAM;AAAA,QAC9C,QAAQ,IAAA,CAAK,MAAA;AAAA,QACb,OAAA,EAAS,KAAK,GAAA,CAAI;AAAA,OACnB,CAAA;AACD,MAAA,OAAO,WAAA;AAAA,IACT;AACA,IAAA,OAAO,IAAI,QAAA,CAAS,IAAA,CAAK,OAAA,EAAS;AAAA,MAChC,QAAQ,IAAA,CAAK;AAAA,KACd,CAAA;AAAA,EACH;AACF","file":"chunk-64ITUOXI.cjs","sourcesContent":["// Copied from https://github.com/honojs/hono/blob/main/packages/hono/src/http-exception.ts\n\n/**\n * @module\n * This module provides the `HTTPException` class.\n */\n\ntype InfoStatusCode = 100 | 101 | 102 | 103;\ntype SuccessStatusCode = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226;\ntype DeprecatedStatusCode = 305 | 306;\ntype RedirectStatusCode = 300 | 301 | 302 | 303 | 304 | DeprecatedStatusCode | 307 | 308;\ntype ClientErrorStatusCode =\n | 400\n | 401\n | 402\n | 403\n | 404\n | 405\n | 406\n | 407\n | 408\n | 409\n | 410\n | 411\n | 412\n | 413\n | 414\n | 415\n | 416\n | 417\n | 418\n | 421\n | 422\n | 423\n | 424\n | 425\n | 426\n | 428\n | 429\n | 431\n | 451;\ntype ServerErrorStatusCode = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;\n\n/**\n * `UnofficialStatusCode` can be used to specify an unofficial status code.\n * @example\n *\n * ```ts\n * app.get('/unknown', (c) => {\n * return c.text(\"Unknown Error\", 520 as UnofficialStatusCode)\n * })\n * ```\n */\nexport type UnofficialStatusCode = -1;\n\n/**\n * If you want to use an unofficial status, use `UnofficialStatusCode`.\n */\nexport type StatusCode =\n | InfoStatusCode\n | SuccessStatusCode\n | RedirectStatusCode\n | ClientErrorStatusCode\n | ServerErrorStatusCode\n | UnofficialStatusCode;\n\n/**\n * Options for creating an `HTTPException`.\n * @property res - Optional response object to use.\n * @property message - Optional custom error message.\n * @property cause - Optional cause of the error.\n * @property stack - Optional stack trace for the error.\n */\ntype HTTPExceptionOptions = {\n res?: Response;\n message?: string;\n cause?: unknown;\n stack?: string;\n};\n\n/**\n * `HTTPException` must be used when a fatal error such as authentication failure occurs.\n *\n * @see {@link https://hono.dev/docs/api/exception}\n *\n * @param {StatusCode} status - status code of HTTPException\n * @param {HTTPExceptionOptions} options - options of HTTPException\n * @param {HTTPExceptionOptions[\"res\"]} options.res - response of options of HTTPException\n * @param {HTTPExceptionOptions[\"message\"]} options.message - message of options of HTTPException\n * @param {HTTPExceptionOptions[\"cause\"]} options.cause - cause of options of HTTPException\n *\n * @example\n * ```ts\n * import { HTTPException } from 'hono/http-exception'\n *\n * // ...\n *\n * app.post('/auth', async (c, next) => {\n * // authentication\n * if (authorized === false) {\n * throw new HTTPException(401, { message: 'Custom error message' })\n * }\n * await next()\n * })\n * ```\n */\nexport class HTTPException extends Error {\n readonly res?: Response;\n readonly status: StatusCode;\n\n /**\n * Creates an instance of `HTTPException`.\n * @param status - HTTP status code for the exception. Defaults to 500.\n * @param options - Additional options for the exception.\n */\n constructor(status: StatusCode = 500, options?: HTTPExceptionOptions) {\n super(options?.message, { cause: options?.cause });\n this.res = options?.res;\n this.status = status;\n this.stack = options?.stack || this.stack;\n }\n\n /**\n * Returns the response object associated with the exception.\n * If a response object is not provided, a new response is created with the error message and status code.\n * @returns The response object.\n */\n getResponse(): Response {\n if (this.res) {\n const newResponse = new Response(this.res.body, {\n status: this.status,\n headers: this.res.headers,\n });\n return newResponse;\n }\n return new Response(this.message, {\n status: this.status,\n });\n }\n}\n"]}
@@ -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;
@@ -17,6 +11,7 @@ var HTTPException = class extends Error {
17
11
  super(options?.message, { cause: options?.cause });
18
12
  this.res = options?.res;
19
13
  this.status = status;
14
+ this.stack = options?.stack || this.stack;
20
15
  }
21
16
  /**
22
17
  * Returns the response object associated with the exception.
@@ -37,4 +32,6 @@ var HTTPException = class extends Error {
37
32
  }
38
33
  };
39
34
 
40
- export { HTTPException, __export };
35
+ export { HTTPException };
36
+ //# sourceMappingURL=chunk-6QWQZI4Q.js.map
37
+ //# sourceMappingURL=chunk-6QWQZI4Q.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server/http-exception.ts"],"names":[],"mappings":";AA0GO,IAAM,aAAA,GAAN,cAA4B,KAAA,CAAM;AAAA,EAC9B,GAAA;AAAA,EACA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,WAAA,CAAY,MAAA,GAAqB,GAAA,EAAK,OAAA,EAAgC;AACpE,IAAA,KAAA,CAAM,SAAS,OAAA,EAAS,EAAE,KAAA,EAAO,OAAA,EAAS,OAAO,CAAA;AACjD,IAAA,IAAA,CAAK,MAAM,OAAA,EAAS,GAAA;AACpB,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,KAAA,GAAQ,OAAA,EAAS,KAAA,IAAS,IAAA,CAAK,KAAA;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAA,GAAwB;AACtB,IAAA,IAAI,KAAK,GAAA,EAAK;AACZ,MAAA,MAAM,WAAA,GAAc,IAAI,QAAA,CAAS,IAAA,CAAK,IAAI,IAAA,EAAM;AAAA,QAC9C,QAAQ,IAAA,CAAK,MAAA;AAAA,QACb,OAAA,EAAS,KAAK,GAAA,CAAI;AAAA,OACnB,CAAA;AACD,MAAA,OAAO,WAAA;AAAA,IACT;AACA,IAAA,OAAO,IAAI,QAAA,CAAS,IAAA,CAAK,OAAA,EAAS;AAAA,MAChC,QAAQ,IAAA,CAAK;AAAA,KACd,CAAA;AAAA,EACH;AACF","file":"chunk-6QWQZI4Q.js","sourcesContent":["// Copied from https://github.com/honojs/hono/blob/main/packages/hono/src/http-exception.ts\n\n/**\n * @module\n * This module provides the `HTTPException` class.\n */\n\ntype InfoStatusCode = 100 | 101 | 102 | 103;\ntype SuccessStatusCode = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226;\ntype DeprecatedStatusCode = 305 | 306;\ntype RedirectStatusCode = 300 | 301 | 302 | 303 | 304 | DeprecatedStatusCode | 307 | 308;\ntype ClientErrorStatusCode =\n | 400\n | 401\n | 402\n | 403\n | 404\n | 405\n | 406\n | 407\n | 408\n | 409\n | 410\n | 411\n | 412\n | 413\n | 414\n | 415\n | 416\n | 417\n | 418\n | 421\n | 422\n | 423\n | 424\n | 425\n | 426\n | 428\n | 429\n | 431\n | 451;\ntype ServerErrorStatusCode = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;\n\n/**\n * `UnofficialStatusCode` can be used to specify an unofficial status code.\n * @example\n *\n * ```ts\n * app.get('/unknown', (c) => {\n * return c.text(\"Unknown Error\", 520 as UnofficialStatusCode)\n * })\n * ```\n */\nexport type UnofficialStatusCode = -1;\n\n/**\n * If you want to use an unofficial status, use `UnofficialStatusCode`.\n */\nexport type StatusCode =\n | InfoStatusCode\n | SuccessStatusCode\n | RedirectStatusCode\n | ClientErrorStatusCode\n | ServerErrorStatusCode\n | UnofficialStatusCode;\n\n/**\n * Options for creating an `HTTPException`.\n * @property res - Optional response object to use.\n * @property message - Optional custom error message.\n * @property cause - Optional cause of the error.\n * @property stack - Optional stack trace for the error.\n */\ntype HTTPExceptionOptions = {\n res?: Response;\n message?: string;\n cause?: unknown;\n stack?: string;\n};\n\n/**\n * `HTTPException` must be used when a fatal error such as authentication failure occurs.\n *\n * @see {@link https://hono.dev/docs/api/exception}\n *\n * @param {StatusCode} status - status code of HTTPException\n * @param {HTTPExceptionOptions} options - options of HTTPException\n * @param {HTTPExceptionOptions[\"res\"]} options.res - response of options of HTTPException\n * @param {HTTPExceptionOptions[\"message\"]} options.message - message of options of HTTPException\n * @param {HTTPExceptionOptions[\"cause\"]} options.cause - cause of options of HTTPException\n *\n * @example\n * ```ts\n * import { HTTPException } from 'hono/http-exception'\n *\n * // ...\n *\n * app.post('/auth', async (c, next) => {\n * // authentication\n * if (authorized === false) {\n * throw new HTTPException(401, { message: 'Custom error message' })\n * }\n * await next()\n * })\n * ```\n */\nexport class HTTPException extends Error {\n readonly res?: Response;\n readonly status: StatusCode;\n\n /**\n * Creates an instance of `HTTPException`.\n * @param status - HTTP status code for the exception. Defaults to 500.\n * @param options - Additional options for the exception.\n */\n constructor(status: StatusCode = 500, options?: HTTPExceptionOptions) {\n super(options?.message, { cause: options?.cause });\n this.res = options?.res;\n this.status = status;\n this.stack = options?.stack || this.stack;\n }\n\n /**\n * Returns the response object associated with the exception.\n * If a response object is not provided, a new response is created with the error message and status code.\n * @returns The response object.\n */\n getResponse(): Response {\n if (this.res) {\n const newResponse = new Response(this.res.body, {\n status: this.status,\n headers: this.res.headers,\n });\n return newResponse;\n }\n return new Response(this.message, {\n status: this.status,\n });\n }\n}\n"]}