@mastra/server 0.0.0-vnextWorkflows-20250422142014 → 0.0.0-workflow-deno-20250616115451
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 +351 -60
- package/dist/_tsup-dts-rollup.d.ts +351 -60
- package/dist/{chunk-XISBMH56.js → chunk-2HXKRRNS.js} +11 -9
- package/dist/chunk-42IKSJNO.js +421 -0
- package/dist/chunk-42YJ2YVD.cjs +263 -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-2FJURXCL.cjs → chunk-6TJSHFCJ.cjs} +44 -36
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/chunk-ASKESBJW.cjs +2004 -0
- package/dist/{chunk-7IWQE76Z.cjs → chunk-B4MQFJ7G.cjs} +16 -10
- package/dist/{chunk-WTHDCRMY.js → chunk-BFOA2QQY.js} +12 -6
- package/dist/{chunk-M56ECCHK.cjs → chunk-BNEY4P4P.cjs} +20 -19
- package/dist/{chunk-YANVFOYA.js → chunk-C7564HUT.js} +56 -34
- package/dist/chunk-CK32I2VN.cjs +435 -0
- package/dist/{chunk-4B7OUZXW.js → chunk-CLYX4KLH.js} +78 -63
- package/dist/chunk-CMMOIUFC.cjs +114 -0
- package/dist/{chunk-3RVHWGWO.js → chunk-CP55EVBK.js} +26 -13
- package/dist/chunk-GHC4YV6R.js +504 -0
- package/dist/{chunk-L7XE5QTW.js → chunk-H5PTF3Y4.js} +1 -1
- package/dist/{chunk-RBQASTUP.js → chunk-I7KJZNX5.js} +14 -6
- 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-HABV7TZK.cjs → chunk-NGURCFEJ.cjs} +28 -26
- package/dist/{chunk-TRDNDNGQ.js → chunk-NYN7KFXL.js} +1 -7
- package/dist/chunk-O2YAAFY3.js +255 -0
- package/dist/{chunk-FV45V6WC.cjs → chunk-OCWPVYNI.cjs} +0 -7
- package/dist/chunk-QLG2PFHE.js +81 -0
- package/dist/chunk-SDPGVWQJ.cjs +512 -0
- package/dist/chunk-TGJMNUYJ.js +2001 -0
- package/dist/chunk-VPNDC2DI.cjs +148 -0
- package/dist/chunk-WE32JG64.cjs +332 -0
- 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/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 +33 -23
- package/dist/server/handlers.d.cts +2 -0
- package/dist/server/handlers.d.ts +2 -0
- package/dist/server/handlers.js +11 -9
- package/package.json +13 -12
- package/dist/chunk-3EJZQ6TQ.js +0 -49
- package/dist/chunk-4WJ5GHRG.cjs +0 -164
- package/dist/chunk-5SWCVTNL.cjs +0 -5579
- package/dist/chunk-A7DF4ETD.cjs +0 -100
- package/dist/chunk-JLDXUWK7.cjs +0 -126
- package/dist/chunk-OMN3UI6X.js +0 -5576
- package/dist/chunk-RNU4JMLM.cjs +0 -317
- package/dist/chunk-SKBVVI24.cjs +0 -54
- package/dist/chunk-TFFNX7FI.js +0 -156
|
@@ -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-TGJMNUYJ.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
|
|
@@ -56,7 +57,7 @@ function executeToolHandler(tools) {
|
|
|
56
57
|
runId,
|
|
57
58
|
toolId,
|
|
58
59
|
data,
|
|
59
|
-
|
|
60
|
+
runtimeContext
|
|
60
61
|
}) => {
|
|
61
62
|
try {
|
|
62
63
|
if (!toolId) {
|
|
@@ -78,7 +79,7 @@ function executeToolHandler(tools) {
|
|
|
78
79
|
context: data,
|
|
79
80
|
mastra,
|
|
80
81
|
runId,
|
|
81
|
-
|
|
82
|
+
runtimeContext
|
|
82
83
|
});
|
|
83
84
|
return result;
|
|
84
85
|
} catch (error) {
|
|
@@ -91,14 +92,15 @@ async function executeAgentToolHandler({
|
|
|
91
92
|
agentId,
|
|
92
93
|
toolId,
|
|
93
94
|
data,
|
|
94
|
-
|
|
95
|
+
runtimeContext
|
|
95
96
|
}) {
|
|
96
97
|
try {
|
|
97
98
|
const agent = agentId ? mastra.getAgent(agentId) : null;
|
|
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
|
}
|
|
@@ -107,7 +109,7 @@ async function executeAgentToolHandler({
|
|
|
107
109
|
}
|
|
108
110
|
const result = await tool.execute({
|
|
109
111
|
context: data,
|
|
110
|
-
|
|
112
|
+
runtimeContext,
|
|
111
113
|
mastra,
|
|
112
114
|
runId: agentId
|
|
113
115
|
});
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import { stringify, esm_default } from './chunk-TGJMNUYJ.js';
|
|
2
|
+
import { handleError } from './chunk-M5ABIP7D.js';
|
|
3
|
+
import { HTTPException } from './chunk-NYN7KFXL.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
|
+
createWorkflowRunHandler: () => createWorkflowRunHandler,
|
|
11
|
+
getWorkflowByIdHandler: () => getWorkflowByIdHandler,
|
|
12
|
+
getWorkflowRunByIdHandler: () => getWorkflowRunByIdHandler,
|
|
13
|
+
getWorkflowRunExecutionResultHandler: () => getWorkflowRunExecutionResultHandler,
|
|
14
|
+
getWorkflowRunsHandler: () => getWorkflowRunsHandler,
|
|
15
|
+
getWorkflowsHandler: () => getWorkflowsHandler,
|
|
16
|
+
resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
|
|
17
|
+
resumeWorkflowHandler: () => resumeWorkflowHandler,
|
|
18
|
+
startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
|
|
19
|
+
startWorkflowRunHandler: () => startWorkflowRunHandler,
|
|
20
|
+
streamWorkflowHandler: () => streamWorkflowHandler,
|
|
21
|
+
watchWorkflowHandler: () => watchWorkflowHandler
|
|
22
|
+
});
|
|
23
|
+
async function getWorkflowsHandler({ mastra }) {
|
|
24
|
+
try {
|
|
25
|
+
const workflows = mastra.getWorkflows({ serialized: false });
|
|
26
|
+
const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
|
|
27
|
+
acc[key] = {
|
|
28
|
+
name: workflow.name,
|
|
29
|
+
description: workflow.description,
|
|
30
|
+
steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
|
|
31
|
+
acc2[key2] = {
|
|
32
|
+
id: step.id,
|
|
33
|
+
description: step.description,
|
|
34
|
+
inputSchema: step.inputSchema ? stringify(esm_default(step.inputSchema)) : void 0,
|
|
35
|
+
outputSchema: step.outputSchema ? stringify(esm_default(step.outputSchema)) : void 0,
|
|
36
|
+
resumeSchema: step.resumeSchema ? stringify(esm_default(step.resumeSchema)) : void 0,
|
|
37
|
+
suspendSchema: step.suspendSchema ? stringify(esm_default(step.suspendSchema)) : void 0
|
|
38
|
+
};
|
|
39
|
+
return acc2;
|
|
40
|
+
}, {}),
|
|
41
|
+
stepGraph: workflow.serializedStepGraph,
|
|
42
|
+
inputSchema: workflow.inputSchema ? stringify(esm_default(workflow.inputSchema)) : void 0,
|
|
43
|
+
outputSchema: workflow.outputSchema ? stringify(esm_default(workflow.outputSchema)) : void 0
|
|
44
|
+
};
|
|
45
|
+
return acc;
|
|
46
|
+
}, {});
|
|
47
|
+
return _workflows;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
throw new HTTPException(500, { message: error?.message || "Error getting workflows" });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function getWorkflowsFromSystem({ mastra, workflowId }) {
|
|
53
|
+
const logger = mastra.getLogger();
|
|
54
|
+
if (!workflowId) {
|
|
55
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
56
|
+
}
|
|
57
|
+
let workflow;
|
|
58
|
+
try {
|
|
59
|
+
workflow = mastra.getWorkflow(workflowId);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
logger.debug("Error getting workflow, searching agents for workflow", error);
|
|
62
|
+
}
|
|
63
|
+
if (!workflow) {
|
|
64
|
+
logger.debug("Workflow not found, searching agents for workflow", { workflowId });
|
|
65
|
+
const agents = mastra.getAgents();
|
|
66
|
+
if (Object.keys(agents || {}).length) {
|
|
67
|
+
for (const [_, agent] of Object.entries(agents)) {
|
|
68
|
+
try {
|
|
69
|
+
const workflows = await agent.getWorkflows();
|
|
70
|
+
if (workflows[workflowId]) {
|
|
71
|
+
workflow = workflows[workflowId];
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
break;
|
|
75
|
+
} catch (error) {
|
|
76
|
+
logger.debug("Error getting workflow from agent", error);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!workflow) {
|
|
82
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
83
|
+
}
|
|
84
|
+
return { workflow };
|
|
85
|
+
}
|
|
86
|
+
async function getWorkflowByIdHandler({ mastra, workflowId }) {
|
|
87
|
+
try {
|
|
88
|
+
if (!workflowId) {
|
|
89
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
90
|
+
}
|
|
91
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
92
|
+
if (!workflow) {
|
|
93
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
|
|
97
|
+
acc[key] = {
|
|
98
|
+
id: step.id,
|
|
99
|
+
description: step.description,
|
|
100
|
+
inputSchema: step.inputSchema ? stringify(esm_default(step.inputSchema)) : void 0,
|
|
101
|
+
outputSchema: step.outputSchema ? stringify(esm_default(step.outputSchema)) : void 0,
|
|
102
|
+
resumeSchema: step.resumeSchema ? stringify(esm_default(step.resumeSchema)) : void 0,
|
|
103
|
+
suspendSchema: step.suspendSchema ? stringify(esm_default(step.suspendSchema)) : void 0
|
|
104
|
+
};
|
|
105
|
+
return acc;
|
|
106
|
+
}, {}),
|
|
107
|
+
name: workflow.name,
|
|
108
|
+
description: workflow.description,
|
|
109
|
+
stepGraph: workflow.serializedStepGraph,
|
|
110
|
+
inputSchema: workflow.inputSchema ? stringify(esm_default(workflow.inputSchema)) : void 0,
|
|
111
|
+
outputSchema: workflow.outputSchema ? stringify(esm_default(workflow.outputSchema)) : void 0
|
|
112
|
+
};
|
|
113
|
+
} catch (error) {
|
|
114
|
+
throw new HTTPException(500, { message: error?.message || "Error getting workflow" });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function getWorkflowRunByIdHandler({
|
|
118
|
+
mastra,
|
|
119
|
+
workflowId,
|
|
120
|
+
runId
|
|
121
|
+
}) {
|
|
122
|
+
try {
|
|
123
|
+
if (!workflowId) {
|
|
124
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
125
|
+
}
|
|
126
|
+
if (!runId) {
|
|
127
|
+
throw new HTTPException(400, { message: "Run ID is required" });
|
|
128
|
+
}
|
|
129
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
130
|
+
if (!workflow) {
|
|
131
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
132
|
+
}
|
|
133
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
134
|
+
if (!run) {
|
|
135
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
136
|
+
}
|
|
137
|
+
return run;
|
|
138
|
+
} catch (error) {
|
|
139
|
+
throw new HTTPException(500, { message: error?.message || "Error getting workflow run" });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async function getWorkflowRunExecutionResultHandler({
|
|
143
|
+
mastra,
|
|
144
|
+
workflowId,
|
|
145
|
+
runId
|
|
146
|
+
}) {
|
|
147
|
+
try {
|
|
148
|
+
if (!workflowId) {
|
|
149
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
150
|
+
}
|
|
151
|
+
if (!runId) {
|
|
152
|
+
throw new HTTPException(400, { message: "Run ID is required" });
|
|
153
|
+
}
|
|
154
|
+
const workflow = mastra.getWorkflow(workflowId);
|
|
155
|
+
if (!workflow) {
|
|
156
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
157
|
+
}
|
|
158
|
+
const executionResult = await workflow.getWorkflowRunExecutionResult(runId);
|
|
159
|
+
if (!executionResult) {
|
|
160
|
+
throw new HTTPException(404, { message: "Workflow run execution result not found" });
|
|
161
|
+
}
|
|
162
|
+
return executionResult;
|
|
163
|
+
} catch (error) {
|
|
164
|
+
throw new HTTPException(500, {
|
|
165
|
+
message: error?.message || "Error getting workflow run execution result"
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async function createWorkflowRunHandler({
|
|
170
|
+
mastra,
|
|
171
|
+
workflowId,
|
|
172
|
+
runId: prevRunId
|
|
173
|
+
}) {
|
|
174
|
+
try {
|
|
175
|
+
if (!workflowId) {
|
|
176
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
177
|
+
}
|
|
178
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
179
|
+
if (!workflow) {
|
|
180
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
181
|
+
}
|
|
182
|
+
const run = await workflow.createRun({ runId: prevRunId });
|
|
183
|
+
return { runId: run.runId };
|
|
184
|
+
} catch (error) {
|
|
185
|
+
throw new HTTPException(500, { message: error?.message || "Error creating workflow run" });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async function startAsyncWorkflowHandler({
|
|
189
|
+
mastra,
|
|
190
|
+
runtimeContext,
|
|
191
|
+
workflowId,
|
|
192
|
+
runId,
|
|
193
|
+
inputData
|
|
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.createRun({ runId });
|
|
204
|
+
const result = await _run.start({
|
|
205
|
+
inputData,
|
|
206
|
+
runtimeContext
|
|
207
|
+
});
|
|
208
|
+
return result;
|
|
209
|
+
} catch (error) {
|
|
210
|
+
throw new HTTPException(500, { message: error?.message || "Error executing workflow" });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
async function startWorkflowRunHandler({
|
|
214
|
+
mastra,
|
|
215
|
+
runtimeContext,
|
|
216
|
+
workflowId,
|
|
217
|
+
runId,
|
|
218
|
+
inputData
|
|
219
|
+
}) {
|
|
220
|
+
try {
|
|
221
|
+
if (!workflowId) {
|
|
222
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
223
|
+
}
|
|
224
|
+
if (!runId) {
|
|
225
|
+
throw new HTTPException(400, { message: "runId required to start run" });
|
|
226
|
+
}
|
|
227
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
228
|
+
if (!workflow) {
|
|
229
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
230
|
+
}
|
|
231
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
232
|
+
if (!run) {
|
|
233
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
234
|
+
}
|
|
235
|
+
const _run = await workflow.createRun({ runId });
|
|
236
|
+
void _run.start({
|
|
237
|
+
inputData,
|
|
238
|
+
runtimeContext
|
|
239
|
+
});
|
|
240
|
+
return { message: "Workflow run started" };
|
|
241
|
+
} catch (e) {
|
|
242
|
+
return handleError(e, "Error starting workflow run");
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async function watchWorkflowHandler({
|
|
246
|
+
mastra,
|
|
247
|
+
workflowId,
|
|
248
|
+
runId
|
|
249
|
+
}) {
|
|
250
|
+
try {
|
|
251
|
+
if (!workflowId) {
|
|
252
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
253
|
+
}
|
|
254
|
+
if (!runId) {
|
|
255
|
+
throw new HTTPException(400, { message: "runId required to watch workflow" });
|
|
256
|
+
}
|
|
257
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
258
|
+
if (!workflow) {
|
|
259
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
260
|
+
}
|
|
261
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
262
|
+
if (!run) {
|
|
263
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
264
|
+
}
|
|
265
|
+
const _run = await workflow.createRun({ runId });
|
|
266
|
+
let unwatch;
|
|
267
|
+
let asyncRef = null;
|
|
268
|
+
const stream = new ReadableStream({
|
|
269
|
+
start(controller) {
|
|
270
|
+
unwatch = _run.watch(({ type, payload, eventTimestamp }) => {
|
|
271
|
+
controller.enqueue(JSON.stringify({ type, payload, eventTimestamp, runId }));
|
|
272
|
+
if (asyncRef) {
|
|
273
|
+
clearImmediate(asyncRef);
|
|
274
|
+
asyncRef = null;
|
|
275
|
+
}
|
|
276
|
+
asyncRef = setImmediate(async () => {
|
|
277
|
+
const runDone = payload.workflowState.status !== "running";
|
|
278
|
+
if (runDone) {
|
|
279
|
+
controller.close();
|
|
280
|
+
unwatch?.();
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
},
|
|
285
|
+
cancel() {
|
|
286
|
+
unwatch?.();
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
return stream;
|
|
290
|
+
} catch (error) {
|
|
291
|
+
return handleError(error, "Error watching workflow");
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
async function streamWorkflowHandler({
|
|
295
|
+
mastra,
|
|
296
|
+
runtimeContext,
|
|
297
|
+
workflowId,
|
|
298
|
+
runId,
|
|
299
|
+
inputData
|
|
300
|
+
}) {
|
|
301
|
+
try {
|
|
302
|
+
if (!workflowId) {
|
|
303
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
304
|
+
}
|
|
305
|
+
if (!runId) {
|
|
306
|
+
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
307
|
+
}
|
|
308
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
309
|
+
if (!workflow) {
|
|
310
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
311
|
+
}
|
|
312
|
+
const run = await workflow.createRun({ runId });
|
|
313
|
+
const result = run.stream({
|
|
314
|
+
inputData,
|
|
315
|
+
runtimeContext
|
|
316
|
+
});
|
|
317
|
+
return result;
|
|
318
|
+
} catch (error) {
|
|
319
|
+
return handleError(error, "Error executing workflow");
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
async function resumeAsyncWorkflowHandler({
|
|
323
|
+
mastra,
|
|
324
|
+
workflowId,
|
|
325
|
+
runId,
|
|
326
|
+
body,
|
|
327
|
+
runtimeContext
|
|
328
|
+
}) {
|
|
329
|
+
try {
|
|
330
|
+
if (!workflowId) {
|
|
331
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
332
|
+
}
|
|
333
|
+
if (!runId) {
|
|
334
|
+
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
335
|
+
}
|
|
336
|
+
if (!body.step) {
|
|
337
|
+
throw new HTTPException(400, { message: "step required to resume workflow" });
|
|
338
|
+
}
|
|
339
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
340
|
+
if (!workflow) {
|
|
341
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
342
|
+
}
|
|
343
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
344
|
+
if (!run) {
|
|
345
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
346
|
+
}
|
|
347
|
+
const _run = await workflow.createRun({ runId });
|
|
348
|
+
const result = await _run.resume({
|
|
349
|
+
step: body.step,
|
|
350
|
+
resumeData: body.resumeData,
|
|
351
|
+
runtimeContext
|
|
352
|
+
});
|
|
353
|
+
return result;
|
|
354
|
+
} catch (error) {
|
|
355
|
+
return handleError(error, "Error resuming workflow step");
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
async function resumeWorkflowHandler({
|
|
359
|
+
mastra,
|
|
360
|
+
workflowId,
|
|
361
|
+
runId,
|
|
362
|
+
body,
|
|
363
|
+
runtimeContext
|
|
364
|
+
}) {
|
|
365
|
+
try {
|
|
366
|
+
if (!workflowId) {
|
|
367
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
368
|
+
}
|
|
369
|
+
if (!runId) {
|
|
370
|
+
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
371
|
+
}
|
|
372
|
+
if (!body.step) {
|
|
373
|
+
throw new HTTPException(400, { message: "step required to resume workflow" });
|
|
374
|
+
}
|
|
375
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
376
|
+
if (!workflow) {
|
|
377
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
378
|
+
}
|
|
379
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
380
|
+
if (!run) {
|
|
381
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
382
|
+
}
|
|
383
|
+
const _run = await workflow.createRun({ runId });
|
|
384
|
+
void _run.resume({
|
|
385
|
+
step: body.step,
|
|
386
|
+
resumeData: body.resumeData,
|
|
387
|
+
runtimeContext
|
|
388
|
+
});
|
|
389
|
+
return { message: "Workflow run resumed" };
|
|
390
|
+
} catch (error) {
|
|
391
|
+
return handleError(error, "Error resuming workflow");
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
async function getWorkflowRunsHandler({
|
|
395
|
+
mastra,
|
|
396
|
+
workflowId,
|
|
397
|
+
fromDate,
|
|
398
|
+
toDate,
|
|
399
|
+
limit,
|
|
400
|
+
offset,
|
|
401
|
+
resourceId
|
|
402
|
+
}) {
|
|
403
|
+
try {
|
|
404
|
+
if (!workflowId) {
|
|
405
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
406
|
+
}
|
|
407
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
408
|
+
if (!workflow) {
|
|
409
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
410
|
+
}
|
|
411
|
+
const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
|
|
412
|
+
runs: [],
|
|
413
|
+
total: 0
|
|
414
|
+
};
|
|
415
|
+
return workflowRuns;
|
|
416
|
+
} catch (error) {
|
|
417
|
+
return handleError(error, "Error getting workflow runs");
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export { createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunExecutionResultHandler, getWorkflowRunsHandler, getWorkflowsHandler, resumeAsyncWorkflowHandler, resumeWorkflowHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamWorkflowHandler, watchWorkflowHandler, workflows_exports };
|