@mastra/server 0.10.13 → 0.10.15-alpha.0
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/dist/_tsup-dts-rollup.d.cts +1107 -0
- package/dist/_tsup-dts-rollup.d.ts +1107 -0
- package/dist/chunk-2KZFMI6P.cjs +37 -0
- package/dist/chunk-2SLFAFTR.cjs +148 -0
- package/dist/chunk-3CNDE7QY.cjs +308 -0
- package/dist/chunk-4D66QEKC.js +81 -0
- package/dist/chunk-5PQQ42EZ.js +320 -0
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/chunk-7TP2LX5L.cjs +129 -0
- package/dist/chunk-B2PAS2IB.cjs +514 -0
- package/dist/chunk-BK4XT6EG.js +270 -0
- package/dist/chunk-CCGRCYWJ.cjs +18 -0
- package/dist/chunk-CRCR3ZUK.js +142 -0
- package/dist/chunk-FRVBFMO2.cjs +128 -0
- package/dist/chunk-G7KH752Y.cjs +145 -0
- package/dist/chunk-GHC4YV6R.js +504 -0
- package/dist/chunk-H7DMHBKY.js +498 -0
- package/dist/chunk-JMLYCXMK.cjs +332 -0
- package/dist/chunk-KHZKYUNR.js +112 -0
- package/dist/chunk-KOHWJYJT.js +296 -0
- package/dist/chunk-LCM566I4.js +35 -0
- package/dist/chunk-LF7P5PLR.js +14 -0
- package/dist/chunk-LI436ITD.cjs +2042 -0
- package/dist/chunk-LRCAAFUA.js +122 -0
- package/dist/chunk-LZ3VJXSO.cjs +278 -0
- package/dist/chunk-MEGCYGBU.js +2039 -0
- package/dist/chunk-MLKGABMK.js +7 -0
- package/dist/chunk-PZQDCRPV.cjs +16 -0
- package/dist/chunk-QGX47B5D.cjs +86 -0
- package/dist/chunk-RG473F6Y.js +141 -0
- package/dist/chunk-RHSWAXKB.cjs +118 -0
- package/dist/chunk-RSEO4XPX.js +16 -0
- package/dist/chunk-SDPGVWQJ.cjs +512 -0
- package/dist/chunk-WNVFNNWN.js +121 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -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 +30 -0
- package/dist/server/handlers/agents.d.cts +6 -0
- package/dist/server/handlers/agents.d.ts +6 -0
- package/dist/server/handlers/agents.js +1 -0
- package/dist/server/handlers/error.cjs +10 -0
- package/dist/server/handlers/error.d.cts +1 -0
- package/dist/server/handlers/error.d.ts +1 -0
- package/dist/server/handlers/error.js +1 -0
- 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 +18 -0
- package/dist/server/handlers/logs.d.cts +3 -0
- package/dist/server/handlers/logs.d.ts +3 -0
- package/dist/server/handlers/logs.js +1 -0
- package/dist/server/handlers/memory.cjs +46 -0
- package/dist/server/handlers/memory.d.cts +10 -0
- package/dist/server/handlers/memory.d.ts +10 -0
- package/dist/server/handlers/memory.js +1 -0
- package/dist/server/handlers/network.cjs +22 -0
- package/dist/server/handlers/network.d.cts +4 -0
- package/dist/server/handlers/network.d.ts +4 -0
- package/dist/server/handlers/network.js +1 -0
- package/dist/server/handlers/telemetry.cjs +14 -0
- package/dist/server/handlers/telemetry.d.cts +2 -0
- package/dist/server/handlers/telemetry.d.ts +2 -0
- package/dist/server/handlers/telemetry.js +1 -0
- package/dist/server/handlers/tools.cjs +22 -0
- package/dist/server/handlers/tools.d.cts +4 -0
- package/dist/server/handlers/tools.d.ts +4 -0
- package/dist/server/handlers/tools.js +1 -0
- package/dist/server/handlers/utils.cjs +10 -0
- package/dist/server/handlers/utils.d.cts +1 -0
- package/dist/server/handlers/utils.d.ts +1 -0
- package/dist/server/handlers/utils.js +1 -0
- 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 +30 -0
- package/dist/server/handlers/vector.d.cts +6 -0
- package/dist/server/handlers/vector.d.ts +6 -0
- package/dist/server/handlers/vector.js +1 -0
- package/dist/server/handlers/voice.cjs +22 -0
- package/dist/server/handlers/voice.d.cts +4 -0
- package/dist/server/handlers/voice.d.ts +4 -0
- package/dist/server/handlers/voice.js +1 -0
- package/dist/server/handlers/workflows.cjs +62 -0
- package/dist/server/handlers/workflows.d.cts +14 -0
- package/dist/server/handlers/workflows.d.ts +14 -0
- package/dist/server/handlers/workflows.js +1 -0
- package/dist/server/handlers.cjs +60 -0
- package/dist/server/handlers.d.cts +11 -0
- package/dist/server/handlers.d.ts +11 -0
- package/dist/server/handlers.js +11 -0
- package/package.json +3 -3
|
@@ -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;
|