@mastra/server 0.0.0-message-ordering-20250415215612 → 0.0.0-redis-cloud-transporter-20250508191651

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 (40) hide show
  1. package/README.md +48 -135
  2. package/dist/_tsup-dts-rollup.d.cts +128 -31
  3. package/dist/_tsup-dts-rollup.d.ts +128 -31
  4. package/dist/{chunk-OPP7H5TW.js → chunk-3XTEV33Q.js} +26 -14
  5. package/dist/{chunk-A7DF4ETD.cjs → chunk-55HTWX4C.cjs} +2 -9
  6. package/dist/{chunk-UV4WTEH4.js → chunk-5JNVY6DU.js} +5 -5
  7. package/dist/{chunk-QH6XWSXP.cjs → chunk-5SWCVTNL.cjs} +38 -38
  8. package/dist/{chunk-JLDXUWK7.cjs → chunk-5YGDYMRB.cjs} +52 -31
  9. package/dist/{chunk-Z46X3YCB.cjs → chunk-6Q7UXAYJ.cjs} +72 -38
  10. package/dist/{chunk-CWSDZEZG.cjs → chunk-AMVOS7YB.cjs} +6 -4
  11. package/dist/{chunk-DVPP5S6I.js → chunk-BPL2CBLV.js} +6 -4
  12. package/dist/{chunk-B64YROKU.cjs → chunk-CHFORQ7J.cjs} +32 -20
  13. package/dist/{chunk-PDC4ZBQW.cjs → chunk-D3G23FP3.cjs} +9 -9
  14. package/dist/{chunk-67WTHYAV.js → chunk-GVBJ5I2S.js} +70 -36
  15. package/dist/chunk-M2RXDCPV.cjs +324 -0
  16. package/dist/{chunk-VK6FX47H.js → chunk-OMN3UI6X.js} +38 -38
  17. package/dist/chunk-OWNA6I2H.js +312 -0
  18. package/dist/{chunk-3RVHWGWO.js → chunk-Q6SHQECN.js} +2 -9
  19. package/dist/{chunk-YANVFOYA.js → chunk-QJ3AHN64.js} +52 -31
  20. package/dist/server/handlers/agents.cjs +7 -7
  21. package/dist/server/handlers/agents.js +1 -1
  22. package/dist/server/handlers/network.cjs +5 -5
  23. package/dist/server/handlers/network.js +1 -1
  24. package/dist/server/handlers/telemetry.cjs +3 -3
  25. package/dist/server/handlers/telemetry.js +1 -1
  26. package/dist/server/handlers/tools.cjs +5 -5
  27. package/dist/server/handlers/tools.js +1 -1
  28. package/dist/server/handlers/vNextWorkflows.cjs +46 -0
  29. package/dist/server/handlers/vNextWorkflows.d.cts +10 -0
  30. package/dist/server/handlers/vNextWorkflows.d.ts +10 -0
  31. package/dist/server/handlers/vNextWorkflows.js +1 -0
  32. package/dist/server/handlers/voice.cjs +4 -4
  33. package/dist/server/handlers/voice.js +1 -1
  34. package/dist/server/handlers/workflows.cjs +11 -11
  35. package/dist/server/handlers/workflows.js +1 -1
  36. package/dist/server/handlers.cjs +17 -12
  37. package/dist/server/handlers.d.cts +1 -0
  38. package/dist/server/handlers.d.ts +1 -0
  39. package/dist/server/handlers.js +7 -6
  40. package/package.json +6 -6
@@ -22,19 +22,21 @@ async function getTelemetryHandler({ mastra, body }) {
22
22
  if (!body) {
23
23
  throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Body is required" });
24
24
  }
25
- const { name, scope, page, perPage, attribute } = body;
25
+ const { name, scope, page, perPage, attribute, fromDate, toDate } = body;
26
26
  const attributes = attribute ? Object.fromEntries(
27
27
  (Array.isArray(attribute) ? attribute : [attribute]).map((attr) => {
28
28
  const [key, value] = attr.split(":");
29
29
  return [key, value];
30
30
  })
31
31
  ) : void 0;
32
- const traces = await storage.__getTraces({
32
+ const traces = await storage.getTraces({
33
33
  name,
34
34
  scope,
35
35
  page: Number(page ?? 0),
36
36
  perPage: Number(perPage ?? 100),
37
- attributes
37
+ attributes,
38
+ fromDate: fromDate ? new Date(fromDate) : void 0,
39
+ toDate: toDate ? new Date(toDate) : void 0
38
40
  });
39
41
  return traces;
40
42
  } catch (error2) {
@@ -107,7 +109,7 @@ async function storeTelemetryHandler({ mastra, body }) {
107
109
  }
108
110
  return acc;
109
111
  }, []);
110
- return storage.__batchTraceInsert({
112
+ return storage.batchTraceInsert({
111
113
  records: allSpans
112
114
  }).then(() => {
113
115
  return {
@@ -20,19 +20,21 @@ async function getTelemetryHandler({ mastra, body }) {
20
20
  if (!body) {
21
21
  throw new HTTPException(400, { message: "Body is required" });
22
22
  }
23
- const { name, scope, page, perPage, attribute } = body;
23
+ const { name, scope, page, perPage, attribute, fromDate, toDate } = body;
24
24
  const attributes = attribute ? Object.fromEntries(
25
25
  (Array.isArray(attribute) ? attribute : [attribute]).map((attr) => {
26
26
  const [key, value] = attr.split(":");
27
27
  return [key, value];
28
28
  })
29
29
  ) : void 0;
30
- const traces = await storage.__getTraces({
30
+ const traces = await storage.getTraces({
31
31
  name,
32
32
  scope,
33
33
  page: Number(page ?? 0),
34
34
  perPage: Number(perPage ?? 100),
35
- attributes
35
+ attributes,
36
+ fromDate: fromDate ? new Date(fromDate) : void 0,
37
+ toDate: toDate ? new Date(toDate) : void 0
36
38
  });
37
39
  return traces;
38
40
  } catch (error2) {
@@ -105,7 +107,7 @@ async function storeTelemetryHandler({ mastra, body }) {
105
107
  }
106
108
  return acc;
107
109
  }, []);
108
- return storage.__batchTraceInsert({
110
+ return storage.batchTraceInsert({
109
111
  records: allSpans
110
112
  }).then(() => {
111
113
  return {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkQH6XWSXP_cjs = require('./chunk-QH6XWSXP.cjs');
3
+ var chunk5SWCVTNL_cjs = require('./chunk-5SWCVTNL.cjs');
4
4
  var chunkZLBRQFDD_cjs = require('./chunk-ZLBRQFDD.cjs');
5
5
  var chunkFV45V6WC_cjs = require('./chunk-FV45V6WC.cjs');
6
6
  var web = require('stream/web');
@@ -30,13 +30,15 @@ async function getWorkflowsHandler({ mastra }) {
30
30
  serializedStepGraph: workflow.serializedStepGraph,
31
31
  serializedStepSubscriberGraph: workflow.serializedStepSubscriberGraph,
32
32
  name: workflow.name,
33
- triggerSchema: workflow.triggerSchema ? chunkQH6XWSXP_cjs.stringify(chunkQH6XWSXP_cjs.esm_default(workflow.triggerSchema)) : void 0,
33
+ triggerSchema: workflow.triggerSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(workflow.triggerSchema)) : void 0,
34
34
  steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
35
35
  const _step = step;
36
36
  acc2[key2] = {
37
- ..._step,
38
- inputSchema: _step.inputSchema ? chunkQH6XWSXP_cjs.stringify(chunkQH6XWSXP_cjs.esm_default(_step.inputSchema)) : void 0,
39
- outputSchema: _step.outputSchema ? chunkQH6XWSXP_cjs.stringify(chunkQH6XWSXP_cjs.esm_default(_step.outputSchema)) : void 0
37
+ id: _step.id,
38
+ description: _step.description,
39
+ workflowId: _step.workflowId,
40
+ inputSchema: _step.inputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_step.inputSchema)) : void 0,
41
+ outputSchema: _step.outputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_step.outputSchema)) : void 0
40
42
  };
41
43
  return acc2;
42
44
  }, {})
@@ -63,13 +65,15 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
63
65
  serializedStepGraph: workflow.serializedStepGraph,
64
66
  serializedStepSubscriberGraph: workflow.serializedStepSubscriberGraph,
65
67
  name: workflow.name,
66
- triggerSchema: workflow.triggerSchema ? chunkQH6XWSXP_cjs.stringify(chunkQH6XWSXP_cjs.esm_default(workflow.triggerSchema)) : void 0,
68
+ triggerSchema: workflow.triggerSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(workflow.triggerSchema)) : void 0,
67
69
  steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
68
70
  const _step = step;
69
71
  acc[key] = {
70
- ..._step,
71
- inputSchema: _step.inputSchema ? chunkQH6XWSXP_cjs.stringify(chunkQH6XWSXP_cjs.esm_default(_step.inputSchema)) : void 0,
72
- outputSchema: _step.outputSchema ? chunkQH6XWSXP_cjs.stringify(chunkQH6XWSXP_cjs.esm_default(_step.outputSchema)) : void 0
72
+ id: _step.id,
73
+ description: _step.description,
74
+ workflowId: _step.workflowId,
75
+ inputSchema: _step.inputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_step.inputSchema)) : void 0,
76
+ outputSchema: _step.outputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_step.outputSchema)) : void 0
73
77
  };
74
78
  return acc;
75
79
  }, {})
@@ -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,20 +285,28 @@ 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) {
288
292
  return chunkZLBRQFDD_cjs.handleError(error, "Error resuming workflow");
289
293
  }
290
294
  }
291
- async function getWorkflowRunsHandler({ mastra, workflowId }) {
295
+ async function getWorkflowRunsHandler({
296
+ mastra,
297
+ workflowId,
298
+ fromDate,
299
+ toDate,
300
+ limit,
301
+ offset,
302
+ resourceId
303
+ }) {
292
304
  try {
293
305
  if (!workflowId) {
294
306
  throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Workflow ID is required" });
295
307
  }
296
308
  const workflow = mastra.getWorkflow(workflowId);
297
- const workflowRuns = await workflow.getWorkflowRuns() || {
309
+ const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
298
310
  runs: [],
299
311
  total: 0
300
312
  };
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkQH6XWSXP_cjs = require('./chunk-QH6XWSXP.cjs');
3
+ var chunk5SWCVTNL_cjs = require('./chunk-5SWCVTNL.cjs');
4
4
  var chunkQN4KF3BH_cjs = require('./chunk-QN4KF3BH.cjs');
5
5
  var chunkZLBRQFDD_cjs = require('./chunk-ZLBRQFDD.cjs');
6
6
  var chunkFV45V6WC_cjs = require('./chunk-FV45V6WC.cjs');
@@ -24,8 +24,8 @@ async function getToolsHandler({ tools }) {
24
24
  const tool = _tool;
25
25
  acc[id] = {
26
26
  ...tool,
27
- inputSchema: tool.inputSchema ? chunkQH6XWSXP_cjs.stringify(chunkQH6XWSXP_cjs.esm_default(tool.inputSchema)) : void 0,
28
- outputSchema: tool.outputSchema ? chunkQH6XWSXP_cjs.stringify(chunkQH6XWSXP_cjs.esm_default(tool.outputSchema)) : void 0
27
+ inputSchema: tool.inputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(tool.inputSchema)) : void 0,
28
+ outputSchema: tool.outputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(tool.outputSchema)) : void 0
29
29
  };
30
30
  return acc;
31
31
  },
@@ -44,8 +44,8 @@ async function getToolByIdHandler({ tools, toolId }) {
44
44
  }
45
45
  const serializedTool = {
46
46
  ...tool,
47
- inputSchema: tool.inputSchema ? chunkQH6XWSXP_cjs.stringify(chunkQH6XWSXP_cjs.esm_default(tool.inputSchema)) : void 0,
48
- outputSchema: tool.outputSchema ? chunkQH6XWSXP_cjs.stringify(chunkQH6XWSXP_cjs.esm_default(tool.outputSchema)) : void 0
47
+ inputSchema: tool.inputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(tool.inputSchema)) : void 0,
48
+ outputSchema: tool.outputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(tool.outputSchema)) : void 0
49
49
  };
50
50
  return serializedTool;
51
51
  } catch (error) {
@@ -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
  });
@@ -1,7 +1,8 @@
1
- import { stringify, esm_default } from './chunk-VK6FX47H.js';
1
+ import { stringify, esm_default } from './chunk-OMN3UI6X.js';
2
2
  import { validateBody } from './chunk-L7XE5QTW.js';
3
3
  import { handleError } from './chunk-3AHQ5RGN.js';
4
4
  import { __export, HTTPException } from './chunk-TRDNDNGQ.js';
5
+ import { RuntimeContext } from '@mastra/core/runtime-context';
5
6
 
6
7
  // src/server/handlers/agents.ts
7
8
  var agents_exports = {};
@@ -13,27 +14,35 @@ __export(agents_exports, {
13
14
  getLiveEvalsByAgentIdHandler: () => getLiveEvalsByAgentIdHandler,
14
15
  streamGenerateHandler: () => streamGenerateHandler
15
16
  });
16
- async function getAgentsHandler({ mastra }) {
17
+ async function getAgentsHandler({ mastra, runtimeContext }) {
17
18
  try {
18
19
  const agents = mastra.getAgents();
19
- const serializedAgents = Object.entries(agents).reduce((acc, [_id, _agent]) => {
20
- const agent = _agent;
21
- const serializedAgentTools = Object.entries(agent?.tools || {}).reduce((acc2, [key, tool]) => {
22
- const _tool = tool;
23
- acc2[key] = {
24
- ..._tool,
25
- inputSchema: _tool.inputSchema ? stringify(esm_default(_tool.inputSchema)) : void 0,
26
- outputSchema: _tool.outputSchema ? stringify(esm_default(_tool.outputSchema)) : void 0
20
+ const serializedAgentsMap = await Promise.all(
21
+ Object.entries(agents).map(async ([id, agent]) => {
22
+ const instructions = await agent.getInstructions({ runtimeContext });
23
+ const tools = await agent.getTools({ runtimeContext });
24
+ const llm = await agent.getLLM({ runtimeContext });
25
+ const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
26
+ const _tool = tool;
27
+ acc[key] = {
28
+ ..._tool,
29
+ inputSchema: _tool.inputSchema ? stringify(esm_default(_tool.inputSchema)) : void 0,
30
+ outputSchema: _tool.outputSchema ? stringify(esm_default(_tool.outputSchema)) : void 0
31
+ };
32
+ return acc;
33
+ }, {});
34
+ return {
35
+ id,
36
+ name: agent.name,
37
+ instructions,
38
+ tools: serializedAgentTools,
39
+ provider: llm?.getProvider(),
40
+ modelId: llm?.getModelId()
27
41
  };
28
- return acc2;
29
- }, {});
30
- acc[_id] = {
31
- name: agent.name,
32
- instructions: agent.instructions,
33
- tools: serializedAgentTools,
34
- provider: agent.llm?.getProvider(),
35
- modelId: agent.llm?.getModelId()
36
- };
42
+ })
43
+ );
44
+ const serializedAgents = serializedAgentsMap.reduce((acc, { id, ...rest }) => {
45
+ acc[id] = rest;
37
46
  return acc;
38
47
  }, {});
39
48
  return serializedAgents;
@@ -41,13 +50,18 @@ async function getAgentsHandler({ mastra }) {
41
50
  return handleError(error, "Error getting agents");
42
51
  }
43
52
  }
44
- async function getAgentByIdHandler({ mastra, agentId }) {
53
+ async function getAgentByIdHandler({
54
+ mastra,
55
+ runtimeContext,
56
+ agentId
57
+ }) {
45
58
  try {
46
59
  const agent = mastra.getAgent(agentId);
47
60
  if (!agent) {
48
61
  throw new HTTPException(404, { message: "Agent not found" });
49
62
  }
50
- const serializedAgentTools = Object.entries(agent?.tools || {}).reduce((acc, [key, tool]) => {
63
+ const tools = await agent.getTools({ runtimeContext });
64
+ const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
51
65
  const _tool = tool;
52
66
  acc[key] = {
53
67
  ..._tool,
@@ -56,39 +70,51 @@ async function getAgentByIdHandler({ mastra, agentId }) {
56
70
  };
57
71
  return acc;
58
72
  }, {});
73
+ const instructions = await agent.getInstructions({ runtimeContext });
74
+ const llm = await agent.getLLM({ runtimeContext });
59
75
  return {
60
76
  name: agent.name,
61
- instructions: agent.instructions,
77
+ instructions,
62
78
  tools: serializedAgentTools,
63
- provider: agent.llm?.getProvider(),
64
- modelId: agent.llm?.getModelId()
79
+ provider: llm?.getProvider(),
80
+ modelId: llm?.getModelId()
65
81
  };
66
82
  } catch (error) {
67
83
  return handleError(error, "Error getting agent");
68
84
  }
69
85
  }
70
- async function getEvalsByAgentIdHandler({ mastra, agentId }) {
86
+ async function getEvalsByAgentIdHandler({
87
+ mastra,
88
+ runtimeContext,
89
+ agentId
90
+ }) {
71
91
  try {
72
92
  const agent = mastra.getAgent(agentId);
73
- const evals = await mastra.getStorage()?.__getEvalsByAgentName?.(agent.name, "test") || [];
93
+ const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
94
+ const instructions = await agent.getInstructions({ runtimeContext });
74
95
  return {
75
96
  id: agentId,
76
97
  name: agent.name,
77
- instructions: agent.instructions,
98
+ instructions,
78
99
  evals
79
100
  };
80
101
  } catch (error) {
81
102
  return handleError(error, "Error getting test evals");
82
103
  }
83
104
  }
84
- async function getLiveEvalsByAgentIdHandler({ mastra, agentId }) {
105
+ async function getLiveEvalsByAgentIdHandler({
106
+ mastra,
107
+ runtimeContext,
108
+ agentId
109
+ }) {
85
110
  try {
86
111
  const agent = mastra.getAgent(agentId);
87
- const evals = await mastra.getStorage()?.__getEvalsByAgentName?.(agent.name, "live") || [];
112
+ const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
113
+ const instructions = await agent.getInstructions({ runtimeContext });
88
114
  return {
89
115
  id: agentId,
90
116
  name: agent.name,
91
- instructions: agent.instructions,
117
+ instructions,
92
118
  evals
93
119
  };
94
120
  } catch (error) {
@@ -97,7 +123,7 @@ async function getLiveEvalsByAgentIdHandler({ mastra, agentId }) {
97
123
  }
98
124
  async function generateHandler({
99
125
  mastra,
100
- container,
126
+ runtimeContext,
101
127
  agentId,
102
128
  body
103
129
  }) {
@@ -106,14 +132,18 @@ async function generateHandler({
106
132
  if (!agent) {
107
133
  throw new HTTPException(404, { message: "Agent not found" });
108
134
  }
109
- const { messages, resourceId, resourceid, ...rest } = body;
135
+ const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
110
136
  const finalResourceId = resourceId ?? resourceid;
137
+ const finalRuntimeContext = new RuntimeContext([
138
+ ...Array.from(runtimeContext.entries()),
139
+ ...Array.from(Object.entries(agentRuntimeContext ?? {}))
140
+ ]);
111
141
  validateBody({ messages });
112
142
  const result = await agent.generate(messages, {
113
143
  ...rest,
114
144
  // @ts-expect-error TODO fix types
115
145
  resourceId: finalResourceId,
116
- container
146
+ runtimeContext: finalRuntimeContext
117
147
  });
118
148
  return result;
119
149
  } catch (error) {
@@ -122,7 +152,7 @@ async function generateHandler({
122
152
  }
123
153
  async function streamGenerateHandler({
124
154
  mastra,
125
- container,
155
+ runtimeContext,
126
156
  agentId,
127
157
  body
128
158
  }) {
@@ -131,14 +161,18 @@ async function streamGenerateHandler({
131
161
  if (!agent) {
132
162
  throw new HTTPException(404, { message: "Agent not found" });
133
163
  }
134
- const { messages, resourceId, resourceid, ...rest } = body;
164
+ const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
135
165
  const finalResourceId = resourceId ?? resourceid;
166
+ const finalRuntimeContext = new RuntimeContext([
167
+ ...Array.from(runtimeContext.entries()),
168
+ ...Array.from(Object.entries(agentRuntimeContext ?? {}))
169
+ ]);
136
170
  validateBody({ messages });
137
171
  const streamResult = await agent.stream(messages, {
138
172
  ...rest,
139
173
  // @ts-expect-error TODO fix types
140
174
  resourceId: finalResourceId,
141
- container
175
+ runtimeContext: finalRuntimeContext
142
176
  });
143
177
  const streamResponse = rest.output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
144
178
  sendUsage: true,