@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,37 @@
1
+ 'use strict';
2
+
3
+ // src/server/http-exception.ts
4
+ var HTTPException = class extends Error {
5
+ res;
6
+ status;
7
+ /**
8
+ * Creates an instance of `HTTPException`.
9
+ * @param status - HTTP status code for the exception. Defaults to 500.
10
+ * @param options - Additional options for the exception.
11
+ */
12
+ constructor(status = 500, options) {
13
+ super(options?.message, { cause: options?.cause });
14
+ this.res = options?.res;
15
+ this.status = status;
16
+ this.stack = options?.stack || this.stack;
17
+ }
18
+ /**
19
+ * Returns the response object associated with the exception.
20
+ * If a response object is not provided, a new response is created with the error message and status code.
21
+ * @returns The response object.
22
+ */
23
+ getResponse() {
24
+ if (this.res) {
25
+ const newResponse = new Response(this.res.body, {
26
+ status: this.status,
27
+ headers: this.res.headers
28
+ });
29
+ return newResponse;
30
+ }
31
+ return new Response(this.message, {
32
+ status: this.status
33
+ });
34
+ }
35
+ };
36
+
37
+ exports.HTTPException = HTTPException;
@@ -0,0 +1,148 @@
1
+ 'use strict';
2
+
3
+ var chunkCCGRCYWJ_cjs = require('./chunk-CCGRCYWJ.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
+
8
+ // src/server/handlers/network.ts
9
+ var network_exports = {};
10
+ chunk75ZPJI57_cjs.__export(network_exports, {
11
+ generateHandler: () => generateHandler,
12
+ getNetworkByIdHandler: () => getNetworkByIdHandler,
13
+ getNetworksHandler: () => getNetworksHandler,
14
+ streamGenerateHandler: () => streamGenerateHandler
15
+ });
16
+ async function getNetworksHandler({
17
+ mastra,
18
+ runtimeContext
19
+ }) {
20
+ try {
21
+ const networks = mastra.getNetworks();
22
+ const serializedNetworks = await Promise.all(
23
+ networks.map(async (network) => {
24
+ const routingAgent = network.getRoutingAgent();
25
+ const routingLLM = await routingAgent.getLLM({ runtimeContext });
26
+ const agents = network.getAgents();
27
+ return {
28
+ id: network.formatAgentId(routingAgent.name),
29
+ name: routingAgent.name,
30
+ instructions: routingAgent.instructions,
31
+ agents: await Promise.all(
32
+ agents.map(async (agent) => {
33
+ const llm = await agent.getLLM({ runtimeContext });
34
+ return {
35
+ name: agent.name,
36
+ provider: llm?.getProvider(),
37
+ modelId: llm?.getModelId()
38
+ };
39
+ })
40
+ ),
41
+ routingModel: {
42
+ provider: routingLLM?.getProvider(),
43
+ modelId: routingLLM?.getModelId()
44
+ }
45
+ };
46
+ })
47
+ );
48
+ return serializedNetworks;
49
+ } catch (error) {
50
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting networks");
51
+ }
52
+ }
53
+ async function getNetworkByIdHandler({
54
+ mastra,
55
+ networkId,
56
+ runtimeContext
57
+ }) {
58
+ try {
59
+ const networks = mastra.getNetworks();
60
+ const network = networks.find((network2) => {
61
+ const routingAgent2 = network2.getRoutingAgent();
62
+ return network2.formatAgentId(routingAgent2.name) === networkId;
63
+ });
64
+ if (!network) {
65
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Network not found" });
66
+ }
67
+ const routingAgent = network.getRoutingAgent();
68
+ const routingLLM = await routingAgent.getLLM({ runtimeContext });
69
+ const agents = network.getAgents();
70
+ const serializedNetwork = {
71
+ id: network.formatAgentId(routingAgent.name),
72
+ name: routingAgent.name,
73
+ instructions: routingAgent.instructions,
74
+ agents: await Promise.all(
75
+ agents.map(async (agent) => {
76
+ const llm = await agent.getLLM({ runtimeContext });
77
+ return {
78
+ name: agent.name,
79
+ provider: llm?.getProvider(),
80
+ modelId: llm?.getModelId()
81
+ };
82
+ })
83
+ ),
84
+ routingModel: {
85
+ provider: routingLLM?.getProvider(),
86
+ modelId: routingLLM?.getModelId()
87
+ }
88
+ };
89
+ return serializedNetwork;
90
+ } catch (error) {
91
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting network by ID");
92
+ }
93
+ }
94
+ async function generateHandler({
95
+ mastra,
96
+ runtimeContext,
97
+ networkId,
98
+ body
99
+ }) {
100
+ try {
101
+ const network = mastra.getNetwork(networkId);
102
+ if (!network) {
103
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Network not found" });
104
+ }
105
+ chunkCCGRCYWJ_cjs.validateBody({ messages: body.messages });
106
+ const { messages, ...rest } = body;
107
+ const result = await network.generate(messages, { ...rest, runtimeContext });
108
+ return result;
109
+ } catch (error) {
110
+ return chunkPZQDCRPV_cjs.handleError(error, "Error generating from network");
111
+ }
112
+ }
113
+ async function streamGenerateHandler({
114
+ mastra,
115
+ networkId,
116
+ body,
117
+ runtimeContext
118
+ }) {
119
+ try {
120
+ const network = mastra.getNetwork(networkId);
121
+ if (!network) {
122
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Network not found" });
123
+ }
124
+ chunkCCGRCYWJ_cjs.validateBody({ messages: body.messages });
125
+ const { messages, output, ...rest } = body;
126
+ const streamResult = await network.stream(messages, {
127
+ output,
128
+ ...rest,
129
+ runtimeContext
130
+ });
131
+ const streamResponse = output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
132
+ sendUsage: true,
133
+ sendReasoning: true,
134
+ getErrorMessage: (error) => {
135
+ return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
136
+ }
137
+ });
138
+ return streamResponse;
139
+ } catch (error) {
140
+ return chunkPZQDCRPV_cjs.handleError(error, "Error streaming from network");
141
+ }
142
+ }
143
+
144
+ exports.generateHandler = generateHandler;
145
+ exports.getNetworkByIdHandler = getNetworkByIdHandler;
146
+ exports.getNetworksHandler = getNetworksHandler;
147
+ exports.network_exports = network_exports;
148
+ exports.streamGenerateHandler = streamGenerateHandler;
@@ -0,0 +1,81 @@
1
+ import { validateBody } from './chunk-RSEO4XPX.js';
2
+ import { handleError } from './chunk-LF7P5PLR.js';
3
+ import { __export } from './chunk-MLKGABMK.js';
4
+
5
+ // src/server/handlers/logs.ts
6
+ var logs_exports = {};
7
+ __export(logs_exports, {
8
+ getLogTransports: () => getLogTransports,
9
+ getLogsByRunIdHandler: () => getLogsByRunIdHandler,
10
+ getLogsHandler: () => getLogsHandler
11
+ });
12
+ async function getLogsHandler({
13
+ mastra,
14
+ transportId,
15
+ params
16
+ }) {
17
+ try {
18
+ validateBody({ transportId });
19
+ const { fromDate, toDate, logLevel, filters: _filters, page, perPage } = params || {};
20
+ const filters = _filters ? Object.fromEntries(
21
+ (Array.isArray(_filters) ? _filters : [_filters]).map((attr) => {
22
+ const [key, value] = attr.split(":");
23
+ return [key, value];
24
+ })
25
+ ) : void 0;
26
+ const logs = await mastra.getLogs(transportId, {
27
+ fromDate,
28
+ toDate,
29
+ logLevel,
30
+ filters,
31
+ page: page ? Number(page) : void 0,
32
+ perPage: perPage ? Number(perPage) : void 0
33
+ });
34
+ return logs;
35
+ } catch (error) {
36
+ return handleError(error, "Error getting logs");
37
+ }
38
+ }
39
+ async function getLogsByRunIdHandler({
40
+ mastra,
41
+ runId,
42
+ transportId,
43
+ params
44
+ }) {
45
+ try {
46
+ validateBody({ runId, transportId });
47
+ const { fromDate, toDate, logLevel, filters: _filters, page, perPage } = params || {};
48
+ const filters = _filters ? Object.fromEntries(
49
+ (Array.isArray(_filters) ? _filters : [_filters]).map((attr) => {
50
+ const [key, value] = attr.split(":");
51
+ return [key, value];
52
+ })
53
+ ) : void 0;
54
+ const logs = await mastra.getLogsByRunId({
55
+ runId,
56
+ transportId,
57
+ fromDate,
58
+ toDate,
59
+ logLevel,
60
+ filters,
61
+ page: page ? Number(page) : void 0,
62
+ perPage: perPage ? Number(perPage) : void 0
63
+ });
64
+ return logs;
65
+ } catch (error) {
66
+ return handleError(error, "Error getting logs by run ID");
67
+ }
68
+ }
69
+ async function getLogTransports({ mastra }) {
70
+ try {
71
+ const logger = mastra.getLogger();
72
+ const transports = logger.getTransports();
73
+ return {
74
+ transports: transports ? [...transports.keys()] : []
75
+ };
76
+ } catch (error) {
77
+ return handleError(error, "Error getting log Transports");
78
+ }
79
+ }
80
+
81
+ export { getLogTransports, getLogsByRunIdHandler, getLogsHandler, logs_exports };
@@ -0,0 +1,320 @@
1
+ import { stringify, esm_default } from './chunk-MEGCYGBU.js';
2
+ import { handleError } from './chunk-LF7P5PLR.js';
3
+ import { HTTPException } from './chunk-LCM566I4.js';
4
+ import { __export } from './chunk-MLKGABMK.js';
5
+ import { ReadableStream } from 'stream/web';
6
+
7
+ // src/server/handlers/legacyWorkflows.ts
8
+ var legacyWorkflows_exports = {};
9
+ __export(legacyWorkflows_exports, {
10
+ createLegacyWorkflowRunHandler: () => createLegacyWorkflowRunHandler,
11
+ getLegacyWorkflowByIdHandler: () => getLegacyWorkflowByIdHandler,
12
+ getLegacyWorkflowRunHandler: () => getLegacyWorkflowRunHandler,
13
+ getLegacyWorkflowRunsHandler: () => getLegacyWorkflowRunsHandler,
14
+ getLegacyWorkflowsHandler: () => getLegacyWorkflowsHandler,
15
+ resumeAsyncLegacyWorkflowHandler: () => resumeAsyncLegacyWorkflowHandler,
16
+ resumeLegacyWorkflowHandler: () => resumeLegacyWorkflowHandler,
17
+ startAsyncLegacyWorkflowHandler: () => startAsyncLegacyWorkflowHandler,
18
+ startLegacyWorkflowRunHandler: () => startLegacyWorkflowRunHandler,
19
+ watchLegacyWorkflowHandler: () => watchLegacyWorkflowHandler
20
+ });
21
+ async function getLegacyWorkflowsHandler({ mastra }) {
22
+ try {
23
+ const workflows = mastra.legacy_getWorkflows({ serialized: false });
24
+ const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
25
+ if (workflow.isNested) return acc;
26
+ acc[key] = {
27
+ stepGraph: workflow.stepGraph,
28
+ stepSubscriberGraph: workflow.stepSubscriberGraph,
29
+ serializedStepGraph: workflow.serializedStepGraph,
30
+ serializedStepSubscriberGraph: workflow.serializedStepSubscriberGraph,
31
+ name: workflow.name,
32
+ triggerSchema: workflow.triggerSchema ? stringify(esm_default(workflow.triggerSchema)) : void 0,
33
+ steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
34
+ const _step = step;
35
+ acc2[key2] = {
36
+ id: _step.id,
37
+ description: _step.description,
38
+ workflowId: _step.workflowId,
39
+ inputSchema: _step.inputSchema ? stringify(esm_default(_step.inputSchema)) : void 0,
40
+ outputSchema: _step.outputSchema ? stringify(esm_default(_step.outputSchema)) : void 0
41
+ };
42
+ return acc2;
43
+ }, {})
44
+ };
45
+ return acc;
46
+ }, {});
47
+ return _workflows;
48
+ } catch (error) {
49
+ return handleError(error, "error getting workflows");
50
+ }
51
+ }
52
+ async function getLegacyWorkflowByIdHandler({ mastra, workflowId }) {
53
+ try {
54
+ if (!workflowId) {
55
+ throw new HTTPException(400, { message: "Workflow ID is required" });
56
+ }
57
+ const workflow = mastra.legacy_getWorkflow(workflowId);
58
+ if (!workflow) {
59
+ throw new HTTPException(404, { message: "Workflow not found" });
60
+ }
61
+ return {
62
+ stepGraph: workflow.stepGraph,
63
+ stepSubscriberGraph: workflow.stepSubscriberGraph,
64
+ serializedStepGraph: workflow.serializedStepGraph,
65
+ serializedStepSubscriberGraph: workflow.serializedStepSubscriberGraph,
66
+ name: workflow.name,
67
+ triggerSchema: workflow.triggerSchema ? stringify(esm_default(workflow.triggerSchema)) : void 0,
68
+ steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
69
+ const _step = step;
70
+ acc[key] = {
71
+ id: _step.id,
72
+ description: _step.description,
73
+ workflowId: _step.workflowId,
74
+ inputSchema: _step.inputSchema ? stringify(esm_default(_step.inputSchema)) : void 0,
75
+ outputSchema: _step.outputSchema ? stringify(esm_default(_step.outputSchema)) : void 0
76
+ };
77
+ return acc;
78
+ }, {})
79
+ };
80
+ } catch (error) {
81
+ return handleError(error, "error getting workflow by id");
82
+ }
83
+ }
84
+ async function startAsyncLegacyWorkflowHandler({
85
+ mastra,
86
+ runtimeContext,
87
+ workflowId,
88
+ runId,
89
+ triggerData
90
+ }) {
91
+ try {
92
+ if (!workflowId) {
93
+ throw new HTTPException(400, { message: "Workflow ID is required" });
94
+ }
95
+ const workflow = mastra.legacy_getWorkflow(workflowId);
96
+ if (!workflow) {
97
+ throw new HTTPException(404, { message: "Workflow not found" });
98
+ }
99
+ if (!runId) {
100
+ const newRun = workflow.createRun();
101
+ const result2 = await newRun.start({
102
+ triggerData,
103
+ runtimeContext
104
+ });
105
+ return result2;
106
+ }
107
+ const run = workflow.getMemoryRun(runId);
108
+ if (!run) {
109
+ throw new HTTPException(404, { message: "Workflow run not found" });
110
+ }
111
+ const result = await run.start({
112
+ triggerData,
113
+ runtimeContext
114
+ });
115
+ return result;
116
+ } catch (error) {
117
+ return handleError(error, "error starting workflow");
118
+ }
119
+ }
120
+ async function getLegacyWorkflowRunHandler({
121
+ mastra,
122
+ workflowId,
123
+ runId
124
+ }) {
125
+ try {
126
+ if (!workflowId) {
127
+ throw new HTTPException(400, { message: "Workflow ID is required" });
128
+ }
129
+ if (!runId) {
130
+ throw new HTTPException(400, { message: "Run ID is required" });
131
+ }
132
+ const workflow = mastra.legacy_getWorkflow(workflowId);
133
+ if (!workflow) {
134
+ throw new HTTPException(404, { message: "Workflow not found" });
135
+ }
136
+ const run = await workflow.getRun(runId);
137
+ if (!run) {
138
+ throw new HTTPException(404, { message: "Workflow run not found" });
139
+ }
140
+ return run;
141
+ } catch (error) {
142
+ return handleError(error, "error getting workflow run");
143
+ }
144
+ }
145
+ async function createLegacyWorkflowRunHandler({
146
+ mastra,
147
+ workflowId,
148
+ runId: prevRunId
149
+ }) {
150
+ try {
151
+ if (!workflowId) {
152
+ throw new HTTPException(400, { message: "Workflow ID is required" });
153
+ }
154
+ const workflow = mastra.legacy_getWorkflow(workflowId);
155
+ if (!workflow) {
156
+ throw new HTTPException(404, { message: "Workflow not found" });
157
+ }
158
+ const newRun = workflow.createRun({ runId: prevRunId });
159
+ return { runId: newRun.runId };
160
+ } catch (error) {
161
+ return handleError(error, "error creating workflow run");
162
+ }
163
+ }
164
+ async function startLegacyWorkflowRunHandler({
165
+ mastra,
166
+ runtimeContext,
167
+ workflowId,
168
+ runId,
169
+ triggerData
170
+ }) {
171
+ try {
172
+ if (!workflowId) {
173
+ throw new HTTPException(400, { message: "Workflow ID is required" });
174
+ }
175
+ if (!runId) {
176
+ throw new HTTPException(400, { message: "runId required to start run" });
177
+ }
178
+ const workflow = mastra.legacy_getWorkflow(workflowId);
179
+ const run = workflow.getMemoryRun(runId);
180
+ if (!run) {
181
+ throw new HTTPException(404, { message: "Workflow run not found" });
182
+ }
183
+ void run.start({
184
+ triggerData,
185
+ runtimeContext
186
+ });
187
+ return { message: "Workflow run started" };
188
+ } catch (e) {
189
+ return handleError(e, "Error starting workflow run");
190
+ }
191
+ }
192
+ async function watchLegacyWorkflowHandler({
193
+ mastra,
194
+ workflowId,
195
+ runId
196
+ }) {
197
+ try {
198
+ if (!workflowId) {
199
+ throw new HTTPException(400, { message: "Workflow ID is required" });
200
+ }
201
+ if (!runId) {
202
+ throw new HTTPException(400, { message: "runId required to watch workflow" });
203
+ }
204
+ const workflow = mastra.legacy_getWorkflow(workflowId);
205
+ const run = workflow.getMemoryRun(runId);
206
+ if (!run) {
207
+ throw new HTTPException(404, { message: "Workflow run not found" });
208
+ }
209
+ let unwatch;
210
+ let asyncRef = null;
211
+ const stream = new ReadableStream({
212
+ start(controller) {
213
+ unwatch = run.watch(({ activePaths, runId: runId2, timestamp, results }) => {
214
+ const activePathsObj = Object.fromEntries(activePaths);
215
+ controller.enqueue(JSON.stringify({ activePaths: activePathsObj, runId: runId2, timestamp, results }));
216
+ if (asyncRef) {
217
+ clearImmediate(asyncRef);
218
+ asyncRef = null;
219
+ }
220
+ asyncRef = setImmediate(() => {
221
+ const runDone = Object.values(activePathsObj).every((value) => value.status !== "executing");
222
+ if (runDone) {
223
+ controller.close();
224
+ unwatch?.();
225
+ }
226
+ });
227
+ });
228
+ },
229
+ cancel() {
230
+ unwatch?.();
231
+ }
232
+ });
233
+ return stream;
234
+ } catch (error) {
235
+ return handleError(error, "Error watching workflow");
236
+ }
237
+ }
238
+ async function resumeAsyncLegacyWorkflowHandler({
239
+ mastra,
240
+ workflowId,
241
+ runId,
242
+ body,
243
+ runtimeContext
244
+ }) {
245
+ try {
246
+ if (!workflowId) {
247
+ throw new HTTPException(400, { message: "Workflow ID is required" });
248
+ }
249
+ if (!runId) {
250
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
251
+ }
252
+ const workflow = mastra.legacy_getWorkflow(workflowId);
253
+ const run = workflow.getMemoryRun(runId);
254
+ if (!run) {
255
+ throw new HTTPException(404, { message: "Workflow run not found" });
256
+ }
257
+ const result = await run.resume({
258
+ stepId: body.stepId,
259
+ context: body.context,
260
+ runtimeContext
261
+ });
262
+ return result;
263
+ } catch (error) {
264
+ return handleError(error, "Error resuming workflow step");
265
+ }
266
+ }
267
+ async function resumeLegacyWorkflowHandler({
268
+ mastra,
269
+ workflowId,
270
+ runId,
271
+ body,
272
+ runtimeContext
273
+ }) {
274
+ try {
275
+ if (!workflowId) {
276
+ throw new HTTPException(400, { message: "Workflow ID is required" });
277
+ }
278
+ if (!runId) {
279
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
280
+ }
281
+ const workflow = mastra.legacy_getWorkflow(workflowId);
282
+ const run = workflow.getMemoryRun(runId);
283
+ if (!run) {
284
+ throw new HTTPException(404, { message: "Workflow run not found" });
285
+ }
286
+ void run.resume({
287
+ stepId: body.stepId,
288
+ context: body.context,
289
+ runtimeContext
290
+ });
291
+ return { message: "Workflow run resumed" };
292
+ } catch (error) {
293
+ return handleError(error, "Error resuming workflow");
294
+ }
295
+ }
296
+ async function getLegacyWorkflowRunsHandler({
297
+ mastra,
298
+ workflowId,
299
+ fromDate,
300
+ toDate,
301
+ limit,
302
+ offset,
303
+ resourceId
304
+ }) {
305
+ try {
306
+ if (!workflowId) {
307
+ throw new HTTPException(400, { message: "Workflow ID is required" });
308
+ }
309
+ const workflow = mastra.legacy_getWorkflow(workflowId);
310
+ const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
311
+ runs: [],
312
+ total: 0
313
+ };
314
+ return workflowRuns;
315
+ } catch (error) {
316
+ return handleError(error, "Error getting workflow runs");
317
+ }
318
+ }
319
+
320
+ export { createLegacyWorkflowRunHandler, getLegacyWorkflowByIdHandler, getLegacyWorkflowRunHandler, getLegacyWorkflowRunsHandler, getLegacyWorkflowsHandler, legacyWorkflows_exports, resumeAsyncLegacyWorkflowHandler, resumeLegacyWorkflowHandler, startAsyncLegacyWorkflowHandler, startLegacyWorkflowRunHandler, watchLegacyWorkflowHandler };
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __export = (target, all) => {
5
+ for (var name in all)
6
+ __defProp(target, name, { get: all[name], enumerable: true });
7
+ };
8
+
9
+ exports.__export = __export;