@mastra/core 0.13.2 → 0.14.0-alpha.1
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/README.md +5 -44
- package/dist/agent/agent.types.d.ts +12 -2
- package/dist/agent/agent.types.d.ts.map +1 -1
- package/dist/agent/index.cjs +14 -14
- package/dist/agent/index.d.ts +17 -17
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +2 -2
- package/dist/agent/input-processor/index.cjs +28 -0
- package/dist/agent/input-processor/index.js +3 -0
- package/dist/agent/input-processor/processors/index.d.ts +4 -4
- package/dist/agent/input-processor/processors/index.d.ts.map +1 -1
- package/dist/agent/input-processor/processors/language-detector.d.ts +6 -139
- package/dist/agent/input-processor/processors/language-detector.d.ts.map +1 -1
- package/dist/agent/input-processor/processors/moderation.d.ts +5 -94
- package/dist/agent/input-processor/processors/moderation.d.ts.map +1 -1
- package/dist/agent/input-processor/processors/pii-detector.d.ts +6 -164
- package/dist/agent/input-processor/processors/pii-detector.d.ts.map +1 -1
- package/dist/agent/input-processor/processors/prompt-injection-detector.d.ts +6 -96
- package/dist/agent/input-processor/processors/prompt-injection-detector.d.ts.map +1 -1
- package/dist/agent/input-processor/processors/unicode-normalizer.d.ts +9 -25
- package/dist/agent/input-processor/processors/unicode-normalizer.d.ts.map +1 -1
- package/dist/agent/message-list/index.d.ts +138 -39
- package/dist/agent/message-list/index.d.ts.map +1 -1
- package/dist/agent/message-list/types.d.ts +3 -0
- package/dist/agent/message-list/types.d.ts.map +1 -0
- package/dist/agent/message-list/utils/ai-v4-v5/core-model-message.d.ts +3 -0
- package/dist/agent/message-list/utils/ai-v4-v5/core-model-message.d.ts.map +1 -0
- package/dist/agent/message-list/utils/ai-v4-v5/ui-message.d.ts +3 -0
- package/dist/agent/message-list/utils/ai-v4-v5/ui-message.d.ts.map +1 -0
- package/dist/agent/message-list/utils/ai-v5/tool.d.ts +16 -0
- package/dist/agent/message-list/utils/ai-v5/tool.d.ts.map +1 -0
- package/dist/agent/types.d.ts +34 -4
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/ai-tracing/base.d.ts +22 -7
- package/dist/ai-tracing/base.d.ts.map +1 -1
- package/dist/ai-tracing/default.d.ts +3 -3
- package/dist/ai-tracing/default.d.ts.map +1 -1
- package/dist/ai-tracing/index.cjs +253 -72
- package/dist/ai-tracing/index.cjs.map +1 -1
- package/dist/ai-tracing/index.d.ts +1 -0
- package/dist/ai-tracing/index.d.ts.map +1 -1
- package/dist/ai-tracing/index.js +243 -71
- package/dist/ai-tracing/index.js.map +1 -1
- package/dist/ai-tracing/no-op.d.ts +39 -7
- package/dist/ai-tracing/no-op.d.ts.map +1 -1
- package/dist/ai-tracing/registry.d.ts +29 -4
- package/dist/ai-tracing/registry.d.ts.map +1 -1
- package/dist/ai-tracing/types.d.ts +112 -53
- package/dist/ai-tracing/types.d.ts.map +1 -1
- package/dist/ai-tracing/utils.d.ts +24 -0
- package/dist/ai-tracing/utils.d.ts.map +1 -0
- 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/{chunk-N3VGOJZV.cjs → chunk-4BMFOQDC.cjs} +27 -47
- package/dist/chunk-4BMFOQDC.cjs.map +1 -0
- package/dist/{chunk-MTRRRTB4.js → chunk-4XDSHUFK.js} +7 -6
- package/dist/chunk-4XDSHUFK.js.map +1 -0
- package/dist/{chunk-SSJVFUBZ.js → chunk-67L5DRLO.js} +3 -3
- package/dist/{chunk-SSJVFUBZ.js.map → chunk-67L5DRLO.js.map} +1 -1
- package/dist/{chunk-FUERFM46.js → chunk-6GF5M4GX.js} +3 -3
- package/dist/{chunk-FUERFM46.js.map → chunk-6GF5M4GX.js.map} +1 -1
- package/dist/{chunk-7E2SNI5D.cjs → chunk-7AXX55C5.cjs} +5 -5
- package/dist/chunk-7AXX55C5.cjs.map +1 -0
- package/dist/{chunk-6W6LYR7M.js → chunk-7XGDFDZ2.js} +3 -3
- package/dist/{chunk-6W6LYR7M.js.map → chunk-7XGDFDZ2.js.map} +1 -1
- package/dist/{chunk-R4HT5XUH.cjs → chunk-ASJVWHIK.cjs} +993 -124
- package/dist/chunk-ASJVWHIK.cjs.map +1 -0
- package/dist/{chunk-ZDZ57MIU.js → chunk-AWILTHBM.js} +3 -3
- package/dist/{chunk-ZDZ57MIU.js.map → chunk-AWILTHBM.js.map} +1 -1
- package/dist/{chunk-DDYSOZ25.js → chunk-AYXRNQH3.js} +3 -3
- package/dist/{chunk-DDYSOZ25.js.map → chunk-AYXRNQH3.js.map} +1 -1
- package/dist/{chunk-U2CK6AN5.cjs → chunk-BCCEYWAV.cjs} +4 -4
- package/dist/{chunk-U2CK6AN5.cjs.map → chunk-BCCEYWAV.cjs.map} +1 -1
- package/dist/{chunk-MH64VYGF.cjs → chunk-CSTWQQ3C.cjs} +14 -13
- package/dist/chunk-CSTWQQ3C.cjs.map +1 -0
- package/dist/{chunk-FTPL7ILZ.js → chunk-CWZDKGJ6.js} +3 -3
- package/dist/{chunk-FTPL7ILZ.js.map → chunk-CWZDKGJ6.js.map} +1 -1
- package/dist/{chunk-MVSUZXER.cjs → chunk-D7P76YH6.cjs} +4 -4
- package/dist/{chunk-MVSUZXER.cjs.map → chunk-D7P76YH6.cjs.map} +1 -1
- package/dist/{chunk-IL5SHDY4.js → chunk-DAMIFZPW.js} +949 -103
- package/dist/chunk-DAMIFZPW.js.map +1 -0
- package/dist/{chunk-KLXRYVVQ.cjs → chunk-DVI6XHUC.cjs} +4 -4
- package/dist/{chunk-KLXRYVVQ.cjs.map → chunk-DVI6XHUC.cjs.map} +1 -1
- package/dist/chunk-ELKY3FEM.cjs +14 -0
- package/dist/{chunk-IP5NGA2S.cjs.map → chunk-ELKY3FEM.cjs.map} +1 -1
- package/dist/{chunk-TOODGJKM.js → chunk-GZVSHXPP.js} +3 -3
- package/dist/chunk-GZVSHXPP.js.map +1 -0
- package/dist/{chunk-WA3SWCXD.cjs → chunk-I4XP6RAN.cjs} +9 -9
- package/dist/{chunk-WA3SWCXD.cjs.map → chunk-I4XP6RAN.cjs.map} +1 -1
- package/dist/{chunk-PLVSXEQP.cjs → chunk-IAP4IWKM.cjs} +4 -4
- package/dist/{chunk-PLVSXEQP.cjs.map → chunk-IAP4IWKM.cjs.map} +1 -1
- package/dist/{chunk-YT4RGZYO.cjs → chunk-KXCUCBEI.cjs} +8 -8
- package/dist/{chunk-YT4RGZYO.cjs.map → chunk-KXCUCBEI.cjs.map} +1 -1
- package/dist/{chunk-Z74LG5VH.cjs → chunk-LFAAEOQC.cjs} +21 -4
- package/dist/chunk-LFAAEOQC.cjs.map +1 -0
- package/dist/{chunk-DK7AVDMI.cjs → chunk-LVVAUDVQ.cjs} +4 -4
- package/dist/{chunk-DK7AVDMI.cjs.map → chunk-LVVAUDVQ.cjs.map} +1 -1
- package/dist/{chunk-HBMZEZTO.js → chunk-ON4S33NP.js} +3 -3
- package/dist/{chunk-HBMZEZTO.js.map → chunk-ON4S33NP.js.map} +1 -1
- package/dist/{chunk-L6YBPFYF.js → chunk-OPT2L5AM.js} +1089 -81
- package/dist/chunk-OPT2L5AM.js.map +1 -0
- package/dist/{chunk-N2KMAW6T.js → chunk-P7WF6NQU.js} +20 -4
- package/dist/chunk-P7WF6NQU.js.map +1 -0
- package/dist/{chunk-KEMW2BER.js → chunk-PY4MHJTE.js} +3 -3
- package/dist/{chunk-KEMW2BER.js.map → chunk-PY4MHJTE.js.map} +1 -1
- package/dist/{chunk-TZVJV7EV.js → chunk-QSJZLHWA.js} +5 -5
- package/dist/{chunk-TZVJV7EV.js.map → chunk-QSJZLHWA.js.map} +1 -1
- package/dist/{chunk-DCOKWJ5G.cjs → chunk-RJCNC57P.cjs} +1110 -79
- package/dist/chunk-RJCNC57P.cjs.map +1 -0
- package/dist/{chunk-LMW44O4V.cjs → chunk-RPV7GQAX.cjs} +4 -4
- package/dist/{chunk-LMW44O4V.cjs.map → chunk-RPV7GQAX.cjs.map} +1 -1
- package/dist/{chunk-TZOR5M7H.js → chunk-RYCRCJCY.js} +25 -45
- package/dist/chunk-RYCRCJCY.js.map +1 -0
- package/dist/{chunk-IDDUQR6P.cjs → chunk-V5WKCX3G.cjs} +3 -3
- package/dist/chunk-V5WKCX3G.cjs.map +1 -0
- package/dist/{chunk-6AR2Z5ZG.js → chunk-X3GXU6TZ.js} +3 -3
- package/dist/chunk-X3GXU6TZ.js.map +1 -0
- package/dist/deployer/index.cjs +2 -2
- package/dist/deployer/index.js +1 -1
- package/dist/index.cjs +74 -70
- package/dist/index.js +14 -14
- package/dist/llm/index.d.ts +2 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/model/base.types.d.ts +2 -6
- package/dist/llm/model/base.types.d.ts.map +1 -1
- package/dist/llm/model/index.d.ts +0 -1
- package/dist/llm/model/index.d.ts.map +1 -1
- package/dist/llm/model/model.d.ts +3 -2
- package/dist/llm/model/model.d.ts.map +1 -1
- package/dist/llm/model/model.loop.d.ts +25 -0
- package/dist/llm/model/model.loop.d.ts.map +1 -0
- package/dist/llm/model/model.loop.types.d.ts +39 -0
- package/dist/llm/model/model.loop.types.d.ts.map +1 -0
- package/dist/llm/model/shared.types.d.ts +8 -0
- package/dist/llm/model/shared.types.d.ts.map +1 -0
- package/dist/logger/constants.d.ts +1 -1
- package/dist/logger/index.cjs +6 -6
- package/dist/logger/index.js +1 -1
- package/dist/loop/index.cjs +2848 -0
- package/dist/loop/index.cjs.map +1 -0
- package/dist/loop/index.d.ts +2 -0
- package/dist/loop/index.d.ts.map +1 -0
- package/dist/loop/index.js +2842 -0
- package/dist/loop/index.js.map +1 -0
- package/dist/loop/loop.d.ts +5 -0
- package/dist/loop/loop.d.ts.map +1 -0
- package/dist/loop/telemetry/index.d.ts +36 -0
- package/dist/loop/telemetry/index.d.ts.map +1 -0
- package/dist/loop/telemetry/noop.d.ts +3 -0
- package/dist/loop/telemetry/noop.d.ts.map +1 -0
- package/dist/loop/test-utils/fullStream.d.ts +6 -0
- package/dist/loop/test-utils/fullStream.d.ts.map +1 -0
- package/dist/loop/test-utils/generateText.d.ts +6 -0
- package/dist/loop/test-utils/generateText.d.ts.map +1 -0
- package/dist/loop/test-utils/mockTracer.d.ts +47 -0
- package/dist/loop/test-utils/mockTracer.d.ts.map +1 -0
- package/dist/loop/test-utils/options.d.ts +6 -0
- package/dist/loop/test-utils/options.d.ts.map +1 -0
- package/dist/loop/test-utils/resultObject.d.ts +6 -0
- package/dist/loop/test-utils/resultObject.d.ts.map +1 -0
- package/dist/loop/test-utils/streamObject.d.ts +6 -0
- package/dist/loop/test-utils/streamObject.d.ts.map +1 -0
- package/dist/loop/test-utils/telemetry.d.ts +6 -0
- package/dist/loop/test-utils/telemetry.d.ts.map +1 -0
- package/dist/loop/test-utils/textStream.d.ts +6 -0
- package/dist/loop/test-utils/textStream.d.ts.map +1 -0
- package/dist/loop/test-utils/toUIMessageStream.d.ts +6 -0
- package/dist/loop/test-utils/toUIMessageStream.d.ts.map +1 -0
- package/dist/loop/test-utils/tools.d.ts +6 -0
- package/dist/loop/test-utils/tools.d.ts.map +1 -0
- package/dist/loop/test-utils/utils.d.ts +40 -0
- package/dist/loop/test-utils/utils.d.ts.map +1 -0
- package/dist/loop/types.d.ts +68 -0
- package/dist/loop/types.d.ts.map +1 -0
- package/dist/loop/workflow/llm-execution.d.ts +80 -0
- package/dist/loop/workflow/llm-execution.d.ts.map +1 -0
- package/dist/loop/workflow/outer-llm-step.d.ts +43 -0
- package/dist/loop/workflow/outer-llm-step.d.ts.map +1 -0
- package/dist/loop/workflow/run-state.d.ts +24 -0
- package/dist/loop/workflow/run-state.d.ts.map +1 -0
- package/dist/loop/workflow/schema.d.ts +80 -0
- package/dist/loop/workflow/schema.d.ts.map +1 -0
- package/dist/loop/workflow/stream.d.ts +6 -0
- package/dist/loop/workflow/stream.d.ts.map +1 -0
- package/dist/loop/workflow/tool-call-step.d.ts +41 -0
- package/dist/loop/workflow/tool-call-step.d.ts.map +1 -0
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.ts +4 -5
- 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.js +2 -2
- package/dist/memory/index.cjs +4 -4
- package/dist/memory/index.js +1 -1
- package/dist/network/index.cjs +6 -6
- package/dist/network/index.cjs.map +1 -1
- package/dist/network/index.js +3 -3
- package/dist/network/index.js.map +1 -1
- package/dist/network/network.d.ts +8 -7
- package/dist/network/network.d.ts.map +1 -1
- package/dist/network/vNext/index.cjs +21 -21
- package/dist/network/vNext/index.cjs.map +1 -1
- package/dist/network/vNext/index.d.ts +7 -7
- package/dist/network/vNext/index.d.ts.map +1 -1
- package/dist/network/vNext/index.js +7 -7
- package/dist/network/vNext/index.js.map +1 -1
- package/dist/processors/index.cjs +512 -0
- package/dist/processors/index.cjs.map +1 -0
- package/dist/processors/index.d.ts +38 -0
- package/dist/processors/index.d.ts.map +1 -0
- package/dist/processors/index.js +481 -0
- package/dist/processors/index.js.map +1 -0
- package/dist/processors/processors/batch-parts.d.ts +42 -0
- package/dist/processors/processors/batch-parts.d.ts.map +1 -0
- package/dist/processors/processors/index.d.ts +10 -0
- package/dist/processors/processors/index.d.ts.map +1 -0
- package/dist/processors/processors/language-detector.d.ts +151 -0
- package/dist/processors/processors/language-detector.d.ts.map +1 -0
- package/dist/processors/processors/moderation.d.ts +130 -0
- package/dist/processors/processors/moderation.d.ts.map +1 -0
- package/dist/processors/processors/pii-detector.d.ts +197 -0
- package/dist/processors/processors/pii-detector.d.ts.map +1 -0
- package/dist/processors/processors/prompt-injection-detector.d.ts +108 -0
- package/dist/processors/processors/prompt-injection-detector.d.ts.map +1 -0
- package/dist/processors/processors/structured-output.d.ts +42 -0
- package/dist/processors/processors/structured-output.d.ts.map +1 -0
- package/dist/processors/processors/system-prompt-scrubber.d.ts +92 -0
- package/dist/processors/processors/system-prompt-scrubber.d.ts.map +1 -0
- package/dist/processors/processors/token-limiter.d.ts +66 -0
- package/dist/processors/processors/token-limiter.d.ts.map +1 -0
- package/dist/processors/processors/unicode-normalizer.d.ts +34 -0
- package/dist/processors/processors/unicode-normalizer.d.ts.map +1 -0
- package/dist/processors/runner.d.ts +41 -0
- package/dist/processors/runner.d.ts.map +1 -0
- package/dist/relevance/index.cjs +4 -4
- package/dist/relevance/index.js +1 -1
- package/dist/scores/index.cjs +5 -5
- package/dist/scores/index.js +2 -2
- package/dist/server/index.cjs +2 -2
- package/dist/server/index.js +1 -1
- package/dist/storage/domains/operations/base.d.ts.map +1 -1
- package/dist/storage/index.cjs +15 -17
- package/dist/storage/index.cjs.map +1 -1
- package/dist/storage/index.js +4 -6
- package/dist/storage/index.js.map +1 -1
- package/dist/stream/aisdk/v4/transform.d.ts +26 -0
- package/dist/stream/aisdk/v4/transform.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/compat.d.ts +159 -0
- package/dist/stream/aisdk/v5/compat.d.ts.map +1 -0
- package/dist/stream/aisdk/v5/execute.d.ts +29 -0
- package/dist/stream/aisdk/v5/execute.d.ts.map +1 -0
- package/dist/stream/aisdk/v5/file.d.ts +38 -0
- package/dist/stream/aisdk/v5/file.d.ts.map +1 -0
- package/dist/stream/aisdk/v5/input.d.ts +15 -0
- package/dist/stream/aisdk/v5/input.d.ts.map +1 -0
- package/dist/stream/aisdk/v5/object/schema.d.ts +4 -0
- package/dist/stream/aisdk/v5/object/schema.d.ts.map +1 -0
- package/dist/stream/aisdk/v5/object/stream-object.d.ts +34 -0
- package/dist/stream/aisdk/v5/object/stream-object.d.ts.map +1 -0
- package/dist/stream/aisdk/v5/output-helpers.d.ts +76 -0
- package/dist/stream/aisdk/v5/output-helpers.d.ts.map +1 -0
- package/dist/stream/aisdk/v5/output.d.ts +119 -0
- package/dist/stream/aisdk/v5/output.d.ts.map +1 -0
- package/dist/stream/aisdk/v5/test-utils.d.ts +19 -0
- package/dist/stream/aisdk/v5/test-utils.d.ts.map +1 -0
- package/dist/stream/aisdk/v5/transform.d.ts +31 -0
- package/dist/stream/aisdk/v5/transform.d.ts.map +1 -0
- package/dist/stream/base/input.d.ts +1 -1
- package/dist/stream/base/output.d.ts +89 -0
- package/dist/stream/base/output.d.ts.map +1 -0
- package/dist/stream/types.d.ts +30 -0
- package/dist/stream/types.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.cjs +2 -2
- package/dist/test-utils/llm-mock.cjs.map +1 -1
- package/dist/test-utils/llm-mock.d.ts +2 -2
- package/dist/test-utils/llm-mock.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.js +2 -2
- package/dist/test-utils/llm-mock.js.map +1 -1
- package/dist/tools/tool-builder/builder.d.ts +3 -2
- package/dist/tools/tool-builder/builder.d.ts.map +1 -1
- package/dist/tools/types.d.ts +9 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tts/index.cjs +2 -2
- package/dist/tts/index.js +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.cjs +19 -15
- package/dist/utils.d.ts +3 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/vector/index.cjs +2 -2
- package/dist/vector/index.js +1 -1
- package/dist/voice/index.cjs +4 -4
- package/dist/voice/index.js +1 -1
- package/dist/workflows/default.d.ts.map +1 -1
- package/dist/workflows/index.cjs +10 -10
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/legacy/index.cjs +22 -22
- package/dist/workflows/legacy/index.js +1 -1
- package/loop.d.ts +1 -0
- package/package.json +16 -1
- package/processors.d.ts +1 -0
- package/dist/agent/input-processor/processors/index.cjs +0 -28
- package/dist/agent/input-processor/processors/index.js +0 -3
- package/dist/agent/input-processor/runner.d.ts +0 -4
- package/dist/agent/input-processor/runner.d.ts.map +0 -1
- package/dist/chunk-6AR2Z5ZG.js.map +0 -1
- package/dist/chunk-7E2SNI5D.cjs.map +0 -1
- package/dist/chunk-DCOKWJ5G.cjs.map +0 -1
- package/dist/chunk-IDDUQR6P.cjs.map +0 -1
- package/dist/chunk-IL5SHDY4.js.map +0 -1
- package/dist/chunk-IP5NGA2S.cjs +0 -14
- package/dist/chunk-L6YBPFYF.js.map +0 -1
- package/dist/chunk-MH64VYGF.cjs.map +0 -1
- package/dist/chunk-MTRRRTB4.js.map +0 -1
- package/dist/chunk-N2KMAW6T.js.map +0 -1
- package/dist/chunk-N3VGOJZV.cjs.map +0 -1
- package/dist/chunk-R4HT5XUH.cjs.map +0 -1
- package/dist/chunk-TOODGJKM.js.map +0 -1
- package/dist/chunk-TZOR5M7H.js.map +0 -1
- package/dist/chunk-Z74LG5VH.cjs.map +0 -1
- package/dist/llm/model/base.d.ts +0 -26
- package/dist/llm/model/base.d.ts.map +0 -1
- /package/dist/agent/input-processor/{processors/index.cjs.map → index.cjs.map} +0 -0
- /package/dist/agent/input-processor/{processors/index.js.map → index.js.map} +0 -0
|
@@ -1,12 +1,65 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var chunkZ74LG5VH_cjs = require('./chunk-Z74LG5VH.cjs');
|
|
4
3
|
var chunk3BFAQTC3_cjs = require('./chunk-3BFAQTC3.cjs');
|
|
5
4
|
var crypto = require('crypto');
|
|
6
|
-
var
|
|
5
|
+
var AIV4 = require('ai');
|
|
6
|
+
var AIV5 = require('ai-v5');
|
|
7
7
|
var providerUtils = require('@ai-sdk/provider-utils');
|
|
8
8
|
var zod = require('zod');
|
|
9
9
|
|
|
10
|
+
function _interopNamespace(e) {
|
|
11
|
+
if (e && e.__esModule) return e;
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n.default = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var AIV4__namespace = /*#__PURE__*/_interopNamespace(AIV4);
|
|
29
|
+
var AIV5__namespace = /*#__PURE__*/_interopNamespace(AIV5);
|
|
30
|
+
|
|
31
|
+
var DefaultGeneratedFile = class {
|
|
32
|
+
base64Data;
|
|
33
|
+
uint8ArrayData;
|
|
34
|
+
mediaType;
|
|
35
|
+
constructor({ data, mediaType }) {
|
|
36
|
+
const isUint8Array = data instanceof Uint8Array;
|
|
37
|
+
this.base64Data = isUint8Array ? void 0 : data;
|
|
38
|
+
this.uint8ArrayData = isUint8Array ? data : void 0;
|
|
39
|
+
this.mediaType = mediaType;
|
|
40
|
+
}
|
|
41
|
+
// lazy conversion with caching to avoid unnecessary conversion overhead:
|
|
42
|
+
get base64() {
|
|
43
|
+
if (this.base64Data == null) {
|
|
44
|
+
this.base64Data = providerUtils.convertUint8ArrayToBase64(this.uint8ArrayData);
|
|
45
|
+
}
|
|
46
|
+
return this.base64Data;
|
|
47
|
+
}
|
|
48
|
+
// lazy conversion with caching to avoid unnecessary conversion overhead:
|
|
49
|
+
get uint8Array() {
|
|
50
|
+
if (this.uint8ArrayData == null) {
|
|
51
|
+
this.uint8ArrayData = providerUtils.convertBase64ToUint8Array(this.base64Data);
|
|
52
|
+
}
|
|
53
|
+
return this.uint8ArrayData;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var DefaultGeneratedFileWithType = class extends DefaultGeneratedFile {
|
|
57
|
+
type = "file";
|
|
58
|
+
constructor(options) {
|
|
59
|
+
super(options);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
10
63
|
// src/agent/message-list/prompt/attachments-to-parts.ts
|
|
11
64
|
function attachmentsToParts(attachments) {
|
|
12
65
|
const parts = [];
|
|
@@ -385,6 +438,23 @@ function convertDataContentToBase64String(content) {
|
|
|
385
438
|
return providerUtils.convertUint8ArrayToBase64(content);
|
|
386
439
|
}
|
|
387
440
|
|
|
441
|
+
// src/agent/message-list/utils/ai-v5/tool.ts
|
|
442
|
+
function getToolName(type) {
|
|
443
|
+
if (typeof type === "object" && type && "type" in type) {
|
|
444
|
+
type = type.type;
|
|
445
|
+
}
|
|
446
|
+
if (typeof type !== "string") {
|
|
447
|
+
return "unknown";
|
|
448
|
+
}
|
|
449
|
+
if (type === "dynamic-tool") {
|
|
450
|
+
return "dynamic-tool";
|
|
451
|
+
}
|
|
452
|
+
if (type.startsWith("tool-")) {
|
|
453
|
+
return type.slice("tool-".length);
|
|
454
|
+
}
|
|
455
|
+
return type;
|
|
456
|
+
}
|
|
457
|
+
|
|
388
458
|
// src/agent/message-list/index.ts
|
|
389
459
|
var MessageList = class _MessageList {
|
|
390
460
|
messages = [];
|
|
@@ -418,6 +488,7 @@ var MessageList = class _MessageList {
|
|
|
418
488
|
this._agentNetworkAppend = _agentNetworkAppend || false;
|
|
419
489
|
}
|
|
420
490
|
add(messages, messageSource) {
|
|
491
|
+
if (messageSource === `user`) messageSource = `input`;
|
|
421
492
|
if (!messages) return this;
|
|
422
493
|
for (const message of Array.isArray(messages) ? messages : [messages]) {
|
|
423
494
|
this.addOne(
|
|
@@ -461,58 +532,216 @@ var MessageList = class _MessageList {
|
|
|
461
532
|
this.newUserMessages.clear();
|
|
462
533
|
return userMessages;
|
|
463
534
|
}
|
|
535
|
+
},
|
|
536
|
+
response: {
|
|
537
|
+
v2: () => {
|
|
538
|
+
const responseMessages = Array.from(this.newResponseMessages);
|
|
539
|
+
this.messages = this.messages.filter((m) => !this.newResponseMessages.has(m));
|
|
540
|
+
this.newResponseMessages.clear();
|
|
541
|
+
return responseMessages;
|
|
542
|
+
}
|
|
464
543
|
}
|
|
465
544
|
};
|
|
466
545
|
}
|
|
467
546
|
all = {
|
|
547
|
+
v3: () => this.cleanV3Metadata(this.messages.map(this.mastraMessageV2ToMastraMessageV3)),
|
|
468
548
|
v2: () => this.messages,
|
|
469
|
-
v1: () => convertToV1Messages(this.
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
549
|
+
v1: () => convertToV1Messages(this.all.v2()),
|
|
550
|
+
aiV5: {
|
|
551
|
+
model: () => this.aiV5UIMessagesToAIV5ModelMessages(this.all.aiV5.ui()),
|
|
552
|
+
ui: () => this.all.v3().map(_MessageList.mastraMessageV3ToAIV5UIMessage),
|
|
553
|
+
// Used when calling AI SDK streamText/generateText
|
|
554
|
+
prompt: () => {
|
|
555
|
+
const messages = [
|
|
556
|
+
...this.aiV4CoreMessagesToAIV5ModelMessages(
|
|
557
|
+
[...this.systemMessages, ...Object.values(this.taggedSystemMessages).flat()],
|
|
558
|
+
`system`
|
|
559
|
+
),
|
|
560
|
+
...this.all.aiV5.model()
|
|
561
|
+
];
|
|
562
|
+
const needsDefaultUserMessage = !messages.length || messages[0]?.role === "assistant";
|
|
563
|
+
if (needsDefaultUserMessage) {
|
|
564
|
+
const defaultMessage = {
|
|
565
|
+
role: "user",
|
|
566
|
+
content: " "
|
|
567
|
+
};
|
|
568
|
+
messages.unshift(defaultMessage);
|
|
569
|
+
}
|
|
570
|
+
return messages;
|
|
571
|
+
},
|
|
572
|
+
// Used for creating LLM prompt messages without AI SDK streamText/generateText
|
|
573
|
+
llmPrompt: () => {
|
|
574
|
+
const modelMessages = this.all.aiV5.model();
|
|
575
|
+
const systemMessages = this.aiV4CoreMessagesToAIV5ModelMessages(
|
|
576
|
+
[...this.systemMessages, ...Object.values(this.taggedSystemMessages).flat()],
|
|
577
|
+
`system`
|
|
578
|
+
);
|
|
579
|
+
const messages = [...systemMessages, ...modelMessages];
|
|
580
|
+
const needsDefaultUserMessage = !messages.length || messages[0]?.role === "assistant";
|
|
581
|
+
if (needsDefaultUserMessage) {
|
|
582
|
+
const defaultMessage = {
|
|
583
|
+
role: "user",
|
|
584
|
+
content: " "
|
|
585
|
+
};
|
|
586
|
+
messages.unshift(defaultMessage);
|
|
587
|
+
}
|
|
588
|
+
return messages.map(_MessageList.aiV5ModelMessageToV2PromptMessage);
|
|
589
|
+
}
|
|
590
|
+
},
|
|
591
|
+
/* @deprecated use list.get.all.aiV4.prompt() instead */
|
|
592
|
+
prompt: () => this.all.aiV4.prompt(),
|
|
593
|
+
/* @deprecated use list.get.all.aiV4.ui() */
|
|
594
|
+
ui: () => this.all.v2().map(_MessageList.mastraMessageV2ToAIV4UIMessage),
|
|
595
|
+
/* @deprecated use list.get.all.aiV4.core() */
|
|
596
|
+
core: () => this.aiV4UIMessagesToAIV4CoreMessages(this.all.aiV4.ui()),
|
|
597
|
+
aiV4: {
|
|
598
|
+
ui: () => this.all.v2().map(_MessageList.mastraMessageV2ToAIV4UIMessage),
|
|
599
|
+
core: () => this.aiV4UIMessagesToAIV4CoreMessages(this.all.aiV4.ui()),
|
|
600
|
+
// Used when calling AI SDK streamText/generateText
|
|
601
|
+
prompt: () => {
|
|
602
|
+
const coreMessages = this.all.aiV4.core();
|
|
603
|
+
const messages = [...this.systemMessages, ...Object.values(this.taggedSystemMessages).flat(), ...coreMessages];
|
|
604
|
+
const needsDefaultUserMessage = !messages.length || messages[0]?.role === "assistant";
|
|
605
|
+
if (needsDefaultUserMessage) {
|
|
606
|
+
const defaultMessage = {
|
|
607
|
+
role: "user",
|
|
608
|
+
content: " "
|
|
609
|
+
};
|
|
610
|
+
messages.unshift(defaultMessage);
|
|
611
|
+
}
|
|
612
|
+
return messages;
|
|
613
|
+
},
|
|
614
|
+
// Used for creating LLM prompt messages without AI SDK streamText/generateText
|
|
615
|
+
llmPrompt: () => {
|
|
616
|
+
const coreMessages = this.all.aiV4.core();
|
|
617
|
+
const systemMessages = [...this.systemMessages, ...Object.values(this.taggedSystemMessages).flat()];
|
|
618
|
+
const messages = [...systemMessages, ...coreMessages];
|
|
619
|
+
const needsDefaultUserMessage = !messages.length || messages[0]?.role === "assistant";
|
|
620
|
+
if (needsDefaultUserMessage) {
|
|
621
|
+
const defaultMessage = {
|
|
622
|
+
role: "user",
|
|
623
|
+
content: " "
|
|
624
|
+
};
|
|
625
|
+
messages.unshift(defaultMessage);
|
|
626
|
+
}
|
|
627
|
+
return messages.map(_MessageList.aiV4CoreMessageToV1PromptMessage);
|
|
482
628
|
}
|
|
483
|
-
return messages;
|
|
484
629
|
}
|
|
485
630
|
};
|
|
486
631
|
remembered = {
|
|
632
|
+
v3: () => this.remembered.v2().map(this.mastraMessageV2ToMastraMessageV3),
|
|
487
633
|
v2: () => this.messages.filter((m) => this.memoryMessages.has(m)),
|
|
488
634
|
v1: () => convertToV1Messages(this.remembered.v2()),
|
|
489
|
-
|
|
490
|
-
|
|
635
|
+
aiV5: {
|
|
636
|
+
model: () => this.aiV5UIMessagesToAIV5ModelMessages(this.remembered.aiV5.ui()),
|
|
637
|
+
ui: () => this.remembered.v3().map(_MessageList.mastraMessageV3ToAIV5UIMessage)
|
|
638
|
+
},
|
|
639
|
+
/* @deprecated use list.get.remembered.aiV4.ui() */
|
|
640
|
+
ui: () => this.remembered.v2().map(_MessageList.mastraMessageV2ToAIV4UIMessage),
|
|
641
|
+
/* @deprecated use list.get.remembered.aiV4.core() */
|
|
642
|
+
core: () => this.aiV4UIMessagesToAIV4CoreMessages(this.all.aiV4.ui()),
|
|
643
|
+
aiV4: {
|
|
644
|
+
ui: () => this.remembered.v2().map(_MessageList.mastraMessageV2ToAIV4UIMessage),
|
|
645
|
+
core: () => this.aiV4UIMessagesToAIV4CoreMessages(this.all.aiV4.ui())
|
|
646
|
+
}
|
|
491
647
|
};
|
|
648
|
+
// TODO: need to update this for new .aiV4/5.x() pattern
|
|
492
649
|
rememberedPersisted = {
|
|
493
|
-
v2: () => this.
|
|
650
|
+
v2: () => this.all.v2().filter((m) => this.memoryMessagesPersisted.has(m)),
|
|
494
651
|
v1: () => convertToV1Messages(this.rememberedPersisted.v2()),
|
|
495
|
-
ui: () => this.rememberedPersisted.v2().map(_MessageList.
|
|
496
|
-
core: () => this.
|
|
652
|
+
ui: () => this.rememberedPersisted.v2().map(_MessageList.mastraMessageV2ToAIV4UIMessage),
|
|
653
|
+
core: () => this.aiV4UIMessagesToAIV4CoreMessages(this.rememberedPersisted.ui())
|
|
497
654
|
};
|
|
498
655
|
input = {
|
|
656
|
+
v3: () => this.cleanV3Metadata(
|
|
657
|
+
this.messages.filter((m) => this.newUserMessages.has(m)).map(this.mastraMessageV2ToMastraMessageV3)
|
|
658
|
+
),
|
|
499
659
|
v2: () => this.messages.filter((m) => this.newUserMessages.has(m)),
|
|
500
660
|
v1: () => convertToV1Messages(this.input.v2()),
|
|
501
|
-
|
|
502
|
-
|
|
661
|
+
aiV5: {
|
|
662
|
+
model: () => this.aiV5UIMessagesToAIV5ModelMessages(this.input.aiV5.ui()),
|
|
663
|
+
ui: () => this.input.v3().map(_MessageList.mastraMessageV3ToAIV5UIMessage)
|
|
664
|
+
},
|
|
665
|
+
/* @deprecated use list.get.input.aiV4.ui() instead */
|
|
666
|
+
ui: () => this.input.v2().map(_MessageList.mastraMessageV2ToAIV4UIMessage),
|
|
667
|
+
/* @deprecated use list.get.core.aiV4.ui() instead */
|
|
668
|
+
core: () => this.aiV4UIMessagesToAIV4CoreMessages(this.input.ui()),
|
|
669
|
+
aiV4: {
|
|
670
|
+
ui: () => this.input.v2().map(_MessageList.mastraMessageV2ToAIV4UIMessage),
|
|
671
|
+
core: () => this.aiV4UIMessagesToAIV4CoreMessages(this.input.aiV4.ui())
|
|
672
|
+
}
|
|
503
673
|
};
|
|
674
|
+
// TODO: need to update this for new .aiV4/5.x() pattern
|
|
504
675
|
inputPersisted = {
|
|
676
|
+
v3: () => this.cleanV3Metadata(
|
|
677
|
+
this.messages.filter((m) => this.newUserMessagesPersisted.has(m)).map(this.mastraMessageV2ToMastraMessageV3)
|
|
678
|
+
),
|
|
505
679
|
v2: () => this.messages.filter((m) => this.newUserMessagesPersisted.has(m)),
|
|
506
680
|
v1: () => convertToV1Messages(this.inputPersisted.v2()),
|
|
507
|
-
ui: () => this.inputPersisted.v2().map(_MessageList.
|
|
508
|
-
core: () => this.
|
|
681
|
+
ui: () => this.inputPersisted.v2().map(_MessageList.mastraMessageV2ToAIV4UIMessage),
|
|
682
|
+
core: () => this.aiV4UIMessagesToAIV4CoreMessages(this.inputPersisted.ui())
|
|
509
683
|
};
|
|
510
684
|
response = {
|
|
511
|
-
|
|
685
|
+
v3: () => this.response.v2().map(this.mastraMessageV2ToMastraMessageV3),
|
|
686
|
+
v2: () => this.messages.filter((m) => this.newResponseMessages.has(m)),
|
|
687
|
+
v1: () => convertToV1Messages(this.response.v3().map(_MessageList.mastraMessageV3ToV2)),
|
|
688
|
+
aiV5: {
|
|
689
|
+
ui: () => this.response.v3().map(_MessageList.mastraMessageV3ToAIV5UIMessage),
|
|
690
|
+
model: () => this.aiV5UIMessagesToAIV5ModelMessages(this.response.aiV5.ui()).filter(
|
|
691
|
+
(m) => m.role === `tool` || m.role === `assistant`
|
|
692
|
+
),
|
|
693
|
+
modelContent: () => {
|
|
694
|
+
return this.response.aiV5.model().map(this.response.aiV5.stepContent).flat();
|
|
695
|
+
},
|
|
696
|
+
stepContent: (message) => {
|
|
697
|
+
const latest = message ? message : this.response.aiV5.model().at(-1);
|
|
698
|
+
if (!latest) return [];
|
|
699
|
+
if (typeof latest.content === `string`) {
|
|
700
|
+
return [{ type: "text", text: latest.content }];
|
|
701
|
+
}
|
|
702
|
+
return latest.content.map((c) => {
|
|
703
|
+
if (c.type === `tool-result`)
|
|
704
|
+
return {
|
|
705
|
+
type: "tool-result",
|
|
706
|
+
input: {},
|
|
707
|
+
// TODO: we need to find the tool call here and add the input from it
|
|
708
|
+
output: c.output,
|
|
709
|
+
toolCallId: c.toolCallId,
|
|
710
|
+
toolName: c.toolName
|
|
711
|
+
};
|
|
712
|
+
if (c.type === `file`)
|
|
713
|
+
return {
|
|
714
|
+
type: "file",
|
|
715
|
+
file: new DefaultGeneratedFileWithType({
|
|
716
|
+
data: typeof c.data === `string` ? c.data : c.data instanceof URL ? c.data.toString() : convertDataContentToBase64String(c.data),
|
|
717
|
+
mediaType: c.mediaType
|
|
718
|
+
})
|
|
719
|
+
};
|
|
720
|
+
if (c.type === `image`) {
|
|
721
|
+
return {
|
|
722
|
+
type: "file",
|
|
723
|
+
file: new DefaultGeneratedFileWithType({
|
|
724
|
+
data: typeof c.image === `string` ? c.image : c.image instanceof URL ? c.image.toString() : convertDataContentToBase64String(c.image),
|
|
725
|
+
mediaType: c.mediaType || "unknown"
|
|
726
|
+
})
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
return c;
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
},
|
|
733
|
+
aiV4: {
|
|
734
|
+
ui: () => this.response.v2().map(_MessageList.mastraMessageV2ToAIV4UIMessage),
|
|
735
|
+
core: () => this.aiV4UIMessagesToAIV4CoreMessages(this.response.aiV4.ui())
|
|
736
|
+
}
|
|
512
737
|
};
|
|
738
|
+
// TODO: need to update this for new .aiV4/5.x() pattern
|
|
513
739
|
responsePersisted = {
|
|
740
|
+
v3: () => this.cleanV3Metadata(
|
|
741
|
+
this.messages.filter((m) => this.newResponseMessagesPersisted.has(m)).map(this.mastraMessageV2ToMastraMessageV3)
|
|
742
|
+
),
|
|
514
743
|
v2: () => this.messages.filter((m) => this.newResponseMessagesPersisted.has(m)),
|
|
515
|
-
ui: () => this.responsePersisted.v2().map(_MessageList.
|
|
744
|
+
ui: () => this.responsePersisted.v2().map(_MessageList.mastraMessageV2ToAIV4UIMessage)
|
|
516
745
|
};
|
|
517
746
|
drainUnsavedMessages() {
|
|
518
747
|
const messages = this.messages.filter((m) => this.newUserMessages.has(m) || this.newResponseMessages.has(m));
|
|
@@ -538,10 +767,10 @@ var MessageList = class _MessageList {
|
|
|
538
767
|
}
|
|
539
768
|
return this;
|
|
540
769
|
}
|
|
541
|
-
|
|
542
|
-
return
|
|
770
|
+
aiV4UIMessagesToAIV4CoreMessages(messages) {
|
|
771
|
+
return AIV4__namespace.convertToCoreMessages(this.sanitizeAIV4UIMessages(messages));
|
|
543
772
|
}
|
|
544
|
-
|
|
773
|
+
sanitizeAIV4UIMessages(messages) {
|
|
545
774
|
const msgs = messages.map((m) => {
|
|
546
775
|
if (m.parts.length === 0) return false;
|
|
547
776
|
const safeParts = m.parts.filter(
|
|
@@ -563,25 +792,31 @@ var MessageList = class _MessageList {
|
|
|
563
792
|
}
|
|
564
793
|
addOneSystem(message, tag) {
|
|
565
794
|
if (typeof message === `string`) message = { role: "system", content: message };
|
|
566
|
-
|
|
795
|
+
const coreMessage = _MessageList.isAIV4CoreMessage(message) ? message : this.aiV5ModelMessagesToAIV4CoreMessages([message], `system`)[0];
|
|
796
|
+
if (coreMessage.role !== `system`) {
|
|
797
|
+
throw new Error(
|
|
798
|
+
`Expected role "system" but saw ${coreMessage.role} for message ${JSON.stringify(coreMessage, null, 2)}`
|
|
799
|
+
);
|
|
800
|
+
}
|
|
801
|
+
if (tag && !this.isDuplicateSystem(coreMessage, tag)) {
|
|
567
802
|
this.taggedSystemMessages[tag] ||= [];
|
|
568
|
-
this.taggedSystemMessages[tag].push(
|
|
569
|
-
} else if (!this.isDuplicateSystem(
|
|
570
|
-
this.systemMessages.push(
|
|
803
|
+
this.taggedSystemMessages[tag].push(coreMessage);
|
|
804
|
+
} else if (!this.isDuplicateSystem(coreMessage)) {
|
|
805
|
+
this.systemMessages.push(coreMessage);
|
|
571
806
|
}
|
|
572
807
|
}
|
|
573
808
|
isDuplicateSystem(message, tag) {
|
|
574
809
|
if (tag) {
|
|
575
810
|
if (!this.taggedSystemMessages[tag]) return false;
|
|
576
811
|
return this.taggedSystemMessages[tag].some(
|
|
577
|
-
(m) => _MessageList.
|
|
812
|
+
(m) => _MessageList.cacheKeyFromAIV4CoreMessageContent(m.content) === _MessageList.cacheKeyFromAIV4CoreMessageContent(message.content)
|
|
578
813
|
);
|
|
579
814
|
}
|
|
580
815
|
return this.systemMessages.some(
|
|
581
|
-
(m) => _MessageList.
|
|
816
|
+
(m) => _MessageList.cacheKeyFromAIV4CoreMessageContent(m.content) === _MessageList.cacheKeyFromAIV4CoreMessageContent(message.content)
|
|
582
817
|
);
|
|
583
818
|
}
|
|
584
|
-
static
|
|
819
|
+
static mastraMessageV2ToAIV4UIMessage(m) {
|
|
585
820
|
const experimentalAttachments = m.content.experimental_attachments ? [...m.content.experimental_attachments] : [];
|
|
586
821
|
const contentString = typeof m.content.content === `string` && m.content.content !== "" ? m.content.content : m.content.parts.reduce((prev, part) => {
|
|
587
822
|
if (part.type === `text`) {
|
|
@@ -599,6 +834,32 @@ var MessageList = class _MessageList {
|
|
|
599
834
|
});
|
|
600
835
|
} else if (part.type === "tool-invocation" && (part.toolInvocation.state === "call" || part.toolInvocation.state === "partial-call")) {
|
|
601
836
|
continue;
|
|
837
|
+
} else if (part.type === "tool-invocation") {
|
|
838
|
+
const toolInvocation = { ...part.toolInvocation };
|
|
839
|
+
let currentStep = -1;
|
|
840
|
+
let toolStep = -1;
|
|
841
|
+
for (const innerPart of m.content.parts) {
|
|
842
|
+
if (innerPart.type === `step-start`) currentStep++;
|
|
843
|
+
if (innerPart.type === `tool-invocation` && innerPart.toolInvocation.toolCallId === part.toolInvocation.toolCallId) {
|
|
844
|
+
toolStep = currentStep;
|
|
845
|
+
break;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
if (toolStep >= 0) {
|
|
849
|
+
const preparedInvocation = {
|
|
850
|
+
step: toolStep,
|
|
851
|
+
...toolInvocation
|
|
852
|
+
};
|
|
853
|
+
parts.push({
|
|
854
|
+
type: "tool-invocation",
|
|
855
|
+
toolInvocation: preparedInvocation
|
|
856
|
+
});
|
|
857
|
+
} else {
|
|
858
|
+
parts.push({
|
|
859
|
+
type: "tool-invocation",
|
|
860
|
+
toolInvocation
|
|
861
|
+
});
|
|
862
|
+
}
|
|
602
863
|
} else {
|
|
603
864
|
parts.push(part);
|
|
604
865
|
}
|
|
@@ -680,8 +941,10 @@ var MessageList = class _MessageList {
|
|
|
680
941
|
}
|
|
681
942
|
});
|
|
682
943
|
}
|
|
683
|
-
if (message.role === `system` && _MessageList.isVercelCoreMessage(message)) return this.addSystem(message);
|
|
684
944
|
if (message.role === `system`) {
|
|
945
|
+
if (messageSource === `memory`) return null;
|
|
946
|
+
if (_MessageList.isAIV4CoreMessage(message) || _MessageList.isAIV5CoreMessage(message))
|
|
947
|
+
return this.addSystem(message);
|
|
685
948
|
throw new chunk3BFAQTC3_cjs.MastraError({
|
|
686
949
|
id: "INVALID_SYSTEM_MESSAGE_FORMAT",
|
|
687
950
|
domain: "AGENT" /* AGENT */,
|
|
@@ -786,7 +1049,7 @@ var MessageList = class _MessageList {
|
|
|
786
1049
|
} else if (messageSource === `response`) {
|
|
787
1050
|
this.newResponseMessages.add(messageV2);
|
|
788
1051
|
this.newResponseMessagesPersisted.add(messageV2);
|
|
789
|
-
} else if (messageSource === `
|
|
1052
|
+
} else if (messageSource === `input`) {
|
|
790
1053
|
this.newUserMessages.add(messageV2);
|
|
791
1054
|
this.newUserMessagesPersisted.add(messageV2);
|
|
792
1055
|
} else if (messageSource === `context`) {
|
|
@@ -810,11 +1073,13 @@ var MessageList = class _MessageList {
|
|
|
810
1073
|
insertAt
|
|
811
1074
|
// optional
|
|
812
1075
|
}) {
|
|
813
|
-
const partKey = _MessageList.
|
|
1076
|
+
const partKey = _MessageList.cacheKeyFromAIV4Parts([part]);
|
|
814
1077
|
const latestPartCount = latestMessage.content.parts.filter(
|
|
815
|
-
(p) => _MessageList.
|
|
1078
|
+
(p) => _MessageList.cacheKeyFromAIV4Parts([p]) === partKey
|
|
1079
|
+
).length;
|
|
1080
|
+
const newPartCount = newMessage.content.parts.filter(
|
|
1081
|
+
(p) => _MessageList.cacheKeyFromAIV4Parts([p]) === partKey
|
|
816
1082
|
).length;
|
|
817
|
-
const newPartCount = newMessage.content.parts.filter((p) => _MessageList.cacheKeyFromParts([p]) === partKey).length;
|
|
818
1083
|
if (latestPartCount < newPartCount) {
|
|
819
1084
|
if (typeof insertAt === "number") {
|
|
820
1085
|
latestMessage.content.parts.splice(insertAt, 0, part);
|
|
@@ -839,7 +1104,7 @@ var MessageList = class _MessageList {
|
|
|
839
1104
|
for (let i = 0; i < messageV2.content.parts.length; ++i) {
|
|
840
1105
|
const part = messageV2.content.parts[i];
|
|
841
1106
|
if (!part) continue;
|
|
842
|
-
const key = _MessageList.
|
|
1107
|
+
const key = _MessageList.cacheKeyFromAIV4Parts([part]);
|
|
843
1108
|
const partToAdd = partsToAdd.get(i);
|
|
844
1109
|
if (!key || !partToAdd) continue;
|
|
845
1110
|
if (anchorMap.size > 0) {
|
|
@@ -850,7 +1115,7 @@ var MessageList = class _MessageList {
|
|
|
850
1115
|
const offset = leftAnchorV2 === -1 ? i : i - leftAnchorV2;
|
|
851
1116
|
const insertAt = leftAnchorLatest + offset;
|
|
852
1117
|
const rightAnchorLatest = rightAnchorV2 !== -1 ? anchorMap.get(rightAnchorV2) : latestMessage.content.parts.length;
|
|
853
|
-
if (insertAt >= 0 && insertAt <= rightAnchorLatest && !latestMessage.content.parts.slice(insertAt, rightAnchorLatest).some((p) => _MessageList.
|
|
1118
|
+
if (insertAt >= 0 && insertAt <= rightAnchorLatest && !latestMessage.content.parts.slice(insertAt, rightAnchorLatest).some((p) => _MessageList.cacheKeyFromAIV4Parts([p]) === _MessageList.cacheKeyFromAIV4Parts([part]))) {
|
|
854
1119
|
this.pushNewMessagePart({
|
|
855
1120
|
latestMessage,
|
|
856
1121
|
newMessage: messageV2,
|
|
@@ -893,11 +1158,20 @@ var MessageList = class _MessageList {
|
|
|
893
1158
|
if (_MessageList.isMastraMessageV2(message)) {
|
|
894
1159
|
return this.hydrateMastraMessageV2Fields(message);
|
|
895
1160
|
}
|
|
896
|
-
if (_MessageList.
|
|
897
|
-
return this.
|
|
1161
|
+
if (_MessageList.isAIV4CoreMessage(message)) {
|
|
1162
|
+
return this.aiV4CoreMessageToMastraMessageV2(message, messageSource);
|
|
1163
|
+
}
|
|
1164
|
+
if (_MessageList.isAIV4UIMessage(message)) {
|
|
1165
|
+
return this.aiV4UIMessageToMastraMessageV2(message, messageSource);
|
|
1166
|
+
}
|
|
1167
|
+
if (_MessageList.isAIV5CoreMessage(message)) {
|
|
1168
|
+
return _MessageList.mastraMessageV3ToV2(this.aiV5ModelMessageToMastraMessageV3(message, messageSource));
|
|
1169
|
+
}
|
|
1170
|
+
if (_MessageList.isAIV5UIMessage(message)) {
|
|
1171
|
+
return _MessageList.mastraMessageV3ToV2(this.aiV5UIMessageToMastraMessageV3(message, messageSource));
|
|
898
1172
|
}
|
|
899
|
-
if (_MessageList.
|
|
900
|
-
return this.
|
|
1173
|
+
if (_MessageList.isMastraMessageV3(message)) {
|
|
1174
|
+
return _MessageList.mastraMessageV3ToV2(this.hydrateMastraMessageV3Fields(message));
|
|
901
1175
|
}
|
|
902
1176
|
throw new Error(`Found unhandled message ${JSON.stringify(message)}`);
|
|
903
1177
|
}
|
|
@@ -933,7 +1207,7 @@ var MessageList = class _MessageList {
|
|
|
933
1207
|
return crypto.randomUUID();
|
|
934
1208
|
}
|
|
935
1209
|
mastraMessageV1ToMastraMessageV2(message, messageSource) {
|
|
936
|
-
const coreV2 = this.
|
|
1210
|
+
const coreV2 = this.aiV4CoreMessageToMastraMessageV2(
|
|
937
1211
|
{
|
|
938
1212
|
content: message.content,
|
|
939
1213
|
role: message.role
|
|
@@ -949,6 +1223,10 @@ var MessageList = class _MessageList {
|
|
|
949
1223
|
content: coreV2.content
|
|
950
1224
|
};
|
|
951
1225
|
}
|
|
1226
|
+
hydrateMastraMessageV3Fields(message) {
|
|
1227
|
+
if (!(message.createdAt instanceof Date)) message.createdAt = new Date(message.createdAt);
|
|
1228
|
+
return message;
|
|
1229
|
+
}
|
|
952
1230
|
hydrateMastraMessageV2Fields(message) {
|
|
953
1231
|
if (!(message.createdAt instanceof Date)) message.createdAt = new Date(message.createdAt);
|
|
954
1232
|
if (message.content.toolInvocations && message.content.parts) {
|
|
@@ -966,7 +1244,7 @@ var MessageList = class _MessageList {
|
|
|
966
1244
|
}
|
|
967
1245
|
return message;
|
|
968
1246
|
}
|
|
969
|
-
|
|
1247
|
+
aiV4UIMessageToMastraMessageV2(message, messageSource) {
|
|
970
1248
|
const content = {
|
|
971
1249
|
format: 2,
|
|
972
1250
|
parts: message.parts
|
|
@@ -989,7 +1267,7 @@ var MessageList = class _MessageList {
|
|
|
989
1267
|
content
|
|
990
1268
|
};
|
|
991
1269
|
}
|
|
992
|
-
|
|
1270
|
+
aiV4CoreMessageToMastraMessageV2(coreMessage, messageSource) {
|
|
993
1271
|
const id = `id` in coreMessage ? coreMessage.id : this.newMessageId();
|
|
994
1272
|
const parts = [];
|
|
995
1273
|
const experimentalAttachments = [];
|
|
@@ -1114,44 +1392,52 @@ var MessageList = class _MessageList {
|
|
|
1114
1392
|
content
|
|
1115
1393
|
};
|
|
1116
1394
|
}
|
|
1117
|
-
static
|
|
1118
|
-
return !_MessageList.isMastraMessage(msg) &&
|
|
1395
|
+
static isAIV4UIMessage(msg) {
|
|
1396
|
+
return !_MessageList.isMastraMessage(msg) && !_MessageList.isAIV4CoreMessage(msg) && `parts` in msg && !_MessageList.hasAIV5UIMessageCharacteristics(msg);
|
|
1119
1397
|
}
|
|
1120
|
-
static
|
|
1121
|
-
return !_MessageList.isMastraMessage(msg) &&
|
|
1398
|
+
static isAIV5CoreMessage(msg) {
|
|
1399
|
+
return !_MessageList.isMastraMessage(msg) && !(`parts` in msg) && `content` in msg && _MessageList.hasAIV5CoreMessageCharacteristics(msg);
|
|
1400
|
+
}
|
|
1401
|
+
static isAIV4CoreMessage(msg) {
|
|
1402
|
+
return !_MessageList.isMastraMessage(msg) && !(`parts` in msg) && `content` in msg && !_MessageList.hasAIV5CoreMessageCharacteristics(msg);
|
|
1122
1403
|
}
|
|
1123
1404
|
static isMastraMessage(msg) {
|
|
1124
|
-
return _MessageList.isMastraMessageV2(msg) || _MessageList.isMastraMessageV1(msg);
|
|
1405
|
+
return _MessageList.isMastraMessageV3(msg) || _MessageList.isMastraMessageV2(msg) || _MessageList.isMastraMessageV1(msg);
|
|
1125
1406
|
}
|
|
1126
1407
|
static isMastraMessageV1(msg) {
|
|
1127
|
-
return !_MessageList.isMastraMessageV2(msg) && (`threadId` in msg || `resourceId` in msg);
|
|
1408
|
+
return !_MessageList.isMastraMessageV2(msg) && !_MessageList.isMastraMessageV3(msg) && (`threadId` in msg || `resourceId` in msg);
|
|
1128
1409
|
}
|
|
1129
1410
|
static isMastraMessageV2(msg) {
|
|
1130
1411
|
return Boolean(
|
|
1131
|
-
msg.content && !Array.isArray(msg.content) && typeof msg.content !== `string` &&
|
|
1132
|
-
|
|
1412
|
+
`content` in msg && msg.content && !Array.isArray(msg.content) && typeof msg.content !== `string` && `format` in msg.content && msg.content.format === 2
|
|
1413
|
+
);
|
|
1414
|
+
}
|
|
1415
|
+
static isMastraMessageV3(msg) {
|
|
1416
|
+
return Boolean(
|
|
1417
|
+
`content` in msg && msg.content && !Array.isArray(msg.content) && typeof msg.content !== `string` && `format` in msg.content && msg.content.format === 3
|
|
1133
1418
|
);
|
|
1134
1419
|
}
|
|
1135
1420
|
static getRole(message) {
|
|
1136
1421
|
if (message.role === `assistant` || message.role === `tool`) return `assistant`;
|
|
1137
1422
|
if (message.role === `user`) return `user`;
|
|
1423
|
+
if (message.role === `system`) return `system`;
|
|
1138
1424
|
throw new Error(
|
|
1139
1425
|
`BUG: add handling for message role ${message.role} in message ${JSON.stringify(message, null, 2)}`
|
|
1140
1426
|
);
|
|
1141
1427
|
}
|
|
1142
|
-
static
|
|
1428
|
+
static cacheKeyFromAIV4Parts(parts) {
|
|
1143
1429
|
let key = ``;
|
|
1144
1430
|
for (const part of parts) {
|
|
1145
1431
|
key += part.type;
|
|
1146
1432
|
if (part.type === `text`) {
|
|
1147
|
-
key +=
|
|
1433
|
+
key += part.text;
|
|
1148
1434
|
}
|
|
1149
1435
|
if (part.type === `tool-invocation`) {
|
|
1150
1436
|
key += part.toolInvocation.toolCallId;
|
|
1151
1437
|
key += part.toolInvocation.state;
|
|
1152
1438
|
}
|
|
1153
1439
|
if (part.type === `reasoning`) {
|
|
1154
|
-
key += part.reasoning
|
|
1440
|
+
key += part.reasoning;
|
|
1155
1441
|
key += part.details.reduce((prev, current) => {
|
|
1156
1442
|
if (current.type === `text`) {
|
|
1157
1443
|
return prev + current.text.length + (current.signature?.length || 0);
|
|
@@ -1160,7 +1446,7 @@ var MessageList = class _MessageList {
|
|
|
1160
1446
|
}, 0);
|
|
1161
1447
|
}
|
|
1162
1448
|
if (part.type === `file`) {
|
|
1163
|
-
key += part.data
|
|
1449
|
+
key += part.data;
|
|
1164
1450
|
key += part.mimeType;
|
|
1165
1451
|
}
|
|
1166
1452
|
}
|
|
@@ -1175,7 +1461,7 @@ var MessageList = class _MessageList {
|
|
|
1175
1461
|
return p;
|
|
1176
1462
|
}, "");
|
|
1177
1463
|
}
|
|
1178
|
-
static
|
|
1464
|
+
static cacheKeyFromAIV4CoreMessageContent(content) {
|
|
1179
1465
|
if (typeof content === `string`) return content;
|
|
1180
1466
|
let key = ``;
|
|
1181
1467
|
for (const part of content) {
|
|
@@ -1209,34 +1495,779 @@ var MessageList = class _MessageList {
|
|
|
1209
1495
|
return key;
|
|
1210
1496
|
}
|
|
1211
1497
|
static messagesAreEqual(one, two) {
|
|
1212
|
-
const
|
|
1213
|
-
const
|
|
1214
|
-
if (
|
|
1215
|
-
if (
|
|
1216
|
-
return _MessageList.
|
|
1217
|
-
}
|
|
1218
|
-
const
|
|
1219
|
-
const
|
|
1220
|
-
if (
|
|
1221
|
-
if (
|
|
1222
|
-
return _MessageList.
|
|
1498
|
+
const oneUIV4 = _MessageList.isAIV4UIMessage(one) && one;
|
|
1499
|
+
const twoUIV4 = _MessageList.isAIV4UIMessage(two) && two;
|
|
1500
|
+
if (oneUIV4 && !twoUIV4) return false;
|
|
1501
|
+
if (oneUIV4 && twoUIV4) {
|
|
1502
|
+
return _MessageList.cacheKeyFromAIV4Parts(one.parts) === _MessageList.cacheKeyFromAIV4Parts(two.parts);
|
|
1503
|
+
}
|
|
1504
|
+
const oneCMV4 = _MessageList.isAIV4CoreMessage(one) && one;
|
|
1505
|
+
const twoCMV4 = _MessageList.isAIV4CoreMessage(two) && two;
|
|
1506
|
+
if (oneCMV4 && !twoCMV4) return false;
|
|
1507
|
+
if (oneCMV4 && twoCMV4) {
|
|
1508
|
+
return _MessageList.cacheKeyFromAIV4CoreMessageContent(oneCMV4.content) === _MessageList.cacheKeyFromAIV4CoreMessageContent(twoCMV4.content);
|
|
1223
1509
|
}
|
|
1224
1510
|
const oneMM1 = _MessageList.isMastraMessageV1(one) && one;
|
|
1225
1511
|
const twoMM1 = _MessageList.isMastraMessageV1(two) && two;
|
|
1226
1512
|
if (oneMM1 && !twoMM1) return false;
|
|
1227
1513
|
if (oneMM1 && twoMM1) {
|
|
1228
|
-
return oneMM1.id === twoMM1.id && _MessageList.
|
|
1514
|
+
return oneMM1.id === twoMM1.id && _MessageList.cacheKeyFromAIV4CoreMessageContent(oneMM1.content) === _MessageList.cacheKeyFromAIV4CoreMessageContent(twoMM1.content);
|
|
1229
1515
|
}
|
|
1230
1516
|
const oneMM2 = _MessageList.isMastraMessageV2(one) && one;
|
|
1231
1517
|
const twoMM2 = _MessageList.isMastraMessageV2(two) && two;
|
|
1232
1518
|
if (oneMM2 && !twoMM2) return false;
|
|
1233
1519
|
if (oneMM2 && twoMM2) {
|
|
1234
|
-
return oneMM2.id === twoMM2.id && _MessageList.
|
|
1520
|
+
return oneMM2.id === twoMM2.id && _MessageList.cacheKeyFromAIV4Parts(oneMM2.content.parts) === _MessageList.cacheKeyFromAIV4Parts(twoMM2.content.parts);
|
|
1521
|
+
}
|
|
1522
|
+
const oneMM3 = _MessageList.isMastraMessageV3(one) && one;
|
|
1523
|
+
const twoMM3 = _MessageList.isMastraMessageV3(two) && two;
|
|
1524
|
+
if (oneMM3 && !twoMM3) return false;
|
|
1525
|
+
if (oneMM3 && twoMM3) {
|
|
1526
|
+
return oneMM3.id === twoMM3.id && _MessageList.cacheKeyFromAIV5Parts(oneMM3.content.parts) === _MessageList.cacheKeyFromAIV5Parts(twoMM3.content.parts);
|
|
1527
|
+
}
|
|
1528
|
+
const oneUIV5 = _MessageList.isAIV5UIMessage(one) && one;
|
|
1529
|
+
const twoUIV5 = _MessageList.isAIV5UIMessage(two) && two;
|
|
1530
|
+
if (oneUIV5 && !twoUIV5) return false;
|
|
1531
|
+
if (oneUIV5 && twoUIV5) {
|
|
1532
|
+
return _MessageList.cacheKeyFromAIV5Parts(one.parts) === _MessageList.cacheKeyFromAIV5Parts(two.parts);
|
|
1533
|
+
}
|
|
1534
|
+
const oneCMV5 = _MessageList.isAIV5CoreMessage(one) && one;
|
|
1535
|
+
const twoCMV5 = _MessageList.isAIV5CoreMessage(two) && two;
|
|
1536
|
+
if (oneCMV5 && !twoCMV5) return false;
|
|
1537
|
+
if (oneCMV5 && twoCMV5) {
|
|
1538
|
+
return _MessageList.cacheKeyFromAIV5ModelMessageContent(oneCMV5.content) === _MessageList.cacheKeyFromAIV5ModelMessageContent(twoCMV5.content);
|
|
1235
1539
|
}
|
|
1236
1540
|
return true;
|
|
1237
1541
|
}
|
|
1542
|
+
cleanV3Metadata(messages) {
|
|
1543
|
+
return messages.map((msg) => {
|
|
1544
|
+
if (!msg.content.metadata || typeof msg.content.metadata !== "object") {
|
|
1545
|
+
return msg;
|
|
1546
|
+
}
|
|
1547
|
+
const metadata = { ...msg.content.metadata };
|
|
1548
|
+
const hasOriginalContent = "__originalContent" in metadata;
|
|
1549
|
+
const hasOriginalAttachments = "__originalExperimentalAttachments" in metadata;
|
|
1550
|
+
if (!hasOriginalContent && !hasOriginalAttachments) {
|
|
1551
|
+
return msg;
|
|
1552
|
+
}
|
|
1553
|
+
const { __originalContent, __originalExperimentalAttachments, ...cleanMetadata } = metadata;
|
|
1554
|
+
if (Object.keys(cleanMetadata).length === 0) {
|
|
1555
|
+
const { metadata: metadata2, ...contentWithoutMetadata } = msg.content;
|
|
1556
|
+
return { ...msg, content: contentWithoutMetadata };
|
|
1557
|
+
}
|
|
1558
|
+
return { ...msg, content: { ...msg.content, metadata: cleanMetadata } };
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
static aiV4CoreMessageToV1PromptMessage(coreMessage) {
|
|
1562
|
+
if (coreMessage.role === `system`) {
|
|
1563
|
+
return coreMessage;
|
|
1564
|
+
}
|
|
1565
|
+
if (typeof coreMessage.content === `string` && (coreMessage.role === `assistant` || coreMessage.role === `user`)) {
|
|
1566
|
+
return {
|
|
1567
|
+
...coreMessage,
|
|
1568
|
+
content: [{ type: "text", text: coreMessage.content }]
|
|
1569
|
+
};
|
|
1570
|
+
}
|
|
1571
|
+
if (typeof coreMessage.content === `string`) {
|
|
1572
|
+
throw new Error(
|
|
1573
|
+
`Saw text content for input CoreMessage, but the role is ${coreMessage.role}. This is only allowed for "system", "assistant", and "user" roles.`
|
|
1574
|
+
);
|
|
1575
|
+
}
|
|
1576
|
+
const roleContent = {
|
|
1577
|
+
user: [],
|
|
1578
|
+
assistant: [],
|
|
1579
|
+
tool: []
|
|
1580
|
+
};
|
|
1581
|
+
const role = coreMessage.role;
|
|
1582
|
+
for (const part of coreMessage.content) {
|
|
1583
|
+
const incompatibleMessage = `Saw incompatible message content part type ${part.type} for message role ${role}`;
|
|
1584
|
+
switch (part.type) {
|
|
1585
|
+
case "text": {
|
|
1586
|
+
if (role === `tool`) {
|
|
1587
|
+
throw new Error(incompatibleMessage);
|
|
1588
|
+
}
|
|
1589
|
+
roleContent[role].push(part);
|
|
1590
|
+
break;
|
|
1591
|
+
}
|
|
1592
|
+
case "redacted-reasoning":
|
|
1593
|
+
case "reasoning": {
|
|
1594
|
+
if (role !== `assistant`) {
|
|
1595
|
+
throw new Error(incompatibleMessage);
|
|
1596
|
+
}
|
|
1597
|
+
roleContent[role].push(part);
|
|
1598
|
+
break;
|
|
1599
|
+
}
|
|
1600
|
+
case "tool-call": {
|
|
1601
|
+
if (role === `tool` || role === `user`) {
|
|
1602
|
+
throw new Error(incompatibleMessage);
|
|
1603
|
+
}
|
|
1604
|
+
roleContent[role].push(part);
|
|
1605
|
+
break;
|
|
1606
|
+
}
|
|
1607
|
+
case "tool-result": {
|
|
1608
|
+
if (role === `assistant` || role === `user`) {
|
|
1609
|
+
throw new Error(incompatibleMessage);
|
|
1610
|
+
}
|
|
1611
|
+
roleContent[role].push(part);
|
|
1612
|
+
break;
|
|
1613
|
+
}
|
|
1614
|
+
case "image": {
|
|
1615
|
+
if (role === `tool` || role === `assistant`) {
|
|
1616
|
+
throw new Error(incompatibleMessage);
|
|
1617
|
+
}
|
|
1618
|
+
roleContent[role].push({
|
|
1619
|
+
...part,
|
|
1620
|
+
image: part.image instanceof URL || part.image instanceof Uint8Array ? part.image : Buffer.isBuffer(part.image) || part.image instanceof ArrayBuffer ? new Uint8Array(part.image) : new URL(part.image)
|
|
1621
|
+
});
|
|
1622
|
+
break;
|
|
1623
|
+
}
|
|
1624
|
+
case "file": {
|
|
1625
|
+
if (role === `tool`) {
|
|
1626
|
+
throw new Error(incompatibleMessage);
|
|
1627
|
+
}
|
|
1628
|
+
roleContent[role].push({
|
|
1629
|
+
...part,
|
|
1630
|
+
data: part.data instanceof URL ? part.data : typeof part.data === "string" ? part.data : convertDataContentToBase64String(part.data)
|
|
1631
|
+
});
|
|
1632
|
+
break;
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
if (role === `tool`) {
|
|
1637
|
+
return {
|
|
1638
|
+
...coreMessage,
|
|
1639
|
+
content: roleContent[role]
|
|
1640
|
+
};
|
|
1641
|
+
}
|
|
1642
|
+
if (role === `user`) {
|
|
1643
|
+
return {
|
|
1644
|
+
...coreMessage,
|
|
1645
|
+
content: roleContent[role]
|
|
1646
|
+
};
|
|
1647
|
+
}
|
|
1648
|
+
if (role === `assistant`) {
|
|
1649
|
+
return {
|
|
1650
|
+
...coreMessage,
|
|
1651
|
+
content: roleContent[role]
|
|
1652
|
+
};
|
|
1653
|
+
}
|
|
1654
|
+
throw new Error(
|
|
1655
|
+
`Encountered unknown role ${role} when converting V4 CoreMessage -> V4 LanguageModelV1Prompt, input message: ${JSON.stringify(coreMessage, null, 2)}`
|
|
1656
|
+
);
|
|
1657
|
+
}
|
|
1658
|
+
static aiV5ModelMessageToV2PromptMessage(modelMessage) {
|
|
1659
|
+
if (modelMessage.role === `system`) {
|
|
1660
|
+
return modelMessage;
|
|
1661
|
+
}
|
|
1662
|
+
if (typeof modelMessage.content === `string` && (modelMessage.role === `assistant` || modelMessage.role === `user`)) {
|
|
1663
|
+
return {
|
|
1664
|
+
role: modelMessage.role,
|
|
1665
|
+
content: [{ type: "text", text: modelMessage.content }],
|
|
1666
|
+
providerOptions: modelMessage.providerOptions
|
|
1667
|
+
};
|
|
1668
|
+
}
|
|
1669
|
+
if (typeof modelMessage.content === `string`) {
|
|
1670
|
+
throw new Error(
|
|
1671
|
+
`Saw text content for input ModelMessage, but the role is ${modelMessage.role}. This is only allowed for "system", "assistant", and "user" roles.`
|
|
1672
|
+
);
|
|
1673
|
+
}
|
|
1674
|
+
const roleContent = {
|
|
1675
|
+
user: [],
|
|
1676
|
+
assistant: [],
|
|
1677
|
+
tool: []
|
|
1678
|
+
};
|
|
1679
|
+
const role = modelMessage.role;
|
|
1680
|
+
for (const part of modelMessage.content) {
|
|
1681
|
+
const incompatibleMessage = `Saw incompatible message content part type ${part.type} for message role ${role}`;
|
|
1682
|
+
switch (part.type) {
|
|
1683
|
+
case "text": {
|
|
1684
|
+
if (role === `tool`) {
|
|
1685
|
+
throw new Error(incompatibleMessage);
|
|
1686
|
+
}
|
|
1687
|
+
roleContent[role].push(part);
|
|
1688
|
+
break;
|
|
1689
|
+
}
|
|
1690
|
+
case "reasoning": {
|
|
1691
|
+
if (role === `tool` || role === `user`) {
|
|
1692
|
+
throw new Error(incompatibleMessage);
|
|
1693
|
+
}
|
|
1694
|
+
roleContent[role].push(part);
|
|
1695
|
+
break;
|
|
1696
|
+
}
|
|
1697
|
+
case "tool-call": {
|
|
1698
|
+
if (role !== `assistant`) {
|
|
1699
|
+
throw new Error(incompatibleMessage);
|
|
1700
|
+
}
|
|
1701
|
+
roleContent[role].push(part);
|
|
1702
|
+
break;
|
|
1703
|
+
}
|
|
1704
|
+
case "tool-result": {
|
|
1705
|
+
if (role === `assistant` || role === `user`) {
|
|
1706
|
+
throw new Error(incompatibleMessage);
|
|
1707
|
+
}
|
|
1708
|
+
roleContent[role].push(part);
|
|
1709
|
+
break;
|
|
1710
|
+
}
|
|
1711
|
+
case "file": {
|
|
1712
|
+
if (role === `tool`) {
|
|
1713
|
+
throw new Error(incompatibleMessage);
|
|
1714
|
+
}
|
|
1715
|
+
roleContent[role].push({
|
|
1716
|
+
...part,
|
|
1717
|
+
data: part.data instanceof ArrayBuffer ? new Uint8Array(part.data) : part.data
|
|
1718
|
+
});
|
|
1719
|
+
break;
|
|
1720
|
+
}
|
|
1721
|
+
case "image": {
|
|
1722
|
+
if (role === `tool`) {
|
|
1723
|
+
throw new Error(incompatibleMessage);
|
|
1724
|
+
}
|
|
1725
|
+
roleContent[role].push({
|
|
1726
|
+
...part,
|
|
1727
|
+
mediaType: part.mediaType || "image/unknown",
|
|
1728
|
+
type: "file",
|
|
1729
|
+
data: part.image instanceof ArrayBuffer ? new Uint8Array(part.image) : part.image
|
|
1730
|
+
});
|
|
1731
|
+
break;
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
if (role === `tool`) {
|
|
1736
|
+
return {
|
|
1737
|
+
...modelMessage,
|
|
1738
|
+
content: roleContent[role]
|
|
1739
|
+
};
|
|
1740
|
+
}
|
|
1741
|
+
if (role === `user`) {
|
|
1742
|
+
return {
|
|
1743
|
+
...modelMessage,
|
|
1744
|
+
content: roleContent[role]
|
|
1745
|
+
};
|
|
1746
|
+
}
|
|
1747
|
+
if (role === `assistant`) {
|
|
1748
|
+
return {
|
|
1749
|
+
...modelMessage,
|
|
1750
|
+
content: roleContent[role]
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1753
|
+
throw new Error(
|
|
1754
|
+
`Encountered unknown role ${role} when converting V5 ModelMessage -> V5 LanguageModelV2Message, input message: ${JSON.stringify(modelMessage, null, 2)}`
|
|
1755
|
+
);
|
|
1756
|
+
}
|
|
1757
|
+
static mastraMessageV3ToV2(v3Msg) {
|
|
1758
|
+
const toolInvocationParts = v3Msg.content.parts.filter((p) => AIV5__namespace.isToolUIPart(p));
|
|
1759
|
+
const hadToolInvocations = v3Msg.content.metadata?.__hadToolInvocations === true;
|
|
1760
|
+
let toolInvocations = void 0;
|
|
1761
|
+
if (toolInvocationParts.length > 0) {
|
|
1762
|
+
const invocations = toolInvocationParts.map((p) => {
|
|
1763
|
+
const toolName = getToolName(p);
|
|
1764
|
+
if (p.state === `output-available`) {
|
|
1765
|
+
return {
|
|
1766
|
+
args: p.input,
|
|
1767
|
+
result: typeof p.output === "object" && p.output && "value" in p.output ? p.output.value : p.output,
|
|
1768
|
+
toolCallId: p.toolCallId,
|
|
1769
|
+
toolName,
|
|
1770
|
+
state: "result"
|
|
1771
|
+
};
|
|
1772
|
+
}
|
|
1773
|
+
return {
|
|
1774
|
+
args: p.input,
|
|
1775
|
+
state: "call",
|
|
1776
|
+
toolName,
|
|
1777
|
+
toolCallId: p.toolCallId
|
|
1778
|
+
};
|
|
1779
|
+
});
|
|
1780
|
+
toolInvocations = invocations;
|
|
1781
|
+
} else if (hadToolInvocations && v3Msg.role === "assistant") {
|
|
1782
|
+
toolInvocations = [];
|
|
1783
|
+
}
|
|
1784
|
+
const attachmentUrls = new Set(v3Msg.content.metadata?.__attachmentUrls || []);
|
|
1785
|
+
const v2Msg = {
|
|
1786
|
+
id: v3Msg.id,
|
|
1787
|
+
resourceId: v3Msg.resourceId,
|
|
1788
|
+
threadId: v3Msg.threadId,
|
|
1789
|
+
createdAt: v3Msg.createdAt,
|
|
1790
|
+
role: v3Msg.role,
|
|
1791
|
+
content: {
|
|
1792
|
+
format: 2,
|
|
1793
|
+
parts: v3Msg.content.parts.map((p) => {
|
|
1794
|
+
if (AIV5__namespace.isToolUIPart(p) || p.type === "dynamic-tool") {
|
|
1795
|
+
const toolName = getToolName(p);
|
|
1796
|
+
const shared = {
|
|
1797
|
+
state: p.state,
|
|
1798
|
+
args: p.input,
|
|
1799
|
+
toolCallId: p.toolCallId,
|
|
1800
|
+
toolName
|
|
1801
|
+
};
|
|
1802
|
+
if (p.state === `output-available`) {
|
|
1803
|
+
return {
|
|
1804
|
+
type: "tool-invocation",
|
|
1805
|
+
toolInvocation: {
|
|
1806
|
+
...shared,
|
|
1807
|
+
state: "result",
|
|
1808
|
+
result: typeof p.output === "object" && p.output && "value" in p.output ? p.output.value : p.output
|
|
1809
|
+
},
|
|
1810
|
+
providerMetadata: p.callProviderMetadata
|
|
1811
|
+
};
|
|
1812
|
+
}
|
|
1813
|
+
return {
|
|
1814
|
+
type: "tool-invocation",
|
|
1815
|
+
toolInvocation: {
|
|
1816
|
+
...shared,
|
|
1817
|
+
state: p.state === `input-available` ? `call` : `partial-call`
|
|
1818
|
+
}
|
|
1819
|
+
};
|
|
1820
|
+
}
|
|
1821
|
+
switch (p.type) {
|
|
1822
|
+
case "text":
|
|
1823
|
+
return p;
|
|
1824
|
+
case "file":
|
|
1825
|
+
if (attachmentUrls.has(p.url)) {
|
|
1826
|
+
return null;
|
|
1827
|
+
}
|
|
1828
|
+
return {
|
|
1829
|
+
type: "file",
|
|
1830
|
+
mimeType: p.mediaType,
|
|
1831
|
+
data: p.url,
|
|
1832
|
+
providerMetadata: p.providerMetadata
|
|
1833
|
+
};
|
|
1834
|
+
case "reasoning":
|
|
1835
|
+
if (p.text === "") return null;
|
|
1836
|
+
return {
|
|
1837
|
+
type: "reasoning",
|
|
1838
|
+
reasoning: p.text,
|
|
1839
|
+
details: [{ type: "text", text: p.text }],
|
|
1840
|
+
providerMetadata: p.providerMetadata
|
|
1841
|
+
};
|
|
1842
|
+
case "source-url":
|
|
1843
|
+
return {
|
|
1844
|
+
type: "source",
|
|
1845
|
+
source: {
|
|
1846
|
+
url: p.url,
|
|
1847
|
+
id: p.sourceId,
|
|
1848
|
+
sourceType: "url"
|
|
1849
|
+
},
|
|
1850
|
+
providerMetadata: p.providerMetadata
|
|
1851
|
+
};
|
|
1852
|
+
case "step-start":
|
|
1853
|
+
return p;
|
|
1854
|
+
}
|
|
1855
|
+
return null;
|
|
1856
|
+
}).filter((p) => Boolean(p))
|
|
1857
|
+
}
|
|
1858
|
+
};
|
|
1859
|
+
if (toolInvocations !== void 0) {
|
|
1860
|
+
v2Msg.content.toolInvocations = toolInvocations;
|
|
1861
|
+
}
|
|
1862
|
+
if (v3Msg.content.metadata) {
|
|
1863
|
+
const { __originalContent, __originalExperimentalAttachments, __attachmentUrls, ...userMetadata } = v3Msg.content.metadata;
|
|
1864
|
+
v2Msg.content.metadata = userMetadata;
|
|
1865
|
+
}
|
|
1866
|
+
const originalContent = v3Msg.content.metadata?.__originalContent;
|
|
1867
|
+
if (originalContent !== void 0) {
|
|
1868
|
+
if (typeof originalContent !== `string` || v2Msg.content.parts.every((p) => p.type === `step-start` || p.type === `text`)) {
|
|
1869
|
+
v2Msg.content.content = originalContent;
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
const originalAttachments = v3Msg.content.metadata?.__originalExperimentalAttachments;
|
|
1873
|
+
if (originalAttachments && Array.isArray(originalAttachments)) {
|
|
1874
|
+
v2Msg.content.experimental_attachments = originalAttachments || [];
|
|
1875
|
+
}
|
|
1876
|
+
if (toolInvocations && toolInvocations.length > 0) {
|
|
1877
|
+
const resultToolInvocations = toolInvocations.filter((t) => t.state === "result");
|
|
1878
|
+
if (resultToolInvocations.length > 0) {
|
|
1879
|
+
v2Msg.content.toolInvocations = resultToolInvocations;
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
if (v3Msg.type) v2Msg.type = v3Msg.type;
|
|
1883
|
+
return v2Msg;
|
|
1884
|
+
}
|
|
1885
|
+
mastraMessageV2ToMastraMessageV3(v2Msg) {
|
|
1886
|
+
const parts = [];
|
|
1887
|
+
const v3Msg = {
|
|
1888
|
+
id: v2Msg.id,
|
|
1889
|
+
content: {
|
|
1890
|
+
format: 3,
|
|
1891
|
+
parts
|
|
1892
|
+
},
|
|
1893
|
+
role: v2Msg.role,
|
|
1894
|
+
createdAt: v2Msg.createdAt instanceof Date ? v2Msg.createdAt : new Date(v2Msg.createdAt),
|
|
1895
|
+
resourceId: v2Msg.resourceId,
|
|
1896
|
+
threadId: v2Msg.threadId,
|
|
1897
|
+
type: v2Msg.type
|
|
1898
|
+
};
|
|
1899
|
+
if (v2Msg.content.metadata) {
|
|
1900
|
+
v3Msg.content.metadata = { ...v2Msg.content.metadata };
|
|
1901
|
+
}
|
|
1902
|
+
if (v2Msg.content.content !== void 0) {
|
|
1903
|
+
v3Msg.content.metadata = {
|
|
1904
|
+
...v3Msg.content.metadata || {},
|
|
1905
|
+
__originalContent: v2Msg.content.content
|
|
1906
|
+
};
|
|
1907
|
+
}
|
|
1908
|
+
if (v2Msg.content.experimental_attachments !== void 0) {
|
|
1909
|
+
v3Msg.content.metadata = {
|
|
1910
|
+
...v3Msg.content.metadata || {},
|
|
1911
|
+
__originalExperimentalAttachments: v2Msg.content.experimental_attachments
|
|
1912
|
+
};
|
|
1913
|
+
}
|
|
1914
|
+
const fileUrls = /* @__PURE__ */ new Set();
|
|
1915
|
+
for (const part of v2Msg.content.parts) {
|
|
1916
|
+
switch (part.type) {
|
|
1917
|
+
case "step-start":
|
|
1918
|
+
case "text":
|
|
1919
|
+
parts.push(part);
|
|
1920
|
+
break;
|
|
1921
|
+
case "tool-invocation":
|
|
1922
|
+
if (part.toolInvocation.state === `result`) {
|
|
1923
|
+
parts.push({
|
|
1924
|
+
type: `tool-${part.toolInvocation.toolName}`,
|
|
1925
|
+
toolCallId: part.toolInvocation.toolCallId,
|
|
1926
|
+
state: "output-available",
|
|
1927
|
+
input: part.toolInvocation.args,
|
|
1928
|
+
output: part.toolInvocation.result,
|
|
1929
|
+
callProviderMetadata: part.providerMetadata
|
|
1930
|
+
});
|
|
1931
|
+
} else {
|
|
1932
|
+
parts.push({
|
|
1933
|
+
type: `tool-${part.toolInvocation.toolName}`,
|
|
1934
|
+
toolCallId: part.toolInvocation.toolCallId,
|
|
1935
|
+
state: part.toolInvocation.state === `call` ? `input-available` : `input-streaming`,
|
|
1936
|
+
input: part.toolInvocation.args
|
|
1937
|
+
});
|
|
1938
|
+
}
|
|
1939
|
+
break;
|
|
1940
|
+
case "source":
|
|
1941
|
+
parts.push({
|
|
1942
|
+
type: "source-url",
|
|
1943
|
+
sourceId: part.source.id,
|
|
1944
|
+
url: part.source.url,
|
|
1945
|
+
title: part.source.title,
|
|
1946
|
+
providerMetadata: part.source.providerMetadata || part.providerMetadata
|
|
1947
|
+
});
|
|
1948
|
+
break;
|
|
1949
|
+
case "reasoning":
|
|
1950
|
+
const text = part.reasoning || (part.details?.reduce((p, c) => {
|
|
1951
|
+
if (c.type === `text`) return p + c.text;
|
|
1952
|
+
return p;
|
|
1953
|
+
}, "") ?? "");
|
|
1954
|
+
if (text || part.details?.length) {
|
|
1955
|
+
parts.push({
|
|
1956
|
+
type: "reasoning",
|
|
1957
|
+
text: text || "",
|
|
1958
|
+
state: "done",
|
|
1959
|
+
providerMetadata: part.providerMetadata
|
|
1960
|
+
});
|
|
1961
|
+
}
|
|
1962
|
+
break;
|
|
1963
|
+
case "file":
|
|
1964
|
+
parts.push({
|
|
1965
|
+
type: "file",
|
|
1966
|
+
url: part.data,
|
|
1967
|
+
mediaType: part.mimeType,
|
|
1968
|
+
providerMetadata: part.providerMetadata
|
|
1969
|
+
});
|
|
1970
|
+
fileUrls.add(part.data);
|
|
1971
|
+
break;
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
if (v2Msg.content.content && !v3Msg.content.parts?.some((p) => p.type === `text`)) {
|
|
1975
|
+
v3Msg.content.parts.push({ type: "text", text: v2Msg.content.content });
|
|
1976
|
+
}
|
|
1977
|
+
const attachmentUrls = [];
|
|
1978
|
+
if (v2Msg.content.experimental_attachments?.length) {
|
|
1979
|
+
for (const attachment of v2Msg.content.experimental_attachments) {
|
|
1980
|
+
if (fileUrls.has(attachment.url)) continue;
|
|
1981
|
+
attachmentUrls.push(attachment.url);
|
|
1982
|
+
parts.push({
|
|
1983
|
+
url: attachment.url,
|
|
1984
|
+
mediaType: attachment.contentType || "unknown",
|
|
1985
|
+
type: "file"
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
if (attachmentUrls.length > 0) {
|
|
1990
|
+
v3Msg.content.metadata = {
|
|
1991
|
+
...v3Msg.content.metadata || {},
|
|
1992
|
+
__attachmentUrls: attachmentUrls
|
|
1993
|
+
};
|
|
1994
|
+
}
|
|
1995
|
+
return v3Msg;
|
|
1996
|
+
}
|
|
1997
|
+
aiV5UIMessagesToAIV5ModelMessages(messages) {
|
|
1998
|
+
return AIV5__namespace.convertToModelMessages(this.sanitizeV5UIMessages(messages));
|
|
1999
|
+
}
|
|
2000
|
+
sanitizeV5UIMessages(messages) {
|
|
2001
|
+
const msgs = messages.map((m) => {
|
|
2002
|
+
if (m.parts.length === 0) return false;
|
|
2003
|
+
const safeParts = m.parts.filter((p) => {
|
|
2004
|
+
if (!AIV5__namespace.isToolUIPart(p)) return true;
|
|
2005
|
+
return p.state === "output-available" || p.state === "output-error";
|
|
2006
|
+
});
|
|
2007
|
+
if (!safeParts.length) return false;
|
|
2008
|
+
const sanitized = {
|
|
2009
|
+
...m,
|
|
2010
|
+
parts: safeParts.map((part) => {
|
|
2011
|
+
if (AIV5__namespace.isToolUIPart(part) && part.state === "output-available") {
|
|
2012
|
+
return {
|
|
2013
|
+
...part,
|
|
2014
|
+
output: typeof part.output === "object" && part.output && "value" in part.output ? part.output.value : part.output
|
|
2015
|
+
};
|
|
2016
|
+
}
|
|
2017
|
+
return part;
|
|
2018
|
+
})
|
|
2019
|
+
};
|
|
2020
|
+
return sanitized;
|
|
2021
|
+
}).filter((m) => Boolean(m));
|
|
2022
|
+
return msgs;
|
|
2023
|
+
}
|
|
2024
|
+
static mastraMessageV3ToAIV5UIMessage(m) {
|
|
2025
|
+
const metadata = {
|
|
2026
|
+
...m.content.metadata || {}
|
|
2027
|
+
};
|
|
2028
|
+
if (m.createdAt) metadata.createdAt = m.createdAt;
|
|
2029
|
+
if (m.threadId) metadata.threadId = m.threadId;
|
|
2030
|
+
if (m.resourceId) metadata.resourceId = m.resourceId;
|
|
2031
|
+
const filteredParts = m.content.parts;
|
|
2032
|
+
return {
|
|
2033
|
+
id: m.id,
|
|
2034
|
+
role: m.role,
|
|
2035
|
+
metadata,
|
|
2036
|
+
parts: filteredParts
|
|
2037
|
+
};
|
|
2038
|
+
}
|
|
2039
|
+
aiV5ModelMessagesToAIV4CoreMessages(messages, messageSource) {
|
|
2040
|
+
const v3 = messages.map((msg) => this.aiV5ModelMessageToMastraMessageV3(msg, messageSource));
|
|
2041
|
+
const v2 = v3.map(_MessageList.mastraMessageV3ToV2);
|
|
2042
|
+
const ui = v2.map(_MessageList.mastraMessageV2ToAIV4UIMessage);
|
|
2043
|
+
const core = this.aiV4UIMessagesToAIV4CoreMessages(ui);
|
|
2044
|
+
return core;
|
|
2045
|
+
}
|
|
2046
|
+
aiV4CoreMessagesToAIV5ModelMessages(messages, source) {
|
|
2047
|
+
return this.aiV5UIMessagesToAIV5ModelMessages(
|
|
2048
|
+
messages.map((m) => this.aiV4CoreMessageToMastraMessageV2(m, source)).map((m) => this.mastraMessageV2ToMastraMessageV3(m)).map((m) => _MessageList.mastraMessageV3ToAIV5UIMessage(m))
|
|
2049
|
+
);
|
|
2050
|
+
}
|
|
2051
|
+
aiV5UIMessageToMastraMessageV3(message, messageSource) {
|
|
2052
|
+
const content = {
|
|
2053
|
+
format: 3,
|
|
2054
|
+
parts: message.parts,
|
|
2055
|
+
metadata: message.metadata
|
|
2056
|
+
};
|
|
2057
|
+
const metadata = message.metadata;
|
|
2058
|
+
const createdAt = (() => {
|
|
2059
|
+
if ("createdAt" in message && message.createdAt instanceof Date) {
|
|
2060
|
+
return message.createdAt;
|
|
2061
|
+
}
|
|
2062
|
+
if (metadata && "createdAt" in metadata && metadata.createdAt instanceof Date) {
|
|
2063
|
+
return metadata.createdAt;
|
|
2064
|
+
}
|
|
2065
|
+
return void 0;
|
|
2066
|
+
})();
|
|
2067
|
+
if ("metadata" in message && message.metadata) {
|
|
2068
|
+
content.metadata = { ...message.metadata };
|
|
2069
|
+
}
|
|
2070
|
+
return {
|
|
2071
|
+
id: message.id || this.newMessageId(),
|
|
2072
|
+
role: _MessageList.getRole(message),
|
|
2073
|
+
createdAt: this.generateCreatedAt(messageSource, createdAt),
|
|
2074
|
+
threadId: this.memoryInfo?.threadId,
|
|
2075
|
+
resourceId: this.memoryInfo?.resourceId,
|
|
2076
|
+
content
|
|
2077
|
+
};
|
|
2078
|
+
}
|
|
2079
|
+
aiV5ModelMessageToMastraMessageV3(coreMessage, messageSource) {
|
|
2080
|
+
const id = `id` in coreMessage && typeof coreMessage.id === `string` ? coreMessage.id : this.newMessageId();
|
|
2081
|
+
const parts = [];
|
|
2082
|
+
if (messageSource === "input" && coreMessage.role === "user") {
|
|
2083
|
+
parts.push({ type: "step-start" });
|
|
2084
|
+
}
|
|
2085
|
+
if (typeof coreMessage.content === "string") {
|
|
2086
|
+
parts.push({
|
|
2087
|
+
type: "text",
|
|
2088
|
+
text: coreMessage.content
|
|
2089
|
+
});
|
|
2090
|
+
} else if (Array.isArray(coreMessage.content)) {
|
|
2091
|
+
for (const part of coreMessage.content) {
|
|
2092
|
+
switch (part.type) {
|
|
2093
|
+
case "text":
|
|
2094
|
+
parts.push({
|
|
2095
|
+
type: "text",
|
|
2096
|
+
text: part.text,
|
|
2097
|
+
providerMetadata: part.providerOptions
|
|
2098
|
+
});
|
|
2099
|
+
break;
|
|
2100
|
+
case "tool-call":
|
|
2101
|
+
parts.push({
|
|
2102
|
+
type: "dynamic-tool",
|
|
2103
|
+
toolName: part.toolName,
|
|
2104
|
+
state: "input-available",
|
|
2105
|
+
toolCallId: part.toolCallId,
|
|
2106
|
+
input: part.input
|
|
2107
|
+
});
|
|
2108
|
+
break;
|
|
2109
|
+
case "tool-result":
|
|
2110
|
+
parts.push({
|
|
2111
|
+
type: "dynamic-tool",
|
|
2112
|
+
toolName: part.toolName,
|
|
2113
|
+
state: "output-available",
|
|
2114
|
+
toolCallId: part.toolCallId,
|
|
2115
|
+
output: typeof part.output === "string" ? { type: "text", value: part.output } : part.output ?? { type: "text", value: "" },
|
|
2116
|
+
input: {},
|
|
2117
|
+
callProviderMetadata: part.providerOptions
|
|
2118
|
+
});
|
|
2119
|
+
break;
|
|
2120
|
+
case "reasoning":
|
|
2121
|
+
parts.push({
|
|
2122
|
+
type: "reasoning",
|
|
2123
|
+
text: part.text,
|
|
2124
|
+
providerMetadata: part.providerOptions
|
|
2125
|
+
});
|
|
2126
|
+
break;
|
|
2127
|
+
case "image":
|
|
2128
|
+
parts.push({
|
|
2129
|
+
type: "file",
|
|
2130
|
+
url: part.image.toString(),
|
|
2131
|
+
mediaType: part.mediaType || "unknown",
|
|
2132
|
+
providerMetadata: part.providerOptions
|
|
2133
|
+
});
|
|
2134
|
+
break;
|
|
2135
|
+
case "file":
|
|
2136
|
+
if (part.data instanceof URL) {
|
|
2137
|
+
parts.push({
|
|
2138
|
+
type: "file",
|
|
2139
|
+
url: part.data.toString(),
|
|
2140
|
+
mediaType: part.mediaType,
|
|
2141
|
+
providerMetadata: part.providerOptions
|
|
2142
|
+
});
|
|
2143
|
+
} else {
|
|
2144
|
+
try {
|
|
2145
|
+
parts.push({
|
|
2146
|
+
type: "file",
|
|
2147
|
+
mediaType: part.mediaType,
|
|
2148
|
+
url: convertDataContentToBase64String(part.data),
|
|
2149
|
+
providerMetadata: part.providerOptions
|
|
2150
|
+
});
|
|
2151
|
+
} catch (error) {
|
|
2152
|
+
console.error(`Failed to convert binary data to base64 in CoreMessage file part: ${error}`, error);
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
break;
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
const content = {
|
|
2160
|
+
format: 3,
|
|
2161
|
+
parts
|
|
2162
|
+
};
|
|
2163
|
+
if (coreMessage.content) {
|
|
2164
|
+
content.metadata = {
|
|
2165
|
+
...content.metadata || {},
|
|
2166
|
+
__originalContent: coreMessage.content
|
|
2167
|
+
};
|
|
2168
|
+
}
|
|
2169
|
+
return {
|
|
2170
|
+
id,
|
|
2171
|
+
role: _MessageList.getRole(coreMessage),
|
|
2172
|
+
createdAt: this.generateCreatedAt(messageSource),
|
|
2173
|
+
threadId: this.memoryInfo?.threadId,
|
|
2174
|
+
resourceId: this.memoryInfo?.resourceId,
|
|
2175
|
+
content
|
|
2176
|
+
};
|
|
2177
|
+
}
|
|
2178
|
+
static hasAIV5UIMessageCharacteristics(msg) {
|
|
2179
|
+
if (`toolInvocations` in msg || `reasoning` in msg || `experimental_attachments` in msg || `data` in msg || `annotations` in msg)
|
|
2180
|
+
return false;
|
|
2181
|
+
if (!msg.parts) return false;
|
|
2182
|
+
for (const part of msg.parts) {
|
|
2183
|
+
if (`metadata` in part) return true;
|
|
2184
|
+
if (`toolInvocation` in part) return false;
|
|
2185
|
+
if (`toolCallId` in part) return true;
|
|
2186
|
+
if (part.type === `source`) return false;
|
|
2187
|
+
if (part.type === `source-url`) return true;
|
|
2188
|
+
if (part.type === `reasoning`) {
|
|
2189
|
+
if (`state` in part || `text` in part) return true;
|
|
2190
|
+
if (`reasoning` in part || `details` in part) return false;
|
|
2191
|
+
}
|
|
2192
|
+
if (part.type === `file` && `mediaType` in part) return true;
|
|
2193
|
+
}
|
|
2194
|
+
return false;
|
|
2195
|
+
}
|
|
2196
|
+
static isAIV5UIMessage(msg) {
|
|
2197
|
+
return !_MessageList.isMastraMessage(msg) && !_MessageList.isAIV5CoreMessage(msg) && `parts` in msg && _MessageList.hasAIV5UIMessageCharacteristics(msg);
|
|
2198
|
+
}
|
|
2199
|
+
static hasAIV5CoreMessageCharacteristics(msg) {
|
|
2200
|
+
if (`experimental_providerMetadata` in msg) return false;
|
|
2201
|
+
if (typeof msg.content === `string`) return false;
|
|
2202
|
+
for (const part of msg.content) {
|
|
2203
|
+
if (part.type === `tool-result` && `output` in part) return true;
|
|
2204
|
+
if (part.type === `tool-call` && `input` in part) return true;
|
|
2205
|
+
if (part.type === `tool-result` && `result` in part) return false;
|
|
2206
|
+
if (part.type === `tool-call` && `args` in part) return false;
|
|
2207
|
+
if (`mediaType` in part) return true;
|
|
2208
|
+
if (`mimeType` in part) return false;
|
|
2209
|
+
if (`experimental_providerMetadata` in part) return false;
|
|
2210
|
+
if (part.type === `reasoning` && `signature` in part) return false;
|
|
2211
|
+
if (part.type === `redacted-reasoning`) return false;
|
|
2212
|
+
}
|
|
2213
|
+
return false;
|
|
2214
|
+
}
|
|
2215
|
+
static cacheKeyFromAIV5Parts(parts) {
|
|
2216
|
+
let key = ``;
|
|
2217
|
+
for (const part of parts) {
|
|
2218
|
+
key += part.type;
|
|
2219
|
+
if (part.type === `text`) {
|
|
2220
|
+
key += part.text;
|
|
2221
|
+
}
|
|
2222
|
+
if (AIV5__namespace.isToolUIPart(part) || part.type === "dynamic-tool") {
|
|
2223
|
+
key += part.toolCallId;
|
|
2224
|
+
key += part.state;
|
|
2225
|
+
}
|
|
2226
|
+
if (part.type === `reasoning`) {
|
|
2227
|
+
key += part.text;
|
|
2228
|
+
}
|
|
2229
|
+
if (part.type === `file`) {
|
|
2230
|
+
key += part.url.length;
|
|
2231
|
+
key += part.mediaType;
|
|
2232
|
+
key += part.filename || "";
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
return key;
|
|
2236
|
+
}
|
|
2237
|
+
static cacheKeyFromAIV5ModelMessageContent(content) {
|
|
2238
|
+
if (typeof content === `string`) return content;
|
|
2239
|
+
let key = ``;
|
|
2240
|
+
for (const part of content) {
|
|
2241
|
+
key += part.type;
|
|
2242
|
+
if (part.type === `text`) {
|
|
2243
|
+
key += part.text.length;
|
|
2244
|
+
}
|
|
2245
|
+
if (part.type === `reasoning`) {
|
|
2246
|
+
key += part.text.length;
|
|
2247
|
+
}
|
|
2248
|
+
if (part.type === `tool-call`) {
|
|
2249
|
+
key += part.toolCallId;
|
|
2250
|
+
key += part.toolName;
|
|
2251
|
+
}
|
|
2252
|
+
if (part.type === `tool-result`) {
|
|
2253
|
+
key += part.toolCallId;
|
|
2254
|
+
key += part.toolName;
|
|
2255
|
+
}
|
|
2256
|
+
if (part.type === `file`) {
|
|
2257
|
+
key += part.filename;
|
|
2258
|
+
key += part.mediaType;
|
|
2259
|
+
}
|
|
2260
|
+
if (part.type === `image`) {
|
|
2261
|
+
key += part.image instanceof URL ? part.image.toString() : part.image.toString().length;
|
|
2262
|
+
key += part.mediaType;
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
return key;
|
|
2266
|
+
}
|
|
1238
2267
|
};
|
|
1239
2268
|
|
|
2269
|
+
exports.DefaultGeneratedFile = DefaultGeneratedFile;
|
|
2270
|
+
exports.DefaultGeneratedFileWithType = DefaultGeneratedFileWithType;
|
|
1240
2271
|
exports.MessageList = MessageList;
|
|
1241
|
-
//# sourceMappingURL=chunk-
|
|
1242
|
-
//# sourceMappingURL=chunk-
|
|
2272
|
+
//# sourceMappingURL=chunk-RJCNC57P.cjs.map
|
|
2273
|
+
//# sourceMappingURL=chunk-RJCNC57P.cjs.map
|