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