@mastra/core 1.0.0-beta.2 → 1.0.0-beta.4
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 +206 -0
- package/dist/agent/agent-legacy.d.ts +2 -2
- package/dist/agent/agent-legacy.d.ts.map +1 -1
- package/dist/agent/agent.d.ts +1 -1
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.types.d.ts +3 -2
- 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/convert-file.d.ts +1 -1
- package/dist/agent/message-list/prompt/convert-file.d.ts.map +1 -1
- package/dist/agent/message-list/prompt/download-assets.d.ts.map +1 -1
- package/dist/agent/types.d.ts +1 -0
- 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 +2 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts +3 -1
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +2 -1
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts +2 -1
- package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts +3 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
- package/dist/{chunk-YCVEJ3UN.cjs → chunk-2NVBZKZI.cjs} +988 -233
- package/dist/chunk-2NVBZKZI.cjs.map +1 -0
- package/dist/{chunk-SNPVZPLB.js → chunk-2OTDXX73.js} +6 -5
- package/dist/chunk-2OTDXX73.js.map +1 -0
- package/dist/chunk-3PSWNGBF.js +3 -0
- package/dist/{chunk-ZV5CC35D.js.map → chunk-3PSWNGBF.js.map} +1 -1
- package/dist/{chunk-ZGHTOYHW.js → chunk-3RW5EMSB.js} +155 -24
- package/dist/chunk-3RW5EMSB.js.map +1 -0
- package/dist/chunk-3W5RQCCY.cjs +440 -0
- package/dist/chunk-3W5RQCCY.cjs.map +1 -0
- package/dist/{chunk-ET6UOTTU.cjs → chunk-4IKJAKCD.cjs} +40 -4
- package/dist/chunk-4IKJAKCD.cjs.map +1 -0
- package/dist/{chunk-2ZVKF4HP.cjs → chunk-4RXG622P.cjs} +184 -285
- package/dist/chunk-4RXG622P.cjs.map +1 -0
- package/dist/{chunk-22443P6A.cjs → chunk-5WXEYDFI.cjs} +173 -42
- package/dist/chunk-5WXEYDFI.cjs.map +1 -0
- package/dist/{chunk-ZWNI5IWX.cjs → chunk-CYVNOIXS.cjs} +13 -12
- package/dist/chunk-CYVNOIXS.cjs.map +1 -0
- package/dist/{chunk-4CDL2QJT.js → chunk-D6EDHNGV.js} +53 -16
- package/dist/chunk-D6EDHNGV.js.map +1 -0
- package/dist/chunk-FVNT7VTO.js +436 -0
- package/dist/chunk-FVNT7VTO.js.map +1 -0
- package/dist/{chunk-WM6CK2F3.cjs → chunk-HBJPYQRN.cjs} +57 -19
- package/dist/chunk-HBJPYQRN.cjs.map +1 -0
- package/dist/{chunk-HDJFSJCK.js → chunk-IHJDOC3A.js} +35 -587
- package/dist/chunk-IHJDOC3A.js.map +1 -0
- package/dist/{chunk-QUKUN6NR.cjs → chunk-ISMGVGUM.cjs} +105 -5
- package/dist/chunk-ISMGVGUM.cjs.map +1 -0
- package/dist/{chunk-JYYQQEBH.cjs → chunk-IWB65P37.cjs} +241 -4
- package/dist/chunk-IWB65P37.cjs.map +1 -0
- package/dist/{chunk-MV7KHWUT.js → chunk-IWQDBVJK.js} +25 -4
- package/dist/chunk-IWQDBVJK.js.map +1 -0
- package/dist/{chunk-XEVG546F.js → chunk-JXESKY4A.js} +3 -3
- package/dist/{chunk-XEVG546F.js.map → chunk-JXESKY4A.js.map} +1 -1
- package/dist/{chunk-7AHYOMHJ.js → chunk-KEURQGCQ.js} +40 -5
- package/dist/chunk-KEURQGCQ.js.map +1 -0
- package/dist/{chunk-JPGVRWWL.js → chunk-MDKPL2R2.js} +470 -124
- package/dist/chunk-MDKPL2R2.js.map +1 -0
- package/dist/{chunk-UIZSWUKP.js → chunk-NZAXAFI3.js} +104 -6
- package/dist/chunk-NZAXAFI3.js.map +1 -0
- package/dist/{chunk-VOY2RXOC.cjs → chunk-O6NA3Z43.cjs} +6 -6
- package/dist/{chunk-VOY2RXOC.cjs.map → chunk-O6NA3Z43.cjs.map} +1 -1
- package/dist/chunk-PE3V7GUL.cjs +4 -0
- package/dist/{chunk-LJFJTTZQ.cjs.map → chunk-PE3V7GUL.cjs.map} +1 -1
- package/dist/{chunk-I4CXL4SR.js → chunk-RXDJL5QT.js} +5 -4
- package/dist/chunk-RXDJL5QT.js.map +1 -0
- package/dist/{chunk-LWBQ4P4N.cjs → chunk-S6OEQHEI.cjs} +62 -614
- package/dist/chunk-S6OEQHEI.cjs.map +1 -0
- package/dist/{chunk-7PO6SEJF.js → chunk-U7VECK2G.js} +240 -3
- package/dist/chunk-U7VECK2G.js.map +1 -0
- package/dist/{chunk-ECFXGXWO.cjs → chunk-VSM3NLUX.cjs} +312 -210
- package/dist/chunk-VSM3NLUX.cjs.map +1 -0
- package/dist/{chunk-IQO7ANVS.cjs → chunk-VZC4BWWH.cjs} +10 -9
- package/dist/chunk-VZC4BWWH.cjs.map +1 -0
- package/dist/{chunk-JV2KH24V.js → chunk-W3DD3XP5.js} +312 -210
- package/dist/chunk-W3DD3XP5.js.map +1 -0
- package/dist/{chunk-GGYKYORQ.cjs → chunk-WQSGX6XA.cjs} +27 -6
- package/dist/chunk-WQSGX6XA.cjs.map +1 -0
- package/dist/{chunk-W7UH2PWL.js → chunk-WTYNK7Q4.js} +179 -282
- package/dist/chunk-WTYNK7Q4.js.map +1 -0
- package/dist/{chunk-7CBEP2ZQ.js → chunk-XXBWX7DT.js} +949 -197
- package/dist/chunk-XXBWX7DT.js.map +1 -0
- package/dist/{chunk-CB575O6L.cjs → chunk-ZCVTH3CH.cjs} +470 -130
- package/dist/chunk-ZCVTH3CH.cjs.map +1 -0
- package/dist/evals/base.d.ts.map +1 -1
- package/dist/evals/index.cjs +4 -4
- package/dist/evals/index.js +1 -1
- package/dist/evals/scoreTraces/index.cjs +5 -4
- package/dist/evals/scoreTraces/index.cjs.map +1 -1
- package/dist/evals/scoreTraces/index.js +3 -2
- package/dist/evals/scoreTraces/index.js.map +1 -1
- package/dist/evals/scoreTraces/scoreTracesWorkflow.d.ts.map +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 +26 -10
- package/dist/llm/index.d.ts +1 -0
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +5 -1
- package/dist/llm/model/aisdk/v5/model.d.ts +47 -0
- package/dist/llm/model/aisdk/v5/model.d.ts.map +1 -0
- package/dist/llm/model/gateways/base.d.ts +8 -0
- package/dist/llm/model/gateways/base.d.ts.map +1 -1
- package/dist/llm/model/gateways/models-dev.d.ts +1 -0
- package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
- package/dist/llm/model/gateways/netlify.d.ts +2 -1
- package/dist/llm/model/gateways/netlify.d.ts.map +1 -1
- package/dist/llm/model/is-v2-model.d.ts +3 -0
- package/dist/llm/model/is-v2-model.d.ts.map +1 -0
- package/dist/llm/model/model-method-from-agent.d.ts +4 -0
- package/dist/llm/model/model-method-from-agent.d.ts.map +1 -0
- package/dist/llm/model/model.loop.d.ts +2 -2
- package/dist/llm/model/model.loop.d.ts.map +1 -1
- package/dist/llm/model/model.loop.types.d.ts +2 -0
- package/dist/llm/model/model.loop.types.d.ts.map +1 -1
- package/dist/llm/model/provider-registry.d.ts +11 -1
- package/dist/llm/model/provider-registry.d.ts.map +1 -1
- package/dist/llm/model/provider-types.generated.d.ts +56 -7
- package/dist/llm/model/registry-generator.d.ts.map +1 -1
- package/dist/llm/model/resolve-model.d.ts +1 -1
- package/dist/llm/model/resolve-model.d.ts.map +1 -1
- package/dist/llm/model/router.d.ts +12 -5
- package/dist/llm/model/router.d.ts.map +1 -1
- package/dist/llm/model/shared.types.d.ts +10 -4
- package/dist/llm/model/shared.types.d.ts.map +1 -1
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/network/index.d.ts.map +1 -1
- package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts +37 -0
- package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts.map +1 -0
- package/dist/loop/test-utils/fullStream.d.ts.map +1 -1
- package/dist/loop/test-utils/generateText.d.ts.map +1 -1
- package/dist/loop/test-utils/options.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/textStream.d.ts.map +1 -1
- package/dist/loop/test-utils/toUIMessageStream.d.ts.map +1 -1
- package/dist/loop/test-utils/tools.d.ts.map +1 -1
- package/dist/loop/test-utils/utils.d.ts +1 -1
- package/dist/loop/test-utils/utils.d.ts.map +1 -1
- package/dist/loop/types.d.ts +8 -3
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +12 -12
- package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +9 -9
- 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 +4 -4
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts +13 -12
- package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
- package/dist/loop/workflows/run-state.d.ts +2 -2
- package/dist/loop/workflows/run-state.d.ts.map +1 -1
- package/dist/loop/workflows/schema.d.ts +4 -4
- package/dist/loop/workflows/stream.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.ts +127 -3
- package/dist/mastra/index.d.ts.map +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +8 -8
- package/dist/memory/index.js +4 -4
- package/dist/models-dev-6PRLJKVZ.js +3 -0
- package/dist/{models-dev-DNBKXHT4.js.map → models-dev-6PRLJKVZ.js.map} +1 -1
- package/dist/models-dev-WHMI5G6Y.cjs +12 -0
- package/dist/{models-dev-YBEEQIX6.cjs.map → models-dev-WHMI5G6Y.cjs.map} +1 -1
- package/dist/netlify-46I3SNNV.cjs +12 -0
- package/dist/{netlify-GWNGSIRZ.cjs.map → netlify-46I3SNNV.cjs.map} +1 -1
- package/dist/netlify-EBQ6YUC6.js +3 -0
- package/dist/{netlify-7G2L5VSH.js.map → netlify-EBQ6YUC6.js.map} +1 -1
- package/dist/processors/index.cjs +11 -11
- package/dist/processors/index.js +1 -1
- package/dist/provider-registry-HDG6UMUC.js +3 -0
- package/dist/provider-registry-HDG6UMUC.js.map +1 -0
- package/dist/provider-registry-RP2W4B24.cjs +40 -0
- package/dist/provider-registry-RP2W4B24.cjs.map +1 -0
- package/dist/provider-registry.json +140 -18
- package/dist/{registry-generator-MK63POJO.cjs → registry-generator-JPCV47SC.cjs} +6 -4
- package/dist/registry-generator-JPCV47SC.cjs.map +1 -0
- package/dist/{registry-generator-H4YNODDH.js → registry-generator-XD4FPZTU.js} +6 -4
- package/dist/registry-generator-XD4FPZTU.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/index.cjs +12 -1
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +12 -1
- package/dist/server/index.js.map +1 -1
- package/dist/storage/domains/workflows/inmemory.d.ts +1 -1
- package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
- package/dist/storage/index.cjs +29 -29
- package/dist/storage/index.js +1 -1
- package/dist/storage/types.d.ts +2 -1
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/stream/RunOutput.d.ts +1 -1
- package/dist/stream/RunOutput.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/execute.d.ts +6 -3
- package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
- package/dist/stream/base/input.d.ts +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 +4 -3
- 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 +4 -4
- package/dist/tools/index.js +1 -1
- package/dist/tools/is-vercel-tool.cjs +2 -2
- package/dist/tools/is-vercel-tool.js +1 -1
- package/dist/tools/tool-builder/builder.d.ts.map +1 -1
- package/dist/tools/tool.d.ts.map +1 -1
- package/dist/tools/types.d.ts +1 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/validation.d.ts +12 -0
- package/dist/tools/validation.d.ts.map +1 -1
- package/dist/utils.cjs +25 -21
- package/dist/utils.d.ts +4 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +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 +24 -8
- package/dist/workflows/default.d.ts.map +1 -1
- package/dist/workflows/evented/execution-engine.d.ts +3 -1
- package/dist/workflows/evented/execution-engine.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/workflow-event-processor/index.d.ts +5 -4
- package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/loop.d.ts +1 -1
- package/dist/workflows/evented/workflow-event-processor/loop.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/parallel.d.ts +2 -2
- package/dist/workflows/evented/workflow-event-processor/parallel.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/sleep.d.ts +2 -2
- package/dist/workflows/evented/workflow-event-processor/sleep.d.ts.map +1 -1
- package/dist/workflows/evented/workflow.d.ts +2 -1
- package/dist/workflows/evented/workflow.d.ts.map +1 -1
- package/dist/workflows/execution-engine.d.ts +4 -2
- package/dist/workflows/execution-engine.d.ts.map +1 -1
- package/dist/workflows/index.cjs +28 -16
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/step.d.ts +1 -0
- package/dist/workflows/step.d.ts.map +1 -1
- package/dist/workflows/types.d.ts +54 -2
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/utils.d.ts +20 -0
- package/dist/workflows/utils.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +108 -40
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +19 -27
- package/src/llm/model/provider-types.generated.d.ts +56 -7
- package/dist/chunk-22443P6A.cjs.map +0 -1
- package/dist/chunk-2ZVKF4HP.cjs.map +0 -1
- package/dist/chunk-4CDL2QJT.js.map +0 -1
- package/dist/chunk-7AHYOMHJ.js.map +0 -1
- package/dist/chunk-7CBEP2ZQ.js.map +0 -1
- package/dist/chunk-7PO6SEJF.js.map +0 -1
- package/dist/chunk-CB575O6L.cjs.map +0 -1
- package/dist/chunk-ECFXGXWO.cjs.map +0 -1
- package/dist/chunk-ET6UOTTU.cjs.map +0 -1
- package/dist/chunk-GGYKYORQ.cjs.map +0 -1
- package/dist/chunk-HDJFSJCK.js.map +0 -1
- package/dist/chunk-I4CXL4SR.js.map +0 -1
- package/dist/chunk-IQO7ANVS.cjs.map +0 -1
- package/dist/chunk-JPGVRWWL.js.map +0 -1
- package/dist/chunk-JV2KH24V.js.map +0 -1
- package/dist/chunk-JYYQQEBH.cjs.map +0 -1
- package/dist/chunk-LJFJTTZQ.cjs +0 -4
- package/dist/chunk-LWBQ4P4N.cjs.map +0 -1
- package/dist/chunk-MV7KHWUT.js.map +0 -1
- package/dist/chunk-QUKUN6NR.cjs.map +0 -1
- package/dist/chunk-SNPVZPLB.js.map +0 -1
- package/dist/chunk-UIZSWUKP.js.map +0 -1
- package/dist/chunk-W7UH2PWL.js.map +0 -1
- package/dist/chunk-WM6CK2F3.cjs.map +0 -1
- package/dist/chunk-YCVEJ3UN.cjs.map +0 -1
- package/dist/chunk-ZGHTOYHW.js.map +0 -1
- package/dist/chunk-ZV5CC35D.js +0 -3
- package/dist/chunk-ZWNI5IWX.cjs.map +0 -1
- package/dist/models-dev-DNBKXHT4.js +0 -3
- package/dist/models-dev-YBEEQIX6.cjs +0 -12
- package/dist/netlify-7G2L5VSH.js +0 -3
- package/dist/netlify-GWNGSIRZ.cjs +0 -12
- package/dist/registry-generator-H4YNODDH.js.map +0 -1
- package/dist/registry-generator-MK63POJO.cjs.map +0 -1
|
@@ -195,7 +195,7 @@ function convertImageFilePart(part, downloadedAssets) {
|
|
|
195
195
|
const { data: convertedData, mediaType: convertedMediaType } = convertToDataContent(originalData);
|
|
196
196
|
let mediaType = convertedMediaType ?? part.mediaType;
|
|
197
197
|
let data = convertedData;
|
|
198
|
-
if (data instanceof URL) {
|
|
198
|
+
if (data instanceof URL && downloadedAssets) {
|
|
199
199
|
const downloadedFile = downloadedAssets[data.toString()];
|
|
200
200
|
if (downloadedFile) {
|
|
201
201
|
data = downloadedFile.data;
|
|
@@ -697,18 +697,20 @@ async function downloadAssetsFromMessages({
|
|
|
697
697
|
}
|
|
698
698
|
}
|
|
699
699
|
return { mediaType, data };
|
|
700
|
-
}).filter((part) => part.data instanceof URL).map((part) =>
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
700
|
+
}).filter((part) => part.data instanceof URL).map((part) => {
|
|
701
|
+
return {
|
|
702
|
+
url: part.data,
|
|
703
|
+
isUrlSupportedByModel: part.mediaType != null && providerUtilsV5.isUrlSupported({
|
|
704
|
+
url: part.data.toString(),
|
|
705
|
+
mediaType: part.mediaType,
|
|
706
|
+
supportedUrls: supportedUrls ?? {}
|
|
707
|
+
})
|
|
708
|
+
};
|
|
709
|
+
});
|
|
708
710
|
const downloadedFiles = await pMap(
|
|
709
711
|
filesToDownload,
|
|
710
712
|
async (fileItem) => {
|
|
711
|
-
if (
|
|
713
|
+
if (fileItem.isUrlSupportedByModel) {
|
|
712
714
|
return null;
|
|
713
715
|
}
|
|
714
716
|
return {
|
|
@@ -1063,7 +1065,10 @@ var MessageList = class _MessageList {
|
|
|
1063
1065
|
supportedUrls: options?.supportedUrls
|
|
1064
1066
|
});
|
|
1065
1067
|
let messages = [...systemMessages, ...modelMessages];
|
|
1066
|
-
|
|
1068
|
+
const hasImageOrFileContent = modelMessages.some(
|
|
1069
|
+
(message) => message.role === "user" && typeof message.content !== "string" && message.content.some((part) => part.type === "image" || part.type === "file")
|
|
1070
|
+
);
|
|
1071
|
+
if (hasImageOrFileContent) {
|
|
1067
1072
|
messages = messages.map((message) => {
|
|
1068
1073
|
if (message.role === "user") {
|
|
1069
1074
|
if (typeof message.content === "string") {
|
|
@@ -1875,6 +1880,12 @@ var MessageList = class _MessageList {
|
|
|
1875
1880
|
return ti;
|
|
1876
1881
|
});
|
|
1877
1882
|
}
|
|
1883
|
+
if (!message.threadId && this.memoryInfo?.threadId) {
|
|
1884
|
+
message.threadId = this.memoryInfo.threadId;
|
|
1885
|
+
if (!message.resourceId && this.memoryInfo?.resourceId) {
|
|
1886
|
+
message.resourceId = this.memoryInfo.resourceId;
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1878
1889
|
return message;
|
|
1879
1890
|
}
|
|
1880
1891
|
aiV4UIMessageToMastraDBMessage(message, messageSource) {
|
|
@@ -1912,137 +1923,180 @@ var MessageList = class _MessageList {
|
|
|
1912
1923
|
if (typeof coreMessage.content === "string") {
|
|
1913
1924
|
parts.push({
|
|
1914
1925
|
type: "text",
|
|
1915
|
-
text: coreMessage.content
|
|
1916
|
-
// Preserve providerOptions from CoreMessage (e.g., for system messages with cacheControl)
|
|
1917
|
-
..."providerOptions" in coreMessage && coreMessage.providerOptions ? { providerMetadata: coreMessage.providerOptions } : {}
|
|
1926
|
+
text: coreMessage.content
|
|
1918
1927
|
});
|
|
1919
1928
|
} else if (Array.isArray(coreMessage.content)) {
|
|
1920
|
-
for (const
|
|
1921
|
-
switch (
|
|
1922
|
-
case "text":
|
|
1929
|
+
for (const aiV4Part of coreMessage.content) {
|
|
1930
|
+
switch (aiV4Part.type) {
|
|
1931
|
+
case "text": {
|
|
1923
1932
|
const prevPart = parts.at(-1);
|
|
1924
1933
|
if (coreMessage.role === "assistant" && prevPart && prevPart.type === "tool-invocation") {
|
|
1925
1934
|
parts.push({ type: "step-start" });
|
|
1926
1935
|
}
|
|
1927
|
-
const
|
|
1928
|
-
..."providerOptions" in coreMessage && coreMessage.providerOptions ? coreMessage.providerOptions : {},
|
|
1929
|
-
..."providerOptions" in part && part.providerOptions ? part.providerOptions : {}
|
|
1930
|
-
};
|
|
1931
|
-
parts.push({
|
|
1936
|
+
const part = {
|
|
1932
1937
|
type: "text",
|
|
1933
|
-
text:
|
|
1934
|
-
|
|
1935
|
-
|
|
1938
|
+
text: aiV4Part.text
|
|
1939
|
+
};
|
|
1940
|
+
if (aiV4Part.providerOptions) {
|
|
1941
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
1942
|
+
}
|
|
1943
|
+
parts.push(part);
|
|
1936
1944
|
break;
|
|
1937
|
-
|
|
1938
|
-
|
|
1945
|
+
}
|
|
1946
|
+
case "tool-call": {
|
|
1947
|
+
const part = {
|
|
1939
1948
|
type: "tool-invocation",
|
|
1940
1949
|
toolInvocation: {
|
|
1941
1950
|
state: "call",
|
|
1942
|
-
toolCallId:
|
|
1943
|
-
toolName:
|
|
1944
|
-
args:
|
|
1951
|
+
toolCallId: aiV4Part.toolCallId,
|
|
1952
|
+
toolName: aiV4Part.toolName,
|
|
1953
|
+
args: aiV4Part.args
|
|
1945
1954
|
}
|
|
1946
|
-
}
|
|
1955
|
+
};
|
|
1956
|
+
if (aiV4Part.providerOptions) {
|
|
1957
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
1958
|
+
}
|
|
1959
|
+
parts.push(part);
|
|
1947
1960
|
break;
|
|
1961
|
+
}
|
|
1948
1962
|
case "tool-result":
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1963
|
+
{
|
|
1964
|
+
let toolArgs = {};
|
|
1965
|
+
const toolCallInSameMsg = coreMessage.content.find(
|
|
1966
|
+
(p) => p.type === "tool-call" && p.toolCallId === aiV4Part.toolCallId
|
|
1967
|
+
);
|
|
1968
|
+
if (toolCallInSameMsg && toolCallInSameMsg.type === "tool-call") {
|
|
1969
|
+
toolArgs = toolCallInSameMsg.args;
|
|
1970
|
+
}
|
|
1971
|
+
if (Object.keys(toolArgs).length === 0) {
|
|
1972
|
+
for (let i = this.messages.length - 1; i >= 0; i--) {
|
|
1973
|
+
const msg = this.messages[i];
|
|
1974
|
+
if (msg && msg.role === "assistant" && msg.content.parts) {
|
|
1975
|
+
const toolCallPart = msg.content.parts.find(
|
|
1976
|
+
(p) => p.type === "tool-invocation" && p.toolInvocation.toolCallId === aiV4Part.toolCallId && p.toolInvocation.state === "call"
|
|
1977
|
+
);
|
|
1978
|
+
if (toolCallPart && toolCallPart.type === "tool-invocation" && toolCallPart.toolInvocation.args) {
|
|
1979
|
+
toolArgs = toolCallPart.toolInvocation.args;
|
|
1980
|
+
break;
|
|
1981
|
+
}
|
|
1966
1982
|
}
|
|
1967
1983
|
}
|
|
1968
1984
|
}
|
|
1985
|
+
const invocation = {
|
|
1986
|
+
state: "result",
|
|
1987
|
+
toolCallId: aiV4Part.toolCallId,
|
|
1988
|
+
toolName: aiV4Part.toolName,
|
|
1989
|
+
result: aiV4Part.result ?? "",
|
|
1990
|
+
// undefined will cause AI SDK to throw an error, but for client side tool calls this really could be undefined
|
|
1991
|
+
args: toolArgs
|
|
1992
|
+
// Use the args from the corresponding tool-call
|
|
1993
|
+
};
|
|
1994
|
+
const part = {
|
|
1995
|
+
type: "tool-invocation",
|
|
1996
|
+
toolInvocation: invocation
|
|
1997
|
+
};
|
|
1998
|
+
if (aiV4Part.providerOptions) {
|
|
1999
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2000
|
+
}
|
|
2001
|
+
parts.push(part);
|
|
2002
|
+
toolInvocations.push(invocation);
|
|
1969
2003
|
}
|
|
1970
|
-
const invocation = {
|
|
1971
|
-
state: "result",
|
|
1972
|
-
toolCallId: part.toolCallId,
|
|
1973
|
-
toolName: part.toolName,
|
|
1974
|
-
result: part.result ?? "",
|
|
1975
|
-
// undefined will cause AI SDK to throw an error, but for client side tool calls this really could be undefined
|
|
1976
|
-
args: toolArgs
|
|
1977
|
-
// Use the args from the corresponding tool-call
|
|
1978
|
-
};
|
|
1979
|
-
parts.push({
|
|
1980
|
-
type: "tool-invocation",
|
|
1981
|
-
toolInvocation: invocation
|
|
1982
|
-
});
|
|
1983
|
-
toolInvocations.push(invocation);
|
|
1984
2004
|
break;
|
|
1985
2005
|
case "reasoning":
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
2006
|
+
{
|
|
2007
|
+
const part = {
|
|
2008
|
+
type: "reasoning",
|
|
2009
|
+
reasoning: "",
|
|
2010
|
+
// leave this blank so we aren't double storing it in the db along with details
|
|
2011
|
+
details: [{ type: "text", text: aiV4Part.text, signature: aiV4Part.signature }]
|
|
2012
|
+
};
|
|
2013
|
+
if (aiV4Part.providerOptions) {
|
|
2014
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2015
|
+
}
|
|
2016
|
+
parts.push(part);
|
|
2017
|
+
}
|
|
1992
2018
|
break;
|
|
1993
2019
|
case "redacted-reasoning":
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2020
|
+
{
|
|
2021
|
+
const part = {
|
|
2022
|
+
type: "reasoning",
|
|
2023
|
+
reasoning: "",
|
|
2024
|
+
// No text reasoning for redacted parts
|
|
2025
|
+
details: [{ type: "redacted", data: aiV4Part.data }]
|
|
2026
|
+
};
|
|
2027
|
+
if (aiV4Part.providerOptions) {
|
|
2028
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2029
|
+
}
|
|
2030
|
+
parts.push(part);
|
|
2031
|
+
}
|
|
2000
2032
|
break;
|
|
2001
|
-
case "image":
|
|
2002
|
-
|
|
2033
|
+
case "image": {
|
|
2034
|
+
const part = {
|
|
2003
2035
|
type: "file",
|
|
2004
|
-
data: imageContentToString(
|
|
2005
|
-
mimeType:
|
|
2006
|
-
}
|
|
2036
|
+
data: imageContentToString(aiV4Part.image),
|
|
2037
|
+
mimeType: aiV4Part.mimeType
|
|
2038
|
+
};
|
|
2039
|
+
if (aiV4Part.providerOptions) {
|
|
2040
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2041
|
+
}
|
|
2042
|
+
parts.push(part);
|
|
2007
2043
|
break;
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2044
|
+
}
|
|
2045
|
+
case "file": {
|
|
2046
|
+
if (aiV4Part.data instanceof URL) {
|
|
2047
|
+
const part = {
|
|
2011
2048
|
type: "file",
|
|
2012
|
-
data:
|
|
2013
|
-
mimeType:
|
|
2014
|
-
}
|
|
2015
|
-
|
|
2016
|
-
|
|
2049
|
+
data: aiV4Part.data.toString(),
|
|
2050
|
+
mimeType: aiV4Part.mimeType
|
|
2051
|
+
};
|
|
2052
|
+
if (aiV4Part.providerOptions) {
|
|
2053
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2054
|
+
}
|
|
2055
|
+
parts.push(part);
|
|
2056
|
+
} else if (typeof aiV4Part.data === "string") {
|
|
2057
|
+
const categorized = categorizeFileData(aiV4Part.data, aiV4Part.mimeType);
|
|
2017
2058
|
if (categorized.type === "url" || categorized.type === "dataUri") {
|
|
2018
|
-
|
|
2059
|
+
const part = {
|
|
2019
2060
|
type: "file",
|
|
2020
|
-
data:
|
|
2061
|
+
data: aiV4Part.data,
|
|
2021
2062
|
mimeType: categorized.mimeType || "image/png"
|
|
2022
|
-
}
|
|
2063
|
+
};
|
|
2064
|
+
if (aiV4Part.providerOptions) {
|
|
2065
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2066
|
+
}
|
|
2067
|
+
parts.push(part);
|
|
2023
2068
|
} else {
|
|
2024
2069
|
try {
|
|
2025
|
-
|
|
2070
|
+
const part = {
|
|
2026
2071
|
type: "file",
|
|
2027
2072
|
mimeType: categorized.mimeType || "image/png",
|
|
2028
|
-
data: convertDataContentToBase64String(
|
|
2029
|
-
}
|
|
2073
|
+
data: convertDataContentToBase64String(aiV4Part.data)
|
|
2074
|
+
};
|
|
2075
|
+
if (aiV4Part.providerOptions) {
|
|
2076
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2077
|
+
}
|
|
2078
|
+
parts.push(part);
|
|
2030
2079
|
} catch (error) {
|
|
2031
2080
|
console.error(`Failed to convert binary data to base64 in CoreMessage file part: ${error}`, error);
|
|
2032
2081
|
}
|
|
2033
2082
|
}
|
|
2034
2083
|
} else {
|
|
2035
2084
|
try {
|
|
2036
|
-
|
|
2085
|
+
const part = {
|
|
2037
2086
|
type: "file",
|
|
2038
|
-
mimeType:
|
|
2039
|
-
data: convertDataContentToBase64String(
|
|
2040
|
-
}
|
|
2087
|
+
mimeType: aiV4Part.mimeType,
|
|
2088
|
+
data: convertDataContentToBase64String(aiV4Part.data)
|
|
2089
|
+
};
|
|
2090
|
+
if (aiV4Part.providerOptions) {
|
|
2091
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2092
|
+
}
|
|
2093
|
+
parts.push(part);
|
|
2041
2094
|
} catch (error) {
|
|
2042
2095
|
console.error(`Failed to convert binary data to base64 in CoreMessage file part: ${error}`, error);
|
|
2043
2096
|
}
|
|
2044
2097
|
}
|
|
2045
2098
|
break;
|
|
2099
|
+
}
|
|
2046
2100
|
}
|
|
2047
2101
|
}
|
|
2048
2102
|
}
|
|
@@ -2053,6 +2107,9 @@ var MessageList = class _MessageList {
|
|
|
2053
2107
|
if (toolInvocations.length) content.toolInvocations = toolInvocations;
|
|
2054
2108
|
if (typeof coreMessage.content === `string`) content.content = coreMessage.content;
|
|
2055
2109
|
if (experimentalAttachments.length) content.experimental_attachments = experimentalAttachments;
|
|
2110
|
+
if (coreMessage.providerOptions) {
|
|
2111
|
+
content.providerMetadata = coreMessage.providerOptions;
|
|
2112
|
+
}
|
|
2056
2113
|
return {
|
|
2057
2114
|
id,
|
|
2058
2115
|
role: _MessageList.getRole(coreMessage),
|
|
@@ -2403,6 +2460,9 @@ var MessageList = class _MessageList {
|
|
|
2403
2460
|
if (dbMsg.createdAt) metadata.createdAt = dbMsg.createdAt;
|
|
2404
2461
|
if (dbMsg.threadId) metadata.threadId = dbMsg.threadId;
|
|
2405
2462
|
if (dbMsg.resourceId) metadata.resourceId = dbMsg.resourceId;
|
|
2463
|
+
if (dbMsg.content.providerMetadata) {
|
|
2464
|
+
metadata.providerMetadata = dbMsg.content.providerMetadata;
|
|
2465
|
+
}
|
|
2406
2466
|
const hasToolInvocationParts = dbMsg.content.parts?.some((p) => p.type === "tool-invocation");
|
|
2407
2467
|
if (dbMsg.content.toolInvocations && !hasToolInvocationParts) {
|
|
2408
2468
|
for (const invocation of dbMsg.content.toolInvocations) {
|
|
@@ -2469,18 +2529,20 @@ var MessageList = class _MessageList {
|
|
|
2469
2529
|
continue;
|
|
2470
2530
|
}
|
|
2471
2531
|
if (part.type === "reasoning") {
|
|
2472
|
-
const
|
|
2473
|
-
const text = reasoningPart.text || reasoningPart.reasoning || (reasoningPart.details?.reduce((p, c) => {
|
|
2532
|
+
const text = part.reasoning || (part.details?.reduce((p, c) => {
|
|
2474
2533
|
if (c.type === `text` && c.text) return p + c.text;
|
|
2475
2534
|
return p;
|
|
2476
2535
|
}, "") ?? "");
|
|
2477
|
-
if (text ||
|
|
2478
|
-
|
|
2536
|
+
if (text || part.details?.length) {
|
|
2537
|
+
const v5UIPart = {
|
|
2479
2538
|
type: "reasoning",
|
|
2480
2539
|
text: text || "",
|
|
2481
|
-
state: "done"
|
|
2482
|
-
|
|
2483
|
-
|
|
2540
|
+
state: "done"
|
|
2541
|
+
};
|
|
2542
|
+
if (part.providerMetadata) {
|
|
2543
|
+
v5UIPart.providerMetadata = part.providerMetadata;
|
|
2544
|
+
}
|
|
2545
|
+
parts.push(v5UIPart);
|
|
2484
2546
|
}
|
|
2485
2547
|
continue;
|
|
2486
2548
|
}
|
|
@@ -2493,12 +2555,15 @@ var MessageList = class _MessageList {
|
|
|
2493
2555
|
}
|
|
2494
2556
|
const categorized = typeof part.data === "string" ? categorizeFileData(part.data, part.mimeType) : { type: "raw", mimeType: part.mimeType};
|
|
2495
2557
|
if (categorized.type === "url" && typeof part.data === "string") {
|
|
2496
|
-
|
|
2558
|
+
const v5UIPart = {
|
|
2497
2559
|
type: "file",
|
|
2498
2560
|
url: part.data,
|
|
2499
|
-
mediaType: categorized.mimeType || "image/png"
|
|
2500
|
-
|
|
2501
|
-
|
|
2561
|
+
mediaType: categorized.mimeType || "image/png"
|
|
2562
|
+
};
|
|
2563
|
+
if (part.providerMetadata) {
|
|
2564
|
+
v5UIPart.providerMetadata = part.providerMetadata;
|
|
2565
|
+
}
|
|
2566
|
+
parts.push(v5UIPart);
|
|
2502
2567
|
} else {
|
|
2503
2568
|
let filePartData;
|
|
2504
2569
|
let extractedMimeType = part.mimeType;
|
|
@@ -2522,27 +2587,37 @@ var MessageList = class _MessageList {
|
|
|
2522
2587
|
} else {
|
|
2523
2588
|
dataUri = createDataUri(filePartData, finalMimeType);
|
|
2524
2589
|
}
|
|
2525
|
-
|
|
2590
|
+
const v5UIPart = {
|
|
2526
2591
|
type: "file",
|
|
2527
2592
|
url: dataUri,
|
|
2528
2593
|
// Use url field with data URI
|
|
2529
|
-
mediaType: finalMimeType
|
|
2530
|
-
|
|
2531
|
-
|
|
2594
|
+
mediaType: finalMimeType
|
|
2595
|
+
};
|
|
2596
|
+
if (part.providerMetadata) {
|
|
2597
|
+
v5UIPart.providerMetadata = part.providerMetadata;
|
|
2598
|
+
}
|
|
2599
|
+
parts.push(v5UIPart);
|
|
2532
2600
|
}
|
|
2533
2601
|
} else if (part.type === "source") {
|
|
2534
|
-
const
|
|
2535
|
-
parts.push({
|
|
2602
|
+
const v5UIPart = {
|
|
2536
2603
|
type: "source-url",
|
|
2537
|
-
url:
|
|
2538
|
-
|
|
2539
|
-
|
|
2604
|
+
url: part.source.url,
|
|
2605
|
+
sourceId: part.source.id,
|
|
2606
|
+
title: part.source.title
|
|
2607
|
+
};
|
|
2608
|
+
if (part.providerMetadata) {
|
|
2609
|
+
v5UIPart.providerMetadata = part.providerMetadata;
|
|
2610
|
+
}
|
|
2611
|
+
parts.push(v5UIPart);
|
|
2540
2612
|
} else if (part.type === "text") {
|
|
2541
|
-
|
|
2613
|
+
const v5UIPart = {
|
|
2542
2614
|
type: "text",
|
|
2543
|
-
text: part.text
|
|
2544
|
-
|
|
2545
|
-
|
|
2615
|
+
text: part.text
|
|
2616
|
+
};
|
|
2617
|
+
if (part.providerMetadata) {
|
|
2618
|
+
v5UIPart.providerMetadata = part.providerMetadata;
|
|
2619
|
+
}
|
|
2620
|
+
parts.push(v5UIPart);
|
|
2546
2621
|
hasNonToolReasoningParts = true;
|
|
2547
2622
|
} else {
|
|
2548
2623
|
parts.push(part);
|
|
@@ -2706,32 +2781,69 @@ var MessageList = class _MessageList {
|
|
|
2706
2781
|
}
|
|
2707
2782
|
};
|
|
2708
2783
|
}
|
|
2784
|
+
/**
|
|
2785
|
+
* Convert image or file to data URI or URL for V2 file part
|
|
2786
|
+
*/
|
|
2787
|
+
static getDataStringFromAIV5DataPart = (part) => {
|
|
2788
|
+
let mimeType;
|
|
2789
|
+
let data;
|
|
2790
|
+
if ("data" in part) {
|
|
2791
|
+
mimeType = part.mediaType || "application/octet-stream";
|
|
2792
|
+
data = part.data;
|
|
2793
|
+
} else if ("image" in part) {
|
|
2794
|
+
mimeType = part.mediaType || "image/jpeg";
|
|
2795
|
+
data = part.image;
|
|
2796
|
+
} else {
|
|
2797
|
+
throw new chunkTWH4PTDG_cjs.MastraError({
|
|
2798
|
+
id: "MASTRA_AIV5_DATA_PART_INVALID",
|
|
2799
|
+
domain: "AGENT" /* AGENT */,
|
|
2800
|
+
category: "USER" /* USER */,
|
|
2801
|
+
text: "Invalid AIV5 data part in getDataStringFromAIV5DataPart",
|
|
2802
|
+
details: {
|
|
2803
|
+
part
|
|
2804
|
+
}
|
|
2805
|
+
});
|
|
2806
|
+
}
|
|
2807
|
+
if (data instanceof URL) {
|
|
2808
|
+
return data.toString();
|
|
2809
|
+
} else {
|
|
2810
|
+
if (data instanceof Buffer) {
|
|
2811
|
+
const base64 = data.toString("base64");
|
|
2812
|
+
return `data:${mimeType};base64,${base64}`;
|
|
2813
|
+
} else if (typeof data === "string") {
|
|
2814
|
+
return data.startsWith("data:") || data.startsWith("http") ? data : `data:${mimeType};base64,${data}`;
|
|
2815
|
+
} else if (data instanceof Uint8Array) {
|
|
2816
|
+
const base64 = Buffer.from(data).toString("base64");
|
|
2817
|
+
return `data:${mimeType};base64,${base64}`;
|
|
2818
|
+
} else if (data instanceof ArrayBuffer) {
|
|
2819
|
+
const base64 = Buffer.from(data).toString("base64");
|
|
2820
|
+
return `data:${mimeType};base64,${base64}`;
|
|
2821
|
+
} else {
|
|
2822
|
+
return "";
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
};
|
|
2709
2826
|
/**
|
|
2710
2827
|
* Direct conversion from AIV5 ModelMessage to MastraDBMessage
|
|
2711
2828
|
* Combines logic from aiV5ModelMessageToMastraMessageV3 + mastraMessageV3ToV2
|
|
2712
2829
|
*/
|
|
2713
2830
|
static aiV5ModelMessageToMastraDBMessage(modelMsg, _messageSource) {
|
|
2714
2831
|
const content = Array.isArray(modelMsg.content) ? modelMsg.content : [{ type: "text", text: modelMsg.content }];
|
|
2715
|
-
const
|
|
2832
|
+
const mastraDBParts = [];
|
|
2716
2833
|
const toolInvocations = [];
|
|
2717
2834
|
const reasoningParts = [];
|
|
2718
2835
|
const experimental_attachments = [];
|
|
2719
|
-
const textParts = [];
|
|
2720
2836
|
let lastPartWasToolResult = false;
|
|
2721
2837
|
for (const part of content) {
|
|
2722
|
-
const providerMetadata = {
|
|
2723
|
-
...modelMsg.providerMetadata || {},
|
|
2724
|
-
...part.providerMetadata || {}
|
|
2725
|
-
};
|
|
2726
|
-
const hasProviderMetadata = Object.keys(providerMetadata).length > 0;
|
|
2727
2838
|
if (part.type === "text") {
|
|
2728
2839
|
const textPart = {
|
|
2729
2840
|
type: "text",
|
|
2730
|
-
text: part.text
|
|
2731
|
-
...hasProviderMetadata && { experimental_providerMetadata: providerMetadata }
|
|
2841
|
+
text: part.text
|
|
2732
2842
|
};
|
|
2733
|
-
|
|
2734
|
-
|
|
2843
|
+
if (part.providerOptions) {
|
|
2844
|
+
textPart.providerMetadata = part.providerOptions;
|
|
2845
|
+
}
|
|
2846
|
+
mastraDBParts.push(textPart);
|
|
2735
2847
|
lastPartWasToolResult = false;
|
|
2736
2848
|
} else if (part.type === "tool-call") {
|
|
2737
2849
|
const toolCallPart = part;
|
|
@@ -2742,10 +2854,12 @@ var MessageList = class _MessageList {
|
|
|
2742
2854
|
toolName: toolCallPart.toolName,
|
|
2743
2855
|
args: toolCallPart.input,
|
|
2744
2856
|
state: "call"
|
|
2745
|
-
}
|
|
2746
|
-
...hasProviderMetadata && { providerMetadata }
|
|
2857
|
+
}
|
|
2747
2858
|
};
|
|
2748
|
-
|
|
2859
|
+
if (part.providerOptions) {
|
|
2860
|
+
toolInvocationPart.providerMetadata = part.providerOptions;
|
|
2861
|
+
}
|
|
2862
|
+
mastraDBParts.push(toolInvocationPart);
|
|
2749
2863
|
toolInvocations.push({
|
|
2750
2864
|
toolCallId: toolCallPart.toolCallId,
|
|
2751
2865
|
toolName: toolCallPart.toolName,
|
|
@@ -2756,78 +2870,67 @@ var MessageList = class _MessageList {
|
|
|
2756
2870
|
} else if (part.type === "tool-result") {
|
|
2757
2871
|
const toolResultPart = part;
|
|
2758
2872
|
const matchingCall = toolInvocations.find((inv) => inv.toolCallId === toolResultPart.toolCallId);
|
|
2759
|
-
const matchingV2Part =
|
|
2873
|
+
const matchingV2Part = mastraDBParts.find(
|
|
2760
2874
|
(p) => p.type === "tool-invocation" && "toolInvocation" in p && p.toolInvocation.toolCallId === toolResultPart.toolCallId
|
|
2761
2875
|
);
|
|
2876
|
+
const updateMatchingCallInvocationResult = (toolResultPart2, matchingCall2) => {
|
|
2877
|
+
matchingCall2.state = "result";
|
|
2878
|
+
matchingCall2.result = typeof toolResultPart2.output === "object" && toolResultPart2.output && "value" in toolResultPart2.output ? toolResultPart2.output.value : toolResultPart2.output;
|
|
2879
|
+
};
|
|
2762
2880
|
if (matchingCall) {
|
|
2763
|
-
matchingCall
|
|
2764
|
-
matchingCall.result = typeof toolResultPart.output === "object" && toolResultPart.output && "value" in toolResultPart.output ? toolResultPart.output.value : toolResultPart.output;
|
|
2881
|
+
updateMatchingCallInvocationResult(toolResultPart, matchingCall);
|
|
2765
2882
|
} else {
|
|
2766
|
-
const
|
|
2767
|
-
|
|
2883
|
+
const call = {
|
|
2884
|
+
state: "call",
|
|
2768
2885
|
toolCallId: toolResultPart.toolCallId,
|
|
2769
|
-
toolName:
|
|
2770
|
-
args: {}
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2886
|
+
toolName: toolResultPart.toolName || "unknown",
|
|
2887
|
+
args: {}
|
|
2888
|
+
};
|
|
2889
|
+
updateMatchingCallInvocationResult(toolResultPart, call);
|
|
2890
|
+
toolInvocations.push(call);
|
|
2774
2891
|
}
|
|
2775
2892
|
if (matchingV2Part && matchingV2Part.type === "tool-invocation") {
|
|
2776
|
-
matchingV2Part.toolInvocation
|
|
2777
|
-
matchingV2Part.toolInvocation.result = typeof toolResultPart.output === "object" && toolResultPart.output && "value" in toolResultPart.output ? toolResultPart.output.value : toolResultPart.output;
|
|
2778
|
-
if (hasProviderMetadata) {
|
|
2779
|
-
matchingV2Part.providerMetadata = providerMetadata;
|
|
2780
|
-
}
|
|
2893
|
+
updateMatchingCallInvocationResult(toolResultPart, matchingV2Part.toolInvocation);
|
|
2781
2894
|
} else {
|
|
2782
|
-
const resultPartWithName = toolResultPart;
|
|
2783
2895
|
const toolInvocationPart = {
|
|
2784
2896
|
type: "tool-invocation",
|
|
2785
2897
|
toolInvocation: {
|
|
2786
2898
|
toolCallId: toolResultPart.toolCallId,
|
|
2787
|
-
toolName:
|
|
2899
|
+
toolName: toolResultPart.toolName || "unknown",
|
|
2788
2900
|
args: {},
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
},
|
|
2792
|
-
...hasProviderMetadata && { providerMetadata }
|
|
2901
|
+
state: "call"
|
|
2902
|
+
}
|
|
2793
2903
|
};
|
|
2794
|
-
|
|
2904
|
+
updateMatchingCallInvocationResult(toolResultPart, toolInvocationPart.toolInvocation);
|
|
2905
|
+
mastraDBParts.push(toolInvocationPart);
|
|
2795
2906
|
}
|
|
2796
2907
|
lastPartWasToolResult = true;
|
|
2797
2908
|
} else if (part.type === "reasoning") {
|
|
2798
|
-
const reasoningPart = part;
|
|
2799
2909
|
const v2ReasoningPart = {
|
|
2800
2910
|
type: "reasoning",
|
|
2801
|
-
reasoning:
|
|
2802
|
-
|
|
2803
|
-
|
|
2911
|
+
reasoning: "",
|
|
2912
|
+
// leave this blank so we aren't double storing it in the db along with details
|
|
2913
|
+
details: [{ type: "text", text: part.text }]
|
|
2804
2914
|
};
|
|
2805
|
-
|
|
2806
|
-
|
|
2915
|
+
if (part.providerOptions) {
|
|
2916
|
+
v2ReasoningPart.providerMetadata = part.providerOptions;
|
|
2917
|
+
}
|
|
2918
|
+
mastraDBParts.push(v2ReasoningPart);
|
|
2919
|
+
reasoningParts.push(part.text);
|
|
2807
2920
|
lastPartWasToolResult = false;
|
|
2808
2921
|
} else if (part.type === "image") {
|
|
2809
2922
|
const imagePart = part;
|
|
2810
|
-
|
|
2811
|
-
const
|
|
2812
|
-
if ("url" in imagePart && typeof imagePart.url === "string") {
|
|
2813
|
-
imageData = imagePart.url;
|
|
2814
|
-
} else if ("data" in imagePart) {
|
|
2815
|
-
if (typeof imagePart.data === "string") {
|
|
2816
|
-
imageData = imagePart.data.startsWith("data:") || imagePart.data.startsWith("http") ? imagePart.data : `data:${mimeType};base64,${imagePart.data}`;
|
|
2817
|
-
} else {
|
|
2818
|
-
const base64 = Buffer.from(imagePart.data).toString("base64");
|
|
2819
|
-
imageData = `data:${mimeType};base64,${base64}`;
|
|
2820
|
-
}
|
|
2821
|
-
} else {
|
|
2822
|
-
imageData = "";
|
|
2823
|
-
}
|
|
2923
|
+
const mimeType = imagePart.mediaType || "image/jpeg";
|
|
2924
|
+
const imageData = this.getDataStringFromAIV5DataPart(imagePart);
|
|
2824
2925
|
const imageFilePart = {
|
|
2825
2926
|
type: "file",
|
|
2826
2927
|
data: imageData,
|
|
2827
|
-
mimeType
|
|
2828
|
-
...hasProviderMetadata && { providerMetadata }
|
|
2928
|
+
mimeType
|
|
2829
2929
|
};
|
|
2830
|
-
|
|
2930
|
+
if (part.providerOptions) {
|
|
2931
|
+
imageFilePart.providerMetadata = part.providerOptions;
|
|
2932
|
+
}
|
|
2933
|
+
mastraDBParts.push(imageFilePart);
|
|
2831
2934
|
experimental_attachments.push({
|
|
2832
2935
|
url: imageData,
|
|
2833
2936
|
contentType: mimeType
|
|
@@ -2836,26 +2939,16 @@ var MessageList = class _MessageList {
|
|
|
2836
2939
|
} else if (part.type === "file") {
|
|
2837
2940
|
const filePart = part;
|
|
2838
2941
|
const mimeType = filePart.mediaType || "application/octet-stream";
|
|
2839
|
-
|
|
2840
|
-
if ("url" in filePart && typeof filePart.url === "string") {
|
|
2841
|
-
fileData = filePart.url;
|
|
2842
|
-
} else if ("data" in filePart) {
|
|
2843
|
-
if (typeof filePart.data === "string") {
|
|
2844
|
-
fileData = filePart.data.startsWith("data:") || filePart.data.startsWith("http") ? filePart.data : `data:${mimeType};base64,${filePart.data}`;
|
|
2845
|
-
} else {
|
|
2846
|
-
const base64 = Buffer.from(filePart.data).toString("base64");
|
|
2847
|
-
fileData = `data:${mimeType};base64,${base64}`;
|
|
2848
|
-
}
|
|
2849
|
-
} else {
|
|
2850
|
-
fileData = "";
|
|
2851
|
-
}
|
|
2942
|
+
const fileData = this.getDataStringFromAIV5DataPart(filePart);
|
|
2852
2943
|
const v2FilePart = {
|
|
2853
2944
|
type: "file",
|
|
2854
2945
|
data: fileData,
|
|
2855
|
-
mimeType
|
|
2856
|
-
...hasProviderMetadata && { providerMetadata }
|
|
2946
|
+
mimeType
|
|
2857
2947
|
};
|
|
2858
|
-
|
|
2948
|
+
if (part.providerOptions) {
|
|
2949
|
+
v2FilePart.providerMetadata = part.providerOptions;
|
|
2950
|
+
}
|
|
2951
|
+
mastraDBParts.push(v2FilePart);
|
|
2859
2952
|
experimental_attachments.push({
|
|
2860
2953
|
url: fileData,
|
|
2861
2954
|
contentType: mimeType
|
|
@@ -2863,34 +2956,34 @@ var MessageList = class _MessageList {
|
|
|
2863
2956
|
lastPartWasToolResult = false;
|
|
2864
2957
|
}
|
|
2865
2958
|
}
|
|
2866
|
-
if (modelMsg.role === "assistant" && lastPartWasToolResult &&
|
|
2867
|
-
const lastPart =
|
|
2959
|
+
if (modelMsg.role === "assistant" && lastPartWasToolResult && mastraDBParts.length > 0) {
|
|
2960
|
+
const lastPart = mastraDBParts[mastraDBParts.length - 1];
|
|
2868
2961
|
if (lastPart && lastPart.type !== "text") {
|
|
2869
2962
|
const emptyTextPart = { type: "text", text: "" };
|
|
2870
|
-
|
|
2871
|
-
textParts.push({ text: "" });
|
|
2963
|
+
mastraDBParts.push(emptyTextPart);
|
|
2872
2964
|
}
|
|
2873
2965
|
}
|
|
2874
|
-
|
|
2875
|
-
if (textParts.length > 0) {
|
|
2876
|
-
contentString = textParts.map((p) => p.text).join("\n");
|
|
2877
|
-
}
|
|
2966
|
+
const contentString = mastraDBParts.filter((p) => p.type === "text").map((p) => p.text).join("\n");
|
|
2878
2967
|
const metadata = {};
|
|
2879
2968
|
const id = `id` in modelMsg && typeof modelMsg.id === `string` ? modelMsg.id : `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
2880
|
-
|
|
2969
|
+
const message = {
|
|
2881
2970
|
id,
|
|
2882
2971
|
role: _MessageList.getRole(modelMsg),
|
|
2883
2972
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2884
2973
|
content: {
|
|
2885
2974
|
format: 2,
|
|
2886
|
-
parts:
|
|
2975
|
+
parts: mastraDBParts,
|
|
2887
2976
|
toolInvocations: toolInvocations.length > 0 ? toolInvocations : void 0,
|
|
2888
2977
|
reasoning: reasoningParts.length > 0 ? reasoningParts.join("\n") : void 0,
|
|
2889
2978
|
experimental_attachments: experimental_attachments.length > 0 ? experimental_attachments : void 0,
|
|
2890
|
-
content: contentString,
|
|
2979
|
+
content: contentString || void 0,
|
|
2891
2980
|
metadata
|
|
2892
2981
|
}
|
|
2893
2982
|
};
|
|
2983
|
+
if (modelMsg.providerOptions) {
|
|
2984
|
+
message.content.providerMetadata = modelMsg.providerOptions;
|
|
2985
|
+
}
|
|
2986
|
+
return message;
|
|
2894
2987
|
}
|
|
2895
2988
|
aiV4CoreMessagesToAIV5ModelMessages(messages, source) {
|
|
2896
2989
|
return this.aiV5UIMessagesToAIV5ModelMessages(
|
|
@@ -2901,7 +2994,16 @@ var MessageList = class _MessageList {
|
|
|
2901
2994
|
const sanitized = this.sanitizeV5UIMessages(messages, filterIncompleteToolCalls);
|
|
2902
2995
|
const preprocessed = this.addStartStepPartsForAIV5(sanitized);
|
|
2903
2996
|
const result = AIV5__namespace.convertToModelMessages(preprocessed);
|
|
2904
|
-
return result
|
|
2997
|
+
return result.map((modelMsg, index) => {
|
|
2998
|
+
const uiMsg = preprocessed[index];
|
|
2999
|
+
if (uiMsg?.metadata && typeof uiMsg.metadata === "object" && "providerMetadata" in uiMsg.metadata && uiMsg.metadata.providerMetadata) {
|
|
3000
|
+
return {
|
|
3001
|
+
...modelMsg,
|
|
3002
|
+
providerOptions: uiMsg.metadata.providerMetadata
|
|
3003
|
+
};
|
|
3004
|
+
}
|
|
3005
|
+
return modelMsg;
|
|
3006
|
+
});
|
|
2905
3007
|
}
|
|
2906
3008
|
addStartStepPartsForAIV5(messages) {
|
|
2907
3009
|
for (const message of messages) {
|
|
@@ -3037,5 +3139,5 @@ exports.DefaultGeneratedFile = DefaultGeneratedFile;
|
|
|
3037
3139
|
exports.DefaultGeneratedFileWithType = DefaultGeneratedFileWithType;
|
|
3038
3140
|
exports.MessageList = MessageList;
|
|
3039
3141
|
exports.convertMessages = convertMessages;
|
|
3040
|
-
//# sourceMappingURL=chunk-
|
|
3041
|
-
//# sourceMappingURL=chunk-
|
|
3142
|
+
//# sourceMappingURL=chunk-VSM3NLUX.cjs.map
|
|
3143
|
+
//# sourceMappingURL=chunk-VSM3NLUX.cjs.map
|