@mastra/server 0.0.0-message-ordering-20250415215612 → 0.0.0-message-list-update-20250715150321

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 (93) hide show
  1. package/LICENSE.md +11 -42
  2. package/README.md +48 -135
  3. package/dist/_tsup-dts-rollup.d.cts +604 -70
  4. package/dist/_tsup-dts-rollup.d.ts +604 -70
  5. package/dist/{chunk-FV45V6WC.cjs → chunk-2KZFMI6P.cjs} +1 -7
  6. package/dist/chunk-2SLFAFTR.cjs +148 -0
  7. package/dist/chunk-3CNDE7QY.cjs +308 -0
  8. package/dist/chunk-4D66QEKC.js +81 -0
  9. package/dist/{chunk-OPP7H5TW.js → chunk-5PQQ42EZ.js} +83 -68
  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-BK4XT6EG.js +270 -0
  14. package/dist/{chunk-QN4KF3BH.cjs → chunk-CCGRCYWJ.cjs} +2 -2
  15. package/dist/{chunk-YANVFOYA.js → chunk-CRCR3ZUK.js} +56 -34
  16. package/dist/{chunk-PDC4ZBQW.cjs → chunk-FRVBFMO2.cjs} +28 -26
  17. package/dist/{chunk-CWSDZEZG.cjs → chunk-G7KH752Y.cjs} +18 -12
  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-3RVHWGWO.js → chunk-KHZKYUNR.js} +36 -19
  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-UV4WTEH4.js → chunk-LRCAAFUA.js} +11 -9
  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-DVPP5S6I.js → chunk-RG473F6Y.js} +14 -8
  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 +33 -23
  78. package/dist/server/handlers.d.cts +2 -0
  79. package/dist/server/handlers.d.ts +2 -0
  80. package/dist/server/handlers.js +11 -9
  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-67WTHYAV.js +0 -156
  86. package/dist/chunk-A7DF4ETD.cjs +0 -100
  87. package/dist/chunk-B64YROKU.cjs +0 -317
  88. package/dist/chunk-JLDXUWK7.cjs +0 -126
  89. package/dist/chunk-QH6XWSXP.cjs +0 -5579
  90. package/dist/chunk-SKBVVI24.cjs +0 -54
  91. package/dist/chunk-VK6FX47H.js +0 -5576
  92. package/dist/chunk-Z46X3YCB.cjs +0 -164
  93. package/dist/chunk-ZLBRQFDD.cjs +0 -13
@@ -0,0 +1,332 @@
1
+ 'use strict';
2
+
3
+ var chunkLI436ITD_cjs = require('./chunk-LI436ITD.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 web = require('stream/web');
8
+
9
+ // src/server/handlers/legacyWorkflows.ts
10
+ var legacyWorkflows_exports = {};
11
+ chunk75ZPJI57_cjs.__export(legacyWorkflows_exports, {
12
+ createLegacyWorkflowRunHandler: () => createLegacyWorkflowRunHandler,
13
+ getLegacyWorkflowByIdHandler: () => getLegacyWorkflowByIdHandler,
14
+ getLegacyWorkflowRunHandler: () => getLegacyWorkflowRunHandler,
15
+ getLegacyWorkflowRunsHandler: () => getLegacyWorkflowRunsHandler,
16
+ getLegacyWorkflowsHandler: () => getLegacyWorkflowsHandler,
17
+ resumeAsyncLegacyWorkflowHandler: () => resumeAsyncLegacyWorkflowHandler,
18
+ resumeLegacyWorkflowHandler: () => resumeLegacyWorkflowHandler,
19
+ startAsyncLegacyWorkflowHandler: () => startAsyncLegacyWorkflowHandler,
20
+ startLegacyWorkflowRunHandler: () => startLegacyWorkflowRunHandler,
21
+ watchLegacyWorkflowHandler: () => watchLegacyWorkflowHandler
22
+ });
23
+ async function getLegacyWorkflowsHandler({ mastra }) {
24
+ try {
25
+ const workflows = mastra.legacy_getWorkflows({ serialized: false });
26
+ const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
27
+ if (workflow.isNested) return acc;
28
+ acc[key] = {
29
+ stepGraph: workflow.stepGraph,
30
+ stepSubscriberGraph: workflow.stepSubscriberGraph,
31
+ serializedStepGraph: workflow.serializedStepGraph,
32
+ serializedStepSubscriberGraph: workflow.serializedStepSubscriberGraph,
33
+ name: workflow.name,
34
+ triggerSchema: workflow.triggerSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(workflow.triggerSchema)) : void 0,
35
+ steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
36
+ const _step = step;
37
+ acc2[key2] = {
38
+ id: _step.id,
39
+ description: _step.description,
40
+ workflowId: _step.workflowId,
41
+ inputSchema: _step.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(_step.inputSchema)) : void 0,
42
+ outputSchema: _step.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(_step.outputSchema)) : void 0
43
+ };
44
+ return acc2;
45
+ }, {})
46
+ };
47
+ return acc;
48
+ }, {});
49
+ return _workflows;
50
+ } catch (error) {
51
+ return chunkPZQDCRPV_cjs.handleError(error, "error getting workflows");
52
+ }
53
+ }
54
+ async function getLegacyWorkflowByIdHandler({ mastra, workflowId }) {
55
+ try {
56
+ if (!workflowId) {
57
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
58
+ }
59
+ const workflow = mastra.legacy_getWorkflow(workflowId);
60
+ if (!workflow) {
61
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
62
+ }
63
+ return {
64
+ stepGraph: workflow.stepGraph,
65
+ stepSubscriberGraph: workflow.stepSubscriberGraph,
66
+ serializedStepGraph: workflow.serializedStepGraph,
67
+ serializedStepSubscriberGraph: workflow.serializedStepSubscriberGraph,
68
+ name: workflow.name,
69
+ triggerSchema: workflow.triggerSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(workflow.triggerSchema)) : void 0,
70
+ steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
71
+ const _step = step;
72
+ acc[key] = {
73
+ id: _step.id,
74
+ description: _step.description,
75
+ workflowId: _step.workflowId,
76
+ inputSchema: _step.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(_step.inputSchema)) : void 0,
77
+ outputSchema: _step.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(_step.outputSchema)) : void 0
78
+ };
79
+ return acc;
80
+ }, {})
81
+ };
82
+ } catch (error) {
83
+ return chunkPZQDCRPV_cjs.handleError(error, "error getting workflow by id");
84
+ }
85
+ }
86
+ async function startAsyncLegacyWorkflowHandler({
87
+ mastra,
88
+ runtimeContext,
89
+ workflowId,
90
+ runId,
91
+ triggerData
92
+ }) {
93
+ try {
94
+ if (!workflowId) {
95
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
96
+ }
97
+ const workflow = mastra.legacy_getWorkflow(workflowId);
98
+ if (!workflow) {
99
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
100
+ }
101
+ if (!runId) {
102
+ const newRun = workflow.createRun();
103
+ const result2 = await newRun.start({
104
+ triggerData,
105
+ runtimeContext
106
+ });
107
+ return result2;
108
+ }
109
+ const run = workflow.getMemoryRun(runId);
110
+ if (!run) {
111
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
112
+ }
113
+ const result = await run.start({
114
+ triggerData,
115
+ runtimeContext
116
+ });
117
+ return result;
118
+ } catch (error) {
119
+ return chunkPZQDCRPV_cjs.handleError(error, "error starting workflow");
120
+ }
121
+ }
122
+ async function getLegacyWorkflowRunHandler({
123
+ mastra,
124
+ workflowId,
125
+ runId
126
+ }) {
127
+ try {
128
+ if (!workflowId) {
129
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
130
+ }
131
+ if (!runId) {
132
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Run ID is required" });
133
+ }
134
+ const workflow = mastra.legacy_getWorkflow(workflowId);
135
+ if (!workflow) {
136
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
137
+ }
138
+ const run = await workflow.getRun(runId);
139
+ if (!run) {
140
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
141
+ }
142
+ return run;
143
+ } catch (error) {
144
+ return chunkPZQDCRPV_cjs.handleError(error, "error getting workflow run");
145
+ }
146
+ }
147
+ async function createLegacyWorkflowRunHandler({
148
+ mastra,
149
+ workflowId,
150
+ runId: prevRunId
151
+ }) {
152
+ try {
153
+ if (!workflowId) {
154
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
155
+ }
156
+ const workflow = mastra.legacy_getWorkflow(workflowId);
157
+ if (!workflow) {
158
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
159
+ }
160
+ const newRun = workflow.createRun({ runId: prevRunId });
161
+ return { runId: newRun.runId };
162
+ } catch (error) {
163
+ return chunkPZQDCRPV_cjs.handleError(error, "error creating workflow run");
164
+ }
165
+ }
166
+ async function startLegacyWorkflowRunHandler({
167
+ mastra,
168
+ runtimeContext,
169
+ workflowId,
170
+ runId,
171
+ triggerData
172
+ }) {
173
+ try {
174
+ if (!workflowId) {
175
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
176
+ }
177
+ if (!runId) {
178
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to start run" });
179
+ }
180
+ const workflow = mastra.legacy_getWorkflow(workflowId);
181
+ const run = workflow.getMemoryRun(runId);
182
+ if (!run) {
183
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
184
+ }
185
+ void run.start({
186
+ triggerData,
187
+ runtimeContext
188
+ });
189
+ return { message: "Workflow run started" };
190
+ } catch (e) {
191
+ return chunkPZQDCRPV_cjs.handleError(e, "Error starting workflow run");
192
+ }
193
+ }
194
+ async function watchLegacyWorkflowHandler({
195
+ mastra,
196
+ workflowId,
197
+ runId
198
+ }) {
199
+ try {
200
+ if (!workflowId) {
201
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
202
+ }
203
+ if (!runId) {
204
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to watch workflow" });
205
+ }
206
+ const workflow = mastra.legacy_getWorkflow(workflowId);
207
+ const run = workflow.getMemoryRun(runId);
208
+ if (!run) {
209
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
210
+ }
211
+ let unwatch;
212
+ let asyncRef = null;
213
+ const stream = new web.ReadableStream({
214
+ start(controller) {
215
+ unwatch = run.watch(({ activePaths, runId: runId2, timestamp, results }) => {
216
+ const activePathsObj = Object.fromEntries(activePaths);
217
+ controller.enqueue(JSON.stringify({ activePaths: activePathsObj, runId: runId2, timestamp, results }));
218
+ if (asyncRef) {
219
+ clearImmediate(asyncRef);
220
+ asyncRef = null;
221
+ }
222
+ asyncRef = setImmediate(() => {
223
+ const runDone = Object.values(activePathsObj).every((value) => value.status !== "executing");
224
+ if (runDone) {
225
+ controller.close();
226
+ unwatch?.();
227
+ }
228
+ });
229
+ });
230
+ },
231
+ cancel() {
232
+ unwatch?.();
233
+ }
234
+ });
235
+ return stream;
236
+ } catch (error) {
237
+ return chunkPZQDCRPV_cjs.handleError(error, "Error watching workflow");
238
+ }
239
+ }
240
+ async function resumeAsyncLegacyWorkflowHandler({
241
+ mastra,
242
+ workflowId,
243
+ runId,
244
+ body,
245
+ runtimeContext
246
+ }) {
247
+ try {
248
+ if (!workflowId) {
249
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
250
+ }
251
+ if (!runId) {
252
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to resume workflow" });
253
+ }
254
+ const workflow = mastra.legacy_getWorkflow(workflowId);
255
+ const run = workflow.getMemoryRun(runId);
256
+ if (!run) {
257
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
258
+ }
259
+ const result = await run.resume({
260
+ stepId: body.stepId,
261
+ context: body.context,
262
+ runtimeContext
263
+ });
264
+ return result;
265
+ } catch (error) {
266
+ return chunkPZQDCRPV_cjs.handleError(error, "Error resuming workflow step");
267
+ }
268
+ }
269
+ async function resumeLegacyWorkflowHandler({
270
+ mastra,
271
+ workflowId,
272
+ runId,
273
+ body,
274
+ runtimeContext
275
+ }) {
276
+ try {
277
+ if (!workflowId) {
278
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
279
+ }
280
+ if (!runId) {
281
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to resume workflow" });
282
+ }
283
+ const workflow = mastra.legacy_getWorkflow(workflowId);
284
+ const run = workflow.getMemoryRun(runId);
285
+ if (!run) {
286
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
287
+ }
288
+ void run.resume({
289
+ stepId: body.stepId,
290
+ context: body.context,
291
+ runtimeContext
292
+ });
293
+ return { message: "Workflow run resumed" };
294
+ } catch (error) {
295
+ return chunkPZQDCRPV_cjs.handleError(error, "Error resuming workflow");
296
+ }
297
+ }
298
+ async function getLegacyWorkflowRunsHandler({
299
+ mastra,
300
+ workflowId,
301
+ fromDate,
302
+ toDate,
303
+ limit,
304
+ offset,
305
+ resourceId
306
+ }) {
307
+ try {
308
+ if (!workflowId) {
309
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
310
+ }
311
+ const workflow = mastra.legacy_getWorkflow(workflowId);
312
+ const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
313
+ runs: [],
314
+ total: 0
315
+ };
316
+ return workflowRuns;
317
+ } catch (error) {
318
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting workflow runs");
319
+ }
320
+ }
321
+
322
+ exports.createLegacyWorkflowRunHandler = createLegacyWorkflowRunHandler;
323
+ exports.getLegacyWorkflowByIdHandler = getLegacyWorkflowByIdHandler;
324
+ exports.getLegacyWorkflowRunHandler = getLegacyWorkflowRunHandler;
325
+ exports.getLegacyWorkflowRunsHandler = getLegacyWorkflowRunsHandler;
326
+ exports.getLegacyWorkflowsHandler = getLegacyWorkflowsHandler;
327
+ exports.legacyWorkflows_exports = legacyWorkflows_exports;
328
+ exports.resumeAsyncLegacyWorkflowHandler = resumeAsyncLegacyWorkflowHandler;
329
+ exports.resumeLegacyWorkflowHandler = resumeLegacyWorkflowHandler;
330
+ exports.startAsyncLegacyWorkflowHandler = startAsyncLegacyWorkflowHandler;
331
+ exports.startLegacyWorkflowRunHandler = startLegacyWorkflowRunHandler;
332
+ exports.watchLegacyWorkflowHandler = watchLegacyWorkflowHandler;
@@ -1,12 +1,14 @@
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-RSEO4XPX.js';
2
+ import { handleError } from './chunk-LF7P5PLR.js';
3
+ import { HTTPException } from './chunk-LCM566I4.js';
4
+ import { __export } from './chunk-MLKGABMK.js';
4
5
  import { Readable } from 'stream';
5
6
 
6
7
  // src/server/handlers/voice.ts
7
8
  var voice_exports = {};
8
9
  __export(voice_exports, {
9
10
  generateSpeechHandler: () => generateSpeechHandler,
11
+ getListenerHandler: () => getListenerHandler,
10
12
  getSpeakersHandler: () => getSpeakersHandler,
11
13
  transcribeSpeechHandler: () => transcribeSpeechHandler
12
14
  });
@@ -19,10 +21,11 @@ async function getSpeakersHandler({ mastra, agentId }) {
19
21
  if (!agent) {
20
22
  throw new HTTPException(404, { message: "Agent not found" });
21
23
  }
22
- if (!agent.voice) {
24
+ const voice = await agent.getVoice();
25
+ if (!voice) {
23
26
  throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
24
27
  }
25
- const speakers = await agent.voice.getSpeakers();
28
+ const speakers = await voice.getSpeakers();
26
29
  return speakers;
27
30
  } catch (error) {
28
31
  return handleError(error, "Error getting speakers");
@@ -38,27 +41,21 @@ async function generateSpeechHandler({
38
41
  throw new HTTPException(400, { message: "Agent ID is required" });
39
42
  }
40
43
  validateBody({
41
- text: void 0,
42
- speakerId: void 0,
43
- ...body
44
+ text: body?.text
44
45
  });
45
46
  const agent = mastra.getAgent(agentId);
46
47
  if (!agent) {
47
48
  throw new HTTPException(404, { message: "Agent not found" });
48
49
  }
49
- if (!agent.voice) {
50
+ const voice = await agent.getVoice();
51
+ if (!voice) {
50
52
  throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
51
53
  }
52
- const audioStream = await agent.voice.speak(body.text, { speaker: body.speakerId });
54
+ const audioStream = await voice.speak(body.text, { speaker: body.speakerId });
53
55
  if (!audioStream) {
54
56
  throw new HTTPException(500, { message: "Failed to generate speech" });
55
57
  }
56
- const chunks = [];
57
- for await (const chunk of audioStream) {
58
- chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
59
- }
60
- const audioData = Buffer.concat(chunks);
61
- return { audioData };
58
+ return audioStream;
62
59
  } catch (error) {
63
60
  return handleError(error, "Error generating speech");
64
61
  }
@@ -79,17 +76,37 @@ async function transcribeSpeechHandler({
79
76
  if (!agent) {
80
77
  throw new HTTPException(404, { message: "Agent not found" });
81
78
  }
82
- if (!agent.voice) {
79
+ const voice = await agent.getVoice();
80
+ if (!voice) {
83
81
  throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
84
82
  }
85
83
  const audioStream = new Readable();
86
84
  audioStream.push(body.audioData);
87
85
  audioStream.push(null);
88
- const text = await agent.voice.listen(audioStream, body.options);
86
+ const text = await voice.listen(audioStream, body.options);
89
87
  return { text };
90
88
  } catch (error) {
91
89
  return handleError(error, "Error transcribing speech");
92
90
  }
93
91
  }
92
+ async function getListenerHandler({ mastra, agentId }) {
93
+ try {
94
+ if (!agentId) {
95
+ throw new HTTPException(400, { message: "Agent ID is required" });
96
+ }
97
+ const agent = mastra.getAgent(agentId);
98
+ if (!agent) {
99
+ throw new HTTPException(404, { message: "Agent not found" });
100
+ }
101
+ const voice = await agent.getVoice();
102
+ if (!voice) {
103
+ throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
104
+ }
105
+ const listeners = await voice.getListener();
106
+ return listeners;
107
+ } catch (error) {
108
+ return handleError(error, "Error getting listeners");
109
+ }
110
+ }
94
111
 
95
- export { generateSpeechHandler, getSpeakersHandler, transcribeSpeechHandler, voice_exports };
112
+ export { generateSpeechHandler, getListenerHandler, getSpeakersHandler, transcribeSpeechHandler, voice_exports };
@@ -1,6 +1,8 @@
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-RSEO4XPX.js';
2
+ import { handleError } from './chunk-LF7P5PLR.js';
3
+ import { HTTPException } from './chunk-LCM566I4.js';
4
+ import { __export } from './chunk-MLKGABMK.js';
5
+ import { generateEmptyFromSchema } from '@mastra/core';
4
6
 
5
7
  // src/server/handlers/memory.ts
6
8
  var memory_exports = {};
@@ -11,23 +13,41 @@ __export(memory_exports, {
11
13
  getMessagesHandler: () => getMessagesHandler,
12
14
  getThreadByIdHandler: () => getThreadByIdHandler,
13
15
  getThreadsHandler: () => getThreadsHandler,
16
+ getWorkingMemoryHandler: () => getWorkingMemoryHandler,
14
17
  saveMessagesHandler: () => saveMessagesHandler,
15
- updateThreadHandler: () => updateThreadHandler
18
+ updateThreadHandler: () => updateThreadHandler,
19
+ updateWorkingMemoryHandler: () => updateWorkingMemoryHandler
16
20
  });
17
- function getMemoryFromContext({
21
+ async function getMemoryFromContext({
18
22
  mastra,
19
- agentId
23
+ agentId,
24
+ networkId,
25
+ runtimeContext
20
26
  }) {
21
27
  const agent = agentId ? mastra.getAgent(agentId) : null;
22
28
  if (agentId && !agent) {
23
29
  throw new HTTPException(404, { message: "Agent not found" });
24
30
  }
25
- const memory = agent?.getMemory?.() || mastra.getMemory();
26
- return memory;
31
+ const network = networkId ? mastra.vnext_getNetwork(networkId) : null;
32
+ if (networkId && !network) {
33
+ throw new HTTPException(404, { message: "Network not found" });
34
+ }
35
+ if (agent) {
36
+ return agent?.getMemory() || mastra.getMemory();
37
+ }
38
+ if (network) {
39
+ return await network?.getMemory({ runtimeContext }) || mastra.getMemory();
40
+ }
41
+ return mastra.getMemory();
27
42
  }
28
- async function getMemoryStatusHandler({ mastra, agentId }) {
43
+ async function getMemoryStatusHandler({
44
+ mastra,
45
+ agentId,
46
+ networkId,
47
+ runtimeContext
48
+ }) {
29
49
  try {
30
- const memory = getMemoryFromContext({ mastra, agentId });
50
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
31
51
  if (!memory) {
32
52
  return { result: false };
33
53
  }
@@ -39,10 +59,12 @@ async function getMemoryStatusHandler({ mastra, agentId }) {
39
59
  async function getThreadsHandler({
40
60
  mastra,
41
61
  agentId,
42
- resourceId
62
+ resourceId,
63
+ networkId,
64
+ runtimeContext
43
65
  }) {
44
66
  try {
45
- const memory = getMemoryFromContext({ mastra, agentId });
67
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
46
68
  if (!memory) {
47
69
  throw new HTTPException(400, { message: "Memory is not initialized" });
48
70
  }
@@ -56,11 +78,13 @@ async function getThreadsHandler({
56
78
  async function getThreadByIdHandler({
57
79
  mastra,
58
80
  agentId,
59
- threadId
81
+ threadId,
82
+ networkId,
83
+ runtimeContext
60
84
  }) {
61
85
  try {
62
86
  validateBody({ threadId });
63
- const memory = getMemoryFromContext({ mastra, agentId });
87
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
64
88
  if (!memory) {
65
89
  throw new HTTPException(400, { message: "Memory is not initialized" });
66
90
  }
@@ -76,10 +100,12 @@ async function getThreadByIdHandler({
76
100
  async function saveMessagesHandler({
77
101
  mastra,
78
102
  agentId,
79
- body
103
+ body,
104
+ networkId,
105
+ runtimeContext
80
106
  }) {
81
107
  try {
82
- const memory = getMemoryFromContext({ mastra, agentId });
108
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
83
109
  if (!memory) {
84
110
  throw new HTTPException(400, { message: "Memory is not initialized" });
85
111
  }
@@ -103,10 +129,12 @@ async function saveMessagesHandler({
103
129
  async function createThreadHandler({
104
130
  mastra,
105
131
  agentId,
106
- body
132
+ body,
133
+ networkId,
134
+ runtimeContext
107
135
  }) {
108
136
  try {
109
- const memory = getMemoryFromContext({ mastra, agentId });
137
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
110
138
  if (!memory) {
111
139
  throw new HTTPException(400, { message: "Memory is not initialized" });
112
140
  }
@@ -126,10 +154,12 @@ async function updateThreadHandler({
126
154
  mastra,
127
155
  agentId,
128
156
  threadId,
129
- body
157
+ body,
158
+ networkId,
159
+ runtimeContext
130
160
  }) {
131
161
  try {
132
- const memory = getMemoryFromContext({ mastra, agentId });
162
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
133
163
  if (!body) {
134
164
  throw new HTTPException(400, { message: "Body is required" });
135
165
  }
@@ -160,11 +190,13 @@ async function updateThreadHandler({
160
190
  async function deleteThreadHandler({
161
191
  mastra,
162
192
  agentId,
163
- threadId
193
+ threadId,
194
+ networkId,
195
+ runtimeContext
164
196
  }) {
165
197
  try {
166
198
  validateBody({ threadId });
167
- const memory = getMemoryFromContext({ mastra, agentId });
199
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
168
200
  if (!memory) {
169
201
  throw new HTTPException(400, { message: "Memory is not initialized" });
170
202
  }
@@ -181,11 +213,17 @@ async function deleteThreadHandler({
181
213
  async function getMessagesHandler({
182
214
  mastra,
183
215
  agentId,
184
- threadId
216
+ threadId,
217
+ limit,
218
+ networkId,
219
+ runtimeContext
185
220
  }) {
221
+ if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
222
+ throw new HTTPException(400, { message: "Invalid limit: must be a positive integer" });
223
+ }
186
224
  try {
187
225
  validateBody({ threadId });
188
- const memory = getMemoryFromContext({ mastra, agentId });
226
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
189
227
  if (!memory) {
190
228
  throw new HTTPException(400, { message: "Memory is not initialized" });
191
229
  }
@@ -193,11 +231,66 @@ async function getMessagesHandler({
193
231
  if (!thread) {
194
232
  throw new HTTPException(404, { message: "Thread not found" });
195
233
  }
196
- const result = await memory.query({ threadId });
197
- return result;
234
+ const result = await memory.query({
235
+ threadId,
236
+ ...limit && { selectBy: { last: limit } }
237
+ });
238
+ return { messages: result.messages, uiMessages: result.uiMessages };
198
239
  } catch (error) {
199
240
  return handleError(error, "Error getting messages");
200
241
  }
201
242
  }
243
+ async function getWorkingMemoryHandler({
244
+ mastra,
245
+ agentId,
246
+ threadId,
247
+ resourceId,
248
+ networkId,
249
+ runtimeContext,
250
+ memoryConfig
251
+ }) {
252
+ try {
253
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
254
+ validateBody({ threadId });
255
+ if (!memory) {
256
+ throw new HTTPException(400, { message: "Memory is not initialized" });
257
+ }
258
+ const thread = await memory.getThreadById({ threadId });
259
+ const threadExists = !!thread;
260
+ const template = await memory.getWorkingMemoryTemplate({ memoryConfig });
261
+ const workingMemoryTemplate = template?.format === "json" ? { ...template, content: JSON.stringify(generateEmptyFromSchema(template.content)) } : template;
262
+ const workingMemory = await memory.getWorkingMemory({ threadId, resourceId, memoryConfig });
263
+ const config = memory.getMergedThreadConfig(memoryConfig || {});
264
+ const source = config.workingMemory?.scope === "resource" && resourceId ? "resource" : "thread";
265
+ return { workingMemory, source, workingMemoryTemplate, threadExists };
266
+ } catch (error) {
267
+ return handleError(error, "Error getting working memory");
268
+ }
269
+ }
270
+ async function updateWorkingMemoryHandler({
271
+ mastra,
272
+ agentId,
273
+ threadId,
274
+ body,
275
+ networkId,
276
+ runtimeContext
277
+ }) {
278
+ try {
279
+ validateBody({ threadId });
280
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
281
+ const { resourceId, memoryConfig, workingMemory } = body;
282
+ if (!memory) {
283
+ throw new HTTPException(400, { message: "Memory is not initialized" });
284
+ }
285
+ const thread = await memory.getThreadById({ threadId });
286
+ if (!thread) {
287
+ throw new HTTPException(404, { message: "Thread not found" });
288
+ }
289
+ await memory.updateWorkingMemory({ threadId, resourceId, workingMemory, memoryConfig });
290
+ return { success: true };
291
+ } catch (error) {
292
+ return handleError(error, "Error updating working memory");
293
+ }
294
+ }
202
295
 
203
- export { createThreadHandler, deleteThreadHandler, getMemoryStatusHandler, getMessagesHandler, getThreadByIdHandler, getThreadsHandler, memory_exports, saveMessagesHandler, updateThreadHandler };
296
+ export { createThreadHandler, deleteThreadHandler, getMemoryStatusHandler, getMessagesHandler, getThreadByIdHandler, getThreadsHandler, getWorkingMemoryHandler, memory_exports, saveMessagesHandler, updateThreadHandler, updateWorkingMemoryHandler };
@@ -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,4 @@ var HTTPException = class extends Error {
37
32
  }
38
33
  };
39
34
 
40
- export { HTTPException, __export };
35
+ export { HTTPException };