@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
|
@@ -230,14 +230,137 @@ function convertImageFilePart(part, downloadedAssets) {
|
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
|
+
zod.z.union([
|
|
234
|
+
zod.z.string(),
|
|
235
|
+
zod.z.instanceof(Uint8Array),
|
|
236
|
+
zod.z.instanceof(ArrayBuffer),
|
|
237
|
+
zod.z.custom(
|
|
238
|
+
// Buffer might not be available in some environments such as CloudFlare:
|
|
239
|
+
(value) => globalThis.Buffer?.isBuffer(value) ?? false,
|
|
240
|
+
{ message: "Must be a Buffer" }
|
|
241
|
+
)
|
|
242
|
+
]);
|
|
243
|
+
function convertDataContentToBase64String(content) {
|
|
244
|
+
if (typeof content === "string") {
|
|
245
|
+
return content;
|
|
246
|
+
}
|
|
247
|
+
if (content instanceof ArrayBuffer) {
|
|
248
|
+
return chunkSVLMF4UZ_cjs.convertUint8ArrayToBase64(new Uint8Array(content));
|
|
249
|
+
}
|
|
250
|
+
return chunkSVLMF4UZ_cjs.convertUint8ArrayToBase64(content);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// src/agent/message-list/prompt/image-utils.ts
|
|
254
|
+
function parseDataUri(dataUri) {
|
|
255
|
+
if (!dataUri.startsWith("data:")) {
|
|
256
|
+
return {
|
|
257
|
+
isDataUri: false,
|
|
258
|
+
base64Content: dataUri
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
const base64Index = dataUri.indexOf(",");
|
|
262
|
+
if (base64Index === -1) {
|
|
263
|
+
return {
|
|
264
|
+
isDataUri: true,
|
|
265
|
+
base64Content: dataUri
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
const header = dataUri.substring(5, base64Index);
|
|
269
|
+
const base64Content = dataUri.substring(base64Index + 1);
|
|
270
|
+
const semicolonIndex = header.indexOf(";");
|
|
271
|
+
const mimeType = semicolonIndex !== -1 ? header.substring(0, semicolonIndex) : header;
|
|
272
|
+
return {
|
|
273
|
+
isDataUri: true,
|
|
274
|
+
mimeType: mimeType || void 0,
|
|
275
|
+
base64Content
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function createDataUri(base64Content, mimeType = "application/octet-stream") {
|
|
279
|
+
if (base64Content.startsWith("data:")) {
|
|
280
|
+
return base64Content;
|
|
281
|
+
}
|
|
282
|
+
return `data:${mimeType};base64,${base64Content}`;
|
|
283
|
+
}
|
|
284
|
+
function imageContentToString(image, fallbackMimeType) {
|
|
285
|
+
if (typeof image === "string") {
|
|
286
|
+
return image;
|
|
287
|
+
}
|
|
288
|
+
if (image instanceof URL) {
|
|
289
|
+
return image.toString();
|
|
290
|
+
}
|
|
291
|
+
if (image instanceof Uint8Array || image instanceof ArrayBuffer || globalThis.Buffer && Buffer.isBuffer(image)) {
|
|
292
|
+
const base64 = convertDataContentToBase64String(image);
|
|
293
|
+
return base64;
|
|
294
|
+
}
|
|
295
|
+
return String(image);
|
|
296
|
+
}
|
|
297
|
+
function getImageCacheKey(image) {
|
|
298
|
+
if (image instanceof URL) {
|
|
299
|
+
return image.toString();
|
|
300
|
+
}
|
|
301
|
+
if (typeof image === "string") {
|
|
302
|
+
return image.length;
|
|
303
|
+
}
|
|
304
|
+
if (image instanceof Uint8Array) {
|
|
305
|
+
return image.byteLength;
|
|
306
|
+
}
|
|
307
|
+
if (image instanceof ArrayBuffer) {
|
|
308
|
+
return image.byteLength;
|
|
309
|
+
}
|
|
310
|
+
return image;
|
|
311
|
+
}
|
|
312
|
+
function isValidUrl(str) {
|
|
313
|
+
try {
|
|
314
|
+
new URL(str);
|
|
315
|
+
return true;
|
|
316
|
+
} catch {
|
|
317
|
+
if (str.startsWith("//")) {
|
|
318
|
+
try {
|
|
319
|
+
new URL(`https:${str}`);
|
|
320
|
+
return true;
|
|
321
|
+
} catch {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function categorizeFileData(data, fallbackMimeType) {
|
|
329
|
+
const parsed = parseDataUri(data);
|
|
330
|
+
const mimeType = parsed.isDataUri && parsed.mimeType ? parsed.mimeType : fallbackMimeType;
|
|
331
|
+
if (parsed.isDataUri) {
|
|
332
|
+
return {
|
|
333
|
+
type: "dataUri",
|
|
334
|
+
mimeType,
|
|
335
|
+
data
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
if (isValidUrl(data)) {
|
|
339
|
+
return {
|
|
340
|
+
type: "url",
|
|
341
|
+
mimeType,
|
|
342
|
+
data
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
type: "raw",
|
|
347
|
+
mimeType,
|
|
348
|
+
data
|
|
349
|
+
};
|
|
350
|
+
}
|
|
233
351
|
|
|
234
352
|
// src/agent/message-list/prompt/attachments-to-parts.ts
|
|
235
353
|
function attachmentsToParts(attachments) {
|
|
236
354
|
const parts = [];
|
|
237
355
|
for (const attachment of attachments) {
|
|
356
|
+
const categorized = categorizeFileData(attachment.url, attachment.contentType);
|
|
357
|
+
let urlString = attachment.url;
|
|
358
|
+
if (categorized.type === "raw") {
|
|
359
|
+
urlString = createDataUri(attachment.url, attachment.contentType || "application/octet-stream");
|
|
360
|
+
}
|
|
238
361
|
let url;
|
|
239
362
|
try {
|
|
240
|
-
url = new URL(
|
|
363
|
+
url = new URL(urlString);
|
|
241
364
|
} catch {
|
|
242
365
|
throw new Error(`Invalid URL: ${attachment.url}`);
|
|
243
366
|
}
|
|
@@ -262,13 +385,13 @@ function attachmentsToParts(attachments) {
|
|
|
262
385
|
if (attachment.contentType?.startsWith("image/")) {
|
|
263
386
|
parts.push({
|
|
264
387
|
type: "image",
|
|
265
|
-
image:
|
|
388
|
+
image: urlString,
|
|
266
389
|
mimeType: attachment.contentType
|
|
267
390
|
});
|
|
268
391
|
} else if (attachment.contentType?.startsWith("text/")) {
|
|
269
392
|
parts.push({
|
|
270
393
|
type: "file",
|
|
271
|
-
data:
|
|
394
|
+
data: urlString,
|
|
272
395
|
mimeType: attachment.contentType
|
|
273
396
|
});
|
|
274
397
|
} else {
|
|
@@ -277,7 +400,7 @@ function attachmentsToParts(attachments) {
|
|
|
277
400
|
}
|
|
278
401
|
parts.push({
|
|
279
402
|
type: "file",
|
|
280
|
-
data:
|
|
403
|
+
data: urlString,
|
|
281
404
|
mimeType: attachment.contentType
|
|
282
405
|
});
|
|
283
406
|
}
|
|
@@ -588,25 +711,6 @@ function convertToV1Messages(messages) {
|
|
|
588
711
|
}
|
|
589
712
|
return v1Messages;
|
|
590
713
|
}
|
|
591
|
-
zod.z.union([
|
|
592
|
-
zod.z.string(),
|
|
593
|
-
zod.z.instanceof(Uint8Array),
|
|
594
|
-
zod.z.instanceof(ArrayBuffer),
|
|
595
|
-
zod.z.custom(
|
|
596
|
-
// Buffer might not be available in some environments such as CloudFlare:
|
|
597
|
-
(value) => globalThis.Buffer?.isBuffer(value) ?? false,
|
|
598
|
-
{ message: "Must be a Buffer" }
|
|
599
|
-
)
|
|
600
|
-
]);
|
|
601
|
-
function convertDataContentToBase64String(content) {
|
|
602
|
-
if (typeof content === "string") {
|
|
603
|
-
return content;
|
|
604
|
-
}
|
|
605
|
-
if (content instanceof ArrayBuffer) {
|
|
606
|
-
return chunkSVLMF4UZ_cjs.convertUint8ArrayToBase64(new Uint8Array(content));
|
|
607
|
-
}
|
|
608
|
-
return chunkSVLMF4UZ_cjs.convertUint8ArrayToBase64(content);
|
|
609
|
-
}
|
|
610
714
|
|
|
611
715
|
// src/utils/fetchWithRetry.ts
|
|
612
716
|
async function fetchWithRetry(url, options = {}, maxRetries = 3) {
|
|
@@ -728,105 +832,6 @@ async function downloadAssetsFromMessages({
|
|
|
728
832
|
return Object.fromEntries(downloadFileList);
|
|
729
833
|
}
|
|
730
834
|
|
|
731
|
-
// src/agent/message-list/prompt/image-utils.ts
|
|
732
|
-
function parseDataUri(dataUri) {
|
|
733
|
-
if (!dataUri.startsWith("data:")) {
|
|
734
|
-
return {
|
|
735
|
-
isDataUri: false,
|
|
736
|
-
base64Content: dataUri
|
|
737
|
-
};
|
|
738
|
-
}
|
|
739
|
-
const base64Index = dataUri.indexOf(",");
|
|
740
|
-
if (base64Index === -1) {
|
|
741
|
-
return {
|
|
742
|
-
isDataUri: true,
|
|
743
|
-
base64Content: dataUri
|
|
744
|
-
};
|
|
745
|
-
}
|
|
746
|
-
const header = dataUri.substring(5, base64Index);
|
|
747
|
-
const base64Content = dataUri.substring(base64Index + 1);
|
|
748
|
-
const semicolonIndex = header.indexOf(";");
|
|
749
|
-
const mimeType = semicolonIndex !== -1 ? header.substring(0, semicolonIndex) : header;
|
|
750
|
-
return {
|
|
751
|
-
isDataUri: true,
|
|
752
|
-
mimeType: mimeType || void 0,
|
|
753
|
-
base64Content
|
|
754
|
-
};
|
|
755
|
-
}
|
|
756
|
-
function createDataUri(base64Content, mimeType = "application/octet-stream") {
|
|
757
|
-
if (base64Content.startsWith("data:")) {
|
|
758
|
-
return base64Content;
|
|
759
|
-
}
|
|
760
|
-
return `data:${mimeType};base64,${base64Content}`;
|
|
761
|
-
}
|
|
762
|
-
function imageContentToString(image, fallbackMimeType) {
|
|
763
|
-
if (typeof image === "string") {
|
|
764
|
-
return image;
|
|
765
|
-
}
|
|
766
|
-
if (image instanceof URL) {
|
|
767
|
-
return image.toString();
|
|
768
|
-
}
|
|
769
|
-
if (image instanceof Uint8Array || image instanceof ArrayBuffer || globalThis.Buffer && Buffer.isBuffer(image)) {
|
|
770
|
-
const base64 = convertDataContentToBase64String(image);
|
|
771
|
-
return base64;
|
|
772
|
-
}
|
|
773
|
-
return String(image);
|
|
774
|
-
}
|
|
775
|
-
function getImageCacheKey(image) {
|
|
776
|
-
if (image instanceof URL) {
|
|
777
|
-
return image.toString();
|
|
778
|
-
}
|
|
779
|
-
if (typeof image === "string") {
|
|
780
|
-
return image.length;
|
|
781
|
-
}
|
|
782
|
-
if (image instanceof Uint8Array) {
|
|
783
|
-
return image.byteLength;
|
|
784
|
-
}
|
|
785
|
-
if (image instanceof ArrayBuffer) {
|
|
786
|
-
return image.byteLength;
|
|
787
|
-
}
|
|
788
|
-
return image;
|
|
789
|
-
}
|
|
790
|
-
function isValidUrl(str) {
|
|
791
|
-
try {
|
|
792
|
-
new URL(str);
|
|
793
|
-
return true;
|
|
794
|
-
} catch {
|
|
795
|
-
if (str.startsWith("//")) {
|
|
796
|
-
try {
|
|
797
|
-
new URL(`https:${str}`);
|
|
798
|
-
return true;
|
|
799
|
-
} catch {
|
|
800
|
-
return false;
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
return false;
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
function categorizeFileData(data, fallbackMimeType) {
|
|
807
|
-
const parsed = parseDataUri(data);
|
|
808
|
-
const mimeType = parsed.isDataUri && parsed.mimeType ? parsed.mimeType : fallbackMimeType;
|
|
809
|
-
if (parsed.isDataUri) {
|
|
810
|
-
return {
|
|
811
|
-
type: "dataUri",
|
|
812
|
-
mimeType,
|
|
813
|
-
data
|
|
814
|
-
};
|
|
815
|
-
}
|
|
816
|
-
if (isValidUrl(data)) {
|
|
817
|
-
return {
|
|
818
|
-
type: "url",
|
|
819
|
-
mimeType,
|
|
820
|
-
data
|
|
821
|
-
};
|
|
822
|
-
}
|
|
823
|
-
return {
|
|
824
|
-
type: "raw",
|
|
825
|
-
mimeType,
|
|
826
|
-
data
|
|
827
|
-
};
|
|
828
|
-
}
|
|
829
|
-
|
|
830
835
|
// src/agent/message-list/utils/ai-v5/gemini-compatibility.ts
|
|
831
836
|
function ensureGeminiCompatibleMessages(messages) {
|
|
832
837
|
const result = [...messages];
|
|
@@ -1426,9 +1431,20 @@ var MessageList = class _MessageList {
|
|
|
1426
1431
|
if (m.content.parts.length) {
|
|
1427
1432
|
for (const part of m.content.parts) {
|
|
1428
1433
|
if (part.type === `file`) {
|
|
1434
|
+
let normalizedUrl;
|
|
1435
|
+
if (typeof part.data === "string") {
|
|
1436
|
+
const categorized = categorizeFileData(part.data, part.mimeType);
|
|
1437
|
+
if (categorized.type === "raw") {
|
|
1438
|
+
normalizedUrl = createDataUri(part.data, part.mimeType || "application/octet-stream");
|
|
1439
|
+
} else {
|
|
1440
|
+
normalizedUrl = part.data;
|
|
1441
|
+
}
|
|
1442
|
+
} else {
|
|
1443
|
+
normalizedUrl = part.data;
|
|
1444
|
+
}
|
|
1429
1445
|
experimentalAttachments.push({
|
|
1430
1446
|
contentType: part.mimeType,
|
|
1431
|
-
url:
|
|
1447
|
+
url: normalizedUrl
|
|
1432
1448
|
});
|
|
1433
1449
|
} else if (part.type === "tool-invocation" && (part.toolInvocation.state === "call" || part.toolInvocation.state === "partial-call")) {
|
|
1434
1450
|
continue;
|
|
@@ -2110,6 +2126,9 @@ var MessageList = class _MessageList {
|
|
|
2110
2126
|
if (coreMessage.providerOptions) {
|
|
2111
2127
|
content.providerMetadata = coreMessage.providerOptions;
|
|
2112
2128
|
}
|
|
2129
|
+
if ("metadata" in coreMessage && coreMessage.metadata !== null && coreMessage.metadata !== void 0) {
|
|
2130
|
+
content.metadata = coreMessage.metadata;
|
|
2131
|
+
}
|
|
2113
2132
|
return {
|
|
2114
2133
|
id,
|
|
2115
2134
|
role: _MessageList.getRole(coreMessage),
|
|
@@ -2312,9 +2331,23 @@ var MessageList = class _MessageList {
|
|
|
2312
2331
|
if (role === `tool` || role === `assistant`) {
|
|
2313
2332
|
throw new Error(incompatibleMessage);
|
|
2314
2333
|
}
|
|
2334
|
+
let processedImage;
|
|
2335
|
+
if (part.image instanceof URL || part.image instanceof Uint8Array) {
|
|
2336
|
+
processedImage = part.image;
|
|
2337
|
+
} else if (Buffer.isBuffer(part.image) || part.image instanceof ArrayBuffer) {
|
|
2338
|
+
processedImage = new Uint8Array(part.image);
|
|
2339
|
+
} else {
|
|
2340
|
+
const categorized = categorizeFileData(part.image, part.mimeType);
|
|
2341
|
+
if (categorized.type === "raw") {
|
|
2342
|
+
const dataUri = createDataUri(part.image, part.mimeType || "image/png");
|
|
2343
|
+
processedImage = new URL(dataUri);
|
|
2344
|
+
} else {
|
|
2345
|
+
processedImage = new URL(part.image);
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2315
2348
|
roleContent[role].push({
|
|
2316
2349
|
...part,
|
|
2317
|
-
image:
|
|
2350
|
+
image: processedImage
|
|
2318
2351
|
});
|
|
2319
2352
|
break;
|
|
2320
2353
|
}
|
|
@@ -2964,7 +2997,7 @@ var MessageList = class _MessageList {
|
|
|
2964
2997
|
}
|
|
2965
2998
|
}
|
|
2966
2999
|
const contentString = mastraDBParts.filter((p) => p.type === "text").map((p) => p.text).join("\n");
|
|
2967
|
-
const metadata = {};
|
|
3000
|
+
const metadata = "metadata" in modelMsg && modelMsg.metadata !== null && modelMsg.metadata !== void 0 ? modelMsg.metadata : {};
|
|
2968
3001
|
const id = `id` in modelMsg && typeof modelMsg.id === `string` ? modelMsg.id : `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
2969
3002
|
const message = {
|
|
2970
3003
|
id,
|
|
@@ -2977,7 +3010,7 @@ var MessageList = class _MessageList {
|
|
|
2977
3010
|
reasoning: reasoningParts.length > 0 ? reasoningParts.join("\n") : void 0,
|
|
2978
3011
|
experimental_attachments: experimental_attachments.length > 0 ? experimental_attachments : void 0,
|
|
2979
3012
|
content: contentString || void 0,
|
|
2980
|
-
metadata
|
|
3013
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : void 0
|
|
2981
3014
|
}
|
|
2982
3015
|
};
|
|
2983
3016
|
if (modelMsg.providerOptions) {
|
|
@@ -3010,7 +3043,8 @@ var MessageList = class _MessageList {
|
|
|
3010
3043
|
if (message.role !== `assistant`) continue;
|
|
3011
3044
|
for (const [index, part] of message.parts.entries()) {
|
|
3012
3045
|
if (!AIV5__namespace.isToolUIPart(part)) continue;
|
|
3013
|
-
|
|
3046
|
+
const nextPart = message.parts.at(index + 1);
|
|
3047
|
+
if (nextPart && nextPart.type !== `step-start` && !AIV5__namespace.isToolUIPart(nextPart)) {
|
|
3014
3048
|
message.parts.splice(index + 1, 0, { type: "step-start" });
|
|
3015
3049
|
}
|
|
3016
3050
|
}
|
|
@@ -3139,5 +3173,5 @@ exports.DefaultGeneratedFile = DefaultGeneratedFile;
|
|
|
3139
3173
|
exports.DefaultGeneratedFileWithType = DefaultGeneratedFileWithType;
|
|
3140
3174
|
exports.MessageList = MessageList;
|
|
3141
3175
|
exports.convertMessages = convertMessages;
|
|
3142
|
-
//# sourceMappingURL=chunk-
|
|
3143
|
-
//# sourceMappingURL=chunk-
|
|
3176
|
+
//# sourceMappingURL=chunk-DQIZ5FFX.cjs.map
|
|
3177
|
+
//# sourceMappingURL=chunk-DQIZ5FFX.cjs.map
|