@mastra/server 0.0.0-error-handler-fix-20251020202607 → 0.0.0-export-agent-memory-from-local-studio-20251112153946

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 (179) hide show
  1. package/CHANGELOG.md +802 -3
  2. package/README.md +1 -1
  3. package/dist/{chunk-FWO7VQDC.js → chunk-2IS5WICF.js} +7079 -1524
  4. package/dist/chunk-2IS5WICF.js.map +1 -0
  5. package/dist/{chunk-SPRRK3P7.cjs → chunk-2YZH5PH6.cjs} +47 -47
  6. package/dist/chunk-2YZH5PH6.cjs.map +1 -0
  7. package/dist/{chunk-BATEJLED.js → chunk-3AMNUUZF.js} +20 -20
  8. package/dist/chunk-3AMNUUZF.js.map +1 -0
  9. package/dist/{chunk-AW5BU3RQ.js → chunk-3F52QCI4.js} +40 -40
  10. package/dist/chunk-3F52QCI4.js.map +1 -0
  11. package/dist/{chunk-OEOGYAQC.js → chunk-4JF5WXPL.js} +155 -206
  12. package/dist/chunk-4JF5WXPL.js.map +1 -0
  13. package/dist/{chunk-7NADHFD2.cjs → chunk-64ITUOXI.cjs} +2 -2
  14. package/dist/chunk-64ITUOXI.cjs.map +1 -0
  15. package/dist/{chunk-MMROOK5J.js → chunk-6QWQZI4Q.js} +2 -2
  16. package/dist/{chunk-7NADHFD2.cjs.map → chunk-6QWQZI4Q.js.map} +1 -1
  17. package/dist/{chunk-ABRFV4XP.js → chunk-73PAWDM5.js} +13 -13
  18. package/dist/chunk-73PAWDM5.js.map +1 -0
  19. package/dist/{chunk-2S4IMB6E.cjs → chunk-A24TSVEZ.cjs} +39 -39
  20. package/dist/chunk-A24TSVEZ.cjs.map +1 -0
  21. package/dist/chunk-A2NPD5N6.cjs +517 -0
  22. package/dist/chunk-A2NPD5N6.cjs.map +1 -0
  23. package/dist/{chunk-QQXMIP6C.js → chunk-B3Z6J745.js} +17 -17
  24. package/dist/chunk-B3Z6J745.js.map +1 -0
  25. package/dist/{chunk-G4PUALCE.cjs → chunk-BTWIR2B7.cjs} +4 -4
  26. package/dist/{chunk-G4PUALCE.cjs.map → chunk-BTWIR2B7.cjs.map} +1 -1
  27. package/dist/{chunk-YWOK4F5A.js → chunk-D7T74TVR.js} +4 -6
  28. package/dist/chunk-D7T74TVR.js.map +1 -0
  29. package/dist/{chunk-FHSOPERI.cjs → chunk-EHACNWDL.cjs} +221 -242
  30. package/dist/chunk-EHACNWDL.cjs.map +1 -0
  31. package/dist/{chunk-HPXAM2PG.js → chunk-FPBYKMIS.js} +13 -13
  32. package/dist/chunk-FPBYKMIS.js.map +1 -0
  33. package/dist/{chunk-3SNGNFUJ.cjs → chunk-GLAZTMX3.cjs} +37 -37
  34. package/dist/chunk-GLAZTMX3.cjs.map +1 -0
  35. package/dist/{chunk-7HDOBOGG.cjs → chunk-ID6JYDNL.cjs} +7102 -1544
  36. package/dist/chunk-ID6JYDNL.cjs.map +1 -0
  37. package/dist/{chunk-TRGAMKHX.cjs → chunk-KF3RI45U.cjs} +46 -41
  38. package/dist/chunk-KF3RI45U.cjs.map +1 -0
  39. package/dist/{chunk-TOP25AIO.cjs → chunk-KJIDZQRA.cjs} +14 -14
  40. package/dist/chunk-KJIDZQRA.cjs.map +1 -0
  41. package/dist/{chunk-MYR4PVGN.js → chunk-KWH5QBXP.js} +4 -4
  42. package/dist/{chunk-MYR4PVGN.js.map → chunk-KWH5QBXP.js.map} +1 -1
  43. package/dist/{chunk-AHB4JCIQ.js → chunk-ND5OKOMT.js} +31 -26
  44. package/dist/chunk-ND5OKOMT.js.map +1 -0
  45. package/dist/{chunk-XN74I6VW.cjs → chunk-PPMIB3FQ.cjs} +20 -20
  46. package/dist/chunk-PPMIB3FQ.cjs.map +1 -0
  47. package/dist/{chunk-XVPBGW6Y.cjs → chunk-QU6N55W6.cjs} +9 -9
  48. package/dist/{chunk-XVPBGW6Y.cjs.map → chunk-QU6N55W6.cjs.map} +1 -1
  49. package/dist/{chunk-EP3JQDPD.cjs → chunk-S54HNARD.cjs} +18 -18
  50. package/dist/{chunk-EP3JQDPD.cjs.map → chunk-S54HNARD.cjs.map} +1 -1
  51. package/dist/{chunk-SIW6CYO3.js → chunk-SHWNNZBL.js} +7 -7
  52. package/dist/{chunk-SIW6CYO3.js.map → chunk-SHWNNZBL.js.map} +1 -1
  53. package/dist/{chunk-4QCXUEAT.js → chunk-SZIFSF4T.js} +3 -3
  54. package/dist/{chunk-4QCXUEAT.js.map → chunk-SZIFSF4T.js.map} +1 -1
  55. package/dist/{chunk-FZNS32WJ.js → chunk-TOCYBDP2.js} +4 -4
  56. package/dist/{chunk-FZNS32WJ.js.map → chunk-TOCYBDP2.js.map} +1 -1
  57. package/dist/{chunk-CY4TP3FK.js → chunk-UXGQZUYZ.js} +3 -3
  58. package/dist/{chunk-CY4TP3FK.js.map → chunk-UXGQZUYZ.js.map} +1 -1
  59. package/dist/{chunk-RE4RPXT2.cjs → chunk-V5WWQN7P.cjs} +4 -4
  60. package/dist/{chunk-RE4RPXT2.cjs.map → chunk-V5WWQN7P.cjs.map} +1 -1
  61. package/dist/{chunk-VY4ENABS.cjs → chunk-W2KMU354.cjs} +4 -6
  62. package/dist/chunk-W2KMU354.cjs.map +1 -0
  63. package/dist/chunk-X3MICMI2.cjs +620 -0
  64. package/dist/chunk-X3MICMI2.cjs.map +1 -0
  65. package/dist/{chunk-OYL5TBJW.cjs → chunk-X6C7BUWN.cjs} +4 -4
  66. package/dist/{chunk-OYL5TBJW.cjs.map → chunk-X6C7BUWN.cjs.map} +1 -1
  67. package/dist/{chunk-XDAYZS6N.js → chunk-Z2O5YVHY.js} +190 -211
  68. package/dist/chunk-Z2O5YVHY.js.map +1 -0
  69. package/dist/{chunk-DB63UMTV.js → chunk-ZJ6KEY6H.js} +110 -170
  70. package/dist/chunk-ZJ6KEY6H.js.map +1 -0
  71. package/dist/server/handlers/a2a.cjs +7 -7
  72. package/dist/server/handlers/a2a.d.ts +10 -10
  73. package/dist/server/handlers/a2a.d.ts.map +1 -1
  74. package/dist/server/handlers/a2a.js +1 -1
  75. package/dist/server/handlers/agent-builder.cjs +31 -19
  76. package/dist/server/handlers/agent-builder.d.ts +38 -47
  77. package/dist/server/handlers/agent-builder.d.ts.map +1 -1
  78. package/dist/server/handlers/agent-builder.js +1 -1
  79. package/dist/server/handlers/agents.cjs +26 -26
  80. package/dist/server/handlers/agents.d.ts +44 -54
  81. package/dist/server/handlers/agents.d.ts.map +1 -1
  82. package/dist/server/handlers/agents.js +1 -1
  83. package/dist/server/handlers/error.cjs +2 -2
  84. package/dist/server/handlers/error.js +1 -1
  85. package/dist/server/handlers/logs.cjs +7 -7
  86. package/dist/server/handlers/logs.d.ts +3 -3
  87. package/dist/server/handlers/logs.d.ts.map +1 -1
  88. package/dist/server/handlers/logs.js +1 -1
  89. package/dist/server/handlers/memory.cjs +17 -25
  90. package/dist/server/handlers/memory.d.ts +28 -34
  91. package/dist/server/handlers/memory.d.ts.map +1 -1
  92. package/dist/server/handlers/memory.js +1 -1
  93. package/dist/server/handlers/observability.cjs +8 -8
  94. package/dist/server/handlers/observability.d.ts +12 -12
  95. package/dist/server/handlers/observability.d.ts.map +1 -1
  96. package/dist/server/handlers/observability.js +1 -1
  97. package/dist/server/handlers/scores.cjs +11 -11
  98. package/dist/server/handlers/scores.d.ts +24 -24
  99. package/dist/server/handlers/scores.d.ts.map +1 -1
  100. package/dist/server/handlers/scores.js +1 -1
  101. package/dist/server/handlers/tools.cjs +7 -7
  102. package/dist/server/handlers/tools.d.ts +8 -8
  103. package/dist/server/handlers/tools.d.ts.map +1 -1
  104. package/dist/server/handlers/tools.js +1 -1
  105. package/dist/server/handlers/utils.cjs +3 -3
  106. package/dist/server/handlers/utils.js +1 -1
  107. package/dist/server/handlers/vector.cjs +7 -7
  108. package/dist/server/handlers/vector.js +1 -1
  109. package/dist/server/handlers/voice.cjs +5 -5
  110. package/dist/server/handlers/voice.d.ts +6 -6
  111. package/dist/server/handlers/voice.js +1 -1
  112. package/dist/server/handlers/workflows.cjs +27 -27
  113. package/dist/server/handlers/workflows.d.ts +34 -37
  114. package/dist/server/handlers/workflows.d.ts.map +1 -1
  115. package/dist/server/handlers/workflows.js +1 -1
  116. package/dist/server/handlers.cjs +26 -36
  117. package/dist/server/handlers.d.ts +0 -2
  118. package/dist/server/handlers.d.ts.map +1 -1
  119. package/dist/server/handlers.js +11 -13
  120. package/dist/server/http-exception.d.ts +0 -5
  121. package/dist/server/http-exception.d.ts.map +1 -1
  122. package/dist/server/utils.d.ts +3 -2
  123. package/dist/server/utils.d.ts.map +1 -1
  124. package/dist/{token-53CFGXUO.cjs → token-375W3LEI.cjs} +10 -10
  125. package/dist/{token-53CFGXUO.cjs.map → token-375W3LEI.cjs.map} +1 -1
  126. package/dist/{token-WAEKDUVY.js → token-C3IMNCC4.js} +8 -8
  127. package/dist/{token-WAEKDUVY.js.map → token-C3IMNCC4.js.map} +1 -1
  128. package/dist/token-util-CV3RRG6K.cjs +9 -0
  129. package/dist/{token-util-S4A355II.cjs.map → token-util-CV3RRG6K.cjs.map} +1 -1
  130. package/dist/token-util-E5QO2RCL.js +7 -0
  131. package/dist/{token-util-LY37VCIN.js.map → token-util-E5QO2RCL.js.map} +1 -1
  132. package/package.json +11 -8
  133. package/dist/chunk-2S4IMB6E.cjs.map +0 -1
  134. package/dist/chunk-3LTO44EP.cjs +0 -570
  135. package/dist/chunk-3LTO44EP.cjs.map +0 -1
  136. package/dist/chunk-3SNGNFUJ.cjs.map +0 -1
  137. package/dist/chunk-67GYDFSB.js +0 -160
  138. package/dist/chunk-67GYDFSB.js.map +0 -1
  139. package/dist/chunk-6ZR275MD.cjs +0 -165
  140. package/dist/chunk-6ZR275MD.cjs.map +0 -1
  141. package/dist/chunk-7HDOBOGG.cjs.map +0 -1
  142. package/dist/chunk-ABRFV4XP.js.map +0 -1
  143. package/dist/chunk-AHB4JCIQ.js.map +0 -1
  144. package/dist/chunk-AW5BU3RQ.js.map +0 -1
  145. package/dist/chunk-BATEJLED.js.map +0 -1
  146. package/dist/chunk-DB63UMTV.js.map +0 -1
  147. package/dist/chunk-FHSOPERI.cjs.map +0 -1
  148. package/dist/chunk-FWO7VQDC.js.map +0 -1
  149. package/dist/chunk-HPXAM2PG.js.map +0 -1
  150. package/dist/chunk-I3C4ODGV.cjs +0 -335
  151. package/dist/chunk-I3C4ODGV.cjs.map +0 -1
  152. package/dist/chunk-LLUOPR3J.js +0 -323
  153. package/dist/chunk-LLUOPR3J.js.map +0 -1
  154. package/dist/chunk-MMROOK5J.js.map +0 -1
  155. package/dist/chunk-MQDBNHBT.cjs +0 -680
  156. package/dist/chunk-MQDBNHBT.cjs.map +0 -1
  157. package/dist/chunk-OEOGYAQC.js.map +0 -1
  158. package/dist/chunk-QQXMIP6C.js.map +0 -1
  159. package/dist/chunk-SPRRK3P7.cjs.map +0 -1
  160. package/dist/chunk-TOP25AIO.cjs.map +0 -1
  161. package/dist/chunk-TRGAMKHX.cjs.map +0 -1
  162. package/dist/chunk-VY4ENABS.cjs.map +0 -1
  163. package/dist/chunk-XDAYZS6N.js.map +0 -1
  164. package/dist/chunk-XN74I6VW.cjs.map +0 -1
  165. package/dist/chunk-YWOK4F5A.js.map +0 -1
  166. package/dist/server/handlers/legacyWorkflows.cjs +0 -48
  167. package/dist/server/handlers/legacyWorkflows.cjs.map +0 -1
  168. package/dist/server/handlers/legacyWorkflows.d.ts +0 -59
  169. package/dist/server/handlers/legacyWorkflows.d.ts.map +0 -1
  170. package/dist/server/handlers/legacyWorkflows.js +0 -3
  171. package/dist/server/handlers/legacyWorkflows.js.map +0 -1
  172. package/dist/server/handlers/telemetry.cjs +0 -20
  173. package/dist/server/handlers/telemetry.cjs.map +0 -1
  174. package/dist/server/handlers/telemetry.d.ts +0 -33
  175. package/dist/server/handlers/telemetry.d.ts.map +0 -1
  176. package/dist/server/handlers/telemetry.js +0 -3
  177. package/dist/server/handlers/telemetry.js.map +0 -1
  178. package/dist/token-util-LY37VCIN.js +0 -7
  179. package/dist/token-util-S4A355II.cjs +0 -9
@@ -1,8 +1,8 @@
1
- import { getWorkflowInfo, WorkflowRegistry } from './chunk-YWOK4F5A.js';
2
- import { handleError } from './chunk-CY4TP3FK.js';
3
- import { HTTPException } from './chunk-MMROOK5J.js';
1
+ import { getWorkflowInfo, WorkflowRegistry } from './chunk-D7T74TVR.js';
2
+ import { handleError } from './chunk-UXGQZUYZ.js';
3
+ import { HTTPException } from './chunk-6QWQZI4Q.js';
4
4
  import { __export } from './chunk-PR4QN5HX.js';
5
- import { ReadableStream, TransformStream } from 'stream/web';
5
+ import { TransformStream, ReadableStream } from 'stream/web';
6
6
 
7
7
  // src/server/handlers/workflows.ts
8
8
  var workflows_exports = {};
@@ -12,23 +12,23 @@ __export(workflows_exports, {
12
12
  getWorkflowByIdHandler: () => getWorkflowByIdHandler,
13
13
  getWorkflowRunByIdHandler: () => getWorkflowRunByIdHandler,
14
14
  getWorkflowRunExecutionResultHandler: () => getWorkflowRunExecutionResultHandler,
15
- getWorkflowRunsHandler: () => getWorkflowRunsHandler,
16
- getWorkflowsHandler: () => getWorkflowsHandler,
15
+ listWorkflowRunsHandler: () => listWorkflowRunsHandler,
16
+ listWorkflowsHandler: () => listWorkflowsHandler,
17
+ observeStreamLegacyWorkflowHandler: () => observeStreamLegacyWorkflowHandler,
17
18
  observeStreamVNextWorkflowHandler: () => observeStreamVNextWorkflowHandler,
18
19
  observeStreamWorkflowHandler: () => observeStreamWorkflowHandler,
19
20
  resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
20
21
  resumeStreamWorkflowHandler: () => resumeStreamWorkflowHandler,
21
22
  resumeWorkflowHandler: () => resumeWorkflowHandler,
22
- sendWorkflowRunEventHandler: () => sendWorkflowRunEventHandler,
23
23
  startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
24
24
  startWorkflowRunHandler: () => startWorkflowRunHandler,
25
+ streamLegacyWorkflowHandler: () => streamLegacyWorkflowHandler,
25
26
  streamVNextWorkflowHandler: () => streamVNextWorkflowHandler,
26
- streamWorkflowHandler: () => streamWorkflowHandler,
27
- watchWorkflowHandler: () => watchWorkflowHandler
27
+ streamWorkflowHandler: () => streamWorkflowHandler
28
28
  });
29
- async function getWorkflowsHandler({ mastra }) {
29
+ async function listWorkflowsHandler({ mastra }) {
30
30
  try {
31
- const workflows = mastra.getWorkflows({ serialized: false });
31
+ const workflows = mastra.listWorkflows({ serialized: false });
32
32
  const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
33
33
  acc[key] = getWorkflowInfo(workflow);
34
34
  return acc;
@@ -38,7 +38,7 @@ async function getWorkflowsHandler({ mastra }) {
38
38
  return handleError(error, "Error getting workflows");
39
39
  }
40
40
  }
41
- async function getWorkflowsFromSystem({ mastra, workflowId }) {
41
+ async function listWorkflowsFromSystem({ mastra, workflowId }) {
42
42
  const logger = mastra.getLogger();
43
43
  if (!workflowId) {
44
44
  throw new HTTPException(400, { message: "Workflow ID is required" });
@@ -47,18 +47,18 @@ async function getWorkflowsFromSystem({ mastra, workflowId }) {
47
47
  workflow = WorkflowRegistry.getWorkflow(workflowId);
48
48
  if (!workflow) {
49
49
  try {
50
- workflow = mastra.getWorkflow(workflowId);
50
+ workflow = mastra.getWorkflowById(workflowId);
51
51
  } catch (error) {
52
52
  logger.debug("Error getting workflow, searching agents for workflow", error);
53
53
  }
54
54
  }
55
55
  if (!workflow) {
56
56
  logger.debug("Workflow not found, searching agents for workflow", { workflowId });
57
- const agents = mastra.getAgents();
57
+ const agents = mastra.listAgents();
58
58
  if (Object.keys(agents || {}).length) {
59
59
  for (const [_, agent] of Object.entries(agents)) {
60
60
  try {
61
- const workflows = await agent.getWorkflows();
61
+ const workflows = await agent.listWorkflows();
62
62
  if (workflows[workflowId]) {
63
63
  workflow = workflows[workflowId];
64
64
  break;
@@ -80,7 +80,7 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
80
80
  if (!workflowId) {
81
81
  throw new HTTPException(400, { message: "Workflow ID is required" });
82
82
  }
83
- const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
83
+ const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
84
84
  if (!workflow) {
85
85
  throw new HTTPException(404, { message: "Workflow not found" });
86
86
  }
@@ -101,7 +101,7 @@ async function getWorkflowRunByIdHandler({
101
101
  if (!runId) {
102
102
  throw new HTTPException(400, { message: "Run ID is required" });
103
103
  }
104
- const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
104
+ const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
105
105
  if (!workflow) {
106
106
  throw new HTTPException(404, { message: "Workflow not found" });
107
107
  }
@@ -148,11 +148,11 @@ async function createWorkflowRunHandler({
148
148
  if (!workflowId) {
149
149
  throw new HTTPException(400, { message: "Workflow ID is required" });
150
150
  }
151
- const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
151
+ const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
152
152
  if (!workflow) {
153
153
  throw new HTTPException(404, { message: "Workflow not found" });
154
154
  }
155
- const run = await workflow.createRunAsync({ runId: prevRunId });
155
+ const run = await workflow.createRun({ runId: prevRunId });
156
156
  return { runId: run.runId };
157
157
  } catch (error) {
158
158
  return handleError(error, "Error creating workflow run");
@@ -160,7 +160,7 @@ async function createWorkflowRunHandler({
160
160
  }
161
161
  async function startAsyncWorkflowHandler({
162
162
  mastra,
163
- runtimeContext,
163
+ requestContext,
164
164
  workflowId,
165
165
  runId,
166
166
  inputData,
@@ -170,14 +170,14 @@ async function startAsyncWorkflowHandler({
170
170
  if (!workflowId) {
171
171
  throw new HTTPException(400, { message: "Workflow ID is required" });
172
172
  }
173
- const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
173
+ const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
174
174
  if (!workflow) {
175
175
  throw new HTTPException(404, { message: "Workflow not found" });
176
176
  }
177
- const _run = await workflow.createRunAsync({ runId });
177
+ const _run = await workflow.createRun({ runId });
178
178
  const result = await _run.start({
179
179
  inputData,
180
- runtimeContext,
180
+ requestContext,
181
181
  tracingOptions
182
182
  });
183
183
  return result;
@@ -187,7 +187,7 @@ async function startAsyncWorkflowHandler({
187
187
  }
188
188
  async function startWorkflowRunHandler({
189
189
  mastra,
190
- runtimeContext,
190
+ requestContext,
191
191
  workflowId,
192
192
  runId,
193
193
  inputData,
@@ -200,7 +200,7 @@ async function startWorkflowRunHandler({
200
200
  if (!runId) {
201
201
  throw new HTTPException(400, { message: "runId required to start run" });
202
202
  }
203
- const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
203
+ const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
204
204
  if (!workflow) {
205
205
  throw new HTTPException(404, { message: "Workflow not found" });
206
206
  }
@@ -208,10 +208,10 @@ async function startWorkflowRunHandler({
208
208
  if (!run) {
209
209
  throw new HTTPException(404, { message: "Workflow run not found" });
210
210
  }
211
- const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
211
+ const _run = await workflow.createRun({ runId, resourceId: run.resourceId });
212
212
  void _run.start({
213
213
  inputData,
214
- runtimeContext,
214
+ requestContext,
215
215
  tracingOptions
216
216
  });
217
217
  return { message: "Workflow run started" };
@@ -219,64 +219,19 @@ async function startWorkflowRunHandler({
219
219
  return handleError(e, "Error starting workflow run");
220
220
  }
221
221
  }
222
- async function watchWorkflowHandler({
222
+ async function streamWorkflowHandler({
223
223
  mastra,
224
+ requestContext,
224
225
  workflowId,
225
226
  runId,
226
- eventType = "watch"
227
+ inputData,
228
+ tracingOptions
227
229
  }) {
228
- try {
229
- if (!workflowId) {
230
- throw new HTTPException(400, { message: "Workflow ID is required" });
231
- }
232
- if (!runId) {
233
- throw new HTTPException(400, { message: "runId required to watch workflow" });
234
- }
235
- const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
236
- if (!workflow) {
237
- throw new HTTPException(404, { message: "Workflow not found" });
238
- }
239
- const run = await workflow.getWorkflowRunById(runId);
240
- if (!run) {
241
- throw new HTTPException(404, { message: "Workflow run not found" });
242
- }
243
- const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
244
- let unwatch;
245
- let asyncRef = null;
246
- const stream = new ReadableStream({
247
- start(controller) {
248
- unwatch = _run.watch((event) => {
249
- const { type, payload, eventTimestamp } = event;
250
- controller.enqueue(JSON.stringify({ type, payload, eventTimestamp, runId }));
251
- if (asyncRef) {
252
- clearImmediate(asyncRef);
253
- asyncRef = null;
254
- }
255
- asyncRef = setImmediate(async () => {
256
- const runDone = eventType === "watch" ? payload.workflowState.status !== "running" : type === "finish";
257
- if (runDone) {
258
- controller.close();
259
- unwatch?.();
260
- }
261
- });
262
- }, eventType);
263
- },
264
- cancel() {
265
- if (asyncRef) {
266
- clearImmediate(asyncRef);
267
- asyncRef = null;
268
- }
269
- unwatch?.();
270
- }
271
- });
272
- return stream;
273
- } catch (error) {
274
- return handleError(error, "Error watching workflow");
275
- }
230
+ return streamVNextWorkflowHandler({ mastra, workflowId, runId, inputData, requestContext, tracingOptions });
276
231
  }
277
- async function streamWorkflowHandler({
232
+ async function streamLegacyWorkflowHandler({
278
233
  mastra,
279
- runtimeContext,
234
+ requestContext,
280
235
  workflowId,
281
236
  runId,
282
237
  inputData,
@@ -289,15 +244,15 @@ async function streamWorkflowHandler({
289
244
  if (!runId) {
290
245
  throw new HTTPException(400, { message: "runId required to resume workflow" });
291
246
  }
292
- const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
247
+ const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
293
248
  if (!workflow) {
294
249
  throw new HTTPException(404, { message: "Workflow not found" });
295
250
  }
296
251
  const serverCache = mastra.getServerCache();
297
- const run = await workflow.createRunAsync({ runId });
298
- const result = run.stream({
252
+ const run = await workflow.createRun({ runId });
253
+ const result = run.streamLegacy({
299
254
  inputData,
300
- runtimeContext,
255
+ requestContext,
301
256
  onChunk: async (chunk) => {
302
257
  if (serverCache) {
303
258
  const cacheKey = runId;
@@ -311,7 +266,7 @@ async function streamWorkflowHandler({
311
266
  return handleError(error, "Error executing workflow");
312
267
  }
313
268
  }
314
- async function observeStreamWorkflowHandler({
269
+ async function observeStreamLegacyWorkflowHandler({
315
270
  mastra,
316
271
  workflowId,
317
272
  runId
@@ -323,7 +278,7 @@ async function observeStreamWorkflowHandler({
323
278
  if (!runId) {
324
279
  throw new HTTPException(400, { message: "runId required to observe workflow stream" });
325
280
  }
326
- const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
281
+ const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
327
282
  if (!workflow) {
328
283
  throw new HTTPException(404, { message: "Workflow not found" });
329
284
  }
@@ -331,7 +286,7 @@ async function observeStreamWorkflowHandler({
331
286
  if (!run) {
332
287
  throw new HTTPException(404, { message: "Workflow run not found" });
333
288
  }
334
- const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
289
+ const _run = await workflow.createRun({ runId, resourceId: run.resourceId });
335
290
  const serverCache = mastra.getServerCache();
336
291
  if (!serverCache) {
337
292
  throw new HTTPException(500, { message: "Server cache not found" });
@@ -343,15 +298,22 @@ async function observeStreamWorkflowHandler({
343
298
  await writer.write(chunk);
344
299
  }
345
300
  writer.releaseLock();
346
- const result = _run.observeStream();
301
+ const result = _run.observeStreamLegacy();
347
302
  return result.stream?.pipeThrough(transformStream);
348
303
  } catch (error) {
349
304
  return handleError(error, "Error observing workflow stream");
350
305
  }
351
306
  }
307
+ async function observeStreamWorkflowHandler({
308
+ mastra,
309
+ workflowId,
310
+ runId
311
+ }) {
312
+ return observeStreamVNextWorkflowHandler({ mastra, workflowId, runId });
313
+ }
352
314
  async function streamVNextWorkflowHandler({
353
315
  mastra,
354
- runtimeContext,
316
+ requestContext,
355
317
  workflowId,
356
318
  runId,
357
319
  inputData,
@@ -365,25 +327,30 @@ async function streamVNextWorkflowHandler({
365
327
  if (!runId) {
366
328
  throw new HTTPException(400, { message: "runId required to stream workflow" });
367
329
  }
368
- const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
330
+ const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
369
331
  if (!workflow) {
370
332
  throw new HTTPException(404, { message: "Workflow not found" });
371
333
  }
372
334
  const serverCache = mastra.getServerCache();
373
- const run = await workflow.createRunAsync({ runId });
374
- const result = run.streamVNext({
335
+ const run = await workflow.createRun({ runId });
336
+ const result = run.stream({
375
337
  inputData,
376
- runtimeContext,
338
+ requestContext,
377
339
  closeOnSuspend,
378
- onChunk: async (chunk) => {
379
- if (serverCache) {
380
- const cacheKey = runId;
381
- await serverCache.listPush(cacheKey, chunk);
382
- }
383
- },
384
340
  tracingOptions
385
341
  });
386
- return result;
342
+ return result.fullStream.pipeThrough(
343
+ new TransformStream({
344
+ transform(chunk, controller) {
345
+ if (serverCache) {
346
+ const cacheKey = runId;
347
+ serverCache.listPush(cacheKey, chunk).catch(() => {
348
+ });
349
+ }
350
+ controller.enqueue(chunk);
351
+ }
352
+ })
353
+ );
387
354
  } catch (error) {
388
355
  return handleError(error, "Error streaming workflow");
389
356
  }
@@ -400,7 +367,7 @@ async function observeStreamVNextWorkflowHandler({
400
367
  if (!runId) {
401
368
  throw new HTTPException(400, { message: "runId required to observe workflow stream" });
402
369
  }
403
- const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
370
+ const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
404
371
  if (!workflow) {
405
372
  throw new HTTPException(404, { message: "Workflow not found" });
406
373
  }
@@ -408,7 +375,7 @@ async function observeStreamVNextWorkflowHandler({
408
375
  if (!run) {
409
376
  throw new HTTPException(404, { message: "Workflow run not found" });
410
377
  }
411
- const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
378
+ const _run = await workflow.createRun({ runId, resourceId: run.resourceId });
412
379
  const serverCache = mastra.getServerCache();
413
380
  if (!serverCache) {
414
381
  throw new HTTPException(500, { message: "Server cache not found" });
@@ -421,7 +388,7 @@ async function observeStreamVNextWorkflowHandler({
421
388
  controller.enqueue(chunk);
422
389
  }
423
390
  };
424
- const liveStream = _run.observeStreamVNext();
391
+ const liveStream = _run.observeStream();
425
392
  const reader = liveStream.getReader();
426
393
  const pump = async () => {
427
394
  try {
@@ -456,7 +423,7 @@ async function resumeAsyncWorkflowHandler({
456
423
  workflowId,
457
424
  runId,
458
425
  body,
459
- runtimeContext,
426
+ requestContext,
460
427
  tracingOptions
461
428
  }) {
462
429
  try {
@@ -466,10 +433,7 @@ async function resumeAsyncWorkflowHandler({
466
433
  if (!runId) {
467
434
  throw new HTTPException(400, { message: "runId required to resume workflow" });
468
435
  }
469
- if (!body.step) {
470
- throw new HTTPException(400, { message: "step required to resume workflow" });
471
- }
472
- const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
436
+ const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
473
437
  if (!workflow) {
474
438
  throw new HTTPException(404, { message: "Workflow not found" });
475
439
  }
@@ -477,11 +441,11 @@ async function resumeAsyncWorkflowHandler({
477
441
  if (!run) {
478
442
  throw new HTTPException(404, { message: "Workflow run not found" });
479
443
  }
480
- const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
444
+ const _run = await workflow.createRun({ runId, resourceId: run.resourceId });
481
445
  const result = await _run.resume({
482
446
  step: body.step,
483
447
  resumeData: body.resumeData,
484
- runtimeContext,
448
+ requestContext,
485
449
  tracingOptions
486
450
  });
487
451
  return result;
@@ -494,7 +458,7 @@ async function resumeWorkflowHandler({
494
458
  workflowId,
495
459
  runId,
496
460
  body,
497
- runtimeContext,
461
+ requestContext,
498
462
  tracingOptions
499
463
  }) {
500
464
  try {
@@ -504,10 +468,7 @@ async function resumeWorkflowHandler({
504
468
  if (!runId) {
505
469
  throw new HTTPException(400, { message: "runId required to resume workflow" });
506
470
  }
507
- if (!body.step) {
508
- throw new HTTPException(400, { message: "step required to resume workflow" });
509
- }
510
- const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
471
+ const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
511
472
  if (!workflow) {
512
473
  throw new HTTPException(404, { message: "Workflow not found" });
513
474
  }
@@ -515,11 +476,11 @@ async function resumeWorkflowHandler({
515
476
  if (!run) {
516
477
  throw new HTTPException(404, { message: "Workflow run not found" });
517
478
  }
518
- const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
479
+ const _run = await workflow.createRun({ runId, resourceId: run.resourceId });
519
480
  void _run.resume({
520
481
  step: body.step,
521
482
  resumeData: body.resumeData,
522
- runtimeContext,
483
+ requestContext,
523
484
  tracingOptions
524
485
  });
525
486
  return { message: "Workflow run resumed" };
@@ -532,7 +493,7 @@ async function resumeStreamWorkflowHandler({
532
493
  workflowId,
533
494
  runId,
534
495
  body,
535
- runtimeContext,
496
+ requestContext,
536
497
  tracingOptions
537
498
  }) {
538
499
  try {
@@ -542,10 +503,7 @@ async function resumeStreamWorkflowHandler({
542
503
  if (!runId) {
543
504
  throw new HTTPException(400, { message: "runId required to resume workflow" });
544
505
  }
545
- if (!body.step) {
546
- throw new HTTPException(400, { message: "step required to resume workflow" });
547
- }
548
- const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
506
+ const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
549
507
  if (!workflow) {
550
508
  throw new HTTPException(404, { message: "Workflow not found" });
551
509
  }
@@ -553,43 +511,54 @@ async function resumeStreamWorkflowHandler({
553
511
  if (!run) {
554
512
  throw new HTTPException(404, { message: "Workflow run not found" });
555
513
  }
556
- const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
514
+ const _run = await workflow.createRun({ runId, resourceId: run.resourceId });
557
515
  const serverCache = mastra.getServerCache();
558
- const stream = _run.resumeStreamVNext({
516
+ const stream = _run.resumeStream({
559
517
  step: body.step,
560
518
  resumeData: body.resumeData,
561
- runtimeContext,
562
- tracingOptions,
563
- onChunk: async (chunk) => {
564
- if (serverCache) {
565
- const cacheKey = runId;
566
- await serverCache.listPush(cacheKey, chunk);
519
+ requestContext,
520
+ tracingOptions
521
+ }).fullStream.pipeThrough(
522
+ new TransformStream({
523
+ transform(chunk, controller) {
524
+ if (serverCache) {
525
+ const cacheKey = runId;
526
+ serverCache.listPush(cacheKey, chunk).catch(() => {
527
+ });
528
+ }
529
+ controller.enqueue(chunk);
567
530
  }
568
- }
569
- });
531
+ })
532
+ );
570
533
  return stream;
571
534
  } catch (error) {
572
535
  return handleError(error, "Error resuming workflow");
573
536
  }
574
537
  }
575
- async function getWorkflowRunsHandler({
538
+ async function listWorkflowRunsHandler({
576
539
  mastra,
577
540
  workflowId,
578
541
  fromDate,
579
542
  toDate,
580
- limit,
581
- offset,
543
+ perPage,
544
+ page,
582
545
  resourceId
583
546
  }) {
584
547
  try {
585
548
  if (!workflowId) {
586
549
  throw new HTTPException(400, { message: "Workflow ID is required" });
587
550
  }
588
- const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
551
+ if (perPage !== void 0 && perPage !== false && (!Number.isInteger(perPage) || perPage <= 0)) {
552
+ throw new HTTPException(400, { message: "perPage must be a positive integer or false" });
553
+ }
554
+ if (page !== void 0 && (!Number.isInteger(page) || page < 0)) {
555
+ throw new HTTPException(400, { message: "page must be a non-negative integer" });
556
+ }
557
+ const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
589
558
  if (!workflow) {
590
559
  throw new HTTPException(404, { message: "Workflow not found" });
591
560
  }
592
- const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
561
+ const workflowRuns = await workflow.listWorkflowRuns({ fromDate, toDate, perPage, page, resourceId }) || {
593
562
  runs: [],
594
563
  total: 0
595
564
  };
@@ -610,7 +579,7 @@ async function cancelWorkflowRunHandler({
610
579
  if (!runId) {
611
580
  throw new HTTPException(400, { message: "runId required to cancel workflow run" });
612
581
  }
613
- const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
582
+ const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });
614
583
  if (!workflow) {
615
584
  throw new HTTPException(404, { message: "Workflow not found" });
616
585
  }
@@ -618,43 +587,14 @@ async function cancelWorkflowRunHandler({
618
587
  if (!run) {
619
588
  throw new HTTPException(404, { message: "Workflow run not found" });
620
589
  }
621
- const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
590
+ const _run = await workflow.createRun({ runId, resourceId: run.resourceId });
622
591
  await _run.cancel();
623
592
  return { message: "Workflow run cancelled" };
624
593
  } catch (error) {
625
594
  return handleError(error, "Error canceling workflow run");
626
595
  }
627
596
  }
628
- async function sendWorkflowRunEventHandler({
629
- mastra,
630
- workflowId,
631
- runId,
632
- event,
633
- data
634
- }) {
635
- try {
636
- if (!workflowId) {
637
- throw new HTTPException(400, { message: "Workflow ID is required" });
638
- }
639
- if (!runId) {
640
- throw new HTTPException(400, { message: "runId required to send workflow run event" });
641
- }
642
- const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
643
- if (!workflow) {
644
- throw new HTTPException(404, { message: "Workflow not found" });
645
- }
646
- const run = await workflow.getWorkflowRunById(runId);
647
- if (!run) {
648
- throw new HTTPException(404, { message: "Workflow run not found" });
649
- }
650
- const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
651
- await _run.sendEvent(event, data);
652
- return { message: "Workflow run event sent" };
653
- } catch (error) {
654
- return handleError(error, "Error sending workflow run event");
655
- }
656
- }
657
597
 
658
- export { cancelWorkflowRunHandler, createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunExecutionResultHandler, getWorkflowRunsHandler, getWorkflowsHandler, observeStreamVNextWorkflowHandler, observeStreamWorkflowHandler, resumeAsyncWorkflowHandler, resumeStreamWorkflowHandler, resumeWorkflowHandler, sendWorkflowRunEventHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamVNextWorkflowHandler, streamWorkflowHandler, watchWorkflowHandler, workflows_exports };
659
- //# sourceMappingURL=chunk-DB63UMTV.js.map
660
- //# sourceMappingURL=chunk-DB63UMTV.js.map
598
+ export { cancelWorkflowRunHandler, createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunExecutionResultHandler, listWorkflowRunsHandler, listWorkflowsHandler, observeStreamLegacyWorkflowHandler, observeStreamVNextWorkflowHandler, observeStreamWorkflowHandler, resumeAsyncWorkflowHandler, resumeStreamWorkflowHandler, resumeWorkflowHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamLegacyWorkflowHandler, streamVNextWorkflowHandler, streamWorkflowHandler, workflows_exports };
599
+ //# sourceMappingURL=chunk-ZJ6KEY6H.js.map
600
+ //# sourceMappingURL=chunk-ZJ6KEY6H.js.map