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

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 (576) hide show
  1. package/CHANGELOG.md +1218 -0
  2. package/dist/agent/agent-legacy.d.ts +35 -30
  3. package/dist/agent/agent-legacy.d.ts.map +1 -1
  4. package/dist/agent/agent-types.test-d.d.ts +2 -0
  5. package/dist/agent/agent-types.test-d.d.ts.map +1 -0
  6. package/dist/agent/agent.d.ts +24 -9
  7. package/dist/agent/agent.d.ts.map +1 -1
  8. package/dist/agent/agent.types.d.ts +17 -9
  9. package/dist/agent/agent.types.d.ts.map +1 -1
  10. package/dist/agent/index.cjs +9 -9
  11. package/dist/agent/index.js +2 -2
  12. package/dist/agent/message-list/index.cjs +3 -3
  13. package/dist/agent/message-list/index.d.ts +61 -3
  14. package/dist/agent/message-list/index.d.ts.map +1 -1
  15. package/dist/agent/message-list/index.js +1 -1
  16. package/dist/agent/message-list/prompt/attachments-to-parts.d.ts.map +1 -1
  17. package/dist/agent/message-list/prompt/convert-file.d.ts +1 -1
  18. package/dist/agent/message-list/prompt/convert-file.d.ts.map +1 -1
  19. package/dist/agent/message-list/prompt/download-assets.d.ts.map +1 -1
  20. package/dist/agent/save-queue/index.d.ts +3 -1
  21. package/dist/agent/save-queue/index.d.ts.map +1 -1
  22. package/dist/agent/test-utils.d.ts +37 -0
  23. package/dist/agent/test-utils.d.ts.map +1 -1
  24. package/dist/agent/trip-wire.d.ts +38 -4
  25. package/dist/agent/trip-wire.d.ts.map +1 -1
  26. package/dist/agent/types.d.ts +46 -14
  27. package/dist/agent/types.d.ts.map +1 -1
  28. package/dist/agent/utils.d.ts +4 -5
  29. package/dist/agent/utils.d.ts.map +1 -1
  30. package/dist/agent/workflows/prepare-stream/index.d.ts +37 -13
  31. package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
  32. package/dist/agent/workflows/prepare-stream/map-results-step.d.ts +3 -3
  33. package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
  34. package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +34 -11
  35. package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts.map +1 -1
  36. package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts +2 -1
  37. package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts.map +1 -1
  38. package/dist/agent/workflows/prepare-stream/schema.d.ts +38 -15
  39. package/dist/agent/workflows/prepare-stream/schema.d.ts.map +1 -1
  40. package/dist/agent/workflows/prepare-stream/stream-step.d.ts +11 -1
  41. package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
  42. package/dist/base.cjs +2 -2
  43. package/dist/base.js +1 -1
  44. package/dist/bundler/index.cjs +2 -2
  45. package/dist/bundler/index.js +1 -1
  46. package/dist/cache/index.cjs +3 -3
  47. package/dist/cache/index.js +1 -1
  48. package/dist/{chunk-JUBFO5J3.js → chunk-2ULLRN4Y.js} +16333 -11839
  49. package/dist/chunk-2ULLRN4Y.js.map +1 -0
  50. package/dist/{chunk-OJNJA5ZI.js → chunk-3CKZSDTQ.js} +3 -3
  51. package/dist/{chunk-OJNJA5ZI.js.map → chunk-3CKZSDTQ.js.map} +1 -1
  52. package/dist/chunk-3E3ILV6T.cjs +518 -0
  53. package/dist/chunk-3E3ILV6T.cjs.map +1 -0
  54. package/dist/{chunk-TQTAMPSC.js → chunk-3N3QE4ZK.js} +3 -3
  55. package/dist/chunk-3N3QE4ZK.js.map +1 -0
  56. package/dist/{chunk-QUKUN6NR.cjs → chunk-4JKEUSCC.cjs} +107 -7
  57. package/dist/chunk-4JKEUSCC.cjs.map +1 -0
  58. package/dist/{chunk-MSWTA73A.cjs → chunk-52RSUALV.cjs} +16490 -11957
  59. package/dist/chunk-52RSUALV.cjs.map +1 -0
  60. package/dist/chunk-5PAEYE3Q.js +513 -0
  61. package/dist/chunk-5PAEYE3Q.js.map +1 -0
  62. package/dist/{chunk-ECFXGXWO.cjs → chunk-5Q6WAYEY.cjs} +695 -375
  63. package/dist/chunk-5Q6WAYEY.cjs.map +1 -0
  64. package/dist/{chunk-CBAB7GOD.cjs → chunk-6BJ7XHRH.cjs} +2 -2
  65. package/dist/{chunk-CBAB7GOD.cjs.map → chunk-6BJ7XHRH.cjs.map} +1 -1
  66. package/dist/{chunk-GRBGQ2GE.js → chunk-6TBWJV35.js} +5 -3
  67. package/dist/chunk-6TBWJV35.js.map +1 -0
  68. package/dist/chunk-6XCINXZ7.cjs +194 -0
  69. package/dist/chunk-6XCINXZ7.cjs.map +1 -0
  70. package/dist/{chunk-E7K4FTLN.cjs → chunk-72YCRTEX.cjs} +18 -2
  71. package/dist/chunk-72YCRTEX.cjs.map +1 -0
  72. package/dist/{chunk-W7UH2PWL.js → chunk-7P6BNIJH.js} +1142 -331
  73. package/dist/chunk-7P6BNIJH.js.map +1 -0
  74. package/dist/{chunk-76K3IYWM.js → chunk-ADADLFDR.js} +3 -3
  75. package/dist/{chunk-76K3IYWM.js.map → chunk-ADADLFDR.js.map} +1 -1
  76. package/dist/{chunk-DSNPWVIG.cjs → chunk-AF74UXR5.cjs} +4 -3
  77. package/dist/chunk-AF74UXR5.cjs.map +1 -0
  78. package/dist/{chunk-GGYKYORQ.cjs → chunk-BJXKH4LG.cjs} +407 -22
  79. package/dist/chunk-BJXKH4LG.cjs.map +1 -0
  80. package/dist/{chunk-2ZVKF4HP.cjs → chunk-BUKY6CTR.cjs} +1147 -334
  81. package/dist/chunk-BUKY6CTR.cjs.map +1 -0
  82. package/dist/chunk-BWYU7D33.js +192 -0
  83. package/dist/chunk-BWYU7D33.js.map +1 -0
  84. package/dist/{chunk-XEVG546F.js → chunk-C36YRTZ6.js} +178 -12
  85. package/dist/chunk-C36YRTZ6.js.map +1 -0
  86. package/dist/{chunk-CB575O6L.cjs → chunk-CZEJQSWB.cjs} +473 -124
  87. package/dist/chunk-CZEJQSWB.cjs.map +1 -0
  88. package/dist/chunk-DD2VNRQM.js +62 -0
  89. package/dist/chunk-DD2VNRQM.js.map +1 -0
  90. package/dist/{chunk-KEXGB7FK.cjs → chunk-DGV2FWB4.cjs} +7 -7
  91. package/dist/{chunk-KEXGB7FK.cjs.map → chunk-DGV2FWB4.cjs.map} +1 -1
  92. package/dist/{chunk-Y63IFHEZ.cjs → chunk-EOPEDKLG.cjs} +4 -4
  93. package/dist/chunk-EOPEDKLG.cjs.map +1 -0
  94. package/dist/{chunk-UIZSWUKP.js → chunk-F2GAJSBI.js} +105 -7
  95. package/dist/chunk-F2GAJSBI.js.map +1 -0
  96. package/dist/{chunk-4CDL2QJT.js → chunk-IVV5TOMD.js} +122 -37
  97. package/dist/chunk-IVV5TOMD.js.map +1 -0
  98. package/dist/{chunk-MV7KHWUT.js → chunk-JIGDJK2O.js} +391 -15
  99. package/dist/chunk-JIGDJK2O.js.map +1 -0
  100. package/dist/chunk-KJBMTK5B.cjs +64 -0
  101. package/dist/chunk-KJBMTK5B.cjs.map +1 -0
  102. package/dist/{chunk-S6URFGCZ.js → chunk-LSHPJWM5.js} +3 -3
  103. package/dist/{chunk-S6URFGCZ.js.map → chunk-LSHPJWM5.js.map} +1 -1
  104. package/dist/chunk-MGCGWPQJ.cjs +275 -0
  105. package/dist/chunk-MGCGWPQJ.cjs.map +1 -0
  106. package/dist/chunk-MRFUISXC.cjs +4981 -0
  107. package/dist/chunk-MRFUISXC.cjs.map +1 -0
  108. package/dist/{chunk-KJ2SW6VA.js → chunk-NRUZYMHE.js} +4 -3
  109. package/dist/chunk-NRUZYMHE.js.map +1 -0
  110. package/dist/{chunk-CINNK34N.js → chunk-O2BJW7YA.js} +26 -11
  111. package/dist/chunk-O2BJW7YA.js.map +1 -0
  112. package/dist/chunk-OEIVMCWX.js +4959 -0
  113. package/dist/chunk-OEIVMCWX.js.map +1 -0
  114. package/dist/{chunk-WM6CK2F3.cjs → chunk-PG5H6QIO.cjs} +131 -49
  115. package/dist/chunk-PG5H6QIO.cjs.map +1 -0
  116. package/dist/{chunk-JPGVRWWL.js → chunk-PK2A5WBG.js} +472 -125
  117. package/dist/chunk-PK2A5WBG.js.map +1 -0
  118. package/dist/{chunk-X7JMA3IY.js → chunk-PSCMWPLC.js} +2 -2
  119. package/dist/{chunk-X7JMA3IY.js.map → chunk-PSCMWPLC.js.map} +1 -1
  120. package/dist/{chunk-VOY2RXOC.cjs → chunk-S73Z3PBJ.cjs} +182 -15
  121. package/dist/chunk-S73Z3PBJ.cjs.map +1 -0
  122. package/dist/{chunk-MA7TEM62.cjs → chunk-SCUWP4II.cjs} +769 -27
  123. package/dist/chunk-SCUWP4II.cjs.map +1 -0
  124. package/dist/{chunk-JV2KH24V.js → chunk-SXNQRJQD.js} +695 -375
  125. package/dist/chunk-SXNQRJQD.js.map +1 -0
  126. package/dist/{chunk-BMAFVZ2D.cjs → chunk-T2VLUFGG.cjs} +4 -4
  127. package/dist/{chunk-BMAFVZ2D.cjs.map → chunk-T2VLUFGG.cjs.map} +1 -1
  128. package/dist/chunk-THZTRBFS.js +268 -0
  129. package/dist/chunk-THZTRBFS.js.map +1 -0
  130. package/dist/{chunk-VOQ3ULMT.js → chunk-U3XOLEPX.js} +759 -17
  131. package/dist/chunk-U3XOLEPX.js.map +1 -0
  132. package/dist/{chunk-Y6ROD72V.cjs → chunk-UIGRFDO6.cjs} +4 -4
  133. package/dist/{chunk-Y6ROD72V.cjs.map → chunk-UIGRFDO6.cjs.map} +1 -1
  134. package/dist/{chunk-H6CZGPZD.js → chunk-US2U7ECW.js} +179 -38
  135. package/dist/chunk-US2U7ECW.js.map +1 -0
  136. package/dist/{chunk-J7O6WENZ.cjs → chunk-UVHSM2GU.cjs} +6 -2
  137. package/dist/chunk-UVHSM2GU.cjs.map +1 -0
  138. package/dist/{chunk-CD56CXVE.cjs → chunk-WTSZBHIZ.cjs} +32 -17
  139. package/dist/chunk-WTSZBHIZ.cjs.map +1 -0
  140. package/dist/{chunk-KIZIOFZC.js → chunk-Y36Y5MTD.js} +17 -3
  141. package/dist/chunk-Y36Y5MTD.js.map +1 -0
  142. package/dist/{chunk-DNEURYF3.cjs → chunk-YC6PJEPH.cjs} +206 -65
  143. package/dist/chunk-YC6PJEPH.cjs.map +1 -0
  144. package/dist/{chunk-IQO7ANVS.cjs → chunk-YWMMBIOM.cjs} +21 -20
  145. package/dist/chunk-YWMMBIOM.cjs.map +1 -0
  146. package/dist/{chunk-I4CXL4SR.js → chunk-Z57R5WS4.js} +16 -15
  147. package/dist/chunk-Z57R5WS4.js.map +1 -0
  148. package/dist/deployer/index.cjs +2 -2
  149. package/dist/deployer/index.js +1 -1
  150. package/dist/di/index.cjs +10 -2
  151. package/dist/di/index.d.ts +1 -1
  152. package/dist/di/index.d.ts.map +1 -1
  153. package/dist/di/index.js +1 -1
  154. package/dist/evals/base.d.ts +10 -2
  155. package/dist/evals/base.d.ts.map +1 -1
  156. package/dist/evals/base.test-utils.d.ts +25 -25
  157. package/dist/evals/index.cjs +9 -9
  158. package/dist/evals/index.js +2 -2
  159. package/dist/evals/scoreTraces/index.cjs +7 -6
  160. package/dist/evals/scoreTraces/index.cjs.map +1 -1
  161. package/dist/evals/scoreTraces/index.js +4 -3
  162. package/dist/evals/scoreTraces/index.js.map +1 -1
  163. package/dist/evals/scoreTraces/scoreTracesWorkflow.d.ts.map +1 -1
  164. package/dist/evals/types.d.ts +25 -24
  165. package/dist/evals/types.d.ts.map +1 -1
  166. package/dist/index.cjs +2 -2
  167. package/dist/index.js +1 -1
  168. package/dist/integration/index.cjs +2 -2
  169. package/dist/integration/index.js +1 -1
  170. package/dist/llm/index.cjs +30 -10
  171. package/dist/llm/index.d.ts +2 -0
  172. package/dist/llm/index.d.ts.map +1 -1
  173. package/dist/llm/index.js +5 -1
  174. package/dist/llm/model/aisdk/v5/model.d.ts +47 -0
  175. package/dist/llm/model/aisdk/v5/model.d.ts.map +1 -0
  176. package/dist/llm/model/base.types.d.ts +2 -2
  177. package/dist/llm/model/base.types.d.ts.map +1 -1
  178. package/dist/llm/model/gateway-resolver.d.ts.map +1 -1
  179. package/dist/llm/model/gateways/azure.d.ts +36 -0
  180. package/dist/llm/model/gateways/azure.d.ts.map +1 -0
  181. package/dist/llm/model/gateways/base.d.ts +9 -4
  182. package/dist/llm/model/gateways/base.d.ts.map +1 -1
  183. package/dist/llm/model/gateways/constants.d.ts.map +1 -1
  184. package/dist/llm/model/gateways/index.d.ts +4 -1
  185. package/dist/llm/model/gateways/index.d.ts.map +1 -1
  186. package/dist/llm/model/gateways/models-dev.d.ts +3 -2
  187. package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
  188. package/dist/llm/model/gateways/netlify.d.ts +4 -3
  189. package/dist/llm/model/gateways/netlify.d.ts.map +1 -1
  190. package/dist/llm/model/is-v2-model.d.ts +3 -0
  191. package/dist/llm/model/is-v2-model.d.ts.map +1 -0
  192. package/dist/llm/model/model-method-from-agent.d.ts +4 -0
  193. package/dist/llm/model/model-method-from-agent.d.ts.map +1 -0
  194. package/dist/llm/model/model.d.ts.map +1 -1
  195. package/dist/llm/model/model.loop.d.ts +2 -2
  196. package/dist/llm/model/model.loop.d.ts.map +1 -1
  197. package/dist/llm/model/model.loop.types.d.ts +4 -2
  198. package/dist/llm/model/model.loop.types.d.ts.map +1 -1
  199. package/dist/llm/model/provider-options.d.ts +4 -1
  200. package/dist/llm/model/provider-options.d.ts.map +1 -1
  201. package/dist/llm/model/provider-registry.d.ts +11 -1
  202. package/dist/llm/model/provider-registry.d.ts.map +1 -1
  203. package/dist/llm/model/provider-types.generated.d.ts +489 -27
  204. package/dist/llm/model/registry-generator.d.ts +12 -0
  205. package/dist/llm/model/registry-generator.d.ts.map +1 -1
  206. package/dist/llm/model/resolve-model.d.ts +1 -1
  207. package/dist/llm/model/resolve-model.d.ts.map +1 -1
  208. package/dist/llm/model/router.d.ts +12 -5
  209. package/dist/llm/model/router.d.ts.map +1 -1
  210. package/dist/llm/model/shared.types.d.ts +17 -6
  211. package/dist/llm/model/shared.types.d.ts.map +1 -1
  212. package/dist/logger/constants.d.ts +1 -0
  213. package/dist/logger/constants.d.ts.map +1 -1
  214. package/dist/logger/index.cjs +11 -11
  215. package/dist/logger/index.js +2 -2
  216. package/dist/logger/transport.d.ts +1 -1
  217. package/dist/logger/transport.d.ts.map +1 -1
  218. package/dist/loop/index.cjs +2 -2
  219. package/dist/loop/index.js +1 -1
  220. package/dist/loop/loop.d.ts.map +1 -1
  221. package/dist/loop/network/index.d.ts.map +1 -1
  222. package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts +37 -0
  223. package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts.map +1 -0
  224. package/dist/loop/test-utils/fullStream.d.ts.map +1 -1
  225. package/dist/loop/test-utils/generateText.d.ts.map +1 -1
  226. package/dist/loop/test-utils/options.d.ts.map +1 -1
  227. package/dist/loop/test-utils/resultObject.d.ts.map +1 -1
  228. package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
  229. package/dist/loop/test-utils/textStream.d.ts.map +1 -1
  230. package/dist/loop/test-utils/toUIMessageStream.d.ts.map +1 -1
  231. package/dist/loop/test-utils/tools.d.ts.map +1 -1
  232. package/dist/loop/test-utils/utils.d.ts +1 -1
  233. package/dist/loop/test-utils/utils.d.ts.map +1 -1
  234. package/dist/loop/types.d.ts +42 -20
  235. package/dist/loop/types.d.ts.map +1 -1
  236. package/dist/loop/workflows/agentic-execution/index.d.ts +60 -42
  237. package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
  238. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +41 -29
  239. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
  240. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +20 -14
  241. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
  242. package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts +1 -1
  243. package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
  244. package/dist/loop/workflows/agentic-loop/index.d.ts +62 -43
  245. package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
  246. package/dist/loop/workflows/run-state.d.ts +2 -2
  247. package/dist/loop/workflows/run-state.d.ts.map +1 -1
  248. package/dist/loop/workflows/schema.d.ts +32 -15
  249. package/dist/loop/workflows/schema.d.ts.map +1 -1
  250. package/dist/loop/workflows/stream.d.ts +1 -1
  251. package/dist/loop/workflows/stream.d.ts.map +1 -1
  252. package/dist/mastra/index.cjs +2 -2
  253. package/dist/mastra/index.d.ts +377 -12
  254. package/dist/mastra/index.d.ts.map +1 -1
  255. package/dist/mastra/index.js +1 -1
  256. package/dist/mcp/index.cjs +4 -4
  257. package/dist/mcp/index.cjs.map +1 -1
  258. package/dist/mcp/index.d.ts +4 -4
  259. package/dist/mcp/index.d.ts.map +1 -1
  260. package/dist/mcp/index.js +2 -2
  261. package/dist/mcp/index.js.map +1 -1
  262. package/dist/mcp/types.d.ts +2 -2
  263. package/dist/mcp/types.d.ts.map +1 -1
  264. package/dist/memory/index.cjs +21 -327
  265. package/dist/memory/index.cjs.map +1 -1
  266. package/dist/memory/index.js +1 -327
  267. package/dist/memory/index.js.map +1 -1
  268. package/dist/memory/memory.d.ts +28 -18
  269. package/dist/memory/memory.d.ts.map +1 -1
  270. package/dist/memory/mock.d.ts +15 -14
  271. package/dist/memory/mock.d.ts.map +1 -1
  272. package/dist/memory/types.d.ts +69 -11
  273. package/dist/memory/types.d.ts.map +1 -1
  274. package/dist/models-dev-23RN2WHG.js +3 -0
  275. package/dist/{models-dev-DNBKXHT4.js.map → models-dev-23RN2WHG.js.map} +1 -1
  276. package/dist/models-dev-EO3SUIY2.cjs +12 -0
  277. package/dist/{models-dev-YBEEQIX6.cjs.map → models-dev-EO3SUIY2.cjs.map} +1 -1
  278. package/dist/netlify-GXJ5D5DD.js +3 -0
  279. package/dist/{netlify-7G2L5VSH.js.map → netlify-GXJ5D5DD.js.map} +1 -1
  280. package/dist/netlify-KJLY3GFS.cjs +12 -0
  281. package/dist/{netlify-GWNGSIRZ.cjs.map → netlify-KJLY3GFS.cjs.map} +1 -1
  282. package/dist/observability/index.cjs +16 -8
  283. package/dist/observability/index.js +1 -1
  284. package/dist/observability/types/tracing.d.ts +236 -13
  285. package/dist/observability/types/tracing.d.ts.map +1 -1
  286. package/dist/observability/utils.d.ts +47 -1
  287. package/dist/observability/utils.d.ts.map +1 -1
  288. package/dist/processors/index.cjs +115 -11
  289. package/dist/processors/index.d.ts +246 -26
  290. package/dist/processors/index.d.ts.map +1 -1
  291. package/dist/processors/index.js +1 -1
  292. package/dist/processors/memory/index.d.ts +7 -0
  293. package/dist/processors/memory/index.d.ts.map +1 -0
  294. package/dist/processors/memory/message-history.d.ts +43 -0
  295. package/dist/processors/memory/message-history.d.ts.map +1 -0
  296. package/dist/processors/memory/semantic-recall.d.ts +152 -0
  297. package/dist/processors/memory/semantic-recall.d.ts.map +1 -0
  298. package/dist/processors/memory/working-memory.d.ts +65 -0
  299. package/dist/processors/memory/working-memory.d.ts.map +1 -0
  300. package/dist/processors/processors/batch-parts.d.ts +1 -1
  301. package/dist/processors/processors/batch-parts.d.ts.map +1 -1
  302. package/dist/processors/processors/index.d.ts +2 -1
  303. package/dist/processors/processors/index.d.ts.map +1 -1
  304. package/dist/processors/processors/language-detector.d.ts +15 -1
  305. package/dist/processors/processors/language-detector.d.ts.map +1 -1
  306. package/dist/processors/processors/moderation.d.ts +15 -1
  307. package/dist/processors/processors/moderation.d.ts.map +1 -1
  308. package/dist/processors/processors/pii-detector.d.ts +15 -1
  309. package/dist/processors/processors/pii-detector.d.ts.map +1 -1
  310. package/dist/processors/processors/prepare-step.d.ts +12 -0
  311. package/dist/processors/processors/prepare-step.d.ts.map +1 -0
  312. package/dist/processors/processors/prompt-injection-detector.d.ts +15 -1
  313. package/dist/processors/processors/prompt-injection-detector.d.ts.map +1 -1
  314. package/dist/processors/processors/structured-output.d.ts +7 -5
  315. package/dist/processors/processors/structured-output.d.ts.map +1 -1
  316. package/dist/processors/processors/system-prompt-scrubber.d.ts +1 -1
  317. package/dist/processors/processors/system-prompt-scrubber.d.ts.map +1 -1
  318. package/dist/processors/processors/token-limiter.d.ts +22 -12
  319. package/dist/processors/processors/token-limiter.d.ts.map +1 -1
  320. package/dist/processors/processors/tool-call-filter.d.ts +28 -0
  321. package/dist/processors/processors/tool-call-filter.d.ts.map +1 -0
  322. package/dist/processors/processors/unicode-normalizer.d.ts +1 -1
  323. package/dist/processors/processors/unicode-normalizer.d.ts.map +1 -1
  324. package/dist/processors/runner.d.ts +83 -9
  325. package/dist/processors/runner.d.ts.map +1 -1
  326. package/dist/processors/step-schema.d.ts +49731 -0
  327. package/dist/processors/step-schema.d.ts.map +1 -0
  328. package/dist/provider-registry-3TG2KUD2.cjs +40 -0
  329. package/dist/provider-registry-3TG2KUD2.cjs.map +1 -0
  330. package/dist/provider-registry-F67Y6OF2.js +3 -0
  331. package/dist/provider-registry-F67Y6OF2.js.map +1 -0
  332. package/dist/provider-registry.json +1056 -61
  333. package/dist/{registry-generator-MK63POJO.cjs → registry-generator-34SC4TAU.cjs} +23 -6
  334. package/dist/registry-generator-34SC4TAU.cjs.map +1 -0
  335. package/dist/{registry-generator-H4YNODDH.js → registry-generator-UMTNPBJX.js} +23 -7
  336. package/dist/registry-generator-UMTNPBJX.js.map +1 -0
  337. package/dist/relevance/index.cjs +2 -2
  338. package/dist/relevance/index.js +1 -1
  339. package/dist/request-context/index.cjs +10 -2
  340. package/dist/request-context/index.d.ts +26 -0
  341. package/dist/request-context/index.d.ts.map +1 -1
  342. package/dist/request-context/index.js +1 -1
  343. package/dist/server/auth.d.ts +11 -0
  344. package/dist/server/auth.d.ts.map +1 -1
  345. package/dist/server/base.d.ts +51 -0
  346. package/dist/server/base.d.ts.map +1 -0
  347. package/dist/server/composite-auth.d.ts +9 -0
  348. package/dist/server/composite-auth.d.ts.map +1 -0
  349. package/dist/server/index.cjs +124 -3
  350. package/dist/server/index.cjs.map +1 -1
  351. package/dist/server/index.d.ts +8 -0
  352. package/dist/server/index.d.ts.map +1 -1
  353. package/dist/server/index.js +121 -3
  354. package/dist/server/index.js.map +1 -1
  355. package/dist/server/simple-auth.d.ts +27 -0
  356. package/dist/server/simple-auth.d.ts.map +1 -0
  357. package/dist/server/types.d.ts +6 -0
  358. package/dist/server/types.d.ts.map +1 -1
  359. package/dist/storage/base.d.ts +76 -3
  360. package/dist/storage/base.d.ts.map +1 -1
  361. package/dist/storage/constants.d.ts +3 -1
  362. package/dist/storage/constants.d.ts.map +1 -1
  363. package/dist/storage/domains/agents/base.d.ts +49 -0
  364. package/dist/storage/domains/agents/base.d.ts.map +1 -0
  365. package/dist/storage/domains/agents/index.d.ts +3 -0
  366. package/dist/storage/domains/agents/index.d.ts.map +1 -0
  367. package/dist/storage/domains/agents/inmemory.d.ts +22 -0
  368. package/dist/storage/domains/agents/inmemory.d.ts.map +1 -0
  369. package/dist/storage/domains/index.d.ts +1 -0
  370. package/dist/storage/domains/index.d.ts.map +1 -1
  371. package/dist/storage/domains/memory/inmemory.d.ts.map +1 -1
  372. package/dist/storage/domains/operations/inmemory.d.ts.map +1 -1
  373. package/dist/storage/domains/scores/base.d.ts +2 -2
  374. package/dist/storage/domains/scores/base.d.ts.map +1 -1
  375. package/dist/storage/domains/scores/inmemory.d.ts +2 -2
  376. package/dist/storage/domains/scores/inmemory.d.ts.map +1 -1
  377. package/dist/storage/domains/workflows/base.d.ts +4 -0
  378. package/dist/storage/domains/workflows/base.d.ts.map +1 -1
  379. package/dist/storage/domains/workflows/inmemory.d.ts +5 -1
  380. package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
  381. package/dist/storage/index.cjs +65 -29
  382. package/dist/storage/index.js +1 -1
  383. package/dist/storage/mock.d.ts +7 -2
  384. package/dist/storage/mock.d.ts.map +1 -1
  385. package/dist/storage/storageWithInit.d.ts.map +1 -1
  386. package/dist/storage/types.d.ts +88 -5
  387. package/dist/storage/types.d.ts.map +1 -1
  388. package/dist/storage/utils.d.ts +82 -0
  389. package/dist/storage/utils.d.ts.map +1 -1
  390. package/dist/stream/MastraAgentNetworkStream.d.ts +2 -2
  391. package/dist/stream/MastraAgentNetworkStream.d.ts.map +1 -1
  392. package/dist/stream/MastraWorkflowStream.d.ts +2 -2
  393. package/dist/stream/MastraWorkflowStream.d.ts.map +1 -1
  394. package/dist/stream/RunOutput.d.ts +2 -2
  395. package/dist/stream/RunOutput.d.ts.map +1 -1
  396. package/dist/stream/aisdk/v4/transform.d.ts.map +1 -1
  397. package/dist/stream/aisdk/v4/usage.d.ts +19 -0
  398. package/dist/stream/aisdk/v4/usage.d.ts.map +1 -0
  399. package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
  400. package/dist/stream/aisdk/v5/execute.d.ts +9 -5
  401. package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
  402. package/dist/stream/aisdk/v5/input.d.ts +4 -1
  403. package/dist/stream/aisdk/v5/input.d.ts.map +1 -1
  404. package/dist/stream/aisdk/v5/output-helpers.d.ts +5 -1
  405. package/dist/stream/aisdk/v5/output-helpers.d.ts.map +1 -1
  406. package/dist/stream/aisdk/v5/output.d.ts +11 -13
  407. package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
  408. package/dist/stream/aisdk/v5/transform.d.ts +2 -1
  409. package/dist/stream/aisdk/v5/transform.d.ts.map +1 -1
  410. package/dist/stream/base/base.d.ts +1 -1
  411. package/dist/stream/base/base.d.ts.map +1 -1
  412. package/dist/stream/base/input.d.ts +1 -1
  413. package/dist/stream/base/output-format-handlers.d.ts +14 -1
  414. package/dist/stream/base/output-format-handlers.d.ts.map +1 -1
  415. package/dist/stream/base/output.d.ts +9 -14
  416. package/dist/stream/base/output.d.ts.map +1 -1
  417. package/dist/stream/index.cjs +15 -11
  418. package/dist/stream/index.d.ts +2 -2
  419. package/dist/stream/index.d.ts.map +1 -1
  420. package/dist/stream/index.js +2 -2
  421. package/dist/stream/types.d.ts +97 -32
  422. package/dist/stream/types.d.ts.map +1 -1
  423. package/dist/test-utils/llm-mock.cjs +101 -30
  424. package/dist/test-utils/llm-mock.cjs.map +1 -1
  425. package/dist/test-utils/llm-mock.d.ts +7 -2
  426. package/dist/test-utils/llm-mock.d.ts.map +1 -1
  427. package/dist/test-utils/llm-mock.js +97 -30
  428. package/dist/test-utils/llm-mock.js.map +1 -1
  429. package/dist/tools/index.cjs +6 -6
  430. package/dist/tools/index.js +2 -2
  431. package/dist/tools/is-vercel-tool.cjs +2 -2
  432. package/dist/tools/is-vercel-tool.js +1 -1
  433. package/dist/tools/stream.d.ts +10 -4
  434. package/dist/tools/stream.d.ts.map +1 -1
  435. package/dist/tools/tool-builder/builder.d.ts +2 -0
  436. package/dist/tools/tool-builder/builder.d.ts.map +1 -1
  437. package/dist/tools/tool-stream-types.test-d.d.ts +2 -0
  438. package/dist/tools/tool-stream-types.test-d.d.ts.map +1 -0
  439. package/dist/tools/tool.d.ts +21 -8
  440. package/dist/tools/tool.d.ts.map +1 -1
  441. package/dist/tools/types.d.ts +33 -6
  442. package/dist/tools/types.d.ts.map +1 -1
  443. package/dist/tools/validation.d.ts +25 -1
  444. package/dist/tools/validation.d.ts.map +1 -1
  445. package/dist/tts/index.cjs +2 -2
  446. package/dist/tts/index.js +1 -1
  447. package/dist/types/zod-compat.d.ts +14 -1
  448. package/dist/types/zod-compat.d.ts.map +1 -1
  449. package/dist/utils.cjs +25 -21
  450. package/dist/utils.d.ts +9 -4
  451. package/dist/utils.d.ts.map +1 -1
  452. package/dist/utils.js +1 -1
  453. package/dist/vector/filter/index.cjs +7 -189
  454. package/dist/vector/filter/index.cjs.map +1 -1
  455. package/dist/vector/filter/index.js +1 -190
  456. package/dist/vector/filter/index.js.map +1 -1
  457. package/dist/vector/index.cjs +7 -2
  458. package/dist/vector/index.cjs.map +1 -1
  459. package/dist/vector/index.d.ts +1 -0
  460. package/dist/vector/index.d.ts.map +1 -1
  461. package/dist/vector/index.js +2 -1
  462. package/dist/vector/index.js.map +1 -1
  463. package/dist/vector/types.d.ts +86 -3
  464. package/dist/vector/types.d.ts.map +1 -1
  465. package/dist/vector/vector.d.ts +39 -2
  466. package/dist/vector/vector.d.ts.map +1 -1
  467. package/dist/voice/aisdk/index.d.ts +3 -0
  468. package/dist/voice/aisdk/index.d.ts.map +1 -0
  469. package/dist/voice/aisdk/speech.d.ts +23 -0
  470. package/dist/voice/aisdk/speech.d.ts.map +1 -0
  471. package/dist/voice/aisdk/transcription.d.ts +22 -0
  472. package/dist/voice/aisdk/transcription.d.ts.map +1 -0
  473. package/dist/voice/composite-voice.d.ts +4 -3
  474. package/dist/voice/composite-voice.d.ts.map +1 -1
  475. package/dist/voice/index.cjs +12 -4
  476. package/dist/voice/index.d.ts +1 -0
  477. package/dist/voice/index.d.ts.map +1 -1
  478. package/dist/voice/index.js +1 -1
  479. package/dist/workflows/default.d.ts +180 -270
  480. package/dist/workflows/default.d.ts.map +1 -1
  481. package/dist/workflows/evented/execution-engine.d.ts +3 -1
  482. package/dist/workflows/evented/execution-engine.d.ts.map +1 -1
  483. package/dist/workflows/evented/index.cjs +10 -10
  484. package/dist/workflows/evented/index.js +1 -1
  485. package/dist/workflows/evented/step-executor.d.ts +1 -1
  486. package/dist/workflows/evented/step-executor.d.ts.map +1 -1
  487. package/dist/workflows/evented/workflow-event-processor/index.d.ts +5 -4
  488. package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
  489. package/dist/workflows/evented/workflow-event-processor/loop.d.ts +1 -1
  490. package/dist/workflows/evented/workflow-event-processor/loop.d.ts.map +1 -1
  491. package/dist/workflows/evented/workflow-event-processor/parallel.d.ts +2 -2
  492. package/dist/workflows/evented/workflow-event-processor/parallel.d.ts.map +1 -1
  493. package/dist/workflows/evented/workflow-event-processor/sleep.d.ts +2 -2
  494. package/dist/workflows/evented/workflow-event-processor/sleep.d.ts.map +1 -1
  495. package/dist/workflows/evented/workflow.d.ts +2 -1
  496. package/dist/workflows/evented/workflow.d.ts.map +1 -1
  497. package/dist/workflows/execution-engine.d.ts +8 -6
  498. package/dist/workflows/execution-engine.d.ts.map +1 -1
  499. package/dist/workflows/handlers/control-flow.d.ts +133 -0
  500. package/dist/workflows/handlers/control-flow.d.ts.map +1 -0
  501. package/dist/workflows/handlers/entry.d.ts +43 -0
  502. package/dist/workflows/handlers/entry.d.ts.map +1 -0
  503. package/dist/workflows/handlers/sleep.d.ts +60 -0
  504. package/dist/workflows/handlers/sleep.d.ts.map +1 -0
  505. package/dist/workflows/handlers/step.d.ts +58 -0
  506. package/dist/workflows/handlers/step.d.ts.map +1 -0
  507. package/dist/workflows/index.cjs +40 -16
  508. package/dist/workflows/index.js +1 -1
  509. package/dist/workflows/step.d.ts +8 -6
  510. package/dist/workflows/step.d.ts.map +1 -1
  511. package/dist/workflows/types.d.ts +257 -10
  512. package/dist/workflows/types.d.ts.map +1 -1
  513. package/dist/workflows/utils.d.ts +36 -0
  514. package/dist/workflows/utils.d.ts.map +1 -1
  515. package/dist/workflows/workflow.d.ts +146 -55
  516. package/dist/workflows/workflow.d.ts.map +1 -1
  517. package/package.json +26 -30
  518. package/src/llm/model/provider-types.generated.d.ts +489 -27
  519. package/dist/chunk-2ZVKF4HP.cjs.map +0 -1
  520. package/dist/chunk-436FFEF6.js +0 -34
  521. package/dist/chunk-436FFEF6.js.map +0 -1
  522. package/dist/chunk-4CDL2QJT.js.map +0 -1
  523. package/dist/chunk-7AHYOMHJ.js +0 -149
  524. package/dist/chunk-7AHYOMHJ.js.map +0 -1
  525. package/dist/chunk-CB575O6L.cjs.map +0 -1
  526. package/dist/chunk-CD56CXVE.cjs.map +0 -1
  527. package/dist/chunk-CINNK34N.js.map +0 -1
  528. package/dist/chunk-DNEURYF3.cjs.map +0 -1
  529. package/dist/chunk-DSNPWVIG.cjs.map +0 -1
  530. package/dist/chunk-E7K4FTLN.cjs.map +0 -1
  531. package/dist/chunk-ECFXGXWO.cjs.map +0 -1
  532. package/dist/chunk-ET6UOTTU.cjs +0 -154
  533. package/dist/chunk-ET6UOTTU.cjs.map +0 -1
  534. package/dist/chunk-GGYKYORQ.cjs.map +0 -1
  535. package/dist/chunk-GRBGQ2GE.js.map +0 -1
  536. package/dist/chunk-H6CZGPZD.js.map +0 -1
  537. package/dist/chunk-HDJFSJCK.js +0 -2237
  538. package/dist/chunk-HDJFSJCK.js.map +0 -1
  539. package/dist/chunk-HGNRQ3OG.js +0 -58
  540. package/dist/chunk-HGNRQ3OG.js.map +0 -1
  541. package/dist/chunk-I4CXL4SR.js.map +0 -1
  542. package/dist/chunk-IQO7ANVS.cjs.map +0 -1
  543. package/dist/chunk-J7O6WENZ.cjs.map +0 -1
  544. package/dist/chunk-JPGVRWWL.js.map +0 -1
  545. package/dist/chunk-JUBFO5J3.js.map +0 -1
  546. package/dist/chunk-JV2KH24V.js.map +0 -1
  547. package/dist/chunk-KIZIOFZC.js.map +0 -1
  548. package/dist/chunk-KJ2SW6VA.js.map +0 -1
  549. package/dist/chunk-LJFJTTZQ.cjs +0 -4
  550. package/dist/chunk-LJFJTTZQ.cjs.map +0 -1
  551. package/dist/chunk-LRSB62Z6.cjs +0 -60
  552. package/dist/chunk-LRSB62Z6.cjs.map +0 -1
  553. package/dist/chunk-LWBQ4P4N.cjs +0 -2240
  554. package/dist/chunk-LWBQ4P4N.cjs.map +0 -1
  555. package/dist/chunk-MA7TEM62.cjs.map +0 -1
  556. package/dist/chunk-MSWTA73A.cjs.map +0 -1
  557. package/dist/chunk-MV7KHWUT.js.map +0 -1
  558. package/dist/chunk-QUKUN6NR.cjs.map +0 -1
  559. package/dist/chunk-TQTAMPSC.js.map +0 -1
  560. package/dist/chunk-UIZSWUKP.js.map +0 -1
  561. package/dist/chunk-V3VLOOSW.cjs +0 -36
  562. package/dist/chunk-V3VLOOSW.cjs.map +0 -1
  563. package/dist/chunk-VOQ3ULMT.js.map +0 -1
  564. package/dist/chunk-VOY2RXOC.cjs.map +0 -1
  565. package/dist/chunk-W7UH2PWL.js.map +0 -1
  566. package/dist/chunk-WM6CK2F3.cjs.map +0 -1
  567. package/dist/chunk-XEVG546F.js.map +0 -1
  568. package/dist/chunk-Y63IFHEZ.cjs.map +0 -1
  569. package/dist/chunk-ZV5CC35D.js +0 -3
  570. package/dist/chunk-ZV5CC35D.js.map +0 -1
  571. package/dist/models-dev-DNBKXHT4.js +0 -3
  572. package/dist/models-dev-YBEEQIX6.cjs +0 -12
  573. package/dist/netlify-7G2L5VSH.js +0 -3
  574. package/dist/netlify-GWNGSIRZ.cjs +0 -12
  575. package/dist/registry-generator-H4YNODDH.js.map +0 -1
  576. package/dist/registry-generator-MK63POJO.cjs.map +0 -1
@@ -195,7 +195,7 @@ function convertImageFilePart(part, downloadedAssets) {
195
195
  const { data: convertedData, mediaType: convertedMediaType } = convertToDataContent(originalData);
196
196
  let mediaType = convertedMediaType ?? part.mediaType;
197
197
  let data = convertedData;
198
- if (data instanceof URL) {
198
+ if (data instanceof URL && downloadedAssets) {
199
199
  const downloadedFile = downloadedAssets[data.toString()];
200
200
  if (downloadedFile) {
201
201
  data = downloadedFile.data;
@@ -230,14 +230,137 @@ function convertImageFilePart(part, downloadedAssets) {
230
230
  }
231
231
  }
232
232
  }
233
+ zod.z.union([
234
+ zod.z.string(),
235
+ zod.z.instanceof(Uint8Array),
236
+ zod.z.instanceof(ArrayBuffer),
237
+ zod.z.custom(
238
+ // Buffer might not be available in some environments such as CloudFlare:
239
+ (value) => globalThis.Buffer?.isBuffer(value) ?? false,
240
+ { message: "Must be a Buffer" }
241
+ )
242
+ ]);
243
+ function convertDataContentToBase64String(content) {
244
+ if (typeof content === "string") {
245
+ return content;
246
+ }
247
+ if (content instanceof ArrayBuffer) {
248
+ return chunkSVLMF4UZ_cjs.convertUint8ArrayToBase64(new Uint8Array(content));
249
+ }
250
+ return chunkSVLMF4UZ_cjs.convertUint8ArrayToBase64(content);
251
+ }
252
+
253
+ // src/agent/message-list/prompt/image-utils.ts
254
+ function parseDataUri(dataUri) {
255
+ if (!dataUri.startsWith("data:")) {
256
+ return {
257
+ isDataUri: false,
258
+ base64Content: dataUri
259
+ };
260
+ }
261
+ const base64Index = dataUri.indexOf(",");
262
+ if (base64Index === -1) {
263
+ return {
264
+ isDataUri: true,
265
+ base64Content: dataUri
266
+ };
267
+ }
268
+ const header = dataUri.substring(5, base64Index);
269
+ const base64Content = dataUri.substring(base64Index + 1);
270
+ const semicolonIndex = header.indexOf(";");
271
+ const mimeType = semicolonIndex !== -1 ? header.substring(0, semicolonIndex) : header;
272
+ return {
273
+ isDataUri: true,
274
+ mimeType: mimeType || void 0,
275
+ base64Content
276
+ };
277
+ }
278
+ function createDataUri(base64Content, mimeType = "application/octet-stream") {
279
+ if (base64Content.startsWith("data:")) {
280
+ return base64Content;
281
+ }
282
+ return `data:${mimeType};base64,${base64Content}`;
283
+ }
284
+ function imageContentToString(image, fallbackMimeType) {
285
+ if (typeof image === "string") {
286
+ return image;
287
+ }
288
+ if (image instanceof URL) {
289
+ return image.toString();
290
+ }
291
+ if (image instanceof Uint8Array || image instanceof ArrayBuffer || globalThis.Buffer && Buffer.isBuffer(image)) {
292
+ const base64 = convertDataContentToBase64String(image);
293
+ return base64;
294
+ }
295
+ return String(image);
296
+ }
297
+ function getImageCacheKey(image) {
298
+ if (image instanceof URL) {
299
+ return image.toString();
300
+ }
301
+ if (typeof image === "string") {
302
+ return image.length;
303
+ }
304
+ if (image instanceof Uint8Array) {
305
+ return image.byteLength;
306
+ }
307
+ if (image instanceof ArrayBuffer) {
308
+ return image.byteLength;
309
+ }
310
+ return image;
311
+ }
312
+ function isValidUrl(str) {
313
+ try {
314
+ new URL(str);
315
+ return true;
316
+ } catch {
317
+ if (str.startsWith("//")) {
318
+ try {
319
+ new URL(`https:${str}`);
320
+ return true;
321
+ } catch {
322
+ return false;
323
+ }
324
+ }
325
+ return false;
326
+ }
327
+ }
328
+ function categorizeFileData(data, fallbackMimeType) {
329
+ const parsed = parseDataUri(data);
330
+ const mimeType = parsed.isDataUri && parsed.mimeType ? parsed.mimeType : fallbackMimeType;
331
+ if (parsed.isDataUri) {
332
+ return {
333
+ type: "dataUri",
334
+ mimeType,
335
+ data
336
+ };
337
+ }
338
+ if (isValidUrl(data)) {
339
+ return {
340
+ type: "url",
341
+ mimeType,
342
+ data
343
+ };
344
+ }
345
+ return {
346
+ type: "raw",
347
+ mimeType,
348
+ data
349
+ };
350
+ }
233
351
 
234
352
  // src/agent/message-list/prompt/attachments-to-parts.ts
235
353
  function attachmentsToParts(attachments) {
236
354
  const parts = [];
237
355
  for (const attachment of attachments) {
356
+ const categorized = categorizeFileData(attachment.url, attachment.contentType);
357
+ let urlString = attachment.url;
358
+ if (categorized.type === "raw") {
359
+ urlString = createDataUri(attachment.url, attachment.contentType || "application/octet-stream");
360
+ }
238
361
  let url;
239
362
  try {
240
- url = new URL(attachment.url);
363
+ url = new URL(urlString);
241
364
  } catch {
242
365
  throw new Error(`Invalid URL: ${attachment.url}`);
243
366
  }
@@ -262,13 +385,13 @@ function attachmentsToParts(attachments) {
262
385
  if (attachment.contentType?.startsWith("image/")) {
263
386
  parts.push({
264
387
  type: "image",
265
- image: attachment.url,
388
+ image: urlString,
266
389
  mimeType: attachment.contentType
267
390
  });
268
391
  } else if (attachment.contentType?.startsWith("text/")) {
269
392
  parts.push({
270
393
  type: "file",
271
- data: attachment.url,
394
+ data: urlString,
272
395
  mimeType: attachment.contentType
273
396
  });
274
397
  } else {
@@ -277,7 +400,7 @@ function attachmentsToParts(attachments) {
277
400
  }
278
401
  parts.push({
279
402
  type: "file",
280
- data: attachment.url,
403
+ data: urlString,
281
404
  mimeType: attachment.contentType
282
405
  });
283
406
  }
@@ -588,25 +711,6 @@ function convertToV1Messages(messages) {
588
711
  }
589
712
  return v1Messages;
590
713
  }
591
- zod.z.union([
592
- zod.z.string(),
593
- zod.z.instanceof(Uint8Array),
594
- zod.z.instanceof(ArrayBuffer),
595
- zod.z.custom(
596
- // Buffer might not be available in some environments such as CloudFlare:
597
- (value) => globalThis.Buffer?.isBuffer(value) ?? false,
598
- { message: "Must be a Buffer" }
599
- )
600
- ]);
601
- function convertDataContentToBase64String(content) {
602
- if (typeof content === "string") {
603
- return content;
604
- }
605
- if (content instanceof ArrayBuffer) {
606
- return chunkSVLMF4UZ_cjs.convertUint8ArrayToBase64(new Uint8Array(content));
607
- }
608
- return chunkSVLMF4UZ_cjs.convertUint8ArrayToBase64(content);
609
- }
610
714
 
611
715
  // src/utils/fetchWithRetry.ts
612
716
  async function fetchWithRetry(url, options = {}, maxRetries = 3) {
@@ -697,18 +801,20 @@ async function downloadAssetsFromMessages({
697
801
  }
698
802
  }
699
803
  return { mediaType, data };
700
- }).filter((part) => part.data instanceof URL).map((part) => ({
701
- url: part.data,
702
- isUrlSupportedByModel: part.mediaType != null && providerUtilsV5.isUrlSupported({
703
- url: part.data.toString(),
704
- mediaType: part.mediaType,
705
- supportedUrls: supportedUrls ?? {}
706
- })
707
- }));
804
+ }).filter((part) => part.data instanceof URL).map((part) => {
805
+ return {
806
+ url: part.data,
807
+ isUrlSupportedByModel: part.mediaType != null && providerUtilsV5.isUrlSupported({
808
+ url: part.data.toString(),
809
+ mediaType: part.mediaType,
810
+ supportedUrls: supportedUrls ?? {}
811
+ })
812
+ };
813
+ });
708
814
  const downloadedFiles = await pMap(
709
815
  filesToDownload,
710
816
  async (fileItem) => {
711
- if (!fileItem.isUrlSupportedByModel) {
817
+ if (fileItem.isUrlSupportedByModel) {
712
818
  return null;
713
819
  }
714
820
  return {
@@ -726,105 +832,6 @@ async function downloadAssetsFromMessages({
726
832
  return Object.fromEntries(downloadFileList);
727
833
  }
728
834
 
729
- // src/agent/message-list/prompt/image-utils.ts
730
- function parseDataUri(dataUri) {
731
- if (!dataUri.startsWith("data:")) {
732
- return {
733
- isDataUri: false,
734
- base64Content: dataUri
735
- };
736
- }
737
- const base64Index = dataUri.indexOf(",");
738
- if (base64Index === -1) {
739
- return {
740
- isDataUri: true,
741
- base64Content: dataUri
742
- };
743
- }
744
- const header = dataUri.substring(5, base64Index);
745
- const base64Content = dataUri.substring(base64Index + 1);
746
- const semicolonIndex = header.indexOf(";");
747
- const mimeType = semicolonIndex !== -1 ? header.substring(0, semicolonIndex) : header;
748
- return {
749
- isDataUri: true,
750
- mimeType: mimeType || void 0,
751
- base64Content
752
- };
753
- }
754
- function createDataUri(base64Content, mimeType = "application/octet-stream") {
755
- if (base64Content.startsWith("data:")) {
756
- return base64Content;
757
- }
758
- return `data:${mimeType};base64,${base64Content}`;
759
- }
760
- function imageContentToString(image, fallbackMimeType) {
761
- if (typeof image === "string") {
762
- return image;
763
- }
764
- if (image instanceof URL) {
765
- return image.toString();
766
- }
767
- if (image instanceof Uint8Array || image instanceof ArrayBuffer || globalThis.Buffer && Buffer.isBuffer(image)) {
768
- const base64 = convertDataContentToBase64String(image);
769
- return base64;
770
- }
771
- return String(image);
772
- }
773
- function getImageCacheKey(image) {
774
- if (image instanceof URL) {
775
- return image.toString();
776
- }
777
- if (typeof image === "string") {
778
- return image.length;
779
- }
780
- if (image instanceof Uint8Array) {
781
- return image.byteLength;
782
- }
783
- if (image instanceof ArrayBuffer) {
784
- return image.byteLength;
785
- }
786
- return image;
787
- }
788
- function isValidUrl(str) {
789
- try {
790
- new URL(str);
791
- return true;
792
- } catch {
793
- if (str.startsWith("//")) {
794
- try {
795
- new URL(`https:${str}`);
796
- return true;
797
- } catch {
798
- return false;
799
- }
800
- }
801
- return false;
802
- }
803
- }
804
- function categorizeFileData(data, fallbackMimeType) {
805
- const parsed = parseDataUri(data);
806
- const mimeType = parsed.isDataUri && parsed.mimeType ? parsed.mimeType : fallbackMimeType;
807
- if (parsed.isDataUri) {
808
- return {
809
- type: "dataUri",
810
- mimeType,
811
- data
812
- };
813
- }
814
- if (isValidUrl(data)) {
815
- return {
816
- type: "url",
817
- mimeType,
818
- data
819
- };
820
- }
821
- return {
822
- type: "raw",
823
- mimeType,
824
- data
825
- };
826
- }
827
-
828
835
  // src/agent/message-list/utils/ai-v5/gemini-compatibility.ts
829
836
  function ensureGeminiCompatibleMessages(messages) {
830
837
  const result = [...messages];
@@ -892,6 +899,9 @@ function convertMessages(messages) {
892
899
  }
893
900
 
894
901
  // src/agent/message-list/index.ts
902
+ function filterDataParts(parts) {
903
+ return parts.filter((part) => !part.type.startsWith("data-"));
904
+ }
895
905
  var MessageList = class _MessageList {
896
906
  messages = [];
897
907
  // passed in by dev in input or context
@@ -910,6 +920,9 @@ var MessageList = class _MessageList {
910
920
  userContextMessagesPersisted = /* @__PURE__ */ new Set();
911
921
  generateMessageId;
912
922
  _agentNetworkAppend = false;
923
+ // Event recording for observability
924
+ isRecording = false;
925
+ recordedEvents = [];
913
926
  constructor({
914
927
  threadId,
915
928
  resourceId,
@@ -923,10 +936,34 @@ var MessageList = class _MessageList {
923
936
  this.generateMessageId = generateMessageId;
924
937
  this._agentNetworkAppend = _agentNetworkAppend || false;
925
938
  }
939
+ /**
940
+ * Start recording mutations to the MessageList for observability/tracing
941
+ */
942
+ startRecording() {
943
+ this.isRecording = true;
944
+ this.recordedEvents = [];
945
+ }
946
+ /**
947
+ * Stop recording and return the list of recorded events
948
+ */
949
+ stopRecording() {
950
+ this.isRecording = false;
951
+ const events = [...this.recordedEvents];
952
+ this.recordedEvents = [];
953
+ return events;
954
+ }
926
955
  add(messages, messageSource) {
927
956
  if (messageSource === `user`) messageSource = `input`;
928
957
  if (!messages) return this;
929
- for (const message of Array.isArray(messages) ? messages : [messages]) {
958
+ const messageArray = Array.isArray(messages) ? messages : [messages];
959
+ if (this.isRecording) {
960
+ this.recordedEvents.push({
961
+ type: "add",
962
+ source: messageSource,
963
+ count: messageArray.length
964
+ });
965
+ }
966
+ for (const message of messageArray) {
930
967
  this.addOne(
931
968
  typeof message === `string` ? {
932
969
  role: "user",
@@ -988,6 +1025,24 @@ var MessageList = class _MessageList {
988
1025
  this.userContextMessagesPersisted = this.deserializeSet(state.userContextMessagesPersisted);
989
1026
  return this;
990
1027
  }
1028
+ makeMessageSourceChecker() {
1029
+ const sources = {
1030
+ memory: new Set(Array.from(this.memoryMessages.values()).map((m) => m.id)),
1031
+ output: new Set(Array.from(this.newResponseMessages.values()).map((m) => m.id)),
1032
+ input: new Set(Array.from(this.newUserMessages.values()).map((m) => m.id)),
1033
+ context: new Set(Array.from(this.userContextMessages.values()).map((m) => m.id))
1034
+ };
1035
+ return {
1036
+ ...sources,
1037
+ getSource: (msg) => {
1038
+ if (sources.memory.has(msg.id)) return "memory";
1039
+ if (sources.input.has(msg.id)) return "input";
1040
+ if (sources.output.has(msg.id)) return "response";
1041
+ if (sources.context.has(msg.id)) return "context";
1042
+ return null;
1043
+ }
1044
+ };
1045
+ }
991
1046
  getLatestUserContent() {
992
1047
  const currentUserMessages = this.all.core().filter((m) => m.role === "user");
993
1048
  const content = currentUserMessages.at(-1)?.content;
@@ -1012,11 +1067,34 @@ var MessageList = class _MessageList {
1012
1067
  }
1013
1068
  get clear() {
1014
1069
  return {
1070
+ all: {
1071
+ db: () => {
1072
+ const allMessages = [...this.messages];
1073
+ this.messages = [];
1074
+ this.newUserMessages.clear();
1075
+ this.newResponseMessages.clear();
1076
+ this.userContextMessages.clear();
1077
+ if (this.isRecording && allMessages.length > 0) {
1078
+ this.recordedEvents.push({
1079
+ type: "clear",
1080
+ count: allMessages.length
1081
+ });
1082
+ }
1083
+ return allMessages;
1084
+ }
1085
+ },
1015
1086
  input: {
1016
1087
  db: () => {
1017
1088
  const userMessages = Array.from(this.newUserMessages);
1018
1089
  this.messages = this.messages.filter((m) => !this.newUserMessages.has(m));
1019
1090
  this.newUserMessages.clear();
1091
+ if (this.isRecording && userMessages.length > 0) {
1092
+ this.recordedEvents.push({
1093
+ type: "clear",
1094
+ source: "input",
1095
+ count: userMessages.length
1096
+ });
1097
+ }
1020
1098
  return userMessages;
1021
1099
  }
1022
1100
  },
@@ -1025,11 +1103,46 @@ var MessageList = class _MessageList {
1025
1103
  const responseMessages = Array.from(this.newResponseMessages);
1026
1104
  this.messages = this.messages.filter((m) => !this.newResponseMessages.has(m));
1027
1105
  this.newResponseMessages.clear();
1106
+ if (this.isRecording && responseMessages.length > 0) {
1107
+ this.recordedEvents.push({
1108
+ type: "clear",
1109
+ source: "response",
1110
+ count: responseMessages.length
1111
+ });
1112
+ }
1028
1113
  return responseMessages;
1029
1114
  }
1030
1115
  }
1031
1116
  };
1032
1117
  }
1118
+ /**
1119
+ * Remove messages by ID
1120
+ * @param ids - Array of message IDs to remove
1121
+ * @returns Array of removed messages
1122
+ */
1123
+ removeByIds(ids) {
1124
+ const idsSet = new Set(ids);
1125
+ const removed = [];
1126
+ this.messages = this.messages.filter((m) => {
1127
+ if (idsSet.has(m.id)) {
1128
+ removed.push(m);
1129
+ this.memoryMessages.delete(m);
1130
+ this.newUserMessages.delete(m);
1131
+ this.newResponseMessages.delete(m);
1132
+ this.userContextMessages.delete(m);
1133
+ return false;
1134
+ }
1135
+ return true;
1136
+ });
1137
+ if (this.isRecording && removed.length > 0) {
1138
+ this.recordedEvents.push({
1139
+ type: "removeByIds",
1140
+ ids,
1141
+ count: removed.length
1142
+ });
1143
+ }
1144
+ return removed;
1145
+ }
1033
1146
  all = {
1034
1147
  db: () => this.messages,
1035
1148
  v1: () => convertToV1Messages(this.all.db()),
@@ -1063,7 +1176,10 @@ var MessageList = class _MessageList {
1063
1176
  supportedUrls: options?.supportedUrls
1064
1177
  });
1065
1178
  let messages = [...systemMessages, ...modelMessages];
1066
- if (Object.keys(downloadedAssets || {}).length > 0) {
1179
+ const hasImageOrFileContent = modelMessages.some(
1180
+ (message) => message.role === "user" && typeof message.content !== "string" && message.content.some((part) => part.type === "image" || part.type === "file")
1181
+ );
1182
+ if (hasImageOrFileContent) {
1067
1183
  messages = messages.map((message) => {
1068
1184
  if (message.role === "user") {
1069
1185
  if (typeof message.content === "string") {
@@ -1330,12 +1446,47 @@ var MessageList = class _MessageList {
1330
1446
  if (unsavedMessages.length === 0) return void 0;
1331
1447
  return Math.min(...unsavedMessages.map((m) => new Date(m.createdAt).getTime()));
1332
1448
  }
1449
+ /**
1450
+ * Check if a message is a new user or response message that should be saved.
1451
+ * Checks by message ID to handle cases where the message object may be a copy.
1452
+ */
1453
+ isNewMessage(messageOrId) {
1454
+ const id = typeof messageOrId === "string" ? messageOrId : messageOrId.id;
1455
+ if (typeof messageOrId !== "string") {
1456
+ if (this.newUserMessages.has(messageOrId) || this.newResponseMessages.has(messageOrId)) {
1457
+ return true;
1458
+ }
1459
+ }
1460
+ return Array.from(this.newUserMessages).some((m) => m.id === id) || Array.from(this.newResponseMessages).some((m) => m.id === id);
1461
+ }
1333
1462
  getSystemMessages(tag) {
1334
1463
  if (tag) {
1335
1464
  return this.taggedSystemMessages[tag] || [];
1336
1465
  }
1337
1466
  return this.systemMessages;
1338
1467
  }
1468
+ /**
1469
+ * Get all system messages (both tagged and untagged)
1470
+ * @returns Array of all system messages
1471
+ */
1472
+ getAllSystemMessages() {
1473
+ return [...this.systemMessages, ...Object.values(this.taggedSystemMessages).flat()];
1474
+ }
1475
+ /**
1476
+ * Replace all system messages with new ones
1477
+ * This clears both tagged and untagged system messages and replaces them with the provided array
1478
+ * @param messages - Array of system messages to set
1479
+ */
1480
+ replaceAllSystemMessages(messages) {
1481
+ this.systemMessages = [];
1482
+ this.taggedSystemMessages = {};
1483
+ for (const message of messages) {
1484
+ if (message.role === "system") {
1485
+ this.systemMessages.push(message);
1486
+ }
1487
+ }
1488
+ return this;
1489
+ }
1339
1490
  addSystem(messages, tag) {
1340
1491
  if (!messages) return this;
1341
1492
  for (const message of Array.isArray(messages) ? messages : [messages]) {
@@ -1394,8 +1545,21 @@ var MessageList = class _MessageList {
1394
1545
  if (tag && !this.isDuplicateSystem(coreMessage, tag)) {
1395
1546
  this.taggedSystemMessages[tag] ||= [];
1396
1547
  this.taggedSystemMessages[tag].push(coreMessage);
1548
+ if (this.isRecording) {
1549
+ this.recordedEvents.push({
1550
+ type: "addSystem",
1551
+ tag,
1552
+ message: coreMessage
1553
+ });
1554
+ }
1397
1555
  } else if (!tag && !this.isDuplicateSystem(coreMessage)) {
1398
1556
  this.systemMessages.push(coreMessage);
1557
+ if (this.isRecording) {
1558
+ this.recordedEvents.push({
1559
+ type: "addSystem",
1560
+ message: coreMessage
1561
+ });
1562
+ }
1399
1563
  }
1400
1564
  }
1401
1565
  isDuplicateSystem(message, tag) {
@@ -1421,9 +1585,20 @@ var MessageList = class _MessageList {
1421
1585
  if (m.content.parts.length) {
1422
1586
  for (const part of m.content.parts) {
1423
1587
  if (part.type === `file`) {
1588
+ let normalizedUrl;
1589
+ if (typeof part.data === "string") {
1590
+ const categorized = categorizeFileData(part.data, part.mimeType);
1591
+ if (categorized.type === "raw") {
1592
+ normalizedUrl = createDataUri(part.data, part.mimeType || "application/octet-stream");
1593
+ } else {
1594
+ normalizedUrl = part.data;
1595
+ }
1596
+ } else {
1597
+ normalizedUrl = part.data;
1598
+ }
1424
1599
  experimentalAttachments.push({
1425
1600
  contentType: part.mimeType,
1426
- url: part.data
1601
+ url: normalizedUrl
1427
1602
  });
1428
1603
  } else if (part.type === "tool-invocation" && (part.toolInvocation.state === "call" || part.toolInvocation.state === "partial-call")) {
1429
1604
  continue;
@@ -1461,13 +1636,14 @@ var MessageList = class _MessageList {
1461
1636
  if (parts.length === 0 && experimentalAttachments.length > 0) {
1462
1637
  parts.push({ type: "text", text: "" });
1463
1638
  }
1639
+ const v4Parts = filterDataParts(parts);
1464
1640
  if (m.role === `user`) {
1465
1641
  const uiMessage2 = {
1466
1642
  id: m.id,
1467
1643
  role: m.role,
1468
1644
  content: m.content.content || contentString,
1469
1645
  createdAt: m.createdAt,
1470
- parts,
1646
+ parts: v4Parts,
1471
1647
  experimental_attachments: experimentalAttachments
1472
1648
  };
1473
1649
  if (m.content.metadata) {
@@ -1481,7 +1657,7 @@ var MessageList = class _MessageList {
1481
1657
  role: m.role,
1482
1658
  content: isSingleTextContentArray ? contentString : m.content.content || contentString,
1483
1659
  createdAt: m.createdAt,
1484
- parts,
1660
+ parts: v4Parts,
1485
1661
  reasoning: void 0,
1486
1662
  toolInvocations: `toolInvocations` in m.content ? m.content.toolInvocations?.filter((t) => t.state === "result") : void 0
1487
1663
  };
@@ -1495,7 +1671,7 @@ var MessageList = class _MessageList {
1495
1671
  role: m.role,
1496
1672
  content: m.content.content || contentString,
1497
1673
  createdAt: m.createdAt,
1498
- parts,
1674
+ parts: v4Parts,
1499
1675
  experimental_attachments: experimentalAttachments
1500
1676
  };
1501
1677
  if (m.content.metadata) {
@@ -1664,6 +1840,9 @@ var MessageList = class _MessageList {
1664
1840
  } else if (messageSource === `response`) {
1665
1841
  this.newResponseMessages.add(messageV2);
1666
1842
  this.newResponseMessagesPersisted.add(messageV2);
1843
+ if (this.newUserMessages.has(messageV2)) {
1844
+ this.newUserMessages.delete(messageV2);
1845
+ }
1667
1846
  } else if (messageSource === `input`) {
1668
1847
  this.newUserMessages.add(messageV2);
1669
1848
  this.newUserMessagesPersisted.add(messageV2);
@@ -1688,13 +1867,11 @@ var MessageList = class _MessageList {
1688
1867
  insertAt
1689
1868
  // optional
1690
1869
  }) {
1691
- const partKey = _MessageList.cacheKeyFromAIV4Parts([part]);
1870
+ const partKey = _MessageList.cacheKeyFromDBParts([part]);
1692
1871
  const latestPartCount = latestMessage.content.parts.filter(
1693
- (p) => _MessageList.cacheKeyFromAIV4Parts([p]) === partKey
1694
- ).length;
1695
- const newPartCount = newMessage.content.parts.filter(
1696
- (p) => _MessageList.cacheKeyFromAIV4Parts([p]) === partKey
1872
+ (p) => _MessageList.cacheKeyFromDBParts([p]) === partKey
1697
1873
  ).length;
1874
+ const newPartCount = newMessage.content.parts.filter((p) => _MessageList.cacheKeyFromDBParts([p]) === partKey).length;
1698
1875
  if (latestPartCount < newPartCount) {
1699
1876
  const partIndex = newMessage.content.parts.indexOf(part);
1700
1877
  const hasStepStartBefore = partIndex > 0 && newMessage.content.parts[partIndex - 1]?.type === "step-start";
@@ -1730,7 +1907,7 @@ var MessageList = class _MessageList {
1730
1907
  for (let i = 0; i < messageV2.content.parts.length; ++i) {
1731
1908
  const part = messageV2.content.parts[i];
1732
1909
  if (!part) continue;
1733
- const key = _MessageList.cacheKeyFromAIV4Parts([part]);
1910
+ const key = _MessageList.cacheKeyFromDBParts([part]);
1734
1911
  const partToAdd = partsToAdd.get(i);
1735
1912
  if (!key || !partToAdd) continue;
1736
1913
  if (anchorMap.size > 0) {
@@ -1741,7 +1918,7 @@ var MessageList = class _MessageList {
1741
1918
  const offset = leftAnchorV2 === -1 ? i : i - leftAnchorV2;
1742
1919
  const insertAt = leftAnchorLatest + offset;
1743
1920
  const rightAnchorLatest = rightAnchorV2 !== -1 ? anchorMap.get(rightAnchorV2) : latestMessage.content.parts.length;
1744
- if (insertAt >= 0 && insertAt <= rightAnchorLatest && !latestMessage.content.parts.slice(insertAt, rightAnchorLatest).some((p) => _MessageList.cacheKeyFromAIV4Parts([p]) === _MessageList.cacheKeyFromAIV4Parts([part]))) {
1921
+ if (insertAt >= 0 && insertAt <= rightAnchorLatest && !latestMessage.content.parts.slice(insertAt, rightAnchorLatest).some((p) => _MessageList.cacheKeyFromDBParts([p]) === _MessageList.cacheKeyFromDBParts([part]))) {
1745
1922
  this.pushNewMessagePart({
1746
1923
  latestMessage,
1747
1924
  newMessage: messageV2,
@@ -1792,8 +1969,10 @@ var MessageList = class _MessageList {
1792
1969
  }
1793
1970
  if (_MessageList.isAIV5CoreMessage(message)) {
1794
1971
  const dbMsg = _MessageList.aiV5ModelMessageToMastraDBMessage(message, messageSource);
1972
+ const rawCreatedAt = "metadata" in message && message.metadata && typeof message.metadata === "object" && "createdAt" in message.metadata ? message.metadata.createdAt : void 0;
1795
1973
  const result = {
1796
1974
  ...dbMsg,
1975
+ createdAt: this.generateCreatedAt(messageSource, rawCreatedAt),
1797
1976
  threadId: this.memoryInfo?.threadId,
1798
1977
  resourceId: this.memoryInfo?.resourceId
1799
1978
  };
@@ -1801,8 +1980,10 @@ var MessageList = class _MessageList {
1801
1980
  }
1802
1981
  if (_MessageList.isAIV5UIMessage(message)) {
1803
1982
  const dbMsg = _MessageList.aiV5UIMessageToMastraDBMessage(message);
1983
+ const rawCreatedAt = "createdAt" in message ? message.createdAt : void 0;
1804
1984
  return {
1805
1985
  ...dbMsg,
1986
+ createdAt: this.generateCreatedAt(messageSource, rawCreatedAt),
1806
1987
  threadId: this.memoryInfo?.threadId,
1807
1988
  resourceId: this.memoryInfo?.resourceId
1808
1989
  };
@@ -1812,16 +1993,16 @@ var MessageList = class _MessageList {
1812
1993
  lastCreatedAt;
1813
1994
  // this makes sure messages added in order will always have a date atleast 1ms apart.
1814
1995
  generateCreatedAt(messageSource, start) {
1815
- start = start instanceof Date ? start : start ? new Date(start) : void 0;
1816
- if (start && !this.lastCreatedAt) {
1817
- this.lastCreatedAt = start.getTime();
1818
- return start;
1996
+ const startDate = start instanceof Date ? start : typeof start === "string" || typeof start === "number" ? new Date(start) : void 0;
1997
+ if (startDate && !this.lastCreatedAt) {
1998
+ this.lastCreatedAt = startDate.getTime();
1999
+ return startDate;
1819
2000
  }
1820
- if (start && messageSource === `memory`) {
1821
- return start;
2001
+ if (startDate && messageSource === `memory`) {
2002
+ return startDate;
1822
2003
  }
1823
2004
  const now = /* @__PURE__ */ new Date();
1824
- const nowTime = start?.getTime() || now.getTime();
2005
+ const nowTime = startDate?.getTime() || now.getTime();
1825
2006
  const lastTime = this.messages.reduce((p, m) => {
1826
2007
  if (m.createdAt.getTime() > p) return m.createdAt.getTime();
1827
2008
  return p;
@@ -1875,6 +2056,12 @@ var MessageList = class _MessageList {
1875
2056
  return ti;
1876
2057
  });
1877
2058
  }
2059
+ if (!message.threadId && this.memoryInfo?.threadId) {
2060
+ message.threadId = this.memoryInfo.threadId;
2061
+ if (!message.resourceId && this.memoryInfo?.resourceId) {
2062
+ message.resourceId = this.memoryInfo.resourceId;
2063
+ }
2064
+ }
1878
2065
  return message;
1879
2066
  }
1880
2067
  aiV4UIMessageToMastraDBMessage(message, messageSource) {
@@ -1912,137 +2099,180 @@ var MessageList = class _MessageList {
1912
2099
  if (typeof coreMessage.content === "string") {
1913
2100
  parts.push({
1914
2101
  type: "text",
1915
- text: coreMessage.content,
1916
- // Preserve providerOptions from CoreMessage (e.g., for system messages with cacheControl)
1917
- ..."providerOptions" in coreMessage && coreMessage.providerOptions ? { providerMetadata: coreMessage.providerOptions } : {}
2102
+ text: coreMessage.content
1918
2103
  });
1919
2104
  } else if (Array.isArray(coreMessage.content)) {
1920
- for (const part of coreMessage.content) {
1921
- switch (part.type) {
1922
- case "text":
2105
+ for (const aiV4Part of coreMessage.content) {
2106
+ switch (aiV4Part.type) {
2107
+ case "text": {
1923
2108
  const prevPart = parts.at(-1);
1924
2109
  if (coreMessage.role === "assistant" && prevPart && prevPart.type === "tool-invocation") {
1925
2110
  parts.push({ type: "step-start" });
1926
2111
  }
1927
- const mergedProviderMetadata = {
1928
- ..."providerOptions" in coreMessage && coreMessage.providerOptions ? coreMessage.providerOptions : {},
1929
- ..."providerOptions" in part && part.providerOptions ? part.providerOptions : {}
1930
- };
1931
- parts.push({
2112
+ const part = {
1932
2113
  type: "text",
1933
- text: part.text,
1934
- ...Object.keys(mergedProviderMetadata).length > 0 ? { providerMetadata: mergedProviderMetadata } : {}
1935
- });
2114
+ text: aiV4Part.text
2115
+ };
2116
+ if (aiV4Part.providerOptions) {
2117
+ part.providerMetadata = aiV4Part.providerOptions;
2118
+ }
2119
+ parts.push(part);
1936
2120
  break;
1937
- case "tool-call":
1938
- parts.push({
2121
+ }
2122
+ case "tool-call": {
2123
+ const part = {
1939
2124
  type: "tool-invocation",
1940
2125
  toolInvocation: {
1941
2126
  state: "call",
1942
- toolCallId: part.toolCallId,
1943
- toolName: part.toolName,
1944
- args: part.args
2127
+ toolCallId: aiV4Part.toolCallId,
2128
+ toolName: aiV4Part.toolName,
2129
+ args: aiV4Part.args
1945
2130
  }
1946
- });
2131
+ };
2132
+ if (aiV4Part.providerOptions) {
2133
+ part.providerMetadata = aiV4Part.providerOptions;
2134
+ }
2135
+ parts.push(part);
1947
2136
  break;
2137
+ }
1948
2138
  case "tool-result":
1949
- let toolArgs = {};
1950
- const toolCallInSameMsg = coreMessage.content.find(
1951
- (p) => p.type === "tool-call" && p.toolCallId === part.toolCallId
1952
- );
1953
- if (toolCallInSameMsg && toolCallInSameMsg.type === "tool-call") {
1954
- toolArgs = toolCallInSameMsg.args;
1955
- }
1956
- if (Object.keys(toolArgs).length === 0) {
1957
- for (let i = this.messages.length - 1; i >= 0; i--) {
1958
- const msg = this.messages[i];
1959
- if (msg && msg.role === "assistant" && msg.content.parts) {
1960
- const toolCallPart = msg.content.parts.find(
1961
- (p) => p.type === "tool-invocation" && p.toolInvocation.toolCallId === part.toolCallId && p.toolInvocation.state === "call"
1962
- );
1963
- if (toolCallPart && toolCallPart.type === "tool-invocation" && toolCallPart.toolInvocation.args) {
1964
- toolArgs = toolCallPart.toolInvocation.args;
1965
- break;
2139
+ {
2140
+ let toolArgs = {};
2141
+ const toolCallInSameMsg = coreMessage.content.find(
2142
+ (p) => p.type === "tool-call" && p.toolCallId === aiV4Part.toolCallId
2143
+ );
2144
+ if (toolCallInSameMsg && toolCallInSameMsg.type === "tool-call") {
2145
+ toolArgs = toolCallInSameMsg.args;
2146
+ }
2147
+ if (Object.keys(toolArgs).length === 0) {
2148
+ for (let i = this.messages.length - 1; i >= 0; i--) {
2149
+ const msg = this.messages[i];
2150
+ if (msg && msg.role === "assistant" && msg.content.parts) {
2151
+ const toolCallPart = msg.content.parts.find(
2152
+ (p) => p.type === "tool-invocation" && p.toolInvocation.toolCallId === aiV4Part.toolCallId && p.toolInvocation.state === "call"
2153
+ );
2154
+ if (toolCallPart && toolCallPart.type === "tool-invocation" && toolCallPart.toolInvocation.args) {
2155
+ toolArgs = toolCallPart.toolInvocation.args;
2156
+ break;
2157
+ }
1966
2158
  }
1967
2159
  }
1968
2160
  }
2161
+ const invocation = {
2162
+ state: "result",
2163
+ toolCallId: aiV4Part.toolCallId,
2164
+ toolName: aiV4Part.toolName,
2165
+ result: aiV4Part.result ?? "",
2166
+ // undefined will cause AI SDK to throw an error, but for client side tool calls this really could be undefined
2167
+ args: toolArgs
2168
+ // Use the args from the corresponding tool-call
2169
+ };
2170
+ const part = {
2171
+ type: "tool-invocation",
2172
+ toolInvocation: invocation
2173
+ };
2174
+ if (aiV4Part.providerOptions) {
2175
+ part.providerMetadata = aiV4Part.providerOptions;
2176
+ }
2177
+ parts.push(part);
2178
+ toolInvocations.push(invocation);
1969
2179
  }
1970
- const invocation = {
1971
- state: "result",
1972
- toolCallId: part.toolCallId,
1973
- toolName: part.toolName,
1974
- result: part.result ?? "",
1975
- // undefined will cause AI SDK to throw an error, but for client side tool calls this really could be undefined
1976
- args: toolArgs
1977
- // Use the args from the corresponding tool-call
1978
- };
1979
- parts.push({
1980
- type: "tool-invocation",
1981
- toolInvocation: invocation
1982
- });
1983
- toolInvocations.push(invocation);
1984
2180
  break;
1985
2181
  case "reasoning":
1986
- parts.push({
1987
- type: "reasoning",
1988
- reasoning: "",
1989
- // leave this blank so we aren't double storing it in the db along with details
1990
- details: [{ type: "text", text: part.text, signature: part.signature }]
1991
- });
2182
+ {
2183
+ const part = {
2184
+ type: "reasoning",
2185
+ reasoning: "",
2186
+ // leave this blank so we aren't double storing it in the db along with details
2187
+ details: [{ type: "text", text: aiV4Part.text, signature: aiV4Part.signature }]
2188
+ };
2189
+ if (aiV4Part.providerOptions) {
2190
+ part.providerMetadata = aiV4Part.providerOptions;
2191
+ }
2192
+ parts.push(part);
2193
+ }
1992
2194
  break;
1993
2195
  case "redacted-reasoning":
1994
- parts.push({
1995
- type: "reasoning",
1996
- reasoning: "",
1997
- // No text reasoning for redacted parts
1998
- details: [{ type: "redacted", data: part.data }]
1999
- });
2196
+ {
2197
+ const part = {
2198
+ type: "reasoning",
2199
+ reasoning: "",
2200
+ // No text reasoning for redacted parts
2201
+ details: [{ type: "redacted", data: aiV4Part.data }]
2202
+ };
2203
+ if (aiV4Part.providerOptions) {
2204
+ part.providerMetadata = aiV4Part.providerOptions;
2205
+ }
2206
+ parts.push(part);
2207
+ }
2000
2208
  break;
2001
- case "image":
2002
- parts.push({
2209
+ case "image": {
2210
+ const part = {
2003
2211
  type: "file",
2004
- data: imageContentToString(part.image),
2005
- mimeType: part.mimeType
2006
- });
2212
+ data: imageContentToString(aiV4Part.image),
2213
+ mimeType: aiV4Part.mimeType
2214
+ };
2215
+ if (aiV4Part.providerOptions) {
2216
+ part.providerMetadata = aiV4Part.providerOptions;
2217
+ }
2218
+ parts.push(part);
2007
2219
  break;
2008
- case "file":
2009
- if (part.data instanceof URL) {
2010
- parts.push({
2220
+ }
2221
+ case "file": {
2222
+ if (aiV4Part.data instanceof URL) {
2223
+ const part = {
2011
2224
  type: "file",
2012
- data: part.data.toString(),
2013
- mimeType: part.mimeType
2014
- });
2015
- } else if (typeof part.data === "string") {
2016
- const categorized = categorizeFileData(part.data, part.mimeType);
2225
+ data: aiV4Part.data.toString(),
2226
+ mimeType: aiV4Part.mimeType
2227
+ };
2228
+ if (aiV4Part.providerOptions) {
2229
+ part.providerMetadata = aiV4Part.providerOptions;
2230
+ }
2231
+ parts.push(part);
2232
+ } else if (typeof aiV4Part.data === "string") {
2233
+ const categorized = categorizeFileData(aiV4Part.data, aiV4Part.mimeType);
2017
2234
  if (categorized.type === "url" || categorized.type === "dataUri") {
2018
- parts.push({
2235
+ const part = {
2019
2236
  type: "file",
2020
- data: part.data,
2237
+ data: aiV4Part.data,
2021
2238
  mimeType: categorized.mimeType || "image/png"
2022
- });
2239
+ };
2240
+ if (aiV4Part.providerOptions) {
2241
+ part.providerMetadata = aiV4Part.providerOptions;
2242
+ }
2243
+ parts.push(part);
2023
2244
  } else {
2024
2245
  try {
2025
- parts.push({
2246
+ const part = {
2026
2247
  type: "file",
2027
2248
  mimeType: categorized.mimeType || "image/png",
2028
- data: convertDataContentToBase64String(part.data)
2029
- });
2249
+ data: convertDataContentToBase64String(aiV4Part.data)
2250
+ };
2251
+ if (aiV4Part.providerOptions) {
2252
+ part.providerMetadata = aiV4Part.providerOptions;
2253
+ }
2254
+ parts.push(part);
2030
2255
  } catch (error) {
2031
2256
  console.error(`Failed to convert binary data to base64 in CoreMessage file part: ${error}`, error);
2032
2257
  }
2033
2258
  }
2034
2259
  } else {
2035
2260
  try {
2036
- parts.push({
2261
+ const part = {
2037
2262
  type: "file",
2038
- mimeType: part.mimeType,
2039
- data: convertDataContentToBase64String(part.data)
2040
- });
2263
+ mimeType: aiV4Part.mimeType,
2264
+ data: convertDataContentToBase64String(aiV4Part.data)
2265
+ };
2266
+ if (aiV4Part.providerOptions) {
2267
+ part.providerMetadata = aiV4Part.providerOptions;
2268
+ }
2269
+ parts.push(part);
2041
2270
  } catch (error) {
2042
2271
  console.error(`Failed to convert binary data to base64 in CoreMessage file part: ${error}`, error);
2043
2272
  }
2044
2273
  }
2045
2274
  break;
2275
+ }
2046
2276
  }
2047
2277
  }
2048
2278
  }
@@ -2053,10 +2283,17 @@ var MessageList = class _MessageList {
2053
2283
  if (toolInvocations.length) content.toolInvocations = toolInvocations;
2054
2284
  if (typeof coreMessage.content === `string`) content.content = coreMessage.content;
2055
2285
  if (experimentalAttachments.length) content.experimental_attachments = experimentalAttachments;
2286
+ if (coreMessage.providerOptions) {
2287
+ content.providerMetadata = coreMessage.providerOptions;
2288
+ }
2289
+ if ("metadata" in coreMessage && coreMessage.metadata !== null && coreMessage.metadata !== void 0) {
2290
+ content.metadata = coreMessage.metadata;
2291
+ }
2292
+ const rawCreatedAt = "metadata" in coreMessage && coreMessage.metadata && typeof coreMessage.metadata === "object" && "createdAt" in coreMessage.metadata ? coreMessage.metadata.createdAt : void 0;
2056
2293
  return {
2057
2294
  id,
2058
2295
  role: _MessageList.getRole(coreMessage),
2059
- createdAt: this.generateCreatedAt(messageSource),
2296
+ createdAt: this.generateCreatedAt(messageSource, rawCreatedAt),
2060
2297
  threadId: this.memoryInfo?.threadId,
2061
2298
  resourceId: this.memoryInfo?.resourceId,
2062
2299
  content
@@ -2094,25 +2331,48 @@ var MessageList = class _MessageList {
2094
2331
  let key = ``;
2095
2332
  for (const part of parts) {
2096
2333
  key += part.type;
2097
- if (part.type === `text`) {
2098
- key += part.text;
2099
- }
2100
- if (part.type === `tool-invocation`) {
2101
- key += part.toolInvocation.toolCallId;
2102
- key += part.toolInvocation.state;
2103
- }
2104
- if (part.type === `reasoning`) {
2105
- key += part.reasoning;
2106
- key += part.details.reduce((prev, current) => {
2107
- if (current.type === `text`) {
2108
- return prev + current.text.length + (current.signature?.length || 0);
2109
- }
2110
- return prev;
2111
- }, 0);
2334
+ key += _MessageList.cacheKeyFromAIV4Part(part);
2335
+ }
2336
+ return key;
2337
+ }
2338
+ static cacheKeyFromAIV4Part(part) {
2339
+ let cacheKey = "";
2340
+ if (part.type === `text`) {
2341
+ cacheKey += part.text;
2342
+ }
2343
+ if (part.type === `tool-invocation`) {
2344
+ cacheKey += part.toolInvocation.toolCallId;
2345
+ cacheKey += part.toolInvocation.state;
2346
+ }
2347
+ if (part.type === `reasoning`) {
2348
+ cacheKey += part.reasoning;
2349
+ cacheKey += part.details.reduce((prev, current) => {
2350
+ if (current.type === `text`) {
2351
+ return prev + current.text.length + (current.signature?.length || 0);
2352
+ }
2353
+ return prev;
2354
+ }, 0);
2355
+ const partAny = part;
2356
+ if (partAny && Object.hasOwn(partAny, "providerMetadata") && partAny.providerMetadata && Object.hasOwn(partAny.providerMetadata, "openai") && partAny.providerMetadata.openai && Object.hasOwn(partAny.providerMetadata.openai, "itemId")) {
2357
+ const itemId = partAny.providerMetadata.openai.itemId;
2358
+ cacheKey += `|${itemId}`;
2112
2359
  }
2113
- if (part.type === `file`) {
2114
- key += part.data;
2115
- key += part.mimeType;
2360
+ }
2361
+ if (part.type === `file`) {
2362
+ cacheKey += part.data;
2363
+ cacheKey += part.mimeType;
2364
+ }
2365
+ return cacheKey;
2366
+ }
2367
+ static cacheKeyFromDBParts(parts) {
2368
+ let key = ``;
2369
+ for (const part of parts) {
2370
+ key += part.type;
2371
+ if (part.type.startsWith("data-")) {
2372
+ const data = part.data;
2373
+ key += JSON.stringify(data);
2374
+ } else {
2375
+ key += _MessageList.cacheKeyFromAIV4Part(part);
2116
2376
  }
2117
2377
  }
2118
2378
  return key;
@@ -2182,7 +2442,7 @@ var MessageList = class _MessageList {
2182
2442
  const twoMM2 = _MessageList.isMastraDBMessage(two) && two;
2183
2443
  if (oneMM2 && !twoMM2) return false;
2184
2444
  if (oneMM2 && twoMM2) {
2185
- return oneMM2.id === twoMM2.id && _MessageList.cacheKeyFromAIV4Parts(oneMM2.content.parts) === _MessageList.cacheKeyFromAIV4Parts(twoMM2.content.parts);
2445
+ return oneMM2.id === twoMM2.id && _MessageList.cacheKeyFromDBParts(oneMM2.content.parts) === _MessageList.cacheKeyFromDBParts(twoMM2.content.parts);
2186
2446
  }
2187
2447
  const oneUIV5 = _MessageList.isAIV5UIMessage(one) && one;
2188
2448
  const twoUIV5 = _MessageList.isAIV5UIMessage(two) && two;
@@ -2255,9 +2515,23 @@ var MessageList = class _MessageList {
2255
2515
  if (role === `tool` || role === `assistant`) {
2256
2516
  throw new Error(incompatibleMessage);
2257
2517
  }
2518
+ let processedImage;
2519
+ if (part.image instanceof URL || part.image instanceof Uint8Array) {
2520
+ processedImage = part.image;
2521
+ } else if (Buffer.isBuffer(part.image) || part.image instanceof ArrayBuffer) {
2522
+ processedImage = new Uint8Array(part.image);
2523
+ } else {
2524
+ const categorized = categorizeFileData(part.image, part.mimeType);
2525
+ if (categorized.type === "raw") {
2526
+ const dataUri = createDataUri(part.image, part.mimeType || "image/png");
2527
+ processedImage = new URL(dataUri);
2528
+ } else {
2529
+ processedImage = new URL(part.image);
2530
+ }
2531
+ }
2258
2532
  roleContent[role].push({
2259
2533
  ...part,
2260
- image: part.image instanceof URL || part.image instanceof Uint8Array ? part.image : Buffer.isBuffer(part.image) || part.image instanceof ArrayBuffer ? new Uint8Array(part.image) : new URL(part.image)
2534
+ image: processedImage
2261
2535
  });
2262
2536
  break;
2263
2537
  }
@@ -2403,6 +2677,9 @@ var MessageList = class _MessageList {
2403
2677
  if (dbMsg.createdAt) metadata.createdAt = dbMsg.createdAt;
2404
2678
  if (dbMsg.threadId) metadata.threadId = dbMsg.threadId;
2405
2679
  if (dbMsg.resourceId) metadata.resourceId = dbMsg.resourceId;
2680
+ if (dbMsg.content.providerMetadata) {
2681
+ metadata.providerMetadata = dbMsg.content.providerMetadata;
2682
+ }
2406
2683
  const hasToolInvocationParts = dbMsg.content.parts?.some((p) => p.type === "tool-invocation");
2407
2684
  if (dbMsg.content.toolInvocations && !hasToolInvocationParts) {
2408
2685
  for (const invocation of dbMsg.content.toolInvocations) {
@@ -2469,18 +2746,20 @@ var MessageList = class _MessageList {
2469
2746
  continue;
2470
2747
  }
2471
2748
  if (part.type === "reasoning") {
2472
- const reasoningPart = part;
2473
- const text = reasoningPart.text || reasoningPart.reasoning || (reasoningPart.details?.reduce((p, c) => {
2749
+ const text = part.reasoning || (part.details?.reduce((p, c) => {
2474
2750
  if (c.type === `text` && c.text) return p + c.text;
2475
2751
  return p;
2476
2752
  }, "") ?? "");
2477
- if (text || reasoningPart.details?.length) {
2478
- parts.push({
2753
+ if (text || part.details?.length) {
2754
+ const v5UIPart = {
2479
2755
  type: "reasoning",
2480
2756
  text: text || "",
2481
- state: "done",
2482
- ...part.providerMetadata && { providerMetadata: part.providerMetadata }
2483
- });
2757
+ state: "done"
2758
+ };
2759
+ if (part.providerMetadata) {
2760
+ v5UIPart.providerMetadata = part.providerMetadata;
2761
+ }
2762
+ parts.push(v5UIPart);
2484
2763
  }
2485
2764
  continue;
2486
2765
  }
@@ -2493,12 +2772,15 @@ var MessageList = class _MessageList {
2493
2772
  }
2494
2773
  const categorized = typeof part.data === "string" ? categorizeFileData(part.data, part.mimeType) : { type: "raw", mimeType: part.mimeType};
2495
2774
  if (categorized.type === "url" && typeof part.data === "string") {
2496
- parts.push({
2775
+ const v5UIPart = {
2497
2776
  type: "file",
2498
2777
  url: part.data,
2499
- mediaType: categorized.mimeType || "image/png",
2500
- providerMetadata: part.providerMetadata
2501
- });
2778
+ mediaType: categorized.mimeType || "image/png"
2779
+ };
2780
+ if (part.providerMetadata) {
2781
+ v5UIPart.providerMetadata = part.providerMetadata;
2782
+ }
2783
+ parts.push(v5UIPart);
2502
2784
  } else {
2503
2785
  let filePartData;
2504
2786
  let extractedMimeType = part.mimeType;
@@ -2522,27 +2804,37 @@ var MessageList = class _MessageList {
2522
2804
  } else {
2523
2805
  dataUri = createDataUri(filePartData, finalMimeType);
2524
2806
  }
2525
- parts.push({
2807
+ const v5UIPart = {
2526
2808
  type: "file",
2527
2809
  url: dataUri,
2528
2810
  // Use url field with data URI
2529
- mediaType: finalMimeType,
2530
- providerMetadata: part.providerMetadata
2531
- });
2811
+ mediaType: finalMimeType
2812
+ };
2813
+ if (part.providerMetadata) {
2814
+ v5UIPart.providerMetadata = part.providerMetadata;
2815
+ }
2816
+ parts.push(v5UIPart);
2532
2817
  }
2533
2818
  } else if (part.type === "source") {
2534
- const sourcePart = part;
2535
- parts.push({
2819
+ const v5UIPart = {
2536
2820
  type: "source-url",
2537
- url: sourcePart.source.url,
2538
- ...part.providerMetadata && { providerMetadata: part.providerMetadata }
2539
- });
2821
+ url: part.source.url,
2822
+ sourceId: part.source.id,
2823
+ title: part.source.title
2824
+ };
2825
+ if (part.providerMetadata) {
2826
+ v5UIPart.providerMetadata = part.providerMetadata;
2827
+ }
2828
+ parts.push(v5UIPart);
2540
2829
  } else if (part.type === "text") {
2541
- parts.push({
2830
+ const v5UIPart = {
2542
2831
  type: "text",
2543
- text: part.text,
2544
- ...part.providerMetadata && { providerMetadata: part.providerMetadata }
2545
- });
2832
+ text: part.text
2833
+ };
2834
+ if (part.providerMetadata) {
2835
+ v5UIPart.providerMetadata = part.providerMetadata;
2836
+ }
2837
+ parts.push(v5UIPart);
2546
2838
  hasNonToolReasoningParts = true;
2547
2839
  } else {
2548
2840
  parts.push(part);
@@ -2706,32 +2998,69 @@ var MessageList = class _MessageList {
2706
2998
  }
2707
2999
  };
2708
3000
  }
3001
+ /**
3002
+ * Convert image or file to data URI or URL for V2 file part
3003
+ */
3004
+ static getDataStringFromAIV5DataPart = (part) => {
3005
+ let mimeType;
3006
+ let data;
3007
+ if ("data" in part) {
3008
+ mimeType = part.mediaType || "application/octet-stream";
3009
+ data = part.data;
3010
+ } else if ("image" in part) {
3011
+ mimeType = part.mediaType || "image/jpeg";
3012
+ data = part.image;
3013
+ } else {
3014
+ throw new chunkTWH4PTDG_cjs.MastraError({
3015
+ id: "MASTRA_AIV5_DATA_PART_INVALID",
3016
+ domain: "AGENT" /* AGENT */,
3017
+ category: "USER" /* USER */,
3018
+ text: "Invalid AIV5 data part in getDataStringFromAIV5DataPart",
3019
+ details: {
3020
+ part
3021
+ }
3022
+ });
3023
+ }
3024
+ if (data instanceof URL) {
3025
+ return data.toString();
3026
+ } else {
3027
+ if (data instanceof Buffer) {
3028
+ const base64 = data.toString("base64");
3029
+ return `data:${mimeType};base64,${base64}`;
3030
+ } else if (typeof data === "string") {
3031
+ return data.startsWith("data:") || data.startsWith("http") ? data : `data:${mimeType};base64,${data}`;
3032
+ } else if (data instanceof Uint8Array) {
3033
+ const base64 = Buffer.from(data).toString("base64");
3034
+ return `data:${mimeType};base64,${base64}`;
3035
+ } else if (data instanceof ArrayBuffer) {
3036
+ const base64 = Buffer.from(data).toString("base64");
3037
+ return `data:${mimeType};base64,${base64}`;
3038
+ } else {
3039
+ return "";
3040
+ }
3041
+ }
3042
+ };
2709
3043
  /**
2710
3044
  * Direct conversion from AIV5 ModelMessage to MastraDBMessage
2711
3045
  * Combines logic from aiV5ModelMessageToMastraMessageV3 + mastraMessageV3ToV2
2712
3046
  */
2713
3047
  static aiV5ModelMessageToMastraDBMessage(modelMsg, _messageSource) {
2714
3048
  const content = Array.isArray(modelMsg.content) ? modelMsg.content : [{ type: "text", text: modelMsg.content }];
2715
- const v2Parts = [];
3049
+ const mastraDBParts = [];
2716
3050
  const toolInvocations = [];
2717
3051
  const reasoningParts = [];
2718
3052
  const experimental_attachments = [];
2719
- const textParts = [];
2720
3053
  let lastPartWasToolResult = false;
2721
3054
  for (const part of content) {
2722
- const providerMetadata = {
2723
- ...modelMsg.providerMetadata || {},
2724
- ...part.providerMetadata || {}
2725
- };
2726
- const hasProviderMetadata = Object.keys(providerMetadata).length > 0;
2727
3055
  if (part.type === "text") {
2728
3056
  const textPart = {
2729
3057
  type: "text",
2730
- text: part.text,
2731
- ...hasProviderMetadata && { experimental_providerMetadata: providerMetadata }
3058
+ text: part.text
2732
3059
  };
2733
- v2Parts.push(textPart);
2734
- textParts.push({ text: part.text, providerMetadata: hasProviderMetadata ? providerMetadata : void 0 });
3060
+ if (part.providerOptions) {
3061
+ textPart.providerMetadata = part.providerOptions;
3062
+ }
3063
+ mastraDBParts.push(textPart);
2735
3064
  lastPartWasToolResult = false;
2736
3065
  } else if (part.type === "tool-call") {
2737
3066
  const toolCallPart = part;
@@ -2742,10 +3071,12 @@ var MessageList = class _MessageList {
2742
3071
  toolName: toolCallPart.toolName,
2743
3072
  args: toolCallPart.input,
2744
3073
  state: "call"
2745
- },
2746
- ...hasProviderMetadata && { providerMetadata }
3074
+ }
2747
3075
  };
2748
- v2Parts.push(toolInvocationPart);
3076
+ if (part.providerOptions) {
3077
+ toolInvocationPart.providerMetadata = part.providerOptions;
3078
+ }
3079
+ mastraDBParts.push(toolInvocationPart);
2749
3080
  toolInvocations.push({
2750
3081
  toolCallId: toolCallPart.toolCallId,
2751
3082
  toolName: toolCallPart.toolName,
@@ -2756,78 +3087,67 @@ var MessageList = class _MessageList {
2756
3087
  } else if (part.type === "tool-result") {
2757
3088
  const toolResultPart = part;
2758
3089
  const matchingCall = toolInvocations.find((inv) => inv.toolCallId === toolResultPart.toolCallId);
2759
- const matchingV2Part = v2Parts.find(
3090
+ const matchingV2Part = mastraDBParts.find(
2760
3091
  (p) => p.type === "tool-invocation" && "toolInvocation" in p && p.toolInvocation.toolCallId === toolResultPart.toolCallId
2761
3092
  );
3093
+ const updateMatchingCallInvocationResult = (toolResultPart2, matchingCall2) => {
3094
+ matchingCall2.state = "result";
3095
+ matchingCall2.result = typeof toolResultPart2.output === "object" && toolResultPart2.output && "value" in toolResultPart2.output ? toolResultPart2.output.value : toolResultPart2.output;
3096
+ };
2762
3097
  if (matchingCall) {
2763
- matchingCall.state = "result";
2764
- matchingCall.result = typeof toolResultPart.output === "object" && toolResultPart.output && "value" in toolResultPart.output ? toolResultPart.output.value : toolResultPart.output;
3098
+ updateMatchingCallInvocationResult(toolResultPart, matchingCall);
2765
3099
  } else {
2766
- const resultPartWithName = toolResultPart;
2767
- toolInvocations.push({
3100
+ const call = {
3101
+ state: "call",
2768
3102
  toolCallId: toolResultPart.toolCallId,
2769
- toolName: resultPartWithName.toolName || "unknown",
2770
- args: {},
2771
- result: typeof toolResultPart.output === "object" && toolResultPart.output && "value" in toolResultPart.output ? toolResultPart.output.value : toolResultPart.output,
2772
- state: "result"
2773
- });
3103
+ toolName: toolResultPart.toolName || "unknown",
3104
+ args: {}
3105
+ };
3106
+ updateMatchingCallInvocationResult(toolResultPart, call);
3107
+ toolInvocations.push(call);
2774
3108
  }
2775
3109
  if (matchingV2Part && matchingV2Part.type === "tool-invocation") {
2776
- matchingV2Part.toolInvocation.state = "result";
2777
- matchingV2Part.toolInvocation.result = typeof toolResultPart.output === "object" && toolResultPart.output && "value" in toolResultPart.output ? toolResultPart.output.value : toolResultPart.output;
2778
- if (hasProviderMetadata) {
2779
- matchingV2Part.providerMetadata = providerMetadata;
2780
- }
3110
+ updateMatchingCallInvocationResult(toolResultPart, matchingV2Part.toolInvocation);
2781
3111
  } else {
2782
- const resultPartWithName = toolResultPart;
2783
3112
  const toolInvocationPart = {
2784
3113
  type: "tool-invocation",
2785
3114
  toolInvocation: {
2786
3115
  toolCallId: toolResultPart.toolCallId,
2787
- toolName: resultPartWithName.toolName || "unknown",
3116
+ toolName: toolResultPart.toolName || "unknown",
2788
3117
  args: {},
2789
- result: typeof toolResultPart.output === "object" && toolResultPart.output && "value" in toolResultPart.output ? toolResultPart.output.value : toolResultPart.output,
2790
- state: "result"
2791
- },
2792
- ...hasProviderMetadata && { providerMetadata }
3118
+ state: "call"
3119
+ }
2793
3120
  };
2794
- v2Parts.push(toolInvocationPart);
3121
+ updateMatchingCallInvocationResult(toolResultPart, toolInvocationPart.toolInvocation);
3122
+ mastraDBParts.push(toolInvocationPart);
2795
3123
  }
2796
3124
  lastPartWasToolResult = true;
2797
3125
  } else if (part.type === "reasoning") {
2798
- const reasoningPart = part;
2799
3126
  const v2ReasoningPart = {
2800
3127
  type: "reasoning",
2801
- reasoning: reasoningPart.text,
2802
- details: [{ type: "text", text: reasoningPart.text }],
2803
- ...hasProviderMetadata && { providerMetadata }
3128
+ reasoning: "",
3129
+ // leave this blank so we aren't double storing it in the db along with details
3130
+ details: [{ type: "text", text: part.text }]
2804
3131
  };
2805
- v2Parts.push(v2ReasoningPart);
2806
- reasoningParts.push(reasoningPart.text);
3132
+ if (part.providerOptions) {
3133
+ v2ReasoningPart.providerMetadata = part.providerOptions;
3134
+ }
3135
+ mastraDBParts.push(v2ReasoningPart);
3136
+ reasoningParts.push(part.text);
2807
3137
  lastPartWasToolResult = false;
2808
3138
  } else if (part.type === "image") {
2809
3139
  const imagePart = part;
2810
- let imageData;
2811
- const mimeType = imagePart.mimeType || "image/jpeg";
2812
- if ("url" in imagePart && typeof imagePart.url === "string") {
2813
- imageData = imagePart.url;
2814
- } else if ("data" in imagePart) {
2815
- if (typeof imagePart.data === "string") {
2816
- imageData = imagePart.data.startsWith("data:") || imagePart.data.startsWith("http") ? imagePart.data : `data:${mimeType};base64,${imagePart.data}`;
2817
- } else {
2818
- const base64 = Buffer.from(imagePart.data).toString("base64");
2819
- imageData = `data:${mimeType};base64,${base64}`;
2820
- }
2821
- } else {
2822
- imageData = "";
2823
- }
3140
+ const mimeType = imagePart.mediaType || "image/jpeg";
3141
+ const imageData = this.getDataStringFromAIV5DataPart(imagePart);
2824
3142
  const imageFilePart = {
2825
3143
  type: "file",
2826
3144
  data: imageData,
2827
- mimeType,
2828
- ...hasProviderMetadata && { providerMetadata }
3145
+ mimeType
2829
3146
  };
2830
- v2Parts.push(imageFilePart);
3147
+ if (part.providerOptions) {
3148
+ imageFilePart.providerMetadata = part.providerOptions;
3149
+ }
3150
+ mastraDBParts.push(imageFilePart);
2831
3151
  experimental_attachments.push({
2832
3152
  url: imageData,
2833
3153
  contentType: mimeType
@@ -2836,26 +3156,16 @@ var MessageList = class _MessageList {
2836
3156
  } else if (part.type === "file") {
2837
3157
  const filePart = part;
2838
3158
  const mimeType = filePart.mediaType || "application/octet-stream";
2839
- let fileData;
2840
- if ("url" in filePart && typeof filePart.url === "string") {
2841
- fileData = filePart.url;
2842
- } else if ("data" in filePart) {
2843
- if (typeof filePart.data === "string") {
2844
- fileData = filePart.data.startsWith("data:") || filePart.data.startsWith("http") ? filePart.data : `data:${mimeType};base64,${filePart.data}`;
2845
- } else {
2846
- const base64 = Buffer.from(filePart.data).toString("base64");
2847
- fileData = `data:${mimeType};base64,${base64}`;
2848
- }
2849
- } else {
2850
- fileData = "";
2851
- }
3159
+ const fileData = this.getDataStringFromAIV5DataPart(filePart);
2852
3160
  const v2FilePart = {
2853
3161
  type: "file",
2854
3162
  data: fileData,
2855
- mimeType,
2856
- ...hasProviderMetadata && { providerMetadata }
3163
+ mimeType
2857
3164
  };
2858
- v2Parts.push(v2FilePart);
3165
+ if (part.providerOptions) {
3166
+ v2FilePart.providerMetadata = part.providerOptions;
3167
+ }
3168
+ mastraDBParts.push(v2FilePart);
2859
3169
  experimental_attachments.push({
2860
3170
  url: fileData,
2861
3171
  contentType: mimeType
@@ -2863,34 +3173,34 @@ var MessageList = class _MessageList {
2863
3173
  lastPartWasToolResult = false;
2864
3174
  }
2865
3175
  }
2866
- if (modelMsg.role === "assistant" && lastPartWasToolResult && v2Parts.length > 0) {
2867
- const lastPart = v2Parts[v2Parts.length - 1];
3176
+ if (modelMsg.role === "assistant" && lastPartWasToolResult && mastraDBParts.length > 0) {
3177
+ const lastPart = mastraDBParts[mastraDBParts.length - 1];
2868
3178
  if (lastPart && lastPart.type !== "text") {
2869
3179
  const emptyTextPart = { type: "text", text: "" };
2870
- v2Parts.push(emptyTextPart);
2871
- textParts.push({ text: "" });
3180
+ mastraDBParts.push(emptyTextPart);
2872
3181
  }
2873
3182
  }
2874
- let contentString = void 0;
2875
- if (textParts.length > 0) {
2876
- contentString = textParts.map((p) => p.text).join("\n");
2877
- }
2878
- const metadata = {};
3183
+ const contentString = mastraDBParts.filter((p) => p.type === "text").map((p) => p.text).join("\n");
3184
+ const metadata = "metadata" in modelMsg && modelMsg.metadata !== null && modelMsg.metadata !== void 0 ? modelMsg.metadata : {};
2879
3185
  const id = `id` in modelMsg && typeof modelMsg.id === `string` ? modelMsg.id : `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
2880
- return {
3186
+ const message = {
2881
3187
  id,
2882
3188
  role: _MessageList.getRole(modelMsg),
2883
3189
  createdAt: /* @__PURE__ */ new Date(),
2884
3190
  content: {
2885
3191
  format: 2,
2886
- parts: v2Parts,
3192
+ parts: mastraDBParts,
2887
3193
  toolInvocations: toolInvocations.length > 0 ? toolInvocations : void 0,
2888
3194
  reasoning: reasoningParts.length > 0 ? reasoningParts.join("\n") : void 0,
2889
3195
  experimental_attachments: experimental_attachments.length > 0 ? experimental_attachments : void 0,
2890
- content: contentString,
2891
- metadata
3196
+ content: contentString || void 0,
3197
+ metadata: Object.keys(metadata).length > 0 ? metadata : void 0
2892
3198
  }
2893
3199
  };
3200
+ if (modelMsg.providerOptions) {
3201
+ message.content.providerMetadata = modelMsg.providerOptions;
3202
+ }
3203
+ return message;
2894
3204
  }
2895
3205
  aiV4CoreMessagesToAIV5ModelMessages(messages, source) {
2896
3206
  return this.aiV5UIMessagesToAIV5ModelMessages(
@@ -2901,14 +3211,24 @@ var MessageList = class _MessageList {
2901
3211
  const sanitized = this.sanitizeV5UIMessages(messages, filterIncompleteToolCalls);
2902
3212
  const preprocessed = this.addStartStepPartsForAIV5(sanitized);
2903
3213
  const result = AIV5__namespace.convertToModelMessages(preprocessed);
2904
- return result;
3214
+ return result.map((modelMsg, index) => {
3215
+ const uiMsg = preprocessed[index];
3216
+ if (uiMsg?.metadata && typeof uiMsg.metadata === "object" && "providerMetadata" in uiMsg.metadata && uiMsg.metadata.providerMetadata) {
3217
+ return {
3218
+ ...modelMsg,
3219
+ providerOptions: uiMsg.metadata.providerMetadata
3220
+ };
3221
+ }
3222
+ return modelMsg;
3223
+ });
2905
3224
  }
2906
3225
  addStartStepPartsForAIV5(messages) {
2907
3226
  for (const message of messages) {
2908
3227
  if (message.role !== `assistant`) continue;
2909
3228
  for (const [index, part] of message.parts.entries()) {
2910
3229
  if (!AIV5__namespace.isToolUIPart(part)) continue;
2911
- if (message.parts.at(index + 1)?.type !== `step-start`) {
3230
+ const nextPart = message.parts.at(index + 1);
3231
+ if (nextPart && nextPart.type !== `step-start` && !AIV5__namespace.isToolUIPart(nextPart)) {
2912
3232
  message.parts.splice(index + 1, 0, { type: "step-start" });
2913
3233
  }
2914
3234
  }
@@ -3037,5 +3357,5 @@ exports.DefaultGeneratedFile = DefaultGeneratedFile;
3037
3357
  exports.DefaultGeneratedFileWithType = DefaultGeneratedFileWithType;
3038
3358
  exports.MessageList = MessageList;
3039
3359
  exports.convertMessages = convertMessages;
3040
- //# sourceMappingURL=chunk-ECFXGXWO.cjs.map
3041
- //# sourceMappingURL=chunk-ECFXGXWO.cjs.map
3360
+ //# sourceMappingURL=chunk-5Q6WAYEY.cjs.map
3361
+ //# sourceMappingURL=chunk-5Q6WAYEY.cjs.map