@mastra/core 1.0.0-beta.3 → 1.0.0-beta.5
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 +369 -0
- package/dist/agent/agent.d.ts +2 -2
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.types.d.ts +2 -0
- 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/attachments-to-parts.d.ts.map +1 -1
- package/dist/agent/types.d.ts +2 -3
- 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.map +1 -1
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts +8 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
- package/dist/{chunk-4DWZ4Z6H.js → chunk-3B2OPLGG.js} +13 -7
- package/dist/chunk-3B2OPLGG.js.map +1 -0
- package/dist/{chunk-GRGPQ32U.js → chunk-3ZQ7LX73.js} +13 -13
- package/dist/chunk-3ZQ7LX73.js.map +1 -0
- package/dist/{chunk-VZGBVYXA.cjs → chunk-556MJ7CL.cjs} +33 -27
- package/dist/chunk-556MJ7CL.cjs.map +1 -0
- package/dist/{chunk-HGNRQ3OG.js → chunk-5O52O25J.js} +15 -8
- package/dist/chunk-5O52O25J.js.map +1 -0
- package/dist/{chunk-VU6DVS7J.js → chunk-5SA2EZ33.js} +421 -29
- package/dist/chunk-5SA2EZ33.js.map +1 -0
- package/dist/chunk-6XCINXZ7.cjs +194 -0
- package/dist/chunk-6XCINXZ7.cjs.map +1 -0
- package/dist/{chunk-KOSW5PP5.js → chunk-7ZADRRDW.js} +466 -125
- package/dist/chunk-7ZADRRDW.js.map +1 -0
- package/dist/{chunk-JXESKY4A.js → chunk-B5J5HYDN.js} +7 -5
- package/dist/chunk-B5J5HYDN.js.map +1 -0
- package/dist/chunk-BWYU7D33.js +192 -0
- package/dist/chunk-BWYU7D33.js.map +1 -0
- package/dist/{chunk-MCUX2D5Q.js → chunk-D7CJ4HIQ.js} +263 -24
- package/dist/chunk-D7CJ4HIQ.js.map +1 -0
- package/dist/{chunk-G36A2JRR.cjs → chunk-DQIZ5FFX.cjs} +457 -326
- package/dist/chunk-DQIZ5FFX.cjs.map +1 -0
- package/dist/{chunk-ZPMFINU2.cjs → chunk-HNHZGFZY.cjs} +466 -131
- package/dist/chunk-HNHZGFZY.cjs.map +1 -0
- package/dist/{chunk-3VOUB4ZU.cjs → chunk-IITXXVYI.cjs} +17 -17
- package/dist/chunk-IITXXVYI.cjs.map +1 -0
- package/dist/{chunk-QUKUN6NR.cjs → chunk-ISMGVGUM.cjs} +105 -5
- package/dist/chunk-ISMGVGUM.cjs.map +1 -0
- package/dist/{chunk-OQF4H5Y2.js → chunk-KJIQGPQR.js} +4 -4
- package/dist/{chunk-OQF4H5Y2.js.map → chunk-KJIQGPQR.js.map} +1 -1
- package/dist/{chunk-OWX2PUFH.cjs → chunk-KP42JLXE.cjs} +506 -236
- package/dist/chunk-KP42JLXE.cjs.map +1 -0
- package/dist/{chunk-4RSHBKDJ.cjs → chunk-KWWD3U7G.cjs} +5 -5
- package/dist/chunk-KWWD3U7G.cjs.map +1 -0
- package/dist/{chunk-N4SJ4YX7.cjs → chunk-NHP6ZIDG.cjs} +271 -31
- package/dist/chunk-NHP6ZIDG.cjs.map +1 -0
- package/dist/{chunk-UIZSWUKP.js → chunk-NZAXAFI3.js} +104 -6
- package/dist/chunk-NZAXAFI3.js.map +1 -0
- package/dist/{chunk-O6NA3Z43.cjs → chunk-OUUPUAGA.cjs} +10 -8
- package/dist/chunk-OUUPUAGA.cjs.map +1 -0
- package/dist/{chunk-D6EDHNGV.js → chunk-PC6EKOWK.js} +64 -11
- package/dist/chunk-PC6EKOWK.js.map +1 -0
- package/dist/{chunk-YQ7NLZZ3.cjs → chunk-QGWNF2QJ.cjs} +74 -618
- package/dist/chunk-QGWNF2QJ.cjs.map +1 -0
- package/dist/{chunk-HBJPYQRN.cjs → chunk-RROQ46B6.cjs} +69 -16
- package/dist/chunk-RROQ46B6.cjs.map +1 -0
- package/dist/{chunk-G3OOCXAI.js → chunk-T2CJRA6E.js} +4 -4
- package/dist/chunk-T2CJRA6E.js.map +1 -0
- package/dist/{chunk-T3WZCEC4.js → chunk-T2UNO766.js} +47 -591
- package/dist/chunk-T2UNO766.js.map +1 -0
- package/dist/{chunk-EZVRSZMK.cjs → chunk-U3VE2EVB.cjs} +11 -11
- package/dist/{chunk-EZVRSZMK.cjs.map → chunk-U3VE2EVB.cjs.map} +1 -1
- package/dist/{chunk-4IKJAKCD.cjs → chunk-V537VSV4.cjs} +74 -16
- package/dist/chunk-V537VSV4.cjs.map +1 -0
- package/dist/{chunk-XRIVPHXV.cjs → chunk-VYJXTHII.cjs} +422 -30
- package/dist/chunk-VYJXTHII.cjs.map +1 -0
- package/dist/{chunk-LRSB62Z6.cjs → chunk-X7F4CSGR.cjs} +15 -8
- package/dist/chunk-X7F4CSGR.cjs.map +1 -0
- package/dist/{chunk-CKGIPST2.js → chunk-XBO6W7LZ.js} +462 -193
- package/dist/chunk-XBO6W7LZ.js.map +1 -0
- package/dist/{chunk-KEURQGCQ.js → chunk-XIDKHXNR.js} +74 -17
- package/dist/chunk-XIDKHXNR.js.map +1 -0
- package/dist/{chunk-JTXVR2RA.cjs → chunk-XJQX54QP.cjs} +5 -5
- package/dist/{chunk-JTXVR2RA.cjs.map → chunk-XJQX54QP.cjs.map} +1 -1
- package/dist/{chunk-BAMR7HKO.js → chunk-YDFX3JR2.js} +457 -326
- package/dist/chunk-YDFX3JR2.js.map +1 -0
- package/dist/{chunk-5CWWU22H.js → chunk-ZTTMSCLU.js} +3 -3
- package/dist/{chunk-5CWWU22H.js.map → chunk-ZTTMSCLU.js.map} +1 -1
- package/dist/evals/base.d.ts +1 -1
- package/dist/evals/base.d.ts.map +1 -1
- package/dist/evals/base.test-utils.d.ts +25 -25
- package/dist/evals/index.cjs +4 -4
- package/dist/evals/index.js +1 -1
- package/dist/evals/scoreTraces/index.cjs +3 -3
- package/dist/evals/scoreTraces/index.js +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 +18 -14
- package/dist/llm/index.d.ts +2 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +5 -5
- package/dist/llm/model/aisdk/v5/model.d.ts.map +1 -1
- package/dist/llm/model/gateway-resolver.d.ts.map +1 -1
- package/dist/llm/model/gateways/azure.d.ts +36 -0
- package/dist/llm/model/gateways/azure.d.ts.map +1 -0
- package/dist/llm/model/gateways/base.d.ts +3 -6
- package/dist/llm/model/gateways/base.d.ts.map +1 -1
- package/dist/llm/model/gateways/index.d.ts +4 -1
- package/dist/llm/model/gateways/index.d.ts.map +1 -1
- package/dist/llm/model/gateways/models-dev.d.ts +2 -2
- package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
- package/dist/llm/model/gateways/netlify.d.ts +2 -2
- package/dist/llm/model/gateways/netlify.d.ts.map +1 -1
- package/dist/llm/model/model.d.ts.map +1 -1
- package/dist/llm/model/model.loop.d.ts +1 -1
- package/dist/llm/model/model.loop.d.ts.map +1 -1
- package/dist/llm/model/provider-registry.d.ts.map +1 -1
- package/dist/llm/model/provider-types.generated.d.ts +192 -11
- package/dist/llm/model/registry-generator.d.ts +12 -0
- package/dist/llm/model/registry-generator.d.ts.map +1 -1
- package/dist/llm/model/router.d.ts.map +1 -1
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/loop.d.ts.map +1 -1
- package/dist/loop/network/index.d.ts.map +1 -1
- package/dist/loop/test-utils/generateText.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/toUIMessageStream.d.ts.map +1 -1
- package/dist/loop/test-utils/utils.d.ts.map +1 -1
- package/dist/loop/types.d.ts +8 -0
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts +1 -1
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.ts +9 -9
- package/dist/mastra/index.d.ts.map +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.d.ts +4 -4
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/types.d.ts +2 -2
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/memory/index.cjs +89 -34
- package/dist/memory/index.cjs.map +1 -1
- package/dist/memory/index.js +85 -30
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/mock.d.ts +9 -13
- package/dist/memory/mock.d.ts.map +1 -1
- package/dist/models-dev-F6MTIYTO.js +3 -0
- package/dist/{models-dev-GCVENVWA.js.map → models-dev-F6MTIYTO.js.map} +1 -1
- package/dist/models-dev-XIVR5EJV.cjs +12 -0
- package/dist/{models-dev-TIBJR6IG.cjs.map → models-dev-XIVR5EJV.cjs.map} +1 -1
- package/dist/netlify-MXBOGAJR.cjs +12 -0
- package/dist/{netlify-NTSNNT6F.cjs.map → netlify-MXBOGAJR.cjs.map} +1 -1
- package/dist/netlify-RX3JXCFQ.js +3 -0
- package/dist/{netlify-O5NJW7CF.js.map → netlify-RX3JXCFQ.js.map} +1 -1
- package/dist/processors/index.cjs +11 -11
- package/dist/processors/index.d.ts +2 -2
- package/dist/processors/index.d.ts.map +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/processors/batch-parts.d.ts +1 -1
- package/dist/processors/processors/batch-parts.d.ts.map +1 -1
- package/dist/processors/processors/language-detector.d.ts +1 -1
- package/dist/processors/processors/language-detector.d.ts.map +1 -1
- package/dist/processors/processors/moderation.d.ts +1 -1
- package/dist/processors/processors/moderation.d.ts.map +1 -1
- package/dist/processors/processors/pii-detector.d.ts +1 -1
- package/dist/processors/processors/pii-detector.d.ts.map +1 -1
- package/dist/processors/processors/prompt-injection-detector.d.ts +1 -1
- package/dist/processors/processors/prompt-injection-detector.d.ts.map +1 -1
- package/dist/processors/processors/structured-output.d.ts +1 -1
- package/dist/processors/processors/structured-output.d.ts.map +1 -1
- package/dist/processors/processors/system-prompt-scrubber.d.ts +1 -1
- package/dist/processors/processors/system-prompt-scrubber.d.ts.map +1 -1
- package/dist/processors/processors/token-limiter.d.ts +1 -1
- package/dist/processors/processors/token-limiter.d.ts.map +1 -1
- package/dist/processors/processors/unicode-normalizer.d.ts +1 -1
- package/dist/processors/processors/unicode-normalizer.d.ts.map +1 -1
- package/dist/provider-registry-3LUCE7FT.js +3 -0
- package/dist/{provider-registry-74GMFZKT.js.map → provider-registry-3LUCE7FT.js.map} +1 -1
- package/dist/provider-registry-NBRXBOQT.cjs +40 -0
- package/dist/{provider-registry-BZP3DIIV.cjs.map → provider-registry-NBRXBOQT.cjs.map} +1 -1
- package/dist/provider-registry.json +400 -22
- package/dist/{registry-generator-JPCV47SC.cjs → registry-generator-DEPPRYYJ.cjs} +21 -6
- package/dist/registry-generator-DEPPRYYJ.cjs.map +1 -0
- package/dist/{registry-generator-XD4FPZTU.js → registry-generator-FLW6NV42.js} +21 -7
- package/dist/registry-generator-FLW6NV42.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/composite-auth.d.ts +9 -0
- package/dist/server/composite-auth.d.ts.map +1 -0
- package/dist/server/index.cjs +41 -0
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +41 -1
- package/dist/server/index.js.map +1 -1
- package/dist/storage/index.cjs +29 -29
- package/dist/storage/index.js +1 -1
- package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/output.d.ts.map +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 +7 -2
- 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 +6 -6
- package/dist/tools/index.js +2 -2
- package/dist/tools/is-vercel-tool.cjs +2 -2
- package/dist/tools/is-vercel-tool.js +1 -1
- package/dist/tools/stream.d.ts +1 -0
- package/dist/tools/stream.d.ts.map +1 -1
- package/dist/tools/tool-builder/builder.d.ts +2 -0
- package/dist/tools/tool-builder/builder.d.ts.map +1 -1
- package/dist/tools/tool.d.ts +6 -6
- package/dist/tools/tool.d.ts.map +1 -1
- package/dist/tools/types.d.ts +6 -2
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/validation.d.ts +13 -1
- package/dist/tools/validation.d.ts.map +1 -1
- package/dist/utils.cjs +22 -22
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/vector/filter/index.cjs +7 -189
- package/dist/vector/filter/index.cjs.map +1 -1
- package/dist/vector/filter/index.js +1 -190
- package/dist/vector/filter/index.js.map +1 -1
- package/dist/vector/index.cjs +5 -0
- package/dist/vector/index.cjs.map +1 -1
- package/dist/vector/index.d.ts +1 -0
- package/dist/vector/index.d.ts.map +1 -1
- package/dist/vector/index.js +1 -0
- package/dist/vector/index.js.map +1 -1
- package/dist/vector/types.d.ts +86 -3
- package/dist/vector/types.d.ts.map +1 -1
- package/dist/vector/vector.d.ts +39 -2
- package/dist/vector/vector.d.ts.map +1 -1
- package/dist/voice/aisdk/index.d.ts +3 -0
- package/dist/voice/aisdk/index.d.ts.map +1 -0
- package/dist/voice/aisdk/speech.d.ts +23 -0
- package/dist/voice/aisdk/speech.d.ts.map +1 -0
- package/dist/voice/aisdk/transcription.d.ts +22 -0
- package/dist/voice/aisdk/transcription.d.ts.map +1 -0
- package/dist/voice/composite-voice.d.ts +4 -3
- package/dist/voice/composite-voice.d.ts.map +1 -1
- package/dist/voice/index.cjs +12 -4
- package/dist/voice/index.d.ts +1 -0
- package/dist/voice/index.d.ts.map +1 -1
- package/dist/voice/index.js +1 -1
- package/dist/workflows/default.d.ts.map +1 -1
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/evented/step-executor.d.ts.map +1 -1
- package/dist/workflows/index.cjs +23 -19
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/types.d.ts +2 -2
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/utils.d.ts +7 -0
- package/dist/workflows/utils.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +4 -2
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +17 -16
- package/src/llm/model/provider-types.generated.d.ts +192 -11
- package/dist/chunk-3VOUB4ZU.cjs.map +0 -1
- package/dist/chunk-4DWZ4Z6H.js.map +0 -1
- package/dist/chunk-4IKJAKCD.cjs.map +0 -1
- package/dist/chunk-4RSHBKDJ.cjs.map +0 -1
- package/dist/chunk-BAMR7HKO.js.map +0 -1
- package/dist/chunk-CKGIPST2.js.map +0 -1
- package/dist/chunk-D6EDHNGV.js.map +0 -1
- package/dist/chunk-G36A2JRR.cjs.map +0 -1
- package/dist/chunk-G3OOCXAI.js.map +0 -1
- package/dist/chunk-GRGPQ32U.js.map +0 -1
- package/dist/chunk-HBJPYQRN.cjs.map +0 -1
- package/dist/chunk-HGNRQ3OG.js.map +0 -1
- package/dist/chunk-JXESKY4A.js.map +0 -1
- package/dist/chunk-KEURQGCQ.js.map +0 -1
- package/dist/chunk-KOSW5PP5.js.map +0 -1
- package/dist/chunk-LRSB62Z6.cjs.map +0 -1
- package/dist/chunk-MCUX2D5Q.js.map +0 -1
- package/dist/chunk-N4SJ4YX7.cjs.map +0 -1
- package/dist/chunk-O6NA3Z43.cjs.map +0 -1
- package/dist/chunk-OWX2PUFH.cjs.map +0 -1
- package/dist/chunk-QUKUN6NR.cjs.map +0 -1
- package/dist/chunk-T3WZCEC4.js.map +0 -1
- package/dist/chunk-UIZSWUKP.js.map +0 -1
- package/dist/chunk-VU6DVS7J.js.map +0 -1
- package/dist/chunk-VZGBVYXA.cjs.map +0 -1
- package/dist/chunk-XRIVPHXV.cjs.map +0 -1
- package/dist/chunk-YQ7NLZZ3.cjs.map +0 -1
- package/dist/chunk-ZPMFINU2.cjs.map +0 -1
- package/dist/models-dev-GCVENVWA.js +0 -3
- package/dist/models-dev-TIBJR6IG.cjs +0 -12
- package/dist/netlify-NTSNNT6F.cjs +0 -12
- package/dist/netlify-O5NJW7CF.js +0 -3
- package/dist/provider-registry-74GMFZKT.js +0 -3
- package/dist/provider-registry-BZP3DIIV.cjs +0 -40
- package/dist/registry-generator-JPCV47SC.cjs.map +0 -1
- package/dist/registry-generator-XD4FPZTU.js.map +0 -1
|
@@ -1,14 +1,14 @@
|
|
|
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-YDFX3JR2.js';
|
|
4
|
+
import { resolveModelConfig } from './chunk-D7CJ4HIQ.js';
|
|
5
|
+
import { MastraLLMV1 } from './chunk-B5J5HYDN.js';
|
|
6
6
|
import { executeHook } from './chunk-L54GIUCB.js';
|
|
7
|
-
import { removeUndefinedValues, selectFields, ensureToolProperties, makeCoreTool, createMastraProxy, delay } from './chunk-
|
|
7
|
+
import { removeUndefinedValues, selectFields, ensureToolProperties, makeCoreTool, createMastraProxy, isZodType, delay } from './chunk-PC6EKOWK.js';
|
|
8
8
|
import { wrapMastra, getOrCreateSpan } from './chunk-KIZIOFZC.js';
|
|
9
9
|
import { MastraError, getErrorFromUnknown } from './chunk-JJ5O45LH.js';
|
|
10
|
-
import { ToolStream } from './chunk-
|
|
11
|
-
import { Tool, createTool } from './chunk-
|
|
10
|
+
import { ToolStream } from './chunk-5O52O25J.js';
|
|
11
|
+
import { Tool, createTool } from './chunk-XIDKHXNR.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';
|
|
@@ -20,8 +20,8 @@ import * as crypto2 from 'crypto';
|
|
|
20
20
|
import { randomUUID } from 'crypto';
|
|
21
21
|
import { getErrorMessage, TypeValidationError } from '@ai-sdk/provider-v5';
|
|
22
22
|
import { generateId, createTextStreamResponse, createUIMessageStreamResponse, createUIMessageStream, asSchema, parsePartialJson, isDeepEqualData, jsonSchema, APICallError, tool, stepCountIs } from 'ai-v5';
|
|
23
|
-
import z5, { z } from 'zod';
|
|
24
23
|
import { OpenAIReasoningSchemaCompatLayer, OpenAISchemaCompatLayer, GoogleSchemaCompatLayer, AnthropicSchemaCompatLayer, DeepSeekSchemaCompatLayer, MetaSchemaCompatLayer, applyCompatLayer } from '@mastra/schema-compat';
|
|
24
|
+
import z5, { z } from 'zod';
|
|
25
25
|
import { isEmpty } from 'radash';
|
|
26
26
|
import { isAbortError, injectJsonInstructionIntoMessages } from '@ai-sdk/provider-utils-v5';
|
|
27
27
|
import { Tiktoken } from 'js-tiktoken/lite';
|
|
@@ -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}`);
|
|
@@ -935,7 +943,8 @@ async function validateStepInput({
|
|
|
935
943
|
const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
|
|
936
944
|
validationError = new Error("Step input validation failed: \n" + errorMessages);
|
|
937
945
|
} else {
|
|
938
|
-
|
|
946
|
+
const isEmptyData = isEmpty(validatedInput.data);
|
|
947
|
+
inputData = isEmptyData ? prevOutput : validatedInput.data;
|
|
939
948
|
}
|
|
940
949
|
}
|
|
941
950
|
return { inputData, validationError };
|
|
@@ -958,6 +967,27 @@ async function validateStepResumeData({ resumeData, step }) {
|
|
|
958
967
|
}
|
|
959
968
|
return { resumeData, validationError };
|
|
960
969
|
}
|
|
970
|
+
async function validateStepSuspendData({
|
|
971
|
+
suspendData,
|
|
972
|
+
step
|
|
973
|
+
}) {
|
|
974
|
+
if (!suspendData) {
|
|
975
|
+
return { suspendData: void 0, validationError: void 0 };
|
|
976
|
+
}
|
|
977
|
+
let validationError;
|
|
978
|
+
const suspendSchema = step.suspendSchema;
|
|
979
|
+
if (suspendSchema) {
|
|
980
|
+
const validatedSuspendData = await suspendSchema.safeParseAsync(suspendData);
|
|
981
|
+
if (!validatedSuspendData.success) {
|
|
982
|
+
const errors = getZodErrors(validatedSuspendData.error);
|
|
983
|
+
const errorMessages = errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n");
|
|
984
|
+
validationError = new Error("Step suspend data validation failed: \n" + errorMessages);
|
|
985
|
+
} else {
|
|
986
|
+
suspendData = validatedSuspendData.data;
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
return { suspendData, validationError };
|
|
990
|
+
}
|
|
961
991
|
function getResumeLabelsByStepId(resumeLabels, stepId) {
|
|
962
992
|
return Object.entries(resumeLabels).filter(([_, value]) => value.stepId === stepId).reduce(
|
|
963
993
|
(acc, [key, value]) => {
|
|
@@ -1646,6 +1676,13 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1646
1676
|
getInitData: () => stepResults?.input,
|
|
1647
1677
|
getStepResult: getStepResult.bind(this, stepResults),
|
|
1648
1678
|
suspend: async (suspendPayload, suspendOptions) => {
|
|
1679
|
+
const { suspendData, validationError: validationError2 } = await validateStepSuspendData({
|
|
1680
|
+
suspendData: suspendPayload,
|
|
1681
|
+
step
|
|
1682
|
+
});
|
|
1683
|
+
if (validationError2) {
|
|
1684
|
+
throw validationError2;
|
|
1685
|
+
}
|
|
1649
1686
|
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
1650
1687
|
if (suspendOptions?.resumeLabel) {
|
|
1651
1688
|
const resumeLabel = Array.isArray(suspendOptions.resumeLabel) ? suspendOptions.resumeLabel : [suspendOptions.resumeLabel];
|
|
@@ -1656,7 +1693,7 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
1656
1693
|
};
|
|
1657
1694
|
}
|
|
1658
1695
|
}
|
|
1659
|
-
suspended = { payload:
|
|
1696
|
+
suspended = { payload: suspendData };
|
|
1660
1697
|
},
|
|
1661
1698
|
bail: (result2) => {
|
|
1662
1699
|
bailed = { payload: result2 };
|
|
@@ -2952,7 +2989,7 @@ function mapVariable(config) {
|
|
|
2952
2989
|
function createStep(params, agentOptions) {
|
|
2953
2990
|
if (params instanceof Agent) {
|
|
2954
2991
|
return {
|
|
2955
|
-
id: params.
|
|
2992
|
+
id: params.id,
|
|
2956
2993
|
description: params.getDescription(),
|
|
2957
2994
|
// @ts-ignore
|
|
2958
2995
|
inputSchema: z.object({
|
|
@@ -3055,6 +3092,8 @@ function createStep(params, agentOptions) {
|
|
|
3055
3092
|
description: params.description,
|
|
3056
3093
|
inputSchema: params.inputSchema,
|
|
3057
3094
|
outputSchema: params.outputSchema,
|
|
3095
|
+
resumeSchema: params.resumeSchema,
|
|
3096
|
+
suspendSchema: params.suspendSchema,
|
|
3058
3097
|
execute: async ({
|
|
3059
3098
|
inputData,
|
|
3060
3099
|
mastra,
|
|
@@ -3071,10 +3110,11 @@ function createStep(params, agentOptions) {
|
|
|
3071
3110
|
mastra,
|
|
3072
3111
|
requestContext,
|
|
3073
3112
|
tracingContext,
|
|
3074
|
-
suspend,
|
|
3075
3113
|
resumeData,
|
|
3076
3114
|
workflow: {
|
|
3077
3115
|
runId,
|
|
3116
|
+
suspend,
|
|
3117
|
+
resumeData,
|
|
3078
3118
|
workflowId,
|
|
3079
3119
|
state,
|
|
3080
3120
|
setState
|
|
@@ -3535,6 +3575,7 @@ var Workflow = class extends MastraBase {
|
|
|
3535
3575
|
const run = this.#runs.get(runIdToUse) ?? new Run({
|
|
3536
3576
|
workflowId: this.id,
|
|
3537
3577
|
stateSchema: this.stateSchema,
|
|
3578
|
+
inputSchema: this.inputSchema,
|
|
3538
3579
|
runId: runIdToUse,
|
|
3539
3580
|
resourceId: options?.resourceId,
|
|
3540
3581
|
executionEngine: this.executionEngine,
|
|
@@ -3894,6 +3935,7 @@ var Run = class {
|
|
|
3894
3935
|
closeStreamAction;
|
|
3895
3936
|
executionResults;
|
|
3896
3937
|
stateSchema;
|
|
3938
|
+
inputSchema;
|
|
3897
3939
|
cleanup;
|
|
3898
3940
|
retryConfig;
|
|
3899
3941
|
constructor(params) {
|
|
@@ -3912,6 +3954,7 @@ var Run = class {
|
|
|
3912
3954
|
this.workflowSteps = params.workflowSteps;
|
|
3913
3955
|
this.validateInputs = params.validateInputs;
|
|
3914
3956
|
this.stateSchema = params.stateSchema;
|
|
3957
|
+
this.inputSchema = params.inputSchema;
|
|
3915
3958
|
this.workflowRunStatus = "pending";
|
|
3916
3959
|
this.workflowEngineType = params.workflowEngineType;
|
|
3917
3960
|
}
|
|
@@ -3928,29 +3971,16 @@ var Run = class {
|
|
|
3928
3971
|
this.abortController?.abort();
|
|
3929
3972
|
}
|
|
3930
3973
|
async _validateInput(inputData) {
|
|
3931
|
-
const firstEntry = this.executionGraph.steps[0];
|
|
3932
3974
|
let inputDataToUse = inputData;
|
|
3933
|
-
if (
|
|
3934
|
-
|
|
3935
|
-
if (
|
|
3936
|
-
const
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
if (firstStep && firstStep.type === "step") {
|
|
3941
|
-
inputSchema = firstStep.step.inputSchema;
|
|
3942
|
-
}
|
|
3943
|
-
}
|
|
3944
|
-
if (inputSchema) {
|
|
3945
|
-
const validatedInputData = await inputSchema.safeParseAsync(inputData);
|
|
3946
|
-
if (!validatedInputData.success) {
|
|
3947
|
-
const errors = getZodErrors(validatedInputData.error);
|
|
3948
|
-
throw new Error(
|
|
3949
|
-
"Invalid input data: \n" + errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n")
|
|
3950
|
-
);
|
|
3951
|
-
}
|
|
3952
|
-
inputDataToUse = validatedInputData.data;
|
|
3975
|
+
if (this.validateInputs && this.inputSchema) {
|
|
3976
|
+
const validatedInputData = await this.inputSchema.safeParseAsync(inputData);
|
|
3977
|
+
if (!validatedInputData.success) {
|
|
3978
|
+
const errors = getZodErrors(validatedInputData.error);
|
|
3979
|
+
throw new Error(
|
|
3980
|
+
"Invalid input data: \n" + errors.map((e) => `- ${e.path?.join(".")}: ${e.message}`).join("\n")
|
|
3981
|
+
);
|
|
3953
3982
|
}
|
|
3983
|
+
inputDataToUse = validatedInputData.data;
|
|
3954
3984
|
}
|
|
3955
3985
|
return inputDataToUse;
|
|
3956
3986
|
}
|
|
@@ -5721,23 +5751,22 @@ async function processOutputStream({
|
|
|
5721
5751
|
if (runState.state.textDeltas.length) {
|
|
5722
5752
|
const textStartPayload = chunk.payload;
|
|
5723
5753
|
const providerMetadata = textStartPayload.providerMetadata ?? runState.state.providerOptions;
|
|
5724
|
-
|
|
5725
|
-
|
|
5726
|
-
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
|
|
5754
|
+
const message = {
|
|
5755
|
+
id: messageId,
|
|
5756
|
+
role: "assistant",
|
|
5757
|
+
content: {
|
|
5758
|
+
format: 2,
|
|
5759
|
+
parts: [
|
|
5760
|
+
{
|
|
5730
5761
|
type: "text",
|
|
5731
5762
|
text: runState.state.textDeltas.join(""),
|
|
5732
|
-
|
|
5733
|
-
} : {
|
|
5734
|
-
type: "text",
|
|
5735
|
-
text: runState.state.textDeltas.join("")
|
|
5763
|
+
...providerMetadata ? { providerMetadata } : {}
|
|
5736
5764
|
}
|
|
5737
5765
|
]
|
|
5738
5766
|
},
|
|
5739
|
-
|
|
5740
|
-
|
|
5767
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
5768
|
+
};
|
|
5769
|
+
messageList.add(message, "response");
|
|
5741
5770
|
}
|
|
5742
5771
|
runState.setState({
|
|
5743
5772
|
isStreaming: false,
|
|
@@ -5817,20 +5846,23 @@ async function processOutputStream({
|
|
|
5817
5846
|
providerOptions: chunk.payload.providerMetadata ?? runState.state.providerOptions
|
|
5818
5847
|
});
|
|
5819
5848
|
if (Object.values(chunk.payload.providerMetadata || {}).find((v) => v?.redactedData)) {
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
|
|
5823
|
-
|
|
5824
|
-
|
|
5849
|
+
const message = {
|
|
5850
|
+
id: messageId,
|
|
5851
|
+
role: "assistant",
|
|
5852
|
+
content: {
|
|
5853
|
+
format: 2,
|
|
5854
|
+
parts: [
|
|
5825
5855
|
{
|
|
5826
5856
|
type: "reasoning",
|
|
5827
|
-
|
|
5828
|
-
|
|
5857
|
+
reasoning: "",
|
|
5858
|
+
details: [{ type: "redacted", data: "" }],
|
|
5859
|
+
providerMetadata: chunk.payload.providerMetadata ?? runState.state.providerOptions
|
|
5829
5860
|
}
|
|
5830
5861
|
]
|
|
5831
5862
|
},
|
|
5832
|
-
|
|
5833
|
-
|
|
5863
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
5864
|
+
};
|
|
5865
|
+
messageList.add(message, "response");
|
|
5834
5866
|
if (isControllerOpen(controller)) {
|
|
5835
5867
|
controller.enqueue(chunk);
|
|
5836
5868
|
}
|
|
@@ -5856,20 +5888,23 @@ async function processOutputStream({
|
|
|
5856
5888
|
}
|
|
5857
5889
|
case "reasoning-end": {
|
|
5858
5890
|
if (runState.state.reasoningDeltas.length > 0) {
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
|
|
5891
|
+
const message = {
|
|
5892
|
+
id: messageId,
|
|
5893
|
+
role: "assistant",
|
|
5894
|
+
content: {
|
|
5895
|
+
format: 2,
|
|
5896
|
+
parts: [
|
|
5864
5897
|
{
|
|
5865
5898
|
type: "reasoning",
|
|
5866
|
-
|
|
5867
|
-
|
|
5899
|
+
reasoning: "",
|
|
5900
|
+
details: [{ type: "text", text: runState.state.reasoningDeltas.join("") }],
|
|
5901
|
+
providerMetadata: chunk.payload.providerMetadata ?? runState.state.providerOptions
|
|
5868
5902
|
}
|
|
5869
5903
|
]
|
|
5870
5904
|
},
|
|
5871
|
-
|
|
5872
|
-
|
|
5905
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
5906
|
+
};
|
|
5907
|
+
messageList.add(message, "response");
|
|
5873
5908
|
}
|
|
5874
5909
|
runState.setState({
|
|
5875
5910
|
isReasoning: false,
|
|
@@ -5881,25 +5916,31 @@ async function processOutputStream({
|
|
|
5881
5916
|
break;
|
|
5882
5917
|
}
|
|
5883
5918
|
case "file":
|
|
5884
|
-
|
|
5885
|
-
{
|
|
5919
|
+
{
|
|
5920
|
+
const message = {
|
|
5886
5921
|
id: messageId,
|
|
5887
5922
|
role: "assistant",
|
|
5888
|
-
content:
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
5897
|
-
|
|
5898
|
-
|
|
5923
|
+
content: {
|
|
5924
|
+
format: 2,
|
|
5925
|
+
parts: [
|
|
5926
|
+
{
|
|
5927
|
+
type: "file",
|
|
5928
|
+
// @ts-expect-error
|
|
5929
|
+
data: chunk.payload.data,
|
|
5930
|
+
// TODO: incorrect string type
|
|
5931
|
+
mimeType: chunk.payload.mimeType
|
|
5932
|
+
}
|
|
5933
|
+
]
|
|
5934
|
+
},
|
|
5935
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
5936
|
+
};
|
|
5937
|
+
messageList.add(message, "response");
|
|
5938
|
+
controller.enqueue(chunk);
|
|
5939
|
+
}
|
|
5899
5940
|
break;
|
|
5900
5941
|
case "source":
|
|
5901
|
-
|
|
5902
|
-
{
|
|
5942
|
+
{
|
|
5943
|
+
const message = {
|
|
5903
5944
|
id: messageId,
|
|
5904
5945
|
role: "assistant",
|
|
5905
5946
|
content: {
|
|
@@ -5918,10 +5959,10 @@ async function processOutputStream({
|
|
|
5918
5959
|
]
|
|
5919
5960
|
},
|
|
5920
5961
|
createdAt: /* @__PURE__ */ new Date()
|
|
5921
|
-
}
|
|
5922
|
-
"response"
|
|
5923
|
-
|
|
5924
|
-
|
|
5962
|
+
};
|
|
5963
|
+
messageList.add(message, "response");
|
|
5964
|
+
controller.enqueue(chunk);
|
|
5965
|
+
}
|
|
5925
5966
|
break;
|
|
5926
5967
|
case "finish":
|
|
5927
5968
|
runState.setState({
|
|
@@ -6260,24 +6301,27 @@ function createLLMExecutionStep({
|
|
|
6260
6301
|
return chunk.payload;
|
|
6261
6302
|
});
|
|
6262
6303
|
if (toolCalls.length > 0) {
|
|
6263
|
-
const
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
|
|
6304
|
+
const message = {
|
|
6305
|
+
id: messageId,
|
|
6306
|
+
role: "assistant",
|
|
6307
|
+
content: {
|
|
6308
|
+
format: 2,
|
|
6309
|
+
parts: toolCalls.map((toolCall) => {
|
|
6310
|
+
return {
|
|
6311
|
+
type: "tool-invocation",
|
|
6312
|
+
toolInvocation: {
|
|
6313
|
+
state: "call",
|
|
6314
|
+
toolCallId: toolCall.toolCallId,
|
|
6315
|
+
toolName: toolCall.toolName,
|
|
6316
|
+
args: toolCall.args
|
|
6317
|
+
},
|
|
6318
|
+
...toolCall.providerMetadata ? { providerMetadata: toolCall.providerMetadata } : {}
|
|
6319
|
+
};
|
|
6320
|
+
})
|
|
6278
6321
|
},
|
|
6279
|
-
|
|
6280
|
-
|
|
6322
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
6323
|
+
};
|
|
6324
|
+
messageList.add(message, "response");
|
|
6281
6325
|
}
|
|
6282
6326
|
const finishReason = runState?.state?.stepResult?.reason ?? outputStream._getImmediateFinishReason();
|
|
6283
6327
|
const hasErrored = runState.state.hasErrored;
|
|
@@ -6359,24 +6403,28 @@ function createLLMMappingStep({ models, _internal, ...rest }, llmExecutionStep)
|
|
|
6359
6403
|
};
|
|
6360
6404
|
rest.controller.enqueue(chunk);
|
|
6361
6405
|
});
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
|
|
6406
|
+
const msg = {
|
|
6407
|
+
id: toolResultMessageId || "",
|
|
6408
|
+
role: "assistant",
|
|
6409
|
+
content: {
|
|
6410
|
+
format: 2,
|
|
6411
|
+
parts: errorResults.map((toolCallErrorResult) => {
|
|
6367
6412
|
return {
|
|
6368
|
-
type: "tool-
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
|
|
6374
|
-
|
|
6413
|
+
type: "tool-invocation",
|
|
6414
|
+
toolInvocation: {
|
|
6415
|
+
state: "result",
|
|
6416
|
+
toolCallId: toolCallErrorResult.toolCallId,
|
|
6417
|
+
toolName: toolCallErrorResult.toolName,
|
|
6418
|
+
args: toolCallErrorResult.args,
|
|
6419
|
+
result: toolCallErrorResult.error?.message ?? toolCallErrorResult.error
|
|
6420
|
+
},
|
|
6421
|
+
...toolCallErrorResult.providerMetadata ? { providerMetadata: toolCallErrorResult.providerMetadata } : {}
|
|
6375
6422
|
};
|
|
6376
6423
|
})
|
|
6377
6424
|
},
|
|
6378
|
-
|
|
6379
|
-
|
|
6425
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
6426
|
+
};
|
|
6427
|
+
rest.messageList.add(msg, "response");
|
|
6380
6428
|
}
|
|
6381
6429
|
initialResult.stepResult.isContinued = false;
|
|
6382
6430
|
return bail(initialResult);
|
|
@@ -6404,24 +6452,30 @@ function createLLMMappingStep({ models, _internal, ...rest }, llmExecutionStep)
|
|
|
6404
6452
|
})
|
|
6405
6453
|
});
|
|
6406
6454
|
}
|
|
6407
|
-
const toolResultMessageId = rest.experimental_generateMessageId?.() || _internal?.generateId?.();
|
|
6408
|
-
rest.messageList.add(
|
|
6409
|
-
{
|
|
6410
|
-
id: toolResultMessageId,
|
|
6411
|
-
role: "tool",
|
|
6412
|
-
content: inputData.map((toolCall2) => {
|
|
6413
|
-
return {
|
|
6414
|
-
type: "tool-result",
|
|
6415
|
-
args: toolCall2.args,
|
|
6416
|
-
toolCallId: toolCall2.toolCallId,
|
|
6417
|
-
toolName: toolCall2.toolName,
|
|
6418
|
-
result: toolCall2.result
|
|
6419
|
-
};
|
|
6420
|
-
})
|
|
6421
|
-
},
|
|
6422
|
-
"response"
|
|
6423
|
-
);
|
|
6424
6455
|
}
|
|
6456
|
+
const toolResultMessageId = rest.experimental_generateMessageId?.() || _internal?.generateId?.();
|
|
6457
|
+
const toolResultMessage = {
|
|
6458
|
+
id: toolResultMessageId || "",
|
|
6459
|
+
role: "assistant",
|
|
6460
|
+
content: {
|
|
6461
|
+
format: 2,
|
|
6462
|
+
parts: inputData.map((toolCall) => {
|
|
6463
|
+
return {
|
|
6464
|
+
type: "tool-invocation",
|
|
6465
|
+
toolInvocation: {
|
|
6466
|
+
state: "result",
|
|
6467
|
+
toolCallId: toolCall.toolCallId,
|
|
6468
|
+
toolName: toolCall.toolName,
|
|
6469
|
+
args: toolCall.args,
|
|
6470
|
+
result: toolCall.result
|
|
6471
|
+
},
|
|
6472
|
+
...toolCall.providerMetadata ? { providerMetadata: toolCall.providerMetadata } : {}
|
|
6473
|
+
};
|
|
6474
|
+
})
|
|
6475
|
+
},
|
|
6476
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
6477
|
+
};
|
|
6478
|
+
rest.messageList.add(toolResultMessage, "response");
|
|
6425
6479
|
return {
|
|
6426
6480
|
...initialResult,
|
|
6427
6481
|
messages: {
|
|
@@ -6444,13 +6498,87 @@ function createToolCallStep({
|
|
|
6444
6498
|
controller,
|
|
6445
6499
|
runId,
|
|
6446
6500
|
streamState,
|
|
6447
|
-
modelSpanTracker
|
|
6501
|
+
modelSpanTracker,
|
|
6502
|
+
_internal
|
|
6448
6503
|
}) {
|
|
6449
6504
|
return createStep({
|
|
6450
6505
|
id: "toolCallStep",
|
|
6451
6506
|
inputSchema: toolCallInputSchema,
|
|
6452
6507
|
outputSchema: toolCallOutputSchema,
|
|
6453
6508
|
execute: async ({ inputData, suspend, resumeData, requestContext }) => {
|
|
6509
|
+
const addToolApprovalMetadata = (toolCallId, toolName, args) => {
|
|
6510
|
+
const responseMessages = messageList.get.response.db();
|
|
6511
|
+
const lastAssistantMessage = [...responseMessages].reverse().find((msg) => msg.role === "assistant");
|
|
6512
|
+
if (lastAssistantMessage) {
|
|
6513
|
+
const content = lastAssistantMessage.content;
|
|
6514
|
+
if (!content) return;
|
|
6515
|
+
const metadata = typeof lastAssistantMessage.content.metadata === "object" && lastAssistantMessage.content.metadata !== null ? lastAssistantMessage.content.metadata : {};
|
|
6516
|
+
metadata.pendingToolApprovals = metadata.pendingToolApprovals || {};
|
|
6517
|
+
metadata.pendingToolApprovals[toolCallId] = {
|
|
6518
|
+
toolName,
|
|
6519
|
+
args,
|
|
6520
|
+
type: "approval",
|
|
6521
|
+
runId
|
|
6522
|
+
// Store the runId so we can resume after page refresh
|
|
6523
|
+
};
|
|
6524
|
+
lastAssistantMessage.content.metadata = metadata;
|
|
6525
|
+
}
|
|
6526
|
+
};
|
|
6527
|
+
const removeToolApprovalMetadata = async (toolCallId) => {
|
|
6528
|
+
const { saveQueueManager, memoryConfig, threadId } = _internal || {};
|
|
6529
|
+
if (!saveQueueManager || !threadId) {
|
|
6530
|
+
return;
|
|
6531
|
+
}
|
|
6532
|
+
const getMetadata = (message) => {
|
|
6533
|
+
const content = message.content;
|
|
6534
|
+
if (!content) return void 0;
|
|
6535
|
+
const metadata = typeof content.metadata === "object" && content.metadata !== null ? content.metadata : void 0;
|
|
6536
|
+
return metadata;
|
|
6537
|
+
};
|
|
6538
|
+
const allMessages = messageList.get.all.db();
|
|
6539
|
+
const lastAssistantMessage = [...allMessages].reverse().find((msg) => {
|
|
6540
|
+
const metadata = getMetadata(msg);
|
|
6541
|
+
const pendingToolApprovals = metadata?.pendingToolApprovals;
|
|
6542
|
+
return !!pendingToolApprovals?.[toolCallId];
|
|
6543
|
+
});
|
|
6544
|
+
if (lastAssistantMessage) {
|
|
6545
|
+
const metadata = getMetadata(lastAssistantMessage);
|
|
6546
|
+
const pendingToolApprovals = metadata?.pendingToolApprovals;
|
|
6547
|
+
if (pendingToolApprovals && typeof pendingToolApprovals === "object") {
|
|
6548
|
+
delete pendingToolApprovals[toolCallId];
|
|
6549
|
+
if (metadata && Object.keys(pendingToolApprovals).length === 0) {
|
|
6550
|
+
delete metadata.pendingToolApprovals;
|
|
6551
|
+
}
|
|
6552
|
+
try {
|
|
6553
|
+
await saveQueueManager.flushMessages(messageList, threadId, memoryConfig);
|
|
6554
|
+
} catch (error) {
|
|
6555
|
+
console.error("Error removing tool approval metadata:", error);
|
|
6556
|
+
}
|
|
6557
|
+
}
|
|
6558
|
+
}
|
|
6559
|
+
};
|
|
6560
|
+
const flushMessagesBeforeSuspension = async () => {
|
|
6561
|
+
const { saveQueueManager, memoryConfig, threadId, resourceId, memory } = _internal || {};
|
|
6562
|
+
if (!saveQueueManager || !threadId) {
|
|
6563
|
+
return;
|
|
6564
|
+
}
|
|
6565
|
+
try {
|
|
6566
|
+
if (memory && !_internal.threadExists && resourceId) {
|
|
6567
|
+
const thread = await memory.getThreadById?.({ threadId });
|
|
6568
|
+
if (!thread) {
|
|
6569
|
+
await memory.createThread?.({
|
|
6570
|
+
threadId,
|
|
6571
|
+
resourceId,
|
|
6572
|
+
memoryConfig
|
|
6573
|
+
});
|
|
6574
|
+
}
|
|
6575
|
+
_internal.threadExists = true;
|
|
6576
|
+
}
|
|
6577
|
+
await saveQueueManager.flushMessages(messageList, threadId, memoryConfig);
|
|
6578
|
+
} catch (error) {
|
|
6579
|
+
console.error("Error flushing messages before suspension:", error);
|
|
6580
|
+
}
|
|
6581
|
+
};
|
|
6454
6582
|
if (inputData.providerExecuted) {
|
|
6455
6583
|
return {
|
|
6456
6584
|
...inputData,
|
|
@@ -6490,6 +6618,8 @@ function createToolCallStep({
|
|
|
6490
6618
|
args: inputData.args
|
|
6491
6619
|
}
|
|
6492
6620
|
});
|
|
6621
|
+
addToolApprovalMetadata(inputData.toolCallId, inputData.toolName, inputData.args);
|
|
6622
|
+
await flushMessagesBeforeSuspension();
|
|
6493
6623
|
return suspend(
|
|
6494
6624
|
{
|
|
6495
6625
|
requireToolApproval: {
|
|
@@ -6504,6 +6634,7 @@ function createToolCallStep({
|
|
|
6504
6634
|
}
|
|
6505
6635
|
);
|
|
6506
6636
|
} else {
|
|
6637
|
+
await removeToolApprovalMetadata(inputData.toolCallId);
|
|
6507
6638
|
if (!resumeData.approved) {
|
|
6508
6639
|
return {
|
|
6509
6640
|
result: "Tool call was not approved by the user",
|
|
@@ -6526,6 +6657,7 @@ function createToolCallStep({
|
|
|
6526
6657
|
from: "AGENT" /* AGENT */,
|
|
6527
6658
|
payload: { toolCallId: inputData.toolCallId, toolName: inputData.toolName, suspendPayload }
|
|
6528
6659
|
});
|
|
6660
|
+
await flushMessagesBeforeSuspension();
|
|
6529
6661
|
return await suspend(
|
|
6530
6662
|
{
|
|
6531
6663
|
toolCallSuspended: suspendPayload,
|
|
@@ -6539,6 +6671,18 @@ function createToolCallStep({
|
|
|
6539
6671
|
resumeData
|
|
6540
6672
|
};
|
|
6541
6673
|
const result = await tool.execute(inputData.args, toolOptions);
|
|
6674
|
+
if (tool && "onOutput" in tool && typeof tool.onOutput === "function") {
|
|
6675
|
+
try {
|
|
6676
|
+
await tool.onOutput({
|
|
6677
|
+
toolCallId: inputData.toolCallId,
|
|
6678
|
+
toolName: inputData.toolName,
|
|
6679
|
+
output: result,
|
|
6680
|
+
abortSignal: options?.abortSignal
|
|
6681
|
+
});
|
|
6682
|
+
} catch (error) {
|
|
6683
|
+
console.error("Error calling onOutput", error);
|
|
6684
|
+
}
|
|
6685
|
+
}
|
|
6542
6686
|
return { result, ...inputData };
|
|
6543
6687
|
} catch (error) {
|
|
6544
6688
|
return {
|
|
@@ -6558,6 +6702,7 @@ function createAgenticExecutionWorkflow({ models, _internal, ...rest }) {
|
|
|
6558
6702
|
...rest
|
|
6559
6703
|
});
|
|
6560
6704
|
const toolCallStep = createToolCallStep({
|
|
6705
|
+
_internal,
|
|
6561
6706
|
...rest
|
|
6562
6707
|
});
|
|
6563
6708
|
const llmMappingStep = createLLMMappingStep(
|
|
@@ -6582,6 +6727,16 @@ function createAgenticExecutionWorkflow({ models, _internal, ...rest }) {
|
|
|
6582
6727
|
validateInputs: false
|
|
6583
6728
|
}
|
|
6584
6729
|
}).then(llmExecutionStep).map(
|
|
6730
|
+
async ({ inputData }) => {
|
|
6731
|
+
const typedInputData = inputData;
|
|
6732
|
+
const responseMessages = typedInputData.messages.nonUser;
|
|
6733
|
+
if (responseMessages && responseMessages.length > 0) {
|
|
6734
|
+
rest.messageList.add(responseMessages, "response");
|
|
6735
|
+
}
|
|
6736
|
+
return typedInputData;
|
|
6737
|
+
},
|
|
6738
|
+
{ id: "add-response-to-messagelist" }
|
|
6739
|
+
).map(
|
|
6585
6740
|
async ({ inputData }) => {
|
|
6586
6741
|
const typedInputData = inputData;
|
|
6587
6742
|
return typedInputData.output.toolCalls || [];
|
|
@@ -6845,7 +7000,13 @@ function loop({
|
|
|
6845
7000
|
const internalToUse = {
|
|
6846
7001
|
now: _internal?.now || (() => Date.now()),
|
|
6847
7002
|
generateId: _internal?.generateId || (() => generateId()),
|
|
6848
|
-
currentDate: _internal?.currentDate || (() => /* @__PURE__ */ new Date())
|
|
7003
|
+
currentDate: _internal?.currentDate || (() => /* @__PURE__ */ new Date()),
|
|
7004
|
+
saveQueueManager: _internal?.saveQueueManager,
|
|
7005
|
+
memoryConfig: _internal?.memoryConfig,
|
|
7006
|
+
threadId: _internal?.threadId,
|
|
7007
|
+
resourceId: _internal?.resourceId,
|
|
7008
|
+
memory: _internal?.memory,
|
|
7009
|
+
threadExists: _internal?.threadExists
|
|
6849
7010
|
};
|
|
6850
7011
|
let startTimestamp = internalToUse.now?.();
|
|
6851
7012
|
const messageId = rest.experimental_generateMessageId?.() || internalToUse.generateId?.();
|
|
@@ -7031,7 +7192,8 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
7031
7192
|
_internal,
|
|
7032
7193
|
agentId,
|
|
7033
7194
|
toolCallId,
|
|
7034
|
-
methodType
|
|
7195
|
+
methodType,
|
|
7196
|
+
includeRawChunks
|
|
7035
7197
|
}) {
|
|
7036
7198
|
let stopWhenToUse;
|
|
7037
7199
|
if (maxSteps && typeof maxSteps === "number") {
|
|
@@ -7089,6 +7251,7 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
7089
7251
|
requireToolApproval,
|
|
7090
7252
|
agentId,
|
|
7091
7253
|
methodType,
|
|
7254
|
+
includeRawChunks,
|
|
7092
7255
|
options: {
|
|
7093
7256
|
...options,
|
|
7094
7257
|
onStepFinish: async (props) => {
|
|
@@ -7126,7 +7289,8 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
7126
7289
|
usage: props?.usage,
|
|
7127
7290
|
runId
|
|
7128
7291
|
});
|
|
7129
|
-
|
|
7292
|
+
const remainingTokens = parseInt(props?.response?.headers?.["x-ratelimit-remaining-tokens"] ?? "", 10);
|
|
7293
|
+
if (!isNaN(remainingTokens) && remainingTokens > 0 && remainingTokens < 2e3) {
|
|
7130
7294
|
this.logger.warn("Rate limit approaching, waiting 10 seconds", { runId });
|
|
7131
7295
|
await delay(10 * 1e3);
|
|
7132
7296
|
}
|
|
@@ -7522,11 +7686,13 @@ async function createNetworkLoop({
|
|
|
7522
7686
|
const routingAgent = await getRoutingAgent({ requestContext, agent });
|
|
7523
7687
|
let completionResult;
|
|
7524
7688
|
const iterationCount = (inputData.iteration ?? -1) + 1;
|
|
7689
|
+
const stepId = generateId3();
|
|
7525
7690
|
await writer.write({
|
|
7526
7691
|
type: "routing-agent-start",
|
|
7527
7692
|
payload: {
|
|
7693
|
+
networkId: agent.id,
|
|
7528
7694
|
agentId: routingAgent.id,
|
|
7529
|
-
runId,
|
|
7695
|
+
runId: stepId,
|
|
7530
7696
|
inputData: {
|
|
7531
7697
|
...inputData,
|
|
7532
7698
|
iteration: iterationCount
|
|
@@ -7572,7 +7738,7 @@ async function createNetworkLoop({
|
|
|
7572
7738
|
await writer.write({
|
|
7573
7739
|
type: "routing-agent-text-start",
|
|
7574
7740
|
payload: {
|
|
7575
|
-
runId
|
|
7741
|
+
runId: stepId
|
|
7576
7742
|
},
|
|
7577
7743
|
from: "NETWORK" /* NETWORK */,
|
|
7578
7744
|
runId
|
|
@@ -7586,6 +7752,7 @@ async function createNetworkLoop({
|
|
|
7586
7752
|
await writer.write({
|
|
7587
7753
|
type: "routing-agent-text-delta",
|
|
7588
7754
|
payload: {
|
|
7755
|
+
runId: stepId,
|
|
7589
7756
|
text: currentSlice
|
|
7590
7757
|
},
|
|
7591
7758
|
from: "NETWORK" /* NETWORK */,
|
|
@@ -7614,6 +7781,7 @@ async function createNetworkLoop({
|
|
|
7614
7781
|
await writer.write({
|
|
7615
7782
|
type: "routing-agent-text-delta",
|
|
7616
7783
|
payload: {
|
|
7784
|
+
runId: stepId,
|
|
7617
7785
|
text: currentSlice
|
|
7618
7786
|
},
|
|
7619
7787
|
from: "NETWORK" /* NETWORK */,
|
|
@@ -7634,7 +7802,7 @@ async function createNetworkLoop({
|
|
|
7634
7802
|
isComplete: true,
|
|
7635
7803
|
selectionReason: completionResult.object.completionReason || "",
|
|
7636
7804
|
iteration: iterationCount,
|
|
7637
|
-
runId
|
|
7805
|
+
runId: stepId
|
|
7638
7806
|
};
|
|
7639
7807
|
await writer.write({
|
|
7640
7808
|
type: "routing-agent-end",
|
|
@@ -7736,7 +7904,7 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
7736
7904
|
isComplete: object.primitiveId === "none" && object.primitiveType === "none",
|
|
7737
7905
|
selectionReason: object.selectionReason,
|
|
7738
7906
|
iteration: iterationCount,
|
|
7739
|
-
runId
|
|
7907
|
+
runId: stepId
|
|
7740
7908
|
};
|
|
7741
7909
|
await writer.write({
|
|
7742
7910
|
type: "routing-agent-end",
|
|
@@ -7772,23 +7940,24 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
7772
7940
|
}),
|
|
7773
7941
|
execute: async ({ inputData, writer, getInitData }) => {
|
|
7774
7942
|
const agentsMap = await agent.listAgents({ requestContext });
|
|
7775
|
-
const
|
|
7776
|
-
const agentForStep = agentsMap[agentId];
|
|
7943
|
+
const agentForStep = agentsMap[inputData.primitiveId];
|
|
7777
7944
|
if (!agentForStep) {
|
|
7778
7945
|
const mastraError = new MastraError({
|
|
7779
7946
|
id: "AGENT_NETWORK_AGENT_EXECUTION_STEP_INVALID_TASK_INPUT",
|
|
7780
7947
|
domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
|
|
7781
7948
|
category: "USER" /* USER */,
|
|
7782
|
-
text: `Agent ${
|
|
7949
|
+
text: `Agent ${inputData.primitiveId} not found`
|
|
7783
7950
|
});
|
|
7784
7951
|
throw mastraError;
|
|
7785
7952
|
}
|
|
7953
|
+
const agentId = agentForStep.id;
|
|
7954
|
+
const stepId = generateId3();
|
|
7786
7955
|
await writer.write({
|
|
7787
7956
|
type: "agent-execution-start",
|
|
7788
7957
|
payload: {
|
|
7789
|
-
agentId
|
|
7958
|
+
agentId,
|
|
7790
7959
|
args: inputData,
|
|
7791
|
-
runId
|
|
7960
|
+
runId: stepId
|
|
7792
7961
|
},
|
|
7793
7962
|
from: "NETWORK" /* NETWORK */,
|
|
7794
7963
|
runId
|
|
@@ -7800,9 +7969,12 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
7800
7969
|
for await (const chunk of result.fullStream) {
|
|
7801
7970
|
await writer.write({
|
|
7802
7971
|
type: `agent-execution-event-${chunk.type}`,
|
|
7803
|
-
payload:
|
|
7804
|
-
|
|
7805
|
-
|
|
7972
|
+
payload: {
|
|
7973
|
+
...chunk,
|
|
7974
|
+
runId: stepId
|
|
7975
|
+
},
|
|
7976
|
+
from: "NETWORK" /* NETWORK */,
|
|
7977
|
+
runId
|
|
7806
7978
|
});
|
|
7807
7979
|
}
|
|
7808
7980
|
const memory = await agent.getMemory({ requestContext });
|
|
@@ -7838,10 +8010,11 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
7838
8010
|
});
|
|
7839
8011
|
const endPayload = {
|
|
7840
8012
|
task: inputData.task,
|
|
7841
|
-
agentId
|
|
8013
|
+
agentId,
|
|
7842
8014
|
result: await result.text,
|
|
7843
8015
|
isComplete: false,
|
|
7844
|
-
iteration: inputData.iteration
|
|
8016
|
+
iteration: inputData.iteration,
|
|
8017
|
+
runId: stepId
|
|
7845
8018
|
};
|
|
7846
8019
|
await writer.write({
|
|
7847
8020
|
type: "agent-execution-end",
|
|
@@ -7910,11 +8083,12 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
7910
8083
|
);
|
|
7911
8084
|
throw mastraError;
|
|
7912
8085
|
}
|
|
8086
|
+
const stepId = generateId3();
|
|
7913
8087
|
const run = await wf.createRun({ runId });
|
|
7914
8088
|
const toolData = {
|
|
7915
|
-
|
|
8089
|
+
workflowId: wf.id,
|
|
7916
8090
|
args: inputData,
|
|
7917
|
-
runId
|
|
8091
|
+
runId: stepId
|
|
7918
8092
|
};
|
|
7919
8093
|
await writer?.write({
|
|
7920
8094
|
type: "workflow-execution-start",
|
|
@@ -7927,13 +8101,16 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
7927
8101
|
requestContext
|
|
7928
8102
|
});
|
|
7929
8103
|
let chunks = [];
|
|
7930
|
-
for await (const chunk of stream) {
|
|
8104
|
+
for await (const chunk of stream.fullStream) {
|
|
7931
8105
|
chunks.push(chunk);
|
|
7932
8106
|
await writer?.write({
|
|
7933
8107
|
type: `workflow-execution-event-${chunk.type}`,
|
|
7934
|
-
payload:
|
|
7935
|
-
|
|
7936
|
-
|
|
8108
|
+
payload: {
|
|
8109
|
+
...chunk,
|
|
8110
|
+
runId: stepId
|
|
8111
|
+
},
|
|
8112
|
+
from: "NETWORK" /* NETWORK */,
|
|
8113
|
+
runId
|
|
7937
8114
|
});
|
|
7938
8115
|
}
|
|
7939
8116
|
let runSuccess = true;
|
|
@@ -7975,13 +8152,15 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
7975
8152
|
primitiveType: inputData.primitiveType,
|
|
7976
8153
|
result: finalResult,
|
|
7977
8154
|
isComplete: false,
|
|
7978
|
-
iteration: inputData.iteration
|
|
7979
|
-
name: wf.name
|
|
8155
|
+
iteration: inputData.iteration
|
|
7980
8156
|
};
|
|
7981
8157
|
await writer?.write({
|
|
7982
8158
|
type: "workflow-execution-end",
|
|
7983
8159
|
payload: {
|
|
7984
8160
|
...endPayload,
|
|
8161
|
+
result: workflowState,
|
|
8162
|
+
name: wf.name,
|
|
8163
|
+
runId: stepId,
|
|
7985
8164
|
usage: await stream.usage
|
|
7986
8165
|
},
|
|
7987
8166
|
from: "NETWORK" /* NETWORK */,
|
|
@@ -8016,14 +8195,13 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
8016
8195
|
const memory = await agent.getMemory({ requestContext });
|
|
8017
8196
|
const memoryTools = await memory?.listTools?.();
|
|
8018
8197
|
const toolsMap = { ...agentTools, ...memoryTools };
|
|
8019
|
-
|
|
8020
|
-
let tool = toolsMap[toolId];
|
|
8198
|
+
let tool = toolsMap[inputData.primitiveId];
|
|
8021
8199
|
if (!tool) {
|
|
8022
8200
|
const mastraError = new MastraError({
|
|
8023
8201
|
id: "AGENT_NETWORK_TOOL_EXECUTION_STEP_INVALID_TASK_INPUT",
|
|
8024
8202
|
domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
|
|
8025
8203
|
category: "USER" /* USER */,
|
|
8026
|
-
text: `Tool ${
|
|
8204
|
+
text: `Tool ${inputData.primitiveId} not found`
|
|
8027
8205
|
});
|
|
8028
8206
|
throw mastraError;
|
|
8029
8207
|
}
|
|
@@ -8032,10 +8210,11 @@ ${completionResult?.object?.finalResult}` : ""}
|
|
|
8032
8210
|
id: "AGENT_NETWORK_TOOL_EXECUTION_STEP_INVALID_TASK_INPUT",
|
|
8033
8211
|
domain: "AGENT_NETWORK" /* AGENT_NETWORK */,
|
|
8034
8212
|
category: "USER" /* USER */,
|
|
8035
|
-
text: `Tool ${
|
|
8213
|
+
text: `Tool ${inputData.primitiveId} does not have an execute function`
|
|
8036
8214
|
});
|
|
8037
8215
|
throw mastraError;
|
|
8038
8216
|
}
|
|
8217
|
+
const toolId = tool.id;
|
|
8039
8218
|
let inputDataToUse;
|
|
8040
8219
|
try {
|
|
8041
8220
|
inputDataToUse = JSON.parse(inputData.prompt);
|
|
@@ -11847,6 +12026,7 @@ function createMapResultsStep({
|
|
|
11847
12026
|
stopWhen: result.stopWhen,
|
|
11848
12027
|
maxSteps: result.maxSteps,
|
|
11849
12028
|
providerOptions: result.providerOptions,
|
|
12029
|
+
includeRawChunks: options.includeRawChunks,
|
|
11850
12030
|
options: {
|
|
11851
12031
|
...options.prepareStep && { prepareStep: options.prepareStep },
|
|
11852
12032
|
onFinish: async (payload) => {
|
|
@@ -12202,7 +12382,11 @@ function createStreamStep({
|
|
|
12202
12382
|
resumeContext,
|
|
12203
12383
|
agentId,
|
|
12204
12384
|
toolCallId,
|
|
12205
|
-
methodType
|
|
12385
|
+
methodType,
|
|
12386
|
+
saveQueueManager,
|
|
12387
|
+
memoryConfig,
|
|
12388
|
+
memory,
|
|
12389
|
+
resourceId
|
|
12206
12390
|
}) {
|
|
12207
12391
|
return createStep({
|
|
12208
12392
|
id: "stream-text-step",
|
|
@@ -12229,7 +12413,12 @@ function createStreamStep({
|
|
|
12229
12413
|
requireToolApproval,
|
|
12230
12414
|
resumeContext,
|
|
12231
12415
|
_internal: {
|
|
12232
|
-
generateId: capabilities.generateMessageId
|
|
12416
|
+
generateId: capabilities.generateMessageId,
|
|
12417
|
+
saveQueueManager,
|
|
12418
|
+
memoryConfig,
|
|
12419
|
+
threadId: validatedInputData.threadId,
|
|
12420
|
+
resourceId,
|
|
12421
|
+
memory
|
|
12233
12422
|
},
|
|
12234
12423
|
agentId,
|
|
12235
12424
|
toolCallId,
|
|
@@ -12290,7 +12479,11 @@ function createPrepareStreamWorkflow({
|
|
|
12290
12479
|
resumeContext,
|
|
12291
12480
|
agentId,
|
|
12292
12481
|
toolCallId,
|
|
12293
|
-
methodType
|
|
12482
|
+
methodType,
|
|
12483
|
+
saveQueueManager,
|
|
12484
|
+
memoryConfig,
|
|
12485
|
+
memory,
|
|
12486
|
+
resourceId
|
|
12294
12487
|
});
|
|
12295
12488
|
const mapResultsStep = createMapResultsStep({
|
|
12296
12489
|
capabilities,
|
|
@@ -13331,7 +13524,8 @@ var Agent = class extends MastraBase {
|
|
|
13331
13524
|
requestContext,
|
|
13332
13525
|
tracingContext,
|
|
13333
13526
|
model: await this.getModel({ requestContext }),
|
|
13334
|
-
tracingPolicy: this.#options?.tracingPolicy
|
|
13527
|
+
tracingPolicy: this.#options?.tracingPolicy,
|
|
13528
|
+
requireApproval: toolObj.requireApproval
|
|
13335
13529
|
};
|
|
13336
13530
|
const convertedToCoreTool = makeCoreTool(toolObj, options);
|
|
13337
13531
|
convertedMemoryTools[toolName] = convertedToCoreTool;
|
|
@@ -13529,7 +13723,8 @@ var Agent = class extends MastraBase {
|
|
|
13529
13723
|
requestContext,
|
|
13530
13724
|
tracingContext,
|
|
13531
13725
|
model: await this.getModel({ requestContext }),
|
|
13532
|
-
tracingPolicy: this.#options?.tracingPolicy
|
|
13726
|
+
tracingPolicy: this.#options?.tracingPolicy,
|
|
13727
|
+
requireApproval: toolObj.requireApproval
|
|
13533
13728
|
};
|
|
13534
13729
|
const convertedToCoreTool = makeCoreTool(toolObj, options, "toolset");
|
|
13535
13730
|
toolsForRequest[toolName] = convertedToCoreTool;
|
|
@@ -13572,7 +13767,8 @@ var Agent = class extends MastraBase {
|
|
|
13572
13767
|
requestContext,
|
|
13573
13768
|
tracingContext,
|
|
13574
13769
|
model: await this.getModel({ requestContext }),
|
|
13575
|
-
tracingPolicy: this.#options?.tracingPolicy
|
|
13770
|
+
tracingPolicy: this.#options?.tracingPolicy,
|
|
13771
|
+
requireApproval: tool.requireApproval
|
|
13576
13772
|
};
|
|
13577
13773
|
const convertedToCoreTool = makeCoreTool(rest, options, "client-tool");
|
|
13578
13774
|
toolsForRequest[toolName] = convertedToCoreTool;
|
|
@@ -13597,7 +13793,11 @@ var Agent = class extends MastraBase {
|
|
|
13597
13793
|
if (Object.keys(agents).length > 0) {
|
|
13598
13794
|
for (const [agentName, agent] of Object.entries(agents)) {
|
|
13599
13795
|
const agentInputSchema = z.object({
|
|
13600
|
-
prompt: z.string().describe("The prompt to send to the agent")
|
|
13796
|
+
prompt: z.string().describe("The prompt to send to the agent"),
|
|
13797
|
+
threadId: z.string().optional().describe("Thread ID for conversation continuity for memory messages"),
|
|
13798
|
+
resourceId: z.string().optional().describe("Resource/user identifier for memory messages"),
|
|
13799
|
+
instructions: z.string().optional().describe("Custom instructions to override agent defaults"),
|
|
13800
|
+
maxSteps: z.number().optional().describe("Maximum number of execution steps for the sub-agent")
|
|
13601
13801
|
});
|
|
13602
13802
|
const agentOutputSchema = z.object({
|
|
13603
13803
|
text: z.string().describe("The response from the agent"),
|
|
@@ -13611,7 +13811,6 @@ var Agent = class extends MastraBase {
|
|
|
13611
13811
|
inputSchema: agentInputSchema,
|
|
13612
13812
|
outputSchema: agentOutputSchema,
|
|
13613
13813
|
mastra: this.#mastra,
|
|
13614
|
-
// BREAKING CHANGE v1.0: New tool signature - first param is inputData, second is context
|
|
13615
13814
|
// manually wrap agent tools with tracing, so that we can pass the
|
|
13616
13815
|
// current tool span onto the agent to maintain continuity of the trace
|
|
13617
13816
|
execute: async (inputData, context) => {
|
|
@@ -13624,16 +13823,18 @@ var Agent = class extends MastraBase {
|
|
|
13624
13823
|
resourceId
|
|
13625
13824
|
});
|
|
13626
13825
|
let result;
|
|
13826
|
+
const slugify = await import('@sindresorhus/slugify');
|
|
13827
|
+
const subAgentThreadId = inputData.threadId || context?.mastra?.generateId() || randomUUID();
|
|
13828
|
+
const subAgentResourceId = inputData.resourceId || context?.mastra?.generateId() || `${slugify.default(this.id)}-${agentName}`;
|
|
13627
13829
|
if ((methodType === "generate" || methodType === "generateLegacy") && modelVersion === "v2") {
|
|
13628
13830
|
if (!agent.hasOwnMemory() && this.#memory) {
|
|
13629
13831
|
agent.__setMemory(this.#memory);
|
|
13630
13832
|
}
|
|
13631
|
-
const subAgentThreadId = randomUUID();
|
|
13632
|
-
const slugify = await import('@sindresorhus/slugify');
|
|
13633
|
-
const subAgentResourceId = `${slugify.default(this.id)}-${agentName}`;
|
|
13634
13833
|
const generateResult = await agent.generate(inputData.prompt, {
|
|
13635
13834
|
requestContext,
|
|
13636
13835
|
tracingContext: context?.tracingContext,
|
|
13836
|
+
...inputData.instructions && { instructions: inputData.instructions },
|
|
13837
|
+
...inputData.maxSteps && { maxSteps: inputData.maxSteps },
|
|
13637
13838
|
...resourceId && threadId ? {
|
|
13638
13839
|
memory: {
|
|
13639
13840
|
resource: subAgentResourceId,
|
|
@@ -13652,12 +13853,11 @@ var Agent = class extends MastraBase {
|
|
|
13652
13853
|
if (!agent.hasOwnMemory() && this.#memory) {
|
|
13653
13854
|
agent.__setMemory(this.#memory);
|
|
13654
13855
|
}
|
|
13655
|
-
const subAgentThreadId = randomUUID();
|
|
13656
|
-
const slugify = await import('@sindresorhus/slugify');
|
|
13657
|
-
const subAgentResourceId = `${slugify.default(this.id)}-${agentName}`;
|
|
13658
13856
|
const streamResult = await agent.stream(inputData.prompt, {
|
|
13659
13857
|
requestContext,
|
|
13660
13858
|
tracingContext: context?.tracingContext,
|
|
13859
|
+
...inputData.instructions && { instructions: inputData.instructions },
|
|
13860
|
+
...inputData.maxSteps && { maxSteps: inputData.maxSteps },
|
|
13661
13861
|
...resourceId && threadId ? {
|
|
13662
13862
|
memory: {
|
|
13663
13863
|
resource: subAgentResourceId,
|
|
@@ -13668,7 +13868,11 @@ var Agent = class extends MastraBase {
|
|
|
13668
13868
|
let fullText = "";
|
|
13669
13869
|
for await (const chunk of streamResult.fullStream) {
|
|
13670
13870
|
if (context?.writer) {
|
|
13671
|
-
|
|
13871
|
+
if (chunk.type.startsWith("data-")) {
|
|
13872
|
+
await context.writer.custom(chunk);
|
|
13873
|
+
} else {
|
|
13874
|
+
await context.writer.write(chunk);
|
|
13875
|
+
}
|
|
13672
13876
|
}
|
|
13673
13877
|
if (chunk.type === "text-delta") {
|
|
13674
13878
|
fullText += chunk.payload.text;
|
|
@@ -13683,7 +13887,11 @@ var Agent = class extends MastraBase {
|
|
|
13683
13887
|
let fullText = "";
|
|
13684
13888
|
for await (const chunk of streamResult.fullStream) {
|
|
13685
13889
|
if (context?.writer) {
|
|
13686
|
-
|
|
13890
|
+
if (chunk.type.startsWith("data-")) {
|
|
13891
|
+
await context.writer.custom(chunk);
|
|
13892
|
+
} else {
|
|
13893
|
+
await context.writer.write(chunk);
|
|
13894
|
+
}
|
|
13687
13895
|
}
|
|
13688
13896
|
if (chunk.type === "text-delta") {
|
|
13689
13897
|
fullText += chunk.textDelta;
|
|
@@ -13750,13 +13958,25 @@ var Agent = class extends MastraBase {
|
|
|
13750
13958
|
const workflows = await this.listWorkflows({ requestContext });
|
|
13751
13959
|
if (Object.keys(workflows).length > 0) {
|
|
13752
13960
|
for (const [workflowName, workflow] of Object.entries(workflows)) {
|
|
13961
|
+
const extendedInputSchema = z.object({
|
|
13962
|
+
inputData: workflow.inputSchema,
|
|
13963
|
+
...workflow.stateSchema ? { initialState: workflow.stateSchema } : {}
|
|
13964
|
+
});
|
|
13753
13965
|
const toolObj = createTool({
|
|
13754
13966
|
id: `workflow-${workflowName}`,
|
|
13755
13967
|
description: workflow.description || `Workflow: ${workflowName}`,
|
|
13756
|
-
inputSchema:
|
|
13757
|
-
outputSchema: z.
|
|
13968
|
+
inputSchema: extendedInputSchema,
|
|
13969
|
+
outputSchema: z.union([
|
|
13970
|
+
z.object({
|
|
13971
|
+
result: workflow.outputSchema,
|
|
13972
|
+
runId: z.string().describe("Unique identifier for the workflow run")
|
|
13973
|
+
}),
|
|
13974
|
+
z.object({
|
|
13975
|
+
runId: z.string().describe("Unique identifier for the workflow run"),
|
|
13976
|
+
error: z.string().describe("Error message if workflow execution failed")
|
|
13977
|
+
})
|
|
13978
|
+
]),
|
|
13758
13979
|
mastra: this.#mastra,
|
|
13759
|
-
// BREAKING CHANGE v1.0: New tool signature - first param is inputData, second is context
|
|
13760
13980
|
// manually wrap workflow tools with tracing, so that we can pass the
|
|
13761
13981
|
// current tool span onto the workflow to maintain continuity of the trace
|
|
13762
13982
|
execute: async (inputData, context) => {
|
|
@@ -13770,16 +13990,18 @@ var Agent = class extends MastraBase {
|
|
|
13770
13990
|
resourceId
|
|
13771
13991
|
});
|
|
13772
13992
|
const run = await workflow.createRun();
|
|
13773
|
-
|
|
13993
|
+
const { initialState, inputData: workflowInputData } = inputData;
|
|
13994
|
+
let result = void 0;
|
|
13774
13995
|
if (methodType === "generate" || methodType === "generateLegacy") {
|
|
13775
13996
|
result = await run.start({
|
|
13776
|
-
inputData,
|
|
13997
|
+
inputData: workflowInputData,
|
|
13777
13998
|
requestContext,
|
|
13778
|
-
tracingContext: context?.tracingContext
|
|
13999
|
+
tracingContext: context?.tracingContext,
|
|
14000
|
+
...initialState && { initialState }
|
|
13779
14001
|
});
|
|
13780
14002
|
} else if (methodType === "streamLegacy") {
|
|
13781
14003
|
const streamResult = run.streamLegacy({
|
|
13782
|
-
inputData,
|
|
14004
|
+
inputData: workflowInputData,
|
|
13783
14005
|
requestContext,
|
|
13784
14006
|
tracingContext: context?.tracingContext
|
|
13785
14007
|
});
|
|
@@ -13792,17 +14014,36 @@ var Agent = class extends MastraBase {
|
|
|
13792
14014
|
result = await streamResult.getWorkflowState();
|
|
13793
14015
|
} else if (methodType === "stream") {
|
|
13794
14016
|
const streamResult = run.stream({
|
|
13795
|
-
inputData,
|
|
14017
|
+
inputData: workflowInputData,
|
|
13796
14018
|
requestContext,
|
|
13797
|
-
tracingContext: context?.tracingContext
|
|
14019
|
+
tracingContext: context?.tracingContext,
|
|
14020
|
+
...initialState && { initialState }
|
|
13798
14021
|
});
|
|
13799
14022
|
if (context?.writer) {
|
|
13800
14023
|
await streamResult.fullStream.pipeTo(context.writer);
|
|
13801
14024
|
}
|
|
13802
14025
|
result = await streamResult.result;
|
|
13803
14026
|
}
|
|
13804
|
-
|
|
13805
|
-
|
|
14027
|
+
if (result?.status === "success") {
|
|
14028
|
+
const workflowOutput = result?.result || result;
|
|
14029
|
+
return { result: workflowOutput, runId: run.runId };
|
|
14030
|
+
} else if (result?.status === "failed") {
|
|
14031
|
+
const workflowOutputError = result?.error;
|
|
14032
|
+
return {
|
|
14033
|
+
error: workflowOutputError?.message || String(workflowOutputError) || "Workflow execution failed",
|
|
14034
|
+
runId: run.runId
|
|
14035
|
+
};
|
|
14036
|
+
} else if (result?.status === "suspended") {
|
|
14037
|
+
return {
|
|
14038
|
+
error: `Workflow ended with status: "suspended". This is not currently handled in the basic agent workflow tool transformation. To achieve this you'll need to write your own tool that uses a workflow internally.`,
|
|
14039
|
+
runId: run.runId
|
|
14040
|
+
};
|
|
14041
|
+
} else {
|
|
14042
|
+
return {
|
|
14043
|
+
error: `Workflow should never reach this path, workflow returned no status`,
|
|
14044
|
+
runId: run.runId
|
|
14045
|
+
};
|
|
14046
|
+
}
|
|
13806
14047
|
} catch (err) {
|
|
13807
14048
|
const mastraError = new MastraError(
|
|
13808
14049
|
{
|
|
@@ -14177,6 +14418,34 @@ var Agent = class extends MastraBase {
|
|
|
14177
14418
|
);
|
|
14178
14419
|
}
|
|
14179
14420
|
const llm = await this.getLLM({ requestContext, model: options.model });
|
|
14421
|
+
if ("structuredOutput" in options && options.structuredOutput && options.structuredOutput.schema) {
|
|
14422
|
+
let structuredOutputModel = llm.getModel();
|
|
14423
|
+
if (options.structuredOutput?.model) {
|
|
14424
|
+
structuredOutputModel = await this.resolveModelConfig(
|
|
14425
|
+
options.structuredOutput?.model,
|
|
14426
|
+
requestContext
|
|
14427
|
+
);
|
|
14428
|
+
}
|
|
14429
|
+
const targetProvider = structuredOutputModel.provider;
|
|
14430
|
+
const targetModelId = structuredOutputModel.modelId;
|
|
14431
|
+
if (targetProvider.includes("openai") || targetModelId.includes("openai")) {
|
|
14432
|
+
if (isZodType(options.structuredOutput.schema) && targetModelId) {
|
|
14433
|
+
const modelInfo = {
|
|
14434
|
+
provider: targetProvider,
|
|
14435
|
+
modelId: targetModelId,
|
|
14436
|
+
supportsStructuredOutputs: false
|
|
14437
|
+
// Set to false to enable transform
|
|
14438
|
+
};
|
|
14439
|
+
const isReasoningModel = /^o[1-5]/.test(targetModelId);
|
|
14440
|
+
const compatLayer = isReasoningModel ? new OpenAIReasoningSchemaCompatLayer(modelInfo) : new OpenAISchemaCompatLayer(modelInfo);
|
|
14441
|
+
if (compatLayer.shouldApply() && options.structuredOutput.schema) {
|
|
14442
|
+
options.structuredOutput.schema = compatLayer.processZodType(
|
|
14443
|
+
options.structuredOutput.schema
|
|
14444
|
+
);
|
|
14445
|
+
}
|
|
14446
|
+
}
|
|
14447
|
+
}
|
|
14448
|
+
}
|
|
14180
14449
|
const runId = options.runId || this.#mastra?.generateId() || randomUUID();
|
|
14181
14450
|
const instructions = options.instructions || await this.getInstructions({ requestContext });
|
|
14182
14451
|
const agentSpan = getOrCreateSpan({
|
|
@@ -16493,6 +16762,6 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
16493
16762
|
}
|
|
16494
16763
|
};
|
|
16495
16764
|
|
|
16496
|
-
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 };
|
|
16497
|
-
//# sourceMappingURL=chunk-
|
|
16498
|
-
//# sourceMappingURL=chunk-
|
|
16765
|
+
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, validateStepSuspendData };
|
|
16766
|
+
//# sourceMappingURL=chunk-XBO6W7LZ.js.map
|
|
16767
|
+
//# sourceMappingURL=chunk-XBO6W7LZ.js.map
|