@mastra/server 0.0.0-separate-trace-data-from-component-20250501141108 → 0.0.0-share-agent-metadata-with-cloud-20250718123411

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 (97) hide show
  1. package/LICENSE.md +11 -42
  2. package/README.md +48 -135
  3. package/dist/_tsup-dts-rollup.d.cts +556 -103
  4. package/dist/_tsup-dts-rollup.d.ts +556 -103
  5. package/dist/{chunk-FV45V6WC.cjs → chunk-2KZFMI6P.cjs} +1 -7
  6. package/dist/{chunk-5YGDYMRB.cjs → chunk-2SLFAFTR.cjs} +14 -13
  7. package/dist/chunk-3CNDE7QY.cjs +308 -0
  8. package/dist/chunk-4D66QEKC.js +81 -0
  9. package/dist/{chunk-M3YJLWTU.js → chunk-5PQQ42EZ.js} +68 -57
  10. package/dist/chunk-75ZPJI57.cjs +9 -0
  11. package/dist/{chunk-M56ECCHK.cjs → chunk-7TP2LX5L.cjs} +20 -19
  12. package/dist/chunk-B2PAS2IB.cjs +514 -0
  13. package/dist/{chunk-Y3SV5XK4.js → chunk-BK4XT6EG.js} +105 -16
  14. package/dist/{chunk-QN4KF3BH.cjs → chunk-CCGRCYWJ.cjs} +2 -2
  15. package/dist/{chunk-QJ3AHN64.js → chunk-CRCR3ZUK.js} +4 -3
  16. package/dist/{chunk-D3G23FP3.cjs → chunk-FRVBFMO2.cjs} +24 -22
  17. package/dist/{chunk-7IWQE76Z.cjs → chunk-G7KH752Y.cjs} +16 -10
  18. package/dist/chunk-GHC4YV6R.js +504 -0
  19. package/dist/chunk-H7DMHBKY.js +498 -0
  20. package/dist/chunk-JMLYCXMK.cjs +332 -0
  21. package/dist/{chunk-Q6SHQECN.js → chunk-KHZKYUNR.js} +34 -10
  22. package/dist/{chunk-RBQASTUP.js → chunk-KOHWJYJT.js} +120 -27
  23. package/dist/{chunk-TRDNDNGQ.js → chunk-LCM566I4.js} +2 -7
  24. package/dist/chunk-LF7P5PLR.js +14 -0
  25. package/dist/chunk-LI436ITD.cjs +2042 -0
  26. package/dist/{chunk-5JNVY6DU.js → chunk-LRCAAFUA.js} +7 -5
  27. package/dist/chunk-LZ3VJXSO.cjs +278 -0
  28. package/dist/chunk-MEGCYGBU.js +2039 -0
  29. package/dist/chunk-MLKGABMK.js +7 -0
  30. package/dist/chunk-PZQDCRPV.cjs +16 -0
  31. package/dist/chunk-QGX47B5D.cjs +86 -0
  32. package/dist/{chunk-WTHDCRMY.js → chunk-RG473F6Y.js} +12 -6
  33. package/dist/chunk-RHSWAXKB.cjs +118 -0
  34. package/dist/{chunk-L7XE5QTW.js → chunk-RSEO4XPX.js} +1 -1
  35. package/dist/chunk-SDPGVWQJ.cjs +512 -0
  36. package/dist/{chunk-4JINXASC.js → chunk-WNVFNNWN.js} +5 -4
  37. package/dist/server/handlers/a2a.cjs +30 -0
  38. package/dist/server/handlers/a2a.d.cts +6 -0
  39. package/dist/server/handlers/a2a.d.ts +6 -0
  40. package/dist/server/handlers/a2a.js +1 -0
  41. package/dist/server/handlers/agents.cjs +7 -7
  42. package/dist/server/handlers/agents.js +1 -1
  43. package/dist/server/handlers/error.cjs +2 -2
  44. package/dist/server/handlers/error.js +1 -1
  45. package/dist/server/handlers/legacyWorkflows.cjs +46 -0
  46. package/dist/server/handlers/legacyWorkflows.d.cts +10 -0
  47. package/dist/server/handlers/legacyWorkflows.d.ts +10 -0
  48. package/dist/server/handlers/legacyWorkflows.js +1 -0
  49. package/dist/server/handlers/logs.cjs +4 -4
  50. package/dist/server/handlers/logs.js +1 -1
  51. package/dist/server/handlers/memory.cjs +17 -9
  52. package/dist/server/handlers/memory.d.cts +2 -0
  53. package/dist/server/handlers/memory.d.ts +2 -0
  54. package/dist/server/handlers/memory.js +1 -1
  55. package/dist/server/handlers/network.cjs +5 -5
  56. package/dist/server/handlers/network.js +1 -1
  57. package/dist/server/handlers/telemetry.cjs +3 -3
  58. package/dist/server/handlers/telemetry.js +1 -1
  59. package/dist/server/handlers/tools.cjs +5 -5
  60. package/dist/server/handlers/tools.js +1 -1
  61. package/dist/server/handlers/utils.cjs +2 -2
  62. package/dist/server/handlers/utils.js +1 -1
  63. package/dist/server/handlers/vNextNetwork.cjs +218 -0
  64. package/dist/server/handlers/vNextNetwork.d.cts +6 -0
  65. package/dist/server/handlers/vNextNetwork.d.ts +6 -0
  66. package/dist/server/handlers/vNextNetwork.js +211 -0
  67. package/dist/server/handlers/vector.cjs +7 -7
  68. package/dist/server/handlers/vector.js +1 -1
  69. package/dist/server/handlers/voice.cjs +8 -4
  70. package/dist/server/handlers/voice.d.cts +1 -0
  71. package/dist/server/handlers/voice.d.ts +1 -0
  72. package/dist/server/handlers/voice.js +1 -1
  73. package/dist/server/handlers/workflows.cjs +29 -13
  74. package/dist/server/handlers/workflows.d.cts +6 -2
  75. package/dist/server/handlers/workflows.d.ts +6 -2
  76. package/dist/server/handlers/workflows.js +1 -1
  77. package/dist/server/handlers.cjs +32 -27
  78. package/dist/server/handlers.d.cts +2 -1
  79. package/dist/server/handlers.d.ts +2 -1
  80. package/dist/server/handlers.js +11 -10
  81. package/package.json +15 -14
  82. package/dist/chunk-2FJURXCL.cjs +0 -213
  83. package/dist/chunk-3AHQ5RGN.js +0 -11
  84. package/dist/chunk-3EJZQ6TQ.js +0 -49
  85. package/dist/chunk-4BIX6GMY.cjs +0 -189
  86. package/dist/chunk-55HTWX4C.cjs +0 -93
  87. package/dist/chunk-5SWCVTNL.cjs +0 -5579
  88. package/dist/chunk-AELYAUEE.cjs +0 -316
  89. package/dist/chunk-EVCC233P.cjs +0 -321
  90. package/dist/chunk-JPB6RPGB.js +0 -304
  91. package/dist/chunk-OMN3UI6X.js +0 -5576
  92. package/dist/chunk-SKBVVI24.cjs +0 -54
  93. package/dist/chunk-ZLBRQFDD.cjs +0 -13
  94. package/dist/server/handlers/vNextWorkflows.cjs +0 -46
  95. package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
  96. package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
  97. package/dist/server/handlers/vNextWorkflows.js +0 -1
@@ -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,3 @@ var HTTPException = class extends Error {
40
35
  };
41
36
 
42
37
  exports.HTTPException = HTTPException;
43
- exports.__export = __export;
@@ -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 chunkCCGRCYWJ_cjs = require('./chunk-CCGRCYWJ.cjs');
4
+ var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
5
+ var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
6
+ var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
6
7
 
7
8
  // src/server/handlers/network.ts
8
9
  var network_exports = {};
9
- chunkFV45V6WC_cjs.__export(network_exports, {
10
+ chunk75ZPJI57_cjs.__export(network_exports, {
10
11
  generateHandler: () => generateHandler,
11
12
  getNetworkByIdHandler: () => getNetworkByIdHandler,
12
13
  getNetworksHandler: () => getNetworksHandler,
@@ -46,7 +47,7 @@ async function getNetworksHandler({
46
47
  );
47
48
  return serializedNetworks;
48
49
  } catch (error) {
49
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting networks");
50
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting networks");
50
51
  }
51
52
  }
52
53
  async function getNetworkByIdHandler({
@@ -61,7 +62,7 @@ async function getNetworkByIdHandler({
61
62
  return network2.formatAgentId(routingAgent2.name) === networkId;
62
63
  });
63
64
  if (!network) {
64
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Network not found" });
65
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Network not found" });
65
66
  }
66
67
  const routingAgent = network.getRoutingAgent();
67
68
  const routingLLM = await routingAgent.getLLM({ runtimeContext });
@@ -87,7 +88,7 @@ async function getNetworkByIdHandler({
87
88
  };
88
89
  return serializedNetwork;
89
90
  } catch (error) {
90
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting network by ID");
91
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting network by ID");
91
92
  }
92
93
  }
93
94
  async function generateHandler({
@@ -99,14 +100,14 @@ async function generateHandler({
99
100
  try {
100
101
  const network = mastra.getNetwork(networkId);
101
102
  if (!network) {
102
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Network not found" });
103
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Network not found" });
103
104
  }
104
- chunkQN4KF3BH_cjs.validateBody({ messages: body.messages });
105
+ chunkCCGRCYWJ_cjs.validateBody({ messages: body.messages });
105
106
  const { messages, ...rest } = body;
106
107
  const result = await network.generate(messages, { ...rest, runtimeContext });
107
108
  return result;
108
109
  } catch (error) {
109
- return chunkZLBRQFDD_cjs.handleError(error, "Error generating from network");
110
+ return chunkPZQDCRPV_cjs.handleError(error, "Error generating from network");
110
111
  }
111
112
  }
112
113
  async function streamGenerateHandler({
@@ -118,9 +119,9 @@ async function streamGenerateHandler({
118
119
  try {
119
120
  const network = mastra.getNetwork(networkId);
120
121
  if (!network) {
121
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Network not found" });
122
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Network not found" });
122
123
  }
123
- chunkQN4KF3BH_cjs.validateBody({ messages: body.messages });
124
+ chunkCCGRCYWJ_cjs.validateBody({ messages: body.messages });
124
125
  const { messages, output, ...rest } = body;
125
126
  const streamResult = await network.stream(messages, {
126
127
  output,
@@ -136,7 +137,7 @@ async function streamGenerateHandler({
136
137
  });
137
138
  return streamResponse;
138
139
  } catch (error) {
139
- return chunkZLBRQFDD_cjs.handleError(error, "Error streaming from network");
140
+ return chunkPZQDCRPV_cjs.handleError(error, "Error streaming from network");
140
141
  }
141
142
  }
142
143
 
@@ -0,0 +1,308 @@
1
+ 'use strict';
2
+
3
+ var chunkCCGRCYWJ_cjs = require('./chunk-CCGRCYWJ.cjs');
4
+ var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
5
+ var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
6
+ var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
7
+ var core = require('@mastra/core');
8
+
9
+ // src/server/handlers/memory.ts
10
+ var memory_exports = {};
11
+ chunk75ZPJI57_cjs.__export(memory_exports, {
12
+ createThreadHandler: () => createThreadHandler,
13
+ deleteThreadHandler: () => deleteThreadHandler,
14
+ getMemoryStatusHandler: () => getMemoryStatusHandler,
15
+ getMessagesHandler: () => getMessagesHandler,
16
+ getThreadByIdHandler: () => getThreadByIdHandler,
17
+ getThreadsHandler: () => getThreadsHandler,
18
+ getWorkingMemoryHandler: () => getWorkingMemoryHandler,
19
+ saveMessagesHandler: () => saveMessagesHandler,
20
+ updateThreadHandler: () => updateThreadHandler,
21
+ updateWorkingMemoryHandler: () => updateWorkingMemoryHandler
22
+ });
23
+ async function getMemoryFromContext({
24
+ mastra,
25
+ agentId,
26
+ networkId,
27
+ runtimeContext
28
+ }) {
29
+ const agent = agentId ? mastra.getAgent(agentId) : null;
30
+ if (agentId && !agent) {
31
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Agent not found" });
32
+ }
33
+ const network = networkId ? mastra.vnext_getNetwork(networkId) : null;
34
+ if (networkId && !network) {
35
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Network not found" });
36
+ }
37
+ if (agent) {
38
+ return agent?.getMemory() || mastra.getMemory();
39
+ }
40
+ if (network) {
41
+ return await network?.getMemory({ runtimeContext }) || mastra.getMemory();
42
+ }
43
+ return mastra.getMemory();
44
+ }
45
+ async function getMemoryStatusHandler({
46
+ mastra,
47
+ agentId,
48
+ networkId,
49
+ runtimeContext
50
+ }) {
51
+ try {
52
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
53
+ if (!memory) {
54
+ return { result: false };
55
+ }
56
+ return { result: true };
57
+ } catch (error) {
58
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting memory status");
59
+ }
60
+ }
61
+ async function getThreadsHandler({
62
+ mastra,
63
+ agentId,
64
+ resourceId,
65
+ networkId,
66
+ runtimeContext
67
+ }) {
68
+ try {
69
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
70
+ if (!memory) {
71
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
72
+ }
73
+ chunkCCGRCYWJ_cjs.validateBody({ resourceId });
74
+ const threads = await memory.getThreadsByResourceId({ resourceId });
75
+ return threads;
76
+ } catch (error) {
77
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting threads");
78
+ }
79
+ }
80
+ async function getThreadByIdHandler({
81
+ mastra,
82
+ agentId,
83
+ threadId,
84
+ networkId,
85
+ runtimeContext
86
+ }) {
87
+ try {
88
+ chunkCCGRCYWJ_cjs.validateBody({ threadId });
89
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
90
+ if (!memory) {
91
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
92
+ }
93
+ const thread = await memory.getThreadById({ threadId });
94
+ if (!thread) {
95
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Thread not found" });
96
+ }
97
+ return thread;
98
+ } catch (error) {
99
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting thread");
100
+ }
101
+ }
102
+ async function saveMessagesHandler({
103
+ mastra,
104
+ agentId,
105
+ body,
106
+ networkId,
107
+ runtimeContext
108
+ }) {
109
+ try {
110
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
111
+ if (!memory) {
112
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
113
+ }
114
+ if (!body?.messages) {
115
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Messages are required" });
116
+ }
117
+ if (!Array.isArray(body.messages)) {
118
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Messages should be an array" });
119
+ }
120
+ const processedMessages = body.messages.map((message) => ({
121
+ ...message,
122
+ id: memory.generateId(),
123
+ createdAt: message.createdAt ? new Date(message.createdAt) : /* @__PURE__ */ new Date()
124
+ }));
125
+ const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });
126
+ return result;
127
+ } catch (error) {
128
+ return chunkPZQDCRPV_cjs.handleError(error, "Error saving messages");
129
+ }
130
+ }
131
+ async function createThreadHandler({
132
+ mastra,
133
+ agentId,
134
+ body,
135
+ networkId,
136
+ runtimeContext
137
+ }) {
138
+ try {
139
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
140
+ if (!memory) {
141
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
142
+ }
143
+ chunkCCGRCYWJ_cjs.validateBody({ resourceId: body?.resourceId });
144
+ const result = await memory.createThread({
145
+ resourceId: body?.resourceId,
146
+ title: body?.title,
147
+ metadata: body?.metadata,
148
+ threadId: body?.threadId
149
+ });
150
+ return result;
151
+ } catch (error) {
152
+ return chunkPZQDCRPV_cjs.handleError(error, "Error saving thread to memory");
153
+ }
154
+ }
155
+ async function updateThreadHandler({
156
+ mastra,
157
+ agentId,
158
+ threadId,
159
+ body,
160
+ networkId,
161
+ runtimeContext
162
+ }) {
163
+ try {
164
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
165
+ if (!body) {
166
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Body is required" });
167
+ }
168
+ const { title, metadata, resourceId } = body;
169
+ const updatedAt = /* @__PURE__ */ new Date();
170
+ chunkCCGRCYWJ_cjs.validateBody({ threadId });
171
+ if (!memory) {
172
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
173
+ }
174
+ const thread = await memory.getThreadById({ threadId });
175
+ if (!thread) {
176
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Thread not found" });
177
+ }
178
+ const updatedThread = {
179
+ ...thread,
180
+ title: title || thread.title,
181
+ metadata: metadata || thread.metadata,
182
+ resourceId: resourceId || thread.resourceId,
183
+ createdAt: thread.createdAt,
184
+ updatedAt
185
+ };
186
+ const result = await memory.saveThread({ thread: updatedThread });
187
+ return result;
188
+ } catch (error) {
189
+ return chunkPZQDCRPV_cjs.handleError(error, "Error updating thread");
190
+ }
191
+ }
192
+ async function deleteThreadHandler({
193
+ mastra,
194
+ agentId,
195
+ threadId,
196
+ networkId,
197
+ runtimeContext
198
+ }) {
199
+ try {
200
+ chunkCCGRCYWJ_cjs.validateBody({ threadId });
201
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
202
+ if (!memory) {
203
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
204
+ }
205
+ const thread = await memory.getThreadById({ threadId });
206
+ if (!thread) {
207
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Thread not found" });
208
+ }
209
+ await memory.deleteThread(threadId);
210
+ return { result: "Thread deleted" };
211
+ } catch (error) {
212
+ return chunkPZQDCRPV_cjs.handleError(error, "Error deleting thread");
213
+ }
214
+ }
215
+ async function getMessagesHandler({
216
+ mastra,
217
+ agentId,
218
+ threadId,
219
+ limit,
220
+ networkId,
221
+ runtimeContext
222
+ }) {
223
+ if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
224
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Invalid limit: must be a positive integer" });
225
+ }
226
+ try {
227
+ chunkCCGRCYWJ_cjs.validateBody({ threadId });
228
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
229
+ if (!memory) {
230
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
231
+ }
232
+ const thread = await memory.getThreadById({ threadId });
233
+ if (!thread) {
234
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Thread not found" });
235
+ }
236
+ const result = await memory.query({
237
+ threadId,
238
+ ...limit && { selectBy: { last: limit } }
239
+ });
240
+ return { messages: result.messages, uiMessages: result.uiMessages };
241
+ } catch (error) {
242
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting messages");
243
+ }
244
+ }
245
+ async function getWorkingMemoryHandler({
246
+ mastra,
247
+ agentId,
248
+ threadId,
249
+ resourceId,
250
+ networkId,
251
+ runtimeContext,
252
+ memoryConfig
253
+ }) {
254
+ try {
255
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
256
+ chunkCCGRCYWJ_cjs.validateBody({ threadId });
257
+ if (!memory) {
258
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
259
+ }
260
+ const thread = await memory.getThreadById({ threadId });
261
+ const threadExists = !!thread;
262
+ const template = await memory.getWorkingMemoryTemplate({ memoryConfig });
263
+ const workingMemoryTemplate = template?.format === "json" ? { ...template, content: JSON.stringify(core.generateEmptyFromSchema(template.content)) } : template;
264
+ const workingMemory = await memory.getWorkingMemory({ threadId, resourceId, memoryConfig });
265
+ const config = memory.getMergedThreadConfig(memoryConfig || {});
266
+ const source = config.workingMemory?.scope === "resource" && resourceId ? "resource" : "thread";
267
+ return { workingMemory, source, workingMemoryTemplate, threadExists };
268
+ } catch (error) {
269
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting working memory");
270
+ }
271
+ }
272
+ async function updateWorkingMemoryHandler({
273
+ mastra,
274
+ agentId,
275
+ threadId,
276
+ body,
277
+ networkId,
278
+ runtimeContext
279
+ }) {
280
+ try {
281
+ chunkCCGRCYWJ_cjs.validateBody({ threadId });
282
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
283
+ const { resourceId, memoryConfig, workingMemory } = body;
284
+ if (!memory) {
285
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
286
+ }
287
+ const thread = await memory.getThreadById({ threadId });
288
+ if (!thread) {
289
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Thread not found" });
290
+ }
291
+ await memory.updateWorkingMemory({ threadId, resourceId, workingMemory, memoryConfig });
292
+ return { success: true };
293
+ } catch (error) {
294
+ return chunkPZQDCRPV_cjs.handleError(error, "Error updating working memory");
295
+ }
296
+ }
297
+
298
+ exports.createThreadHandler = createThreadHandler;
299
+ exports.deleteThreadHandler = deleteThreadHandler;
300
+ exports.getMemoryStatusHandler = getMemoryStatusHandler;
301
+ exports.getMessagesHandler = getMessagesHandler;
302
+ exports.getThreadByIdHandler = getThreadByIdHandler;
303
+ exports.getThreadsHandler = getThreadsHandler;
304
+ exports.getWorkingMemoryHandler = getWorkingMemoryHandler;
305
+ exports.memory_exports = memory_exports;
306
+ exports.saveMessagesHandler = saveMessagesHandler;
307
+ exports.updateThreadHandler = updateThreadHandler;
308
+ exports.updateWorkingMemoryHandler = updateWorkingMemoryHandler;
@@ -0,0 +1,81 @@
1
+ import { validateBody } from './chunk-RSEO4XPX.js';
2
+ import { handleError } from './chunk-LF7P5PLR.js';
3
+ import { __export } from './chunk-MLKGABMK.js';
4
+
5
+ // src/server/handlers/logs.ts
6
+ var logs_exports = {};
7
+ __export(logs_exports, {
8
+ getLogTransports: () => getLogTransports,
9
+ getLogsByRunIdHandler: () => getLogsByRunIdHandler,
10
+ getLogsHandler: () => getLogsHandler
11
+ });
12
+ async function getLogsHandler({
13
+ mastra,
14
+ transportId,
15
+ params
16
+ }) {
17
+ try {
18
+ validateBody({ transportId });
19
+ const { fromDate, toDate, logLevel, filters: _filters, page, perPage } = params || {};
20
+ const filters = _filters ? Object.fromEntries(
21
+ (Array.isArray(_filters) ? _filters : [_filters]).map((attr) => {
22
+ const [key, value] = attr.split(":");
23
+ return [key, value];
24
+ })
25
+ ) : void 0;
26
+ const logs = await mastra.getLogs(transportId, {
27
+ fromDate,
28
+ toDate,
29
+ logLevel,
30
+ filters,
31
+ page: page ? Number(page) : void 0,
32
+ perPage: perPage ? Number(perPage) : void 0
33
+ });
34
+ return logs;
35
+ } catch (error) {
36
+ return handleError(error, "Error getting logs");
37
+ }
38
+ }
39
+ async function getLogsByRunIdHandler({
40
+ mastra,
41
+ runId,
42
+ transportId,
43
+ params
44
+ }) {
45
+ try {
46
+ validateBody({ runId, transportId });
47
+ const { fromDate, toDate, logLevel, filters: _filters, page, perPage } = params || {};
48
+ const filters = _filters ? Object.fromEntries(
49
+ (Array.isArray(_filters) ? _filters : [_filters]).map((attr) => {
50
+ const [key, value] = attr.split(":");
51
+ return [key, value];
52
+ })
53
+ ) : void 0;
54
+ const logs = await mastra.getLogsByRunId({
55
+ runId,
56
+ transportId,
57
+ fromDate,
58
+ toDate,
59
+ logLevel,
60
+ filters,
61
+ page: page ? Number(page) : void 0,
62
+ perPage: perPage ? Number(perPage) : void 0
63
+ });
64
+ return logs;
65
+ } catch (error) {
66
+ return handleError(error, "Error getting logs by run ID");
67
+ }
68
+ }
69
+ async function getLogTransports({ mastra }) {
70
+ try {
71
+ const logger = mastra.getLogger();
72
+ const transports = logger.getTransports();
73
+ return {
74
+ transports: transports ? [...transports.keys()] : []
75
+ };
76
+ } catch (error) {
77
+ return handleError(error, "Error getting log Transports");
78
+ }
79
+ }
80
+
81
+ export { getLogTransports, getLogsByRunIdHandler, getLogsHandler, logs_exports };