@mastra/core 1.0.0-beta.3 → 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 +369 -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 +5 -0
- 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-4DWZ4Z6H.js → chunk-3B2OPLGG.js} +13 -7
- package/dist/chunk-3B2OPLGG.js.map +1 -0
- package/dist/{chunk-GRGPQ32U.js → chunk-3ZQ7LX73.js} +13 -13
- package/dist/chunk-3ZQ7LX73.js.map +1 -0
- package/dist/{chunk-VZGBVYXA.cjs → chunk-556MJ7CL.cjs} +33 -27
- 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-VU6DVS7J.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-KOSW5PP5.js → chunk-7ZADRRDW.js} +466 -125
- 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-MCUX2D5Q.js → chunk-D7CJ4HIQ.js} +263 -24
- package/dist/chunk-D7CJ4HIQ.js.map +1 -0
- package/dist/{chunk-G36A2JRR.cjs → chunk-DQIZ5FFX.cjs} +457 -326
- package/dist/chunk-DQIZ5FFX.cjs.map +1 -0
- package/dist/{chunk-ZPMFINU2.cjs → chunk-HNHZGFZY.cjs} +466 -131
- package/dist/chunk-HNHZGFZY.cjs.map +1 -0
- package/dist/{chunk-3VOUB4ZU.cjs → chunk-IITXXVYI.cjs} +17 -17
- package/dist/chunk-IITXXVYI.cjs.map +1 -0
- package/dist/{chunk-QUKUN6NR.cjs → chunk-ISMGVGUM.cjs} +105 -5
- package/dist/chunk-ISMGVGUM.cjs.map +1 -0
- package/dist/{chunk-OQF4H5Y2.js → chunk-KJIQGPQR.js} +4 -4
- package/dist/{chunk-OQF4H5Y2.js.map → chunk-KJIQGPQR.js.map} +1 -1
- package/dist/{chunk-OWX2PUFH.cjs → chunk-KP42JLXE.cjs} +506 -236
- package/dist/chunk-KP42JLXE.cjs.map +1 -0
- package/dist/{chunk-4RSHBKDJ.cjs → chunk-KWWD3U7G.cjs} +5 -5
- package/dist/chunk-KWWD3U7G.cjs.map +1 -0
- package/dist/{chunk-N4SJ4YX7.cjs → chunk-NHP6ZIDG.cjs} +271 -31
- package/dist/chunk-NHP6ZIDG.cjs.map +1 -0
- package/dist/{chunk-UIZSWUKP.js → chunk-NZAXAFI3.js} +104 -6
- package/dist/chunk-NZAXAFI3.js.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-YQ7NLZZ3.cjs → chunk-QGWNF2QJ.cjs} +74 -618
- 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-G3OOCXAI.js → chunk-T2CJRA6E.js} +4 -4
- package/dist/chunk-T2CJRA6E.js.map +1 -0
- package/dist/{chunk-T3WZCEC4.js → chunk-T2UNO766.js} +47 -591
- package/dist/chunk-T2UNO766.js.map +1 -0
- package/dist/{chunk-EZVRSZMK.cjs → chunk-U3VE2EVB.cjs} +11 -11
- package/dist/{chunk-EZVRSZMK.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-XRIVPHXV.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-CKGIPST2.js → chunk-XBO6W7LZ.js} +462 -193
- 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-JTXVR2RA.cjs → chunk-XJQX54QP.cjs} +5 -5
- package/dist/{chunk-JTXVR2RA.cjs.map → chunk-XJQX54QP.cjs.map} +1 -1
- package/dist/{chunk-BAMR7HKO.js → chunk-YDFX3JR2.js} +457 -326
- package/dist/chunk-YDFX3JR2.js.map +1 -0
- package/dist/{chunk-5CWWU22H.js → chunk-ZTTMSCLU.js} +3 -3
- package/dist/{chunk-5CWWU22H.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/aisdk/v5/model.d.ts.map +1 -1
- 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/test-utils/toUIMessageStream.d.ts.map +1 -1
- package/dist/loop/test-utils/utils.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/llm-execution-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.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-GCVENVWA.js.map → models-dev-F6MTIYTO.js.map} +1 -1
- package/dist/models-dev-XIVR5EJV.cjs +12 -0
- package/dist/{models-dev-TIBJR6IG.cjs.map → models-dev-XIVR5EJV.cjs.map} +1 -1
- package/dist/netlify-MXBOGAJR.cjs +12 -0
- package/dist/{netlify-NTSNNT6F.cjs.map → netlify-MXBOGAJR.cjs.map} +1 -1
- package/dist/netlify-RX3JXCFQ.js +3 -0
- package/dist/{netlify-O5NJW7CF.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-74GMFZKT.js.map → provider-registry-3LUCE7FT.js.map} +1 -1
- package/dist/provider-registry-NBRXBOQT.cjs +40 -0
- package/dist/{provider-registry-BZP3DIIV.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/auth.d.ts +11 -0
- package/dist/server/auth.d.ts.map +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 +41 -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 +41 -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/compat/prepare-tools.d.ts.map +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 +68 -31
- package/dist/test-utils/llm-mock.cjs.map +1 -1
- package/dist/test-utils/llm-mock.d.ts +4 -2
- package/dist/test-utils/llm-mock.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.js +67 -30
- package/dist/test-utils/llm-mock.js.map +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/voice/aisdk/index.d.ts +3 -0
- package/dist/voice/aisdk/index.d.ts.map +1 -0
- package/dist/voice/aisdk/speech.d.ts +23 -0
- package/dist/voice/aisdk/speech.d.ts.map +1 -0
- package/dist/voice/aisdk/transcription.d.ts +22 -0
- package/dist/voice/aisdk/transcription.d.ts.map +1 -0
- package/dist/voice/composite-voice.d.ts +4 -3
- package/dist/voice/composite-voice.d.ts.map +1 -1
- package/dist/voice/index.cjs +12 -4
- package/dist/voice/index.d.ts +1 -0
- package/dist/voice/index.d.ts.map +1 -1
- package/dist/voice/index.js +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 +17 -16
- package/src/llm/model/provider-types.generated.d.ts +192 -11
- package/dist/chunk-3VOUB4ZU.cjs.map +0 -1
- package/dist/chunk-4DWZ4Z6H.js.map +0 -1
- package/dist/chunk-4IKJAKCD.cjs.map +0 -1
- package/dist/chunk-4RSHBKDJ.cjs.map +0 -1
- package/dist/chunk-BAMR7HKO.js.map +0 -1
- package/dist/chunk-CKGIPST2.js.map +0 -1
- package/dist/chunk-D6EDHNGV.js.map +0 -1
- package/dist/chunk-G36A2JRR.cjs.map +0 -1
- package/dist/chunk-G3OOCXAI.js.map +0 -1
- package/dist/chunk-GRGPQ32U.js.map +0 -1
- package/dist/chunk-HBJPYQRN.cjs.map +0 -1
- package/dist/chunk-HGNRQ3OG.js.map +0 -1
- package/dist/chunk-JXESKY4A.js.map +0 -1
- package/dist/chunk-KEURQGCQ.js.map +0 -1
- package/dist/chunk-KOSW5PP5.js.map +0 -1
- package/dist/chunk-LRSB62Z6.cjs.map +0 -1
- package/dist/chunk-MCUX2D5Q.js.map +0 -1
- package/dist/chunk-N4SJ4YX7.cjs.map +0 -1
- package/dist/chunk-O6NA3Z43.cjs.map +0 -1
- package/dist/chunk-OWX2PUFH.cjs.map +0 -1
- package/dist/chunk-QUKUN6NR.cjs.map +0 -1
- package/dist/chunk-T3WZCEC4.js.map +0 -1
- package/dist/chunk-UIZSWUKP.js.map +0 -1
- package/dist/chunk-VU6DVS7J.js.map +0 -1
- package/dist/chunk-VZGBVYXA.cjs.map +0 -1
- package/dist/chunk-XRIVPHXV.cjs.map +0 -1
- package/dist/chunk-YQ7NLZZ3.cjs.map +0 -1
- package/dist/chunk-ZPMFINU2.cjs.map +0 -1
- package/dist/models-dev-GCVENVWA.js +0 -3
- package/dist/models-dev-TIBJR6IG.cjs +0 -12
- package/dist/netlify-NTSNNT6F.cjs +0 -12
- package/dist/netlify-O5NJW7CF.js +0 -3
- package/dist/provider-registry-74GMFZKT.js +0 -3
- package/dist/provider-registry-BZP3DIIV.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;
|
|
@@ -1858,6 +1874,12 @@ var MessageList = class _MessageList {
|
|
|
1858
1874
|
return ti;
|
|
1859
1875
|
});
|
|
1860
1876
|
}
|
|
1877
|
+
if (!message.threadId && this.memoryInfo?.threadId) {
|
|
1878
|
+
message.threadId = this.memoryInfo.threadId;
|
|
1879
|
+
if (!message.resourceId && this.memoryInfo?.resourceId) {
|
|
1880
|
+
message.resourceId = this.memoryInfo.resourceId;
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1861
1883
|
return message;
|
|
1862
1884
|
}
|
|
1863
1885
|
aiV4UIMessageToMastraDBMessage(message, messageSource) {
|
|
@@ -1895,137 +1917,180 @@ var MessageList = class _MessageList {
|
|
|
1895
1917
|
if (typeof coreMessage.content === "string") {
|
|
1896
1918
|
parts.push({
|
|
1897
1919
|
type: "text",
|
|
1898
|
-
text: coreMessage.content
|
|
1899
|
-
// Preserve providerOptions from CoreMessage (e.g., for system messages with cacheControl)
|
|
1900
|
-
..."providerOptions" in coreMessage && coreMessage.providerOptions ? { providerMetadata: coreMessage.providerOptions } : {}
|
|
1920
|
+
text: coreMessage.content
|
|
1901
1921
|
});
|
|
1902
1922
|
} else if (Array.isArray(coreMessage.content)) {
|
|
1903
|
-
for (const
|
|
1904
|
-
switch (
|
|
1905
|
-
case "text":
|
|
1923
|
+
for (const aiV4Part of coreMessage.content) {
|
|
1924
|
+
switch (aiV4Part.type) {
|
|
1925
|
+
case "text": {
|
|
1906
1926
|
const prevPart = parts.at(-1);
|
|
1907
1927
|
if (coreMessage.role === "assistant" && prevPart && prevPart.type === "tool-invocation") {
|
|
1908
1928
|
parts.push({ type: "step-start" });
|
|
1909
1929
|
}
|
|
1910
|
-
const
|
|
1911
|
-
..."providerOptions" in coreMessage && coreMessage.providerOptions ? coreMessage.providerOptions : {},
|
|
1912
|
-
..."providerOptions" in part && part.providerOptions ? part.providerOptions : {}
|
|
1913
|
-
};
|
|
1914
|
-
parts.push({
|
|
1930
|
+
const part = {
|
|
1915
1931
|
type: "text",
|
|
1916
|
-
text:
|
|
1917
|
-
|
|
1918
|
-
|
|
1932
|
+
text: aiV4Part.text
|
|
1933
|
+
};
|
|
1934
|
+
if (aiV4Part.providerOptions) {
|
|
1935
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
1936
|
+
}
|
|
1937
|
+
parts.push(part);
|
|
1919
1938
|
break;
|
|
1920
|
-
|
|
1921
|
-
|
|
1939
|
+
}
|
|
1940
|
+
case "tool-call": {
|
|
1941
|
+
const part = {
|
|
1922
1942
|
type: "tool-invocation",
|
|
1923
1943
|
toolInvocation: {
|
|
1924
1944
|
state: "call",
|
|
1925
|
-
toolCallId:
|
|
1926
|
-
toolName:
|
|
1927
|
-
args:
|
|
1945
|
+
toolCallId: aiV4Part.toolCallId,
|
|
1946
|
+
toolName: aiV4Part.toolName,
|
|
1947
|
+
args: aiV4Part.args
|
|
1928
1948
|
}
|
|
1929
|
-
}
|
|
1949
|
+
};
|
|
1950
|
+
if (aiV4Part.providerOptions) {
|
|
1951
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
1952
|
+
}
|
|
1953
|
+
parts.push(part);
|
|
1930
1954
|
break;
|
|
1955
|
+
}
|
|
1931
1956
|
case "tool-result":
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1957
|
+
{
|
|
1958
|
+
let toolArgs = {};
|
|
1959
|
+
const toolCallInSameMsg = coreMessage.content.find(
|
|
1960
|
+
(p) => p.type === "tool-call" && p.toolCallId === aiV4Part.toolCallId
|
|
1961
|
+
);
|
|
1962
|
+
if (toolCallInSameMsg && toolCallInSameMsg.type === "tool-call") {
|
|
1963
|
+
toolArgs = toolCallInSameMsg.args;
|
|
1964
|
+
}
|
|
1965
|
+
if (Object.keys(toolArgs).length === 0) {
|
|
1966
|
+
for (let i = this.messages.length - 1; i >= 0; i--) {
|
|
1967
|
+
const msg = this.messages[i];
|
|
1968
|
+
if (msg && msg.role === "assistant" && msg.content.parts) {
|
|
1969
|
+
const toolCallPart = msg.content.parts.find(
|
|
1970
|
+
(p) => p.type === "tool-invocation" && p.toolInvocation.toolCallId === aiV4Part.toolCallId && p.toolInvocation.state === "call"
|
|
1971
|
+
);
|
|
1972
|
+
if (toolCallPart && toolCallPart.type === "tool-invocation" && toolCallPart.toolInvocation.args) {
|
|
1973
|
+
toolArgs = toolCallPart.toolInvocation.args;
|
|
1974
|
+
break;
|
|
1975
|
+
}
|
|
1949
1976
|
}
|
|
1950
1977
|
}
|
|
1951
1978
|
}
|
|
1979
|
+
const invocation = {
|
|
1980
|
+
state: "result",
|
|
1981
|
+
toolCallId: aiV4Part.toolCallId,
|
|
1982
|
+
toolName: aiV4Part.toolName,
|
|
1983
|
+
result: aiV4Part.result ?? "",
|
|
1984
|
+
// undefined will cause AI SDK to throw an error, but for client side tool calls this really could be undefined
|
|
1985
|
+
args: toolArgs
|
|
1986
|
+
// Use the args from the corresponding tool-call
|
|
1987
|
+
};
|
|
1988
|
+
const part = {
|
|
1989
|
+
type: "tool-invocation",
|
|
1990
|
+
toolInvocation: invocation
|
|
1991
|
+
};
|
|
1992
|
+
if (aiV4Part.providerOptions) {
|
|
1993
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
1994
|
+
}
|
|
1995
|
+
parts.push(part);
|
|
1996
|
+
toolInvocations.push(invocation);
|
|
1952
1997
|
}
|
|
1953
|
-
const invocation = {
|
|
1954
|
-
state: "result",
|
|
1955
|
-
toolCallId: part.toolCallId,
|
|
1956
|
-
toolName: part.toolName,
|
|
1957
|
-
result: part.result ?? "",
|
|
1958
|
-
// undefined will cause AI SDK to throw an error, but for client side tool calls this really could be undefined
|
|
1959
|
-
args: toolArgs
|
|
1960
|
-
// Use the args from the corresponding tool-call
|
|
1961
|
-
};
|
|
1962
|
-
parts.push({
|
|
1963
|
-
type: "tool-invocation",
|
|
1964
|
-
toolInvocation: invocation
|
|
1965
|
-
});
|
|
1966
|
-
toolInvocations.push(invocation);
|
|
1967
1998
|
break;
|
|
1968
1999
|
case "reasoning":
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
2000
|
+
{
|
|
2001
|
+
const part = {
|
|
2002
|
+
type: "reasoning",
|
|
2003
|
+
reasoning: "",
|
|
2004
|
+
// leave this blank so we aren't double storing it in the db along with details
|
|
2005
|
+
details: [{ type: "text", text: aiV4Part.text, signature: aiV4Part.signature }]
|
|
2006
|
+
};
|
|
2007
|
+
if (aiV4Part.providerOptions) {
|
|
2008
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2009
|
+
}
|
|
2010
|
+
parts.push(part);
|
|
2011
|
+
}
|
|
1975
2012
|
break;
|
|
1976
2013
|
case "redacted-reasoning":
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
2014
|
+
{
|
|
2015
|
+
const part = {
|
|
2016
|
+
type: "reasoning",
|
|
2017
|
+
reasoning: "",
|
|
2018
|
+
// No text reasoning for redacted parts
|
|
2019
|
+
details: [{ type: "redacted", data: aiV4Part.data }]
|
|
2020
|
+
};
|
|
2021
|
+
if (aiV4Part.providerOptions) {
|
|
2022
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2023
|
+
}
|
|
2024
|
+
parts.push(part);
|
|
2025
|
+
}
|
|
1983
2026
|
break;
|
|
1984
|
-
case "image":
|
|
1985
|
-
|
|
2027
|
+
case "image": {
|
|
2028
|
+
const part = {
|
|
1986
2029
|
type: "file",
|
|
1987
|
-
data: imageContentToString(
|
|
1988
|
-
mimeType:
|
|
1989
|
-
}
|
|
2030
|
+
data: imageContentToString(aiV4Part.image),
|
|
2031
|
+
mimeType: aiV4Part.mimeType
|
|
2032
|
+
};
|
|
2033
|
+
if (aiV4Part.providerOptions) {
|
|
2034
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2035
|
+
}
|
|
2036
|
+
parts.push(part);
|
|
1990
2037
|
break;
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
2038
|
+
}
|
|
2039
|
+
case "file": {
|
|
2040
|
+
if (aiV4Part.data instanceof URL) {
|
|
2041
|
+
const part = {
|
|
1994
2042
|
type: "file",
|
|
1995
|
-
data:
|
|
1996
|
-
mimeType:
|
|
1997
|
-
}
|
|
1998
|
-
|
|
1999
|
-
|
|
2043
|
+
data: aiV4Part.data.toString(),
|
|
2044
|
+
mimeType: aiV4Part.mimeType
|
|
2045
|
+
};
|
|
2046
|
+
if (aiV4Part.providerOptions) {
|
|
2047
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2048
|
+
}
|
|
2049
|
+
parts.push(part);
|
|
2050
|
+
} else if (typeof aiV4Part.data === "string") {
|
|
2051
|
+
const categorized = categorizeFileData(aiV4Part.data, aiV4Part.mimeType);
|
|
2000
2052
|
if (categorized.type === "url" || categorized.type === "dataUri") {
|
|
2001
|
-
|
|
2053
|
+
const part = {
|
|
2002
2054
|
type: "file",
|
|
2003
|
-
data:
|
|
2055
|
+
data: aiV4Part.data,
|
|
2004
2056
|
mimeType: categorized.mimeType || "image/png"
|
|
2005
|
-
}
|
|
2057
|
+
};
|
|
2058
|
+
if (aiV4Part.providerOptions) {
|
|
2059
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2060
|
+
}
|
|
2061
|
+
parts.push(part);
|
|
2006
2062
|
} else {
|
|
2007
2063
|
try {
|
|
2008
|
-
|
|
2064
|
+
const part = {
|
|
2009
2065
|
type: "file",
|
|
2010
2066
|
mimeType: categorized.mimeType || "image/png",
|
|
2011
|
-
data: convertDataContentToBase64String(
|
|
2012
|
-
}
|
|
2067
|
+
data: convertDataContentToBase64String(aiV4Part.data)
|
|
2068
|
+
};
|
|
2069
|
+
if (aiV4Part.providerOptions) {
|
|
2070
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2071
|
+
}
|
|
2072
|
+
parts.push(part);
|
|
2013
2073
|
} catch (error) {
|
|
2014
2074
|
console.error(`Failed to convert binary data to base64 in CoreMessage file part: ${error}`, error);
|
|
2015
2075
|
}
|
|
2016
2076
|
}
|
|
2017
2077
|
} else {
|
|
2018
2078
|
try {
|
|
2019
|
-
|
|
2079
|
+
const part = {
|
|
2020
2080
|
type: "file",
|
|
2021
|
-
mimeType:
|
|
2022
|
-
data: convertDataContentToBase64String(
|
|
2023
|
-
}
|
|
2081
|
+
mimeType: aiV4Part.mimeType,
|
|
2082
|
+
data: convertDataContentToBase64String(aiV4Part.data)
|
|
2083
|
+
};
|
|
2084
|
+
if (aiV4Part.providerOptions) {
|
|
2085
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2086
|
+
}
|
|
2087
|
+
parts.push(part);
|
|
2024
2088
|
} catch (error) {
|
|
2025
2089
|
console.error(`Failed to convert binary data to base64 in CoreMessage file part: ${error}`, error);
|
|
2026
2090
|
}
|
|
2027
2091
|
}
|
|
2028
2092
|
break;
|
|
2093
|
+
}
|
|
2029
2094
|
}
|
|
2030
2095
|
}
|
|
2031
2096
|
}
|
|
@@ -2036,6 +2101,12 @@ var MessageList = class _MessageList {
|
|
|
2036
2101
|
if (toolInvocations.length) content.toolInvocations = toolInvocations;
|
|
2037
2102
|
if (typeof coreMessage.content === `string`) content.content = coreMessage.content;
|
|
2038
2103
|
if (experimentalAttachments.length) content.experimental_attachments = experimentalAttachments;
|
|
2104
|
+
if (coreMessage.providerOptions) {
|
|
2105
|
+
content.providerMetadata = coreMessage.providerOptions;
|
|
2106
|
+
}
|
|
2107
|
+
if ("metadata" in coreMessage && coreMessage.metadata !== null && coreMessage.metadata !== void 0) {
|
|
2108
|
+
content.metadata = coreMessage.metadata;
|
|
2109
|
+
}
|
|
2039
2110
|
return {
|
|
2040
2111
|
id,
|
|
2041
2112
|
role: _MessageList.getRole(coreMessage),
|
|
@@ -2238,9 +2309,23 @@ var MessageList = class _MessageList {
|
|
|
2238
2309
|
if (role === `tool` || role === `assistant`) {
|
|
2239
2310
|
throw new Error(incompatibleMessage);
|
|
2240
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
|
+
}
|
|
2241
2326
|
roleContent[role].push({
|
|
2242
2327
|
...part,
|
|
2243
|
-
image:
|
|
2328
|
+
image: processedImage
|
|
2244
2329
|
});
|
|
2245
2330
|
break;
|
|
2246
2331
|
}
|
|
@@ -2386,6 +2471,9 @@ var MessageList = class _MessageList {
|
|
|
2386
2471
|
if (dbMsg.createdAt) metadata.createdAt = dbMsg.createdAt;
|
|
2387
2472
|
if (dbMsg.threadId) metadata.threadId = dbMsg.threadId;
|
|
2388
2473
|
if (dbMsg.resourceId) metadata.resourceId = dbMsg.resourceId;
|
|
2474
|
+
if (dbMsg.content.providerMetadata) {
|
|
2475
|
+
metadata.providerMetadata = dbMsg.content.providerMetadata;
|
|
2476
|
+
}
|
|
2389
2477
|
const hasToolInvocationParts = dbMsg.content.parts?.some((p) => p.type === "tool-invocation");
|
|
2390
2478
|
if (dbMsg.content.toolInvocations && !hasToolInvocationParts) {
|
|
2391
2479
|
for (const invocation of dbMsg.content.toolInvocations) {
|
|
@@ -2452,18 +2540,20 @@ var MessageList = class _MessageList {
|
|
|
2452
2540
|
continue;
|
|
2453
2541
|
}
|
|
2454
2542
|
if (part.type === "reasoning") {
|
|
2455
|
-
const
|
|
2456
|
-
const text = reasoningPart.text || reasoningPart.reasoning || (reasoningPart.details?.reduce((p, c) => {
|
|
2543
|
+
const text = part.reasoning || (part.details?.reduce((p, c) => {
|
|
2457
2544
|
if (c.type === `text` && c.text) return p + c.text;
|
|
2458
2545
|
return p;
|
|
2459
2546
|
}, "") ?? "");
|
|
2460
|
-
if (text ||
|
|
2461
|
-
|
|
2547
|
+
if (text || part.details?.length) {
|
|
2548
|
+
const v5UIPart = {
|
|
2462
2549
|
type: "reasoning",
|
|
2463
2550
|
text: text || "",
|
|
2464
|
-
state: "done"
|
|
2465
|
-
|
|
2466
|
-
|
|
2551
|
+
state: "done"
|
|
2552
|
+
};
|
|
2553
|
+
if (part.providerMetadata) {
|
|
2554
|
+
v5UIPart.providerMetadata = part.providerMetadata;
|
|
2555
|
+
}
|
|
2556
|
+
parts.push(v5UIPart);
|
|
2467
2557
|
}
|
|
2468
2558
|
continue;
|
|
2469
2559
|
}
|
|
@@ -2476,12 +2566,15 @@ var MessageList = class _MessageList {
|
|
|
2476
2566
|
}
|
|
2477
2567
|
const categorized = typeof part.data === "string" ? categorizeFileData(part.data, part.mimeType) : { type: "raw", mimeType: part.mimeType};
|
|
2478
2568
|
if (categorized.type === "url" && typeof part.data === "string") {
|
|
2479
|
-
|
|
2569
|
+
const v5UIPart = {
|
|
2480
2570
|
type: "file",
|
|
2481
2571
|
url: part.data,
|
|
2482
|
-
mediaType: categorized.mimeType || "image/png"
|
|
2483
|
-
|
|
2484
|
-
|
|
2572
|
+
mediaType: categorized.mimeType || "image/png"
|
|
2573
|
+
};
|
|
2574
|
+
if (part.providerMetadata) {
|
|
2575
|
+
v5UIPart.providerMetadata = part.providerMetadata;
|
|
2576
|
+
}
|
|
2577
|
+
parts.push(v5UIPart);
|
|
2485
2578
|
} else {
|
|
2486
2579
|
let filePartData;
|
|
2487
2580
|
let extractedMimeType = part.mimeType;
|
|
@@ -2505,27 +2598,37 @@ var MessageList = class _MessageList {
|
|
|
2505
2598
|
} else {
|
|
2506
2599
|
dataUri = createDataUri(filePartData, finalMimeType);
|
|
2507
2600
|
}
|
|
2508
|
-
|
|
2601
|
+
const v5UIPart = {
|
|
2509
2602
|
type: "file",
|
|
2510
2603
|
url: dataUri,
|
|
2511
2604
|
// Use url field with data URI
|
|
2512
|
-
mediaType: finalMimeType
|
|
2513
|
-
|
|
2514
|
-
|
|
2605
|
+
mediaType: finalMimeType
|
|
2606
|
+
};
|
|
2607
|
+
if (part.providerMetadata) {
|
|
2608
|
+
v5UIPart.providerMetadata = part.providerMetadata;
|
|
2609
|
+
}
|
|
2610
|
+
parts.push(v5UIPart);
|
|
2515
2611
|
}
|
|
2516
2612
|
} else if (part.type === "source") {
|
|
2517
|
-
const
|
|
2518
|
-
parts.push({
|
|
2613
|
+
const v5UIPart = {
|
|
2519
2614
|
type: "source-url",
|
|
2520
|
-
url:
|
|
2521
|
-
|
|
2522
|
-
|
|
2615
|
+
url: part.source.url,
|
|
2616
|
+
sourceId: part.source.id,
|
|
2617
|
+
title: part.source.title
|
|
2618
|
+
};
|
|
2619
|
+
if (part.providerMetadata) {
|
|
2620
|
+
v5UIPart.providerMetadata = part.providerMetadata;
|
|
2621
|
+
}
|
|
2622
|
+
parts.push(v5UIPart);
|
|
2523
2623
|
} else if (part.type === "text") {
|
|
2524
|
-
|
|
2624
|
+
const v5UIPart = {
|
|
2525
2625
|
type: "text",
|
|
2526
|
-
text: part.text
|
|
2527
|
-
|
|
2528
|
-
|
|
2626
|
+
text: part.text
|
|
2627
|
+
};
|
|
2628
|
+
if (part.providerMetadata) {
|
|
2629
|
+
v5UIPart.providerMetadata = part.providerMetadata;
|
|
2630
|
+
}
|
|
2631
|
+
parts.push(v5UIPart);
|
|
2529
2632
|
hasNonToolReasoningParts = true;
|
|
2530
2633
|
} else {
|
|
2531
2634
|
parts.push(part);
|
|
@@ -2689,32 +2792,69 @@ var MessageList = class _MessageList {
|
|
|
2689
2792
|
}
|
|
2690
2793
|
};
|
|
2691
2794
|
}
|
|
2795
|
+
/**
|
|
2796
|
+
* Convert image or file to data URI or URL for V2 file part
|
|
2797
|
+
*/
|
|
2798
|
+
static getDataStringFromAIV5DataPart = (part) => {
|
|
2799
|
+
let mimeType;
|
|
2800
|
+
let data;
|
|
2801
|
+
if ("data" in part) {
|
|
2802
|
+
mimeType = part.mediaType || "application/octet-stream";
|
|
2803
|
+
data = part.data;
|
|
2804
|
+
} else if ("image" in part) {
|
|
2805
|
+
mimeType = part.mediaType || "image/jpeg";
|
|
2806
|
+
data = part.image;
|
|
2807
|
+
} else {
|
|
2808
|
+
throw new MastraError({
|
|
2809
|
+
id: "MASTRA_AIV5_DATA_PART_INVALID",
|
|
2810
|
+
domain: "AGENT" /* AGENT */,
|
|
2811
|
+
category: "USER" /* USER */,
|
|
2812
|
+
text: "Invalid AIV5 data part in getDataStringFromAIV5DataPart",
|
|
2813
|
+
details: {
|
|
2814
|
+
part
|
|
2815
|
+
}
|
|
2816
|
+
});
|
|
2817
|
+
}
|
|
2818
|
+
if (data instanceof URL) {
|
|
2819
|
+
return data.toString();
|
|
2820
|
+
} else {
|
|
2821
|
+
if (data instanceof Buffer) {
|
|
2822
|
+
const base64 = data.toString("base64");
|
|
2823
|
+
return `data:${mimeType};base64,${base64}`;
|
|
2824
|
+
} else if (typeof data === "string") {
|
|
2825
|
+
return data.startsWith("data:") || data.startsWith("http") ? data : `data:${mimeType};base64,${data}`;
|
|
2826
|
+
} else if (data instanceof Uint8Array) {
|
|
2827
|
+
const base64 = Buffer.from(data).toString("base64");
|
|
2828
|
+
return `data:${mimeType};base64,${base64}`;
|
|
2829
|
+
} else if (data instanceof ArrayBuffer) {
|
|
2830
|
+
const base64 = Buffer.from(data).toString("base64");
|
|
2831
|
+
return `data:${mimeType};base64,${base64}`;
|
|
2832
|
+
} else {
|
|
2833
|
+
return "";
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
};
|
|
2692
2837
|
/**
|
|
2693
2838
|
* Direct conversion from AIV5 ModelMessage to MastraDBMessage
|
|
2694
2839
|
* Combines logic from aiV5ModelMessageToMastraMessageV3 + mastraMessageV3ToV2
|
|
2695
2840
|
*/
|
|
2696
2841
|
static aiV5ModelMessageToMastraDBMessage(modelMsg, _messageSource) {
|
|
2697
2842
|
const content = Array.isArray(modelMsg.content) ? modelMsg.content : [{ type: "text", text: modelMsg.content }];
|
|
2698
|
-
const
|
|
2843
|
+
const mastraDBParts = [];
|
|
2699
2844
|
const toolInvocations = [];
|
|
2700
2845
|
const reasoningParts = [];
|
|
2701
2846
|
const experimental_attachments = [];
|
|
2702
|
-
const textParts = [];
|
|
2703
2847
|
let lastPartWasToolResult = false;
|
|
2704
2848
|
for (const part of content) {
|
|
2705
|
-
const providerMetadata = {
|
|
2706
|
-
...modelMsg.providerMetadata || {},
|
|
2707
|
-
...part.providerMetadata || {}
|
|
2708
|
-
};
|
|
2709
|
-
const hasProviderMetadata = Object.keys(providerMetadata).length > 0;
|
|
2710
2849
|
if (part.type === "text") {
|
|
2711
2850
|
const textPart = {
|
|
2712
2851
|
type: "text",
|
|
2713
|
-
text: part.text
|
|
2714
|
-
...hasProviderMetadata && { experimental_providerMetadata: providerMetadata }
|
|
2852
|
+
text: part.text
|
|
2715
2853
|
};
|
|
2716
|
-
|
|
2717
|
-
|
|
2854
|
+
if (part.providerOptions) {
|
|
2855
|
+
textPart.providerMetadata = part.providerOptions;
|
|
2856
|
+
}
|
|
2857
|
+
mastraDBParts.push(textPart);
|
|
2718
2858
|
lastPartWasToolResult = false;
|
|
2719
2859
|
} else if (part.type === "tool-call") {
|
|
2720
2860
|
const toolCallPart = part;
|
|
@@ -2725,10 +2865,12 @@ var MessageList = class _MessageList {
|
|
|
2725
2865
|
toolName: toolCallPart.toolName,
|
|
2726
2866
|
args: toolCallPart.input,
|
|
2727
2867
|
state: "call"
|
|
2728
|
-
}
|
|
2729
|
-
...hasProviderMetadata && { providerMetadata }
|
|
2868
|
+
}
|
|
2730
2869
|
};
|
|
2731
|
-
|
|
2870
|
+
if (part.providerOptions) {
|
|
2871
|
+
toolInvocationPart.providerMetadata = part.providerOptions;
|
|
2872
|
+
}
|
|
2873
|
+
mastraDBParts.push(toolInvocationPart);
|
|
2732
2874
|
toolInvocations.push({
|
|
2733
2875
|
toolCallId: toolCallPart.toolCallId,
|
|
2734
2876
|
toolName: toolCallPart.toolName,
|
|
@@ -2739,78 +2881,67 @@ var MessageList = class _MessageList {
|
|
|
2739
2881
|
} else if (part.type === "tool-result") {
|
|
2740
2882
|
const toolResultPart = part;
|
|
2741
2883
|
const matchingCall = toolInvocations.find((inv) => inv.toolCallId === toolResultPart.toolCallId);
|
|
2742
|
-
const matchingV2Part =
|
|
2884
|
+
const matchingV2Part = mastraDBParts.find(
|
|
2743
2885
|
(p) => p.type === "tool-invocation" && "toolInvocation" in p && p.toolInvocation.toolCallId === toolResultPart.toolCallId
|
|
2744
2886
|
);
|
|
2887
|
+
const updateMatchingCallInvocationResult = (toolResultPart2, matchingCall2) => {
|
|
2888
|
+
matchingCall2.state = "result";
|
|
2889
|
+
matchingCall2.result = typeof toolResultPart2.output === "object" && toolResultPart2.output && "value" in toolResultPart2.output ? toolResultPart2.output.value : toolResultPart2.output;
|
|
2890
|
+
};
|
|
2745
2891
|
if (matchingCall) {
|
|
2746
|
-
matchingCall
|
|
2747
|
-
matchingCall.result = typeof toolResultPart.output === "object" && toolResultPart.output && "value" in toolResultPart.output ? toolResultPart.output.value : toolResultPart.output;
|
|
2892
|
+
updateMatchingCallInvocationResult(toolResultPart, matchingCall);
|
|
2748
2893
|
} else {
|
|
2749
|
-
const
|
|
2750
|
-
|
|
2894
|
+
const call = {
|
|
2895
|
+
state: "call",
|
|
2751
2896
|
toolCallId: toolResultPart.toolCallId,
|
|
2752
|
-
toolName:
|
|
2753
|
-
args: {}
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2897
|
+
toolName: toolResultPart.toolName || "unknown",
|
|
2898
|
+
args: {}
|
|
2899
|
+
};
|
|
2900
|
+
updateMatchingCallInvocationResult(toolResultPart, call);
|
|
2901
|
+
toolInvocations.push(call);
|
|
2757
2902
|
}
|
|
2758
2903
|
if (matchingV2Part && matchingV2Part.type === "tool-invocation") {
|
|
2759
|
-
matchingV2Part.toolInvocation
|
|
2760
|
-
matchingV2Part.toolInvocation.result = typeof toolResultPart.output === "object" && toolResultPart.output && "value" in toolResultPart.output ? toolResultPart.output.value : toolResultPart.output;
|
|
2761
|
-
if (hasProviderMetadata) {
|
|
2762
|
-
matchingV2Part.providerMetadata = providerMetadata;
|
|
2763
|
-
}
|
|
2904
|
+
updateMatchingCallInvocationResult(toolResultPart, matchingV2Part.toolInvocation);
|
|
2764
2905
|
} else {
|
|
2765
|
-
const resultPartWithName = toolResultPart;
|
|
2766
2906
|
const toolInvocationPart = {
|
|
2767
2907
|
type: "tool-invocation",
|
|
2768
2908
|
toolInvocation: {
|
|
2769
2909
|
toolCallId: toolResultPart.toolCallId,
|
|
2770
|
-
toolName:
|
|
2910
|
+
toolName: toolResultPart.toolName || "unknown",
|
|
2771
2911
|
args: {},
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
},
|
|
2775
|
-
...hasProviderMetadata && { providerMetadata }
|
|
2912
|
+
state: "call"
|
|
2913
|
+
}
|
|
2776
2914
|
};
|
|
2777
|
-
|
|
2915
|
+
updateMatchingCallInvocationResult(toolResultPart, toolInvocationPart.toolInvocation);
|
|
2916
|
+
mastraDBParts.push(toolInvocationPart);
|
|
2778
2917
|
}
|
|
2779
2918
|
lastPartWasToolResult = true;
|
|
2780
2919
|
} else if (part.type === "reasoning") {
|
|
2781
|
-
const reasoningPart = part;
|
|
2782
2920
|
const v2ReasoningPart = {
|
|
2783
2921
|
type: "reasoning",
|
|
2784
|
-
reasoning:
|
|
2785
|
-
|
|
2786
|
-
|
|
2922
|
+
reasoning: "",
|
|
2923
|
+
// leave this blank so we aren't double storing it in the db along with details
|
|
2924
|
+
details: [{ type: "text", text: part.text }]
|
|
2787
2925
|
};
|
|
2788
|
-
|
|
2789
|
-
|
|
2926
|
+
if (part.providerOptions) {
|
|
2927
|
+
v2ReasoningPart.providerMetadata = part.providerOptions;
|
|
2928
|
+
}
|
|
2929
|
+
mastraDBParts.push(v2ReasoningPart);
|
|
2930
|
+
reasoningParts.push(part.text);
|
|
2790
2931
|
lastPartWasToolResult = false;
|
|
2791
2932
|
} else if (part.type === "image") {
|
|
2792
2933
|
const imagePart = part;
|
|
2793
|
-
|
|
2794
|
-
const
|
|
2795
|
-
if ("url" in imagePart && typeof imagePart.url === "string") {
|
|
2796
|
-
imageData = imagePart.url;
|
|
2797
|
-
} else if ("data" in imagePart) {
|
|
2798
|
-
if (typeof imagePart.data === "string") {
|
|
2799
|
-
imageData = imagePart.data.startsWith("data:") || imagePart.data.startsWith("http") ? imagePart.data : `data:${mimeType};base64,${imagePart.data}`;
|
|
2800
|
-
} else {
|
|
2801
|
-
const base64 = Buffer.from(imagePart.data).toString("base64");
|
|
2802
|
-
imageData = `data:${mimeType};base64,${base64}`;
|
|
2803
|
-
}
|
|
2804
|
-
} else {
|
|
2805
|
-
imageData = "";
|
|
2806
|
-
}
|
|
2934
|
+
const mimeType = imagePart.mediaType || "image/jpeg";
|
|
2935
|
+
const imageData = this.getDataStringFromAIV5DataPart(imagePart);
|
|
2807
2936
|
const imageFilePart = {
|
|
2808
2937
|
type: "file",
|
|
2809
2938
|
data: imageData,
|
|
2810
|
-
mimeType
|
|
2811
|
-
...hasProviderMetadata && { providerMetadata }
|
|
2939
|
+
mimeType
|
|
2812
2940
|
};
|
|
2813
|
-
|
|
2941
|
+
if (part.providerOptions) {
|
|
2942
|
+
imageFilePart.providerMetadata = part.providerOptions;
|
|
2943
|
+
}
|
|
2944
|
+
mastraDBParts.push(imageFilePart);
|
|
2814
2945
|
experimental_attachments.push({
|
|
2815
2946
|
url: imageData,
|
|
2816
2947
|
contentType: mimeType
|
|
@@ -2819,26 +2950,16 @@ var MessageList = class _MessageList {
|
|
|
2819
2950
|
} else if (part.type === "file") {
|
|
2820
2951
|
const filePart = part;
|
|
2821
2952
|
const mimeType = filePart.mediaType || "application/octet-stream";
|
|
2822
|
-
|
|
2823
|
-
if ("url" in filePart && typeof filePart.url === "string") {
|
|
2824
|
-
fileData = filePart.url;
|
|
2825
|
-
} else if ("data" in filePart) {
|
|
2826
|
-
if (typeof filePart.data === "string") {
|
|
2827
|
-
fileData = filePart.data.startsWith("data:") || filePart.data.startsWith("http") ? filePart.data : `data:${mimeType};base64,${filePart.data}`;
|
|
2828
|
-
} else {
|
|
2829
|
-
const base64 = Buffer.from(filePart.data).toString("base64");
|
|
2830
|
-
fileData = `data:${mimeType};base64,${base64}`;
|
|
2831
|
-
}
|
|
2832
|
-
} else {
|
|
2833
|
-
fileData = "";
|
|
2834
|
-
}
|
|
2953
|
+
const fileData = this.getDataStringFromAIV5DataPart(filePart);
|
|
2835
2954
|
const v2FilePart = {
|
|
2836
2955
|
type: "file",
|
|
2837
2956
|
data: fileData,
|
|
2838
|
-
mimeType
|
|
2839
|
-
...hasProviderMetadata && { providerMetadata }
|
|
2957
|
+
mimeType
|
|
2840
2958
|
};
|
|
2841
|
-
|
|
2959
|
+
if (part.providerOptions) {
|
|
2960
|
+
v2FilePart.providerMetadata = part.providerOptions;
|
|
2961
|
+
}
|
|
2962
|
+
mastraDBParts.push(v2FilePart);
|
|
2842
2963
|
experimental_attachments.push({
|
|
2843
2964
|
url: fileData,
|
|
2844
2965
|
contentType: mimeType
|
|
@@ -2846,34 +2967,34 @@ var MessageList = class _MessageList {
|
|
|
2846
2967
|
lastPartWasToolResult = false;
|
|
2847
2968
|
}
|
|
2848
2969
|
}
|
|
2849
|
-
if (modelMsg.role === "assistant" && lastPartWasToolResult &&
|
|
2850
|
-
const lastPart =
|
|
2970
|
+
if (modelMsg.role === "assistant" && lastPartWasToolResult && mastraDBParts.length > 0) {
|
|
2971
|
+
const lastPart = mastraDBParts[mastraDBParts.length - 1];
|
|
2851
2972
|
if (lastPart && lastPart.type !== "text") {
|
|
2852
2973
|
const emptyTextPart = { type: "text", text: "" };
|
|
2853
|
-
|
|
2854
|
-
textParts.push({ text: "" });
|
|
2974
|
+
mastraDBParts.push(emptyTextPart);
|
|
2855
2975
|
}
|
|
2856
2976
|
}
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
contentString = textParts.map((p) => p.text).join("\n");
|
|
2860
|
-
}
|
|
2861
|
-
const metadata = {};
|
|
2977
|
+
const contentString = mastraDBParts.filter((p) => p.type === "text").map((p) => p.text).join("\n");
|
|
2978
|
+
const metadata = "metadata" in modelMsg && modelMsg.metadata !== null && modelMsg.metadata !== void 0 ? modelMsg.metadata : {};
|
|
2862
2979
|
const id = `id` in modelMsg && typeof modelMsg.id === `string` ? modelMsg.id : `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
2863
|
-
|
|
2980
|
+
const message = {
|
|
2864
2981
|
id,
|
|
2865
2982
|
role: _MessageList.getRole(modelMsg),
|
|
2866
2983
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2867
2984
|
content: {
|
|
2868
2985
|
format: 2,
|
|
2869
|
-
parts:
|
|
2986
|
+
parts: mastraDBParts,
|
|
2870
2987
|
toolInvocations: toolInvocations.length > 0 ? toolInvocations : void 0,
|
|
2871
2988
|
reasoning: reasoningParts.length > 0 ? reasoningParts.join("\n") : void 0,
|
|
2872
2989
|
experimental_attachments: experimental_attachments.length > 0 ? experimental_attachments : void 0,
|
|
2873
|
-
content: contentString,
|
|
2874
|
-
metadata
|
|
2990
|
+
content: contentString || void 0,
|
|
2991
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : void 0
|
|
2875
2992
|
}
|
|
2876
2993
|
};
|
|
2994
|
+
if (modelMsg.providerOptions) {
|
|
2995
|
+
message.content.providerMetadata = modelMsg.providerOptions;
|
|
2996
|
+
}
|
|
2997
|
+
return message;
|
|
2877
2998
|
}
|
|
2878
2999
|
aiV4CoreMessagesToAIV5ModelMessages(messages, source) {
|
|
2879
3000
|
return this.aiV5UIMessagesToAIV5ModelMessages(
|
|
@@ -2884,14 +3005,24 @@ var MessageList = class _MessageList {
|
|
|
2884
3005
|
const sanitized = this.sanitizeV5UIMessages(messages, filterIncompleteToolCalls);
|
|
2885
3006
|
const preprocessed = this.addStartStepPartsForAIV5(sanitized);
|
|
2886
3007
|
const result = AIV5.convertToModelMessages(preprocessed);
|
|
2887
|
-
return result
|
|
3008
|
+
return result.map((modelMsg, index) => {
|
|
3009
|
+
const uiMsg = preprocessed[index];
|
|
3010
|
+
if (uiMsg?.metadata && typeof uiMsg.metadata === "object" && "providerMetadata" in uiMsg.metadata && uiMsg.metadata.providerMetadata) {
|
|
3011
|
+
return {
|
|
3012
|
+
...modelMsg,
|
|
3013
|
+
providerOptions: uiMsg.metadata.providerMetadata
|
|
3014
|
+
};
|
|
3015
|
+
}
|
|
3016
|
+
return modelMsg;
|
|
3017
|
+
});
|
|
2888
3018
|
}
|
|
2889
3019
|
addStartStepPartsForAIV5(messages) {
|
|
2890
3020
|
for (const message of messages) {
|
|
2891
3021
|
if (message.role !== `assistant`) continue;
|
|
2892
3022
|
for (const [index, part] of message.parts.entries()) {
|
|
2893
3023
|
if (!AIV5.isToolUIPart(part)) continue;
|
|
2894
|
-
|
|
3024
|
+
const nextPart = message.parts.at(index + 1);
|
|
3025
|
+
if (nextPart && nextPart.type !== `step-start` && !AIV5.isToolUIPart(nextPart)) {
|
|
2895
3026
|
message.parts.splice(index + 1, 0, { type: "step-start" });
|
|
2896
3027
|
}
|
|
2897
3028
|
}
|
|
@@ -3017,5 +3148,5 @@ var MessageList = class _MessageList {
|
|
|
3017
3148
|
};
|
|
3018
3149
|
|
|
3019
3150
|
export { DefaultGeneratedFile, DefaultGeneratedFileWithType, MessageList, convertMessages };
|
|
3020
|
-
//# sourceMappingURL=chunk-
|
|
3021
|
-
//# sourceMappingURL=chunk-
|
|
3151
|
+
//# sourceMappingURL=chunk-YDFX3JR2.js.map
|
|
3152
|
+
//# sourceMappingURL=chunk-YDFX3JR2.js.map
|