@mastra/server 0.0.0-taofeeqInngest-20250603090617 → 0.0.0-transpile-packages-20250724123433
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 +390 -45
- package/dist/_tsup-dts-rollup.d.ts +390 -45
- package/dist/{chunk-OCWPVYNI.cjs → chunk-2KZFMI6P.cjs} +1 -0
- package/dist/{chunk-VPNDC2DI.cjs → chunk-2SLFAFTR.cjs} +12 -12
- package/dist/chunk-4D66QEKC.js +81 -0
- package/dist/{chunk-W7VCKPAD.js → chunk-5PQQ42EZ.js} +9 -9
- package/dist/{chunk-BNEY4P4P.cjs → chunk-7TP2LX5L.cjs} +16 -16
- package/dist/chunk-B2PAS2IB.cjs +514 -0
- package/dist/{chunk-J3PKLB3A.js → chunk-BK4XT6EG.js} +56 -17
- package/dist/chunk-CBFTEHOO.cjs +157 -0
- package/dist/{chunk-57CJTIPW.cjs → chunk-CCGRCYWJ.cjs} +2 -2
- package/dist/{chunk-C7564HUT.js → chunk-CRCR3ZUK.js} +3 -3
- package/dist/{chunk-ZE5AAC4I.cjs → chunk-FRVBFMO2.cjs} +26 -36
- package/dist/{chunk-DJJIUEL2.js → chunk-G4L7OMCA.js} +135 -26
- package/dist/{chunk-B4MQFJ7G.cjs → chunk-G7KH752Y.cjs} +5 -5
- package/dist/{chunk-KUNQFY2W.js → chunk-H7DMHBKY.js} +190 -57
- package/dist/{chunk-YIOVBYZH.cjs → chunk-JMLYCXMK.cjs} +43 -43
- package/dist/{chunk-CP55EVBK.js → chunk-KHZKYUNR.js} +15 -11
- package/dist/{chunk-NYN7KFXL.js → chunk-LCM566I4.js} +1 -0
- package/dist/chunk-LF7P5PLR.js +14 -0
- package/dist/{chunk-YWLUOY3D.cjs → chunk-LI436ITD.cjs} +107 -69
- package/dist/{chunk-TJKLBTFB.js → chunk-LRCAAFUA.js} +10 -20
- package/dist/{chunk-A3KDUGS7.cjs → chunk-LZ3VJXSO.cjs} +70 -31
- package/dist/{chunk-LIVAK2DM.js → chunk-MEGCYGBU.js} +108 -70
- package/dist/chunk-PZQDCRPV.cjs +16 -0
- package/dist/chunk-QGX47B5D.cjs +86 -0
- 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-VULESSU5.js +149 -0
- package/dist/{chunk-55DOQLP6.js → chunk-WNVFNNWN.js} +2 -2
- package/dist/chunk-Z75RYULP.cjs +333 -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 +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 +21 -9
- package/dist/server/handlers/memory.d.cts +3 -0
- package/dist/server/handlers/memory.d.ts +3 -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/scores.cjs +30 -0
- package/dist/server/handlers/scores.d.cts +6 -0
- package/dist/server/handlers/scores.d.ts +6 -0
- package/dist/server/handlers/scores.js +1 -0
- 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 +28 -23
- package/dist/server/handlers.d.cts +3 -2
- package/dist/server/handlers.d.ts +3 -2
- package/dist/server/handlers.js +11 -10
- package/package.json +15 -15
- package/dist/chunk-64U3UDTH.cjs +0 -13
- package/dist/chunk-DQLE3DVM.js +0 -49
- package/dist/chunk-M5ABIP7D.js +0 -11
- package/dist/chunk-MMO2HDM6.cjs +0 -378
- package/dist/chunk-NEOOQUKW.cjs +0 -54
- package/dist/chunk-Y7UWRW5X.cjs +0 -221
|
@@ -1,25 +1,46 @@
|
|
|
1
|
-
import { stringify, esm_default } from './chunk-
|
|
2
|
-
import { handleError } from './chunk-
|
|
3
|
-
import { HTTPException } from './chunk-
|
|
1
|
+
import { stringify, esm_default } from './chunk-MEGCYGBU.js';
|
|
2
|
+
import { handleError } from './chunk-LF7P5PLR.js';
|
|
3
|
+
import { HTTPException } from './chunk-LCM566I4.js';
|
|
4
4
|
import { __export } from './chunk-MLKGABMK.js';
|
|
5
|
-
import { ReadableStream } from '
|
|
6
|
-
import { RuntimeContext } from '@mastra/core/di';
|
|
5
|
+
import { ReadableStream } from 'stream/web';
|
|
7
6
|
|
|
8
7
|
// src/server/handlers/workflows.ts
|
|
9
8
|
var workflows_exports = {};
|
|
10
9
|
__export(workflows_exports, {
|
|
10
|
+
cancelWorkflowRunHandler: () => cancelWorkflowRunHandler,
|
|
11
11
|
createWorkflowRunHandler: () => createWorkflowRunHandler,
|
|
12
12
|
getWorkflowByIdHandler: () => getWorkflowByIdHandler,
|
|
13
13
|
getWorkflowRunByIdHandler: () => getWorkflowRunByIdHandler,
|
|
14
|
+
getWorkflowRunExecutionResultHandler: () => getWorkflowRunExecutionResultHandler,
|
|
14
15
|
getWorkflowRunsHandler: () => getWorkflowRunsHandler,
|
|
15
16
|
getWorkflowsHandler: () => getWorkflowsHandler,
|
|
16
17
|
resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
|
|
17
18
|
resumeWorkflowHandler: () => resumeWorkflowHandler,
|
|
19
|
+
sendWorkflowRunEventHandler: () => sendWorkflowRunEventHandler,
|
|
18
20
|
startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
|
|
19
21
|
startWorkflowRunHandler: () => startWorkflowRunHandler,
|
|
20
22
|
streamWorkflowHandler: () => streamWorkflowHandler,
|
|
21
23
|
watchWorkflowHandler: () => watchWorkflowHandler
|
|
22
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
|
+
}
|
|
23
44
|
async function getWorkflowsHandler({ mastra }) {
|
|
24
45
|
try {
|
|
25
46
|
const workflows = mastra.getWorkflows({ serialized: false });
|
|
@@ -38,6 +59,7 @@ async function getWorkflowsHandler({ mastra }) {
|
|
|
38
59
|
};
|
|
39
60
|
return acc2;
|
|
40
61
|
}, {}),
|
|
62
|
+
allSteps: getSteps(workflow.steps) || {},
|
|
41
63
|
stepGraph: workflow.serializedStepGraph,
|
|
42
64
|
inputSchema: workflow.inputSchema ? stringify(esm_default(workflow.inputSchema)) : void 0,
|
|
43
65
|
outputSchema: workflow.outputSchema ? stringify(esm_default(workflow.outputSchema)) : void 0
|
|
@@ -46,15 +68,49 @@ async function getWorkflowsHandler({ mastra }) {
|
|
|
46
68
|
}, {});
|
|
47
69
|
return _workflows;
|
|
48
70
|
} catch (error) {
|
|
49
|
-
|
|
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" });
|
|
50
105
|
}
|
|
106
|
+
return { workflow };
|
|
51
107
|
}
|
|
52
108
|
async function getWorkflowByIdHandler({ mastra, workflowId }) {
|
|
53
109
|
try {
|
|
54
110
|
if (!workflowId) {
|
|
55
111
|
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
56
112
|
}
|
|
57
|
-
const workflow = mastra
|
|
113
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
58
114
|
if (!workflow) {
|
|
59
115
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
60
116
|
}
|
|
@@ -70,6 +126,7 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
|
|
|
70
126
|
};
|
|
71
127
|
return acc;
|
|
72
128
|
}, {}),
|
|
129
|
+
allSteps: getSteps(workflow.steps) || {},
|
|
73
130
|
name: workflow.name,
|
|
74
131
|
description: workflow.description,
|
|
75
132
|
stepGraph: workflow.serializedStepGraph,
|
|
@@ -77,7 +134,7 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
|
|
|
77
134
|
outputSchema: workflow.outputSchema ? stringify(esm_default(workflow.outputSchema)) : void 0
|
|
78
135
|
};
|
|
79
136
|
} catch (error) {
|
|
80
|
-
|
|
137
|
+
return handleError(error, "Error getting workflow");
|
|
81
138
|
}
|
|
82
139
|
}
|
|
83
140
|
async function getWorkflowRunByIdHandler({
|
|
@@ -92,7 +149,7 @@ async function getWorkflowRunByIdHandler({
|
|
|
92
149
|
if (!runId) {
|
|
93
150
|
throw new HTTPException(400, { message: "Run ID is required" });
|
|
94
151
|
}
|
|
95
|
-
const workflow = mastra
|
|
152
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
96
153
|
if (!workflow) {
|
|
97
154
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
98
155
|
}
|
|
@@ -102,7 +159,32 @@ async function getWorkflowRunByIdHandler({
|
|
|
102
159
|
}
|
|
103
160
|
return run;
|
|
104
161
|
} catch (error) {
|
|
105
|
-
|
|
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");
|
|
106
188
|
}
|
|
107
189
|
}
|
|
108
190
|
async function createWorkflowRunHandler({
|
|
@@ -114,14 +196,14 @@ async function createWorkflowRunHandler({
|
|
|
114
196
|
if (!workflowId) {
|
|
115
197
|
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
116
198
|
}
|
|
117
|
-
const workflow = mastra
|
|
199
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
118
200
|
if (!workflow) {
|
|
119
201
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
120
202
|
}
|
|
121
|
-
const run = workflow.
|
|
203
|
+
const run = await workflow.createRunAsync({ runId: prevRunId });
|
|
122
204
|
return { runId: run.runId };
|
|
123
205
|
} catch (error) {
|
|
124
|
-
|
|
206
|
+
return handleError(error, "Error creating workflow run");
|
|
125
207
|
}
|
|
126
208
|
}
|
|
127
209
|
async function startAsyncWorkflowHandler({
|
|
@@ -129,29 +211,24 @@ async function startAsyncWorkflowHandler({
|
|
|
129
211
|
runtimeContext,
|
|
130
212
|
workflowId,
|
|
131
213
|
runId,
|
|
132
|
-
inputData
|
|
133
|
-
runtimeContextFromRequest
|
|
214
|
+
inputData
|
|
134
215
|
}) {
|
|
135
216
|
try {
|
|
136
217
|
if (!workflowId) {
|
|
137
218
|
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
138
219
|
}
|
|
139
|
-
const workflow = mastra
|
|
220
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
140
221
|
if (!workflow) {
|
|
141
222
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
142
223
|
}
|
|
143
|
-
const
|
|
144
|
-
...Array.from(runtimeContext?.entries() ?? []),
|
|
145
|
-
...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
|
|
146
|
-
]);
|
|
147
|
-
const _run = workflow.createRun({ runId });
|
|
224
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
148
225
|
const result = await _run.start({
|
|
149
226
|
inputData,
|
|
150
|
-
runtimeContext
|
|
227
|
+
runtimeContext
|
|
151
228
|
});
|
|
152
229
|
return result;
|
|
153
230
|
} catch (error) {
|
|
154
|
-
|
|
231
|
+
return handleError(error, "Error starting async workflow");
|
|
155
232
|
}
|
|
156
233
|
}
|
|
157
234
|
async function startWorkflowRunHandler({
|
|
@@ -159,8 +236,7 @@ async function startWorkflowRunHandler({
|
|
|
159
236
|
runtimeContext,
|
|
160
237
|
workflowId,
|
|
161
238
|
runId,
|
|
162
|
-
inputData
|
|
163
|
-
runtimeContextFromRequest
|
|
239
|
+
inputData
|
|
164
240
|
}) {
|
|
165
241
|
try {
|
|
166
242
|
if (!workflowId) {
|
|
@@ -169,19 +245,18 @@ async function startWorkflowRunHandler({
|
|
|
169
245
|
if (!runId) {
|
|
170
246
|
throw new HTTPException(400, { message: "runId required to start run" });
|
|
171
247
|
}
|
|
172
|
-
const workflow = mastra
|
|
248
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
249
|
+
if (!workflow) {
|
|
250
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
251
|
+
}
|
|
173
252
|
const run = await workflow.getWorkflowRunById(runId);
|
|
174
253
|
if (!run) {
|
|
175
254
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
176
255
|
}
|
|
177
|
-
const
|
|
178
|
-
...Array.from(runtimeContext?.entries() ?? []),
|
|
179
|
-
...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
|
|
180
|
-
]);
|
|
181
|
-
const _run = workflow.createRun({ runId });
|
|
256
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
182
257
|
void _run.start({
|
|
183
258
|
inputData,
|
|
184
|
-
runtimeContext
|
|
259
|
+
runtimeContext
|
|
185
260
|
});
|
|
186
261
|
return { message: "Workflow run started" };
|
|
187
262
|
} catch (e) {
|
|
@@ -200,12 +275,15 @@ async function watchWorkflowHandler({
|
|
|
200
275
|
if (!runId) {
|
|
201
276
|
throw new HTTPException(400, { message: "runId required to watch workflow" });
|
|
202
277
|
}
|
|
203
|
-
const workflow = mastra
|
|
278
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
279
|
+
if (!workflow) {
|
|
280
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
281
|
+
}
|
|
204
282
|
const run = await workflow.getWorkflowRunById(runId);
|
|
205
283
|
if (!run) {
|
|
206
284
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
207
285
|
}
|
|
208
|
-
const _run = workflow.
|
|
286
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
209
287
|
let unwatch;
|
|
210
288
|
let asyncRef = null;
|
|
211
289
|
const stream = new ReadableStream({
|
|
@@ -234,13 +312,12 @@ async function watchWorkflowHandler({
|
|
|
234
312
|
return handleError(error, "Error watching workflow");
|
|
235
313
|
}
|
|
236
314
|
}
|
|
237
|
-
function streamWorkflowHandler({
|
|
315
|
+
async function streamWorkflowHandler({
|
|
238
316
|
mastra,
|
|
239
317
|
runtimeContext,
|
|
240
318
|
workflowId,
|
|
241
319
|
runId,
|
|
242
|
-
inputData
|
|
243
|
-
runtimeContextFromRequest
|
|
320
|
+
inputData
|
|
244
321
|
}) {
|
|
245
322
|
try {
|
|
246
323
|
if (!workflowId) {
|
|
@@ -249,18 +326,14 @@ function streamWorkflowHandler({
|
|
|
249
326
|
if (!runId) {
|
|
250
327
|
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
251
328
|
}
|
|
252
|
-
const workflow = mastra
|
|
329
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
253
330
|
if (!workflow) {
|
|
254
331
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
255
332
|
}
|
|
256
|
-
const
|
|
257
|
-
...Array.from(runtimeContext?.entries() ?? []),
|
|
258
|
-
...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
|
|
259
|
-
]);
|
|
260
|
-
const run = workflow.createRun({ runId });
|
|
333
|
+
const run = await workflow.createRunAsync({ runId });
|
|
261
334
|
const result = run.stream({
|
|
262
335
|
inputData,
|
|
263
|
-
runtimeContext
|
|
336
|
+
runtimeContext
|
|
264
337
|
});
|
|
265
338
|
return result;
|
|
266
339
|
} catch (error) {
|
|
@@ -272,8 +345,7 @@ async function resumeAsyncWorkflowHandler({
|
|
|
272
345
|
workflowId,
|
|
273
346
|
runId,
|
|
274
347
|
body,
|
|
275
|
-
runtimeContext
|
|
276
|
-
runtimeContextFromRequest
|
|
348
|
+
runtimeContext
|
|
277
349
|
}) {
|
|
278
350
|
try {
|
|
279
351
|
if (!workflowId) {
|
|
@@ -285,20 +357,19 @@ async function resumeAsyncWorkflowHandler({
|
|
|
285
357
|
if (!body.step) {
|
|
286
358
|
throw new HTTPException(400, { message: "step required to resume workflow" });
|
|
287
359
|
}
|
|
288
|
-
const workflow = mastra
|
|
360
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
361
|
+
if (!workflow) {
|
|
362
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
363
|
+
}
|
|
289
364
|
const run = await workflow.getWorkflowRunById(runId);
|
|
290
365
|
if (!run) {
|
|
291
366
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
292
367
|
}
|
|
293
|
-
const
|
|
294
|
-
...Array.from(runtimeContext?.entries() ?? []),
|
|
295
|
-
...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
|
|
296
|
-
]);
|
|
297
|
-
const _run = workflow.createRun({ runId });
|
|
368
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
298
369
|
const result = await _run.resume({
|
|
299
370
|
step: body.step,
|
|
300
371
|
resumeData: body.resumeData,
|
|
301
|
-
runtimeContext
|
|
372
|
+
runtimeContext
|
|
302
373
|
});
|
|
303
374
|
return result;
|
|
304
375
|
} catch (error) {
|
|
@@ -322,12 +393,15 @@ async function resumeWorkflowHandler({
|
|
|
322
393
|
if (!body.step) {
|
|
323
394
|
throw new HTTPException(400, { message: "step required to resume workflow" });
|
|
324
395
|
}
|
|
325
|
-
const workflow = mastra
|
|
396
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
397
|
+
if (!workflow) {
|
|
398
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
399
|
+
}
|
|
326
400
|
const run = await workflow.getWorkflowRunById(runId);
|
|
327
401
|
if (!run) {
|
|
328
402
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
329
403
|
}
|
|
330
|
-
const _run = workflow.
|
|
404
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
331
405
|
void _run.resume({
|
|
332
406
|
step: body.step,
|
|
333
407
|
resumeData: body.resumeData,
|
|
@@ -351,7 +425,10 @@ async function getWorkflowRunsHandler({
|
|
|
351
425
|
if (!workflowId) {
|
|
352
426
|
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
353
427
|
}
|
|
354
|
-
const workflow = mastra
|
|
428
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
429
|
+
if (!workflow) {
|
|
430
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
431
|
+
}
|
|
355
432
|
const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
|
|
356
433
|
runs: [],
|
|
357
434
|
total: 0
|
|
@@ -361,5 +438,61 @@ async function getWorkflowRunsHandler({
|
|
|
361
438
|
return handleError(error, "Error getting workflow runs");
|
|
362
439
|
}
|
|
363
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
|
+
}
|
|
364
497
|
|
|
365
|
-
export { createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunsHandler, getWorkflowsHandler, resumeAsyncWorkflowHandler, resumeWorkflowHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamWorkflowHandler, watchWorkflowHandler, workflows_exports };
|
|
498
|
+
export { cancelWorkflowRunHandler, createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunExecutionResultHandler, getWorkflowRunsHandler, getWorkflowsHandler, resumeAsyncWorkflowHandler, resumeWorkflowHandler, sendWorkflowRunEventHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamWorkflowHandler, watchWorkflowHandler, workflows_exports };
|