@mastra/server 0.0.0-commonjs-20250414101718 → 0.0.0-custom-instrumentation-20250626084921

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 (87) hide show
  1. package/README.md +48 -135
  2. package/dist/_tsup-dts-rollup.d.cts +544 -62
  3. package/dist/_tsup-dts-rollup.d.ts +544 -62
  4. package/dist/chunk-4DTDPTQC.cjs +332 -0
  5. package/dist/{chunk-4JINXASC.js → chunk-55DOQLP6.js} +5 -4
  6. package/dist/{chunk-QN4KF3BH.cjs → chunk-57CJTIPW.cjs} +2 -2
  7. package/dist/{chunk-ZLBRQFDD.cjs → chunk-64U3UDTH.cjs} +2 -2
  8. package/dist/chunk-75ZPJI57.cjs +9 -0
  9. package/dist/{chunk-CWSDZEZG.cjs → chunk-B4MQFJ7G.cjs} +18 -12
  10. package/dist/{chunk-DVPP5S6I.js → chunk-BFOA2QQY.js} +14 -8
  11. package/dist/{chunk-M56ECCHK.cjs → chunk-BNEY4P4P.cjs} +20 -19
  12. package/dist/{chunk-YANVFOYA.js → chunk-C7564HUT.js} +56 -34
  13. package/dist/{chunk-4C3EPMMF.cjs → chunk-CPPYMJX5.cjs} +31 -25
  14. package/dist/chunk-GHC4YV6R.js +504 -0
  15. package/dist/chunk-GKM45O24.cjs +278 -0
  16. package/dist/{chunk-L7XE5QTW.js → chunk-H5PTF3Y4.js} +1 -1
  17. package/dist/chunk-IMBY5XUG.cjs +86 -0
  18. package/dist/{chunk-3AHQ5RGN.js → chunk-M5ABIP7D.js} +1 -1
  19. package/dist/chunk-MLKGABMK.js +7 -0
  20. package/dist/chunk-MN6F4D5A.cjs +2004 -0
  21. package/dist/{chunk-OPP7H5TW.js → chunk-N2YBMSO2.js} +78 -63
  22. package/dist/{chunk-TRDNDNGQ.js → chunk-NYN7KFXL.js} +1 -7
  23. package/dist/{chunk-FV45V6WC.cjs → chunk-OCWPVYNI.cjs} +0 -7
  24. package/dist/chunk-OSZM4EAY.js +2001 -0
  25. package/dist/chunk-PMUATKV2.js +270 -0
  26. package/dist/chunk-QLG2PFHE.js +81 -0
  27. package/dist/{chunk-3RVHWGWO.js → chunk-R5VGYBV6.js} +36 -19
  28. package/dist/{chunk-2FJURXCL.cjs → chunk-RQ2Z56EC.cjs} +93 -55
  29. package/dist/chunk-SDPGVWQJ.cjs +512 -0
  30. package/dist/chunk-SOBBILUG.js +421 -0
  31. package/dist/chunk-TO5U6HW3.cjs +435 -0
  32. package/dist/chunk-VPNDC2DI.cjs +148 -0
  33. package/dist/chunk-WJY57THV.cjs +118 -0
  34. package/dist/{chunk-YNSGUC2O.js → chunk-XR7VJOOP.js} +14 -8
  35. package/dist/{chunk-RBQASTUP.js → chunk-XUIJ7WRT.js} +63 -25
  36. package/dist/server/handlers/a2a.cjs +30 -0
  37. package/dist/server/handlers/a2a.d.cts +6 -0
  38. package/dist/server/handlers/a2a.d.ts +6 -0
  39. package/dist/server/handlers/a2a.js +1 -0
  40. package/dist/server/handlers/agents.cjs +7 -7
  41. package/dist/server/handlers/agents.js +1 -1
  42. package/dist/server/handlers/error.cjs +2 -2
  43. package/dist/server/handlers/error.js +1 -1
  44. package/dist/server/handlers/legacyWorkflows.cjs +46 -0
  45. package/dist/server/handlers/legacyWorkflows.d.cts +10 -0
  46. package/dist/server/handlers/legacyWorkflows.d.ts +10 -0
  47. package/dist/server/handlers/legacyWorkflows.js +1 -0
  48. package/dist/server/handlers/logs.cjs +4 -4
  49. package/dist/server/handlers/logs.js +1 -1
  50. package/dist/server/handlers/memory.cjs +9 -9
  51. package/dist/server/handlers/memory.js +1 -1
  52. package/dist/server/handlers/network.cjs +5 -5
  53. package/dist/server/handlers/network.js +1 -1
  54. package/dist/server/handlers/telemetry.cjs +3 -3
  55. package/dist/server/handlers/telemetry.js +1 -1
  56. package/dist/server/handlers/tools.cjs +5 -5
  57. package/dist/server/handlers/tools.js +1 -1
  58. package/dist/server/handlers/utils.cjs +2 -2
  59. package/dist/server/handlers/utils.js +1 -1
  60. package/dist/server/handlers/vNextNetwork.cjs +200 -0
  61. package/dist/server/handlers/vNextNetwork.d.cts +6 -0
  62. package/dist/server/handlers/vNextNetwork.d.ts +6 -0
  63. package/dist/server/handlers/vNextNetwork.js +193 -0
  64. package/dist/server/handlers/vector.cjs +7 -7
  65. package/dist/server/handlers/vector.js +1 -1
  66. package/dist/server/handlers/voice.cjs +8 -4
  67. package/dist/server/handlers/voice.d.cts +1 -0
  68. package/dist/server/handlers/voice.d.ts +1 -0
  69. package/dist/server/handlers/voice.js +1 -1
  70. package/dist/server/handlers/workflows.cjs +21 -13
  71. package/dist/server/handlers/workflows.d.cts +4 -2
  72. package/dist/server/handlers/workflows.d.ts +4 -2
  73. package/dist/server/handlers/workflows.js +1 -1
  74. package/dist/server/handlers.cjs +33 -23
  75. package/dist/server/handlers.d.cts +2 -0
  76. package/dist/server/handlers.d.ts +2 -0
  77. package/dist/server/handlers.js +11 -9
  78. package/package.json +13 -12
  79. package/dist/chunk-3EJZQ6TQ.js +0 -49
  80. package/dist/chunk-67WTHYAV.js +0 -156
  81. package/dist/chunk-A7DF4ETD.cjs +0 -100
  82. package/dist/chunk-B64YROKU.cjs +0 -317
  83. package/dist/chunk-JLDXUWK7.cjs +0 -126
  84. package/dist/chunk-QH6XWSXP.cjs +0 -5579
  85. package/dist/chunk-SKBVVI24.cjs +0 -54
  86. package/dist/chunk-VK6FX47H.js +0 -5576
  87. package/dist/chunk-Z46X3YCB.cjs +0 -164
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var chunkQN4KF3BH_cjs = require('./chunk-QN4KF3BH.cjs');
4
- var chunkZLBRQFDD_cjs = require('./chunk-ZLBRQFDD.cjs');
5
- var chunkFV45V6WC_cjs = require('./chunk-FV45V6WC.cjs');
3
+ var chunk57CJTIPW_cjs = require('./chunk-57CJTIPW.cjs');
4
+ var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
5
+ var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
6
+ var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
6
7
 
7
8
  // src/server/handlers/memory.ts
8
9
  var memory_exports = {};
9
- chunkFV45V6WC_cjs.__export(memory_exports, {
10
+ chunk75ZPJI57_cjs.__export(memory_exports, {
10
11
  createThreadHandler: () => createThreadHandler,
11
12
  deleteThreadHandler: () => deleteThreadHandler,
12
13
  getMemoryStatusHandler: () => getMemoryStatusHandler,
@@ -16,80 +17,102 @@ chunkFV45V6WC_cjs.__export(memory_exports, {
16
17
  saveMessagesHandler: () => saveMessagesHandler,
17
18
  updateThreadHandler: () => updateThreadHandler
18
19
  });
19
- function getMemoryFromContext({
20
+ async function getMemoryFromContext({
20
21
  mastra,
21
- agentId
22
+ agentId,
23
+ networkId,
24
+ runtimeContext
22
25
  }) {
23
26
  const agent = agentId ? mastra.getAgent(agentId) : null;
24
27
  if (agentId && !agent) {
25
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Agent not found" });
28
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
29
+ }
30
+ const network = networkId ? mastra.vnext_getNetwork(networkId) : null;
31
+ if (networkId && !network) {
32
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Network not found" });
33
+ }
34
+ if (agent) {
35
+ return agent?.getMemory() || mastra.getMemory();
36
+ }
37
+ if (network) {
38
+ return await network?.getMemory({ runtimeContext }) || mastra.getMemory();
26
39
  }
27
- const memory = agent?.getMemory?.() || mastra.getMemory();
28
- return memory;
40
+ return mastra.getMemory();
29
41
  }
30
- async function getMemoryStatusHandler({ mastra, agentId }) {
42
+ async function getMemoryStatusHandler({
43
+ mastra,
44
+ agentId,
45
+ networkId,
46
+ runtimeContext
47
+ }) {
31
48
  try {
32
- const memory = getMemoryFromContext({ mastra, agentId });
49
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
33
50
  if (!memory) {
34
51
  return { result: false };
35
52
  }
36
53
  return { result: true };
37
54
  } catch (error) {
38
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting memory status");
55
+ return chunk64U3UDTH_cjs.handleError(error, "Error getting memory status");
39
56
  }
40
57
  }
41
58
  async function getThreadsHandler({
42
59
  mastra,
43
60
  agentId,
44
- resourceId
61
+ resourceId,
62
+ networkId,
63
+ runtimeContext
45
64
  }) {
46
65
  try {
47
- const memory = getMemoryFromContext({ mastra, agentId });
66
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
48
67
  if (!memory) {
49
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
68
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
50
69
  }
51
- chunkQN4KF3BH_cjs.validateBody({ resourceId });
70
+ chunk57CJTIPW_cjs.validateBody({ resourceId });
52
71
  const threads = await memory.getThreadsByResourceId({ resourceId });
53
72
  return threads;
54
73
  } catch (error) {
55
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting threads");
74
+ return chunk64U3UDTH_cjs.handleError(error, "Error getting threads");
56
75
  }
57
76
  }
58
77
  async function getThreadByIdHandler({
59
78
  mastra,
60
79
  agentId,
61
- threadId
80
+ threadId,
81
+ networkId,
82
+ runtimeContext
62
83
  }) {
63
84
  try {
64
- chunkQN4KF3BH_cjs.validateBody({ threadId });
65
- const memory = getMemoryFromContext({ mastra, agentId });
85
+ chunk57CJTIPW_cjs.validateBody({ threadId });
86
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
66
87
  if (!memory) {
67
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
88
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
68
89
  }
69
90
  const thread = await memory.getThreadById({ threadId });
70
91
  if (!thread) {
71
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Thread not found" });
92
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
72
93
  }
73
94
  return thread;
74
95
  } catch (error) {
75
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting thread");
96
+ return chunk64U3UDTH_cjs.handleError(error, "Error getting thread");
76
97
  }
77
98
  }
78
99
  async function saveMessagesHandler({
79
100
  mastra,
80
101
  agentId,
81
- body
102
+ body,
103
+ networkId,
104
+ runtimeContext
82
105
  }) {
83
106
  try {
84
- const memory = getMemoryFromContext({ mastra, agentId });
107
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
85
108
  if (!memory) {
86
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
109
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
87
110
  }
88
111
  if (!body?.messages) {
89
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Messages are required" });
112
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Messages are required" });
90
113
  }
91
114
  if (!Array.isArray(body.messages)) {
92
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Messages should be an array" });
115
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Messages should be an array" });
93
116
  }
94
117
  const processedMessages = body.messages.map((message) => ({
95
118
  ...message,
@@ -99,20 +122,22 @@ async function saveMessagesHandler({
99
122
  const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });
100
123
  return result;
101
124
  } catch (error) {
102
- return chunkZLBRQFDD_cjs.handleError(error, "Error saving messages");
125
+ return chunk64U3UDTH_cjs.handleError(error, "Error saving messages");
103
126
  }
104
127
  }
105
128
  async function createThreadHandler({
106
129
  mastra,
107
130
  agentId,
108
- body
131
+ body,
132
+ networkId,
133
+ runtimeContext
109
134
  }) {
110
135
  try {
111
- const memory = getMemoryFromContext({ mastra, agentId });
136
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
112
137
  if (!memory) {
113
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
138
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
114
139
  }
115
- chunkQN4KF3BH_cjs.validateBody({ resourceId: body?.resourceId });
140
+ chunk57CJTIPW_cjs.validateBody({ resourceId: body?.resourceId });
116
141
  const result = await memory.createThread({
117
142
  resourceId: body?.resourceId,
118
143
  title: body?.title,
@@ -121,29 +146,31 @@ async function createThreadHandler({
121
146
  });
122
147
  return result;
123
148
  } catch (error) {
124
- return chunkZLBRQFDD_cjs.handleError(error, "Error saving thread to memory");
149
+ return chunk64U3UDTH_cjs.handleError(error, "Error saving thread to memory");
125
150
  }
126
151
  }
127
152
  async function updateThreadHandler({
128
153
  mastra,
129
154
  agentId,
130
155
  threadId,
131
- body
156
+ body,
157
+ networkId,
158
+ runtimeContext
132
159
  }) {
133
160
  try {
134
- const memory = getMemoryFromContext({ mastra, agentId });
161
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
135
162
  if (!body) {
136
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Body is required" });
163
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Body is required" });
137
164
  }
138
165
  const { title, metadata, resourceId } = body;
139
166
  const updatedAt = /* @__PURE__ */ new Date();
140
- chunkQN4KF3BH_cjs.validateBody({ threadId });
167
+ chunk57CJTIPW_cjs.validateBody({ threadId });
141
168
  if (!memory) {
142
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
169
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
143
170
  }
144
171
  const thread = await memory.getThreadById({ threadId });
145
172
  if (!thread) {
146
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Thread not found" });
173
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
147
174
  }
148
175
  const updatedThread = {
149
176
  ...thread,
@@ -156,49 +183,60 @@ async function updateThreadHandler({
156
183
  const result = await memory.saveThread({ thread: updatedThread });
157
184
  return result;
158
185
  } catch (error) {
159
- return chunkZLBRQFDD_cjs.handleError(error, "Error updating thread");
186
+ return chunk64U3UDTH_cjs.handleError(error, "Error updating thread");
160
187
  }
161
188
  }
162
189
  async function deleteThreadHandler({
163
190
  mastra,
164
191
  agentId,
165
- threadId
192
+ threadId,
193
+ networkId,
194
+ runtimeContext
166
195
  }) {
167
196
  try {
168
- chunkQN4KF3BH_cjs.validateBody({ threadId });
169
- const memory = getMemoryFromContext({ mastra, agentId });
197
+ chunk57CJTIPW_cjs.validateBody({ threadId });
198
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
170
199
  if (!memory) {
171
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
200
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
172
201
  }
173
202
  const thread = await memory.getThreadById({ threadId });
174
203
  if (!thread) {
175
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Thread not found" });
204
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
176
205
  }
177
206
  await memory.deleteThread(threadId);
178
207
  return { result: "Thread deleted" };
179
208
  } catch (error) {
180
- return chunkZLBRQFDD_cjs.handleError(error, "Error deleting thread");
209
+ return chunk64U3UDTH_cjs.handleError(error, "Error deleting thread");
181
210
  }
182
211
  }
183
212
  async function getMessagesHandler({
184
213
  mastra,
185
214
  agentId,
186
- threadId
215
+ threadId,
216
+ limit,
217
+ networkId,
218
+ runtimeContext
187
219
  }) {
220
+ if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
221
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Invalid limit: must be a positive integer" });
222
+ }
188
223
  try {
189
- chunkQN4KF3BH_cjs.validateBody({ threadId });
190
- const memory = getMemoryFromContext({ mastra, agentId });
224
+ chunk57CJTIPW_cjs.validateBody({ threadId });
225
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
191
226
  if (!memory) {
192
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
227
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
193
228
  }
194
229
  const thread = await memory.getThreadById({ threadId });
195
230
  if (!thread) {
196
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Thread not found" });
231
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
197
232
  }
198
- const result = await memory.query({ threadId });
199
- return result;
233
+ const result = await memory.query({
234
+ threadId,
235
+ ...limit && { selectBy: { last: limit } }
236
+ });
237
+ return { messages: result.messages, uiMessages: result.uiMessages };
200
238
  } catch (error) {
201
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting messages");
239
+ return chunk64U3UDTH_cjs.handleError(error, "Error getting messages");
202
240
  }
203
241
  }
204
242