@mastra/react 0.3.3 → 0.4.0-alpha.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.
package/dist/index.js CHANGED
@@ -87,6 +87,19 @@ var extractRunIdFromMessages = (messages) => {
87
87
  return void 0;
88
88
  };
89
89
 
90
+ // src/agent/signal-data.ts
91
+ function convertSignalDataToBase64String(content) {
92
+ if (typeof content === "string") {
93
+ return content;
94
+ }
95
+ const bytes = content instanceof ArrayBuffer ? new Uint8Array(content) : content;
96
+ let binary = "";
97
+ for (const byte of bytes) {
98
+ binary += String.fromCharCode(byte);
99
+ }
100
+ return btoa(binary);
101
+ }
102
+
90
103
  // src/lib/ai-sdk/utils/formatCompletionFeedback.ts
91
104
  var formatBaseCompletionFeedback = (result, maxIterationReached, formatScorerHeading, incompleteMessage) => {
92
105
  const lines = [];
@@ -1987,11 +2000,37 @@ var useChat = ({
1987
2000
  useEffect(() => {
1988
2001
  _requestContext.current = propsRequestContext;
1989
2002
  }, [propsRequestContext]);
2003
+ const normalizeSignalFileData = (data) => {
2004
+ if (data instanceof URL) return data.toString();
2005
+ return convertSignalDataToBase64String(data);
2006
+ };
1990
2007
  const getSignalContents = (coreUserMessages) => {
1991
- if (coreUserMessages.length === 1) {
1992
- return coreUserMessages[0];
1993
- }
1994
- return coreUserMessages;
2008
+ const parts = coreUserMessages.reduce((allParts, message) => {
2009
+ if (typeof message.content === "string") {
2010
+ allParts.push({ type: "text", text: message.content });
2011
+ return allParts;
2012
+ }
2013
+ for (const part of message.content) {
2014
+ if (part.type === "text") {
2015
+ allParts.push({ type: "text", text: part.text });
2016
+ } else if (part.type === "file") {
2017
+ allParts.push({
2018
+ type: "file",
2019
+ data: normalizeSignalFileData(part.data),
2020
+ mediaType: part.mimeType,
2021
+ ...part.filename ? { filename: part.filename } : {}
2022
+ });
2023
+ } else if (part.type === "image") {
2024
+ allParts.push({
2025
+ type: "file",
2026
+ data: normalizeSignalFileData(part.image),
2027
+ mediaType: part.mimeType ?? "image/png"
2028
+ });
2029
+ }
2030
+ }
2031
+ return allParts;
2032
+ }, []);
2033
+ return parts.length === 1 && parts[0]?.type === "text" ? parts[0].text : parts;
1995
2034
  };
1996
2035
  const markThreadSignalsUnsupported = useCallback(() => {
1997
2036
  _threadSignalsUnsupportedRef.current = true;