@mastra/server 1.0.0-beta.4 → 1.0.0-beta.5
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/CHANGELOG.md +19 -0
- package/dist/chunk-2NW6POYK.cjs +89 -0
- package/dist/chunk-2NW6POYK.cjs.map +1 -0
- package/dist/chunk-4JMHKKV3.cjs +201 -0
- package/dist/chunk-4JMHKKV3.cjs.map +1 -0
- package/dist/chunk-4O2QGUW3.js +354 -0
- package/dist/chunk-4O2QGUW3.js.map +1 -0
- package/dist/chunk-4W2SM6CG.js +294 -0
- package/dist/chunk-4W2SM6CG.js.map +1 -0
- package/dist/chunk-5W4RPVTK.cjs +49 -0
- package/dist/chunk-5W4RPVTK.cjs.map +1 -0
- package/dist/chunk-65Q7HO3Q.cjs +907 -0
- package/dist/chunk-65Q7HO3Q.cjs.map +1 -0
- package/dist/chunk-6KNI7VIX.js +1021 -0
- package/dist/chunk-6KNI7VIX.js.map +1 -0
- package/dist/chunk-A6MQQTHN.js +310 -0
- package/dist/chunk-A6MQQTHN.js.map +1 -0
- package/dist/chunk-AUQBEMDP.cjs +322 -0
- package/dist/chunk-AUQBEMDP.cjs.map +1 -0
- package/dist/chunk-CBDUTSTI.js +192 -0
- package/dist/chunk-CBDUTSTI.js.map +1 -0
- package/dist/{chunk-VEVU6EUO.js → chunk-EI2GXZE2.js} +735 -154
- package/dist/chunk-EI2GXZE2.js.map +1 -0
- package/dist/{chunk-TOCYBDP2.js → chunk-ER3QM7DD.js} +4 -4
- package/dist/{chunk-TOCYBDP2.js.map → chunk-ER3QM7DD.js.map} +1 -1
- package/dist/chunk-FCHN5M25.js +878 -0
- package/dist/chunk-FCHN5M25.js.map +1 -0
- package/dist/chunk-FPCGLPLJ.cjs +297 -0
- package/dist/chunk-FPCGLPLJ.cjs.map +1 -0
- package/dist/{chunk-D7T74TVR.js → chunk-G7BPNX2V.js} +4 -3
- package/dist/chunk-G7BPNX2V.js.map +1 -0
- package/dist/chunk-IMK7366C.cjs +346 -0
- package/dist/chunk-IMK7366C.cjs.map +1 -0
- package/dist/chunk-LGG3N3AV.js +116 -0
- package/dist/chunk-LGG3N3AV.js.map +1 -0
- package/dist/chunk-LZDCXQMX.js +164 -0
- package/dist/chunk-LZDCXQMX.js.map +1 -0
- package/dist/chunk-MH3A7RDQ.cjs +1064 -0
- package/dist/chunk-MH3A7RDQ.cjs.map +1 -0
- package/dist/chunk-MWQQRVQC.cjs +259 -0
- package/dist/chunk-MWQQRVQC.cjs.map +1 -0
- package/dist/{chunk-7HVY3D64.cjs → chunk-P6BEEW5J.cjs} +1767 -1183
- package/dist/chunk-P6BEEW5J.cjs.map +1 -0
- package/dist/{chunk-KJIDZQRA.cjs → chunk-PDVJ2TTM.cjs} +216 -23
- package/dist/chunk-PDVJ2TTM.cjs.map +1 -0
- package/dist/chunk-PKRHEXX7.js +74 -0
- package/dist/chunk-PKRHEXX7.js.map +1 -0
- package/dist/chunk-QVHQZUGJ.cjs +368 -0
- package/dist/chunk-QVHQZUGJ.cjs.map +1 -0
- package/dist/chunk-R4M3BSUG.js +226 -0
- package/dist/chunk-R4M3BSUG.js.map +1 -0
- package/dist/chunk-R6ZTXNN2.cjs +797 -0
- package/dist/chunk-R6ZTXNN2.cjs.map +1 -0
- package/dist/{chunk-FPBYKMIS.js → chunk-RCCWKKI3.js} +210 -23
- package/dist/chunk-RCCWKKI3.js.map +1 -0
- package/dist/chunk-S6DFGBDD.cjs +211 -0
- package/dist/chunk-S6DFGBDD.cjs.map +1 -0
- package/dist/chunk-SAQSK4AG.cjs +167 -0
- package/dist/chunk-SAQSK4AG.cjs.map +1 -0
- package/dist/chunk-UCRV7PD3.js +773 -0
- package/dist/chunk-UCRV7PD3.js.map +1 -0
- package/dist/{chunk-W2KMU354.cjs → chunk-UZ6CYAOG.cjs} +4 -3
- package/dist/chunk-UZ6CYAOG.cjs.map +1 -0
- package/dist/{chunk-QU6N55W6.cjs → chunk-V272B7RM.cjs} +11 -12
- package/dist/chunk-V272B7RM.cjs.map +1 -0
- package/dist/{chunk-X6C7BUWN.cjs → chunk-XQPJ63ZD.cjs} +4 -4
- package/dist/{chunk-X6C7BUWN.cjs.map → chunk-XQPJ63ZD.cjs.map} +1 -1
- package/dist/chunk-XWGAT2DA.js +44 -0
- package/dist/chunk-XWGAT2DA.js.map +1 -0
- package/dist/chunk-YLQHE2S5.js +204 -0
- package/dist/chunk-YLQHE2S5.js.map +1 -0
- package/dist/{chunk-SHWNNZBL.js → chunk-YP34EWWK.js} +9 -10
- package/dist/chunk-YP34EWWK.js.map +1 -0
- package/dist/chunk-Z7R7CFVF.cjs +125 -0
- package/dist/chunk-Z7R7CFVF.cjs.map +1 -0
- package/dist/chunk-ZPZSAJAR.js +328 -0
- package/dist/chunk-ZPZSAJAR.js.map +1 -0
- package/dist/server/handlers/a2a.cjs +15 -7
- package/dist/server/handlers/a2a.d.ts +482 -0
- package/dist/server/handlers/a2a.d.ts.map +1 -1
- package/dist/server/handlers/a2a.js +1 -1
- package/dist/server/handlers/agent-builder.cjs +37 -37
- package/dist/server/handlers/agent-builder.d.ts +600 -77
- package/dist/server/handlers/agent-builder.d.ts.map +1 -1
- package/dist/server/handlers/agent-builder.js +1 -1
- package/dist/server/handlers/agents.cjs +53 -37
- package/dist/server/handlers/agents.d.ts +3271 -125
- package/dist/server/handlers/agents.d.ts.map +1 -1
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/logs.cjs +7 -7
- package/dist/server/handlers/logs.d.ts +135 -27
- package/dist/server/handlers/logs.d.ts.map +1 -1
- package/dist/server/handlers/logs.js +1 -1
- package/dist/server/handlers/memory.cjs +65 -29
- package/dist/server/handlers/memory.d.ts +932 -96
- package/dist/server/handlers/memory.d.ts.map +1 -1
- package/dist/server/handlers/memory.js +1 -1
- package/dist/server/handlers/observability.cjs +21 -5
- package/dist/server/handlers/observability.d.ts +119 -12
- package/dist/server/handlers/observability.d.ts.map +1 -1
- package/dist/server/handlers/observability.js +1 -1
- package/dist/server/handlers/scores.cjs +13 -13
- package/dist/server/handlers/scores.d.ts +110 -141
- package/dist/server/handlers/scores.d.ts.map +1 -1
- package/dist/server/handlers/scores.js +1 -1
- package/dist/server/handlers/test-utils.cjs +15 -0
- package/dist/server/handlers/test-utils.cjs.map +1 -0
- package/dist/server/handlers/test-utils.d.ts +6 -0
- package/dist/server/handlers/test-utils.d.ts.map +1 -0
- package/dist/server/handlers/test-utils.js +13 -0
- package/dist/server/handlers/test-utils.js.map +1 -0
- package/dist/server/handlers/tools.cjs +11 -11
- package/dist/server/handlers/tools.d.ts +69 -23
- package/dist/server/handlers/tools.d.ts.map +1 -1
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/utils.cjs +11 -3
- package/dist/server/handlers/utils.d.ts +5 -0
- package/dist/server/handlers/utils.d.ts.map +1 -1
- package/dist/server/handlers/utils.js +1 -1
- package/dist/server/handlers/vector.cjs +31 -7
- package/dist/server/handlers/vector.d.ts +93 -9
- package/dist/server/handlers/vector.d.ts.map +1 -1
- package/dist/server/handlers/vector.js +1 -1
- package/dist/server/handlers/voice.cjs +21 -9
- package/dist/server/handlers/voice.d.ts +81 -40
- package/dist/server/handlers/voice.d.ts.map +1 -1
- package/dist/server/handlers/voice.js +1 -1
- package/dist/server/handlers/workflows.cjs +65 -37
- package/dist/server/handlers/workflows.d.ts +919 -79
- package/dist/server/handlers/workflows.d.ts.map +1 -1
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +22 -22
- package/dist/server/handlers.js +11 -11
- package/dist/server/schemas/a2a.d.ts +786 -0
- package/dist/server/schemas/a2a.d.ts.map +1 -0
- package/dist/server/schemas/agent-builder.d.ts +195 -0
- package/dist/server/schemas/agent-builder.d.ts.map +1 -0
- package/dist/server/schemas/agents.d.ts +1375 -0
- package/dist/server/schemas/agents.d.ts.map +1 -0
- package/dist/server/schemas/common.d.ts +165 -0
- package/dist/server/schemas/common.d.ts.map +1 -0
- package/dist/server/schemas/logs.d.ts +124 -0
- package/dist/server/schemas/logs.d.ts.map +1 -0
- package/dist/server/schemas/memory.d.ts +998 -0
- package/dist/server/schemas/memory.d.ts.map +1 -0
- package/dist/server/schemas/observability.d.ts +402 -0
- package/dist/server/schemas/observability.d.ts.map +1 -0
- package/dist/server/schemas/scores.d.ts +259 -0
- package/dist/server/schemas/scores.d.ts.map +1 -0
- package/dist/server/schemas/vectors.d.ts +107 -0
- package/dist/server/schemas/vectors.d.ts.map +1 -0
- package/dist/server/schemas/workflows.d.ts +608 -0
- package/dist/server/schemas/workflows.d.ts.map +1 -0
- package/dist/server/server-adapter/index.cjs +330 -0
- package/dist/server/server-adapter/index.cjs.map +1 -0
- package/dist/server/server-adapter/index.d.ts +52 -0
- package/dist/server/server-adapter/index.d.ts.map +1 -0
- package/dist/server/server-adapter/index.js +316 -0
- package/dist/server/server-adapter/index.js.map +1 -0
- package/dist/server/server-adapter/openapi-utils.d.ts +59 -0
- package/dist/server/server-adapter/openapi-utils.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/a2a.d.ts +3 -0
- package/dist/server/server-adapter/routes/a2a.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/agent-builder.d.ts +3 -0
- package/dist/server/server-adapter/routes/agent-builder.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/agents.d.ts +3 -0
- package/dist/server/server-adapter/routes/agents.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/index.d.ts +41 -0
- package/dist/server/server-adapter/routes/index.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/legacy.d.ts +7 -0
- package/dist/server/server-adapter/routes/legacy.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/logs.d.ts +3 -0
- package/dist/server/server-adapter/routes/logs.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/memory.d.ts +3 -0
- package/dist/server/server-adapter/routes/memory.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/observability.d.ts +3 -0
- package/dist/server/server-adapter/routes/observability.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/route-builder.d.ts +52 -0
- package/dist/server/server-adapter/routes/route-builder.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/scorers.d.ts +3 -0
- package/dist/server/server-adapter/routes/scorers.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/stream-types.d.ts +10 -0
- package/dist/server/server-adapter/routes/stream-types.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/tools.d.ts +3 -0
- package/dist/server/server-adapter/routes/tools.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/vectors.d.ts +3 -0
- package/dist/server/server-adapter/routes/vectors.d.ts.map +1 -0
- package/dist/server/server-adapter/routes/workflows.d.ts +3 -0
- package/dist/server/server-adapter/routes/workflows.d.ts.map +1 -0
- package/dist/server/utils.d.ts.map +1 -1
- package/dist/token-GVZ7HRD7.js +62 -0
- package/dist/{token-C3IMNCC4.js.map → token-GVZ7HRD7.js.map} +1 -1
- package/dist/{token-C3IMNCC4.js → token-JGA3ZWAN.js} +5 -6
- package/dist/token-JGA3ZWAN.js.map +1 -0
- package/dist/token-VFONFWVS.cjs +64 -0
- package/dist/{token-375W3LEI.cjs.map → token-VFONFWVS.cjs.map} +1 -1
- package/dist/{token-375W3LEI.cjs → token-ZOD6YIQ3.cjs} +7 -8
- package/dist/token-ZOD6YIQ3.cjs.map +1 -0
- package/dist/token-util-7R2ZFIXO.js +7 -0
- package/dist/{token-util-E5QO2RCL.js.map → token-util-7R2ZFIXO.js.map} +1 -1
- package/dist/token-util-BLJZJDBZ.cjs +9 -0
- package/dist/{token-util-CV3RRG6K.cjs.map → token-util-BLJZJDBZ.cjs.map} +1 -1
- package/dist/token-util-VGZUWSNR.cjs +9 -0
- package/dist/token-util-VGZUWSNR.cjs.map +1 -0
- package/dist/token-util-VKTPZLSE.js +7 -0
- package/dist/token-util-VKTPZLSE.js.map +1 -0
- package/package.json +20 -7
- package/dist/chunk-2YZH5PH6.cjs +0 -200
- package/dist/chunk-2YZH5PH6.cjs.map +0 -1
- package/dist/chunk-3AMNUUZF.js +0 -124
- package/dist/chunk-3AMNUUZF.js.map +0 -1
- package/dist/chunk-3F52QCI4.js +0 -192
- package/dist/chunk-3F52QCI4.js.map +0 -1
- package/dist/chunk-4G5QBFEW.cjs +0 -681
- package/dist/chunk-4G5QBFEW.cjs.map +0 -1
- package/dist/chunk-73PAWDM5.js +0 -83
- package/dist/chunk-73PAWDM5.js.map +0 -1
- package/dist/chunk-7HVY3D64.cjs.map +0 -1
- package/dist/chunk-A24TSVEZ.cjs +0 -130
- package/dist/chunk-A24TSVEZ.cjs.map +0 -1
- package/dist/chunk-B3Z6J745.js +0 -122
- package/dist/chunk-B3Z6J745.js.map +0 -1
- package/dist/chunk-BTWIR2B7.cjs +0 -28
- package/dist/chunk-BTWIR2B7.cjs.map +0 -1
- package/dist/chunk-D7T74TVR.js.map +0 -1
- package/dist/chunk-FPBYKMIS.js.map +0 -1
- package/dist/chunk-GLAZTMX3.cjs +0 -128
- package/dist/chunk-GLAZTMX3.cjs.map +0 -1
- package/dist/chunk-KF3RI45U.cjs +0 -172
- package/dist/chunk-KF3RI45U.cjs.map +0 -1
- package/dist/chunk-KJIDZQRA.cjs.map +0 -1
- package/dist/chunk-KWH5QBXP.js +0 -123
- package/dist/chunk-KWH5QBXP.js.map +0 -1
- package/dist/chunk-ND5OKOMT.js +0 -165
- package/dist/chunk-ND5OKOMT.js.map +0 -1
- package/dist/chunk-PPMIB3FQ.cjs +0 -88
- package/dist/chunk-PPMIB3FQ.cjs.map +0 -1
- package/dist/chunk-QU6N55W6.cjs.map +0 -1
- package/dist/chunk-S54HNARD.cjs +0 -131
- package/dist/chunk-S54HNARD.cjs.map +0 -1
- package/dist/chunk-SHWNNZBL.js.map +0 -1
- package/dist/chunk-SZIFSF4T.js +0 -25
- package/dist/chunk-SZIFSF4T.js.map +0 -1
- package/dist/chunk-U7GLIXYO.cjs +0 -534
- package/dist/chunk-U7GLIXYO.cjs.map +0 -1
- package/dist/chunk-UGXW2KPL.js +0 -661
- package/dist/chunk-UGXW2KPL.js.map +0 -1
- package/dist/chunk-V6JYJS7O.js +0 -518
- package/dist/chunk-V6JYJS7O.js.map +0 -1
- package/dist/chunk-VEVU6EUO.js.map +0 -1
- package/dist/chunk-W2KMU354.cjs.map +0 -1
- package/dist/chunk-X3MICMI2.cjs +0 -620
- package/dist/chunk-X3MICMI2.cjs.map +0 -1
- package/dist/chunk-ZJ6KEY6H.js +0 -600
- package/dist/chunk-ZJ6KEY6H.js.map +0 -1
- package/dist/token-util-CV3RRG6K.cjs +0 -9
- package/dist/token-util-E5QO2RCL.js +0 -7
|
@@ -0,0 +1,1021 @@
|
|
|
1
|
+
import { getWorkflowInfo, WorkflowRegistry } from './chunk-G7BPNX2V.js';
|
|
2
|
+
import { streamResponseSchema } from './chunk-R4M3BSUG.js';
|
|
3
|
+
import { createOffsetPaginationSchema, tracingOptionsSchema, optionalRunIdSchema, runIdSchema, messageResponseSchema } from './chunk-PKRHEXX7.js';
|
|
4
|
+
import { createRoute } from './chunk-LZDCXQMX.js';
|
|
5
|
+
import { handleError } from './chunk-UXGQZUYZ.js';
|
|
6
|
+
import { HTTPException } from './chunk-6QWQZI4Q.js';
|
|
7
|
+
import { __export } from './chunk-PR4QN5HX.js';
|
|
8
|
+
import { TransformStream, ReadableStream } from 'stream/web';
|
|
9
|
+
import z from 'zod';
|
|
10
|
+
|
|
11
|
+
// src/server/handlers/workflows.ts
|
|
12
|
+
var workflows_exports = {};
|
|
13
|
+
__export(workflows_exports, {
|
|
14
|
+
CANCEL_WORKFLOW_RUN_ROUTE: () => CANCEL_WORKFLOW_RUN_ROUTE,
|
|
15
|
+
CREATE_WORKFLOW_RUN_ROUTE: () => CREATE_WORKFLOW_RUN_ROUTE,
|
|
16
|
+
GET_WORKFLOW_BY_ID_ROUTE: () => GET_WORKFLOW_BY_ID_ROUTE,
|
|
17
|
+
GET_WORKFLOW_RUN_BY_ID_ROUTE: () => GET_WORKFLOW_RUN_BY_ID_ROUTE,
|
|
18
|
+
GET_WORKFLOW_RUN_EXECUTION_RESULT_ROUTE: () => GET_WORKFLOW_RUN_EXECUTION_RESULT_ROUTE,
|
|
19
|
+
LIST_WORKFLOWS_ROUTE: () => LIST_WORKFLOWS_ROUTE,
|
|
20
|
+
LIST_WORKFLOW_RUNS_ROUTE: () => LIST_WORKFLOW_RUNS_ROUTE,
|
|
21
|
+
OBSERVE_STREAM_LEGACY_WORKFLOW_ROUTE: () => OBSERVE_STREAM_LEGACY_WORKFLOW_ROUTE,
|
|
22
|
+
OBSERVE_STREAM_VNEXT_WORKFLOW_ROUTE: () => OBSERVE_STREAM_VNEXT_WORKFLOW_ROUTE,
|
|
23
|
+
OBSERVE_STREAM_WORKFLOW_ROUTE: () => OBSERVE_STREAM_WORKFLOW_ROUTE,
|
|
24
|
+
RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ASYNC_ROUTE: () => RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ASYNC_ROUTE,
|
|
25
|
+
RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ROUTE: () => RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ROUTE,
|
|
26
|
+
RESTART_ASYNC_WORKFLOW_ROUTE: () => RESTART_ASYNC_WORKFLOW_ROUTE,
|
|
27
|
+
RESTART_WORKFLOW_ROUTE: () => RESTART_WORKFLOW_ROUTE,
|
|
28
|
+
RESUME_ASYNC_WORKFLOW_ROUTE: () => RESUME_ASYNC_WORKFLOW_ROUTE,
|
|
29
|
+
RESUME_STREAM_WORKFLOW_ROUTE: () => RESUME_STREAM_WORKFLOW_ROUTE,
|
|
30
|
+
RESUME_WORKFLOW_ROUTE: () => RESUME_WORKFLOW_ROUTE,
|
|
31
|
+
START_ASYNC_WORKFLOW_ROUTE: () => START_ASYNC_WORKFLOW_ROUTE,
|
|
32
|
+
START_WORKFLOW_RUN_ROUTE: () => START_WORKFLOW_RUN_ROUTE,
|
|
33
|
+
STREAM_LEGACY_WORKFLOW_ROUTE: () => STREAM_LEGACY_WORKFLOW_ROUTE,
|
|
34
|
+
STREAM_VNEXT_WORKFLOW_ROUTE: () => STREAM_VNEXT_WORKFLOW_ROUTE,
|
|
35
|
+
STREAM_WORKFLOW_ROUTE: () => STREAM_WORKFLOW_ROUTE,
|
|
36
|
+
TIME_TRAVEL_ASYNC_WORKFLOW_ROUTE: () => TIME_TRAVEL_ASYNC_WORKFLOW_ROUTE,
|
|
37
|
+
TIME_TRAVEL_STREAM_WORKFLOW_ROUTE: () => TIME_TRAVEL_STREAM_WORKFLOW_ROUTE,
|
|
38
|
+
TIME_TRAVEL_WORKFLOW_ROUTE: () => TIME_TRAVEL_WORKFLOW_ROUTE
|
|
39
|
+
});
|
|
40
|
+
var workflowRunStatusSchema = z.enum([
|
|
41
|
+
"running",
|
|
42
|
+
"waiting",
|
|
43
|
+
"suspended",
|
|
44
|
+
"success",
|
|
45
|
+
"failed",
|
|
46
|
+
"canceled",
|
|
47
|
+
"pending",
|
|
48
|
+
"bailed"
|
|
49
|
+
]);
|
|
50
|
+
var workflowIdPathParams = z.object({
|
|
51
|
+
workflowId: z.string().describe("Unique identifier for the workflow")
|
|
52
|
+
});
|
|
53
|
+
var workflowRunPathParams = workflowIdPathParams.extend({
|
|
54
|
+
runId: z.string().describe("Unique identifier for the workflow run")
|
|
55
|
+
});
|
|
56
|
+
var serializedStepSchema = z.object({
|
|
57
|
+
id: z.string(),
|
|
58
|
+
description: z.string().optional()
|
|
59
|
+
});
|
|
60
|
+
var serializedStepFlowEntrySchema = z.object({
|
|
61
|
+
type: z.enum(["step", "sleep", "sleepUntil", "waitForEvent", "parallel", "conditional", "loop", "foreach"])
|
|
62
|
+
});
|
|
63
|
+
var workflowInfoSchema = z.object({
|
|
64
|
+
steps: z.record(z.string(), serializedStepSchema),
|
|
65
|
+
allSteps: z.record(z.string(), serializedStepSchema),
|
|
66
|
+
name: z.string().optional(),
|
|
67
|
+
description: z.string().optional(),
|
|
68
|
+
stepGraph: z.array(serializedStepFlowEntrySchema),
|
|
69
|
+
inputSchema: z.string().optional(),
|
|
70
|
+
outputSchema: z.string().optional(),
|
|
71
|
+
options: z.object({}).optional()
|
|
72
|
+
});
|
|
73
|
+
var listWorkflowsResponseSchema = z.record(z.string(), workflowInfoSchema);
|
|
74
|
+
var workflowRunSchema = z.object({
|
|
75
|
+
workflowName: z.string(),
|
|
76
|
+
runId: z.string(),
|
|
77
|
+
snapshot: z.union([z.object({}), z.string()]),
|
|
78
|
+
createdAt: z.date(),
|
|
79
|
+
updatedAt: z.date(),
|
|
80
|
+
resourceId: z.string().optional()
|
|
81
|
+
});
|
|
82
|
+
var workflowRunsResponseSchema = z.object({
|
|
83
|
+
runs: z.array(workflowRunSchema),
|
|
84
|
+
total: z.number()
|
|
85
|
+
});
|
|
86
|
+
var workflowRunResponseSchema = workflowRunSchema;
|
|
87
|
+
var listWorkflowRunsQuerySchema = createOffsetPaginationSchema().extend({
|
|
88
|
+
fromDate: z.coerce.date().optional(),
|
|
89
|
+
toDate: z.coerce.date().optional(),
|
|
90
|
+
resourceId: z.string().optional(),
|
|
91
|
+
status: workflowRunStatusSchema.optional()
|
|
92
|
+
});
|
|
93
|
+
var workflowExecutionBodySchema = z.object({
|
|
94
|
+
inputData: z.unknown().optional(),
|
|
95
|
+
requestContext: z.record(z.string(), z.unknown()).optional(),
|
|
96
|
+
tracingOptions: tracingOptionsSchema.optional()
|
|
97
|
+
});
|
|
98
|
+
var streamLegacyWorkflowBodySchema = workflowExecutionBodySchema;
|
|
99
|
+
var streamWorkflowBodySchema = workflowExecutionBodySchema.extend({
|
|
100
|
+
closeOnSuspend: z.boolean().optional()
|
|
101
|
+
});
|
|
102
|
+
var resumeBodySchema = z.object({
|
|
103
|
+
step: z.union([z.string(), z.array(z.string())]).optional(),
|
|
104
|
+
// Optional - workflow can auto-resume all suspended steps
|
|
105
|
+
resumeData: z.unknown().optional(),
|
|
106
|
+
requestContext: z.record(z.string(), z.unknown()).optional(),
|
|
107
|
+
tracingOptions: tracingOptionsSchema.optional()
|
|
108
|
+
});
|
|
109
|
+
var restartBodySchema = z.object({
|
|
110
|
+
requestContext: z.record(z.string(), z.unknown()).optional(),
|
|
111
|
+
tracingOptions: tracingOptionsSchema.optional()
|
|
112
|
+
});
|
|
113
|
+
var timeTravelBodySchema = z.object({
|
|
114
|
+
inputData: z.unknown().optional(),
|
|
115
|
+
resumeData: z.unknown().optional(),
|
|
116
|
+
initialState: z.unknown().optional(),
|
|
117
|
+
step: z.union([z.string(), z.array(z.string())]),
|
|
118
|
+
context: z.record(z.string(), z.any()).optional(),
|
|
119
|
+
nestedStepsContext: z.record(z.string(), z.record(z.string(), z.any())).optional(),
|
|
120
|
+
requestContext: z.record(z.string(), z.unknown()).optional(),
|
|
121
|
+
tracingOptions: tracingOptionsSchema.optional()
|
|
122
|
+
});
|
|
123
|
+
var startAsyncWorkflowBodySchema = workflowExecutionBodySchema;
|
|
124
|
+
z.object({
|
|
125
|
+
event: z.string(),
|
|
126
|
+
data: z.unknown()
|
|
127
|
+
});
|
|
128
|
+
var workflowExecutionResultSchema = z.object({
|
|
129
|
+
status: workflowRunStatusSchema,
|
|
130
|
+
result: z.unknown().optional(),
|
|
131
|
+
error: z.unknown().optional()
|
|
132
|
+
});
|
|
133
|
+
var workflowControlResponseSchema = messageResponseSchema;
|
|
134
|
+
var createWorkflowRunResponseSchema = z.object({
|
|
135
|
+
runId: z.string()
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// src/server/handlers/workflows.ts
|
|
139
|
+
async function listWorkflowsFromSystem({ mastra, workflowId }) {
|
|
140
|
+
const logger = mastra.getLogger();
|
|
141
|
+
if (!workflowId) {
|
|
142
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
143
|
+
}
|
|
144
|
+
let workflow;
|
|
145
|
+
workflow = WorkflowRegistry.getWorkflow(workflowId);
|
|
146
|
+
if (!workflow) {
|
|
147
|
+
try {
|
|
148
|
+
workflow = mastra.getWorkflowById(workflowId);
|
|
149
|
+
} catch (error) {
|
|
150
|
+
logger.debug("Error getting workflow, searching agents for workflow", error);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (!workflow) {
|
|
154
|
+
logger.debug("Workflow not found, searching agents for workflow", { workflowId });
|
|
155
|
+
const agents = mastra.listAgents();
|
|
156
|
+
if (Object.keys(agents || {}).length) {
|
|
157
|
+
for (const [_, agent] of Object.entries(agents)) {
|
|
158
|
+
try {
|
|
159
|
+
const workflows = await agent.listWorkflows();
|
|
160
|
+
if (workflows[workflowId]) {
|
|
161
|
+
workflow = workflows[workflowId];
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
break;
|
|
165
|
+
} catch (error) {
|
|
166
|
+
logger.debug("Error getting workflow from agent", error);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (!workflow) {
|
|
172
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
173
|
+
}
|
|
174
|
+
return { workflow };
|
|
175
|
+
}
|
|
176
|
+
var LIST_WORKFLOWS_ROUTE = createRoute({
|
|
177
|
+
method: "GET",
|
|
178
|
+
path: "/api/workflows",
|
|
179
|
+
responseType: "json",
|
|
180
|
+
responseSchema: listWorkflowsResponseSchema,
|
|
181
|
+
summary: "List all workflows",
|
|
182
|
+
description: "Returns a list of all available workflows in the system",
|
|
183
|
+
tags: ["Workflows"],
|
|
184
|
+
handler: async ({ mastra }) => {
|
|
185
|
+
try {
|
|
186
|
+
const workflows = mastra.listWorkflows({ serialized: false });
|
|
187
|
+
const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
|
|
188
|
+
acc[key] = getWorkflowInfo(workflow);
|
|
189
|
+
return acc;
|
|
190
|
+
}, {});
|
|
191
|
+
return _workflows;
|
|
192
|
+
} catch (error) {
|
|
193
|
+
return handleError(error, "Error getting workflows");
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
var GET_WORKFLOW_BY_ID_ROUTE = createRoute({
|
|
198
|
+
method: "GET",
|
|
199
|
+
path: "/api/workflows/:workflowId",
|
|
200
|
+
responseType: "json",
|
|
201
|
+
pathParamSchema: workflowIdPathParams,
|
|
202
|
+
responseSchema: workflowInfoSchema,
|
|
203
|
+
summary: "Get workflow by ID",
|
|
204
|
+
description: "Returns details for a specific workflow",
|
|
205
|
+
tags: ["Workflows"],
|
|
206
|
+
handler: async ({ mastra, workflowId }) => {
|
|
207
|
+
try {
|
|
208
|
+
if (!workflowId) {
|
|
209
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
210
|
+
}
|
|
211
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
212
|
+
return getWorkflowInfo(workflow);
|
|
213
|
+
} catch (error) {
|
|
214
|
+
return handleError(error, "Error getting workflow");
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
var LIST_WORKFLOW_RUNS_ROUTE = createRoute({
|
|
219
|
+
method: "GET",
|
|
220
|
+
path: "/api/workflows/:workflowId/runs",
|
|
221
|
+
responseType: "json",
|
|
222
|
+
pathParamSchema: workflowIdPathParams,
|
|
223
|
+
queryParamSchema: listWorkflowRunsQuerySchema,
|
|
224
|
+
responseSchema: workflowRunsResponseSchema,
|
|
225
|
+
summary: "List workflow runs",
|
|
226
|
+
description: "Returns a paginated list of execution runs for the specified workflow",
|
|
227
|
+
tags: ["Workflows"],
|
|
228
|
+
handler: async ({ mastra, workflowId, fromDate, toDate, limit, offset, resourceId, status }) => {
|
|
229
|
+
try {
|
|
230
|
+
if (!workflowId) {
|
|
231
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
232
|
+
}
|
|
233
|
+
const perPage = limit;
|
|
234
|
+
const page = offset !== void 0 && typeof limit === "number" && limit !== 0 ? Math.floor(offset / limit) : 0;
|
|
235
|
+
if (perPage !== void 0 && (typeof perPage !== "number" || !Number.isInteger(perPage) || perPage <= 0)) {
|
|
236
|
+
throw new HTTPException(400, { message: "limit must be a positive integer" });
|
|
237
|
+
}
|
|
238
|
+
if (page !== void 0 && (!Number.isInteger(page) || page < 0)) {
|
|
239
|
+
throw new HTTPException(400, { message: "page must be a non-negative integer" });
|
|
240
|
+
}
|
|
241
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
242
|
+
if (!workflow) {
|
|
243
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
244
|
+
}
|
|
245
|
+
const workflowRuns = await workflow.listWorkflowRuns({
|
|
246
|
+
fromDate: fromDate ? typeof fromDate === "string" ? new Date(fromDate) : fromDate : void 0,
|
|
247
|
+
toDate: toDate ? typeof toDate === "string" ? new Date(toDate) : toDate : void 0,
|
|
248
|
+
perPage,
|
|
249
|
+
page,
|
|
250
|
+
resourceId,
|
|
251
|
+
status
|
|
252
|
+
}) || {
|
|
253
|
+
runs: [],
|
|
254
|
+
total: 0
|
|
255
|
+
};
|
|
256
|
+
return workflowRuns;
|
|
257
|
+
} catch (error) {
|
|
258
|
+
return handleError(error, "Error getting workflow runs");
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
var GET_WORKFLOW_RUN_BY_ID_ROUTE = createRoute({
|
|
263
|
+
method: "GET",
|
|
264
|
+
path: "/api/workflows/:workflowId/runs/:runId",
|
|
265
|
+
responseType: "json",
|
|
266
|
+
pathParamSchema: workflowRunPathParams,
|
|
267
|
+
responseSchema: workflowRunResponseSchema,
|
|
268
|
+
summary: "Get workflow run by ID",
|
|
269
|
+
description: "Returns details for a specific workflow run",
|
|
270
|
+
tags: ["Workflows"],
|
|
271
|
+
handler: async ({ mastra, workflowId, runId }) => {
|
|
272
|
+
try {
|
|
273
|
+
if (!workflowId) {
|
|
274
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
275
|
+
}
|
|
276
|
+
if (!runId) {
|
|
277
|
+
throw new HTTPException(400, { message: "Run ID is required" });
|
|
278
|
+
}
|
|
279
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
280
|
+
if (!workflow) {
|
|
281
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
282
|
+
}
|
|
283
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
284
|
+
if (!run) {
|
|
285
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
286
|
+
}
|
|
287
|
+
return run;
|
|
288
|
+
} catch (error) {
|
|
289
|
+
return handleError(error, "Error getting workflow run");
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
var CREATE_WORKFLOW_RUN_ROUTE = createRoute({
|
|
294
|
+
method: "POST",
|
|
295
|
+
path: "/api/workflows/:workflowId/create-run",
|
|
296
|
+
responseType: "json",
|
|
297
|
+
pathParamSchema: workflowIdPathParams,
|
|
298
|
+
queryParamSchema: optionalRunIdSchema,
|
|
299
|
+
responseSchema: createWorkflowRunResponseSchema,
|
|
300
|
+
summary: "Create workflow run",
|
|
301
|
+
description: "Creates a new workflow execution instance with an optional custom run ID",
|
|
302
|
+
tags: ["Workflows"],
|
|
303
|
+
handler: async ({ mastra, workflowId, runId }) => {
|
|
304
|
+
try {
|
|
305
|
+
if (!workflowId) {
|
|
306
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
307
|
+
}
|
|
308
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
309
|
+
if (!workflow) {
|
|
310
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
311
|
+
}
|
|
312
|
+
const run = await workflow.createRun({ runId });
|
|
313
|
+
return { runId: run.runId };
|
|
314
|
+
} catch (error) {
|
|
315
|
+
return handleError(error, "Error creating workflow run");
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
var STREAM_WORKFLOW_ROUTE = createRoute({
|
|
320
|
+
method: "POST",
|
|
321
|
+
path: "/api/workflows/:workflowId/stream",
|
|
322
|
+
responseType: "stream",
|
|
323
|
+
pathParamSchema: workflowIdPathParams,
|
|
324
|
+
queryParamSchema: runIdSchema,
|
|
325
|
+
bodySchema: streamWorkflowBodySchema,
|
|
326
|
+
summary: "Stream workflow execution",
|
|
327
|
+
description: "Executes a workflow and streams the results in real-time",
|
|
328
|
+
tags: ["Workflows"],
|
|
329
|
+
handler: async ({ mastra, workflowId, runId, ...params }) => {
|
|
330
|
+
try {
|
|
331
|
+
if (!workflowId) {
|
|
332
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
333
|
+
}
|
|
334
|
+
if (!runId) {
|
|
335
|
+
throw new HTTPException(400, { message: "runId required to stream workflow" });
|
|
336
|
+
}
|
|
337
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
338
|
+
if (!workflow) {
|
|
339
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
340
|
+
}
|
|
341
|
+
const serverCache = mastra.getServerCache();
|
|
342
|
+
const run = await workflow.createRun({ runId });
|
|
343
|
+
const result = run.stream(params);
|
|
344
|
+
return result.fullStream.pipeThrough(
|
|
345
|
+
new TransformStream({
|
|
346
|
+
transform(chunk, controller) {
|
|
347
|
+
if (serverCache) {
|
|
348
|
+
const cacheKey = runId;
|
|
349
|
+
serverCache.listPush(cacheKey, chunk).catch(() => {
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
controller.enqueue(chunk);
|
|
353
|
+
}
|
|
354
|
+
})
|
|
355
|
+
);
|
|
356
|
+
} catch (error) {
|
|
357
|
+
return handleError(error, "Error streaming workflow");
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
var STREAM_VNEXT_WORKFLOW_ROUTE = createRoute({
|
|
362
|
+
method: "POST",
|
|
363
|
+
path: "/api/workflows/:workflowId/streamVNext",
|
|
364
|
+
responseType: "stream",
|
|
365
|
+
pathParamSchema: workflowIdPathParams,
|
|
366
|
+
queryParamSchema: runIdSchema,
|
|
367
|
+
bodySchema: streamWorkflowBodySchema,
|
|
368
|
+
summary: "Stream workflow execution (v2)",
|
|
369
|
+
description: "Executes a workflow using the v2 streaming API and streams the results in real-time",
|
|
370
|
+
tags: ["Workflows"],
|
|
371
|
+
handler: STREAM_WORKFLOW_ROUTE.handler
|
|
372
|
+
});
|
|
373
|
+
var RESUME_STREAM_WORKFLOW_ROUTE = createRoute({
|
|
374
|
+
method: "POST",
|
|
375
|
+
path: "/api/workflows/:workflowId/resume-stream",
|
|
376
|
+
responseType: "stream",
|
|
377
|
+
pathParamSchema: workflowIdPathParams,
|
|
378
|
+
queryParamSchema: runIdSchema,
|
|
379
|
+
bodySchema: resumeBodySchema,
|
|
380
|
+
responseSchema: streamResponseSchema,
|
|
381
|
+
summary: "Resume workflow stream",
|
|
382
|
+
description: "Resumes a suspended workflow execution and continues streaming results",
|
|
383
|
+
tags: ["Workflows"],
|
|
384
|
+
handler: async ({ mastra, workflowId, runId, ...params }) => {
|
|
385
|
+
try {
|
|
386
|
+
if (!workflowId) {
|
|
387
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
388
|
+
}
|
|
389
|
+
if (!runId) {
|
|
390
|
+
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
391
|
+
}
|
|
392
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
393
|
+
if (!workflow) {
|
|
394
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
395
|
+
}
|
|
396
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
397
|
+
if (!run) {
|
|
398
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
399
|
+
}
|
|
400
|
+
const _run = await workflow.createRun({ runId, resourceId: run.resourceId });
|
|
401
|
+
const serverCache = mastra.getServerCache();
|
|
402
|
+
const stream = _run.resumeStream(params).fullStream.pipeThrough(
|
|
403
|
+
new TransformStream({
|
|
404
|
+
transform(chunk, controller) {
|
|
405
|
+
if (serverCache) {
|
|
406
|
+
const cacheKey = runId;
|
|
407
|
+
serverCache.listPush(cacheKey, chunk).catch(() => {
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
controller.enqueue(chunk);
|
|
411
|
+
}
|
|
412
|
+
})
|
|
413
|
+
);
|
|
414
|
+
return stream;
|
|
415
|
+
} catch (error) {
|
|
416
|
+
return handleError(error, "Error resuming workflow");
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
var GET_WORKFLOW_RUN_EXECUTION_RESULT_ROUTE = createRoute({
|
|
421
|
+
method: "GET",
|
|
422
|
+
path: "/api/workflows/:workflowId/runs/:runId/execution-result",
|
|
423
|
+
responseType: "json",
|
|
424
|
+
pathParamSchema: workflowRunPathParams,
|
|
425
|
+
responseSchema: workflowExecutionResultSchema,
|
|
426
|
+
summary: "Get workflow execution result",
|
|
427
|
+
description: "Returns the final execution result of a completed workflow run",
|
|
428
|
+
tags: ["Workflows"],
|
|
429
|
+
handler: async ({ mastra, workflowId, runId }) => {
|
|
430
|
+
try {
|
|
431
|
+
if (!workflowId) {
|
|
432
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
433
|
+
}
|
|
434
|
+
if (!runId) {
|
|
435
|
+
throw new HTTPException(400, { message: "Run ID is required" });
|
|
436
|
+
}
|
|
437
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
438
|
+
if (!workflow) {
|
|
439
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
440
|
+
}
|
|
441
|
+
const executionResult = await workflow.getWorkflowRunExecutionResult(runId);
|
|
442
|
+
if (!executionResult) {
|
|
443
|
+
throw new HTTPException(404, { message: "Workflow run execution result not found" });
|
|
444
|
+
}
|
|
445
|
+
return executionResult;
|
|
446
|
+
} catch (error) {
|
|
447
|
+
return handleError(error, "Error getting workflow run execution result");
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
var START_ASYNC_WORKFLOW_ROUTE = createRoute({
|
|
452
|
+
method: "POST",
|
|
453
|
+
path: "/api/workflows/:workflowId/start-async",
|
|
454
|
+
responseType: "json",
|
|
455
|
+
pathParamSchema: workflowIdPathParams,
|
|
456
|
+
queryParamSchema: optionalRunIdSchema,
|
|
457
|
+
bodySchema: startAsyncWorkflowBodySchema,
|
|
458
|
+
responseSchema: workflowExecutionResultSchema,
|
|
459
|
+
summary: "Start workflow asynchronously",
|
|
460
|
+
description: "Starts a workflow execution asynchronously without streaming results",
|
|
461
|
+
tags: ["Workflows"],
|
|
462
|
+
handler: async ({ mastra, workflowId, runId, ...params }) => {
|
|
463
|
+
try {
|
|
464
|
+
if (!workflowId) {
|
|
465
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
466
|
+
}
|
|
467
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
468
|
+
if (!workflow) {
|
|
469
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
470
|
+
}
|
|
471
|
+
const _run = await workflow.createRun({ runId });
|
|
472
|
+
const result = await _run.start(params);
|
|
473
|
+
return result;
|
|
474
|
+
} catch (error) {
|
|
475
|
+
return handleError(error, "Error starting async workflow");
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
var START_WORKFLOW_RUN_ROUTE = createRoute({
|
|
480
|
+
method: "POST",
|
|
481
|
+
path: "/api/workflows/:workflowId/start",
|
|
482
|
+
responseType: "json",
|
|
483
|
+
pathParamSchema: workflowIdPathParams,
|
|
484
|
+
queryParamSchema: runIdSchema,
|
|
485
|
+
bodySchema: startAsyncWorkflowBodySchema,
|
|
486
|
+
responseSchema: workflowControlResponseSchema,
|
|
487
|
+
summary: "Start specific workflow run",
|
|
488
|
+
description: "Starts execution of a specific workflow run by ID",
|
|
489
|
+
tags: ["Workflows"],
|
|
490
|
+
handler: async ({ mastra, workflowId, runId, ...params }) => {
|
|
491
|
+
try {
|
|
492
|
+
if (!workflowId) {
|
|
493
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
494
|
+
}
|
|
495
|
+
if (!runId) {
|
|
496
|
+
throw new HTTPException(400, { message: "runId required to start run" });
|
|
497
|
+
}
|
|
498
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
499
|
+
if (!workflow) {
|
|
500
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
501
|
+
}
|
|
502
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
503
|
+
if (!run) {
|
|
504
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
505
|
+
}
|
|
506
|
+
const _run = await workflow.createRun({ runId, resourceId: run.resourceId });
|
|
507
|
+
void _run.start({
|
|
508
|
+
...params
|
|
509
|
+
});
|
|
510
|
+
return { message: "Workflow run started" };
|
|
511
|
+
} catch (e) {
|
|
512
|
+
return handleError(e, "Error starting workflow run");
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
var OBSERVE_STREAM_WORKFLOW_ROUTE = createRoute({
|
|
517
|
+
method: "POST",
|
|
518
|
+
path: "/api/workflows/:workflowId/observe",
|
|
519
|
+
responseType: "stream",
|
|
520
|
+
pathParamSchema: workflowIdPathParams,
|
|
521
|
+
queryParamSchema: runIdSchema,
|
|
522
|
+
responseSchema: streamResponseSchema,
|
|
523
|
+
summary: "Observe workflow stream",
|
|
524
|
+
description: "Observes and streams updates from an already running workflow execution",
|
|
525
|
+
tags: ["Workflows"],
|
|
526
|
+
handler: async ({ mastra, workflowId, runId }) => {
|
|
527
|
+
try {
|
|
528
|
+
if (!workflowId) {
|
|
529
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
530
|
+
}
|
|
531
|
+
if (!runId) {
|
|
532
|
+
throw new HTTPException(400, { message: "runId required to observe workflow stream" });
|
|
533
|
+
}
|
|
534
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
535
|
+
if (!workflow) {
|
|
536
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
537
|
+
}
|
|
538
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
539
|
+
if (!run) {
|
|
540
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
541
|
+
}
|
|
542
|
+
const _run = await workflow.createRun({ runId, resourceId: run.resourceId });
|
|
543
|
+
const serverCache = mastra.getServerCache();
|
|
544
|
+
if (!serverCache) {
|
|
545
|
+
throw new HTTPException(500, { message: "Server cache not found" });
|
|
546
|
+
}
|
|
547
|
+
const cachedRunChunks = await serverCache.listFromTo(runId, 0);
|
|
548
|
+
const combinedStream = new ReadableStream({
|
|
549
|
+
start(controller) {
|
|
550
|
+
const emitCachedChunks = async () => {
|
|
551
|
+
for (const chunk of cachedRunChunks) {
|
|
552
|
+
controller.enqueue(chunk);
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
const liveStream = _run.observeStream();
|
|
556
|
+
const reader = liveStream.getReader();
|
|
557
|
+
const pump = async () => {
|
|
558
|
+
try {
|
|
559
|
+
while (true) {
|
|
560
|
+
const { done, value } = await reader.read();
|
|
561
|
+
if (done) {
|
|
562
|
+
controller.close();
|
|
563
|
+
break;
|
|
564
|
+
}
|
|
565
|
+
controller.enqueue(value);
|
|
566
|
+
}
|
|
567
|
+
} catch (error) {
|
|
568
|
+
controller.error(error);
|
|
569
|
+
} finally {
|
|
570
|
+
reader.releaseLock();
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
void emitCachedChunks().then(() => {
|
|
574
|
+
void pump();
|
|
575
|
+
}).catch((error) => {
|
|
576
|
+
controller.error(error);
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
return combinedStream;
|
|
581
|
+
} catch (error) {
|
|
582
|
+
return handleError(error, "Error observing workflow stream");
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
var OBSERVE_STREAM_VNEXT_WORKFLOW_ROUTE = createRoute({
|
|
587
|
+
method: "POST",
|
|
588
|
+
path: "/api/workflows/:workflowId/observe-streamVNext",
|
|
589
|
+
responseType: "stream",
|
|
590
|
+
pathParamSchema: workflowIdPathParams,
|
|
591
|
+
queryParamSchema: runIdSchema,
|
|
592
|
+
responseSchema: streamResponseSchema,
|
|
593
|
+
summary: "Observe workflow stream (v2)",
|
|
594
|
+
description: "Observes and streams updates from an already running workflow execution using v2 streaming API",
|
|
595
|
+
tags: ["Workflows"],
|
|
596
|
+
handler: OBSERVE_STREAM_WORKFLOW_ROUTE.handler
|
|
597
|
+
});
|
|
598
|
+
var RESUME_ASYNC_WORKFLOW_ROUTE = createRoute({
|
|
599
|
+
method: "POST",
|
|
600
|
+
path: "/api/workflows/:workflowId/resume-async",
|
|
601
|
+
responseType: "json",
|
|
602
|
+
pathParamSchema: workflowIdPathParams,
|
|
603
|
+
queryParamSchema: runIdSchema,
|
|
604
|
+
bodySchema: resumeBodySchema,
|
|
605
|
+
responseSchema: workflowExecutionResultSchema,
|
|
606
|
+
summary: "Resume workflow asynchronously",
|
|
607
|
+
description: "Resumes a suspended workflow execution asynchronously without streaming",
|
|
608
|
+
tags: ["Workflows"],
|
|
609
|
+
handler: async ({ mastra, workflowId, runId, ...params }) => {
|
|
610
|
+
try {
|
|
611
|
+
if (!workflowId) {
|
|
612
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
613
|
+
}
|
|
614
|
+
if (!runId) {
|
|
615
|
+
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
616
|
+
}
|
|
617
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
618
|
+
if (!workflow) {
|
|
619
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
620
|
+
}
|
|
621
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
622
|
+
if (!run) {
|
|
623
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
624
|
+
}
|
|
625
|
+
const _run = await workflow.createRun({ runId, resourceId: run.resourceId });
|
|
626
|
+
const result = await _run.resume(params);
|
|
627
|
+
return result;
|
|
628
|
+
} catch (error) {
|
|
629
|
+
return handleError(error, "Error resuming workflow step");
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
var RESUME_WORKFLOW_ROUTE = createRoute({
|
|
634
|
+
method: "POST",
|
|
635
|
+
path: "/api/workflows/:workflowId/resume",
|
|
636
|
+
responseType: "json",
|
|
637
|
+
pathParamSchema: workflowIdPathParams,
|
|
638
|
+
queryParamSchema: runIdSchema,
|
|
639
|
+
bodySchema: resumeBodySchema,
|
|
640
|
+
responseSchema: workflowControlResponseSchema,
|
|
641
|
+
summary: "Resume workflow",
|
|
642
|
+
description: "Resumes a suspended workflow execution from a specific step",
|
|
643
|
+
tags: ["Workflows"],
|
|
644
|
+
handler: async ({ mastra, workflowId, runId, ...params }) => {
|
|
645
|
+
try {
|
|
646
|
+
if (!workflowId) {
|
|
647
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
648
|
+
}
|
|
649
|
+
if (!runId) {
|
|
650
|
+
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
651
|
+
}
|
|
652
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
653
|
+
if (!workflow) {
|
|
654
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
655
|
+
}
|
|
656
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
657
|
+
if (!run) {
|
|
658
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
659
|
+
}
|
|
660
|
+
const _run = await workflow.createRun({ runId, resourceId: run.resourceId });
|
|
661
|
+
void _run.resume(params);
|
|
662
|
+
return { message: "Workflow run resumed" };
|
|
663
|
+
} catch (error) {
|
|
664
|
+
return handleError(error, "Error resuming workflow");
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
});
|
|
668
|
+
var RESTART_ASYNC_WORKFLOW_ROUTE = createRoute({
|
|
669
|
+
method: "POST",
|
|
670
|
+
path: "/api/workflows/:workflowId/restart-async",
|
|
671
|
+
responseType: "json",
|
|
672
|
+
pathParamSchema: workflowIdPathParams,
|
|
673
|
+
queryParamSchema: runIdSchema,
|
|
674
|
+
bodySchema: restartBodySchema,
|
|
675
|
+
responseSchema: workflowExecutionResultSchema,
|
|
676
|
+
summary: "Restart workflow asynchronously",
|
|
677
|
+
description: "Restarts an active workflow execution asynchronously",
|
|
678
|
+
tags: ["Workflows"],
|
|
679
|
+
handler: async ({ mastra, workflowId, runId, ...params }) => {
|
|
680
|
+
try {
|
|
681
|
+
if (!workflowId) {
|
|
682
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
683
|
+
}
|
|
684
|
+
if (!runId) {
|
|
685
|
+
throw new HTTPException(400, { message: "runId required to restart workflow" });
|
|
686
|
+
}
|
|
687
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
688
|
+
if (!workflow) {
|
|
689
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
690
|
+
}
|
|
691
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
692
|
+
if (!run) {
|
|
693
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
694
|
+
}
|
|
695
|
+
const _run = await workflow.createRun({ runId, resourceId: run.resourceId });
|
|
696
|
+
const result = await _run.restart(params);
|
|
697
|
+
return result;
|
|
698
|
+
} catch (error) {
|
|
699
|
+
return handleError(error, "Error restarting workflow");
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
var RESTART_WORKFLOW_ROUTE = createRoute({
|
|
704
|
+
method: "POST",
|
|
705
|
+
path: "/api/workflows/:workflowId/restart",
|
|
706
|
+
responseType: "json",
|
|
707
|
+
pathParamSchema: workflowIdPathParams,
|
|
708
|
+
queryParamSchema: runIdSchema,
|
|
709
|
+
bodySchema: restartBodySchema,
|
|
710
|
+
responseSchema: workflowControlResponseSchema,
|
|
711
|
+
summary: "Restart workflow",
|
|
712
|
+
description: "Restarts an active workflow execution",
|
|
713
|
+
tags: ["Workflows"],
|
|
714
|
+
handler: async ({ mastra, workflowId, runId, ...params }) => {
|
|
715
|
+
try {
|
|
716
|
+
if (!workflowId) {
|
|
717
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
718
|
+
}
|
|
719
|
+
if (!runId) {
|
|
720
|
+
throw new HTTPException(400, { message: "runId required to restart workflow" });
|
|
721
|
+
}
|
|
722
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
723
|
+
if (!workflow) {
|
|
724
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
725
|
+
}
|
|
726
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
727
|
+
if (!run) {
|
|
728
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
729
|
+
}
|
|
730
|
+
const _run = await workflow.createRun({ runId, resourceId: run.resourceId });
|
|
731
|
+
void _run.restart(params);
|
|
732
|
+
return { message: "Workflow run restarted" };
|
|
733
|
+
} catch (error) {
|
|
734
|
+
return handleError(error, "Error restarting workflow");
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
});
|
|
738
|
+
var RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ASYNC_ROUTE = createRoute({
|
|
739
|
+
method: "POST",
|
|
740
|
+
path: "/api/workflows/:workflowId/restart-all-active-workflow-runs-async",
|
|
741
|
+
responseType: "json",
|
|
742
|
+
pathParamSchema: workflowIdPathParams,
|
|
743
|
+
responseSchema: workflowControlResponseSchema,
|
|
744
|
+
summary: "Restart all active workflow runs asynchronously",
|
|
745
|
+
description: "Restarts all active workflow runs asynchronously",
|
|
746
|
+
tags: ["Workflows"],
|
|
747
|
+
handler: async ({ mastra, workflowId }) => {
|
|
748
|
+
try {
|
|
749
|
+
if (!workflowId) {
|
|
750
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
751
|
+
}
|
|
752
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
753
|
+
if (!workflow) {
|
|
754
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
755
|
+
}
|
|
756
|
+
await workflow.restartAllActiveWorkflowRuns();
|
|
757
|
+
return { message: "All active workflow runs restarted" };
|
|
758
|
+
} catch (error) {
|
|
759
|
+
return handleError(error, "Error restarting workflow");
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
});
|
|
763
|
+
var RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ROUTE = createRoute({
|
|
764
|
+
method: "POST",
|
|
765
|
+
path: "/api/workflows/:workflowId/restart-all-active-workflow-runs",
|
|
766
|
+
responseType: "json",
|
|
767
|
+
pathParamSchema: workflowIdPathParams,
|
|
768
|
+
responseSchema: workflowControlResponseSchema,
|
|
769
|
+
summary: "Restart all active workflow runs",
|
|
770
|
+
description: "Restarts all active workflow runs",
|
|
771
|
+
tags: ["Workflows"],
|
|
772
|
+
handler: async ({ mastra, workflowId }) => {
|
|
773
|
+
try {
|
|
774
|
+
if (!workflowId) {
|
|
775
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
776
|
+
}
|
|
777
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
778
|
+
if (!workflow) {
|
|
779
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
780
|
+
}
|
|
781
|
+
void workflow.restartAllActiveWorkflowRuns();
|
|
782
|
+
return { message: "All active workflow runs restarted" };
|
|
783
|
+
} catch (error) {
|
|
784
|
+
return handleError(error, "Error restarting workflow");
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
});
|
|
788
|
+
var TIME_TRAVEL_ASYNC_WORKFLOW_ROUTE = createRoute({
|
|
789
|
+
method: "POST",
|
|
790
|
+
path: "/api/workflows/:workflowId/time-travel-async",
|
|
791
|
+
responseType: "json",
|
|
792
|
+
pathParamSchema: workflowIdPathParams,
|
|
793
|
+
queryParamSchema: runIdSchema,
|
|
794
|
+
bodySchema: timeTravelBodySchema,
|
|
795
|
+
responseSchema: workflowExecutionResultSchema,
|
|
796
|
+
summary: "Time travel workflow asynchronously",
|
|
797
|
+
description: "Time travels a workflow run asynchronously without streaming",
|
|
798
|
+
tags: ["Workflows"],
|
|
799
|
+
handler: async ({ mastra, workflowId, runId, ...params }) => {
|
|
800
|
+
try {
|
|
801
|
+
if (!workflowId) {
|
|
802
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
803
|
+
}
|
|
804
|
+
if (!runId) {
|
|
805
|
+
throw new HTTPException(400, { message: "runId required to time travel workflow" });
|
|
806
|
+
}
|
|
807
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
808
|
+
if (!workflow) {
|
|
809
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
810
|
+
}
|
|
811
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
812
|
+
if (!run) {
|
|
813
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
814
|
+
}
|
|
815
|
+
const _run = await workflow.createRun({ runId, resourceId: run.resourceId });
|
|
816
|
+
const result = await _run.timeTravel(params);
|
|
817
|
+
return result;
|
|
818
|
+
} catch (error) {
|
|
819
|
+
return handleError(error, "Error time traveling workflow");
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
});
|
|
823
|
+
var TIME_TRAVEL_WORKFLOW_ROUTE = createRoute({
|
|
824
|
+
method: "POST",
|
|
825
|
+
path: "/api/workflows/:workflowId/time-travel",
|
|
826
|
+
responseType: "json",
|
|
827
|
+
pathParamSchema: workflowIdPathParams,
|
|
828
|
+
queryParamSchema: runIdSchema,
|
|
829
|
+
bodySchema: timeTravelBodySchema,
|
|
830
|
+
responseSchema: workflowControlResponseSchema,
|
|
831
|
+
summary: "Time travel workflow",
|
|
832
|
+
description: "Time travels a workflow run, starting from a specific step",
|
|
833
|
+
tags: ["Workflows"],
|
|
834
|
+
handler: async ({ mastra, workflowId, runId, ...params }) => {
|
|
835
|
+
try {
|
|
836
|
+
if (!workflowId) {
|
|
837
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
838
|
+
}
|
|
839
|
+
if (!runId) {
|
|
840
|
+
throw new HTTPException(400, { message: "runId required to time travel workflow" });
|
|
841
|
+
}
|
|
842
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
843
|
+
if (!workflow) {
|
|
844
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
845
|
+
}
|
|
846
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
847
|
+
if (!run) {
|
|
848
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
849
|
+
}
|
|
850
|
+
const _run = await workflow.createRun({ runId, resourceId: run.resourceId });
|
|
851
|
+
void _run.timeTravel(params);
|
|
852
|
+
return { message: "Workflow run time travel started" };
|
|
853
|
+
} catch (error) {
|
|
854
|
+
return handleError(error, "Error time traveling workflow");
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
});
|
|
858
|
+
var TIME_TRAVEL_STREAM_WORKFLOW_ROUTE = createRoute({
|
|
859
|
+
method: "POST",
|
|
860
|
+
path: "/api/workflows/:workflowId/time-travel-stream",
|
|
861
|
+
responseType: "stream",
|
|
862
|
+
pathParamSchema: workflowIdPathParams,
|
|
863
|
+
queryParamSchema: runIdSchema,
|
|
864
|
+
bodySchema: timeTravelBodySchema,
|
|
865
|
+
summary: "Time travel workflow stream",
|
|
866
|
+
description: "Time travels a workflow run, starting from a specific step, and streams the results in real-time",
|
|
867
|
+
tags: ["Workflows"],
|
|
868
|
+
handler: async ({ mastra, workflowId, runId, ...params }) => {
|
|
869
|
+
try {
|
|
870
|
+
if (!workflowId) {
|
|
871
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
872
|
+
}
|
|
873
|
+
if (!runId) {
|
|
874
|
+
throw new HTTPException(400, { message: "runId required to time travel workflow stream" });
|
|
875
|
+
}
|
|
876
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
877
|
+
if (!workflow) {
|
|
878
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
879
|
+
}
|
|
880
|
+
const serverCache = mastra.getServerCache();
|
|
881
|
+
const run = await workflow.createRun({ runId });
|
|
882
|
+
const result = run.timeTravelStream(params);
|
|
883
|
+
return result.fullStream.pipeThrough(
|
|
884
|
+
new TransformStream({
|
|
885
|
+
transform(chunk, controller) {
|
|
886
|
+
if (serverCache) {
|
|
887
|
+
const cacheKey = runId;
|
|
888
|
+
serverCache.listPush(cacheKey, chunk).catch(() => {
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
controller.enqueue(chunk);
|
|
892
|
+
}
|
|
893
|
+
})
|
|
894
|
+
);
|
|
895
|
+
} catch (error) {
|
|
896
|
+
return handleError(error, "Error time traveling workflow stream");
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
});
|
|
900
|
+
var CANCEL_WORKFLOW_RUN_ROUTE = createRoute({
|
|
901
|
+
method: "POST",
|
|
902
|
+
path: "/api/workflows/:workflowId/runs/:runId/cancel",
|
|
903
|
+
responseType: "json",
|
|
904
|
+
pathParamSchema: workflowRunPathParams,
|
|
905
|
+
responseSchema: workflowControlResponseSchema,
|
|
906
|
+
summary: "Cancel workflow run",
|
|
907
|
+
description: "Cancels an in-progress workflow execution",
|
|
908
|
+
tags: ["Workflows"],
|
|
909
|
+
handler: async ({ mastra, workflowId, runId }) => {
|
|
910
|
+
try {
|
|
911
|
+
if (!workflowId) {
|
|
912
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
913
|
+
}
|
|
914
|
+
if (!runId) {
|
|
915
|
+
throw new HTTPException(400, { message: "runId required to cancel workflow run" });
|
|
916
|
+
}
|
|
917
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
918
|
+
if (!workflow) {
|
|
919
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
920
|
+
}
|
|
921
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
922
|
+
if (!run) {
|
|
923
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
924
|
+
}
|
|
925
|
+
const _run = await workflow.createRun({ runId, resourceId: run.resourceId });
|
|
926
|
+
await _run.cancel();
|
|
927
|
+
return { message: "Workflow run cancelled" };
|
|
928
|
+
} catch (error) {
|
|
929
|
+
return handleError(error, "Error canceling workflow run");
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
});
|
|
933
|
+
var STREAM_LEGACY_WORKFLOW_ROUTE = createRoute({
|
|
934
|
+
method: "POST",
|
|
935
|
+
path: "/api/workflows/:workflowId/stream-legacy",
|
|
936
|
+
responseType: "stream",
|
|
937
|
+
pathParamSchema: workflowIdPathParams,
|
|
938
|
+
queryParamSchema: runIdSchema,
|
|
939
|
+
bodySchema: streamWorkflowBodySchema,
|
|
940
|
+
responseSchema: streamResponseSchema,
|
|
941
|
+
summary: "[DEPRECATED] Stream workflow with legacy format",
|
|
942
|
+
description: "Legacy endpoint for streaming workflow execution. Use /api/workflows/:workflowId/stream instead.",
|
|
943
|
+
tags: ["Workflows", "Legacy"],
|
|
944
|
+
handler: async ({ mastra, workflowId, runId, ...params }) => {
|
|
945
|
+
try {
|
|
946
|
+
if (!workflowId) {
|
|
947
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
948
|
+
}
|
|
949
|
+
if (!runId) {
|
|
950
|
+
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
951
|
+
}
|
|
952
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
953
|
+
if (!workflow) {
|
|
954
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
955
|
+
}
|
|
956
|
+
const serverCache = mastra.getServerCache();
|
|
957
|
+
const run = await workflow.createRun({ runId });
|
|
958
|
+
const result = run.streamLegacy({
|
|
959
|
+
...params,
|
|
960
|
+
onChunk: async (chunk) => {
|
|
961
|
+
if (serverCache) {
|
|
962
|
+
const cacheKey = runId;
|
|
963
|
+
await serverCache.listPush(cacheKey, chunk);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
});
|
|
967
|
+
return result.stream;
|
|
968
|
+
} catch (error) {
|
|
969
|
+
return handleError(error, "Error executing workflow");
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
});
|
|
973
|
+
var OBSERVE_STREAM_LEGACY_WORKFLOW_ROUTE = createRoute({
|
|
974
|
+
method: "POST",
|
|
975
|
+
path: "/api/workflows/:workflowId/observe-stream-legacy",
|
|
976
|
+
responseType: "stream",
|
|
977
|
+
pathParamSchema: workflowIdPathParams,
|
|
978
|
+
queryParamSchema: runIdSchema,
|
|
979
|
+
responseSchema: streamResponseSchema,
|
|
980
|
+
summary: "[DEPRECATED] Observe workflow stream with legacy format",
|
|
981
|
+
description: "Legacy endpoint for observing workflow stream. Use /api/workflows/:workflowId/observe instead.",
|
|
982
|
+
tags: ["Workflows", "Legacy"],
|
|
983
|
+
handler: async ({ mastra, workflowId, runId }) => {
|
|
984
|
+
try {
|
|
985
|
+
if (!workflowId) {
|
|
986
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
987
|
+
}
|
|
988
|
+
if (!runId) {
|
|
989
|
+
throw new HTTPException(400, { message: "runId required to observe workflow stream" });
|
|
990
|
+
}
|
|
991
|
+
const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
|
|
992
|
+
if (!workflow) {
|
|
993
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
994
|
+
}
|
|
995
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
996
|
+
if (!run) {
|
|
997
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
998
|
+
}
|
|
999
|
+
const _run = await workflow.createRun({ runId, resourceId: run.resourceId });
|
|
1000
|
+
const serverCache = mastra.getServerCache();
|
|
1001
|
+
if (!serverCache) {
|
|
1002
|
+
throw new HTTPException(500, { message: "Server cache not found" });
|
|
1003
|
+
}
|
|
1004
|
+
const transformStream = new TransformStream();
|
|
1005
|
+
const writer = transformStream.writable.getWriter();
|
|
1006
|
+
const cachedRunChunks = await serverCache.listFromTo(runId, 0);
|
|
1007
|
+
for (const chunk of cachedRunChunks) {
|
|
1008
|
+
await writer.write(chunk);
|
|
1009
|
+
}
|
|
1010
|
+
writer.releaseLock();
|
|
1011
|
+
const result = _run.observeStreamLegacy();
|
|
1012
|
+
return result.stream?.pipeThrough(transformStream);
|
|
1013
|
+
} catch (error) {
|
|
1014
|
+
return handleError(error, "Error observing workflow stream");
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
});
|
|
1018
|
+
|
|
1019
|
+
export { CANCEL_WORKFLOW_RUN_ROUTE, CREATE_WORKFLOW_RUN_ROUTE, GET_WORKFLOW_BY_ID_ROUTE, GET_WORKFLOW_RUN_BY_ID_ROUTE, GET_WORKFLOW_RUN_EXECUTION_RESULT_ROUTE, LIST_WORKFLOWS_ROUTE, LIST_WORKFLOW_RUNS_ROUTE, OBSERVE_STREAM_LEGACY_WORKFLOW_ROUTE, OBSERVE_STREAM_VNEXT_WORKFLOW_ROUTE, OBSERVE_STREAM_WORKFLOW_ROUTE, RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ASYNC_ROUTE, RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ROUTE, RESTART_ASYNC_WORKFLOW_ROUTE, RESTART_WORKFLOW_ROUTE, RESUME_ASYNC_WORKFLOW_ROUTE, RESUME_STREAM_WORKFLOW_ROUTE, RESUME_WORKFLOW_ROUTE, START_ASYNC_WORKFLOW_ROUTE, START_WORKFLOW_RUN_ROUTE, STREAM_LEGACY_WORKFLOW_ROUTE, STREAM_VNEXT_WORKFLOW_ROUTE, STREAM_WORKFLOW_ROUTE, TIME_TRAVEL_ASYNC_WORKFLOW_ROUTE, TIME_TRAVEL_STREAM_WORKFLOW_ROUTE, TIME_TRAVEL_WORKFLOW_ROUTE, createWorkflowRunResponseSchema, listWorkflowRunsQuerySchema, listWorkflowsResponseSchema, resumeBodySchema, startAsyncWorkflowBodySchema, streamLegacyWorkflowBodySchema, streamWorkflowBodySchema, workflowControlResponseSchema, workflowExecutionResultSchema, workflowInfoSchema, workflowRunResponseSchema, workflowRunsResponseSchema, workflows_exports };
|
|
1020
|
+
//# sourceMappingURL=chunk-6KNI7VIX.js.map
|
|
1021
|
+
//# sourceMappingURL=chunk-6KNI7VIX.js.map
|