@mastra/core 1.0.0-beta.11 → 1.0.0-beta.13

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 (394) hide show
  1. package/CHANGELOG.md +173 -0
  2. package/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +7549 -0
  3. package/dist/_types/@internal_ai-sdk-v4/dist/test.d.ts +65 -0
  4. package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +8396 -0
  5. package/dist/_types/@internal_ai-sdk-v5/dist/test.d.ts +1708 -0
  6. package/dist/_types/@internal_external-types/dist/index.d.ts +858 -0
  7. package/dist/agent/agent-legacy.d.ts +1 -1
  8. package/dist/agent/agent.d.ts +1 -1
  9. package/dist/agent/agent.d.ts.map +1 -1
  10. package/dist/agent/agent.types.d.ts +5 -1
  11. package/dist/agent/agent.types.d.ts.map +1 -1
  12. package/dist/agent/index.cjs +9 -9
  13. package/dist/agent/index.js +2 -2
  14. package/dist/agent/message-list/index.cjs +3 -3
  15. package/dist/agent/message-list/index.d.ts +4 -3
  16. package/dist/agent/message-list/index.d.ts.map +1 -1
  17. package/dist/agent/message-list/index.js +1 -1
  18. package/dist/agent/message-list/prompt/attachments-to-parts.d.ts +1 -1
  19. package/dist/agent/message-list/prompt/invalid-content-error.d.ts +1 -1
  20. package/dist/agent/message-list/types.d.ts +3 -3
  21. package/dist/agent/message-list/types.d.ts.map +1 -1
  22. package/dist/agent/message-list/utils/ai-v4-v5/core-model-message.d.ts +1 -1
  23. package/dist/agent/message-list/utils/ai-v4-v5/ui-message.d.ts +1 -1
  24. package/dist/agent/message-list/utils/ai-v5/gemini-compatibility.d.ts +2 -2
  25. package/dist/agent/message-list/utils/ai-v5/gemini-compatibility.d.ts.map +1 -1
  26. package/dist/agent/message-list/utils/convert-messages.d.ts +2 -2
  27. package/dist/agent/message-list/utils/convert-messages.d.ts.map +1 -1
  28. package/dist/agent/types.d.ts +3 -3
  29. package/dist/agent/utils.d.ts +3 -3
  30. package/dist/agent/utils.d.ts.map +1 -1
  31. package/dist/agent/workflows/prepare-stream/index.d.ts +2 -1
  32. package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
  33. package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts.map +1 -1
  34. package/dist/agent/workflows/prepare-stream/stream-step.d.ts +3 -1
  35. package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
  36. package/dist/bundler/types.d.ts +14 -1
  37. package/dist/bundler/types.d.ts.map +1 -1
  38. package/dist/{chunk-U3XOLEPX.js → chunk-2IU4RGU5.js} +6 -32
  39. package/dist/chunk-2IU4RGU5.js.map +1 -0
  40. package/dist/chunk-2SQB3WBT.js +4574 -0
  41. package/dist/chunk-2SQB3WBT.js.map +1 -0
  42. package/dist/{chunk-THZTRBFS.js → chunk-373OC54J.js} +8 -8
  43. package/dist/chunk-373OC54J.js.map +1 -0
  44. package/dist/{chunk-F2GAJSBI.js → chunk-4BC5FUAO.js} +8 -6
  45. package/dist/{chunk-F2GAJSBI.js.map → chunk-4BC5FUAO.js.map} +1 -1
  46. package/dist/chunk-55VPMN3N.js +250 -0
  47. package/dist/chunk-55VPMN3N.js.map +1 -0
  48. package/dist/{chunk-QM5SRDJX.js → chunk-5PTZG26U.js} +66 -84
  49. package/dist/chunk-5PTZG26U.js.map +1 -0
  50. package/dist/chunk-5VZGJTPR.js +4837 -0
  51. package/dist/chunk-5VZGJTPR.js.map +1 -0
  52. package/dist/{chunk-C36YRTZ6.js → chunk-62Q7K656.js} +6 -7
  53. package/dist/chunk-62Q7K656.js.map +1 -0
  54. package/dist/chunk-6PMMP3FR.js +7 -0
  55. package/dist/chunk-6PMMP3FR.js.map +1 -0
  56. package/dist/{chunk-DZUJEN5N.cjs → chunk-6SZKM6EC.cjs} +10 -3
  57. package/dist/{chunk-DZUJEN5N.cjs.map → chunk-6SZKM6EC.cjs.map} +1 -1
  58. package/dist/{chunk-5WRI5ZAA.js → chunk-7D4SUZUM.js} +10 -4
  59. package/dist/{chunk-5WRI5ZAA.js.map → chunk-7D4SUZUM.js.map} +1 -1
  60. package/dist/{chunk-YWMMBIOM.cjs → chunk-7HEAVZRS.cjs} +15 -15
  61. package/dist/{chunk-YWMMBIOM.cjs.map → chunk-7HEAVZRS.cjs.map} +1 -1
  62. package/dist/{chunk-BUKY6CTR.cjs → chunk-AGHLXC4I.cjs} +106 -36
  63. package/dist/chunk-AGHLXC4I.cjs.map +1 -0
  64. package/dist/{chunk-PK2A5WBG.js → chunk-ARAQIW6E.js} +222 -604
  65. package/dist/chunk-ARAQIW6E.js.map +1 -0
  66. package/dist/{chunk-US2U7ECW.js → chunk-BQDZIQ3G.js} +156 -90
  67. package/dist/chunk-BQDZIQ3G.js.map +1 -0
  68. package/dist/chunk-D22XABFZ.js +79 -0
  69. package/dist/chunk-D22XABFZ.js.map +1 -0
  70. package/dist/{chunk-2ULLRN4Y.js → chunk-E5BQRAJK.js} +943 -626
  71. package/dist/chunk-E5BQRAJK.js.map +1 -0
  72. package/dist/chunk-FST2G2FQ.cjs +84 -0
  73. package/dist/chunk-FST2G2FQ.cjs.map +1 -0
  74. package/dist/chunk-FVQTJUBD.cjs +2120 -0
  75. package/dist/chunk-FVQTJUBD.cjs.map +1 -0
  76. package/dist/chunk-G6E6V2Z4.js +2070 -0
  77. package/dist/chunk-G6E6V2Z4.js.map +1 -0
  78. package/dist/{chunk-7P6BNIJH.js → chunk-GIWC35YQ.js} +105 -35
  79. package/dist/chunk-GIWC35YQ.js.map +1 -0
  80. package/dist/{chunk-4JKEUSCC.cjs → chunk-H4VUIOWU.cjs} +22 -20
  81. package/dist/chunk-H4VUIOWU.cjs.map +1 -0
  82. package/dist/{chunk-TWH4PTDG.cjs → chunk-HWMMIRIF.cjs} +32 -27
  83. package/dist/chunk-HWMMIRIF.cjs.map +1 -0
  84. package/dist/chunk-IXZ2T2QX.cjs +448 -0
  85. package/dist/chunk-IXZ2T2QX.cjs.map +1 -0
  86. package/dist/chunk-L3NKIMF5.cjs +10 -0
  87. package/dist/chunk-L3NKIMF5.cjs.map +1 -0
  88. package/dist/chunk-L4JCRWDY.cjs +252 -0
  89. package/dist/chunk-L4JCRWDY.cjs.map +1 -0
  90. package/dist/{chunk-BJXKH4LG.cjs → chunk-LGB4VNZI.cjs} +43 -78
  91. package/dist/chunk-LGB4VNZI.cjs.map +1 -0
  92. package/dist/{chunk-PG5H6QIO.cjs → chunk-MLKE7HRS.cjs} +41 -21
  93. package/dist/chunk-MLKE7HRS.cjs.map +1 -0
  94. package/dist/{chunk-OEIVMCWX.js → chunk-MRRFTNF4.js} +2537 -84
  95. package/dist/chunk-MRRFTNF4.js.map +1 -0
  96. package/dist/chunk-MXBVP7HX.cjs +4842 -0
  97. package/dist/chunk-MXBVP7HX.cjs.map +1 -0
  98. package/dist/chunk-NESKUIRE.cjs +4586 -0
  99. package/dist/chunk-NESKUIRE.cjs.map +1 -0
  100. package/dist/{chunk-SVLMF4UZ.cjs → chunk-NIOEY3N3.cjs} +66 -85
  101. package/dist/chunk-NIOEY3N3.cjs.map +1 -0
  102. package/dist/{chunk-CZEJQSWB.cjs → chunk-OWIEOL55.cjs} +295 -677
  103. package/dist/chunk-OWIEOL55.cjs.map +1 -0
  104. package/dist/{chunk-WTSZBHIZ.cjs → chunk-PJAK4U6R.cjs} +24 -24
  105. package/dist/{chunk-WTSZBHIZ.cjs.map → chunk-PJAK4U6R.cjs.map} +1 -1
  106. package/dist/{chunk-52RSUALV.cjs → chunk-R5AJGM55.cjs} +1314 -995
  107. package/dist/chunk-R5AJGM55.cjs.map +1 -0
  108. package/dist/{chunk-IVV5TOMD.js → chunk-RCJLMMTO.js} +32 -12
  109. package/dist/chunk-RCJLMMTO.js.map +1 -0
  110. package/dist/{chunk-S73Z3PBJ.cjs → chunk-SZYSDJTN.cjs} +27 -28
  111. package/dist/chunk-SZYSDJTN.cjs.map +1 -0
  112. package/dist/{chunk-YC6PJEPH.cjs → chunk-U4CSOY6T.cjs} +188 -122
  113. package/dist/chunk-U4CSOY6T.cjs.map +1 -0
  114. package/dist/chunk-UBSPZTQX.js +434 -0
  115. package/dist/chunk-UBSPZTQX.js.map +1 -0
  116. package/dist/{chunk-SCUWP4II.cjs → chunk-VEPP75C4.cjs} +47 -74
  117. package/dist/chunk-VEPP75C4.cjs.map +1 -0
  118. package/dist/{chunk-JIGDJK2O.js → chunk-VETAQUW3.js} +4 -39
  119. package/dist/chunk-VETAQUW3.js.map +1 -0
  120. package/dist/{chunk-Z57R5WS4.js → chunk-WPTTKULS.js} +4 -4
  121. package/dist/{chunk-Z57R5WS4.js.map → chunk-WPTTKULS.js.map} +1 -1
  122. package/dist/{chunk-O2BJW7YA.js → chunk-WYGUWVTF.js} +5 -5
  123. package/dist/{chunk-O2BJW7YA.js.map → chunk-WYGUWVTF.js.map} +1 -1
  124. package/dist/{chunk-SXNQRJQD.js → chunk-WYWRMIQC.js} +127 -22
  125. package/dist/chunk-WYWRMIQC.js.map +1 -0
  126. package/dist/{chunk-5Q6WAYEY.cjs → chunk-X6IBA7FP.cjs} +137 -50
  127. package/dist/chunk-X6IBA7FP.cjs.map +1 -0
  128. package/dist/{chunk-MRFUISXC.cjs → chunk-Y7MZ5LJT.cjs} +2632 -179
  129. package/dist/chunk-Y7MZ5LJT.cjs.map +1 -0
  130. package/dist/{chunk-JJ5O45LH.js → chunk-YPLZDWG7.js} +32 -27
  131. package/dist/chunk-YPLZDWG7.js.map +1 -0
  132. package/dist/{chunk-MGCGWPQJ.cjs → chunk-Z55SJVEC.cjs} +8 -8
  133. package/dist/chunk-Z55SJVEC.cjs.map +1 -0
  134. package/dist/error/index.cjs +6 -6
  135. package/dist/error/index.d.ts +26 -20
  136. package/dist/error/index.d.ts.map +1 -1
  137. package/dist/error/index.js +1 -1
  138. package/dist/error/utils.d.ts +19 -5
  139. package/dist/error/utils.d.ts.map +1 -1
  140. package/dist/evals/index.cjs +4 -4
  141. package/dist/evals/index.js +1 -1
  142. package/dist/evals/run/index.d.ts +1 -1
  143. package/dist/evals/scoreTraces/index.cjs +8 -8
  144. package/dist/evals/scoreTraces/index.js +2 -2
  145. package/dist/evals/types.d.ts +1 -1
  146. package/dist/events/event-emitter.d.ts +6 -1
  147. package/dist/events/event-emitter.d.ts.map +1 -1
  148. package/dist/index.cjs +2 -2
  149. package/dist/index.js +1 -1
  150. package/dist/integration/index.cjs +2 -2
  151. package/dist/integration/index.js +1 -1
  152. package/dist/llm/index.cjs +15 -15
  153. package/dist/llm/index.d.ts +2 -2
  154. package/dist/llm/index.d.ts.map +1 -1
  155. package/dist/llm/index.js +5 -5
  156. package/dist/llm/model/aisdk/v5/model.d.ts +1 -1
  157. package/dist/llm/model/base.types.d.ts +2 -2
  158. package/dist/llm/model/model.d.ts +1 -1
  159. package/dist/llm/model/model.d.ts.map +1 -1
  160. package/dist/llm/model/model.loop.d.ts +2 -2
  161. package/dist/llm/model/model.loop.d.ts.map +1 -1
  162. package/dist/llm/model/model.loop.types.d.ts +1 -1
  163. package/dist/llm/model/model.loop.types.d.ts.map +1 -1
  164. package/dist/llm/model/provider-types.generated.d.ts +51 -11
  165. package/dist/llm/model/shared.types.d.ts +1 -1
  166. package/dist/loop/index.cjs +2 -2
  167. package/dist/loop/index.js +1 -1
  168. package/dist/loop/loop.d.ts +2 -2
  169. package/dist/loop/loop.d.ts.map +1 -1
  170. package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts +1 -1
  171. package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts.map +1 -1
  172. package/dist/loop/test-utils/options.d.ts.map +1 -1
  173. package/dist/loop/test-utils/streamObject.d.ts +1 -1
  174. package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
  175. package/dist/loop/test-utils/tools.d.ts.map +1 -1
  176. package/dist/loop/types.d.ts +3 -1
  177. package/dist/loop/types.d.ts.map +1 -1
  178. package/dist/loop/workflows/agentic-execution/index.d.ts +13 -13
  179. package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
  180. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +10 -10
  181. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
  182. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +5 -5
  183. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
  184. package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts +22 -21
  185. package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
  186. package/dist/loop/workflows/agentic-loop/index.d.ts +13 -13
  187. package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
  188. package/dist/loop/workflows/schema.d.ts +6 -6
  189. package/dist/loop/workflows/schema.d.ts.map +1 -1
  190. package/dist/loop/workflows/stream.d.ts +2 -2
  191. package/dist/loop/workflows/stream.d.ts.map +1 -1
  192. package/dist/mastra/index.cjs +2 -2
  193. package/dist/mastra/index.js +1 -1
  194. package/dist/mcp/index.cjs +4 -4
  195. package/dist/mcp/index.js +1 -1
  196. package/dist/memory/index.cjs +6 -6
  197. package/dist/memory/index.js +1 -1
  198. package/dist/memory/memory.d.ts +1 -1
  199. package/dist/memory/types.d.ts +3 -3
  200. package/dist/memory/types.d.ts.map +1 -1
  201. package/dist/models-dev-D3EKFGAO.cjs +12 -0
  202. package/dist/{models-dev-EO3SUIY2.cjs.map → models-dev-D3EKFGAO.cjs.map} +1 -1
  203. package/dist/models-dev-EO22XOXQ.js +3 -0
  204. package/dist/{models-dev-23RN2WHG.js.map → models-dev-EO22XOXQ.js.map} +1 -1
  205. package/dist/netlify-AE4LNCAI.js +3 -0
  206. package/dist/{netlify-GXJ5D5DD.js.map → netlify-AE4LNCAI.js.map} +1 -1
  207. package/dist/netlify-WE42TZIT.cjs +12 -0
  208. package/dist/{netlify-KJLY3GFS.cjs.map → netlify-WE42TZIT.cjs.map} +1 -1
  209. package/dist/processors/index.cjs +37 -37
  210. package/dist/processors/index.d.ts +2 -2
  211. package/dist/processors/index.d.ts.map +1 -1
  212. package/dist/processors/index.js +1 -1
  213. package/dist/processors/step-schema.d.ts +1267 -1267
  214. package/dist/processors/step-schema.d.ts.map +1 -1
  215. package/dist/provider-registry-6LF3NGC5.js +3 -0
  216. package/dist/{provider-registry-F67Y6OF2.js.map → provider-registry-6LF3NGC5.js.map} +1 -1
  217. package/dist/provider-registry-73FKMXJV.cjs +40 -0
  218. package/dist/{provider-registry-3TG2KUD2.cjs.map → provider-registry-73FKMXJV.cjs.map} +1 -1
  219. package/dist/provider-registry.json +100 -30
  220. package/dist/{registry-generator-UMTNPBJX.js → registry-generator-AVQXI3GX.js} +2 -2
  221. package/dist/{registry-generator-UMTNPBJX.js.map → registry-generator-AVQXI3GX.js.map} +1 -1
  222. package/dist/{registry-generator-34SC4TAU.cjs → registry-generator-KOFNIIWJ.cjs} +2 -2
  223. package/dist/{registry-generator-34SC4TAU.cjs.map → registry-generator-KOFNIIWJ.cjs.map} +1 -1
  224. package/dist/relevance/index.cjs +2 -2
  225. package/dist/relevance/index.js +1 -1
  226. package/dist/server/index.cjs +5 -5
  227. package/dist/server/index.js +1 -1
  228. package/dist/storage/base.d.ts +2 -10
  229. package/dist/storage/base.d.ts.map +1 -1
  230. package/dist/storage/domains/workflows/base.d.ts +2 -8
  231. package/dist/storage/domains/workflows/base.d.ts.map +1 -1
  232. package/dist/storage/domains/workflows/inmemory.d.ts +2 -8
  233. package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
  234. package/dist/storage/index.cjs +38 -38
  235. package/dist/storage/index.js +1 -1
  236. package/dist/storage/mock.d.ts +2 -8
  237. package/dist/storage/mock.d.ts.map +1 -1
  238. package/dist/storage/types.d.ts +9 -1
  239. package/dist/storage/types.d.ts.map +1 -1
  240. package/dist/stream/RunOutput.d.ts +1 -1
  241. package/dist/stream/aisdk/v4/input.d.ts +1 -1
  242. package/dist/stream/aisdk/v5/compat/content.d.ts +1 -1
  243. package/dist/stream/aisdk/v5/compat/content.d.ts.map +1 -1
  244. package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts +1 -1
  245. package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
  246. package/dist/stream/aisdk/v5/compat/ui-message.d.ts +1 -1
  247. package/dist/stream/aisdk/v5/compat/ui-message.d.ts.map +1 -1
  248. package/dist/stream/aisdk/v5/compat/validation.d.ts +1 -1
  249. package/dist/stream/aisdk/v5/compat/validation.d.ts.map +1 -1
  250. package/dist/stream/aisdk/v5/execute.d.ts +2 -2
  251. package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
  252. package/dist/stream/aisdk/v5/input.d.ts +1 -1
  253. package/dist/stream/aisdk/v5/input.d.ts.map +1 -1
  254. package/dist/stream/aisdk/v5/output-helpers.d.ts +12 -27
  255. package/dist/stream/aisdk/v5/output-helpers.d.ts.map +1 -1
  256. package/dist/stream/aisdk/v5/output.d.ts +41 -91
  257. package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
  258. package/dist/stream/aisdk/v5/transform.d.ts +1 -1
  259. package/dist/stream/aisdk/v5/transform.d.ts.map +1 -1
  260. package/dist/stream/base/input.d.ts +1 -1
  261. package/dist/stream/base/output.d.ts +9 -31
  262. package/dist/stream/base/output.d.ts.map +1 -1
  263. package/dist/stream/base/schema.d.ts +2 -2
  264. package/dist/stream/base/schema.d.ts.map +1 -1
  265. package/dist/stream/index.cjs +12 -12
  266. package/dist/stream/index.js +2 -2
  267. package/dist/stream/types.d.ts +3 -2
  268. package/dist/stream/types.d.ts.map +1 -1
  269. package/dist/test-utils/llm-mock.cjs +14587 -14
  270. package/dist/test-utils/llm-mock.cjs.map +1 -1
  271. package/dist/test-utils/llm-mock.d.ts +3 -3
  272. package/dist/test-utils/llm-mock.d.ts.map +1 -1
  273. package/dist/test-utils/llm-mock.js +14577 -4
  274. package/dist/test-utils/llm-mock.js.map +1 -1
  275. package/dist/token-6GSAFR2W-SGVIXFCP.cjs +63 -0
  276. package/dist/token-6GSAFR2W-SGVIXFCP.cjs.map +1 -0
  277. package/dist/token-6GSAFR2W-SPYPLMBM.js +61 -0
  278. package/dist/token-6GSAFR2W-SPYPLMBM.js.map +1 -0
  279. package/dist/token-util-NEHG7TUY-7GMW5FXI.cjs +10 -0
  280. package/dist/token-util-NEHG7TUY-7GMW5FXI.cjs.map +1 -0
  281. package/dist/token-util-NEHG7TUY-JRJTGTAB.js +8 -0
  282. package/dist/token-util-NEHG7TUY-JRJTGTAB.js.map +1 -0
  283. package/dist/tools/index.cjs +4 -4
  284. package/dist/tools/index.js +1 -1
  285. package/dist/tools/is-vercel-tool.cjs +2 -2
  286. package/dist/tools/is-vercel-tool.js +1 -1
  287. package/dist/tools/tool-builder/builder.d.ts +2 -1
  288. package/dist/tools/tool-builder/builder.d.ts.map +1 -1
  289. package/dist/tools/tool.d.ts.map +1 -1
  290. package/dist/tools/types.d.ts +5 -5
  291. package/dist/tools/types.d.ts.map +1 -1
  292. package/dist/utils.cjs +22 -22
  293. package/dist/utils.d.ts +3 -3
  294. package/dist/utils.d.ts.map +1 -1
  295. package/dist/utils.js +1 -1
  296. package/dist/vector/embed.d.ts +2 -2
  297. package/dist/vector/embed.d.ts.map +1 -1
  298. package/dist/vector/index.cjs +11 -11
  299. package/dist/vector/index.js +3 -3
  300. package/dist/vector/vector.d.ts +1 -1
  301. package/dist/voice/aisdk/speech.d.ts +1 -1
  302. package/dist/voice/aisdk/speech.d.ts.map +1 -1
  303. package/dist/voice/aisdk/transcription.d.ts +1 -1
  304. package/dist/voice/aisdk/transcription.d.ts.map +1 -1
  305. package/dist/voice/composite-voice.d.ts +1 -1
  306. package/dist/voice/composite-voice.d.ts.map +1 -1
  307. package/dist/voice/index.cjs +6 -6
  308. package/dist/voice/index.js +1 -1
  309. package/dist/workflows/constants.cjs +4 -4
  310. package/dist/workflows/constants.d.ts +1 -1
  311. package/dist/workflows/constants.d.ts.map +1 -1
  312. package/dist/workflows/constants.js +1 -1
  313. package/dist/workflows/default.d.ts +9 -16
  314. package/dist/workflows/default.d.ts.map +1 -1
  315. package/dist/workflows/evented/execution-engine.d.ts +3 -2
  316. package/dist/workflows/evented/execution-engine.d.ts.map +1 -1
  317. package/dist/workflows/evented/index.cjs +10 -10
  318. package/dist/workflows/evented/index.js +1 -1
  319. package/dist/workflows/evented/step-executor.d.ts +1 -1
  320. package/dist/workflows/evented/step-executor.d.ts.map +1 -1
  321. package/dist/workflows/evented/workflow-event-processor/index.d.ts +1 -1
  322. package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
  323. package/dist/workflows/evented/workflow.d.ts +15 -0
  324. package/dist/workflows/evented/workflow.d.ts.map +1 -1
  325. package/dist/workflows/execution-engine.d.ts +25 -2
  326. package/dist/workflows/execution-engine.d.ts.map +1 -1
  327. package/dist/workflows/handlers/control-flow.d.ts +6 -5
  328. package/dist/workflows/handlers/control-flow.d.ts.map +1 -1
  329. package/dist/workflows/handlers/entry.d.ts +5 -3
  330. package/dist/workflows/handlers/entry.d.ts.map +1 -1
  331. package/dist/workflows/handlers/sleep.d.ts +4 -3
  332. package/dist/workflows/handlers/sleep.d.ts.map +1 -1
  333. package/dist/workflows/handlers/step.d.ts +5 -3
  334. package/dist/workflows/handlers/step.d.ts.map +1 -1
  335. package/dist/workflows/index.cjs +26 -22
  336. package/dist/workflows/index.js +1 -1
  337. package/dist/workflows/step.d.ts +5 -4
  338. package/dist/workflows/step.d.ts.map +1 -1
  339. package/dist/workflows/types.d.ts +66 -14
  340. package/dist/workflows/types.d.ts.map +1 -1
  341. package/dist/workflows/utils.d.ts +11 -0
  342. package/dist/workflows/utils.d.ts.map +1 -1
  343. package/dist/workflows/workflow.d.ts +26 -8
  344. package/dist/workflows/workflow.d.ts.map +1 -1
  345. package/package.json +12 -11
  346. package/src/llm/model/provider-types.generated.d.ts +51 -11
  347. package/dist/agent/__tests__/mock-model.d.ts +0 -8
  348. package/dist/agent/__tests__/mock-model.d.ts.map +0 -1
  349. package/dist/agent/agent-types.test-d.d.ts +0 -2
  350. package/dist/agent/agent-types.test-d.d.ts.map +0 -1
  351. package/dist/ai-sdk.types.d.ts +0 -4705
  352. package/dist/chunk-2ULLRN4Y.js.map +0 -1
  353. package/dist/chunk-3E3ILV6T.cjs +0 -518
  354. package/dist/chunk-3E3ILV6T.cjs.map +0 -1
  355. package/dist/chunk-4JKEUSCC.cjs.map +0 -1
  356. package/dist/chunk-52RSUALV.cjs.map +0 -1
  357. package/dist/chunk-5PAEYE3Q.js +0 -513
  358. package/dist/chunk-5PAEYE3Q.js.map +0 -1
  359. package/dist/chunk-5Q6WAYEY.cjs.map +0 -1
  360. package/dist/chunk-7P6BNIJH.js.map +0 -1
  361. package/dist/chunk-ABJOUEVA.cjs +0 -10
  362. package/dist/chunk-ABJOUEVA.cjs.map +0 -1
  363. package/dist/chunk-BJXKH4LG.cjs.map +0 -1
  364. package/dist/chunk-BUKY6CTR.cjs.map +0 -1
  365. package/dist/chunk-C36YRTZ6.js.map +0 -1
  366. package/dist/chunk-CZEJQSWB.cjs.map +0 -1
  367. package/dist/chunk-IVV5TOMD.js.map +0 -1
  368. package/dist/chunk-JIGDJK2O.js.map +0 -1
  369. package/dist/chunk-JJ5O45LH.js.map +0 -1
  370. package/dist/chunk-MGCGWPQJ.cjs.map +0 -1
  371. package/dist/chunk-MRFUISXC.cjs.map +0 -1
  372. package/dist/chunk-NLNKQD2T.js +0 -7
  373. package/dist/chunk-NLNKQD2T.js.map +0 -1
  374. package/dist/chunk-OEIVMCWX.js.map +0 -1
  375. package/dist/chunk-PG5H6QIO.cjs.map +0 -1
  376. package/dist/chunk-PK2A5WBG.js.map +0 -1
  377. package/dist/chunk-QM5SRDJX.js.map +0 -1
  378. package/dist/chunk-S73Z3PBJ.cjs.map +0 -1
  379. package/dist/chunk-SCUWP4II.cjs.map +0 -1
  380. package/dist/chunk-SVLMF4UZ.cjs.map +0 -1
  381. package/dist/chunk-SXNQRJQD.js.map +0 -1
  382. package/dist/chunk-THZTRBFS.js.map +0 -1
  383. package/dist/chunk-TWH4PTDG.cjs.map +0 -1
  384. package/dist/chunk-U3XOLEPX.js.map +0 -1
  385. package/dist/chunk-US2U7ECW.js.map +0 -1
  386. package/dist/chunk-YC6PJEPH.cjs.map +0 -1
  387. package/dist/models-dev-23RN2WHG.js +0 -3
  388. package/dist/models-dev-EO3SUIY2.cjs +0 -12
  389. package/dist/netlify-GXJ5D5DD.js +0 -3
  390. package/dist/netlify-KJLY3GFS.cjs +0 -12
  391. package/dist/provider-registry-3TG2KUD2.cjs +0 -40
  392. package/dist/provider-registry-F67Y6OF2.js +0 -3
  393. package/dist/tools/tool-stream-types.test-d.d.ts +0 -2
  394. package/dist/tools/tool-stream-types.test-d.d.ts.map +0 -1
@@ -1,31 +1,32 @@
1
- import { DefaultVoice } from './chunk-F2GAJSBI.js';
2
- import { EMITTER_SYMBOL, STREAM_FORMAT_SYMBOL } from './chunk-NLNKQD2T.js';
3
- import { InMemoryStore } from './chunk-JIGDJK2O.js';
4
- import { MessageList, DefaultGeneratedFile, DefaultGeneratedFileWithType } from './chunk-SXNQRJQD.js';
5
- import { resolveModelConfig, ModelRouterEmbeddingModel } from './chunk-5PAEYE3Q.js';
6
- import { MastraLLMV1 } from './chunk-C36YRTZ6.js';
1
+ import { DefaultVoice } from './chunk-4BC5FUAO.js';
2
+ import { PUBSUB_SYMBOL, STREAM_FORMAT_SYMBOL } from './chunk-6PMMP3FR.js';
3
+ import { InMemoryStore } from './chunk-VETAQUW3.js';
4
+ import { MessageList, DefaultGeneratedFile, DefaultGeneratedFileWithType, isAbortError, injectJsonInstructionIntoMessages } from './chunk-WYWRMIQC.js';
5
+ import { createTextStreamResponse, createUIMessageStreamResponse, createUIMessageStream, parsePartialJson, isDeepEqualData, stepCountIs } from './chunk-2SQB3WBT.js';
6
+ import { generateId, asSchema, jsonSchema, APICallError, tool } from './chunk-G6E6V2Z4.js';
7
+ import { PubSub } from './chunk-BVUMKER5.js';
7
8
  import { executeHook } from './chunk-L54GIUCB.js';
8
- import { removeUndefinedValues, ensureToolProperties, makeCoreTool, createMastraProxy, isZodType, deepMerge, selectFields, delay } from './chunk-IVV5TOMD.js';
9
- import { getOrCreateSpan, wrapMastra, executeWithContextSync } from './chunk-Y36Y5MTD.js';
10
- import { MastraError, getErrorFromUnknown } from './chunk-JJ5O45LH.js';
9
+ import { resolveModelConfig, ModelRouterEmbeddingModel } from './chunk-5VZGJTPR.js';
10
+ import { MastraLLMV1 } from './chunk-62Q7K656.js';
11
+ import { removeUndefinedValues, ensureToolProperties, makeCoreTool, createMastraProxy, isZodType, deepMerge, selectFields, delay } from './chunk-RCJLMMTO.js';
11
12
  import { ToolStream } from './chunk-DD2VNRQM.js';
12
- import { Tool, createTool } from './chunk-THZTRBFS.js';
13
+ import { Tool, createTool } from './chunk-373OC54J.js';
14
+ import { getOrCreateSpan, wrapMastra, executeWithContextSync } from './chunk-Y36Y5MTD.js';
13
15
  import { RequestContext, MASTRA_RESOURCE_ID_KEY, MASTRA_THREAD_ID_KEY } from './chunk-6TBWJV35.js';
16
+ import { MastraError, getErrorFromUnknown } from './chunk-YPLZDWG7.js';
14
17
  import { zodToJsonSchema as zodToJsonSchema$1 } from './chunk-PJKCPRYF.js';
15
18
  import { MastraBase } from './chunk-LSHPJWM5.js';
16
19
  import { RegisteredLogger, ConsoleLogger } from './chunk-NRUZYMHE.js';
17
- import { __commonJS, __toESM } from './chunk-5WRI5ZAA.js';
18
- import z7, { z, ZodObject } from 'zod';
20
+ import { __commonJS, __toESM } from './chunk-7D4SUZUM.js';
21
+ import z8, { z, ZodObject } from 'zod';
19
22
  import * as crypto2 from 'crypto';
20
23
  import { randomUUID } from 'crypto';
21
24
  import { TransformStream, ReadableStream as ReadableStream$1, WritableStream as WritableStream$1 } from 'stream/web';
22
25
  import EventEmitter2, { EventEmitter } from 'events';
23
26
  import { getErrorMessage, TypeValidationError } from '@ai-sdk/provider-v5';
24
- import { createTextStreamResponse, createUIMessageStreamResponse, createUIMessageStream, generateId, asSchema, parsePartialJson, isDeepEqualData, jsonSchema, APICallError, tool, stepCountIs } from 'ai-v5';
25
27
  import z4 from 'zod/v4';
26
28
  import { OpenAIReasoningSchemaCompatLayer, OpenAISchemaCompatLayer, GoogleSchemaCompatLayer, AnthropicSchemaCompatLayer, DeepSeekSchemaCompatLayer, MetaSchemaCompatLayer, applyCompatLayer } from '@mastra/schema-compat';
27
29
  import { isEmpty } from 'radash';
28
- import { isAbortError, injectJsonInstructionIntoMessages } from '@ai-sdk/provider-utils-v5';
29
30
  import { Tiktoken } from 'js-tiktoken/lite';
30
31
  import o200k_base from 'js-tiktoken/ranks/o200k_base';
31
32
  import { LRUCache } from 'lru-cache';
@@ -426,6 +427,8 @@ var DelayedPromise = class {
426
427
  }
427
428
  }
428
429
  };
430
+
431
+ // src/stream/aisdk/v5/compat/prepare-tools.ts
429
432
  function prepareToolsAndToolChoice({
430
433
  tools,
431
434
  toolChoice,
@@ -439,17 +442,17 @@ function prepareToolsAndToolChoice({
439
442
  }
440
443
  const filteredTools = activeTools != null ? Object.entries(tools || {}).filter(([name]) => activeTools.includes(name)) : Object.entries(tools || {});
441
444
  return {
442
- tools: filteredTools.map(([name, tool$1]) => {
445
+ tools: filteredTools.map(([name, tool2]) => {
443
446
  try {
444
447
  let inputSchema;
445
- if ("inputSchema" in tool$1) {
446
- inputSchema = tool$1.inputSchema;
447
- } else if ("parameters" in tool$1) {
448
- inputSchema = tool$1.parameters;
448
+ if ("inputSchema" in tool2) {
449
+ inputSchema = tool2.inputSchema;
450
+ } else if ("parameters" in tool2) {
451
+ inputSchema = tool2.parameters;
449
452
  }
450
453
  const sdkTool = tool({
451
454
  type: "function",
452
- ...tool$1,
455
+ ...tool2,
453
456
  inputSchema
454
457
  });
455
458
  const toolType = sdkTool?.type ?? "function";
@@ -489,7 +492,7 @@ function prepareToolsAndToolChoice({
489
492
  console.error("Error preparing tool", e);
490
493
  return null;
491
494
  }
492
- }).filter((tool) => tool !== null),
495
+ }).filter((tool2) => tool2 !== null),
493
496
  toolChoice: toolChoice == null ? { type: "auto" } : typeof toolChoice === "string" ? { type: toolChoice } : { type: "tool", toolName: toolChoice.toolName }
494
497
  };
495
498
  }
@@ -2366,6 +2369,8 @@ var AISDKV5OutputStream = class {
2366
2369
  return this.#modelOutput.object;
2367
2370
  }
2368
2371
  };
2372
+
2373
+ // src/stream/base/schema.ts
2369
2374
  function asJsonSchema(schema) {
2370
2375
  if (!schema) {
2371
2376
  return void 0;
@@ -4591,6 +4596,36 @@ function runScorer({
4591
4596
  function isV2Model(model) {
4592
4597
  return model.specificationVersion === "v2";
4593
4598
  }
4599
+ var EventEmitterPubSub = class extends PubSub {
4600
+ emitter;
4601
+ constructor(existingEmitter) {
4602
+ super();
4603
+ this.emitter = existingEmitter ?? new EventEmitter2();
4604
+ }
4605
+ async publish(topic, event) {
4606
+ const id = crypto.randomUUID();
4607
+ const createdAt = /* @__PURE__ */ new Date();
4608
+ this.emitter.emit(topic, {
4609
+ ...event,
4610
+ id,
4611
+ createdAt
4612
+ });
4613
+ }
4614
+ async subscribe(topic, cb) {
4615
+ this.emitter.on(topic, cb);
4616
+ }
4617
+ async unsubscribe(topic, cb) {
4618
+ this.emitter.off(topic, cb);
4619
+ }
4620
+ async flush() {
4621
+ }
4622
+ /**
4623
+ * Clean up all listeners during graceful shutdown.
4624
+ */
4625
+ async close() {
4626
+ this.emitter.removeAllListeners();
4627
+ }
4628
+ };
4594
4629
  var TextPartSchema = z.object({
4595
4630
  type: z.literal("text"),
4596
4631
  text: z.string()
@@ -4818,6 +4853,43 @@ var ExecutionEngine = class extends MastraBase {
4818
4853
  getLogger() {
4819
4854
  return this.logger;
4820
4855
  }
4856
+ /**
4857
+ * Invokes the onFinish and onError lifecycle callbacks if they are defined.
4858
+ * Errors in callbacks are caught and logged, not propagated.
4859
+ * @param result The workflow result containing status, result, error, steps, and tripwire info
4860
+ */
4861
+ async invokeLifecycleCallbacks(result) {
4862
+ const { onFinish, onError } = this.options;
4863
+ if (onFinish) {
4864
+ try {
4865
+ await Promise.resolve(
4866
+ onFinish({
4867
+ status: result.status,
4868
+ result: result.result,
4869
+ error: result.error,
4870
+ steps: result.steps,
4871
+ tripwire: result.tripwire
4872
+ })
4873
+ );
4874
+ } catch (err) {
4875
+ this.logger.error("Error in onFinish callback", { error: err });
4876
+ }
4877
+ }
4878
+ if (onError && (result.status === "failed" || result.status === "tripwire")) {
4879
+ try {
4880
+ await Promise.resolve(
4881
+ onError({
4882
+ status: result.status,
4883
+ error: result.error,
4884
+ steps: result.steps,
4885
+ tripwire: result.tripwire
4886
+ })
4887
+ );
4888
+ } catch (err) {
4889
+ this.logger.error("Error in onError callback", { error: err });
4890
+ }
4891
+ }
4892
+ }
4821
4893
  };
4822
4894
 
4823
4895
  // src/workflows/step.ts
@@ -4850,7 +4922,16 @@ async function validateStepInput({
4850
4922
  if (!validatedInput.success) {
4851
4923
  const errors = getZodErrors(validatedInput.error);
4852
4924
  const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
4853
- validationError = new Error("Step input validation failed: \n" + errorMessages);
4925
+ validationError = new MastraError(
4926
+ {
4927
+ id: "WORKFLOW_STEP_INPUT_VALIDATION_FAILED",
4928
+ domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
4929
+ category: "USER" /* USER */,
4930
+ text: "Step input validation failed: \n" + errorMessages
4931
+ },
4932
+ // keep the original zod error as the cause for consumers
4933
+ validatedInput.error
4934
+ );
4854
4935
  } else {
4855
4936
  const isEmptyData = isEmpty(validatedInput.data);
4856
4937
  inputData = isEmptyData ? prevOutput : validatedInput.data;
@@ -4869,7 +4950,16 @@ async function validateStepResumeData({ resumeData, step }) {
4869
4950
  if (!validatedResumeData.success) {
4870
4951
  const errors = getZodErrors(validatedResumeData.error);
4871
4952
  const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
4872
- validationError = new Error("Step resume data validation failed: \n" + errorMessages);
4953
+ validationError = new MastraError(
4954
+ {
4955
+ id: "WORKFLOW_STEP_RESUME_DATA_VALIDATION_FAILED",
4956
+ domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
4957
+ category: "USER" /* USER */,
4958
+ text: "Step resume data validation failed: \n" + errorMessages
4959
+ },
4960
+ // keep the original zod error as the cause for consumers
4961
+ validatedResumeData.error
4962
+ );
4873
4963
  } else {
4874
4964
  resumeData = validatedResumeData.data;
4875
4965
  }
@@ -4891,7 +4981,16 @@ async function validateStepSuspendData({
4891
4981
  if (!validatedSuspendData.success) {
4892
4982
  const errors = getZodErrors(validatedSuspendData.error);
4893
4983
  const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
4894
- validationError = new Error("Step suspend data validation failed: \n" + errorMessages);
4984
+ validationError = new MastraError(
4985
+ {
4986
+ id: "WORKFLOW_STEP_SUSPEND_DATA_VALIDATION_FAILED",
4987
+ domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
4988
+ category: "USER" /* USER */,
4989
+ text: "Step suspend data validation failed: \n" + errorMessages
4990
+ },
4991
+ // keep the original zod error as the cause for consumers
4992
+ validatedSuspendData.error
4993
+ );
4895
4994
  } else {
4896
4995
  suspendData = validatedSuspendData.data;
4897
4996
  }
@@ -5055,6 +5154,16 @@ var createTimeTravelExecutionParams = (params) => {
5055
5154
  };
5056
5155
  return timeTravelData;
5057
5156
  };
5157
+ function hydrateSerializedStepErrors(steps) {
5158
+ if (steps) {
5159
+ for (const step of Object.values(steps)) {
5160
+ if (step.status === "failed" && "error" in step && step.error) {
5161
+ step.error = getErrorFromUnknown(step.error, { serializeStack: false });
5162
+ }
5163
+ }
5164
+ }
5165
+ return steps;
5166
+ }
5058
5167
 
5059
5168
  // src/workflows/handlers/control-flow.ts
5060
5169
  async function executeParallel(engine, params) {
@@ -5071,7 +5180,7 @@ async function executeParallel(engine, params) {
5071
5180
  timeTravel,
5072
5181
  executionContext,
5073
5182
  tracingContext,
5074
- emitter,
5183
+ pubsub,
5075
5184
  abortController,
5076
5185
  requestContext,
5077
5186
  outputWriter,
@@ -5144,7 +5253,7 @@ async function executeParallel(engine, params) {
5144
5253
  tracingContext: {
5145
5254
  currentSpan: parallelSpan
5146
5255
  },
5147
- emitter,
5256
+ pubsub,
5148
5257
  abortController,
5149
5258
  requestContext,
5150
5259
  outputWriter,
@@ -5183,9 +5292,7 @@ async function executeParallel(engine, params) {
5183
5292
  };
5184
5293
  }
5185
5294
  if (execResults.status === "failed") {
5186
- parallelSpan?.error({
5187
- error: new Error(execResults.error)
5188
- });
5295
+ parallelSpan?.error({ error: execResults.error });
5189
5296
  } else {
5190
5297
  parallelSpan?.end({
5191
5298
  output: execResults.output || execResults
@@ -5207,7 +5314,7 @@ async function executeConditional(engine, params) {
5207
5314
  timeTravel,
5208
5315
  executionContext,
5209
5316
  tracingContext,
5210
- emitter,
5317
+ pubsub,
5211
5318
  abortController,
5212
5319
  requestContext,
5213
5320
  outputWriter,
@@ -5254,7 +5361,7 @@ async function executeConditional(engine, params) {
5254
5361
  abort: () => {
5255
5362
  abortController?.abort();
5256
5363
  },
5257
- [EMITTER_SYMBOL]: emitter,
5364
+ [PUBSUB_SYMBOL]: pubsub,
5258
5365
  [STREAM_FORMAT_SYMBOL]: executionContext.format,
5259
5366
  engine: engine.getEngineContext(),
5260
5367
  abortSignal: abortController?.signal,
@@ -5284,18 +5391,20 @@ async function executeConditional(engine, params) {
5284
5391
  });
5285
5392
  return result;
5286
5393
  } catch (e) {
5287
- const error = engine.preprocessExecutionError(
5288
- e,
5394
+ const errorInstance = getErrorFromUnknown(e, { serializeStack: false });
5395
+ const mastraError = new MastraError(
5289
5396
  {
5290
5397
  id: "WORKFLOW_CONDITION_EVALUATION_FAILED",
5291
- domain: "MASTRA_WORKFLOW",
5292
- category: "USER",
5398
+ domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
5399
+ category: "USER" /* USER */,
5293
5400
  details: { workflowId, runId }
5294
5401
  },
5295
- "Error evaluating condition: "
5402
+ errorInstance
5296
5403
  );
5404
+ engine.getLogger()?.trackException(mastraError);
5405
+ engine.getLogger()?.error("Error evaluating condition: " + errorInstance.stack);
5297
5406
  evalSpan?.error({
5298
- error,
5407
+ error: mastraError,
5299
5408
  attributes: {
5300
5409
  result: false
5301
5410
  }
@@ -5347,7 +5456,7 @@ async function executeConditional(engine, params) {
5347
5456
  tracingContext: {
5348
5457
  currentSpan: conditionalSpan
5349
5458
  },
5350
- emitter,
5459
+ pubsub,
5351
5460
  abortController,
5352
5461
  requestContext,
5353
5462
  outputWriter,
@@ -5387,9 +5496,7 @@ async function executeConditional(engine, params) {
5387
5496
  };
5388
5497
  }
5389
5498
  if (execResults.status === "failed") {
5390
- conditionalSpan?.error({
5391
- error: new Error(execResults.error)
5392
- });
5499
+ conditionalSpan?.error({ error: execResults.error });
5393
5500
  } else {
5394
5501
  conditionalSpan?.end({
5395
5502
  output: execResults.output || execResults
@@ -5410,7 +5517,7 @@ async function executeLoop(engine, params) {
5410
5517
  timeTravel,
5411
5518
  executionContext,
5412
5519
  tracingContext,
5413
- emitter,
5520
+ pubsub,
5414
5521
  abortController,
5415
5522
  requestContext,
5416
5523
  outputWriter,
@@ -5450,7 +5557,7 @@ async function executeLoop(engine, params) {
5450
5557
  tracingContext: {
5451
5558
  currentSpan: loopSpan
5452
5559
  },
5453
- emitter,
5560
+ pubsub,
5454
5561
  abortController,
5455
5562
  requestContext,
5456
5563
  outputWriter,
@@ -5504,7 +5611,7 @@ async function executeLoop(engine, params) {
5504
5611
  abort: () => {
5505
5612
  abortController?.abort();
5506
5613
  },
5507
- [EMITTER_SYMBOL]: emitter,
5614
+ [PUBSUB_SYMBOL]: pubsub,
5508
5615
  [STREAM_FORMAT_SYMBOL]: executionContext.format,
5509
5616
  engine: engine.getEngineContext(),
5510
5617
  abortSignal: abortController?.signal,
@@ -5551,7 +5658,7 @@ async function executeForeach(engine, params) {
5551
5658
  timeTravel,
5552
5659
  executionContext,
5553
5660
  tracingContext,
5554
- emitter,
5661
+ pubsub,
5555
5662
  abortController,
5556
5663
  requestContext,
5557
5664
  outputWriter,
@@ -5579,12 +5686,16 @@ async function executeForeach(engine, params) {
5579
5686
  },
5580
5687
  tracingPolicy: engine.options?.tracingPolicy
5581
5688
  });
5582
- await emitter.emit("watch", {
5583
- type: "workflow-step-start",
5584
- payload: {
5585
- id: step.id,
5586
- ...stepInfo,
5587
- status: "running"
5689
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
5690
+ type: "watch",
5691
+ runId,
5692
+ data: {
5693
+ type: "workflow-step-start",
5694
+ payload: {
5695
+ id: step.id,
5696
+ ...stepInfo,
5697
+ status: "running"
5698
+ }
5588
5699
  }
5589
5700
  });
5590
5701
  const prevPayload = stepResults[step.id];
@@ -5623,7 +5734,7 @@ async function executeForeach(engine, params) {
5623
5734
  resume: resumeToUse,
5624
5735
  prevOutput: item,
5625
5736
  tracingContext: { currentSpan: loopSpan },
5626
- emitter,
5737
+ pubsub,
5627
5738
  abortController,
5628
5739
  requestContext,
5629
5740
  skipEmits: true,
@@ -5643,18 +5754,26 @@ async function executeForeach(engine, params) {
5643
5754
  if (execResults.status === "suspended") {
5644
5755
  foreachIndexObj[i + resultIndex] = execResults;
5645
5756
  } else {
5646
- await emitter.emit("watch", {
5647
- type: "workflow-step-result",
5648
- payload: {
5649
- id: step.id,
5650
- ...execResults
5757
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
5758
+ type: "watch",
5759
+ runId,
5760
+ data: {
5761
+ type: "workflow-step-result",
5762
+ payload: {
5763
+ id: step.id,
5764
+ ...execResults
5765
+ }
5651
5766
  }
5652
5767
  });
5653
- await emitter.emit("watch", {
5654
- type: "workflow-step-finish",
5655
- payload: {
5656
- id: step.id,
5657
- metadata: {}
5768
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
5769
+ type: "watch",
5770
+ runId,
5771
+ data: {
5772
+ type: "workflow-step-finish",
5773
+ payload: {
5774
+ id: step.id,
5775
+ metadata: {}
5776
+ }
5658
5777
  }
5659
5778
  });
5660
5779
  return result;
@@ -5673,11 +5792,15 @@ async function executeForeach(engine, params) {
5673
5792
  if (Object.keys(foreachIndexObj).length > 0) {
5674
5793
  const suspendedIndices = Object.keys(foreachIndexObj).map(Number);
5675
5794
  const foreachIndex = suspendedIndices[0];
5676
- await emitter.emit("watch", {
5677
- type: "workflow-step-suspended",
5678
- payload: {
5679
- id: step.id,
5680
- ...foreachIndexObj[foreachIndex]
5795
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
5796
+ type: "watch",
5797
+ runId,
5798
+ data: {
5799
+ type: "workflow-step-suspended",
5800
+ payload: {
5801
+ id: step.id,
5802
+ ...foreachIndexObj[foreachIndex]
5803
+ }
5681
5804
  }
5682
5805
  });
5683
5806
  executionContext.suspendedPaths[step.id] = executionContext.executionPath;
@@ -5699,20 +5822,28 @@ async function executeForeach(engine, params) {
5699
5822
  };
5700
5823
  }
5701
5824
  }
5702
- await emitter.emit("watch", {
5703
- type: "workflow-step-result",
5704
- payload: {
5705
- id: step.id,
5706
- status: "success",
5707
- output: results,
5708
- endedAt: Date.now()
5825
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
5826
+ type: "watch",
5827
+ runId,
5828
+ data: {
5829
+ type: "workflow-step-result",
5830
+ payload: {
5831
+ id: step.id,
5832
+ status: "success",
5833
+ output: results,
5834
+ endedAt: Date.now()
5835
+ }
5709
5836
  }
5710
5837
  });
5711
- await emitter.emit("watch", {
5712
- type: "workflow-step-finish",
5713
- payload: {
5714
- id: step.id,
5715
- metadata: {}
5838
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
5839
+ type: "watch",
5840
+ runId,
5841
+ data: {
5842
+ type: "workflow-step-finish",
5843
+ payload: {
5844
+ id: step.id,
5845
+ metadata: {}
5846
+ }
5716
5847
  }
5717
5848
  });
5718
5849
  loopSpan?.end({
@@ -5789,7 +5920,7 @@ async function executeEntry(engine, params) {
5789
5920
  resume,
5790
5921
  executionContext,
5791
5922
  tracingContext,
5792
- emitter,
5923
+ pubsub,
5793
5924
  abortController,
5794
5925
  requestContext,
5795
5926
  outputWriter,
@@ -5812,7 +5943,7 @@ async function executeEntry(engine, params) {
5812
5943
  resume,
5813
5944
  prevOutput,
5814
5945
  tracingContext,
5815
- emitter,
5946
+ pubsub,
5816
5947
  abortController,
5817
5948
  requestContext,
5818
5949
  outputWriter,
@@ -5845,7 +5976,7 @@ async function executeEntry(engine, params) {
5845
5976
  state: executionContext.state
5846
5977
  },
5847
5978
  tracingContext,
5848
- emitter,
5979
+ pubsub,
5849
5980
  abortController,
5850
5981
  requestContext,
5851
5982
  outputWriter,
@@ -5915,7 +6046,7 @@ async function executeEntry(engine, params) {
5915
6046
  resume,
5916
6047
  executionContext,
5917
6048
  tracingContext,
5918
- emitter,
6049
+ pubsub,
5919
6050
  abortController,
5920
6051
  requestContext,
5921
6052
  outputWriter,
@@ -5934,7 +6065,7 @@ async function executeEntry(engine, params) {
5934
6065
  resume,
5935
6066
  executionContext,
5936
6067
  tracingContext,
5937
- emitter,
6068
+ pubsub,
5938
6069
  abortController,
5939
6070
  requestContext,
5940
6071
  outputWriter,
@@ -5953,7 +6084,7 @@ async function executeEntry(engine, params) {
5953
6084
  resume,
5954
6085
  executionContext,
5955
6086
  tracingContext,
5956
- emitter,
6087
+ pubsub,
5957
6088
  abortController,
5958
6089
  requestContext,
5959
6090
  outputWriter,
@@ -5973,7 +6104,7 @@ async function executeEntry(engine, params) {
5973
6104
  resume,
5974
6105
  executionContext,
5975
6106
  tracingContext,
5976
- emitter,
6107
+ pubsub,
5977
6108
  abortController,
5978
6109
  requestContext,
5979
6110
  outputWriter,
@@ -5984,13 +6115,17 @@ async function executeEntry(engine, params) {
5984
6115
  const startedAt = Date.now();
5985
6116
  const sleepWaitingOperationId = `workflow.${workflowId}.run.${runId}.sleep.${entry.id}.waiting_ev`;
5986
6117
  await engine.wrapDurableOperation(sleepWaitingOperationId, async () => {
5987
- await emitter.emit("watch", {
5988
- type: "workflow-step-waiting",
5989
- payload: {
5990
- id: entry.id,
5991
- payload: prevOutput,
5992
- startedAt,
5993
- status: "waiting"
6118
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
6119
+ type: "watch",
6120
+ runId,
6121
+ data: {
6122
+ type: "workflow-step-waiting",
6123
+ payload: {
6124
+ id: entry.id,
6125
+ payload: prevOutput,
6126
+ startedAt,
6127
+ status: "waiting"
6128
+ }
5994
6129
  }
5995
6130
  });
5996
6131
  });
@@ -6021,7 +6156,7 @@ async function executeEntry(engine, params) {
6021
6156
  resume,
6022
6157
  executionContext,
6023
6158
  tracingContext,
6024
- emitter,
6159
+ pubsub,
6025
6160
  abortController,
6026
6161
  requestContext,
6027
6162
  outputWriter
@@ -6047,20 +6182,28 @@ async function executeEntry(engine, params) {
6047
6182
  stepResults[entry.id] = { ...stepInfo, status: "success", output: prevOutput };
6048
6183
  const sleepResultOperationId = `workflow.${workflowId}.run.${runId}.sleep.${entry.id}.result_ev`;
6049
6184
  await engine.wrapDurableOperation(sleepResultOperationId, async () => {
6050
- await emitter.emit("watch", {
6051
- type: "workflow-step-result",
6052
- payload: {
6053
- id: entry.id,
6054
- endedAt,
6055
- status: "success",
6056
- output: prevOutput
6185
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
6186
+ type: "watch",
6187
+ runId,
6188
+ data: {
6189
+ type: "workflow-step-result",
6190
+ payload: {
6191
+ id: entry.id,
6192
+ endedAt,
6193
+ status: "success",
6194
+ output: prevOutput
6195
+ }
6057
6196
  }
6058
6197
  });
6059
- await emitter.emit("watch", {
6060
- type: "workflow-step-finish",
6061
- payload: {
6062
- id: entry.id,
6063
- metadata: {}
6198
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
6199
+ type: "watch",
6200
+ runId,
6201
+ data: {
6202
+ type: "workflow-step-finish",
6203
+ payload: {
6204
+ id: entry.id,
6205
+ metadata: {}
6206
+ }
6064
6207
  }
6065
6208
  });
6066
6209
  });
@@ -6068,13 +6211,17 @@ async function executeEntry(engine, params) {
6068
6211
  const startedAt = Date.now();
6069
6212
  const sleepUntilWaitingOperationId = `workflow.${workflowId}.run.${runId}.sleepUntil.${entry.id}.waiting_ev`;
6070
6213
  await engine.wrapDurableOperation(sleepUntilWaitingOperationId, async () => {
6071
- await emitter.emit("watch", {
6072
- type: "workflow-step-waiting",
6073
- payload: {
6074
- id: entry.id,
6075
- payload: prevOutput,
6076
- startedAt,
6077
- status: "waiting"
6214
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
6215
+ type: "watch",
6216
+ runId,
6217
+ data: {
6218
+ type: "workflow-step-waiting",
6219
+ payload: {
6220
+ id: entry.id,
6221
+ payload: prevOutput,
6222
+ startedAt,
6223
+ status: "waiting"
6224
+ }
6078
6225
  }
6079
6226
  });
6080
6227
  });
@@ -6105,7 +6252,7 @@ async function executeEntry(engine, params) {
6105
6252
  resume,
6106
6253
  executionContext,
6107
6254
  tracingContext,
6108
- emitter,
6255
+ pubsub,
6109
6256
  abortController,
6110
6257
  requestContext,
6111
6258
  outputWriter
@@ -6131,20 +6278,28 @@ async function executeEntry(engine, params) {
6131
6278
  stepResults[entry.id] = { ...stepInfo, status: "success", output: prevOutput };
6132
6279
  const sleepUntilResultOperationId = `workflow.${workflowId}.run.${runId}.sleepUntil.${entry.id}.result_ev`;
6133
6280
  await engine.wrapDurableOperation(sleepUntilResultOperationId, async () => {
6134
- await emitter.emit("watch", {
6135
- type: "workflow-step-result",
6136
- payload: {
6137
- id: entry.id,
6138
- endedAt,
6139
- status: "success",
6140
- output: prevOutput
6281
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
6282
+ type: "watch",
6283
+ runId,
6284
+ data: {
6285
+ type: "workflow-step-result",
6286
+ payload: {
6287
+ id: entry.id,
6288
+ endedAt,
6289
+ status: "success",
6290
+ output: prevOutput
6291
+ }
6141
6292
  }
6142
6293
  });
6143
- await emitter.emit("watch", {
6144
- type: "workflow-step-finish",
6145
- payload: {
6146
- id: entry.id,
6147
- metadata: {}
6294
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
6295
+ type: "watch",
6296
+ runId,
6297
+ data: {
6298
+ type: "workflow-step-finish",
6299
+ payload: {
6300
+ id: entry.id,
6301
+ metadata: {}
6302
+ }
6148
6303
  }
6149
6304
  });
6150
6305
  });
@@ -6166,9 +6321,10 @@ async function executeEntry(engine, params) {
6166
6321
  requestContext
6167
6322
  });
6168
6323
  if (execResults.status === "canceled") {
6169
- await emitter.emit("watch", {
6170
- type: "workflow-canceled",
6171
- payload: {}
6324
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
6325
+ type: "watch",
6326
+ runId,
6327
+ data: { type: "workflow-canceled", payload: {} }
6172
6328
  });
6173
6329
  }
6174
6330
  return {
@@ -6185,7 +6341,7 @@ async function executeSleep(engine, params) {
6185
6341
  entry,
6186
6342
  prevOutput,
6187
6343
  stepResults,
6188
- emitter,
6344
+ pubsub,
6189
6345
  abortController,
6190
6346
  requestContext,
6191
6347
  executionContext,
@@ -6229,7 +6385,7 @@ async function executeSleep(engine, params) {
6229
6385
  abort: () => {
6230
6386
  abortController?.abort();
6231
6387
  },
6232
- [EMITTER_SYMBOL]: emitter,
6388
+ [PUBSUB_SYMBOL]: pubsub,
6233
6389
  [STREAM_FORMAT_SYMBOL]: executionContext.format,
6234
6390
  engine: engine.getEngineContext(),
6235
6391
  abortSignal: abortController?.signal,
@@ -6265,7 +6421,7 @@ async function executeSleepUntil(engine, params) {
6265
6421
  entry,
6266
6422
  prevOutput,
6267
6423
  stepResults,
6268
- emitter,
6424
+ pubsub,
6269
6425
  abortController,
6270
6426
  requestContext,
6271
6427
  executionContext,
@@ -6310,7 +6466,7 @@ async function executeSleepUntil(engine, params) {
6310
6466
  abort: () => {
6311
6467
  abortController?.abort();
6312
6468
  },
6313
- [EMITTER_SYMBOL]: emitter,
6469
+ [PUBSUB_SYMBOL]: pubsub,
6314
6470
  [STREAM_FORMAT_SYMBOL]: executionContext.format,
6315
6471
  engine: engine.getEngineContext(),
6316
6472
  abortSignal: abortController?.signal,
@@ -6357,7 +6513,7 @@ async function executeStep(engine, params) {
6357
6513
  resume,
6358
6514
  timeTravel,
6359
6515
  prevOutput,
6360
- emitter,
6516
+ pubsub,
6361
6517
  abortController,
6362
6518
  requestContext,
6363
6519
  skipEmits = false,
@@ -6417,7 +6573,7 @@ async function executeStep(engine, params) {
6417
6573
  await engine.onStepExecutionStart({
6418
6574
  step,
6419
6575
  inputData,
6420
- emitter,
6576
+ pubsub,
6421
6577
  executionContext,
6422
6578
  stepCallId,
6423
6579
  stepInfo,
@@ -6446,7 +6602,7 @@ async function executeStep(engine, params) {
6446
6602
  timeTravel,
6447
6603
  prevOutput,
6448
6604
  inputData,
6449
- emitter,
6605
+ pubsub,
6450
6606
  startedAt: startTime ?? Date.now(),
6451
6607
  abortController,
6452
6608
  requestContext,
@@ -6568,7 +6724,7 @@ async function executeStep(engine, params) {
6568
6724
  nestedStepResults: timeTravel?.nestedStepResults,
6569
6725
  resumeData: timeTravel?.resumeData
6570
6726
  } : void 0,
6571
- [EMITTER_SYMBOL]: emitter,
6727
+ [PUBSUB_SYMBOL]: pubsub,
6572
6728
  [STREAM_FORMAT_SYMBOL]: executionContext.format,
6573
6729
  engine: engine.getEngineContext(),
6574
6730
  abortSignal: abortController?.signal,
@@ -6640,7 +6796,8 @@ async function executeStep(engine, params) {
6640
6796
  stepId: step.id,
6641
6797
  stepCallId,
6642
6798
  execResults: { ...stepInfo, ...execResults },
6643
- emitter
6799
+ pubsub,
6800
+ runId
6644
6801
  });
6645
6802
  });
6646
6803
  }
@@ -6671,9 +6828,9 @@ async function runScorersForStep(params) {
6671
6828
  scorersToUse = await scorersToUse({
6672
6829
  requestContext
6673
6830
  });
6674
- } catch (error) {
6675
- engine.preprocessExecutionError(
6676
- error,
6831
+ } catch (e) {
6832
+ const errorInstance = getErrorFromUnknown(e, { serializeStack: false });
6833
+ const mastraError = new MastraError(
6677
6834
  {
6678
6835
  id: "WORKFLOW_FAILED_TO_FETCH_SCORERS",
6679
6836
  domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
@@ -6684,8 +6841,10 @@ async function runScorersForStep(params) {
6684
6841
  stepId
6685
6842
  }
6686
6843
  },
6687
- "Error fetching scorers: "
6844
+ errorInstance
6688
6845
  );
6846
+ engine.getLogger()?.trackException(mastraError);
6847
+ engine.getLogger()?.error("Error fetching scorers: " + errorInstance?.stack);
6689
6848
  }
6690
6849
  }
6691
6850
  if (!disableScorers && scorersToUse && Object.keys(scorersToUse || {}).length > 0) {
@@ -6710,42 +6869,30 @@ async function runScorersForStep(params) {
6710
6869
  }
6711
6870
  }
6712
6871
  async function emitStepResultEvents(params) {
6713
- const { stepId, stepCallId, execResults, emitter } = params;
6872
+ const { stepId, stepCallId, execResults, pubsub, runId } = params;
6714
6873
  const payloadBase = stepCallId ? { id: stepId, stepCallId } : { id: stepId };
6715
6874
  if (execResults.status === "suspended") {
6716
- await emitter.emit("watch", {
6717
- type: "workflow-step-suspended",
6718
- payload: { ...payloadBase, ...execResults }
6875
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
6876
+ type: "watch",
6877
+ runId,
6878
+ data: { type: "workflow-step-suspended", payload: { ...payloadBase, ...execResults } }
6719
6879
  });
6720
6880
  } else {
6721
- await emitter.emit("watch", {
6722
- type: "workflow-step-result",
6723
- payload: { ...payloadBase, ...execResults }
6881
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
6882
+ type: "watch",
6883
+ runId,
6884
+ data: { type: "workflow-step-result", payload: { ...payloadBase, ...execResults } }
6724
6885
  });
6725
- await emitter.emit("watch", {
6726
- type: "workflow-step-finish",
6727
- payload: { ...payloadBase, metadata: {} }
6886
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
6887
+ type: "watch",
6888
+ runId,
6889
+ data: { type: "workflow-step-finish", payload: { ...payloadBase, metadata: {} } }
6728
6890
  });
6729
6891
  }
6730
6892
  }
6731
6893
 
6732
6894
  // src/workflows/default.ts
6733
6895
  var DefaultExecutionEngine = class extends ExecutionEngine {
6734
- /**
6735
- * Preprocesses an error caught during workflow execution.
6736
- *
6737
- * - Wraps a non-MastraError exception
6738
- * - Logs error details
6739
- */
6740
- preprocessExecutionError(e, errorDefinition, logPrefix) {
6741
- const error = e instanceof MastraError ? e : new MastraError(errorDefinition, e);
6742
- if (!(e instanceof MastraError) && e instanceof Error && e.stack) {
6743
- error.stack = e.stack;
6744
- }
6745
- this.logger?.trackException(error);
6746
- this.logger?.error(logPrefix + error?.stack);
6747
- return error;
6748
- }
6749
6896
  /**
6750
6897
  * The retryCounts map is used to keep track of the retry count for each step.
6751
6898
  * The step id is used as the key and the retry count is the value.
@@ -6852,12 +6999,16 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
6852
6999
  return this.wrapDurableOperation(params.operationId, async () => {
6853
7000
  const startedAt = Date.now();
6854
7001
  if (!params.skipEmits) {
6855
- await params.emitter.emit("watch", {
6856
- type: "workflow-step-start",
6857
- payload: {
6858
- id: params.step.id,
6859
- stepCallId: params.stepCallId,
6860
- ...params.stepInfo
7002
+ await params.pubsub.publish(`workflow.events.v2.${params.executionContext.runId}`, {
7003
+ type: "watch",
7004
+ runId: params.executionContext.runId,
7005
+ data: {
7006
+ type: "workflow-step-start",
7007
+ payload: {
7008
+ id: params.step.id,
7009
+ stepCallId: params.stepCallId,
7010
+ ...params.stepInfo
7011
+ }
6861
7012
  }
6862
7013
  });
6863
7014
  }
@@ -6897,29 +7048,30 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
6897
7048
  return { ok: true, result };
6898
7049
  } catch (e) {
6899
7050
  if (i === params.retries) {
6900
- const processedError = this.preprocessExecutionError(
6901
- e,
7051
+ const errorInstance = getErrorFromUnknown(e, {
7052
+ serializeStack: false,
7053
+ fallbackMessage: "Unknown step execution error"
7054
+ });
7055
+ const mastraError = new MastraError(
6902
7056
  {
6903
7057
  id: "WORKFLOW_STEP_INVOKE_FAILED",
6904
7058
  domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
6905
7059
  category: "USER" /* USER */,
6906
7060
  details: { workflowId: params.workflowId, runId: params.runId, stepId }
6907
7061
  },
6908
- `Error executing step ${stepId}: `
7062
+ errorInstance
6909
7063
  );
7064
+ this.logger?.trackException(mastraError);
7065
+ this.logger?.error(`Error executing step ${stepId}: ` + errorInstance?.stack);
6910
7066
  params.stepSpan?.error({
6911
- error: processedError,
7067
+ error: mastraError,
6912
7068
  attributes: { status: "failed" }
6913
7069
  });
6914
- const errorInstance = getErrorFromUnknown(processedError, {
6915
- includeStack: false,
6916
- fallbackMessage: "Unknown step execution error"
6917
- });
6918
7070
  return {
6919
7071
  ok: false,
6920
7072
  error: {
6921
7073
  status: "failed",
6922
- error: `Error: ${errorInstance.message}`,
7074
+ error: errorInstance,
6923
7075
  endedAt: Date.now(),
6924
7076
  // Preserve TripWire data as plain object for proper serialization
6925
7077
  tripwire: e instanceof TripWire ? {
@@ -6933,7 +7085,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
6933
7085
  }
6934
7086
  }
6935
7087
  }
6936
- return { ok: false, error: { status: "failed", error: "Unknown error", endedAt: Date.now() } };
7088
+ return { ok: false, error: { status: "failed", error: new Error("Unknown error"), endedAt: Date.now() } };
6937
7089
  }
6938
7090
  /**
6939
7091
  * Format an error for the workflow result.
@@ -6943,12 +7095,12 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
6943
7095
  const outputError = lastOutput?.error;
6944
7096
  const errorSource = error || outputError;
6945
7097
  const errorInstance = getErrorFromUnknown(errorSource, {
6946
- includeStack: false,
7098
+ serializeStack: false,
6947
7099
  fallbackMessage: "Unknown workflow error"
6948
7100
  });
6949
- return typeof errorSource === "string" ? errorInstance.message : `Error: ${errorInstance.message}`;
7101
+ return errorInstance.toJSON();
6950
7102
  }
6951
- async fmtReturnValue(emitter, stepResults, lastOutput, error) {
7103
+ async fmtReturnValue(_pubsub, stepResults, lastOutput, error) {
6952
7104
  const base = {
6953
7105
  status: lastOutput.status,
6954
7106
  steps: stepResults,
@@ -6973,14 +7125,18 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
6973
7125
  base.error = this.formatResultError(error, lastOutput);
6974
7126
  }
6975
7127
  } else if (lastOutput.status === "suspended") {
7128
+ const suspendPayload = {};
6976
7129
  const suspendedStepIds = Object.entries(stepResults).flatMap(([stepId, stepResult]) => {
6977
7130
  if (stepResult?.status === "suspended") {
6978
- const nestedPath = stepResult?.suspendPayload?.__workflow_meta?.path;
7131
+ const { __workflow_meta, ...rest } = stepResult?.suspendPayload ?? {};
7132
+ suspendPayload[stepId] = rest;
7133
+ const nestedPath = __workflow_meta?.path;
6979
7134
  return nestedPath ? [[stepId, ...nestedPath]] : [[stepId]];
6980
7135
  }
6981
7136
  return [];
6982
7137
  });
6983
7138
  base.suspended = suspendedStepIds;
7139
+ base.suspendPayload = suspendPayload;
6984
7140
  }
6985
7141
  return base;
6986
7142
  }
@@ -7112,7 +7268,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
7112
7268
  currentSpan: workflowSpan
7113
7269
  },
7114
7270
  abortController: params.abortController,
7115
- emitter: params.emitter,
7271
+ pubsub: params.pubsub,
7116
7272
  requestContext: currentRequestContext,
7117
7273
  outputWriter: params.outputWriter,
7118
7274
  disableScorers
@@ -7126,7 +7282,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
7126
7282
  if (lastOutput.result.status === "bailed") {
7127
7283
  lastOutput.result.status = "success";
7128
7284
  }
7129
- const result2 = await this.fmtReturnValue(params.emitter, stepResults, lastOutput.result);
7285
+ const result2 = await this.fmtReturnValue(params.pubsub, stepResults, lastOutput.result);
7130
7286
  await this.persistStepUpdate({
7131
7287
  workflowId,
7132
7288
  runId,
@@ -7154,6 +7310,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
7154
7310
  }
7155
7311
  });
7156
7312
  }
7313
+ await this.invokeLifecycleCallbacks(result2);
7157
7314
  return {
7158
7315
  ...result2,
7159
7316
  ...lastOutput.result.status === "suspended" && params.outputOptions?.includeResumeLabels ? { resumeLabels: lastOutput.mutableContext.resumeLabels } : {},
@@ -7161,7 +7318,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
7161
7318
  };
7162
7319
  }
7163
7320
  }
7164
- const result = await this.fmtReturnValue(params.emitter, stepResults, lastOutput.result);
7321
+ const result = await this.fmtReturnValue(params.pubsub, stepResults, lastOutput.result);
7165
7322
  await this.persistStepUpdate({
7166
7323
  workflowId,
7167
7324
  runId,
@@ -7180,6 +7337,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
7180
7337
  status: result.status
7181
7338
  }
7182
7339
  });
7340
+ await this.invokeLifecycleCallbacks(result);
7183
7341
  if (params.outputOptions?.includeState) {
7184
7342
  return { ...result, state: lastState };
7185
7343
  }
@@ -7255,7 +7413,8 @@ function createStep(params, agentOptions) {
7255
7413
  outputSchema,
7256
7414
  execute: async ({
7257
7415
  inputData,
7258
- [EMITTER_SYMBOL]: emitter,
7416
+ runId,
7417
+ [PUBSUB_SYMBOL]: pubsub,
7259
7418
  [STREAM_FORMAT_SYMBOL]: streamFormat,
7260
7419
  requestContext,
7261
7420
  tracingContext,
@@ -7311,9 +7470,10 @@ function createStep(params, agentOptions) {
7311
7470
  }
7312
7471
  let tripwireChunk = null;
7313
7472
  if (streamFormat === "legacy") {
7314
- await emitter.emit("watch", {
7315
- type: "tool-call-streaming-start",
7316
- ...toolData ?? {}
7473
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
7474
+ type: "watch",
7475
+ runId,
7476
+ data: { type: "tool-call-streaming-start", ...toolData ?? {} }
7317
7477
  });
7318
7478
  for await (const chunk of stream) {
7319
7479
  if (chunk.type === "tripwire") {
@@ -7321,16 +7481,17 @@ function createStep(params, agentOptions) {
7321
7481
  break;
7322
7482
  }
7323
7483
  if (chunk.type === "text-delta") {
7324
- await emitter.emit("watch", {
7325
- type: "tool-call-delta",
7326
- ...toolData ?? {},
7327
- argsTextDelta: chunk.textDelta
7484
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
7485
+ type: "watch",
7486
+ runId,
7487
+ data: { type: "tool-call-delta", ...toolData ?? {}, argsTextDelta: chunk.textDelta }
7328
7488
  });
7329
7489
  }
7330
7490
  }
7331
- await emitter.emit("watch", {
7332
- type: "tool-call-streaming-finish",
7333
- ...toolData ?? {}
7491
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
7492
+ type: "watch",
7493
+ runId,
7494
+ data: { type: "tool-call-streaming-finish", ...toolData ?? {} }
7334
7495
  });
7335
7496
  } else {
7336
7497
  for await (const chunk of stream) {
@@ -7840,7 +8001,9 @@ var Workflow = class extends MastraBase {
7840
8001
  this.#options = {
7841
8002
  validateInputs: options.validateInputs ?? true,
7842
8003
  shouldPersistSnapshot: options.shouldPersistSnapshot ?? (() => true),
7843
- tracingPolicy: options.tracingPolicy
8004
+ tracingPolicy: options.tracingPolicy,
8005
+ onFinish: options.onFinish,
8006
+ onError: options.onError
7844
8007
  };
7845
8008
  if (!executionEngine) {
7846
8009
  this.executionEngine = new DefaultExecutionEngine({
@@ -7960,7 +8123,7 @@ var Workflow = class extends MastraBase {
7960
8123
  type: "step",
7961
8124
  step: {
7962
8125
  id: mappingStep2.id,
7963
- mapConfig: mappingConfig.toString()
8126
+ mapConfig: mappingConfig.toString()?.length > 1e3 ? mappingConfig.toString().slice(0, 1e3) + "...\n}" : mappingConfig.toString()
7964
8127
  }
7965
8128
  });
7966
8129
  return this;
@@ -8032,7 +8195,7 @@ var Workflow = class extends MastraBase {
8032
8195
  type: "step",
8033
8196
  step: {
8034
8197
  id: mappingStep.id,
8035
- mapConfig: JSON.stringify(newMappingConfig, null, 2)
8198
+ mapConfig: JSON.stringify(newMappingConfig, null, 2)?.length > 1e3 ? JSON.stringify(newMappingConfig, null, 2).slice(0, 1e3) + "...\n}" : JSON.stringify(newMappingConfig, null, 2)
8036
8199
  }
8037
8200
  });
8038
8201
  return this;
@@ -8281,7 +8444,7 @@ var Workflow = class extends MastraBase {
8281
8444
  restart,
8282
8445
  resume,
8283
8446
  timeTravel,
8284
- [EMITTER_SYMBOL]: emitter,
8447
+ [PUBSUB_SYMBOL]: pubsub,
8285
8448
  mastra,
8286
8449
  requestContext,
8287
8450
  abort,
@@ -8316,7 +8479,11 @@ var Workflow = class extends MastraBase {
8316
8479
  await run.cancel();
8317
8480
  });
8318
8481
  const unwatch = run.watch((event) => {
8319
- emitter.emit("nested-watch", { event, workflowId: this.id });
8482
+ void pubsub.publish("nested-watch", {
8483
+ type: "nested-watch",
8484
+ runId: run.runId,
8485
+ data: { event, workflowId: this.id }
8486
+ });
8320
8487
  });
8321
8488
  if (retryCount && retryCount > 0 && isResume && requestContext) {
8322
8489
  requestContext.set("__mastraWorflowInputData", inputData);
@@ -8513,7 +8680,7 @@ var Workflow = class extends MastraBase {
8513
8680
  };
8514
8681
  var Run = class {
8515
8682
  #abortController;
8516
- emitter;
8683
+ pubsub;
8517
8684
  /**
8518
8685
  * Unique identifier for this workflow
8519
8686
  */
@@ -8583,7 +8750,7 @@ var Run = class {
8583
8750
  this.executionEngine = params.executionEngine;
8584
8751
  this.executionGraph = params.executionGraph;
8585
8752
  this.#mastra = params.mastra;
8586
- this.emitter = new EventEmitter2();
8753
+ this.pubsub = new EventEmitterPubSub();
8587
8754
  this.retryConfig = params.retryConfig;
8588
8755
  this.cleanup = params.cleanup;
8589
8756
  this.disableScorers = params.disableScorers;
@@ -8602,10 +8769,22 @@ var Run = class {
8602
8769
  return this.#abortController;
8603
8770
  }
8604
8771
  /**
8605
- * Cancels the workflow execution
8772
+ * Cancels the workflow execution.
8773
+ * This aborts any running execution and updates the workflow status to 'canceled' in storage.
8606
8774
  */
8607
8775
  async cancel() {
8608
- this.abortController?.abort();
8776
+ this.abortController.abort();
8777
+ this.workflowRunStatus = "canceled";
8778
+ try {
8779
+ await this.mastra?.getStorage()?.updateWorkflowState({
8780
+ workflowName: this.workflowId,
8781
+ runId: this.runId,
8782
+ opts: {
8783
+ status: "canceled"
8784
+ }
8785
+ });
8786
+ } catch {
8787
+ }
8609
8788
  }
8610
8789
  async _validateInput(inputData) {
8611
8790
  let inputDataToUse = inputData;
@@ -8706,20 +8885,7 @@ var Run = class {
8706
8885
  serializedStepGraph: this.serializedStepGraph,
8707
8886
  input: inputDataToUse,
8708
8887
  initialState: initialStateToUse,
8709
- emitter: {
8710
- emit: async (event, data) => {
8711
- this.emitter.emit(event, data);
8712
- },
8713
- on: (event, callback) => {
8714
- this.emitter.on(event, callback);
8715
- },
8716
- off: (event, callback) => {
8717
- this.emitter.off(event, callback);
8718
- },
8719
- once: (event, callback) => {
8720
- this.emitter.once(event, callback);
8721
- }
8722
- },
8888
+ pubsub: this.pubsub,
8723
8889
  retryConfig: this.retryConfig,
8724
8890
  requestContext: requestContext ?? new RequestContext(),
8725
8891
  abortController: this.abortController,
@@ -8742,6 +8908,19 @@ var Run = class {
8742
8908
  async start(args) {
8743
8909
  return this._start(args);
8744
8910
  }
8911
+ /**
8912
+ * Starts the workflow execution without waiting for completion (fire-and-forget).
8913
+ * Returns immediately with the runId. The workflow executes in the background.
8914
+ * Use this when you don't need to wait for the result or want to avoid polling failures.
8915
+ * @param args The input data and configuration for the workflow
8916
+ * @returns A promise that resolves immediately with the runId
8917
+ */
8918
+ async startAsync(args) {
8919
+ this._start(args).catch((err) => {
8920
+ console.error(`[Workflow ${this.workflowId}] Background execution failed:`, err);
8921
+ });
8922
+ return { runId: this.runId };
8923
+ }
8745
8924
  /**
8746
8925
  * Starts the workflow execution with the provided input as a stream
8747
8926
  * @param input The input data for the workflow
@@ -8776,9 +8955,10 @@ var Run = class {
8776
8955
  }
8777
8956
  });
8778
8957
  this.closeStreamAction = async () => {
8779
- this.emitter.emit("watch", {
8780
- type: "workflow-finish",
8781
- payload: { runId: this.runId }
8958
+ await this.pubsub.publish(`workflow.events.v2.${this.runId}`, {
8959
+ type: "watch",
8960
+ runId: this.runId,
8961
+ data: { type: "workflow-finish", payload: { runId: this.runId } }
8782
8962
  });
8783
8963
  unwatch();
8784
8964
  await Promise.all(this.#observerHandlers.map((handler) => handler()));
@@ -8791,9 +8971,10 @@ var Run = class {
8791
8971
  writer.releaseLock();
8792
8972
  }
8793
8973
  };
8794
- this.emitter.emit("watch", {
8795
- type: "workflow-start",
8796
- payload: { runId: this.runId }
8974
+ void this.pubsub.publish(`workflow.events.v2.${this.runId}`, {
8975
+ type: "watch",
8976
+ runId: this.runId,
8977
+ data: { type: "workflow-start", payload: { runId: this.runId } }
8797
8978
  });
8798
8979
  this.executionResults = this._start({
8799
8980
  inputData,
@@ -8929,7 +9110,9 @@ var Run = class {
8929
9110
  self.closeStreamAction = async () => {
8930
9111
  unwatch();
8931
9112
  try {
8932
- await controller.close();
9113
+ if (controller.desiredSize !== null) {
9114
+ controller.close();
9115
+ }
8933
9116
  } catch (err) {
8934
9117
  console.error("Error closing stream:", err);
8935
9118
  }
@@ -8942,7 +9125,11 @@ var Run = class {
8942
9125
  initialState,
8943
9126
  outputOptions,
8944
9127
  outputWriter: async (chunk) => {
8945
- void self.emitter.emit("watch", chunk);
9128
+ void self.pubsub.publish(`workflow.events.v2.${self.runId}`, {
9129
+ type: "watch",
9130
+ runId: self.runId,
9131
+ data: chunk
9132
+ });
8946
9133
  }
8947
9134
  });
8948
9135
  let executionResults;
@@ -9040,7 +9227,9 @@ var Run = class {
9040
9227
  self.closeStreamAction = async () => {
9041
9228
  unwatch();
9042
9229
  try {
9043
- await controller.close();
9230
+ if (controller.desiredSize !== null) {
9231
+ controller.close();
9232
+ }
9044
9233
  } catch (err) {
9045
9234
  console.error("Error closing stream:", err);
9046
9235
  }
@@ -9085,20 +9274,29 @@ var Run = class {
9085
9274
  * @internal
9086
9275
  */
9087
9276
  watch(cb) {
9088
- const nestedWatchCb = ({
9089
- event,
9090
- workflowId
9091
- }) => {
9092
- this.emitter.emit("watch", {
9093
- ...event,
9094
- ...event.payload?.id ? { payload: { ...event.payload, id: `${workflowId}.${event.payload.id}` } } : {}
9095
- });
9277
+ const wrappedCb = (event) => {
9278
+ if (event.runId === this.runId) {
9279
+ cb(event.data);
9280
+ }
9096
9281
  };
9097
- this.emitter.on("watch", cb);
9098
- this.emitter.on("nested-watch", nestedWatchCb);
9282
+ const nestedWatchCb = (event) => {
9283
+ if (event.runId === this.runId) {
9284
+ const { event: nestedEvent, workflowId } = event.data;
9285
+ void this.pubsub.publish(`workflow.events.v2.${this.runId}`, {
9286
+ type: "watch",
9287
+ runId: this.runId,
9288
+ data: {
9289
+ ...nestedEvent,
9290
+ ...nestedEvent.payload?.id ? { payload: { ...nestedEvent.payload, id: `${workflowId}.${nestedEvent.payload.id}` } } : {}
9291
+ }
9292
+ });
9293
+ }
9294
+ };
9295
+ void this.pubsub.subscribe(`workflow.events.v2.${this.runId}`, wrappedCb);
9296
+ void this.pubsub.subscribe("nested-watch", nestedWatchCb);
9099
9297
  return () => {
9100
- this.emitter.off("watch", cb);
9101
- this.emitter.off("nested-watch", nestedWatchCb);
9298
+ void this.pubsub.unsubscribe(`workflow.events.v2.${this.runId}`, wrappedCb);
9299
+ void this.pubsub.unsubscribe("nested-watch", nestedWatchCb);
9102
9300
  };
9103
9301
  }
9104
9302
  /**
@@ -9226,21 +9424,7 @@ var Run = class {
9226
9424
  label: params.label
9227
9425
  },
9228
9426
  format: params.format,
9229
- emitter: {
9230
- emit: (event, data) => {
9231
- this.emitter.emit(event, data);
9232
- return Promise.resolve();
9233
- },
9234
- on: (event, callback) => {
9235
- this.emitter.on(event, callback);
9236
- },
9237
- off: (event, callback) => {
9238
- this.emitter.off(event, callback);
9239
- },
9240
- once: (event, callback) => {
9241
- this.emitter.once(event, callback);
9242
- }
9243
- },
9427
+ pubsub: this.pubsub,
9244
9428
  requestContext: requestContextToUse,
9245
9429
  abortController: this.abortController,
9246
9430
  workflowSpan,
@@ -9340,20 +9524,7 @@ var Run = class {
9340
9524
  graph: this.executionGraph,
9341
9525
  serializedStepGraph: this.serializedStepGraph,
9342
9526
  restart: restartData,
9343
- emitter: {
9344
- emit: async (event, data) => {
9345
- this.emitter.emit(event, data);
9346
- },
9347
- on: (event, callback) => {
9348
- this.emitter.on(event, callback);
9349
- },
9350
- off: (event, callback) => {
9351
- this.emitter.off(event, callback);
9352
- },
9353
- once: (event, callback) => {
9354
- this.emitter.once(event, callback);
9355
- }
9356
- },
9527
+ pubsub: this.pubsub,
9357
9528
  retryConfig: this.retryConfig,
9358
9529
  requestContext: requestContextToUse,
9359
9530
  abortController: this.abortController,
@@ -9446,20 +9617,7 @@ var Run = class {
9446
9617
  graph: this.executionGraph,
9447
9618
  timeTravel: timeTravelData,
9448
9619
  serializedStepGraph: this.serializedStepGraph,
9449
- emitter: {
9450
- emit: async (event, data) => {
9451
- this.emitter.emit(event, data);
9452
- },
9453
- on: (event, callback) => {
9454
- this.emitter.on(event, callback);
9455
- },
9456
- off: (event, callback) => {
9457
- this.emitter.off(event, callback);
9458
- },
9459
- once: (event, callback) => {
9460
- this.emitter.once(event, callback);
9461
- }
9462
- },
9620
+ pubsub: this.pubsub,
9463
9621
  retryConfig: this.retryConfig,
9464
9622
  requestContext: requestContextToUse,
9465
9623
  abortController: this.abortController,
@@ -9507,7 +9665,9 @@ var Run = class {
9507
9665
  self.closeStreamAction = async () => {
9508
9666
  unwatch();
9509
9667
  try {
9510
- await controller.close();
9668
+ if (controller.desiredSize !== null) {
9669
+ controller.close();
9670
+ }
9511
9671
  } catch (err) {
9512
9672
  console.error("Error closing stream:", err);
9513
9673
  }
@@ -9558,80 +9718,80 @@ var Run = class {
9558
9718
  return this.executionResults ?? this.streamOutput?.result;
9559
9719
  }
9560
9720
  };
9561
- var languageModelUsageSchema = z7.object({
9562
- inputTokens: z7.number(),
9563
- outputTokens: z7.number(),
9564
- totalTokens: z7.number(),
9565
- reasoningTokens: z7.number().optional(),
9566
- cachedInputTokens: z7.number().optional()
9721
+ var languageModelUsageSchema = z8.object({
9722
+ inputTokens: z8.number(),
9723
+ outputTokens: z8.number(),
9724
+ totalTokens: z8.number(),
9725
+ reasoningTokens: z8.number().optional(),
9726
+ cachedInputTokens: z8.number().optional()
9567
9727
  });
9568
- var llmIterationStepResultSchema = z7.object({
9569
- reason: z7.string(),
9570
- warnings: z7.array(z7.any()),
9571
- isContinued: z7.boolean(),
9572
- logprobs: z7.any().optional(),
9728
+ var llmIterationStepResultSchema = z8.object({
9729
+ reason: z8.string(),
9730
+ warnings: z8.array(z8.any()),
9731
+ isContinued: z8.boolean(),
9732
+ logprobs: z8.any().optional(),
9573
9733
  totalUsage: languageModelUsageSchema.optional(),
9574
- headers: z7.record(z7.string()).optional(),
9575
- messageId: z7.string().optional(),
9576
- request: z7.record(z7.any()).optional()
9734
+ headers: z8.record(z8.string()).optional(),
9735
+ messageId: z8.string().optional(),
9736
+ request: z8.record(z8.any()).optional()
9577
9737
  });
9578
- var llmIterationOutputSchema = z7.object({
9579
- messageId: z7.string(),
9580
- messages: z7.object({
9581
- all: z7.array(z7.any()),
9738
+ var llmIterationOutputSchema = z8.object({
9739
+ messageId: z8.string(),
9740
+ messages: z8.object({
9741
+ all: z8.array(z8.any()),
9582
9742
  // ModelMessage[] but too complex to validate at runtime
9583
- user: z7.array(z7.any()),
9584
- nonUser: z7.array(z7.any())
9743
+ user: z8.array(z8.any()),
9744
+ nonUser: z8.array(z8.any())
9585
9745
  }),
9586
- output: z7.object({
9587
- text: z7.string().optional(),
9588
- reasoning: z7.array(z7.any()).optional(),
9589
- reasoningText: z7.string().optional(),
9590
- files: z7.array(z7.any()).optional(),
9746
+ output: z8.object({
9747
+ text: z8.string().optional(),
9748
+ reasoning: z8.array(z8.any()).optional(),
9749
+ reasoningText: z8.string().optional(),
9750
+ files: z8.array(z8.any()).optional(),
9591
9751
  // GeneratedFile[]
9592
- toolCalls: z7.array(z7.any()).optional(),
9752
+ toolCalls: z8.array(z8.any()).optional(),
9593
9753
  // TypedToolCall[]
9594
- toolResults: z7.array(z7.any()).optional(),
9754
+ toolResults: z8.array(z8.any()).optional(),
9595
9755
  // TypedToolResult[]
9596
- sources: z7.array(z7.any()).optional(),
9756
+ sources: z8.array(z8.any()).optional(),
9597
9757
  // LanguageModelV2Source[]
9598
- staticToolCalls: z7.array(z7.any()).optional(),
9599
- dynamicToolCalls: z7.array(z7.any()).optional(),
9600
- staticToolResults: z7.array(z7.any()).optional(),
9601
- dynamicToolResults: z7.array(z7.any()).optional(),
9758
+ staticToolCalls: z8.array(z8.any()).optional(),
9759
+ dynamicToolCalls: z8.array(z8.any()).optional(),
9760
+ staticToolResults: z8.array(z8.any()).optional(),
9761
+ dynamicToolResults: z8.array(z8.any()).optional(),
9602
9762
  usage: languageModelUsageSchema,
9603
- steps: z7.array(z7.any())
9763
+ steps: z8.array(z8.any())
9604
9764
  // StepResult[]
9605
9765
  }),
9606
- metadata: z7.object({
9607
- id: z7.string().optional(),
9608
- model: z7.string().optional(),
9609
- modelId: z7.string().optional(),
9610
- modelMetadata: z7.object({
9611
- modelId: z7.string(),
9612
- modelVersion: z7.string(),
9613
- modelProvider: z7.string()
9766
+ metadata: z8.object({
9767
+ id: z8.string().optional(),
9768
+ model: z8.string().optional(),
9769
+ modelId: z8.string().optional(),
9770
+ modelMetadata: z8.object({
9771
+ modelId: z8.string(),
9772
+ modelVersion: z8.string(),
9773
+ modelProvider: z8.string()
9614
9774
  }).optional(),
9615
- timestamp: z7.date().optional(),
9616
- providerMetadata: z7.record(z7.any()).optional(),
9617
- headers: z7.record(z7.string()).optional(),
9618
- request: z7.record(z7.any()).optional()
9775
+ timestamp: z8.date().optional(),
9776
+ providerMetadata: z8.record(z8.any()).optional(),
9777
+ headers: z8.record(z8.string()).optional(),
9778
+ request: z8.record(z8.any()).optional()
9619
9779
  }),
9620
9780
  stepResult: llmIterationStepResultSchema,
9621
- processorRetryCount: z7.number().optional(),
9622
- processorRetryFeedback: z7.string().optional()
9781
+ processorRetryCount: z8.number().optional(),
9782
+ processorRetryFeedback: z8.string().optional()
9623
9783
  });
9624
- var toolCallInputSchema = z7.object({
9625
- toolCallId: z7.string(),
9626
- toolName: z7.string(),
9627
- args: z7.record(z7.any()),
9628
- providerMetadata: z7.record(z7.any()).optional(),
9629
- providerExecuted: z7.boolean().optional(),
9630
- output: z7.any().optional()
9784
+ var toolCallInputSchema = z8.object({
9785
+ toolCallId: z8.string(),
9786
+ toolName: z8.string(),
9787
+ args: z8.record(z8.any()),
9788
+ providerMetadata: z8.record(z8.any()).optional(),
9789
+ providerExecuted: z8.boolean().optional(),
9790
+ output: z8.any().optional()
9631
9791
  });
9632
9792
  var toolCallOutputSchema = toolCallInputSchema.extend({
9633
- result: z7.any(),
9634
- error: z7.any().optional()
9793
+ result: z8.any(),
9794
+ error: z8.any().optional()
9635
9795
  });
9636
9796
 
9637
9797
  // src/processors/processors/prepare-step.ts
@@ -9684,10 +9844,10 @@ var AISDKV5InputStream = class extends MastraModelInput {
9684
9844
  constructor({
9685
9845
  component,
9686
9846
  name,
9687
- generateId: generateId3
9847
+ generateId: generateId2
9688
9848
  }) {
9689
9849
  super({ component, name });
9690
- this.#generateId = generateId3 ?? generateId;
9850
+ this.#generateId = generateId2 ?? generateId;
9691
9851
  }
9692
9852
  async transform({
9693
9853
  runId,
@@ -9739,12 +9899,12 @@ function execute({
9739
9899
  headers,
9740
9900
  shouldThrowError,
9741
9901
  methodType,
9742
- generateId: generateId3
9902
+ generateId: generateId2
9743
9903
  }) {
9744
9904
  const v5 = new AISDKV5InputStream({
9745
9905
  component: "LLM",
9746
9906
  name: model.modelId,
9747
- generateId: generateId3
9907
+ generateId: generateId2
9748
9908
  });
9749
9909
  const toolsAndToolChoice = prepareToolsAndToolChoice({
9750
9910
  tools,
@@ -10027,10 +10187,10 @@ async function processOutputStream({
10027
10187
  break;
10028
10188
  }
10029
10189
  case "tool-call-input-streaming-start": {
10030
- const tool = tools?.[chunk.payload.toolName] || Object.values(tools || {})?.find((tool2) => `id` in tool2 && tool2.id === chunk.payload.toolName);
10031
- if (tool && "onInputStart" in tool) {
10190
+ const tool2 = tools?.[chunk.payload.toolName] || Object.values(tools || {})?.find((tool3) => `id` in tool3 && tool3.id === chunk.payload.toolName);
10191
+ if (tool2 && "onInputStart" in tool2) {
10032
10192
  try {
10033
- await tool?.onInputStart?.({
10193
+ await tool2?.onInputStart?.({
10034
10194
  toolCallId: chunk.payload.toolCallId,
10035
10195
  messages: messageList.get.input.aiV5.model(),
10036
10196
  abortSignal: options?.abortSignal
@@ -10045,10 +10205,10 @@ async function processOutputStream({
10045
10205
  break;
10046
10206
  }
10047
10207
  case "tool-call-delta": {
10048
- const tool = tools?.[chunk.payload.toolName || ""] || Object.values(tools || {})?.find((tool2) => `id` in tool2 && tool2.id === chunk.payload.toolName);
10049
- if (tool && "onInputDelta" in tool) {
10208
+ const tool2 = tools?.[chunk.payload.toolName || ""] || Object.values(tools || {})?.find((tool3) => `id` in tool3 && tool3.id === chunk.payload.toolName);
10209
+ if (tool2 && "onInputDelta" in tool2) {
10050
10210
  try {
10051
- await tool?.onInputDelta?.({
10211
+ await tool2?.onInputDelta?.({
10052
10212
  inputTextDelta: chunk.payload.argsTextDelta,
10053
10213
  toolCallId: chunk.payload.toolCallId,
10054
10214
  messages: messageList.get.input.aiV5.model(),
@@ -10308,6 +10468,7 @@ function createLLMExecutionStep({
10308
10468
  requestContext,
10309
10469
  methodType,
10310
10470
  modelSpanTracker,
10471
+ autoResumeSuspendedTools,
10311
10472
  maxProcessorRetries
10312
10473
  }) {
10313
10474
  const initialSystemMessages = messageList.getAllSystemMessages();
@@ -10378,7 +10539,33 @@ function createLLMExecutionStep({
10378
10539
  downloadConcurrency,
10379
10540
  supportedUrls: currentStep.model?.supportedUrls
10380
10541
  };
10381
- const inputMessages = await messageList.get.all.aiV5.llmPrompt(messageListPromptArgs);
10542
+ let inputMessages = await messageList.get.all.aiV5.llmPrompt(messageListPromptArgs);
10543
+ if (autoResumeSuspendedTools) {
10544
+ const messages2 = messageList.get.all.db();
10545
+ const assistantMessages = [...messages2].reverse().filter((message) => message.role === "assistant");
10546
+ const suspendedToolsMessage = assistantMessages.find(
10547
+ (message) => message.content.metadata?.suspendedTools || message.content.metadata?.pendingToolApprovals
10548
+ );
10549
+ if (suspendedToolsMessage) {
10550
+ const metadata = suspendedToolsMessage.content.metadata;
10551
+ const suspendedToolObj = metadata?.suspendedTools || metadata?.pendingToolApprovals;
10552
+ const suspendedTools = Object.values(suspendedToolObj);
10553
+ if (suspendedTools.length > 0) {
10554
+ inputMessages = inputMessages.map((message, index) => {
10555
+ if (message.role === "system" && index === 0) {
10556
+ message.content = message.content + `
10557
+
10558
+ Analyse the suspended tools: ${JSON.stringify(suspendedTools)}, using the messages available to you and the resumeSchema of each suspended tool, find the tool whose resumeData you can construct properly.
10559
+ resumeData can not be an empty object nor null/undefined.
10560
+ When you find that and call that tool, add the resumeData to the tool call arguments/input.
10561
+ Also, add the runId of the suspended tool as suspendedToolRunId to the tool call arguments/input.
10562
+ If the suspendedTool.type is 'approval', resumeData will be an object that contains 'approved' which can either be true or false depending on the user's message.`;
10563
+ }
10564
+ return message;
10565
+ });
10566
+ }
10567
+ }
10568
+ }
10382
10569
  switch (currentStep.model.specificationVersion) {
10383
10570
  case "v2": {
10384
10571
  modelResult = executeWithContextSync({
@@ -10739,11 +10926,11 @@ function createLLMMappingStep({ models, _internal, ...rest }, llmExecutionStep)
10739
10926
  }
10740
10927
  return createStep({
10741
10928
  id: "llmExecutionMappingStep",
10742
- inputSchema: z7.array(toolCallOutputSchema),
10929
+ inputSchema: z8.array(toolCallOutputSchema),
10743
10930
  outputSchema: llmIterationOutputSchema,
10744
10931
  execute: async ({ inputData, getStepResult: getStepResult2, bail }) => {
10745
10932
  const initialResult = getStepResult2(llmExecutionStep);
10746
- if (inputData?.every((toolCall) => toolCall?.result === void 0)) {
10933
+ if (inputData?.some((toolCall) => toolCall?.result === void 0)) {
10747
10934
  const errorResults = inputData.filter((toolCall) => toolCall?.error);
10748
10935
  const toolResultMessageId = rest.experimental_generateMessageId?.() || _internal?.generateId?.();
10749
10936
  if (errorResults?.length) {
@@ -10788,7 +10975,14 @@ function createLLMMappingStep({ models, _internal, ...rest }, llmExecutionStep)
10788
10975
  if (initialResult.stepResult.reason !== "retry") {
10789
10976
  initialResult.stepResult.isContinued = false;
10790
10977
  }
10791
- return bail(initialResult);
10978
+ return bail({
10979
+ ...initialResult,
10980
+ messages: {
10981
+ all: rest.messageList.get.all.aiV5.model(),
10982
+ user: rest.messageList.get.input.aiV5.model(),
10983
+ nonUser: rest.messageList.get.response.aiV5.model()
10984
+ }
10985
+ });
10792
10986
  }
10793
10987
  if (inputData?.length) {
10794
10988
  for (const toolCall of inputData) {
@@ -10846,11 +11040,10 @@ function createLLMMappingStep({ models, _internal, ...rest }, llmExecutionStep)
10846
11040
  }
10847
11041
  };
10848
11042
  }
11043
+ return initialResult;
10849
11044
  }
10850
11045
  });
10851
11046
  }
10852
-
10853
- // src/loop/workflows/agentic-execution/tool-call-step.ts
10854
11047
  function createToolCallStep({
10855
11048
  tools,
10856
11049
  messageList,
@@ -10866,28 +11059,39 @@ function createToolCallStep({
10866
11059
  id: "toolCallStep",
10867
11060
  inputSchema: toolCallInputSchema,
10868
11061
  outputSchema: toolCallOutputSchema,
10869
- execute: async ({ inputData, suspend, resumeData, requestContext }) => {
11062
+ execute: async ({ inputData, suspend, resumeData: workflowResumeData, requestContext }) => {
10870
11063
  const stepTools = _internal?.stepTools || tools;
10871
- const tool = stepTools?.[inputData.toolName] || Object.values(stepTools || {})?.find((t) => `id` in t && t.id === inputData.toolName);
10872
- const addToolApprovalMetadata = (toolCallId, toolName, args) => {
11064
+ const tool2 = stepTools?.[inputData.toolName] || Object.values(stepTools || {})?.find((t) => `id` in t && t.id === inputData.toolName);
11065
+ const addToolMetadata = ({
11066
+ toolCallId,
11067
+ toolName,
11068
+ args,
11069
+ suspendPayload,
11070
+ resumeSchema,
11071
+ type
11072
+ }) => {
11073
+ const metadataKey = type === "suspension" ? "suspendedTools" : "pendingToolApprovals";
10873
11074
  const responseMessages = messageList.get.response.db();
10874
11075
  const lastAssistantMessage = [...responseMessages].reverse().find((msg) => msg.role === "assistant");
10875
11076
  if (lastAssistantMessage) {
10876
11077
  const content = lastAssistantMessage.content;
10877
11078
  if (!content) return;
10878
11079
  const metadata = typeof lastAssistantMessage.content.metadata === "object" && lastAssistantMessage.content.metadata !== null ? lastAssistantMessage.content.metadata : {};
10879
- metadata.pendingToolApprovals = metadata.pendingToolApprovals || {};
10880
- metadata.pendingToolApprovals[toolCallId] = {
11080
+ metadata[metadataKey] = metadata[metadataKey] || {};
11081
+ metadata[metadataKey][toolName] = {
11082
+ toolCallId,
10881
11083
  toolName,
10882
11084
  args,
10883
- type: "approval",
10884
- runId
11085
+ type,
11086
+ runId,
10885
11087
  // Store the runId so we can resume after page refresh
11088
+ ...type === "suspension" ? { suspendPayload } : {},
11089
+ resumeSchema
10886
11090
  };
10887
11091
  lastAssistantMessage.content.metadata = metadata;
10888
11092
  }
10889
11093
  };
10890
- const removeToolApprovalMetadata = async (toolCallId) => {
11094
+ const removeToolMetadata = async (toolName, type) => {
10891
11095
  const { saveQueueManager, memoryConfig, threadId } = _internal || {};
10892
11096
  if (!saveQueueManager || !threadId) {
10893
11097
  return;
@@ -10898,24 +11102,25 @@ function createToolCallStep({
10898
11102
  const metadata = typeof content.metadata === "object" && content.metadata !== null ? content.metadata : void 0;
10899
11103
  return metadata;
10900
11104
  };
11105
+ const metadataKey = type === "suspension" ? "suspendedTools" : "pendingToolApprovals";
10901
11106
  const allMessages = messageList.get.all.db();
10902
11107
  const lastAssistantMessage = [...allMessages].reverse().find((msg) => {
10903
11108
  const metadata = getMetadata(msg);
10904
- const pendingToolApprovals = metadata?.pendingToolApprovals;
10905
- return !!pendingToolApprovals?.[toolCallId];
11109
+ const suspendedTools = metadata?.[metadataKey];
11110
+ return !!suspendedTools?.[toolName];
10906
11111
  });
10907
11112
  if (lastAssistantMessage) {
10908
11113
  const metadata = getMetadata(lastAssistantMessage);
10909
- const pendingToolApprovals = metadata?.pendingToolApprovals;
10910
- if (pendingToolApprovals && typeof pendingToolApprovals === "object") {
10911
- delete pendingToolApprovals[toolCallId];
10912
- if (metadata && Object.keys(pendingToolApprovals).length === 0) {
10913
- delete metadata.pendingToolApprovals;
11114
+ const suspendedTools = metadata?.[metadataKey];
11115
+ if (suspendedTools && typeof suspendedTools === "object") {
11116
+ delete suspendedTools[toolName];
11117
+ if (metadata && Object.keys(suspendedTools).length === 0) {
11118
+ delete metadata[metadataKey];
10914
11119
  }
10915
11120
  try {
10916
11121
  await saveQueueManager.flushMessages(messageList, threadId, memoryConfig);
10917
11122
  } catch (error) {
10918
- console.error("Error removing tool approval metadata:", error);
11123
+ console.error("Error removing tool suspension metadata:", error);
10919
11124
  }
10920
11125
  }
10921
11126
  }
@@ -10948,12 +11153,12 @@ function createToolCallStep({
10948
11153
  result: inputData.output
10949
11154
  };
10950
11155
  }
10951
- if (!tool) {
11156
+ if (!tool2) {
10952
11157
  throw new Error(`Tool ${inputData.toolName} not found`);
10953
11158
  }
10954
- if (tool && "onInputAvailable" in tool) {
11159
+ if (tool2 && "onInputAvailable" in tool2) {
10955
11160
  try {
10956
- await tool?.onInputAvailable?.({
11161
+ await tool2?.onInputAvailable?.({
10957
11162
  toolCallId: inputData.toolCallId,
10958
11163
  input: inputData.args,
10959
11164
  messages: messageList.get.input.aiV5.model(),
@@ -10963,12 +11168,21 @@ function createToolCallStep({
10963
11168
  console.error("Error calling onInputAvailable", error);
10964
11169
  }
10965
11170
  }
10966
- if (!tool.execute) {
11171
+ if (!tool2.execute) {
10967
11172
  return inputData;
10968
11173
  }
10969
11174
  try {
10970
11175
  const requireToolApproval = requestContext.get("__mastra_requireToolApproval");
10971
- if (requireToolApproval || tool.requireApproval) {
11176
+ let resumeDataFromArgs = void 0;
11177
+ let args = inputData.args;
11178
+ if (typeof inputData.args === "object" && inputData.args !== null) {
11179
+ const { resumeData: resumeDataFromInput, ...argsFromInput } = inputData.args;
11180
+ args = argsFromInput;
11181
+ resumeDataFromArgs = resumeDataFromInput;
11182
+ }
11183
+ const resumeData = resumeDataFromArgs ?? workflowResumeData;
11184
+ const isResumeToolCall = !!resumeDataFromArgs;
11185
+ if (requireToolApproval || tool2.requireApproval) {
10972
11186
  if (!resumeData) {
10973
11187
  controller.enqueue({
10974
11188
  type: "tool-call-approval",
@@ -10980,7 +11194,17 @@ function createToolCallStep({
10980
11194
  args: inputData.args
10981
11195
  }
10982
11196
  });
10983
- addToolApprovalMetadata(inputData.toolCallId, inputData.toolName, inputData.args);
11197
+ addToolMetadata({
11198
+ toolCallId: inputData.toolCallId,
11199
+ toolName: inputData.toolName,
11200
+ args: inputData.args,
11201
+ type: "approval",
11202
+ resumeSchema: z8.object({
11203
+ approved: z8.boolean().describe(
11204
+ "Controls if the tool call is approved or not, should be true when approved and false when declined"
11205
+ )
11206
+ })
11207
+ });
10984
11208
  await flushMessagesBeforeSuspension();
10985
11209
  return suspend(
10986
11210
  {
@@ -10996,7 +11220,7 @@ function createToolCallStep({
10996
11220
  }
10997
11221
  );
10998
11222
  } else {
10999
- await removeToolApprovalMetadata(inputData.toolCallId);
11223
+ await removeToolMetadata(inputData.toolName, "approval");
11000
11224
  if (!resumeData.approved) {
11001
11225
  return {
11002
11226
  result: "Tool call was not approved by the user",
@@ -11004,6 +11228,8 @@ function createToolCallStep({
11004
11228
  };
11005
11229
  }
11006
11230
  }
11231
+ } else if (isResumeToolCall) {
11232
+ await removeToolMetadata(inputData.toolName, "suspension");
11007
11233
  }
11008
11234
  const toolOptions = {
11009
11235
  abortSignal: options?.abortSignal,
@@ -11012,18 +11238,33 @@ function createToolCallStep({
11012
11238
  outputWriter,
11013
11239
  // Pass current step span as parent for tool call spans
11014
11240
  tracingContext: modelSpanTracker?.getTracingContext(),
11015
- suspend: async (suspendPayload) => {
11241
+ suspend: async (suspendPayload, options2) => {
11016
11242
  controller.enqueue({
11017
11243
  type: "tool-call-suspended",
11018
11244
  runId,
11019
11245
  from: "AGENT" /* AGENT */,
11020
- payload: { toolCallId: inputData.toolCallId, toolName: inputData.toolName, suspendPayload }
11246
+ payload: {
11247
+ toolCallId: inputData.toolCallId,
11248
+ toolName: inputData.toolName,
11249
+ suspendPayload,
11250
+ args: inputData.args
11251
+ }
11252
+ });
11253
+ addToolMetadata({
11254
+ toolCallId: inputData.toolCallId,
11255
+ toolName: inputData.toolName,
11256
+ args,
11257
+ suspendPayload,
11258
+ type: "suspension",
11259
+ resumeSchema: options2?.resumeSchema
11021
11260
  });
11022
11261
  await flushMessagesBeforeSuspension();
11023
11262
  return await suspend(
11024
11263
  {
11025
11264
  toolCallSuspended: suspendPayload,
11026
- __streamState: streamState.serialize()
11265
+ __streamState: streamState.serialize(),
11266
+ toolName: inputData.toolName,
11267
+ resumeLabel: options2?.resumeLabel
11027
11268
  },
11028
11269
  {
11029
11270
  resumeLabel: inputData.toolCallId
@@ -11032,10 +11273,10 @@ function createToolCallStep({
11032
11273
  },
11033
11274
  resumeData
11034
11275
  };
11035
- const result = await tool.execute(inputData.args, toolOptions);
11036
- if (tool && "onOutput" in tool && typeof tool.onOutput === "function") {
11276
+ const result = await tool2.execute(args, toolOptions);
11277
+ if (tool2 && "onOutput" in tool2 && typeof tool2.onOutput === "function") {
11037
11278
  try {
11038
- await tool.onOutput({
11279
+ await tool2.onOutput({
11039
11280
  toolCallId: inputData.toolCallId,
11040
11281
  toolName: inputData.toolName,
11041
11282
  output: result,
@@ -11075,6 +11316,25 @@ function createAgenticExecutionWorkflow({ models, _internal, ...rest }) {
11075
11316
  },
11076
11317
  llmExecutionStep
11077
11318
  );
11319
+ let toolCallConcurrency = 10;
11320
+ if (rest?.toolCallConcurrency) {
11321
+ toolCallConcurrency = rest.toolCallConcurrency > 0 ? rest.toolCallConcurrency : 10;
11322
+ }
11323
+ const hasRequireToolApproval = !!rest.requireToolApproval;
11324
+ let hasSuspendSchema = false;
11325
+ let hasRequireApproval = false;
11326
+ if (rest.tools) {
11327
+ for (const tool2 of Object.values(rest.tools)) {
11328
+ if (tool2?.hasSuspendSchema) {
11329
+ hasSuspendSchema = true;
11330
+ }
11331
+ if (tool2?.requireApproval) {
11332
+ hasRequireApproval = true;
11333
+ }
11334
+ if (hasSuspendSchema || hasRequireApproval) break;
11335
+ }
11336
+ }
11337
+ const sequentialExecutionRequired = hasRequireToolApproval || hasSuspendSchema || hasRequireApproval;
11078
11338
  return createWorkflow({
11079
11339
  id: "executionWorkflow",
11080
11340
  inputSchema: llmIterationOutputSchema,
@@ -11104,7 +11364,7 @@ function createAgenticExecutionWorkflow({ models, _internal, ...rest }) {
11104
11364
  return typedInputData.output.toolCalls || [];
11105
11365
  },
11106
11366
  { id: "map-tool-calls" }
11107
- ).foreach(toolCallStep, { concurrency: 10 }).then(llmMappingStep).commit();
11367
+ ).foreach(toolCallStep, { concurrency: sequentialExecutionRequired ? 1 : toolCallConcurrency }).then(llmMappingStep).commit();
11108
11368
  }
11109
11369
 
11110
11370
  // src/loop/workflows/agentic-loop/index.ts
@@ -11237,6 +11497,7 @@ function workflowLoopStream({
11237
11497
  streamState,
11238
11498
  agentId,
11239
11499
  toolCallId,
11500
+ toolCallConcurrency,
11240
11501
  ...rest
11241
11502
  }) {
11242
11503
  return new ReadableStream$1({
@@ -11254,7 +11515,9 @@ function workflowLoopStream({
11254
11515
  format: 2,
11255
11516
  parts: [dataPart]
11256
11517
  },
11257
- createdAt: /* @__PURE__ */ new Date()
11518
+ createdAt: /* @__PURE__ */ new Date(),
11519
+ threadId: _internal?.threadId,
11520
+ resourceId: _internal?.resourceId
11258
11521
  };
11259
11522
  messageList.add(message, "response");
11260
11523
  }
@@ -11274,6 +11537,8 @@ function workflowLoopStream({
11274
11537
  startTimestamp,
11275
11538
  streamState,
11276
11539
  agentId,
11540
+ requireToolApproval,
11541
+ toolCallConcurrency,
11277
11542
  ...rest
11278
11543
  });
11279
11544
  if (rest.mastra) {
@@ -11304,7 +11569,8 @@ function workflowLoopStream({
11304
11569
  runId,
11305
11570
  from: "AGENT" /* AGENT */,
11306
11571
  payload: {
11307
- id: agentId
11572
+ id: agentId,
11573
+ messageId
11308
11574
  }
11309
11575
  });
11310
11576
  }
@@ -11326,18 +11592,7 @@ function workflowLoopStream({
11326
11592
  });
11327
11593
  if (executionResult.status !== "success") {
11328
11594
  if (executionResult.status === "failed") {
11329
- let executionResultError = executionResult.error;
11330
- if (typeof executionResult.error === "string") {
11331
- const prependedErrorString = "Error: ";
11332
- if (executionResult.error.startsWith(`${prependedErrorString}${prependedErrorString}`)) {
11333
- executionResultError = executionResult.error.substring(
11334
- `${prependedErrorString}${prependedErrorString}`.length
11335
- );
11336
- } else if (executionResult.error.startsWith(prependedErrorString)) {
11337
- executionResultError = executionResult.error.substring(prependedErrorString.length);
11338
- }
11339
- }
11340
- const error = getErrorFromUnknown(executionResultError, {
11595
+ const error = getErrorFromUnknown(executionResult.error, {
11341
11596
  fallbackMessage: "Unknown error in agent workflow stream"
11342
11597
  });
11343
11598
  controller.enqueue({
@@ -11350,9 +11605,13 @@ function workflowLoopStream({
11350
11605
  await rest.options?.onError?.({ error });
11351
11606
  }
11352
11607
  }
11608
+ if (executionResult.status !== "suspended") {
11609
+ await agenticLoopWorkflow.deleteWorkflowRunById(runId);
11610
+ }
11353
11611
  controller.close();
11354
11612
  return;
11355
11613
  }
11614
+ await agenticLoopWorkflow.deleteWorkflowRunById(runId);
11356
11615
  controller.enqueue({
11357
11616
  type: "finish",
11358
11617
  runId,
@@ -11387,6 +11646,7 @@ function loop({
11387
11646
  returnScorerData,
11388
11647
  requireToolApproval,
11389
11648
  agentId,
11649
+ toolCallConcurrency,
11390
11650
  ...rest
11391
11651
  }) {
11392
11652
  let loggerToUse = logger || new ConsoleLogger({
@@ -11443,6 +11703,7 @@ function loop({
11443
11703
  messageId,
11444
11704
  agentId,
11445
11705
  requireToolApproval,
11706
+ toolCallConcurrency,
11446
11707
  streamState: {
11447
11708
  serialize: serializeStreamState,
11448
11709
  deserialize: deserializeStreamState
@@ -11601,6 +11862,7 @@ var MastraLLMVNext = class extends MastraBase {
11601
11862
  tracingContext,
11602
11863
  messageList,
11603
11864
  requireToolApproval,
11865
+ toolCallConcurrency,
11604
11866
  _internal,
11605
11867
  agentId,
11606
11868
  agentName,
@@ -11608,6 +11870,7 @@ var MastraLLMVNext = class extends MastraBase {
11608
11870
  requestContext,
11609
11871
  methodType,
11610
11872
  includeRawChunks,
11873
+ autoResumeSuspendedTools,
11611
11874
  maxProcessorRetries
11612
11875
  }) {
11613
11876
  let stopWhenToUse;
@@ -11667,11 +11930,13 @@ var MastraLLMVNext = class extends MastraBase {
11667
11930
  returnScorerData,
11668
11931
  modelSpanTracker,
11669
11932
  requireToolApproval,
11933
+ toolCallConcurrency,
11670
11934
  agentId,
11671
11935
  agentName,
11672
11936
  requestContext,
11673
11937
  methodType,
11674
11938
  includeRawChunks,
11939
+ autoResumeSuspendedTools,
11675
11940
  maxProcessorRetries,
11676
11941
  options: {
11677
11942
  ...options,
@@ -11796,7 +12061,7 @@ var MastraLLMVNext = class extends MastraBase {
11796
12061
  }
11797
12062
  }
11798
12063
  };
11799
- var PRIMITIVE_TYPES = z7.enum(["agent", "workflow", "none", "tool"]);
12064
+ var PRIMITIVE_TYPES = z8.enum(["agent", "workflow", "none", "tool"]);
11800
12065
 
11801
12066
  // src/loop/network/index.ts
11802
12067
  async function getRoutingAgent({ requestContext, agent }) {
@@ -11815,9 +12080,9 @@ async function getRoutingAgent({ requestContext, agent }) {
11815
12080
  )}`;
11816
12081
  }).join("\n");
11817
12082
  const memoryTools = await memoryToUse?.listTools?.();
11818
- const toolList = Object.entries({ ...toolsToUse, ...memoryTools }).map(([name, tool]) => {
11819
- return ` - **${name}**: ${tool.description}, input schema: ${JSON.stringify(
11820
- zodToJsonSchema$1(tool.inputSchema || z7.object({}))
12083
+ const toolList = Object.entries({ ...toolsToUse, ...memoryTools }).map(([name, tool2]) => {
12084
+ return ` - **${name}**: ${tool2.description}, input schema: ${JSON.stringify(
12085
+ zodToJsonSchema$1(tool2.inputSchema || z8.object({}))
11821
12086
  )}`;
11822
12087
  }).join("\n");
11823
12088
  const instructions = `
@@ -11888,7 +12153,7 @@ async function prepareMemoryStep({
11888
12153
  messages,
11889
12154
  routingAgent,
11890
12155
  requestContext,
11891
- generateId: generateId3,
12156
+ generateId: generateId2,
11892
12157
  tracingContext,
11893
12158
  memoryConfig
11894
12159
  }) {
@@ -11910,7 +12175,7 @@ async function prepareMemoryStep({
11910
12175
  memory.saveMessages({
11911
12176
  messages: [
11912
12177
  {
11913
- id: generateId3(),
12178
+ id: generateId2(),
11914
12179
  type: "text",
11915
12180
  role: "user",
11916
12181
  content: { parts: [{ type: "text", text: messages }], format: 2 },
@@ -11977,43 +12242,43 @@ async function createNetworkLoop({
11977
12242
  requestContext,
11978
12243
  runId,
11979
12244
  agent,
11980
- generateId: generateId3,
12245
+ generateId: generateId2,
11981
12246
  routingAgentOptions
11982
12247
  }) {
11983
12248
  const routingStep = createStep({
11984
12249
  id: "routing-agent-step",
11985
- inputSchema: z7.object({
11986
- task: z7.string(),
11987
- primitiveId: z7.string(),
12250
+ inputSchema: z8.object({
12251
+ task: z8.string(),
12252
+ primitiveId: z8.string(),
11988
12253
  primitiveType: PRIMITIVE_TYPES,
11989
- result: z7.string().optional(),
11990
- iteration: z7.number(),
11991
- threadId: z7.string().optional(),
11992
- threadResourceId: z7.string().optional(),
11993
- isOneOff: z7.boolean(),
11994
- verboseIntrospection: z7.boolean()
12254
+ result: z8.string().optional(),
12255
+ iteration: z8.number(),
12256
+ threadId: z8.string().optional(),
12257
+ threadResourceId: z8.string().optional(),
12258
+ isOneOff: z8.boolean(),
12259
+ verboseIntrospection: z8.boolean()
11995
12260
  }),
11996
- outputSchema: z7.object({
11997
- task: z7.string(),
11998
- primitiveId: z7.string(),
12261
+ outputSchema: z8.object({
12262
+ task: z8.string(),
12263
+ primitiveId: z8.string(),
11999
12264
  primitiveType: PRIMITIVE_TYPES,
12000
- prompt: z7.string(),
12001
- result: z7.string(),
12002
- isComplete: z7.boolean().optional(),
12003
- selectionReason: z7.string(),
12004
- iteration: z7.number()
12265
+ prompt: z8.string(),
12266
+ result: z8.string(),
12267
+ isComplete: z8.boolean().optional(),
12268
+ selectionReason: z8.string(),
12269
+ iteration: z8.number()
12005
12270
  }),
12006
12271
  execute: async ({ inputData, getInitData, writer }) => {
12007
12272
  const initData = await getInitData();
12008
- const completionSchema = z7.object({
12009
- isComplete: z7.boolean(),
12010
- finalResult: z7.string(),
12011
- completionReason: z7.string()
12273
+ const completionSchema = z8.object({
12274
+ isComplete: z8.boolean(),
12275
+ finalResult: z8.string(),
12276
+ completionReason: z8.string()
12012
12277
  });
12013
12278
  const routingAgent = await getRoutingAgent({ requestContext, agent });
12014
12279
  let completionResult;
12015
12280
  const iterationCount = (inputData.iteration ?? -1) + 1;
12016
- const stepId = generateId3();
12281
+ const stepId = generateId2();
12017
12282
  await writer.write({
12018
12283
  type: "routing-agent-start",
12019
12284
  payload: {
@@ -12149,7 +12414,7 @@ async function createNetworkLoop({
12149
12414
  await memory?.saveMessages({
12150
12415
  messages: [
12151
12416
  {
12152
- id: generateId3(),
12417
+ id: generateId2(),
12153
12418
  type: "text",
12154
12419
  role: "assistant",
12155
12420
  content: {
@@ -12209,11 +12474,11 @@ ${completionResult?.object?.finalResult}` : ""}
12209
12474
  ];
12210
12475
  const options = {
12211
12476
  structuredOutput: {
12212
- schema: z7.object({
12213
- primitiveId: z7.string().describe("The id of the primitive to be called"),
12477
+ schema: z8.object({
12478
+ primitiveId: z8.string().describe("The id of the primitive to be called"),
12214
12479
  primitiveType: PRIMITIVE_TYPES.describe("The type of the primitive to be called"),
12215
- prompt: z7.string().describe("The json string or text value to be sent to the primitive"),
12216
- selectionReason: z7.string().describe("The reason you picked the primitive")
12480
+ prompt: z8.string().describe("The json string or text value to be sent to the primitive"),
12481
+ selectionReason: z8.string().describe("The reason you picked the primitive")
12217
12482
  })
12218
12483
  },
12219
12484
  requestContext,
@@ -12257,23 +12522,23 @@ ${completionResult?.object?.finalResult}` : ""}
12257
12522
  });
12258
12523
  const agentStep = createStep({
12259
12524
  id: "agent-execution-step",
12260
- inputSchema: z7.object({
12261
- task: z7.string(),
12262
- primitiveId: z7.string(),
12525
+ inputSchema: z8.object({
12526
+ task: z8.string(),
12527
+ primitiveId: z8.string(),
12263
12528
  primitiveType: PRIMITIVE_TYPES,
12264
- prompt: z7.string(),
12265
- result: z7.string(),
12266
- isComplete: z7.boolean().optional(),
12267
- selectionReason: z7.string(),
12268
- iteration: z7.number()
12529
+ prompt: z8.string(),
12530
+ result: z8.string(),
12531
+ isComplete: z8.boolean().optional(),
12532
+ selectionReason: z8.string(),
12533
+ iteration: z8.number()
12269
12534
  }),
12270
- outputSchema: z7.object({
12271
- task: z7.string(),
12272
- primitiveId: z7.string(),
12535
+ outputSchema: z8.object({
12536
+ task: z8.string(),
12537
+ primitiveId: z8.string(),
12273
12538
  primitiveType: PRIMITIVE_TYPES,
12274
- result: z7.string(),
12275
- isComplete: z7.boolean().optional(),
12276
- iteration: z7.number()
12539
+ result: z8.string(),
12540
+ isComplete: z8.boolean().optional(),
12541
+ iteration: z8.number()
12277
12542
  }),
12278
12543
  execute: async ({ inputData, writer, getInitData }) => {
12279
12544
  const agentsMap = await agent.listAgents({ requestContext });
@@ -12288,7 +12553,7 @@ ${completionResult?.object?.finalResult}` : ""}
12288
12553
  throw mastraError;
12289
12554
  }
12290
12555
  const agentId = agentForStep.id;
12291
- const stepId = generateId3();
12556
+ const stepId = generateId2();
12292
12557
  await writer.write({
12293
12558
  type: "agent-execution-start",
12294
12559
  payload: {
@@ -12329,7 +12594,7 @@ ${completionResult?.object?.finalResult}` : ""}
12329
12594
  await memory?.saveMessages({
12330
12595
  messages: [
12331
12596
  {
12332
- id: generateId3(),
12597
+ id: generateId2(),
12333
12598
  type: "text",
12334
12599
  role: "assistant",
12335
12600
  content: {
@@ -12342,7 +12607,7 @@ ${completionResult?.object?.finalResult}` : ""}
12342
12607
  primitiveType: inputData.primitiveType,
12343
12608
  primitiveId: inputData.primitiveId,
12344
12609
  input: inputData.prompt,
12345
- finalResult: { text: await result.text, toolCalls: await result.toolCalls, messages }
12610
+ finalResult: { text: await result.text, messages }
12346
12611
  })
12347
12612
  }
12348
12613
  ],
@@ -12383,23 +12648,23 @@ ${completionResult?.object?.finalResult}` : ""}
12383
12648
  });
12384
12649
  const workflowStep = createStep({
12385
12650
  id: "workflow-execution-step",
12386
- inputSchema: z7.object({
12387
- task: z7.string(),
12388
- primitiveId: z7.string(),
12651
+ inputSchema: z8.object({
12652
+ task: z8.string(),
12653
+ primitiveId: z8.string(),
12389
12654
  primitiveType: PRIMITIVE_TYPES,
12390
- prompt: z7.string(),
12391
- result: z7.string(),
12392
- isComplete: z7.boolean().optional(),
12393
- selectionReason: z7.string(),
12394
- iteration: z7.number()
12655
+ prompt: z8.string(),
12656
+ result: z8.string(),
12657
+ isComplete: z8.boolean().optional(),
12658
+ selectionReason: z8.string(),
12659
+ iteration: z8.number()
12395
12660
  }),
12396
- outputSchema: z7.object({
12397
- task: z7.string(),
12398
- primitiveId: z7.string(),
12661
+ outputSchema: z8.object({
12662
+ task: z8.string(),
12663
+ primitiveId: z8.string(),
12399
12664
  primitiveType: PRIMITIVE_TYPES,
12400
- result: z7.string(),
12401
- isComplete: z7.boolean().optional(),
12402
- iteration: z7.number()
12665
+ result: z8.string(),
12666
+ isComplete: z8.boolean().optional(),
12667
+ iteration: z8.number()
12403
12668
  }),
12404
12669
  execute: async ({ inputData, writer, getInitData }) => {
12405
12670
  const workflowsMap = await agent.listWorkflows({ requestContext });
@@ -12429,7 +12694,7 @@ ${completionResult?.object?.finalResult}` : ""}
12429
12694
  );
12430
12695
  throw mastraError;
12431
12696
  }
12432
- const stepId = generateId3();
12697
+ const stepId = generateId2();
12433
12698
  const run = await wf.createRun({ runId });
12434
12699
  const toolData = {
12435
12700
  workflowId: wf.id,
@@ -12482,7 +12747,7 @@ ${completionResult?.object?.finalResult}` : ""}
12482
12747
  await memory?.saveMessages({
12483
12748
  messages: [
12484
12749
  {
12485
- id: generateId3(),
12750
+ id: generateId2(),
12486
12751
  type: "text",
12487
12752
  role: "assistant",
12488
12753
  content: { parts: [{ type: "text", text: finalResult }], format: 2 },
@@ -12517,23 +12782,23 @@ ${completionResult?.object?.finalResult}` : ""}
12517
12782
  });
12518
12783
  const toolStep = createStep({
12519
12784
  id: "tool-execution-step",
12520
- inputSchema: z7.object({
12521
- task: z7.string(),
12522
- primitiveId: z7.string(),
12785
+ inputSchema: z8.object({
12786
+ task: z8.string(),
12787
+ primitiveId: z8.string(),
12523
12788
  primitiveType: PRIMITIVE_TYPES,
12524
- prompt: z7.string(),
12525
- result: z7.string(),
12526
- isComplete: z7.boolean().optional(),
12527
- selectionReason: z7.string(),
12528
- iteration: z7.number()
12789
+ prompt: z8.string(),
12790
+ result: z8.string(),
12791
+ isComplete: z8.boolean().optional(),
12792
+ selectionReason: z8.string(),
12793
+ iteration: z8.number()
12529
12794
  }),
12530
- outputSchema: z7.object({
12531
- task: z7.string(),
12532
- primitiveId: z7.string(),
12795
+ outputSchema: z8.object({
12796
+ task: z8.string(),
12797
+ primitiveId: z8.string(),
12533
12798
  primitiveType: PRIMITIVE_TYPES,
12534
- result: z7.string(),
12535
- isComplete: z7.boolean().optional(),
12536
- iteration: z7.number()
12799
+ result: z8.string(),
12800
+ isComplete: z8.boolean().optional(),
12801
+ iteration: z8.number()
12537
12802
  }),
12538
12803
  execute: async ({ inputData, getInitData, writer }) => {
12539
12804
  const initData = await getInitData();
@@ -12541,8 +12806,8 @@ ${completionResult?.object?.finalResult}` : ""}
12541
12806
  const memory = await agent.getMemory({ requestContext });
12542
12807
  const memoryTools = await memory?.listTools?.();
12543
12808
  const toolsMap = { ...agentTools, ...memoryTools };
12544
- let tool = toolsMap[inputData.primitiveId];
12545
- if (!tool) {
12809
+ let tool2 = toolsMap[inputData.primitiveId];
12810
+ if (!tool2) {
12546
12811
  const mastraError = new MastraError({
12547
12812
  id: "AGENT_NETWORK_TOOL_EXECUTION_STEP_INVALID_TASK_INPUT",
12548
12813
  domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
@@ -12551,7 +12816,7 @@ ${completionResult?.object?.finalResult}` : ""}
12551
12816
  });
12552
12817
  throw mastraError;
12553
12818
  }
12554
- if (!tool.execute) {
12819
+ if (!tool2.execute) {
12555
12820
  const mastraError = new MastraError({
12556
12821
  id: "AGENT_NETWORK_TOOL_EXECUTION_STEP_INVALID_TASK_INPUT",
12557
12822
  domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
@@ -12560,7 +12825,7 @@ ${completionResult?.object?.finalResult}` : ""}
12560
12825
  });
12561
12826
  throw mastraError;
12562
12827
  }
12563
- const toolId = tool.id;
12828
+ const toolId = tool2.id;
12564
12829
  let inputDataToUse;
12565
12830
  try {
12566
12831
  inputDataToUse = JSON.parse(inputData.prompt);
@@ -12576,7 +12841,7 @@ ${completionResult?.object?.finalResult}` : ""}
12576
12841
  );
12577
12842
  throw mastraError;
12578
12843
  }
12579
- const toolCallId = generateId3();
12844
+ const toolCallId = generateId2();
12580
12845
  await writer?.write({
12581
12846
  type: "tool-execution-start",
12582
12847
  payload: {
@@ -12591,7 +12856,7 @@ ${completionResult?.object?.finalResult}` : ""}
12591
12856
  from: "NETWORK" /* NETWORK */,
12592
12857
  runId
12593
12858
  });
12594
- const finalResult = await tool.execute(
12859
+ const finalResult = await tool2.execute(
12595
12860
  inputDataToUse,
12596
12861
  {
12597
12862
  requestContext,
@@ -12613,7 +12878,7 @@ ${completionResult?.object?.finalResult}` : ""}
12613
12878
  await memory?.saveMessages({
12614
12879
  messages: [
12615
12880
  {
12616
- id: generateId3(),
12881
+ id: generateId2(),
12617
12882
  type: "text",
12618
12883
  role: "assistant",
12619
12884
  content: {
@@ -12659,21 +12924,21 @@ ${completionResult?.object?.finalResult}` : ""}
12659
12924
  });
12660
12925
  const finishStep = createStep({
12661
12926
  id: "finish-step",
12662
- inputSchema: z7.object({
12663
- task: z7.string(),
12664
- primitiveId: z7.string(),
12927
+ inputSchema: z8.object({
12928
+ task: z8.string(),
12929
+ primitiveId: z8.string(),
12665
12930
  primitiveType: PRIMITIVE_TYPES,
12666
- prompt: z7.string(),
12667
- result: z7.string(),
12668
- isComplete: z7.boolean().optional(),
12669
- selectionReason: z7.string(),
12670
- iteration: z7.number()
12931
+ prompt: z8.string(),
12932
+ result: z8.string(),
12933
+ isComplete: z8.boolean().optional(),
12934
+ selectionReason: z8.string(),
12935
+ iteration: z8.number()
12671
12936
  }),
12672
- outputSchema: z7.object({
12673
- task: z7.string(),
12674
- result: z7.string(),
12675
- isComplete: z7.boolean(),
12676
- iteration: z7.number()
12937
+ outputSchema: z8.object({
12938
+ task: z8.string(),
12939
+ result: z8.string(),
12940
+ isComplete: z8.boolean(),
12941
+ iteration: z8.number()
12677
12942
  }),
12678
12943
  execute: async ({ inputData, writer }) => {
12679
12944
  let endResult = inputData.result;
@@ -12698,29 +12963,29 @@ ${completionResult?.object?.finalResult}` : ""}
12698
12963
  });
12699
12964
  const networkWorkflow = createWorkflow({
12700
12965
  id: "Agent-Network-Outer-Workflow",
12701
- inputSchema: z7.object({
12702
- task: z7.string(),
12703
- primitiveId: z7.string(),
12966
+ inputSchema: z8.object({
12967
+ task: z8.string(),
12968
+ primitiveId: z8.string(),
12704
12969
  primitiveType: PRIMITIVE_TYPES,
12705
- result: z7.string().optional(),
12706
- iteration: z7.number(),
12707
- threadId: z7.string().optional(),
12708
- threadResourceId: z7.string().optional(),
12709
- isOneOff: z7.boolean(),
12710
- verboseIntrospection: z7.boolean()
12970
+ result: z8.string().optional(),
12971
+ iteration: z8.number(),
12972
+ threadId: z8.string().optional(),
12973
+ threadResourceId: z8.string().optional(),
12974
+ isOneOff: z8.boolean(),
12975
+ verboseIntrospection: z8.boolean()
12711
12976
  }),
12712
- outputSchema: z7.object({
12713
- task: z7.string(),
12714
- primitiveId: z7.string(),
12977
+ outputSchema: z8.object({
12978
+ task: z8.string(),
12979
+ primitiveId: z8.string(),
12715
12980
  primitiveType: PRIMITIVE_TYPES,
12716
- prompt: z7.string(),
12717
- result: z7.string(),
12718
- isComplete: z7.boolean().optional(),
12719
- completionReason: z7.string().optional(),
12720
- iteration: z7.number(),
12721
- threadId: z7.string().optional(),
12722
- threadResourceId: z7.string().optional(),
12723
- isOneOff: z7.boolean()
12981
+ prompt: z8.string(),
12982
+ result: z8.string(),
12983
+ isComplete: z8.boolean().optional(),
12984
+ completionReason: z8.string().optional(),
12985
+ iteration: z8.number(),
12986
+ threadId: z8.string().optional(),
12987
+ threadResourceId: z8.string().optional(),
12988
+ isOneOff: z8.boolean()
12724
12989
  }),
12725
12990
  options: {
12726
12991
  shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended",
@@ -12782,7 +13047,7 @@ async function networkLoop({
12782
13047
  runId,
12783
13048
  routingAgent,
12784
13049
  routingAgentOptions,
12785
- generateId: generateId3,
13050
+ generateId: generateId2,
12786
13051
  maxIterations,
12787
13052
  threadId,
12788
13053
  resourceId,
@@ -12807,7 +13072,7 @@ async function networkLoop({
12807
13072
  runId,
12808
13073
  agent: routingAgent,
12809
13074
  routingAgentOptions: routingAgentOptionsWithoutMemory,
12810
- generateId: generateId3
13075
+ generateId: generateId2
12811
13076
  });
12812
13077
  const finalStep = createStep({
12813
13078
  id: "final-step",
@@ -12829,26 +13094,26 @@ async function networkLoop({
12829
13094
  });
12830
13095
  const mainWorkflow = createWorkflow({
12831
13096
  id: "agent-loop-main-workflow",
12832
- inputSchema: z7.object({
12833
- iteration: z7.number(),
12834
- task: z7.string(),
12835
- primitiveId: z7.string(),
13097
+ inputSchema: z8.object({
13098
+ iteration: z8.number(),
13099
+ task: z8.string(),
13100
+ primitiveId: z8.string(),
12836
13101
  primitiveType: PRIMITIVE_TYPES,
12837
- result: z7.string().optional(),
12838
- threadId: z7.string().optional(),
12839
- threadResourceId: z7.string().optional(),
12840
- isOneOff: z7.boolean(),
12841
- verboseIntrospection: z7.boolean()
13102
+ result: z8.string().optional(),
13103
+ threadId: z8.string().optional(),
13104
+ threadResourceId: z8.string().optional(),
13105
+ isOneOff: z8.boolean(),
13106
+ verboseIntrospection: z8.boolean()
12842
13107
  }),
12843
- outputSchema: z7.object({
12844
- task: z7.string(),
12845
- primitiveId: z7.string(),
13108
+ outputSchema: z8.object({
13109
+ task: z8.string(),
13110
+ primitiveId: z8.string(),
12846
13111
  primitiveType: PRIMITIVE_TYPES,
12847
- prompt: z7.string(),
12848
- result: z7.string(),
12849
- isComplete: z7.boolean().optional(),
12850
- completionReason: z7.string().optional(),
12851
- iteration: z7.number()
13112
+ prompt: z8.string(),
13113
+ result: z8.string(),
13114
+ isComplete: z8.boolean().optional(),
13115
+ completionReason: z8.string().optional(),
13116
+ iteration: z8.number()
12852
13117
  }),
12853
13118
  options: {
12854
13119
  shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended",
@@ -12866,7 +13131,7 @@ async function networkLoop({
12866
13131
  resourceId: resourceId || networkName,
12867
13132
  messages,
12868
13133
  routingAgent,
12869
- generateId: generateId3,
13134
+ generateId: generateId2,
12870
13135
  tracingContext: routingAgentOptions?.tracingContext,
12871
13136
  memoryConfig: routingAgentMemoryOptions?.options
12872
13137
  });
@@ -14331,7 +14596,8 @@ function createPrepareToolsStep({
14331
14596
  tracingContext: { currentSpan: agentSpan },
14332
14597
  outputWriter: options.outputWriter,
14333
14598
  methodType,
14334
- memoryConfig: options.memory?.options
14599
+ memoryConfig: options.memory?.options,
14600
+ autoResumeSuspendedTools: options.autoResumeSuspendedTools
14335
14601
  });
14336
14602
  return {
14337
14603
  convertedTools
@@ -14344,6 +14610,7 @@ function createStreamStep({
14344
14610
  runId,
14345
14611
  returnScorerData,
14346
14612
  requireToolApproval,
14613
+ toolCallConcurrency,
14347
14614
  resumeContext,
14348
14615
  agentId,
14349
14616
  agentName,
@@ -14352,7 +14619,8 @@ function createStreamStep({
14352
14619
  saveQueueManager,
14353
14620
  memoryConfig,
14354
14621
  memory,
14355
- resourceId
14622
+ resourceId,
14623
+ autoResumeSuspendedTools
14356
14624
  }) {
14357
14625
  return createStep({
14358
14626
  id: "stream-text-step",
@@ -14377,6 +14645,7 @@ function createStreamStep({
14377
14645
  returnScorerData,
14378
14646
  tracingContext,
14379
14647
  requireToolApproval,
14648
+ toolCallConcurrency,
14380
14649
  resumeContext,
14381
14650
  _internal: {
14382
14651
  generateId: capabilities.generateMessageId,
@@ -14389,7 +14658,8 @@ function createStreamStep({
14389
14658
  agentId,
14390
14659
  agentName,
14391
14660
  toolCallId,
14392
- methodType: modelMethodType
14661
+ methodType: modelMethodType,
14662
+ autoResumeSuspendedTools
14393
14663
  });
14394
14664
  return streamResult;
14395
14665
  }
@@ -14412,6 +14682,7 @@ function createPrepareStreamWorkflow({
14412
14682
  returnScorerData,
14413
14683
  saveQueueManager,
14414
14684
  requireToolApproval,
14685
+ toolCallConcurrency,
14415
14686
  resumeContext,
14416
14687
  agentId,
14417
14688
  agentName,
@@ -14444,6 +14715,7 @@ function createPrepareStreamWorkflow({
14444
14715
  runId,
14445
14716
  returnScorerData,
14446
14717
  requireToolApproval,
14718
+ toolCallConcurrency,
14447
14719
  resumeContext,
14448
14720
  agentId,
14449
14721
  agentName,
@@ -14452,7 +14724,8 @@ function createPrepareStreamWorkflow({
14452
14724
  saveQueueManager,
14453
14725
  memoryConfig,
14454
14726
  memory,
14455
- resourceId
14727
+ resourceId,
14728
+ autoResumeSuspendedTools: options.autoResumeSuspendedTools
14456
14729
  });
14457
14730
  const mapResultsStep = createMapResultsStep({
14458
14731
  capabilities,
@@ -14706,7 +14979,8 @@ var Agent = class extends MastraBase {
14706
14979
  id: workflowId,
14707
14980
  inputSchema: ProcessorStepSchema,
14708
14981
  outputSchema: ProcessorStepSchema,
14709
- type: "processor"
14982
+ type: "processor",
14983
+ options: { validateInputs: false }
14710
14984
  });
14711
14985
  for (const processorOrWorkflow of validProcessors) {
14712
14986
  const step = isProcessorWorkflow(processorOrWorkflow) ? processorOrWorkflow : createStep(processorOrWorkflow);
@@ -15373,11 +15647,11 @@ var Agent = class extends MastraBase {
15373
15647
  __registerMastra(mastra) {
15374
15648
  this.#mastra = mastra;
15375
15649
  if (this.#tools && typeof this.#tools === "object") {
15376
- Object.entries(this.#tools).forEach(([key, tool]) => {
15650
+ Object.entries(this.#tools).forEach(([key, tool2]) => {
15377
15651
  try {
15378
- if (tool && typeof tool === "object" && "id" in tool) {
15379
- const toolKey = typeof tool.id === "string" ? tool.id : key;
15380
- mastra.addTool(tool, toolKey);
15652
+ if (tool2 && typeof tool2 === "object" && "id" in tool2) {
15653
+ const toolKey = typeof tool2.id === "string" ? tool2.id : key;
15654
+ mastra.addTool(tool2, toolKey);
15381
15655
  }
15382
15656
  } catch (error) {
15383
15657
  if (error instanceof MastraError && error.id !== "MASTRA_ADD_TOOL_DUPLICATE_KEY") {
@@ -15533,7 +15807,8 @@ var Agent = class extends MastraBase {
15533
15807
  requestContext,
15534
15808
  tracingContext,
15535
15809
  mastraProxy,
15536
- memoryConfig
15810
+ memoryConfig,
15811
+ autoResumeSuspendedTools
15537
15812
  }) {
15538
15813
  let convertedMemoryTools = {};
15539
15814
  if (this._agentNetworkAppend) {
@@ -15549,8 +15824,8 @@ var Agent = class extends MastraBase {
15549
15824
  runId
15550
15825
  }
15551
15826
  );
15552
- for (const [toolName, tool] of Object.entries(memoryTools)) {
15553
- const toolObj = tool;
15827
+ for (const [toolName, tool2] of Object.entries(memoryTools)) {
15828
+ const toolObj = tool2;
15554
15829
  const options = {
15555
15830
  name: toolName,
15556
15831
  runId,
@@ -15566,7 +15841,7 @@ var Agent = class extends MastraBase {
15566
15841
  tracingPolicy: this.#options?.tracingPolicy,
15567
15842
  requireApproval: toolObj.requireApproval
15568
15843
  };
15569
- const convertedToCoreTool = makeCoreTool(toolObj, options);
15844
+ const convertedToCoreTool = makeCoreTool(toolObj, options, void 0, autoResumeSuspendedTools);
15570
15845
  convertedMemoryTools[toolName] = convertedToCoreTool;
15571
15846
  }
15572
15847
  }
@@ -15692,7 +15967,8 @@ var Agent = class extends MastraBase {
15692
15967
  requestContext,
15693
15968
  tracingContext,
15694
15969
  mastraProxy,
15695
- outputWriter
15970
+ outputWriter,
15971
+ autoResumeSuspendedTools
15696
15972
  }) {
15697
15973
  let toolsForRequest = {};
15698
15974
  this.logger.debug(`[Agents:${this.name}] - Assembling assigned tools`, { runId, threadId, resourceId });
@@ -15700,8 +15976,8 @@ var Agent = class extends MastraBase {
15700
15976
  const assignedTools = await this.listTools({ requestContext });
15701
15977
  const assignedToolEntries = Object.entries(assignedTools || {});
15702
15978
  const assignedCoreToolEntries = await Promise.all(
15703
- assignedToolEntries.map(async ([k, tool]) => {
15704
- if (!tool) {
15979
+ assignedToolEntries.map(async ([k, tool2]) => {
15980
+ if (!tool2) {
15705
15981
  return;
15706
15982
  }
15707
15983
  const options = {
@@ -15718,9 +15994,9 @@ var Agent = class extends MastraBase {
15718
15994
  model: await this.getModel({ requestContext }),
15719
15995
  outputWriter,
15720
15996
  tracingPolicy: this.#options?.tracingPolicy,
15721
- requireApproval: tool.requireApproval
15997
+ requireApproval: tool2.requireApproval
15722
15998
  };
15723
- return [k, makeCoreTool(tool, options)];
15999
+ return [k, makeCoreTool(tool2, options, void 0, autoResumeSuspendedTools)];
15724
16000
  })
15725
16001
  );
15726
16002
  const assignedToolEntriesConverted = Object.fromEntries(
@@ -15742,7 +16018,8 @@ var Agent = class extends MastraBase {
15742
16018
  toolsets,
15743
16019
  requestContext,
15744
16020
  tracingContext,
15745
- mastraProxy
16021
+ mastraProxy,
16022
+ autoResumeSuspendedTools
15746
16023
  }) {
15747
16024
  let toolsForRequest = {};
15748
16025
  const memory = await this.getMemory({ requestContext });
@@ -15752,8 +16029,8 @@ var Agent = class extends MastraBase {
15752
16029
  runId
15753
16030
  });
15754
16031
  for (const toolset of toolsFromToolsets) {
15755
- for (const [toolName, tool] of Object.entries(toolset)) {
15756
- const toolObj = tool;
16032
+ for (const [toolName, tool2] of Object.entries(toolset)) {
16033
+ const toolObj = tool2;
15757
16034
  const options = {
15758
16035
  name: toolName,
15759
16036
  runId,
@@ -15769,7 +16046,7 @@ var Agent = class extends MastraBase {
15769
16046
  tracingPolicy: this.#options?.tracingPolicy,
15770
16047
  requireApproval: toolObj.requireApproval
15771
16048
  };
15772
- const convertedToCoreTool = makeCoreTool(toolObj, options, "toolset");
16049
+ const convertedToCoreTool = makeCoreTool(toolObj, options, "toolset", autoResumeSuspendedTools);
15773
16050
  toolsForRequest[toolName] = convertedToCoreTool;
15774
16051
  }
15775
16052
  }
@@ -15787,7 +16064,8 @@ var Agent = class extends MastraBase {
15787
16064
  requestContext,
15788
16065
  tracingContext,
15789
16066
  mastraProxy,
15790
- clientTools
16067
+ clientTools,
16068
+ autoResumeSuspendedTools
15791
16069
  }) {
15792
16070
  let toolsForRequest = {};
15793
16071
  const memory = await this.getMemory({ requestContext });
@@ -15796,8 +16074,8 @@ var Agent = class extends MastraBase {
15796
16074
  this.logger.debug(`[Agent:${this.name}] - Adding client tools ${Object.keys(clientTools || {}).join(", ")}`, {
15797
16075
  runId
15798
16076
  });
15799
- for (const [toolName, tool] of clientToolsForInput) {
15800
- const { execute: execute2, ...rest } = tool;
16077
+ for (const [toolName, tool2] of clientToolsForInput) {
16078
+ const { execute: execute2, ...rest } = tool2;
15801
16079
  const options = {
15802
16080
  name: toolName,
15803
16081
  runId,
@@ -15811,9 +16089,9 @@ var Agent = class extends MastraBase {
15811
16089
  tracingContext,
15812
16090
  model: await this.getModel({ requestContext }),
15813
16091
  tracingPolicy: this.#options?.tracingPolicy,
15814
- requireApproval: tool.requireApproval
16092
+ requireApproval: tool2.requireApproval
15815
16093
  };
15816
- const convertedToCoreTool = makeCoreTool(rest, options, "client-tool");
16094
+ const convertedToCoreTool = makeCoreTool(rest, options, "client-tool", autoResumeSuspendedTools);
15817
16095
  toolsForRequest[toolName] = convertedToCoreTool;
15818
16096
  }
15819
16097
  }
@@ -15829,7 +16107,8 @@ var Agent = class extends MastraBase {
15829
16107
  resourceId,
15830
16108
  requestContext,
15831
16109
  tracingContext,
15832
- methodType
16110
+ methodType,
16111
+ autoResumeSuspendedTools
15833
16112
  }) {
15834
16113
  const convertedAgentTools = {};
15835
16114
  const agents = await this.listAgents({ requestContext });
@@ -15982,7 +16261,12 @@ var Agent = class extends MastraBase {
15982
16261
  tracingContext,
15983
16262
  tracingPolicy: this.#options?.tracingPolicy
15984
16263
  };
15985
- convertedAgentTools[`agent-${agentName}`] = makeCoreTool(toolObj, options);
16264
+ convertedAgentTools[`agent-${agentName}`] = makeCoreTool(
16265
+ toolObj,
16266
+ options,
16267
+ void 0,
16268
+ autoResumeSuspendedTools
16269
+ );
15986
16270
  }
15987
16271
  }
15988
16272
  return convertedAgentTools;
@@ -15997,7 +16281,8 @@ var Agent = class extends MastraBase {
15997
16281
  resourceId,
15998
16282
  requestContext,
15999
16283
  tracingContext,
16000
- methodType
16284
+ methodType,
16285
+ autoResumeSuspendedTools
16001
16286
  }) {
16002
16287
  const convertedWorkflowTools = {};
16003
16288
  const workflows = await this.listWorkflows({ requestContext });
@@ -16026,16 +16311,17 @@ var Agent = class extends MastraBase {
16026
16311
  // current tool span onto the workflow to maintain continuity of the trace
16027
16312
  execute: async (inputData, context) => {
16028
16313
  try {
16314
+ const { initialState, inputData: workflowInputData, suspendedToolRunId } = inputData;
16315
+ const runIdToUse = suspendedToolRunId ?? runId;
16029
16316
  this.logger.debug(`[Agent:${this.name}] - Executing workflow as tool ${workflowName}`, {
16030
16317
  name: workflowName,
16031
16318
  description: workflow.description,
16032
16319
  args: inputData,
16033
- runId,
16320
+ runId: runIdToUse,
16034
16321
  threadId,
16035
16322
  resourceId
16036
16323
  });
16037
- const run = await workflow.createRun({ runId });
16038
- const { initialState, inputData: workflowInputData } = inputData;
16324
+ const run = await workflow.createRun({ runId: runIdToUse });
16039
16325
  const { resumeData, suspend } = context?.agent ?? {};
16040
16326
  let result = void 0;
16041
16327
  if (methodType === "generate" || methodType === "generateLegacy") {
@@ -16094,10 +16380,24 @@ var Agent = class extends MastraBase {
16094
16380
  } else if (result?.status === "suspended") {
16095
16381
  const suspendedStep = result?.suspended?.[0]?.[0];
16096
16382
  const suspendPayload = result?.steps?.[suspendedStep]?.suspendPayload;
16383
+ const suspendedStepIds = result?.suspended?.map((stepPath) => stepPath.join("."));
16384
+ const firstSuspendedStepPath = [...result?.suspended?.[0] ?? []];
16385
+ let wflowStep = workflow;
16386
+ while (firstSuspendedStepPath.length > 0) {
16387
+ const key = firstSuspendedStepPath.shift();
16388
+ if (key) {
16389
+ if (!workflow.steps[key]) {
16390
+ this.logger.warn(`Suspended step '${key}' not found in workflow '${workflowName}'`);
16391
+ break;
16392
+ }
16393
+ wflowStep = workflow.steps[key];
16394
+ }
16395
+ }
16396
+ const resumeSchema = wflowStep?.resumeSchema;
16097
16397
  if (suspendPayload?.__workflow_meta) {
16098
16398
  delete suspendPayload.__workflow_meta;
16099
16399
  }
16100
- return suspend?.(suspendPayload);
16400
+ return suspend?.(suspendPayload, { resumeLabel: suspendedStepIds, resumeSchema });
16101
16401
  } else {
16102
16402
  return {
16103
16403
  error: `Workflow should never reach this path, workflow returned no status`,
@@ -16112,7 +16412,7 @@ var Agent = class extends MastraBase {
16112
16412
  category: "USER" /* USER */,
16113
16413
  details: {
16114
16414
  agentName: this.name,
16115
- runId: runId || "",
16415
+ runId: inputData.suspendedToolRunId || runId || "",
16116
16416
  threadId: threadId || "",
16117
16417
  resourceId: resourceId || ""
16118
16418
  },
@@ -16140,7 +16440,12 @@ var Agent = class extends MastraBase {
16140
16440
  tracingContext,
16141
16441
  tracingPolicy: this.#options?.tracingPolicy
16142
16442
  };
16143
- convertedWorkflowTools[`workflow-${workflowName}`] = makeCoreTool(toolObj, options);
16443
+ convertedWorkflowTools[`workflow-${workflowName}`] = makeCoreTool(
16444
+ toolObj,
16445
+ options,
16446
+ void 0,
16447
+ autoResumeSuspendedTools
16448
+ );
16144
16449
  }
16145
16450
  }
16146
16451
  return convertedWorkflowTools;
@@ -16159,7 +16464,8 @@ var Agent = class extends MastraBase {
16159
16464
  tracingContext,
16160
16465
  outputWriter,
16161
16466
  methodType,
16162
- memoryConfig
16467
+ memoryConfig,
16468
+ autoResumeSuspendedTools
16163
16469
  }) {
16164
16470
  let mastraProxy = void 0;
16165
16471
  const logger = this.logger;
@@ -16173,7 +16479,8 @@ var Agent = class extends MastraBase {
16173
16479
  requestContext,
16174
16480
  tracingContext,
16175
16481
  mastraProxy,
16176
- outputWriter
16482
+ outputWriter,
16483
+ autoResumeSuspendedTools
16177
16484
  });
16178
16485
  const memoryTools = await this.listMemoryTools({
16179
16486
  runId,
@@ -16182,7 +16489,8 @@ var Agent = class extends MastraBase {
16182
16489
  requestContext,
16183
16490
  tracingContext,
16184
16491
  mastraProxy,
16185
- memoryConfig
16492
+ memoryConfig,
16493
+ autoResumeSuspendedTools
16186
16494
  });
16187
16495
  const toolsetTools = await this.listToolsets({
16188
16496
  runId,
@@ -16191,7 +16499,8 @@ var Agent = class extends MastraBase {
16191
16499
  requestContext,
16192
16500
  tracingContext,
16193
16501
  mastraProxy,
16194
- toolsets
16502
+ toolsets,
16503
+ autoResumeSuspendedTools
16195
16504
  });
16196
16505
  const clientSideTools = await this.listClientTools({
16197
16506
  runId,
@@ -16200,7 +16509,8 @@ var Agent = class extends MastraBase {
16200
16509
  requestContext,
16201
16510
  tracingContext,
16202
16511
  mastraProxy,
16203
- clientTools
16512
+ clientTools,
16513
+ autoResumeSuspendedTools
16204
16514
  });
16205
16515
  const agentTools = await this.listAgentTools({
16206
16516
  runId,
@@ -16208,7 +16518,8 @@ var Agent = class extends MastraBase {
16208
16518
  threadId,
16209
16519
  requestContext,
16210
16520
  methodType,
16211
- tracingContext
16521
+ tracingContext,
16522
+ autoResumeSuspendedTools
16212
16523
  });
16213
16524
  const workflowTools = await this.listWorkflowTools({
16214
16525
  runId,
@@ -16216,7 +16527,8 @@ var Agent = class extends MastraBase {
16216
16527
  threadId,
16217
16528
  requestContext,
16218
16529
  methodType,
16219
- tracingContext
16530
+ tracingContext,
16531
+ autoResumeSuspendedTools
16220
16532
  });
16221
16533
  return this.formatTools({
16222
16534
  ...assignedTools,
@@ -16567,6 +16879,7 @@ var Agent = class extends MastraBase {
16567
16879
  saveQueueManager,
16568
16880
  returnScorerData: options.returnScorerData,
16569
16881
  requireToolApproval: options.requireToolApproval,
16882
+ toolCallConcurrency: options.toolCallConcurrency,
16570
16883
  resumeContext,
16571
16884
  agentId: this.id,
16572
16885
  agentName: this.name,
@@ -16764,6 +17077,10 @@ var Agent = class extends MastraBase {
16764
17077
  async network(messages, options) {
16765
17078
  const runId = options?.runId || this.#mastra?.generateId() || randomUUID();
16766
17079
  const requestContextToUse = options?.requestContext || new RequestContext();
17080
+ const resourceIdFromContext = requestContextToUse.get(MASTRA_RESOURCE_ID_KEY);
17081
+ const threadIdFromContext = requestContextToUse.get(MASTRA_THREAD_ID_KEY);
17082
+ const threadId = threadIdFromContext || (typeof options?.memory?.thread === "string" ? options?.memory?.thread : options?.memory?.thread?.id);
17083
+ const resourceId = resourceIdFromContext || options?.memory?.resource;
16767
17084
  return await networkLoop({
16768
17085
  networkName: this.name,
16769
17086
  requestContext: requestContextToUse,
@@ -16776,8 +17093,8 @@ var Agent = class extends MastraBase {
16776
17093
  generateId: () => this.#mastra?.generateId() || randomUUID(),
16777
17094
  maxIterations: options?.maxSteps || 1,
16778
17095
  messages,
16779
- threadId: typeof options?.memory?.thread === "string" ? options?.memory?.thread : options?.memory?.thread?.id,
16780
- resourceId: options?.memory?.resource
17096
+ threadId,
17097
+ resourceId
16781
17098
  });
16782
17099
  }
16783
17100
  async generate(messages, options) {
@@ -17153,14 +17470,14 @@ var ModerationProcessor = class _ModerationProcessor {
17153
17470
  const prompt = this.createModerationPrompt(content, isStream);
17154
17471
  try {
17155
17472
  const model = await this.moderationAgent.getModel();
17156
- const schema = z7.object({
17157
- category_scores: z7.array(
17158
- z7.object({
17159
- category: z7.enum(this.categories).describe("The moderation category being evaluated"),
17160
- score: z7.number().min(0).max(1).describe("Confidence score between 0 and 1 indicating how strongly the content matches this category")
17473
+ const schema = z8.object({
17474
+ category_scores: z8.array(
17475
+ z8.object({
17476
+ category: z8.enum(this.categories).describe("The moderation category being evaluated"),
17477
+ score: z8.number().min(0).max(1).describe("Confidence score between 0 and 1 indicating how strongly the content matches this category")
17161
17478
  })
17162
17479
  ).describe("Array of flagged categories with their confidence scores").nullable(),
17163
- reason: z7.string().describe("Brief explanation of why content was flagged").nullable()
17480
+ reason: z8.string().describe("Brief explanation of why content was flagged").nullable()
17164
17481
  });
17165
17482
  let response;
17166
17483
  if (model.specificationVersion === "v2") {
@@ -17368,19 +17685,19 @@ var PromptInjectionDetector = class _PromptInjectionDetector {
17368
17685
  try {
17369
17686
  const model = await this.detectionAgent.getModel();
17370
17687
  let response;
17371
- const baseSchema = z7.object({
17372
- categories: z7.array(
17373
- z7.object({
17374
- type: z7.enum(this.detectionTypes).describe("The type of attack detected from the list of detection types"),
17375
- score: z7.number().min(0).max(1).describe("Confidence level between 0 and 1 indicating how certain the detection is")
17688
+ const baseSchema = z8.object({
17689
+ categories: z8.array(
17690
+ z8.object({
17691
+ type: z8.enum(this.detectionTypes).describe("The type of attack detected from the list of detection types"),
17692
+ score: z8.number().min(0).max(1).describe("Confidence level between 0 and 1 indicating how certain the detection is")
17376
17693
  })
17377
17694
  ).nullable(),
17378
- reason: z7.string().describe("The reason for the detection").nullable()
17695
+ reason: z8.string().describe("The reason for the detection").nullable()
17379
17696
  });
17380
17697
  let schema = baseSchema;
17381
17698
  if (this.strategy === "rewrite") {
17382
17699
  schema = baseSchema.extend({
17383
- rewritten_content: z7.string().describe("The rewritten content that neutralizes the attack while preserving any legitimate user intent").nullable()
17700
+ rewritten_content: z8.string().describe("The rewritten content that neutralizes the attack while preserving any legitimate user intent").nullable()
17384
17701
  });
17385
17702
  }
17386
17703
  if (model.specificationVersion === "v2") {
@@ -17608,27 +17925,27 @@ var PIIDetector = class _PIIDetector {
17608
17925
  const prompt = this.createDetectionPrompt(content);
17609
17926
  try {
17610
17927
  const model = await this.detectionAgent.getModel();
17611
- const baseDetectionSchema = z7.object({
17612
- type: z7.string().describe("Type of PII detected"),
17613
- value: z7.string().describe("The actual PII value found"),
17614
- confidence: z7.number().min(0).max(1).describe("Confidence of this detection"),
17615
- start: z7.number().describe("Start position in the text"),
17616
- end: z7.number().describe("End position in the text")
17928
+ const baseDetectionSchema = z8.object({
17929
+ type: z8.string().describe("Type of PII detected"),
17930
+ value: z8.string().describe("The actual PII value found"),
17931
+ confidence: z8.number().min(0).max(1).describe("Confidence of this detection"),
17932
+ start: z8.number().describe("Start position in the text"),
17933
+ end: z8.number().describe("End position in the text")
17617
17934
  });
17618
17935
  const detectionSchema = this.strategy === "redact" ? baseDetectionSchema.extend({
17619
- redacted_value: z7.string().describe("Redacted version of the value").nullable()
17936
+ redacted_value: z8.string().describe("Redacted version of the value").nullable()
17620
17937
  }) : baseDetectionSchema;
17621
- const baseSchema = z7.object({
17622
- categories: z7.array(
17623
- z7.object({
17624
- type: z7.enum(this.detectionTypes).describe("The type of PII detected from the list of detection types"),
17625
- score: z7.number().min(0).max(1).describe("Confidence level between 0 and 1 indicating how certain the detection is")
17938
+ const baseSchema = z8.object({
17939
+ categories: z8.array(
17940
+ z8.object({
17941
+ type: z8.enum(this.detectionTypes).describe("The type of PII detected from the list of detection types"),
17942
+ score: z8.number().min(0).max(1).describe("Confidence level between 0 and 1 indicating how certain the detection is")
17626
17943
  })
17627
17944
  ).describe("Array of detected PII types with their confidence scores").nullable(),
17628
- detections: z7.array(detectionSchema).describe("Array of specific PII detections with locations").nullable()
17945
+ detections: z8.array(detectionSchema).describe("Array of specific PII detections with locations").nullable()
17629
17946
  });
17630
17947
  const schema = this.strategy === "redact" ? baseSchema.extend({
17631
- redacted_content: z7.string().describe("The content with all PII redacted according to the redaction method").nullable()
17948
+ redacted_content: z8.string().describe("The content with all PII redacted according to the redaction method").nullable()
17632
17949
  }) : baseSchema;
17633
17950
  let response;
17634
17951
  if (model.specificationVersion === "v2") {
@@ -18086,12 +18403,12 @@ var LanguageDetector = class _LanguageDetector {
18086
18403
  try {
18087
18404
  const model = await this.detectionAgent.getModel();
18088
18405
  let response;
18089
- const baseSchema = z7.object({
18090
- iso_code: z7.string().describe("ISO language code").nullable(),
18091
- confidence: z7.number().min(0).max(1).describe("Detection confidence").nullable()
18406
+ const baseSchema = z8.object({
18407
+ iso_code: z8.string().describe("ISO language code").nullable(),
18408
+ confidence: z8.number().min(0).max(1).describe("Detection confidence").nullable()
18092
18409
  });
18093
18410
  const schema = this.strategy === "translate" ? baseSchema.extend({
18094
- translated_text: z7.string().describe("Translated text").nullable()
18411
+ translated_text: z8.string().describe("Translated text").nullable()
18095
18412
  }) : baseSchema;
18096
18413
  if (model.specificationVersion === "v2") {
18097
18414
  response = await this.detectionAgent.generate(prompt, {
@@ -20141,7 +20458,7 @@ var MockMemory = class extends MastraMemory {
20141
20458
  updateWorkingMemory: createTool({
20142
20459
  id: "update-working-memory",
20143
20460
  description: `Update the working memory with new information. Any data not included will be overwritten.`,
20144
- inputSchema: z7.object({ memory: z7.string() }),
20461
+ inputSchema: z8.object({ memory: z8.string() }),
20145
20462
  execute: async (inputData, context) => {
20146
20463
  const threadId = context?.agent?.threadId;
20147
20464
  const resourceId = context?.agent?.resourceId;
@@ -20250,6 +20567,6 @@ var MockMemory = class extends MastraMemory {
20250
20567
  }
20251
20568
  };
20252
20569
 
20253
- export { AISDKV5OutputStream, Agent, BatchPartsProcessor, ChunkFrom, DefaultExecutionEngine, ExecutionEngine, FilePartSchema, ImagePartSchema, LanguageDetector, MastraAgentNetworkStream, MastraMemory, MastraModelOutput, MemoryProcessor, MessageContentSchema, MessageHistory, MessagePartSchema, MockMemory, ModerationProcessor, PIIDetector, ProcessorInputPhaseSchema, ProcessorInputStepPhaseSchema, ProcessorMessageContentSchema, ProcessorMessageSchema, ProcessorOutputResultPhaseSchema, ProcessorOutputStepPhaseSchema, ProcessorOutputStreamPhaseSchema, ProcessorRunner, ProcessorState, ProcessorStepInputSchema, ProcessorStepOutputSchema, ProcessorStepSchema, PromptInjectionDetector, ReasoningPartSchema, Run, SemanticRecall, SourcePartSchema, StepStartPartSchema, StructuredOutputProcessor, SystemPromptScrubber, TextPartSchema, TokenLimiterProcessor, ToolCallFilter, ToolInvocationPartSchema, TripWire, UnicodeNormalizer, Workflow, WorkflowRunOutput, WorkingMemory, augmentWithInit, cloneStep, cloneWorkflow, convertFullStreamChunkToMastra, convertFullStreamChunkToUIMessageStream, convertMastraChunkToAISDKv5, createDeprecationProxy, createStep, createTimeTravelExecutionParams, createWorkflow, getResumeLabelsByStepId, getStepIds, getStepResult, getZodErrors, isProcessor, isProcessorWorkflow, loop, mapVariable, memoryDefaultOptions, parseMemoryRequestContext, resolveThreadIdFromArgs, runCountDeprecationMessage, tryGenerateWithJsonFallback, tryStreamWithJsonFallback, validateStepInput, validateStepResumeData, validateStepStateData, validateStepSuspendData };
20254
- //# sourceMappingURL=chunk-2ULLRN4Y.js.map
20255
- //# sourceMappingURL=chunk-2ULLRN4Y.js.map
20570
+ export { AISDKV5OutputStream, Agent, BatchPartsProcessor, ChunkFrom, DefaultExecutionEngine, EventEmitterPubSub, ExecutionEngine, FilePartSchema, ImagePartSchema, LanguageDetector, MastraAgentNetworkStream, MastraMemory, MastraModelOutput, MemoryProcessor, MessageContentSchema, MessageHistory, MessagePartSchema, MockMemory, ModerationProcessor, PIIDetector, ProcessorInputPhaseSchema, ProcessorInputStepPhaseSchema, ProcessorMessageContentSchema, ProcessorMessageSchema, ProcessorOutputResultPhaseSchema, ProcessorOutputStepPhaseSchema, ProcessorOutputStreamPhaseSchema, ProcessorRunner, ProcessorState, ProcessorStepInputSchema, ProcessorStepOutputSchema, ProcessorStepSchema, PromptInjectionDetector, ReasoningPartSchema, Run, SemanticRecall, SourcePartSchema, StepStartPartSchema, StructuredOutputProcessor, SystemPromptScrubber, TextPartSchema, TokenLimiterProcessor, ToolCallFilter, ToolInvocationPartSchema, TripWire, UnicodeNormalizer, Workflow, WorkflowRunOutput, WorkingMemory, augmentWithInit, cloneStep, cloneWorkflow, convertFullStreamChunkToMastra, convertFullStreamChunkToUIMessageStream, convertMastraChunkToAISDKv5, createDeprecationProxy, createStep, createTimeTravelExecutionParams, createWorkflow, getResumeLabelsByStepId, getStepIds, getStepResult, getZodErrors, hydrateSerializedStepErrors, isProcessor, isProcessorWorkflow, loop, mapVariable, memoryDefaultOptions, parseMemoryRequestContext, resolveThreadIdFromArgs, runCountDeprecationMessage, tryGenerateWithJsonFallback, tryStreamWithJsonFallback, validateStepInput, validateStepResumeData, validateStepStateData, validateStepSuspendData };
20571
+ //# sourceMappingURL=chunk-E5BQRAJK.js.map
20572
+ //# sourceMappingURL=chunk-E5BQRAJK.js.map