@mastra/server 0.0.0-fix-message-embedding-20250506021742 → 0.0.0-fix-fetch-workflow-runs-20250624231457
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/README.md +48 -135
- package/dist/_tsup-dts-rollup.d.cts +444 -108
- package/dist/_tsup-dts-rollup.d.ts +444 -108
- package/dist/chunk-4DTDPTQC.cjs +332 -0
- package/dist/{chunk-4JINXASC.js → chunk-55DOQLP6.js} +5 -4
- package/dist/{chunk-QN4KF3BH.cjs → chunk-57CJTIPW.cjs} +2 -2
- package/dist/{chunk-ZLBRQFDD.cjs → chunk-64U3UDTH.cjs} +2 -2
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/{chunk-AMVOS7YB.cjs → chunk-B4MQFJ7G.cjs} +12 -8
- package/dist/{chunk-BPL2CBLV.js → chunk-BFOA2QQY.js} +8 -4
- package/dist/{chunk-M56ECCHK.cjs → chunk-BNEY4P4P.cjs} +20 -19
- package/dist/{chunk-QJ3AHN64.js → chunk-C7564HUT.js} +4 -3
- package/dist/{chunk-D3G23FP3.cjs → chunk-CPPYMJX5.cjs} +24 -22
- package/dist/chunk-GHC4YV6R.js +504 -0
- package/dist/chunk-GKM45O24.cjs +278 -0
- package/dist/{chunk-L7XE5QTW.js → chunk-H5PTF3Y4.js} +1 -1
- package/dist/chunk-IMBY5XUG.cjs +86 -0
- package/dist/{chunk-3AHQ5RGN.js → chunk-M5ABIP7D.js} +1 -1
- package/dist/chunk-MLKGABMK.js +7 -0
- package/dist/chunk-MN6F4D5A.cjs +2004 -0
- package/dist/{chunk-3XTEV33Q.js → chunk-N2YBMSO2.js} +54 -51
- package/dist/{chunk-TRDNDNGQ.js → chunk-NYN7KFXL.js} +1 -7
- package/dist/{chunk-FV45V6WC.cjs → chunk-OCWPVYNI.cjs} +0 -7
- package/dist/chunk-OSZM4EAY.js +2001 -0
- package/dist/{chunk-Y3SV5XK4.js → chunk-PMUATKV2.js} +104 -15
- package/dist/chunk-QLG2PFHE.js +81 -0
- package/dist/{chunk-Q6SHQECN.js → chunk-R5VGYBV6.js} +34 -10
- package/dist/{chunk-2FJURXCL.cjs → chunk-RQ2Z56EC.cjs} +93 -55
- package/dist/chunk-SDPGVWQJ.cjs +512 -0
- package/dist/{chunk-IQTNZSFP.js → chunk-SOBBILUG.js} +160 -51
- package/dist/chunk-TO5U6HW3.cjs +435 -0
- package/dist/{chunk-5YGDYMRB.cjs → chunk-VPNDC2DI.cjs} +14 -13
- package/dist/chunk-WJY57THV.cjs +118 -0
- package/dist/{chunk-5JNVY6DU.js → chunk-XR7VJOOP.js} +7 -5
- package/dist/{chunk-RBQASTUP.js → chunk-XUIJ7WRT.js} +63 -25
- package/dist/server/handlers/a2a.cjs +30 -0
- package/dist/server/handlers/a2a.d.cts +6 -0
- package/dist/server/handlers/a2a.d.ts +6 -0
- package/dist/server/handlers/a2a.js +1 -0
- package/dist/server/handlers/agents.cjs +7 -7
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/error.cjs +2 -2
- package/dist/server/handlers/error.js +1 -1
- package/dist/server/handlers/legacyWorkflows.cjs +46 -0
- package/dist/server/handlers/legacyWorkflows.d.cts +10 -0
- package/dist/server/handlers/legacyWorkflows.d.ts +10 -0
- package/dist/server/handlers/legacyWorkflows.js +1 -0
- package/dist/server/handlers/logs.cjs +4 -4
- package/dist/server/handlers/logs.js +1 -1
- package/dist/server/handlers/memory.cjs +9 -9
- package/dist/server/handlers/memory.js +1 -1
- package/dist/server/handlers/network.cjs +5 -5
- package/dist/server/handlers/network.js +1 -1
- package/dist/server/handlers/telemetry.cjs +3 -3
- package/dist/server/handlers/telemetry.js +1 -1
- package/dist/server/handlers/tools.cjs +5 -5
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/utils.cjs +2 -2
- package/dist/server/handlers/utils.js +1 -1
- package/dist/server/handlers/vNextNetwork.cjs +175 -0
- package/dist/server/handlers/vNextNetwork.d.cts +5 -0
- package/dist/server/handlers/vNextNetwork.d.ts +5 -0
- package/dist/server/handlers/vNextNetwork.js +169 -0
- package/dist/server/handlers/vector.cjs +7 -7
- package/dist/server/handlers/vector.js +1 -1
- package/dist/server/handlers/voice.cjs +8 -4
- package/dist/server/handlers/voice.d.cts +1 -0
- package/dist/server/handlers/voice.d.ts +1 -0
- package/dist/server/handlers/voice.js +1 -1
- package/dist/server/handlers/workflows.cjs +21 -13
- package/dist/server/handlers/workflows.d.cts +4 -2
- package/dist/server/handlers/workflows.d.ts +4 -2
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +32 -27
- package/dist/server/handlers.d.cts +2 -1
- package/dist/server/handlers.d.ts +2 -1
- package/dist/server/handlers.js +11 -10
- package/package.json +13 -12
- package/dist/chunk-3EJZQ6TQ.js +0 -49
- package/dist/chunk-4BIX6GMY.cjs +0 -189
- package/dist/chunk-55HTWX4C.cjs +0 -93
- package/dist/chunk-5SWCVTNL.cjs +0 -5579
- package/dist/chunk-CHFORQ7J.cjs +0 -329
- package/dist/chunk-FOXHTOQZ.cjs +0 -324
- package/dist/chunk-OMN3UI6X.js +0 -5576
- package/dist/chunk-SKBVVI24.cjs +0 -54
- package/dist/server/handlers/vNextWorkflows.cjs +0 -46
- package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
- package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
- package/dist/server/handlers/vNextWorkflows.js +0 -1
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkMN6F4D5A_cjs = require('./chunk-MN6F4D5A.cjs');
|
|
4
|
+
var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
|
|
5
|
+
var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.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
|
+
createWorkflowRunHandler: () => createWorkflowRunHandler,
|
|
13
|
+
getWorkflowByIdHandler: () => getWorkflowByIdHandler,
|
|
14
|
+
getWorkflowRunByIdHandler: () => getWorkflowRunByIdHandler,
|
|
15
|
+
getWorkflowRunExecutionResultHandler: () => getWorkflowRunExecutionResultHandler,
|
|
16
|
+
getWorkflowRunsHandler: () => getWorkflowRunsHandler,
|
|
17
|
+
getWorkflowsHandler: () => getWorkflowsHandler,
|
|
18
|
+
resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
|
|
19
|
+
resumeWorkflowHandler: () => resumeWorkflowHandler,
|
|
20
|
+
startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
|
|
21
|
+
startWorkflowRunHandler: () => startWorkflowRunHandler,
|
|
22
|
+
streamWorkflowHandler: () => streamWorkflowHandler,
|
|
23
|
+
watchWorkflowHandler: () => watchWorkflowHandler
|
|
24
|
+
});
|
|
25
|
+
async function getWorkflowsHandler({ mastra }) {
|
|
26
|
+
try {
|
|
27
|
+
const workflows = mastra.getWorkflows({ serialized: false });
|
|
28
|
+
const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
|
|
29
|
+
acc[key] = {
|
|
30
|
+
name: workflow.name,
|
|
31
|
+
description: workflow.description,
|
|
32
|
+
steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
|
|
33
|
+
acc2[key2] = {
|
|
34
|
+
id: step.id,
|
|
35
|
+
description: step.description,
|
|
36
|
+
inputSchema: step.inputSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(step.inputSchema)) : void 0,
|
|
37
|
+
outputSchema: step.outputSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(step.outputSchema)) : void 0,
|
|
38
|
+
resumeSchema: step.resumeSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(step.resumeSchema)) : void 0,
|
|
39
|
+
suspendSchema: step.suspendSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(step.suspendSchema)) : void 0
|
|
40
|
+
};
|
|
41
|
+
return acc2;
|
|
42
|
+
}, {}),
|
|
43
|
+
stepGraph: workflow.serializedStepGraph,
|
|
44
|
+
inputSchema: workflow.inputSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(workflow.inputSchema)) : void 0,
|
|
45
|
+
outputSchema: workflow.outputSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(workflow.outputSchema)) : void 0
|
|
46
|
+
};
|
|
47
|
+
return acc;
|
|
48
|
+
}, {});
|
|
49
|
+
return _workflows;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error getting workflows" });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function getWorkflowsFromSystem({ mastra, workflowId }) {
|
|
55
|
+
const logger = mastra.getLogger();
|
|
56
|
+
if (!workflowId) {
|
|
57
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
58
|
+
}
|
|
59
|
+
let workflow;
|
|
60
|
+
try {
|
|
61
|
+
workflow = mastra.getWorkflow(workflowId);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
logger.debug("Error getting workflow, searching agents for workflow", error);
|
|
64
|
+
}
|
|
65
|
+
if (!workflow) {
|
|
66
|
+
logger.debug("Workflow not found, searching agents for workflow", { workflowId });
|
|
67
|
+
const agents = mastra.getAgents();
|
|
68
|
+
if (Object.keys(agents || {}).length) {
|
|
69
|
+
for (const [_, agent] of Object.entries(agents)) {
|
|
70
|
+
try {
|
|
71
|
+
const workflows = await agent.getWorkflows();
|
|
72
|
+
if (workflows[workflowId]) {
|
|
73
|
+
workflow = workflows[workflowId];
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
} catch (error) {
|
|
78
|
+
logger.debug("Error getting workflow from agent", error);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (!workflow) {
|
|
84
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
85
|
+
}
|
|
86
|
+
return { workflow };
|
|
87
|
+
}
|
|
88
|
+
async function getWorkflowByIdHandler({ mastra, workflowId }) {
|
|
89
|
+
try {
|
|
90
|
+
if (!workflowId) {
|
|
91
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
92
|
+
}
|
|
93
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
94
|
+
if (!workflow) {
|
|
95
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
|
|
99
|
+
acc[key] = {
|
|
100
|
+
id: step.id,
|
|
101
|
+
description: step.description,
|
|
102
|
+
inputSchema: step.inputSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(step.inputSchema)) : void 0,
|
|
103
|
+
outputSchema: step.outputSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(step.outputSchema)) : void 0,
|
|
104
|
+
resumeSchema: step.resumeSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(step.resumeSchema)) : void 0,
|
|
105
|
+
suspendSchema: step.suspendSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(step.suspendSchema)) : void 0
|
|
106
|
+
};
|
|
107
|
+
return acc;
|
|
108
|
+
}, {}),
|
|
109
|
+
name: workflow.name,
|
|
110
|
+
description: workflow.description,
|
|
111
|
+
stepGraph: workflow.serializedStepGraph,
|
|
112
|
+
inputSchema: workflow.inputSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(workflow.inputSchema)) : void 0,
|
|
113
|
+
outputSchema: workflow.outputSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(workflow.outputSchema)) : void 0
|
|
114
|
+
};
|
|
115
|
+
} catch (error) {
|
|
116
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error getting workflow" });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async function getWorkflowRunByIdHandler({
|
|
120
|
+
mastra,
|
|
121
|
+
workflowId,
|
|
122
|
+
runId
|
|
123
|
+
}) {
|
|
124
|
+
try {
|
|
125
|
+
if (!workflowId) {
|
|
126
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
127
|
+
}
|
|
128
|
+
if (!runId) {
|
|
129
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Run ID is required" });
|
|
130
|
+
}
|
|
131
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
132
|
+
if (!workflow) {
|
|
133
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
134
|
+
}
|
|
135
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
136
|
+
if (!run) {
|
|
137
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
138
|
+
}
|
|
139
|
+
return run;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error getting workflow run" });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async function getWorkflowRunExecutionResultHandler({
|
|
145
|
+
mastra,
|
|
146
|
+
workflowId,
|
|
147
|
+
runId
|
|
148
|
+
}) {
|
|
149
|
+
try {
|
|
150
|
+
if (!workflowId) {
|
|
151
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
152
|
+
}
|
|
153
|
+
if (!runId) {
|
|
154
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Run ID is required" });
|
|
155
|
+
}
|
|
156
|
+
const workflow = mastra.getWorkflow(workflowId);
|
|
157
|
+
if (!workflow) {
|
|
158
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
159
|
+
}
|
|
160
|
+
const executionResult = await workflow.getWorkflowRunExecutionResult(runId);
|
|
161
|
+
if (!executionResult) {
|
|
162
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run execution result not found" });
|
|
163
|
+
}
|
|
164
|
+
return executionResult;
|
|
165
|
+
} catch (error) {
|
|
166
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(500, {
|
|
167
|
+
message: error?.message || "Error getting workflow run execution result"
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
async function createWorkflowRunHandler({
|
|
172
|
+
mastra,
|
|
173
|
+
workflowId,
|
|
174
|
+
runId: prevRunId
|
|
175
|
+
}) {
|
|
176
|
+
try {
|
|
177
|
+
if (!workflowId) {
|
|
178
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
179
|
+
}
|
|
180
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
181
|
+
if (!workflow) {
|
|
182
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
183
|
+
}
|
|
184
|
+
const run = await workflow.createRunAsync({ runId: prevRunId });
|
|
185
|
+
return { runId: run.runId };
|
|
186
|
+
} catch (error) {
|
|
187
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error creating workflow run" });
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
async function startAsyncWorkflowHandler({
|
|
191
|
+
mastra,
|
|
192
|
+
runtimeContext,
|
|
193
|
+
workflowId,
|
|
194
|
+
runId,
|
|
195
|
+
inputData
|
|
196
|
+
}) {
|
|
197
|
+
try {
|
|
198
|
+
if (!workflowId) {
|
|
199
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
200
|
+
}
|
|
201
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
202
|
+
if (!workflow) {
|
|
203
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
204
|
+
}
|
|
205
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
206
|
+
const result = await _run.start({
|
|
207
|
+
inputData,
|
|
208
|
+
runtimeContext
|
|
209
|
+
});
|
|
210
|
+
return result;
|
|
211
|
+
} catch (error) {
|
|
212
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error executing workflow" });
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
async function startWorkflowRunHandler({
|
|
216
|
+
mastra,
|
|
217
|
+
runtimeContext,
|
|
218
|
+
workflowId,
|
|
219
|
+
runId,
|
|
220
|
+
inputData
|
|
221
|
+
}) {
|
|
222
|
+
try {
|
|
223
|
+
if (!workflowId) {
|
|
224
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
225
|
+
}
|
|
226
|
+
if (!runId) {
|
|
227
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to start run" });
|
|
228
|
+
}
|
|
229
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
230
|
+
if (!workflow) {
|
|
231
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
232
|
+
}
|
|
233
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
234
|
+
if (!run) {
|
|
235
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
236
|
+
}
|
|
237
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
238
|
+
void _run.start({
|
|
239
|
+
inputData,
|
|
240
|
+
runtimeContext
|
|
241
|
+
});
|
|
242
|
+
return { message: "Workflow run started" };
|
|
243
|
+
} catch (e) {
|
|
244
|
+
return chunk64U3UDTH_cjs.handleError(e, "Error starting workflow run");
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
async function watchWorkflowHandler({
|
|
248
|
+
mastra,
|
|
249
|
+
workflowId,
|
|
250
|
+
runId
|
|
251
|
+
}) {
|
|
252
|
+
try {
|
|
253
|
+
if (!workflowId) {
|
|
254
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
255
|
+
}
|
|
256
|
+
if (!runId) {
|
|
257
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to watch workflow" });
|
|
258
|
+
}
|
|
259
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
260
|
+
if (!workflow) {
|
|
261
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
262
|
+
}
|
|
263
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
264
|
+
if (!run) {
|
|
265
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
266
|
+
}
|
|
267
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
268
|
+
let unwatch;
|
|
269
|
+
let asyncRef = null;
|
|
270
|
+
const stream = new web.ReadableStream({
|
|
271
|
+
start(controller) {
|
|
272
|
+
unwatch = _run.watch(({ type, payload, eventTimestamp }) => {
|
|
273
|
+
controller.enqueue(JSON.stringify({ type, payload, eventTimestamp, runId }));
|
|
274
|
+
if (asyncRef) {
|
|
275
|
+
clearImmediate(asyncRef);
|
|
276
|
+
asyncRef = null;
|
|
277
|
+
}
|
|
278
|
+
asyncRef = setImmediate(async () => {
|
|
279
|
+
const runDone = payload.workflowState.status !== "running";
|
|
280
|
+
if (runDone) {
|
|
281
|
+
controller.close();
|
|
282
|
+
unwatch?.();
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
},
|
|
287
|
+
cancel() {
|
|
288
|
+
unwatch?.();
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
return stream;
|
|
292
|
+
} catch (error) {
|
|
293
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error watching workflow");
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
async function streamWorkflowHandler({
|
|
297
|
+
mastra,
|
|
298
|
+
runtimeContext,
|
|
299
|
+
workflowId,
|
|
300
|
+
runId,
|
|
301
|
+
inputData
|
|
302
|
+
}) {
|
|
303
|
+
try {
|
|
304
|
+
if (!workflowId) {
|
|
305
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
306
|
+
}
|
|
307
|
+
if (!runId) {
|
|
308
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to resume workflow" });
|
|
309
|
+
}
|
|
310
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
311
|
+
if (!workflow) {
|
|
312
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
313
|
+
}
|
|
314
|
+
const run = await workflow.createRunAsync({ runId });
|
|
315
|
+
const result = run.stream({
|
|
316
|
+
inputData,
|
|
317
|
+
runtimeContext
|
|
318
|
+
});
|
|
319
|
+
return result;
|
|
320
|
+
} catch (error) {
|
|
321
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error executing workflow");
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
async function resumeAsyncWorkflowHandler({
|
|
325
|
+
mastra,
|
|
326
|
+
workflowId,
|
|
327
|
+
runId,
|
|
328
|
+
body,
|
|
329
|
+
runtimeContext
|
|
330
|
+
}) {
|
|
331
|
+
try {
|
|
332
|
+
if (!workflowId) {
|
|
333
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
334
|
+
}
|
|
335
|
+
if (!runId) {
|
|
336
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to resume workflow" });
|
|
337
|
+
}
|
|
338
|
+
if (!body.step) {
|
|
339
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "step required to resume workflow" });
|
|
340
|
+
}
|
|
341
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
342
|
+
if (!workflow) {
|
|
343
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
344
|
+
}
|
|
345
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
346
|
+
if (!run) {
|
|
347
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
348
|
+
}
|
|
349
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
350
|
+
const result = await _run.resume({
|
|
351
|
+
step: body.step,
|
|
352
|
+
resumeData: body.resumeData,
|
|
353
|
+
runtimeContext
|
|
354
|
+
});
|
|
355
|
+
return result;
|
|
356
|
+
} catch (error) {
|
|
357
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error resuming workflow step");
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
async function resumeWorkflowHandler({
|
|
361
|
+
mastra,
|
|
362
|
+
workflowId,
|
|
363
|
+
runId,
|
|
364
|
+
body,
|
|
365
|
+
runtimeContext
|
|
366
|
+
}) {
|
|
367
|
+
try {
|
|
368
|
+
if (!workflowId) {
|
|
369
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
370
|
+
}
|
|
371
|
+
if (!runId) {
|
|
372
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to resume workflow" });
|
|
373
|
+
}
|
|
374
|
+
if (!body.step) {
|
|
375
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "step required to resume workflow" });
|
|
376
|
+
}
|
|
377
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
378
|
+
if (!workflow) {
|
|
379
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
380
|
+
}
|
|
381
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
382
|
+
if (!run) {
|
|
383
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
384
|
+
}
|
|
385
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
386
|
+
void _run.resume({
|
|
387
|
+
step: body.step,
|
|
388
|
+
resumeData: body.resumeData,
|
|
389
|
+
runtimeContext
|
|
390
|
+
});
|
|
391
|
+
return { message: "Workflow run resumed" };
|
|
392
|
+
} catch (error) {
|
|
393
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error resuming workflow");
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
async function getWorkflowRunsHandler({
|
|
397
|
+
mastra,
|
|
398
|
+
workflowId,
|
|
399
|
+
fromDate,
|
|
400
|
+
toDate,
|
|
401
|
+
limit,
|
|
402
|
+
offset,
|
|
403
|
+
resourceId
|
|
404
|
+
}) {
|
|
405
|
+
try {
|
|
406
|
+
if (!workflowId) {
|
|
407
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
408
|
+
}
|
|
409
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
410
|
+
if (!workflow) {
|
|
411
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
412
|
+
}
|
|
413
|
+
const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
|
|
414
|
+
runs: [],
|
|
415
|
+
total: 0
|
|
416
|
+
};
|
|
417
|
+
return workflowRuns;
|
|
418
|
+
} catch (error) {
|
|
419
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting workflow runs");
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
exports.createWorkflowRunHandler = createWorkflowRunHandler;
|
|
424
|
+
exports.getWorkflowByIdHandler = getWorkflowByIdHandler;
|
|
425
|
+
exports.getWorkflowRunByIdHandler = getWorkflowRunByIdHandler;
|
|
426
|
+
exports.getWorkflowRunExecutionResultHandler = getWorkflowRunExecutionResultHandler;
|
|
427
|
+
exports.getWorkflowRunsHandler = getWorkflowRunsHandler;
|
|
428
|
+
exports.getWorkflowsHandler = getWorkflowsHandler;
|
|
429
|
+
exports.resumeAsyncWorkflowHandler = resumeAsyncWorkflowHandler;
|
|
430
|
+
exports.resumeWorkflowHandler = resumeWorkflowHandler;
|
|
431
|
+
exports.startAsyncWorkflowHandler = startAsyncWorkflowHandler;
|
|
432
|
+
exports.startWorkflowRunHandler = startWorkflowRunHandler;
|
|
433
|
+
exports.streamWorkflowHandler = streamWorkflowHandler;
|
|
434
|
+
exports.watchWorkflowHandler = watchWorkflowHandler;
|
|
435
|
+
exports.workflows_exports = workflows_exports;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunk57CJTIPW_cjs = require('./chunk-57CJTIPW.cjs');
|
|
4
|
+
var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
|
|
5
|
+
var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
|
|
6
|
+
var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
|
|
6
7
|
|
|
7
8
|
// src/server/handlers/network.ts
|
|
8
9
|
var network_exports = {};
|
|
9
|
-
|
|
10
|
+
chunk75ZPJI57_cjs.__export(network_exports, {
|
|
10
11
|
generateHandler: () => generateHandler,
|
|
11
12
|
getNetworkByIdHandler: () => getNetworkByIdHandler,
|
|
12
13
|
getNetworksHandler: () => getNetworksHandler,
|
|
@@ -46,7 +47,7 @@ async function getNetworksHandler({
|
|
|
46
47
|
);
|
|
47
48
|
return serializedNetworks;
|
|
48
49
|
} catch (error) {
|
|
49
|
-
return
|
|
50
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting networks");
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
async function getNetworkByIdHandler({
|
|
@@ -61,7 +62,7 @@ async function getNetworkByIdHandler({
|
|
|
61
62
|
return network2.formatAgentId(routingAgent2.name) === networkId;
|
|
62
63
|
});
|
|
63
64
|
if (!network) {
|
|
64
|
-
throw new
|
|
65
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Network not found" });
|
|
65
66
|
}
|
|
66
67
|
const routingAgent = network.getRoutingAgent();
|
|
67
68
|
const routingLLM = await routingAgent.getLLM({ runtimeContext });
|
|
@@ -87,7 +88,7 @@ async function getNetworkByIdHandler({
|
|
|
87
88
|
};
|
|
88
89
|
return serializedNetwork;
|
|
89
90
|
} catch (error) {
|
|
90
|
-
return
|
|
91
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting network by ID");
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
async function generateHandler({
|
|
@@ -99,14 +100,14 @@ async function generateHandler({
|
|
|
99
100
|
try {
|
|
100
101
|
const network = mastra.getNetwork(networkId);
|
|
101
102
|
if (!network) {
|
|
102
|
-
throw new
|
|
103
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Network not found" });
|
|
103
104
|
}
|
|
104
|
-
|
|
105
|
+
chunk57CJTIPW_cjs.validateBody({ messages: body.messages });
|
|
105
106
|
const { messages, ...rest } = body;
|
|
106
107
|
const result = await network.generate(messages, { ...rest, runtimeContext });
|
|
107
108
|
return result;
|
|
108
109
|
} catch (error) {
|
|
109
|
-
return
|
|
110
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error generating from network");
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
113
|
async function streamGenerateHandler({
|
|
@@ -118,9 +119,9 @@ async function streamGenerateHandler({
|
|
|
118
119
|
try {
|
|
119
120
|
const network = mastra.getNetwork(networkId);
|
|
120
121
|
if (!network) {
|
|
121
|
-
throw new
|
|
122
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Network not found" });
|
|
122
123
|
}
|
|
123
|
-
|
|
124
|
+
chunk57CJTIPW_cjs.validateBody({ messages: body.messages });
|
|
124
125
|
const { messages, output, ...rest } = body;
|
|
125
126
|
const streamResult = await network.stream(messages, {
|
|
126
127
|
output,
|
|
@@ -136,7 +137,7 @@ async function streamGenerateHandler({
|
|
|
136
137
|
});
|
|
137
138
|
return streamResponse;
|
|
138
139
|
} catch (error) {
|
|
139
|
-
return
|
|
140
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error streaming from network");
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
143
|
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk57CJTIPW_cjs = require('./chunk-57CJTIPW.cjs');
|
|
4
|
+
var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
|
|
5
|
+
var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
|
|
6
|
+
var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
|
|
7
|
+
var stream = require('stream');
|
|
8
|
+
|
|
9
|
+
// src/server/handlers/voice.ts
|
|
10
|
+
var voice_exports = {};
|
|
11
|
+
chunk75ZPJI57_cjs.__export(voice_exports, {
|
|
12
|
+
generateSpeechHandler: () => generateSpeechHandler,
|
|
13
|
+
getListenerHandler: () => getListenerHandler,
|
|
14
|
+
getSpeakersHandler: () => getSpeakersHandler,
|
|
15
|
+
transcribeSpeechHandler: () => transcribeSpeechHandler
|
|
16
|
+
});
|
|
17
|
+
async function getSpeakersHandler({ mastra, agentId }) {
|
|
18
|
+
try {
|
|
19
|
+
if (!agentId) {
|
|
20
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent ID is required" });
|
|
21
|
+
}
|
|
22
|
+
const agent = mastra.getAgent(agentId);
|
|
23
|
+
if (!agent) {
|
|
24
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
25
|
+
}
|
|
26
|
+
const voice = await agent.getVoice();
|
|
27
|
+
if (!voice) {
|
|
28
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
29
|
+
}
|
|
30
|
+
const speakers = await voice.getSpeakers();
|
|
31
|
+
return speakers;
|
|
32
|
+
} catch (error) {
|
|
33
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting speakers");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function generateSpeechHandler({
|
|
37
|
+
mastra,
|
|
38
|
+
agentId,
|
|
39
|
+
body
|
|
40
|
+
}) {
|
|
41
|
+
try {
|
|
42
|
+
if (!agentId) {
|
|
43
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent ID is required" });
|
|
44
|
+
}
|
|
45
|
+
chunk57CJTIPW_cjs.validateBody({
|
|
46
|
+
text: body?.text
|
|
47
|
+
});
|
|
48
|
+
const agent = mastra.getAgent(agentId);
|
|
49
|
+
if (!agent) {
|
|
50
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
51
|
+
}
|
|
52
|
+
const voice = await agent.getVoice();
|
|
53
|
+
if (!voice) {
|
|
54
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
55
|
+
}
|
|
56
|
+
const audioStream = await voice.speak(body.text, { speaker: body.speakerId });
|
|
57
|
+
if (!audioStream) {
|
|
58
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: "Failed to generate speech" });
|
|
59
|
+
}
|
|
60
|
+
return audioStream;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error generating speech");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function transcribeSpeechHandler({
|
|
66
|
+
mastra,
|
|
67
|
+
agentId,
|
|
68
|
+
body
|
|
69
|
+
}) {
|
|
70
|
+
try {
|
|
71
|
+
if (!agentId) {
|
|
72
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent ID is required" });
|
|
73
|
+
}
|
|
74
|
+
if (!body?.audioData) {
|
|
75
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Audio data is required" });
|
|
76
|
+
}
|
|
77
|
+
const agent = mastra.getAgent(agentId);
|
|
78
|
+
if (!agent) {
|
|
79
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
80
|
+
}
|
|
81
|
+
const voice = await agent.getVoice();
|
|
82
|
+
if (!voice) {
|
|
83
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
84
|
+
}
|
|
85
|
+
const audioStream = new stream.Readable();
|
|
86
|
+
audioStream.push(body.audioData);
|
|
87
|
+
audioStream.push(null);
|
|
88
|
+
const text = await voice.listen(audioStream, body.options);
|
|
89
|
+
return { text };
|
|
90
|
+
} catch (error) {
|
|
91
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error transcribing speech");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async function getListenerHandler({ mastra, agentId }) {
|
|
95
|
+
try {
|
|
96
|
+
if (!agentId) {
|
|
97
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent ID is required" });
|
|
98
|
+
}
|
|
99
|
+
const agent = mastra.getAgent(agentId);
|
|
100
|
+
if (!agent) {
|
|
101
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
102
|
+
}
|
|
103
|
+
const voice = await agent.getVoice();
|
|
104
|
+
if (!voice) {
|
|
105
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
106
|
+
}
|
|
107
|
+
const listeners = await voice.getListener();
|
|
108
|
+
return listeners;
|
|
109
|
+
} catch (error) {
|
|
110
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting listeners");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
exports.generateSpeechHandler = generateSpeechHandler;
|
|
115
|
+
exports.getListenerHandler = getListenerHandler;
|
|
116
|
+
exports.getSpeakersHandler = getSpeakersHandler;
|
|
117
|
+
exports.transcribeSpeechHandler = transcribeSpeechHandler;
|
|
118
|
+
exports.voice_exports = voice_exports;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { stringify, esm_default } from './chunk-
|
|
2
|
-
import { validateBody } from './chunk-
|
|
3
|
-
import { handleError } from './chunk-
|
|
4
|
-
import {
|
|
1
|
+
import { stringify, esm_default } from './chunk-OSZM4EAY.js';
|
|
2
|
+
import { validateBody } from './chunk-H5PTF3Y4.js';
|
|
3
|
+
import { handleError } from './chunk-M5ABIP7D.js';
|
|
4
|
+
import { HTTPException } from './chunk-NYN7KFXL.js';
|
|
5
|
+
import { __export } from './chunk-MLKGABMK.js';
|
|
5
6
|
import { isVercelTool } from '@mastra/core/tools';
|
|
6
7
|
|
|
7
8
|
// src/server/handlers/tools.ts
|
|
@@ -98,7 +99,8 @@ async function executeAgentToolHandler({
|
|
|
98
99
|
if (!agent) {
|
|
99
100
|
throw new HTTPException(404, { message: "Tool not found" });
|
|
100
101
|
}
|
|
101
|
-
const
|
|
102
|
+
const agentTools = await agent.getTools({ runtimeContext });
|
|
103
|
+
const tool = Object.values(agentTools || {}).find((tool2) => tool2.id === toolId);
|
|
102
104
|
if (!tool) {
|
|
103
105
|
throw new HTTPException(404, { message: "Tool not found" });
|
|
104
106
|
}
|