@mastra/core 0.24.5 → 0.24.6

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 (277) hide show
  1. package/CHANGELOG.md +612 -0
  2. package/dist/agent/agent.d.ts +8 -6
  3. package/dist/agent/agent.d.ts.map +1 -1
  4. package/dist/agent/agent.types.d.ts +2 -0
  5. package/dist/agent/agent.types.d.ts.map +1 -1
  6. package/dist/agent/index.cjs +13 -13
  7. package/dist/agent/index.js +2 -2
  8. package/dist/agent/input-processor/index.cjs +6 -6
  9. package/dist/agent/input-processor/index.js +1 -1
  10. package/dist/agent/message-list/index.d.ts.map +1 -1
  11. package/dist/agent/message-list/prompt/attachments-to-parts.d.ts.map +1 -1
  12. package/dist/agent/test-utils.d.ts +4 -3
  13. package/dist/agent/test-utils.d.ts.map +1 -1
  14. package/dist/agent/utils.d.ts.map +1 -1
  15. package/dist/agent/workflows/prepare-stream/index.d.ts +4 -4
  16. package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
  17. package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
  18. package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +4 -4
  19. package/dist/agent/workflows/prepare-stream/schema.d.ts +4 -4
  20. package/dist/agent/workflows/prepare-stream/stream-step.d.ts +8 -1
  21. package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
  22. package/dist/ai-tracing/index.cjs +36 -36
  23. package/dist/ai-tracing/index.js +1 -1
  24. package/dist/chunk-3PSWNGBF.js +3 -0
  25. package/dist/{chunk-ZV5CC35D.js.map → chunk-3PSWNGBF.js.map} +1 -1
  26. package/dist/{chunk-XHKMGOON.cjs → chunk-42RUESSD.cjs} +204 -150
  27. package/dist/chunk-42RUESSD.cjs.map +1 -0
  28. package/dist/{chunk-UD7DS7OY.cjs → chunk-46XGIEXM.cjs} +4 -4
  29. package/dist/{chunk-UD7DS7OY.cjs.map → chunk-46XGIEXM.cjs.map} +1 -1
  30. package/dist/{chunk-HGNRQ3OG.js → chunk-5O52O25J.js} +15 -8
  31. package/dist/chunk-5O52O25J.js.map +1 -0
  32. package/dist/{chunk-OLERJ2OU.js → chunk-6D2K2CAA.js} +7 -5
  33. package/dist/chunk-6D2K2CAA.js.map +1 -0
  34. package/dist/chunk-6XCINXZ7.cjs +194 -0
  35. package/dist/chunk-6XCINXZ7.cjs.map +1 -0
  36. package/dist/chunk-BJ6XIEC6.js +13 -0
  37. package/dist/chunk-BJ6XIEC6.js.map +1 -0
  38. package/dist/chunk-BWYU7D33.js +192 -0
  39. package/dist/chunk-BWYU7D33.js.map +1 -0
  40. package/dist/{chunk-R7UDZZA5.cjs → chunk-CT2DMHGC.cjs} +8 -8
  41. package/dist/{chunk-R7UDZZA5.cjs.map → chunk-CT2DMHGC.cjs.map} +1 -1
  42. package/dist/{chunk-YSQE5IHK.cjs → chunk-CYEQK4PM.cjs} +10 -8
  43. package/dist/chunk-CYEQK4PM.cjs.map +1 -0
  44. package/dist/{chunk-FCJ5INK7.js → chunk-DHLW4AP7.js} +3 -3
  45. package/dist/{chunk-FCJ5INK7.js.map → chunk-DHLW4AP7.js.map} +1 -1
  46. package/dist/{chunk-4UOIJRD6.cjs → chunk-GZDIHQDK.cjs} +4 -4
  47. package/dist/{chunk-4UOIJRD6.cjs.map → chunk-GZDIHQDK.cjs.map} +1 -1
  48. package/dist/{chunk-WCHE6FJ7.js → chunk-HCCXJ5YJ.js} +111 -6
  49. package/dist/chunk-HCCXJ5YJ.js.map +1 -0
  50. package/dist/{chunk-34ZCWSUA.js → chunk-HSX2K7HB.js} +15 -14
  51. package/dist/chunk-HSX2K7HB.js.map +1 -0
  52. package/dist/{chunk-LZFCR2SE.cjs → chunk-IAJHRFO4.cjs} +4 -4
  53. package/dist/{chunk-LZFCR2SE.cjs.map → chunk-IAJHRFO4.cjs.map} +1 -1
  54. package/dist/{chunk-4HQPVSGA.cjs → chunk-ICF3MCIN.cjs} +64 -12
  55. package/dist/chunk-ICF3MCIN.cjs.map +1 -0
  56. package/dist/{chunk-N2DOZAFH.js → chunk-INOOZ2A2.js} +760 -508
  57. package/dist/chunk-INOOZ2A2.js.map +1 -0
  58. package/dist/{chunk-3JX2Y3WH.cjs → chunk-IWU4YSYT.cjs} +16 -15
  59. package/dist/chunk-IWU4YSYT.cjs.map +1 -0
  60. package/dist/{chunk-3KVI2HLS.cjs → chunk-KWF3J2Q4.cjs} +11 -11
  61. package/dist/{chunk-3KVI2HLS.cjs.map → chunk-KWF3J2Q4.cjs.map} +1 -1
  62. package/dist/{chunk-TEW3ODXX.js → chunk-LAQQETGP.js} +36 -34
  63. package/dist/chunk-LAQQETGP.js.map +1 -0
  64. package/dist/{chunk-EUNOQ7HN.js → chunk-MRSBLBQ5.js} +4 -4
  65. package/dist/{chunk-EUNOQ7HN.js.map → chunk-MRSBLBQ5.js.map} +1 -1
  66. package/dist/{chunk-LLSLFDO6.js → chunk-NRQC7DQW.js} +57 -5
  67. package/dist/chunk-NRQC7DQW.js.map +1 -0
  68. package/dist/{chunk-WBAXXG34.cjs → chunk-PAOBGBU7.cjs} +112 -5
  69. package/dist/chunk-PAOBGBU7.cjs.map +1 -0
  70. package/dist/chunk-PE3V7GUL.cjs +4 -0
  71. package/dist/{chunk-LJFJTTZQ.cjs.map → chunk-PE3V7GUL.cjs.map} +1 -1
  72. package/dist/{chunk-DOLSYVNJ.cjs → chunk-PIH5FBNQ.cjs} +12 -12
  73. package/dist/{chunk-DOLSYVNJ.cjs.map → chunk-PIH5FBNQ.cjs.map} +1 -1
  74. package/dist/{chunk-4SXWN3RR.js → chunk-Q6LWNLAJ.js} +203 -149
  75. package/dist/chunk-Q6LWNLAJ.js.map +1 -0
  76. package/dist/{chunk-SL7VKAQ3.js → chunk-R6XC4DV5.js} +7 -7
  77. package/dist/chunk-R6XC4DV5.js.map +1 -0
  78. package/dist/{chunk-WNFLWMEP.cjs → chunk-RJOVFHWN.cjs} +765 -511
  79. package/dist/chunk-RJOVFHWN.cjs.map +1 -0
  80. package/dist/chunk-UCPGYU55.cjs +15 -0
  81. package/dist/chunk-UCPGYU55.cjs.map +1 -0
  82. package/dist/{chunk-K7MEUZ3O.js → chunk-UWTYVVVZ.js} +3 -3
  83. package/dist/{chunk-K7MEUZ3O.js.map → chunk-UWTYVVVZ.js.map} +1 -1
  84. package/dist/{chunk-ZISECZZO.js → chunk-VHEA3YXS.js} +2 -2
  85. package/dist/chunk-VHEA3YXS.js.map +1 -0
  86. package/dist/chunk-VXHOOZSK.js +446 -0
  87. package/dist/chunk-VXHOOZSK.js.map +1 -0
  88. package/dist/{chunk-NUAURT4I.cjs → chunk-W4UVO3HL.cjs} +2 -2
  89. package/dist/chunk-W4UVO3HL.cjs.map +1 -0
  90. package/dist/{chunk-ZIHEKHUB.js → chunk-WIMFJ2BA.js} +3 -3
  91. package/dist/{chunk-ZIHEKHUB.js.map → chunk-WIMFJ2BA.js.map} +1 -1
  92. package/dist/{chunk-LRSB62Z6.cjs → chunk-X7F4CSGR.cjs} +15 -8
  93. package/dist/chunk-X7F4CSGR.cjs.map +1 -0
  94. package/dist/{chunk-WUFFST2N.cjs → chunk-XDMQQZNX.cjs} +70 -68
  95. package/dist/chunk-XDMQQZNX.cjs.map +1 -0
  96. package/dist/chunk-XWGHD4C7.cjs +450 -0
  97. package/dist/chunk-XWGHD4C7.cjs.map +1 -0
  98. package/dist/{chunk-FZXAPBVV.js → chunk-Z6QCWTTO.js} +3 -3
  99. package/dist/{chunk-FZXAPBVV.js.map → chunk-Z6QCWTTO.js.map} +1 -1
  100. package/dist/{chunk-GWACPQ56.js → chunk-ZIWN73GQ.js} +5 -5
  101. package/dist/{chunk-GWACPQ56.js.map → chunk-ZIWN73GQ.js.map} +1 -1
  102. package/dist/{chunk-IJRERAWQ.cjs → chunk-ZOYE65RA.cjs} +8 -8
  103. package/dist/chunk-ZOYE65RA.cjs.map +1 -0
  104. package/dist/index.cjs +75 -54
  105. package/dist/index.cjs.map +1 -1
  106. package/dist/index.js +15 -10
  107. package/dist/index.js.map +1 -1
  108. package/dist/llm/index.cjs +24 -8
  109. package/dist/llm/index.d.ts +1 -0
  110. package/dist/llm/index.d.ts.map +1 -1
  111. package/dist/llm/index.js +5 -1
  112. package/dist/llm/model/gateways/base.d.ts +9 -4
  113. package/dist/llm/model/gateways/base.d.ts.map +1 -1
  114. package/dist/llm/model/gateways/index.d.ts +3 -1
  115. package/dist/llm/model/gateways/index.d.ts.map +1 -1
  116. package/dist/llm/model/gateways/models-dev.d.ts +3 -2
  117. package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
  118. package/dist/llm/model/gateways/netlify.d.ts +4 -3
  119. package/dist/llm/model/gateways/netlify.d.ts.map +1 -1
  120. package/dist/llm/model/model.d.ts.map +1 -1
  121. package/dist/llm/model/model.loop.d.ts +1 -1
  122. package/dist/llm/model/model.loop.d.ts.map +1 -1
  123. package/dist/llm/model/provider-registry.d.ts +11 -1
  124. package/dist/llm/model/provider-registry.d.ts.map +1 -1
  125. package/dist/llm/model/provider-types.generated.d.ts +324 -29
  126. package/dist/llm/model/registry-generator.d.ts +12 -0
  127. package/dist/llm/model/registry-generator.d.ts.map +1 -1
  128. package/dist/llm/model/resolve-model.d.ts.map +1 -1
  129. package/dist/llm/model/router.d.ts +6 -1
  130. package/dist/llm/model/router.d.ts.map +1 -1
  131. package/dist/loop/index.cjs +2 -2
  132. package/dist/loop/index.js +1 -1
  133. package/dist/loop/loop.d.ts.map +1 -1
  134. package/dist/loop/network/index.d.ts +6 -6
  135. package/dist/loop/network/index.d.ts.map +1 -1
  136. package/dist/loop/test-utils/generateText.d.ts.map +1 -1
  137. package/dist/loop/test-utils/resultObject.d.ts.map +1 -1
  138. package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
  139. package/dist/loop/types.d.ts +8 -0
  140. package/dist/loop/types.d.ts.map +1 -1
  141. package/dist/loop/workflows/agentic-execution/index.d.ts +36 -36
  142. package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
  143. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +24 -24
  144. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
  145. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +12 -12
  146. package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts +1 -1
  147. package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
  148. package/dist/loop/workflows/agentic-loop/index.d.ts +36 -36
  149. package/dist/loop/workflows/schema.d.ts +16 -16
  150. package/dist/mastra/index.cjs +2 -2
  151. package/dist/mastra/index.d.ts +23 -0
  152. package/dist/mastra/index.d.ts.map +1 -1
  153. package/dist/mastra/index.js +1 -1
  154. package/dist/memory/index.cjs +4 -4
  155. package/dist/memory/index.js +1 -1
  156. package/dist/memory/types.d.ts +3 -2
  157. package/dist/memory/types.d.ts.map +1 -1
  158. package/dist/models-dev-LJ4O6FNF.js +3 -0
  159. package/dist/{models-dev-BL5TAKE6.js.map → models-dev-LJ4O6FNF.js.map} +1 -1
  160. package/dist/models-dev-T2CXOEDH.cjs +12 -0
  161. package/dist/{models-dev-HZ3LZHPX.cjs.map → models-dev-T2CXOEDH.cjs.map} +1 -1
  162. package/dist/netlify-BAEMIQNH.cjs +12 -0
  163. package/dist/{netlify-TX6V7SJJ.cjs.map → netlify-BAEMIQNH.cjs.map} +1 -1
  164. package/dist/netlify-L7AZ74PV.js +3 -0
  165. package/dist/{netlify-VJXBII33.js.map → netlify-L7AZ74PV.js.map} +1 -1
  166. package/dist/processors/index.cjs +11 -11
  167. package/dist/processors/index.js +1 -1
  168. package/dist/provider-registry-RUDYHG7J.cjs +40 -0
  169. package/dist/provider-registry-RUDYHG7J.cjs.map +1 -0
  170. package/dist/provider-registry-THITZUJ7.js +3 -0
  171. package/dist/provider-registry-THITZUJ7.js.map +1 -0
  172. package/dist/provider-registry.json +705 -68
  173. package/dist/{registry-generator-6WVOHM2L.cjs → registry-generator-DL42NMBM.cjs} +23 -6
  174. package/dist/registry-generator-DL42NMBM.cjs.map +1 -0
  175. package/dist/{registry-generator-DXRSYYYT.js → registry-generator-I6S4ARS6.js} +23 -7
  176. package/dist/registry-generator-I6S4ARS6.js.map +1 -0
  177. package/dist/relevance/index.cjs +4 -4
  178. package/dist/relevance/index.js +1 -1
  179. package/dist/scores/index.cjs +9 -9
  180. package/dist/scores/index.js +2 -2
  181. package/dist/scores/scoreTraces/index.cjs +8 -8
  182. package/dist/scores/scoreTraces/index.js +3 -3
  183. package/dist/server/composite-auth.d.ts +9 -0
  184. package/dist/server/composite-auth.d.ts.map +1 -0
  185. package/dist/server/index.cjs +83 -1
  186. package/dist/server/index.cjs.map +1 -1
  187. package/dist/server/index.d.ts +3 -0
  188. package/dist/server/index.d.ts.map +1 -1
  189. package/dist/server/index.js +82 -2
  190. package/dist/server/index.js.map +1 -1
  191. package/dist/server/simple-auth.d.ts +32 -0
  192. package/dist/server/simple-auth.d.ts.map +1 -0
  193. package/dist/storage/index.cjs +3 -3
  194. package/dist/storage/index.js +1 -1
  195. package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
  196. package/dist/stream/base/output.d.ts.map +1 -1
  197. package/dist/stream/index.cjs +11 -11
  198. package/dist/stream/index.js +2 -2
  199. package/dist/stream/types.d.ts +7 -2
  200. package/dist/stream/types.d.ts.map +1 -1
  201. package/dist/test-utils/llm-mock.cjs +2 -2
  202. package/dist/test-utils/llm-mock.js +1 -1
  203. package/dist/tools/index.cjs +2 -2
  204. package/dist/tools/index.js +1 -1
  205. package/dist/tools/stream.d.ts +1 -0
  206. package/dist/tools/stream.d.ts.map +1 -1
  207. package/dist/utils.cjs +17 -17
  208. package/dist/utils.js +1 -1
  209. package/dist/vector/filter/index.cjs +7 -189
  210. package/dist/vector/filter/index.cjs.map +1 -1
  211. package/dist/vector/filter/index.js +1 -190
  212. package/dist/vector/filter/index.js.map +1 -1
  213. package/dist/vector/index.cjs +9 -4
  214. package/dist/vector/index.d.ts +1 -0
  215. package/dist/vector/index.d.ts.map +1 -1
  216. package/dist/vector/index.js +2 -1
  217. package/dist/vector/types.d.ts +86 -3
  218. package/dist/vector/types.d.ts.map +1 -1
  219. package/dist/vector/vector.d.ts +39 -2
  220. package/dist/vector/vector.d.ts.map +1 -1
  221. package/dist/voice/aisdk/index.d.ts +3 -0
  222. package/dist/voice/aisdk/index.d.ts.map +1 -0
  223. package/dist/voice/aisdk/speech.d.ts +23 -0
  224. package/dist/voice/aisdk/speech.d.ts.map +1 -0
  225. package/dist/voice/aisdk/transcription.d.ts +22 -0
  226. package/dist/voice/aisdk/transcription.d.ts.map +1 -0
  227. package/dist/voice/composite-voice.d.ts +3 -2
  228. package/dist/voice/composite-voice.d.ts.map +1 -1
  229. package/dist/voice/index.cjs +12 -4
  230. package/dist/voice/index.d.ts +1 -0
  231. package/dist/voice/index.d.ts.map +1 -1
  232. package/dist/voice/index.js +1 -1
  233. package/dist/workflows/evented/index.cjs +10 -10
  234. package/dist/workflows/evented/index.js +1 -1
  235. package/dist/workflows/index.cjs +14 -14
  236. package/dist/workflows/index.js +1 -1
  237. package/dist/workflows/legacy/index.cjs +22 -22
  238. package/dist/workflows/legacy/index.js +1 -1
  239. package/dist/workflows/legacy/machine.d.ts +1 -1
  240. package/dist/workflows/legacy/workflow-instance.d.ts +2 -2
  241. package/dist/workflows/utils.d.ts.map +1 -1
  242. package/dist/workflows/workflow.d.ts +2 -0
  243. package/dist/workflows/workflow.d.ts.map +1 -1
  244. package/package.json +7 -7
  245. package/src/llm/model/provider-types.generated.d.ts +324 -29
  246. package/dist/chunk-34ZCWSUA.js.map +0 -1
  247. package/dist/chunk-3JX2Y3WH.cjs.map +0 -1
  248. package/dist/chunk-4HQPVSGA.cjs.map +0 -1
  249. package/dist/chunk-4SXWN3RR.js.map +0 -1
  250. package/dist/chunk-HF3GZRFP.cjs +0 -9
  251. package/dist/chunk-HF3GZRFP.cjs.map +0 -1
  252. package/dist/chunk-HGNRQ3OG.js.map +0 -1
  253. package/dist/chunk-IJRERAWQ.cjs.map +0 -1
  254. package/dist/chunk-LJFJTTZQ.cjs +0 -4
  255. package/dist/chunk-LLSLFDO6.js.map +0 -1
  256. package/dist/chunk-LRSB62Z6.cjs.map +0 -1
  257. package/dist/chunk-N2DOZAFH.js.map +0 -1
  258. package/dist/chunk-NUAURT4I.cjs.map +0 -1
  259. package/dist/chunk-OLERJ2OU.js.map +0 -1
  260. package/dist/chunk-RKXWLG33.js +0 -7
  261. package/dist/chunk-RKXWLG33.js.map +0 -1
  262. package/dist/chunk-SL7VKAQ3.js.map +0 -1
  263. package/dist/chunk-TEW3ODXX.js.map +0 -1
  264. package/dist/chunk-WBAXXG34.cjs.map +0 -1
  265. package/dist/chunk-WCHE6FJ7.js.map +0 -1
  266. package/dist/chunk-WNFLWMEP.cjs.map +0 -1
  267. package/dist/chunk-WUFFST2N.cjs.map +0 -1
  268. package/dist/chunk-XHKMGOON.cjs.map +0 -1
  269. package/dist/chunk-YSQE5IHK.cjs.map +0 -1
  270. package/dist/chunk-ZISECZZO.js.map +0 -1
  271. package/dist/chunk-ZV5CC35D.js +0 -3
  272. package/dist/models-dev-BL5TAKE6.js +0 -3
  273. package/dist/models-dev-HZ3LZHPX.cjs +0 -12
  274. package/dist/netlify-TX6V7SJJ.cjs +0 -12
  275. package/dist/netlify-VJXBII33.js +0 -3
  276. package/dist/registry-generator-6WVOHM2L.cjs.map +0 -1
  277. package/dist/registry-generator-DXRSYYYT.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { fetchWithRetry } from './chunk-ZIHEKHUB.js';
1
+ import { fetchWithRetry } from './chunk-WIMFJ2BA.js';
2
2
  import { MastraError } from './chunk-PZUZNPFM.js';
3
3
  import { convertUint8ArrayToBase64, convertBase64ToUint8Array, isUrlSupported } from '@ai-sdk/provider-utils-v5';
4
4
  import { randomUUID } from 'crypto';
@@ -210,14 +210,150 @@ function convertImageFilePart(part, downloadedAssets) {
210
210
  }
211
211
  }
212
212
  }
213
+ z.union([
214
+ z.string(),
215
+ z.instanceof(Uint8Array),
216
+ z.instanceof(ArrayBuffer),
217
+ z.custom(
218
+ // Buffer might not be available in some environments such as CloudFlare:
219
+ (value) => globalThis.Buffer?.isBuffer(value) ?? false,
220
+ { message: "Must be a Buffer" }
221
+ )
222
+ ]);
223
+ function convertDataContentToBase64String(content) {
224
+ if (typeof content === "string") {
225
+ return content;
226
+ }
227
+ if (content instanceof ArrayBuffer) {
228
+ return convertUint8ArrayToBase64$1(new Uint8Array(content));
229
+ }
230
+ return convertUint8ArrayToBase64$1(content);
231
+ }
232
+
233
+ // src/agent/message-list/prompt/image-utils.ts
234
+ function parseDataUri(dataUri) {
235
+ if (!dataUri.startsWith("data:")) {
236
+ return {
237
+ isDataUri: false,
238
+ base64Content: dataUri
239
+ };
240
+ }
241
+ const base64Index = dataUri.indexOf(",");
242
+ if (base64Index === -1) {
243
+ return {
244
+ isDataUri: true,
245
+ base64Content: dataUri
246
+ };
247
+ }
248
+ const header = dataUri.substring(5, base64Index);
249
+ const base64Content = dataUri.substring(base64Index + 1);
250
+ const semicolonIndex = header.indexOf(";");
251
+ const mimeType = semicolonIndex !== -1 ? header.substring(0, semicolonIndex) : header;
252
+ return {
253
+ isDataUri: true,
254
+ mimeType: mimeType || void 0,
255
+ base64Content
256
+ };
257
+ }
258
+ function createDataUri(base64Content, mimeType = "application/octet-stream") {
259
+ if (base64Content.startsWith("data:")) {
260
+ return base64Content;
261
+ }
262
+ return `data:${mimeType};base64,${base64Content}`;
263
+ }
264
+ function imageContentToString(image, fallbackMimeType) {
265
+ if (typeof image === "string") {
266
+ return image;
267
+ }
268
+ if (image instanceof URL) {
269
+ return image.toString();
270
+ }
271
+ if (image instanceof Uint8Array || image instanceof ArrayBuffer || globalThis.Buffer && Buffer.isBuffer(image)) {
272
+ const base64 = convertDataContentToBase64String(image);
273
+ if (fallbackMimeType && !base64.startsWith("data:")) {
274
+ return `data:${fallbackMimeType};base64,${base64}`;
275
+ }
276
+ return base64;
277
+ }
278
+ return String(image);
279
+ }
280
+ function imageContentToDataUri(image, mimeType = "image/png") {
281
+ const imageStr = imageContentToString(image, mimeType);
282
+ if (imageStr.startsWith("data:")) {
283
+ return imageStr;
284
+ }
285
+ if (imageStr.startsWith("http://") || imageStr.startsWith("https://")) {
286
+ return imageStr;
287
+ }
288
+ return `data:${mimeType};base64,${imageStr}`;
289
+ }
290
+ function getImageCacheKey(image) {
291
+ if (image instanceof URL) {
292
+ return image.toString();
293
+ }
294
+ if (typeof image === "string") {
295
+ return image.length;
296
+ }
297
+ if (image instanceof Uint8Array) {
298
+ return image.byteLength;
299
+ }
300
+ if (image instanceof ArrayBuffer) {
301
+ return image.byteLength;
302
+ }
303
+ return image;
304
+ }
305
+ function isValidUrl(str) {
306
+ try {
307
+ new URL(str);
308
+ return true;
309
+ } catch {
310
+ if (str.startsWith("//")) {
311
+ try {
312
+ new URL(`https:${str}`);
313
+ return true;
314
+ } catch {
315
+ return false;
316
+ }
317
+ }
318
+ return false;
319
+ }
320
+ }
321
+ function categorizeFileData(data, fallbackMimeType) {
322
+ const parsed = parseDataUri(data);
323
+ const mimeType = parsed.isDataUri && parsed.mimeType ? parsed.mimeType : fallbackMimeType;
324
+ if (parsed.isDataUri) {
325
+ return {
326
+ type: "dataUri",
327
+ mimeType,
328
+ data
329
+ };
330
+ }
331
+ if (isValidUrl(data)) {
332
+ return {
333
+ type: "url",
334
+ mimeType,
335
+ data
336
+ };
337
+ }
338
+ return {
339
+ type: "raw",
340
+ mimeType,
341
+ data
342
+ };
343
+ }
213
344
 
214
345
  // src/agent/message-list/prompt/attachments-to-parts.ts
215
346
  function attachmentsToParts(attachments) {
216
347
  const parts = [];
217
348
  for (const attachment of attachments) {
349
+ const categorized = categorizeFileData(attachment.url, attachment.contentType);
350
+ let urlString = attachment.url;
351
+ if (categorized.type === "raw") {
352
+ urlString = createDataUri(attachment.url, attachment.contentType || "application/octet-stream");
353
+ }
218
354
  let url;
219
355
  try {
220
- url = new URL(attachment.url);
356
+ url = new URL(urlString);
221
357
  } catch {
222
358
  throw new Error(`Invalid URL: ${attachment.url}`);
223
359
  }
@@ -242,13 +378,13 @@ function attachmentsToParts(attachments) {
242
378
  if (attachment.contentType?.startsWith("image/")) {
243
379
  parts.push({
244
380
  type: "image",
245
- image: attachment.url,
381
+ image: urlString,
246
382
  mimeType: attachment.contentType
247
383
  });
248
384
  } else if (attachment.contentType?.startsWith("text/")) {
249
385
  parts.push({
250
386
  type: "file",
251
- data: attachment.url,
387
+ data: urlString,
252
388
  mimeType: attachment.contentType
253
389
  });
254
390
  } else {
@@ -257,7 +393,7 @@ function attachmentsToParts(attachments) {
257
393
  }
258
394
  parts.push({
259
395
  type: "file",
260
- data: attachment.url,
396
+ data: urlString,
261
397
  mimeType: attachment.contentType
262
398
  });
263
399
  }
@@ -568,25 +704,6 @@ function convertToV1Messages(messages) {
568
704
  }
569
705
  return v1Messages;
570
706
  }
571
- z.union([
572
- z.string(),
573
- z.instanceof(Uint8Array),
574
- z.instanceof(ArrayBuffer),
575
- z.custom(
576
- // Buffer might not be available in some environments such as CloudFlare:
577
- (value) => globalThis.Buffer?.isBuffer(value) ?? false,
578
- { message: "Must be a Buffer" }
579
- )
580
- ]);
581
- function convertDataContentToBase64String(content) {
582
- if (typeof content === "string") {
583
- return content;
584
- }
585
- if (content instanceof ArrayBuffer) {
586
- return convertUint8ArrayToBase64$1(new Uint8Array(content));
587
- }
588
- return convertUint8ArrayToBase64$1(content);
589
- }
590
707
  var downloadFromUrl = async ({ url, downloadRetries }) => {
591
708
  const urlText = url.toString();
592
709
  try {
@@ -669,118 +786,6 @@ async function downloadAssetsFromMessages({
669
786
  return Object.fromEntries(downloadFileList);
670
787
  }
671
788
 
672
- // src/agent/message-list/prompt/image-utils.ts
673
- function parseDataUri(dataUri) {
674
- if (!dataUri.startsWith("data:")) {
675
- return {
676
- isDataUri: false,
677
- base64Content: dataUri
678
- };
679
- }
680
- const base64Index = dataUri.indexOf(",");
681
- if (base64Index === -1) {
682
- return {
683
- isDataUri: true,
684
- base64Content: dataUri
685
- };
686
- }
687
- const header = dataUri.substring(5, base64Index);
688
- const base64Content = dataUri.substring(base64Index + 1);
689
- const semicolonIndex = header.indexOf(";");
690
- const mimeType = semicolonIndex !== -1 ? header.substring(0, semicolonIndex) : header;
691
- return {
692
- isDataUri: true,
693
- mimeType: mimeType || void 0,
694
- base64Content
695
- };
696
- }
697
- function createDataUri(base64Content, mimeType = "application/octet-stream") {
698
- if (base64Content.startsWith("data:")) {
699
- return base64Content;
700
- }
701
- return `data:${mimeType};base64,${base64Content}`;
702
- }
703
- function imageContentToString(image, fallbackMimeType) {
704
- if (typeof image === "string") {
705
- return image;
706
- }
707
- if (image instanceof URL) {
708
- return image.toString();
709
- }
710
- if (image instanceof Uint8Array || image instanceof ArrayBuffer || globalThis.Buffer && Buffer.isBuffer(image)) {
711
- const base64 = convertDataContentToBase64String(image);
712
- if (fallbackMimeType && !base64.startsWith("data:")) {
713
- return `data:${fallbackMimeType};base64,${base64}`;
714
- }
715
- return base64;
716
- }
717
- return String(image);
718
- }
719
- function imageContentToDataUri(image, mimeType = "image/png") {
720
- const imageStr = imageContentToString(image, mimeType);
721
- if (imageStr.startsWith("data:")) {
722
- return imageStr;
723
- }
724
- if (imageStr.startsWith("http://") || imageStr.startsWith("https://")) {
725
- return imageStr;
726
- }
727
- return `data:${mimeType};base64,${imageStr}`;
728
- }
729
- function getImageCacheKey(image) {
730
- if (image instanceof URL) {
731
- return image.toString();
732
- }
733
- if (typeof image === "string") {
734
- return image.length;
735
- }
736
- if (image instanceof Uint8Array) {
737
- return image.byteLength;
738
- }
739
- if (image instanceof ArrayBuffer) {
740
- return image.byteLength;
741
- }
742
- return image;
743
- }
744
- function isValidUrl(str) {
745
- try {
746
- new URL(str);
747
- return true;
748
- } catch {
749
- if (str.startsWith("//")) {
750
- try {
751
- new URL(`https:${str}`);
752
- return true;
753
- } catch {
754
- return false;
755
- }
756
- }
757
- return false;
758
- }
759
- }
760
- function categorizeFileData(data, fallbackMimeType) {
761
- const parsed = parseDataUri(data);
762
- const mimeType = parsed.isDataUri && parsed.mimeType ? parsed.mimeType : fallbackMimeType;
763
- if (parsed.isDataUri) {
764
- return {
765
- type: "dataUri",
766
- mimeType,
767
- data
768
- };
769
- }
770
- if (isValidUrl(data)) {
771
- return {
772
- type: "url",
773
- mimeType,
774
- data
775
- };
776
- }
777
- return {
778
- type: "raw",
779
- mimeType,
780
- data
781
- };
782
- }
783
-
784
789
  // src/agent/message-list/utils/ai-v5/gemini-compatibility.ts
785
790
  function ensureGeminiCompatibleMessages(messages) {
786
791
  const result = [...messages];
@@ -1362,9 +1367,20 @@ var MessageList = class _MessageList {
1362
1367
  if (m.content.parts.length) {
1363
1368
  for (const part of m.content.parts) {
1364
1369
  if (part.type === `file`) {
1370
+ let normalizedUrl;
1371
+ if (typeof part.data === "string") {
1372
+ const categorized = categorizeFileData(part.data, part.mimeType);
1373
+ if (categorized.type === "raw") {
1374
+ normalizedUrl = createDataUri(part.data, part.mimeType || "application/octet-stream");
1375
+ } else {
1376
+ normalizedUrl = part.data;
1377
+ }
1378
+ } else {
1379
+ normalizedUrl = part.data;
1380
+ }
1365
1381
  experimentalAttachments.push({
1366
1382
  contentType: part.mimeType,
1367
- url: part.data
1383
+ url: normalizedUrl
1368
1384
  });
1369
1385
  } else if (part.type === "tool-invocation" && (part.toolInvocation.state === "call" || part.toolInvocation.state === "partial-call")) {
1370
1386
  continue;
@@ -2010,6 +2026,12 @@ var MessageList = class _MessageList {
2010
2026
  if (toolInvocations.length) content.toolInvocations = toolInvocations;
2011
2027
  if (typeof coreMessage.content === `string`) content.content = coreMessage.content;
2012
2028
  if (experimentalAttachments.length) content.experimental_attachments = experimentalAttachments;
2029
+ if (coreMessage.providerOptions) {
2030
+ content.providerMetadata = coreMessage.providerOptions;
2031
+ }
2032
+ if ("metadata" in coreMessage && coreMessage.metadata !== null && coreMessage.metadata !== void 0) {
2033
+ content.metadata = coreMessage.metadata;
2034
+ }
2013
2035
  return {
2014
2036
  id,
2015
2037
  role: _MessageList.getRole(coreMessage),
@@ -2242,9 +2264,23 @@ var MessageList = class _MessageList {
2242
2264
  if (role === `tool` || role === `assistant`) {
2243
2265
  throw new Error(incompatibleMessage);
2244
2266
  }
2267
+ let processedImage;
2268
+ if (part.image instanceof URL || part.image instanceof Uint8Array) {
2269
+ processedImage = part.image;
2270
+ } else if (Buffer.isBuffer(part.image) || part.image instanceof ArrayBuffer) {
2271
+ processedImage = new Uint8Array(part.image);
2272
+ } else {
2273
+ const categorized = categorizeFileData(part.image, part.mimeType);
2274
+ if (categorized.type === "raw") {
2275
+ const dataUri = createDataUri(part.image, part.mimeType || "image/png");
2276
+ processedImage = new URL(dataUri);
2277
+ } else {
2278
+ processedImage = new URL(part.image);
2279
+ }
2280
+ }
2245
2281
  roleContent[role].push({
2246
2282
  ...part,
2247
- image: part.image instanceof URL || part.image instanceof Uint8Array ? part.image : Buffer.isBuffer(part.image) || part.image instanceof ArrayBuffer ? new Uint8Array(part.image) : new URL(part.image)
2283
+ image: processedImage
2248
2284
  });
2249
2285
  break;
2250
2286
  }
@@ -2460,15 +2496,17 @@ var MessageList = class _MessageList {
2460
2496
  type: "file",
2461
2497
  mimeType: p.mediaType,
2462
2498
  data: fileDataSource,
2463
- providerMetadata: p.providerMetadata
2499
+ ...p.providerMetadata ? { providerMetadata: p.providerMetadata } : {}
2464
2500
  };
2465
2501
  }
2466
2502
  case "reasoning":
2467
- if (p.text === "") return null;
2503
+ if (p.text === "" && !p.providerMetadata) return null;
2468
2504
  return {
2469
2505
  type: "reasoning",
2470
- reasoning: p.text,
2471
- details: [{ type: "text", text: p.text }],
2506
+ // Keep reasoning field empty to match the format used in llm-execution-step
2507
+ // This ensures cache keys match for deduplication when merging assistant messages
2508
+ reasoning: "",
2509
+ details: p.text ? [{ type: "text", text: p.text }] : [],
2472
2510
  providerMetadata: p.providerMetadata
2473
2511
  };
2474
2512
  case "source-url":
@@ -2612,7 +2650,7 @@ var MessageList = class _MessageList {
2612
2650
  if (c.type === `text`) return p + c.text;
2613
2651
  return p;
2614
2652
  }, "") ?? "");
2615
- if (text || part.details?.length) {
2653
+ if (text || part.details?.length || part.providerMetadata) {
2616
2654
  parts.push({
2617
2655
  type: "reasoning",
2618
2656
  text: text || "",
@@ -2628,7 +2666,7 @@ var MessageList = class _MessageList {
2628
2666
  type: "file",
2629
2667
  url: part.data,
2630
2668
  mediaType: categorized.mimeType || "image/png",
2631
- providerMetadata: part.providerMetadata
2669
+ ...part.providerMetadata ? { providerMetadata: part.providerMetadata } : {}
2632
2670
  });
2633
2671
  fileUrls.add(part.data);
2634
2672
  } else {
@@ -2659,7 +2697,7 @@ var MessageList = class _MessageList {
2659
2697
  url: dataUri,
2660
2698
  // Use url field with data URI
2661
2699
  mediaType: finalMimeType,
2662
- providerMetadata: part.providerMetadata
2700
+ ...part.providerMetadata ? { providerMetadata: part.providerMetadata } : {}
2663
2701
  });
2664
2702
  }
2665
2703
  fileUrls.add(part.data);
@@ -2710,7 +2748,16 @@ var MessageList = class _MessageList {
2710
2748
  if (uiPart && "callProviderMetadata" in uiPart && uiPart.callProviderMetadata) {
2711
2749
  return {
2712
2750
  ...part,
2713
- providerMetadata: uiPart.callProviderMetadata
2751
+ providerOptions: uiPart.callProviderMetadata
2752
+ };
2753
+ }
2754
+ }
2755
+ if (part.type === "reasoning") {
2756
+ const uiPart = uiMsg?.parts[partIndex];
2757
+ if (uiPart && "providerMetadata" in uiPart && uiPart.providerMetadata) {
2758
+ return {
2759
+ ...part,
2760
+ providerOptions: uiPart.providerMetadata
2714
2761
  };
2715
2762
  }
2716
2763
  }
@@ -2763,8 +2810,9 @@ var MessageList = class _MessageList {
2763
2810
  return msgs;
2764
2811
  }
2765
2812
  static mastraMessageV3ToAIV5UIMessage(m) {
2813
+ const { __originalContent, ...cleanMetadata } = m.content.metadata || {};
2766
2814
  const metadata = {
2767
- ...m.content.metadata || {}
2815
+ ...cleanMetadata
2768
2816
  };
2769
2817
  if (m.createdAt) metadata.createdAt = m.createdAt;
2770
2818
  if (m.threadId) metadata.threadId = m.threadId;
@@ -2984,6 +3032,12 @@ var MessageList = class _MessageList {
2984
3032
  format: 3,
2985
3033
  parts
2986
3034
  };
3035
+ if ("metadata" in coreMessage && coreMessage.metadata !== null && coreMessage.metadata !== void 0) {
3036
+ content.metadata = {
3037
+ ...content.metadata || {},
3038
+ ...coreMessage.metadata
3039
+ };
3040
+ }
2987
3041
  if (coreMessage.content) {
2988
3042
  content.metadata = {
2989
3043
  ...content.metadata || {},
@@ -3119,5 +3173,5 @@ function convertMessages(messages) {
3119
3173
  }
3120
3174
 
3121
3175
  export { DefaultGeneratedFile, DefaultGeneratedFileWithType, MessageList, convertMessages };
3122
- //# sourceMappingURL=chunk-4SXWN3RR.js.map
3123
- //# sourceMappingURL=chunk-4SXWN3RR.js.map
3176
+ //# sourceMappingURL=chunk-Q6LWNLAJ.js.map
3177
+ //# sourceMappingURL=chunk-Q6LWNLAJ.js.map