@mastra/server 0.10.5 → 0.10.6-alpha.1
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 +17 -13
- package/dist/_tsup-dts-rollup.d.ts +17 -13
- package/dist/{chunk-HYP7B2TL.js → chunk-2HXKRRNS.js} +1 -1
- package/dist/{chunk-JEWNMAYQ.cjs → chunk-42YJ2YVD.cjs} +5 -5
- package/dist/{chunk-XUGQSVZ4.cjs → chunk-ASKESBJW.cjs} +35 -35
- package/dist/{chunk-TEZOEGR4.js → chunk-CLYX4KLH.js} +1 -1
- package/dist/{chunk-JKF6PRPU.cjs → chunk-FRXZL32L.cjs} +143 -29
- package/dist/{chunk-7IBZ4L35.js → chunk-JKTNRUKY.js} +131 -18
- package/dist/{chunk-TJO277H7.cjs → chunk-NGURCFEJ.cjs} +5 -5
- package/dist/{chunk-6F2H7Y45.js → chunk-O2YAAFY3.js} +1 -1
- package/dist/{chunk-WKWHYFX4.js → chunk-TGJMNUYJ.js} +35 -35
- package/dist/{chunk-UZ7FJ66C.cjs → chunk-WE32JG64.cjs} +7 -7
- package/dist/server/handlers/agents.cjs +7 -7
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/legacyWorkflows.cjs +11 -11
- package/dist/server/handlers/legacyWorkflows.js +1 -1
- package/dist/server/handlers/tools.cjs +5 -5
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/workflows.cjs +16 -12
- package/dist/server/handlers/workflows.d.cts +1 -0
- package/dist/server/handlers/workflows.d.ts +1 -0
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +8 -8
- package/dist/server/handlers.js +4 -4
- package/package.json +5 -6
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkASKESBJW_cjs = require('./chunk-ASKESBJW.cjs');
|
|
4
4
|
var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
|
|
5
5
|
var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
|
|
6
6
|
var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
|
|
7
7
|
var web = require('stream/web');
|
|
8
|
+
var di = require('@mastra/core/di');
|
|
8
9
|
|
|
9
10
|
// src/server/handlers/workflows.ts
|
|
10
11
|
var workflows_exports = {};
|
|
@@ -12,6 +13,7 @@ chunk75ZPJI57_cjs.__export(workflows_exports, {
|
|
|
12
13
|
createWorkflowRunHandler: () => createWorkflowRunHandler,
|
|
13
14
|
getWorkflowByIdHandler: () => getWorkflowByIdHandler,
|
|
14
15
|
getWorkflowRunByIdHandler: () => getWorkflowRunByIdHandler,
|
|
16
|
+
getWorkflowRunExecutionResultHandler: () => getWorkflowRunExecutionResultHandler,
|
|
15
17
|
getWorkflowRunsHandler: () => getWorkflowRunsHandler,
|
|
16
18
|
getWorkflowsHandler: () => getWorkflowsHandler,
|
|
17
19
|
resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
|
|
@@ -32,16 +34,16 @@ async function getWorkflowsHandler({ mastra }) {
|
|
|
32
34
|
acc2[key2] = {
|
|
33
35
|
id: step.id,
|
|
34
36
|
description: step.description,
|
|
35
|
-
inputSchema: step.inputSchema ?
|
|
36
|
-
outputSchema: step.outputSchema ?
|
|
37
|
-
resumeSchema: step.resumeSchema ?
|
|
38
|
-
suspendSchema: step.suspendSchema ?
|
|
37
|
+
inputSchema: step.inputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(step.inputSchema)) : void 0,
|
|
38
|
+
outputSchema: step.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(step.outputSchema)) : void 0,
|
|
39
|
+
resumeSchema: step.resumeSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(step.resumeSchema)) : void 0,
|
|
40
|
+
suspendSchema: step.suspendSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(step.suspendSchema)) : void 0
|
|
39
41
|
};
|
|
40
42
|
return acc2;
|
|
41
43
|
}, {}),
|
|
42
44
|
stepGraph: workflow.serializedStepGraph,
|
|
43
|
-
inputSchema: workflow.inputSchema ?
|
|
44
|
-
outputSchema: workflow.outputSchema ?
|
|
45
|
+
inputSchema: workflow.inputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(workflow.inputSchema)) : void 0,
|
|
46
|
+
outputSchema: workflow.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(workflow.outputSchema)) : void 0
|
|
45
47
|
};
|
|
46
48
|
return acc;
|
|
47
49
|
}, {});
|
|
@@ -50,12 +52,46 @@ async function getWorkflowsHandler({ mastra }) {
|
|
|
50
52
|
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error getting workflows" });
|
|
51
53
|
}
|
|
52
54
|
}
|
|
55
|
+
async function getWorkflowsFromSystem({ mastra, workflowId }) {
|
|
56
|
+
const logger = mastra.getLogger();
|
|
57
|
+
if (!workflowId) {
|
|
58
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
59
|
+
}
|
|
60
|
+
let workflow;
|
|
61
|
+
try {
|
|
62
|
+
workflow = mastra.getWorkflow(workflowId);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
logger.debug("Error getting workflow, searching agents for workflow", error);
|
|
65
|
+
}
|
|
66
|
+
if (!workflow) {
|
|
67
|
+
logger.debug("Workflow not found, searching agents for workflow", { workflowId });
|
|
68
|
+
const agents = mastra.getAgents();
|
|
69
|
+
if (Object.keys(agents || {}).length) {
|
|
70
|
+
for (const [_, agent] of Object.entries(agents)) {
|
|
71
|
+
try {
|
|
72
|
+
const workflows = await agent.getWorkflows();
|
|
73
|
+
if (workflows[workflowId]) {
|
|
74
|
+
workflow = workflows[workflowId];
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
logger.debug("Error getting workflow from agent", error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (!workflow) {
|
|
85
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
86
|
+
}
|
|
87
|
+
return { workflow };
|
|
88
|
+
}
|
|
53
89
|
async function getWorkflowByIdHandler({ mastra, workflowId }) {
|
|
54
90
|
try {
|
|
55
91
|
if (!workflowId) {
|
|
56
92
|
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
57
93
|
}
|
|
58
|
-
const workflow = mastra
|
|
94
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
59
95
|
if (!workflow) {
|
|
60
96
|
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
61
97
|
}
|
|
@@ -64,18 +100,18 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
|
|
|
64
100
|
acc[key] = {
|
|
65
101
|
id: step.id,
|
|
66
102
|
description: step.description,
|
|
67
|
-
inputSchema: step.inputSchema ?
|
|
68
|
-
outputSchema: step.outputSchema ?
|
|
69
|
-
resumeSchema: step.resumeSchema ?
|
|
70
|
-
suspendSchema: step.suspendSchema ?
|
|
103
|
+
inputSchema: step.inputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(step.inputSchema)) : void 0,
|
|
104
|
+
outputSchema: step.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(step.outputSchema)) : void 0,
|
|
105
|
+
resumeSchema: step.resumeSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(step.resumeSchema)) : void 0,
|
|
106
|
+
suspendSchema: step.suspendSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(step.suspendSchema)) : void 0
|
|
71
107
|
};
|
|
72
108
|
return acc;
|
|
73
109
|
}, {}),
|
|
74
110
|
name: workflow.name,
|
|
75
111
|
description: workflow.description,
|
|
76
112
|
stepGraph: workflow.serializedStepGraph,
|
|
77
|
-
inputSchema: workflow.inputSchema ?
|
|
78
|
-
outputSchema: workflow.outputSchema ?
|
|
113
|
+
inputSchema: workflow.inputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(workflow.inputSchema)) : void 0,
|
|
114
|
+
outputSchema: workflow.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(workflow.outputSchema)) : void 0
|
|
79
115
|
};
|
|
80
116
|
} catch (error) {
|
|
81
117
|
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error getting workflow" });
|
|
@@ -93,7 +129,7 @@ async function getWorkflowRunByIdHandler({
|
|
|
93
129
|
if (!runId) {
|
|
94
130
|
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Run ID is required" });
|
|
95
131
|
}
|
|
96
|
-
const workflow = mastra
|
|
132
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
97
133
|
if (!workflow) {
|
|
98
134
|
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
99
135
|
}
|
|
@@ -106,6 +142,33 @@ async function getWorkflowRunByIdHandler({
|
|
|
106
142
|
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error getting workflow run" });
|
|
107
143
|
}
|
|
108
144
|
}
|
|
145
|
+
async function getWorkflowRunExecutionResultHandler({
|
|
146
|
+
mastra,
|
|
147
|
+
workflowId,
|
|
148
|
+
runId
|
|
149
|
+
}) {
|
|
150
|
+
try {
|
|
151
|
+
if (!workflowId) {
|
|
152
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
153
|
+
}
|
|
154
|
+
if (!runId) {
|
|
155
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Run ID is required" });
|
|
156
|
+
}
|
|
157
|
+
const workflow = mastra.getWorkflow(workflowId);
|
|
158
|
+
if (!workflow) {
|
|
159
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
160
|
+
}
|
|
161
|
+
const executionResult = await workflow.getWorkflowRunExecutionResult(runId);
|
|
162
|
+
if (!executionResult) {
|
|
163
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run execution result not found" });
|
|
164
|
+
}
|
|
165
|
+
return executionResult;
|
|
166
|
+
} catch (error) {
|
|
167
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(500, {
|
|
168
|
+
message: error?.message || "Error getting workflow run execution result"
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
109
172
|
async function createWorkflowRunHandler({
|
|
110
173
|
mastra,
|
|
111
174
|
workflowId,
|
|
@@ -115,7 +178,7 @@ async function createWorkflowRunHandler({
|
|
|
115
178
|
if (!workflowId) {
|
|
116
179
|
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
117
180
|
}
|
|
118
|
-
const workflow = mastra
|
|
181
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
119
182
|
if (!workflow) {
|
|
120
183
|
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
121
184
|
}
|
|
@@ -127,7 +190,7 @@ async function createWorkflowRunHandler({
|
|
|
127
190
|
}
|
|
128
191
|
async function startAsyncWorkflowHandler({
|
|
129
192
|
mastra,
|
|
130
|
-
runtimeContext,
|
|
193
|
+
runtimeContext: payloadRuntimeContext,
|
|
131
194
|
workflowId,
|
|
132
195
|
runId,
|
|
133
196
|
inputData
|
|
@@ -136,10 +199,17 @@ async function startAsyncWorkflowHandler({
|
|
|
136
199
|
if (!workflowId) {
|
|
137
200
|
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
138
201
|
}
|
|
139
|
-
const workflow = mastra
|
|
202
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
140
203
|
if (!workflow) {
|
|
141
204
|
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
142
205
|
}
|
|
206
|
+
let runtimeContext;
|
|
207
|
+
if (payloadRuntimeContext) {
|
|
208
|
+
runtimeContext = new di.RuntimeContext();
|
|
209
|
+
Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
|
|
210
|
+
runtimeContext.set(key, value);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
143
213
|
const _run = workflow.createRun({ runId });
|
|
144
214
|
const result = await _run.start({
|
|
145
215
|
inputData,
|
|
@@ -152,7 +222,7 @@ async function startAsyncWorkflowHandler({
|
|
|
152
222
|
}
|
|
153
223
|
async function startWorkflowRunHandler({
|
|
154
224
|
mastra,
|
|
155
|
-
runtimeContext,
|
|
225
|
+
runtimeContext: payloadRuntimeContext,
|
|
156
226
|
workflowId,
|
|
157
227
|
runId,
|
|
158
228
|
inputData
|
|
@@ -164,11 +234,21 @@ async function startWorkflowRunHandler({
|
|
|
164
234
|
if (!runId) {
|
|
165
235
|
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to start run" });
|
|
166
236
|
}
|
|
167
|
-
const workflow = mastra
|
|
237
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
238
|
+
if (!workflow) {
|
|
239
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
240
|
+
}
|
|
168
241
|
const run = await workflow.getWorkflowRunById(runId);
|
|
169
242
|
if (!run) {
|
|
170
243
|
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
171
244
|
}
|
|
245
|
+
let runtimeContext;
|
|
246
|
+
if (payloadRuntimeContext) {
|
|
247
|
+
runtimeContext = new di.RuntimeContext();
|
|
248
|
+
Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
|
|
249
|
+
runtimeContext.set(key, value);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
172
252
|
const _run = workflow.createRun({ runId });
|
|
173
253
|
void _run.start({
|
|
174
254
|
inputData,
|
|
@@ -191,7 +271,10 @@ async function watchWorkflowHandler({
|
|
|
191
271
|
if (!runId) {
|
|
192
272
|
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to watch workflow" });
|
|
193
273
|
}
|
|
194
|
-
const workflow = mastra
|
|
274
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
275
|
+
if (!workflow) {
|
|
276
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
277
|
+
}
|
|
195
278
|
const run = await workflow.getWorkflowRunById(runId);
|
|
196
279
|
if (!run) {
|
|
197
280
|
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
@@ -225,9 +308,9 @@ async function watchWorkflowHandler({
|
|
|
225
308
|
return chunk64U3UDTH_cjs.handleError(error, "Error watching workflow");
|
|
226
309
|
}
|
|
227
310
|
}
|
|
228
|
-
function streamWorkflowHandler({
|
|
311
|
+
async function streamWorkflowHandler({
|
|
229
312
|
mastra,
|
|
230
|
-
runtimeContext,
|
|
313
|
+
runtimeContext: payloadRuntimeContext,
|
|
231
314
|
workflowId,
|
|
232
315
|
runId,
|
|
233
316
|
inputData
|
|
@@ -239,10 +322,17 @@ function streamWorkflowHandler({
|
|
|
239
322
|
if (!runId) {
|
|
240
323
|
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to resume workflow" });
|
|
241
324
|
}
|
|
242
|
-
const workflow = mastra
|
|
325
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
243
326
|
if (!workflow) {
|
|
244
327
|
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
245
328
|
}
|
|
329
|
+
let runtimeContext;
|
|
330
|
+
if (payloadRuntimeContext) {
|
|
331
|
+
runtimeContext = new di.RuntimeContext();
|
|
332
|
+
Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
|
|
333
|
+
runtimeContext.set(key, value);
|
|
334
|
+
});
|
|
335
|
+
}
|
|
246
336
|
const run = workflow.createRun({ runId });
|
|
247
337
|
const result = run.stream({
|
|
248
338
|
inputData,
|
|
@@ -258,7 +348,7 @@ async function resumeAsyncWorkflowHandler({
|
|
|
258
348
|
workflowId,
|
|
259
349
|
runId,
|
|
260
350
|
body,
|
|
261
|
-
runtimeContext
|
|
351
|
+
runtimeContext: payloadRuntimeContext
|
|
262
352
|
}) {
|
|
263
353
|
try {
|
|
264
354
|
if (!workflowId) {
|
|
@@ -270,11 +360,21 @@ async function resumeAsyncWorkflowHandler({
|
|
|
270
360
|
if (!body.step) {
|
|
271
361
|
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "step required to resume workflow" });
|
|
272
362
|
}
|
|
273
|
-
const workflow = mastra
|
|
363
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
364
|
+
if (!workflow) {
|
|
365
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
366
|
+
}
|
|
274
367
|
const run = await workflow.getWorkflowRunById(runId);
|
|
275
368
|
if (!run) {
|
|
276
369
|
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
277
370
|
}
|
|
371
|
+
let runtimeContext;
|
|
372
|
+
if (payloadRuntimeContext) {
|
|
373
|
+
runtimeContext = new di.RuntimeContext();
|
|
374
|
+
Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
|
|
375
|
+
runtimeContext.set(key, value);
|
|
376
|
+
});
|
|
377
|
+
}
|
|
278
378
|
const _run = workflow.createRun({ runId });
|
|
279
379
|
const result = await _run.resume({
|
|
280
380
|
step: body.step,
|
|
@@ -291,7 +391,7 @@ async function resumeWorkflowHandler({
|
|
|
291
391
|
workflowId,
|
|
292
392
|
runId,
|
|
293
393
|
body,
|
|
294
|
-
runtimeContext
|
|
394
|
+
runtimeContext: payloadRuntimeContext
|
|
295
395
|
}) {
|
|
296
396
|
try {
|
|
297
397
|
if (!workflowId) {
|
|
@@ -303,11 +403,21 @@ async function resumeWorkflowHandler({
|
|
|
303
403
|
if (!body.step) {
|
|
304
404
|
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "step required to resume workflow" });
|
|
305
405
|
}
|
|
306
|
-
const workflow = mastra
|
|
406
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
407
|
+
if (!workflow) {
|
|
408
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
409
|
+
}
|
|
307
410
|
const run = await workflow.getWorkflowRunById(runId);
|
|
308
411
|
if (!run) {
|
|
309
412
|
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
310
413
|
}
|
|
414
|
+
let runtimeContext;
|
|
415
|
+
if (payloadRuntimeContext) {
|
|
416
|
+
runtimeContext = new di.RuntimeContext();
|
|
417
|
+
Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
|
|
418
|
+
runtimeContext.set(key, value);
|
|
419
|
+
});
|
|
420
|
+
}
|
|
311
421
|
const _run = workflow.createRun({ runId });
|
|
312
422
|
void _run.resume({
|
|
313
423
|
step: body.step,
|
|
@@ -332,7 +442,10 @@ async function getWorkflowRunsHandler({
|
|
|
332
442
|
if (!workflowId) {
|
|
333
443
|
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
334
444
|
}
|
|
335
|
-
const workflow = mastra
|
|
445
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
446
|
+
if (!workflow) {
|
|
447
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
448
|
+
}
|
|
336
449
|
const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
|
|
337
450
|
runs: [],
|
|
338
451
|
total: 0
|
|
@@ -346,6 +459,7 @@ async function getWorkflowRunsHandler({
|
|
|
346
459
|
exports.createWorkflowRunHandler = createWorkflowRunHandler;
|
|
347
460
|
exports.getWorkflowByIdHandler = getWorkflowByIdHandler;
|
|
348
461
|
exports.getWorkflowRunByIdHandler = getWorkflowRunByIdHandler;
|
|
462
|
+
exports.getWorkflowRunExecutionResultHandler = getWorkflowRunExecutionResultHandler;
|
|
349
463
|
exports.getWorkflowRunsHandler = getWorkflowRunsHandler;
|
|
350
464
|
exports.getWorkflowsHandler = getWorkflowsHandler;
|
|
351
465
|
exports.resumeAsyncWorkflowHandler = resumeAsyncWorkflowHandler;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { stringify, esm_default } from './chunk-
|
|
1
|
+
import { stringify, esm_default } from './chunk-TGJMNUYJ.js';
|
|
2
2
|
import { handleError } from './chunk-M5ABIP7D.js';
|
|
3
3
|
import { HTTPException } from './chunk-NYN7KFXL.js';
|
|
4
4
|
import { __export } from './chunk-MLKGABMK.js';
|
|
5
5
|
import { ReadableStream } from 'stream/web';
|
|
6
|
+
import { RuntimeContext } from '@mastra/core/di';
|
|
6
7
|
|
|
7
8
|
// src/server/handlers/workflows.ts
|
|
8
9
|
var workflows_exports = {};
|
|
@@ -10,6 +11,7 @@ __export(workflows_exports, {
|
|
|
10
11
|
createWorkflowRunHandler: () => createWorkflowRunHandler,
|
|
11
12
|
getWorkflowByIdHandler: () => getWorkflowByIdHandler,
|
|
12
13
|
getWorkflowRunByIdHandler: () => getWorkflowRunByIdHandler,
|
|
14
|
+
getWorkflowRunExecutionResultHandler: () => getWorkflowRunExecutionResultHandler,
|
|
13
15
|
getWorkflowRunsHandler: () => getWorkflowRunsHandler,
|
|
14
16
|
getWorkflowsHandler: () => getWorkflowsHandler,
|
|
15
17
|
resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
|
|
@@ -48,12 +50,46 @@ async function getWorkflowsHandler({ mastra }) {
|
|
|
48
50
|
throw new HTTPException(500, { message: error?.message || "Error getting workflows" });
|
|
49
51
|
}
|
|
50
52
|
}
|
|
53
|
+
async function getWorkflowsFromSystem({ mastra, workflowId }) {
|
|
54
|
+
const logger = mastra.getLogger();
|
|
55
|
+
if (!workflowId) {
|
|
56
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
57
|
+
}
|
|
58
|
+
let workflow;
|
|
59
|
+
try {
|
|
60
|
+
workflow = mastra.getWorkflow(workflowId);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
logger.debug("Error getting workflow, searching agents for workflow", error);
|
|
63
|
+
}
|
|
64
|
+
if (!workflow) {
|
|
65
|
+
logger.debug("Workflow not found, searching agents for workflow", { workflowId });
|
|
66
|
+
const agents = mastra.getAgents();
|
|
67
|
+
if (Object.keys(agents || {}).length) {
|
|
68
|
+
for (const [_, agent] of Object.entries(agents)) {
|
|
69
|
+
try {
|
|
70
|
+
const workflows = await agent.getWorkflows();
|
|
71
|
+
if (workflows[workflowId]) {
|
|
72
|
+
workflow = workflows[workflowId];
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
} catch (error) {
|
|
77
|
+
logger.debug("Error getting workflow from agent", error);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (!workflow) {
|
|
83
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
84
|
+
}
|
|
85
|
+
return { workflow };
|
|
86
|
+
}
|
|
51
87
|
async function getWorkflowByIdHandler({ mastra, workflowId }) {
|
|
52
88
|
try {
|
|
53
89
|
if (!workflowId) {
|
|
54
90
|
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
55
91
|
}
|
|
56
|
-
const workflow = mastra
|
|
92
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
57
93
|
if (!workflow) {
|
|
58
94
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
59
95
|
}
|
|
@@ -91,7 +127,7 @@ async function getWorkflowRunByIdHandler({
|
|
|
91
127
|
if (!runId) {
|
|
92
128
|
throw new HTTPException(400, { message: "Run ID is required" });
|
|
93
129
|
}
|
|
94
|
-
const workflow = mastra
|
|
130
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
95
131
|
if (!workflow) {
|
|
96
132
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
97
133
|
}
|
|
@@ -104,6 +140,33 @@ async function getWorkflowRunByIdHandler({
|
|
|
104
140
|
throw new HTTPException(500, { message: error?.message || "Error getting workflow run" });
|
|
105
141
|
}
|
|
106
142
|
}
|
|
143
|
+
async function getWorkflowRunExecutionResultHandler({
|
|
144
|
+
mastra,
|
|
145
|
+
workflowId,
|
|
146
|
+
runId
|
|
147
|
+
}) {
|
|
148
|
+
try {
|
|
149
|
+
if (!workflowId) {
|
|
150
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
151
|
+
}
|
|
152
|
+
if (!runId) {
|
|
153
|
+
throw new HTTPException(400, { message: "Run ID is required" });
|
|
154
|
+
}
|
|
155
|
+
const workflow = mastra.getWorkflow(workflowId);
|
|
156
|
+
if (!workflow) {
|
|
157
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
158
|
+
}
|
|
159
|
+
const executionResult = await workflow.getWorkflowRunExecutionResult(runId);
|
|
160
|
+
if (!executionResult) {
|
|
161
|
+
throw new HTTPException(404, { message: "Workflow run execution result not found" });
|
|
162
|
+
}
|
|
163
|
+
return executionResult;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
throw new HTTPException(500, {
|
|
166
|
+
message: error?.message || "Error getting workflow run execution result"
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
107
170
|
async function createWorkflowRunHandler({
|
|
108
171
|
mastra,
|
|
109
172
|
workflowId,
|
|
@@ -113,7 +176,7 @@ async function createWorkflowRunHandler({
|
|
|
113
176
|
if (!workflowId) {
|
|
114
177
|
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
115
178
|
}
|
|
116
|
-
const workflow = mastra
|
|
179
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
117
180
|
if (!workflow) {
|
|
118
181
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
119
182
|
}
|
|
@@ -125,7 +188,7 @@ async function createWorkflowRunHandler({
|
|
|
125
188
|
}
|
|
126
189
|
async function startAsyncWorkflowHandler({
|
|
127
190
|
mastra,
|
|
128
|
-
runtimeContext,
|
|
191
|
+
runtimeContext: payloadRuntimeContext,
|
|
129
192
|
workflowId,
|
|
130
193
|
runId,
|
|
131
194
|
inputData
|
|
@@ -134,10 +197,17 @@ async function startAsyncWorkflowHandler({
|
|
|
134
197
|
if (!workflowId) {
|
|
135
198
|
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
136
199
|
}
|
|
137
|
-
const workflow = mastra
|
|
200
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
138
201
|
if (!workflow) {
|
|
139
202
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
140
203
|
}
|
|
204
|
+
let runtimeContext;
|
|
205
|
+
if (payloadRuntimeContext) {
|
|
206
|
+
runtimeContext = new RuntimeContext();
|
|
207
|
+
Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
|
|
208
|
+
runtimeContext.set(key, value);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
141
211
|
const _run = workflow.createRun({ runId });
|
|
142
212
|
const result = await _run.start({
|
|
143
213
|
inputData,
|
|
@@ -150,7 +220,7 @@ async function startAsyncWorkflowHandler({
|
|
|
150
220
|
}
|
|
151
221
|
async function startWorkflowRunHandler({
|
|
152
222
|
mastra,
|
|
153
|
-
runtimeContext,
|
|
223
|
+
runtimeContext: payloadRuntimeContext,
|
|
154
224
|
workflowId,
|
|
155
225
|
runId,
|
|
156
226
|
inputData
|
|
@@ -162,11 +232,21 @@ async function startWorkflowRunHandler({
|
|
|
162
232
|
if (!runId) {
|
|
163
233
|
throw new HTTPException(400, { message: "runId required to start run" });
|
|
164
234
|
}
|
|
165
|
-
const workflow = mastra
|
|
235
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
236
|
+
if (!workflow) {
|
|
237
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
238
|
+
}
|
|
166
239
|
const run = await workflow.getWorkflowRunById(runId);
|
|
167
240
|
if (!run) {
|
|
168
241
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
169
242
|
}
|
|
243
|
+
let runtimeContext;
|
|
244
|
+
if (payloadRuntimeContext) {
|
|
245
|
+
runtimeContext = new RuntimeContext();
|
|
246
|
+
Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
|
|
247
|
+
runtimeContext.set(key, value);
|
|
248
|
+
});
|
|
249
|
+
}
|
|
170
250
|
const _run = workflow.createRun({ runId });
|
|
171
251
|
void _run.start({
|
|
172
252
|
inputData,
|
|
@@ -189,7 +269,10 @@ async function watchWorkflowHandler({
|
|
|
189
269
|
if (!runId) {
|
|
190
270
|
throw new HTTPException(400, { message: "runId required to watch workflow" });
|
|
191
271
|
}
|
|
192
|
-
const workflow = mastra
|
|
272
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
273
|
+
if (!workflow) {
|
|
274
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
275
|
+
}
|
|
193
276
|
const run = await workflow.getWorkflowRunById(runId);
|
|
194
277
|
if (!run) {
|
|
195
278
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
@@ -223,9 +306,9 @@ async function watchWorkflowHandler({
|
|
|
223
306
|
return handleError(error, "Error watching workflow");
|
|
224
307
|
}
|
|
225
308
|
}
|
|
226
|
-
function streamWorkflowHandler({
|
|
309
|
+
async function streamWorkflowHandler({
|
|
227
310
|
mastra,
|
|
228
|
-
runtimeContext,
|
|
311
|
+
runtimeContext: payloadRuntimeContext,
|
|
229
312
|
workflowId,
|
|
230
313
|
runId,
|
|
231
314
|
inputData
|
|
@@ -237,10 +320,17 @@ function streamWorkflowHandler({
|
|
|
237
320
|
if (!runId) {
|
|
238
321
|
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
239
322
|
}
|
|
240
|
-
const workflow = mastra
|
|
323
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
241
324
|
if (!workflow) {
|
|
242
325
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
243
326
|
}
|
|
327
|
+
let runtimeContext;
|
|
328
|
+
if (payloadRuntimeContext) {
|
|
329
|
+
runtimeContext = new RuntimeContext();
|
|
330
|
+
Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
|
|
331
|
+
runtimeContext.set(key, value);
|
|
332
|
+
});
|
|
333
|
+
}
|
|
244
334
|
const run = workflow.createRun({ runId });
|
|
245
335
|
const result = run.stream({
|
|
246
336
|
inputData,
|
|
@@ -256,7 +346,7 @@ async function resumeAsyncWorkflowHandler({
|
|
|
256
346
|
workflowId,
|
|
257
347
|
runId,
|
|
258
348
|
body,
|
|
259
|
-
runtimeContext
|
|
349
|
+
runtimeContext: payloadRuntimeContext
|
|
260
350
|
}) {
|
|
261
351
|
try {
|
|
262
352
|
if (!workflowId) {
|
|
@@ -268,11 +358,21 @@ async function resumeAsyncWorkflowHandler({
|
|
|
268
358
|
if (!body.step) {
|
|
269
359
|
throw new HTTPException(400, { message: "step required to resume workflow" });
|
|
270
360
|
}
|
|
271
|
-
const workflow = mastra
|
|
361
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
362
|
+
if (!workflow) {
|
|
363
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
364
|
+
}
|
|
272
365
|
const run = await workflow.getWorkflowRunById(runId);
|
|
273
366
|
if (!run) {
|
|
274
367
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
275
368
|
}
|
|
369
|
+
let runtimeContext;
|
|
370
|
+
if (payloadRuntimeContext) {
|
|
371
|
+
runtimeContext = new RuntimeContext();
|
|
372
|
+
Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
|
|
373
|
+
runtimeContext.set(key, value);
|
|
374
|
+
});
|
|
375
|
+
}
|
|
276
376
|
const _run = workflow.createRun({ runId });
|
|
277
377
|
const result = await _run.resume({
|
|
278
378
|
step: body.step,
|
|
@@ -289,7 +389,7 @@ async function resumeWorkflowHandler({
|
|
|
289
389
|
workflowId,
|
|
290
390
|
runId,
|
|
291
391
|
body,
|
|
292
|
-
runtimeContext
|
|
392
|
+
runtimeContext: payloadRuntimeContext
|
|
293
393
|
}) {
|
|
294
394
|
try {
|
|
295
395
|
if (!workflowId) {
|
|
@@ -301,11 +401,21 @@ async function resumeWorkflowHandler({
|
|
|
301
401
|
if (!body.step) {
|
|
302
402
|
throw new HTTPException(400, { message: "step required to resume workflow" });
|
|
303
403
|
}
|
|
304
|
-
const workflow = mastra
|
|
404
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
405
|
+
if (!workflow) {
|
|
406
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
407
|
+
}
|
|
305
408
|
const run = await workflow.getWorkflowRunById(runId);
|
|
306
409
|
if (!run) {
|
|
307
410
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
308
411
|
}
|
|
412
|
+
let runtimeContext;
|
|
413
|
+
if (payloadRuntimeContext) {
|
|
414
|
+
runtimeContext = new RuntimeContext();
|
|
415
|
+
Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
|
|
416
|
+
runtimeContext.set(key, value);
|
|
417
|
+
});
|
|
418
|
+
}
|
|
309
419
|
const _run = workflow.createRun({ runId });
|
|
310
420
|
void _run.resume({
|
|
311
421
|
step: body.step,
|
|
@@ -330,7 +440,10 @@ async function getWorkflowRunsHandler({
|
|
|
330
440
|
if (!workflowId) {
|
|
331
441
|
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
332
442
|
}
|
|
333
|
-
const workflow = mastra
|
|
443
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
444
|
+
if (!workflow) {
|
|
445
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
446
|
+
}
|
|
334
447
|
const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
|
|
335
448
|
runs: [],
|
|
336
449
|
total: 0
|
|
@@ -341,4 +454,4 @@ async function getWorkflowRunsHandler({
|
|
|
341
454
|
}
|
|
342
455
|
}
|
|
343
456
|
|
|
344
|
-
export { createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunsHandler, getWorkflowsHandler, resumeAsyncWorkflowHandler, resumeWorkflowHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamWorkflowHandler, watchWorkflowHandler, workflows_exports };
|
|
457
|
+
export { createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunExecutionResultHandler, getWorkflowRunsHandler, getWorkflowsHandler, resumeAsyncWorkflowHandler, resumeWorkflowHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamWorkflowHandler, watchWorkflowHandler, workflows_exports };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkASKESBJW_cjs = require('./chunk-ASKESBJW.cjs');
|
|
4
4
|
var chunk57CJTIPW_cjs = require('./chunk-57CJTIPW.cjs');
|
|
5
5
|
var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
|
|
6
6
|
var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
|
|
@@ -25,8 +25,8 @@ async function getToolsHandler({ tools }) {
|
|
|
25
25
|
const tool = _tool;
|
|
26
26
|
acc[id] = {
|
|
27
27
|
...tool,
|
|
28
|
-
inputSchema: tool.inputSchema ?
|
|
29
|
-
outputSchema: tool.outputSchema ?
|
|
28
|
+
inputSchema: tool.inputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(tool.inputSchema)) : void 0,
|
|
29
|
+
outputSchema: tool.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(tool.outputSchema)) : void 0
|
|
30
30
|
};
|
|
31
31
|
return acc;
|
|
32
32
|
},
|
|
@@ -45,8 +45,8 @@ async function getToolByIdHandler({ tools, toolId }) {
|
|
|
45
45
|
}
|
|
46
46
|
const serializedTool = {
|
|
47
47
|
...tool,
|
|
48
|
-
inputSchema: tool.inputSchema ?
|
|
49
|
-
outputSchema: tool.outputSchema ?
|
|
48
|
+
inputSchema: tool.inputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(tool.inputSchema)) : void 0,
|
|
49
|
+
outputSchema: tool.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(tool.outputSchema)) : void 0
|
|
50
50
|
};
|
|
51
51
|
return serializedTool;
|
|
52
52
|
} catch (error) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { stringify, esm_default } from './chunk-
|
|
1
|
+
import { stringify, esm_default } from './chunk-TGJMNUYJ.js';
|
|
2
2
|
import { validateBody } from './chunk-H5PTF3Y4.js';
|
|
3
3
|
import { handleError } from './chunk-M5ABIP7D.js';
|
|
4
4
|
import { HTTPException } from './chunk-NYN7KFXL.js';
|