@mastra/server 0.0.0-generate-message-id-20250512171942 → 0.0.0-http-transporter-20250702160118
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 +394 -128
- package/dist/_tsup-dts-rollup.d.ts +394 -128
- 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-EJO45KYT.js → chunk-5PQQ42EZ.js} +43 -43
- package/dist/{chunk-4YZ3U35L.cjs → chunk-7TP2LX5L.cjs} +18 -18
- package/dist/chunk-B2PAS2IB.cjs +514 -0
- package/dist/{chunk-Q6KMBIAN.js → chunk-BK4XT6EG.js} +93 -14
- package/dist/{chunk-57CJTIPW.cjs → chunk-CCGRCYWJ.cjs} +2 -2
- package/dist/{chunk-C7564HUT.js → chunk-CRCR3ZUK.js} +3 -3
- package/dist/{chunk-24EGIVT7.cjs → chunk-DN7K6FJK.cjs} +91 -54
- package/dist/{chunk-ZE5AAC4I.cjs → chunk-FRVBFMO2.cjs} +26 -36
- package/dist/{chunk-MHKNLNAN.cjs → chunk-G7KH752Y.cjs} +10 -7
- package/dist/{chunk-P6SCPDYW.js → chunk-GHC4YV6R.js} +5 -1
- package/dist/chunk-H7DMHBKY.js +498 -0
- package/dist/chunk-JMLYCXMK.cjs +332 -0
- package/dist/{chunk-HFWCEP5S.js → chunk-KHZKYUNR.js} +33 -10
- 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-3HQNCTZ2.cjs → chunk-LZ3VJXSO.cjs} +107 -28
- package/dist/{chunk-LIVAK2DM.js → chunk-MEGCYGBU.js} +108 -70
- package/dist/{chunk-X3ZDCS52.js → chunk-MKLYEKEF.js} +62 -25
- package/dist/chunk-PZQDCRPV.cjs +16 -0
- package/dist/chunk-QGX47B5D.cjs +86 -0
- package/dist/{chunk-OR3CIE2H.js → chunk-RG473F6Y.js} +7 -4
- package/dist/chunk-RHSWAXKB.cjs +118 -0
- package/dist/{chunk-H5PTF3Y4.js → chunk-RSEO4XPX.js} +1 -1
- package/dist/{chunk-5SN4U5AC.cjs → chunk-SDPGVWQJ.cjs} +5 -1
- package/dist/{chunk-IU5VO2I2.js → chunk-WNVFNNWN.js} +4 -4
- package/dist/server/handlers/a2a.cjs +7 -7
- package/dist/server/handlers/a2a.js +1 -1
- 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/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 +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 +29 -13
- package/dist/server/handlers/workflows.d.cts +6 -2
- package/dist/server/handlers/workflows.d.ts +6 -2
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +28 -28
- package/dist/server/handlers.d.cts +1 -1
- package/dist/server/handlers.d.ts +1 -1
- package/dist/server/handlers.js +11 -11
- package/package.json +12 -13
- package/dist/chunk-64U3UDTH.cjs +0 -13
- package/dist/chunk-HWZVAG3H.js +0 -49
- package/dist/chunk-I2B73Y4I.cjs +0 -332
- package/dist/chunk-M5ABIP7D.js +0 -11
- package/dist/chunk-MIQYDLLM.js +0 -329
- package/dist/chunk-OGCNNUHF.cjs +0 -54
- package/dist/chunk-UCTEMO2Q.cjs +0 -341
- package/dist/chunk-YBVOQN4M.cjs +0 -94
- package/dist/server/handlers/vNextWorkflows.cjs +0 -46
- package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
- package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
- package/dist/server/handlers/vNextWorkflows.js +0 -1
|
@@ -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;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { stringify, esm_default } from './chunk-
|
|
2
|
-
import { validateBody } from './chunk-
|
|
3
|
-
import { handleError } from './chunk-
|
|
4
|
-
import { HTTPException } from './chunk-
|
|
1
|
+
import { stringify, esm_default } from './chunk-MEGCYGBU.js';
|
|
2
|
+
import { validateBody } from './chunk-RSEO4XPX.js';
|
|
3
|
+
import { handleError } from './chunk-LF7P5PLR.js';
|
|
4
|
+
import { HTTPException } from './chunk-LCM566I4.js';
|
|
5
5
|
import { __export } from './chunk-MLKGABMK.js';
|
|
6
6
|
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
7
7
|
|
|
@@ -23,6 +23,8 @@ async function getAgentsHandler({ mastra, runtimeContext }) {
|
|
|
23
23
|
const instructions = await agent.getInstructions({ runtimeContext });
|
|
24
24
|
const tools = await agent.getTools({ runtimeContext });
|
|
25
25
|
const llm = await agent.getLLM({ runtimeContext });
|
|
26
|
+
const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext });
|
|
27
|
+
const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext });
|
|
26
28
|
const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
|
|
27
29
|
const _tool = tool;
|
|
28
30
|
acc[key] = {
|
|
@@ -32,13 +34,33 @@ async function getAgentsHandler({ mastra, runtimeContext }) {
|
|
|
32
34
|
};
|
|
33
35
|
return acc;
|
|
34
36
|
}, {});
|
|
37
|
+
let serializedAgentWorkflows = {};
|
|
38
|
+
if ("getWorkflows" in agent) {
|
|
39
|
+
const logger = mastra.getLogger();
|
|
40
|
+
try {
|
|
41
|
+
const workflows = await agent.getWorkflows({ runtimeContext });
|
|
42
|
+
serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
|
|
43
|
+
return {
|
|
44
|
+
...acc,
|
|
45
|
+
[key]: {
|
|
46
|
+
name: workflow.name
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}, {});
|
|
50
|
+
} catch (error) {
|
|
51
|
+
logger.error("Error getting workflows for agent", { agentName: agent.name, error });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
35
54
|
return {
|
|
36
55
|
id,
|
|
37
56
|
name: agent.name,
|
|
38
57
|
instructions,
|
|
39
58
|
tools: serializedAgentTools,
|
|
59
|
+
workflows: serializedAgentWorkflows,
|
|
40
60
|
provider: llm?.getProvider(),
|
|
41
|
-
modelId: llm?.getModelId()
|
|
61
|
+
modelId: llm?.getModelId(),
|
|
62
|
+
defaultGenerateOptions,
|
|
63
|
+
defaultStreamOptions
|
|
42
64
|
};
|
|
43
65
|
})
|
|
44
66
|
);
|
|
@@ -54,7 +76,8 @@ async function getAgentsHandler({ mastra, runtimeContext }) {
|
|
|
54
76
|
async function getAgentByIdHandler({
|
|
55
77
|
mastra,
|
|
56
78
|
runtimeContext,
|
|
57
|
-
agentId
|
|
79
|
+
agentId,
|
|
80
|
+
isPlayground = false
|
|
58
81
|
}) {
|
|
59
82
|
try {
|
|
60
83
|
const agent = mastra.getAgent(agentId);
|
|
@@ -71,14 +94,59 @@ async function getAgentByIdHandler({
|
|
|
71
94
|
};
|
|
72
95
|
return acc;
|
|
73
96
|
}, {});
|
|
74
|
-
|
|
97
|
+
let serializedAgentWorkflows = {};
|
|
98
|
+
if ("getWorkflows" in agent) {
|
|
99
|
+
const logger = mastra.getLogger();
|
|
100
|
+
try {
|
|
101
|
+
const workflows = await agent.getWorkflows({ runtimeContext });
|
|
102
|
+
serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
|
|
103
|
+
return {
|
|
104
|
+
...acc,
|
|
105
|
+
[key]: {
|
|
106
|
+
name: workflow.name,
|
|
107
|
+
steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
|
|
108
|
+
return {
|
|
109
|
+
...acc2,
|
|
110
|
+
[key2]: {
|
|
111
|
+
id: step.id,
|
|
112
|
+
description: step.description
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}, {})
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}, {});
|
|
119
|
+
} catch (error) {
|
|
120
|
+
logger.error("Error getting workflows for agent", { agentName: agent.name, error });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
let proxyRuntimeContext = runtimeContext;
|
|
124
|
+
if (isPlayground) {
|
|
125
|
+
proxyRuntimeContext = new Proxy(runtimeContext, {
|
|
126
|
+
get(target, prop) {
|
|
127
|
+
if (prop === "get") {
|
|
128
|
+
return function(key) {
|
|
129
|
+
const value = target.get(key);
|
|
130
|
+
return value ?? `<${key}>`;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return Reflect.get(target, prop);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
const instructions = await agent.getInstructions({ runtimeContext: proxyRuntimeContext });
|
|
75
138
|
const llm = await agent.getLLM({ runtimeContext });
|
|
139
|
+
const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext: proxyRuntimeContext });
|
|
140
|
+
const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext: proxyRuntimeContext });
|
|
76
141
|
return {
|
|
77
142
|
name: agent.name,
|
|
78
143
|
instructions,
|
|
79
144
|
tools: serializedAgentTools,
|
|
145
|
+
workflows: serializedAgentWorkflows,
|
|
80
146
|
provider: llm?.getProvider(),
|
|
81
|
-
modelId: llm?.getModelId()
|
|
147
|
+
modelId: llm?.getModelId(),
|
|
148
|
+
defaultGenerateOptions,
|
|
149
|
+
defaultStreamOptions
|
|
82
150
|
};
|
|
83
151
|
} catch (error) {
|
|
84
152
|
return handleError(error, "Error getting agent");
|
|
@@ -126,7 +194,8 @@ async function generateHandler({
|
|
|
126
194
|
mastra,
|
|
127
195
|
runtimeContext,
|
|
128
196
|
agentId,
|
|
129
|
-
body
|
|
197
|
+
body,
|
|
198
|
+
abortSignal
|
|
130
199
|
}) {
|
|
131
200
|
try {
|
|
132
201
|
const agent = mastra.getAgent(agentId);
|
|
@@ -144,7 +213,8 @@ async function generateHandler({
|
|
|
144
213
|
...rest,
|
|
145
214
|
// @ts-expect-error TODO fix types
|
|
146
215
|
resourceId: finalResourceId,
|
|
147
|
-
runtimeContext: finalRuntimeContext
|
|
216
|
+
runtimeContext: finalRuntimeContext,
|
|
217
|
+
signal: abortSignal
|
|
148
218
|
});
|
|
149
219
|
return result;
|
|
150
220
|
} catch (error) {
|
|
@@ -155,7 +225,8 @@ async function streamGenerateHandler({
|
|
|
155
225
|
mastra,
|
|
156
226
|
runtimeContext,
|
|
157
227
|
agentId,
|
|
158
|
-
body
|
|
228
|
+
body,
|
|
229
|
+
abortSignal
|
|
159
230
|
}) {
|
|
160
231
|
try {
|
|
161
232
|
const agent = mastra.getAgent(agentId);
|
|
@@ -173,18 +244,26 @@ async function streamGenerateHandler({
|
|
|
173
244
|
...rest,
|
|
174
245
|
// @ts-expect-error TODO fix types
|
|
175
246
|
resourceId: finalResourceId,
|
|
176
|
-
runtimeContext: finalRuntimeContext
|
|
247
|
+
runtimeContext: finalRuntimeContext,
|
|
248
|
+
signal: abortSignal
|
|
177
249
|
});
|
|
178
|
-
const streamResponse = rest.output ? streamResult.toTextStreamResponse(
|
|
250
|
+
const streamResponse = rest.output ? streamResult.toTextStreamResponse({
|
|
251
|
+
headers: {
|
|
252
|
+
"Transfer-Encoding": "chunked"
|
|
253
|
+
}
|
|
254
|
+
}) : streamResult.toDataStreamResponse({
|
|
179
255
|
sendUsage: true,
|
|
180
256
|
sendReasoning: true,
|
|
181
257
|
getErrorMessage: (error) => {
|
|
182
258
|
return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
|
|
259
|
+
},
|
|
260
|
+
headers: {
|
|
261
|
+
"Transfer-Encoding": "chunked"
|
|
183
262
|
}
|
|
184
263
|
});
|
|
185
264
|
return streamResponse;
|
|
186
265
|
} catch (error) {
|
|
187
|
-
|
|
266
|
+
return handleError(error, "error streaming agent response");
|
|
188
267
|
}
|
|
189
268
|
}
|
|
190
269
|
|