@mastra/server 0.0.0-fix-memory-xxhash-20250409202110 → 0.0.0-fix-generate-title-20250616171351

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 (84) hide show
  1. package/{LICENSE → LICENSE.md} +3 -1
  2. package/README.md +48 -135
  3. package/dist/_tsup-dts-rollup.d.cts +357 -57
  4. package/dist/_tsup-dts-rollup.d.ts +357 -57
  5. package/dist/{chunk-YNSGUC2O.js → chunk-2HXKRRNS.js} +14 -8
  6. package/dist/chunk-4O23XCE5.js +262 -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-CWSDZEZG.cjs → chunk-B4MQFJ7G.cjs} +18 -12
  14. package/dist/{chunk-DVPP5S6I.js → chunk-BFOA2QQY.js} +14 -8
  15. package/dist/{chunk-M56ECCHK.cjs → chunk-BNEY4P4P.cjs} +20 -19
  16. package/dist/{chunk-2YONKUWB.js → chunk-C7564HUT.js} +58 -33
  17. package/dist/chunk-C75ZRJKD.cjs +270 -0
  18. package/dist/{chunk-ILW7XYNJ.js → chunk-CLYX4KLH.js} +85 -61
  19. package/dist/chunk-CMMOIUFC.cjs +114 -0
  20. package/dist/{chunk-3RVHWGWO.js → chunk-CP55EVBK.js} +26 -13
  21. package/dist/chunk-FRXZL32L.cjs +471 -0
  22. package/dist/chunk-GHC4YV6R.js +504 -0
  23. package/dist/{chunk-L7XE5QTW.js → chunk-H5PTF3Y4.js} +1 -1
  24. package/dist/{chunk-RBQASTUP.js → chunk-I7KJZNX5.js} +14 -6
  25. package/dist/chunk-IMBY5XUG.cjs +86 -0
  26. package/dist/chunk-JKTNRUKY.js +457 -0
  27. package/dist/{chunk-3AHQ5RGN.js → chunk-M5ABIP7D.js} +1 -1
  28. package/dist/chunk-MLKGABMK.js +7 -0
  29. package/dist/{chunk-4C3EPMMF.cjs → chunk-NGURCFEJ.cjs} +31 -25
  30. package/dist/{chunk-TRDNDNGQ.js → chunk-NYN7KFXL.js} +1 -7
  31. package/dist/{chunk-FV45V6WC.cjs → chunk-OCWPVYNI.cjs} +0 -7
  32. package/dist/chunk-QLG2PFHE.js +81 -0
  33. package/dist/chunk-SDPGVWQJ.cjs +512 -0
  34. package/dist/chunk-TGJMNUYJ.js +2001 -0
  35. package/dist/chunk-VPNDC2DI.cjs +148 -0
  36. package/dist/chunk-WE32JG64.cjs +332 -0
  37. package/dist/server/handlers/a2a.cjs +30 -0
  38. package/dist/server/handlers/a2a.d.cts +6 -0
  39. package/dist/server/handlers/a2a.d.ts +6 -0
  40. package/dist/server/handlers/a2a.js +1 -0
  41. package/dist/server/handlers/agents.cjs +7 -7
  42. package/dist/server/handlers/agents.js +1 -1
  43. package/dist/server/handlers/error.cjs +2 -2
  44. package/dist/server/handlers/error.js +1 -1
  45. package/dist/server/handlers/legacyWorkflows.cjs +46 -0
  46. package/dist/server/handlers/legacyWorkflows.d.cts +10 -0
  47. package/dist/server/handlers/legacyWorkflows.d.ts +10 -0
  48. package/dist/server/handlers/legacyWorkflows.js +1 -0
  49. package/dist/server/handlers/logs.cjs +4 -4
  50. package/dist/server/handlers/logs.js +1 -1
  51. package/dist/server/handlers/memory.cjs +9 -9
  52. package/dist/server/handlers/memory.js +1 -1
  53. package/dist/server/handlers/network.cjs +5 -5
  54. package/dist/server/handlers/network.js +1 -1
  55. package/dist/server/handlers/telemetry.cjs +3 -3
  56. package/dist/server/handlers/telemetry.js +1 -1
  57. package/dist/server/handlers/tools.cjs +5 -5
  58. package/dist/server/handlers/tools.js +1 -1
  59. package/dist/server/handlers/utils.cjs +2 -2
  60. package/dist/server/handlers/utils.js +1 -1
  61. package/dist/server/handlers/vector.cjs +7 -7
  62. package/dist/server/handlers/vector.js +1 -1
  63. package/dist/server/handlers/voice.cjs +8 -4
  64. package/dist/server/handlers/voice.d.cts +1 -0
  65. package/dist/server/handlers/voice.d.ts +1 -0
  66. package/dist/server/handlers/voice.js +1 -1
  67. package/dist/server/handlers/workflows.cjs +21 -13
  68. package/dist/server/handlers/workflows.d.cts +4 -2
  69. package/dist/server/handlers/workflows.d.ts +4 -2
  70. package/dist/server/handlers/workflows.js +1 -1
  71. package/dist/server/handlers.cjs +33 -23
  72. package/dist/server/handlers.d.cts +2 -0
  73. package/dist/server/handlers.d.ts +2 -0
  74. package/dist/server/handlers.js +11 -9
  75. package/package.json +14 -13
  76. package/dist/chunk-2JQC6JWP.js +0 -46
  77. package/dist/chunk-5JOF627H.cjs +0 -123
  78. package/dist/chunk-A7DF4ETD.cjs +0 -100
  79. package/dist/chunk-BMA2ORRT.js +0 -152
  80. package/dist/chunk-GV52BII2.cjs +0 -160
  81. package/dist/chunk-QH6XWSXP.cjs +0 -5579
  82. package/dist/chunk-VB7KH62D.cjs +0 -51
  83. package/dist/chunk-VK6FX47H.js +0 -5576
  84. package/dist/chunk-X37I6GZT.cjs +0 -308
@@ -0,0 +1,457 @@
1
+ import { stringify, esm_default } from './chunk-TGJMNUYJ.js';
2
+ import { handleError } from './chunk-M5ABIP7D.js';
3
+ import { HTTPException } from './chunk-NYN7KFXL.js';
4
+ import { __export } from './chunk-MLKGABMK.js';
5
+ import { ReadableStream } from 'stream/web';
6
+ import { RuntimeContext } from '@mastra/core/di';
7
+
8
+ // src/server/handlers/workflows.ts
9
+ var workflows_exports = {};
10
+ __export(workflows_exports, {
11
+ createWorkflowRunHandler: () => createWorkflowRunHandler,
12
+ getWorkflowByIdHandler: () => getWorkflowByIdHandler,
13
+ getWorkflowRunByIdHandler: () => getWorkflowRunByIdHandler,
14
+ getWorkflowRunExecutionResultHandler: () => getWorkflowRunExecutionResultHandler,
15
+ getWorkflowRunsHandler: () => getWorkflowRunsHandler,
16
+ getWorkflowsHandler: () => getWorkflowsHandler,
17
+ resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
18
+ resumeWorkflowHandler: () => resumeWorkflowHandler,
19
+ startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
20
+ startWorkflowRunHandler: () => startWorkflowRunHandler,
21
+ streamWorkflowHandler: () => streamWorkflowHandler,
22
+ watchWorkflowHandler: () => watchWorkflowHandler
23
+ });
24
+ async function getWorkflowsHandler({ mastra }) {
25
+ try {
26
+ const workflows = mastra.getWorkflows({ serialized: false });
27
+ const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
28
+ acc[key] = {
29
+ name: workflow.name,
30
+ description: workflow.description,
31
+ steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
32
+ acc2[key2] = {
33
+ id: step.id,
34
+ description: step.description,
35
+ inputSchema: step.inputSchema ? stringify(esm_default(step.inputSchema)) : void 0,
36
+ outputSchema: step.outputSchema ? stringify(esm_default(step.outputSchema)) : void 0,
37
+ resumeSchema: step.resumeSchema ? stringify(esm_default(step.resumeSchema)) : void 0,
38
+ suspendSchema: step.suspendSchema ? stringify(esm_default(step.suspendSchema)) : void 0
39
+ };
40
+ return acc2;
41
+ }, {}),
42
+ stepGraph: workflow.serializedStepGraph,
43
+ inputSchema: workflow.inputSchema ? stringify(esm_default(workflow.inputSchema)) : void 0,
44
+ outputSchema: workflow.outputSchema ? stringify(esm_default(workflow.outputSchema)) : void 0
45
+ };
46
+ return acc;
47
+ }, {});
48
+ return _workflows;
49
+ } catch (error) {
50
+ throw new HTTPException(500, { message: error?.message || "Error getting workflows" });
51
+ }
52
+ }
53
+ async function getWorkflowsFromSystem({ mastra, workflowId }) {
54
+ const logger = mastra.getLogger();
55
+ if (!workflowId) {
56
+ throw new HTTPException(400, { message: "Workflow ID is required" });
57
+ }
58
+ let workflow;
59
+ try {
60
+ workflow = mastra.getWorkflow(workflowId);
61
+ } catch (error) {
62
+ logger.debug("Error getting workflow, searching agents for workflow", error);
63
+ }
64
+ if (!workflow) {
65
+ logger.debug("Workflow not found, searching agents for workflow", { workflowId });
66
+ const agents = mastra.getAgents();
67
+ if (Object.keys(agents || {}).length) {
68
+ for (const [_, agent] of Object.entries(agents)) {
69
+ try {
70
+ const workflows = await agent.getWorkflows();
71
+ if (workflows[workflowId]) {
72
+ workflow = workflows[workflowId];
73
+ break;
74
+ }
75
+ break;
76
+ } catch (error) {
77
+ logger.debug("Error getting workflow from agent", error);
78
+ }
79
+ }
80
+ }
81
+ }
82
+ if (!workflow) {
83
+ throw new HTTPException(404, { message: "Workflow not found" });
84
+ }
85
+ return { workflow };
86
+ }
87
+ async function getWorkflowByIdHandler({ mastra, workflowId }) {
88
+ try {
89
+ if (!workflowId) {
90
+ throw new HTTPException(400, { message: "Workflow ID is required" });
91
+ }
92
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
93
+ if (!workflow) {
94
+ throw new HTTPException(404, { message: "Workflow not found" });
95
+ }
96
+ return {
97
+ steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
98
+ acc[key] = {
99
+ id: step.id,
100
+ description: step.description,
101
+ inputSchema: step.inputSchema ? stringify(esm_default(step.inputSchema)) : void 0,
102
+ outputSchema: step.outputSchema ? stringify(esm_default(step.outputSchema)) : void 0,
103
+ resumeSchema: step.resumeSchema ? stringify(esm_default(step.resumeSchema)) : void 0,
104
+ suspendSchema: step.suspendSchema ? stringify(esm_default(step.suspendSchema)) : void 0
105
+ };
106
+ return acc;
107
+ }, {}),
108
+ name: workflow.name,
109
+ description: workflow.description,
110
+ stepGraph: workflow.serializedStepGraph,
111
+ inputSchema: workflow.inputSchema ? stringify(esm_default(workflow.inputSchema)) : void 0,
112
+ outputSchema: workflow.outputSchema ? stringify(esm_default(workflow.outputSchema)) : void 0
113
+ };
114
+ } catch (error) {
115
+ throw new HTTPException(500, { message: error?.message || "Error getting workflow" });
116
+ }
117
+ }
118
+ async function getWorkflowRunByIdHandler({
119
+ mastra,
120
+ workflowId,
121
+ runId
122
+ }) {
123
+ try {
124
+ if (!workflowId) {
125
+ throw new HTTPException(400, { message: "Workflow ID is required" });
126
+ }
127
+ if (!runId) {
128
+ throw new HTTPException(400, { message: "Run ID is required" });
129
+ }
130
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
131
+ if (!workflow) {
132
+ throw new HTTPException(404, { message: "Workflow not found" });
133
+ }
134
+ const run = await workflow.getWorkflowRunById(runId);
135
+ if (!run) {
136
+ throw new HTTPException(404, { message: "Workflow run not found" });
137
+ }
138
+ return run;
139
+ } catch (error) {
140
+ throw new HTTPException(500, { message: error?.message || "Error getting workflow run" });
141
+ }
142
+ }
143
+ async function getWorkflowRunExecutionResultHandler({
144
+ mastra,
145
+ workflowId,
146
+ runId
147
+ }) {
148
+ try {
149
+ if (!workflowId) {
150
+ throw new HTTPException(400, { message: "Workflow ID is required" });
151
+ }
152
+ if (!runId) {
153
+ throw new HTTPException(400, { message: "Run ID is required" });
154
+ }
155
+ const workflow = mastra.getWorkflow(workflowId);
156
+ if (!workflow) {
157
+ throw new HTTPException(404, { message: "Workflow not found" });
158
+ }
159
+ const executionResult = await workflow.getWorkflowRunExecutionResult(runId);
160
+ if (!executionResult) {
161
+ throw new HTTPException(404, { message: "Workflow run execution result not found" });
162
+ }
163
+ return executionResult;
164
+ } catch (error) {
165
+ throw new HTTPException(500, {
166
+ message: error?.message || "Error getting workflow run execution result"
167
+ });
168
+ }
169
+ }
170
+ async function createWorkflowRunHandler({
171
+ mastra,
172
+ workflowId,
173
+ runId: prevRunId
174
+ }) {
175
+ try {
176
+ if (!workflowId) {
177
+ throw new HTTPException(400, { message: "Workflow ID is required" });
178
+ }
179
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
180
+ if (!workflow) {
181
+ throw new HTTPException(404, { message: "Workflow not found" });
182
+ }
183
+ const run = workflow.createRun({ runId: prevRunId });
184
+ return { runId: run.runId };
185
+ } catch (error) {
186
+ throw new HTTPException(500, { message: error?.message || "Error creating workflow run" });
187
+ }
188
+ }
189
+ async function startAsyncWorkflowHandler({
190
+ mastra,
191
+ runtimeContext: payloadRuntimeContext,
192
+ workflowId,
193
+ runId,
194
+ inputData
195
+ }) {
196
+ try {
197
+ if (!workflowId) {
198
+ throw new HTTPException(400, { message: "Workflow ID is required" });
199
+ }
200
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
201
+ if (!workflow) {
202
+ throw new HTTPException(404, { message: "Workflow not found" });
203
+ }
204
+ let runtimeContext;
205
+ if (payloadRuntimeContext) {
206
+ runtimeContext = new RuntimeContext();
207
+ Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
208
+ runtimeContext.set(key, value);
209
+ });
210
+ }
211
+ const _run = workflow.createRun({ runId });
212
+ const result = await _run.start({
213
+ inputData,
214
+ runtimeContext
215
+ });
216
+ return result;
217
+ } catch (error) {
218
+ throw new HTTPException(500, { message: error?.message || "Error executing workflow" });
219
+ }
220
+ }
221
+ async function startWorkflowRunHandler({
222
+ mastra,
223
+ runtimeContext: payloadRuntimeContext,
224
+ workflowId,
225
+ runId,
226
+ inputData
227
+ }) {
228
+ try {
229
+ if (!workflowId) {
230
+ throw new HTTPException(400, { message: "Workflow ID is required" });
231
+ }
232
+ if (!runId) {
233
+ throw new HTTPException(400, { message: "runId required to start run" });
234
+ }
235
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
236
+ if (!workflow) {
237
+ throw new HTTPException(404, { message: "Workflow not found" });
238
+ }
239
+ const run = await workflow.getWorkflowRunById(runId);
240
+ if (!run) {
241
+ throw new HTTPException(404, { message: "Workflow run not found" });
242
+ }
243
+ let runtimeContext;
244
+ if (payloadRuntimeContext) {
245
+ runtimeContext = new RuntimeContext();
246
+ Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
247
+ runtimeContext.set(key, value);
248
+ });
249
+ }
250
+ const _run = workflow.createRun({ runId });
251
+ void _run.start({
252
+ inputData,
253
+ runtimeContext
254
+ });
255
+ return { message: "Workflow run started" };
256
+ } catch (e) {
257
+ return handleError(e, "Error starting workflow run");
258
+ }
259
+ }
260
+ async function watchWorkflowHandler({
261
+ mastra,
262
+ workflowId,
263
+ runId
264
+ }) {
265
+ try {
266
+ if (!workflowId) {
267
+ throw new HTTPException(400, { message: "Workflow ID is required" });
268
+ }
269
+ if (!runId) {
270
+ throw new HTTPException(400, { message: "runId required to watch workflow" });
271
+ }
272
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
273
+ if (!workflow) {
274
+ throw new HTTPException(404, { message: "Workflow not found" });
275
+ }
276
+ const run = await workflow.getWorkflowRunById(runId);
277
+ if (!run) {
278
+ throw new HTTPException(404, { message: "Workflow run not found" });
279
+ }
280
+ const _run = workflow.createRun({ runId });
281
+ let unwatch;
282
+ let asyncRef = null;
283
+ const stream = new ReadableStream({
284
+ start(controller) {
285
+ unwatch = _run.watch(({ type, payload, eventTimestamp }) => {
286
+ controller.enqueue(JSON.stringify({ type, payload, eventTimestamp, runId }));
287
+ if (asyncRef) {
288
+ clearImmediate(asyncRef);
289
+ asyncRef = null;
290
+ }
291
+ asyncRef = setImmediate(async () => {
292
+ const runDone = payload.workflowState.status !== "running";
293
+ if (runDone) {
294
+ controller.close();
295
+ unwatch?.();
296
+ }
297
+ });
298
+ });
299
+ },
300
+ cancel() {
301
+ unwatch?.();
302
+ }
303
+ });
304
+ return stream;
305
+ } catch (error) {
306
+ return handleError(error, "Error watching workflow");
307
+ }
308
+ }
309
+ async function streamWorkflowHandler({
310
+ mastra,
311
+ runtimeContext: payloadRuntimeContext,
312
+ workflowId,
313
+ runId,
314
+ inputData
315
+ }) {
316
+ try {
317
+ if (!workflowId) {
318
+ throw new HTTPException(400, { message: "Workflow ID is required" });
319
+ }
320
+ if (!runId) {
321
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
322
+ }
323
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
324
+ if (!workflow) {
325
+ throw new HTTPException(404, { message: "Workflow not found" });
326
+ }
327
+ let runtimeContext;
328
+ if (payloadRuntimeContext) {
329
+ runtimeContext = new RuntimeContext();
330
+ Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
331
+ runtimeContext.set(key, value);
332
+ });
333
+ }
334
+ const run = workflow.createRun({ runId });
335
+ const result = run.stream({
336
+ inputData,
337
+ runtimeContext
338
+ });
339
+ return result;
340
+ } catch (error) {
341
+ return handleError(error, "Error executing workflow");
342
+ }
343
+ }
344
+ async function resumeAsyncWorkflowHandler({
345
+ mastra,
346
+ workflowId,
347
+ runId,
348
+ body,
349
+ runtimeContext: payloadRuntimeContext
350
+ }) {
351
+ try {
352
+ if (!workflowId) {
353
+ throw new HTTPException(400, { message: "Workflow ID is required" });
354
+ }
355
+ if (!runId) {
356
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
357
+ }
358
+ if (!body.step) {
359
+ throw new HTTPException(400, { message: "step required to resume workflow" });
360
+ }
361
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
362
+ if (!workflow) {
363
+ throw new HTTPException(404, { message: "Workflow not found" });
364
+ }
365
+ const run = await workflow.getWorkflowRunById(runId);
366
+ if (!run) {
367
+ throw new HTTPException(404, { message: "Workflow run not found" });
368
+ }
369
+ let runtimeContext;
370
+ if (payloadRuntimeContext) {
371
+ runtimeContext = new RuntimeContext();
372
+ Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
373
+ runtimeContext.set(key, value);
374
+ });
375
+ }
376
+ const _run = workflow.createRun({ runId });
377
+ const result = await _run.resume({
378
+ step: body.step,
379
+ resumeData: body.resumeData,
380
+ runtimeContext
381
+ });
382
+ return result;
383
+ } catch (error) {
384
+ return handleError(error, "Error resuming workflow step");
385
+ }
386
+ }
387
+ async function resumeWorkflowHandler({
388
+ mastra,
389
+ workflowId,
390
+ runId,
391
+ body,
392
+ runtimeContext: payloadRuntimeContext
393
+ }) {
394
+ try {
395
+ if (!workflowId) {
396
+ throw new HTTPException(400, { message: "Workflow ID is required" });
397
+ }
398
+ if (!runId) {
399
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
400
+ }
401
+ if (!body.step) {
402
+ throw new HTTPException(400, { message: "step required to resume workflow" });
403
+ }
404
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
405
+ if (!workflow) {
406
+ throw new HTTPException(404, { message: "Workflow not found" });
407
+ }
408
+ const run = await workflow.getWorkflowRunById(runId);
409
+ if (!run) {
410
+ throw new HTTPException(404, { message: "Workflow run not found" });
411
+ }
412
+ let runtimeContext;
413
+ if (payloadRuntimeContext) {
414
+ runtimeContext = new RuntimeContext();
415
+ Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
416
+ runtimeContext.set(key, value);
417
+ });
418
+ }
419
+ const _run = workflow.createRun({ runId });
420
+ void _run.resume({
421
+ step: body.step,
422
+ resumeData: body.resumeData,
423
+ runtimeContext
424
+ });
425
+ return { message: "Workflow run resumed" };
426
+ } catch (error) {
427
+ return handleError(error, "Error resuming workflow");
428
+ }
429
+ }
430
+ async function getWorkflowRunsHandler({
431
+ mastra,
432
+ workflowId,
433
+ fromDate,
434
+ toDate,
435
+ limit,
436
+ offset,
437
+ resourceId
438
+ }) {
439
+ try {
440
+ if (!workflowId) {
441
+ throw new HTTPException(400, { message: "Workflow ID is required" });
442
+ }
443
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
444
+ if (!workflow) {
445
+ throw new HTTPException(404, { message: "Workflow not found" });
446
+ }
447
+ const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
448
+ runs: [],
449
+ total: 0
450
+ };
451
+ return workflowRuns;
452
+ } catch (error) {
453
+ return handleError(error, "Error getting workflow runs");
454
+ }
455
+ }
456
+
457
+ export { createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunExecutionResultHandler, getWorkflowRunsHandler, getWorkflowsHandler, resumeAsyncWorkflowHandler, resumeWorkflowHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamWorkflowHandler, watchWorkflowHandler, workflows_exports };
@@ -1,4 +1,4 @@
1
- import { HTTPException } from './chunk-TRDNDNGQ.js';
1
+ import { HTTPException } from './chunk-NYN7KFXL.js';
2
2
 
3
3
  // src/server/handlers/error.ts
4
4
  function handleError(error, defaultMessage) {
@@ -0,0 +1,7 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ export { __export };
@@ -1,14 +1,15 @@
1
1
  'use strict';
2
2
 
3
- var chunkQH6XWSXP_cjs = require('./chunk-QH6XWSXP.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');
3
+ var chunkASKESBJW_cjs = require('./chunk-ASKESBJW.cjs');
4
+ var chunk57CJTIPW_cjs = require('./chunk-57CJTIPW.cjs');
5
+ var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
6
+ var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
7
+ var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
7
8
  var tools = require('@mastra/core/tools');
8
9
 
9
10
  // src/server/handlers/tools.ts
10
11
  var tools_exports = {};
11
- chunkFV45V6WC_cjs.__export(tools_exports, {
12
+ chunk75ZPJI57_cjs.__export(tools_exports, {
12
13
  executeAgentToolHandler: () => executeAgentToolHandler,
13
14
  executeToolHandler: () => executeToolHandler,
14
15
  getToolByIdHandler: () => getToolByIdHandler,
@@ -24,8 +25,8 @@ async function getToolsHandler({ tools }) {
24
25
  const tool = _tool;
25
26
  acc[id] = {
26
27
  ...tool,
27
- inputSchema: tool.inputSchema ? chunkQH6XWSXP_cjs.stringify(chunkQH6XWSXP_cjs.esm_default(tool.inputSchema)) : void 0,
28
- outputSchema: tool.outputSchema ? chunkQH6XWSXP_cjs.stringify(chunkQH6XWSXP_cjs.esm_default(tool.outputSchema)) : void 0
28
+ inputSchema: tool.inputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(tool.inputSchema)) : void 0,
29
+ outputSchema: tool.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(tool.outputSchema)) : void 0
29
30
  };
30
31
  return acc;
31
32
  },
@@ -33,23 +34,23 @@ async function getToolsHandler({ tools }) {
33
34
  );
34
35
  return serializedTools;
35
36
  } catch (error) {
36
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting tools");
37
+ return chunk64U3UDTH_cjs.handleError(error, "Error getting tools");
37
38
  }
38
39
  }
39
40
  async function getToolByIdHandler({ tools, toolId }) {
40
41
  try {
41
42
  const tool = Object.values(tools || {}).find((tool2) => tool2.id === toolId);
42
43
  if (!tool) {
43
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Tool not found" });
44
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Tool not found" });
44
45
  }
45
46
  const serializedTool = {
46
47
  ...tool,
47
- inputSchema: tool.inputSchema ? chunkQH6XWSXP_cjs.stringify(chunkQH6XWSXP_cjs.esm_default(tool.inputSchema)) : void 0,
48
- outputSchema: tool.outputSchema ? chunkQH6XWSXP_cjs.stringify(chunkQH6XWSXP_cjs.esm_default(tool.outputSchema)) : void 0
48
+ inputSchema: tool.inputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(tool.inputSchema)) : void 0,
49
+ outputSchema: tool.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(tool.outputSchema)) : void 0
49
50
  };
50
51
  return serializedTool;
51
52
  } catch (error) {
52
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting tool");
53
+ return chunk64U3UDTH_cjs.handleError(error, "Error getting tool");
53
54
  }
54
55
  }
55
56
  function executeToolHandler(tools$1) {
@@ -57,20 +58,21 @@ function executeToolHandler(tools$1) {
57
58
  mastra,
58
59
  runId,
59
60
  toolId,
60
- data
61
+ data,
62
+ runtimeContext
61
63
  }) => {
62
64
  try {
63
65
  if (!toolId) {
64
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Tool ID is required" });
66
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Tool ID is required" });
65
67
  }
66
68
  const tool = Object.values(tools$1 || {}).find((tool2) => tool2.id === toolId);
67
69
  if (!tool) {
68
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Tool not found" });
70
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Tool not found" });
69
71
  }
70
72
  if (!tool?.execute) {
71
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Tool is not executable" });
73
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Tool is not executable" });
72
74
  }
73
- chunkQN4KF3BH_cjs.validateBody({ data });
75
+ chunk57CJTIPW_cjs.validateBody({ data });
74
76
  if (tools.isVercelTool(tool)) {
75
77
  const result2 = await tool.execute(data);
76
78
  return result2;
@@ -78,11 +80,12 @@ function executeToolHandler(tools$1) {
78
80
  const result = await tool.execute({
79
81
  context: data,
80
82
  mastra,
81
- runId
83
+ runId,
84
+ runtimeContext
82
85
  });
83
86
  return result;
84
87
  } catch (error) {
85
- return chunkZLBRQFDD_cjs.handleError(error, "Error executing tool");
88
+ return chunk64U3UDTH_cjs.handleError(error, "Error executing tool");
86
89
  }
87
90
  };
88
91
  }
@@ -90,28 +93,31 @@ async function executeAgentToolHandler({
90
93
  mastra,
91
94
  agentId,
92
95
  toolId,
93
- data
96
+ data,
97
+ runtimeContext
94
98
  }) {
95
99
  try {
96
100
  const agent = agentId ? mastra.getAgent(agentId) : null;
97
101
  if (!agent) {
98
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Tool not found" });
102
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Tool not found" });
99
103
  }
100
- const tool = Object.values(agent?.tools || {}).find((tool2) => tool2.id === toolId);
104
+ const agentTools = await agent.getTools({ runtimeContext });
105
+ const tool = Object.values(agentTools || {}).find((tool2) => tool2.id === toolId);
101
106
  if (!tool) {
102
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Tool not found" });
107
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Tool not found" });
103
108
  }
104
109
  if (!tool?.execute) {
105
- throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Tool is not executable" });
110
+ throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Tool is not executable" });
106
111
  }
107
112
  const result = await tool.execute({
108
113
  context: data,
114
+ runtimeContext,
109
115
  mastra,
110
116
  runId: agentId
111
117
  });
112
118
  return result;
113
119
  } catch (error) {
114
- return chunkZLBRQFDD_cjs.handleError(error, "Error executing tool");
120
+ return chunk64U3UDTH_cjs.handleError(error, "Error executing tool");
115
121
  }
116
122
  }
117
123
 
@@ -1,9 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
1
  // src/server/http-exception.ts
8
2
  var HTTPException = class extends Error {
9
3
  res;
@@ -37,4 +31,4 @@ var HTTPException = class extends Error {
37
31
  }
38
32
  };
39
33
 
40
- export { HTTPException, __export };
34
+ export { HTTPException };
@@ -1,11 +1,5 @@
1
1
  'use strict';
2
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
3
  // src/server/http-exception.ts
10
4
  var HTTPException = class extends Error {
11
5
  res;
@@ -40,4 +34,3 @@ var HTTPException = class extends Error {
40
34
  };
41
35
 
42
36
  exports.HTTPException = HTTPException;
43
- exports.__export = __export;