@mastra/core 1.0.0-beta.1 → 1.0.0-beta.10
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 +1128 -0
- package/dist/agent/agent-legacy.d.ts +19 -22
- package/dist/agent/agent-legacy.d.ts.map +1 -1
- package/dist/agent/agent-types.test-d.d.ts +2 -0
- package/dist/agent/agent-types.test-d.d.ts.map +1 -0
- package/dist/agent/agent.d.ts +6 -6
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.types.d.ts +6 -4
- 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 +60 -3
- package/dist/agent/message-list/index.d.ts.map +1 -1
- package/dist/agent/message-list/index.js +1 -1
- package/dist/agent/message-list/prompt/attachments-to-parts.d.ts.map +1 -1
- package/dist/agent/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/save-queue/index.d.ts +3 -1
- package/dist/agent/save-queue/index.d.ts.map +1 -1
- package/dist/agent/test-utils.d.ts +37 -0
- package/dist/agent/test-utils.d.ts.map +1 -1
- package/dist/agent/trip-wire.d.ts.map +1 -1
- package/dist/agent/types.d.ts +21 -6
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/utils.d.ts +3 -3
- package/dist/agent/utils.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +9 -7
- package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts +3 -3
- 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 +6 -5
- 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/schema.d.ts +8 -8
- package/dist/agent/workflows/prepare-stream/schema.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts +11 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
- package/dist/base.cjs +2 -2
- package/dist/base.js +1 -1
- package/dist/bundler/index.cjs +2 -2
- package/dist/bundler/index.js +1 -1
- package/dist/cache/index.cjs +3 -3
- package/dist/cache/index.js +1 -1
- package/dist/{chunk-4CDL2QJT.js → chunk-267YOF47.js} +121 -36
- package/dist/chunk-267YOF47.js.map +1 -0
- package/dist/{chunk-OJNJA5ZI.js → chunk-3CKZSDTQ.js} +3 -3
- package/dist/{chunk-OJNJA5ZI.js.map → chunk-3CKZSDTQ.js.map} +1 -1
- package/dist/{chunk-JV2KH24V.js → chunk-3GKKHF36.js} +693 -375
- package/dist/chunk-3GKKHF36.js.map +1 -0
- package/dist/{chunk-TQTAMPSC.js → chunk-3N3QE4ZK.js} +3 -3
- package/dist/chunk-3N3QE4ZK.js.map +1 -0
- package/dist/{chunk-QUKUN6NR.cjs → chunk-4JKEUSCC.cjs} +107 -7
- package/dist/chunk-4JKEUSCC.cjs.map +1 -0
- package/dist/{chunk-XEVG546F.js → chunk-4Q3Z6QRE.js} +178 -12
- package/dist/chunk-4Q3Z6QRE.js.map +1 -0
- package/dist/{chunk-CBAB7GOD.cjs → chunk-6BJ7XHRH.cjs} +2 -2
- package/dist/{chunk-CBAB7GOD.cjs.map → chunk-6BJ7XHRH.cjs.map} +1 -1
- package/dist/{chunk-JUBFO5J3.js → chunk-6CYYFT4O.js} +11378 -8189
- package/dist/chunk-6CYYFT4O.js.map +1 -0
- package/dist/{chunk-W7UH2PWL.js → chunk-6ONQWD6S.js} +1124 -325
- package/dist/chunk-6ONQWD6S.js.map +1 -0
- package/dist/{chunk-GRBGQ2GE.js → chunk-6TBWJV35.js} +5 -3
- package/dist/chunk-6TBWJV35.js.map +1 -0
- package/dist/chunk-6XCINXZ7.cjs +194 -0
- package/dist/chunk-6XCINXZ7.cjs.map +1 -0
- package/dist/{chunk-E7K4FTLN.cjs → chunk-72YCRTEX.cjs} +18 -2
- package/dist/chunk-72YCRTEX.cjs.map +1 -0
- package/dist/{chunk-MA7TEM62.cjs → chunk-7THRV5KZ.cjs} +762 -27
- package/dist/chunk-7THRV5KZ.cjs.map +1 -0
- package/dist/{chunk-76K3IYWM.js → chunk-ADADLFDR.js} +3 -3
- package/dist/{chunk-76K3IYWM.js.map → chunk-ADADLFDR.js.map} +1 -1
- package/dist/{chunk-DSNPWVIG.cjs → chunk-AF74UXR5.cjs} +4 -3
- package/dist/chunk-AF74UXR5.cjs.map +1 -0
- package/dist/{chunk-DNEURYF3.cjs → chunk-BCRRHJGV.cjs} +206 -65
- package/dist/chunk-BCRRHJGV.cjs.map +1 -0
- package/dist/chunk-BWYU7D33.js +192 -0
- package/dist/chunk-BWYU7D33.js.map +1 -0
- package/dist/{chunk-MV7KHWUT.js → chunk-BXONP7HX.js} +391 -15
- package/dist/chunk-BXONP7HX.js.map +1 -0
- package/dist/chunk-CDRYT2A5.js +513 -0
- package/dist/chunk-CDRYT2A5.js.map +1 -0
- package/dist/{chunk-CB575O6L.cjs → chunk-CZEJQSWB.cjs} +473 -124
- package/dist/chunk-CZEJQSWB.cjs.map +1 -0
- package/dist/chunk-DD2VNRQM.js +62 -0
- package/dist/chunk-DD2VNRQM.js.map +1 -0
- package/dist/{chunk-KEXGB7FK.cjs → chunk-DGV2FWB4.cjs} +7 -7
- package/dist/{chunk-KEXGB7FK.cjs.map → chunk-DGV2FWB4.cjs.map} +1 -1
- package/dist/{chunk-Y63IFHEZ.cjs → chunk-EOPEDKLG.cjs} +4 -4
- package/dist/chunk-EOPEDKLG.cjs.map +1 -0
- package/dist/{chunk-UIZSWUKP.js → chunk-F2GAJSBI.js} +105 -7
- package/dist/chunk-F2GAJSBI.js.map +1 -0
- package/dist/{chunk-VOY2RXOC.cjs → chunk-G4IFCTL5.cjs} +182 -15
- package/dist/chunk-G4IFCTL5.cjs.map +1 -0
- package/dist/chunk-KJBMTK5B.cjs +64 -0
- package/dist/chunk-KJBMTK5B.cjs.map +1 -0
- package/dist/{chunk-S6URFGCZ.js → chunk-LSHPJWM5.js} +3 -3
- package/dist/{chunk-S6URFGCZ.js.map → chunk-LSHPJWM5.js.map} +1 -1
- package/dist/chunk-MGCGWPQJ.cjs +275 -0
- package/dist/chunk-MGCGWPQJ.cjs.map +1 -0
- package/dist/chunk-MRFUISXC.cjs +4981 -0
- package/dist/chunk-MRFUISXC.cjs.map +1 -0
- package/dist/chunk-MSZP3FNH.cjs +518 -0
- package/dist/chunk-MSZP3FNH.cjs.map +1 -0
- package/dist/{chunk-KJ2SW6VA.js → chunk-NRUZYMHE.js} +4 -3
- package/dist/chunk-NRUZYMHE.js.map +1 -0
- package/dist/{chunk-VOQ3ULMT.js → chunk-NUA6TSRD.js} +752 -17
- package/dist/chunk-NUA6TSRD.js.map +1 -0
- package/dist/chunk-OEIVMCWX.js +4959 -0
- package/dist/chunk-OEIVMCWX.js.map +1 -0
- package/dist/{chunk-CINNK34N.js → chunk-OIDPIW42.js} +26 -11
- package/dist/chunk-OIDPIW42.js.map +1 -0
- package/dist/{chunk-CD56CXVE.cjs → chunk-OYIDRI3A.cjs} +32 -17
- package/dist/chunk-OYIDRI3A.cjs.map +1 -0
- package/dist/{chunk-2ZVKF4HP.cjs → chunk-P2D2VO2O.cjs} +1129 -328
- package/dist/chunk-P2D2VO2O.cjs.map +1 -0
- package/dist/{chunk-JPGVRWWL.js → chunk-PK2A5WBG.js} +472 -125
- package/dist/chunk-PK2A5WBG.js.map +1 -0
- package/dist/{chunk-X7JMA3IY.js → chunk-PSCMWPLC.js} +2 -2
- package/dist/{chunk-X7JMA3IY.js.map → chunk-PSCMWPLC.js.map} +1 -1
- package/dist/{chunk-WM6CK2F3.cjs → chunk-QD3UWFAV.cjs} +130 -48
- package/dist/chunk-QD3UWFAV.cjs.map +1 -0
- package/dist/{chunk-MSWTA73A.cjs → chunk-SL7Q6IZF.cjs} +11426 -8219
- package/dist/chunk-SL7Q6IZF.cjs.map +1 -0
- package/dist/{chunk-ECFXGXWO.cjs → chunk-SSPUH2N7.cjs} +693 -375
- package/dist/chunk-SSPUH2N7.cjs.map +1 -0
- package/dist/{chunk-BMAFVZ2D.cjs → chunk-T2VLUFGG.cjs} +4 -4
- package/dist/{chunk-BMAFVZ2D.cjs.map → chunk-T2VLUFGG.cjs.map} +1 -1
- package/dist/chunk-THZTRBFS.js +268 -0
- package/dist/chunk-THZTRBFS.js.map +1 -0
- package/dist/{chunk-Y6ROD72V.cjs → chunk-UIGRFDO6.cjs} +4 -4
- package/dist/{chunk-Y6ROD72V.cjs.map → chunk-UIGRFDO6.cjs.map} +1 -1
- package/dist/{chunk-J7O6WENZ.cjs → chunk-UVHSM2GU.cjs} +6 -2
- package/dist/chunk-UVHSM2GU.cjs.map +1 -0
- package/dist/{chunk-GGYKYORQ.cjs → chunk-WX2DLWXF.cjs} +407 -22
- package/dist/chunk-WX2DLWXF.cjs.map +1 -0
- package/dist/{chunk-H6CZGPZD.js → chunk-XRJQ5ZA7.js} +179 -38
- package/dist/chunk-XRJQ5ZA7.js.map +1 -0
- package/dist/{chunk-KIZIOFZC.js → chunk-Y36Y5MTD.js} +17 -3
- package/dist/chunk-Y36Y5MTD.js.map +1 -0
- package/dist/{chunk-IQO7ANVS.cjs → chunk-YWMMBIOM.cjs} +21 -20
- package/dist/chunk-YWMMBIOM.cjs.map +1 -0
- package/dist/{chunk-I4CXL4SR.js → chunk-Z57R5WS4.js} +16 -15
- package/dist/chunk-Z57R5WS4.js.map +1 -0
- package/dist/deployer/index.cjs +2 -2
- package/dist/deployer/index.js +1 -1
- package/dist/di/index.cjs +10 -2
- package/dist/di/index.d.ts +1 -1
- package/dist/di/index.d.ts.map +1 -1
- package/dist/di/index.js +1 -1
- package/dist/evals/base.d.ts +10 -2
- package/dist/evals/base.d.ts.map +1 -1
- package/dist/evals/base.test-utils.d.ts +25 -25
- package/dist/evals/index.cjs +9 -9
- package/dist/evals/index.js +2 -2
- package/dist/evals/scoreTraces/index.cjs +7 -6
- package/dist/evals/scoreTraces/index.cjs.map +1 -1
- package/dist/evals/scoreTraces/index.js +4 -3
- package/dist/evals/scoreTraces/index.js.map +1 -1
- package/dist/evals/scoreTraces/scoreTracesWorkflow.d.ts.map +1 -1
- package/dist/evals/types.d.ts +25 -24
- package/dist/evals/types.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 +30 -10
- package/dist/llm/index.d.ts +2 -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/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 +9 -4
- package/dist/llm/model/gateways/base.d.ts.map +1 -1
- package/dist/llm/model/gateways/constants.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 +3 -2
- package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
- package/dist/llm/model/gateways/netlify.d.ts +4 -3
- 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.d.ts.map +1 -1
- 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-options.d.ts +4 -1
- package/dist/llm/model/provider-options.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 +473 -24
- 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/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/logger/constants.d.ts +1 -0
- package/dist/logger/constants.d.ts.map +1 -1
- package/dist/logger/index.cjs +11 -11
- package/dist/logger/index.js +2 -2
- package/dist/logger/transport.d.ts +1 -1
- package/dist/logger/transport.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/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 +22 -5
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +42 -42
- package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +29 -29
- 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 +14 -14
- 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/loop/workflows/agentic-loop/index.d.ts +44 -43
- 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 +14 -14
- package/dist/loop/workflows/stream.d.ts +1 -1
- package/dist/loop/workflows/stream.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.ts +377 -12
- package/dist/mastra/index.d.ts.map +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/mcp/index.cjs +4 -4
- 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 +2 -2
- 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 +21 -327
- package/dist/memory/index.cjs.map +1 -1
- package/dist/memory/index.js +1 -327
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/memory.d.ts +28 -18
- package/dist/memory/memory.d.ts.map +1 -1
- package/dist/memory/mock.d.ts +15 -14
- package/dist/memory/mock.d.ts.map +1 -1
- package/dist/memory/types.d.ts +69 -11
- package/dist/memory/types.d.ts.map +1 -1
- package/dist/models-dev-23RN2WHG.js +3 -0
- package/dist/{models-dev-DNBKXHT4.js.map → models-dev-23RN2WHG.js.map} +1 -1
- package/dist/models-dev-EO3SUIY2.cjs +12 -0
- package/dist/{models-dev-YBEEQIX6.cjs.map → models-dev-EO3SUIY2.cjs.map} +1 -1
- package/dist/netlify-GXJ5D5DD.js +3 -0
- package/dist/{netlify-7G2L5VSH.js.map → netlify-GXJ5D5DD.js.map} +1 -1
- package/dist/netlify-KJLY3GFS.cjs +12 -0
- package/dist/{netlify-GWNGSIRZ.cjs.map → netlify-KJLY3GFS.cjs.map} +1 -1
- package/dist/observability/index.cjs +16 -8
- package/dist/observability/index.js +1 -1
- package/dist/observability/types/tracing.d.ts +236 -13
- package/dist/observability/types/tracing.d.ts.map +1 -1
- package/dist/observability/utils.d.ts +47 -1
- package/dist/observability/utils.d.ts.map +1 -1
- package/dist/processors/index.cjs +35 -11
- package/dist/processors/index.d.ts +101 -23
- package/dist/processors/index.d.ts.map +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/memory/index.d.ts +7 -0
- package/dist/processors/memory/index.d.ts.map +1 -0
- package/dist/processors/memory/message-history.d.ts +43 -0
- package/dist/processors/memory/message-history.d.ts.map +1 -0
- package/dist/processors/memory/semantic-recall.d.ts +152 -0
- package/dist/processors/memory/semantic-recall.d.ts.map +1 -0
- package/dist/processors/memory/working-memory.d.ts +65 -0
- package/dist/processors/memory/working-memory.d.ts.map +1 -0
- 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/index.d.ts +2 -1
- package/dist/processors/processors/index.d.ts.map +1 -1
- package/dist/processors/processors/language-detector.d.ts +15 -1
- package/dist/processors/processors/language-detector.d.ts.map +1 -1
- package/dist/processors/processors/moderation.d.ts +15 -1
- package/dist/processors/processors/moderation.d.ts.map +1 -1
- package/dist/processors/processors/pii-detector.d.ts +15 -1
- package/dist/processors/processors/pii-detector.d.ts.map +1 -1
- package/dist/processors/processors/prompt-injection-detector.d.ts +15 -1
- package/dist/processors/processors/prompt-injection-detector.d.ts.map +1 -1
- package/dist/processors/processors/structured-output.d.ts +3 -2
- 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 +22 -12
- package/dist/processors/processors/token-limiter.d.ts.map +1 -1
- package/dist/processors/processors/tool-call-filter.d.ts +28 -0
- package/dist/processors/processors/tool-call-filter.d.ts.map +1 -0
- package/dist/processors/processors/unicode-normalizer.d.ts +1 -1
- package/dist/processors/processors/unicode-normalizer.d.ts.map +1 -1
- package/dist/processors/runner.d.ts +35 -4
- package/dist/processors/runner.d.ts.map +1 -1
- package/dist/provider-registry-A7FILT6Q.cjs +40 -0
- package/dist/provider-registry-A7FILT6Q.cjs.map +1 -0
- package/dist/provider-registry-XM2YDI5X.js +3 -0
- package/dist/provider-registry-XM2YDI5X.js.map +1 -0
- package/dist/provider-registry.json +1038 -55
- package/dist/{registry-generator-MK63POJO.cjs → registry-generator-34SC4TAU.cjs} +23 -6
- package/dist/registry-generator-34SC4TAU.cjs.map +1 -0
- package/dist/{registry-generator-H4YNODDH.js → registry-generator-UMTNPBJX.js} +23 -7
- package/dist/registry-generator-UMTNPBJX.js.map +1 -0
- package/dist/relevance/index.cjs +2 -2
- package/dist/relevance/index.js +1 -1
- package/dist/request-context/index.cjs +10 -2
- package/dist/request-context/index.d.ts +26 -0
- package/dist/request-context/index.d.ts.map +1 -1
- package/dist/request-context/index.js +1 -1
- package/dist/server/auth.d.ts +11 -0
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/base.d.ts +51 -0
- package/dist/server/base.d.ts.map +1 -0
- package/dist/server/composite-auth.d.ts +9 -0
- package/dist/server/composite-auth.d.ts.map +1 -0
- package/dist/server/index.cjs +124 -3
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts +8 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +121 -3
- package/dist/server/index.js.map +1 -1
- package/dist/server/simple-auth.d.ts +27 -0
- package/dist/server/simple-auth.d.ts.map +1 -0
- package/dist/storage/base.d.ts +76 -3
- package/dist/storage/base.d.ts.map +1 -1
- package/dist/storage/constants.d.ts +3 -1
- package/dist/storage/constants.d.ts.map +1 -1
- package/dist/storage/domains/agents/base.d.ts +49 -0
- package/dist/storage/domains/agents/base.d.ts.map +1 -0
- package/dist/storage/domains/agents/index.d.ts +3 -0
- package/dist/storage/domains/agents/index.d.ts.map +1 -0
- package/dist/storage/domains/agents/inmemory.d.ts +22 -0
- package/dist/storage/domains/agents/inmemory.d.ts.map +1 -0
- package/dist/storage/domains/index.d.ts +1 -0
- package/dist/storage/domains/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/operations/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/scores/base.d.ts +2 -2
- package/dist/storage/domains/scores/base.d.ts.map +1 -1
- package/dist/storage/domains/scores/inmemory.d.ts +2 -2
- package/dist/storage/domains/scores/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/workflows/base.d.ts +4 -0
- package/dist/storage/domains/workflows/base.d.ts.map +1 -1
- package/dist/storage/domains/workflows/inmemory.d.ts +5 -1
- package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
- package/dist/storage/index.cjs +65 -29
- package/dist/storage/index.js +1 -1
- package/dist/storage/mock.d.ts +7 -2
- package/dist/storage/mock.d.ts.map +1 -1
- package/dist/storage/storageWithInit.d.ts.map +1 -1
- package/dist/storage/types.d.ts +85 -2
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/storage/utils.d.ts +82 -0
- package/dist/storage/utils.d.ts.map +1 -1
- package/dist/stream/MastraAgentNetworkStream.d.ts +1 -1
- package/dist/stream/MastraAgentNetworkStream.d.ts.map +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts.map +1 -1
- package/dist/stream/RunOutput.d.ts +2 -2
- package/dist/stream/RunOutput.d.ts.map +1 -1
- package/dist/stream/aisdk/v4/usage.d.ts +19 -0
- package/dist/stream/aisdk/v4/usage.d.ts.map +1 -0
- package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/execute.d.ts +8 -4
- package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/input.d.ts +4 -1
- package/dist/stream/aisdk/v5/input.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/output.d.ts +9 -9
- package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/transform.d.ts.map +1 -1
- package/dist/stream/base/base.d.ts +1 -1
- package/dist/stream/base/base.d.ts.map +1 -1
- package/dist/stream/base/input.d.ts +1 -1
- package/dist/stream/base/output-format-handlers.d.ts +14 -1
- package/dist/stream/base/output-format-handlers.d.ts.map +1 -1
- package/dist/stream/base/output.d.ts +3 -3
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/index.cjs +15 -11
- package/dist/stream/index.d.ts +2 -2
- package/dist/stream/index.d.ts.map +1 -1
- package/dist/stream/index.js +2 -2
- package/dist/stream/types.d.ts +48 -25
- package/dist/stream/types.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.cjs +101 -30
- package/dist/test-utils/llm-mock.cjs.map +1 -1
- package/dist/test-utils/llm-mock.d.ts +7 -2
- package/dist/test-utils/llm-mock.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.js +97 -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 +10 -4
- 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-stream-types.test-d.d.ts +2 -0
- package/dist/tools/tool-stream-types.test-d.d.ts.map +1 -0
- package/dist/tools/tool.d.ts +21 -8
- package/dist/tools/tool.d.ts.map +1 -1
- package/dist/tools/types.d.ts +33 -6
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/validation.d.ts +25 -1
- package/dist/tools/validation.d.ts.map +1 -1
- package/dist/tts/index.cjs +2 -2
- package/dist/tts/index.js +1 -1
- package/dist/types/zod-compat.d.ts +14 -1
- package/dist/types/zod-compat.d.ts.map +1 -1
- package/dist/utils.cjs +25 -21
- package/dist/utils.d.ts +9 -4
- 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 +7 -2
- 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 +2 -1
- 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 +179 -270
- 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/step-executor.d.ts +1 -1
- package/dist/workflows/evented/step-executor.d.ts.map +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 +8 -6
- package/dist/workflows/execution-engine.d.ts.map +1 -1
- package/dist/workflows/handlers/control-flow.d.ts +133 -0
- package/dist/workflows/handlers/control-flow.d.ts.map +1 -0
- package/dist/workflows/handlers/entry.d.ts +43 -0
- package/dist/workflows/handlers/entry.d.ts.map +1 -0
- package/dist/workflows/handlers/sleep.d.ts +60 -0
- package/dist/workflows/handlers/sleep.d.ts.map +1 -0
- package/dist/workflows/handlers/step.d.ts +58 -0
- package/dist/workflows/handlers/step.d.ts.map +1 -0
- package/dist/workflows/index.cjs +36 -16
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/step.d.ts +8 -6
- package/dist/workflows/step.d.ts.map +1 -1
- package/dist/workflows/types.d.ts +223 -10
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/utils.d.ts +36 -0
- package/dist/workflows/utils.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +135 -54
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +26 -30
- package/src/llm/model/provider-types.generated.d.ts +473 -24
- package/dist/chunk-2ZVKF4HP.cjs.map +0 -1
- package/dist/chunk-436FFEF6.js +0 -34
- package/dist/chunk-436FFEF6.js.map +0 -1
- package/dist/chunk-4CDL2QJT.js.map +0 -1
- package/dist/chunk-7AHYOMHJ.js +0 -149
- package/dist/chunk-7AHYOMHJ.js.map +0 -1
- package/dist/chunk-CB575O6L.cjs.map +0 -1
- package/dist/chunk-CD56CXVE.cjs.map +0 -1
- package/dist/chunk-CINNK34N.js.map +0 -1
- package/dist/chunk-DNEURYF3.cjs.map +0 -1
- package/dist/chunk-DSNPWVIG.cjs.map +0 -1
- package/dist/chunk-E7K4FTLN.cjs.map +0 -1
- package/dist/chunk-ECFXGXWO.cjs.map +0 -1
- package/dist/chunk-ET6UOTTU.cjs +0 -154
- package/dist/chunk-ET6UOTTU.cjs.map +0 -1
- package/dist/chunk-GGYKYORQ.cjs.map +0 -1
- package/dist/chunk-GRBGQ2GE.js.map +0 -1
- package/dist/chunk-H6CZGPZD.js.map +0 -1
- package/dist/chunk-HDJFSJCK.js +0 -2237
- package/dist/chunk-HDJFSJCK.js.map +0 -1
- package/dist/chunk-HGNRQ3OG.js +0 -58
- package/dist/chunk-HGNRQ3OG.js.map +0 -1
- package/dist/chunk-I4CXL4SR.js.map +0 -1
- package/dist/chunk-IQO7ANVS.cjs.map +0 -1
- package/dist/chunk-J7O6WENZ.cjs.map +0 -1
- package/dist/chunk-JPGVRWWL.js.map +0 -1
- package/dist/chunk-JUBFO5J3.js.map +0 -1
- package/dist/chunk-JV2KH24V.js.map +0 -1
- package/dist/chunk-KIZIOFZC.js.map +0 -1
- package/dist/chunk-KJ2SW6VA.js.map +0 -1
- package/dist/chunk-LJFJTTZQ.cjs +0 -4
- package/dist/chunk-LJFJTTZQ.cjs.map +0 -1
- package/dist/chunk-LRSB62Z6.cjs +0 -60
- package/dist/chunk-LRSB62Z6.cjs.map +0 -1
- package/dist/chunk-LWBQ4P4N.cjs +0 -2240
- package/dist/chunk-LWBQ4P4N.cjs.map +0 -1
- package/dist/chunk-MA7TEM62.cjs.map +0 -1
- package/dist/chunk-MSWTA73A.cjs.map +0 -1
- package/dist/chunk-MV7KHWUT.js.map +0 -1
- package/dist/chunk-QUKUN6NR.cjs.map +0 -1
- package/dist/chunk-TQTAMPSC.js.map +0 -1
- package/dist/chunk-UIZSWUKP.js.map +0 -1
- package/dist/chunk-V3VLOOSW.cjs +0 -36
- package/dist/chunk-V3VLOOSW.cjs.map +0 -1
- package/dist/chunk-VOQ3ULMT.js.map +0 -1
- package/dist/chunk-VOY2RXOC.cjs.map +0 -1
- package/dist/chunk-W7UH2PWL.js.map +0 -1
- package/dist/chunk-WM6CK2F3.cjs.map +0 -1
- package/dist/chunk-XEVG546F.js.map +0 -1
- package/dist/chunk-Y63IFHEZ.cjs.map +0 -1
- package/dist/chunk-ZV5CC35D.js +0 -3
- package/dist/chunk-ZV5CC35D.js.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;
|
|
@@ -230,14 +230,137 @@ function convertImageFilePart(part, downloadedAssets) {
|
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
|
+
zod.z.union([
|
|
234
|
+
zod.z.string(),
|
|
235
|
+
zod.z.instanceof(Uint8Array),
|
|
236
|
+
zod.z.instanceof(ArrayBuffer),
|
|
237
|
+
zod.z.custom(
|
|
238
|
+
// Buffer might not be available in some environments such as CloudFlare:
|
|
239
|
+
(value) => globalThis.Buffer?.isBuffer(value) ?? false,
|
|
240
|
+
{ message: "Must be a Buffer" }
|
|
241
|
+
)
|
|
242
|
+
]);
|
|
243
|
+
function convertDataContentToBase64String(content) {
|
|
244
|
+
if (typeof content === "string") {
|
|
245
|
+
return content;
|
|
246
|
+
}
|
|
247
|
+
if (content instanceof ArrayBuffer) {
|
|
248
|
+
return chunkSVLMF4UZ_cjs.convertUint8ArrayToBase64(new Uint8Array(content));
|
|
249
|
+
}
|
|
250
|
+
return chunkSVLMF4UZ_cjs.convertUint8ArrayToBase64(content);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// src/agent/message-list/prompt/image-utils.ts
|
|
254
|
+
function parseDataUri(dataUri) {
|
|
255
|
+
if (!dataUri.startsWith("data:")) {
|
|
256
|
+
return {
|
|
257
|
+
isDataUri: false,
|
|
258
|
+
base64Content: dataUri
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
const base64Index = dataUri.indexOf(",");
|
|
262
|
+
if (base64Index === -1) {
|
|
263
|
+
return {
|
|
264
|
+
isDataUri: true,
|
|
265
|
+
base64Content: dataUri
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
const header = dataUri.substring(5, base64Index);
|
|
269
|
+
const base64Content = dataUri.substring(base64Index + 1);
|
|
270
|
+
const semicolonIndex = header.indexOf(";");
|
|
271
|
+
const mimeType = semicolonIndex !== -1 ? header.substring(0, semicolonIndex) : header;
|
|
272
|
+
return {
|
|
273
|
+
isDataUri: true,
|
|
274
|
+
mimeType: mimeType || void 0,
|
|
275
|
+
base64Content
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function createDataUri(base64Content, mimeType = "application/octet-stream") {
|
|
279
|
+
if (base64Content.startsWith("data:")) {
|
|
280
|
+
return base64Content;
|
|
281
|
+
}
|
|
282
|
+
return `data:${mimeType};base64,${base64Content}`;
|
|
283
|
+
}
|
|
284
|
+
function imageContentToString(image, fallbackMimeType) {
|
|
285
|
+
if (typeof image === "string") {
|
|
286
|
+
return image;
|
|
287
|
+
}
|
|
288
|
+
if (image instanceof URL) {
|
|
289
|
+
return image.toString();
|
|
290
|
+
}
|
|
291
|
+
if (image instanceof Uint8Array || image instanceof ArrayBuffer || globalThis.Buffer && Buffer.isBuffer(image)) {
|
|
292
|
+
const base64 = convertDataContentToBase64String(image);
|
|
293
|
+
return base64;
|
|
294
|
+
}
|
|
295
|
+
return String(image);
|
|
296
|
+
}
|
|
297
|
+
function getImageCacheKey(image) {
|
|
298
|
+
if (image instanceof URL) {
|
|
299
|
+
return image.toString();
|
|
300
|
+
}
|
|
301
|
+
if (typeof image === "string") {
|
|
302
|
+
return image.length;
|
|
303
|
+
}
|
|
304
|
+
if (image instanceof Uint8Array) {
|
|
305
|
+
return image.byteLength;
|
|
306
|
+
}
|
|
307
|
+
if (image instanceof ArrayBuffer) {
|
|
308
|
+
return image.byteLength;
|
|
309
|
+
}
|
|
310
|
+
return image;
|
|
311
|
+
}
|
|
312
|
+
function isValidUrl(str) {
|
|
313
|
+
try {
|
|
314
|
+
new URL(str);
|
|
315
|
+
return true;
|
|
316
|
+
} catch {
|
|
317
|
+
if (str.startsWith("//")) {
|
|
318
|
+
try {
|
|
319
|
+
new URL(`https:${str}`);
|
|
320
|
+
return true;
|
|
321
|
+
} catch {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function categorizeFileData(data, fallbackMimeType) {
|
|
329
|
+
const parsed = parseDataUri(data);
|
|
330
|
+
const mimeType = parsed.isDataUri && parsed.mimeType ? parsed.mimeType : fallbackMimeType;
|
|
331
|
+
if (parsed.isDataUri) {
|
|
332
|
+
return {
|
|
333
|
+
type: "dataUri",
|
|
334
|
+
mimeType,
|
|
335
|
+
data
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
if (isValidUrl(data)) {
|
|
339
|
+
return {
|
|
340
|
+
type: "url",
|
|
341
|
+
mimeType,
|
|
342
|
+
data
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
type: "raw",
|
|
347
|
+
mimeType,
|
|
348
|
+
data
|
|
349
|
+
};
|
|
350
|
+
}
|
|
233
351
|
|
|
234
352
|
// src/agent/message-list/prompt/attachments-to-parts.ts
|
|
235
353
|
function attachmentsToParts(attachments) {
|
|
236
354
|
const parts = [];
|
|
237
355
|
for (const attachment of attachments) {
|
|
356
|
+
const categorized = categorizeFileData(attachment.url, attachment.contentType);
|
|
357
|
+
let urlString = attachment.url;
|
|
358
|
+
if (categorized.type === "raw") {
|
|
359
|
+
urlString = createDataUri(attachment.url, attachment.contentType || "application/octet-stream");
|
|
360
|
+
}
|
|
238
361
|
let url;
|
|
239
362
|
try {
|
|
240
|
-
url = new URL(
|
|
363
|
+
url = new URL(urlString);
|
|
241
364
|
} catch {
|
|
242
365
|
throw new Error(`Invalid URL: ${attachment.url}`);
|
|
243
366
|
}
|
|
@@ -262,13 +385,13 @@ function attachmentsToParts(attachments) {
|
|
|
262
385
|
if (attachment.contentType?.startsWith("image/")) {
|
|
263
386
|
parts.push({
|
|
264
387
|
type: "image",
|
|
265
|
-
image:
|
|
388
|
+
image: urlString,
|
|
266
389
|
mimeType: attachment.contentType
|
|
267
390
|
});
|
|
268
391
|
} else if (attachment.contentType?.startsWith("text/")) {
|
|
269
392
|
parts.push({
|
|
270
393
|
type: "file",
|
|
271
|
-
data:
|
|
394
|
+
data: urlString,
|
|
272
395
|
mimeType: attachment.contentType
|
|
273
396
|
});
|
|
274
397
|
} else {
|
|
@@ -277,7 +400,7 @@ function attachmentsToParts(attachments) {
|
|
|
277
400
|
}
|
|
278
401
|
parts.push({
|
|
279
402
|
type: "file",
|
|
280
|
-
data:
|
|
403
|
+
data: urlString,
|
|
281
404
|
mimeType: attachment.contentType
|
|
282
405
|
});
|
|
283
406
|
}
|
|
@@ -588,25 +711,6 @@ function convertToV1Messages(messages) {
|
|
|
588
711
|
}
|
|
589
712
|
return v1Messages;
|
|
590
713
|
}
|
|
591
|
-
zod.z.union([
|
|
592
|
-
zod.z.string(),
|
|
593
|
-
zod.z.instanceof(Uint8Array),
|
|
594
|
-
zod.z.instanceof(ArrayBuffer),
|
|
595
|
-
zod.z.custom(
|
|
596
|
-
// Buffer might not be available in some environments such as CloudFlare:
|
|
597
|
-
(value) => globalThis.Buffer?.isBuffer(value) ?? false,
|
|
598
|
-
{ message: "Must be a Buffer" }
|
|
599
|
-
)
|
|
600
|
-
]);
|
|
601
|
-
function convertDataContentToBase64String(content) {
|
|
602
|
-
if (typeof content === "string") {
|
|
603
|
-
return content;
|
|
604
|
-
}
|
|
605
|
-
if (content instanceof ArrayBuffer) {
|
|
606
|
-
return chunkSVLMF4UZ_cjs.convertUint8ArrayToBase64(new Uint8Array(content));
|
|
607
|
-
}
|
|
608
|
-
return chunkSVLMF4UZ_cjs.convertUint8ArrayToBase64(content);
|
|
609
|
-
}
|
|
610
714
|
|
|
611
715
|
// src/utils/fetchWithRetry.ts
|
|
612
716
|
async function fetchWithRetry(url, options = {}, maxRetries = 3) {
|
|
@@ -697,18 +801,20 @@ async function downloadAssetsFromMessages({
|
|
|
697
801
|
}
|
|
698
802
|
}
|
|
699
803
|
return { mediaType, data };
|
|
700
|
-
}).filter((part) => part.data instanceof URL).map((part) =>
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
804
|
+
}).filter((part) => part.data instanceof URL).map((part) => {
|
|
805
|
+
return {
|
|
806
|
+
url: part.data,
|
|
807
|
+
isUrlSupportedByModel: part.mediaType != null && providerUtilsV5.isUrlSupported({
|
|
808
|
+
url: part.data.toString(),
|
|
809
|
+
mediaType: part.mediaType,
|
|
810
|
+
supportedUrls: supportedUrls ?? {}
|
|
811
|
+
})
|
|
812
|
+
};
|
|
813
|
+
});
|
|
708
814
|
const downloadedFiles = await pMap(
|
|
709
815
|
filesToDownload,
|
|
710
816
|
async (fileItem) => {
|
|
711
|
-
if (
|
|
817
|
+
if (fileItem.isUrlSupportedByModel) {
|
|
712
818
|
return null;
|
|
713
819
|
}
|
|
714
820
|
return {
|
|
@@ -726,105 +832,6 @@ async function downloadAssetsFromMessages({
|
|
|
726
832
|
return Object.fromEntries(downloadFileList);
|
|
727
833
|
}
|
|
728
834
|
|
|
729
|
-
// src/agent/message-list/prompt/image-utils.ts
|
|
730
|
-
function parseDataUri(dataUri) {
|
|
731
|
-
if (!dataUri.startsWith("data:")) {
|
|
732
|
-
return {
|
|
733
|
-
isDataUri: false,
|
|
734
|
-
base64Content: dataUri
|
|
735
|
-
};
|
|
736
|
-
}
|
|
737
|
-
const base64Index = dataUri.indexOf(",");
|
|
738
|
-
if (base64Index === -1) {
|
|
739
|
-
return {
|
|
740
|
-
isDataUri: true,
|
|
741
|
-
base64Content: dataUri
|
|
742
|
-
};
|
|
743
|
-
}
|
|
744
|
-
const header = dataUri.substring(5, base64Index);
|
|
745
|
-
const base64Content = dataUri.substring(base64Index + 1);
|
|
746
|
-
const semicolonIndex = header.indexOf(";");
|
|
747
|
-
const mimeType = semicolonIndex !== -1 ? header.substring(0, semicolonIndex) : header;
|
|
748
|
-
return {
|
|
749
|
-
isDataUri: true,
|
|
750
|
-
mimeType: mimeType || void 0,
|
|
751
|
-
base64Content
|
|
752
|
-
};
|
|
753
|
-
}
|
|
754
|
-
function createDataUri(base64Content, mimeType = "application/octet-stream") {
|
|
755
|
-
if (base64Content.startsWith("data:")) {
|
|
756
|
-
return base64Content;
|
|
757
|
-
}
|
|
758
|
-
return `data:${mimeType};base64,${base64Content}`;
|
|
759
|
-
}
|
|
760
|
-
function imageContentToString(image, fallbackMimeType) {
|
|
761
|
-
if (typeof image === "string") {
|
|
762
|
-
return image;
|
|
763
|
-
}
|
|
764
|
-
if (image instanceof URL) {
|
|
765
|
-
return image.toString();
|
|
766
|
-
}
|
|
767
|
-
if (image instanceof Uint8Array || image instanceof ArrayBuffer || globalThis.Buffer && Buffer.isBuffer(image)) {
|
|
768
|
-
const base64 = convertDataContentToBase64String(image);
|
|
769
|
-
return base64;
|
|
770
|
-
}
|
|
771
|
-
return String(image);
|
|
772
|
-
}
|
|
773
|
-
function getImageCacheKey(image) {
|
|
774
|
-
if (image instanceof URL) {
|
|
775
|
-
return image.toString();
|
|
776
|
-
}
|
|
777
|
-
if (typeof image === "string") {
|
|
778
|
-
return image.length;
|
|
779
|
-
}
|
|
780
|
-
if (image instanceof Uint8Array) {
|
|
781
|
-
return image.byteLength;
|
|
782
|
-
}
|
|
783
|
-
if (image instanceof ArrayBuffer) {
|
|
784
|
-
return image.byteLength;
|
|
785
|
-
}
|
|
786
|
-
return image;
|
|
787
|
-
}
|
|
788
|
-
function isValidUrl(str) {
|
|
789
|
-
try {
|
|
790
|
-
new URL(str);
|
|
791
|
-
return true;
|
|
792
|
-
} catch {
|
|
793
|
-
if (str.startsWith("//")) {
|
|
794
|
-
try {
|
|
795
|
-
new URL(`https:${str}`);
|
|
796
|
-
return true;
|
|
797
|
-
} catch {
|
|
798
|
-
return false;
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
return false;
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
function categorizeFileData(data, fallbackMimeType) {
|
|
805
|
-
const parsed = parseDataUri(data);
|
|
806
|
-
const mimeType = parsed.isDataUri && parsed.mimeType ? parsed.mimeType : fallbackMimeType;
|
|
807
|
-
if (parsed.isDataUri) {
|
|
808
|
-
return {
|
|
809
|
-
type: "dataUri",
|
|
810
|
-
mimeType,
|
|
811
|
-
data
|
|
812
|
-
};
|
|
813
|
-
}
|
|
814
|
-
if (isValidUrl(data)) {
|
|
815
|
-
return {
|
|
816
|
-
type: "url",
|
|
817
|
-
mimeType,
|
|
818
|
-
data
|
|
819
|
-
};
|
|
820
|
-
}
|
|
821
|
-
return {
|
|
822
|
-
type: "raw",
|
|
823
|
-
mimeType,
|
|
824
|
-
data
|
|
825
|
-
};
|
|
826
|
-
}
|
|
827
|
-
|
|
828
835
|
// src/agent/message-list/utils/ai-v5/gemini-compatibility.ts
|
|
829
836
|
function ensureGeminiCompatibleMessages(messages) {
|
|
830
837
|
const result = [...messages];
|
|
@@ -892,6 +899,9 @@ function convertMessages(messages) {
|
|
|
892
899
|
}
|
|
893
900
|
|
|
894
901
|
// src/agent/message-list/index.ts
|
|
902
|
+
function filterDataParts(parts) {
|
|
903
|
+
return parts.filter((part) => !part.type.startsWith("data-"));
|
|
904
|
+
}
|
|
895
905
|
var MessageList = class _MessageList {
|
|
896
906
|
messages = [];
|
|
897
907
|
// passed in by dev in input or context
|
|
@@ -910,6 +920,9 @@ var MessageList = class _MessageList {
|
|
|
910
920
|
userContextMessagesPersisted = /* @__PURE__ */ new Set();
|
|
911
921
|
generateMessageId;
|
|
912
922
|
_agentNetworkAppend = false;
|
|
923
|
+
// Event recording for observability
|
|
924
|
+
isRecording = false;
|
|
925
|
+
recordedEvents = [];
|
|
913
926
|
constructor({
|
|
914
927
|
threadId,
|
|
915
928
|
resourceId,
|
|
@@ -923,10 +936,34 @@ var MessageList = class _MessageList {
|
|
|
923
936
|
this.generateMessageId = generateMessageId;
|
|
924
937
|
this._agentNetworkAppend = _agentNetworkAppend || false;
|
|
925
938
|
}
|
|
939
|
+
/**
|
|
940
|
+
* Start recording mutations to the MessageList for observability/tracing
|
|
941
|
+
*/
|
|
942
|
+
startRecording() {
|
|
943
|
+
this.isRecording = true;
|
|
944
|
+
this.recordedEvents = [];
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* Stop recording and return the list of recorded events
|
|
948
|
+
*/
|
|
949
|
+
stopRecording() {
|
|
950
|
+
this.isRecording = false;
|
|
951
|
+
const events = [...this.recordedEvents];
|
|
952
|
+
this.recordedEvents = [];
|
|
953
|
+
return events;
|
|
954
|
+
}
|
|
926
955
|
add(messages, messageSource) {
|
|
927
956
|
if (messageSource === `user`) messageSource = `input`;
|
|
928
957
|
if (!messages) return this;
|
|
929
|
-
|
|
958
|
+
const messageArray = Array.isArray(messages) ? messages : [messages];
|
|
959
|
+
if (this.isRecording) {
|
|
960
|
+
this.recordedEvents.push({
|
|
961
|
+
type: "add",
|
|
962
|
+
source: messageSource,
|
|
963
|
+
count: messageArray.length
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
for (const message of messageArray) {
|
|
930
967
|
this.addOne(
|
|
931
968
|
typeof message === `string` ? {
|
|
932
969
|
role: "user",
|
|
@@ -988,6 +1025,22 @@ var MessageList = class _MessageList {
|
|
|
988
1025
|
this.userContextMessagesPersisted = this.deserializeSet(state.userContextMessagesPersisted);
|
|
989
1026
|
return this;
|
|
990
1027
|
}
|
|
1028
|
+
makeMessageSourceChecker() {
|
|
1029
|
+
const sources = {
|
|
1030
|
+
memory: new Set(Array.from(this.memoryMessages.values()).map((m) => m.id)),
|
|
1031
|
+
output: new Set(Array.from(this.newResponseMessages.values()).map((m) => m.id)),
|
|
1032
|
+
input: new Set(Array.from(this.newUserMessages.values()).map((m) => m.id))
|
|
1033
|
+
};
|
|
1034
|
+
return {
|
|
1035
|
+
...sources,
|
|
1036
|
+
getSource: (msg) => {
|
|
1037
|
+
if (sources.memory.has(msg.id)) return "memory";
|
|
1038
|
+
if (sources.input.has(msg.id)) return "input";
|
|
1039
|
+
if (sources.output.has(msg.id)) return "response";
|
|
1040
|
+
return null;
|
|
1041
|
+
}
|
|
1042
|
+
};
|
|
1043
|
+
}
|
|
991
1044
|
getLatestUserContent() {
|
|
992
1045
|
const currentUserMessages = this.all.core().filter((m) => m.role === "user");
|
|
993
1046
|
const content = currentUserMessages.at(-1)?.content;
|
|
@@ -1012,11 +1065,34 @@ var MessageList = class _MessageList {
|
|
|
1012
1065
|
}
|
|
1013
1066
|
get clear() {
|
|
1014
1067
|
return {
|
|
1068
|
+
all: {
|
|
1069
|
+
db: () => {
|
|
1070
|
+
const allMessages = [...this.messages];
|
|
1071
|
+
this.messages = [];
|
|
1072
|
+
this.newUserMessages.clear();
|
|
1073
|
+
this.newResponseMessages.clear();
|
|
1074
|
+
this.userContextMessages.clear();
|
|
1075
|
+
if (this.isRecording && allMessages.length > 0) {
|
|
1076
|
+
this.recordedEvents.push({
|
|
1077
|
+
type: "clear",
|
|
1078
|
+
count: allMessages.length
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
return allMessages;
|
|
1082
|
+
}
|
|
1083
|
+
},
|
|
1015
1084
|
input: {
|
|
1016
1085
|
db: () => {
|
|
1017
1086
|
const userMessages = Array.from(this.newUserMessages);
|
|
1018
1087
|
this.messages = this.messages.filter((m) => !this.newUserMessages.has(m));
|
|
1019
1088
|
this.newUserMessages.clear();
|
|
1089
|
+
if (this.isRecording && userMessages.length > 0) {
|
|
1090
|
+
this.recordedEvents.push({
|
|
1091
|
+
type: "clear",
|
|
1092
|
+
source: "input",
|
|
1093
|
+
count: userMessages.length
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1020
1096
|
return userMessages;
|
|
1021
1097
|
}
|
|
1022
1098
|
},
|
|
@@ -1025,11 +1101,46 @@ var MessageList = class _MessageList {
|
|
|
1025
1101
|
const responseMessages = Array.from(this.newResponseMessages);
|
|
1026
1102
|
this.messages = this.messages.filter((m) => !this.newResponseMessages.has(m));
|
|
1027
1103
|
this.newResponseMessages.clear();
|
|
1104
|
+
if (this.isRecording && responseMessages.length > 0) {
|
|
1105
|
+
this.recordedEvents.push({
|
|
1106
|
+
type: "clear",
|
|
1107
|
+
source: "response",
|
|
1108
|
+
count: responseMessages.length
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1028
1111
|
return responseMessages;
|
|
1029
1112
|
}
|
|
1030
1113
|
}
|
|
1031
1114
|
};
|
|
1032
1115
|
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Remove messages by ID
|
|
1118
|
+
* @param ids - Array of message IDs to remove
|
|
1119
|
+
* @returns Array of removed messages
|
|
1120
|
+
*/
|
|
1121
|
+
removeByIds(ids) {
|
|
1122
|
+
const idsSet = new Set(ids);
|
|
1123
|
+
const removed = [];
|
|
1124
|
+
this.messages = this.messages.filter((m) => {
|
|
1125
|
+
if (idsSet.has(m.id)) {
|
|
1126
|
+
removed.push(m);
|
|
1127
|
+
this.memoryMessages.delete(m);
|
|
1128
|
+
this.newUserMessages.delete(m);
|
|
1129
|
+
this.newResponseMessages.delete(m);
|
|
1130
|
+
this.userContextMessages.delete(m);
|
|
1131
|
+
return false;
|
|
1132
|
+
}
|
|
1133
|
+
return true;
|
|
1134
|
+
});
|
|
1135
|
+
if (this.isRecording && removed.length > 0) {
|
|
1136
|
+
this.recordedEvents.push({
|
|
1137
|
+
type: "removeByIds",
|
|
1138
|
+
ids,
|
|
1139
|
+
count: removed.length
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
return removed;
|
|
1143
|
+
}
|
|
1033
1144
|
all = {
|
|
1034
1145
|
db: () => this.messages,
|
|
1035
1146
|
v1: () => convertToV1Messages(this.all.db()),
|
|
@@ -1063,7 +1174,10 @@ var MessageList = class _MessageList {
|
|
|
1063
1174
|
supportedUrls: options?.supportedUrls
|
|
1064
1175
|
});
|
|
1065
1176
|
let messages = [...systemMessages, ...modelMessages];
|
|
1066
|
-
|
|
1177
|
+
const hasImageOrFileContent = modelMessages.some(
|
|
1178
|
+
(message) => message.role === "user" && typeof message.content !== "string" && message.content.some((part) => part.type === "image" || part.type === "file")
|
|
1179
|
+
);
|
|
1180
|
+
if (hasImageOrFileContent) {
|
|
1067
1181
|
messages = messages.map((message) => {
|
|
1068
1182
|
if (message.role === "user") {
|
|
1069
1183
|
if (typeof message.content === "string") {
|
|
@@ -1330,12 +1444,47 @@ var MessageList = class _MessageList {
|
|
|
1330
1444
|
if (unsavedMessages.length === 0) return void 0;
|
|
1331
1445
|
return Math.min(...unsavedMessages.map((m) => new Date(m.createdAt).getTime()));
|
|
1332
1446
|
}
|
|
1447
|
+
/**
|
|
1448
|
+
* Check if a message is a new user or response message that should be saved.
|
|
1449
|
+
* Checks by message ID to handle cases where the message object may be a copy.
|
|
1450
|
+
*/
|
|
1451
|
+
isNewMessage(messageOrId) {
|
|
1452
|
+
const id = typeof messageOrId === "string" ? messageOrId : messageOrId.id;
|
|
1453
|
+
if (typeof messageOrId !== "string") {
|
|
1454
|
+
if (this.newUserMessages.has(messageOrId) || this.newResponseMessages.has(messageOrId)) {
|
|
1455
|
+
return true;
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
return Array.from(this.newUserMessages).some((m) => m.id === id) || Array.from(this.newResponseMessages).some((m) => m.id === id);
|
|
1459
|
+
}
|
|
1333
1460
|
getSystemMessages(tag) {
|
|
1334
1461
|
if (tag) {
|
|
1335
1462
|
return this.taggedSystemMessages[tag] || [];
|
|
1336
1463
|
}
|
|
1337
1464
|
return this.systemMessages;
|
|
1338
1465
|
}
|
|
1466
|
+
/**
|
|
1467
|
+
* Get all system messages (both tagged and untagged)
|
|
1468
|
+
* @returns Array of all system messages
|
|
1469
|
+
*/
|
|
1470
|
+
getAllSystemMessages() {
|
|
1471
|
+
return [...this.systemMessages, ...Object.values(this.taggedSystemMessages).flat()];
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* Replace all system messages with new ones
|
|
1475
|
+
* This clears both tagged and untagged system messages and replaces them with the provided array
|
|
1476
|
+
* @param messages - Array of system messages to set
|
|
1477
|
+
*/
|
|
1478
|
+
replaceAllSystemMessages(messages) {
|
|
1479
|
+
this.systemMessages = [];
|
|
1480
|
+
this.taggedSystemMessages = {};
|
|
1481
|
+
for (const message of messages) {
|
|
1482
|
+
if (message.role === "system") {
|
|
1483
|
+
this.systemMessages.push(message);
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
return this;
|
|
1487
|
+
}
|
|
1339
1488
|
addSystem(messages, tag) {
|
|
1340
1489
|
if (!messages) return this;
|
|
1341
1490
|
for (const message of Array.isArray(messages) ? messages : [messages]) {
|
|
@@ -1394,8 +1543,21 @@ var MessageList = class _MessageList {
|
|
|
1394
1543
|
if (tag && !this.isDuplicateSystem(coreMessage, tag)) {
|
|
1395
1544
|
this.taggedSystemMessages[tag] ||= [];
|
|
1396
1545
|
this.taggedSystemMessages[tag].push(coreMessage);
|
|
1546
|
+
if (this.isRecording) {
|
|
1547
|
+
this.recordedEvents.push({
|
|
1548
|
+
type: "addSystem",
|
|
1549
|
+
tag,
|
|
1550
|
+
message: coreMessage
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1397
1553
|
} else if (!tag && !this.isDuplicateSystem(coreMessage)) {
|
|
1398
1554
|
this.systemMessages.push(coreMessage);
|
|
1555
|
+
if (this.isRecording) {
|
|
1556
|
+
this.recordedEvents.push({
|
|
1557
|
+
type: "addSystem",
|
|
1558
|
+
message: coreMessage
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1399
1561
|
}
|
|
1400
1562
|
}
|
|
1401
1563
|
isDuplicateSystem(message, tag) {
|
|
@@ -1421,9 +1583,20 @@ var MessageList = class _MessageList {
|
|
|
1421
1583
|
if (m.content.parts.length) {
|
|
1422
1584
|
for (const part of m.content.parts) {
|
|
1423
1585
|
if (part.type === `file`) {
|
|
1586
|
+
let normalizedUrl;
|
|
1587
|
+
if (typeof part.data === "string") {
|
|
1588
|
+
const categorized = categorizeFileData(part.data, part.mimeType);
|
|
1589
|
+
if (categorized.type === "raw") {
|
|
1590
|
+
normalizedUrl = createDataUri(part.data, part.mimeType || "application/octet-stream");
|
|
1591
|
+
} else {
|
|
1592
|
+
normalizedUrl = part.data;
|
|
1593
|
+
}
|
|
1594
|
+
} else {
|
|
1595
|
+
normalizedUrl = part.data;
|
|
1596
|
+
}
|
|
1424
1597
|
experimentalAttachments.push({
|
|
1425
1598
|
contentType: part.mimeType,
|
|
1426
|
-
url:
|
|
1599
|
+
url: normalizedUrl
|
|
1427
1600
|
});
|
|
1428
1601
|
} else if (part.type === "tool-invocation" && (part.toolInvocation.state === "call" || part.toolInvocation.state === "partial-call")) {
|
|
1429
1602
|
continue;
|
|
@@ -1461,13 +1634,14 @@ var MessageList = class _MessageList {
|
|
|
1461
1634
|
if (parts.length === 0 && experimentalAttachments.length > 0) {
|
|
1462
1635
|
parts.push({ type: "text", text: "" });
|
|
1463
1636
|
}
|
|
1637
|
+
const v4Parts = filterDataParts(parts);
|
|
1464
1638
|
if (m.role === `user`) {
|
|
1465
1639
|
const uiMessage2 = {
|
|
1466
1640
|
id: m.id,
|
|
1467
1641
|
role: m.role,
|
|
1468
1642
|
content: m.content.content || contentString,
|
|
1469
1643
|
createdAt: m.createdAt,
|
|
1470
|
-
parts,
|
|
1644
|
+
parts: v4Parts,
|
|
1471
1645
|
experimental_attachments: experimentalAttachments
|
|
1472
1646
|
};
|
|
1473
1647
|
if (m.content.metadata) {
|
|
@@ -1481,7 +1655,7 @@ var MessageList = class _MessageList {
|
|
|
1481
1655
|
role: m.role,
|
|
1482
1656
|
content: isSingleTextContentArray ? contentString : m.content.content || contentString,
|
|
1483
1657
|
createdAt: m.createdAt,
|
|
1484
|
-
parts,
|
|
1658
|
+
parts: v4Parts,
|
|
1485
1659
|
reasoning: void 0,
|
|
1486
1660
|
toolInvocations: `toolInvocations` in m.content ? m.content.toolInvocations?.filter((t) => t.state === "result") : void 0
|
|
1487
1661
|
};
|
|
@@ -1495,7 +1669,7 @@ var MessageList = class _MessageList {
|
|
|
1495
1669
|
role: m.role,
|
|
1496
1670
|
content: m.content.content || contentString,
|
|
1497
1671
|
createdAt: m.createdAt,
|
|
1498
|
-
parts,
|
|
1672
|
+
parts: v4Parts,
|
|
1499
1673
|
experimental_attachments: experimentalAttachments
|
|
1500
1674
|
};
|
|
1501
1675
|
if (m.content.metadata) {
|
|
@@ -1664,6 +1838,9 @@ var MessageList = class _MessageList {
|
|
|
1664
1838
|
} else if (messageSource === `response`) {
|
|
1665
1839
|
this.newResponseMessages.add(messageV2);
|
|
1666
1840
|
this.newResponseMessagesPersisted.add(messageV2);
|
|
1841
|
+
if (this.newUserMessages.has(messageV2)) {
|
|
1842
|
+
this.newUserMessages.delete(messageV2);
|
|
1843
|
+
}
|
|
1667
1844
|
} else if (messageSource === `input`) {
|
|
1668
1845
|
this.newUserMessages.add(messageV2);
|
|
1669
1846
|
this.newUserMessagesPersisted.add(messageV2);
|
|
@@ -1688,13 +1865,11 @@ var MessageList = class _MessageList {
|
|
|
1688
1865
|
insertAt
|
|
1689
1866
|
// optional
|
|
1690
1867
|
}) {
|
|
1691
|
-
const partKey = _MessageList.
|
|
1868
|
+
const partKey = _MessageList.cacheKeyFromDBParts([part]);
|
|
1692
1869
|
const latestPartCount = latestMessage.content.parts.filter(
|
|
1693
|
-
(p) => _MessageList.
|
|
1694
|
-
).length;
|
|
1695
|
-
const newPartCount = newMessage.content.parts.filter(
|
|
1696
|
-
(p) => _MessageList.cacheKeyFromAIV4Parts([p]) === partKey
|
|
1870
|
+
(p) => _MessageList.cacheKeyFromDBParts([p]) === partKey
|
|
1697
1871
|
).length;
|
|
1872
|
+
const newPartCount = newMessage.content.parts.filter((p) => _MessageList.cacheKeyFromDBParts([p]) === partKey).length;
|
|
1698
1873
|
if (latestPartCount < newPartCount) {
|
|
1699
1874
|
const partIndex = newMessage.content.parts.indexOf(part);
|
|
1700
1875
|
const hasStepStartBefore = partIndex > 0 && newMessage.content.parts[partIndex - 1]?.type === "step-start";
|
|
@@ -1730,7 +1905,7 @@ var MessageList = class _MessageList {
|
|
|
1730
1905
|
for (let i = 0; i < messageV2.content.parts.length; ++i) {
|
|
1731
1906
|
const part = messageV2.content.parts[i];
|
|
1732
1907
|
if (!part) continue;
|
|
1733
|
-
const key = _MessageList.
|
|
1908
|
+
const key = _MessageList.cacheKeyFromDBParts([part]);
|
|
1734
1909
|
const partToAdd = partsToAdd.get(i);
|
|
1735
1910
|
if (!key || !partToAdd) continue;
|
|
1736
1911
|
if (anchorMap.size > 0) {
|
|
@@ -1741,7 +1916,7 @@ var MessageList = class _MessageList {
|
|
|
1741
1916
|
const offset = leftAnchorV2 === -1 ? i : i - leftAnchorV2;
|
|
1742
1917
|
const insertAt = leftAnchorLatest + offset;
|
|
1743
1918
|
const rightAnchorLatest = rightAnchorV2 !== -1 ? anchorMap.get(rightAnchorV2) : latestMessage.content.parts.length;
|
|
1744
|
-
if (insertAt >= 0 && insertAt <= rightAnchorLatest && !latestMessage.content.parts.slice(insertAt, rightAnchorLatest).some((p) => _MessageList.
|
|
1919
|
+
if (insertAt >= 0 && insertAt <= rightAnchorLatest && !latestMessage.content.parts.slice(insertAt, rightAnchorLatest).some((p) => _MessageList.cacheKeyFromDBParts([p]) === _MessageList.cacheKeyFromDBParts([part]))) {
|
|
1745
1920
|
this.pushNewMessagePart({
|
|
1746
1921
|
latestMessage,
|
|
1747
1922
|
newMessage: messageV2,
|
|
@@ -1792,8 +1967,10 @@ var MessageList = class _MessageList {
|
|
|
1792
1967
|
}
|
|
1793
1968
|
if (_MessageList.isAIV5CoreMessage(message)) {
|
|
1794
1969
|
const dbMsg = _MessageList.aiV5ModelMessageToMastraDBMessage(message, messageSource);
|
|
1970
|
+
const rawCreatedAt = "metadata" in message && message.metadata && typeof message.metadata === "object" && "createdAt" in message.metadata ? message.metadata.createdAt : void 0;
|
|
1795
1971
|
const result = {
|
|
1796
1972
|
...dbMsg,
|
|
1973
|
+
createdAt: this.generateCreatedAt(messageSource, rawCreatedAt),
|
|
1797
1974
|
threadId: this.memoryInfo?.threadId,
|
|
1798
1975
|
resourceId: this.memoryInfo?.resourceId
|
|
1799
1976
|
};
|
|
@@ -1801,8 +1978,10 @@ var MessageList = class _MessageList {
|
|
|
1801
1978
|
}
|
|
1802
1979
|
if (_MessageList.isAIV5UIMessage(message)) {
|
|
1803
1980
|
const dbMsg = _MessageList.aiV5UIMessageToMastraDBMessage(message);
|
|
1981
|
+
const rawCreatedAt = "createdAt" in message ? message.createdAt : void 0;
|
|
1804
1982
|
return {
|
|
1805
1983
|
...dbMsg,
|
|
1984
|
+
createdAt: this.generateCreatedAt(messageSource, rawCreatedAt),
|
|
1806
1985
|
threadId: this.memoryInfo?.threadId,
|
|
1807
1986
|
resourceId: this.memoryInfo?.resourceId
|
|
1808
1987
|
};
|
|
@@ -1812,16 +1991,16 @@ var MessageList = class _MessageList {
|
|
|
1812
1991
|
lastCreatedAt;
|
|
1813
1992
|
// this makes sure messages added in order will always have a date atleast 1ms apart.
|
|
1814
1993
|
generateCreatedAt(messageSource, start) {
|
|
1815
|
-
|
|
1816
|
-
if (
|
|
1817
|
-
this.lastCreatedAt =
|
|
1818
|
-
return
|
|
1994
|
+
const startDate = start instanceof Date ? start : typeof start === "string" || typeof start === "number" ? new Date(start) : void 0;
|
|
1995
|
+
if (startDate && !this.lastCreatedAt) {
|
|
1996
|
+
this.lastCreatedAt = startDate.getTime();
|
|
1997
|
+
return startDate;
|
|
1819
1998
|
}
|
|
1820
|
-
if (
|
|
1821
|
-
return
|
|
1999
|
+
if (startDate && messageSource === `memory`) {
|
|
2000
|
+
return startDate;
|
|
1822
2001
|
}
|
|
1823
2002
|
const now = /* @__PURE__ */ new Date();
|
|
1824
|
-
const nowTime =
|
|
2003
|
+
const nowTime = startDate?.getTime() || now.getTime();
|
|
1825
2004
|
const lastTime = this.messages.reduce((p, m) => {
|
|
1826
2005
|
if (m.createdAt.getTime() > p) return m.createdAt.getTime();
|
|
1827
2006
|
return p;
|
|
@@ -1875,6 +2054,12 @@ var MessageList = class _MessageList {
|
|
|
1875
2054
|
return ti;
|
|
1876
2055
|
});
|
|
1877
2056
|
}
|
|
2057
|
+
if (!message.threadId && this.memoryInfo?.threadId) {
|
|
2058
|
+
message.threadId = this.memoryInfo.threadId;
|
|
2059
|
+
if (!message.resourceId && this.memoryInfo?.resourceId) {
|
|
2060
|
+
message.resourceId = this.memoryInfo.resourceId;
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
1878
2063
|
return message;
|
|
1879
2064
|
}
|
|
1880
2065
|
aiV4UIMessageToMastraDBMessage(message, messageSource) {
|
|
@@ -1912,137 +2097,180 @@ var MessageList = class _MessageList {
|
|
|
1912
2097
|
if (typeof coreMessage.content === "string") {
|
|
1913
2098
|
parts.push({
|
|
1914
2099
|
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 } : {}
|
|
2100
|
+
text: coreMessage.content
|
|
1918
2101
|
});
|
|
1919
2102
|
} else if (Array.isArray(coreMessage.content)) {
|
|
1920
|
-
for (const
|
|
1921
|
-
switch (
|
|
1922
|
-
case "text":
|
|
2103
|
+
for (const aiV4Part of coreMessage.content) {
|
|
2104
|
+
switch (aiV4Part.type) {
|
|
2105
|
+
case "text": {
|
|
1923
2106
|
const prevPart = parts.at(-1);
|
|
1924
2107
|
if (coreMessage.role === "assistant" && prevPart && prevPart.type === "tool-invocation") {
|
|
1925
2108
|
parts.push({ type: "step-start" });
|
|
1926
2109
|
}
|
|
1927
|
-
const
|
|
1928
|
-
..."providerOptions" in coreMessage && coreMessage.providerOptions ? coreMessage.providerOptions : {},
|
|
1929
|
-
..."providerOptions" in part && part.providerOptions ? part.providerOptions : {}
|
|
1930
|
-
};
|
|
1931
|
-
parts.push({
|
|
2110
|
+
const part = {
|
|
1932
2111
|
type: "text",
|
|
1933
|
-
text:
|
|
1934
|
-
|
|
1935
|
-
|
|
2112
|
+
text: aiV4Part.text
|
|
2113
|
+
};
|
|
2114
|
+
if (aiV4Part.providerOptions) {
|
|
2115
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2116
|
+
}
|
|
2117
|
+
parts.push(part);
|
|
1936
2118
|
break;
|
|
1937
|
-
|
|
1938
|
-
|
|
2119
|
+
}
|
|
2120
|
+
case "tool-call": {
|
|
2121
|
+
const part = {
|
|
1939
2122
|
type: "tool-invocation",
|
|
1940
2123
|
toolInvocation: {
|
|
1941
2124
|
state: "call",
|
|
1942
|
-
toolCallId:
|
|
1943
|
-
toolName:
|
|
1944
|
-
args:
|
|
2125
|
+
toolCallId: aiV4Part.toolCallId,
|
|
2126
|
+
toolName: aiV4Part.toolName,
|
|
2127
|
+
args: aiV4Part.args
|
|
1945
2128
|
}
|
|
1946
|
-
}
|
|
2129
|
+
};
|
|
2130
|
+
if (aiV4Part.providerOptions) {
|
|
2131
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2132
|
+
}
|
|
2133
|
+
parts.push(part);
|
|
1947
2134
|
break;
|
|
2135
|
+
}
|
|
1948
2136
|
case "tool-result":
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
2137
|
+
{
|
|
2138
|
+
let toolArgs = {};
|
|
2139
|
+
const toolCallInSameMsg = coreMessage.content.find(
|
|
2140
|
+
(p) => p.type === "tool-call" && p.toolCallId === aiV4Part.toolCallId
|
|
2141
|
+
);
|
|
2142
|
+
if (toolCallInSameMsg && toolCallInSameMsg.type === "tool-call") {
|
|
2143
|
+
toolArgs = toolCallInSameMsg.args;
|
|
2144
|
+
}
|
|
2145
|
+
if (Object.keys(toolArgs).length === 0) {
|
|
2146
|
+
for (let i = this.messages.length - 1; i >= 0; i--) {
|
|
2147
|
+
const msg = this.messages[i];
|
|
2148
|
+
if (msg && msg.role === "assistant" && msg.content.parts) {
|
|
2149
|
+
const toolCallPart = msg.content.parts.find(
|
|
2150
|
+
(p) => p.type === "tool-invocation" && p.toolInvocation.toolCallId === aiV4Part.toolCallId && p.toolInvocation.state === "call"
|
|
2151
|
+
);
|
|
2152
|
+
if (toolCallPart && toolCallPart.type === "tool-invocation" && toolCallPart.toolInvocation.args) {
|
|
2153
|
+
toolArgs = toolCallPart.toolInvocation.args;
|
|
2154
|
+
break;
|
|
2155
|
+
}
|
|
1966
2156
|
}
|
|
1967
2157
|
}
|
|
1968
2158
|
}
|
|
2159
|
+
const invocation = {
|
|
2160
|
+
state: "result",
|
|
2161
|
+
toolCallId: aiV4Part.toolCallId,
|
|
2162
|
+
toolName: aiV4Part.toolName,
|
|
2163
|
+
result: aiV4Part.result ?? "",
|
|
2164
|
+
// undefined will cause AI SDK to throw an error, but for client side tool calls this really could be undefined
|
|
2165
|
+
args: toolArgs
|
|
2166
|
+
// Use the args from the corresponding tool-call
|
|
2167
|
+
};
|
|
2168
|
+
const part = {
|
|
2169
|
+
type: "tool-invocation",
|
|
2170
|
+
toolInvocation: invocation
|
|
2171
|
+
};
|
|
2172
|
+
if (aiV4Part.providerOptions) {
|
|
2173
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2174
|
+
}
|
|
2175
|
+
parts.push(part);
|
|
2176
|
+
toolInvocations.push(invocation);
|
|
1969
2177
|
}
|
|
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
2178
|
break;
|
|
1985
2179
|
case "reasoning":
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
2180
|
+
{
|
|
2181
|
+
const part = {
|
|
2182
|
+
type: "reasoning",
|
|
2183
|
+
reasoning: "",
|
|
2184
|
+
// leave this blank so we aren't double storing it in the db along with details
|
|
2185
|
+
details: [{ type: "text", text: aiV4Part.text, signature: aiV4Part.signature }]
|
|
2186
|
+
};
|
|
2187
|
+
if (aiV4Part.providerOptions) {
|
|
2188
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2189
|
+
}
|
|
2190
|
+
parts.push(part);
|
|
2191
|
+
}
|
|
1992
2192
|
break;
|
|
1993
2193
|
case "redacted-reasoning":
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2194
|
+
{
|
|
2195
|
+
const part = {
|
|
2196
|
+
type: "reasoning",
|
|
2197
|
+
reasoning: "",
|
|
2198
|
+
// No text reasoning for redacted parts
|
|
2199
|
+
details: [{ type: "redacted", data: aiV4Part.data }]
|
|
2200
|
+
};
|
|
2201
|
+
if (aiV4Part.providerOptions) {
|
|
2202
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2203
|
+
}
|
|
2204
|
+
parts.push(part);
|
|
2205
|
+
}
|
|
2000
2206
|
break;
|
|
2001
|
-
case "image":
|
|
2002
|
-
|
|
2207
|
+
case "image": {
|
|
2208
|
+
const part = {
|
|
2003
2209
|
type: "file",
|
|
2004
|
-
data: imageContentToString(
|
|
2005
|
-
mimeType:
|
|
2006
|
-
}
|
|
2210
|
+
data: imageContentToString(aiV4Part.image),
|
|
2211
|
+
mimeType: aiV4Part.mimeType
|
|
2212
|
+
};
|
|
2213
|
+
if (aiV4Part.providerOptions) {
|
|
2214
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2215
|
+
}
|
|
2216
|
+
parts.push(part);
|
|
2007
2217
|
break;
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2218
|
+
}
|
|
2219
|
+
case "file": {
|
|
2220
|
+
if (aiV4Part.data instanceof URL) {
|
|
2221
|
+
const part = {
|
|
2011
2222
|
type: "file",
|
|
2012
|
-
data:
|
|
2013
|
-
mimeType:
|
|
2014
|
-
}
|
|
2015
|
-
|
|
2016
|
-
|
|
2223
|
+
data: aiV4Part.data.toString(),
|
|
2224
|
+
mimeType: aiV4Part.mimeType
|
|
2225
|
+
};
|
|
2226
|
+
if (aiV4Part.providerOptions) {
|
|
2227
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2228
|
+
}
|
|
2229
|
+
parts.push(part);
|
|
2230
|
+
} else if (typeof aiV4Part.data === "string") {
|
|
2231
|
+
const categorized = categorizeFileData(aiV4Part.data, aiV4Part.mimeType);
|
|
2017
2232
|
if (categorized.type === "url" || categorized.type === "dataUri") {
|
|
2018
|
-
|
|
2233
|
+
const part = {
|
|
2019
2234
|
type: "file",
|
|
2020
|
-
data:
|
|
2235
|
+
data: aiV4Part.data,
|
|
2021
2236
|
mimeType: categorized.mimeType || "image/png"
|
|
2022
|
-
}
|
|
2237
|
+
};
|
|
2238
|
+
if (aiV4Part.providerOptions) {
|
|
2239
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2240
|
+
}
|
|
2241
|
+
parts.push(part);
|
|
2023
2242
|
} else {
|
|
2024
2243
|
try {
|
|
2025
|
-
|
|
2244
|
+
const part = {
|
|
2026
2245
|
type: "file",
|
|
2027
2246
|
mimeType: categorized.mimeType || "image/png",
|
|
2028
|
-
data: convertDataContentToBase64String(
|
|
2029
|
-
}
|
|
2247
|
+
data: convertDataContentToBase64String(aiV4Part.data)
|
|
2248
|
+
};
|
|
2249
|
+
if (aiV4Part.providerOptions) {
|
|
2250
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2251
|
+
}
|
|
2252
|
+
parts.push(part);
|
|
2030
2253
|
} catch (error) {
|
|
2031
2254
|
console.error(`Failed to convert binary data to base64 in CoreMessage file part: ${error}`, error);
|
|
2032
2255
|
}
|
|
2033
2256
|
}
|
|
2034
2257
|
} else {
|
|
2035
2258
|
try {
|
|
2036
|
-
|
|
2259
|
+
const part = {
|
|
2037
2260
|
type: "file",
|
|
2038
|
-
mimeType:
|
|
2039
|
-
data: convertDataContentToBase64String(
|
|
2040
|
-
}
|
|
2261
|
+
mimeType: aiV4Part.mimeType,
|
|
2262
|
+
data: convertDataContentToBase64String(aiV4Part.data)
|
|
2263
|
+
};
|
|
2264
|
+
if (aiV4Part.providerOptions) {
|
|
2265
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2266
|
+
}
|
|
2267
|
+
parts.push(part);
|
|
2041
2268
|
} catch (error) {
|
|
2042
2269
|
console.error(`Failed to convert binary data to base64 in CoreMessage file part: ${error}`, error);
|
|
2043
2270
|
}
|
|
2044
2271
|
}
|
|
2045
2272
|
break;
|
|
2273
|
+
}
|
|
2046
2274
|
}
|
|
2047
2275
|
}
|
|
2048
2276
|
}
|
|
@@ -2053,10 +2281,17 @@ var MessageList = class _MessageList {
|
|
|
2053
2281
|
if (toolInvocations.length) content.toolInvocations = toolInvocations;
|
|
2054
2282
|
if (typeof coreMessage.content === `string`) content.content = coreMessage.content;
|
|
2055
2283
|
if (experimentalAttachments.length) content.experimental_attachments = experimentalAttachments;
|
|
2284
|
+
if (coreMessage.providerOptions) {
|
|
2285
|
+
content.providerMetadata = coreMessage.providerOptions;
|
|
2286
|
+
}
|
|
2287
|
+
if ("metadata" in coreMessage && coreMessage.metadata !== null && coreMessage.metadata !== void 0) {
|
|
2288
|
+
content.metadata = coreMessage.metadata;
|
|
2289
|
+
}
|
|
2290
|
+
const rawCreatedAt = "metadata" in coreMessage && coreMessage.metadata && typeof coreMessage.metadata === "object" && "createdAt" in coreMessage.metadata ? coreMessage.metadata.createdAt : void 0;
|
|
2056
2291
|
return {
|
|
2057
2292
|
id,
|
|
2058
2293
|
role: _MessageList.getRole(coreMessage),
|
|
2059
|
-
createdAt: this.generateCreatedAt(messageSource),
|
|
2294
|
+
createdAt: this.generateCreatedAt(messageSource, rawCreatedAt),
|
|
2060
2295
|
threadId: this.memoryInfo?.threadId,
|
|
2061
2296
|
resourceId: this.memoryInfo?.resourceId,
|
|
2062
2297
|
content
|
|
@@ -2094,25 +2329,48 @@ var MessageList = class _MessageList {
|
|
|
2094
2329
|
let key = ``;
|
|
2095
2330
|
for (const part of parts) {
|
|
2096
2331
|
key += part.type;
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2332
|
+
key += _MessageList.cacheKeyFromAIV4Part(part);
|
|
2333
|
+
}
|
|
2334
|
+
return key;
|
|
2335
|
+
}
|
|
2336
|
+
static cacheKeyFromAIV4Part(part) {
|
|
2337
|
+
let cacheKey = "";
|
|
2338
|
+
if (part.type === `text`) {
|
|
2339
|
+
cacheKey += part.text;
|
|
2340
|
+
}
|
|
2341
|
+
if (part.type === `tool-invocation`) {
|
|
2342
|
+
cacheKey += part.toolInvocation.toolCallId;
|
|
2343
|
+
cacheKey += part.toolInvocation.state;
|
|
2344
|
+
}
|
|
2345
|
+
if (part.type === `reasoning`) {
|
|
2346
|
+
cacheKey += part.reasoning;
|
|
2347
|
+
cacheKey += part.details.reduce((prev, current) => {
|
|
2348
|
+
if (current.type === `text`) {
|
|
2349
|
+
return prev + current.text.length + (current.signature?.length || 0);
|
|
2350
|
+
}
|
|
2351
|
+
return prev;
|
|
2352
|
+
}, 0);
|
|
2353
|
+
const partAny = part;
|
|
2354
|
+
if (partAny && Object.hasOwn(partAny, "providerMetadata") && partAny.providerMetadata && Object.hasOwn(partAny.providerMetadata, "openai") && partAny.providerMetadata.openai && Object.hasOwn(partAny.providerMetadata.openai, "itemId")) {
|
|
2355
|
+
const itemId = partAny.providerMetadata.openai.itemId;
|
|
2356
|
+
cacheKey += `|${itemId}`;
|
|
2112
2357
|
}
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2358
|
+
}
|
|
2359
|
+
if (part.type === `file`) {
|
|
2360
|
+
cacheKey += part.data;
|
|
2361
|
+
cacheKey += part.mimeType;
|
|
2362
|
+
}
|
|
2363
|
+
return cacheKey;
|
|
2364
|
+
}
|
|
2365
|
+
static cacheKeyFromDBParts(parts) {
|
|
2366
|
+
let key = ``;
|
|
2367
|
+
for (const part of parts) {
|
|
2368
|
+
key += part.type;
|
|
2369
|
+
if (part.type.startsWith("data-")) {
|
|
2370
|
+
const data = part.data;
|
|
2371
|
+
key += JSON.stringify(data);
|
|
2372
|
+
} else {
|
|
2373
|
+
key += _MessageList.cacheKeyFromAIV4Part(part);
|
|
2116
2374
|
}
|
|
2117
2375
|
}
|
|
2118
2376
|
return key;
|
|
@@ -2182,7 +2440,7 @@ var MessageList = class _MessageList {
|
|
|
2182
2440
|
const twoMM2 = _MessageList.isMastraDBMessage(two) && two;
|
|
2183
2441
|
if (oneMM2 && !twoMM2) return false;
|
|
2184
2442
|
if (oneMM2 && twoMM2) {
|
|
2185
|
-
return oneMM2.id === twoMM2.id && _MessageList.
|
|
2443
|
+
return oneMM2.id === twoMM2.id && _MessageList.cacheKeyFromDBParts(oneMM2.content.parts) === _MessageList.cacheKeyFromDBParts(twoMM2.content.parts);
|
|
2186
2444
|
}
|
|
2187
2445
|
const oneUIV5 = _MessageList.isAIV5UIMessage(one) && one;
|
|
2188
2446
|
const twoUIV5 = _MessageList.isAIV5UIMessage(two) && two;
|
|
@@ -2255,9 +2513,23 @@ var MessageList = class _MessageList {
|
|
|
2255
2513
|
if (role === `tool` || role === `assistant`) {
|
|
2256
2514
|
throw new Error(incompatibleMessage);
|
|
2257
2515
|
}
|
|
2516
|
+
let processedImage;
|
|
2517
|
+
if (part.image instanceof URL || part.image instanceof Uint8Array) {
|
|
2518
|
+
processedImage = part.image;
|
|
2519
|
+
} else if (Buffer.isBuffer(part.image) || part.image instanceof ArrayBuffer) {
|
|
2520
|
+
processedImage = new Uint8Array(part.image);
|
|
2521
|
+
} else {
|
|
2522
|
+
const categorized = categorizeFileData(part.image, part.mimeType);
|
|
2523
|
+
if (categorized.type === "raw") {
|
|
2524
|
+
const dataUri = createDataUri(part.image, part.mimeType || "image/png");
|
|
2525
|
+
processedImage = new URL(dataUri);
|
|
2526
|
+
} else {
|
|
2527
|
+
processedImage = new URL(part.image);
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2258
2530
|
roleContent[role].push({
|
|
2259
2531
|
...part,
|
|
2260
|
-
image:
|
|
2532
|
+
image: processedImage
|
|
2261
2533
|
});
|
|
2262
2534
|
break;
|
|
2263
2535
|
}
|
|
@@ -2403,6 +2675,9 @@ var MessageList = class _MessageList {
|
|
|
2403
2675
|
if (dbMsg.createdAt) metadata.createdAt = dbMsg.createdAt;
|
|
2404
2676
|
if (dbMsg.threadId) metadata.threadId = dbMsg.threadId;
|
|
2405
2677
|
if (dbMsg.resourceId) metadata.resourceId = dbMsg.resourceId;
|
|
2678
|
+
if (dbMsg.content.providerMetadata) {
|
|
2679
|
+
metadata.providerMetadata = dbMsg.content.providerMetadata;
|
|
2680
|
+
}
|
|
2406
2681
|
const hasToolInvocationParts = dbMsg.content.parts?.some((p) => p.type === "tool-invocation");
|
|
2407
2682
|
if (dbMsg.content.toolInvocations && !hasToolInvocationParts) {
|
|
2408
2683
|
for (const invocation of dbMsg.content.toolInvocations) {
|
|
@@ -2469,18 +2744,20 @@ var MessageList = class _MessageList {
|
|
|
2469
2744
|
continue;
|
|
2470
2745
|
}
|
|
2471
2746
|
if (part.type === "reasoning") {
|
|
2472
|
-
const
|
|
2473
|
-
const text = reasoningPart.text || reasoningPart.reasoning || (reasoningPart.details?.reduce((p, c) => {
|
|
2747
|
+
const text = part.reasoning || (part.details?.reduce((p, c) => {
|
|
2474
2748
|
if (c.type === `text` && c.text) return p + c.text;
|
|
2475
2749
|
return p;
|
|
2476
2750
|
}, "") ?? "");
|
|
2477
|
-
if (text ||
|
|
2478
|
-
|
|
2751
|
+
if (text || part.details?.length) {
|
|
2752
|
+
const v5UIPart = {
|
|
2479
2753
|
type: "reasoning",
|
|
2480
2754
|
text: text || "",
|
|
2481
|
-
state: "done"
|
|
2482
|
-
|
|
2483
|
-
|
|
2755
|
+
state: "done"
|
|
2756
|
+
};
|
|
2757
|
+
if (part.providerMetadata) {
|
|
2758
|
+
v5UIPart.providerMetadata = part.providerMetadata;
|
|
2759
|
+
}
|
|
2760
|
+
parts.push(v5UIPart);
|
|
2484
2761
|
}
|
|
2485
2762
|
continue;
|
|
2486
2763
|
}
|
|
@@ -2493,12 +2770,15 @@ var MessageList = class _MessageList {
|
|
|
2493
2770
|
}
|
|
2494
2771
|
const categorized = typeof part.data === "string" ? categorizeFileData(part.data, part.mimeType) : { type: "raw", mimeType: part.mimeType};
|
|
2495
2772
|
if (categorized.type === "url" && typeof part.data === "string") {
|
|
2496
|
-
|
|
2773
|
+
const v5UIPart = {
|
|
2497
2774
|
type: "file",
|
|
2498
2775
|
url: part.data,
|
|
2499
|
-
mediaType: categorized.mimeType || "image/png"
|
|
2500
|
-
|
|
2501
|
-
|
|
2776
|
+
mediaType: categorized.mimeType || "image/png"
|
|
2777
|
+
};
|
|
2778
|
+
if (part.providerMetadata) {
|
|
2779
|
+
v5UIPart.providerMetadata = part.providerMetadata;
|
|
2780
|
+
}
|
|
2781
|
+
parts.push(v5UIPart);
|
|
2502
2782
|
} else {
|
|
2503
2783
|
let filePartData;
|
|
2504
2784
|
let extractedMimeType = part.mimeType;
|
|
@@ -2522,27 +2802,37 @@ var MessageList = class _MessageList {
|
|
|
2522
2802
|
} else {
|
|
2523
2803
|
dataUri = createDataUri(filePartData, finalMimeType);
|
|
2524
2804
|
}
|
|
2525
|
-
|
|
2805
|
+
const v5UIPart = {
|
|
2526
2806
|
type: "file",
|
|
2527
2807
|
url: dataUri,
|
|
2528
2808
|
// Use url field with data URI
|
|
2529
|
-
mediaType: finalMimeType
|
|
2530
|
-
|
|
2531
|
-
|
|
2809
|
+
mediaType: finalMimeType
|
|
2810
|
+
};
|
|
2811
|
+
if (part.providerMetadata) {
|
|
2812
|
+
v5UIPart.providerMetadata = part.providerMetadata;
|
|
2813
|
+
}
|
|
2814
|
+
parts.push(v5UIPart);
|
|
2532
2815
|
}
|
|
2533
2816
|
} else if (part.type === "source") {
|
|
2534
|
-
const
|
|
2535
|
-
parts.push({
|
|
2817
|
+
const v5UIPart = {
|
|
2536
2818
|
type: "source-url",
|
|
2537
|
-
url:
|
|
2538
|
-
|
|
2539
|
-
|
|
2819
|
+
url: part.source.url,
|
|
2820
|
+
sourceId: part.source.id,
|
|
2821
|
+
title: part.source.title
|
|
2822
|
+
};
|
|
2823
|
+
if (part.providerMetadata) {
|
|
2824
|
+
v5UIPart.providerMetadata = part.providerMetadata;
|
|
2825
|
+
}
|
|
2826
|
+
parts.push(v5UIPart);
|
|
2540
2827
|
} else if (part.type === "text") {
|
|
2541
|
-
|
|
2828
|
+
const v5UIPart = {
|
|
2542
2829
|
type: "text",
|
|
2543
|
-
text: part.text
|
|
2544
|
-
|
|
2545
|
-
|
|
2830
|
+
text: part.text
|
|
2831
|
+
};
|
|
2832
|
+
if (part.providerMetadata) {
|
|
2833
|
+
v5UIPart.providerMetadata = part.providerMetadata;
|
|
2834
|
+
}
|
|
2835
|
+
parts.push(v5UIPart);
|
|
2546
2836
|
hasNonToolReasoningParts = true;
|
|
2547
2837
|
} else {
|
|
2548
2838
|
parts.push(part);
|
|
@@ -2706,32 +2996,69 @@ var MessageList = class _MessageList {
|
|
|
2706
2996
|
}
|
|
2707
2997
|
};
|
|
2708
2998
|
}
|
|
2999
|
+
/**
|
|
3000
|
+
* Convert image or file to data URI or URL for V2 file part
|
|
3001
|
+
*/
|
|
3002
|
+
static getDataStringFromAIV5DataPart = (part) => {
|
|
3003
|
+
let mimeType;
|
|
3004
|
+
let data;
|
|
3005
|
+
if ("data" in part) {
|
|
3006
|
+
mimeType = part.mediaType || "application/octet-stream";
|
|
3007
|
+
data = part.data;
|
|
3008
|
+
} else if ("image" in part) {
|
|
3009
|
+
mimeType = part.mediaType || "image/jpeg";
|
|
3010
|
+
data = part.image;
|
|
3011
|
+
} else {
|
|
3012
|
+
throw new chunkTWH4PTDG_cjs.MastraError({
|
|
3013
|
+
id: "MASTRA_AIV5_DATA_PART_INVALID",
|
|
3014
|
+
domain: "AGENT" /* AGENT */,
|
|
3015
|
+
category: "USER" /* USER */,
|
|
3016
|
+
text: "Invalid AIV5 data part in getDataStringFromAIV5DataPart",
|
|
3017
|
+
details: {
|
|
3018
|
+
part
|
|
3019
|
+
}
|
|
3020
|
+
});
|
|
3021
|
+
}
|
|
3022
|
+
if (data instanceof URL) {
|
|
3023
|
+
return data.toString();
|
|
3024
|
+
} else {
|
|
3025
|
+
if (data instanceof Buffer) {
|
|
3026
|
+
const base64 = data.toString("base64");
|
|
3027
|
+
return `data:${mimeType};base64,${base64}`;
|
|
3028
|
+
} else if (typeof data === "string") {
|
|
3029
|
+
return data.startsWith("data:") || data.startsWith("http") ? data : `data:${mimeType};base64,${data}`;
|
|
3030
|
+
} else if (data instanceof Uint8Array) {
|
|
3031
|
+
const base64 = Buffer.from(data).toString("base64");
|
|
3032
|
+
return `data:${mimeType};base64,${base64}`;
|
|
3033
|
+
} else if (data instanceof ArrayBuffer) {
|
|
3034
|
+
const base64 = Buffer.from(data).toString("base64");
|
|
3035
|
+
return `data:${mimeType};base64,${base64}`;
|
|
3036
|
+
} else {
|
|
3037
|
+
return "";
|
|
3038
|
+
}
|
|
3039
|
+
}
|
|
3040
|
+
};
|
|
2709
3041
|
/**
|
|
2710
3042
|
* Direct conversion from AIV5 ModelMessage to MastraDBMessage
|
|
2711
3043
|
* Combines logic from aiV5ModelMessageToMastraMessageV3 + mastraMessageV3ToV2
|
|
2712
3044
|
*/
|
|
2713
3045
|
static aiV5ModelMessageToMastraDBMessage(modelMsg, _messageSource) {
|
|
2714
3046
|
const content = Array.isArray(modelMsg.content) ? modelMsg.content : [{ type: "text", text: modelMsg.content }];
|
|
2715
|
-
const
|
|
3047
|
+
const mastraDBParts = [];
|
|
2716
3048
|
const toolInvocations = [];
|
|
2717
3049
|
const reasoningParts = [];
|
|
2718
3050
|
const experimental_attachments = [];
|
|
2719
|
-
const textParts = [];
|
|
2720
3051
|
let lastPartWasToolResult = false;
|
|
2721
3052
|
for (const part of content) {
|
|
2722
|
-
const providerMetadata = {
|
|
2723
|
-
...modelMsg.providerMetadata || {},
|
|
2724
|
-
...part.providerMetadata || {}
|
|
2725
|
-
};
|
|
2726
|
-
const hasProviderMetadata = Object.keys(providerMetadata).length > 0;
|
|
2727
3053
|
if (part.type === "text") {
|
|
2728
3054
|
const textPart = {
|
|
2729
3055
|
type: "text",
|
|
2730
|
-
text: part.text
|
|
2731
|
-
...hasProviderMetadata && { experimental_providerMetadata: providerMetadata }
|
|
3056
|
+
text: part.text
|
|
2732
3057
|
};
|
|
2733
|
-
|
|
2734
|
-
|
|
3058
|
+
if (part.providerOptions) {
|
|
3059
|
+
textPart.providerMetadata = part.providerOptions;
|
|
3060
|
+
}
|
|
3061
|
+
mastraDBParts.push(textPart);
|
|
2735
3062
|
lastPartWasToolResult = false;
|
|
2736
3063
|
} else if (part.type === "tool-call") {
|
|
2737
3064
|
const toolCallPart = part;
|
|
@@ -2742,10 +3069,12 @@ var MessageList = class _MessageList {
|
|
|
2742
3069
|
toolName: toolCallPart.toolName,
|
|
2743
3070
|
args: toolCallPart.input,
|
|
2744
3071
|
state: "call"
|
|
2745
|
-
}
|
|
2746
|
-
...hasProviderMetadata && { providerMetadata }
|
|
3072
|
+
}
|
|
2747
3073
|
};
|
|
2748
|
-
|
|
3074
|
+
if (part.providerOptions) {
|
|
3075
|
+
toolInvocationPart.providerMetadata = part.providerOptions;
|
|
3076
|
+
}
|
|
3077
|
+
mastraDBParts.push(toolInvocationPart);
|
|
2749
3078
|
toolInvocations.push({
|
|
2750
3079
|
toolCallId: toolCallPart.toolCallId,
|
|
2751
3080
|
toolName: toolCallPart.toolName,
|
|
@@ -2756,78 +3085,67 @@ var MessageList = class _MessageList {
|
|
|
2756
3085
|
} else if (part.type === "tool-result") {
|
|
2757
3086
|
const toolResultPart = part;
|
|
2758
3087
|
const matchingCall = toolInvocations.find((inv) => inv.toolCallId === toolResultPart.toolCallId);
|
|
2759
|
-
const matchingV2Part =
|
|
3088
|
+
const matchingV2Part = mastraDBParts.find(
|
|
2760
3089
|
(p) => p.type === "tool-invocation" && "toolInvocation" in p && p.toolInvocation.toolCallId === toolResultPart.toolCallId
|
|
2761
3090
|
);
|
|
3091
|
+
const updateMatchingCallInvocationResult = (toolResultPart2, matchingCall2) => {
|
|
3092
|
+
matchingCall2.state = "result";
|
|
3093
|
+
matchingCall2.result = typeof toolResultPart2.output === "object" && toolResultPart2.output && "value" in toolResultPart2.output ? toolResultPart2.output.value : toolResultPart2.output;
|
|
3094
|
+
};
|
|
2762
3095
|
if (matchingCall) {
|
|
2763
|
-
matchingCall
|
|
2764
|
-
matchingCall.result = typeof toolResultPart.output === "object" && toolResultPart.output && "value" in toolResultPart.output ? toolResultPart.output.value : toolResultPart.output;
|
|
3096
|
+
updateMatchingCallInvocationResult(toolResultPart, matchingCall);
|
|
2765
3097
|
} else {
|
|
2766
|
-
const
|
|
2767
|
-
|
|
3098
|
+
const call = {
|
|
3099
|
+
state: "call",
|
|
2768
3100
|
toolCallId: toolResultPart.toolCallId,
|
|
2769
|
-
toolName:
|
|
2770
|
-
args: {}
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
3101
|
+
toolName: toolResultPart.toolName || "unknown",
|
|
3102
|
+
args: {}
|
|
3103
|
+
};
|
|
3104
|
+
updateMatchingCallInvocationResult(toolResultPart, call);
|
|
3105
|
+
toolInvocations.push(call);
|
|
2774
3106
|
}
|
|
2775
3107
|
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
|
-
}
|
|
3108
|
+
updateMatchingCallInvocationResult(toolResultPart, matchingV2Part.toolInvocation);
|
|
2781
3109
|
} else {
|
|
2782
|
-
const resultPartWithName = toolResultPart;
|
|
2783
3110
|
const toolInvocationPart = {
|
|
2784
3111
|
type: "tool-invocation",
|
|
2785
3112
|
toolInvocation: {
|
|
2786
3113
|
toolCallId: toolResultPart.toolCallId,
|
|
2787
|
-
toolName:
|
|
3114
|
+
toolName: toolResultPart.toolName || "unknown",
|
|
2788
3115
|
args: {},
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
},
|
|
2792
|
-
...hasProviderMetadata && { providerMetadata }
|
|
3116
|
+
state: "call"
|
|
3117
|
+
}
|
|
2793
3118
|
};
|
|
2794
|
-
|
|
3119
|
+
updateMatchingCallInvocationResult(toolResultPart, toolInvocationPart.toolInvocation);
|
|
3120
|
+
mastraDBParts.push(toolInvocationPart);
|
|
2795
3121
|
}
|
|
2796
3122
|
lastPartWasToolResult = true;
|
|
2797
3123
|
} else if (part.type === "reasoning") {
|
|
2798
|
-
const reasoningPart = part;
|
|
2799
3124
|
const v2ReasoningPart = {
|
|
2800
3125
|
type: "reasoning",
|
|
2801
|
-
reasoning:
|
|
2802
|
-
|
|
2803
|
-
|
|
3126
|
+
reasoning: "",
|
|
3127
|
+
// leave this blank so we aren't double storing it in the db along with details
|
|
3128
|
+
details: [{ type: "text", text: part.text }]
|
|
2804
3129
|
};
|
|
2805
|
-
|
|
2806
|
-
|
|
3130
|
+
if (part.providerOptions) {
|
|
3131
|
+
v2ReasoningPart.providerMetadata = part.providerOptions;
|
|
3132
|
+
}
|
|
3133
|
+
mastraDBParts.push(v2ReasoningPart);
|
|
3134
|
+
reasoningParts.push(part.text);
|
|
2807
3135
|
lastPartWasToolResult = false;
|
|
2808
3136
|
} else if (part.type === "image") {
|
|
2809
3137
|
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
|
-
}
|
|
3138
|
+
const mimeType = imagePart.mediaType || "image/jpeg";
|
|
3139
|
+
const imageData = this.getDataStringFromAIV5DataPart(imagePart);
|
|
2824
3140
|
const imageFilePart = {
|
|
2825
3141
|
type: "file",
|
|
2826
3142
|
data: imageData,
|
|
2827
|
-
mimeType
|
|
2828
|
-
...hasProviderMetadata && { providerMetadata }
|
|
3143
|
+
mimeType
|
|
2829
3144
|
};
|
|
2830
|
-
|
|
3145
|
+
if (part.providerOptions) {
|
|
3146
|
+
imageFilePart.providerMetadata = part.providerOptions;
|
|
3147
|
+
}
|
|
3148
|
+
mastraDBParts.push(imageFilePart);
|
|
2831
3149
|
experimental_attachments.push({
|
|
2832
3150
|
url: imageData,
|
|
2833
3151
|
contentType: mimeType
|
|
@@ -2836,26 +3154,16 @@ var MessageList = class _MessageList {
|
|
|
2836
3154
|
} else if (part.type === "file") {
|
|
2837
3155
|
const filePart = part;
|
|
2838
3156
|
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
|
-
}
|
|
3157
|
+
const fileData = this.getDataStringFromAIV5DataPart(filePart);
|
|
2852
3158
|
const v2FilePart = {
|
|
2853
3159
|
type: "file",
|
|
2854
3160
|
data: fileData,
|
|
2855
|
-
mimeType
|
|
2856
|
-
...hasProviderMetadata && { providerMetadata }
|
|
3161
|
+
mimeType
|
|
2857
3162
|
};
|
|
2858
|
-
|
|
3163
|
+
if (part.providerOptions) {
|
|
3164
|
+
v2FilePart.providerMetadata = part.providerOptions;
|
|
3165
|
+
}
|
|
3166
|
+
mastraDBParts.push(v2FilePart);
|
|
2859
3167
|
experimental_attachments.push({
|
|
2860
3168
|
url: fileData,
|
|
2861
3169
|
contentType: mimeType
|
|
@@ -2863,34 +3171,34 @@ var MessageList = class _MessageList {
|
|
|
2863
3171
|
lastPartWasToolResult = false;
|
|
2864
3172
|
}
|
|
2865
3173
|
}
|
|
2866
|
-
if (modelMsg.role === "assistant" && lastPartWasToolResult &&
|
|
2867
|
-
const lastPart =
|
|
3174
|
+
if (modelMsg.role === "assistant" && lastPartWasToolResult && mastraDBParts.length > 0) {
|
|
3175
|
+
const lastPart = mastraDBParts[mastraDBParts.length - 1];
|
|
2868
3176
|
if (lastPart && lastPart.type !== "text") {
|
|
2869
3177
|
const emptyTextPart = { type: "text", text: "" };
|
|
2870
|
-
|
|
2871
|
-
textParts.push({ text: "" });
|
|
3178
|
+
mastraDBParts.push(emptyTextPart);
|
|
2872
3179
|
}
|
|
2873
3180
|
}
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
contentString = textParts.map((p) => p.text).join("\n");
|
|
2877
|
-
}
|
|
2878
|
-
const metadata = {};
|
|
3181
|
+
const contentString = mastraDBParts.filter((p) => p.type === "text").map((p) => p.text).join("\n");
|
|
3182
|
+
const metadata = "metadata" in modelMsg && modelMsg.metadata !== null && modelMsg.metadata !== void 0 ? modelMsg.metadata : {};
|
|
2879
3183
|
const id = `id` in modelMsg && typeof modelMsg.id === `string` ? modelMsg.id : `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
2880
|
-
|
|
3184
|
+
const message = {
|
|
2881
3185
|
id,
|
|
2882
3186
|
role: _MessageList.getRole(modelMsg),
|
|
2883
3187
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2884
3188
|
content: {
|
|
2885
3189
|
format: 2,
|
|
2886
|
-
parts:
|
|
3190
|
+
parts: mastraDBParts,
|
|
2887
3191
|
toolInvocations: toolInvocations.length > 0 ? toolInvocations : void 0,
|
|
2888
3192
|
reasoning: reasoningParts.length > 0 ? reasoningParts.join("\n") : void 0,
|
|
2889
3193
|
experimental_attachments: experimental_attachments.length > 0 ? experimental_attachments : void 0,
|
|
2890
|
-
content: contentString,
|
|
2891
|
-
metadata
|
|
3194
|
+
content: contentString || void 0,
|
|
3195
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : void 0
|
|
2892
3196
|
}
|
|
2893
3197
|
};
|
|
3198
|
+
if (modelMsg.providerOptions) {
|
|
3199
|
+
message.content.providerMetadata = modelMsg.providerOptions;
|
|
3200
|
+
}
|
|
3201
|
+
return message;
|
|
2894
3202
|
}
|
|
2895
3203
|
aiV4CoreMessagesToAIV5ModelMessages(messages, source) {
|
|
2896
3204
|
return this.aiV5UIMessagesToAIV5ModelMessages(
|
|
@@ -2901,14 +3209,24 @@ var MessageList = class _MessageList {
|
|
|
2901
3209
|
const sanitized = this.sanitizeV5UIMessages(messages, filterIncompleteToolCalls);
|
|
2902
3210
|
const preprocessed = this.addStartStepPartsForAIV5(sanitized);
|
|
2903
3211
|
const result = AIV5__namespace.convertToModelMessages(preprocessed);
|
|
2904
|
-
return result
|
|
3212
|
+
return result.map((modelMsg, index) => {
|
|
3213
|
+
const uiMsg = preprocessed[index];
|
|
3214
|
+
if (uiMsg?.metadata && typeof uiMsg.metadata === "object" && "providerMetadata" in uiMsg.metadata && uiMsg.metadata.providerMetadata) {
|
|
3215
|
+
return {
|
|
3216
|
+
...modelMsg,
|
|
3217
|
+
providerOptions: uiMsg.metadata.providerMetadata
|
|
3218
|
+
};
|
|
3219
|
+
}
|
|
3220
|
+
return modelMsg;
|
|
3221
|
+
});
|
|
2905
3222
|
}
|
|
2906
3223
|
addStartStepPartsForAIV5(messages) {
|
|
2907
3224
|
for (const message of messages) {
|
|
2908
3225
|
if (message.role !== `assistant`) continue;
|
|
2909
3226
|
for (const [index, part] of message.parts.entries()) {
|
|
2910
3227
|
if (!AIV5__namespace.isToolUIPart(part)) continue;
|
|
2911
|
-
|
|
3228
|
+
const nextPart = message.parts.at(index + 1);
|
|
3229
|
+
if (nextPart && nextPart.type !== `step-start` && !AIV5__namespace.isToolUIPart(nextPart)) {
|
|
2912
3230
|
message.parts.splice(index + 1, 0, { type: "step-start" });
|
|
2913
3231
|
}
|
|
2914
3232
|
}
|
|
@@ -3037,5 +3355,5 @@ exports.DefaultGeneratedFile = DefaultGeneratedFile;
|
|
|
3037
3355
|
exports.DefaultGeneratedFileWithType = DefaultGeneratedFileWithType;
|
|
3038
3356
|
exports.MessageList = MessageList;
|
|
3039
3357
|
exports.convertMessages = convertMessages;
|
|
3040
|
-
//# sourceMappingURL=chunk-
|
|
3041
|
-
//# sourceMappingURL=chunk-
|
|
3358
|
+
//# sourceMappingURL=chunk-SSPUH2N7.cjs.map
|
|
3359
|
+
//# sourceMappingURL=chunk-SSPUH2N7.cjs.map
|