@mastra/server 0.0.0-mcp-server-update-parse-20250421171139 → 0.0.0-mcp-schema-serializer-20250430202337

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 (33) hide show
  1. package/dist/_tsup-dts-rollup.d.cts +111 -30
  2. package/dist/_tsup-dts-rollup.d.ts +111 -30
  3. package/dist/{chunk-4WJ5GHRG.cjs → chunk-4BIX6GMY.cjs} +56 -31
  4. package/dist/{chunk-A7DF4ETD.cjs → chunk-55HTWX4C.cjs} +2 -9
  5. package/dist/{chunk-XISBMH56.js → chunk-5JNVY6DU.js} +4 -4
  6. package/dist/{chunk-JLDXUWK7.cjs → chunk-5YGDYMRB.cjs} +52 -31
  7. package/dist/chunk-AELYAUEE.cjs +316 -0
  8. package/dist/{chunk-HABV7TZK.cjs → chunk-D3G23FP3.cjs} +4 -4
  9. package/dist/{chunk-RNU4JMLM.cjs → chunk-EVCC233P.cjs} +15 -11
  10. package/dist/chunk-JPB6RPGB.js +304 -0
  11. package/dist/{chunk-4B7OUZXW.js → chunk-M3YJLWTU.js} +15 -11
  12. package/dist/{chunk-3RVHWGWO.js → chunk-Q6SHQECN.js} +2 -9
  13. package/dist/{chunk-YANVFOYA.js → chunk-QJ3AHN64.js} +52 -31
  14. package/dist/{chunk-TFFNX7FI.js → chunk-Y3SV5XK4.js} +56 -31
  15. package/dist/server/handlers/agents.cjs +7 -7
  16. package/dist/server/handlers/agents.js +1 -1
  17. package/dist/server/handlers/network.cjs +5 -5
  18. package/dist/server/handlers/network.js +1 -1
  19. package/dist/server/handlers/tools.cjs +5 -5
  20. package/dist/server/handlers/tools.js +1 -1
  21. package/dist/server/handlers/vNextWorkflows.cjs +46 -0
  22. package/dist/server/handlers/vNextWorkflows.d.cts +10 -0
  23. package/dist/server/handlers/vNextWorkflows.d.ts +10 -0
  24. package/dist/server/handlers/vNextWorkflows.js +1 -0
  25. package/dist/server/handlers/voice.cjs +4 -4
  26. package/dist/server/handlers/voice.js +1 -1
  27. package/dist/server/handlers/workflows.cjs +11 -11
  28. package/dist/server/handlers/workflows.js +1 -1
  29. package/dist/server/handlers.cjs +15 -10
  30. package/dist/server/handlers.d.cts +1 -0
  31. package/dist/server/handlers.d.ts +1 -0
  32. package/dist/server/handlers.js +6 -5
  33. package/package.json +5 -5
@@ -58,7 +58,7 @@ function executeToolHandler(tools$1) {
58
58
  runId,
59
59
  toolId,
60
60
  data,
61
- container
61
+ runtimeContext
62
62
  }) => {
63
63
  try {
64
64
  if (!toolId) {
@@ -80,7 +80,7 @@ function executeToolHandler(tools$1) {
80
80
  context: data,
81
81
  mastra,
82
82
  runId,
83
- container
83
+ runtimeContext
84
84
  });
85
85
  return result;
86
86
  } catch (error) {
@@ -93,7 +93,7 @@ async function executeAgentToolHandler({
93
93
  agentId,
94
94
  toolId,
95
95
  data,
96
- container
96
+ runtimeContext
97
97
  }) {
98
98
  try {
99
99
  const agent = agentId ? mastra.getAgent(agentId) : null;
@@ -109,7 +109,7 @@ async function executeAgentToolHandler({
109
109
  }
110
110
  const result = await tool.execute({
111
111
  context: data,
112
- container,
112
+ runtimeContext,
113
113
  mastra,
114
114
  runId: agentId
115
115
  });
@@ -34,7 +34,9 @@ async function getWorkflowsHandler({ mastra }) {
34
34
  steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
35
35
  const _step = step;
36
36
  acc2[key2] = {
37
- ..._step,
37
+ id: _step.id,
38
+ description: _step.description,
39
+ workflowId: _step.workflowId,
38
40
  inputSchema: _step.inputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_step.inputSchema)) : void 0,
39
41
  outputSchema: _step.outputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_step.outputSchema)) : void 0
40
42
  };
@@ -67,7 +69,9 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
67
69
  steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
68
70
  const _step = step;
69
71
  acc[key] = {
70
- ..._step,
72
+ id: _step.id,
73
+ description: _step.description,
74
+ workflowId: _step.workflowId,
71
75
  inputSchema: _step.inputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_step.inputSchema)) : void 0,
72
76
  outputSchema: _step.outputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_step.outputSchema)) : void 0
73
77
  };
@@ -80,7 +84,7 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
80
84
  }
81
85
  async function startAsyncWorkflowHandler({
82
86
  mastra,
83
- container,
87
+ runtimeContext,
84
88
  workflowId,
85
89
  runId,
86
90
  triggerData
@@ -97,7 +101,7 @@ async function startAsyncWorkflowHandler({
97
101
  const { start } = workflow.createRun();
98
102
  const result2 = await start({
99
103
  triggerData,
100
- container
104
+ runtimeContext
101
105
  });
102
106
  return result2;
103
107
  }
@@ -107,7 +111,7 @@ async function startAsyncWorkflowHandler({
107
111
  }
108
112
  const result = await run.start({
109
113
  triggerData,
110
- container
114
+ runtimeContext
111
115
  });
112
116
  return result;
113
117
  } catch (error) {
@@ -160,7 +164,7 @@ async function createRunHandler({
160
164
  }
161
165
  async function startWorkflowRunHandler({
162
166
  mastra,
163
- container,
167
+ runtimeContext,
164
168
  workflowId,
165
169
  runId,
166
170
  triggerData
@@ -179,7 +183,7 @@ async function startWorkflowRunHandler({
179
183
  }
180
184
  await run.start({
181
185
  triggerData,
182
- container
186
+ runtimeContext
183
187
  });
184
188
  return { message: "Workflow run started" };
185
189
  } catch (e) {
@@ -235,7 +239,7 @@ async function resumeAsyncWorkflowHandler({
235
239
  workflowId,
236
240
  runId,
237
241
  body,
238
- container
242
+ runtimeContext
239
243
  }) {
240
244
  try {
241
245
  if (!workflowId) {
@@ -252,7 +256,7 @@ async function resumeAsyncWorkflowHandler({
252
256
  const result = await run.resume({
253
257
  stepId: body.stepId,
254
258
  context: body.context,
255
- container
259
+ runtimeContext
256
260
  });
257
261
  return result;
258
262
  } catch (error) {
@@ -264,7 +268,7 @@ async function resumeWorkflowHandler({
264
268
  workflowId,
265
269
  runId,
266
270
  body,
267
- container
271
+ runtimeContext
268
272
  }) {
269
273
  try {
270
274
  if (!workflowId) {
@@ -281,7 +285,7 @@ async function resumeWorkflowHandler({
281
285
  await run.resume({
282
286
  stepId: body.stepId,
283
287
  context: body.context,
284
- container
288
+ runtimeContext
285
289
  });
286
290
  return { message: "Workflow run resumed" };
287
291
  } catch (error) {
@@ -0,0 +1,304 @@
1
+ import { stringify, esm_default } from './chunk-OMN3UI6X.js';
2
+ import { handleError } from './chunk-3AHQ5RGN.js';
3
+ import { __export, HTTPException } from './chunk-TRDNDNGQ.js';
4
+ import { ReadableStream } from 'node:stream/web';
5
+
6
+ // src/server/handlers/vNextWorkflows.ts
7
+ var vNextWorkflows_exports = {};
8
+ __export(vNextWorkflows_exports, {
9
+ createVNextWorkflowRunHandler: () => createVNextWorkflowRunHandler,
10
+ getVNextWorkflowByIdHandler: () => getVNextWorkflowByIdHandler,
11
+ getVNextWorkflowRunHandler: () => getVNextWorkflowRunHandler,
12
+ getVNextWorkflowRunsHandler: () => getVNextWorkflowRunsHandler,
13
+ getVNextWorkflowsHandler: () => getVNextWorkflowsHandler,
14
+ resumeAsyncVNextWorkflowHandler: () => resumeAsyncVNextWorkflowHandler,
15
+ resumeVNextWorkflowHandler: () => resumeVNextWorkflowHandler,
16
+ startAsyncVNextWorkflowHandler: () => startAsyncVNextWorkflowHandler,
17
+ startVNextWorkflowRunHandler: () => startVNextWorkflowRunHandler,
18
+ watchVNextWorkflowHandler: () => watchVNextWorkflowHandler
19
+ });
20
+ async function getVNextWorkflowsHandler({ mastra }) {
21
+ try {
22
+ const workflows = mastra.vnext_getWorkflows({ serialized: false });
23
+ const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
24
+ acc[key] = {
25
+ name: workflow.name,
26
+ steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
27
+ acc2[key2] = {
28
+ id: step.id,
29
+ description: step.description,
30
+ inputSchema: step.inputSchema ? stringify(esm_default(step.inputSchema)) : void 0,
31
+ outputSchema: step.outputSchema ? stringify(esm_default(step.outputSchema)) : void 0,
32
+ resumeSchema: step.resumeSchema ? stringify(esm_default(step.resumeSchema)) : void 0,
33
+ suspendSchema: step.suspendSchema ? stringify(esm_default(step.suspendSchema)) : void 0
34
+ };
35
+ return acc2;
36
+ }, {}),
37
+ stepGraph: workflow.serializedStepGraph,
38
+ inputSchema: workflow.inputSchema ? stringify(esm_default(workflow.inputSchema)) : void 0,
39
+ outputSchema: workflow.outputSchema ? stringify(esm_default(workflow.outputSchema)) : void 0
40
+ };
41
+ return acc;
42
+ }, {});
43
+ return _workflows;
44
+ } catch (error) {
45
+ throw new HTTPException(500, { message: error?.message || "Error getting workflows" });
46
+ }
47
+ }
48
+ async function getVNextWorkflowByIdHandler({ mastra, workflowId }) {
49
+ try {
50
+ if (!workflowId) {
51
+ throw new HTTPException(400, { message: "Workflow ID is required" });
52
+ }
53
+ const workflow = mastra.vnext_getWorkflow(workflowId);
54
+ if (!workflow) {
55
+ throw new HTTPException(404, { message: "Workflow not found" });
56
+ }
57
+ return {
58
+ steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
59
+ acc[key] = {
60
+ id: step.id,
61
+ description: step.description,
62
+ inputSchema: step.inputSchema ? stringify(esm_default(step.inputSchema)) : void 0,
63
+ outputSchema: step.outputSchema ? stringify(esm_default(step.outputSchema)) : void 0,
64
+ resumeSchema: step.resumeSchema ? stringify(esm_default(step.resumeSchema)) : void 0,
65
+ suspendSchema: step.suspendSchema ? stringify(esm_default(step.suspendSchema)) : void 0
66
+ };
67
+ return acc;
68
+ }, {}),
69
+ name: workflow.name,
70
+ stepGraph: workflow.serializedStepGraph,
71
+ inputSchema: workflow.inputSchema ? stringify(esm_default(workflow.inputSchema)) : void 0,
72
+ outputSchema: workflow.outputSchema ? stringify(esm_default(workflow.outputSchema)) : void 0
73
+ };
74
+ } catch (error) {
75
+ throw new HTTPException(500, { message: error?.message || "Error getting workflow" });
76
+ }
77
+ }
78
+ async function getVNextWorkflowRunHandler({
79
+ mastra,
80
+ workflowId,
81
+ runId
82
+ }) {
83
+ try {
84
+ if (!workflowId) {
85
+ throw new HTTPException(400, { message: "Workflow ID is required" });
86
+ }
87
+ if (!runId) {
88
+ throw new HTTPException(400, { message: "Run ID is required" });
89
+ }
90
+ const workflow = mastra.vnext_getWorkflow(workflowId);
91
+ if (!workflow) {
92
+ throw new HTTPException(404, { message: "Workflow not found" });
93
+ }
94
+ const run = await workflow.getWorkflowRun(runId);
95
+ if (!run) {
96
+ throw new HTTPException(404, { message: "Workflow run not found" });
97
+ }
98
+ return run;
99
+ } catch (error) {
100
+ throw new HTTPException(500, { message: error?.message || "Error getting workflow run" });
101
+ }
102
+ }
103
+ async function createVNextWorkflowRunHandler({
104
+ mastra,
105
+ workflowId,
106
+ runId: prevRunId
107
+ }) {
108
+ try {
109
+ if (!workflowId) {
110
+ throw new HTTPException(400, { message: "Workflow ID is required" });
111
+ }
112
+ const workflow = mastra.vnext_getWorkflow(workflowId);
113
+ if (!workflow) {
114
+ throw new HTTPException(404, { message: "Workflow not found" });
115
+ }
116
+ const run = workflow.createRun({ runId: prevRunId });
117
+ return { runId: run.runId };
118
+ } catch (error) {
119
+ throw new HTTPException(500, { message: error?.message || "Error creating workflow run" });
120
+ }
121
+ }
122
+ async function startAsyncVNextWorkflowHandler({
123
+ mastra,
124
+ runtimeContext,
125
+ workflowId,
126
+ runId,
127
+ inputData
128
+ }) {
129
+ try {
130
+ if (!workflowId) {
131
+ throw new HTTPException(400, { message: "Workflow ID is required" });
132
+ }
133
+ const workflow = mastra.vnext_getWorkflow(workflowId);
134
+ if (!workflow) {
135
+ throw new HTTPException(404, { message: "Workflow not found" });
136
+ }
137
+ const _run = workflow.createRun({ runId });
138
+ const result = await _run.start({
139
+ inputData,
140
+ runtimeContext
141
+ });
142
+ return result;
143
+ } catch (error) {
144
+ throw new HTTPException(500, { message: error?.message || "Error executing workflow" });
145
+ }
146
+ }
147
+ async function startVNextWorkflowRunHandler({
148
+ mastra,
149
+ runtimeContext,
150
+ workflowId,
151
+ runId,
152
+ inputData
153
+ }) {
154
+ try {
155
+ if (!workflowId) {
156
+ throw new HTTPException(400, { message: "Workflow ID is required" });
157
+ }
158
+ if (!runId) {
159
+ throw new HTTPException(400, { message: "runId required to start run" });
160
+ }
161
+ const workflow = mastra.vnext_getWorkflow(workflowId);
162
+ const run = await workflow.getWorkflowRun(runId);
163
+ if (!run) {
164
+ throw new HTTPException(404, { message: "Workflow run not found" });
165
+ }
166
+ const _run = workflow.createRun({ runId });
167
+ await _run.start({
168
+ inputData,
169
+ runtimeContext
170
+ });
171
+ return { message: "Workflow run started" };
172
+ } catch (e) {
173
+ return handleError(e, "Error starting workflow run");
174
+ }
175
+ }
176
+ async function watchVNextWorkflowHandler({
177
+ mastra,
178
+ workflowId,
179
+ runId
180
+ }) {
181
+ try {
182
+ if (!workflowId) {
183
+ throw new HTTPException(400, { message: "Workflow ID is required" });
184
+ }
185
+ if (!runId) {
186
+ throw new HTTPException(400, { message: "runId required to watch workflow" });
187
+ }
188
+ const workflow = mastra.vnext_getWorkflow(workflowId);
189
+ const run = await workflow.getWorkflowRun(runId);
190
+ if (!run) {
191
+ throw new HTTPException(404, { message: "Workflow run not found" });
192
+ }
193
+ const _run = workflow.createRun({ runId });
194
+ let unwatch;
195
+ let asyncRef = null;
196
+ const stream = new ReadableStream({
197
+ start(controller) {
198
+ unwatch = _run.watch(({ type, payload, eventTimestamp }) => {
199
+ controller.enqueue(JSON.stringify({ type, payload, eventTimestamp, runId }));
200
+ if (asyncRef) {
201
+ clearImmediate(asyncRef);
202
+ asyncRef = null;
203
+ }
204
+ asyncRef = setImmediate(async () => {
205
+ const runDone = payload.workflowState.status !== "running";
206
+ if (runDone) {
207
+ controller.close();
208
+ unwatch?.();
209
+ }
210
+ });
211
+ });
212
+ },
213
+ cancel() {
214
+ unwatch?.();
215
+ }
216
+ });
217
+ return stream;
218
+ } catch (error) {
219
+ return handleError(error, "Error watching workflow");
220
+ }
221
+ }
222
+ async function resumeAsyncVNextWorkflowHandler({
223
+ mastra,
224
+ workflowId,
225
+ runId,
226
+ body,
227
+ runtimeContext
228
+ }) {
229
+ try {
230
+ if (!workflowId) {
231
+ throw new HTTPException(400, { message: "Workflow ID is required" });
232
+ }
233
+ if (!runId) {
234
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
235
+ }
236
+ if (!body.step) {
237
+ throw new HTTPException(400, { message: "step required to resume workflow" });
238
+ }
239
+ const workflow = mastra.vnext_getWorkflow(workflowId);
240
+ const run = await workflow.getWorkflowRun(runId);
241
+ if (!run) {
242
+ throw new HTTPException(404, { message: "Workflow run not found" });
243
+ }
244
+ const _run = workflow.createRun({ runId });
245
+ const result = await _run.resume({
246
+ step: body.step,
247
+ resumeData: body.resumeData,
248
+ runtimeContext
249
+ });
250
+ return result;
251
+ } catch (error) {
252
+ return handleError(error, "Error resuming workflow step");
253
+ }
254
+ }
255
+ async function resumeVNextWorkflowHandler({
256
+ mastra,
257
+ workflowId,
258
+ runId,
259
+ body,
260
+ runtimeContext
261
+ }) {
262
+ try {
263
+ if (!workflowId) {
264
+ throw new HTTPException(400, { message: "Workflow ID is required" });
265
+ }
266
+ if (!runId) {
267
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
268
+ }
269
+ if (!body.step) {
270
+ throw new HTTPException(400, { message: "step required to resume workflow" });
271
+ }
272
+ const workflow = mastra.vnext_getWorkflow(workflowId);
273
+ const run = await workflow.getWorkflowRun(runId);
274
+ if (!run) {
275
+ throw new HTTPException(404, { message: "Workflow run not found" });
276
+ }
277
+ const _run = workflow.createRun({ runId });
278
+ await _run.resume({
279
+ step: body.step,
280
+ resumeData: body.resumeData,
281
+ runtimeContext
282
+ });
283
+ return { message: "Workflow run resumed" };
284
+ } catch (error) {
285
+ return handleError(error, "Error resuming workflow");
286
+ }
287
+ }
288
+ async function getVNextWorkflowRunsHandler({ mastra, workflowId }) {
289
+ try {
290
+ if (!workflowId) {
291
+ throw new HTTPException(400, { message: "Workflow ID is required" });
292
+ }
293
+ const workflow = mastra.vnext_getWorkflow(workflowId);
294
+ const workflowRuns = await workflow.getWorkflowRuns() || {
295
+ runs: [],
296
+ total: 0
297
+ };
298
+ return workflowRuns;
299
+ } catch (error) {
300
+ return handleError(error, "Error getting workflow runs");
301
+ }
302
+ }
303
+
304
+ export { createVNextWorkflowRunHandler, getVNextWorkflowByIdHandler, getVNextWorkflowRunHandler, getVNextWorkflowRunsHandler, getVNextWorkflowsHandler, resumeAsyncVNextWorkflowHandler, resumeVNextWorkflowHandler, startAsyncVNextWorkflowHandler, startVNextWorkflowRunHandler, vNextWorkflows_exports, watchVNextWorkflowHandler };
@@ -32,7 +32,9 @@ async function getWorkflowsHandler({ mastra }) {
32
32
  steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
33
33
  const _step = step;
34
34
  acc2[key2] = {
35
- ..._step,
35
+ id: _step.id,
36
+ description: _step.description,
37
+ workflowId: _step.workflowId,
36
38
  inputSchema: _step.inputSchema ? stringify(esm_default(_step.inputSchema)) : void 0,
37
39
  outputSchema: _step.outputSchema ? stringify(esm_default(_step.outputSchema)) : void 0
38
40
  };
@@ -65,7 +67,9 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
65
67
  steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
66
68
  const _step = step;
67
69
  acc[key] = {
68
- ..._step,
70
+ id: _step.id,
71
+ description: _step.description,
72
+ workflowId: _step.workflowId,
69
73
  inputSchema: _step.inputSchema ? stringify(esm_default(_step.inputSchema)) : void 0,
70
74
  outputSchema: _step.outputSchema ? stringify(esm_default(_step.outputSchema)) : void 0
71
75
  };
@@ -78,7 +82,7 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
78
82
  }
79
83
  async function startAsyncWorkflowHandler({
80
84
  mastra,
81
- container,
85
+ runtimeContext,
82
86
  workflowId,
83
87
  runId,
84
88
  triggerData
@@ -95,7 +99,7 @@ async function startAsyncWorkflowHandler({
95
99
  const { start } = workflow.createRun();
96
100
  const result2 = await start({
97
101
  triggerData,
98
- container
102
+ runtimeContext
99
103
  });
100
104
  return result2;
101
105
  }
@@ -105,7 +109,7 @@ async function startAsyncWorkflowHandler({
105
109
  }
106
110
  const result = await run.start({
107
111
  triggerData,
108
- container
112
+ runtimeContext
109
113
  });
110
114
  return result;
111
115
  } catch (error) {
@@ -158,7 +162,7 @@ async function createRunHandler({
158
162
  }
159
163
  async function startWorkflowRunHandler({
160
164
  mastra,
161
- container,
165
+ runtimeContext,
162
166
  workflowId,
163
167
  runId,
164
168
  triggerData
@@ -177,7 +181,7 @@ async function startWorkflowRunHandler({
177
181
  }
178
182
  await run.start({
179
183
  triggerData,
180
- container
184
+ runtimeContext
181
185
  });
182
186
  return { message: "Workflow run started" };
183
187
  } catch (e) {
@@ -233,7 +237,7 @@ async function resumeAsyncWorkflowHandler({
233
237
  workflowId,
234
238
  runId,
235
239
  body,
236
- container
240
+ runtimeContext
237
241
  }) {
238
242
  try {
239
243
  if (!workflowId) {
@@ -250,7 +254,7 @@ async function resumeAsyncWorkflowHandler({
250
254
  const result = await run.resume({
251
255
  stepId: body.stepId,
252
256
  context: body.context,
253
- container
257
+ runtimeContext
254
258
  });
255
259
  return result;
256
260
  } catch (error) {
@@ -262,7 +266,7 @@ async function resumeWorkflowHandler({
262
266
  workflowId,
263
267
  runId,
264
268
  body,
265
- container
269
+ runtimeContext
266
270
  }) {
267
271
  try {
268
272
  if (!workflowId) {
@@ -279,7 +283,7 @@ async function resumeWorkflowHandler({
279
283
  await run.resume({
280
284
  stepId: body.stepId,
281
285
  context: body.context,
282
- container
286
+ runtimeContext
283
287
  });
284
288
  return { message: "Workflow run resumed" };
285
289
  } catch (error) {
@@ -38,9 +38,7 @@ async function generateSpeechHandler({
38
38
  throw new HTTPException(400, { message: "Agent ID is required" });
39
39
  }
40
40
  validateBody({
41
- text: void 0,
42
- speakerId: void 0,
43
- ...body
41
+ text: body?.text
44
42
  });
45
43
  const agent = mastra.getAgent(agentId);
46
44
  if (!agent) {
@@ -53,12 +51,7 @@ async function generateSpeechHandler({
53
51
  if (!audioStream) {
54
52
  throw new HTTPException(500, { message: "Failed to generate speech" });
55
53
  }
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 };
54
+ return audioStream;
62
55
  } catch (error) {
63
56
  return handleError(error, "Error generating speech");
64
57
  }
@@ -10,33 +10,48 @@ __export(network_exports, {
10
10
  getNetworksHandler: () => getNetworksHandler,
11
11
  streamGenerateHandler: () => streamGenerateHandler
12
12
  });
13
- async function getNetworksHandler({ mastra }) {
13
+ async function getNetworksHandler({
14
+ mastra,
15
+ runtimeContext
16
+ }) {
14
17
  try {
15
18
  const networks = mastra.getNetworks();
16
- const serializedNetworks = networks.map((network) => {
17
- const routingAgent = network.getRoutingAgent();
18
- const agents = network.getAgents();
19
- return {
20
- id: network.formatAgentId(routingAgent.name),
21
- name: routingAgent.name,
22
- instructions: routingAgent.instructions,
23
- agents: agents.map((agent) => ({
24
- name: agent.name,
25
- provider: agent.llm?.getProvider(),
26
- modelId: agent.llm?.getModelId()
27
- })),
28
- routingModel: {
29
- provider: routingAgent.llm?.getProvider(),
30
- modelId: routingAgent.llm?.getModelId()
31
- }
32
- };
33
- });
19
+ const serializedNetworks = await Promise.all(
20
+ networks.map(async (network) => {
21
+ const routingAgent = network.getRoutingAgent();
22
+ const routingLLM = await routingAgent.getLLM({ runtimeContext });
23
+ const agents = network.getAgents();
24
+ return {
25
+ id: network.formatAgentId(routingAgent.name),
26
+ name: routingAgent.name,
27
+ instructions: routingAgent.instructions,
28
+ agents: await Promise.all(
29
+ agents.map(async (agent) => {
30
+ const llm = await agent.getLLM({ runtimeContext });
31
+ return {
32
+ name: agent.name,
33
+ provider: llm?.getProvider(),
34
+ modelId: llm?.getModelId()
35
+ };
36
+ })
37
+ ),
38
+ routingModel: {
39
+ provider: routingLLM?.getProvider(),
40
+ modelId: routingLLM?.getModelId()
41
+ }
42
+ };
43
+ })
44
+ );
34
45
  return serializedNetworks;
35
46
  } catch (error) {
36
47
  return handleError(error, "Error getting networks");
37
48
  }
38
49
  }
39
- async function getNetworkByIdHandler({ mastra, networkId }) {
50
+ async function getNetworkByIdHandler({
51
+ mastra,
52
+ networkId,
53
+ runtimeContext
54
+ }) {
40
55
  try {
41
56
  const networks = mastra.getNetworks();
42
57
  const network = networks.find((network2) => {
@@ -47,19 +62,25 @@ async function getNetworkByIdHandler({ mastra, networkId }) {
47
62
  throw new HTTPException(404, { message: "Network not found" });
48
63
  }
49
64
  const routingAgent = network.getRoutingAgent();
65
+ const routingLLM = await routingAgent.getLLM({ runtimeContext });
50
66
  const agents = network.getAgents();
51
67
  const serializedNetwork = {
52
68
  id: network.formatAgentId(routingAgent.name),
53
69
  name: routingAgent.name,
54
70
  instructions: routingAgent.instructions,
55
- agents: agents.map((agent) => ({
56
- name: agent.name,
57
- provider: agent.llm?.getProvider(),
58
- modelId: agent.llm?.getModelId()
59
- })),
71
+ agents: await Promise.all(
72
+ agents.map(async (agent) => {
73
+ const llm = await agent.getLLM({ runtimeContext });
74
+ return {
75
+ name: agent.name,
76
+ provider: llm?.getProvider(),
77
+ modelId: llm?.getModelId()
78
+ };
79
+ })
80
+ ),
60
81
  routingModel: {
61
- provider: routingAgent.llm?.getProvider(),
62
- modelId: routingAgent.llm?.getModelId()
82
+ provider: routingLLM?.getProvider(),
83
+ modelId: routingLLM?.getModelId()
63
84
  }
64
85
  };
65
86
  return serializedNetwork;
@@ -69,7 +90,7 @@ async function getNetworkByIdHandler({ mastra, networkId }) {
69
90
  }
70
91
  async function generateHandler({
71
92
  mastra,
72
- container,
93
+ runtimeContext,
73
94
  networkId,
74
95
  body
75
96
  }) {
@@ -80,7 +101,7 @@ async function generateHandler({
80
101
  }
81
102
  validateBody({ messages: body.messages });
82
103
  const { messages, ...rest } = body;
83
- const result = await network.generate(messages, { ...rest, container });
104
+ const result = await network.generate(messages, { ...rest, runtimeContext });
84
105
  return result;
85
106
  } catch (error) {
86
107
  return handleError(error, "Error generating from network");
@@ -90,7 +111,7 @@ async function streamGenerateHandler({
90
111
  mastra,
91
112
  networkId,
92
113
  body,
93
- container
114
+ runtimeContext
94
115
  }) {
95
116
  try {
96
117
  const network = mastra.getNetwork(networkId);
@@ -102,7 +123,7 @@ async function streamGenerateHandler({
102
123
  const streamResult = await network.stream(messages, {
103
124
  output,
104
125
  ...rest,
105
- container
126
+ runtimeContext
106
127
  });
107
128
  const streamResponse = output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
108
129
  sendUsage: true,