@mastra/react 1.2.5 → 1.2.6-alpha.0
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 +10 -0
- package/dist/agent/signal-data.d.ts +3 -0
- package/dist/agent/signal-data.d.ts.map +1 -1
- package/dist/index.cjs +76 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +76 -38
- package/dist/index.js.map +1 -1
- package/dist/lib/mastra-db/accumulator.d.ts.map +1 -1
- package/dist/lib/mastra-db/fromCoreUserMessage.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -68,6 +68,37 @@ var MastraReactProvider = ({
|
|
|
68
68
|
);
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
+
// src/agent/signal-data.ts
|
|
72
|
+
var uint8ArrayToBase64 = (bytes) => {
|
|
73
|
+
const chunkSize = 32768;
|
|
74
|
+
let binary = "";
|
|
75
|
+
for (let i = 0; i < bytes.length; i += chunkSize) {
|
|
76
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + chunkSize));
|
|
77
|
+
}
|
|
78
|
+
return btoa(binary);
|
|
79
|
+
};
|
|
80
|
+
function convertSignalDataToBase64String(content) {
|
|
81
|
+
if (typeof content === "string") {
|
|
82
|
+
return content;
|
|
83
|
+
}
|
|
84
|
+
const bytes = content instanceof ArrayBuffer ? new Uint8Array(content) : content;
|
|
85
|
+
return uint8ArrayToBase64(bytes);
|
|
86
|
+
}
|
|
87
|
+
function encodeFilePartDataForStorage(data, mimeType) {
|
|
88
|
+
if (typeof data === "string") {
|
|
89
|
+
return data;
|
|
90
|
+
}
|
|
91
|
+
if (data instanceof URL) {
|
|
92
|
+
return data.toString();
|
|
93
|
+
}
|
|
94
|
+
const bytes = data instanceof ArrayBuffer ? new Uint8Array(data) : data;
|
|
95
|
+
const base64 = uint8ArrayToBase64(bytes);
|
|
96
|
+
if (base64.startsWith("data:")) {
|
|
97
|
+
return base64;
|
|
98
|
+
}
|
|
99
|
+
return `data:${mimeType};base64,${base64}`;
|
|
100
|
+
}
|
|
101
|
+
|
|
71
102
|
// src/lib/mastra-db/formatCompletionFeedback.ts
|
|
72
103
|
var formatBaseCompletionFeedback = (result, maxIterationReached, formatScorerHeading, incompleteMessage) => {
|
|
73
104
|
const lines = [];
|
|
@@ -118,14 +149,6 @@ var CLIENT_MESSAGE_ID_KEY = "clientMessageId";
|
|
|
118
149
|
|
|
119
150
|
// src/lib/mastra-db/accumulator.ts
|
|
120
151
|
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
|
-
};
|
|
129
152
|
var withParts = (message, parts) => ({
|
|
130
153
|
...message,
|
|
131
154
|
content: {
|
|
@@ -322,22 +345,37 @@ var signalContentsToUserMessages = (contents, metadata) => {
|
|
|
322
345
|
}
|
|
323
346
|
if (typedPart.type === "image") {
|
|
324
347
|
const image = typedPart.image;
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
348
|
+
const mimeType = typeof typedPart.mediaType === "string" ? typedPart.mediaType : typeof typedPart.mimeType === "string" ? typedPart.mimeType : "image/*";
|
|
349
|
+
if (typeof image === "string" || image instanceof URL || image instanceof ArrayBuffer || image instanceof Uint8Array) {
|
|
350
|
+
return [
|
|
351
|
+
{
|
|
352
|
+
type: "file",
|
|
353
|
+
mimeType,
|
|
354
|
+
data: encodeFilePartDataForStorage(image, mimeType)
|
|
355
|
+
}
|
|
356
|
+
];
|
|
357
|
+
}
|
|
358
|
+
return [{ type: "file", mimeType, data: "" }];
|
|
332
359
|
}
|
|
333
360
|
if (typedPart.type === "file") {
|
|
334
361
|
const data = typedPart.data;
|
|
335
|
-
const
|
|
362
|
+
const mimeType = typeof typedPart.mediaType === "string" ? typedPart.mediaType : typeof typedPart.mimeType === "string" ? typedPart.mimeType : "application/octet-stream";
|
|
363
|
+
if (typeof data === "string" || data instanceof URL || data instanceof ArrayBuffer || data instanceof Uint8Array) {
|
|
364
|
+
return [
|
|
365
|
+
{
|
|
366
|
+
type: "file",
|
|
367
|
+
mimeType,
|
|
368
|
+
data: encodeFilePartDataForStorage(data, mimeType),
|
|
369
|
+
...typeof typedPart.filename === "string" ? { filename: typedPart.filename } : {}
|
|
370
|
+
}
|
|
371
|
+
];
|
|
372
|
+
}
|
|
373
|
+
const urlFallback = typeof typedPart.url === "string" ? typedPart.url : "";
|
|
336
374
|
return [
|
|
337
375
|
{
|
|
338
376
|
type: "file",
|
|
339
|
-
mimeType
|
|
340
|
-
data:
|
|
377
|
+
mimeType,
|
|
378
|
+
data: urlFallback,
|
|
341
379
|
...typeof typedPart.filename === "string" ? { filename: typedPart.filename } : {}
|
|
342
380
|
}
|
|
343
381
|
];
|
|
@@ -362,6 +400,15 @@ var signalContentsToUserMessages = (contents, metadata) => {
|
|
|
362
400
|
const parts = content.flatMap(toMessagePart);
|
|
363
401
|
return parts.length ? [makeUserMessage(parts)] : [];
|
|
364
402
|
};
|
|
403
|
+
var reconcilePendingUserEcho = (message, echoedContents, metadata, options) => {
|
|
404
|
+
const echoedMessages = signalContentsToUserMessages(echoedContents, metadata);
|
|
405
|
+
const echoedParts = echoedMessages[0]?.content.parts;
|
|
406
|
+
let reconciled = typeof options.signalId === "string" ? { ...message, id: options.signalId } : message;
|
|
407
|
+
if (echoedParts?.length) {
|
|
408
|
+
reconciled = { ...reconciled, content: { ...reconciled.content, parts: echoedParts } };
|
|
409
|
+
}
|
|
410
|
+
return options.keepClientMessageId ? clearPendingStatusKeepClientId(reconciled) : clearPendingStatus(reconciled);
|
|
411
|
+
};
|
|
365
412
|
var makeToolInvocationPart = (invocation) => ({
|
|
366
413
|
type: "tool-invocation",
|
|
367
414
|
toolInvocation: invocation
|
|
@@ -382,14 +429,19 @@ var accumulateChunk = ({ chunk, conversation, metadata }) => {
|
|
|
382
429
|
)) {
|
|
383
430
|
return finishStreamingAssistantMessage(
|
|
384
431
|
result.map(
|
|
385
|
-
(message) => message.content.metadata?.status === "pending" && message.content.metadata[CLIENT_MESSAGE_ID_KEY] === echoedClientMessageId ?
|
|
432
|
+
(message) => message.content.metadata?.status === "pending" && message.content.metadata[CLIENT_MESSAGE_ID_KEY] === echoedClientMessageId ? reconcilePendingUserEcho(message, chunk.data.contents, metadata, {
|
|
433
|
+
signalId: typeof signalId === "string" ? signalId : void 0,
|
|
434
|
+
keepClientMessageId: true
|
|
435
|
+
}) : message
|
|
386
436
|
)
|
|
387
437
|
);
|
|
388
438
|
}
|
|
389
439
|
if (typeof signalId === "string" && result.some((message) => message.id === signalId)) {
|
|
390
440
|
return finishStreamingAssistantMessage(
|
|
391
441
|
result.map(
|
|
392
|
-
(message) => message.id === signalId && message.content.metadata?.status === "pending" ?
|
|
442
|
+
(message) => message.id === signalId && message.content.metadata?.status === "pending" ? reconcilePendingUserEcho(message, chunk.data.contents, metadata, {
|
|
443
|
+
keepClientMessageId: false
|
|
444
|
+
}) : message
|
|
393
445
|
)
|
|
394
446
|
);
|
|
395
447
|
}
|
|
@@ -1676,19 +1728,18 @@ var coreUserMessageToParts = (coreUserMessage) => typeof coreUserMessage.content
|
|
|
1676
1728
|
return { type: "text", text: part.text };
|
|
1677
1729
|
}
|
|
1678
1730
|
case "image": {
|
|
1679
|
-
const
|
|
1731
|
+
const mimeType = part.mimeType ?? "image/*";
|
|
1680
1732
|
return {
|
|
1681
1733
|
type: "file",
|
|
1682
|
-
mimeType
|
|
1683
|
-
data
|
|
1734
|
+
mimeType,
|
|
1735
|
+
data: encodeFilePartDataForStorage(part.image, mimeType)
|
|
1684
1736
|
};
|
|
1685
1737
|
}
|
|
1686
1738
|
case "file": {
|
|
1687
|
-
const data = typeof part.data === "string" ? part.data : part.data instanceof URL ? part.data.toString() : "";
|
|
1688
1739
|
return {
|
|
1689
1740
|
type: "file",
|
|
1690
1741
|
mimeType: part.mimeType,
|
|
1691
|
-
data,
|
|
1742
|
+
data: encodeFilePartDataForStorage(part.data, part.mimeType),
|
|
1692
1743
|
...part.filename !== void 0 ? { filename: part.filename } : {}
|
|
1693
1744
|
};
|
|
1694
1745
|
}
|
|
@@ -1816,19 +1867,6 @@ var extractRunIdFromMessages = (messages) => {
|
|
|
1816
1867
|
return void 0;
|
|
1817
1868
|
};
|
|
1818
1869
|
|
|
1819
|
-
// src/agent/signal-data.ts
|
|
1820
|
-
function convertSignalDataToBase64String(content) {
|
|
1821
|
-
if (typeof content === "string") {
|
|
1822
|
-
return content;
|
|
1823
|
-
}
|
|
1824
|
-
const bytes = content instanceof ArrayBuffer ? new Uint8Array(content) : content;
|
|
1825
|
-
let binary = "";
|
|
1826
|
-
for (const byte of bytes) {
|
|
1827
|
-
binary += String.fromCharCode(byte);
|
|
1828
|
-
}
|
|
1829
|
-
return btoa(binary);
|
|
1830
|
-
}
|
|
1831
|
-
|
|
1832
1870
|
// src/agent/hooks.ts
|
|
1833
1871
|
var extractPendingToolApprovalIdsFromMessages = (messages) => {
|
|
1834
1872
|
const pendingToolApprovalIds = /* @__PURE__ */ new Set();
|