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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. package/CHANGELOG.md +325 -0
  2. package/dist/agent/agent.d.ts +2 -2
  3. package/dist/agent/agent.d.ts.map +1 -1
  4. package/dist/agent/agent.types.d.ts +2 -0
  5. package/dist/agent/agent.types.d.ts.map +1 -1
  6. package/dist/agent/index.cjs +9 -9
  7. package/dist/agent/index.js +2 -2
  8. package/dist/agent/message-list/index.cjs +3 -3
  9. package/dist/agent/message-list/index.d.ts.map +1 -1
  10. package/dist/agent/message-list/index.js +1 -1
  11. package/dist/agent/message-list/prompt/attachments-to-parts.d.ts.map +1 -1
  12. package/dist/agent/types.d.ts +2 -3
  13. package/dist/agent/types.d.ts.map +1 -1
  14. package/dist/agent/utils.d.ts.map +1 -1
  15. package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
  16. package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
  17. package/dist/agent/workflows/prepare-stream/stream-step.d.ts +8 -1
  18. package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
  19. package/dist/{chunk-3RW5EMSB.js → chunk-3B2OPLGG.js} +13 -6
  20. package/dist/chunk-3B2OPLGG.js.map +1 -0
  21. package/dist/{chunk-RXDJL5QT.js → chunk-3ZQ7LX73.js} +13 -13
  22. package/dist/chunk-3ZQ7LX73.js.map +1 -0
  23. package/dist/{chunk-5WXEYDFI.cjs → chunk-556MJ7CL.cjs} +33 -26
  24. package/dist/chunk-556MJ7CL.cjs.map +1 -0
  25. package/dist/{chunk-HGNRQ3OG.js → chunk-5O52O25J.js} +15 -8
  26. package/dist/chunk-5O52O25J.js.map +1 -0
  27. package/dist/{chunk-WTYNK7Q4.js → chunk-5SA2EZ33.js} +421 -29
  28. package/dist/chunk-5SA2EZ33.js.map +1 -0
  29. package/dist/chunk-6XCINXZ7.cjs +194 -0
  30. package/dist/chunk-6XCINXZ7.cjs.map +1 -0
  31. package/dist/{chunk-MDKPL2R2.js → chunk-7ZADRRDW.js} +5 -4
  32. package/dist/chunk-7ZADRRDW.js.map +1 -0
  33. package/dist/{chunk-JXESKY4A.js → chunk-B5J5HYDN.js} +7 -5
  34. package/dist/chunk-B5J5HYDN.js.map +1 -0
  35. package/dist/chunk-BWYU7D33.js +192 -0
  36. package/dist/chunk-BWYU7D33.js.map +1 -0
  37. package/dist/{chunk-FVNT7VTO.js → chunk-D7CJ4HIQ.js} +240 -17
  38. package/dist/chunk-D7CJ4HIQ.js.map +1 -0
  39. package/dist/{chunk-VSM3NLUX.cjs → chunk-DQIZ5FFX.cjs} +163 -129
  40. package/dist/chunk-DQIZ5FFX.cjs.map +1 -0
  41. package/dist/{chunk-ZCVTH3CH.cjs → chunk-HNHZGFZY.cjs} +5 -4
  42. package/dist/chunk-HNHZGFZY.cjs.map +1 -0
  43. package/dist/{chunk-VZC4BWWH.cjs → chunk-IITXXVYI.cjs} +17 -17
  44. package/dist/chunk-IITXXVYI.cjs.map +1 -0
  45. package/dist/{chunk-2OTDXX73.js → chunk-KJIQGPQR.js} +4 -4
  46. package/dist/{chunk-2OTDXX73.js.map → chunk-KJIQGPQR.js.map} +1 -1
  47. package/dist/{chunk-2NVBZKZI.cjs → chunk-KP42JLXE.cjs} +370 -132
  48. package/dist/chunk-KP42JLXE.cjs.map +1 -0
  49. package/dist/{chunk-IWB65P37.cjs → chunk-KWWD3U7G.cjs} +5 -5
  50. package/dist/chunk-KWWD3U7G.cjs.map +1 -0
  51. package/dist/{chunk-3W5RQCCY.cjs → chunk-NHP6ZIDG.cjs} +248 -24
  52. package/dist/chunk-NHP6ZIDG.cjs.map +1 -0
  53. package/dist/{chunk-O6NA3Z43.cjs → chunk-OUUPUAGA.cjs} +10 -8
  54. package/dist/chunk-OUUPUAGA.cjs.map +1 -0
  55. package/dist/{chunk-D6EDHNGV.js → chunk-PC6EKOWK.js} +64 -11
  56. package/dist/chunk-PC6EKOWK.js.map +1 -0
  57. package/dist/{chunk-S6OEQHEI.cjs → chunk-QGWNF2QJ.cjs} +59 -50
  58. package/dist/chunk-QGWNF2QJ.cjs.map +1 -0
  59. package/dist/{chunk-HBJPYQRN.cjs → chunk-RROQ46B6.cjs} +69 -16
  60. package/dist/chunk-RROQ46B6.cjs.map +1 -0
  61. package/dist/{chunk-U7VECK2G.js → chunk-T2CJRA6E.js} +4 -4
  62. package/dist/chunk-T2CJRA6E.js.map +1 -0
  63. package/dist/{chunk-IHJDOC3A.js → chunk-T2UNO766.js} +16 -7
  64. package/dist/chunk-T2UNO766.js.map +1 -0
  65. package/dist/{chunk-CYVNOIXS.cjs → chunk-U3VE2EVB.cjs} +11 -11
  66. package/dist/{chunk-CYVNOIXS.cjs.map → chunk-U3VE2EVB.cjs.map} +1 -1
  67. package/dist/{chunk-4IKJAKCD.cjs → chunk-V537VSV4.cjs} +74 -16
  68. package/dist/chunk-V537VSV4.cjs.map +1 -0
  69. package/dist/{chunk-4RXG622P.cjs → chunk-VYJXTHII.cjs} +422 -30
  70. package/dist/chunk-VYJXTHII.cjs.map +1 -0
  71. package/dist/{chunk-LRSB62Z6.cjs → chunk-X7F4CSGR.cjs} +15 -8
  72. package/dist/chunk-X7F4CSGR.cjs.map +1 -0
  73. package/dist/{chunk-XXBWX7DT.js → chunk-XBO6W7LZ.js} +328 -91
  74. package/dist/chunk-XBO6W7LZ.js.map +1 -0
  75. package/dist/{chunk-KEURQGCQ.js → chunk-XIDKHXNR.js} +74 -17
  76. package/dist/chunk-XIDKHXNR.js.map +1 -0
  77. package/dist/{chunk-WQSGX6XA.cjs → chunk-XJQX54QP.cjs} +5 -5
  78. package/dist/{chunk-WQSGX6XA.cjs.map → chunk-XJQX54QP.cjs.map} +1 -1
  79. package/dist/{chunk-W3DD3XP5.js → chunk-YDFX3JR2.js} +163 -129
  80. package/dist/chunk-YDFX3JR2.js.map +1 -0
  81. package/dist/{chunk-IWQDBVJK.js → chunk-ZTTMSCLU.js} +3 -3
  82. package/dist/{chunk-IWQDBVJK.js.map → chunk-ZTTMSCLU.js.map} +1 -1
  83. package/dist/evals/base.d.ts +1 -1
  84. package/dist/evals/base.d.ts.map +1 -1
  85. package/dist/evals/base.test-utils.d.ts +25 -25
  86. package/dist/evals/index.cjs +4 -4
  87. package/dist/evals/index.js +1 -1
  88. package/dist/evals/scoreTraces/index.cjs +3 -3
  89. package/dist/evals/scoreTraces/index.js +1 -1
  90. package/dist/index.cjs +2 -2
  91. package/dist/index.js +1 -1
  92. package/dist/integration/index.cjs +2 -2
  93. package/dist/integration/index.js +1 -1
  94. package/dist/llm/index.cjs +18 -14
  95. package/dist/llm/index.d.ts +2 -1
  96. package/dist/llm/index.d.ts.map +1 -1
  97. package/dist/llm/index.js +5 -5
  98. package/dist/llm/model/gateway-resolver.d.ts.map +1 -1
  99. package/dist/llm/model/gateways/azure.d.ts +36 -0
  100. package/dist/llm/model/gateways/azure.d.ts.map +1 -0
  101. package/dist/llm/model/gateways/base.d.ts +3 -6
  102. package/dist/llm/model/gateways/base.d.ts.map +1 -1
  103. package/dist/llm/model/gateways/index.d.ts +4 -1
  104. package/dist/llm/model/gateways/index.d.ts.map +1 -1
  105. package/dist/llm/model/gateways/models-dev.d.ts +2 -2
  106. package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
  107. package/dist/llm/model/gateways/netlify.d.ts +2 -2
  108. package/dist/llm/model/gateways/netlify.d.ts.map +1 -1
  109. package/dist/llm/model/model.d.ts.map +1 -1
  110. package/dist/llm/model/model.loop.d.ts +1 -1
  111. package/dist/llm/model/model.loop.d.ts.map +1 -1
  112. package/dist/llm/model/provider-registry.d.ts.map +1 -1
  113. package/dist/llm/model/provider-types.generated.d.ts +192 -11
  114. package/dist/llm/model/registry-generator.d.ts +12 -0
  115. package/dist/llm/model/registry-generator.d.ts.map +1 -1
  116. package/dist/llm/model/router.d.ts.map +1 -1
  117. package/dist/loop/index.cjs +2 -2
  118. package/dist/loop/index.js +1 -1
  119. package/dist/loop/loop.d.ts.map +1 -1
  120. package/dist/loop/network/index.d.ts.map +1 -1
  121. package/dist/loop/test-utils/generateText.d.ts.map +1 -1
  122. package/dist/loop/test-utils/resultObject.d.ts.map +1 -1
  123. package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
  124. package/dist/loop/types.d.ts +8 -0
  125. package/dist/loop/types.d.ts.map +1 -1
  126. package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
  127. package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts +1 -1
  128. package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
  129. package/dist/mastra/index.cjs +2 -2
  130. package/dist/mastra/index.d.ts +9 -9
  131. package/dist/mastra/index.d.ts.map +1 -1
  132. package/dist/mastra/index.js +1 -1
  133. package/dist/mcp/index.cjs.map +1 -1
  134. package/dist/mcp/index.d.ts +4 -4
  135. package/dist/mcp/index.d.ts.map +1 -1
  136. package/dist/mcp/index.js.map +1 -1
  137. package/dist/mcp/types.d.ts +2 -2
  138. package/dist/mcp/types.d.ts.map +1 -1
  139. package/dist/memory/index.cjs +89 -34
  140. package/dist/memory/index.cjs.map +1 -1
  141. package/dist/memory/index.js +85 -30
  142. package/dist/memory/index.js.map +1 -1
  143. package/dist/memory/mock.d.ts +9 -13
  144. package/dist/memory/mock.d.ts.map +1 -1
  145. package/dist/models-dev-F6MTIYTO.js +3 -0
  146. package/dist/{models-dev-6PRLJKVZ.js.map → models-dev-F6MTIYTO.js.map} +1 -1
  147. package/dist/models-dev-XIVR5EJV.cjs +12 -0
  148. package/dist/{models-dev-WHMI5G6Y.cjs.map → models-dev-XIVR5EJV.cjs.map} +1 -1
  149. package/dist/netlify-MXBOGAJR.cjs +12 -0
  150. package/dist/{netlify-46I3SNNV.cjs.map → netlify-MXBOGAJR.cjs.map} +1 -1
  151. package/dist/netlify-RX3JXCFQ.js +3 -0
  152. package/dist/{netlify-EBQ6YUC6.js.map → netlify-RX3JXCFQ.js.map} +1 -1
  153. package/dist/processors/index.cjs +11 -11
  154. package/dist/processors/index.d.ts +2 -2
  155. package/dist/processors/index.d.ts.map +1 -1
  156. package/dist/processors/index.js +1 -1
  157. package/dist/processors/processors/batch-parts.d.ts +1 -1
  158. package/dist/processors/processors/batch-parts.d.ts.map +1 -1
  159. package/dist/processors/processors/language-detector.d.ts +1 -1
  160. package/dist/processors/processors/language-detector.d.ts.map +1 -1
  161. package/dist/processors/processors/moderation.d.ts +1 -1
  162. package/dist/processors/processors/moderation.d.ts.map +1 -1
  163. package/dist/processors/processors/pii-detector.d.ts +1 -1
  164. package/dist/processors/processors/pii-detector.d.ts.map +1 -1
  165. package/dist/processors/processors/prompt-injection-detector.d.ts +1 -1
  166. package/dist/processors/processors/prompt-injection-detector.d.ts.map +1 -1
  167. package/dist/processors/processors/structured-output.d.ts +1 -1
  168. package/dist/processors/processors/structured-output.d.ts.map +1 -1
  169. package/dist/processors/processors/system-prompt-scrubber.d.ts +1 -1
  170. package/dist/processors/processors/system-prompt-scrubber.d.ts.map +1 -1
  171. package/dist/processors/processors/token-limiter.d.ts +1 -1
  172. package/dist/processors/processors/token-limiter.d.ts.map +1 -1
  173. package/dist/processors/processors/unicode-normalizer.d.ts +1 -1
  174. package/dist/processors/processors/unicode-normalizer.d.ts.map +1 -1
  175. package/dist/provider-registry-3LUCE7FT.js +3 -0
  176. package/dist/{provider-registry-HDG6UMUC.js.map → provider-registry-3LUCE7FT.js.map} +1 -1
  177. package/dist/provider-registry-NBRXBOQT.cjs +40 -0
  178. package/dist/{provider-registry-RP2W4B24.cjs.map → provider-registry-NBRXBOQT.cjs.map} +1 -1
  179. package/dist/provider-registry.json +400 -22
  180. package/dist/{registry-generator-JPCV47SC.cjs → registry-generator-DEPPRYYJ.cjs} +21 -6
  181. package/dist/registry-generator-DEPPRYYJ.cjs.map +1 -0
  182. package/dist/{registry-generator-XD4FPZTU.js → registry-generator-FLW6NV42.js} +21 -7
  183. package/dist/registry-generator-FLW6NV42.js.map +1 -0
  184. package/dist/relevance/index.cjs +2 -2
  185. package/dist/relevance/index.js +1 -1
  186. package/dist/server/composite-auth.d.ts +9 -0
  187. package/dist/server/composite-auth.d.ts.map +1 -0
  188. package/dist/server/index.cjs +31 -0
  189. package/dist/server/index.cjs.map +1 -1
  190. package/dist/server/index.d.ts +1 -0
  191. package/dist/server/index.d.ts.map +1 -1
  192. package/dist/server/index.js +31 -1
  193. package/dist/server/index.js.map +1 -1
  194. package/dist/storage/index.cjs +29 -29
  195. package/dist/storage/index.js +1 -1
  196. package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
  197. package/dist/stream/base/output.d.ts.map +1 -1
  198. package/dist/stream/index.cjs +11 -11
  199. package/dist/stream/index.js +2 -2
  200. package/dist/stream/types.d.ts +7 -2
  201. package/dist/stream/types.d.ts.map +1 -1
  202. package/dist/test-utils/llm-mock.cjs +2 -2
  203. package/dist/test-utils/llm-mock.js +1 -1
  204. package/dist/tools/index.cjs +6 -6
  205. package/dist/tools/index.js +2 -2
  206. package/dist/tools/is-vercel-tool.cjs +2 -2
  207. package/dist/tools/is-vercel-tool.js +1 -1
  208. package/dist/tools/stream.d.ts +1 -0
  209. package/dist/tools/stream.d.ts.map +1 -1
  210. package/dist/tools/tool-builder/builder.d.ts +2 -0
  211. package/dist/tools/tool-builder/builder.d.ts.map +1 -1
  212. package/dist/tools/tool.d.ts +6 -6
  213. package/dist/tools/tool.d.ts.map +1 -1
  214. package/dist/tools/types.d.ts +6 -2
  215. package/dist/tools/types.d.ts.map +1 -1
  216. package/dist/tools/validation.d.ts +13 -1
  217. package/dist/tools/validation.d.ts.map +1 -1
  218. package/dist/utils.cjs +22 -22
  219. package/dist/utils.d.ts +1 -1
  220. package/dist/utils.d.ts.map +1 -1
  221. package/dist/utils.js +1 -1
  222. package/dist/vector/filter/index.cjs +7 -189
  223. package/dist/vector/filter/index.cjs.map +1 -1
  224. package/dist/vector/filter/index.js +1 -190
  225. package/dist/vector/filter/index.js.map +1 -1
  226. package/dist/vector/index.cjs +5 -0
  227. package/dist/vector/index.cjs.map +1 -1
  228. package/dist/vector/index.d.ts +1 -0
  229. package/dist/vector/index.d.ts.map +1 -1
  230. package/dist/vector/index.js +1 -0
  231. package/dist/vector/index.js.map +1 -1
  232. package/dist/vector/types.d.ts +86 -3
  233. package/dist/vector/types.d.ts.map +1 -1
  234. package/dist/vector/vector.d.ts +39 -2
  235. package/dist/vector/vector.d.ts.map +1 -1
  236. package/dist/workflows/default.d.ts.map +1 -1
  237. package/dist/workflows/evented/index.cjs +10 -10
  238. package/dist/workflows/evented/index.js +1 -1
  239. package/dist/workflows/evented/step-executor.d.ts.map +1 -1
  240. package/dist/workflows/index.cjs +23 -19
  241. package/dist/workflows/index.js +1 -1
  242. package/dist/workflows/types.d.ts +2 -2
  243. package/dist/workflows/types.d.ts.map +1 -1
  244. package/dist/workflows/utils.d.ts +7 -0
  245. package/dist/workflows/utils.d.ts.map +1 -1
  246. package/dist/workflows/workflow.d.ts +4 -2
  247. package/dist/workflows/workflow.d.ts.map +1 -1
  248. package/package.json +9 -8
  249. package/src/llm/model/provider-types.generated.d.ts +192 -11
  250. package/dist/chunk-2NVBZKZI.cjs.map +0 -1
  251. package/dist/chunk-3RW5EMSB.js.map +0 -1
  252. package/dist/chunk-3W5RQCCY.cjs.map +0 -1
  253. package/dist/chunk-4IKJAKCD.cjs.map +0 -1
  254. package/dist/chunk-4RXG622P.cjs.map +0 -1
  255. package/dist/chunk-5WXEYDFI.cjs.map +0 -1
  256. package/dist/chunk-D6EDHNGV.js.map +0 -1
  257. package/dist/chunk-FVNT7VTO.js.map +0 -1
  258. package/dist/chunk-HBJPYQRN.cjs.map +0 -1
  259. package/dist/chunk-HGNRQ3OG.js.map +0 -1
  260. package/dist/chunk-IHJDOC3A.js.map +0 -1
  261. package/dist/chunk-IWB65P37.cjs.map +0 -1
  262. package/dist/chunk-JXESKY4A.js.map +0 -1
  263. package/dist/chunk-KEURQGCQ.js.map +0 -1
  264. package/dist/chunk-LRSB62Z6.cjs.map +0 -1
  265. package/dist/chunk-MDKPL2R2.js.map +0 -1
  266. package/dist/chunk-O6NA3Z43.cjs.map +0 -1
  267. package/dist/chunk-RXDJL5QT.js.map +0 -1
  268. package/dist/chunk-S6OEQHEI.cjs.map +0 -1
  269. package/dist/chunk-U7VECK2G.js.map +0 -1
  270. package/dist/chunk-VSM3NLUX.cjs.map +0 -1
  271. package/dist/chunk-VZC4BWWH.cjs.map +0 -1
  272. package/dist/chunk-W3DD3XP5.js.map +0 -1
  273. package/dist/chunk-WTYNK7Q4.js.map +0 -1
  274. package/dist/chunk-XXBWX7DT.js.map +0 -1
  275. package/dist/chunk-ZCVTH3CH.cjs.map +0 -1
  276. package/dist/models-dev-6PRLJKVZ.js +0 -3
  277. package/dist/models-dev-WHMI5G6Y.cjs +0 -12
  278. package/dist/netlify-46I3SNNV.cjs +0 -12
  279. package/dist/netlify-EBQ6YUC6.js +0 -3
  280. package/dist/provider-registry-HDG6UMUC.js +0 -3
  281. package/dist/provider-registry-RP2W4B24.cjs +0 -40
  282. package/dist/registry-generator-JPCV47SC.cjs.map +0 -1
  283. package/dist/registry-generator-XD4FPZTU.js.map +0 -1
@@ -1,14 +1,14 @@
1
1
  import { DefaultVoice } from './chunk-NZAXAFI3.js';
2
2
  import { STREAM_FORMAT_SYMBOL, EMITTER_SYMBOL } from './chunk-NLNKQD2T.js';
3
- import { MessageList, DefaultGeneratedFile, DefaultGeneratedFileWithType } from './chunk-W3DD3XP5.js';
4
- import { resolveModelConfig } from './chunk-FVNT7VTO.js';
5
- import { MastraLLMV1 } from './chunk-JXESKY4A.js';
3
+ import { MessageList, DefaultGeneratedFile, DefaultGeneratedFileWithType } from './chunk-YDFX3JR2.js';
4
+ import { resolveModelConfig } from './chunk-D7CJ4HIQ.js';
5
+ import { MastraLLMV1 } from './chunk-B5J5HYDN.js';
6
6
  import { executeHook } from './chunk-L54GIUCB.js';
7
- import { removeUndefinedValues, selectFields, ensureToolProperties, makeCoreTool, createMastraProxy, delay } from './chunk-D6EDHNGV.js';
7
+ import { removeUndefinedValues, selectFields, ensureToolProperties, makeCoreTool, createMastraProxy, isZodType, delay } from './chunk-PC6EKOWK.js';
8
8
  import { wrapMastra, getOrCreateSpan } from './chunk-KIZIOFZC.js';
9
9
  import { MastraError, getErrorFromUnknown } from './chunk-JJ5O45LH.js';
10
- import { ToolStream } from './chunk-HGNRQ3OG.js';
11
- import { Tool, createTool } from './chunk-KEURQGCQ.js';
10
+ import { ToolStream } from './chunk-5O52O25J.js';
11
+ import { Tool, createTool } from './chunk-XIDKHXNR.js';
12
12
  import { RequestContext } from './chunk-GRBGQ2GE.js';
13
13
  import { zodToJsonSchema } from './chunk-PJKCPRYF.js';
14
14
  import { MastraBase } from './chunk-S6URFGCZ.js';
@@ -20,8 +20,8 @@ import * as crypto2 from 'crypto';
20
20
  import { randomUUID } from 'crypto';
21
21
  import { getErrorMessage, TypeValidationError } from '@ai-sdk/provider-v5';
22
22
  import { generateId, createTextStreamResponse, createUIMessageStreamResponse, createUIMessageStream, asSchema, parsePartialJson, isDeepEqualData, jsonSchema, APICallError, tool, stepCountIs } from 'ai-v5';
23
- import z5, { z } from 'zod';
24
23
  import { OpenAIReasoningSchemaCompatLayer, OpenAISchemaCompatLayer, GoogleSchemaCompatLayer, AnthropicSchemaCompatLayer, DeepSeekSchemaCompatLayer, MetaSchemaCompatLayer, applyCompatLayer } from '@mastra/schema-compat';
24
+ import z5, { z } from 'zod';
25
25
  import { isEmpty } from 'radash';
26
26
  import { isAbortError, injectJsonInstructionIntoMessages } from '@ai-sdk/provider-utils-v5';
27
27
  import { Tiktoken } from 'js-tiktoken/lite';
@@ -943,7 +943,8 @@ async function validateStepInput({
943
943
  const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
944
944
  validationError = new Error("Step input validation failed: \n" + errorMessages);
945
945
  } else {
946
- inputData = isEmpty(validatedInput.data) ? prevOutput : validatedInput.data;
946
+ const isEmptyData = isEmpty(validatedInput.data);
947
+ inputData = isEmptyData ? prevOutput : validatedInput.data;
947
948
  }
948
949
  }
949
950
  return { inputData, validationError };
@@ -966,6 +967,27 @@ async function validateStepResumeData({ resumeData, step }) {
966
967
  }
967
968
  return { resumeData, validationError };
968
969
  }
970
+ async function validateStepSuspendData({
971
+ suspendData,
972
+ step
973
+ }) {
974
+ if (!suspendData) {
975
+ return { suspendData: void 0, validationError: void 0 };
976
+ }
977
+ let validationError;
978
+ const suspendSchema = step.suspendSchema;
979
+ if (suspendSchema) {
980
+ const validatedSuspendData = await suspendSchema.safeParseAsync(suspendData);
981
+ if (!validatedSuspendData.success) {
982
+ const errors = getZodErrors(validatedSuspendData.error);
983
+ const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
984
+ validationError = new Error("Step suspend data validation failed: \n" + errorMessages);
985
+ } else {
986
+ suspendData = validatedSuspendData.data;
987
+ }
988
+ }
989
+ return { suspendData, validationError };
990
+ }
969
991
  function getResumeLabelsByStepId(resumeLabels, stepId) {
970
992
  return Object.entries(resumeLabels).filter(([_, value]) => value.stepId === stepId).reduce(
971
993
  (acc, [key, value]) => {
@@ -1654,6 +1676,13 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1654
1676
  getInitData: () => stepResults?.input,
1655
1677
  getStepResult: getStepResult.bind(this, stepResults),
1656
1678
  suspend: async (suspendPayload, suspendOptions) => {
1679
+ const { suspendData, validationError: validationError2 } = await validateStepSuspendData({
1680
+ suspendData: suspendPayload,
1681
+ step
1682
+ });
1683
+ if (validationError2) {
1684
+ throw validationError2;
1685
+ }
1657
1686
  executionContext.suspendedPaths[step.id] = executionContext.executionPath;
1658
1687
  if (suspendOptions?.resumeLabel) {
1659
1688
  const resumeLabel = Array.isArray(suspendOptions.resumeLabel) ? suspendOptions.resumeLabel : [suspendOptions.resumeLabel];
@@ -1664,7 +1693,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
1664
1693
  };
1665
1694
  }
1666
1695
  }
1667
- suspended = { payload: suspendPayload };
1696
+ suspended = { payload: suspendData };
1668
1697
  },
1669
1698
  bail: (result2) => {
1670
1699
  bailed = { payload: result2 };
@@ -2960,7 +2989,7 @@ function mapVariable(config) {
2960
2989
  function createStep(params, agentOptions) {
2961
2990
  if (params instanceof Agent) {
2962
2991
  return {
2963
- id: params.name,
2992
+ id: params.id,
2964
2993
  description: params.getDescription(),
2965
2994
  // @ts-ignore
2966
2995
  inputSchema: z.object({
@@ -3063,6 +3092,8 @@ function createStep(params, agentOptions) {
3063
3092
  description: params.description,
3064
3093
  inputSchema: params.inputSchema,
3065
3094
  outputSchema: params.outputSchema,
3095
+ resumeSchema: params.resumeSchema,
3096
+ suspendSchema: params.suspendSchema,
3066
3097
  execute: async ({
3067
3098
  inputData,
3068
3099
  mastra,
@@ -3079,10 +3110,11 @@ function createStep(params, agentOptions) {
3079
3110
  mastra,
3080
3111
  requestContext,
3081
3112
  tracingContext,
3082
- suspend,
3083
3113
  resumeData,
3084
3114
  workflow: {
3085
3115
  runId,
3116
+ suspend,
3117
+ resumeData,
3086
3118
  workflowId,
3087
3119
  state,
3088
3120
  setState
@@ -3543,6 +3575,7 @@ var Workflow = class extends MastraBase {
3543
3575
  const run = this.#runs.get(runIdToUse) ?? new Run({
3544
3576
  workflowId: this.id,
3545
3577
  stateSchema: this.stateSchema,
3578
+ inputSchema: this.inputSchema,
3546
3579
  runId: runIdToUse,
3547
3580
  resourceId: options?.resourceId,
3548
3581
  executionEngine: this.executionEngine,
@@ -3902,6 +3935,7 @@ var Run = class {
3902
3935
  closeStreamAction;
3903
3936
  executionResults;
3904
3937
  stateSchema;
3938
+ inputSchema;
3905
3939
  cleanup;
3906
3940
  retryConfig;
3907
3941
  constructor(params) {
@@ -3920,6 +3954,7 @@ var Run = class {
3920
3954
  this.workflowSteps = params.workflowSteps;
3921
3955
  this.validateInputs = params.validateInputs;
3922
3956
  this.stateSchema = params.stateSchema;
3957
+ this.inputSchema = params.inputSchema;
3923
3958
  this.workflowRunStatus = "pending";
3924
3959
  this.workflowEngineType = params.workflowEngineType;
3925
3960
  }
@@ -3936,29 +3971,16 @@ var Run = class {
3936
3971
  this.abortController?.abort();
3937
3972
  }
3938
3973
  async _validateInput(inputData) {
3939
- const firstEntry = this.executionGraph.steps[0];
3940
3974
  let inputDataToUse = inputData;
3941
- if (firstEntry && this.validateInputs) {
3942
- let inputSchema;
3943
- if (firstEntry.type === "step" || firstEntry.type === "foreach" || firstEntry.type === "loop") {
3944
- const step = firstEntry.step;
3945
- inputSchema = step.inputSchema;
3946
- } else if (firstEntry.type === "conditional" || firstEntry.type === "parallel") {
3947
- const firstStep = firstEntry.steps[0];
3948
- if (firstStep && firstStep.type === "step") {
3949
- inputSchema = firstStep.step.inputSchema;
3950
- }
3951
- }
3952
- if (inputSchema) {
3953
- const validatedInputData = await inputSchema.safeParseAsync(inputData);
3954
- if (!validatedInputData.success) {
3955
- const errors = getZodErrors(validatedInputData.error);
3956
- throw new Error(
3957
- "Invalid input data: \n" + errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n")
3958
- );
3959
- }
3960
- inputDataToUse = validatedInputData.data;
3975
+ if (this.validateInputs && this.inputSchema) {
3976
+ const validatedInputData = await this.inputSchema.safeParseAsync(inputData);
3977
+ if (!validatedInputData.success) {
3978
+ const errors = getZodErrors(validatedInputData.error);
3979
+ throw new Error(
3980
+ "Invalid input data: \n" + errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n")
3981
+ );
3961
3982
  }
3983
+ inputDataToUse = validatedInputData.data;
3962
3984
  }
3963
3985
  return inputDataToUse;
3964
3986
  }
@@ -6476,13 +6498,87 @@ function createToolCallStep({
6476
6498
  controller,
6477
6499
  runId,
6478
6500
  streamState,
6479
- modelSpanTracker
6501
+ modelSpanTracker,
6502
+ _internal
6480
6503
  }) {
6481
6504
  return createStep({
6482
6505
  id: "toolCallStep",
6483
6506
  inputSchema: toolCallInputSchema,
6484
6507
  outputSchema: toolCallOutputSchema,
6485
6508
  execute: async ({ inputData, suspend, resumeData, requestContext }) => {
6509
+ const addToolApprovalMetadata = (toolCallId, toolName, args) => {
6510
+ const responseMessages = messageList.get.response.db();
6511
+ const lastAssistantMessage = [...responseMessages].reverse().find((msg) => msg.role === "assistant");
6512
+ if (lastAssistantMessage) {
6513
+ const content = lastAssistantMessage.content;
6514
+ if (!content) return;
6515
+ const metadata = typeof lastAssistantMessage.content.metadata === "object" && lastAssistantMessage.content.metadata !== null ? lastAssistantMessage.content.metadata : {};
6516
+ metadata.pendingToolApprovals = metadata.pendingToolApprovals || {};
6517
+ metadata.pendingToolApprovals[toolCallId] = {
6518
+ toolName,
6519
+ args,
6520
+ type: "approval",
6521
+ runId
6522
+ // Store the runId so we can resume after page refresh
6523
+ };
6524
+ lastAssistantMessage.content.metadata = metadata;
6525
+ }
6526
+ };
6527
+ const removeToolApprovalMetadata = async (toolCallId) => {
6528
+ const { saveQueueManager, memoryConfig, threadId } = _internal || {};
6529
+ if (!saveQueueManager || !threadId) {
6530
+ return;
6531
+ }
6532
+ const getMetadata = (message) => {
6533
+ const content = message.content;
6534
+ if (!content) return void 0;
6535
+ const metadata = typeof content.metadata === "object" && content.metadata !== null ? content.metadata : void 0;
6536
+ return metadata;
6537
+ };
6538
+ const allMessages = messageList.get.all.db();
6539
+ const lastAssistantMessage = [...allMessages].reverse().find((msg) => {
6540
+ const metadata = getMetadata(msg);
6541
+ const pendingToolApprovals = metadata?.pendingToolApprovals;
6542
+ return !!pendingToolApprovals?.[toolCallId];
6543
+ });
6544
+ if (lastAssistantMessage) {
6545
+ const metadata = getMetadata(lastAssistantMessage);
6546
+ const pendingToolApprovals = metadata?.pendingToolApprovals;
6547
+ if (pendingToolApprovals && typeof pendingToolApprovals === "object") {
6548
+ delete pendingToolApprovals[toolCallId];
6549
+ if (metadata && Object.keys(pendingToolApprovals).length === 0) {
6550
+ delete metadata.pendingToolApprovals;
6551
+ }
6552
+ try {
6553
+ await saveQueueManager.flushMessages(messageList, threadId, memoryConfig);
6554
+ } catch (error) {
6555
+ console.error("Error removing tool approval metadata:", error);
6556
+ }
6557
+ }
6558
+ }
6559
+ };
6560
+ const flushMessagesBeforeSuspension = async () => {
6561
+ const { saveQueueManager, memoryConfig, threadId, resourceId, memory } = _internal || {};
6562
+ if (!saveQueueManager || !threadId) {
6563
+ return;
6564
+ }
6565
+ try {
6566
+ if (memory && !_internal.threadExists && resourceId) {
6567
+ const thread = await memory.getThreadById?.({ threadId });
6568
+ if (!thread) {
6569
+ await memory.createThread?.({
6570
+ threadId,
6571
+ resourceId,
6572
+ memoryConfig
6573
+ });
6574
+ }
6575
+ _internal.threadExists = true;
6576
+ }
6577
+ await saveQueueManager.flushMessages(messageList, threadId, memoryConfig);
6578
+ } catch (error) {
6579
+ console.error("Error flushing messages before suspension:", error);
6580
+ }
6581
+ };
6486
6582
  if (inputData.providerExecuted) {
6487
6583
  return {
6488
6584
  ...inputData,
@@ -6522,6 +6618,8 @@ function createToolCallStep({
6522
6618
  args: inputData.args
6523
6619
  }
6524
6620
  });
6621
+ addToolApprovalMetadata(inputData.toolCallId, inputData.toolName, inputData.args);
6622
+ await flushMessagesBeforeSuspension();
6525
6623
  return suspend(
6526
6624
  {
6527
6625
  requireToolApproval: {
@@ -6536,6 +6634,7 @@ function createToolCallStep({
6536
6634
  }
6537
6635
  );
6538
6636
  } else {
6637
+ await removeToolApprovalMetadata(inputData.toolCallId);
6539
6638
  if (!resumeData.approved) {
6540
6639
  return {
6541
6640
  result: "Tool call was not approved by the user",
@@ -6558,6 +6657,7 @@ function createToolCallStep({
6558
6657
  from: "AGENT" /* AGENT */,
6559
6658
  payload: { toolCallId: inputData.toolCallId, toolName: inputData.toolName, suspendPayload }
6560
6659
  });
6660
+ await flushMessagesBeforeSuspension();
6561
6661
  return await suspend(
6562
6662
  {
6563
6663
  toolCallSuspended: suspendPayload,
@@ -6571,6 +6671,18 @@ function createToolCallStep({
6571
6671
  resumeData
6572
6672
  };
6573
6673
  const result = await tool.execute(inputData.args, toolOptions);
6674
+ if (tool && "onOutput" in tool && typeof tool.onOutput === "function") {
6675
+ try {
6676
+ await tool.onOutput({
6677
+ toolCallId: inputData.toolCallId,
6678
+ toolName: inputData.toolName,
6679
+ output: result,
6680
+ abortSignal: options?.abortSignal
6681
+ });
6682
+ } catch (error) {
6683
+ console.error("Error calling onOutput", error);
6684
+ }
6685
+ }
6574
6686
  return { result, ...inputData };
6575
6687
  } catch (error) {
6576
6688
  return {
@@ -6590,6 +6702,7 @@ function createAgenticExecutionWorkflow({ models, _internal, ...rest }) {
6590
6702
  ...rest
6591
6703
  });
6592
6704
  const toolCallStep = createToolCallStep({
6705
+ _internal,
6593
6706
  ...rest
6594
6707
  });
6595
6708
  const llmMappingStep = createLLMMappingStep(
@@ -6614,6 +6727,16 @@ function createAgenticExecutionWorkflow({ models, _internal, ...rest }) {
6614
6727
  validateInputs: false
6615
6728
  }
6616
6729
  }).then(llmExecutionStep).map(
6730
+ async ({ inputData }) => {
6731
+ const typedInputData = inputData;
6732
+ const responseMessages = typedInputData.messages.nonUser;
6733
+ if (responseMessages && responseMessages.length > 0) {
6734
+ rest.messageList.add(responseMessages, "response");
6735
+ }
6736
+ return typedInputData;
6737
+ },
6738
+ { id: "add-response-to-messagelist" }
6739
+ ).map(
6617
6740
  async ({ inputData }) => {
6618
6741
  const typedInputData = inputData;
6619
6742
  return typedInputData.output.toolCalls || [];
@@ -6877,7 +7000,13 @@ function loop({
6877
7000
  const internalToUse = {
6878
7001
  now: _internal?.now || (() => Date.now()),
6879
7002
  generateId: _internal?.generateId || (() => generateId()),
6880
- currentDate: _internal?.currentDate || (() => /* @__PURE__ */ new Date())
7003
+ currentDate: _internal?.currentDate || (() => /* @__PURE__ */ new Date()),
7004
+ saveQueueManager: _internal?.saveQueueManager,
7005
+ memoryConfig: _internal?.memoryConfig,
7006
+ threadId: _internal?.threadId,
7007
+ resourceId: _internal?.resourceId,
7008
+ memory: _internal?.memory,
7009
+ threadExists: _internal?.threadExists
6881
7010
  };
6882
7011
  let startTimestamp = internalToUse.now?.();
6883
7012
  const messageId = rest.experimental_generateMessageId?.() || internalToUse.generateId?.();
@@ -7063,7 +7192,8 @@ var MastraLLMVNext = class extends MastraBase {
7063
7192
  _internal,
7064
7193
  agentId,
7065
7194
  toolCallId,
7066
- methodType
7195
+ methodType,
7196
+ includeRawChunks
7067
7197
  }) {
7068
7198
  let stopWhenToUse;
7069
7199
  if (maxSteps && typeof maxSteps === "number") {
@@ -7121,6 +7251,7 @@ var MastraLLMVNext = class extends MastraBase {
7121
7251
  requireToolApproval,
7122
7252
  agentId,
7123
7253
  methodType,
7254
+ includeRawChunks,
7124
7255
  options: {
7125
7256
  ...options,
7126
7257
  onStepFinish: async (props) => {
@@ -7158,7 +7289,8 @@ var MastraLLMVNext = class extends MastraBase {
7158
7289
  usage: props?.usage,
7159
7290
  runId
7160
7291
  });
7161
- if (props?.response?.headers?.["x-ratelimit-remaining-tokens"] && parseInt(props?.response?.headers?.["x-ratelimit-remaining-tokens"], 10) < 2e3) {
7292
+ const remainingTokens = parseInt(props?.response?.headers?.["x-ratelimit-remaining-tokens"] ?? "", 10);
7293
+ if (!isNaN(remainingTokens) && remainingTokens > 0 && remainingTokens < 2e3) {
7162
7294
  this.logger.warn("Rate limit approaching, waiting 10 seconds", { runId });
7163
7295
  await delay(10 * 1e3);
7164
7296
  }
@@ -7554,11 +7686,13 @@ async function createNetworkLoop({
7554
7686
  const routingAgent = await getRoutingAgent({ requestContext, agent });
7555
7687
  let completionResult;
7556
7688
  const iterationCount = (inputData.iteration ?? -1) + 1;
7689
+ const stepId = generateId3();
7557
7690
  await writer.write({
7558
7691
  type: "routing-agent-start",
7559
7692
  payload: {
7693
+ networkId: agent.id,
7560
7694
  agentId: routingAgent.id,
7561
- runId,
7695
+ runId: stepId,
7562
7696
  inputData: {
7563
7697
  ...inputData,
7564
7698
  iteration: iterationCount
@@ -7604,7 +7738,7 @@ async function createNetworkLoop({
7604
7738
  await writer.write({
7605
7739
  type: "routing-agent-text-start",
7606
7740
  payload: {
7607
- runId
7741
+ runId: stepId
7608
7742
  },
7609
7743
  from: "NETWORK" /* NETWORK */,
7610
7744
  runId
@@ -7618,6 +7752,7 @@ async function createNetworkLoop({
7618
7752
  await writer.write({
7619
7753
  type: "routing-agent-text-delta",
7620
7754
  payload: {
7755
+ runId: stepId,
7621
7756
  text: currentSlice
7622
7757
  },
7623
7758
  from: "NETWORK" /* NETWORK */,
@@ -7646,6 +7781,7 @@ async function createNetworkLoop({
7646
7781
  await writer.write({
7647
7782
  type: "routing-agent-text-delta",
7648
7783
  payload: {
7784
+ runId: stepId,
7649
7785
  text: currentSlice
7650
7786
  },
7651
7787
  from: "NETWORK" /* NETWORK */,
@@ -7666,7 +7802,7 @@ async function createNetworkLoop({
7666
7802
  isComplete: true,
7667
7803
  selectionReason: completionResult.object.completionReason || "",
7668
7804
  iteration: iterationCount,
7669
- runId
7805
+ runId: stepId
7670
7806
  };
7671
7807
  await writer.write({
7672
7808
  type: "routing-agent-end",
@@ -7768,7 +7904,7 @@ ${completionResult?.object?.finalResult}` : ""}
7768
7904
  isComplete: object.primitiveId === "none" && object.primitiveType === "none",
7769
7905
  selectionReason: object.selectionReason,
7770
7906
  iteration: iterationCount,
7771
- runId
7907
+ runId: stepId
7772
7908
  };
7773
7909
  await writer.write({
7774
7910
  type: "routing-agent-end",
@@ -7804,23 +7940,24 @@ ${completionResult?.object?.finalResult}` : ""}
7804
7940
  }),
7805
7941
  execute: async ({ inputData, writer, getInitData }) => {
7806
7942
  const agentsMap = await agent.listAgents({ requestContext });
7807
- const agentId = inputData.primitiveId;
7808
- const agentForStep = agentsMap[agentId];
7943
+ const agentForStep = agentsMap[inputData.primitiveId];
7809
7944
  if (!agentForStep) {
7810
7945
  const mastraError = new MastraError({
7811
7946
  id: "AGENT_NETWORK_AGENT_EXECUTION_STEP_INVALID_TASK_INPUT",
7812
7947
  domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
7813
7948
  category: "USER" /* USER */,
7814
- text: `Agent ${agentId} not found`
7949
+ text: `Agent ${inputData.primitiveId} not found`
7815
7950
  });
7816
7951
  throw mastraError;
7817
7952
  }
7953
+ const agentId = agentForStep.id;
7954
+ const stepId = generateId3();
7818
7955
  await writer.write({
7819
7956
  type: "agent-execution-start",
7820
7957
  payload: {
7821
- agentId: inputData.primitiveId,
7958
+ agentId,
7822
7959
  args: inputData,
7823
- runId
7960
+ runId: stepId
7824
7961
  },
7825
7962
  from: "NETWORK" /* NETWORK */,
7826
7963
  runId
@@ -7832,9 +7969,12 @@ ${completionResult?.object?.finalResult}` : ""}
7832
7969
  for await (const chunk of result.fullStream) {
7833
7970
  await writer.write({
7834
7971
  type: `agent-execution-event-${chunk.type}`,
7835
- payload: chunk,
7836
- runId: chunk.runId,
7837
- from: "NETWORK" /* NETWORK */
7972
+ payload: {
7973
+ ...chunk,
7974
+ runId: stepId
7975
+ },
7976
+ from: "NETWORK" /* NETWORK */,
7977
+ runId
7838
7978
  });
7839
7979
  }
7840
7980
  const memory = await agent.getMemory({ requestContext });
@@ -7870,10 +8010,11 @@ ${completionResult?.object?.finalResult}` : ""}
7870
8010
  });
7871
8011
  const endPayload = {
7872
8012
  task: inputData.task,
7873
- agentId: inputData.primitiveId,
8013
+ agentId,
7874
8014
  result: await result.text,
7875
8015
  isComplete: false,
7876
- iteration: inputData.iteration
8016
+ iteration: inputData.iteration,
8017
+ runId: stepId
7877
8018
  };
7878
8019
  await writer.write({
7879
8020
  type: "agent-execution-end",
@@ -7942,11 +8083,12 @@ ${completionResult?.object?.finalResult}` : ""}
7942
8083
  );
7943
8084
  throw mastraError;
7944
8085
  }
8086
+ const stepId = generateId3();
7945
8087
  const run = await wf.createRun({ runId });
7946
8088
  const toolData = {
7947
- name: wf.name,
8089
+ workflowId: wf.id,
7948
8090
  args: inputData,
7949
- runId
8091
+ runId: stepId
7950
8092
  };
7951
8093
  await writer?.write({
7952
8094
  type: "workflow-execution-start",
@@ -7963,9 +8105,12 @@ ${completionResult?.object?.finalResult}` : ""}
7963
8105
  chunks.push(chunk);
7964
8106
  await writer?.write({
7965
8107
  type: `workflow-execution-event-${chunk.type}`,
7966
- payload: chunk,
7967
- runId: chunk.runId,
7968
- from: "NETWORK" /* NETWORK */
8108
+ payload: {
8109
+ ...chunk,
8110
+ runId: stepId
8111
+ },
8112
+ from: "NETWORK" /* NETWORK */,
8113
+ runId
7969
8114
  });
7970
8115
  }
7971
8116
  let runSuccess = true;
@@ -8007,13 +8152,15 @@ ${completionResult?.object?.finalResult}` : ""}
8007
8152
  primitiveType: inputData.primitiveType,
8008
8153
  result: finalResult,
8009
8154
  isComplete: false,
8010
- iteration: inputData.iteration,
8011
- name: wf.name
8155
+ iteration: inputData.iteration
8012
8156
  };
8013
8157
  await writer?.write({
8014
8158
  type: "workflow-execution-end",
8015
8159
  payload: {
8016
8160
  ...endPayload,
8161
+ result: workflowState,
8162
+ name: wf.name,
8163
+ runId: stepId,
8017
8164
  usage: await stream.usage
8018
8165
  },
8019
8166
  from: "NETWORK" /* NETWORK */,
@@ -8048,14 +8195,13 @@ ${completionResult?.object?.finalResult}` : ""}
8048
8195
  const memory = await agent.getMemory({ requestContext });
8049
8196
  const memoryTools = await memory?.listTools?.();
8050
8197
  const toolsMap = { ...agentTools, ...memoryTools };
8051
- const toolId = inputData.primitiveId;
8052
- let tool = toolsMap[toolId];
8198
+ let tool = toolsMap[inputData.primitiveId];
8053
8199
  if (!tool) {
8054
8200
  const mastraError = new MastraError({
8055
8201
  id: "AGENT_NETWORK_TOOL_EXECUTION_STEP_INVALID_TASK_INPUT",
8056
8202
  domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
8057
8203
  category: "USER" /* USER */,
8058
- text: `Tool ${toolId} not found`
8204
+ text: `Tool ${inputData.primitiveId} not found`
8059
8205
  });
8060
8206
  throw mastraError;
8061
8207
  }
@@ -8064,10 +8210,11 @@ ${completionResult?.object?.finalResult}` : ""}
8064
8210
  id: "AGENT_NETWORK_TOOL_EXECUTION_STEP_INVALID_TASK_INPUT",
8065
8211
  domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
8066
8212
  category: "USER" /* USER */,
8067
- text: `Tool ${toolId} does not have an execute function`
8213
+ text: `Tool ${inputData.primitiveId} does not have an execute function`
8068
8214
  });
8069
8215
  throw mastraError;
8070
8216
  }
8217
+ const toolId = tool.id;
8071
8218
  let inputDataToUse;
8072
8219
  try {
8073
8220
  inputDataToUse = JSON.parse(inputData.prompt);
@@ -11879,6 +12026,7 @@ function createMapResultsStep({
11879
12026
  stopWhen: result.stopWhen,
11880
12027
  maxSteps: result.maxSteps,
11881
12028
  providerOptions: result.providerOptions,
12029
+ includeRawChunks: options.includeRawChunks,
11882
12030
  options: {
11883
12031
  ...options.prepareStep && { prepareStep: options.prepareStep },
11884
12032
  onFinish: async (payload) => {
@@ -12234,7 +12382,11 @@ function createStreamStep({
12234
12382
  resumeContext,
12235
12383
  agentId,
12236
12384
  toolCallId,
12237
- methodType
12385
+ methodType,
12386
+ saveQueueManager,
12387
+ memoryConfig,
12388
+ memory,
12389
+ resourceId
12238
12390
  }) {
12239
12391
  return createStep({
12240
12392
  id: "stream-text-step",
@@ -12261,7 +12413,12 @@ function createStreamStep({
12261
12413
  requireToolApproval,
12262
12414
  resumeContext,
12263
12415
  _internal: {
12264
- generateId: capabilities.generateMessageId
12416
+ generateId: capabilities.generateMessageId,
12417
+ saveQueueManager,
12418
+ memoryConfig,
12419
+ threadId: validatedInputData.threadId,
12420
+ resourceId,
12421
+ memory
12265
12422
  },
12266
12423
  agentId,
12267
12424
  toolCallId,
@@ -12322,7 +12479,11 @@ function createPrepareStreamWorkflow({
12322
12479
  resumeContext,
12323
12480
  agentId,
12324
12481
  toolCallId,
12325
- methodType
12482
+ methodType,
12483
+ saveQueueManager,
12484
+ memoryConfig,
12485
+ memory,
12486
+ resourceId
12326
12487
  });
12327
12488
  const mapResultsStep = createMapResultsStep({
12328
12489
  capabilities,
@@ -13363,7 +13524,8 @@ var Agent = class extends MastraBase {
13363
13524
  requestContext,
13364
13525
  tracingContext,
13365
13526
  model: await this.getModel({ requestContext }),
13366
- tracingPolicy: this.#options?.tracingPolicy
13527
+ tracingPolicy: this.#options?.tracingPolicy,
13528
+ requireApproval: toolObj.requireApproval
13367
13529
  };
13368
13530
  const convertedToCoreTool = makeCoreTool(toolObj, options);
13369
13531
  convertedMemoryTools[toolName] = convertedToCoreTool;
@@ -13561,7 +13723,8 @@ var Agent = class extends MastraBase {
13561
13723
  requestContext,
13562
13724
  tracingContext,
13563
13725
  model: await this.getModel({ requestContext }),
13564
- tracingPolicy: this.#options?.tracingPolicy
13726
+ tracingPolicy: this.#options?.tracingPolicy,
13727
+ requireApproval: toolObj.requireApproval
13565
13728
  };
13566
13729
  const convertedToCoreTool = makeCoreTool(toolObj, options, "toolset");
13567
13730
  toolsForRequest[toolName] = convertedToCoreTool;
@@ -13604,7 +13767,8 @@ var Agent = class extends MastraBase {
13604
13767
  requestContext,
13605
13768
  tracingContext,
13606
13769
  model: await this.getModel({ requestContext }),
13607
- tracingPolicy: this.#options?.tracingPolicy
13770
+ tracingPolicy: this.#options?.tracingPolicy,
13771
+ requireApproval: tool.requireApproval
13608
13772
  };
13609
13773
  const convertedToCoreTool = makeCoreTool(rest, options, "client-tool");
13610
13774
  toolsForRequest[toolName] = convertedToCoreTool;
@@ -13629,7 +13793,11 @@ var Agent = class extends MastraBase {
13629
13793
  if (Object.keys(agents).length > 0) {
13630
13794
  for (const [agentName, agent] of Object.entries(agents)) {
13631
13795
  const agentInputSchema = z.object({
13632
- prompt: z.string().describe("The prompt to send to the agent")
13796
+ prompt: z.string().describe("The prompt to send to the agent"),
13797
+ threadId: z.string().optional().describe("Thread ID for conversation continuity for memory messages"),
13798
+ resourceId: z.string().optional().describe("Resource/user identifier for memory messages"),
13799
+ instructions: z.string().optional().describe("Custom instructions to override agent defaults"),
13800
+ maxSteps: z.number().optional().describe("Maximum number of execution steps for the sub-agent")
13633
13801
  });
13634
13802
  const agentOutputSchema = z.object({
13635
13803
  text: z.string().describe("The response from the agent"),
@@ -13643,7 +13811,6 @@ var Agent = class extends MastraBase {
13643
13811
  inputSchema: agentInputSchema,
13644
13812
  outputSchema: agentOutputSchema,
13645
13813
  mastra: this.#mastra,
13646
- // BREAKING CHANGE v1.0: New tool signature - first param is inputData, second is context
13647
13814
  // manually wrap agent tools with tracing, so that we can pass the
13648
13815
  // current tool span onto the agent to maintain continuity of the trace
13649
13816
  execute: async (inputData, context) => {
@@ -13656,16 +13823,18 @@ var Agent = class extends MastraBase {
13656
13823
  resourceId
13657
13824
  });
13658
13825
  let result;
13826
+ const slugify = await import('@sindresorhus/slugify');
13827
+ const subAgentThreadId = inputData.threadId || context?.mastra?.generateId() || randomUUID();
13828
+ const subAgentResourceId = inputData.resourceId || context?.mastra?.generateId() || `${slugify.default(this.id)}-${agentName}`;
13659
13829
  if ((methodType === "generate" || methodType === "generateLegacy") && modelVersion === "v2") {
13660
13830
  if (!agent.hasOwnMemory() && this.#memory) {
13661
13831
  agent.__setMemory(this.#memory);
13662
13832
  }
13663
- const subAgentThreadId = randomUUID();
13664
- const slugify = await import('@sindresorhus/slugify');
13665
- const subAgentResourceId = `${slugify.default(this.id)}-${agentName}`;
13666
13833
  const generateResult = await agent.generate(inputData.prompt, {
13667
13834
  requestContext,
13668
13835
  tracingContext: context?.tracingContext,
13836
+ ...inputData.instructions && { instructions: inputData.instructions },
13837
+ ...inputData.maxSteps && { maxSteps: inputData.maxSteps },
13669
13838
  ...resourceId && threadId ? {
13670
13839
  memory: {
13671
13840
  resource: subAgentResourceId,
@@ -13684,12 +13853,11 @@ var Agent = class extends MastraBase {
13684
13853
  if (!agent.hasOwnMemory() && this.#memory) {
13685
13854
  agent.__setMemory(this.#memory);
13686
13855
  }
13687
- const subAgentThreadId = randomUUID();
13688
- const slugify = await import('@sindresorhus/slugify');
13689
- const subAgentResourceId = `${slugify.default(this.id)}-${agentName}`;
13690
13856
  const streamResult = await agent.stream(inputData.prompt, {
13691
13857
  requestContext,
13692
13858
  tracingContext: context?.tracingContext,
13859
+ ...inputData.instructions && { instructions: inputData.instructions },
13860
+ ...inputData.maxSteps && { maxSteps: inputData.maxSteps },
13693
13861
  ...resourceId && threadId ? {
13694
13862
  memory: {
13695
13863
  resource: subAgentResourceId,
@@ -13700,7 +13868,11 @@ var Agent = class extends MastraBase {
13700
13868
  let fullText = "";
13701
13869
  for await (const chunk of streamResult.fullStream) {
13702
13870
  if (context?.writer) {
13703
- await context.writer.write(chunk);
13871
+ if (chunk.type.startsWith("data-")) {
13872
+ await context.writer.custom(chunk);
13873
+ } else {
13874
+ await context.writer.write(chunk);
13875
+ }
13704
13876
  }
13705
13877
  if (chunk.type === "text-delta") {
13706
13878
  fullText += chunk.payload.text;
@@ -13715,7 +13887,11 @@ var Agent = class extends MastraBase {
13715
13887
  let fullText = "";
13716
13888
  for await (const chunk of streamResult.fullStream) {
13717
13889
  if (context?.writer) {
13718
- await context.writer.write(chunk);
13890
+ if (chunk.type.startsWith("data-")) {
13891
+ await context.writer.custom(chunk);
13892
+ } else {
13893
+ await context.writer.write(chunk);
13894
+ }
13719
13895
  }
13720
13896
  if (chunk.type === "text-delta") {
13721
13897
  fullText += chunk.textDelta;
@@ -13782,13 +13958,25 @@ var Agent = class extends MastraBase {
13782
13958
  const workflows = await this.listWorkflows({ requestContext });
13783
13959
  if (Object.keys(workflows).length > 0) {
13784
13960
  for (const [workflowName, workflow] of Object.entries(workflows)) {
13961
+ const extendedInputSchema = z.object({
13962
+ inputData: workflow.inputSchema,
13963
+ ...workflow.stateSchema ? { initialState: workflow.stateSchema } : {}
13964
+ });
13785
13965
  const toolObj = createTool({
13786
13966
  id: `workflow-${workflowName}`,
13787
13967
  description: workflow.description || `Workflow: ${workflowName}`,
13788
- inputSchema: workflow.inputSchema,
13789
- outputSchema: z.object({ result: workflow.outputSchema, runId: z.string() }),
13968
+ inputSchema: extendedInputSchema,
13969
+ outputSchema: z.union([
13970
+ z.object({
13971
+ result: workflow.outputSchema,
13972
+ runId: z.string().describe("Unique identifier for the workflow run")
13973
+ }),
13974
+ z.object({
13975
+ runId: z.string().describe("Unique identifier for the workflow run"),
13976
+ error: z.string().describe("Error message if workflow execution failed")
13977
+ })
13978
+ ]),
13790
13979
  mastra: this.#mastra,
13791
- // BREAKING CHANGE v1.0: New tool signature - first param is inputData, second is context
13792
13980
  // manually wrap workflow tools with tracing, so that we can pass the
13793
13981
  // current tool span onto the workflow to maintain continuity of the trace
13794
13982
  execute: async (inputData, context) => {
@@ -13802,16 +13990,18 @@ var Agent = class extends MastraBase {
13802
13990
  resourceId
13803
13991
  });
13804
13992
  const run = await workflow.createRun();
13805
- let result;
13993
+ const { initialState, inputData: workflowInputData } = inputData;
13994
+ let result = void 0;
13806
13995
  if (methodType === "generate" || methodType === "generateLegacy") {
13807
13996
  result = await run.start({
13808
- inputData,
13997
+ inputData: workflowInputData,
13809
13998
  requestContext,
13810
- tracingContext: context?.tracingContext
13999
+ tracingContext: context?.tracingContext,
14000
+ ...initialState && { initialState }
13811
14001
  });
13812
14002
  } else if (methodType === "streamLegacy") {
13813
14003
  const streamResult = run.streamLegacy({
13814
- inputData,
14004
+ inputData: workflowInputData,
13815
14005
  requestContext,
13816
14006
  tracingContext: context?.tracingContext
13817
14007
  });
@@ -13824,17 +14014,36 @@ var Agent = class extends MastraBase {
13824
14014
  result = await streamResult.getWorkflowState();
13825
14015
  } else if (methodType === "stream") {
13826
14016
  const streamResult = run.stream({
13827
- inputData,
14017
+ inputData: workflowInputData,
13828
14018
  requestContext,
13829
- tracingContext: context?.tracingContext
14019
+ tracingContext: context?.tracingContext,
14020
+ ...initialState && { initialState }
13830
14021
  });
13831
14022
  if (context?.writer) {
13832
14023
  await streamResult.fullStream.pipeTo(context.writer);
13833
14024
  }
13834
14025
  result = await streamResult.result;
13835
14026
  }
13836
- const workflowOutput = result?.result || result;
13837
- return { result: workflowOutput, runId: run.runId };
14027
+ if (result?.status === "success") {
14028
+ const workflowOutput = result?.result || result;
14029
+ return { result: workflowOutput, runId: run.runId };
14030
+ } else if (result?.status === "failed") {
14031
+ const workflowOutputError = result?.error;
14032
+ return {
14033
+ error: workflowOutputError?.message || String(workflowOutputError) || "Workflow execution failed",
14034
+ runId: run.runId
14035
+ };
14036
+ } else if (result?.status === "suspended") {
14037
+ return {
14038
+ error: `Workflow ended with status: "suspended". This is not currently handled in the basic agent workflow tool transformation. To achieve this you'll need to write your own tool that uses a workflow internally.`,
14039
+ runId: run.runId
14040
+ };
14041
+ } else {
14042
+ return {
14043
+ error: `Workflow should never reach this path, workflow returned no status`,
14044
+ runId: run.runId
14045
+ };
14046
+ }
13838
14047
  } catch (err) {
13839
14048
  const mastraError = new MastraError(
13840
14049
  {
@@ -14209,6 +14418,34 @@ var Agent = class extends MastraBase {
14209
14418
  );
14210
14419
  }
14211
14420
  const llm = await this.getLLM({ requestContext, model: options.model });
14421
+ if ("structuredOutput" in options && options.structuredOutput && options.structuredOutput.schema) {
14422
+ let structuredOutputModel = llm.getModel();
14423
+ if (options.structuredOutput?.model) {
14424
+ structuredOutputModel = await this.resolveModelConfig(
14425
+ options.structuredOutput?.model,
14426
+ requestContext
14427
+ );
14428
+ }
14429
+ const targetProvider = structuredOutputModel.provider;
14430
+ const targetModelId = structuredOutputModel.modelId;
14431
+ if (targetProvider.includes("openai") || targetModelId.includes("openai")) {
14432
+ if (isZodType(options.structuredOutput.schema) && targetModelId) {
14433
+ const modelInfo = {
14434
+ provider: targetProvider,
14435
+ modelId: targetModelId,
14436
+ supportsStructuredOutputs: false
14437
+ // Set to false to enable transform
14438
+ };
14439
+ const isReasoningModel = /^o[1-5]/.test(targetModelId);
14440
+ const compatLayer = isReasoningModel ? new OpenAIReasoningSchemaCompatLayer(modelInfo) : new OpenAISchemaCompatLayer(modelInfo);
14441
+ if (compatLayer.shouldApply() && options.structuredOutput.schema) {
14442
+ options.structuredOutput.schema = compatLayer.processZodType(
14443
+ options.structuredOutput.schema
14444
+ );
14445
+ }
14446
+ }
14447
+ }
14448
+ }
14212
14449
  const runId = options.runId || this.#mastra?.generateId() || randomUUID();
14213
14450
  const instructions = options.instructions || await this.getInstructions({ requestContext });
14214
14451
  const agentSpan = getOrCreateSpan({
@@ -16525,6 +16762,6 @@ var MastraModelOutput = class extends MastraBase {
16525
16762
  }
16526
16763
  };
16527
16764
 
16528
- export { AISDKV5OutputStream, Agent, BatchPartsProcessor, ChunkFrom, DefaultExecutionEngine, ExecutionEngine, LanguageDetector, MastraAgentNetworkStream, MastraModelOutput, ModerationProcessor, PIIDetector, ProcessorState, PromptInjectionDetector, Run, StructuredOutputProcessor, SystemPromptScrubber, TokenLimiterProcessor, TripWire, UnicodeNormalizer, Workflow, WorkflowRunOutput, cloneStep, cloneWorkflow, convertFullStreamChunkToUIMessageStream, convertMastraChunkToAISDKv5, createDeprecationProxy, createStep, createTimeTravelExecutionParams, createWorkflow, getResumeLabelsByStepId, getStepIds, getStepResult, getZodErrors, loop, mapVariable, resolveThreadIdFromArgs, runCountDeprecationMessage, tryGenerateWithJsonFallback, tryStreamWithJsonFallback, validateStepInput, validateStepResumeData };
16529
- //# sourceMappingURL=chunk-XXBWX7DT.js.map
16530
- //# sourceMappingURL=chunk-XXBWX7DT.js.map
16765
+ export { AISDKV5OutputStream, Agent, BatchPartsProcessor, ChunkFrom, DefaultExecutionEngine, ExecutionEngine, LanguageDetector, MastraAgentNetworkStream, MastraModelOutput, ModerationProcessor, PIIDetector, ProcessorState, PromptInjectionDetector, Run, StructuredOutputProcessor, SystemPromptScrubber, TokenLimiterProcessor, TripWire, UnicodeNormalizer, Workflow, WorkflowRunOutput, cloneStep, cloneWorkflow, convertFullStreamChunkToUIMessageStream, convertMastraChunkToAISDKv5, createDeprecationProxy, createStep, createTimeTravelExecutionParams, createWorkflow, getResumeLabelsByStepId, getStepIds, getStepResult, getZodErrors, loop, mapVariable, resolveThreadIdFromArgs, runCountDeprecationMessage, tryGenerateWithJsonFallback, tryStreamWithJsonFallback, validateStepInput, validateStepResumeData, validateStepSuspendData };
16766
+ //# sourceMappingURL=chunk-XBO6W7LZ.js.map
16767
+ //# sourceMappingURL=chunk-XBO6W7LZ.js.map