@mastra/server 0.10.13 → 0.10.14

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.
Files changed (99) hide show
  1. package/dist/_tsup-dts-rollup.d.cts +1078 -0
  2. package/dist/_tsup-dts-rollup.d.ts +1078 -0
  3. package/dist/chunk-2KZFMI6P.cjs +37 -0
  4. package/dist/chunk-2SLFAFTR.cjs +148 -0
  5. package/dist/chunk-4D66QEKC.js +81 -0
  6. package/dist/chunk-5PQQ42EZ.js +320 -0
  7. package/dist/chunk-75ZPJI57.cjs +9 -0
  8. package/dist/chunk-7TP2LX5L.cjs +129 -0
  9. package/dist/chunk-B2PAS2IB.cjs +514 -0
  10. package/dist/chunk-BK4XT6EG.js +270 -0
  11. package/dist/chunk-CCGRCYWJ.cjs +18 -0
  12. package/dist/chunk-CRCR3ZUK.js +142 -0
  13. package/dist/chunk-DN7K6FJK.cjs +251 -0
  14. package/dist/chunk-FRVBFMO2.cjs +128 -0
  15. package/dist/chunk-G7KH752Y.cjs +145 -0
  16. package/dist/chunk-GHC4YV6R.js +504 -0
  17. package/dist/chunk-H7DMHBKY.js +498 -0
  18. package/dist/chunk-JMLYCXMK.cjs +332 -0
  19. package/dist/chunk-KHZKYUNR.js +112 -0
  20. package/dist/chunk-LCM566I4.js +35 -0
  21. package/dist/chunk-LF7P5PLR.js +14 -0
  22. package/dist/chunk-LI436ITD.cjs +2042 -0
  23. package/dist/chunk-LRCAAFUA.js +122 -0
  24. package/dist/chunk-LZ3VJXSO.cjs +278 -0
  25. package/dist/chunk-MEGCYGBU.js +2039 -0
  26. package/dist/chunk-MKLYEKEF.js +241 -0
  27. package/dist/chunk-MLKGABMK.js +7 -0
  28. package/dist/chunk-PZQDCRPV.cjs +16 -0
  29. package/dist/chunk-QGX47B5D.cjs +86 -0
  30. package/dist/chunk-RG473F6Y.js +141 -0
  31. package/dist/chunk-RHSWAXKB.cjs +118 -0
  32. package/dist/chunk-RSEO4XPX.js +16 -0
  33. package/dist/chunk-SDPGVWQJ.cjs +512 -0
  34. package/dist/chunk-WNVFNNWN.js +121 -0
  35. package/dist/index.cjs +2 -0
  36. package/dist/index.d.cts +1 -0
  37. package/dist/index.d.ts +1 -0
  38. package/dist/index.js +1 -0
  39. package/dist/server/handlers/a2a.cjs +30 -0
  40. package/dist/server/handlers/a2a.d.cts +6 -0
  41. package/dist/server/handlers/a2a.d.ts +6 -0
  42. package/dist/server/handlers/a2a.js +1 -0
  43. package/dist/server/handlers/agents.cjs +30 -0
  44. package/dist/server/handlers/agents.d.cts +6 -0
  45. package/dist/server/handlers/agents.d.ts +6 -0
  46. package/dist/server/handlers/agents.js +1 -0
  47. package/dist/server/handlers/error.cjs +10 -0
  48. package/dist/server/handlers/error.d.cts +1 -0
  49. package/dist/server/handlers/error.d.ts +1 -0
  50. package/dist/server/handlers/error.js +1 -0
  51. package/dist/server/handlers/legacyWorkflows.cjs +46 -0
  52. package/dist/server/handlers/legacyWorkflows.d.cts +10 -0
  53. package/dist/server/handlers/legacyWorkflows.d.ts +10 -0
  54. package/dist/server/handlers/legacyWorkflows.js +1 -0
  55. package/dist/server/handlers/logs.cjs +18 -0
  56. package/dist/server/handlers/logs.d.cts +3 -0
  57. package/dist/server/handlers/logs.d.ts +3 -0
  58. package/dist/server/handlers/logs.js +1 -0
  59. package/dist/server/handlers/memory.cjs +38 -0
  60. package/dist/server/handlers/memory.d.cts +8 -0
  61. package/dist/server/handlers/memory.d.ts +8 -0
  62. package/dist/server/handlers/memory.js +1 -0
  63. package/dist/server/handlers/network.cjs +22 -0
  64. package/dist/server/handlers/network.d.cts +4 -0
  65. package/dist/server/handlers/network.d.ts +4 -0
  66. package/dist/server/handlers/network.js +1 -0
  67. package/dist/server/handlers/telemetry.cjs +14 -0
  68. package/dist/server/handlers/telemetry.d.cts +2 -0
  69. package/dist/server/handlers/telemetry.d.ts +2 -0
  70. package/dist/server/handlers/telemetry.js +1 -0
  71. package/dist/server/handlers/tools.cjs +22 -0
  72. package/dist/server/handlers/tools.d.cts +4 -0
  73. package/dist/server/handlers/tools.d.ts +4 -0
  74. package/dist/server/handlers/tools.js +1 -0
  75. package/dist/server/handlers/utils.cjs +10 -0
  76. package/dist/server/handlers/utils.d.cts +1 -0
  77. package/dist/server/handlers/utils.d.ts +1 -0
  78. package/dist/server/handlers/utils.js +1 -0
  79. package/dist/server/handlers/vNextNetwork.cjs +218 -0
  80. package/dist/server/handlers/vNextNetwork.d.cts +6 -0
  81. package/dist/server/handlers/vNextNetwork.d.ts +6 -0
  82. package/dist/server/handlers/vNextNetwork.js +211 -0
  83. package/dist/server/handlers/vector.cjs +30 -0
  84. package/dist/server/handlers/vector.d.cts +6 -0
  85. package/dist/server/handlers/vector.d.ts +6 -0
  86. package/dist/server/handlers/vector.js +1 -0
  87. package/dist/server/handlers/voice.cjs +22 -0
  88. package/dist/server/handlers/voice.d.cts +4 -0
  89. package/dist/server/handlers/voice.d.ts +4 -0
  90. package/dist/server/handlers/voice.js +1 -0
  91. package/dist/server/handlers/workflows.cjs +62 -0
  92. package/dist/server/handlers/workflows.d.cts +14 -0
  93. package/dist/server/handlers/workflows.d.ts +14 -0
  94. package/dist/server/handlers/workflows.js +1 -0
  95. package/dist/server/handlers.cjs +60 -0
  96. package/dist/server/handlers.d.cts +11 -0
  97. package/dist/server/handlers.d.ts +11 -0
  98. package/dist/server/handlers.js +11 -0
  99. package/package.json +2 -2
@@ -0,0 +1,129 @@
1
+ 'use strict';
2
+
3
+ var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
4
+ var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
5
+ var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
6
+
7
+ // src/server/handlers/vector.ts
8
+ var vector_exports = {};
9
+ chunk75ZPJI57_cjs.__export(vector_exports, {
10
+ createIndex: () => createIndex,
11
+ deleteIndex: () => deleteIndex,
12
+ describeIndex: () => describeIndex,
13
+ listIndexes: () => listIndexes,
14
+ queryVectors: () => queryVectors,
15
+ upsertVectors: () => upsertVectors
16
+ });
17
+ function getVector(mastra, vectorName) {
18
+ if (!vectorName) {
19
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Vector name is required" });
20
+ }
21
+ const vector = mastra.getVector(vectorName);
22
+ if (!vector) {
23
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: `Vector store ${vectorName} not found` });
24
+ }
25
+ return vector;
26
+ }
27
+ async function upsertVectors({ mastra, vectorName, index }) {
28
+ try {
29
+ if (!index?.indexName || !index?.vectors || !Array.isArray(index.vectors)) {
30
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Invalid request index. indexName and vectors array are required." });
31
+ }
32
+ const vector = getVector(mastra, vectorName);
33
+ const result = await vector.upsert(index);
34
+ return { ids: result };
35
+ } catch (error) {
36
+ return chunkPZQDCRPV_cjs.handleError(error, "Error upserting vectors");
37
+ }
38
+ }
39
+ async function createIndex({
40
+ mastra,
41
+ vectorName,
42
+ index
43
+ }) {
44
+ try {
45
+ const { indexName, dimension, metric } = index;
46
+ if (!indexName || typeof dimension !== "number" || dimension <= 0) {
47
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, {
48
+ message: "Invalid request index, indexName and positive dimension number are required."
49
+ });
50
+ }
51
+ if (metric && !["cosine", "euclidean", "dotproduct"].includes(metric)) {
52
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Invalid metric. Must be one of: cosine, euclidean, dotproduct" });
53
+ }
54
+ const vector = getVector(mastra, vectorName);
55
+ await vector.createIndex({ indexName, dimension, metric });
56
+ return { success: true };
57
+ } catch (error) {
58
+ return chunkPZQDCRPV_cjs.handleError(error, "Error creating index");
59
+ }
60
+ }
61
+ async function queryVectors({
62
+ mastra,
63
+ vectorName,
64
+ query
65
+ }) {
66
+ try {
67
+ if (!query?.indexName || !query?.queryVector || !Array.isArray(query.queryVector)) {
68
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Invalid request query. indexName and queryVector array are required." });
69
+ }
70
+ const vector = getVector(mastra, vectorName);
71
+ const results = await vector.query(query);
72
+ return results;
73
+ } catch (error) {
74
+ return chunkPZQDCRPV_cjs.handleError(error, "Error querying vectors");
75
+ }
76
+ }
77
+ async function listIndexes({ mastra, vectorName }) {
78
+ try {
79
+ const vector = getVector(mastra, vectorName);
80
+ const indexes = await vector.listIndexes();
81
+ return indexes.filter(Boolean);
82
+ } catch (error) {
83
+ return chunkPZQDCRPV_cjs.handleError(error, "Error listing indexes");
84
+ }
85
+ }
86
+ async function describeIndex({
87
+ mastra,
88
+ vectorName,
89
+ indexName
90
+ }) {
91
+ try {
92
+ if (!indexName) {
93
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Index name is required" });
94
+ }
95
+ const vector = getVector(mastra, vectorName);
96
+ const stats = await vector.describeIndex({ indexName });
97
+ return {
98
+ dimension: stats.dimension,
99
+ count: stats.count,
100
+ metric: stats.metric?.toLowerCase()
101
+ };
102
+ } catch (error) {
103
+ return chunkPZQDCRPV_cjs.handleError(error, "Error describing index");
104
+ }
105
+ }
106
+ async function deleteIndex({
107
+ mastra,
108
+ vectorName,
109
+ indexName
110
+ }) {
111
+ try {
112
+ if (!indexName) {
113
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Index name is required" });
114
+ }
115
+ const vector = getVector(mastra, vectorName);
116
+ await vector.deleteIndex({ indexName });
117
+ return { success: true };
118
+ } catch (error) {
119
+ return chunkPZQDCRPV_cjs.handleError(error, "Error deleting index");
120
+ }
121
+ }
122
+
123
+ exports.createIndex = createIndex;
124
+ exports.deleteIndex = deleteIndex;
125
+ exports.describeIndex = describeIndex;
126
+ exports.listIndexes = listIndexes;
127
+ exports.queryVectors = queryVectors;
128
+ exports.upsertVectors = upsertVectors;
129
+ exports.vector_exports = vector_exports;
@@ -0,0 +1,514 @@
1
+ 'use strict';
2
+
3
+ var chunkLI436ITD_cjs = require('./chunk-LI436ITD.cjs');
4
+ var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
5
+ var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
6
+ var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
7
+ var web = require('stream/web');
8
+
9
+ // src/server/handlers/workflows.ts
10
+ var workflows_exports = {};
11
+ chunk75ZPJI57_cjs.__export(workflows_exports, {
12
+ cancelWorkflowRunHandler: () => cancelWorkflowRunHandler,
13
+ createWorkflowRunHandler: () => createWorkflowRunHandler,
14
+ getWorkflowByIdHandler: () => getWorkflowByIdHandler,
15
+ getWorkflowRunByIdHandler: () => getWorkflowRunByIdHandler,
16
+ getWorkflowRunExecutionResultHandler: () => getWorkflowRunExecutionResultHandler,
17
+ getWorkflowRunsHandler: () => getWorkflowRunsHandler,
18
+ getWorkflowsHandler: () => getWorkflowsHandler,
19
+ resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
20
+ resumeWorkflowHandler: () => resumeWorkflowHandler,
21
+ sendWorkflowRunEventHandler: () => sendWorkflowRunEventHandler,
22
+ startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
23
+ startWorkflowRunHandler: () => startWorkflowRunHandler,
24
+ streamWorkflowHandler: () => streamWorkflowHandler,
25
+ watchWorkflowHandler: () => watchWorkflowHandler
26
+ });
27
+ function getSteps(steps, path) {
28
+ return Object.entries(steps).reduce((acc, [key, step]) => {
29
+ const fullKey = path ? `${path}.${key}` : key;
30
+ acc[fullKey] = {
31
+ id: step.id,
32
+ description: step.description,
33
+ inputSchema: step.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.inputSchema)) : void 0,
34
+ outputSchema: step.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.outputSchema)) : void 0,
35
+ resumeSchema: step.resumeSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.resumeSchema)) : void 0,
36
+ suspendSchema: step.suspendSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.suspendSchema)) : void 0,
37
+ isWorkflow: step.component === "WORKFLOW"
38
+ };
39
+ if (step.component === "WORKFLOW" && step.steps) {
40
+ const nestedSteps = getSteps(step.steps, fullKey) || {};
41
+ acc = { ...acc, ...nestedSteps };
42
+ }
43
+ return acc;
44
+ }, {});
45
+ }
46
+ async function getWorkflowsHandler({ mastra }) {
47
+ try {
48
+ const workflows = mastra.getWorkflows({ serialized: false });
49
+ const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
50
+ acc[key] = {
51
+ name: workflow.name,
52
+ description: workflow.description,
53
+ steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
54
+ acc2[key2] = {
55
+ id: step.id,
56
+ description: step.description,
57
+ inputSchema: step.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.inputSchema)) : void 0,
58
+ outputSchema: step.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.outputSchema)) : void 0,
59
+ resumeSchema: step.resumeSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.resumeSchema)) : void 0,
60
+ suspendSchema: step.suspendSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.suspendSchema)) : void 0
61
+ };
62
+ return acc2;
63
+ }, {}),
64
+ allSteps: getSteps(workflow.steps) || {},
65
+ stepGraph: workflow.serializedStepGraph,
66
+ inputSchema: workflow.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(workflow.inputSchema)) : void 0,
67
+ outputSchema: workflow.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(workflow.outputSchema)) : void 0
68
+ };
69
+ return acc;
70
+ }, {});
71
+ return _workflows;
72
+ } catch (error) {
73
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting workflows");
74
+ }
75
+ }
76
+ async function getWorkflowsFromSystem({ mastra, workflowId }) {
77
+ const logger = mastra.getLogger();
78
+ if (!workflowId) {
79
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
80
+ }
81
+ let workflow;
82
+ try {
83
+ workflow = mastra.getWorkflow(workflowId);
84
+ } catch (error) {
85
+ logger.debug("Error getting workflow, searching agents for workflow", error);
86
+ }
87
+ if (!workflow) {
88
+ logger.debug("Workflow not found, searching agents for workflow", { workflowId });
89
+ const agents = mastra.getAgents();
90
+ if (Object.keys(agents || {}).length) {
91
+ for (const [_, agent] of Object.entries(agents)) {
92
+ try {
93
+ const workflows = await agent.getWorkflows();
94
+ if (workflows[workflowId]) {
95
+ workflow = workflows[workflowId];
96
+ break;
97
+ }
98
+ break;
99
+ } catch (error) {
100
+ logger.debug("Error getting workflow from agent", error);
101
+ }
102
+ }
103
+ }
104
+ }
105
+ if (!workflow) {
106
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
107
+ }
108
+ return { workflow };
109
+ }
110
+ async function getWorkflowByIdHandler({ mastra, workflowId }) {
111
+ try {
112
+ if (!workflowId) {
113
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
114
+ }
115
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
116
+ if (!workflow) {
117
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
118
+ }
119
+ return {
120
+ steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
121
+ acc[key] = {
122
+ id: step.id,
123
+ description: step.description,
124
+ inputSchema: step.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.inputSchema)) : void 0,
125
+ outputSchema: step.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.outputSchema)) : void 0,
126
+ resumeSchema: step.resumeSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.resumeSchema)) : void 0,
127
+ suspendSchema: step.suspendSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(step.suspendSchema)) : void 0
128
+ };
129
+ return acc;
130
+ }, {}),
131
+ allSteps: getSteps(workflow.steps) || {},
132
+ name: workflow.name,
133
+ description: workflow.description,
134
+ stepGraph: workflow.serializedStepGraph,
135
+ inputSchema: workflow.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(workflow.inputSchema)) : void 0,
136
+ outputSchema: workflow.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(workflow.outputSchema)) : void 0
137
+ };
138
+ } catch (error) {
139
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting workflow");
140
+ }
141
+ }
142
+ async function getWorkflowRunByIdHandler({
143
+ mastra,
144
+ workflowId,
145
+ runId
146
+ }) {
147
+ try {
148
+ if (!workflowId) {
149
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
150
+ }
151
+ if (!runId) {
152
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Run ID is required" });
153
+ }
154
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
155
+ if (!workflow) {
156
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
157
+ }
158
+ const run = await workflow.getWorkflowRunById(runId);
159
+ if (!run) {
160
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
161
+ }
162
+ return run;
163
+ } catch (error) {
164
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting workflow run");
165
+ }
166
+ }
167
+ async function getWorkflowRunExecutionResultHandler({
168
+ mastra,
169
+ workflowId,
170
+ runId
171
+ }) {
172
+ try {
173
+ if (!workflowId) {
174
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
175
+ }
176
+ if (!runId) {
177
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Run ID is required" });
178
+ }
179
+ const workflow = mastra.getWorkflow(workflowId);
180
+ if (!workflow) {
181
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
182
+ }
183
+ const executionResult = await workflow.getWorkflowRunExecutionResult(runId);
184
+ if (!executionResult) {
185
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run execution result not found" });
186
+ }
187
+ return executionResult;
188
+ } catch (error) {
189
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting workflow run execution result");
190
+ }
191
+ }
192
+ async function createWorkflowRunHandler({
193
+ mastra,
194
+ workflowId,
195
+ runId: prevRunId
196
+ }) {
197
+ try {
198
+ if (!workflowId) {
199
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
200
+ }
201
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
202
+ if (!workflow) {
203
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
204
+ }
205
+ const run = await workflow.createRunAsync({ runId: prevRunId });
206
+ return { runId: run.runId };
207
+ } catch (error) {
208
+ return chunkPZQDCRPV_cjs.handleError(error, "Error creating workflow run");
209
+ }
210
+ }
211
+ async function startAsyncWorkflowHandler({
212
+ mastra,
213
+ runtimeContext,
214
+ workflowId,
215
+ runId,
216
+ inputData
217
+ }) {
218
+ try {
219
+ if (!workflowId) {
220
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
221
+ }
222
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
223
+ if (!workflow) {
224
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
225
+ }
226
+ const _run = await workflow.createRunAsync({ runId });
227
+ const result = await _run.start({
228
+ inputData,
229
+ runtimeContext
230
+ });
231
+ return result;
232
+ } catch (error) {
233
+ return chunkPZQDCRPV_cjs.handleError(error, "Error starting async workflow");
234
+ }
235
+ }
236
+ async function startWorkflowRunHandler({
237
+ mastra,
238
+ runtimeContext,
239
+ workflowId,
240
+ runId,
241
+ inputData
242
+ }) {
243
+ try {
244
+ if (!workflowId) {
245
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
246
+ }
247
+ if (!runId) {
248
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to start run" });
249
+ }
250
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
251
+ if (!workflow) {
252
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
253
+ }
254
+ const run = await workflow.getWorkflowRunById(runId);
255
+ if (!run) {
256
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
257
+ }
258
+ const _run = await workflow.createRunAsync({ runId });
259
+ void _run.start({
260
+ inputData,
261
+ runtimeContext
262
+ });
263
+ return { message: "Workflow run started" };
264
+ } catch (e) {
265
+ return chunkPZQDCRPV_cjs.handleError(e, "Error starting workflow run");
266
+ }
267
+ }
268
+ async function watchWorkflowHandler({
269
+ mastra,
270
+ workflowId,
271
+ runId
272
+ }) {
273
+ try {
274
+ if (!workflowId) {
275
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
276
+ }
277
+ if (!runId) {
278
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to watch workflow" });
279
+ }
280
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
281
+ if (!workflow) {
282
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
283
+ }
284
+ const run = await workflow.getWorkflowRunById(runId);
285
+ if (!run) {
286
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
287
+ }
288
+ const _run = await workflow.createRunAsync({ runId });
289
+ let unwatch;
290
+ let asyncRef = null;
291
+ const stream = new web.ReadableStream({
292
+ start(controller) {
293
+ unwatch = _run.watch(({ type, payload, eventTimestamp }) => {
294
+ controller.enqueue(JSON.stringify({ type, payload, eventTimestamp, runId }));
295
+ if (asyncRef) {
296
+ clearImmediate(asyncRef);
297
+ asyncRef = null;
298
+ }
299
+ asyncRef = setImmediate(async () => {
300
+ const runDone = payload.workflowState.status !== "running";
301
+ if (runDone) {
302
+ controller.close();
303
+ unwatch?.();
304
+ }
305
+ });
306
+ });
307
+ },
308
+ cancel() {
309
+ unwatch?.();
310
+ }
311
+ });
312
+ return stream;
313
+ } catch (error) {
314
+ return chunkPZQDCRPV_cjs.handleError(error, "Error watching workflow");
315
+ }
316
+ }
317
+ async function streamWorkflowHandler({
318
+ mastra,
319
+ runtimeContext,
320
+ workflowId,
321
+ runId,
322
+ inputData
323
+ }) {
324
+ try {
325
+ if (!workflowId) {
326
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
327
+ }
328
+ if (!runId) {
329
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to resume workflow" });
330
+ }
331
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
332
+ if (!workflow) {
333
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
334
+ }
335
+ const run = await workflow.createRunAsync({ runId });
336
+ const result = run.stream({
337
+ inputData,
338
+ runtimeContext
339
+ });
340
+ return result;
341
+ } catch (error) {
342
+ return chunkPZQDCRPV_cjs.handleError(error, "Error executing workflow");
343
+ }
344
+ }
345
+ async function resumeAsyncWorkflowHandler({
346
+ mastra,
347
+ workflowId,
348
+ runId,
349
+ body,
350
+ runtimeContext
351
+ }) {
352
+ try {
353
+ if (!workflowId) {
354
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
355
+ }
356
+ if (!runId) {
357
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to resume workflow" });
358
+ }
359
+ if (!body.step) {
360
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "step required to resume workflow" });
361
+ }
362
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
363
+ if (!workflow) {
364
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
365
+ }
366
+ const run = await workflow.getWorkflowRunById(runId);
367
+ if (!run) {
368
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
369
+ }
370
+ const _run = await workflow.createRunAsync({ runId });
371
+ const result = await _run.resume({
372
+ step: body.step,
373
+ resumeData: body.resumeData,
374
+ runtimeContext
375
+ });
376
+ return result;
377
+ } catch (error) {
378
+ return chunkPZQDCRPV_cjs.handleError(error, "Error resuming workflow step");
379
+ }
380
+ }
381
+ async function resumeWorkflowHandler({
382
+ mastra,
383
+ workflowId,
384
+ runId,
385
+ body,
386
+ runtimeContext
387
+ }) {
388
+ try {
389
+ if (!workflowId) {
390
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
391
+ }
392
+ if (!runId) {
393
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to resume workflow" });
394
+ }
395
+ if (!body.step) {
396
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "step required to resume workflow" });
397
+ }
398
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
399
+ if (!workflow) {
400
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
401
+ }
402
+ const run = await workflow.getWorkflowRunById(runId);
403
+ if (!run) {
404
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
405
+ }
406
+ const _run = await workflow.createRunAsync({ runId });
407
+ void _run.resume({
408
+ step: body.step,
409
+ resumeData: body.resumeData,
410
+ runtimeContext
411
+ });
412
+ return { message: "Workflow run resumed" };
413
+ } catch (error) {
414
+ return chunkPZQDCRPV_cjs.handleError(error, "Error resuming workflow");
415
+ }
416
+ }
417
+ async function getWorkflowRunsHandler({
418
+ mastra,
419
+ workflowId,
420
+ fromDate,
421
+ toDate,
422
+ limit,
423
+ offset,
424
+ resourceId
425
+ }) {
426
+ try {
427
+ if (!workflowId) {
428
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
429
+ }
430
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
431
+ if (!workflow) {
432
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
433
+ }
434
+ const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
435
+ runs: [],
436
+ total: 0
437
+ };
438
+ return workflowRuns;
439
+ } catch (error) {
440
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting workflow runs");
441
+ }
442
+ }
443
+ async function cancelWorkflowRunHandler({
444
+ mastra,
445
+ workflowId,
446
+ runId
447
+ }) {
448
+ try {
449
+ if (!workflowId) {
450
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
451
+ }
452
+ if (!runId) {
453
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to cancel workflow run" });
454
+ }
455
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
456
+ if (!workflow) {
457
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
458
+ }
459
+ const run = await workflow.getWorkflowRunById(runId);
460
+ if (!run) {
461
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
462
+ }
463
+ const _run = await workflow.createRunAsync({ runId });
464
+ await _run.cancel();
465
+ return { message: "Workflow run cancelled" };
466
+ } catch (error) {
467
+ return chunkPZQDCRPV_cjs.handleError(error, "Error canceling workflow run");
468
+ }
469
+ }
470
+ async function sendWorkflowRunEventHandler({
471
+ mastra,
472
+ workflowId,
473
+ runId,
474
+ event,
475
+ data
476
+ }) {
477
+ try {
478
+ if (!workflowId) {
479
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
480
+ }
481
+ if (!runId) {
482
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to send workflow run event" });
483
+ }
484
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
485
+ if (!workflow) {
486
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
487
+ }
488
+ const run = await workflow.getWorkflowRunById(runId);
489
+ if (!run) {
490
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
491
+ }
492
+ const _run = await workflow.createRunAsync({ runId });
493
+ await _run.sendEvent(event, data);
494
+ return { message: "Workflow run event sent" };
495
+ } catch (error) {
496
+ return chunkPZQDCRPV_cjs.handleError(error, "Error sending workflow run event");
497
+ }
498
+ }
499
+
500
+ exports.cancelWorkflowRunHandler = cancelWorkflowRunHandler;
501
+ exports.createWorkflowRunHandler = createWorkflowRunHandler;
502
+ exports.getWorkflowByIdHandler = getWorkflowByIdHandler;
503
+ exports.getWorkflowRunByIdHandler = getWorkflowRunByIdHandler;
504
+ exports.getWorkflowRunExecutionResultHandler = getWorkflowRunExecutionResultHandler;
505
+ exports.getWorkflowRunsHandler = getWorkflowRunsHandler;
506
+ exports.getWorkflowsHandler = getWorkflowsHandler;
507
+ exports.resumeAsyncWorkflowHandler = resumeAsyncWorkflowHandler;
508
+ exports.resumeWorkflowHandler = resumeWorkflowHandler;
509
+ exports.sendWorkflowRunEventHandler = sendWorkflowRunEventHandler;
510
+ exports.startAsyncWorkflowHandler = startAsyncWorkflowHandler;
511
+ exports.startWorkflowRunHandler = startWorkflowRunHandler;
512
+ exports.streamWorkflowHandler = streamWorkflowHandler;
513
+ exports.watchWorkflowHandler = watchWorkflowHandler;
514
+ exports.workflows_exports = workflows_exports;