@mastra/core 1.0.0-beta.2 → 1.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +206 -0
- package/dist/agent/agent-legacy.d.ts +2 -2
- package/dist/agent/agent-legacy.d.ts.map +1 -1
- package/dist/agent/agent.d.ts +1 -1
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.types.d.ts +3 -2
- package/dist/agent/agent.types.d.ts.map +1 -1
- package/dist/agent/index.cjs +9 -9
- package/dist/agent/index.js +2 -2
- package/dist/agent/message-list/index.cjs +3 -3
- package/dist/agent/message-list/index.d.ts +5 -0
- package/dist/agent/message-list/index.d.ts.map +1 -1
- package/dist/agent/message-list/index.js +1 -1
- package/dist/agent/message-list/prompt/convert-file.d.ts +1 -1
- package/dist/agent/message-list/prompt/convert-file.d.ts.map +1 -1
- package/dist/agent/message-list/prompt/download-assets.d.ts.map +1 -1
- package/dist/agent/types.d.ts +1 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/utils.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +2 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts +3 -1
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +2 -1
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts +2 -1
- package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts +3 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
- package/dist/{chunk-YCVEJ3UN.cjs → chunk-2NVBZKZI.cjs} +988 -233
- package/dist/chunk-2NVBZKZI.cjs.map +1 -0
- package/dist/{chunk-SNPVZPLB.js → chunk-2OTDXX73.js} +6 -5
- package/dist/chunk-2OTDXX73.js.map +1 -0
- package/dist/chunk-3PSWNGBF.js +3 -0
- package/dist/{chunk-ZV5CC35D.js.map → chunk-3PSWNGBF.js.map} +1 -1
- package/dist/{chunk-ZGHTOYHW.js → chunk-3RW5EMSB.js} +155 -24
- package/dist/chunk-3RW5EMSB.js.map +1 -0
- package/dist/chunk-3W5RQCCY.cjs +440 -0
- package/dist/chunk-3W5RQCCY.cjs.map +1 -0
- package/dist/{chunk-ET6UOTTU.cjs → chunk-4IKJAKCD.cjs} +40 -4
- package/dist/chunk-4IKJAKCD.cjs.map +1 -0
- package/dist/{chunk-2ZVKF4HP.cjs → chunk-4RXG622P.cjs} +184 -285
- package/dist/chunk-4RXG622P.cjs.map +1 -0
- package/dist/{chunk-22443P6A.cjs → chunk-5WXEYDFI.cjs} +173 -42
- package/dist/chunk-5WXEYDFI.cjs.map +1 -0
- package/dist/{chunk-ZWNI5IWX.cjs → chunk-CYVNOIXS.cjs} +13 -12
- package/dist/chunk-CYVNOIXS.cjs.map +1 -0
- package/dist/{chunk-4CDL2QJT.js → chunk-D6EDHNGV.js} +53 -16
- package/dist/chunk-D6EDHNGV.js.map +1 -0
- package/dist/chunk-FVNT7VTO.js +436 -0
- package/dist/chunk-FVNT7VTO.js.map +1 -0
- package/dist/{chunk-WM6CK2F3.cjs → chunk-HBJPYQRN.cjs} +57 -19
- package/dist/chunk-HBJPYQRN.cjs.map +1 -0
- package/dist/{chunk-HDJFSJCK.js → chunk-IHJDOC3A.js} +35 -587
- package/dist/chunk-IHJDOC3A.js.map +1 -0
- package/dist/{chunk-QUKUN6NR.cjs → chunk-ISMGVGUM.cjs} +105 -5
- package/dist/chunk-ISMGVGUM.cjs.map +1 -0
- package/dist/{chunk-JYYQQEBH.cjs → chunk-IWB65P37.cjs} +241 -4
- package/dist/chunk-IWB65P37.cjs.map +1 -0
- package/dist/{chunk-MV7KHWUT.js → chunk-IWQDBVJK.js} +25 -4
- package/dist/chunk-IWQDBVJK.js.map +1 -0
- package/dist/{chunk-XEVG546F.js → chunk-JXESKY4A.js} +3 -3
- package/dist/{chunk-XEVG546F.js.map → chunk-JXESKY4A.js.map} +1 -1
- package/dist/{chunk-7AHYOMHJ.js → chunk-KEURQGCQ.js} +40 -5
- package/dist/chunk-KEURQGCQ.js.map +1 -0
- package/dist/{chunk-JPGVRWWL.js → chunk-MDKPL2R2.js} +470 -124
- package/dist/chunk-MDKPL2R2.js.map +1 -0
- package/dist/{chunk-UIZSWUKP.js → chunk-NZAXAFI3.js} +104 -6
- package/dist/chunk-NZAXAFI3.js.map +1 -0
- package/dist/{chunk-VOY2RXOC.cjs → chunk-O6NA3Z43.cjs} +6 -6
- package/dist/{chunk-VOY2RXOC.cjs.map → chunk-O6NA3Z43.cjs.map} +1 -1
- package/dist/chunk-PE3V7GUL.cjs +4 -0
- package/dist/{chunk-LJFJTTZQ.cjs.map → chunk-PE3V7GUL.cjs.map} +1 -1
- package/dist/{chunk-I4CXL4SR.js → chunk-RXDJL5QT.js} +5 -4
- package/dist/chunk-RXDJL5QT.js.map +1 -0
- package/dist/{chunk-LWBQ4P4N.cjs → chunk-S6OEQHEI.cjs} +62 -614
- package/dist/chunk-S6OEQHEI.cjs.map +1 -0
- package/dist/{chunk-7PO6SEJF.js → chunk-U7VECK2G.js} +240 -3
- package/dist/chunk-U7VECK2G.js.map +1 -0
- package/dist/{chunk-ECFXGXWO.cjs → chunk-VSM3NLUX.cjs} +312 -210
- package/dist/chunk-VSM3NLUX.cjs.map +1 -0
- package/dist/{chunk-IQO7ANVS.cjs → chunk-VZC4BWWH.cjs} +10 -9
- package/dist/chunk-VZC4BWWH.cjs.map +1 -0
- package/dist/{chunk-JV2KH24V.js → chunk-W3DD3XP5.js} +312 -210
- package/dist/chunk-W3DD3XP5.js.map +1 -0
- package/dist/{chunk-GGYKYORQ.cjs → chunk-WQSGX6XA.cjs} +27 -6
- package/dist/chunk-WQSGX6XA.cjs.map +1 -0
- package/dist/{chunk-W7UH2PWL.js → chunk-WTYNK7Q4.js} +179 -282
- package/dist/chunk-WTYNK7Q4.js.map +1 -0
- package/dist/{chunk-7CBEP2ZQ.js → chunk-XXBWX7DT.js} +949 -197
- package/dist/chunk-XXBWX7DT.js.map +1 -0
- package/dist/{chunk-CB575O6L.cjs → chunk-ZCVTH3CH.cjs} +470 -130
- package/dist/chunk-ZCVTH3CH.cjs.map +1 -0
- package/dist/evals/base.d.ts.map +1 -1
- package/dist/evals/index.cjs +4 -4
- package/dist/evals/index.js +1 -1
- package/dist/evals/scoreTraces/index.cjs +5 -4
- package/dist/evals/scoreTraces/index.cjs.map +1 -1
- package/dist/evals/scoreTraces/index.js +3 -2
- package/dist/evals/scoreTraces/index.js.map +1 -1
- package/dist/evals/scoreTraces/scoreTracesWorkflow.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/integration/index.cjs +2 -2
- package/dist/integration/index.js +1 -1
- package/dist/llm/index.cjs +26 -10
- package/dist/llm/index.d.ts +1 -0
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +5 -1
- package/dist/llm/model/aisdk/v5/model.d.ts +47 -0
- package/dist/llm/model/aisdk/v5/model.d.ts.map +1 -0
- package/dist/llm/model/gateways/base.d.ts +8 -0
- package/dist/llm/model/gateways/base.d.ts.map +1 -1
- package/dist/llm/model/gateways/models-dev.d.ts +1 -0
- package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
- package/dist/llm/model/gateways/netlify.d.ts +2 -1
- package/dist/llm/model/gateways/netlify.d.ts.map +1 -1
- package/dist/llm/model/is-v2-model.d.ts +3 -0
- package/dist/llm/model/is-v2-model.d.ts.map +1 -0
- package/dist/llm/model/model-method-from-agent.d.ts +4 -0
- package/dist/llm/model/model-method-from-agent.d.ts.map +1 -0
- package/dist/llm/model/model.loop.d.ts +2 -2
- package/dist/llm/model/model.loop.d.ts.map +1 -1
- package/dist/llm/model/model.loop.types.d.ts +2 -0
- package/dist/llm/model/model.loop.types.d.ts.map +1 -1
- package/dist/llm/model/provider-registry.d.ts +11 -1
- package/dist/llm/model/provider-registry.d.ts.map +1 -1
- package/dist/llm/model/provider-types.generated.d.ts +56 -7
- package/dist/llm/model/registry-generator.d.ts.map +1 -1
- package/dist/llm/model/resolve-model.d.ts +1 -1
- package/dist/llm/model/resolve-model.d.ts.map +1 -1
- package/dist/llm/model/router.d.ts +12 -5
- package/dist/llm/model/router.d.ts.map +1 -1
- package/dist/llm/model/shared.types.d.ts +10 -4
- package/dist/llm/model/shared.types.d.ts.map +1 -1
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/network/index.d.ts.map +1 -1
- package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts +37 -0
- package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts.map +1 -0
- package/dist/loop/test-utils/fullStream.d.ts.map +1 -1
- package/dist/loop/test-utils/generateText.d.ts.map +1 -1
- package/dist/loop/test-utils/options.d.ts.map +1 -1
- package/dist/loop/test-utils/resultObject.d.ts.map +1 -1
- package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
- package/dist/loop/test-utils/textStream.d.ts.map +1 -1
- package/dist/loop/test-utils/toUIMessageStream.d.ts.map +1 -1
- package/dist/loop/test-utils/tools.d.ts.map +1 -1
- package/dist/loop/test-utils/utils.d.ts +1 -1
- package/dist/loop/test-utils/utils.d.ts.map +1 -1
- package/dist/loop/types.d.ts +8 -3
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +12 -12
- package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +9 -9
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +4 -4
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts +13 -12
- package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
- package/dist/loop/workflows/run-state.d.ts +2 -2
- package/dist/loop/workflows/run-state.d.ts.map +1 -1
- package/dist/loop/workflows/schema.d.ts +4 -4
- package/dist/loop/workflows/stream.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.ts +127 -3
- package/dist/mastra/index.d.ts.map +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +8 -8
- package/dist/memory/index.js +4 -4
- package/dist/models-dev-6PRLJKVZ.js +3 -0
- package/dist/{models-dev-DNBKXHT4.js.map → models-dev-6PRLJKVZ.js.map} +1 -1
- package/dist/models-dev-WHMI5G6Y.cjs +12 -0
- package/dist/{models-dev-YBEEQIX6.cjs.map → models-dev-WHMI5G6Y.cjs.map} +1 -1
- package/dist/netlify-46I3SNNV.cjs +12 -0
- package/dist/{netlify-GWNGSIRZ.cjs.map → netlify-46I3SNNV.cjs.map} +1 -1
- package/dist/netlify-EBQ6YUC6.js +3 -0
- package/dist/{netlify-7G2L5VSH.js.map → netlify-EBQ6YUC6.js.map} +1 -1
- package/dist/processors/index.cjs +11 -11
- package/dist/processors/index.js +1 -1
- package/dist/provider-registry-HDG6UMUC.js +3 -0
- package/dist/provider-registry-HDG6UMUC.js.map +1 -0
- package/dist/provider-registry-RP2W4B24.cjs +40 -0
- package/dist/provider-registry-RP2W4B24.cjs.map +1 -0
- package/dist/provider-registry.json +140 -18
- package/dist/{registry-generator-MK63POJO.cjs → registry-generator-JPCV47SC.cjs} +6 -4
- package/dist/registry-generator-JPCV47SC.cjs.map +1 -0
- package/dist/{registry-generator-H4YNODDH.js → registry-generator-XD4FPZTU.js} +6 -4
- package/dist/registry-generator-XD4FPZTU.js.map +1 -0
- package/dist/relevance/index.cjs +2 -2
- package/dist/relevance/index.js +1 -1
- package/dist/server/auth.d.ts +11 -0
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/index.cjs +12 -1
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +12 -1
- package/dist/server/index.js.map +1 -1
- package/dist/storage/domains/workflows/inmemory.d.ts +1 -1
- package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
- package/dist/storage/index.cjs +29 -29
- package/dist/storage/index.js +1 -1
- package/dist/storage/types.d.ts +2 -1
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/stream/RunOutput.d.ts +1 -1
- package/dist/stream/RunOutput.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/execute.d.ts +6 -3
- package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
- package/dist/stream/base/input.d.ts +1 -1
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/index.cjs +11 -11
- package/dist/stream/index.js +2 -2
- package/dist/stream/types.d.ts +4 -3
- package/dist/stream/types.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.cjs +68 -31
- package/dist/test-utils/llm-mock.cjs.map +1 -1
- package/dist/test-utils/llm-mock.d.ts +4 -2
- package/dist/test-utils/llm-mock.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.js +67 -30
- package/dist/test-utils/llm-mock.js.map +1 -1
- package/dist/tools/index.cjs +4 -4
- package/dist/tools/index.js +1 -1
- package/dist/tools/is-vercel-tool.cjs +2 -2
- package/dist/tools/is-vercel-tool.js +1 -1
- package/dist/tools/tool-builder/builder.d.ts.map +1 -1
- package/dist/tools/tool.d.ts.map +1 -1
- package/dist/tools/types.d.ts +1 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/validation.d.ts +12 -0
- package/dist/tools/validation.d.ts.map +1 -1
- package/dist/utils.cjs +25 -21
- package/dist/utils.d.ts +4 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/voice/aisdk/index.d.ts +3 -0
- package/dist/voice/aisdk/index.d.ts.map +1 -0
- package/dist/voice/aisdk/speech.d.ts +23 -0
- package/dist/voice/aisdk/speech.d.ts.map +1 -0
- package/dist/voice/aisdk/transcription.d.ts +22 -0
- package/dist/voice/aisdk/transcription.d.ts.map +1 -0
- package/dist/voice/composite-voice.d.ts +4 -3
- package/dist/voice/composite-voice.d.ts.map +1 -1
- package/dist/voice/index.cjs +12 -4
- package/dist/voice/index.d.ts +1 -0
- package/dist/voice/index.d.ts.map +1 -1
- package/dist/voice/index.js +1 -1
- package/dist/workflows/default.d.ts +24 -8
- package/dist/workflows/default.d.ts.map +1 -1
- package/dist/workflows/evented/execution-engine.d.ts +3 -1
- package/dist/workflows/evented/execution-engine.d.ts.map +1 -1
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/evented/workflow-event-processor/index.d.ts +5 -4
- package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/loop.d.ts +1 -1
- package/dist/workflows/evented/workflow-event-processor/loop.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/parallel.d.ts +2 -2
- package/dist/workflows/evented/workflow-event-processor/parallel.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/sleep.d.ts +2 -2
- package/dist/workflows/evented/workflow-event-processor/sleep.d.ts.map +1 -1
- package/dist/workflows/evented/workflow.d.ts +2 -1
- package/dist/workflows/evented/workflow.d.ts.map +1 -1
- package/dist/workflows/execution-engine.d.ts +4 -2
- package/dist/workflows/execution-engine.d.ts.map +1 -1
- package/dist/workflows/index.cjs +28 -16
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/step.d.ts +1 -0
- package/dist/workflows/step.d.ts.map +1 -1
- package/dist/workflows/types.d.ts +54 -2
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/utils.d.ts +20 -0
- package/dist/workflows/utils.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +108 -40
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +19 -27
- package/src/llm/model/provider-types.generated.d.ts +56 -7
- package/dist/chunk-22443P6A.cjs.map +0 -1
- package/dist/chunk-2ZVKF4HP.cjs.map +0 -1
- package/dist/chunk-4CDL2QJT.js.map +0 -1
- package/dist/chunk-7AHYOMHJ.js.map +0 -1
- package/dist/chunk-7CBEP2ZQ.js.map +0 -1
- package/dist/chunk-7PO6SEJF.js.map +0 -1
- package/dist/chunk-CB575O6L.cjs.map +0 -1
- package/dist/chunk-ECFXGXWO.cjs.map +0 -1
- package/dist/chunk-ET6UOTTU.cjs.map +0 -1
- package/dist/chunk-GGYKYORQ.cjs.map +0 -1
- package/dist/chunk-HDJFSJCK.js.map +0 -1
- package/dist/chunk-I4CXL4SR.js.map +0 -1
- package/dist/chunk-IQO7ANVS.cjs.map +0 -1
- package/dist/chunk-JPGVRWWL.js.map +0 -1
- package/dist/chunk-JV2KH24V.js.map +0 -1
- package/dist/chunk-JYYQQEBH.cjs.map +0 -1
- package/dist/chunk-LJFJTTZQ.cjs +0 -4
- package/dist/chunk-LWBQ4P4N.cjs.map +0 -1
- package/dist/chunk-MV7KHWUT.js.map +0 -1
- package/dist/chunk-QUKUN6NR.cjs.map +0 -1
- package/dist/chunk-SNPVZPLB.js.map +0 -1
- package/dist/chunk-UIZSWUKP.js.map +0 -1
- package/dist/chunk-W7UH2PWL.js.map +0 -1
- package/dist/chunk-WM6CK2F3.cjs.map +0 -1
- package/dist/chunk-YCVEJ3UN.cjs.map +0 -1
- package/dist/chunk-ZGHTOYHW.js.map +0 -1
- package/dist/chunk-ZV5CC35D.js +0 -3
- package/dist/chunk-ZWNI5IWX.cjs.map +0 -1
- package/dist/models-dev-DNBKXHT4.js +0 -3
- package/dist/models-dev-YBEEQIX6.cjs +0 -12
- package/dist/netlify-7G2L5VSH.js +0 -3
- package/dist/netlify-GWNGSIRZ.cjs +0 -12
- package/dist/registry-generator-H4YNODDH.js.map +0 -1
- package/dist/registry-generator-MK63POJO.cjs.map +0 -1
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { DefaultVoice } from './chunk-
|
|
1
|
+
import { DefaultVoice } from './chunk-NZAXAFI3.js';
|
|
2
2
|
import { STREAM_FORMAT_SYMBOL, EMITTER_SYMBOL } from './chunk-NLNKQD2T.js';
|
|
3
|
-
import { MessageList, DefaultGeneratedFile, DefaultGeneratedFileWithType } from './chunk-
|
|
4
|
-
import { resolveModelConfig } from './chunk-
|
|
5
|
-
import { MastraLLMV1 } from './chunk-
|
|
3
|
+
import { MessageList, DefaultGeneratedFile, DefaultGeneratedFileWithType } from './chunk-W3DD3XP5.js';
|
|
4
|
+
import { resolveModelConfig } from './chunk-FVNT7VTO.js';
|
|
5
|
+
import { MastraLLMV1 } from './chunk-JXESKY4A.js';
|
|
6
6
|
import { executeHook } from './chunk-L54GIUCB.js';
|
|
7
|
-
import { selectFields, ensureToolProperties, makeCoreTool, createMastraProxy, delay } from './chunk-
|
|
7
|
+
import { removeUndefinedValues, selectFields, ensureToolProperties, makeCoreTool, createMastraProxy, delay } from './chunk-D6EDHNGV.js';
|
|
8
8
|
import { wrapMastra, getOrCreateSpan } from './chunk-KIZIOFZC.js';
|
|
9
9
|
import { MastraError, getErrorFromUnknown } from './chunk-JJ5O45LH.js';
|
|
10
10
|
import { ToolStream } from './chunk-HGNRQ3OG.js';
|
|
11
|
-
import { Tool, createTool } from './chunk-
|
|
11
|
+
import { Tool, createTool } from './chunk-KEURQGCQ.js';
|
|
12
12
|
import { RequestContext } from './chunk-GRBGQ2GE.js';
|
|
13
13
|
import { zodToJsonSchema } from './chunk-PJKCPRYF.js';
|
|
14
14
|
import { MastraBase } from './chunk-S6URFGCZ.js';
|
|
15
15
|
import { RegisteredLogger, ConsoleLogger } from './chunk-KJ2SW6VA.js';
|
|
16
16
|
import { __commonJS, __toESM } from './chunk-5WRI5ZAA.js';
|
|
17
17
|
import EventEmitter, { EventEmitter as EventEmitter$1 } from 'events';
|
|
18
|
-
import {
|
|
18
|
+
import { WritableStream as WritableStream$1, ReadableStream as ReadableStream$1, TransformStream } from 'stream/web';
|
|
19
19
|
import * as crypto2 from 'crypto';
|
|
20
20
|
import { randomUUID } from 'crypto';
|
|
21
21
|
import { getErrorMessage, TypeValidationError } from '@ai-sdk/provider-v5';
|
|
@@ -422,14 +422,22 @@ function prepareToolsAndToolChoice({
|
|
|
422
422
|
inputSchema: asSchema(sdkTool.inputSchema).jsonSchema,
|
|
423
423
|
providerOptions: sdkTool.providerOptions
|
|
424
424
|
};
|
|
425
|
-
case "provider-defined":
|
|
425
|
+
case "provider-defined": {
|
|
426
|
+
const providerId = sdkTool.id;
|
|
427
|
+
let providerToolName = name;
|
|
428
|
+
if (providerId && providerId.includes(".")) {
|
|
429
|
+
providerToolName = providerId.split(".").slice(1).join(".");
|
|
430
|
+
} else if (providerId) {
|
|
431
|
+
providerToolName = providerId;
|
|
432
|
+
}
|
|
426
433
|
return {
|
|
427
434
|
type: "provider-defined",
|
|
428
|
-
name,
|
|
435
|
+
name: providerToolName,
|
|
429
436
|
// TODO: as any seems wrong here. are there cases where we don't have an id?
|
|
430
|
-
id:
|
|
437
|
+
id: providerId,
|
|
431
438
|
args: sdkTool.args
|
|
432
439
|
};
|
|
440
|
+
}
|
|
433
441
|
default: {
|
|
434
442
|
const exhaustiveCheck = toolType;
|
|
435
443
|
throw new Error(`Unsupported tool type: ${exhaustiveCheck}`);
|
|
@@ -516,6 +524,11 @@ function runScorer({
|
|
|
516
524
|
executeHook("onScorerRun" /* ON_SCORER_RUN */, payload);
|
|
517
525
|
}
|
|
518
526
|
|
|
527
|
+
// src/llm/model/is-v2-model.ts
|
|
528
|
+
function isV2Model(model) {
|
|
529
|
+
return model.specificationVersion === "v2";
|
|
530
|
+
}
|
|
531
|
+
|
|
519
532
|
// src/stream/base/consume-stream.ts
|
|
520
533
|
async function consumeStream2({
|
|
521
534
|
stream,
|
|
@@ -572,7 +585,7 @@ var WorkflowRunOutput = class {
|
|
|
572
585
|
this.workflowId = workflowId;
|
|
573
586
|
this.#baseStream = stream;
|
|
574
587
|
stream.pipeTo(
|
|
575
|
-
new WritableStream({
|
|
588
|
+
new WritableStream$1({
|
|
576
589
|
start() {
|
|
577
590
|
const chunk = {
|
|
578
591
|
type: "workflow-start",
|
|
@@ -700,7 +713,7 @@ var WorkflowRunOutput = class {
|
|
|
700
713
|
};
|
|
701
714
|
const self = this;
|
|
702
715
|
stream.pipeTo(
|
|
703
|
-
new WritableStream({
|
|
716
|
+
new WritableStream$1({
|
|
704
717
|
start() {
|
|
705
718
|
const chunk = {
|
|
706
719
|
type: "workflow-start",
|
|
@@ -935,6 +948,24 @@ async function validateStepInput({
|
|
|
935
948
|
}
|
|
936
949
|
return { inputData, validationError };
|
|
937
950
|
}
|
|
951
|
+
async function validateStepResumeData({ resumeData, step }) {
|
|
952
|
+
if (!resumeData) {
|
|
953
|
+
return { resumeData: void 0, validationError: void 0 };
|
|
954
|
+
}
|
|
955
|
+
let validationError;
|
|
956
|
+
const resumeSchema = step.resumeSchema;
|
|
957
|
+
if (resumeSchema) {
|
|
958
|
+
const validatedResumeData = await resumeSchema.safeParseAsync(resumeData);
|
|
959
|
+
if (!validatedResumeData.success) {
|
|
960
|
+
const errors = getZodErrors(validatedResumeData.error);
|
|
961
|
+
const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
|
|
962
|
+
validationError = new Error("Step resume data validation failed: \n" + errorMessages);
|
|
963
|
+
} else {
|
|
964
|
+
resumeData = validatedResumeData.data;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
return { resumeData, validationError };
|
|
968
|
+
}
|
|
938
969
|
function getResumeLabelsByStepId(resumeLabels, stepId) {
|
|
939
970
|
return Object.entries(resumeLabels).filter(([_, value]) => value.stepId === stepId).reduce(
|
|
940
971
|
(acc, [key, value]) => {
|
|
@@ -965,6 +996,111 @@ function createDeprecationProxy(params, {
|
|
|
965
996
|
}
|
|
966
997
|
});
|
|
967
998
|
}
|
|
999
|
+
var getStepIds = (entry) => {
|
|
1000
|
+
if (entry.type === "step" || entry.type === "foreach" || entry.type === "loop") {
|
|
1001
|
+
return [entry.step.id];
|
|
1002
|
+
}
|
|
1003
|
+
if (entry.type === "parallel" || entry.type === "conditional") {
|
|
1004
|
+
return entry.steps.map((s) => s.step.id);
|
|
1005
|
+
}
|
|
1006
|
+
if (entry.type === "sleep" || entry.type === "sleepUntil") {
|
|
1007
|
+
return [entry.id];
|
|
1008
|
+
}
|
|
1009
|
+
return [];
|
|
1010
|
+
};
|
|
1011
|
+
var createTimeTravelExecutionParams = (params) => {
|
|
1012
|
+
const { steps, inputData, resumeData, context, nestedStepsContext, snapshot, initialState, graph } = params;
|
|
1013
|
+
const firstStepId = steps[0];
|
|
1014
|
+
let executionPath = [];
|
|
1015
|
+
const stepResults = {};
|
|
1016
|
+
const snapshotContext = snapshot.context;
|
|
1017
|
+
for (const [index, entry] of graph.steps.entries()) {
|
|
1018
|
+
const currentExecPathLength = executionPath.length;
|
|
1019
|
+
if (currentExecPathLength > 0 && !resumeData) {
|
|
1020
|
+
break;
|
|
1021
|
+
}
|
|
1022
|
+
const stepIds = getStepIds(entry);
|
|
1023
|
+
if (stepIds.includes(firstStepId)) {
|
|
1024
|
+
const innerExecutionPath = stepIds?.length > 1 ? [stepIds?.findIndex((s) => s === firstStepId)] : [];
|
|
1025
|
+
executionPath = [index, ...innerExecutionPath];
|
|
1026
|
+
}
|
|
1027
|
+
const prevStep = graph.steps[index - 1];
|
|
1028
|
+
let stepPayload = void 0;
|
|
1029
|
+
if (prevStep) {
|
|
1030
|
+
const prevStepIds = getStepIds(prevStep);
|
|
1031
|
+
if (prevStepIds.length > 0) {
|
|
1032
|
+
if (prevStepIds.length === 1) {
|
|
1033
|
+
stepPayload = stepResults?.[prevStepIds[0]]?.output ?? {};
|
|
1034
|
+
} else {
|
|
1035
|
+
stepPayload = prevStepIds.reduce(
|
|
1036
|
+
(acc, stepId) => {
|
|
1037
|
+
acc[stepId] = stepResults?.[stepId]?.output ?? {};
|
|
1038
|
+
return acc;
|
|
1039
|
+
},
|
|
1040
|
+
{}
|
|
1041
|
+
);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
if (index === 0 && stepIds.includes(firstStepId)) {
|
|
1046
|
+
stepResults.input = context?.[firstStepId]?.payload ?? inputData ?? snapshotContext?.input;
|
|
1047
|
+
} else if (index === 0) {
|
|
1048
|
+
stepResults.input = stepIds?.reduce((acc, stepId) => {
|
|
1049
|
+
if (acc) return acc;
|
|
1050
|
+
return context?.[stepId]?.payload ?? snapshotContext?.[stepId]?.payload;
|
|
1051
|
+
}, null) ?? snapshotContext?.input ?? {};
|
|
1052
|
+
}
|
|
1053
|
+
let stepOutput = void 0;
|
|
1054
|
+
const nextStep = graph.steps[index + 1];
|
|
1055
|
+
if (nextStep) {
|
|
1056
|
+
const nextStepIds = getStepIds(nextStep);
|
|
1057
|
+
if (nextStepIds.length > 0 && inputData && nextStepIds.includes(firstStepId) && steps.length === 1) {
|
|
1058
|
+
stepOutput = inputData;
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
stepIds.forEach((stepId) => {
|
|
1062
|
+
let result;
|
|
1063
|
+
const stepContext = context?.[stepId] ?? snapshotContext[stepId];
|
|
1064
|
+
const defaultStepStatus = steps?.includes(stepId) ? "running" : "success";
|
|
1065
|
+
const status = ["failed", "canceled"].includes(stepContext?.status) ? defaultStepStatus : stepContext?.status ?? defaultStepStatus;
|
|
1066
|
+
const isCompleteStatus = ["success", "failed", "canceled"].includes(status);
|
|
1067
|
+
result = {
|
|
1068
|
+
status,
|
|
1069
|
+
payload: context?.[stepId]?.payload ?? stepPayload ?? snapshotContext[stepId]?.payload ?? {},
|
|
1070
|
+
output: isCompleteStatus ? context?.[stepId]?.output ?? stepOutput ?? snapshotContext[stepId]?.output ?? {} : void 0,
|
|
1071
|
+
resumePayload: stepContext?.resumePayload,
|
|
1072
|
+
suspendPayload: stepContext?.suspendPayload,
|
|
1073
|
+
suspendOutput: stepContext?.suspendOutput,
|
|
1074
|
+
startedAt: stepContext?.startedAt ?? Date.now(),
|
|
1075
|
+
endedAt: isCompleteStatus ? stepContext?.endedAt ?? Date.now() : void 0,
|
|
1076
|
+
suspendedAt: stepContext?.suspendedAt,
|
|
1077
|
+
resumedAt: stepContext?.resumedAt
|
|
1078
|
+
};
|
|
1079
|
+
if (currentExecPathLength > 0 && (!snapshotContext[stepId] || snapshotContext[stepId] && snapshotContext[stepId].status !== "suspended")) {
|
|
1080
|
+
result = void 0;
|
|
1081
|
+
}
|
|
1082
|
+
if (result) {
|
|
1083
|
+
const formattedResult = removeUndefinedValues(result);
|
|
1084
|
+
stepResults[stepId] = formattedResult;
|
|
1085
|
+
}
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
if (!executionPath.length) {
|
|
1089
|
+
throw new Error(
|
|
1090
|
+
`Time travel target step not found in execution graph: '${steps?.join(".")}'. Verify the step id/path.`
|
|
1091
|
+
);
|
|
1092
|
+
}
|
|
1093
|
+
const timeTravelData = {
|
|
1094
|
+
inputData,
|
|
1095
|
+
executionPath,
|
|
1096
|
+
steps,
|
|
1097
|
+
stepResults,
|
|
1098
|
+
nestedStepResults: nestedStepsContext,
|
|
1099
|
+
state: initialState ?? snapshot.value ?? {},
|
|
1100
|
+
resumeData
|
|
1101
|
+
};
|
|
1102
|
+
return timeTravelData;
|
|
1103
|
+
};
|
|
968
1104
|
|
|
969
1105
|
// src/workflows/default.ts
|
|
970
1106
|
var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
@@ -1051,7 +1187,9 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1051
1187
|
resume,
|
|
1052
1188
|
retryConfig,
|
|
1053
1189
|
workflowSpan,
|
|
1054
|
-
disableScorers
|
|
1190
|
+
disableScorers,
|
|
1191
|
+
restart,
|
|
1192
|
+
timeTravel
|
|
1055
1193
|
} = params;
|
|
1056
1194
|
const { attempts = 0, delay: delay2 = 0 } = retryConfig ?? {};
|
|
1057
1195
|
const steps = graph.steps;
|
|
@@ -1067,19 +1205,26 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1067
1205
|
throw empty_graph_error;
|
|
1068
1206
|
}
|
|
1069
1207
|
let startIdx = 0;
|
|
1070
|
-
if (
|
|
1208
|
+
if (timeTravel) {
|
|
1209
|
+
startIdx = timeTravel.executionPath[0];
|
|
1210
|
+
timeTravel.executionPath.shift();
|
|
1211
|
+
} else if (restart) {
|
|
1212
|
+
startIdx = restart.activePaths[0];
|
|
1213
|
+
restart.activePaths.shift();
|
|
1214
|
+
} else if (resume?.resumePath) {
|
|
1071
1215
|
startIdx = resume.resumePath[0];
|
|
1072
1216
|
resume.resumePath.shift();
|
|
1073
1217
|
}
|
|
1074
|
-
const stepResults = resume?.stepResults || { input };
|
|
1218
|
+
const stepResults = timeTravel?.stepResults || restart?.stepResults || resume?.stepResults || { input };
|
|
1075
1219
|
let lastOutput;
|
|
1076
|
-
let lastState = initialState ?? {};
|
|
1220
|
+
let lastState = timeTravel?.state ?? restart?.state ?? initialState ?? {};
|
|
1077
1221
|
for (let i = startIdx; i < steps.length; i++) {
|
|
1078
1222
|
const entry = steps[i];
|
|
1079
1223
|
const executionContext = {
|
|
1080
1224
|
workflowId,
|
|
1081
1225
|
runId,
|
|
1082
1226
|
executionPath: [i],
|
|
1227
|
+
activeStepsPath: {},
|
|
1083
1228
|
suspendedPaths: {},
|
|
1084
1229
|
resumeLabels: {},
|
|
1085
1230
|
retryConfig: { attempts, delay: delay2 },
|
|
@@ -1097,6 +1242,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1097
1242
|
prevStep: steps[i - 1],
|
|
1098
1243
|
stepResults,
|
|
1099
1244
|
resume,
|
|
1245
|
+
timeTravel,
|
|
1246
|
+
restart,
|
|
1100
1247
|
tracingContext: {
|
|
1101
1248
|
currentSpan: workflowSpan
|
|
1102
1249
|
},
|
|
@@ -1386,7 +1533,9 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1386
1533
|
step,
|
|
1387
1534
|
stepResults,
|
|
1388
1535
|
executionContext,
|
|
1536
|
+
restart,
|
|
1389
1537
|
resume,
|
|
1538
|
+
timeTravel,
|
|
1390
1539
|
prevOutput,
|
|
1391
1540
|
emitter,
|
|
1392
1541
|
abortController,
|
|
@@ -1398,22 +1547,38 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1398
1547
|
tracingContext,
|
|
1399
1548
|
iterationCount
|
|
1400
1549
|
}) {
|
|
1401
|
-
const startTime = resume?.steps[0] === step.id ? void 0 : Date.now();
|
|
1402
|
-
const resumeTime = resume?.steps[0] === step.id ? Date.now() : void 0;
|
|
1403
1550
|
const stepCallId = randomUUID();
|
|
1404
1551
|
const { inputData, validationError } = await validateStepInput({
|
|
1405
1552
|
prevOutput,
|
|
1406
1553
|
step,
|
|
1407
|
-
validateInputs: this.options?.validateInputs ??
|
|
1554
|
+
validateInputs: this.options?.validateInputs ?? true
|
|
1555
|
+
});
|
|
1556
|
+
const { resumeData: timeTravelResumeData, validationError: timeTravelResumeValidationError } = await validateStepResumeData({
|
|
1557
|
+
resumeData: timeTravel?.stepResults[step.id]?.status === "suspended" ? timeTravel?.resumeData : void 0,
|
|
1558
|
+
step
|
|
1408
1559
|
});
|
|
1560
|
+
let resumeDataToUse;
|
|
1561
|
+
if (timeTravelResumeData && !timeTravelResumeValidationError) {
|
|
1562
|
+
resumeDataToUse = timeTravelResumeData;
|
|
1563
|
+
} else if (timeTravelResumeData && timeTravelResumeValidationError) {
|
|
1564
|
+
this.logger.warn("Time travel resume data validation failed", {
|
|
1565
|
+
stepId: step.id,
|
|
1566
|
+
error: timeTravelResumeValidationError.message
|
|
1567
|
+
});
|
|
1568
|
+
} else if (resume?.steps[0] === step.id) {
|
|
1569
|
+
resumeDataToUse = resume?.resumePayload;
|
|
1570
|
+
}
|
|
1571
|
+
const startTime = resumeDataToUse ? void 0 : Date.now();
|
|
1572
|
+
const resumeTime = resumeDataToUse ? Date.now() : void 0;
|
|
1409
1573
|
const stepInfo = {
|
|
1410
1574
|
...stepResults[step.id],
|
|
1411
|
-
...
|
|
1575
|
+
...resumeDataToUse ? { resumePayload: resumeDataToUse } : { payload: inputData },
|
|
1412
1576
|
...startTime ? { startedAt: startTime } : {},
|
|
1413
1577
|
...resumeTime ? { resumedAt: resumeTime } : {},
|
|
1414
1578
|
status: "running",
|
|
1415
1579
|
...iterationCount ? { metadata: { iterationCount } } : {}
|
|
1416
1580
|
};
|
|
1581
|
+
executionContext.activeStepsPath[step.id] = executionContext.executionPath;
|
|
1417
1582
|
const stepSpan = tracingContext.currentSpan?.createChildSpan({
|
|
1418
1583
|
name: `workflow step: '${step.id}'`,
|
|
1419
1584
|
type: "workflow_step" /* WORKFLOW_STEP */,
|
|
@@ -1468,6 +1633,10 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1468
1633
|
throw validationError;
|
|
1469
1634
|
}
|
|
1470
1635
|
const retryCount = this.getOrGenerateRetryCount(step.id);
|
|
1636
|
+
let timeTravelSteps = [];
|
|
1637
|
+
if (timeTravel && timeTravel.steps.length > 0) {
|
|
1638
|
+
timeTravelSteps = timeTravel.steps[0] === step.id ? timeTravel.steps.slice(1) : [];
|
|
1639
|
+
}
|
|
1471
1640
|
const result = await runStep({
|
|
1472
1641
|
runId,
|
|
1473
1642
|
resourceId,
|
|
@@ -1480,7 +1649,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1480
1649
|
executionContext.state = state;
|
|
1481
1650
|
},
|
|
1482
1651
|
retryCount,
|
|
1483
|
-
resumeData:
|
|
1652
|
+
resumeData: resumeDataToUse,
|
|
1484
1653
|
tracingContext: { currentSpan: stepSpan },
|
|
1485
1654
|
getInitData: () => stepResults?.input,
|
|
1486
1655
|
getStepResult: getStepResult.bind(this, stepResults),
|
|
@@ -1513,6 +1682,15 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1513
1682
|
label: resume?.label,
|
|
1514
1683
|
forEachIndex: resume?.forEachIndex
|
|
1515
1684
|
} : void 0,
|
|
1685
|
+
// Only pass restart data if this step is part of activeStepsPath
|
|
1686
|
+
// This prevents pending nested workflows from trying to restart instead of start
|
|
1687
|
+
restart: !!restart?.activeStepsPath?.[step.id],
|
|
1688
|
+
timeTravel: timeTravelSteps.length > 0 ? {
|
|
1689
|
+
inputData: timeTravel?.inputData,
|
|
1690
|
+
steps: timeTravelSteps,
|
|
1691
|
+
nestedStepResults: timeTravel?.nestedStepResults,
|
|
1692
|
+
resumeData: timeTravel?.resumeData
|
|
1693
|
+
} : void 0,
|
|
1516
1694
|
[EMITTER_SYMBOL]: emitter,
|
|
1517
1695
|
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1518
1696
|
engine: {},
|
|
@@ -1584,6 +1762,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1584
1762
|
};
|
|
1585
1763
|
}
|
|
1586
1764
|
}
|
|
1765
|
+
delete executionContext.activeStepsPath[step.id];
|
|
1587
1766
|
if (!skipEmits) {
|
|
1588
1767
|
if (execResults.status === "suspended") {
|
|
1589
1768
|
await emitter.emit("watch", {
|
|
@@ -1687,6 +1866,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1687
1866
|
serializedStepGraph,
|
|
1688
1867
|
stepResults,
|
|
1689
1868
|
resume,
|
|
1869
|
+
restart,
|
|
1870
|
+
timeTravel,
|
|
1690
1871
|
executionContext,
|
|
1691
1872
|
tracingContext,
|
|
1692
1873
|
emitter,
|
|
@@ -1706,22 +1887,38 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1706
1887
|
tracingPolicy: this.options?.tracingPolicy
|
|
1707
1888
|
});
|
|
1708
1889
|
const prevOutput = this.getStepOutput(stepResults, prevStep);
|
|
1709
|
-
for (const step of entry.steps) {
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
stepResults[step.step.id] = {
|
|
1714
|
-
...stepResults[step.step.id],
|
|
1715
|
-
status: "running",
|
|
1716
|
-
...resumeTime ? { resumePayload: resume?.resumePayload } : { payload: prevOutput },
|
|
1717
|
-
...startTime ? { startedAt: startTime } : {},
|
|
1718
|
-
...resumeTime ? { resumedAt: resumeTime } : {}
|
|
1719
|
-
};
|
|
1890
|
+
for (const [stepIndex, step] of entry.steps.entries()) {
|
|
1891
|
+
let makeStepRunning = true;
|
|
1892
|
+
if (restart) {
|
|
1893
|
+
makeStepRunning = !!restart.activeStepsPath[step.step.id];
|
|
1720
1894
|
}
|
|
1895
|
+
if (timeTravel && timeTravel.executionPath.length > 0) {
|
|
1896
|
+
makeStepRunning = timeTravel.steps[0] === step.step.id;
|
|
1897
|
+
}
|
|
1898
|
+
if (!makeStepRunning) {
|
|
1899
|
+
continue;
|
|
1900
|
+
}
|
|
1901
|
+
const startTime = resume?.steps[0] === step.step.id ? void 0 : Date.now();
|
|
1902
|
+
const resumeTime = resume?.steps[0] === step.step.id ? Date.now() : void 0;
|
|
1903
|
+
stepResults[step.step.id] = {
|
|
1904
|
+
...stepResults[step.step.id],
|
|
1905
|
+
status: "running",
|
|
1906
|
+
...resumeTime ? { resumePayload: resume?.resumePayload } : { payload: prevOutput },
|
|
1907
|
+
...startTime ? { startedAt: startTime } : {},
|
|
1908
|
+
...resumeTime ? { resumedAt: resumeTime } : {}
|
|
1909
|
+
};
|
|
1910
|
+
executionContext.activeStepsPath[step.step.id] = [...executionContext.executionPath, stepIndex];
|
|
1911
|
+
}
|
|
1912
|
+
if (timeTravel && timeTravel.executionPath.length > 0) {
|
|
1913
|
+
timeTravel.executionPath.shift();
|
|
1721
1914
|
}
|
|
1722
1915
|
let execResults;
|
|
1723
1916
|
const results = await Promise.all(
|
|
1724
1917
|
entry.steps.map(async (step, i) => {
|
|
1918
|
+
const currStepResult = stepResults[step.step.id];
|
|
1919
|
+
if (currStepResult && currStepResult.status !== "running") {
|
|
1920
|
+
return currStepResult;
|
|
1921
|
+
}
|
|
1725
1922
|
const result = await this.executeStep({
|
|
1726
1923
|
workflowId,
|
|
1727
1924
|
runId,
|
|
@@ -1730,8 +1927,11 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1730
1927
|
prevOutput,
|
|
1731
1928
|
stepResults,
|
|
1732
1929
|
serializedStepGraph,
|
|
1930
|
+
restart,
|
|
1931
|
+
timeTravel,
|
|
1733
1932
|
resume,
|
|
1734
1933
|
executionContext: {
|
|
1934
|
+
activeStepsPath: executionContext.activeStepsPath,
|
|
1735
1935
|
workflowId,
|
|
1736
1936
|
runId,
|
|
1737
1937
|
executionPath: [...executionContext.executionPath, i],
|
|
@@ -1796,6 +1996,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1796
1996
|
serializedStepGraph,
|
|
1797
1997
|
stepResults,
|
|
1798
1998
|
resume,
|
|
1999
|
+
restart,
|
|
2000
|
+
timeTravel,
|
|
1799
2001
|
executionContext,
|
|
1800
2002
|
tracingContext,
|
|
1801
2003
|
emitter,
|
|
@@ -1911,7 +2113,13 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1911
2113
|
const results = await Promise.all(
|
|
1912
2114
|
stepsToRun.map(async (step, index) => {
|
|
1913
2115
|
const currStepResult = stepResults[step.step.id];
|
|
1914
|
-
|
|
2116
|
+
const isRestartStep = restart ? !!restart.activeStepsPath[step.step.id] : void 0;
|
|
2117
|
+
if (currStepResult && timeTravel && timeTravel.executionPath.length > 0) {
|
|
2118
|
+
if (timeTravel.steps[0] !== step.step.id) {
|
|
2119
|
+
return currStepResult;
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
if (currStepResult && ["success", "failed"].includes(currStepResult.status) && isRestartStep === void 0) {
|
|
1915
2123
|
return currStepResult;
|
|
1916
2124
|
}
|
|
1917
2125
|
const result = await this.executeStep({
|
|
@@ -1923,10 +2131,13 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1923
2131
|
stepResults,
|
|
1924
2132
|
serializedStepGraph,
|
|
1925
2133
|
resume,
|
|
2134
|
+
restart,
|
|
2135
|
+
timeTravel,
|
|
1926
2136
|
executionContext: {
|
|
1927
2137
|
workflowId,
|
|
1928
2138
|
runId,
|
|
1929
2139
|
executionPath: [...executionContext.executionPath, index],
|
|
2140
|
+
activeStepsPath: executionContext.activeStepsPath,
|
|
1930
2141
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1931
2142
|
resumeLabels: executionContext.resumeLabels,
|
|
1932
2143
|
retryConfig: executionContext.retryConfig,
|
|
@@ -1988,6 +2199,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1988
2199
|
prevOutput,
|
|
1989
2200
|
stepResults,
|
|
1990
2201
|
resume,
|
|
2202
|
+
restart,
|
|
2203
|
+
timeTravel,
|
|
1991
2204
|
executionContext,
|
|
1992
2205
|
tracingContext,
|
|
1993
2206
|
emitter,
|
|
@@ -2013,6 +2226,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2013
2226
|
const prevPayload = stepResults[step.id]?.payload;
|
|
2014
2227
|
let result = { status: "success", output: prevPayload ?? prevOutput };
|
|
2015
2228
|
let currentResume = resume;
|
|
2229
|
+
let currentRestart = restart;
|
|
2230
|
+
let currentTimeTravel = timeTravel;
|
|
2016
2231
|
do {
|
|
2017
2232
|
result = await this.executeStep({
|
|
2018
2233
|
workflowId,
|
|
@@ -2021,7 +2236,9 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2021
2236
|
step,
|
|
2022
2237
|
stepResults,
|
|
2023
2238
|
executionContext,
|
|
2239
|
+
restart: currentRestart,
|
|
2024
2240
|
resume: currentResume,
|
|
2241
|
+
timeTravel: currentTimeTravel,
|
|
2025
2242
|
prevOutput: result.output,
|
|
2026
2243
|
tracingContext: {
|
|
2027
2244
|
currentSpan: loopSpan
|
|
@@ -2034,6 +2251,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2034
2251
|
serializedStepGraph,
|
|
2035
2252
|
iterationCount: iteration + 1
|
|
2036
2253
|
});
|
|
2254
|
+
currentRestart = void 0;
|
|
2255
|
+
currentTimeTravel = void 0;
|
|
2037
2256
|
if (currentResume && result.status !== "suspended") {
|
|
2038
2257
|
currentResume = void 0;
|
|
2039
2258
|
}
|
|
@@ -2121,7 +2340,9 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2121
2340
|
entry,
|
|
2122
2341
|
prevOutput,
|
|
2123
2342
|
stepResults,
|
|
2343
|
+
restart,
|
|
2124
2344
|
resume,
|
|
2345
|
+
timeTravel,
|
|
2125
2346
|
executionContext,
|
|
2126
2347
|
tracingContext,
|
|
2127
2348
|
emitter,
|
|
@@ -2190,6 +2411,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2190
2411
|
resourceId,
|
|
2191
2412
|
step,
|
|
2192
2413
|
stepResults,
|
|
2414
|
+
restart,
|
|
2415
|
+
timeTravel,
|
|
2193
2416
|
executionContext: { ...executionContext, foreachIndex: k },
|
|
2194
2417
|
resume: resumeToUse,
|
|
2195
2418
|
prevOutput: item,
|
|
@@ -2323,7 +2546,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2323
2546
|
status: workflowStatus,
|
|
2324
2547
|
value: executionContext.state,
|
|
2325
2548
|
context: stepResults,
|
|
2326
|
-
activePaths:
|
|
2549
|
+
activePaths: executionContext.executionPath,
|
|
2550
|
+
activeStepsPath: executionContext.activeStepsPath,
|
|
2327
2551
|
serializedStepGraph,
|
|
2328
2552
|
suspendedPaths: executionContext.suspendedPaths,
|
|
2329
2553
|
waitingPaths: {},
|
|
@@ -2344,6 +2568,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2344
2568
|
prevStep,
|
|
2345
2569
|
serializedStepGraph,
|
|
2346
2570
|
stepResults,
|
|
2571
|
+
restart,
|
|
2572
|
+
timeTravel,
|
|
2347
2573
|
resume,
|
|
2348
2574
|
executionContext,
|
|
2349
2575
|
tracingContext,
|
|
@@ -2364,6 +2590,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2364
2590
|
step,
|
|
2365
2591
|
stepResults,
|
|
2366
2592
|
executionContext,
|
|
2593
|
+
timeTravel,
|
|
2594
|
+
restart,
|
|
2367
2595
|
resume,
|
|
2368
2596
|
prevOutput,
|
|
2369
2597
|
tracingContext,
|
|
@@ -2392,6 +2620,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2392
2620
|
suspendedPaths: executionContext.suspendedPaths,
|
|
2393
2621
|
resumeLabels: executionContext.resumeLabels,
|
|
2394
2622
|
retryConfig: executionContext.retryConfig,
|
|
2623
|
+
activeStepsPath: executionContext.activeStepsPath,
|
|
2395
2624
|
state: executionContext.state
|
|
2396
2625
|
},
|
|
2397
2626
|
tracingContext,
|
|
@@ -2471,6 +2700,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2471
2700
|
prevStep,
|
|
2472
2701
|
stepResults,
|
|
2473
2702
|
serializedStepGraph,
|
|
2703
|
+
timeTravel,
|
|
2704
|
+
restart,
|
|
2474
2705
|
resume,
|
|
2475
2706
|
executionContext,
|
|
2476
2707
|
tracingContext,
|
|
@@ -2488,6 +2719,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2488
2719
|
prevOutput,
|
|
2489
2720
|
stepResults,
|
|
2490
2721
|
serializedStepGraph,
|
|
2722
|
+
timeTravel,
|
|
2723
|
+
restart,
|
|
2491
2724
|
resume,
|
|
2492
2725
|
executionContext,
|
|
2493
2726
|
tracingContext,
|
|
@@ -2505,6 +2738,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2505
2738
|
prevStep,
|
|
2506
2739
|
prevOutput,
|
|
2507
2740
|
stepResults,
|
|
2741
|
+
timeTravel,
|
|
2742
|
+
restart,
|
|
2508
2743
|
resume,
|
|
2509
2744
|
executionContext,
|
|
2510
2745
|
tracingContext,
|
|
@@ -2523,6 +2758,8 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2523
2758
|
prevStep,
|
|
2524
2759
|
prevOutput,
|
|
2525
2760
|
stepResults,
|
|
2761
|
+
timeTravel,
|
|
2762
|
+
restart,
|
|
2526
2763
|
resume,
|
|
2527
2764
|
executionContext,
|
|
2528
2765
|
tracingContext,
|
|
@@ -2544,6 +2781,12 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2544
2781
|
status: "waiting"
|
|
2545
2782
|
}
|
|
2546
2783
|
});
|
|
2784
|
+
stepResults[entry.id] = {
|
|
2785
|
+
status: "waiting",
|
|
2786
|
+
payload: prevOutput,
|
|
2787
|
+
startedAt
|
|
2788
|
+
};
|
|
2789
|
+
executionContext.activeStepsPath[entry.id] = executionContext.executionPath;
|
|
2547
2790
|
await this.persistStepUpdate({
|
|
2548
2791
|
workflowId,
|
|
2549
2792
|
runId,
|
|
@@ -2570,6 +2813,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2570
2813
|
requestContext,
|
|
2571
2814
|
writableStream
|
|
2572
2815
|
});
|
|
2816
|
+
delete executionContext.activeStepsPath[entry.id];
|
|
2573
2817
|
await this.persistStepUpdate({
|
|
2574
2818
|
workflowId,
|
|
2575
2819
|
runId,
|
|
@@ -2615,6 +2859,12 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2615
2859
|
status: "waiting"
|
|
2616
2860
|
}
|
|
2617
2861
|
});
|
|
2862
|
+
stepResults[entry.id] = {
|
|
2863
|
+
status: "waiting",
|
|
2864
|
+
payload: prevOutput,
|
|
2865
|
+
startedAt
|
|
2866
|
+
};
|
|
2867
|
+
executionContext.activeStepsPath[entry.id] = executionContext.executionPath;
|
|
2618
2868
|
await this.persistStepUpdate({
|
|
2619
2869
|
workflowId,
|
|
2620
2870
|
runId,
|
|
@@ -2641,6 +2891,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
2641
2891
|
requestContext,
|
|
2642
2892
|
writableStream
|
|
2643
2893
|
});
|
|
2894
|
+
delete executionContext.activeStepsPath[entry.id];
|
|
2644
2895
|
await this.persistStepUpdate({
|
|
2645
2896
|
workflowId,
|
|
2646
2897
|
runId,
|
|
@@ -2861,8 +3112,12 @@ function cloneStep(step, opts) {
|
|
|
2861
3112
|
description: step.description,
|
|
2862
3113
|
inputSchema: step.inputSchema,
|
|
2863
3114
|
outputSchema: step.outputSchema,
|
|
3115
|
+
suspendSchema: step.suspendSchema,
|
|
3116
|
+
resumeSchema: step.resumeSchema,
|
|
3117
|
+
stateSchema: step.stateSchema,
|
|
2864
3118
|
execute: step.execute,
|
|
2865
3119
|
retries: step.retries,
|
|
3120
|
+
scorers: step.scorers,
|
|
2866
3121
|
component: step.component
|
|
2867
3122
|
};
|
|
2868
3123
|
}
|
|
@@ -2875,7 +3130,8 @@ function cloneWorkflow(workflow, opts) {
|
|
|
2875
3130
|
inputSchema: workflow.inputSchema,
|
|
2876
3131
|
outputSchema: workflow.outputSchema,
|
|
2877
3132
|
steps: workflow.stepDefs,
|
|
2878
|
-
mastra: workflow.mastra
|
|
3133
|
+
mastra: workflow.mastra,
|
|
3134
|
+
options: workflow.options
|
|
2879
3135
|
});
|
|
2880
3136
|
wf.setStepFlow(workflow.stepGraph);
|
|
2881
3137
|
wf.commit();
|
|
@@ -2889,6 +3145,8 @@ var Workflow = class extends MastraBase {
|
|
|
2889
3145
|
stateSchema;
|
|
2890
3146
|
steps;
|
|
2891
3147
|
stepDefs;
|
|
3148
|
+
engineType = "default";
|
|
3149
|
+
#nestedWorkflowInput;
|
|
2892
3150
|
committed = false;
|
|
2893
3151
|
stepFlow;
|
|
2894
3152
|
serializedStepFlow;
|
|
@@ -2924,7 +3182,7 @@ var Workflow = class extends MastraBase {
|
|
|
2924
3182
|
this.steps = {};
|
|
2925
3183
|
this.stepDefs = steps;
|
|
2926
3184
|
this.#options = {
|
|
2927
|
-
validateInputs: options.validateInputs ??
|
|
3185
|
+
validateInputs: options.validateInputs ?? true,
|
|
2928
3186
|
shouldPersistSnapshot: options.shouldPersistSnapshot ?? (() => true),
|
|
2929
3187
|
tracingPolicy: options.tracingPolicy
|
|
2930
3188
|
};
|
|
@@ -2936,6 +3194,7 @@ var Workflow = class extends MastraBase {
|
|
|
2936
3194
|
} else {
|
|
2937
3195
|
this.executionEngine = executionEngine;
|
|
2938
3196
|
}
|
|
3197
|
+
this.engineType = "default";
|
|
2939
3198
|
this.#runs = /* @__PURE__ */ new Map();
|
|
2940
3199
|
}
|
|
2941
3200
|
get runs() {
|
|
@@ -3295,7 +3554,8 @@ var Workflow = class extends MastraBase {
|
|
|
3295
3554
|
cleanup: () => this.#runs.delete(runIdToUse),
|
|
3296
3555
|
tracingPolicy: this.#options?.tracingPolicy,
|
|
3297
3556
|
workflowSteps: this.steps,
|
|
3298
|
-
validateInputs: this.#options?.validateInputs
|
|
3557
|
+
validateInputs: this.#options?.validateInputs,
|
|
3558
|
+
workflowEngineType: this.engineType
|
|
3299
3559
|
});
|
|
3300
3560
|
this.#runs.set(runIdToUse, run);
|
|
3301
3561
|
const shouldPersistSnapshot = this.#options.shouldPersistSnapshot({
|
|
@@ -3312,8 +3572,9 @@ var Workflow = class extends MastraBase {
|
|
|
3312
3572
|
runId: runIdToUse,
|
|
3313
3573
|
status: "pending",
|
|
3314
3574
|
value: {},
|
|
3315
|
-
context: {},
|
|
3575
|
+
context: this.#nestedWorkflowInput ? { input: this.#nestedWorkflowInput } : {},
|
|
3316
3576
|
activePaths: [],
|
|
3577
|
+
activeStepsPath: {},
|
|
3317
3578
|
serializedStepGraph: this.serializedStepGraph,
|
|
3318
3579
|
suspendedPaths: {},
|
|
3319
3580
|
resumeLabels: {},
|
|
@@ -3357,7 +3618,9 @@ var Workflow = class extends MastraBase {
|
|
|
3357
3618
|
state,
|
|
3358
3619
|
setState,
|
|
3359
3620
|
suspend,
|
|
3621
|
+
restart,
|
|
3360
3622
|
resume,
|
|
3623
|
+
timeTravel,
|
|
3361
3624
|
[EMITTER_SYMBOL]: emitter,
|
|
3362
3625
|
mastra,
|
|
3363
3626
|
requestContext,
|
|
@@ -3369,17 +3632,20 @@ var Workflow = class extends MastraBase {
|
|
|
3369
3632
|
validateInputs
|
|
3370
3633
|
}) {
|
|
3371
3634
|
this.__registerMastra(mastra);
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
}
|
|
3635
|
+
const effectiveValidateInputs = validateInputs ?? this.#options.validateInputs ?? true;
|
|
3636
|
+
this.#options = {
|
|
3637
|
+
...this.#options || {},
|
|
3638
|
+
validateInputs: effectiveValidateInputs
|
|
3639
|
+
};
|
|
3378
3640
|
this.executionEngine.options = {
|
|
3379
3641
|
...this.executionEngine.options || {},
|
|
3380
|
-
validateInputs:
|
|
3642
|
+
validateInputs: effectiveValidateInputs
|
|
3381
3643
|
};
|
|
3382
3644
|
const isResume = !!(resume?.steps && resume.steps.length > 0) || !!resume?.label || !!(resume?.steps && resume.steps.length === 0 && (!retryCount || retryCount === 0));
|
|
3645
|
+
if (!restart && !isResume) {
|
|
3646
|
+
this.#nestedWorkflowInput = inputData;
|
|
3647
|
+
}
|
|
3648
|
+
const isTimeTravel = !!(timeTravel && timeTravel.steps.length > 0);
|
|
3383
3649
|
const run = isResume ? await this.createRun({ runId: resume.runId }) : await this.createRun({ runId });
|
|
3384
3650
|
const nestedAbortCb = () => {
|
|
3385
3651
|
abort();
|
|
@@ -3395,21 +3661,41 @@ var Workflow = class extends MastraBase {
|
|
|
3395
3661
|
if (retryCount && retryCount > 0 && isResume && requestContext) {
|
|
3396
3662
|
requestContext.set("__mastraWorflowInputData", inputData);
|
|
3397
3663
|
}
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
})
|
|
3664
|
+
let res;
|
|
3665
|
+
if (isTimeTravel) {
|
|
3666
|
+
res = await run.timeTravel({
|
|
3667
|
+
inputData: timeTravel?.inputData,
|
|
3668
|
+
resumeData: timeTravel?.resumeData,
|
|
3669
|
+
initialState: state,
|
|
3670
|
+
step: timeTravel?.steps,
|
|
3671
|
+
context: timeTravel?.nestedStepResults?.[this.id] ?? {},
|
|
3672
|
+
nestedStepsContext: timeTravel?.nestedStepResults,
|
|
3673
|
+
requestContext,
|
|
3674
|
+
tracingContext,
|
|
3675
|
+
writableStream: writer,
|
|
3676
|
+
outputOptions: { includeState: true, includeResumeLabels: true }
|
|
3677
|
+
});
|
|
3678
|
+
} else if (restart) {
|
|
3679
|
+
res = await run.restart({ requestContext, tracingContext, writableStream: writer });
|
|
3680
|
+
} else if (isResume) {
|
|
3681
|
+
res = await run.resume({
|
|
3682
|
+
resumeData,
|
|
3683
|
+
step: resume.steps?.length > 0 ? resume.steps : void 0,
|
|
3684
|
+
requestContext,
|
|
3685
|
+
tracingContext,
|
|
3686
|
+
outputOptions: { includeState: true, includeResumeLabels: true },
|
|
3687
|
+
label: resume.label
|
|
3688
|
+
});
|
|
3689
|
+
} else {
|
|
3690
|
+
res = await run.start({
|
|
3691
|
+
inputData,
|
|
3692
|
+
requestContext,
|
|
3693
|
+
tracingContext,
|
|
3694
|
+
writableStream: writer,
|
|
3695
|
+
initialState: state,
|
|
3696
|
+
outputOptions: { includeState: true, includeResumeLabels: true }
|
|
3697
|
+
});
|
|
3698
|
+
}
|
|
3413
3699
|
unwatch();
|
|
3414
3700
|
const suspendedSteps = Object.entries(res.steps).filter(([_stepName, stepResult]) => {
|
|
3415
3701
|
const stepRes = stepResult;
|
|
@@ -3445,6 +3731,35 @@ var Workflow = class extends MastraBase {
|
|
|
3445
3731
|
}
|
|
3446
3732
|
return storage.listWorkflowRuns({ workflowName: this.id, ...args ?? {} });
|
|
3447
3733
|
}
|
|
3734
|
+
async listActiveWorkflowRuns() {
|
|
3735
|
+
const runningRuns = await this.listWorkflowRuns({ status: "running" });
|
|
3736
|
+
const waitingRuns = await this.listWorkflowRuns({ status: "waiting" });
|
|
3737
|
+
return {
|
|
3738
|
+
runs: [...runningRuns.runs, ...waitingRuns.runs],
|
|
3739
|
+
total: runningRuns.total + waitingRuns.total
|
|
3740
|
+
};
|
|
3741
|
+
}
|
|
3742
|
+
async restartAllActiveWorkflowRuns() {
|
|
3743
|
+
if (this.engineType !== "default") {
|
|
3744
|
+
this.logger.debug(`Cannot restart active workflow runs for ${this.engineType} engine`);
|
|
3745
|
+
return;
|
|
3746
|
+
}
|
|
3747
|
+
const activeRuns = await this.listActiveWorkflowRuns();
|
|
3748
|
+
if (activeRuns.runs.length > 0) {
|
|
3749
|
+
this.logger.debug(
|
|
3750
|
+
`Restarting ${activeRuns.runs.length} active workflow run${activeRuns.runs.length > 1 ? "s" : ""}`
|
|
3751
|
+
);
|
|
3752
|
+
}
|
|
3753
|
+
for (const runSnapshot of activeRuns.runs) {
|
|
3754
|
+
try {
|
|
3755
|
+
const run = await this.createRun({ runId: runSnapshot.runId });
|
|
3756
|
+
await run.restart();
|
|
3757
|
+
this.logger.debug(`Restarted ${this.id} workflow run ${runSnapshot.runId}`);
|
|
3758
|
+
} catch (error) {
|
|
3759
|
+
this.logger.error(`Failed to restart ${this.id} workflow run ${runSnapshot.runId}: ${error}`);
|
|
3760
|
+
}
|
|
3761
|
+
}
|
|
3762
|
+
}
|
|
3448
3763
|
async getWorkflowRunById(runId) {
|
|
3449
3764
|
const storage = this.#mastra?.getStorage();
|
|
3450
3765
|
if (!storage) {
|
|
@@ -3520,7 +3835,9 @@ var Workflow = class extends MastraBase {
|
|
|
3520
3835
|
result: snapshot.result,
|
|
3521
3836
|
error: snapshot.error,
|
|
3522
3837
|
payload: snapshot.context?.input,
|
|
3523
|
-
steps: fullSteps
|
|
3838
|
+
steps: fullSteps,
|
|
3839
|
+
activeStepsPath: snapshot.activeStepsPath,
|
|
3840
|
+
serializedStepGraph: snapshot.serializedStepGraph
|
|
3524
3841
|
};
|
|
3525
3842
|
}
|
|
3526
3843
|
};
|
|
@@ -3572,6 +3889,7 @@ var Run = class {
|
|
|
3572
3889
|
*/
|
|
3573
3890
|
workflowSteps;
|
|
3574
3891
|
workflowRunStatus;
|
|
3892
|
+
workflowEngineType;
|
|
3575
3893
|
/**
|
|
3576
3894
|
* The storage for this run
|
|
3577
3895
|
*/
|
|
@@ -3603,6 +3921,7 @@ var Run = class {
|
|
|
3603
3921
|
this.validateInputs = params.validateInputs;
|
|
3604
3922
|
this.stateSchema = params.stateSchema;
|
|
3605
3923
|
this.workflowRunStatus = "pending";
|
|
3924
|
+
this.workflowEngineType = params.workflowEngineType;
|
|
3606
3925
|
}
|
|
3607
3926
|
get abortController() {
|
|
3608
3927
|
if (!this.#abortController) {
|
|
@@ -3675,6 +3994,20 @@ var Run = class {
|
|
|
3675
3994
|
}
|
|
3676
3995
|
return resumeDataToUse;
|
|
3677
3996
|
}
|
|
3997
|
+
async _validateTimetravelInputData(inputData, step) {
|
|
3998
|
+
let inputDataToUse = inputData;
|
|
3999
|
+
if (step && step.inputSchema && this.validateInputs) {
|
|
4000
|
+
const inputSchema = step.inputSchema;
|
|
4001
|
+
const validatedInputData = await inputSchema.safeParseAsync(inputData);
|
|
4002
|
+
if (!validatedInputData.success) {
|
|
4003
|
+
const errors = getZodErrors(validatedInputData.error);
|
|
4004
|
+
const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
|
|
4005
|
+
throw new Error("Invalid inputData: \n" + errorMessages);
|
|
4006
|
+
}
|
|
4007
|
+
inputDataToUse = validatedInputData.data;
|
|
4008
|
+
}
|
|
4009
|
+
return inputDataToUse;
|
|
4010
|
+
}
|
|
3678
4011
|
async _start({
|
|
3679
4012
|
inputData,
|
|
3680
4013
|
initialState,
|
|
@@ -4100,6 +4433,13 @@ var Run = class {
|
|
|
4100
4433
|
async resume(params) {
|
|
4101
4434
|
return this._resume(params);
|
|
4102
4435
|
}
|
|
4436
|
+
/**
|
|
4437
|
+
* Restarts the workflow execution that was previously active
|
|
4438
|
+
* @returns A promise that resolves to the workflow output
|
|
4439
|
+
*/
|
|
4440
|
+
async restart(args = {}) {
|
|
4441
|
+
return this._restart(args);
|
|
4442
|
+
}
|
|
4103
4443
|
async _resume(params) {
|
|
4104
4444
|
const snapshot = await this.#mastra?.getStorage()?.loadWorkflowSnapshot({
|
|
4105
4445
|
workflowName: this.workflowId,
|
|
@@ -4167,7 +4507,7 @@ var Run = class {
|
|
|
4167
4507
|
params.requestContext.delete("__mastraWorflowInputData");
|
|
4168
4508
|
}
|
|
4169
4509
|
const stepResults = { ...snapshot?.context ?? {}, input: requestContextInput ?? snapshot?.context?.input };
|
|
4170
|
-
|
|
4510
|
+
const requestContextToUse = params.requestContext ?? new RequestContext();
|
|
4171
4511
|
Object.entries(snapshot?.requestContext ?? {}).forEach(([key, value]) => {
|
|
4172
4512
|
if (!requestContextToUse.has(key)) {
|
|
4173
4513
|
requestContextToUse.set(key, value);
|
|
@@ -4234,14 +4574,306 @@ var Run = class {
|
|
|
4234
4574
|
this.closeStreamAction?.().catch(() => {
|
|
4235
4575
|
});
|
|
4236
4576
|
}
|
|
4237
|
-
result.traceId = traceId;
|
|
4238
|
-
return result;
|
|
4577
|
+
result.traceId = traceId;
|
|
4578
|
+
return result;
|
|
4579
|
+
});
|
|
4580
|
+
this.executionResults = executionResultPromise;
|
|
4581
|
+
return executionResultPromise.then((result) => {
|
|
4582
|
+
this.streamOutput?.updateResults(result);
|
|
4583
|
+
return result;
|
|
4584
|
+
});
|
|
4585
|
+
}
|
|
4586
|
+
async _restart({
|
|
4587
|
+
requestContext,
|
|
4588
|
+
writableStream,
|
|
4589
|
+
tracingContext,
|
|
4590
|
+
tracingOptions
|
|
4591
|
+
}) {
|
|
4592
|
+
if (this.workflowEngineType !== "default") {
|
|
4593
|
+
throw new Error(`restart() is not supported on ${this.workflowEngineType} workflows`);
|
|
4594
|
+
}
|
|
4595
|
+
const snapshot = await this.#mastra?.getStorage()?.loadWorkflowSnapshot({
|
|
4596
|
+
workflowName: this.workflowId,
|
|
4597
|
+
runId: this.runId
|
|
4598
|
+
});
|
|
4599
|
+
let nestedWorkflowPending = false;
|
|
4600
|
+
if (!snapshot) {
|
|
4601
|
+
throw new Error(`Snapshot not found for run ${this.runId}`);
|
|
4602
|
+
}
|
|
4603
|
+
if (snapshot.status !== "running" && snapshot.status !== "waiting") {
|
|
4604
|
+
if (snapshot.status === "pending" && !!snapshot.context.input) {
|
|
4605
|
+
nestedWorkflowPending = true;
|
|
4606
|
+
} else {
|
|
4607
|
+
throw new Error("This workflow run was not active");
|
|
4608
|
+
}
|
|
4609
|
+
}
|
|
4610
|
+
let nestedWorkflowActiveStepsPath = {};
|
|
4611
|
+
const firstEntry = this.executionGraph.steps[0];
|
|
4612
|
+
if (firstEntry.type === "step" || firstEntry.type === "foreach" || firstEntry.type === "loop") {
|
|
4613
|
+
nestedWorkflowActiveStepsPath = {
|
|
4614
|
+
[firstEntry.step.id]: [0]
|
|
4615
|
+
};
|
|
4616
|
+
} else if (firstEntry.type === "sleep" || firstEntry.type === "sleepUntil") {
|
|
4617
|
+
nestedWorkflowActiveStepsPath = {
|
|
4618
|
+
[firstEntry.id]: [0]
|
|
4619
|
+
};
|
|
4620
|
+
} else if (firstEntry.type === "conditional" || firstEntry.type === "parallel") {
|
|
4621
|
+
nestedWorkflowActiveStepsPath = firstEntry.steps.reduce(
|
|
4622
|
+
(acc, step) => {
|
|
4623
|
+
acc[step.step.id] = [0];
|
|
4624
|
+
return acc;
|
|
4625
|
+
},
|
|
4626
|
+
{}
|
|
4627
|
+
);
|
|
4628
|
+
}
|
|
4629
|
+
const restartData = {
|
|
4630
|
+
activePaths: nestedWorkflowPending ? [0] : snapshot.activePaths,
|
|
4631
|
+
activeStepsPath: nestedWorkflowPending ? nestedWorkflowActiveStepsPath : snapshot.activeStepsPath,
|
|
4632
|
+
stepResults: snapshot.context,
|
|
4633
|
+
state: snapshot.value
|
|
4634
|
+
};
|
|
4635
|
+
const requestContextToUse = requestContext ?? new RequestContext();
|
|
4636
|
+
for (const [key, value] of Object.entries(snapshot.requestContext ?? {})) {
|
|
4637
|
+
if (!requestContextToUse.has(key)) {
|
|
4638
|
+
requestContextToUse.set(key, value);
|
|
4639
|
+
}
|
|
4640
|
+
}
|
|
4641
|
+
const workflowSpan = getOrCreateSpan({
|
|
4642
|
+
type: "workflow_run" /* WORKFLOW_RUN */,
|
|
4643
|
+
name: `workflow run: '${this.workflowId}'`,
|
|
4644
|
+
attributes: {
|
|
4645
|
+
workflowId: this.workflowId
|
|
4646
|
+
},
|
|
4647
|
+
metadata: {
|
|
4648
|
+
resourceId: this.resourceId,
|
|
4649
|
+
runId: this.runId
|
|
4650
|
+
},
|
|
4651
|
+
tracingPolicy: this.tracingPolicy,
|
|
4652
|
+
tracingOptions,
|
|
4653
|
+
tracingContext,
|
|
4654
|
+
requestContext: requestContextToUse,
|
|
4655
|
+
mastra: this.#mastra
|
|
4656
|
+
});
|
|
4657
|
+
const traceId = workflowSpan?.externalTraceId;
|
|
4658
|
+
const result = await this.executionEngine.execute({
|
|
4659
|
+
workflowId: this.workflowId,
|
|
4660
|
+
runId: this.runId,
|
|
4661
|
+
resourceId: this.resourceId,
|
|
4662
|
+
disableScorers: this.disableScorers,
|
|
4663
|
+
graph: this.executionGraph,
|
|
4664
|
+
serializedStepGraph: this.serializedStepGraph,
|
|
4665
|
+
restart: restartData,
|
|
4666
|
+
emitter: {
|
|
4667
|
+
emit: async (event, data) => {
|
|
4668
|
+
this.emitter.emit(event, data);
|
|
4669
|
+
},
|
|
4670
|
+
on: (event, callback) => {
|
|
4671
|
+
this.emitter.on(event, callback);
|
|
4672
|
+
},
|
|
4673
|
+
off: (event, callback) => {
|
|
4674
|
+
this.emitter.off(event, callback);
|
|
4675
|
+
},
|
|
4676
|
+
once: (event, callback) => {
|
|
4677
|
+
this.emitter.once(event, callback);
|
|
4678
|
+
}
|
|
4679
|
+
},
|
|
4680
|
+
retryConfig: this.retryConfig,
|
|
4681
|
+
requestContext: requestContextToUse,
|
|
4682
|
+
abortController: this.abortController,
|
|
4683
|
+
writableStream,
|
|
4684
|
+
workflowSpan
|
|
4685
|
+
});
|
|
4686
|
+
if (result.status !== "suspended") {
|
|
4687
|
+
this.cleanup?.();
|
|
4688
|
+
}
|
|
4689
|
+
result.traceId = traceId;
|
|
4690
|
+
return result;
|
|
4691
|
+
}
|
|
4692
|
+
async _timeTravel({
|
|
4693
|
+
inputData,
|
|
4694
|
+
resumeData,
|
|
4695
|
+
initialState,
|
|
4696
|
+
step: stepParam,
|
|
4697
|
+
context,
|
|
4698
|
+
nestedStepsContext,
|
|
4699
|
+
requestContext,
|
|
4700
|
+
writableStream,
|
|
4701
|
+
tracingContext,
|
|
4702
|
+
tracingOptions,
|
|
4703
|
+
outputOptions
|
|
4704
|
+
}) {
|
|
4705
|
+
if (!stepParam || Array.isArray(stepParam) && stepParam.length === 0) {
|
|
4706
|
+
throw new Error("Step is required and must be a valid step or array of steps");
|
|
4707
|
+
}
|
|
4708
|
+
const snapshot = await this.#mastra?.getStorage()?.loadWorkflowSnapshot({
|
|
4709
|
+
workflowName: this.workflowId,
|
|
4710
|
+
runId: this.runId
|
|
4711
|
+
});
|
|
4712
|
+
if (!snapshot) {
|
|
4713
|
+
throw new Error(`Snapshot not found for run ${this.runId}`);
|
|
4714
|
+
}
|
|
4715
|
+
if (snapshot.status === "running") {
|
|
4716
|
+
throw new Error("This workflow run is still running, cannot time travel");
|
|
4717
|
+
}
|
|
4718
|
+
let steps;
|
|
4719
|
+
let newStepParam = stepParam;
|
|
4720
|
+
if (typeof stepParam === "string") {
|
|
4721
|
+
newStepParam = stepParam.split(".");
|
|
4722
|
+
}
|
|
4723
|
+
steps = (Array.isArray(newStepParam) ? newStepParam : [newStepParam]).map(
|
|
4724
|
+
(step) => typeof step === "string" ? step : step?.id
|
|
4725
|
+
);
|
|
4726
|
+
let inputDataToUse = inputData;
|
|
4727
|
+
if (inputDataToUse && steps.length === 1) {
|
|
4728
|
+
inputDataToUse = await this._validateTimetravelInputData(inputData, this.workflowSteps[steps[0]]);
|
|
4729
|
+
}
|
|
4730
|
+
const timeTravelData = createTimeTravelExecutionParams({
|
|
4731
|
+
steps,
|
|
4732
|
+
inputData: inputDataToUse,
|
|
4733
|
+
resumeData,
|
|
4734
|
+
context,
|
|
4735
|
+
nestedStepsContext,
|
|
4736
|
+
snapshot,
|
|
4737
|
+
initialState,
|
|
4738
|
+
graph: this.executionGraph
|
|
4739
|
+
});
|
|
4740
|
+
const requestContextToUse = requestContext ?? new RequestContext();
|
|
4741
|
+
for (const [key, value] of Object.entries(snapshot.requestContext ?? {})) {
|
|
4742
|
+
if (!requestContextToUse.has(key)) {
|
|
4743
|
+
requestContextToUse.set(key, value);
|
|
4744
|
+
}
|
|
4745
|
+
}
|
|
4746
|
+
const workflowSpan = getOrCreateSpan({
|
|
4747
|
+
type: "workflow_run" /* WORKFLOW_RUN */,
|
|
4748
|
+
name: `workflow run: '${this.workflowId}'`,
|
|
4749
|
+
input: inputData,
|
|
4750
|
+
attributes: {
|
|
4751
|
+
workflowId: this.workflowId
|
|
4752
|
+
},
|
|
4753
|
+
metadata: {
|
|
4754
|
+
resourceId: this.resourceId,
|
|
4755
|
+
runId: this.runId
|
|
4756
|
+
},
|
|
4757
|
+
tracingPolicy: this.tracingPolicy,
|
|
4758
|
+
tracingOptions,
|
|
4759
|
+
tracingContext,
|
|
4760
|
+
requestContext: requestContextToUse,
|
|
4761
|
+
mastra: this.#mastra
|
|
4762
|
+
});
|
|
4763
|
+
const traceId = workflowSpan?.externalTraceId;
|
|
4764
|
+
const result = await this.executionEngine.execute({
|
|
4765
|
+
workflowId: this.workflowId,
|
|
4766
|
+
runId: this.runId,
|
|
4767
|
+
resourceId: this.resourceId,
|
|
4768
|
+
disableScorers: this.disableScorers,
|
|
4769
|
+
graph: this.executionGraph,
|
|
4770
|
+
timeTravel: timeTravelData,
|
|
4771
|
+
serializedStepGraph: this.serializedStepGraph,
|
|
4772
|
+
emitter: {
|
|
4773
|
+
emit: async (event, data) => {
|
|
4774
|
+
this.emitter.emit(event, data);
|
|
4775
|
+
},
|
|
4776
|
+
on: (event, callback) => {
|
|
4777
|
+
this.emitter.on(event, callback);
|
|
4778
|
+
},
|
|
4779
|
+
off: (event, callback) => {
|
|
4780
|
+
this.emitter.off(event, callback);
|
|
4781
|
+
},
|
|
4782
|
+
once: (event, callback) => {
|
|
4783
|
+
this.emitter.once(event, callback);
|
|
4784
|
+
}
|
|
4785
|
+
},
|
|
4786
|
+
retryConfig: this.retryConfig,
|
|
4787
|
+
requestContext: requestContextToUse,
|
|
4788
|
+
abortController: this.abortController,
|
|
4789
|
+
writableStream,
|
|
4790
|
+
workflowSpan,
|
|
4791
|
+
outputOptions
|
|
4792
|
+
});
|
|
4793
|
+
if (result.status !== "suspended") {
|
|
4794
|
+
this.cleanup?.();
|
|
4795
|
+
}
|
|
4796
|
+
result.traceId = traceId;
|
|
4797
|
+
return result;
|
|
4798
|
+
}
|
|
4799
|
+
async timeTravel(args) {
|
|
4800
|
+
return this._timeTravel(args);
|
|
4801
|
+
}
|
|
4802
|
+
timeTravelStream({
|
|
4803
|
+
inputData,
|
|
4804
|
+
resumeData,
|
|
4805
|
+
initialState,
|
|
4806
|
+
step,
|
|
4807
|
+
context,
|
|
4808
|
+
nestedStepsContext,
|
|
4809
|
+
requestContext,
|
|
4810
|
+
tracingContext,
|
|
4811
|
+
tracingOptions,
|
|
4812
|
+
outputOptions
|
|
4813
|
+
}) {
|
|
4814
|
+
this.closeStreamAction = async () => {
|
|
4815
|
+
};
|
|
4816
|
+
const self = this;
|
|
4817
|
+
const stream = new ReadableStream$1({
|
|
4818
|
+
async start(controller) {
|
|
4819
|
+
const unwatch = self.watch(async ({ type, from = "WORKFLOW" /* WORKFLOW */, payload }) => {
|
|
4820
|
+
controller.enqueue({
|
|
4821
|
+
type,
|
|
4822
|
+
runId: self.runId,
|
|
4823
|
+
from,
|
|
4824
|
+
payload: {
|
|
4825
|
+
stepName: payload.id,
|
|
4826
|
+
...payload
|
|
4827
|
+
}
|
|
4828
|
+
});
|
|
4829
|
+
});
|
|
4830
|
+
self.closeStreamAction = async () => {
|
|
4831
|
+
unwatch();
|
|
4832
|
+
try {
|
|
4833
|
+
await controller.close();
|
|
4834
|
+
} catch (err) {
|
|
4835
|
+
console.error("Error closing stream:", err);
|
|
4836
|
+
}
|
|
4837
|
+
};
|
|
4838
|
+
const executionResultsPromise = self._timeTravel({
|
|
4839
|
+
inputData,
|
|
4840
|
+
step,
|
|
4841
|
+
context,
|
|
4842
|
+
nestedStepsContext,
|
|
4843
|
+
resumeData,
|
|
4844
|
+
initialState,
|
|
4845
|
+
requestContext,
|
|
4846
|
+
tracingContext,
|
|
4847
|
+
tracingOptions,
|
|
4848
|
+
writableStream: new WritableStream$1({
|
|
4849
|
+
write(chunk) {
|
|
4850
|
+
controller.enqueue(chunk);
|
|
4851
|
+
}
|
|
4852
|
+
}),
|
|
4853
|
+
outputOptions
|
|
4854
|
+
});
|
|
4855
|
+
self.executionResults = executionResultsPromise;
|
|
4856
|
+
let executionResults;
|
|
4857
|
+
try {
|
|
4858
|
+
executionResults = await executionResultsPromise;
|
|
4859
|
+
self.closeStreamAction?.().catch(() => {
|
|
4860
|
+
});
|
|
4861
|
+
if (self.streamOutput) {
|
|
4862
|
+
self.streamOutput.updateResults(executionResults);
|
|
4863
|
+
}
|
|
4864
|
+
} catch (err) {
|
|
4865
|
+
self.streamOutput?.rejectResults(err);
|
|
4866
|
+
self.closeStreamAction?.().catch(() => {
|
|
4867
|
+
});
|
|
4868
|
+
}
|
|
4869
|
+
}
|
|
4239
4870
|
});
|
|
4240
|
-
this.
|
|
4241
|
-
|
|
4242
|
-
this.
|
|
4243
|
-
|
|
4871
|
+
this.streamOutput = new WorkflowRunOutput({
|
|
4872
|
+
runId: this.runId,
|
|
4873
|
+
workflowId: this.workflowId,
|
|
4874
|
+
stream
|
|
4244
4875
|
});
|
|
4876
|
+
return this.streamOutput;
|
|
4245
4877
|
}
|
|
4246
4878
|
/**
|
|
4247
4879
|
* @access private
|
|
@@ -4868,7 +5500,8 @@ function execute({
|
|
|
4868
5500
|
modelSettings,
|
|
4869
5501
|
structuredOutput,
|
|
4870
5502
|
headers,
|
|
4871
|
-
shouldThrowError
|
|
5503
|
+
shouldThrowError,
|
|
5504
|
+
methodType
|
|
4872
5505
|
}) {
|
|
4873
5506
|
const v5 = new AISDKV5InputStream({
|
|
4874
5507
|
component: "LLM",
|
|
@@ -4916,7 +5549,8 @@ You don't need to format your response as JSON unless the user asks you to. Just
|
|
|
4916
5549
|
const pRetry = await import('p-retry');
|
|
4917
5550
|
return await pRetry.default(
|
|
4918
5551
|
async () => {
|
|
4919
|
-
const
|
|
5552
|
+
const fn = (methodType === "stream" ? model.doStream : model.doGenerate).bind(model);
|
|
5553
|
+
const streamResult = await fn({
|
|
4920
5554
|
...toolsAndToolChoice,
|
|
4921
5555
|
prompt,
|
|
4922
5556
|
providerOptions: providerOptionsToUse,
|
|
@@ -4940,10 +5574,6 @@ You don't need to format your response as JSON unless the user asks you to. Just
|
|
|
4940
5574
|
}
|
|
4941
5575
|
);
|
|
4942
5576
|
} catch (error) {
|
|
4943
|
-
const abortSignal = options?.abortSignal;
|
|
4944
|
-
if (isAbortError(error) && abortSignal?.aborted) {
|
|
4945
|
-
console.error("Abort error", error);
|
|
4946
|
-
}
|
|
4947
5577
|
if (shouldThrowError) {
|
|
4948
5578
|
throw error;
|
|
4949
5579
|
}
|
|
@@ -5099,23 +5729,22 @@ async function processOutputStream({
|
|
|
5099
5729
|
if (runState.state.textDeltas.length) {
|
|
5100
5730
|
const textStartPayload = chunk.payload;
|
|
5101
5731
|
const providerMetadata = textStartPayload.providerMetadata ?? runState.state.providerOptions;
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5732
|
+
const message = {
|
|
5733
|
+
id: messageId,
|
|
5734
|
+
role: "assistant",
|
|
5735
|
+
content: {
|
|
5736
|
+
format: 2,
|
|
5737
|
+
parts: [
|
|
5738
|
+
{
|
|
5108
5739
|
type: "text",
|
|
5109
5740
|
text: runState.state.textDeltas.join(""),
|
|
5110
|
-
|
|
5111
|
-
} : {
|
|
5112
|
-
type: "text",
|
|
5113
|
-
text: runState.state.textDeltas.join("")
|
|
5741
|
+
...providerMetadata ? { providerMetadata } : {}
|
|
5114
5742
|
}
|
|
5115
5743
|
]
|
|
5116
5744
|
},
|
|
5117
|
-
|
|
5118
|
-
|
|
5745
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
5746
|
+
};
|
|
5747
|
+
messageList.add(message, "response");
|
|
5119
5748
|
}
|
|
5120
5749
|
runState.setState({
|
|
5121
5750
|
isStreaming: false,
|
|
@@ -5195,20 +5824,23 @@ async function processOutputStream({
|
|
|
5195
5824
|
providerOptions: chunk.payload.providerMetadata ?? runState.state.providerOptions
|
|
5196
5825
|
});
|
|
5197
5826
|
if (Object.values(chunk.payload.providerMetadata || {}).find((v) => v?.redactedData)) {
|
|
5198
|
-
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5827
|
+
const message = {
|
|
5828
|
+
id: messageId,
|
|
5829
|
+
role: "assistant",
|
|
5830
|
+
content: {
|
|
5831
|
+
format: 2,
|
|
5832
|
+
parts: [
|
|
5203
5833
|
{
|
|
5204
5834
|
type: "reasoning",
|
|
5205
|
-
|
|
5206
|
-
|
|
5835
|
+
reasoning: "",
|
|
5836
|
+
details: [{ type: "redacted", data: "" }],
|
|
5837
|
+
providerMetadata: chunk.payload.providerMetadata ?? runState.state.providerOptions
|
|
5207
5838
|
}
|
|
5208
5839
|
]
|
|
5209
5840
|
},
|
|
5210
|
-
|
|
5211
|
-
|
|
5841
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
5842
|
+
};
|
|
5843
|
+
messageList.add(message, "response");
|
|
5212
5844
|
if (isControllerOpen(controller)) {
|
|
5213
5845
|
controller.enqueue(chunk);
|
|
5214
5846
|
}
|
|
@@ -5234,20 +5866,23 @@ async function processOutputStream({
|
|
|
5234
5866
|
}
|
|
5235
5867
|
case "reasoning-end": {
|
|
5236
5868
|
if (runState.state.reasoningDeltas.length > 0) {
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5869
|
+
const message = {
|
|
5870
|
+
id: messageId,
|
|
5871
|
+
role: "assistant",
|
|
5872
|
+
content: {
|
|
5873
|
+
format: 2,
|
|
5874
|
+
parts: [
|
|
5242
5875
|
{
|
|
5243
5876
|
type: "reasoning",
|
|
5244
|
-
|
|
5245
|
-
|
|
5877
|
+
reasoning: "",
|
|
5878
|
+
details: [{ type: "text", text: runState.state.reasoningDeltas.join("") }],
|
|
5879
|
+
providerMetadata: chunk.payload.providerMetadata ?? runState.state.providerOptions
|
|
5246
5880
|
}
|
|
5247
5881
|
]
|
|
5248
5882
|
},
|
|
5249
|
-
|
|
5250
|
-
|
|
5883
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
5884
|
+
};
|
|
5885
|
+
messageList.add(message, "response");
|
|
5251
5886
|
}
|
|
5252
5887
|
runState.setState({
|
|
5253
5888
|
isReasoning: false,
|
|
@@ -5259,25 +5894,31 @@ async function processOutputStream({
|
|
|
5259
5894
|
break;
|
|
5260
5895
|
}
|
|
5261
5896
|
case "file":
|
|
5262
|
-
|
|
5263
|
-
{
|
|
5897
|
+
{
|
|
5898
|
+
const message = {
|
|
5264
5899
|
id: messageId,
|
|
5265
5900
|
role: "assistant",
|
|
5266
|
-
content:
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5271
|
-
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5901
|
+
content: {
|
|
5902
|
+
format: 2,
|
|
5903
|
+
parts: [
|
|
5904
|
+
{
|
|
5905
|
+
type: "file",
|
|
5906
|
+
// @ts-expect-error
|
|
5907
|
+
data: chunk.payload.data,
|
|
5908
|
+
// TODO: incorrect string type
|
|
5909
|
+
mimeType: chunk.payload.mimeType
|
|
5910
|
+
}
|
|
5911
|
+
]
|
|
5912
|
+
},
|
|
5913
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
5914
|
+
};
|
|
5915
|
+
messageList.add(message, "response");
|
|
5916
|
+
controller.enqueue(chunk);
|
|
5917
|
+
}
|
|
5277
5918
|
break;
|
|
5278
5919
|
case "source":
|
|
5279
|
-
|
|
5280
|
-
{
|
|
5920
|
+
{
|
|
5921
|
+
const message = {
|
|
5281
5922
|
id: messageId,
|
|
5282
5923
|
role: "assistant",
|
|
5283
5924
|
content: {
|
|
@@ -5296,10 +5937,10 @@ async function processOutputStream({
|
|
|
5296
5937
|
]
|
|
5297
5938
|
},
|
|
5298
5939
|
createdAt: /* @__PURE__ */ new Date()
|
|
5299
|
-
}
|
|
5300
|
-
"response"
|
|
5301
|
-
|
|
5302
|
-
|
|
5940
|
+
};
|
|
5941
|
+
messageList.add(message, "response");
|
|
5942
|
+
controller.enqueue(chunk);
|
|
5943
|
+
}
|
|
5303
5944
|
break;
|
|
5304
5945
|
case "finish":
|
|
5305
5946
|
runState.setState({
|
|
@@ -5415,7 +6056,8 @@ function createLLMExecutionStep({
|
|
|
5415
6056
|
headers,
|
|
5416
6057
|
downloadRetries,
|
|
5417
6058
|
downloadConcurrency,
|
|
5418
|
-
processorStates
|
|
6059
|
+
processorStates,
|
|
6060
|
+
methodType
|
|
5419
6061
|
}) {
|
|
5420
6062
|
return createStep({
|
|
5421
6063
|
id: "llm-execution",
|
|
@@ -5494,6 +6136,7 @@ function createLLMExecutionStep({
|
|
|
5494
6136
|
includeRawChunks,
|
|
5495
6137
|
structuredOutput,
|
|
5496
6138
|
headers,
|
|
6139
|
+
methodType,
|
|
5497
6140
|
onResult: ({
|
|
5498
6141
|
warnings: warningsFromStream,
|
|
5499
6142
|
request: requestFromStream,
|
|
@@ -5636,24 +6279,27 @@ function createLLMExecutionStep({
|
|
|
5636
6279
|
return chunk.payload;
|
|
5637
6280
|
});
|
|
5638
6281
|
if (toolCalls.length > 0) {
|
|
5639
|
-
const
|
|
5640
|
-
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
6282
|
+
const message = {
|
|
6283
|
+
id: messageId,
|
|
6284
|
+
role: "assistant",
|
|
6285
|
+
content: {
|
|
6286
|
+
format: 2,
|
|
6287
|
+
parts: toolCalls.map((toolCall) => {
|
|
6288
|
+
return {
|
|
6289
|
+
type: "tool-invocation",
|
|
6290
|
+
toolInvocation: {
|
|
6291
|
+
state: "call",
|
|
6292
|
+
toolCallId: toolCall.toolCallId,
|
|
6293
|
+
toolName: toolCall.toolName,
|
|
6294
|
+
args: toolCall.args
|
|
6295
|
+
},
|
|
6296
|
+
...toolCall.providerMetadata ? { providerMetadata: toolCall.providerMetadata } : {}
|
|
6297
|
+
};
|
|
6298
|
+
})
|
|
5654
6299
|
},
|
|
5655
|
-
|
|
5656
|
-
|
|
6300
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
6301
|
+
};
|
|
6302
|
+
messageList.add(message, "response");
|
|
5657
6303
|
}
|
|
5658
6304
|
const finishReason = runState?.state?.stepResult?.reason ?? outputStream._getImmediateFinishReason();
|
|
5659
6305
|
const hasErrored = runState.state.hasErrored;
|
|
@@ -5735,24 +6381,28 @@ function createLLMMappingStep({ models, _internal, ...rest }, llmExecutionStep)
|
|
|
5735
6381
|
};
|
|
5736
6382
|
rest.controller.enqueue(chunk);
|
|
5737
6383
|
});
|
|
5738
|
-
|
|
5739
|
-
|
|
5740
|
-
|
|
5741
|
-
|
|
5742
|
-
|
|
6384
|
+
const msg = {
|
|
6385
|
+
id: toolResultMessageId || "",
|
|
6386
|
+
role: "assistant",
|
|
6387
|
+
content: {
|
|
6388
|
+
format: 2,
|
|
6389
|
+
parts: errorResults.map((toolCallErrorResult) => {
|
|
5743
6390
|
return {
|
|
5744
|
-
type: "tool-
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
6391
|
+
type: "tool-invocation",
|
|
6392
|
+
toolInvocation: {
|
|
6393
|
+
state: "result",
|
|
6394
|
+
toolCallId: toolCallErrorResult.toolCallId,
|
|
6395
|
+
toolName: toolCallErrorResult.toolName,
|
|
6396
|
+
args: toolCallErrorResult.args,
|
|
6397
|
+
result: toolCallErrorResult.error?.message ?? toolCallErrorResult.error
|
|
6398
|
+
},
|
|
6399
|
+
...toolCallErrorResult.providerMetadata ? { providerMetadata: toolCallErrorResult.providerMetadata } : {}
|
|
5751
6400
|
};
|
|
5752
6401
|
})
|
|
5753
6402
|
},
|
|
5754
|
-
|
|
5755
|
-
|
|
6403
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
6404
|
+
};
|
|
6405
|
+
rest.messageList.add(msg, "response");
|
|
5756
6406
|
}
|
|
5757
6407
|
initialResult.stepResult.isContinued = false;
|
|
5758
6408
|
return bail(initialResult);
|
|
@@ -5780,24 +6430,30 @@ function createLLMMappingStep({ models, _internal, ...rest }, llmExecutionStep)
|
|
|
5780
6430
|
})
|
|
5781
6431
|
});
|
|
5782
6432
|
}
|
|
5783
|
-
const toolResultMessageId = rest.experimental_generateMessageId?.() || _internal?.generateId?.();
|
|
5784
|
-
rest.messageList.add(
|
|
5785
|
-
{
|
|
5786
|
-
id: toolResultMessageId,
|
|
5787
|
-
role: "tool",
|
|
5788
|
-
content: inputData.map((toolCall2) => {
|
|
5789
|
-
return {
|
|
5790
|
-
type: "tool-result",
|
|
5791
|
-
args: toolCall2.args,
|
|
5792
|
-
toolCallId: toolCall2.toolCallId,
|
|
5793
|
-
toolName: toolCall2.toolName,
|
|
5794
|
-
result: toolCall2.result
|
|
5795
|
-
};
|
|
5796
|
-
})
|
|
5797
|
-
},
|
|
5798
|
-
"response"
|
|
5799
|
-
);
|
|
5800
6433
|
}
|
|
6434
|
+
const toolResultMessageId = rest.experimental_generateMessageId?.() || _internal?.generateId?.();
|
|
6435
|
+
const toolResultMessage = {
|
|
6436
|
+
id: toolResultMessageId || "",
|
|
6437
|
+
role: "assistant",
|
|
6438
|
+
content: {
|
|
6439
|
+
format: 2,
|
|
6440
|
+
parts: inputData.map((toolCall) => {
|
|
6441
|
+
return {
|
|
6442
|
+
type: "tool-invocation",
|
|
6443
|
+
toolInvocation: {
|
|
6444
|
+
state: "result",
|
|
6445
|
+
toolCallId: toolCall.toolCallId,
|
|
6446
|
+
toolName: toolCall.toolName,
|
|
6447
|
+
args: toolCall.args,
|
|
6448
|
+
result: toolCall.result
|
|
6449
|
+
},
|
|
6450
|
+
...toolCall.providerMetadata ? { providerMetadata: toolCall.providerMetadata } : {}
|
|
6451
|
+
};
|
|
6452
|
+
})
|
|
6453
|
+
},
|
|
6454
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
6455
|
+
};
|
|
6456
|
+
rest.messageList.add(toolResultMessage, "response");
|
|
5801
6457
|
return {
|
|
5802
6458
|
...initialResult,
|
|
5803
6459
|
messages: {
|
|
@@ -5954,7 +6610,8 @@ function createAgenticExecutionWorkflow({ models, _internal, ...rest }) {
|
|
|
5954
6610
|
// VNext execution as internal
|
|
5955
6611
|
internal: 1 /* WORKFLOW */
|
|
5956
6612
|
},
|
|
5957
|
-
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended"
|
|
6613
|
+
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended",
|
|
6614
|
+
validateInputs: false
|
|
5958
6615
|
}
|
|
5959
6616
|
}).then(llmExecutionStep).map(
|
|
5960
6617
|
async ({ inputData }) => {
|
|
@@ -5994,7 +6651,8 @@ function createAgenticLoopWorkflow(params) {
|
|
|
5994
6651
|
},
|
|
5995
6652
|
shouldPersistSnapshot: (params2) => {
|
|
5996
6653
|
return params2.workflowStatus === "suspended";
|
|
5997
|
-
}
|
|
6654
|
+
},
|
|
6655
|
+
validateInputs: false
|
|
5998
6656
|
}
|
|
5999
6657
|
}).dowhile(agenticExecutionWorkflow, async ({ inputData }) => {
|
|
6000
6658
|
const typedInputData = inputData;
|
|
@@ -6085,7 +6743,7 @@ function workflowLoopStream({
|
|
|
6085
6743
|
}) {
|
|
6086
6744
|
return new ReadableStream$1({
|
|
6087
6745
|
start: async (controller) => {
|
|
6088
|
-
const writer = new WritableStream({
|
|
6746
|
+
const writer = new WritableStream$1({
|
|
6089
6747
|
write: (chunk) => {
|
|
6090
6748
|
controller.enqueue(chunk);
|
|
6091
6749
|
}
|
|
@@ -6404,7 +7062,8 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
6404
7062
|
requireToolApproval,
|
|
6405
7063
|
_internal,
|
|
6406
7064
|
agentId,
|
|
6407
|
-
toolCallId
|
|
7065
|
+
toolCallId,
|
|
7066
|
+
methodType
|
|
6408
7067
|
}) {
|
|
6409
7068
|
let stopWhenToUse;
|
|
6410
7069
|
if (maxSteps && typeof maxSteps === "number") {
|
|
@@ -6461,6 +7120,7 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
6461
7120
|
modelSpanTracker,
|
|
6462
7121
|
requireToolApproval,
|
|
6463
7122
|
agentId,
|
|
7123
|
+
methodType,
|
|
6464
7124
|
options: {
|
|
6465
7125
|
...options,
|
|
6466
7126
|
onStepFinish: async (props) => {
|
|
@@ -7299,7 +7959,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
7299
7959
|
requestContext
|
|
7300
7960
|
});
|
|
7301
7961
|
let chunks = [];
|
|
7302
|
-
for await (const chunk of stream) {
|
|
7962
|
+
for await (const chunk of stream.fullStream) {
|
|
7303
7963
|
chunks.push(chunk);
|
|
7304
7964
|
await writer?.write({
|
|
7305
7965
|
type: `workflow-execution-event-${chunk.type}`,
|
|
@@ -7569,7 +8229,8 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
7569
8229
|
isOneOff: z5.boolean()
|
|
7570
8230
|
}),
|
|
7571
8231
|
options: {
|
|
7572
|
-
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended"
|
|
8232
|
+
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended",
|
|
8233
|
+
validateInputs: false
|
|
7573
8234
|
}
|
|
7574
8235
|
});
|
|
7575
8236
|
networkWorkflow.then(routingStep).branch([
|
|
@@ -7696,7 +8357,8 @@ async function networkLoop({
|
|
|
7696
8357
|
iteration: z5.number()
|
|
7697
8358
|
}),
|
|
7698
8359
|
options: {
|
|
7699
|
-
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended"
|
|
8360
|
+
shouldPersistSnapshot: ({ workflowStatus }) => workflowStatus === "suspended",
|
|
8361
|
+
validateInputs: false
|
|
7700
8362
|
}
|
|
7701
8363
|
}).dountil(networkWorkflow, async ({ inputData }) => {
|
|
7702
8364
|
return inputData.isComplete || inputData.iteration >= maxIterations;
|
|
@@ -9124,6 +9786,21 @@ the following messages are from ${ymd}
|
|
|
9124
9786
|
}
|
|
9125
9787
|
};
|
|
9126
9788
|
|
|
9789
|
+
// src/llm/model/model-method-from-agent.ts
|
|
9790
|
+
function getModelMethodFromAgentMethod(methodType) {
|
|
9791
|
+
if (methodType === "generate" || methodType === "generateLegacy") {
|
|
9792
|
+
return "generate";
|
|
9793
|
+
} else if (methodType === "stream" || methodType === "streamLegacy") {
|
|
9794
|
+
return "stream";
|
|
9795
|
+
} else {
|
|
9796
|
+
throw new MastraError({
|
|
9797
|
+
id: "INVALID_METHOD_TYPE",
|
|
9798
|
+
domain: "AGENT" /* AGENT */,
|
|
9799
|
+
category: "USER" /* USER */
|
|
9800
|
+
});
|
|
9801
|
+
}
|
|
9802
|
+
}
|
|
9803
|
+
|
|
9127
9804
|
// src/processors/processors/unicode-normalizer.ts
|
|
9128
9805
|
var UnicodeNormalizer = class {
|
|
9129
9806
|
id = "unicode-normalizer";
|
|
@@ -11122,7 +11799,8 @@ function createMapResultsStep({
|
|
|
11122
11799
|
memoryConfig,
|
|
11123
11800
|
saveQueueManager,
|
|
11124
11801
|
agentSpan,
|
|
11125
|
-
agentId
|
|
11802
|
+
agentId,
|
|
11803
|
+
methodType
|
|
11126
11804
|
}) {
|
|
11127
11805
|
return async ({
|
|
11128
11806
|
inputData,
|
|
@@ -11187,7 +11865,9 @@ function createMapResultsStep({
|
|
|
11187
11865
|
effectiveOutputProcessors = effectiveOutputProcessors ? [...effectiveOutputProcessors, structuredProcessor] : [structuredProcessor];
|
|
11188
11866
|
}
|
|
11189
11867
|
const messageList = memoryData.messageList;
|
|
11868
|
+
const modelMethodType = getModelMethodFromAgentMethod(methodType);
|
|
11190
11869
|
const loopOptions = {
|
|
11870
|
+
methodType: modelMethodType,
|
|
11191
11871
|
agentId,
|
|
11192
11872
|
requestContext: result.requestContext,
|
|
11193
11873
|
tracingContext: { currentSpan: agentSpan },
|
|
@@ -11553,7 +12233,8 @@ function createStreamStep({
|
|
|
11553
12233
|
requireToolApproval,
|
|
11554
12234
|
resumeContext,
|
|
11555
12235
|
agentId,
|
|
11556
|
-
toolCallId
|
|
12236
|
+
toolCallId,
|
|
12237
|
+
methodType
|
|
11557
12238
|
}) {
|
|
11558
12239
|
return createStep({
|
|
11559
12240
|
id: "stream-text-step",
|
|
@@ -11571,6 +12252,7 @@ function createStreamStep({
|
|
|
11571
12252
|
const processors = validatedInputData.outputProcessors || (capabilities.outputProcessors ? typeof capabilities.outputProcessors === "function" ? await capabilities.outputProcessors({
|
|
11572
12253
|
requestContext: validatedInputData.requestContext || new RequestContext()
|
|
11573
12254
|
}) : capabilities.outputProcessors : []);
|
|
12255
|
+
const modelMethodType = getModelMethodFromAgentMethod(methodType);
|
|
11574
12256
|
const streamResult = capabilities.llm.stream({
|
|
11575
12257
|
...validatedInputData,
|
|
11576
12258
|
outputProcessors: processors,
|
|
@@ -11582,7 +12264,8 @@ function createStreamStep({
|
|
|
11582
12264
|
generateId: capabilities.generateMessageId
|
|
11583
12265
|
},
|
|
11584
12266
|
agentId,
|
|
11585
|
-
toolCallId
|
|
12267
|
+
toolCallId,
|
|
12268
|
+
methodType: modelMethodType
|
|
11586
12269
|
});
|
|
11587
12270
|
return streamResult;
|
|
11588
12271
|
}
|
|
@@ -11638,7 +12321,8 @@ function createPrepareStreamWorkflow({
|
|
|
11638
12321
|
requireToolApproval,
|
|
11639
12322
|
resumeContext,
|
|
11640
12323
|
agentId,
|
|
11641
|
-
toolCallId
|
|
12324
|
+
toolCallId,
|
|
12325
|
+
methodType
|
|
11642
12326
|
});
|
|
11643
12327
|
const mapResultsStep = createMapResultsStep({
|
|
11644
12328
|
capabilities,
|
|
@@ -11650,7 +12334,8 @@ function createPrepareStreamWorkflow({
|
|
|
11650
12334
|
memoryConfig,
|
|
11651
12335
|
saveQueueManager,
|
|
11652
12336
|
agentSpan,
|
|
11653
|
-
agentId
|
|
12337
|
+
agentId,
|
|
12338
|
+
methodType
|
|
11654
12339
|
});
|
|
11655
12340
|
return createWorkflow({
|
|
11656
12341
|
id: "execution-workflow",
|
|
@@ -11663,7 +12348,8 @@ function createPrepareStreamWorkflow({
|
|
|
11663
12348
|
options: {
|
|
11664
12349
|
tracingPolicy: {
|
|
11665
12350
|
internal: 1 /* WORKFLOW */
|
|
11666
|
-
}
|
|
12351
|
+
},
|
|
12352
|
+
validateInputs: false
|
|
11667
12353
|
}
|
|
11668
12354
|
}).parallel([prepareToolsStep, prepareMemoryStep2]).map(mapResultsStep).then(streamStep).commit();
|
|
11669
12355
|
}
|
|
@@ -12583,6 +13269,7 @@ var Agent = class extends MastraBase {
|
|
|
12583
13269
|
"input"
|
|
12584
13270
|
);
|
|
12585
13271
|
const result = llm.stream({
|
|
13272
|
+
methodType: "generate",
|
|
12586
13273
|
requestContext,
|
|
12587
13274
|
tracingContext,
|
|
12588
13275
|
messageList,
|
|
@@ -12970,12 +13657,24 @@ var Agent = class extends MastraBase {
|
|
|
12970
13657
|
});
|
|
12971
13658
|
let result;
|
|
12972
13659
|
if ((methodType === "generate" || methodType === "generateLegacy") && modelVersion === "v2") {
|
|
13660
|
+
if (!agent.hasOwnMemory() && this.#memory) {
|
|
13661
|
+
agent.__setMemory(this.#memory);
|
|
13662
|
+
}
|
|
13663
|
+
const subAgentThreadId = randomUUID();
|
|
13664
|
+
const slugify = await import('@sindresorhus/slugify');
|
|
13665
|
+
const subAgentResourceId = `${slugify.default(this.id)}-${agentName}`;
|
|
12973
13666
|
const generateResult = await agent.generate(inputData.prompt, {
|
|
12974
13667
|
requestContext,
|
|
12975
|
-
tracingContext: context?.tracingContext
|
|
13668
|
+
tracingContext: context?.tracingContext,
|
|
13669
|
+
...resourceId && threadId ? {
|
|
13670
|
+
memory: {
|
|
13671
|
+
resource: subAgentResourceId,
|
|
13672
|
+
thread: subAgentThreadId
|
|
13673
|
+
}
|
|
13674
|
+
} : {}
|
|
12976
13675
|
});
|
|
12977
|
-
result = { text: generateResult.text };
|
|
12978
|
-
} else if (
|
|
13676
|
+
result = { text: generateResult.text, subAgentThreadId, subAgentResourceId };
|
|
13677
|
+
} else if (methodType === "generate" && modelVersion === "v1") {
|
|
12979
13678
|
const generateResult = await agent.generateLegacy(inputData.prompt, {
|
|
12980
13679
|
requestContext,
|
|
12981
13680
|
tracingContext: context?.tracingContext
|
|
@@ -13087,7 +13786,7 @@ var Agent = class extends MastraBase {
|
|
|
13087
13786
|
id: `workflow-${workflowName}`,
|
|
13088
13787
|
description: workflow.description || `Workflow: ${workflowName}`,
|
|
13089
13788
|
inputSchema: workflow.inputSchema,
|
|
13090
|
-
outputSchema: workflow.outputSchema,
|
|
13789
|
+
outputSchema: z.object({ result: workflow.outputSchema, runId: z.string() }),
|
|
13091
13790
|
mastra: this.#mastra,
|
|
13092
13791
|
// BREAKING CHANGE v1.0: New tool signature - first param is inputData, second is context
|
|
13093
13792
|
// manually wrap workflow tools with tracing, so that we can pass the
|
|
@@ -13134,7 +13833,8 @@ var Agent = class extends MastraBase {
|
|
|
13134
13833
|
}
|
|
13135
13834
|
result = await streamResult.result;
|
|
13136
13835
|
}
|
|
13137
|
-
|
|
13836
|
+
const workflowOutput = result?.result || result;
|
|
13837
|
+
return { result: workflowOutput, runId: run.runId };
|
|
13138
13838
|
} catch (err) {
|
|
13139
13839
|
const mastraError = new MastraError(
|
|
13140
13840
|
{
|
|
@@ -13414,7 +14114,7 @@ var Agent = class extends MastraBase {
|
|
|
13414
14114
|
if (model || !Array.isArray(this.model)) {
|
|
13415
14115
|
const modelToUse = model ?? this.model;
|
|
13416
14116
|
const resolvedModel = typeof modelToUse === "function" ? await modelToUse({ requestContext, mastra: this.#mastra }) : modelToUse;
|
|
13417
|
-
if (resolvedModel
|
|
14117
|
+
if (resolvedModel?.specificationVersion !== "v2") {
|
|
13418
14118
|
const mastraError = new MastraError({
|
|
13419
14119
|
id: "AGENT_PREPARE_MODELS_INCOMPATIBLE_WITH_MODEL_ARRAY_V1",
|
|
13420
14120
|
domain: "AGENT" /* AGENT */,
|
|
@@ -13431,6 +14131,7 @@ var Agent = class extends MastraBase {
|
|
|
13431
14131
|
return [
|
|
13432
14132
|
{
|
|
13433
14133
|
id: "main",
|
|
14134
|
+
// TODO fix type check
|
|
13434
14135
|
model: resolvedModel,
|
|
13435
14136
|
maxRetries: this.maxRetries ?? 0,
|
|
13436
14137
|
enabled: true
|
|
@@ -13440,7 +14141,7 @@ var Agent = class extends MastraBase {
|
|
|
13440
14141
|
const models = await Promise.all(
|
|
13441
14142
|
this.model.map(async (modelConfig) => {
|
|
13442
14143
|
const model2 = await this.resolveModelConfig(modelConfig.model, requestContext);
|
|
13443
|
-
if (model2
|
|
14144
|
+
if (!isV2Model(model2)) {
|
|
13444
14145
|
const mastraError = new MastraError({
|
|
13445
14146
|
id: "AGENT_PREPARE_MODELS_INCOMPATIBLE_WITH_MODEL_ARRAY_V1",
|
|
13446
14147
|
domain: "AGENT" /* AGENT */,
|
|
@@ -13787,8 +14488,59 @@ var Agent = class extends MastraBase {
|
|
|
13787
14488
|
});
|
|
13788
14489
|
}
|
|
13789
14490
|
async generate(messages, options) {
|
|
13790
|
-
const
|
|
13791
|
-
|
|
14491
|
+
const defaultOptions = await this.getDefaultOptions({
|
|
14492
|
+
requestContext: options?.requestContext
|
|
14493
|
+
});
|
|
14494
|
+
const mergedOptions = {
|
|
14495
|
+
...defaultOptions,
|
|
14496
|
+
...options ?? {}
|
|
14497
|
+
};
|
|
14498
|
+
const llm = await this.getLLM({
|
|
14499
|
+
requestContext: mergedOptions.requestContext
|
|
14500
|
+
});
|
|
14501
|
+
const modelInfo = llm.getModel();
|
|
14502
|
+
if (modelInfo.specificationVersion !== "v2") {
|
|
14503
|
+
const modelId = modelInfo.modelId || "unknown";
|
|
14504
|
+
const provider = modelInfo.provider || "unknown";
|
|
14505
|
+
throw new MastraError({
|
|
14506
|
+
id: "AGENT_GENERATE_V1_MODEL_NOT_SUPPORTED",
|
|
14507
|
+
domain: "AGENT" /* AGENT */,
|
|
14508
|
+
category: "USER" /* USER */,
|
|
14509
|
+
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.`,
|
|
14510
|
+
details: {
|
|
14511
|
+
agentName: this.name,
|
|
14512
|
+
modelId,
|
|
14513
|
+
provider,
|
|
14514
|
+
specificationVersion: modelInfo.specificationVersion
|
|
14515
|
+
}
|
|
14516
|
+
});
|
|
14517
|
+
}
|
|
14518
|
+
const executeOptions = {
|
|
14519
|
+
...mergedOptions,
|
|
14520
|
+
messages,
|
|
14521
|
+
methodType: "generate"
|
|
14522
|
+
};
|
|
14523
|
+
const result = await this.#execute(executeOptions);
|
|
14524
|
+
if (result.status !== "success") {
|
|
14525
|
+
if (result.status === "failed") {
|
|
14526
|
+
throw new MastraError(
|
|
14527
|
+
{
|
|
14528
|
+
id: "AGENT_GENERATE_FAILED",
|
|
14529
|
+
domain: "AGENT" /* AGENT */,
|
|
14530
|
+
category: "USER" /* USER */
|
|
14531
|
+
},
|
|
14532
|
+
// pass original error to preserve stack trace
|
|
14533
|
+
result.error
|
|
14534
|
+
);
|
|
14535
|
+
}
|
|
14536
|
+
throw new MastraError({
|
|
14537
|
+
id: "AGENT_GENERATE_UNKNOWN_ERROR",
|
|
14538
|
+
domain: "AGENT" /* AGENT */,
|
|
14539
|
+
category: "USER" /* USER */,
|
|
14540
|
+
text: "An unknown error occurred while streaming"
|
|
14541
|
+
});
|
|
14542
|
+
}
|
|
14543
|
+
const fullOutput = await result.result.getFullOutput();
|
|
13792
14544
|
const error = fullOutput.error;
|
|
13793
14545
|
if (fullOutput.finishReason === "error" && error) {
|
|
13794
14546
|
throw error;
|
|
@@ -15773,6 +16525,6 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
15773
16525
|
}
|
|
15774
16526
|
};
|
|
15775
16527
|
|
|
15776
|
-
export { AISDKV5OutputStream, Agent, BatchPartsProcessor, ChunkFrom, DefaultExecutionEngine, ExecutionEngine, LanguageDetector, MastraAgentNetworkStream, MastraModelOutput, ModerationProcessor, PIIDetector, ProcessorState, PromptInjectionDetector, Run, StructuredOutputProcessor, SystemPromptScrubber, TokenLimiterProcessor, TripWire, UnicodeNormalizer, Workflow, WorkflowRunOutput, cloneStep, cloneWorkflow, convertFullStreamChunkToUIMessageStream, convertMastraChunkToAISDKv5, createDeprecationProxy, createStep, createWorkflow, getResumeLabelsByStepId, getStepResult, getZodErrors, loop, mapVariable, resolveThreadIdFromArgs, runCountDeprecationMessage, tryGenerateWithJsonFallback, tryStreamWithJsonFallback, validateStepInput };
|
|
15777
|
-
//# sourceMappingURL=chunk-
|
|
15778
|
-
//# sourceMappingURL=chunk-
|
|
16528
|
+
export { AISDKV5OutputStream, Agent, BatchPartsProcessor, ChunkFrom, DefaultExecutionEngine, ExecutionEngine, LanguageDetector, MastraAgentNetworkStream, MastraModelOutput, ModerationProcessor, PIIDetector, ProcessorState, PromptInjectionDetector, Run, StructuredOutputProcessor, SystemPromptScrubber, TokenLimiterProcessor, TripWire, UnicodeNormalizer, Workflow, WorkflowRunOutput, cloneStep, cloneWorkflow, convertFullStreamChunkToUIMessageStream, convertMastraChunkToAISDKv5, createDeprecationProxy, createStep, createTimeTravelExecutionParams, createWorkflow, getResumeLabelsByStepId, getStepIds, getStepResult, getZodErrors, loop, mapVariable, resolveThreadIdFromArgs, runCountDeprecationMessage, tryGenerateWithJsonFallback, tryStreamWithJsonFallback, validateStepInput, validateStepResumeData };
|
|
16529
|
+
//# sourceMappingURL=chunk-XXBWX7DT.js.map
|
|
16530
|
+
//# sourceMappingURL=chunk-XXBWX7DT.js.map
|