@mastra/core 1.0.0-beta.4 → 1.0.0-beta.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 +325 -0
- package/dist/agent/agent.d.ts +2 -2
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.types.d.ts +2 -0
- package/dist/agent/agent.types.d.ts.map +1 -1
- package/dist/agent/index.cjs +9 -9
- package/dist/agent/index.js +2 -2
- package/dist/agent/message-list/index.cjs +3 -3
- package/dist/agent/message-list/index.d.ts.map +1 -1
- package/dist/agent/message-list/index.js +1 -1
- package/dist/agent/message-list/prompt/attachments-to-parts.d.ts.map +1 -1
- package/dist/agent/types.d.ts +2 -3
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/utils.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts +8 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
- package/dist/{chunk-3RW5EMSB.js → chunk-3B2OPLGG.js} +13 -6
- package/dist/chunk-3B2OPLGG.js.map +1 -0
- package/dist/{chunk-RXDJL5QT.js → chunk-3ZQ7LX73.js} +13 -13
- package/dist/chunk-3ZQ7LX73.js.map +1 -0
- package/dist/{chunk-5WXEYDFI.cjs → chunk-556MJ7CL.cjs} +33 -26
- package/dist/chunk-556MJ7CL.cjs.map +1 -0
- package/dist/{chunk-HGNRQ3OG.js → chunk-5O52O25J.js} +15 -8
- package/dist/chunk-5O52O25J.js.map +1 -0
- package/dist/{chunk-WTYNK7Q4.js → chunk-5SA2EZ33.js} +421 -29
- package/dist/chunk-5SA2EZ33.js.map +1 -0
- package/dist/chunk-6XCINXZ7.cjs +194 -0
- package/dist/chunk-6XCINXZ7.cjs.map +1 -0
- package/dist/{chunk-MDKPL2R2.js → chunk-7ZADRRDW.js} +5 -4
- package/dist/chunk-7ZADRRDW.js.map +1 -0
- package/dist/{chunk-JXESKY4A.js → chunk-B5J5HYDN.js} +7 -5
- package/dist/chunk-B5J5HYDN.js.map +1 -0
- package/dist/chunk-BWYU7D33.js +192 -0
- package/dist/chunk-BWYU7D33.js.map +1 -0
- package/dist/{chunk-FVNT7VTO.js → chunk-D7CJ4HIQ.js} +240 -17
- package/dist/chunk-D7CJ4HIQ.js.map +1 -0
- package/dist/{chunk-VSM3NLUX.cjs → chunk-DQIZ5FFX.cjs} +163 -129
- package/dist/chunk-DQIZ5FFX.cjs.map +1 -0
- package/dist/{chunk-ZCVTH3CH.cjs → chunk-HNHZGFZY.cjs} +5 -4
- package/dist/chunk-HNHZGFZY.cjs.map +1 -0
- package/dist/{chunk-VZC4BWWH.cjs → chunk-IITXXVYI.cjs} +17 -17
- package/dist/chunk-IITXXVYI.cjs.map +1 -0
- package/dist/{chunk-2OTDXX73.js → chunk-KJIQGPQR.js} +4 -4
- package/dist/{chunk-2OTDXX73.js.map → chunk-KJIQGPQR.js.map} +1 -1
- package/dist/{chunk-2NVBZKZI.cjs → chunk-KP42JLXE.cjs} +370 -132
- package/dist/chunk-KP42JLXE.cjs.map +1 -0
- package/dist/{chunk-IWB65P37.cjs → chunk-KWWD3U7G.cjs} +5 -5
- package/dist/chunk-KWWD3U7G.cjs.map +1 -0
- package/dist/{chunk-3W5RQCCY.cjs → chunk-NHP6ZIDG.cjs} +248 -24
- package/dist/chunk-NHP6ZIDG.cjs.map +1 -0
- package/dist/{chunk-O6NA3Z43.cjs → chunk-OUUPUAGA.cjs} +10 -8
- package/dist/chunk-OUUPUAGA.cjs.map +1 -0
- package/dist/{chunk-D6EDHNGV.js → chunk-PC6EKOWK.js} +64 -11
- package/dist/chunk-PC6EKOWK.js.map +1 -0
- package/dist/{chunk-S6OEQHEI.cjs → chunk-QGWNF2QJ.cjs} +59 -50
- package/dist/chunk-QGWNF2QJ.cjs.map +1 -0
- package/dist/{chunk-HBJPYQRN.cjs → chunk-RROQ46B6.cjs} +69 -16
- package/dist/chunk-RROQ46B6.cjs.map +1 -0
- package/dist/{chunk-U7VECK2G.js → chunk-T2CJRA6E.js} +4 -4
- package/dist/chunk-T2CJRA6E.js.map +1 -0
- package/dist/{chunk-IHJDOC3A.js → chunk-T2UNO766.js} +16 -7
- package/dist/chunk-T2UNO766.js.map +1 -0
- package/dist/{chunk-CYVNOIXS.cjs → chunk-U3VE2EVB.cjs} +11 -11
- package/dist/{chunk-CYVNOIXS.cjs.map → chunk-U3VE2EVB.cjs.map} +1 -1
- package/dist/{chunk-4IKJAKCD.cjs → chunk-V537VSV4.cjs} +74 -16
- package/dist/chunk-V537VSV4.cjs.map +1 -0
- package/dist/{chunk-4RXG622P.cjs → chunk-VYJXTHII.cjs} +422 -30
- package/dist/chunk-VYJXTHII.cjs.map +1 -0
- package/dist/{chunk-LRSB62Z6.cjs → chunk-X7F4CSGR.cjs} +15 -8
- package/dist/chunk-X7F4CSGR.cjs.map +1 -0
- package/dist/{chunk-XXBWX7DT.js → chunk-XBO6W7LZ.js} +328 -91
- package/dist/chunk-XBO6W7LZ.js.map +1 -0
- package/dist/{chunk-KEURQGCQ.js → chunk-XIDKHXNR.js} +74 -17
- package/dist/chunk-XIDKHXNR.js.map +1 -0
- package/dist/{chunk-WQSGX6XA.cjs → chunk-XJQX54QP.cjs} +5 -5
- package/dist/{chunk-WQSGX6XA.cjs.map → chunk-XJQX54QP.cjs.map} +1 -1
- package/dist/{chunk-W3DD3XP5.js → chunk-YDFX3JR2.js} +163 -129
- package/dist/chunk-YDFX3JR2.js.map +1 -0
- package/dist/{chunk-IWQDBVJK.js → chunk-ZTTMSCLU.js} +3 -3
- package/dist/{chunk-IWQDBVJK.js.map → chunk-ZTTMSCLU.js.map} +1 -1
- package/dist/evals/base.d.ts +1 -1
- package/dist/evals/base.d.ts.map +1 -1
- package/dist/evals/base.test-utils.d.ts +25 -25
- package/dist/evals/index.cjs +4 -4
- package/dist/evals/index.js +1 -1
- package/dist/evals/scoreTraces/index.cjs +3 -3
- package/dist/evals/scoreTraces/index.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/integration/index.cjs +2 -2
- package/dist/integration/index.js +1 -1
- package/dist/llm/index.cjs +18 -14
- package/dist/llm/index.d.ts +2 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +5 -5
- package/dist/llm/model/gateway-resolver.d.ts.map +1 -1
- package/dist/llm/model/gateways/azure.d.ts +36 -0
- package/dist/llm/model/gateways/azure.d.ts.map +1 -0
- package/dist/llm/model/gateways/base.d.ts +3 -6
- package/dist/llm/model/gateways/base.d.ts.map +1 -1
- package/dist/llm/model/gateways/index.d.ts +4 -1
- package/dist/llm/model/gateways/index.d.ts.map +1 -1
- package/dist/llm/model/gateways/models-dev.d.ts +2 -2
- package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
- package/dist/llm/model/gateways/netlify.d.ts +2 -2
- package/dist/llm/model/gateways/netlify.d.ts.map +1 -1
- package/dist/llm/model/model.d.ts.map +1 -1
- package/dist/llm/model/model.loop.d.ts +1 -1
- package/dist/llm/model/model.loop.d.ts.map +1 -1
- package/dist/llm/model/provider-registry.d.ts.map +1 -1
- package/dist/llm/model/provider-types.generated.d.ts +192 -11
- package/dist/llm/model/registry-generator.d.ts +12 -0
- package/dist/llm/model/registry-generator.d.ts.map +1 -1
- package/dist/llm/model/router.d.ts.map +1 -1
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/loop.d.ts.map +1 -1
- package/dist/loop/network/index.d.ts.map +1 -1
- package/dist/loop/test-utils/generateText.d.ts.map +1 -1
- package/dist/loop/test-utils/resultObject.d.ts.map +1 -1
- package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
- package/dist/loop/types.d.ts +8 -0
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts +1 -1
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.ts +9 -9
- package/dist/mastra/index.d.ts.map +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.d.ts +4 -4
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/types.d.ts +2 -2
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/memory/index.cjs +89 -34
- package/dist/memory/index.cjs.map +1 -1
- package/dist/memory/index.js +85 -30
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/mock.d.ts +9 -13
- package/dist/memory/mock.d.ts.map +1 -1
- package/dist/models-dev-F6MTIYTO.js +3 -0
- package/dist/{models-dev-6PRLJKVZ.js.map → models-dev-F6MTIYTO.js.map} +1 -1
- package/dist/models-dev-XIVR5EJV.cjs +12 -0
- package/dist/{models-dev-WHMI5G6Y.cjs.map → models-dev-XIVR5EJV.cjs.map} +1 -1
- package/dist/netlify-MXBOGAJR.cjs +12 -0
- package/dist/{netlify-46I3SNNV.cjs.map → netlify-MXBOGAJR.cjs.map} +1 -1
- package/dist/netlify-RX3JXCFQ.js +3 -0
- package/dist/{netlify-EBQ6YUC6.js.map → netlify-RX3JXCFQ.js.map} +1 -1
- package/dist/processors/index.cjs +11 -11
- package/dist/processors/index.d.ts +2 -2
- package/dist/processors/index.d.ts.map +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/processors/batch-parts.d.ts +1 -1
- package/dist/processors/processors/batch-parts.d.ts.map +1 -1
- package/dist/processors/processors/language-detector.d.ts +1 -1
- package/dist/processors/processors/language-detector.d.ts.map +1 -1
- package/dist/processors/processors/moderation.d.ts +1 -1
- package/dist/processors/processors/moderation.d.ts.map +1 -1
- package/dist/processors/processors/pii-detector.d.ts +1 -1
- package/dist/processors/processors/pii-detector.d.ts.map +1 -1
- package/dist/processors/processors/prompt-injection-detector.d.ts +1 -1
- package/dist/processors/processors/prompt-injection-detector.d.ts.map +1 -1
- package/dist/processors/processors/structured-output.d.ts +1 -1
- package/dist/processors/processors/structured-output.d.ts.map +1 -1
- package/dist/processors/processors/system-prompt-scrubber.d.ts +1 -1
- package/dist/processors/processors/system-prompt-scrubber.d.ts.map +1 -1
- package/dist/processors/processors/token-limiter.d.ts +1 -1
- package/dist/processors/processors/token-limiter.d.ts.map +1 -1
- package/dist/processors/processors/unicode-normalizer.d.ts +1 -1
- package/dist/processors/processors/unicode-normalizer.d.ts.map +1 -1
- package/dist/provider-registry-3LUCE7FT.js +3 -0
- package/dist/{provider-registry-HDG6UMUC.js.map → provider-registry-3LUCE7FT.js.map} +1 -1
- package/dist/provider-registry-NBRXBOQT.cjs +40 -0
- package/dist/{provider-registry-RP2W4B24.cjs.map → provider-registry-NBRXBOQT.cjs.map} +1 -1
- package/dist/provider-registry.json +400 -22
- package/dist/{registry-generator-JPCV47SC.cjs → registry-generator-DEPPRYYJ.cjs} +21 -6
- package/dist/registry-generator-DEPPRYYJ.cjs.map +1 -0
- package/dist/{registry-generator-XD4FPZTU.js → registry-generator-FLW6NV42.js} +21 -7
- package/dist/registry-generator-FLW6NV42.js.map +1 -0
- package/dist/relevance/index.cjs +2 -2
- package/dist/relevance/index.js +1 -1
- package/dist/server/composite-auth.d.ts +9 -0
- package/dist/server/composite-auth.d.ts.map +1 -0
- package/dist/server/index.cjs +31 -0
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +31 -1
- package/dist/server/index.js.map +1 -1
- package/dist/storage/index.cjs +29 -29
- package/dist/storage/index.js +1 -1
- package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/index.cjs +11 -11
- package/dist/stream/index.js +2 -2
- package/dist/stream/types.d.ts +7 -2
- package/dist/stream/types.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.cjs +2 -2
- package/dist/test-utils/llm-mock.js +1 -1
- package/dist/tools/index.cjs +6 -6
- package/dist/tools/index.js +2 -2
- package/dist/tools/is-vercel-tool.cjs +2 -2
- package/dist/tools/is-vercel-tool.js +1 -1
- package/dist/tools/stream.d.ts +1 -0
- package/dist/tools/stream.d.ts.map +1 -1
- package/dist/tools/tool-builder/builder.d.ts +2 -0
- package/dist/tools/tool-builder/builder.d.ts.map +1 -1
- package/dist/tools/tool.d.ts +6 -6
- package/dist/tools/tool.d.ts.map +1 -1
- package/dist/tools/types.d.ts +6 -2
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/validation.d.ts +13 -1
- package/dist/tools/validation.d.ts.map +1 -1
- package/dist/utils.cjs +22 -22
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/vector/filter/index.cjs +7 -189
- package/dist/vector/filter/index.cjs.map +1 -1
- package/dist/vector/filter/index.js +1 -190
- package/dist/vector/filter/index.js.map +1 -1
- package/dist/vector/index.cjs +5 -0
- package/dist/vector/index.cjs.map +1 -1
- package/dist/vector/index.d.ts +1 -0
- package/dist/vector/index.d.ts.map +1 -1
- package/dist/vector/index.js +1 -0
- package/dist/vector/index.js.map +1 -1
- package/dist/vector/types.d.ts +86 -3
- package/dist/vector/types.d.ts.map +1 -1
- package/dist/vector/vector.d.ts +39 -2
- package/dist/vector/vector.d.ts.map +1 -1
- 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/evented/step-executor.d.ts.map +1 -1
- package/dist/workflows/index.cjs +23 -19
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/types.d.ts +2 -2
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/utils.d.ts +7 -0
- package/dist/workflows/utils.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +4 -2
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +9 -8
- package/src/llm/model/provider-types.generated.d.ts +192 -11
- package/dist/chunk-2NVBZKZI.cjs.map +0 -1
- package/dist/chunk-3RW5EMSB.js.map +0 -1
- package/dist/chunk-3W5RQCCY.cjs.map +0 -1
- package/dist/chunk-4IKJAKCD.cjs.map +0 -1
- package/dist/chunk-4RXG622P.cjs.map +0 -1
- package/dist/chunk-5WXEYDFI.cjs.map +0 -1
- package/dist/chunk-D6EDHNGV.js.map +0 -1
- package/dist/chunk-FVNT7VTO.js.map +0 -1
- package/dist/chunk-HBJPYQRN.cjs.map +0 -1
- package/dist/chunk-HGNRQ3OG.js.map +0 -1
- package/dist/chunk-IHJDOC3A.js.map +0 -1
- package/dist/chunk-IWB65P37.cjs.map +0 -1
- package/dist/chunk-JXESKY4A.js.map +0 -1
- package/dist/chunk-KEURQGCQ.js.map +0 -1
- package/dist/chunk-LRSB62Z6.cjs.map +0 -1
- package/dist/chunk-MDKPL2R2.js.map +0 -1
- package/dist/chunk-O6NA3Z43.cjs.map +0 -1
- package/dist/chunk-RXDJL5QT.js.map +0 -1
- package/dist/chunk-S6OEQHEI.cjs.map +0 -1
- package/dist/chunk-U7VECK2G.js.map +0 -1
- package/dist/chunk-VSM3NLUX.cjs.map +0 -1
- package/dist/chunk-VZC4BWWH.cjs.map +0 -1
- package/dist/chunk-W3DD3XP5.js.map +0 -1
- package/dist/chunk-WTYNK7Q4.js.map +0 -1
- package/dist/chunk-XXBWX7DT.js.map +0 -1
- package/dist/chunk-ZCVTH3CH.cjs.map +0 -1
- package/dist/models-dev-6PRLJKVZ.js +0 -3
- package/dist/models-dev-WHMI5G6Y.cjs +0 -12
- package/dist/netlify-46I3SNNV.cjs +0 -12
- package/dist/netlify-EBQ6YUC6.js +0 -3
- package/dist/provider-registry-HDG6UMUC.js +0 -3
- package/dist/provider-registry-RP2W4B24.cjs +0 -40
- package/dist/registry-generator-JPCV47SC.cjs.map +0 -1
- package/dist/registry-generator-XD4FPZTU.js.map +0 -1
|
@@ -208,14 +208,137 @@ function convertImageFilePart(part, downloadedAssets) {
|
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
|
+
z.union([
|
|
212
|
+
z.string(),
|
|
213
|
+
z.instanceof(Uint8Array),
|
|
214
|
+
z.instanceof(ArrayBuffer),
|
|
215
|
+
z.custom(
|
|
216
|
+
// Buffer might not be available in some environments such as CloudFlare:
|
|
217
|
+
(value) => globalThis.Buffer?.isBuffer(value) ?? false,
|
|
218
|
+
{ message: "Must be a Buffer" }
|
|
219
|
+
)
|
|
220
|
+
]);
|
|
221
|
+
function convertDataContentToBase64String(content) {
|
|
222
|
+
if (typeof content === "string") {
|
|
223
|
+
return content;
|
|
224
|
+
}
|
|
225
|
+
if (content instanceof ArrayBuffer) {
|
|
226
|
+
return convertUint8ArrayToBase64$1(new Uint8Array(content));
|
|
227
|
+
}
|
|
228
|
+
return convertUint8ArrayToBase64$1(content);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// src/agent/message-list/prompt/image-utils.ts
|
|
232
|
+
function parseDataUri(dataUri) {
|
|
233
|
+
if (!dataUri.startsWith("data:")) {
|
|
234
|
+
return {
|
|
235
|
+
isDataUri: false,
|
|
236
|
+
base64Content: dataUri
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
const base64Index = dataUri.indexOf(",");
|
|
240
|
+
if (base64Index === -1) {
|
|
241
|
+
return {
|
|
242
|
+
isDataUri: true,
|
|
243
|
+
base64Content: dataUri
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
const header = dataUri.substring(5, base64Index);
|
|
247
|
+
const base64Content = dataUri.substring(base64Index + 1);
|
|
248
|
+
const semicolonIndex = header.indexOf(";");
|
|
249
|
+
const mimeType = semicolonIndex !== -1 ? header.substring(0, semicolonIndex) : header;
|
|
250
|
+
return {
|
|
251
|
+
isDataUri: true,
|
|
252
|
+
mimeType: mimeType || void 0,
|
|
253
|
+
base64Content
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function createDataUri(base64Content, mimeType = "application/octet-stream") {
|
|
257
|
+
if (base64Content.startsWith("data:")) {
|
|
258
|
+
return base64Content;
|
|
259
|
+
}
|
|
260
|
+
return `data:${mimeType};base64,${base64Content}`;
|
|
261
|
+
}
|
|
262
|
+
function imageContentToString(image, fallbackMimeType) {
|
|
263
|
+
if (typeof image === "string") {
|
|
264
|
+
return image;
|
|
265
|
+
}
|
|
266
|
+
if (image instanceof URL) {
|
|
267
|
+
return image.toString();
|
|
268
|
+
}
|
|
269
|
+
if (image instanceof Uint8Array || image instanceof ArrayBuffer || globalThis.Buffer && Buffer.isBuffer(image)) {
|
|
270
|
+
const base64 = convertDataContentToBase64String(image);
|
|
271
|
+
return base64;
|
|
272
|
+
}
|
|
273
|
+
return String(image);
|
|
274
|
+
}
|
|
275
|
+
function getImageCacheKey(image) {
|
|
276
|
+
if (image instanceof URL) {
|
|
277
|
+
return image.toString();
|
|
278
|
+
}
|
|
279
|
+
if (typeof image === "string") {
|
|
280
|
+
return image.length;
|
|
281
|
+
}
|
|
282
|
+
if (image instanceof Uint8Array) {
|
|
283
|
+
return image.byteLength;
|
|
284
|
+
}
|
|
285
|
+
if (image instanceof ArrayBuffer) {
|
|
286
|
+
return image.byteLength;
|
|
287
|
+
}
|
|
288
|
+
return image;
|
|
289
|
+
}
|
|
290
|
+
function isValidUrl(str) {
|
|
291
|
+
try {
|
|
292
|
+
new URL(str);
|
|
293
|
+
return true;
|
|
294
|
+
} catch {
|
|
295
|
+
if (str.startsWith("//")) {
|
|
296
|
+
try {
|
|
297
|
+
new URL(`https:${str}`);
|
|
298
|
+
return true;
|
|
299
|
+
} catch {
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
function categorizeFileData(data, fallbackMimeType) {
|
|
307
|
+
const parsed = parseDataUri(data);
|
|
308
|
+
const mimeType = parsed.isDataUri && parsed.mimeType ? parsed.mimeType : fallbackMimeType;
|
|
309
|
+
if (parsed.isDataUri) {
|
|
310
|
+
return {
|
|
311
|
+
type: "dataUri",
|
|
312
|
+
mimeType,
|
|
313
|
+
data
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
if (isValidUrl(data)) {
|
|
317
|
+
return {
|
|
318
|
+
type: "url",
|
|
319
|
+
mimeType,
|
|
320
|
+
data
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
return {
|
|
324
|
+
type: "raw",
|
|
325
|
+
mimeType,
|
|
326
|
+
data
|
|
327
|
+
};
|
|
328
|
+
}
|
|
211
329
|
|
|
212
330
|
// src/agent/message-list/prompt/attachments-to-parts.ts
|
|
213
331
|
function attachmentsToParts(attachments) {
|
|
214
332
|
const parts = [];
|
|
215
333
|
for (const attachment of attachments) {
|
|
334
|
+
const categorized = categorizeFileData(attachment.url, attachment.contentType);
|
|
335
|
+
let urlString = attachment.url;
|
|
336
|
+
if (categorized.type === "raw") {
|
|
337
|
+
urlString = createDataUri(attachment.url, attachment.contentType || "application/octet-stream");
|
|
338
|
+
}
|
|
216
339
|
let url;
|
|
217
340
|
try {
|
|
218
|
-
url = new URL(
|
|
341
|
+
url = new URL(urlString);
|
|
219
342
|
} catch {
|
|
220
343
|
throw new Error(`Invalid URL: ${attachment.url}`);
|
|
221
344
|
}
|
|
@@ -240,13 +363,13 @@ function attachmentsToParts(attachments) {
|
|
|
240
363
|
if (attachment.contentType?.startsWith("image/")) {
|
|
241
364
|
parts.push({
|
|
242
365
|
type: "image",
|
|
243
|
-
image:
|
|
366
|
+
image: urlString,
|
|
244
367
|
mimeType: attachment.contentType
|
|
245
368
|
});
|
|
246
369
|
} else if (attachment.contentType?.startsWith("text/")) {
|
|
247
370
|
parts.push({
|
|
248
371
|
type: "file",
|
|
249
|
-
data:
|
|
372
|
+
data: urlString,
|
|
250
373
|
mimeType: attachment.contentType
|
|
251
374
|
});
|
|
252
375
|
} else {
|
|
@@ -255,7 +378,7 @@ function attachmentsToParts(attachments) {
|
|
|
255
378
|
}
|
|
256
379
|
parts.push({
|
|
257
380
|
type: "file",
|
|
258
|
-
data:
|
|
381
|
+
data: urlString,
|
|
259
382
|
mimeType: attachment.contentType
|
|
260
383
|
});
|
|
261
384
|
}
|
|
@@ -566,25 +689,6 @@ function convertToV1Messages(messages) {
|
|
|
566
689
|
}
|
|
567
690
|
return v1Messages;
|
|
568
691
|
}
|
|
569
|
-
z.union([
|
|
570
|
-
z.string(),
|
|
571
|
-
z.instanceof(Uint8Array),
|
|
572
|
-
z.instanceof(ArrayBuffer),
|
|
573
|
-
z.custom(
|
|
574
|
-
// Buffer might not be available in some environments such as CloudFlare:
|
|
575
|
-
(value) => globalThis.Buffer?.isBuffer(value) ?? false,
|
|
576
|
-
{ message: "Must be a Buffer" }
|
|
577
|
-
)
|
|
578
|
-
]);
|
|
579
|
-
function convertDataContentToBase64String(content) {
|
|
580
|
-
if (typeof content === "string") {
|
|
581
|
-
return content;
|
|
582
|
-
}
|
|
583
|
-
if (content instanceof ArrayBuffer) {
|
|
584
|
-
return convertUint8ArrayToBase64$1(new Uint8Array(content));
|
|
585
|
-
}
|
|
586
|
-
return convertUint8ArrayToBase64$1(content);
|
|
587
|
-
}
|
|
588
692
|
|
|
589
693
|
// src/utils/fetchWithRetry.ts
|
|
590
694
|
async function fetchWithRetry(url, options = {}, maxRetries = 3) {
|
|
@@ -706,105 +810,6 @@ async function downloadAssetsFromMessages({
|
|
|
706
810
|
return Object.fromEntries(downloadFileList);
|
|
707
811
|
}
|
|
708
812
|
|
|
709
|
-
// src/agent/message-list/prompt/image-utils.ts
|
|
710
|
-
function parseDataUri(dataUri) {
|
|
711
|
-
if (!dataUri.startsWith("data:")) {
|
|
712
|
-
return {
|
|
713
|
-
isDataUri: false,
|
|
714
|
-
base64Content: dataUri
|
|
715
|
-
};
|
|
716
|
-
}
|
|
717
|
-
const base64Index = dataUri.indexOf(",");
|
|
718
|
-
if (base64Index === -1) {
|
|
719
|
-
return {
|
|
720
|
-
isDataUri: true,
|
|
721
|
-
base64Content: dataUri
|
|
722
|
-
};
|
|
723
|
-
}
|
|
724
|
-
const header = dataUri.substring(5, base64Index);
|
|
725
|
-
const base64Content = dataUri.substring(base64Index + 1);
|
|
726
|
-
const semicolonIndex = header.indexOf(";");
|
|
727
|
-
const mimeType = semicolonIndex !== -1 ? header.substring(0, semicolonIndex) : header;
|
|
728
|
-
return {
|
|
729
|
-
isDataUri: true,
|
|
730
|
-
mimeType: mimeType || void 0,
|
|
731
|
-
base64Content
|
|
732
|
-
};
|
|
733
|
-
}
|
|
734
|
-
function createDataUri(base64Content, mimeType = "application/octet-stream") {
|
|
735
|
-
if (base64Content.startsWith("data:")) {
|
|
736
|
-
return base64Content;
|
|
737
|
-
}
|
|
738
|
-
return `data:${mimeType};base64,${base64Content}`;
|
|
739
|
-
}
|
|
740
|
-
function imageContentToString(image, fallbackMimeType) {
|
|
741
|
-
if (typeof image === "string") {
|
|
742
|
-
return image;
|
|
743
|
-
}
|
|
744
|
-
if (image instanceof URL) {
|
|
745
|
-
return image.toString();
|
|
746
|
-
}
|
|
747
|
-
if (image instanceof Uint8Array || image instanceof ArrayBuffer || globalThis.Buffer && Buffer.isBuffer(image)) {
|
|
748
|
-
const base64 = convertDataContentToBase64String(image);
|
|
749
|
-
return base64;
|
|
750
|
-
}
|
|
751
|
-
return String(image);
|
|
752
|
-
}
|
|
753
|
-
function getImageCacheKey(image) {
|
|
754
|
-
if (image instanceof URL) {
|
|
755
|
-
return image.toString();
|
|
756
|
-
}
|
|
757
|
-
if (typeof image === "string") {
|
|
758
|
-
return image.length;
|
|
759
|
-
}
|
|
760
|
-
if (image instanceof Uint8Array) {
|
|
761
|
-
return image.byteLength;
|
|
762
|
-
}
|
|
763
|
-
if (image instanceof ArrayBuffer) {
|
|
764
|
-
return image.byteLength;
|
|
765
|
-
}
|
|
766
|
-
return image;
|
|
767
|
-
}
|
|
768
|
-
function isValidUrl(str) {
|
|
769
|
-
try {
|
|
770
|
-
new URL(str);
|
|
771
|
-
return true;
|
|
772
|
-
} catch {
|
|
773
|
-
if (str.startsWith("//")) {
|
|
774
|
-
try {
|
|
775
|
-
new URL(`https:${str}`);
|
|
776
|
-
return true;
|
|
777
|
-
} catch {
|
|
778
|
-
return false;
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
return false;
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
function categorizeFileData(data, fallbackMimeType) {
|
|
785
|
-
const parsed = parseDataUri(data);
|
|
786
|
-
const mimeType = parsed.isDataUri && parsed.mimeType ? parsed.mimeType : fallbackMimeType;
|
|
787
|
-
if (parsed.isDataUri) {
|
|
788
|
-
return {
|
|
789
|
-
type: "dataUri",
|
|
790
|
-
mimeType,
|
|
791
|
-
data
|
|
792
|
-
};
|
|
793
|
-
}
|
|
794
|
-
if (isValidUrl(data)) {
|
|
795
|
-
return {
|
|
796
|
-
type: "url",
|
|
797
|
-
mimeType,
|
|
798
|
-
data
|
|
799
|
-
};
|
|
800
|
-
}
|
|
801
|
-
return {
|
|
802
|
-
type: "raw",
|
|
803
|
-
mimeType,
|
|
804
|
-
data
|
|
805
|
-
};
|
|
806
|
-
}
|
|
807
|
-
|
|
808
813
|
// src/agent/message-list/utils/ai-v5/gemini-compatibility.ts
|
|
809
814
|
function ensureGeminiCompatibleMessages(messages) {
|
|
810
815
|
const result = [...messages];
|
|
@@ -1404,9 +1409,20 @@ var MessageList = class _MessageList {
|
|
|
1404
1409
|
if (m.content.parts.length) {
|
|
1405
1410
|
for (const part of m.content.parts) {
|
|
1406
1411
|
if (part.type === `file`) {
|
|
1412
|
+
let normalizedUrl;
|
|
1413
|
+
if (typeof part.data === "string") {
|
|
1414
|
+
const categorized = categorizeFileData(part.data, part.mimeType);
|
|
1415
|
+
if (categorized.type === "raw") {
|
|
1416
|
+
normalizedUrl = createDataUri(part.data, part.mimeType || "application/octet-stream");
|
|
1417
|
+
} else {
|
|
1418
|
+
normalizedUrl = part.data;
|
|
1419
|
+
}
|
|
1420
|
+
} else {
|
|
1421
|
+
normalizedUrl = part.data;
|
|
1422
|
+
}
|
|
1407
1423
|
experimentalAttachments.push({
|
|
1408
1424
|
contentType: part.mimeType,
|
|
1409
|
-
url:
|
|
1425
|
+
url: normalizedUrl
|
|
1410
1426
|
});
|
|
1411
1427
|
} else if (part.type === "tool-invocation" && (part.toolInvocation.state === "call" || part.toolInvocation.state === "partial-call")) {
|
|
1412
1428
|
continue;
|
|
@@ -2088,6 +2104,9 @@ var MessageList = class _MessageList {
|
|
|
2088
2104
|
if (coreMessage.providerOptions) {
|
|
2089
2105
|
content.providerMetadata = coreMessage.providerOptions;
|
|
2090
2106
|
}
|
|
2107
|
+
if ("metadata" in coreMessage && coreMessage.metadata !== null && coreMessage.metadata !== void 0) {
|
|
2108
|
+
content.metadata = coreMessage.metadata;
|
|
2109
|
+
}
|
|
2091
2110
|
return {
|
|
2092
2111
|
id,
|
|
2093
2112
|
role: _MessageList.getRole(coreMessage),
|
|
@@ -2290,9 +2309,23 @@ var MessageList = class _MessageList {
|
|
|
2290
2309
|
if (role === `tool` || role === `assistant`) {
|
|
2291
2310
|
throw new Error(incompatibleMessage);
|
|
2292
2311
|
}
|
|
2312
|
+
let processedImage;
|
|
2313
|
+
if (part.image instanceof URL || part.image instanceof Uint8Array) {
|
|
2314
|
+
processedImage = part.image;
|
|
2315
|
+
} else if (Buffer.isBuffer(part.image) || part.image instanceof ArrayBuffer) {
|
|
2316
|
+
processedImage = new Uint8Array(part.image);
|
|
2317
|
+
} else {
|
|
2318
|
+
const categorized = categorizeFileData(part.image, part.mimeType);
|
|
2319
|
+
if (categorized.type === "raw") {
|
|
2320
|
+
const dataUri = createDataUri(part.image, part.mimeType || "image/png");
|
|
2321
|
+
processedImage = new URL(dataUri);
|
|
2322
|
+
} else {
|
|
2323
|
+
processedImage = new URL(part.image);
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2293
2326
|
roleContent[role].push({
|
|
2294
2327
|
...part,
|
|
2295
|
-
image:
|
|
2328
|
+
image: processedImage
|
|
2296
2329
|
});
|
|
2297
2330
|
break;
|
|
2298
2331
|
}
|
|
@@ -2942,7 +2975,7 @@ var MessageList = class _MessageList {
|
|
|
2942
2975
|
}
|
|
2943
2976
|
}
|
|
2944
2977
|
const contentString = mastraDBParts.filter((p) => p.type === "text").map((p) => p.text).join("\n");
|
|
2945
|
-
const metadata = {};
|
|
2978
|
+
const metadata = "metadata" in modelMsg && modelMsg.metadata !== null && modelMsg.metadata !== void 0 ? modelMsg.metadata : {};
|
|
2946
2979
|
const id = `id` in modelMsg && typeof modelMsg.id === `string` ? modelMsg.id : `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
2947
2980
|
const message = {
|
|
2948
2981
|
id,
|
|
@@ -2955,7 +2988,7 @@ var MessageList = class _MessageList {
|
|
|
2955
2988
|
reasoning: reasoningParts.length > 0 ? reasoningParts.join("\n") : void 0,
|
|
2956
2989
|
experimental_attachments: experimental_attachments.length > 0 ? experimental_attachments : void 0,
|
|
2957
2990
|
content: contentString || void 0,
|
|
2958
|
-
metadata
|
|
2991
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : void 0
|
|
2959
2992
|
}
|
|
2960
2993
|
};
|
|
2961
2994
|
if (modelMsg.providerOptions) {
|
|
@@ -2988,7 +3021,8 @@ var MessageList = class _MessageList {
|
|
|
2988
3021
|
if (message.role !== `assistant`) continue;
|
|
2989
3022
|
for (const [index, part] of message.parts.entries()) {
|
|
2990
3023
|
if (!AIV5.isToolUIPart(part)) continue;
|
|
2991
|
-
|
|
3024
|
+
const nextPart = message.parts.at(index + 1);
|
|
3025
|
+
if (nextPart && nextPart.type !== `step-start` && !AIV5.isToolUIPart(nextPart)) {
|
|
2992
3026
|
message.parts.splice(index + 1, 0, { type: "step-start" });
|
|
2993
3027
|
}
|
|
2994
3028
|
}
|
|
@@ -3114,5 +3148,5 @@ var MessageList = class _MessageList {
|
|
|
3114
3148
|
};
|
|
3115
3149
|
|
|
3116
3150
|
export { DefaultGeneratedFile, DefaultGeneratedFileWithType, MessageList, convertMessages };
|
|
3117
|
-
//# sourceMappingURL=chunk-
|
|
3118
|
-
//# sourceMappingURL=chunk-
|
|
3151
|
+
//# sourceMappingURL=chunk-YDFX3JR2.js.map
|
|
3152
|
+
//# sourceMappingURL=chunk-YDFX3JR2.js.map
|