@mastra/server 0.0.0-remove-cloud-span-transform-20250425214156 → 0.0.0-remove-unused-model-providers-api-20251030210744

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 (268) hide show
  1. package/CHANGELOG.md +4230 -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-5JNVY6DU.js → chunk-2XD2KQEK.js} +57 -17
  9. package/dist/chunk-2XD2KQEK.js.map +1 -0
  10. package/dist/chunk-36CWLQQT.js +192 -0
  11. package/dist/chunk-36CWLQQT.js.map +1 -0
  12. package/dist/chunk-4BKR6543.cjs +19504 -0
  13. package/dist/chunk-4BKR6543.cjs.map +1 -0
  14. package/dist/{chunk-L7XE5QTW.js → chunk-4QCXUEAT.js} +11 -2
  15. package/dist/chunk-4QCXUEAT.js.map +1 -0
  16. package/dist/chunk-4YFT3JFJ.js +19463 -0
  17. package/dist/chunk-4YFT3JFJ.js.map +1 -0
  18. package/dist/chunk-6562SOHJ.js +130 -0
  19. package/dist/chunk-6562SOHJ.js.map +1 -0
  20. package/dist/chunk-6IGZKIRM.cjs +200 -0
  21. package/dist/chunk-6IGZKIRM.cjs.map +1 -0
  22. package/dist/{chunk-Q6SHQECN.js → chunk-74ZF4DII.js} +47 -13
  23. package/dist/chunk-74ZF4DII.js.map +1 -0
  24. package/dist/chunk-7KNKINQE.js +83 -0
  25. package/dist/chunk-7KNKINQE.js.map +1 -0
  26. package/dist/chunk-7MCHFMDF.js +665 -0
  27. package/dist/chunk-7MCHFMDF.js.map +1 -0
  28. package/dist/{chunk-FV45V6WC.cjs → chunk-7NADHFD2.cjs} +3 -7
  29. package/dist/chunk-7NADHFD2.cjs.map +1 -0
  30. package/dist/chunk-7YHMDEQ6.cjs +128 -0
  31. package/dist/chunk-7YHMDEQ6.cjs.map +1 -0
  32. package/dist/chunk-BATEJLED.js +124 -0
  33. package/dist/chunk-BATEJLED.js.map +1 -0
  34. package/dist/chunk-BMOVKZO7.cjs +167 -0
  35. package/dist/chunk-BMOVKZO7.cjs.map +1 -0
  36. package/dist/chunk-CXVOX4WB.js +508 -0
  37. package/dist/chunk-CXVOX4WB.js.map +1 -0
  38. package/dist/chunk-CY4TP3FK.js +16 -0
  39. package/dist/chunk-CY4TP3FK.js.map +1 -0
  40. package/dist/{chunk-M56ECCHK.cjs → chunk-EP3JQDPD.cjs} +22 -19
  41. package/dist/chunk-EP3JQDPD.cjs.map +1 -0
  42. package/dist/chunk-G4PUALCE.cjs +28 -0
  43. package/dist/chunk-G4PUALCE.cjs.map +1 -0
  44. package/dist/chunk-GQRJOUV7.js +797 -0
  45. package/dist/chunk-GQRJOUV7.js.map +1 -0
  46. package/dist/chunk-HLIRV42R.cjs +685 -0
  47. package/dist/chunk-HLIRV42R.cjs.map +1 -0
  48. package/dist/chunk-LPM6BBAX.cjs +1043 -0
  49. package/dist/chunk-LPM6BBAX.cjs.map +1 -0
  50. package/dist/chunk-LROVQBIB.cjs +524 -0
  51. package/dist/chunk-LROVQBIB.cjs.map +1 -0
  52. package/dist/chunk-LZKJT7QP.cjs +799 -0
  53. package/dist/chunk-LZKJT7QP.cjs.map +1 -0
  54. package/dist/{chunk-TRDNDNGQ.js → chunk-MMROOK5J.js} +4 -7
  55. package/dist/chunk-MMROOK5J.js.map +1 -0
  56. package/dist/{chunk-4JINXASC.js → chunk-MYR4PVGN.js} +7 -4
  57. package/dist/chunk-MYR4PVGN.js.map +1 -0
  58. package/dist/chunk-O7I5CWRX.cjs +44 -0
  59. package/dist/chunk-O7I5CWRX.cjs.map +1 -0
  60. package/dist/chunk-OEW3R7V4.js +477 -0
  61. package/dist/chunk-OEW3R7V4.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-PUYDRTPG.cjs +720 -0
  65. package/dist/chunk-PUYDRTPG.cjs.map +1 -0
  66. package/dist/chunk-QU6N55W6.cjs +256 -0
  67. package/dist/chunk-QU6N55W6.cjs.map +1 -0
  68. package/dist/chunk-RE4RPXT2.cjs +18 -0
  69. package/dist/chunk-RE4RPXT2.cjs.map +1 -0
  70. package/dist/chunk-RQK4FQUD.js +1012 -0
  71. package/dist/chunk-RQK4FQUD.js.map +1 -0
  72. package/dist/chunk-S4IOWSI3.js +698 -0
  73. package/dist/chunk-S4IOWSI3.js.map +1 -0
  74. package/dist/chunk-SED4H2GJ.cjs +485 -0
  75. package/dist/chunk-SED4H2GJ.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-TOCYBDP2.js +46 -0
  79. package/dist/chunk-TOCYBDP2.js.map +1 -0
  80. package/dist/chunk-WH5RPLO4.cjs +88 -0
  81. package/dist/chunk-WH5RPLO4.cjs.map +1 -0
  82. package/dist/chunk-X6C7BUWN.cjs +48 -0
  83. package/dist/chunk-X6C7BUWN.cjs.map +1 -0
  84. package/dist/chunk-YNGDJJOH.cjs +134 -0
  85. package/dist/chunk-YNGDJJOH.cjs.map +1 -0
  86. package/dist/chunk-ZULZ2752.js +2774 -0
  87. package/dist/chunk-ZULZ2752.js.map +1 -0
  88. package/dist/dist-4MVGNSRL.cjs +1150 -0
  89. package/dist/dist-4MVGNSRL.cjs.map +1 -0
  90. package/dist/dist-FZYCV3VB.cjs +940 -0
  91. package/dist/dist-FZYCV3VB.cjs.map +1 -0
  92. package/dist/dist-G2BYZJOC.cjs +928 -0
  93. package/dist/dist-G2BYZJOC.cjs.map +1 -0
  94. package/dist/dist-P4MXBQ3U.cjs +16 -0
  95. package/dist/dist-P4MXBQ3U.cjs.map +1 -0
  96. package/dist/dist-PQZUVLPC.js +937 -0
  97. package/dist/dist-PQZUVLPC.js.map +1 -0
  98. package/dist/dist-R7WYX6LC.js +925 -0
  99. package/dist/dist-R7WYX6LC.js.map +1 -0
  100. package/dist/dist-RFMYFILX.cjs +764 -0
  101. package/dist/dist-RFMYFILX.cjs.map +1 -0
  102. package/dist/dist-X7XR3M3Z.js +1147 -0
  103. package/dist/dist-X7XR3M3Z.js.map +1 -0
  104. package/dist/dist-XVBSOGFK.js +761 -0
  105. package/dist/dist-XVBSOGFK.js.map +1 -0
  106. package/dist/dist-YREX2TJT.js +3 -0
  107. package/dist/dist-YREX2TJT.js.map +1 -0
  108. package/dist/index.cjs +6 -0
  109. package/dist/index.cjs.map +1 -0
  110. package/dist/index.d.ts +1 -0
  111. package/dist/index.d.ts.map +1 -0
  112. package/dist/index.js +5 -0
  113. package/dist/index.js.map +1 -0
  114. package/dist/server/a2a/protocol.d.ts +8 -0
  115. package/dist/server/a2a/protocol.d.ts.map +1 -0
  116. package/dist/server/a2a/store.cjs +25 -0
  117. package/dist/server/a2a/store.cjs.map +1 -0
  118. package/dist/server/a2a/store.d.ts +14 -0
  119. package/dist/server/a2a/store.d.ts.map +1 -0
  120. package/dist/server/a2a/store.js +23 -0
  121. package/dist/server/a2a/store.js.map +1 -0
  122. package/dist/server/a2a/tasks.d.ts +20 -0
  123. package/dist/server/a2a/tasks.d.ts.map +1 -0
  124. package/dist/server/handlers/a2a.cjs +32 -0
  125. package/dist/server/handlers/a2a.cjs.map +1 -0
  126. package/dist/server/handlers/a2a.d.ts +68 -0
  127. package/dist/server/handlers/a2a.d.ts.map +1 -0
  128. package/dist/server/handlers/a2a.js +3 -0
  129. package/dist/server/handlers/a2a.js.map +1 -0
  130. package/dist/server/handlers/agent-builder.cjs +88 -0
  131. package/dist/server/handlers/agent-builder.cjs.map +1 -0
  132. package/dist/server/handlers/agent-builder.d.ts +110 -0
  133. package/dist/server/handlers/agent-builder.d.ts.map +1 -0
  134. package/dist/server/handlers/agent-builder.js +3 -0
  135. package/dist/server/handlers/agent-builder.js.map +1 -0
  136. package/dist/server/handlers/agents.cjs +60 -10
  137. package/dist/server/handlers/agents.cjs.map +1 -0
  138. package/dist/server/handlers/agents.d.ts +195 -6
  139. package/dist/server/handlers/agents.d.ts.map +1 -0
  140. package/dist/server/handlers/agents.js +3 -1
  141. package/dist/server/handlers/agents.js.map +1 -0
  142. package/dist/server/handlers/error.cjs +4 -2
  143. package/dist/server/handlers/error.cjs.map +1 -0
  144. package/dist/server/handlers/error.d.ts +2 -1
  145. package/dist/server/handlers/error.d.ts.map +1 -0
  146. package/dist/server/handlers/error.js +3 -1
  147. package/dist/server/handlers/error.js.map +1 -0
  148. package/dist/server/handlers/logs.cjs +9 -7
  149. package/dist/server/handlers/logs.cjs.map +1 -0
  150. package/dist/server/handlers/logs.d.ts +34 -3
  151. package/dist/server/handlers/logs.d.ts.map +1 -0
  152. package/dist/server/handlers/logs.js +3 -1
  153. package/dist/server/handlers/logs.js.map +1 -0
  154. package/dist/server/handlers/memory.cjs +36 -10
  155. package/dist/server/handlers/memory.cjs.map +1 -0
  156. package/dist/server/handlers/memory.d.ts +115 -8
  157. package/dist/server/handlers/memory.d.ts.map +1 -0
  158. package/dist/server/handlers/memory.js +3 -1
  159. package/dist/server/handlers/memory.js.map +1 -0
  160. package/dist/server/handlers/observability.cjs +24 -0
  161. package/dist/server/handlers/observability.cjs.map +1 -0
  162. package/dist/server/handlers/observability.d.ts +49 -0
  163. package/dist/server/handlers/observability.d.ts.map +1 -0
  164. package/dist/server/handlers/observability.js +3 -0
  165. package/dist/server/handlers/observability.js.map +1 -0
  166. package/dist/server/handlers/scores.cjs +32 -0
  167. package/dist/server/handlers/scores.cjs.map +1 -0
  168. package/dist/server/handlers/scores.d.ts +152 -0
  169. package/dist/server/handlers/scores.d.ts.map +1 -0
  170. package/dist/server/handlers/scores.js +3 -0
  171. package/dist/server/handlers/scores.js.map +1 -0
  172. package/dist/server/handlers/tools.cjs +12 -6
  173. package/dist/server/handlers/tools.cjs.map +1 -0
  174. package/dist/server/handlers/tools.d.ts +25 -4
  175. package/dist/server/handlers/tools.d.ts.map +1 -0
  176. package/dist/server/handlers/tools.js +3 -1
  177. package/dist/server/handlers/tools.js.map +1 -0
  178. package/dist/server/handlers/utils.cjs +8 -2
  179. package/dist/server/handlers/utils.cjs.map +1 -0
  180. package/dist/server/handlers/utils.d.ts +8 -1
  181. package/dist/server/handlers/utils.d.ts.map +1 -0
  182. package/dist/server/handlers/utils.js +3 -1
  183. package/dist/server/handlers/utils.js.map +1 -0
  184. package/dist/server/handlers/vector.cjs +9 -7
  185. package/dist/server/handlers/vector.cjs.map +1 -0
  186. package/dist/server/handlers/vector.d.ts +51 -6
  187. package/dist/server/handlers/vector.d.ts.map +1 -0
  188. package/dist/server/handlers/vector.js +3 -1
  189. package/dist/server/handlers/vector.js.map +1 -0
  190. package/dist/server/handlers/voice.cjs +10 -4
  191. package/dist/server/handlers/voice.cjs.map +1 -0
  192. package/dist/server/handlers/voice.d.ts +41 -3
  193. package/dist/server/handlers/voice.d.ts.map +1 -0
  194. package/dist/server/handlers/voice.js +3 -1
  195. package/dist/server/handlers/voice.js.map +1 -0
  196. package/dist/server/handlers/workflows.cjs +57 -15
  197. package/dist/server/handlers/workflows.cjs.map +1 -0
  198. package/dist/server/handlers/workflows.d.ts +97 -10
  199. package/dist/server/handlers/workflows.d.ts.map +1 -0
  200. package/dist/server/handlers/workflows.js +3 -1
  201. package/dist/server/handlers/workflows.js.map +1 -0
  202. package/dist/server/handlers.cjs +37 -30
  203. package/dist/server/handlers.cjs.map +1 -0
  204. package/dist/server/handlers.d.ts +12 -10
  205. package/dist/server/handlers.d.ts.map +1 -0
  206. package/dist/server/handlers.js +13 -10
  207. package/dist/server/handlers.js.map +1 -0
  208. package/dist/server/http-exception.d.ts +87 -0
  209. package/dist/server/http-exception.d.ts.map +1 -0
  210. package/dist/server/types.d.ts +10 -0
  211. package/dist/server/types.d.ts.map +1 -0
  212. package/dist/server/utils.d.ts +44 -0
  213. package/dist/server/utils.d.ts.map +1 -0
  214. package/dist/token-375W3LEI.cjs +64 -0
  215. package/dist/token-375W3LEI.cjs.map +1 -0
  216. package/dist/token-C3IMNCC4.js +62 -0
  217. package/dist/token-C3IMNCC4.js.map +1 -0
  218. package/dist/token-util-CV3RRG6K.cjs +9 -0
  219. package/dist/token-util-CV3RRG6K.cjs.map +1 -0
  220. package/dist/token-util-E5QO2RCL.js +7 -0
  221. package/dist/token-util-E5QO2RCL.js.map +1 -0
  222. package/package.json +43 -19
  223. package/dist/_tsup-dts-rollup.d.cts +0 -648
  224. package/dist/_tsup-dts-rollup.d.ts +0 -648
  225. package/dist/chunk-2FJURXCL.cjs +0 -213
  226. package/dist/chunk-3AHQ5RGN.js +0 -11
  227. package/dist/chunk-3EJZQ6TQ.js +0 -49
  228. package/dist/chunk-55HTWX4C.cjs +0 -93
  229. package/dist/chunk-5SWCVTNL.cjs +0 -5579
  230. package/dist/chunk-7IWQE76Z.cjs +0 -139
  231. package/dist/chunk-B66WVPGJ.js +0 -297
  232. package/dist/chunk-D3G23FP3.cjs +0 -126
  233. package/dist/chunk-FPIWDH5Y.cjs +0 -126
  234. package/dist/chunk-HCOPJZ4A.cjs +0 -164
  235. package/dist/chunk-LFOBHRFO.js +0 -305
  236. package/dist/chunk-OMN3UI6X.js +0 -5576
  237. package/dist/chunk-QN4KF3BH.cjs +0 -18
  238. package/dist/chunk-R4J7XQYU.js +0 -156
  239. package/dist/chunk-RBQASTUP.js +0 -203
  240. package/dist/chunk-RE6YL32K.js +0 -120
  241. package/dist/chunk-SKBVVI24.cjs +0 -54
  242. package/dist/chunk-TZK63M5N.cjs +0 -317
  243. package/dist/chunk-WTHDCRMY.js +0 -135
  244. package/dist/chunk-ZHNKYTNS.cjs +0 -309
  245. package/dist/chunk-ZLBRQFDD.cjs +0 -13
  246. package/dist/index.d.cts +0 -1
  247. package/dist/server/handlers/agents.d.cts +0 -6
  248. package/dist/server/handlers/error.d.cts +0 -1
  249. package/dist/server/handlers/logs.d.cts +0 -3
  250. package/dist/server/handlers/memory.d.cts +0 -8
  251. package/dist/server/handlers/network.cjs +0 -22
  252. package/dist/server/handlers/network.d.cts +0 -4
  253. package/dist/server/handlers/network.d.ts +0 -4
  254. package/dist/server/handlers/network.js +0 -1
  255. package/dist/server/handlers/telemetry.cjs +0 -14
  256. package/dist/server/handlers/telemetry.d.cts +0 -2
  257. package/dist/server/handlers/telemetry.d.ts +0 -2
  258. package/dist/server/handlers/telemetry.js +0 -1
  259. package/dist/server/handlers/tools.d.cts +0 -4
  260. package/dist/server/handlers/utils.d.cts +0 -1
  261. package/dist/server/handlers/vNextWorkflows.cjs +0 -46
  262. package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
  263. package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
  264. package/dist/server/handlers/vNextWorkflows.js +0 -1
  265. package/dist/server/handlers/vector.d.cts +0 -6
  266. package/dist/server/handlers/voice.d.cts +0 -3
  267. package/dist/server/handlers/workflows.d.cts +0 -10
  268. package/dist/server/handlers.d.cts +0 -10
@@ -1,164 +0,0 @@
1
- 'use strict';
2
-
3
- var chunk5SWCVTNL_cjs = require('./chunk-5SWCVTNL.cjs');
4
- var chunkQN4KF3BH_cjs = require('./chunk-QN4KF3BH.cjs');
5
- var chunkZLBRQFDD_cjs = require('./chunk-ZLBRQFDD.cjs');
6
- var chunkFV45V6WC_cjs = require('./chunk-FV45V6WC.cjs');
7
-
8
- // src/server/handlers/agents.ts
9
- var agents_exports = {};
10
- chunkFV45V6WC_cjs.__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 }) {
19
- try {
20
- const agents = mastra.getAgents();
21
- const serializedAgents = Object.entries(agents).reduce((acc, [_id, _agent]) => {
22
- const agent = _agent;
23
- const serializedAgentTools = Object.entries(agent?.tools || {}).reduce((acc2, [key, tool]) => {
24
- const _tool = tool;
25
- acc2[key] = {
26
- ..._tool,
27
- inputSchema: _tool.inputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_tool.inputSchema)) : void 0,
28
- outputSchema: _tool.outputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_tool.outputSchema)) : void 0
29
- };
30
- return acc2;
31
- }, {});
32
- acc[_id] = {
33
- name: agent.name,
34
- instructions: agent.instructions,
35
- tools: serializedAgentTools,
36
- provider: agent.llm?.getProvider(),
37
- modelId: agent.llm?.getModelId()
38
- };
39
- return acc;
40
- }, {});
41
- return serializedAgents;
42
- } catch (error) {
43
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting agents");
44
- }
45
- }
46
- async function getAgentByIdHandler({ mastra, agentId }) {
47
- try {
48
- const agent = mastra.getAgent(agentId);
49
- if (!agent) {
50
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Agent not found" });
51
- }
52
- const serializedAgentTools = Object.entries(agent?.tools || {}).reduce((acc, [key, tool]) => {
53
- const _tool = tool;
54
- acc[key] = {
55
- ..._tool,
56
- inputSchema: _tool.inputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_tool.inputSchema)) : void 0,
57
- outputSchema: _tool.outputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_tool.outputSchema)) : void 0
58
- };
59
- return acc;
60
- }, {});
61
- return {
62
- name: agent.name,
63
- instructions: agent.instructions,
64
- tools: serializedAgentTools,
65
- provider: agent.llm?.getProvider(),
66
- modelId: agent.llm?.getModelId()
67
- };
68
- } catch (error) {
69
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting agent");
70
- }
71
- }
72
- async function getEvalsByAgentIdHandler({ mastra, agentId }) {
73
- try {
74
- const agent = mastra.getAgent(agentId);
75
- const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
76
- return {
77
- id: agentId,
78
- name: agent.name,
79
- instructions: agent.instructions,
80
- evals
81
- };
82
- } catch (error) {
83
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting test evals");
84
- }
85
- }
86
- async function getLiveEvalsByAgentIdHandler({ mastra, agentId }) {
87
- try {
88
- const agent = mastra.getAgent(agentId);
89
- const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
90
- return {
91
- id: agentId,
92
- name: agent.name,
93
- instructions: agent.instructions,
94
- evals
95
- };
96
- } catch (error) {
97
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting live evals");
98
- }
99
- }
100
- async function generateHandler({
101
- mastra,
102
- runtimeContext,
103
- agentId,
104
- body
105
- }) {
106
- try {
107
- const agent = mastra.getAgent(agentId);
108
- if (!agent) {
109
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Agent not found" });
110
- }
111
- const { messages, resourceId, resourceid, ...rest } = body;
112
- const finalResourceId = resourceId ?? resourceid;
113
- chunkQN4KF3BH_cjs.validateBody({ messages });
114
- const result = await agent.generate(messages, {
115
- ...rest,
116
- // @ts-expect-error TODO fix types
117
- resourceId: finalResourceId,
118
- runtimeContext
119
- });
120
- return result;
121
- } catch (error) {
122
- return chunkZLBRQFDD_cjs.handleError(error, "Error generating from agent");
123
- }
124
- }
125
- async function streamGenerateHandler({
126
- mastra,
127
- runtimeContext,
128
- agentId,
129
- body
130
- }) {
131
- try {
132
- const agent = mastra.getAgent(agentId);
133
- if (!agent) {
134
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Agent not found" });
135
- }
136
- const { messages, resourceId, resourceid, ...rest } = body;
137
- const finalResourceId = resourceId ?? resourceid;
138
- chunkQN4KF3BH_cjs.validateBody({ messages });
139
- const streamResult = await agent.stream(messages, {
140
- ...rest,
141
- // @ts-expect-error TODO fix types
142
- resourceId: finalResourceId,
143
- runtimeContext
144
- });
145
- const streamResponse = rest.output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
146
- sendUsage: true,
147
- sendReasoning: true,
148
- getErrorMessage: (error) => {
149
- return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
150
- }
151
- });
152
- return streamResponse;
153
- } catch (error) {
154
- throw new chunkFV45V6WC_cjs.HTTPException(error?.status ?? 500, { message: error?.message ?? "Error streaming from agent" });
155
- }
156
- }
157
-
158
- exports.agents_exports = agents_exports;
159
- exports.generateHandler = generateHandler;
160
- exports.getAgentByIdHandler = getAgentByIdHandler;
161
- exports.getAgentsHandler = getAgentsHandler;
162
- exports.getEvalsByAgentIdHandler = getEvalsByAgentIdHandler;
163
- exports.getLiveEvalsByAgentIdHandler = getLiveEvalsByAgentIdHandler;
164
- exports.streamGenerateHandler = streamGenerateHandler;
@@ -1,305 +0,0 @@
1
- import { stringify, esm_default } from './chunk-OMN3UI6X.js';
2
- import { handleError } from './chunk-3AHQ5RGN.js';
3
- import { __export, HTTPException } from './chunk-TRDNDNGQ.js';
4
- import { ReadableStream } from 'node:stream/web';
5
-
6
- // src/server/handlers/workflows.ts
7
- var workflows_exports = {};
8
- __export(workflows_exports, {
9
- createRunHandler: () => createRunHandler,
10
- getWorkflowByIdHandler: () => getWorkflowByIdHandler,
11
- getWorkflowRunHandler: () => getWorkflowRunHandler,
12
- getWorkflowRunsHandler: () => getWorkflowRunsHandler,
13
- getWorkflowsHandler: () => getWorkflowsHandler,
14
- resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
15
- resumeWorkflowHandler: () => resumeWorkflowHandler,
16
- startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
17
- startWorkflowRunHandler: () => startWorkflowRunHandler,
18
- watchWorkflowHandler: () => watchWorkflowHandler
19
- });
20
- async function getWorkflowsHandler({ mastra }) {
21
- try {
22
- const workflows = mastra.getWorkflows({ serialized: false });
23
- const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
24
- if (workflow.isNested) return acc;
25
- acc[key] = {
26
- stepGraph: workflow.stepGraph,
27
- stepSubscriberGraph: workflow.stepSubscriberGraph,
28
- serializedStepGraph: workflow.serializedStepGraph,
29
- serializedStepSubscriberGraph: workflow.serializedStepSubscriberGraph,
30
- name: workflow.name,
31
- triggerSchema: workflow.triggerSchema ? stringify(esm_default(workflow.triggerSchema)) : void 0,
32
- steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
33
- const _step = step;
34
- acc2[key2] = {
35
- ..._step,
36
- inputSchema: _step.inputSchema ? stringify(esm_default(_step.inputSchema)) : void 0,
37
- outputSchema: _step.outputSchema ? stringify(esm_default(_step.outputSchema)) : void 0
38
- };
39
- return acc2;
40
- }, {})
41
- };
42
- return acc;
43
- }, {});
44
- return _workflows;
45
- } catch (error) {
46
- throw new HTTPException(500, { message: error?.message || "Error getting workflows" });
47
- }
48
- }
49
- async function getWorkflowByIdHandler({ mastra, workflowId }) {
50
- try {
51
- if (!workflowId) {
52
- throw new HTTPException(400, { message: "Workflow ID is required" });
53
- }
54
- const workflow = mastra.getWorkflow(workflowId);
55
- if (!workflow) {
56
- throw new HTTPException(404, { message: "Workflow not found" });
57
- }
58
- return {
59
- stepGraph: workflow.stepGraph,
60
- stepSubscriberGraph: workflow.stepSubscriberGraph,
61
- serializedStepGraph: workflow.serializedStepGraph,
62
- serializedStepSubscriberGraph: workflow.serializedStepSubscriberGraph,
63
- name: workflow.name,
64
- triggerSchema: workflow.triggerSchema ? stringify(esm_default(workflow.triggerSchema)) : void 0,
65
- steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
66
- const _step = step;
67
- acc[key] = {
68
- ..._step,
69
- inputSchema: _step.inputSchema ? stringify(esm_default(_step.inputSchema)) : void 0,
70
- outputSchema: _step.outputSchema ? stringify(esm_default(_step.outputSchema)) : void 0
71
- };
72
- return acc;
73
- }, {})
74
- };
75
- } catch (error) {
76
- throw new HTTPException(500, { message: error?.message || "Error getting workflow" });
77
- }
78
- }
79
- async function startAsyncWorkflowHandler({
80
- mastra,
81
- runtimeContext,
82
- workflowId,
83
- runId,
84
- triggerData
85
- }) {
86
- try {
87
- if (!workflowId) {
88
- throw new HTTPException(400, { message: "Workflow ID is required" });
89
- }
90
- const workflow = mastra.getWorkflow(workflowId);
91
- if (!workflow) {
92
- throw new HTTPException(404, { message: "Workflow not found" });
93
- }
94
- if (!runId) {
95
- const { start } = workflow.createRun();
96
- const result2 = await start({
97
- triggerData,
98
- runtimeContext
99
- });
100
- return result2;
101
- }
102
- const run = workflow.getRun(runId);
103
- if (!run) {
104
- throw new HTTPException(404, { message: "Workflow run not found" });
105
- }
106
- const result = await run.start({
107
- triggerData,
108
- runtimeContext
109
- });
110
- return result;
111
- } catch (error) {
112
- throw new HTTPException(500, { message: error?.message || "Error executing workflow" });
113
- }
114
- }
115
- async function getWorkflowRunHandler({
116
- mastra,
117
- workflowId,
118
- runId
119
- }) {
120
- try {
121
- if (!workflowId) {
122
- throw new HTTPException(400, { message: "Workflow ID is required" });
123
- }
124
- if (!runId) {
125
- throw new HTTPException(400, { message: "Run ID is required" });
126
- }
127
- const workflow = mastra.getWorkflow(workflowId);
128
- if (!workflow) {
129
- throw new HTTPException(404, { message: "Workflow not found" });
130
- }
131
- const run = workflow.getRun(runId);
132
- if (!run) {
133
- throw new HTTPException(404, { message: "Workflow run not found" });
134
- }
135
- return run;
136
- } catch (error) {
137
- throw new HTTPException(500, { message: error?.message || "Error getting workflow run" });
138
- }
139
- }
140
- async function createRunHandler({
141
- mastra,
142
- workflowId,
143
- runId: prevRunId
144
- }) {
145
- try {
146
- if (!workflowId) {
147
- throw new HTTPException(400, { message: "Workflow ID is required" });
148
- }
149
- const workflow = mastra.getWorkflow(workflowId);
150
- if (!workflow) {
151
- throw new HTTPException(404, { message: "Workflow not found" });
152
- }
153
- const { runId } = workflow.createRun({ runId: prevRunId });
154
- return { runId };
155
- } catch (error) {
156
- throw new HTTPException(500, { message: error?.message || "Error creating workflow run" });
157
- }
158
- }
159
- async function startWorkflowRunHandler({
160
- mastra,
161
- runtimeContext,
162
- workflowId,
163
- runId,
164
- triggerData
165
- }) {
166
- try {
167
- if (!workflowId) {
168
- throw new HTTPException(400, { message: "Workflow ID is required" });
169
- }
170
- if (!runId) {
171
- throw new HTTPException(400, { message: "runId required to start run" });
172
- }
173
- const workflow = mastra.getWorkflow(workflowId);
174
- const run = workflow.getRun(runId);
175
- if (!run) {
176
- throw new HTTPException(404, { message: "Workflow run not found" });
177
- }
178
- await run.start({
179
- triggerData,
180
- runtimeContext
181
- });
182
- return { message: "Workflow run started" };
183
- } catch (e) {
184
- return handleError(e, "Error starting workflow run");
185
- }
186
- }
187
- async function watchWorkflowHandler({
188
- mastra,
189
- workflowId,
190
- runId
191
- }) {
192
- try {
193
- if (!workflowId) {
194
- throw new HTTPException(400, { message: "Workflow ID is required" });
195
- }
196
- if (!runId) {
197
- throw new HTTPException(400, { message: "runId required to watch workflow" });
198
- }
199
- const workflow = mastra.getWorkflow(workflowId);
200
- const run = workflow.getRun(runId);
201
- if (!run) {
202
- throw new HTTPException(404, { message: "Workflow run not found" });
203
- }
204
- let unwatch;
205
- let asyncRef = null;
206
- const stream = new ReadableStream({
207
- start(controller) {
208
- unwatch = run.watch(({ activePaths, runId: runId2, timestamp, results }) => {
209
- const activePathsObj = Object.fromEntries(activePaths);
210
- controller.enqueue(JSON.stringify({ activePaths: activePathsObj, runId: runId2, timestamp, results }));
211
- if (asyncRef) {
212
- clearImmediate(asyncRef);
213
- asyncRef = null;
214
- }
215
- asyncRef = setImmediate(() => {
216
- if (!workflow.getRun(runId2)) {
217
- controller.close();
218
- }
219
- });
220
- });
221
- },
222
- cancel() {
223
- unwatch?.();
224
- }
225
- });
226
- return stream;
227
- } catch (error) {
228
- return handleError(error, "Error watching workflow");
229
- }
230
- }
231
- async function resumeAsyncWorkflowHandler({
232
- mastra,
233
- workflowId,
234
- runId,
235
- body,
236
- runtimeContext
237
- }) {
238
- try {
239
- if (!workflowId) {
240
- throw new HTTPException(400, { message: "Workflow ID is required" });
241
- }
242
- if (!runId) {
243
- throw new HTTPException(400, { message: "runId required to resume workflow" });
244
- }
245
- const workflow = mastra.getWorkflow(workflowId);
246
- const run = workflow.getRun(runId);
247
- if (!run) {
248
- throw new HTTPException(404, { message: "Workflow run not found" });
249
- }
250
- const result = await run.resume({
251
- stepId: body.stepId,
252
- context: body.context,
253
- runtimeContext
254
- });
255
- return result;
256
- } catch (error) {
257
- return handleError(error, "Error resuming workflow step");
258
- }
259
- }
260
- async function resumeWorkflowHandler({
261
- mastra,
262
- workflowId,
263
- runId,
264
- body,
265
- runtimeContext
266
- }) {
267
- try {
268
- if (!workflowId) {
269
- throw new HTTPException(400, { message: "Workflow ID is required" });
270
- }
271
- if (!runId) {
272
- throw new HTTPException(400, { message: "runId required to resume workflow" });
273
- }
274
- const workflow = mastra.getWorkflow(workflowId);
275
- const run = workflow.getRun(runId);
276
- if (!run) {
277
- throw new HTTPException(404, { message: "Workflow run not found" });
278
- }
279
- await run.resume({
280
- stepId: body.stepId,
281
- context: body.context,
282
- runtimeContext
283
- });
284
- return { message: "Workflow run resumed" };
285
- } catch (error) {
286
- return handleError(error, "Error resuming workflow");
287
- }
288
- }
289
- async function getWorkflowRunsHandler({ mastra, workflowId }) {
290
- try {
291
- if (!workflowId) {
292
- throw new HTTPException(400, { message: "Workflow ID is required" });
293
- }
294
- const workflow = mastra.getWorkflow(workflowId);
295
- const workflowRuns = await workflow.getWorkflowRuns() || {
296
- runs: [],
297
- total: 0
298
- };
299
- return workflowRuns;
300
- } catch (error) {
301
- return handleError(error, "Error getting workflow runs");
302
- }
303
- }
304
-
305
- export { createRunHandler, getWorkflowByIdHandler, getWorkflowRunHandler, getWorkflowRunsHandler, getWorkflowsHandler, resumeAsyncWorkflowHandler, resumeWorkflowHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, watchWorkflowHandler, workflows_exports };