@mastra/server 0.0.0-fix-bundle-cleanup-20250911062914 → 0.0.0-fix-cloud-peer-deps-20250929-20250929175756
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.
- package/CHANGELOG.md +241 -4
- package/README.md +0 -5
- package/dist/{chunk-L265APUD.cjs → chunk-52UP7DFT.cjs} +64 -3
- package/dist/chunk-52UP7DFT.cjs.map +1 -0
- package/dist/{chunk-5QUKZCEF.js → chunk-6IJWRJZE.js} +4 -3
- package/dist/chunk-6IJWRJZE.js.map +1 -0
- package/dist/{chunk-GUI3CROV.cjs → chunk-BKCWZLEL.cjs} +60 -22
- package/dist/chunk-BKCWZLEL.cjs.map +1 -0
- package/dist/{chunk-DMSCGAWM.js → chunk-BOVFMBXY.js} +92 -9
- package/dist/chunk-BOVFMBXY.js.map +1 -0
- package/dist/{chunk-6LUKYSWE.cjs → chunk-CML3EOO5.cjs} +96 -119
- package/dist/chunk-CML3EOO5.cjs.map +1 -0
- package/dist/{chunk-A75S4TDD.js → chunk-JRDEOHAJ.js} +19 -11
- package/dist/chunk-JRDEOHAJ.js.map +1 -0
- package/dist/{chunk-SYRRSBGL.js → chunk-KM7EJKXV.js} +8 -4
- package/dist/chunk-KM7EJKXV.js.map +1 -0
- package/dist/{chunk-J7BPKKOG.cjs → chunk-LJFAAEU7.cjs} +8 -4
- package/dist/chunk-LJFAAEU7.cjs.map +1 -0
- package/dist/{chunk-OTU37YZO.js → chunk-N5ID53SA.js} +172 -131
- package/dist/chunk-N5ID53SA.js.map +1 -0
- package/dist/{chunk-B2V3PUB7.js → chunk-NH7XUTIO.js} +93 -116
- package/dist/chunk-NH7XUTIO.js.map +1 -0
- package/dist/{chunk-WZC6CIVD.cjs → chunk-NLWACBE7.cjs} +19 -11
- package/dist/chunk-NLWACBE7.cjs.map +1 -0
- package/dist/{chunk-3THIIWWW.cjs → chunk-OPI3FZYH.cjs} +4 -3
- package/dist/chunk-OPI3FZYH.cjs.map +1 -0
- package/dist/{chunk-2JEDATG5.cjs → chunk-QNWXF57L.cjs} +191 -150
- package/dist/chunk-QNWXF57L.cjs.map +1 -0
- package/dist/{chunk-3TETONBL.cjs → chunk-SXENNNR7.cjs} +93 -8
- package/dist/chunk-SXENNNR7.cjs.map +1 -0
- package/dist/chunk-VY4ENABS.cjs +135 -0
- package/dist/chunk-VY4ENABS.cjs.map +1 -0
- package/dist/{chunk-R7NOGUZG.js → chunk-WUJLVNLU.js} +63 -4
- package/dist/chunk-WUJLVNLU.js.map +1 -0
- package/dist/{chunk-7QEJ5QG5.js → chunk-XJOYGRTN.js} +60 -22
- package/dist/chunk-XJOYGRTN.js.map +1 -0
- package/dist/chunk-YWOK4F5A.js +131 -0
- package/dist/chunk-YWOK4F5A.js.map +1 -0
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/server/handlers/a2a.cjs +7 -7
- package/dist/server/handlers/a2a.d.ts.map +1 -1
- package/dist/server/handlers/a2a.js +1 -1
- package/dist/server/handlers/agent-builder.cjs +16 -16
- package/dist/server/handlers/agent-builder.d.ts +5 -4
- package/dist/server/handlers/agent-builder.d.ts.map +1 -1
- package/dist/server/handlers/agent-builder.js +1 -1
- package/dist/server/handlers/agents.cjs +23 -15
- package/dist/server/handlers/agents.d.ts +51 -5
- package/dist/server/handlers/agents.d.ts.map +1 -1
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/observability.cjs +11 -3
- package/dist/server/handlers/observability.d.ts +27 -1
- package/dist/server/handlers/observability.d.ts.map +1 -1
- package/dist/server/handlers/observability.js +1 -1
- package/dist/server/handlers/scores.cjs +7 -7
- package/dist/server/handlers/scores.d.ts +208 -6
- package/dist/server/handlers/scores.d.ts.map +1 -1
- package/dist/server/handlers/scores.js +1 -1
- package/dist/server/handlers/tools.cjs +6 -6
- package/dist/server/handlers/tools.d.ts.map +1 -1
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/vNextNetwork.d.ts +73 -6
- package/dist/server/handlers/vNextNetwork.d.ts.map +1 -1
- package/dist/server/handlers/voice.cjs +5 -5
- package/dist/server/handlers/voice.d.ts +6 -4
- package/dist/server/handlers/voice.d.ts.map +1 -1
- package/dist/server/handlers/voice.js +1 -1
- package/dist/server/handlers/workflows.cjs +24 -16
- package/dist/server/handlers/workflows.d.ts +16 -7
- package/dist/server/handlers/workflows.d.ts.map +1 -1
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +16 -21
- package/dist/server/handlers.d.ts +0 -1
- package/dist/server/handlers.d.ts.map +1 -1
- package/dist/server/handlers.js +8 -9
- package/dist/server/utils.d.ts +2 -0
- package/dist/server/utils.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/chunk-2JEDATG5.cjs.map +0 -1
- package/dist/chunk-3TETONBL.cjs.map +0 -1
- package/dist/chunk-3THIIWWW.cjs.map +0 -1
- package/dist/chunk-5QUKZCEF.js.map +0 -1
- package/dist/chunk-6LUKYSWE.cjs.map +0 -1
- package/dist/chunk-7QEJ5QG5.js.map +0 -1
- package/dist/chunk-A75S4TDD.js.map +0 -1
- package/dist/chunk-B2V3PUB7.js.map +0 -1
- package/dist/chunk-DMSCGAWM.js.map +0 -1
- package/dist/chunk-GUI3CROV.cjs.map +0 -1
- package/dist/chunk-IY34NOLA.cjs +0 -150
- package/dist/chunk-IY34NOLA.cjs.map +0 -1
- package/dist/chunk-J7BPKKOG.cjs.map +0 -1
- package/dist/chunk-L265APUD.cjs.map +0 -1
- package/dist/chunk-OTU37YZO.js.map +0 -1
- package/dist/chunk-R7NOGUZG.js.map +0 -1
- package/dist/chunk-SYRRSBGL.js.map +0 -1
- package/dist/chunk-U46VIX2V.js +0 -144
- package/dist/chunk-U46VIX2V.js.map +0 -1
- package/dist/chunk-WZC6CIVD.cjs.map +0 -1
- package/dist/server/handlers/network.cjs +0 -24
- package/dist/server/handlers/network.cjs.map +0 -1
- package/dist/server/handlers/network.d.ts +0 -50
- package/dist/server/handlers/network.d.ts.map +0 -1
- package/dist/server/handlers/network.js +0 -3
- package/dist/server/handlers/network.js.map +0 -1
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkVY4ENABS_cjs = require('./chunk-VY4ENABS.cjs');
|
|
4
4
|
var chunkRE4RPXT2_cjs = require('./chunk-RE4RPXT2.cjs');
|
|
5
5
|
var chunk7NADHFD2_cjs = require('./chunk-7NADHFD2.cjs');
|
|
6
6
|
var chunkEMMSS5I5_cjs = require('./chunk-EMMSS5I5.cjs');
|
|
7
7
|
var web = require('stream/web');
|
|
8
|
-
var zodToJson = require('@mastra/core/utils/zod-to-json');
|
|
9
8
|
|
|
10
9
|
// src/server/handlers/workflows.ts
|
|
11
10
|
var workflows_exports = {};
|
|
@@ -17,7 +16,9 @@ chunkEMMSS5I5_cjs.__export(workflows_exports, {
|
|
|
17
16
|
getWorkflowRunExecutionResultHandler: () => getWorkflowRunExecutionResultHandler,
|
|
18
17
|
getWorkflowRunsHandler: () => getWorkflowRunsHandler,
|
|
19
18
|
getWorkflowsHandler: () => getWorkflowsHandler,
|
|
19
|
+
observeStreamWorkflowHandler: () => observeStreamWorkflowHandler,
|
|
20
20
|
resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
|
|
21
|
+
resumeStreamWorkflowHandler: () => resumeStreamWorkflowHandler,
|
|
21
22
|
resumeWorkflowHandler: () => resumeWorkflowHandler,
|
|
22
23
|
sendWorkflowRunEventHandler: () => sendWorkflowRunEventHandler,
|
|
23
24
|
startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
|
|
@@ -26,118 +27,11 @@ chunkEMMSS5I5_cjs.__export(workflows_exports, {
|
|
|
26
27
|
streamWorkflowHandler: () => streamWorkflowHandler,
|
|
27
28
|
watchWorkflowHandler: () => watchWorkflowHandler
|
|
28
29
|
});
|
|
29
|
-
function getSteps(steps, path) {
|
|
30
|
-
return Object.entries(steps).reduce((acc, [key, step]) => {
|
|
31
|
-
const fullKey = path ? `${path}.${key}` : key;
|
|
32
|
-
acc[fullKey] = {
|
|
33
|
-
id: step.id,
|
|
34
|
-
description: step.description,
|
|
35
|
-
inputSchema: step.inputSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(step.inputSchema)) : void 0,
|
|
36
|
-
outputSchema: step.outputSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(step.outputSchema)) : void 0,
|
|
37
|
-
resumeSchema: step.resumeSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(step.resumeSchema)) : void 0,
|
|
38
|
-
suspendSchema: step.suspendSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(step.suspendSchema)) : void 0,
|
|
39
|
-
isWorkflow: step.component === "WORKFLOW"
|
|
40
|
-
};
|
|
41
|
-
if (step.component === "WORKFLOW" && step.steps) {
|
|
42
|
-
const nestedSteps = getSteps(step.steps, fullKey) || {};
|
|
43
|
-
acc = { ...acc, ...nestedSteps };
|
|
44
|
-
}
|
|
45
|
-
return acc;
|
|
46
|
-
}, {});
|
|
47
|
-
}
|
|
48
|
-
function getWorkflowInfo(workflow) {
|
|
49
|
-
return {
|
|
50
|
-
name: workflow.name,
|
|
51
|
-
description: workflow.description,
|
|
52
|
-
steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
|
|
53
|
-
acc[key] = {
|
|
54
|
-
id: step.id,
|
|
55
|
-
description: step.description,
|
|
56
|
-
inputSchema: step.inputSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(step.inputSchema)) : void 0,
|
|
57
|
-
outputSchema: step.outputSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(step.outputSchema)) : void 0,
|
|
58
|
-
resumeSchema: step.resumeSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(step.resumeSchema)) : void 0,
|
|
59
|
-
suspendSchema: step.suspendSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(step.suspendSchema)) : void 0
|
|
60
|
-
};
|
|
61
|
-
return acc;
|
|
62
|
-
}, {}),
|
|
63
|
-
allSteps: getSteps(workflow.steps) || {},
|
|
64
|
-
stepGraph: workflow.serializedStepGraph,
|
|
65
|
-
inputSchema: workflow.inputSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(workflow.inputSchema)) : void 0,
|
|
66
|
-
outputSchema: workflow.outputSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(workflow.outputSchema)) : void 0
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
var WorkflowRegistry = class {
|
|
70
|
-
static additionalWorkflows = {};
|
|
71
|
-
/**
|
|
72
|
-
* Register a workflow temporarily
|
|
73
|
-
*/
|
|
74
|
-
static registerTemporaryWorkflow(id, workflow) {
|
|
75
|
-
this.additionalWorkflows[id] = workflow;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Register all workflows from map
|
|
79
|
-
*/
|
|
80
|
-
static registerTemporaryWorkflows(workflows, mastra) {
|
|
81
|
-
for (const [id, workflow] of Object.entries(workflows)) {
|
|
82
|
-
if (mastra) {
|
|
83
|
-
workflow.__registerMastra(mastra);
|
|
84
|
-
workflow.__registerPrimitives({
|
|
85
|
-
logger: mastra.getLogger(),
|
|
86
|
-
telemetry: mastra.getTelemetry(),
|
|
87
|
-
storage: mastra.getStorage(),
|
|
88
|
-
memory: mastra.getMemory(),
|
|
89
|
-
agents: mastra.getAgents(),
|
|
90
|
-
tts: mastra.getTTS(),
|
|
91
|
-
vectors: mastra.getVectors()
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
this.additionalWorkflows[id] = workflow;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Get a workflow by ID from the registry (returns undefined if not found)
|
|
99
|
-
*/
|
|
100
|
-
static getWorkflow(workflowId) {
|
|
101
|
-
return this.additionalWorkflows[workflowId];
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Get all workflows from the registry
|
|
105
|
-
*/
|
|
106
|
-
static getAllWorkflows() {
|
|
107
|
-
return { ...this.additionalWorkflows };
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Clean up a temporary workflow
|
|
111
|
-
*/
|
|
112
|
-
static cleanupTemporaryWorkflow(workflowId) {
|
|
113
|
-
delete this.additionalWorkflows[workflowId];
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Clean up all registered workflows
|
|
117
|
-
*/
|
|
118
|
-
static cleanup() {
|
|
119
|
-
this.additionalWorkflows = {};
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Check if a workflow ID is a valid agent-builder workflow
|
|
123
|
-
*/
|
|
124
|
-
static isAgentBuilderWorkflow(workflowId) {
|
|
125
|
-
return workflowId in this.additionalWorkflows;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Get all registered temporary workflow IDs (for debugging)
|
|
129
|
-
*/
|
|
130
|
-
static getRegisteredWorkflowIds() {
|
|
131
|
-
return Object.keys(this.additionalWorkflows);
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
// src/server/handlers/workflows.ts
|
|
136
30
|
async function getWorkflowsHandler({ mastra }) {
|
|
137
31
|
try {
|
|
138
32
|
const workflows = mastra.getWorkflows({ serialized: false });
|
|
139
33
|
const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
|
|
140
|
-
acc[key] = getWorkflowInfo(workflow);
|
|
34
|
+
acc[key] = chunkVY4ENABS_cjs.getWorkflowInfo(workflow);
|
|
141
35
|
return acc;
|
|
142
36
|
}, {});
|
|
143
37
|
return _workflows;
|
|
@@ -151,7 +45,7 @@ async function getWorkflowsFromSystem({ mastra, workflowId }) {
|
|
|
151
45
|
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
152
46
|
}
|
|
153
47
|
let workflow;
|
|
154
|
-
workflow = WorkflowRegistry.getWorkflow(workflowId);
|
|
48
|
+
workflow = chunkVY4ENABS_cjs.WorkflowRegistry.getWorkflow(workflowId);
|
|
155
49
|
if (!workflow) {
|
|
156
50
|
try {
|
|
157
51
|
workflow = mastra.getWorkflow(workflowId);
|
|
@@ -191,7 +85,7 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
|
|
|
191
85
|
if (!workflow) {
|
|
192
86
|
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
193
87
|
}
|
|
194
|
-
return getWorkflowInfo(workflow);
|
|
88
|
+
return chunkVY4ENABS_cjs.getWorkflowInfo(workflow);
|
|
195
89
|
} catch (error) {
|
|
196
90
|
return chunkRE4RPXT2_cjs.handleError(error, "Error getting workflow");
|
|
197
91
|
}
|
|
@@ -395,22 +289,68 @@ async function streamWorkflowHandler({
|
|
|
395
289
|
if (!workflow) {
|
|
396
290
|
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
397
291
|
}
|
|
292
|
+
const serverCache = mastra.getServerCache();
|
|
398
293
|
const run = await workflow.createRunAsync({ runId });
|
|
399
294
|
const result = run.stream({
|
|
400
295
|
inputData,
|
|
401
|
-
runtimeContext
|
|
296
|
+
runtimeContext,
|
|
297
|
+
onChunk: async (chunk) => {
|
|
298
|
+
if (serverCache) {
|
|
299
|
+
const cacheKey = runId;
|
|
300
|
+
await serverCache.listPush(cacheKey, chunk);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
402
303
|
});
|
|
403
304
|
return result;
|
|
404
305
|
} catch (error) {
|
|
405
306
|
return chunkRE4RPXT2_cjs.handleError(error, "Error executing workflow");
|
|
406
307
|
}
|
|
407
308
|
}
|
|
309
|
+
async function observeStreamWorkflowHandler({
|
|
310
|
+
mastra,
|
|
311
|
+
workflowId,
|
|
312
|
+
runId
|
|
313
|
+
}) {
|
|
314
|
+
try {
|
|
315
|
+
if (!workflowId) {
|
|
316
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
317
|
+
}
|
|
318
|
+
if (!runId) {
|
|
319
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "runId required to observe workflow stream" });
|
|
320
|
+
}
|
|
321
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
322
|
+
if (!workflow) {
|
|
323
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
324
|
+
}
|
|
325
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
326
|
+
if (!run) {
|
|
327
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
328
|
+
}
|
|
329
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
330
|
+
const serverCache = mastra.getServerCache();
|
|
331
|
+
if (!serverCache) {
|
|
332
|
+
throw new chunk7NADHFD2_cjs.HTTPException(500, { message: "Server cache not found" });
|
|
333
|
+
}
|
|
334
|
+
const transformStream = new web.TransformStream();
|
|
335
|
+
const writer = transformStream.writable.getWriter();
|
|
336
|
+
const cachedRunChunks = await serverCache.listFromTo(runId, 0);
|
|
337
|
+
for (const chunk of cachedRunChunks) {
|
|
338
|
+
await writer.write(chunk);
|
|
339
|
+
}
|
|
340
|
+
writer.releaseLock();
|
|
341
|
+
const result = _run.observeStream();
|
|
342
|
+
return result.stream?.pipeThrough(transformStream);
|
|
343
|
+
} catch (error) {
|
|
344
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error observing workflow stream");
|
|
345
|
+
}
|
|
346
|
+
}
|
|
408
347
|
async function streamVNextWorkflowHandler({
|
|
409
348
|
mastra,
|
|
410
349
|
runtimeContext,
|
|
411
350
|
workflowId,
|
|
412
351
|
runId,
|
|
413
|
-
inputData
|
|
352
|
+
inputData,
|
|
353
|
+
closeOnSuspend
|
|
414
354
|
}) {
|
|
415
355
|
try {
|
|
416
356
|
if (!workflowId) {
|
|
@@ -426,7 +366,8 @@ async function streamVNextWorkflowHandler({
|
|
|
426
366
|
const run = await workflow.createRunAsync({ runId });
|
|
427
367
|
const result = run.streamVNext({
|
|
428
368
|
inputData,
|
|
429
|
-
runtimeContext
|
|
369
|
+
runtimeContext,
|
|
370
|
+
closeOnSuspend
|
|
430
371
|
});
|
|
431
372
|
return result;
|
|
432
373
|
} catch (error) {
|
|
@@ -505,6 +446,42 @@ async function resumeWorkflowHandler({
|
|
|
505
446
|
return chunkRE4RPXT2_cjs.handleError(error, "Error resuming workflow");
|
|
506
447
|
}
|
|
507
448
|
}
|
|
449
|
+
async function resumeStreamWorkflowHandler({
|
|
450
|
+
mastra,
|
|
451
|
+
workflowId,
|
|
452
|
+
runId,
|
|
453
|
+
body,
|
|
454
|
+
runtimeContext
|
|
455
|
+
}) {
|
|
456
|
+
try {
|
|
457
|
+
if (!workflowId) {
|
|
458
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
459
|
+
}
|
|
460
|
+
if (!runId) {
|
|
461
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "runId required to resume workflow" });
|
|
462
|
+
}
|
|
463
|
+
if (!body.step) {
|
|
464
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "step required to resume workflow" });
|
|
465
|
+
}
|
|
466
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
467
|
+
if (!workflow) {
|
|
468
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
469
|
+
}
|
|
470
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
471
|
+
if (!run) {
|
|
472
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
473
|
+
}
|
|
474
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
475
|
+
const stream = await _run.resumeStreamVNext({
|
|
476
|
+
step: body.step,
|
|
477
|
+
resumeData: body.resumeData,
|
|
478
|
+
runtimeContext
|
|
479
|
+
});
|
|
480
|
+
return stream;
|
|
481
|
+
} catch (error) {
|
|
482
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error resuming workflow");
|
|
483
|
+
}
|
|
484
|
+
}
|
|
508
485
|
async function getWorkflowRunsHandler({
|
|
509
486
|
mastra,
|
|
510
487
|
workflowId,
|
|
@@ -588,16 +565,16 @@ async function sendWorkflowRunEventHandler({
|
|
|
588
565
|
}
|
|
589
566
|
}
|
|
590
567
|
|
|
591
|
-
exports.WorkflowRegistry = WorkflowRegistry;
|
|
592
568
|
exports.cancelWorkflowRunHandler = cancelWorkflowRunHandler;
|
|
593
569
|
exports.createWorkflowRunHandler = createWorkflowRunHandler;
|
|
594
570
|
exports.getWorkflowByIdHandler = getWorkflowByIdHandler;
|
|
595
|
-
exports.getWorkflowInfo = getWorkflowInfo;
|
|
596
571
|
exports.getWorkflowRunByIdHandler = getWorkflowRunByIdHandler;
|
|
597
572
|
exports.getWorkflowRunExecutionResultHandler = getWorkflowRunExecutionResultHandler;
|
|
598
573
|
exports.getWorkflowRunsHandler = getWorkflowRunsHandler;
|
|
599
574
|
exports.getWorkflowsHandler = getWorkflowsHandler;
|
|
575
|
+
exports.observeStreamWorkflowHandler = observeStreamWorkflowHandler;
|
|
600
576
|
exports.resumeAsyncWorkflowHandler = resumeAsyncWorkflowHandler;
|
|
577
|
+
exports.resumeStreamWorkflowHandler = resumeStreamWorkflowHandler;
|
|
601
578
|
exports.resumeWorkflowHandler = resumeWorkflowHandler;
|
|
602
579
|
exports.sendWorkflowRunEventHandler = sendWorkflowRunEventHandler;
|
|
603
580
|
exports.startAsyncWorkflowHandler = startAsyncWorkflowHandler;
|
|
@@ -606,5 +583,5 @@ exports.streamVNextWorkflowHandler = streamVNextWorkflowHandler;
|
|
|
606
583
|
exports.streamWorkflowHandler = streamWorkflowHandler;
|
|
607
584
|
exports.watchWorkflowHandler = watchWorkflowHandler;
|
|
608
585
|
exports.workflows_exports = workflows_exports;
|
|
609
|
-
//# sourceMappingURL=chunk-
|
|
610
|
-
//# sourceMappingURL=chunk-
|
|
586
|
+
//# sourceMappingURL=chunk-CML3EOO5.cjs.map
|
|
587
|
+
//# sourceMappingURL=chunk-CML3EOO5.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/handlers/workflows.ts"],"names":["__export","getWorkflowInfo","handleError","HTTPException","WorkflowRegistry","ReadableStream","TransformStream"],"mappings":";;;;;;;;;AAAA,IAAA,iBAAA,GAAA;AAAAA,0BAAA,CAAA,iBAAA,EAAA;AAAA,EAAA,wBAAA,EAAA,MAAA,wBAAA;AAAA,EAAA,wBAAA,EAAA,MAAA,wBAAA;AAAA,EAAA,sBAAA,EAAA,MAAA,sBAAA;AAAA,EAAA,yBAAA,EAAA,MAAA,yBAAA;AAAA,EAAA,oCAAA,EAAA,MAAA,oCAAA;AAAA,EAAA,sBAAA,EAAA,MAAA,sBAAA;AAAA,EAAA,mBAAA,EAAA,MAAA,mBAAA;AAAA,EAAA,4BAAA,EAAA,MAAA,4BAAA;AAAA,EAAA,0BAAA,EAAA,MAAA,0BAAA;AAAA,EAAA,2BAAA,EAAA,MAAA,2BAAA;AAAA,EAAA,qBAAA,EAAA,MAAA,qBAAA;AAAA,EAAA,2BAAA,EAAA,MAAA,2BAAA;AAAA,EAAA,yBAAA,EAAA,MAAA,yBAAA;AAAA,EAAA,uBAAA,EAAA,MAAA,uBAAA;AAAA,EAAA,0BAAA,EAAA,MAAA,0BAAA;AAAA,EAAA,qBAAA,EAAA,MAAA,qBAAA;AAAA,EAAA,oBAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AAcA,eAAsB,mBAAA,CAAoB,EAAE,MAAA,EAAO,EAAoB;AACrE,EAAA,IAAI;AACF,IAAA,MAAM,YAAY,MAAA,CAAO,YAAA,CAAa,EAAE,UAAA,EAAY,OAAO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,EAAK,EAAE,OAAA,EAAS,2BAA2B,CAAA;AAAA,IACrE;AAEA,IAAA,IAAI,CAAC,KAAA,EAAO;AACV,MAAA,MAAM,IAAIA,+BAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,6CAA6C,CAAA;AAAA,IACvF;AAEA,IAAA,MAAM,EAAE,UAAS,GAAI,MAAM,uBAAuB,EAAE,MAAA,EAAQ,YAAY,CAAA;AAExE,IAAA,IAAI,CAAC,QAAA,EAAU;AACb,MAAA,MAAM,IAAIA,+BAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,sBAAsB,CAAA;AAAA,IAChE;AAEA,IAAA,MAAM,GAAA,GAAM,MAAM,QAAA,CAAS,kBAAA,CAAmB,KAAK,CAAA;AAEnD,IAAA,IAAI,CAAC,GAAA,EAAK;AACR,MAAA,MAAM,IAAIA,+BAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,0BAA0B,CAAA;AAAA,IACpE;AAEA,IAAA,MAAM,OAAO,MAAM,QAAA,CAAS,cAAA,CAAe,EAAE,OAAO,CAAA;AAEpD,IAAA,MAAM,IAAA,CAAK,SAAA,CAAU,KAAA,EAAO,IAAI,CAAA;AAEhC,IAAA,OAAO,EAAE,SAAS,yBAAA,EAA0B;AAAA,EAC9C,SAAS,KAAA,EAAO;AACd,IAAA,OAAOD,6BAAA,CAAY,OAAO,kCAAkC,CAAA;AAAA,EAC9D;AACF","file":"chunk-CML3EOO5.cjs","sourcesContent":["import { ReadableStream, TransformStream } from 'node:stream/web';\nimport type { RuntimeContext } from '@mastra/core/di';\nimport type { WorkflowRuns } from '@mastra/core/storage';\nimport type { Workflow, WatchEvent, WorkflowInfo, StreamEvent } from '@mastra/core/workflows';\nimport { HTTPException } from '../http-exception';\nimport type { Context } from '../types';\nimport { getWorkflowInfo, WorkflowRegistry } from '../utils';\nimport { handleError } from './error';\n\nexport interface WorkflowContext extends Context {\n workflowId?: string;\n runId?: string;\n}\n\nexport async function getWorkflowsHandler({ mastra }: WorkflowContext) {\n try {\n const workflows = mastra.getWorkflows({ serialized: false });\n const _workflows = Object.entries(workflows).reduce<Record<string, WorkflowInfo>>((acc, [key, workflow]) => {\n acc[key] = getWorkflowInfo(workflow);\n return acc;\n }, {});\n return _workflows;\n } catch (error) {\n return handleError(error, 'Error getting workflows');\n }\n}\n\nasync function getWorkflowsFromSystem({ mastra, workflowId }: WorkflowContext) {\n const logger = mastra.getLogger();\n\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n let workflow;\n\n // First check registry for temporary workflows\n workflow = WorkflowRegistry.getWorkflow(workflowId);\n\n if (!workflow) {\n try {\n workflow = mastra.getWorkflow(workflowId);\n } catch (error) {\n logger.debug('Error getting workflow, searching agents for workflow', error);\n }\n }\n\n if (!workflow) {\n logger.debug('Workflow not found, searching agents for workflow', { workflowId });\n const agents = mastra.getAgents();\n\n if (Object.keys(agents || {}).length) {\n for (const [_, agent] of Object.entries(agents)) {\n try {\n const workflows = await agent.getWorkflows();\n\n if (workflows[workflowId]) {\n workflow = workflows[workflowId];\n break;\n }\n break;\n } catch (error) {\n logger.debug('Error getting workflow from agent', error);\n }\n }\n }\n }\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n return { workflow };\n}\n\nexport async function getWorkflowByIdHandler({ mastra, workflowId }: WorkflowContext): Promise<WorkflowInfo> {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n return getWorkflowInfo(workflow);\n } catch (error) {\n return handleError(error, 'Error getting workflow');\n }\n}\n\nexport async function getWorkflowRunByIdHandler({\n mastra,\n workflowId,\n runId,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'>): Promise<ReturnType<Workflow['getWorkflowRunById']>> {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'Run ID is required' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.getWorkflowRunById(runId);\n\n if (!run) {\n throw new HTTPException(404, { message: 'Workflow run not found' });\n }\n\n return run;\n } catch (error) {\n return handleError(error, 'Error getting workflow run');\n }\n}\n\nexport async function getWorkflowRunExecutionResultHandler({\n mastra,\n workflowId,\n runId,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'>): Promise<WatchEvent['payload']['workflowState']> {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'Run ID is required' });\n }\n\n const workflow = mastra.getWorkflow(workflowId);\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const executionResult = await workflow.getWorkflowRunExecutionResult(runId);\n\n if (!executionResult) {\n throw new HTTPException(404, { message: 'Workflow run execution result not found' });\n }\n\n return executionResult;\n } catch (error) {\n return handleError(error, 'Error getting workflow run execution result');\n }\n}\n\nexport async function createWorkflowRunHandler({\n mastra,\n workflowId,\n runId: prevRunId,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'>) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.createRunAsync({ runId: prevRunId });\n\n return { runId: run.runId };\n } catch (error) {\n return handleError(error, 'Error creating workflow run');\n }\n}\n\nexport async function startAsyncWorkflowHandler({\n mastra,\n runtimeContext,\n workflowId,\n runId,\n inputData,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {\n inputData?: unknown;\n runtimeContext?: RuntimeContext;\n}) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const _run = await workflow.createRunAsync({ runId });\n const result = await _run.start({\n inputData,\n runtimeContext,\n });\n return result;\n } catch (error) {\n return handleError(error, 'Error starting async workflow');\n }\n}\n\nexport async function startWorkflowRunHandler({\n mastra,\n runtimeContext,\n workflowId,\n runId,\n inputData,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {\n inputData?: unknown;\n runtimeContext?: RuntimeContext;\n}) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'runId required to start run' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.getWorkflowRunById(runId);\n\n if (!run) {\n throw new HTTPException(404, { message: 'Workflow run not found' });\n }\n\n const _run = await workflow.createRunAsync({ runId });\n void _run.start({\n inputData,\n runtimeContext,\n });\n\n return { message: 'Workflow run started' };\n } catch (e) {\n return handleError(e, 'Error starting workflow run');\n }\n}\n\nexport async function watchWorkflowHandler({\n mastra,\n workflowId,\n runId,\n eventType = 'watch',\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {\n eventType?: 'watch' | 'watch-v2';\n}): Promise<ReadableStream<string>> {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'runId required to watch workflow' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.getWorkflowRunById(runId);\n\n if (!run) {\n throw new HTTPException(404, { message: 'Workflow run not found' });\n }\n\n const _run = await workflow.createRunAsync({ runId });\n let unwatch: () => void;\n let asyncRef: NodeJS.Immediate | null = null;\n const stream = new ReadableStream<string>({\n start(controller) {\n unwatch = _run.watch((event: any) => {\n const { type, payload, eventTimestamp } = event;\n controller.enqueue(JSON.stringify({ type, payload, eventTimestamp, runId }));\n\n if (asyncRef) {\n clearImmediate(asyncRef);\n asyncRef = null;\n }\n\n // a run is finished if the status is not running\n asyncRef = setImmediate(async () => {\n const runDone = eventType === 'watch' ? payload.workflowState.status !== 'running' : type === 'finish';\n if (runDone) {\n controller.close();\n unwatch?.();\n }\n });\n }, eventType);\n },\n cancel() {\n if (asyncRef) {\n clearImmediate(asyncRef);\n asyncRef = null;\n }\n unwatch?.();\n },\n });\n\n return stream;\n } catch (error) {\n return handleError(error, 'Error watching workflow');\n }\n}\n\nexport async function streamWorkflowHandler({\n mastra,\n runtimeContext,\n workflowId,\n runId,\n inputData,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {\n inputData?: unknown;\n runtimeContext?: RuntimeContext;\n}) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'runId required to resume workflow' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const serverCache = mastra.getServerCache();\n\n const run = await workflow.createRunAsync({ runId });\n const result = run.stream({\n inputData,\n runtimeContext,\n onChunk: async chunk => {\n if (serverCache) {\n const cacheKey = runId;\n await serverCache.listPush(cacheKey, chunk);\n }\n },\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error executing workflow');\n }\n}\n\nexport async function observeStreamWorkflowHandler({\n mastra,\n workflowId,\n runId,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'>) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'runId required to observe workflow stream' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.getWorkflowRunById(runId);\n\n if (!run) {\n throw new HTTPException(404, { message: 'Workflow run not found' });\n }\n\n const _run = await workflow.createRunAsync({ runId });\n const serverCache = mastra.getServerCache();\n if (!serverCache) {\n throw new HTTPException(500, { message: 'Server cache not found' });\n }\n\n const transformStream = new TransformStream<StreamEvent, StreamEvent>();\n\n const writer = transformStream.writable.getWriter();\n\n const cachedRunChunks = await serverCache.listFromTo(runId, 0);\n\n for (const chunk of cachedRunChunks) {\n await writer.write(chunk as any);\n }\n\n writer.releaseLock();\n\n const result = _run.observeStream();\n return result.stream?.pipeThrough(transformStream);\n } catch (error) {\n return handleError(error, 'Error observing workflow stream');\n }\n}\n\nexport async function streamVNextWorkflowHandler({\n mastra,\n runtimeContext,\n workflowId,\n runId,\n inputData,\n closeOnSuspend,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {\n inputData?: unknown;\n runtimeContext?: RuntimeContext;\n closeOnSuspend?: boolean;\n}) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'runId required to stream workflow' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.createRunAsync({ runId });\n const result = run.streamVNext({\n inputData,\n runtimeContext,\n closeOnSuspend,\n });\n return result;\n } catch (error) {\n return handleError(error, 'Error streaming workflow');\n }\n}\n\nexport async function resumeAsyncWorkflowHandler({\n mastra,\n workflowId,\n runId,\n body,\n runtimeContext,\n}: WorkflowContext & {\n body: { step: string | string[]; resumeData?: unknown };\n runtimeContext?: RuntimeContext;\n}) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'runId required to resume workflow' });\n }\n\n if (!body.step) {\n throw new HTTPException(400, { message: 'step required to resume workflow' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.getWorkflowRunById(runId);\n\n if (!run) {\n throw new HTTPException(404, { message: 'Workflow run not found' });\n }\n\n const _run = await workflow.createRunAsync({ runId });\n const result = await _run.resume({\n step: body.step,\n resumeData: body.resumeData,\n runtimeContext,\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error resuming workflow step');\n }\n}\n\nexport async function resumeWorkflowHandler({\n mastra,\n workflowId,\n runId,\n body,\n runtimeContext,\n}: WorkflowContext & {\n body: { step: string | string[]; resumeData?: unknown };\n runtimeContext?: RuntimeContext;\n}) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'runId required to resume workflow' });\n }\n\n if (!body.step) {\n throw new HTTPException(400, { message: 'step required to resume workflow' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.getWorkflowRunById(runId);\n\n if (!run) {\n throw new HTTPException(404, { message: 'Workflow run not found' });\n }\n\n const _run = await workflow.createRunAsync({ runId });\n\n void _run.resume({\n step: body.step,\n resumeData: body.resumeData,\n runtimeContext,\n });\n\n return { message: 'Workflow run resumed' };\n } catch (error) {\n return handleError(error, 'Error resuming workflow');\n }\n}\n\nexport async function resumeStreamWorkflowHandler({\n mastra,\n workflowId,\n runId,\n body,\n runtimeContext,\n}: WorkflowContext & {\n body: { step: string | string[]; resumeData?: unknown };\n runtimeContext?: RuntimeContext;\n}) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'runId required to resume workflow' });\n }\n\n if (!body.step) {\n throw new HTTPException(400, { message: 'step required to resume workflow' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.getWorkflowRunById(runId);\n\n if (!run) {\n throw new HTTPException(404, { message: 'Workflow run not found' });\n }\n\n const _run = await workflow.createRunAsync({ runId });\n\n const stream = await _run.resumeStreamVNext({\n step: body.step,\n resumeData: body.resumeData,\n runtimeContext,\n });\n\n return stream;\n } catch (error) {\n return handleError(error, 'Error resuming workflow');\n }\n}\n\nexport async function getWorkflowRunsHandler({\n mastra,\n workflowId,\n fromDate,\n toDate,\n limit,\n offset,\n resourceId,\n}: WorkflowContext & {\n fromDate?: Date;\n toDate?: Date;\n limit?: number;\n offset?: number;\n resourceId?: string;\n}): Promise<WorkflowRuns> {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const workflowRuns = (await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId })) || {\n runs: [],\n total: 0,\n };\n return workflowRuns;\n } catch (error) {\n return handleError(error, 'Error getting workflow runs');\n }\n}\n\nexport async function cancelWorkflowRunHandler({\n mastra,\n workflowId,\n runId,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'>) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'runId required to cancel workflow run' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.getWorkflowRunById(runId);\n\n if (!run) {\n throw new HTTPException(404, { message: 'Workflow run not found' });\n }\n\n const _run = await workflow.createRunAsync({ runId });\n\n await _run.cancel();\n\n return { message: 'Workflow run cancelled' };\n } catch (error) {\n return handleError(error, 'Error canceling workflow run');\n }\n}\n\nexport async function sendWorkflowRunEventHandler({\n mastra,\n workflowId,\n runId,\n event,\n data,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {\n event: string;\n data: unknown;\n}) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'runId required to send workflow run event' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.getWorkflowRunById(runId);\n\n if (!run) {\n throw new HTTPException(404, { message: 'Workflow run not found' });\n }\n\n const _run = await workflow.createRunAsync({ runId });\n\n await _run.sendEvent(event, data);\n\n return { message: 'Workflow run event sent' };\n } catch (error) {\n return handleError(error, 'Error sending workflow run event');\n }\n}\n"]}
|
|
@@ -3,6 +3,7 @@ import { handleError } from './chunk-CY4TP3FK.js';
|
|
|
3
3
|
import { HTTPException } from './chunk-MMROOK5J.js';
|
|
4
4
|
import { __export } from './chunk-G3PMV62Z.js';
|
|
5
5
|
import { Readable } from 'stream';
|
|
6
|
+
import { MastraError } from '@mastra/core/error';
|
|
6
7
|
|
|
7
8
|
// src/server/handlers/voice.ts
|
|
8
9
|
var voice_exports = {};
|
|
@@ -12,7 +13,7 @@ __export(voice_exports, {
|
|
|
12
13
|
getSpeakersHandler: () => getSpeakersHandler,
|
|
13
14
|
transcribeSpeechHandler: () => transcribeSpeechHandler
|
|
14
15
|
});
|
|
15
|
-
async function getSpeakersHandler({ mastra, agentId }) {
|
|
16
|
+
async function getSpeakersHandler({ mastra, agentId, runtimeContext }) {
|
|
16
17
|
try {
|
|
17
18
|
if (!agentId) {
|
|
18
19
|
throw new HTTPException(400, { message: "Agent ID is required" });
|
|
@@ -21,7 +22,7 @@ async function getSpeakersHandler({ mastra, agentId }) {
|
|
|
21
22
|
if (!agent) {
|
|
22
23
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
23
24
|
}
|
|
24
|
-
const voice = await agent.getVoice();
|
|
25
|
+
const voice = await agent.getVoice({ runtimeContext });
|
|
25
26
|
if (!voice) {
|
|
26
27
|
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
27
28
|
}
|
|
@@ -34,7 +35,8 @@ async function getSpeakersHandler({ mastra, agentId }) {
|
|
|
34
35
|
async function generateSpeechHandler({
|
|
35
36
|
mastra,
|
|
36
37
|
agentId,
|
|
37
|
-
body
|
|
38
|
+
body,
|
|
39
|
+
runtimeContext
|
|
38
40
|
}) {
|
|
39
41
|
try {
|
|
40
42
|
if (!agentId) {
|
|
@@ -47,11 +49,16 @@ async function generateSpeechHandler({
|
|
|
47
49
|
if (!agent) {
|
|
48
50
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
49
51
|
}
|
|
50
|
-
const voice = await agent.getVoice();
|
|
52
|
+
const voice = await agent.getVoice({ runtimeContext });
|
|
51
53
|
if (!voice) {
|
|
52
54
|
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
53
55
|
}
|
|
54
|
-
const audioStream = await voice.speak(body.text, { speaker: body.speakerId })
|
|
56
|
+
const audioStream = await Promise.resolve().then(() => voice.speak(body.text, { speaker: body.speakerId })).catch((err) => {
|
|
57
|
+
if (err instanceof MastraError) {
|
|
58
|
+
throw new HTTPException(400, { message: err.message });
|
|
59
|
+
}
|
|
60
|
+
throw err;
|
|
61
|
+
});
|
|
55
62
|
if (!audioStream) {
|
|
56
63
|
throw new HTTPException(500, { message: "Failed to generate speech" });
|
|
57
64
|
}
|
|
@@ -63,7 +70,8 @@ async function generateSpeechHandler({
|
|
|
63
70
|
async function transcribeSpeechHandler({
|
|
64
71
|
mastra,
|
|
65
72
|
agentId,
|
|
66
|
-
body
|
|
73
|
+
body,
|
|
74
|
+
runtimeContext
|
|
67
75
|
}) {
|
|
68
76
|
try {
|
|
69
77
|
if (!agentId) {
|
|
@@ -76,7 +84,7 @@ async function transcribeSpeechHandler({
|
|
|
76
84
|
if (!agent) {
|
|
77
85
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
78
86
|
}
|
|
79
|
-
const voice = await agent.getVoice();
|
|
87
|
+
const voice = await agent.getVoice({ runtimeContext });
|
|
80
88
|
if (!voice) {
|
|
81
89
|
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
82
90
|
}
|
|
@@ -89,7 +97,7 @@ async function transcribeSpeechHandler({
|
|
|
89
97
|
return handleError(error, "Error transcribing speech");
|
|
90
98
|
}
|
|
91
99
|
}
|
|
92
|
-
async function getListenerHandler({ mastra, agentId }) {
|
|
100
|
+
async function getListenerHandler({ mastra, agentId, runtimeContext }) {
|
|
93
101
|
try {
|
|
94
102
|
if (!agentId) {
|
|
95
103
|
throw new HTTPException(400, { message: "Agent ID is required" });
|
|
@@ -98,7 +106,7 @@ async function getListenerHandler({ mastra, agentId }) {
|
|
|
98
106
|
if (!agent) {
|
|
99
107
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
100
108
|
}
|
|
101
|
-
const voice = await agent.getVoice();
|
|
109
|
+
const voice = await agent.getVoice({ runtimeContext });
|
|
102
110
|
if (!voice) {
|
|
103
111
|
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
104
112
|
}
|
|
@@ -110,5 +118,5 @@ async function getListenerHandler({ mastra, agentId }) {
|
|
|
110
118
|
}
|
|
111
119
|
|
|
112
120
|
export { generateSpeechHandler, getListenerHandler, getSpeakersHandler, transcribeSpeechHandler, voice_exports };
|
|
113
|
-
//# sourceMappingURL=chunk-
|
|
114
|
-
//# sourceMappingURL=chunk-
|
|
121
|
+
//# sourceMappingURL=chunk-JRDEOHAJ.js.map
|
|
122
|
+
//# sourceMappingURL=chunk-JRDEOHA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,EAAA,IAAI;AACF,IAAA,IAAI,CAAC,OAAA,EAAS;AACZ,MAAA,MAAM,IAAI,aAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,wBAAwB,CAAA;AAAA,IAClE;AAEA,IAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,QAAA,CAAS,OAAO,CAAA;AAErC,IAAA,IAAI,CAAC,KAAA,EAAO;AACV,MAAA,MAAM,IAAI,aAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,mBAAmB,CAAA;AAAA,IAC7D;AAEA,IAAA,MAAM,QAAQ,MAAM,KAAA,CAAM,QAAA,CAAS,EAAE,gBAAgB,CAAA;AAErD,IAAA,IAAI,CAAC,KAAA,EAAO;AACV,MAAA,MAAM,IAAI,aAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,0CAA0C,CAAA;AAAA,IACpF;AAEA,IAAA,MAAM,SAAA,GAAY,MAAM,KAAA,CAAM,WAAA,EAAY;AAC1C,IAAA,OAAO,SAAA;AAAA,EACT,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,WAAA,CAAY,OAAO,yBAAyB,CAAA;AAAA,EACrD;AACF","file":"chunk-JRDEOHAJ.js","sourcesContent":["import { Readable } from 'stream';\nimport type { Agent } from '@mastra/core/agent';\nimport { MastraError } from '@mastra/core/error';\nimport type { RuntimeContext } from '@mastra/core/runtime-context';\nimport { HTTPException } from '../http-exception';\nimport type { Context } from '../types';\n\nimport { handleError } from './error';\nimport { validateBody } from './utils';\n\ninterface VoiceContext extends Context {\n agentId?: string;\n runtimeContext?: RuntimeContext;\n}\n\n/**\n * Get available speakers for an agent\n */\nexport async function getSpeakersHandler({ mastra, agentId, runtimeContext }: VoiceContext) {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n\n const agent = mastra.getAgent(agentId);\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n const voice = await agent.getVoice({ runtimeContext });\n\n if (!voice) {\n throw new HTTPException(400, { message: 'Agent does not have voice capabilities' });\n }\n\n const speakers = await voice.getSpeakers();\n return speakers;\n } catch (error) {\n return handleError(error, 'Error getting speakers');\n }\n}\n\n/**\n * Generate speech from text\n */\nexport async function generateSpeechHandler({\n mastra,\n agentId,\n body,\n runtimeContext,\n}: VoiceContext & {\n body?: {\n text?: string;\n speakerId?: string;\n };\n}) {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n\n validateBody({\n text: body?.text,\n });\n\n const agent = mastra.getAgent(agentId);\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n const voice = await agent.getVoice({ runtimeContext });\n\n if (!voice) {\n throw new HTTPException(400, { message: 'Agent does not have voice capabilities' });\n }\n\n const audioStream = await Promise.resolve()\n .then(() => voice.speak(body!.text!, { speaker: body!.speakerId! }))\n .catch(err => {\n if (err instanceof MastraError) {\n throw new HTTPException(400, { message: err.message });\n }\n\n throw err;\n });\n\n if (!audioStream) {\n throw new HTTPException(500, { message: 'Failed to generate speech' });\n }\n\n return audioStream;\n } catch (error) {\n return handleError(error, 'Error generating speech');\n }\n}\n\n/**\n * Transcribe speech to text\n */\nexport async function transcribeSpeechHandler({\n mastra,\n agentId,\n body,\n runtimeContext,\n}: VoiceContext & {\n body?: {\n audioData?: Buffer;\n options?: Parameters<NonNullable<Agent['voice']>['listen']>[1];\n };\n}) {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n\n if (!body?.audioData) {\n throw new HTTPException(400, { message: 'Audio data is required' });\n }\n\n const agent = mastra.getAgent(agentId);\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n const voice = await agent.getVoice({ runtimeContext });\n\n if (!voice) {\n throw new HTTPException(400, { message: 'Agent does not have voice capabilities' });\n }\n\n const audioStream = new Readable();\n audioStream.push(body.audioData);\n audioStream.push(null);\n\n const text = await voice.listen(audioStream, body.options);\n return { text };\n } catch (error) {\n return handleError(error, 'Error transcribing speech');\n }\n}\n\n/**\n * Get available listeners for an agent\n */\nexport async function getListenerHandler({ mastra, agentId, runtimeContext }: VoiceContext) {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n\n const agent = mastra.getAgent(agentId);\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n const voice = await agent.getVoice({ runtimeContext });\n\n if (!voice) {\n throw new HTTPException(400, { message: 'Agent does not have voice capabilities' });\n }\n\n const listeners = await voice.getListener();\n return listeners;\n } catch (error) {\n return handleError(error, 'Error getting listeners');\n }\n}\n"]}
|
|
@@ -83,7 +83,9 @@ function executeToolHandler(tools) {
|
|
|
83
83
|
runId,
|
|
84
84
|
runtimeContext,
|
|
85
85
|
// TODO: Pass proper tracing context when server API supports tracing
|
|
86
|
-
tracingContext: { currentSpan: void 0 }
|
|
86
|
+
tracingContext: { currentSpan: void 0 },
|
|
87
|
+
suspend: async () => {
|
|
88
|
+
}
|
|
87
89
|
});
|
|
88
90
|
return result;
|
|
89
91
|
} catch (error) {
|
|
@@ -143,7 +145,9 @@ async function executeAgentToolHandler({
|
|
|
143
145
|
mastra,
|
|
144
146
|
runId: agentId,
|
|
145
147
|
// TODO: Pass proper tracing context when server API supports tracing
|
|
146
|
-
tracingContext: { currentSpan: void 0 }
|
|
148
|
+
tracingContext: { currentSpan: void 0 },
|
|
149
|
+
suspend: async () => {
|
|
150
|
+
}
|
|
147
151
|
});
|
|
148
152
|
return result;
|
|
149
153
|
} catch (error) {
|
|
@@ -152,5 +156,5 @@ async function executeAgentToolHandler({
|
|
|
152
156
|
}
|
|
153
157
|
|
|
154
158
|
export { executeAgentToolHandler, executeToolHandler, getAgentToolHandler, getToolByIdHandler, getToolsHandler, tools_exports };
|
|
155
|
-
//# sourceMappingURL=chunk-
|
|
156
|
-
//# sourceMappingURL=chunk-
|
|
159
|
+
//# sourceMappingURL=chunk-KM7EJKXV.js.map
|
|
160
|
+
//# sour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,IAAA,IAAI,CAAC,IAAA,EAAM;AACT,MAAA,MAAM,IAAI,aAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,kBAAkB,CAAA;AAAA,IAC5D;AAEA,IAAA,IAAI,CAAC,MAAM,OAAA,EAAS;AAClB,MAAA,MAAM,IAAI,aAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,0BAA0B,CAAA;AAAA,IACpE;AAOA,IAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,OAAA,CAAQ;AAAA,MAChC,OAAA,EAAS,IAAA;AAAA,MACT,cAAA;AAAA,MACA,MAAA;AAAA,MACA,KAAA,EAAO,OAAA;AAAA;AAAA,MAEP,cAAA,EAAgB,EAAE,WAAA,EAAa,MAAA,EAAU;AAAA,MACzC,SAAS,YAAY;AAAA,MAAC;AAAA,KACvB,CAAA;AAED,IAAA,OAAO,MAAA;AAAA,EACT,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,WAAA,CAAY,OAAO,sBAAsB,CAAA;AAAA,EAClD;AACF","file":"chunk-KM7EJKXV.js","sourcesContent":["import type { RuntimeContext } from '@mastra/core/di';\nimport type { ToolAction, VercelTool } from '@mastra/core/tools';\nimport { isVercelTool } from '@mastra/core/tools';\nimport { zodToJsonSchema } from '@mastra/core/utils/zod-to-json';\nimport { stringify } from 'superjson';\nimport { HTTPException } from '../http-exception';\nimport type { Context } from '../types';\n\nimport { handleError } from './error';\nimport { validateBody } from './utils';\n\ninterface ToolsContext extends Context {\n tools?: Record<string, ToolAction | VercelTool>;\n toolId?: string;\n runId?: string;\n}\n\n// Tool handlers\nexport async function getToolsHandler({ tools }: Pick<ToolsContext, 'tools'>) {\n try {\n if (!tools) {\n return {};\n }\n\n const serializedTools = Object.entries(tools).reduce(\n (acc, [id, _tool]) => {\n const tool = _tool as any;\n acc[id] = {\n ...tool,\n inputSchema: tool.inputSchema ? stringify(zodToJsonSchema(tool.inputSchema)) : undefined,\n outputSchema: tool.outputSchema ? stringify(zodToJsonSchema(tool.outputSchema)) : undefined,\n };\n return acc;\n },\n {} as Record<string, any>,\n );\n\n return serializedTools;\n } catch (error) {\n return handleError(error, 'Error getting tools');\n }\n}\n\nexport async function getToolByIdHandler({ tools, toolId }: Pick<ToolsContext, 'tools' | 'toolId'>) {\n try {\n const tool = Object.values(tools || {}).find((tool: any) => tool.id === toolId) as any;\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n const serializedTool = {\n ...tool,\n inputSchema: tool.inputSchema ? stringify(zodToJsonSchema(tool.inputSchema)) : undefined,\n outputSchema: tool.outputSchema ? stringify(zodToJsonSchema(tool.outputSchema)) : undefined,\n };\n\n return serializedTool;\n } catch (error) {\n return handleError(error, 'Error getting tool');\n }\n}\n\nexport function executeToolHandler(tools: ToolsContext['tools']) {\n return async ({\n mastra,\n runId,\n toolId,\n data,\n runtimeContext,\n }: Pick<ToolsContext, 'mastra' | 'toolId' | 'runId'> & {\n data?: unknown;\n runtimeContext: RuntimeContext;\n }) => {\n try {\n if (!toolId) {\n throw new HTTPException(400, { message: 'Tool ID is required' });\n }\n\n const tool = Object.values(tools || {}).find((tool: any) => tool.id === toolId) as any;\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n if (!tool?.execute) {\n throw new HTTPException(400, { message: 'Tool is not executable' });\n }\n\n validateBody({ data });\n\n if (isVercelTool(tool)) {\n const result = await (tool as any).execute(data);\n return result;\n }\n\n const result = await tool.execute({\n context: data!,\n mastra,\n runId,\n runtimeContext,\n // TODO: Pass proper tracing context when server API supports tracing\n tracingContext: { currentSpan: undefined },\n suspend: async () => {},\n });\n return result;\n } catch (error) {\n return handleError(error, 'Error executing tool');\n }\n };\n}\n\nexport async function getAgentToolHandler({\n mastra,\n agentId,\n toolId,\n runtimeContext,\n}: Pick<ToolsContext, 'mastra' | 'toolId'> & {\n agentId?: string;\n runtimeContext: RuntimeContext;\n}) {\n try {\n const agent = agentId ? mastra.getAgent(agentId) : null;\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n const agentTools = await agent.getTools({ runtimeContext });\n\n const tool = Object.values(agentTools || {}).find((tool: any) => tool.id === toolId) as any;\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n const serializedTool = {\n ...tool,\n inputSchema: tool.inputSchema ? stringify(zodToJsonSchema(tool.inputSchema)) : undefined,\n outputSchema: tool.outputSchema ? stringify(zodToJsonSchema(tool.outputSchema)) : undefined,\n };\n\n return serializedTool;\n } catch (error) {\n return handleError(error, 'Error getting agent tool');\n }\n}\n\nexport async function executeAgentToolHandler({\n mastra,\n agentId,\n toolId,\n data,\n runtimeContext,\n}: Pick<ToolsContext, 'mastra' | 'toolId'> & {\n agentId?: string;\n data: any;\n runtimeContext: RuntimeContext;\n}) {\n try {\n const agent = agentId ? mastra.getAgent(agentId) : null;\n if (!agent) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n const agentTools = await agent.getTools({ runtimeContext });\n\n const tool = Object.values(agentTools || {}).find((tool: any) => tool.id === toolId) as any;\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n if (!tool?.execute) {\n throw new HTTPException(400, { message: 'Tool is not executable' });\n }\n\n // if (isVercelTool(tool)) {\n // const result = await (tool as any).execute(data);\n // return result;\n // }\n\n const result = await tool.execute({\n context: data,\n runtimeContext,\n mastra,\n runId: agentId,\n // TODO: Pass proper tracing context when server API supports tracing\n tracingContext: { currentSpan: undefined },\n suspend: async () => {},\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error executing tool');\n }\n}\n"]}
|
|
@@ -85,7 +85,9 @@ function executeToolHandler(tools$1) {
|
|
|
85
85
|
runId,
|
|
86
86
|
runtimeContext,
|
|
87
87
|
// TODO: Pass proper tracing context when server API supports tracing
|
|
88
|
-
tracingContext: { currentSpan: void 0 }
|
|
88
|
+
tracingContext: { currentSpan: void 0 },
|
|
89
|
+
suspend: async () => {
|
|
90
|
+
}
|
|
89
91
|
});
|
|
90
92
|
return result;
|
|
91
93
|
} catch (error) {
|
|
@@ -145,7 +147,9 @@ async function executeAgentToolHandler({
|
|
|
145
147
|
mastra,
|
|
146
148
|
runId: agentId,
|
|
147
149
|
// TODO: Pass proper tracing context when server API supports tracing
|
|
148
|
-
tracingContext: { currentSpan: void 0 }
|
|
150
|
+
tracingContext: { currentSpan: void 0 },
|
|
151
|
+
suspend: async () => {
|
|
152
|
+
}
|
|
149
153
|
});
|
|
150
154
|
return result;
|
|
151
155
|
} catch (error) {
|
|
@@ -159,5 +163,5 @@ exports.getAgentToolHandler = getAgentToolHandler;
|
|
|
159
163
|
exports.getToolByIdHandler = getToolByIdHandler;
|
|
160
164
|
exports.getToolsHandler = getToolsHandler;
|
|
161
165
|
exports.tools_exports = tools_exports;
|
|
162
|
-
//# sourceMappingURL=chunk-
|
|
163
|
-
//# sourceMappingURL=chunk-
|
|
166
|
+
//# sourceMappingURL=chunk-LJFAAEU7.cjs.map
|
|
167
|
+
//# sourceMappingURL=chunk-LJFAAEU7.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/handlers/tools.ts"],"names":["__export","stringify","zodToJsonSchema","handleError","tool","HTTPException","tools","validateBody","isVercelTool","result"],"mappings":";;;;;;;;;;;AAAA,IAAA,aAAA,GAAA;AAAAA,0BAAA,CAAA,aAAA,EAAA;AAAA,EAAA,uBAAA,EAAA,MAAA,uBAAA;AAAA,EAAA,kBAAA,EAAA,MAAA,kBAAA;AAAA,EAAA,mBAAA,EAAA,MAAA,mBAAA;AAAA,EAAA,kBAAA,EAAA,MAAA,kBAAA;AAAA,EAAA,eAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AAkBA,eAAsB,eAAA,CAAgB,EAAE,KAAA,EAAM,EAAgC;AAC5E,EAAA,IAAI;AACF,IAAA,IAAI,CAAC,KAAA,EAAO;AACV,MAAA,OAAO,EAAC;AAAA,IACV;AAEA,IAAA,MAAM,eAAA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SAAS,YAAY;AAAA,MAAC;AAAA,KACvB,CAAA;AAED,IAAA,OAAO,MAAA;AAAA,EACT,SAAS,KAAA,EAAO;AACd,IAAA,OAAOF,6BAAA,CAAY,OAAO,sBAAsB,CAAA;AAAA,EAClD;AACF","file":"chunk-LJFAAEU7.cjs","sourcesContent":["import type { RuntimeContext } from '@mastra/core/di';\nimport type { ToolAction, VercelTool } from '@mastra/core/tools';\nimport { isVercelTool } from '@mastra/core/tools';\nimport { zodToJsonSchema } from '@mastra/core/utils/zod-to-json';\nimport { stringify } from 'superjson';\nimport { HTTPException } from '../http-exception';\nimport type { Context } from '../types';\n\nimport { handleError } from './error';\nimport { validateBody } from './utils';\n\ninterface ToolsContext extends Context {\n tools?: Record<string, ToolAction | VercelTool>;\n toolId?: string;\n runId?: string;\n}\n\n// Tool handlers\nexport async function getToolsHandler({ tools }: Pick<ToolsContext, 'tools'>) {\n try {\n if (!tools) {\n return {};\n }\n\n const serializedTools = Object.entries(tools).reduce(\n (acc, [id, _tool]) => {\n const tool = _tool as any;\n acc[id] = {\n ...tool,\n inputSchema: tool.inputSchema ? stringify(zodToJsonSchema(tool.inputSchema)) : undefined,\n outputSchema: tool.outputSchema ? stringify(zodToJsonSchema(tool.outputSchema)) : undefined,\n };\n return acc;\n },\n {} as Record<string, any>,\n );\n\n return serializedTools;\n } catch (error) {\n return handleError(error, 'Error getting tools');\n }\n}\n\nexport async function getToolByIdHandler({ tools, toolId }: Pick<ToolsContext, 'tools' | 'toolId'>) {\n try {\n const tool = Object.values(tools || {}).find((tool: any) => tool.id === toolId) as any;\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n const serializedTool = {\n ...tool,\n inputSchema: tool.inputSchema ? stringify(zodToJsonSchema(tool.inputSchema)) : undefined,\n outputSchema: tool.outputSchema ? stringify(zodToJsonSchema(tool.outputSchema)) : undefined,\n };\n\n return serializedTool;\n } catch (error) {\n return handleError(error, 'Error getting tool');\n }\n}\n\nexport function executeToolHandler(tools: ToolsContext['tools']) {\n return async ({\n mastra,\n runId,\n toolId,\n data,\n runtimeContext,\n }: Pick<ToolsContext, 'mastra' | 'toolId' | 'runId'> & {\n data?: unknown;\n runtimeContext: RuntimeContext;\n }) => {\n try {\n if (!toolId) {\n throw new HTTPException(400, { message: 'Tool ID is required' });\n }\n\n const tool = Object.values(tools || {}).find((tool: any) => tool.id === toolId) as any;\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n if (!tool?.execute) {\n throw new HTTPException(400, { message: 'Tool is not executable' });\n }\n\n validateBody({ data });\n\n if (isVercelTool(tool)) {\n const result = await (tool as any).execute(data);\n return result;\n }\n\n const result = await tool.execute({\n context: data!,\n mastra,\n runId,\n runtimeContext,\n // TODO: Pass proper tracing context when server API supports tracing\n tracingContext: { currentSpan: undefined },\n suspend: async () => {},\n });\n return result;\n } catch (error) {\n return handleError(error, 'Error executing tool');\n }\n };\n}\n\nexport async function getAgentToolHandler({\n mastra,\n agentId,\n toolId,\n runtimeContext,\n}: Pick<ToolsContext, 'mastra' | 'toolId'> & {\n agentId?: string;\n runtimeContext: RuntimeContext;\n}) {\n try {\n const agent = agentId ? mastra.getAgent(agentId) : null;\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n const agentTools = await agent.getTools({ runtimeContext });\n\n const tool = Object.values(agentTools || {}).find((tool: any) => tool.id === toolId) as any;\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n const serializedTool = {\n ...tool,\n inputSchema: tool.inputSchema ? stringify(zodToJsonSchema(tool.inputSchema)) : undefined,\n outputSchema: tool.outputSchema ? stringify(zodToJsonSchema(tool.outputSchema)) : undefined,\n };\n\n return serializedTool;\n } catch (error) {\n return handleError(error, 'Error getting agent tool');\n }\n}\n\nexport async function executeAgentToolHandler({\n mastra,\n agentId,\n toolId,\n data,\n runtimeContext,\n}: Pick<ToolsContext, 'mastra' | 'toolId'> & {\n agentId?: string;\n data: any;\n runtimeContext: RuntimeContext;\n}) {\n try {\n const agent = agentId ? mastra.getAgent(agentId) : null;\n if (!agent) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n const agentTools = await agent.getTools({ runtimeContext });\n\n const tool = Object.values(agentTools || {}).find((tool: any) => tool.id === toolId) as any;\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n if (!tool?.execute) {\n throw new HTTPException(400, { message: 'Tool is not executable' });\n }\n\n // if (isVercelTool(tool)) {\n // const result = await (tool as any).execute(data);\n // return result;\n // }\n\n const result = await tool.execute({\n context: data,\n runtimeContext,\n mastra,\n runId: agentId,\n // TODO: Pass proper tracing context when server API supports tracing\n tracingContext: { currentSpan: undefined },\n suspend: async () => {},\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error executing tool');\n }\n}\n"]}
|