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

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 (146) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/agent/index.cjs +9 -9
  3. package/dist/agent/index.js +2 -2
  4. package/dist/agent/message-list/index.cjs +3 -3
  5. package/dist/agent/message-list/index.d.ts +5 -0
  6. package/dist/agent/message-list/index.d.ts.map +1 -1
  7. package/dist/agent/message-list/index.js +1 -1
  8. package/dist/{chunk-OWX2PUFH.cjs → chunk-2NVBZKZI.cjs} +161 -129
  9. package/dist/chunk-2NVBZKZI.cjs.map +1 -0
  10. package/dist/{chunk-OQF4H5Y2.js → chunk-2OTDXX73.js} +4 -4
  11. package/dist/{chunk-OQF4H5Y2.js.map → chunk-2OTDXX73.js.map} +1 -1
  12. package/dist/{chunk-4DWZ4Z6H.js → chunk-3RW5EMSB.js} +3 -4
  13. package/dist/chunk-3RW5EMSB.js.map +1 -0
  14. package/dist/{chunk-N4SJ4YX7.cjs → chunk-3W5RQCCY.cjs} +40 -24
  15. package/dist/chunk-3W5RQCCY.cjs.map +1 -0
  16. package/dist/{chunk-XRIVPHXV.cjs → chunk-4RXG622P.cjs} +5 -5
  17. package/dist/{chunk-XRIVPHXV.cjs.map → chunk-4RXG622P.cjs.map} +1 -1
  18. package/dist/{chunk-VZGBVYXA.cjs → chunk-5WXEYDFI.cjs} +22 -23
  19. package/dist/chunk-5WXEYDFI.cjs.map +1 -0
  20. package/dist/{chunk-EZVRSZMK.cjs → chunk-CYVNOIXS.cjs} +11 -11
  21. package/dist/{chunk-EZVRSZMK.cjs.map → chunk-CYVNOIXS.cjs.map} +1 -1
  22. package/dist/{chunk-MCUX2D5Q.js → chunk-FVNT7VTO.js} +29 -13
  23. package/dist/chunk-FVNT7VTO.js.map +1 -0
  24. package/dist/{chunk-T3WZCEC4.js → chunk-IHJDOC3A.js} +34 -587
  25. package/dist/chunk-IHJDOC3A.js.map +1 -0
  26. package/dist/{chunk-QUKUN6NR.cjs → chunk-ISMGVGUM.cjs} +105 -5
  27. package/dist/chunk-ISMGVGUM.cjs.map +1 -0
  28. package/dist/{chunk-4RSHBKDJ.cjs → chunk-IWB65P37.cjs} +5 -5
  29. package/dist/{chunk-4RSHBKDJ.cjs.map → chunk-IWB65P37.cjs.map} +1 -1
  30. package/dist/{chunk-5CWWU22H.js → chunk-IWQDBVJK.js} +3 -3
  31. package/dist/{chunk-5CWWU22H.js.map → chunk-IWQDBVJK.js.map} +1 -1
  32. package/dist/{chunk-KOSW5PP5.js → chunk-MDKPL2R2.js} +464 -124
  33. package/dist/chunk-MDKPL2R2.js.map +1 -0
  34. package/dist/{chunk-UIZSWUKP.js → chunk-NZAXAFI3.js} +104 -6
  35. package/dist/chunk-NZAXAFI3.js.map +1 -0
  36. package/dist/{chunk-GRGPQ32U.js → chunk-RXDJL5QT.js} +3 -3
  37. package/dist/{chunk-GRGPQ32U.js.map → chunk-RXDJL5QT.js.map} +1 -1
  38. package/dist/{chunk-YQ7NLZZ3.cjs → chunk-S6OEQHEI.cjs} +61 -614
  39. package/dist/chunk-S6OEQHEI.cjs.map +1 -0
  40. package/dist/{chunk-G3OOCXAI.js → chunk-U7VECK2G.js} +4 -4
  41. package/dist/{chunk-G3OOCXAI.js.map → chunk-U7VECK2G.js.map} +1 -1
  42. package/dist/{chunk-G36A2JRR.cjs → chunk-VSM3NLUX.cjs} +296 -199
  43. package/dist/chunk-VSM3NLUX.cjs.map +1 -0
  44. package/dist/{chunk-3VOUB4ZU.cjs → chunk-VZC4BWWH.cjs} +8 -8
  45. package/dist/{chunk-3VOUB4ZU.cjs.map → chunk-VZC4BWWH.cjs.map} +1 -1
  46. package/dist/{chunk-BAMR7HKO.js → chunk-W3DD3XP5.js} +296 -199
  47. package/dist/chunk-W3DD3XP5.js.map +1 -0
  48. package/dist/{chunk-JTXVR2RA.cjs → chunk-WQSGX6XA.cjs} +5 -5
  49. package/dist/{chunk-JTXVR2RA.cjs.map → chunk-WQSGX6XA.cjs.map} +1 -1
  50. package/dist/{chunk-VU6DVS7J.js → chunk-WTYNK7Q4.js} +4 -4
  51. package/dist/{chunk-VU6DVS7J.js.map → chunk-WTYNK7Q4.js.map} +1 -1
  52. package/dist/{chunk-CKGIPST2.js → chunk-XXBWX7DT.js} +138 -106
  53. package/dist/chunk-XXBWX7DT.js.map +1 -0
  54. package/dist/{chunk-ZPMFINU2.cjs → chunk-ZCVTH3CH.cjs} +464 -130
  55. package/dist/chunk-ZCVTH3CH.cjs.map +1 -0
  56. package/dist/evals/index.cjs +4 -4
  57. package/dist/evals/index.js +1 -1
  58. package/dist/evals/scoreTraces/index.cjs +3 -3
  59. package/dist/evals/scoreTraces/index.js +1 -1
  60. package/dist/index.cjs +2 -2
  61. package/dist/index.js +1 -1
  62. package/dist/llm/index.cjs +14 -14
  63. package/dist/llm/index.js +5 -5
  64. package/dist/llm/model/aisdk/v5/model.d.ts.map +1 -1
  65. package/dist/loop/index.cjs +2 -2
  66. package/dist/loop/index.js +1 -1
  67. package/dist/loop/test-utils/generateText.d.ts.map +1 -1
  68. package/dist/loop/test-utils/resultObject.d.ts.map +1 -1
  69. package/dist/loop/test-utils/toUIMessageStream.d.ts.map +1 -1
  70. package/dist/loop/test-utils/utils.d.ts.map +1 -1
  71. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
  72. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
  73. package/dist/mastra/index.cjs +2 -2
  74. package/dist/mastra/index.js +1 -1
  75. package/dist/memory/index.cjs +6 -6
  76. package/dist/memory/index.js +3 -3
  77. package/dist/models-dev-6PRLJKVZ.js +3 -0
  78. package/dist/{models-dev-GCVENVWA.js.map → models-dev-6PRLJKVZ.js.map} +1 -1
  79. package/dist/models-dev-WHMI5G6Y.cjs +12 -0
  80. package/dist/{models-dev-TIBJR6IG.cjs.map → models-dev-WHMI5G6Y.cjs.map} +1 -1
  81. package/dist/netlify-46I3SNNV.cjs +12 -0
  82. package/dist/{netlify-NTSNNT6F.cjs.map → netlify-46I3SNNV.cjs.map} +1 -1
  83. package/dist/netlify-EBQ6YUC6.js +3 -0
  84. package/dist/{netlify-O5NJW7CF.js.map → netlify-EBQ6YUC6.js.map} +1 -1
  85. package/dist/processors/index.cjs +11 -11
  86. package/dist/processors/index.js +1 -1
  87. package/dist/provider-registry-HDG6UMUC.js +3 -0
  88. package/dist/{provider-registry-74GMFZKT.js.map → provider-registry-HDG6UMUC.js.map} +1 -1
  89. package/dist/provider-registry-RP2W4B24.cjs +40 -0
  90. package/dist/{provider-registry-BZP3DIIV.cjs.map → provider-registry-RP2W4B24.cjs.map} +1 -1
  91. package/dist/relevance/index.cjs +2 -2
  92. package/dist/relevance/index.js +1 -1
  93. package/dist/server/auth.d.ts +11 -0
  94. package/dist/server/auth.d.ts.map +1 -1
  95. package/dist/server/index.cjs +10 -0
  96. package/dist/server/index.cjs.map +1 -1
  97. package/dist/server/index.js +10 -0
  98. package/dist/server/index.js.map +1 -1
  99. package/dist/storage/index.cjs +29 -29
  100. package/dist/storage/index.js +1 -1
  101. package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
  102. package/dist/stream/index.cjs +11 -11
  103. package/dist/stream/index.js +2 -2
  104. package/dist/test-utils/llm-mock.cjs +66 -29
  105. package/dist/test-utils/llm-mock.cjs.map +1 -1
  106. package/dist/test-utils/llm-mock.d.ts +4 -2
  107. package/dist/test-utils/llm-mock.d.ts.map +1 -1
  108. package/dist/test-utils/llm-mock.js +66 -29
  109. package/dist/test-utils/llm-mock.js.map +1 -1
  110. package/dist/voice/aisdk/index.d.ts +3 -0
  111. package/dist/voice/aisdk/index.d.ts.map +1 -0
  112. package/dist/voice/aisdk/speech.d.ts +23 -0
  113. package/dist/voice/aisdk/speech.d.ts.map +1 -0
  114. package/dist/voice/aisdk/transcription.d.ts +22 -0
  115. package/dist/voice/aisdk/transcription.d.ts.map +1 -0
  116. package/dist/voice/composite-voice.d.ts +4 -3
  117. package/dist/voice/composite-voice.d.ts.map +1 -1
  118. package/dist/voice/index.cjs +12 -4
  119. package/dist/voice/index.d.ts +1 -0
  120. package/dist/voice/index.d.ts.map +1 -1
  121. package/dist/voice/index.js +1 -1
  122. package/dist/workflows/evented/index.cjs +10 -10
  123. package/dist/workflows/evented/index.js +1 -1
  124. package/dist/workflows/index.cjs +19 -19
  125. package/dist/workflows/index.js +1 -1
  126. package/package.json +10 -10
  127. package/dist/chunk-4DWZ4Z6H.js.map +0 -1
  128. package/dist/chunk-BAMR7HKO.js.map +0 -1
  129. package/dist/chunk-CKGIPST2.js.map +0 -1
  130. package/dist/chunk-G36A2JRR.cjs.map +0 -1
  131. package/dist/chunk-KOSW5PP5.js.map +0 -1
  132. package/dist/chunk-MCUX2D5Q.js.map +0 -1
  133. package/dist/chunk-N4SJ4YX7.cjs.map +0 -1
  134. package/dist/chunk-OWX2PUFH.cjs.map +0 -1
  135. package/dist/chunk-QUKUN6NR.cjs.map +0 -1
  136. package/dist/chunk-T3WZCEC4.js.map +0 -1
  137. package/dist/chunk-UIZSWUKP.js.map +0 -1
  138. package/dist/chunk-VZGBVYXA.cjs.map +0 -1
  139. package/dist/chunk-YQ7NLZZ3.cjs.map +0 -1
  140. package/dist/chunk-ZPMFINU2.cjs.map +0 -1
  141. package/dist/models-dev-GCVENVWA.js +0 -3
  142. package/dist/models-dev-TIBJR6IG.cjs +0 -12
  143. package/dist/netlify-NTSNNT6F.cjs +0 -12
  144. package/dist/netlify-O5NJW7CF.js +0 -3
  145. package/dist/provider-registry-74GMFZKT.js +0 -3
  146. package/dist/provider-registry-BZP3DIIV.cjs +0 -40
@@ -1880,6 +1880,12 @@ var MessageList = class _MessageList {
1880
1880
  return ti;
1881
1881
  });
1882
1882
  }
1883
+ if (!message.threadId && this.memoryInfo?.threadId) {
1884
+ message.threadId = this.memoryInfo.threadId;
1885
+ if (!message.resourceId && this.memoryInfo?.resourceId) {
1886
+ message.resourceId = this.memoryInfo.resourceId;
1887
+ }
1888
+ }
1883
1889
  return message;
1884
1890
  }
1885
1891
  aiV4UIMessageToMastraDBMessage(message, messageSource) {
@@ -1917,137 +1923,180 @@ var MessageList = class _MessageList {
1917
1923
  if (typeof coreMessage.content === "string") {
1918
1924
  parts.push({
1919
1925
  type: "text",
1920
- text: coreMessage.content,
1921
- // Preserve providerOptions from CoreMessage (e.g., for system messages with cacheControl)
1922
- ..."providerOptions" in coreMessage && coreMessage.providerOptions ? { providerMetadata: coreMessage.providerOptions } : {}
1926
+ text: coreMessage.content
1923
1927
  });
1924
1928
  } else if (Array.isArray(coreMessage.content)) {
1925
- for (const part of coreMessage.content) {
1926
- switch (part.type) {
1927
- case "text":
1929
+ for (const aiV4Part of coreMessage.content) {
1930
+ switch (aiV4Part.type) {
1931
+ case "text": {
1928
1932
  const prevPart = parts.at(-1);
1929
1933
  if (coreMessage.role === "assistant" && prevPart && prevPart.type === "tool-invocation") {
1930
1934
  parts.push({ type: "step-start" });
1931
1935
  }
1932
- const mergedProviderMetadata = {
1933
- ..."providerOptions" in coreMessage && coreMessage.providerOptions ? coreMessage.providerOptions : {},
1934
- ..."providerOptions" in part && part.providerOptions ? part.providerOptions : {}
1935
- };
1936
- parts.push({
1936
+ const part = {
1937
1937
  type: "text",
1938
- text: part.text,
1939
- ...Object.keys(mergedProviderMetadata).length > 0 ? { providerMetadata: mergedProviderMetadata } : {}
1940
- });
1938
+ text: aiV4Part.text
1939
+ };
1940
+ if (aiV4Part.providerOptions) {
1941
+ part.providerMetadata = aiV4Part.providerOptions;
1942
+ }
1943
+ parts.push(part);
1941
1944
  break;
1942
- case "tool-call":
1943
- parts.push({
1945
+ }
1946
+ case "tool-call": {
1947
+ const part = {
1944
1948
  type: "tool-invocation",
1945
1949
  toolInvocation: {
1946
1950
  state: "call",
1947
- toolCallId: part.toolCallId,
1948
- toolName: part.toolName,
1949
- args: part.args
1951
+ toolCallId: aiV4Part.toolCallId,
1952
+ toolName: aiV4Part.toolName,
1953
+ args: aiV4Part.args
1950
1954
  }
1951
- });
1955
+ };
1956
+ if (aiV4Part.providerOptions) {
1957
+ part.providerMetadata = aiV4Part.providerOptions;
1958
+ }
1959
+ parts.push(part);
1952
1960
  break;
1961
+ }
1953
1962
  case "tool-result":
1954
- let toolArgs = {};
1955
- const toolCallInSameMsg = coreMessage.content.find(
1956
- (p) => p.type === "tool-call" && p.toolCallId === part.toolCallId
1957
- );
1958
- if (toolCallInSameMsg && toolCallInSameMsg.type === "tool-call") {
1959
- toolArgs = toolCallInSameMsg.args;
1960
- }
1961
- if (Object.keys(toolArgs).length === 0) {
1962
- for (let i = this.messages.length - 1; i >= 0; i--) {
1963
- const msg = this.messages[i];
1964
- if (msg && msg.role === "assistant" && msg.content.parts) {
1965
- const toolCallPart = msg.content.parts.find(
1966
- (p) => p.type === "tool-invocation" && p.toolInvocation.toolCallId === part.toolCallId && p.toolInvocation.state === "call"
1967
- );
1968
- if (toolCallPart && toolCallPart.type === "tool-invocation" && toolCallPart.toolInvocation.args) {
1969
- toolArgs = toolCallPart.toolInvocation.args;
1970
- break;
1963
+ {
1964
+ let toolArgs = {};
1965
+ const toolCallInSameMsg = coreMessage.content.find(
1966
+ (p) => p.type === "tool-call" && p.toolCallId === aiV4Part.toolCallId
1967
+ );
1968
+ if (toolCallInSameMsg && toolCallInSameMsg.type === "tool-call") {
1969
+ toolArgs = toolCallInSameMsg.args;
1970
+ }
1971
+ if (Object.keys(toolArgs).length === 0) {
1972
+ for (let i = this.messages.length - 1; i >= 0; i--) {
1973
+ const msg = this.messages[i];
1974
+ if (msg && msg.role === "assistant" && msg.content.parts) {
1975
+ const toolCallPart = msg.content.parts.find(
1976
+ (p) => p.type === "tool-invocation" && p.toolInvocation.toolCallId === aiV4Part.toolCallId && p.toolInvocation.state === "call"
1977
+ );
1978
+ if (toolCallPart && toolCallPart.type === "tool-invocation" && toolCallPart.toolInvocation.args) {
1979
+ toolArgs = toolCallPart.toolInvocation.args;
1980
+ break;
1981
+ }
1971
1982
  }
1972
1983
  }
1973
1984
  }
1985
+ const invocation = {
1986
+ state: "result",
1987
+ toolCallId: aiV4Part.toolCallId,
1988
+ toolName: aiV4Part.toolName,
1989
+ result: aiV4Part.result ?? "",
1990
+ // undefined will cause AI SDK to throw an error, but for client side tool calls this really could be undefined
1991
+ args: toolArgs
1992
+ // Use the args from the corresponding tool-call
1993
+ };
1994
+ const part = {
1995
+ type: "tool-invocation",
1996
+ toolInvocation: invocation
1997
+ };
1998
+ if (aiV4Part.providerOptions) {
1999
+ part.providerMetadata = aiV4Part.providerOptions;
2000
+ }
2001
+ parts.push(part);
2002
+ toolInvocations.push(invocation);
1974
2003
  }
1975
- const invocation = {
1976
- state: "result",
1977
- toolCallId: part.toolCallId,
1978
- toolName: part.toolName,
1979
- result: part.result ?? "",
1980
- // undefined will cause AI SDK to throw an error, but for client side tool calls this really could be undefined
1981
- args: toolArgs
1982
- // Use the args from the corresponding tool-call
1983
- };
1984
- parts.push({
1985
- type: "tool-invocation",
1986
- toolInvocation: invocation
1987
- });
1988
- toolInvocations.push(invocation);
1989
2004
  break;
1990
2005
  case "reasoning":
1991
- parts.push({
1992
- type: "reasoning",
1993
- reasoning: "",
1994
- // leave this blank so we aren't double storing it in the db along with details
1995
- details: [{ type: "text", text: part.text, signature: part.signature }]
1996
- });
2006
+ {
2007
+ const part = {
2008
+ type: "reasoning",
2009
+ reasoning: "",
2010
+ // leave this blank so we aren't double storing it in the db along with details
2011
+ details: [{ type: "text", text: aiV4Part.text, signature: aiV4Part.signature }]
2012
+ };
2013
+ if (aiV4Part.providerOptions) {
2014
+ part.providerMetadata = aiV4Part.providerOptions;
2015
+ }
2016
+ parts.push(part);
2017
+ }
1997
2018
  break;
1998
2019
  case "redacted-reasoning":
1999
- parts.push({
2000
- type: "reasoning",
2001
- reasoning: "",
2002
- // No text reasoning for redacted parts
2003
- details: [{ type: "redacted", data: part.data }]
2004
- });
2020
+ {
2021
+ const part = {
2022
+ type: "reasoning",
2023
+ reasoning: "",
2024
+ // No text reasoning for redacted parts
2025
+ details: [{ type: "redacted", data: aiV4Part.data }]
2026
+ };
2027
+ if (aiV4Part.providerOptions) {
2028
+ part.providerMetadata = aiV4Part.providerOptions;
2029
+ }
2030
+ parts.push(part);
2031
+ }
2005
2032
  break;
2006
- case "image":
2007
- parts.push({
2033
+ case "image": {
2034
+ const part = {
2008
2035
  type: "file",
2009
- data: imageContentToString(part.image),
2010
- mimeType: part.mimeType
2011
- });
2036
+ data: imageContentToString(aiV4Part.image),
2037
+ mimeType: aiV4Part.mimeType
2038
+ };
2039
+ if (aiV4Part.providerOptions) {
2040
+ part.providerMetadata = aiV4Part.providerOptions;
2041
+ }
2042
+ parts.push(part);
2012
2043
  break;
2013
- case "file":
2014
- if (part.data instanceof URL) {
2015
- parts.push({
2044
+ }
2045
+ case "file": {
2046
+ if (aiV4Part.data instanceof URL) {
2047
+ const part = {
2016
2048
  type: "file",
2017
- data: part.data.toString(),
2018
- mimeType: part.mimeType
2019
- });
2020
- } else if (typeof part.data === "string") {
2021
- const categorized = categorizeFileData(part.data, part.mimeType);
2049
+ data: aiV4Part.data.toString(),
2050
+ mimeType: aiV4Part.mimeType
2051
+ };
2052
+ if (aiV4Part.providerOptions) {
2053
+ part.providerMetadata = aiV4Part.providerOptions;
2054
+ }
2055
+ parts.push(part);
2056
+ } else if (typeof aiV4Part.data === "string") {
2057
+ const categorized = categorizeFileData(aiV4Part.data, aiV4Part.mimeType);
2022
2058
  if (categorized.type === "url" || categorized.type === "dataUri") {
2023
- parts.push({
2059
+ const part = {
2024
2060
  type: "file",
2025
- data: part.data,
2061
+ data: aiV4Part.data,
2026
2062
  mimeType: categorized.mimeType || "image/png"
2027
- });
2063
+ };
2064
+ if (aiV4Part.providerOptions) {
2065
+ part.providerMetadata = aiV4Part.providerOptions;
2066
+ }
2067
+ parts.push(part);
2028
2068
  } else {
2029
2069
  try {
2030
- parts.push({
2070
+ const part = {
2031
2071
  type: "file",
2032
2072
  mimeType: categorized.mimeType || "image/png",
2033
- data: convertDataContentToBase64String(part.data)
2034
- });
2073
+ data: convertDataContentToBase64String(aiV4Part.data)
2074
+ };
2075
+ if (aiV4Part.providerOptions) {
2076
+ part.providerMetadata = aiV4Part.providerOptions;
2077
+ }
2078
+ parts.push(part);
2035
2079
  } catch (error) {
2036
2080
  console.error(`Failed to convert binary data to base64 in CoreMessage file part: ${error}`, error);
2037
2081
  }
2038
2082
  }
2039
2083
  } else {
2040
2084
  try {
2041
- parts.push({
2085
+ const part = {
2042
2086
  type: "file",
2043
- mimeType: part.mimeType,
2044
- data: convertDataContentToBase64String(part.data)
2045
- });
2087
+ mimeType: aiV4Part.mimeType,
2088
+ data: convertDataContentToBase64String(aiV4Part.data)
2089
+ };
2090
+ if (aiV4Part.providerOptions) {
2091
+ part.providerMetadata = aiV4Part.providerOptions;
2092
+ }
2093
+ parts.push(part);
2046
2094
  } catch (error) {
2047
2095
  console.error(`Failed to convert binary data to base64 in CoreMessage file part: ${error}`, error);
2048
2096
  }
2049
2097
  }
2050
2098
  break;
2099
+ }
2051
2100
  }
2052
2101
  }
2053
2102
  }
@@ -2058,6 +2107,9 @@ var MessageList = class _MessageList {
2058
2107
  if (toolInvocations.length) content.toolInvocations = toolInvocations;
2059
2108
  if (typeof coreMessage.content === `string`) content.content = coreMessage.content;
2060
2109
  if (experimentalAttachments.length) content.experimental_attachments = experimentalAttachments;
2110
+ if (coreMessage.providerOptions) {
2111
+ content.providerMetadata = coreMessage.providerOptions;
2112
+ }
2061
2113
  return {
2062
2114
  id,
2063
2115
  role: _MessageList.getRole(coreMessage),
@@ -2408,6 +2460,9 @@ var MessageList = class _MessageList {
2408
2460
  if (dbMsg.createdAt) metadata.createdAt = dbMsg.createdAt;
2409
2461
  if (dbMsg.threadId) metadata.threadId = dbMsg.threadId;
2410
2462
  if (dbMsg.resourceId) metadata.resourceId = dbMsg.resourceId;
2463
+ if (dbMsg.content.providerMetadata) {
2464
+ metadata.providerMetadata = dbMsg.content.providerMetadata;
2465
+ }
2411
2466
  const hasToolInvocationParts = dbMsg.content.parts?.some((p) => p.type === "tool-invocation");
2412
2467
  if (dbMsg.content.toolInvocations && !hasToolInvocationParts) {
2413
2468
  for (const invocation of dbMsg.content.toolInvocations) {
@@ -2474,18 +2529,20 @@ var MessageList = class _MessageList {
2474
2529
  continue;
2475
2530
  }
2476
2531
  if (part.type === "reasoning") {
2477
- const reasoningPart = part;
2478
- const text = reasoningPart.text || reasoningPart.reasoning || (reasoningPart.details?.reduce((p, c) => {
2532
+ const text = part.reasoning || (part.details?.reduce((p, c) => {
2479
2533
  if (c.type === `text` && c.text) return p + c.text;
2480
2534
  return p;
2481
2535
  }, "") ?? "");
2482
- if (text || reasoningPart.details?.length) {
2483
- parts.push({
2536
+ if (text || part.details?.length) {
2537
+ const v5UIPart = {
2484
2538
  type: "reasoning",
2485
2539
  text: text || "",
2486
- state: "done",
2487
- ...part.providerMetadata && { providerMetadata: part.providerMetadata }
2488
- });
2540
+ state: "done"
2541
+ };
2542
+ if (part.providerMetadata) {
2543
+ v5UIPart.providerMetadata = part.providerMetadata;
2544
+ }
2545
+ parts.push(v5UIPart);
2489
2546
  }
2490
2547
  continue;
2491
2548
  }
@@ -2498,12 +2555,15 @@ var MessageList = class _MessageList {
2498
2555
  }
2499
2556
  const categorized = typeof part.data === "string" ? categorizeFileData(part.data, part.mimeType) : { type: "raw", mimeType: part.mimeType};
2500
2557
  if (categorized.type === "url" && typeof part.data === "string") {
2501
- parts.push({
2558
+ const v5UIPart = {
2502
2559
  type: "file",
2503
2560
  url: part.data,
2504
- mediaType: categorized.mimeType || "image/png",
2505
- providerMetadata: part.providerMetadata
2506
- });
2561
+ mediaType: categorized.mimeType || "image/png"
2562
+ };
2563
+ if (part.providerMetadata) {
2564
+ v5UIPart.providerMetadata = part.providerMetadata;
2565
+ }
2566
+ parts.push(v5UIPart);
2507
2567
  } else {
2508
2568
  let filePartData;
2509
2569
  let extractedMimeType = part.mimeType;
@@ -2527,27 +2587,37 @@ var MessageList = class _MessageList {
2527
2587
  } else {
2528
2588
  dataUri = createDataUri(filePartData, finalMimeType);
2529
2589
  }
2530
- parts.push({
2590
+ const v5UIPart = {
2531
2591
  type: "file",
2532
2592
  url: dataUri,
2533
2593
  // Use url field with data URI
2534
- mediaType: finalMimeType,
2535
- providerMetadata: part.providerMetadata
2536
- });
2594
+ mediaType: finalMimeType
2595
+ };
2596
+ if (part.providerMetadata) {
2597
+ v5UIPart.providerMetadata = part.providerMetadata;
2598
+ }
2599
+ parts.push(v5UIPart);
2537
2600
  }
2538
2601
  } else if (part.type === "source") {
2539
- const sourcePart = part;
2540
- parts.push({
2602
+ const v5UIPart = {
2541
2603
  type: "source-url",
2542
- url: sourcePart.source.url,
2543
- ...part.providerMetadata && { providerMetadata: part.providerMetadata }
2544
- });
2604
+ url: part.source.url,
2605
+ sourceId: part.source.id,
2606
+ title: part.source.title
2607
+ };
2608
+ if (part.providerMetadata) {
2609
+ v5UIPart.providerMetadata = part.providerMetadata;
2610
+ }
2611
+ parts.push(v5UIPart);
2545
2612
  } else if (part.type === "text") {
2546
- parts.push({
2613
+ const v5UIPart = {
2547
2614
  type: "text",
2548
- text: part.text,
2549
- ...part.providerMetadata && { providerMetadata: part.providerMetadata }
2550
- });
2615
+ text: part.text
2616
+ };
2617
+ if (part.providerMetadata) {
2618
+ v5UIPart.providerMetadata = part.providerMetadata;
2619
+ }
2620
+ parts.push(v5UIPart);
2551
2621
  hasNonToolReasoningParts = true;
2552
2622
  } else {
2553
2623
  parts.push(part);
@@ -2711,32 +2781,69 @@ var MessageList = class _MessageList {
2711
2781
  }
2712
2782
  };
2713
2783
  }
2784
+ /**
2785
+ * Convert image or file to data URI or URL for V2 file part
2786
+ */
2787
+ static getDataStringFromAIV5DataPart = (part) => {
2788
+ let mimeType;
2789
+ let data;
2790
+ if ("data" in part) {
2791
+ mimeType = part.mediaType || "application/octet-stream";
2792
+ data = part.data;
2793
+ } else if ("image" in part) {
2794
+ mimeType = part.mediaType || "image/jpeg";
2795
+ data = part.image;
2796
+ } else {
2797
+ throw new chunkTWH4PTDG_cjs.MastraError({
2798
+ id: "MASTRA_AIV5_DATA_PART_INVALID",
2799
+ domain: "AGENT" /* AGENT */,
2800
+ category: "USER" /* USER */,
2801
+ text: "Invalid AIV5 data part in getDataStringFromAIV5DataPart",
2802
+ details: {
2803
+ part
2804
+ }
2805
+ });
2806
+ }
2807
+ if (data instanceof URL) {
2808
+ return data.toString();
2809
+ } else {
2810
+ if (data instanceof Buffer) {
2811
+ const base64 = data.toString("base64");
2812
+ return `data:${mimeType};base64,${base64}`;
2813
+ } else if (typeof data === "string") {
2814
+ return data.startsWith("data:") || data.startsWith("http") ? data : `data:${mimeType};base64,${data}`;
2815
+ } else if (data instanceof Uint8Array) {
2816
+ const base64 = Buffer.from(data).toString("base64");
2817
+ return `data:${mimeType};base64,${base64}`;
2818
+ } else if (data instanceof ArrayBuffer) {
2819
+ const base64 = Buffer.from(data).toString("base64");
2820
+ return `data:${mimeType};base64,${base64}`;
2821
+ } else {
2822
+ return "";
2823
+ }
2824
+ }
2825
+ };
2714
2826
  /**
2715
2827
  * Direct conversion from AIV5 ModelMessage to MastraDBMessage
2716
2828
  * Combines logic from aiV5ModelMessageToMastraMessageV3 + mastraMessageV3ToV2
2717
2829
  */
2718
2830
  static aiV5ModelMessageToMastraDBMessage(modelMsg, _messageSource) {
2719
2831
  const content = Array.isArray(modelMsg.content) ? modelMsg.content : [{ type: "text", text: modelMsg.content }];
2720
- const v2Parts = [];
2832
+ const mastraDBParts = [];
2721
2833
  const toolInvocations = [];
2722
2834
  const reasoningParts = [];
2723
2835
  const experimental_attachments = [];
2724
- const textParts = [];
2725
2836
  let lastPartWasToolResult = false;
2726
2837
  for (const part of content) {
2727
- const providerMetadata = {
2728
- ...modelMsg.providerMetadata || {},
2729
- ...part.providerMetadata || {}
2730
- };
2731
- const hasProviderMetadata = Object.keys(providerMetadata).length > 0;
2732
2838
  if (part.type === "text") {
2733
2839
  const textPart = {
2734
2840
  type: "text",
2735
- text: part.text,
2736
- ...hasProviderMetadata && { experimental_providerMetadata: providerMetadata }
2841
+ text: part.text
2737
2842
  };
2738
- v2Parts.push(textPart);
2739
- textParts.push({ text: part.text, providerMetadata: hasProviderMetadata ? providerMetadata : void 0 });
2843
+ if (part.providerOptions) {
2844
+ textPart.providerMetadata = part.providerOptions;
2845
+ }
2846
+ mastraDBParts.push(textPart);
2740
2847
  lastPartWasToolResult = false;
2741
2848
  } else if (part.type === "tool-call") {
2742
2849
  const toolCallPart = part;
@@ -2747,10 +2854,12 @@ var MessageList = class _MessageList {
2747
2854
  toolName: toolCallPart.toolName,
2748
2855
  args: toolCallPart.input,
2749
2856
  state: "call"
2750
- },
2751
- ...hasProviderMetadata && { providerMetadata }
2857
+ }
2752
2858
  };
2753
- v2Parts.push(toolInvocationPart);
2859
+ if (part.providerOptions) {
2860
+ toolInvocationPart.providerMetadata = part.providerOptions;
2861
+ }
2862
+ mastraDBParts.push(toolInvocationPart);
2754
2863
  toolInvocations.push({
2755
2864
  toolCallId: toolCallPart.toolCallId,
2756
2865
  toolName: toolCallPart.toolName,
@@ -2761,78 +2870,67 @@ var MessageList = class _MessageList {
2761
2870
  } else if (part.type === "tool-result") {
2762
2871
  const toolResultPart = part;
2763
2872
  const matchingCall = toolInvocations.find((inv) => inv.toolCallId === toolResultPart.toolCallId);
2764
- const matchingV2Part = v2Parts.find(
2873
+ const matchingV2Part = mastraDBParts.find(
2765
2874
  (p) => p.type === "tool-invocation" && "toolInvocation" in p && p.toolInvocation.toolCallId === toolResultPart.toolCallId
2766
2875
  );
2876
+ const updateMatchingCallInvocationResult = (toolResultPart2, matchingCall2) => {
2877
+ matchingCall2.state = "result";
2878
+ matchingCall2.result = typeof toolResultPart2.output === "object" && toolResultPart2.output && "value" in toolResultPart2.output ? toolResultPart2.output.value : toolResultPart2.output;
2879
+ };
2767
2880
  if (matchingCall) {
2768
- matchingCall.state = "result";
2769
- matchingCall.result = typeof toolResultPart.output === "object" && toolResultPart.output && "value" in toolResultPart.output ? toolResultPart.output.value : toolResultPart.output;
2881
+ updateMatchingCallInvocationResult(toolResultPart, matchingCall);
2770
2882
  } else {
2771
- const resultPartWithName = toolResultPart;
2772
- toolInvocations.push({
2883
+ const call = {
2884
+ state: "call",
2773
2885
  toolCallId: toolResultPart.toolCallId,
2774
- toolName: resultPartWithName.toolName || "unknown",
2775
- args: {},
2776
- result: typeof toolResultPart.output === "object" && toolResultPart.output && "value" in toolResultPart.output ? toolResultPart.output.value : toolResultPart.output,
2777
- state: "result"
2778
- });
2886
+ toolName: toolResultPart.toolName || "unknown",
2887
+ args: {}
2888
+ };
2889
+ updateMatchingCallInvocationResult(toolResultPart, call);
2890
+ toolInvocations.push(call);
2779
2891
  }
2780
2892
  if (matchingV2Part && matchingV2Part.type === "tool-invocation") {
2781
- matchingV2Part.toolInvocation.state = "result";
2782
- matchingV2Part.toolInvocation.result = typeof toolResultPart.output === "object" && toolResultPart.output && "value" in toolResultPart.output ? toolResultPart.output.value : toolResultPart.output;
2783
- if (hasProviderMetadata) {
2784
- matchingV2Part.providerMetadata = providerMetadata;
2785
- }
2893
+ updateMatchingCallInvocationResult(toolResultPart, matchingV2Part.toolInvocation);
2786
2894
  } else {
2787
- const resultPartWithName = toolResultPart;
2788
2895
  const toolInvocationPart = {
2789
2896
  type: "tool-invocation",
2790
2897
  toolInvocation: {
2791
2898
  toolCallId: toolResultPart.toolCallId,
2792
- toolName: resultPartWithName.toolName || "unknown",
2899
+ toolName: toolResultPart.toolName || "unknown",
2793
2900
  args: {},
2794
- result: typeof toolResultPart.output === "object" && toolResultPart.output && "value" in toolResultPart.output ? toolResultPart.output.value : toolResultPart.output,
2795
- state: "result"
2796
- },
2797
- ...hasProviderMetadata && { providerMetadata }
2901
+ state: "call"
2902
+ }
2798
2903
  };
2799
- v2Parts.push(toolInvocationPart);
2904
+ updateMatchingCallInvocationResult(toolResultPart, toolInvocationPart.toolInvocation);
2905
+ mastraDBParts.push(toolInvocationPart);
2800
2906
  }
2801
2907
  lastPartWasToolResult = true;
2802
2908
  } else if (part.type === "reasoning") {
2803
- const reasoningPart = part;
2804
2909
  const v2ReasoningPart = {
2805
2910
  type: "reasoning",
2806
- reasoning: reasoningPart.text,
2807
- details: [{ type: "text", text: reasoningPart.text }],
2808
- ...hasProviderMetadata && { providerMetadata }
2911
+ reasoning: "",
2912
+ // leave this blank so we aren't double storing it in the db along with details
2913
+ details: [{ type: "text", text: part.text }]
2809
2914
  };
2810
- v2Parts.push(v2ReasoningPart);
2811
- reasoningParts.push(reasoningPart.text);
2915
+ if (part.providerOptions) {
2916
+ v2ReasoningPart.providerMetadata = part.providerOptions;
2917
+ }
2918
+ mastraDBParts.push(v2ReasoningPart);
2919
+ reasoningParts.push(part.text);
2812
2920
  lastPartWasToolResult = false;
2813
2921
  } else if (part.type === "image") {
2814
2922
  const imagePart = part;
2815
- let imageData;
2816
- const mimeType = imagePart.mimeType || "image/jpeg";
2817
- if ("url" in imagePart && typeof imagePart.url === "string") {
2818
- imageData = imagePart.url;
2819
- } else if ("data" in imagePart) {
2820
- if (typeof imagePart.data === "string") {
2821
- imageData = imagePart.data.startsWith("data:") || imagePart.data.startsWith("http") ? imagePart.data : `data:${mimeType};base64,${imagePart.data}`;
2822
- } else {
2823
- const base64 = Buffer.from(imagePart.data).toString("base64");
2824
- imageData = `data:${mimeType};base64,${base64}`;
2825
- }
2826
- } else {
2827
- imageData = "";
2828
- }
2923
+ const mimeType = imagePart.mediaType || "image/jpeg";
2924
+ const imageData = this.getDataStringFromAIV5DataPart(imagePart);
2829
2925
  const imageFilePart = {
2830
2926
  type: "file",
2831
2927
  data: imageData,
2832
- mimeType,
2833
- ...hasProviderMetadata && { providerMetadata }
2928
+ mimeType
2834
2929
  };
2835
- v2Parts.push(imageFilePart);
2930
+ if (part.providerOptions) {
2931
+ imageFilePart.providerMetadata = part.providerOptions;
2932
+ }
2933
+ mastraDBParts.push(imageFilePart);
2836
2934
  experimental_attachments.push({
2837
2935
  url: imageData,
2838
2936
  contentType: mimeType
@@ -2841,26 +2939,16 @@ var MessageList = class _MessageList {
2841
2939
  } else if (part.type === "file") {
2842
2940
  const filePart = part;
2843
2941
  const mimeType = filePart.mediaType || "application/octet-stream";
2844
- let fileData;
2845
- if ("url" in filePart && typeof filePart.url === "string") {
2846
- fileData = filePart.url;
2847
- } else if ("data" in filePart) {
2848
- if (typeof filePart.data === "string") {
2849
- fileData = filePart.data.startsWith("data:") || filePart.data.startsWith("http") ? filePart.data : `data:${mimeType};base64,${filePart.data}`;
2850
- } else {
2851
- const base64 = Buffer.from(filePart.data).toString("base64");
2852
- fileData = `data:${mimeType};base64,${base64}`;
2853
- }
2854
- } else {
2855
- fileData = "";
2856
- }
2942
+ const fileData = this.getDataStringFromAIV5DataPart(filePart);
2857
2943
  const v2FilePart = {
2858
2944
  type: "file",
2859
2945
  data: fileData,
2860
- mimeType,
2861
- ...hasProviderMetadata && { providerMetadata }
2946
+ mimeType
2862
2947
  };
2863
- v2Parts.push(v2FilePart);
2948
+ if (part.providerOptions) {
2949
+ v2FilePart.providerMetadata = part.providerOptions;
2950
+ }
2951
+ mastraDBParts.push(v2FilePart);
2864
2952
  experimental_attachments.push({
2865
2953
  url: fileData,
2866
2954
  contentType: mimeType
@@ -2868,34 +2956,34 @@ var MessageList = class _MessageList {
2868
2956
  lastPartWasToolResult = false;
2869
2957
  }
2870
2958
  }
2871
- if (modelMsg.role === "assistant" && lastPartWasToolResult && v2Parts.length > 0) {
2872
- const lastPart = v2Parts[v2Parts.length - 1];
2959
+ if (modelMsg.role === "assistant" && lastPartWasToolResult && mastraDBParts.length > 0) {
2960
+ const lastPart = mastraDBParts[mastraDBParts.length - 1];
2873
2961
  if (lastPart && lastPart.type !== "text") {
2874
2962
  const emptyTextPart = { type: "text", text: "" };
2875
- v2Parts.push(emptyTextPart);
2876
- textParts.push({ text: "" });
2963
+ mastraDBParts.push(emptyTextPart);
2877
2964
  }
2878
2965
  }
2879
- let contentString = void 0;
2880
- if (textParts.length > 0) {
2881
- contentString = textParts.map((p) => p.text).join("\n");
2882
- }
2966
+ const contentString = mastraDBParts.filter((p) => p.type === "text").map((p) => p.text).join("\n");
2883
2967
  const metadata = {};
2884
2968
  const id = `id` in modelMsg && typeof modelMsg.id === `string` ? modelMsg.id : `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
2885
- return {
2969
+ const message = {
2886
2970
  id,
2887
2971
  role: _MessageList.getRole(modelMsg),
2888
2972
  createdAt: /* @__PURE__ */ new Date(),
2889
2973
  content: {
2890
2974
  format: 2,
2891
- parts: v2Parts,
2975
+ parts: mastraDBParts,
2892
2976
  toolInvocations: toolInvocations.length > 0 ? toolInvocations : void 0,
2893
2977
  reasoning: reasoningParts.length > 0 ? reasoningParts.join("\n") : void 0,
2894
2978
  experimental_attachments: experimental_attachments.length > 0 ? experimental_attachments : void 0,
2895
- content: contentString,
2979
+ content: contentString || void 0,
2896
2980
  metadata
2897
2981
  }
2898
2982
  };
2983
+ if (modelMsg.providerOptions) {
2984
+ message.content.providerMetadata = modelMsg.providerOptions;
2985
+ }
2986
+ return message;
2899
2987
  }
2900
2988
  aiV4CoreMessagesToAIV5ModelMessages(messages, source) {
2901
2989
  return this.aiV5UIMessagesToAIV5ModelMessages(
@@ -2906,7 +2994,16 @@ var MessageList = class _MessageList {
2906
2994
  const sanitized = this.sanitizeV5UIMessages(messages, filterIncompleteToolCalls);
2907
2995
  const preprocessed = this.addStartStepPartsForAIV5(sanitized);
2908
2996
  const result = AIV5__namespace.convertToModelMessages(preprocessed);
2909
- return result;
2997
+ return result.map((modelMsg, index) => {
2998
+ const uiMsg = preprocessed[index];
2999
+ if (uiMsg?.metadata && typeof uiMsg.metadata === "object" && "providerMetadata" in uiMsg.metadata && uiMsg.metadata.providerMetadata) {
3000
+ return {
3001
+ ...modelMsg,
3002
+ providerOptions: uiMsg.metadata.providerMetadata
3003
+ };
3004
+ }
3005
+ return modelMsg;
3006
+ });
2910
3007
  }
2911
3008
  addStartStepPartsForAIV5(messages) {
2912
3009
  for (const message of messages) {
@@ -3042,5 +3139,5 @@ exports.DefaultGeneratedFile = DefaultGeneratedFile;
3042
3139
  exports.DefaultGeneratedFileWithType = DefaultGeneratedFileWithType;
3043
3140
  exports.MessageList = MessageList;
3044
3141
  exports.convertMessages = convertMessages;
3045
- //# sourceMappingURL=chunk-G36A2JRR.cjs.map
3046
- //# sourceMappingURL=chunk-G36A2JRR.cjs.map
3142
+ //# sourceMappingURL=chunk-VSM3NLUX.cjs.map
3143
+ //# sourceMappingURL=chunk-VSM3NLUX.cjs.map