@mastra/server 0.0.0-cli-debug-2-20250611100354 → 0.0.0-cloudflare-deployer-dont-install-deps-20250714111754
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/LICENSE.md +11 -42
- package/dist/_tsup-dts-rollup.d.cts +275 -28
- package/dist/_tsup-dts-rollup.d.ts +275 -28
- package/dist/{chunk-OCWPVYNI.cjs → chunk-2KZFMI6P.cjs} +1 -0
- package/dist/{chunk-VPNDC2DI.cjs → chunk-2SLFAFTR.cjs} +12 -12
- package/dist/chunk-3CNDE7QY.cjs +308 -0
- package/dist/{chunk-QLG2PFHE.js → chunk-4D66QEKC.js} +2 -2
- package/dist/{chunk-TEZOEGR4.js → chunk-5PQQ42EZ.js} +8 -8
- package/dist/{chunk-BNEY4P4P.cjs → chunk-7TP2LX5L.cjs} +16 -16
- package/dist/chunk-B2PAS2IB.cjs +514 -0
- package/dist/{chunk-6F2H7Y45.js → chunk-BK4XT6EG.js} +29 -14
- package/dist/{chunk-57CJTIPW.cjs → chunk-CCGRCYWJ.cjs} +2 -2
- package/dist/{chunk-C7564HUT.js → chunk-CRCR3ZUK.js} +3 -3
- package/dist/{chunk-TJO277H7.cjs → chunk-FRVBFMO2.cjs} +20 -20
- package/dist/{chunk-B4MQFJ7G.cjs → chunk-G7KH752Y.cjs} +5 -5
- package/dist/{chunk-7IBZ4L35.js → chunk-H7DMHBKY.js} +181 -27
- package/dist/{chunk-UZ7FJ66C.cjs → chunk-JMLYCXMK.cjs} +43 -43
- package/dist/{chunk-CP55EVBK.js → chunk-KHZKYUNR.js} +15 -11
- package/dist/{chunk-I7KJZNX5.js → chunk-KOHWJYJT.js} +110 -25
- package/dist/{chunk-NYN7KFXL.js → chunk-LCM566I4.js} +1 -0
- package/dist/chunk-LF7P5PLR.js +14 -0
- package/dist/{chunk-XUGQSVZ4.cjs → chunk-LI436ITD.cjs} +107 -69
- package/dist/{chunk-HYP7B2TL.js → chunk-LRCAAFUA.js} +4 -4
- package/dist/{chunk-JEWNMAYQ.cjs → chunk-LZ3VJXSO.cjs} +43 -28
- package/dist/{chunk-WKWHYFX4.js → chunk-MEGCYGBU.js} +108 -70
- package/dist/chunk-PZQDCRPV.cjs +16 -0
- package/dist/{chunk-IMBY5XUG.cjs → chunk-QGX47B5D.cjs} +7 -7
- package/dist/{chunk-BFOA2QQY.js → chunk-RG473F6Y.js} +2 -2
- package/dist/{chunk-CMMOIUFC.cjs → chunk-RHSWAXKB.cjs} +34 -30
- package/dist/{chunk-H5PTF3Y4.js → chunk-RSEO4XPX.js} +1 -1
- package/dist/{chunk-55DOQLP6.js → chunk-WNVFNNWN.js} +2 -2
- 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 +11 -11
- package/dist/server/handlers/legacyWorkflows.js +1 -1
- package/dist/server/handlers/logs.cjs +4 -4
- package/dist/server/handlers/logs.js +1 -1
- package/dist/server/handlers/memory.cjs +17 -9
- package/dist/server/handlers/memory.d.cts +2 -0
- package/dist/server/handlers/memory.d.ts +2 -0
- 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 +218 -0
- package/dist/server/handlers/vNextNetwork.d.cts +6 -0
- package/dist/server/handlers/vNextNetwork.d.ts +6 -0
- package/dist/server/handlers/vNextNetwork.js +211 -0
- package/dist/server/handlers/vector.cjs +7 -7
- package/dist/server/handlers/vector.js +1 -1
- package/dist/server/handlers/voice.cjs +5 -5
- package/dist/server/handlers/voice.js +1 -1
- package/dist/server/handlers/workflows.cjs +24 -12
- package/dist/server/handlers/workflows.d.cts +3 -0
- package/dist/server/handlers/workflows.d.ts +3 -0
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +20 -20
- package/dist/server/handlers.js +10 -10
- package/package.json +11 -12
- package/dist/chunk-64U3UDTH.cjs +0 -13
- package/dist/chunk-6TJSHFCJ.cjs +0 -221
- package/dist/chunk-JKF6PRPU.cjs +0 -357
- package/dist/chunk-M5ABIP7D.js +0 -11
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkLI436ITD_cjs = require('./chunk-LI436ITD.cjs');
|
|
4
|
+
var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
|
|
5
|
+
var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
|
|
6
|
+
var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
|
|
7
|
+
var web = require('stream/web');
|
|
8
|
+
|
|
9
|
+
// src/server/handlers/workflows.ts
|
|
10
|
+
var workflows_exports = {};
|
|
11
|
+
chunk75ZPJI57_cjs.__export(workflows_exports, {
|
|
12
|
+
cancelWorkflowRunHandler: () => cancelWorkflowRunHandler,
|
|
13
|
+
createWorkflowRunHandler: () => createWorkflowRunHandler,
|
|
14
|
+
getWorkflowByIdHandler: () => getWorkflowByIdHandler,
|
|
15
|
+
getWorkflowRunByIdHandler: () => getWorkflowRunByIdHandler,
|
|
16
|
+
getWorkflowRunExecutionResultHandler: () => getWorkflowRunExecutionResultHandler,
|
|
17
|
+
getWorkflowRunsHandler: () => getWorkflowRunsHandler,
|
|
18
|
+
getWorkflowsHandler: () => getWorkflowsHandler,
|
|
19
|
+
resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
|
|
20
|
+
resumeWorkflowHandler: () => resumeWorkflowHandler,
|
|
21
|
+
sendWorkflowRunEventHandler: () => sendWorkflowRunEventHandler,
|
|
22
|
+
startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
|
|
23
|
+
startWorkflowRunHandler: () => startWorkflowRunHandler,
|
|
24
|
+
streamWorkflowHandler: () => streamWorkflowHandler,
|
|
25
|
+
watchWorkflowHandler: () => watchWorkflowHandler
|
|
26
|
+
});
|
|
27
|
+
function getSteps(steps, path) {
|
|
28
|
+
return Object.entries(steps).reduce((acc, [key, step]) => {
|
|
29
|
+
const fullKey = path ? `${path}.${key}` : key;
|
|
30
|
+
acc[fullKey] = {
|
|
31
|
+
id: step.id,
|
|
32
|
+
description: step.description,
|
|
33
|
+
inputSchema: step.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.inputSchema)) : void 0,
|
|
34
|
+
outputSchema: step.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.outputSchema)) : void 0,
|
|
35
|
+
resumeSchema: step.resumeSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.resumeSchema)) : void 0,
|
|
36
|
+
suspendSchema: step.suspendSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.suspendSchema)) : void 0,
|
|
37
|
+
isWorkflow: step.component === "WORKFLOW"
|
|
38
|
+
};
|
|
39
|
+
if (step.component === "WORKFLOW" && step.steps) {
|
|
40
|
+
const nestedSteps = getSteps(step.steps, fullKey) || {};
|
|
41
|
+
acc = { ...acc, ...nestedSteps };
|
|
42
|
+
}
|
|
43
|
+
return acc;
|
|
44
|
+
}, {});
|
|
45
|
+
}
|
|
46
|
+
async function getWorkflowsHandler({ mastra }) {
|
|
47
|
+
try {
|
|
48
|
+
const workflows = mastra.getWorkflows({ serialized: false });
|
|
49
|
+
const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
|
|
50
|
+
acc[key] = {
|
|
51
|
+
name: workflow.name,
|
|
52
|
+
description: workflow.description,
|
|
53
|
+
steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
|
|
54
|
+
acc2[key2] = {
|
|
55
|
+
id: step.id,
|
|
56
|
+
description: step.description,
|
|
57
|
+
inputSchema: step.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.inputSchema)) : void 0,
|
|
58
|
+
outputSchema: step.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.outputSchema)) : void 0,
|
|
59
|
+
resumeSchema: step.resumeSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.resumeSchema)) : void 0,
|
|
60
|
+
suspendSchema: step.suspendSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.suspendSchema)) : void 0
|
|
61
|
+
};
|
|
62
|
+
return acc2;
|
|
63
|
+
}, {}),
|
|
64
|
+
allSteps: getSteps(workflow.steps) || {},
|
|
65
|
+
stepGraph: workflow.serializedStepGraph,
|
|
66
|
+
inputSchema: workflow.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(workflow.inputSchema)) : void 0,
|
|
67
|
+
outputSchema: workflow.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(workflow.outputSchema)) : void 0
|
|
68
|
+
};
|
|
69
|
+
return acc;
|
|
70
|
+
}, {});
|
|
71
|
+
return _workflows;
|
|
72
|
+
} catch (error) {
|
|
73
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error getting workflows");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async function getWorkflowsFromSystem({ mastra, workflowId }) {
|
|
77
|
+
const logger = mastra.getLogger();
|
|
78
|
+
if (!workflowId) {
|
|
79
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
80
|
+
}
|
|
81
|
+
let workflow;
|
|
82
|
+
try {
|
|
83
|
+
workflow = mastra.getWorkflow(workflowId);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
logger.debug("Error getting workflow, searching agents for workflow", error);
|
|
86
|
+
}
|
|
87
|
+
if (!workflow) {
|
|
88
|
+
logger.debug("Workflow not found, searching agents for workflow", { workflowId });
|
|
89
|
+
const agents = mastra.getAgents();
|
|
90
|
+
if (Object.keys(agents || {}).length) {
|
|
91
|
+
for (const [_, agent] of Object.entries(agents)) {
|
|
92
|
+
try {
|
|
93
|
+
const workflows = await agent.getWorkflows();
|
|
94
|
+
if (workflows[workflowId]) {
|
|
95
|
+
workflow = workflows[workflowId];
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
break;
|
|
99
|
+
} catch (error) {
|
|
100
|
+
logger.debug("Error getting workflow from agent", error);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (!workflow) {
|
|
106
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
107
|
+
}
|
|
108
|
+
return { workflow };
|
|
109
|
+
}
|
|
110
|
+
async function getWorkflowByIdHandler({ mastra, workflowId }) {
|
|
111
|
+
try {
|
|
112
|
+
if (!workflowId) {
|
|
113
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
114
|
+
}
|
|
115
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
116
|
+
if (!workflow) {
|
|
117
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
|
|
121
|
+
acc[key] = {
|
|
122
|
+
id: step.id,
|
|
123
|
+
description: step.description,
|
|
124
|
+
inputSchema: step.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.inputSchema)) : void 0,
|
|
125
|
+
outputSchema: step.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.outputSchema)) : void 0,
|
|
126
|
+
resumeSchema: step.resumeSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.resumeSchema)) : void 0,
|
|
127
|
+
suspendSchema: step.suspendSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.suspendSchema)) : void 0
|
|
128
|
+
};
|
|
129
|
+
return acc;
|
|
130
|
+
}, {}),
|
|
131
|
+
allSteps: getSteps(workflow.steps) || {},
|
|
132
|
+
name: workflow.name,
|
|
133
|
+
description: workflow.description,
|
|
134
|
+
stepGraph: workflow.serializedStepGraph,
|
|
135
|
+
inputSchema: workflow.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(workflow.inputSchema)) : void 0,
|
|
136
|
+
outputSchema: workflow.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(workflow.outputSchema)) : void 0
|
|
137
|
+
};
|
|
138
|
+
} catch (error) {
|
|
139
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error getting workflow");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async function getWorkflowRunByIdHandler({
|
|
143
|
+
mastra,
|
|
144
|
+
workflowId,
|
|
145
|
+
runId
|
|
146
|
+
}) {
|
|
147
|
+
try {
|
|
148
|
+
if (!workflowId) {
|
|
149
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
150
|
+
}
|
|
151
|
+
if (!runId) {
|
|
152
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Run ID is required" });
|
|
153
|
+
}
|
|
154
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
155
|
+
if (!workflow) {
|
|
156
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
157
|
+
}
|
|
158
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
159
|
+
if (!run) {
|
|
160
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
161
|
+
}
|
|
162
|
+
return run;
|
|
163
|
+
} catch (error) {
|
|
164
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error getting workflow run");
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async function getWorkflowRunExecutionResultHandler({
|
|
168
|
+
mastra,
|
|
169
|
+
workflowId,
|
|
170
|
+
runId
|
|
171
|
+
}) {
|
|
172
|
+
try {
|
|
173
|
+
if (!workflowId) {
|
|
174
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
175
|
+
}
|
|
176
|
+
if (!runId) {
|
|
177
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Run ID is required" });
|
|
178
|
+
}
|
|
179
|
+
const workflow = mastra.getWorkflow(workflowId);
|
|
180
|
+
if (!workflow) {
|
|
181
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
182
|
+
}
|
|
183
|
+
const executionResult = await workflow.getWorkflowRunExecutionResult(runId);
|
|
184
|
+
if (!executionResult) {
|
|
185
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run execution result not found" });
|
|
186
|
+
}
|
|
187
|
+
return executionResult;
|
|
188
|
+
} catch (error) {
|
|
189
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error getting workflow run execution result");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
async function createWorkflowRunHandler({
|
|
193
|
+
mastra,
|
|
194
|
+
workflowId,
|
|
195
|
+
runId: prevRunId
|
|
196
|
+
}) {
|
|
197
|
+
try {
|
|
198
|
+
if (!workflowId) {
|
|
199
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
200
|
+
}
|
|
201
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
202
|
+
if (!workflow) {
|
|
203
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
204
|
+
}
|
|
205
|
+
const run = await workflow.createRunAsync({ runId: prevRunId });
|
|
206
|
+
return { runId: run.runId };
|
|
207
|
+
} catch (error) {
|
|
208
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error creating workflow run");
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async function startAsyncWorkflowHandler({
|
|
212
|
+
mastra,
|
|
213
|
+
runtimeContext,
|
|
214
|
+
workflowId,
|
|
215
|
+
runId,
|
|
216
|
+
inputData
|
|
217
|
+
}) {
|
|
218
|
+
try {
|
|
219
|
+
if (!workflowId) {
|
|
220
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
221
|
+
}
|
|
222
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
223
|
+
if (!workflow) {
|
|
224
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
225
|
+
}
|
|
226
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
227
|
+
const result = await _run.start({
|
|
228
|
+
inputData,
|
|
229
|
+
runtimeContext
|
|
230
|
+
});
|
|
231
|
+
return result;
|
|
232
|
+
} catch (error) {
|
|
233
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error starting async workflow");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
async function startWorkflowRunHandler({
|
|
237
|
+
mastra,
|
|
238
|
+
runtimeContext,
|
|
239
|
+
workflowId,
|
|
240
|
+
runId,
|
|
241
|
+
inputData
|
|
242
|
+
}) {
|
|
243
|
+
try {
|
|
244
|
+
if (!workflowId) {
|
|
245
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
246
|
+
}
|
|
247
|
+
if (!runId) {
|
|
248
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to start run" });
|
|
249
|
+
}
|
|
250
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
251
|
+
if (!workflow) {
|
|
252
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
253
|
+
}
|
|
254
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
255
|
+
if (!run) {
|
|
256
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
257
|
+
}
|
|
258
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
259
|
+
void _run.start({
|
|
260
|
+
inputData,
|
|
261
|
+
runtimeContext
|
|
262
|
+
});
|
|
263
|
+
return { message: "Workflow run started" };
|
|
264
|
+
} catch (e) {
|
|
265
|
+
return chunkPZQDCRPV_cjs.handleError(e, "Error starting workflow run");
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
async function watchWorkflowHandler({
|
|
269
|
+
mastra,
|
|
270
|
+
workflowId,
|
|
271
|
+
runId
|
|
272
|
+
}) {
|
|
273
|
+
try {
|
|
274
|
+
if (!workflowId) {
|
|
275
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
276
|
+
}
|
|
277
|
+
if (!runId) {
|
|
278
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to watch workflow" });
|
|
279
|
+
}
|
|
280
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
281
|
+
if (!workflow) {
|
|
282
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
283
|
+
}
|
|
284
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
285
|
+
if (!run) {
|
|
286
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
287
|
+
}
|
|
288
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
289
|
+
let unwatch;
|
|
290
|
+
let asyncRef = null;
|
|
291
|
+
const stream = new web.ReadableStream({
|
|
292
|
+
start(controller) {
|
|
293
|
+
unwatch = _run.watch(({ type, payload, eventTimestamp }) => {
|
|
294
|
+
controller.enqueue(JSON.stringify({ type, payload, eventTimestamp, runId }));
|
|
295
|
+
if (asyncRef) {
|
|
296
|
+
clearImmediate(asyncRef);
|
|
297
|
+
asyncRef = null;
|
|
298
|
+
}
|
|
299
|
+
asyncRef = setImmediate(async () => {
|
|
300
|
+
const runDone = payload.workflowState.status !== "running";
|
|
301
|
+
if (runDone) {
|
|
302
|
+
controller.close();
|
|
303
|
+
unwatch?.();
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
},
|
|
308
|
+
cancel() {
|
|
309
|
+
unwatch?.();
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
return stream;
|
|
313
|
+
} catch (error) {
|
|
314
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error watching workflow");
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
async function streamWorkflowHandler({
|
|
318
|
+
mastra,
|
|
319
|
+
runtimeContext,
|
|
320
|
+
workflowId,
|
|
321
|
+
runId,
|
|
322
|
+
inputData
|
|
323
|
+
}) {
|
|
324
|
+
try {
|
|
325
|
+
if (!workflowId) {
|
|
326
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
327
|
+
}
|
|
328
|
+
if (!runId) {
|
|
329
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to resume workflow" });
|
|
330
|
+
}
|
|
331
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
332
|
+
if (!workflow) {
|
|
333
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
334
|
+
}
|
|
335
|
+
const run = await workflow.createRunAsync({ runId });
|
|
336
|
+
const result = run.stream({
|
|
337
|
+
inputData,
|
|
338
|
+
runtimeContext
|
|
339
|
+
});
|
|
340
|
+
return result;
|
|
341
|
+
} catch (error) {
|
|
342
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error executing workflow");
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
async function resumeAsyncWorkflowHandler({
|
|
346
|
+
mastra,
|
|
347
|
+
workflowId,
|
|
348
|
+
runId,
|
|
349
|
+
body,
|
|
350
|
+
runtimeContext
|
|
351
|
+
}) {
|
|
352
|
+
try {
|
|
353
|
+
if (!workflowId) {
|
|
354
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
355
|
+
}
|
|
356
|
+
if (!runId) {
|
|
357
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to resume workflow" });
|
|
358
|
+
}
|
|
359
|
+
if (!body.step) {
|
|
360
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "step required to resume workflow" });
|
|
361
|
+
}
|
|
362
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
363
|
+
if (!workflow) {
|
|
364
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
365
|
+
}
|
|
366
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
367
|
+
if (!run) {
|
|
368
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
369
|
+
}
|
|
370
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
371
|
+
const result = await _run.resume({
|
|
372
|
+
step: body.step,
|
|
373
|
+
resumeData: body.resumeData,
|
|
374
|
+
runtimeContext
|
|
375
|
+
});
|
|
376
|
+
return result;
|
|
377
|
+
} catch (error) {
|
|
378
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error resuming workflow step");
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
async function resumeWorkflowHandler({
|
|
382
|
+
mastra,
|
|
383
|
+
workflowId,
|
|
384
|
+
runId,
|
|
385
|
+
body,
|
|
386
|
+
runtimeContext
|
|
387
|
+
}) {
|
|
388
|
+
try {
|
|
389
|
+
if (!workflowId) {
|
|
390
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
391
|
+
}
|
|
392
|
+
if (!runId) {
|
|
393
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to resume workflow" });
|
|
394
|
+
}
|
|
395
|
+
if (!body.step) {
|
|
396
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "step required to resume workflow" });
|
|
397
|
+
}
|
|
398
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
399
|
+
if (!workflow) {
|
|
400
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
401
|
+
}
|
|
402
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
403
|
+
if (!run) {
|
|
404
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
405
|
+
}
|
|
406
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
407
|
+
void _run.resume({
|
|
408
|
+
step: body.step,
|
|
409
|
+
resumeData: body.resumeData,
|
|
410
|
+
runtimeContext
|
|
411
|
+
});
|
|
412
|
+
return { message: "Workflow run resumed" };
|
|
413
|
+
} catch (error) {
|
|
414
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error resuming workflow");
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
async function getWorkflowRunsHandler({
|
|
418
|
+
mastra,
|
|
419
|
+
workflowId,
|
|
420
|
+
fromDate,
|
|
421
|
+
toDate,
|
|
422
|
+
limit,
|
|
423
|
+
offset,
|
|
424
|
+
resourceId
|
|
425
|
+
}) {
|
|
426
|
+
try {
|
|
427
|
+
if (!workflowId) {
|
|
428
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
429
|
+
}
|
|
430
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
431
|
+
if (!workflow) {
|
|
432
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
433
|
+
}
|
|
434
|
+
const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
|
|
435
|
+
runs: [],
|
|
436
|
+
total: 0
|
|
437
|
+
};
|
|
438
|
+
return workflowRuns;
|
|
439
|
+
} catch (error) {
|
|
440
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error getting workflow runs");
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
async function cancelWorkflowRunHandler({
|
|
444
|
+
mastra,
|
|
445
|
+
workflowId,
|
|
446
|
+
runId
|
|
447
|
+
}) {
|
|
448
|
+
try {
|
|
449
|
+
if (!workflowId) {
|
|
450
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
451
|
+
}
|
|
452
|
+
if (!runId) {
|
|
453
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to cancel workflow run" });
|
|
454
|
+
}
|
|
455
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
456
|
+
if (!workflow) {
|
|
457
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
458
|
+
}
|
|
459
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
460
|
+
if (!run) {
|
|
461
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
462
|
+
}
|
|
463
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
464
|
+
await _run.cancel();
|
|
465
|
+
return { message: "Workflow run cancelled" };
|
|
466
|
+
} catch (error) {
|
|
467
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error canceling workflow run");
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
async function sendWorkflowRunEventHandler({
|
|
471
|
+
mastra,
|
|
472
|
+
workflowId,
|
|
473
|
+
runId,
|
|
474
|
+
event,
|
|
475
|
+
data
|
|
476
|
+
}) {
|
|
477
|
+
try {
|
|
478
|
+
if (!workflowId) {
|
|
479
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
480
|
+
}
|
|
481
|
+
if (!runId) {
|
|
482
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to send workflow run event" });
|
|
483
|
+
}
|
|
484
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
485
|
+
if (!workflow) {
|
|
486
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
487
|
+
}
|
|
488
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
489
|
+
if (!run) {
|
|
490
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
491
|
+
}
|
|
492
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
493
|
+
await _run.sendEvent(event, data);
|
|
494
|
+
return { message: "Workflow run event sent" };
|
|
495
|
+
} catch (error) {
|
|
496
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error sending workflow run event");
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
exports.cancelWorkflowRunHandler = cancelWorkflowRunHandler;
|
|
501
|
+
exports.createWorkflowRunHandler = createWorkflowRunHandler;
|
|
502
|
+
exports.getWorkflowByIdHandler = getWorkflowByIdHandler;
|
|
503
|
+
exports.getWorkflowRunByIdHandler = getWorkflowRunByIdHandler;
|
|
504
|
+
exports.getWorkflowRunExecutionResultHandler = getWorkflowRunExecutionResultHandler;
|
|
505
|
+
exports.getWorkflowRunsHandler = getWorkflowRunsHandler;
|
|
506
|
+
exports.getWorkflowsHandler = getWorkflowsHandler;
|
|
507
|
+
exports.resumeAsyncWorkflowHandler = resumeAsyncWorkflowHandler;
|
|
508
|
+
exports.resumeWorkflowHandler = resumeWorkflowHandler;
|
|
509
|
+
exports.sendWorkflowRunEventHandler = sendWorkflowRunEventHandler;
|
|
510
|
+
exports.startAsyncWorkflowHandler = startAsyncWorkflowHandler;
|
|
511
|
+
exports.startWorkflowRunHandler = startWorkflowRunHandler;
|
|
512
|
+
exports.streamWorkflowHandler = streamWorkflowHandler;
|
|
513
|
+
exports.watchWorkflowHandler = watchWorkflowHandler;
|
|
514
|
+
exports.workflows_exports = workflows_exports;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { stringify, esm_default } from './chunk-
|
|
2
|
-
import { validateBody } from './chunk-
|
|
3
|
-
import { handleError } from './chunk-
|
|
4
|
-
import { HTTPException } from './chunk-
|
|
1
|
+
import { stringify, esm_default } from './chunk-MEGCYGBU.js';
|
|
2
|
+
import { validateBody } from './chunk-RSEO4XPX.js';
|
|
3
|
+
import { handleError } from './chunk-LF7P5PLR.js';
|
|
4
|
+
import { HTTPException } from './chunk-LCM566I4.js';
|
|
5
5
|
import { __export } from './chunk-MLKGABMK.js';
|
|
6
6
|
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
7
7
|
|
|
@@ -23,6 +23,8 @@ async function getAgentsHandler({ mastra, runtimeContext }) {
|
|
|
23
23
|
const instructions = await agent.getInstructions({ runtimeContext });
|
|
24
24
|
const tools = await agent.getTools({ runtimeContext });
|
|
25
25
|
const llm = await agent.getLLM({ runtimeContext });
|
|
26
|
+
const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext });
|
|
27
|
+
const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext });
|
|
26
28
|
const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
|
|
27
29
|
const _tool = tool;
|
|
28
30
|
acc[key] = {
|
|
@@ -57,8 +59,8 @@ async function getAgentsHandler({ mastra, runtimeContext }) {
|
|
|
57
59
|
workflows: serializedAgentWorkflows,
|
|
58
60
|
provider: llm?.getProvider(),
|
|
59
61
|
modelId: llm?.getModelId(),
|
|
60
|
-
defaultGenerateOptions
|
|
61
|
-
defaultStreamOptions
|
|
62
|
+
defaultGenerateOptions,
|
|
63
|
+
defaultStreamOptions
|
|
62
64
|
};
|
|
63
65
|
})
|
|
64
66
|
);
|
|
@@ -134,6 +136,8 @@ async function getAgentByIdHandler({
|
|
|
134
136
|
}
|
|
135
137
|
const instructions = await agent.getInstructions({ runtimeContext: proxyRuntimeContext });
|
|
136
138
|
const llm = await agent.getLLM({ runtimeContext });
|
|
139
|
+
const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext: proxyRuntimeContext });
|
|
140
|
+
const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext: proxyRuntimeContext });
|
|
137
141
|
return {
|
|
138
142
|
name: agent.name,
|
|
139
143
|
instructions,
|
|
@@ -141,8 +145,8 @@ async function getAgentByIdHandler({
|
|
|
141
145
|
workflows: serializedAgentWorkflows,
|
|
142
146
|
provider: llm?.getProvider(),
|
|
143
147
|
modelId: llm?.getModelId(),
|
|
144
|
-
defaultGenerateOptions
|
|
145
|
-
defaultStreamOptions
|
|
148
|
+
defaultGenerateOptions,
|
|
149
|
+
defaultStreamOptions
|
|
146
150
|
};
|
|
147
151
|
} catch (error) {
|
|
148
152
|
return handleError(error, "Error getting agent");
|
|
@@ -190,7 +194,8 @@ async function generateHandler({
|
|
|
190
194
|
mastra,
|
|
191
195
|
runtimeContext,
|
|
192
196
|
agentId,
|
|
193
|
-
body
|
|
197
|
+
body,
|
|
198
|
+
abortSignal
|
|
194
199
|
}) {
|
|
195
200
|
try {
|
|
196
201
|
const agent = mastra.getAgent(agentId);
|
|
@@ -208,7 +213,8 @@ async function generateHandler({
|
|
|
208
213
|
...rest,
|
|
209
214
|
// @ts-expect-error TODO fix types
|
|
210
215
|
resourceId: finalResourceId,
|
|
211
|
-
runtimeContext: finalRuntimeContext
|
|
216
|
+
runtimeContext: finalRuntimeContext,
|
|
217
|
+
signal: abortSignal
|
|
212
218
|
});
|
|
213
219
|
return result;
|
|
214
220
|
} catch (error) {
|
|
@@ -219,7 +225,8 @@ async function streamGenerateHandler({
|
|
|
219
225
|
mastra,
|
|
220
226
|
runtimeContext,
|
|
221
227
|
agentId,
|
|
222
|
-
body
|
|
228
|
+
body,
|
|
229
|
+
abortSignal
|
|
223
230
|
}) {
|
|
224
231
|
try {
|
|
225
232
|
const agent = mastra.getAgent(agentId);
|
|
@@ -237,18 +244,26 @@ async function streamGenerateHandler({
|
|
|
237
244
|
...rest,
|
|
238
245
|
// @ts-expect-error TODO fix types
|
|
239
246
|
resourceId: finalResourceId,
|
|
240
|
-
runtimeContext: finalRuntimeContext
|
|
247
|
+
runtimeContext: finalRuntimeContext,
|
|
248
|
+
signal: abortSignal
|
|
241
249
|
});
|
|
242
|
-
const streamResponse = rest.output ? streamResult.toTextStreamResponse(
|
|
250
|
+
const streamResponse = rest.output ? streamResult.toTextStreamResponse({
|
|
251
|
+
headers: {
|
|
252
|
+
"Transfer-Encoding": "chunked"
|
|
253
|
+
}
|
|
254
|
+
}) : streamResult.toDataStreamResponse({
|
|
243
255
|
sendUsage: true,
|
|
244
256
|
sendReasoning: true,
|
|
245
257
|
getErrorMessage: (error) => {
|
|
246
258
|
return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
|
|
259
|
+
},
|
|
260
|
+
headers: {
|
|
261
|
+
"Transfer-Encoding": "chunked"
|
|
247
262
|
}
|
|
248
263
|
});
|
|
249
264
|
return streamResponse;
|
|
250
265
|
} catch (error) {
|
|
251
|
-
|
|
266
|
+
return handleError(error, "error streaming agent response");
|
|
252
267
|
}
|
|
253
268
|
}
|
|
254
269
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
|
|
4
4
|
|
|
5
5
|
// src/server/handlers/utils.ts
|
|
6
6
|
function validateBody(body) {
|
|
@@ -11,7 +11,7 @@ function validateBody(body) {
|
|
|
11
11
|
return acc;
|
|
12
12
|
}, {});
|
|
13
13
|
if (Object.keys(errorResponse).length > 0) {
|
|
14
|
-
throw new
|
|
14
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: Object.values(errorResponse)[0] });
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { validateBody } from './chunk-
|
|
2
|
-
import { handleError } from './chunk-
|
|
3
|
-
import { HTTPException } from './chunk-
|
|
1
|
+
import { validateBody } from './chunk-RSEO4XPX.js';
|
|
2
|
+
import { handleError } from './chunk-LF7P5PLR.js';
|
|
3
|
+
import { HTTPException } from './chunk-LCM566I4.js';
|
|
4
4
|
import { __export } from './chunk-MLKGABMK.js';
|
|
5
5
|
|
|
6
6
|
// src/server/handlers/network.ts
|