@mastra/core 1.0.0-beta.13 → 1.0.0-beta.15
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 +477 -0
- package/dist/agent/agent-legacy.d.ts.map +1 -1
- package/dist/agent/agent.d.ts +2 -2
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.types.d.ts +6 -7
- package/dist/agent/agent.types.d.ts.map +1 -1
- package/dist/agent/index.cjs +17 -9
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +2 -2
- package/dist/agent/message-list/index.cjs +3 -3
- package/dist/agent/message-list/index.d.ts +1 -1
- 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/trip-wire.d.ts +2 -2
- package/dist/agent/trip-wire.d.ts.map +1 -1
- package/dist/agent/utils.d.ts +4 -1
- package/dist/agent/utils.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +3 -3
- 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 +3 -3
- 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 +3 -3
- package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts.map +1 -1
- package/dist/bundler/types.d.ts +1 -0
- package/dist/bundler/types.d.ts.map +1 -1
- package/dist/chunk-2AU5ZHBL.js +79 -0
- package/dist/chunk-2AU5ZHBL.js.map +1 -0
- package/dist/{chunk-7HEAVZRS.cjs → chunk-2OOMJRXZ.cjs} +15 -15
- package/dist/{chunk-7HEAVZRS.cjs.map → chunk-2OOMJRXZ.cjs.map} +1 -1
- package/dist/chunk-37YWZMBX.js +27 -0
- package/dist/chunk-37YWZMBX.js.map +1 -0
- package/dist/{chunk-VETAQUW3.js → chunk-3HDRO3GG.js} +790 -1206
- package/dist/chunk-3HDRO3GG.js.map +1 -0
- package/dist/{chunk-MRRFTNF4.js → chunk-4DFWV4IR.js} +3 -4
- package/dist/chunk-4DFWV4IR.js.map +1 -0
- package/dist/{chunk-373OC54J.js → chunk-4HP7CS6L.js} +7 -6
- package/dist/chunk-4HP7CS6L.js.map +1 -0
- package/dist/{chunk-62Q7K656.js → chunk-4J4M2Q5R.js} +125 -121
- package/dist/chunk-4J4M2Q5R.js.map +1 -0
- package/dist/{chunk-HWMMIRIF.cjs → chunk-4U7ZLI36.cjs} +3 -2
- package/dist/chunk-4U7ZLI36.cjs.map +1 -0
- package/dist/{chunk-Z55SJVEC.cjs → chunk-6HJFCSJ4.cjs} +7 -6
- package/dist/chunk-6HJFCSJ4.cjs.map +1 -0
- package/dist/{chunk-Y7MZ5LJT.cjs → chunk-AAX7ZOM7.cjs} +101 -102
- package/dist/chunk-AAX7ZOM7.cjs.map +1 -0
- package/dist/{chunk-WPTTKULS.js → chunk-AR5CF3IN.js} +4 -4
- package/dist/{chunk-WPTTKULS.js.map → chunk-AR5CF3IN.js.map} +1 -1
- package/dist/{chunk-5VZGJTPR.js → chunk-BAZHNX5P.js} +57 -11
- package/dist/chunk-BAZHNX5P.js.map +1 -0
- package/dist/{chunk-MLKE7HRS.cjs → chunk-BC2VKOH4.cjs} +43 -21
- package/dist/chunk-BC2VKOH4.cjs.map +1 -0
- package/dist/{chunk-2IU4RGU5.js → chunk-BCUKD2XG.js} +59 -19
- package/dist/chunk-BCUKD2XG.js.map +1 -0
- package/dist/{chunk-WYGUWVTF.js → chunk-CBQ6WDUJ.js} +9 -9
- package/dist/chunk-CBQ6WDUJ.js.map +1 -0
- package/dist/chunk-CBVHOGXX.cjs +674 -0
- package/dist/chunk-CBVHOGXX.cjs.map +1 -0
- package/dist/{chunk-PJAK4U6R.cjs → chunk-CBY37FTP.cjs} +28 -28
- package/dist/chunk-CBY37FTP.cjs.map +1 -0
- package/dist/{chunk-BQDZIQ3G.js → chunk-D2IFWD7A.js} +365 -137
- package/dist/chunk-D2IFWD7A.js.map +1 -0
- package/dist/{chunk-R5AJGM55.cjs → chunk-DDK3URK2.cjs} +987 -519
- package/dist/chunk-DDK3URK2.cjs.map +1 -0
- package/dist/chunk-DRJTNGI4.cjs +263 -0
- package/dist/chunk-DRJTNGI4.cjs.map +1 -0
- package/dist/{chunk-X6IBA7FP.cjs → chunk-EMLEZXTQ.cjs} +22 -120
- package/dist/chunk-EMLEZXTQ.cjs.map +1 -0
- package/dist/{chunk-OWIEOL55.cjs → chunk-F75EQ574.cjs} +695 -254
- package/dist/chunk-F75EQ574.cjs.map +1 -0
- package/dist/{chunk-YPLZDWG7.js → chunk-FJEVLHJT.js} +3 -2
- package/dist/chunk-FJEVLHJT.js.map +1 -0
- package/dist/chunk-GVAPYQRO.cjs +252 -0
- package/dist/chunk-GVAPYQRO.cjs.map +1 -0
- package/dist/{chunk-MXBVP7HX.cjs → chunk-GXMJ5URG.cjs} +227 -181
- package/dist/chunk-GXMJ5URG.cjs.map +1 -0
- package/dist/chunk-H2NHG7QL.cjs +32 -0
- package/dist/chunk-H2NHG7QL.cjs.map +1 -0
- package/dist/chunk-HAYBGFPA.js +259 -0
- package/dist/chunk-HAYBGFPA.js.map +1 -0
- package/dist/{chunk-GIWC35YQ.js → chunk-IHISDRFV.js} +299 -49
- package/dist/chunk-IHISDRFV.js.map +1 -0
- package/dist/{chunk-VEPP75C4.cjs → chunk-IRTICXRZ.cjs} +101 -61
- package/dist/chunk-IRTICXRZ.cjs.map +1 -0
- package/dist/{chunk-ARAQIW6E.js → chunk-K66U47VL.js} +617 -188
- package/dist/chunk-K66U47VL.js.map +1 -0
- package/dist/{chunk-LGB4VNZI.cjs → chunk-LOV5NNGK.cjs} +811 -1235
- package/dist/chunk-LOV5NNGK.cjs.map +1 -0
- package/dist/{chunk-E5BQRAJK.js → chunk-NGWTSHNA.js} +823 -362
- package/dist/chunk-NGWTSHNA.js.map +1 -0
- package/dist/{chunk-72YCRTEX.cjs → chunk-O2CAMK4A.cjs} +13 -2
- package/dist/chunk-O2CAMK4A.cjs.map +1 -0
- package/dist/{chunk-4BC5FUAO.js → chunk-O7M7DR4E.js} +6 -5
- package/dist/chunk-O7M7DR4E.js.map +1 -0
- package/dist/chunk-OTIGV7CL.js +10215 -0
- package/dist/chunk-OTIGV7CL.js.map +1 -0
- package/dist/{chunk-WYWRMIQC.js → chunk-QXL3F3T2.js} +9 -105
- package/dist/chunk-QXL3F3T2.js.map +1 -0
- package/dist/{chunk-U4CSOY6T.cjs → chunk-RA2CHJCY.cjs} +399 -171
- package/dist/chunk-RA2CHJCY.cjs.map +1 -0
- package/dist/chunk-RMV5HJM7.cjs +10237 -0
- package/dist/chunk-RMV5HJM7.cjs.map +1 -0
- package/dist/{chunk-AGHLXC4I.cjs → chunk-S23TNDXG.cjs} +300 -50
- package/dist/chunk-S23TNDXG.cjs.map +1 -0
- package/dist/{chunk-H4VUIOWU.cjs → chunk-SSB4AVHU.cjs} +20 -19
- package/dist/chunk-SSB4AVHU.cjs.map +1 -0
- package/dist/chunk-ST7NBF4H.cjs +84 -0
- package/dist/chunk-ST7NBF4H.cjs.map +1 -0
- package/dist/{chunk-SZYSDJTN.cjs → chunk-T2LVULCK.cjs} +142 -137
- package/dist/chunk-T2LVULCK.cjs.map +1 -0
- package/dist/chunk-VE6HQ7H6.js +250 -0
- package/dist/chunk-VE6HQ7H6.js.map +1 -0
- package/dist/{chunk-RCJLMMTO.js → chunk-XJB7J4UT.js} +30 -8
- package/dist/chunk-XJB7J4UT.js.map +1 -0
- package/dist/chunk-YV43YEZ6.js +598 -0
- package/dist/chunk-YV43YEZ6.js.map +1 -0
- package/dist/{chunk-Y36Y5MTD.js → chunk-ZGIVAQRI.js} +13 -3
- package/dist/chunk-ZGIVAQRI.js.map +1 -0
- package/dist/error/index.cjs +6 -6
- package/dist/error/index.d.ts +1 -0
- package/dist/error/index.d.ts.map +1 -1
- package/dist/error/index.js +1 -1
- package/dist/evals/index.cjs +49 -9
- package/dist/evals/index.js +2 -2
- package/dist/evals/run/index.d.ts.map +1 -1
- package/dist/evals/scoreTraces/index.cjs +70 -22
- package/dist/evals/scoreTraces/index.cjs.map +1 -1
- package/dist/evals/scoreTraces/index.js +63 -15
- package/dist/evals/scoreTraces/index.js.map +1 -1
- package/dist/evals/scoreTraces/scoreTracesWorkflow.d.ts.map +1 -1
- package/dist/evals/scoreTraces/utils.d.ts.map +1 -1
- package/dist/evals/types.d.ts +568 -116
- 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 +21 -21
- package/dist/llm/index.js +5 -5
- package/dist/llm/model/aisdk/generate-to-stream.d.ts +20 -0
- package/dist/llm/model/aisdk/generate-to-stream.d.ts.map +1 -0
- package/dist/llm/model/aisdk/v5/model.d.ts +4 -0
- package/dist/llm/model/aisdk/v5/model.d.ts.map +1 -1
- package/dist/llm/model/aisdk/v6/model.d.ts +43 -0
- package/dist/llm/model/aisdk/v6/model.d.ts.map +1 -0
- package/dist/llm/model/embedding-router.d.ts +1 -1
- package/dist/llm/model/model.d.ts.map +1 -1
- package/dist/llm/model/model.loop.d.ts +1 -1
- package/dist/llm/model/model.loop.d.ts.map +1 -1
- package/dist/llm/model/provider-options.d.ts +2 -1
- package/dist/llm/model/provider-options.d.ts.map +1 -1
- package/dist/llm/model/provider-types.generated.d.ts +126 -17
- package/dist/llm/model/resolve-model.d.ts +2 -2
- package/dist/llm/model/resolve-model.d.ts.map +1 -1
- package/dist/llm/model/shared.types.d.ts +18 -7
- package/dist/llm/model/shared.types.d.ts.map +1 -1
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/network/index.d.ts +8 -8
- package/dist/loop/network/index.d.ts.map +1 -1
- package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts +1 -1
- package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts.map +1 -1
- package/dist/loop/test-utils/MastraLanguageModelV3Mock.d.ts +29 -0
- package/dist/loop/test-utils/MastraLanguageModelV3Mock.d.ts.map +1 -0
- package/dist/loop/test-utils/fullStream.d.ts +2 -1
- package/dist/loop/test-utils/fullStream.d.ts.map +1 -1
- package/dist/loop/test-utils/resultObject.d.ts +2 -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/utils-v3.d.ts +55 -0
- package/dist/loop/test-utils/utils-v3.d.ts.map +1 -0
- package/dist/loop/types.d.ts +10 -8
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +36 -36
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +25 -25
- 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 +12 -12
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts +36 -36
- 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 +12 -12
- package/dist/mastra/hooks.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.ts +7 -2
- 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 +1 -1
- package/dist/memory/index.cjs +26 -6
- package/dist/memory/index.d.ts +1 -0
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +1 -1
- package/dist/memory/memory.d.ts +9 -8
- package/dist/memory/memory.d.ts.map +1 -1
- package/dist/memory/mock.d.ts +2 -1
- package/dist/memory/mock.d.ts.map +1 -1
- package/dist/memory/types.d.ts +3 -4
- package/dist/memory/types.d.ts.map +1 -1
- package/dist/memory/working-memory-utils.d.ts +20 -0
- package/dist/memory/working-memory-utils.d.ts.map +1 -0
- package/dist/models-dev-26XLUKVK.cjs +12 -0
- package/dist/{models-dev-D3EKFGAO.cjs.map → models-dev-26XLUKVK.cjs.map} +1 -1
- package/dist/models-dev-HUFLQFPB.js +3 -0
- package/dist/{models-dev-EO22XOXQ.js.map → models-dev-HUFLQFPB.js.map} +1 -1
- package/dist/netlify-CUYK2MZ2.cjs +12 -0
- package/dist/{netlify-WE42TZIT.cjs.map → netlify-CUYK2MZ2.cjs.map} +1 -1
- package/dist/netlify-J4QPOROO.js +3 -0
- package/dist/{netlify-AE4LNCAI.js.map → netlify-J4QPOROO.js.map} +1 -1
- package/dist/observability/index.cjs +14 -10
- package/dist/observability/index.js +1 -1
- package/dist/observability/types/tracing.d.ts +32 -19
- package/dist/observability/types/tracing.d.ts.map +1 -1
- package/dist/processors/index.cjs +37 -37
- package/dist/processors/index.d.ts +9 -7
- package/dist/processors/index.d.ts.map +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/memory/message-history.d.ts +7 -1
- package/dist/processors/memory/message-history.d.ts.map +1 -1
- package/dist/processors/processors/language-detector.d.ts.map +1 -1
- package/dist/processors/processors/moderation.d.ts.map +1 -1
- package/dist/processors/processors/pii-detector.d.ts.map +1 -1
- package/dist/processors/processors/prompt-injection-detector.d.ts.map +1 -1
- package/dist/processors/processors/token-limiter.d.ts +5 -2
- package/dist/processors/processors/token-limiter.d.ts.map +1 -1
- package/dist/processors/runner.d.ts +2 -0
- package/dist/processors/runner.d.ts.map +1 -1
- package/dist/processors/step-schema.d.ts +26 -26
- package/dist/processors/step-schema.d.ts.map +1 -1
- package/dist/provider-registry-6CIGRQVZ.js +3 -0
- package/dist/{provider-registry-6LF3NGC5.js.map → provider-registry-6CIGRQVZ.js.map} +1 -1
- package/dist/provider-registry-7O7FJ4BS.cjs +40 -0
- package/dist/{provider-registry-73FKMXJV.cjs.map → provider-registry-7O7FJ4BS.cjs.map} +1 -1
- package/dist/provider-registry.json +295 -45
- package/dist/relevance/index.cjs +3 -3
- package/dist/relevance/index.cjs.map +1 -1
- package/dist/relevance/index.js +2 -2
- package/dist/relevance/index.js.map +1 -1
- package/dist/server/index.cjs +5 -5
- package/dist/server/index.js +1 -1
- package/dist/storage/base.d.ts +40 -292
- package/dist/storage/base.d.ts.map +1 -1
- package/dist/storage/constants.cjs +60 -0
- package/dist/storage/constants.cjs.map +1 -0
- package/dist/storage/constants.d.ts +6 -1
- package/dist/storage/constants.d.ts.map +1 -1
- package/dist/storage/constants.js +3 -0
- package/dist/storage/constants.js.map +1 -0
- package/dist/storage/domains/agents/base.d.ts +2 -2
- package/dist/storage/domains/agents/base.d.ts.map +1 -1
- package/dist/storage/domains/agents/inmemory.d.ts +5 -4
- package/dist/storage/domains/agents/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/base.d.ts +20 -0
- package/dist/storage/domains/base.d.ts.map +1 -0
- package/dist/storage/domains/index.d.ts +3 -0
- package/dist/storage/domains/index.d.ts.map +1 -1
- package/dist/storage/domains/inmemory-db.d.ts +57 -0
- package/dist/storage/domains/inmemory-db.d.ts.map +1 -0
- package/dist/storage/domains/memory/base.d.ts +2 -2
- package/dist/storage/domains/memory/base.d.ts.map +1 -1
- package/dist/storage/domains/memory/inmemory.d.ts +5 -13
- package/dist/storage/domains/memory/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/observability/base.d.ts +24 -29
- package/dist/storage/domains/observability/base.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts +1 -0
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/inmemory.d.ts +46 -35
- package/dist/storage/domains/observability/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/observability/types.d.ts +2365 -0
- package/dist/storage/domains/observability/types.d.ts.map +1 -0
- package/dist/storage/domains/scores/base.d.ts +9 -20
- package/dist/storage/domains/scores/base.d.ts.map +1 -1
- package/dist/storage/domains/scores/inmemory.d.ts +11 -22
- package/dist/storage/domains/scores/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/shared.d.ts +76 -0
- package/dist/storage/domains/shared.d.ts.map +1 -0
- package/dist/storage/domains/workflows/base.d.ts +4 -2
- package/dist/storage/domains/workflows/base.d.ts.map +1 -1
- package/dist/storage/domains/workflows/inmemory.d.ts +10 -9
- package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
- package/dist/storage/index.cjs +272 -59
- package/dist/storage/index.js +2 -1
- package/dist/storage/mock.d.ts +28 -174
- package/dist/storage/mock.d.ts.map +1 -1
- package/dist/storage/types.d.ts +39 -44
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/storage/utils.d.ts +5 -0
- package/dist/storage/utils.d.ts.map +1 -1
- package/dist/stream/MastraAgentNetworkStream.d.ts +1 -1
- package/dist/stream/MastraAgentNetworkStream.d.ts.map +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts.map +1 -1
- package/dist/stream/RunOutput.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/execute.d.ts +4 -4
- package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/output.d.ts +2 -2
- package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/transform.d.ts.map +1 -1
- package/dist/stream/base/output.d.ts +7 -5
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/index.cjs +12 -12
- package/dist/stream/index.js +2 -2
- package/dist/stream/types.d.ts +32 -21
- package/dist/stream/types.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.cjs +4 -4
- package/dist/test-utils/llm-mock.cjs.map +1 -1
- package/dist/test-utils/llm-mock.js +1 -1
- package/dist/test-utils/llm-mock.js.map +1 -1
- package/dist/token-6GSAFR2W-LTZ7QQUP.js +61 -0
- package/dist/token-6GSAFR2W-LTZ7QQUP.js.map +1 -0
- package/dist/token-6GSAFR2W-UEEINYAN.cjs +63 -0
- package/dist/token-6GSAFR2W-UEEINYAN.cjs.map +1 -0
- package/dist/token-util-NEHG7TUY-QTFZ26EN.js +8 -0
- package/dist/token-util-NEHG7TUY-QTFZ26EN.js.map +1 -0
- package/dist/token-util-NEHG7TUY-WZL2DNCG.cjs +10 -0
- package/dist/token-util-NEHG7TUY-WZL2DNCG.cjs.map +1 -0
- package/dist/tool-loop-agent/index.cjs +20 -0
- package/dist/tool-loop-agent/index.cjs.map +1 -0
- package/dist/tool-loop-agent/index.d.ts +36 -0
- package/dist/tool-loop-agent/index.d.ts.map +1 -0
- package/dist/tool-loop-agent/index.js +3 -0
- package/dist/tool-loop-agent/index.js.map +1 -0
- package/dist/tool-loop-agent/tool-loop-processor.d.ts +30 -0
- package/dist/tool-loop-agent/tool-loop-processor.d.ts.map +1 -0
- package/dist/tool-loop-agent/utils.d.ts +17 -0
- package/dist/tool-loop-agent/utils.d.ts.map +1 -0
- package/dist/tools/index.cjs +4 -4
- package/dist/tools/index.js +1 -1
- package/dist/tools/is-vercel-tool.cjs +2 -2
- package/dist/tools/is-vercel-tool.js +1 -1
- package/dist/tools/tool-builder/builder.d.ts.map +1 -1
- package/dist/tools/toolchecks.d.ts +1 -1
- package/dist/tools/toolchecks.d.ts.map +1 -1
- package/dist/tools/validation.d.ts +1 -1
- package/dist/tools/validation.d.ts.map +1 -1
- package/dist/utils/zod-utils.d.ts +34 -0
- package/dist/utils/zod-utils.d.ts.map +1 -0
- package/dist/utils.cjs +39 -22
- package/dist/utils.d.ts +3 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +2 -1
- package/dist/vector/embed.d.ts +1 -0
- package/dist/vector/embed.d.ts.map +1 -1
- package/dist/vector/index.cjs +18 -5
- package/dist/vector/index.cjs.map +1 -1
- package/dist/vector/index.js +9 -2
- package/dist/vector/index.js.map +1 -1
- package/dist/vector/vector.d.ts +26 -3
- package/dist/vector/vector.d.ts.map +1 -1
- package/dist/voice/composite-voice.d.ts.map +1 -1
- package/dist/voice/index.cjs +6 -6
- package/dist/voice/index.js +1 -1
- package/dist/workflows/default.d.ts +2 -0
- package/dist/workflows/default.d.ts.map +1 -1
- package/dist/workflows/evented/execution-engine.d.ts +1 -0
- 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 +5 -0
- package/dist/workflows/evented/step-executor.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/index.d.ts +20 -4
- package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/loop.d.ts +2 -2
- 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 +10 -2
- package/dist/workflows/evented/workflow.d.ts.map +1 -1
- package/dist/workflows/execution-engine.d.ts +1 -0
- package/dist/workflows/execution-engine.d.ts.map +1 -1
- package/dist/workflows/handlers/control-flow.d.ts +4 -0
- package/dist/workflows/handlers/control-flow.d.ts.map +1 -1
- package/dist/workflows/handlers/entry.d.ts +3 -2
- package/dist/workflows/handlers/entry.d.ts.map +1 -1
- package/dist/workflows/handlers/step.d.ts +1 -0
- package/dist/workflows/handlers/step.d.ts.map +1 -1
- package/dist/workflows/index.cjs +23 -23
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/types.d.ts +23 -3
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/utils.d.ts +1 -0
- package/dist/workflows/utils.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +26 -9
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +20 -12
- package/src/llm/model/provider-types.generated.d.ts +126 -17
- package/storage/constants.d.ts +1 -0
- package/tool-loop-agent.d.ts +1 -0
- package/dist/chunk-2IU4RGU5.js.map +0 -1
- package/dist/chunk-373OC54J.js.map +0 -1
- package/dist/chunk-4BC5FUAO.js.map +0 -1
- package/dist/chunk-5VZGJTPR.js.map +0 -1
- package/dist/chunk-62Q7K656.js.map +0 -1
- package/dist/chunk-72YCRTEX.cjs.map +0 -1
- package/dist/chunk-ADADLFDR.js +0 -42
- package/dist/chunk-ADADLFDR.js.map +0 -1
- package/dist/chunk-AGHLXC4I.cjs.map +0 -1
- package/dist/chunk-ARAQIW6E.js.map +0 -1
- package/dist/chunk-BQDZIQ3G.js.map +0 -1
- package/dist/chunk-E5BQRAJK.js.map +0 -1
- package/dist/chunk-GIWC35YQ.js.map +0 -1
- package/dist/chunk-H4VUIOWU.cjs.map +0 -1
- package/dist/chunk-HWMMIRIF.cjs.map +0 -1
- package/dist/chunk-IXZ2T2QX.cjs +0 -448
- package/dist/chunk-IXZ2T2QX.cjs.map +0 -1
- package/dist/chunk-LGB4VNZI.cjs.map +0 -1
- package/dist/chunk-MLKE7HRS.cjs.map +0 -1
- package/dist/chunk-MRRFTNF4.js.map +0 -1
- package/dist/chunk-MXBVP7HX.cjs.map +0 -1
- package/dist/chunk-OWIEOL55.cjs.map +0 -1
- package/dist/chunk-PJAK4U6R.cjs.map +0 -1
- package/dist/chunk-R5AJGM55.cjs.map +0 -1
- package/dist/chunk-RCJLMMTO.js.map +0 -1
- package/dist/chunk-SZYSDJTN.cjs.map +0 -1
- package/dist/chunk-T2VLUFGG.cjs +0 -47
- package/dist/chunk-T2VLUFGG.cjs.map +0 -1
- package/dist/chunk-U4CSOY6T.cjs.map +0 -1
- package/dist/chunk-UBSPZTQX.js +0 -434
- package/dist/chunk-UBSPZTQX.js.map +0 -1
- package/dist/chunk-VEPP75C4.cjs.map +0 -1
- package/dist/chunk-VETAQUW3.js.map +0 -1
- package/dist/chunk-WYGUWVTF.js.map +0 -1
- package/dist/chunk-WYWRMIQC.js.map +0 -1
- package/dist/chunk-X6IBA7FP.cjs.map +0 -1
- package/dist/chunk-Y36Y5MTD.js.map +0 -1
- package/dist/chunk-Y7MZ5LJT.cjs.map +0 -1
- package/dist/chunk-YPLZDWG7.js.map +0 -1
- package/dist/chunk-Z55SJVEC.cjs.map +0 -1
- package/dist/llm/model/is-v2-model.d.ts +0 -3
- package/dist/llm/model/is-v2-model.d.ts.map +0 -1
- package/dist/models-dev-D3EKFGAO.cjs +0 -12
- package/dist/models-dev-EO22XOXQ.js +0 -3
- package/dist/netlify-AE4LNCAI.js +0 -3
- package/dist/netlify-WE42TZIT.cjs +0 -12
- package/dist/provider-registry-6LF3NGC5.js +0 -3
- package/dist/provider-registry-73FKMXJV.cjs +0 -40
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkSSB4AVHU_cjs = require('./chunk-SSB4AVHU.cjs');
|
|
4
4
|
var chunkL3NKIMF5_cjs = require('./chunk-L3NKIMF5.cjs');
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var chunkLOV5NNGK_cjs = require('./chunk-LOV5NNGK.cjs');
|
|
6
|
+
var chunkEMLEZXTQ_cjs = require('./chunk-EMLEZXTQ.cjs');
|
|
7
7
|
var chunkNESKUIRE_cjs = require('./chunk-NESKUIRE.cjs');
|
|
8
8
|
var chunkFVQTJUBD_cjs = require('./chunk-FVQTJUBD.cjs');
|
|
9
|
+
var chunkGXMJ5URG_cjs = require('./chunk-GXMJ5URG.cjs');
|
|
10
|
+
var chunkT2LVULCK_cjs = require('./chunk-T2LVULCK.cjs');
|
|
9
11
|
var chunk4D4KB75Y_cjs = require('./chunk-4D4KB75Y.cjs');
|
|
10
12
|
var chunkMR7ZWBL6_cjs = require('./chunk-MR7ZWBL6.cjs');
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
13
|
+
var chunkBC2VKOH4_cjs = require('./chunk-BC2VKOH4.cjs');
|
|
14
|
+
var chunkO2CAMK4A_cjs = require('./chunk-O2CAMK4A.cjs');
|
|
15
|
+
var chunk4U7ZLI36_cjs = require('./chunk-4U7ZLI36.cjs');
|
|
14
16
|
var chunkKJBMTK5B_cjs = require('./chunk-KJBMTK5B.cjs');
|
|
15
|
-
var
|
|
16
|
-
var chunk72YCRTEX_cjs = require('./chunk-72YCRTEX.cjs');
|
|
17
|
+
var chunk6HJFCSJ4_cjs = require('./chunk-6HJFCSJ4.cjs');
|
|
17
18
|
var chunkUVHSM2GU_cjs = require('./chunk-UVHSM2GU.cjs');
|
|
18
|
-
var chunkHWMMIRIF_cjs = require('./chunk-HWMMIRIF.cjs');
|
|
19
19
|
var chunk4WQYXT2I_cjs = require('./chunk-4WQYXT2I.cjs');
|
|
20
20
|
var chunkDGV2FWB4_cjs = require('./chunk-DGV2FWB4.cjs');
|
|
21
21
|
var chunkAF74UXR5_cjs = require('./chunk-AF74UXR5.cjs');
|
|
@@ -28,6 +28,7 @@ var providerV5 = require('@ai-sdk/provider-v5');
|
|
|
28
28
|
var z4 = require('zod/v4');
|
|
29
29
|
var schemaCompat = require('@mastra/schema-compat');
|
|
30
30
|
var radash = require('radash');
|
|
31
|
+
var providerUtilsV5 = require('@ai-sdk/provider-utils-v5');
|
|
31
32
|
var lite = require('js-tiktoken/lite');
|
|
32
33
|
var o200k_base = require('js-tiktoken/ranks/o200k_base');
|
|
33
34
|
var lruCache = require('lru-cache');
|
|
@@ -558,7 +559,7 @@ var StructuredOutputProcessor = class {
|
|
|
558
559
|
providerOptions;
|
|
559
560
|
constructor(options) {
|
|
560
561
|
if (!options.schema) {
|
|
561
|
-
throw new
|
|
562
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
562
563
|
id: "STRUCTURED_OUTPUT_PROCESSOR_SCHEMA_REQUIRED",
|
|
563
564
|
domain: "AGENT" /* AGENT */,
|
|
564
565
|
category: "USER" /* USER */,
|
|
@@ -566,7 +567,7 @@ var StructuredOutputProcessor = class {
|
|
|
566
567
|
});
|
|
567
568
|
}
|
|
568
569
|
if (!options.model) {
|
|
569
|
-
throw new
|
|
570
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
570
571
|
id: "STRUCTURED_OUTPUT_PROCESSOR_MODEL_REQUIRED",
|
|
571
572
|
domain: "AGENT" /* AGENT */,
|
|
572
573
|
category: "USER" /* USER */,
|
|
@@ -756,6 +757,69 @@ The input text may be in any format (sentences, bullet points, paragraphs, etc.)
|
|
|
756
757
|
}
|
|
757
758
|
};
|
|
758
759
|
|
|
760
|
+
// src/agent/utils.ts
|
|
761
|
+
var supportedLanguageModelSpecifications = ["v2", "v3"];
|
|
762
|
+
var isSupportedLanguageModel = (model) => {
|
|
763
|
+
return supportedLanguageModelSpecifications.includes(model.specificationVersion);
|
|
764
|
+
};
|
|
765
|
+
async function tryGenerateWithJsonFallback(agent, prompt, options) {
|
|
766
|
+
if (!options.structuredOutput?.schema) {
|
|
767
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
768
|
+
id: "STRUCTURED_OUTPUT_OPTIONS_REQUIRED",
|
|
769
|
+
domain: "AGENT" /* AGENT */,
|
|
770
|
+
category: "USER" /* USER */,
|
|
771
|
+
text: "structuredOutput is required to use tryGenerateWithJsonFallback"
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
try {
|
|
775
|
+
return await agent.generate(prompt, options);
|
|
776
|
+
} catch (error) {
|
|
777
|
+
console.warn("Error in tryGenerateWithJsonFallback. Attempting fallback.", error);
|
|
778
|
+
return await agent.generate(prompt, {
|
|
779
|
+
...options,
|
|
780
|
+
structuredOutput: { ...options.structuredOutput, jsonPromptInjection: true }
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
async function tryStreamWithJsonFallback(agent, prompt, options) {
|
|
785
|
+
if (!options.structuredOutput?.schema) {
|
|
786
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
787
|
+
id: "STRUCTURED_OUTPUT_OPTIONS_REQUIRED",
|
|
788
|
+
domain: "AGENT" /* AGENT */,
|
|
789
|
+
category: "USER" /* USER */,
|
|
790
|
+
text: "structuredOutput is required to use tryStreamWithJsonFallback"
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
try {
|
|
794
|
+
const result = await agent.stream(prompt, options);
|
|
795
|
+
const object = await result.object;
|
|
796
|
+
if (!object) {
|
|
797
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
798
|
+
id: "STRUCTURED_OUTPUT_OBJECT_UNDEFINED",
|
|
799
|
+
domain: "AGENT" /* AGENT */,
|
|
800
|
+
category: "USER" /* USER */,
|
|
801
|
+
text: "structuredOutput object is undefined"
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
return result;
|
|
805
|
+
} catch (error) {
|
|
806
|
+
console.warn("Error in tryStreamWithJsonFallback. Attempting fallback.", error);
|
|
807
|
+
return await agent.stream(prompt, {
|
|
808
|
+
...options,
|
|
809
|
+
structuredOutput: { ...options.structuredOutput, jsonPromptInjection: true }
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
function resolveThreadIdFromArgs(args) {
|
|
814
|
+
if (args?.memory?.thread) {
|
|
815
|
+
if (typeof args.memory.thread === "string") return { id: args.memory.thread };
|
|
816
|
+
if (typeof args.memory.thread === "object" && args.memory.thread.id)
|
|
817
|
+
return args.memory.thread;
|
|
818
|
+
}
|
|
819
|
+
if (args?.threadId) return { id: args.threadId };
|
|
820
|
+
return void 0;
|
|
821
|
+
}
|
|
822
|
+
|
|
759
823
|
// src/processors/runner.ts
|
|
760
824
|
var ProcessorState = class {
|
|
761
825
|
accumulatedText = "";
|
|
@@ -769,8 +833,9 @@ var ProcessorState = class {
|
|
|
769
833
|
this.span = parentSpan?.createChildSpan({
|
|
770
834
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
771
835
|
name: `output processor: ${processorName}`,
|
|
836
|
+
entityType: "output_processor" /* OUTPUT_PROCESSOR */,
|
|
837
|
+
entityName: processorName,
|
|
772
838
|
attributes: {
|
|
773
|
-
processorName,
|
|
774
839
|
processorType: "output",
|
|
775
840
|
processorIndex: processorIndex ?? 0
|
|
776
841
|
},
|
|
@@ -836,7 +901,7 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
836
901
|
);
|
|
837
902
|
}
|
|
838
903
|
if (result.status !== "success") {
|
|
839
|
-
throw new
|
|
904
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
840
905
|
category: "USER",
|
|
841
906
|
domain: "AGENT",
|
|
842
907
|
id: "PROCESSOR_WORKFLOW_FAILED",
|
|
@@ -848,7 +913,7 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
848
913
|
return input;
|
|
849
914
|
}
|
|
850
915
|
if (!("phase" in output) || !("messages" in output || "part" in output || "messageList" in output)) {
|
|
851
|
-
throw new
|
|
916
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
852
917
|
category: "USER",
|
|
853
918
|
domain: "AGENT",
|
|
854
919
|
id: "PROCESSOR_WORKFLOW_INVALID_OUTPUT",
|
|
@@ -869,8 +934,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
869
934
|
const processorSpan2 = parentSpan2?.createChildSpan({
|
|
870
935
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
871
936
|
name: `output processor workflow: ${processorOrWorkflow.id}`,
|
|
937
|
+
entityType: "output_processor" /* OUTPUT_PROCESSOR */,
|
|
938
|
+
entityId: processorOrWorkflow.id,
|
|
939
|
+
entityName: processorOrWorkflow.name,
|
|
872
940
|
attributes: {
|
|
873
|
-
processorName: processorOrWorkflow.id,
|
|
874
941
|
processorType: "output",
|
|
875
942
|
processorIndex: index
|
|
876
943
|
},
|
|
@@ -911,8 +978,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
911
978
|
const processorSpan = parentSpan?.createChildSpan({
|
|
912
979
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
913
980
|
name: `output processor: ${processor.id}`,
|
|
981
|
+
entityType: "output_processor" /* OUTPUT_PROCESSOR */,
|
|
982
|
+
entityId: processor.id,
|
|
983
|
+
entityName: processor.name,
|
|
914
984
|
attributes: {
|
|
915
|
-
processorName: processor.name ?? processor.id,
|
|
916
985
|
processorType: "output",
|
|
917
986
|
processorIndex: index
|
|
918
987
|
},
|
|
@@ -928,9 +997,9 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
928
997
|
retryCount
|
|
929
998
|
});
|
|
930
999
|
const mutations = messageList.stopRecording();
|
|
931
|
-
if (result instanceof
|
|
1000
|
+
if (result instanceof chunkEMLEZXTQ_cjs.MessageList) {
|
|
932
1001
|
if (result !== messageList) {
|
|
933
|
-
throw new
|
|
1002
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
934
1003
|
category: "USER",
|
|
935
1004
|
domain: "AGENT",
|
|
936
1005
|
id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
|
|
@@ -1147,8 +1216,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1147
1216
|
const processorSpan2 = parentSpan2?.createChildSpan({
|
|
1148
1217
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
1149
1218
|
name: `input processor workflow: ${processorOrWorkflow.id}`,
|
|
1219
|
+
entityType: "input_processor" /* INPUT_PROCESSOR */,
|
|
1220
|
+
entityId: processorOrWorkflow.id,
|
|
1221
|
+
entityName: processorOrWorkflow.name,
|
|
1150
1222
|
attributes: {
|
|
1151
|
-
processorName: processorOrWorkflow.id,
|
|
1152
1223
|
processorType: "input",
|
|
1153
1224
|
processorIndex: index
|
|
1154
1225
|
},
|
|
@@ -1191,8 +1262,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1191
1262
|
const processorSpan = parentSpan?.createChildSpan({
|
|
1192
1263
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
1193
1264
|
name: `input processor: ${processor.id}`,
|
|
1265
|
+
entityType: "input_processor" /* INPUT_PROCESSOR */,
|
|
1266
|
+
entityId: processor.id,
|
|
1267
|
+
entityName: processor.name,
|
|
1194
1268
|
attributes: {
|
|
1195
|
-
processorName: processor.name ?? processor.id,
|
|
1196
1269
|
processorType: "input",
|
|
1197
1270
|
processorIndex: index
|
|
1198
1271
|
},
|
|
@@ -1210,9 +1283,9 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1210
1283
|
retryCount
|
|
1211
1284
|
});
|
|
1212
1285
|
let mutations;
|
|
1213
|
-
if (result instanceof
|
|
1286
|
+
if (result instanceof chunkEMLEZXTQ_cjs.MessageList) {
|
|
1214
1287
|
if (result !== messageList) {
|
|
1215
|
-
throw new
|
|
1288
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
1216
1289
|
category: "USER",
|
|
1217
1290
|
domain: "AGENT",
|
|
1218
1291
|
id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
|
|
@@ -1315,8 +1388,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1315
1388
|
const processorSpan2 = parentSpan?.createChildSpan({
|
|
1316
1389
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
1317
1390
|
name: `input step processor workflow: ${processorOrWorkflow.id}`,
|
|
1391
|
+
entityType: "input_processor" /* INPUT_PROCESSOR */,
|
|
1392
|
+
entityId: processorOrWorkflow.id,
|
|
1393
|
+
entityName: processorOrWorkflow.name,
|
|
1318
1394
|
attributes: {
|
|
1319
|
-
processorName: processorOrWorkflow.id,
|
|
1320
1395
|
processorType: "input",
|
|
1321
1396
|
processorIndex: index
|
|
1322
1397
|
},
|
|
@@ -1375,8 +1450,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1375
1450
|
const processorSpan = currentSpan?.createChildSpan({
|
|
1376
1451
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
1377
1452
|
name: `input step processor: ${processor.id}`,
|
|
1453
|
+
entityType: "input_processor" /* INPUT_PROCESSOR */,
|
|
1454
|
+
entityId: processor.id,
|
|
1455
|
+
entityName: processor.name,
|
|
1378
1456
|
attributes: {
|
|
1379
|
-
processorName: processor.name ?? processor.id,
|
|
1380
1457
|
processorType: "input",
|
|
1381
1458
|
processorIndex: index
|
|
1382
1459
|
},
|
|
@@ -1469,6 +1546,7 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1469
1546
|
*/
|
|
1470
1547
|
async runProcessOutputStep(args) {
|
|
1471
1548
|
const {
|
|
1549
|
+
steps,
|
|
1472
1550
|
messageList,
|
|
1473
1551
|
stepNumber,
|
|
1474
1552
|
finishReason,
|
|
@@ -1488,8 +1566,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1488
1566
|
const processorSpan2 = parentSpan2?.createChildSpan({
|
|
1489
1567
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
1490
1568
|
name: `output step processor workflow: ${processorOrWorkflow.id}`,
|
|
1569
|
+
entityType: "output_processor" /* OUTPUT_PROCESSOR */,
|
|
1570
|
+
entityId: processorOrWorkflow.id,
|
|
1571
|
+
entityName: processorOrWorkflow.name,
|
|
1491
1572
|
attributes: {
|
|
1492
|
-
processorName: processorOrWorkflow.id,
|
|
1493
1573
|
processorType: "output",
|
|
1494
1574
|
processorIndex: index
|
|
1495
1575
|
},
|
|
@@ -1508,6 +1588,7 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1508
1588
|
toolCalls,
|
|
1509
1589
|
text,
|
|
1510
1590
|
systemMessages: currentSystemMessages2,
|
|
1591
|
+
steps,
|
|
1511
1592
|
retryCount
|
|
1512
1593
|
},
|
|
1513
1594
|
tracingContext,
|
|
@@ -1536,8 +1617,10 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1536
1617
|
const processorSpan = parentSpan?.createChildSpan({
|
|
1537
1618
|
type: "processor_run" /* PROCESSOR_RUN */,
|
|
1538
1619
|
name: `output step processor: ${processor.id}`,
|
|
1620
|
+
entityType: "output_processor" /* OUTPUT_PROCESSOR */,
|
|
1621
|
+
entityId: processor.id,
|
|
1622
|
+
entityName: processor.name,
|
|
1539
1623
|
attributes: {
|
|
1540
|
-
processorName: processor.name ?? processor.id,
|
|
1541
1624
|
processorType: "output",
|
|
1542
1625
|
processorIndex: index
|
|
1543
1626
|
},
|
|
@@ -1554,15 +1637,16 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1554
1637
|
toolCalls,
|
|
1555
1638
|
text,
|
|
1556
1639
|
systemMessages: currentSystemMessages,
|
|
1640
|
+
steps,
|
|
1557
1641
|
abort,
|
|
1558
1642
|
tracingContext: { currentSpan: processorSpan },
|
|
1559
1643
|
requestContext,
|
|
1560
1644
|
retryCount
|
|
1561
1645
|
});
|
|
1562
1646
|
const mutations = messageList.stopRecording();
|
|
1563
|
-
if (result instanceof
|
|
1647
|
+
if (result instanceof chunkEMLEZXTQ_cjs.MessageList) {
|
|
1564
1648
|
if (result !== messageList) {
|
|
1565
|
-
throw new
|
|
1649
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
1566
1650
|
category: "USER",
|
|
1567
1651
|
domain: "AGENT",
|
|
1568
1652
|
id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
|
|
@@ -1630,9 +1714,9 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1630
1714
|
processor,
|
|
1631
1715
|
stepNumber
|
|
1632
1716
|
}) {
|
|
1633
|
-
if (result instanceof
|
|
1717
|
+
if (result instanceof chunkEMLEZXTQ_cjs.MessageList) {
|
|
1634
1718
|
if (result !== messageList) {
|
|
1635
|
-
throw new
|
|
1719
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
1636
1720
|
category: "USER",
|
|
1637
1721
|
domain: "AGENT",
|
|
1638
1722
|
id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
|
|
@@ -1648,7 +1732,7 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1648
1732
|
};
|
|
1649
1733
|
} else if (result) {
|
|
1650
1734
|
if (result.messageList && result.messageList !== messageList) {
|
|
1651
|
-
throw new
|
|
1735
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
1652
1736
|
category: "USER",
|
|
1653
1737
|
domain: "AGENT",
|
|
1654
1738
|
id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
|
|
@@ -1656,7 +1740,7 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1656
1740
|
});
|
|
1657
1741
|
}
|
|
1658
1742
|
if (result.messages && result.messageList) {
|
|
1659
|
-
throw new
|
|
1743
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
1660
1744
|
category: "USER",
|
|
1661
1745
|
domain: "AGENT",
|
|
1662
1746
|
id: "PROCESSOR_RETURNED_MESSAGES_AND_MESSAGE_LIST",
|
|
@@ -1665,13 +1749,14 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
1665
1749
|
}
|
|
1666
1750
|
const { model: _model, ...rest } = result;
|
|
1667
1751
|
if (result.model) {
|
|
1668
|
-
const resolvedModel = await
|
|
1669
|
-
|
|
1670
|
-
|
|
1752
|
+
const resolvedModel = await chunkGXMJ5URG_cjs.resolveModelConfig(result.model);
|
|
1753
|
+
const isSupported = isSupportedLanguageModel(resolvedModel);
|
|
1754
|
+
if (!isSupported) {
|
|
1755
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
1671
1756
|
category: "USER",
|
|
1672
1757
|
domain: "AGENT",
|
|
1673
|
-
id: "
|
|
1674
|
-
text: `Processor ${processor.id} returned
|
|
1758
|
+
id: "PROCESSOR_RETURNED_UNSUPPORTED_MODEL",
|
|
1759
|
+
text: `Processor ${processor.id} returned an unsupported model version ${resolvedModel.specificationVersion} in step ${stepNumber}. Only ${supportedLanguageModelSpecifications.join(", ")} models are supported in processInputStep.`
|
|
1675
1760
|
});
|
|
1676
1761
|
}
|
|
1677
1762
|
return {
|
|
@@ -1867,13 +1952,11 @@ function convertFullStreamChunkToMastra(value, ctx) {
|
|
|
1867
1952
|
from: "AGENT" /* AGENT */,
|
|
1868
1953
|
payload: {
|
|
1869
1954
|
stepResult: {
|
|
1870
|
-
reason: value.finishReason
|
|
1955
|
+
reason: normalizeFinishReason(value.finishReason)
|
|
1871
1956
|
},
|
|
1872
1957
|
output: {
|
|
1873
|
-
usage
|
|
1874
|
-
|
|
1875
|
-
totalTokens: value?.usage?.totalTokens ?? (value.usage?.inputTokens ?? 0) + (value.usage?.outputTokens ?? 0)
|
|
1876
|
-
}
|
|
1958
|
+
// Normalize usage to handle both V2 (flat) and V3 (nested) formats
|
|
1959
|
+
usage: normalizeUsage(value.usage)
|
|
1877
1960
|
},
|
|
1878
1961
|
metadata: {
|
|
1879
1962
|
providerMetadata: value.providerMetadata
|
|
@@ -1925,6 +2008,7 @@ function convertMastraChunkToAISDKv5({
|
|
|
1925
2008
|
type: "finish",
|
|
1926
2009
|
// Cast needed: Mastra extends reason with 'tripwire' | 'retry' for processor scenarios
|
|
1927
2010
|
finishReason: chunk.payload.stepResult.reason,
|
|
2011
|
+
// Cast needed: Mastra's LanguageModelUsage has optional properties, V2 has required-but-nullable
|
|
1928
2012
|
totalUsage: chunk.payload.output.usage
|
|
1929
2013
|
};
|
|
1930
2014
|
}
|
|
@@ -1943,18 +2027,8 @@ function convertMastraChunkToAISDKv5({
|
|
|
1943
2027
|
};
|
|
1944
2028
|
case "reasoning-signature":
|
|
1945
2029
|
throw new Error('AISDKv5 chunk type "reasoning-signature" not supported');
|
|
1946
|
-
// return {
|
|
1947
|
-
// type: 'reasoning-signature' as const,
|
|
1948
|
-
// id: chunk.payload.id,
|
|
1949
|
-
// signature: chunk.payload.signature,
|
|
1950
|
-
// };
|
|
1951
2030
|
case "redacted-reasoning":
|
|
1952
2031
|
throw new Error('AISDKv5 chunk type "redacted-reasoning" not supported');
|
|
1953
|
-
// return {
|
|
1954
|
-
// type: 'redacted-reasoning',
|
|
1955
|
-
// id: chunk.payload.id,
|
|
1956
|
-
// data: chunk.payload.data,
|
|
1957
|
-
// };
|
|
1958
2032
|
case "reasoning-end":
|
|
1959
2033
|
return {
|
|
1960
2034
|
type: "reasoning-end",
|
|
@@ -1986,7 +2060,7 @@ function convertMastraChunkToAISDKv5({
|
|
|
1986
2060
|
if (mode === "generate") {
|
|
1987
2061
|
return {
|
|
1988
2062
|
type: "file",
|
|
1989
|
-
file: new
|
|
2063
|
+
file: new chunkEMLEZXTQ_cjs.DefaultGeneratedFile({
|
|
1990
2064
|
data: chunk.payload.data,
|
|
1991
2065
|
mediaType: chunk.payload.mimeType
|
|
1992
2066
|
})
|
|
@@ -1994,7 +2068,7 @@ function convertMastraChunkToAISDKv5({
|
|
|
1994
2068
|
}
|
|
1995
2069
|
return {
|
|
1996
2070
|
type: "file",
|
|
1997
|
-
file: new
|
|
2071
|
+
file: new chunkEMLEZXTQ_cjs.DefaultGeneratedFileWithType({
|
|
1998
2072
|
data: chunk.payload.data,
|
|
1999
2073
|
mediaType: chunk.payload.mimeType
|
|
2000
2074
|
})
|
|
@@ -2108,6 +2182,59 @@ function convertMastraChunkToAISDKv5({
|
|
|
2108
2182
|
return;
|
|
2109
2183
|
}
|
|
2110
2184
|
}
|
|
2185
|
+
function isV3Usage(usage) {
|
|
2186
|
+
if (!usage || typeof usage !== "object") return false;
|
|
2187
|
+
const u = usage;
|
|
2188
|
+
return typeof u.inputTokens === "object" && u.inputTokens !== null && "total" in u.inputTokens && typeof u.outputTokens === "object" && u.outputTokens !== null && "total" in u.outputTokens;
|
|
2189
|
+
}
|
|
2190
|
+
function normalizeUsage(usage) {
|
|
2191
|
+
if (!usage) {
|
|
2192
|
+
return {
|
|
2193
|
+
inputTokens: void 0,
|
|
2194
|
+
outputTokens: void 0,
|
|
2195
|
+
totalTokens: void 0,
|
|
2196
|
+
reasoningTokens: void 0,
|
|
2197
|
+
cachedInputTokens: void 0,
|
|
2198
|
+
raw: void 0
|
|
2199
|
+
};
|
|
2200
|
+
}
|
|
2201
|
+
if (isV3Usage(usage)) {
|
|
2202
|
+
const inputTokens = usage.inputTokens.total;
|
|
2203
|
+
const outputTokens = usage.outputTokens.total;
|
|
2204
|
+
return {
|
|
2205
|
+
inputTokens,
|
|
2206
|
+
outputTokens,
|
|
2207
|
+
totalTokens: (inputTokens ?? 0) + (outputTokens ?? 0),
|
|
2208
|
+
reasoningTokens: usage.outputTokens.reasoning,
|
|
2209
|
+
cachedInputTokens: usage.inputTokens.cacheRead,
|
|
2210
|
+
raw: usage
|
|
2211
|
+
};
|
|
2212
|
+
}
|
|
2213
|
+
const v2Usage = usage;
|
|
2214
|
+
return {
|
|
2215
|
+
inputTokens: v2Usage.inputTokens,
|
|
2216
|
+
outputTokens: v2Usage.outputTokens,
|
|
2217
|
+
totalTokens: v2Usage.totalTokens ?? (v2Usage.inputTokens ?? 0) + (v2Usage.outputTokens ?? 0),
|
|
2218
|
+
reasoningTokens: v2Usage.reasoningTokens,
|
|
2219
|
+
cachedInputTokens: v2Usage.cachedInputTokens,
|
|
2220
|
+
raw: usage
|
|
2221
|
+
};
|
|
2222
|
+
}
|
|
2223
|
+
function isV3FinishReason(finishReason) {
|
|
2224
|
+
return typeof finishReason === "object" && finishReason !== null && "unified" in finishReason;
|
|
2225
|
+
}
|
|
2226
|
+
function normalizeFinishReason(finishReason) {
|
|
2227
|
+
if (!finishReason) {
|
|
2228
|
+
return "other";
|
|
2229
|
+
}
|
|
2230
|
+
if (finishReason === "tripwire" || finishReason === "retry") {
|
|
2231
|
+
return finishReason;
|
|
2232
|
+
}
|
|
2233
|
+
if (isV3FinishReason(finishReason)) {
|
|
2234
|
+
return finishReason.unified;
|
|
2235
|
+
}
|
|
2236
|
+
return finishReason === "unknown" ? "other" : finishReason;
|
|
2237
|
+
}
|
|
2111
2238
|
|
|
2112
2239
|
// src/stream/aisdk/v5/output.ts
|
|
2113
2240
|
var AISDKV5OutputStream = class {
|
|
@@ -2549,7 +2676,7 @@ var BaseFormatHandler = class {
|
|
|
2549
2676
|
} else {
|
|
2550
2677
|
return {
|
|
2551
2678
|
success: false,
|
|
2552
|
-
error: new
|
|
2679
|
+
error: new chunk4U7ZLI36_cjs.MastraError(
|
|
2553
2680
|
{
|
|
2554
2681
|
domain: "AGENT" /* AGENT */,
|
|
2555
2682
|
category: "SYSTEM" /* SYSTEM */,
|
|
@@ -3003,7 +3130,11 @@ var MastraModelOutput = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
3003
3130
|
#warnings = [];
|
|
3004
3131
|
#finishReason = void 0;
|
|
3005
3132
|
#request = {};
|
|
3006
|
-
#usageCount = {
|
|
3133
|
+
#usageCount = {
|
|
3134
|
+
inputTokens: void 0,
|
|
3135
|
+
outputTokens: void 0,
|
|
3136
|
+
totalTokens: void 0
|
|
3137
|
+
};
|
|
3007
3138
|
#tripwire = void 0;
|
|
3008
3139
|
#delayedPromises = {
|
|
3009
3140
|
suspendPayload: new DelayedPromise(),
|
|
@@ -3350,23 +3481,25 @@ var MastraModelOutput = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
3350
3481
|
};
|
|
3351
3482
|
self.#finishReason = "other";
|
|
3352
3483
|
self.#streamFinished = true;
|
|
3353
|
-
self
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3484
|
+
self.resolvePromises({
|
|
3485
|
+
text: self.#bufferedText.join(""),
|
|
3486
|
+
finishReason: "other",
|
|
3487
|
+
object: void 0,
|
|
3488
|
+
usage: self.#usageCount,
|
|
3489
|
+
warnings: self.#warnings,
|
|
3490
|
+
providerMetadata: void 0,
|
|
3491
|
+
response: {},
|
|
3492
|
+
request: {},
|
|
3493
|
+
reasoning: [],
|
|
3494
|
+
reasoningText: void 0,
|
|
3495
|
+
sources: [],
|
|
3496
|
+
files: [],
|
|
3497
|
+
toolCalls: [],
|
|
3498
|
+
toolResults: [],
|
|
3499
|
+
steps: self.#bufferedSteps,
|
|
3500
|
+
totalUsage: self.#usageCount,
|
|
3501
|
+
content: []
|
|
3502
|
+
});
|
|
3370
3503
|
self.#emitChunk(chunk);
|
|
3371
3504
|
controller.enqueue(chunk);
|
|
3372
3505
|
self.#emitter.emit("finish");
|
|
@@ -3430,12 +3563,14 @@ var MastraModelOutput = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
3430
3563
|
);
|
|
3431
3564
|
const responseMessages = self.messageList.get.response.aiV4.core();
|
|
3432
3565
|
const lastResponseMessage = responseMessages[responseMessages.length - 1];
|
|
3433
|
-
const outputText = lastResponseMessage ?
|
|
3566
|
+
const outputText = lastResponseMessage ? chunkEMLEZXTQ_cjs.MessageList.coreContentToString(lastResponseMessage.content) : "";
|
|
3434
3567
|
if (lastStep && outputText && outputText !== originalText) {
|
|
3435
3568
|
lastStep.text = outputText;
|
|
3436
3569
|
}
|
|
3437
|
-
|
|
3438
|
-
|
|
3570
|
+
this.resolvePromises({
|
|
3571
|
+
text: outputText || originalText,
|
|
3572
|
+
finishReason: self.#finishReason
|
|
3573
|
+
});
|
|
3439
3574
|
if (chunk.payload.metadata) {
|
|
3440
3575
|
const { providerMetadata, request, ...otherMetadata } = chunk.payload.metadata;
|
|
3441
3576
|
response = {
|
|
@@ -3445,9 +3580,10 @@ var MastraModelOutput = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
3445
3580
|
};
|
|
3446
3581
|
}
|
|
3447
3582
|
} else if (!self.#options.isLLMExecutionStep) {
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3583
|
+
this.resolvePromises({
|
|
3584
|
+
text: self.#bufferedText.join(""),
|
|
3585
|
+
finishReason: self.#finishReason
|
|
3586
|
+
});
|
|
3451
3587
|
}
|
|
3452
3588
|
} catch (error2) {
|
|
3453
3589
|
if (error2 instanceof TripWire) {
|
|
@@ -3457,35 +3593,41 @@ var MastraModelOutput = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
3457
3593
|
metadata: error2.options?.metadata,
|
|
3458
3594
|
processorId: error2.processorId
|
|
3459
3595
|
};
|
|
3460
|
-
self
|
|
3461
|
-
|
|
3596
|
+
self.resolvePromises({
|
|
3597
|
+
finishReason: "other",
|
|
3598
|
+
text: ""
|
|
3599
|
+
});
|
|
3462
3600
|
} else {
|
|
3463
|
-
self.#error =
|
|
3601
|
+
self.#error = chunk4U7ZLI36_cjs.getErrorFromUnknown(error2, {
|
|
3464
3602
|
fallbackMessage: "Unknown error in stream"
|
|
3465
3603
|
});
|
|
3466
|
-
self
|
|
3467
|
-
|
|
3604
|
+
self.resolvePromises({
|
|
3605
|
+
finishReason: "error",
|
|
3606
|
+
text: ""
|
|
3607
|
+
});
|
|
3468
3608
|
}
|
|
3469
3609
|
if (self.#delayedPromises.object.status.type !== "resolved") {
|
|
3470
3610
|
self.#delayedPromises.object.resolve(void 0);
|
|
3471
3611
|
}
|
|
3472
3612
|
}
|
|
3473
|
-
self.#delayedPromises.usage.resolve(self.#usageCount);
|
|
3474
|
-
self.#delayedPromises.warnings.resolve(self.#warnings);
|
|
3475
|
-
self.#delayedPromises.providerMetadata.resolve(chunk.payload.metadata?.providerMetadata);
|
|
3476
|
-
self.#delayedPromises.response.resolve(response);
|
|
3477
|
-
self.#delayedPromises.request.resolve(self.#request || {});
|
|
3478
3613
|
const reasoningText = self.#bufferedReasoning.length > 0 ? self.#bufferedReasoning.map((reasoningPart) => reasoningPart.payload.text).join("") : void 0;
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3614
|
+
this.resolvePromises({
|
|
3615
|
+
usage: self.#usageCount,
|
|
3616
|
+
warnings: self.#warnings,
|
|
3617
|
+
providerMetadata: chunk.payload.metadata?.providerMetadata,
|
|
3618
|
+
response,
|
|
3619
|
+
request: self.#request || {},
|
|
3620
|
+
reasoningText,
|
|
3621
|
+
reasoning: Object.values(self.#bufferedReasoningDetails || {}),
|
|
3622
|
+
sources: self.#bufferedSources,
|
|
3623
|
+
files: self.#bufferedFiles,
|
|
3624
|
+
toolCalls: self.#toolCalls,
|
|
3625
|
+
toolResults: self.#toolResults,
|
|
3626
|
+
steps: self.#bufferedSteps,
|
|
3627
|
+
totalUsage: self.#getTotalUsage(),
|
|
3628
|
+
content: messageList.get.response.aiV5.stepContent(),
|
|
3629
|
+
suspendPayload: void 0
|
|
3630
|
+
});
|
|
3489
3631
|
const baseFinishStep = self.#bufferedSteps[self.#bufferedSteps.length - 1];
|
|
3490
3632
|
if (baseFinishStep) {
|
|
3491
3633
|
const onFinishPayload = {
|
|
@@ -3533,7 +3675,7 @@ var MastraModelOutput = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
3533
3675
|
}
|
|
3534
3676
|
break;
|
|
3535
3677
|
case "error":
|
|
3536
|
-
const error =
|
|
3678
|
+
const error = chunk4U7ZLI36_cjs.getErrorFromUnknown(chunk.payload.error, {
|
|
3537
3679
|
fallbackMessage: "Unknown error chunk in stream"
|
|
3538
3680
|
});
|
|
3539
3681
|
self.#error = error;
|
|
@@ -3553,6 +3695,28 @@ var MastraModelOutput = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
3553
3695
|
if (self.#delayedPromises.object.status.type === "pending") {
|
|
3554
3696
|
self.#delayedPromises.object.resolve(void 0);
|
|
3555
3697
|
}
|
|
3698
|
+
if (self.#status === "suspended") {
|
|
3699
|
+
const reasoningText = self.#bufferedReasoning.length > 0 ? self.#bufferedReasoning.map((reasoningPart) => reasoningPart.payload.text).join("") : void 0;
|
|
3700
|
+
self.resolvePromises({
|
|
3701
|
+
toolResults: self.#toolResults,
|
|
3702
|
+
toolCalls: self.#toolCalls,
|
|
3703
|
+
text: self.#bufferedText.join(""),
|
|
3704
|
+
reasoning: Object.values(self.#bufferedReasoningDetails || {}),
|
|
3705
|
+
reasoningText,
|
|
3706
|
+
sources: self.#bufferedSources,
|
|
3707
|
+
files: self.#bufferedFiles,
|
|
3708
|
+
steps: self.#bufferedSteps,
|
|
3709
|
+
usage: self.#usageCount,
|
|
3710
|
+
totalUsage: self.#getTotalUsage(),
|
|
3711
|
+
warnings: self.#warnings,
|
|
3712
|
+
finishReason: "other",
|
|
3713
|
+
content: self.messageList.get.response.aiV5.stepContent(),
|
|
3714
|
+
object: void 0,
|
|
3715
|
+
request: self.#request,
|
|
3716
|
+
response: {},
|
|
3717
|
+
providerMetadata: void 0
|
|
3718
|
+
});
|
|
3719
|
+
}
|
|
3556
3720
|
Object.entries(self.#delayedPromises).forEach(([key, promise]) => {
|
|
3557
3721
|
if (promise.status.type === "pending") {
|
|
3558
3722
|
promise.reject(new Error(`promise '${key}' was not resolved or rejected when stream finished`));
|
|
@@ -3576,6 +3740,23 @@ var MastraModelOutput = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
3576
3740
|
this.deserializeState(initialState);
|
|
3577
3741
|
}
|
|
3578
3742
|
}
|
|
3743
|
+
resolvePromise(key, value) {
|
|
3744
|
+
if (!(key in this.#delayedPromises)) {
|
|
3745
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
3746
|
+
id: "MASTRA_MODEL_OUTPUT_INVALID_PROMISE_KEY",
|
|
3747
|
+
domain: "LLM" /* LLM */,
|
|
3748
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
3749
|
+
text: `Attempted to resolve invalid promise key '${key}' with value '${typeof value === "object" ? JSON.stringify(value, null, 2) : value}'`
|
|
3750
|
+
});
|
|
3751
|
+
}
|
|
3752
|
+
this.#delayedPromises[key].resolve(value);
|
|
3753
|
+
}
|
|
3754
|
+
resolvePromises(data) {
|
|
3755
|
+
for (const keyString in data) {
|
|
3756
|
+
const key = keyString;
|
|
3757
|
+
this.resolvePromise(key, data[key]);
|
|
3758
|
+
}
|
|
3759
|
+
}
|
|
3579
3760
|
#getDelayedPromise(promise) {
|
|
3580
3761
|
if (!this.#consumptionStarted) {
|
|
3581
3762
|
void this.consumeStream();
|
|
@@ -4226,6 +4407,8 @@ var WorkflowRunOutput = class {
|
|
|
4226
4407
|
} else {
|
|
4227
4408
|
self.#status = "failed";
|
|
4228
4409
|
}
|
|
4410
|
+
} else if (chunk.type === "workflow-paused") {
|
|
4411
|
+
self.#status = "paused";
|
|
4229
4412
|
}
|
|
4230
4413
|
},
|
|
4231
4414
|
close() {
|
|
@@ -4361,6 +4544,8 @@ var WorkflowRunOutput = class {
|
|
|
4361
4544
|
} else {
|
|
4362
4545
|
self.#status = "failed";
|
|
4363
4546
|
}
|
|
4547
|
+
} else if (chunk.type === "workflow-paused") {
|
|
4548
|
+
self.#status = "paused";
|
|
4364
4549
|
}
|
|
4365
4550
|
},
|
|
4366
4551
|
close() {
|
|
@@ -4548,7 +4733,7 @@ var getModelOutputForTripwire = async ({
|
|
|
4548
4733
|
model: {
|
|
4549
4734
|
modelId: model.modelId,
|
|
4550
4735
|
provider: model.provider,
|
|
4551
|
-
version: model.specificationVersion
|
|
4736
|
+
version: model.specificationVersion
|
|
4552
4737
|
},
|
|
4553
4738
|
stream: tripwireStream,
|
|
4554
4739
|
messageList,
|
|
@@ -4619,11 +4804,6 @@ function runScorer({
|
|
|
4619
4804
|
};
|
|
4620
4805
|
chunkMR7ZWBL6_cjs.executeHook("onScorerRun" /* ON_SCORER_RUN */, payload);
|
|
4621
4806
|
}
|
|
4622
|
-
|
|
4623
|
-
// src/llm/model/is-v2-model.ts
|
|
4624
|
-
function isV2Model(model) {
|
|
4625
|
-
return model.specificationVersion === "v2";
|
|
4626
|
-
}
|
|
4627
4807
|
var EventEmitterPubSub = class extends chunk4D4KB75Y_cjs.PubSub {
|
|
4628
4808
|
emitter;
|
|
4629
4809
|
constructor(existingEmitter) {
|
|
@@ -4950,7 +5130,7 @@ async function validateStepInput({
|
|
|
4950
5130
|
if (!validatedInput.success) {
|
|
4951
5131
|
const errors = getZodErrors(validatedInput.error);
|
|
4952
5132
|
const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
|
|
4953
|
-
validationError = new
|
|
5133
|
+
validationError = new chunk4U7ZLI36_cjs.MastraError(
|
|
4954
5134
|
{
|
|
4955
5135
|
id: "WORKFLOW_STEP_INPUT_VALIDATION_FAILED",
|
|
4956
5136
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
@@ -4978,7 +5158,7 @@ async function validateStepResumeData({ resumeData, step }) {
|
|
|
4978
5158
|
if (!validatedResumeData.success) {
|
|
4979
5159
|
const errors = getZodErrors(validatedResumeData.error);
|
|
4980
5160
|
const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
|
|
4981
|
-
validationError = new
|
|
5161
|
+
validationError = new chunk4U7ZLI36_cjs.MastraError(
|
|
4982
5162
|
{
|
|
4983
5163
|
id: "WORKFLOW_STEP_RESUME_DATA_VALIDATION_FAILED",
|
|
4984
5164
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
@@ -5009,7 +5189,7 @@ async function validateStepSuspendData({
|
|
|
5009
5189
|
if (!validatedSuspendData.success) {
|
|
5010
5190
|
const errors = getZodErrors(validatedSuspendData.error);
|
|
5011
5191
|
const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
|
|
5012
|
-
validationError = new
|
|
5192
|
+
validationError = new chunk4U7ZLI36_cjs.MastraError(
|
|
5013
5193
|
{
|
|
5014
5194
|
id: "WORKFLOW_STEP_SUSPEND_DATA_VALIDATION_FAILED",
|
|
5015
5195
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
@@ -5090,7 +5270,7 @@ var getStepIds = (entry) => {
|
|
|
5090
5270
|
return [];
|
|
5091
5271
|
};
|
|
5092
5272
|
var createTimeTravelExecutionParams = (params) => {
|
|
5093
|
-
const { steps, inputData, resumeData, context, nestedStepsContext, snapshot, initialState, graph } = params;
|
|
5273
|
+
const { steps, inputData, resumeData, context, nestedStepsContext, snapshot, initialState, graph, perStep } = params;
|
|
5094
5274
|
const firstStepId = steps[0];
|
|
5095
5275
|
let executionPath = [];
|
|
5096
5276
|
const stepResults = {};
|
|
@@ -5157,11 +5337,12 @@ var createTimeTravelExecutionParams = (params) => {
|
|
|
5157
5337
|
suspendedAt: stepContext?.suspendedAt,
|
|
5158
5338
|
resumedAt: stepContext?.resumedAt
|
|
5159
5339
|
};
|
|
5160
|
-
|
|
5340
|
+
const execPathLengthToUse = perStep ? executionPath.length : currentExecPathLength;
|
|
5341
|
+
if (execPathLengthToUse > 0 && !steps?.includes(stepId) && !context?.[stepId] && (!snapshotContext[stepId] || snapshotContext[stepId] && snapshotContext[stepId].status !== "suspended")) {
|
|
5161
5342
|
result = void 0;
|
|
5162
5343
|
}
|
|
5163
5344
|
if (result) {
|
|
5164
|
-
const formattedResult =
|
|
5345
|
+
const formattedResult = chunkBC2VKOH4_cjs.removeUndefinedValues(result);
|
|
5165
5346
|
stepResults[stepId] = formattedResult;
|
|
5166
5347
|
}
|
|
5167
5348
|
});
|
|
@@ -5186,7 +5367,7 @@ function hydrateSerializedStepErrors(steps) {
|
|
|
5186
5367
|
if (steps) {
|
|
5187
5368
|
for (const step of Object.values(steps)) {
|
|
5188
5369
|
if (step.status === "failed" && "error" in step && step.error) {
|
|
5189
|
-
step.error =
|
|
5370
|
+
step.error = chunk4U7ZLI36_cjs.getErrorFromUnknown(step.error, { serializeStack: false });
|
|
5190
5371
|
}
|
|
5191
5372
|
}
|
|
5192
5373
|
}
|
|
@@ -5212,7 +5393,8 @@ async function executeParallel(engine, params) {
|
|
|
5212
5393
|
abortController,
|
|
5213
5394
|
requestContext,
|
|
5214
5395
|
outputWriter,
|
|
5215
|
-
disableScorers
|
|
5396
|
+
disableScorers,
|
|
5397
|
+
perStep
|
|
5216
5398
|
} = params;
|
|
5217
5399
|
const parallelSpan = tracingContext.currentSpan?.createChildSpan({
|
|
5218
5400
|
type: "workflow_parallel" /* WORKFLOW_PARALLEL */,
|
|
@@ -5234,7 +5416,7 @@ async function executeParallel(engine, params) {
|
|
|
5234
5416
|
makeStepRunning = timeTravel.steps[0] === step.step.id;
|
|
5235
5417
|
}
|
|
5236
5418
|
if (!makeStepRunning) {
|
|
5237
|
-
|
|
5419
|
+
break;
|
|
5238
5420
|
}
|
|
5239
5421
|
const startTime = resume?.steps[0] === step.step.id ? void 0 : Date.now();
|
|
5240
5422
|
const resumeTime = resume?.steps[0] === step.step.id ? Date.now() : void 0;
|
|
@@ -5246,6 +5428,9 @@ async function executeParallel(engine, params) {
|
|
|
5246
5428
|
...resumeTime ? { resumedAt: resumeTime } : {}
|
|
5247
5429
|
};
|
|
5248
5430
|
executionContext.activeStepsPath[step.step.id] = [...executionContext.executionPath, stepIndex];
|
|
5431
|
+
if (perStep) {
|
|
5432
|
+
break;
|
|
5433
|
+
}
|
|
5249
5434
|
}
|
|
5250
5435
|
if (timeTravel && timeTravel.executionPath.length > 0) {
|
|
5251
5436
|
timeTravel.executionPath.shift();
|
|
@@ -5257,6 +5442,9 @@ async function executeParallel(engine, params) {
|
|
|
5257
5442
|
if (currStepResult && currStepResult.status !== "running") {
|
|
5258
5443
|
return currStepResult;
|
|
5259
5444
|
}
|
|
5445
|
+
if (!currStepResult && (perStep || timeTravel)) {
|
|
5446
|
+
return {};
|
|
5447
|
+
}
|
|
5260
5448
|
const stepExecResult = await engine.executeStep({
|
|
5261
5449
|
workflowId,
|
|
5262
5450
|
runId,
|
|
@@ -5285,7 +5473,8 @@ async function executeParallel(engine, params) {
|
|
|
5285
5473
|
abortController,
|
|
5286
5474
|
requestContext,
|
|
5287
5475
|
outputWriter,
|
|
5288
|
-
disableScorers
|
|
5476
|
+
disableScorers,
|
|
5477
|
+
perStep
|
|
5289
5478
|
});
|
|
5290
5479
|
engine.applyMutableContext(executionContext, stepExecResult.mutableContext);
|
|
5291
5480
|
Object.assign(stepResults, stepExecResult.stepResults);
|
|
@@ -5346,7 +5535,8 @@ async function executeConditional(engine, params) {
|
|
|
5346
5535
|
abortController,
|
|
5347
5536
|
requestContext,
|
|
5348
5537
|
outputWriter,
|
|
5349
|
-
disableScorers
|
|
5538
|
+
disableScorers,
|
|
5539
|
+
perStep
|
|
5350
5540
|
} = params;
|
|
5351
5541
|
const conditionalSpan = tracingContext.currentSpan?.createChildSpan({
|
|
5352
5542
|
type: "workflow_conditional" /* WORKFLOW_CONDITIONAL */,
|
|
@@ -5419,8 +5609,8 @@ async function executeConditional(engine, params) {
|
|
|
5419
5609
|
});
|
|
5420
5610
|
return result;
|
|
5421
5611
|
} catch (e) {
|
|
5422
|
-
const errorInstance =
|
|
5423
|
-
const mastraError = new
|
|
5612
|
+
const errorInstance = chunk4U7ZLI36_cjs.getErrorFromUnknown(e, { serializeStack: false });
|
|
5613
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError(
|
|
5424
5614
|
{
|
|
5425
5615
|
id: "WORKFLOW_CONDITION_EVALUATION_FAILED",
|
|
5426
5616
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
@@ -5441,7 +5631,18 @@ async function executeConditional(engine, params) {
|
|
|
5441
5631
|
}
|
|
5442
5632
|
})
|
|
5443
5633
|
)).filter((index) => index !== null);
|
|
5444
|
-
|
|
5634
|
+
let stepsToRun = entry.steps.filter((_, index) => truthyIndexes.includes(index));
|
|
5635
|
+
if (perStep || timeTravel && timeTravel.executionPath.length > 0) {
|
|
5636
|
+
const possibleStepsToRun = stepsToRun.filter((s) => {
|
|
5637
|
+
const currStepResult = stepResults[s.step.id];
|
|
5638
|
+
if (timeTravel && timeTravel.executionPath.length > 0) {
|
|
5639
|
+
return timeTravel.steps[0] === s.step.id;
|
|
5640
|
+
}
|
|
5641
|
+
return !currStepResult;
|
|
5642
|
+
});
|
|
5643
|
+
const possibleStepToRun = possibleStepsToRun?.[0];
|
|
5644
|
+
stepsToRun = possibleStepToRun ? [possibleStepToRun] : stepsToRun;
|
|
5645
|
+
}
|
|
5445
5646
|
conditionalSpan?.update({
|
|
5446
5647
|
attributes: {
|
|
5447
5648
|
truthyIndexes,
|
|
@@ -5488,7 +5689,8 @@ async function executeConditional(engine, params) {
|
|
|
5488
5689
|
abortController,
|
|
5489
5690
|
requestContext,
|
|
5490
5691
|
outputWriter,
|
|
5491
|
-
disableScorers
|
|
5692
|
+
disableScorers,
|
|
5693
|
+
perStep
|
|
5492
5694
|
});
|
|
5493
5695
|
engine.applyMutableContext(executionContext, stepExecResult.mutableContext);
|
|
5494
5696
|
Object.assign(stepResults, stepExecResult.stepResults);
|
|
@@ -5550,7 +5752,8 @@ async function executeLoop(engine, params) {
|
|
|
5550
5752
|
requestContext,
|
|
5551
5753
|
outputWriter,
|
|
5552
5754
|
disableScorers,
|
|
5553
|
-
serializedStepGraph
|
|
5755
|
+
serializedStepGraph,
|
|
5756
|
+
perStep
|
|
5554
5757
|
} = params;
|
|
5555
5758
|
const { step, condition } = entry;
|
|
5556
5759
|
const loopSpan = tracingContext.currentSpan?.createChildSpan({
|
|
@@ -5591,7 +5794,8 @@ async function executeLoop(engine, params) {
|
|
|
5591
5794
|
outputWriter,
|
|
5592
5795
|
disableScorers,
|
|
5593
5796
|
serializedStepGraph,
|
|
5594
|
-
iterationCount: iteration + 1
|
|
5797
|
+
iterationCount: iteration + 1,
|
|
5798
|
+
perStep
|
|
5595
5799
|
});
|
|
5596
5800
|
engine.applyMutableContext(executionContext, stepExecResult.mutableContext);
|
|
5597
5801
|
Object.assign(stepResults, stepExecResult.stepResults);
|
|
@@ -5612,7 +5816,7 @@ async function executeLoop(engine, params) {
|
|
|
5612
5816
|
const evalSpan = loopSpan?.createChildSpan({
|
|
5613
5817
|
type: "workflow_conditional_eval" /* WORKFLOW_CONDITIONAL_EVAL */,
|
|
5614
5818
|
name: `condition: '${entry.loopType}'`,
|
|
5615
|
-
input:
|
|
5819
|
+
input: chunkBC2VKOH4_cjs.selectFields(result.output, ["stepResult", "output.text", "output.object", "messages"]),
|
|
5616
5820
|
attributes: {
|
|
5617
5821
|
conditionIndex: iteration
|
|
5618
5822
|
},
|
|
@@ -5691,7 +5895,8 @@ async function executeForeach(engine, params) {
|
|
|
5691
5895
|
requestContext,
|
|
5692
5896
|
outputWriter,
|
|
5693
5897
|
disableScorers,
|
|
5694
|
-
serializedStepGraph
|
|
5898
|
+
serializedStepGraph,
|
|
5899
|
+
perStep
|
|
5695
5900
|
} = params;
|
|
5696
5901
|
const { step, opts } = entry;
|
|
5697
5902
|
const results = [];
|
|
@@ -5768,7 +5973,8 @@ async function executeForeach(engine, params) {
|
|
|
5768
5973
|
skipEmits: true,
|
|
5769
5974
|
outputWriter,
|
|
5770
5975
|
disableScorers,
|
|
5771
|
-
serializedStepGraph
|
|
5976
|
+
serializedStepGraph,
|
|
5977
|
+
perStep
|
|
5772
5978
|
});
|
|
5773
5979
|
engine.applyMutableContext(executionContext, stepExecResult.mutableContext);
|
|
5774
5980
|
Object.assign(stepResults, stepExecResult.stepResults);
|
|
@@ -5910,7 +6116,8 @@ async function persistStepUpdate(engine, params) {
|
|
|
5910
6116
|
requestContext.forEach((value, key) => {
|
|
5911
6117
|
requestContextObj[key] = value;
|
|
5912
6118
|
});
|
|
5913
|
-
await engine.mastra?.getStorage()?.
|
|
6119
|
+
const workflowsStore = await engine.mastra?.getStorage()?.getStore("workflows");
|
|
6120
|
+
await workflowsStore?.persistWorkflowSnapshot({
|
|
5914
6121
|
workflowName: workflowId,
|
|
5915
6122
|
runId,
|
|
5916
6123
|
resourceId,
|
|
@@ -5952,7 +6159,8 @@ async function executeEntry(engine, params) {
|
|
|
5952
6159
|
abortController,
|
|
5953
6160
|
requestContext,
|
|
5954
6161
|
outputWriter,
|
|
5955
|
-
disableScorers
|
|
6162
|
+
disableScorers,
|
|
6163
|
+
perStep
|
|
5956
6164
|
} = params;
|
|
5957
6165
|
const prevOutput = engine.getStepOutput(stepResults, prevStep);
|
|
5958
6166
|
let execResults;
|
|
@@ -5976,7 +6184,8 @@ async function executeEntry(engine, params) {
|
|
|
5976
6184
|
requestContext,
|
|
5977
6185
|
outputWriter,
|
|
5978
6186
|
disableScorers,
|
|
5979
|
-
serializedStepGraph
|
|
6187
|
+
serializedStepGraph,
|
|
6188
|
+
perStep
|
|
5980
6189
|
});
|
|
5981
6190
|
execResults = stepExecResult.result;
|
|
5982
6191
|
engine.applyMutableContext(executionContext, stepExecResult.mutableContext);
|
|
@@ -6008,7 +6217,8 @@ async function executeEntry(engine, params) {
|
|
|
6008
6217
|
abortController,
|
|
6009
6218
|
requestContext,
|
|
6010
6219
|
outputWriter,
|
|
6011
|
-
disableScorers
|
|
6220
|
+
disableScorers,
|
|
6221
|
+
perStep
|
|
6012
6222
|
});
|
|
6013
6223
|
engine.applyMutableContext(executionContext, resumedStepResult.mutableContext);
|
|
6014
6224
|
Object.assign(stepResults, resumedStepResult.stepResults);
|
|
@@ -6078,7 +6288,8 @@ async function executeEntry(engine, params) {
|
|
|
6078
6288
|
abortController,
|
|
6079
6289
|
requestContext,
|
|
6080
6290
|
outputWriter,
|
|
6081
|
-
disableScorers
|
|
6291
|
+
disableScorers,
|
|
6292
|
+
perStep
|
|
6082
6293
|
});
|
|
6083
6294
|
} else if (entry.type === "conditional") {
|
|
6084
6295
|
execResults = await engine.executeConditional({
|
|
@@ -6097,7 +6308,8 @@ async function executeEntry(engine, params) {
|
|
|
6097
6308
|
abortController,
|
|
6098
6309
|
requestContext,
|
|
6099
6310
|
outputWriter,
|
|
6100
|
-
disableScorers
|
|
6311
|
+
disableScorers,
|
|
6312
|
+
perStep
|
|
6101
6313
|
});
|
|
6102
6314
|
} else if (entry.type === "loop") {
|
|
6103
6315
|
execResults = await engine.executeLoop({
|
|
@@ -6117,7 +6329,8 @@ async function executeEntry(engine, params) {
|
|
|
6117
6329
|
requestContext,
|
|
6118
6330
|
outputWriter,
|
|
6119
6331
|
disableScorers,
|
|
6120
|
-
serializedStepGraph
|
|
6332
|
+
serializedStepGraph,
|
|
6333
|
+
perStep
|
|
6121
6334
|
});
|
|
6122
6335
|
} else if (entry.type === "foreach") {
|
|
6123
6336
|
execResults = await engine.executeForeach({
|
|
@@ -6137,7 +6350,8 @@ async function executeEntry(engine, params) {
|
|
|
6137
6350
|
requestContext,
|
|
6138
6351
|
outputWriter,
|
|
6139
6352
|
disableScorers,
|
|
6140
|
-
serializedStepGraph
|
|
6353
|
+
serializedStepGraph,
|
|
6354
|
+
perStep
|
|
6141
6355
|
});
|
|
6142
6356
|
} else if (entry.type === "sleep") {
|
|
6143
6357
|
const startedAt = Date.now();
|
|
@@ -6549,7 +6763,8 @@ async function executeStep(engine, params) {
|
|
|
6549
6763
|
disableScorers,
|
|
6550
6764
|
serializedStepGraph,
|
|
6551
6765
|
tracingContext,
|
|
6552
|
-
iterationCount
|
|
6766
|
+
iterationCount,
|
|
6767
|
+
perStep
|
|
6553
6768
|
} = params;
|
|
6554
6769
|
const stepCallId = crypto2.randomUUID();
|
|
6555
6770
|
const { inputData, validationError } = await validateStepInput({
|
|
@@ -6591,10 +6806,9 @@ async function executeStep(engine, params) {
|
|
|
6591
6806
|
const stepSpan = tracingContext.currentSpan?.createChildSpan({
|
|
6592
6807
|
name: `workflow step: '${step.id}'`,
|
|
6593
6808
|
type: "workflow_step" /* WORKFLOW_STEP */,
|
|
6809
|
+
entityType: "workflow_step" /* WORKFLOW_STEP */,
|
|
6810
|
+
entityId: step.id,
|
|
6594
6811
|
input: inputData,
|
|
6595
|
-
attributes: {
|
|
6596
|
-
stepId: step.id
|
|
6597
|
-
},
|
|
6598
6812
|
tracingPolicy: engine.options?.tracingPolicy
|
|
6599
6813
|
});
|
|
6600
6814
|
const operationId = `workflow.${workflowId}.run.${runId}.step.${step.id}.running_ev`;
|
|
@@ -6636,7 +6850,8 @@ async function executeStep(engine, params) {
|
|
|
6636
6850
|
requestContext,
|
|
6637
6851
|
tracingContext,
|
|
6638
6852
|
outputWriter,
|
|
6639
|
-
stepSpan
|
|
6853
|
+
stepSpan,
|
|
6854
|
+
perStep
|
|
6640
6855
|
});
|
|
6641
6856
|
if (workflowResult !== null) {
|
|
6642
6857
|
const stepResult2 = { ...stepInfo, ...workflowResult };
|
|
@@ -6682,7 +6897,7 @@ async function executeStep(engine, params) {
|
|
|
6682
6897
|
runId,
|
|
6683
6898
|
resourceId,
|
|
6684
6899
|
workflowId,
|
|
6685
|
-
mastra: engine.mastra ?
|
|
6900
|
+
mastra: engine.mastra ? chunkO2CAMK4A_cjs.wrapMastra(engine.mastra, { currentSpan: stepSpan }) : void 0,
|
|
6686
6901
|
requestContext,
|
|
6687
6902
|
inputData,
|
|
6688
6903
|
state: executionContext.state,
|
|
@@ -6768,12 +6983,15 @@ async function executeStep(engine, params) {
|
|
|
6768
6983
|
outputWriter,
|
|
6769
6984
|
// Disable scorers must be explicitly set to false they are on by default
|
|
6770
6985
|
scorers: disableScorers === false ? void 0 : step.scorers,
|
|
6771
|
-
validateInputs: engine.options?.validateInputs
|
|
6986
|
+
validateInputs: engine.options?.validateInputs,
|
|
6987
|
+
perStep
|
|
6772
6988
|
});
|
|
6773
6989
|
if (engine.requiresDurableContextSerialization()) {
|
|
6774
6990
|
contextMutations.requestContextUpdate = engine.serializeRequestContext(requestContext);
|
|
6775
6991
|
}
|
|
6776
|
-
|
|
6992
|
+
const isNestedWorkflowStep = step.component === "WORKFLOW";
|
|
6993
|
+
const nestedWflowStepPaused = isNestedWorkflowStep && perStep;
|
|
6994
|
+
return { output, suspended, bailed, contextMutations, nestedWflowStepPaused };
|
|
6777
6995
|
},
|
|
6778
6996
|
{ retries, delay: delay2, stepSpan, workflowId, runId }
|
|
6779
6997
|
);
|
|
@@ -6812,6 +7030,8 @@ async function executeStep(engine, params) {
|
|
|
6812
7030
|
};
|
|
6813
7031
|
} else if (durableResult.bailed) {
|
|
6814
7032
|
execResults = { status: "bailed", output: durableResult.bailed.payload, endedAt: Date.now() };
|
|
7033
|
+
} else if (durableResult.nestedWflowStepPaused) {
|
|
7034
|
+
execResults = { status: "paused" };
|
|
6815
7035
|
} else {
|
|
6816
7036
|
execResults = { status: "success", output: durableResult.output, endedAt: Date.now() };
|
|
6817
7037
|
}
|
|
@@ -6857,8 +7077,8 @@ async function runScorersForStep(params) {
|
|
|
6857
7077
|
requestContext
|
|
6858
7078
|
});
|
|
6859
7079
|
} catch (e) {
|
|
6860
|
-
const errorInstance =
|
|
6861
|
-
const mastraError = new
|
|
7080
|
+
const errorInstance = chunk4U7ZLI36_cjs.getErrorFromUnknown(e, { serializeStack: false });
|
|
7081
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError(
|
|
6862
7082
|
{
|
|
6863
7083
|
id: "WORKFLOW_FAILED_TO_FETCH_SCORERS",
|
|
6864
7084
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
@@ -7076,11 +7296,11 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7076
7296
|
return { ok: true, result };
|
|
7077
7297
|
} catch (e) {
|
|
7078
7298
|
if (i === params.retries) {
|
|
7079
|
-
const errorInstance =
|
|
7299
|
+
const errorInstance = chunk4U7ZLI36_cjs.getErrorFromUnknown(e, {
|
|
7080
7300
|
serializeStack: false,
|
|
7081
7301
|
fallbackMessage: "Unknown step execution error"
|
|
7082
7302
|
});
|
|
7083
|
-
const mastraError = new
|
|
7303
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError(
|
|
7084
7304
|
{
|
|
7085
7305
|
id: "WORKFLOW_STEP_INVOKE_FAILED",
|
|
7086
7306
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
@@ -7122,7 +7342,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7122
7342
|
formatResultError(error, lastOutput) {
|
|
7123
7343
|
const outputError = lastOutput?.error;
|
|
7124
7344
|
const errorSource = error || outputError;
|
|
7125
|
-
const errorInstance =
|
|
7345
|
+
const errorInstance = chunk4U7ZLI36_cjs.getErrorFromUnknown(errorSource, {
|
|
7126
7346
|
serializeStack: false,
|
|
7127
7347
|
fallbackMessage: "Unknown workflow error"
|
|
7128
7348
|
});
|
|
@@ -7235,13 +7455,14 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7235
7455
|
workflowSpan,
|
|
7236
7456
|
disableScorers,
|
|
7237
7457
|
restart,
|
|
7238
|
-
timeTravel
|
|
7458
|
+
timeTravel,
|
|
7459
|
+
perStep
|
|
7239
7460
|
} = params;
|
|
7240
7461
|
const { attempts = 0, delay: delay2 = 0 } = retryConfig ?? {};
|
|
7241
7462
|
const steps = graph.steps;
|
|
7242
7463
|
this.retryCounts.clear();
|
|
7243
7464
|
if (steps.length === 0) {
|
|
7244
|
-
const empty_graph_error = new
|
|
7465
|
+
const empty_graph_error = new chunk4U7ZLI36_cjs.MastraError({
|
|
7245
7466
|
id: "WORKFLOW_EXECUTE_EMPTY_GRAPH",
|
|
7246
7467
|
text: "Workflow must have at least one step",
|
|
7247
7468
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
@@ -7299,7 +7520,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7299
7520
|
pubsub: params.pubsub,
|
|
7300
7521
|
requestContext: currentRequestContext,
|
|
7301
7522
|
outputWriter: params.outputWriter,
|
|
7302
|
-
disableScorers
|
|
7523
|
+
disableScorers,
|
|
7524
|
+
perStep
|
|
7303
7525
|
});
|
|
7304
7526
|
this.applyMutableContext(executionContext, lastOutput.mutableContext);
|
|
7305
7527
|
lastState = lastOutput.mutableContext.state;
|
|
@@ -7338,13 +7560,47 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
7338
7560
|
}
|
|
7339
7561
|
});
|
|
7340
7562
|
}
|
|
7341
|
-
|
|
7563
|
+
if (lastOutput.result.status !== "paused") {
|
|
7564
|
+
await this.invokeLifecycleCallbacks(result2);
|
|
7565
|
+
}
|
|
7566
|
+
if (lastOutput.result.status === "paused") {
|
|
7567
|
+
await params.pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
7568
|
+
type: "watch",
|
|
7569
|
+
runId,
|
|
7570
|
+
data: { type: "workflow-paused", payload: {} }
|
|
7571
|
+
});
|
|
7572
|
+
}
|
|
7342
7573
|
return {
|
|
7343
7574
|
...result2,
|
|
7344
7575
|
...lastOutput.result.status === "suspended" && params.outputOptions?.includeResumeLabels ? { resumeLabels: lastOutput.mutableContext.resumeLabels } : {},
|
|
7345
7576
|
...params.outputOptions?.includeState ? { state: lastState } : {}
|
|
7346
7577
|
};
|
|
7347
7578
|
}
|
|
7579
|
+
if (perStep) {
|
|
7580
|
+
const result2 = await this.fmtReturnValue(params.pubsub, stepResults, lastOutput.result);
|
|
7581
|
+
await this.persistStepUpdate({
|
|
7582
|
+
workflowId,
|
|
7583
|
+
runId,
|
|
7584
|
+
resourceId,
|
|
7585
|
+
stepResults: lastOutput.stepResults,
|
|
7586
|
+
serializedStepGraph: params.serializedStepGraph,
|
|
7587
|
+
executionContext: lastExecutionContext,
|
|
7588
|
+
workflowStatus: "paused",
|
|
7589
|
+
requestContext: currentRequestContext
|
|
7590
|
+
});
|
|
7591
|
+
await params.pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
7592
|
+
type: "watch",
|
|
7593
|
+
runId,
|
|
7594
|
+
data: { type: "workflow-paused", payload: {} }
|
|
7595
|
+
});
|
|
7596
|
+
workflowSpan?.end({
|
|
7597
|
+
attributes: {
|
|
7598
|
+
status: "paused"
|
|
7599
|
+
}
|
|
7600
|
+
});
|
|
7601
|
+
delete result2.result;
|
|
7602
|
+
return { ...result2, status: "paused", ...params.outputOptions?.includeState ? { state: lastState } : {} };
|
|
7603
|
+
}
|
|
7348
7604
|
}
|
|
7349
7605
|
const result = await this.fmtReturnValue(params.pubsub, stepResults, lastOutput.result);
|
|
7350
7606
|
await this.persistStepUpdate({
|
|
@@ -7553,7 +7809,7 @@ function createStep(params, agentOptions) {
|
|
|
7553
7809
|
component: params.component
|
|
7554
7810
|
};
|
|
7555
7811
|
}
|
|
7556
|
-
if (params instanceof
|
|
7812
|
+
if (params instanceof chunk6HJFCSJ4_cjs.Tool) {
|
|
7557
7813
|
if (!params.inputSchema || !params.outputSchema) {
|
|
7558
7814
|
throw new Error("Tool must have input and output schemas defined");
|
|
7559
7815
|
}
|
|
@@ -7647,7 +7903,7 @@ function createStep(params, agentOptions) {
|
|
|
7647
7903
|
phase,
|
|
7648
7904
|
// Auto-create MessageList from messages if not provided
|
|
7649
7905
|
// This enables running processor workflows from the UI where messageList can't be serialized
|
|
7650
|
-
messageList: messageList ?? (Array.isArray(messages) ? new
|
|
7906
|
+
messageList: messageList ?? (Array.isArray(messages) ? new chunkEMLEZXTQ_cjs.MessageList().add(messages, "input").addSystem(systemMessages ?? []) : void 0),
|
|
7651
7907
|
stepNumber,
|
|
7652
7908
|
systemMessages,
|
|
7653
7909
|
streamParts,
|
|
@@ -7670,7 +7926,7 @@ function createStep(params, agentOptions) {
|
|
|
7670
7926
|
case "input": {
|
|
7671
7927
|
if (processor.processInput) {
|
|
7672
7928
|
if (!passThrough.messageList) {
|
|
7673
|
-
throw new
|
|
7929
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
7674
7930
|
category: "USER" /* USER */,
|
|
7675
7931
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
7676
7932
|
id: "PROCESSOR_MISSING_MESSAGE_LIST",
|
|
@@ -7700,9 +7956,9 @@ function createStep(params, agentOptions) {
|
|
|
7700
7956
|
}
|
|
7701
7957
|
}
|
|
7702
7958
|
};
|
|
7703
|
-
if (result instanceof
|
|
7959
|
+
if (result instanceof chunkEMLEZXTQ_cjs.MessageList) {
|
|
7704
7960
|
if (result !== passThrough.messageList) {
|
|
7705
|
-
throw new
|
|
7961
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
7706
7962
|
category: "USER" /* USER */,
|
|
7707
7963
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
7708
7964
|
id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
|
|
@@ -7734,7 +7990,7 @@ function createStep(params, agentOptions) {
|
|
|
7734
7990
|
case "inputStep": {
|
|
7735
7991
|
if (processor.processInputStep) {
|
|
7736
7992
|
if (!passThrough.messageList) {
|
|
7737
|
-
throw new
|
|
7993
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
7738
7994
|
category: "USER" /* USER */,
|
|
7739
7995
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
7740
7996
|
id: "PROCESSOR_MISSING_MESSAGE_LIST",
|
|
@@ -7796,7 +8052,7 @@ function createStep(params, agentOptions) {
|
|
|
7796
8052
|
case "outputResult": {
|
|
7797
8053
|
if (processor.processOutputResult) {
|
|
7798
8054
|
if (!passThrough.messageList) {
|
|
7799
|
-
throw new
|
|
8055
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
7800
8056
|
category: "USER" /* USER */,
|
|
7801
8057
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
7802
8058
|
id: "PROCESSOR_MISSING_MESSAGE_LIST",
|
|
@@ -7825,9 +8081,9 @@ function createStep(params, agentOptions) {
|
|
|
7825
8081
|
}
|
|
7826
8082
|
}
|
|
7827
8083
|
};
|
|
7828
|
-
if (result instanceof
|
|
8084
|
+
if (result instanceof chunkEMLEZXTQ_cjs.MessageList) {
|
|
7829
8085
|
if (result !== passThrough.messageList) {
|
|
7830
|
-
throw new
|
|
8086
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
7831
8087
|
category: "USER" /* USER */,
|
|
7832
8088
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
7833
8089
|
id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
|
|
@@ -7859,7 +8115,7 @@ function createStep(params, agentOptions) {
|
|
|
7859
8115
|
case "outputStep": {
|
|
7860
8116
|
if (processor.processOutputStep) {
|
|
7861
8117
|
if (!passThrough.messageList) {
|
|
7862
|
-
throw new
|
|
8118
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
7863
8119
|
category: "USER" /* USER */,
|
|
7864
8120
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
7865
8121
|
id: "PROCESSOR_MISSING_MESSAGE_LIST",
|
|
@@ -7876,7 +8132,8 @@ function createStep(params, agentOptions) {
|
|
|
7876
8132
|
finishReason,
|
|
7877
8133
|
toolCalls,
|
|
7878
8134
|
text,
|
|
7879
|
-
systemMessages: systemMessages ?? []
|
|
8135
|
+
systemMessages: systemMessages ?? [],
|
|
8136
|
+
steps: steps ?? []
|
|
7880
8137
|
});
|
|
7881
8138
|
const applyMessages = (msgs) => {
|
|
7882
8139
|
const deletedIds = idsBeforeProcessing.filter((i) => !msgs.some((m) => m.id === i));
|
|
@@ -7893,9 +8150,9 @@ function createStep(params, agentOptions) {
|
|
|
7893
8150
|
}
|
|
7894
8151
|
}
|
|
7895
8152
|
};
|
|
7896
|
-
if (result instanceof
|
|
8153
|
+
if (result instanceof chunkEMLEZXTQ_cjs.MessageList) {
|
|
7897
8154
|
if (result !== passThrough.messageList) {
|
|
7898
|
-
throw new
|
|
8155
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
7899
8156
|
category: "USER" /* USER */,
|
|
7900
8157
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
7901
8158
|
id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
|
|
@@ -7960,7 +8217,7 @@ function cloneStep(step, opts) {
|
|
|
7960
8217
|
};
|
|
7961
8218
|
}
|
|
7962
8219
|
function isProcessor(obj) {
|
|
7963
|
-
return obj !== null && typeof obj === "object" && "id" in obj && typeof obj.id === "string" && !(obj instanceof Agent) && !(obj instanceof
|
|
8220
|
+
return obj !== null && typeof obj === "object" && "id" in obj && typeof obj.id === "string" && !(obj instanceof Agent) && !(obj instanceof chunk6HJFCSJ4_cjs.Tool) && (typeof obj.processInput === "function" || typeof obj.processInputStep === "function" || typeof obj.processOutputStream === "function" || typeof obj.processOutputResult === "function" || typeof obj.processOutputStep === "function");
|
|
7964
8221
|
}
|
|
7965
8222
|
function createWorkflow(params) {
|
|
7966
8223
|
return new Workflow(params);
|
|
@@ -8131,7 +8388,7 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
8131
8388
|
* @deprecated waitForEvent has been removed. Please use suspend/resume instead.
|
|
8132
8389
|
*/
|
|
8133
8390
|
waitForEvent(_event, _step, _opts) {
|
|
8134
|
-
throw new
|
|
8391
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
8135
8392
|
id: "WORKFLOW_WAIT_FOR_EVENT_REMOVED",
|
|
8136
8393
|
domain: "MASTRA_WORKFLOW" /* MASTRA_WORKFLOW */,
|
|
8137
8394
|
category: "USER" /* USER */,
|
|
@@ -8142,8 +8399,8 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
8142
8399
|
if (typeof mappingConfig === "function") {
|
|
8143
8400
|
const mappingStep2 = createStep({
|
|
8144
8401
|
id: stepOptions?.id || `mapping_${this.#mastra?.generateId() || crypto2.randomUUID()}`,
|
|
8145
|
-
inputSchema: z8.z.
|
|
8146
|
-
outputSchema: z8.z.
|
|
8402
|
+
inputSchema: z8.z.any(),
|
|
8403
|
+
outputSchema: z8.z.any(),
|
|
8147
8404
|
execute: mappingConfig
|
|
8148
8405
|
});
|
|
8149
8406
|
this.stepFlow.push({ type: "step", step: mappingStep2 });
|
|
@@ -8199,7 +8456,15 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
8199
8456
|
result[key] = requestContext.get(m.requestContextPath);
|
|
8200
8457
|
continue;
|
|
8201
8458
|
}
|
|
8202
|
-
const stepResult = m.initData ? getInitData() : getStepResult2(
|
|
8459
|
+
const stepResult = m.initData ? getInitData() : getStepResult2(
|
|
8460
|
+
Array.isArray(m.step) ? m.step.find((s) => {
|
|
8461
|
+
const result2 = getStepResult2(s);
|
|
8462
|
+
if (typeof result2 === "object" && result2 !== null) {
|
|
8463
|
+
return Object.keys(result2).length > 0;
|
|
8464
|
+
}
|
|
8465
|
+
return result2;
|
|
8466
|
+
}) : m.step
|
|
8467
|
+
);
|
|
8203
8468
|
if (m.path === ".") {
|
|
8204
8469
|
result[key] = stepResult;
|
|
8205
8470
|
continue;
|
|
@@ -8410,12 +8675,15 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
8410
8675
|
workflowStatus: run.workflowRunStatus,
|
|
8411
8676
|
stepResults: {}
|
|
8412
8677
|
});
|
|
8413
|
-
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse,
|
|
8678
|
+
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse, {
|
|
8679
|
+
withNestedWorkflows: false
|
|
8680
|
+
});
|
|
8414
8681
|
if (workflowSnapshotInStorage && workflowSnapshotInStorage.status) {
|
|
8415
8682
|
run.workflowRunStatus = workflowSnapshotInStorage.status;
|
|
8416
8683
|
}
|
|
8417
8684
|
if (!workflowSnapshotInStorage && shouldPersistSnapshot) {
|
|
8418
|
-
await this.mastra?.getStorage()?.
|
|
8685
|
+
const workflowsStore = await this.mastra?.getStorage()?.getStore("workflows");
|
|
8686
|
+
await workflowsStore?.persistWorkflowSnapshot({
|
|
8419
8687
|
workflowName: this.id,
|
|
8420
8688
|
runId: runIdToUse,
|
|
8421
8689
|
resourceId: options?.resourceId,
|
|
@@ -8480,7 +8748,8 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
8480
8748
|
retryCount,
|
|
8481
8749
|
tracingContext,
|
|
8482
8750
|
outputWriter,
|
|
8483
|
-
validateInputs
|
|
8751
|
+
validateInputs,
|
|
8752
|
+
perStep
|
|
8484
8753
|
}) {
|
|
8485
8754
|
this.__registerMastra(mastra);
|
|
8486
8755
|
const effectiveValidateInputs = validateInputs ?? this.#options.validateInputs ?? true;
|
|
@@ -8528,7 +8797,8 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
8528
8797
|
requestContext,
|
|
8529
8798
|
tracingContext,
|
|
8530
8799
|
outputWriter,
|
|
8531
|
-
outputOptions: { includeState: true, includeResumeLabels: true }
|
|
8800
|
+
outputOptions: { includeState: true, includeResumeLabels: true },
|
|
8801
|
+
perStep
|
|
8532
8802
|
});
|
|
8533
8803
|
} else if (restart) {
|
|
8534
8804
|
res = await run.restart({ requestContext, tracingContext, outputWriter });
|
|
@@ -8540,7 +8810,8 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
8540
8810
|
tracingContext,
|
|
8541
8811
|
outputWriter,
|
|
8542
8812
|
outputOptions: { includeState: true, includeResumeLabels: true },
|
|
8543
|
-
label: resume.label
|
|
8813
|
+
label: resume.label,
|
|
8814
|
+
perStep
|
|
8544
8815
|
});
|
|
8545
8816
|
} else {
|
|
8546
8817
|
res = await run.start({
|
|
@@ -8549,7 +8820,8 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
8549
8820
|
tracingContext,
|
|
8550
8821
|
outputWriter,
|
|
8551
8822
|
initialState: state,
|
|
8552
|
-
outputOptions: { includeState: true, includeResumeLabels: true }
|
|
8823
|
+
outputOptions: { includeState: true, includeResumeLabels: true },
|
|
8824
|
+
perStep
|
|
8553
8825
|
});
|
|
8554
8826
|
}
|
|
8555
8827
|
unwatch();
|
|
@@ -8585,7 +8857,12 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
8585
8857
|
this.logger.debug("Cannot get workflow runs. Mastra storage is not initialized");
|
|
8586
8858
|
return { runs: [], total: 0 };
|
|
8587
8859
|
}
|
|
8588
|
-
|
|
8860
|
+
const workflowsStore = await storage.getStore("workflows");
|
|
8861
|
+
if (!workflowsStore) {
|
|
8862
|
+
this.logger.debug("Cannot get workflow runs. Workflows storage domain is not available");
|
|
8863
|
+
return { runs: [], total: 0 };
|
|
8864
|
+
}
|
|
8865
|
+
return workflowsStore.listWorkflowRuns({ workflowName: this.id, ...args ?? {} });
|
|
8589
8866
|
}
|
|
8590
8867
|
async listActiveWorkflowRuns() {
|
|
8591
8868
|
const runningRuns = await this.listWorkflowRuns({ status: "running" });
|
|
@@ -8622,7 +8899,12 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
8622
8899
|
this.logger.debug("Cannot get workflow runs from storage. Mastra storage is not initialized");
|
|
8623
8900
|
return this.#runs.get(runId) ? { ...this.#runs.get(runId), workflowName: this.id } : null;
|
|
8624
8901
|
}
|
|
8625
|
-
const
|
|
8902
|
+
const workflowsStore = await storage.getStore("workflows");
|
|
8903
|
+
if (!workflowsStore) {
|
|
8904
|
+
this.logger.debug("Cannot get workflow runs. Workflows storage domain is not available");
|
|
8905
|
+
return this.#runs.get(runId) ? { ...this.#runs.get(runId), workflowName: this.id } : null;
|
|
8906
|
+
}
|
|
8907
|
+
const run = await workflowsStore.getWorkflowRunById({ runId, workflowName: this.id });
|
|
8626
8908
|
return run ?? (this.#runs.get(runId) ? { ...this.#runs.get(runId), workflowName: this.id } : null);
|
|
8627
8909
|
}
|
|
8628
8910
|
async deleteWorkflowRunById(runId) {
|
|
@@ -8631,7 +8913,12 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
8631
8913
|
this.logger.debug("Cannot delete workflow run by ID. Mastra storage is not initialized");
|
|
8632
8914
|
return;
|
|
8633
8915
|
}
|
|
8634
|
-
await storage.
|
|
8916
|
+
const workflowsStore = await storage.getStore("workflows");
|
|
8917
|
+
if (!workflowsStore) {
|
|
8918
|
+
this.logger.debug("Cannot delete workflow run. Workflows storage domain is not available");
|
|
8919
|
+
return;
|
|
8920
|
+
}
|
|
8921
|
+
await workflowsStore.deleteWorkflowRunById({ runId, workflowName: this.id });
|
|
8635
8922
|
this.#runs.delete(runId);
|
|
8636
8923
|
}
|
|
8637
8924
|
async getWorkflowRunSteps({ runId, workflowId }) {
|
|
@@ -8640,7 +8927,12 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
8640
8927
|
this.logger.debug("Cannot get workflow run steps. Mastra storage is not initialized");
|
|
8641
8928
|
return {};
|
|
8642
8929
|
}
|
|
8643
|
-
const
|
|
8930
|
+
const workflowsStore = await storage.getStore("workflows");
|
|
8931
|
+
if (!workflowsStore) {
|
|
8932
|
+
this.logger.debug("Cannot get workflow run steps. Workflows storage domain is not available");
|
|
8933
|
+
return {};
|
|
8934
|
+
}
|
|
8935
|
+
const run = await workflowsStore.getWorkflowRunById({ runId, workflowName: workflowId });
|
|
8644
8936
|
let snapshot = run?.snapshot;
|
|
8645
8937
|
if (!snapshot) {
|
|
8646
8938
|
return {};
|
|
@@ -8675,13 +8967,19 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
8675
8967
|
}
|
|
8676
8968
|
return finalSteps;
|
|
8677
8969
|
}
|
|
8678
|
-
async getWorkflowRunExecutionResult(runId,
|
|
8970
|
+
async getWorkflowRunExecutionResult(runId, options = {}) {
|
|
8971
|
+
const { withNestedWorkflows = true, fields } = options;
|
|
8679
8972
|
const storage = this.#mastra?.getStorage();
|
|
8680
8973
|
if (!storage) {
|
|
8681
8974
|
this.logger.debug("Cannot get workflow run execution result. Mastra storage is not initialized");
|
|
8682
8975
|
return null;
|
|
8683
8976
|
}
|
|
8684
|
-
const
|
|
8977
|
+
const workflowsStore = await storage.getStore("workflows");
|
|
8978
|
+
if (!workflowsStore) {
|
|
8979
|
+
this.logger.debug("Cannot get workflow run execution result. Workflows storage domain is not available");
|
|
8980
|
+
return null;
|
|
8981
|
+
}
|
|
8982
|
+
const run = await workflowsStore.getWorkflowRunById({ runId, workflowName: this.id });
|
|
8685
8983
|
let snapshot = run?.snapshot;
|
|
8686
8984
|
if (!snapshot) {
|
|
8687
8985
|
return null;
|
|
@@ -8694,15 +8992,51 @@ var Workflow = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
8694
8992
|
return null;
|
|
8695
8993
|
}
|
|
8696
8994
|
}
|
|
8697
|
-
const
|
|
8995
|
+
const snapshotState = snapshot;
|
|
8996
|
+
const defaultResult = {
|
|
8997
|
+
status: snapshotState.status,
|
|
8998
|
+
result: snapshotState.result,
|
|
8999
|
+
error: snapshotState.error,
|
|
9000
|
+
payload: snapshotState.context?.input,
|
|
9001
|
+
steps: null,
|
|
9002
|
+
// Will be populated below
|
|
9003
|
+
activeStepsPath: snapshotState.activeStepsPath,
|
|
9004
|
+
serializedStepGraph: snapshotState.serializedStepGraph
|
|
9005
|
+
};
|
|
9006
|
+
const allowedFields = new Set(Object.keys(defaultResult));
|
|
9007
|
+
if (fields && fields.length > 0) {
|
|
9008
|
+
const result = {};
|
|
9009
|
+
for (const field of fields) {
|
|
9010
|
+
if (!allowedFields.has(field)) {
|
|
9011
|
+
continue;
|
|
9012
|
+
}
|
|
9013
|
+
if (field === "steps") {
|
|
9014
|
+
let fullSteps2;
|
|
9015
|
+
if (withNestedWorkflows) {
|
|
9016
|
+
fullSteps2 = await this.getWorkflowRunSteps({ runId, workflowId: this.id });
|
|
9017
|
+
} else {
|
|
9018
|
+
const { input, ...stepsOnly } = snapshotState.context || {};
|
|
9019
|
+
fullSteps2 = stepsOnly;
|
|
9020
|
+
}
|
|
9021
|
+
result.steps = fullSteps2;
|
|
9022
|
+
} else if (field === "payload") {
|
|
9023
|
+
result.payload = snapshotState.context?.input;
|
|
9024
|
+
} else {
|
|
9025
|
+
result[field] = snapshotState[field];
|
|
9026
|
+
}
|
|
9027
|
+
}
|
|
9028
|
+
return result;
|
|
9029
|
+
}
|
|
9030
|
+
let fullSteps;
|
|
9031
|
+
if (withNestedWorkflows) {
|
|
9032
|
+
fullSteps = await this.getWorkflowRunSteps({ runId, workflowId: this.id });
|
|
9033
|
+
} else {
|
|
9034
|
+
const { input, ...stepsOnly } = snapshotState.context || {};
|
|
9035
|
+
fullSteps = stepsOnly;
|
|
9036
|
+
}
|
|
8698
9037
|
return {
|
|
8699
|
-
|
|
8700
|
-
|
|
8701
|
-
error: snapshot.error,
|
|
8702
|
-
payload: snapshot.context?.input,
|
|
8703
|
-
steps: fullSteps,
|
|
8704
|
-
activeStepsPath: snapshot.activeStepsPath,
|
|
8705
|
-
serializedStepGraph: snapshot.serializedStepGraph
|
|
9038
|
+
...defaultResult,
|
|
9039
|
+
steps: fullSteps
|
|
8706
9040
|
};
|
|
8707
9041
|
}
|
|
8708
9042
|
};
|
|
@@ -8804,7 +9138,8 @@ var Run = class {
|
|
|
8804
9138
|
this.abortController.abort();
|
|
8805
9139
|
this.workflowRunStatus = "canceled";
|
|
8806
9140
|
try {
|
|
8807
|
-
await this.mastra?.getStorage()?.
|
|
9141
|
+
const workflowsStore = await this.mastra?.getStorage()?.getStore("workflows");
|
|
9142
|
+
await workflowsStore?.updateWorkflowState({
|
|
8808
9143
|
workflowName: this.workflowId,
|
|
8809
9144
|
runId: this.runId,
|
|
8810
9145
|
opts: {
|
|
@@ -8882,15 +9217,15 @@ var Run = class {
|
|
|
8882
9217
|
tracingContext,
|
|
8883
9218
|
tracingOptions,
|
|
8884
9219
|
format,
|
|
8885
|
-
outputOptions
|
|
9220
|
+
outputOptions,
|
|
9221
|
+
perStep
|
|
8886
9222
|
}) {
|
|
8887
|
-
const workflowSpan =
|
|
9223
|
+
const workflowSpan = chunkO2CAMK4A_cjs.getOrCreateSpan({
|
|
8888
9224
|
type: "workflow_run" /* WORKFLOW_RUN */,
|
|
8889
9225
|
name: `workflow run: '${this.workflowId}'`,
|
|
9226
|
+
entityType: "workflow_run" /* WORKFLOW_RUN */,
|
|
9227
|
+
entityId: this.workflowId,
|
|
8890
9228
|
input: inputData,
|
|
8891
|
-
attributes: {
|
|
8892
|
-
workflowId: this.workflowId
|
|
8893
|
-
},
|
|
8894
9229
|
metadata: {
|
|
8895
9230
|
resourceId: this.resourceId,
|
|
8896
9231
|
runId: this.runId
|
|
@@ -8920,7 +9255,8 @@ var Run = class {
|
|
|
8920
9255
|
outputWriter,
|
|
8921
9256
|
workflowSpan,
|
|
8922
9257
|
format,
|
|
8923
|
-
outputOptions
|
|
9258
|
+
outputOptions,
|
|
9259
|
+
perStep
|
|
8924
9260
|
});
|
|
8925
9261
|
if (result.status !== "suspended") {
|
|
8926
9262
|
this.cleanup?.();
|
|
@@ -9087,9 +9423,10 @@ var Run = class {
|
|
|
9087
9423
|
}
|
|
9088
9424
|
async streamAsync({
|
|
9089
9425
|
inputData,
|
|
9090
|
-
requestContext
|
|
9426
|
+
requestContext,
|
|
9427
|
+
perStep
|
|
9091
9428
|
} = {}) {
|
|
9092
|
-
return this.stream({ inputData, requestContext });
|
|
9429
|
+
return this.stream({ inputData, requestContext, perStep });
|
|
9093
9430
|
}
|
|
9094
9431
|
/**
|
|
9095
9432
|
* Starts the workflow execution with the provided input as a stream
|
|
@@ -9103,7 +9440,8 @@ var Run = class {
|
|
|
9103
9440
|
tracingOptions,
|
|
9104
9441
|
closeOnSuspend = true,
|
|
9105
9442
|
initialState,
|
|
9106
|
-
outputOptions
|
|
9443
|
+
outputOptions,
|
|
9444
|
+
perStep
|
|
9107
9445
|
} = {}) {
|
|
9108
9446
|
if (this.closeStreamAction && this.streamOutput) {
|
|
9109
9447
|
return this.streamOutput;
|
|
@@ -9158,7 +9496,8 @@ var Run = class {
|
|
|
9158
9496
|
runId: self.runId,
|
|
9159
9497
|
data: chunk
|
|
9160
9498
|
});
|
|
9161
|
-
}
|
|
9499
|
+
},
|
|
9500
|
+
perStep
|
|
9162
9501
|
});
|
|
9163
9502
|
let executionResults;
|
|
9164
9503
|
try {
|
|
@@ -9200,7 +9539,8 @@ var Run = class {
|
|
|
9200
9539
|
requestContext,
|
|
9201
9540
|
tracingContext,
|
|
9202
9541
|
tracingOptions,
|
|
9203
|
-
outputOptions
|
|
9542
|
+
outputOptions,
|
|
9543
|
+
perStep
|
|
9204
9544
|
} = {}) {
|
|
9205
9545
|
return this.resumeStreamVNext({
|
|
9206
9546
|
resumeData,
|
|
@@ -9208,7 +9548,8 @@ var Run = class {
|
|
|
9208
9548
|
requestContext,
|
|
9209
9549
|
tracingContext,
|
|
9210
9550
|
tracingOptions,
|
|
9211
|
-
outputOptions
|
|
9551
|
+
outputOptions,
|
|
9552
|
+
perStep
|
|
9212
9553
|
});
|
|
9213
9554
|
}
|
|
9214
9555
|
/**
|
|
@@ -9223,7 +9564,8 @@ var Run = class {
|
|
|
9223
9564
|
tracingContext,
|
|
9224
9565
|
tracingOptions,
|
|
9225
9566
|
forEachIndex,
|
|
9226
|
-
outputOptions
|
|
9567
|
+
outputOptions,
|
|
9568
|
+
perStep
|
|
9227
9569
|
} = {}) {
|
|
9228
9570
|
this.closeStreamAction = async () => {
|
|
9229
9571
|
};
|
|
@@ -9273,7 +9615,8 @@ var Run = class {
|
|
|
9273
9615
|
},
|
|
9274
9616
|
isVNext: true,
|
|
9275
9617
|
forEachIndex,
|
|
9276
|
-
outputOptions
|
|
9618
|
+
outputOptions,
|
|
9619
|
+
perStep
|
|
9277
9620
|
});
|
|
9278
9621
|
self.executionResults = executionResultsPromise;
|
|
9279
9622
|
let executionResults;
|
|
@@ -9344,7 +9687,8 @@ var Run = class {
|
|
|
9344
9687
|
return this._restart(args);
|
|
9345
9688
|
}
|
|
9346
9689
|
async _resume(params) {
|
|
9347
|
-
const
|
|
9690
|
+
const workflowsStore = await this.#mastra?.getStorage()?.getStore("workflows");
|
|
9691
|
+
const snapshot = await workflowsStore?.loadWorkflowSnapshot({
|
|
9348
9692
|
workflowName: this.workflowId,
|
|
9349
9693
|
runId: this.runId
|
|
9350
9694
|
});
|
|
@@ -9416,13 +9760,12 @@ var Run = class {
|
|
|
9416
9760
|
requestContextToUse.set(key, value);
|
|
9417
9761
|
}
|
|
9418
9762
|
});
|
|
9419
|
-
const workflowSpan =
|
|
9763
|
+
const workflowSpan = chunkO2CAMK4A_cjs.getOrCreateSpan({
|
|
9420
9764
|
type: "workflow_run" /* WORKFLOW_RUN */,
|
|
9421
9765
|
name: `workflow run: '${this.workflowId}'`,
|
|
9766
|
+
entityType: "workflow_run" /* WORKFLOW_RUN */,
|
|
9767
|
+
entityId: this.workflowId,
|
|
9422
9768
|
input: resumeDataToUse,
|
|
9423
|
-
attributes: {
|
|
9424
|
-
workflowId: this.workflowId
|
|
9425
|
-
},
|
|
9426
9769
|
metadata: {
|
|
9427
9770
|
resourceId: this.resourceId,
|
|
9428
9771
|
runId: this.runId
|
|
@@ -9457,7 +9800,8 @@ var Run = class {
|
|
|
9457
9800
|
abortController: this.abortController,
|
|
9458
9801
|
workflowSpan,
|
|
9459
9802
|
outputOptions: params.outputOptions,
|
|
9460
|
-
outputWriter: params.outputWriter
|
|
9803
|
+
outputWriter: params.outputWriter,
|
|
9804
|
+
perStep: params.perStep
|
|
9461
9805
|
}).then((result) => {
|
|
9462
9806
|
if (!params.isVNext && result.status !== "suspended") {
|
|
9463
9807
|
this.closeStreamAction?.().catch(() => {
|
|
@@ -9481,7 +9825,8 @@ var Run = class {
|
|
|
9481
9825
|
if (this.workflowEngineType !== "default") {
|
|
9482
9826
|
throw new Error(`restart() is not supported on ${this.workflowEngineType} workflows`);
|
|
9483
9827
|
}
|
|
9484
|
-
const
|
|
9828
|
+
const workflowsStore = await this.#mastra?.getStorage()?.getStore("workflows");
|
|
9829
|
+
const snapshot = await workflowsStore?.loadWorkflowSnapshot({
|
|
9485
9830
|
workflowName: this.workflowId,
|
|
9486
9831
|
runId: this.runId
|
|
9487
9832
|
});
|
|
@@ -9527,12 +9872,11 @@ var Run = class {
|
|
|
9527
9872
|
requestContextToUse.set(key, value);
|
|
9528
9873
|
}
|
|
9529
9874
|
}
|
|
9530
|
-
const workflowSpan =
|
|
9875
|
+
const workflowSpan = chunkO2CAMK4A_cjs.getOrCreateSpan({
|
|
9531
9876
|
type: "workflow_run" /* WORKFLOW_RUN */,
|
|
9532
9877
|
name: `workflow run: '${this.workflowId}'`,
|
|
9533
|
-
|
|
9534
|
-
|
|
9535
|
-
},
|
|
9878
|
+
entityType: "workflow_run" /* WORKFLOW_RUN */,
|
|
9879
|
+
entityId: this.workflowId,
|
|
9536
9880
|
metadata: {
|
|
9537
9881
|
resourceId: this.resourceId,
|
|
9538
9882
|
runId: this.runId
|
|
@@ -9576,12 +9920,14 @@ var Run = class {
|
|
|
9576
9920
|
outputWriter,
|
|
9577
9921
|
tracingContext,
|
|
9578
9922
|
tracingOptions,
|
|
9579
|
-
outputOptions
|
|
9923
|
+
outputOptions,
|
|
9924
|
+
perStep
|
|
9580
9925
|
}) {
|
|
9581
9926
|
if (!stepParam || Array.isArray(stepParam) && stepParam.length === 0) {
|
|
9582
9927
|
throw new Error("Step is required and must be a valid step or array of steps");
|
|
9583
9928
|
}
|
|
9584
|
-
const
|
|
9929
|
+
const workflowsStore = await this.#mastra?.getStorage()?.getStore("workflows");
|
|
9930
|
+
const snapshot = await workflowsStore?.loadWorkflowSnapshot({
|
|
9585
9931
|
workflowName: this.workflowId,
|
|
9586
9932
|
runId: this.runId
|
|
9587
9933
|
});
|
|
@@ -9611,7 +9957,8 @@ var Run = class {
|
|
|
9611
9957
|
nestedStepsContext,
|
|
9612
9958
|
snapshot,
|
|
9613
9959
|
initialState,
|
|
9614
|
-
graph: this.executionGraph
|
|
9960
|
+
graph: this.executionGraph,
|
|
9961
|
+
perStep
|
|
9615
9962
|
});
|
|
9616
9963
|
const requestContextToUse = requestContext ?? new chunkUVHSM2GU_cjs.RequestContext();
|
|
9617
9964
|
for (const [key, value] of Object.entries(snapshot.requestContext ?? {})) {
|
|
@@ -9619,13 +9966,12 @@ var Run = class {
|
|
|
9619
9966
|
requestContextToUse.set(key, value);
|
|
9620
9967
|
}
|
|
9621
9968
|
}
|
|
9622
|
-
const workflowSpan =
|
|
9969
|
+
const workflowSpan = chunkO2CAMK4A_cjs.getOrCreateSpan({
|
|
9623
9970
|
type: "workflow_run" /* WORKFLOW_RUN */,
|
|
9624
9971
|
name: `workflow run: '${this.workflowId}'`,
|
|
9625
9972
|
input: inputData,
|
|
9626
|
-
|
|
9627
|
-
|
|
9628
|
-
},
|
|
9973
|
+
entityType: "workflow_run" /* WORKFLOW_RUN */,
|
|
9974
|
+
entityId: this.workflowId,
|
|
9629
9975
|
metadata: {
|
|
9630
9976
|
resourceId: this.resourceId,
|
|
9631
9977
|
runId: this.runId
|
|
@@ -9651,7 +9997,8 @@ var Run = class {
|
|
|
9651
9997
|
abortController: this.abortController,
|
|
9652
9998
|
outputWriter,
|
|
9653
9999
|
workflowSpan,
|
|
9654
|
-
outputOptions
|
|
10000
|
+
outputOptions,
|
|
10001
|
+
perStep
|
|
9655
10002
|
});
|
|
9656
10003
|
if (result.status !== "suspended") {
|
|
9657
10004
|
this.cleanup?.();
|
|
@@ -9672,7 +10019,8 @@ var Run = class {
|
|
|
9672
10019
|
requestContext,
|
|
9673
10020
|
tracingContext,
|
|
9674
10021
|
tracingOptions,
|
|
9675
|
-
outputOptions
|
|
10022
|
+
outputOptions,
|
|
10023
|
+
perStep
|
|
9676
10024
|
}) {
|
|
9677
10025
|
this.closeStreamAction = async () => {
|
|
9678
10026
|
};
|
|
@@ -9713,7 +10061,8 @@ var Run = class {
|
|
|
9713
10061
|
outputWriter: async (chunk) => {
|
|
9714
10062
|
void controller.enqueue(chunk);
|
|
9715
10063
|
},
|
|
9716
|
-
outputOptions
|
|
10064
|
+
outputOptions,
|
|
10065
|
+
perStep
|
|
9717
10066
|
});
|
|
9718
10067
|
self.executionResults = executionResultsPromise;
|
|
9719
10068
|
let executionResults;
|
|
@@ -9943,13 +10292,13 @@ function execute({
|
|
|
9943
10292
|
const responseFormat = structuredOutput?.schema ? getResponseFormat(structuredOutput?.schema) : void 0;
|
|
9944
10293
|
let prompt = inputMessages;
|
|
9945
10294
|
if (structuredOutputMode === "direct" && responseFormat?.type === "json" && structuredOutput?.jsonPromptInjection) {
|
|
9946
|
-
prompt =
|
|
10295
|
+
prompt = providerUtilsV5.injectJsonInstructionIntoMessages({
|
|
9947
10296
|
messages: inputMessages,
|
|
9948
10297
|
schema: responseFormat.schema
|
|
9949
10298
|
});
|
|
9950
10299
|
}
|
|
9951
10300
|
if (structuredOutputMode === "processor" && responseFormat?.type === "json" && responseFormat?.schema) {
|
|
9952
|
-
prompt =
|
|
10301
|
+
prompt = providerUtilsV5.injectJsonInstructionIntoMessages({
|
|
9953
10302
|
messages: inputMessages,
|
|
9954
10303
|
schema: responseFormat.schema,
|
|
9955
10304
|
schemaPrefix: `Your response will be processed by another agent to extract structured data. Please ensure your response contains comprehensive information for all the following fields that will be extracted:
|
|
@@ -10318,7 +10667,8 @@ async function processOutputStream({
|
|
|
10318
10667
|
messageList.add(message, "response");
|
|
10319
10668
|
runState.setState({
|
|
10320
10669
|
isReasoning: false,
|
|
10321
|
-
reasoningDeltas: []
|
|
10670
|
+
reasoningDeltas: [],
|
|
10671
|
+
providerOptions: void 0
|
|
10322
10672
|
});
|
|
10323
10673
|
if (isControllerOpen(controller)) {
|
|
10324
10674
|
controller.enqueue(chunk);
|
|
@@ -10390,7 +10740,7 @@ async function processOutputStream({
|
|
|
10390
10740
|
});
|
|
10391
10741
|
break;
|
|
10392
10742
|
case "error":
|
|
10393
|
-
if (
|
|
10743
|
+
if (providerUtilsV5.isAbortError(chunk.payload.error) && options?.abortSignal?.aborted) {
|
|
10394
10744
|
break;
|
|
10395
10745
|
}
|
|
10396
10746
|
runState.setState({
|
|
@@ -10402,7 +10752,7 @@ async function processOutputStream({
|
|
|
10402
10752
|
reason: "error"
|
|
10403
10753
|
}
|
|
10404
10754
|
});
|
|
10405
|
-
const error =
|
|
10755
|
+
const error = chunk4U7ZLI36_cjs.getErrorFromUnknown(chunk.payload.error, {
|
|
10406
10756
|
fallbackMessage: "Unknown error in agent stream"
|
|
10407
10757
|
});
|
|
10408
10758
|
controller.enqueue({ ...chunk, payload: { ...chunk.payload, error } });
|
|
@@ -10447,11 +10797,14 @@ function executeStreamWithFallbackModels(models) {
|
|
|
10447
10797
|
while (attempt <= maxRetries) {
|
|
10448
10798
|
try {
|
|
10449
10799
|
const isLastModel = attempt === maxRetries && index === models.length;
|
|
10450
|
-
const result = await callback(modelConfig
|
|
10800
|
+
const result = await callback(modelConfig, isLastModel);
|
|
10451
10801
|
finalResult = result;
|
|
10452
10802
|
done = true;
|
|
10453
10803
|
break;
|
|
10454
10804
|
} catch (err) {
|
|
10805
|
+
if (err instanceof TripWire) {
|
|
10806
|
+
throw err;
|
|
10807
|
+
}
|
|
10455
10808
|
attempt++;
|
|
10456
10809
|
console.error(`Error executing model ${modelConfig.model.modelId}, attempt ${attempt}====`, err);
|
|
10457
10810
|
if (attempt > maxRetries) {
|
|
@@ -10489,7 +10842,6 @@ function createLLMExecutionStep({
|
|
|
10489
10842
|
inputProcessors,
|
|
10490
10843
|
logger,
|
|
10491
10844
|
agentId,
|
|
10492
|
-
headers,
|
|
10493
10845
|
downloadRetries,
|
|
10494
10846
|
downloadConcurrency,
|
|
10495
10847
|
processorStates,
|
|
@@ -10509,7 +10861,9 @@ function createLLMExecutionStep({
|
|
|
10509
10861
|
let warnings;
|
|
10510
10862
|
let request;
|
|
10511
10863
|
let rawResponse;
|
|
10512
|
-
const { outputStream, callBail, runState, stepTools } = await executeStreamWithFallbackModels(models)(async (
|
|
10864
|
+
const { outputStream, callBail, runState, stepTools } = await executeStreamWithFallbackModels(models)(async (modelConfig, isLastModel) => {
|
|
10865
|
+
const model = modelConfig.model;
|
|
10866
|
+
const modelHeaders = modelConfig.headers;
|
|
10513
10867
|
if (initialSystemMessages) {
|
|
10514
10868
|
messageList.replaceAllSystemMessages(initialSystemMessages);
|
|
10515
10869
|
}
|
|
@@ -10554,6 +10908,45 @@ function createLLMExecutionStep({
|
|
|
10554
10908
|
});
|
|
10555
10909
|
Object.assign(currentStep, processInputStepResult);
|
|
10556
10910
|
} catch (error) {
|
|
10911
|
+
if (error instanceof TripWire) {
|
|
10912
|
+
if (isControllerOpen(controller)) {
|
|
10913
|
+
controller.enqueue({
|
|
10914
|
+
type: "tripwire",
|
|
10915
|
+
runId,
|
|
10916
|
+
from: "AGENT" /* AGENT */,
|
|
10917
|
+
payload: {
|
|
10918
|
+
reason: error.message,
|
|
10919
|
+
retry: error.options?.retry,
|
|
10920
|
+
metadata: error.options?.metadata,
|
|
10921
|
+
processorId: error.processorId
|
|
10922
|
+
}
|
|
10923
|
+
});
|
|
10924
|
+
}
|
|
10925
|
+
const runState3 = new AgenticRunState({
|
|
10926
|
+
_internal,
|
|
10927
|
+
model
|
|
10928
|
+
});
|
|
10929
|
+
return {
|
|
10930
|
+
callBail: true,
|
|
10931
|
+
outputStream: new MastraModelOutput({
|
|
10932
|
+
model: {
|
|
10933
|
+
modelId: model.modelId,
|
|
10934
|
+
provider: model.provider,
|
|
10935
|
+
version: model.specificationVersion
|
|
10936
|
+
},
|
|
10937
|
+
stream: new web.ReadableStream({
|
|
10938
|
+
start(c) {
|
|
10939
|
+
c.close();
|
|
10940
|
+
}
|
|
10941
|
+
}),
|
|
10942
|
+
messageList,
|
|
10943
|
+
messageId,
|
|
10944
|
+
options: { runId }
|
|
10945
|
+
}),
|
|
10946
|
+
runState: runState3,
|
|
10947
|
+
stepTools: tools
|
|
10948
|
+
};
|
|
10949
|
+
}
|
|
10557
10950
|
console.error("Error in processInputStep processors:", error);
|
|
10558
10951
|
throw error;
|
|
10559
10952
|
}
|
|
@@ -10587,62 +10980,63 @@ Analyse the suspended tools: ${JSON.stringify(suspendedTools)}, using the messag
|
|
|
10587
10980
|
resumeData can not be an empty object nor null/undefined.
|
|
10588
10981
|
When you find that and call that tool, add the resumeData to the tool call arguments/input.
|
|
10589
10982
|
Also, add the runId of the suspended tool as suspendedToolRunId to the tool call arguments/input.
|
|
10590
|
-
If the suspendedTool.type is 'approval', resumeData will be an object that contains 'approved' which can either be true or false depending on the user's message
|
|
10983
|
+
If the suspendedTool.type is 'approval', resumeData will be an object that contains 'approved' which can either be true or false depending on the user's message. If you can't construct resumeData from the message for approval type, set approved to true and add resumeData: { approved: true } to the tool call arguments/input.
|
|
10984
|
+
`;
|
|
10591
10985
|
}
|
|
10592
10986
|
return message;
|
|
10593
10987
|
});
|
|
10594
10988
|
}
|
|
10595
10989
|
}
|
|
10596
10990
|
}
|
|
10597
|
-
|
|
10598
|
-
|
|
10599
|
-
|
|
10600
|
-
|
|
10601
|
-
|
|
10602
|
-
|
|
10603
|
-
|
|
10604
|
-
|
|
10605
|
-
|
|
10606
|
-
|
|
10607
|
-
|
|
10608
|
-
|
|
10609
|
-
|
|
10610
|
-
|
|
10611
|
-
|
|
10612
|
-
|
|
10613
|
-
|
|
10614
|
-
|
|
10615
|
-
|
|
10616
|
-
|
|
10617
|
-
|
|
10618
|
-
|
|
10619
|
-
|
|
10620
|
-
|
|
10621
|
-
|
|
10622
|
-
|
|
10623
|
-
|
|
10624
|
-
|
|
10625
|
-
|
|
10991
|
+
if (isSupportedLanguageModel(currentStep.model)) {
|
|
10992
|
+
modelResult = chunkO2CAMK4A_cjs.executeWithContextSync({
|
|
10993
|
+
span: modelSpanTracker?.getTracingContext()?.currentSpan,
|
|
10994
|
+
fn: () => execute({
|
|
10995
|
+
runId,
|
|
10996
|
+
model: currentStep.model,
|
|
10997
|
+
providerOptions: currentStep.providerOptions,
|
|
10998
|
+
inputMessages,
|
|
10999
|
+
tools: currentStep.tools,
|
|
11000
|
+
toolChoice: currentStep.toolChoice,
|
|
11001
|
+
activeTools: currentStep.activeTools,
|
|
11002
|
+
options,
|
|
11003
|
+
modelSettings: currentStep.modelSettings,
|
|
11004
|
+
includeRawChunks,
|
|
11005
|
+
structuredOutput: currentStep.structuredOutput,
|
|
11006
|
+
// Merge headers: modelConfig headers first, then modelSettings overrides them
|
|
11007
|
+
// Only create object if there are actual headers to avoid passing empty {}
|
|
11008
|
+
headers: modelHeaders || currentStep.modelSettings?.headers ? { ...modelHeaders, ...currentStep.modelSettings?.headers } : void 0,
|
|
11009
|
+
methodType,
|
|
11010
|
+
generateId: _internal?.generateId,
|
|
11011
|
+
onResult: ({
|
|
11012
|
+
warnings: warningsFromStream,
|
|
11013
|
+
request: requestFromStream,
|
|
11014
|
+
rawResponse: rawResponseFromStream
|
|
11015
|
+
}) => {
|
|
11016
|
+
warnings = warningsFromStream;
|
|
11017
|
+
request = requestFromStream || {};
|
|
11018
|
+
rawResponse = rawResponseFromStream;
|
|
11019
|
+
if (!isControllerOpen(controller)) {
|
|
11020
|
+
return;
|
|
11021
|
+
}
|
|
11022
|
+
controller.enqueue({
|
|
11023
|
+
runId,
|
|
11024
|
+
from: "AGENT" /* AGENT */,
|
|
11025
|
+
type: "step-start",
|
|
11026
|
+
payload: {
|
|
11027
|
+
request: request || {},
|
|
11028
|
+
warnings: warnings || [],
|
|
11029
|
+
messageId
|
|
10626
11030
|
}
|
|
10627
|
-
|
|
10628
|
-
|
|
10629
|
-
|
|
10630
|
-
|
|
10631
|
-
|
|
10632
|
-
|
|
10633
|
-
|
|
10634
|
-
|
|
10635
|
-
|
|
10636
|
-
});
|
|
10637
|
-
},
|
|
10638
|
-
shouldThrowError: !isLastModel
|
|
10639
|
-
})
|
|
10640
|
-
});
|
|
10641
|
-
break;
|
|
10642
|
-
}
|
|
10643
|
-
default: {
|
|
10644
|
-
throw new Error(`Unsupported model version: ${model.specificationVersion}`);
|
|
10645
|
-
}
|
|
11031
|
+
});
|
|
11032
|
+
},
|
|
11033
|
+
shouldThrowError: !isLastModel
|
|
11034
|
+
})
|
|
11035
|
+
});
|
|
11036
|
+
} else {
|
|
11037
|
+
throw new Error(
|
|
11038
|
+
`Unsupported model version: ${currentStep.model.specificationVersion}. Supported versions: ${supportedLanguageModelSpecifications.join(", ")}`
|
|
11039
|
+
);
|
|
10646
11040
|
}
|
|
10647
11041
|
const outputStream2 = new MastraModelOutput({
|
|
10648
11042
|
model: {
|
|
@@ -10683,7 +11077,7 @@ Analyse the suspended tools: ${JSON.stringify(suspendedTools)}, using the messag
|
|
|
10683
11077
|
});
|
|
10684
11078
|
} catch (error) {
|
|
10685
11079
|
console.error("Error in LLM Execution Step", error);
|
|
10686
|
-
if (
|
|
11080
|
+
if (providerUtilsV5.isAbortError(error) && options?.abortSignal?.aborted) {
|
|
10687
11081
|
await options?.onAbort?.({
|
|
10688
11082
|
steps: inputData?.output?.steps ?? []
|
|
10689
11083
|
});
|
|
@@ -10801,6 +11195,7 @@ Analyse the suspended tools: ${JSON.stringify(suspendedTools)}, using the messag
|
|
|
10801
11195
|
}));
|
|
10802
11196
|
const currentRetryCount = inputData.processorRetryCount || 0;
|
|
10803
11197
|
await processorRunner.runProcessOutputStep({
|
|
11198
|
+
steps: inputData.output?.steps ?? [],
|
|
10804
11199
|
messages: messageList.get.all.db(),
|
|
10805
11200
|
messageList,
|
|
10806
11201
|
stepNumber,
|
|
@@ -11210,7 +11605,17 @@ function createToolCallStep({
|
|
|
11210
11605
|
}
|
|
11211
11606
|
const resumeData = resumeDataFromArgs ?? workflowResumeData;
|
|
11212
11607
|
const isResumeToolCall = !!resumeDataFromArgs;
|
|
11213
|
-
|
|
11608
|
+
let toolRequiresApproval = requireToolApproval || tool2.requireApproval;
|
|
11609
|
+
if (tool2.needsApprovalFn) {
|
|
11610
|
+
try {
|
|
11611
|
+
const needsApprovalResult = await tool2.needsApprovalFn(args);
|
|
11612
|
+
toolRequiresApproval = needsApprovalResult;
|
|
11613
|
+
} catch (error) {
|
|
11614
|
+
console.error(`Error evaluating needsApprovalFn for tool ${inputData.toolName}:`, error);
|
|
11615
|
+
toolRequiresApproval = true;
|
|
11616
|
+
}
|
|
11617
|
+
}
|
|
11618
|
+
if (toolRequiresApproval) {
|
|
11214
11619
|
if (!resumeData) {
|
|
11215
11620
|
controller.enqueue({
|
|
11216
11621
|
type: "tool-call-approval",
|
|
@@ -11473,11 +11878,10 @@ function createAgenticLoopWorkflow(params) {
|
|
|
11473
11878
|
};
|
|
11474
11879
|
accumulatedSteps.push(currentStep);
|
|
11475
11880
|
if (rest.stopWhen && typedInputData.stepResult?.isContinued && accumulatedSteps.length > 0) {
|
|
11881
|
+
const steps = accumulatedSteps;
|
|
11476
11882
|
const conditions = await Promise.all(
|
|
11477
11883
|
(Array.isArray(rest.stopWhen) ? rest.stopWhen : [rest.stopWhen]).map((condition) => {
|
|
11478
|
-
return condition({
|
|
11479
|
-
steps: accumulatedSteps
|
|
11480
|
-
});
|
|
11884
|
+
return condition({ steps });
|
|
11481
11885
|
})
|
|
11482
11886
|
);
|
|
11483
11887
|
const hasStopped = conditions.some((condition) => condition);
|
|
@@ -11620,7 +12024,7 @@ function workflowLoopStream({
|
|
|
11620
12024
|
});
|
|
11621
12025
|
if (executionResult.status !== "success") {
|
|
11622
12026
|
if (executionResult.status === "failed") {
|
|
11623
|
-
const error =
|
|
12027
|
+
const error = chunk4U7ZLI36_cjs.getErrorFromUnknown(executionResult.error, {
|
|
11624
12028
|
fallbackMessage: "Unknown error in agent workflow stream"
|
|
11625
12029
|
});
|
|
11626
12030
|
controller.enqueue({
|
|
@@ -11681,7 +12085,7 @@ function loop({
|
|
|
11681
12085
|
level: "debug"
|
|
11682
12086
|
});
|
|
11683
12087
|
if (models.length === 0 || !models[0]) {
|
|
11684
|
-
const mastraError = new
|
|
12088
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
11685
12089
|
id: "LOOP_MODELS_EMPTY",
|
|
11686
12090
|
domain: "LLM" /* LLM */,
|
|
11687
12091
|
category: "USER" /* USER */
|
|
@@ -11798,7 +12202,7 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
11798
12202
|
}
|
|
11799
12203
|
}
|
|
11800
12204
|
if (models.length === 0 || !models[0]) {
|
|
11801
|
-
const mastraError = new
|
|
12205
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
11802
12206
|
id: "LLM_LOOP_MODELS_EMPTY",
|
|
11803
12207
|
domain: "LLM" /* LLM */,
|
|
11804
12208
|
category: "USER" /* USER */
|
|
@@ -11923,8 +12327,6 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
11923
12327
|
messages: [...messageList.getSystemMessages(), ...messages]
|
|
11924
12328
|
},
|
|
11925
12329
|
attributes: {
|
|
11926
|
-
agentId,
|
|
11927
|
-
agentName,
|
|
11928
12330
|
model: firstModel.modelId,
|
|
11929
12331
|
provider: firstModel.provider,
|
|
11930
12332
|
streaming: true,
|
|
@@ -11972,7 +12374,7 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
11972
12374
|
try {
|
|
11973
12375
|
await options?.onStepFinish?.({ ...props, runId });
|
|
11974
12376
|
} catch (e) {
|
|
11975
|
-
const mastraError = new
|
|
12377
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError(
|
|
11976
12378
|
{
|
|
11977
12379
|
id: "LLM_STREAM_ON_STEP_FINISH_CALLBACK_EXECUTION_FAILED",
|
|
11978
12380
|
domain: "LLM" /* LLM */,
|
|
@@ -12006,7 +12408,7 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
12006
12408
|
const remainingTokens = parseInt(props?.response?.headers?.["x-ratelimit-remaining-tokens"] ?? "", 10);
|
|
12007
12409
|
if (!isNaN(remainingTokens) && remainingTokens > 0 && remainingTokens < 2e3) {
|
|
12008
12410
|
this.logger.warn("Rate limit approaching, waiting 10 seconds", { runId });
|
|
12009
|
-
await
|
|
12411
|
+
await chunkBC2VKOH4_cjs.delay(10 * 1e3);
|
|
12010
12412
|
}
|
|
12011
12413
|
},
|
|
12012
12414
|
onFinish: async (props) => {
|
|
@@ -12031,7 +12433,7 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
12031
12433
|
try {
|
|
12032
12434
|
await options?.onFinish?.({ ...props, runId });
|
|
12033
12435
|
} catch (e) {
|
|
12034
|
-
const mastraError = new
|
|
12436
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError(
|
|
12035
12437
|
{
|
|
12036
12438
|
id: "LLM_STREAM_ON_FINISH_CALLBACK_EXECUTION_FAILED",
|
|
12037
12439
|
domain: "LLM" /* LLM */,
|
|
@@ -12069,7 +12471,7 @@ var MastraLLMVNext = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
12069
12471
|
};
|
|
12070
12472
|
return loop(loopOptions);
|
|
12071
12473
|
} catch (e) {
|
|
12072
|
-
const mastraError = new
|
|
12474
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError(
|
|
12073
12475
|
{
|
|
12074
12476
|
id: "LLM_STREAM_TEXT_AI_SDK_EXECUTION_FAILED",
|
|
12075
12477
|
domain: "LLM" /* LLM */,
|
|
@@ -12216,7 +12618,7 @@ async function prepareMemoryStep({
|
|
|
12216
12618
|
);
|
|
12217
12619
|
}
|
|
12218
12620
|
} else {
|
|
12219
|
-
const messageList = new
|
|
12621
|
+
const messageList = new chunkEMLEZXTQ_cjs.MessageList({
|
|
12220
12622
|
threadId: thread?.id,
|
|
12221
12623
|
resourceId: thread?.resourceId
|
|
12222
12624
|
});
|
|
@@ -12572,7 +12974,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12572
12974
|
const agentsMap = await agent.listAgents({ requestContext });
|
|
12573
12975
|
const agentForStep = agentsMap[inputData.primitiveId];
|
|
12574
12976
|
if (!agentForStep) {
|
|
12575
|
-
const mastraError = new
|
|
12977
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
12576
12978
|
id: "AGENT_NETWORK_AGENT_EXECUTION_STEP_INVALID_TASK_INPUT",
|
|
12577
12979
|
domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
|
|
12578
12980
|
category: "USER" /* USER */,
|
|
@@ -12699,7 +13101,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12699
13101
|
const workflowId = inputData.primitiveId;
|
|
12700
13102
|
const wf = workflowsMap[workflowId];
|
|
12701
13103
|
if (!wf) {
|
|
12702
|
-
const mastraError = new
|
|
13104
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
12703
13105
|
id: "AGENT_NETWORK_WORKFLOW_EXECUTION_STEP_INVALID_TASK_INPUT",
|
|
12704
13106
|
domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
|
|
12705
13107
|
category: "USER" /* USER */,
|
|
@@ -12711,7 +13113,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12711
13113
|
try {
|
|
12712
13114
|
input = JSON.parse(inputData.prompt);
|
|
12713
13115
|
} catch (e) {
|
|
12714
|
-
const mastraError = new
|
|
13116
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError(
|
|
12715
13117
|
{
|
|
12716
13118
|
id: "WORKFLOW_EXECUTION_STEP_INVALID_TASK_INPUT",
|
|
12717
13119
|
domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
|
|
@@ -12836,7 +13238,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12836
13238
|
const toolsMap = { ...agentTools, ...memoryTools };
|
|
12837
13239
|
let tool2 = toolsMap[inputData.primitiveId];
|
|
12838
13240
|
if (!tool2) {
|
|
12839
|
-
const mastraError = new
|
|
13241
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
12840
13242
|
id: "AGENT_NETWORK_TOOL_EXECUTION_STEP_INVALID_TASK_INPUT",
|
|
12841
13243
|
domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
|
|
12842
13244
|
category: "USER" /* USER */,
|
|
@@ -12845,7 +13247,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12845
13247
|
throw mastraError;
|
|
12846
13248
|
}
|
|
12847
13249
|
if (!tool2.execute) {
|
|
12848
|
-
const mastraError = new
|
|
13250
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
12849
13251
|
id: "AGENT_NETWORK_TOOL_EXECUTION_STEP_INVALID_TASK_INPUT",
|
|
12850
13252
|
domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
|
|
12851
13253
|
category: "USER" /* USER */,
|
|
@@ -12858,7 +13260,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
12858
13260
|
try {
|
|
12859
13261
|
inputDataToUse = JSON.parse(inputData.prompt);
|
|
12860
13262
|
} catch (e) {
|
|
12861
|
-
const mastraError = new
|
|
13263
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError(
|
|
12862
13264
|
{
|
|
12863
13265
|
id: "AGENT_NETWORK_TOOL_EXECUTION_STEP_INVALID_TASK_INPUT",
|
|
12864
13266
|
domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
|
|
@@ -13083,7 +13485,7 @@ async function networkLoop({
|
|
|
13083
13485
|
}) {
|
|
13084
13486
|
const memoryToUse = await routingAgent.getMemory({ requestContext });
|
|
13085
13487
|
if (!memoryToUse) {
|
|
13086
|
-
throw new
|
|
13488
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
13087
13489
|
id: "AGENT_NETWORK_MEMORY_REQUIRED",
|
|
13088
13490
|
domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
|
|
13089
13491
|
category: "USER" /* USER */,
|
|
@@ -13186,67 +13588,6 @@ async function networkLoop({
|
|
|
13186
13588
|
|
|
13187
13589
|
// src/agent/agent-legacy.ts
|
|
13188
13590
|
var import_fast_deep_equal = chunk6SZKM6EC_cjs.__toESM(require_fast_deep_equal(), 1);
|
|
13189
|
-
|
|
13190
|
-
// src/agent/utils.ts
|
|
13191
|
-
async function tryGenerateWithJsonFallback(agent, prompt, options) {
|
|
13192
|
-
if (!options.structuredOutput?.schema) {
|
|
13193
|
-
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
13194
|
-
id: "STRUCTURED_OUTPUT_OPTIONS_REQUIRED",
|
|
13195
|
-
domain: "AGENT" /* AGENT */,
|
|
13196
|
-
category: "USER" /* USER */,
|
|
13197
|
-
text: "structuredOutput is required to use tryGenerateWithJsonFallback"
|
|
13198
|
-
});
|
|
13199
|
-
}
|
|
13200
|
-
try {
|
|
13201
|
-
return await agent.generate(prompt, options);
|
|
13202
|
-
} catch (error) {
|
|
13203
|
-
console.warn("Error in tryGenerateWithJsonFallback. Attempting fallback.", error);
|
|
13204
|
-
return await agent.generate(prompt, {
|
|
13205
|
-
...options,
|
|
13206
|
-
structuredOutput: { ...options.structuredOutput, jsonPromptInjection: true }
|
|
13207
|
-
});
|
|
13208
|
-
}
|
|
13209
|
-
}
|
|
13210
|
-
async function tryStreamWithJsonFallback(agent, prompt, options) {
|
|
13211
|
-
if (!options.structuredOutput?.schema) {
|
|
13212
|
-
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
13213
|
-
id: "STRUCTURED_OUTPUT_OPTIONS_REQUIRED",
|
|
13214
|
-
domain: "AGENT" /* AGENT */,
|
|
13215
|
-
category: "USER" /* USER */,
|
|
13216
|
-
text: "structuredOutput is required to use tryStreamWithJsonFallback"
|
|
13217
|
-
});
|
|
13218
|
-
}
|
|
13219
|
-
try {
|
|
13220
|
-
const result = await agent.stream(prompt, options);
|
|
13221
|
-
const object = await result.object;
|
|
13222
|
-
if (!object) {
|
|
13223
|
-
throw new chunkHWMMIRIF_cjs.MastraError({
|
|
13224
|
-
id: "STRUCTURED_OUTPUT_OBJECT_UNDEFINED",
|
|
13225
|
-
domain: "AGENT" /* AGENT */,
|
|
13226
|
-
category: "USER" /* USER */,
|
|
13227
|
-
text: "structuredOutput object is undefined"
|
|
13228
|
-
});
|
|
13229
|
-
}
|
|
13230
|
-
return result;
|
|
13231
|
-
} catch (error) {
|
|
13232
|
-
console.warn("Error in tryStreamWithJsonFallback. Attempting fallback.", error);
|
|
13233
|
-
return await agent.stream(prompt, {
|
|
13234
|
-
...options,
|
|
13235
|
-
structuredOutput: { ...options.structuredOutput, jsonPromptInjection: true }
|
|
13236
|
-
});
|
|
13237
|
-
}
|
|
13238
|
-
}
|
|
13239
|
-
function resolveThreadIdFromArgs(args) {
|
|
13240
|
-
if (args?.memory?.thread) {
|
|
13241
|
-
if (typeof args.memory.thread === "string") return { id: args.memory.thread };
|
|
13242
|
-
if (typeof args.memory.thread === "object" && args.memory.thread.id)
|
|
13243
|
-
return args.memory.thread;
|
|
13244
|
-
}
|
|
13245
|
-
if (args?.threadId) return { id: args.threadId };
|
|
13246
|
-
return void 0;
|
|
13247
|
-
}
|
|
13248
|
-
|
|
13249
|
-
// src/agent/agent-legacy.ts
|
|
13250
13591
|
var AgentLegacyHandler = class {
|
|
13251
13592
|
constructor(capabilities) {
|
|
13252
13593
|
this.capabilities = capabilities;
|
|
@@ -13277,15 +13618,16 @@ var AgentLegacyHandler = class {
|
|
|
13277
13618
|
if (process.env.NODE_ENV !== "test") {
|
|
13278
13619
|
this.capabilities.logger.debug(`[Agents:${this.capabilities.name}] - Starting generation`, { runId });
|
|
13279
13620
|
}
|
|
13280
|
-
const agentSpan =
|
|
13621
|
+
const agentSpan = chunkO2CAMK4A_cjs.getOrCreateSpan({
|
|
13281
13622
|
type: "agent_run" /* AGENT_RUN */,
|
|
13282
13623
|
name: `agent run: '${this.capabilities.id}'`,
|
|
13624
|
+
entityType: "agent" /* AGENT */,
|
|
13625
|
+
entityId: this.capabilities.id,
|
|
13626
|
+
entityName: this.capabilities.name,
|
|
13283
13627
|
input: {
|
|
13284
13628
|
messages
|
|
13285
13629
|
},
|
|
13286
13630
|
attributes: {
|
|
13287
|
-
agentId: this.capabilities.id,
|
|
13288
|
-
agentName: this.capabilities.name,
|
|
13289
13631
|
instructions: this.capabilities.convertInstructionsToString(instructions),
|
|
13290
13632
|
availableTools: [
|
|
13291
13633
|
...toolsets ? Object.keys(toolsets) : [],
|
|
@@ -13331,7 +13673,7 @@ var AgentLegacyHandler = class {
|
|
|
13331
13673
|
methodType: methodType === "generate" ? "generateLegacy" : "streamLegacy",
|
|
13332
13674
|
memoryConfig
|
|
13333
13675
|
});
|
|
13334
|
-
let messageList = new
|
|
13676
|
+
let messageList = new chunkEMLEZXTQ_cjs.MessageList({
|
|
13335
13677
|
threadId,
|
|
13336
13678
|
resourceId,
|
|
13337
13679
|
generateMessageId: this.capabilities.mastra?.generateId?.bind(this.capabilities.mastra),
|
|
@@ -13356,7 +13698,7 @@ var AgentLegacyHandler = class {
|
|
|
13356
13698
|
};
|
|
13357
13699
|
}
|
|
13358
13700
|
if (!threadId || !resourceId) {
|
|
13359
|
-
const mastraError = new
|
|
13701
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
13360
13702
|
id: "AGENT_MEMORY_MISSING_RESOURCE_ID",
|
|
13361
13703
|
domain: "AGENT" /* AGENT */,
|
|
13362
13704
|
category: "USER" /* USER */,
|
|
@@ -13462,7 +13804,7 @@ var AgentLegacyHandler = class {
|
|
|
13462
13804
|
result: resToLog,
|
|
13463
13805
|
threadId
|
|
13464
13806
|
});
|
|
13465
|
-
const messageListResponses = new
|
|
13807
|
+
const messageListResponses = new chunkEMLEZXTQ_cjs.MessageList({
|
|
13466
13808
|
threadId,
|
|
13467
13809
|
resourceId,
|
|
13468
13810
|
generateMessageId: this.capabilities.mastra?.generateId?.bind(this.capabilities.mastra),
|
|
@@ -13532,11 +13874,11 @@ var AgentLegacyHandler = class {
|
|
|
13532
13874
|
await Promise.all(promises);
|
|
13533
13875
|
}
|
|
13534
13876
|
} catch (e) {
|
|
13535
|
-
if (e instanceof
|
|
13877
|
+
if (e instanceof chunk4U7ZLI36_cjs.MastraError) {
|
|
13536
13878
|
agentSpan?.error({ error: e });
|
|
13537
13879
|
throw e;
|
|
13538
13880
|
}
|
|
13539
|
-
const mastraError = new
|
|
13881
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError(
|
|
13540
13882
|
{
|
|
13541
13883
|
id: "AGENT_MEMORY_PERSIST_RESPONSE_MESSAGES_FAILED",
|
|
13542
13884
|
domain: "AGENT" /* AGENT */,
|
|
@@ -13738,7 +14080,7 @@ var AgentLegacyHandler = class {
|
|
|
13738
14080
|
*/
|
|
13739
14081
|
async generateLegacy(messages, generateOptions = {}) {
|
|
13740
14082
|
if ("structuredOutput" in generateOptions && generateOptions.structuredOutput) {
|
|
13741
|
-
throw new
|
|
14083
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
13742
14084
|
id: "AGENT_GENERATE_LEGACY_STRUCTURED_OUTPUT_NOT_SUPPORTED",
|
|
13743
14085
|
domain: "AGENT" /* AGENT */,
|
|
13744
14086
|
category: "USER" /* USER */,
|
|
@@ -13760,7 +14102,7 @@ var AgentLegacyHandler = class {
|
|
|
13760
14102
|
this.capabilities.logger.error("V2 models are not supported for generateLegacy. Please use generate instead.", {
|
|
13761
14103
|
modelId: llm.getModel().modelId
|
|
13762
14104
|
});
|
|
13763
|
-
throw new
|
|
14105
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
13764
14106
|
id: "AGENT_GENERATE_V2_MODEL_NOT_SUPPORTED",
|
|
13765
14107
|
domain: "AGENT" /* AGENT */,
|
|
13766
14108
|
category: "USER" /* USER */,
|
|
@@ -13980,7 +14322,7 @@ var AgentLegacyHandler = class {
|
|
|
13980
14322
|
this.capabilities.logger.error("V2 models are not supported for streamLegacy. Please use stream instead.", {
|
|
13981
14323
|
modelId: llm.getModel().modelId
|
|
13982
14324
|
});
|
|
13983
|
-
throw new
|
|
14325
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
13984
14326
|
id: "AGENT_STREAM_V2_MODEL_NOT_SUPPORTED",
|
|
13985
14327
|
domain: "AGENT" /* AGENT */,
|
|
13986
14328
|
category: "USER" /* USER */,
|
|
@@ -14264,7 +14606,7 @@ function getModelMethodFromAgentMethod(methodType) {
|
|
|
14264
14606
|
} else if (methodType === "stream" || methodType === "streamLegacy") {
|
|
14265
14607
|
return "stream";
|
|
14266
14608
|
} else {
|
|
14267
|
-
throw new
|
|
14609
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
14268
14610
|
id: "INVALID_METHOD_TYPE",
|
|
14269
14611
|
domain: "AGENT" /* AGENT */,
|
|
14270
14612
|
category: "USER" /* USER */
|
|
@@ -14326,6 +14668,14 @@ function createMapResultsStep({
|
|
|
14326
14668
|
};
|
|
14327
14669
|
if (result.tripwire) {
|
|
14328
14670
|
const agentModel = await capabilities.getModel({ requestContext: result.requestContext });
|
|
14671
|
+
if (!isSupportedLanguageModel(agentModel)) {
|
|
14672
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
14673
|
+
id: "MAP_RESULTS_STEP_UNSUPPORTED_MODEL",
|
|
14674
|
+
domain: "AGENT" /* AGENT */,
|
|
14675
|
+
category: "USER" /* USER */,
|
|
14676
|
+
text: "Tripwire handling requires a v2/v3 model"
|
|
14677
|
+
});
|
|
14678
|
+
}
|
|
14329
14679
|
const modelOutput = await getModelOutputForTripwire({
|
|
14330
14680
|
tripwire: memoryData.tripwire,
|
|
14331
14681
|
runId,
|
|
@@ -14455,7 +14805,7 @@ var prepareToolsStepOutputSchema = z8.z.object({
|
|
|
14455
14805
|
var prepareMemoryStepOutputSchema = z8.z.object({
|
|
14456
14806
|
threadExists: z8.z.boolean(),
|
|
14457
14807
|
thread: storageThreadSchema.optional(),
|
|
14458
|
-
messageList: z8.z.instanceof(
|
|
14808
|
+
messageList: z8.z.instanceof(chunkEMLEZXTQ_cjs.MessageList),
|
|
14459
14809
|
/** Tripwire data when input processor triggered abort */
|
|
14460
14810
|
tripwire: z8.z.object({
|
|
14461
14811
|
reason: z8.z.string(),
|
|
@@ -14493,7 +14843,7 @@ function createPrepareMemoryStep({
|
|
|
14493
14843
|
outputSchema: prepareMemoryStepOutputSchema,
|
|
14494
14844
|
execute: async ({ tracingContext }) => {
|
|
14495
14845
|
const thread = threadFromArgs;
|
|
14496
|
-
const messageList = new
|
|
14846
|
+
const messageList = new chunkEMLEZXTQ_cjs.MessageList({
|
|
14497
14847
|
threadId: thread?.id,
|
|
14498
14848
|
resourceId,
|
|
14499
14849
|
generateMessageId: capabilities.generateMessageId,
|
|
@@ -14519,7 +14869,7 @@ function createPrepareMemoryStep({
|
|
|
14519
14869
|
};
|
|
14520
14870
|
}
|
|
14521
14871
|
if (!thread?.id || !resourceId) {
|
|
14522
|
-
const mastraError = new
|
|
14872
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
14523
14873
|
id: "AGENT_MEMORY_MISSING_RESOURCE_ID",
|
|
14524
14874
|
domain: "AGENT" /* AGENT */,
|
|
14525
14875
|
category: "USER" /* USER */,
|
|
@@ -14843,7 +15193,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
14843
15193
|
this.#description = config.description;
|
|
14844
15194
|
this.#options = config.options;
|
|
14845
15195
|
if (!config.model) {
|
|
14846
|
-
const mastraError = new
|
|
15196
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
14847
15197
|
id: "AGENT_CONSTRUCTOR_MODEL_REQUIRED",
|
|
14848
15198
|
domain: "AGENT" /* AGENT */,
|
|
14849
15199
|
category: "USER" /* USER */,
|
|
@@ -14858,7 +15208,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
14858
15208
|
}
|
|
14859
15209
|
if (Array.isArray(config.model)) {
|
|
14860
15210
|
if (config.model.length === 0) {
|
|
14861
|
-
const mastraError = new
|
|
15211
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
14862
15212
|
id: "AGENT_CONSTRUCTOR_MODEL_ARRAY_EMPTY",
|
|
14863
15213
|
domain: "AGENT" /* AGENT */,
|
|
14864
15214
|
category: "USER" /* USER */,
|
|
@@ -14910,7 +15260,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
14910
15260
|
this.#voice?.addInstructions(config.instructions);
|
|
14911
15261
|
}
|
|
14912
15262
|
} else {
|
|
14913
|
-
this.#voice = new
|
|
15263
|
+
this.#voice = new chunkSSB4AVHU_cjs.DefaultVoice();
|
|
14914
15264
|
}
|
|
14915
15265
|
if (config.inputProcessors) {
|
|
14916
15266
|
this.#inputProcessors = config.inputProcessors;
|
|
@@ -14940,7 +15290,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
14940
15290
|
const agentsToUse = this.#agents ? typeof this.#agents === "function" ? this.#agents({ requestContext }) : this.#agents : {};
|
|
14941
15291
|
return resolveMaybePromise(agentsToUse, (agents) => {
|
|
14942
15292
|
if (!agents) {
|
|
14943
|
-
const mastraError = new
|
|
15293
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
14944
15294
|
id: "AGENT_GET_AGENTS_FUNCTION_EMPTY_RETURN",
|
|
14945
15295
|
domain: "AGENT" /* AGENT */,
|
|
14946
15296
|
category: "USER" /* USER */,
|
|
@@ -14967,7 +15317,6 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
14967
15317
|
}) {
|
|
14968
15318
|
const inputProcessors = inputProcessorOverrides ?? await this.listResolvedInputProcessors(requestContext);
|
|
14969
15319
|
const outputProcessors = outputProcessorOverrides ?? await this.listResolvedOutputProcessors(requestContext);
|
|
14970
|
-
this.logger.debug("outputProcessors", outputProcessors);
|
|
14971
15320
|
return new ProcessorRunner({
|
|
14972
15321
|
inputProcessors,
|
|
14973
15322
|
outputProcessors,
|
|
@@ -15024,7 +15373,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15024
15373
|
async listResolvedOutputProcessors(requestContext) {
|
|
15025
15374
|
const configuredProcessors = this.#outputProcessors ? typeof this.#outputProcessors === "function" ? await this.#outputProcessors({ requestContext: requestContext || new chunkUVHSM2GU_cjs.RequestContext() }) : this.#outputProcessors : [];
|
|
15026
15375
|
const memory = await this.getMemory({ requestContext: requestContext || new chunkUVHSM2GU_cjs.RequestContext() });
|
|
15027
|
-
const memoryProcessors = memory ? memory.getOutputProcessors(configuredProcessors, requestContext) : [];
|
|
15376
|
+
const memoryProcessors = memory ? await memory.getOutputProcessors(configuredProcessors, requestContext) : [];
|
|
15028
15377
|
const allProcessors = [...configuredProcessors, ...memoryProcessors];
|
|
15029
15378
|
return this.combineProcessorsIntoWorkflow(allProcessors, `${this.id}-output-processor`);
|
|
15030
15379
|
}
|
|
@@ -15036,7 +15385,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15036
15385
|
async listResolvedInputProcessors(requestContext) {
|
|
15037
15386
|
const configuredProcessors = this.#inputProcessors ? typeof this.#inputProcessors === "function" ? await this.#inputProcessors({ requestContext: requestContext || new chunkUVHSM2GU_cjs.RequestContext() }) : this.#inputProcessors : [];
|
|
15038
15387
|
const memory = await this.getMemory({ requestContext: requestContext || new chunkUVHSM2GU_cjs.RequestContext() });
|
|
15039
|
-
const memoryProcessors = memory ? memory.getInputProcessors(configuredProcessors, requestContext) : [];
|
|
15388
|
+
const memoryProcessors = memory ? await memory.getInputProcessors(configuredProcessors, requestContext) : [];
|
|
15040
15389
|
const allProcessors = [...memoryProcessors, ...configuredProcessors];
|
|
15041
15390
|
return this.combineProcessorsIntoWorkflow(allProcessors, `${this.id}-input-processor`);
|
|
15042
15391
|
}
|
|
@@ -15115,7 +15464,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15115
15464
|
const result = this.#memory({ requestContext, mastra: this.#mastra });
|
|
15116
15465
|
resolvedMemory = await Promise.resolve(result);
|
|
15117
15466
|
if (!resolvedMemory) {
|
|
15118
|
-
const mastraError = new
|
|
15467
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
15119
15468
|
id: "AGENT_GET_MEMORY_FUNCTION_EMPTY_RETURN",
|
|
15120
15469
|
domain: "AGENT" /* AGENT */,
|
|
15121
15470
|
category: "USER" /* USER */,
|
|
@@ -15142,7 +15491,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15142
15491
|
}
|
|
15143
15492
|
get voice() {
|
|
15144
15493
|
if (typeof this.#instructions === "function") {
|
|
15145
|
-
const mastraError = new
|
|
15494
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
15146
15495
|
id: "AGENT_VOICE_INCOMPATIBLE_WITH_FUNCTION_INSTRUCTIONS",
|
|
15147
15496
|
domain: "AGENT" /* AGENT */,
|
|
15148
15497
|
category: "USER" /* USER */,
|
|
@@ -15192,7 +15541,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15192
15541
|
const result = this.#scorers({ requestContext, mastra: this.#mastra });
|
|
15193
15542
|
return resolveMaybePromise(result, (scorers) => {
|
|
15194
15543
|
if (!scorers) {
|
|
15195
|
-
const mastraError = new
|
|
15544
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
15196
15545
|
id: "AGENT_GET_SCORERS_FUNCTION_EMPTY_RETURN",
|
|
15197
15546
|
domain: "AGENT" /* AGENT */,
|
|
15198
15547
|
category: "USER" /* USER */,
|
|
@@ -15226,7 +15575,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15226
15575
|
voice?.addInstructions(this.#convertInstructionsToString(instructions));
|
|
15227
15576
|
return voice;
|
|
15228
15577
|
} else {
|
|
15229
|
-
return new
|
|
15578
|
+
return new chunkSSB4AVHU_cjs.DefaultVoice();
|
|
15230
15579
|
}
|
|
15231
15580
|
}
|
|
15232
15581
|
/**
|
|
@@ -15244,7 +15593,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15244
15593
|
const result = this.#instructions({ requestContext, mastra: this.#mastra });
|
|
15245
15594
|
return resolveMaybePromise(result, (instructions) => {
|
|
15246
15595
|
if (!instructions) {
|
|
15247
|
-
const mastraError = new
|
|
15596
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
15248
15597
|
id: "AGENT_GET_INSTRUCTIONS_FUNCTION_EMPTY_RETURN",
|
|
15249
15598
|
domain: "AGENT" /* AGENT */,
|
|
15250
15599
|
category: "USER" /* USER */,
|
|
@@ -15349,7 +15698,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15349
15698
|
const result = this.#defaultGenerateOptionsLegacy({ requestContext, mastra: this.#mastra });
|
|
15350
15699
|
return resolveMaybePromise(result, (options) => {
|
|
15351
15700
|
if (!options) {
|
|
15352
|
-
const mastraError = new
|
|
15701
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
15353
15702
|
id: "AGENT_GET_DEFAULT_GENERATE_OPTIONS_FUNCTION_EMPTY_RETURN",
|
|
15354
15703
|
domain: "AGENT" /* AGENT */,
|
|
15355
15704
|
category: "USER" /* USER */,
|
|
@@ -15384,7 +15733,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15384
15733
|
const result = this.#defaultStreamOptionsLegacy({ requestContext, mastra: this.#mastra });
|
|
15385
15734
|
return resolveMaybePromise(result, (options) => {
|
|
15386
15735
|
if (!options) {
|
|
15387
|
-
const mastraError = new
|
|
15736
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
15388
15737
|
id: "AGENT_GET_DEFAULT_STREAM_OPTIONS_FUNCTION_EMPTY_RETURN",
|
|
15389
15738
|
domain: "AGENT" /* AGENT */,
|
|
15390
15739
|
category: "USER" /* USER */,
|
|
@@ -15419,7 +15768,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15419
15768
|
const result = this.#defaultOptions({ requestContext, mastra: this.#mastra });
|
|
15420
15769
|
return resolveMaybePromise(result, (options) => {
|
|
15421
15770
|
if (!options) {
|
|
15422
|
-
const mastraError = new
|
|
15771
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
15423
15772
|
id: "AGENT_GET_DEFAULT_OPTIONS_FUNCTION_EMPTY_RETURN",
|
|
15424
15773
|
domain: "AGENT" /* AGENT */,
|
|
15425
15774
|
category: "USER" /* USER */,
|
|
@@ -15447,12 +15796,12 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15447
15796
|
*/
|
|
15448
15797
|
listTools({ requestContext = new chunkUVHSM2GU_cjs.RequestContext() } = {}) {
|
|
15449
15798
|
if (typeof this.#tools !== "function") {
|
|
15450
|
-
return
|
|
15799
|
+
return chunkBC2VKOH4_cjs.ensureToolProperties(this.#tools);
|
|
15451
15800
|
}
|
|
15452
15801
|
const result = this.#tools({ requestContext, mastra: this.#mastra });
|
|
15453
15802
|
return resolveMaybePromise(result, (tools) => {
|
|
15454
15803
|
if (!tools) {
|
|
15455
|
-
const mastraError = new
|
|
15804
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
15456
15805
|
id: "AGENT_GET_TOOLS_FUNCTION_EMPTY_RETURN",
|
|
15457
15806
|
domain: "AGENT" /* AGENT */,
|
|
15458
15807
|
category: "USER" /* USER */,
|
|
@@ -15465,7 +15814,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15465
15814
|
this.logger.error(mastraError.toString());
|
|
15466
15815
|
throw mastraError;
|
|
15467
15816
|
}
|
|
15468
|
-
return
|
|
15817
|
+
return chunkBC2VKOH4_cjs.ensureToolProperties(tools);
|
|
15469
15818
|
});
|
|
15470
15819
|
}
|
|
15471
15820
|
/**
|
|
@@ -15486,7 +15835,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15486
15835
|
const modelToUse = this.getModel({ modelConfig: model, requestContext });
|
|
15487
15836
|
return resolveMaybePromise(modelToUse, (resolvedModel) => {
|
|
15488
15837
|
let llm;
|
|
15489
|
-
if (resolvedModel
|
|
15838
|
+
if (isSupportedLanguageModel(resolvedModel)) {
|
|
15490
15839
|
const modelsPromise = Array.isArray(this.model) && !model ? this.prepareModels(requestContext) : this.prepareModels(requestContext, resolvedModel);
|
|
15491
15840
|
llm = modelsPromise.then((models) => {
|
|
15492
15841
|
const enabledModels = models.filter((model2) => model2.enabled);
|
|
@@ -15497,7 +15846,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15497
15846
|
});
|
|
15498
15847
|
});
|
|
15499
15848
|
} else {
|
|
15500
|
-
llm = new
|
|
15849
|
+
llm = new chunkT2LVULCK_cjs.MastraLLMV1({
|
|
15501
15850
|
model: resolvedModel,
|
|
15502
15851
|
mastra: this.#mastra,
|
|
15503
15852
|
options: { tracingPolicy: this.#options?.tracingPolicy }
|
|
@@ -15522,9 +15871,9 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15522
15871
|
*/
|
|
15523
15872
|
async resolveModelConfig(modelConfig, requestContext) {
|
|
15524
15873
|
try {
|
|
15525
|
-
return await
|
|
15874
|
+
return await chunkGXMJ5URG_cjs.resolveModelConfig(modelConfig, requestContext, this.#mastra);
|
|
15526
15875
|
} catch (error) {
|
|
15527
|
-
const mastraError = new
|
|
15876
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
15528
15877
|
id: "AGENT_GET_MODEL_MISSING_MODEL_INSTANCE",
|
|
15529
15878
|
domain: "AGENT" /* AGENT */,
|
|
15530
15879
|
category: "USER" /* USER */,
|
|
@@ -15558,7 +15907,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15558
15907
|
} = {}) {
|
|
15559
15908
|
if (!Array.isArray(modelConfig)) return this.resolveModelConfig(modelConfig, requestContext);
|
|
15560
15909
|
if (modelConfig.length === 0 || !modelConfig[0]) {
|
|
15561
|
-
const mastraError = new
|
|
15910
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
15562
15911
|
id: "AGENT_GET_MODEL_MISSING_MODEL_INSTANCE",
|
|
15563
15912
|
domain: "AGENT" /* AGENT */,
|
|
15564
15913
|
category: "USER" /* USER */,
|
|
@@ -15682,7 +16031,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15682
16031
|
mastra.addTool(tool2, toolKey);
|
|
15683
16032
|
}
|
|
15684
16033
|
} catch (error) {
|
|
15685
|
-
if (error instanceof
|
|
16034
|
+
if (error instanceof chunk4U7ZLI36_cjs.MastraError && error.id !== "MASTRA_ADD_TOOL_DUPLICATE_KEY") {
|
|
15686
16035
|
throw error;
|
|
15687
16036
|
}
|
|
15688
16037
|
}
|
|
@@ -15693,7 +16042,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15693
16042
|
try {
|
|
15694
16043
|
mastra.addProcessor(processor);
|
|
15695
16044
|
} catch (error) {
|
|
15696
|
-
if (error instanceof
|
|
16045
|
+
if (error instanceof chunk4U7ZLI36_cjs.MastraError && error.id !== "MASTRA_ADD_PROCESSOR_DUPLICATE_KEY") {
|
|
15697
16046
|
throw error;
|
|
15698
16047
|
}
|
|
15699
16048
|
}
|
|
@@ -15704,7 +16053,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15704
16053
|
try {
|
|
15705
16054
|
mastra.addProcessor(processor);
|
|
15706
16055
|
} catch (error) {
|
|
15707
|
-
if (error instanceof
|
|
16056
|
+
if (error instanceof chunk4U7ZLI36_cjs.MastraError && error.id !== "MASTRA_ADD_PROCESSOR_DUPLICATE_KEY") {
|
|
15708
16057
|
throw error;
|
|
15709
16058
|
}
|
|
15710
16059
|
}
|
|
@@ -15728,7 +16077,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15728
16077
|
instructions
|
|
15729
16078
|
}) {
|
|
15730
16079
|
const llm = await this.getLLM({ requestContext, model });
|
|
15731
|
-
const normMessage = new
|
|
16080
|
+
const normMessage = new chunkEMLEZXTQ_cjs.MessageList().add(message, "user").get.all.ui().at(-1);
|
|
15732
16081
|
if (!normMessage) {
|
|
15733
16082
|
throw new Error(`Could not generate title from input ${JSON.stringify(message)}`);
|
|
15734
16083
|
}
|
|
@@ -15750,8 +16099,8 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15750
16099
|
}
|
|
15751
16100
|
const systemInstructions = await this.resolveTitleInstructions(requestContext, instructions);
|
|
15752
16101
|
let text = "";
|
|
15753
|
-
if (llm.getModel()
|
|
15754
|
-
const messageList = new
|
|
16102
|
+
if (isSupportedLanguageModel(llm.getModel())) {
|
|
16103
|
+
const messageList = new chunkEMLEZXTQ_cjs.MessageList().add(
|
|
15755
16104
|
[
|
|
15756
16105
|
{
|
|
15757
16106
|
role: "system",
|
|
@@ -15804,7 +16153,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15804
16153
|
async genTitle(userMessage, requestContext, tracingContext, model, instructions) {
|
|
15805
16154
|
try {
|
|
15806
16155
|
if (userMessage) {
|
|
15807
|
-
const normMessage = new
|
|
16156
|
+
const normMessage = new chunkEMLEZXTQ_cjs.MessageList().add(userMessage, "user").get.all.ui().at(-1);
|
|
15808
16157
|
if (normMessage) {
|
|
15809
16158
|
return await this.generateTitleFromUserMessage({
|
|
15810
16159
|
message: normMessage,
|
|
@@ -15869,7 +16218,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15869
16218
|
tracingPolicy: this.#options?.tracingPolicy,
|
|
15870
16219
|
requireApproval: toolObj.requireApproval
|
|
15871
16220
|
};
|
|
15872
|
-
const convertedToCoreTool =
|
|
16221
|
+
const convertedToCoreTool = chunkBC2VKOH4_cjs.makeCoreTool(toolObj, options, void 0, autoResumeSuspendedTools);
|
|
15873
16222
|
convertedMemoryTools[toolName] = convertedToCoreTool;
|
|
15874
16223
|
}
|
|
15875
16224
|
}
|
|
@@ -15902,7 +16251,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
15902
16251
|
processorId: error.processorId
|
|
15903
16252
|
};
|
|
15904
16253
|
} else {
|
|
15905
|
-
throw new
|
|
16254
|
+
throw new chunk4U7ZLI36_cjs.MastraError(
|
|
15906
16255
|
{
|
|
15907
16256
|
id: "AGENT_INPUT_PROCESSOR_ERROR",
|
|
15908
16257
|
domain: "AGENT" /* AGENT */,
|
|
@@ -16024,7 +16373,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16024
16373
|
tracingPolicy: this.#options?.tracingPolicy,
|
|
16025
16374
|
requireApproval: tool2.requireApproval
|
|
16026
16375
|
};
|
|
16027
|
-
return [k,
|
|
16376
|
+
return [k, chunkBC2VKOH4_cjs.makeCoreTool(tool2, options, void 0, autoResumeSuspendedTools)];
|
|
16028
16377
|
})
|
|
16029
16378
|
);
|
|
16030
16379
|
const assignedToolEntriesConverted = Object.fromEntries(
|
|
@@ -16074,7 +16423,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16074
16423
|
tracingPolicy: this.#options?.tracingPolicy,
|
|
16075
16424
|
requireApproval: toolObj.requireApproval
|
|
16076
16425
|
};
|
|
16077
|
-
const convertedToCoreTool =
|
|
16426
|
+
const convertedToCoreTool = chunkBC2VKOH4_cjs.makeCoreTool(toolObj, options, "toolset", autoResumeSuspendedTools);
|
|
16078
16427
|
toolsForRequest[toolName] = convertedToCoreTool;
|
|
16079
16428
|
}
|
|
16080
16429
|
}
|
|
@@ -16119,7 +16468,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16119
16468
|
tracingPolicy: this.#options?.tracingPolicy,
|
|
16120
16469
|
requireApproval: tool2.requireApproval
|
|
16121
16470
|
};
|
|
16122
|
-
const convertedToCoreTool =
|
|
16471
|
+
const convertedToCoreTool = chunkBC2VKOH4_cjs.makeCoreTool(rest, options, "client-tool", autoResumeSuspendedTools);
|
|
16123
16472
|
toolsForRequest[toolName] = convertedToCoreTool;
|
|
16124
16473
|
}
|
|
16125
16474
|
}
|
|
@@ -16157,7 +16506,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16157
16506
|
subAgentResourceId: z8.z.string().describe("The resource ID of the agent").optional()
|
|
16158
16507
|
});
|
|
16159
16508
|
const modelVersion = (await agent.getModel({ requestContext })).specificationVersion;
|
|
16160
|
-
const toolObj =
|
|
16509
|
+
const toolObj = chunk6HJFCSJ4_cjs.createTool({
|
|
16161
16510
|
id: `agent-${agentName}`,
|
|
16162
16511
|
description: agent.getDescription() || `Agent: ${agentName}`,
|
|
16163
16512
|
inputSchema: agentInputSchema,
|
|
@@ -16253,7 +16602,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16253
16602
|
}
|
|
16254
16603
|
return result;
|
|
16255
16604
|
} catch (err) {
|
|
16256
|
-
const mastraError = new
|
|
16605
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError(
|
|
16257
16606
|
{
|
|
16258
16607
|
id: "AGENT_AGENT_TOOL_EXECUTION_FAILED",
|
|
16259
16608
|
domain: "AGENT" /* AGENT */,
|
|
@@ -16289,7 +16638,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16289
16638
|
tracingContext,
|
|
16290
16639
|
tracingPolicy: this.#options?.tracingPolicy
|
|
16291
16640
|
};
|
|
16292
|
-
convertedAgentTools[`agent-${agentName}`] =
|
|
16641
|
+
convertedAgentTools[`agent-${agentName}`] = chunkBC2VKOH4_cjs.makeCoreTool(
|
|
16293
16642
|
toolObj,
|
|
16294
16643
|
options,
|
|
16295
16644
|
void 0,
|
|
@@ -16320,7 +16669,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16320
16669
|
inputData: workflow.inputSchema,
|
|
16321
16670
|
...workflow.stateSchema ? { initialState: workflow.stateSchema } : {}
|
|
16322
16671
|
});
|
|
16323
|
-
const toolObj =
|
|
16672
|
+
const toolObj = chunk6HJFCSJ4_cjs.createTool({
|
|
16324
16673
|
id: `workflow-${workflowName}`,
|
|
16325
16674
|
description: workflow.description || `Workflow: ${workflowName}`,
|
|
16326
16675
|
inputSchema: extendedInputSchema,
|
|
@@ -16433,7 +16782,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16433
16782
|
};
|
|
16434
16783
|
}
|
|
16435
16784
|
} catch (err) {
|
|
16436
|
-
const mastraError = new
|
|
16785
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError(
|
|
16437
16786
|
{
|
|
16438
16787
|
id: "AGENT_WORKFLOW_TOOL_EXECUTION_FAILED",
|
|
16439
16788
|
domain: "AGENT" /* AGENT */,
|
|
@@ -16468,7 +16817,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16468
16817
|
tracingContext,
|
|
16469
16818
|
tracingPolicy: this.#options?.tracingPolicy
|
|
16470
16819
|
};
|
|
16471
|
-
convertedWorkflowTools[`workflow-${workflowName}`] =
|
|
16820
|
+
convertedWorkflowTools[`workflow-${workflowName}`] = chunkBC2VKOH4_cjs.makeCoreTool(
|
|
16472
16821
|
toolObj,
|
|
16473
16822
|
options,
|
|
16474
16823
|
void 0,
|
|
@@ -16498,7 +16847,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16498
16847
|
let mastraProxy = void 0;
|
|
16499
16848
|
const logger = this.logger;
|
|
16500
16849
|
if (this.#mastra) {
|
|
16501
|
-
mastraProxy =
|
|
16850
|
+
mastraProxy = chunkBC2VKOH4_cjs.createMastraProxy({ mastra: this.#mastra, logger });
|
|
16502
16851
|
}
|
|
16503
16852
|
const assignedTools = await this.listAssignedTools({
|
|
16504
16853
|
runId,
|
|
@@ -16582,7 +16931,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16582
16931
|
}
|
|
16583
16932
|
newKey = newKey.slice(0, 63);
|
|
16584
16933
|
if (tools[newKey]) {
|
|
16585
|
-
const mastraError = new
|
|
16934
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
16586
16935
|
id: "AGENT_TOOL_NAME_COLLISION",
|
|
16587
16936
|
domain: "AGENT" /* AGENT */,
|
|
16588
16937
|
category: "USER" /* USER */,
|
|
@@ -16686,7 +17035,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16686
17035
|
if (typeof scorerObject.scorer === "string") {
|
|
16687
17036
|
try {
|
|
16688
17037
|
if (!this.#mastra) {
|
|
16689
|
-
throw new
|
|
17038
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
16690
17039
|
id: "AGENT_GENEREATE_SCORER_NOT_FOUND",
|
|
16691
17040
|
domain: "AGENT" /* AGENT */,
|
|
16692
17041
|
category: "USER" /* USER */,
|
|
@@ -16702,8 +17051,8 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16702
17051
|
result[id] = scorerObject;
|
|
16703
17052
|
}
|
|
16704
17053
|
}
|
|
16705
|
-
if (Object.keys(result).length === 0) {
|
|
16706
|
-
throw new
|
|
17054
|
+
if (Object.keys(result).length === 0 && Object.keys(overrideScorers).length > 0) {
|
|
17055
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
16707
17056
|
id: "AGENT_GENEREATE_SCORER_NOT_FOUND",
|
|
16708
17057
|
domain: "AGENT" /* AGENT */,
|
|
16709
17058
|
category: "USER" /* USER */,
|
|
@@ -16719,43 +17068,50 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16719
17068
|
async prepareModels(requestContext, model) {
|
|
16720
17069
|
if (model || !Array.isArray(this.model)) {
|
|
16721
17070
|
const modelToUse = model ?? this.model;
|
|
16722
|
-
const resolvedModel =
|
|
16723
|
-
|
|
16724
|
-
|
|
17071
|
+
const resolvedModel = await this.resolveModelConfig(
|
|
17072
|
+
modelToUse,
|
|
17073
|
+
requestContext
|
|
17074
|
+
);
|
|
17075
|
+
if (!isSupportedLanguageModel(resolvedModel)) {
|
|
17076
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
16725
17077
|
id: "AGENT_PREPARE_MODELS_INCOMPATIBLE_WITH_MODEL_ARRAY_V1",
|
|
16726
17078
|
domain: "AGENT" /* AGENT */,
|
|
16727
17079
|
category: "USER" /* USER */,
|
|
16728
17080
|
details: {
|
|
16729
17081
|
agentName: this.name
|
|
16730
17082
|
},
|
|
16731
|
-
text: `[Agent:${this.name}] - Only v2 models are allowed when an array of models is provided`
|
|
17083
|
+
text: `[Agent:${this.name}] - Only v2/v3 models are allowed when an array of models is provided`
|
|
16732
17084
|
});
|
|
16733
17085
|
this.logger.trackException(mastraError);
|
|
16734
17086
|
this.logger.error(mastraError.toString());
|
|
16735
17087
|
throw mastraError;
|
|
16736
17088
|
}
|
|
17089
|
+
let headers;
|
|
17090
|
+
if (resolvedModel instanceof chunkGXMJ5URG_cjs.ModelRouterLanguageModel) {
|
|
17091
|
+
headers = resolvedModel.config?.headers;
|
|
17092
|
+
}
|
|
16737
17093
|
return [
|
|
16738
17094
|
{
|
|
16739
17095
|
id: "main",
|
|
16740
|
-
// TODO fix type check
|
|
16741
17096
|
model: resolvedModel,
|
|
16742
17097
|
maxRetries: this.maxRetries ?? 0,
|
|
16743
|
-
enabled: true
|
|
17098
|
+
enabled: true,
|
|
17099
|
+
headers
|
|
16744
17100
|
}
|
|
16745
17101
|
];
|
|
16746
17102
|
}
|
|
16747
17103
|
const models = await Promise.all(
|
|
16748
17104
|
this.model.map(async (modelConfig) => {
|
|
16749
17105
|
const model2 = await this.resolveModelConfig(modelConfig.model, requestContext);
|
|
16750
|
-
if (!
|
|
16751
|
-
const mastraError = new
|
|
17106
|
+
if (!isSupportedLanguageModel(model2)) {
|
|
17107
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
16752
17108
|
id: "AGENT_PREPARE_MODELS_INCOMPATIBLE_WITH_MODEL_ARRAY_V1",
|
|
16753
17109
|
domain: "AGENT" /* AGENT */,
|
|
16754
17110
|
category: "USER" /* USER */,
|
|
16755
17111
|
details: {
|
|
16756
17112
|
agentName: this.name
|
|
16757
17113
|
},
|
|
16758
|
-
text: `[Agent:${this.name}] - Only v2 models are allowed when an array of models is provided`
|
|
17114
|
+
text: `[Agent:${this.name}] - Only v2/v3 models are allowed when an array of models is provided`
|
|
16759
17115
|
});
|
|
16760
17116
|
this.logger.trackException(mastraError);
|
|
16761
17117
|
this.logger.error(mastraError.toString());
|
|
@@ -16763,7 +17119,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16763
17119
|
}
|
|
16764
17120
|
const modelId = modelConfig.id || model2.modelId;
|
|
16765
17121
|
if (!modelId) {
|
|
16766
|
-
const mastraError = new
|
|
17122
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
16767
17123
|
id: "AGENT_PREPARE_MODELS_MISSING_MODEL_ID",
|
|
16768
17124
|
domain: "AGENT" /* AGENT */,
|
|
16769
17125
|
category: "USER" /* USER */,
|
|
@@ -16776,11 +17132,16 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16776
17132
|
this.logger.error(mastraError.toString());
|
|
16777
17133
|
throw mastraError;
|
|
16778
17134
|
}
|
|
17135
|
+
let headers;
|
|
17136
|
+
if (model2 instanceof chunkGXMJ5URG_cjs.ModelRouterLanguageModel) {
|
|
17137
|
+
headers = model2.config?.headers;
|
|
17138
|
+
}
|
|
16779
17139
|
return {
|
|
16780
17140
|
id: modelId,
|
|
16781
17141
|
model: model2,
|
|
16782
17142
|
maxRetries: modelConfig.maxRetries ?? 0,
|
|
16783
|
-
enabled: modelConfig.enabled ?? true
|
|
17143
|
+
enabled: modelConfig.enabled ?? true,
|
|
17144
|
+
headers
|
|
16784
17145
|
};
|
|
16785
17146
|
})
|
|
16786
17147
|
);
|
|
@@ -16790,7 +17151,11 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16790
17151
|
* Executes the agent call, handling tools, memory, and streaming.
|
|
16791
17152
|
* @internal
|
|
16792
17153
|
*/
|
|
16793
|
-
async #execute({
|
|
17154
|
+
async #execute({
|
|
17155
|
+
methodType,
|
|
17156
|
+
resumeContext,
|
|
17157
|
+
...options
|
|
17158
|
+
}) {
|
|
16794
17159
|
const existingSnapshot = resumeContext?.snapshot;
|
|
16795
17160
|
let snapshotMemoryInfo;
|
|
16796
17161
|
if (existingSnapshot) {
|
|
@@ -16828,7 +17193,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16828
17193
|
const targetProvider = structuredOutputModel.provider;
|
|
16829
17194
|
const targetModelId = structuredOutputModel.modelId;
|
|
16830
17195
|
if (targetProvider.includes("openai") || targetModelId.includes("openai")) {
|
|
16831
|
-
if (
|
|
17196
|
+
if (chunkBC2VKOH4_cjs.isZodType(options.structuredOutput.schema) && targetModelId) {
|
|
16832
17197
|
const modelInfo = {
|
|
16833
17198
|
provider: targetProvider,
|
|
16834
17199
|
modelId: targetModelId,
|
|
@@ -16847,13 +17212,14 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
16847
17212
|
}
|
|
16848
17213
|
const runId = options.runId || this.#mastra?.generateId() || crypto2.randomUUID();
|
|
16849
17214
|
const instructions = options.instructions || await this.getInstructions({ requestContext });
|
|
16850
|
-
const agentSpan =
|
|
17215
|
+
const agentSpan = chunkO2CAMK4A_cjs.getOrCreateSpan({
|
|
16851
17216
|
type: "agent_run" /* AGENT_RUN */,
|
|
16852
17217
|
name: `agent run: '${this.id}'`,
|
|
17218
|
+
entityType: "agent" /* AGENT */,
|
|
17219
|
+
entityId: this.id,
|
|
17220
|
+
entityName: this.name,
|
|
16853
17221
|
input: options.messages,
|
|
16854
17222
|
attributes: {
|
|
16855
|
-
agentId: this.id,
|
|
16856
|
-
agentName: this.name,
|
|
16857
17223
|
conversationId: threadFromArgs?.id,
|
|
16858
17224
|
instructions: this.#convertInstructionsToString(instructions)
|
|
16859
17225
|
},
|
|
@@ -17023,10 +17389,10 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
17023
17389
|
}
|
|
17024
17390
|
}
|
|
17025
17391
|
} catch (e) {
|
|
17026
|
-
if (e instanceof
|
|
17392
|
+
if (e instanceof chunk4U7ZLI36_cjs.MastraError) {
|
|
17027
17393
|
throw e;
|
|
17028
17394
|
}
|
|
17029
|
-
const mastraError = new
|
|
17395
|
+
const mastraError = new chunk4U7ZLI36_cjs.MastraError(
|
|
17030
17396
|
{
|
|
17031
17397
|
id: "AGENT_MEMORY_PERSIST_RESPONSE_MESSAGES_FAILED",
|
|
17032
17398
|
domain: "AGENT" /* AGENT */,
|
|
@@ -17137,14 +17503,14 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
17137
17503
|
requestContext: mergedOptions.requestContext
|
|
17138
17504
|
});
|
|
17139
17505
|
const modelInfo = llm.getModel();
|
|
17140
|
-
if (modelInfo
|
|
17506
|
+
if (!isSupportedLanguageModel(modelInfo)) {
|
|
17141
17507
|
const modelId = modelInfo.modelId || "unknown";
|
|
17142
17508
|
const provider = modelInfo.provider || "unknown";
|
|
17143
|
-
throw new
|
|
17509
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
17144
17510
|
id: "AGENT_GENERATE_V1_MODEL_NOT_SUPPORTED",
|
|
17145
17511
|
domain: "AGENT" /* AGENT */,
|
|
17146
17512
|
category: "USER" /* USER */,
|
|
17147
|
-
text: `Agent "${this.name}" is using AI SDK v4 model (${provider}:${modelId}) which is not compatible with generate(). Please use AI SDK v5 models or call the generateLegacy() method instead. See https://mastra.ai/en/docs/streaming/overview for more information.`,
|
|
17513
|
+
text: `Agent "${this.name}" is using AI SDK v4 model (${provider}:${modelId}) which is not compatible with generate(). Please use AI SDK v5+ models or call the generateLegacy() method instead. See https://mastra.ai/en/docs/streaming/overview for more information.`,
|
|
17148
17514
|
details: {
|
|
17149
17515
|
agentName: this.name,
|
|
17150
17516
|
modelId,
|
|
@@ -17163,7 +17529,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
17163
17529
|
const result = await this.#execute(executeOptions);
|
|
17164
17530
|
if (result.status !== "success") {
|
|
17165
17531
|
if (result.status === "failed") {
|
|
17166
|
-
throw new
|
|
17532
|
+
throw new chunk4U7ZLI36_cjs.MastraError(
|
|
17167
17533
|
{
|
|
17168
17534
|
id: "AGENT_GENERATE_FAILED",
|
|
17169
17535
|
domain: "AGENT" /* AGENT */,
|
|
@@ -17173,7 +17539,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
17173
17539
|
result.error
|
|
17174
17540
|
);
|
|
17175
17541
|
}
|
|
17176
|
-
throw new
|
|
17542
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
17177
17543
|
id: "AGENT_GENERATE_UNKNOWN_ERROR",
|
|
17178
17544
|
domain: "AGENT" /* AGENT */,
|
|
17179
17545
|
category: "USER" /* USER */,
|
|
@@ -17199,14 +17565,14 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
17199
17565
|
requestContext: mergedOptions.requestContext
|
|
17200
17566
|
});
|
|
17201
17567
|
const modelInfo = llm.getModel();
|
|
17202
|
-
if (modelInfo
|
|
17568
|
+
if (!isSupportedLanguageModel(modelInfo)) {
|
|
17203
17569
|
const modelId = modelInfo.modelId || "unknown";
|
|
17204
17570
|
const provider = modelInfo.provider || "unknown";
|
|
17205
|
-
throw new
|
|
17571
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
17206
17572
|
id: "AGENT_STREAM_V1_MODEL_NOT_SUPPORTED",
|
|
17207
17573
|
domain: "AGENT" /* AGENT */,
|
|
17208
17574
|
category: "USER" /* USER */,
|
|
17209
|
-
text: `Agent "${this.name}" is using AI SDK v4 model (${provider}:${modelId}) which is not compatible with stream(). Please use AI SDK v5 models or call the streamLegacy() method instead. See https://mastra.ai/en/docs/streaming/overview for more information.`,
|
|
17575
|
+
text: `Agent "${this.name}" is using AI SDK v4 model (${provider}:${modelId}) which is not compatible with stream(). Please use AI SDK v5+ models or call the streamLegacy() method instead. See https://mastra.ai/en/docs/streaming/overview for more information.`,
|
|
17210
17576
|
details: {
|
|
17211
17577
|
agentName: this.name,
|
|
17212
17578
|
modelId,
|
|
@@ -17225,7 +17591,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
17225
17591
|
const result = await this.#execute(executeOptions);
|
|
17226
17592
|
if (result.status !== "success") {
|
|
17227
17593
|
if (result.status === "failed") {
|
|
17228
|
-
throw new
|
|
17594
|
+
throw new chunk4U7ZLI36_cjs.MastraError(
|
|
17229
17595
|
{
|
|
17230
17596
|
id: "AGENT_STREAM_FAILED",
|
|
17231
17597
|
domain: "AGENT" /* AGENT */,
|
|
@@ -17235,7 +17601,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
17235
17601
|
result.error
|
|
17236
17602
|
);
|
|
17237
17603
|
}
|
|
17238
|
-
throw new
|
|
17604
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
17239
17605
|
id: "AGENT_STREAM_UNKNOWN_ERROR",
|
|
17240
17606
|
domain: "AGENT" /* AGENT */,
|
|
17241
17607
|
category: "USER" /* USER */,
|
|
@@ -17268,15 +17634,16 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
17268
17634
|
const llm = await this.getLLM({
|
|
17269
17635
|
requestContext: mergedStreamOptions.requestContext
|
|
17270
17636
|
});
|
|
17271
|
-
if (llm.getModel()
|
|
17272
|
-
throw new
|
|
17637
|
+
if (!isSupportedLanguageModel(llm.getModel())) {
|
|
17638
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
17273
17639
|
id: "AGENT_STREAM_V1_MODEL_NOT_SUPPORTED",
|
|
17274
17640
|
domain: "AGENT" /* AGENT */,
|
|
17275
17641
|
category: "USER" /* USER */,
|
|
17276
17642
|
text: "V1 models are not supported for stream. Please use streamLegacy instead."
|
|
17277
17643
|
});
|
|
17278
17644
|
}
|
|
17279
|
-
const
|
|
17645
|
+
const workflowsStore = await this.#mastra?.getStorage()?.getStore("workflows");
|
|
17646
|
+
const existingSnapshot = await workflowsStore?.loadWorkflowSnapshot({
|
|
17280
17647
|
workflowName: "agentic-loop",
|
|
17281
17648
|
runId: streamOptions?.runId ?? ""
|
|
17282
17649
|
});
|
|
@@ -17291,7 +17658,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
17291
17658
|
});
|
|
17292
17659
|
if (result.status !== "success") {
|
|
17293
17660
|
if (result.status === "failed") {
|
|
17294
|
-
throw new
|
|
17661
|
+
throw new chunk4U7ZLI36_cjs.MastraError(
|
|
17295
17662
|
{
|
|
17296
17663
|
id: "AGENT_STREAM_FAILED",
|
|
17297
17664
|
domain: "AGENT" /* AGENT */,
|
|
@@ -17301,7 +17668,7 @@ var Agent = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
17301
17668
|
result.error
|
|
17302
17669
|
);
|
|
17303
17670
|
}
|
|
17304
|
-
throw new
|
|
17671
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
17305
17672
|
id: "AGENT_STREAM_UNKNOWN_ERROR",
|
|
17306
17673
|
domain: "AGENT" /* AGENT */,
|
|
17307
17674
|
category: "USER" /* USER */,
|
|
@@ -17508,7 +17875,7 @@ var ModerationProcessor = class _ModerationProcessor {
|
|
|
17508
17875
|
reason: z8__default.default.string().describe("Brief explanation of why content was flagged").nullable()
|
|
17509
17876
|
});
|
|
17510
17877
|
let response;
|
|
17511
|
-
if (model
|
|
17878
|
+
if (isSupportedLanguageModel(model)) {
|
|
17512
17879
|
response = await this.moderationAgent.generate(prompt, {
|
|
17513
17880
|
structuredOutput: {
|
|
17514
17881
|
schema,
|
|
@@ -17728,7 +18095,7 @@ var PromptInjectionDetector = class _PromptInjectionDetector {
|
|
|
17728
18095
|
rewritten_content: z8__default.default.string().describe("The rewritten content that neutralizes the attack while preserving any legitimate user intent").nullable()
|
|
17729
18096
|
});
|
|
17730
18097
|
}
|
|
17731
|
-
if (model
|
|
18098
|
+
if (isSupportedLanguageModel(model)) {
|
|
17732
18099
|
response = await this.detectionAgent.generate(prompt, {
|
|
17733
18100
|
structuredOutput: {
|
|
17734
18101
|
schema,
|
|
@@ -17976,7 +18343,7 @@ var PIIDetector = class _PIIDetector {
|
|
|
17976
18343
|
redacted_content: z8__default.default.string().describe("The content with all PII redacted according to the redaction method").nullable()
|
|
17977
18344
|
}) : baseSchema;
|
|
17978
18345
|
let response;
|
|
17979
|
-
if (model
|
|
18346
|
+
if (isSupportedLanguageModel(model)) {
|
|
17980
18347
|
response = await this.detectionAgent.generate(prompt, {
|
|
17981
18348
|
structuredOutput: {
|
|
17982
18349
|
schema,
|
|
@@ -18438,7 +18805,7 @@ var LanguageDetector = class _LanguageDetector {
|
|
|
18438
18805
|
const schema = this.strategy === "translate" ? baseSchema.extend({
|
|
18439
18806
|
translated_text: z8__default.default.string().describe("Translated text").nullable()
|
|
18440
18807
|
}) : baseSchema;
|
|
18441
|
-
if (model
|
|
18808
|
+
if (isSupportedLanguageModel(model)) {
|
|
18442
18809
|
response = await this.detectionAgent.generate(prompt, {
|
|
18443
18810
|
structuredOutput: {
|
|
18444
18811
|
schema
|
|
@@ -19116,7 +19483,7 @@ var SystemPromptScrubber = class {
|
|
|
19116
19483
|
const schema = this.strategy === "redact" ? baseSchema.extend({
|
|
19117
19484
|
redacted_content: z8.z.string().describe("Redacted content").nullable()
|
|
19118
19485
|
}) : baseSchema;
|
|
19119
|
-
if (model
|
|
19486
|
+
if (isSupportedLanguageModel(model)) {
|
|
19120
19487
|
result = await this.detectionAgent.generate(text, {
|
|
19121
19488
|
structuredOutput: {
|
|
19122
19489
|
schema,
|
|
@@ -19344,6 +19711,50 @@ var ToolCallFilter = class {
|
|
|
19344
19711
|
}
|
|
19345
19712
|
};
|
|
19346
19713
|
|
|
19714
|
+
// src/memory/working-memory-utils.ts
|
|
19715
|
+
var WORKING_MEMORY_START_TAG = "<working_memory>";
|
|
19716
|
+
var WORKING_MEMORY_END_TAG = "</working_memory>";
|
|
19717
|
+
function extractWorkingMemoryTags(text) {
|
|
19718
|
+
const results = [];
|
|
19719
|
+
let pos = 0;
|
|
19720
|
+
while (pos < text.length) {
|
|
19721
|
+
const start = text.indexOf(WORKING_MEMORY_START_TAG, pos);
|
|
19722
|
+
if (start === -1) break;
|
|
19723
|
+
const end = text.indexOf(WORKING_MEMORY_END_TAG, start + WORKING_MEMORY_START_TAG.length);
|
|
19724
|
+
if (end === -1) break;
|
|
19725
|
+
results.push(text.substring(start, end + WORKING_MEMORY_END_TAG.length));
|
|
19726
|
+
pos = end + WORKING_MEMORY_END_TAG.length;
|
|
19727
|
+
}
|
|
19728
|
+
return results.length > 0 ? results : null;
|
|
19729
|
+
}
|
|
19730
|
+
function removeWorkingMemoryTags(text) {
|
|
19731
|
+
let result = "";
|
|
19732
|
+
let pos = 0;
|
|
19733
|
+
while (pos < text.length) {
|
|
19734
|
+
const start = text.indexOf(WORKING_MEMORY_START_TAG, pos);
|
|
19735
|
+
if (start === -1) {
|
|
19736
|
+
result += text.substring(pos);
|
|
19737
|
+
break;
|
|
19738
|
+
}
|
|
19739
|
+
result += text.substring(pos, start);
|
|
19740
|
+
const end = text.indexOf(WORKING_MEMORY_END_TAG, start + WORKING_MEMORY_START_TAG.length);
|
|
19741
|
+
if (end === -1) {
|
|
19742
|
+
result += text.substring(start);
|
|
19743
|
+
break;
|
|
19744
|
+
}
|
|
19745
|
+
pos = end + WORKING_MEMORY_END_TAG.length;
|
|
19746
|
+
}
|
|
19747
|
+
return result;
|
|
19748
|
+
}
|
|
19749
|
+
function extractWorkingMemoryContent(text) {
|
|
19750
|
+
const start = text.indexOf(WORKING_MEMORY_START_TAG);
|
|
19751
|
+
if (start === -1) return null;
|
|
19752
|
+
const contentStart = start + WORKING_MEMORY_START_TAG.length;
|
|
19753
|
+
const end = text.indexOf(WORKING_MEMORY_END_TAG, contentStart);
|
|
19754
|
+
if (end === -1) return null;
|
|
19755
|
+
return text.substring(contentStart, end);
|
|
19756
|
+
}
|
|
19757
|
+
|
|
19347
19758
|
// src/processors/memory/message-history.ts
|
|
19348
19759
|
var MessageHistory = class {
|
|
19349
19760
|
id = "message-history";
|
|
@@ -19386,25 +19797,43 @@ var MessageHistory = class {
|
|
|
19386
19797
|
}
|
|
19387
19798
|
return messageList;
|
|
19388
19799
|
}
|
|
19389
|
-
|
|
19800
|
+
/**
|
|
19801
|
+
* Filters messages before persisting to storage:
|
|
19802
|
+
* 1. Removes incomplete tool calls (state === 'call' or 'partial-call')
|
|
19803
|
+
* 2. Removes updateWorkingMemory tool invocations (hide args from message history)
|
|
19804
|
+
* 3. Strips <working_memory> tags from text content
|
|
19805
|
+
*/
|
|
19806
|
+
filterMessagesForPersistence(messages) {
|
|
19390
19807
|
return messages.map((m) => {
|
|
19391
|
-
|
|
19392
|
-
|
|
19393
|
-
|
|
19394
|
-
|
|
19395
|
-
|
|
19396
|
-
|
|
19397
|
-
|
|
19398
|
-
|
|
19399
|
-
|
|
19400
|
-
|
|
19401
|
-
|
|
19808
|
+
const newMessage = { ...m };
|
|
19809
|
+
if (m.content && typeof m.content === "object" && !Array.isArray(m.content)) {
|
|
19810
|
+
newMessage.content = { ...m.content };
|
|
19811
|
+
}
|
|
19812
|
+
if (typeof newMessage.content?.content === "string" && newMessage.content.content.length > 0) {
|
|
19813
|
+
newMessage.content.content = removeWorkingMemoryTags(newMessage.content.content).trim();
|
|
19814
|
+
}
|
|
19815
|
+
if (Array.isArray(newMessage.content?.parts)) {
|
|
19816
|
+
newMessage.content.parts = newMessage.content.parts.map((p) => {
|
|
19817
|
+
if (p.type === `tool-invocation` && (p.toolInvocation.state === `call` || p.toolInvocation.state === `partial-call`)) {
|
|
19818
|
+
return null;
|
|
19402
19819
|
}
|
|
19403
|
-
|
|
19404
|
-
|
|
19405
|
-
|
|
19820
|
+
if (p.type === `tool-invocation` && p.toolInvocation.toolName === `updateWorkingMemory`) {
|
|
19821
|
+
return null;
|
|
19822
|
+
}
|
|
19823
|
+
if (p.type === `text`) {
|
|
19824
|
+
const text = typeof p.text === "string" ? p.text : "";
|
|
19825
|
+
return {
|
|
19826
|
+
...p,
|
|
19827
|
+
text: removeWorkingMemoryTags(text).trim()
|
|
19828
|
+
};
|
|
19829
|
+
}
|
|
19830
|
+
return p;
|
|
19831
|
+
}).filter((p) => Boolean(p));
|
|
19832
|
+
if (newMessage.content.parts.length === 0) {
|
|
19833
|
+
return null;
|
|
19834
|
+
}
|
|
19406
19835
|
}
|
|
19407
|
-
return
|
|
19836
|
+
return newMessage;
|
|
19408
19837
|
}).filter((m) => Boolean(m));
|
|
19409
19838
|
}
|
|
19410
19839
|
async processOutputResult(args) {
|
|
@@ -19421,7 +19850,7 @@ var MessageHistory = class {
|
|
|
19421
19850
|
if (messagesToSave.length === 0) {
|
|
19422
19851
|
return messageList;
|
|
19423
19852
|
}
|
|
19424
|
-
const filtered = this.
|
|
19853
|
+
const filtered = this.filterMessagesForPersistence(messagesToSave);
|
|
19425
19854
|
await this.storage.saveMessages({ messages: filtered });
|
|
19426
19855
|
const thread = await this.storage.getThreadById({ threadId });
|
|
19427
19856
|
if (thread) {
|
|
@@ -19685,7 +20114,7 @@ var SemanticRecall = class {
|
|
|
19685
20114
|
*/
|
|
19686
20115
|
formatCrossThreadMessages(messages, currentThreadId) {
|
|
19687
20116
|
let result = ``;
|
|
19688
|
-
const v1Messages = new
|
|
20117
|
+
const v1Messages = new chunkEMLEZXTQ_cjs.MessageList().add(messages, "memory").get.all.v1();
|
|
19689
20118
|
let lastYmd = null;
|
|
19690
20119
|
for (const msg of v1Messages) {
|
|
19691
20120
|
const date = msg.createdAt;
|
|
@@ -20035,6 +20464,7 @@ var MastraMemory = class extends chunkDGV2FWB4_cjs.MastraBase {
|
|
|
20035
20464
|
_storage;
|
|
20036
20465
|
vector;
|
|
20037
20466
|
embedder;
|
|
20467
|
+
embedderOptions;
|
|
20038
20468
|
threadConfig = { ...memoryDefaultOptions };
|
|
20039
20469
|
#mastra;
|
|
20040
20470
|
constructor(config) {
|
|
@@ -20090,7 +20520,7 @@ https://mastra.ai/en/docs/memory/semantic-recall`
|
|
|
20090
20520
|
);
|
|
20091
20521
|
}
|
|
20092
20522
|
if (typeof config.embedder === "string") {
|
|
20093
|
-
this.embedder = new
|
|
20523
|
+
this.embedder = new chunkGXMJ5URG_cjs.ModelRouterEmbeddingModel(config.embedder);
|
|
20094
20524
|
} else {
|
|
20095
20525
|
this.embedder = config.embedder;
|
|
20096
20526
|
}
|
|
@@ -20125,7 +20555,11 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20125
20555
|
this.vector = vector;
|
|
20126
20556
|
}
|
|
20127
20557
|
setEmbedder(embedder) {
|
|
20128
|
-
|
|
20558
|
+
if (typeof embedder === "string") {
|
|
20559
|
+
this.embedder = new chunkGXMJ5URG_cjs.ModelRouterEmbeddingModel(embedder);
|
|
20560
|
+
} else {
|
|
20561
|
+
this.embedder = embedder;
|
|
20562
|
+
}
|
|
20129
20563
|
}
|
|
20130
20564
|
/**
|
|
20131
20565
|
* Get a system message to inject into the conversation.
|
|
@@ -20186,7 +20620,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20186
20620
|
"The threads.generateTitle option has been moved. Use the top-level generateTitle option instead."
|
|
20187
20621
|
);
|
|
20188
20622
|
}
|
|
20189
|
-
const mergedConfig =
|
|
20623
|
+
const mergedConfig = chunkBC2VKOH4_cjs.deepMerge(this.threadConfig, config || {});
|
|
20190
20624
|
if (typeof config?.workingMemory === "object" && config.workingMemory?.schema && typeof mergedConfig.workingMemory === "object") {
|
|
20191
20625
|
mergedConfig.workingMemory.schema = config.workingMemory.schema;
|
|
20192
20626
|
}
|
|
@@ -20247,15 +20681,16 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20247
20681
|
* @param configuredProcessors - Processors already configured by the user (for deduplication)
|
|
20248
20682
|
* @returns Array of input processors configured for this memory instance
|
|
20249
20683
|
*/
|
|
20250
|
-
getInputProcessors(configuredProcessors = [], context) {
|
|
20684
|
+
async getInputProcessors(configuredProcessors = [], context) {
|
|
20685
|
+
const memoryStore = await this.storage.getStore("memory");
|
|
20251
20686
|
const processors = [];
|
|
20252
20687
|
const memoryContext = context?.get("MastraMemory");
|
|
20253
20688
|
const runtimeMemoryConfig = memoryContext?.memoryConfig;
|
|
20254
20689
|
const effectiveConfig = runtimeMemoryConfig ? this.getMergedThreadConfig(runtimeMemoryConfig) : this.threadConfig;
|
|
20255
20690
|
const isWorkingMemoryEnabled = typeof effectiveConfig.workingMemory === "object" && effectiveConfig.workingMemory.enabled !== false;
|
|
20256
20691
|
if (isWorkingMemoryEnabled) {
|
|
20257
|
-
if (!
|
|
20258
|
-
throw new
|
|
20692
|
+
if (!memoryStore)
|
|
20693
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
20259
20694
|
category: "USER",
|
|
20260
20695
|
domain: "STORAGE" /* STORAGE */,
|
|
20261
20696
|
id: "WORKING_MEMORY_MISSING_STORAGE_ADAPTER",
|
|
@@ -20272,7 +20707,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20272
20707
|
}
|
|
20273
20708
|
processors.push(
|
|
20274
20709
|
new WorkingMemory({
|
|
20275
|
-
storage:
|
|
20710
|
+
storage: memoryStore,
|
|
20276
20711
|
template,
|
|
20277
20712
|
scope: typeof effectiveConfig.workingMemory === "object" ? effectiveConfig.workingMemory.scope : void 0,
|
|
20278
20713
|
useVNext: typeof effectiveConfig.workingMemory === "object" && "version" in effectiveConfig.workingMemory && effectiveConfig.workingMemory.version === "vnext",
|
|
@@ -20283,8 +20718,8 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20283
20718
|
}
|
|
20284
20719
|
const lastMessages = effectiveConfig.lastMessages;
|
|
20285
20720
|
if (lastMessages) {
|
|
20286
|
-
if (!
|
|
20287
|
-
throw new
|
|
20721
|
+
if (!memoryStore)
|
|
20722
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
20288
20723
|
category: "USER",
|
|
20289
20724
|
domain: "STORAGE" /* STORAGE */,
|
|
20290
20725
|
id: "MESSAGE_HISTORY_MISSING_STORAGE_ADAPTER",
|
|
@@ -20294,29 +20729,29 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20294
20729
|
if (!hasMessageHistory) {
|
|
20295
20730
|
processors.push(
|
|
20296
20731
|
new MessageHistory({
|
|
20297
|
-
storage:
|
|
20732
|
+
storage: memoryStore,
|
|
20298
20733
|
lastMessages: typeof lastMessages === "number" ? lastMessages : void 0
|
|
20299
20734
|
})
|
|
20300
20735
|
);
|
|
20301
20736
|
}
|
|
20302
20737
|
}
|
|
20303
20738
|
if (effectiveConfig.semanticRecall) {
|
|
20304
|
-
if (!
|
|
20305
|
-
throw new
|
|
20739
|
+
if (!memoryStore)
|
|
20740
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
20306
20741
|
category: "USER",
|
|
20307
20742
|
domain: "STORAGE" /* STORAGE */,
|
|
20308
20743
|
id: "SEMANTIC_RECALL_MISSING_STORAGE_ADAPTER",
|
|
20309
20744
|
text: "Using Mastra Memory semantic recall requires a storage adapter but no attached adapter was detected."
|
|
20310
20745
|
});
|
|
20311
20746
|
if (!this.vector)
|
|
20312
|
-
throw new
|
|
20747
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
20313
20748
|
category: "USER",
|
|
20314
20749
|
domain: "MASTRA_VECTOR" /* MASTRA_VECTOR */,
|
|
20315
20750
|
id: "SEMANTIC_RECALL_MISSING_VECTOR_ADAPTER",
|
|
20316
20751
|
text: "Using Mastra Memory semantic recall requires a vector adapter but no attached adapter was detected."
|
|
20317
20752
|
});
|
|
20318
20753
|
if (!this.embedder)
|
|
20319
|
-
throw new
|
|
20754
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
20320
20755
|
category: "USER",
|
|
20321
20756
|
domain: "MASTRA_VECTOR" /* MASTRA_VECTOR */,
|
|
20322
20757
|
id: "SEMANTIC_RECALL_MISSING_EMBEDDER",
|
|
@@ -20328,7 +20763,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20328
20763
|
const indexName = this.getEmbeddingIndexName();
|
|
20329
20764
|
processors.push(
|
|
20330
20765
|
new SemanticRecall({
|
|
20331
|
-
storage:
|
|
20766
|
+
storage: memoryStore,
|
|
20332
20767
|
vector: this.vector,
|
|
20333
20768
|
embedder: this.embedder,
|
|
20334
20769
|
indexName,
|
|
@@ -20345,7 +20780,8 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20345
20780
|
* @param configuredProcessors - Processors already configured by the user (for deduplication)
|
|
20346
20781
|
* @returns Array of output processors configured for this memory instance
|
|
20347
20782
|
*/
|
|
20348
|
-
getOutputProcessors(configuredProcessors = [], context) {
|
|
20783
|
+
async getOutputProcessors(configuredProcessors = [], context) {
|
|
20784
|
+
const memoryStore = await this.storage.getStore("memory");
|
|
20349
20785
|
const processors = [];
|
|
20350
20786
|
const memoryContext = context?.get("MastraMemory");
|
|
20351
20787
|
const runtimeMemoryConfig = memoryContext?.memoryConfig;
|
|
@@ -20354,22 +20790,22 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20354
20790
|
return [];
|
|
20355
20791
|
}
|
|
20356
20792
|
if (effectiveConfig.semanticRecall) {
|
|
20357
|
-
if (!
|
|
20358
|
-
throw new
|
|
20793
|
+
if (!memoryStore)
|
|
20794
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
20359
20795
|
category: "USER",
|
|
20360
20796
|
domain: "STORAGE" /* STORAGE */,
|
|
20361
20797
|
id: "SEMANTIC_RECALL_MISSING_STORAGE_ADAPTER",
|
|
20362
20798
|
text: "Using Mastra Memory semantic recall requires a storage adapter but no attached adapter was detected."
|
|
20363
20799
|
});
|
|
20364
20800
|
if (!this.vector)
|
|
20365
|
-
throw new
|
|
20801
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
20366
20802
|
category: "USER",
|
|
20367
20803
|
domain: "MASTRA_VECTOR" /* MASTRA_VECTOR */,
|
|
20368
20804
|
id: "SEMANTIC_RECALL_MISSING_VECTOR_ADAPTER",
|
|
20369
20805
|
text: "Using Mastra Memory semantic recall requires a vector adapter but no attached adapter was detected."
|
|
20370
20806
|
});
|
|
20371
20807
|
if (!this.embedder)
|
|
20372
|
-
throw new
|
|
20808
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
20373
20809
|
category: "USER",
|
|
20374
20810
|
domain: "MASTRA_VECTOR" /* MASTRA_VECTOR */,
|
|
20375
20811
|
id: "SEMANTIC_RECALL_MISSING_EMBEDDER",
|
|
@@ -20381,7 +20817,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20381
20817
|
const indexName = this.getEmbeddingIndexName();
|
|
20382
20818
|
processors.push(
|
|
20383
20819
|
new SemanticRecall({
|
|
20384
|
-
storage:
|
|
20820
|
+
storage: memoryStore,
|
|
20385
20821
|
vector: this.vector,
|
|
20386
20822
|
embedder: this.embedder,
|
|
20387
20823
|
indexName,
|
|
@@ -20392,8 +20828,8 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20392
20828
|
}
|
|
20393
20829
|
const lastMessages = effectiveConfig.lastMessages;
|
|
20394
20830
|
if (lastMessages) {
|
|
20395
|
-
if (!
|
|
20396
|
-
throw new
|
|
20831
|
+
if (!memoryStore)
|
|
20832
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
20397
20833
|
category: "USER",
|
|
20398
20834
|
domain: "STORAGE" /* STORAGE */,
|
|
20399
20835
|
id: "MESSAGE_HISTORY_MISSING_STORAGE_ADAPTER",
|
|
@@ -20403,7 +20839,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
20403
20839
|
if (!hasMessageHistory) {
|
|
20404
20840
|
processors.push(
|
|
20405
20841
|
new MessageHistory({
|
|
20406
|
-
storage:
|
|
20842
|
+
storage: memoryStore,
|
|
20407
20843
|
lastMessages: typeof lastMessages === "number" ? lastMessages : void 0
|
|
20408
20844
|
})
|
|
20409
20845
|
);
|
|
@@ -20422,7 +20858,7 @@ var MockMemory = class extends MastraMemory {
|
|
|
20422
20858
|
} = {}) {
|
|
20423
20859
|
super({
|
|
20424
20860
|
name: "mock",
|
|
20425
|
-
storage: storage || new
|
|
20861
|
+
storage: storage || new chunkLOV5NNGK_cjs.InMemoryStore(),
|
|
20426
20862
|
options: {
|
|
20427
20863
|
workingMemory: enableWorkingMemory ? { enabled: true, template: workingMemoryTemplate } : void 0,
|
|
20428
20864
|
lastMessages: enableMessageHistory ? 10 : void 0
|
|
@@ -20430,22 +20866,39 @@ var MockMemory = class extends MastraMemory {
|
|
|
20430
20866
|
});
|
|
20431
20867
|
this._hasOwnStorage = true;
|
|
20432
20868
|
}
|
|
20869
|
+
async getMemoryStore() {
|
|
20870
|
+
const store = await this.storage.getStore("memory");
|
|
20871
|
+
if (!store) {
|
|
20872
|
+
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
20873
|
+
id: "MASTRA_MEMORY_STORAGE_NOT_AVAILABLE",
|
|
20874
|
+
domain: "MASTRA_MEMORY" /* MASTRA_MEMORY */,
|
|
20875
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
20876
|
+
text: "Memory storage is not supported by this storage adapter"
|
|
20877
|
+
});
|
|
20878
|
+
}
|
|
20879
|
+
return store;
|
|
20880
|
+
}
|
|
20433
20881
|
async getThreadById({ threadId }) {
|
|
20434
|
-
|
|
20882
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20883
|
+
return memoryStorage.getThreadById({ threadId });
|
|
20435
20884
|
}
|
|
20436
20885
|
async saveThread({ thread }) {
|
|
20437
|
-
|
|
20886
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20887
|
+
return memoryStorage.saveThread({ thread });
|
|
20438
20888
|
}
|
|
20439
20889
|
async saveMessages({
|
|
20440
20890
|
messages
|
|
20441
20891
|
}) {
|
|
20442
|
-
|
|
20892
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20893
|
+
return memoryStorage.saveMessages({ messages });
|
|
20443
20894
|
}
|
|
20444
20895
|
async listThreadsByResourceId(args) {
|
|
20445
|
-
|
|
20896
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20897
|
+
return memoryStorage.listThreadsByResourceId(args);
|
|
20446
20898
|
}
|
|
20447
20899
|
async recall(args) {
|
|
20448
|
-
const
|
|
20900
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20901
|
+
const result = await memoryStorage.listMessages({
|
|
20449
20902
|
threadId: args.threadId,
|
|
20450
20903
|
resourceId: args.resourceId,
|
|
20451
20904
|
perPage: args.perPage,
|
|
@@ -20457,11 +20910,13 @@ var MockMemory = class extends MastraMemory {
|
|
|
20457
20910
|
return result;
|
|
20458
20911
|
}
|
|
20459
20912
|
async deleteThread(threadId) {
|
|
20460
|
-
|
|
20913
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20914
|
+
return memoryStorage.deleteThread({ threadId });
|
|
20461
20915
|
}
|
|
20462
20916
|
async deleteMessages(messageIds) {
|
|
20917
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20463
20918
|
const ids = Array.isArray(messageIds) ? messageIds?.map((item) => typeof item === "string" ? item : item.id) : [messageIds];
|
|
20464
|
-
return
|
|
20919
|
+
return memoryStorage.deleteMessages(ids);
|
|
20465
20920
|
}
|
|
20466
20921
|
async getWorkingMemory({
|
|
20467
20922
|
threadId,
|
|
@@ -20478,12 +20933,17 @@ var MockMemory = class extends MastraMemory {
|
|
|
20478
20933
|
if (!id) {
|
|
20479
20934
|
return null;
|
|
20480
20935
|
}
|
|
20481
|
-
const
|
|
20936
|
+
const memoryStorage = await this.getMemoryStore();
|
|
20937
|
+
const resource = await memoryStorage.getResourceById({ resourceId: id });
|
|
20482
20938
|
return resource?.workingMemory || null;
|
|
20483
20939
|
}
|
|
20484
20940
|
listTools(_config) {
|
|
20941
|
+
const mergedConfig = this.getMergedThreadConfig(_config);
|
|
20942
|
+
if (!mergedConfig.workingMemory?.enabled) {
|
|
20943
|
+
return {};
|
|
20944
|
+
}
|
|
20485
20945
|
return {
|
|
20486
|
-
updateWorkingMemory:
|
|
20946
|
+
updateWorkingMemory: chunk6HJFCSJ4_cjs.createTool({
|
|
20487
20947
|
id: "update-working-memory",
|
|
20488
20948
|
description: `Update the working memory with new information. Any data not included will be overwritten.`,
|
|
20489
20949
|
inputSchema: z8__default.default.object({ memory: z8__default.default.string() }),
|
|
@@ -20566,7 +21026,8 @@ var MockMemory = class extends MastraMemory {
|
|
|
20566
21026
|
if (!id) {
|
|
20567
21027
|
throw new Error(`Cannot update working memory: ${scope} ID is required`);
|
|
20568
21028
|
}
|
|
20569
|
-
await this.
|
|
21029
|
+
const memoryStorage = await this.getMemoryStore();
|
|
21030
|
+
await memoryStorage.updateResource({
|
|
20570
21031
|
resourceId: id,
|
|
20571
21032
|
workingMemory
|
|
20572
21033
|
});
|
|
@@ -20641,6 +21102,8 @@ exports.ToolCallFilter = ToolCallFilter;
|
|
|
20641
21102
|
exports.ToolInvocationPartSchema = ToolInvocationPartSchema;
|
|
20642
21103
|
exports.TripWire = TripWire;
|
|
20643
21104
|
exports.UnicodeNormalizer = UnicodeNormalizer;
|
|
21105
|
+
exports.WORKING_MEMORY_END_TAG = WORKING_MEMORY_END_TAG;
|
|
21106
|
+
exports.WORKING_MEMORY_START_TAG = WORKING_MEMORY_START_TAG;
|
|
20644
21107
|
exports.Workflow = Workflow;
|
|
20645
21108
|
exports.WorkflowRunOutput = WorkflowRunOutput;
|
|
20646
21109
|
exports.WorkingMemory = WorkingMemory;
|
|
@@ -20654,6 +21117,8 @@ exports.createDeprecationProxy = createDeprecationProxy;
|
|
|
20654
21117
|
exports.createStep = createStep;
|
|
20655
21118
|
exports.createTimeTravelExecutionParams = createTimeTravelExecutionParams;
|
|
20656
21119
|
exports.createWorkflow = createWorkflow;
|
|
21120
|
+
exports.extractWorkingMemoryContent = extractWorkingMemoryContent;
|
|
21121
|
+
exports.extractWorkingMemoryTags = extractWorkingMemoryTags;
|
|
20657
21122
|
exports.getResumeLabelsByStepId = getResumeLabelsByStepId;
|
|
20658
21123
|
exports.getStepIds = getStepIds;
|
|
20659
21124
|
exports.getStepResult = getStepResult;
|
|
@@ -20661,17 +21126,20 @@ exports.getZodErrors = getZodErrors;
|
|
|
20661
21126
|
exports.hydrateSerializedStepErrors = hydrateSerializedStepErrors;
|
|
20662
21127
|
exports.isProcessor = isProcessor;
|
|
20663
21128
|
exports.isProcessorWorkflow = isProcessorWorkflow;
|
|
21129
|
+
exports.isSupportedLanguageModel = isSupportedLanguageModel;
|
|
20664
21130
|
exports.loop = loop;
|
|
20665
21131
|
exports.mapVariable = mapVariable;
|
|
20666
21132
|
exports.memoryDefaultOptions = memoryDefaultOptions;
|
|
20667
21133
|
exports.parseMemoryRequestContext = parseMemoryRequestContext;
|
|
21134
|
+
exports.removeWorkingMemoryTags = removeWorkingMemoryTags;
|
|
20668
21135
|
exports.resolveThreadIdFromArgs = resolveThreadIdFromArgs;
|
|
20669
21136
|
exports.runCountDeprecationMessage = runCountDeprecationMessage;
|
|
21137
|
+
exports.supportedLanguageModelSpecifications = supportedLanguageModelSpecifications;
|
|
20670
21138
|
exports.tryGenerateWithJsonFallback = tryGenerateWithJsonFallback;
|
|
20671
21139
|
exports.tryStreamWithJsonFallback = tryStreamWithJsonFallback;
|
|
20672
21140
|
exports.validateStepInput = validateStepInput;
|
|
20673
21141
|
exports.validateStepResumeData = validateStepResumeData;
|
|
20674
21142
|
exports.validateStepStateData = validateStepStateData;
|
|
20675
21143
|
exports.validateStepSuspendData = validateStepSuspendData;
|
|
20676
|
-
//# sourceMappingURL=chunk-
|
|
20677
|
-
//# sourceMappingURL=chunk-
|
|
21144
|
+
//# sourceMappingURL=chunk-DDK3URK2.cjs.map
|
|
21145
|
+
//# sourceMappingURL=chunk-DDK3URK2.cjs.map
|