@scoutqa/mastra-core 0.24.6-fork.1

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 (1064) hide show
  1. package/CHANGELOG.md +5844 -0
  2. package/LICENSE.md +15 -0
  3. package/README.md +59 -0
  4. package/a2a.d.ts +1 -0
  5. package/action.d.ts +1 -0
  6. package/agent/input-processor/processors.d.ts +1 -0
  7. package/agent.d.ts +1 -0
  8. package/ai-tracing.d.ts +1 -0
  9. package/base.d.ts +1 -0
  10. package/bundler.d.ts +1 -0
  11. package/cache.d.ts +1 -0
  12. package/deployer.d.ts +1 -0
  13. package/di.d.ts +1 -0
  14. package/dist/a2a/error.d.ts +24 -0
  15. package/dist/a2a/error.d.ts.map +1 -0
  16. package/dist/a2a/index.cjs +80 -0
  17. package/dist/a2a/index.cjs.map +1 -0
  18. package/dist/a2a/index.d.ts +4 -0
  19. package/dist/a2a/index.d.ts.map +1 -0
  20. package/dist/a2a/index.js +72 -0
  21. package/dist/a2a/index.js.map +1 -0
  22. package/dist/a2a/types.d.ts +93 -0
  23. package/dist/a2a/types.d.ts.map +1 -0
  24. package/dist/action/index.d.ts +36 -0
  25. package/dist/action/index.d.ts.map +1 -0
  26. package/dist/agent/__tests__/mock-model.d.ts +6 -0
  27. package/dist/agent/__tests__/mock-model.d.ts.map +1 -0
  28. package/dist/agent/agent.d.ts +728 -0
  29. package/dist/agent/agent.d.ts.map +1 -0
  30. package/dist/agent/agent.types.d.ts +130 -0
  31. package/dist/agent/agent.types.d.ts.map +1 -0
  32. package/dist/agent/index.cjs +53 -0
  33. package/dist/agent/index.cjs.map +1 -0
  34. package/dist/agent/index.d.ts +10 -0
  35. package/dist/agent/index.d.ts.map +1 -0
  36. package/dist/agent/index.js +4 -0
  37. package/dist/agent/index.js.map +1 -0
  38. package/dist/agent/index.warning.d.ts +13 -0
  39. package/dist/agent/index.warning.d.ts.map +1 -0
  40. package/dist/agent/input-processor/index.cjs +28 -0
  41. package/dist/agent/input-processor/index.cjs.map +1 -0
  42. package/dist/agent/input-processor/index.d.ts +10 -0
  43. package/dist/agent/input-processor/index.d.ts.map +1 -0
  44. package/dist/agent/input-processor/index.js +3 -0
  45. package/dist/agent/input-processor/index.js.map +1 -0
  46. package/dist/agent/input-processor/processors/index.d.ts +6 -0
  47. package/dist/agent/input-processor/processors/index.d.ts.map +1 -0
  48. package/dist/agent/input-processor/processors/language-detector.d.ts +18 -0
  49. package/dist/agent/input-processor/processors/language-detector.d.ts.map +1 -0
  50. package/dist/agent/input-processor/processors/moderation.d.ts +18 -0
  51. package/dist/agent/input-processor/processors/moderation.d.ts.map +1 -0
  52. package/dist/agent/input-processor/processors/pii-detector.d.ts +18 -0
  53. package/dist/agent/input-processor/processors/pii-detector.d.ts.map +1 -0
  54. package/dist/agent/input-processor/processors/prompt-injection-detector.d.ts +18 -0
  55. package/dist/agent/input-processor/processors/prompt-injection-detector.d.ts.map +1 -0
  56. package/dist/agent/input-processor/processors/unicode-normalizer.d.ts +18 -0
  57. package/dist/agent/input-processor/processors/unicode-normalizer.d.ts.map +1 -0
  58. package/dist/agent/message-list/index.d.ts +305 -0
  59. package/dist/agent/message-list/index.d.ts.map +1 -0
  60. package/dist/agent/message-list/prompt/attachments-to-parts.d.ts +11 -0
  61. package/dist/agent/message-list/prompt/attachments-to-parts.d.ts.map +1 -0
  62. package/dist/agent/message-list/prompt/convert-file.d.ts +7 -0
  63. package/dist/agent/message-list/prompt/convert-file.d.ts.map +1 -0
  64. package/dist/agent/message-list/prompt/convert-to-mastra-v1.d.ts +4 -0
  65. package/dist/agent/message-list/prompt/convert-to-mastra-v1.d.ts.map +1 -0
  66. package/dist/agent/message-list/prompt/data-content.d.ts +17 -0
  67. package/dist/agent/message-list/prompt/data-content.d.ts.map +1 -0
  68. package/dist/agent/message-list/prompt/download-assets.d.ts +15 -0
  69. package/dist/agent/message-list/prompt/download-assets.d.ts.map +1 -0
  70. package/dist/agent/message-list/prompt/image-utils.d.ts +86 -0
  71. package/dist/agent/message-list/prompt/image-utils.d.ts.map +1 -0
  72. package/dist/agent/message-list/prompt/invalid-content-error.d.ts +14 -0
  73. package/dist/agent/message-list/prompt/invalid-content-error.d.ts.map +1 -0
  74. package/dist/agent/message-list/types.d.ts +3 -0
  75. package/dist/agent/message-list/types.d.ts.map +1 -0
  76. package/dist/agent/message-list/utils/ai-v4-v5/core-model-message.d.ts +3 -0
  77. package/dist/agent/message-list/utils/ai-v4-v5/core-model-message.d.ts.map +1 -0
  78. package/dist/agent/message-list/utils/ai-v4-v5/ui-message.d.ts +3 -0
  79. package/dist/agent/message-list/utils/ai-v4-v5/ui-message.d.ts.map +1 -0
  80. package/dist/agent/message-list/utils/ai-v5/gemini-compatibility.d.ts +22 -0
  81. package/dist/agent/message-list/utils/ai-v5/gemini-compatibility.d.ts.map +1 -0
  82. package/dist/agent/message-list/utils/ai-v5/tool.d.ts +16 -0
  83. package/dist/agent/message-list/utils/ai-v5/tool.d.ts.map +1 -0
  84. package/dist/agent/message-list/utils/convert-messages.d.ts +91 -0
  85. package/dist/agent/message-list/utils/convert-messages.d.ts.map +1 -0
  86. package/dist/agent/save-queue/index.d.ts +68 -0
  87. package/dist/agent/save-queue/index.d.ts.map +1 -0
  88. package/dist/agent/test-utils.d.ts +82 -0
  89. package/dist/agent/test-utils.d.ts.map +1 -0
  90. package/dist/agent/trip-wire.d.ts +18 -0
  91. package/dist/agent/trip-wire.d.ts.map +1 -0
  92. package/dist/agent/types.d.ts +358 -0
  93. package/dist/agent/types.d.ts.map +1 -0
  94. package/dist/agent/utils.d.ts +104 -0
  95. package/dist/agent/utils.d.ts.map +1 -0
  96. package/dist/agent/workflows/prepare-stream/index.d.ts +158 -0
  97. package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -0
  98. package/dist/agent/workflows/prepare-stream/map-results-step.d.ts +35 -0
  99. package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -0
  100. package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +90 -0
  101. package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts.map +1 -0
  102. package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts +75 -0
  103. package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts.map +1 -0
  104. package/dist/agent/workflows/prepare-stream/schema.d.ts +179 -0
  105. package/dist/agent/workflows/prepare-stream/schema.d.ts.map +1 -0
  106. package/dist/agent/workflows/prepare-stream/stream-step.d.ts +36 -0
  107. package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -0
  108. package/dist/ai-tracing/context.d.ts +21 -0
  109. package/dist/ai-tracing/context.d.ts.map +1 -0
  110. package/dist/ai-tracing/exporters/base.d.ts +111 -0
  111. package/dist/ai-tracing/exporters/base.d.ts.map +1 -0
  112. package/dist/ai-tracing/exporters/cloud.d.ts +30 -0
  113. package/dist/ai-tracing/exporters/cloud.d.ts.map +1 -0
  114. package/dist/ai-tracing/exporters/console.d.ts +10 -0
  115. package/dist/ai-tracing/exporters/console.d.ts.map +1 -0
  116. package/dist/ai-tracing/exporters/default.d.ts +98 -0
  117. package/dist/ai-tracing/exporters/default.d.ts.map +1 -0
  118. package/dist/ai-tracing/exporters/index.d.ts +9 -0
  119. package/dist/ai-tracing/exporters/index.d.ts.map +1 -0
  120. package/dist/ai-tracing/index.cjs +148 -0
  121. package/dist/ai-tracing/index.cjs.map +1 -0
  122. package/dist/ai-tracing/index.d.ts +13 -0
  123. package/dist/ai-tracing/index.d.ts.map +1 -0
  124. package/dist/ai-tracing/index.js +3 -0
  125. package/dist/ai-tracing/index.js.map +1 -0
  126. package/dist/ai-tracing/model-tracing.d.ts +63 -0
  127. package/dist/ai-tracing/model-tracing.d.ts.map +1 -0
  128. package/dist/ai-tracing/registry.d.ts +51 -0
  129. package/dist/ai-tracing/registry.d.ts.map +1 -0
  130. package/dist/ai-tracing/span_processors/index.d.ts +5 -0
  131. package/dist/ai-tracing/span_processors/index.d.ts.map +1 -0
  132. package/dist/ai-tracing/span_processors/sensitive-data-filter.d.ts +85 -0
  133. package/dist/ai-tracing/span_processors/sensitive-data-filter.d.ts.map +1 -0
  134. package/dist/ai-tracing/spans/base.d.ts +65 -0
  135. package/dist/ai-tracing/spans/base.d.ts.map +1 -0
  136. package/dist/ai-tracing/spans/default.d.ts +13 -0
  137. package/dist/ai-tracing/spans/default.d.ts.map +1 -0
  138. package/dist/ai-tracing/spans/index.d.ts +7 -0
  139. package/dist/ai-tracing/spans/index.d.ts.map +1 -0
  140. package/dist/ai-tracing/spans/no-op.d.ts +15 -0
  141. package/dist/ai-tracing/spans/no-op.d.ts.map +1 -0
  142. package/dist/ai-tracing/tracers/base.d.ts +105 -0
  143. package/dist/ai-tracing/tracers/base.d.ts.map +1 -0
  144. package/dist/ai-tracing/tracers/default.d.ts +7 -0
  145. package/dist/ai-tracing/tracers/default.d.ts.map +1 -0
  146. package/dist/ai-tracing/tracers/index.d.ts +6 -0
  147. package/dist/ai-tracing/tracers/index.d.ts.map +1 -0
  148. package/dist/ai-tracing/types.d.ts +696 -0
  149. package/dist/ai-tracing/types.d.ts.map +1 -0
  150. package/dist/ai-tracing/utils.d.ts +68 -0
  151. package/dist/ai-tracing/utils.d.ts.map +1 -0
  152. package/dist/base.cjs +12 -0
  153. package/dist/base.cjs.map +1 -0
  154. package/dist/base.d.ts +34 -0
  155. package/dist/base.d.ts.map +1 -0
  156. package/dist/base.js +3 -0
  157. package/dist/base.js.map +1 -0
  158. package/dist/base.warning.d.ts +9 -0
  159. package/dist/base.warning.d.ts.map +1 -0
  160. package/dist/bundler/index.cjs +12 -0
  161. package/dist/bundler/index.cjs.map +1 -0
  162. package/dist/bundler/index.d.ts +31 -0
  163. package/dist/bundler/index.d.ts.map +1 -0
  164. package/dist/bundler/index.js +3 -0
  165. package/dist/bundler/index.js.map +1 -0
  166. package/dist/bundler/index.warning.d.ts +9 -0
  167. package/dist/bundler/index.warning.d.ts.map +1 -0
  168. package/dist/bundler/types.d.ts +6 -0
  169. package/dist/bundler/types.d.ts.map +1 -0
  170. package/dist/cache/base.d.ts +14 -0
  171. package/dist/cache/base.d.ts.map +1 -0
  172. package/dist/cache/index.cjs +16 -0
  173. package/dist/cache/index.cjs.map +1 -0
  174. package/dist/cache/index.d.ts +3 -0
  175. package/dist/cache/index.d.ts.map +1 -0
  176. package/dist/cache/index.js +3 -0
  177. package/dist/cache/index.js.map +1 -0
  178. package/dist/cache/inmemory.d.ts +13 -0
  179. package/dist/cache/inmemory.d.ts.map +1 -0
  180. package/dist/chunk-3HXBPDKN.js +105 -0
  181. package/dist/chunk-3HXBPDKN.js.map +1 -0
  182. package/dist/chunk-3NTOFNIU.js +60 -0
  183. package/dist/chunk-3NTOFNIU.js.map +1 -0
  184. package/dist/chunk-3PSWNGBF.js +3 -0
  185. package/dist/chunk-3PSWNGBF.js.map +1 -0
  186. package/dist/chunk-42RUESSD.cjs +3203 -0
  187. package/dist/chunk-42RUESSD.cjs.map +1 -0
  188. package/dist/chunk-436FFEF6.js +34 -0
  189. package/dist/chunk-436FFEF6.js.map +1 -0
  190. package/dist/chunk-46XGIEXM.cjs +47 -0
  191. package/dist/chunk-46XGIEXM.cjs.map +1 -0
  192. package/dist/chunk-4D4KB75Y.cjs +9 -0
  193. package/dist/chunk-4D4KB75Y.cjs.map +1 -0
  194. package/dist/chunk-4L63C6E5.cjs +2554 -0
  195. package/dist/chunk-4L63C6E5.cjs.map +1 -0
  196. package/dist/chunk-4LSFAAZW.js +3 -0
  197. package/dist/chunk-4LSFAAZW.js.map +1 -0
  198. package/dist/chunk-4R2TBRS7.cjs +191 -0
  199. package/dist/chunk-4R2TBRS7.cjs.map +1 -0
  200. package/dist/chunk-4WQYXT2I.cjs +12 -0
  201. package/dist/chunk-4WQYXT2I.cjs.map +1 -0
  202. package/dist/chunk-5NTO7S5I.cjs +173 -0
  203. package/dist/chunk-5NTO7S5I.cjs.map +1 -0
  204. package/dist/chunk-5O52O25J.js +65 -0
  205. package/dist/chunk-5O52O25J.js.map +1 -0
  206. package/dist/chunk-5X4TQR6K.js +12 -0
  207. package/dist/chunk-5X4TQR6K.js.map +1 -0
  208. package/dist/chunk-6D2K2CAA.js +776 -0
  209. package/dist/chunk-6D2K2CAA.js.map +1 -0
  210. package/dist/chunk-6KOL2B3A.cjs +75 -0
  211. package/dist/chunk-6KOL2B3A.cjs.map +1 -0
  212. package/dist/chunk-6TEQIYXV.cjs +96 -0
  213. package/dist/chunk-6TEQIYXV.cjs.map +1 -0
  214. package/dist/chunk-6VOPKVYH.cjs +57 -0
  215. package/dist/chunk-6VOPKVYH.cjs.map +1 -0
  216. package/dist/chunk-6XCINXZ7.cjs +194 -0
  217. package/dist/chunk-6XCINXZ7.cjs.map +1 -0
  218. package/dist/chunk-7J5DS33F.js +3 -0
  219. package/dist/chunk-7J5DS33F.js.map +1 -0
  220. package/dist/chunk-A5KDVZDL.cjs +124 -0
  221. package/dist/chunk-A5KDVZDL.cjs.map +1 -0
  222. package/dist/chunk-AAYCOJUL.cjs +14 -0
  223. package/dist/chunk-AAYCOJUL.cjs.map +1 -0
  224. package/dist/chunk-ABJOUEVA.cjs +10 -0
  225. package/dist/chunk-ABJOUEVA.cjs.map +1 -0
  226. package/dist/chunk-AQGLVU53.cjs +603 -0
  227. package/dist/chunk-AQGLVU53.cjs.map +1 -0
  228. package/dist/chunk-B7V6NYWH.cjs +67 -0
  229. package/dist/chunk-B7V6NYWH.cjs.map +1 -0
  230. package/dist/chunk-BJ6XIEC6.js +13 -0
  231. package/dist/chunk-BJ6XIEC6.js.map +1 -0
  232. package/dist/chunk-BLUDYAPI.js +596 -0
  233. package/dist/chunk-BLUDYAPI.js.map +1 -0
  234. package/dist/chunk-BVUMKER5.js +7 -0
  235. package/dist/chunk-BVUMKER5.js.map +1 -0
  236. package/dist/chunk-BWYU7D33.js +192 -0
  237. package/dist/chunk-BWYU7D33.js.map +1 -0
  238. package/dist/chunk-CNMPROPI.js +24 -0
  239. package/dist/chunk-CNMPROPI.js.map +1 -0
  240. package/dist/chunk-CT2DMHGC.cjs +271 -0
  241. package/dist/chunk-CT2DMHGC.cjs.map +1 -0
  242. package/dist/chunk-CYEQK4PM.cjs +778 -0
  243. package/dist/chunk-CYEQK4PM.cjs.map +1 -0
  244. package/dist/chunk-DMBN72QF.cjs +39 -0
  245. package/dist/chunk-DMBN72QF.cjs.map +1 -0
  246. package/dist/chunk-EBVYYC2Q.cjs +111 -0
  247. package/dist/chunk-EBVYYC2Q.cjs.map +1 -0
  248. package/dist/chunk-F7GI2OYP.js +3 -0
  249. package/dist/chunk-F7GI2OYP.js.map +1 -0
  250. package/dist/chunk-FUVNHPNL.cjs +4 -0
  251. package/dist/chunk-FUVNHPNL.cjs.map +1 -0
  252. package/dist/chunk-FVIT6JZ5.cjs +4 -0
  253. package/dist/chunk-FVIT6JZ5.cjs.map +1 -0
  254. package/dist/chunk-G3KSVDML.cjs +1310 -0
  255. package/dist/chunk-G3KSVDML.cjs.map +1 -0
  256. package/dist/chunk-GPWMM745.cjs +80 -0
  257. package/dist/chunk-GPWMM745.cjs.map +1 -0
  258. package/dist/chunk-GXSERFAG.js +3 -0
  259. package/dist/chunk-GXSERFAG.js.map +1 -0
  260. package/dist/chunk-HCCXJ5YJ.js +466 -0
  261. package/dist/chunk-HCCXJ5YJ.js.map +1 -0
  262. package/dist/chunk-HLRWYUFN.js +78 -0
  263. package/dist/chunk-HLRWYUFN.js.map +1 -0
  264. package/dist/chunk-HQDX7PWJ.cjs +26 -0
  265. package/dist/chunk-HQDX7PWJ.cjs.map +1 -0
  266. package/dist/chunk-HSX2K7HB.js +164 -0
  267. package/dist/chunk-HSX2K7HB.js.map +1 -0
  268. package/dist/chunk-IAJHRFO4.cjs +2936 -0
  269. package/dist/chunk-IAJHRFO4.cjs.map +1 -0
  270. package/dist/chunk-INOOZ2A2.js +3144 -0
  271. package/dist/chunk-INOOZ2A2.js.map +1 -0
  272. package/dist/chunk-IWU4YSYT.cjs +166 -0
  273. package/dist/chunk-IWU4YSYT.cjs.map +1 -0
  274. package/dist/chunk-JQE3BLYA.js +3 -0
  275. package/dist/chunk-JQE3BLYA.js.map +1 -0
  276. package/dist/chunk-JVV5LREI.js +431 -0
  277. package/dist/chunk-JVV5LREI.js.map +1 -0
  278. package/dist/chunk-LZPOIBOR.js +87 -0
  279. package/dist/chunk-LZPOIBOR.js.map +1 -0
  280. package/dist/chunk-MKCC5K77.js +90 -0
  281. package/dist/chunk-MKCC5K77.js.map +1 -0
  282. package/dist/chunk-N2ILP2YD.js +2539 -0
  283. package/dist/chunk-N2ILP2YD.js.map +1 -0
  284. package/dist/chunk-NLNKQD2T.js +7 -0
  285. package/dist/chunk-NLNKQD2T.js.map +1 -0
  286. package/dist/chunk-NPNGPMT2.js +39 -0
  287. package/dist/chunk-NPNGPMT2.js.map +1 -0
  288. package/dist/chunk-NSIYMRY7.cjs +91 -0
  289. package/dist/chunk-NSIYMRY7.cjs.map +1 -0
  290. package/dist/chunk-OIT3PCWA.js +72 -0
  291. package/dist/chunk-OIT3PCWA.js.map +1 -0
  292. package/dist/chunk-PAOBGBU7.cjs +471 -0
  293. package/dist/chunk-PAOBGBU7.cjs.map +1 -0
  294. package/dist/chunk-PE3V7GUL.cjs +4 -0
  295. package/dist/chunk-PE3V7GUL.cjs.map +1 -0
  296. package/dist/chunk-PFXXH2RP.js +91 -0
  297. package/dist/chunk-PFXXH2RP.js.map +1 -0
  298. package/dist/chunk-PJKCPRYF.js +3 -0
  299. package/dist/chunk-PJKCPRYF.js.map +1 -0
  300. package/dist/chunk-PZUZNPFM.js +166 -0
  301. package/dist/chunk-PZUZNPFM.js.map +1 -0
  302. package/dist/chunk-Q6LWNLAJ.js +3177 -0
  303. package/dist/chunk-Q6LWNLAJ.js.map +1 -0
  304. package/dist/chunk-QLMWFSDC.js +653 -0
  305. package/dist/chunk-QLMWFSDC.js.map +1 -0
  306. package/dist/chunk-R6XC4DV5.js +170 -0
  307. package/dist/chunk-R6XC4DV5.js.map +1 -0
  308. package/dist/chunk-RJOVFHWN.cjs +3160 -0
  309. package/dist/chunk-RJOVFHWN.cjs.map +1 -0
  310. package/dist/chunk-SJMKDSRF.js +179 -0
  311. package/dist/chunk-SJMKDSRF.js.map +1 -0
  312. package/dist/chunk-TCHOIK53.cjs +4 -0
  313. package/dist/chunk-TCHOIK53.cjs.map +1 -0
  314. package/dist/chunk-TEORHM5O.js +1222 -0
  315. package/dist/chunk-TEORHM5O.js.map +1 -0
  316. package/dist/chunk-TSNDVBUU.cjs +90 -0
  317. package/dist/chunk-TSNDVBUU.cjs.map +1 -0
  318. package/dist/chunk-TTELJD4F.js +86 -0
  319. package/dist/chunk-TTELJD4F.js.map +1 -0
  320. package/dist/chunk-TX4TTPYJ.cjs +436 -0
  321. package/dist/chunk-TX4TTPYJ.cjs.map +1 -0
  322. package/dist/chunk-UCPGYU55.cjs +15 -0
  323. package/dist/chunk-UCPGYU55.cjs.map +1 -0
  324. package/dist/chunk-UWTYVVVZ.js +42 -0
  325. package/dist/chunk-UWTYVVVZ.js.map +1 -0
  326. package/dist/chunk-UXG7PYML.js +118 -0
  327. package/dist/chunk-UXG7PYML.js.map +1 -0
  328. package/dist/chunk-V3VLOOSW.cjs +36 -0
  329. package/dist/chunk-V3VLOOSW.cjs.map +1 -0
  330. package/dist/chunk-VED2OIYL.cjs +4 -0
  331. package/dist/chunk-VED2OIYL.cjs.map +1 -0
  332. package/dist/chunk-VF676YCO.cjs +150 -0
  333. package/dist/chunk-VF676YCO.cjs.map +1 -0
  334. package/dist/chunk-VHEA3YXS.js +72 -0
  335. package/dist/chunk-VHEA3YXS.js.map +1 -0
  336. package/dist/chunk-VQASQG5D.js +55 -0
  337. package/dist/chunk-VQASQG5D.js.map +1 -0
  338. package/dist/chunk-VXHOOZSK.js +446 -0
  339. package/dist/chunk-VXHOOZSK.js.map +1 -0
  340. package/dist/chunk-W4UVO3HL.cjs +82 -0
  341. package/dist/chunk-W4UVO3HL.cjs.map +1 -0
  342. package/dist/chunk-WIMFJ2BA.js +2880 -0
  343. package/dist/chunk-WIMFJ2BA.js.map +1 -0
  344. package/dist/chunk-WM4RO23J.js +145 -0
  345. package/dist/chunk-WM4RO23J.js.map +1 -0
  346. package/dist/chunk-WMTXUQC4.cjs +657 -0
  347. package/dist/chunk-WMTXUQC4.cjs.map +1 -0
  348. package/dist/chunk-WNV57BEW.cjs +1705 -0
  349. package/dist/chunk-WNV57BEW.cjs.map +1 -0
  350. package/dist/chunk-X4RMXTXF.cjs +4 -0
  351. package/dist/chunk-X4RMXTXF.cjs.map +1 -0
  352. package/dist/chunk-X7F4CSGR.cjs +67 -0
  353. package/dist/chunk-X7F4CSGR.cjs.map +1 -0
  354. package/dist/chunk-XWGHD4C7.cjs +450 -0
  355. package/dist/chunk-XWGHD4C7.cjs.map +1 -0
  356. package/dist/chunk-YFKTLS32.js +1700 -0
  357. package/dist/chunk-YFKTLS32.js.map +1 -0
  358. package/dist/chunk-ZABG3SZ2.cjs +93 -0
  359. package/dist/chunk-ZABG3SZ2.cjs.map +1 -0
  360. package/dist/chunk-ZIWN73GQ.js +267 -0
  361. package/dist/chunk-ZIWN73GQ.js.map +1 -0
  362. package/dist/chunk-ZOYE65RA.cjs +173 -0
  363. package/dist/chunk-ZOYE65RA.cjs.map +1 -0
  364. package/dist/deployer/index.cjs +12 -0
  365. package/dist/deployer/index.cjs.map +1 -0
  366. package/dist/deployer/index.d.ts +12 -0
  367. package/dist/deployer/index.d.ts.map +1 -0
  368. package/dist/deployer/index.js +3 -0
  369. package/dist/deployer/index.js.map +1 -0
  370. package/dist/deployer/index.warning.d.ts +9 -0
  371. package/dist/deployer/index.warning.d.ts.map +1 -0
  372. package/dist/di/index.cjs +12 -0
  373. package/dist/di/index.cjs.map +1 -0
  374. package/dist/di/index.d.ts +2 -0
  375. package/dist/di/index.d.ts.map +1 -0
  376. package/dist/di/index.js +3 -0
  377. package/dist/di/index.js.map +1 -0
  378. package/dist/error/index.cjs +28 -0
  379. package/dist/error/index.cjs.map +1 -0
  380. package/dist/error/index.d.ts +89 -0
  381. package/dist/error/index.d.ts.map +1 -0
  382. package/dist/error/index.js +3 -0
  383. package/dist/error/index.js.map +1 -0
  384. package/dist/error/utils.d.ts +36 -0
  385. package/dist/error/utils.d.ts.map +1 -0
  386. package/dist/eval/evaluation.d.ts +14 -0
  387. package/dist/eval/evaluation.d.ts.map +1 -0
  388. package/dist/eval/index.cjs +16 -0
  389. package/dist/eval/index.cjs.map +1 -0
  390. package/dist/eval/index.d.ts +4 -0
  391. package/dist/eval/index.d.ts.map +1 -0
  392. package/dist/eval/index.js +3 -0
  393. package/dist/eval/index.js.map +1 -0
  394. package/dist/eval/metric.d.ts +8 -0
  395. package/dist/eval/metric.d.ts.map +1 -0
  396. package/dist/eval/types.d.ts +9 -0
  397. package/dist/eval/types.d.ts.map +1 -0
  398. package/dist/events/event-emitter.d.ts +11 -0
  399. package/dist/events/event-emitter.d.ts.map +1 -0
  400. package/dist/events/index.cjs +12 -0
  401. package/dist/events/index.cjs.map +1 -0
  402. package/dist/events/index.d.ts +3 -0
  403. package/dist/events/index.d.ts.map +1 -0
  404. package/dist/events/index.js +3 -0
  405. package/dist/events/index.js.map +1 -0
  406. package/dist/events/processor.d.ts +11 -0
  407. package/dist/events/processor.d.ts.map +1 -0
  408. package/dist/events/pubsub.d.ts +8 -0
  409. package/dist/events/pubsub.d.ts.map +1 -0
  410. package/dist/events/types.d.ts +8 -0
  411. package/dist/events/types.d.ts.map +1 -0
  412. package/dist/hooks/index.cjs +20 -0
  413. package/dist/hooks/index.cjs.map +1 -0
  414. package/dist/hooks/index.d.ts +36 -0
  415. package/dist/hooks/index.d.ts.map +1 -0
  416. package/dist/hooks/index.js +3 -0
  417. package/dist/hooks/index.js.map +1 -0
  418. package/dist/hooks/mitt.d.ts +22 -0
  419. package/dist/hooks/mitt.d.ts.map +1 -0
  420. package/dist/index.cjs +371 -0
  421. package/dist/index.cjs.map +1 -0
  422. package/dist/index.d.ts +19 -0
  423. package/dist/index.d.ts.map +1 -0
  424. package/dist/index.js +120 -0
  425. package/dist/index.js.map +1 -0
  426. package/dist/integration/index.cjs +16 -0
  427. package/dist/integration/index.cjs.map +1 -0
  428. package/dist/integration/index.d.ts +3 -0
  429. package/dist/integration/index.d.ts.map +1 -0
  430. package/dist/integration/index.js +3 -0
  431. package/dist/integration/index.js.map +1 -0
  432. package/dist/integration/index.warning.d.ts +3 -0
  433. package/dist/integration/index.warning.d.ts.map +1 -0
  434. package/dist/integration/integration.d.ts +21 -0
  435. package/dist/integration/integration.d.ts.map +1 -0
  436. package/dist/integration/integration.warning.d.ts +5 -0
  437. package/dist/integration/integration.warning.d.ts.map +1 -0
  438. package/dist/integration/openapi-toolset.d.ts +16 -0
  439. package/dist/integration/openapi-toolset.d.ts.map +1 -0
  440. package/dist/integration/openapi-toolset.warning.d.ts +5 -0
  441. package/dist/integration/openapi-toolset.warning.d.ts.map +1 -0
  442. package/dist/llm/index.cjs +48 -0
  443. package/dist/llm/index.cjs.map +1 -0
  444. package/dist/llm/index.d.ts +83 -0
  445. package/dist/llm/index.d.ts.map +1 -0
  446. package/dist/llm/index.js +7 -0
  447. package/dist/llm/index.js.map +1 -0
  448. package/dist/llm/model/aisdk/v5/model.d.ts +47 -0
  449. package/dist/llm/model/aisdk/v5/model.d.ts.map +1 -0
  450. package/dist/llm/model/base.types.d.ts +100 -0
  451. package/dist/llm/model/base.types.d.ts.map +1 -0
  452. package/dist/llm/model/embedding-router.d.ts +50 -0
  453. package/dist/llm/model/embedding-router.d.ts.map +1 -0
  454. package/dist/llm/model/gateway-resolver.d.ts +11 -0
  455. package/dist/llm/model/gateway-resolver.d.ts.map +1 -0
  456. package/dist/llm/model/gateways/base.d.ts +50 -0
  457. package/dist/llm/model/gateways/base.d.ts.map +1 -0
  458. package/dist/llm/model/gateways/constants.d.ts +3 -0
  459. package/dist/llm/model/gateways/constants.d.ts.map +1 -0
  460. package/dist/llm/model/gateways/index.d.ts +11 -0
  461. package/dist/llm/model/gateways/index.d.ts.map +1 -0
  462. package/dist/llm/model/gateways/models-dev.d.ts +19 -0
  463. package/dist/llm/model/gateways/models-dev.d.ts.map +1 -0
  464. package/dist/llm/model/gateways/netlify.d.ts +25 -0
  465. package/dist/llm/model/gateways/netlify.d.ts.map +1 -0
  466. package/dist/llm/model/index.d.ts +6 -0
  467. package/dist/llm/model/index.d.ts.map +1 -0
  468. package/dist/llm/model/is-v2-model.d.ts +3 -0
  469. package/dist/llm/model/is-v2-model.d.ts.map +1 -0
  470. package/dist/llm/model/model-method-from-agent.d.ts +4 -0
  471. package/dist/llm/model/model-method-from-agent.d.ts.map +1 -0
  472. package/dist/llm/model/model.d.ts +36 -0
  473. package/dist/llm/model/model.d.ts.map +1 -0
  474. package/dist/llm/model/model.loop.d.ts +26 -0
  475. package/dist/llm/model/model.loop.d.ts.map +1 -0
  476. package/dist/llm/model/model.loop.types.d.ts +31 -0
  477. package/dist/llm/model/model.loop.types.d.ts.map +1 -0
  478. package/dist/llm/model/provider-options.d.ts +42 -0
  479. package/dist/llm/model/provider-options.d.ts.map +1 -0
  480. package/dist/llm/model/provider-registry.d.ts +108 -0
  481. package/dist/llm/model/provider-registry.d.ts.map +1 -0
  482. package/dist/llm/model/provider-types.generated.d.ts +1205 -0
  483. package/dist/llm/model/registry-generator.d.ts +41 -0
  484. package/dist/llm/model/registry-generator.d.ts.map +1 -0
  485. package/dist/llm/model/resolve-model.d.ts +46 -0
  486. package/dist/llm/model/resolve-model.d.ts.map +1 -0
  487. package/dist/llm/model/router.d.ts +30 -0
  488. package/dist/llm/model/router.d.ts.map +1 -0
  489. package/dist/llm/model/shared.types.d.ts +40 -0
  490. package/dist/llm/model/shared.types.d.ts.map +1 -0
  491. package/dist/logger/constants.d.ts +28 -0
  492. package/dist/logger/constants.d.ts.map +1 -0
  493. package/dist/logger/default-logger.d.ts +49 -0
  494. package/dist/logger/default-logger.d.ts.map +1 -0
  495. package/dist/logger/index.cjs +45 -0
  496. package/dist/logger/index.cjs.map +1 -0
  497. package/dist/logger/index.d.ts +7 -0
  498. package/dist/logger/index.d.ts.map +1 -0
  499. package/dist/logger/index.js +4 -0
  500. package/dist/logger/index.js.map +1 -0
  501. package/dist/logger/logger.d.ts +88 -0
  502. package/dist/logger/logger.d.ts.map +1 -0
  503. package/dist/logger/multi-logger.d.ts +46 -0
  504. package/dist/logger/multi-logger.d.ts.map +1 -0
  505. package/dist/logger/noop-logger.d.ts +3 -0
  506. package/dist/logger/noop-logger.d.ts.map +1 -0
  507. package/dist/logger/transport.d.ts +46 -0
  508. package/dist/logger/transport.d.ts.map +1 -0
  509. package/dist/loop/index.cjs +12 -0
  510. package/dist/loop/index.cjs.map +1 -0
  511. package/dist/loop/index.d.ts +2 -0
  512. package/dist/loop/index.d.ts.map +1 -0
  513. package/dist/loop/index.js +3 -0
  514. package/dist/loop/index.js.map +1 -0
  515. package/dist/loop/loop.d.ts +6 -0
  516. package/dist/loop/loop.d.ts.map +1 -0
  517. package/dist/loop/network/index.d.ts +145 -0
  518. package/dist/loop/network/index.d.ts.map +1 -0
  519. package/dist/loop/telemetry/index.d.ts +36 -0
  520. package/dist/loop/telemetry/index.d.ts.map +1 -0
  521. package/dist/loop/telemetry/noop.d.ts +3 -0
  522. package/dist/loop/telemetry/noop.d.ts.map +1 -0
  523. package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts +37 -0
  524. package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts.map +1 -0
  525. package/dist/loop/test-utils/fullStream.d.ts +6 -0
  526. package/dist/loop/test-utils/fullStream.d.ts.map +1 -0
  527. package/dist/loop/test-utils/generateText.d.ts +6 -0
  528. package/dist/loop/test-utils/generateText.d.ts.map +1 -0
  529. package/dist/loop/test-utils/mock-server-response.d.ts +28 -0
  530. package/dist/loop/test-utils/mock-server-response.d.ts.map +1 -0
  531. package/dist/loop/test-utils/mockTracer.d.ts +47 -0
  532. package/dist/loop/test-utils/mockTracer.d.ts.map +1 -0
  533. package/dist/loop/test-utils/options.d.ts +6 -0
  534. package/dist/loop/test-utils/options.d.ts.map +1 -0
  535. package/dist/loop/test-utils/resultObject.d.ts +6 -0
  536. package/dist/loop/test-utils/resultObject.d.ts.map +1 -0
  537. package/dist/loop/test-utils/streamObject.d.ts +15 -0
  538. package/dist/loop/test-utils/streamObject.d.ts.map +1 -0
  539. package/dist/loop/test-utils/telemetry.d.ts +6 -0
  540. package/dist/loop/test-utils/telemetry.d.ts.map +1 -0
  541. package/dist/loop/test-utils/textStream.d.ts +6 -0
  542. package/dist/loop/test-utils/textStream.d.ts.map +1 -0
  543. package/dist/loop/test-utils/toUIMessageStream.d.ts +6 -0
  544. package/dist/loop/test-utils/toUIMessageStream.d.ts.map +1 -0
  545. package/dist/loop/test-utils/tools.d.ts +6 -0
  546. package/dist/loop/test-utils/tools.d.ts.map +1 -0
  547. package/dist/loop/test-utils/utils.d.ts +45 -0
  548. package/dist/loop/test-utils/utils.d.ts.map +1 -0
  549. package/dist/loop/types.d.ts +111 -0
  550. package/dist/loop/types.d.ts.map +1 -0
  551. package/dist/loop/workflows/agentic-execution/index.d.ts +939 -0
  552. package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -0
  553. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +629 -0
  554. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -0
  555. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +348 -0
  556. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -0
  557. package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts +58 -0
  558. package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -0
  559. package/dist/loop/workflows/agentic-loop/index.d.ts +945 -0
  560. package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -0
  561. package/dist/loop/workflows/run-state.d.ts +29 -0
  562. package/dist/loop/workflows/run-state.d.ts.map +1 -0
  563. package/dist/loop/workflows/schema.d.ts +479 -0
  564. package/dist/loop/workflows/schema.d.ts.map +1 -0
  565. package/dist/loop/workflows/stream.d.ts +20 -0
  566. package/dist/loop/workflows/stream.d.ts.map +1 -0
  567. package/dist/mastra/hooks.d.ts +6 -0
  568. package/dist/mastra/hooks.d.ts.map +1 -0
  569. package/dist/mastra/index.cjs +12 -0
  570. package/dist/mastra/index.cjs.map +1 -0
  571. package/dist/mastra/index.d.ts +892 -0
  572. package/dist/mastra/index.d.ts.map +1 -0
  573. package/dist/mastra/index.js +3 -0
  574. package/dist/mastra/index.js.map +1 -0
  575. package/dist/mcp/index.cjs +112 -0
  576. package/dist/mcp/index.cjs.map +1 -0
  577. package/dist/mcp/index.d.ts +158 -0
  578. package/dist/mcp/index.d.ts.map +1 -0
  579. package/dist/mcp/index.js +106 -0
  580. package/dist/mcp/index.js.map +1 -0
  581. package/dist/mcp/types.d.ts +255 -0
  582. package/dist/mcp/types.d.ts.map +1 -0
  583. package/dist/memory/index.cjs +20 -0
  584. package/dist/memory/index.cjs.map +1 -0
  585. package/dist/memory/index.d.ts +3 -0
  586. package/dist/memory/index.d.ts.map +1 -0
  587. package/dist/memory/index.js +3 -0
  588. package/dist/memory/index.js.map +1 -0
  589. package/dist/memory/index.warning.d.ts +6 -0
  590. package/dist/memory/index.warning.d.ts.map +1 -0
  591. package/dist/memory/memory.d.ts +272 -0
  592. package/dist/memory/memory.d.ts.map +1 -0
  593. package/dist/memory/types.d.ts +393 -0
  594. package/dist/memory/types.d.ts.map +1 -0
  595. package/dist/models-dev-LJ4O6FNF.js +3 -0
  596. package/dist/models-dev-LJ4O6FNF.js.map +1 -0
  597. package/dist/models-dev-T2CXOEDH.cjs +12 -0
  598. package/dist/models-dev-T2CXOEDH.cjs.map +1 -0
  599. package/dist/netlify-BAEMIQNH.cjs +12 -0
  600. package/dist/netlify-BAEMIQNH.cjs.map +1 -0
  601. package/dist/netlify-L7AZ74PV.js +3 -0
  602. package/dist/netlify-L7AZ74PV.js.map +1 -0
  603. package/dist/processors/index.cjs +48 -0
  604. package/dist/processors/index.cjs.map +1 -0
  605. package/dist/processors/index.d.ts +43 -0
  606. package/dist/processors/index.d.ts.map +1 -0
  607. package/dist/processors/index.js +3 -0
  608. package/dist/processors/index.js.map +1 -0
  609. package/dist/processors/processors/batch-parts.d.ts +47 -0
  610. package/dist/processors/processors/batch-parts.d.ts.map +1 -0
  611. package/dist/processors/processors/index.d.ts +10 -0
  612. package/dist/processors/processors/index.d.ts.map +1 -0
  613. package/dist/processors/processors/language-detector.d.ts +153 -0
  614. package/dist/processors/processors/language-detector.d.ts.map +1 -0
  615. package/dist/processors/processors/moderation.d.ts +138 -0
  616. package/dist/processors/processors/moderation.d.ts.map +1 -0
  617. package/dist/processors/processors/pii-detector.d.ts +203 -0
  618. package/dist/processors/processors/pii-detector.d.ts.map +1 -0
  619. package/dist/processors/processors/prompt-injection-detector.d.ts +116 -0
  620. package/dist/processors/processors/prompt-injection-detector.d.ts.map +1 -0
  621. package/dist/processors/processors/structured-output.d.ts +53 -0
  622. package/dist/processors/processors/structured-output.d.ts.map +1 -0
  623. package/dist/processors/processors/system-prompt-scrubber.d.ts +105 -0
  624. package/dist/processors/processors/system-prompt-scrubber.d.ts.map +1 -0
  625. package/dist/processors/processors/token-limiter.d.ts +66 -0
  626. package/dist/processors/processors/token-limiter.d.ts.map +1 -0
  627. package/dist/processors/processors/unicode-normalizer.d.ts +34 -0
  628. package/dist/processors/processors/unicode-normalizer.d.ts.map +1 -0
  629. package/dist/processors/runner.d.ts +46 -0
  630. package/dist/processors/runner.d.ts.map +1 -0
  631. package/dist/provider-registry-RUDYHG7J.cjs +40 -0
  632. package/dist/provider-registry-RUDYHG7J.cjs.map +1 -0
  633. package/dist/provider-registry-THITZUJ7.js +3 -0
  634. package/dist/provider-registry-THITZUJ7.js.map +1 -0
  635. package/dist/provider-registry.json +2748 -0
  636. package/dist/registry-generator-DL42NMBM.cjs +134 -0
  637. package/dist/registry-generator-DL42NMBM.cjs.map +1 -0
  638. package/dist/registry-generator-I6S4ARS6.js +124 -0
  639. package/dist/registry-generator-I6S4ARS6.js.map +1 -0
  640. package/dist/relevance/cohere/index.d.ts +9 -0
  641. package/dist/relevance/cohere/index.d.ts.map +1 -0
  642. package/dist/relevance/index.cjs +20 -0
  643. package/dist/relevance/index.cjs.map +1 -0
  644. package/dist/relevance/index.d.ts +4 -0
  645. package/dist/relevance/index.d.ts.map +1 -0
  646. package/dist/relevance/index.js +3 -0
  647. package/dist/relevance/index.js.map +1 -0
  648. package/dist/relevance/mastra-agent/index.d.ts +8 -0
  649. package/dist/relevance/mastra-agent/index.d.ts.map +1 -0
  650. package/dist/relevance/relevance-score-provider.d.ts +5 -0
  651. package/dist/relevance/relevance-score-provider.d.ts.map +1 -0
  652. package/dist/run/types.d.ts +6 -0
  653. package/dist/run/types.d.ts.map +1 -0
  654. package/dist/runtime-context/index.cjs +12 -0
  655. package/dist/runtime-context/index.cjs.map +1 -0
  656. package/dist/runtime-context/index.d.ts +57 -0
  657. package/dist/runtime-context/index.d.ts.map +1 -0
  658. package/dist/runtime-context/index.js +3 -0
  659. package/dist/runtime-context/index.js.map +1 -0
  660. package/dist/scores/base.d.ts +141 -0
  661. package/dist/scores/base.d.ts.map +1 -0
  662. package/dist/scores/base.test-utils.d.ts +124 -0
  663. package/dist/scores/base.test-utils.d.ts.map +1 -0
  664. package/dist/scores/hooks.d.ts +19 -0
  665. package/dist/scores/hooks.d.ts.map +1 -0
  666. package/dist/scores/index.cjs +37 -0
  667. package/dist/scores/index.cjs.map +1 -0
  668. package/dist/scores/index.d.ts +4 -0
  669. package/dist/scores/index.d.ts.map +1 -0
  670. package/dist/scores/index.js +4 -0
  671. package/dist/scores/index.js.map +1 -0
  672. package/dist/scores/run-experiment/index.d.ts +61 -0
  673. package/dist/scores/run-experiment/index.d.ts.map +1 -0
  674. package/dist/scores/run-experiment/scorerAccumulator.d.ts +12 -0
  675. package/dist/scores/run-experiment/scorerAccumulator.d.ts.map +1 -0
  676. package/dist/scores/scoreTraces/index.cjs +431 -0
  677. package/dist/scores/scoreTraces/index.cjs.map +1 -0
  678. package/dist/scores/scoreTraces/index.d.ts +3 -0
  679. package/dist/scores/scoreTraces/index.d.ts.map +1 -0
  680. package/dist/scores/scoreTraces/index.js +423 -0
  681. package/dist/scores/scoreTraces/index.js.map +1 -0
  682. package/dist/scores/scoreTraces/scoreTraces.d.ts +10 -0
  683. package/dist/scores/scoreTraces/scoreTraces.d.ts.map +1 -0
  684. package/dist/scores/scoreTraces/scoreTracesWorkflow.d.ts +95 -0
  685. package/dist/scores/scoreTraces/scoreTracesWorkflow.d.ts.map +1 -0
  686. package/dist/scores/scoreTraces/utils.d.ts +21 -0
  687. package/dist/scores/scoreTraces/utils.d.ts.map +1 -0
  688. package/dist/scores/types.d.ts +191 -0
  689. package/dist/scores/types.d.ts.map +1 -0
  690. package/dist/server/auth.d.ts +36 -0
  691. package/dist/server/auth.d.ts.map +1 -0
  692. package/dist/server/composite-auth.d.ts +9 -0
  693. package/dist/server/composite-auth.d.ts.map +1 -0
  694. package/dist/server/index.cjs +185 -0
  695. package/dist/server/index.cjs.map +1 -0
  696. package/dist/server/index.d.ts +37 -0
  697. package/dist/server/index.d.ts.map +1 -0
  698. package/dist/server/index.js +180 -0
  699. package/dist/server/index.js.map +1 -0
  700. package/dist/server/simple-auth.d.ts +32 -0
  701. package/dist/server/simple-auth.d.ts.map +1 -0
  702. package/dist/server/types.d.ts +140 -0
  703. package/dist/server/types.d.ts.map +1 -0
  704. package/dist/storage/base.d.ts +360 -0
  705. package/dist/storage/base.d.ts.map +1 -0
  706. package/dist/storage/base.warning.d.ts +8 -0
  707. package/dist/storage/base.warning.d.ts.map +1 -0
  708. package/dist/storage/constants.d.ts +14 -0
  709. package/dist/storage/constants.d.ts.map +1 -0
  710. package/dist/storage/domains/index.d.ts +8 -0
  711. package/dist/storage/domains/index.d.ts.map +1 -0
  712. package/dist/storage/domains/legacy-evals/base.d.ts +13 -0
  713. package/dist/storage/domains/legacy-evals/base.d.ts.map +1 -0
  714. package/dist/storage/domains/legacy-evals/index.d.ts +2 -0
  715. package/dist/storage/domains/legacy-evals/index.d.ts.map +1 -0
  716. package/dist/storage/domains/legacy-evals/inmemory.d.ts +17 -0
  717. package/dist/storage/domains/legacy-evals/inmemory.d.ts.map +1 -0
  718. package/dist/storage/domains/memory/base.d.ts +96 -0
  719. package/dist/storage/domains/memory/base.d.ts.map +1 -0
  720. package/dist/storage/domains/memory/index.d.ts +3 -0
  721. package/dist/storage/domains/memory/index.d.ts.map +1 -0
  722. package/dist/storage/domains/memory/inmemory.d.ts +85 -0
  723. package/dist/storage/domains/memory/inmemory.d.ts.map +1 -0
  724. package/dist/storage/domains/observability/base.d.ts +60 -0
  725. package/dist/storage/domains/observability/base.d.ts.map +1 -0
  726. package/dist/storage/domains/observability/index.d.ts +3 -0
  727. package/dist/storage/domains/observability/index.d.ts.map +1 -0
  728. package/dist/storage/domains/observability/inmemory.d.ts +48 -0
  729. package/dist/storage/domains/observability/inmemory.d.ts.map +1 -0
  730. package/dist/storage/domains/operations/base.d.ts +68 -0
  731. package/dist/storage/domains/operations/base.d.ts.map +1 -0
  732. package/dist/storage/domains/operations/index.d.ts +3 -0
  733. package/dist/storage/domains/operations/index.d.ts.map +1 -0
  734. package/dist/storage/domains/operations/inmemory.d.ts +37 -0
  735. package/dist/storage/domains/operations/inmemory.d.ts.map +1 -0
  736. package/dist/storage/domains/scores/base.d.ts +46 -0
  737. package/dist/storage/domains/scores/base.d.ts.map +1 -0
  738. package/dist/storage/domains/scores/index.d.ts +3 -0
  739. package/dist/storage/domains/scores/index.d.ts.map +1 -0
  740. package/dist/storage/domains/scores/inmemory.d.ts +50 -0
  741. package/dist/storage/domains/scores/inmemory.d.ts.map +1 -0
  742. package/dist/storage/domains/traces/base.d.ts +14 -0
  743. package/dist/storage/domains/traces/base.d.ts.map +1 -0
  744. package/dist/storage/domains/traces/index.d.ts +3 -0
  745. package/dist/storage/domains/traces/index.d.ts.map +1 -0
  746. package/dist/storage/domains/traces/inmemory.d.ts +22 -0
  747. package/dist/storage/domains/traces/inmemory.d.ts.map +1 -0
  748. package/dist/storage/domains/workflows/base.d.ts +47 -0
  749. package/dist/storage/domains/workflows/base.d.ts.map +1 -0
  750. package/dist/storage/domains/workflows/index.d.ts +3 -0
  751. package/dist/storage/domains/workflows/index.d.ts.map +1 -0
  752. package/dist/storage/domains/workflows/inmemory.d.ts +54 -0
  753. package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -0
  754. package/dist/storage/index.cjs +1821 -0
  755. package/dist/storage/index.cjs.map +1 -0
  756. package/dist/storage/index.d.ts +7 -0
  757. package/dist/storage/index.d.ts.map +1 -0
  758. package/dist/storage/index.js +1746 -0
  759. package/dist/storage/index.js.map +1 -0
  760. package/dist/storage/index.warning.d.ts +3 -0
  761. package/dist/storage/index.warning.d.ts.map +1 -0
  762. package/dist/storage/mock.d.ts +242 -0
  763. package/dist/storage/mock.d.ts.map +1 -0
  764. package/dist/storage/storageWithInit.d.ts +3 -0
  765. package/dist/storage/storageWithInit.d.ts.map +1 -0
  766. package/dist/storage/types.d.ts +206 -0
  767. package/dist/storage/types.d.ts.map +1 -0
  768. package/dist/storage/utils.d.ts +2 -0
  769. package/dist/storage/utils.d.ts.map +1 -0
  770. package/dist/stream/MastraAgentNetworkStream.d.ts +22 -0
  771. package/dist/stream/MastraAgentNetworkStream.d.ts.map +1 -0
  772. package/dist/stream/MastraWorkflowStream.d.ts +19 -0
  773. package/dist/stream/MastraWorkflowStream.d.ts.map +1 -0
  774. package/dist/stream/RunOutput.d.ts +72 -0
  775. package/dist/stream/RunOutput.d.ts.map +1 -0
  776. package/dist/stream/aisdk/v4/input.d.ts +16 -0
  777. package/dist/stream/aisdk/v4/input.d.ts.map +1 -0
  778. package/dist/stream/aisdk/v4/transform.d.ts +5 -0
  779. package/dist/stream/aisdk/v4/transform.d.ts.map +1 -0
  780. package/dist/stream/aisdk/v5/compat/consume-stream.d.ts +8 -0
  781. package/dist/stream/aisdk/v5/compat/consume-stream.d.ts.map +1 -0
  782. package/dist/stream/aisdk/v5/compat/content.d.ts +7 -0
  783. package/dist/stream/aisdk/v5/compat/content.d.ts.map +1 -0
  784. package/dist/stream/aisdk/v5/compat/delayed-promise.d.ts +23 -0
  785. package/dist/stream/aisdk/v5/compat/delayed-promise.d.ts.map +1 -0
  786. package/dist/stream/aisdk/v5/compat/index.d.ts +8 -0
  787. package/dist/stream/aisdk/v5/compat/index.d.ts.map +1 -0
  788. package/dist/stream/aisdk/v5/compat/media.d.ts +91 -0
  789. package/dist/stream/aisdk/v5/compat/media.d.ts.map +1 -0
  790. package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts +11 -0
  791. package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -0
  792. package/dist/stream/aisdk/v5/compat/ui-message.d.ts +20 -0
  793. package/dist/stream/aisdk/v5/compat/ui-message.d.ts.map +1 -0
  794. package/dist/stream/aisdk/v5/compat/validation.d.ts +17 -0
  795. package/dist/stream/aisdk/v5/compat/validation.d.ts.map +1 -0
  796. package/dist/stream/aisdk/v5/execute.d.ts +41 -0
  797. package/dist/stream/aisdk/v5/execute.d.ts.map +1 -0
  798. package/dist/stream/aisdk/v5/file.d.ts +38 -0
  799. package/dist/stream/aisdk/v5/file.d.ts.map +1 -0
  800. package/dist/stream/aisdk/v5/input.d.ts +16 -0
  801. package/dist/stream/aisdk/v5/input.d.ts.map +1 -0
  802. package/dist/stream/aisdk/v5/output-helpers.d.ts +66 -0
  803. package/dist/stream/aisdk/v5/output-helpers.d.ts.map +1 -0
  804. package/dist/stream/aisdk/v5/output.d.ts +173 -0
  805. package/dist/stream/aisdk/v5/output.d.ts.map +1 -0
  806. package/dist/stream/aisdk/v5/test-utils.d.ts +19 -0
  807. package/dist/stream/aisdk/v5/test-utils.d.ts.map +1 -0
  808. package/dist/stream/aisdk/v5/transform.d.ts +27 -0
  809. package/dist/stream/aisdk/v5/transform.d.ts.map +1 -0
  810. package/dist/stream/base/base.d.ts +7 -0
  811. package/dist/stream/base/base.d.ts.map +1 -0
  812. package/dist/stream/base/consume-stream.d.ts +5 -0
  813. package/dist/stream/base/consume-stream.d.ts.map +1 -0
  814. package/dist/stream/base/index.d.ts +2 -0
  815. package/dist/stream/base/index.d.ts.map +1 -0
  816. package/dist/stream/base/input.d.ts +16 -0
  817. package/dist/stream/base/input.d.ts.map +1 -0
  818. package/dist/stream/base/output-format-handlers.d.ts +29 -0
  819. package/dist/stream/base/output-format-handlers.d.ts.map +1 -0
  820. package/dist/stream/base/output.d.ts +313 -0
  821. package/dist/stream/base/output.d.ts.map +1 -0
  822. package/dist/stream/base/schema.d.ts +31 -0
  823. package/dist/stream/base/schema.d.ts.map +1 -0
  824. package/dist/stream/index.cjs +45 -0
  825. package/dist/stream/index.cjs.map +1 -0
  826. package/dist/stream/index.d.ts +11 -0
  827. package/dist/stream/index.d.ts.map +1 -0
  828. package/dist/stream/index.js +4 -0
  829. package/dist/stream/index.js.map +1 -0
  830. package/dist/stream/types.d.ts +734 -0
  831. package/dist/stream/types.d.ts.map +1 -0
  832. package/dist/telemetry/composite-exporter.d.ts +10 -0
  833. package/dist/telemetry/composite-exporter.d.ts.map +1 -0
  834. package/dist/telemetry/index.cjs +32 -0
  835. package/dist/telemetry/index.cjs.map +1 -0
  836. package/dist/telemetry/index.d.ts +6 -0
  837. package/dist/telemetry/index.d.ts.map +1 -0
  838. package/dist/telemetry/index.js +3 -0
  839. package/dist/telemetry/index.js.map +1 -0
  840. package/dist/telemetry/otel-vendor.cjs +105 -0
  841. package/dist/telemetry/otel-vendor.cjs.map +1 -0
  842. package/dist/telemetry/otel-vendor.d.ts +11 -0
  843. package/dist/telemetry/otel-vendor.d.ts.map +1 -0
  844. package/dist/telemetry/otel-vendor.js +59 -0
  845. package/dist/telemetry/otel-vendor.js.map +1 -0
  846. package/dist/telemetry/storage-exporter.d.ts +21 -0
  847. package/dist/telemetry/storage-exporter.d.ts.map +1 -0
  848. package/dist/telemetry/telemetry.d.ts +59 -0
  849. package/dist/telemetry/telemetry.d.ts.map +1 -0
  850. package/dist/telemetry/telemetry.decorators.d.ts +15 -0
  851. package/dist/telemetry/telemetry.decorators.d.ts.map +1 -0
  852. package/dist/telemetry/types.d.ts +74 -0
  853. package/dist/telemetry/types.d.ts.map +1 -0
  854. package/dist/telemetry/utility.d.ts +15 -0
  855. package/dist/telemetry/utility.d.ts.map +1 -0
  856. package/dist/test-utils/llm-mock.cjs +181 -0
  857. package/dist/test-utils/llm-mock.cjs.map +1 -0
  858. package/dist/test-utils/llm-mock.d.ts +21 -0
  859. package/dist/test-utils/llm-mock.d.ts.map +1 -0
  860. package/dist/test-utils/llm-mock.js +178 -0
  861. package/dist/test-utils/llm-mock.js.map +1 -0
  862. package/dist/tools/index.cjs +25 -0
  863. package/dist/tools/index.cjs.map +1 -0
  864. package/dist/tools/index.d.ts +6 -0
  865. package/dist/tools/index.d.ts.map +1 -0
  866. package/dist/tools/index.js +4 -0
  867. package/dist/tools/index.js.map +1 -0
  868. package/dist/tools/index.warning.d.ts +8 -0
  869. package/dist/tools/index.warning.d.ts.map +1 -0
  870. package/dist/tools/is-vercel-tool.cjs +12 -0
  871. package/dist/tools/is-vercel-tool.cjs.map +1 -0
  872. package/dist/tools/is-vercel-tool.d.ts +2 -0
  873. package/dist/tools/is-vercel-tool.d.ts.map +1 -0
  874. package/dist/tools/is-vercel-tool.js +3 -0
  875. package/dist/tools/is-vercel-tool.js.map +1 -0
  876. package/dist/tools/stream.d.ts +19 -0
  877. package/dist/tools/stream.d.ts.map +1 -0
  878. package/dist/tools/tool-builder/builder.d.ts +28 -0
  879. package/dist/tools/tool-builder/builder.d.ts.map +1 -0
  880. package/dist/tools/tool.d.ts +186 -0
  881. package/dist/tools/tool.d.ts.map +1 -0
  882. package/dist/tools/toolchecks.d.ts +9 -0
  883. package/dist/tools/toolchecks.d.ts.map +1 -0
  884. package/dist/tools/types.d.ts +70 -0
  885. package/dist/tools/types.d.ts.map +1 -0
  886. package/dist/tools/ui-types.d.ts +39 -0
  887. package/dist/tools/ui-types.d.ts.map +1 -0
  888. package/dist/tools/validation.d.ts +19 -0
  889. package/dist/tools/validation.d.ts.map +1 -0
  890. package/dist/tts/index.cjs +12 -0
  891. package/dist/tts/index.cjs.map +1 -0
  892. package/dist/tts/index.d.ts +22 -0
  893. package/dist/tts/index.d.ts.map +1 -0
  894. package/dist/tts/index.js +3 -0
  895. package/dist/tts/index.js.map +1 -0
  896. package/dist/tts/index.warning.d.ts +7 -0
  897. package/dist/tts/index.warning.d.ts.map +1 -0
  898. package/dist/types/dynamic-argument.d.ts +9 -0
  899. package/dist/types/dynamic-argument.d.ts.map +1 -0
  900. package/dist/types/index.cjs +4 -0
  901. package/dist/types/index.cjs.map +1 -0
  902. package/dist/types/index.d.ts +2 -0
  903. package/dist/types/index.d.ts.map +1 -0
  904. package/dist/types/index.js +3 -0
  905. package/dist/types/index.js.map +1 -0
  906. package/dist/types/zod-compat.d.ts +23 -0
  907. package/dist/types/zod-compat.d.ts.map +1 -0
  908. package/dist/utils.cjs +72 -0
  909. package/dist/utils.cjs.map +1 -0
  910. package/dist/utils.d.ts +148 -0
  911. package/dist/utils.d.ts.map +1 -0
  912. package/dist/utils.js +3 -0
  913. package/dist/utils.js.map +1 -0
  914. package/dist/vector/embed.d.ts +3 -0
  915. package/dist/vector/embed.d.ts.map +1 -0
  916. package/dist/vector/filter/base.d.ts +128 -0
  917. package/dist/vector/filter/base.d.ts.map +1 -0
  918. package/dist/vector/filter/index.cjs +12 -0
  919. package/dist/vector/filter/index.cjs.map +1 -0
  920. package/dist/vector/filter/index.d.ts +2 -0
  921. package/dist/vector/filter/index.d.ts.map +1 -0
  922. package/dist/vector/filter/index.js +3 -0
  923. package/dist/vector/filter/index.js.map +1 -0
  924. package/dist/vector/index.cjs +25 -0
  925. package/dist/vector/index.cjs.map +1 -0
  926. package/dist/vector/index.d.ts +5 -0
  927. package/dist/vector/index.d.ts.map +1 -0
  928. package/dist/vector/index.js +4 -0
  929. package/dist/vector/index.js.map +1 -0
  930. package/dist/vector/index.warning.d.ts +6 -0
  931. package/dist/vector/index.warning.d.ts.map +1 -0
  932. package/dist/vector/types.d.ts +152 -0
  933. package/dist/vector/types.d.ts.map +1 -0
  934. package/dist/vector/vector.d.ts +57 -0
  935. package/dist/vector/vector.d.ts.map +1 -0
  936. package/dist/voice/aisdk/index.d.ts +3 -0
  937. package/dist/voice/aisdk/index.d.ts.map +1 -0
  938. package/dist/voice/aisdk/speech.d.ts +23 -0
  939. package/dist/voice/aisdk/speech.d.ts.map +1 -0
  940. package/dist/voice/aisdk/transcription.d.ts +22 -0
  941. package/dist/voice/aisdk/transcription.d.ts.map +1 -0
  942. package/dist/voice/composite-voice.d.ts +78 -0
  943. package/dist/voice/composite-voice.d.ts.map +1 -0
  944. package/dist/voice/default-voice.d.ts +13 -0
  945. package/dist/voice/default-voice.d.ts.map +1 -0
  946. package/dist/voice/index.cjs +28 -0
  947. package/dist/voice/index.cjs.map +1 -0
  948. package/dist/voice/index.d.ts +5 -0
  949. package/dist/voice/index.d.ts.map +1 -0
  950. package/dist/voice/index.js +3 -0
  951. package/dist/voice/index.js.map +1 -0
  952. package/dist/voice/voice.d.ts +132 -0
  953. package/dist/voice/voice.d.ts.map +1 -0
  954. package/dist/workflows/constants.cjs +16 -0
  955. package/dist/workflows/constants.cjs.map +1 -0
  956. package/dist/workflows/constants.d.ts +3 -0
  957. package/dist/workflows/constants.d.ts.map +1 -0
  958. package/dist/workflows/constants.js +3 -0
  959. package/dist/workflows/constants.js.map +1 -0
  960. package/dist/workflows/default.d.ts +345 -0
  961. package/dist/workflows/default.d.ts.map +1 -0
  962. package/dist/workflows/evented/execution-engine.d.ts +41 -0
  963. package/dist/workflows/evented/execution-engine.d.ts.map +1 -0
  964. package/dist/workflows/evented/index.cjs +44 -0
  965. package/dist/workflows/evented/index.cjs.map +1 -0
  966. package/dist/workflows/evented/index.d.ts +5 -0
  967. package/dist/workflows/evented/index.d.ts.map +1 -0
  968. package/dist/workflows/evented/index.js +3 -0
  969. package/dist/workflows/evented/index.js.map +1 -0
  970. package/dist/workflows/evented/step-executor.d.ts +90 -0
  971. package/dist/workflows/evented/step-executor.d.ts.map +1 -0
  972. package/dist/workflows/evented/workflow-event-processor/index.d.ts +54 -0
  973. package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -0
  974. package/dist/workflows/evented/workflow-event-processor/loop.d.ts +21 -0
  975. package/dist/workflows/evented/workflow-event-processor/loop.d.ts.map +1 -0
  976. package/dist/workflows/evented/workflow-event-processor/parallel.d.ts +18 -0
  977. package/dist/workflows/evented/workflow-event-processor/parallel.d.ts.map +1 -0
  978. package/dist/workflows/evented/workflow-event-processor/sleep.d.ts +24 -0
  979. package/dist/workflows/evented/workflow-event-processor/sleep.d.ts.map +1 -0
  980. package/dist/workflows/evented/workflow-event-processor/utils.d.ts +30 -0
  981. package/dist/workflows/evented/workflow-event-processor/utils.d.ts.map +1 -0
  982. package/dist/workflows/evented/workflow.d.ts +81 -0
  983. package/dist/workflows/evented/workflow.d.ts.map +1 -0
  984. package/dist/workflows/execution-engine.d.ts +75 -0
  985. package/dist/workflows/execution-engine.d.ts.map +1 -0
  986. package/dist/workflows/index.cjs +60 -0
  987. package/dist/workflows/index.cjs.map +1 -0
  988. package/dist/workflows/index.d.ts +7 -0
  989. package/dist/workflows/index.d.ts.map +1 -0
  990. package/dist/workflows/index.js +3 -0
  991. package/dist/workflows/index.js.map +1 -0
  992. package/dist/workflows/index.warning.d.ts +6 -0
  993. package/dist/workflows/index.warning.d.ts.map +1 -0
  994. package/dist/workflows/legacy/index.cjs +92 -0
  995. package/dist/workflows/legacy/index.cjs.map +1 -0
  996. package/dist/workflows/legacy/index.d.ts +5 -0
  997. package/dist/workflows/legacy/index.d.ts.map +1 -0
  998. package/dist/workflows/legacy/index.js +3 -0
  999. package/dist/workflows/legacy/index.js.map +1 -0
  1000. package/dist/workflows/legacy/machine.d.ts +386 -0
  1001. package/dist/workflows/legacy/machine.d.ts.map +1 -0
  1002. package/dist/workflows/legacy/step.d.ts +15 -0
  1003. package/dist/workflows/legacy/step.d.ts.map +1 -0
  1004. package/dist/workflows/legacy/types.d.ts +397 -0
  1005. package/dist/workflows/legacy/types.d.ts.map +1 -0
  1006. package/dist/workflows/legacy/utils.d.ts +68 -0
  1007. package/dist/workflows/legacy/utils.d.ts.map +1 -0
  1008. package/dist/workflows/legacy/workflow-instance.d.ts +97 -0
  1009. package/dist/workflows/legacy/workflow-instance.d.ts.map +1 -0
  1010. package/dist/workflows/legacy/workflow.d.ts +109 -0
  1011. package/dist/workflows/legacy/workflow.d.ts.map +1 -0
  1012. package/dist/workflows/step.d.ts +64 -0
  1013. package/dist/workflows/step.d.ts.map +1 -0
  1014. package/dist/workflows/types.d.ts +351 -0
  1015. package/dist/workflows/types.d.ts.map +1 -0
  1016. package/dist/workflows/utils.d.ts +19 -0
  1017. package/dist/workflows/utils.d.ts.map +1 -0
  1018. package/dist/workflows/workflow.d.ts +493 -0
  1019. package/dist/workflows/workflow.d.ts.map +1 -0
  1020. package/dist/workflows/workflow.warning.d.ts +9 -0
  1021. package/dist/workflows/workflow.warning.d.ts.map +1 -0
  1022. package/dist/zod-to-json.cjs +12 -0
  1023. package/dist/zod-to-json.cjs.map +1 -0
  1024. package/dist/zod-to-json.d.ts +2 -0
  1025. package/dist/zod-to-json.d.ts.map +1 -0
  1026. package/dist/zod-to-json.js +3 -0
  1027. package/dist/zod-to-json.js.map +1 -0
  1028. package/error.d.ts +1 -0
  1029. package/eval.d.ts +1 -0
  1030. package/events.d.ts +1 -0
  1031. package/hooks.d.ts +1 -0
  1032. package/integration.d.ts +1 -0
  1033. package/llm.d.ts +1 -0
  1034. package/logger.d.ts +1 -0
  1035. package/loop.d.ts +1 -0
  1036. package/mastra.d.ts +1 -0
  1037. package/mcp.d.ts +1 -0
  1038. package/memory.d.ts +1 -0
  1039. package/package.json +305 -0
  1040. package/processors.d.ts +1 -0
  1041. package/relevance.d.ts +1 -0
  1042. package/runtime-context.d.ts +1 -0
  1043. package/scores/scoreTraces.d.ts +1 -0
  1044. package/scores.d.ts +1 -0
  1045. package/server.d.ts +1 -0
  1046. package/src/llm/model/provider-types.generated.d.ts +1205 -0
  1047. package/storage.d.ts +1 -0
  1048. package/stream.d.ts +1 -0
  1049. package/telemetry/otel-vendor.d.ts +1 -0
  1050. package/telemetry.d.ts +1 -0
  1051. package/test-utils/llm-mock.d.ts +1 -0
  1052. package/tools/is-vercel-tool.d.ts +1 -0
  1053. package/tools.d.ts +1 -0
  1054. package/tts.d.ts +1 -0
  1055. package/types.d.ts +1 -0
  1056. package/utils/zod-to-json.d.ts +1 -0
  1057. package/utils.d.ts +1 -0
  1058. package/vector/filter.d.ts +1 -0
  1059. package/vector.d.ts +1 -0
  1060. package/voice.d.ts +1 -0
  1061. package/workflows/_constants.d.ts +1 -0
  1062. package/workflows/evented.d.ts +1 -0
  1063. package/workflows/legacy.d.ts +1 -0
  1064. package/workflows.d.ts +1 -0
@@ -0,0 +1,3203 @@
1
+ 'use strict';
2
+
3
+ var chunkIAJHRFO4_cjs = require('./chunk-IAJHRFO4.cjs');
4
+ var chunk5NTO7S5I_cjs = require('./chunk-5NTO7S5I.cjs');
5
+ var providerUtilsV5 = require('@ai-sdk/provider-utils-v5');
6
+ var crypto = require('crypto');
7
+ var AIV4 = require('ai');
8
+ var AIV5 = require('ai-v5');
9
+ var providerUtils = require('@ai-sdk/provider-utils');
10
+ var zod = require('zod');
11
+
12
+ function _interopNamespace(e) {
13
+ if (e && e.__esModule) return e;
14
+ var n = Object.create(null);
15
+ if (e) {
16
+ Object.keys(e).forEach(function (k) {
17
+ if (k !== 'default') {
18
+ var d = Object.getOwnPropertyDescriptor(e, k);
19
+ Object.defineProperty(n, k, d.get ? d : {
20
+ enumerable: true,
21
+ get: function () { return e[k]; }
22
+ });
23
+ }
24
+ });
25
+ }
26
+ n.default = e;
27
+ return Object.freeze(n);
28
+ }
29
+
30
+ var AIV4__namespace = /*#__PURE__*/_interopNamespace(AIV4);
31
+ var AIV5__namespace = /*#__PURE__*/_interopNamespace(AIV5);
32
+
33
+ var DefaultGeneratedFile = class {
34
+ base64Data;
35
+ uint8ArrayData;
36
+ mediaType;
37
+ constructor({ data, mediaType }) {
38
+ const isUint8Array = data instanceof Uint8Array;
39
+ this.base64Data = isUint8Array ? void 0 : data;
40
+ this.uint8ArrayData = isUint8Array ? data : void 0;
41
+ this.mediaType = mediaType;
42
+ }
43
+ // lazy conversion with caching to avoid unnecessary conversion overhead:
44
+ get base64() {
45
+ if (this.base64Data == null) {
46
+ this.base64Data = providerUtilsV5.convertUint8ArrayToBase64(this.uint8ArrayData);
47
+ }
48
+ return this.base64Data;
49
+ }
50
+ // lazy conversion with caching to avoid unnecessary conversion overhead:
51
+ get uint8Array() {
52
+ if (this.uint8ArrayData == null) {
53
+ this.uint8ArrayData = providerUtilsV5.convertBase64ToUint8Array(this.base64Data);
54
+ }
55
+ return this.uint8ArrayData;
56
+ }
57
+ };
58
+ var DefaultGeneratedFileWithType = class extends DefaultGeneratedFile {
59
+ type = "file";
60
+ constructor(options) {
61
+ super(options);
62
+ }
63
+ };
64
+
65
+ // src/stream/aisdk/v5/compat/content.ts
66
+ function splitDataUrl(dataUrl) {
67
+ try {
68
+ const [header, base64Content] = dataUrl.split(",");
69
+ return {
70
+ mediaType: header?.split(";")[0]?.split(":")[1],
71
+ base64Content
72
+ };
73
+ } catch {
74
+ return {
75
+ mediaType: void 0,
76
+ base64Content: void 0
77
+ };
78
+ }
79
+ }
80
+ function convertToDataContent(content) {
81
+ if (content instanceof Uint8Array) {
82
+ return { data: content, mediaType: void 0 };
83
+ }
84
+ if (content instanceof ArrayBuffer) {
85
+ return { data: new Uint8Array(content), mediaType: void 0 };
86
+ }
87
+ if (typeof content === "string") {
88
+ try {
89
+ content = new URL(content);
90
+ } catch {
91
+ }
92
+ }
93
+ if (content instanceof URL && content.protocol === "data:") {
94
+ const { mediaType: dataUrlMediaType, base64Content } = splitDataUrl(content.toString());
95
+ if (dataUrlMediaType == null || base64Content == null) {
96
+ throw new chunk5NTO7S5I_cjs.MastraError({
97
+ id: "INVALID_DATA_URL_FORMAT",
98
+ text: `Invalid data URL format in content ${content.toString()}`,
99
+ domain: "LLM" /* LLM */,
100
+ category: "USER" /* USER */
101
+ });
102
+ }
103
+ return { data: base64Content, mediaType: dataUrlMediaType };
104
+ }
105
+ return { data: content, mediaType: void 0 };
106
+ }
107
+ var imageMediaTypeSignatures = [
108
+ {
109
+ mediaType: "image/gif",
110
+ bytesPrefix: [71, 73, 70],
111
+ base64Prefix: "R0lG"
112
+ },
113
+ {
114
+ mediaType: "image/png",
115
+ bytesPrefix: [137, 80, 78, 71],
116
+ base64Prefix: "iVBORw"
117
+ },
118
+ {
119
+ mediaType: "image/jpeg",
120
+ bytesPrefix: [255, 216],
121
+ base64Prefix: "/9j/"
122
+ },
123
+ {
124
+ mediaType: "image/webp",
125
+ bytesPrefix: [82, 73, 70, 70],
126
+ base64Prefix: "UklGRg"
127
+ },
128
+ {
129
+ mediaType: "image/bmp",
130
+ bytesPrefix: [66, 77],
131
+ base64Prefix: "Qk"
132
+ },
133
+ {
134
+ mediaType: "image/tiff",
135
+ bytesPrefix: [73, 73, 42, 0],
136
+ base64Prefix: "SUkqAA"
137
+ },
138
+ {
139
+ mediaType: "image/tiff",
140
+ bytesPrefix: [77, 77, 0, 42],
141
+ base64Prefix: "TU0AKg"
142
+ },
143
+ {
144
+ mediaType: "image/avif",
145
+ bytesPrefix: [0, 0, 0, 32, 102, 116, 121, 112, 97, 118, 105, 102],
146
+ base64Prefix: "AAAAIGZ0eXBhdmlm"
147
+ },
148
+ {
149
+ mediaType: "image/heic",
150
+ bytesPrefix: [0, 0, 0, 32, 102, 116, 121, 112, 104, 101, 105, 99],
151
+ base64Prefix: "AAAAIGZ0eXBoZWlj"
152
+ }
153
+ ];
154
+ var stripID3 = (data) => {
155
+ const bytes = typeof data === "string" ? providerUtilsV5.convertBase64ToUint8Array(data) : data;
156
+ const id3Size = (
157
+ // @ts-ignore
158
+ (bytes[6] & 127) << 21 | // @ts-ignore
159
+ (bytes[7] & 127) << 14 | // @ts-ignore
160
+ (bytes[8] & 127) << 7 | // @ts-ignore
161
+ bytes[9] & 127
162
+ );
163
+ return bytes.slice(id3Size + 10);
164
+ };
165
+ function stripID3TagsIfPresent(data) {
166
+ const hasId3 = typeof data === "string" && data.startsWith("SUQz") || typeof data !== "string" && data.length > 10 && data[0] === 73 && // 'I'
167
+ data[1] === 68 && // 'D'
168
+ data[2] === 51;
169
+ return hasId3 ? stripID3(data) : data;
170
+ }
171
+ function detectMediaType({
172
+ data,
173
+ signatures
174
+ }) {
175
+ const processedData = stripID3TagsIfPresent(data);
176
+ for (const signature of signatures) {
177
+ if (typeof processedData === "string" ? processedData.startsWith(signature.base64Prefix) : processedData.length >= signature.bytesPrefix.length && signature.bytesPrefix.every((byte, index) => processedData[index] === byte)) {
178
+ return signature.mediaType;
179
+ }
180
+ }
181
+ return void 0;
182
+ }
183
+
184
+ // src/agent/message-list/prompt/convert-file.ts
185
+ function convertImageFilePart(part, downloadedAssets) {
186
+ let originalData;
187
+ const type = part.type;
188
+ switch (type) {
189
+ case "image":
190
+ originalData = part.image;
191
+ break;
192
+ case "file":
193
+ originalData = part.data;
194
+ break;
195
+ default:
196
+ throw new Error(`Unsupported part type: ${type}`);
197
+ }
198
+ const { data: convertedData, mediaType: convertedMediaType } = convertToDataContent(originalData);
199
+ let mediaType = convertedMediaType ?? part.mediaType;
200
+ let data = convertedData;
201
+ if (data instanceof URL && downloadedAssets) {
202
+ const downloadedFile = downloadedAssets[data.toString()];
203
+ if (downloadedFile) {
204
+ data = downloadedFile.data;
205
+ mediaType ??= downloadedFile.mediaType;
206
+ }
207
+ }
208
+ switch (type) {
209
+ case "image": {
210
+ if (data instanceof Uint8Array || typeof data === "string") {
211
+ mediaType = detectMediaType({ data, signatures: imageMediaTypeSignatures }) ?? mediaType;
212
+ }
213
+ return {
214
+ type: "file",
215
+ mediaType: mediaType ?? "image/*",
216
+ // any image
217
+ filename: void 0,
218
+ data,
219
+ providerOptions: part.providerOptions
220
+ };
221
+ }
222
+ case "file": {
223
+ if (mediaType == null) {
224
+ throw new Error(`Media type is missing for file part`);
225
+ }
226
+ return {
227
+ type: "file",
228
+ mediaType,
229
+ filename: part.filename,
230
+ data,
231
+ providerOptions: part.providerOptions
232
+ };
233
+ }
234
+ }
235
+ }
236
+ zod.z.union([
237
+ zod.z.string(),
238
+ zod.z.instanceof(Uint8Array),
239
+ zod.z.instanceof(ArrayBuffer),
240
+ zod.z.custom(
241
+ // Buffer might not be available in some environments such as CloudFlare:
242
+ (value) => globalThis.Buffer?.isBuffer(value) ?? false,
243
+ { message: "Must be a Buffer" }
244
+ )
245
+ ]);
246
+ function convertDataContentToBase64String(content) {
247
+ if (typeof content === "string") {
248
+ return content;
249
+ }
250
+ if (content instanceof ArrayBuffer) {
251
+ return providerUtils.convertUint8ArrayToBase64(new Uint8Array(content));
252
+ }
253
+ return providerUtils.convertUint8ArrayToBase64(content);
254
+ }
255
+
256
+ // src/agent/message-list/prompt/image-utils.ts
257
+ function parseDataUri(dataUri) {
258
+ if (!dataUri.startsWith("data:")) {
259
+ return {
260
+ isDataUri: false,
261
+ base64Content: dataUri
262
+ };
263
+ }
264
+ const base64Index = dataUri.indexOf(",");
265
+ if (base64Index === -1) {
266
+ return {
267
+ isDataUri: true,
268
+ base64Content: dataUri
269
+ };
270
+ }
271
+ const header = dataUri.substring(5, base64Index);
272
+ const base64Content = dataUri.substring(base64Index + 1);
273
+ const semicolonIndex = header.indexOf(";");
274
+ const mimeType = semicolonIndex !== -1 ? header.substring(0, semicolonIndex) : header;
275
+ return {
276
+ isDataUri: true,
277
+ mimeType: mimeType || void 0,
278
+ base64Content
279
+ };
280
+ }
281
+ function createDataUri(base64Content, mimeType = "application/octet-stream") {
282
+ if (base64Content.startsWith("data:")) {
283
+ return base64Content;
284
+ }
285
+ return `data:${mimeType};base64,${base64Content}`;
286
+ }
287
+ function imageContentToString(image, fallbackMimeType) {
288
+ if (typeof image === "string") {
289
+ return image;
290
+ }
291
+ if (image instanceof URL) {
292
+ return image.toString();
293
+ }
294
+ if (image instanceof Uint8Array || image instanceof ArrayBuffer || globalThis.Buffer && Buffer.isBuffer(image)) {
295
+ const base64 = convertDataContentToBase64String(image);
296
+ if (fallbackMimeType && !base64.startsWith("data:")) {
297
+ return `data:${fallbackMimeType};base64,${base64}`;
298
+ }
299
+ return base64;
300
+ }
301
+ return String(image);
302
+ }
303
+ function imageContentToDataUri(image, mimeType = "image/png") {
304
+ const imageStr = imageContentToString(image, mimeType);
305
+ if (imageStr.startsWith("data:")) {
306
+ return imageStr;
307
+ }
308
+ if (imageStr.startsWith("http://") || imageStr.startsWith("https://")) {
309
+ return imageStr;
310
+ }
311
+ return `data:${mimeType};base64,${imageStr}`;
312
+ }
313
+ function getImageCacheKey(image) {
314
+ if (image instanceof URL) {
315
+ return image.toString();
316
+ }
317
+ if (typeof image === "string") {
318
+ return image.length;
319
+ }
320
+ if (image instanceof Uint8Array) {
321
+ return image.byteLength;
322
+ }
323
+ if (image instanceof ArrayBuffer) {
324
+ return image.byteLength;
325
+ }
326
+ return image;
327
+ }
328
+ function isValidUrl(str) {
329
+ try {
330
+ new URL(str);
331
+ return true;
332
+ } catch {
333
+ if (str.startsWith("//")) {
334
+ try {
335
+ new URL(`https:${str}`);
336
+ return true;
337
+ } catch {
338
+ return false;
339
+ }
340
+ }
341
+ return false;
342
+ }
343
+ }
344
+ function categorizeFileData(data, fallbackMimeType) {
345
+ const parsed = parseDataUri(data);
346
+ const mimeType = parsed.isDataUri && parsed.mimeType ? parsed.mimeType : fallbackMimeType;
347
+ if (parsed.isDataUri) {
348
+ return {
349
+ type: "dataUri",
350
+ mimeType,
351
+ data
352
+ };
353
+ }
354
+ if (isValidUrl(data)) {
355
+ return {
356
+ type: "url",
357
+ mimeType,
358
+ data
359
+ };
360
+ }
361
+ return {
362
+ type: "raw",
363
+ mimeType,
364
+ data
365
+ };
366
+ }
367
+
368
+ // src/agent/message-list/prompt/attachments-to-parts.ts
369
+ function attachmentsToParts(attachments) {
370
+ const parts = [];
371
+ for (const attachment of attachments) {
372
+ const categorized = categorizeFileData(attachment.url, attachment.contentType);
373
+ let urlString = attachment.url;
374
+ if (categorized.type === "raw") {
375
+ urlString = createDataUri(attachment.url, attachment.contentType || "application/octet-stream");
376
+ }
377
+ let url;
378
+ try {
379
+ url = new URL(urlString);
380
+ } catch {
381
+ throw new Error(`Invalid URL: ${attachment.url}`);
382
+ }
383
+ switch (url.protocol) {
384
+ case "http:":
385
+ case "https:": {
386
+ if (attachment.contentType?.startsWith("image/")) {
387
+ parts.push({ type: "image", image: url.toString(), mimeType: attachment.contentType });
388
+ } else {
389
+ if (!attachment.contentType) {
390
+ throw new Error("If the attachment is not an image, it must specify a content type");
391
+ }
392
+ parts.push({
393
+ type: "file",
394
+ data: url.toString(),
395
+ mimeType: attachment.contentType
396
+ });
397
+ }
398
+ break;
399
+ }
400
+ case "data:": {
401
+ if (attachment.contentType?.startsWith("image/")) {
402
+ parts.push({
403
+ type: "image",
404
+ image: urlString,
405
+ mimeType: attachment.contentType
406
+ });
407
+ } else if (attachment.contentType?.startsWith("text/")) {
408
+ parts.push({
409
+ type: "file",
410
+ data: urlString,
411
+ mimeType: attachment.contentType
412
+ });
413
+ } else {
414
+ if (!attachment.contentType) {
415
+ throw new Error("If the attachment is not an image or text, it must specify a content type");
416
+ }
417
+ parts.push({
418
+ type: "file",
419
+ data: urlString,
420
+ mimeType: attachment.contentType
421
+ });
422
+ }
423
+ break;
424
+ }
425
+ default: {
426
+ throw new Error(`Unsupported URL protocol: ${url.protocol}`);
427
+ }
428
+ }
429
+ }
430
+ return parts;
431
+ }
432
+
433
+ // src/agent/message-list/prompt/convert-to-mastra-v1.ts
434
+ var makePushOrCombine = (v1Messages) => {
435
+ const idUsageCount = /* @__PURE__ */ new Map();
436
+ const SPLIT_SUFFIX_PATTERN = /__split-\d+$/;
437
+ return (msg) => {
438
+ const previousMessage = v1Messages.at(-1);
439
+ if (msg.role === previousMessage?.role && Array.isArray(previousMessage.content) && Array.isArray(msg.content) && // we were creating new messages for tool calls before and not appending to the assistant message
440
+ // so don't append here so everything works as before
441
+ (msg.role !== `assistant` || msg.role === `assistant` && msg.content.at(-1)?.type !== `tool-call`)) {
442
+ for (const part of msg.content) {
443
+ previousMessage.content.push(part);
444
+ }
445
+ } else {
446
+ let baseId = msg.id;
447
+ const hasSplitSuffix = SPLIT_SUFFIX_PATTERN.test(baseId);
448
+ if (hasSplitSuffix) {
449
+ v1Messages.push(msg);
450
+ return;
451
+ }
452
+ const currentCount = idUsageCount.get(baseId) || 0;
453
+ if (currentCount > 0) {
454
+ msg.id = `${baseId}__split-${currentCount}`;
455
+ }
456
+ idUsageCount.set(baseId, currentCount + 1);
457
+ v1Messages.push(msg);
458
+ }
459
+ };
460
+ };
461
+ function convertToV1Messages(messages) {
462
+ const v1Messages = [];
463
+ const pushOrCombine = makePushOrCombine(v1Messages);
464
+ for (let i = 0; i < messages.length; i++) {
465
+ const message = messages[i];
466
+ const isLastMessage = i === messages.length - 1;
467
+ if (!message?.content) continue;
468
+ const { content, experimental_attachments: inputAttachments = [], parts: inputParts } = message.content;
469
+ const { role } = message;
470
+ const fields = {
471
+ id: message.id,
472
+ createdAt: message.createdAt,
473
+ resourceId: message.resourceId,
474
+ threadId: message.threadId
475
+ };
476
+ const experimental_attachments = [...inputAttachments];
477
+ const parts = [];
478
+ for (const part of inputParts) {
479
+ if (part.type === "file") {
480
+ experimental_attachments.push({
481
+ url: part.data,
482
+ contentType: part.mimeType
483
+ });
484
+ } else {
485
+ parts.push(part);
486
+ }
487
+ }
488
+ switch (role) {
489
+ case "user": {
490
+ if (parts == null) {
491
+ const userContent = experimental_attachments ? [{ type: "text", text: content || "" }, ...attachmentsToParts(experimental_attachments)] : { type: "text", text: content || "" };
492
+ pushOrCombine({
493
+ role: "user",
494
+ ...fields,
495
+ type: "text",
496
+ // @ts-ignore
497
+ content: userContent
498
+ });
499
+ } else {
500
+ const textParts = message.content.parts.filter((part) => part.type === "text").map((part) => ({
501
+ type: "text",
502
+ text: part.text
503
+ }));
504
+ const userContent = experimental_attachments ? [...textParts, ...attachmentsToParts(experimental_attachments)] : textParts;
505
+ pushOrCombine({
506
+ role: "user",
507
+ ...fields,
508
+ type: "text",
509
+ content: Array.isArray(userContent) && userContent.length === 1 && userContent[0]?.type === `text` && typeof content !== `undefined` ? content : userContent
510
+ });
511
+ }
512
+ break;
513
+ }
514
+ case "assistant": {
515
+ if (message.content.parts != null) {
516
+ let processBlock2 = function() {
517
+ const content2 = [];
518
+ for (const part of block) {
519
+ switch (part.type) {
520
+ case "file":
521
+ case "text": {
522
+ content2.push(part);
523
+ break;
524
+ }
525
+ case "reasoning": {
526
+ for (const detail of part.details) {
527
+ switch (detail.type) {
528
+ case "text":
529
+ content2.push({
530
+ type: "reasoning",
531
+ text: detail.text,
532
+ signature: detail.signature
533
+ });
534
+ break;
535
+ case "redacted":
536
+ content2.push({
537
+ type: "redacted-reasoning",
538
+ data: detail.data
539
+ });
540
+ break;
541
+ }
542
+ }
543
+ break;
544
+ }
545
+ case "tool-invocation":
546
+ if (part.toolInvocation.toolName !== "updateWorkingMemory") {
547
+ content2.push({
548
+ type: "tool-call",
549
+ toolCallId: part.toolInvocation.toolCallId,
550
+ toolName: part.toolInvocation.toolName,
551
+ args: part.toolInvocation.args
552
+ });
553
+ }
554
+ break;
555
+ }
556
+ }
557
+ pushOrCombine({
558
+ role: "assistant",
559
+ ...fields,
560
+ type: content2.some((c) => c.type === `tool-call`) ? "tool-call" : "text",
561
+ content: typeof content2 !== `string` && Array.isArray(content2) && content2.length === 1 && content2[0]?.type === `text` ? content2[0].text : content2
562
+ });
563
+ const stepInvocations = block.filter((part) => `type` in part && part.type === "tool-invocation").map((part) => part.toolInvocation).filter((ti) => ti.toolName !== "updateWorkingMemory");
564
+ const invocationsWithResults = stepInvocations.filter((ti) => ti.state === "result" && "result" in ti);
565
+ if (invocationsWithResults.length > 0) {
566
+ pushOrCombine({
567
+ role: "tool",
568
+ ...fields,
569
+ type: "tool-result",
570
+ content: invocationsWithResults.map((toolInvocation) => {
571
+ const { toolCallId, toolName, result } = toolInvocation;
572
+ return {
573
+ type: "tool-result",
574
+ toolCallId,
575
+ toolName,
576
+ result
577
+ };
578
+ })
579
+ });
580
+ }
581
+ block = [];
582
+ blockHasToolInvocations = false;
583
+ currentStep++;
584
+ };
585
+ let currentStep = 0;
586
+ let blockHasToolInvocations = false;
587
+ let block = [];
588
+ for (const part of message.content.parts) {
589
+ switch (part.type) {
590
+ case "text": {
591
+ if (blockHasToolInvocations) {
592
+ processBlock2();
593
+ }
594
+ block.push(part);
595
+ break;
596
+ }
597
+ case "file":
598
+ case "reasoning": {
599
+ block.push(part);
600
+ break;
601
+ }
602
+ case "tool-invocation": {
603
+ const hasNonToolContent = block.some(
604
+ (p) => p.type === "text" || p.type === "file" || p.type === "reasoning"
605
+ );
606
+ if (hasNonToolContent || (part.toolInvocation.step ?? 0) !== currentStep) {
607
+ processBlock2();
608
+ }
609
+ block.push(part);
610
+ blockHasToolInvocations = true;
611
+ break;
612
+ }
613
+ }
614
+ }
615
+ processBlock2();
616
+ const toolInvocations2 = message.content.toolInvocations;
617
+ if (toolInvocations2 && toolInvocations2.length > 0) {
618
+ const processedToolCallIds = /* @__PURE__ */ new Set();
619
+ for (const part of message.content.parts) {
620
+ if (part.type === "tool-invocation" && part.toolInvocation.toolCallId) {
621
+ processedToolCallIds.add(part.toolInvocation.toolCallId);
622
+ }
623
+ }
624
+ const unprocessedToolInvocations = toolInvocations2.filter(
625
+ (ti) => !processedToolCallIds.has(ti.toolCallId) && ti.toolName !== "updateWorkingMemory"
626
+ );
627
+ if (unprocessedToolInvocations.length > 0) {
628
+ const invocationsByStep = /* @__PURE__ */ new Map();
629
+ for (const inv of unprocessedToolInvocations) {
630
+ const step = inv.step ?? 0;
631
+ if (!invocationsByStep.has(step)) {
632
+ invocationsByStep.set(step, []);
633
+ }
634
+ invocationsByStep.get(step).push(inv);
635
+ }
636
+ const sortedSteps = Array.from(invocationsByStep.keys()).sort((a, b) => a - b);
637
+ for (const step of sortedSteps) {
638
+ const stepInvocations = invocationsByStep.get(step);
639
+ pushOrCombine({
640
+ role: "assistant",
641
+ ...fields,
642
+ type: "tool-call",
643
+ content: [
644
+ ...stepInvocations.map(({ toolCallId, toolName, args }) => ({
645
+ type: "tool-call",
646
+ toolCallId,
647
+ toolName,
648
+ args
649
+ }))
650
+ ]
651
+ });
652
+ const invocationsWithResults = stepInvocations.filter((ti) => ti.state === "result" && "result" in ti);
653
+ if (invocationsWithResults.length > 0) {
654
+ pushOrCombine({
655
+ role: "tool",
656
+ ...fields,
657
+ type: "tool-result",
658
+ content: invocationsWithResults.map((toolInvocation) => {
659
+ const { toolCallId, toolName, result } = toolInvocation;
660
+ return {
661
+ type: "tool-result",
662
+ toolCallId,
663
+ toolName,
664
+ result
665
+ };
666
+ })
667
+ });
668
+ }
669
+ }
670
+ }
671
+ }
672
+ break;
673
+ }
674
+ const toolInvocations = message.content.toolInvocations;
675
+ if (toolInvocations == null || toolInvocations.length === 0) {
676
+ pushOrCombine({ role: "assistant", ...fields, content: content || "", type: "text" });
677
+ break;
678
+ }
679
+ const maxStep = toolInvocations.reduce((max, toolInvocation) => {
680
+ return Math.max(max, toolInvocation.step ?? 0);
681
+ }, 0);
682
+ for (let i2 = 0; i2 <= maxStep; i2++) {
683
+ const stepInvocations = toolInvocations.filter(
684
+ (toolInvocation) => (toolInvocation.step ?? 0) === i2 && toolInvocation.toolName !== "updateWorkingMemory"
685
+ );
686
+ if (stepInvocations.length === 0) {
687
+ continue;
688
+ }
689
+ pushOrCombine({
690
+ role: "assistant",
691
+ ...fields,
692
+ type: "tool-call",
693
+ content: [
694
+ ...isLastMessage && content && i2 === 0 ? [{ type: "text", text: content }] : [],
695
+ ...stepInvocations.map(({ toolCallId, toolName, args }) => ({
696
+ type: "tool-call",
697
+ toolCallId,
698
+ toolName,
699
+ args
700
+ }))
701
+ ]
702
+ });
703
+ const invocationsWithResults = stepInvocations.filter((ti) => ti.state === "result" && "result" in ti);
704
+ if (invocationsWithResults.length > 0) {
705
+ pushOrCombine({
706
+ role: "tool",
707
+ ...fields,
708
+ type: "tool-result",
709
+ content: invocationsWithResults.map((toolInvocation) => {
710
+ const { toolCallId, toolName, result } = toolInvocation;
711
+ return {
712
+ type: "tool-result",
713
+ toolCallId,
714
+ toolName,
715
+ result
716
+ };
717
+ })
718
+ });
719
+ }
720
+ }
721
+ if (content && !isLastMessage) {
722
+ pushOrCombine({ role: "assistant", ...fields, type: "text", content: content || "" });
723
+ }
724
+ break;
725
+ }
726
+ }
727
+ }
728
+ return v1Messages;
729
+ }
730
+ var downloadFromUrl = async ({ url, downloadRetries }) => {
731
+ const urlText = url.toString();
732
+ try {
733
+ const response = await chunkIAJHRFO4_cjs.fetchWithRetry(
734
+ urlText,
735
+ {
736
+ method: "GET"
737
+ },
738
+ downloadRetries
739
+ );
740
+ if (!response.ok) {
741
+ throw new chunk5NTO7S5I_cjs.MastraError({
742
+ id: "DOWNLOAD_ASSETS_FAILED",
743
+ text: "Failed to download asset",
744
+ domain: "LLM" /* LLM */,
745
+ category: "USER" /* USER */
746
+ });
747
+ }
748
+ return {
749
+ data: new Uint8Array(await response.arrayBuffer()),
750
+ mediaType: response.headers.get("content-type") ?? void 0
751
+ };
752
+ } catch (error) {
753
+ throw new chunk5NTO7S5I_cjs.MastraError(
754
+ {
755
+ id: "DOWNLOAD_ASSETS_FAILED",
756
+ text: "Failed to download asset",
757
+ domain: "LLM" /* LLM */,
758
+ category: "USER" /* USER */
759
+ },
760
+ error
761
+ );
762
+ }
763
+ };
764
+ async function downloadAssetsFromMessages({
765
+ messages,
766
+ downloadConcurrency = 10,
767
+ downloadRetries = 3,
768
+ supportedUrls
769
+ }) {
770
+ const pMap = (await import('p-map')).default;
771
+ const filesToDownload = messages.filter((message) => message.role === "user").map((message) => message.content).filter((content) => Array.isArray(content)).flat().filter((part) => part.type === "image" || part.type === "file").map((part) => {
772
+ const mediaType = part.mediaType ?? (part.type === "image" ? "image/*" : void 0);
773
+ let data = part.type === "image" ? part.image : part.data;
774
+ if (typeof data === "string") {
775
+ try {
776
+ data = new URL(data);
777
+ } catch {
778
+ }
779
+ }
780
+ return { mediaType, data };
781
+ }).filter((part) => part.data instanceof URL).map((part) => {
782
+ return {
783
+ url: part.data,
784
+ isUrlSupportedByModel: part.mediaType != null && providerUtilsV5.isUrlSupported({
785
+ url: part.data.toString(),
786
+ mediaType: part.mediaType,
787
+ supportedUrls: supportedUrls ?? {}
788
+ })
789
+ };
790
+ });
791
+ const downloadedFiles = await pMap(
792
+ filesToDownload,
793
+ async (fileItem) => {
794
+ if (fileItem.isUrlSupportedByModel) {
795
+ return null;
796
+ }
797
+ return {
798
+ url: fileItem.url.toString(),
799
+ ...await downloadFromUrl({ url: fileItem.url, downloadRetries })
800
+ };
801
+ },
802
+ {
803
+ concurrency: downloadConcurrency
804
+ }
805
+ );
806
+ const downloadFileList = downloadedFiles.filter(
807
+ (downloadedFile) => downloadedFile?.data != null
808
+ ).map(({ url, data, mediaType }) => [url, { data, mediaType }]);
809
+ return Object.fromEntries(downloadFileList);
810
+ }
811
+
812
+ // src/agent/message-list/utils/ai-v5/gemini-compatibility.ts
813
+ function ensureGeminiCompatibleMessages(messages) {
814
+ const result = [...messages];
815
+ const firstNonSystemIndex = result.findIndex((m) => m.role !== "system");
816
+ if (firstNonSystemIndex === -1) {
817
+ throw new chunk5NTO7S5I_cjs.MastraError({
818
+ id: "NO_USER_OR_ASSISTANT_MESSAGES",
819
+ domain: "AGENT" /* AGENT */,
820
+ category: "USER" /* USER */,
821
+ text: "This request does not contain any user or assistant messages. At least one user or assistant message is required to generate a response."
822
+ });
823
+ } else if (result[firstNonSystemIndex]?.role === "assistant") {
824
+ result.splice(firstNonSystemIndex, 0, {
825
+ role: "user",
826
+ content: "."
827
+ });
828
+ }
829
+ return result;
830
+ }
831
+
832
+ // src/agent/message-list/utils/ai-v5/tool.ts
833
+ function getToolName(type) {
834
+ if (typeof type === "object" && type && "type" in type) {
835
+ type = type.type;
836
+ }
837
+ if (typeof type !== "string") {
838
+ return "unknown";
839
+ }
840
+ if (type === "dynamic-tool") {
841
+ return "dynamic-tool";
842
+ }
843
+ if (type.startsWith("tool-")) {
844
+ return type.slice("tool-".length);
845
+ }
846
+ return type;
847
+ }
848
+
849
+ // src/agent/message-list/index.ts
850
+ var MessageList = class _MessageList {
851
+ messages = [];
852
+ // passed in by dev in input or context
853
+ systemMessages = [];
854
+ // passed in by us for a specific purpose, eg memory system message
855
+ taggedSystemMessages = {};
856
+ memoryInfo = null;
857
+ // used to filter this.messages by how it was added: input/response/memory
858
+ memoryMessages = /* @__PURE__ */ new Set();
859
+ newUserMessages = /* @__PURE__ */ new Set();
860
+ newResponseMessages = /* @__PURE__ */ new Set();
861
+ userContextMessages = /* @__PURE__ */ new Set();
862
+ memoryMessagesPersisted = /* @__PURE__ */ new Set();
863
+ newUserMessagesPersisted = /* @__PURE__ */ new Set();
864
+ newResponseMessagesPersisted = /* @__PURE__ */ new Set();
865
+ userContextMessagesPersisted = /* @__PURE__ */ new Set();
866
+ generateMessageId;
867
+ _agentNetworkAppend = false;
868
+ constructor({
869
+ threadId,
870
+ resourceId,
871
+ generateMessageId,
872
+ // @ts-ignore Flag for agent network messages
873
+ _agentNetworkAppend
874
+ } = {}) {
875
+ if (threadId) {
876
+ this.memoryInfo = { threadId, resourceId };
877
+ }
878
+ this.generateMessageId = generateMessageId;
879
+ this._agentNetworkAppend = _agentNetworkAppend || false;
880
+ }
881
+ add(messages, messageSource) {
882
+ if (messageSource === `user`) messageSource = `input`;
883
+ if (!messages) return this;
884
+ for (const message of Array.isArray(messages) ? messages : [messages]) {
885
+ this.addOne(
886
+ typeof message === `string` ? {
887
+ role: "user",
888
+ content: message
889
+ } : message,
890
+ messageSource
891
+ );
892
+ }
893
+ return this;
894
+ }
895
+ serializeSet(set) {
896
+ return Array.from(set).map((value) => value.id);
897
+ }
898
+ deserializeSet(ids) {
899
+ return new Set(ids.map((id) => this.messages.find((m) => m.id === id)).filter(Boolean));
900
+ }
901
+ serializeMessage(message) {
902
+ return {
903
+ ...message,
904
+ createdAt: message.createdAt.toUTCString()
905
+ };
906
+ }
907
+ deserializeMessage(state) {
908
+ return {
909
+ ...state,
910
+ createdAt: new Date(state.createdAt)
911
+ };
912
+ }
913
+ serialize() {
914
+ return {
915
+ messages: this.messages.map(this.serializeMessage),
916
+ systemMessages: this.systemMessages,
917
+ taggedSystemMessages: this.taggedSystemMessages,
918
+ memoryInfo: this.memoryInfo,
919
+ _agentNetworkAppend: this._agentNetworkAppend,
920
+ memoryMessages: this.serializeSet(this.memoryMessages),
921
+ newUserMessages: this.serializeSet(this.newUserMessages),
922
+ newResponseMessages: this.serializeSet(this.newResponseMessages),
923
+ userContextMessages: this.serializeSet(this.userContextMessages),
924
+ memoryMessagesPersisted: this.serializeSet(this.memoryMessagesPersisted),
925
+ newUserMessagesPersisted: this.serializeSet(this.newUserMessagesPersisted),
926
+ newResponseMessagesPersisted: this.serializeSet(this.newResponseMessagesPersisted),
927
+ userContextMessagesPersisted: this.serializeSet(this.userContextMessagesPersisted)
928
+ };
929
+ }
930
+ deserialize(state) {
931
+ this.messages = state.messages.map(this.deserializeMessage);
932
+ this.systemMessages = state.systemMessages;
933
+ this.taggedSystemMessages = state.taggedSystemMessages;
934
+ this.memoryInfo = state.memoryInfo;
935
+ this._agentNetworkAppend = state._agentNetworkAppend;
936
+ this.memoryMessages = this.deserializeSet(state.memoryMessages);
937
+ this.newUserMessages = this.deserializeSet(state.newUserMessages);
938
+ this.newResponseMessages = this.deserializeSet(state.newResponseMessages);
939
+ this.userContextMessages = this.deserializeSet(state.userContextMessages);
940
+ this.memoryMessagesPersisted = this.deserializeSet(state.memoryMessagesPersisted);
941
+ this.newUserMessagesPersisted = this.deserializeSet(state.newUserMessagesPersisted);
942
+ this.newResponseMessagesPersisted = this.deserializeSet(state.newResponseMessagesPersisted);
943
+ this.userContextMessagesPersisted = this.deserializeSet(state.userContextMessagesPersisted);
944
+ return this;
945
+ }
946
+ getLatestUserContent() {
947
+ const currentUserMessages = this.all.core().filter((m) => m.role === "user");
948
+ const content = currentUserMessages.at(-1)?.content;
949
+ if (!content) return null;
950
+ return _MessageList.coreContentToString(content);
951
+ }
952
+ get get() {
953
+ return {
954
+ all: this.all,
955
+ remembered: this.remembered,
956
+ input: this.input,
957
+ response: this.response
958
+ };
959
+ }
960
+ get getPersisted() {
961
+ return {
962
+ remembered: this.rememberedPersisted,
963
+ input: this.inputPersisted,
964
+ taggedSystemMessages: this.taggedSystemMessages,
965
+ response: this.responsePersisted
966
+ };
967
+ }
968
+ get clear() {
969
+ return {
970
+ input: {
971
+ v2: () => {
972
+ const userMessages = Array.from(this.newUserMessages);
973
+ this.messages = this.messages.filter((m) => !this.newUserMessages.has(m));
974
+ this.newUserMessages.clear();
975
+ return userMessages;
976
+ }
977
+ },
978
+ response: {
979
+ v2: () => {
980
+ const responseMessages = Array.from(this.newResponseMessages);
981
+ this.messages = this.messages.filter((m) => !this.newResponseMessages.has(m));
982
+ this.newResponseMessages.clear();
983
+ return responseMessages;
984
+ }
985
+ }
986
+ };
987
+ }
988
+ all = {
989
+ v3: () => this.cleanV3Metadata(this.messages.map(this.mastraMessageV2ToMastraMessageV3)),
990
+ v2: () => this.messages,
991
+ v1: () => convertToV1Messages(this.all.v2()),
992
+ aiV5: {
993
+ model: () => this.aiV5UIMessagesToAIV5ModelMessages(this.all.aiV5.ui()),
994
+ ui: () => this.all.v3().map(_MessageList.mastraMessageV3ToAIV5UIMessage),
995
+ // Used when calling AI SDK streamText/generateText
996
+ prompt: () => {
997
+ const systemMessages = this.aiV4CoreMessagesToAIV5ModelMessages(
998
+ [...this.systemMessages, ...Object.values(this.taggedSystemMessages).flat()],
999
+ `system`
1000
+ );
1001
+ const modelMessages = this.all.aiV5.model();
1002
+ const messages = [...systemMessages, ...modelMessages];
1003
+ return ensureGeminiCompatibleMessages(messages);
1004
+ },
1005
+ // Used for creating LLM prompt messages without AI SDK streamText/generateText
1006
+ llmPrompt: async (options = {
1007
+ downloadConcurrency: 10,
1008
+ downloadRetries: 3
1009
+ }) => {
1010
+ const modelMessages = this.all.aiV5.model();
1011
+ const systemMessages = this.aiV4CoreMessagesToAIV5ModelMessages(
1012
+ [...this.systemMessages, ...Object.values(this.taggedSystemMessages).flat()],
1013
+ `system`
1014
+ );
1015
+ const downloadedAssets = await downloadAssetsFromMessages({
1016
+ messages: modelMessages,
1017
+ downloadConcurrency: options?.downloadConcurrency,
1018
+ downloadRetries: options?.downloadRetries,
1019
+ supportedUrls: options?.supportedUrls
1020
+ });
1021
+ let messages = [...systemMessages, ...modelMessages];
1022
+ const hasImageOrFileContent = modelMessages.some(
1023
+ (message) => message.role === "user" && typeof message.content !== "string" && message.content.some((part) => part.type === "image" || part.type === "file")
1024
+ );
1025
+ if (hasImageOrFileContent) {
1026
+ messages = messages.map((message) => {
1027
+ if (message.role === "user") {
1028
+ if (typeof message.content === "string") {
1029
+ return {
1030
+ role: "user",
1031
+ content: [{ type: "text", text: message.content }],
1032
+ providerOptions: message.providerOptions
1033
+ };
1034
+ }
1035
+ const convertedContent = message.content.map((part) => {
1036
+ if (part.type === "image" || part.type === "file") {
1037
+ return convertImageFilePart(part, downloadedAssets);
1038
+ }
1039
+ return part;
1040
+ }).filter((part) => part.type !== "text" || part.text !== "");
1041
+ return {
1042
+ role: "user",
1043
+ content: convertedContent,
1044
+ providerOptions: message.providerOptions
1045
+ };
1046
+ }
1047
+ return message;
1048
+ });
1049
+ }
1050
+ messages = ensureGeminiCompatibleMessages(messages);
1051
+ return messages.map(_MessageList.aiV5ModelMessageToV2PromptMessage);
1052
+ }
1053
+ },
1054
+ /* @deprecated use list.get.all.aiV4.prompt() instead */
1055
+ prompt: () => this.all.aiV4.prompt(),
1056
+ /* @deprecated use list.get.all.aiV4.ui() */
1057
+ ui: () => this.all.v2().map(_MessageList.mastraMessageV2ToAIV4UIMessage),
1058
+ /* @deprecated use list.get.all.aiV4.core() */
1059
+ core: () => this.aiV4UIMessagesToAIV4CoreMessages(this.all.aiV4.ui()),
1060
+ aiV4: {
1061
+ ui: () => this.all.v2().map(_MessageList.mastraMessageV2ToAIV4UIMessage),
1062
+ core: () => this.aiV4UIMessagesToAIV4CoreMessages(this.all.aiV4.ui()),
1063
+ // Used when calling AI SDK streamText/generateText
1064
+ prompt: () => {
1065
+ const coreMessages = this.all.aiV4.core();
1066
+ const messages = [...this.systemMessages, ...Object.values(this.taggedSystemMessages).flat(), ...coreMessages];
1067
+ return ensureGeminiCompatibleMessages(messages);
1068
+ },
1069
+ // Used for creating LLM prompt messages without AI SDK streamText/generateText
1070
+ llmPrompt: () => {
1071
+ const coreMessages = this.all.aiV4.core();
1072
+ const systemMessages = [...this.systemMessages, ...Object.values(this.taggedSystemMessages).flat()];
1073
+ let messages = [...systemMessages, ...coreMessages];
1074
+ messages = ensureGeminiCompatibleMessages(messages);
1075
+ return messages.map(_MessageList.aiV4CoreMessageToV1PromptMessage);
1076
+ }
1077
+ }
1078
+ };
1079
+ remembered = {
1080
+ v3: () => this.remembered.v2().map(this.mastraMessageV2ToMastraMessageV3),
1081
+ v2: () => this.messages.filter((m) => this.memoryMessages.has(m)),
1082
+ v1: () => convertToV1Messages(this.remembered.v2()),
1083
+ aiV5: {
1084
+ model: () => this.aiV5UIMessagesToAIV5ModelMessages(this.remembered.aiV5.ui()),
1085
+ ui: () => this.remembered.v3().map(_MessageList.mastraMessageV3ToAIV5UIMessage)
1086
+ },
1087
+ /* @deprecated use list.get.remembered.aiV4.ui() */
1088
+ ui: () => this.remembered.v2().map(_MessageList.mastraMessageV2ToAIV4UIMessage),
1089
+ /* @deprecated use list.get.remembered.aiV4.core() */
1090
+ core: () => this.aiV4UIMessagesToAIV4CoreMessages(this.all.aiV4.ui()),
1091
+ aiV4: {
1092
+ ui: () => this.remembered.v2().map(_MessageList.mastraMessageV2ToAIV4UIMessage),
1093
+ core: () => this.aiV4UIMessagesToAIV4CoreMessages(this.all.aiV4.ui())
1094
+ }
1095
+ };
1096
+ // TODO: need to update this for new .aiV4/5.x() pattern
1097
+ rememberedPersisted = {
1098
+ v2: () => this.all.v2().filter((m) => this.memoryMessagesPersisted.has(m)),
1099
+ v1: () => convertToV1Messages(this.rememberedPersisted.v2()),
1100
+ ui: () => this.rememberedPersisted.v2().map(_MessageList.mastraMessageV2ToAIV4UIMessage),
1101
+ core: () => this.aiV4UIMessagesToAIV4CoreMessages(this.rememberedPersisted.ui())
1102
+ };
1103
+ input = {
1104
+ v3: () => this.cleanV3Metadata(
1105
+ this.messages.filter((m) => this.newUserMessages.has(m)).map(this.mastraMessageV2ToMastraMessageV3)
1106
+ ),
1107
+ v2: () => this.messages.filter((m) => this.newUserMessages.has(m)),
1108
+ v1: () => convertToV1Messages(this.input.v2()),
1109
+ aiV5: {
1110
+ model: () => this.aiV5UIMessagesToAIV5ModelMessages(this.input.aiV5.ui()),
1111
+ ui: () => this.input.v3().map(_MessageList.mastraMessageV3ToAIV5UIMessage)
1112
+ },
1113
+ /* @deprecated use list.get.input.aiV4.ui() instead */
1114
+ ui: () => this.input.v2().map(_MessageList.mastraMessageV2ToAIV4UIMessage),
1115
+ /* @deprecated use list.get.core.aiV4.ui() instead */
1116
+ core: () => this.aiV4UIMessagesToAIV4CoreMessages(this.input.ui()),
1117
+ aiV4: {
1118
+ ui: () => this.input.v2().map(_MessageList.mastraMessageV2ToAIV4UIMessage),
1119
+ core: () => this.aiV4UIMessagesToAIV4CoreMessages(this.input.aiV4.ui())
1120
+ }
1121
+ };
1122
+ // TODO: need to update this for new .aiV4/5.x() pattern
1123
+ inputPersisted = {
1124
+ v3: () => this.cleanV3Metadata(
1125
+ this.messages.filter((m) => this.newUserMessagesPersisted.has(m)).map(this.mastraMessageV2ToMastraMessageV3)
1126
+ ),
1127
+ v2: () => this.messages.filter((m) => this.newUserMessagesPersisted.has(m)),
1128
+ v1: () => convertToV1Messages(this.inputPersisted.v2()),
1129
+ ui: () => this.inputPersisted.v2().map(_MessageList.mastraMessageV2ToAIV4UIMessage),
1130
+ core: () => this.aiV4UIMessagesToAIV4CoreMessages(this.inputPersisted.ui())
1131
+ };
1132
+ response = {
1133
+ v3: () => this.response.v2().map(this.mastraMessageV2ToMastraMessageV3),
1134
+ v2: () => this.messages.filter((m) => this.newResponseMessages.has(m)),
1135
+ v1: () => convertToV1Messages(this.response.v3().map(_MessageList.mastraMessageV3ToV2)),
1136
+ aiV5: {
1137
+ ui: () => this.response.v3().map(_MessageList.mastraMessageV3ToAIV5UIMessage),
1138
+ model: () => this.aiV5UIMessagesToAIV5ModelMessages(this.response.aiV5.ui()).filter(
1139
+ (m) => m.role === `tool` || m.role === `assistant`
1140
+ ),
1141
+ modelContent: (stepNumber) => {
1142
+ if (typeof stepNumber === "number") {
1143
+ const uiMessages = this.response.aiV5.ui();
1144
+ const uiMessagesParts = uiMessages.flatMap((item) => item.parts);
1145
+ const stepBoundaries = [];
1146
+ uiMessagesParts.forEach((part, index) => {
1147
+ if (part.type === "step-start") {
1148
+ stepBoundaries.push(index);
1149
+ }
1150
+ });
1151
+ if (stepNumber === -1) {
1152
+ const toolParts = uiMessagesParts.filter((p) => p.type?.startsWith("tool-"));
1153
+ const hasStepStart = stepBoundaries.length > 0;
1154
+ if (!hasStepStart && toolParts.length > 0) {
1155
+ const lastToolPart = toolParts[toolParts.length - 1];
1156
+ if (!lastToolPart) {
1157
+ return [];
1158
+ }
1159
+ const lastToolIndex = uiMessagesParts.indexOf(lastToolPart);
1160
+ const previousToolPart = toolParts[toolParts.length - 2];
1161
+ const previousToolIndex = previousToolPart ? uiMessagesParts.indexOf(previousToolPart) : -1;
1162
+ const startIndex2 = previousToolIndex + 1;
1163
+ const stepParts3 = uiMessagesParts.slice(startIndex2, lastToolIndex + 1);
1164
+ const stepUiMessages3 = [
1165
+ {
1166
+ id: "last-step",
1167
+ role: "assistant",
1168
+ parts: stepParts3
1169
+ }
1170
+ ];
1171
+ const modelMessages3 = AIV5__namespace.convertToModelMessages(this.sanitizeV5UIMessages(stepUiMessages3));
1172
+ return modelMessages3.flatMap(this.response.aiV5.stepContent);
1173
+ }
1174
+ const totalSteps = stepBoundaries.length + 1;
1175
+ if (totalSteps === 1 && !hasStepStart) {
1176
+ const stepUiMessages3 = [
1177
+ {
1178
+ id: "last-step",
1179
+ role: "assistant",
1180
+ parts: uiMessagesParts
1181
+ }
1182
+ ];
1183
+ const modelMessages3 = AIV5__namespace.convertToModelMessages(this.sanitizeV5UIMessages(stepUiMessages3));
1184
+ return modelMessages3.flatMap(this.response.aiV5.stepContent);
1185
+ }
1186
+ const lastStepStart = stepBoundaries[stepBoundaries.length - 1];
1187
+ if (lastStepStart === void 0) {
1188
+ return [];
1189
+ }
1190
+ const stepParts2 = uiMessagesParts.slice(lastStepStart + 1);
1191
+ if (stepParts2.length === 0) {
1192
+ return [];
1193
+ }
1194
+ const stepUiMessages2 = [
1195
+ {
1196
+ id: "last-step",
1197
+ role: "assistant",
1198
+ parts: stepParts2
1199
+ }
1200
+ ];
1201
+ const modelMessages2 = AIV5__namespace.convertToModelMessages(this.sanitizeV5UIMessages(stepUiMessages2));
1202
+ return modelMessages2.flatMap(this.response.aiV5.stepContent);
1203
+ }
1204
+ if (stepNumber === 1) {
1205
+ const firstStepStart = stepBoundaries[0] ?? uiMessagesParts.length;
1206
+ if (firstStepStart === 0) {
1207
+ return [];
1208
+ }
1209
+ const stepParts2 = uiMessagesParts.slice(0, firstStepStart);
1210
+ const stepUiMessages2 = [
1211
+ {
1212
+ id: "step-1",
1213
+ role: "assistant",
1214
+ parts: stepParts2
1215
+ }
1216
+ ];
1217
+ const modelMessages2 = AIV5__namespace.convertToModelMessages(this.sanitizeV5UIMessages(stepUiMessages2));
1218
+ return modelMessages2.flatMap(this.response.aiV5.stepContent);
1219
+ }
1220
+ const stepIndex = stepNumber - 2;
1221
+ if (stepIndex < 0 || stepIndex >= stepBoundaries.length) {
1222
+ return [];
1223
+ }
1224
+ const startIndex = (stepBoundaries[stepIndex] ?? 0) + 1;
1225
+ const endIndex = stepBoundaries[stepIndex + 1] ?? uiMessagesParts.length;
1226
+ if (startIndex >= endIndex) {
1227
+ return [];
1228
+ }
1229
+ const stepParts = uiMessagesParts.slice(startIndex, endIndex);
1230
+ const stepUiMessages = [
1231
+ {
1232
+ id: `step-${stepNumber}`,
1233
+ role: "assistant",
1234
+ parts: stepParts
1235
+ }
1236
+ ];
1237
+ const modelMessages = AIV5__namespace.convertToModelMessages(this.sanitizeV5UIMessages(stepUiMessages));
1238
+ return modelMessages.flatMap(this.response.aiV5.stepContent);
1239
+ }
1240
+ return this.response.aiV5.model().map(this.response.aiV5.stepContent).flat();
1241
+ },
1242
+ stepContent: (message) => {
1243
+ const latest = message ? message : this.response.aiV5.model().at(-1);
1244
+ if (!latest) return [];
1245
+ if (typeof latest.content === `string`) {
1246
+ return [{ type: "text", text: latest.content }];
1247
+ }
1248
+ return latest.content.map((c) => {
1249
+ if (c.type === `tool-result`)
1250
+ return {
1251
+ type: "tool-result",
1252
+ input: {},
1253
+ // TODO: we need to find the tool call here and add the input from it
1254
+ output: c.output,
1255
+ toolCallId: c.toolCallId,
1256
+ toolName: c.toolName
1257
+ };
1258
+ if (c.type === `file`)
1259
+ return {
1260
+ type: "file",
1261
+ file: new DefaultGeneratedFileWithType({
1262
+ data: typeof c.data === `string` ? parseDataUri(c.data).base64Content : c.data instanceof URL ? c.data.toString() : convertDataContentToBase64String(c.data),
1263
+ mediaType: c.mediaType
1264
+ })
1265
+ };
1266
+ if (c.type === `image`) {
1267
+ return {
1268
+ type: "file",
1269
+ file: new DefaultGeneratedFileWithType({
1270
+ data: typeof c.image === `string` ? parseDataUri(c.image).base64Content : c.image instanceof URL ? c.image.toString() : convertDataContentToBase64String(c.image),
1271
+ mediaType: c.mediaType || "unknown"
1272
+ })
1273
+ };
1274
+ }
1275
+ return { ...c };
1276
+ });
1277
+ }
1278
+ },
1279
+ aiV4: {
1280
+ ui: () => this.response.v2().map(_MessageList.mastraMessageV2ToAIV4UIMessage),
1281
+ core: () => this.aiV4UIMessagesToAIV4CoreMessages(this.response.aiV4.ui())
1282
+ }
1283
+ };
1284
+ // TODO: need to update this for new .aiV4/5.x() pattern
1285
+ responsePersisted = {
1286
+ v3: () => this.cleanV3Metadata(
1287
+ this.messages.filter((m) => this.newResponseMessagesPersisted.has(m)).map(this.mastraMessageV2ToMastraMessageV3)
1288
+ ),
1289
+ v2: () => this.messages.filter((m) => this.newResponseMessagesPersisted.has(m)),
1290
+ ui: () => this.responsePersisted.v2().map(_MessageList.mastraMessageV2ToAIV4UIMessage)
1291
+ };
1292
+ drainUnsavedMessages() {
1293
+ const messages = this.messages.filter((m) => this.newUserMessages.has(m) || this.newResponseMessages.has(m));
1294
+ this.newUserMessages.clear();
1295
+ this.newResponseMessages.clear();
1296
+ return messages;
1297
+ }
1298
+ getEarliestUnsavedMessageTimestamp() {
1299
+ const unsavedMessages = this.messages.filter((m) => this.newUserMessages.has(m) || this.newResponseMessages.has(m));
1300
+ if (unsavedMessages.length === 0) return void 0;
1301
+ return Math.min(...unsavedMessages.map((m) => new Date(m.createdAt).getTime()));
1302
+ }
1303
+ getSystemMessages(tag) {
1304
+ if (tag) {
1305
+ return this.taggedSystemMessages[tag] || [];
1306
+ }
1307
+ return this.systemMessages;
1308
+ }
1309
+ addSystem(messages, tag) {
1310
+ if (!messages) return this;
1311
+ for (const message of Array.isArray(messages) ? messages : [messages]) {
1312
+ this.addOneSystem(message, tag);
1313
+ }
1314
+ return this;
1315
+ }
1316
+ aiV4UIMessagesToAIV4CoreMessages(messages) {
1317
+ return AIV4__namespace.convertToCoreMessages(this.sanitizeAIV4UIMessages(messages));
1318
+ }
1319
+ sanitizeAIV4UIMessages(messages) {
1320
+ const msgs = messages.map((m) => {
1321
+ if (m.parts.length === 0) return false;
1322
+ const safeParts = m.parts.filter(
1323
+ (p) => p.type !== `tool-invocation` || // calls and partial-calls should be updated to be results at this point
1324
+ // if they haven't we can't send them back to the llm and need to remove them.
1325
+ p.toolInvocation.state !== `call` && p.toolInvocation.state !== `partial-call`
1326
+ );
1327
+ if (!safeParts.length) return false;
1328
+ const sanitized = {
1329
+ ...m,
1330
+ parts: safeParts
1331
+ };
1332
+ if (`toolInvocations` in m && m.toolInvocations) {
1333
+ sanitized.toolInvocations = m.toolInvocations.filter((t) => t.state === `result`);
1334
+ }
1335
+ return sanitized;
1336
+ }).filter((m) => Boolean(m));
1337
+ return msgs;
1338
+ }
1339
+ /**
1340
+ * Converts various message formats to AIV4 CoreMessage format for system messages
1341
+ * @param message - The message to convert (can be string, MastraMessageV2, or AI SDK message types)
1342
+ * @returns AIV4 CoreMessage in the proper format
1343
+ */
1344
+ systemMessageToAICore(message) {
1345
+ if (typeof message === `string`) {
1346
+ return { role: "system", content: message };
1347
+ }
1348
+ if (_MessageList.isAIV5CoreMessage(message)) {
1349
+ return this.aiV5ModelMessagesToAIV4CoreMessages([message], `system`)[0];
1350
+ }
1351
+ if (_MessageList.isMastraMessageV2(message)) {
1352
+ return _MessageList.mastraMessageV2SystemToV4Core(message);
1353
+ }
1354
+ return message;
1355
+ }
1356
+ addOneSystem(message, tag) {
1357
+ const coreMessage = this.systemMessageToAICore(message);
1358
+ if (coreMessage.role !== `system`) {
1359
+ throw new Error(
1360
+ `Expected role "system" but saw ${coreMessage.role} for message ${JSON.stringify(coreMessage, null, 2)}`
1361
+ );
1362
+ }
1363
+ if (tag && !this.isDuplicateSystem(coreMessage, tag)) {
1364
+ this.taggedSystemMessages[tag] ||= [];
1365
+ this.taggedSystemMessages[tag].push(coreMessage);
1366
+ } else if (!tag && !this.isDuplicateSystem(coreMessage)) {
1367
+ this.systemMessages.push(coreMessage);
1368
+ }
1369
+ }
1370
+ isDuplicateSystem(message, tag) {
1371
+ if (tag) {
1372
+ if (!this.taggedSystemMessages[tag]) return false;
1373
+ return this.taggedSystemMessages[tag].some(
1374
+ (m) => _MessageList.cacheKeyFromAIV4CoreMessageContent(m.content) === _MessageList.cacheKeyFromAIV4CoreMessageContent(message.content)
1375
+ );
1376
+ }
1377
+ return this.systemMessages.some(
1378
+ (m) => _MessageList.cacheKeyFromAIV4CoreMessageContent(m.content) === _MessageList.cacheKeyFromAIV4CoreMessageContent(message.content)
1379
+ );
1380
+ }
1381
+ static mastraMessageV2ToAIV4UIMessage(m) {
1382
+ const experimentalAttachments = m.content.experimental_attachments ? [...m.content.experimental_attachments] : [];
1383
+ const contentString = typeof m.content.content === `string` && m.content.content !== "" ? m.content.content : m.content.parts.reduce((prev, part) => {
1384
+ if (part.type === `text`) {
1385
+ return part.text;
1386
+ }
1387
+ return prev;
1388
+ }, "");
1389
+ const parts = [];
1390
+ if (m.content.parts.length) {
1391
+ for (const part of m.content.parts) {
1392
+ if (part.type === `file`) {
1393
+ let normalizedUrl;
1394
+ if (typeof part.data === "string") {
1395
+ const categorized = categorizeFileData(part.data, part.mimeType);
1396
+ if (categorized.type === "raw") {
1397
+ normalizedUrl = createDataUri(part.data, part.mimeType || "application/octet-stream");
1398
+ } else {
1399
+ normalizedUrl = part.data;
1400
+ }
1401
+ } else {
1402
+ normalizedUrl = part.data;
1403
+ }
1404
+ experimentalAttachments.push({
1405
+ contentType: part.mimeType,
1406
+ url: normalizedUrl
1407
+ });
1408
+ } else if (part.type === "tool-invocation" && (part.toolInvocation.state === "call" || part.toolInvocation.state === "partial-call")) {
1409
+ continue;
1410
+ } else if (part.type === "tool-invocation") {
1411
+ const toolInvocation = { ...part.toolInvocation };
1412
+ let currentStep = -1;
1413
+ let toolStep = -1;
1414
+ for (const innerPart of m.content.parts) {
1415
+ if (innerPart.type === `step-start`) currentStep++;
1416
+ if (innerPart.type === `tool-invocation` && innerPart.toolInvocation.toolCallId === part.toolInvocation.toolCallId) {
1417
+ toolStep = currentStep;
1418
+ break;
1419
+ }
1420
+ }
1421
+ if (toolStep >= 0) {
1422
+ const preparedInvocation = {
1423
+ step: toolStep,
1424
+ ...toolInvocation
1425
+ };
1426
+ parts.push({
1427
+ type: "tool-invocation",
1428
+ toolInvocation: preparedInvocation
1429
+ });
1430
+ } else {
1431
+ parts.push({
1432
+ type: "tool-invocation",
1433
+ toolInvocation
1434
+ });
1435
+ }
1436
+ } else {
1437
+ parts.push(part);
1438
+ }
1439
+ }
1440
+ }
1441
+ if (parts.length === 0 && experimentalAttachments.length > 0) {
1442
+ parts.push({ type: "text", text: "" });
1443
+ }
1444
+ if (m.role === `user`) {
1445
+ const uiMessage2 = {
1446
+ id: m.id,
1447
+ role: m.role,
1448
+ content: m.content.content || contentString,
1449
+ createdAt: m.createdAt,
1450
+ parts,
1451
+ experimental_attachments: experimentalAttachments
1452
+ };
1453
+ if (m.content.metadata) {
1454
+ uiMessage2.metadata = m.content.metadata;
1455
+ }
1456
+ return uiMessage2;
1457
+ } else if (m.role === `assistant`) {
1458
+ const isSingleTextContentArray = Array.isArray(m.content.content) && m.content.content.length === 1 && m.content.content[0].type === `text`;
1459
+ const uiMessage2 = {
1460
+ id: m.id,
1461
+ role: m.role,
1462
+ content: isSingleTextContentArray ? contentString : m.content.content || contentString,
1463
+ createdAt: m.createdAt,
1464
+ parts,
1465
+ reasoning: void 0,
1466
+ toolInvocations: `toolInvocations` in m.content ? m.content.toolInvocations?.filter((t) => t.state === "result") : void 0
1467
+ };
1468
+ if (m.content.metadata) {
1469
+ uiMessage2.metadata = m.content.metadata;
1470
+ }
1471
+ return uiMessage2;
1472
+ }
1473
+ const uiMessage = {
1474
+ id: m.id,
1475
+ role: m.role,
1476
+ content: m.content.content || contentString,
1477
+ createdAt: m.createdAt,
1478
+ parts,
1479
+ experimental_attachments: experimentalAttachments
1480
+ };
1481
+ if (m.content.metadata) {
1482
+ uiMessage.metadata = m.content.metadata;
1483
+ }
1484
+ return uiMessage;
1485
+ }
1486
+ /**
1487
+ * Converts a MastraMessageV2 system message directly to AIV4 CoreMessage format
1488
+ * This is more efficient than converting to UI message first and then to core
1489
+ * @param message - The MastraMessageV2 message to convert
1490
+ * @returns AIV4 CoreMessage with system role
1491
+ */
1492
+ static mastraMessageV2SystemToV4Core(message) {
1493
+ if (message.role !== `system` || !message.content.content)
1494
+ throw new chunk5NTO7S5I_cjs.MastraError({
1495
+ id: "INVALID_SYSTEM_MESSAGE_FORMAT",
1496
+ domain: "AGENT" /* AGENT */,
1497
+ category: "USER" /* USER */,
1498
+ text: `Invalid system message format. System messages must include 'role' and 'content' properties. The content should be a string.`,
1499
+ details: {
1500
+ receivedMessage: JSON.stringify(message, null, 2)
1501
+ }
1502
+ });
1503
+ return { role: "system", content: message.content.content };
1504
+ }
1505
+ getMessageById(id) {
1506
+ return this.messages.find((m) => m.id === id);
1507
+ }
1508
+ shouldReplaceMessage(message) {
1509
+ if (!this.messages.length) return { exists: false };
1510
+ if (!(`id` in message) || !message?.id) {
1511
+ return { exists: false };
1512
+ }
1513
+ const existingMessage = this.getMessageById(message.id);
1514
+ if (!existingMessage) return { exists: false };
1515
+ return {
1516
+ exists: true,
1517
+ shouldReplace: !_MessageList.messagesAreEqual(existingMessage, message),
1518
+ id: existingMessage.id
1519
+ };
1520
+ }
1521
+ addOne(message, messageSource) {
1522
+ if ((!(`content` in message) || !message.content && // allow empty strings
1523
+ typeof message.content !== "string") && (!(`parts` in message) || !message.parts)) {
1524
+ throw new chunk5NTO7S5I_cjs.MastraError({
1525
+ id: "INVALID_MESSAGE_CONTENT",
1526
+ domain: "AGENT" /* AGENT */,
1527
+ category: "USER" /* USER */,
1528
+ text: `Message with role "${message.role}" must have either a 'content' property (string or array) or a 'parts' property (array) that is not empty, null, or undefined. Received message: ${JSON.stringify(message, null, 2)}`,
1529
+ details: {
1530
+ role: message.role,
1531
+ messageSource,
1532
+ hasContent: "content" in message,
1533
+ hasParts: "parts" in message
1534
+ }
1535
+ });
1536
+ }
1537
+ if (message.role === `system`) {
1538
+ if (messageSource === `memory`) return null;
1539
+ const isSupportedSystemFormat = _MessageList.isAIV4CoreMessage(message) || _MessageList.isAIV5CoreMessage(message) || _MessageList.isMastraMessageV2(message);
1540
+ if (isSupportedSystemFormat) {
1541
+ return this.addSystem(message);
1542
+ }
1543
+ throw new chunk5NTO7S5I_cjs.MastraError({
1544
+ id: "INVALID_SYSTEM_MESSAGE_FORMAT",
1545
+ domain: "AGENT" /* AGENT */,
1546
+ category: "USER" /* USER */,
1547
+ text: `Invalid system message format. System messages must be CoreMessage format with 'role' and 'content' properties. The content should be a string or valid content array.`,
1548
+ details: {
1549
+ messageSource,
1550
+ receivedMessage: JSON.stringify(message, null, 2)
1551
+ }
1552
+ });
1553
+ }
1554
+ const messageV2 = this.inputToMastraMessageV2(message, messageSource);
1555
+ const { exists, shouldReplace, id } = this.shouldReplaceMessage(messageV2);
1556
+ const latestMessage = this.messages.at(-1);
1557
+ if (messageSource === `memory`) {
1558
+ for (const existingMessage of this.messages) {
1559
+ if (_MessageList.messagesAreEqual(existingMessage, messageV2)) {
1560
+ return;
1561
+ }
1562
+ }
1563
+ }
1564
+ const shouldAppendToLastAssistantMessage = latestMessage?.role === "assistant" && messageV2.role === "assistant" && latestMessage.threadId === messageV2.threadId && // If the message is from memory, don't append to the last assistant message
1565
+ messageSource !== "memory";
1566
+ const appendNetworkMessage = this._agentNetworkAppend && latestMessage && !this.memoryMessages.has(latestMessage) || !this._agentNetworkAppend;
1567
+ if (shouldAppendToLastAssistantMessage && appendNetworkMessage) {
1568
+ latestMessage.createdAt = messageV2.createdAt || latestMessage.createdAt;
1569
+ const toolResultAnchorMap = /* @__PURE__ */ new Map();
1570
+ const partsToAdd = /* @__PURE__ */ new Map();
1571
+ for (const [index, part] of messageV2.content.parts.entries()) {
1572
+ if (part.type === "tool-invocation") {
1573
+ const existingCallPart = [...latestMessage.content.parts].reverse().find((p) => p.type === "tool-invocation" && p.toolInvocation.toolCallId === part.toolInvocation.toolCallId);
1574
+ const existingCallToolInvocation = !!existingCallPart && existingCallPart.type === "tool-invocation";
1575
+ if (existingCallToolInvocation) {
1576
+ if (part.toolInvocation.state === "result") {
1577
+ existingCallPart.toolInvocation = {
1578
+ ...existingCallPart.toolInvocation,
1579
+ step: part.toolInvocation.step,
1580
+ state: "result",
1581
+ result: part.toolInvocation.result,
1582
+ args: {
1583
+ ...existingCallPart.toolInvocation.args,
1584
+ ...part.toolInvocation.args
1585
+ }
1586
+ };
1587
+ if (!latestMessage.content.toolInvocations) {
1588
+ latestMessage.content.toolInvocations = [];
1589
+ }
1590
+ const toolInvocationIndex = latestMessage.content.toolInvocations.findIndex(
1591
+ (t) => t.toolCallId === existingCallPart.toolInvocation.toolCallId
1592
+ );
1593
+ if (toolInvocationIndex === -1) {
1594
+ latestMessage.content.toolInvocations.push(existingCallPart.toolInvocation);
1595
+ } else {
1596
+ latestMessage.content.toolInvocations[toolInvocationIndex] = existingCallPart.toolInvocation;
1597
+ }
1598
+ }
1599
+ const existingIndex = latestMessage.content.parts.findIndex((p) => p === existingCallPart);
1600
+ toolResultAnchorMap.set(index, existingIndex);
1601
+ } else {
1602
+ partsToAdd.set(index, part);
1603
+ }
1604
+ } else {
1605
+ partsToAdd.set(index, part);
1606
+ }
1607
+ }
1608
+ this.addPartsToLatestMessage({
1609
+ latestMessage,
1610
+ messageV2,
1611
+ anchorMap: toolResultAnchorMap,
1612
+ partsToAdd
1613
+ });
1614
+ if (latestMessage.createdAt.getTime() < messageV2.createdAt.getTime()) {
1615
+ latestMessage.createdAt = messageV2.createdAt;
1616
+ }
1617
+ if (!latestMessage.content.content && messageV2.content.content) {
1618
+ latestMessage.content.content = messageV2.content.content;
1619
+ }
1620
+ if (latestMessage.content.content && messageV2.content.content && latestMessage.content.content !== messageV2.content.content) {
1621
+ latestMessage.content.content = messageV2.content.content;
1622
+ }
1623
+ this.pushMessageToSource(latestMessage, messageSource);
1624
+ } else {
1625
+ let existingIndex = -1;
1626
+ if (shouldReplace) {
1627
+ existingIndex = this.messages.findIndex((m) => m.id === id);
1628
+ }
1629
+ const existingMessage = existingIndex !== -1 && this.messages[existingIndex];
1630
+ if (shouldReplace && existingMessage) {
1631
+ this.messages[existingIndex] = messageV2;
1632
+ } else if (!exists) {
1633
+ this.messages.push(messageV2);
1634
+ }
1635
+ this.pushMessageToSource(messageV2, messageSource);
1636
+ }
1637
+ this.messages.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
1638
+ return this;
1639
+ }
1640
+ pushMessageToSource(messageV2, messageSource) {
1641
+ if (messageSource === `memory`) {
1642
+ this.memoryMessages.add(messageV2);
1643
+ this.memoryMessagesPersisted.add(messageV2);
1644
+ } else if (messageSource === `response`) {
1645
+ this.newResponseMessages.add(messageV2);
1646
+ this.newResponseMessagesPersisted.add(messageV2);
1647
+ } else if (messageSource === `input`) {
1648
+ this.newUserMessages.add(messageV2);
1649
+ this.newUserMessagesPersisted.add(messageV2);
1650
+ } else if (messageSource === `context`) {
1651
+ this.userContextMessages.add(messageV2);
1652
+ this.userContextMessagesPersisted.add(messageV2);
1653
+ } else {
1654
+ throw new Error(`Missing message source for message ${messageV2}`);
1655
+ }
1656
+ }
1657
+ /**
1658
+ * Pushes a new message part to the latest message.
1659
+ * @param latestMessage - The latest message to push the part to.
1660
+ * @param newMessage - The new message to push the part from.
1661
+ * @param part - The part to push.
1662
+ * @param insertAt - The index at which to insert the part. Optional.
1663
+ */
1664
+ pushNewMessagePart({
1665
+ latestMessage,
1666
+ newMessage,
1667
+ part,
1668
+ insertAt
1669
+ // optional
1670
+ }) {
1671
+ const partKey = _MessageList.cacheKeyFromAIV4Parts([part]);
1672
+ const latestPartCount = latestMessage.content.parts.filter(
1673
+ (p) => _MessageList.cacheKeyFromAIV4Parts([p]) === partKey
1674
+ ).length;
1675
+ const newPartCount = newMessage.content.parts.filter(
1676
+ (p) => _MessageList.cacheKeyFromAIV4Parts([p]) === partKey
1677
+ ).length;
1678
+ if (latestPartCount < newPartCount) {
1679
+ const partIndex = newMessage.content.parts.indexOf(part);
1680
+ const hasStepStartBefore = partIndex > 0 && newMessage.content.parts[partIndex - 1]?.type === "step-start";
1681
+ const needsStepStart = latestMessage.role === "assistant" && part.type === "text" && !hasStepStartBefore && latestMessage.content.parts.length > 0 && latestMessage.content.parts.at(-1)?.type === "tool-invocation";
1682
+ if (typeof insertAt === "number") {
1683
+ if (needsStepStart) {
1684
+ latestMessage.content.parts.splice(insertAt, 0, { type: "step-start" });
1685
+ latestMessage.content.parts.splice(insertAt + 1, 0, part);
1686
+ } else {
1687
+ latestMessage.content.parts.splice(insertAt, 0, part);
1688
+ }
1689
+ } else {
1690
+ if (needsStepStart) {
1691
+ latestMessage.content.parts.push({ type: "step-start" });
1692
+ }
1693
+ latestMessage.content.parts.push(part);
1694
+ }
1695
+ }
1696
+ }
1697
+ /**
1698
+ * Upserts parts of messageV2 into latestMessage based on the anchorMap.
1699
+ * This is used when appending a message to the last assistant message to ensure that parts are inserted in the correct order.
1700
+ * @param latestMessage - The latest message to upsert parts into.
1701
+ * @param messageV2 - The message to upsert parts from.
1702
+ * @param anchorMap - The anchor map to use for upserting parts.
1703
+ */
1704
+ addPartsToLatestMessage({
1705
+ latestMessage,
1706
+ messageV2,
1707
+ anchorMap,
1708
+ partsToAdd
1709
+ }) {
1710
+ for (let i = 0; i < messageV2.content.parts.length; ++i) {
1711
+ const part = messageV2.content.parts[i];
1712
+ if (!part) continue;
1713
+ const key = _MessageList.cacheKeyFromAIV4Parts([part]);
1714
+ const partToAdd = partsToAdd.get(i);
1715
+ if (!key || !partToAdd) continue;
1716
+ if (anchorMap.size > 0) {
1717
+ if (anchorMap.has(i)) continue;
1718
+ const leftAnchorV2 = [...anchorMap.keys()].filter((idx) => idx < i).pop() ?? -1;
1719
+ const rightAnchorV2 = [...anchorMap.keys()].find((idx) => idx > i) ?? -1;
1720
+ const leftAnchorLatest = leftAnchorV2 !== -1 ? anchorMap.get(leftAnchorV2) : 0;
1721
+ const offset = leftAnchorV2 === -1 ? i : i - leftAnchorV2;
1722
+ const insertAt = leftAnchorLatest + offset;
1723
+ const rightAnchorLatest = rightAnchorV2 !== -1 ? anchorMap.get(rightAnchorV2) : latestMessage.content.parts.length;
1724
+ if (insertAt >= 0 && insertAt <= rightAnchorLatest && !latestMessage.content.parts.slice(insertAt, rightAnchorLatest).some((p) => _MessageList.cacheKeyFromAIV4Parts([p]) === _MessageList.cacheKeyFromAIV4Parts([part]))) {
1725
+ this.pushNewMessagePart({
1726
+ latestMessage,
1727
+ newMessage: messageV2,
1728
+ part,
1729
+ insertAt
1730
+ });
1731
+ for (const [v2Idx, latestIdx] of anchorMap.entries()) {
1732
+ if (latestIdx >= insertAt) {
1733
+ anchorMap.set(v2Idx, latestIdx + 1);
1734
+ }
1735
+ }
1736
+ }
1737
+ } else {
1738
+ this.pushNewMessagePart({
1739
+ latestMessage,
1740
+ newMessage: messageV2,
1741
+ part
1742
+ });
1743
+ }
1744
+ }
1745
+ }
1746
+ inputToMastraMessageV2(message, messageSource) {
1747
+ if (
1748
+ // we can't throw if the threadId doesn't match and this message came from memory
1749
+ // this is because per-user semantic recall can retrieve messages from other threads
1750
+ messageSource !== `memory` && `threadId` in message && message.threadId && this.memoryInfo && message.threadId !== this.memoryInfo.threadId
1751
+ ) {
1752
+ throw new Error(
1753
+ `Received input message with wrong threadId. Input ${message.threadId}, expected ${this.memoryInfo.threadId}`
1754
+ );
1755
+ }
1756
+ if (`resourceId` in message && message.resourceId && this.memoryInfo?.resourceId && message.resourceId !== this.memoryInfo.resourceId) {
1757
+ throw new Error(
1758
+ `Received input message with wrong resourceId. Input ${message.resourceId}, expected ${this.memoryInfo.resourceId}`
1759
+ );
1760
+ }
1761
+ if (_MessageList.isMastraMessageV1(message)) {
1762
+ return this.mastraMessageV1ToMastraMessageV2(message, messageSource);
1763
+ }
1764
+ if (_MessageList.isMastraMessageV2(message)) {
1765
+ return this.hydrateMastraMessageV2Fields(message);
1766
+ }
1767
+ if (_MessageList.isAIV4CoreMessage(message)) {
1768
+ return this.aiV4CoreMessageToMastraMessageV2(message, messageSource);
1769
+ }
1770
+ if (_MessageList.isAIV4UIMessage(message)) {
1771
+ return this.aiV4UIMessageToMastraMessageV2(message, messageSource);
1772
+ }
1773
+ if (_MessageList.isAIV5CoreMessage(message)) {
1774
+ return _MessageList.mastraMessageV3ToV2(this.aiV5ModelMessageToMastraMessageV3(message, messageSource));
1775
+ }
1776
+ if (_MessageList.isAIV5UIMessage(message)) {
1777
+ return _MessageList.mastraMessageV3ToV2(this.aiV5UIMessageToMastraMessageV3(message, messageSource));
1778
+ }
1779
+ if (_MessageList.isMastraMessageV3(message)) {
1780
+ return _MessageList.mastraMessageV3ToV2(this.hydrateMastraMessageV3Fields(message));
1781
+ }
1782
+ throw new Error(`Found unhandled message ${JSON.stringify(message)}`);
1783
+ }
1784
+ lastCreatedAt;
1785
+ // this makes sure messages added in order will always have a date atleast 1ms apart.
1786
+ generateCreatedAt(messageSource, start) {
1787
+ start = start instanceof Date ? start : start ? new Date(start) : void 0;
1788
+ if (start && !this.lastCreatedAt) {
1789
+ this.lastCreatedAt = start.getTime();
1790
+ return start;
1791
+ }
1792
+ if (start && messageSource === `memory`) {
1793
+ return start;
1794
+ }
1795
+ const now = /* @__PURE__ */ new Date();
1796
+ const nowTime = start?.getTime() || now.getTime();
1797
+ const lastTime = this.messages.reduce((p, m) => {
1798
+ if (m.createdAt.getTime() > p) return m.createdAt.getTime();
1799
+ return p;
1800
+ }, this.lastCreatedAt || 0);
1801
+ if (nowTime <= lastTime) {
1802
+ const newDate = new Date(lastTime + 1);
1803
+ this.lastCreatedAt = newDate.getTime();
1804
+ return newDate;
1805
+ }
1806
+ this.lastCreatedAt = nowTime;
1807
+ return now;
1808
+ }
1809
+ newMessageId() {
1810
+ if (this.generateMessageId) {
1811
+ return this.generateMessageId();
1812
+ }
1813
+ return crypto.randomUUID();
1814
+ }
1815
+ mastraMessageV1ToMastraMessageV2(message, messageSource) {
1816
+ const coreV2 = this.aiV4CoreMessageToMastraMessageV2(
1817
+ {
1818
+ content: message.content,
1819
+ role: message.role
1820
+ },
1821
+ messageSource
1822
+ );
1823
+ return {
1824
+ id: message.id,
1825
+ role: coreV2.role,
1826
+ createdAt: this.generateCreatedAt(messageSource, message.createdAt),
1827
+ threadId: message.threadId,
1828
+ resourceId: message.resourceId,
1829
+ content: coreV2.content
1830
+ };
1831
+ }
1832
+ hydrateMastraMessageV3Fields(message) {
1833
+ if (!(message.createdAt instanceof Date)) message.createdAt = new Date(message.createdAt);
1834
+ return message;
1835
+ }
1836
+ hydrateMastraMessageV2Fields(message) {
1837
+ if (!(message.createdAt instanceof Date)) message.createdAt = new Date(message.createdAt);
1838
+ if (!message.threadId && this.memoryInfo?.threadId) {
1839
+ message.threadId = this.memoryInfo.threadId;
1840
+ }
1841
+ if (!message.resourceId && this.memoryInfo?.resourceId) {
1842
+ message.resourceId = this.memoryInfo.resourceId;
1843
+ }
1844
+ if (message.content.toolInvocations && message.content.parts) {
1845
+ message.content.toolInvocations = message.content.toolInvocations.map((ti) => {
1846
+ if (!ti.args || Object.keys(ti.args).length === 0) {
1847
+ const partWithArgs = message.content.parts.find(
1848
+ (part) => part.type === "tool-invocation" && part.toolInvocation && part.toolInvocation.toolCallId === ti.toolCallId && part.toolInvocation.args && Object.keys(part.toolInvocation.args).length > 0
1849
+ );
1850
+ if (partWithArgs && partWithArgs.type === "tool-invocation") {
1851
+ return { ...ti, args: partWithArgs.toolInvocation.args };
1852
+ }
1853
+ }
1854
+ return ti;
1855
+ });
1856
+ }
1857
+ return message;
1858
+ }
1859
+ aiV4UIMessageToMastraMessageV2(message, messageSource) {
1860
+ const content = {
1861
+ format: 2,
1862
+ parts: message.parts
1863
+ };
1864
+ if (message.toolInvocations) content.toolInvocations = message.toolInvocations;
1865
+ if (message.reasoning) content.reasoning = message.reasoning;
1866
+ if (message.annotations) content.annotations = message.annotations;
1867
+ if (message.experimental_attachments) {
1868
+ content.experimental_attachments = message.experimental_attachments;
1869
+ }
1870
+ if ("metadata" in message && message.metadata !== null && message.metadata !== void 0) {
1871
+ content.metadata = message.metadata;
1872
+ }
1873
+ if ("providerMetadata" in message && message.providerMetadata !== null && message.providerMetadata !== void 0) {
1874
+ content.providerMetadata = message.providerMetadata;
1875
+ }
1876
+ return {
1877
+ id: message.id || this.newMessageId(),
1878
+ role: _MessageList.getRole(message),
1879
+ createdAt: this.generateCreatedAt(messageSource, message.createdAt),
1880
+ threadId: this.memoryInfo?.threadId,
1881
+ resourceId: this.memoryInfo?.resourceId,
1882
+ content
1883
+ };
1884
+ }
1885
+ aiV4CoreMessageToMastraMessageV2(coreMessage, messageSource) {
1886
+ const id = `id` in coreMessage ? coreMessage.id : this.newMessageId();
1887
+ const parts = [];
1888
+ const experimentalAttachments = [];
1889
+ const toolInvocations = [];
1890
+ const isSingleTextContent = messageSource === `response` && Array.isArray(coreMessage.content) && coreMessage.content.length === 1 && coreMessage.content[0] && coreMessage.content[0].type === `text` && `text` in coreMessage.content[0] && coreMessage.content[0].text;
1891
+ if (isSingleTextContent && messageSource === `response`) {
1892
+ coreMessage.content = isSingleTextContent;
1893
+ }
1894
+ if (typeof coreMessage.content === "string") {
1895
+ parts.push({
1896
+ type: "text",
1897
+ text: coreMessage.content,
1898
+ // Preserve providerOptions from CoreMessage (e.g., for system messages with cacheControl)
1899
+ ..."providerOptions" in coreMessage && coreMessage.providerOptions ? { providerMetadata: coreMessage.providerOptions } : {}
1900
+ });
1901
+ } else if (Array.isArray(coreMessage.content)) {
1902
+ for (const part of coreMessage.content) {
1903
+ switch (part.type) {
1904
+ case "text":
1905
+ const prevPart = parts.at(-1);
1906
+ if (coreMessage.role === "assistant" && prevPart && prevPart.type === "tool-invocation") {
1907
+ parts.push({ type: "step-start" });
1908
+ }
1909
+ const mergedProviderMetadata = {
1910
+ ..."providerOptions" in coreMessage && coreMessage.providerOptions ? coreMessage.providerOptions : {},
1911
+ ..."providerOptions" in part && part.providerOptions ? part.providerOptions : {}
1912
+ };
1913
+ parts.push({
1914
+ type: "text",
1915
+ text: part.text,
1916
+ ...Object.keys(mergedProviderMetadata).length > 0 ? { providerMetadata: mergedProviderMetadata } : {}
1917
+ });
1918
+ break;
1919
+ case "tool-call": {
1920
+ const toolCallPart = {
1921
+ type: "tool-invocation",
1922
+ toolInvocation: {
1923
+ state: "call",
1924
+ toolCallId: part.toolCallId,
1925
+ toolName: part.toolName,
1926
+ args: part.args
1927
+ }
1928
+ };
1929
+ if ("providerOptions" in part && part.providerOptions) {
1930
+ toolCallPart.providerMetadata = part.providerOptions;
1931
+ }
1932
+ parts.push(toolCallPart);
1933
+ break;
1934
+ }
1935
+ case "tool-result":
1936
+ let toolArgs = {};
1937
+ const toolCallInSameMsg = coreMessage.content.find(
1938
+ (p) => p.type === "tool-call" && p.toolCallId === part.toolCallId
1939
+ );
1940
+ if (toolCallInSameMsg && toolCallInSameMsg.type === "tool-call") {
1941
+ toolArgs = toolCallInSameMsg.args;
1942
+ }
1943
+ if (Object.keys(toolArgs).length === 0) {
1944
+ for (let i = this.messages.length - 1; i >= 0; i--) {
1945
+ const msg = this.messages[i];
1946
+ if (msg && msg.role === "assistant" && msg.content.parts) {
1947
+ const toolCallPart = msg.content.parts.find(
1948
+ (p) => p.type === "tool-invocation" && p.toolInvocation.toolCallId === part.toolCallId && p.toolInvocation.state === "call"
1949
+ );
1950
+ if (toolCallPart && toolCallPart.type === "tool-invocation" && toolCallPart.toolInvocation.args) {
1951
+ toolArgs = toolCallPart.toolInvocation.args;
1952
+ break;
1953
+ }
1954
+ }
1955
+ }
1956
+ }
1957
+ const invocation = {
1958
+ state: "result",
1959
+ toolCallId: part.toolCallId,
1960
+ toolName: part.toolName,
1961
+ result: part.result ?? "",
1962
+ // undefined will cause AI SDK to throw an error, but for client side tool calls this really could be undefined
1963
+ args: toolArgs
1964
+ // Use the args from the corresponding tool-call
1965
+ };
1966
+ const toolResultPart = {
1967
+ type: "tool-invocation",
1968
+ toolInvocation: invocation
1969
+ };
1970
+ if ("providerOptions" in part && part.providerOptions) {
1971
+ toolResultPart.providerMetadata = part.providerOptions;
1972
+ }
1973
+ parts.push(toolResultPart);
1974
+ toolInvocations.push(invocation);
1975
+ break;
1976
+ case "reasoning": {
1977
+ const reasoningPart = {
1978
+ type: "reasoning",
1979
+ reasoning: "",
1980
+ // leave this blank so we aren't double storing it in the db along with details
1981
+ details: [{ type: "text", text: part.text, signature: part.signature }]
1982
+ };
1983
+ if ("providerOptions" in part && part.providerOptions) {
1984
+ reasoningPart.providerMetadata = part.providerOptions;
1985
+ }
1986
+ parts.push(reasoningPart);
1987
+ break;
1988
+ }
1989
+ case "redacted-reasoning":
1990
+ parts.push({
1991
+ type: "reasoning",
1992
+ reasoning: "",
1993
+ // No text reasoning for redacted parts
1994
+ details: [{ type: "redacted", data: part.data }]
1995
+ });
1996
+ break;
1997
+ case "image":
1998
+ parts.push({
1999
+ type: "file",
2000
+ data: imageContentToString(part.image),
2001
+ mimeType: part.mimeType
2002
+ });
2003
+ break;
2004
+ case "file":
2005
+ if (part.data instanceof URL) {
2006
+ parts.push({
2007
+ type: "file",
2008
+ data: part.data.toString(),
2009
+ mimeType: part.mimeType
2010
+ });
2011
+ } else if (typeof part.data === "string") {
2012
+ const categorized = categorizeFileData(part.data, part.mimeType);
2013
+ if (categorized.type === "url" || categorized.type === "dataUri") {
2014
+ parts.push({
2015
+ type: "file",
2016
+ data: part.data,
2017
+ mimeType: categorized.mimeType || "image/png"
2018
+ });
2019
+ } else {
2020
+ try {
2021
+ parts.push({
2022
+ type: "file",
2023
+ mimeType: categorized.mimeType || "image/png",
2024
+ data: convertDataContentToBase64String(part.data)
2025
+ });
2026
+ } catch (error) {
2027
+ console.error(`Failed to convert binary data to base64 in CoreMessage file part: ${error}`, error);
2028
+ }
2029
+ }
2030
+ } else {
2031
+ try {
2032
+ parts.push({
2033
+ type: "file",
2034
+ mimeType: part.mimeType,
2035
+ data: convertDataContentToBase64String(part.data)
2036
+ });
2037
+ } catch (error) {
2038
+ console.error(`Failed to convert binary data to base64 in CoreMessage file part: ${error}`, error);
2039
+ }
2040
+ }
2041
+ break;
2042
+ }
2043
+ }
2044
+ }
2045
+ const content = {
2046
+ format: 2,
2047
+ parts
2048
+ };
2049
+ if (toolInvocations.length) content.toolInvocations = toolInvocations;
2050
+ if (typeof coreMessage.content === `string`) content.content = coreMessage.content;
2051
+ if (experimentalAttachments.length) content.experimental_attachments = experimentalAttachments;
2052
+ if (coreMessage.providerOptions) {
2053
+ content.providerMetadata = coreMessage.providerOptions;
2054
+ }
2055
+ if ("metadata" in coreMessage && coreMessage.metadata !== null && coreMessage.metadata !== void 0) {
2056
+ content.metadata = coreMessage.metadata;
2057
+ }
2058
+ return {
2059
+ id,
2060
+ role: _MessageList.getRole(coreMessage),
2061
+ createdAt: this.generateCreatedAt(messageSource),
2062
+ threadId: this.memoryInfo?.threadId,
2063
+ resourceId: this.memoryInfo?.resourceId,
2064
+ content
2065
+ };
2066
+ }
2067
+ static isAIV4UIMessage(msg) {
2068
+ return !_MessageList.isMastraMessage(msg) && !_MessageList.isAIV4CoreMessage(msg) && `parts` in msg && !_MessageList.hasAIV5UIMessageCharacteristics(msg);
2069
+ }
2070
+ static isAIV5CoreMessage(msg) {
2071
+ return !_MessageList.isMastraMessage(msg) && !(`parts` in msg) && `content` in msg && _MessageList.hasAIV5CoreMessageCharacteristics(msg);
2072
+ }
2073
+ static isAIV4CoreMessage(msg) {
2074
+ return !_MessageList.isMastraMessage(msg) && !(`parts` in msg) && `content` in msg && !_MessageList.hasAIV5CoreMessageCharacteristics(msg);
2075
+ }
2076
+ static isMastraMessage(msg) {
2077
+ return _MessageList.isMastraMessageV3(msg) || _MessageList.isMastraMessageV2(msg) || _MessageList.isMastraMessageV1(msg);
2078
+ }
2079
+ static isMastraMessageV1(msg) {
2080
+ return !_MessageList.isMastraMessageV2(msg) && !_MessageList.isMastraMessageV3(msg) && (`threadId` in msg || `resourceId` in msg);
2081
+ }
2082
+ static isMastraMessageV2(msg) {
2083
+ return Boolean(
2084
+ `content` in msg && msg.content && !Array.isArray(msg.content) && typeof msg.content !== `string` && `format` in msg.content && msg.content.format === 2
2085
+ );
2086
+ }
2087
+ static isMastraMessageV3(msg) {
2088
+ return Boolean(
2089
+ `content` in msg && msg.content && !Array.isArray(msg.content) && typeof msg.content !== `string` && `format` in msg.content && msg.content.format === 3
2090
+ );
2091
+ }
2092
+ static getRole(message) {
2093
+ if (message.role === `assistant` || message.role === `tool`) return `assistant`;
2094
+ if (message.role === `user`) return `user`;
2095
+ if (message.role === `system`) return `system`;
2096
+ throw new Error(
2097
+ `BUG: add handling for message role ${message.role} in message ${JSON.stringify(message, null, 2)}`
2098
+ );
2099
+ }
2100
+ static cacheKeyFromAIV4Parts(parts) {
2101
+ let key = ``;
2102
+ for (const part of parts) {
2103
+ key += part.type;
2104
+ if (part.type === `text`) {
2105
+ key += part.text;
2106
+ }
2107
+ if (part.type === `tool-invocation`) {
2108
+ key += part.toolInvocation.toolCallId;
2109
+ key += part.toolInvocation.state;
2110
+ }
2111
+ if (part.type === `reasoning`) {
2112
+ key += part.reasoning;
2113
+ key += part.details.reduce((prev, current) => {
2114
+ if (current.type === `text`) {
2115
+ return prev + current.text.length + (current.signature?.length || 0);
2116
+ }
2117
+ return prev;
2118
+ }, 0);
2119
+ }
2120
+ if (part.type === `file`) {
2121
+ key += part.data;
2122
+ key += part.mimeType;
2123
+ }
2124
+ }
2125
+ return key;
2126
+ }
2127
+ static coreContentToString(content) {
2128
+ if (typeof content === `string`) return content;
2129
+ return content.reduce((p, c) => {
2130
+ if (c.type === `text`) {
2131
+ p += c.text;
2132
+ }
2133
+ return p;
2134
+ }, "");
2135
+ }
2136
+ static cacheKeyFromAIV4CoreMessageContent(content) {
2137
+ if (typeof content === `string`) return content;
2138
+ let key = ``;
2139
+ for (const part of content) {
2140
+ key += part.type;
2141
+ if (part.type === `text`) {
2142
+ key += part.text.length;
2143
+ }
2144
+ if (part.type === `reasoning`) {
2145
+ key += part.text.length;
2146
+ }
2147
+ if (part.type === `tool-call`) {
2148
+ key += part.toolCallId;
2149
+ key += part.toolName;
2150
+ }
2151
+ if (part.type === `tool-result`) {
2152
+ key += part.toolCallId;
2153
+ key += part.toolName;
2154
+ }
2155
+ if (part.type === `file`) {
2156
+ key += part.filename;
2157
+ key += part.mimeType;
2158
+ }
2159
+ if (part.type === `image`) {
2160
+ key += getImageCacheKey(part.image);
2161
+ key += part.mimeType;
2162
+ }
2163
+ if (part.type === `redacted-reasoning`) {
2164
+ key += part.data.length;
2165
+ }
2166
+ }
2167
+ return key;
2168
+ }
2169
+ static messagesAreEqual(one, two) {
2170
+ const oneUIV4 = _MessageList.isAIV4UIMessage(one) && one;
2171
+ const twoUIV4 = _MessageList.isAIV4UIMessage(two) && two;
2172
+ if (oneUIV4 && !twoUIV4) return false;
2173
+ if (oneUIV4 && twoUIV4) {
2174
+ return _MessageList.cacheKeyFromAIV4Parts(one.parts) === _MessageList.cacheKeyFromAIV4Parts(two.parts);
2175
+ }
2176
+ const oneCMV4 = _MessageList.isAIV4CoreMessage(one) && one;
2177
+ const twoCMV4 = _MessageList.isAIV4CoreMessage(two) && two;
2178
+ if (oneCMV4 && !twoCMV4) return false;
2179
+ if (oneCMV4 && twoCMV4) {
2180
+ return _MessageList.cacheKeyFromAIV4CoreMessageContent(oneCMV4.content) === _MessageList.cacheKeyFromAIV4CoreMessageContent(twoCMV4.content);
2181
+ }
2182
+ const oneMM1 = _MessageList.isMastraMessageV1(one) && one;
2183
+ const twoMM1 = _MessageList.isMastraMessageV1(two) && two;
2184
+ if (oneMM1 && !twoMM1) return false;
2185
+ if (oneMM1 && twoMM1) {
2186
+ return oneMM1.id === twoMM1.id && _MessageList.cacheKeyFromAIV4CoreMessageContent(oneMM1.content) === _MessageList.cacheKeyFromAIV4CoreMessageContent(twoMM1.content);
2187
+ }
2188
+ const oneMM2 = _MessageList.isMastraMessageV2(one) && one;
2189
+ const twoMM2 = _MessageList.isMastraMessageV2(two) && two;
2190
+ if (oneMM2 && !twoMM2) return false;
2191
+ if (oneMM2 && twoMM2) {
2192
+ return oneMM2.id === twoMM2.id && _MessageList.cacheKeyFromAIV4Parts(oneMM2.content.parts) === _MessageList.cacheKeyFromAIV4Parts(twoMM2.content.parts);
2193
+ }
2194
+ const oneMM3 = _MessageList.isMastraMessageV3(one) && one;
2195
+ const twoMM3 = _MessageList.isMastraMessageV3(two) && two;
2196
+ if (oneMM3 && !twoMM3) return false;
2197
+ if (oneMM3 && twoMM3) {
2198
+ return oneMM3.id === twoMM3.id && _MessageList.cacheKeyFromAIV5Parts(oneMM3.content.parts) === _MessageList.cacheKeyFromAIV5Parts(twoMM3.content.parts);
2199
+ }
2200
+ const oneUIV5 = _MessageList.isAIV5UIMessage(one) && one;
2201
+ const twoUIV5 = _MessageList.isAIV5UIMessage(two) && two;
2202
+ if (oneUIV5 && !twoUIV5) return false;
2203
+ if (oneUIV5 && twoUIV5) {
2204
+ return _MessageList.cacheKeyFromAIV5Parts(one.parts) === _MessageList.cacheKeyFromAIV5Parts(two.parts);
2205
+ }
2206
+ const oneCMV5 = _MessageList.isAIV5CoreMessage(one) && one;
2207
+ const twoCMV5 = _MessageList.isAIV5CoreMessage(two) && two;
2208
+ if (oneCMV5 && !twoCMV5) return false;
2209
+ if (oneCMV5 && twoCMV5) {
2210
+ return _MessageList.cacheKeyFromAIV5ModelMessageContent(oneCMV5.content) === _MessageList.cacheKeyFromAIV5ModelMessageContent(twoCMV5.content);
2211
+ }
2212
+ return true;
2213
+ }
2214
+ cleanV3Metadata(messages) {
2215
+ return messages.map((msg) => {
2216
+ if (!msg.content.metadata || typeof msg.content.metadata !== "object") {
2217
+ return msg;
2218
+ }
2219
+ const metadata = { ...msg.content.metadata };
2220
+ const hasOriginalContent = "__originalContent" in metadata;
2221
+ const hasOriginalAttachments = "__originalExperimentalAttachments" in metadata;
2222
+ if (!hasOriginalContent && !hasOriginalAttachments) {
2223
+ return msg;
2224
+ }
2225
+ const { __originalContent, __originalExperimentalAttachments, ...cleanMetadata } = metadata;
2226
+ if (Object.keys(cleanMetadata).length === 0) {
2227
+ const { metadata: metadata2, ...contentWithoutMetadata } = msg.content;
2228
+ return { ...msg, content: contentWithoutMetadata };
2229
+ }
2230
+ return { ...msg, content: { ...msg.content, metadata: cleanMetadata } };
2231
+ });
2232
+ }
2233
+ static aiV4CoreMessageToV1PromptMessage(coreMessage) {
2234
+ if (coreMessage.role === `system`) {
2235
+ return coreMessage;
2236
+ }
2237
+ if (typeof coreMessage.content === `string` && (coreMessage.role === `assistant` || coreMessage.role === `user`)) {
2238
+ return {
2239
+ ...coreMessage,
2240
+ content: [{ type: "text", text: coreMessage.content }]
2241
+ };
2242
+ }
2243
+ if (typeof coreMessage.content === `string`) {
2244
+ throw new Error(
2245
+ `Saw text content for input CoreMessage, but the role is ${coreMessage.role}. This is only allowed for "system", "assistant", and "user" roles.`
2246
+ );
2247
+ }
2248
+ const roleContent = {
2249
+ user: [],
2250
+ assistant: [],
2251
+ tool: []
2252
+ };
2253
+ const role = coreMessage.role;
2254
+ for (const part of coreMessage.content) {
2255
+ const incompatibleMessage = `Saw incompatible message content part type ${part.type} for message role ${role}`;
2256
+ switch (part.type) {
2257
+ case "text": {
2258
+ if (role === `tool`) {
2259
+ throw new Error(incompatibleMessage);
2260
+ }
2261
+ roleContent[role].push(part);
2262
+ break;
2263
+ }
2264
+ case "redacted-reasoning":
2265
+ case "reasoning": {
2266
+ if (role !== `assistant`) {
2267
+ throw new Error(incompatibleMessage);
2268
+ }
2269
+ roleContent[role].push(part);
2270
+ break;
2271
+ }
2272
+ case "tool-call": {
2273
+ if (role === `tool` || role === `user`) {
2274
+ throw new Error(incompatibleMessage);
2275
+ }
2276
+ roleContent[role].push(part);
2277
+ break;
2278
+ }
2279
+ case "tool-result": {
2280
+ if (role === `assistant` || role === `user`) {
2281
+ throw new Error(incompatibleMessage);
2282
+ }
2283
+ roleContent[role].push(part);
2284
+ break;
2285
+ }
2286
+ case "image": {
2287
+ if (role === `tool` || role === `assistant`) {
2288
+ throw new Error(incompatibleMessage);
2289
+ }
2290
+ let processedImage;
2291
+ if (part.image instanceof URL || part.image instanceof Uint8Array) {
2292
+ processedImage = part.image;
2293
+ } else if (Buffer.isBuffer(part.image) || part.image instanceof ArrayBuffer) {
2294
+ processedImage = new Uint8Array(part.image);
2295
+ } else {
2296
+ const categorized = categorizeFileData(part.image, part.mimeType);
2297
+ if (categorized.type === "raw") {
2298
+ const dataUri = createDataUri(part.image, part.mimeType || "image/png");
2299
+ processedImage = new URL(dataUri);
2300
+ } else {
2301
+ processedImage = new URL(part.image);
2302
+ }
2303
+ }
2304
+ roleContent[role].push({
2305
+ ...part,
2306
+ image: processedImage
2307
+ });
2308
+ break;
2309
+ }
2310
+ case "file": {
2311
+ if (role === `tool`) {
2312
+ throw new Error(incompatibleMessage);
2313
+ }
2314
+ roleContent[role].push({
2315
+ ...part,
2316
+ data: part.data instanceof URL ? part.data : typeof part.data === "string" ? part.data : convertDataContentToBase64String(part.data)
2317
+ });
2318
+ break;
2319
+ }
2320
+ }
2321
+ }
2322
+ if (role === `tool`) {
2323
+ return {
2324
+ ...coreMessage,
2325
+ content: roleContent[role]
2326
+ };
2327
+ }
2328
+ if (role === `user`) {
2329
+ return {
2330
+ ...coreMessage,
2331
+ content: roleContent[role]
2332
+ };
2333
+ }
2334
+ if (role === `assistant`) {
2335
+ return {
2336
+ ...coreMessage,
2337
+ content: roleContent[role]
2338
+ };
2339
+ }
2340
+ throw new Error(
2341
+ `Encountered unknown role ${role} when converting V4 CoreMessage -> V4 LanguageModelV1Prompt, input message: ${JSON.stringify(coreMessage, null, 2)}`
2342
+ );
2343
+ }
2344
+ static aiV5ModelMessageToV2PromptMessage(modelMessage) {
2345
+ if (modelMessage.role === `system`) {
2346
+ return modelMessage;
2347
+ }
2348
+ if (typeof modelMessage.content === `string` && (modelMessage.role === `assistant` || modelMessage.role === `user`)) {
2349
+ return {
2350
+ role: modelMessage.role,
2351
+ content: [{ type: "text", text: modelMessage.content }],
2352
+ providerOptions: modelMessage.providerOptions
2353
+ };
2354
+ }
2355
+ if (typeof modelMessage.content === `string`) {
2356
+ throw new Error(
2357
+ `Saw text content for input ModelMessage, but the role is ${modelMessage.role}. This is only allowed for "system", "assistant", and "user" roles.`
2358
+ );
2359
+ }
2360
+ const roleContent = {
2361
+ user: [],
2362
+ assistant: [],
2363
+ tool: []
2364
+ };
2365
+ const role = modelMessage.role;
2366
+ for (const part of modelMessage.content) {
2367
+ const incompatibleMessage = `Saw incompatible message content part type ${part.type} for message role ${role}`;
2368
+ switch (part.type) {
2369
+ case "text": {
2370
+ if (role === `tool`) {
2371
+ throw new Error(incompatibleMessage);
2372
+ }
2373
+ roleContent[role].push(part);
2374
+ break;
2375
+ }
2376
+ case "reasoning": {
2377
+ if (role === `tool` || role === `user`) {
2378
+ throw new Error(incompatibleMessage);
2379
+ }
2380
+ roleContent[role].push(part);
2381
+ break;
2382
+ }
2383
+ case "tool-call": {
2384
+ if (role !== `assistant`) {
2385
+ throw new Error(incompatibleMessage);
2386
+ }
2387
+ roleContent[role].push(part);
2388
+ break;
2389
+ }
2390
+ case "tool-result": {
2391
+ if (role === `assistant` || role === `user`) {
2392
+ throw new Error(incompatibleMessage);
2393
+ }
2394
+ roleContent[role].push(part);
2395
+ break;
2396
+ }
2397
+ case "file": {
2398
+ if (role === `tool`) {
2399
+ throw new Error(incompatibleMessage);
2400
+ }
2401
+ roleContent[role].push({
2402
+ ...part,
2403
+ data: part.data instanceof ArrayBuffer ? new Uint8Array(part.data) : part.data
2404
+ });
2405
+ break;
2406
+ }
2407
+ case "image": {
2408
+ if (role === `tool`) {
2409
+ throw new Error(incompatibleMessage);
2410
+ }
2411
+ roleContent[role].push({
2412
+ ...part,
2413
+ mediaType: part.mediaType || "image/unknown",
2414
+ type: "file",
2415
+ data: part.image instanceof ArrayBuffer ? new Uint8Array(part.image) : part.image
2416
+ });
2417
+ break;
2418
+ }
2419
+ }
2420
+ }
2421
+ if (role === `tool`) {
2422
+ return {
2423
+ ...modelMessage,
2424
+ content: roleContent[role]
2425
+ };
2426
+ }
2427
+ if (role === `user`) {
2428
+ return {
2429
+ ...modelMessage,
2430
+ content: roleContent[role]
2431
+ };
2432
+ }
2433
+ if (role === `assistant`) {
2434
+ return {
2435
+ ...modelMessage,
2436
+ content: roleContent[role]
2437
+ };
2438
+ }
2439
+ throw new Error(
2440
+ `Encountered unknown role ${role} when converting V5 ModelMessage -> V5 LanguageModelV2Message, input message: ${JSON.stringify(modelMessage, null, 2)}`
2441
+ );
2442
+ }
2443
+ static mastraMessageV3ToV2(v3Msg) {
2444
+ const toolInvocationParts = v3Msg.content.parts.filter((p) => AIV5__namespace.isToolUIPart(p));
2445
+ const hadToolInvocations = v3Msg.content.metadata?.__hadToolInvocations === true;
2446
+ let toolInvocations = void 0;
2447
+ if (toolInvocationParts.length > 0) {
2448
+ const invocations = toolInvocationParts.map((p) => {
2449
+ const toolName = getToolName(p);
2450
+ if (p.state === `output-available`) {
2451
+ return {
2452
+ args: p.input,
2453
+ result: typeof p.output === "object" && p.output && "value" in p.output ? p.output.value : p.output,
2454
+ toolCallId: p.toolCallId,
2455
+ toolName,
2456
+ state: "result"
2457
+ };
2458
+ }
2459
+ return {
2460
+ args: p.input,
2461
+ state: "call",
2462
+ toolName,
2463
+ toolCallId: p.toolCallId
2464
+ };
2465
+ });
2466
+ toolInvocations = invocations;
2467
+ } else if (hadToolInvocations && v3Msg.role === "assistant") {
2468
+ toolInvocations = [];
2469
+ }
2470
+ const attachmentUrls = new Set(v3Msg.content.metadata?.__attachmentUrls || []);
2471
+ const v2Msg = {
2472
+ id: v3Msg.id,
2473
+ resourceId: v3Msg.resourceId,
2474
+ threadId: v3Msg.threadId,
2475
+ createdAt: v3Msg.createdAt,
2476
+ role: v3Msg.role,
2477
+ content: {
2478
+ format: 2,
2479
+ parts: v3Msg.content.parts.map((p) => {
2480
+ if (AIV5__namespace.isToolUIPart(p) || p.type === "dynamic-tool") {
2481
+ const toolName = getToolName(p);
2482
+ const shared = {
2483
+ state: p.state,
2484
+ args: p.input,
2485
+ toolCallId: p.toolCallId,
2486
+ toolName
2487
+ };
2488
+ if (p.state === `output-available`) {
2489
+ return {
2490
+ type: "tool-invocation",
2491
+ toolInvocation: {
2492
+ ...shared,
2493
+ state: "result",
2494
+ result: typeof p.output === "object" && p.output && "value" in p.output ? p.output.value : p.output
2495
+ },
2496
+ providerMetadata: p.callProviderMetadata
2497
+ };
2498
+ }
2499
+ return {
2500
+ type: "tool-invocation",
2501
+ toolInvocation: {
2502
+ ...shared,
2503
+ state: p.state === `input-available` ? `call` : `partial-call`
2504
+ }
2505
+ };
2506
+ }
2507
+ switch (p.type) {
2508
+ case "text":
2509
+ return p;
2510
+ case "file": {
2511
+ const fileDataSource = "url" in p && typeof p.url === "string" ? p.url : "data" in p && typeof p.data === "string" ? p.data : void 0;
2512
+ if (!fileDataSource) {
2513
+ return null;
2514
+ }
2515
+ if (attachmentUrls.has(fileDataSource)) {
2516
+ return null;
2517
+ }
2518
+ return {
2519
+ type: "file",
2520
+ mimeType: p.mediaType,
2521
+ data: fileDataSource,
2522
+ ...p.providerMetadata ? { providerMetadata: p.providerMetadata } : {}
2523
+ };
2524
+ }
2525
+ case "reasoning":
2526
+ if (p.text === "" && !p.providerMetadata) return null;
2527
+ return {
2528
+ type: "reasoning",
2529
+ // Keep reasoning field empty to match the format used in llm-execution-step
2530
+ // This ensures cache keys match for deduplication when merging assistant messages
2531
+ reasoning: "",
2532
+ details: p.text ? [{ type: "text", text: p.text }] : [],
2533
+ providerMetadata: p.providerMetadata
2534
+ };
2535
+ case "source-url":
2536
+ return {
2537
+ type: "source",
2538
+ source: {
2539
+ url: p.url,
2540
+ id: p.sourceId,
2541
+ sourceType: "url"
2542
+ },
2543
+ providerMetadata: p.providerMetadata
2544
+ };
2545
+ case "step-start":
2546
+ return p;
2547
+ }
2548
+ return null;
2549
+ }).filter((p) => Boolean(p))
2550
+ }
2551
+ };
2552
+ if (toolInvocations !== void 0) {
2553
+ v2Msg.content.toolInvocations = toolInvocations;
2554
+ }
2555
+ if (v3Msg.content.metadata) {
2556
+ const { __originalContent, __originalExperimentalAttachments, __attachmentUrls, ...userMetadata } = v3Msg.content.metadata;
2557
+ v2Msg.content.metadata = userMetadata;
2558
+ }
2559
+ const originalContent = v3Msg.content.metadata?.__originalContent;
2560
+ if (originalContent !== void 0) {
2561
+ const hasOnlyTextOrStepStart = v2Msg.content.parts.every((p) => p.type === `step-start` || p.type === `text`);
2562
+ if (typeof originalContent === `string` || hasOnlyTextOrStepStart) {
2563
+ v2Msg.content.content = originalContent;
2564
+ }
2565
+ }
2566
+ const originalAttachments = v3Msg.content.metadata?.__originalExperimentalAttachments;
2567
+ if (originalAttachments && Array.isArray(originalAttachments)) {
2568
+ v2Msg.content.experimental_attachments = originalAttachments || [];
2569
+ }
2570
+ const originalContentIsV5 = Array.isArray(v3Msg.content.metadata?.__originalContent) && v3Msg.content.metadata?.__originalContent.some((part) => part.type === "file");
2571
+ const urlFileParts = originalContentIsV5 ? [] : v2Msg.content.parts.filter(
2572
+ (p) => p.type === "file" && typeof p.data === "string" && (p.data.startsWith("http://") || p.data.startsWith("https://")) && !p.providerMetadata
2573
+ // Don't move if it has providerMetadata (needed for roundtrip)
2574
+ );
2575
+ if (urlFileParts.length > 0) {
2576
+ if (!v2Msg.content.experimental_attachments) {
2577
+ v2Msg.content.experimental_attachments = [];
2578
+ }
2579
+ for (const urlPart of urlFileParts) {
2580
+ if (urlPart.type === "file") {
2581
+ v2Msg.content.experimental_attachments.push({
2582
+ url: urlPart.data,
2583
+ contentType: urlPart.mimeType
2584
+ });
2585
+ }
2586
+ }
2587
+ v2Msg.content.parts = v2Msg.content.parts.filter(
2588
+ (p) => !(p.type === "file" && typeof p.data === "string" && (p.data.startsWith("http://") || p.data.startsWith("https://")) && !p.providerMetadata)
2589
+ );
2590
+ }
2591
+ if (toolInvocations && toolInvocations.length > 0) {
2592
+ const resultToolInvocations = toolInvocations.filter((t) => t.state === "result");
2593
+ if (resultToolInvocations.length > 0) {
2594
+ v2Msg.content.toolInvocations = resultToolInvocations;
2595
+ }
2596
+ }
2597
+ if (v3Msg.type) v2Msg.type = v3Msg.type;
2598
+ return v2Msg;
2599
+ }
2600
+ mastraMessageV2ToMastraMessageV3(v2Msg) {
2601
+ const parts = [];
2602
+ const v3Msg = {
2603
+ id: v2Msg.id,
2604
+ content: {
2605
+ format: 3,
2606
+ parts
2607
+ },
2608
+ role: v2Msg.role,
2609
+ createdAt: v2Msg.createdAt instanceof Date ? v2Msg.createdAt : new Date(v2Msg.createdAt),
2610
+ resourceId: v2Msg.resourceId,
2611
+ threadId: v2Msg.threadId,
2612
+ type: v2Msg.type
2613
+ };
2614
+ if (v2Msg.content.metadata) {
2615
+ v3Msg.content.metadata = { ...v2Msg.content.metadata };
2616
+ }
2617
+ if (v2Msg.content.providerMetadata) {
2618
+ v3Msg.content.providerMetadata = v2Msg.content.providerMetadata;
2619
+ }
2620
+ if (v2Msg.content.content !== void 0) {
2621
+ v3Msg.content.metadata = {
2622
+ ...v3Msg.content.metadata || {},
2623
+ __originalContent: v2Msg.content.content
2624
+ };
2625
+ }
2626
+ if (v2Msg.content.experimental_attachments !== void 0) {
2627
+ v3Msg.content.metadata = {
2628
+ ...v3Msg.content.metadata || {},
2629
+ __originalExperimentalAttachments: v2Msg.content.experimental_attachments
2630
+ };
2631
+ }
2632
+ const fileUrls = /* @__PURE__ */ new Set();
2633
+ for (const part of v2Msg.content.parts) {
2634
+ switch (part.type) {
2635
+ case "step-start":
2636
+ case "text":
2637
+ parts.push(part);
2638
+ break;
2639
+ case "tool-invocation":
2640
+ if (part.toolInvocation.state === `result`) {
2641
+ parts.push({
2642
+ type: `tool-${part.toolInvocation.toolName}`,
2643
+ toolCallId: part.toolInvocation.toolCallId,
2644
+ state: "output-available",
2645
+ input: part.toolInvocation.args,
2646
+ output: part.toolInvocation.result,
2647
+ callProviderMetadata: part.providerMetadata
2648
+ });
2649
+ } else {
2650
+ const toolPart = {
2651
+ type: `tool-${part.toolInvocation.toolName}`,
2652
+ toolCallId: part.toolInvocation.toolCallId,
2653
+ state: part.toolInvocation.state === `call` ? `input-available` : `input-streaming`,
2654
+ input: part.toolInvocation.args
2655
+ };
2656
+ if (part.providerMetadata) {
2657
+ toolPart.callProviderMetadata = part.providerMetadata;
2658
+ }
2659
+ parts.push(toolPart);
2660
+ }
2661
+ break;
2662
+ case "source":
2663
+ parts.push({
2664
+ type: "source-url",
2665
+ sourceId: part.source.id,
2666
+ url: part.source.url,
2667
+ title: part.source.title,
2668
+ providerMetadata: part.source.providerMetadata || part.providerMetadata
2669
+ });
2670
+ break;
2671
+ case "reasoning":
2672
+ const text = part.reasoning || (part.details?.reduce((p, c) => {
2673
+ if (c.type === `text`) return p + c.text;
2674
+ return p;
2675
+ }, "") ?? "");
2676
+ if (text || part.details?.length || part.providerMetadata) {
2677
+ parts.push({
2678
+ type: "reasoning",
2679
+ text: text || "",
2680
+ state: "done",
2681
+ providerMetadata: part.providerMetadata
2682
+ });
2683
+ }
2684
+ break;
2685
+ case "file": {
2686
+ const categorized = typeof part.data === "string" ? categorizeFileData(part.data, part.mimeType) : { type: "raw", mimeType: part.mimeType};
2687
+ if (categorized.type === "url" && typeof part.data === "string") {
2688
+ parts.push({
2689
+ type: "file",
2690
+ url: part.data,
2691
+ mediaType: categorized.mimeType || "image/png",
2692
+ ...part.providerMetadata ? { providerMetadata: part.providerMetadata } : {}
2693
+ });
2694
+ fileUrls.add(part.data);
2695
+ } else {
2696
+ let filePartData;
2697
+ let extractedMimeType = part.mimeType;
2698
+ if (typeof part.data === "string") {
2699
+ const parsed = parseDataUri(part.data);
2700
+ if (parsed.isDataUri) {
2701
+ filePartData = parsed.base64Content;
2702
+ if (parsed.mimeType) {
2703
+ extractedMimeType = extractedMimeType || parsed.mimeType;
2704
+ }
2705
+ } else {
2706
+ filePartData = part.data;
2707
+ }
2708
+ } else {
2709
+ filePartData = part.data;
2710
+ }
2711
+ const finalMimeType = extractedMimeType || "image/png";
2712
+ let dataUri;
2713
+ if (typeof filePartData === "string" && filePartData.startsWith("data:")) {
2714
+ dataUri = filePartData;
2715
+ } else {
2716
+ dataUri = createDataUri(filePartData, finalMimeType);
2717
+ }
2718
+ parts.push({
2719
+ type: "file",
2720
+ url: dataUri,
2721
+ // Use url field with data URI
2722
+ mediaType: finalMimeType,
2723
+ ...part.providerMetadata ? { providerMetadata: part.providerMetadata } : {}
2724
+ });
2725
+ }
2726
+ fileUrls.add(part.data);
2727
+ break;
2728
+ }
2729
+ }
2730
+ }
2731
+ if (v2Msg.content.content && !v3Msg.content.parts?.some((p) => p.type === `text`)) {
2732
+ v3Msg.content.parts.push({ type: "text", text: v2Msg.content.content });
2733
+ }
2734
+ const attachmentUrls = [];
2735
+ if (v2Msg.content.experimental_attachments?.length) {
2736
+ for (const attachment of v2Msg.content.experimental_attachments) {
2737
+ if (fileUrls.has(attachment.url)) continue;
2738
+ attachmentUrls.push(attachment.url);
2739
+ parts.push({
2740
+ url: attachment.url,
2741
+ mediaType: attachment.contentType || "unknown",
2742
+ type: "file"
2743
+ });
2744
+ }
2745
+ }
2746
+ if (attachmentUrls.length > 0) {
2747
+ v3Msg.content.metadata = {
2748
+ ...v3Msg.content.metadata || {},
2749
+ __attachmentUrls: attachmentUrls
2750
+ };
2751
+ }
2752
+ return v3Msg;
2753
+ }
2754
+ aiV5UIMessagesToAIV5ModelMessages(messages) {
2755
+ const sanitized = this.sanitizeV5UIMessages(messages);
2756
+ const preprocessed = this.addStartStepPartsForAIV5(sanitized);
2757
+ const result = AIV5__namespace.convertToModelMessages(preprocessed);
2758
+ const finalResult = result.map((modelMsg, index) => {
2759
+ const uiMsg = preprocessed[index];
2760
+ let updatedMsg = modelMsg;
2761
+ if (uiMsg?.metadata && typeof uiMsg.metadata === "object" && "providerMetadata" in uiMsg.metadata && uiMsg.metadata.providerMetadata) {
2762
+ updatedMsg = {
2763
+ ...updatedMsg,
2764
+ providerOptions: uiMsg.metadata.providerMetadata
2765
+ };
2766
+ }
2767
+ if (updatedMsg.role === "assistant" && Array.isArray(updatedMsg.content)) {
2768
+ const updatedContent = updatedMsg.content.map((part, partIndex) => {
2769
+ if (part.type === "tool-call") {
2770
+ const uiPart = uiMsg?.parts[partIndex];
2771
+ if (uiPart && "callProviderMetadata" in uiPart && uiPart.callProviderMetadata) {
2772
+ return {
2773
+ ...part,
2774
+ providerOptions: uiPart.callProviderMetadata
2775
+ };
2776
+ }
2777
+ }
2778
+ if (part.type === "reasoning") {
2779
+ const uiPart = uiMsg?.parts[partIndex];
2780
+ if (uiPart && "providerMetadata" in uiPart && uiPart.providerMetadata) {
2781
+ return {
2782
+ ...part,
2783
+ providerOptions: uiPart.providerMetadata
2784
+ };
2785
+ }
2786
+ }
2787
+ return part;
2788
+ });
2789
+ return {
2790
+ ...updatedMsg,
2791
+ content: updatedContent
2792
+ };
2793
+ }
2794
+ return updatedMsg;
2795
+ });
2796
+ return finalResult;
2797
+ }
2798
+ addStartStepPartsForAIV5(messages) {
2799
+ for (const message of messages) {
2800
+ if (message.role !== `assistant`) continue;
2801
+ for (const [index, part] of message.parts.entries()) {
2802
+ if (!AIV5__namespace.isToolUIPart(part)) continue;
2803
+ const nextPart = message.parts.at(index + 1);
2804
+ if (nextPart && nextPart.type !== `step-start` && !AIV5__namespace.isToolUIPart(nextPart)) {
2805
+ message.parts.splice(index + 1, 0, { type: "step-start" });
2806
+ }
2807
+ }
2808
+ }
2809
+ return messages;
2810
+ }
2811
+ sanitizeV5UIMessages(messages) {
2812
+ const msgs = messages.map((m) => {
2813
+ if (m.parts.length === 0) return false;
2814
+ const safeParts = m.parts.filter((p) => {
2815
+ if (!AIV5__namespace.isToolUIPart(p)) return true;
2816
+ return p.state === "output-available" || p.state === "output-error";
2817
+ });
2818
+ if (!safeParts.length) return false;
2819
+ const sanitized = {
2820
+ ...m,
2821
+ parts: safeParts.map((part) => {
2822
+ if (AIV5__namespace.isToolUIPart(part) && part.state === "output-available") {
2823
+ return {
2824
+ ...part,
2825
+ output: typeof part.output === "object" && part.output && "value" in part.output ? part.output.value : part.output
2826
+ };
2827
+ }
2828
+ return part;
2829
+ })
2830
+ };
2831
+ return sanitized;
2832
+ }).filter((m) => Boolean(m));
2833
+ return msgs;
2834
+ }
2835
+ static mastraMessageV3ToAIV5UIMessage(m) {
2836
+ const { __originalContent, ...cleanMetadata } = m.content.metadata || {};
2837
+ const metadata = {
2838
+ ...cleanMetadata
2839
+ };
2840
+ if (m.createdAt) metadata.createdAt = m.createdAt;
2841
+ if (m.threadId) metadata.threadId = m.threadId;
2842
+ if (m.resourceId) metadata.resourceId = m.resourceId;
2843
+ if (m.content.providerMetadata) metadata.providerMetadata = m.content.providerMetadata;
2844
+ const filteredParts = m.content.parts;
2845
+ return {
2846
+ id: m.id,
2847
+ role: m.role,
2848
+ metadata,
2849
+ parts: filteredParts
2850
+ };
2851
+ }
2852
+ aiV5ModelMessagesToAIV4CoreMessages(messages, messageSource) {
2853
+ const v3 = messages.map((msg) => this.aiV5ModelMessageToMastraMessageV3(msg, messageSource));
2854
+ const v2 = v3.map(_MessageList.mastraMessageV3ToV2);
2855
+ const ui = v2.map(_MessageList.mastraMessageV2ToAIV4UIMessage);
2856
+ const core = this.aiV4UIMessagesToAIV4CoreMessages(ui);
2857
+ return core;
2858
+ }
2859
+ aiV4CoreMessagesToAIV5ModelMessages(messages, source) {
2860
+ return this.aiV5UIMessagesToAIV5ModelMessages(
2861
+ messages.map((m) => this.aiV4CoreMessageToMastraMessageV2(m, source)).map((m) => this.mastraMessageV2ToMastraMessageV3(m)).map((m) => _MessageList.mastraMessageV3ToAIV5UIMessage(m))
2862
+ );
2863
+ }
2864
+ aiV5UIMessageToMastraMessageV3(message, messageSource) {
2865
+ const content = {
2866
+ format: 3,
2867
+ parts: message.parts,
2868
+ metadata: message.metadata
2869
+ };
2870
+ const metadata = message.metadata;
2871
+ const createdAt = (() => {
2872
+ if ("createdAt" in message && message.createdAt instanceof Date) {
2873
+ return message.createdAt;
2874
+ }
2875
+ if (metadata && "createdAt" in metadata && metadata.createdAt instanceof Date) {
2876
+ return metadata.createdAt;
2877
+ }
2878
+ return void 0;
2879
+ })();
2880
+ if ("metadata" in message && message.metadata) {
2881
+ content.metadata = { ...message.metadata };
2882
+ }
2883
+ return {
2884
+ id: message.id || this.newMessageId(),
2885
+ role: _MessageList.getRole(message),
2886
+ createdAt: this.generateCreatedAt(messageSource, createdAt),
2887
+ threadId: this.memoryInfo?.threadId,
2888
+ resourceId: this.memoryInfo?.resourceId,
2889
+ content
2890
+ };
2891
+ }
2892
+ aiV5ModelMessageToMastraMessageV3(coreMessage, messageSource) {
2893
+ const id = `id` in coreMessage && typeof coreMessage.id === `string` ? coreMessage.id : this.newMessageId();
2894
+ const parts = [];
2895
+ if (typeof coreMessage.content === "string") {
2896
+ parts.push({
2897
+ type: "text",
2898
+ text: coreMessage.content,
2899
+ // Preserve providerOptions from ModelMessage level (e.g., system messages with cacheControl)
2900
+ ..."providerOptions" in coreMessage && coreMessage.providerOptions ? { providerMetadata: coreMessage.providerOptions } : {}
2901
+ });
2902
+ } else if (Array.isArray(coreMessage.content)) {
2903
+ for (const part of coreMessage.content) {
2904
+ switch (part.type) {
2905
+ case "text":
2906
+ const prevPart = parts.at(-1);
2907
+ if (coreMessage.role === "assistant" && prevPart && AIV5__namespace.isToolUIPart(prevPart) && prevPart.state === "output-available") {
2908
+ parts.push({
2909
+ type: "step-start"
2910
+ });
2911
+ }
2912
+ const mergedProviderMetadataV3 = {
2913
+ ..."providerOptions" in coreMessage && coreMessage.providerOptions ? coreMessage.providerOptions : {},
2914
+ ...part.providerOptions || {}
2915
+ };
2916
+ parts.push({
2917
+ type: "text",
2918
+ text: part.text,
2919
+ ...Object.keys(mergedProviderMetadataV3).length > 0 ? { providerMetadata: mergedProviderMetadataV3 } : {}
2920
+ });
2921
+ break;
2922
+ case "tool-call":
2923
+ parts.push({
2924
+ type: `tool-${part.toolName}`,
2925
+ state: "input-available",
2926
+ toolCallId: part.toolCallId,
2927
+ input: part.input
2928
+ });
2929
+ break;
2930
+ case "tool-result":
2931
+ parts.push({
2932
+ type: `tool-${part.toolName}`,
2933
+ state: "output-available",
2934
+ toolCallId: part.toolCallId,
2935
+ output: typeof part.output === "string" ? { type: "text", value: part.output } : part.output ?? { type: "text", value: "" },
2936
+ input: {},
2937
+ callProviderMetadata: part.providerOptions
2938
+ });
2939
+ break;
2940
+ case "reasoning":
2941
+ parts.push({
2942
+ type: "reasoning",
2943
+ text: part.text,
2944
+ providerMetadata: part.providerOptions
2945
+ });
2946
+ break;
2947
+ case "image": {
2948
+ let imageData;
2949
+ let extractedMimeType = part.mediaType;
2950
+ const imageStr = imageContentToDataUri(part.image, extractedMimeType || "image/png");
2951
+ const parsed = parseDataUri(imageStr);
2952
+ if (parsed.isDataUri) {
2953
+ imageData = parsed.base64Content;
2954
+ if (!extractedMimeType && parsed.mimeType) {
2955
+ extractedMimeType = parsed.mimeType;
2956
+ }
2957
+ } else if (imageStr.startsWith("http://") || imageStr.startsWith("https://")) {
2958
+ parts.push({
2959
+ type: "file",
2960
+ url: imageStr,
2961
+ mediaType: part.mediaType || "image/jpeg",
2962
+ // Default to image/jpeg for URLs
2963
+ providerMetadata: part.providerOptions
2964
+ });
2965
+ break;
2966
+ } else {
2967
+ imageData = imageStr;
2968
+ }
2969
+ const finalMimeType = extractedMimeType || "image/jpeg";
2970
+ const dataUri = imageData.startsWith("data:") ? imageData : createDataUri(imageData, finalMimeType);
2971
+ parts.push({
2972
+ type: "file",
2973
+ url: dataUri,
2974
+ mediaType: finalMimeType,
2975
+ providerMetadata: part.providerOptions
2976
+ });
2977
+ break;
2978
+ }
2979
+ case "file": {
2980
+ if (part.data instanceof URL) {
2981
+ const urlStr = part.data.toString();
2982
+ let extractedMimeType = part.mediaType;
2983
+ const parsed = parseDataUri(urlStr);
2984
+ if (parsed.isDataUri) {
2985
+ if (!extractedMimeType && parsed.mimeType) {
2986
+ extractedMimeType = parsed.mimeType;
2987
+ }
2988
+ if (parsed.base64Content !== urlStr) {
2989
+ const dataUri = createDataUri(parsed.base64Content, extractedMimeType || "image/png");
2990
+ parts.push({
2991
+ type: "file",
2992
+ url: dataUri,
2993
+ mediaType: extractedMimeType || "image/png",
2994
+ providerMetadata: part.providerOptions
2995
+ });
2996
+ } else {
2997
+ parts.push({
2998
+ type: "file",
2999
+ url: urlStr,
3000
+ mediaType: part.mediaType || "image/png",
3001
+ providerMetadata: part.providerOptions
3002
+ });
3003
+ }
3004
+ } else {
3005
+ parts.push({
3006
+ type: "file",
3007
+ url: urlStr,
3008
+ mediaType: part.mediaType || "application/octet-stream",
3009
+ providerMetadata: part.providerOptions
3010
+ });
3011
+ }
3012
+ } else if (typeof part.data === "string") {
3013
+ const categorized = categorizeFileData(part.data, part.mediaType);
3014
+ if (categorized.type === "url" || categorized.type === "dataUri") {
3015
+ parts.push({
3016
+ type: "file",
3017
+ url: part.data,
3018
+ mediaType: categorized.mimeType || "application/octet-stream",
3019
+ providerMetadata: part.providerOptions
3020
+ });
3021
+ } else {
3022
+ try {
3023
+ const base64Data = convertDataContentToBase64String(part.data);
3024
+ const dataUri = createDataUri(base64Data, categorized.mimeType || "image/png");
3025
+ parts.push({
3026
+ type: "file",
3027
+ url: dataUri,
3028
+ mediaType: categorized.mimeType || "image/png",
3029
+ providerMetadata: part.providerOptions
3030
+ });
3031
+ } catch (error) {
3032
+ console.error(`Failed to convert binary data to base64 in CoreMessage file part: ${error}`, error);
3033
+ }
3034
+ }
3035
+ } else {
3036
+ try {
3037
+ const base64Data = convertDataContentToBase64String(part.data);
3038
+ const dataUri = createDataUri(base64Data, part.mediaType || "image/png");
3039
+ parts.push({
3040
+ type: "file",
3041
+ url: dataUri,
3042
+ mediaType: part.mediaType || "image/png",
3043
+ providerMetadata: part.providerOptions
3044
+ });
3045
+ } catch (error) {
3046
+ console.error(`Failed to convert binary data to base64 in CoreMessage file part: ${error}`, error);
3047
+ }
3048
+ }
3049
+ break;
3050
+ }
3051
+ }
3052
+ }
3053
+ }
3054
+ const content = {
3055
+ format: 3,
3056
+ parts
3057
+ };
3058
+ if ("metadata" in coreMessage && coreMessage.metadata !== null && coreMessage.metadata !== void 0) {
3059
+ content.metadata = {
3060
+ ...content.metadata || {},
3061
+ ...coreMessage.metadata
3062
+ };
3063
+ }
3064
+ if (coreMessage.content) {
3065
+ content.metadata = {
3066
+ ...content.metadata || {},
3067
+ __originalContent: coreMessage.content
3068
+ };
3069
+ }
3070
+ return {
3071
+ id,
3072
+ role: _MessageList.getRole(coreMessage),
3073
+ createdAt: this.generateCreatedAt(messageSource),
3074
+ threadId: this.memoryInfo?.threadId,
3075
+ resourceId: this.memoryInfo?.resourceId,
3076
+ content
3077
+ };
3078
+ }
3079
+ static hasAIV5UIMessageCharacteristics(msg) {
3080
+ if (`toolInvocations` in msg || `reasoning` in msg || `experimental_attachments` in msg || `data` in msg || `annotations` in msg)
3081
+ return false;
3082
+ if (!msg.parts) return false;
3083
+ for (const part of msg.parts) {
3084
+ if (`metadata` in part) return true;
3085
+ if (`toolInvocation` in part) return false;
3086
+ if (`toolCallId` in part) return true;
3087
+ if (part.type === `source`) return false;
3088
+ if (part.type === `source-url`) return true;
3089
+ if (part.type === `reasoning`) {
3090
+ if (`state` in part || `text` in part) return true;
3091
+ if (`reasoning` in part || `details` in part) return false;
3092
+ }
3093
+ if (part.type === `file` && `mediaType` in part) return true;
3094
+ }
3095
+ return false;
3096
+ }
3097
+ static isAIV5UIMessage(msg) {
3098
+ return !_MessageList.isMastraMessage(msg) && !_MessageList.isAIV5CoreMessage(msg) && `parts` in msg && _MessageList.hasAIV5UIMessageCharacteristics(msg);
3099
+ }
3100
+ static hasAIV5CoreMessageCharacteristics(msg) {
3101
+ if (`experimental_providerMetadata` in msg) return false;
3102
+ if (typeof msg.content === `string`) return false;
3103
+ for (const part of msg.content) {
3104
+ if (part.type === `tool-result` && `output` in part) return true;
3105
+ if (part.type === `tool-call` && `input` in part) return true;
3106
+ if (part.type === `tool-result` && `result` in part) return false;
3107
+ if (part.type === `tool-call` && `args` in part) return false;
3108
+ if (`mediaType` in part) return true;
3109
+ if (`mimeType` in part) return false;
3110
+ if (`experimental_providerMetadata` in part) return false;
3111
+ if (part.type === `reasoning` && `signature` in part) return false;
3112
+ if (part.type === `redacted-reasoning`) return false;
3113
+ }
3114
+ return false;
3115
+ }
3116
+ static cacheKeyFromAIV5Parts(parts) {
3117
+ let key = ``;
3118
+ for (const part of parts) {
3119
+ key += part.type;
3120
+ if (part.type === `text`) {
3121
+ key += part.text;
3122
+ }
3123
+ if (AIV5__namespace.isToolUIPart(part) || part.type === "dynamic-tool") {
3124
+ key += part.toolCallId;
3125
+ key += part.state;
3126
+ }
3127
+ if (part.type === `reasoning`) {
3128
+ key += part.text;
3129
+ }
3130
+ if (part.type === `file`) {
3131
+ key += part.url.length;
3132
+ key += part.mediaType;
3133
+ key += part.filename || "";
3134
+ }
3135
+ }
3136
+ return key;
3137
+ }
3138
+ static cacheKeyFromAIV5ModelMessageContent(content) {
3139
+ if (typeof content === `string`) return content;
3140
+ let key = ``;
3141
+ for (const part of content) {
3142
+ key += part.type;
3143
+ if (part.type === `text`) {
3144
+ key += part.text.length;
3145
+ }
3146
+ if (part.type === `reasoning`) {
3147
+ key += part.text.length;
3148
+ }
3149
+ if (part.type === `tool-call`) {
3150
+ key += part.toolCallId;
3151
+ key += part.toolName;
3152
+ }
3153
+ if (part.type === `tool-result`) {
3154
+ key += part.toolCallId;
3155
+ key += part.toolName;
3156
+ }
3157
+ if (part.type === `file`) {
3158
+ key += part.filename;
3159
+ key += part.mediaType;
3160
+ }
3161
+ if (part.type === `image`) {
3162
+ key += getImageCacheKey(part.image);
3163
+ key += part.mediaType;
3164
+ }
3165
+ }
3166
+ return key;
3167
+ }
3168
+ };
3169
+
3170
+ // src/agent/message-list/utils/convert-messages.ts
3171
+ var MessageConverter = class {
3172
+ messageList;
3173
+ constructor(messages) {
3174
+ this.messageList = new MessageList();
3175
+ this.messageList.add(messages, "memory");
3176
+ }
3177
+ to(format) {
3178
+ switch (format) {
3179
+ case "Mastra.V2":
3180
+ return this.messageList.get.all.v2();
3181
+ case "AIV4.UI":
3182
+ return this.messageList.get.all.aiV4.ui();
3183
+ case "AIV4.Core":
3184
+ return this.messageList.get.all.aiV4.core();
3185
+ case "AIV5.UI":
3186
+ return this.messageList.get.all.aiV5.ui();
3187
+ case "AIV5.Model":
3188
+ return this.messageList.get.all.aiV5.model();
3189
+ default:
3190
+ throw new Error(`Unsupported output format: ${format}`);
3191
+ }
3192
+ }
3193
+ };
3194
+ function convertMessages(messages) {
3195
+ return new MessageConverter(messages);
3196
+ }
3197
+
3198
+ exports.DefaultGeneratedFile = DefaultGeneratedFile;
3199
+ exports.DefaultGeneratedFileWithType = DefaultGeneratedFileWithType;
3200
+ exports.MessageList = MessageList;
3201
+ exports.convertMessages = convertMessages;
3202
+ //# sourceMappingURL=chunk-42RUESSD.cjs.map
3203
+ //# sourceMappingURL=chunk-42RUESSD.cjs.map