@mastra/server 0.0.0-separate-trace-data-from-component-20250501042644 → 0.0.0-support-d1-client-20250701191943

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 (91) hide show
  1. package/README.md +48 -135
  2. package/dist/_tsup-dts-rollup.d.cts +517 -103
  3. package/dist/_tsup-dts-rollup.d.ts +517 -103
  4. package/dist/{chunk-2FJURXCL.cjs → chunk-3DKDT264.cjs} +93 -55
  5. package/dist/{chunk-Y3SV5XK4.js → chunk-4QBIUKVY.js} +105 -16
  6. package/dist/{chunk-QN4KF3BH.cjs → chunk-57CJTIPW.cjs} +2 -2
  7. package/dist/chunk-7524QH7G.cjs +483 -0
  8. package/dist/chunk-75ZPJI57.cjs +9 -0
  9. package/dist/{chunk-M3YJLWTU.js → chunk-7GQJAMTA.js} +68 -57
  10. package/dist/chunk-BOXE6WSV.js +81 -0
  11. package/dist/{chunk-WTHDCRMY.js → chunk-BP24Z4WG.js} +12 -6
  12. package/dist/chunk-BWHGBV3K.cjs +278 -0
  13. package/dist/chunk-CNVDCLSY.cjs +86 -0
  14. package/dist/{chunk-5JNVY6DU.js → chunk-DFJUGWNU.js} +7 -5
  15. package/dist/{chunk-5YGDYMRB.cjs → chunk-DPRB3R7Y.cjs} +14 -13
  16. package/dist/{chunk-D3G23FP3.cjs → chunk-FGGMQCPP.cjs} +24 -22
  17. package/dist/{chunk-4JINXASC.js → chunk-FVMGZKFD.js} +5 -4
  18. package/dist/{chunk-Q6SHQECN.js → chunk-G37NVEDX.js} +34 -10
  19. package/dist/chunk-GHC4YV6R.js +504 -0
  20. package/dist/{chunk-L7XE5QTW.js → chunk-H5PTF3Y4.js} +1 -1
  21. package/dist/chunk-L3N7ST2Z.cjs +118 -0
  22. package/dist/chunk-LI436ITD.cjs +2042 -0
  23. package/dist/{chunk-RBQASTUP.js → chunk-LTJNMM2Y.js} +63 -25
  24. package/dist/chunk-MEGCYGBU.js +2039 -0
  25. package/dist/chunk-MLKGABMK.js +7 -0
  26. package/dist/{chunk-ZLBRQFDD.cjs → chunk-MTR2B27E.cjs} +3 -2
  27. package/dist/{chunk-TRDNDNGQ.js → chunk-NYN7KFXL.js} +1 -7
  28. package/dist/{chunk-FV45V6WC.cjs → chunk-OCWPVYNI.cjs} +0 -7
  29. package/dist/{chunk-3AHQ5RGN.js → chunk-QDOJJCS4.js} +3 -2
  30. package/dist/chunk-SDPGVWQJ.cjs +512 -0
  31. package/dist/chunk-TGZIR6AK.cjs +332 -0
  32. package/dist/{chunk-M56ECCHK.cjs → chunk-TVBPFPTN.cjs} +20 -19
  33. package/dist/{chunk-7IWQE76Z.cjs → chunk-ULFULEW4.cjs} +16 -10
  34. package/dist/{chunk-QJ3AHN64.js → chunk-VMXLEF54.js} +4 -3
  35. package/dist/chunk-Z5TH5F35.js +468 -0
  36. package/dist/server/handlers/a2a.cjs +30 -0
  37. package/dist/server/handlers/a2a.d.cts +6 -0
  38. package/dist/server/handlers/a2a.d.ts +6 -0
  39. package/dist/server/handlers/a2a.js +1 -0
  40. package/dist/server/handlers/agents.cjs +7 -7
  41. package/dist/server/handlers/agents.js +1 -1
  42. package/dist/server/handlers/error.cjs +2 -2
  43. package/dist/server/handlers/error.js +1 -1
  44. package/dist/server/handlers/legacyWorkflows.cjs +46 -0
  45. package/dist/server/handlers/legacyWorkflows.d.cts +10 -0
  46. package/dist/server/handlers/legacyWorkflows.d.ts +10 -0
  47. package/dist/server/handlers/legacyWorkflows.js +1 -0
  48. package/dist/server/handlers/logs.cjs +4 -4
  49. package/dist/server/handlers/logs.js +1 -1
  50. package/dist/server/handlers/memory.cjs +9 -9
  51. package/dist/server/handlers/memory.js +1 -1
  52. package/dist/server/handlers/network.cjs +5 -5
  53. package/dist/server/handlers/network.js +1 -1
  54. package/dist/server/handlers/telemetry.cjs +3 -3
  55. package/dist/server/handlers/telemetry.js +1 -1
  56. package/dist/server/handlers/tools.cjs +5 -5
  57. package/dist/server/handlers/tools.js +1 -1
  58. package/dist/server/handlers/utils.cjs +2 -2
  59. package/dist/server/handlers/utils.js +1 -1
  60. package/dist/server/handlers/vNextNetwork.cjs +218 -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 +211 -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 +25 -13
  71. package/dist/server/handlers/workflows.d.cts +5 -2
  72. package/dist/server/handlers/workflows.d.ts +5 -2
  73. package/dist/server/handlers/workflows.js +1 -1
  74. package/dist/server/handlers.cjs +32 -27
  75. package/dist/server/handlers.d.cts +2 -1
  76. package/dist/server/handlers.d.ts +2 -1
  77. package/dist/server/handlers.js +11 -10
  78. package/package.json +14 -13
  79. package/dist/chunk-3EJZQ6TQ.js +0 -49
  80. package/dist/chunk-4BIX6GMY.cjs +0 -189
  81. package/dist/chunk-55HTWX4C.cjs +0 -93
  82. package/dist/chunk-5SWCVTNL.cjs +0 -5579
  83. package/dist/chunk-AELYAUEE.cjs +0 -316
  84. package/dist/chunk-EVCC233P.cjs +0 -321
  85. package/dist/chunk-JPB6RPGB.js +0 -304
  86. package/dist/chunk-OMN3UI6X.js +0 -5576
  87. package/dist/chunk-SKBVVI24.cjs +0 -54
  88. package/dist/server/handlers/vNextWorkflows.cjs +0 -46
  89. package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
  90. package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
  91. package/dist/server/handlers/vNextWorkflows.js +0 -1
@@ -1,6 +1,7 @@
1
- import { validateBody } from './chunk-L7XE5QTW.js';
2
- import { handleError } from './chunk-3AHQ5RGN.js';
3
- import { __export, HTTPException } from './chunk-TRDNDNGQ.js';
1
+ import { validateBody } from './chunk-H5PTF3Y4.js';
2
+ import { handleError } from './chunk-QDOJJCS4.js';
3
+ import { HTTPException } from './chunk-NYN7KFXL.js';
4
+ import { __export } from './chunk-MLKGABMK.js';
4
5
 
5
6
  // src/server/handlers/memory.ts
6
7
  var memory_exports = {};
@@ -14,20 +15,36 @@ __export(memory_exports, {
14
15
  saveMessagesHandler: () => saveMessagesHandler,
15
16
  updateThreadHandler: () => updateThreadHandler
16
17
  });
17
- function getMemoryFromContext({
18
+ async function getMemoryFromContext({
18
19
  mastra,
19
- agentId
20
+ agentId,
21
+ networkId,
22
+ runtimeContext
20
23
  }) {
21
24
  const agent = agentId ? mastra.getAgent(agentId) : null;
22
25
  if (agentId && !agent) {
23
26
  throw new HTTPException(404, { message: "Agent not found" });
24
27
  }
25
- const memory = agent?.getMemory?.() || mastra.getMemory();
26
- return memory;
28
+ const network = networkId ? mastra.vnext_getNetwork(networkId) : null;
29
+ if (networkId && !network) {
30
+ throw new HTTPException(404, { message: "Network not found" });
31
+ }
32
+ if (agent) {
33
+ return agent?.getMemory() || mastra.getMemory();
34
+ }
35
+ if (network) {
36
+ return await network?.getMemory({ runtimeContext }) || mastra.getMemory();
37
+ }
38
+ return mastra.getMemory();
27
39
  }
28
- async function getMemoryStatusHandler({ mastra, agentId }) {
40
+ async function getMemoryStatusHandler({
41
+ mastra,
42
+ agentId,
43
+ networkId,
44
+ runtimeContext
45
+ }) {
29
46
  try {
30
- const memory = getMemoryFromContext({ mastra, agentId });
47
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
31
48
  if (!memory) {
32
49
  return { result: false };
33
50
  }
@@ -39,10 +56,12 @@ async function getMemoryStatusHandler({ mastra, agentId }) {
39
56
  async function getThreadsHandler({
40
57
  mastra,
41
58
  agentId,
42
- resourceId
59
+ resourceId,
60
+ networkId,
61
+ runtimeContext
43
62
  }) {
44
63
  try {
45
- const memory = getMemoryFromContext({ mastra, agentId });
64
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
46
65
  if (!memory) {
47
66
  throw new HTTPException(400, { message: "Memory is not initialized" });
48
67
  }
@@ -56,11 +75,13 @@ async function getThreadsHandler({
56
75
  async function getThreadByIdHandler({
57
76
  mastra,
58
77
  agentId,
59
- threadId
78
+ threadId,
79
+ networkId,
80
+ runtimeContext
60
81
  }) {
61
82
  try {
62
83
  validateBody({ threadId });
63
- const memory = getMemoryFromContext({ mastra, agentId });
84
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
64
85
  if (!memory) {
65
86
  throw new HTTPException(400, { message: "Memory is not initialized" });
66
87
  }
@@ -76,10 +97,12 @@ async function getThreadByIdHandler({
76
97
  async function saveMessagesHandler({
77
98
  mastra,
78
99
  agentId,
79
- body
100
+ body,
101
+ networkId,
102
+ runtimeContext
80
103
  }) {
81
104
  try {
82
- const memory = getMemoryFromContext({ mastra, agentId });
105
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
83
106
  if (!memory) {
84
107
  throw new HTTPException(400, { message: "Memory is not initialized" });
85
108
  }
@@ -103,10 +126,12 @@ async function saveMessagesHandler({
103
126
  async function createThreadHandler({
104
127
  mastra,
105
128
  agentId,
106
- body
129
+ body,
130
+ networkId,
131
+ runtimeContext
107
132
  }) {
108
133
  try {
109
- const memory = getMemoryFromContext({ mastra, agentId });
134
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
110
135
  if (!memory) {
111
136
  throw new HTTPException(400, { message: "Memory is not initialized" });
112
137
  }
@@ -126,10 +151,12 @@ async function updateThreadHandler({
126
151
  mastra,
127
152
  agentId,
128
153
  threadId,
129
- body
154
+ body,
155
+ networkId,
156
+ runtimeContext
130
157
  }) {
131
158
  try {
132
- const memory = getMemoryFromContext({ mastra, agentId });
159
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
133
160
  if (!body) {
134
161
  throw new HTTPException(400, { message: "Body is required" });
135
162
  }
@@ -160,11 +187,13 @@ async function updateThreadHandler({
160
187
  async function deleteThreadHandler({
161
188
  mastra,
162
189
  agentId,
163
- threadId
190
+ threadId,
191
+ networkId,
192
+ runtimeContext
164
193
  }) {
165
194
  try {
166
195
  validateBody({ threadId });
167
- const memory = getMemoryFromContext({ mastra, agentId });
196
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
168
197
  if (!memory) {
169
198
  throw new HTTPException(400, { message: "Memory is not initialized" });
170
199
  }
@@ -181,11 +210,17 @@ async function deleteThreadHandler({
181
210
  async function getMessagesHandler({
182
211
  mastra,
183
212
  agentId,
184
- threadId
213
+ threadId,
214
+ limit,
215
+ networkId,
216
+ runtimeContext
185
217
  }) {
218
+ if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
219
+ throw new HTTPException(400, { message: "Invalid limit: must be a positive integer" });
220
+ }
186
221
  try {
187
222
  validateBody({ threadId });
188
- const memory = getMemoryFromContext({ mastra, agentId });
223
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
189
224
  if (!memory) {
190
225
  throw new HTTPException(400, { message: "Memory is not initialized" });
191
226
  }
@@ -193,8 +228,11 @@ async function getMessagesHandler({
193
228
  if (!thread) {
194
229
  throw new HTTPException(404, { message: "Thread not found" });
195
230
  }
196
- const result = await memory.query({ threadId });
197
- return result;
231
+ const result = await memory.query({
232
+ threadId,
233
+ ...limit && { selectBy: { last: limit } }
234
+ });
235
+ return { messages: result.messages, uiMessages: result.uiMessages };
198
236
  } catch (error) {
199
237
  return handleError(error, "Error getting messages");
200
238
  }