@mastra/react 1.2.5-alpha.8 → 1.2.5
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/CHANGELOG.md +52 -0
- package/dist/index.cjs +19 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19 -10
- package/dist/index.js.map +1 -1
- package/dist/lib/mastra-db/accumulator.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -118,6 +118,14 @@ var CLIENT_MESSAGE_ID_KEY = "clientMessageId";
|
|
|
118
118
|
|
|
119
119
|
// src/lib/mastra-db/accumulator.ts
|
|
120
120
|
var cloneMetadata = (metadata) => metadata ? { ...metadata } : {};
|
|
121
|
+
var uint8ArrayToBase64 = (bytes) => {
|
|
122
|
+
const chunkSize = 32768;
|
|
123
|
+
let binary = "";
|
|
124
|
+
for (let i = 0; i < bytes.length; i += chunkSize) {
|
|
125
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + chunkSize));
|
|
126
|
+
}
|
|
127
|
+
return btoa(binary);
|
|
128
|
+
};
|
|
121
129
|
var withParts = (message, parts) => ({
|
|
122
130
|
...message,
|
|
123
131
|
content: {
|
|
@@ -317,18 +325,19 @@ var signalContentsToUserMessages = (contents, metadata) => {
|
|
|
317
325
|
return [
|
|
318
326
|
{
|
|
319
327
|
type: "file",
|
|
320
|
-
|
|
321
|
-
|
|
328
|
+
mimeType: typeof typedPart.mediaType === "string" ? typedPart.mediaType : typeof typedPart.mimeType === "string" ? typedPart.mimeType : "image/*",
|
|
329
|
+
data: typeof image === "string" ? image : image instanceof URL ? image.toString() : ""
|
|
322
330
|
}
|
|
323
331
|
];
|
|
324
332
|
}
|
|
325
333
|
if (typedPart.type === "file") {
|
|
326
334
|
const data = typedPart.data;
|
|
335
|
+
const dataValue = typeof data === "string" ? data : data instanceof URL ? data.toString() : typeof typedPart.url === "string" ? typedPart.url : "";
|
|
327
336
|
return [
|
|
328
337
|
{
|
|
329
338
|
type: "file",
|
|
330
|
-
|
|
331
|
-
|
|
339
|
+
mimeType: typeof typedPart.mediaType === "string" ? typedPart.mediaType : typeof typedPart.mimeType === "string" ? typedPart.mimeType : "application/octet-stream",
|
|
340
|
+
data: dataValue,
|
|
332
341
|
...typeof typedPart.filename === "string" ? { filename: typedPart.filename } : {}
|
|
333
342
|
}
|
|
334
343
|
];
|
|
@@ -987,17 +996,17 @@ var accumulateChunk = ({ chunk, conversation, metadata }) => {
|
|
|
987
996
|
const lastMessage = result[result.length - 1];
|
|
988
997
|
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
989
998
|
const parts = [...lastMessage.content.parts];
|
|
990
|
-
let
|
|
999
|
+
let data;
|
|
991
1000
|
if (typeof chunk.payload.data === "string") {
|
|
992
|
-
|
|
1001
|
+
data = chunk.payload.base64 ? `data:${chunk.payload.mimeType};base64,${chunk.payload.data}` : `data:${chunk.payload.mimeType},${encodeURIComponent(chunk.payload.data)}`;
|
|
993
1002
|
} else {
|
|
994
|
-
const base64 =
|
|
995
|
-
|
|
1003
|
+
const base64 = uint8ArrayToBase64(chunk.payload.data);
|
|
1004
|
+
data = `data:${chunk.payload.mimeType};base64,${base64}`;
|
|
996
1005
|
}
|
|
997
1006
|
parts.push({
|
|
998
1007
|
type: "file",
|
|
999
|
-
|
|
1000
|
-
|
|
1008
|
+
mimeType: chunk.payload.mimeType,
|
|
1009
|
+
data,
|
|
1001
1010
|
providerMetadata: chunk.payload.providerMetadata
|
|
1002
1011
|
});
|
|
1003
1012
|
return replaceLast(result, withParts(lastMessage, parts));
|