@mastra/server 0.0.0-message-list-update-20250715150321 → 0.0.0-monorepo-binary-20251013210052

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 (279) hide show
  1. package/CHANGELOG.md +4009 -0
  2. package/README.md +0 -5
  3. package/dist/chunk-2PLXW4ZX.cjs +2777 -0
  4. package/dist/chunk-2PLXW4ZX.cjs.map +1 -0
  5. package/dist/chunk-2S4IMB6E.cjs +130 -0
  6. package/dist/chunk-2S4IMB6E.cjs.map +1 -0
  7. package/dist/chunk-3LGGSMCC.cjs +256 -0
  8. package/dist/chunk-3LGGSMCC.cjs.map +1 -0
  9. package/dist/chunk-3LTO44EP.cjs +570 -0
  10. package/dist/chunk-3LTO44EP.cjs.map +1 -0
  11. package/dist/chunk-3SNGNFUJ.cjs +128 -0
  12. package/dist/chunk-3SNGNFUJ.cjs.map +1 -0
  13. package/dist/{chunk-RSEO4XPX.js → chunk-4QCXUEAT.js} +11 -2
  14. package/dist/chunk-4QCXUEAT.js.map +1 -0
  15. package/dist/chunk-5BNQIYQN.js +189 -0
  16. package/dist/chunk-5BNQIYQN.js.map +1 -0
  17. package/dist/{chunk-RG473F6Y.js → chunk-67GYDFSB.js} +24 -5
  18. package/dist/chunk-67GYDFSB.js.map +1 -0
  19. package/dist/chunk-6BMOC6SA.cjs +48 -0
  20. package/dist/chunk-6BMOC6SA.cjs.map +1 -0
  21. package/dist/{chunk-G7KH752Y.cjs → chunk-6ZR275MD.cjs} +28 -8
  22. package/dist/chunk-6ZR275MD.cjs.map +1 -0
  23. package/dist/{chunk-2KZFMI6P.cjs → chunk-7NADHFD2.cjs} +2 -0
  24. package/dist/chunk-7NADHFD2.cjs.map +1 -0
  25. package/dist/{chunk-4D66QEKC.js → chunk-ABRFV4XP.js} +5 -3
  26. package/dist/chunk-ABRFV4XP.js.map +1 -0
  27. package/dist/{chunk-LRCAAFUA.js → chunk-AHB4JCIQ.js} +50 -12
  28. package/dist/chunk-AHB4JCIQ.js.map +1 -0
  29. package/dist/chunk-BATEJLED.js +124 -0
  30. package/dist/chunk-BATEJLED.js.map +1 -0
  31. package/dist/chunk-BZLZFHAT.cjs +682 -0
  32. package/dist/chunk-BZLZFHAT.cjs.map +1 -0
  33. package/dist/{chunk-LF7P5PLR.js → chunk-CY4TP3FK.js} +3 -1
  34. package/dist/chunk-CY4TP3FK.js.map +1 -0
  35. package/dist/{chunk-H7DMHBKY.js → chunk-DB63UMTV.js} +249 -87
  36. package/dist/chunk-DB63UMTV.js.map +1 -0
  37. package/dist/chunk-DTBJ3D22.js +19480 -0
  38. package/dist/chunk-DTBJ3D22.js.map +1 -0
  39. package/dist/{chunk-7TP2LX5L.cjs → chunk-EP3JQDPD.cjs} +20 -18
  40. package/dist/chunk-EP3JQDPD.cjs.map +1 -0
  41. package/dist/chunk-G4PUALCE.cjs +28 -0
  42. package/dist/chunk-G4PUALCE.cjs.map +1 -0
  43. package/dist/chunk-GU4EWMZB.cjs +769 -0
  44. package/dist/chunk-GU4EWMZB.cjs.map +1 -0
  45. package/dist/chunk-H2CO44WB.js +46 -0
  46. package/dist/chunk-H2CO44WB.js.map +1 -0
  47. package/dist/{chunk-GHC4YV6R.js → chunk-HPXAM2PG.js} +109 -136
  48. package/dist/chunk-HPXAM2PG.js.map +1 -0
  49. package/dist/{chunk-JMLYCXMK.cjs → chunk-I3C4ODGV.cjs} +48 -45
  50. package/dist/chunk-I3C4ODGV.cjs.map +1 -0
  51. package/dist/chunk-JSLAYFEW.js +662 -0
  52. package/dist/chunk-JSLAYFEW.js.map +1 -0
  53. package/dist/chunk-KQZPT7AO.js +254 -0
  54. package/dist/chunk-KQZPT7AO.js.map +1 -0
  55. package/dist/chunk-LF2ZLOFP.js +767 -0
  56. package/dist/chunk-LF2ZLOFP.js.map +1 -0
  57. package/dist/{chunk-5PQQ42EZ.js → chunk-LLUOPR3J.js} +13 -10
  58. package/dist/chunk-LLUOPR3J.js.map +1 -0
  59. package/dist/chunk-LNT5N7XW.cjs +197 -0
  60. package/dist/chunk-LNT5N7XW.cjs.map +1 -0
  61. package/dist/chunk-LPM6BBAX.cjs +1043 -0
  62. package/dist/chunk-LPM6BBAX.cjs.map +1 -0
  63. package/dist/{chunk-LCM566I4.js → chunk-MMROOK5J.js} +2 -0
  64. package/dist/chunk-MMROOK5J.js.map +1 -0
  65. package/dist/chunk-MQDBNHBT.cjs +680 -0
  66. package/dist/chunk-MQDBNHBT.cjs.map +1 -0
  67. package/dist/{chunk-WNVFNNWN.js → chunk-MYR4PVGN.js} +5 -3
  68. package/dist/chunk-MYR4PVGN.js.map +1 -0
  69. package/dist/chunk-O7I5CWRX.cjs +44 -0
  70. package/dist/chunk-O7I5CWRX.cjs.map +1 -0
  71. package/dist/chunk-OEOGYAQC.js +553 -0
  72. package/dist/chunk-OEOGYAQC.js.map +1 -0
  73. package/dist/chunk-PR4QN5HX.js +39 -0
  74. package/dist/chunk-PR4QN5HX.js.map +1 -0
  75. package/dist/{chunk-KHZKYUNR.js → chunk-QQXMIP6C.js} +23 -13
  76. package/dist/chunk-QQXMIP6C.js.map +1 -0
  77. package/dist/{chunk-PZQDCRPV.cjs → chunk-RE4RPXT2.cjs} +4 -2
  78. package/dist/chunk-RE4RPXT2.cjs.map +1 -0
  79. package/dist/chunk-RQK4FQUD.js +1012 -0
  80. package/dist/chunk-RQK4FQUD.js.map +1 -0
  81. package/dist/chunk-SBWOUCO3.cjs +19516 -0
  82. package/dist/chunk-SBWOUCO3.cjs.map +1 -0
  83. package/dist/{chunk-SDPGVWQJ.cjs → chunk-TOP25AIO.cjs} +110 -137
  84. package/dist/chunk-TOP25AIO.cjs.map +1 -0
  85. package/dist/chunk-TRGAMKHX.cjs +167 -0
  86. package/dist/chunk-TRGAMKHX.cjs.map +1 -0
  87. package/dist/chunk-VY4ENABS.cjs +135 -0
  88. package/dist/chunk-VY4ENABS.cjs.map +1 -0
  89. package/dist/{chunk-QGX47B5D.cjs → chunk-XN74I6VW.cjs} +11 -9
  90. package/dist/chunk-XN74I6VW.cjs.map +1 -0
  91. package/dist/chunk-YWOK4F5A.js +131 -0
  92. package/dist/chunk-YWOK4F5A.js.map +1 -0
  93. package/dist/chunk-ZULZ2752.js +2774 -0
  94. package/dist/chunk-ZULZ2752.js.map +1 -0
  95. package/dist/dist-4MVGNSRL.cjs +1150 -0
  96. package/dist/dist-4MVGNSRL.cjs.map +1 -0
  97. package/dist/dist-FZYCV3VB.cjs +940 -0
  98. package/dist/dist-FZYCV3VB.cjs.map +1 -0
  99. package/dist/dist-G2BYZJOC.cjs +928 -0
  100. package/dist/dist-G2BYZJOC.cjs.map +1 -0
  101. package/dist/dist-P4MXBQ3U.cjs +16 -0
  102. package/dist/dist-P4MXBQ3U.cjs.map +1 -0
  103. package/dist/dist-PQZUVLPC.js +937 -0
  104. package/dist/dist-PQZUVLPC.js.map +1 -0
  105. package/dist/dist-R7WYX6LC.js +925 -0
  106. package/dist/dist-R7WYX6LC.js.map +1 -0
  107. package/dist/dist-RFMYFILX.cjs +764 -0
  108. package/dist/dist-RFMYFILX.cjs.map +1 -0
  109. package/dist/dist-X7XR3M3Z.js +1147 -0
  110. package/dist/dist-X7XR3M3Z.js.map +1 -0
  111. package/dist/dist-XVBSOGFK.js +761 -0
  112. package/dist/dist-XVBSOGFK.js.map +1 -0
  113. package/dist/dist-YREX2TJT.js +3 -0
  114. package/dist/dist-YREX2TJT.js.map +1 -0
  115. package/dist/index.cjs +6 -0
  116. package/dist/index.cjs.map +1 -0
  117. package/dist/index.d.ts +1 -0
  118. package/dist/index.d.ts.map +1 -0
  119. package/dist/index.js +5 -0
  120. package/dist/index.js.map +1 -0
  121. package/dist/server/a2a/protocol.d.ts +8 -0
  122. package/dist/server/a2a/protocol.d.ts.map +1 -0
  123. package/dist/server/a2a/store.cjs +25 -0
  124. package/dist/server/a2a/store.cjs.map +1 -0
  125. package/dist/server/a2a/store.d.ts +14 -0
  126. package/dist/server/a2a/store.d.ts.map +1 -0
  127. package/dist/server/a2a/store.js +23 -0
  128. package/dist/server/a2a/store.js.map +1 -0
  129. package/dist/server/a2a/tasks.d.ts +20 -0
  130. package/dist/server/a2a/tasks.d.ts.map +1 -0
  131. package/dist/server/handlers/a2a.cjs +13 -11
  132. package/dist/server/handlers/a2a.cjs.map +1 -0
  133. package/dist/server/handlers/a2a.d.ts +68 -6
  134. package/dist/server/handlers/a2a.d.ts.map +1 -0
  135. package/dist/server/handlers/a2a.js +3 -1
  136. package/dist/server/handlers/a2a.js.map +1 -0
  137. package/dist/server/handlers/agent-builder.cjs +68 -0
  138. package/dist/server/handlers/agent-builder.cjs.map +1 -0
  139. package/dist/server/handlers/agent-builder.d.ts +94 -0
  140. package/dist/server/handlers/agent-builder.d.ts.map +1 -0
  141. package/dist/server/handlers/agent-builder.js +3 -0
  142. package/dist/server/handlers/agent-builder.js.map +1 -0
  143. package/dist/server/handlers/agents.cjs +57 -7
  144. package/dist/server/handlers/agents.cjs.map +1 -0
  145. package/dist/server/handlers/agents.d.ts +204 -6
  146. package/dist/server/handlers/agents.d.ts.map +1 -0
  147. package/dist/server/handlers/agents.js +3 -1
  148. package/dist/server/handlers/agents.js.map +1 -0
  149. package/dist/server/handlers/error.cjs +4 -2
  150. package/dist/server/handlers/error.cjs.map +1 -0
  151. package/dist/server/handlers/error.d.ts +2 -1
  152. package/dist/server/handlers/error.d.ts.map +1 -0
  153. package/dist/server/handlers/error.js +3 -1
  154. package/dist/server/handlers/error.js.map +1 -0
  155. package/dist/server/handlers/legacyWorkflows.cjs +13 -11
  156. package/dist/server/handlers/legacyWorkflows.cjs.map +1 -0
  157. package/dist/server/handlers/legacyWorkflows.d.ts +59 -10
  158. package/dist/server/handlers/legacyWorkflows.d.ts.map +1 -0
  159. package/dist/server/handlers/legacyWorkflows.js +3 -1
  160. package/dist/server/handlers/legacyWorkflows.js.map +1 -0
  161. package/dist/server/handlers/logs.cjs +6 -4
  162. package/dist/server/handlers/logs.cjs.map +1 -0
  163. package/dist/server/handlers/logs.d.ts +34 -3
  164. package/dist/server/handlers/logs.d.ts.map +1 -0
  165. package/dist/server/handlers/logs.js +3 -1
  166. package/dist/server/handlers/logs.js.map +1 -0
  167. package/dist/server/handlers/memory.cjs +33 -11
  168. package/dist/server/handlers/memory.cjs.map +1 -0
  169. package/dist/server/handlers/memory.d.ts +118 -10
  170. package/dist/server/handlers/memory.d.ts.map +1 -0
  171. package/dist/server/handlers/memory.js +3 -1
  172. package/dist/server/handlers/memory.js.map +1 -0
  173. package/dist/server/handlers/observability.cjs +24 -0
  174. package/dist/server/handlers/observability.cjs.map +1 -0
  175. package/dist/server/handlers/observability.d.ts +49 -0
  176. package/dist/server/handlers/observability.d.ts.map +1 -0
  177. package/dist/server/handlers/observability.js +3 -0
  178. package/dist/server/handlers/observability.js.map +1 -0
  179. package/dist/server/handlers/scores.cjs +32 -0
  180. package/dist/server/handlers/scores.cjs.map +1 -0
  181. package/dist/server/handlers/scores.d.ts +251 -0
  182. package/dist/server/handlers/scores.d.ts.map +1 -0
  183. package/dist/server/handlers/scores.js +3 -0
  184. package/dist/server/handlers/scores.js.map +1 -0
  185. package/dist/server/handlers/telemetry.cjs +9 -3
  186. package/dist/server/handlers/telemetry.cjs.map +1 -0
  187. package/dist/server/handlers/telemetry.d.ts +33 -2
  188. package/dist/server/handlers/telemetry.d.ts.map +1 -0
  189. package/dist/server/handlers/telemetry.js +3 -1
  190. package/dist/server/handlers/telemetry.js.map +1 -0
  191. package/dist/server/handlers/tools.cjs +11 -5
  192. package/dist/server/handlers/tools.cjs.map +1 -0
  193. package/dist/server/handlers/tools.d.ts +25 -4
  194. package/dist/server/handlers/tools.d.ts.map +1 -0
  195. package/dist/server/handlers/tools.js +3 -1
  196. package/dist/server/handlers/tools.js.map +1 -0
  197. package/dist/server/handlers/utils.cjs +8 -2
  198. package/dist/server/handlers/utils.cjs.map +1 -0
  199. package/dist/server/handlers/utils.d.ts +8 -1
  200. package/dist/server/handlers/utils.d.ts.map +1 -0
  201. package/dist/server/handlers/utils.js +3 -1
  202. package/dist/server/handlers/utils.js.map +1 -0
  203. package/dist/server/handlers/vector.cjs +9 -7
  204. package/dist/server/handlers/vector.cjs.map +1 -0
  205. package/dist/server/handlers/vector.d.ts +51 -6
  206. package/dist/server/handlers/vector.d.ts.map +1 -0
  207. package/dist/server/handlers/vector.js +3 -1
  208. package/dist/server/handlers/vector.js.map +1 -0
  209. package/dist/server/handlers/voice.cjs +7 -5
  210. package/dist/server/handlers/voice.cjs.map +1 -0
  211. package/dist/server/handlers/voice.d.ts +41 -4
  212. package/dist/server/handlers/voice.d.ts.map +1 -0
  213. package/dist/server/handlers/voice.js +3 -1
  214. package/dist/server/handlers/voice.js.map +1 -0
  215. package/dist/server/handlers/workflows.cjs +33 -15
  216. package/dist/server/handlers/workflows.cjs.map +1 -0
  217. package/dist/server/handlers/workflows.d.ts +91 -14
  218. package/dist/server/handlers/workflows.d.ts.map +1 -0
  219. package/dist/server/handlers/workflows.js +3 -1
  220. package/dist/server/handlers/workflows.js.map +1 -0
  221. package/dist/server/handlers.cjs +44 -32
  222. package/dist/server/handlers.cjs.map +1 -0
  223. package/dist/server/handlers.d.ts +14 -11
  224. package/dist/server/handlers.d.ts.map +1 -0
  225. package/dist/server/handlers.js +15 -11
  226. package/dist/server/handlers.js.map +1 -0
  227. package/dist/server/http-exception.d.ts +87 -0
  228. package/dist/server/http-exception.d.ts.map +1 -0
  229. package/dist/server/types.d.ts +10 -0
  230. package/dist/server/types.d.ts.map +1 -0
  231. package/dist/server/utils.d.ts +44 -0
  232. package/dist/server/utils.d.ts.map +1 -0
  233. package/dist/token-352SFL4N.js +62 -0
  234. package/dist/token-352SFL4N.js.map +1 -0
  235. package/dist/token-JT637FZG.cjs +64 -0
  236. package/dist/token-JT637FZG.cjs.map +1 -0
  237. package/dist/token-util-75OQWZ4W.js +7 -0
  238. package/dist/token-util-75OQWZ4W.js.map +1 -0
  239. package/dist/token-util-WGALAXWM.cjs +9 -0
  240. package/dist/token-util-WGALAXWM.cjs.map +1 -0
  241. package/package.json +37 -14
  242. package/dist/_tsup-dts-rollup.d.cts +0 -1107
  243. package/dist/_tsup-dts-rollup.d.ts +0 -1107
  244. package/dist/chunk-2SLFAFTR.cjs +0 -148
  245. package/dist/chunk-3CNDE7QY.cjs +0 -308
  246. package/dist/chunk-75ZPJI57.cjs +0 -9
  247. package/dist/chunk-B2PAS2IB.cjs +0 -514
  248. package/dist/chunk-BK4XT6EG.js +0 -270
  249. package/dist/chunk-CCGRCYWJ.cjs +0 -18
  250. package/dist/chunk-CRCR3ZUK.js +0 -142
  251. package/dist/chunk-FRVBFMO2.cjs +0 -128
  252. package/dist/chunk-KOHWJYJT.js +0 -296
  253. package/dist/chunk-LI436ITD.cjs +0 -2042
  254. package/dist/chunk-LZ3VJXSO.cjs +0 -278
  255. package/dist/chunk-MEGCYGBU.js +0 -2039
  256. package/dist/chunk-MLKGABMK.js +0 -7
  257. package/dist/chunk-RHSWAXKB.cjs +0 -118
  258. package/dist/index.d.cts +0 -1
  259. package/dist/server/handlers/a2a.d.cts +0 -6
  260. package/dist/server/handlers/agents.d.cts +0 -6
  261. package/dist/server/handlers/error.d.cts +0 -1
  262. package/dist/server/handlers/legacyWorkflows.d.cts +0 -10
  263. package/dist/server/handlers/logs.d.cts +0 -3
  264. package/dist/server/handlers/memory.d.cts +0 -10
  265. package/dist/server/handlers/network.cjs +0 -22
  266. package/dist/server/handlers/network.d.cts +0 -4
  267. package/dist/server/handlers/network.d.ts +0 -4
  268. package/dist/server/handlers/network.js +0 -1
  269. package/dist/server/handlers/telemetry.d.cts +0 -2
  270. package/dist/server/handlers/tools.d.cts +0 -4
  271. package/dist/server/handlers/utils.d.cts +0 -1
  272. package/dist/server/handlers/vNextNetwork.cjs +0 -218
  273. package/dist/server/handlers/vNextNetwork.d.cts +0 -6
  274. package/dist/server/handlers/vNextNetwork.d.ts +0 -6
  275. package/dist/server/handlers/vNextNetwork.js +0 -211
  276. package/dist/server/handlers/vector.d.cts +0 -6
  277. package/dist/server/handlers/voice.d.cts +0 -4
  278. package/dist/server/handlers/workflows.d.cts +0 -14
  279. package/dist/server/handlers.d.cts +0 -11
@@ -1,270 +0,0 @@
1
- import { stringify, esm_default } from './chunk-MEGCYGBU.js';
2
- import { validateBody } from './chunk-RSEO4XPX.js';
3
- import { handleError } from './chunk-LF7P5PLR.js';
4
- import { HTTPException } from './chunk-LCM566I4.js';
5
- import { __export } from './chunk-MLKGABMK.js';
6
- import { RuntimeContext } from '@mastra/core/runtime-context';
7
-
8
- // src/server/handlers/agents.ts
9
- var agents_exports = {};
10
- __export(agents_exports, {
11
- generateHandler: () => generateHandler,
12
- getAgentByIdHandler: () => getAgentByIdHandler,
13
- getAgentsHandler: () => getAgentsHandler,
14
- getEvalsByAgentIdHandler: () => getEvalsByAgentIdHandler,
15
- getLiveEvalsByAgentIdHandler: () => getLiveEvalsByAgentIdHandler,
16
- streamGenerateHandler: () => streamGenerateHandler
17
- });
18
- async function getAgentsHandler({ mastra, runtimeContext }) {
19
- try {
20
- const agents = mastra.getAgents();
21
- const serializedAgentsMap = await Promise.all(
22
- Object.entries(agents).map(async ([id, agent]) => {
23
- const instructions = await agent.getInstructions({ runtimeContext });
24
- const tools = await agent.getTools({ runtimeContext });
25
- const llm = await agent.getLLM({ runtimeContext });
26
- const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext });
27
- const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext });
28
- const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
29
- const _tool = tool;
30
- acc[key] = {
31
- ..._tool,
32
- inputSchema: _tool.inputSchema ? stringify(esm_default(_tool.inputSchema)) : void 0,
33
- outputSchema: _tool.outputSchema ? stringify(esm_default(_tool.outputSchema)) : void 0
34
- };
35
- return acc;
36
- }, {});
37
- let serializedAgentWorkflows = {};
38
- if ("getWorkflows" in agent) {
39
- const logger = mastra.getLogger();
40
- try {
41
- const workflows = await agent.getWorkflows({ runtimeContext });
42
- serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
43
- return {
44
- ...acc,
45
- [key]: {
46
- name: workflow.name
47
- }
48
- };
49
- }, {});
50
- } catch (error) {
51
- logger.error("Error getting workflows for agent", { agentName: agent.name, error });
52
- }
53
- }
54
- return {
55
- id,
56
- name: agent.name,
57
- instructions,
58
- tools: serializedAgentTools,
59
- workflows: serializedAgentWorkflows,
60
- provider: llm?.getProvider(),
61
- modelId: llm?.getModelId(),
62
- defaultGenerateOptions,
63
- defaultStreamOptions
64
- };
65
- })
66
- );
67
- const serializedAgents = serializedAgentsMap.reduce((acc, { id, ...rest }) => {
68
- acc[id] = rest;
69
- return acc;
70
- }, {});
71
- return serializedAgents;
72
- } catch (error) {
73
- return handleError(error, "Error getting agents");
74
- }
75
- }
76
- async function getAgentByIdHandler({
77
- mastra,
78
- runtimeContext,
79
- agentId,
80
- isPlayground = false
81
- }) {
82
- try {
83
- const agent = mastra.getAgent(agentId);
84
- if (!agent) {
85
- throw new HTTPException(404, { message: "Agent not found" });
86
- }
87
- const tools = await agent.getTools({ runtimeContext });
88
- const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
89
- const _tool = tool;
90
- acc[key] = {
91
- ..._tool,
92
- inputSchema: _tool.inputSchema ? stringify(esm_default(_tool.inputSchema)) : void 0,
93
- outputSchema: _tool.outputSchema ? stringify(esm_default(_tool.outputSchema)) : void 0
94
- };
95
- return acc;
96
- }, {});
97
- let serializedAgentWorkflows = {};
98
- if ("getWorkflows" in agent) {
99
- const logger = mastra.getLogger();
100
- try {
101
- const workflows = await agent.getWorkflows({ runtimeContext });
102
- serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
103
- return {
104
- ...acc,
105
- [key]: {
106
- name: workflow.name,
107
- steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
108
- return {
109
- ...acc2,
110
- [key2]: {
111
- id: step.id,
112
- description: step.description
113
- }
114
- };
115
- }, {})
116
- }
117
- };
118
- }, {});
119
- } catch (error) {
120
- logger.error("Error getting workflows for agent", { agentName: agent.name, error });
121
- }
122
- }
123
- let proxyRuntimeContext = runtimeContext;
124
- if (isPlayground) {
125
- proxyRuntimeContext = new Proxy(runtimeContext, {
126
- get(target, prop) {
127
- if (prop === "get") {
128
- return function(key) {
129
- const value = target.get(key);
130
- return value ?? `<${key}>`;
131
- };
132
- }
133
- return Reflect.get(target, prop);
134
- }
135
- });
136
- }
137
- const instructions = await agent.getInstructions({ runtimeContext: proxyRuntimeContext });
138
- const llm = await agent.getLLM({ runtimeContext });
139
- const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext: proxyRuntimeContext });
140
- const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext: proxyRuntimeContext });
141
- return {
142
- name: agent.name,
143
- instructions,
144
- tools: serializedAgentTools,
145
- workflows: serializedAgentWorkflows,
146
- provider: llm?.getProvider(),
147
- modelId: llm?.getModelId(),
148
- defaultGenerateOptions,
149
- defaultStreamOptions
150
- };
151
- } catch (error) {
152
- return handleError(error, "Error getting agent");
153
- }
154
- }
155
- async function getEvalsByAgentIdHandler({
156
- mastra,
157
- runtimeContext,
158
- agentId
159
- }) {
160
- try {
161
- const agent = mastra.getAgent(agentId);
162
- const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
163
- const instructions = await agent.getInstructions({ runtimeContext });
164
- return {
165
- id: agentId,
166
- name: agent.name,
167
- instructions,
168
- evals
169
- };
170
- } catch (error) {
171
- return handleError(error, "Error getting test evals");
172
- }
173
- }
174
- async function getLiveEvalsByAgentIdHandler({
175
- mastra,
176
- runtimeContext,
177
- agentId
178
- }) {
179
- try {
180
- const agent = mastra.getAgent(agentId);
181
- const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
182
- const instructions = await agent.getInstructions({ runtimeContext });
183
- return {
184
- id: agentId,
185
- name: agent.name,
186
- instructions,
187
- evals
188
- };
189
- } catch (error) {
190
- return handleError(error, "Error getting live evals");
191
- }
192
- }
193
- async function generateHandler({
194
- mastra,
195
- runtimeContext,
196
- agentId,
197
- body,
198
- abortSignal
199
- }) {
200
- try {
201
- const agent = mastra.getAgent(agentId);
202
- if (!agent) {
203
- throw new HTTPException(404, { message: "Agent not found" });
204
- }
205
- const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
206
- const finalResourceId = resourceId ?? resourceid;
207
- const finalRuntimeContext = new RuntimeContext([
208
- ...Array.from(runtimeContext.entries()),
209
- ...Array.from(Object.entries(agentRuntimeContext ?? {}))
210
- ]);
211
- validateBody({ messages });
212
- const result = await agent.generate(messages, {
213
- ...rest,
214
- // @ts-expect-error TODO fix types
215
- resourceId: finalResourceId,
216
- runtimeContext: finalRuntimeContext,
217
- signal: abortSignal
218
- });
219
- return result;
220
- } catch (error) {
221
- return handleError(error, "Error generating from agent");
222
- }
223
- }
224
- async function streamGenerateHandler({
225
- mastra,
226
- runtimeContext,
227
- agentId,
228
- body,
229
- abortSignal
230
- }) {
231
- try {
232
- const agent = mastra.getAgent(agentId);
233
- if (!agent) {
234
- throw new HTTPException(404, { message: "Agent not found" });
235
- }
236
- const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
237
- const finalResourceId = resourceId ?? resourceid;
238
- const finalRuntimeContext = new RuntimeContext([
239
- ...Array.from(runtimeContext.entries()),
240
- ...Array.from(Object.entries(agentRuntimeContext ?? {}))
241
- ]);
242
- validateBody({ messages });
243
- const streamResult = await agent.stream(messages, {
244
- ...rest,
245
- // @ts-expect-error TODO fix types
246
- resourceId: finalResourceId,
247
- runtimeContext: finalRuntimeContext,
248
- signal: abortSignal
249
- });
250
- const streamResponse = rest.output ? streamResult.toTextStreamResponse({
251
- headers: {
252
- "Transfer-Encoding": "chunked"
253
- }
254
- }) : streamResult.toDataStreamResponse({
255
- sendUsage: true,
256
- sendReasoning: true,
257
- getErrorMessage: (error) => {
258
- return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
259
- },
260
- headers: {
261
- "Transfer-Encoding": "chunked"
262
- }
263
- });
264
- return streamResponse;
265
- } catch (error) {
266
- return handleError(error, "error streaming agent response");
267
- }
268
- }
269
-
270
- export { agents_exports, generateHandler, getAgentByIdHandler, getAgentsHandler, getEvalsByAgentIdHandler, getLiveEvalsByAgentIdHandler, streamGenerateHandler };
@@ -1,18 +0,0 @@
1
- 'use strict';
2
-
3
- var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
4
-
5
- // src/server/handlers/utils.ts
6
- function validateBody(body) {
7
- const errorResponse = Object.entries(body).reduce((acc, [key, value]) => {
8
- if (!value) {
9
- acc[key] = `Argument "${key}" is required`;
10
- }
11
- return acc;
12
- }, {});
13
- if (Object.keys(errorResponse).length > 0) {
14
- throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: Object.values(errorResponse)[0] });
15
- }
16
- }
17
-
18
- exports.validateBody = validateBody;
@@ -1,142 +0,0 @@
1
- import { validateBody } from './chunk-RSEO4XPX.js';
2
- import { handleError } from './chunk-LF7P5PLR.js';
3
- import { HTTPException } from './chunk-LCM566I4.js';
4
- import { __export } from './chunk-MLKGABMK.js';
5
-
6
- // src/server/handlers/network.ts
7
- var network_exports = {};
8
- __export(network_exports, {
9
- generateHandler: () => generateHandler,
10
- getNetworkByIdHandler: () => getNetworkByIdHandler,
11
- getNetworksHandler: () => getNetworksHandler,
12
- streamGenerateHandler: () => streamGenerateHandler
13
- });
14
- async function getNetworksHandler({
15
- mastra,
16
- runtimeContext
17
- }) {
18
- try {
19
- const networks = mastra.getNetworks();
20
- const serializedNetworks = await Promise.all(
21
- networks.map(async (network) => {
22
- const routingAgent = network.getRoutingAgent();
23
- const routingLLM = await routingAgent.getLLM({ runtimeContext });
24
- const agents = network.getAgents();
25
- return {
26
- id: network.formatAgentId(routingAgent.name),
27
- name: routingAgent.name,
28
- instructions: routingAgent.instructions,
29
- agents: await Promise.all(
30
- agents.map(async (agent) => {
31
- const llm = await agent.getLLM({ runtimeContext });
32
- return {
33
- name: agent.name,
34
- provider: llm?.getProvider(),
35
- modelId: llm?.getModelId()
36
- };
37
- })
38
- ),
39
- routingModel: {
40
- provider: routingLLM?.getProvider(),
41
- modelId: routingLLM?.getModelId()
42
- }
43
- };
44
- })
45
- );
46
- return serializedNetworks;
47
- } catch (error) {
48
- return handleError(error, "Error getting networks");
49
- }
50
- }
51
- async function getNetworkByIdHandler({
52
- mastra,
53
- networkId,
54
- runtimeContext
55
- }) {
56
- try {
57
- const networks = mastra.getNetworks();
58
- const network = networks.find((network2) => {
59
- const routingAgent2 = network2.getRoutingAgent();
60
- return network2.formatAgentId(routingAgent2.name) === networkId;
61
- });
62
- if (!network) {
63
- throw new HTTPException(404, { message: "Network not found" });
64
- }
65
- const routingAgent = network.getRoutingAgent();
66
- const routingLLM = await routingAgent.getLLM({ runtimeContext });
67
- const agents = network.getAgents();
68
- const serializedNetwork = {
69
- id: network.formatAgentId(routingAgent.name),
70
- name: routingAgent.name,
71
- instructions: routingAgent.instructions,
72
- agents: await Promise.all(
73
- agents.map(async (agent) => {
74
- const llm = await agent.getLLM({ runtimeContext });
75
- return {
76
- name: agent.name,
77
- provider: llm?.getProvider(),
78
- modelId: llm?.getModelId()
79
- };
80
- })
81
- ),
82
- routingModel: {
83
- provider: routingLLM?.getProvider(),
84
- modelId: routingLLM?.getModelId()
85
- }
86
- };
87
- return serializedNetwork;
88
- } catch (error) {
89
- return handleError(error, "Error getting network by ID");
90
- }
91
- }
92
- async function generateHandler({
93
- mastra,
94
- runtimeContext,
95
- networkId,
96
- body
97
- }) {
98
- try {
99
- const network = mastra.getNetwork(networkId);
100
- if (!network) {
101
- throw new HTTPException(404, { message: "Network not found" });
102
- }
103
- validateBody({ messages: body.messages });
104
- const { messages, ...rest } = body;
105
- const result = await network.generate(messages, { ...rest, runtimeContext });
106
- return result;
107
- } catch (error) {
108
- return handleError(error, "Error generating from network");
109
- }
110
- }
111
- async function streamGenerateHandler({
112
- mastra,
113
- networkId,
114
- body,
115
- runtimeContext
116
- }) {
117
- try {
118
- const network = mastra.getNetwork(networkId);
119
- if (!network) {
120
- throw new HTTPException(404, { message: "Network not found" });
121
- }
122
- validateBody({ messages: body.messages });
123
- const { messages, output, ...rest } = body;
124
- const streamResult = await network.stream(messages, {
125
- output,
126
- ...rest,
127
- runtimeContext
128
- });
129
- const streamResponse = output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
130
- sendUsage: true,
131
- sendReasoning: true,
132
- getErrorMessage: (error) => {
133
- return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
134
- }
135
- });
136
- return streamResponse;
137
- } catch (error) {
138
- return handleError(error, "Error streaming from network");
139
- }
140
- }
141
-
142
- export { generateHandler, getNetworkByIdHandler, getNetworksHandler, network_exports, streamGenerateHandler };
@@ -1,128 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkLI436ITD_cjs = require('./chunk-LI436ITD.cjs');
4
- var chunkCCGRCYWJ_cjs = require('./chunk-CCGRCYWJ.cjs');
5
- var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
6
- var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
7
- var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
8
- var tools = require('@mastra/core/tools');
9
-
10
- // src/server/handlers/tools.ts
11
- var tools_exports = {};
12
- chunk75ZPJI57_cjs.__export(tools_exports, {
13
- executeAgentToolHandler: () => executeAgentToolHandler,
14
- executeToolHandler: () => executeToolHandler,
15
- getToolByIdHandler: () => getToolByIdHandler,
16
- getToolsHandler: () => getToolsHandler
17
- });
18
- async function getToolsHandler({ tools }) {
19
- try {
20
- if (!tools) {
21
- return {};
22
- }
23
- const serializedTools = Object.entries(tools).reduce(
24
- (acc, [id, _tool]) => {
25
- const tool = _tool;
26
- acc[id] = {
27
- ...tool,
28
- inputSchema: tool.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(tool.inputSchema)) : void 0,
29
- outputSchema: tool.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(tool.outputSchema)) : void 0
30
- };
31
- return acc;
32
- },
33
- {}
34
- );
35
- return serializedTools;
36
- } catch (error) {
37
- return chunkPZQDCRPV_cjs.handleError(error, "Error getting tools");
38
- }
39
- }
40
- async function getToolByIdHandler({ tools, toolId }) {
41
- try {
42
- const tool = Object.values(tools || {}).find((tool2) => tool2.id === toolId);
43
- if (!tool) {
44
- throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Tool not found" });
45
- }
46
- const serializedTool = {
47
- ...tool,
48
- inputSchema: tool.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(tool.inputSchema)) : void 0,
49
- outputSchema: tool.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(tool.outputSchema)) : void 0
50
- };
51
- return serializedTool;
52
- } catch (error) {
53
- return chunkPZQDCRPV_cjs.handleError(error, "Error getting tool");
54
- }
55
- }
56
- function executeToolHandler(tools$1) {
57
- return async ({
58
- mastra,
59
- runId,
60
- toolId,
61
- data,
62
- runtimeContext
63
- }) => {
64
- try {
65
- if (!toolId) {
66
- throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Tool ID is required" });
67
- }
68
- const tool = Object.values(tools$1 || {}).find((tool2) => tool2.id === toolId);
69
- if (!tool) {
70
- throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Tool not found" });
71
- }
72
- if (!tool?.execute) {
73
- throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Tool is not executable" });
74
- }
75
- chunkCCGRCYWJ_cjs.validateBody({ data });
76
- if (tools.isVercelTool(tool)) {
77
- const result2 = await tool.execute(data);
78
- return result2;
79
- }
80
- const result = await tool.execute({
81
- context: data,
82
- mastra,
83
- runId,
84
- runtimeContext
85
- });
86
- return result;
87
- } catch (error) {
88
- return chunkPZQDCRPV_cjs.handleError(error, "Error executing tool");
89
- }
90
- };
91
- }
92
- async function executeAgentToolHandler({
93
- mastra,
94
- agentId,
95
- toolId,
96
- data,
97
- runtimeContext
98
- }) {
99
- try {
100
- const agent = agentId ? mastra.getAgent(agentId) : null;
101
- if (!agent) {
102
- throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Tool not found" });
103
- }
104
- const agentTools = await agent.getTools({ runtimeContext });
105
- const tool = Object.values(agentTools || {}).find((tool2) => tool2.id === toolId);
106
- if (!tool) {
107
- throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Tool not found" });
108
- }
109
- if (!tool?.execute) {
110
- throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Tool is not executable" });
111
- }
112
- const result = await tool.execute({
113
- context: data,
114
- runtimeContext,
115
- mastra,
116
- runId: agentId
117
- });
118
- return result;
119
- } catch (error) {
120
- return chunkPZQDCRPV_cjs.handleError(error, "Error executing tool");
121
- }
122
- }
123
-
124
- exports.executeAgentToolHandler = executeAgentToolHandler;
125
- exports.executeToolHandler = executeToolHandler;
126
- exports.getToolByIdHandler = getToolByIdHandler;
127
- exports.getToolsHandler = getToolsHandler;
128
- exports.tools_exports = tools_exports;