@mastra/core 1.0.0-beta.2 → 1.0.0-beta.3

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 (286) hide show
  1. package/CHANGELOG.md +162 -0
  2. package/dist/agent/agent-legacy.d.ts +2 -2
  3. package/dist/agent/agent-legacy.d.ts.map +1 -1
  4. package/dist/agent/agent.d.ts +1 -1
  5. package/dist/agent/agent.d.ts.map +1 -1
  6. package/dist/agent/agent.types.d.ts +3 -2
  7. package/dist/agent/agent.types.d.ts.map +1 -1
  8. package/dist/agent/index.cjs +9 -9
  9. package/dist/agent/index.js +2 -2
  10. package/dist/agent/message-list/index.cjs +3 -3
  11. package/dist/agent/message-list/index.d.ts.map +1 -1
  12. package/dist/agent/message-list/index.js +1 -1
  13. package/dist/agent/message-list/prompt/convert-file.d.ts +1 -1
  14. package/dist/agent/message-list/prompt/convert-file.d.ts.map +1 -1
  15. package/dist/agent/message-list/prompt/download-assets.d.ts.map +1 -1
  16. package/dist/agent/types.d.ts +1 -0
  17. package/dist/agent/types.d.ts.map +1 -1
  18. package/dist/agent/utils.d.ts.map +1 -1
  19. package/dist/agent/workflows/prepare-stream/index.d.ts +2 -1
  20. package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
  21. package/dist/agent/workflows/prepare-stream/map-results-step.d.ts +3 -1
  22. package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
  23. package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +2 -1
  24. package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts.map +1 -1
  25. package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts +2 -1
  26. package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts.map +1 -1
  27. package/dist/agent/workflows/prepare-stream/stream-step.d.ts +3 -1
  28. package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
  29. package/dist/chunk-3PSWNGBF.js +3 -0
  30. package/dist/{chunk-ZV5CC35D.js.map → chunk-3PSWNGBF.js.map} +1 -1
  31. package/dist/{chunk-IQO7ANVS.cjs → chunk-3VOUB4ZU.cjs} +10 -9
  32. package/dist/chunk-3VOUB4ZU.cjs.map +1 -0
  33. package/dist/{chunk-ZGHTOYHW.js → chunk-4DWZ4Z6H.js} +155 -23
  34. package/dist/chunk-4DWZ4Z6H.js.map +1 -0
  35. package/dist/{chunk-ET6UOTTU.cjs → chunk-4IKJAKCD.cjs} +40 -4
  36. package/dist/chunk-4IKJAKCD.cjs.map +1 -0
  37. package/dist/{chunk-JYYQQEBH.cjs → chunk-4RSHBKDJ.cjs} +241 -4
  38. package/dist/chunk-4RSHBKDJ.cjs.map +1 -0
  39. package/dist/{chunk-MV7KHWUT.js → chunk-5CWWU22H.js} +25 -4
  40. package/dist/chunk-5CWWU22H.js.map +1 -0
  41. package/dist/{chunk-JV2KH24V.js → chunk-BAMR7HKO.js} +18 -13
  42. package/dist/chunk-BAMR7HKO.js.map +1 -0
  43. package/dist/{chunk-7CBEP2ZQ.js → chunk-CKGIPST2.js} +809 -89
  44. package/dist/chunk-CKGIPST2.js.map +1 -0
  45. package/dist/{chunk-4CDL2QJT.js → chunk-D6EDHNGV.js} +53 -16
  46. package/dist/chunk-D6EDHNGV.js.map +1 -0
  47. package/dist/{chunk-ZWNI5IWX.cjs → chunk-EZVRSZMK.cjs} +13 -12
  48. package/dist/chunk-EZVRSZMK.cjs.map +1 -0
  49. package/dist/{chunk-ECFXGXWO.cjs → chunk-G36A2JRR.cjs} +18 -13
  50. package/dist/chunk-G36A2JRR.cjs.map +1 -0
  51. package/dist/{chunk-7PO6SEJF.js → chunk-G3OOCXAI.js} +240 -3
  52. package/dist/chunk-G3OOCXAI.js.map +1 -0
  53. package/dist/{chunk-I4CXL4SR.js → chunk-GRGPQ32U.js} +5 -4
  54. package/dist/chunk-GRGPQ32U.js.map +1 -0
  55. package/dist/{chunk-WM6CK2F3.cjs → chunk-HBJPYQRN.cjs} +57 -19
  56. package/dist/chunk-HBJPYQRN.cjs.map +1 -0
  57. package/dist/{chunk-GGYKYORQ.cjs → chunk-JTXVR2RA.cjs} +27 -6
  58. package/dist/chunk-JTXVR2RA.cjs.map +1 -0
  59. package/dist/{chunk-XEVG546F.js → chunk-JXESKY4A.js} +3 -3
  60. package/dist/{chunk-XEVG546F.js.map → chunk-JXESKY4A.js.map} +1 -1
  61. package/dist/{chunk-7AHYOMHJ.js → chunk-KEURQGCQ.js} +40 -5
  62. package/dist/chunk-KEURQGCQ.js.map +1 -0
  63. package/dist/{chunk-JPGVRWWL.js → chunk-KOSW5PP5.js} +8 -2
  64. package/dist/chunk-KOSW5PP5.js.map +1 -0
  65. package/dist/chunk-MCUX2D5Q.js +420 -0
  66. package/dist/chunk-MCUX2D5Q.js.map +1 -0
  67. package/dist/chunk-N4SJ4YX7.cjs +424 -0
  68. package/dist/chunk-N4SJ4YX7.cjs.map +1 -0
  69. package/dist/{chunk-VOY2RXOC.cjs → chunk-O6NA3Z43.cjs} +6 -6
  70. package/dist/{chunk-VOY2RXOC.cjs.map → chunk-O6NA3Z43.cjs.map} +1 -1
  71. package/dist/{chunk-SNPVZPLB.js → chunk-OQF4H5Y2.js} +6 -5
  72. package/dist/chunk-OQF4H5Y2.js.map +1 -0
  73. package/dist/{chunk-YCVEJ3UN.cjs → chunk-OWX2PUFH.cjs} +846 -123
  74. package/dist/chunk-OWX2PUFH.cjs.map +1 -0
  75. package/dist/chunk-PE3V7GUL.cjs +4 -0
  76. package/dist/{chunk-LJFJTTZQ.cjs.map → chunk-PE3V7GUL.cjs.map} +1 -1
  77. package/dist/{chunk-HDJFSJCK.js → chunk-T3WZCEC4.js} +4 -3
  78. package/dist/chunk-T3WZCEC4.js.map +1 -0
  79. package/dist/{chunk-W7UH2PWL.js → chunk-VU6DVS7J.js} +179 -282
  80. package/dist/chunk-VU6DVS7J.js.map +1 -0
  81. package/dist/{chunk-22443P6A.cjs → chunk-VZGBVYXA.cjs} +173 -41
  82. package/dist/chunk-VZGBVYXA.cjs.map +1 -0
  83. package/dist/{chunk-2ZVKF4HP.cjs → chunk-XRIVPHXV.cjs} +184 -285
  84. package/dist/chunk-XRIVPHXV.cjs.map +1 -0
  85. package/dist/{chunk-LWBQ4P4N.cjs → chunk-YQ7NLZZ3.cjs} +54 -53
  86. package/dist/chunk-YQ7NLZZ3.cjs.map +1 -0
  87. package/dist/{chunk-CB575O6L.cjs → chunk-ZPMFINU2.cjs} +8 -2
  88. package/dist/chunk-ZPMFINU2.cjs.map +1 -0
  89. package/dist/evals/base.d.ts.map +1 -1
  90. package/dist/evals/index.cjs +4 -4
  91. package/dist/evals/index.js +1 -1
  92. package/dist/evals/scoreTraces/index.cjs +5 -4
  93. package/dist/evals/scoreTraces/index.cjs.map +1 -1
  94. package/dist/evals/scoreTraces/index.js +3 -2
  95. package/dist/evals/scoreTraces/index.js.map +1 -1
  96. package/dist/evals/scoreTraces/scoreTracesWorkflow.d.ts.map +1 -1
  97. package/dist/index.cjs +2 -2
  98. package/dist/index.js +1 -1
  99. package/dist/integration/index.cjs +2 -2
  100. package/dist/integration/index.js +1 -1
  101. package/dist/llm/index.cjs +26 -10
  102. package/dist/llm/index.d.ts +1 -0
  103. package/dist/llm/index.d.ts.map +1 -1
  104. package/dist/llm/index.js +5 -1
  105. package/dist/llm/model/aisdk/v5/model.d.ts +47 -0
  106. package/dist/llm/model/aisdk/v5/model.d.ts.map +1 -0
  107. package/dist/llm/model/gateways/base.d.ts +8 -0
  108. package/dist/llm/model/gateways/base.d.ts.map +1 -1
  109. package/dist/llm/model/gateways/models-dev.d.ts +1 -0
  110. package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
  111. package/dist/llm/model/gateways/netlify.d.ts +2 -1
  112. package/dist/llm/model/gateways/netlify.d.ts.map +1 -1
  113. package/dist/llm/model/is-v2-model.d.ts +3 -0
  114. package/dist/llm/model/is-v2-model.d.ts.map +1 -0
  115. package/dist/llm/model/model-method-from-agent.d.ts +4 -0
  116. package/dist/llm/model/model-method-from-agent.d.ts.map +1 -0
  117. package/dist/llm/model/model.loop.d.ts +2 -2
  118. package/dist/llm/model/model.loop.d.ts.map +1 -1
  119. package/dist/llm/model/model.loop.types.d.ts +2 -0
  120. package/dist/llm/model/model.loop.types.d.ts.map +1 -1
  121. package/dist/llm/model/provider-registry.d.ts +11 -1
  122. package/dist/llm/model/provider-registry.d.ts.map +1 -1
  123. package/dist/llm/model/provider-types.generated.d.ts +56 -7
  124. package/dist/llm/model/registry-generator.d.ts.map +1 -1
  125. package/dist/llm/model/resolve-model.d.ts +1 -1
  126. package/dist/llm/model/resolve-model.d.ts.map +1 -1
  127. package/dist/llm/model/router.d.ts +12 -5
  128. package/dist/llm/model/router.d.ts.map +1 -1
  129. package/dist/llm/model/shared.types.d.ts +10 -4
  130. package/dist/llm/model/shared.types.d.ts.map +1 -1
  131. package/dist/loop/index.cjs +2 -2
  132. package/dist/loop/index.js +1 -1
  133. package/dist/loop/network/index.d.ts.map +1 -1
  134. package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts +37 -0
  135. package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts.map +1 -0
  136. package/dist/loop/test-utils/fullStream.d.ts.map +1 -1
  137. package/dist/loop/test-utils/generateText.d.ts.map +1 -1
  138. package/dist/loop/test-utils/options.d.ts.map +1 -1
  139. package/dist/loop/test-utils/resultObject.d.ts.map +1 -1
  140. package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
  141. package/dist/loop/test-utils/textStream.d.ts.map +1 -1
  142. package/dist/loop/test-utils/toUIMessageStream.d.ts.map +1 -1
  143. package/dist/loop/test-utils/tools.d.ts.map +1 -1
  144. package/dist/loop/test-utils/utils.d.ts +1 -1
  145. package/dist/loop/test-utils/utils.d.ts.map +1 -1
  146. package/dist/loop/types.d.ts +8 -3
  147. package/dist/loop/types.d.ts.map +1 -1
  148. package/dist/loop/workflows/agentic-execution/index.d.ts +12 -12
  149. package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
  150. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +9 -9
  151. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
  152. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +4 -4
  153. package/dist/loop/workflows/agentic-loop/index.d.ts +13 -12
  154. package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
  155. package/dist/loop/workflows/run-state.d.ts +2 -2
  156. package/dist/loop/workflows/run-state.d.ts.map +1 -1
  157. package/dist/loop/workflows/schema.d.ts +4 -4
  158. package/dist/loop/workflows/stream.d.ts.map +1 -1
  159. package/dist/mastra/index.cjs +2 -2
  160. package/dist/mastra/index.d.ts +127 -3
  161. package/dist/mastra/index.d.ts.map +1 -1
  162. package/dist/mastra/index.js +1 -1
  163. package/dist/memory/index.cjs +8 -8
  164. package/dist/memory/index.js +4 -4
  165. package/dist/models-dev-GCVENVWA.js +3 -0
  166. package/dist/{models-dev-DNBKXHT4.js.map → models-dev-GCVENVWA.js.map} +1 -1
  167. package/dist/models-dev-TIBJR6IG.cjs +12 -0
  168. package/dist/{models-dev-YBEEQIX6.cjs.map → models-dev-TIBJR6IG.cjs.map} +1 -1
  169. package/dist/netlify-NTSNNT6F.cjs +12 -0
  170. package/dist/{netlify-GWNGSIRZ.cjs.map → netlify-NTSNNT6F.cjs.map} +1 -1
  171. package/dist/netlify-O5NJW7CF.js +3 -0
  172. package/dist/{netlify-7G2L5VSH.js.map → netlify-O5NJW7CF.js.map} +1 -1
  173. package/dist/processors/index.cjs +11 -11
  174. package/dist/processors/index.js +1 -1
  175. package/dist/provider-registry-74GMFZKT.js +3 -0
  176. package/dist/provider-registry-74GMFZKT.js.map +1 -0
  177. package/dist/provider-registry-BZP3DIIV.cjs +40 -0
  178. package/dist/provider-registry-BZP3DIIV.cjs.map +1 -0
  179. package/dist/provider-registry.json +140 -18
  180. package/dist/{registry-generator-MK63POJO.cjs → registry-generator-JPCV47SC.cjs} +6 -4
  181. package/dist/registry-generator-JPCV47SC.cjs.map +1 -0
  182. package/dist/{registry-generator-H4YNODDH.js → registry-generator-XD4FPZTU.js} +6 -4
  183. package/dist/registry-generator-XD4FPZTU.js.map +1 -0
  184. package/dist/relevance/index.cjs +2 -2
  185. package/dist/relevance/index.js +1 -1
  186. package/dist/server/index.cjs +2 -1
  187. package/dist/server/index.cjs.map +1 -1
  188. package/dist/server/index.d.ts +4 -0
  189. package/dist/server/index.d.ts.map +1 -1
  190. package/dist/server/index.js +2 -1
  191. package/dist/server/index.js.map +1 -1
  192. package/dist/storage/domains/workflows/inmemory.d.ts +1 -1
  193. package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
  194. package/dist/storage/index.cjs +29 -29
  195. package/dist/storage/index.js +1 -1
  196. package/dist/storage/types.d.ts +2 -1
  197. package/dist/storage/types.d.ts.map +1 -1
  198. package/dist/stream/RunOutput.d.ts +1 -1
  199. package/dist/stream/RunOutput.d.ts.map +1 -1
  200. package/dist/stream/aisdk/v5/execute.d.ts +6 -3
  201. package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
  202. package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
  203. package/dist/stream/base/input.d.ts +1 -1
  204. package/dist/stream/base/output.d.ts.map +1 -1
  205. package/dist/stream/index.cjs +11 -11
  206. package/dist/stream/index.js +2 -2
  207. package/dist/stream/types.d.ts +4 -3
  208. package/dist/stream/types.d.ts.map +1 -1
  209. package/dist/test-utils/llm-mock.cjs +2 -2
  210. package/dist/test-utils/llm-mock.js +1 -1
  211. package/dist/tools/index.cjs +4 -4
  212. package/dist/tools/index.js +1 -1
  213. package/dist/tools/is-vercel-tool.cjs +2 -2
  214. package/dist/tools/is-vercel-tool.js +1 -1
  215. package/dist/tools/tool-builder/builder.d.ts.map +1 -1
  216. package/dist/tools/tool.d.ts.map +1 -1
  217. package/dist/tools/types.d.ts +1 -0
  218. package/dist/tools/types.d.ts.map +1 -1
  219. package/dist/tools/validation.d.ts +12 -0
  220. package/dist/tools/validation.d.ts.map +1 -1
  221. package/dist/utils.cjs +25 -21
  222. package/dist/utils.d.ts +4 -1
  223. package/dist/utils.d.ts.map +1 -1
  224. package/dist/utils.js +1 -1
  225. package/dist/workflows/default.d.ts +24 -8
  226. package/dist/workflows/default.d.ts.map +1 -1
  227. package/dist/workflows/evented/execution-engine.d.ts +3 -1
  228. package/dist/workflows/evented/execution-engine.d.ts.map +1 -1
  229. package/dist/workflows/evented/index.cjs +10 -10
  230. package/dist/workflows/evented/index.js +1 -1
  231. package/dist/workflows/evented/workflow-event-processor/index.d.ts +5 -4
  232. package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
  233. package/dist/workflows/evented/workflow-event-processor/loop.d.ts +1 -1
  234. package/dist/workflows/evented/workflow-event-processor/loop.d.ts.map +1 -1
  235. package/dist/workflows/evented/workflow-event-processor/parallel.d.ts +2 -2
  236. package/dist/workflows/evented/workflow-event-processor/parallel.d.ts.map +1 -1
  237. package/dist/workflows/evented/workflow-event-processor/sleep.d.ts +2 -2
  238. package/dist/workflows/evented/workflow-event-processor/sleep.d.ts.map +1 -1
  239. package/dist/workflows/evented/workflow.d.ts +2 -1
  240. package/dist/workflows/evented/workflow.d.ts.map +1 -1
  241. package/dist/workflows/execution-engine.d.ts +4 -2
  242. package/dist/workflows/execution-engine.d.ts.map +1 -1
  243. package/dist/workflows/index.cjs +28 -16
  244. package/dist/workflows/index.js +1 -1
  245. package/dist/workflows/step.d.ts +1 -0
  246. package/dist/workflows/step.d.ts.map +1 -1
  247. package/dist/workflows/types.d.ts +54 -2
  248. package/dist/workflows/types.d.ts.map +1 -1
  249. package/dist/workflows/utils.d.ts +20 -0
  250. package/dist/workflows/utils.d.ts.map +1 -1
  251. package/dist/workflows/workflow.d.ts +108 -40
  252. package/dist/workflows/workflow.d.ts.map +1 -1
  253. package/package.json +12 -20
  254. package/src/llm/model/provider-types.generated.d.ts +56 -7
  255. package/dist/chunk-22443P6A.cjs.map +0 -1
  256. package/dist/chunk-2ZVKF4HP.cjs.map +0 -1
  257. package/dist/chunk-4CDL2QJT.js.map +0 -1
  258. package/dist/chunk-7AHYOMHJ.js.map +0 -1
  259. package/dist/chunk-7CBEP2ZQ.js.map +0 -1
  260. package/dist/chunk-7PO6SEJF.js.map +0 -1
  261. package/dist/chunk-CB575O6L.cjs.map +0 -1
  262. package/dist/chunk-ECFXGXWO.cjs.map +0 -1
  263. package/dist/chunk-ET6UOTTU.cjs.map +0 -1
  264. package/dist/chunk-GGYKYORQ.cjs.map +0 -1
  265. package/dist/chunk-HDJFSJCK.js.map +0 -1
  266. package/dist/chunk-I4CXL4SR.js.map +0 -1
  267. package/dist/chunk-IQO7ANVS.cjs.map +0 -1
  268. package/dist/chunk-JPGVRWWL.js.map +0 -1
  269. package/dist/chunk-JV2KH24V.js.map +0 -1
  270. package/dist/chunk-JYYQQEBH.cjs.map +0 -1
  271. package/dist/chunk-LJFJTTZQ.cjs +0 -4
  272. package/dist/chunk-LWBQ4P4N.cjs.map +0 -1
  273. package/dist/chunk-MV7KHWUT.js.map +0 -1
  274. package/dist/chunk-SNPVZPLB.js.map +0 -1
  275. package/dist/chunk-W7UH2PWL.js.map +0 -1
  276. package/dist/chunk-WM6CK2F3.cjs.map +0 -1
  277. package/dist/chunk-YCVEJ3UN.cjs.map +0 -1
  278. package/dist/chunk-ZGHTOYHW.js.map +0 -1
  279. package/dist/chunk-ZV5CC35D.js +0 -3
  280. package/dist/chunk-ZWNI5IWX.cjs.map +0 -1
  281. package/dist/models-dev-DNBKXHT4.js +0 -3
  282. package/dist/models-dev-YBEEQIX6.cjs +0 -12
  283. package/dist/netlify-7G2L5VSH.js +0 -3
  284. package/dist/netlify-GWNGSIRZ.cjs +0 -12
  285. package/dist/registry-generator-H4YNODDH.js.map +0 -1
  286. package/dist/registry-generator-MK63POJO.cjs.map +0 -1
@@ -2,15 +2,15 @@
2
2
 
3
3
  var chunkQUKUN6NR_cjs = require('./chunk-QUKUN6NR.cjs');
4
4
  var chunkABJOUEVA_cjs = require('./chunk-ABJOUEVA.cjs');
5
- var chunkECFXGXWO_cjs = require('./chunk-ECFXGXWO.cjs');
6
- var chunk2ZVKF4HP_cjs = require('./chunk-2ZVKF4HP.cjs');
7
- var chunkVOY2RXOC_cjs = require('./chunk-VOY2RXOC.cjs');
5
+ var chunkG36A2JRR_cjs = require('./chunk-G36A2JRR.cjs');
6
+ var chunkN4SJ4YX7_cjs = require('./chunk-N4SJ4YX7.cjs');
7
+ var chunkO6NA3Z43_cjs = require('./chunk-O6NA3Z43.cjs');
8
8
  var chunkMR7ZWBL6_cjs = require('./chunk-MR7ZWBL6.cjs');
9
- var chunkWM6CK2F3_cjs = require('./chunk-WM6CK2F3.cjs');
9
+ var chunkHBJPYQRN_cjs = require('./chunk-HBJPYQRN.cjs');
10
10
  var chunkE7K4FTLN_cjs = require('./chunk-E7K4FTLN.cjs');
11
11
  var chunkTWH4PTDG_cjs = require('./chunk-TWH4PTDG.cjs');
12
12
  var chunkLRSB62Z6_cjs = require('./chunk-LRSB62Z6.cjs');
13
- var chunkET6UOTTU_cjs = require('./chunk-ET6UOTTU.cjs');
13
+ var chunk4IKJAKCD_cjs = require('./chunk-4IKJAKCD.cjs');
14
14
  var chunkJ7O6WENZ_cjs = require('./chunk-J7O6WENZ.cjs');
15
15
  var chunk4WQYXT2I_cjs = require('./chunk-4WQYXT2I.cjs');
16
16
  var chunkKEXGB7FK_cjs = require('./chunk-KEXGB7FK.cjs');
@@ -543,6 +543,11 @@ function runScorer({
543
543
  chunkMR7ZWBL6_cjs.executeHook("onScorerRun" /* ON_SCORER_RUN */, payload);
544
544
  }
545
545
 
546
+ // src/llm/model/is-v2-model.ts
547
+ function isV2Model(model) {
548
+ return model.specificationVersion === "v2";
549
+ }
550
+
546
551
  // src/stream/base/consume-stream.ts
547
552
  async function consumeStream2({
548
553
  stream,
@@ -599,7 +604,7 @@ var WorkflowRunOutput = class {
599
604
  this.workflowId = workflowId;
600
605
  this.#baseStream = stream;
601
606
  stream.pipeTo(
602
- new WritableStream({
607
+ new web.WritableStream({
603
608
  start() {
604
609
  const chunk = {
605
610
  type: "workflow-start",
@@ -727,7 +732,7 @@ var WorkflowRunOutput = class {
727
732
  };
728
733
  const self = this;
729
734
  stream.pipeTo(
730
- new WritableStream({
735
+ new web.WritableStream({
731
736
  start() {
732
737
  const chunk = {
733
738
  type: "workflow-start",
@@ -962,6 +967,24 @@ async function validateStepInput({
962
967
  }
963
968
  return { inputData, validationError };
964
969
  }
970
+ async function validateStepResumeData({ resumeData, step }) {
971
+ if (!resumeData) {
972
+ return { resumeData: void 0, validationError: void 0 };
973
+ }
974
+ let validationError;
975
+ const resumeSchema = step.resumeSchema;
976
+ if (resumeSchema) {
977
+ const validatedResumeData = await resumeSchema.safeParseAsync(resumeData);
978
+ if (!validatedResumeData.success) {
979
+ const errors = getZodErrors(validatedResumeData.error);
980
+ const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
981
+ validationError = new Error("Step resume data validation failed: \n" + errorMessages);
982
+ } else {
983
+ resumeData = validatedResumeData.data;
984
+ }
985
+ }
986
+ return { resumeData, validationError };
987
+ }
965
988
  function getResumeLabelsByStepId(resumeLabels, stepId) {
966
989
  return Object.entries(resumeLabels).filter(([_, value]) => value.stepId === stepId).reduce(
967
990
  (acc, [key, value]) => {
@@ -992,6 +1015,111 @@ function createDeprecationProxy(params, {
992
1015
  }
993
1016
  });
994
1017
  }
1018
+ var getStepIds = (entry) => {
1019
+ if (entry.type === "step" || entry.type === "foreach" || entry.type === "loop") {
1020
+ return [entry.step.id];
1021
+ }
1022
+ if (entry.type === "parallel" || entry.type === "conditional") {
1023
+ return entry.steps.map((s) => s.step.id);
1024
+ }
1025
+ if (entry.type === "sleep" || entry.type === "sleepUntil") {
1026
+ return [entry.id];
1027
+ }
1028
+ return [];
1029
+ };
1030
+ var createTimeTravelExecutionParams = (params) => {
1031
+ const { steps, inputData, resumeData, context, nestedStepsContext, snapshot, initialState, graph } = params;
1032
+ const firstStepId = steps[0];
1033
+ let executionPath = [];
1034
+ const stepResults = {};
1035
+ const snapshotContext = snapshot.context;
1036
+ for (const [index, entry] of graph.steps.entries()) {
1037
+ const currentExecPathLength = executionPath.length;
1038
+ if (currentExecPathLength > 0 && !resumeData) {
1039
+ break;
1040
+ }
1041
+ const stepIds = getStepIds(entry);
1042
+ if (stepIds.includes(firstStepId)) {
1043
+ const innerExecutionPath = stepIds?.length > 1 ? [stepIds?.findIndex((s) => s === firstStepId)] : [];
1044
+ executionPath = [index, ...innerExecutionPath];
1045
+ }
1046
+ const prevStep = graph.steps[index - 1];
1047
+ let stepPayload = void 0;
1048
+ if (prevStep) {
1049
+ const prevStepIds = getStepIds(prevStep);
1050
+ if (prevStepIds.length > 0) {
1051
+ if (prevStepIds.length === 1) {
1052
+ stepPayload = stepResults?.[prevStepIds[0]]?.output ?? {};
1053
+ } else {
1054
+ stepPayload = prevStepIds.reduce(
1055
+ (acc, stepId) => {
1056
+ acc[stepId] = stepResults?.[stepId]?.output ?? {};
1057
+ return acc;
1058
+ },
1059
+ {}
1060
+ );
1061
+ }
1062
+ }
1063
+ }
1064
+ if (index === 0 && stepIds.includes(firstStepId)) {
1065
+ stepResults.input = context?.[firstStepId]?.payload ?? inputData ?? snapshotContext?.input;
1066
+ } else if (index === 0) {
1067
+ stepResults.input = stepIds?.reduce((acc, stepId) => {
1068
+ if (acc) return acc;
1069
+ return context?.[stepId]?.payload ?? snapshotContext?.[stepId]?.payload;
1070
+ }, null) ?? snapshotContext?.input ?? {};
1071
+ }
1072
+ let stepOutput = void 0;
1073
+ const nextStep = graph.steps[index + 1];
1074
+ if (nextStep) {
1075
+ const nextStepIds = getStepIds(nextStep);
1076
+ if (nextStepIds.length > 0 && inputData && nextStepIds.includes(firstStepId) && steps.length === 1) {
1077
+ stepOutput = inputData;
1078
+ }
1079
+ }
1080
+ stepIds.forEach((stepId) => {
1081
+ let result;
1082
+ const stepContext = context?.[stepId] ?? snapshotContext[stepId];
1083
+ const defaultStepStatus = steps?.includes(stepId) ? "running" : "success";
1084
+ const status = ["failed", "canceled"].includes(stepContext?.status) ? defaultStepStatus : stepContext?.status ?? defaultStepStatus;
1085
+ const isCompleteStatus = ["success", "failed", "canceled"].includes(status);
1086
+ result = {
1087
+ status,
1088
+ payload: context?.[stepId]?.payload ?? stepPayload ?? snapshotContext[stepId]?.payload ?? {},
1089
+ output: isCompleteStatus ? context?.[stepId]?.output ?? stepOutput ?? snapshotContext[stepId]?.output ?? {} : void 0,
1090
+ resumePayload: stepContext?.resumePayload,
1091
+ suspendPayload: stepContext?.suspendPayload,
1092
+ suspendOutput: stepContext?.suspendOutput,
1093
+ startedAt: stepContext?.startedAt ?? Date.now(),
1094
+ endedAt: isCompleteStatus ? stepContext?.endedAt ?? Date.now() : void 0,
1095
+ suspendedAt: stepContext?.suspendedAt,
1096
+ resumedAt: stepContext?.resumedAt
1097
+ };
1098
+ if (currentExecPathLength > 0 && (!snapshotContext[stepId] || snapshotContext[stepId] && snapshotContext[stepId].status !== "suspended")) {
1099
+ result = void 0;
1100
+ }
1101
+ if (result) {
1102
+ const formattedResult = chunkHBJPYQRN_cjs.removeUndefinedValues(result);
1103
+ stepResults[stepId] = formattedResult;
1104
+ }
1105
+ });
1106
+ }
1107
+ if (!executionPath.length) {
1108
+ throw new Error(
1109
+ `Time travel target step not found in execution graph: '${steps?.join(".")}'. Verify the step id/path.`
1110
+ );
1111
+ }
1112
+ const timeTravelData = {
1113
+ inputData,
1114
+ executionPath,
1115
+ steps,
1116
+ stepResults,
1117
+ nestedStepResults: nestedStepsContext,
1118
+ state: initialState ?? snapshot.value ?? {},
1119
+ resumeData
1120
+ };
1121
+ return timeTravelData;
1122
+ };
995
1123
 
996
1124
  // src/workflows/default.ts
997
1125
  var DefaultExecutionEngine = class extends ExecutionEngine {
@@ -1078,7 +1206,9 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1078
1206
  resume,
1079
1207
  retryConfig,
1080
1208
  workflowSpan,
1081
- disableScorers
1209
+ disableScorers,
1210
+ restart,
1211
+ timeTravel
1082
1212
  } = params;
1083
1213
  const { attempts = 0, delay: delay2 = 0 } = retryConfig ?? {};
1084
1214
  const steps = graph.steps;
@@ -1094,19 +1224,26 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1094
1224
  throw empty_graph_error;
1095
1225
  }
1096
1226
  let startIdx = 0;
1097
- if (resume?.resumePath) {
1227
+ if (timeTravel) {
1228
+ startIdx = timeTravel.executionPath[0];
1229
+ timeTravel.executionPath.shift();
1230
+ } else if (restart) {
1231
+ startIdx = restart.activePaths[0];
1232
+ restart.activePaths.shift();
1233
+ } else if (resume?.resumePath) {
1098
1234
  startIdx = resume.resumePath[0];
1099
1235
  resume.resumePath.shift();
1100
1236
  }
1101
- const stepResults = resume?.stepResults || { input };
1237
+ const stepResults = timeTravel?.stepResults || restart?.stepResults || resume?.stepResults || { input };
1102
1238
  let lastOutput;
1103
- let lastState = initialState ?? {};
1239
+ let lastState = timeTravel?.state ?? restart?.state ?? initialState ?? {};
1104
1240
  for (let i = startIdx; i < steps.length; i++) {
1105
1241
  const entry = steps[i];
1106
1242
  const executionContext = {
1107
1243
  workflowId,
1108
1244
  runId,
1109
1245
  executionPath: [i],
1246
+ activeStepsPath: {},
1110
1247
  suspendedPaths: {},
1111
1248
  resumeLabels: {},
1112
1249
  retryConfig: { attempts, delay: delay2 },
@@ -1124,6 +1261,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1124
1261
  prevStep: steps[i - 1],
1125
1262
  stepResults,
1126
1263
  resume,
1264
+ timeTravel,
1265
+ restart,
1127
1266
  tracingContext: {
1128
1267
  currentSpan: workflowSpan
1129
1268
  },
@@ -1413,7 +1552,9 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1413
1552
  step,
1414
1553
  stepResults,
1415
1554
  executionContext,
1555
+ restart,
1416
1556
  resume,
1557
+ timeTravel,
1417
1558
  prevOutput,
1418
1559
  emitter,
1419
1560
  abortController,
@@ -1425,22 +1566,38 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1425
1566
  tracingContext,
1426
1567
  iterationCount
1427
1568
  }) {
1428
- const startTime = resume?.steps[0] === step.id ? void 0 : Date.now();
1429
- const resumeTime = resume?.steps[0] === step.id ? Date.now() : void 0;
1430
1569
  const stepCallId = crypto2.randomUUID();
1431
1570
  const { inputData, validationError } = await validateStepInput({
1432
1571
  prevOutput,
1433
1572
  step,
1434
- validateInputs: this.options?.validateInputs ?? false
1573
+ validateInputs: this.options?.validateInputs ?? true
1435
1574
  });
1575
+ const { resumeData: timeTravelResumeData, validationError: timeTravelResumeValidationError } = await validateStepResumeData({
1576
+ resumeData: timeTravel?.stepResults[step.id]?.status === "suspended" ? timeTravel?.resumeData : void 0,
1577
+ step
1578
+ });
1579
+ let resumeDataToUse;
1580
+ if (timeTravelResumeData && !timeTravelResumeValidationError) {
1581
+ resumeDataToUse = timeTravelResumeData;
1582
+ } else if (timeTravelResumeData && timeTravelResumeValidationError) {
1583
+ this.logger.warn("Time travel resume data validation failed", {
1584
+ stepId: step.id,
1585
+ error: timeTravelResumeValidationError.message
1586
+ });
1587
+ } else if (resume?.steps[0] === step.id) {
1588
+ resumeDataToUse = resume?.resumePayload;
1589
+ }
1590
+ const startTime = resumeDataToUse ? void 0 : Date.now();
1591
+ const resumeTime = resumeDataToUse ? Date.now() : void 0;
1436
1592
  const stepInfo = {
1437
1593
  ...stepResults[step.id],
1438
- ...resume?.steps[0] === step.id ? { resumePayload: resume?.resumePayload } : { payload: inputData },
1594
+ ...resumeDataToUse ? { resumePayload: resumeDataToUse } : { payload: inputData },
1439
1595
  ...startTime ? { startedAt: startTime } : {},
1440
1596
  ...resumeTime ? { resumedAt: resumeTime } : {},
1441
1597
  status: "running",
1442
1598
  ...iterationCount ? { metadata: { iterationCount } } : {}
1443
1599
  };
1600
+ executionContext.activeStepsPath[step.id] = executionContext.executionPath;
1444
1601
  const stepSpan = tracingContext.currentSpan?.createChildSpan({
1445
1602
  name: `workflow step: '${step.id}'`,
1446
1603
  type: "workflow_step" /* WORKFLOW_STEP */,
@@ -1495,6 +1652,10 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1495
1652
  throw validationError;
1496
1653
  }
1497
1654
  const retryCount = this.getOrGenerateRetryCount(step.id);
1655
+ let timeTravelSteps = [];
1656
+ if (timeTravel && timeTravel.steps.length > 0) {
1657
+ timeTravelSteps = timeTravel.steps[0] === step.id ? timeTravel.steps.slice(1) : [];
1658
+ }
1498
1659
  const result = await runStep({
1499
1660
  runId,
1500
1661
  resourceId,
@@ -1507,7 +1668,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1507
1668
  executionContext.state = state;
1508
1669
  },
1509
1670
  retryCount,
1510
- resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
1671
+ resumeData: resumeDataToUse,
1511
1672
  tracingContext: { currentSpan: stepSpan },
1512
1673
  getInitData: () => stepResults?.input,
1513
1674
  getStepResult: getStepResult.bind(this, stepResults),
@@ -1540,6 +1701,15 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1540
1701
  label: resume?.label,
1541
1702
  forEachIndex: resume?.forEachIndex
1542
1703
  } : void 0,
1704
+ // Only pass restart data if this step is part of activeStepsPath
1705
+ // This prevents pending nested workflows from trying to restart instead of start
1706
+ restart: !!restart?.activeStepsPath?.[step.id],
1707
+ timeTravel: timeTravelSteps.length > 0 ? {
1708
+ inputData: timeTravel?.inputData,
1709
+ steps: timeTravelSteps,
1710
+ nestedStepResults: timeTravel?.nestedStepResults,
1711
+ resumeData: timeTravel?.resumeData
1712
+ } : void 0,
1543
1713
  [chunkABJOUEVA_cjs.EMITTER_SYMBOL]: emitter,
1544
1714
  [chunkABJOUEVA_cjs.STREAM_FORMAT_SYMBOL]: executionContext.format,
1545
1715
  engine: {},
@@ -1611,6 +1781,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1611
1781
  };
1612
1782
  }
1613
1783
  }
1784
+ delete executionContext.activeStepsPath[step.id];
1614
1785
  if (!skipEmits) {
1615
1786
  if (execResults.status === "suspended") {
1616
1787
  await emitter.emit("watch", {
@@ -1714,6 +1885,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1714
1885
  serializedStepGraph,
1715
1886
  stepResults,
1716
1887
  resume,
1888
+ restart,
1889
+ timeTravel,
1717
1890
  executionContext,
1718
1891
  tracingContext,
1719
1892
  emitter,
@@ -1733,22 +1906,38 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1733
1906
  tracingPolicy: this.options?.tracingPolicy
1734
1907
  });
1735
1908
  const prevOutput = this.getStepOutput(stepResults, prevStep);
1736
- for (const step of entry.steps) {
1737
- if (step.type === "step") {
1738
- const startTime = resume?.steps[0] === step.step.id ? void 0 : Date.now();
1739
- const resumeTime = resume?.steps[0] === step.step.id ? Date.now() : void 0;
1740
- stepResults[step.step.id] = {
1741
- ...stepResults[step.step.id],
1742
- status: "running",
1743
- ...resumeTime ? { resumePayload: resume?.resumePayload } : { payload: prevOutput },
1744
- ...startTime ? { startedAt: startTime } : {},
1745
- ...resumeTime ? { resumedAt: resumeTime } : {}
1746
- };
1909
+ for (const [stepIndex, step] of entry.steps.entries()) {
1910
+ let makeStepRunning = true;
1911
+ if (restart) {
1912
+ makeStepRunning = !!restart.activeStepsPath[step.step.id];
1913
+ }
1914
+ if (timeTravel && timeTravel.executionPath.length > 0) {
1915
+ makeStepRunning = timeTravel.steps[0] === step.step.id;
1747
1916
  }
1917
+ if (!makeStepRunning) {
1918
+ continue;
1919
+ }
1920
+ const startTime = resume?.steps[0] === step.step.id ? void 0 : Date.now();
1921
+ const resumeTime = resume?.steps[0] === step.step.id ? Date.now() : void 0;
1922
+ stepResults[step.step.id] = {
1923
+ ...stepResults[step.step.id],
1924
+ status: "running",
1925
+ ...resumeTime ? { resumePayload: resume?.resumePayload } : { payload: prevOutput },
1926
+ ...startTime ? { startedAt: startTime } : {},
1927
+ ...resumeTime ? { resumedAt: resumeTime } : {}
1928
+ };
1929
+ executionContext.activeStepsPath[step.step.id] = [...executionContext.executionPath, stepIndex];
1930
+ }
1931
+ if (timeTravel && timeTravel.executionPath.length > 0) {
1932
+ timeTravel.executionPath.shift();
1748
1933
  }
1749
1934
  let execResults;
1750
1935
  const results = await Promise.all(
1751
1936
  entry.steps.map(async (step, i) => {
1937
+ const currStepResult = stepResults[step.step.id];
1938
+ if (currStepResult && currStepResult.status !== "running") {
1939
+ return currStepResult;
1940
+ }
1752
1941
  const result = await this.executeStep({
1753
1942
  workflowId,
1754
1943
  runId,
@@ -1757,8 +1946,11 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1757
1946
  prevOutput,
1758
1947
  stepResults,
1759
1948
  serializedStepGraph,
1949
+ restart,
1950
+ timeTravel,
1760
1951
  resume,
1761
1952
  executionContext: {
1953
+ activeStepsPath: executionContext.activeStepsPath,
1762
1954
  workflowId,
1763
1955
  runId,
1764
1956
  executionPath: [...executionContext.executionPath, i],
@@ -1823,6 +2015,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1823
2015
  serializedStepGraph,
1824
2016
  stepResults,
1825
2017
  resume,
2018
+ restart,
2019
+ timeTravel,
1826
2020
  executionContext,
1827
2021
  tracingContext,
1828
2022
  emitter,
@@ -1938,7 +2132,13 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1938
2132
  const results = await Promise.all(
1939
2133
  stepsToRun.map(async (step, index) => {
1940
2134
  const currStepResult = stepResults[step.step.id];
1941
- if (currStepResult && currStepResult.status === "success") {
2135
+ const isRestartStep = restart ? !!restart.activeStepsPath[step.step.id] : void 0;
2136
+ if (currStepResult && timeTravel && timeTravel.executionPath.length > 0) {
2137
+ if (timeTravel.steps[0] !== step.step.id) {
2138
+ return currStepResult;
2139
+ }
2140
+ }
2141
+ if (currStepResult && ["success", "failed"].includes(currStepResult.status) && isRestartStep === void 0) {
1942
2142
  return currStepResult;
1943
2143
  }
1944
2144
  const result = await this.executeStep({
@@ -1950,10 +2150,13 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1950
2150
  stepResults,
1951
2151
  serializedStepGraph,
1952
2152
  resume,
2153
+ restart,
2154
+ timeTravel,
1953
2155
  executionContext: {
1954
2156
  workflowId,
1955
2157
  runId,
1956
2158
  executionPath: [...executionContext.executionPath, index],
2159
+ activeStepsPath: executionContext.activeStepsPath,
1957
2160
  suspendedPaths: executionContext.suspendedPaths,
1958
2161
  resumeLabels: executionContext.resumeLabels,
1959
2162
  retryConfig: executionContext.retryConfig,
@@ -2015,6 +2218,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2015
2218
  prevOutput,
2016
2219
  stepResults,
2017
2220
  resume,
2221
+ restart,
2222
+ timeTravel,
2018
2223
  executionContext,
2019
2224
  tracingContext,
2020
2225
  emitter,
@@ -2040,6 +2245,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2040
2245
  const prevPayload = stepResults[step.id]?.payload;
2041
2246
  let result = { status: "success", output: prevPayload ?? prevOutput };
2042
2247
  let currentResume = resume;
2248
+ let currentRestart = restart;
2249
+ let currentTimeTravel = timeTravel;
2043
2250
  do {
2044
2251
  result = await this.executeStep({
2045
2252
  workflowId,
@@ -2048,7 +2255,9 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2048
2255
  step,
2049
2256
  stepResults,
2050
2257
  executionContext,
2258
+ restart: currentRestart,
2051
2259
  resume: currentResume,
2260
+ timeTravel: currentTimeTravel,
2052
2261
  prevOutput: result.output,
2053
2262
  tracingContext: {
2054
2263
  currentSpan: loopSpan
@@ -2061,6 +2270,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2061
2270
  serializedStepGraph,
2062
2271
  iterationCount: iteration + 1
2063
2272
  });
2273
+ currentRestart = void 0;
2274
+ currentTimeTravel = void 0;
2064
2275
  if (currentResume && result.status !== "suspended") {
2065
2276
  currentResume = void 0;
2066
2277
  }
@@ -2075,7 +2286,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2075
2286
  const evalSpan = loopSpan?.createChildSpan({
2076
2287
  type: "workflow_conditional_eval" /* WORKFLOW_CONDITIONAL_EVAL */,
2077
2288
  name: `condition: '${entry.loopType}'`,
2078
- input: chunkWM6CK2F3_cjs.selectFields(result.output, ["stepResult", "output.text", "output.object", "messages"]),
2289
+ input: chunkHBJPYQRN_cjs.selectFields(result.output, ["stepResult", "output.text", "output.object", "messages"]),
2079
2290
  attributes: {
2080
2291
  conditionIndex: iteration
2081
2292
  },
@@ -2148,7 +2359,9 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2148
2359
  entry,
2149
2360
  prevOutput,
2150
2361
  stepResults,
2362
+ restart,
2151
2363
  resume,
2364
+ timeTravel,
2152
2365
  executionContext,
2153
2366
  tracingContext,
2154
2367
  emitter,
@@ -2217,6 +2430,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2217
2430
  resourceId,
2218
2431
  step,
2219
2432
  stepResults,
2433
+ restart,
2434
+ timeTravel,
2220
2435
  executionContext: { ...executionContext, foreachIndex: k },
2221
2436
  resume: resumeToUse,
2222
2437
  prevOutput: item,
@@ -2350,7 +2565,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2350
2565
  status: workflowStatus,
2351
2566
  value: executionContext.state,
2352
2567
  context: stepResults,
2353
- activePaths: [],
2568
+ activePaths: executionContext.executionPath,
2569
+ activeStepsPath: executionContext.activeStepsPath,
2354
2570
  serializedStepGraph,
2355
2571
  suspendedPaths: executionContext.suspendedPaths,
2356
2572
  waitingPaths: {},
@@ -2371,6 +2587,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2371
2587
  prevStep,
2372
2588
  serializedStepGraph,
2373
2589
  stepResults,
2590
+ restart,
2591
+ timeTravel,
2374
2592
  resume,
2375
2593
  executionContext,
2376
2594
  tracingContext,
@@ -2391,6 +2609,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2391
2609
  step,
2392
2610
  stepResults,
2393
2611
  executionContext,
2612
+ timeTravel,
2613
+ restart,
2394
2614
  resume,
2395
2615
  prevOutput,
2396
2616
  tracingContext,
@@ -2419,6 +2639,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2419
2639
  suspendedPaths: executionContext.suspendedPaths,
2420
2640
  resumeLabels: executionContext.resumeLabels,
2421
2641
  retryConfig: executionContext.retryConfig,
2642
+ activeStepsPath: executionContext.activeStepsPath,
2422
2643
  state: executionContext.state
2423
2644
  },
2424
2645
  tracingContext,
@@ -2498,6 +2719,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2498
2719
  prevStep,
2499
2720
  stepResults,
2500
2721
  serializedStepGraph,
2722
+ timeTravel,
2723
+ restart,
2501
2724
  resume,
2502
2725
  executionContext,
2503
2726
  tracingContext,
@@ -2515,6 +2738,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2515
2738
  prevOutput,
2516
2739
  stepResults,
2517
2740
  serializedStepGraph,
2741
+ timeTravel,
2742
+ restart,
2518
2743
  resume,
2519
2744
  executionContext,
2520
2745
  tracingContext,
@@ -2532,6 +2757,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2532
2757
  prevStep,
2533
2758
  prevOutput,
2534
2759
  stepResults,
2760
+ timeTravel,
2761
+ restart,
2535
2762
  resume,
2536
2763
  executionContext,
2537
2764
  tracingContext,
@@ -2550,6 +2777,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2550
2777
  prevStep,
2551
2778
  prevOutput,
2552
2779
  stepResults,
2780
+ timeTravel,
2781
+ restart,
2553
2782
  resume,
2554
2783
  executionContext,
2555
2784
  tracingContext,
@@ -2571,6 +2800,12 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2571
2800
  status: "waiting"
2572
2801
  }
2573
2802
  });
2803
+ stepResults[entry.id] = {
2804
+ status: "waiting",
2805
+ payload: prevOutput,
2806
+ startedAt
2807
+ };
2808
+ executionContext.activeStepsPath[entry.id] = executionContext.executionPath;
2574
2809
  await this.persistStepUpdate({
2575
2810
  workflowId,
2576
2811
  runId,
@@ -2597,6 +2832,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2597
2832
  requestContext,
2598
2833
  writableStream
2599
2834
  });
2835
+ delete executionContext.activeStepsPath[entry.id];
2600
2836
  await this.persistStepUpdate({
2601
2837
  workflowId,
2602
2838
  runId,
@@ -2642,6 +2878,12 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2642
2878
  status: "waiting"
2643
2879
  }
2644
2880
  });
2881
+ stepResults[entry.id] = {
2882
+ status: "waiting",
2883
+ payload: prevOutput,
2884
+ startedAt
2885
+ };
2886
+ executionContext.activeStepsPath[entry.id] = executionContext.executionPath;
2645
2887
  await this.persistStepUpdate({
2646
2888
  workflowId,
2647
2889
  runId,
@@ -2668,6 +2910,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2668
2910
  requestContext,
2669
2911
  writableStream
2670
2912
  });
2913
+ delete executionContext.activeStepsPath[entry.id];
2671
2914
  await this.persistStepUpdate({
2672
2915
  workflowId,
2673
2916
  runId,
@@ -2828,7 +3071,7 @@ function createStep(params, agentOptions) {
2828
3071
  component: params.component
2829
3072
  };
2830
3073
  }
2831
- if (params instanceof chunkET6UOTTU_cjs.Tool) {
3074
+ if (params instanceof chunk4IKJAKCD_cjs.Tool) {
2832
3075
  if (!params.inputSchema || !params.outputSchema) {
2833
3076
  throw new Error("Tool must have input and output schemas defined");
2834
3077
  }
@@ -2888,8 +3131,12 @@ function cloneStep(step, opts) {
2888
3131
  description: step.description,
2889
3132
  inputSchema: step.inputSchema,
2890
3133
  outputSchema: step.outputSchema,
3134
+ suspendSchema: step.suspendSchema,
3135
+ resumeSchema: step.resumeSchema,
3136
+ stateSchema: step.stateSchema,
2891
3137
  execute: step.execute,
2892
3138
  retries: step.retries,
3139
+ scorers: step.scorers,
2893
3140
  component: step.component
2894
3141
  };
2895
3142
  }
@@ -2902,7 +3149,8 @@ function cloneWorkflow(workflow, opts) {
2902
3149
  inputSchema: workflow.inputSchema,
2903
3150
  outputSchema: workflow.outputSchema,
2904
3151
  steps: workflow.stepDefs,
2905
- mastra: workflow.mastra
3152
+ mastra: workflow.mastra,
3153
+ options: workflow.options
2906
3154
  });
2907
3155
  wf.setStepFlow(workflow.stepGraph);
2908
3156
  wf.commit();
@@ -2916,6 +3164,8 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
2916
3164
  stateSchema;
2917
3165
  steps;
2918
3166
  stepDefs;
3167
+ engineType = "default";
3168
+ #nestedWorkflowInput;
2919
3169
  committed = false;
2920
3170
  stepFlow;
2921
3171
  serializedStepFlow;
@@ -2951,7 +3201,7 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
2951
3201
  this.steps = {};
2952
3202
  this.stepDefs = steps;
2953
3203
  this.#options = {
2954
- validateInputs: options.validateInputs ?? false,
3204
+ validateInputs: options.validateInputs ?? true,
2955
3205
  shouldPersistSnapshot: options.shouldPersistSnapshot ?? (() => true),
2956
3206
  tracingPolicy: options.tracingPolicy
2957
3207
  };
@@ -2963,6 +3213,7 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
2963
3213
  } else {
2964
3214
  this.executionEngine = executionEngine;
2965
3215
  }
3216
+ this.engineType = "default";
2966
3217
  this.#runs = /* @__PURE__ */ new Map();
2967
3218
  }
2968
3219
  get runs() {
@@ -3322,7 +3573,8 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
3322
3573
  cleanup: () => this.#runs.delete(runIdToUse),
3323
3574
  tracingPolicy: this.#options?.tracingPolicy,
3324
3575
  workflowSteps: this.steps,
3325
- validateInputs: this.#options?.validateInputs
3576
+ validateInputs: this.#options?.validateInputs,
3577
+ workflowEngineType: this.engineType
3326
3578
  });
3327
3579
  this.#runs.set(runIdToUse, run);
3328
3580
  const shouldPersistSnapshot = this.#options.shouldPersistSnapshot({
@@ -3339,8 +3591,9 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
3339
3591
  runId: runIdToUse,
3340
3592
  status: "pending",
3341
3593
  value: {},
3342
- context: {},
3594
+ context: this.#nestedWorkflowInput ? { input: this.#nestedWorkflowInput } : {},
3343
3595
  activePaths: [],
3596
+ activeStepsPath: {},
3344
3597
  serializedStepGraph: this.serializedStepGraph,
3345
3598
  suspendedPaths: {},
3346
3599
  resumeLabels: {},
@@ -3384,7 +3637,9 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
3384
3637
  state,
3385
3638
  setState,
3386
3639
  suspend,
3640
+ restart,
3387
3641
  resume,
3642
+ timeTravel,
3388
3643
  [chunkABJOUEVA_cjs.EMITTER_SYMBOL]: emitter,
3389
3644
  mastra,
3390
3645
  requestContext,
@@ -3396,17 +3651,20 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
3396
3651
  validateInputs
3397
3652
  }) {
3398
3653
  this.__registerMastra(mastra);
3399
- if (validateInputs) {
3400
- this.#options = {
3401
- ...this.#options || {},
3402
- validateInputs
3403
- };
3404
- }
3654
+ const effectiveValidateInputs = validateInputs ?? this.#options.validateInputs ?? true;
3655
+ this.#options = {
3656
+ ...this.#options || {},
3657
+ validateInputs: effectiveValidateInputs
3658
+ };
3405
3659
  this.executionEngine.options = {
3406
3660
  ...this.executionEngine.options || {},
3407
- validateInputs: validateInputs ?? false
3661
+ validateInputs: effectiveValidateInputs
3408
3662
  };
3409
3663
  const isResume = !!(resume?.steps && resume.steps.length > 0) || !!resume?.label || !!(resume?.steps && resume.steps.length === 0 && (!retryCount || retryCount === 0));
3664
+ if (!restart && !isResume) {
3665
+ this.#nestedWorkflowInput = inputData;
3666
+ }
3667
+ const isTimeTravel = !!(timeTravel && timeTravel.steps.length > 0);
3410
3668
  const run = isResume ? await this.createRun({ runId: resume.runId }) : await this.createRun({ runId });
3411
3669
  const nestedAbortCb = () => {
3412
3670
  abort();
@@ -3422,21 +3680,41 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
3422
3680
  if (retryCount && retryCount > 0 && isResume && requestContext) {
3423
3681
  requestContext.set("__mastraWorflowInputData", inputData);
3424
3682
  }
3425
- const res = isResume ? await run.resume({
3426
- resumeData,
3427
- step: resume.steps?.length > 0 ? resume.steps : void 0,
3428
- requestContext,
3429
- tracingContext,
3430
- outputOptions: { includeState: true, includeResumeLabels: true },
3431
- label: resume.label
3432
- }) : await run.start({
3433
- inputData,
3434
- requestContext,
3435
- tracingContext,
3436
- writableStream: writer,
3437
- initialState: state,
3438
- outputOptions: { includeState: true, includeResumeLabels: true }
3439
- });
3683
+ let res;
3684
+ if (isTimeTravel) {
3685
+ res = await run.timeTravel({
3686
+ inputData: timeTravel?.inputData,
3687
+ resumeData: timeTravel?.resumeData,
3688
+ initialState: state,
3689
+ step: timeTravel?.steps,
3690
+ context: timeTravel?.nestedStepResults?.[this.id] ?? {},
3691
+ nestedStepsContext: timeTravel?.nestedStepResults,
3692
+ requestContext,
3693
+ tracingContext,
3694
+ writableStream: writer,
3695
+ outputOptions: { includeState: true, includeResumeLabels: true }
3696
+ });
3697
+ } else if (restart) {
3698
+ res = await run.restart({ requestContext, tracingContext, writableStream: writer });
3699
+ } else if (isResume) {
3700
+ res = await run.resume({
3701
+ resumeData,
3702
+ step: resume.steps?.length > 0 ? resume.steps : void 0,
3703
+ requestContext,
3704
+ tracingContext,
3705
+ outputOptions: { includeState: true, includeResumeLabels: true },
3706
+ label: resume.label
3707
+ });
3708
+ } else {
3709
+ res = await run.start({
3710
+ inputData,
3711
+ requestContext,
3712
+ tracingContext,
3713
+ writableStream: writer,
3714
+ initialState: state,
3715
+ outputOptions: { includeState: true, includeResumeLabels: true }
3716
+ });
3717
+ }
3440
3718
  unwatch();
3441
3719
  const suspendedSteps = Object.entries(res.steps).filter(([_stepName, stepResult]) => {
3442
3720
  const stepRes = stepResult;
@@ -3472,6 +3750,35 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
3472
3750
  }
3473
3751
  return storage.listWorkflowRuns({ workflowName: this.id, ...args ?? {} });
3474
3752
  }
3753
+ async listActiveWorkflowRuns() {
3754
+ const runningRuns = await this.listWorkflowRuns({ status: "running" });
3755
+ const waitingRuns = await this.listWorkflowRuns({ status: "waiting" });
3756
+ return {
3757
+ runs: [...runningRuns.runs, ...waitingRuns.runs],
3758
+ total: runningRuns.total + waitingRuns.total
3759
+ };
3760
+ }
3761
+ async restartAllActiveWorkflowRuns() {
3762
+ if (this.engineType !== "default") {
3763
+ this.logger.debug(`Cannot restart active workflow runs for ${this.engineType} engine`);
3764
+ return;
3765
+ }
3766
+ const activeRuns = await this.listActiveWorkflowRuns();
3767
+ if (activeRuns.runs.length > 0) {
3768
+ this.logger.debug(
3769
+ `Restarting ${activeRuns.runs.length} active workflow run${activeRuns.runs.length > 1 ? "s" : ""}`
3770
+ );
3771
+ }
3772
+ for (const runSnapshot of activeRuns.runs) {
3773
+ try {
3774
+ const run = await this.createRun({ runId: runSnapshot.runId });
3775
+ await run.restart();
3776
+ this.logger.debug(`Restarted ${this.id} workflow run ${runSnapshot.runId}`);
3777
+ } catch (error) {
3778
+ this.logger.error(`Failed to restart ${this.id} workflow run ${runSnapshot.runId}: ${error}`);
3779
+ }
3780
+ }
3781
+ }
3475
3782
  async getWorkflowRunById(runId) {
3476
3783
  const storage = this.#mastra?.getStorage();
3477
3784
  if (!storage) {
@@ -3547,7 +3854,9 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
3547
3854
  result: snapshot.result,
3548
3855
  error: snapshot.error,
3549
3856
  payload: snapshot.context?.input,
3550
- steps: fullSteps
3857
+ steps: fullSteps,
3858
+ activeStepsPath: snapshot.activeStepsPath,
3859
+ serializedStepGraph: snapshot.serializedStepGraph
3551
3860
  };
3552
3861
  }
3553
3862
  };
@@ -3599,6 +3908,7 @@ var Run = class {
3599
3908
  */
3600
3909
  workflowSteps;
3601
3910
  workflowRunStatus;
3911
+ workflowEngineType;
3602
3912
  /**
3603
3913
  * The storage for this run
3604
3914
  */
@@ -3630,6 +3940,7 @@ var Run = class {
3630
3940
  this.validateInputs = params.validateInputs;
3631
3941
  this.stateSchema = params.stateSchema;
3632
3942
  this.workflowRunStatus = "pending";
3943
+ this.workflowEngineType = params.workflowEngineType;
3633
3944
  }
3634
3945
  get abortController() {
3635
3946
  if (!this.#abortController) {
@@ -3702,6 +4013,20 @@ var Run = class {
3702
4013
  }
3703
4014
  return resumeDataToUse;
3704
4015
  }
4016
+ async _validateTimetravelInputData(inputData, step) {
4017
+ let inputDataToUse = inputData;
4018
+ if (step && step.inputSchema && this.validateInputs) {
4019
+ const inputSchema = step.inputSchema;
4020
+ const validatedInputData = await inputSchema.safeParseAsync(inputData);
4021
+ if (!validatedInputData.success) {
4022
+ const errors = getZodErrors(validatedInputData.error);
4023
+ const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
4024
+ throw new Error("Invalid inputData: \n" + errorMessages);
4025
+ }
4026
+ inputDataToUse = validatedInputData.data;
4027
+ }
4028
+ return inputDataToUse;
4029
+ }
3705
4030
  async _start({
3706
4031
  inputData,
3707
4032
  initialState,
@@ -4127,6 +4452,13 @@ var Run = class {
4127
4452
  async resume(params) {
4128
4453
  return this._resume(params);
4129
4454
  }
4455
+ /**
4456
+ * Restarts the workflow execution that was previously active
4457
+ * @returns A promise that resolves to the workflow output
4458
+ */
4459
+ async restart(args = {}) {
4460
+ return this._restart(args);
4461
+ }
4130
4462
  async _resume(params) {
4131
4463
  const snapshot = await this.#mastra?.getStorage()?.loadWorkflowSnapshot({
4132
4464
  workflowName: this.workflowId,
@@ -4194,7 +4526,7 @@ var Run = class {
4194
4526
  params.requestContext.delete("__mastraWorflowInputData");
4195
4527
  }
4196
4528
  const stepResults = { ...snapshot?.context ?? {}, input: requestContextInput ?? snapshot?.context?.input };
4197
- let requestContextToUse = params.requestContext ?? new chunkJ7O6WENZ_cjs.RequestContext();
4529
+ const requestContextToUse = params.requestContext ?? new chunkJ7O6WENZ_cjs.RequestContext();
4198
4530
  Object.entries(snapshot?.requestContext ?? {}).forEach(([key, value]) => {
4199
4531
  if (!requestContextToUse.has(key)) {
4200
4532
  requestContextToUse.set(key, value);
@@ -4270,6 +4602,298 @@ var Run = class {
4270
4602
  return result;
4271
4603
  });
4272
4604
  }
4605
+ async _restart({
4606
+ requestContext,
4607
+ writableStream,
4608
+ tracingContext,
4609
+ tracingOptions
4610
+ }) {
4611
+ if (this.workflowEngineType !== "default") {
4612
+ throw new Error(`restart() is not supported on ${this.workflowEngineType} workflows`);
4613
+ }
4614
+ const snapshot = await this.#mastra?.getStorage()?.loadWorkflowSnapshot({
4615
+ workflowName: this.workflowId,
4616
+ runId: this.runId
4617
+ });
4618
+ let nestedWorkflowPending = false;
4619
+ if (!snapshot) {
4620
+ throw new Error(`Snapshot not found for run ${this.runId}`);
4621
+ }
4622
+ if (snapshot.status !== "running" && snapshot.status !== "waiting") {
4623
+ if (snapshot.status === "pending" && !!snapshot.context.input) {
4624
+ nestedWorkflowPending = true;
4625
+ } else {
4626
+ throw new Error("This workflow run was not active");
4627
+ }
4628
+ }
4629
+ let nestedWorkflowActiveStepsPath = {};
4630
+ const firstEntry = this.executionGraph.steps[0];
4631
+ if (firstEntry.type === "step" || firstEntry.type === "foreach" || firstEntry.type === "loop") {
4632
+ nestedWorkflowActiveStepsPath = {
4633
+ [firstEntry.step.id]: [0]
4634
+ };
4635
+ } else if (firstEntry.type === "sleep" || firstEntry.type === "sleepUntil") {
4636
+ nestedWorkflowActiveStepsPath = {
4637
+ [firstEntry.id]: [0]
4638
+ };
4639
+ } else if (firstEntry.type === "conditional" || firstEntry.type === "parallel") {
4640
+ nestedWorkflowActiveStepsPath = firstEntry.steps.reduce(
4641
+ (acc, step) => {
4642
+ acc[step.step.id] = [0];
4643
+ return acc;
4644
+ },
4645
+ {}
4646
+ );
4647
+ }
4648
+ const restartData = {
4649
+ activePaths: nestedWorkflowPending ? [0] : snapshot.activePaths,
4650
+ activeStepsPath: nestedWorkflowPending ? nestedWorkflowActiveStepsPath : snapshot.activeStepsPath,
4651
+ stepResults: snapshot.context,
4652
+ state: snapshot.value
4653
+ };
4654
+ const requestContextToUse = requestContext ?? new chunkJ7O6WENZ_cjs.RequestContext();
4655
+ for (const [key, value] of Object.entries(snapshot.requestContext ?? {})) {
4656
+ if (!requestContextToUse.has(key)) {
4657
+ requestContextToUse.set(key, value);
4658
+ }
4659
+ }
4660
+ const workflowSpan = chunkE7K4FTLN_cjs.getOrCreateSpan({
4661
+ type: "workflow_run" /* WORKFLOW_RUN */,
4662
+ name: `workflow run: '${this.workflowId}'`,
4663
+ attributes: {
4664
+ workflowId: this.workflowId
4665
+ },
4666
+ metadata: {
4667
+ resourceId: this.resourceId,
4668
+ runId: this.runId
4669
+ },
4670
+ tracingPolicy: this.tracingPolicy,
4671
+ tracingOptions,
4672
+ tracingContext,
4673
+ requestContext: requestContextToUse,
4674
+ mastra: this.#mastra
4675
+ });
4676
+ const traceId = workflowSpan?.externalTraceId;
4677
+ const result = await this.executionEngine.execute({
4678
+ workflowId: this.workflowId,
4679
+ runId: this.runId,
4680
+ resourceId: this.resourceId,
4681
+ disableScorers: this.disableScorers,
4682
+ graph: this.executionGraph,
4683
+ serializedStepGraph: this.serializedStepGraph,
4684
+ restart: restartData,
4685
+ emitter: {
4686
+ emit: async (event, data) => {
4687
+ this.emitter.emit(event, data);
4688
+ },
4689
+ on: (event, callback) => {
4690
+ this.emitter.on(event, callback);
4691
+ },
4692
+ off: (event, callback) => {
4693
+ this.emitter.off(event, callback);
4694
+ },
4695
+ once: (event, callback) => {
4696
+ this.emitter.once(event, callback);
4697
+ }
4698
+ },
4699
+ retryConfig: this.retryConfig,
4700
+ requestContext: requestContextToUse,
4701
+ abortController: this.abortController,
4702
+ writableStream,
4703
+ workflowSpan
4704
+ });
4705
+ if (result.status !== "suspended") {
4706
+ this.cleanup?.();
4707
+ }
4708
+ result.traceId = traceId;
4709
+ return result;
4710
+ }
4711
+ async _timeTravel({
4712
+ inputData,
4713
+ resumeData,
4714
+ initialState,
4715
+ step: stepParam,
4716
+ context,
4717
+ nestedStepsContext,
4718
+ requestContext,
4719
+ writableStream,
4720
+ tracingContext,
4721
+ tracingOptions,
4722
+ outputOptions
4723
+ }) {
4724
+ if (!stepParam || Array.isArray(stepParam) && stepParam.length === 0) {
4725
+ throw new Error("Step is required and must be a valid step or array of steps");
4726
+ }
4727
+ const snapshot = await this.#mastra?.getStorage()?.loadWorkflowSnapshot({
4728
+ workflowName: this.workflowId,
4729
+ runId: this.runId
4730
+ });
4731
+ if (!snapshot) {
4732
+ throw new Error(`Snapshot not found for run ${this.runId}`);
4733
+ }
4734
+ if (snapshot.status === "running") {
4735
+ throw new Error("This workflow run is still running, cannot time travel");
4736
+ }
4737
+ let steps;
4738
+ let newStepParam = stepParam;
4739
+ if (typeof stepParam === "string") {
4740
+ newStepParam = stepParam.split(".");
4741
+ }
4742
+ steps = (Array.isArray(newStepParam) ? newStepParam : [newStepParam]).map(
4743
+ (step) => typeof step === "string" ? step : step?.id
4744
+ );
4745
+ let inputDataToUse = inputData;
4746
+ if (inputDataToUse && steps.length === 1) {
4747
+ inputDataToUse = await this._validateTimetravelInputData(inputData, this.workflowSteps[steps[0]]);
4748
+ }
4749
+ const timeTravelData = createTimeTravelExecutionParams({
4750
+ steps,
4751
+ inputData: inputDataToUse,
4752
+ resumeData,
4753
+ context,
4754
+ nestedStepsContext,
4755
+ snapshot,
4756
+ initialState,
4757
+ graph: this.executionGraph
4758
+ });
4759
+ const requestContextToUse = requestContext ?? new chunkJ7O6WENZ_cjs.RequestContext();
4760
+ for (const [key, value] of Object.entries(snapshot.requestContext ?? {})) {
4761
+ if (!requestContextToUse.has(key)) {
4762
+ requestContextToUse.set(key, value);
4763
+ }
4764
+ }
4765
+ const workflowSpan = chunkE7K4FTLN_cjs.getOrCreateSpan({
4766
+ type: "workflow_run" /* WORKFLOW_RUN */,
4767
+ name: `workflow run: '${this.workflowId}'`,
4768
+ input: inputData,
4769
+ attributes: {
4770
+ workflowId: this.workflowId
4771
+ },
4772
+ metadata: {
4773
+ resourceId: this.resourceId,
4774
+ runId: this.runId
4775
+ },
4776
+ tracingPolicy: this.tracingPolicy,
4777
+ tracingOptions,
4778
+ tracingContext,
4779
+ requestContext: requestContextToUse,
4780
+ mastra: this.#mastra
4781
+ });
4782
+ const traceId = workflowSpan?.externalTraceId;
4783
+ const result = await this.executionEngine.execute({
4784
+ workflowId: this.workflowId,
4785
+ runId: this.runId,
4786
+ resourceId: this.resourceId,
4787
+ disableScorers: this.disableScorers,
4788
+ graph: this.executionGraph,
4789
+ timeTravel: timeTravelData,
4790
+ serializedStepGraph: this.serializedStepGraph,
4791
+ emitter: {
4792
+ emit: async (event, data) => {
4793
+ this.emitter.emit(event, data);
4794
+ },
4795
+ on: (event, callback) => {
4796
+ this.emitter.on(event, callback);
4797
+ },
4798
+ off: (event, callback) => {
4799
+ this.emitter.off(event, callback);
4800
+ },
4801
+ once: (event, callback) => {
4802
+ this.emitter.once(event, callback);
4803
+ }
4804
+ },
4805
+ retryConfig: this.retryConfig,
4806
+ requestContext: requestContextToUse,
4807
+ abortController: this.abortController,
4808
+ writableStream,
4809
+ workflowSpan,
4810
+ outputOptions
4811
+ });
4812
+ if (result.status !== "suspended") {
4813
+ this.cleanup?.();
4814
+ }
4815
+ result.traceId = traceId;
4816
+ return result;
4817
+ }
4818
+ async timeTravel(args) {
4819
+ return this._timeTravel(args);
4820
+ }
4821
+ timeTravelStream({
4822
+ inputData,
4823
+ resumeData,
4824
+ initialState,
4825
+ step,
4826
+ context,
4827
+ nestedStepsContext,
4828
+ requestContext,
4829
+ tracingContext,
4830
+ tracingOptions,
4831
+ outputOptions
4832
+ }) {
4833
+ this.closeStreamAction = async () => {
4834
+ };
4835
+ const self = this;
4836
+ const stream = new web.ReadableStream({
4837
+ async start(controller) {
4838
+ const unwatch = self.watch(async ({ type, from = "WORKFLOW" /* WORKFLOW */, payload }) => {
4839
+ controller.enqueue({
4840
+ type,
4841
+ runId: self.runId,
4842
+ from,
4843
+ payload: {
4844
+ stepName: payload.id,
4845
+ ...payload
4846
+ }
4847
+ });
4848
+ });
4849
+ self.closeStreamAction = async () => {
4850
+ unwatch();
4851
+ try {
4852
+ await controller.close();
4853
+ } catch (err) {
4854
+ console.error("Error closing stream:", err);
4855
+ }
4856
+ };
4857
+ const executionResultsPromise = self._timeTravel({
4858
+ inputData,
4859
+ step,
4860
+ context,
4861
+ nestedStepsContext,
4862
+ resumeData,
4863
+ initialState,
4864
+ requestContext,
4865
+ tracingContext,
4866
+ tracingOptions,
4867
+ writableStream: new web.WritableStream({
4868
+ write(chunk) {
4869
+ controller.enqueue(chunk);
4870
+ }
4871
+ }),
4872
+ outputOptions
4873
+ });
4874
+ self.executionResults = executionResultsPromise;
4875
+ let executionResults;
4876
+ try {
4877
+ executionResults = await executionResultsPromise;
4878
+ self.closeStreamAction?.().catch(() => {
4879
+ });
4880
+ if (self.streamOutput) {
4881
+ self.streamOutput.updateResults(executionResults);
4882
+ }
4883
+ } catch (err) {
4884
+ self.streamOutput?.rejectResults(err);
4885
+ self.closeStreamAction?.().catch(() => {
4886
+ });
4887
+ }
4888
+ }
4889
+ });
4890
+ this.streamOutput = new WorkflowRunOutput({
4891
+ runId: this.runId,
4892
+ workflowId: this.workflowId,
4893
+ stream
4894
+ });
4895
+ return this.streamOutput;
4896
+ }
4273
4897
  /**
4274
4898
  * @access private
4275
4899
  * @returns The execution results of the workflow run
@@ -4732,7 +5356,7 @@ function convertMastraChunkToAISDKv5({
4732
5356
  if (mode === "generate") {
4733
5357
  return {
4734
5358
  type: "file",
4735
- file: new chunkECFXGXWO_cjs.DefaultGeneratedFile({
5359
+ file: new chunkG36A2JRR_cjs.DefaultGeneratedFile({
4736
5360
  data: chunk.payload.data,
4737
5361
  mediaType: chunk.payload.mimeType
4738
5362
  })
@@ -4740,7 +5364,7 @@ function convertMastraChunkToAISDKv5({
4740
5364
  }
4741
5365
  return {
4742
5366
  type: "file",
4743
- file: new chunkECFXGXWO_cjs.DefaultGeneratedFileWithType({
5367
+ file: new chunkG36A2JRR_cjs.DefaultGeneratedFileWithType({
4744
5368
  data: chunk.payload.data,
4745
5369
  mediaType: chunk.payload.mimeType
4746
5370
  })
@@ -4895,7 +5519,8 @@ function execute({
4895
5519
  modelSettings,
4896
5520
  structuredOutput,
4897
5521
  headers,
4898
- shouldThrowError
5522
+ shouldThrowError,
5523
+ methodType
4899
5524
  }) {
4900
5525
  const v5 = new AISDKV5InputStream({
4901
5526
  component: "LLM",
@@ -4943,7 +5568,8 @@ You don't need to format your response as JSON unless the user asks you to. Just
4943
5568
  const pRetry = await import('p-retry');
4944
5569
  return await pRetry.default(
4945
5570
  async () => {
4946
- const streamResult = await model.doStream({
5571
+ const fn = (methodType === "stream" ? model.doStream : model.doGenerate).bind(model);
5572
+ const streamResult = await fn({
4947
5573
  ...toolsAndToolChoice,
4948
5574
  prompt,
4949
5575
  providerOptions: providerOptionsToUse,
@@ -4967,10 +5593,6 @@ You don't need to format your response as JSON unless the user asks you to. Just
4967
5593
  }
4968
5594
  );
4969
5595
  } catch (error) {
4970
- const abortSignal = options?.abortSignal;
4971
- if (providerUtilsV5.isAbortError(error) && abortSignal?.aborted) {
4972
- console.error("Abort error", error);
4973
- }
4974
5596
  if (shouldThrowError) {
4975
5597
  throw error;
4976
5598
  }
@@ -5442,7 +6064,8 @@ function createLLMExecutionStep({
5442
6064
  headers,
5443
6065
  downloadRetries,
5444
6066
  downloadConcurrency,
5445
- processorStates
6067
+ processorStates,
6068
+ methodType
5446
6069
  }) {
5447
6070
  return createStep({
5448
6071
  id: "llm-execution",
@@ -5492,7 +6115,7 @@ function createLLMExecutionStep({
5492
6115
  }
5493
6116
  if (prepareStepResult.messages) {
5494
6117
  const newMessages = prepareStepResult.messages;
5495
- const newMessageList = new chunkECFXGXWO_cjs.MessageList();
6118
+ const newMessageList = new chunkG36A2JRR_cjs.MessageList();
5496
6119
  for (const message of newMessages) {
5497
6120
  if (message.role === "system") {
5498
6121
  newMessageList.addSystem(message);
@@ -5521,6 +6144,7 @@ function createLLMExecutionStep({
5521
6144
  includeRawChunks,
5522
6145
  structuredOutput,
5523
6146
  headers,
6147
+ methodType,
5524
6148
  onResult: ({
5525
6149
  warnings: warningsFromStream,
5526
6150
  request: requestFromStream,
@@ -5981,7 +6605,8 @@ function createAgenticExecutionWorkflow({ models, _internal, ...rest }) {
5981
6605
  // VNext execution as internal
5982
6606
  internal: 1 /* WORKFLOW */
5983
6607
  },
5984
- shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended"
6608
+ shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended",
6609
+ validateInputs: false
5985
6610
  }
5986
6611
  }).then(llmExecutionStep).map(
5987
6612
  async ({ inputData }) => {
@@ -6021,7 +6646,8 @@ function createAgenticLoopWorkflow(params) {
6021
6646
  },
6022
6647
  shouldPersistSnapshot: (params2) => {
6023
6648
  return params2.workflowStatus === "suspended";
6024
- }
6649
+ },
6650
+ validateInputs: false
6025
6651
  }
6026
6652
  }).dowhile(agenticExecutionWorkflow, async ({ inputData }) => {
6027
6653
  const typedInputData = inputData;
@@ -6112,7 +6738,7 @@ function workflowLoopStream({
6112
6738
  }) {
6113
6739
  return new web.ReadableStream({
6114
6740
  start: async (controller) => {
6115
- const writer = new WritableStream({
6741
+ const writer = new web.WritableStream({
6116
6742
  write: (chunk) => {
6117
6743
  controller.enqueue(chunk);
6118
6744
  }
@@ -6431,7 +7057,8 @@ var MastraLLMVNext = class extends chunkKEXGB7FK_cjs.MastraBase {
6431
7057
  requireToolApproval,
6432
7058
  _internal,
6433
7059
  agentId,
6434
- toolCallId
7060
+ toolCallId,
7061
+ methodType
6435
7062
  }) {
6436
7063
  let stopWhenToUse;
6437
7064
  if (maxSteps && typeof maxSteps === "number") {
@@ -6488,6 +7115,7 @@ var MastraLLMVNext = class extends chunkKEXGB7FK_cjs.MastraBase {
6488
7115
  modelSpanTracker,
6489
7116
  requireToolApproval,
6490
7117
  agentId,
7118
+ methodType,
6491
7119
  options: {
6492
7120
  ...options,
6493
7121
  onStepFinish: async (props) => {
@@ -6527,7 +7155,7 @@ var MastraLLMVNext = class extends chunkKEXGB7FK_cjs.MastraBase {
6527
7155
  });
6528
7156
  if (props?.response?.headers?.["x-ratelimit-remaining-tokens"] && parseInt(props?.response?.headers?.["x-ratelimit-remaining-tokens"], 10) < 2e3) {
6529
7157
  this.logger.warn("Rate limit approaching, waiting 10 seconds", { runId });
6530
- await chunkWM6CK2F3_cjs.delay(10 * 1e3);
7158
+ await chunkHBJPYQRN_cjs.delay(10 * 1e3);
6531
7159
  }
6532
7160
  },
6533
7161
  onFinish: async (props) => {
@@ -6831,7 +7459,7 @@ async function prepareMemoryStep({
6831
7459
  );
6832
7460
  }
6833
7461
  } else {
6834
- const messageList = new chunkECFXGXWO_cjs.MessageList({
7462
+ const messageList = new chunkG36A2JRR_cjs.MessageList({
6835
7463
  threadId: thread?.id,
6836
7464
  resourceId: thread?.resourceId
6837
7465
  });
@@ -7596,7 +8224,8 @@ ${completionResult?.object?.finalResult}` : ""}
7596
8224
  isOneOff: z5__default.default.boolean()
7597
8225
  }),
7598
8226
  options: {
7599
- shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended"
8227
+ shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended",
8228
+ validateInputs: false
7600
8229
  }
7601
8230
  });
7602
8231
  networkWorkflow.then(routingStep).branch([
@@ -7723,7 +8352,8 @@ async function networkLoop({
7723
8352
  iteration: z5__default.default.number()
7724
8353
  }),
7725
8354
  options: {
7726
- shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended"
8355
+ shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended",
8356
+ validateInputs: false
7727
8357
  }
7728
8358
  }).dountil(networkWorkflow, async ({ inputData }) => {
7729
8359
  return inputData.isComplete || inputData.iteration >= maxIterations;
@@ -8281,7 +8911,7 @@ var AgentLegacyHandler = class {
8281
8911
  writableStream,
8282
8912
  methodType: methodType === "generate" ? "generateLegacy" : "streamLegacy"
8283
8913
  });
8284
- const messageList = new chunkECFXGXWO_cjs.MessageList({
8914
+ const messageList = new chunkG36A2JRR_cjs.MessageList({
8285
8915
  threadId,
8286
8916
  resourceId,
8287
8917
  generateMessageId: this.capabilities.mastra?.generateId?.bind(this.capabilities.mastra),
@@ -8362,7 +8992,7 @@ var AgentLegacyHandler = class {
8362
8992
  existingThread || hasResourceScopeSemanticRecall ? this.capabilities.getMemoryMessages({
8363
8993
  resourceId,
8364
8994
  threadId: threadObject.id,
8365
- vectorMessageSearch: new chunkECFXGXWO_cjs.MessageList().add(messages, `user`).getLatestUserContent() || "",
8995
+ vectorMessageSearch: new chunkG36A2JRR_cjs.MessageList().add(messages, `user`).getLatestUserContent() || "",
8366
8996
  memoryConfig,
8367
8997
  requestContext
8368
8998
  }) : { messages: [] },
@@ -8384,7 +9014,7 @@ The following messages were remembered from a different conversation:
8384
9014
  <remembered_from_other_conversation>
8385
9015
  ${(() => {
8386
9016
  let result = ``;
8387
- const messages2 = new chunkECFXGXWO_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
9017
+ const messages2 = new chunkG36A2JRR_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
8388
9018
  let lastYmd = null;
8389
9019
  for (const msg of messages2) {
8390
9020
  const date = msg.createdAt;
@@ -8435,7 +9065,7 @@ the following messages are from ${ymd}
8435
9065
  systemMessage,
8436
9066
  memorySystemMessage: memorySystemMessage || void 0
8437
9067
  });
8438
- const processedList = new chunkECFXGXWO_cjs.MessageList({
9068
+ const processedList = new chunkG36A2JRR_cjs.MessageList({
8439
9069
  threadId: threadObject.id,
8440
9070
  resourceId,
8441
9071
  generateMessageId: this.capabilities.mastra?.generateId?.bind(this.capabilities.mastra),
@@ -8491,7 +9121,7 @@ the following messages are from ${ymd}
8491
9121
  result: resToLog,
8492
9122
  threadId
8493
9123
  });
8494
- const messageListResponses = new chunkECFXGXWO_cjs.MessageList({
9124
+ const messageListResponses = new chunkG36A2JRR_cjs.MessageList({
8495
9125
  threadId,
8496
9126
  resourceId,
8497
9127
  generateMessageId: this.capabilities.mastra?.generateId?.bind(this.capabilities.mastra),
@@ -8851,7 +9481,7 @@ the following messages are from ${ymd}
8851
9481
  requestContext: mergedGenerateOptions.requestContext || new chunkJ7O6WENZ_cjs.RequestContext(),
8852
9482
  tracingContext,
8853
9483
  outputProcessorOverrides: finalOutputProcessors,
8854
- messageList: new chunkECFXGXWO_cjs.MessageList({
9484
+ messageList: new chunkG36A2JRR_cjs.MessageList({
8855
9485
  threadId: llmOptions.threadId || "",
8856
9486
  resourceId: llmOptions.resourceId || ""
8857
9487
  }).add(
@@ -8941,7 +9571,7 @@ the following messages are from ${ymd}
8941
9571
  const outputProcessorResult = await this.capabilities.__runOutputProcessors({
8942
9572
  requestContext: mergedGenerateOptions.requestContext || new chunkJ7O6WENZ_cjs.RequestContext(),
8943
9573
  tracingContext,
8944
- messageList: new chunkECFXGXWO_cjs.MessageList({
9574
+ messageList: new chunkG36A2JRR_cjs.MessageList({
8945
9575
  threadId: llmOptions.threadId || "",
8946
9576
  resourceId: llmOptions.resourceId || ""
8947
9577
  }).add(
@@ -9151,6 +9781,21 @@ the following messages are from ${ymd}
9151
9781
  }
9152
9782
  };
9153
9783
 
9784
+ // src/llm/model/model-method-from-agent.ts
9785
+ function getModelMethodFromAgentMethod(methodType) {
9786
+ if (methodType === "generate" || methodType === "generateLegacy") {
9787
+ return "generate";
9788
+ } else if (methodType === "stream" || methodType === "streamLegacy") {
9789
+ return "stream";
9790
+ } else {
9791
+ throw new chunkTWH4PTDG_cjs.MastraError({
9792
+ id: "INVALID_METHOD_TYPE",
9793
+ domain: "AGENT" /* AGENT */,
9794
+ category: "USER" /* USER */
9795
+ });
9796
+ }
9797
+ }
9798
+
9154
9799
  // src/processors/processors/unicode-normalizer.ts
9155
9800
  var UnicodeNormalizer = class {
9156
9801
  id = "unicode-normalizer";
@@ -11149,7 +11794,8 @@ function createMapResultsStep({
11149
11794
  memoryConfig,
11150
11795
  saveQueueManager,
11151
11796
  agentSpan,
11152
- agentId
11797
+ agentId,
11798
+ methodType
11153
11799
  }) {
11154
11800
  return async ({
11155
11801
  inputData,
@@ -11214,7 +11860,9 @@ function createMapResultsStep({
11214
11860
  effectiveOutputProcessors = effectiveOutputProcessors ? [...effectiveOutputProcessors, structuredProcessor] : [structuredProcessor];
11215
11861
  }
11216
11862
  const messageList = memoryData.messageList;
11863
+ const modelMethodType = getModelMethodFromAgentMethod(methodType);
11217
11864
  const loopOptions = {
11865
+ methodType: modelMethodType,
11218
11866
  agentId,
11219
11867
  requestContext: result.requestContext,
11220
11868
  tracingContext: { currentSpan: agentSpan },
@@ -11318,7 +11966,7 @@ var prepareToolsStepOutputSchema = z5.z.object({
11318
11966
  var prepareMemoryStepOutputSchema = z5.z.object({
11319
11967
  threadExists: z5.z.boolean(),
11320
11968
  thread: storageThreadSchema.optional(),
11321
- messageList: z5.z.instanceof(chunkECFXGXWO_cjs.MessageList),
11969
+ messageList: z5.z.instanceof(chunkG36A2JRR_cjs.MessageList),
11322
11970
  tripwire: z5.z.boolean().optional(),
11323
11971
  tripwireReason: z5.z.string().optional()
11324
11972
  });
@@ -11351,7 +11999,7 @@ function createPrepareMemoryStep({
11351
11999
  outputSchema: prepareMemoryStepOutputSchema,
11352
12000
  execute: async ({ tracingContext }) => {
11353
12001
  const thread = threadFromArgs;
11354
- const messageList = new chunkECFXGXWO_cjs.MessageList({
12002
+ const messageList = new chunkG36A2JRR_cjs.MessageList({
11355
12003
  threadId: thread?.id,
11356
12004
  resourceId,
11357
12005
  generateMessageId: capabilities.generateMessageId,
@@ -11432,7 +12080,7 @@ function createPrepareMemoryStep({
11432
12080
  existingThread || hasResourceScopeSemanticRecall ? capabilities.getMemoryMessages({
11433
12081
  resourceId,
11434
12082
  threadId: threadObject.id,
11435
- vectorMessageSearch: new chunkECFXGXWO_cjs.MessageList().add(options.messages, `user`).getLatestUserContent() || "",
12083
+ vectorMessageSearch: new chunkG36A2JRR_cjs.MessageList().add(options.messages, `user`).getLatestUserContent() || "",
11436
12084
  memoryConfig,
11437
12085
  requestContext
11438
12086
  }) : { messages: [] },
@@ -11458,7 +12106,7 @@ The following messages were remembered from a different conversation:
11458
12106
  <remembered_from_other_conversation>
11459
12107
  ${(() => {
11460
12108
  let result = ``;
11461
- const messages = new chunkECFXGXWO_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
12109
+ const messages = new chunkG36A2JRR_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
11462
12110
  let lastYmd = null;
11463
12111
  for (const msg of messages) {
11464
12112
  const date = msg.createdAt;
@@ -11505,7 +12153,7 @@ the following messages are from ${ymd}
11505
12153
  systemMessage,
11506
12154
  memorySystemMessage: memorySystemMessage || void 0
11507
12155
  });
11508
- const processedList = new chunkECFXGXWO_cjs.MessageList({
12156
+ const processedList = new chunkG36A2JRR_cjs.MessageList({
11509
12157
  threadId: threadObject.id,
11510
12158
  resourceId,
11511
12159
  generateMessageId: capabilities.generateMessageId,
@@ -11580,7 +12228,8 @@ function createStreamStep({
11580
12228
  requireToolApproval,
11581
12229
  resumeContext,
11582
12230
  agentId,
11583
- toolCallId
12231
+ toolCallId,
12232
+ methodType
11584
12233
  }) {
11585
12234
  return createStep({
11586
12235
  id: "stream-text-step",
@@ -11598,6 +12247,7 @@ function createStreamStep({
11598
12247
  const processors = validatedInputData.outputProcessors || (capabilities.outputProcessors ? typeof capabilities.outputProcessors === "function" ? await capabilities.outputProcessors({
11599
12248
  requestContext: validatedInputData.requestContext || new chunkJ7O6WENZ_cjs.RequestContext()
11600
12249
  }) : capabilities.outputProcessors : []);
12250
+ const modelMethodType = getModelMethodFromAgentMethod(methodType);
11601
12251
  const streamResult = capabilities.llm.stream({
11602
12252
  ...validatedInputData,
11603
12253
  outputProcessors: processors,
@@ -11609,7 +12259,8 @@ function createStreamStep({
11609
12259
  generateId: capabilities.generateMessageId
11610
12260
  },
11611
12261
  agentId,
11612
- toolCallId
12262
+ toolCallId,
12263
+ methodType: modelMethodType
11613
12264
  });
11614
12265
  return streamResult;
11615
12266
  }
@@ -11665,7 +12316,8 @@ function createPrepareStreamWorkflow({
11665
12316
  requireToolApproval,
11666
12317
  resumeContext,
11667
12318
  agentId,
11668
- toolCallId
12319
+ toolCallId,
12320
+ methodType
11669
12321
  });
11670
12322
  const mapResultsStep = createMapResultsStep({
11671
12323
  capabilities,
@@ -11677,7 +12329,8 @@ function createPrepareStreamWorkflow({
11677
12329
  memoryConfig,
11678
12330
  saveQueueManager,
11679
12331
  agentSpan,
11680
- agentId
12332
+ agentId,
12333
+ methodType
11681
12334
  });
11682
12335
  return createWorkflow({
11683
12336
  id: "execution-workflow",
@@ -11690,7 +12343,8 @@ function createPrepareStreamWorkflow({
11690
12343
  options: {
11691
12344
  tracingPolicy: {
11692
12345
  internal: 1 /* WORKFLOW */
11693
- }
12346
+ },
12347
+ validateInputs: false
11694
12348
  }
11695
12349
  }).parallel([prepareToolsStep, prepareMemoryStep2]).map(mapResultsStep).then(streamStep).commit();
11696
12350
  }
@@ -12288,7 +12942,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
12288
12942
  */
12289
12943
  listTools({ requestContext = new chunkJ7O6WENZ_cjs.RequestContext() } = {}) {
12290
12944
  if (typeof this.#tools !== "function") {
12291
- return chunkWM6CK2F3_cjs.ensureToolProperties(this.#tools);
12945
+ return chunkHBJPYQRN_cjs.ensureToolProperties(this.#tools);
12292
12946
  }
12293
12947
  const result = this.#tools({ requestContext, mastra: this.#mastra });
12294
12948
  return resolveMaybePromise(result, (tools) => {
@@ -12306,7 +12960,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
12306
12960
  this.logger.error(mastraError.toString());
12307
12961
  throw mastraError;
12308
12962
  }
12309
- return chunkWM6CK2F3_cjs.ensureToolProperties(tools);
12963
+ return chunkHBJPYQRN_cjs.ensureToolProperties(tools);
12310
12964
  });
12311
12965
  }
12312
12966
  /**
@@ -12338,7 +12992,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
12338
12992
  });
12339
12993
  });
12340
12994
  } else {
12341
- llm = new chunkVOY2RXOC_cjs.MastraLLMV1({
12995
+ llm = new chunkO6NA3Z43_cjs.MastraLLMV1({
12342
12996
  model: resolvedModel,
12343
12997
  mastra: this.#mastra,
12344
12998
  options: { tracingPolicy: this.#options?.tracingPolicy }
@@ -12363,7 +13017,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
12363
13017
  */
12364
13018
  async resolveModelConfig(modelConfig, requestContext) {
12365
13019
  try {
12366
- return await chunk2ZVKF4HP_cjs.resolveModelConfig(modelConfig, requestContext, this.#mastra);
13020
+ return await chunkN4SJ4YX7_cjs.resolveModelConfig(modelConfig, requestContext, this.#mastra);
12367
13021
  } catch (error) {
12368
13022
  const mastraError = new chunkTWH4PTDG_cjs.MastraError({
12369
13023
  id: "AGENT_GET_MODEL_MISSING_MODEL_INSTANCE",
@@ -12569,7 +13223,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
12569
13223
  instructions
12570
13224
  }) {
12571
13225
  const llm = await this.getLLM({ requestContext, model });
12572
- const normMessage = new chunkECFXGXWO_cjs.MessageList().add(message, "user").get.all.ui().at(-1);
13226
+ const normMessage = new chunkG36A2JRR_cjs.MessageList().add(message, "user").get.all.ui().at(-1);
12573
13227
  if (!normMessage) {
12574
13228
  throw new Error(`Could not generate title from input ${JSON.stringify(message)}`);
12575
13229
  }
@@ -12592,7 +13246,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
12592
13246
  const systemInstructions = await this.resolveTitleInstructions(requestContext, instructions);
12593
13247
  let text = "";
12594
13248
  if (llm.getModel().specificationVersion === "v2") {
12595
- const messageList = new chunkECFXGXWO_cjs.MessageList().add(
13249
+ const messageList = new chunkG36A2JRR_cjs.MessageList().add(
12596
13250
  [
12597
13251
  {
12598
13252
  role: "system",
@@ -12610,6 +13264,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
12610
13264
  "input"
12611
13265
  );
12612
13266
  const result = llm.stream({
13267
+ methodType: "generate",
12613
13268
  requestContext,
12614
13269
  tracingContext,
12615
13270
  messageList,
@@ -12643,7 +13298,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
12643
13298
  async genTitle(userMessage, requestContext, tracingContext, model, instructions) {
12644
13299
  try {
12645
13300
  if (userMessage) {
12646
- const normMessage = new chunkECFXGXWO_cjs.MessageList().add(userMessage, "user").get.all.ui().at(-1);
13301
+ const normMessage = new chunkG36A2JRR_cjs.MessageList().add(userMessage, "user").get.all.ui().at(-1);
12647
13302
  if (normMessage) {
12648
13303
  return await this.generateTitleFromUserMessage({
12649
13304
  message: normMessage,
@@ -12705,7 +13360,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
12705
13360
  model: await this.getModel({ requestContext }),
12706
13361
  tracingPolicy: this.#options?.tracingPolicy
12707
13362
  };
12708
- const convertedToCoreTool = chunkWM6CK2F3_cjs.makeCoreTool(toolObj, options);
13363
+ const convertedToCoreTool = chunkHBJPYQRN_cjs.makeCoreTool(toolObj, options);
12709
13364
  convertedMemoryTools[toolName] = convertedToCoreTool;
12710
13365
  }
12711
13366
  }
@@ -12855,7 +13510,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
12855
13510
  tracingPolicy: this.#options?.tracingPolicy,
12856
13511
  requireApproval: tool.requireApproval
12857
13512
  };
12858
- return [k, chunkWM6CK2F3_cjs.makeCoreTool(tool, options)];
13513
+ return [k, chunkHBJPYQRN_cjs.makeCoreTool(tool, options)];
12859
13514
  })
12860
13515
  );
12861
13516
  const assignedToolEntriesConverted = Object.fromEntries(
@@ -12903,7 +13558,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
12903
13558
  model: await this.getModel({ requestContext }),
12904
13559
  tracingPolicy: this.#options?.tracingPolicy
12905
13560
  };
12906
- const convertedToCoreTool = chunkWM6CK2F3_cjs.makeCoreTool(toolObj, options, "toolset");
13561
+ const convertedToCoreTool = chunkHBJPYQRN_cjs.makeCoreTool(toolObj, options, "toolset");
12907
13562
  toolsForRequest[toolName] = convertedToCoreTool;
12908
13563
  }
12909
13564
  }
@@ -12946,7 +13601,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
12946
13601
  model: await this.getModel({ requestContext }),
12947
13602
  tracingPolicy: this.#options?.tracingPolicy
12948
13603
  };
12949
- const convertedToCoreTool = chunkWM6CK2F3_cjs.makeCoreTool(rest, options, "client-tool");
13604
+ const convertedToCoreTool = chunkHBJPYQRN_cjs.makeCoreTool(rest, options, "client-tool");
12950
13605
  toolsForRequest[toolName] = convertedToCoreTool;
12951
13606
  }
12952
13607
  }
@@ -12977,7 +13632,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
12977
13632
  subAgentResourceId: z5.z.string().describe("The resource ID of the agent").optional()
12978
13633
  });
12979
13634
  const modelVersion = (await agent.getModel()).specificationVersion;
12980
- const toolObj = chunkET6UOTTU_cjs.createTool({
13635
+ const toolObj = chunk4IKJAKCD_cjs.createTool({
12981
13636
  id: `agent-${agentName}`,
12982
13637
  description: `Agent: ${agentName}`,
12983
13638
  inputSchema: agentInputSchema,
@@ -12997,12 +13652,24 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
12997
13652
  });
12998
13653
  let result;
12999
13654
  if ((methodType === "generate" || methodType === "generateLegacy") && modelVersion === "v2") {
13655
+ if (!agent.hasOwnMemory() && this.#memory) {
13656
+ agent.__setMemory(this.#memory);
13657
+ }
13658
+ const subAgentThreadId = crypto2.randomUUID();
13659
+ const slugify = await import('@sindresorhus/slugify');
13660
+ const subAgentResourceId = `${slugify.default(this.id)}-${agentName}`;
13000
13661
  const generateResult = await agent.generate(inputData.prompt, {
13001
13662
  requestContext,
13002
- tracingContext: context?.tracingContext
13663
+ tracingContext: context?.tracingContext,
13664
+ ...resourceId && threadId ? {
13665
+ memory: {
13666
+ resource: subAgentResourceId,
13667
+ thread: subAgentThreadId
13668
+ }
13669
+ } : {}
13003
13670
  });
13004
- result = { text: generateResult.text };
13005
- } else if ((methodType === "generate" || methodType === "generateLegacy") && modelVersion === "v1") {
13671
+ result = { text: generateResult.text, subAgentThreadId, subAgentResourceId };
13672
+ } else if (methodType === "generate" && modelVersion === "v1") {
13006
13673
  const generateResult = await agent.generateLegacy(inputData.prompt, {
13007
13674
  requestContext,
13008
13675
  tracingContext: context?.tracingContext
@@ -13089,7 +13756,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13089
13756
  tracingContext,
13090
13757
  tracingPolicy: this.#options?.tracingPolicy
13091
13758
  };
13092
- convertedAgentTools[`agent-${agentName}`] = chunkWM6CK2F3_cjs.makeCoreTool(toolObj, options);
13759
+ convertedAgentTools[`agent-${agentName}`] = chunkHBJPYQRN_cjs.makeCoreTool(toolObj, options);
13093
13760
  }
13094
13761
  }
13095
13762
  return convertedAgentTools;
@@ -13110,11 +13777,11 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13110
13777
  const workflows = await this.listWorkflows({ requestContext });
13111
13778
  if (Object.keys(workflows).length > 0) {
13112
13779
  for (const [workflowName, workflow] of Object.entries(workflows)) {
13113
- const toolObj = chunkET6UOTTU_cjs.createTool({
13780
+ const toolObj = chunk4IKJAKCD_cjs.createTool({
13114
13781
  id: `workflow-${workflowName}`,
13115
13782
  description: workflow.description || `Workflow: ${workflowName}`,
13116
13783
  inputSchema: workflow.inputSchema,
13117
- outputSchema: workflow.outputSchema,
13784
+ outputSchema: z5.z.object({ result: workflow.outputSchema, runId: z5.z.string() }),
13118
13785
  mastra: this.#mastra,
13119
13786
  // BREAKING CHANGE v1.0: New tool signature - first param is inputData, second is context
13120
13787
  // manually wrap workflow tools with tracing, so that we can pass the
@@ -13161,7 +13828,8 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13161
13828
  }
13162
13829
  result = await streamResult.result;
13163
13830
  }
13164
- return { result, runId: run.runId };
13831
+ const workflowOutput = result?.result || result;
13832
+ return { result: workflowOutput, runId: run.runId };
13165
13833
  } catch (err) {
13166
13834
  const mastraError = new chunkTWH4PTDG_cjs.MastraError(
13167
13835
  {
@@ -13198,7 +13866,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13198
13866
  tracingContext,
13199
13867
  tracingPolicy: this.#options?.tracingPolicy
13200
13868
  };
13201
- convertedWorkflowTools[`workflow-${workflowName}`] = chunkWM6CK2F3_cjs.makeCoreTool(toolObj, options);
13869
+ convertedWorkflowTools[`workflow-${workflowName}`] = chunkHBJPYQRN_cjs.makeCoreTool(toolObj, options);
13202
13870
  }
13203
13871
  }
13204
13872
  return convertedWorkflowTools;
@@ -13221,7 +13889,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13221
13889
  let mastraProxy = void 0;
13222
13890
  const logger = this.logger;
13223
13891
  if (this.#mastra) {
13224
- mastraProxy = chunkWM6CK2F3_cjs.createMastraProxy({ mastra: this.#mastra, logger });
13892
+ mastraProxy = chunkHBJPYQRN_cjs.createMastraProxy({ mastra: this.#mastra, logger });
13225
13893
  }
13226
13894
  const assignedTools = await this.listAssignedTools({
13227
13895
  runId,
@@ -13441,7 +14109,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13441
14109
  if (model || !Array.isArray(this.model)) {
13442
14110
  const modelToUse = model ?? this.model;
13443
14111
  const resolvedModel = typeof modelToUse === "function" ? await modelToUse({ requestContext, mastra: this.#mastra }) : modelToUse;
13444
- if (resolvedModel.specificationVersion !== "v2") {
14112
+ if (resolvedModel?.specificationVersion !== "v2") {
13445
14113
  const mastraError = new chunkTWH4PTDG_cjs.MastraError({
13446
14114
  id: "AGENT_PREPARE_MODELS_INCOMPATIBLE_WITH_MODEL_ARRAY_V1",
13447
14115
  domain: "AGENT" /* AGENT */,
@@ -13458,6 +14126,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13458
14126
  return [
13459
14127
  {
13460
14128
  id: "main",
14129
+ // TODO fix type check
13461
14130
  model: resolvedModel,
13462
14131
  maxRetries: this.maxRetries ?? 0,
13463
14132
  enabled: true
@@ -13467,7 +14136,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13467
14136
  const models = await Promise.all(
13468
14137
  this.model.map(async (modelConfig) => {
13469
14138
  const model2 = await this.resolveModelConfig(modelConfig.model, requestContext);
13470
- if (model2.specificationVersion !== "v2") {
14139
+ if (!isV2Model(model2)) {
13471
14140
  const mastraError = new chunkTWH4PTDG_cjs.MastraError({
13472
14141
  id: "AGENT_PREPARE_MODELS_INCOMPATIBLE_WITH_MODEL_ARRAY_V1",
13473
14142
  domain: "AGENT" /* AGENT */,
@@ -13814,8 +14483,59 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13814
14483
  });
13815
14484
  }
13816
14485
  async generate(messages, options) {
13817
- const result = await this.stream(messages, options);
13818
- const fullOutput = await result.getFullOutput();
14486
+ const defaultOptions = await this.getDefaultOptions({
14487
+ requestContext: options?.requestContext
14488
+ });
14489
+ const mergedOptions = {
14490
+ ...defaultOptions,
14491
+ ...options ?? {}
14492
+ };
14493
+ const llm = await this.getLLM({
14494
+ requestContext: mergedOptions.requestContext
14495
+ });
14496
+ const modelInfo = llm.getModel();
14497
+ if (modelInfo.specificationVersion !== "v2") {
14498
+ const modelId = modelInfo.modelId || "unknown";
14499
+ const provider = modelInfo.provider || "unknown";
14500
+ throw new chunkTWH4PTDG_cjs.MastraError({
14501
+ id: "AGENT_GENERATE_V1_MODEL_NOT_SUPPORTED",
14502
+ domain: "AGENT" /* AGENT */,
14503
+ category: "USER" /* USER */,
14504
+ text: `Agent "${this.name}" is using AI SDK v4 model (${provider}:${modelId}) which is not compatible with generate(). Please use AI SDK v5 models or call the generateLegacy() method instead. See https://mastra.ai/en/docs/streaming/overview for more information.`,
14505
+ details: {
14506
+ agentName: this.name,
14507
+ modelId,
14508
+ provider,
14509
+ specificationVersion: modelInfo.specificationVersion
14510
+ }
14511
+ });
14512
+ }
14513
+ const executeOptions = {
14514
+ ...mergedOptions,
14515
+ messages,
14516
+ methodType: "generate"
14517
+ };
14518
+ const result = await this.#execute(executeOptions);
14519
+ if (result.status !== "success") {
14520
+ if (result.status === "failed") {
14521
+ throw new chunkTWH4PTDG_cjs.MastraError(
14522
+ {
14523
+ id: "AGENT_GENERATE_FAILED",
14524
+ domain: "AGENT" /* AGENT */,
14525
+ category: "USER" /* USER */
14526
+ },
14527
+ // pass original error to preserve stack trace
14528
+ result.error
14529
+ );
14530
+ }
14531
+ throw new chunkTWH4PTDG_cjs.MastraError({
14532
+ id: "AGENT_GENERATE_UNKNOWN_ERROR",
14533
+ domain: "AGENT" /* AGENT */,
14534
+ category: "USER" /* USER */,
14535
+ text: "An unknown error occurred while streaming"
14536
+ });
14537
+ }
14538
+ const fullOutput = await result.result.getFullOutput();
13819
14539
  const error = fullOutput.error;
13820
14540
  if (fullOutput.finishReason === "error" && error) {
13821
14541
  throw error;
@@ -15204,7 +15924,7 @@ var MastraModelOutput = class extends chunkKEXGB7FK_cjs.MastraBase {
15204
15924
  self.messageList,
15205
15925
  options.tracingContext
15206
15926
  );
15207
- const outputText = self.messageList.get.response.aiV4.core().map((m) => chunkECFXGXWO_cjs.MessageList.coreContentToString(m.content)).join("\n");
15927
+ const outputText = self.messageList.get.response.aiV4.core().map((m) => chunkG36A2JRR_cjs.MessageList.coreContentToString(m.content)).join("\n");
15208
15928
  self.#delayedPromises.text.resolve(outputText);
15209
15929
  self.#delayedPromises.finishReason.resolve(self.#finishReason);
15210
15930
  if (chunk.payload.metadata) {
@@ -15827,8 +16547,10 @@ exports.convertFullStreamChunkToUIMessageStream = convertFullStreamChunkToUIMess
15827
16547
  exports.convertMastraChunkToAISDKv5 = convertMastraChunkToAISDKv5;
15828
16548
  exports.createDeprecationProxy = createDeprecationProxy;
15829
16549
  exports.createStep = createStep;
16550
+ exports.createTimeTravelExecutionParams = createTimeTravelExecutionParams;
15830
16551
  exports.createWorkflow = createWorkflow;
15831
16552
  exports.getResumeLabelsByStepId = getResumeLabelsByStepId;
16553
+ exports.getStepIds = getStepIds;
15832
16554
  exports.getStepResult = getStepResult;
15833
16555
  exports.getZodErrors = getZodErrors;
15834
16556
  exports.loop = loop;
@@ -15838,5 +16560,6 @@ exports.runCountDeprecationMessage = runCountDeprecationMessage;
15838
16560
  exports.tryGenerateWithJsonFallback = tryGenerateWithJsonFallback;
15839
16561
  exports.tryStreamWithJsonFallback = tryStreamWithJsonFallback;
15840
16562
  exports.validateStepInput = validateStepInput;
15841
- //# sourceMappingURL=chunk-YCVEJ3UN.cjs.map
15842
- //# sourceMappingURL=chunk-YCVEJ3UN.cjs.map
16563
+ exports.validateStepResumeData = validateStepResumeData;
16564
+ //# sourceMappingURL=chunk-OWX2PUFH.cjs.map
16565
+ //# sourceMappingURL=chunk-OWX2PUFH.cjs.map