@mastra/core 0.15.3-alpha.6 → 0.15.3-alpha.8
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 +14 -0
- package/dist/agent/index.cjs +11 -11
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +2 -2
- package/dist/agent/input-processor/index.cjs +6 -6
- package/dist/agent/input-processor/index.js +1 -1
- package/dist/agent/message-list/index.d.ts.map +1 -1
- package/dist/agent/message-list/prompt/image-utils.d.ts +56 -0
- package/dist/agent/message-list/prompt/image-utils.d.ts.map +1 -0
- package/dist/{chunk-JWURNPTP.js → chunk-3J53FZD3.js} +3 -3
- package/dist/{chunk-JWURNPTP.js.map → chunk-3J53FZD3.js.map} +1 -1
- package/dist/{chunk-6C6CR7JZ.cjs → chunk-4VDXHBFW.cjs} +7 -7
- package/dist/{chunk-6C6CR7JZ.cjs.map → chunk-4VDXHBFW.cjs.map} +1 -1
- package/dist/{chunk-NHAHPLS5.js → chunk-AQE35OJE.js} +3 -3
- package/dist/{chunk-NHAHPLS5.js.map → chunk-AQE35OJE.js.map} +1 -1
- package/dist/{chunk-25VRTGOH.cjs → chunk-AQX57EIH.cjs} +30 -31
- package/dist/chunk-AQX57EIH.cjs.map +1 -0
- package/dist/{chunk-IQ5ISXGO.cjs → chunk-EBOMP2R5.cjs} +4 -4
- package/dist/{chunk-IQ5ISXGO.cjs.map → chunk-EBOMP2R5.cjs.map} +1 -1
- package/dist/{chunk-IH5UAO56.js → chunk-ELYFYZO6.js} +11 -12
- package/dist/chunk-ELYFYZO6.js.map +1 -0
- package/dist/{chunk-POFCBVHG.js → chunk-EU3ADOKK.js} +3 -3
- package/dist/{chunk-POFCBVHG.js.map → chunk-EU3ADOKK.js.map} +1 -1
- package/dist/{chunk-BGE27UEX.js → chunk-HF7HXOCC.js} +196 -28
- package/dist/chunk-HF7HXOCC.js.map +1 -0
- package/dist/{chunk-AAJF7WLJ.cjs → chunk-SIKEQ32R.cjs} +196 -28
- package/dist/chunk-SIKEQ32R.cjs.map +1 -0
- package/dist/{chunk-626FLQPT.cjs → chunk-TCYQAAIT.cjs} +4 -4
- package/dist/{chunk-626FLQPT.cjs.map → chunk-TCYQAAIT.cjs.map} +1 -1
- package/dist/{chunk-7S5FYPH7.js → chunk-YI3DG7WN.js} +3 -3
- package/dist/{chunk-7S5FYPH7.js.map → chunk-YI3DG7WN.js.map} +1 -1
- package/dist/{chunk-5KIEN3HX.cjs → chunk-ZDPAMCRK.cjs} +4 -4
- package/dist/{chunk-5KIEN3HX.cjs.map → chunk-ZDPAMCRK.cjs.map} +1 -1
- package/dist/index.cjs +21 -21
- package/dist/index.js +6 -6
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +4 -4
- package/dist/memory/index.js +1 -1
- package/dist/network/index.cjs +2 -2
- package/dist/network/index.js +1 -1
- package/dist/network/vNext/index.cjs +14 -14
- package/dist/network/vNext/index.js +2 -2
- package/dist/processors/index.cjs +8 -8
- package/dist/processors/index.js +2 -2
- package/dist/relevance/index.cjs +4 -4
- package/dist/relevance/index.js +1 -1
- package/dist/scores/index.cjs +5 -5
- package/dist/scores/index.js +1 -1
- package/dist/storage/index.cjs +3 -3
- package/dist/storage/index.js +1 -1
- package/dist/stream/index.cjs +3 -3
- package/dist/stream/index.js +1 -1
- package/dist/workflows/default.d.ts +1 -2
- package/dist/workflows/default.d.ts.map +1 -1
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/index.cjs +10 -10
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/legacy/index.cjs +22 -22
- package/dist/workflows/legacy/index.js +1 -1
- package/package.json +3 -3
- package/dist/chunk-25VRTGOH.cjs.map +0 -1
- package/dist/chunk-AAJF7WLJ.cjs.map +0 -1
- package/dist/chunk-BGE27UEX.js.map +0 -1
- package/dist/chunk-IH5UAO56.js.map +0 -1
|
@@ -684,6 +684,79 @@ async function downloadAssetsFromMessages({
|
|
|
684
684
|
return Object.fromEntries(downloadFileList);
|
|
685
685
|
}
|
|
686
686
|
|
|
687
|
+
// src/agent/message-list/prompt/image-utils.ts
|
|
688
|
+
function parseDataUri(dataUri) {
|
|
689
|
+
if (!dataUri.startsWith("data:")) {
|
|
690
|
+
return {
|
|
691
|
+
isDataUri: false,
|
|
692
|
+
base64Content: dataUri
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
const base64Index = dataUri.indexOf(",");
|
|
696
|
+
if (base64Index === -1) {
|
|
697
|
+
return {
|
|
698
|
+
isDataUri: true,
|
|
699
|
+
base64Content: dataUri
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
const header = dataUri.substring(5, base64Index);
|
|
703
|
+
const base64Content = dataUri.substring(base64Index + 1);
|
|
704
|
+
const semicolonIndex = header.indexOf(";");
|
|
705
|
+
const mimeType = semicolonIndex !== -1 ? header.substring(0, semicolonIndex) : header;
|
|
706
|
+
return {
|
|
707
|
+
isDataUri: true,
|
|
708
|
+
mimeType: mimeType || void 0,
|
|
709
|
+
base64Content
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
function createDataUri(base64Content, mimeType = "application/octet-stream") {
|
|
713
|
+
if (base64Content.startsWith("data:")) {
|
|
714
|
+
return base64Content;
|
|
715
|
+
}
|
|
716
|
+
return `data:${mimeType};base64,${base64Content}`;
|
|
717
|
+
}
|
|
718
|
+
function imageContentToString(image, fallbackMimeType) {
|
|
719
|
+
if (typeof image === "string") {
|
|
720
|
+
return image;
|
|
721
|
+
}
|
|
722
|
+
if (image instanceof URL) {
|
|
723
|
+
return image.toString();
|
|
724
|
+
}
|
|
725
|
+
if (image instanceof Uint8Array || image instanceof ArrayBuffer || globalThis.Buffer && Buffer.isBuffer(image)) {
|
|
726
|
+
const base64 = convertDataContentToBase64String(image);
|
|
727
|
+
if (fallbackMimeType && !base64.startsWith("data:")) {
|
|
728
|
+
return `data:${fallbackMimeType};base64,${base64}`;
|
|
729
|
+
}
|
|
730
|
+
return base64;
|
|
731
|
+
}
|
|
732
|
+
return String(image);
|
|
733
|
+
}
|
|
734
|
+
function imageContentToDataUri(image, mimeType = "image/png") {
|
|
735
|
+
const imageStr = imageContentToString(image, mimeType);
|
|
736
|
+
if (imageStr.startsWith("data:")) {
|
|
737
|
+
return imageStr;
|
|
738
|
+
}
|
|
739
|
+
if (imageStr.startsWith("http://") || imageStr.startsWith("https://")) {
|
|
740
|
+
return imageStr;
|
|
741
|
+
}
|
|
742
|
+
return `data:${mimeType};base64,${imageStr}`;
|
|
743
|
+
}
|
|
744
|
+
function getImageCacheKey(image) {
|
|
745
|
+
if (image instanceof URL) {
|
|
746
|
+
return image.toString();
|
|
747
|
+
}
|
|
748
|
+
if (typeof image === "string") {
|
|
749
|
+
return image.length;
|
|
750
|
+
}
|
|
751
|
+
if (image instanceof Uint8Array) {
|
|
752
|
+
return image.byteLength;
|
|
753
|
+
}
|
|
754
|
+
if (image instanceof ArrayBuffer) {
|
|
755
|
+
return image.byteLength;
|
|
756
|
+
}
|
|
757
|
+
return image;
|
|
758
|
+
}
|
|
759
|
+
|
|
687
760
|
// src/agent/message-list/utils/ai-v5/tool.ts
|
|
688
761
|
function getToolName(type) {
|
|
689
762
|
if (typeof type === "object" && type && "type" in type) {
|
|
@@ -993,7 +1066,7 @@ var MessageList = class _MessageList {
|
|
|
993
1066
|
return {
|
|
994
1067
|
type: "file",
|
|
995
1068
|
file: new DefaultGeneratedFileWithType({
|
|
996
|
-
data: typeof c.data === `string` ? c.data : c.data instanceof URL ? c.data.toString() : convertDataContentToBase64String(c.data),
|
|
1069
|
+
data: typeof c.data === `string` ? parseDataUri(c.data).base64Content : c.data instanceof URL ? c.data.toString() : convertDataContentToBase64String(c.data),
|
|
997
1070
|
mediaType: c.mediaType
|
|
998
1071
|
})
|
|
999
1072
|
};
|
|
@@ -1001,7 +1074,7 @@ var MessageList = class _MessageList {
|
|
|
1001
1074
|
return {
|
|
1002
1075
|
type: "file",
|
|
1003
1076
|
file: new DefaultGeneratedFileWithType({
|
|
1004
|
-
data: typeof c.image === `string` ? c.image : c.image instanceof URL ? c.image.toString() : convertDataContentToBase64String(c.image),
|
|
1077
|
+
data: typeof c.image === `string` ? parseDataUri(c.image).base64Content : c.image instanceof URL ? c.image.toString() : convertDataContentToBase64String(c.image),
|
|
1005
1078
|
mediaType: c.mediaType || "unknown"
|
|
1006
1079
|
})
|
|
1007
1080
|
};
|
|
@@ -1651,7 +1724,11 @@ var MessageList = class _MessageList {
|
|
|
1651
1724
|
});
|
|
1652
1725
|
break;
|
|
1653
1726
|
case "image":
|
|
1654
|
-
parts.push({
|
|
1727
|
+
parts.push({
|
|
1728
|
+
type: "file",
|
|
1729
|
+
data: imageContentToString(part.image),
|
|
1730
|
+
mimeType: part.mimeType
|
|
1731
|
+
});
|
|
1655
1732
|
break;
|
|
1656
1733
|
case "file":
|
|
1657
1734
|
if (part.data instanceof URL) {
|
|
@@ -1784,7 +1861,7 @@ var MessageList = class _MessageList {
|
|
|
1784
1861
|
key += part.mimeType;
|
|
1785
1862
|
}
|
|
1786
1863
|
if (part.type === `image`) {
|
|
1787
|
-
key +=
|
|
1864
|
+
key += getImageCacheKey(part.image);
|
|
1788
1865
|
key += part.mimeType;
|
|
1789
1866
|
}
|
|
1790
1867
|
if (part.type === `redacted-reasoning`) {
|
|
@@ -2259,15 +2336,39 @@ var MessageList = class _MessageList {
|
|
|
2259
2336
|
});
|
|
2260
2337
|
}
|
|
2261
2338
|
break;
|
|
2262
|
-
case "file":
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2339
|
+
case "file": {
|
|
2340
|
+
if (typeof part.data === "string" && (part.data.startsWith("http://") || part.data.startsWith("https://"))) {
|
|
2341
|
+
parts.push({
|
|
2342
|
+
type: "file",
|
|
2343
|
+
url: part.data,
|
|
2344
|
+
mediaType: part.mimeType || "image/png",
|
|
2345
|
+
providerMetadata: part.providerMetadata
|
|
2346
|
+
});
|
|
2347
|
+
} else {
|
|
2348
|
+
let filePartData;
|
|
2349
|
+
let extractedMimeType = part.mimeType;
|
|
2350
|
+
if (typeof part.data === "string") {
|
|
2351
|
+
const parsed = parseDataUri(part.data);
|
|
2352
|
+
filePartData = parsed.base64Content;
|
|
2353
|
+
if (parsed.isDataUri && parsed.mimeType) {
|
|
2354
|
+
extractedMimeType = extractedMimeType || parsed.mimeType;
|
|
2355
|
+
}
|
|
2356
|
+
} else {
|
|
2357
|
+
filePartData = part.data;
|
|
2358
|
+
}
|
|
2359
|
+
const finalMimeType = extractedMimeType || "image/png";
|
|
2360
|
+
const dataUri = createDataUri(filePartData, finalMimeType);
|
|
2361
|
+
parts.push({
|
|
2362
|
+
type: "file",
|
|
2363
|
+
url: dataUri,
|
|
2364
|
+
// Use url field with data URI
|
|
2365
|
+
mediaType: finalMimeType,
|
|
2366
|
+
providerMetadata: part.providerMetadata
|
|
2367
|
+
});
|
|
2368
|
+
}
|
|
2269
2369
|
fileUrls.add(part.data);
|
|
2270
2370
|
break;
|
|
2371
|
+
}
|
|
2271
2372
|
}
|
|
2272
2373
|
}
|
|
2273
2374
|
if (v2Msg.content.content && !v3Msg.content.parts?.some((p) => p.type === `text`)) {
|
|
@@ -2438,35 +2539,102 @@ var MessageList = class _MessageList {
|
|
|
2438
2539
|
providerMetadata: part.providerOptions
|
|
2439
2540
|
});
|
|
2440
2541
|
break;
|
|
2441
|
-
case "image":
|
|
2542
|
+
case "image": {
|
|
2543
|
+
let imageData;
|
|
2544
|
+
let extractedMimeType = part.mediaType;
|
|
2545
|
+
const imageStr = imageContentToDataUri(part.image, extractedMimeType || "image/png");
|
|
2546
|
+
const parsed = parseDataUri(imageStr);
|
|
2547
|
+
if (parsed.isDataUri) {
|
|
2548
|
+
imageData = parsed.base64Content;
|
|
2549
|
+
if (!extractedMimeType && parsed.mimeType) {
|
|
2550
|
+
extractedMimeType = parsed.mimeType;
|
|
2551
|
+
}
|
|
2552
|
+
} else if (imageStr.startsWith("http://") || imageStr.startsWith("https://")) {
|
|
2553
|
+
parts.push({
|
|
2554
|
+
type: "file",
|
|
2555
|
+
url: imageStr,
|
|
2556
|
+
mediaType: part.mediaType || "image/jpeg",
|
|
2557
|
+
// Default to image/jpeg for URLs
|
|
2558
|
+
providerMetadata: part.providerOptions
|
|
2559
|
+
});
|
|
2560
|
+
break;
|
|
2561
|
+
} else {
|
|
2562
|
+
imageData = imageStr;
|
|
2563
|
+
}
|
|
2564
|
+
const finalMimeType = extractedMimeType || "image/jpeg";
|
|
2565
|
+
const dataUri = imageData.startsWith("data:") ? imageData : createDataUri(imageData, finalMimeType);
|
|
2442
2566
|
parts.push({
|
|
2443
2567
|
type: "file",
|
|
2444
|
-
url:
|
|
2445
|
-
mediaType:
|
|
2568
|
+
url: dataUri,
|
|
2569
|
+
mediaType: finalMimeType,
|
|
2446
2570
|
providerMetadata: part.providerOptions
|
|
2447
2571
|
});
|
|
2448
2572
|
break;
|
|
2449
|
-
|
|
2573
|
+
}
|
|
2574
|
+
case "file": {
|
|
2450
2575
|
if (part.data instanceof URL) {
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2576
|
+
const urlStr = part.data.toString();
|
|
2577
|
+
let extractedMimeType = part.mediaType;
|
|
2578
|
+
const parsed = parseDataUri(urlStr);
|
|
2579
|
+
if (parsed.isDataUri) {
|
|
2580
|
+
if (!extractedMimeType && parsed.mimeType) {
|
|
2581
|
+
extractedMimeType = parsed.mimeType;
|
|
2582
|
+
}
|
|
2583
|
+
if (parsed.base64Content !== urlStr) {
|
|
2584
|
+
const dataUri = createDataUri(parsed.base64Content, extractedMimeType || "image/png");
|
|
2585
|
+
parts.push({
|
|
2586
|
+
type: "file",
|
|
2587
|
+
url: dataUri,
|
|
2588
|
+
mediaType: extractedMimeType || "image/png",
|
|
2589
|
+
providerMetadata: part.providerOptions
|
|
2590
|
+
});
|
|
2591
|
+
} else {
|
|
2592
|
+
parts.push({
|
|
2593
|
+
type: "file",
|
|
2594
|
+
url: urlStr,
|
|
2595
|
+
mediaType: part.mediaType || "image/png",
|
|
2596
|
+
providerMetadata: part.providerOptions
|
|
2597
|
+
});
|
|
2598
|
+
}
|
|
2599
|
+
} else {
|
|
2459
2600
|
parts.push({
|
|
2460
2601
|
type: "file",
|
|
2461
|
-
|
|
2462
|
-
|
|
2602
|
+
url: urlStr,
|
|
2603
|
+
mediaType: part.mediaType || "application/octet-stream",
|
|
2463
2604
|
providerMetadata: part.providerOptions
|
|
2464
2605
|
});
|
|
2606
|
+
}
|
|
2607
|
+
} else {
|
|
2608
|
+
try {
|
|
2609
|
+
const base64Data = convertDataContentToBase64String(part.data);
|
|
2610
|
+
let extractedMimeType = part.mediaType;
|
|
2611
|
+
const parsed = parseDataUri(base64Data);
|
|
2612
|
+
if (parsed.isDataUri) {
|
|
2613
|
+
if (!extractedMimeType && parsed.mimeType) {
|
|
2614
|
+
extractedMimeType = parsed.mimeType;
|
|
2615
|
+
}
|
|
2616
|
+
const dataUri = createDataUri(parsed.base64Content, extractedMimeType || "image/png");
|
|
2617
|
+
parts.push({
|
|
2618
|
+
type: "file",
|
|
2619
|
+
url: dataUri,
|
|
2620
|
+
mediaType: extractedMimeType || "image/png",
|
|
2621
|
+
providerMetadata: part.providerOptions
|
|
2622
|
+
});
|
|
2623
|
+
} else {
|
|
2624
|
+
const dataUri = createDataUri(base64Data, part.mediaType || "image/png");
|
|
2625
|
+
parts.push({
|
|
2626
|
+
type: "file",
|
|
2627
|
+
url: dataUri,
|
|
2628
|
+
mediaType: part.mediaType || "image/png",
|
|
2629
|
+
providerMetadata: part.providerOptions
|
|
2630
|
+
});
|
|
2631
|
+
}
|
|
2465
2632
|
} catch (error) {
|
|
2466
2633
|
console.error(`Failed to convert binary data to base64 in CoreMessage file part: ${error}`, error);
|
|
2467
2634
|
}
|
|
2468
2635
|
}
|
|
2469
2636
|
break;
|
|
2637
|
+
}
|
|
2470
2638
|
}
|
|
2471
2639
|
}
|
|
2472
2640
|
}
|
|
@@ -2572,7 +2740,7 @@ var MessageList = class _MessageList {
|
|
|
2572
2740
|
key += part.mediaType;
|
|
2573
2741
|
}
|
|
2574
2742
|
if (part.type === `image`) {
|
|
2575
|
-
key +=
|
|
2743
|
+
key += getImageCacheKey(part.image);
|
|
2576
2744
|
key += part.mediaType;
|
|
2577
2745
|
}
|
|
2578
2746
|
}
|
|
@@ -2612,5 +2780,5 @@ exports.DefaultGeneratedFile = DefaultGeneratedFile;
|
|
|
2612
2780
|
exports.DefaultGeneratedFileWithType = DefaultGeneratedFileWithType;
|
|
2613
2781
|
exports.MessageList = MessageList;
|
|
2614
2782
|
exports.convertMessages = convertMessages;
|
|
2615
|
-
//# sourceMappingURL=chunk-
|
|
2616
|
-
//# sourceMappingURL=chunk-
|
|
2783
|
+
//# sourceMappingURL=chunk-SIKEQ32R.cjs.map
|
|
2784
|
+
//# sourceMappingURL=chunk-SIKEQ32R.cjs.map
|