@mastra/server 0.0.0-extend-clickhouse-20250418135620 → 0.0.0-feat-tool-input-validation-20250731232758

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 (102) hide show
  1. package/LICENSE.md +11 -42
  2. package/README.md +48 -135
  3. package/dist/_tsup-dts-rollup.d.cts +763 -76
  4. package/dist/_tsup-dts-rollup.d.ts +763 -76
  5. package/dist/{chunk-FV45V6WC.cjs → chunk-2KZFMI6P.cjs} +1 -7
  6. package/dist/chunk-2SLFAFTR.cjs +148 -0
  7. package/dist/chunk-36BLNJHS.js +2039 -0
  8. package/dist/chunk-424T5F2J.cjs +157 -0
  9. package/dist/chunk-4D66QEKC.js +81 -0
  10. package/dist/chunk-6KP2OBYA.cjs +544 -0
  11. package/dist/chunk-6T5JUKOQ.js +149 -0
  12. package/dist/chunk-75ZPJI57.cjs +9 -0
  13. package/dist/{chunk-M56ECCHK.cjs → chunk-7TP2LX5L.cjs} +20 -19
  14. package/dist/{chunk-QN4KF3BH.cjs → chunk-CCGRCYWJ.cjs} +2 -2
  15. package/dist/{chunk-YANVFOYA.js → chunk-CRCR3ZUK.js} +56 -34
  16. package/dist/{chunk-7IWQE76Z.cjs → chunk-G7KH752Y.cjs} +16 -10
  17. package/dist/chunk-GHC4YV6R.js +504 -0
  18. package/dist/chunk-HISYIDYH.cjs +2042 -0
  19. package/dist/{chunk-HABV7TZK.cjs → chunk-HRSAZUIK.cjs} +28 -26
  20. package/dist/chunk-I5JKUCGE.cjs +308 -0
  21. package/dist/{chunk-3RVHWGWO.js → chunk-KHZKYUNR.js} +36 -19
  22. package/dist/{chunk-TRDNDNGQ.js → chunk-LCM566I4.js} +2 -7
  23. package/dist/chunk-LF7P5PLR.js +14 -0
  24. package/dist/chunk-MLKGABMK.js +7 -0
  25. package/dist/chunk-PIAJQ75M.js +539 -0
  26. package/dist/chunk-PZQDCRPV.cjs +16 -0
  27. package/dist/chunk-QGX47B5D.cjs +86 -0
  28. package/dist/{chunk-WTHDCRMY.js → chunk-RG473F6Y.js} +12 -6
  29. package/dist/chunk-RHSWAXKB.cjs +118 -0
  30. package/dist/{chunk-L7XE5QTW.js → chunk-RSEO4XPX.js} +1 -1
  31. package/dist/chunk-SDPGVWQJ.cjs +512 -0
  32. package/dist/chunk-T7HAZC2E.js +527 -0
  33. package/dist/chunk-UCV4247U.cjs +332 -0
  34. package/dist/chunk-UEVYOKAH.cjs +555 -0
  35. package/dist/chunk-VTTN2FW3.js +299 -0
  36. package/dist/{chunk-XISBMH56.js → chunk-WBRFIHSF.js} +11 -9
  37. package/dist/{chunk-4JINXASC.js → chunk-WNVFNNWN.js} +5 -4
  38. package/dist/{chunk-4B7OUZXW.js → chunk-ZYAFP2AV.js} +83 -68
  39. package/dist/server/handlers/a2a.cjs +30 -0
  40. package/dist/server/handlers/a2a.d.cts +6 -0
  41. package/dist/server/handlers/a2a.d.ts +6 -0
  42. package/dist/server/handlers/a2a.js +1 -0
  43. package/dist/server/handlers/agents.cjs +11 -7
  44. package/dist/server/handlers/agents.d.cts +1 -0
  45. package/dist/server/handlers/agents.d.ts +1 -0
  46. package/dist/server/handlers/agents.js +1 -1
  47. package/dist/server/handlers/error.cjs +2 -2
  48. package/dist/server/handlers/error.js +1 -1
  49. package/dist/server/handlers/legacyWorkflows.cjs +46 -0
  50. package/dist/server/handlers/legacyWorkflows.d.cts +10 -0
  51. package/dist/server/handlers/legacyWorkflows.d.ts +10 -0
  52. package/dist/server/handlers/legacyWorkflows.js +1 -0
  53. package/dist/server/handlers/logs.cjs +4 -4
  54. package/dist/server/handlers/logs.js +1 -1
  55. package/dist/server/handlers/memory.cjs +33 -9
  56. package/dist/server/handlers/memory.d.cts +6 -0
  57. package/dist/server/handlers/memory.d.ts +6 -0
  58. package/dist/server/handlers/memory.js +1 -1
  59. package/dist/server/handlers/network.cjs +5 -5
  60. package/dist/server/handlers/network.js +1 -1
  61. package/dist/server/handlers/scores.cjs +30 -0
  62. package/dist/server/handlers/scores.d.cts +6 -0
  63. package/dist/server/handlers/scores.d.ts +6 -0
  64. package/dist/server/handlers/scores.js +1 -0
  65. package/dist/server/handlers/telemetry.cjs +3 -3
  66. package/dist/server/handlers/telemetry.js +1 -1
  67. package/dist/server/handlers/tools.cjs +5 -5
  68. package/dist/server/handlers/tools.js +1 -1
  69. package/dist/server/handlers/utils.cjs +2 -2
  70. package/dist/server/handlers/utils.js +1 -1
  71. package/dist/server/handlers/vNextNetwork.cjs +218 -0
  72. package/dist/server/handlers/vNextNetwork.d.cts +6 -0
  73. package/dist/server/handlers/vNextNetwork.d.ts +6 -0
  74. package/dist/server/handlers/vNextNetwork.js +211 -0
  75. package/dist/server/handlers/vector.cjs +7 -7
  76. package/dist/server/handlers/vector.js +1 -1
  77. package/dist/server/handlers/voice.cjs +8 -4
  78. package/dist/server/handlers/voice.d.cts +1 -0
  79. package/dist/server/handlers/voice.d.ts +1 -0
  80. package/dist/server/handlers/voice.js +1 -1
  81. package/dist/server/handlers/workflows.cjs +33 -13
  82. package/dist/server/handlers/workflows.d.cts +7 -2
  83. package/dist/server/handlers/workflows.d.ts +7 -2
  84. package/dist/server/handlers/workflows.js +1 -1
  85. package/dist/server/handlers.cjs +40 -25
  86. package/dist/server/handlers.d.cts +4 -1
  87. package/dist/server/handlers.d.ts +4 -1
  88. package/dist/server/handlers.js +12 -9
  89. package/package.json +17 -15
  90. package/dist/chunk-2FJURXCL.cjs +0 -213
  91. package/dist/chunk-3AHQ5RGN.js +0 -11
  92. package/dist/chunk-3EJZQ6TQ.js +0 -49
  93. package/dist/chunk-4WJ5GHRG.cjs +0 -164
  94. package/dist/chunk-5SWCVTNL.cjs +0 -5579
  95. package/dist/chunk-A7DF4ETD.cjs +0 -100
  96. package/dist/chunk-JLDXUWK7.cjs +0 -126
  97. package/dist/chunk-OMN3UI6X.js +0 -5576
  98. package/dist/chunk-RBQASTUP.js +0 -203
  99. package/dist/chunk-RNU4JMLM.cjs +0 -317
  100. package/dist/chunk-SKBVVI24.cjs +0 -54
  101. package/dist/chunk-TFFNX7FI.js +0 -156
  102. package/dist/chunk-ZLBRQFDD.cjs +0 -13
@@ -0,0 +1,544 @@
1
+ 'use strict';
2
+
3
+ var chunkHISYIDYH_cjs = require('./chunk-HISYIDYH.cjs');
4
+ var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
5
+ var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
6
+ var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
7
+ var web = require('stream/web');
8
+
9
+ // src/server/handlers/workflows.ts
10
+ var workflows_exports = {};
11
+ chunk75ZPJI57_cjs.__export(workflows_exports, {
12
+ cancelWorkflowRunHandler: () => cancelWorkflowRunHandler,
13
+ createWorkflowRunHandler: () => createWorkflowRunHandler,
14
+ getWorkflowByIdHandler: () => getWorkflowByIdHandler,
15
+ getWorkflowRunByIdHandler: () => getWorkflowRunByIdHandler,
16
+ getWorkflowRunExecutionResultHandler: () => getWorkflowRunExecutionResultHandler,
17
+ getWorkflowRunsHandler: () => getWorkflowRunsHandler,
18
+ getWorkflowsHandler: () => getWorkflowsHandler,
19
+ resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
20
+ resumeWorkflowHandler: () => resumeWorkflowHandler,
21
+ sendWorkflowRunEventHandler: () => sendWorkflowRunEventHandler,
22
+ startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
23
+ startWorkflowRunHandler: () => startWorkflowRunHandler,
24
+ streamVNextWorkflowHandler: () => streamVNextWorkflowHandler,
25
+ streamWorkflowHandler: () => streamWorkflowHandler,
26
+ watchWorkflowHandler: () => watchWorkflowHandler
27
+ });
28
+ function getSteps(steps, path) {
29
+ return Object.entries(steps).reduce((acc, [key, step]) => {
30
+ const fullKey = path ? `${path}.${key}` : key;
31
+ acc[fullKey] = {
32
+ id: step.id,
33
+ description: step.description,
34
+ inputSchema: step.inputSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.inputSchema)) : void 0,
35
+ outputSchema: step.outputSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.outputSchema)) : void 0,
36
+ resumeSchema: step.resumeSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.resumeSchema)) : void 0,
37
+ suspendSchema: step.suspendSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.suspendSchema)) : void 0,
38
+ isWorkflow: step.component === "WORKFLOW"
39
+ };
40
+ if (step.component === "WORKFLOW" && step.steps) {
41
+ const nestedSteps = getSteps(step.steps, fullKey) || {};
42
+ acc = { ...acc, ...nestedSteps };
43
+ }
44
+ return acc;
45
+ }, {});
46
+ }
47
+ async function getWorkflowsHandler({ mastra }) {
48
+ try {
49
+ const workflows = mastra.getWorkflows({ serialized: false });
50
+ const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
51
+ acc[key] = {
52
+ name: workflow.name,
53
+ description: workflow.description,
54
+ steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
55
+ acc2[key2] = {
56
+ id: step.id,
57
+ description: step.description,
58
+ inputSchema: step.inputSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.inputSchema)) : void 0,
59
+ outputSchema: step.outputSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.outputSchema)) : void 0,
60
+ resumeSchema: step.resumeSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.resumeSchema)) : void 0,
61
+ suspendSchema: step.suspendSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.suspendSchema)) : void 0
62
+ };
63
+ return acc2;
64
+ }, {}),
65
+ allSteps: getSteps(workflow.steps) || {},
66
+ stepGraph: workflow.serializedStepGraph,
67
+ inputSchema: workflow.inputSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(workflow.inputSchema)) : void 0,
68
+ outputSchema: workflow.outputSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(workflow.outputSchema)) : void 0
69
+ };
70
+ return acc;
71
+ }, {});
72
+ return _workflows;
73
+ } catch (error) {
74
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting workflows");
75
+ }
76
+ }
77
+ async function getWorkflowsFromSystem({ mastra, workflowId }) {
78
+ const logger = mastra.getLogger();
79
+ if (!workflowId) {
80
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
81
+ }
82
+ let workflow;
83
+ try {
84
+ workflow = mastra.getWorkflow(workflowId);
85
+ } catch (error) {
86
+ logger.debug("Error getting workflow, searching agents for workflow", error);
87
+ }
88
+ if (!workflow) {
89
+ logger.debug("Workflow not found, searching agents for workflow", { workflowId });
90
+ const agents = mastra.getAgents();
91
+ if (Object.keys(agents || {}).length) {
92
+ for (const [_, agent] of Object.entries(agents)) {
93
+ try {
94
+ const workflows = await agent.getWorkflows();
95
+ if (workflows[workflowId]) {
96
+ workflow = workflows[workflowId];
97
+ break;
98
+ }
99
+ break;
100
+ } catch (error) {
101
+ logger.debug("Error getting workflow from agent", error);
102
+ }
103
+ }
104
+ }
105
+ }
106
+ if (!workflow) {
107
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
108
+ }
109
+ return { workflow };
110
+ }
111
+ async function getWorkflowByIdHandler({ mastra, workflowId }) {
112
+ try {
113
+ if (!workflowId) {
114
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
115
+ }
116
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
117
+ if (!workflow) {
118
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
119
+ }
120
+ return {
121
+ steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
122
+ acc[key] = {
123
+ id: step.id,
124
+ description: step.description,
125
+ inputSchema: step.inputSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.inputSchema)) : void 0,
126
+ outputSchema: step.outputSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.outputSchema)) : void 0,
127
+ resumeSchema: step.resumeSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.resumeSchema)) : void 0,
128
+ suspendSchema: step.suspendSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.suspendSchema)) : void 0
129
+ };
130
+ return acc;
131
+ }, {}),
132
+ allSteps: getSteps(workflow.steps) || {},
133
+ name: workflow.name,
134
+ description: workflow.description,
135
+ stepGraph: workflow.serializedStepGraph,
136
+ inputSchema: workflow.inputSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(workflow.inputSchema)) : void 0,
137
+ outputSchema: workflow.outputSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(workflow.outputSchema)) : void 0
138
+ };
139
+ } catch (error) {
140
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting workflow");
141
+ }
142
+ }
143
+ async function getWorkflowRunByIdHandler({
144
+ mastra,
145
+ workflowId,
146
+ runId
147
+ }) {
148
+ try {
149
+ if (!workflowId) {
150
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
151
+ }
152
+ if (!runId) {
153
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Run ID is required" });
154
+ }
155
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
156
+ if (!workflow) {
157
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
158
+ }
159
+ const run = await workflow.getWorkflowRunById(runId);
160
+ if (!run) {
161
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
162
+ }
163
+ return run;
164
+ } catch (error) {
165
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting workflow run");
166
+ }
167
+ }
168
+ async function getWorkflowRunExecutionResultHandler({
169
+ mastra,
170
+ workflowId,
171
+ runId
172
+ }) {
173
+ try {
174
+ if (!workflowId) {
175
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
176
+ }
177
+ if (!runId) {
178
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Run ID is required" });
179
+ }
180
+ const workflow = mastra.getWorkflow(workflowId);
181
+ if (!workflow) {
182
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
183
+ }
184
+ const executionResult = await workflow.getWorkflowRunExecutionResult(runId);
185
+ if (!executionResult) {
186
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run execution result not found" });
187
+ }
188
+ return executionResult;
189
+ } catch (error) {
190
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting workflow run execution result");
191
+ }
192
+ }
193
+ async function createWorkflowRunHandler({
194
+ mastra,
195
+ workflowId,
196
+ runId: prevRunId
197
+ }) {
198
+ try {
199
+ if (!workflowId) {
200
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
201
+ }
202
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
203
+ if (!workflow) {
204
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
205
+ }
206
+ const run = await workflow.createRunAsync({ runId: prevRunId });
207
+ return { runId: run.runId };
208
+ } catch (error) {
209
+ return chunkPZQDCRPV_cjs.handleError(error, "Error creating workflow run");
210
+ }
211
+ }
212
+ async function startAsyncWorkflowHandler({
213
+ mastra,
214
+ runtimeContext,
215
+ workflowId,
216
+ runId,
217
+ inputData
218
+ }) {
219
+ try {
220
+ if (!workflowId) {
221
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
222
+ }
223
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
224
+ if (!workflow) {
225
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
226
+ }
227
+ const _run = await workflow.createRunAsync({ runId });
228
+ const result = await _run.start({
229
+ inputData,
230
+ runtimeContext
231
+ });
232
+ return result;
233
+ } catch (error) {
234
+ return chunkPZQDCRPV_cjs.handleError(error, "Error starting async workflow");
235
+ }
236
+ }
237
+ async function startWorkflowRunHandler({
238
+ mastra,
239
+ runtimeContext,
240
+ workflowId,
241
+ runId,
242
+ inputData
243
+ }) {
244
+ try {
245
+ if (!workflowId) {
246
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
247
+ }
248
+ if (!runId) {
249
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to start run" });
250
+ }
251
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
252
+ if (!workflow) {
253
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
254
+ }
255
+ const run = await workflow.getWorkflowRunById(runId);
256
+ if (!run) {
257
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
258
+ }
259
+ const _run = await workflow.createRunAsync({ runId });
260
+ void _run.start({
261
+ inputData,
262
+ runtimeContext
263
+ });
264
+ return { message: "Workflow run started" };
265
+ } catch (e) {
266
+ return chunkPZQDCRPV_cjs.handleError(e, "Error starting workflow run");
267
+ }
268
+ }
269
+ async function watchWorkflowHandler({
270
+ mastra,
271
+ workflowId,
272
+ runId
273
+ }) {
274
+ try {
275
+ if (!workflowId) {
276
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
277
+ }
278
+ if (!runId) {
279
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to watch workflow" });
280
+ }
281
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
282
+ if (!workflow) {
283
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
284
+ }
285
+ const run = await workflow.getWorkflowRunById(runId);
286
+ if (!run) {
287
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
288
+ }
289
+ const _run = await workflow.createRunAsync({ runId });
290
+ let unwatch;
291
+ let asyncRef = null;
292
+ const stream = new web.ReadableStream({
293
+ start(controller) {
294
+ unwatch = _run.watch(({ type, payload, eventTimestamp }) => {
295
+ controller.enqueue(JSON.stringify({ type, payload, eventTimestamp, runId }));
296
+ if (asyncRef) {
297
+ clearImmediate(asyncRef);
298
+ asyncRef = null;
299
+ }
300
+ asyncRef = setImmediate(async () => {
301
+ const runDone = payload.workflowState.status !== "running";
302
+ if (runDone) {
303
+ controller.close();
304
+ unwatch?.();
305
+ }
306
+ });
307
+ });
308
+ },
309
+ cancel() {
310
+ unwatch?.();
311
+ }
312
+ });
313
+ return stream;
314
+ } catch (error) {
315
+ return chunkPZQDCRPV_cjs.handleError(error, "Error watching workflow");
316
+ }
317
+ }
318
+ async function streamWorkflowHandler({
319
+ mastra,
320
+ runtimeContext,
321
+ workflowId,
322
+ runId,
323
+ inputData
324
+ }) {
325
+ try {
326
+ if (!workflowId) {
327
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
328
+ }
329
+ if (!runId) {
330
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to resume workflow" });
331
+ }
332
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
333
+ if (!workflow) {
334
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
335
+ }
336
+ const run = await workflow.createRunAsync({ runId });
337
+ const result = run.stream({
338
+ inputData,
339
+ runtimeContext
340
+ });
341
+ return result;
342
+ } catch (error) {
343
+ return chunkPZQDCRPV_cjs.handleError(error, "Error executing workflow");
344
+ }
345
+ }
346
+ async function streamVNextWorkflowHandler({
347
+ mastra,
348
+ runtimeContext,
349
+ workflowId,
350
+ runId,
351
+ inputData
352
+ }) {
353
+ try {
354
+ if (!workflowId) {
355
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
356
+ }
357
+ if (!runId) {
358
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to stream workflow" });
359
+ }
360
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
361
+ if (!workflow) {
362
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
363
+ }
364
+ const run = await workflow.createRunAsync({ runId });
365
+ const result = run.streamVNext({
366
+ inputData,
367
+ runtimeContext
368
+ });
369
+ return result;
370
+ } catch (error) {
371
+ return chunkPZQDCRPV_cjs.handleError(error, "Error streaming workflow");
372
+ }
373
+ }
374
+ async function resumeAsyncWorkflowHandler({
375
+ mastra,
376
+ workflowId,
377
+ runId,
378
+ body,
379
+ runtimeContext
380
+ }) {
381
+ try {
382
+ if (!workflowId) {
383
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
384
+ }
385
+ if (!runId) {
386
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to resume workflow" });
387
+ }
388
+ if (!body.step) {
389
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "step required to resume workflow" });
390
+ }
391
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
392
+ if (!workflow) {
393
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
394
+ }
395
+ const run = await workflow.getWorkflowRunById(runId);
396
+ if (!run) {
397
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
398
+ }
399
+ const _run = await workflow.createRunAsync({ runId });
400
+ const result = await _run.resume({
401
+ step: body.step,
402
+ resumeData: body.resumeData,
403
+ runtimeContext
404
+ });
405
+ return result;
406
+ } catch (error) {
407
+ return chunkPZQDCRPV_cjs.handleError(error, "Error resuming workflow step");
408
+ }
409
+ }
410
+ async function resumeWorkflowHandler({
411
+ mastra,
412
+ workflowId,
413
+ runId,
414
+ body,
415
+ runtimeContext
416
+ }) {
417
+ try {
418
+ if (!workflowId) {
419
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
420
+ }
421
+ if (!runId) {
422
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to resume workflow" });
423
+ }
424
+ if (!body.step) {
425
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "step required to resume workflow" });
426
+ }
427
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
428
+ if (!workflow) {
429
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
430
+ }
431
+ const run = await workflow.getWorkflowRunById(runId);
432
+ if (!run) {
433
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
434
+ }
435
+ const _run = await workflow.createRunAsync({ runId });
436
+ void _run.resume({
437
+ step: body.step,
438
+ resumeData: body.resumeData,
439
+ runtimeContext
440
+ });
441
+ return { message: "Workflow run resumed" };
442
+ } catch (error) {
443
+ return chunkPZQDCRPV_cjs.handleError(error, "Error resuming workflow");
444
+ }
445
+ }
446
+ async function getWorkflowRunsHandler({
447
+ mastra,
448
+ workflowId,
449
+ fromDate,
450
+ toDate,
451
+ limit,
452
+ offset,
453
+ resourceId
454
+ }) {
455
+ try {
456
+ if (!workflowId) {
457
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
458
+ }
459
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
460
+ if (!workflow) {
461
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
462
+ }
463
+ const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
464
+ runs: [],
465
+ total: 0
466
+ };
467
+ return workflowRuns;
468
+ } catch (error) {
469
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting workflow runs");
470
+ }
471
+ }
472
+ async function cancelWorkflowRunHandler({
473
+ mastra,
474
+ workflowId,
475
+ runId
476
+ }) {
477
+ try {
478
+ if (!workflowId) {
479
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
480
+ }
481
+ if (!runId) {
482
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to cancel workflow run" });
483
+ }
484
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
485
+ if (!workflow) {
486
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
487
+ }
488
+ const run = await workflow.getWorkflowRunById(runId);
489
+ if (!run) {
490
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
491
+ }
492
+ const _run = await workflow.createRunAsync({ runId });
493
+ await _run.cancel();
494
+ return { message: "Workflow run cancelled" };
495
+ } catch (error) {
496
+ return chunkPZQDCRPV_cjs.handleError(error, "Error canceling workflow run");
497
+ }
498
+ }
499
+ async function sendWorkflowRunEventHandler({
500
+ mastra,
501
+ workflowId,
502
+ runId,
503
+ event,
504
+ data
505
+ }) {
506
+ try {
507
+ if (!workflowId) {
508
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
509
+ }
510
+ if (!runId) {
511
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to send workflow run event" });
512
+ }
513
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
514
+ if (!workflow) {
515
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
516
+ }
517
+ const run = await workflow.getWorkflowRunById(runId);
518
+ if (!run) {
519
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
520
+ }
521
+ const _run = await workflow.createRunAsync({ runId });
522
+ await _run.sendEvent(event, data);
523
+ return { message: "Workflow run event sent" };
524
+ } catch (error) {
525
+ return chunkPZQDCRPV_cjs.handleError(error, "Error sending workflow run event");
526
+ }
527
+ }
528
+
529
+ exports.cancelWorkflowRunHandler = cancelWorkflowRunHandler;
530
+ exports.createWorkflowRunHandler = createWorkflowRunHandler;
531
+ exports.getWorkflowByIdHandler = getWorkflowByIdHandler;
532
+ exports.getWorkflowRunByIdHandler = getWorkflowRunByIdHandler;
533
+ exports.getWorkflowRunExecutionResultHandler = getWorkflowRunExecutionResultHandler;
534
+ exports.getWorkflowRunsHandler = getWorkflowRunsHandler;
535
+ exports.getWorkflowsHandler = getWorkflowsHandler;
536
+ exports.resumeAsyncWorkflowHandler = resumeAsyncWorkflowHandler;
537
+ exports.resumeWorkflowHandler = resumeWorkflowHandler;
538
+ exports.sendWorkflowRunEventHandler = sendWorkflowRunEventHandler;
539
+ exports.startAsyncWorkflowHandler = startAsyncWorkflowHandler;
540
+ exports.startWorkflowRunHandler = startWorkflowRunHandler;
541
+ exports.streamVNextWorkflowHandler = streamVNextWorkflowHandler;
542
+ exports.streamWorkflowHandler = streamWorkflowHandler;
543
+ exports.watchWorkflowHandler = watchWorkflowHandler;
544
+ exports.workflows_exports = workflows_exports;
@@ -0,0 +1,149 @@
1
+ import { handleError } from './chunk-LF7P5PLR.js';
2
+ import { __export } from './chunk-MLKGABMK.js';
3
+
4
+ // src/server/handlers/scores.ts
5
+ var scores_exports = {};
6
+ __export(scores_exports, {
7
+ getScorerHandler: () => getScorerHandler,
8
+ getScorersHandler: () => getScorersHandler,
9
+ getScoresByEntityIdHandler: () => getScoresByEntityIdHandler,
10
+ getScoresByRunIdHandler: () => getScoresByRunIdHandler,
11
+ getScoresByScorerIdHandler: () => getScoresByScorerIdHandler,
12
+ saveScoreHandler: () => saveScoreHandler
13
+ });
14
+ async function getScorersFromSystem({
15
+ mastra,
16
+ runtimeContext
17
+ }) {
18
+ const agents = mastra.getAgents();
19
+ const workflows = mastra.getWorkflows();
20
+ const scorersMap = /* @__PURE__ */ new Map();
21
+ for (const [agentId, agent] of Object.entries(agents)) {
22
+ const scorers = await agent.getScorers({
23
+ runtimeContext
24
+ }) || {};
25
+ if (Object.keys(scorers).length > 0) {
26
+ for (const [scorerId, scorer] of Object.entries(scorers)) {
27
+ if (scorersMap.has(scorerId)) {
28
+ scorersMap.get(scorerId)?.agentIds.push(agentId);
29
+ } else {
30
+ scorersMap.set(scorerId, {
31
+ workflowIds: [],
32
+ ...scorer,
33
+ agentIds: [agent.name]
34
+ });
35
+ }
36
+ }
37
+ }
38
+ }
39
+ for (const [workflowId, workflow] of Object.entries(workflows)) {
40
+ const scorers = await workflow.getScorers({
41
+ runtimeContext
42
+ }) || {};
43
+ if (Object.keys(scorers).length > 0) {
44
+ for (const [scorerId, scorer] of Object.entries(scorers)) {
45
+ if (scorersMap.has(scorerId)) {
46
+ scorersMap.get(scorerId)?.workflowIds.push(workflowId);
47
+ } else {
48
+ scorersMap.set(scorerId, {
49
+ agentIds: [],
50
+ ...scorer,
51
+ workflowIds: [workflowId]
52
+ });
53
+ }
54
+ }
55
+ }
56
+ }
57
+ return Object.fromEntries(scorersMap.entries());
58
+ }
59
+ async function getScorersHandler({ mastra, runtimeContext }) {
60
+ const scorers = await getScorersFromSystem({
61
+ mastra,
62
+ runtimeContext
63
+ });
64
+ return scorers;
65
+ }
66
+ async function getScorerHandler({
67
+ mastra,
68
+ scorerId,
69
+ runtimeContext
70
+ }) {
71
+ const scorers = await getScorersFromSystem({
72
+ mastra,
73
+ runtimeContext
74
+ });
75
+ const scorer = scorers[scorerId];
76
+ if (!scorer) {
77
+ return null;
78
+ }
79
+ return scorer;
80
+ }
81
+ async function getScoresByRunIdHandler({
82
+ mastra,
83
+ runId,
84
+ pagination
85
+ }) {
86
+ try {
87
+ const scores = await mastra.getStorage()?.getScoresByRunId?.({
88
+ runId,
89
+ pagination
90
+ }) || [];
91
+ return scores;
92
+ } catch (error) {
93
+ return handleError(error, "Error getting scores by run id");
94
+ }
95
+ }
96
+ async function getScoresByScorerIdHandler({
97
+ mastra,
98
+ scorerId,
99
+ pagination,
100
+ entityId,
101
+ entityType
102
+ }) {
103
+ try {
104
+ const scores = await mastra.getStorage()?.getScoresByScorerId?.({
105
+ scorerId,
106
+ pagination,
107
+ entityId,
108
+ entityType
109
+ }) || [];
110
+ return scores;
111
+ } catch (error) {
112
+ return handleError(error, "Error getting scores by scorer id");
113
+ }
114
+ }
115
+ async function getScoresByEntityIdHandler({
116
+ mastra,
117
+ entityId,
118
+ entityType,
119
+ pagination
120
+ }) {
121
+ try {
122
+ let entityIdToUse = entityId;
123
+ if (entityType === "AGENT") {
124
+ const agent = mastra.getAgentById(entityId);
125
+ entityIdToUse = agent.id;
126
+ } else if (entityType === "WORKFLOW") {
127
+ const workflow = mastra.getWorkflowById(entityId);
128
+ entityIdToUse = workflow.id;
129
+ }
130
+ const scores = await mastra.getStorage()?.getScoresByEntityId?.({
131
+ entityId: entityIdToUse,
132
+ entityType,
133
+ pagination
134
+ }) || [];
135
+ return scores;
136
+ } catch (error) {
137
+ return handleError(error, "Error getting scores by entity id");
138
+ }
139
+ }
140
+ async function saveScoreHandler({ mastra, score }) {
141
+ try {
142
+ const scores = await mastra.getStorage()?.saveScore?.(score) || [];
143
+ return scores;
144
+ } catch (error) {
145
+ return handleError(error, "Error saving score");
146
+ }
147
+ }
148
+
149
+ export { getScorerHandler, getScorersHandler, getScoresByEntityIdHandler, getScoresByRunIdHandler, getScoresByScorerIdHandler, saveScoreHandler, scores_exports };
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __export = (target, all) => {
5
+ for (var name in all)
6
+ __defProp(target, name, { get: all[name], enumerable: true });
7
+ };
8
+
9
+ exports.__export = __export;