@mastra/server 0.0.0-vnextWorkflows-20250422081019 → 0.0.0-workflow-deno-20250616115451

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 (83) hide show
  1. package/README.md +48 -135
  2. package/dist/_tsup-dts-rollup.d.cts +351 -60
  3. package/dist/_tsup-dts-rollup.d.ts +351 -60
  4. package/dist/{chunk-XISBMH56.js → chunk-2HXKRRNS.js} +11 -9
  5. package/dist/chunk-42IKSJNO.js +421 -0
  6. package/dist/chunk-42YJ2YVD.cjs +263 -0
  7. package/dist/{chunk-4JINXASC.js → chunk-55DOQLP6.js} +5 -4
  8. package/dist/{chunk-QN4KF3BH.cjs → chunk-57CJTIPW.cjs} +2 -2
  9. package/dist/{chunk-ZLBRQFDD.cjs → chunk-64U3UDTH.cjs} +2 -2
  10. package/dist/{chunk-2FJURXCL.cjs → chunk-6TJSHFCJ.cjs} +44 -36
  11. package/dist/chunk-75ZPJI57.cjs +9 -0
  12. package/dist/chunk-ASKESBJW.cjs +2004 -0
  13. package/dist/{chunk-7IWQE76Z.cjs → chunk-B4MQFJ7G.cjs} +16 -10
  14. package/dist/{chunk-WTHDCRMY.js → chunk-BFOA2QQY.js} +12 -6
  15. package/dist/{chunk-M56ECCHK.cjs → chunk-BNEY4P4P.cjs} +20 -19
  16. package/dist/{chunk-YANVFOYA.js → chunk-C7564HUT.js} +56 -34
  17. package/dist/chunk-CK32I2VN.cjs +435 -0
  18. package/dist/{chunk-4B7OUZXW.js → chunk-CLYX4KLH.js} +78 -63
  19. package/dist/chunk-CMMOIUFC.cjs +114 -0
  20. package/dist/{chunk-3RVHWGWO.js → chunk-CP55EVBK.js} +26 -13
  21. package/dist/chunk-GHC4YV6R.js +504 -0
  22. package/dist/{chunk-L7XE5QTW.js → chunk-H5PTF3Y4.js} +1 -1
  23. package/dist/{chunk-RBQASTUP.js → chunk-I7KJZNX5.js} +14 -6
  24. package/dist/chunk-IMBY5XUG.cjs +86 -0
  25. package/dist/{chunk-3AHQ5RGN.js → chunk-M5ABIP7D.js} +1 -1
  26. package/dist/chunk-MLKGABMK.js +7 -0
  27. package/dist/{chunk-HABV7TZK.cjs → chunk-NGURCFEJ.cjs} +28 -26
  28. package/dist/{chunk-TRDNDNGQ.js → chunk-NYN7KFXL.js} +1 -7
  29. package/dist/chunk-O2YAAFY3.js +255 -0
  30. package/dist/{chunk-FV45V6WC.cjs → chunk-OCWPVYNI.cjs} +0 -7
  31. package/dist/chunk-QLG2PFHE.js +81 -0
  32. package/dist/chunk-SDPGVWQJ.cjs +512 -0
  33. package/dist/chunk-TGJMNUYJ.js +2001 -0
  34. package/dist/chunk-VPNDC2DI.cjs +148 -0
  35. package/dist/chunk-WE32JG64.cjs +332 -0
  36. package/dist/server/handlers/a2a.cjs +30 -0
  37. package/dist/server/handlers/a2a.d.cts +6 -0
  38. package/dist/server/handlers/a2a.d.ts +6 -0
  39. package/dist/server/handlers/a2a.js +1 -0
  40. package/dist/server/handlers/agents.cjs +7 -7
  41. package/dist/server/handlers/agents.js +1 -1
  42. package/dist/server/handlers/error.cjs +2 -2
  43. package/dist/server/handlers/error.js +1 -1
  44. package/dist/server/handlers/legacyWorkflows.cjs +46 -0
  45. package/dist/server/handlers/legacyWorkflows.d.cts +10 -0
  46. package/dist/server/handlers/legacyWorkflows.d.ts +10 -0
  47. package/dist/server/handlers/legacyWorkflows.js +1 -0
  48. package/dist/server/handlers/logs.cjs +4 -4
  49. package/dist/server/handlers/logs.js +1 -1
  50. package/dist/server/handlers/memory.cjs +9 -9
  51. package/dist/server/handlers/memory.js +1 -1
  52. package/dist/server/handlers/network.cjs +5 -5
  53. package/dist/server/handlers/network.js +1 -1
  54. package/dist/server/handlers/telemetry.cjs +3 -3
  55. package/dist/server/handlers/telemetry.js +1 -1
  56. package/dist/server/handlers/tools.cjs +5 -5
  57. package/dist/server/handlers/tools.js +1 -1
  58. package/dist/server/handlers/utils.cjs +2 -2
  59. package/dist/server/handlers/utils.js +1 -1
  60. package/dist/server/handlers/vector.cjs +7 -7
  61. package/dist/server/handlers/vector.js +1 -1
  62. package/dist/server/handlers/voice.cjs +8 -4
  63. package/dist/server/handlers/voice.d.cts +1 -0
  64. package/dist/server/handlers/voice.d.ts +1 -0
  65. package/dist/server/handlers/voice.js +1 -1
  66. package/dist/server/handlers/workflows.cjs +21 -13
  67. package/dist/server/handlers/workflows.d.cts +4 -2
  68. package/dist/server/handlers/workflows.d.ts +4 -2
  69. package/dist/server/handlers/workflows.js +1 -1
  70. package/dist/server/handlers.cjs +33 -23
  71. package/dist/server/handlers.d.cts +2 -0
  72. package/dist/server/handlers.d.ts +2 -0
  73. package/dist/server/handlers.js +11 -9
  74. package/package.json +13 -12
  75. package/dist/chunk-3EJZQ6TQ.js +0 -49
  76. package/dist/chunk-4WJ5GHRG.cjs +0 -164
  77. package/dist/chunk-5SWCVTNL.cjs +0 -5579
  78. package/dist/chunk-A7DF4ETD.cjs +0 -100
  79. package/dist/chunk-JLDXUWK7.cjs +0 -126
  80. package/dist/chunk-OMN3UI6X.js +0 -5576
  81. package/dist/chunk-RNU4JMLM.cjs +0 -317
  82. package/dist/chunk-SKBVVI24.cjs +0 -54
  83. package/dist/chunk-TFFNX7FI.js +0 -156
@@ -1,317 +0,0 @@
1
- 'use strict';
2
-
3
- var chunk5SWCVTNL_cjs = require('./chunk-5SWCVTNL.cjs');
4
- var chunkZLBRQFDD_cjs = require('./chunk-ZLBRQFDD.cjs');
5
- var chunkFV45V6WC_cjs = require('./chunk-FV45V6WC.cjs');
6
- var web = require('stream/web');
7
-
8
- // src/server/handlers/workflows.ts
9
- var workflows_exports = {};
10
- chunkFV45V6WC_cjs.__export(workflows_exports, {
11
- createRunHandler: () => createRunHandler,
12
- getWorkflowByIdHandler: () => getWorkflowByIdHandler,
13
- getWorkflowRunHandler: () => getWorkflowRunHandler,
14
- getWorkflowRunsHandler: () => getWorkflowRunsHandler,
15
- getWorkflowsHandler: () => getWorkflowsHandler,
16
- resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
17
- resumeWorkflowHandler: () => resumeWorkflowHandler,
18
- startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
19
- startWorkflowRunHandler: () => startWorkflowRunHandler,
20
- watchWorkflowHandler: () => watchWorkflowHandler
21
- });
22
- async function getWorkflowsHandler({ mastra }) {
23
- try {
24
- const workflows = mastra.getWorkflows({ serialized: false });
25
- const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
26
- if (workflow.isNested) return acc;
27
- acc[key] = {
28
- stepGraph: workflow.stepGraph,
29
- stepSubscriberGraph: workflow.stepSubscriberGraph,
30
- serializedStepGraph: workflow.serializedStepGraph,
31
- serializedStepSubscriberGraph: workflow.serializedStepSubscriberGraph,
32
- name: workflow.name,
33
- triggerSchema: workflow.triggerSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(workflow.triggerSchema)) : void 0,
34
- steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
35
- const _step = step;
36
- acc2[key2] = {
37
- ..._step,
38
- inputSchema: _step.inputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_step.inputSchema)) : void 0,
39
- outputSchema: _step.outputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_step.outputSchema)) : void 0
40
- };
41
- return acc2;
42
- }, {})
43
- };
44
- return acc;
45
- }, {});
46
- return _workflows;
47
- } catch (error) {
48
- throw new chunkFV45V6WC_cjs.HTTPException(500, { message: error?.message || "Error getting workflows" });
49
- }
50
- }
51
- async function getWorkflowByIdHandler({ mastra, workflowId }) {
52
- try {
53
- if (!workflowId) {
54
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Workflow ID is required" });
55
- }
56
- const workflow = mastra.getWorkflow(workflowId);
57
- if (!workflow) {
58
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Workflow not found" });
59
- }
60
- return {
61
- stepGraph: workflow.stepGraph,
62
- stepSubscriberGraph: workflow.stepSubscriberGraph,
63
- serializedStepGraph: workflow.serializedStepGraph,
64
- serializedStepSubscriberGraph: workflow.serializedStepSubscriberGraph,
65
- name: workflow.name,
66
- triggerSchema: workflow.triggerSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(workflow.triggerSchema)) : void 0,
67
- steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
68
- const _step = step;
69
- acc[key] = {
70
- ..._step,
71
- inputSchema: _step.inputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_step.inputSchema)) : void 0,
72
- outputSchema: _step.outputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_step.outputSchema)) : void 0
73
- };
74
- return acc;
75
- }, {})
76
- };
77
- } catch (error) {
78
- throw new chunkFV45V6WC_cjs.HTTPException(500, { message: error?.message || "Error getting workflow" });
79
- }
80
- }
81
- async function startAsyncWorkflowHandler({
82
- mastra,
83
- container,
84
- workflowId,
85
- runId,
86
- triggerData
87
- }) {
88
- try {
89
- if (!workflowId) {
90
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Workflow ID is required" });
91
- }
92
- const workflow = mastra.getWorkflow(workflowId);
93
- if (!workflow) {
94
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Workflow not found" });
95
- }
96
- if (!runId) {
97
- const { start } = workflow.createRun();
98
- const result2 = await start({
99
- triggerData,
100
- container
101
- });
102
- return result2;
103
- }
104
- const run = workflow.getRun(runId);
105
- if (!run) {
106
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Workflow run not found" });
107
- }
108
- const result = await run.start({
109
- triggerData,
110
- container
111
- });
112
- return result;
113
- } catch (error) {
114
- throw new chunkFV45V6WC_cjs.HTTPException(500, { message: error?.message || "Error executing workflow" });
115
- }
116
- }
117
- async function getWorkflowRunHandler({
118
- mastra,
119
- workflowId,
120
- runId
121
- }) {
122
- try {
123
- if (!workflowId) {
124
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Workflow ID is required" });
125
- }
126
- if (!runId) {
127
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Run ID is required" });
128
- }
129
- const workflow = mastra.getWorkflow(workflowId);
130
- if (!workflow) {
131
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Workflow not found" });
132
- }
133
- const run = workflow.getRun(runId);
134
- if (!run) {
135
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Workflow run not found" });
136
- }
137
- return run;
138
- } catch (error) {
139
- throw new chunkFV45V6WC_cjs.HTTPException(500, { message: error?.message || "Error getting workflow run" });
140
- }
141
- }
142
- async function createRunHandler({
143
- mastra,
144
- workflowId,
145
- runId: prevRunId
146
- }) {
147
- try {
148
- if (!workflowId) {
149
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Workflow ID is required" });
150
- }
151
- const workflow = mastra.getWorkflow(workflowId);
152
- if (!workflow) {
153
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Workflow not found" });
154
- }
155
- const { runId } = workflow.createRun({ runId: prevRunId });
156
- return { runId };
157
- } catch (error) {
158
- throw new chunkFV45V6WC_cjs.HTTPException(500, { message: error?.message || "Error creating workflow run" });
159
- }
160
- }
161
- async function startWorkflowRunHandler({
162
- mastra,
163
- container,
164
- workflowId,
165
- runId,
166
- triggerData
167
- }) {
168
- try {
169
- if (!workflowId) {
170
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Workflow ID is required" });
171
- }
172
- if (!runId) {
173
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "runId required to start run" });
174
- }
175
- const workflow = mastra.getWorkflow(workflowId);
176
- const run = workflow.getRun(runId);
177
- if (!run) {
178
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Workflow run not found" });
179
- }
180
- await run.start({
181
- triggerData,
182
- container
183
- });
184
- return { message: "Workflow run started" };
185
- } catch (e) {
186
- return chunkZLBRQFDD_cjs.handleError(e, "Error starting workflow run");
187
- }
188
- }
189
- async function watchWorkflowHandler({
190
- mastra,
191
- workflowId,
192
- runId
193
- }) {
194
- try {
195
- if (!workflowId) {
196
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Workflow ID is required" });
197
- }
198
- if (!runId) {
199
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "runId required to watch workflow" });
200
- }
201
- const workflow = mastra.getWorkflow(workflowId);
202
- const run = workflow.getRun(runId);
203
- if (!run) {
204
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Workflow run not found" });
205
- }
206
- let unwatch;
207
- let asyncRef = null;
208
- const stream = new web.ReadableStream({
209
- start(controller) {
210
- unwatch = run.watch(({ activePaths, runId: runId2, timestamp, results }) => {
211
- const activePathsObj = Object.fromEntries(activePaths);
212
- controller.enqueue(JSON.stringify({ activePaths: activePathsObj, runId: runId2, timestamp, results }));
213
- if (asyncRef) {
214
- clearImmediate(asyncRef);
215
- asyncRef = null;
216
- }
217
- asyncRef = setImmediate(() => {
218
- if (!workflow.getRun(runId2)) {
219
- controller.close();
220
- }
221
- });
222
- });
223
- },
224
- cancel() {
225
- unwatch?.();
226
- }
227
- });
228
- return stream;
229
- } catch (error) {
230
- return chunkZLBRQFDD_cjs.handleError(error, "Error watching workflow");
231
- }
232
- }
233
- async function resumeAsyncWorkflowHandler({
234
- mastra,
235
- workflowId,
236
- runId,
237
- body,
238
- container
239
- }) {
240
- try {
241
- if (!workflowId) {
242
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Workflow ID is required" });
243
- }
244
- if (!runId) {
245
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "runId required to resume workflow" });
246
- }
247
- const workflow = mastra.getWorkflow(workflowId);
248
- const run = workflow.getRun(runId);
249
- if (!run) {
250
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Workflow run not found" });
251
- }
252
- const result = await run.resume({
253
- stepId: body.stepId,
254
- context: body.context,
255
- container
256
- });
257
- return result;
258
- } catch (error) {
259
- return chunkZLBRQFDD_cjs.handleError(error, "Error resuming workflow step");
260
- }
261
- }
262
- async function resumeWorkflowHandler({
263
- mastra,
264
- workflowId,
265
- runId,
266
- body,
267
- container
268
- }) {
269
- try {
270
- if (!workflowId) {
271
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Workflow ID is required" });
272
- }
273
- if (!runId) {
274
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "runId required to resume workflow" });
275
- }
276
- const workflow = mastra.getWorkflow(workflowId);
277
- const run = workflow.getRun(runId);
278
- if (!run) {
279
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Workflow run not found" });
280
- }
281
- await run.resume({
282
- stepId: body.stepId,
283
- context: body.context,
284
- container
285
- });
286
- return { message: "Workflow run resumed" };
287
- } catch (error) {
288
- return chunkZLBRQFDD_cjs.handleError(error, "Error resuming workflow");
289
- }
290
- }
291
- async function getWorkflowRunsHandler({ mastra, workflowId }) {
292
- try {
293
- if (!workflowId) {
294
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Workflow ID is required" });
295
- }
296
- const workflow = mastra.getWorkflow(workflowId);
297
- const workflowRuns = await workflow.getWorkflowRuns() || {
298
- runs: [],
299
- total: 0
300
- };
301
- return workflowRuns;
302
- } catch (error) {
303
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting workflow runs");
304
- }
305
- }
306
-
307
- exports.createRunHandler = createRunHandler;
308
- exports.getWorkflowByIdHandler = getWorkflowByIdHandler;
309
- exports.getWorkflowRunHandler = getWorkflowRunHandler;
310
- exports.getWorkflowRunsHandler = getWorkflowRunsHandler;
311
- exports.getWorkflowsHandler = getWorkflowsHandler;
312
- exports.resumeAsyncWorkflowHandler = resumeAsyncWorkflowHandler;
313
- exports.resumeWorkflowHandler = resumeWorkflowHandler;
314
- exports.startAsyncWorkflowHandler = startAsyncWorkflowHandler;
315
- exports.startWorkflowRunHandler = startWorkflowRunHandler;
316
- exports.watchWorkflowHandler = watchWorkflowHandler;
317
- exports.workflows_exports = workflows_exports;
@@ -1,54 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkQN4KF3BH_cjs = require('./chunk-QN4KF3BH.cjs');
4
- var chunkZLBRQFDD_cjs = require('./chunk-ZLBRQFDD.cjs');
5
- var chunkFV45V6WC_cjs = require('./chunk-FV45V6WC.cjs');
6
-
7
- // src/server/handlers/logs.ts
8
- var logs_exports = {};
9
- chunkFV45V6WC_cjs.__export(logs_exports, {
10
- getLogTransports: () => getLogTransports,
11
- getLogsByRunIdHandler: () => getLogsByRunIdHandler,
12
- getLogsHandler: () => getLogsHandler
13
- });
14
- async function getLogsHandler({
15
- mastra,
16
- transportId
17
- }) {
18
- try {
19
- chunkQN4KF3BH_cjs.validateBody({ transportId });
20
- const logs = await mastra.getLogs(transportId);
21
- return logs;
22
- } catch (error) {
23
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting logs");
24
- }
25
- }
26
- async function getLogsByRunIdHandler({
27
- mastra,
28
- runId,
29
- transportId
30
- }) {
31
- try {
32
- chunkQN4KF3BH_cjs.validateBody({ runId, transportId });
33
- const logs = await mastra.getLogsByRunId({ runId, transportId });
34
- return logs;
35
- } catch (error) {
36
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting logs by run ID");
37
- }
38
- }
39
- async function getLogTransports({ mastra }) {
40
- try {
41
- const logger = mastra.getLogger();
42
- const transports = logger.transports;
43
- return {
44
- transports: transports ? Object.keys(transports) : []
45
- };
46
- } catch (error) {
47
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting log Transports");
48
- }
49
- }
50
-
51
- exports.getLogTransports = getLogTransports;
52
- exports.getLogsByRunIdHandler = getLogsByRunIdHandler;
53
- exports.getLogsHandler = getLogsHandler;
54
- exports.logs_exports = logs_exports;
@@ -1,156 +0,0 @@
1
- import { stringify, esm_default } from './chunk-OMN3UI6X.js';
2
- import { validateBody } from './chunk-L7XE5QTW.js';
3
- import { handleError } from './chunk-3AHQ5RGN.js';
4
- import { __export, HTTPException } from './chunk-TRDNDNGQ.js';
5
-
6
- // src/server/handlers/agents.ts
7
- var agents_exports = {};
8
- __export(agents_exports, {
9
- generateHandler: () => generateHandler,
10
- getAgentByIdHandler: () => getAgentByIdHandler,
11
- getAgentsHandler: () => getAgentsHandler,
12
- getEvalsByAgentIdHandler: () => getEvalsByAgentIdHandler,
13
- getLiveEvalsByAgentIdHandler: () => getLiveEvalsByAgentIdHandler,
14
- streamGenerateHandler: () => streamGenerateHandler
15
- });
16
- async function getAgentsHandler({ mastra }) {
17
- try {
18
- const agents = mastra.getAgents();
19
- const serializedAgents = Object.entries(agents).reduce((acc, [_id, _agent]) => {
20
- const agent = _agent;
21
- const serializedAgentTools = Object.entries(agent?.tools || {}).reduce((acc2, [key, tool]) => {
22
- const _tool = tool;
23
- acc2[key] = {
24
- ..._tool,
25
- inputSchema: _tool.inputSchema ? stringify(esm_default(_tool.inputSchema)) : void 0,
26
- outputSchema: _tool.outputSchema ? stringify(esm_default(_tool.outputSchema)) : void 0
27
- };
28
- return acc2;
29
- }, {});
30
- acc[_id] = {
31
- name: agent.name,
32
- instructions: agent.instructions,
33
- tools: serializedAgentTools,
34
- provider: agent.llm?.getProvider(),
35
- modelId: agent.llm?.getModelId()
36
- };
37
- return acc;
38
- }, {});
39
- return serializedAgents;
40
- } catch (error) {
41
- return handleError(error, "Error getting agents");
42
- }
43
- }
44
- async function getAgentByIdHandler({ mastra, agentId }) {
45
- try {
46
- const agent = mastra.getAgent(agentId);
47
- if (!agent) {
48
- throw new HTTPException(404, { message: "Agent not found" });
49
- }
50
- const serializedAgentTools = Object.entries(agent?.tools || {}).reduce((acc, [key, tool]) => {
51
- const _tool = tool;
52
- acc[key] = {
53
- ..._tool,
54
- inputSchema: _tool.inputSchema ? stringify(esm_default(_tool.inputSchema)) : void 0,
55
- outputSchema: _tool.outputSchema ? stringify(esm_default(_tool.outputSchema)) : void 0
56
- };
57
- return acc;
58
- }, {});
59
- return {
60
- name: agent.name,
61
- instructions: agent.instructions,
62
- tools: serializedAgentTools,
63
- provider: agent.llm?.getProvider(),
64
- modelId: agent.llm?.getModelId()
65
- };
66
- } catch (error) {
67
- return handleError(error, "Error getting agent");
68
- }
69
- }
70
- async function getEvalsByAgentIdHandler({ mastra, agentId }) {
71
- try {
72
- const agent = mastra.getAgent(agentId);
73
- const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
74
- return {
75
- id: agentId,
76
- name: agent.name,
77
- instructions: agent.instructions,
78
- evals
79
- };
80
- } catch (error) {
81
- return handleError(error, "Error getting test evals");
82
- }
83
- }
84
- async function getLiveEvalsByAgentIdHandler({ mastra, agentId }) {
85
- try {
86
- const agent = mastra.getAgent(agentId);
87
- const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
88
- return {
89
- id: agentId,
90
- name: agent.name,
91
- instructions: agent.instructions,
92
- evals
93
- };
94
- } catch (error) {
95
- return handleError(error, "Error getting live evals");
96
- }
97
- }
98
- async function generateHandler({
99
- mastra,
100
- container,
101
- agentId,
102
- body
103
- }) {
104
- try {
105
- const agent = mastra.getAgent(agentId);
106
- if (!agent) {
107
- throw new HTTPException(404, { message: "Agent not found" });
108
- }
109
- const { messages, resourceId, resourceid, ...rest } = body;
110
- const finalResourceId = resourceId ?? resourceid;
111
- validateBody({ messages });
112
- const result = await agent.generate(messages, {
113
- ...rest,
114
- // @ts-expect-error TODO fix types
115
- resourceId: finalResourceId,
116
- container
117
- });
118
- return result;
119
- } catch (error) {
120
- return handleError(error, "Error generating from agent");
121
- }
122
- }
123
- async function streamGenerateHandler({
124
- mastra,
125
- container,
126
- agentId,
127
- body
128
- }) {
129
- try {
130
- const agent = mastra.getAgent(agentId);
131
- if (!agent) {
132
- throw new HTTPException(404, { message: "Agent not found" });
133
- }
134
- const { messages, resourceId, resourceid, ...rest } = body;
135
- const finalResourceId = resourceId ?? resourceid;
136
- validateBody({ messages });
137
- const streamResult = await agent.stream(messages, {
138
- ...rest,
139
- // @ts-expect-error TODO fix types
140
- resourceId: finalResourceId,
141
- container
142
- });
143
- const streamResponse = rest.output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
144
- sendUsage: true,
145
- sendReasoning: true,
146
- getErrorMessage: (error) => {
147
- return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
148
- }
149
- });
150
- return streamResponse;
151
- } catch (error) {
152
- throw new HTTPException(error?.status ?? 500, { message: error?.message ?? "Error streaming from agent" });
153
- }
154
- }
155
-
156
- export { agents_exports, generateHandler, getAgentByIdHandler, getAgentsHandler, getEvalsByAgentIdHandler, getLiveEvalsByAgentIdHandler, streamGenerateHandler };