@mastra/core 1.0.0-beta.1 → 1.0.0-beta.11
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 +1218 -0
- package/dist/agent/agent-legacy.d.ts +35 -30
- 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 +24 -9
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.types.d.ts +17 -9
- 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 +61 -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 +38 -4
- package/dist/agent/trip-wire.d.ts.map +1 -1
- package/dist/agent/types.d.ts +46 -14
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/utils.d.ts +4 -5
- package/dist/agent/utils.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +37 -13
- 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 +34 -11
- 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 +38 -15
- 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-JUBFO5J3.js → chunk-2ULLRN4Y.js} +16333 -11839
- package/dist/chunk-2ULLRN4Y.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-3E3ILV6T.cjs +518 -0
- package/dist/chunk-3E3ILV6T.cjs.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-MSWTA73A.cjs → chunk-52RSUALV.cjs} +16490 -11957
- package/dist/chunk-52RSUALV.cjs.map +1 -0
- package/dist/chunk-5PAEYE3Q.js +513 -0
- package/dist/chunk-5PAEYE3Q.js.map +1 -0
- package/dist/{chunk-ECFXGXWO.cjs → chunk-5Q6WAYEY.cjs} +695 -375
- package/dist/chunk-5Q6WAYEY.cjs.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-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-W7UH2PWL.js → chunk-7P6BNIJH.js} +1142 -331
- package/dist/chunk-7P6BNIJH.js.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-GGYKYORQ.cjs → chunk-BJXKH4LG.cjs} +407 -22
- package/dist/chunk-BJXKH4LG.cjs.map +1 -0
- package/dist/{chunk-2ZVKF4HP.cjs → chunk-BUKY6CTR.cjs} +1147 -334
- package/dist/chunk-BUKY6CTR.cjs.map +1 -0
- package/dist/chunk-BWYU7D33.js +192 -0
- package/dist/chunk-BWYU7D33.js.map +1 -0
- package/dist/{chunk-XEVG546F.js → chunk-C36YRTZ6.js} +178 -12
- package/dist/chunk-C36YRTZ6.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-4CDL2QJT.js → chunk-IVV5TOMD.js} +122 -37
- package/dist/chunk-IVV5TOMD.js.map +1 -0
- package/dist/{chunk-MV7KHWUT.js → chunk-JIGDJK2O.js} +391 -15
- package/dist/chunk-JIGDJK2O.js.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-KJ2SW6VA.js → chunk-NRUZYMHE.js} +4 -3
- package/dist/chunk-NRUZYMHE.js.map +1 -0
- package/dist/{chunk-CINNK34N.js → chunk-O2BJW7YA.js} +26 -11
- package/dist/chunk-O2BJW7YA.js.map +1 -0
- package/dist/chunk-OEIVMCWX.js +4959 -0
- package/dist/chunk-OEIVMCWX.js.map +1 -0
- package/dist/{chunk-WM6CK2F3.cjs → chunk-PG5H6QIO.cjs} +131 -49
- package/dist/chunk-PG5H6QIO.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-VOY2RXOC.cjs → chunk-S73Z3PBJ.cjs} +182 -15
- package/dist/chunk-S73Z3PBJ.cjs.map +1 -0
- package/dist/{chunk-MA7TEM62.cjs → chunk-SCUWP4II.cjs} +769 -27
- package/dist/chunk-SCUWP4II.cjs.map +1 -0
- package/dist/{chunk-JV2KH24V.js → chunk-SXNQRJQD.js} +695 -375
- package/dist/chunk-SXNQRJQD.js.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-VOQ3ULMT.js → chunk-U3XOLEPX.js} +759 -17
- package/dist/chunk-U3XOLEPX.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-H6CZGPZD.js → chunk-US2U7ECW.js} +179 -38
- package/dist/chunk-US2U7ECW.js.map +1 -0
- package/dist/{chunk-J7O6WENZ.cjs → chunk-UVHSM2GU.cjs} +6 -2
- package/dist/chunk-UVHSM2GU.cjs.map +1 -0
- package/dist/{chunk-CD56CXVE.cjs → chunk-WTSZBHIZ.cjs} +32 -17
- package/dist/chunk-WTSZBHIZ.cjs.map +1 -0
- package/dist/{chunk-KIZIOFZC.js → chunk-Y36Y5MTD.js} +17 -3
- package/dist/chunk-Y36Y5MTD.js.map +1 -0
- package/dist/{chunk-DNEURYF3.cjs → chunk-YC6PJEPH.cjs} +206 -65
- package/dist/chunk-YC6PJEPH.cjs.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/base.types.d.ts +2 -2
- package/dist/llm/model/base.types.d.ts.map +1 -1
- package/dist/llm/model/gateway-resolver.d.ts.map +1 -1
- package/dist/llm/model/gateways/azure.d.ts +36 -0
- package/dist/llm/model/gateways/azure.d.ts.map +1 -0
- package/dist/llm/model/gateways/base.d.ts +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 +4 -2
- 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 +489 -27
- 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 +17 -6
- 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 +42 -20
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +60 -42
- package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +41 -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 +20 -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 +62 -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 +32 -15
- package/dist/loop/workflows/schema.d.ts.map +1 -1
- 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 +115 -11
- package/dist/processors/index.d.ts +246 -26
- 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/prepare-step.d.ts +12 -0
- package/dist/processors/processors/prepare-step.d.ts.map +1 -0
- 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 +7 -5
- 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 +83 -9
- package/dist/processors/runner.d.ts.map +1 -1
- package/dist/processors/step-schema.d.ts +49731 -0
- package/dist/processors/step-schema.d.ts.map +1 -0
- package/dist/provider-registry-3TG2KUD2.cjs +40 -0
- package/dist/provider-registry-3TG2KUD2.cjs.map +1 -0
- package/dist/provider-registry-F67Y6OF2.js +3 -0
- package/dist/provider-registry-F67Y6OF2.js.map +1 -0
- package/dist/provider-registry.json +1056 -61
- 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/server/types.d.ts +6 -0
- package/dist/server/types.d.ts.map +1 -1
- 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 +88 -5
- 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 +2 -2
- package/dist/stream/MastraAgentNetworkStream.d.ts.map +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts +2 -2
- 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/transform.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 +9 -5
- 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-helpers.d.ts +5 -1
- package/dist/stream/aisdk/v5/output-helpers.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/output.d.ts +11 -13
- package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/transform.d.ts +2 -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 +9 -14
- 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 +97 -32
- 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 +180 -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 +40 -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 +257 -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 +146 -55
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +26 -30
- package/src/llm/model/provider-types.generated.d.ts +489 -27
- 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
|
@@ -173,7 +173,7 @@ function convertImageFilePart(part, downloadedAssets) {
|
|
|
173
173
|
const { data: convertedData, mediaType: convertedMediaType } = convertToDataContent(originalData);
|
|
174
174
|
let mediaType = convertedMediaType ?? part.mediaType;
|
|
175
175
|
let data = convertedData;
|
|
176
|
-
if (data instanceof URL) {
|
|
176
|
+
if (data instanceof URL && downloadedAssets) {
|
|
177
177
|
const downloadedFile = downloadedAssets[data.toString()];
|
|
178
178
|
if (downloadedFile) {
|
|
179
179
|
data = downloadedFile.data;
|
|
@@ -208,14 +208,137 @@ function convertImageFilePart(part, downloadedAssets) {
|
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
|
+
z.union([
|
|
212
|
+
z.string(),
|
|
213
|
+
z.instanceof(Uint8Array),
|
|
214
|
+
z.instanceof(ArrayBuffer),
|
|
215
|
+
z.custom(
|
|
216
|
+
// Buffer might not be available in some environments such as CloudFlare:
|
|
217
|
+
(value) => globalThis.Buffer?.isBuffer(value) ?? false,
|
|
218
|
+
{ message: "Must be a Buffer" }
|
|
219
|
+
)
|
|
220
|
+
]);
|
|
221
|
+
function convertDataContentToBase64String(content) {
|
|
222
|
+
if (typeof content === "string") {
|
|
223
|
+
return content;
|
|
224
|
+
}
|
|
225
|
+
if (content instanceof ArrayBuffer) {
|
|
226
|
+
return convertUint8ArrayToBase64$1(new Uint8Array(content));
|
|
227
|
+
}
|
|
228
|
+
return convertUint8ArrayToBase64$1(content);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// src/agent/message-list/prompt/image-utils.ts
|
|
232
|
+
function parseDataUri(dataUri) {
|
|
233
|
+
if (!dataUri.startsWith("data:")) {
|
|
234
|
+
return {
|
|
235
|
+
isDataUri: false,
|
|
236
|
+
base64Content: dataUri
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
const base64Index = dataUri.indexOf(",");
|
|
240
|
+
if (base64Index === -1) {
|
|
241
|
+
return {
|
|
242
|
+
isDataUri: true,
|
|
243
|
+
base64Content: dataUri
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
const header = dataUri.substring(5, base64Index);
|
|
247
|
+
const base64Content = dataUri.substring(base64Index + 1);
|
|
248
|
+
const semicolonIndex = header.indexOf(";");
|
|
249
|
+
const mimeType = semicolonIndex !== -1 ? header.substring(0, semicolonIndex) : header;
|
|
250
|
+
return {
|
|
251
|
+
isDataUri: true,
|
|
252
|
+
mimeType: mimeType || void 0,
|
|
253
|
+
base64Content
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function createDataUri(base64Content, mimeType = "application/octet-stream") {
|
|
257
|
+
if (base64Content.startsWith("data:")) {
|
|
258
|
+
return base64Content;
|
|
259
|
+
}
|
|
260
|
+
return `data:${mimeType};base64,${base64Content}`;
|
|
261
|
+
}
|
|
262
|
+
function imageContentToString(image, fallbackMimeType) {
|
|
263
|
+
if (typeof image === "string") {
|
|
264
|
+
return image;
|
|
265
|
+
}
|
|
266
|
+
if (image instanceof URL) {
|
|
267
|
+
return image.toString();
|
|
268
|
+
}
|
|
269
|
+
if (image instanceof Uint8Array || image instanceof ArrayBuffer || globalThis.Buffer && Buffer.isBuffer(image)) {
|
|
270
|
+
const base64 = convertDataContentToBase64String(image);
|
|
271
|
+
return base64;
|
|
272
|
+
}
|
|
273
|
+
return String(image);
|
|
274
|
+
}
|
|
275
|
+
function getImageCacheKey(image) {
|
|
276
|
+
if (image instanceof URL) {
|
|
277
|
+
return image.toString();
|
|
278
|
+
}
|
|
279
|
+
if (typeof image === "string") {
|
|
280
|
+
return image.length;
|
|
281
|
+
}
|
|
282
|
+
if (image instanceof Uint8Array) {
|
|
283
|
+
return image.byteLength;
|
|
284
|
+
}
|
|
285
|
+
if (image instanceof ArrayBuffer) {
|
|
286
|
+
return image.byteLength;
|
|
287
|
+
}
|
|
288
|
+
return image;
|
|
289
|
+
}
|
|
290
|
+
function isValidUrl(str) {
|
|
291
|
+
try {
|
|
292
|
+
new URL(str);
|
|
293
|
+
return true;
|
|
294
|
+
} catch {
|
|
295
|
+
if (str.startsWith("//")) {
|
|
296
|
+
try {
|
|
297
|
+
new URL(`https:${str}`);
|
|
298
|
+
return true;
|
|
299
|
+
} catch {
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
function categorizeFileData(data, fallbackMimeType) {
|
|
307
|
+
const parsed = parseDataUri(data);
|
|
308
|
+
const mimeType = parsed.isDataUri && parsed.mimeType ? parsed.mimeType : fallbackMimeType;
|
|
309
|
+
if (parsed.isDataUri) {
|
|
310
|
+
return {
|
|
311
|
+
type: "dataUri",
|
|
312
|
+
mimeType,
|
|
313
|
+
data
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
if (isValidUrl(data)) {
|
|
317
|
+
return {
|
|
318
|
+
type: "url",
|
|
319
|
+
mimeType,
|
|
320
|
+
data
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
return {
|
|
324
|
+
type: "raw",
|
|
325
|
+
mimeType,
|
|
326
|
+
data
|
|
327
|
+
};
|
|
328
|
+
}
|
|
211
329
|
|
|
212
330
|
// src/agent/message-list/prompt/attachments-to-parts.ts
|
|
213
331
|
function attachmentsToParts(attachments) {
|
|
214
332
|
const parts = [];
|
|
215
333
|
for (const attachment of attachments) {
|
|
334
|
+
const categorized = categorizeFileData(attachment.url, attachment.contentType);
|
|
335
|
+
let urlString = attachment.url;
|
|
336
|
+
if (categorized.type === "raw") {
|
|
337
|
+
urlString = createDataUri(attachment.url, attachment.contentType || "application/octet-stream");
|
|
338
|
+
}
|
|
216
339
|
let url;
|
|
217
340
|
try {
|
|
218
|
-
url = new URL(
|
|
341
|
+
url = new URL(urlString);
|
|
219
342
|
} catch {
|
|
220
343
|
throw new Error(`Invalid URL: ${attachment.url}`);
|
|
221
344
|
}
|
|
@@ -240,13 +363,13 @@ function attachmentsToParts(attachments) {
|
|
|
240
363
|
if (attachment.contentType?.startsWith("image/")) {
|
|
241
364
|
parts.push({
|
|
242
365
|
type: "image",
|
|
243
|
-
image:
|
|
366
|
+
image: urlString,
|
|
244
367
|
mimeType: attachment.contentType
|
|
245
368
|
});
|
|
246
369
|
} else if (attachment.contentType?.startsWith("text/")) {
|
|
247
370
|
parts.push({
|
|
248
371
|
type: "file",
|
|
249
|
-
data:
|
|
372
|
+
data: urlString,
|
|
250
373
|
mimeType: attachment.contentType
|
|
251
374
|
});
|
|
252
375
|
} else {
|
|
@@ -255,7 +378,7 @@ function attachmentsToParts(attachments) {
|
|
|
255
378
|
}
|
|
256
379
|
parts.push({
|
|
257
380
|
type: "file",
|
|
258
|
-
data:
|
|
381
|
+
data: urlString,
|
|
259
382
|
mimeType: attachment.contentType
|
|
260
383
|
});
|
|
261
384
|
}
|
|
@@ -566,25 +689,6 @@ function convertToV1Messages(messages) {
|
|
|
566
689
|
}
|
|
567
690
|
return v1Messages;
|
|
568
691
|
}
|
|
569
|
-
z.union([
|
|
570
|
-
z.string(),
|
|
571
|
-
z.instanceof(Uint8Array),
|
|
572
|
-
z.instanceof(ArrayBuffer),
|
|
573
|
-
z.custom(
|
|
574
|
-
// Buffer might not be available in some environments such as CloudFlare:
|
|
575
|
-
(value) => globalThis.Buffer?.isBuffer(value) ?? false,
|
|
576
|
-
{ message: "Must be a Buffer" }
|
|
577
|
-
)
|
|
578
|
-
]);
|
|
579
|
-
function convertDataContentToBase64String(content) {
|
|
580
|
-
if (typeof content === "string") {
|
|
581
|
-
return content;
|
|
582
|
-
}
|
|
583
|
-
if (content instanceof ArrayBuffer) {
|
|
584
|
-
return convertUint8ArrayToBase64$1(new Uint8Array(content));
|
|
585
|
-
}
|
|
586
|
-
return convertUint8ArrayToBase64$1(content);
|
|
587
|
-
}
|
|
588
692
|
|
|
589
693
|
// src/utils/fetchWithRetry.ts
|
|
590
694
|
async function fetchWithRetry(url, options = {}, maxRetries = 3) {
|
|
@@ -675,18 +779,20 @@ async function downloadAssetsFromMessages({
|
|
|
675
779
|
}
|
|
676
780
|
}
|
|
677
781
|
return { mediaType, data };
|
|
678
|
-
}).filter((part) => part.data instanceof URL).map((part) =>
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
782
|
+
}).filter((part) => part.data instanceof URL).map((part) => {
|
|
783
|
+
return {
|
|
784
|
+
url: part.data,
|
|
785
|
+
isUrlSupportedByModel: part.mediaType != null && isUrlSupported({
|
|
786
|
+
url: part.data.toString(),
|
|
787
|
+
mediaType: part.mediaType,
|
|
788
|
+
supportedUrls: supportedUrls ?? {}
|
|
789
|
+
})
|
|
790
|
+
};
|
|
791
|
+
});
|
|
686
792
|
const downloadedFiles = await pMap(
|
|
687
793
|
filesToDownload,
|
|
688
794
|
async (fileItem) => {
|
|
689
|
-
if (
|
|
795
|
+
if (fileItem.isUrlSupportedByModel) {
|
|
690
796
|
return null;
|
|
691
797
|
}
|
|
692
798
|
return {
|
|
@@ -704,105 +810,6 @@ async function downloadAssetsFromMessages({
|
|
|
704
810
|
return Object.fromEntries(downloadFileList);
|
|
705
811
|
}
|
|
706
812
|
|
|
707
|
-
// src/agent/message-list/prompt/image-utils.ts
|
|
708
|
-
function parseDataUri(dataUri) {
|
|
709
|
-
if (!dataUri.startsWith("data:")) {
|
|
710
|
-
return {
|
|
711
|
-
isDataUri: false,
|
|
712
|
-
base64Content: dataUri
|
|
713
|
-
};
|
|
714
|
-
}
|
|
715
|
-
const base64Index = dataUri.indexOf(",");
|
|
716
|
-
if (base64Index === -1) {
|
|
717
|
-
return {
|
|
718
|
-
isDataUri: true,
|
|
719
|
-
base64Content: dataUri
|
|
720
|
-
};
|
|
721
|
-
}
|
|
722
|
-
const header = dataUri.substring(5, base64Index);
|
|
723
|
-
const base64Content = dataUri.substring(base64Index + 1);
|
|
724
|
-
const semicolonIndex = header.indexOf(";");
|
|
725
|
-
const mimeType = semicolonIndex !== -1 ? header.substring(0, semicolonIndex) : header;
|
|
726
|
-
return {
|
|
727
|
-
isDataUri: true,
|
|
728
|
-
mimeType: mimeType || void 0,
|
|
729
|
-
base64Content
|
|
730
|
-
};
|
|
731
|
-
}
|
|
732
|
-
function createDataUri(base64Content, mimeType = "application/octet-stream") {
|
|
733
|
-
if (base64Content.startsWith("data:")) {
|
|
734
|
-
return base64Content;
|
|
735
|
-
}
|
|
736
|
-
return `data:${mimeType};base64,${base64Content}`;
|
|
737
|
-
}
|
|
738
|
-
function imageContentToString(image, fallbackMimeType) {
|
|
739
|
-
if (typeof image === "string") {
|
|
740
|
-
return image;
|
|
741
|
-
}
|
|
742
|
-
if (image instanceof URL) {
|
|
743
|
-
return image.toString();
|
|
744
|
-
}
|
|
745
|
-
if (image instanceof Uint8Array || image instanceof ArrayBuffer || globalThis.Buffer && Buffer.isBuffer(image)) {
|
|
746
|
-
const base64 = convertDataContentToBase64String(image);
|
|
747
|
-
return base64;
|
|
748
|
-
}
|
|
749
|
-
return String(image);
|
|
750
|
-
}
|
|
751
|
-
function getImageCacheKey(image) {
|
|
752
|
-
if (image instanceof URL) {
|
|
753
|
-
return image.toString();
|
|
754
|
-
}
|
|
755
|
-
if (typeof image === "string") {
|
|
756
|
-
return image.length;
|
|
757
|
-
}
|
|
758
|
-
if (image instanceof Uint8Array) {
|
|
759
|
-
return image.byteLength;
|
|
760
|
-
}
|
|
761
|
-
if (image instanceof ArrayBuffer) {
|
|
762
|
-
return image.byteLength;
|
|
763
|
-
}
|
|
764
|
-
return image;
|
|
765
|
-
}
|
|
766
|
-
function isValidUrl(str) {
|
|
767
|
-
try {
|
|
768
|
-
new URL(str);
|
|
769
|
-
return true;
|
|
770
|
-
} catch {
|
|
771
|
-
if (str.startsWith("//")) {
|
|
772
|
-
try {
|
|
773
|
-
new URL(`https:${str}`);
|
|
774
|
-
return true;
|
|
775
|
-
} catch {
|
|
776
|
-
return false;
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
return false;
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
function categorizeFileData(data, fallbackMimeType) {
|
|
783
|
-
const parsed = parseDataUri(data);
|
|
784
|
-
const mimeType = parsed.isDataUri && parsed.mimeType ? parsed.mimeType : fallbackMimeType;
|
|
785
|
-
if (parsed.isDataUri) {
|
|
786
|
-
return {
|
|
787
|
-
type: "dataUri",
|
|
788
|
-
mimeType,
|
|
789
|
-
data
|
|
790
|
-
};
|
|
791
|
-
}
|
|
792
|
-
if (isValidUrl(data)) {
|
|
793
|
-
return {
|
|
794
|
-
type: "url",
|
|
795
|
-
mimeType,
|
|
796
|
-
data
|
|
797
|
-
};
|
|
798
|
-
}
|
|
799
|
-
return {
|
|
800
|
-
type: "raw",
|
|
801
|
-
mimeType,
|
|
802
|
-
data
|
|
803
|
-
};
|
|
804
|
-
}
|
|
805
|
-
|
|
806
813
|
// src/agent/message-list/utils/ai-v5/gemini-compatibility.ts
|
|
807
814
|
function ensureGeminiCompatibleMessages(messages) {
|
|
808
815
|
const result = [...messages];
|
|
@@ -870,6 +877,9 @@ function convertMessages(messages) {
|
|
|
870
877
|
}
|
|
871
878
|
|
|
872
879
|
// src/agent/message-list/index.ts
|
|
880
|
+
function filterDataParts(parts) {
|
|
881
|
+
return parts.filter((part) => !part.type.startsWith("data-"));
|
|
882
|
+
}
|
|
873
883
|
var MessageList = class _MessageList {
|
|
874
884
|
messages = [];
|
|
875
885
|
// passed in by dev in input or context
|
|
@@ -888,6 +898,9 @@ var MessageList = class _MessageList {
|
|
|
888
898
|
userContextMessagesPersisted = /* @__PURE__ */ new Set();
|
|
889
899
|
generateMessageId;
|
|
890
900
|
_agentNetworkAppend = false;
|
|
901
|
+
// Event recording for observability
|
|
902
|
+
isRecording = false;
|
|
903
|
+
recordedEvents = [];
|
|
891
904
|
constructor({
|
|
892
905
|
threadId,
|
|
893
906
|
resourceId,
|
|
@@ -901,10 +914,34 @@ var MessageList = class _MessageList {
|
|
|
901
914
|
this.generateMessageId = generateMessageId;
|
|
902
915
|
this._agentNetworkAppend = _agentNetworkAppend || false;
|
|
903
916
|
}
|
|
917
|
+
/**
|
|
918
|
+
* Start recording mutations to the MessageList for observability/tracing
|
|
919
|
+
*/
|
|
920
|
+
startRecording() {
|
|
921
|
+
this.isRecording = true;
|
|
922
|
+
this.recordedEvents = [];
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Stop recording and return the list of recorded events
|
|
926
|
+
*/
|
|
927
|
+
stopRecording() {
|
|
928
|
+
this.isRecording = false;
|
|
929
|
+
const events = [...this.recordedEvents];
|
|
930
|
+
this.recordedEvents = [];
|
|
931
|
+
return events;
|
|
932
|
+
}
|
|
904
933
|
add(messages, messageSource) {
|
|
905
934
|
if (messageSource === `user`) messageSource = `input`;
|
|
906
935
|
if (!messages) return this;
|
|
907
|
-
|
|
936
|
+
const messageArray = Array.isArray(messages) ? messages : [messages];
|
|
937
|
+
if (this.isRecording) {
|
|
938
|
+
this.recordedEvents.push({
|
|
939
|
+
type: "add",
|
|
940
|
+
source: messageSource,
|
|
941
|
+
count: messageArray.length
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
for (const message of messageArray) {
|
|
908
945
|
this.addOne(
|
|
909
946
|
typeof message === `string` ? {
|
|
910
947
|
role: "user",
|
|
@@ -966,6 +1003,24 @@ var MessageList = class _MessageList {
|
|
|
966
1003
|
this.userContextMessagesPersisted = this.deserializeSet(state.userContextMessagesPersisted);
|
|
967
1004
|
return this;
|
|
968
1005
|
}
|
|
1006
|
+
makeMessageSourceChecker() {
|
|
1007
|
+
const sources = {
|
|
1008
|
+
memory: new Set(Array.from(this.memoryMessages.values()).map((m) => m.id)),
|
|
1009
|
+
output: new Set(Array.from(this.newResponseMessages.values()).map((m) => m.id)),
|
|
1010
|
+
input: new Set(Array.from(this.newUserMessages.values()).map((m) => m.id)),
|
|
1011
|
+
context: new Set(Array.from(this.userContextMessages.values()).map((m) => m.id))
|
|
1012
|
+
};
|
|
1013
|
+
return {
|
|
1014
|
+
...sources,
|
|
1015
|
+
getSource: (msg) => {
|
|
1016
|
+
if (sources.memory.has(msg.id)) return "memory";
|
|
1017
|
+
if (sources.input.has(msg.id)) return "input";
|
|
1018
|
+
if (sources.output.has(msg.id)) return "response";
|
|
1019
|
+
if (sources.context.has(msg.id)) return "context";
|
|
1020
|
+
return null;
|
|
1021
|
+
}
|
|
1022
|
+
};
|
|
1023
|
+
}
|
|
969
1024
|
getLatestUserContent() {
|
|
970
1025
|
const currentUserMessages = this.all.core().filter((m) => m.role === "user");
|
|
971
1026
|
const content = currentUserMessages.at(-1)?.content;
|
|
@@ -990,11 +1045,34 @@ var MessageList = class _MessageList {
|
|
|
990
1045
|
}
|
|
991
1046
|
get clear() {
|
|
992
1047
|
return {
|
|
1048
|
+
all: {
|
|
1049
|
+
db: () => {
|
|
1050
|
+
const allMessages = [...this.messages];
|
|
1051
|
+
this.messages = [];
|
|
1052
|
+
this.newUserMessages.clear();
|
|
1053
|
+
this.newResponseMessages.clear();
|
|
1054
|
+
this.userContextMessages.clear();
|
|
1055
|
+
if (this.isRecording && allMessages.length > 0) {
|
|
1056
|
+
this.recordedEvents.push({
|
|
1057
|
+
type: "clear",
|
|
1058
|
+
count: allMessages.length
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
return allMessages;
|
|
1062
|
+
}
|
|
1063
|
+
},
|
|
993
1064
|
input: {
|
|
994
1065
|
db: () => {
|
|
995
1066
|
const userMessages = Array.from(this.newUserMessages);
|
|
996
1067
|
this.messages = this.messages.filter((m) => !this.newUserMessages.has(m));
|
|
997
1068
|
this.newUserMessages.clear();
|
|
1069
|
+
if (this.isRecording && userMessages.length > 0) {
|
|
1070
|
+
this.recordedEvents.push({
|
|
1071
|
+
type: "clear",
|
|
1072
|
+
source: "input",
|
|
1073
|
+
count: userMessages.length
|
|
1074
|
+
});
|
|
1075
|
+
}
|
|
998
1076
|
return userMessages;
|
|
999
1077
|
}
|
|
1000
1078
|
},
|
|
@@ -1003,11 +1081,46 @@ var MessageList = class _MessageList {
|
|
|
1003
1081
|
const responseMessages = Array.from(this.newResponseMessages);
|
|
1004
1082
|
this.messages = this.messages.filter((m) => !this.newResponseMessages.has(m));
|
|
1005
1083
|
this.newResponseMessages.clear();
|
|
1084
|
+
if (this.isRecording && responseMessages.length > 0) {
|
|
1085
|
+
this.recordedEvents.push({
|
|
1086
|
+
type: "clear",
|
|
1087
|
+
source: "response",
|
|
1088
|
+
count: responseMessages.length
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1006
1091
|
return responseMessages;
|
|
1007
1092
|
}
|
|
1008
1093
|
}
|
|
1009
1094
|
};
|
|
1010
1095
|
}
|
|
1096
|
+
/**
|
|
1097
|
+
* Remove messages by ID
|
|
1098
|
+
* @param ids - Array of message IDs to remove
|
|
1099
|
+
* @returns Array of removed messages
|
|
1100
|
+
*/
|
|
1101
|
+
removeByIds(ids) {
|
|
1102
|
+
const idsSet = new Set(ids);
|
|
1103
|
+
const removed = [];
|
|
1104
|
+
this.messages = this.messages.filter((m) => {
|
|
1105
|
+
if (idsSet.has(m.id)) {
|
|
1106
|
+
removed.push(m);
|
|
1107
|
+
this.memoryMessages.delete(m);
|
|
1108
|
+
this.newUserMessages.delete(m);
|
|
1109
|
+
this.newResponseMessages.delete(m);
|
|
1110
|
+
this.userContextMessages.delete(m);
|
|
1111
|
+
return false;
|
|
1112
|
+
}
|
|
1113
|
+
return true;
|
|
1114
|
+
});
|
|
1115
|
+
if (this.isRecording && removed.length > 0) {
|
|
1116
|
+
this.recordedEvents.push({
|
|
1117
|
+
type: "removeByIds",
|
|
1118
|
+
ids,
|
|
1119
|
+
count: removed.length
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
return removed;
|
|
1123
|
+
}
|
|
1011
1124
|
all = {
|
|
1012
1125
|
db: () => this.messages,
|
|
1013
1126
|
v1: () => convertToV1Messages(this.all.db()),
|
|
@@ -1041,7 +1154,10 @@ var MessageList = class _MessageList {
|
|
|
1041
1154
|
supportedUrls: options?.supportedUrls
|
|
1042
1155
|
});
|
|
1043
1156
|
let messages = [...systemMessages, ...modelMessages];
|
|
1044
|
-
|
|
1157
|
+
const hasImageOrFileContent = modelMessages.some(
|
|
1158
|
+
(message) => message.role === "user" && typeof message.content !== "string" && message.content.some((part) => part.type === "image" || part.type === "file")
|
|
1159
|
+
);
|
|
1160
|
+
if (hasImageOrFileContent) {
|
|
1045
1161
|
messages = messages.map((message) => {
|
|
1046
1162
|
if (message.role === "user") {
|
|
1047
1163
|
if (typeof message.content === "string") {
|
|
@@ -1308,12 +1424,47 @@ var MessageList = class _MessageList {
|
|
|
1308
1424
|
if (unsavedMessages.length === 0) return void 0;
|
|
1309
1425
|
return Math.min(...unsavedMessages.map((m) => new Date(m.createdAt).getTime()));
|
|
1310
1426
|
}
|
|
1427
|
+
/**
|
|
1428
|
+
* Check if a message is a new user or response message that should be saved.
|
|
1429
|
+
* Checks by message ID to handle cases where the message object may be a copy.
|
|
1430
|
+
*/
|
|
1431
|
+
isNewMessage(messageOrId) {
|
|
1432
|
+
const id = typeof messageOrId === "string" ? messageOrId : messageOrId.id;
|
|
1433
|
+
if (typeof messageOrId !== "string") {
|
|
1434
|
+
if (this.newUserMessages.has(messageOrId) || this.newResponseMessages.has(messageOrId)) {
|
|
1435
|
+
return true;
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
return Array.from(this.newUserMessages).some((m) => m.id === id) || Array.from(this.newResponseMessages).some((m) => m.id === id);
|
|
1439
|
+
}
|
|
1311
1440
|
getSystemMessages(tag) {
|
|
1312
1441
|
if (tag) {
|
|
1313
1442
|
return this.taggedSystemMessages[tag] || [];
|
|
1314
1443
|
}
|
|
1315
1444
|
return this.systemMessages;
|
|
1316
1445
|
}
|
|
1446
|
+
/**
|
|
1447
|
+
* Get all system messages (both tagged and untagged)
|
|
1448
|
+
* @returns Array of all system messages
|
|
1449
|
+
*/
|
|
1450
|
+
getAllSystemMessages() {
|
|
1451
|
+
return [...this.systemMessages, ...Object.values(this.taggedSystemMessages).flat()];
|
|
1452
|
+
}
|
|
1453
|
+
/**
|
|
1454
|
+
* Replace all system messages with new ones
|
|
1455
|
+
* This clears both tagged and untagged system messages and replaces them with the provided array
|
|
1456
|
+
* @param messages - Array of system messages to set
|
|
1457
|
+
*/
|
|
1458
|
+
replaceAllSystemMessages(messages) {
|
|
1459
|
+
this.systemMessages = [];
|
|
1460
|
+
this.taggedSystemMessages = {};
|
|
1461
|
+
for (const message of messages) {
|
|
1462
|
+
if (message.role === "system") {
|
|
1463
|
+
this.systemMessages.push(message);
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
return this;
|
|
1467
|
+
}
|
|
1317
1468
|
addSystem(messages, tag) {
|
|
1318
1469
|
if (!messages) return this;
|
|
1319
1470
|
for (const message of Array.isArray(messages) ? messages : [messages]) {
|
|
@@ -1372,8 +1523,21 @@ var MessageList = class _MessageList {
|
|
|
1372
1523
|
if (tag && !this.isDuplicateSystem(coreMessage, tag)) {
|
|
1373
1524
|
this.taggedSystemMessages[tag] ||= [];
|
|
1374
1525
|
this.taggedSystemMessages[tag].push(coreMessage);
|
|
1526
|
+
if (this.isRecording) {
|
|
1527
|
+
this.recordedEvents.push({
|
|
1528
|
+
type: "addSystem",
|
|
1529
|
+
tag,
|
|
1530
|
+
message: coreMessage
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1375
1533
|
} else if (!tag && !this.isDuplicateSystem(coreMessage)) {
|
|
1376
1534
|
this.systemMessages.push(coreMessage);
|
|
1535
|
+
if (this.isRecording) {
|
|
1536
|
+
this.recordedEvents.push({
|
|
1537
|
+
type: "addSystem",
|
|
1538
|
+
message: coreMessage
|
|
1539
|
+
});
|
|
1540
|
+
}
|
|
1377
1541
|
}
|
|
1378
1542
|
}
|
|
1379
1543
|
isDuplicateSystem(message, tag) {
|
|
@@ -1399,9 +1563,20 @@ var MessageList = class _MessageList {
|
|
|
1399
1563
|
if (m.content.parts.length) {
|
|
1400
1564
|
for (const part of m.content.parts) {
|
|
1401
1565
|
if (part.type === `file`) {
|
|
1566
|
+
let normalizedUrl;
|
|
1567
|
+
if (typeof part.data === "string") {
|
|
1568
|
+
const categorized = categorizeFileData(part.data, part.mimeType);
|
|
1569
|
+
if (categorized.type === "raw") {
|
|
1570
|
+
normalizedUrl = createDataUri(part.data, part.mimeType || "application/octet-stream");
|
|
1571
|
+
} else {
|
|
1572
|
+
normalizedUrl = part.data;
|
|
1573
|
+
}
|
|
1574
|
+
} else {
|
|
1575
|
+
normalizedUrl = part.data;
|
|
1576
|
+
}
|
|
1402
1577
|
experimentalAttachments.push({
|
|
1403
1578
|
contentType: part.mimeType,
|
|
1404
|
-
url:
|
|
1579
|
+
url: normalizedUrl
|
|
1405
1580
|
});
|
|
1406
1581
|
} else if (part.type === "tool-invocation" && (part.toolInvocation.state === "call" || part.toolInvocation.state === "partial-call")) {
|
|
1407
1582
|
continue;
|
|
@@ -1439,13 +1614,14 @@ var MessageList = class _MessageList {
|
|
|
1439
1614
|
if (parts.length === 0 && experimentalAttachments.length > 0) {
|
|
1440
1615
|
parts.push({ type: "text", text: "" });
|
|
1441
1616
|
}
|
|
1617
|
+
const v4Parts = filterDataParts(parts);
|
|
1442
1618
|
if (m.role === `user`) {
|
|
1443
1619
|
const uiMessage2 = {
|
|
1444
1620
|
id: m.id,
|
|
1445
1621
|
role: m.role,
|
|
1446
1622
|
content: m.content.content || contentString,
|
|
1447
1623
|
createdAt: m.createdAt,
|
|
1448
|
-
parts,
|
|
1624
|
+
parts: v4Parts,
|
|
1449
1625
|
experimental_attachments: experimentalAttachments
|
|
1450
1626
|
};
|
|
1451
1627
|
if (m.content.metadata) {
|
|
@@ -1459,7 +1635,7 @@ var MessageList = class _MessageList {
|
|
|
1459
1635
|
role: m.role,
|
|
1460
1636
|
content: isSingleTextContentArray ? contentString : m.content.content || contentString,
|
|
1461
1637
|
createdAt: m.createdAt,
|
|
1462
|
-
parts,
|
|
1638
|
+
parts: v4Parts,
|
|
1463
1639
|
reasoning: void 0,
|
|
1464
1640
|
toolInvocations: `toolInvocations` in m.content ? m.content.toolInvocations?.filter((t) => t.state === "result") : void 0
|
|
1465
1641
|
};
|
|
@@ -1473,7 +1649,7 @@ var MessageList = class _MessageList {
|
|
|
1473
1649
|
role: m.role,
|
|
1474
1650
|
content: m.content.content || contentString,
|
|
1475
1651
|
createdAt: m.createdAt,
|
|
1476
|
-
parts,
|
|
1652
|
+
parts: v4Parts,
|
|
1477
1653
|
experimental_attachments: experimentalAttachments
|
|
1478
1654
|
};
|
|
1479
1655
|
if (m.content.metadata) {
|
|
@@ -1642,6 +1818,9 @@ var MessageList = class _MessageList {
|
|
|
1642
1818
|
} else if (messageSource === `response`) {
|
|
1643
1819
|
this.newResponseMessages.add(messageV2);
|
|
1644
1820
|
this.newResponseMessagesPersisted.add(messageV2);
|
|
1821
|
+
if (this.newUserMessages.has(messageV2)) {
|
|
1822
|
+
this.newUserMessages.delete(messageV2);
|
|
1823
|
+
}
|
|
1645
1824
|
} else if (messageSource === `input`) {
|
|
1646
1825
|
this.newUserMessages.add(messageV2);
|
|
1647
1826
|
this.newUserMessagesPersisted.add(messageV2);
|
|
@@ -1666,13 +1845,11 @@ var MessageList = class _MessageList {
|
|
|
1666
1845
|
insertAt
|
|
1667
1846
|
// optional
|
|
1668
1847
|
}) {
|
|
1669
|
-
const partKey = _MessageList.
|
|
1848
|
+
const partKey = _MessageList.cacheKeyFromDBParts([part]);
|
|
1670
1849
|
const latestPartCount = latestMessage.content.parts.filter(
|
|
1671
|
-
(p) => _MessageList.
|
|
1672
|
-
).length;
|
|
1673
|
-
const newPartCount = newMessage.content.parts.filter(
|
|
1674
|
-
(p) => _MessageList.cacheKeyFromAIV4Parts([p]) === partKey
|
|
1850
|
+
(p) => _MessageList.cacheKeyFromDBParts([p]) === partKey
|
|
1675
1851
|
).length;
|
|
1852
|
+
const newPartCount = newMessage.content.parts.filter((p) => _MessageList.cacheKeyFromDBParts([p]) === partKey).length;
|
|
1676
1853
|
if (latestPartCount < newPartCount) {
|
|
1677
1854
|
const partIndex = newMessage.content.parts.indexOf(part);
|
|
1678
1855
|
const hasStepStartBefore = partIndex > 0 && newMessage.content.parts[partIndex - 1]?.type === "step-start";
|
|
@@ -1708,7 +1885,7 @@ var MessageList = class _MessageList {
|
|
|
1708
1885
|
for (let i = 0; i < messageV2.content.parts.length; ++i) {
|
|
1709
1886
|
const part = messageV2.content.parts[i];
|
|
1710
1887
|
if (!part) continue;
|
|
1711
|
-
const key = _MessageList.
|
|
1888
|
+
const key = _MessageList.cacheKeyFromDBParts([part]);
|
|
1712
1889
|
const partToAdd = partsToAdd.get(i);
|
|
1713
1890
|
if (!key || !partToAdd) continue;
|
|
1714
1891
|
if (anchorMap.size > 0) {
|
|
@@ -1719,7 +1896,7 @@ var MessageList = class _MessageList {
|
|
|
1719
1896
|
const offset = leftAnchorV2 === -1 ? i : i - leftAnchorV2;
|
|
1720
1897
|
const insertAt = leftAnchorLatest + offset;
|
|
1721
1898
|
const rightAnchorLatest = rightAnchorV2 !== -1 ? anchorMap.get(rightAnchorV2) : latestMessage.content.parts.length;
|
|
1722
|
-
if (insertAt >= 0 && insertAt <= rightAnchorLatest && !latestMessage.content.parts.slice(insertAt, rightAnchorLatest).some((p) => _MessageList.
|
|
1899
|
+
if (insertAt >= 0 && insertAt <= rightAnchorLatest && !latestMessage.content.parts.slice(insertAt, rightAnchorLatest).some((p) => _MessageList.cacheKeyFromDBParts([p]) === _MessageList.cacheKeyFromDBParts([part]))) {
|
|
1723
1900
|
this.pushNewMessagePart({
|
|
1724
1901
|
latestMessage,
|
|
1725
1902
|
newMessage: messageV2,
|
|
@@ -1770,8 +1947,10 @@ var MessageList = class _MessageList {
|
|
|
1770
1947
|
}
|
|
1771
1948
|
if (_MessageList.isAIV5CoreMessage(message)) {
|
|
1772
1949
|
const dbMsg = _MessageList.aiV5ModelMessageToMastraDBMessage(message, messageSource);
|
|
1950
|
+
const rawCreatedAt = "metadata" in message && message.metadata && typeof message.metadata === "object" && "createdAt" in message.metadata ? message.metadata.createdAt : void 0;
|
|
1773
1951
|
const result = {
|
|
1774
1952
|
...dbMsg,
|
|
1953
|
+
createdAt: this.generateCreatedAt(messageSource, rawCreatedAt),
|
|
1775
1954
|
threadId: this.memoryInfo?.threadId,
|
|
1776
1955
|
resourceId: this.memoryInfo?.resourceId
|
|
1777
1956
|
};
|
|
@@ -1779,8 +1958,10 @@ var MessageList = class _MessageList {
|
|
|
1779
1958
|
}
|
|
1780
1959
|
if (_MessageList.isAIV5UIMessage(message)) {
|
|
1781
1960
|
const dbMsg = _MessageList.aiV5UIMessageToMastraDBMessage(message);
|
|
1961
|
+
const rawCreatedAt = "createdAt" in message ? message.createdAt : void 0;
|
|
1782
1962
|
return {
|
|
1783
1963
|
...dbMsg,
|
|
1964
|
+
createdAt: this.generateCreatedAt(messageSource, rawCreatedAt),
|
|
1784
1965
|
threadId: this.memoryInfo?.threadId,
|
|
1785
1966
|
resourceId: this.memoryInfo?.resourceId
|
|
1786
1967
|
};
|
|
@@ -1790,16 +1971,16 @@ var MessageList = class _MessageList {
|
|
|
1790
1971
|
lastCreatedAt;
|
|
1791
1972
|
// this makes sure messages added in order will always have a date atleast 1ms apart.
|
|
1792
1973
|
generateCreatedAt(messageSource, start) {
|
|
1793
|
-
|
|
1794
|
-
if (
|
|
1795
|
-
this.lastCreatedAt =
|
|
1796
|
-
return
|
|
1974
|
+
const startDate = start instanceof Date ? start : typeof start === "string" || typeof start === "number" ? new Date(start) : void 0;
|
|
1975
|
+
if (startDate && !this.lastCreatedAt) {
|
|
1976
|
+
this.lastCreatedAt = startDate.getTime();
|
|
1977
|
+
return startDate;
|
|
1797
1978
|
}
|
|
1798
|
-
if (
|
|
1799
|
-
return
|
|
1979
|
+
if (startDate && messageSource === `memory`) {
|
|
1980
|
+
return startDate;
|
|
1800
1981
|
}
|
|
1801
1982
|
const now = /* @__PURE__ */ new Date();
|
|
1802
|
-
const nowTime =
|
|
1983
|
+
const nowTime = startDate?.getTime() || now.getTime();
|
|
1803
1984
|
const lastTime = this.messages.reduce((p, m) => {
|
|
1804
1985
|
if (m.createdAt.getTime() > p) return m.createdAt.getTime();
|
|
1805
1986
|
return p;
|
|
@@ -1853,6 +2034,12 @@ var MessageList = class _MessageList {
|
|
|
1853
2034
|
return ti;
|
|
1854
2035
|
});
|
|
1855
2036
|
}
|
|
2037
|
+
if (!message.threadId && this.memoryInfo?.threadId) {
|
|
2038
|
+
message.threadId = this.memoryInfo.threadId;
|
|
2039
|
+
if (!message.resourceId && this.memoryInfo?.resourceId) {
|
|
2040
|
+
message.resourceId = this.memoryInfo.resourceId;
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
1856
2043
|
return message;
|
|
1857
2044
|
}
|
|
1858
2045
|
aiV4UIMessageToMastraDBMessage(message, messageSource) {
|
|
@@ -1890,137 +2077,180 @@ var MessageList = class _MessageList {
|
|
|
1890
2077
|
if (typeof coreMessage.content === "string") {
|
|
1891
2078
|
parts.push({
|
|
1892
2079
|
type: "text",
|
|
1893
|
-
text: coreMessage.content
|
|
1894
|
-
// Preserve providerOptions from CoreMessage (e.g., for system messages with cacheControl)
|
|
1895
|
-
..."providerOptions" in coreMessage && coreMessage.providerOptions ? { providerMetadata: coreMessage.providerOptions } : {}
|
|
2080
|
+
text: coreMessage.content
|
|
1896
2081
|
});
|
|
1897
2082
|
} else if (Array.isArray(coreMessage.content)) {
|
|
1898
|
-
for (const
|
|
1899
|
-
switch (
|
|
1900
|
-
case "text":
|
|
2083
|
+
for (const aiV4Part of coreMessage.content) {
|
|
2084
|
+
switch (aiV4Part.type) {
|
|
2085
|
+
case "text": {
|
|
1901
2086
|
const prevPart = parts.at(-1);
|
|
1902
2087
|
if (coreMessage.role === "assistant" && prevPart && prevPart.type === "tool-invocation") {
|
|
1903
2088
|
parts.push({ type: "step-start" });
|
|
1904
2089
|
}
|
|
1905
|
-
const
|
|
1906
|
-
..."providerOptions" in coreMessage && coreMessage.providerOptions ? coreMessage.providerOptions : {},
|
|
1907
|
-
..."providerOptions" in part && part.providerOptions ? part.providerOptions : {}
|
|
1908
|
-
};
|
|
1909
|
-
parts.push({
|
|
2090
|
+
const part = {
|
|
1910
2091
|
type: "text",
|
|
1911
|
-
text:
|
|
1912
|
-
|
|
1913
|
-
|
|
2092
|
+
text: aiV4Part.text
|
|
2093
|
+
};
|
|
2094
|
+
if (aiV4Part.providerOptions) {
|
|
2095
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2096
|
+
}
|
|
2097
|
+
parts.push(part);
|
|
1914
2098
|
break;
|
|
1915
|
-
|
|
1916
|
-
|
|
2099
|
+
}
|
|
2100
|
+
case "tool-call": {
|
|
2101
|
+
const part = {
|
|
1917
2102
|
type: "tool-invocation",
|
|
1918
2103
|
toolInvocation: {
|
|
1919
2104
|
state: "call",
|
|
1920
|
-
toolCallId:
|
|
1921
|
-
toolName:
|
|
1922
|
-
args:
|
|
2105
|
+
toolCallId: aiV4Part.toolCallId,
|
|
2106
|
+
toolName: aiV4Part.toolName,
|
|
2107
|
+
args: aiV4Part.args
|
|
1923
2108
|
}
|
|
1924
|
-
}
|
|
2109
|
+
};
|
|
2110
|
+
if (aiV4Part.providerOptions) {
|
|
2111
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2112
|
+
}
|
|
2113
|
+
parts.push(part);
|
|
1925
2114
|
break;
|
|
2115
|
+
}
|
|
1926
2116
|
case "tool-result":
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
2117
|
+
{
|
|
2118
|
+
let toolArgs = {};
|
|
2119
|
+
const toolCallInSameMsg = coreMessage.content.find(
|
|
2120
|
+
(p) => p.type === "tool-call" && p.toolCallId === aiV4Part.toolCallId
|
|
2121
|
+
);
|
|
2122
|
+
if (toolCallInSameMsg && toolCallInSameMsg.type === "tool-call") {
|
|
2123
|
+
toolArgs = toolCallInSameMsg.args;
|
|
2124
|
+
}
|
|
2125
|
+
if (Object.keys(toolArgs).length === 0) {
|
|
2126
|
+
for (let i = this.messages.length - 1; i >= 0; i--) {
|
|
2127
|
+
const msg = this.messages[i];
|
|
2128
|
+
if (msg && msg.role === "assistant" && msg.content.parts) {
|
|
2129
|
+
const toolCallPart = msg.content.parts.find(
|
|
2130
|
+
(p) => p.type === "tool-invocation" && p.toolInvocation.toolCallId === aiV4Part.toolCallId && p.toolInvocation.state === "call"
|
|
2131
|
+
);
|
|
2132
|
+
if (toolCallPart && toolCallPart.type === "tool-invocation" && toolCallPart.toolInvocation.args) {
|
|
2133
|
+
toolArgs = toolCallPart.toolInvocation.args;
|
|
2134
|
+
break;
|
|
2135
|
+
}
|
|
1944
2136
|
}
|
|
1945
2137
|
}
|
|
1946
2138
|
}
|
|
2139
|
+
const invocation = {
|
|
2140
|
+
state: "result",
|
|
2141
|
+
toolCallId: aiV4Part.toolCallId,
|
|
2142
|
+
toolName: aiV4Part.toolName,
|
|
2143
|
+
result: aiV4Part.result ?? "",
|
|
2144
|
+
// undefined will cause AI SDK to throw an error, but for client side tool calls this really could be undefined
|
|
2145
|
+
args: toolArgs
|
|
2146
|
+
// Use the args from the corresponding tool-call
|
|
2147
|
+
};
|
|
2148
|
+
const part = {
|
|
2149
|
+
type: "tool-invocation",
|
|
2150
|
+
toolInvocation: invocation
|
|
2151
|
+
};
|
|
2152
|
+
if (aiV4Part.providerOptions) {
|
|
2153
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2154
|
+
}
|
|
2155
|
+
parts.push(part);
|
|
2156
|
+
toolInvocations.push(invocation);
|
|
1947
2157
|
}
|
|
1948
|
-
const invocation = {
|
|
1949
|
-
state: "result",
|
|
1950
|
-
toolCallId: part.toolCallId,
|
|
1951
|
-
toolName: part.toolName,
|
|
1952
|
-
result: part.result ?? "",
|
|
1953
|
-
// undefined will cause AI SDK to throw an error, but for client side tool calls this really could be undefined
|
|
1954
|
-
args: toolArgs
|
|
1955
|
-
// Use the args from the corresponding tool-call
|
|
1956
|
-
};
|
|
1957
|
-
parts.push({
|
|
1958
|
-
type: "tool-invocation",
|
|
1959
|
-
toolInvocation: invocation
|
|
1960
|
-
});
|
|
1961
|
-
toolInvocations.push(invocation);
|
|
1962
2158
|
break;
|
|
1963
2159
|
case "reasoning":
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
2160
|
+
{
|
|
2161
|
+
const part = {
|
|
2162
|
+
type: "reasoning",
|
|
2163
|
+
reasoning: "",
|
|
2164
|
+
// leave this blank so we aren't double storing it in the db along with details
|
|
2165
|
+
details: [{ type: "text", text: aiV4Part.text, signature: aiV4Part.signature }]
|
|
2166
|
+
};
|
|
2167
|
+
if (aiV4Part.providerOptions) {
|
|
2168
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2169
|
+
}
|
|
2170
|
+
parts.push(part);
|
|
2171
|
+
}
|
|
1970
2172
|
break;
|
|
1971
2173
|
case "redacted-reasoning":
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
2174
|
+
{
|
|
2175
|
+
const part = {
|
|
2176
|
+
type: "reasoning",
|
|
2177
|
+
reasoning: "",
|
|
2178
|
+
// No text reasoning for redacted parts
|
|
2179
|
+
details: [{ type: "redacted", data: aiV4Part.data }]
|
|
2180
|
+
};
|
|
2181
|
+
if (aiV4Part.providerOptions) {
|
|
2182
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2183
|
+
}
|
|
2184
|
+
parts.push(part);
|
|
2185
|
+
}
|
|
1978
2186
|
break;
|
|
1979
|
-
case "image":
|
|
1980
|
-
|
|
2187
|
+
case "image": {
|
|
2188
|
+
const part = {
|
|
1981
2189
|
type: "file",
|
|
1982
|
-
data: imageContentToString(
|
|
1983
|
-
mimeType:
|
|
1984
|
-
}
|
|
2190
|
+
data: imageContentToString(aiV4Part.image),
|
|
2191
|
+
mimeType: aiV4Part.mimeType
|
|
2192
|
+
};
|
|
2193
|
+
if (aiV4Part.providerOptions) {
|
|
2194
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2195
|
+
}
|
|
2196
|
+
parts.push(part);
|
|
1985
2197
|
break;
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
2198
|
+
}
|
|
2199
|
+
case "file": {
|
|
2200
|
+
if (aiV4Part.data instanceof URL) {
|
|
2201
|
+
const part = {
|
|
1989
2202
|
type: "file",
|
|
1990
|
-
data:
|
|
1991
|
-
mimeType:
|
|
1992
|
-
}
|
|
1993
|
-
|
|
1994
|
-
|
|
2203
|
+
data: aiV4Part.data.toString(),
|
|
2204
|
+
mimeType: aiV4Part.mimeType
|
|
2205
|
+
};
|
|
2206
|
+
if (aiV4Part.providerOptions) {
|
|
2207
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2208
|
+
}
|
|
2209
|
+
parts.push(part);
|
|
2210
|
+
} else if (typeof aiV4Part.data === "string") {
|
|
2211
|
+
const categorized = categorizeFileData(aiV4Part.data, aiV4Part.mimeType);
|
|
1995
2212
|
if (categorized.type === "url" || categorized.type === "dataUri") {
|
|
1996
|
-
|
|
2213
|
+
const part = {
|
|
1997
2214
|
type: "file",
|
|
1998
|
-
data:
|
|
2215
|
+
data: aiV4Part.data,
|
|
1999
2216
|
mimeType: categorized.mimeType || "image/png"
|
|
2000
|
-
}
|
|
2217
|
+
};
|
|
2218
|
+
if (aiV4Part.providerOptions) {
|
|
2219
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2220
|
+
}
|
|
2221
|
+
parts.push(part);
|
|
2001
2222
|
} else {
|
|
2002
2223
|
try {
|
|
2003
|
-
|
|
2224
|
+
const part = {
|
|
2004
2225
|
type: "file",
|
|
2005
2226
|
mimeType: categorized.mimeType || "image/png",
|
|
2006
|
-
data: convertDataContentToBase64String(
|
|
2007
|
-
}
|
|
2227
|
+
data: convertDataContentToBase64String(aiV4Part.data)
|
|
2228
|
+
};
|
|
2229
|
+
if (aiV4Part.providerOptions) {
|
|
2230
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2231
|
+
}
|
|
2232
|
+
parts.push(part);
|
|
2008
2233
|
} catch (error) {
|
|
2009
2234
|
console.error(`Failed to convert binary data to base64 in CoreMessage file part: ${error}`, error);
|
|
2010
2235
|
}
|
|
2011
2236
|
}
|
|
2012
2237
|
} else {
|
|
2013
2238
|
try {
|
|
2014
|
-
|
|
2239
|
+
const part = {
|
|
2015
2240
|
type: "file",
|
|
2016
|
-
mimeType:
|
|
2017
|
-
data: convertDataContentToBase64String(
|
|
2018
|
-
}
|
|
2241
|
+
mimeType: aiV4Part.mimeType,
|
|
2242
|
+
data: convertDataContentToBase64String(aiV4Part.data)
|
|
2243
|
+
};
|
|
2244
|
+
if (aiV4Part.providerOptions) {
|
|
2245
|
+
part.providerMetadata = aiV4Part.providerOptions;
|
|
2246
|
+
}
|
|
2247
|
+
parts.push(part);
|
|
2019
2248
|
} catch (error) {
|
|
2020
2249
|
console.error(`Failed to convert binary data to base64 in CoreMessage file part: ${error}`, error);
|
|
2021
2250
|
}
|
|
2022
2251
|
}
|
|
2023
2252
|
break;
|
|
2253
|
+
}
|
|
2024
2254
|
}
|
|
2025
2255
|
}
|
|
2026
2256
|
}
|
|
@@ -2031,10 +2261,17 @@ var MessageList = class _MessageList {
|
|
|
2031
2261
|
if (toolInvocations.length) content.toolInvocations = toolInvocations;
|
|
2032
2262
|
if (typeof coreMessage.content === `string`) content.content = coreMessage.content;
|
|
2033
2263
|
if (experimentalAttachments.length) content.experimental_attachments = experimentalAttachments;
|
|
2264
|
+
if (coreMessage.providerOptions) {
|
|
2265
|
+
content.providerMetadata = coreMessage.providerOptions;
|
|
2266
|
+
}
|
|
2267
|
+
if ("metadata" in coreMessage && coreMessage.metadata !== null && coreMessage.metadata !== void 0) {
|
|
2268
|
+
content.metadata = coreMessage.metadata;
|
|
2269
|
+
}
|
|
2270
|
+
const rawCreatedAt = "metadata" in coreMessage && coreMessage.metadata && typeof coreMessage.metadata === "object" && "createdAt" in coreMessage.metadata ? coreMessage.metadata.createdAt : void 0;
|
|
2034
2271
|
return {
|
|
2035
2272
|
id,
|
|
2036
2273
|
role: _MessageList.getRole(coreMessage),
|
|
2037
|
-
createdAt: this.generateCreatedAt(messageSource),
|
|
2274
|
+
createdAt: this.generateCreatedAt(messageSource, rawCreatedAt),
|
|
2038
2275
|
threadId: this.memoryInfo?.threadId,
|
|
2039
2276
|
resourceId: this.memoryInfo?.resourceId,
|
|
2040
2277
|
content
|
|
@@ -2072,25 +2309,48 @@ var MessageList = class _MessageList {
|
|
|
2072
2309
|
let key = ``;
|
|
2073
2310
|
for (const part of parts) {
|
|
2074
2311
|
key += part.type;
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2312
|
+
key += _MessageList.cacheKeyFromAIV4Part(part);
|
|
2313
|
+
}
|
|
2314
|
+
return key;
|
|
2315
|
+
}
|
|
2316
|
+
static cacheKeyFromAIV4Part(part) {
|
|
2317
|
+
let cacheKey = "";
|
|
2318
|
+
if (part.type === `text`) {
|
|
2319
|
+
cacheKey += part.text;
|
|
2320
|
+
}
|
|
2321
|
+
if (part.type === `tool-invocation`) {
|
|
2322
|
+
cacheKey += part.toolInvocation.toolCallId;
|
|
2323
|
+
cacheKey += part.toolInvocation.state;
|
|
2324
|
+
}
|
|
2325
|
+
if (part.type === `reasoning`) {
|
|
2326
|
+
cacheKey += part.reasoning;
|
|
2327
|
+
cacheKey += part.details.reduce((prev, current) => {
|
|
2328
|
+
if (current.type === `text`) {
|
|
2329
|
+
return prev + current.text.length + (current.signature?.length || 0);
|
|
2330
|
+
}
|
|
2331
|
+
return prev;
|
|
2332
|
+
}, 0);
|
|
2333
|
+
const partAny = part;
|
|
2334
|
+
if (partAny && Object.hasOwn(partAny, "providerMetadata") && partAny.providerMetadata && Object.hasOwn(partAny.providerMetadata, "openai") && partAny.providerMetadata.openai && Object.hasOwn(partAny.providerMetadata.openai, "itemId")) {
|
|
2335
|
+
const itemId = partAny.providerMetadata.openai.itemId;
|
|
2336
|
+
cacheKey += `|${itemId}`;
|
|
2090
2337
|
}
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2338
|
+
}
|
|
2339
|
+
if (part.type === `file`) {
|
|
2340
|
+
cacheKey += part.data;
|
|
2341
|
+
cacheKey += part.mimeType;
|
|
2342
|
+
}
|
|
2343
|
+
return cacheKey;
|
|
2344
|
+
}
|
|
2345
|
+
static cacheKeyFromDBParts(parts) {
|
|
2346
|
+
let key = ``;
|
|
2347
|
+
for (const part of parts) {
|
|
2348
|
+
key += part.type;
|
|
2349
|
+
if (part.type.startsWith("data-")) {
|
|
2350
|
+
const data = part.data;
|
|
2351
|
+
key += JSON.stringify(data);
|
|
2352
|
+
} else {
|
|
2353
|
+
key += _MessageList.cacheKeyFromAIV4Part(part);
|
|
2094
2354
|
}
|
|
2095
2355
|
}
|
|
2096
2356
|
return key;
|
|
@@ -2160,7 +2420,7 @@ var MessageList = class _MessageList {
|
|
|
2160
2420
|
const twoMM2 = _MessageList.isMastraDBMessage(two) && two;
|
|
2161
2421
|
if (oneMM2 && !twoMM2) return false;
|
|
2162
2422
|
if (oneMM2 && twoMM2) {
|
|
2163
|
-
return oneMM2.id === twoMM2.id && _MessageList.
|
|
2423
|
+
return oneMM2.id === twoMM2.id && _MessageList.cacheKeyFromDBParts(oneMM2.content.parts) === _MessageList.cacheKeyFromDBParts(twoMM2.content.parts);
|
|
2164
2424
|
}
|
|
2165
2425
|
const oneUIV5 = _MessageList.isAIV5UIMessage(one) && one;
|
|
2166
2426
|
const twoUIV5 = _MessageList.isAIV5UIMessage(two) && two;
|
|
@@ -2233,9 +2493,23 @@ var MessageList = class _MessageList {
|
|
|
2233
2493
|
if (role === `tool` || role === `assistant`) {
|
|
2234
2494
|
throw new Error(incompatibleMessage);
|
|
2235
2495
|
}
|
|
2496
|
+
let processedImage;
|
|
2497
|
+
if (part.image instanceof URL || part.image instanceof Uint8Array) {
|
|
2498
|
+
processedImage = part.image;
|
|
2499
|
+
} else if (Buffer.isBuffer(part.image) || part.image instanceof ArrayBuffer) {
|
|
2500
|
+
processedImage = new Uint8Array(part.image);
|
|
2501
|
+
} else {
|
|
2502
|
+
const categorized = categorizeFileData(part.image, part.mimeType);
|
|
2503
|
+
if (categorized.type === "raw") {
|
|
2504
|
+
const dataUri = createDataUri(part.image, part.mimeType || "image/png");
|
|
2505
|
+
processedImage = new URL(dataUri);
|
|
2506
|
+
} else {
|
|
2507
|
+
processedImage = new URL(part.image);
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2236
2510
|
roleContent[role].push({
|
|
2237
2511
|
...part,
|
|
2238
|
-
image:
|
|
2512
|
+
image: processedImage
|
|
2239
2513
|
});
|
|
2240
2514
|
break;
|
|
2241
2515
|
}
|
|
@@ -2381,6 +2655,9 @@ var MessageList = class _MessageList {
|
|
|
2381
2655
|
if (dbMsg.createdAt) metadata.createdAt = dbMsg.createdAt;
|
|
2382
2656
|
if (dbMsg.threadId) metadata.threadId = dbMsg.threadId;
|
|
2383
2657
|
if (dbMsg.resourceId) metadata.resourceId = dbMsg.resourceId;
|
|
2658
|
+
if (dbMsg.content.providerMetadata) {
|
|
2659
|
+
metadata.providerMetadata = dbMsg.content.providerMetadata;
|
|
2660
|
+
}
|
|
2384
2661
|
const hasToolInvocationParts = dbMsg.content.parts?.some((p) => p.type === "tool-invocation");
|
|
2385
2662
|
if (dbMsg.content.toolInvocations && !hasToolInvocationParts) {
|
|
2386
2663
|
for (const invocation of dbMsg.content.toolInvocations) {
|
|
@@ -2447,18 +2724,20 @@ var MessageList = class _MessageList {
|
|
|
2447
2724
|
continue;
|
|
2448
2725
|
}
|
|
2449
2726
|
if (part.type === "reasoning") {
|
|
2450
|
-
const
|
|
2451
|
-
const text = reasoningPart.text || reasoningPart.reasoning || (reasoningPart.details?.reduce((p, c) => {
|
|
2727
|
+
const text = part.reasoning || (part.details?.reduce((p, c) => {
|
|
2452
2728
|
if (c.type === `text` && c.text) return p + c.text;
|
|
2453
2729
|
return p;
|
|
2454
2730
|
}, "") ?? "");
|
|
2455
|
-
if (text ||
|
|
2456
|
-
|
|
2731
|
+
if (text || part.details?.length) {
|
|
2732
|
+
const v5UIPart = {
|
|
2457
2733
|
type: "reasoning",
|
|
2458
2734
|
text: text || "",
|
|
2459
|
-
state: "done"
|
|
2460
|
-
|
|
2461
|
-
|
|
2735
|
+
state: "done"
|
|
2736
|
+
};
|
|
2737
|
+
if (part.providerMetadata) {
|
|
2738
|
+
v5UIPart.providerMetadata = part.providerMetadata;
|
|
2739
|
+
}
|
|
2740
|
+
parts.push(v5UIPart);
|
|
2462
2741
|
}
|
|
2463
2742
|
continue;
|
|
2464
2743
|
}
|
|
@@ -2471,12 +2750,15 @@ var MessageList = class _MessageList {
|
|
|
2471
2750
|
}
|
|
2472
2751
|
const categorized = typeof part.data === "string" ? categorizeFileData(part.data, part.mimeType) : { type: "raw", mimeType: part.mimeType};
|
|
2473
2752
|
if (categorized.type === "url" && typeof part.data === "string") {
|
|
2474
|
-
|
|
2753
|
+
const v5UIPart = {
|
|
2475
2754
|
type: "file",
|
|
2476
2755
|
url: part.data,
|
|
2477
|
-
mediaType: categorized.mimeType || "image/png"
|
|
2478
|
-
|
|
2479
|
-
|
|
2756
|
+
mediaType: categorized.mimeType || "image/png"
|
|
2757
|
+
};
|
|
2758
|
+
if (part.providerMetadata) {
|
|
2759
|
+
v5UIPart.providerMetadata = part.providerMetadata;
|
|
2760
|
+
}
|
|
2761
|
+
parts.push(v5UIPart);
|
|
2480
2762
|
} else {
|
|
2481
2763
|
let filePartData;
|
|
2482
2764
|
let extractedMimeType = part.mimeType;
|
|
@@ -2500,27 +2782,37 @@ var MessageList = class _MessageList {
|
|
|
2500
2782
|
} else {
|
|
2501
2783
|
dataUri = createDataUri(filePartData, finalMimeType);
|
|
2502
2784
|
}
|
|
2503
|
-
|
|
2785
|
+
const v5UIPart = {
|
|
2504
2786
|
type: "file",
|
|
2505
2787
|
url: dataUri,
|
|
2506
2788
|
// Use url field with data URI
|
|
2507
|
-
mediaType: finalMimeType
|
|
2508
|
-
|
|
2509
|
-
|
|
2789
|
+
mediaType: finalMimeType
|
|
2790
|
+
};
|
|
2791
|
+
if (part.providerMetadata) {
|
|
2792
|
+
v5UIPart.providerMetadata = part.providerMetadata;
|
|
2793
|
+
}
|
|
2794
|
+
parts.push(v5UIPart);
|
|
2510
2795
|
}
|
|
2511
2796
|
} else if (part.type === "source") {
|
|
2512
|
-
const
|
|
2513
|
-
parts.push({
|
|
2797
|
+
const v5UIPart = {
|
|
2514
2798
|
type: "source-url",
|
|
2515
|
-
url:
|
|
2516
|
-
|
|
2517
|
-
|
|
2799
|
+
url: part.source.url,
|
|
2800
|
+
sourceId: part.source.id,
|
|
2801
|
+
title: part.source.title
|
|
2802
|
+
};
|
|
2803
|
+
if (part.providerMetadata) {
|
|
2804
|
+
v5UIPart.providerMetadata = part.providerMetadata;
|
|
2805
|
+
}
|
|
2806
|
+
parts.push(v5UIPart);
|
|
2518
2807
|
} else if (part.type === "text") {
|
|
2519
|
-
|
|
2808
|
+
const v5UIPart = {
|
|
2520
2809
|
type: "text",
|
|
2521
|
-
text: part.text
|
|
2522
|
-
|
|
2523
|
-
|
|
2810
|
+
text: part.text
|
|
2811
|
+
};
|
|
2812
|
+
if (part.providerMetadata) {
|
|
2813
|
+
v5UIPart.providerMetadata = part.providerMetadata;
|
|
2814
|
+
}
|
|
2815
|
+
parts.push(v5UIPart);
|
|
2524
2816
|
hasNonToolReasoningParts = true;
|
|
2525
2817
|
} else {
|
|
2526
2818
|
parts.push(part);
|
|
@@ -2684,32 +2976,69 @@ var MessageList = class _MessageList {
|
|
|
2684
2976
|
}
|
|
2685
2977
|
};
|
|
2686
2978
|
}
|
|
2979
|
+
/**
|
|
2980
|
+
* Convert image or file to data URI or URL for V2 file part
|
|
2981
|
+
*/
|
|
2982
|
+
static getDataStringFromAIV5DataPart = (part) => {
|
|
2983
|
+
let mimeType;
|
|
2984
|
+
let data;
|
|
2985
|
+
if ("data" in part) {
|
|
2986
|
+
mimeType = part.mediaType || "application/octet-stream";
|
|
2987
|
+
data = part.data;
|
|
2988
|
+
} else if ("image" in part) {
|
|
2989
|
+
mimeType = part.mediaType || "image/jpeg";
|
|
2990
|
+
data = part.image;
|
|
2991
|
+
} else {
|
|
2992
|
+
throw new MastraError({
|
|
2993
|
+
id: "MASTRA_AIV5_DATA_PART_INVALID",
|
|
2994
|
+
domain: "AGENT" /* AGENT */,
|
|
2995
|
+
category: "USER" /* USER */,
|
|
2996
|
+
text: "Invalid AIV5 data part in getDataStringFromAIV5DataPart",
|
|
2997
|
+
details: {
|
|
2998
|
+
part
|
|
2999
|
+
}
|
|
3000
|
+
});
|
|
3001
|
+
}
|
|
3002
|
+
if (data instanceof URL) {
|
|
3003
|
+
return data.toString();
|
|
3004
|
+
} else {
|
|
3005
|
+
if (data instanceof Buffer) {
|
|
3006
|
+
const base64 = data.toString("base64");
|
|
3007
|
+
return `data:${mimeType};base64,${base64}`;
|
|
3008
|
+
} else if (typeof data === "string") {
|
|
3009
|
+
return data.startsWith("data:") || data.startsWith("http") ? data : `data:${mimeType};base64,${data}`;
|
|
3010
|
+
} else if (data instanceof Uint8Array) {
|
|
3011
|
+
const base64 = Buffer.from(data).toString("base64");
|
|
3012
|
+
return `data:${mimeType};base64,${base64}`;
|
|
3013
|
+
} else if (data instanceof ArrayBuffer) {
|
|
3014
|
+
const base64 = Buffer.from(data).toString("base64");
|
|
3015
|
+
return `data:${mimeType};base64,${base64}`;
|
|
3016
|
+
} else {
|
|
3017
|
+
return "";
|
|
3018
|
+
}
|
|
3019
|
+
}
|
|
3020
|
+
};
|
|
2687
3021
|
/**
|
|
2688
3022
|
* Direct conversion from AIV5 ModelMessage to MastraDBMessage
|
|
2689
3023
|
* Combines logic from aiV5ModelMessageToMastraMessageV3 + mastraMessageV3ToV2
|
|
2690
3024
|
*/
|
|
2691
3025
|
static aiV5ModelMessageToMastraDBMessage(modelMsg, _messageSource) {
|
|
2692
3026
|
const content = Array.isArray(modelMsg.content) ? modelMsg.content : [{ type: "text", text: modelMsg.content }];
|
|
2693
|
-
const
|
|
3027
|
+
const mastraDBParts = [];
|
|
2694
3028
|
const toolInvocations = [];
|
|
2695
3029
|
const reasoningParts = [];
|
|
2696
3030
|
const experimental_attachments = [];
|
|
2697
|
-
const textParts = [];
|
|
2698
3031
|
let lastPartWasToolResult = false;
|
|
2699
3032
|
for (const part of content) {
|
|
2700
|
-
const providerMetadata = {
|
|
2701
|
-
...modelMsg.providerMetadata || {},
|
|
2702
|
-
...part.providerMetadata || {}
|
|
2703
|
-
};
|
|
2704
|
-
const hasProviderMetadata = Object.keys(providerMetadata).length > 0;
|
|
2705
3033
|
if (part.type === "text") {
|
|
2706
3034
|
const textPart = {
|
|
2707
3035
|
type: "text",
|
|
2708
|
-
text: part.text
|
|
2709
|
-
...hasProviderMetadata && { experimental_providerMetadata: providerMetadata }
|
|
3036
|
+
text: part.text
|
|
2710
3037
|
};
|
|
2711
|
-
|
|
2712
|
-
|
|
3038
|
+
if (part.providerOptions) {
|
|
3039
|
+
textPart.providerMetadata = part.providerOptions;
|
|
3040
|
+
}
|
|
3041
|
+
mastraDBParts.push(textPart);
|
|
2713
3042
|
lastPartWasToolResult = false;
|
|
2714
3043
|
} else if (part.type === "tool-call") {
|
|
2715
3044
|
const toolCallPart = part;
|
|
@@ -2720,10 +3049,12 @@ var MessageList = class _MessageList {
|
|
|
2720
3049
|
toolName: toolCallPart.toolName,
|
|
2721
3050
|
args: toolCallPart.input,
|
|
2722
3051
|
state: "call"
|
|
2723
|
-
}
|
|
2724
|
-
...hasProviderMetadata && { providerMetadata }
|
|
3052
|
+
}
|
|
2725
3053
|
};
|
|
2726
|
-
|
|
3054
|
+
if (part.providerOptions) {
|
|
3055
|
+
toolInvocationPart.providerMetadata = part.providerOptions;
|
|
3056
|
+
}
|
|
3057
|
+
mastraDBParts.push(toolInvocationPart);
|
|
2727
3058
|
toolInvocations.push({
|
|
2728
3059
|
toolCallId: toolCallPart.toolCallId,
|
|
2729
3060
|
toolName: toolCallPart.toolName,
|
|
@@ -2734,78 +3065,67 @@ var MessageList = class _MessageList {
|
|
|
2734
3065
|
} else if (part.type === "tool-result") {
|
|
2735
3066
|
const toolResultPart = part;
|
|
2736
3067
|
const matchingCall = toolInvocations.find((inv) => inv.toolCallId === toolResultPart.toolCallId);
|
|
2737
|
-
const matchingV2Part =
|
|
3068
|
+
const matchingV2Part = mastraDBParts.find(
|
|
2738
3069
|
(p) => p.type === "tool-invocation" && "toolInvocation" in p && p.toolInvocation.toolCallId === toolResultPart.toolCallId
|
|
2739
3070
|
);
|
|
3071
|
+
const updateMatchingCallInvocationResult = (toolResultPart2, matchingCall2) => {
|
|
3072
|
+
matchingCall2.state = "result";
|
|
3073
|
+
matchingCall2.result = typeof toolResultPart2.output === "object" && toolResultPart2.output && "value" in toolResultPart2.output ? toolResultPart2.output.value : toolResultPart2.output;
|
|
3074
|
+
};
|
|
2740
3075
|
if (matchingCall) {
|
|
2741
|
-
matchingCall
|
|
2742
|
-
matchingCall.result = typeof toolResultPart.output === "object" && toolResultPart.output && "value" in toolResultPart.output ? toolResultPart.output.value : toolResultPart.output;
|
|
3076
|
+
updateMatchingCallInvocationResult(toolResultPart, matchingCall);
|
|
2743
3077
|
} else {
|
|
2744
|
-
const
|
|
2745
|
-
|
|
3078
|
+
const call = {
|
|
3079
|
+
state: "call",
|
|
2746
3080
|
toolCallId: toolResultPart.toolCallId,
|
|
2747
|
-
toolName:
|
|
2748
|
-
args: {}
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
3081
|
+
toolName: toolResultPart.toolName || "unknown",
|
|
3082
|
+
args: {}
|
|
3083
|
+
};
|
|
3084
|
+
updateMatchingCallInvocationResult(toolResultPart, call);
|
|
3085
|
+
toolInvocations.push(call);
|
|
2752
3086
|
}
|
|
2753
3087
|
if (matchingV2Part && matchingV2Part.type === "tool-invocation") {
|
|
2754
|
-
matchingV2Part.toolInvocation
|
|
2755
|
-
matchingV2Part.toolInvocation.result = typeof toolResultPart.output === "object" && toolResultPart.output && "value" in toolResultPart.output ? toolResultPart.output.value : toolResultPart.output;
|
|
2756
|
-
if (hasProviderMetadata) {
|
|
2757
|
-
matchingV2Part.providerMetadata = providerMetadata;
|
|
2758
|
-
}
|
|
3088
|
+
updateMatchingCallInvocationResult(toolResultPart, matchingV2Part.toolInvocation);
|
|
2759
3089
|
} else {
|
|
2760
|
-
const resultPartWithName = toolResultPart;
|
|
2761
3090
|
const toolInvocationPart = {
|
|
2762
3091
|
type: "tool-invocation",
|
|
2763
3092
|
toolInvocation: {
|
|
2764
3093
|
toolCallId: toolResultPart.toolCallId,
|
|
2765
|
-
toolName:
|
|
3094
|
+
toolName: toolResultPart.toolName || "unknown",
|
|
2766
3095
|
args: {},
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
},
|
|
2770
|
-
...hasProviderMetadata && { providerMetadata }
|
|
3096
|
+
state: "call"
|
|
3097
|
+
}
|
|
2771
3098
|
};
|
|
2772
|
-
|
|
3099
|
+
updateMatchingCallInvocationResult(toolResultPart, toolInvocationPart.toolInvocation);
|
|
3100
|
+
mastraDBParts.push(toolInvocationPart);
|
|
2773
3101
|
}
|
|
2774
3102
|
lastPartWasToolResult = true;
|
|
2775
3103
|
} else if (part.type === "reasoning") {
|
|
2776
|
-
const reasoningPart = part;
|
|
2777
3104
|
const v2ReasoningPart = {
|
|
2778
3105
|
type: "reasoning",
|
|
2779
|
-
reasoning:
|
|
2780
|
-
|
|
2781
|
-
|
|
3106
|
+
reasoning: "",
|
|
3107
|
+
// leave this blank so we aren't double storing it in the db along with details
|
|
3108
|
+
details: [{ type: "text", text: part.text }]
|
|
2782
3109
|
};
|
|
2783
|
-
|
|
2784
|
-
|
|
3110
|
+
if (part.providerOptions) {
|
|
3111
|
+
v2ReasoningPart.providerMetadata = part.providerOptions;
|
|
3112
|
+
}
|
|
3113
|
+
mastraDBParts.push(v2ReasoningPart);
|
|
3114
|
+
reasoningParts.push(part.text);
|
|
2785
3115
|
lastPartWasToolResult = false;
|
|
2786
3116
|
} else if (part.type === "image") {
|
|
2787
3117
|
const imagePart = part;
|
|
2788
|
-
|
|
2789
|
-
const
|
|
2790
|
-
if ("url" in imagePart && typeof imagePart.url === "string") {
|
|
2791
|
-
imageData = imagePart.url;
|
|
2792
|
-
} else if ("data" in imagePart) {
|
|
2793
|
-
if (typeof imagePart.data === "string") {
|
|
2794
|
-
imageData = imagePart.data.startsWith("data:") || imagePart.data.startsWith("http") ? imagePart.data : `data:${mimeType};base64,${imagePart.data}`;
|
|
2795
|
-
} else {
|
|
2796
|
-
const base64 = Buffer.from(imagePart.data).toString("base64");
|
|
2797
|
-
imageData = `data:${mimeType};base64,${base64}`;
|
|
2798
|
-
}
|
|
2799
|
-
} else {
|
|
2800
|
-
imageData = "";
|
|
2801
|
-
}
|
|
3118
|
+
const mimeType = imagePart.mediaType || "image/jpeg";
|
|
3119
|
+
const imageData = this.getDataStringFromAIV5DataPart(imagePart);
|
|
2802
3120
|
const imageFilePart = {
|
|
2803
3121
|
type: "file",
|
|
2804
3122
|
data: imageData,
|
|
2805
|
-
mimeType
|
|
2806
|
-
...hasProviderMetadata && { providerMetadata }
|
|
3123
|
+
mimeType
|
|
2807
3124
|
};
|
|
2808
|
-
|
|
3125
|
+
if (part.providerOptions) {
|
|
3126
|
+
imageFilePart.providerMetadata = part.providerOptions;
|
|
3127
|
+
}
|
|
3128
|
+
mastraDBParts.push(imageFilePart);
|
|
2809
3129
|
experimental_attachments.push({
|
|
2810
3130
|
url: imageData,
|
|
2811
3131
|
contentType: mimeType
|
|
@@ -2814,26 +3134,16 @@ var MessageList = class _MessageList {
|
|
|
2814
3134
|
} else if (part.type === "file") {
|
|
2815
3135
|
const filePart = part;
|
|
2816
3136
|
const mimeType = filePart.mediaType || "application/octet-stream";
|
|
2817
|
-
|
|
2818
|
-
if ("url" in filePart && typeof filePart.url === "string") {
|
|
2819
|
-
fileData = filePart.url;
|
|
2820
|
-
} else if ("data" in filePart) {
|
|
2821
|
-
if (typeof filePart.data === "string") {
|
|
2822
|
-
fileData = filePart.data.startsWith("data:") || filePart.data.startsWith("http") ? filePart.data : `data:${mimeType};base64,${filePart.data}`;
|
|
2823
|
-
} else {
|
|
2824
|
-
const base64 = Buffer.from(filePart.data).toString("base64");
|
|
2825
|
-
fileData = `data:${mimeType};base64,${base64}`;
|
|
2826
|
-
}
|
|
2827
|
-
} else {
|
|
2828
|
-
fileData = "";
|
|
2829
|
-
}
|
|
3137
|
+
const fileData = this.getDataStringFromAIV5DataPart(filePart);
|
|
2830
3138
|
const v2FilePart = {
|
|
2831
3139
|
type: "file",
|
|
2832
3140
|
data: fileData,
|
|
2833
|
-
mimeType
|
|
2834
|
-
...hasProviderMetadata && { providerMetadata }
|
|
3141
|
+
mimeType
|
|
2835
3142
|
};
|
|
2836
|
-
|
|
3143
|
+
if (part.providerOptions) {
|
|
3144
|
+
v2FilePart.providerMetadata = part.providerOptions;
|
|
3145
|
+
}
|
|
3146
|
+
mastraDBParts.push(v2FilePart);
|
|
2837
3147
|
experimental_attachments.push({
|
|
2838
3148
|
url: fileData,
|
|
2839
3149
|
contentType: mimeType
|
|
@@ -2841,34 +3151,34 @@ var MessageList = class _MessageList {
|
|
|
2841
3151
|
lastPartWasToolResult = false;
|
|
2842
3152
|
}
|
|
2843
3153
|
}
|
|
2844
|
-
if (modelMsg.role === "assistant" && lastPartWasToolResult &&
|
|
2845
|
-
const lastPart =
|
|
3154
|
+
if (modelMsg.role === "assistant" && lastPartWasToolResult && mastraDBParts.length > 0) {
|
|
3155
|
+
const lastPart = mastraDBParts[mastraDBParts.length - 1];
|
|
2846
3156
|
if (lastPart && lastPart.type !== "text") {
|
|
2847
3157
|
const emptyTextPart = { type: "text", text: "" };
|
|
2848
|
-
|
|
2849
|
-
textParts.push({ text: "" });
|
|
3158
|
+
mastraDBParts.push(emptyTextPart);
|
|
2850
3159
|
}
|
|
2851
3160
|
}
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
contentString = textParts.map((p) => p.text).join("\n");
|
|
2855
|
-
}
|
|
2856
|
-
const metadata = {};
|
|
3161
|
+
const contentString = mastraDBParts.filter((p) => p.type === "text").map((p) => p.text).join("\n");
|
|
3162
|
+
const metadata = "metadata" in modelMsg && modelMsg.metadata !== null && modelMsg.metadata !== void 0 ? modelMsg.metadata : {};
|
|
2857
3163
|
const id = `id` in modelMsg && typeof modelMsg.id === `string` ? modelMsg.id : `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
2858
|
-
|
|
3164
|
+
const message = {
|
|
2859
3165
|
id,
|
|
2860
3166
|
role: _MessageList.getRole(modelMsg),
|
|
2861
3167
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2862
3168
|
content: {
|
|
2863
3169
|
format: 2,
|
|
2864
|
-
parts:
|
|
3170
|
+
parts: mastraDBParts,
|
|
2865
3171
|
toolInvocations: toolInvocations.length > 0 ? toolInvocations : void 0,
|
|
2866
3172
|
reasoning: reasoningParts.length > 0 ? reasoningParts.join("\n") : void 0,
|
|
2867
3173
|
experimental_attachments: experimental_attachments.length > 0 ? experimental_attachments : void 0,
|
|
2868
|
-
content: contentString,
|
|
2869
|
-
metadata
|
|
3174
|
+
content: contentString || void 0,
|
|
3175
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : void 0
|
|
2870
3176
|
}
|
|
2871
3177
|
};
|
|
3178
|
+
if (modelMsg.providerOptions) {
|
|
3179
|
+
message.content.providerMetadata = modelMsg.providerOptions;
|
|
3180
|
+
}
|
|
3181
|
+
return message;
|
|
2872
3182
|
}
|
|
2873
3183
|
aiV4CoreMessagesToAIV5ModelMessages(messages, source) {
|
|
2874
3184
|
return this.aiV5UIMessagesToAIV5ModelMessages(
|
|
@@ -2879,14 +3189,24 @@ var MessageList = class _MessageList {
|
|
|
2879
3189
|
const sanitized = this.sanitizeV5UIMessages(messages, filterIncompleteToolCalls);
|
|
2880
3190
|
const preprocessed = this.addStartStepPartsForAIV5(sanitized);
|
|
2881
3191
|
const result = AIV5.convertToModelMessages(preprocessed);
|
|
2882
|
-
return result
|
|
3192
|
+
return result.map((modelMsg, index) => {
|
|
3193
|
+
const uiMsg = preprocessed[index];
|
|
3194
|
+
if (uiMsg?.metadata && typeof uiMsg.metadata === "object" && "providerMetadata" in uiMsg.metadata && uiMsg.metadata.providerMetadata) {
|
|
3195
|
+
return {
|
|
3196
|
+
...modelMsg,
|
|
3197
|
+
providerOptions: uiMsg.metadata.providerMetadata
|
|
3198
|
+
};
|
|
3199
|
+
}
|
|
3200
|
+
return modelMsg;
|
|
3201
|
+
});
|
|
2883
3202
|
}
|
|
2884
3203
|
addStartStepPartsForAIV5(messages) {
|
|
2885
3204
|
for (const message of messages) {
|
|
2886
3205
|
if (message.role !== `assistant`) continue;
|
|
2887
3206
|
for (const [index, part] of message.parts.entries()) {
|
|
2888
3207
|
if (!AIV5.isToolUIPart(part)) continue;
|
|
2889
|
-
|
|
3208
|
+
const nextPart = message.parts.at(index + 1);
|
|
3209
|
+
if (nextPart && nextPart.type !== `step-start` && !AIV5.isToolUIPart(nextPart)) {
|
|
2890
3210
|
message.parts.splice(index + 1, 0, { type: "step-start" });
|
|
2891
3211
|
}
|
|
2892
3212
|
}
|
|
@@ -3012,5 +3332,5 @@ var MessageList = class _MessageList {
|
|
|
3012
3332
|
};
|
|
3013
3333
|
|
|
3014
3334
|
export { DefaultGeneratedFile, DefaultGeneratedFileWithType, MessageList, convertMessages };
|
|
3015
|
-
//# sourceMappingURL=chunk-
|
|
3016
|
-
//# sourceMappingURL=chunk-
|
|
3335
|
+
//# sourceMappingURL=chunk-SXNQRJQD.js.map
|
|
3336
|
+
//# sourceMappingURL=chunk-SXNQRJQD.js.map
|