@mastra/core 1.0.0-beta.14 → 1.0.0-beta.16

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 (374) hide show
  1. package/CHANGELOG.md +472 -0
  2. package/dist/agent/agent-legacy.d.ts.map +1 -1
  3. package/dist/agent/agent.d.ts.map +1 -1
  4. package/dist/agent/index.cjs +11 -11
  5. package/dist/agent/index.js +2 -2
  6. package/dist/agent/message-list/index.cjs +3 -3
  7. package/dist/agent/message-list/index.d.ts +1 -1
  8. package/dist/agent/message-list/index.d.ts.map +1 -1
  9. package/dist/agent/message-list/index.js +1 -1
  10. package/dist/agent/message-list/prompt/attachments-to-parts.d.ts.map +1 -1
  11. package/dist/agent/utils.d.ts.map +1 -1
  12. package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
  13. package/dist/{chunk-DBW6S25C.cjs → chunk-33VDGXRH.cjs} +83 -65
  14. package/dist/chunk-33VDGXRH.cjs.map +1 -0
  15. package/dist/chunk-37YWZMBX.js +27 -0
  16. package/dist/chunk-37YWZMBX.js.map +1 -0
  17. package/dist/chunk-3ZRMVPQA.cjs +263 -0
  18. package/dist/chunk-3ZRMVPQA.cjs.map +1 -0
  19. package/dist/{chunk-VZJOEGQA.js → chunk-4DFWV4IR.js} +2 -2
  20. package/dist/chunk-4DFWV4IR.js.map +1 -0
  21. package/dist/{chunk-53SZJCBX.cjs → chunk-4KVIXN7K.cjs} +24 -24
  22. package/dist/{chunk-53SZJCBX.cjs.map → chunk-4KVIXN7K.cjs.map} +1 -1
  23. package/dist/{chunk-QDVYP2T7.js → chunk-4N6WB4EZ.js} +7 -7
  24. package/dist/{chunk-QDVYP2T7.js.map → chunk-4N6WB4EZ.js.map} +1 -1
  25. package/dist/{chunk-HWMMIRIF.cjs → chunk-4U7ZLI36.cjs} +3 -2
  26. package/dist/chunk-4U7ZLI36.cjs.map +1 -0
  27. package/dist/{chunk-O5BQBZEF.cjs → chunk-4UH5LAF5.cjs} +28 -28
  28. package/dist/{chunk-O5BQBZEF.cjs.map → chunk-4UH5LAF5.cjs.map} +1 -1
  29. package/dist/{chunk-JAGQZZ43.cjs → chunk-5DL6Y7PJ.cjs} +696 -352
  30. package/dist/chunk-5DL6Y7PJ.cjs.map +1 -0
  31. package/dist/{chunk-Z55SJVEC.cjs → chunk-6YUHA5UH.cjs} +7 -6
  32. package/dist/chunk-6YUHA5UH.cjs.map +1 -0
  33. package/dist/{chunk-TRUNX3AX.cjs → chunk-7KL2YFFK.cjs} +31 -31
  34. package/dist/chunk-7KL2YFFK.cjs.map +1 -0
  35. package/dist/{chunk-6CG7IY57.cjs → chunk-A6JNGJIU.cjs} +325 -164
  36. package/dist/chunk-A6JNGJIU.cjs.map +1 -0
  37. package/dist/{chunk-EGHGFLL3.cjs → chunk-AAX7ZOM7.cjs} +2 -2
  38. package/dist/chunk-AAX7ZOM7.cjs.map +1 -0
  39. package/dist/{chunk-O3ULBGV6.cjs → chunk-AQ22JIR7.cjs} +43 -21
  40. package/dist/chunk-AQ22JIR7.cjs.map +1 -0
  41. package/dist/chunk-CSCTVLD5.js +598 -0
  42. package/dist/chunk-CSCTVLD5.js.map +1 -0
  43. package/dist/chunk-DMX7MC4N.js +3 -0
  44. package/dist/{chunk-GXSERFAG.js.map → chunk-DMX7MC4N.js.map} +1 -1
  45. package/dist/{chunk-AYBJ5GAD.js → chunk-DT5RMENY.js} +302 -136
  46. package/dist/chunk-DT5RMENY.js.map +1 -0
  47. package/dist/{chunk-72E3YF6A.cjs → chunk-EMLEZXTQ.cjs} +15 -12
  48. package/dist/chunk-EMLEZXTQ.cjs.map +1 -0
  49. package/dist/{chunk-QF4MHFSU.js → chunk-F7PAZAGE.js} +530 -191
  50. package/dist/chunk-F7PAZAGE.js.map +1 -0
  51. package/dist/{chunk-LDXKZYOV.js → chunk-FB5QMTJJ.js} +30 -8
  52. package/dist/chunk-FB5QMTJJ.js.map +1 -0
  53. package/dist/{chunk-YPLZDWG7.js → chunk-FJEVLHJT.js} +3 -2
  54. package/dist/chunk-FJEVLHJT.js.map +1 -0
  55. package/dist/{chunk-GBQXIVL6.js → chunk-GNUITL2N.js} +801 -1240
  56. package/dist/chunk-GNUITL2N.js.map +1 -0
  57. package/dist/chunk-H2NHG7QL.cjs +32 -0
  58. package/dist/chunk-H2NHG7QL.cjs.map +1 -0
  59. package/dist/chunk-J4SXS7KN.js +259 -0
  60. package/dist/chunk-J4SXS7KN.js.map +1 -0
  61. package/dist/{chunk-Y36Y5MTD.js → chunk-JQM64OZF.js} +13 -3
  62. package/dist/chunk-JQM64OZF.js.map +1 -0
  63. package/dist/{chunk-67LM2UCT.js → chunk-K4XAKG7L.js} +5 -5
  64. package/dist/{chunk-67LM2UCT.js.map → chunk-K4XAKG7L.js.map} +1 -1
  65. package/dist/{chunk-4CMIJQF6.js → chunk-KKYAYRIO.js} +14 -14
  66. package/dist/chunk-KKYAYRIO.js.map +1 -0
  67. package/dist/{chunk-FPDJ4XN6.cjs → chunk-NCAMNQC3.cjs} +303 -137
  68. package/dist/chunk-NCAMNQC3.cjs.map +1 -0
  69. package/dist/chunk-NK4UN2LF.cjs +674 -0
  70. package/dist/chunk-NK4UN2LF.cjs.map +1 -0
  71. package/dist/{chunk-5UQ5TB6J.js → chunk-NNFF3URD.js} +41 -23
  72. package/dist/chunk-NNFF3URD.js.map +1 -0
  73. package/dist/{chunk-GELVUDUY.js → chunk-O7M7DR4E.js} +3 -3
  74. package/dist/{chunk-GELVUDUY.js.map → chunk-O7M7DR4E.js.map} +1 -1
  75. package/dist/chunk-OTIGV7CL.js +10215 -0
  76. package/dist/chunk-OTIGV7CL.js.map +1 -0
  77. package/dist/{chunk-ETWAR2YE.cjs → chunk-OXV6QFSV.cjs} +828 -1275
  78. package/dist/chunk-OXV6QFSV.cjs.map +1 -0
  79. package/dist/{chunk-373OC54J.js → chunk-QD776HMB.js} +7 -6
  80. package/dist/{chunk-373OC54J.js.map → chunk-QD776HMB.js.map} +1 -1
  81. package/dist/{chunk-4AT6YQKZ.js → chunk-QXL3F3T2.js} +7 -4
  82. package/dist/chunk-QXL3F3T2.js.map +1 -0
  83. package/dist/chunk-RMV5HJM7.cjs +10237 -0
  84. package/dist/chunk-RMV5HJM7.cjs.map +1 -0
  85. package/dist/chunk-ROOVGRNA.cjs +4 -0
  86. package/dist/{chunk-X4RMXTXF.cjs.map → chunk-ROOVGRNA.cjs.map} +1 -1
  87. package/dist/{chunk-OOUFPYSX.cjs → chunk-SSB4AVHU.cjs} +17 -17
  88. package/dist/{chunk-OOUFPYSX.cjs.map → chunk-SSB4AVHU.cjs.map} +1 -1
  89. package/dist/{chunk-TDM43G4I.cjs → chunk-UT6MASE5.cjs} +9 -9
  90. package/dist/{chunk-TDM43G4I.cjs.map → chunk-UT6MASE5.cjs.map} +1 -1
  91. package/dist/{chunk-3IP3DZ7G.js → chunk-UTMBASR5.js} +291 -130
  92. package/dist/chunk-UTMBASR5.js.map +1 -0
  93. package/dist/{chunk-SLBWA2F3.js → chunk-WDXYPI3P.js} +3 -3
  94. package/dist/{chunk-SLBWA2F3.js.map → chunk-WDXYPI3P.js.map} +1 -1
  95. package/dist/{chunk-72YCRTEX.cjs → chunk-ZSZOYPSJ.cjs} +13 -2
  96. package/dist/chunk-ZSZOYPSJ.cjs.map +1 -0
  97. package/dist/error/index.cjs +6 -6
  98. package/dist/error/index.d.ts +1 -0
  99. package/dist/error/index.d.ts.map +1 -1
  100. package/dist/error/index.js +1 -1
  101. package/dist/evals/index.cjs +49 -9
  102. package/dist/evals/index.js +2 -2
  103. package/dist/evals/scoreTraces/index.cjs +70 -22
  104. package/dist/evals/scoreTraces/index.cjs.map +1 -1
  105. package/dist/evals/scoreTraces/index.js +63 -15
  106. package/dist/evals/scoreTraces/index.js.map +1 -1
  107. package/dist/evals/scoreTraces/scoreTracesWorkflow.d.ts.map +1 -1
  108. package/dist/evals/scoreTraces/utils.d.ts.map +1 -1
  109. package/dist/evals/types.d.ts +566 -116
  110. package/dist/evals/types.d.ts.map +1 -1
  111. package/dist/index.cjs +2 -2
  112. package/dist/index.js +1 -1
  113. package/dist/integration/index.cjs +2 -2
  114. package/dist/integration/index.js +1 -1
  115. package/dist/llm/index.cjs +20 -20
  116. package/dist/llm/index.js +4 -4
  117. package/dist/llm/model/aisdk/v6/model.d.ts +1 -9
  118. package/dist/llm/model/aisdk/v6/model.d.ts.map +1 -1
  119. package/dist/llm/model/embedding-router.d.ts +1 -1
  120. package/dist/llm/model/model.d.ts.map +1 -1
  121. package/dist/llm/model/model.loop.d.ts.map +1 -1
  122. package/dist/llm/model/provider-options.d.ts +2 -1
  123. package/dist/llm/model/provider-options.d.ts.map +1 -1
  124. package/dist/llm/model/provider-types.generated.d.ts +129 -58
  125. package/dist/loop/index.cjs +2 -2
  126. package/dist/loop/index.js +1 -1
  127. package/dist/loop/network/index.d.ts +6 -6
  128. package/dist/loop/test-utils/MastraLanguageModelV3Mock.d.ts +1 -9
  129. package/dist/loop/test-utils/MastraLanguageModelV3Mock.d.ts.map +1 -1
  130. package/dist/loop/types.d.ts +5 -2
  131. package/dist/loop/types.d.ts.map +1 -1
  132. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
  133. package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts +1 -1
  134. package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
  135. package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
  136. package/dist/mastra/hooks.d.ts.map +1 -1
  137. package/dist/mastra/index.cjs +2 -2
  138. package/dist/mastra/index.d.ts +7 -2
  139. package/dist/mastra/index.d.ts.map +1 -1
  140. package/dist/mastra/index.js +1 -1
  141. package/dist/mcp/index.cjs +7 -4
  142. package/dist/mcp/index.cjs.map +1 -1
  143. package/dist/mcp/index.d.ts +2 -0
  144. package/dist/mcp/index.d.ts.map +1 -1
  145. package/dist/mcp/index.js +4 -1
  146. package/dist/mcp/index.js.map +1 -1
  147. package/dist/mcp/types.d.ts +2 -0
  148. package/dist/mcp/types.d.ts.map +1 -1
  149. package/dist/memory/index.cjs +26 -6
  150. package/dist/memory/index.d.ts +1 -0
  151. package/dist/memory/index.d.ts.map +1 -1
  152. package/dist/memory/index.js +1 -1
  153. package/dist/memory/memory.d.ts +9 -8
  154. package/dist/memory/memory.d.ts.map +1 -1
  155. package/dist/memory/mock.d.ts +2 -1
  156. package/dist/memory/mock.d.ts.map +1 -1
  157. package/dist/memory/types.d.ts +3 -4
  158. package/dist/memory/types.d.ts.map +1 -1
  159. package/dist/memory/working-memory-utils.d.ts +20 -0
  160. package/dist/memory/working-memory-utils.d.ts.map +1 -0
  161. package/dist/models-dev-26XLUKVK.cjs +12 -0
  162. package/dist/{models-dev-PPS7X4JM.cjs.map → models-dev-26XLUKVK.cjs.map} +1 -1
  163. package/dist/models-dev-HUFLQFPB.js +3 -0
  164. package/dist/{models-dev-E3WWI7VA.js.map → models-dev-HUFLQFPB.js.map} +1 -1
  165. package/dist/netlify-3MHHJG2E.js +3 -0
  166. package/dist/{netlify-TY656UYF.js.map → netlify-3MHHJG2E.js.map} +1 -1
  167. package/dist/netlify-5Y33S7WL.cjs +12 -0
  168. package/dist/{netlify-VZFM5UH3.cjs.map → netlify-5Y33S7WL.cjs.map} +1 -1
  169. package/dist/observability/index.cjs +14 -10
  170. package/dist/observability/index.js +1 -1
  171. package/dist/observability/types/tracing.d.ts +34 -20
  172. package/dist/observability/types/tracing.d.ts.map +1 -1
  173. package/dist/processors/index.cjs +37 -37
  174. package/dist/processors/index.d.ts +2 -0
  175. package/dist/processors/index.d.ts.map +1 -1
  176. package/dist/processors/index.js +1 -1
  177. package/dist/processors/memory/message-history.d.ts +7 -1
  178. package/dist/processors/memory/message-history.d.ts.map +1 -1
  179. package/dist/processors/processors/language-detector.d.ts.map +1 -1
  180. package/dist/processors/processors/moderation.d.ts.map +1 -1
  181. package/dist/processors/processors/pii-detector.d.ts.map +1 -1
  182. package/dist/processors/processors/prompt-injection-detector.d.ts.map +1 -1
  183. package/dist/processors/processors/structured-output.d.ts +1 -0
  184. package/dist/processors/processors/structured-output.d.ts.map +1 -1
  185. package/dist/processors/processors/token-limiter.d.ts +5 -2
  186. package/dist/processors/processors/token-limiter.d.ts.map +1 -1
  187. package/dist/processors/runner.d.ts +2 -0
  188. package/dist/processors/runner.d.ts.map +1 -1
  189. package/dist/provider-registry-LXSWMVEC.js +3 -0
  190. package/dist/{provider-registry-NXVD764B.js.map → provider-registry-LXSWMVEC.js.map} +1 -1
  191. package/dist/provider-registry-YJ2P5YY5.cjs +40 -0
  192. package/dist/{provider-registry-ZIWSEUQE.cjs.map → provider-registry-YJ2P5YY5.cjs.map} +1 -1
  193. package/dist/provider-registry.json +298 -132
  194. package/dist/relevance/index.cjs +3 -3
  195. package/dist/relevance/index.js +1 -1
  196. package/dist/server/index.cjs +5 -5
  197. package/dist/server/index.js +1 -1
  198. package/dist/server/types.d.ts +28 -0
  199. package/dist/server/types.d.ts.map +1 -1
  200. package/dist/storage/base.d.ts +95 -300
  201. package/dist/storage/base.d.ts.map +1 -1
  202. package/dist/storage/constants.cjs +60 -0
  203. package/dist/storage/constants.cjs.map +1 -0
  204. package/dist/storage/constants.d.ts +6 -1
  205. package/dist/storage/constants.d.ts.map +1 -1
  206. package/dist/storage/constants.js +3 -0
  207. package/dist/storage/constants.js.map +1 -0
  208. package/dist/storage/domains/agents/base.d.ts +2 -2
  209. package/dist/storage/domains/agents/base.d.ts.map +1 -1
  210. package/dist/storage/domains/agents/inmemory.d.ts +5 -4
  211. package/dist/storage/domains/agents/inmemory.d.ts.map +1 -1
  212. package/dist/storage/domains/base.d.ts +20 -0
  213. package/dist/storage/domains/base.d.ts.map +1 -0
  214. package/dist/storage/domains/index.d.ts +3 -0
  215. package/dist/storage/domains/index.d.ts.map +1 -1
  216. package/dist/storage/domains/inmemory-db.d.ts +57 -0
  217. package/dist/storage/domains/inmemory-db.d.ts.map +1 -0
  218. package/dist/storage/domains/memory/base.d.ts +2 -2
  219. package/dist/storage/domains/memory/base.d.ts.map +1 -1
  220. package/dist/storage/domains/memory/inmemory.d.ts +5 -13
  221. package/dist/storage/domains/memory/inmemory.d.ts.map +1 -1
  222. package/dist/storage/domains/observability/base.d.ts +24 -29
  223. package/dist/storage/domains/observability/base.d.ts.map +1 -1
  224. package/dist/storage/domains/observability/index.d.ts +1 -0
  225. package/dist/storage/domains/observability/index.d.ts.map +1 -1
  226. package/dist/storage/domains/observability/inmemory.d.ts +46 -35
  227. package/dist/storage/domains/observability/inmemory.d.ts.map +1 -1
  228. package/dist/storage/domains/observability/types.d.ts +2365 -0
  229. package/dist/storage/domains/observability/types.d.ts.map +1 -0
  230. package/dist/storage/domains/scores/base.d.ts +9 -20
  231. package/dist/storage/domains/scores/base.d.ts.map +1 -1
  232. package/dist/storage/domains/scores/inmemory.d.ts +11 -22
  233. package/dist/storage/domains/scores/inmemory.d.ts.map +1 -1
  234. package/dist/storage/domains/shared.d.ts +76 -0
  235. package/dist/storage/domains/shared.d.ts.map +1 -0
  236. package/dist/storage/domains/workflows/base.d.ts +4 -2
  237. package/dist/storage/domains/workflows/base.d.ts.map +1 -1
  238. package/dist/storage/domains/workflows/inmemory.d.ts +10 -9
  239. package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
  240. package/dist/storage/index.cjs +272 -59
  241. package/dist/storage/index.js +2 -1
  242. package/dist/storage/mock.d.ts +26 -174
  243. package/dist/storage/mock.d.ts.map +1 -1
  244. package/dist/storage/types.d.ts +15 -44
  245. package/dist/storage/types.d.ts.map +1 -1
  246. package/dist/storage/utils.d.ts +5 -0
  247. package/dist/storage/utils.d.ts.map +1 -1
  248. package/dist/stream/MastraAgentNetworkStream.d.ts +1 -1
  249. package/dist/stream/MastraAgentNetworkStream.d.ts.map +1 -1
  250. package/dist/stream/MastraWorkflowStream.d.ts +1 -1
  251. package/dist/stream/MastraWorkflowStream.d.ts.map +1 -1
  252. package/dist/stream/RunOutput.d.ts.map +1 -1
  253. package/dist/stream/aisdk/v5/compat/consume-stream.d.ts +4 -1
  254. package/dist/stream/aisdk/v5/compat/consume-stream.d.ts.map +1 -1
  255. package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
  256. package/dist/stream/base/output.d.ts.map +1 -1
  257. package/dist/stream/index.cjs +12 -12
  258. package/dist/stream/index.js +2 -2
  259. package/dist/stream/types.d.ts +3 -0
  260. package/dist/stream/types.d.ts.map +1 -1
  261. package/dist/test-utils/llm-mock.cjs +4 -4
  262. package/dist/test-utils/llm-mock.js +1 -1
  263. package/dist/tool-loop-agent/index.cjs +20 -0
  264. package/dist/tool-loop-agent/index.cjs.map +1 -0
  265. package/dist/tool-loop-agent/index.d.ts +36 -0
  266. package/dist/tool-loop-agent/index.d.ts.map +1 -0
  267. package/dist/tool-loop-agent/index.js +3 -0
  268. package/dist/tool-loop-agent/index.js.map +1 -0
  269. package/dist/tool-loop-agent/tool-loop-processor.d.ts +30 -0
  270. package/dist/tool-loop-agent/tool-loop-processor.d.ts.map +1 -0
  271. package/dist/tool-loop-agent/utils.d.ts +17 -0
  272. package/dist/tool-loop-agent/utils.d.ts.map +1 -0
  273. package/dist/tools/index.cjs +4 -4
  274. package/dist/tools/index.d.ts +1 -0
  275. package/dist/tools/index.d.ts.map +1 -1
  276. package/dist/tools/index.js +1 -1
  277. package/dist/tools/is-vercel-tool.cjs +2 -2
  278. package/dist/tools/is-vercel-tool.js +1 -1
  279. package/dist/tools/tool-builder/builder.d.ts.map +1 -1
  280. package/dist/tools/tool.d.ts +4 -4
  281. package/dist/tools/tool.d.ts.map +1 -1
  282. package/dist/tools/toolchecks.d.ts +1 -1
  283. package/dist/tools/toolchecks.d.ts.map +1 -1
  284. package/dist/tools/types.d.ts +3 -1
  285. package/dist/tools/types.d.ts.map +1 -1
  286. package/dist/tools/validation.d.ts +1 -1
  287. package/dist/tools/validation.d.ts.map +1 -1
  288. package/dist/utils/zod-utils.d.ts +34 -0
  289. package/dist/utils/zod-utils.d.ts.map +1 -0
  290. package/dist/utils.cjs +39 -22
  291. package/dist/utils.d.ts +1 -1
  292. package/dist/utils.d.ts.map +1 -1
  293. package/dist/utils.js +2 -1
  294. package/dist/vector/index.cjs +12 -5299
  295. package/dist/vector/index.cjs.map +1 -1
  296. package/dist/vector/index.js +3 -5274
  297. package/dist/vector/index.js.map +1 -1
  298. package/dist/vector/vector.d.ts +13 -3
  299. package/dist/vector/vector.d.ts.map +1 -1
  300. package/dist/voice/index.cjs +6 -6
  301. package/dist/voice/index.js +1 -1
  302. package/dist/workflows/default.d.ts +2 -0
  303. package/dist/workflows/default.d.ts.map +1 -1
  304. package/dist/workflows/evented/execution-engine.d.ts +1 -0
  305. package/dist/workflows/evented/execution-engine.d.ts.map +1 -1
  306. package/dist/workflows/evented/index.cjs +10 -10
  307. package/dist/workflows/evented/index.js +1 -1
  308. package/dist/workflows/evented/step-executor.d.ts +1 -0
  309. package/dist/workflows/evented/step-executor.d.ts.map +1 -1
  310. package/dist/workflows/evented/workflow-event-processor/index.d.ts +5 -4
  311. package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
  312. package/dist/workflows/evented/workflow-event-processor/loop.d.ts +2 -2
  313. package/dist/workflows/evented/workflow-event-processor/loop.d.ts.map +1 -1
  314. package/dist/workflows/evented/workflow-event-processor/parallel.d.ts +2 -2
  315. package/dist/workflows/evented/workflow-event-processor/parallel.d.ts.map +1 -1
  316. package/dist/workflows/evented/workflow-event-processor/sleep.d.ts +2 -2
  317. package/dist/workflows/evented/workflow-event-processor/sleep.d.ts.map +1 -1
  318. package/dist/workflows/evented/workflow.d.ts +5 -2
  319. package/dist/workflows/evented/workflow.d.ts.map +1 -1
  320. package/dist/workflows/execution-engine.d.ts +1 -0
  321. package/dist/workflows/execution-engine.d.ts.map +1 -1
  322. package/dist/workflows/handlers/control-flow.d.ts +4 -0
  323. package/dist/workflows/handlers/control-flow.d.ts.map +1 -1
  324. package/dist/workflows/handlers/entry.d.ts +3 -2
  325. package/dist/workflows/handlers/entry.d.ts.map +1 -1
  326. package/dist/workflows/handlers/step.d.ts +1 -0
  327. package/dist/workflows/handlers/step.d.ts.map +1 -1
  328. package/dist/workflows/index.cjs +23 -23
  329. package/dist/workflows/index.js +1 -1
  330. package/dist/workflows/types.d.ts +23 -3
  331. package/dist/workflows/types.d.ts.map +1 -1
  332. package/dist/workflows/utils.d.ts +1 -0
  333. package/dist/workflows/utils.d.ts.map +1 -1
  334. package/dist/workflows/workflow.d.ts +22 -8
  335. package/dist/workflows/workflow.d.ts.map +1 -1
  336. package/package.json +15 -5
  337. package/src/llm/model/provider-types.generated.d.ts +129 -58
  338. package/storage/constants.d.ts +1 -0
  339. package/tool-loop-agent.d.ts +1 -0
  340. package/dist/chunk-3IP3DZ7G.js.map +0 -1
  341. package/dist/chunk-4AT6YQKZ.js.map +0 -1
  342. package/dist/chunk-4CMIJQF6.js.map +0 -1
  343. package/dist/chunk-5UQ5TB6J.js.map +0 -1
  344. package/dist/chunk-6CG7IY57.cjs.map +0 -1
  345. package/dist/chunk-72E3YF6A.cjs.map +0 -1
  346. package/dist/chunk-72YCRTEX.cjs.map +0 -1
  347. package/dist/chunk-ADADLFDR.js +0 -42
  348. package/dist/chunk-ADADLFDR.js.map +0 -1
  349. package/dist/chunk-AYBJ5GAD.js.map +0 -1
  350. package/dist/chunk-DBW6S25C.cjs.map +0 -1
  351. package/dist/chunk-EGHGFLL3.cjs.map +0 -1
  352. package/dist/chunk-ETWAR2YE.cjs.map +0 -1
  353. package/dist/chunk-FPDJ4XN6.cjs.map +0 -1
  354. package/dist/chunk-GBQXIVL6.js.map +0 -1
  355. package/dist/chunk-GXSERFAG.js +0 -3
  356. package/dist/chunk-HWMMIRIF.cjs.map +0 -1
  357. package/dist/chunk-JAGQZZ43.cjs.map +0 -1
  358. package/dist/chunk-LDXKZYOV.js.map +0 -1
  359. package/dist/chunk-O3ULBGV6.cjs.map +0 -1
  360. package/dist/chunk-QF4MHFSU.js.map +0 -1
  361. package/dist/chunk-T2VLUFGG.cjs +0 -47
  362. package/dist/chunk-T2VLUFGG.cjs.map +0 -1
  363. package/dist/chunk-TRUNX3AX.cjs.map +0 -1
  364. package/dist/chunk-VZJOEGQA.js.map +0 -1
  365. package/dist/chunk-X4RMXTXF.cjs +0 -4
  366. package/dist/chunk-Y36Y5MTD.js.map +0 -1
  367. package/dist/chunk-YPLZDWG7.js.map +0 -1
  368. package/dist/chunk-Z55SJVEC.cjs.map +0 -1
  369. package/dist/models-dev-E3WWI7VA.js +0 -3
  370. package/dist/models-dev-PPS7X4JM.cjs +0 -12
  371. package/dist/netlify-TY656UYF.js +0 -3
  372. package/dist/netlify-VZFM5UH3.cjs +0 -12
  373. package/dist/provider-registry-NXVD764B.js +0 -3
  374. package/dist/provider-registry-ZIWSEUQE.cjs +0 -40
@@ -1,20 +1,20 @@
1
1
  'use strict';
2
2
 
3
- var chunkOOUFPYSX_cjs = require('./chunk-OOUFPYSX.cjs');
3
+ var chunkSSB4AVHU_cjs = require('./chunk-SSB4AVHU.cjs');
4
4
  var chunkL3NKIMF5_cjs = require('./chunk-L3NKIMF5.cjs');
5
- var chunkETWAR2YE_cjs = require('./chunk-ETWAR2YE.cjs');
6
- var chunk72E3YF6A_cjs = require('./chunk-72E3YF6A.cjs');
5
+ var chunkOXV6QFSV_cjs = require('./chunk-OXV6QFSV.cjs');
6
+ var chunkEMLEZXTQ_cjs = require('./chunk-EMLEZXTQ.cjs');
7
7
  var chunkNESKUIRE_cjs = require('./chunk-NESKUIRE.cjs');
8
8
  var chunkFVQTJUBD_cjs = require('./chunk-FVQTJUBD.cjs');
9
- var chunk53SZJCBX_cjs = require('./chunk-53SZJCBX.cjs');
10
- var chunkTRUNX3AX_cjs = require('./chunk-TRUNX3AX.cjs');
9
+ var chunk4KVIXN7K_cjs = require('./chunk-4KVIXN7K.cjs');
10
+ var chunk7KL2YFFK_cjs = require('./chunk-7KL2YFFK.cjs');
11
11
  var chunk4D4KB75Y_cjs = require('./chunk-4D4KB75Y.cjs');
12
12
  var chunkMR7ZWBL6_cjs = require('./chunk-MR7ZWBL6.cjs');
13
- var chunkO3ULBGV6_cjs = require('./chunk-O3ULBGV6.cjs');
14
- var chunk72YCRTEX_cjs = require('./chunk-72YCRTEX.cjs');
15
- var chunkHWMMIRIF_cjs = require('./chunk-HWMMIRIF.cjs');
13
+ var chunkAQ22JIR7_cjs = require('./chunk-AQ22JIR7.cjs');
14
+ var chunkZSZOYPSJ_cjs = require('./chunk-ZSZOYPSJ.cjs');
15
+ var chunk4U7ZLI36_cjs = require('./chunk-4U7ZLI36.cjs');
16
16
  var chunkKJBMTK5B_cjs = require('./chunk-KJBMTK5B.cjs');
17
- var chunkZ55SJVEC_cjs = require('./chunk-Z55SJVEC.cjs');
17
+ var chunk6YUHA5UH_cjs = require('./chunk-6YUHA5UH.cjs');
18
18
  var chunkUVHSM2GU_cjs = require('./chunk-UVHSM2GU.cjs');
19
19
  var chunk4WQYXT2I_cjs = require('./chunk-4WQYXT2I.cjs');
20
20
  var chunkDGV2FWB4_cjs = require('./chunk-DGV2FWB4.cjs');
@@ -529,7 +529,8 @@ function prepareToolsAndToolChoice({
529
529
  // src/stream/aisdk/v5/compat/consume-stream.ts
530
530
  async function consumeStream({
531
531
  stream,
532
- onError
532
+ onError,
533
+ logger
533
534
  }) {
534
535
  const reader = stream.getReader();
535
536
  try {
@@ -538,7 +539,7 @@ async function consumeStream({
538
539
  if (done) break;
539
540
  }
540
541
  } catch (error) {
541
- console.error("consumeStream error", error);
542
+ logger?.error("consumeStream error", error);
542
543
  onError?.(error);
543
544
  } finally {
544
545
  reader.releaseLock();
@@ -557,9 +558,10 @@ var StructuredOutputProcessor = class {
557
558
  isStructuringAgentStreamStarted = false;
558
559
  jsonPromptInjection;
559
560
  providerOptions;
561
+ logger;
560
562
  constructor(options) {
561
563
  if (!options.schema) {
562
- throw new chunkHWMMIRIF_cjs.MastraError({
564
+ throw new chunk4U7ZLI36_cjs.MastraError({
563
565
  id: "STRUCTURED_OUTPUT_PROCESSOR_SCHEMA_REQUIRED",
564
566
  domain: "AGENT" /* AGENT */,
565
567
  category: "USER" /* USER */,
@@ -567,7 +569,7 @@ var StructuredOutputProcessor = class {
567
569
  });
568
570
  }
569
571
  if (!options.model) {
570
- throw new chunkHWMMIRIF_cjs.MastraError({
572
+ throw new chunk4U7ZLI36_cjs.MastraError({
571
573
  id: "STRUCTURED_OUTPUT_PROCESSOR_MODEL_REQUIRED",
572
574
  domain: "AGENT" /* AGENT */,
573
575
  category: "USER" /* USER */,
@@ -579,6 +581,7 @@ var StructuredOutputProcessor = class {
579
581
  this.fallbackValue = options.fallbackValue;
580
582
  this.jsonPromptInjection = options.jsonPromptInjection;
581
583
  this.providerOptions = options.providerOptions;
584
+ this.logger = options.logger;
582
585
  this.structuringAgent = new Agent({
583
586
  id: "structured-output-structurer",
584
587
  name: "structured-output-structurer",
@@ -744,14 +747,14 @@ The input text may be in any format (sentences, bullet points, paragraphs, etc.)
744
747
  const message = `[StructuredOutputProcessor] ${context}: ${error}`;
745
748
  switch (this.errorStrategy) {
746
749
  case "strict":
747
- console.error(message);
750
+ this.logger?.error(message);
748
751
  abort(message);
749
752
  break;
750
753
  case "warn":
751
- console.warn(message);
754
+ this.logger?.warn(message);
752
755
  break;
753
756
  case "fallback":
754
- console.info(`${message} (using fallback)`);
757
+ this.logger?.info(`${message} (using fallback)`);
755
758
  break;
756
759
  }
757
760
  }
@@ -764,7 +767,7 @@ var isSupportedLanguageModel = (model) => {
764
767
  };
765
768
  async function tryGenerateWithJsonFallback(agent, prompt, options) {
766
769
  if (!options.structuredOutput?.schema) {
767
- throw new chunkHWMMIRIF_cjs.MastraError({
770
+ throw new chunk4U7ZLI36_cjs.MastraError({
768
771
  id: "STRUCTURED_OUTPUT_OPTIONS_REQUIRED",
769
772
  domain: "AGENT" /* AGENT */,
770
773
  category: "USER" /* USER */,
@@ -783,7 +786,7 @@ async function tryGenerateWithJsonFallback(agent, prompt, options) {
783
786
  }
784
787
  async function tryStreamWithJsonFallback(agent, prompt, options) {
785
788
  if (!options.structuredOutput?.schema) {
786
- throw new chunkHWMMIRIF_cjs.MastraError({
789
+ throw new chunk4U7ZLI36_cjs.MastraError({
787
790
  id: "STRUCTURED_OUTPUT_OPTIONS_REQUIRED",
788
791
  domain: "AGENT" /* AGENT */,
789
792
  category: "USER" /* USER */,
@@ -794,7 +797,7 @@ async function tryStreamWithJsonFallback(agent, prompt, options) {
794
797
  const result = await agent.stream(prompt, options);
795
798
  const object = await result.object;
796
799
  if (!object) {
797
- throw new chunkHWMMIRIF_cjs.MastraError({
800
+ throw new chunk4U7ZLI36_cjs.MastraError({
798
801
  id: "STRUCTURED_OUTPUT_OBJECT_UNDEFINED",
799
802
  domain: "AGENT" /* AGENT */,
800
803
  category: "USER" /* USER */,
@@ -833,8 +836,9 @@ var ProcessorState = class {
833
836
  this.span = parentSpan?.createChildSpan({
834
837
  type: "processor_run" /* PROCESSOR_RUN */,
835
838
  name: `output processor: ${processorName}`,
839
+ entityType: "output_processor" /* OUTPUT_PROCESSOR */,
840
+ entityName: processorName,
836
841
  attributes: {
837
- processorName,
838
842
  processorType: "output",
839
843
  processorIndex: processorIndex ?? 0
840
844
  },
@@ -900,7 +904,7 @@ var ProcessorRunner = class _ProcessorRunner {
900
904
  );
901
905
  }
902
906
  if (result.status !== "success") {
903
- throw new chunkHWMMIRIF_cjs.MastraError({
907
+ throw new chunk4U7ZLI36_cjs.MastraError({
904
908
  category: "USER",
905
909
  domain: "AGENT",
906
910
  id: "PROCESSOR_WORKFLOW_FAILED",
@@ -912,7 +916,7 @@ var ProcessorRunner = class _ProcessorRunner {
912
916
  return input;
913
917
  }
914
918
  if (!("phase" in output) || !("messages" in output || "part" in output || "messageList" in output)) {
915
- throw new chunkHWMMIRIF_cjs.MastraError({
919
+ throw new chunk4U7ZLI36_cjs.MastraError({
916
920
  category: "USER",
917
921
  domain: "AGENT",
918
922
  id: "PROCESSOR_WORKFLOW_INVALID_OUTPUT",
@@ -933,8 +937,10 @@ var ProcessorRunner = class _ProcessorRunner {
933
937
  const processorSpan2 = parentSpan2?.createChildSpan({
934
938
  type: "processor_run" /* PROCESSOR_RUN */,
935
939
  name: `output processor workflow: ${processorOrWorkflow.id}`,
940
+ entityType: "output_processor" /* OUTPUT_PROCESSOR */,
941
+ entityId: processorOrWorkflow.id,
942
+ entityName: processorOrWorkflow.name,
936
943
  attributes: {
937
- processorName: processorOrWorkflow.id,
938
944
  processorType: "output",
939
945
  processorIndex: index
940
946
  },
@@ -975,8 +981,10 @@ var ProcessorRunner = class _ProcessorRunner {
975
981
  const processorSpan = parentSpan?.createChildSpan({
976
982
  type: "processor_run" /* PROCESSOR_RUN */,
977
983
  name: `output processor: ${processor.id}`,
984
+ entityType: "output_processor" /* OUTPUT_PROCESSOR */,
985
+ entityId: processor.id,
986
+ entityName: processor.name,
978
987
  attributes: {
979
- processorName: processor.name ?? processor.id,
980
988
  processorType: "output",
981
989
  processorIndex: index
982
990
  },
@@ -992,9 +1000,9 @@ var ProcessorRunner = class _ProcessorRunner {
992
1000
  retryCount
993
1001
  });
994
1002
  const mutations = messageList.stopRecording();
995
- if (result instanceof chunk72E3YF6A_cjs.MessageList) {
1003
+ if (result instanceof chunkEMLEZXTQ_cjs.MessageList) {
996
1004
  if (result !== messageList) {
997
- throw new chunkHWMMIRIF_cjs.MastraError({
1005
+ throw new chunk4U7ZLI36_cjs.MastraError({
998
1006
  category: "USER",
999
1007
  domain: "AGENT",
1000
1008
  id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
@@ -1211,8 +1219,10 @@ var ProcessorRunner = class _ProcessorRunner {
1211
1219
  const processorSpan2 = parentSpan2?.createChildSpan({
1212
1220
  type: "processor_run" /* PROCESSOR_RUN */,
1213
1221
  name: `input processor workflow: ${processorOrWorkflow.id}`,
1222
+ entityType: "input_processor" /* INPUT_PROCESSOR */,
1223
+ entityId: processorOrWorkflow.id,
1224
+ entityName: processorOrWorkflow.name,
1214
1225
  attributes: {
1215
- processorName: processorOrWorkflow.id,
1216
1226
  processorType: "input",
1217
1227
  processorIndex: index
1218
1228
  },
@@ -1255,8 +1265,10 @@ var ProcessorRunner = class _ProcessorRunner {
1255
1265
  const processorSpan = parentSpan?.createChildSpan({
1256
1266
  type: "processor_run" /* PROCESSOR_RUN */,
1257
1267
  name: `input processor: ${processor.id}`,
1268
+ entityType: "input_processor" /* INPUT_PROCESSOR */,
1269
+ entityId: processor.id,
1270
+ entityName: processor.name,
1258
1271
  attributes: {
1259
- processorName: processor.name ?? processor.id,
1260
1272
  processorType: "input",
1261
1273
  processorIndex: index
1262
1274
  },
@@ -1274,9 +1286,9 @@ var ProcessorRunner = class _ProcessorRunner {
1274
1286
  retryCount
1275
1287
  });
1276
1288
  let mutations;
1277
- if (result instanceof chunk72E3YF6A_cjs.MessageList) {
1289
+ if (result instanceof chunkEMLEZXTQ_cjs.MessageList) {
1278
1290
  if (result !== messageList) {
1279
- throw new chunkHWMMIRIF_cjs.MastraError({
1291
+ throw new chunk4U7ZLI36_cjs.MastraError({
1280
1292
  category: "USER",
1281
1293
  domain: "AGENT",
1282
1294
  id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
@@ -1379,8 +1391,10 @@ var ProcessorRunner = class _ProcessorRunner {
1379
1391
  const processorSpan2 = parentSpan?.createChildSpan({
1380
1392
  type: "processor_run" /* PROCESSOR_RUN */,
1381
1393
  name: `input step processor workflow: ${processorOrWorkflow.id}`,
1394
+ entityType: "input_processor" /* INPUT_PROCESSOR */,
1395
+ entityId: processorOrWorkflow.id,
1396
+ entityName: processorOrWorkflow.name,
1382
1397
  attributes: {
1383
- processorName: processorOrWorkflow.id,
1384
1398
  processorType: "input",
1385
1399
  processorIndex: index
1386
1400
  },
@@ -1439,8 +1453,10 @@ var ProcessorRunner = class _ProcessorRunner {
1439
1453
  const processorSpan = currentSpan?.createChildSpan({
1440
1454
  type: "processor_run" /* PROCESSOR_RUN */,
1441
1455
  name: `input step processor: ${processor.id}`,
1456
+ entityType: "input_processor" /* INPUT_PROCESSOR */,
1457
+ entityId: processor.id,
1458
+ entityName: processor.name,
1442
1459
  attributes: {
1443
- processorName: processor.name ?? processor.id,
1444
1460
  processorType: "input",
1445
1461
  processorIndex: index
1446
1462
  },
@@ -1533,6 +1549,7 @@ var ProcessorRunner = class _ProcessorRunner {
1533
1549
  */
1534
1550
  async runProcessOutputStep(args) {
1535
1551
  const {
1552
+ steps,
1536
1553
  messageList,
1537
1554
  stepNumber,
1538
1555
  finishReason,
@@ -1552,8 +1569,10 @@ var ProcessorRunner = class _ProcessorRunner {
1552
1569
  const processorSpan2 = parentSpan2?.createChildSpan({
1553
1570
  type: "processor_run" /* PROCESSOR_RUN */,
1554
1571
  name: `output step processor workflow: ${processorOrWorkflow.id}`,
1572
+ entityType: "output_processor" /* OUTPUT_PROCESSOR */,
1573
+ entityId: processorOrWorkflow.id,
1574
+ entityName: processorOrWorkflow.name,
1555
1575
  attributes: {
1556
- processorName: processorOrWorkflow.id,
1557
1576
  processorType: "output",
1558
1577
  processorIndex: index
1559
1578
  },
@@ -1572,6 +1591,7 @@ var ProcessorRunner = class _ProcessorRunner {
1572
1591
  toolCalls,
1573
1592
  text,
1574
1593
  systemMessages: currentSystemMessages2,
1594
+ steps,
1575
1595
  retryCount
1576
1596
  },
1577
1597
  tracingContext,
@@ -1600,8 +1620,10 @@ var ProcessorRunner = class _ProcessorRunner {
1600
1620
  const processorSpan = parentSpan?.createChildSpan({
1601
1621
  type: "processor_run" /* PROCESSOR_RUN */,
1602
1622
  name: `output step processor: ${processor.id}`,
1623
+ entityType: "output_processor" /* OUTPUT_PROCESSOR */,
1624
+ entityId: processor.id,
1625
+ entityName: processor.name,
1603
1626
  attributes: {
1604
- processorName: processor.name ?? processor.id,
1605
1627
  processorType: "output",
1606
1628
  processorIndex: index
1607
1629
  },
@@ -1618,15 +1640,16 @@ var ProcessorRunner = class _ProcessorRunner {
1618
1640
  toolCalls,
1619
1641
  text,
1620
1642
  systemMessages: currentSystemMessages,
1643
+ steps,
1621
1644
  abort,
1622
1645
  tracingContext: { currentSpan: processorSpan },
1623
1646
  requestContext,
1624
1647
  retryCount
1625
1648
  });
1626
1649
  const mutations = messageList.stopRecording();
1627
- if (result instanceof chunk72E3YF6A_cjs.MessageList) {
1650
+ if (result instanceof chunkEMLEZXTQ_cjs.MessageList) {
1628
1651
  if (result !== messageList) {
1629
- throw new chunkHWMMIRIF_cjs.MastraError({
1652
+ throw new chunk4U7ZLI36_cjs.MastraError({
1630
1653
  category: "USER",
1631
1654
  domain: "AGENT",
1632
1655
  id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
@@ -1694,9 +1717,9 @@ var ProcessorRunner = class _ProcessorRunner {
1694
1717
  processor,
1695
1718
  stepNumber
1696
1719
  }) {
1697
- if (result instanceof chunk72E3YF6A_cjs.MessageList) {
1720
+ if (result instanceof chunkEMLEZXTQ_cjs.MessageList) {
1698
1721
  if (result !== messageList) {
1699
- throw new chunkHWMMIRIF_cjs.MastraError({
1722
+ throw new chunk4U7ZLI36_cjs.MastraError({
1700
1723
  category: "USER",
1701
1724
  domain: "AGENT",
1702
1725
  id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
@@ -1712,7 +1735,7 @@ var ProcessorRunner = class _ProcessorRunner {
1712
1735
  };
1713
1736
  } else if (result) {
1714
1737
  if (result.messageList && result.messageList !== messageList) {
1715
- throw new chunkHWMMIRIF_cjs.MastraError({
1738
+ throw new chunk4U7ZLI36_cjs.MastraError({
1716
1739
  category: "USER",
1717
1740
  domain: "AGENT",
1718
1741
  id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
@@ -1720,7 +1743,7 @@ var ProcessorRunner = class _ProcessorRunner {
1720
1743
  });
1721
1744
  }
1722
1745
  if (result.messages && result.messageList) {
1723
- throw new chunkHWMMIRIF_cjs.MastraError({
1746
+ throw new chunk4U7ZLI36_cjs.MastraError({
1724
1747
  category: "USER",
1725
1748
  domain: "AGENT",
1726
1749
  id: "PROCESSOR_RETURNED_MESSAGES_AND_MESSAGE_LIST",
@@ -1729,10 +1752,10 @@ var ProcessorRunner = class _ProcessorRunner {
1729
1752
  }
1730
1753
  const { model: _model, ...rest } = result;
1731
1754
  if (result.model) {
1732
- const resolvedModel = await chunk53SZJCBX_cjs.resolveModelConfig(result.model);
1755
+ const resolvedModel = await chunk4KVIXN7K_cjs.resolveModelConfig(result.model);
1733
1756
  const isSupported = isSupportedLanguageModel(resolvedModel);
1734
1757
  if (!isSupported) {
1735
- throw new chunkHWMMIRIF_cjs.MastraError({
1758
+ throw new chunk4U7ZLI36_cjs.MastraError({
1736
1759
  category: "USER",
1737
1760
  domain: "AGENT",
1738
1761
  id: "PROCESSOR_RETURNED_UNSUPPORTED_MODEL",
@@ -1932,7 +1955,7 @@ function convertFullStreamChunkToMastra(value, ctx) {
1932
1955
  from: "AGENT" /* AGENT */,
1933
1956
  payload: {
1934
1957
  stepResult: {
1935
- reason: value.finishReason
1958
+ reason: normalizeFinishReason(value.finishReason)
1936
1959
  },
1937
1960
  output: {
1938
1961
  // Normalize usage to handle both V2 (flat) and V3 (nested) formats
@@ -2040,7 +2063,7 @@ function convertMastraChunkToAISDKv5({
2040
2063
  if (mode === "generate") {
2041
2064
  return {
2042
2065
  type: "file",
2043
- file: new chunk72E3YF6A_cjs.DefaultGeneratedFile({
2066
+ file: new chunkEMLEZXTQ_cjs.DefaultGeneratedFile({
2044
2067
  data: chunk.payload.data,
2045
2068
  mediaType: chunk.payload.mimeType
2046
2069
  })
@@ -2048,7 +2071,7 @@ function convertMastraChunkToAISDKv5({
2048
2071
  }
2049
2072
  return {
2050
2073
  type: "file",
2051
- file: new chunk72E3YF6A_cjs.DefaultGeneratedFileWithType({
2074
+ file: new chunkEMLEZXTQ_cjs.DefaultGeneratedFileWithType({
2052
2075
  data: chunk.payload.data,
2053
2076
  mediaType: chunk.payload.mimeType
2054
2077
  })
@@ -2200,6 +2223,21 @@ function normalizeUsage(usage) {
2200
2223
  raw: usage
2201
2224
  };
2202
2225
  }
2226
+ function isV3FinishReason(finishReason) {
2227
+ return typeof finishReason === "object" && finishReason !== null && "unified" in finishReason;
2228
+ }
2229
+ function normalizeFinishReason(finishReason) {
2230
+ if (!finishReason) {
2231
+ return "other";
2232
+ }
2233
+ if (finishReason === "tripwire" || finishReason === "retry") {
2234
+ return finishReason;
2235
+ }
2236
+ if (isV3FinishReason(finishReason)) {
2237
+ return finishReason.unified;
2238
+ }
2239
+ return finishReason === "unknown" ? "other" : finishReason;
2240
+ }
2203
2241
 
2204
2242
  // src/stream/aisdk/v5/output.ts
2205
2243
  var AISDKV5OutputStream = class {
@@ -2449,7 +2487,6 @@ var AISDKV5OutputStream = class {
2449
2487
  async getFullOutput() {
2450
2488
  await this.consumeStream({
2451
2489
  onError: (error) => {
2452
- console.error(error);
2453
2490
  throw error;
2454
2491
  }
2455
2492
  });
@@ -2641,7 +2678,7 @@ var BaseFormatHandler = class {
2641
2678
  } else {
2642
2679
  return {
2643
2680
  success: false,
2644
- error: new chunkHWMMIRIF_cjs.MastraError(
2681
+ error: new chunk4U7ZLI36_cjs.MastraError(
2645
2682
  {
2646
2683
  domain: "AGENT" /* AGENT */,
2647
2684
  category: "SYSTEM" /* SYSTEM */,
@@ -3528,7 +3565,7 @@ var MastraModelOutput = class extends chunkDGV2FWB4_cjs.MastraBase {
3528
3565
  );
3529
3566
  const responseMessages = self.messageList.get.response.aiV4.core();
3530
3567
  const lastResponseMessage = responseMessages[responseMessages.length - 1];
3531
- const outputText = lastResponseMessage ? chunk72E3YF6A_cjs.MessageList.coreContentToString(lastResponseMessage.content) : "";
3568
+ const outputText = lastResponseMessage ? chunkEMLEZXTQ_cjs.MessageList.coreContentToString(lastResponseMessage.content) : "";
3532
3569
  if (lastStep && outputText && outputText !== originalText) {
3533
3570
  lastStep.text = outputText;
3534
3571
  }
@@ -3563,7 +3600,7 @@ var MastraModelOutput = class extends chunkDGV2FWB4_cjs.MastraBase {
3563
3600
  text: ""
3564
3601
  });
3565
3602
  } else {
3566
- self.#error = chunkHWMMIRIF_cjs.getErrorFromUnknown(error2, {
3603
+ self.#error = chunk4U7ZLI36_cjs.getErrorFromUnknown(error2, {
3567
3604
  fallbackMessage: "Unknown error in stream"
3568
3605
  });
3569
3606
  self.resolvePromises({
@@ -3640,7 +3677,7 @@ var MastraModelOutput = class extends chunkDGV2FWB4_cjs.MastraBase {
3640
3677
  }
3641
3678
  break;
3642
3679
  case "error":
3643
- const error = chunkHWMMIRIF_cjs.getErrorFromUnknown(chunk.payload.error, {
3680
+ const error = chunk4U7ZLI36_cjs.getErrorFromUnknown(chunk.payload.error, {
3644
3681
  fallbackMessage: "Unknown error chunk in stream"
3645
3682
  });
3646
3683
  self.#error = error;
@@ -3707,7 +3744,7 @@ var MastraModelOutput = class extends chunkDGV2FWB4_cjs.MastraBase {
3707
3744
  }
3708
3745
  resolvePromise(key, value) {
3709
3746
  if (!(key in this.#delayedPromises)) {
3710
- throw new chunkHWMMIRIF_cjs.MastraError({
3747
+ throw new chunk4U7ZLI36_cjs.MastraError({
3711
3748
  id: "MASTRA_MODEL_OUTPUT_INVALID_PROMISE_KEY",
3712
3749
  domain: "LLM" /* LLM */,
3713
3750
  category: "SYSTEM" /* SYSTEM */,
@@ -3866,7 +3903,8 @@ var MastraModelOutput = class extends chunkDGV2FWB4_cjs.MastraBase {
3866
3903
  try {
3867
3904
  await consumeStream({
3868
3905
  stream: this.#baseStream,
3869
- onError: options?.onError
3906
+ onError: options?.onError,
3907
+ logger: this.logger
3870
3908
  });
3871
3909
  } catch (error) {
3872
3910
  options?.onError?.(error);
@@ -3878,7 +3916,7 @@ var MastraModelOutput = class extends chunkDGV2FWB4_cjs.MastraBase {
3878
3916
  async getFullOutput() {
3879
3917
  await this.consumeStream({
3880
3918
  onError: (error) => {
3881
- console.error(error);
3919
+ this.logger.error("Error consuming stream", error);
3882
3920
  throw error;
3883
3921
  }
3884
3922
  });
@@ -4372,6 +4410,8 @@ var WorkflowRunOutput = class {
4372
4410
  } else {
4373
4411
  self.#status = "failed";
4374
4412
  }
4413
+ } else if (chunk.type === "workflow-paused") {
4414
+ self.#status = "paused";
4375
4415
  }
4376
4416
  },
4377
4417
  close() {
@@ -4507,6 +4547,8 @@ var WorkflowRunOutput = class {
4507
4547
  } else {
4508
4548
  self.#status = "failed";
4509
4549
  }
4550
+ } else if (chunk.type === "workflow-paused") {
4551
+ self.#status = "paused";
4510
4552
  }
4511
4553
  },
4512
4554
  close() {
@@ -5091,7 +5133,7 @@ async function validateStepInput({
5091
5133
  if (!validatedInput.success) {
5092
5134
  const errors = getZodErrors(validatedInput.error);
5093
5135
  const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
5094
- validationError = new chunkHWMMIRIF_cjs.MastraError(
5136
+ validationError = new chunk4U7ZLI36_cjs.MastraError(
5095
5137
  {
5096
5138
  id: "WORKFLOW_STEP_INPUT_VALIDATION_FAILED",
5097
5139
  domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
@@ -5119,7 +5161,7 @@ async function validateStepResumeData({ resumeData, step }) {
5119
5161
  if (!validatedResumeData.success) {
5120
5162
  const errors = getZodErrors(validatedResumeData.error);
5121
5163
  const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
5122
- validationError = new chunkHWMMIRIF_cjs.MastraError(
5164
+ validationError = new chunk4U7ZLI36_cjs.MastraError(
5123
5165
  {
5124
5166
  id: "WORKFLOW_STEP_RESUME_DATA_VALIDATION_FAILED",
5125
5167
  domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
@@ -5150,7 +5192,7 @@ async function validateStepSuspendData({
5150
5192
  if (!validatedSuspendData.success) {
5151
5193
  const errors = getZodErrors(validatedSuspendData.error);
5152
5194
  const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
5153
- validationError = new chunkHWMMIRIF_cjs.MastraError(
5195
+ validationError = new chunk4U7ZLI36_cjs.MastraError(
5154
5196
  {
5155
5197
  id: "WORKFLOW_STEP_SUSPEND_DATA_VALIDATION_FAILED",
5156
5198
  domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
@@ -5231,7 +5273,7 @@ var getStepIds = (entry) => {
5231
5273
  return [];
5232
5274
  };
5233
5275
  var createTimeTravelExecutionParams = (params) => {
5234
- const { steps, inputData, resumeData, context, nestedStepsContext, snapshot, initialState, graph } = params;
5276
+ const { steps, inputData, resumeData, context, nestedStepsContext, snapshot, initialState, graph, perStep } = params;
5235
5277
  const firstStepId = steps[0];
5236
5278
  let executionPath = [];
5237
5279
  const stepResults = {};
@@ -5298,11 +5340,12 @@ var createTimeTravelExecutionParams = (params) => {
5298
5340
  suspendedAt: stepContext?.suspendedAt,
5299
5341
  resumedAt: stepContext?.resumedAt
5300
5342
  };
5301
- if (currentExecPathLength > 0 && (!snapshotContext[stepId] || snapshotContext[stepId] && snapshotContext[stepId].status !== "suspended")) {
5343
+ const execPathLengthToUse = perStep ? executionPath.length : currentExecPathLength;
5344
+ if (execPathLengthToUse > 0 && !steps?.includes(stepId) && !context?.[stepId] && (!snapshotContext[stepId] || snapshotContext[stepId] && snapshotContext[stepId].status !== "suspended")) {
5302
5345
  result = void 0;
5303
5346
  }
5304
5347
  if (result) {
5305
- const formattedResult = chunkO3ULBGV6_cjs.removeUndefinedValues(result);
5348
+ const formattedResult = chunkAQ22JIR7_cjs.removeUndefinedValues(result);
5306
5349
  stepResults[stepId] = formattedResult;
5307
5350
  }
5308
5351
  });
@@ -5327,7 +5370,7 @@ function hydrateSerializedStepErrors(steps) {
5327
5370
  if (steps) {
5328
5371
  for (const step of Object.values(steps)) {
5329
5372
  if (step.status === "failed" && "error" in step && step.error) {
5330
- step.error = chunkHWMMIRIF_cjs.getErrorFromUnknown(step.error, { serializeStack: false });
5373
+ step.error = chunk4U7ZLI36_cjs.getErrorFromUnknown(step.error, { serializeStack: false });
5331
5374
  }
5332
5375
  }
5333
5376
  }
@@ -5353,7 +5396,8 @@ async function executeParallel(engine, params) {
5353
5396
  abortController,
5354
5397
  requestContext,
5355
5398
  outputWriter,
5356
- disableScorers
5399
+ disableScorers,
5400
+ perStep
5357
5401
  } = params;
5358
5402
  const parallelSpan = tracingContext.currentSpan?.createChildSpan({
5359
5403
  type: "workflow_parallel" /* WORKFLOW_PARALLEL */,
@@ -5375,7 +5419,7 @@ async function executeParallel(engine, params) {
5375
5419
  makeStepRunning = timeTravel.steps[0] === step.step.id;
5376
5420
  }
5377
5421
  if (!makeStepRunning) {
5378
- continue;
5422
+ break;
5379
5423
  }
5380
5424
  const startTime = resume?.steps[0] === step.step.id ? void 0 : Date.now();
5381
5425
  const resumeTime = resume?.steps[0] === step.step.id ? Date.now() : void 0;
@@ -5387,6 +5431,9 @@ async function executeParallel(engine, params) {
5387
5431
  ...resumeTime ? { resumedAt: resumeTime } : {}
5388
5432
  };
5389
5433
  executionContext.activeStepsPath[step.step.id] = [...executionContext.executionPath, stepIndex];
5434
+ if (perStep) {
5435
+ break;
5436
+ }
5390
5437
  }
5391
5438
  if (timeTravel && timeTravel.executionPath.length > 0) {
5392
5439
  timeTravel.executionPath.shift();
@@ -5398,6 +5445,9 @@ async function executeParallel(engine, params) {
5398
5445
  if (currStepResult && currStepResult.status !== "running") {
5399
5446
  return currStepResult;
5400
5447
  }
5448
+ if (!currStepResult && (perStep || timeTravel)) {
5449
+ return {};
5450
+ }
5401
5451
  const stepExecResult = await engine.executeStep({
5402
5452
  workflowId,
5403
5453
  runId,
@@ -5426,7 +5476,8 @@ async function executeParallel(engine, params) {
5426
5476
  abortController,
5427
5477
  requestContext,
5428
5478
  outputWriter,
5429
- disableScorers
5479
+ disableScorers,
5480
+ perStep
5430
5481
  });
5431
5482
  engine.applyMutableContext(executionContext, stepExecResult.mutableContext);
5432
5483
  Object.assign(stepResults, stepExecResult.stepResults);
@@ -5487,7 +5538,8 @@ async function executeConditional(engine, params) {
5487
5538
  abortController,
5488
5539
  requestContext,
5489
5540
  outputWriter,
5490
- disableScorers
5541
+ disableScorers,
5542
+ perStep
5491
5543
  } = params;
5492
5544
  const conditionalSpan = tracingContext.currentSpan?.createChildSpan({
5493
5545
  type: "workflow_conditional" /* WORKFLOW_CONDITIONAL */,
@@ -5560,8 +5612,8 @@ async function executeConditional(engine, params) {
5560
5612
  });
5561
5613
  return result;
5562
5614
  } catch (e) {
5563
- const errorInstance = chunkHWMMIRIF_cjs.getErrorFromUnknown(e, { serializeStack: false });
5564
- const mastraError = new chunkHWMMIRIF_cjs.MastraError(
5615
+ const errorInstance = chunk4U7ZLI36_cjs.getErrorFromUnknown(e, { serializeStack: false });
5616
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError(
5565
5617
  {
5566
5618
  id: "WORKFLOW_CONDITION_EVALUATION_FAILED",
5567
5619
  domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
@@ -5582,7 +5634,18 @@ async function executeConditional(engine, params) {
5582
5634
  }
5583
5635
  })
5584
5636
  )).filter((index) => index !== null);
5585
- const stepsToRun = entry.steps.filter((_, index) => truthyIndexes.includes(index));
5637
+ let stepsToRun = entry.steps.filter((_, index) => truthyIndexes.includes(index));
5638
+ if (perStep || timeTravel && timeTravel.executionPath.length > 0) {
5639
+ const possibleStepsToRun = stepsToRun.filter((s) => {
5640
+ const currStepResult = stepResults[s.step.id];
5641
+ if (timeTravel && timeTravel.executionPath.length > 0) {
5642
+ return timeTravel.steps[0] === s.step.id;
5643
+ }
5644
+ return !currStepResult;
5645
+ });
5646
+ const possibleStepToRun = possibleStepsToRun?.[0];
5647
+ stepsToRun = possibleStepToRun ? [possibleStepToRun] : stepsToRun;
5648
+ }
5586
5649
  conditionalSpan?.update({
5587
5650
  attributes: {
5588
5651
  truthyIndexes,
@@ -5629,7 +5692,8 @@ async function executeConditional(engine, params) {
5629
5692
  abortController,
5630
5693
  requestContext,
5631
5694
  outputWriter,
5632
- disableScorers
5695
+ disableScorers,
5696
+ perStep
5633
5697
  });
5634
5698
  engine.applyMutableContext(executionContext, stepExecResult.mutableContext);
5635
5699
  Object.assign(stepResults, stepExecResult.stepResults);
@@ -5691,7 +5755,8 @@ async function executeLoop(engine, params) {
5691
5755
  requestContext,
5692
5756
  outputWriter,
5693
5757
  disableScorers,
5694
- serializedStepGraph
5758
+ serializedStepGraph,
5759
+ perStep
5695
5760
  } = params;
5696
5761
  const { step, condition } = entry;
5697
5762
  const loopSpan = tracingContext.currentSpan?.createChildSpan({
@@ -5732,7 +5797,8 @@ async function executeLoop(engine, params) {
5732
5797
  outputWriter,
5733
5798
  disableScorers,
5734
5799
  serializedStepGraph,
5735
- iterationCount: iteration + 1
5800
+ iterationCount: iteration + 1,
5801
+ perStep
5736
5802
  });
5737
5803
  engine.applyMutableContext(executionContext, stepExecResult.mutableContext);
5738
5804
  Object.assign(stepResults, stepExecResult.stepResults);
@@ -5753,7 +5819,7 @@ async function executeLoop(engine, params) {
5753
5819
  const evalSpan = loopSpan?.createChildSpan({
5754
5820
  type: "workflow_conditional_eval" /* WORKFLOW_CONDITIONAL_EVAL */,
5755
5821
  name: `condition: '${entry.loopType}'`,
5756
- input: chunkO3ULBGV6_cjs.selectFields(result.output, ["stepResult", "output.text", "output.object", "messages"]),
5822
+ input: chunkAQ22JIR7_cjs.selectFields(result.output, ["stepResult", "output.text", "output.object", "messages"]),
5757
5823
  attributes: {
5758
5824
  conditionIndex: iteration
5759
5825
  },
@@ -5832,7 +5898,8 @@ async function executeForeach(engine, params) {
5832
5898
  requestContext,
5833
5899
  outputWriter,
5834
5900
  disableScorers,
5835
- serializedStepGraph
5901
+ serializedStepGraph,
5902
+ perStep
5836
5903
  } = params;
5837
5904
  const { step, opts } = entry;
5838
5905
  const results = [];
@@ -5909,7 +5976,8 @@ async function executeForeach(engine, params) {
5909
5976
  skipEmits: true,
5910
5977
  outputWriter,
5911
5978
  disableScorers,
5912
- serializedStepGraph
5979
+ serializedStepGraph,
5980
+ perStep
5913
5981
  });
5914
5982
  engine.applyMutableContext(executionContext, stepExecResult.mutableContext);
5915
5983
  Object.assign(stepResults, stepExecResult.stepResults);
@@ -6051,7 +6119,8 @@ async function persistStepUpdate(engine, params) {
6051
6119
  requestContext.forEach((value, key) => {
6052
6120
  requestContextObj[key] = value;
6053
6121
  });
6054
- await engine.mastra?.getStorage()?.persistWorkflowSnapshot({
6122
+ const workflowsStore = await engine.mastra?.getStorage()?.getStore("workflows");
6123
+ await workflowsStore?.persistWorkflowSnapshot({
6055
6124
  workflowName: workflowId,
6056
6125
  runId,
6057
6126
  resourceId,
@@ -6093,7 +6162,8 @@ async function executeEntry(engine, params) {
6093
6162
  abortController,
6094
6163
  requestContext,
6095
6164
  outputWriter,
6096
- disableScorers
6165
+ disableScorers,
6166
+ perStep
6097
6167
  } = params;
6098
6168
  const prevOutput = engine.getStepOutput(stepResults, prevStep);
6099
6169
  let execResults;
@@ -6117,7 +6187,8 @@ async function executeEntry(engine, params) {
6117
6187
  requestContext,
6118
6188
  outputWriter,
6119
6189
  disableScorers,
6120
- serializedStepGraph
6190
+ serializedStepGraph,
6191
+ perStep
6121
6192
  });
6122
6193
  execResults = stepExecResult.result;
6123
6194
  engine.applyMutableContext(executionContext, stepExecResult.mutableContext);
@@ -6149,7 +6220,8 @@ async function executeEntry(engine, params) {
6149
6220
  abortController,
6150
6221
  requestContext,
6151
6222
  outputWriter,
6152
- disableScorers
6223
+ disableScorers,
6224
+ perStep
6153
6225
  });
6154
6226
  engine.applyMutableContext(executionContext, resumedStepResult.mutableContext);
6155
6227
  Object.assign(stepResults, resumedStepResult.stepResults);
@@ -6219,7 +6291,8 @@ async function executeEntry(engine, params) {
6219
6291
  abortController,
6220
6292
  requestContext,
6221
6293
  outputWriter,
6222
- disableScorers
6294
+ disableScorers,
6295
+ perStep
6223
6296
  });
6224
6297
  } else if (entry.type === "conditional") {
6225
6298
  execResults = await engine.executeConditional({
@@ -6238,7 +6311,8 @@ async function executeEntry(engine, params) {
6238
6311
  abortController,
6239
6312
  requestContext,
6240
6313
  outputWriter,
6241
- disableScorers
6314
+ disableScorers,
6315
+ perStep
6242
6316
  });
6243
6317
  } else if (entry.type === "loop") {
6244
6318
  execResults = await engine.executeLoop({
@@ -6258,7 +6332,8 @@ async function executeEntry(engine, params) {
6258
6332
  requestContext,
6259
6333
  outputWriter,
6260
6334
  disableScorers,
6261
- serializedStepGraph
6335
+ serializedStepGraph,
6336
+ perStep
6262
6337
  });
6263
6338
  } else if (entry.type === "foreach") {
6264
6339
  execResults = await engine.executeForeach({
@@ -6278,7 +6353,8 @@ async function executeEntry(engine, params) {
6278
6353
  requestContext,
6279
6354
  outputWriter,
6280
6355
  disableScorers,
6281
- serializedStepGraph
6356
+ serializedStepGraph,
6357
+ perStep
6282
6358
  });
6283
6359
  } else if (entry.type === "sleep") {
6284
6360
  const startedAt = Date.now();
@@ -6690,7 +6766,8 @@ async function executeStep(engine, params) {
6690
6766
  disableScorers,
6691
6767
  serializedStepGraph,
6692
6768
  tracingContext,
6693
- iterationCount
6769
+ iterationCount,
6770
+ perStep
6694
6771
  } = params;
6695
6772
  const stepCallId = crypto2.randomUUID();
6696
6773
  const { inputData, validationError } = await validateStepInput({
@@ -6732,10 +6809,9 @@ async function executeStep(engine, params) {
6732
6809
  const stepSpan = tracingContext.currentSpan?.createChildSpan({
6733
6810
  name: `workflow step: '${step.id}'`,
6734
6811
  type: "workflow_step" /* WORKFLOW_STEP */,
6812
+ entityType: "workflow_step" /* WORKFLOW_STEP */,
6813
+ entityId: step.id,
6735
6814
  input: inputData,
6736
- attributes: {
6737
- stepId: step.id
6738
- },
6739
6815
  tracingPolicy: engine.options?.tracingPolicy
6740
6816
  });
6741
6817
  const operationId = `workflow.${workflowId}.run.${runId}.step.${step.id}.running_ev`;
@@ -6777,7 +6853,8 @@ async function executeStep(engine, params) {
6777
6853
  requestContext,
6778
6854
  tracingContext,
6779
6855
  outputWriter,
6780
- stepSpan
6856
+ stepSpan,
6857
+ perStep
6781
6858
  });
6782
6859
  if (workflowResult !== null) {
6783
6860
  const stepResult2 = { ...stepInfo, ...workflowResult };
@@ -6823,7 +6900,7 @@ async function executeStep(engine, params) {
6823
6900
  runId,
6824
6901
  resourceId,
6825
6902
  workflowId,
6826
- mastra: engine.mastra ? chunk72YCRTEX_cjs.wrapMastra(engine.mastra, { currentSpan: stepSpan }) : void 0,
6903
+ mastra: engine.mastra ? chunkZSZOYPSJ_cjs.wrapMastra(engine.mastra, { currentSpan: stepSpan }) : void 0,
6827
6904
  requestContext,
6828
6905
  inputData,
6829
6906
  state: executionContext.state,
@@ -6909,12 +6986,15 @@ async function executeStep(engine, params) {
6909
6986
  outputWriter,
6910
6987
  // Disable scorers must be explicitly set to false they are on by default
6911
6988
  scorers: disableScorers === false ? void 0 : step.scorers,
6912
- validateInputs: engine.options?.validateInputs
6989
+ validateInputs: engine.options?.validateInputs,
6990
+ perStep
6913
6991
  });
6914
6992
  if (engine.requiresDurableContextSerialization()) {
6915
6993
  contextMutations.requestContextUpdate = engine.serializeRequestContext(requestContext);
6916
6994
  }
6917
- return { output, suspended, bailed, contextMutations };
6995
+ const isNestedWorkflowStep = step.component === "WORKFLOW";
6996
+ const nestedWflowStepPaused = isNestedWorkflowStep && perStep;
6997
+ return { output, suspended, bailed, contextMutations, nestedWflowStepPaused };
6918
6998
  },
6919
6999
  { retries, delay: delay2, stepSpan, workflowId, runId }
6920
7000
  );
@@ -6953,6 +7033,8 @@ async function executeStep(engine, params) {
6953
7033
  };
6954
7034
  } else if (durableResult.bailed) {
6955
7035
  execResults = { status: "bailed", output: durableResult.bailed.payload, endedAt: Date.now() };
7036
+ } else if (durableResult.nestedWflowStepPaused) {
7037
+ execResults = { status: "paused" };
6956
7038
  } else {
6957
7039
  execResults = { status: "success", output: durableResult.output, endedAt: Date.now() };
6958
7040
  }
@@ -6998,8 +7080,8 @@ async function runScorersForStep(params) {
6998
7080
  requestContext
6999
7081
  });
7000
7082
  } catch (e) {
7001
- const errorInstance = chunkHWMMIRIF_cjs.getErrorFromUnknown(e, { serializeStack: false });
7002
- const mastraError = new chunkHWMMIRIF_cjs.MastraError(
7083
+ const errorInstance = chunk4U7ZLI36_cjs.getErrorFromUnknown(e, { serializeStack: false });
7084
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError(
7003
7085
  {
7004
7086
  id: "WORKFLOW_FAILED_TO_FETCH_SCORERS",
7005
7087
  domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
@@ -7217,11 +7299,11 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
7217
7299
  return { ok: true, result };
7218
7300
  } catch (e) {
7219
7301
  if (i === params.retries) {
7220
- const errorInstance = chunkHWMMIRIF_cjs.getErrorFromUnknown(e, {
7302
+ const errorInstance = chunk4U7ZLI36_cjs.getErrorFromUnknown(e, {
7221
7303
  serializeStack: false,
7222
7304
  fallbackMessage: "Unknown step execution error"
7223
7305
  });
7224
- const mastraError = new chunkHWMMIRIF_cjs.MastraError(
7306
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError(
7225
7307
  {
7226
7308
  id: "WORKFLOW_STEP_INVOKE_FAILED",
7227
7309
  domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
@@ -7263,7 +7345,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
7263
7345
  formatResultError(error, lastOutput) {
7264
7346
  const outputError = lastOutput?.error;
7265
7347
  const errorSource = error || outputError;
7266
- const errorInstance = chunkHWMMIRIF_cjs.getErrorFromUnknown(errorSource, {
7348
+ const errorInstance = chunk4U7ZLI36_cjs.getErrorFromUnknown(errorSource, {
7267
7349
  serializeStack: false,
7268
7350
  fallbackMessage: "Unknown workflow error"
7269
7351
  });
@@ -7376,13 +7458,14 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
7376
7458
  workflowSpan,
7377
7459
  disableScorers,
7378
7460
  restart,
7379
- timeTravel
7461
+ timeTravel,
7462
+ perStep
7380
7463
  } = params;
7381
7464
  const { attempts = 0, delay: delay2 = 0 } = retryConfig ?? {};
7382
7465
  const steps = graph.steps;
7383
7466
  this.retryCounts.clear();
7384
7467
  if (steps.length === 0) {
7385
- const empty_graph_error = new chunkHWMMIRIF_cjs.MastraError({
7468
+ const empty_graph_error = new chunk4U7ZLI36_cjs.MastraError({
7386
7469
  id: "WORKFLOW_EXECUTE_EMPTY_GRAPH",
7387
7470
  text: "Workflow must have at least one step",
7388
7471
  domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
@@ -7440,7 +7523,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
7440
7523
  pubsub: params.pubsub,
7441
7524
  requestContext: currentRequestContext,
7442
7525
  outputWriter: params.outputWriter,
7443
- disableScorers
7526
+ disableScorers,
7527
+ perStep
7444
7528
  });
7445
7529
  this.applyMutableContext(executionContext, lastOutput.mutableContext);
7446
7530
  lastState = lastOutput.mutableContext.state;
@@ -7479,13 +7563,47 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
7479
7563
  }
7480
7564
  });
7481
7565
  }
7482
- await this.invokeLifecycleCallbacks(result2);
7566
+ if (lastOutput.result.status !== "paused") {
7567
+ await this.invokeLifecycleCallbacks(result2);
7568
+ }
7569
+ if (lastOutput.result.status === "paused") {
7570
+ await params.pubsub.publish(`workflow.events.v2.${runId}`, {
7571
+ type: "watch",
7572
+ runId,
7573
+ data: { type: "workflow-paused", payload: {} }
7574
+ });
7575
+ }
7483
7576
  return {
7484
7577
  ...result2,
7485
7578
  ...lastOutput.result.status === "suspended" && params.outputOptions?.includeResumeLabels ? { resumeLabels: lastOutput.mutableContext.resumeLabels } : {},
7486
7579
  ...params.outputOptions?.includeState ? { state: lastState } : {}
7487
7580
  };
7488
7581
  }
7582
+ if (perStep) {
7583
+ const result2 = await this.fmtReturnValue(params.pubsub, stepResults, lastOutput.result);
7584
+ await this.persistStepUpdate({
7585
+ workflowId,
7586
+ runId,
7587
+ resourceId,
7588
+ stepResults: lastOutput.stepResults,
7589
+ serializedStepGraph: params.serializedStepGraph,
7590
+ executionContext: lastExecutionContext,
7591
+ workflowStatus: "paused",
7592
+ requestContext: currentRequestContext
7593
+ });
7594
+ await params.pubsub.publish(`workflow.events.v2.${runId}`, {
7595
+ type: "watch",
7596
+ runId,
7597
+ data: { type: "workflow-paused", payload: {} }
7598
+ });
7599
+ workflowSpan?.end({
7600
+ attributes: {
7601
+ status: "paused"
7602
+ }
7603
+ });
7604
+ delete result2.result;
7605
+ return { ...result2, status: "paused", ...params.outputOptions?.includeState ? { state: lastState } : {} };
7606
+ }
7489
7607
  }
7490
7608
  const result = await this.fmtReturnValue(params.pubsub, stepResults, lastOutput.result);
7491
7609
  await this.persistStepUpdate({
@@ -7694,7 +7812,7 @@ function createStep(params, agentOptions) {
7694
7812
  component: params.component
7695
7813
  };
7696
7814
  }
7697
- if (params instanceof chunkZ55SJVEC_cjs.Tool) {
7815
+ if (params instanceof chunk6YUHA5UH_cjs.Tool) {
7698
7816
  if (!params.inputSchema || !params.outputSchema) {
7699
7817
  throw new Error("Tool must have input and output schemas defined");
7700
7818
  }
@@ -7788,7 +7906,7 @@ function createStep(params, agentOptions) {
7788
7906
  phase,
7789
7907
  // Auto-create MessageList from messages if not provided
7790
7908
  // This enables running processor workflows from the UI where messageList can't be serialized
7791
- messageList: messageList ?? (Array.isArray(messages) ? new chunk72E3YF6A_cjs.MessageList().add(messages, "input").addSystem(systemMessages ?? []) : void 0),
7909
+ messageList: messageList ?? (Array.isArray(messages) ? new chunkEMLEZXTQ_cjs.MessageList().add(messages, "input").addSystem(systemMessages ?? []) : void 0),
7792
7910
  stepNumber,
7793
7911
  systemMessages,
7794
7912
  streamParts,
@@ -7811,7 +7929,7 @@ function createStep(params, agentOptions) {
7811
7929
  case "input": {
7812
7930
  if (processor.processInput) {
7813
7931
  if (!passThrough.messageList) {
7814
- throw new chunkHWMMIRIF_cjs.MastraError({
7932
+ throw new chunk4U7ZLI36_cjs.MastraError({
7815
7933
  category: "USER" /* USER */,
7816
7934
  domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
7817
7935
  id: "PROCESSOR_MISSING_MESSAGE_LIST",
@@ -7841,9 +7959,9 @@ function createStep(params, agentOptions) {
7841
7959
  }
7842
7960
  }
7843
7961
  };
7844
- if (result instanceof chunk72E3YF6A_cjs.MessageList) {
7962
+ if (result instanceof chunkEMLEZXTQ_cjs.MessageList) {
7845
7963
  if (result !== passThrough.messageList) {
7846
- throw new chunkHWMMIRIF_cjs.MastraError({
7964
+ throw new chunk4U7ZLI36_cjs.MastraError({
7847
7965
  category: "USER" /* USER */,
7848
7966
  domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
7849
7967
  id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
@@ -7875,7 +7993,7 @@ function createStep(params, agentOptions) {
7875
7993
  case "inputStep": {
7876
7994
  if (processor.processInputStep) {
7877
7995
  if (!passThrough.messageList) {
7878
- throw new chunkHWMMIRIF_cjs.MastraError({
7996
+ throw new chunk4U7ZLI36_cjs.MastraError({
7879
7997
  category: "USER" /* USER */,
7880
7998
  domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
7881
7999
  id: "PROCESSOR_MISSING_MESSAGE_LIST",
@@ -7937,7 +8055,7 @@ function createStep(params, agentOptions) {
7937
8055
  case "outputResult": {
7938
8056
  if (processor.processOutputResult) {
7939
8057
  if (!passThrough.messageList) {
7940
- throw new chunkHWMMIRIF_cjs.MastraError({
8058
+ throw new chunk4U7ZLI36_cjs.MastraError({
7941
8059
  category: "USER" /* USER */,
7942
8060
  domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
7943
8061
  id: "PROCESSOR_MISSING_MESSAGE_LIST",
@@ -7966,9 +8084,9 @@ function createStep(params, agentOptions) {
7966
8084
  }
7967
8085
  }
7968
8086
  };
7969
- if (result instanceof chunk72E3YF6A_cjs.MessageList) {
8087
+ if (result instanceof chunkEMLEZXTQ_cjs.MessageList) {
7970
8088
  if (result !== passThrough.messageList) {
7971
- throw new chunkHWMMIRIF_cjs.MastraError({
8089
+ throw new chunk4U7ZLI36_cjs.MastraError({
7972
8090
  category: "USER" /* USER */,
7973
8091
  domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
7974
8092
  id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
@@ -8000,7 +8118,7 @@ function createStep(params, agentOptions) {
8000
8118
  case "outputStep": {
8001
8119
  if (processor.processOutputStep) {
8002
8120
  if (!passThrough.messageList) {
8003
- throw new chunkHWMMIRIF_cjs.MastraError({
8121
+ throw new chunk4U7ZLI36_cjs.MastraError({
8004
8122
  category: "USER" /* USER */,
8005
8123
  domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
8006
8124
  id: "PROCESSOR_MISSING_MESSAGE_LIST",
@@ -8017,7 +8135,8 @@ function createStep(params, agentOptions) {
8017
8135
  finishReason,
8018
8136
  toolCalls,
8019
8137
  text,
8020
- systemMessages: systemMessages ?? []
8138
+ systemMessages: systemMessages ?? [],
8139
+ steps: steps ?? []
8021
8140
  });
8022
8141
  const applyMessages = (msgs) => {
8023
8142
  const deletedIds = idsBeforeProcessing.filter((i) => !msgs.some((m) => m.id === i));
@@ -8034,9 +8153,9 @@ function createStep(params, agentOptions) {
8034
8153
  }
8035
8154
  }
8036
8155
  };
8037
- if (result instanceof chunk72E3YF6A_cjs.MessageList) {
8156
+ if (result instanceof chunkEMLEZXTQ_cjs.MessageList) {
8038
8157
  if (result !== passThrough.messageList) {
8039
- throw new chunkHWMMIRIF_cjs.MastraError({
8158
+ throw new chunk4U7ZLI36_cjs.MastraError({
8040
8159
  category: "USER" /* USER */,
8041
8160
  domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
8042
8161
  id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
@@ -8101,7 +8220,7 @@ function cloneStep(step, opts) {
8101
8220
  };
8102
8221
  }
8103
8222
  function isProcessor(obj) {
8104
- return obj !== null && typeof obj === "object" && "id" in obj && typeof obj.id === "string" && !(obj instanceof Agent) && !(obj instanceof chunkZ55SJVEC_cjs.Tool) && (typeof obj.processInput === "function" || typeof obj.processInputStep === "function" || typeof obj.processOutputStream === "function" || typeof obj.processOutputResult === "function" || typeof obj.processOutputStep === "function");
8223
+ return obj !== null && typeof obj === "object" && "id" in obj && typeof obj.id === "string" && !(obj instanceof Agent) && !(obj instanceof chunk6YUHA5UH_cjs.Tool) && (typeof obj.processInput === "function" || typeof obj.processInputStep === "function" || typeof obj.processOutputStream === "function" || typeof obj.processOutputResult === "function" || typeof obj.processOutputStep === "function");
8105
8224
  }
8106
8225
  function createWorkflow(params) {
8107
8226
  return new Workflow(params);
@@ -8272,7 +8391,7 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
8272
8391
  * @deprecated waitForEvent has been removed. Please use suspend/resume instead.
8273
8392
  */
8274
8393
  waitForEvent(_event, _step, _opts) {
8275
- throw new chunkHWMMIRIF_cjs.MastraError({
8394
+ throw new chunk4U7ZLI36_cjs.MastraError({
8276
8395
  id: "WORKFLOW_WAIT_FOR_EVENT_REMOVED",
8277
8396
  domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
8278
8397
  category: "USER" /* USER */,
@@ -8283,8 +8402,8 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
8283
8402
  if (typeof mappingConfig === "function") {
8284
8403
  const mappingStep2 = createStep({
8285
8404
  id: stepOptions?.id || `mapping_${this.#mastra?.generateId() || crypto2.randomUUID()}`,
8286
- inputSchema: z8.z.object({}),
8287
- outputSchema: z8.z.object({}),
8405
+ inputSchema: z8.z.any(),
8406
+ outputSchema: z8.z.any(),
8288
8407
  execute: mappingConfig
8289
8408
  });
8290
8409
  this.stepFlow.push({ type: "step", step: mappingStep2 });
@@ -8340,7 +8459,15 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
8340
8459
  result[key] = requestContext.get(m.requestContextPath);
8341
8460
  continue;
8342
8461
  }
8343
- const stepResult = m.initData ? getInitData() : getStepResult2(Array.isArray(m.step) ? m.step.find((s) => getStepResult2(s)) : m.step);
8462
+ const stepResult = m.initData ? getInitData() : getStepResult2(
8463
+ Array.isArray(m.step) ? m.step.find((s) => {
8464
+ const result2 = getStepResult2(s);
8465
+ if (typeof result2 === "object" && result2 !== null) {
8466
+ return Object.keys(result2).length > 0;
8467
+ }
8468
+ return result2;
8469
+ }) : m.step
8470
+ );
8344
8471
  if (m.path === ".") {
8345
8472
  result[key] = stepResult;
8346
8473
  continue;
@@ -8558,7 +8685,8 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
8558
8685
  run.workflowRunStatus = workflowSnapshotInStorage.status;
8559
8686
  }
8560
8687
  if (!workflowSnapshotInStorage && shouldPersistSnapshot) {
8561
- await this.mastra?.getStorage()?.persistWorkflowSnapshot({
8688
+ const workflowsStore = await this.mastra?.getStorage()?.getStore("workflows");
8689
+ await workflowsStore?.persistWorkflowSnapshot({
8562
8690
  workflowName: this.id,
8563
8691
  runId: runIdToUse,
8564
8692
  resourceId: options?.resourceId,
@@ -8623,7 +8751,8 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
8623
8751
  retryCount,
8624
8752
  tracingContext,
8625
8753
  outputWriter,
8626
- validateInputs
8754
+ validateInputs,
8755
+ perStep
8627
8756
  }) {
8628
8757
  this.__registerMastra(mastra);
8629
8758
  const effectiveValidateInputs = validateInputs ?? this.#options.validateInputs ?? true;
@@ -8671,7 +8800,8 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
8671
8800
  requestContext,
8672
8801
  tracingContext,
8673
8802
  outputWriter,
8674
- outputOptions: { includeState: true, includeResumeLabels: true }
8803
+ outputOptions: { includeState: true, includeResumeLabels: true },
8804
+ perStep
8675
8805
  });
8676
8806
  } else if (restart) {
8677
8807
  res = await run.restart({ requestContext, tracingContext, outputWriter });
@@ -8683,7 +8813,8 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
8683
8813
  tracingContext,
8684
8814
  outputWriter,
8685
8815
  outputOptions: { includeState: true, includeResumeLabels: true },
8686
- label: resume.label
8816
+ label: resume.label,
8817
+ perStep
8687
8818
  });
8688
8819
  } else {
8689
8820
  res = await run.start({
@@ -8692,7 +8823,8 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
8692
8823
  tracingContext,
8693
8824
  outputWriter,
8694
8825
  initialState: state,
8695
- outputOptions: { includeState: true, includeResumeLabels: true }
8826
+ outputOptions: { includeState: true, includeResumeLabels: true },
8827
+ perStep
8696
8828
  });
8697
8829
  }
8698
8830
  unwatch();
@@ -8728,7 +8860,12 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
8728
8860
  this.logger.debug("Cannot get workflow runs. Mastra storage is not initialized");
8729
8861
  return { runs: [], total: 0 };
8730
8862
  }
8731
- return storage.listWorkflowRuns({ workflowName: this.id, ...args ?? {} });
8863
+ const workflowsStore = await storage.getStore("workflows");
8864
+ if (!workflowsStore) {
8865
+ this.logger.debug("Cannot get workflow runs. Workflows storage domain is not available");
8866
+ return { runs: [], total: 0 };
8867
+ }
8868
+ return workflowsStore.listWorkflowRuns({ workflowName: this.id, ...args ?? {} });
8732
8869
  }
8733
8870
  async listActiveWorkflowRuns() {
8734
8871
  const runningRuns = await this.listWorkflowRuns({ status: "running" });
@@ -8765,7 +8902,12 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
8765
8902
  this.logger.debug("Cannot get workflow runs from storage. Mastra storage is not initialized");
8766
8903
  return this.#runs.get(runId) ? { ...this.#runs.get(runId), workflowName: this.id } : null;
8767
8904
  }
8768
- const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
8905
+ const workflowsStore = await storage.getStore("workflows");
8906
+ if (!workflowsStore) {
8907
+ this.logger.debug("Cannot get workflow runs. Workflows storage domain is not available");
8908
+ return this.#runs.get(runId) ? { ...this.#runs.get(runId), workflowName: this.id } : null;
8909
+ }
8910
+ const run = await workflowsStore.getWorkflowRunById({ runId, workflowName: this.id });
8769
8911
  return run ?? (this.#runs.get(runId) ? { ...this.#runs.get(runId), workflowName: this.id } : null);
8770
8912
  }
8771
8913
  async deleteWorkflowRunById(runId) {
@@ -8774,7 +8916,12 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
8774
8916
  this.logger.debug("Cannot delete workflow run by ID. Mastra storage is not initialized");
8775
8917
  return;
8776
8918
  }
8777
- await storage.deleteWorkflowRunById({ runId, workflowName: this.id });
8919
+ const workflowsStore = await storage.getStore("workflows");
8920
+ if (!workflowsStore) {
8921
+ this.logger.debug("Cannot delete workflow run. Workflows storage domain is not available");
8922
+ return;
8923
+ }
8924
+ await workflowsStore.deleteWorkflowRunById({ runId, workflowName: this.id });
8778
8925
  this.#runs.delete(runId);
8779
8926
  }
8780
8927
  async getWorkflowRunSteps({ runId, workflowId }) {
@@ -8783,7 +8930,12 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
8783
8930
  this.logger.debug("Cannot get workflow run steps. Mastra storage is not initialized");
8784
8931
  return {};
8785
8932
  }
8786
- const run = await storage.getWorkflowRunById({ runId, workflowName: workflowId });
8933
+ const workflowsStore = await storage.getStore("workflows");
8934
+ if (!workflowsStore) {
8935
+ this.logger.debug("Cannot get workflow run steps. Workflows storage domain is not available");
8936
+ return {};
8937
+ }
8938
+ const run = await workflowsStore.getWorkflowRunById({ runId, workflowName: workflowId });
8787
8939
  let snapshot = run?.snapshot;
8788
8940
  if (!snapshot) {
8789
8941
  return {};
@@ -8825,7 +8977,12 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
8825
8977
  this.logger.debug("Cannot get workflow run execution result. Mastra storage is not initialized");
8826
8978
  return null;
8827
8979
  }
8828
- const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
8980
+ const workflowsStore = await storage.getStore("workflows");
8981
+ if (!workflowsStore) {
8982
+ this.logger.debug("Cannot get workflow run execution result. Workflows storage domain is not available");
8983
+ return null;
8984
+ }
8985
+ const run = await workflowsStore.getWorkflowRunById({ runId, workflowName: this.id });
8829
8986
  let snapshot = run?.snapshot;
8830
8987
  if (!snapshot) {
8831
8988
  return null;
@@ -8984,7 +9141,8 @@ var Run = class {
8984
9141
  this.abortController.abort();
8985
9142
  this.workflowRunStatus = "canceled";
8986
9143
  try {
8987
- await this.mastra?.getStorage()?.updateWorkflowState({
9144
+ const workflowsStore = await this.mastra?.getStorage()?.getStore("workflows");
9145
+ await workflowsStore?.updateWorkflowState({
8988
9146
  workflowName: this.workflowId,
8989
9147
  runId: this.runId,
8990
9148
  opts: {
@@ -9062,15 +9220,15 @@ var Run = class {
9062
9220
  tracingContext,
9063
9221
  tracingOptions,
9064
9222
  format,
9065
- outputOptions
9223
+ outputOptions,
9224
+ perStep
9066
9225
  }) {
9067
- const workflowSpan = chunk72YCRTEX_cjs.getOrCreateSpan({
9226
+ const workflowSpan = chunkZSZOYPSJ_cjs.getOrCreateSpan({
9068
9227
  type: "workflow_run" /* WORKFLOW_RUN */,
9069
9228
  name: `workflow run: '${this.workflowId}'`,
9229
+ entityType: "workflow_run" /* WORKFLOW_RUN */,
9230
+ entityId: this.workflowId,
9070
9231
  input: inputData,
9071
- attributes: {
9072
- workflowId: this.workflowId
9073
- },
9074
9232
  metadata: {
9075
9233
  resourceId: this.resourceId,
9076
9234
  runId: this.runId
@@ -9100,7 +9258,8 @@ var Run = class {
9100
9258
  outputWriter,
9101
9259
  workflowSpan,
9102
9260
  format,
9103
- outputOptions
9261
+ outputOptions,
9262
+ perStep
9104
9263
  });
9105
9264
  if (result.status !== "suspended") {
9106
9265
  this.cleanup?.();
@@ -9125,7 +9284,7 @@ var Run = class {
9125
9284
  */
9126
9285
  async startAsync(args) {
9127
9286
  this._start(args).catch((err) => {
9128
- console.error(`[Workflow ${this.workflowId}] Background execution failed:`, err);
9287
+ this.mastra?.getLogger()?.error(`[Workflow ${this.workflowId}] Background execution failed:`, err);
9129
9288
  });
9130
9289
  return { runId: this.runId };
9131
9290
  }
@@ -9174,7 +9333,7 @@ var Run = class {
9174
9333
  try {
9175
9334
  await writer.close();
9176
9335
  } catch (err) {
9177
- console.error("Error closing stream:", err);
9336
+ this.mastra?.getLogger()?.error("Error closing stream:", err);
9178
9337
  } finally {
9179
9338
  writer.releaseLock();
9180
9339
  }
@@ -9232,7 +9391,7 @@ var Run = class {
9232
9391
  try {
9233
9392
  await writer.close();
9234
9393
  } catch (err) {
9235
- console.error("Error closing stream:", err);
9394
+ this.mastra?.getLogger()?.error("Error closing stream:", err);
9236
9395
  } finally {
9237
9396
  writer.releaseLock();
9238
9397
  }
@@ -9267,9 +9426,10 @@ var Run = class {
9267
9426
  }
9268
9427
  async streamAsync({
9269
9428
  inputData,
9270
- requestContext
9429
+ requestContext,
9430
+ perStep
9271
9431
  } = {}) {
9272
- return this.stream({ inputData, requestContext });
9432
+ return this.stream({ inputData, requestContext, perStep });
9273
9433
  }
9274
9434
  /**
9275
9435
  * Starts the workflow execution with the provided input as a stream
@@ -9283,7 +9443,8 @@ var Run = class {
9283
9443
  tracingOptions,
9284
9444
  closeOnSuspend = true,
9285
9445
  initialState,
9286
- outputOptions
9446
+ outputOptions,
9447
+ perStep
9287
9448
  } = {}) {
9288
9449
  if (this.closeStreamAction && this.streamOutput) {
9289
9450
  return this.streamOutput;
@@ -9322,7 +9483,7 @@ var Run = class {
9322
9483
  controller.close();
9323
9484
  }
9324
9485
  } catch (err) {
9325
- console.error("Error closing stream:", err);
9486
+ self.mastra?.getLogger()?.error("Error closing stream:", err);
9326
9487
  }
9327
9488
  };
9328
9489
  const executionResultsPromise = self._start({
@@ -9338,7 +9499,8 @@ var Run = class {
9338
9499
  runId: self.runId,
9339
9500
  data: chunk
9340
9501
  });
9341
- }
9502
+ },
9503
+ perStep
9342
9504
  });
9343
9505
  let executionResults;
9344
9506
  try {
@@ -9380,7 +9542,8 @@ var Run = class {
9380
9542
  requestContext,
9381
9543
  tracingContext,
9382
9544
  tracingOptions,
9383
- outputOptions
9545
+ outputOptions,
9546
+ perStep
9384
9547
  } = {}) {
9385
9548
  return this.resumeStreamVNext({
9386
9549
  resumeData,
@@ -9388,7 +9551,8 @@ var Run = class {
9388
9551
  requestContext,
9389
9552
  tracingContext,
9390
9553
  tracingOptions,
9391
- outputOptions
9554
+ outputOptions,
9555
+ perStep
9392
9556
  });
9393
9557
  }
9394
9558
  /**
@@ -9403,7 +9567,8 @@ var Run = class {
9403
9567
  tracingContext,
9404
9568
  tracingOptions,
9405
9569
  forEachIndex,
9406
- outputOptions
9570
+ outputOptions,
9571
+ perStep
9407
9572
  } = {}) {
9408
9573
  this.closeStreamAction = async () => {
9409
9574
  };
@@ -9439,7 +9604,7 @@ var Run = class {
9439
9604
  controller.close();
9440
9605
  }
9441
9606
  } catch (err) {
9442
- console.error("Error closing stream:", err);
9607
+ self.mastra?.getLogger()?.error("Error closing stream:", err);
9443
9608
  }
9444
9609
  };
9445
9610
  const executionResultsPromise = self._resume({
@@ -9453,7 +9618,8 @@ var Run = class {
9453
9618
  },
9454
9619
  isVNext: true,
9455
9620
  forEachIndex,
9456
- outputOptions
9621
+ outputOptions,
9622
+ perStep
9457
9623
  });
9458
9624
  self.executionResults = executionResultsPromise;
9459
9625
  let executionResults;
@@ -9490,14 +9656,22 @@ var Run = class {
9490
9656
  const nestedWatchCb = (event) => {
9491
9657
  if (event.runId === this.runId) {
9492
9658
  const { event: nestedEvent, workflowId } = event.data;
9493
- void this.pubsub.publish(`workflow.events.v2.${this.runId}`, {
9494
- type: "watch",
9495
- runId: this.runId,
9496
- data: {
9497
- ...nestedEvent,
9498
- ...nestedEvent.payload?.id ? { payload: { ...nestedEvent.payload, id: `${workflowId}.${nestedEvent.payload.id}` } } : {}
9499
- }
9500
- });
9659
+ if (nestedEvent.type.startsWith("data-") && nestedEvent.data !== void 0) {
9660
+ void this.pubsub.publish(`workflow.events.v2.${this.runId}`, {
9661
+ type: "watch",
9662
+ runId: this.runId,
9663
+ data: nestedEvent
9664
+ });
9665
+ } else {
9666
+ void this.pubsub.publish(`workflow.events.v2.${this.runId}`, {
9667
+ type: "watch",
9668
+ runId: this.runId,
9669
+ data: {
9670
+ ...nestedEvent,
9671
+ ...nestedEvent.payload?.id ? { payload: { ...nestedEvent.payload, id: `${workflowId}.${nestedEvent.payload.id}` } } : {}
9672
+ }
9673
+ });
9674
+ }
9501
9675
  }
9502
9676
  };
9503
9677
  void this.pubsub.subscribe(`workflow.events.v2.${this.runId}`, wrappedCb);
@@ -9524,7 +9698,8 @@ var Run = class {
9524
9698
  return this._restart(args);
9525
9699
  }
9526
9700
  async _resume(params) {
9527
- const snapshot = await this.#mastra?.getStorage()?.loadWorkflowSnapshot({
9701
+ const workflowsStore = await this.#mastra?.getStorage()?.getStore("workflows");
9702
+ const snapshot = await workflowsStore?.loadWorkflowSnapshot({
9528
9703
  workflowName: this.workflowId,
9529
9704
  runId: this.runId
9530
9705
  });
@@ -9596,13 +9771,12 @@ var Run = class {
9596
9771
  requestContextToUse.set(key, value);
9597
9772
  }
9598
9773
  });
9599
- const workflowSpan = chunk72YCRTEX_cjs.getOrCreateSpan({
9774
+ const workflowSpan = chunkZSZOYPSJ_cjs.getOrCreateSpan({
9600
9775
  type: "workflow_run" /* WORKFLOW_RUN */,
9601
9776
  name: `workflow run: '${this.workflowId}'`,
9777
+ entityType: "workflow_run" /* WORKFLOW_RUN */,
9778
+ entityId: this.workflowId,
9602
9779
  input: resumeDataToUse,
9603
- attributes: {
9604
- workflowId: this.workflowId
9605
- },
9606
9780
  metadata: {
9607
9781
  resourceId: this.resourceId,
9608
9782
  runId: this.runId
@@ -9637,7 +9811,8 @@ var Run = class {
9637
9811
  abortController: this.abortController,
9638
9812
  workflowSpan,
9639
9813
  outputOptions: params.outputOptions,
9640
- outputWriter: params.outputWriter
9814
+ outputWriter: params.outputWriter,
9815
+ perStep: params.perStep
9641
9816
  }).then((result) => {
9642
9817
  if (!params.isVNext && result.status !== "suspended") {
9643
9818
  this.closeStreamAction?.().catch(() => {
@@ -9661,7 +9836,8 @@ var Run = class {
9661
9836
  if (this.workflowEngineType !== "default") {
9662
9837
  throw new Error(`restart() is not supported on ${this.workflowEngineType} workflows`);
9663
9838
  }
9664
- const snapshot = await this.#mastra?.getStorage()?.loadWorkflowSnapshot({
9839
+ const workflowsStore = await this.#mastra?.getStorage()?.getStore("workflows");
9840
+ const snapshot = await workflowsStore?.loadWorkflowSnapshot({
9665
9841
  workflowName: this.workflowId,
9666
9842
  runId: this.runId
9667
9843
  });
@@ -9707,12 +9883,11 @@ var Run = class {
9707
9883
  requestContextToUse.set(key, value);
9708
9884
  }
9709
9885
  }
9710
- const workflowSpan = chunk72YCRTEX_cjs.getOrCreateSpan({
9886
+ const workflowSpan = chunkZSZOYPSJ_cjs.getOrCreateSpan({
9711
9887
  type: "workflow_run" /* WORKFLOW_RUN */,
9712
9888
  name: `workflow run: '${this.workflowId}'`,
9713
- attributes: {
9714
- workflowId: this.workflowId
9715
- },
9889
+ entityType: "workflow_run" /* WORKFLOW_RUN */,
9890
+ entityId: this.workflowId,
9716
9891
  metadata: {
9717
9892
  resourceId: this.resourceId,
9718
9893
  runId: this.runId
@@ -9756,12 +9931,14 @@ var Run = class {
9756
9931
  outputWriter,
9757
9932
  tracingContext,
9758
9933
  tracingOptions,
9759
- outputOptions
9934
+ outputOptions,
9935
+ perStep
9760
9936
  }) {
9761
9937
  if (!stepParam || Array.isArray(stepParam) && stepParam.length === 0) {
9762
9938
  throw new Error("Step is required and must be a valid step or array of steps");
9763
9939
  }
9764
- const snapshot = await this.#mastra?.getStorage()?.loadWorkflowSnapshot({
9940
+ const workflowsStore = await this.#mastra?.getStorage()?.getStore("workflows");
9941
+ const snapshot = await workflowsStore?.loadWorkflowSnapshot({
9765
9942
  workflowName: this.workflowId,
9766
9943
  runId: this.runId
9767
9944
  });
@@ -9791,7 +9968,8 @@ var Run = class {
9791
9968
  nestedStepsContext,
9792
9969
  snapshot,
9793
9970
  initialState,
9794
- graph: this.executionGraph
9971
+ graph: this.executionGraph,
9972
+ perStep
9795
9973
  });
9796
9974
  const requestContextToUse = requestContext ?? new chunkUVHSM2GU_cjs.RequestContext();
9797
9975
  for (const [key, value] of Object.entries(snapshot.requestContext ?? {})) {
@@ -9799,13 +9977,12 @@ var Run = class {
9799
9977
  requestContextToUse.set(key, value);
9800
9978
  }
9801
9979
  }
9802
- const workflowSpan = chunk72YCRTEX_cjs.getOrCreateSpan({
9980
+ const workflowSpan = chunkZSZOYPSJ_cjs.getOrCreateSpan({
9803
9981
  type: "workflow_run" /* WORKFLOW_RUN */,
9804
9982
  name: `workflow run: '${this.workflowId}'`,
9805
9983
  input: inputData,
9806
- attributes: {
9807
- workflowId: this.workflowId
9808
- },
9984
+ entityType: "workflow_run" /* WORKFLOW_RUN */,
9985
+ entityId: this.workflowId,
9809
9986
  metadata: {
9810
9987
  resourceId: this.resourceId,
9811
9988
  runId: this.runId
@@ -9831,7 +10008,8 @@ var Run = class {
9831
10008
  abortController: this.abortController,
9832
10009
  outputWriter,
9833
10010
  workflowSpan,
9834
- outputOptions
10011
+ outputOptions,
10012
+ perStep
9835
10013
  });
9836
10014
  if (result.status !== "suspended") {
9837
10015
  this.cleanup?.();
@@ -9852,7 +10030,8 @@ var Run = class {
9852
10030
  requestContext,
9853
10031
  tracingContext,
9854
10032
  tracingOptions,
9855
- outputOptions
10033
+ outputOptions,
10034
+ perStep
9856
10035
  }) {
9857
10036
  this.closeStreamAction = async () => {
9858
10037
  };
@@ -9877,7 +10056,7 @@ var Run = class {
9877
10056
  controller.close();
9878
10057
  }
9879
10058
  } catch (err) {
9880
- console.error("Error closing stream:", err);
10059
+ self.mastra?.getLogger()?.error("Error closing stream:", err);
9881
10060
  }
9882
10061
  };
9883
10062
  const executionResultsPromise = self._timeTravel({
@@ -9893,7 +10072,8 @@ var Run = class {
9893
10072
  outputWriter: async (chunk) => {
9894
10073
  void controller.enqueue(chunk);
9895
10074
  },
9896
- outputOptions
10075
+ outputOptions,
10076
+ perStep
9897
10077
  });
9898
10078
  self.executionResults = executionResultsPromise;
9899
10079
  let executionResults;
@@ -10321,7 +10501,8 @@ async function processOutputStream({
10321
10501
  options,
10322
10502
  controller,
10323
10503
  responseFromModel,
10324
- includeRawChunks
10504
+ includeRawChunks,
10505
+ logger
10325
10506
  }) {
10326
10507
  for await (const chunk of outputStream._getBaseStream()) {
10327
10508
  if (!chunk) {
@@ -10404,7 +10585,7 @@ async function processOutputStream({
10404
10585
  abortSignal: options?.abortSignal
10405
10586
  });
10406
10587
  } catch (error2) {
10407
- console.error("Error calling onInputStart", error2);
10588
+ logger?.error("Error calling onInputStart", error2);
10408
10589
  }
10409
10590
  }
10410
10591
  if (isControllerOpen(controller)) {
@@ -10423,7 +10604,7 @@ async function processOutputStream({
10423
10604
  abortSignal: options?.abortSignal
10424
10605
  });
10425
10606
  } catch (error2) {
10426
- console.error("Error calling onInputDelta", error2);
10607
+ logger?.error("Error calling onInputDelta", error2);
10427
10608
  }
10428
10609
  }
10429
10610
  if (isControllerOpen(controller)) {
@@ -10498,7 +10679,8 @@ async function processOutputStream({
10498
10679
  messageList.add(message, "response");
10499
10680
  runState.setState({
10500
10681
  isReasoning: false,
10501
- reasoningDeltas: []
10682
+ reasoningDeltas: [],
10683
+ providerOptions: void 0
10502
10684
  });
10503
10685
  if (isControllerOpen(controller)) {
10504
10686
  controller.enqueue(chunk);
@@ -10582,7 +10764,7 @@ async function processOutputStream({
10582
10764
  reason: "error"
10583
10765
  }
10584
10766
  });
10585
- const error = chunkHWMMIRIF_cjs.getErrorFromUnknown(chunk.payload.error, {
10767
+ const error = chunk4U7ZLI36_cjs.getErrorFromUnknown(chunk.payload.error, {
10586
10768
  fallbackMessage: "Unknown error in agent stream"
10587
10769
  });
10588
10770
  controller.enqueue({ ...chunk, payload: { ...chunk.payload, error } });
@@ -10612,7 +10794,7 @@ async function processOutputStream({
10612
10794
  }
10613
10795
  }
10614
10796
  }
10615
- function executeStreamWithFallbackModels(models) {
10797
+ function executeStreamWithFallbackModels(models, logger) {
10616
10798
  return async (callback) => {
10617
10799
  let index = 0;
10618
10800
  let finalResult;
@@ -10632,8 +10814,11 @@ function executeStreamWithFallbackModels(models) {
10632
10814
  done = true;
10633
10815
  break;
10634
10816
  } catch (err) {
10817
+ if (err instanceof TripWire) {
10818
+ throw err;
10819
+ }
10635
10820
  attempt++;
10636
- console.error(`Error executing model ${modelConfig.model.modelId}, attempt ${attempt}====`, err);
10821
+ logger?.error(`Error executing model ${modelConfig.model.modelId}, attempt ${attempt}====`, err);
10637
10822
  if (attempt > maxRetries) {
10638
10823
  break;
10639
10824
  }
@@ -10643,7 +10828,7 @@ function executeStreamWithFallbackModels(models) {
10643
10828
  }
10644
10829
  }
10645
10830
  if (typeof finalResult === "undefined") {
10646
- console.error("Exhausted all fallback models and reached the maximum number of retries.");
10831
+ logger?.error("Exhausted all fallback models and reached the maximum number of retries.");
10647
10832
  throw new Error("Exhausted all fallback models and reached the maximum number of retries.");
10648
10833
  }
10649
10834
  return finalResult;
@@ -10684,11 +10869,15 @@ function createLLMExecutionStep({
10684
10869
  inputSchema: llmIterationOutputSchema,
10685
10870
  outputSchema: llmIterationOutputSchema,
10686
10871
  execute: async ({ inputData, bail, tracingContext }) => {
10872
+ modelSpanTracker?.startStep();
10687
10873
  let modelResult;
10688
10874
  let warnings;
10689
10875
  let request;
10690
10876
  let rawResponse;
10691
- const { outputStream, callBail, runState, stepTools } = await executeStreamWithFallbackModels(models)(async (modelConfig, isLastModel) => {
10877
+ const { outputStream, callBail, runState, stepTools } = await executeStreamWithFallbackModels(
10878
+ models,
10879
+ logger
10880
+ )(async (modelConfig, isLastModel) => {
10692
10881
  const model = modelConfig.model;
10693
10882
  const modelHeaders = modelConfig.headers;
10694
10883
  if (initialSystemMessages) {
@@ -10735,7 +10924,46 @@ function createLLMExecutionStep({
10735
10924
  });
10736
10925
  Object.assign(currentStep, processInputStepResult);
10737
10926
  } catch (error) {
10738
- console.error("Error in processInputStep processors:", error);
10927
+ if (error instanceof TripWire) {
10928
+ if (isControllerOpen(controller)) {
10929
+ controller.enqueue({
10930
+ type: "tripwire",
10931
+ runId,
10932
+ from: "AGENT" /* AGENT */,
10933
+ payload: {
10934
+ reason: error.message,
10935
+ retry: error.options?.retry,
10936
+ metadata: error.options?.metadata,
10937
+ processorId: error.processorId
10938
+ }
10939
+ });
10940
+ }
10941
+ const runState3 = new AgenticRunState({
10942
+ _internal,
10943
+ model
10944
+ });
10945
+ return {
10946
+ callBail: true,
10947
+ outputStream: new MastraModelOutput({
10948
+ model: {
10949
+ modelId: model.modelId,
10950
+ provider: model.provider,
10951
+ version: model.specificationVersion
10952
+ },
10953
+ stream: new web.ReadableStream({
10954
+ start(c) {
10955
+ c.close();
10956
+ }
10957
+ }),
10958
+ messageList,
10959
+ messageId,
10960
+ options: { runId }
10961
+ }),
10962
+ runState: runState3,
10963
+ stepTools: tools
10964
+ };
10965
+ }
10966
+ logger?.error("Error in processInputStep processors:", error);
10739
10967
  throw error;
10740
10968
  }
10741
10969
  }
@@ -10768,7 +10996,8 @@ Analyse the suspended tools: ${JSON.stringify(suspendedTools)}, using the messag
10768
10996
  resumeData can not be an empty object nor null/undefined.
10769
10997
  When you find that and call that tool, add the resumeData to the tool call arguments/input.
10770
10998
  Also, add the runId of the suspended tool as suspendedToolRunId to the tool call arguments/input.
10771
- 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.`;
10999
+ 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. If you can't construct resumeData from the message for approval type, set approved to true and add resumeData: { approved: true } to the tool call arguments/input.
11000
+ `;
10772
11001
  }
10773
11002
  return message;
10774
11003
  });
@@ -10776,7 +11005,7 @@ Analyse the suspended tools: ${JSON.stringify(suspendedTools)}, using the messag
10776
11005
  }
10777
11006
  }
10778
11007
  if (isSupportedLanguageModel(currentStep.model)) {
10779
- modelResult = chunk72YCRTEX_cjs.executeWithContextSync({
11008
+ modelResult = chunkZSZOYPSJ_cjs.executeWithContextSync({
10780
11009
  span: modelSpanTracker?.getTracingContext()?.currentSpan,
10781
11010
  fn: () => execute({
10782
11011
  runId,
@@ -10860,10 +11089,11 @@ Analyse the suspended tools: ${JSON.stringify(suspendedTools)}, using the messag
10860
11089
  warnings,
10861
11090
  request,
10862
11091
  rawResponse
10863
- }
11092
+ },
11093
+ logger
10864
11094
  });
10865
11095
  } catch (error) {
10866
- console.error("Error in LLM Execution Step", error);
11096
+ logger?.error("Error in LLM Execution Step", error);
10867
11097
  if (providerUtilsV5.isAbortError(error) && options?.abortSignal?.aborted) {
10868
11098
  await options?.onAbort?.({
10869
11099
  steps: inputData?.output?.steps ?? []
@@ -10982,6 +11212,7 @@ Analyse the suspended tools: ${JSON.stringify(suspendedTools)}, using the messag
10982
11212
  }));
10983
11213
  const currentRetryCount = inputData.processorRetryCount || 0;
10984
11214
  await processorRunner.runProcessOutputStep({
11215
+ steps: inputData.output?.steps ?? [],
10985
11216
  messages: messageList.get.all.db(),
10986
11217
  messageList,
10987
11218
  stepNumber,
@@ -10996,7 +11227,7 @@ Analyse the suspended tools: ${JSON.stringify(suspendedTools)}, using the messag
10996
11227
  if (error instanceof TripWire) {
10997
11228
  processOutputStepTripwire = error;
10998
11229
  } else {
10999
- console.error("Error in processOutputStep processors:", error);
11230
+ logger?.error("Error in processOutputStep processors:", error);
11000
11231
  throw error;
11001
11232
  }
11002
11233
  }
@@ -11262,7 +11493,8 @@ function createToolCallStep({
11262
11493
  runId,
11263
11494
  streamState,
11264
11495
  modelSpanTracker,
11265
- _internal
11496
+ _internal,
11497
+ logger
11266
11498
  }) {
11267
11499
  return createStep({
11268
11500
  id: "toolCallStep",
@@ -11329,7 +11561,7 @@ function createToolCallStep({
11329
11561
  try {
11330
11562
  await saveQueueManager.flushMessages(messageList, threadId, memoryConfig);
11331
11563
  } catch (error) {
11332
- console.error("Error removing tool suspension metadata:", error);
11564
+ logger?.error("Error removing tool suspension metadata:", error);
11333
11565
  }
11334
11566
  }
11335
11567
  }
@@ -11353,7 +11585,7 @@ function createToolCallStep({
11353
11585
  }
11354
11586
  await saveQueueManager.flushMessages(messageList, threadId, memoryConfig);
11355
11587
  } catch (error) {
11356
- console.error("Error flushing messages before suspension:", error);
11588
+ logger?.error("Error flushing messages before suspension:", error);
11357
11589
  }
11358
11590
  };
11359
11591
  if (inputData.providerExecuted) {
@@ -11374,7 +11606,7 @@ function createToolCallStep({
11374
11606
  abortSignal: options?.abortSignal
11375
11607
  });
11376
11608
  } catch (error) {
11377
- console.error("Error calling onInputAvailable", error);
11609
+ logger?.error("Error calling onInputAvailable", error);
11378
11610
  }
11379
11611
  }
11380
11612
  if (!tool2.execute) {
@@ -11391,7 +11623,17 @@ function createToolCallStep({
11391
11623
  }
11392
11624
  const resumeData = resumeDataFromArgs ?? workflowResumeData;
11393
11625
  const isResumeToolCall = !!resumeDataFromArgs;
11394
- if (requireToolApproval || tool2.requireApproval) {
11626
+ let toolRequiresApproval = requireToolApproval || tool2.requireApproval;
11627
+ if (tool2.needsApprovalFn) {
11628
+ try {
11629
+ const needsApprovalResult = await tool2.needsApprovalFn(args);
11630
+ toolRequiresApproval = needsApprovalResult;
11631
+ } catch (error) {
11632
+ logger?.error(`Error evaluating needsApprovalFn for tool ${inputData.toolName}:`, error);
11633
+ toolRequiresApproval = true;
11634
+ }
11635
+ }
11636
+ if (toolRequiresApproval) {
11395
11637
  if (!resumeData) {
11396
11638
  controller.enqueue({
11397
11639
  type: "tool-call-approval",
@@ -11492,7 +11734,7 @@ function createToolCallStep({
11492
11734
  abortSignal: options?.abortSignal
11493
11735
  });
11494
11736
  } catch (error) {
11495
- console.error("Error calling onOutput", error);
11737
+ logger?.error("Error calling onOutput", error);
11496
11738
  }
11497
11739
  }
11498
11740
  return { result, ...inputData };
@@ -11654,11 +11896,10 @@ function createAgenticLoopWorkflow(params) {
11654
11896
  };
11655
11897
  accumulatedSteps.push(currentStep);
11656
11898
  if (rest.stopWhen && typedInputData.stepResult?.isContinued && accumulatedSteps.length > 0) {
11899
+ const steps = accumulatedSteps;
11657
11900
  const conditions = await Promise.all(
11658
11901
  (Array.isArray(rest.stopWhen) ? rest.stopWhen : [rest.stopWhen]).map((condition) => {
11659
- return condition({
11660
- steps: accumulatedSteps
11661
- });
11902
+ return condition({ steps });
11662
11903
  })
11663
11904
  );
11664
11905
  const hasStopped = conditions.some((condition) => condition);
@@ -11801,7 +12042,7 @@ function workflowLoopStream({
11801
12042
  });
11802
12043
  if (executionResult.status !== "success") {
11803
12044
  if (executionResult.status === "failed") {
11804
- const error = chunkHWMMIRIF_cjs.getErrorFromUnknown(executionResult.error, {
12045
+ const error = chunk4U7ZLI36_cjs.getErrorFromUnknown(executionResult.error, {
11805
12046
  fallbackMessage: "Unknown error in agent workflow stream"
11806
12047
  });
11807
12048
  controller.enqueue({
@@ -11862,7 +12103,7 @@ function loop({
11862
12103
  level: "debug"
11863
12104
  });
11864
12105
  if (models.length === 0 || !models[0]) {
11865
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
12106
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
11866
12107
  id: "LOOP_MODELS_EMPTY",
11867
12108
  domain: "LLM" /* LLM */,
11868
12109
  category: "USER" /* USER */
@@ -11979,7 +12220,7 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
11979
12220
  }
11980
12221
  }
11981
12222
  if (models.length === 0 || !models[0]) {
11982
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
12223
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
11983
12224
  id: "LLM_LOOP_MODELS_EMPTY",
11984
12225
  domain: "LLM" /* LLM */,
11985
12226
  category: "USER" /* USER */
@@ -12104,8 +12345,6 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
12104
12345
  messages: [...messageList.getSystemMessages(), ...messages]
12105
12346
  },
12106
12347
  attributes: {
12107
- agentId,
12108
- agentName,
12109
12348
  model: firstModel.modelId,
12110
12349
  provider: firstModel.provider,
12111
12350
  streaming: true,
@@ -12153,7 +12392,7 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
12153
12392
  try {
12154
12393
  await options?.onStepFinish?.({ ...props, runId });
12155
12394
  } catch (e) {
12156
- const mastraError = new chunkHWMMIRIF_cjs.MastraError(
12395
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError(
12157
12396
  {
12158
12397
  id: "LLM_STREAM_ON_STEP_FINISH_CALLBACK_EXECUTION_FAILED",
12159
12398
  domain: "LLM" /* LLM */,
@@ -12187,7 +12426,7 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
12187
12426
  const remainingTokens = parseInt(props?.response?.headers?.["x-ratelimit-remaining-tokens"] ?? "", 10);
12188
12427
  if (!isNaN(remainingTokens) && remainingTokens > 0 && remainingTokens < 2e3) {
12189
12428
  this.logger.warn("Rate limit approaching, waiting 10 seconds", { runId });
12190
- await chunkO3ULBGV6_cjs.delay(10 * 1e3);
12429
+ await chunkAQ22JIR7_cjs.delay(10 * 1e3);
12191
12430
  }
12192
12431
  },
12193
12432
  onFinish: async (props) => {
@@ -12212,7 +12451,7 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
12212
12451
  try {
12213
12452
  await options?.onFinish?.({ ...props, runId });
12214
12453
  } catch (e) {
12215
- const mastraError = new chunkHWMMIRIF_cjs.MastraError(
12454
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError(
12216
12455
  {
12217
12456
  id: "LLM_STREAM_ON_FINISH_CALLBACK_EXECUTION_FAILED",
12218
12457
  domain: "LLM" /* LLM */,
@@ -12250,7 +12489,7 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
12250
12489
  };
12251
12490
  return loop(loopOptions);
12252
12491
  } catch (e) {
12253
- const mastraError = new chunkHWMMIRIF_cjs.MastraError(
12492
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError(
12254
12493
  {
12255
12494
  id: "LLM_STREAM_TEXT_AI_SDK_EXECUTION_FAILED",
12256
12495
  domain: "LLM" /* LLM */,
@@ -12397,7 +12636,7 @@ async function prepareMemoryStep({
12397
12636
  );
12398
12637
  }
12399
12638
  } else {
12400
- const messageList = new chunk72E3YF6A_cjs.MessageList({
12639
+ const messageList = new chunkEMLEZXTQ_cjs.MessageList({
12401
12640
  threadId: thread?.id,
12402
12641
  resourceId: thread?.resourceId
12403
12642
  });
@@ -12753,7 +12992,7 @@ ${completionResult?.object?.finalResult}` : ""}
12753
12992
  const agentsMap = await agent.listAgents({ requestContext });
12754
12993
  const agentForStep = agentsMap[inputData.primitiveId];
12755
12994
  if (!agentForStep) {
12756
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
12995
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
12757
12996
  id: "AGENT_NETWORK_AGENT_EXECUTION_STEP_INVALID_TASK_INPUT",
12758
12997
  domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
12759
12998
  category: "USER" /* USER */,
@@ -12880,7 +13119,7 @@ ${completionResult?.object?.finalResult}` : ""}
12880
13119
  const workflowId = inputData.primitiveId;
12881
13120
  const wf = workflowsMap[workflowId];
12882
13121
  if (!wf) {
12883
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
13122
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
12884
13123
  id: "AGENT_NETWORK_WORKFLOW_EXECUTION_STEP_INVALID_TASK_INPUT",
12885
13124
  domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
12886
13125
  category: "USER" /* USER */,
@@ -12892,7 +13131,7 @@ ${completionResult?.object?.finalResult}` : ""}
12892
13131
  try {
12893
13132
  input = JSON.parse(inputData.prompt);
12894
13133
  } catch (e) {
12895
- const mastraError = new chunkHWMMIRIF_cjs.MastraError(
13134
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError(
12896
13135
  {
12897
13136
  id: "WORKFLOW_EXECUTION_STEP_INVALID_TASK_INPUT",
12898
13137
  domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
@@ -13017,7 +13256,7 @@ ${completionResult?.object?.finalResult}` : ""}
13017
13256
  const toolsMap = { ...agentTools, ...memoryTools };
13018
13257
  let tool2 = toolsMap[inputData.primitiveId];
13019
13258
  if (!tool2) {
13020
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
13259
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
13021
13260
  id: "AGENT_NETWORK_TOOL_EXECUTION_STEP_INVALID_TASK_INPUT",
13022
13261
  domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
13023
13262
  category: "USER" /* USER */,
@@ -13026,7 +13265,7 @@ ${completionResult?.object?.finalResult}` : ""}
13026
13265
  throw mastraError;
13027
13266
  }
13028
13267
  if (!tool2.execute) {
13029
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
13268
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
13030
13269
  id: "AGENT_NETWORK_TOOL_EXECUTION_STEP_INVALID_TASK_INPUT",
13031
13270
  domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
13032
13271
  category: "USER" /* USER */,
@@ -13039,7 +13278,7 @@ ${completionResult?.object?.finalResult}` : ""}
13039
13278
  try {
13040
13279
  inputDataToUse = JSON.parse(inputData.prompt);
13041
13280
  } catch (e) {
13042
- const mastraError = new chunkHWMMIRIF_cjs.MastraError(
13281
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError(
13043
13282
  {
13044
13283
  id: "AGENT_NETWORK_TOOL_EXECUTION_STEP_INVALID_TASK_INPUT",
13045
13284
  domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
@@ -13264,7 +13503,7 @@ async function networkLoop({
13264
13503
  }) {
13265
13504
  const memoryToUse = await routingAgent.getMemory({ requestContext });
13266
13505
  if (!memoryToUse) {
13267
- throw new chunkHWMMIRIF_cjs.MastraError({
13506
+ throw new chunk4U7ZLI36_cjs.MastraError({
13268
13507
  id: "AGENT_NETWORK_MEMORY_REQUIRED",
13269
13508
  domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
13270
13509
  category: "USER" /* USER */,
@@ -13397,15 +13636,16 @@ var AgentLegacyHandler = class {
13397
13636
  if (process.env.NODE_ENV !== "test") {
13398
13637
  this.capabilities.logger.debug(`[Agents:${this.capabilities.name}] - Starting generation`, { runId });
13399
13638
  }
13400
- const agentSpan = chunk72YCRTEX_cjs.getOrCreateSpan({
13639
+ const agentSpan = chunkZSZOYPSJ_cjs.getOrCreateSpan({
13401
13640
  type: "agent_run" /* AGENT_RUN */,
13402
13641
  name: `agent run: '${this.capabilities.id}'`,
13642
+ entityType: "agent" /* AGENT */,
13643
+ entityId: this.capabilities.id,
13644
+ entityName: this.capabilities.name,
13403
13645
  input: {
13404
13646
  messages
13405
13647
  },
13406
13648
  attributes: {
13407
- agentId: this.capabilities.id,
13408
- agentName: this.capabilities.name,
13409
13649
  instructions: this.capabilities.convertInstructionsToString(instructions),
13410
13650
  availableTools: [
13411
13651
  ...toolsets ? Object.keys(toolsets) : [],
@@ -13451,7 +13691,7 @@ var AgentLegacyHandler = class {
13451
13691
  methodType: methodType === "generate" ? "generateLegacy" : "streamLegacy",
13452
13692
  memoryConfig
13453
13693
  });
13454
- let messageList = new chunk72E3YF6A_cjs.MessageList({
13694
+ let messageList = new chunkEMLEZXTQ_cjs.MessageList({
13455
13695
  threadId,
13456
13696
  resourceId,
13457
13697
  generateMessageId: this.capabilities.mastra?.generateId?.bind(this.capabilities.mastra),
@@ -13476,7 +13716,7 @@ var AgentLegacyHandler = class {
13476
13716
  };
13477
13717
  }
13478
13718
  if (!threadId || !resourceId) {
13479
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
13719
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
13480
13720
  id: "AGENT_MEMORY_MISSING_RESOURCE_ID",
13481
13721
  domain: "AGENT" /* AGENT */,
13482
13722
  category: "USER" /* USER */,
@@ -13582,7 +13822,7 @@ var AgentLegacyHandler = class {
13582
13822
  result: resToLog,
13583
13823
  threadId
13584
13824
  });
13585
- const messageListResponses = new chunk72E3YF6A_cjs.MessageList({
13825
+ const messageListResponses = new chunkEMLEZXTQ_cjs.MessageList({
13586
13826
  threadId,
13587
13827
  resourceId,
13588
13828
  generateMessageId: this.capabilities.mastra?.generateId?.bind(this.capabilities.mastra),
@@ -13652,11 +13892,11 @@ var AgentLegacyHandler = class {
13652
13892
  await Promise.all(promises);
13653
13893
  }
13654
13894
  } catch (e) {
13655
- if (e instanceof chunkHWMMIRIF_cjs.MastraError) {
13895
+ if (e instanceof chunk4U7ZLI36_cjs.MastraError) {
13656
13896
  agentSpan?.error({ error: e });
13657
13897
  throw e;
13658
13898
  }
13659
- const mastraError = new chunkHWMMIRIF_cjs.MastraError(
13899
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError(
13660
13900
  {
13661
13901
  id: "AGENT_MEMORY_PERSIST_RESPONSE_MESSAGES_FAILED",
13662
13902
  domain: "AGENT" /* AGENT */,
@@ -13858,7 +14098,7 @@ var AgentLegacyHandler = class {
13858
14098
  */
13859
14099
  async generateLegacy(messages, generateOptions = {}) {
13860
14100
  if ("structuredOutput" in generateOptions && generateOptions.structuredOutput) {
13861
- throw new chunkHWMMIRIF_cjs.MastraError({
14101
+ throw new chunk4U7ZLI36_cjs.MastraError({
13862
14102
  id: "AGENT_GENERATE_LEGACY_STRUCTURED_OUTPUT_NOT_SUPPORTED",
13863
14103
  domain: "AGENT" /* AGENT */,
13864
14104
  category: "USER" /* USER */,
@@ -13880,7 +14120,7 @@ var AgentLegacyHandler = class {
13880
14120
  this.capabilities.logger.error("V2 models are not supported for generateLegacy. Please use generate instead.", {
13881
14121
  modelId: llm.getModel().modelId
13882
14122
  });
13883
- throw new chunkHWMMIRIF_cjs.MastraError({
14123
+ throw new chunk4U7ZLI36_cjs.MastraError({
13884
14124
  id: "AGENT_GENERATE_V2_MODEL_NOT_SUPPORTED",
13885
14125
  domain: "AGENT" /* AGENT */,
13886
14126
  category: "USER" /* USER */,
@@ -14100,7 +14340,7 @@ var AgentLegacyHandler = class {
14100
14340
  this.capabilities.logger.error("V2 models are not supported for streamLegacy. Please use stream instead.", {
14101
14341
  modelId: llm.getModel().modelId
14102
14342
  });
14103
- throw new chunkHWMMIRIF_cjs.MastraError({
14343
+ throw new chunk4U7ZLI36_cjs.MastraError({
14104
14344
  id: "AGENT_STREAM_V2_MODEL_NOT_SUPPORTED",
14105
14345
  domain: "AGENT" /* AGENT */,
14106
14346
  category: "USER" /* USER */,
@@ -14384,7 +14624,7 @@ function getModelMethodFromAgentMethod(methodType) {
14384
14624
  } else if (methodType === "stream" || methodType === "streamLegacy") {
14385
14625
  return "stream";
14386
14626
  } else {
14387
- throw new chunkHWMMIRIF_cjs.MastraError({
14627
+ throw new chunk4U7ZLI36_cjs.MastraError({
14388
14628
  id: "INVALID_METHOD_TYPE",
14389
14629
  domain: "AGENT" /* AGENT */,
14390
14630
  category: "USER" /* USER */
@@ -14447,7 +14687,7 @@ function createMapResultsStep({
14447
14687
  if (result.tripwire) {
14448
14688
  const agentModel = await capabilities.getModel({ requestContext: result.requestContext });
14449
14689
  if (!isSupportedLanguageModel(agentModel)) {
14450
- throw new chunkHWMMIRIF_cjs.MastraError({
14690
+ throw new chunk4U7ZLI36_cjs.MastraError({
14451
14691
  id: "MAP_RESULTS_STEP_UNSUPPORTED_MODEL",
14452
14692
  domain: "AGENT" /* AGENT */,
14453
14693
  category: "USER" /* USER */,
@@ -14468,7 +14708,10 @@ function createMapResultsStep({
14468
14708
  requestContext: result.requestContext
14469
14709
  }) : capabilities.outputProcessors : []);
14470
14710
  if (options.structuredOutput?.model) {
14471
- const structuredProcessor = new StructuredOutputProcessor(options.structuredOutput);
14711
+ const structuredProcessor = new StructuredOutputProcessor({
14712
+ ...options.structuredOutput,
14713
+ logger: capabilities.logger
14714
+ });
14472
14715
  effectiveOutputProcessors = effectiveOutputProcessors ? [...effectiveOutputProcessors, structuredProcessor] : [structuredProcessor];
14473
14716
  }
14474
14717
  const effectiveInputProcessors = options.inputProcessors || (capabilities.inputProcessors ? typeof capabilities.inputProcessors === "function" ? await capabilities.inputProcessors({
@@ -14583,7 +14826,7 @@ var prepareToolsStepOutputSchema = z8.z.object({
14583
14826
  var prepareMemoryStepOutputSchema = z8.z.object({
14584
14827
  threadExists: z8.z.boolean(),
14585
14828
  thread: storageThreadSchema.optional(),
14586
- messageList: z8.z.instanceof(chunk72E3YF6A_cjs.MessageList),
14829
+ messageList: z8.z.instanceof(chunkEMLEZXTQ_cjs.MessageList),
14587
14830
  /** Tripwire data when input processor triggered abort */
14588
14831
  tripwire: z8.z.object({
14589
14832
  reason: z8.z.string(),
@@ -14621,7 +14864,7 @@ function createPrepareMemoryStep({
14621
14864
  outputSchema: prepareMemoryStepOutputSchema,
14622
14865
  execute: async ({ tracingContext }) => {
14623
14866
  const thread = threadFromArgs;
14624
- const messageList = new chunk72E3YF6A_cjs.MessageList({
14867
+ const messageList = new chunkEMLEZXTQ_cjs.MessageList({
14625
14868
  threadId: thread?.id,
14626
14869
  resourceId,
14627
14870
  generateMessageId: capabilities.generateMessageId,
@@ -14647,7 +14890,7 @@ function createPrepareMemoryStep({
14647
14890
  };
14648
14891
  }
14649
14892
  if (!thread?.id || !resourceId) {
14650
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
14893
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
14651
14894
  id: "AGENT_MEMORY_MISSING_RESOURCE_ID",
14652
14895
  domain: "AGENT" /* AGENT */,
14653
14896
  category: "USER" /* USER */,
@@ -14971,7 +15214,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
14971
15214
  this.#description = config.description;
14972
15215
  this.#options = config.options;
14973
15216
  if (!config.model) {
14974
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
15217
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
14975
15218
  id: "AGENT_CONSTRUCTOR_MODEL_REQUIRED",
14976
15219
  domain: "AGENT" /* AGENT */,
14977
15220
  category: "USER" /* USER */,
@@ -14986,7 +15229,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
14986
15229
  }
14987
15230
  if (Array.isArray(config.model)) {
14988
15231
  if (config.model.length === 0) {
14989
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
15232
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
14990
15233
  id: "AGENT_CONSTRUCTOR_MODEL_ARRAY_EMPTY",
14991
15234
  domain: "AGENT" /* AGENT */,
14992
15235
  category: "USER" /* USER */,
@@ -15038,7 +15281,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15038
15281
  this.#voice?.addInstructions(config.instructions);
15039
15282
  }
15040
15283
  } else {
15041
- this.#voice = new chunkOOUFPYSX_cjs.DefaultVoice();
15284
+ this.#voice = new chunkSSB4AVHU_cjs.DefaultVoice();
15042
15285
  }
15043
15286
  if (config.inputProcessors) {
15044
15287
  this.#inputProcessors = config.inputProcessors;
@@ -15068,7 +15311,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15068
15311
  const agentsToUse = this.#agents ? typeof this.#agents === "function" ? this.#agents({ requestContext }) : this.#agents : {};
15069
15312
  return resolveMaybePromise(agentsToUse, (agents) => {
15070
15313
  if (!agents) {
15071
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
15314
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
15072
15315
  id: "AGENT_GET_AGENTS_FUNCTION_EMPTY_RETURN",
15073
15316
  domain: "AGENT" /* AGENT */,
15074
15317
  category: "USER" /* USER */,
@@ -15151,7 +15394,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15151
15394
  async listResolvedOutputProcessors(requestContext) {
15152
15395
  const configuredProcessors = this.#outputProcessors ? typeof this.#outputProcessors === "function" ? await this.#outputProcessors({ requestContext: requestContext || new chunkUVHSM2GU_cjs.RequestContext() }) : this.#outputProcessors : [];
15153
15396
  const memory = await this.getMemory({ requestContext: requestContext || new chunkUVHSM2GU_cjs.RequestContext() });
15154
- const memoryProcessors = memory ? memory.getOutputProcessors(configuredProcessors, requestContext) : [];
15397
+ const memoryProcessors = memory ? await memory.getOutputProcessors(configuredProcessors, requestContext) : [];
15155
15398
  const allProcessors = [...configuredProcessors, ...memoryProcessors];
15156
15399
  return this.combineProcessorsIntoWorkflow(allProcessors, `${this.id}-output-processor`);
15157
15400
  }
@@ -15163,7 +15406,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15163
15406
  async listResolvedInputProcessors(requestContext) {
15164
15407
  const configuredProcessors = this.#inputProcessors ? typeof this.#inputProcessors === "function" ? await this.#inputProcessors({ requestContext: requestContext || new chunkUVHSM2GU_cjs.RequestContext() }) : this.#inputProcessors : [];
15165
15408
  const memory = await this.getMemory({ requestContext: requestContext || new chunkUVHSM2GU_cjs.RequestContext() });
15166
- const memoryProcessors = memory ? memory.getInputProcessors(configuredProcessors, requestContext) : [];
15409
+ const memoryProcessors = memory ? await memory.getInputProcessors(configuredProcessors, requestContext) : [];
15167
15410
  const allProcessors = [...memoryProcessors, ...configuredProcessors];
15168
15411
  return this.combineProcessorsIntoWorkflow(allProcessors, `${this.id}-input-processor`);
15169
15412
  }
@@ -15242,7 +15485,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15242
15485
  const result = this.#memory({ requestContext, mastra: this.#mastra });
15243
15486
  resolvedMemory = await Promise.resolve(result);
15244
15487
  if (!resolvedMemory) {
15245
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
15488
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
15246
15489
  id: "AGENT_GET_MEMORY_FUNCTION_EMPTY_RETURN",
15247
15490
  domain: "AGENT" /* AGENT */,
15248
15491
  category: "USER" /* USER */,
@@ -15269,7 +15512,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15269
15512
  }
15270
15513
  get voice() {
15271
15514
  if (typeof this.#instructions === "function") {
15272
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
15515
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
15273
15516
  id: "AGENT_VOICE_INCOMPATIBLE_WITH_FUNCTION_INSTRUCTIONS",
15274
15517
  domain: "AGENT" /* AGENT */,
15275
15518
  category: "USER" /* USER */,
@@ -15319,7 +15562,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15319
15562
  const result = this.#scorers({ requestContext, mastra: this.#mastra });
15320
15563
  return resolveMaybePromise(result, (scorers) => {
15321
15564
  if (!scorers) {
15322
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
15565
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
15323
15566
  id: "AGENT_GET_SCORERS_FUNCTION_EMPTY_RETURN",
15324
15567
  domain: "AGENT" /* AGENT */,
15325
15568
  category: "USER" /* USER */,
@@ -15353,7 +15596,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15353
15596
  voice?.addInstructions(this.#convertInstructionsToString(instructions));
15354
15597
  return voice;
15355
15598
  } else {
15356
- return new chunkOOUFPYSX_cjs.DefaultVoice();
15599
+ return new chunkSSB4AVHU_cjs.DefaultVoice();
15357
15600
  }
15358
15601
  }
15359
15602
  /**
@@ -15371,7 +15614,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15371
15614
  const result = this.#instructions({ requestContext, mastra: this.#mastra });
15372
15615
  return resolveMaybePromise(result, (instructions) => {
15373
15616
  if (!instructions) {
15374
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
15617
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
15375
15618
  id: "AGENT_GET_INSTRUCTIONS_FUNCTION_EMPTY_RETURN",
15376
15619
  domain: "AGENT" /* AGENT */,
15377
15620
  category: "USER" /* USER */,
@@ -15476,7 +15719,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15476
15719
  const result = this.#defaultGenerateOptionsLegacy({ requestContext, mastra: this.#mastra });
15477
15720
  return resolveMaybePromise(result, (options) => {
15478
15721
  if (!options) {
15479
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
15722
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
15480
15723
  id: "AGENT_GET_DEFAULT_GENERATE_OPTIONS_FUNCTION_EMPTY_RETURN",
15481
15724
  domain: "AGENT" /* AGENT */,
15482
15725
  category: "USER" /* USER */,
@@ -15511,7 +15754,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15511
15754
  const result = this.#defaultStreamOptionsLegacy({ requestContext, mastra: this.#mastra });
15512
15755
  return resolveMaybePromise(result, (options) => {
15513
15756
  if (!options) {
15514
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
15757
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
15515
15758
  id: "AGENT_GET_DEFAULT_STREAM_OPTIONS_FUNCTION_EMPTY_RETURN",
15516
15759
  domain: "AGENT" /* AGENT */,
15517
15760
  category: "USER" /* USER */,
@@ -15546,7 +15789,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15546
15789
  const result = this.#defaultOptions({ requestContext, mastra: this.#mastra });
15547
15790
  return resolveMaybePromise(result, (options) => {
15548
15791
  if (!options) {
15549
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
15792
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
15550
15793
  id: "AGENT_GET_DEFAULT_OPTIONS_FUNCTION_EMPTY_RETURN",
15551
15794
  domain: "AGENT" /* AGENT */,
15552
15795
  category: "USER" /* USER */,
@@ -15574,12 +15817,12 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15574
15817
  */
15575
15818
  listTools({ requestContext = new chunkUVHSM2GU_cjs.RequestContext() } = {}) {
15576
15819
  if (typeof this.#tools !== "function") {
15577
- return chunkO3ULBGV6_cjs.ensureToolProperties(this.#tools);
15820
+ return chunkAQ22JIR7_cjs.ensureToolProperties(this.#tools);
15578
15821
  }
15579
15822
  const result = this.#tools({ requestContext, mastra: this.#mastra });
15580
15823
  return resolveMaybePromise(result, (tools) => {
15581
15824
  if (!tools) {
15582
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
15825
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
15583
15826
  id: "AGENT_GET_TOOLS_FUNCTION_EMPTY_RETURN",
15584
15827
  domain: "AGENT" /* AGENT */,
15585
15828
  category: "USER" /* USER */,
@@ -15592,7 +15835,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15592
15835
  this.logger.error(mastraError.toString());
15593
15836
  throw mastraError;
15594
15837
  }
15595
- return chunkO3ULBGV6_cjs.ensureToolProperties(tools);
15838
+ return chunkAQ22JIR7_cjs.ensureToolProperties(tools);
15596
15839
  });
15597
15840
  }
15598
15841
  /**
@@ -15624,7 +15867,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15624
15867
  });
15625
15868
  });
15626
15869
  } else {
15627
- llm = new chunkTRUNX3AX_cjs.MastraLLMV1({
15870
+ llm = new chunk7KL2YFFK_cjs.MastraLLMV1({
15628
15871
  model: resolvedModel,
15629
15872
  mastra: this.#mastra,
15630
15873
  options: { tracingPolicy: this.#options?.tracingPolicy }
@@ -15649,9 +15892,9 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15649
15892
  */
15650
15893
  async resolveModelConfig(modelConfig, requestContext) {
15651
15894
  try {
15652
- return await chunk53SZJCBX_cjs.resolveModelConfig(modelConfig, requestContext, this.#mastra);
15895
+ return await chunk4KVIXN7K_cjs.resolveModelConfig(modelConfig, requestContext, this.#mastra);
15653
15896
  } catch (error) {
15654
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
15897
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
15655
15898
  id: "AGENT_GET_MODEL_MISSING_MODEL_INSTANCE",
15656
15899
  domain: "AGENT" /* AGENT */,
15657
15900
  category: "USER" /* USER */,
@@ -15685,7 +15928,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15685
15928
  } = {}) {
15686
15929
  if (!Array.isArray(modelConfig)) return this.resolveModelConfig(modelConfig, requestContext);
15687
15930
  if (modelConfig.length === 0 || !modelConfig[0]) {
15688
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
15931
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
15689
15932
  id: "AGENT_GET_MODEL_MISSING_MODEL_INSTANCE",
15690
15933
  domain: "AGENT" /* AGENT */,
15691
15934
  category: "USER" /* USER */,
@@ -15809,7 +16052,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15809
16052
  mastra.addTool(tool2, toolKey);
15810
16053
  }
15811
16054
  } catch (error) {
15812
- if (error instanceof chunkHWMMIRIF_cjs.MastraError && error.id !== "MASTRA_ADD_TOOL_DUPLICATE_KEY") {
16055
+ if (error instanceof chunk4U7ZLI36_cjs.MastraError && error.id !== "MASTRA_ADD_TOOL_DUPLICATE_KEY") {
15813
16056
  throw error;
15814
16057
  }
15815
16058
  }
@@ -15820,7 +16063,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15820
16063
  try {
15821
16064
  mastra.addProcessor(processor);
15822
16065
  } catch (error) {
15823
- if (error instanceof chunkHWMMIRIF_cjs.MastraError && error.id !== "MASTRA_ADD_PROCESSOR_DUPLICATE_KEY") {
16066
+ if (error instanceof chunk4U7ZLI36_cjs.MastraError && error.id !== "MASTRA_ADD_PROCESSOR_DUPLICATE_KEY") {
15824
16067
  throw error;
15825
16068
  }
15826
16069
  }
@@ -15831,7 +16074,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15831
16074
  try {
15832
16075
  mastra.addProcessor(processor);
15833
16076
  } catch (error) {
15834
- if (error instanceof chunkHWMMIRIF_cjs.MastraError && error.id !== "MASTRA_ADD_PROCESSOR_DUPLICATE_KEY") {
16077
+ if (error instanceof chunk4U7ZLI36_cjs.MastraError && error.id !== "MASTRA_ADD_PROCESSOR_DUPLICATE_KEY") {
15835
16078
  throw error;
15836
16079
  }
15837
16080
  }
@@ -15855,7 +16098,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15855
16098
  instructions
15856
16099
  }) {
15857
16100
  const llm = await this.getLLM({ requestContext, model });
15858
- const normMessage = new chunk72E3YF6A_cjs.MessageList().add(message, "user").get.all.ui().at(-1);
16101
+ const normMessage = new chunkEMLEZXTQ_cjs.MessageList().add(message, "user").get.all.ui().at(-1);
15859
16102
  if (!normMessage) {
15860
16103
  throw new Error(`Could not generate title from input ${JSON.stringify(message)}`);
15861
16104
  }
@@ -15878,7 +16121,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15878
16121
  const systemInstructions = await this.resolveTitleInstructions(requestContext, instructions);
15879
16122
  let text = "";
15880
16123
  if (isSupportedLanguageModel(llm.getModel())) {
15881
- const messageList = new chunk72E3YF6A_cjs.MessageList().add(
16124
+ const messageList = new chunkEMLEZXTQ_cjs.MessageList().add(
15882
16125
  [
15883
16126
  {
15884
16127
  role: "system",
@@ -15931,7 +16174,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15931
16174
  async genTitle(userMessage, requestContext, tracingContext, model, instructions) {
15932
16175
  try {
15933
16176
  if (userMessage) {
15934
- const normMessage = new chunk72E3YF6A_cjs.MessageList().add(userMessage, "user").get.all.ui().at(-1);
16177
+ const normMessage = new chunkEMLEZXTQ_cjs.MessageList().add(userMessage, "user").get.all.ui().at(-1);
15935
16178
  if (normMessage) {
15936
16179
  return await this.generateTitleFromUserMessage({
15937
16180
  message: normMessage,
@@ -15996,7 +16239,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
15996
16239
  tracingPolicy: this.#options?.tracingPolicy,
15997
16240
  requireApproval: toolObj.requireApproval
15998
16241
  };
15999
- const convertedToCoreTool = chunkO3ULBGV6_cjs.makeCoreTool(toolObj, options, void 0, autoResumeSuspendedTools);
16242
+ const convertedToCoreTool = chunkAQ22JIR7_cjs.makeCoreTool(toolObj, options, void 0, autoResumeSuspendedTools);
16000
16243
  convertedMemoryTools[toolName] = convertedToCoreTool;
16001
16244
  }
16002
16245
  }
@@ -16029,7 +16272,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16029
16272
  processorId: error.processorId
16030
16273
  };
16031
16274
  } else {
16032
- throw new chunkHWMMIRIF_cjs.MastraError(
16275
+ throw new chunk4U7ZLI36_cjs.MastraError(
16033
16276
  {
16034
16277
  id: "AGENT_INPUT_PROCESSOR_ERROR",
16035
16278
  domain: "AGENT" /* AGENT */,
@@ -16151,7 +16394,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16151
16394
  tracingPolicy: this.#options?.tracingPolicy,
16152
16395
  requireApproval: tool2.requireApproval
16153
16396
  };
16154
- return [k, chunkO3ULBGV6_cjs.makeCoreTool(tool2, options, void 0, autoResumeSuspendedTools)];
16397
+ return [k, chunkAQ22JIR7_cjs.makeCoreTool(tool2, options, void 0, autoResumeSuspendedTools)];
16155
16398
  })
16156
16399
  );
16157
16400
  const assignedToolEntriesConverted = Object.fromEntries(
@@ -16201,7 +16444,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16201
16444
  tracingPolicy: this.#options?.tracingPolicy,
16202
16445
  requireApproval: toolObj.requireApproval
16203
16446
  };
16204
- const convertedToCoreTool = chunkO3ULBGV6_cjs.makeCoreTool(toolObj, options, "toolset", autoResumeSuspendedTools);
16447
+ const convertedToCoreTool = chunkAQ22JIR7_cjs.makeCoreTool(toolObj, options, "toolset", autoResumeSuspendedTools);
16205
16448
  toolsForRequest[toolName] = convertedToCoreTool;
16206
16449
  }
16207
16450
  }
@@ -16246,7 +16489,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16246
16489
  tracingPolicy: this.#options?.tracingPolicy,
16247
16490
  requireApproval: tool2.requireApproval
16248
16491
  };
16249
- const convertedToCoreTool = chunkO3ULBGV6_cjs.makeCoreTool(rest, options, "client-tool", autoResumeSuspendedTools);
16492
+ const convertedToCoreTool = chunkAQ22JIR7_cjs.makeCoreTool(rest, options, "client-tool", autoResumeSuspendedTools);
16250
16493
  toolsForRequest[toolName] = convertedToCoreTool;
16251
16494
  }
16252
16495
  }
@@ -16284,7 +16527,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16284
16527
  subAgentResourceId: z8.z.string().describe("The resource ID of the agent").optional()
16285
16528
  });
16286
16529
  const modelVersion = (await agent.getModel({ requestContext })).specificationVersion;
16287
- const toolObj = chunkZ55SJVEC_cjs.createTool({
16530
+ const toolObj = chunk6YUHA5UH_cjs.createTool({
16288
16531
  id: `agent-${agentName}`,
16289
16532
  description: agent.getDescription() || `Agent: ${agentName}`,
16290
16533
  inputSchema: agentInputSchema,
@@ -16380,7 +16623,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16380
16623
  }
16381
16624
  return result;
16382
16625
  } catch (err) {
16383
- const mastraError = new chunkHWMMIRIF_cjs.MastraError(
16626
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError(
16384
16627
  {
16385
16628
  id: "AGENT_AGENT_TOOL_EXECUTION_FAILED",
16386
16629
  domain: "AGENT" /* AGENT */,
@@ -16416,7 +16659,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16416
16659
  tracingContext,
16417
16660
  tracingPolicy: this.#options?.tracingPolicy
16418
16661
  };
16419
- convertedAgentTools[`agent-${agentName}`] = chunkO3ULBGV6_cjs.makeCoreTool(
16662
+ convertedAgentTools[`agent-${agentName}`] = chunkAQ22JIR7_cjs.makeCoreTool(
16420
16663
  toolObj,
16421
16664
  options,
16422
16665
  void 0,
@@ -16447,7 +16690,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16447
16690
  inputData: workflow.inputSchema,
16448
16691
  ...workflow.stateSchema ? { initialState: workflow.stateSchema } : {}
16449
16692
  });
16450
- const toolObj = chunkZ55SJVEC_cjs.createTool({
16693
+ const toolObj = chunk6YUHA5UH_cjs.createTool({
16451
16694
  id: `workflow-${workflowName}`,
16452
16695
  description: workflow.description || `Workflow: ${workflowName}`,
16453
16696
  inputSchema: extendedInputSchema,
@@ -16560,7 +16803,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16560
16803
  };
16561
16804
  }
16562
16805
  } catch (err) {
16563
- const mastraError = new chunkHWMMIRIF_cjs.MastraError(
16806
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError(
16564
16807
  {
16565
16808
  id: "AGENT_WORKFLOW_TOOL_EXECUTION_FAILED",
16566
16809
  domain: "AGENT" /* AGENT */,
@@ -16595,7 +16838,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16595
16838
  tracingContext,
16596
16839
  tracingPolicy: this.#options?.tracingPolicy
16597
16840
  };
16598
- convertedWorkflowTools[`workflow-${workflowName}`] = chunkO3ULBGV6_cjs.makeCoreTool(
16841
+ convertedWorkflowTools[`workflow-${workflowName}`] = chunkAQ22JIR7_cjs.makeCoreTool(
16599
16842
  toolObj,
16600
16843
  options,
16601
16844
  void 0,
@@ -16625,7 +16868,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16625
16868
  let mastraProxy = void 0;
16626
16869
  const logger = this.logger;
16627
16870
  if (this.#mastra) {
16628
- mastraProxy = chunkO3ULBGV6_cjs.createMastraProxy({ mastra: this.#mastra, logger });
16871
+ mastraProxy = chunkAQ22JIR7_cjs.createMastraProxy({ mastra: this.#mastra, logger });
16629
16872
  }
16630
16873
  const assignedTools = await this.listAssignedTools({
16631
16874
  runId,
@@ -16709,7 +16952,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16709
16952
  }
16710
16953
  newKey = newKey.slice(0, 63);
16711
16954
  if (tools[newKey]) {
16712
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
16955
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
16713
16956
  id: "AGENT_TOOL_NAME_COLLISION",
16714
16957
  domain: "AGENT" /* AGENT */,
16715
16958
  category: "USER" /* USER */,
@@ -16813,7 +17056,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16813
17056
  if (typeof scorerObject.scorer === "string") {
16814
17057
  try {
16815
17058
  if (!this.#mastra) {
16816
- throw new chunkHWMMIRIF_cjs.MastraError({
17059
+ throw new chunk4U7ZLI36_cjs.MastraError({
16817
17060
  id: "AGENT_GENEREATE_SCORER_NOT_FOUND",
16818
17061
  domain: "AGENT" /* AGENT */,
16819
17062
  category: "USER" /* USER */,
@@ -16830,7 +17073,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16830
17073
  }
16831
17074
  }
16832
17075
  if (Object.keys(result).length === 0 && Object.keys(overrideScorers).length > 0) {
16833
- throw new chunkHWMMIRIF_cjs.MastraError({
17076
+ throw new chunk4U7ZLI36_cjs.MastraError({
16834
17077
  id: "AGENT_GENEREATE_SCORER_NOT_FOUND",
16835
17078
  domain: "AGENT" /* AGENT */,
16836
17079
  category: "USER" /* USER */,
@@ -16851,7 +17094,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16851
17094
  requestContext
16852
17095
  );
16853
17096
  if (!isSupportedLanguageModel(resolvedModel)) {
16854
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
17097
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
16855
17098
  id: "AGENT_PREPARE_MODELS_INCOMPATIBLE_WITH_MODEL_ARRAY_V1",
16856
17099
  domain: "AGENT" /* AGENT */,
16857
17100
  category: "USER" /* USER */,
@@ -16865,7 +17108,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16865
17108
  throw mastraError;
16866
17109
  }
16867
17110
  let headers;
16868
- if (resolvedModel instanceof chunk53SZJCBX_cjs.ModelRouterLanguageModel) {
17111
+ if (resolvedModel instanceof chunk4KVIXN7K_cjs.ModelRouterLanguageModel) {
16869
17112
  headers = resolvedModel.config?.headers;
16870
17113
  }
16871
17114
  return [
@@ -16882,7 +17125,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16882
17125
  this.model.map(async (modelConfig) => {
16883
17126
  const model2 = await this.resolveModelConfig(modelConfig.model, requestContext);
16884
17127
  if (!isSupportedLanguageModel(model2)) {
16885
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
17128
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
16886
17129
  id: "AGENT_PREPARE_MODELS_INCOMPATIBLE_WITH_MODEL_ARRAY_V1",
16887
17130
  domain: "AGENT" /* AGENT */,
16888
17131
  category: "USER" /* USER */,
@@ -16897,7 +17140,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16897
17140
  }
16898
17141
  const modelId = modelConfig.id || model2.modelId;
16899
17142
  if (!modelId) {
16900
- const mastraError = new chunkHWMMIRIF_cjs.MastraError({
17143
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError({
16901
17144
  id: "AGENT_PREPARE_MODELS_MISSING_MODEL_ID",
16902
17145
  domain: "AGENT" /* AGENT */,
16903
17146
  category: "USER" /* USER */,
@@ -16911,7 +17154,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16911
17154
  throw mastraError;
16912
17155
  }
16913
17156
  let headers;
16914
- if (model2 instanceof chunk53SZJCBX_cjs.ModelRouterLanguageModel) {
17157
+ if (model2 instanceof chunk4KVIXN7K_cjs.ModelRouterLanguageModel) {
16915
17158
  headers = model2.config?.headers;
16916
17159
  }
16917
17160
  return {
@@ -16971,7 +17214,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16971
17214
  const targetProvider = structuredOutputModel.provider;
16972
17215
  const targetModelId = structuredOutputModel.modelId;
16973
17216
  if (targetProvider.includes("openai") || targetModelId.includes("openai")) {
16974
- if (chunkO3ULBGV6_cjs.isZodType(options.structuredOutput.schema) && targetModelId) {
17217
+ if (chunkAQ22JIR7_cjs.isZodType(options.structuredOutput.schema) && targetModelId) {
16975
17218
  const modelInfo = {
16976
17219
  provider: targetProvider,
16977
17220
  modelId: targetModelId,
@@ -16990,13 +17233,14 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
16990
17233
  }
16991
17234
  const runId = options.runId || this.#mastra?.generateId() || crypto2.randomUUID();
16992
17235
  const instructions = options.instructions || await this.getInstructions({ requestContext });
16993
- const agentSpan = chunk72YCRTEX_cjs.getOrCreateSpan({
17236
+ const agentSpan = chunkZSZOYPSJ_cjs.getOrCreateSpan({
16994
17237
  type: "agent_run" /* AGENT_RUN */,
16995
17238
  name: `agent run: '${this.id}'`,
17239
+ entityType: "agent" /* AGENT */,
17240
+ entityId: this.id,
17241
+ entityName: this.name,
16996
17242
  input: options.messages,
16997
17243
  attributes: {
16998
- agentId: this.id,
16999
- agentName: this.name,
17000
17244
  conversationId: threadFromArgs?.id,
17001
17245
  instructions: this.#convertInstructionsToString(instructions)
17002
17246
  },
@@ -17166,10 +17410,10 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
17166
17410
  }
17167
17411
  }
17168
17412
  } catch (e) {
17169
- if (e instanceof chunkHWMMIRIF_cjs.MastraError) {
17413
+ if (e instanceof chunk4U7ZLI36_cjs.MastraError) {
17170
17414
  throw e;
17171
17415
  }
17172
- const mastraError = new chunkHWMMIRIF_cjs.MastraError(
17416
+ const mastraError = new chunk4U7ZLI36_cjs.MastraError(
17173
17417
  {
17174
17418
  id: "AGENT_MEMORY_PERSIST_RESPONSE_MESSAGES_FAILED",
17175
17419
  domain: "AGENT" /* AGENT */,
@@ -17283,7 +17527,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
17283
17527
  if (!isSupportedLanguageModel(modelInfo)) {
17284
17528
  const modelId = modelInfo.modelId || "unknown";
17285
17529
  const provider = modelInfo.provider || "unknown";
17286
- throw new chunkHWMMIRIF_cjs.MastraError({
17530
+ throw new chunk4U7ZLI36_cjs.MastraError({
17287
17531
  id: "AGENT_GENERATE_V1_MODEL_NOT_SUPPORTED",
17288
17532
  domain: "AGENT" /* AGENT */,
17289
17533
  category: "USER" /* USER */,
@@ -17306,7 +17550,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
17306
17550
  const result = await this.#execute(executeOptions);
17307
17551
  if (result.status !== "success") {
17308
17552
  if (result.status === "failed") {
17309
- throw new chunkHWMMIRIF_cjs.MastraError(
17553
+ throw new chunk4U7ZLI36_cjs.MastraError(
17310
17554
  {
17311
17555
  id: "AGENT_GENERATE_FAILED",
17312
17556
  domain: "AGENT" /* AGENT */,
@@ -17316,7 +17560,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
17316
17560
  result.error
17317
17561
  );
17318
17562
  }
17319
- throw new chunkHWMMIRIF_cjs.MastraError({
17563
+ throw new chunk4U7ZLI36_cjs.MastraError({
17320
17564
  id: "AGENT_GENERATE_UNKNOWN_ERROR",
17321
17565
  domain: "AGENT" /* AGENT */,
17322
17566
  category: "USER" /* USER */,
@@ -17345,7 +17589,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
17345
17589
  if (!isSupportedLanguageModel(modelInfo)) {
17346
17590
  const modelId = modelInfo.modelId || "unknown";
17347
17591
  const provider = modelInfo.provider || "unknown";
17348
- throw new chunkHWMMIRIF_cjs.MastraError({
17592
+ throw new chunk4U7ZLI36_cjs.MastraError({
17349
17593
  id: "AGENT_STREAM_V1_MODEL_NOT_SUPPORTED",
17350
17594
  domain: "AGENT" /* AGENT */,
17351
17595
  category: "USER" /* USER */,
@@ -17368,7 +17612,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
17368
17612
  const result = await this.#execute(executeOptions);
17369
17613
  if (result.status !== "success") {
17370
17614
  if (result.status === "failed") {
17371
- throw new chunkHWMMIRIF_cjs.MastraError(
17615
+ throw new chunk4U7ZLI36_cjs.MastraError(
17372
17616
  {
17373
17617
  id: "AGENT_STREAM_FAILED",
17374
17618
  domain: "AGENT" /* AGENT */,
@@ -17378,7 +17622,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
17378
17622
  result.error
17379
17623
  );
17380
17624
  }
17381
- throw new chunkHWMMIRIF_cjs.MastraError({
17625
+ throw new chunk4U7ZLI36_cjs.MastraError({
17382
17626
  id: "AGENT_STREAM_UNKNOWN_ERROR",
17383
17627
  domain: "AGENT" /* AGENT */,
17384
17628
  category: "USER" /* USER */,
@@ -17412,14 +17656,15 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
17412
17656
  requestContext: mergedStreamOptions.requestContext
17413
17657
  });
17414
17658
  if (!isSupportedLanguageModel(llm.getModel())) {
17415
- throw new chunkHWMMIRIF_cjs.MastraError({
17659
+ throw new chunk4U7ZLI36_cjs.MastraError({
17416
17660
  id: "AGENT_STREAM_V1_MODEL_NOT_SUPPORTED",
17417
17661
  domain: "AGENT" /* AGENT */,
17418
17662
  category: "USER" /* USER */,
17419
17663
  text: "V1 models are not supported for stream. Please use streamLegacy instead."
17420
17664
  });
17421
17665
  }
17422
- const existingSnapshot = await this.#mastra?.getStorage()?.loadWorkflowSnapshot({
17666
+ const workflowsStore = await this.#mastra?.getStorage()?.getStore("workflows");
17667
+ const existingSnapshot = await workflowsStore?.loadWorkflowSnapshot({
17423
17668
  workflowName: "agentic-loop",
17424
17669
  runId: streamOptions?.runId ?? ""
17425
17670
  });
@@ -17434,7 +17679,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
17434
17679
  });
17435
17680
  if (result.status !== "success") {
17436
17681
  if (result.status === "failed") {
17437
- throw new chunkHWMMIRIF_cjs.MastraError(
17682
+ throw new chunk4U7ZLI36_cjs.MastraError(
17438
17683
  {
17439
17684
  id: "AGENT_STREAM_FAILED",
17440
17685
  domain: "AGENT" /* AGENT */,
@@ -17444,7 +17689,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
17444
17689
  result.error
17445
17690
  );
17446
17691
  }
17447
- throw new chunkHWMMIRIF_cjs.MastraError({
17692
+ throw new chunk4U7ZLI36_cjs.MastraError({
17448
17693
  id: "AGENT_STREAM_UNKNOWN_ERROR",
17449
17694
  domain: "AGENT" /* AGENT */,
17450
17695
  category: "USER" /* USER */,
@@ -19487,6 +19732,50 @@ var ToolCallFilter = class {
19487
19732
  }
19488
19733
  };
19489
19734
 
19735
+ // src/memory/working-memory-utils.ts
19736
+ var WORKING_MEMORY_START_TAG = "<working_memory>";
19737
+ var WORKING_MEMORY_END_TAG = "</working_memory>";
19738
+ function extractWorkingMemoryTags(text) {
19739
+ const results = [];
19740
+ let pos = 0;
19741
+ while (pos < text.length) {
19742
+ const start = text.indexOf(WORKING_MEMORY_START_TAG, pos);
19743
+ if (start === -1) break;
19744
+ const end = text.indexOf(WORKING_MEMORY_END_TAG, start + WORKING_MEMORY_START_TAG.length);
19745
+ if (end === -1) break;
19746
+ results.push(text.substring(start, end + WORKING_MEMORY_END_TAG.length));
19747
+ pos = end + WORKING_MEMORY_END_TAG.length;
19748
+ }
19749
+ return results.length > 0 ? results : null;
19750
+ }
19751
+ function removeWorkingMemoryTags(text) {
19752
+ let result = "";
19753
+ let pos = 0;
19754
+ while (pos < text.length) {
19755
+ const start = text.indexOf(WORKING_MEMORY_START_TAG, pos);
19756
+ if (start === -1) {
19757
+ result += text.substring(pos);
19758
+ break;
19759
+ }
19760
+ result += text.substring(pos, start);
19761
+ const end = text.indexOf(WORKING_MEMORY_END_TAG, start + WORKING_MEMORY_START_TAG.length);
19762
+ if (end === -1) {
19763
+ result += text.substring(start);
19764
+ break;
19765
+ }
19766
+ pos = end + WORKING_MEMORY_END_TAG.length;
19767
+ }
19768
+ return result;
19769
+ }
19770
+ function extractWorkingMemoryContent(text) {
19771
+ const start = text.indexOf(WORKING_MEMORY_START_TAG);
19772
+ if (start === -1) return null;
19773
+ const contentStart = start + WORKING_MEMORY_START_TAG.length;
19774
+ const end = text.indexOf(WORKING_MEMORY_END_TAG, contentStart);
19775
+ if (end === -1) return null;
19776
+ return text.substring(contentStart, end);
19777
+ }
19778
+
19490
19779
  // src/processors/memory/message-history.ts
19491
19780
  var MessageHistory = class {
19492
19781
  id = "message-history";
@@ -19529,25 +19818,43 @@ var MessageHistory = class {
19529
19818
  }
19530
19819
  return messageList;
19531
19820
  }
19532
- filterIncompleteToolCalls(messages) {
19821
+ /**
19822
+ * Filters messages before persisting to storage:
19823
+ * 1. Removes incomplete tool calls (state === 'call' or 'partial-call')
19824
+ * 2. Removes updateWorkingMemory tool invocations (hide args from message history)
19825
+ * 3. Strips <working_memory> tags from text content
19826
+ */
19827
+ filterMessagesForPersistence(messages) {
19533
19828
  return messages.map((m) => {
19534
- if (m.role === `assistant`) {
19535
- const assistant = {
19536
- ...m,
19537
- content: {
19538
- ...m.content,
19539
- parts: m.content.parts.map((p) => {
19540
- if (p.type === `tool-invocation` && (p.toolInvocation.state === `call` || p.toolInvocation.state === `partial-call`)) {
19541
- return null;
19542
- }
19543
- return p;
19544
- }).filter((p) => Boolean(p))
19829
+ const newMessage = { ...m };
19830
+ if (m.content && typeof m.content === "object" && !Array.isArray(m.content)) {
19831
+ newMessage.content = { ...m.content };
19832
+ }
19833
+ if (typeof newMessage.content?.content === "string" && newMessage.content.content.length > 0) {
19834
+ newMessage.content.content = removeWorkingMemoryTags(newMessage.content.content).trim();
19835
+ }
19836
+ if (Array.isArray(newMessage.content?.parts)) {
19837
+ newMessage.content.parts = newMessage.content.parts.map((p) => {
19838
+ if (p.type === `tool-invocation` && (p.toolInvocation.state === `call` || p.toolInvocation.state === `partial-call`)) {
19839
+ return null;
19545
19840
  }
19546
- };
19547
- if (assistant.content.parts.length === 0) return null;
19548
- return assistant;
19841
+ if (p.type === `tool-invocation` && p.toolInvocation.toolName === `updateWorkingMemory`) {
19842
+ return null;
19843
+ }
19844
+ if (p.type === `text`) {
19845
+ const text = typeof p.text === "string" ? p.text : "";
19846
+ return {
19847
+ ...p,
19848
+ text: removeWorkingMemoryTags(text).trim()
19849
+ };
19850
+ }
19851
+ return p;
19852
+ }).filter((p) => Boolean(p));
19853
+ if (newMessage.content.parts.length === 0) {
19854
+ return null;
19855
+ }
19549
19856
  }
19550
- return m;
19857
+ return newMessage;
19551
19858
  }).filter((m) => Boolean(m));
19552
19859
  }
19553
19860
  async processOutputResult(args) {
@@ -19564,7 +19871,7 @@ var MessageHistory = class {
19564
19871
  if (messagesToSave.length === 0) {
19565
19872
  return messageList;
19566
19873
  }
19567
- const filtered = this.filterIncompleteToolCalls(messagesToSave);
19874
+ const filtered = this.filterMessagesForPersistence(messagesToSave);
19568
19875
  await this.storage.saveMessages({ messages: filtered });
19569
19876
  const thread = await this.storage.getThreadById({ threadId });
19570
19877
  if (thread) {
@@ -19828,7 +20135,7 @@ var SemanticRecall = class {
19828
20135
  */
19829
20136
  formatCrossThreadMessages(messages, currentThreadId) {
19830
20137
  let result = ``;
19831
- const v1Messages = new chunk72E3YF6A_cjs.MessageList().add(messages, "memory").get.all.v1();
20138
+ const v1Messages = new chunkEMLEZXTQ_cjs.MessageList().add(messages, "memory").get.all.v1();
19832
20139
  let lastYmd = null;
19833
20140
  for (const msg of v1Messages) {
19834
20141
  const date = msg.createdAt;
@@ -20178,6 +20485,7 @@ var MastraMemory = class extends chunkDGV2FWB4_cjs.MastraBase {
20178
20485
  _storage;
20179
20486
  vector;
20180
20487
  embedder;
20488
+ embedderOptions;
20181
20489
  threadConfig = { ...memoryDefaultOptions };
20182
20490
  #mastra;
20183
20491
  constructor(config) {
@@ -20233,7 +20541,7 @@ https://mastra.ai/en/docs/memory/semantic-recall`
20233
20541
  );
20234
20542
  }
20235
20543
  if (typeof config.embedder === "string") {
20236
- this.embedder = new chunk53SZJCBX_cjs.ModelRouterEmbeddingModel(config.embedder);
20544
+ this.embedder = new chunk4KVIXN7K_cjs.ModelRouterEmbeddingModel(config.embedder);
20237
20545
  } else {
20238
20546
  this.embedder = config.embedder;
20239
20547
  }
@@ -20268,7 +20576,11 @@ https://mastra.ai/en/docs/memory/overview`
20268
20576
  this.vector = vector;
20269
20577
  }
20270
20578
  setEmbedder(embedder) {
20271
- this.embedder = embedder;
20579
+ if (typeof embedder === "string") {
20580
+ this.embedder = new chunk4KVIXN7K_cjs.ModelRouterEmbeddingModel(embedder);
20581
+ } else {
20582
+ this.embedder = embedder;
20583
+ }
20272
20584
  }
20273
20585
  /**
20274
20586
  * Get a system message to inject into the conversation.
@@ -20329,7 +20641,7 @@ https://mastra.ai/en/docs/memory/overview`
20329
20641
  "The threads.generateTitle option has been moved. Use the top-level generateTitle option instead."
20330
20642
  );
20331
20643
  }
20332
- const mergedConfig = chunkO3ULBGV6_cjs.deepMerge(this.threadConfig, config || {});
20644
+ const mergedConfig = chunkAQ22JIR7_cjs.deepMerge(this.threadConfig, config || {});
20333
20645
  if (typeof config?.workingMemory === "object" && config.workingMemory?.schema && typeof mergedConfig.workingMemory === "object") {
20334
20646
  mergedConfig.workingMemory.schema = config.workingMemory.schema;
20335
20647
  }
@@ -20390,15 +20702,16 @@ https://mastra.ai/en/docs/memory/overview`
20390
20702
  * @param configuredProcessors - Processors already configured by the user (for deduplication)
20391
20703
  * @returns Array of input processors configured for this memory instance
20392
20704
  */
20393
- getInputProcessors(configuredProcessors = [], context) {
20705
+ async getInputProcessors(configuredProcessors = [], context) {
20706
+ const memoryStore = await this.storage.getStore("memory");
20394
20707
  const processors = [];
20395
20708
  const memoryContext = context?.get("MastraMemory");
20396
20709
  const runtimeMemoryConfig = memoryContext?.memoryConfig;
20397
20710
  const effectiveConfig = runtimeMemoryConfig ? this.getMergedThreadConfig(runtimeMemoryConfig) : this.threadConfig;
20398
20711
  const isWorkingMemoryEnabled = typeof effectiveConfig.workingMemory === "object" && effectiveConfig.workingMemory.enabled !== false;
20399
20712
  if (isWorkingMemoryEnabled) {
20400
- if (!this.storage?.stores?.memory)
20401
- throw new chunkHWMMIRIF_cjs.MastraError({
20713
+ if (!memoryStore)
20714
+ throw new chunk4U7ZLI36_cjs.MastraError({
20402
20715
  category: "USER",
20403
20716
  domain: "STORAGE" /* STORAGE */,
20404
20717
  id: "WORKING_MEMORY_MISSING_STORAGE_ADAPTER",
@@ -20415,7 +20728,7 @@ https://mastra.ai/en/docs/memory/overview`
20415
20728
  }
20416
20729
  processors.push(
20417
20730
  new WorkingMemory({
20418
- storage: this.storage.stores.memory,
20731
+ storage: memoryStore,
20419
20732
  template,
20420
20733
  scope: typeof effectiveConfig.workingMemory === "object" ? effectiveConfig.workingMemory.scope : void 0,
20421
20734
  useVNext: typeof effectiveConfig.workingMemory === "object" && "version" in effectiveConfig.workingMemory && effectiveConfig.workingMemory.version === "vnext",
@@ -20426,8 +20739,8 @@ https://mastra.ai/en/docs/memory/overview`
20426
20739
  }
20427
20740
  const lastMessages = effectiveConfig.lastMessages;
20428
20741
  if (lastMessages) {
20429
- if (!this.storage?.stores?.memory)
20430
- throw new chunkHWMMIRIF_cjs.MastraError({
20742
+ if (!memoryStore)
20743
+ throw new chunk4U7ZLI36_cjs.MastraError({
20431
20744
  category: "USER",
20432
20745
  domain: "STORAGE" /* STORAGE */,
20433
20746
  id: "MESSAGE_HISTORY_MISSING_STORAGE_ADAPTER",
@@ -20437,29 +20750,29 @@ https://mastra.ai/en/docs/memory/overview`
20437
20750
  if (!hasMessageHistory) {
20438
20751
  processors.push(
20439
20752
  new MessageHistory({
20440
- storage: this.storage.stores.memory,
20753
+ storage: memoryStore,
20441
20754
  lastMessages: typeof lastMessages === "number" ? lastMessages : void 0
20442
20755
  })
20443
20756
  );
20444
20757
  }
20445
20758
  }
20446
20759
  if (effectiveConfig.semanticRecall) {
20447
- if (!this.storage?.stores?.memory)
20448
- throw new chunkHWMMIRIF_cjs.MastraError({
20760
+ if (!memoryStore)
20761
+ throw new chunk4U7ZLI36_cjs.MastraError({
20449
20762
  category: "USER",
20450
20763
  domain: "STORAGE" /* STORAGE */,
20451
20764
  id: "SEMANTIC_RECALL_MISSING_STORAGE_ADAPTER",
20452
20765
  text: "Using Mastra Memory semantic recall requires a storage adapter but no attached adapter was detected."
20453
20766
  });
20454
20767
  if (!this.vector)
20455
- throw new chunkHWMMIRIF_cjs.MastraError({
20768
+ throw new chunk4U7ZLI36_cjs.MastraError({
20456
20769
  category: "USER",
20457
20770
  domain: "MASTRA_VECTOR" /* MASTRA_VECTOR */,
20458
20771
  id: "SEMANTIC_RECALL_MISSING_VECTOR_ADAPTER",
20459
20772
  text: "Using Mastra Memory semantic recall requires a vector adapter but no attached adapter was detected."
20460
20773
  });
20461
20774
  if (!this.embedder)
20462
- throw new chunkHWMMIRIF_cjs.MastraError({
20775
+ throw new chunk4U7ZLI36_cjs.MastraError({
20463
20776
  category: "USER",
20464
20777
  domain: "MASTRA_VECTOR" /* MASTRA_VECTOR */,
20465
20778
  id: "SEMANTIC_RECALL_MISSING_EMBEDDER",
@@ -20471,7 +20784,7 @@ https://mastra.ai/en/docs/memory/overview`
20471
20784
  const indexName = this.getEmbeddingIndexName();
20472
20785
  processors.push(
20473
20786
  new SemanticRecall({
20474
- storage: this.storage.stores.memory,
20787
+ storage: memoryStore,
20475
20788
  vector: this.vector,
20476
20789
  embedder: this.embedder,
20477
20790
  indexName,
@@ -20488,7 +20801,8 @@ https://mastra.ai/en/docs/memory/overview`
20488
20801
  * @param configuredProcessors - Processors already configured by the user (for deduplication)
20489
20802
  * @returns Array of output processors configured for this memory instance
20490
20803
  */
20491
- getOutputProcessors(configuredProcessors = [], context) {
20804
+ async getOutputProcessors(configuredProcessors = [], context) {
20805
+ const memoryStore = await this.storage.getStore("memory");
20492
20806
  const processors = [];
20493
20807
  const memoryContext = context?.get("MastraMemory");
20494
20808
  const runtimeMemoryConfig = memoryContext?.memoryConfig;
@@ -20497,22 +20811,22 @@ https://mastra.ai/en/docs/memory/overview`
20497
20811
  return [];
20498
20812
  }
20499
20813
  if (effectiveConfig.semanticRecall) {
20500
- if (!this.storage?.stores?.memory)
20501
- throw new chunkHWMMIRIF_cjs.MastraError({
20814
+ if (!memoryStore)
20815
+ throw new chunk4U7ZLI36_cjs.MastraError({
20502
20816
  category: "USER",
20503
20817
  domain: "STORAGE" /* STORAGE */,
20504
20818
  id: "SEMANTIC_RECALL_MISSING_STORAGE_ADAPTER",
20505
20819
  text: "Using Mastra Memory semantic recall requires a storage adapter but no attached adapter was detected."
20506
20820
  });
20507
20821
  if (!this.vector)
20508
- throw new chunkHWMMIRIF_cjs.MastraError({
20822
+ throw new chunk4U7ZLI36_cjs.MastraError({
20509
20823
  category: "USER",
20510
20824
  domain: "MASTRA_VECTOR" /* MASTRA_VECTOR */,
20511
20825
  id: "SEMANTIC_RECALL_MISSING_VECTOR_ADAPTER",
20512
20826
  text: "Using Mastra Memory semantic recall requires a vector adapter but no attached adapter was detected."
20513
20827
  });
20514
20828
  if (!this.embedder)
20515
- throw new chunkHWMMIRIF_cjs.MastraError({
20829
+ throw new chunk4U7ZLI36_cjs.MastraError({
20516
20830
  category: "USER",
20517
20831
  domain: "MASTRA_VECTOR" /* MASTRA_VECTOR */,
20518
20832
  id: "SEMANTIC_RECALL_MISSING_EMBEDDER",
@@ -20524,7 +20838,7 @@ https://mastra.ai/en/docs/memory/overview`
20524
20838
  const indexName = this.getEmbeddingIndexName();
20525
20839
  processors.push(
20526
20840
  new SemanticRecall({
20527
- storage: this.storage.stores.memory,
20841
+ storage: memoryStore,
20528
20842
  vector: this.vector,
20529
20843
  embedder: this.embedder,
20530
20844
  indexName,
@@ -20535,8 +20849,8 @@ https://mastra.ai/en/docs/memory/overview`
20535
20849
  }
20536
20850
  const lastMessages = effectiveConfig.lastMessages;
20537
20851
  if (lastMessages) {
20538
- if (!this.storage?.stores?.memory)
20539
- throw new chunkHWMMIRIF_cjs.MastraError({
20852
+ if (!memoryStore)
20853
+ throw new chunk4U7ZLI36_cjs.MastraError({
20540
20854
  category: "USER",
20541
20855
  domain: "STORAGE" /* STORAGE */,
20542
20856
  id: "MESSAGE_HISTORY_MISSING_STORAGE_ADAPTER",
@@ -20546,7 +20860,7 @@ https://mastra.ai/en/docs/memory/overview`
20546
20860
  if (!hasMessageHistory) {
20547
20861
  processors.push(
20548
20862
  new MessageHistory({
20549
- storage: this.storage.stores.memory,
20863
+ storage: memoryStore,
20550
20864
  lastMessages: typeof lastMessages === "number" ? lastMessages : void 0
20551
20865
  })
20552
20866
  );
@@ -20565,7 +20879,7 @@ var MockMemory = class extends MastraMemory {
20565
20879
  } = {}) {
20566
20880
  super({
20567
20881
  name: "mock",
20568
- storage: storage || new chunkETWAR2YE_cjs.InMemoryStore(),
20882
+ storage: storage || new chunkOXV6QFSV_cjs.InMemoryStore(),
20569
20883
  options: {
20570
20884
  workingMemory: enableWorkingMemory ? { enabled: true, template: workingMemoryTemplate } : void 0,
20571
20885
  lastMessages: enableMessageHistory ? 10 : void 0
@@ -20573,22 +20887,39 @@ var MockMemory = class extends MastraMemory {
20573
20887
  });
20574
20888
  this._hasOwnStorage = true;
20575
20889
  }
20890
+ async getMemoryStore() {
20891
+ const store = await this.storage.getStore("memory");
20892
+ if (!store) {
20893
+ throw new chunk4U7ZLI36_cjs.MastraError({
20894
+ id: "MASTRA_MEMORY_STORAGE_NOT_AVAILABLE",
20895
+ domain: "MASTRA_MEMORY" /* MASTRA_MEMORY */,
20896
+ category: "SYSTEM" /* SYSTEM */,
20897
+ text: "Memory storage is not supported by this storage adapter"
20898
+ });
20899
+ }
20900
+ return store;
20901
+ }
20576
20902
  async getThreadById({ threadId }) {
20577
- return this.storage.getThreadById({ threadId });
20903
+ const memoryStorage = await this.getMemoryStore();
20904
+ return memoryStorage.getThreadById({ threadId });
20578
20905
  }
20579
20906
  async saveThread({ thread }) {
20580
- return this.storage.saveThread({ thread });
20907
+ const memoryStorage = await this.getMemoryStore();
20908
+ return memoryStorage.saveThread({ thread });
20581
20909
  }
20582
20910
  async saveMessages({
20583
20911
  messages
20584
20912
  }) {
20585
- return this.storage.saveMessages({ messages });
20913
+ const memoryStorage = await this.getMemoryStore();
20914
+ return memoryStorage.saveMessages({ messages });
20586
20915
  }
20587
20916
  async listThreadsByResourceId(args) {
20588
- return this.storage.listThreadsByResourceId(args);
20917
+ const memoryStorage = await this.getMemoryStore();
20918
+ return memoryStorage.listThreadsByResourceId(args);
20589
20919
  }
20590
20920
  async recall(args) {
20591
- const result = await this.storage.listMessages({
20921
+ const memoryStorage = await this.getMemoryStore();
20922
+ const result = await memoryStorage.listMessages({
20592
20923
  threadId: args.threadId,
20593
20924
  resourceId: args.resourceId,
20594
20925
  perPage: args.perPage,
@@ -20600,11 +20931,13 @@ var MockMemory = class extends MastraMemory {
20600
20931
  return result;
20601
20932
  }
20602
20933
  async deleteThread(threadId) {
20603
- return this.storage.deleteThread({ threadId });
20934
+ const memoryStorage = await this.getMemoryStore();
20935
+ return memoryStorage.deleteThread({ threadId });
20604
20936
  }
20605
20937
  async deleteMessages(messageIds) {
20938
+ const memoryStorage = await this.getMemoryStore();
20606
20939
  const ids = Array.isArray(messageIds) ? messageIds?.map((item) => typeof item === "string" ? item : item.id) : [messageIds];
20607
- return this.storage.deleteMessages(ids);
20940
+ return memoryStorage.deleteMessages(ids);
20608
20941
  }
20609
20942
  async getWorkingMemory({
20610
20943
  threadId,
@@ -20621,12 +20954,17 @@ var MockMemory = class extends MastraMemory {
20621
20954
  if (!id) {
20622
20955
  return null;
20623
20956
  }
20624
- const resource = await this.storage.getResourceById({ resourceId: id });
20957
+ const memoryStorage = await this.getMemoryStore();
20958
+ const resource = await memoryStorage.getResourceById({ resourceId: id });
20625
20959
  return resource?.workingMemory || null;
20626
20960
  }
20627
20961
  listTools(_config) {
20962
+ const mergedConfig = this.getMergedThreadConfig(_config);
20963
+ if (!mergedConfig.workingMemory?.enabled) {
20964
+ return {};
20965
+ }
20628
20966
  return {
20629
- updateWorkingMemory: chunkZ55SJVEC_cjs.createTool({
20967
+ updateWorkingMemory: chunk6YUHA5UH_cjs.createTool({
20630
20968
  id: "update-working-memory",
20631
20969
  description: `Update the working memory with new information. Any data not included will be overwritten.`,
20632
20970
  inputSchema: z8__default.default.object({ memory: z8__default.default.string() }),
@@ -20709,7 +21047,8 @@ var MockMemory = class extends MastraMemory {
20709
21047
  if (!id) {
20710
21048
  throw new Error(`Cannot update working memory: ${scope} ID is required`);
20711
21049
  }
20712
- await this.storage.updateResource({
21050
+ const memoryStorage = await this.getMemoryStore();
21051
+ await memoryStorage.updateResource({
20713
21052
  resourceId: id,
20714
21053
  workingMemory
20715
21054
  });
@@ -20784,6 +21123,8 @@ exports.ToolCallFilter = ToolCallFilter;
20784
21123
  exports.ToolInvocationPartSchema = ToolInvocationPartSchema;
20785
21124
  exports.TripWire = TripWire;
20786
21125
  exports.UnicodeNormalizer = UnicodeNormalizer;
21126
+ exports.WORKING_MEMORY_END_TAG = WORKING_MEMORY_END_TAG;
21127
+ exports.WORKING_MEMORY_START_TAG = WORKING_MEMORY_START_TAG;
20787
21128
  exports.Workflow = Workflow;
20788
21129
  exports.WorkflowRunOutput = WorkflowRunOutput;
20789
21130
  exports.WorkingMemory = WorkingMemory;
@@ -20797,6 +21138,8 @@ exports.createDeprecationProxy = createDeprecationProxy;
20797
21138
  exports.createStep = createStep;
20798
21139
  exports.createTimeTravelExecutionParams = createTimeTravelExecutionParams;
20799
21140
  exports.createWorkflow = createWorkflow;
21141
+ exports.extractWorkingMemoryContent = extractWorkingMemoryContent;
21142
+ exports.extractWorkingMemoryTags = extractWorkingMemoryTags;
20800
21143
  exports.getResumeLabelsByStepId = getResumeLabelsByStepId;
20801
21144
  exports.getStepIds = getStepIds;
20802
21145
  exports.getStepResult = getStepResult;
@@ -20809,6 +21152,7 @@ exports.loop = loop;
20809
21152
  exports.mapVariable = mapVariable;
20810
21153
  exports.memoryDefaultOptions = memoryDefaultOptions;
20811
21154
  exports.parseMemoryRequestContext = parseMemoryRequestContext;
21155
+ exports.removeWorkingMemoryTags = removeWorkingMemoryTags;
20812
21156
  exports.resolveThreadIdFromArgs = resolveThreadIdFromArgs;
20813
21157
  exports.runCountDeprecationMessage = runCountDeprecationMessage;
20814
21158
  exports.supportedLanguageModelSpecifications = supportedLanguageModelSpecifications;
@@ -20818,5 +21162,5 @@ exports.validateStepInput = validateStepInput;
20818
21162
  exports.validateStepResumeData = validateStepResumeData;
20819
21163
  exports.validateStepStateData = validateStepStateData;
20820
21164
  exports.validateStepSuspendData = validateStepSuspendData;
20821
- //# sourceMappingURL=chunk-JAGQZZ43.cjs.map
20822
- //# sourceMappingURL=chunk-JAGQZZ43.cjs.map
21165
+ //# sourceMappingURL=chunk-5DL6Y7PJ.cjs.map
21166
+ //# sourceMappingURL=chunk-5DL6Y7PJ.cjs.map