@mastra/core 1.0.0-beta.4 → 1.0.0-beta.5

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 (283) hide show
  1. package/CHANGELOG.md +325 -0
  2. package/dist/agent/agent.d.ts +2 -2
  3. package/dist/agent/agent.d.ts.map +1 -1
  4. package/dist/agent/agent.types.d.ts +2 -0
  5. package/dist/agent/agent.types.d.ts.map +1 -1
  6. package/dist/agent/index.cjs +9 -9
  7. package/dist/agent/index.js +2 -2
  8. package/dist/agent/message-list/index.cjs +3 -3
  9. package/dist/agent/message-list/index.d.ts.map +1 -1
  10. package/dist/agent/message-list/index.js +1 -1
  11. package/dist/agent/message-list/prompt/attachments-to-parts.d.ts.map +1 -1
  12. package/dist/agent/types.d.ts +2 -3
  13. package/dist/agent/types.d.ts.map +1 -1
  14. package/dist/agent/utils.d.ts.map +1 -1
  15. package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
  16. package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
  17. package/dist/agent/workflows/prepare-stream/stream-step.d.ts +8 -1
  18. package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
  19. package/dist/{chunk-3RW5EMSB.js → chunk-3B2OPLGG.js} +13 -6
  20. package/dist/chunk-3B2OPLGG.js.map +1 -0
  21. package/dist/{chunk-RXDJL5QT.js → chunk-3ZQ7LX73.js} +13 -13
  22. package/dist/chunk-3ZQ7LX73.js.map +1 -0
  23. package/dist/{chunk-5WXEYDFI.cjs → chunk-556MJ7CL.cjs} +33 -26
  24. package/dist/chunk-556MJ7CL.cjs.map +1 -0
  25. package/dist/{chunk-HGNRQ3OG.js → chunk-5O52O25J.js} +15 -8
  26. package/dist/chunk-5O52O25J.js.map +1 -0
  27. package/dist/{chunk-WTYNK7Q4.js → chunk-5SA2EZ33.js} +421 -29
  28. package/dist/chunk-5SA2EZ33.js.map +1 -0
  29. package/dist/chunk-6XCINXZ7.cjs +194 -0
  30. package/dist/chunk-6XCINXZ7.cjs.map +1 -0
  31. package/dist/{chunk-MDKPL2R2.js → chunk-7ZADRRDW.js} +5 -4
  32. package/dist/chunk-7ZADRRDW.js.map +1 -0
  33. package/dist/{chunk-JXESKY4A.js → chunk-B5J5HYDN.js} +7 -5
  34. package/dist/chunk-B5J5HYDN.js.map +1 -0
  35. package/dist/chunk-BWYU7D33.js +192 -0
  36. package/dist/chunk-BWYU7D33.js.map +1 -0
  37. package/dist/{chunk-FVNT7VTO.js → chunk-D7CJ4HIQ.js} +240 -17
  38. package/dist/chunk-D7CJ4HIQ.js.map +1 -0
  39. package/dist/{chunk-VSM3NLUX.cjs → chunk-DQIZ5FFX.cjs} +163 -129
  40. package/dist/chunk-DQIZ5FFX.cjs.map +1 -0
  41. package/dist/{chunk-ZCVTH3CH.cjs → chunk-HNHZGFZY.cjs} +5 -4
  42. package/dist/chunk-HNHZGFZY.cjs.map +1 -0
  43. package/dist/{chunk-VZC4BWWH.cjs → chunk-IITXXVYI.cjs} +17 -17
  44. package/dist/chunk-IITXXVYI.cjs.map +1 -0
  45. package/dist/{chunk-2OTDXX73.js → chunk-KJIQGPQR.js} +4 -4
  46. package/dist/{chunk-2OTDXX73.js.map → chunk-KJIQGPQR.js.map} +1 -1
  47. package/dist/{chunk-2NVBZKZI.cjs → chunk-KP42JLXE.cjs} +370 -132
  48. package/dist/chunk-KP42JLXE.cjs.map +1 -0
  49. package/dist/{chunk-IWB65P37.cjs → chunk-KWWD3U7G.cjs} +5 -5
  50. package/dist/chunk-KWWD3U7G.cjs.map +1 -0
  51. package/dist/{chunk-3W5RQCCY.cjs → chunk-NHP6ZIDG.cjs} +248 -24
  52. package/dist/chunk-NHP6ZIDG.cjs.map +1 -0
  53. package/dist/{chunk-O6NA3Z43.cjs → chunk-OUUPUAGA.cjs} +10 -8
  54. package/dist/chunk-OUUPUAGA.cjs.map +1 -0
  55. package/dist/{chunk-D6EDHNGV.js → chunk-PC6EKOWK.js} +64 -11
  56. package/dist/chunk-PC6EKOWK.js.map +1 -0
  57. package/dist/{chunk-S6OEQHEI.cjs → chunk-QGWNF2QJ.cjs} +59 -50
  58. package/dist/chunk-QGWNF2QJ.cjs.map +1 -0
  59. package/dist/{chunk-HBJPYQRN.cjs → chunk-RROQ46B6.cjs} +69 -16
  60. package/dist/chunk-RROQ46B6.cjs.map +1 -0
  61. package/dist/{chunk-U7VECK2G.js → chunk-T2CJRA6E.js} +4 -4
  62. package/dist/chunk-T2CJRA6E.js.map +1 -0
  63. package/dist/{chunk-IHJDOC3A.js → chunk-T2UNO766.js} +16 -7
  64. package/dist/chunk-T2UNO766.js.map +1 -0
  65. package/dist/{chunk-CYVNOIXS.cjs → chunk-U3VE2EVB.cjs} +11 -11
  66. package/dist/{chunk-CYVNOIXS.cjs.map → chunk-U3VE2EVB.cjs.map} +1 -1
  67. package/dist/{chunk-4IKJAKCD.cjs → chunk-V537VSV4.cjs} +74 -16
  68. package/dist/chunk-V537VSV4.cjs.map +1 -0
  69. package/dist/{chunk-4RXG622P.cjs → chunk-VYJXTHII.cjs} +422 -30
  70. package/dist/chunk-VYJXTHII.cjs.map +1 -0
  71. package/dist/{chunk-LRSB62Z6.cjs → chunk-X7F4CSGR.cjs} +15 -8
  72. package/dist/chunk-X7F4CSGR.cjs.map +1 -0
  73. package/dist/{chunk-XXBWX7DT.js → chunk-XBO6W7LZ.js} +328 -91
  74. package/dist/chunk-XBO6W7LZ.js.map +1 -0
  75. package/dist/{chunk-KEURQGCQ.js → chunk-XIDKHXNR.js} +74 -17
  76. package/dist/chunk-XIDKHXNR.js.map +1 -0
  77. package/dist/{chunk-WQSGX6XA.cjs → chunk-XJQX54QP.cjs} +5 -5
  78. package/dist/{chunk-WQSGX6XA.cjs.map → chunk-XJQX54QP.cjs.map} +1 -1
  79. package/dist/{chunk-W3DD3XP5.js → chunk-YDFX3JR2.js} +163 -129
  80. package/dist/chunk-YDFX3JR2.js.map +1 -0
  81. package/dist/{chunk-IWQDBVJK.js → chunk-ZTTMSCLU.js} +3 -3
  82. package/dist/{chunk-IWQDBVJK.js.map → chunk-ZTTMSCLU.js.map} +1 -1
  83. package/dist/evals/base.d.ts +1 -1
  84. package/dist/evals/base.d.ts.map +1 -1
  85. package/dist/evals/base.test-utils.d.ts +25 -25
  86. package/dist/evals/index.cjs +4 -4
  87. package/dist/evals/index.js +1 -1
  88. package/dist/evals/scoreTraces/index.cjs +3 -3
  89. package/dist/evals/scoreTraces/index.js +1 -1
  90. package/dist/index.cjs +2 -2
  91. package/dist/index.js +1 -1
  92. package/dist/integration/index.cjs +2 -2
  93. package/dist/integration/index.js +1 -1
  94. package/dist/llm/index.cjs +18 -14
  95. package/dist/llm/index.d.ts +2 -1
  96. package/dist/llm/index.d.ts.map +1 -1
  97. package/dist/llm/index.js +5 -5
  98. package/dist/llm/model/gateway-resolver.d.ts.map +1 -1
  99. package/dist/llm/model/gateways/azure.d.ts +36 -0
  100. package/dist/llm/model/gateways/azure.d.ts.map +1 -0
  101. package/dist/llm/model/gateways/base.d.ts +3 -6
  102. package/dist/llm/model/gateways/base.d.ts.map +1 -1
  103. package/dist/llm/model/gateways/index.d.ts +4 -1
  104. package/dist/llm/model/gateways/index.d.ts.map +1 -1
  105. package/dist/llm/model/gateways/models-dev.d.ts +2 -2
  106. package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
  107. package/dist/llm/model/gateways/netlify.d.ts +2 -2
  108. package/dist/llm/model/gateways/netlify.d.ts.map +1 -1
  109. package/dist/llm/model/model.d.ts.map +1 -1
  110. package/dist/llm/model/model.loop.d.ts +1 -1
  111. package/dist/llm/model/model.loop.d.ts.map +1 -1
  112. package/dist/llm/model/provider-registry.d.ts.map +1 -1
  113. package/dist/llm/model/provider-types.generated.d.ts +192 -11
  114. package/dist/llm/model/registry-generator.d.ts +12 -0
  115. package/dist/llm/model/registry-generator.d.ts.map +1 -1
  116. package/dist/llm/model/router.d.ts.map +1 -1
  117. package/dist/loop/index.cjs +2 -2
  118. package/dist/loop/index.js +1 -1
  119. package/dist/loop/loop.d.ts.map +1 -1
  120. package/dist/loop/network/index.d.ts.map +1 -1
  121. package/dist/loop/test-utils/generateText.d.ts.map +1 -1
  122. package/dist/loop/test-utils/resultObject.d.ts.map +1 -1
  123. package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
  124. package/dist/loop/types.d.ts +8 -0
  125. package/dist/loop/types.d.ts.map +1 -1
  126. package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
  127. package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts +1 -1
  128. package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
  129. package/dist/mastra/index.cjs +2 -2
  130. package/dist/mastra/index.d.ts +9 -9
  131. package/dist/mastra/index.d.ts.map +1 -1
  132. package/dist/mastra/index.js +1 -1
  133. package/dist/mcp/index.cjs.map +1 -1
  134. package/dist/mcp/index.d.ts +4 -4
  135. package/dist/mcp/index.d.ts.map +1 -1
  136. package/dist/mcp/index.js.map +1 -1
  137. package/dist/mcp/types.d.ts +2 -2
  138. package/dist/mcp/types.d.ts.map +1 -1
  139. package/dist/memory/index.cjs +89 -34
  140. package/dist/memory/index.cjs.map +1 -1
  141. package/dist/memory/index.js +85 -30
  142. package/dist/memory/index.js.map +1 -1
  143. package/dist/memory/mock.d.ts +9 -13
  144. package/dist/memory/mock.d.ts.map +1 -1
  145. package/dist/models-dev-F6MTIYTO.js +3 -0
  146. package/dist/{models-dev-6PRLJKVZ.js.map → models-dev-F6MTIYTO.js.map} +1 -1
  147. package/dist/models-dev-XIVR5EJV.cjs +12 -0
  148. package/dist/{models-dev-WHMI5G6Y.cjs.map → models-dev-XIVR5EJV.cjs.map} +1 -1
  149. package/dist/netlify-MXBOGAJR.cjs +12 -0
  150. package/dist/{netlify-46I3SNNV.cjs.map → netlify-MXBOGAJR.cjs.map} +1 -1
  151. package/dist/netlify-RX3JXCFQ.js +3 -0
  152. package/dist/{netlify-EBQ6YUC6.js.map → netlify-RX3JXCFQ.js.map} +1 -1
  153. package/dist/processors/index.cjs +11 -11
  154. package/dist/processors/index.d.ts +2 -2
  155. package/dist/processors/index.d.ts.map +1 -1
  156. package/dist/processors/index.js +1 -1
  157. package/dist/processors/processors/batch-parts.d.ts +1 -1
  158. package/dist/processors/processors/batch-parts.d.ts.map +1 -1
  159. package/dist/processors/processors/language-detector.d.ts +1 -1
  160. package/dist/processors/processors/language-detector.d.ts.map +1 -1
  161. package/dist/processors/processors/moderation.d.ts +1 -1
  162. package/dist/processors/processors/moderation.d.ts.map +1 -1
  163. package/dist/processors/processors/pii-detector.d.ts +1 -1
  164. package/dist/processors/processors/pii-detector.d.ts.map +1 -1
  165. package/dist/processors/processors/prompt-injection-detector.d.ts +1 -1
  166. package/dist/processors/processors/prompt-injection-detector.d.ts.map +1 -1
  167. package/dist/processors/processors/structured-output.d.ts +1 -1
  168. package/dist/processors/processors/structured-output.d.ts.map +1 -1
  169. package/dist/processors/processors/system-prompt-scrubber.d.ts +1 -1
  170. package/dist/processors/processors/system-prompt-scrubber.d.ts.map +1 -1
  171. package/dist/processors/processors/token-limiter.d.ts +1 -1
  172. package/dist/processors/processors/token-limiter.d.ts.map +1 -1
  173. package/dist/processors/processors/unicode-normalizer.d.ts +1 -1
  174. package/dist/processors/processors/unicode-normalizer.d.ts.map +1 -1
  175. package/dist/provider-registry-3LUCE7FT.js +3 -0
  176. package/dist/{provider-registry-HDG6UMUC.js.map → provider-registry-3LUCE7FT.js.map} +1 -1
  177. package/dist/provider-registry-NBRXBOQT.cjs +40 -0
  178. package/dist/{provider-registry-RP2W4B24.cjs.map → provider-registry-NBRXBOQT.cjs.map} +1 -1
  179. package/dist/provider-registry.json +400 -22
  180. package/dist/{registry-generator-JPCV47SC.cjs → registry-generator-DEPPRYYJ.cjs} +21 -6
  181. package/dist/registry-generator-DEPPRYYJ.cjs.map +1 -0
  182. package/dist/{registry-generator-XD4FPZTU.js → registry-generator-FLW6NV42.js} +21 -7
  183. package/dist/registry-generator-FLW6NV42.js.map +1 -0
  184. package/dist/relevance/index.cjs +2 -2
  185. package/dist/relevance/index.js +1 -1
  186. package/dist/server/composite-auth.d.ts +9 -0
  187. package/dist/server/composite-auth.d.ts.map +1 -0
  188. package/dist/server/index.cjs +31 -0
  189. package/dist/server/index.cjs.map +1 -1
  190. package/dist/server/index.d.ts +1 -0
  191. package/dist/server/index.d.ts.map +1 -1
  192. package/dist/server/index.js +31 -1
  193. package/dist/server/index.js.map +1 -1
  194. package/dist/storage/index.cjs +29 -29
  195. package/dist/storage/index.js +1 -1
  196. package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
  197. package/dist/stream/base/output.d.ts.map +1 -1
  198. package/dist/stream/index.cjs +11 -11
  199. package/dist/stream/index.js +2 -2
  200. package/dist/stream/types.d.ts +7 -2
  201. package/dist/stream/types.d.ts.map +1 -1
  202. package/dist/test-utils/llm-mock.cjs +2 -2
  203. package/dist/test-utils/llm-mock.js +1 -1
  204. package/dist/tools/index.cjs +6 -6
  205. package/dist/tools/index.js +2 -2
  206. package/dist/tools/is-vercel-tool.cjs +2 -2
  207. package/dist/tools/is-vercel-tool.js +1 -1
  208. package/dist/tools/stream.d.ts +1 -0
  209. package/dist/tools/stream.d.ts.map +1 -1
  210. package/dist/tools/tool-builder/builder.d.ts +2 -0
  211. package/dist/tools/tool-builder/builder.d.ts.map +1 -1
  212. package/dist/tools/tool.d.ts +6 -6
  213. package/dist/tools/tool.d.ts.map +1 -1
  214. package/dist/tools/types.d.ts +6 -2
  215. package/dist/tools/types.d.ts.map +1 -1
  216. package/dist/tools/validation.d.ts +13 -1
  217. package/dist/tools/validation.d.ts.map +1 -1
  218. package/dist/utils.cjs +22 -22
  219. package/dist/utils.d.ts +1 -1
  220. package/dist/utils.d.ts.map +1 -1
  221. package/dist/utils.js +1 -1
  222. package/dist/vector/filter/index.cjs +7 -189
  223. package/dist/vector/filter/index.cjs.map +1 -1
  224. package/dist/vector/filter/index.js +1 -190
  225. package/dist/vector/filter/index.js.map +1 -1
  226. package/dist/vector/index.cjs +5 -0
  227. package/dist/vector/index.cjs.map +1 -1
  228. package/dist/vector/index.d.ts +1 -0
  229. package/dist/vector/index.d.ts.map +1 -1
  230. package/dist/vector/index.js +1 -0
  231. package/dist/vector/index.js.map +1 -1
  232. package/dist/vector/types.d.ts +86 -3
  233. package/dist/vector/types.d.ts.map +1 -1
  234. package/dist/vector/vector.d.ts +39 -2
  235. package/dist/vector/vector.d.ts.map +1 -1
  236. package/dist/workflows/default.d.ts.map +1 -1
  237. package/dist/workflows/evented/index.cjs +10 -10
  238. package/dist/workflows/evented/index.js +1 -1
  239. package/dist/workflows/evented/step-executor.d.ts.map +1 -1
  240. package/dist/workflows/index.cjs +23 -19
  241. package/dist/workflows/index.js +1 -1
  242. package/dist/workflows/types.d.ts +2 -2
  243. package/dist/workflows/types.d.ts.map +1 -1
  244. package/dist/workflows/utils.d.ts +7 -0
  245. package/dist/workflows/utils.d.ts.map +1 -1
  246. package/dist/workflows/workflow.d.ts +4 -2
  247. package/dist/workflows/workflow.d.ts.map +1 -1
  248. package/package.json +9 -8
  249. package/src/llm/model/provider-types.generated.d.ts +192 -11
  250. package/dist/chunk-2NVBZKZI.cjs.map +0 -1
  251. package/dist/chunk-3RW5EMSB.js.map +0 -1
  252. package/dist/chunk-3W5RQCCY.cjs.map +0 -1
  253. package/dist/chunk-4IKJAKCD.cjs.map +0 -1
  254. package/dist/chunk-4RXG622P.cjs.map +0 -1
  255. package/dist/chunk-5WXEYDFI.cjs.map +0 -1
  256. package/dist/chunk-D6EDHNGV.js.map +0 -1
  257. package/dist/chunk-FVNT7VTO.js.map +0 -1
  258. package/dist/chunk-HBJPYQRN.cjs.map +0 -1
  259. package/dist/chunk-HGNRQ3OG.js.map +0 -1
  260. package/dist/chunk-IHJDOC3A.js.map +0 -1
  261. package/dist/chunk-IWB65P37.cjs.map +0 -1
  262. package/dist/chunk-JXESKY4A.js.map +0 -1
  263. package/dist/chunk-KEURQGCQ.js.map +0 -1
  264. package/dist/chunk-LRSB62Z6.cjs.map +0 -1
  265. package/dist/chunk-MDKPL2R2.js.map +0 -1
  266. package/dist/chunk-O6NA3Z43.cjs.map +0 -1
  267. package/dist/chunk-RXDJL5QT.js.map +0 -1
  268. package/dist/chunk-S6OEQHEI.cjs.map +0 -1
  269. package/dist/chunk-U7VECK2G.js.map +0 -1
  270. package/dist/chunk-VSM3NLUX.cjs.map +0 -1
  271. package/dist/chunk-VZC4BWWH.cjs.map +0 -1
  272. package/dist/chunk-W3DD3XP5.js.map +0 -1
  273. package/dist/chunk-WTYNK7Q4.js.map +0 -1
  274. package/dist/chunk-XXBWX7DT.js.map +0 -1
  275. package/dist/chunk-ZCVTH3CH.cjs.map +0 -1
  276. package/dist/models-dev-6PRLJKVZ.js +0 -3
  277. package/dist/models-dev-WHMI5G6Y.cjs +0 -12
  278. package/dist/netlify-46I3SNNV.cjs +0 -12
  279. package/dist/netlify-EBQ6YUC6.js +0 -3
  280. package/dist/provider-registry-HDG6UMUC.js +0 -3
  281. package/dist/provider-registry-RP2W4B24.cjs +0 -40
  282. package/dist/registry-generator-JPCV47SC.cjs.map +0 -1
  283. package/dist/registry-generator-XD4FPZTU.js.map +0 -1
@@ -2,15 +2,15 @@
2
2
 
3
3
  var chunkISMGVGUM_cjs = require('./chunk-ISMGVGUM.cjs');
4
4
  var chunkABJOUEVA_cjs = require('./chunk-ABJOUEVA.cjs');
5
- var chunkVSM3NLUX_cjs = require('./chunk-VSM3NLUX.cjs');
6
- var chunk3W5RQCCY_cjs = require('./chunk-3W5RQCCY.cjs');
7
- var chunkO6NA3Z43_cjs = require('./chunk-O6NA3Z43.cjs');
5
+ var chunkDQIZ5FFX_cjs = require('./chunk-DQIZ5FFX.cjs');
6
+ var chunkNHP6ZIDG_cjs = require('./chunk-NHP6ZIDG.cjs');
7
+ var chunkOUUPUAGA_cjs = require('./chunk-OUUPUAGA.cjs');
8
8
  var chunkMR7ZWBL6_cjs = require('./chunk-MR7ZWBL6.cjs');
9
- var chunkHBJPYQRN_cjs = require('./chunk-HBJPYQRN.cjs');
9
+ var chunkRROQ46B6_cjs = require('./chunk-RROQ46B6.cjs');
10
10
  var chunkE7K4FTLN_cjs = require('./chunk-E7K4FTLN.cjs');
11
11
  var chunkTWH4PTDG_cjs = require('./chunk-TWH4PTDG.cjs');
12
- var chunkLRSB62Z6_cjs = require('./chunk-LRSB62Z6.cjs');
13
- var chunk4IKJAKCD_cjs = require('./chunk-4IKJAKCD.cjs');
12
+ var chunkX7F4CSGR_cjs = require('./chunk-X7F4CSGR.cjs');
13
+ var chunkV537VSV4_cjs = require('./chunk-V537VSV4.cjs');
14
14
  var chunkJ7O6WENZ_cjs = require('./chunk-J7O6WENZ.cjs');
15
15
  var chunk4WQYXT2I_cjs = require('./chunk-4WQYXT2I.cjs');
16
16
  var chunkKEXGB7FK_cjs = require('./chunk-KEXGB7FK.cjs');
@@ -21,8 +21,8 @@ var web = require('stream/web');
21
21
  var crypto2 = require('crypto');
22
22
  var providerV5 = require('@ai-sdk/provider-v5');
23
23
  var aiV5 = require('ai-v5');
24
- var z5 = require('zod');
25
24
  var schemaCompat = require('@mastra/schema-compat');
25
+ var z5 = require('zod');
26
26
  var radash = require('radash');
27
27
  var providerUtilsV5 = require('@ai-sdk/provider-utils-v5');
28
28
  var lite = require('js-tiktoken/lite');
@@ -970,7 +970,8 @@ async function validateStepInput({
970
970
  const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
971
971
  validationError = new Error("Step input validation failed: \n" + errorMessages);
972
972
  } else {
973
- inputData = radash.isEmpty(validatedInput.data) ? prevOutput : validatedInput.data;
973
+ const isEmptyData = radash.isEmpty(validatedInput.data);
974
+ inputData = isEmptyData ? prevOutput : validatedInput.data;
974
975
  }
975
976
  }
976
977
  return { inputData, validationError };
@@ -993,6 +994,27 @@ async function validateStepResumeData({ resumeData, step }) {
993
994
  }
994
995
  return { resumeData, validationError };
995
996
  }
997
+ async function validateStepSuspendData({
998
+ suspendData,
999
+ step
1000
+ }) {
1001
+ if (!suspendData) {
1002
+ return { suspendData: void 0, validationError: void 0 };
1003
+ }
1004
+ let validationError;
1005
+ const suspendSchema = step.suspendSchema;
1006
+ if (suspendSchema) {
1007
+ const validatedSuspendData = await suspendSchema.safeParseAsync(suspendData);
1008
+ if (!validatedSuspendData.success) {
1009
+ const errors = getZodErrors(validatedSuspendData.error);
1010
+ const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
1011
+ validationError = new Error("Step suspend data validation failed: \n" + errorMessages);
1012
+ } else {
1013
+ suspendData = validatedSuspendData.data;
1014
+ }
1015
+ }
1016
+ return { suspendData, validationError };
1017
+ }
996
1018
  function getResumeLabelsByStepId(resumeLabels, stepId) {
997
1019
  return Object.entries(resumeLabels).filter(([_, value]) => value.stepId === stepId).reduce(
998
1020
  (acc, [key, value]) => {
@@ -1107,7 +1129,7 @@ var createTimeTravelExecutionParams = (params) => {
1107
1129
  result = void 0;
1108
1130
  }
1109
1131
  if (result) {
1110
- const formattedResult = chunkHBJPYQRN_cjs.removeUndefinedValues(result);
1132
+ const formattedResult = chunkRROQ46B6_cjs.removeUndefinedValues(result);
1111
1133
  stepResults[stepId] = formattedResult;
1112
1134
  }
1113
1135
  });
@@ -1451,7 +1473,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1451
1473
  [chunkABJOUEVA_cjs.STREAM_FORMAT_SYMBOL]: executionContext.format,
1452
1474
  engine: {},
1453
1475
  abortSignal: abortController?.signal,
1454
- writer: new chunkLRSB62Z6_cjs.ToolStream(
1476
+ writer: new chunkX7F4CSGR_cjs.ToolStream(
1455
1477
  {
1456
1478
  prefix: "workflow-step",
1457
1479
  callId: stepCallId,
@@ -1528,7 +1550,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1528
1550
  [chunkABJOUEVA_cjs.STREAM_FORMAT_SYMBOL]: executionContext.format,
1529
1551
  engine: {},
1530
1552
  abortSignal: abortController?.signal,
1531
- writer: new chunkLRSB62Z6_cjs.ToolStream(
1553
+ writer: new chunkX7F4CSGR_cjs.ToolStream(
1532
1554
  {
1533
1555
  prefix: "workflow-step",
1534
1556
  callId: stepCallId,
@@ -1681,6 +1703,13 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1681
1703
  getInitData: () => stepResults?.input,
1682
1704
  getStepResult: getStepResult.bind(this, stepResults),
1683
1705
  suspend: async (suspendPayload, suspendOptions) => {
1706
+ const { suspendData, validationError: validationError2 } = await validateStepSuspendData({
1707
+ suspendData: suspendPayload,
1708
+ step
1709
+ });
1710
+ if (validationError2) {
1711
+ throw validationError2;
1712
+ }
1684
1713
  executionContext.suspendedPaths[step.id] = executionContext.executionPath;
1685
1714
  if (suspendOptions?.resumeLabel) {
1686
1715
  const resumeLabel = Array.isArray(suspendOptions.resumeLabel) ? suspendOptions.resumeLabel : [suspendOptions.resumeLabel];
@@ -1691,7 +1720,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1691
1720
  };
1692
1721
  }
1693
1722
  }
1694
- suspended = { payload: suspendPayload };
1723
+ suspended = { payload: suspendData };
1695
1724
  },
1696
1725
  bail: (result2) => {
1697
1726
  bailed = { payload: result2 };
@@ -1722,7 +1751,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1722
1751
  [chunkABJOUEVA_cjs.STREAM_FORMAT_SYMBOL]: executionContext.format,
1723
1752
  engine: {},
1724
1753
  abortSignal: abortController?.signal,
1725
- writer: new chunkLRSB62Z6_cjs.ToolStream(
1754
+ writer: new chunkX7F4CSGR_cjs.ToolStream(
1726
1755
  {
1727
1756
  prefix: "workflow-step",
1728
1757
  callId: stepCallId,
@@ -2085,7 +2114,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2085
2114
  [chunkABJOUEVA_cjs.STREAM_FORMAT_SYMBOL]: executionContext.format,
2086
2115
  engine: {},
2087
2116
  abortSignal: abortController?.signal,
2088
- writer: new chunkLRSB62Z6_cjs.ToolStream(
2117
+ writer: new chunkX7F4CSGR_cjs.ToolStream(
2089
2118
  {
2090
2119
  prefix: "workflow-step",
2091
2120
  callId: crypto2.randomUUID(),
@@ -2294,7 +2323,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2294
2323
  const evalSpan = loopSpan?.createChildSpan({
2295
2324
  type: "workflow_conditional_eval" /* WORKFLOW_CONDITIONAL_EVAL */,
2296
2325
  name: `condition: '${entry.loopType}'`,
2297
- input: chunkHBJPYQRN_cjs.selectFields(result.output, ["stepResult", "output.text", "output.object", "messages"]),
2326
+ input: chunkRROQ46B6_cjs.selectFields(result.output, ["stepResult", "output.text", "output.object", "messages"]),
2298
2327
  attributes: {
2299
2328
  conditionIndex: iteration
2300
2329
  },
@@ -2330,7 +2359,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
2330
2359
  [chunkABJOUEVA_cjs.STREAM_FORMAT_SYMBOL]: executionContext.format,
2331
2360
  engine: {},
2332
2361
  abortSignal: abortController?.signal,
2333
- writer: new chunkLRSB62Z6_cjs.ToolStream(
2362
+ writer: new chunkX7F4CSGR_cjs.ToolStream(
2334
2363
  {
2335
2364
  prefix: "workflow-step",
2336
2365
  callId: crypto2.randomUUID(),
@@ -2987,7 +3016,7 @@ function mapVariable(config) {
2987
3016
  function createStep(params, agentOptions) {
2988
3017
  if (params instanceof Agent) {
2989
3018
  return {
2990
- id: params.name,
3019
+ id: params.id,
2991
3020
  description: params.getDescription(),
2992
3021
  // @ts-ignore
2993
3022
  inputSchema: z5.z.object({
@@ -3079,7 +3108,7 @@ function createStep(params, agentOptions) {
3079
3108
  component: params.component
3080
3109
  };
3081
3110
  }
3082
- if (params instanceof chunk4IKJAKCD_cjs.Tool) {
3111
+ if (params instanceof chunkV537VSV4_cjs.Tool) {
3083
3112
  if (!params.inputSchema || !params.outputSchema) {
3084
3113
  throw new Error("Tool must have input and output schemas defined");
3085
3114
  }
@@ -3090,6 +3119,8 @@ function createStep(params, agentOptions) {
3090
3119
  description: params.description,
3091
3120
  inputSchema: params.inputSchema,
3092
3121
  outputSchema: params.outputSchema,
3122
+ resumeSchema: params.resumeSchema,
3123
+ suspendSchema: params.suspendSchema,
3093
3124
  execute: async ({
3094
3125
  inputData,
3095
3126
  mastra,
@@ -3106,10 +3137,11 @@ function createStep(params, agentOptions) {
3106
3137
  mastra,
3107
3138
  requestContext,
3108
3139
  tracingContext,
3109
- suspend,
3110
3140
  resumeData,
3111
3141
  workflow: {
3112
3142
  runId,
3143
+ suspend,
3144
+ resumeData,
3113
3145
  workflowId,
3114
3146
  state,
3115
3147
  setState
@@ -3570,6 +3602,7 @@ var Workflow = class extends chunkKEXGB7FK_cjs.MastraBase {
3570
3602
  const run = this.#runs.get(runIdToUse) ?? new Run({
3571
3603
  workflowId: this.id,
3572
3604
  stateSchema: this.stateSchema,
3605
+ inputSchema: this.inputSchema,
3573
3606
  runId: runIdToUse,
3574
3607
  resourceId: options?.resourceId,
3575
3608
  executionEngine: this.executionEngine,
@@ -3929,6 +3962,7 @@ var Run = class {
3929
3962
  closeStreamAction;
3930
3963
  executionResults;
3931
3964
  stateSchema;
3965
+ inputSchema;
3932
3966
  cleanup;
3933
3967
  retryConfig;
3934
3968
  constructor(params) {
@@ -3947,6 +3981,7 @@ var Run = class {
3947
3981
  this.workflowSteps = params.workflowSteps;
3948
3982
  this.validateInputs = params.validateInputs;
3949
3983
  this.stateSchema = params.stateSchema;
3984
+ this.inputSchema = params.inputSchema;
3950
3985
  this.workflowRunStatus = "pending";
3951
3986
  this.workflowEngineType = params.workflowEngineType;
3952
3987
  }
@@ -3963,29 +3998,16 @@ var Run = class {
3963
3998
  this.abortController?.abort();
3964
3999
  }
3965
4000
  async _validateInput(inputData) {
3966
- const firstEntry = this.executionGraph.steps[0];
3967
4001
  let inputDataToUse = inputData;
3968
- if (firstEntry && this.validateInputs) {
3969
- let inputSchema;
3970
- if (firstEntry.type === "step" || firstEntry.type === "foreach" || firstEntry.type === "loop") {
3971
- const step = firstEntry.step;
3972
- inputSchema = step.inputSchema;
3973
- } else if (firstEntry.type === "conditional" || firstEntry.type === "parallel") {
3974
- const firstStep = firstEntry.steps[0];
3975
- if (firstStep && firstStep.type === "step") {
3976
- inputSchema = firstStep.step.inputSchema;
3977
- }
3978
- }
3979
- if (inputSchema) {
3980
- const validatedInputData = await inputSchema.safeParseAsync(inputData);
3981
- if (!validatedInputData.success) {
3982
- const errors = getZodErrors(validatedInputData.error);
3983
- throw new Error(
3984
- "Invalid input data: \n" + errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n")
3985
- );
3986
- }
3987
- inputDataToUse = validatedInputData.data;
4002
+ if (this.validateInputs && this.inputSchema) {
4003
+ const validatedInputData = await this.inputSchema.safeParseAsync(inputData);
4004
+ if (!validatedInputData.success) {
4005
+ const errors = getZodErrors(validatedInputData.error);
4006
+ throw new Error(
4007
+ "Invalid input data: \n" + errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n")
4008
+ );
3988
4009
  }
4010
+ inputDataToUse = validatedInputData.data;
3989
4011
  }
3990
4012
  return inputDataToUse;
3991
4013
  }
@@ -5364,7 +5386,7 @@ function convertMastraChunkToAISDKv5({
5364
5386
  if (mode === "generate") {
5365
5387
  return {
5366
5388
  type: "file",
5367
- file: new chunkVSM3NLUX_cjs.DefaultGeneratedFile({
5389
+ file: new chunkDQIZ5FFX_cjs.DefaultGeneratedFile({
5368
5390
  data: chunk.payload.data,
5369
5391
  mediaType: chunk.payload.mimeType
5370
5392
  })
@@ -5372,7 +5394,7 @@ function convertMastraChunkToAISDKv5({
5372
5394
  }
5373
5395
  return {
5374
5396
  type: "file",
5375
- file: new chunkVSM3NLUX_cjs.DefaultGeneratedFileWithType({
5397
+ file: new chunkDQIZ5FFX_cjs.DefaultGeneratedFileWithType({
5376
5398
  data: chunk.payload.data,
5377
5399
  mediaType: chunk.payload.mimeType
5378
5400
  })
@@ -6134,7 +6156,7 @@ function createLLMExecutionStep({
6134
6156
  }
6135
6157
  if (prepareStepResult.messages) {
6136
6158
  const newMessages = prepareStepResult.messages;
6137
- const newMessageList = new chunkVSM3NLUX_cjs.MessageList();
6159
+ const newMessageList = new chunkDQIZ5FFX_cjs.MessageList();
6138
6160
  for (const message of newMessages) {
6139
6161
  if (message.role === "system") {
6140
6162
  newMessageList.addSystem(message);
@@ -6503,13 +6525,87 @@ function createToolCallStep({
6503
6525
  controller,
6504
6526
  runId,
6505
6527
  streamState,
6506
- modelSpanTracker
6528
+ modelSpanTracker,
6529
+ _internal
6507
6530
  }) {
6508
6531
  return createStep({
6509
6532
  id: "toolCallStep",
6510
6533
  inputSchema: toolCallInputSchema,
6511
6534
  outputSchema: toolCallOutputSchema,
6512
6535
  execute: async ({ inputData, suspend, resumeData, requestContext }) => {
6536
+ const addToolApprovalMetadata = (toolCallId, toolName, args) => {
6537
+ const responseMessages = messageList.get.response.db();
6538
+ const lastAssistantMessage = [...responseMessages].reverse().find((msg) => msg.role === "assistant");
6539
+ if (lastAssistantMessage) {
6540
+ const content = lastAssistantMessage.content;
6541
+ if (!content) return;
6542
+ const metadata = typeof lastAssistantMessage.content.metadata === "object" && lastAssistantMessage.content.metadata !== null ? lastAssistantMessage.content.metadata : {};
6543
+ metadata.pendingToolApprovals = metadata.pendingToolApprovals || {};
6544
+ metadata.pendingToolApprovals[toolCallId] = {
6545
+ toolName,
6546
+ args,
6547
+ type: "approval",
6548
+ runId
6549
+ // Store the runId so we can resume after page refresh
6550
+ };
6551
+ lastAssistantMessage.content.metadata = metadata;
6552
+ }
6553
+ };
6554
+ const removeToolApprovalMetadata = async (toolCallId) => {
6555
+ const { saveQueueManager, memoryConfig, threadId } = _internal || {};
6556
+ if (!saveQueueManager || !threadId) {
6557
+ return;
6558
+ }
6559
+ const getMetadata = (message) => {
6560
+ const content = message.content;
6561
+ if (!content) return void 0;
6562
+ const metadata = typeof content.metadata === "object" && content.metadata !== null ? content.metadata : void 0;
6563
+ return metadata;
6564
+ };
6565
+ const allMessages = messageList.get.all.db();
6566
+ const lastAssistantMessage = [...allMessages].reverse().find((msg) => {
6567
+ const metadata = getMetadata(msg);
6568
+ const pendingToolApprovals = metadata?.pendingToolApprovals;
6569
+ return !!pendingToolApprovals?.[toolCallId];
6570
+ });
6571
+ if (lastAssistantMessage) {
6572
+ const metadata = getMetadata(lastAssistantMessage);
6573
+ const pendingToolApprovals = metadata?.pendingToolApprovals;
6574
+ if (pendingToolApprovals && typeof pendingToolApprovals === "object") {
6575
+ delete pendingToolApprovals[toolCallId];
6576
+ if (metadata && Object.keys(pendingToolApprovals).length === 0) {
6577
+ delete metadata.pendingToolApprovals;
6578
+ }
6579
+ try {
6580
+ await saveQueueManager.flushMessages(messageList, threadId, memoryConfig);
6581
+ } catch (error) {
6582
+ console.error("Error removing tool approval metadata:", error);
6583
+ }
6584
+ }
6585
+ }
6586
+ };
6587
+ const flushMessagesBeforeSuspension = async () => {
6588
+ const { saveQueueManager, memoryConfig, threadId, resourceId, memory } = _internal || {};
6589
+ if (!saveQueueManager || !threadId) {
6590
+ return;
6591
+ }
6592
+ try {
6593
+ if (memory && !_internal.threadExists && resourceId) {
6594
+ const thread = await memory.getThreadById?.({ threadId });
6595
+ if (!thread) {
6596
+ await memory.createThread?.({
6597
+ threadId,
6598
+ resourceId,
6599
+ memoryConfig
6600
+ });
6601
+ }
6602
+ _internal.threadExists = true;
6603
+ }
6604
+ await saveQueueManager.flushMessages(messageList, threadId, memoryConfig);
6605
+ } catch (error) {
6606
+ console.error("Error flushing messages before suspension:", error);
6607
+ }
6608
+ };
6513
6609
  if (inputData.providerExecuted) {
6514
6610
  return {
6515
6611
  ...inputData,
@@ -6549,6 +6645,8 @@ function createToolCallStep({
6549
6645
  args: inputData.args
6550
6646
  }
6551
6647
  });
6648
+ addToolApprovalMetadata(inputData.toolCallId, inputData.toolName, inputData.args);
6649
+ await flushMessagesBeforeSuspension();
6552
6650
  return suspend(
6553
6651
  {
6554
6652
  requireToolApproval: {
@@ -6563,6 +6661,7 @@ function createToolCallStep({
6563
6661
  }
6564
6662
  );
6565
6663
  } else {
6664
+ await removeToolApprovalMetadata(inputData.toolCallId);
6566
6665
  if (!resumeData.approved) {
6567
6666
  return {
6568
6667
  result: "Tool call was not approved by the user",
@@ -6585,6 +6684,7 @@ function createToolCallStep({
6585
6684
  from: "AGENT" /* AGENT */,
6586
6685
  payload: { toolCallId: inputData.toolCallId, toolName: inputData.toolName, suspendPayload }
6587
6686
  });
6687
+ await flushMessagesBeforeSuspension();
6588
6688
  return await suspend(
6589
6689
  {
6590
6690
  toolCallSuspended: suspendPayload,
@@ -6598,6 +6698,18 @@ function createToolCallStep({
6598
6698
  resumeData
6599
6699
  };
6600
6700
  const result = await tool.execute(inputData.args, toolOptions);
6701
+ if (tool && "onOutput" in tool && typeof tool.onOutput === "function") {
6702
+ try {
6703
+ await tool.onOutput({
6704
+ toolCallId: inputData.toolCallId,
6705
+ toolName: inputData.toolName,
6706
+ output: result,
6707
+ abortSignal: options?.abortSignal
6708
+ });
6709
+ } catch (error) {
6710
+ console.error("Error calling onOutput", error);
6711
+ }
6712
+ }
6601
6713
  return { result, ...inputData };
6602
6714
  } catch (error) {
6603
6715
  return {
@@ -6617,6 +6729,7 @@ function createAgenticExecutionWorkflow({ models, _internal, ...rest }) {
6617
6729
  ...rest
6618
6730
  });
6619
6731
  const toolCallStep = createToolCallStep({
6732
+ _internal,
6620
6733
  ...rest
6621
6734
  });
6622
6735
  const llmMappingStep = createLLMMappingStep(
@@ -6641,6 +6754,16 @@ function createAgenticExecutionWorkflow({ models, _internal, ...rest }) {
6641
6754
  validateInputs: false
6642
6755
  }
6643
6756
  }).then(llmExecutionStep).map(
6757
+ async ({ inputData }) => {
6758
+ const typedInputData = inputData;
6759
+ const responseMessages = typedInputData.messages.nonUser;
6760
+ if (responseMessages && responseMessages.length > 0) {
6761
+ rest.messageList.add(responseMessages, "response");
6762
+ }
6763
+ return typedInputData;
6764
+ },
6765
+ { id: "add-response-to-messagelist" }
6766
+ ).map(
6644
6767
  async ({ inputData }) => {
6645
6768
  const typedInputData = inputData;
6646
6769
  return typedInputData.output.toolCalls || [];
@@ -6904,7 +7027,13 @@ function loop({
6904
7027
  const internalToUse = {
6905
7028
  now: _internal?.now || (() => Date.now()),
6906
7029
  generateId: _internal?.generateId || (() => aiV5.generateId()),
6907
- currentDate: _internal?.currentDate || (() => /* @__PURE__ */ new Date())
7030
+ currentDate: _internal?.currentDate || (() => /* @__PURE__ */ new Date()),
7031
+ saveQueueManager: _internal?.saveQueueManager,
7032
+ memoryConfig: _internal?.memoryConfig,
7033
+ threadId: _internal?.threadId,
7034
+ resourceId: _internal?.resourceId,
7035
+ memory: _internal?.memory,
7036
+ threadExists: _internal?.threadExists
6908
7037
  };
6909
7038
  let startTimestamp = internalToUse.now?.();
6910
7039
  const messageId = rest.experimental_generateMessageId?.() || internalToUse.generateId?.();
@@ -7090,7 +7219,8 @@ var MastraLLMVNext = class extends chunkKEXGB7FK_cjs.MastraBase {
7090
7219
  _internal,
7091
7220
  agentId,
7092
7221
  toolCallId,
7093
- methodType
7222
+ methodType,
7223
+ includeRawChunks
7094
7224
  }) {
7095
7225
  let stopWhenToUse;
7096
7226
  if (maxSteps && typeof maxSteps === "number") {
@@ -7148,6 +7278,7 @@ var MastraLLMVNext = class extends chunkKEXGB7FK_cjs.MastraBase {
7148
7278
  requireToolApproval,
7149
7279
  agentId,
7150
7280
  methodType,
7281
+ includeRawChunks,
7151
7282
  options: {
7152
7283
  ...options,
7153
7284
  onStepFinish: async (props) => {
@@ -7185,9 +7316,10 @@ var MastraLLMVNext = class extends chunkKEXGB7FK_cjs.MastraBase {
7185
7316
  usage: props?.usage,
7186
7317
  runId
7187
7318
  });
7188
- if (props?.response?.headers?.["x-ratelimit-remaining-tokens"] && parseInt(props?.response?.headers?.["x-ratelimit-remaining-tokens"], 10) < 2e3) {
7319
+ const remainingTokens = parseInt(props?.response?.headers?.["x-ratelimit-remaining-tokens"] ?? "", 10);
7320
+ if (!isNaN(remainingTokens) && remainingTokens > 0 && remainingTokens < 2e3) {
7189
7321
  this.logger.warn("Rate limit approaching, waiting 10 seconds", { runId });
7190
- await chunkHBJPYQRN_cjs.delay(10 * 1e3);
7322
+ await chunkRROQ46B6_cjs.delay(10 * 1e3);
7191
7323
  }
7192
7324
  },
7193
7325
  onFinish: async (props) => {
@@ -7491,7 +7623,7 @@ async function prepareMemoryStep({
7491
7623
  );
7492
7624
  }
7493
7625
  } else {
7494
- const messageList = new chunkVSM3NLUX_cjs.MessageList({
7626
+ const messageList = new chunkDQIZ5FFX_cjs.MessageList({
7495
7627
  threadId: thread?.id,
7496
7628
  resourceId: thread?.resourceId
7497
7629
  });
@@ -7581,11 +7713,13 @@ async function createNetworkLoop({
7581
7713
  const routingAgent = await getRoutingAgent({ requestContext, agent });
7582
7714
  let completionResult;
7583
7715
  const iterationCount = (inputData.iteration ?? -1) + 1;
7716
+ const stepId = generateId3();
7584
7717
  await writer.write({
7585
7718
  type: "routing-agent-start",
7586
7719
  payload: {
7720
+ networkId: agent.id,
7587
7721
  agentId: routingAgent.id,
7588
- runId,
7722
+ runId: stepId,
7589
7723
  inputData: {
7590
7724
  ...inputData,
7591
7725
  iteration: iterationCount
@@ -7631,7 +7765,7 @@ async function createNetworkLoop({
7631
7765
  await writer.write({
7632
7766
  type: "routing-agent-text-start",
7633
7767
  payload: {
7634
- runId
7768
+ runId: stepId
7635
7769
  },
7636
7770
  from: "NETWORK" /* NETWORK */,
7637
7771
  runId
@@ -7645,6 +7779,7 @@ async function createNetworkLoop({
7645
7779
  await writer.write({
7646
7780
  type: "routing-agent-text-delta",
7647
7781
  payload: {
7782
+ runId: stepId,
7648
7783
  text: currentSlice
7649
7784
  },
7650
7785
  from: "NETWORK" /* NETWORK */,
@@ -7673,6 +7808,7 @@ async function createNetworkLoop({
7673
7808
  await writer.write({
7674
7809
  type: "routing-agent-text-delta",
7675
7810
  payload: {
7811
+ runId: stepId,
7676
7812
  text: currentSlice
7677
7813
  },
7678
7814
  from: "NETWORK" /* NETWORK */,
@@ -7693,7 +7829,7 @@ async function createNetworkLoop({
7693
7829
  isComplete: true,
7694
7830
  selectionReason: completionResult.object.completionReason || "",
7695
7831
  iteration: iterationCount,
7696
- runId
7832
+ runId: stepId
7697
7833
  };
7698
7834
  await writer.write({
7699
7835
  type: "routing-agent-end",
@@ -7795,7 +7931,7 @@ ${completionResult?.object?.finalResult}` : ""}
7795
7931
  isComplete: object.primitiveId === "none" && object.primitiveType === "none",
7796
7932
  selectionReason: object.selectionReason,
7797
7933
  iteration: iterationCount,
7798
- runId
7934
+ runId: stepId
7799
7935
  };
7800
7936
  await writer.write({
7801
7937
  type: "routing-agent-end",
@@ -7831,23 +7967,24 @@ ${completionResult?.object?.finalResult}` : ""}
7831
7967
  }),
7832
7968
  execute: async ({ inputData, writer, getInitData }) => {
7833
7969
  const agentsMap = await agent.listAgents({ requestContext });
7834
- const agentId = inputData.primitiveId;
7835
- const agentForStep = agentsMap[agentId];
7970
+ const agentForStep = agentsMap[inputData.primitiveId];
7836
7971
  if (!agentForStep) {
7837
7972
  const mastraError = new chunkTWH4PTDG_cjs.MastraError({
7838
7973
  id: "AGENT_NETWORK_AGENT_EXECUTION_STEP_INVALID_TASK_INPUT",
7839
7974
  domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
7840
7975
  category: "USER" /* USER */,
7841
- text: `Agent ${agentId} not found`
7976
+ text: `Agent ${inputData.primitiveId} not found`
7842
7977
  });
7843
7978
  throw mastraError;
7844
7979
  }
7980
+ const agentId = agentForStep.id;
7981
+ const stepId = generateId3();
7845
7982
  await writer.write({
7846
7983
  type: "agent-execution-start",
7847
7984
  payload: {
7848
- agentId: inputData.primitiveId,
7985
+ agentId,
7849
7986
  args: inputData,
7850
- runId
7987
+ runId: stepId
7851
7988
  },
7852
7989
  from: "NETWORK" /* NETWORK */,
7853
7990
  runId
@@ -7859,9 +7996,12 @@ ${completionResult?.object?.finalResult}` : ""}
7859
7996
  for await (const chunk of result.fullStream) {
7860
7997
  await writer.write({
7861
7998
  type: `agent-execution-event-${chunk.type}`,
7862
- payload: chunk,
7863
- runId: chunk.runId,
7864
- from: "NETWORK" /* NETWORK */
7999
+ payload: {
8000
+ ...chunk,
8001
+ runId: stepId
8002
+ },
8003
+ from: "NETWORK" /* NETWORK */,
8004
+ runId
7865
8005
  });
7866
8006
  }
7867
8007
  const memory = await agent.getMemory({ requestContext });
@@ -7897,10 +8037,11 @@ ${completionResult?.object?.finalResult}` : ""}
7897
8037
  });
7898
8038
  const endPayload = {
7899
8039
  task: inputData.task,
7900
- agentId: inputData.primitiveId,
8040
+ agentId,
7901
8041
  result: await result.text,
7902
8042
  isComplete: false,
7903
- iteration: inputData.iteration
8043
+ iteration: inputData.iteration,
8044
+ runId: stepId
7904
8045
  };
7905
8046
  await writer.write({
7906
8047
  type: "agent-execution-end",
@@ -7969,11 +8110,12 @@ ${completionResult?.object?.finalResult}` : ""}
7969
8110
  );
7970
8111
  throw mastraError;
7971
8112
  }
8113
+ const stepId = generateId3();
7972
8114
  const run = await wf.createRun({ runId });
7973
8115
  const toolData = {
7974
- name: wf.name,
8116
+ workflowId: wf.id,
7975
8117
  args: inputData,
7976
- runId
8118
+ runId: stepId
7977
8119
  };
7978
8120
  await writer?.write({
7979
8121
  type: "workflow-execution-start",
@@ -7990,9 +8132,12 @@ ${completionResult?.object?.finalResult}` : ""}
7990
8132
  chunks.push(chunk);
7991
8133
  await writer?.write({
7992
8134
  type: `workflow-execution-event-${chunk.type}`,
7993
- payload: chunk,
7994
- runId: chunk.runId,
7995
- from: "NETWORK" /* NETWORK */
8135
+ payload: {
8136
+ ...chunk,
8137
+ runId: stepId
8138
+ },
8139
+ from: "NETWORK" /* NETWORK */,
8140
+ runId
7996
8141
  });
7997
8142
  }
7998
8143
  let runSuccess = true;
@@ -8034,13 +8179,15 @@ ${completionResult?.object?.finalResult}` : ""}
8034
8179
  primitiveType: inputData.primitiveType,
8035
8180
  result: finalResult,
8036
8181
  isComplete: false,
8037
- iteration: inputData.iteration,
8038
- name: wf.name
8182
+ iteration: inputData.iteration
8039
8183
  };
8040
8184
  await writer?.write({
8041
8185
  type: "workflow-execution-end",
8042
8186
  payload: {
8043
8187
  ...endPayload,
8188
+ result: workflowState,
8189
+ name: wf.name,
8190
+ runId: stepId,
8044
8191
  usage: await stream.usage
8045
8192
  },
8046
8193
  from: "NETWORK" /* NETWORK */,
@@ -8075,14 +8222,13 @@ ${completionResult?.object?.finalResult}` : ""}
8075
8222
  const memory = await agent.getMemory({ requestContext });
8076
8223
  const memoryTools = await memory?.listTools?.();
8077
8224
  const toolsMap = { ...agentTools, ...memoryTools };
8078
- const toolId = inputData.primitiveId;
8079
- let tool = toolsMap[toolId];
8225
+ let tool = toolsMap[inputData.primitiveId];
8080
8226
  if (!tool) {
8081
8227
  const mastraError = new chunkTWH4PTDG_cjs.MastraError({
8082
8228
  id: "AGENT_NETWORK_TOOL_EXECUTION_STEP_INVALID_TASK_INPUT",
8083
8229
  domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
8084
8230
  category: "USER" /* USER */,
8085
- text: `Tool ${toolId} not found`
8231
+ text: `Tool ${inputData.primitiveId} not found`
8086
8232
  });
8087
8233
  throw mastraError;
8088
8234
  }
@@ -8091,10 +8237,11 @@ ${completionResult?.object?.finalResult}` : ""}
8091
8237
  id: "AGENT_NETWORK_TOOL_EXECUTION_STEP_INVALID_TASK_INPUT",
8092
8238
  domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
8093
8239
  category: "USER" /* USER */,
8094
- text: `Tool ${toolId} does not have an execute function`
8240
+ text: `Tool ${inputData.primitiveId} does not have an execute function`
8095
8241
  });
8096
8242
  throw mastraError;
8097
8243
  }
8244
+ const toolId = tool.id;
8098
8245
  let inputDataToUse;
8099
8246
  try {
8100
8247
  inputDataToUse = JSON.parse(inputData.prompt);
@@ -8943,7 +9090,7 @@ var AgentLegacyHandler = class {
8943
9090
  writableStream,
8944
9091
  methodType: methodType === "generate" ? "generateLegacy" : "streamLegacy"
8945
9092
  });
8946
- const messageList = new chunkVSM3NLUX_cjs.MessageList({
9093
+ const messageList = new chunkDQIZ5FFX_cjs.MessageList({
8947
9094
  threadId,
8948
9095
  resourceId,
8949
9096
  generateMessageId: this.capabilities.mastra?.generateId?.bind(this.capabilities.mastra),
@@ -9024,7 +9171,7 @@ var AgentLegacyHandler = class {
9024
9171
  existingThread || hasResourceScopeSemanticRecall ? this.capabilities.getMemoryMessages({
9025
9172
  resourceId,
9026
9173
  threadId: threadObject.id,
9027
- vectorMessageSearch: new chunkVSM3NLUX_cjs.MessageList().add(messages, `user`).getLatestUserContent() || "",
9174
+ vectorMessageSearch: new chunkDQIZ5FFX_cjs.MessageList().add(messages, `user`).getLatestUserContent() || "",
9028
9175
  memoryConfig,
9029
9176
  requestContext
9030
9177
  }) : { messages: [] },
@@ -9046,7 +9193,7 @@ The following messages were remembered from a different conversation:
9046
9193
  <remembered_from_other_conversation>
9047
9194
  ${(() => {
9048
9195
  let result = ``;
9049
- const messages2 = new chunkVSM3NLUX_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
9196
+ const messages2 = new chunkDQIZ5FFX_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
9050
9197
  let lastYmd = null;
9051
9198
  for (const msg of messages2) {
9052
9199
  const date = msg.createdAt;
@@ -9097,7 +9244,7 @@ the following messages are from ${ymd}
9097
9244
  systemMessage,
9098
9245
  memorySystemMessage: memorySystemMessage || void 0
9099
9246
  });
9100
- const processedList = new chunkVSM3NLUX_cjs.MessageList({
9247
+ const processedList = new chunkDQIZ5FFX_cjs.MessageList({
9101
9248
  threadId: threadObject.id,
9102
9249
  resourceId,
9103
9250
  generateMessageId: this.capabilities.mastra?.generateId?.bind(this.capabilities.mastra),
@@ -9153,7 +9300,7 @@ the following messages are from ${ymd}
9153
9300
  result: resToLog,
9154
9301
  threadId
9155
9302
  });
9156
- const messageListResponses = new chunkVSM3NLUX_cjs.MessageList({
9303
+ const messageListResponses = new chunkDQIZ5FFX_cjs.MessageList({
9157
9304
  threadId,
9158
9305
  resourceId,
9159
9306
  generateMessageId: this.capabilities.mastra?.generateId?.bind(this.capabilities.mastra),
@@ -9513,7 +9660,7 @@ the following messages are from ${ymd}
9513
9660
  requestContext: mergedGenerateOptions.requestContext || new chunkJ7O6WENZ_cjs.RequestContext(),
9514
9661
  tracingContext,
9515
9662
  outputProcessorOverrides: finalOutputProcessors,
9516
- messageList: new chunkVSM3NLUX_cjs.MessageList({
9663
+ messageList: new chunkDQIZ5FFX_cjs.MessageList({
9517
9664
  threadId: llmOptions.threadId || "",
9518
9665
  resourceId: llmOptions.resourceId || ""
9519
9666
  }).add(
@@ -9603,7 +9750,7 @@ the following messages are from ${ymd}
9603
9750
  const outputProcessorResult = await this.capabilities.__runOutputProcessors({
9604
9751
  requestContext: mergedGenerateOptions.requestContext || new chunkJ7O6WENZ_cjs.RequestContext(),
9605
9752
  tracingContext,
9606
- messageList: new chunkVSM3NLUX_cjs.MessageList({
9753
+ messageList: new chunkDQIZ5FFX_cjs.MessageList({
9607
9754
  threadId: llmOptions.threadId || "",
9608
9755
  resourceId: llmOptions.resourceId || ""
9609
9756
  }).add(
@@ -11906,6 +12053,7 @@ function createMapResultsStep({
11906
12053
  stopWhen: result.stopWhen,
11907
12054
  maxSteps: result.maxSteps,
11908
12055
  providerOptions: result.providerOptions,
12056
+ includeRawChunks: options.includeRawChunks,
11909
12057
  options: {
11910
12058
  ...options.prepareStep && { prepareStep: options.prepareStep },
11911
12059
  onFinish: async (payload) => {
@@ -11998,7 +12146,7 @@ var prepareToolsStepOutputSchema = z5.z.object({
11998
12146
  var prepareMemoryStepOutputSchema = z5.z.object({
11999
12147
  threadExists: z5.z.boolean(),
12000
12148
  thread: storageThreadSchema.optional(),
12001
- messageList: z5.z.instanceof(chunkVSM3NLUX_cjs.MessageList),
12149
+ messageList: z5.z.instanceof(chunkDQIZ5FFX_cjs.MessageList),
12002
12150
  tripwire: z5.z.boolean().optional(),
12003
12151
  tripwireReason: z5.z.string().optional()
12004
12152
  });
@@ -12031,7 +12179,7 @@ function createPrepareMemoryStep({
12031
12179
  outputSchema: prepareMemoryStepOutputSchema,
12032
12180
  execute: async ({ tracingContext }) => {
12033
12181
  const thread = threadFromArgs;
12034
- const messageList = new chunkVSM3NLUX_cjs.MessageList({
12182
+ const messageList = new chunkDQIZ5FFX_cjs.MessageList({
12035
12183
  threadId: thread?.id,
12036
12184
  resourceId,
12037
12185
  generateMessageId: capabilities.generateMessageId,
@@ -12112,7 +12260,7 @@ function createPrepareMemoryStep({
12112
12260
  existingThread || hasResourceScopeSemanticRecall ? capabilities.getMemoryMessages({
12113
12261
  resourceId,
12114
12262
  threadId: threadObject.id,
12115
- vectorMessageSearch: new chunkVSM3NLUX_cjs.MessageList().add(options.messages, `user`).getLatestUserContent() || "",
12263
+ vectorMessageSearch: new chunkDQIZ5FFX_cjs.MessageList().add(options.messages, `user`).getLatestUserContent() || "",
12116
12264
  memoryConfig,
12117
12265
  requestContext
12118
12266
  }) : { messages: [] },
@@ -12138,7 +12286,7 @@ The following messages were remembered from a different conversation:
12138
12286
  <remembered_from_other_conversation>
12139
12287
  ${(() => {
12140
12288
  let result = ``;
12141
- const messages = new chunkVSM3NLUX_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
12289
+ const messages = new chunkDQIZ5FFX_cjs.MessageList().add(resultsFromOtherThreads, "memory").get.all.v1();
12142
12290
  let lastYmd = null;
12143
12291
  for (const msg of messages) {
12144
12292
  const date = msg.createdAt;
@@ -12185,7 +12333,7 @@ the following messages are from ${ymd}
12185
12333
  systemMessage,
12186
12334
  memorySystemMessage: memorySystemMessage || void 0
12187
12335
  });
12188
- const processedList = new chunkVSM3NLUX_cjs.MessageList({
12336
+ const processedList = new chunkDQIZ5FFX_cjs.MessageList({
12189
12337
  threadId: threadObject.id,
12190
12338
  resourceId,
12191
12339
  generateMessageId: capabilities.generateMessageId,
@@ -12261,7 +12409,11 @@ function createStreamStep({
12261
12409
  resumeContext,
12262
12410
  agentId,
12263
12411
  toolCallId,
12264
- methodType
12412
+ methodType,
12413
+ saveQueueManager,
12414
+ memoryConfig,
12415
+ memory,
12416
+ resourceId
12265
12417
  }) {
12266
12418
  return createStep({
12267
12419
  id: "stream-text-step",
@@ -12288,7 +12440,12 @@ function createStreamStep({
12288
12440
  requireToolApproval,
12289
12441
  resumeContext,
12290
12442
  _internal: {
12291
- generateId: capabilities.generateMessageId
12443
+ generateId: capabilities.generateMessageId,
12444
+ saveQueueManager,
12445
+ memoryConfig,
12446
+ threadId: validatedInputData.threadId,
12447
+ resourceId,
12448
+ memory
12292
12449
  },
12293
12450
  agentId,
12294
12451
  toolCallId,
@@ -12349,7 +12506,11 @@ function createPrepareStreamWorkflow({
12349
12506
  resumeContext,
12350
12507
  agentId,
12351
12508
  toolCallId,
12352
- methodType
12509
+ methodType,
12510
+ saveQueueManager,
12511
+ memoryConfig,
12512
+ memory,
12513
+ resourceId
12353
12514
  });
12354
12515
  const mapResultsStep = createMapResultsStep({
12355
12516
  capabilities,
@@ -12974,7 +13135,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
12974
13135
  */
12975
13136
  listTools({ requestContext = new chunkJ7O6WENZ_cjs.RequestContext() } = {}) {
12976
13137
  if (typeof this.#tools !== "function") {
12977
- return chunkHBJPYQRN_cjs.ensureToolProperties(this.#tools);
13138
+ return chunkRROQ46B6_cjs.ensureToolProperties(this.#tools);
12978
13139
  }
12979
13140
  const result = this.#tools({ requestContext, mastra: this.#mastra });
12980
13141
  return resolveMaybePromise(result, (tools) => {
@@ -12992,7 +13153,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
12992
13153
  this.logger.error(mastraError.toString());
12993
13154
  throw mastraError;
12994
13155
  }
12995
- return chunkHBJPYQRN_cjs.ensureToolProperties(tools);
13156
+ return chunkRROQ46B6_cjs.ensureToolProperties(tools);
12996
13157
  });
12997
13158
  }
12998
13159
  /**
@@ -13024,7 +13185,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13024
13185
  });
13025
13186
  });
13026
13187
  } else {
13027
- llm = new chunkO6NA3Z43_cjs.MastraLLMV1({
13188
+ llm = new chunkOUUPUAGA_cjs.MastraLLMV1({
13028
13189
  model: resolvedModel,
13029
13190
  mastra: this.#mastra,
13030
13191
  options: { tracingPolicy: this.#options?.tracingPolicy }
@@ -13049,7 +13210,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13049
13210
  */
13050
13211
  async resolveModelConfig(modelConfig, requestContext) {
13051
13212
  try {
13052
- return await chunk3W5RQCCY_cjs.resolveModelConfig(modelConfig, requestContext, this.#mastra);
13213
+ return await chunkNHP6ZIDG_cjs.resolveModelConfig(modelConfig, requestContext, this.#mastra);
13053
13214
  } catch (error) {
13054
13215
  const mastraError = new chunkTWH4PTDG_cjs.MastraError({
13055
13216
  id: "AGENT_GET_MODEL_MISSING_MODEL_INSTANCE",
@@ -13255,7 +13416,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13255
13416
  instructions
13256
13417
  }) {
13257
13418
  const llm = await this.getLLM({ requestContext, model });
13258
- const normMessage = new chunkVSM3NLUX_cjs.MessageList().add(message, "user").get.all.ui().at(-1);
13419
+ const normMessage = new chunkDQIZ5FFX_cjs.MessageList().add(message, "user").get.all.ui().at(-1);
13259
13420
  if (!normMessage) {
13260
13421
  throw new Error(`Could not generate title from input ${JSON.stringify(message)}`);
13261
13422
  }
@@ -13278,7 +13439,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13278
13439
  const systemInstructions = await this.resolveTitleInstructions(requestContext, instructions);
13279
13440
  let text = "";
13280
13441
  if (llm.getModel().specificationVersion === "v2") {
13281
- const messageList = new chunkVSM3NLUX_cjs.MessageList().add(
13442
+ const messageList = new chunkDQIZ5FFX_cjs.MessageList().add(
13282
13443
  [
13283
13444
  {
13284
13445
  role: "system",
@@ -13330,7 +13491,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13330
13491
  async genTitle(userMessage, requestContext, tracingContext, model, instructions) {
13331
13492
  try {
13332
13493
  if (userMessage) {
13333
- const normMessage = new chunkVSM3NLUX_cjs.MessageList().add(userMessage, "user").get.all.ui().at(-1);
13494
+ const normMessage = new chunkDQIZ5FFX_cjs.MessageList().add(userMessage, "user").get.all.ui().at(-1);
13334
13495
  if (normMessage) {
13335
13496
  return await this.generateTitleFromUserMessage({
13336
13497
  message: normMessage,
@@ -13390,9 +13551,10 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13390
13551
  requestContext,
13391
13552
  tracingContext,
13392
13553
  model: await this.getModel({ requestContext }),
13393
- tracingPolicy: this.#options?.tracingPolicy
13554
+ tracingPolicy: this.#options?.tracingPolicy,
13555
+ requireApproval: toolObj.requireApproval
13394
13556
  };
13395
- const convertedToCoreTool = chunkHBJPYQRN_cjs.makeCoreTool(toolObj, options);
13557
+ const convertedToCoreTool = chunkRROQ46B6_cjs.makeCoreTool(toolObj, options);
13396
13558
  convertedMemoryTools[toolName] = convertedToCoreTool;
13397
13559
  }
13398
13560
  }
@@ -13542,7 +13704,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13542
13704
  tracingPolicy: this.#options?.tracingPolicy,
13543
13705
  requireApproval: tool.requireApproval
13544
13706
  };
13545
- return [k, chunkHBJPYQRN_cjs.makeCoreTool(tool, options)];
13707
+ return [k, chunkRROQ46B6_cjs.makeCoreTool(tool, options)];
13546
13708
  })
13547
13709
  );
13548
13710
  const assignedToolEntriesConverted = Object.fromEntries(
@@ -13588,9 +13750,10 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13588
13750
  requestContext,
13589
13751
  tracingContext,
13590
13752
  model: await this.getModel({ requestContext }),
13591
- tracingPolicy: this.#options?.tracingPolicy
13753
+ tracingPolicy: this.#options?.tracingPolicy,
13754
+ requireApproval: toolObj.requireApproval
13592
13755
  };
13593
- const convertedToCoreTool = chunkHBJPYQRN_cjs.makeCoreTool(toolObj, options, "toolset");
13756
+ const convertedToCoreTool = chunkRROQ46B6_cjs.makeCoreTool(toolObj, options, "toolset");
13594
13757
  toolsForRequest[toolName] = convertedToCoreTool;
13595
13758
  }
13596
13759
  }
@@ -13631,9 +13794,10 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13631
13794
  requestContext,
13632
13795
  tracingContext,
13633
13796
  model: await this.getModel({ requestContext }),
13634
- tracingPolicy: this.#options?.tracingPolicy
13797
+ tracingPolicy: this.#options?.tracingPolicy,
13798
+ requireApproval: tool.requireApproval
13635
13799
  };
13636
- const convertedToCoreTool = chunkHBJPYQRN_cjs.makeCoreTool(rest, options, "client-tool");
13800
+ const convertedToCoreTool = chunkRROQ46B6_cjs.makeCoreTool(rest, options, "client-tool");
13637
13801
  toolsForRequest[toolName] = convertedToCoreTool;
13638
13802
  }
13639
13803
  }
@@ -13656,7 +13820,11 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13656
13820
  if (Object.keys(agents).length > 0) {
13657
13821
  for (const [agentName, agent] of Object.entries(agents)) {
13658
13822
  const agentInputSchema = z5.z.object({
13659
- prompt: z5.z.string().describe("The prompt to send to the agent")
13823
+ prompt: z5.z.string().describe("The prompt to send to the agent"),
13824
+ threadId: z5.z.string().optional().describe("Thread ID for conversation continuity for memory messages"),
13825
+ resourceId: z5.z.string().optional().describe("Resource/user identifier for memory messages"),
13826
+ instructions: z5.z.string().optional().describe("Custom instructions to override agent defaults"),
13827
+ maxSteps: z5.z.number().optional().describe("Maximum number of execution steps for the sub-agent")
13660
13828
  });
13661
13829
  const agentOutputSchema = z5.z.object({
13662
13830
  text: z5.z.string().describe("The response from the agent"),
@@ -13664,13 +13832,12 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13664
13832
  subAgentResourceId: z5.z.string().describe("The resource ID of the agent").optional()
13665
13833
  });
13666
13834
  const modelVersion = (await agent.getModel()).specificationVersion;
13667
- const toolObj = chunk4IKJAKCD_cjs.createTool({
13835
+ const toolObj = chunkV537VSV4_cjs.createTool({
13668
13836
  id: `agent-${agentName}`,
13669
13837
  description: `Agent: ${agentName}`,
13670
13838
  inputSchema: agentInputSchema,
13671
13839
  outputSchema: agentOutputSchema,
13672
13840
  mastra: this.#mastra,
13673
- // BREAKING CHANGE v1.0: New tool signature - first param is inputData, second is context
13674
13841
  // manually wrap agent tools with tracing, so that we can pass the
13675
13842
  // current tool span onto the agent to maintain continuity of the trace
13676
13843
  execute: async (inputData, context) => {
@@ -13683,16 +13850,18 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13683
13850
  resourceId
13684
13851
  });
13685
13852
  let result;
13853
+ const slugify = await import('@sindresorhus/slugify');
13854
+ const subAgentThreadId = inputData.threadId || context?.mastra?.generateId() || crypto2.randomUUID();
13855
+ const subAgentResourceId = inputData.resourceId || context?.mastra?.generateId() || `${slugify.default(this.id)}-${agentName}`;
13686
13856
  if ((methodType === "generate" || methodType === "generateLegacy") && modelVersion === "v2") {
13687
13857
  if (!agent.hasOwnMemory() && this.#memory) {
13688
13858
  agent.__setMemory(this.#memory);
13689
13859
  }
13690
- const subAgentThreadId = crypto2.randomUUID();
13691
- const slugify = await import('@sindresorhus/slugify');
13692
- const subAgentResourceId = `${slugify.default(this.id)}-${agentName}`;
13693
13860
  const generateResult = await agent.generate(inputData.prompt, {
13694
13861
  requestContext,
13695
13862
  tracingContext: context?.tracingContext,
13863
+ ...inputData.instructions && { instructions: inputData.instructions },
13864
+ ...inputData.maxSteps && { maxSteps: inputData.maxSteps },
13696
13865
  ...resourceId && threadId ? {
13697
13866
  memory: {
13698
13867
  resource: subAgentResourceId,
@@ -13711,12 +13880,11 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13711
13880
  if (!agent.hasOwnMemory() && this.#memory) {
13712
13881
  agent.__setMemory(this.#memory);
13713
13882
  }
13714
- const subAgentThreadId = crypto2.randomUUID();
13715
- const slugify = await import('@sindresorhus/slugify');
13716
- const subAgentResourceId = `${slugify.default(this.id)}-${agentName}`;
13717
13883
  const streamResult = await agent.stream(inputData.prompt, {
13718
13884
  requestContext,
13719
13885
  tracingContext: context?.tracingContext,
13886
+ ...inputData.instructions && { instructions: inputData.instructions },
13887
+ ...inputData.maxSteps && { maxSteps: inputData.maxSteps },
13720
13888
  ...resourceId && threadId ? {
13721
13889
  memory: {
13722
13890
  resource: subAgentResourceId,
@@ -13727,7 +13895,11 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13727
13895
  let fullText = "";
13728
13896
  for await (const chunk of streamResult.fullStream) {
13729
13897
  if (context?.writer) {
13730
- await context.writer.write(chunk);
13898
+ if (chunk.type.startsWith("data-")) {
13899
+ await context.writer.custom(chunk);
13900
+ } else {
13901
+ await context.writer.write(chunk);
13902
+ }
13731
13903
  }
13732
13904
  if (chunk.type === "text-delta") {
13733
13905
  fullText += chunk.payload.text;
@@ -13742,7 +13914,11 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13742
13914
  let fullText = "";
13743
13915
  for await (const chunk of streamResult.fullStream) {
13744
13916
  if (context?.writer) {
13745
- await context.writer.write(chunk);
13917
+ if (chunk.type.startsWith("data-")) {
13918
+ await context.writer.custom(chunk);
13919
+ } else {
13920
+ await context.writer.write(chunk);
13921
+ }
13746
13922
  }
13747
13923
  if (chunk.type === "text-delta") {
13748
13924
  fullText += chunk.textDelta;
@@ -13788,7 +13964,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13788
13964
  tracingContext,
13789
13965
  tracingPolicy: this.#options?.tracingPolicy
13790
13966
  };
13791
- convertedAgentTools[`agent-${agentName}`] = chunkHBJPYQRN_cjs.makeCoreTool(toolObj, options);
13967
+ convertedAgentTools[`agent-${agentName}`] = chunkRROQ46B6_cjs.makeCoreTool(toolObj, options);
13792
13968
  }
13793
13969
  }
13794
13970
  return convertedAgentTools;
@@ -13809,13 +13985,25 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13809
13985
  const workflows = await this.listWorkflows({ requestContext });
13810
13986
  if (Object.keys(workflows).length > 0) {
13811
13987
  for (const [workflowName, workflow] of Object.entries(workflows)) {
13812
- const toolObj = chunk4IKJAKCD_cjs.createTool({
13988
+ const extendedInputSchema = z5.z.object({
13989
+ inputData: workflow.inputSchema,
13990
+ ...workflow.stateSchema ? { initialState: workflow.stateSchema } : {}
13991
+ });
13992
+ const toolObj = chunkV537VSV4_cjs.createTool({
13813
13993
  id: `workflow-${workflowName}`,
13814
13994
  description: workflow.description || `Workflow: ${workflowName}`,
13815
- inputSchema: workflow.inputSchema,
13816
- outputSchema: z5.z.object({ result: workflow.outputSchema, runId: z5.z.string() }),
13995
+ inputSchema: extendedInputSchema,
13996
+ outputSchema: z5.z.union([
13997
+ z5.z.object({
13998
+ result: workflow.outputSchema,
13999
+ runId: z5.z.string().describe("Unique identifier for the workflow run")
14000
+ }),
14001
+ z5.z.object({
14002
+ runId: z5.z.string().describe("Unique identifier for the workflow run"),
14003
+ error: z5.z.string().describe("Error message if workflow execution failed")
14004
+ })
14005
+ ]),
13817
14006
  mastra: this.#mastra,
13818
- // BREAKING CHANGE v1.0: New tool signature - first param is inputData, second is context
13819
14007
  // manually wrap workflow tools with tracing, so that we can pass the
13820
14008
  // current tool span onto the workflow to maintain continuity of the trace
13821
14009
  execute: async (inputData, context) => {
@@ -13829,16 +14017,18 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13829
14017
  resourceId
13830
14018
  });
13831
14019
  const run = await workflow.createRun();
13832
- let result;
14020
+ const { initialState, inputData: workflowInputData } = inputData;
14021
+ let result = void 0;
13833
14022
  if (methodType === "generate" || methodType === "generateLegacy") {
13834
14023
  result = await run.start({
13835
- inputData,
14024
+ inputData: workflowInputData,
13836
14025
  requestContext,
13837
- tracingContext: context?.tracingContext
14026
+ tracingContext: context?.tracingContext,
14027
+ ...initialState && { initialState }
13838
14028
  });
13839
14029
  } else if (methodType === "streamLegacy") {
13840
14030
  const streamResult = run.streamLegacy({
13841
- inputData,
14031
+ inputData: workflowInputData,
13842
14032
  requestContext,
13843
14033
  tracingContext: context?.tracingContext
13844
14034
  });
@@ -13851,17 +14041,36 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13851
14041
  result = await streamResult.getWorkflowState();
13852
14042
  } else if (methodType === "stream") {
13853
14043
  const streamResult = run.stream({
13854
- inputData,
14044
+ inputData: workflowInputData,
13855
14045
  requestContext,
13856
- tracingContext: context?.tracingContext
14046
+ tracingContext: context?.tracingContext,
14047
+ ...initialState && { initialState }
13857
14048
  });
13858
14049
  if (context?.writer) {
13859
14050
  await streamResult.fullStream.pipeTo(context.writer);
13860
14051
  }
13861
14052
  result = await streamResult.result;
13862
14053
  }
13863
- const workflowOutput = result?.result || result;
13864
- return { result: workflowOutput, runId: run.runId };
14054
+ if (result?.status === "success") {
14055
+ const workflowOutput = result?.result || result;
14056
+ return { result: workflowOutput, runId: run.runId };
14057
+ } else if (result?.status === "failed") {
14058
+ const workflowOutputError = result?.error;
14059
+ return {
14060
+ error: workflowOutputError?.message || String(workflowOutputError) || "Workflow execution failed",
14061
+ runId: run.runId
14062
+ };
14063
+ } else if (result?.status === "suspended") {
14064
+ return {
14065
+ error: `Workflow ended with status: "suspended". This is not currently handled in the basic agent workflow tool transformation. To achieve this you'll need to write your own tool that uses a workflow internally.`,
14066
+ runId: run.runId
14067
+ };
14068
+ } else {
14069
+ return {
14070
+ error: `Workflow should never reach this path, workflow returned no status`,
14071
+ runId: run.runId
14072
+ };
14073
+ }
13865
14074
  } catch (err) {
13866
14075
  const mastraError = new chunkTWH4PTDG_cjs.MastraError(
13867
14076
  {
@@ -13898,7 +14107,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13898
14107
  tracingContext,
13899
14108
  tracingPolicy: this.#options?.tracingPolicy
13900
14109
  };
13901
- convertedWorkflowTools[`workflow-${workflowName}`] = chunkHBJPYQRN_cjs.makeCoreTool(toolObj, options);
14110
+ convertedWorkflowTools[`workflow-${workflowName}`] = chunkRROQ46B6_cjs.makeCoreTool(toolObj, options);
13902
14111
  }
13903
14112
  }
13904
14113
  return convertedWorkflowTools;
@@ -13921,7 +14130,7 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
13921
14130
  let mastraProxy = void 0;
13922
14131
  const logger = this.logger;
13923
14132
  if (this.#mastra) {
13924
- mastraProxy = chunkHBJPYQRN_cjs.createMastraProxy({ mastra: this.#mastra, logger });
14133
+ mastraProxy = chunkRROQ46B6_cjs.createMastraProxy({ mastra: this.#mastra, logger });
13925
14134
  }
13926
14135
  const assignedTools = await this.listAssignedTools({
13927
14136
  runId,
@@ -14236,6 +14445,34 @@ var Agent = class extends chunkKEXGB7FK_cjs.MastraBase {
14236
14445
  );
14237
14446
  }
14238
14447
  const llm = await this.getLLM({ requestContext, model: options.model });
14448
+ if ("structuredOutput" in options && options.structuredOutput && options.structuredOutput.schema) {
14449
+ let structuredOutputModel = llm.getModel();
14450
+ if (options.structuredOutput?.model) {
14451
+ structuredOutputModel = await this.resolveModelConfig(
14452
+ options.structuredOutput?.model,
14453
+ requestContext
14454
+ );
14455
+ }
14456
+ const targetProvider = structuredOutputModel.provider;
14457
+ const targetModelId = structuredOutputModel.modelId;
14458
+ if (targetProvider.includes("openai") || targetModelId.includes("openai")) {
14459
+ if (chunkRROQ46B6_cjs.isZodType(options.structuredOutput.schema) && targetModelId) {
14460
+ const modelInfo = {
14461
+ provider: targetProvider,
14462
+ modelId: targetModelId,
14463
+ supportsStructuredOutputs: false
14464
+ // Set to false to enable transform
14465
+ };
14466
+ const isReasoningModel = /^o[1-5]/.test(targetModelId);
14467
+ const compatLayer = isReasoningModel ? new schemaCompat.OpenAIReasoningSchemaCompatLayer(modelInfo) : new schemaCompat.OpenAISchemaCompatLayer(modelInfo);
14468
+ if (compatLayer.shouldApply() && options.structuredOutput.schema) {
14469
+ options.structuredOutput.schema = compatLayer.processZodType(
14470
+ options.structuredOutput.schema
14471
+ );
14472
+ }
14473
+ }
14474
+ }
14475
+ }
14239
14476
  const runId = options.runId || this.#mastra?.generateId() || crypto2.randomUUID();
14240
14477
  const instructions = options.instructions || await this.getInstructions({ requestContext });
14241
14478
  const agentSpan = chunkE7K4FTLN_cjs.getOrCreateSpan({
@@ -15956,7 +16193,7 @@ var MastraModelOutput = class extends chunkKEXGB7FK_cjs.MastraBase {
15956
16193
  self.messageList,
15957
16194
  options.tracingContext
15958
16195
  );
15959
- const outputText = self.messageList.get.response.aiV4.core().map((m) => chunkVSM3NLUX_cjs.MessageList.coreContentToString(m.content)).join("\n");
16196
+ const outputText = self.messageList.get.response.aiV4.core().map((m) => chunkDQIZ5FFX_cjs.MessageList.coreContentToString(m.content)).join("\n");
15960
16197
  self.#delayedPromises.text.resolve(outputText);
15961
16198
  self.#delayedPromises.finishReason.resolve(self.#finishReason);
15962
16199
  if (chunk.payload.metadata) {
@@ -16593,5 +16830,6 @@ exports.tryGenerateWithJsonFallback = tryGenerateWithJsonFallback;
16593
16830
  exports.tryStreamWithJsonFallback = tryStreamWithJsonFallback;
16594
16831
  exports.validateStepInput = validateStepInput;
16595
16832
  exports.validateStepResumeData = validateStepResumeData;
16596
- //# sourceMappingURL=chunk-2NVBZKZI.cjs.map
16597
- //# sourceMappingURL=chunk-2NVBZKZI.cjs.map
16833
+ exports.validateStepSuspendData = validateStepSuspendData;
16834
+ //# sourceMappingURL=chunk-KP42JLXE.cjs.map
16835
+ //# sourceMappingURL=chunk-KP42JLXE.cjs.map