@mastra/server 0.0.0-switch-to-core-20250424015131 → 0.0.0-tool-call-parts-20250630193309
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -135
- package/dist/_tsup-dts-rollup.d.cts +541 -51
- package/dist/_tsup-dts-rollup.d.ts +541 -51
- package/dist/chunk-2BCWG3EZ.js +270 -0
- package/dist/{chunk-4JINXASC.js → chunk-55DOQLP6.js} +5 -4
- package/dist/{chunk-QN4KF3BH.cjs → chunk-57CJTIPW.cjs} +2 -2
- package/dist/{chunk-ZLBRQFDD.cjs → chunk-64U3UDTH.cjs} +2 -2
- package/dist/chunk-72LOJGUV.js +421 -0
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/{chunk-7IWQE76Z.cjs → chunk-B4MQFJ7G.cjs} +16 -10
- package/dist/{chunk-WTHDCRMY.js → chunk-BFOA2QQY.js} +12 -6
- package/dist/{chunk-M56ECCHK.cjs → chunk-BNEY4P4P.cjs} +20 -19
- package/dist/{chunk-RE6YL32K.js → chunk-C7564HUT.js} +52 -30
- package/dist/{chunk-LFOBHRFO.js → chunk-E2LP4J6K.js} +69 -54
- package/dist/chunk-EP3XVEVC.cjs +278 -0
- package/dist/{chunk-5JNVY6DU.js → chunk-EWLR2PNT.js} +7 -5
- package/dist/chunk-GHC4YV6R.js +504 -0
- package/dist/{chunk-L7XE5QTW.js → chunk-H5PTF3Y4.js} +1 -1
- package/dist/chunk-IMBY5XUG.cjs +86 -0
- package/dist/chunk-L3VURYKY.cjs +435 -0
- package/dist/chunk-LI436ITD.cjs +2042 -0
- package/dist/{chunk-3AHQ5RGN.js → chunk-M5ABIP7D.js} +1 -1
- package/dist/chunk-MEGCYGBU.js +2039 -0
- package/dist/chunk-MLKGABMK.js +7 -0
- package/dist/chunk-NGHSYB5B.cjs +332 -0
- package/dist/{chunk-TRDNDNGQ.js → chunk-NYN7KFXL.js} +1 -7
- package/dist/{chunk-FV45V6WC.cjs → chunk-OCWPVYNI.cjs} +0 -7
- package/dist/chunk-QLG2PFHE.js +81 -0
- package/dist/{chunk-Q6SHQECN.js → chunk-R5VGYBV6.js} +34 -10
- package/dist/{chunk-2FJURXCL.cjs → chunk-RQ2Z56EC.cjs} +93 -55
- package/dist/chunk-SDPGVWQJ.cjs +512 -0
- package/dist/{chunk-FPIWDH5Y.cjs → chunk-VPNDC2DI.cjs} +62 -40
- package/dist/chunk-WJY57THV.cjs +118 -0
- package/dist/{chunk-RBQASTUP.js → chunk-XUIJ7WRT.js} +63 -25
- package/dist/{chunk-D3G23FP3.cjs → chunk-Z3PTO2AK.cjs} +24 -22
- package/dist/server/handlers/a2a.cjs +30 -0
- package/dist/server/handlers/a2a.d.cts +6 -0
- package/dist/server/handlers/a2a.d.ts +6 -0
- package/dist/server/handlers/a2a.js +1 -0
- package/dist/server/handlers/agents.cjs +7 -7
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/error.cjs +2 -2
- package/dist/server/handlers/error.js +1 -1
- package/dist/server/handlers/legacyWorkflows.cjs +46 -0
- package/dist/server/handlers/legacyWorkflows.d.cts +10 -0
- package/dist/server/handlers/legacyWorkflows.d.ts +10 -0
- package/dist/server/handlers/legacyWorkflows.js +1 -0
- package/dist/server/handlers/logs.cjs +4 -4
- package/dist/server/handlers/logs.js +1 -1
- package/dist/server/handlers/memory.cjs +9 -9
- package/dist/server/handlers/memory.js +1 -1
- package/dist/server/handlers/network.cjs +5 -5
- package/dist/server/handlers/network.js +1 -1
- package/dist/server/handlers/telemetry.cjs +3 -3
- package/dist/server/handlers/telemetry.js +1 -1
- package/dist/server/handlers/tools.cjs +5 -5
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/utils.cjs +2 -2
- package/dist/server/handlers/utils.js +1 -1
- package/dist/server/handlers/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 +21 -13
- package/dist/server/handlers/workflows.d.cts +4 -2
- package/dist/server/handlers/workflows.d.ts +4 -2
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +33 -23
- package/dist/server/handlers.d.cts +2 -0
- package/dist/server/handlers.d.ts +2 -0
- package/dist/server/handlers.js +11 -9
- package/package.json +13 -12
- package/dist/chunk-3EJZQ6TQ.js +0 -49
- package/dist/chunk-55HTWX4C.cjs +0 -93
- package/dist/chunk-5SWCVTNL.cjs +0 -5579
- package/dist/chunk-HCOPJZ4A.cjs +0 -164
- package/dist/chunk-OMN3UI6X.js +0 -5576
- package/dist/chunk-R4J7XQYU.js +0 -156
- package/dist/chunk-SKBVVI24.cjs +0 -54
- package/dist/chunk-TZK63M5N.cjs +0 -317
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import { stringify, esm_default } from './chunk-MEGCYGBU.js';
|
|
2
|
+
import { handleError } from './chunk-M5ABIP7D.js';
|
|
3
|
+
import { HTTPException } from './chunk-NYN7KFXL.js';
|
|
4
|
+
import { __export } from './chunk-MLKGABMK.js';
|
|
5
|
+
import { ReadableStream } from 'stream/web';
|
|
6
|
+
|
|
7
|
+
// src/server/handlers/workflows.ts
|
|
8
|
+
var workflows_exports = {};
|
|
9
|
+
__export(workflows_exports, {
|
|
10
|
+
createWorkflowRunHandler: () => createWorkflowRunHandler,
|
|
11
|
+
getWorkflowByIdHandler: () => getWorkflowByIdHandler,
|
|
12
|
+
getWorkflowRunByIdHandler: () => getWorkflowRunByIdHandler,
|
|
13
|
+
getWorkflowRunExecutionResultHandler: () => getWorkflowRunExecutionResultHandler,
|
|
14
|
+
getWorkflowRunsHandler: () => getWorkflowRunsHandler,
|
|
15
|
+
getWorkflowsHandler: () => getWorkflowsHandler,
|
|
16
|
+
resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
|
|
17
|
+
resumeWorkflowHandler: () => resumeWorkflowHandler,
|
|
18
|
+
startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
|
|
19
|
+
startWorkflowRunHandler: () => startWorkflowRunHandler,
|
|
20
|
+
streamWorkflowHandler: () => streamWorkflowHandler,
|
|
21
|
+
watchWorkflowHandler: () => watchWorkflowHandler
|
|
22
|
+
});
|
|
23
|
+
async function getWorkflowsHandler({ mastra }) {
|
|
24
|
+
try {
|
|
25
|
+
const workflows = mastra.getWorkflows({ serialized: false });
|
|
26
|
+
const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
|
|
27
|
+
acc[key] = {
|
|
28
|
+
name: workflow.name,
|
|
29
|
+
description: workflow.description,
|
|
30
|
+
steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
|
|
31
|
+
acc2[key2] = {
|
|
32
|
+
id: step.id,
|
|
33
|
+
description: step.description,
|
|
34
|
+
inputSchema: step.inputSchema ? stringify(esm_default(step.inputSchema)) : void 0,
|
|
35
|
+
outputSchema: step.outputSchema ? stringify(esm_default(step.outputSchema)) : void 0,
|
|
36
|
+
resumeSchema: step.resumeSchema ? stringify(esm_default(step.resumeSchema)) : void 0,
|
|
37
|
+
suspendSchema: step.suspendSchema ? stringify(esm_default(step.suspendSchema)) : void 0
|
|
38
|
+
};
|
|
39
|
+
return acc2;
|
|
40
|
+
}, {}),
|
|
41
|
+
stepGraph: workflow.serializedStepGraph,
|
|
42
|
+
inputSchema: workflow.inputSchema ? stringify(esm_default(workflow.inputSchema)) : void 0,
|
|
43
|
+
outputSchema: workflow.outputSchema ? stringify(esm_default(workflow.outputSchema)) : void 0
|
|
44
|
+
};
|
|
45
|
+
return acc;
|
|
46
|
+
}, {});
|
|
47
|
+
return _workflows;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
throw new HTTPException(500, { message: error?.message || "Error getting workflows" });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function getWorkflowsFromSystem({ mastra, workflowId }) {
|
|
53
|
+
const logger = mastra.getLogger();
|
|
54
|
+
if (!workflowId) {
|
|
55
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
56
|
+
}
|
|
57
|
+
let workflow;
|
|
58
|
+
try {
|
|
59
|
+
workflow = mastra.getWorkflow(workflowId);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
logger.debug("Error getting workflow, searching agents for workflow", error);
|
|
62
|
+
}
|
|
63
|
+
if (!workflow) {
|
|
64
|
+
logger.debug("Workflow not found, searching agents for workflow", { workflowId });
|
|
65
|
+
const agents = mastra.getAgents();
|
|
66
|
+
if (Object.keys(agents || {}).length) {
|
|
67
|
+
for (const [_, agent] of Object.entries(agents)) {
|
|
68
|
+
try {
|
|
69
|
+
const workflows = await agent.getWorkflows();
|
|
70
|
+
if (workflows[workflowId]) {
|
|
71
|
+
workflow = workflows[workflowId];
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
break;
|
|
75
|
+
} catch (error) {
|
|
76
|
+
logger.debug("Error getting workflow from agent", error);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!workflow) {
|
|
82
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
83
|
+
}
|
|
84
|
+
return { workflow };
|
|
85
|
+
}
|
|
86
|
+
async function getWorkflowByIdHandler({ mastra, workflowId }) {
|
|
87
|
+
try {
|
|
88
|
+
if (!workflowId) {
|
|
89
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
90
|
+
}
|
|
91
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
92
|
+
if (!workflow) {
|
|
93
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
|
|
97
|
+
acc[key] = {
|
|
98
|
+
id: step.id,
|
|
99
|
+
description: step.description,
|
|
100
|
+
inputSchema: step.inputSchema ? stringify(esm_default(step.inputSchema)) : void 0,
|
|
101
|
+
outputSchema: step.outputSchema ? stringify(esm_default(step.outputSchema)) : void 0,
|
|
102
|
+
resumeSchema: step.resumeSchema ? stringify(esm_default(step.resumeSchema)) : void 0,
|
|
103
|
+
suspendSchema: step.suspendSchema ? stringify(esm_default(step.suspendSchema)) : void 0
|
|
104
|
+
};
|
|
105
|
+
return acc;
|
|
106
|
+
}, {}),
|
|
107
|
+
name: workflow.name,
|
|
108
|
+
description: workflow.description,
|
|
109
|
+
stepGraph: workflow.serializedStepGraph,
|
|
110
|
+
inputSchema: workflow.inputSchema ? stringify(esm_default(workflow.inputSchema)) : void 0,
|
|
111
|
+
outputSchema: workflow.outputSchema ? stringify(esm_default(workflow.outputSchema)) : void 0
|
|
112
|
+
};
|
|
113
|
+
} catch (error) {
|
|
114
|
+
throw new HTTPException(500, { message: error?.message || "Error getting workflow" });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function getWorkflowRunByIdHandler({
|
|
118
|
+
mastra,
|
|
119
|
+
workflowId,
|
|
120
|
+
runId
|
|
121
|
+
}) {
|
|
122
|
+
try {
|
|
123
|
+
if (!workflowId) {
|
|
124
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
125
|
+
}
|
|
126
|
+
if (!runId) {
|
|
127
|
+
throw new HTTPException(400, { message: "Run ID is required" });
|
|
128
|
+
}
|
|
129
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
130
|
+
if (!workflow) {
|
|
131
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
132
|
+
}
|
|
133
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
134
|
+
if (!run) {
|
|
135
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
136
|
+
}
|
|
137
|
+
return run;
|
|
138
|
+
} catch (error) {
|
|
139
|
+
throw new HTTPException(500, { message: error?.message || "Error getting workflow run" });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async function getWorkflowRunExecutionResultHandler({
|
|
143
|
+
mastra,
|
|
144
|
+
workflowId,
|
|
145
|
+
runId
|
|
146
|
+
}) {
|
|
147
|
+
try {
|
|
148
|
+
if (!workflowId) {
|
|
149
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
150
|
+
}
|
|
151
|
+
if (!runId) {
|
|
152
|
+
throw new HTTPException(400, { message: "Run ID is required" });
|
|
153
|
+
}
|
|
154
|
+
const workflow = mastra.getWorkflow(workflowId);
|
|
155
|
+
if (!workflow) {
|
|
156
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
157
|
+
}
|
|
158
|
+
const executionResult = await workflow.getWorkflowRunExecutionResult(runId);
|
|
159
|
+
if (!executionResult) {
|
|
160
|
+
throw new HTTPException(404, { message: "Workflow run execution result not found" });
|
|
161
|
+
}
|
|
162
|
+
return executionResult;
|
|
163
|
+
} catch (error) {
|
|
164
|
+
throw new HTTPException(500, {
|
|
165
|
+
message: error?.message || "Error getting workflow run execution result"
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async function createWorkflowRunHandler({
|
|
170
|
+
mastra,
|
|
171
|
+
workflowId,
|
|
172
|
+
runId: prevRunId
|
|
173
|
+
}) {
|
|
174
|
+
try {
|
|
175
|
+
if (!workflowId) {
|
|
176
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
177
|
+
}
|
|
178
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
179
|
+
if (!workflow) {
|
|
180
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
181
|
+
}
|
|
182
|
+
const run = await workflow.createRunAsync({ runId: prevRunId });
|
|
183
|
+
return { runId: run.runId };
|
|
184
|
+
} catch (error) {
|
|
185
|
+
throw new HTTPException(500, { message: error?.message || "Error creating workflow run" });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async function startAsyncWorkflowHandler({
|
|
189
|
+
mastra,
|
|
190
|
+
runtimeContext,
|
|
191
|
+
workflowId,
|
|
192
|
+
runId,
|
|
193
|
+
inputData
|
|
194
|
+
}) {
|
|
195
|
+
try {
|
|
196
|
+
if (!workflowId) {
|
|
197
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
198
|
+
}
|
|
199
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
200
|
+
if (!workflow) {
|
|
201
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
202
|
+
}
|
|
203
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
204
|
+
const result = await _run.start({
|
|
205
|
+
inputData,
|
|
206
|
+
runtimeContext
|
|
207
|
+
});
|
|
208
|
+
return result;
|
|
209
|
+
} catch (error) {
|
|
210
|
+
throw new HTTPException(500, { message: error?.message || "Error executing workflow" });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
async function startWorkflowRunHandler({
|
|
214
|
+
mastra,
|
|
215
|
+
runtimeContext,
|
|
216
|
+
workflowId,
|
|
217
|
+
runId,
|
|
218
|
+
inputData
|
|
219
|
+
}) {
|
|
220
|
+
try {
|
|
221
|
+
if (!workflowId) {
|
|
222
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
223
|
+
}
|
|
224
|
+
if (!runId) {
|
|
225
|
+
throw new HTTPException(400, { message: "runId required to start run" });
|
|
226
|
+
}
|
|
227
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
228
|
+
if (!workflow) {
|
|
229
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
230
|
+
}
|
|
231
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
232
|
+
if (!run) {
|
|
233
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
234
|
+
}
|
|
235
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
236
|
+
void _run.start({
|
|
237
|
+
inputData,
|
|
238
|
+
runtimeContext
|
|
239
|
+
});
|
|
240
|
+
return { message: "Workflow run started" };
|
|
241
|
+
} catch (e) {
|
|
242
|
+
return handleError(e, "Error starting workflow run");
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async function watchWorkflowHandler({
|
|
246
|
+
mastra,
|
|
247
|
+
workflowId,
|
|
248
|
+
runId
|
|
249
|
+
}) {
|
|
250
|
+
try {
|
|
251
|
+
if (!workflowId) {
|
|
252
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
253
|
+
}
|
|
254
|
+
if (!runId) {
|
|
255
|
+
throw new HTTPException(400, { message: "runId required to watch workflow" });
|
|
256
|
+
}
|
|
257
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
258
|
+
if (!workflow) {
|
|
259
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
260
|
+
}
|
|
261
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
262
|
+
if (!run) {
|
|
263
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
264
|
+
}
|
|
265
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
266
|
+
let unwatch;
|
|
267
|
+
let asyncRef = null;
|
|
268
|
+
const stream = new ReadableStream({
|
|
269
|
+
start(controller) {
|
|
270
|
+
unwatch = _run.watch(({ type, payload, eventTimestamp }) => {
|
|
271
|
+
controller.enqueue(JSON.stringify({ type, payload, eventTimestamp, runId }));
|
|
272
|
+
if (asyncRef) {
|
|
273
|
+
clearImmediate(asyncRef);
|
|
274
|
+
asyncRef = null;
|
|
275
|
+
}
|
|
276
|
+
asyncRef = setImmediate(async () => {
|
|
277
|
+
const runDone = payload.workflowState.status !== "running";
|
|
278
|
+
if (runDone) {
|
|
279
|
+
controller.close();
|
|
280
|
+
unwatch?.();
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
},
|
|
285
|
+
cancel() {
|
|
286
|
+
unwatch?.();
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
return stream;
|
|
290
|
+
} catch (error) {
|
|
291
|
+
return handleError(error, "Error watching workflow");
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
async function streamWorkflowHandler({
|
|
295
|
+
mastra,
|
|
296
|
+
runtimeContext,
|
|
297
|
+
workflowId,
|
|
298
|
+
runId,
|
|
299
|
+
inputData
|
|
300
|
+
}) {
|
|
301
|
+
try {
|
|
302
|
+
if (!workflowId) {
|
|
303
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
304
|
+
}
|
|
305
|
+
if (!runId) {
|
|
306
|
+
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
307
|
+
}
|
|
308
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
309
|
+
if (!workflow) {
|
|
310
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
311
|
+
}
|
|
312
|
+
const run = await workflow.createRunAsync({ runId });
|
|
313
|
+
const result = run.stream({
|
|
314
|
+
inputData,
|
|
315
|
+
runtimeContext
|
|
316
|
+
});
|
|
317
|
+
return result;
|
|
318
|
+
} catch (error) {
|
|
319
|
+
return handleError(error, "Error executing workflow");
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
async function resumeAsyncWorkflowHandler({
|
|
323
|
+
mastra,
|
|
324
|
+
workflowId,
|
|
325
|
+
runId,
|
|
326
|
+
body,
|
|
327
|
+
runtimeContext
|
|
328
|
+
}) {
|
|
329
|
+
try {
|
|
330
|
+
if (!workflowId) {
|
|
331
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
332
|
+
}
|
|
333
|
+
if (!runId) {
|
|
334
|
+
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
335
|
+
}
|
|
336
|
+
if (!body.step) {
|
|
337
|
+
throw new HTTPException(400, { message: "step required to resume workflow" });
|
|
338
|
+
}
|
|
339
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
340
|
+
if (!workflow) {
|
|
341
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
342
|
+
}
|
|
343
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
344
|
+
if (!run) {
|
|
345
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
346
|
+
}
|
|
347
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
348
|
+
const result = await _run.resume({
|
|
349
|
+
step: body.step,
|
|
350
|
+
resumeData: body.resumeData,
|
|
351
|
+
runtimeContext
|
|
352
|
+
});
|
|
353
|
+
return result;
|
|
354
|
+
} catch (error) {
|
|
355
|
+
return handleError(error, "Error resuming workflow step");
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
async function resumeWorkflowHandler({
|
|
359
|
+
mastra,
|
|
360
|
+
workflowId,
|
|
361
|
+
runId,
|
|
362
|
+
body,
|
|
363
|
+
runtimeContext
|
|
364
|
+
}) {
|
|
365
|
+
try {
|
|
366
|
+
if (!workflowId) {
|
|
367
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
368
|
+
}
|
|
369
|
+
if (!runId) {
|
|
370
|
+
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
371
|
+
}
|
|
372
|
+
if (!body.step) {
|
|
373
|
+
throw new HTTPException(400, { message: "step required to resume workflow" });
|
|
374
|
+
}
|
|
375
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
376
|
+
if (!workflow) {
|
|
377
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
378
|
+
}
|
|
379
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
380
|
+
if (!run) {
|
|
381
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
382
|
+
}
|
|
383
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
384
|
+
void _run.resume({
|
|
385
|
+
step: body.step,
|
|
386
|
+
resumeData: body.resumeData,
|
|
387
|
+
runtimeContext
|
|
388
|
+
});
|
|
389
|
+
return { message: "Workflow run resumed" };
|
|
390
|
+
} catch (error) {
|
|
391
|
+
return handleError(error, "Error resuming workflow");
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
async function getWorkflowRunsHandler({
|
|
395
|
+
mastra,
|
|
396
|
+
workflowId,
|
|
397
|
+
fromDate,
|
|
398
|
+
toDate,
|
|
399
|
+
limit,
|
|
400
|
+
offset,
|
|
401
|
+
resourceId
|
|
402
|
+
}) {
|
|
403
|
+
try {
|
|
404
|
+
if (!workflowId) {
|
|
405
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
406
|
+
}
|
|
407
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
408
|
+
if (!workflow) {
|
|
409
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
410
|
+
}
|
|
411
|
+
const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
|
|
412
|
+
runs: [],
|
|
413
|
+
total: 0
|
|
414
|
+
};
|
|
415
|
+
return workflowRuns;
|
|
416
|
+
} catch (error) {
|
|
417
|
+
return handleError(error, "Error getting workflow runs");
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export { createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunExecutionResultHandler, getWorkflowRunsHandler, getWorkflowsHandler, resumeAsyncWorkflowHandler, resumeWorkflowHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamWorkflowHandler, watchWorkflowHandler, workflows_exports };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
|
|
4
|
+
var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
|
|
5
|
+
var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
|
|
5
6
|
|
|
6
7
|
// src/server/handlers/telemetry.ts
|
|
7
8
|
var telemetry_exports = {};
|
|
8
|
-
|
|
9
|
+
chunk75ZPJI57_cjs.__export(telemetry_exports, {
|
|
9
10
|
getTelemetryHandler: () => getTelemetryHandler,
|
|
10
11
|
storeTelemetryHandler: () => storeTelemetryHandler
|
|
11
12
|
});
|
|
@@ -14,15 +15,15 @@ async function getTelemetryHandler({ mastra, body }) {
|
|
|
14
15
|
const telemetry = mastra.getTelemetry();
|
|
15
16
|
const storage = mastra.getStorage();
|
|
16
17
|
if (!telemetry) {
|
|
17
|
-
throw new
|
|
18
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Telemetry is not initialized" });
|
|
18
19
|
}
|
|
19
20
|
if (!storage) {
|
|
20
|
-
|
|
21
|
+
return [];
|
|
21
22
|
}
|
|
22
23
|
if (!body) {
|
|
23
|
-
throw new
|
|
24
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Body is required" });
|
|
24
25
|
}
|
|
25
|
-
const { name, scope, page, perPage, attribute } = body;
|
|
26
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = body;
|
|
26
27
|
const attributes = attribute ? Object.fromEntries(
|
|
27
28
|
(Array.isArray(attribute) ? attribute : [attribute]).map((attr) => {
|
|
28
29
|
const [key, value] = attr.split(":");
|
|
@@ -34,11 +35,13 @@ async function getTelemetryHandler({ mastra, body }) {
|
|
|
34
35
|
scope,
|
|
35
36
|
page: Number(page ?? 0),
|
|
36
37
|
perPage: Number(perPage ?? 100),
|
|
37
|
-
attributes
|
|
38
|
+
attributes,
|
|
39
|
+
fromDate: fromDate ? new Date(fromDate) : void 0,
|
|
40
|
+
toDate: toDate ? new Date(toDate) : void 0
|
|
38
41
|
});
|
|
39
42
|
return traces;
|
|
40
43
|
} catch (error2) {
|
|
41
|
-
return
|
|
44
|
+
return chunk64U3UDTH_cjs.handleError(error2, "Error getting telemetry");
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
47
|
async function storeTelemetryHandler({ mastra, body }) {
|
|
@@ -46,7 +49,10 @@ async function storeTelemetryHandler({ mastra, body }) {
|
|
|
46
49
|
const storage = mastra.getStorage();
|
|
47
50
|
const logger = mastra.getLogger();
|
|
48
51
|
if (!storage) {
|
|
49
|
-
|
|
52
|
+
return {
|
|
53
|
+
status: "error",
|
|
54
|
+
message: "Storage is not initialized"
|
|
55
|
+
};
|
|
50
56
|
}
|
|
51
57
|
const now = /* @__PURE__ */ new Date();
|
|
52
58
|
const items = body?.resourceSpans?.[0]?.scopeSpans;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { handleError } from './chunk-
|
|
2
|
-
import {
|
|
1
|
+
import { handleError } from './chunk-M5ABIP7D.js';
|
|
2
|
+
import { HTTPException } from './chunk-NYN7KFXL.js';
|
|
3
|
+
import { __export } from './chunk-MLKGABMK.js';
|
|
3
4
|
|
|
4
5
|
// src/server/handlers/telemetry.ts
|
|
5
6
|
var telemetry_exports = {};
|
|
@@ -15,12 +16,12 @@ async function getTelemetryHandler({ mastra, body }) {
|
|
|
15
16
|
throw new HTTPException(400, { message: "Telemetry is not initialized" });
|
|
16
17
|
}
|
|
17
18
|
if (!storage) {
|
|
18
|
-
|
|
19
|
+
return [];
|
|
19
20
|
}
|
|
20
21
|
if (!body) {
|
|
21
22
|
throw new HTTPException(400, { message: "Body is required" });
|
|
22
23
|
}
|
|
23
|
-
const { name, scope, page, perPage, attribute } = body;
|
|
24
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = body;
|
|
24
25
|
const attributes = attribute ? Object.fromEntries(
|
|
25
26
|
(Array.isArray(attribute) ? attribute : [attribute]).map((attr) => {
|
|
26
27
|
const [key, value] = attr.split(":");
|
|
@@ -32,7 +33,9 @@ async function getTelemetryHandler({ mastra, body }) {
|
|
|
32
33
|
scope,
|
|
33
34
|
page: Number(page ?? 0),
|
|
34
35
|
perPage: Number(perPage ?? 100),
|
|
35
|
-
attributes
|
|
36
|
+
attributes,
|
|
37
|
+
fromDate: fromDate ? new Date(fromDate) : void 0,
|
|
38
|
+
toDate: toDate ? new Date(toDate) : void 0
|
|
36
39
|
});
|
|
37
40
|
return traces;
|
|
38
41
|
} catch (error2) {
|
|
@@ -44,7 +47,10 @@ async function storeTelemetryHandler({ mastra, body }) {
|
|
|
44
47
|
const storage = mastra.getStorage();
|
|
45
48
|
const logger = mastra.getLogger();
|
|
46
49
|
if (!storage) {
|
|
47
|
-
|
|
50
|
+
return {
|
|
51
|
+
status: "error",
|
|
52
|
+
message: "Storage is not initialized"
|
|
53
|
+
};
|
|
48
54
|
}
|
|
49
55
|
const now = /* @__PURE__ */ new Date();
|
|
50
56
|
const items = body?.resourceSpans?.[0]?.scopeSpans;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
|
|
4
|
+
var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
|
|
5
|
+
var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
|
|
5
6
|
|
|
6
7
|
// src/server/handlers/vector.ts
|
|
7
8
|
var vector_exports = {};
|
|
8
|
-
|
|
9
|
+
chunk75ZPJI57_cjs.__export(vector_exports, {
|
|
9
10
|
createIndex: () => createIndex,
|
|
10
11
|
deleteIndex: () => deleteIndex,
|
|
11
12
|
describeIndex: () => describeIndex,
|
|
@@ -15,24 +16,24 @@ chunkFV45V6WC_cjs.__export(vector_exports, {
|
|
|
15
16
|
});
|
|
16
17
|
function getVector(mastra, vectorName) {
|
|
17
18
|
if (!vectorName) {
|
|
18
|
-
throw new
|
|
19
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Vector name is required" });
|
|
19
20
|
}
|
|
20
21
|
const vector = mastra.getVector(vectorName);
|
|
21
22
|
if (!vector) {
|
|
22
|
-
throw new
|
|
23
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: `Vector store ${vectorName} not found` });
|
|
23
24
|
}
|
|
24
25
|
return vector;
|
|
25
26
|
}
|
|
26
27
|
async function upsertVectors({ mastra, vectorName, index }) {
|
|
27
28
|
try {
|
|
28
29
|
if (!index?.indexName || !index?.vectors || !Array.isArray(index.vectors)) {
|
|
29
|
-
throw new
|
|
30
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Invalid request index. indexName and vectors array are required." });
|
|
30
31
|
}
|
|
31
32
|
const vector = getVector(mastra, vectorName);
|
|
32
33
|
const result = await vector.upsert(index);
|
|
33
34
|
return { ids: result };
|
|
34
35
|
} catch (error) {
|
|
35
|
-
return
|
|
36
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error upserting vectors");
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
async function createIndex({
|
|
@@ -43,18 +44,18 @@ async function createIndex({
|
|
|
43
44
|
try {
|
|
44
45
|
const { indexName, dimension, metric } = index;
|
|
45
46
|
if (!indexName || typeof dimension !== "number" || dimension <= 0) {
|
|
46
|
-
throw new
|
|
47
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, {
|
|
47
48
|
message: "Invalid request index, indexName and positive dimension number are required."
|
|
48
49
|
});
|
|
49
50
|
}
|
|
50
51
|
if (metric && !["cosine", "euclidean", "dotproduct"].includes(metric)) {
|
|
51
|
-
throw new
|
|
52
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Invalid metric. Must be one of: cosine, euclidean, dotproduct" });
|
|
52
53
|
}
|
|
53
54
|
const vector = getVector(mastra, vectorName);
|
|
54
55
|
await vector.createIndex({ indexName, dimension, metric });
|
|
55
56
|
return { success: true };
|
|
56
57
|
} catch (error) {
|
|
57
|
-
return
|
|
58
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error creating index");
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
async function queryVectors({
|
|
@@ -64,13 +65,13 @@ async function queryVectors({
|
|
|
64
65
|
}) {
|
|
65
66
|
try {
|
|
66
67
|
if (!query?.indexName || !query?.queryVector || !Array.isArray(query.queryVector)) {
|
|
67
|
-
throw new
|
|
68
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Invalid request query. indexName and queryVector array are required." });
|
|
68
69
|
}
|
|
69
70
|
const vector = getVector(mastra, vectorName);
|
|
70
71
|
const results = await vector.query(query);
|
|
71
72
|
return results;
|
|
72
73
|
} catch (error) {
|
|
73
|
-
return
|
|
74
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error querying vectors");
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
async function listIndexes({ mastra, vectorName }) {
|
|
@@ -79,7 +80,7 @@ async function listIndexes({ mastra, vectorName }) {
|
|
|
79
80
|
const indexes = await vector.listIndexes();
|
|
80
81
|
return indexes.filter(Boolean);
|
|
81
82
|
} catch (error) {
|
|
82
|
-
return
|
|
83
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error listing indexes");
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
async function describeIndex({
|
|
@@ -89,17 +90,17 @@ async function describeIndex({
|
|
|
89
90
|
}) {
|
|
90
91
|
try {
|
|
91
92
|
if (!indexName) {
|
|
92
|
-
throw new
|
|
93
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Index name is required" });
|
|
93
94
|
}
|
|
94
95
|
const vector = getVector(mastra, vectorName);
|
|
95
|
-
const stats = await vector.describeIndex(indexName);
|
|
96
|
+
const stats = await vector.describeIndex({ indexName });
|
|
96
97
|
return {
|
|
97
98
|
dimension: stats.dimension,
|
|
98
99
|
count: stats.count,
|
|
99
100
|
metric: stats.metric?.toLowerCase()
|
|
100
101
|
};
|
|
101
102
|
} catch (error) {
|
|
102
|
-
return
|
|
103
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error describing index");
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
async function deleteIndex({
|
|
@@ -109,13 +110,13 @@ async function deleteIndex({
|
|
|
109
110
|
}) {
|
|
110
111
|
try {
|
|
111
112
|
if (!indexName) {
|
|
112
|
-
throw new
|
|
113
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Index name is required" });
|
|
113
114
|
}
|
|
114
115
|
const vector = getVector(mastra, vectorName);
|
|
115
|
-
await vector.deleteIndex(indexName);
|
|
116
|
+
await vector.deleteIndex({ indexName });
|
|
116
117
|
return { success: true };
|
|
117
118
|
} catch (error) {
|
|
118
|
-
return
|
|
119
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error deleting index");
|
|
119
120
|
}
|
|
120
121
|
}
|
|
121
122
|
|