@mastra/server 0.0.0-revert-schema-20250416221206 → 0.0.0-safe-stringify-telemetry-20251205024938

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 (276) hide show
  1. package/CHANGELOG.md +4368 -0
  2. package/LICENSE.md +11 -42
  3. package/README.md +45 -137
  4. package/dist/chunk-2PLXW4ZX.cjs +2777 -0
  5. package/dist/chunk-2PLXW4ZX.cjs.map +1 -0
  6. package/dist/chunk-2S4IMB6E.cjs +130 -0
  7. package/dist/chunk-2S4IMB6E.cjs.map +1 -0
  8. package/dist/chunk-3SNGNFUJ.cjs +128 -0
  9. package/dist/chunk-3SNGNFUJ.cjs.map +1 -0
  10. package/dist/{chunk-L7XE5QTW.js → chunk-4QCXUEAT.js} +11 -2
  11. package/dist/chunk-4QCXUEAT.js.map +1 -0
  12. package/dist/{chunk-WTHDCRMY.js → chunk-67GYDFSB.js} +33 -8
  13. package/dist/chunk-67GYDFSB.js.map +1 -0
  14. package/dist/chunk-6N3HC6O4.js +705 -0
  15. package/dist/chunk-6N3HC6O4.js.map +1 -0
  16. package/dist/{chunk-7IWQE76Z.cjs → chunk-6ZR275MD.cjs} +37 -11
  17. package/dist/chunk-6ZR275MD.cjs.map +1 -0
  18. package/dist/{chunk-FV45V6WC.cjs → chunk-7NADHFD2.cjs} +3 -7
  19. package/dist/chunk-7NADHFD2.cjs.map +1 -0
  20. package/dist/chunk-7RGKOGE4.cjs +485 -0
  21. package/dist/chunk-7RGKOGE4.cjs.map +1 -0
  22. package/dist/chunk-ABRFV4XP.js +83 -0
  23. package/dist/chunk-ABRFV4XP.js.map +1 -0
  24. package/dist/{chunk-UV4WTEH4.js → chunk-AHB4JCIQ.js} +55 -15
  25. package/dist/chunk-AHB4JCIQ.js.map +1 -0
  26. package/dist/chunk-AW5BU3RQ.js +192 -0
  27. package/dist/chunk-AW5BU3RQ.js.map +1 -0
  28. package/dist/chunk-BATEJLED.js +124 -0
  29. package/dist/chunk-BATEJLED.js.map +1 -0
  30. package/dist/chunk-CY4TP3FK.js +16 -0
  31. package/dist/chunk-CY4TP3FK.js.map +1 -0
  32. package/dist/chunk-CY6R3HLM.cjs +727 -0
  33. package/dist/chunk-CY6R3HLM.cjs.map +1 -0
  34. package/dist/{chunk-M56ECCHK.cjs → chunk-EP3JQDPD.cjs} +22 -19
  35. package/dist/chunk-EP3JQDPD.cjs.map +1 -0
  36. package/dist/chunk-G4PUALCE.cjs +28 -0
  37. package/dist/chunk-G4PUALCE.cjs.map +1 -0
  38. package/dist/chunk-G5O5SC7R.cjs +19565 -0
  39. package/dist/chunk-G5O5SC7R.cjs.map +1 -0
  40. package/dist/chunk-GU4EWMZB.cjs +769 -0
  41. package/dist/chunk-GU4EWMZB.cjs.map +1 -0
  42. package/dist/chunk-I3C4ODGV.cjs +335 -0
  43. package/dist/chunk-I3C4ODGV.cjs.map +1 -0
  44. package/dist/chunk-IAE7SFBS.js +477 -0
  45. package/dist/chunk-IAE7SFBS.js.map +1 -0
  46. package/dist/chunk-LF2ZLOFP.js +767 -0
  47. package/dist/chunk-LF2ZLOFP.js.map +1 -0
  48. package/dist/{chunk-OPP7H5TW.js → chunk-LLUOPR3J.js} +92 -74
  49. package/dist/chunk-LLUOPR3J.js.map +1 -0
  50. package/dist/chunk-LPM6BBAX.cjs +1043 -0
  51. package/dist/chunk-LPM6BBAX.cjs.map +1 -0
  52. package/dist/{chunk-TRDNDNGQ.js → chunk-MMROOK5J.js} +4 -7
  53. package/dist/chunk-MMROOK5J.js.map +1 -0
  54. package/dist/{chunk-4JINXASC.js → chunk-MYR4PVGN.js} +7 -4
  55. package/dist/chunk-MYR4PVGN.js.map +1 -0
  56. package/dist/chunk-NT5XW5PI.cjs +596 -0
  57. package/dist/chunk-NT5XW5PI.cjs.map +1 -0
  58. package/dist/chunk-O7I5CWRX.cjs +44 -0
  59. package/dist/chunk-O7I5CWRX.cjs.map +1 -0
  60. package/dist/chunk-PBXWFGEH.js +579 -0
  61. package/dist/chunk-PBXWFGEH.js.map +1 -0
  62. package/dist/chunk-PR4QN5HX.js +39 -0
  63. package/dist/chunk-PR4QN5HX.js.map +1 -0
  64. package/dist/chunk-QGNHNNJR.js +909 -0
  65. package/dist/chunk-QGNHNNJR.js.map +1 -0
  66. package/dist/{chunk-3RVHWGWO.js → chunk-QQXMIP6C.js} +49 -22
  67. package/dist/chunk-QQXMIP6C.js.map +1 -0
  68. package/dist/chunk-QU6N55W6.cjs +256 -0
  69. package/dist/chunk-QU6N55W6.cjs.map +1 -0
  70. package/dist/chunk-RE4RPXT2.cjs +18 -0
  71. package/dist/chunk-RE4RPXT2.cjs.map +1 -0
  72. package/dist/chunk-RQK4FQUD.js +1012 -0
  73. package/dist/chunk-RQK4FQUD.js.map +1 -0
  74. package/dist/chunk-S6YZQY4V.cjs +938 -0
  75. package/dist/chunk-S6YZQY4V.cjs.map +1 -0
  76. package/dist/chunk-SHWNNZBL.js +254 -0
  77. package/dist/chunk-SHWNNZBL.js.map +1 -0
  78. package/dist/chunk-SPRRK3P7.cjs +200 -0
  79. package/dist/chunk-SPRRK3P7.cjs.map +1 -0
  80. package/dist/chunk-TOCYBDP2.js +46 -0
  81. package/dist/chunk-TOCYBDP2.js.map +1 -0
  82. package/dist/chunk-TRGAMKHX.cjs +167 -0
  83. package/dist/chunk-TRGAMKHX.cjs.map +1 -0
  84. package/dist/chunk-TRHCWKZ2.js +19529 -0
  85. package/dist/chunk-TRHCWKZ2.js.map +1 -0
  86. package/dist/chunk-VY4ENABS.cjs +135 -0
  87. package/dist/chunk-VY4ENABS.cjs.map +1 -0
  88. package/dist/chunk-X6C7BUWN.cjs +48 -0
  89. package/dist/chunk-X6C7BUWN.cjs.map +1 -0
  90. package/dist/chunk-XN74I6VW.cjs +88 -0
  91. package/dist/chunk-XN74I6VW.cjs.map +1 -0
  92. package/dist/chunk-YWOK4F5A.js +131 -0
  93. package/dist/chunk-YWOK4F5A.js.map +1 -0
  94. package/dist/chunk-ZULZ2752.js +2774 -0
  95. package/dist/chunk-ZULZ2752.js.map +1 -0
  96. package/dist/dist-4MVGNSRL.cjs +1150 -0
  97. package/dist/dist-4MVGNSRL.cjs.map +1 -0
  98. package/dist/dist-FZYCV3VB.cjs +940 -0
  99. package/dist/dist-FZYCV3VB.cjs.map +1 -0
  100. package/dist/dist-G2BYZJOC.cjs +928 -0
  101. package/dist/dist-G2BYZJOC.cjs.map +1 -0
  102. package/dist/dist-P4MXBQ3U.cjs +16 -0
  103. package/dist/dist-P4MXBQ3U.cjs.map +1 -0
  104. package/dist/dist-PQZUVLPC.js +937 -0
  105. package/dist/dist-PQZUVLPC.js.map +1 -0
  106. package/dist/dist-R7WYX6LC.js +925 -0
  107. package/dist/dist-R7WYX6LC.js.map +1 -0
  108. package/dist/dist-RFMYFILX.cjs +764 -0
  109. package/dist/dist-RFMYFILX.cjs.map +1 -0
  110. package/dist/dist-X7XR3M3Z.js +1147 -0
  111. package/dist/dist-X7XR3M3Z.js.map +1 -0
  112. package/dist/dist-XVBSOGFK.js +761 -0
  113. package/dist/dist-XVBSOGFK.js.map +1 -0
  114. package/dist/dist-YREX2TJT.js +3 -0
  115. package/dist/dist-YREX2TJT.js.map +1 -0
  116. package/dist/index.cjs +6 -0
  117. package/dist/index.cjs.map +1 -0
  118. package/dist/index.d.ts +1 -0
  119. package/dist/index.d.ts.map +1 -0
  120. package/dist/index.js +5 -0
  121. package/dist/index.js.map +1 -0
  122. package/dist/server/a2a/protocol.d.ts +8 -0
  123. package/dist/server/a2a/protocol.d.ts.map +1 -0
  124. package/dist/server/a2a/store.cjs +25 -0
  125. package/dist/server/a2a/store.cjs.map +1 -0
  126. package/dist/server/a2a/store.d.ts +14 -0
  127. package/dist/server/a2a/store.d.ts.map +1 -0
  128. package/dist/server/a2a/store.js +23 -0
  129. package/dist/server/a2a/store.js.map +1 -0
  130. package/dist/server/a2a/tasks.d.ts +20 -0
  131. package/dist/server/a2a/tasks.d.ts.map +1 -0
  132. package/dist/server/handlers/a2a.cjs +32 -0
  133. package/dist/server/handlers/a2a.cjs.map +1 -0
  134. package/dist/server/handlers/a2a.d.ts +68 -0
  135. package/dist/server/handlers/a2a.d.ts.map +1 -0
  136. package/dist/server/handlers/a2a.js +3 -0
  137. package/dist/server/handlers/a2a.js.map +1 -0
  138. package/dist/server/handlers/agent-builder.cjs +68 -0
  139. package/dist/server/handlers/agent-builder.cjs.map +1 -0
  140. package/dist/server/handlers/agent-builder.d.ts +94 -0
  141. package/dist/server/handlers/agent-builder.d.ts.map +1 -0
  142. package/dist/server/handlers/agent-builder.js +3 -0
  143. package/dist/server/handlers/agent-builder.js.map +1 -0
  144. package/dist/server/handlers/agents.cjs +65 -7
  145. package/dist/server/handlers/agents.cjs.map +1 -0
  146. package/dist/server/handlers/agents.d.ts +210 -6
  147. package/dist/server/handlers/agents.d.ts.map +1 -0
  148. package/dist/server/handlers/agents.js +3 -1
  149. package/dist/server/handlers/agents.js.map +1 -0
  150. package/dist/server/handlers/error.cjs +4 -2
  151. package/dist/server/handlers/error.cjs.map +1 -0
  152. package/dist/server/handlers/error.d.ts +2 -1
  153. package/dist/server/handlers/error.d.ts.map +1 -0
  154. package/dist/server/handlers/error.js +3 -1
  155. package/dist/server/handlers/error.js.map +1 -0
  156. package/dist/server/handlers/legacyWorkflows.cjs +48 -0
  157. package/dist/server/handlers/legacyWorkflows.cjs.map +1 -0
  158. package/dist/server/handlers/legacyWorkflows.d.ts +59 -0
  159. package/dist/server/handlers/legacyWorkflows.d.ts.map +1 -0
  160. package/dist/server/handlers/legacyWorkflows.js +3 -0
  161. package/dist/server/handlers/legacyWorkflows.js.map +1 -0
  162. package/dist/server/handlers/logs.cjs +6 -4
  163. package/dist/server/handlers/logs.cjs.map +1 -0
  164. package/dist/server/handlers/logs.d.ts +34 -3
  165. package/dist/server/handlers/logs.d.ts.map +1 -0
  166. package/dist/server/handlers/logs.js +3 -1
  167. package/dist/server/handlers/logs.js.map +1 -0
  168. package/dist/server/handlers/memory.cjs +39 -9
  169. package/dist/server/handlers/memory.cjs.map +1 -0
  170. package/dist/server/handlers/memory.d.ts +118 -8
  171. package/dist/server/handlers/memory.d.ts.map +1 -0
  172. package/dist/server/handlers/memory.js +3 -1
  173. package/dist/server/handlers/memory.js.map +1 -0
  174. package/dist/server/handlers/observability.cjs +24 -0
  175. package/dist/server/handlers/observability.cjs.map +1 -0
  176. package/dist/server/handlers/observability.d.ts +49 -0
  177. package/dist/server/handlers/observability.d.ts.map +1 -0
  178. package/dist/server/handlers/observability.js +3 -0
  179. package/dist/server/handlers/observability.js.map +1 -0
  180. package/dist/server/handlers/scores.cjs +32 -0
  181. package/dist/server/handlers/scores.cjs.map +1 -0
  182. package/dist/server/handlers/scores.d.ts +152 -0
  183. package/dist/server/handlers/scores.d.ts.map +1 -0
  184. package/dist/server/handlers/scores.js +3 -0
  185. package/dist/server/handlers/scores.js.map +1 -0
  186. package/dist/server/handlers/telemetry.cjs +9 -3
  187. package/dist/server/handlers/telemetry.cjs.map +1 -0
  188. package/dist/server/handlers/telemetry.d.ts +33 -2
  189. package/dist/server/handlers/telemetry.d.ts.map +1 -0
  190. package/dist/server/handlers/telemetry.js +3 -1
  191. package/dist/server/handlers/telemetry.js.map +1 -0
  192. package/dist/server/handlers/tools.cjs +11 -5
  193. package/dist/server/handlers/tools.cjs.map +1 -0
  194. package/dist/server/handlers/tools.d.ts +25 -4
  195. package/dist/server/handlers/tools.d.ts.map +1 -0
  196. package/dist/server/handlers/tools.js +3 -1
  197. package/dist/server/handlers/tools.js.map +1 -0
  198. package/dist/server/handlers/utils.cjs +8 -2
  199. package/dist/server/handlers/utils.cjs.map +1 -0
  200. package/dist/server/handlers/utils.d.ts +8 -1
  201. package/dist/server/handlers/utils.d.ts.map +1 -0
  202. package/dist/server/handlers/utils.js +3 -1
  203. package/dist/server/handlers/utils.js.map +1 -0
  204. package/dist/server/handlers/vector.cjs +9 -7
  205. package/dist/server/handlers/vector.cjs.map +1 -0
  206. package/dist/server/handlers/vector.d.ts +51 -6
  207. package/dist/server/handlers/vector.d.ts.map +1 -0
  208. package/dist/server/handlers/vector.js +3 -1
  209. package/dist/server/handlers/vector.js.map +1 -0
  210. package/dist/server/handlers/voice.cjs +10 -4
  211. package/dist/server/handlers/voice.cjs.map +1 -0
  212. package/dist/server/handlers/voice.d.ts +41 -3
  213. package/dist/server/handlers/voice.d.ts.map +1 -0
  214. package/dist/server/handlers/voice.js +3 -1
  215. package/dist/server/handlers/voice.js.map +1 -0
  216. package/dist/server/handlers/workflows.cjs +83 -13
  217. package/dist/server/handlers/workflows.cjs.map +1 -0
  218. package/dist/server/handlers/workflows.d.ts +151 -10
  219. package/dist/server/handlers/workflows.d.ts.map +1 -0
  220. package/dist/server/handlers/workflows.js +3 -1
  221. package/dist/server/handlers/workflows.js.map +1 -0
  222. package/dist/server/handlers.cjs +49 -27
  223. package/dist/server/handlers.cjs.map +1 -0
  224. package/dist/server/handlers.d.ts +14 -9
  225. package/dist/server/handlers.d.ts.map +1 -0
  226. package/dist/server/handlers.js +15 -9
  227. package/dist/server/handlers.js.map +1 -0
  228. package/dist/server/http-exception.d.ts +87 -0
  229. package/dist/server/http-exception.d.ts.map +1 -0
  230. package/dist/server/types.d.ts +10 -0
  231. package/dist/server/types.d.ts.map +1 -0
  232. package/dist/server/utils.d.ts +44 -0
  233. package/dist/server/utils.d.ts.map +1 -0
  234. package/dist/token-375W3LEI.cjs +64 -0
  235. package/dist/token-375W3LEI.cjs.map +1 -0
  236. package/dist/token-C3IMNCC4.js +62 -0
  237. package/dist/token-C3IMNCC4.js.map +1 -0
  238. package/dist/token-util-CV3RRG6K.cjs +9 -0
  239. package/dist/token-util-CV3RRG6K.cjs.map +1 -0
  240. package/dist/token-util-E5QO2RCL.js +7 -0
  241. package/dist/token-util-E5QO2RCL.js.map +1 -0
  242. package/package.json +50 -19
  243. package/dist/_tsup-dts-rollup.d.cts +0 -573
  244. package/dist/_tsup-dts-rollup.d.ts +0 -573
  245. package/dist/chunk-2FJURXCL.cjs +0 -213
  246. package/dist/chunk-3AHQ5RGN.js +0 -11
  247. package/dist/chunk-3EJZQ6TQ.js +0 -49
  248. package/dist/chunk-A7DF4ETD.cjs +0 -100
  249. package/dist/chunk-B64YROKU.cjs +0 -317
  250. package/dist/chunk-I6MBOQTH.js +0 -156
  251. package/dist/chunk-JLDXUWK7.cjs +0 -126
  252. package/dist/chunk-PDC4ZBQW.cjs +0 -126
  253. package/dist/chunk-QH6XWSXP.cjs +0 -5579
  254. package/dist/chunk-QN4KF3BH.cjs +0 -18
  255. package/dist/chunk-RBQASTUP.js +0 -203
  256. package/dist/chunk-SKBVVI24.cjs +0 -54
  257. package/dist/chunk-UE27Q3XD.cjs +0 -164
  258. package/dist/chunk-VK6FX47H.js +0 -5576
  259. package/dist/chunk-YANVFOYA.js +0 -120
  260. package/dist/chunk-ZLBRQFDD.cjs +0 -13
  261. package/dist/index.d.cts +0 -1
  262. package/dist/server/handlers/agents.d.cts +0 -6
  263. package/dist/server/handlers/error.d.cts +0 -1
  264. package/dist/server/handlers/logs.d.cts +0 -3
  265. package/dist/server/handlers/memory.d.cts +0 -8
  266. package/dist/server/handlers/network.cjs +0 -22
  267. package/dist/server/handlers/network.d.cts +0 -4
  268. package/dist/server/handlers/network.d.ts +0 -4
  269. package/dist/server/handlers/network.js +0 -1
  270. package/dist/server/handlers/telemetry.d.cts +0 -2
  271. package/dist/server/handlers/tools.d.cts +0 -4
  272. package/dist/server/handlers/utils.d.cts +0 -1
  273. package/dist/server/handlers/vector.d.cts +0 -6
  274. package/dist/server/handlers/voice.d.cts +0 -3
  275. package/dist/server/handlers/workflows.d.cts +0 -10
  276. package/dist/server/handlers.d.cts +0 -9
@@ -0,0 +1,705 @@
1
+ import { sanitizeBody, validateBody } from './chunk-4QCXUEAT.js';
2
+ import { stringify } from './chunk-LF2ZLOFP.js';
3
+ import { handleError } from './chunk-CY4TP3FK.js';
4
+ import { HTTPException } from './chunk-MMROOK5J.js';
5
+ import { __export } from './chunk-PR4QN5HX.js';
6
+ import { PROVIDER_REGISTRY } from '@mastra/core/llm';
7
+ import { RuntimeContext } from '@mastra/core/runtime-context';
8
+ import { zodToJsonSchema } from '@mastra/core/utils/zod-to-json';
9
+
10
+ // src/server/handlers/agents.ts
11
+ var agents_exports = {};
12
+ __export(agents_exports, {
13
+ approveToolCallHandler: () => approveToolCallHandler,
14
+ declineToolCallHandler: () => declineToolCallHandler,
15
+ generateHandler: () => generateHandler,
16
+ generateLegacyHandler: () => generateLegacyHandler,
17
+ getAgentByIdHandler: () => getAgentByIdHandler,
18
+ getAgentFromSystem: () => getAgentFromSystem,
19
+ getAgentsHandler: () => getAgentsHandler,
20
+ getEvalsByAgentIdHandler: () => getEvalsByAgentIdHandler,
21
+ getLiveEvalsByAgentIdHandler: () => getLiveEvalsByAgentIdHandler,
22
+ getProvidersHandler: () => getProvidersHandler,
23
+ getSerializedAgentTools: () => getSerializedAgentTools,
24
+ getSerializedProcessors: () => getSerializedProcessors,
25
+ reorderAgentModelListHandler: () => reorderAgentModelListHandler,
26
+ resetAgentModelHandler: () => resetAgentModelHandler,
27
+ streamGenerateHandler: () => streamGenerateHandler,
28
+ streamGenerateLegacyHandler: () => streamGenerateLegacyHandler,
29
+ streamNetworkHandler: () => streamNetworkHandler,
30
+ streamUIMessageHandler: () => streamUIMessageHandler,
31
+ updateAgentModelHandler: () => updateAgentModelHandler,
32
+ updateAgentModelInModelListHandler: () => updateAgentModelInModelListHandler
33
+ });
34
+ async function getSerializedAgentTools(tools) {
35
+ return Object.entries(tools || {}).reduce((acc, [key, tool]) => {
36
+ const _tool = tool;
37
+ const toolId = _tool.id ?? `tool-${key}`;
38
+ let inputSchemaForReturn = void 0;
39
+ let outputSchemaForReturn = void 0;
40
+ try {
41
+ if (_tool.inputSchema) {
42
+ if (_tool.inputSchema && typeof _tool.inputSchema === "object" && "jsonSchema" in _tool.inputSchema) {
43
+ inputSchemaForReturn = stringify(_tool.inputSchema.jsonSchema);
44
+ } else if (typeof _tool.inputSchema === "function") {
45
+ const inputSchema = _tool.inputSchema();
46
+ if (inputSchema && inputSchema.jsonSchema) {
47
+ inputSchemaForReturn = stringify(inputSchema.jsonSchema);
48
+ }
49
+ } else if (_tool.inputSchema) {
50
+ inputSchemaForReturn = stringify(zodToJsonSchema(_tool.inputSchema));
51
+ }
52
+ }
53
+ if (_tool.outputSchema) {
54
+ if (_tool.outputSchema && typeof _tool.outputSchema === "object" && "jsonSchema" in _tool.outputSchema) {
55
+ outputSchemaForReturn = stringify(_tool.outputSchema.jsonSchema);
56
+ } else if (typeof _tool.outputSchema === "function") {
57
+ const outputSchema = _tool.outputSchema();
58
+ if (outputSchema && outputSchema.jsonSchema) {
59
+ outputSchemaForReturn = stringify(outputSchema.jsonSchema);
60
+ }
61
+ } else if (_tool.outputSchema) {
62
+ outputSchemaForReturn = stringify(
63
+ zodToJsonSchema(_tool.outputSchema)
64
+ );
65
+ }
66
+ }
67
+ } catch (error) {
68
+ console.error(`Error getting serialized tool`, {
69
+ toolId: _tool.id,
70
+ error
71
+ });
72
+ }
73
+ acc[key] = {
74
+ ..._tool,
75
+ id: toolId,
76
+ inputSchema: inputSchemaForReturn,
77
+ outputSchema: outputSchemaForReturn
78
+ };
79
+ return acc;
80
+ }, {});
81
+ }
82
+ function getSerializedProcessors(processors) {
83
+ return processors.map((processor) => {
84
+ return {
85
+ name: processor.name || processor.constructor.name
86
+ };
87
+ });
88
+ }
89
+ async function getSerializedAgentDefinition({
90
+ agent,
91
+ runtimeContext
92
+ }) {
93
+ let serializedAgentAgents = {};
94
+ if ("listAgents" in agent) {
95
+ const agents = await agent.listAgents({ runtimeContext });
96
+ serializedAgentAgents = Object.entries(agents || {}).reduce(
97
+ (acc, [key, agent2]) => {
98
+ return {
99
+ ...acc,
100
+ [key]: { id: agent2.id, name: agent2.name }
101
+ };
102
+ },
103
+ {}
104
+ );
105
+ }
106
+ return serializedAgentAgents;
107
+ }
108
+ async function formatAgentList({
109
+ id,
110
+ mastra,
111
+ agent,
112
+ runtimeContext
113
+ }) {
114
+ const instructions = await agent.getInstructions({ runtimeContext });
115
+ const tools = await agent.getTools({ runtimeContext });
116
+ const llm = await agent.getLLM({ runtimeContext });
117
+ const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext });
118
+ const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext });
119
+ const serializedAgentTools = await getSerializedAgentTools(tools);
120
+ let serializedAgentWorkflows = {};
121
+ if ("getWorkflows" in agent) {
122
+ const logger = mastra.getLogger();
123
+ try {
124
+ const workflows = await agent.getWorkflows({ runtimeContext });
125
+ serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
126
+ return {
127
+ ...acc,
128
+ [key]: {
129
+ name: workflow.name || "Unnamed workflow"
130
+ }
131
+ };
132
+ }, {});
133
+ } catch (error) {
134
+ logger.error("Error getting workflows for agent", { agentName: agent.name, error });
135
+ }
136
+ }
137
+ const serializedAgentAgents = await getSerializedAgentDefinition({ agent, runtimeContext });
138
+ const inputProcessors = await agent.getInputProcessors(runtimeContext);
139
+ const outputProcessors = await agent.getOutputProcessors(runtimeContext);
140
+ const serializedInputProcessors = getSerializedProcessors(inputProcessors);
141
+ const serializedOutputProcessors = getSerializedProcessors(outputProcessors);
142
+ const model = llm?.getModel();
143
+ const models = await agent.getModelList(runtimeContext);
144
+ const modelList = models?.map((md) => ({
145
+ ...md,
146
+ model: {
147
+ modelId: md.model.modelId,
148
+ provider: md.model.provider,
149
+ modelVersion: md.model.specificationVersion
150
+ }
151
+ }));
152
+ return {
153
+ id,
154
+ name: agent.name,
155
+ instructions,
156
+ agents: serializedAgentAgents,
157
+ tools: serializedAgentTools,
158
+ workflows: serializedAgentWorkflows,
159
+ inputProcessors: serializedInputProcessors,
160
+ outputProcessors: serializedOutputProcessors,
161
+ provider: llm?.getProvider(),
162
+ modelId: llm?.getModelId(),
163
+ modelVersion: model?.specificationVersion,
164
+ defaultGenerateOptions,
165
+ defaultStreamOptions,
166
+ modelList
167
+ };
168
+ }
169
+ async function getAgentFromSystem({ mastra, agentId }) {
170
+ const logger = mastra.getLogger();
171
+ if (!agentId) {
172
+ throw new HTTPException(400, { message: "Agent ID is required" });
173
+ }
174
+ let agent;
175
+ try {
176
+ agent = mastra.getAgent(agentId);
177
+ } catch (error) {
178
+ logger.debug("Error getting agent from mastra, searching agents for agent", error);
179
+ }
180
+ if (!agent) {
181
+ logger.debug(`Agent ${agentId} not found, looking through sub-agents`);
182
+ const agents = mastra.getAgents();
183
+ if (Object.keys(agents || {}).length) {
184
+ for (const [_, ag] of Object.entries(agents)) {
185
+ try {
186
+ const subAgents = await ag.listAgents();
187
+ if (subAgents[agentId]) {
188
+ agent = subAgents[agentId];
189
+ break;
190
+ }
191
+ } catch (error) {
192
+ logger.debug("Error getting agent from agent", error);
193
+ }
194
+ }
195
+ }
196
+ }
197
+ if (!agent) {
198
+ throw new HTTPException(404, { message: `Agent with name ${agentId} not found` });
199
+ }
200
+ return agent;
201
+ }
202
+ async function getAgentsHandler({
203
+ mastra,
204
+ runtimeContext
205
+ }) {
206
+ try {
207
+ const agents = mastra.getAgents();
208
+ const serializedAgentsMap = await Promise.all(
209
+ Object.entries(agents).map(async ([id, agent]) => {
210
+ return formatAgentList({ id, mastra, agent, runtimeContext });
211
+ })
212
+ );
213
+ const serializedAgents = serializedAgentsMap.reduce((acc, { id, ...rest }) => {
214
+ acc[id] = rest;
215
+ return acc;
216
+ }, {});
217
+ return serializedAgents;
218
+ } catch (error) {
219
+ return handleError(error, "Error getting agents");
220
+ }
221
+ }
222
+ async function formatAgent({
223
+ mastra,
224
+ agent,
225
+ runtimeContext,
226
+ isPlayground
227
+ }) {
228
+ const tools = await agent.getTools({ runtimeContext });
229
+ const serializedAgentTools = await getSerializedAgentTools(tools);
230
+ let serializedAgentWorkflows = {};
231
+ if ("getWorkflows" in agent) {
232
+ const logger = mastra.getLogger();
233
+ try {
234
+ const workflows = await agent.getWorkflows({ runtimeContext });
235
+ serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
236
+ return {
237
+ ...acc,
238
+ [key]: {
239
+ name: workflow.name || "Unnamed workflow",
240
+ steps: Object.entries(workflow.steps).reduce(
241
+ (acc2, [key2, step]) => {
242
+ return {
243
+ ...acc2,
244
+ [key2]: {
245
+ id: step.id,
246
+ description: step.description
247
+ }
248
+ };
249
+ },
250
+ {}
251
+ )
252
+ }
253
+ };
254
+ }, {});
255
+ } catch (error) {
256
+ logger.error("Error getting workflows for agent", { agentName: agent.name, error });
257
+ }
258
+ }
259
+ let proxyRuntimeContext = runtimeContext;
260
+ if (isPlayground) {
261
+ proxyRuntimeContext = new Proxy(runtimeContext, {
262
+ get(target, prop) {
263
+ if (prop === "get") {
264
+ return function(key) {
265
+ const value = target.get(key);
266
+ return value ?? `<${key}>`;
267
+ };
268
+ }
269
+ return Reflect.get(target, prop);
270
+ }
271
+ });
272
+ }
273
+ const instructions = await agent.getInstructions({ runtimeContext: proxyRuntimeContext });
274
+ const llm = await agent.getLLM({ runtimeContext });
275
+ const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext: proxyRuntimeContext });
276
+ const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext: proxyRuntimeContext });
277
+ const model = llm?.getModel();
278
+ const models = await agent.getModelList(runtimeContext);
279
+ const modelList = models?.map((md) => ({
280
+ ...md,
281
+ model: {
282
+ modelId: md.model.modelId,
283
+ provider: md.model.provider,
284
+ modelVersion: md.model.specificationVersion
285
+ }
286
+ }));
287
+ const serializedAgentAgents = await getSerializedAgentDefinition({ agent, runtimeContext: proxyRuntimeContext });
288
+ const inputProcessors = await agent.getInputProcessors(proxyRuntimeContext);
289
+ const outputProcessors = await agent.getOutputProcessors(proxyRuntimeContext);
290
+ const serializedInputProcessors = getSerializedProcessors(inputProcessors);
291
+ const serializedOutputProcessors = getSerializedProcessors(outputProcessors);
292
+ return {
293
+ name: agent.name,
294
+ instructions,
295
+ tools: serializedAgentTools,
296
+ agents: serializedAgentAgents,
297
+ workflows: serializedAgentWorkflows,
298
+ inputProcessors: serializedInputProcessors,
299
+ outputProcessors: serializedOutputProcessors,
300
+ provider: llm?.getProvider(),
301
+ modelId: llm?.getModelId(),
302
+ modelVersion: model?.specificationVersion,
303
+ modelList,
304
+ defaultGenerateOptions,
305
+ defaultStreamOptions
306
+ };
307
+ }
308
+ async function getAgentByIdHandler({
309
+ mastra,
310
+ runtimeContext,
311
+ agentId,
312
+ isPlayground = false
313
+ }) {
314
+ try {
315
+ const agent = await getAgentFromSystem({ mastra, agentId });
316
+ return formatAgent({ mastra, agent, runtimeContext, isPlayground });
317
+ } catch (error) {
318
+ return handleError(error, "Error getting agent");
319
+ }
320
+ }
321
+ async function getEvalsByAgentIdHandler({
322
+ mastra,
323
+ runtimeContext,
324
+ agentId
325
+ }) {
326
+ try {
327
+ const agent = await getAgentFromSystem({ mastra, agentId });
328
+ const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
329
+ const instructions = await agent.getInstructions({ runtimeContext });
330
+ return {
331
+ id: agentId,
332
+ name: agent.name,
333
+ instructions,
334
+ evals
335
+ };
336
+ } catch (error) {
337
+ return handleError(error, "Error getting test evals");
338
+ }
339
+ }
340
+ async function getLiveEvalsByAgentIdHandler({
341
+ mastra,
342
+ runtimeContext,
343
+ agentId
344
+ }) {
345
+ try {
346
+ const agent = await getAgentFromSystem({ mastra, agentId });
347
+ const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
348
+ const instructions = await agent.getInstructions({ runtimeContext });
349
+ return {
350
+ id: agentId,
351
+ name: agent.name,
352
+ instructions,
353
+ evals
354
+ };
355
+ } catch (error) {
356
+ return handleError(error, "Error getting live evals");
357
+ }
358
+ }
359
+ async function generateLegacyHandler({
360
+ mastra,
361
+ runtimeContext,
362
+ agentId,
363
+ body,
364
+ abortSignal
365
+ }) {
366
+ try {
367
+ const agent = await getAgentFromSystem({ mastra, agentId });
368
+ sanitizeBody(body, ["tools"]);
369
+ const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
370
+ const finalResourceId = resourceId ?? resourceid;
371
+ const finalRuntimeContext = new RuntimeContext([
372
+ ...Array.from(runtimeContext.entries()),
373
+ ...Array.from(Object.entries(agentRuntimeContext ?? {}))
374
+ ]);
375
+ validateBody({ messages });
376
+ const result = await agent.generateLegacy(messages, {
377
+ ...rest,
378
+ abortSignal,
379
+ // @ts-expect-error TODO fix types
380
+ resourceId: finalResourceId,
381
+ runtimeContext: finalRuntimeContext
382
+ });
383
+ return result;
384
+ } catch (error) {
385
+ return handleError(error, "Error generating from agent");
386
+ }
387
+ }
388
+ async function generateHandler({
389
+ mastra,
390
+ runtimeContext,
391
+ agentId,
392
+ body,
393
+ abortSignal
394
+ }) {
395
+ try {
396
+ const agent = await getAgentFromSystem({ mastra, agentId });
397
+ sanitizeBody(body, ["tools"]);
398
+ const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
399
+ const finalRuntimeContext = new RuntimeContext([
400
+ ...Array.from(runtimeContext.entries()),
401
+ ...Array.from(Object.entries(agentRuntimeContext ?? {}))
402
+ ]);
403
+ validateBody({ messages });
404
+ const result = await agent.generate(messages, {
405
+ ...rest,
406
+ runtimeContext: finalRuntimeContext,
407
+ format: rest.format || "mastra",
408
+ abortSignal
409
+ });
410
+ return result;
411
+ } catch (error) {
412
+ return handleError(error, "Error generating from agent");
413
+ }
414
+ }
415
+ async function streamGenerateLegacyHandler({
416
+ mastra,
417
+ runtimeContext,
418
+ agentId,
419
+ body,
420
+ abortSignal
421
+ }) {
422
+ try {
423
+ const agent = await getAgentFromSystem({ mastra, agentId });
424
+ const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
425
+ const finalResourceId = resourceId ?? resourceid;
426
+ const finalRuntimeContext = new RuntimeContext([
427
+ ...Array.from(runtimeContext.entries()),
428
+ ...Array.from(Object.entries(agentRuntimeContext ?? {}))
429
+ ]);
430
+ validateBody({ messages });
431
+ const streamResult = await agent.streamLegacy(messages, {
432
+ ...rest,
433
+ abortSignal,
434
+ // @ts-expect-error TODO fix types
435
+ resourceId: finalResourceId,
436
+ runtimeContext: finalRuntimeContext
437
+ });
438
+ const streamResponse = rest.output ? streamResult.toTextStreamResponse({
439
+ headers: {
440
+ "Transfer-Encoding": "chunked"
441
+ }
442
+ }) : streamResult.toDataStreamResponse({
443
+ sendUsage: true,
444
+ sendReasoning: true,
445
+ getErrorMessage: (error) => {
446
+ return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
447
+ },
448
+ headers: {
449
+ "Transfer-Encoding": "chunked"
450
+ }
451
+ });
452
+ return streamResponse;
453
+ } catch (error) {
454
+ return handleError(error, "error streaming agent response");
455
+ }
456
+ }
457
+ async function streamGenerateHandler({
458
+ mastra,
459
+ runtimeContext,
460
+ agentId,
461
+ body,
462
+ abortSignal
463
+ }) {
464
+ try {
465
+ const agent = await getAgentFromSystem({ mastra, agentId });
466
+ sanitizeBody(body, ["tools"]);
467
+ const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
468
+ const finalRuntimeContext = new RuntimeContext([
469
+ ...Array.from(runtimeContext.entries()),
470
+ ...Array.from(Object.entries(agentRuntimeContext ?? {}))
471
+ ]);
472
+ validateBody({ messages });
473
+ const streamResult = agent.stream(messages, {
474
+ ...rest,
475
+ runtimeContext: finalRuntimeContext,
476
+ abortSignal,
477
+ format: body.format ?? "mastra"
478
+ });
479
+ return streamResult;
480
+ } catch (error) {
481
+ return handleError(error, "error streaming agent response");
482
+ }
483
+ }
484
+ async function approveToolCallHandler({
485
+ mastra,
486
+ runtimeContext,
487
+ agentId,
488
+ body,
489
+ abortSignal
490
+ }) {
491
+ try {
492
+ const agent = await getAgentFromSystem({ mastra, agentId });
493
+ if (!body.runId) {
494
+ throw new HTTPException(400, { message: "Run id is required" });
495
+ }
496
+ if (!body.toolCallId) {
497
+ throw new HTTPException(400, { message: "Tool call id is required" });
498
+ }
499
+ sanitizeBody(body, ["tools"]);
500
+ const { runId, runtimeContext: agentRuntimeContext, ...rest } = body;
501
+ const finalRuntimeContext = new RuntimeContext([
502
+ ...Array.from(runtimeContext.entries()),
503
+ ...Array.from(Object.entries(agentRuntimeContext ?? {}))
504
+ ]);
505
+ const streamResult = agent.approveToolCall({
506
+ ...rest,
507
+ runId,
508
+ runtimeContext: finalRuntimeContext,
509
+ abortSignal,
510
+ format: body.format ?? "mastra"
511
+ });
512
+ return streamResult;
513
+ } catch (error) {
514
+ return handleError(error, "error streaming agent response");
515
+ }
516
+ }
517
+ async function declineToolCallHandler({
518
+ mastra,
519
+ runtimeContext,
520
+ agentId,
521
+ body,
522
+ abortSignal
523
+ }) {
524
+ try {
525
+ const agent = await getAgentFromSystem({ mastra, agentId });
526
+ if (!body.runId) {
527
+ throw new HTTPException(400, { message: "Run id is required" });
528
+ }
529
+ if (!body.toolCallId) {
530
+ throw new HTTPException(400, { message: "Tool call id is required" });
531
+ }
532
+ sanitizeBody(body, ["tools"]);
533
+ const { runId, runtimeContext: agentRuntimeContext, ...rest } = body;
534
+ const finalRuntimeContext = new RuntimeContext([
535
+ ...Array.from(runtimeContext.entries()),
536
+ ...Array.from(Object.entries(agentRuntimeContext ?? {}))
537
+ ]);
538
+ const streamResult = agent.declineToolCall({
539
+ ...rest,
540
+ runId,
541
+ runtimeContext: finalRuntimeContext,
542
+ abortSignal,
543
+ format: body.format ?? "mastra"
544
+ });
545
+ return streamResult;
546
+ } catch (error) {
547
+ return handleError(error, "error streaming agent response");
548
+ }
549
+ }
550
+ async function streamNetworkHandler({
551
+ mastra,
552
+ runtimeContext,
553
+ agentId,
554
+ body
555
+ // abortSignal,
556
+ }) {
557
+ try {
558
+ const agent = await getAgentFromSystem({ mastra, agentId });
559
+ sanitizeBody(body, ["tools"]);
560
+ const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
561
+ const finalRuntimeContext = new RuntimeContext([
562
+ ...Array.from(runtimeContext.entries()),
563
+ ...Array.from(Object.entries(agentRuntimeContext ?? {}))
564
+ ]);
565
+ validateBody({ messages });
566
+ const streamResult = agent.network(messages, {
567
+ ...rest,
568
+ memory: {
569
+ thread: rest.memory?.thread ?? "",
570
+ resource: rest.memory?.resource ?? "",
571
+ options: rest.memory?.options ?? {}
572
+ },
573
+ runtimeContext: finalRuntimeContext
574
+ });
575
+ return streamResult;
576
+ } catch (error) {
577
+ return handleError(error, "error streaming agent loop response");
578
+ }
579
+ }
580
+ async function streamUIMessageHandler({
581
+ mastra,
582
+ runtimeContext,
583
+ agentId,
584
+ body,
585
+ abortSignal
586
+ }) {
587
+ try {
588
+ const agent = await getAgentFromSystem({ mastra, agentId });
589
+ sanitizeBody(body, ["tools"]);
590
+ const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
591
+ const finalRuntimeContext = new RuntimeContext([
592
+ ...Array.from(runtimeContext.entries()),
593
+ ...Array.from(Object.entries(agentRuntimeContext ?? {}))
594
+ ]);
595
+ validateBody({ messages });
596
+ const streamResult = await agent.stream(messages, {
597
+ ...rest,
598
+ runtimeContext: finalRuntimeContext,
599
+ abortSignal,
600
+ format: "aisdk"
601
+ });
602
+ return streamResult.toUIMessageStreamResponse();
603
+ } catch (error) {
604
+ return handleError(error, "error streaming agent response");
605
+ }
606
+ }
607
+ async function updateAgentModelHandler({
608
+ mastra,
609
+ agentId,
610
+ body
611
+ }) {
612
+ try {
613
+ const agent = await getAgentFromSystem({ mastra, agentId });
614
+ const { modelId, provider } = body;
615
+ const newModel = `${provider}/${modelId}`;
616
+ agent.__updateModel({ model: newModel });
617
+ return { message: "Agent model updated" };
618
+ } catch (error) {
619
+ return handleError(error, "error updating agent model");
620
+ }
621
+ }
622
+ async function resetAgentModelHandler({
623
+ mastra,
624
+ agentId
625
+ }) {
626
+ try {
627
+ const agent = await getAgentFromSystem({ mastra, agentId });
628
+ agent.__resetToOriginalModel();
629
+ return { message: "Agent model reset to original" };
630
+ } catch (error) {
631
+ return handleError(error, "error resetting agent model");
632
+ }
633
+ }
634
+ async function reorderAgentModelListHandler({
635
+ mastra,
636
+ agentId,
637
+ body
638
+ }) {
639
+ try {
640
+ const agent = await getAgentFromSystem({ mastra, agentId });
641
+ const modelList = await agent.getModelList();
642
+ if (!modelList || modelList.length === 0) {
643
+ throw new HTTPException(400, { message: "Agent model list is not found or empty" });
644
+ }
645
+ agent.reorderModels(body.reorderedModelIds);
646
+ return { message: "Model list reordered" };
647
+ } catch (error) {
648
+ return handleError(error, "error reordering model list");
649
+ }
650
+ }
651
+ async function updateAgentModelInModelListHandler({
652
+ mastra,
653
+ agentId,
654
+ modelConfigId,
655
+ body
656
+ }) {
657
+ try {
658
+ const agent = await getAgentFromSystem({ mastra, agentId });
659
+ const { model: bodyModel, maxRetries, enabled } = body;
660
+ if (!modelConfigId) {
661
+ throw new HTTPException(400, { message: "Model id is required" });
662
+ }
663
+ const modelList = await agent.getModelList();
664
+ if (!modelList || modelList.length === 0) {
665
+ throw new HTTPException(400, { message: "Agent model list is not found or empty" });
666
+ }
667
+ const modelToUpdate = modelList.find((m) => m.id === modelConfigId);
668
+ if (!modelToUpdate) {
669
+ throw new HTTPException(400, { message: "Model to update is not found in agent model list" });
670
+ }
671
+ let model;
672
+ if (bodyModel) {
673
+ const { modelId, provider } = bodyModel;
674
+ model = `${provider}/${modelId}`;
675
+ }
676
+ agent.updateModelInModelList({ id: modelConfigId, model, maxRetries, enabled });
677
+ return { message: "Model list updated" };
678
+ } catch (error) {
679
+ return handleError(error, "error updating model list");
680
+ }
681
+ }
682
+ async function getProvidersHandler() {
683
+ try {
684
+ const providers = Object.entries(PROVIDER_REGISTRY).map(([id, provider]) => {
685
+ const envVars = Array.isArray(provider.apiKeyEnvVar) ? provider.apiKeyEnvVar : [provider.apiKeyEnvVar];
686
+ const connected = envVars.every((envVar) => !!process.env[envVar]);
687
+ return {
688
+ id,
689
+ name: provider.name,
690
+ envVar: provider.apiKeyEnvVar,
691
+ connected,
692
+ docUrl: provider.docUrl,
693
+ models: [...provider.models]
694
+ // Convert readonly array to regular array
695
+ };
696
+ });
697
+ return { providers };
698
+ } catch (error) {
699
+ return handleError(error, "error fetching providers");
700
+ }
701
+ }
702
+
703
+ export { agents_exports, approveToolCallHandler, declineToolCallHandler, generateHandler, generateLegacyHandler, getAgentByIdHandler, getAgentFromSystem, getAgentsHandler, getEvalsByAgentIdHandler, getLiveEvalsByAgentIdHandler, getProvidersHandler, getSerializedAgentTools, getSerializedProcessors, reorderAgentModelListHandler, resetAgentModelHandler, streamGenerateHandler, streamGenerateLegacyHandler, streamNetworkHandler, streamUIMessageHandler, updateAgentModelHandler, updateAgentModelInModelListHandler };
704
+ //# sourceMappingURL=chunk-6N3HC6O4.js.map
705
+ //# sourceMappingURL=chunk-6N3HC6O4.js.map