@mastra/server 0.0.0-error-handler-fix-20251020202607 → 0.0.0-export-agent-memory-from-local-studio-20251112153946

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 (179) hide show
  1. package/CHANGELOG.md +802 -3
  2. package/README.md +1 -1
  3. package/dist/{chunk-FWO7VQDC.js → chunk-2IS5WICF.js} +7079 -1524
  4. package/dist/chunk-2IS5WICF.js.map +1 -0
  5. package/dist/{chunk-SPRRK3P7.cjs → chunk-2YZH5PH6.cjs} +47 -47
  6. package/dist/chunk-2YZH5PH6.cjs.map +1 -0
  7. package/dist/{chunk-BATEJLED.js → chunk-3AMNUUZF.js} +20 -20
  8. package/dist/chunk-3AMNUUZF.js.map +1 -0
  9. package/dist/{chunk-AW5BU3RQ.js → chunk-3F52QCI4.js} +40 -40
  10. package/dist/chunk-3F52QCI4.js.map +1 -0
  11. package/dist/{chunk-OEOGYAQC.js → chunk-4JF5WXPL.js} +155 -206
  12. package/dist/chunk-4JF5WXPL.js.map +1 -0
  13. package/dist/{chunk-7NADHFD2.cjs → chunk-64ITUOXI.cjs} +2 -2
  14. package/dist/chunk-64ITUOXI.cjs.map +1 -0
  15. package/dist/{chunk-MMROOK5J.js → chunk-6QWQZI4Q.js} +2 -2
  16. package/dist/{chunk-7NADHFD2.cjs.map → chunk-6QWQZI4Q.js.map} +1 -1
  17. package/dist/{chunk-ABRFV4XP.js → chunk-73PAWDM5.js} +13 -13
  18. package/dist/chunk-73PAWDM5.js.map +1 -0
  19. package/dist/{chunk-2S4IMB6E.cjs → chunk-A24TSVEZ.cjs} +39 -39
  20. package/dist/chunk-A24TSVEZ.cjs.map +1 -0
  21. package/dist/chunk-A2NPD5N6.cjs +517 -0
  22. package/dist/chunk-A2NPD5N6.cjs.map +1 -0
  23. package/dist/{chunk-QQXMIP6C.js → chunk-B3Z6J745.js} +17 -17
  24. package/dist/chunk-B3Z6J745.js.map +1 -0
  25. package/dist/{chunk-G4PUALCE.cjs → chunk-BTWIR2B7.cjs} +4 -4
  26. package/dist/{chunk-G4PUALCE.cjs.map → chunk-BTWIR2B7.cjs.map} +1 -1
  27. package/dist/{chunk-YWOK4F5A.js → chunk-D7T74TVR.js} +4 -6
  28. package/dist/chunk-D7T74TVR.js.map +1 -0
  29. package/dist/{chunk-FHSOPERI.cjs → chunk-EHACNWDL.cjs} +221 -242
  30. package/dist/chunk-EHACNWDL.cjs.map +1 -0
  31. package/dist/{chunk-HPXAM2PG.js → chunk-FPBYKMIS.js} +13 -13
  32. package/dist/chunk-FPBYKMIS.js.map +1 -0
  33. package/dist/{chunk-3SNGNFUJ.cjs → chunk-GLAZTMX3.cjs} +37 -37
  34. package/dist/chunk-GLAZTMX3.cjs.map +1 -0
  35. package/dist/{chunk-7HDOBOGG.cjs → chunk-ID6JYDNL.cjs} +7102 -1544
  36. package/dist/chunk-ID6JYDNL.cjs.map +1 -0
  37. package/dist/{chunk-TRGAMKHX.cjs → chunk-KF3RI45U.cjs} +46 -41
  38. package/dist/chunk-KF3RI45U.cjs.map +1 -0
  39. package/dist/{chunk-TOP25AIO.cjs → chunk-KJIDZQRA.cjs} +14 -14
  40. package/dist/chunk-KJIDZQRA.cjs.map +1 -0
  41. package/dist/{chunk-MYR4PVGN.js → chunk-KWH5QBXP.js} +4 -4
  42. package/dist/{chunk-MYR4PVGN.js.map → chunk-KWH5QBXP.js.map} +1 -1
  43. package/dist/{chunk-AHB4JCIQ.js → chunk-ND5OKOMT.js} +31 -26
  44. package/dist/chunk-ND5OKOMT.js.map +1 -0
  45. package/dist/{chunk-XN74I6VW.cjs → chunk-PPMIB3FQ.cjs} +20 -20
  46. package/dist/chunk-PPMIB3FQ.cjs.map +1 -0
  47. package/dist/{chunk-XVPBGW6Y.cjs → chunk-QU6N55W6.cjs} +9 -9
  48. package/dist/{chunk-XVPBGW6Y.cjs.map → chunk-QU6N55W6.cjs.map} +1 -1
  49. package/dist/{chunk-EP3JQDPD.cjs → chunk-S54HNARD.cjs} +18 -18
  50. package/dist/{chunk-EP3JQDPD.cjs.map → chunk-S54HNARD.cjs.map} +1 -1
  51. package/dist/{chunk-SIW6CYO3.js → chunk-SHWNNZBL.js} +7 -7
  52. package/dist/{chunk-SIW6CYO3.js.map → chunk-SHWNNZBL.js.map} +1 -1
  53. package/dist/{chunk-4QCXUEAT.js → chunk-SZIFSF4T.js} +3 -3
  54. package/dist/{chunk-4QCXUEAT.js.map → chunk-SZIFSF4T.js.map} +1 -1
  55. package/dist/{chunk-FZNS32WJ.js → chunk-TOCYBDP2.js} +4 -4
  56. package/dist/{chunk-FZNS32WJ.js.map → chunk-TOCYBDP2.js.map} +1 -1
  57. package/dist/{chunk-CY4TP3FK.js → chunk-UXGQZUYZ.js} +3 -3
  58. package/dist/{chunk-CY4TP3FK.js.map → chunk-UXGQZUYZ.js.map} +1 -1
  59. package/dist/{chunk-RE4RPXT2.cjs → chunk-V5WWQN7P.cjs} +4 -4
  60. package/dist/{chunk-RE4RPXT2.cjs.map → chunk-V5WWQN7P.cjs.map} +1 -1
  61. package/dist/{chunk-VY4ENABS.cjs → chunk-W2KMU354.cjs} +4 -6
  62. package/dist/chunk-W2KMU354.cjs.map +1 -0
  63. package/dist/chunk-X3MICMI2.cjs +620 -0
  64. package/dist/chunk-X3MICMI2.cjs.map +1 -0
  65. package/dist/{chunk-OYL5TBJW.cjs → chunk-X6C7BUWN.cjs} +4 -4
  66. package/dist/{chunk-OYL5TBJW.cjs.map → chunk-X6C7BUWN.cjs.map} +1 -1
  67. package/dist/{chunk-XDAYZS6N.js → chunk-Z2O5YVHY.js} +190 -211
  68. package/dist/chunk-Z2O5YVHY.js.map +1 -0
  69. package/dist/{chunk-DB63UMTV.js → chunk-ZJ6KEY6H.js} +110 -170
  70. package/dist/chunk-ZJ6KEY6H.js.map +1 -0
  71. package/dist/server/handlers/a2a.cjs +7 -7
  72. package/dist/server/handlers/a2a.d.ts +10 -10
  73. package/dist/server/handlers/a2a.d.ts.map +1 -1
  74. package/dist/server/handlers/a2a.js +1 -1
  75. package/dist/server/handlers/agent-builder.cjs +31 -19
  76. package/dist/server/handlers/agent-builder.d.ts +38 -47
  77. package/dist/server/handlers/agent-builder.d.ts.map +1 -1
  78. package/dist/server/handlers/agent-builder.js +1 -1
  79. package/dist/server/handlers/agents.cjs +26 -26
  80. package/dist/server/handlers/agents.d.ts +44 -54
  81. package/dist/server/handlers/agents.d.ts.map +1 -1
  82. package/dist/server/handlers/agents.js +1 -1
  83. package/dist/server/handlers/error.cjs +2 -2
  84. package/dist/server/handlers/error.js +1 -1
  85. package/dist/server/handlers/logs.cjs +7 -7
  86. package/dist/server/handlers/logs.d.ts +3 -3
  87. package/dist/server/handlers/logs.d.ts.map +1 -1
  88. package/dist/server/handlers/logs.js +1 -1
  89. package/dist/server/handlers/memory.cjs +17 -25
  90. package/dist/server/handlers/memory.d.ts +28 -34
  91. package/dist/server/handlers/memory.d.ts.map +1 -1
  92. package/dist/server/handlers/memory.js +1 -1
  93. package/dist/server/handlers/observability.cjs +8 -8
  94. package/dist/server/handlers/observability.d.ts +12 -12
  95. package/dist/server/handlers/observability.d.ts.map +1 -1
  96. package/dist/server/handlers/observability.js +1 -1
  97. package/dist/server/handlers/scores.cjs +11 -11
  98. package/dist/server/handlers/scores.d.ts +24 -24
  99. package/dist/server/handlers/scores.d.ts.map +1 -1
  100. package/dist/server/handlers/scores.js +1 -1
  101. package/dist/server/handlers/tools.cjs +7 -7
  102. package/dist/server/handlers/tools.d.ts +8 -8
  103. package/dist/server/handlers/tools.d.ts.map +1 -1
  104. package/dist/server/handlers/tools.js +1 -1
  105. package/dist/server/handlers/utils.cjs +3 -3
  106. package/dist/server/handlers/utils.js +1 -1
  107. package/dist/server/handlers/vector.cjs +7 -7
  108. package/dist/server/handlers/vector.js +1 -1
  109. package/dist/server/handlers/voice.cjs +5 -5
  110. package/dist/server/handlers/voice.d.ts +6 -6
  111. package/dist/server/handlers/voice.js +1 -1
  112. package/dist/server/handlers/workflows.cjs +27 -27
  113. package/dist/server/handlers/workflows.d.ts +34 -37
  114. package/dist/server/handlers/workflows.d.ts.map +1 -1
  115. package/dist/server/handlers/workflows.js +1 -1
  116. package/dist/server/handlers.cjs +26 -36
  117. package/dist/server/handlers.d.ts +0 -2
  118. package/dist/server/handlers.d.ts.map +1 -1
  119. package/dist/server/handlers.js +11 -13
  120. package/dist/server/http-exception.d.ts +0 -5
  121. package/dist/server/http-exception.d.ts.map +1 -1
  122. package/dist/server/utils.d.ts +3 -2
  123. package/dist/server/utils.d.ts.map +1 -1
  124. package/dist/{token-53CFGXUO.cjs → token-375W3LEI.cjs} +10 -10
  125. package/dist/{token-53CFGXUO.cjs.map → token-375W3LEI.cjs.map} +1 -1
  126. package/dist/{token-WAEKDUVY.js → token-C3IMNCC4.js} +8 -8
  127. package/dist/{token-WAEKDUVY.js.map → token-C3IMNCC4.js.map} +1 -1
  128. package/dist/token-util-CV3RRG6K.cjs +9 -0
  129. package/dist/{token-util-S4A355II.cjs.map → token-util-CV3RRG6K.cjs.map} +1 -1
  130. package/dist/token-util-E5QO2RCL.js +7 -0
  131. package/dist/{token-util-LY37VCIN.js.map → token-util-E5QO2RCL.js.map} +1 -1
  132. package/package.json +11 -8
  133. package/dist/chunk-2S4IMB6E.cjs.map +0 -1
  134. package/dist/chunk-3LTO44EP.cjs +0 -570
  135. package/dist/chunk-3LTO44EP.cjs.map +0 -1
  136. package/dist/chunk-3SNGNFUJ.cjs.map +0 -1
  137. package/dist/chunk-67GYDFSB.js +0 -160
  138. package/dist/chunk-67GYDFSB.js.map +0 -1
  139. package/dist/chunk-6ZR275MD.cjs +0 -165
  140. package/dist/chunk-6ZR275MD.cjs.map +0 -1
  141. package/dist/chunk-7HDOBOGG.cjs.map +0 -1
  142. package/dist/chunk-ABRFV4XP.js.map +0 -1
  143. package/dist/chunk-AHB4JCIQ.js.map +0 -1
  144. package/dist/chunk-AW5BU3RQ.js.map +0 -1
  145. package/dist/chunk-BATEJLED.js.map +0 -1
  146. package/dist/chunk-DB63UMTV.js.map +0 -1
  147. package/dist/chunk-FHSOPERI.cjs.map +0 -1
  148. package/dist/chunk-FWO7VQDC.js.map +0 -1
  149. package/dist/chunk-HPXAM2PG.js.map +0 -1
  150. package/dist/chunk-I3C4ODGV.cjs +0 -335
  151. package/dist/chunk-I3C4ODGV.cjs.map +0 -1
  152. package/dist/chunk-LLUOPR3J.js +0 -323
  153. package/dist/chunk-LLUOPR3J.js.map +0 -1
  154. package/dist/chunk-MMROOK5J.js.map +0 -1
  155. package/dist/chunk-MQDBNHBT.cjs +0 -680
  156. package/dist/chunk-MQDBNHBT.cjs.map +0 -1
  157. package/dist/chunk-OEOGYAQC.js.map +0 -1
  158. package/dist/chunk-QQXMIP6C.js.map +0 -1
  159. package/dist/chunk-SPRRK3P7.cjs.map +0 -1
  160. package/dist/chunk-TOP25AIO.cjs.map +0 -1
  161. package/dist/chunk-TRGAMKHX.cjs.map +0 -1
  162. package/dist/chunk-VY4ENABS.cjs.map +0 -1
  163. package/dist/chunk-XDAYZS6N.js.map +0 -1
  164. package/dist/chunk-XN74I6VW.cjs.map +0 -1
  165. package/dist/chunk-YWOK4F5A.js.map +0 -1
  166. package/dist/server/handlers/legacyWorkflows.cjs +0 -48
  167. package/dist/server/handlers/legacyWorkflows.cjs.map +0 -1
  168. package/dist/server/handlers/legacyWorkflows.d.ts +0 -59
  169. package/dist/server/handlers/legacyWorkflows.d.ts.map +0 -1
  170. package/dist/server/handlers/legacyWorkflows.js +0 -3
  171. package/dist/server/handlers/legacyWorkflows.js.map +0 -1
  172. package/dist/server/handlers/telemetry.cjs +0 -20
  173. package/dist/server/handlers/telemetry.cjs.map +0 -1
  174. package/dist/server/handlers/telemetry.d.ts +0 -33
  175. package/dist/server/handlers/telemetry.d.ts.map +0 -1
  176. package/dist/server/handlers/telemetry.js +0 -3
  177. package/dist/server/handlers/telemetry.js.map +0 -1
  178. package/dist/token-util-LY37VCIN.js +0 -7
  179. package/dist/token-util-S4A355II.cjs +0 -9
@@ -1,10 +1,11 @@
1
- import { sanitizeBody, validateBody } from './chunk-4QCXUEAT.js';
2
1
  import { stringify } from './chunk-LF2ZLOFP.js';
3
- import { handleError } from './chunk-CY4TP3FK.js';
4
- import { HTTPException } from './chunk-MMROOK5J.js';
2
+ import { sanitizeBody, validateBody } from './chunk-SZIFSF4T.js';
3
+ import { handleError } from './chunk-UXGQZUYZ.js';
4
+ import { HTTPException } from './chunk-6QWQZI4Q.js';
5
5
  import { __export } from './chunk-PR4QN5HX.js';
6
+ import { MastraError, ErrorDomain, ErrorCategory } from '@mastra/core/error';
6
7
  import { PROVIDER_REGISTRY } from '@mastra/core/llm';
7
- import { RuntimeContext } from '@mastra/core/runtime-context';
8
+ import { RequestContext } from '@mastra/core/request-context';
8
9
  import { zodToJsonSchema } from '@mastra/core/utils/zod-to-json';
9
10
 
10
11
  // src/server/handlers/agents.ts
@@ -15,13 +16,13 @@ __export(agents_exports, {
15
16
  generateHandler: () => generateHandler,
16
17
  generateLegacyHandler: () => generateLegacyHandler,
17
18
  getAgentByIdHandler: () => getAgentByIdHandler,
18
- getAgentsHandler: () => getAgentsHandler,
19
- getEvalsByAgentIdHandler: () => getEvalsByAgentIdHandler,
20
- getLiveEvalsByAgentIdHandler: () => getLiveEvalsByAgentIdHandler,
19
+ getAgentFromSystem: () => getAgentFromSystem,
21
20
  getProvidersHandler: () => getProvidersHandler,
22
21
  getSerializedAgentTools: () => getSerializedAgentTools,
23
22
  getSerializedProcessors: () => getSerializedProcessors,
23
+ listAgentsHandler: () => listAgentsHandler,
24
24
  reorderAgentModelListHandler: () => reorderAgentModelListHandler,
25
+ resetAgentModelHandler: () => resetAgentModelHandler,
25
26
  streamGenerateHandler: () => streamGenerateHandler,
26
27
  streamGenerateLegacyHandler: () => streamGenerateLegacyHandler,
27
28
  streamNetworkHandler: () => streamNetworkHandler,
@@ -80,17 +81,18 @@ async function getSerializedAgentTools(tools) {
80
81
  function getSerializedProcessors(processors) {
81
82
  return processors.map((processor) => {
82
83
  return {
84
+ id: processor.id,
83
85
  name: processor.name || processor.constructor.name
84
86
  };
85
87
  });
86
88
  }
87
89
  async function getSerializedAgentDefinition({
88
90
  agent,
89
- runtimeContext
91
+ requestContext
90
92
  }) {
91
93
  let serializedAgentAgents = {};
92
94
  if ("listAgents" in agent) {
93
- const agents = await agent.listAgents({ runtimeContext });
95
+ const agents = await agent.listAgents({ requestContext });
94
96
  serializedAgentAgents = Object.entries(agents || {}).reduce(
95
97
  (acc, [key, agent2]) => {
96
98
  return {
@@ -107,19 +109,21 @@ async function formatAgentList({
107
109
  id,
108
110
  mastra,
109
111
  agent,
110
- runtimeContext
112
+ requestContext
111
113
  }) {
112
- const instructions = await agent.getInstructions({ runtimeContext });
113
- const tools = await agent.getTools({ runtimeContext });
114
- const llm = await agent.getLLM({ runtimeContext });
115
- const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext });
116
- const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext });
114
+ const description = agent.getDescription();
115
+ const instructions = await agent.getInstructions({ requestContext });
116
+ const tools = await agent.listTools({ requestContext });
117
+ const llm = await agent.getLLM({ requestContext });
118
+ const defaultGenerateOptionsLegacy = await agent.getDefaultGenerateOptionsLegacy({ requestContext });
119
+ const defaultStreamOptionsLegacy = await agent.getDefaultStreamOptionsLegacy({ requestContext });
120
+ const defaultOptions = await agent.getDefaultOptions({ requestContext });
117
121
  const serializedAgentTools = await getSerializedAgentTools(tools);
118
122
  let serializedAgentWorkflows = {};
119
- if ("getWorkflows" in agent) {
123
+ if ("listWorkflows" in agent) {
120
124
  const logger = mastra.getLogger();
121
125
  try {
122
- const workflows = await agent.getWorkflows({ runtimeContext });
126
+ const workflows = await agent.listWorkflows({ requestContext });
123
127
  serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
124
128
  return {
125
129
  ...acc,
@@ -132,13 +136,13 @@ async function formatAgentList({
132
136
  logger.error("Error getting workflows for agent", { agentName: agent.name, error });
133
137
  }
134
138
  }
135
- const serializedAgentAgents = await getSerializedAgentDefinition({ agent, runtimeContext });
136
- const inputProcessors = await agent.getInputProcessors(runtimeContext);
137
- const outputProcessors = await agent.getOutputProcessors(runtimeContext);
139
+ const serializedAgentAgents = await getSerializedAgentDefinition({ agent, requestContext });
140
+ const inputProcessors = await agent.listInputProcessors(requestContext);
141
+ const outputProcessors = await agent.listOutputProcessors(requestContext);
138
142
  const serializedInputProcessors = getSerializedProcessors(inputProcessors);
139
143
  const serializedOutputProcessors = getSerializedProcessors(outputProcessors);
140
144
  const model = llm?.getModel();
141
- const models = await agent.getModelList(runtimeContext);
145
+ const models = await agent.getModelList(requestContext);
142
146
  const modelList = models?.map((md) => ({
143
147
  ...md,
144
148
  model: {
@@ -148,8 +152,9 @@ async function formatAgentList({
148
152
  }
149
153
  }));
150
154
  return {
151
- id,
155
+ id: agent.id || id,
152
156
  name: agent.name,
157
+ description,
153
158
  instructions,
154
159
  agents: serializedAgentAgents,
155
160
  tools: serializedAgentTools,
@@ -159,26 +164,63 @@ async function formatAgentList({
159
164
  provider: llm?.getProvider(),
160
165
  modelId: llm?.getModelId(),
161
166
  modelVersion: model?.specificationVersion,
162
- defaultGenerateOptions,
163
- defaultStreamOptions,
164
- modelList
167
+ defaultOptions,
168
+ modelList,
169
+ defaultGenerateOptionsLegacy,
170
+ defaultStreamOptionsLegacy
165
171
  };
166
172
  }
167
- async function getAgentsHandler({
173
+ async function getAgentFromSystem({ mastra, agentId }) {
174
+ const logger = mastra.getLogger();
175
+ if (!agentId) {
176
+ throw new HTTPException(400, { message: "Agent ID is required" });
177
+ }
178
+ let agent;
179
+ try {
180
+ agent = mastra.getAgentById(agentId);
181
+ } catch (error) {
182
+ logger.debug("Error getting agent from mastra, searching agents for agent", error);
183
+ }
184
+ if (!agent) {
185
+ logger.debug(`Agent ${agentId} not found, looking through sub-agents`);
186
+ const agents = mastra.listAgents();
187
+ if (Object.keys(agents || {}).length) {
188
+ for (const [_, ag] of Object.entries(agents)) {
189
+ try {
190
+ const subAgents = await ag.listAgents();
191
+ if (subAgents[agentId]) {
192
+ agent = subAgents[agentId];
193
+ break;
194
+ }
195
+ } catch (error) {
196
+ logger.debug("Error getting agent from agent", error);
197
+ }
198
+ }
199
+ }
200
+ }
201
+ if (!agent) {
202
+ throw new HTTPException(404, { message: `Agent with id ${agentId} not found` });
203
+ }
204
+ return agent;
205
+ }
206
+ async function listAgentsHandler({
168
207
  mastra,
169
- runtimeContext
208
+ requestContext
170
209
  }) {
171
210
  try {
172
- const agents = mastra.getAgents();
211
+ const agents = mastra.listAgents();
173
212
  const serializedAgentsMap = await Promise.all(
174
213
  Object.entries(agents).map(async ([id, agent]) => {
175
- return formatAgentList({ id, mastra, agent, runtimeContext });
214
+ return formatAgentList({ id, mastra, agent, requestContext });
176
215
  })
177
216
  );
178
- const serializedAgents = serializedAgentsMap.reduce((acc, { id, ...rest }) => {
179
- acc[id] = rest;
180
- return acc;
181
- }, {});
217
+ const serializedAgents = serializedAgentsMap.reduce(
218
+ (acc, { id, ...rest }) => {
219
+ acc[id] = { id, ...rest };
220
+ return acc;
221
+ },
222
+ {}
223
+ );
182
224
  return serializedAgents;
183
225
  } catch (error) {
184
226
  return handleError(error, "Error getting agents");
@@ -187,16 +229,17 @@ async function getAgentsHandler({
187
229
  async function formatAgent({
188
230
  mastra,
189
231
  agent,
190
- runtimeContext,
232
+ requestContext,
191
233
  isPlayground
192
234
  }) {
193
- const tools = await agent.getTools({ runtimeContext });
235
+ const description = agent.getDescription();
236
+ const tools = await agent.listTools({ requestContext });
194
237
  const serializedAgentTools = await getSerializedAgentTools(tools);
195
238
  let serializedAgentWorkflows = {};
196
- if ("getWorkflows" in agent) {
239
+ if ("listWorkflows" in agent) {
197
240
  const logger = mastra.getLogger();
198
241
  try {
199
- const workflows = await agent.getWorkflows({ runtimeContext });
242
+ const workflows = await agent.listWorkflows({ requestContext });
200
243
  serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
201
244
  return {
202
245
  ...acc,
@@ -221,9 +264,9 @@ async function formatAgent({
221
264
  logger.error("Error getting workflows for agent", { agentName: agent.name, error });
222
265
  }
223
266
  }
224
- let proxyRuntimeContext = runtimeContext;
267
+ let proxyRequestContext = requestContext;
225
268
  if (isPlayground) {
226
- proxyRuntimeContext = new Proxy(runtimeContext, {
269
+ proxyRequestContext = new Proxy(requestContext, {
227
270
  get(target, prop) {
228
271
  if (prop === "get") {
229
272
  return function(key) {
@@ -235,12 +278,15 @@ async function formatAgent({
235
278
  }
236
279
  });
237
280
  }
238
- const instructions = await agent.getInstructions({ runtimeContext: proxyRuntimeContext });
239
- const llm = await agent.getLLM({ runtimeContext });
240
- const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext: proxyRuntimeContext });
241
- const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext: proxyRuntimeContext });
281
+ const instructions = await agent.getInstructions({ requestContext: proxyRequestContext });
282
+ const llm = await agent.getLLM({ requestContext });
283
+ const defaultGenerateOptionsLegacy = await agent.getDefaultGenerateOptionsLegacy({
284
+ requestContext: proxyRequestContext
285
+ });
286
+ const defaultStreamOptionsLegacy = await agent.getDefaultStreamOptionsLegacy({ requestContext: proxyRequestContext });
287
+ const defaultOptions = await agent.getDefaultOptions({ requestContext: proxyRequestContext });
242
288
  const model = llm?.getModel();
243
- const models = await agent.getModelList(runtimeContext);
289
+ const models = await agent.getModelList(requestContext);
244
290
  const modelList = models?.map((md) => ({
245
291
  ...md,
246
292
  model: {
@@ -249,13 +295,14 @@ async function formatAgent({
249
295
  modelVersion: md.model.specificationVersion
250
296
  }
251
297
  }));
252
- const serializedAgentAgents = await getSerializedAgentDefinition({ agent, runtimeContext: proxyRuntimeContext });
253
- const inputProcessors = await agent.getInputProcessors(proxyRuntimeContext);
254
- const outputProcessors = await agent.getOutputProcessors(proxyRuntimeContext);
298
+ const serializedAgentAgents = await getSerializedAgentDefinition({ agent, requestContext: proxyRequestContext });
299
+ const inputProcessors = await agent.listInputProcessors(proxyRequestContext);
300
+ const outputProcessors = await agent.listOutputProcessors(proxyRequestContext);
255
301
  const serializedInputProcessors = getSerializedProcessors(inputProcessors);
256
302
  const serializedOutputProcessors = getSerializedProcessors(outputProcessors);
257
303
  return {
258
304
  name: agent.name,
305
+ description,
259
306
  instructions,
260
307
  tools: serializedAgentTools,
261
308
  agents: serializedAgentAgents,
@@ -266,82 +313,39 @@ async function formatAgent({
266
313
  modelId: llm?.getModelId(),
267
314
  modelVersion: model?.specificationVersion,
268
315
  modelList,
269
- defaultGenerateOptions,
270
- defaultStreamOptions
316
+ defaultOptions,
317
+ defaultGenerateOptionsLegacy,
318
+ defaultStreamOptionsLegacy
271
319
  };
272
320
  }
273
321
  async function getAgentByIdHandler({
274
322
  mastra,
275
- runtimeContext,
323
+ requestContext,
276
324
  agentId,
277
325
  isPlayground = false
278
326
  }) {
279
327
  try {
280
- const agent = mastra.getAgent(agentId);
281
- if (!agent) {
282
- throw new HTTPException(404, { message: "Agent not found" });
283
- }
284
- return formatAgent({ mastra, agent, runtimeContext, isPlayground });
328
+ const agent = await getAgentFromSystem({ mastra, agentId });
329
+ return formatAgent({ mastra, agent, requestContext, isPlayground });
285
330
  } catch (error) {
286
331
  return handleError(error, "Error getting agent");
287
332
  }
288
333
  }
289
- async function getEvalsByAgentIdHandler({
290
- mastra,
291
- runtimeContext,
292
- agentId
293
- }) {
294
- try {
295
- const agent = mastra.getAgent(agentId);
296
- const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
297
- const instructions = await agent.getInstructions({ runtimeContext });
298
- return {
299
- id: agentId,
300
- name: agent.name,
301
- instructions,
302
- evals
303
- };
304
- } catch (error) {
305
- return handleError(error, "Error getting test evals");
306
- }
307
- }
308
- async function getLiveEvalsByAgentIdHandler({
309
- mastra,
310
- runtimeContext,
311
- agentId
312
- }) {
313
- try {
314
- const agent = mastra.getAgent(agentId);
315
- const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
316
- const instructions = await agent.getInstructions({ runtimeContext });
317
- return {
318
- id: agentId,
319
- name: agent.name,
320
- instructions,
321
- evals
322
- };
323
- } catch (error) {
324
- return handleError(error, "Error getting live evals");
325
- }
326
- }
327
334
  async function generateLegacyHandler({
328
335
  mastra,
329
- runtimeContext,
336
+ requestContext,
330
337
  agentId,
331
338
  body,
332
339
  abortSignal
333
340
  }) {
334
341
  try {
335
- const agent = mastra.getAgent(agentId);
336
- if (!agent) {
337
- throw new HTTPException(404, { message: "Agent not found" });
338
- }
342
+ const agent = await getAgentFromSystem({ mastra, agentId });
339
343
  sanitizeBody(body, ["tools"]);
340
- const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
344
+ const { messages, resourceId, resourceid, requestContext: agentRequestContext, ...rest } = body;
341
345
  const finalResourceId = resourceId ?? resourceid;
342
- const finalRuntimeContext = new RuntimeContext([
343
- ...Array.from(runtimeContext.entries()),
344
- ...Array.from(Object.entries(agentRuntimeContext ?? {}))
346
+ const finalRequestContext = new RequestContext([
347
+ ...Array.from(requestContext.entries()),
348
+ ...Array.from(Object.entries(agentRequestContext ?? {}))
345
349
  ]);
346
350
  validateBody({ messages });
347
351
  const result = await agent.generateLegacy(messages, {
@@ -349,7 +353,7 @@ async function generateLegacyHandler({
349
353
  abortSignal,
350
354
  // @ts-expect-error TODO fix types
351
355
  resourceId: finalResourceId,
352
- runtimeContext: finalRuntimeContext
356
+ requestContext: finalRequestContext
353
357
  });
354
358
  return result;
355
359
  } catch (error) {
@@ -358,27 +362,23 @@ async function generateLegacyHandler({
358
362
  }
359
363
  async function generateHandler({
360
364
  mastra,
361
- runtimeContext,
365
+ requestContext,
362
366
  agentId,
363
367
  body,
364
368
  abortSignal
365
369
  }) {
366
370
  try {
367
- const agent = mastra.getAgent(agentId);
368
- if (!agent) {
369
- throw new HTTPException(404, { message: "Agent not found" });
370
- }
371
+ const agent = await getAgentFromSystem({ mastra, agentId });
371
372
  sanitizeBody(body, ["tools"]);
372
- const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
373
- const finalRuntimeContext = new RuntimeContext([
374
- ...Array.from(runtimeContext.entries()),
375
- ...Array.from(Object.entries(agentRuntimeContext ?? {}))
373
+ const { messages, requestContext: agentRequestContext, ...rest } = body;
374
+ const finalRequestContext = new RequestContext([
375
+ ...Array.from(requestContext.entries()),
376
+ ...Array.from(Object.entries(agentRequestContext ?? {}))
376
377
  ]);
377
378
  validateBody({ messages });
378
379
  const result = await agent.generate(messages, {
379
380
  ...rest,
380
- runtimeContext: finalRuntimeContext,
381
- format: rest.format || "mastra",
381
+ requestContext: finalRequestContext,
382
382
  abortSignal
383
383
  });
384
384
  return result;
@@ -388,21 +388,18 @@ async function generateHandler({
388
388
  }
389
389
  async function streamGenerateLegacyHandler({
390
390
  mastra,
391
- runtimeContext,
391
+ requestContext,
392
392
  agentId,
393
393
  body,
394
394
  abortSignal
395
395
  }) {
396
396
  try {
397
- const agent = mastra.getAgent(agentId);
398
- if (!agent) {
399
- throw new HTTPException(404, { message: "Agent not found" });
400
- }
401
- const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
397
+ const agent = await getAgentFromSystem({ mastra, agentId });
398
+ const { messages, resourceId, resourceid, requestContext: agentRequestContext, ...rest } = body;
402
399
  const finalResourceId = resourceId ?? resourceid;
403
- const finalRuntimeContext = new RuntimeContext([
404
- ...Array.from(runtimeContext.entries()),
405
- ...Array.from(Object.entries(agentRuntimeContext ?? {}))
400
+ const finalRequestContext = new RequestContext([
401
+ ...Array.from(requestContext.entries()),
402
+ ...Array.from(Object.entries(agentRequestContext ?? {}))
406
403
  ]);
407
404
  validateBody({ messages });
408
405
  const streamResult = await agent.streamLegacy(messages, {
@@ -410,7 +407,7 @@ async function streamGenerateLegacyHandler({
410
407
  abortSignal,
411
408
  // @ts-expect-error TODO fix types
412
409
  resourceId: finalResourceId,
413
- runtimeContext: finalRuntimeContext
410
+ requestContext: finalRequestContext
414
411
  });
415
412
  const streamResponse = rest.output ? streamResult.toTextStreamResponse({
416
413
  headers: {
@@ -431,113 +428,110 @@ async function streamGenerateLegacyHandler({
431
428
  return handleError(error, "error streaming agent response");
432
429
  }
433
430
  }
434
- function streamGenerateHandler({
431
+ async function streamGenerateHandler({
435
432
  mastra,
436
- runtimeContext,
433
+ requestContext,
437
434
  agentId,
438
435
  body,
439
436
  abortSignal
440
437
  }) {
441
438
  try {
442
- const agent = mastra.getAgent(agentId);
443
- if (!agent) {
444
- throw new HTTPException(404, { message: "Agent not found" });
445
- }
439
+ const agent = await getAgentFromSystem({ mastra, agentId });
446
440
  sanitizeBody(body, ["tools"]);
447
- const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
448
- const finalRuntimeContext = new RuntimeContext([
449
- ...Array.from(runtimeContext.entries()),
450
- ...Array.from(Object.entries(agentRuntimeContext ?? {}))
441
+ const { messages, requestContext: agentRequestContext, ...rest } = body;
442
+ const finalRequestContext = new RequestContext([
443
+ ...Array.from(requestContext.entries()),
444
+ ...Array.from(Object.entries(agentRequestContext ?? {}))
451
445
  ]);
452
446
  validateBody({ messages });
453
447
  const streamResult = agent.stream(messages, {
454
448
  ...rest,
455
- runtimeContext: finalRuntimeContext,
456
- abortSignal,
457
- format: body.format ?? "mastra"
449
+ requestContext: finalRequestContext,
450
+ abortSignal
458
451
  });
459
452
  return streamResult;
460
453
  } catch (error) {
461
454
  return handleError(error, "error streaming agent response");
462
455
  }
463
456
  }
464
- function approveToolCallHandler({
457
+ async function approveToolCallHandler({
465
458
  mastra,
466
- runtimeContext,
459
+ requestContext,
467
460
  agentId,
468
461
  body,
469
462
  abortSignal
470
463
  }) {
471
464
  try {
472
- const agent = mastra.getAgent(agentId);
473
- if (!agent) {
474
- throw new HTTPException(404, { message: "Agent not found" });
465
+ const agent = await getAgentFromSystem({ mastra, agentId });
466
+ if (!body.runId) {
467
+ throw new HTTPException(400, { message: "Run id is required" });
468
+ }
469
+ if (!body.toolCallId) {
470
+ throw new HTTPException(400, { message: "Tool call id is required" });
475
471
  }
476
472
  sanitizeBody(body, ["tools"]);
477
- const { runId, runtimeContext: agentRuntimeContext, ...rest } = body;
478
- const finalRuntimeContext = new RuntimeContext([
479
- ...Array.from(runtimeContext.entries()),
480
- ...Array.from(Object.entries(agentRuntimeContext ?? {}))
473
+ const { runId, requestContext: agentRequestContext, ...rest } = body;
474
+ const finalRequestContext = new RequestContext([
475
+ ...Array.from(requestContext.entries()),
476
+ ...Array.from(Object.entries(agentRequestContext ?? {}))
481
477
  ]);
482
478
  const streamResult = agent.approveToolCall({
483
479
  ...rest,
484
480
  runId,
485
- runtimeContext: finalRuntimeContext,
486
- abortSignal,
487
- format: body.format ?? "mastra"
481
+ requestContext: finalRequestContext,
482
+ abortSignal
488
483
  });
489
484
  return streamResult;
490
485
  } catch (error) {
491
486
  return handleError(error, "error streaming agent response");
492
487
  }
493
488
  }
494
- function declineToolCallHandler({
489
+ async function declineToolCallHandler({
495
490
  mastra,
496
- runtimeContext,
491
+ requestContext,
497
492
  agentId,
498
493
  body,
499
494
  abortSignal
500
495
  }) {
501
496
  try {
502
- const agent = mastra.getAgent(agentId);
503
- if (!agent) {
504
- throw new HTTPException(404, { message: "Agent not found" });
497
+ const agent = await getAgentFromSystem({ mastra, agentId });
498
+ if (!body.runId) {
499
+ throw new HTTPException(400, { message: "Run id is required" });
500
+ }
501
+ if (!body.toolCallId) {
502
+ throw new HTTPException(400, { message: "Tool call id is required" });
505
503
  }
506
504
  sanitizeBody(body, ["tools"]);
507
- const { runId, runtimeContext: agentRuntimeContext, ...rest } = body;
508
- const finalRuntimeContext = new RuntimeContext([
509
- ...Array.from(runtimeContext.entries()),
510
- ...Array.from(Object.entries(agentRuntimeContext ?? {}))
505
+ const { runId, requestContext: agentRequestContext, ...rest } = body;
506
+ const finalRequestContext = new RequestContext([
507
+ ...Array.from(requestContext.entries()),
508
+ ...Array.from(Object.entries(agentRequestContext ?? {}))
511
509
  ]);
512
510
  const streamResult = agent.declineToolCall({
513
511
  ...rest,
514
512
  runId,
515
- runtimeContext: finalRuntimeContext,
516
- abortSignal,
517
- format: body.format ?? "mastra"
513
+ requestContext: finalRequestContext,
514
+ abortSignal
518
515
  });
519
516
  return streamResult;
520
517
  } catch (error) {
521
518
  return handleError(error, "error streaming agent response");
522
519
  }
523
520
  }
524
- function streamNetworkHandler({
521
+ async function streamNetworkHandler({
525
522
  mastra,
526
- runtimeContext,
523
+ requestContext,
527
524
  agentId,
528
525
  body
529
526
  // abortSignal,
530
527
  }) {
531
528
  try {
532
- const agent = mastra.getAgent(agentId);
533
- if (!agent) {
534
- throw new HTTPException(404, { message: "Agent not found" });
535
- }
529
+ const agent = await getAgentFromSystem({ mastra, agentId });
536
530
  sanitizeBody(body, ["tools"]);
537
- const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
538
- const finalRuntimeContext = new RuntimeContext([
539
- ...Array.from(runtimeContext.entries()),
540
- ...Array.from(Object.entries(agentRuntimeContext ?? {}))
531
+ const { messages, requestContext: agentRequestContext, ...rest } = body;
532
+ const finalRequestContext = new RequestContext([
533
+ ...Array.from(requestContext.entries()),
534
+ ...Array.from(Object.entries(agentRequestContext ?? {}))
541
535
  ]);
542
536
  validateBody({ messages });
543
537
  const streamResult = agent.network(messages, {
@@ -547,39 +541,21 @@ function streamNetworkHandler({
547
541
  resource: rest.resourceId ?? "",
548
542
  options: rest.memory?.options ?? {}
549
543
  },
550
- runtimeContext: finalRuntimeContext
544
+ requestContext: finalRequestContext
551
545
  });
552
546
  return streamResult;
553
547
  } catch (error) {
554
548
  return handleError(error, "error streaming agent loop response");
555
549
  }
556
550
  }
557
- async function streamUIMessageHandler({
558
- mastra,
559
- runtimeContext,
560
- agentId,
561
- body,
562
- abortSignal
563
- }) {
551
+ async function streamUIMessageHandler(_params) {
564
552
  try {
565
- const agent = mastra.getAgent(agentId);
566
- if (!agent) {
567
- throw new HTTPException(404, { message: "Agent not found" });
568
- }
569
- sanitizeBody(body, ["tools"]);
570
- const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
571
- const finalRuntimeContext = new RuntimeContext([
572
- ...Array.from(runtimeContext.entries()),
573
- ...Array.from(Object.entries(agentRuntimeContext ?? {}))
574
- ]);
575
- validateBody({ messages });
576
- const streamResult = await agent.stream(messages, {
577
- ...rest,
578
- runtimeContext: finalRuntimeContext,
579
- abortSignal,
580
- format: "aisdk"
553
+ throw new MastraError({
554
+ category: ErrorCategory.USER,
555
+ domain: ErrorDomain.MASTRA_SERVER,
556
+ id: "DEPRECATED_ENDPOINT",
557
+ text: "This endpoint is deprecated. Please use the @mastra/ai-sdk package to for uiMessage transformations"
581
558
  });
582
- return streamResult.toUIMessageStreamResponse();
583
559
  } catch (error) {
584
560
  return handleError(error, "error streaming agent response");
585
561
  }
@@ -590,10 +566,7 @@ async function updateAgentModelHandler({
590
566
  body
591
567
  }) {
592
568
  try {
593
- const agent = mastra.getAgent(agentId);
594
- if (!agent) {
595
- throw new HTTPException(404, { message: "Agent not found" });
596
- }
569
+ const agent = await getAgentFromSystem({ mastra, agentId });
597
570
  const { modelId, provider } = body;
598
571
  const newModel = `${provider}/${modelId}`;
599
572
  agent.__updateModel({ model: newModel });
@@ -602,16 +575,25 @@ async function updateAgentModelHandler({
602
575
  return handleError(error, "error updating agent model");
603
576
  }
604
577
  }
578
+ async function resetAgentModelHandler({
579
+ mastra,
580
+ agentId
581
+ }) {
582
+ try {
583
+ const agent = await getAgentFromSystem({ mastra, agentId });
584
+ agent.__resetToOriginalModel();
585
+ return { message: "Agent model reset to original" };
586
+ } catch (error) {
587
+ return handleError(error, "error resetting agent model");
588
+ }
589
+ }
605
590
  async function reorderAgentModelListHandler({
606
591
  mastra,
607
592
  agentId,
608
593
  body
609
594
  }) {
610
595
  try {
611
- const agent = mastra.getAgent(agentId);
612
- if (!agent) {
613
- throw new HTTPException(404, { message: "Agent not found" });
614
- }
596
+ const agent = await getAgentFromSystem({ mastra, agentId });
615
597
  const modelList = await agent.getModelList();
616
598
  if (!modelList || modelList.length === 0) {
617
599
  throw new HTTPException(400, { message: "Agent model list is not found or empty" });
@@ -629,10 +611,7 @@ async function updateAgentModelInModelListHandler({
629
611
  body
630
612
  }) {
631
613
  try {
632
- const agent = mastra.getAgent(agentId);
633
- if (!agent) {
634
- throw new HTTPException(404, { message: "Agent not found" });
635
- }
614
+ const agent = await getAgentFromSystem({ mastra, agentId });
636
615
  const { model: bodyModel, maxRetries, enabled } = body;
637
616
  if (!modelConfigId) {
638
617
  throw new HTTPException(400, { message: "Model id is required" });
@@ -677,6 +656,6 @@ async function getProvidersHandler() {
677
656
  }
678
657
  }
679
658
 
680
- export { agents_exports, approveToolCallHandler, declineToolCallHandler, generateHandler, generateLegacyHandler, getAgentByIdHandler, getAgentsHandler, getEvalsByAgentIdHandler, getLiveEvalsByAgentIdHandler, getProvidersHandler, getSerializedAgentTools, getSerializedProcessors, reorderAgentModelListHandler, streamGenerateHandler, streamGenerateLegacyHandler, streamNetworkHandler, streamUIMessageHandler, updateAgentModelHandler, updateAgentModelInModelListHandler };
681
- //# sourceMappingURL=chunk-XDAYZS6N.js.map
682
- //# sourceMappingURL=chunk-XDAYZS6N.js.map
659
+ export { agents_exports, approveToolCallHandler, declineToolCallHandler, generateHandler, generateLegacyHandler, getAgentByIdHandler, getAgentFromSystem, getProvidersHandler, getSerializedAgentTools, getSerializedProcessors, listAgentsHandler, reorderAgentModelListHandler, resetAgentModelHandler, streamGenerateHandler, streamGenerateLegacyHandler, streamNetworkHandler, streamUIMessageHandler, updateAgentModelHandler, updateAgentModelInModelListHandler };
660
+ //# sourceMappingURL=chunk-Z2O5YVHY.js.map
661
+ //# sourceMappingURL=chunk-Z2O5YVHY.js.map