@mastra/core 1.87.0-alpha.0 → 1.87.0-alpha.2
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/dist/_types/@ai-sdk_anthropic@3.0.137/dist/index.d.ts +2 -2
- package/dist/_types/@ai-sdk_google@3.0.140/dist/index.d.ts +2 -2
- package/dist/_types/@ai-sdk_openai@3.0.135/dist/index.d.ts +2 -2
- package/dist/a2a/index.cjs +1 -1
- package/dist/a2a/index.js +1 -1
- package/dist/agent/durable/index.cjs +2 -1
- package/dist/agent/durable/index.d.ts +1 -0
- package/dist/agent/durable/index.js +2 -2
- package/dist/agent/durable/run-registry.d.ts +12 -1
- package/dist/agent/durable/types.d.ts +2 -0
- package/dist/agent/durable/workflows/finalize-run.d.ts +2 -1
- package/dist/agent/index.cjs +3 -3
- package/dist/agent/index.js +3 -3
- package/dist/agent/message-list/index.cjs +1 -1
- package/dist/agent/message-list/index.js +1 -1
- package/dist/agent/thread-stream-runtime.d.ts +3 -1
- package/dist/agent-builder/ee/index.cjs +1 -1
- package/dist/agent-builder/ee/index.js +1 -1
- package/dist/agent-controller/index.cjs +1 -1
- package/dist/agent-controller/index.js +1 -1
- package/dist/{agent-controller-B8LoFdtu.js → agent-controller-Dc58ARqw.js} +6 -6
- package/dist/{agent-controller-DSnFynpa.cjs → agent-controller-v64JbuDa.cjs} +6 -6
- package/dist/background-tasks/index.cjs +1 -1
- package/dist/background-tasks/index.js +1 -1
- package/dist/{background-tasks-Ci5h0dhj.cjs → background-tasks-DgiQNKh7.cjs} +1 -1
- package/dist/{background-tasks-IW7M4iD2.js → background-tasks-E-Jjxks4.js} +1 -1
- package/dist/browser/index.cjs +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/{builder-14Uptu8y.cjs → builder-Dfp6Ckjr.cjs} +2 -2
- package/dist/{builder-DI2c2xjy.js → builder-Dh175HnQ.js} +2 -2
- package/dist/capabilities/302ai.json +197 -197
- package/dist/capabilities/abliteratedllm.json +27 -27
- package/dist/capabilities/abliteration-ai.json +10 -10
- package/dist/capabilities/above.json +22 -22
- package/dist/capabilities/adaption.json +12 -12
- package/dist/capabilities/adzuki.json +29 -29
- package/dist/capabilities/agentrouter.json +8 -8
- package/dist/capabilities/agnes.json +3 -3
- package/dist/capabilities/ai-router.json +5 -5
- package/dist/capabilities/aiand.json +23 -23
- package/dist/capabilities/aigrow.json +12 -12
- package/dist/capabilities/aimlapi.json +151 -152
- package/dist/capabilities/aixy.json +23 -23
- package/dist/capabilities/aki-io.json +14 -14
- package/dist/capabilities/alibaba-cn.json +92 -92
- package/dist/capabilities/alibaba-coding-plan-cn.json +5 -5
- package/dist/capabilities/alibaba-coding-plan.json +5 -5
- package/dist/capabilities/alibaba-token-plan-cn.json +53 -53
- package/dist/capabilities/alibaba-token-plan.json +51 -51
- package/dist/capabilities/alibaba.json +62 -62
- package/dist/capabilities/ambient.json +10 -10
- package/dist/capabilities/amd.json +8 -8
- package/dist/capabilities/anthropic.json +34 -34
- package/dist/capabilities/anyapi.json +18 -18
- package/dist/capabilities/apiko.json +4 -4
- package/dist/capabilities/arcee.json +6 -6
- package/dist/capabilities/augure.json +7 -7
- package/dist/capabilities/auriko.json +21 -21
- package/dist/capabilities/bailing.json +5 -5
- package/dist/capabilities/baseten.json +28 -28
- package/dist/capabilities/bee.json +2 -2
- package/dist/capabilities/berget.json +4 -4
- package/dist/capabilities/bothub.json +16 -16
- package/dist/capabilities/boundless.json +39 -39
- package/dist/capabilities/bumo.json +42 -42
- package/dist/capabilities/byteplus.json +29 -29
- package/dist/capabilities/cerebras.json +4 -4
- package/dist/capabilities/cheapaimodel.json +10 -10
- package/dist/capabilities/cheapest-token.json +29 -29
- package/dist/capabilities/chutes.json +5 -5
- package/dist/capabilities/cline-pass.json +39 -39
- package/dist/capabilities/cloudcode.json +8 -8
- package/dist/capabilities/cloudflare-workers-ai.json +18 -18
- package/dist/capabilities/commandcode.json +154 -154
- package/dist/capabilities/concentrate.json +269 -269
- package/dist/capabilities/cortecs.json +113 -113
- package/dist/capabilities/crossmodel.json +168 -168
- package/dist/capabilities/crusoe.json +9 -9
- package/dist/capabilities/daoxe.json +9 -9
- package/dist/capabilities/databricks.json +128 -128
- package/dist/capabilities/deepinfra.json +99 -99
- package/dist/capabilities/deepseek.json +4 -4
- package/dist/capabilities/digitalocean.json +117 -117
- package/dist/capabilities/dothoosh.json +30 -30
- package/dist/capabilities/doubleword.json +27 -27
- package/dist/capabilities/edenai.json +901 -1734
- package/dist/capabilities/empiriolabs.json +175 -175
- package/dist/capabilities/engy.json +21 -21
- package/dist/capabilities/evroc.json +13 -13
- package/dist/capabilities/ezkielyna.json +8 -8
- package/dist/capabilities/fastrouter.json +78 -78
- package/dist/capabilities/fireworks-ai.json +68 -68
- package/dist/capabilities/freemodel.json +21 -21
- package/dist/capabilities/frogbot.json +96 -96
- package/dist/capabilities/gisoo.json +17 -17
- package/dist/capabilities/gmicloud.json +12 -12
- package/dist/capabilities/google.json +51 -51
- package/dist/capabilities/graphn.json +16 -16
- package/dist/capabilities/greenpt.json +35 -35
- package/dist/capabilities/groq.json +2 -2
- package/dist/capabilities/helicone.json +85 -85
- package/dist/capabilities/hopper.json +2 -2
- package/dist/capabilities/hostinger-router.json +13 -13
- package/dist/capabilities/hpc-ai.json +4 -4
- package/dist/capabilities/huawei-maas.json +12 -12
- package/dist/capabilities/hubris.json +29 -29
- package/dist/capabilities/huggingface.json +89 -89
- package/dist/capabilities/humain.json +2 -2
- package/dist/capabilities/hyper.json +27 -27
- package/dist/capabilities/impossibl.json +149 -149
- package/dist/capabilities/inception.json +3 -3
- package/dist/capabilities/inco.json +4 -4
- package/dist/capabilities/infer.json +12 -12
- package/dist/capabilities/inferall.json +10 -10
- package/dist/capabilities/inference-coop.json +11 -11
- package/dist/capabilities/inferenceapis.json +17 -17
- package/dist/capabilities/inferris.json +4 -4
- package/dist/capabilities/infersia.json +12 -12
- package/dist/capabilities/infomaniak.json +3 -3
- package/dist/capabilities/io-net.json +2 -2
- package/dist/capabilities/isoquant.json +4 -4
- package/dist/capabilities/iteracompute.json +44 -44
- package/dist/capabilities/jad-ai.json +2 -2
- package/dist/capabilities/jalapeno.json +11 -11
- package/dist/capabilities/jiekou.json +68 -68
- package/dist/capabilities/jzstoken.json +48 -48
- package/dist/capabilities/keln.json +20 -20
- package/dist/capabilities/kenari.json +125 -125
- package/dist/capabilities/kilo.json +623 -623
- package/dist/capabilities/kimi-code-plan-cn.json +4 -4
- package/dist/capabilities/kimi-code-plan-global.json +4 -4
- package/dist/capabilities/kitani.json +2 -2
- package/dist/capabilities/klavo.json +18 -18
- package/dist/capabilities/korouter.json +30 -30
- package/dist/capabilities/kunavo.json +6 -6
- package/dist/capabilities/liquid.json +12 -12
- package/dist/capabilities/lithosai.json +2 -2
- package/dist/capabilities/llmgateway-providers.json +916 -916
- package/dist/capabilities/llmgateway.json +339 -339
- package/dist/capabilities/llmtr.json +31 -31
- package/dist/capabilities/longcat.json +2 -2
- package/dist/capabilities/lowrouter.json +51 -51
- package/dist/capabilities/lyceum.json +4 -4
- package/dist/capabilities/melious.json +12 -12
- package/dist/capabilities/merge-gateway.json +255 -254
- package/dist/capabilities/meta.json +7 -7
- package/dist/capabilities/minimax-cn-coding-plan.json +2 -2
- package/dist/capabilities/minimax-cn.json +5 -5
- package/dist/capabilities/minimax-coding-plan.json +2 -2
- package/dist/capabilities/minimax.json +5 -5
- package/dist/capabilities/mistral.json +18 -18
- package/dist/capabilities/mixlayer.json +5 -5
- package/dist/capabilities/modal.json +10 -10
- package/dist/capabilities/model-oracle-ai.json +21 -21
- package/dist/capabilities/modelis.json +19 -19
- package/dist/capabilities/modular.json +10 -10
- package/dist/capabilities/moneo.json +14 -14
- package/dist/capabilities/moonshotai-cn.json +5 -5
- package/dist/capabilities/moonshotai.json +5 -5
- package/dist/capabilities/morph.json +14 -14
- package/dist/capabilities/munito-eu.json +8 -8
- package/dist/capabilities/munito.json +9 -9
- package/dist/capabilities/nan.json +28 -28
- package/dist/capabilities/nano-gpt.json +586 -584
- package/dist/capabilities/nearai.json +87 -87
- package/dist/capabilities/nebius.json +26 -26
- package/dist/capabilities/neon.json +122 -122
- package/dist/capabilities/neuralwatt.json +45 -45
- package/dist/capabilities/nokeep.json +2 -2
- package/dist/capabilities/novita-ai.json +163 -163
- package/dist/capabilities/nvidia.json +22 -22
- package/dist/capabilities/oathbreaker.json +2 -2
- package/dist/capabilities/obscurify.json +25 -25
- package/dist/capabilities/oci.json +5 -5
- package/dist/capabilities/ofox.json +293 -293
- package/dist/capabilities/ollama-cloud.json +58 -58
- package/dist/capabilities/openai.json +55 -55
- package/dist/capabilities/opencode-go.json +86 -86
- package/dist/capabilities/openreason.json +4 -4
- package/dist/capabilities/openrouter.json +529 -535
- package/dist/capabilities/opper.json +27 -27
- package/dist/capabilities/orcarouter.json +192 -192
- package/dist/capabilities/outerlabs.json +31 -31
- package/dist/capabilities/ovhcloud.json +20 -20
- package/dist/capabilities/pareto.json +5 -5
- package/dist/capabilities/pendra.json +4 -4
- package/dist/capabilities/perplexity-agent.json +64 -64
- package/dist/capabilities/perplexity.json +2 -2
- package/dist/capabilities/phala.json +22 -22
- package/dist/capabilities/pioneer.json +20 -20
- package/dist/capabilities/poe.json +113 -113
- package/dist/capabilities/poolside.json +3 -3
- package/dist/capabilities/powerspring.json +9 -9
- package/dist/capabilities/primalabs.json +10 -10
- package/dist/capabilities/prime.json +110 -110
- package/dist/capabilities/privatemode-ai.json +12 -12
- package/dist/capabilities/proxystacks.json +7 -7
- package/dist/capabilities/qiniu-ai.json +14 -14
- package/dist/capabilities/refuseless.json +7 -7
- package/dist/capabilities/regolo-ai.json +8 -8
- package/dist/capabilities/requesty.json +172 -172
- package/dist/capabilities/ruapi.json +15 -15
- package/dist/capabilities/runcrate.json +6 -6
- package/dist/capabilities/runinfra.json +13 -13
- package/dist/capabilities/sakana.json +7 -7
- package/dist/capabilities/sambanova.json +9 -9
- package/dist/capabilities/sandbase.json +24 -24
- package/dist/capabilities/sarvam.json +12 -12
- package/dist/capabilities/scaleway.json +18 -18
- package/dist/capabilities/scnet-token-plan.json +9 -9
- package/dist/capabilities/scx-ai.json +30 -30
- package/dist/capabilities/sensenova.json +12 -12
- package/dist/capabilities/siliconflow-cn.json +45 -45
- package/dist/capabilities/siliconflow.json +53 -53
- package/dist/capabilities/snowflake-cortex.json +22 -22
- package/dist/capabilities/sokkan.json +7 -7
- package/dist/capabilities/sparrowcodes.json +19 -19
- package/dist/capabilities/standardcompute.json +89 -89
- package/dist/capabilities/steadyrouter.json +41 -41
- package/dist/capabilities/stepfun-ai-step-plan.json +5 -5
- package/dist/capabilities/stepfun-ai.json +5 -5
- package/dist/capabilities/stepfun-step-plan.json +5 -5
- package/dist/capabilities/stepfun.json +5 -5
- package/dist/capabilities/stepping-stone.json +11 -11
- package/dist/capabilities/subconscious.json +2 -2
- package/dist/capabilities/synthetic.json +10 -10
- package/dist/capabilities/synthorai.json +23 -23
- package/dist/capabilities/teamorouter.json +25 -25
- package/dist/capabilities/teapot-router.json +13 -13
- package/dist/capabilities/tencent-token-plan.json +40 -40
- package/dist/capabilities/tencent-tokenhub.json +45 -45
- package/dist/capabilities/tensorx.json +27 -27
- package/dist/capabilities/the-grid-ai.json +37 -37
- package/dist/capabilities/thinkingmachines.json +74 -74
- package/dist/capabilities/tinfoil.json +12 -12
- package/dist/capabilities/toapis.json +2 -2
- package/dist/capabilities/togetherai.json +53 -53
- package/dist/capabilities/tokengo.json +23 -23
- package/dist/capabilities/tokenify.json +9 -9
- package/dist/capabilities/trustedrouter.json +4 -4
- package/dist/capabilities/trustedtokens.json +12 -12
- package/dist/capabilities/umans-ai-coding-plan.json +14 -14
- package/dist/capabilities/umans-ai.json +10 -10
- package/dist/capabilities/unrestricted.json +8 -8
- package/dist/capabilities/uplinkswitch.json +23 -23
- package/dist/capabilities/upstage.json +7 -7
- package/dist/capabilities/vancine.json +26 -26
- package/dist/capabilities/vercel.json +576 -576
- package/dist/capabilities/vivgrid.json +85 -85
- package/dist/capabilities/volcengine-coding-plan.json +36 -27
- package/dist/capabilities/volcengine.json +27 -27
- package/dist/capabilities/vultr.json +31 -31
- package/dist/capabilities/wafer.ai.json +14 -14
- package/dist/capabilities/wallaby.json +5 -5
- package/dist/capabilities/wally.json +11 -11
- package/dist/capabilities/wandb.json +11 -11
- package/dist/capabilities/watt.json +24 -24
- package/dist/capabilities/xai.json +6 -6
- package/dist/capabilities/xpersona.json +12 -12
- package/dist/capabilities/xxapi.json +29 -29
- package/dist/capabilities/zai-coding-plan.json +6 -6
- package/dist/capabilities/zai.json +32 -32
- package/dist/capabilities/zenifra.json +27 -27
- package/dist/capabilities/zenmux.json +186 -186
- package/dist/capabilities/zerogpu.json +14 -14
- package/dist/capabilities/zhipuai-coding-plan.json +8 -8
- package/dist/capabilities/zhipuai.json +31 -31
- package/dist/capabilities/zro.json +6 -6
- package/dist/channels/agent-channels.d.ts +7 -0
- package/dist/channels/attach-file-tool.d.ts +22 -0
- package/dist/channels/index.cjs +11 -2
- package/dist/channels/index.d.ts +10 -0
- package/dist/channels/index.js +3 -3
- package/dist/channels/reply-guidance-processor.d.ts +26 -0
- package/dist/channels/reply-mode.d.ts +66 -0
- package/dist/channels/reply-reminder-processor.d.ts +23 -0
- package/dist/channels/reply-tool.d.ts +43 -0
- package/dist/channels/thread-link-processor.d.ts +48 -0
- package/dist/channels/thread-lookup.d.ts +16 -0
- package/dist/channels/tool-announcement-processor.d.ts +29 -0
- package/dist/channels/types.d.ts +25 -0
- package/dist/{channels-Wh32drgu.js → channels-0AO7PMJF.js} +99 -2
- package/dist/{channels-tVV_de9Q.cjs → channels-BZL9RT2i.cjs} +122 -1
- package/dist/coding-agent/index.cjs +1 -1
- package/dist/coding-agent/index.js +1 -1
- package/dist/datasets/experiment/index.d.ts +1 -1
- package/dist/datasets/experiment/item.d.ts +4 -3
- package/dist/datasets/experiment/scorer.d.ts +34 -11
- package/dist/datasets/index.cjs +3 -2
- package/dist/datasets/index.js +3 -3
- package/dist/{dist-ByO0vuJJ-BjMue5_p.cjs → dist-CufwpBZM-CwERFaas.cjs} +4 -4
- package/dist/{dist-ByO0vuJJ-CCXLBnvJ.js → dist-CufwpBZM-DK14Qe0Z.js} +4 -4
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +743 -743
- package/dist/docs/references/docs-channels.md +43 -0
- package/dist/docs/references/docs-evals-experiments.md +13 -3
- package/dist/docs/references/reference-agents-durable-agent.md +2 -0
- package/dist/docs/references/reference-channels-thread-link.md +67 -0
- package/dist/docs/references/reference-workspace-factory-sandbox.md +2 -1
- package/dist/docs/references/reference.md +1 -0
- package/dist/evals/index.cjs +1 -1
- package/dist/evals/index.js +1 -1
- package/dist/evals/scoreTraces/index.cjs +1 -1
- package/dist/evals/scoreTraces/index.js +1 -1
- package/dist/harness/index.cjs +1 -1
- package/dist/harness/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/knowledge/importers/host.d.ts +7 -1
- package/dist/knowledge/importers/runner.d.ts +12 -0
- package/dist/knowledge/importers/types.d.ts +2 -0
- package/dist/knowledge/index.cjs +82 -6
- package/dist/knowledge/index.js +82 -6
- package/dist/llm/index.cjs +3 -3
- package/dist/llm/index.js +3 -3
- package/dist/llm/model/provider-types.generated.d.ts +7397 -7534
- package/dist/{llm-B1zaFLYZ.js → llm-B46V7Mi7.js} +2 -2
- package/dist/{llm-BAiOsNAP.cjs → llm-B4AeSFvV.cjs} +2 -2
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +2 -2
- package/dist/{manager-ChK9GdGz.js → manager-BRAvwB9b.js} +120 -70
- package/dist/{manager-BVX9nVrM.cjs → manager-BwDxA1Nn.cjs} +125 -69
- package/dist/mastra/index.cjs +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/{mastra-CUGfgEpZ.js → mastra-CIx6qEq2.js} +16 -16
- package/dist/{mastra-HSmofHEJ.cjs → mastra-DBhdD172.cjs} +16 -16
- package/dist/memory/index.cjs +3 -3
- package/dist/memory/index.js +3 -3
- package/dist/{message-list-Cj0Sq_JP.cjs → message-list-DfN9mWeN.cjs} +121 -121
- package/dist/{message-list-KRbg-TnI.js → message-list-wI71UGxk.js} +1 -1
- package/dist/{model-C47BJRtR.js → model-CJMsDU8w.js} +1 -1
- package/dist/{model-WahorgzJ.cjs → model-CYhAa5qO.cjs} +1 -1
- package/dist/{netlify-D99AnEhW.cjs → netlify-Bw7Vd58y.cjs} +11 -11
- package/dist/{netlify-CfDXkuLf.js → netlify-C9aJA6Cv.js} +10 -10
- package/dist/notifications/index.cjs +1 -1
- package/dist/notifications/index.js +1 -1
- package/dist/processor-provider/index.cjs +1 -1
- package/dist/processor-provider/index.js +1 -1
- package/dist/processors/index.cjs +2 -2
- package/dist/processors/index.js +2 -2
- package/dist/{provider-registry-CO1NVbO5.cjs → provider-registry-Bn_7VvZ8.cjs} +22046 -22320
- package/dist/{provider-registry-CR385GJ4.js → provider-registry-DOfYSEju.js} +22046 -22320
- package/dist/provider-registry.json +22352 -22626
- package/dist/{registry-generator-Cvp34qcB.cjs → registry-generator-BnK5Npgr.cjs} +1 -1
- package/dist/{registry-generator-B3erRqYS.js → registry-generator-Cw594Ttt.js} +1 -1
- package/dist/{rehydrate-Da4hNuaK.cjs → rehydrate-BWnd_TEx.cjs} +2 -2
- package/dist/{rehydrate-CJBLrZxs.js → rehydrate-Dgqkw7Py.js} +2 -2
- package/dist/relevance/index.cjs +2 -2
- package/dist/relevance/index.js +2 -2
- package/dist/{run-registry-DdeEBsVW.js → run-registry-DhOKJtlb.js} +848 -186
- package/dist/{run-registry-TOOfO3hT.cjs → run-registry-lLRc7EE6.cjs} +883 -185
- package/dist/storage/index.cjs +2 -2
- package/dist/storage/index.js +2 -2
- package/dist/stream/index.cjs +2 -2
- package/dist/stream/index.js +2 -2
- package/dist/{stream-DH7Qgz8l.cjs → stream-BIDts1fZ.cjs} +2 -2
- package/dist/{stream-C5PagEDs.js → stream-C8HKG3qC.js} +2 -2
- package/dist/test-utils/llm-mock.cjs +1 -1
- package/dist/test-utils/llm-mock.js +1 -1
- package/dist/tool-loop-agent/index.cjs +1 -1
- package/dist/tool-loop-agent/index.js +1 -1
- package/dist/{tool-loop-agent-DVYJXlQJ.js → tool-loop-agent-DM5V_0XS.js} +4 -4
- package/dist/{tool-loop-agent-CJTs4T8b.cjs → tool-loop-agent-PEY5a1R6.cjs} +4 -4
- package/dist/{utils-xJi_N6Tx.cjs → utils-CxMSu_wc.cjs} +1 -1
- package/dist/{utils-D8upuTwy.js → utils-DcnKVK34.js} +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +1 -1
- package/dist/{validate-DTkW3Vlp.js → validate-Dn750ciE.js} +1 -1
- package/dist/{validate-6eZ8Wssn.cjs → validate-RVKgazCf.cjs} +1 -1
- package/dist/vector/index.cjs +2 -2
- package/dist/vector/index.js +2 -2
- package/dist/worker/index.cjs +1 -1
- package/dist/worker/index.js +1 -1
- package/dist/{worker-24ORi-wV.cjs → worker-CFPu9qwV.cjs} +2 -2
- package/dist/{worker-Dqubrnf8.js → worker-DJPAdazC.js} +2 -2
- package/dist/{worker-BO3u_WjZ.cjs → worker-Dx0ZHMGX.cjs} +2 -2
- package/dist/{worker-DbcFkKJO.js → worker-SDi9jbP5.js} +2 -2
- package/dist/{workflow-wXOf72fO.js → workflow-DkBqNn7X.js} +3 -3
- package/dist/{workflow-D5Fc5ieC.cjs → workflow-ZFOz_365.cjs} +3 -3
- package/dist/workflows/builder/index.cjs +1 -1
- package/dist/workflows/builder/index.js +1 -1
- package/dist/workflows/evented/index.cjs +1 -1
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/index.cjs +4 -4
- package/dist/workflows/index.js +4 -4
- package/package.json +7 -7
- package/src/llm/model/provider-types.generated.d.ts +7397 -7534
- /package/dist/_types/{@ai-sdk_provider-utils@4.0.66 → @ai-sdk_provider-utils@4.0.67}/dist/index.d.ts +0 -0
- /package/dist/_types/{@ai-sdk_provider-utils@4.0.66 → @ai-sdk_provider-utils@4.0.67}/package.json +0 -0
|
@@ -4,14 +4,14 @@ const require_base = require("./base-BIzR1D3_.cjs");
|
|
|
4
4
|
const require_observability = require("./observability-B0R_D1PZ.cjs");
|
|
5
5
|
const require_error = require("./error-D90lJ6M7.cjs");
|
|
6
6
|
const require_error$1 = require("./error-L1V4uUbd.cjs");
|
|
7
|
-
const require_stream = require("./stream-
|
|
7
|
+
const require_stream = require("./stream-BIDts1fZ.cjs");
|
|
8
8
|
const require_request_context = require("./request-context-D9RXYCy8.cjs");
|
|
9
9
|
const require_output_helpers = require("./output-helpers-DgsH4aTb.cjs");
|
|
10
|
-
const require_message_list = require("./message-list-
|
|
10
|
+
const require_message_list = require("./message-list-DfN9mWeN.cjs");
|
|
11
11
|
const require_storage = require("./storage-CfG0I2aF.cjs");
|
|
12
12
|
const require_utils = require("./utils-D-eNsgDM.cjs");
|
|
13
13
|
const require_error_count = require("./error-count-DeDpeWU2.cjs");
|
|
14
|
-
const require_llm = require("./llm-
|
|
14
|
+
const require_llm = require("./llm-B4AeSFvV.cjs");
|
|
15
15
|
const require_payload_transform = require("./payload-transform-CWgnsO9w.cjs");
|
|
16
16
|
const require_utils_safe_stringify = require("./utils/safe-stringify.cjs");
|
|
17
17
|
const require_signals = require("./signals-CWxAMEmE.cjs");
|
|
@@ -23,13 +23,13 @@ const require_tool = require("./tool-CYlT2UA-.cjs");
|
|
|
23
23
|
const require_toolchecks = require("./toolchecks-MFU48cit.cjs");
|
|
24
24
|
const require_fetchWithRetry = require("./fetchWithRetry-f5k4p7_1.cjs");
|
|
25
25
|
const require_model = require("./model-jBymoqGa.cjs");
|
|
26
|
-
const require_provider_registry = require("./provider-registry-
|
|
26
|
+
const require_provider_registry = require("./provider-registry-Bn_7VvZ8.cjs");
|
|
27
27
|
const require_inmemory = require("./inmemory-Dc86VWGB.cjs");
|
|
28
28
|
const require_dynamic_argument = require("./dynamic-argument-CUc1BBOS.cjs");
|
|
29
|
-
const require_model$1 = require("./model-
|
|
30
|
-
const require_utils$1 = require("./utils-
|
|
29
|
+
const require_model$1 = require("./model-CYhAa5qO.cjs");
|
|
30
|
+
const require_utils$1 = require("./utils-CxMSu_wc.cjs");
|
|
31
31
|
const require_ee_iTj2bRDt = require("./ee-iTj2bRDt-D3-QLGDF.cjs");
|
|
32
|
-
const require_background_tasks = require("./background-tasks-
|
|
32
|
+
const require_background_tasks = require("./background-tasks-DgiQNKh7.cjs");
|
|
33
33
|
const require_stream$1 = require("./stream-BGbj9jAU.cjs");
|
|
34
34
|
const require_predicate_index = require("./predicate/index.cjs");
|
|
35
35
|
const require_classifier_index = require("./classifier/index.cjs");
|
|
@@ -12038,6 +12038,118 @@ function liveRequestEntries(runLevel) {
|
|
|
12038
12038
|
const kept = require_request_context.withoutLiveRequestKeys(live);
|
|
12039
12039
|
return Object.entries(live).filter(([key]) => !(key in kept));
|
|
12040
12040
|
}
|
|
12041
|
+
// src/agent/streams/constants.ts
|
|
12042
|
+
/**
|
|
12043
|
+
* Topics and event types of an agent's resumable run stream.
|
|
12044
|
+
*/
|
|
12045
|
+
/**
|
|
12046
|
+
* Generate the pubsub topic name for agent streaming events
|
|
12047
|
+
* @param runId - The unique run identifier
|
|
12048
|
+
* @returns The topic name for subscribing/publishing agent stream events
|
|
12049
|
+
*/
|
|
12050
|
+
const AGENT_STREAM_TOPIC = (runId) => `agent.stream.${runId}`;
|
|
12051
|
+
/**
|
|
12052
|
+
* Generate the pubsub topic name for agent control messages.
|
|
12053
|
+
*
|
|
12054
|
+
* Separate from {@link AGENT_STREAM_TOPIC} because control messages travel the
|
|
12055
|
+
* opposite direction: stream events flow worker -> consumer, control messages
|
|
12056
|
+
* flow caller -> worker. Keeping them apart means stream consumers never see
|
|
12057
|
+
* control traffic and vice versa.
|
|
12058
|
+
*
|
|
12059
|
+
* @param runId - The unique run identifier
|
|
12060
|
+
* @returns The topic name for publishing/subscribing agent control events
|
|
12061
|
+
*/
|
|
12062
|
+
const AGENT_CONTROL_TOPIC = (runId) => `agent.control.${runId}`;
|
|
12063
|
+
/**
|
|
12064
|
+
* Event type constants for agent control events
|
|
12065
|
+
*/
|
|
12066
|
+
const AgentControlEventTypes = {
|
|
12067
|
+
/**
|
|
12068
|
+
* Request that a run abort itself. Published by `abort()` in whichever
|
|
12069
|
+
* process the caller lives in; handled by whichever process is actually
|
|
12070
|
+
* executing the run's steps.
|
|
12071
|
+
*/
|
|
12072
|
+
ABORT_REQUEST: "abort-request" };
|
|
12073
|
+
/**
|
|
12074
|
+
* Event type constants for agent stream events
|
|
12075
|
+
*/
|
|
12076
|
+
const AgentStreamEventTypes = {
|
|
12077
|
+
/** Chunk of streaming data (text, tool call, etc.) */
|
|
12078
|
+
CHUNK: "chunk",
|
|
12079
|
+
/** Internal boundary preceding all output from an LLM execution step. */
|
|
12080
|
+
ITERATION_START: "iteration-start",
|
|
12081
|
+
/** Start of a new step in the agentic loop */
|
|
12082
|
+
STEP_START: "step-start",
|
|
12083
|
+
/** End of a step in the agentic loop */
|
|
12084
|
+
STEP_FINISH: "step-finish",
|
|
12085
|
+
/** Agent execution completed successfully */
|
|
12086
|
+
FINISH: "finish",
|
|
12087
|
+
/** Error occurred during execution */
|
|
12088
|
+
ERROR: "error",
|
|
12089
|
+
/** Workflow suspended (e.g., for tool approval) */
|
|
12090
|
+
SUSPENDED: "suspended",
|
|
12091
|
+
/** Execution aborted by abortSignal */
|
|
12092
|
+
ABORT: "abort",
|
|
12093
|
+
/** Single agentic-loop iteration completed (observability hook) */
|
|
12094
|
+
ITERATION_COMPLETE: "iteration-complete",
|
|
12095
|
+
/**
|
|
12096
|
+
* A new execution claimed the run. Carries no chunk: consumers only raise
|
|
12097
|
+
* their generation so events the superseded execution still publishes are
|
|
12098
|
+
* dropped.
|
|
12099
|
+
*/
|
|
12100
|
+
OWNERSHIP_CLAIMED: "ownership-claimed"
|
|
12101
|
+
};
|
|
12102
|
+
// src/agent/durable/constants.ts
|
|
12103
|
+
const DURABLE_STOP_WHEN_ERROR_ID = "DURABLE_AGENT_STOP_WHEN_FAILED";
|
|
12104
|
+
const REJECT_STREAM_ERROR = Symbol("mastra.durable.rejectStreamError");
|
|
12105
|
+
function markErrorForStreamRejection(error) {
|
|
12106
|
+
error[REJECT_STREAM_ERROR] = true;
|
|
12107
|
+
return error;
|
|
12108
|
+
}
|
|
12109
|
+
function shouldRejectStream(error) {
|
|
12110
|
+
return error[REJECT_STREAM_ERROR] === true;
|
|
12111
|
+
}
|
|
12112
|
+
/**
|
|
12113
|
+
* Default values for durable agent execution
|
|
12114
|
+
*/
|
|
12115
|
+
const DurableAgentDefaults = {
|
|
12116
|
+
/** Default maximum number of agentic loop iterations */
|
|
12117
|
+
MAX_STEPS: 5,
|
|
12118
|
+
/**
|
|
12119
|
+
* Default tool call concurrency.
|
|
12120
|
+
* Applied by `resolveDurableToolCallConcurrency` when a run doesn't
|
|
12121
|
+
* configure `toolCallConcurrency`. Approval / suspend-capable tool sets
|
|
12122
|
+
* always run sequentially (concurrency: 1) regardless of this value.
|
|
12123
|
+
*/
|
|
12124
|
+
TOOL_CALL_CONCURRENCY: 10
|
|
12125
|
+
};
|
|
12126
|
+
/**
|
|
12127
|
+
* Step IDs used in the durable agentic workflow
|
|
12128
|
+
*/
|
|
12129
|
+
const DurableStepIds = {
|
|
12130
|
+
/** LLM execution step */
|
|
12131
|
+
LLM_EXECUTION: "durable-llm-execution",
|
|
12132
|
+
/** Tool call step */
|
|
12133
|
+
TOOL_CALL: "durable-tool-call",
|
|
12134
|
+
/** LLM mapping step (combines results) */
|
|
12135
|
+
LLM_MAPPING: "durable-llm-mapping",
|
|
12136
|
+
/** Agentic execution workflow (one iteration) */
|
|
12137
|
+
AGENTIC_EXECUTION: "durable-agentic-execution",
|
|
12138
|
+
/** Full agentic loop workflow */
|
|
12139
|
+
AGENTIC_LOOP: "durable-agentic-loop",
|
|
12140
|
+
/** Scorer execution step */
|
|
12141
|
+
SCORER_EXECUTION: "durable-scorer-execution",
|
|
12142
|
+
/** isTaskComplete evaluation step */
|
|
12143
|
+
IS_TASK_COMPLETE: "durable-is-task-complete"
|
|
12144
|
+
};
|
|
12145
|
+
/** The loop's last step, which ends the run's spans when it succeeds. */
|
|
12146
|
+
const MAP_FINAL_OUTPUT_STEP_ID = "map-final-output";
|
|
12147
|
+
const RECOVER_ALREADY_IN_PROGRESS_ERROR_ID = "DURABLE_AGENT_RECOVER_ALREADY_IN_PROGRESS";
|
|
12148
|
+
const RECOVER_SNAPSHOT_NOT_FOUND_ERROR_ID = "DURABLE_AGENT_RECOVER_SNAPSHOT_NOT_FOUND";
|
|
12149
|
+
const RECOVER_CHECKPOINT_NOT_AVAILABLE_ERROR_ID = "DURABLE_AGENT_RECOVER_CHECKPOINT_NOT_AVAILABLE";
|
|
12150
|
+
const RECOVER_RUN_SUSPENDED_ERROR_ID = "DURABLE_AGENT_RECOVER_RUN_SUSPENDED";
|
|
12151
|
+
const RECOVER_RUN_NOT_ACTIVE_ERROR_ID = "DURABLE_AGENT_RECOVER_RUN_NOT_ACTIVE";
|
|
12152
|
+
const RECOVER_SHUTDOWN_ERROR_ID = "DURABLE_AGENT_RECOVER_SHUTDOWN";
|
|
12041
12153
|
// src/agent/durable/execution-ownership-guard.ts
|
|
12042
12154
|
/** One step's observation of its immutable driver's claim. Never renews it. */
|
|
12043
12155
|
var ExecutionOwnershipGuard = class {
|
|
@@ -12155,67 +12267,6 @@ var ExecutionOwnershipGuard = class {
|
|
|
12155
12267
|
this.#unsubscribe?.();
|
|
12156
12268
|
}
|
|
12157
12269
|
};
|
|
12158
|
-
// src/agent/streams/constants.ts
|
|
12159
|
-
/**
|
|
12160
|
-
* Topics and event types of an agent's resumable run stream.
|
|
12161
|
-
*/
|
|
12162
|
-
/**
|
|
12163
|
-
* Generate the pubsub topic name for agent streaming events
|
|
12164
|
-
* @param runId - The unique run identifier
|
|
12165
|
-
* @returns The topic name for subscribing/publishing agent stream events
|
|
12166
|
-
*/
|
|
12167
|
-
const AGENT_STREAM_TOPIC = (runId) => `agent.stream.${runId}`;
|
|
12168
|
-
/**
|
|
12169
|
-
* Generate the pubsub topic name for agent control messages.
|
|
12170
|
-
*
|
|
12171
|
-
* Separate from {@link AGENT_STREAM_TOPIC} because control messages travel the
|
|
12172
|
-
* opposite direction: stream events flow worker -> consumer, control messages
|
|
12173
|
-
* flow caller -> worker. Keeping them apart means stream consumers never see
|
|
12174
|
-
* control traffic and vice versa.
|
|
12175
|
-
*
|
|
12176
|
-
* @param runId - The unique run identifier
|
|
12177
|
-
* @returns The topic name for publishing/subscribing agent control events
|
|
12178
|
-
*/
|
|
12179
|
-
const AGENT_CONTROL_TOPIC = (runId) => `agent.control.${runId}`;
|
|
12180
|
-
/**
|
|
12181
|
-
* Event type constants for agent control events
|
|
12182
|
-
*/
|
|
12183
|
-
const AgentControlEventTypes = {
|
|
12184
|
-
/**
|
|
12185
|
-
* Request that a run abort itself. Published by `abort()` in whichever
|
|
12186
|
-
* process the caller lives in; handled by whichever process is actually
|
|
12187
|
-
* executing the run's steps.
|
|
12188
|
-
*/
|
|
12189
|
-
ABORT_REQUEST: "abort-request" };
|
|
12190
|
-
/**
|
|
12191
|
-
* Event type constants for agent stream events
|
|
12192
|
-
*/
|
|
12193
|
-
const AgentStreamEventTypes = {
|
|
12194
|
-
/** Chunk of streaming data (text, tool call, etc.) */
|
|
12195
|
-
CHUNK: "chunk",
|
|
12196
|
-
/** Internal boundary preceding all output from an LLM execution step. */
|
|
12197
|
-
ITERATION_START: "iteration-start",
|
|
12198
|
-
/** Start of a new step in the agentic loop */
|
|
12199
|
-
STEP_START: "step-start",
|
|
12200
|
-
/** End of a step in the agentic loop */
|
|
12201
|
-
STEP_FINISH: "step-finish",
|
|
12202
|
-
/** Agent execution completed successfully */
|
|
12203
|
-
FINISH: "finish",
|
|
12204
|
-
/** Error occurred during execution */
|
|
12205
|
-
ERROR: "error",
|
|
12206
|
-
/** Workflow suspended (e.g., for tool approval) */
|
|
12207
|
-
SUSPENDED: "suspended",
|
|
12208
|
-
/** Execution aborted by abortSignal */
|
|
12209
|
-
ABORT: "abort",
|
|
12210
|
-
/** Single agentic-loop iteration completed (observability hook) */
|
|
12211
|
-
ITERATION_COMPLETE: "iteration-complete",
|
|
12212
|
-
/**
|
|
12213
|
-
* A new execution claimed the run. Carries no chunk: consumers only raise
|
|
12214
|
-
* their generation so events the superseded execution still publishes are
|
|
12215
|
-
* dropped.
|
|
12216
|
-
*/
|
|
12217
|
-
OWNERSHIP_CLAIMED: "ownership-claimed"
|
|
12218
|
-
};
|
|
12219
12270
|
// src/agent/streams/run-records.ts
|
|
12220
12271
|
/**
|
|
12221
12272
|
* Lifetime of a running or suspended run's record. Deliberately much longer
|
|
@@ -14227,26 +14278,97 @@ var ExecutionFence = class ExecutionFence {
|
|
|
14227
14278
|
if (!claim.agentId) return void 0;
|
|
14228
14279
|
const executionBackend = await resolveRemoteBackend(mastra, claim.agentId, runId, claim);
|
|
14229
14280
|
if (!executionBackend) return void 0;
|
|
14230
|
-
const
|
|
14231
|
-
|
|
14232
|
-
|
|
14233
|
-
|
|
14234
|
-
|
|
14235
|
-
|
|
14236
|
-
|
|
14237
|
-
|
|
14238
|
-
|
|
14239
|
-
|
|
14281
|
+
const details = {
|
|
14282
|
+
agentId: claim.agentId,
|
|
14283
|
+
runId,
|
|
14284
|
+
executionId: claim.executionId
|
|
14285
|
+
};
|
|
14286
|
+
const threadId = claim.threadId;
|
|
14287
|
+
const lease = threadId ? [
|
|
14288
|
+
mastra.pubsub,
|
|
14289
|
+
runId,
|
|
14290
|
+
threadId,
|
|
14291
|
+
claim.resourceId,
|
|
14292
|
+
claim.generation,
|
|
14293
|
+
claim.executionId
|
|
14294
|
+
] : void 0;
|
|
14295
|
+
let heartbeatRenewal;
|
|
14296
|
+
let participant;
|
|
14297
|
+
const verifyCurrent = async () => {
|
|
14298
|
+
await executionBackend.verify(claim, details);
|
|
14299
|
+
if (participant?.isLost()) throw new DurableExecutionFenceError(EXECUTION_UNVERIFIED_ERROR_ID, details);
|
|
14300
|
+
};
|
|
14301
|
+
const checkThread = async (threadLease, heartbeatWorker) => {
|
|
14302
|
+
const stopped = () => heartbeatWorker && (!heartbeatWorker.#heartbeat || heartbeatWorker.isLost());
|
|
14303
|
+
let timedOut = false;
|
|
14304
|
+
let timer;
|
|
14305
|
+
const check = async () => {
|
|
14306
|
+
let renewed;
|
|
14307
|
+
try {
|
|
14308
|
+
renewed = await agentThreadStreamRuntime.renewDurableThreadLease(...threadLease);
|
|
14309
|
+
} catch (error) {
|
|
14310
|
+
if (agentThreadStreamRuntime.isThreadLeaseBackendUnavailableToAll(mastra.pubsub, error)) return true;
|
|
14311
|
+
throw error;
|
|
14312
|
+
}
|
|
14313
|
+
if (renewed) return true;
|
|
14314
|
+
if (timedOut || stopped()) return void 0;
|
|
14315
|
+
await verifyCurrent();
|
|
14316
|
+
if (timedOut || stopped()) return void 0;
|
|
14317
|
+
let acquired;
|
|
14318
|
+
try {
|
|
14319
|
+
acquired = await agentThreadStreamRuntime.reclaimDurableThreadLease(...threadLease);
|
|
14320
|
+
} catch (error) {
|
|
14321
|
+
if (agentThreadStreamRuntime.isThreadLeaseBackendUnavailableToAll(mastra.pubsub, error)) return true;
|
|
14322
|
+
throw error;
|
|
14323
|
+
}
|
|
14324
|
+
if (acquired) try {
|
|
14325
|
+
await verifyCurrent();
|
|
14326
|
+
} catch (error) {
|
|
14327
|
+
if (error instanceof DurableExecutionFenceError && error.id === "DURABLE_AGENT_EXECUTION_SUPERSEDED") (async () => {
|
|
14328
|
+
const snapshot = await (await mastra.getStorage()?.getStore("workflows"))?.loadWorkflowSnapshot({
|
|
14329
|
+
workflowName: DurableStepIds.AGENTIC_LOOP,
|
|
14330
|
+
runId
|
|
14331
|
+
});
|
|
14332
|
+
if (!(snapshot?.status === "suspended" || snapshot?.status === "waiting") || await executionBackend.isSuperseded(claim)) await agentThreadStreamRuntime.releaseDurableThreadLease(...threadLease);
|
|
14333
|
+
})().catch(() => {});
|
|
14334
|
+
throw error;
|
|
14335
|
+
}
|
|
14336
|
+
else if (heartbeatWorker) {
|
|
14337
|
+
if (timedOut || stopped()) return void 0;
|
|
14338
|
+
const [pubsub, , threadId, resourceId] = threadLease;
|
|
14339
|
+
if (!await agentThreadStreamRuntime.isDurableThreadLeaseHeldByAnotherRun(pubsub, runId, threadId, resourceId)) return;
|
|
14340
|
+
}
|
|
14341
|
+
return acquired;
|
|
14342
|
+
};
|
|
14240
14343
|
try {
|
|
14241
|
-
return await
|
|
14242
|
-
|
|
14243
|
-
|
|
14244
|
-
|
|
14245
|
-
|
|
14344
|
+
return await Promise.race([check(), new Promise((resolve) => {
|
|
14345
|
+
timer = setTimeout(() => {
|
|
14346
|
+
timedOut = true;
|
|
14347
|
+
resolve(void 0);
|
|
14348
|
+
}, EXECUTION_LEASE_RENEW_INTERVAL_MS);
|
|
14349
|
+
timer.unref?.();
|
|
14350
|
+
})]);
|
|
14351
|
+
} finally {
|
|
14352
|
+
clearTimeout(timer);
|
|
14246
14353
|
}
|
|
14247
14354
|
};
|
|
14248
14355
|
const backend = {
|
|
14249
14356
|
...executionBackend,
|
|
14357
|
+
verify: async () => {
|
|
14358
|
+
await verifyCurrent();
|
|
14359
|
+
if (!lease || claim.generation === void 0) return;
|
|
14360
|
+
for (;;) {
|
|
14361
|
+
const held = await checkThread(lease);
|
|
14362
|
+
await verifyCurrent();
|
|
14363
|
+
if (held === true) return;
|
|
14364
|
+
if (held === false) {
|
|
14365
|
+
ExecutionFence.releaseSharedClaim(mastra, runId, claim, "abandoned").catch(() => {});
|
|
14366
|
+
throw new DurableExecutionFenceError(EXECUTION_UNVERIFIED_ERROR_ID, details);
|
|
14367
|
+
}
|
|
14368
|
+
await sleep(VERIFY_RETRY_DELAY_MS);
|
|
14369
|
+
await verifyCurrent();
|
|
14370
|
+
}
|
|
14371
|
+
},
|
|
14250
14372
|
renew: async (current) => {
|
|
14251
14373
|
const result = await executionBackend.renew(current);
|
|
14252
14374
|
if (!result.renewed) {
|
|
@@ -14257,20 +14379,22 @@ var ExecutionFence = class ExecutionFence {
|
|
|
14257
14379
|
});
|
|
14258
14380
|
return result;
|
|
14259
14381
|
}
|
|
14260
|
-
if (
|
|
14261
|
-
|
|
14262
|
-
|
|
14263
|
-
|
|
14264
|
-
|
|
14382
|
+
if (lease) {
|
|
14383
|
+
if (claim.generation === void 0) {
|
|
14384
|
+
if (!await agentThreadStreamRuntime.renewDurableThreadLease(...lease)) throw new DurableExecutionFenceError(EXECUTION_UNVERIFIED_ERROR_ID, details);
|
|
14385
|
+
} else if (participant && !heartbeatRenewal) {
|
|
14386
|
+
const worker = participant;
|
|
14387
|
+
heartbeatRenewal = checkThread(lease, worker).then(async (held) => {
|
|
14388
|
+
if (held !== false || !worker.#heartbeat || worker.isLost()) return;
|
|
14389
|
+
worker.#markLost(new DurableExecutionFenceError(EXECUTION_UNVERIFIED_ERROR_ID, details));
|
|
14390
|
+
await ExecutionFence.releaseSharedClaim(mastra, runId, claim, "abandoned");
|
|
14391
|
+
}).catch(() => {}).finally(() => heartbeatRenewal = void 0);
|
|
14392
|
+
}
|
|
14393
|
+
}
|
|
14265
14394
|
return result;
|
|
14266
14395
|
}
|
|
14267
14396
|
};
|
|
14268
14397
|
const startedAt = Date.now();
|
|
14269
|
-
const details = {
|
|
14270
|
-
agentId: claim.agentId,
|
|
14271
|
-
runId,
|
|
14272
|
-
executionId: claim.executionId
|
|
14273
|
-
};
|
|
14274
14398
|
let deadline;
|
|
14275
14399
|
try {
|
|
14276
14400
|
await Promise.race([(async () => {
|
|
@@ -14288,7 +14412,7 @@ var ExecutionFence = class ExecutionFence {
|
|
|
14288
14412
|
} finally {
|
|
14289
14413
|
if (deadline) clearTimeout(deadline);
|
|
14290
14414
|
}
|
|
14291
|
-
const fence = new ExecutionFence({
|
|
14415
|
+
const fence = participant = new ExecutionFence({
|
|
14292
14416
|
...details,
|
|
14293
14417
|
backend,
|
|
14294
14418
|
generation: claim.generation,
|
|
@@ -49161,6 +49285,488 @@ function channelLines(ctx, textHidden, tools) {
|
|
|
49161
49285
|
if (tools && "add_reaction" in tools) lines.push(`If you want to acknowledge a message without ${textHidden ? "posting" : "speaking"}, use the \`add_reaction\` tool to react with an emoji instead of replying with text.`);
|
|
49162
49286
|
return lines;
|
|
49163
49287
|
}
|
|
49288
|
+
// src/channels/thread-link-processor.ts
|
|
49289
|
+
/**
|
|
49290
|
+
* Request-context marker for a run that opened a new channel thread. `AgentChannels` sets it when
|
|
49291
|
+
* it creates the thread; a host that decides "new" itself can call {@link markNewChannelThread}.
|
|
49292
|
+
*/
|
|
49293
|
+
const NEW_CHANNEL_THREAD_KEY = "__mastra_new_channel_thread";
|
|
49294
|
+
function markNewChannelThread(requestContext) {
|
|
49295
|
+
requestContext.set(NEW_CHANNEL_THREAD_KEY, true);
|
|
49296
|
+
}
|
|
49297
|
+
/** Text-part id of the link delta; never collides with a model block id. */
|
|
49298
|
+
const LINK_PART_ID = "mastra-channel-thread-link";
|
|
49299
|
+
const EMITTED_SUFFIX_KEY = "mastra__channelThreadLinkSuffix";
|
|
49300
|
+
/**
|
|
49301
|
+
* Posts a link to the thread in the host's web UI right after the first reply of a new channel
|
|
49302
|
+
* thread, so the link closes the reply rather than leading it. The channel driver ends a post at
|
|
49303
|
+
* `text-end`, so the link shows as its own short message after the reply.
|
|
49304
|
+
*
|
|
49305
|
+
* "End of the reply" is not `text-end`: a reply with citations is several text blocks, each with
|
|
49306
|
+
* its own `text-end`. The reply ends at the first `tool-call` (an opener before tools run) or at
|
|
49307
|
+
* `step-finish` (a reply with no tools), whichever comes first after some text. A processor
|
|
49308
|
+
* returns one part, so on that chunk this returns a `text-delta` carrying the link and stashes the
|
|
49309
|
+
* chunk under `REPROCESS_PART_KEY`, which the runner re-drives through the chain right after.
|
|
49310
|
+
*
|
|
49311
|
+
* The link is a channel display detail. Saved to memory it would show the model its own link on
|
|
49312
|
+
* later turns (inviting it to fabricate links) and render a self-link in the web transcript, so
|
|
49313
|
+
* `processOutputStep` drops the link's text part before the message is saved.
|
|
49314
|
+
*
|
|
49315
|
+
* No-op unless the run opened a new thread, the reply text is shown, and `link` returns a URL.
|
|
49316
|
+
*/
|
|
49317
|
+
var ChannelThreadLinkProcessor = class {
|
|
49318
|
+
id = "channel-thread-link";
|
|
49319
|
+
#options;
|
|
49320
|
+
/** Pass options, or a function picking them per run (e.g. by the run's platform). */
|
|
49321
|
+
constructor(options) {
|
|
49322
|
+
this.#options = typeof options === "function" ? options : () => options;
|
|
49323
|
+
}
|
|
49324
|
+
async processOutputStream({ part, state, requestContext }) {
|
|
49325
|
+
if (state.linked || !linksThisRun(requestContext)) return part;
|
|
49326
|
+
if (part.type === "text-delta") {
|
|
49327
|
+
if (part.payload.text.trim()) state.textStarted = true;
|
|
49328
|
+
return part;
|
|
49329
|
+
}
|
|
49330
|
+
if (part.type !== "tool-call" && part.type !== "step-finish" || !state.textStarted) return part;
|
|
49331
|
+
state.linked = true;
|
|
49332
|
+
const suffix = this.#suffix(requestContext);
|
|
49333
|
+
if (!suffix) return part;
|
|
49334
|
+
requestContext.set(EMITTED_SUFFIX_KEY, suffix);
|
|
49335
|
+
state[require_stream.REPROCESS_PART_KEY] = part;
|
|
49336
|
+
return {
|
|
49337
|
+
type: "text-delta",
|
|
49338
|
+
runId: part.runId,
|
|
49339
|
+
from: part.from,
|
|
49340
|
+
payload: {
|
|
49341
|
+
id: LINK_PART_ID,
|
|
49342
|
+
text: suffix
|
|
49343
|
+
}
|
|
49344
|
+
};
|
|
49345
|
+
}
|
|
49346
|
+
processOutputStep({ messageList, requestContext }) {
|
|
49347
|
+
const suffix = requestContext?.get(EMITTED_SUFFIX_KEY);
|
|
49348
|
+
if (!suffix) return messageList;
|
|
49349
|
+
for (const message of messageList.get.response.db()) {
|
|
49350
|
+
if (message.role !== "assistant") continue;
|
|
49351
|
+
const index = message.content.parts.findIndex((part) => part.type === "text" && part.text === suffix);
|
|
49352
|
+
if (index === -1) continue;
|
|
49353
|
+
message.content.parts.splice(index, 1);
|
|
49354
|
+
if (typeof message.content.content === "string" && message.content.content.endsWith(suffix)) message.content.content = message.content.content.slice(0, -suffix.length);
|
|
49355
|
+
return messageList;
|
|
49356
|
+
}
|
|
49357
|
+
return messageList;
|
|
49358
|
+
}
|
|
49359
|
+
#suffix(requestContext) {
|
|
49360
|
+
const options = this.#options(requestContext);
|
|
49361
|
+
if (!options) return void 0;
|
|
49362
|
+
const memory = require_stream.parseMemoryRequestContext(requestContext);
|
|
49363
|
+
const link = options.link({
|
|
49364
|
+
requestContext,
|
|
49365
|
+
threadId: memory?.thread?.id,
|
|
49366
|
+
resourceId: memory?.resourceId
|
|
49367
|
+
});
|
|
49368
|
+
return link && `\n\n[${options.label ?? "Open thread \u2197"}](${link})`;
|
|
49369
|
+
}
|
|
49370
|
+
};
|
|
49371
|
+
function linksThisRun(requestContext) {
|
|
49372
|
+
if (!requestContext?.get("__mastra_new_channel_thread")) return false;
|
|
49373
|
+
return requestContext.get(CHAT_CHANNEL_RENDER_CONTEXT_KEY)?.textDisplay !== "hidden";
|
|
49374
|
+
}
|
|
49375
|
+
// src/channels/reply-tool.ts
|
|
49376
|
+
const REPLY_TOOL_NAME = "reply_in_thread";
|
|
49377
|
+
/**
|
|
49378
|
+
* Which reply carries the session link: `claimed` while that reply is posting,
|
|
49379
|
+
* `posted` once it landed. Claimed before any await, so overlapping replies
|
|
49380
|
+
* can't both take it; a failed post hands it back to the next reply.
|
|
49381
|
+
*/
|
|
49382
|
+
const LINKED_KEY = "mastra__channelReplyLinked";
|
|
49383
|
+
const replyInput = zod.z.object({ text: zod.z.string().trim().min(1).max(12e3).describe("The message to post, in markdown.") }).strict();
|
|
49384
|
+
/** @internal */
|
|
49385
|
+
function createChannelReplyTool(requestContext, options) {
|
|
49386
|
+
const { resolveRender } = options;
|
|
49387
|
+
return { [REPLY_TOOL_NAME]: require_tool.createTool({
|
|
49388
|
+
id: REPLY_TOOL_NAME,
|
|
49389
|
+
description: "Post a message in this chat thread. Nothing you write outside this tool reaches the thread, so use it for anything the people there should see: a short note that you are starting a longer job, a question you need answered, and the outcome when you finish. Post when you have something new; do not repeat yourself or post that nothing changed. To stay quiet, do not call it.",
|
|
49390
|
+
inputSchema: replyInput,
|
|
49391
|
+
execute: async (input, context) => {
|
|
49392
|
+
const link = claimFirstReplyLink(requestContext, options.link);
|
|
49393
|
+
const suffix = link ? `\n\n[${options.link?.label ?? "Open thread \u2197"}](${link})` : "";
|
|
49394
|
+
const toolCallId = context?.agent?.toolCallId;
|
|
49395
|
+
const streamed = toolCallId ? replyStreams(requestContext).get(toolCallId) : void 0;
|
|
49396
|
+
if (toolCallId) replyStreams(requestContext).delete(toolCallId);
|
|
49397
|
+
try {
|
|
49398
|
+
if (!streamed || !await streamed.finish(input.text, suffix)) {
|
|
49399
|
+
const render = await resolveRender(requestContext);
|
|
49400
|
+
if (!render) throw new Error("This session is no longer linked to a chat thread.");
|
|
49401
|
+
await render.chatThread.post({ markdown: `${input.text}${suffix}` });
|
|
49402
|
+
}
|
|
49403
|
+
} catch (error) {
|
|
49404
|
+
if (link) requestContext.set(LINKED_KEY, void 0);
|
|
49405
|
+
throw error;
|
|
49406
|
+
}
|
|
49407
|
+
if (link) requestContext.set(LINKED_KEY, "posted");
|
|
49408
|
+
return { posted: true };
|
|
49409
|
+
}
|
|
49410
|
+
}) };
|
|
49411
|
+
}
|
|
49412
|
+
/**
|
|
49413
|
+
* The session link the first reply of a new session ends with, claimed for
|
|
49414
|
+
* this reply. With reply text hidden, the session-link processor's text delta
|
|
49415
|
+
* never reaches the thread, so the tool carries the link instead.
|
|
49416
|
+
*/
|
|
49417
|
+
function claimFirstReplyLink(requestContext, link) {
|
|
49418
|
+
if (!link || !requestContext.get("__mastra_new_channel_thread") || requestContext.get(LINKED_KEY)) return;
|
|
49419
|
+
const memory = require_stream.parseMemoryRequestContext(requestContext);
|
|
49420
|
+
const url = link.link({
|
|
49421
|
+
requestContext,
|
|
49422
|
+
threadId: memory?.thread?.id,
|
|
49423
|
+
resourceId: memory?.resourceId
|
|
49424
|
+
});
|
|
49425
|
+
if (url) requestContext.set(LINKED_KEY, "claimed");
|
|
49426
|
+
return url;
|
|
49427
|
+
}
|
|
49428
|
+
/** Live posts of `reply_in_thread` calls whose text is still streaming in, by tool call id. */
|
|
49429
|
+
const STREAMS_KEY = "mastra__channelReplyStreams";
|
|
49430
|
+
function replyStreams(requestContext) {
|
|
49431
|
+
let streams = requestContext.get(STREAMS_KEY);
|
|
49432
|
+
if (!streams) {
|
|
49433
|
+
streams = /* @__PURE__ */ new Map();
|
|
49434
|
+
requestContext.set(STREAMS_KEY, streams);
|
|
49435
|
+
}
|
|
49436
|
+
return streams;
|
|
49437
|
+
}
|
|
49438
|
+
/**
|
|
49439
|
+
* One streamed post, opened on the first visible text so an abandoned
|
|
49440
|
+
* call never leaves an empty message behind.
|
|
49441
|
+
*/
|
|
49442
|
+
function openReplyStream({ chatThread, logger }) {
|
|
49443
|
+
const queue = [];
|
|
49444
|
+
let sent = "";
|
|
49445
|
+
let closed = false;
|
|
49446
|
+
let wake;
|
|
49447
|
+
let done;
|
|
49448
|
+
async function* chunks() {
|
|
49449
|
+
while (true) {
|
|
49450
|
+
while (queue.length > 0) yield queue.shift();
|
|
49451
|
+
if (closed) return;
|
|
49452
|
+
await new Promise((resolve) => wake = resolve);
|
|
49453
|
+
}
|
|
49454
|
+
}
|
|
49455
|
+
const push = (text) => {
|
|
49456
|
+
if (!text) return;
|
|
49457
|
+
queue.push(text);
|
|
49458
|
+
done ??= chatThread.post(chunks()).then(() => true, (error) => {
|
|
49459
|
+
logger?.warn("[channels] streamed reply failed; posting it whole", { error });
|
|
49460
|
+
return false;
|
|
49461
|
+
});
|
|
49462
|
+
wake?.();
|
|
49463
|
+
};
|
|
49464
|
+
return {
|
|
49465
|
+
update(text) {
|
|
49466
|
+
const visible = text.trimStart();
|
|
49467
|
+
if (!visible.startsWith(sent)) return;
|
|
49468
|
+
push(visible.slice(sent.length));
|
|
49469
|
+
sent = visible;
|
|
49470
|
+
},
|
|
49471
|
+
async finish(text, suffix) {
|
|
49472
|
+
if (text.startsWith(sent)) push(text.slice(sent.length));
|
|
49473
|
+
if (!done) return false;
|
|
49474
|
+
push(suffix);
|
|
49475
|
+
closed = true;
|
|
49476
|
+
wake?.();
|
|
49477
|
+
return done;
|
|
49478
|
+
},
|
|
49479
|
+
async close() {
|
|
49480
|
+
closed = true;
|
|
49481
|
+
wake?.();
|
|
49482
|
+
return done ?? false;
|
|
49483
|
+
}
|
|
49484
|
+
};
|
|
49485
|
+
}
|
|
49486
|
+
/**
|
|
49487
|
+
* Streams a `reply_in_thread` call's `text` into the thread while the model is
|
|
49488
|
+
* still writing it, so a long reply appears as it is written instead of all at
|
|
49489
|
+
* once when the call completes. The tool finishes the post with the validated
|
|
49490
|
+
* text. Runs whose adapter doesn't stream, or that show reply text, are left
|
|
49491
|
+
* alone.
|
|
49492
|
+
*/
|
|
49493
|
+
var ChannelReplyStreamProcessor = class {
|
|
49494
|
+
id = "channel-reply-stream";
|
|
49495
|
+
#resolveRender;
|
|
49496
|
+
constructor(resolveRender) {
|
|
49497
|
+
this.#resolveRender = resolveRender;
|
|
49498
|
+
}
|
|
49499
|
+
async processOutputStream({ part, state, requestContext }) {
|
|
49500
|
+
if (!requestContext) return part;
|
|
49501
|
+
const args = state.args ??= {};
|
|
49502
|
+
if (part.type === "tool-call-input-streaming-start" && part.payload.toolName === "reply_in_thread") {
|
|
49503
|
+
const render = await this.#resolveRender(requestContext);
|
|
49504
|
+
if (render?.textDisplay !== "hidden" || !render.streaming?.enabled) return part;
|
|
49505
|
+
args[part.payload.toolCallId] = "";
|
|
49506
|
+
replyStreams(requestContext).set(part.payload.toolCallId, openReplyStream(render));
|
|
49507
|
+
} else if (part.type === "tool-call-delta" && part.payload.toolCallId in args) {
|
|
49508
|
+
const text = partialStringField(args[part.payload.toolCallId] += part.payload.argsTextDelta, "text");
|
|
49509
|
+
if (text !== void 0) replyStreams(requestContext).get(part.payload.toolCallId)?.update(text);
|
|
49510
|
+
} else if ((part.type === "tool-error" || part.type === "tool-result") && part.payload.toolCallId in args) {
|
|
49511
|
+
delete args[part.payload.toolCallId];
|
|
49512
|
+
await closeStream(requestContext, part.payload.toolCallId);
|
|
49513
|
+
} else if (RUN_END.has(part.type)) {
|
|
49514
|
+
for (const toolCallId of Object.keys(args)) await closeStream(requestContext, toolCallId);
|
|
49515
|
+
state.args = {};
|
|
49516
|
+
}
|
|
49517
|
+
return part;
|
|
49518
|
+
}
|
|
49519
|
+
};
|
|
49520
|
+
/** Chunks after which no `reply_in_thread` call of this run will still execute. */
|
|
49521
|
+
const RUN_END = /* @__PURE__ */ new Set([
|
|
49522
|
+
"finish",
|
|
49523
|
+
"abort",
|
|
49524
|
+
"error",
|
|
49525
|
+
"tripwire"
|
|
49526
|
+
]);
|
|
49527
|
+
/**
|
|
49528
|
+
* Ends a streamed post whose call will never reach `execute`, keeping the text
|
|
49529
|
+
* shown so far, so the platform isn't left with a message that never finishes.
|
|
49530
|
+
*/
|
|
49531
|
+
async function closeStream(requestContext, toolCallId) {
|
|
49532
|
+
const streams = replyStreams(requestContext);
|
|
49533
|
+
const stream = streams.get(toolCallId);
|
|
49534
|
+
if (!stream) return;
|
|
49535
|
+
streams.delete(toolCallId);
|
|
49536
|
+
await stream.close();
|
|
49537
|
+
}
|
|
49538
|
+
const ESCAPES = {
|
|
49539
|
+
"\"": "\"",
|
|
49540
|
+
"\\": "\\",
|
|
49541
|
+
"/": "/",
|
|
49542
|
+
b: "\b",
|
|
49543
|
+
f: "\f",
|
|
49544
|
+
n: "\n",
|
|
49545
|
+
r: "\r",
|
|
49546
|
+
t: " "
|
|
49547
|
+
};
|
|
49548
|
+
/** The decoded value of a top-level string field in JSON that may still be cut off mid-string. */
|
|
49549
|
+
function partialStringField(json, field) {
|
|
49550
|
+
const start = new RegExp(`"${field}"\\s*:\\s*"`).exec(json);
|
|
49551
|
+
if (!start) return void 0;
|
|
49552
|
+
let out = "";
|
|
49553
|
+
for (let i = start.index + start[0].length; i < json.length; i++) {
|
|
49554
|
+
const ch = json[i];
|
|
49555
|
+
if (ch === "\"") return out;
|
|
49556
|
+
if (ch !== "\\") {
|
|
49557
|
+
out += ch;
|
|
49558
|
+
continue;
|
|
49559
|
+
}
|
|
49560
|
+
const next = json[i + 1];
|
|
49561
|
+
if (next === void 0) return out;
|
|
49562
|
+
if (next === "u") {
|
|
49563
|
+
const hex = json.slice(i + 2, i + 6);
|
|
49564
|
+
if (hex.length < 4) return out;
|
|
49565
|
+
out += String.fromCharCode(parseInt(hex, 16));
|
|
49566
|
+
i += 5;
|
|
49567
|
+
} else {
|
|
49568
|
+
out += ESCAPES[next] ?? next;
|
|
49569
|
+
i += 1;
|
|
49570
|
+
}
|
|
49571
|
+
}
|
|
49572
|
+
return out;
|
|
49573
|
+
}
|
|
49574
|
+
// src/channels/reply-guidance-processor.ts
|
|
49575
|
+
const ID$1 = "channel-reply-guidance";
|
|
49576
|
+
/** Chat surfaces show what the agent writes as-is, so a bare id is a dead end for the reader. */
|
|
49577
|
+
const LINK_REFERENCES = "Write every pull request, issue, commit, ticket or other reference you mention in the thread as a markdown link to its page, with the id as plain link text, e.g. [#28467](https://github.com/<owner>/<repo>/pull/28467). Never leave one as a bare id or wrap it in code formatting. Build links from URLs your tools returned; don't guess a URL, and leave a reference unlinked only when you can't work out its URL.";
|
|
49578
|
+
/** Agents tend to write the way they report to other agents: names, ids and shorthand only they follow. */
|
|
49579
|
+
const WRITE_FOR_PEOPLE = [
|
|
49580
|
+
"Write for the people in the thread, not for another agent. A teammate who knows the product and programming, but has not read this code or this conversation, should follow your message on first read.",
|
|
49581
|
+
"Lead with the answer or the outcome and anything you need from them, in plain sentences. Keep it short: a few sentences answer most questions, and when there is more, offer it rather than writing it all out. Say what code does rather than naming the function, file, field, error class or tool that does it; name one only when they need it to find the code. Use the project\u2019s real terms, not invented analogies.",
|
|
49582
|
+
"Leave out tool names and run ids unless someone asks for them, and always leave out agent shorthand. When you pass on what another agent reported, say what it means for the people here in your own words; never paste its report."
|
|
49583
|
+
].join(" ");
|
|
49584
|
+
/**
|
|
49585
|
+
* Tells the agent how to speak in a chat channel: open a long job with one line that names it,
|
|
49586
|
+
* finish with the outcome, write for people, and link references. With `reply_in_thread` on the
|
|
49587
|
+
* run, that advice becomes advice on when to call it. A run outside the channel that can still
|
|
49588
|
+
* post there (a web prompt on a linked thread) gets a short note on when to. Runs with neither
|
|
49589
|
+
* get nothing.
|
|
49590
|
+
*/
|
|
49591
|
+
var ChannelReplyGuidanceProcessor = class {
|
|
49592
|
+
id = ID$1;
|
|
49593
|
+
#instructions;
|
|
49594
|
+
constructor(options = {}) {
|
|
49595
|
+
this.#instructions = options.instructions;
|
|
49596
|
+
}
|
|
49597
|
+
processInputStep({ messageList, requestContext, tools }) {
|
|
49598
|
+
const canReply = !!tools && "reply_in_thread" in tools;
|
|
49599
|
+
let content;
|
|
49600
|
+
if (!requestContext?.get("channel")) {
|
|
49601
|
+
if (!canReply) return void 0;
|
|
49602
|
+
content = [`Post to that thread with \`${REPLY_TOOL_NAME}\`. This request came from outside it, so don't post an opener or progress there; post the outcome when the people in the thread asked for this work or are waiting on it, or when you're asked to. Don't write a note about what you posted.`];
|
|
49603
|
+
} else if (canReply) content = [
|
|
49604
|
+
`Only messages you send with \`${REPLY_TOOL_NAME}\` reach this thread; your other text stays out of it. Don't write a note about what you posted. After a reply, either keep working or end your turn with an empty message; any text you write after posting is wasted.`,
|
|
49605
|
+
"When a request will take tools or more than a moment, post one short line first that says what you are about to do, then do the work and post the outcome when you finish \u2014 not a replay of the steps.",
|
|
49606
|
+
"Post again in between only when you need an answer or have news the people in the thread would want. When a message that doesn't mention you needs nothing from you, don't call it."
|
|
49607
|
+
];
|
|
49608
|
+
else content = ["When a request will take tools or more than a moment to answer, reply first with one short line that says what you are about to do \u2014 \"On it \u2014 <the task in a few words>.\" \u2014 then do the work; the opener posts as its own message before any progress is shown. Give direct answers and trivial replies without an opener.", "Finish with the outcome, not a replay of the steps."];
|
|
49609
|
+
const extra = typeof this.#instructions === "function" ? this.#instructions({ canReply }) : this.#instructions ?? [];
|
|
49610
|
+
messageList.addSystem({
|
|
49611
|
+
role: "system",
|
|
49612
|
+
content: [
|
|
49613
|
+
...content,
|
|
49614
|
+
...extra,
|
|
49615
|
+
LINK_REFERENCES,
|
|
49616
|
+
WRITE_FOR_PEOPLE
|
|
49617
|
+
].join("\n")
|
|
49618
|
+
}, ID$1);
|
|
49619
|
+
return { messageList };
|
|
49620
|
+
}
|
|
49621
|
+
};
|
|
49622
|
+
// src/channels/reply-reminder-processor.ts
|
|
49623
|
+
const ID = "channel-reply-reminder";
|
|
49624
|
+
/** How long a run may work without posting before it is nudged. */
|
|
49625
|
+
const REPLY_REMINDER_AFTER_MS = 3e5;
|
|
49626
|
+
/**
|
|
49627
|
+
* With reply text hidden, a long job can run silently for an hour while the
|
|
49628
|
+
* person who asked has no idea whether anything is happening. Once a run has
|
|
49629
|
+
* gone `afterMs` without calling `reply_in_thread`, this sends the agent one
|
|
49630
|
+
* signal suggesting a status update, then restarts the clock. Ignoring it is
|
|
49631
|
+
* how the agent stays quiet. A signal joins the end of the transcript, so the
|
|
49632
|
+
* cached prompt prefix is untouched. Only runs that have the reply tool are
|
|
49633
|
+
* touched.
|
|
49634
|
+
*/
|
|
49635
|
+
var ChannelReplyReminderProcessor = class {
|
|
49636
|
+
id = ID;
|
|
49637
|
+
#afterMs;
|
|
49638
|
+
#now;
|
|
49639
|
+
constructor({ afterMs = REPLY_REMINDER_AFTER_MS, now = Date.now } = {}) {
|
|
49640
|
+
this.#afterMs = afterMs;
|
|
49641
|
+
this.#now = now;
|
|
49642
|
+
}
|
|
49643
|
+
async processInputStep({ messageList, tools, state, sendSignal }) {
|
|
49644
|
+
if (!tools || !("reply_in_thread" in tools) || !sendSignal) return void 0;
|
|
49645
|
+
const reminder = state;
|
|
49646
|
+
const now = this.#now();
|
|
49647
|
+
reminder.quietSince ??= now;
|
|
49648
|
+
const seen = new Set(reminder.seenCalls ?? []);
|
|
49649
|
+
const calls = replyCalls(messageList.get.response.db());
|
|
49650
|
+
if (calls.some((id) => !seen.has(id))) reminder.quietSince = now;
|
|
49651
|
+
reminder.seenCalls = calls;
|
|
49652
|
+
const silentFor = now - reminder.quietSince;
|
|
49653
|
+
if (silentFor < this.#afterMs) return void 0;
|
|
49654
|
+
const minutes = Math.floor(silentFor / 6e4);
|
|
49655
|
+
await sendSignal({
|
|
49656
|
+
type: "reactive",
|
|
49657
|
+
contents: `It has been ${minutes} minute${minutes === 1 ? "" : "s"} since you last posted in this thread. If the people there would want to know where things stand, post a short status with \`${REPLY_TOOL_NAME}\`. Otherwise keep working.`
|
|
49658
|
+
});
|
|
49659
|
+
reminder.quietSince = now;
|
|
49660
|
+
}
|
|
49661
|
+
};
|
|
49662
|
+
/** Ids of the `reply_in_thread` calls this run has finished. */
|
|
49663
|
+
function replyCalls(messages) {
|
|
49664
|
+
const ids = [];
|
|
49665
|
+
for (const message of messages) {
|
|
49666
|
+
if (message.role !== "assistant") continue;
|
|
49667
|
+
for (const part of message.content.parts ?? []) {
|
|
49668
|
+
if (part.type !== "tool-invocation") continue;
|
|
49669
|
+
const { toolName, toolCallId, state } = part.toolInvocation;
|
|
49670
|
+
if (toolName === "reply_in_thread" && state === "result") ids.push(toolCallId);
|
|
49671
|
+
}
|
|
49672
|
+
}
|
|
49673
|
+
return ids;
|
|
49674
|
+
}
|
|
49675
|
+
// src/channels/reply-mode.ts
|
|
49676
|
+
/**
|
|
49677
|
+
* Slack renders the status inline next to the app name, and rejects a status
|
|
49678
|
+
* (sent as its loading message) of 51 characters or more. Other platforms get
|
|
49679
|
+
* the same cap; reply mode has only been tested on Slack.
|
|
49680
|
+
*/
|
|
49681
|
+
const MAX_STATUS_LENGTH = 50;
|
|
49682
|
+
/**
|
|
49683
|
+
* Turns a tool's `description` arg ("Listing the repo root") into a status
|
|
49684
|
+
* line that reads after the app name ("<App> is listing the repo root…").
|
|
49685
|
+
* Only the first line counts: issue/PR creators carry whole bodies there.
|
|
49686
|
+
*/
|
|
49687
|
+
function describeToolCall(args) {
|
|
49688
|
+
if (!args || typeof args !== "object") return void 0;
|
|
49689
|
+
const { description } = args;
|
|
49690
|
+
if (typeof description !== "string") return void 0;
|
|
49691
|
+
const line = description.split("\n").map((part) => part.replace(/\s+/g, " ").trim()).find(Boolean);
|
|
49692
|
+
if (!line) return void 0;
|
|
49693
|
+
const status = `is ${/^[A-Z][a-z]/.test(line) ? line.charAt(0).toLowerCase() + line.slice(1) : line}`;
|
|
49694
|
+
return status.length > MAX_STATUS_LENGTH ? `${status.slice(0, 49)}\u2026` : status;
|
|
49695
|
+
}
|
|
49696
|
+
/**
|
|
49697
|
+
* Progress as a status line rather than posts: "is thinking...", the current
|
|
49698
|
+
* tool's `description`, "is typing..." while a reply is written. With reply
|
|
49699
|
+
* text hidden, streamed text never reaches the thread, so it gets no status:
|
|
49700
|
+
* an "is typing..." set after the reply tool's post would sit on the thread
|
|
49701
|
+
* with nothing coming, and race the clear at the end of the run.
|
|
49702
|
+
*
|
|
49703
|
+
* @internal
|
|
49704
|
+
*/
|
|
49705
|
+
function channelReplyTypingStatus(textDisplay = "hidden") {
|
|
49706
|
+
return (chunk) => {
|
|
49707
|
+
switch (chunk.type) {
|
|
49708
|
+
case "reasoning-delta": return "is thinking...";
|
|
49709
|
+
case "text-delta": return textDisplay === "show" ? "is typing..." : void 0;
|
|
49710
|
+
case "tool-call-input-streaming-start": return chunk.payload.toolName === "reply_in_thread" ? "is typing..." : void 0;
|
|
49711
|
+
case "tool-call":
|
|
49712
|
+
if (chunk.payload.toolName === "reply_in_thread") return "is typing...";
|
|
49713
|
+
return describeToolCall(chunk.payload.args) ?? "is working...";
|
|
49714
|
+
default: return;
|
|
49715
|
+
}
|
|
49716
|
+
};
|
|
49717
|
+
}
|
|
49718
|
+
function threadLinkOptions(link) {
|
|
49719
|
+
if (!link) return void 0;
|
|
49720
|
+
return typeof link === "function" ? { link } : link;
|
|
49721
|
+
}
|
|
49722
|
+
/**
|
|
49723
|
+
* Installed by `AgentChannels` when an adapter sets `replyMode`. On runs whose chat
|
|
49724
|
+
* thread is on that adapter (including runs started elsewhere whose thread is linked
|
|
49725
|
+
* to it) it adds the `reply_in_thread` tool, the reply guidance prompt, and the
|
|
49726
|
+
* nudge after a quiet stretch. Other runs are untouched.
|
|
49727
|
+
*
|
|
49728
|
+
* @internal
|
|
49729
|
+
*/
|
|
49730
|
+
var ChannelReplyModeProcessor = class {
|
|
49731
|
+
id = "channel-reply-mode";
|
|
49732
|
+
#deps;
|
|
49733
|
+
constructor(deps) {
|
|
49734
|
+
this.#deps = deps;
|
|
49735
|
+
}
|
|
49736
|
+
async processInputStep(args) {
|
|
49737
|
+
const { requestContext, state } = args;
|
|
49738
|
+
const render = await this.#deps.resolveRender(requestContext, state);
|
|
49739
|
+
const adapter = render && this.#deps.adapter(render.platform);
|
|
49740
|
+
if (!requestContext || !render || !adapter?.replyMode) return void 0;
|
|
49741
|
+
const config = adapter.replyMode === "tool" ? {} : adapter.replyMode;
|
|
49742
|
+
if (render.textDisplay !== "hidden") {
|
|
49743
|
+
new ChannelReplyGuidanceProcessor({ instructions: config.instructions }).processInputStep(args);
|
|
49744
|
+
return { messageList: args.messageList };
|
|
49745
|
+
}
|
|
49746
|
+
const tools = {
|
|
49747
|
+
...args.tools,
|
|
49748
|
+
...createChannelReplyTool(requestContext, {
|
|
49749
|
+
resolveRender: async () => render,
|
|
49750
|
+
link: threadLinkOptions(adapter.threadLink)
|
|
49751
|
+
})
|
|
49752
|
+
};
|
|
49753
|
+
const withTools = {
|
|
49754
|
+
...args,
|
|
49755
|
+
tools
|
|
49756
|
+
};
|
|
49757
|
+
new ChannelReplyGuidanceProcessor({ instructions: config.instructions }).processInputStep(withTools);
|
|
49758
|
+
await new ChannelReplyReminderProcessor({
|
|
49759
|
+
afterMs: config.reminderAfterMs,
|
|
49760
|
+
now: this.#deps.now
|
|
49761
|
+
}).processInputStep(withTools);
|
|
49762
|
+
const activeTools = args.activeTools && !args.activeTools.includes("reply_in_thread") ? [...args.activeTools, REPLY_TOOL_NAME] : void 0;
|
|
49763
|
+
return {
|
|
49764
|
+
tools,
|
|
49765
|
+
messageList: args.messageList,
|
|
49766
|
+
...activeTools ? { activeTools } : {}
|
|
49767
|
+
};
|
|
49768
|
+
}
|
|
49769
|
+
};
|
|
49164
49770
|
// src/channels/state-adapter.ts
|
|
49165
49771
|
/**
|
|
49166
49772
|
* Chat SDK StateAdapter backed by Mastra storage.
|
|
@@ -49580,6 +50186,24 @@ function formatLegacyHistoryBlock(history, chatThread, platform) {
|
|
|
49580
50186
|
for (const msg of history.recent) lines.push(line(msg));
|
|
49581
50187
|
return lines.join("\n");
|
|
49582
50188
|
}
|
|
50189
|
+
// src/channels/thread-lookup.ts
|
|
50190
|
+
/**
|
|
50191
|
+
* The chat thread this run posts into, if any.
|
|
50192
|
+
*
|
|
50193
|
+
* A run started by a platform message has the render context on `requestContext`. A run
|
|
50194
|
+
* started elsewhere (web UI, schedule, signal wake) on a thread linked to a chat thread does
|
|
50195
|
+
* not, so rebuild it from the thread's persisted channel coordinates. The thread id comes from
|
|
50196
|
+
* the agent controller when there is one, else from the run's memory context. A forked
|
|
50197
|
+
* subagent's thread carries no channel metadata, so forks resolve nothing.
|
|
50198
|
+
*/
|
|
50199
|
+
async function resolveChannelRenderContext(requestContext, channels) {
|
|
50200
|
+
if (!requestContext) return void 0;
|
|
50201
|
+
const stashed = requestContext.get(CHAT_CHANNEL_RENDER_CONTEXT_KEY);
|
|
50202
|
+
if (stashed) return stashed;
|
|
50203
|
+
const threadId = requestContext.get("controller")?.threadId ?? require_stream.parseMemoryRequestContext(requestContext)?.thread?.id;
|
|
50204
|
+
if (!threadId) return void 0;
|
|
50205
|
+
return await channels?.()?.buildRenderContextForThread(threadId) ?? void 0;
|
|
50206
|
+
}
|
|
49583
50207
|
// src/channels/typing-status.ts
|
|
49584
50208
|
/**
|
|
49585
50209
|
* Built-in typing-status resolver. Used when `typingStatus: true` (the default)
|
|
@@ -49825,7 +50449,7 @@ var AgentChannels = class {
|
|
|
49825
50449
|
for (const [name, value] of Object.entries(config.adapters)) if (value && typeof value === "object" && "adapter" in value) {
|
|
49826
50450
|
const cfg = value;
|
|
49827
50451
|
adapters[name] = cfg.adapter;
|
|
49828
|
-
adapterConfigs[name] = cfg;
|
|
50452
|
+
adapterConfigs[name] = cfg.replyMode ? withReplyModeDefaults(cfg) : cfg;
|
|
49829
50453
|
} else {
|
|
49830
50454
|
adapters[name] = value;
|
|
49831
50455
|
adapterConfigs[name] = { adapter: value };
|
|
@@ -49846,6 +50470,7 @@ var AgentChannels = class {
|
|
|
49846
50470
|
this.channelConfig = config;
|
|
49847
50471
|
this.channelToolNames = new Set(Object.keys(this.getTools()));
|
|
49848
50472
|
if (this.generativeUIEnabled) this.channelToolNames.add(RENDER_CARD_TOOL_NAME);
|
|
50473
|
+
if (this.replyModeEnabled) this.channelToolNames.add(REPLY_TOOL_NAME);
|
|
49849
50474
|
}
|
|
49850
50475
|
/**
|
|
49851
50476
|
* Bind the owning agent used for webhook paths and stored-thread ownership.
|
|
@@ -50553,8 +51178,28 @@ var AgentChannels = class {
|
|
|
50553
51178
|
const processors = [];
|
|
50554
51179
|
if (this.channelConfig.threadContext?.addSystemMessage !== false && !has("chat-channel-context")) processors.push(new ChatChannelProcessor(this));
|
|
50555
51180
|
if (this.generativeUIEnabled && !has("chat-channel-generative-ui")) processors.push(new ChatChannelGenerativeUIProcessor(this));
|
|
51181
|
+
if (this.replyModeEnabled && !has(REPLY_MODE_PROCESSOR_ID)) processors.push(new ChannelReplyModeProcessor({
|
|
51182
|
+
resolveRender: (requestContext, state) => this.resolveRunRender(requestContext, state),
|
|
51183
|
+
adapter: (platform) => this.adapterConfigs[platform]
|
|
51184
|
+
}));
|
|
50556
51185
|
return processors;
|
|
50557
51186
|
}
|
|
51187
|
+
get replyModeEnabled() {
|
|
51188
|
+
return Object.values(this.adapterConfigs).some((cfg) => cfg.replyMode);
|
|
51189
|
+
}
|
|
51190
|
+
/**
|
|
51191
|
+
* The chat thread a run posts to: the one it came in on, else the one its
|
|
51192
|
+
* thread (the controller's, or memory's) is linked to. Cached on `state`
|
|
51193
|
+
* when given; `null` remembers a thread that isn't channel-backed.
|
|
51194
|
+
*/
|
|
51195
|
+
async resolveRunRender(requestContext, state) {
|
|
51196
|
+
const inbound = requestContext?.get(CHAT_CHANNEL_RENDER_CONTEXT_KEY);
|
|
51197
|
+
if (inbound) return inbound;
|
|
51198
|
+
if (state && "render" in state) return state.render ?? void 0;
|
|
51199
|
+
const render = await resolveChannelRenderContext(requestContext, () => this);
|
|
51200
|
+
if (state) state.render = render ?? null;
|
|
51201
|
+
return render;
|
|
51202
|
+
}
|
|
50558
51203
|
/** Whether the Slack adapter opted into `generativeUI` (the only platform it supports). */
|
|
50559
51204
|
get generativeUIEnabled() {
|
|
50560
51205
|
return this.adapterConfigs.slack?.generativeUI === true;
|
|
@@ -50575,8 +51220,15 @@ var AgentChannels = class {
|
|
|
50575
51220
|
*/
|
|
50576
51221
|
close() {}
|
|
50577
51222
|
getOutputProcessors(configuredProcessors = []) {
|
|
50578
|
-
|
|
50579
|
-
|
|
51223
|
+
const has = (id) => configuredProcessors.some((p) => !require_stream.isProcessorWorkflow(p) && p.id === id);
|
|
51224
|
+
const processors = [];
|
|
51225
|
+
if (Object.values(this.adapterConfigs).some((cfg) => cfg.threadLink) && !has(THREAD_LINK_PROCESSOR_ID)) processors.push(new ChannelThreadLinkProcessor((requestContext) => {
|
|
51226
|
+
const render = requestContext.get(CHAT_CHANNEL_RENDER_CONTEXT_KEY);
|
|
51227
|
+
return render && threadLinkOptions(this.adapterConfigs[render.platform]?.threadLink);
|
|
51228
|
+
}));
|
|
51229
|
+
if (!has("chat-channel-render")) processors.push(new ChatChannelOutputProcessor(this));
|
|
51230
|
+
if (this.replyModeEnabled && !has(REPLY_STREAM_PROCESSOR_ID)) processors.push(new ChannelReplyStreamProcessor((requestContext) => this.resolveRunRender(requestContext)));
|
|
51231
|
+
return processors;
|
|
50580
51232
|
}
|
|
50581
51233
|
/**
|
|
50582
51234
|
* Returns generic channel tools (add_reaction, remove_reaction) that resolve
|
|
@@ -50851,6 +51503,7 @@ var AgentChannels = class {
|
|
|
50851
51503
|
defaultThreadId,
|
|
50852
51504
|
requestContext
|
|
50853
51505
|
}) : void 0,
|
|
51506
|
+
onCreate: () => markNewChannelThread(requestContext),
|
|
50854
51507
|
mastra
|
|
50855
51508
|
});
|
|
50856
51509
|
const threadResourceId = mastraThread.resourceId;
|
|
@@ -51755,7 +52408,7 @@ var AgentChannels = class {
|
|
|
51755
52408
|
/**
|
|
51756
52409
|
* Resolves an existing Mastra thread for the given external IDs, or creates one.
|
|
51757
52410
|
*/
|
|
51758
|
-
async getOrCreateThread({ externalThreadId, channelId, platform, resourceId, threadId, mastra }) {
|
|
52411
|
+
async getOrCreateThread({ externalThreadId, channelId, platform, resourceId, threadId, onCreate, mastra }) {
|
|
51759
52412
|
const { thread: existingThread, memoryStore, metadata } = await this.findThreadMapping({
|
|
51760
52413
|
externalThreadId,
|
|
51761
52414
|
channelId,
|
|
@@ -51763,6 +52416,7 @@ var AgentChannels = class {
|
|
|
51763
52416
|
mastra
|
|
51764
52417
|
});
|
|
51765
52418
|
if (existingThread) return existingThread;
|
|
52419
|
+
onCreate?.();
|
|
51766
52420
|
const resolvedResourceId = typeof resourceId === "function" ? await resourceId() : resourceId;
|
|
51767
52421
|
const defaultThreadId = crypto.randomUUID();
|
|
51768
52422
|
let resolvedThreadId = threadId ? await threadId(resolvedResourceId, defaultThreadId) : defaultThreadId;
|
|
@@ -51964,6 +52618,21 @@ async function storedAttachmentBytes(fs, dir, root = true) {
|
|
|
51964
52618
|
}
|
|
51965
52619
|
return total;
|
|
51966
52620
|
}
|
|
52621
|
+
const REPLY_MODE_PROCESSOR_ID = "channel-reply-mode";
|
|
52622
|
+
const REPLY_STREAM_PROCESSOR_ID = "channel-reply-stream";
|
|
52623
|
+
const THREAD_LINK_PROCESSOR_ID = "channel-thread-link";
|
|
52624
|
+
/** Reply mode keeps reply text and tool calls out of the thread and shows progress in the status, unless set. */
|
|
52625
|
+
function withReplyModeDefaults(cfg) {
|
|
52626
|
+
const legacyCards = "cards" in cfg && cfg.cards !== void 0;
|
|
52627
|
+
const set = Object.fromEntries(Object.entries(cfg).filter(([, value]) => value !== void 0));
|
|
52628
|
+
const textDisplay = cfg.textDisplay ?? "hidden";
|
|
52629
|
+
return {
|
|
52630
|
+
textDisplay,
|
|
52631
|
+
...legacyCards ? {} : { toolDisplay: "hidden" },
|
|
52632
|
+
typingStatus: channelReplyTypingStatus(textDisplay),
|
|
52633
|
+
...set
|
|
52634
|
+
};
|
|
52635
|
+
}
|
|
51967
52636
|
// src/knowledge/instructions.ts
|
|
51968
52637
|
function readInstructions(canEdit) {
|
|
51969
52638
|
return `Use the Knowledge tools for durable, shared knowledge. Pinned knowledge pages may already be in your context if <pinned-knowledge> tags are present in the visible conversation history: answer from their bodies without searching for or reading them again${canEdit ? ", and edit one straight from its body and the version shown, unless its body was cut off: then read it first, since a write replaces the whole body" : ""}. Read a pinned page with knowledge_read only when the answer depends on what its notes say, or on its child pages; a note count alone is no reason to read it. For anything else, search with knowledge_search before answering from Knowledge, and read a page with knowledge_read before relying on it. To see how a scope or section is organized, list it with knowledge_list and read pages by the refs it gives. Read a page whole first; when its body is too long, it comes back as its headings with line numbers and the first lines under each: read the section you need, or match the terms you are looking for. A result's more says what it left out: follow it only when what you need is not already in what you have read, and answer as soon as you have it. Cite the page or note you used. When nothing is found, say so plainly instead of guessing. When notes disagree, show both with their dates.`;
|
|
@@ -71359,57 +72028,6 @@ function armRunDeadline(controller, deadline) {
|
|
|
71359
72028
|
timer.unref?.();
|
|
71360
72029
|
return timer;
|
|
71361
72030
|
}
|
|
71362
|
-
// src/agent/durable/constants.ts
|
|
71363
|
-
const DURABLE_STOP_WHEN_ERROR_ID = "DURABLE_AGENT_STOP_WHEN_FAILED";
|
|
71364
|
-
const REJECT_STREAM_ERROR = Symbol("mastra.durable.rejectStreamError");
|
|
71365
|
-
function markErrorForStreamRejection(error) {
|
|
71366
|
-
error[REJECT_STREAM_ERROR] = true;
|
|
71367
|
-
return error;
|
|
71368
|
-
}
|
|
71369
|
-
function shouldRejectStream(error) {
|
|
71370
|
-
return error[REJECT_STREAM_ERROR] === true;
|
|
71371
|
-
}
|
|
71372
|
-
/**
|
|
71373
|
-
* Default values for durable agent execution
|
|
71374
|
-
*/
|
|
71375
|
-
const DurableAgentDefaults = {
|
|
71376
|
-
/** Default maximum number of agentic loop iterations */
|
|
71377
|
-
MAX_STEPS: 5,
|
|
71378
|
-
/**
|
|
71379
|
-
* Default tool call concurrency.
|
|
71380
|
-
* Applied by `resolveDurableToolCallConcurrency` when a run doesn't
|
|
71381
|
-
* configure `toolCallConcurrency`. Approval / suspend-capable tool sets
|
|
71382
|
-
* always run sequentially (concurrency: 1) regardless of this value.
|
|
71383
|
-
*/
|
|
71384
|
-
TOOL_CALL_CONCURRENCY: 10
|
|
71385
|
-
};
|
|
71386
|
-
/**
|
|
71387
|
-
* Step IDs used in the durable agentic workflow
|
|
71388
|
-
*/
|
|
71389
|
-
const DurableStepIds = {
|
|
71390
|
-
/** LLM execution step */
|
|
71391
|
-
LLM_EXECUTION: "durable-llm-execution",
|
|
71392
|
-
/** Tool call step */
|
|
71393
|
-
TOOL_CALL: "durable-tool-call",
|
|
71394
|
-
/** LLM mapping step (combines results) */
|
|
71395
|
-
LLM_MAPPING: "durable-llm-mapping",
|
|
71396
|
-
/** Agentic execution workflow (one iteration) */
|
|
71397
|
-
AGENTIC_EXECUTION: "durable-agentic-execution",
|
|
71398
|
-
/** Full agentic loop workflow */
|
|
71399
|
-
AGENTIC_LOOP: "durable-agentic-loop",
|
|
71400
|
-
/** Scorer execution step */
|
|
71401
|
-
SCORER_EXECUTION: "durable-scorer-execution",
|
|
71402
|
-
/** isTaskComplete evaluation step */
|
|
71403
|
-
IS_TASK_COMPLETE: "durable-is-task-complete"
|
|
71404
|
-
};
|
|
71405
|
-
/** The loop's last step, which ends the run's spans when it succeeds. */
|
|
71406
|
-
const MAP_FINAL_OUTPUT_STEP_ID = "map-final-output";
|
|
71407
|
-
const RECOVER_ALREADY_IN_PROGRESS_ERROR_ID = "DURABLE_AGENT_RECOVER_ALREADY_IN_PROGRESS";
|
|
71408
|
-
const RECOVER_SNAPSHOT_NOT_FOUND_ERROR_ID = "DURABLE_AGENT_RECOVER_SNAPSHOT_NOT_FOUND";
|
|
71409
|
-
const RECOVER_CHECKPOINT_NOT_AVAILABLE_ERROR_ID = "DURABLE_AGENT_RECOVER_CHECKPOINT_NOT_AVAILABLE";
|
|
71410
|
-
const RECOVER_RUN_SUSPENDED_ERROR_ID = "DURABLE_AGENT_RECOVER_RUN_SUSPENDED";
|
|
71411
|
-
const RECOVER_RUN_NOT_ACTIVE_ERROR_ID = "DURABLE_AGENT_RECOVER_RUN_NOT_ACTIVE";
|
|
71412
|
-
const RECOVER_SHUTDOWN_ERROR_ID = "DURABLE_AGENT_RECOVER_SHUTDOWN";
|
|
71413
72031
|
// src/agent/durable/durable-stream-until-idle.ts
|
|
71414
72032
|
/**
|
|
71415
72033
|
* Run `DurableAgent.streamUntilIdle` (or `DurableAgent.stream({ untilIdle })`).
|
|
@@ -73705,7 +74323,7 @@ function runTranscriptRefs(params) {
|
|
|
73705
74323
|
async function runMemory(params, run) {
|
|
73706
74324
|
const entry = run.runId ? getRunRegistryEntry(run.runId, params.mastra) : void 0;
|
|
73707
74325
|
if (entry?.memory || !params.mastra || !run.agentId) return entry?.memory;
|
|
73708
|
-
return params.mastra.getAgentById(run.agentId).getMemory({ requestContext: restoreRequestContext(run.requestContextEntries, params.requestContext, getLiveRunRequestContext(entry)) });
|
|
74326
|
+
return params.mastra.getAgentById(run.agentId).getMemory({ requestContext: restoreRequestContext(run.requestContextEntries, params.requestContext, getLiveRunRequestContext(entry, run.runId, params.requestContext)) });
|
|
73709
74327
|
}
|
|
73710
74328
|
/** The most recent transcript in a snapshot: workflow state, else the last step output carrying one. */
|
|
73711
74329
|
function latestMessageListState(snapshot) {
|
|
@@ -73781,7 +74399,7 @@ async function runDurableFinishSideEffects({ runId, initData, messageListState,
|
|
|
73781
74399
|
error
|
|
73782
74400
|
});
|
|
73783
74401
|
}
|
|
73784
|
-
const effectiveRequestContext = mergeRequestContextForFinalization(initData.requestContextEntries, requestContext, getLiveRunRequestContext(registryEntry));
|
|
74402
|
+
const effectiveRequestContext = mergeRequestContextForFinalization(initData.requestContextEntries, requestContext, getLiveRunRequestContext(registryEntry, runId, requestContext));
|
|
73785
74403
|
if (!effectiveRequestContext.has("MastraMemory") && durableState?.threadId) effectiveRequestContext.set("MastraMemory", {
|
|
73786
74404
|
thread: { id: durableState.threadId },
|
|
73787
74405
|
resourceId: durableState.resourceId,
|
|
@@ -74078,9 +74696,9 @@ function deadlineMessageListState(entry, fallback) {
|
|
|
74078
74696
|
* durable run. The run never reaches its finish step, so this runs over what the deadline saves
|
|
74079
74697
|
* (see `deadlineMessageListState`), as the default loop's deadline pass does.
|
|
74080
74698
|
*/
|
|
74081
|
-
async function runDurableDeadlineOutputPass({ runId, initData, messageListState, cutOffText, entry, mastra, tracingContext, logger }) {
|
|
74699
|
+
async function runDurableDeadlineOutputPass({ runId, initData, messageListState, cutOffText, entry, executionId, mastra, tracingContext, logger }) {
|
|
74082
74700
|
const durableState = initData.state;
|
|
74083
|
-
const requestContext = mergeRequestContextForFinalization(initData.requestContextEntries, void 0, getLiveRunRequestContext(entry));
|
|
74701
|
+
const requestContext = mergeRequestContextForFinalization(initData.requestContextEntries, void 0, getLiveRunRequestContext(entry, runId, void 0, executionId));
|
|
74084
74702
|
if (!requestContext.has("MastraMemory") && durableState?.threadId) requestContext.set("MastraMemory", {
|
|
74085
74703
|
thread: { id: durableState.threadId },
|
|
74086
74704
|
resourceId: durableState.resourceId,
|
|
@@ -76098,7 +76716,7 @@ function createDurableLLMExecutionStep(_options) {
|
|
|
76098
76716
|
const typedInput = inputData;
|
|
76099
76717
|
const { agentId, messageId, options: execOptions } = typedInput;
|
|
76100
76718
|
const runId = typedInput.runId;
|
|
76101
|
-
const requestContext = getLiveRunRequestContext(getRunRegistryEntry(runId, mastra)) ?? params.requestContext;
|
|
76719
|
+
const requestContext = getLiveRunRequestContext(getRunRegistryEntry(runId, mastra), runId, params.requestContext) ?? params.requestContext;
|
|
76102
76720
|
const logger = mastra?.getLogger?.();
|
|
76103
76721
|
if (pubsub) await emitIterationStartEvent(pubsub, runId, inputData.stepIndex ?? 0);
|
|
76104
76722
|
const { messageList, tools, model: resolvedModel, modelList: resolvedModelList, inputProcessors: resolvedInputProcessors, llmRequestInputProcessors: resolvedLlmRequestInputProcessors, outputProcessors: resolvedOutputProcessors } = await resolveRuntimeDependencies({
|
|
@@ -78995,6 +79613,15 @@ async function flushMessagesBeforeSuspension({ saveQueueManager, messageList, me
|
|
|
78995
79613
|
return false;
|
|
78996
79614
|
}
|
|
78997
79615
|
}
|
|
79616
|
+
/**
|
|
79617
|
+
* Context for output processors on a tool result. A live context is reused only for the execution that
|
|
79618
|
+
* owns it. A context rebuilt from the run snapshot is returned as before; whether a rebuilt entry can
|
|
79619
|
+
* outlive a resume by another caller is tracked in COR-1660.
|
|
79620
|
+
*/
|
|
79621
|
+
function toolResultRequestContext(registryEntry, runId, stepRequestContext) {
|
|
79622
|
+
if (registryEntry?.requestContextRebuilt) return registryEntry.requestContext;
|
|
79623
|
+
return getLiveRunRequestContext(registryEntry, runId, stepRequestContext) ?? stepRequestContext;
|
|
79624
|
+
}
|
|
78998
79625
|
var DurableOutputProcessorError = class extends Error {
|
|
78999
79626
|
constructor(error) {
|
|
79000
79627
|
super(error instanceof Error ? error.message : String(error), { cause: error });
|
|
@@ -79016,7 +79643,7 @@ var DurableChunkPublishError = class extends Error {
|
|
|
79016
79643
|
* Thin glue over the shared per-chunk pipeline core; mirrors the regular
|
|
79017
79644
|
* agent's `processAndEnqueueChunk` in llm-mapping-step.ts.
|
|
79018
79645
|
*/
|
|
79019
|
-
async function processChunkThroughOutputProcessors(chunk, registryEntry, pubsub, runId, agentName, logger, messageList, observabilityContext, collectDataPart, onEmit) {
|
|
79646
|
+
async function processChunkThroughOutputProcessors(chunk, registryEntry, stepRequestContext, pubsub, runId, agentName, logger, messageList, observabilityContext, collectDataPart, onEmit) {
|
|
79020
79647
|
const runner = registryEntry?.outputProcessors?.length && registryEntry.processorStates ? new require_stream.ProcessorRunner({
|
|
79021
79648
|
inputProcessors: [],
|
|
79022
79649
|
outputProcessors: registryEntry.outputProcessors,
|
|
@@ -79029,7 +79656,7 @@ async function processChunkThroughOutputProcessors(chunk, registryEntry, pubsub,
|
|
|
79029
79656
|
runner,
|
|
79030
79657
|
processorStates: registryEntry?.processorStates,
|
|
79031
79658
|
observabilityContext,
|
|
79032
|
-
requestContext: registryEntry
|
|
79659
|
+
requestContext: toolResultRequestContext(registryEntry, runId, stepRequestContext),
|
|
79033
79660
|
messageList,
|
|
79034
79661
|
streamWriter: pubsub ? { custom: async (data, writerOptions) => {
|
|
79035
79662
|
if (data.type.startsWith("data-") && !data.transient) collectDataPart?.({
|
|
@@ -79380,7 +80007,7 @@ function createDurableToolCallStep() {
|
|
|
79380
80007
|
}).add(invocation, "memory");
|
|
79381
80008
|
}
|
|
79382
80009
|
if (saveQueueManager && messagesToFlush && memory && state?.threadId && state.resourceId && !state.memoryConfig?.readOnly) {
|
|
79383
|
-
const authorizationRequestContext = restoreRequestContext(initData.requestContextEntries, requestContext, registryEntry
|
|
80010
|
+
const authorizationRequestContext = restoreRequestContext(initData.requestContextEntries, requestContext, getLiveRunRequestContext(registryEntry, runId, requestContext));
|
|
79384
80011
|
const authorizeMemory = (permission) => authorizeDurableMemory(getDurableMemoryAuthorizationChecks(registryEntry), {
|
|
79385
80012
|
mastra,
|
|
79386
80013
|
user: authorizationRequestContext.get("user"),
|
|
@@ -79424,10 +80051,10 @@ function createDurableToolCallStep() {
|
|
|
79424
80051
|
};
|
|
79425
80052
|
const registryRequireToolApproval = registryEntry?.requireToolApproval;
|
|
79426
80053
|
const effectiveRequireToolApproval = registryRequireToolApproval !== void 0 ? registryRequireToolApproval : agentOptions.requireToolApproval;
|
|
79427
|
-
const approvalRequestContext = restoreRequestContext(initData.requestContextEntries, requestContext, registryEntry
|
|
80054
|
+
const approvalRequestContext = restoreRequestContext(initData.requestContextEntries, requestContext, getLiveRunRequestContext(registryEntry, runId, requestContext));
|
|
79428
80055
|
const requiresApproval = await toolRequiresApproval(tool, effectiveRequireToolApproval, args, {
|
|
79429
80056
|
toolName,
|
|
79430
|
-
requestContext: Object.fromEntries([...approvalRequestContext.entries()].filter(([key]) => !INTERNAL_APPROVAL_KEYS.has(key))),
|
|
80057
|
+
requestContext: Object.fromEntries([...approvalRequestContext.entries()].filter(([key]) => key !== "__mastra_durableContextSegment" && !INTERNAL_APPROVAL_KEYS.has(key))),
|
|
79431
80058
|
workspace
|
|
79432
80059
|
});
|
|
79433
80060
|
const addToolMetadata = (opts) => {
|
|
@@ -79607,7 +80234,7 @@ function createDurableToolCallStep() {
|
|
|
79607
80234
|
toolTransform: tool?.transform,
|
|
79608
80235
|
tools: toolsForTransform,
|
|
79609
80236
|
logger
|
|
79610
|
-
}), registryEntry, pubsub, runId, initData.agentId, logger, messageList, processorObservabilityContext, collectProcessorDataPart);
|
|
80237
|
+
}), registryEntry, requestContext, pubsub, runId, initData.agentId, logger, messageList, processorObservabilityContext, collectProcessorDataPart);
|
|
79611
80238
|
} catch (emitError) {
|
|
79612
80239
|
if (emitError instanceof DurableOutputProcessorError) throw emitError;
|
|
79613
80240
|
logger?.warn?.(`[DurableAgent] Failed to emit tool-result chunk for ${toolName}: ${emitError}`);
|
|
@@ -79709,7 +80336,7 @@ function createDurableToolCallStep() {
|
|
|
79709
80336
|
policy: toolPayloadTransform,
|
|
79710
80337
|
tools: toolsForTransform,
|
|
79711
80338
|
logger
|
|
79712
|
-
}), registryEntry, pubsub, runId, initData.agentId, logger, messageList, processorObservabilityContext, collectProcessorDataPart);
|
|
80339
|
+
}), registryEntry, requestContext, pubsub, runId, initData.agentId, logger, messageList, processorObservabilityContext, collectProcessorDataPart);
|
|
79713
80340
|
} catch (emitError) {
|
|
79714
80341
|
if (emitError instanceof DurableOutputProcessorError) throw emitError;
|
|
79715
80342
|
logger?.warn?.(`[DurableAgent] Failed to emit tool-output-denied chunk for ${toolName}: ${emitError}`);
|
|
@@ -80149,7 +80776,7 @@ function createDurableToolCallStep() {
|
|
|
80149
80776
|
toolCallId: params.toolCallId,
|
|
80150
80777
|
toolName: params.toolName,
|
|
80151
80778
|
status: params.status === "failed" ? "failed" : "completed",
|
|
80152
|
-
requestContext: restoreRequestContext(initData.requestContextEntries, requestContext, registryEntry
|
|
80779
|
+
requestContext: restoreRequestContext(initData.requestContextEntries, requestContext, getLiveRunRequestContext(registryEntry, runId, requestContext))
|
|
80153
80780
|
});
|
|
80154
80781
|
} catch (error) {
|
|
80155
80782
|
resolveReconciliation({ error });
|
|
@@ -80448,7 +81075,7 @@ function createDurableToolCallStep() {
|
|
|
80448
81075
|
result,
|
|
80449
81076
|
modelOutput: require_stream.readModelOutput(providerMetadata),
|
|
80450
81077
|
...processorObservabilityContext ?? {},
|
|
80451
|
-
requestContext: registryEntry
|
|
81078
|
+
requestContext: toolResultRequestContext(registryEntry, runId, requestContext),
|
|
80452
81079
|
retryCount: 0,
|
|
80453
81080
|
writer: pubsub ? { custom: async (data, writerOptions) => {
|
|
80454
81081
|
if (data.type.startsWith("data-") && !data.transient) collectProcessorDataPart({
|
|
@@ -80553,7 +81180,7 @@ function createDurableToolCallStep() {
|
|
|
80553
81180
|
logger
|
|
80554
81181
|
});
|
|
80555
81182
|
transformMetadata = resultChunk.metadata;
|
|
80556
|
-
await processChunkThroughOutputProcessors(resultChunk, registryEntry, pubsub, runId, initData.agentId, logger, messageList, processorObservabilityContext, collectProcessorDataPart, (chunk) => {
|
|
81183
|
+
await processChunkThroughOutputProcessors(resultChunk, registryEntry, requestContext, pubsub, runId, initData.agentId, logger, messageList, processorObservabilityContext, collectProcessorDataPart, (chunk) => {
|
|
80557
81184
|
if (chunk.type === "tool-result" && chunk.payload.toolCallId === toolCallId) resultEmitted = true;
|
|
80558
81185
|
});
|
|
80559
81186
|
} catch (emitError) {
|
|
@@ -80625,7 +81252,7 @@ function createDurableToolCallStep() {
|
|
|
80625
81252
|
logger
|
|
80626
81253
|
});
|
|
80627
81254
|
errorTransformMetadata = errorChunk.metadata;
|
|
80628
|
-
await processChunkThroughOutputProcessors(errorChunk, registryEntry, pubsub, runId, initData.agentId, logger, messageList, processorObservabilityContext, collectProcessorDataPart);
|
|
81255
|
+
await processChunkThroughOutputProcessors(errorChunk, registryEntry, requestContext, pubsub, runId, initData.agentId, logger, messageList, processorObservabilityContext, collectProcessorDataPart);
|
|
80629
81256
|
} catch (emitError) {
|
|
80630
81257
|
ownership?.throwIfLost();
|
|
80631
81258
|
if (emitError instanceof DurableOutputProcessorError) throw emitError;
|
|
@@ -81213,7 +81840,7 @@ function createDurableIsTaskCompleteStep(defaultMaxSteps = DurableAgentDefaults.
|
|
|
81213
81840
|
const restored = await restoreCompletionPolicy({
|
|
81214
81841
|
agent,
|
|
81215
81842
|
persisted: initData.options.isTaskComplete,
|
|
81216
|
-
requestContext: restoreRequestContext(initData.requestContextEntries,
|
|
81843
|
+
requestContext: restoreRequestContext(initData.requestContextEntries, params.requestContext, getLiveRunRequestContext(registryEntry, state.runId, params.requestContext)),
|
|
81217
81844
|
runId: state.runId,
|
|
81218
81845
|
logger: mastra?.getLogger?.()
|
|
81219
81846
|
});
|
|
@@ -81249,7 +81876,7 @@ function createDurableIsTaskCompleteStep(defaultMaxSteps = DurableAgentDefaults.
|
|
|
81249
81876
|
agentName: initData.agentName,
|
|
81250
81877
|
threadId: initData.state?.threadId,
|
|
81251
81878
|
resourceId: initData.state?.resourceId,
|
|
81252
|
-
customContext: restoreCustomContext(initData.requestContextEntries, registryEntry
|
|
81879
|
+
customContext: restoreCustomContext(initData.requestContextEntries, getLiveRunRequestContext(registryEntry, state.runId, params.requestContext) ?? params.requestContext),
|
|
81253
81880
|
generateId: () => mastra?.generateId?.(),
|
|
81254
81881
|
emitChunk: (chunk) => {
|
|
81255
81882
|
if (!pubsub) return;
|
|
@@ -81297,7 +81924,7 @@ function createDurableGoalStep() {
|
|
|
81297
81924
|
const registryEntry = getRunRegistryEntry(state.runId, mastra);
|
|
81298
81925
|
let goalConfig = registryEntry?.goal;
|
|
81299
81926
|
if (!goalConfig && initData.agentId) goalConfig = mastra?.getAgentById?.(initData.agentId)?.__getGoalConfig?.();
|
|
81300
|
-
const liveRunContext = getLiveRunRequestContext(registryEntry);
|
|
81927
|
+
const liveRunContext = getLiveRunRequestContext(registryEntry, state.runId, params.requestContext);
|
|
81301
81928
|
const currentRequestContext = liveRunContext ?? params.requestContext;
|
|
81302
81929
|
const requestContext = restoreRequestContext(initData.requestContextEntries, params.requestContext, liveRunContext);
|
|
81303
81930
|
const customContext = restoreCustomContext(initData.requestContextEntries, currentRequestContext);
|
|
@@ -83433,7 +84060,7 @@ async function prepareForDurableExecution(options) {
|
|
|
83433
84060
|
});
|
|
83434
84061
|
let tripwireData;
|
|
83435
84062
|
if (inputProcessors.length > 0) try {
|
|
83436
|
-
const { ProcessorRunner } = await Promise.resolve().then(() => require("./stream-
|
|
84063
|
+
const { ProcessorRunner } = await Promise.resolve().then(() => require("./stream-BIDts1fZ.cjs")).then((n) => n.runner_exports);
|
|
83437
84064
|
await new ProcessorRunner({
|
|
83438
84065
|
inputProcessors,
|
|
83439
84066
|
outputProcessors,
|
|
@@ -93536,6 +94163,7 @@ var Agent = class Agent extends require_base.MastraBase {
|
|
|
93536
94163
|
initData: runInput,
|
|
93537
94164
|
...deadlineMessageListState(runInputEntry, runInput.messageListState),
|
|
93538
94165
|
entry: runInputEntry,
|
|
94166
|
+
executionId: fence.executionId,
|
|
93539
94167
|
mastra: this.#mastra,
|
|
93540
94168
|
tracingContext: deadlineSpan ? { currentSpan: deadlineSpan } : void 0,
|
|
93541
94169
|
logger: this.logger
|
|
@@ -94069,7 +94697,7 @@ var Agent = class Agent extends require_base.MastraBase {
|
|
|
94069
94697
|
const threadId = workflowInput.state?.threadId ?? memoryInfo?.threadId;
|
|
94070
94698
|
const resourceId = workflowInput.state?.resourceId ?? memoryInfo?.resourceId;
|
|
94071
94699
|
if (sharedExecution && pubsub && entry?.requestContext && executionFence && threadId) {
|
|
94072
|
-
await agentThreadStreamRuntime.claimDurableThreadLease(pubsub, runId, threadId, resourceId, executionFence.generation, executionFence.executionId);
|
|
94700
|
+
await agentThreadStreamRuntime.claimDurableThreadLease(pubsub, runId, threadId, resourceId, executionFence.generation, executionFence.executionId, true);
|
|
94073
94701
|
try {
|
|
94074
94702
|
await executionFence.verify();
|
|
94075
94703
|
} catch (error) {
|
|
@@ -94343,7 +94971,13 @@ var Agent = class Agent extends require_base.MastraBase {
|
|
|
94343
94971
|
messageListFollowsStream: () => !this.executionEngine.executesStepsLocally
|
|
94344
94972
|
});
|
|
94345
94973
|
streamCleanup = createdStreamCleanup;
|
|
94346
|
-
const
|
|
94974
|
+
const threadRegistration = agentThreadStreamRuntime.registerRun(this, output, options, this.getPubSub(), {
|
|
94975
|
+
continuation: methodType === "stream" && !closeOnSuspend ? "across-suspension" : void 0,
|
|
94976
|
+
generation: executionFence.generation,
|
|
94977
|
+
ownershipLost: () => executionFence.isLost(),
|
|
94978
|
+
stepOwner: () => getRunRegistryEntry(runId, this.#mastra)
|
|
94979
|
+
});
|
|
94980
|
+
const workflowExecution = executionFence.run(() => Promise.all([ready, threadRegistration]).then(async () => {
|
|
94347
94981
|
if (await this.redeliverDeadlineError(registryEntry, executionFence)) return;
|
|
94348
94982
|
await emitChunkEvent(fencePubSub(this.#executionStreamBus.forRun(this.__usesSharedRunLog()).pubsub, executionFence), runId, {
|
|
94349
94983
|
type: "start",
|
|
@@ -94384,12 +95018,7 @@ var Agent = class Agent extends require_base.MastraBase {
|
|
|
94384
95018
|
}).catch((error) => this.settleExecution(runId, executionFence, { error: this.executionEngine.workflowExecutionError(error, "Workflow execution failed") })));
|
|
94385
95019
|
const trackedEntry = getRunRegistryEntry(runId, this.#mastra);
|
|
94386
95020
|
if (trackedEntry) trackedEntry.workflowExecution = workflowExecution;
|
|
94387
|
-
await
|
|
94388
|
-
continuation: methodType === "stream" && !closeOnSuspend ? "across-suspension" : void 0,
|
|
94389
|
-
generation: executionFence.generation,
|
|
94390
|
-
ownershipLost: () => executionFence.isLost(),
|
|
94391
|
-
stepOwner: () => getRunRegistryEntry(runId, this.#mastra)
|
|
94392
|
-
});
|
|
95021
|
+
await threadRegistration;
|
|
94393
95022
|
const cleanup = () => {
|
|
94394
95023
|
if (methodType === "generate" || runCleanup.done || output.status !== "running") return performCleanup();
|
|
94395
95024
|
Promise.race([workflowExecution, executionFence.whenSettled]).then(() => this.#executionStreamBus.forRun(this.__usesSharedRunLog()).pubsub.flush()).then(() => waitForEventDelivery()).catch(() => {}).finally(performCleanup);
|
|
@@ -104246,7 +104875,7 @@ var AgentThreadStreamRuntime = class {
|
|
|
104246
104875
|
return state.leaseOwners.get(runId) ?? threadLeaseOwner(runId, state.threadRunsById.get(runId)?.generation);
|
|
104247
104876
|
}
|
|
104248
104877
|
/** @internal Qualify a shared thread lease before dispatching this execution. */
|
|
104249
|
-
async claimDurableThreadLease(pubsub, runId, threadId, resourceId, generation, executionId) {
|
|
104878
|
+
async claimDurableThreadLease(pubsub, runId, threadId, resourceId, generation, executionId, workerFenced = false) {
|
|
104250
104879
|
const key = this.#threadKey(resourceId, threadId);
|
|
104251
104880
|
const owner = threadLeaseOwner(runId, generation, executionId);
|
|
104252
104881
|
let lease = await this.#acquireThreadLease(pubsub, key, runId, owner);
|
|
@@ -104264,7 +104893,7 @@ var AgentThreadStreamRuntime = class {
|
|
|
104264
104893
|
if (!lease.acquired) throw new AgentThreadLeaseConflictError(runId, lease.owner ?? "another owner");
|
|
104265
104894
|
if (this.#getState(pubsub).leaseRenewalTimers.has(runId)) {
|
|
104266
104895
|
this.#stopLeaseRenewal(pubsub, runId);
|
|
104267
|
-
this.#startLeaseRenewal(pubsub, key, runId, owner);
|
|
104896
|
+
this.#startLeaseRenewal(pubsub, key, runId, owner, workerFenced);
|
|
104268
104897
|
}
|
|
104269
104898
|
}
|
|
104270
104899
|
/** @internal Renew only the captured execution's thread lease; never acquire or transfer it. */
|
|
@@ -104280,6 +104909,11 @@ var AgentThreadStreamRuntime = class {
|
|
|
104280
104909
|
const { acquired } = await this.#getLeaseProvider(pubsub).acquireLease(this.#threadKey(resourceId, threadId), threadLeaseOwner(runId, generation, executionId), AGENT_THREAD_LEASE_TTL_MS);
|
|
104281
104910
|
return acquired;
|
|
104282
104911
|
}
|
|
104912
|
+
/** @internal Missing ownership is not evidence that another run took the thread. */
|
|
104913
|
+
async isDurableThreadLeaseHeldByAnotherRun(pubsub, runId, threadId, resourceId) {
|
|
104914
|
+
const owner = await this.#getLeaseProvider(pubsub).getLeaseOwner(this.#threadKey(resourceId, threadId));
|
|
104915
|
+
return owner !== void 0 && threadLeaseRunId(owner) !== runId;
|
|
104916
|
+
}
|
|
104283
104917
|
/** @internal Whether `error` from the thread lease backend means it is refusing every client, not just this one. */
|
|
104284
104918
|
isThreadLeaseBackendUnavailableToAll(pubsub, error) {
|
|
104285
104919
|
return this.#getLeaseProvider(pubsub).isUnavailableToAll?.(error) === true;
|
|
@@ -104493,7 +105127,7 @@ var AgentThreadStreamRuntime = class {
|
|
|
104493
105127
|
* that point, so once it passes a successor may own the thread and the
|
|
104494
105128
|
* run is aborted, even if the backend never answers.
|
|
104495
105129
|
*/
|
|
104496
|
-
#startLeaseRenewal(pubsub, key, runId, owner = this.#threadLeaseOwner(pubsub, runId)) {
|
|
105130
|
+
#startLeaseRenewal(pubsub, key, runId, owner = this.#threadLeaseOwner(pubsub, runId), workerFenced = false, confirmedSentAt = Date.now()) {
|
|
104497
105131
|
const state = this.#getState(pubsub);
|
|
104498
105132
|
if (state.leaseRenewalTimers.has(runId)) {
|
|
104499
105133
|
if (state.leaseOwners.get(runId) === owner) return;
|
|
@@ -104501,10 +105135,12 @@ var AgentThreadStreamRuntime = class {
|
|
|
104501
105135
|
}
|
|
104502
105136
|
const leaseProvider = this.#getLeaseProvider(pubsub);
|
|
104503
105137
|
const timer = setInterval(() => {
|
|
105138
|
+
if (workerFenced && state.pendingLeaseRenewals.has(runId)) return;
|
|
104504
105139
|
const sentAt = Date.now();
|
|
104505
105140
|
state.pendingLeaseRenewals.set(runId, (state.pendingLeaseRenewals.get(runId) ?? 0) + 1);
|
|
104506
105141
|
leaseProvider.renewLease(key, owner, AGENT_THREAD_LEASE_TTL_MS).then((renewed) => {
|
|
104507
105142
|
if (!renewed) {
|
|
105143
|
+
if (workerFenced) return;
|
|
104508
105144
|
if (state.leaseRenewalTimers.get(runId) !== timer) return;
|
|
104509
105145
|
const confirmed = state.leaseDeadlines.get(runId)?.confirmedSentAt;
|
|
104510
105146
|
(confirmed === void 0 || Date.now() >= confirmed + AGENT_THREAD_LEASE_TTL_MS ? this.#retakeLease(pubsub, key, runId, timer) : Promise.resolve(false)).then((kept) => {
|
|
@@ -104513,7 +105149,7 @@ var AgentThreadStreamRuntime = class {
|
|
|
104513
105149
|
this.#abortLeaseLostRun(state, runId);
|
|
104514
105150
|
});
|
|
104515
105151
|
} else {
|
|
104516
|
-
if (state.leaseRenewalTimers.get(runId) === timer) this.#armLeaseDeadline(pubsub, key, runId, sentAt);
|
|
105152
|
+
if (!workerFenced && state.leaseRenewalTimers.get(runId) === timer) this.#armLeaseDeadline(pubsub, key, runId, sentAt);
|
|
104517
105153
|
if (state.sweptLeasedRunIds.has(runId)) state.sweptLeasedRunIds.set(runId, Date.now());
|
|
104518
105154
|
}
|
|
104519
105155
|
}).catch(() => {}).finally(() => {
|
|
@@ -104525,7 +105161,8 @@ var AgentThreadStreamRuntime = class {
|
|
|
104525
105161
|
if (typeof timer === "object" && timer && typeof timer.unref === "function") timer.unref();
|
|
104526
105162
|
state.leaseRenewalTimers.set(runId, timer);
|
|
104527
105163
|
state.leaseOwners.set(runId, owner);
|
|
104528
|
-
|
|
105164
|
+
if (workerFenced) return;
|
|
105165
|
+
this.#armLeaseDeadline(pubsub, key, runId, confirmedSentAt);
|
|
104529
105166
|
if (!this.#resolveLeaseProvider(pubsub).isFallback) {
|
|
104530
105167
|
const fence = this.#leaseFence(pubsub, key, runId, timer, owner);
|
|
104531
105168
|
state.leaseFences.set(runId, fence);
|
|
@@ -107245,7 +107882,14 @@ var AgentThreadStreamRuntime = class {
|
|
|
107245
107882
|
async #publishRunSuspended(pubsub, key, record) {
|
|
107246
107883
|
record.lifecycle = "suspended";
|
|
107247
107884
|
record.suspendedAt = Date.now();
|
|
107248
|
-
|
|
107885
|
+
const state = this.#getState(pubsub);
|
|
107886
|
+
const owner = state.leaseOwners.get(record.runId);
|
|
107887
|
+
if (owner && state.threadRunsById.get(record.runId) === record && !state.leaseDeadlines.has(record.runId)) {
|
|
107888
|
+
const resolvedPubSub = this.#getPubSub(pubsub);
|
|
107889
|
+
this.#stopLeaseRenewal(resolvedPubSub, record.runId);
|
|
107890
|
+
this.#startLeaseRenewal(resolvedPubSub, key, record.runId, owner, false, record.suspendedAt - AGENT_THREAD_LEASE_TTL_MS);
|
|
107891
|
+
}
|
|
107892
|
+
if (state.shutdownStreams.has(record.streamId)) return;
|
|
107249
107893
|
await this.#publishAndWait(pubsub, key, {
|
|
107250
107894
|
type: "run-suspended",
|
|
107251
107895
|
runId: record.runId,
|
|
@@ -109717,8 +110361,26 @@ function getRunRegistryEntry(runId, mastra) {
|
|
|
109717
110361
|
}
|
|
109718
110362
|
return require_observability.unwrapMastraTracingProxy(entry.mastra) === require_observability.unwrapMastraTracingProxy(mastra) ? entry : void 0;
|
|
109719
110363
|
}
|
|
109720
|
-
|
|
109721
|
-
|
|
110364
|
+
/**
|
|
110365
|
+
* Request-context key that identifies a run segment on engines whose steps carry no Core execution
|
|
110366
|
+
* claim (Inngest). The engine stores the same value on the registry entry it seeds for the segment.
|
|
110367
|
+
*/
|
|
110368
|
+
const DURABLE_CONTEXT_SEGMENT_KEY = "__mastra_durableContextSegment";
|
|
110369
|
+
/**
|
|
110370
|
+
* The registry's live request context, when it belongs to the execution running this step. Once
|
|
110371
|
+
* another process claims the run (for example an approval from another host), the context cached
|
|
110372
|
+
* here still belongs to the previous caller and must not be reused for the new execution.
|
|
110373
|
+
*/
|
|
110374
|
+
function getLiveRunRequestContext(entry, runId, stepContext, executionId) {
|
|
110375
|
+
const live = entry?.requestContext;
|
|
110376
|
+
if (!live || entry.requestContextRebuilt) return void 0;
|
|
110377
|
+
const expectedExecutionId = executionId ?? (runId ? getExecutionClaim(stepContext, runId)?.executionId : void 0);
|
|
110378
|
+
if (!expectedExecutionId) {
|
|
110379
|
+
const stepSegment = stepContext?.get(DURABLE_CONTEXT_SEGMENT_KEY);
|
|
110380
|
+
if (stepSegment === void 0) return live;
|
|
110381
|
+
return stepSegment === entry.requestContextSegment ? live : void 0;
|
|
110382
|
+
}
|
|
110383
|
+
return runId && getExecutionClaim(live, runId)?.executionId === expectedExecutionId ? live : void 0;
|
|
109722
110384
|
}
|
|
109723
110385
|
/**
|
|
109724
110386
|
* Publish an entry for `runId`, owned by `mastra`, unless the slot holds
|
|
@@ -110156,6 +110818,12 @@ Object.defineProperty(exports, "ChannelSessionRejectedError", {
|
|
|
110156
110818
|
return ChannelSessionRejectedError;
|
|
110157
110819
|
}
|
|
110158
110820
|
});
|
|
110821
|
+
Object.defineProperty(exports, "ChannelThreadLinkProcessor", {
|
|
110822
|
+
enumerable: true,
|
|
110823
|
+
get: function() {
|
|
110824
|
+
return ChannelThreadLinkProcessor;
|
|
110825
|
+
}
|
|
110826
|
+
});
|
|
110159
110827
|
Object.defineProperty(exports, "ChannelsStorage", {
|
|
110160
110828
|
enumerable: true,
|
|
110161
110829
|
get: function() {
|
|
@@ -110210,6 +110878,12 @@ Object.defineProperty(exports, "DEFAULT_TOOL_DECLINE_REASON", {
|
|
|
110210
110878
|
return DEFAULT_TOOL_DECLINE_REASON;
|
|
110211
110879
|
}
|
|
110212
110880
|
});
|
|
110881
|
+
Object.defineProperty(exports, "DURABLE_CONTEXT_SEGMENT_KEY", {
|
|
110882
|
+
enumerable: true,
|
|
110883
|
+
get: function() {
|
|
110884
|
+
return DURABLE_CONTEXT_SEGMENT_KEY;
|
|
110885
|
+
}
|
|
110886
|
+
});
|
|
110213
110887
|
Object.defineProperty(exports, "DURABLE_STOP_WHEN_ERROR_ID", {
|
|
110214
110888
|
enumerable: true,
|
|
110215
110889
|
get: function() {
|
|
@@ -110720,6 +111394,12 @@ Object.defineProperty(exports, "ModerationProcessor", {
|
|
|
110720
111394
|
return ModerationProcessor;
|
|
110721
111395
|
}
|
|
110722
111396
|
});
|
|
111397
|
+
Object.defineProperty(exports, "NEW_CHANNEL_THREAD_KEY", {
|
|
111398
|
+
enumerable: true,
|
|
111399
|
+
get: function() {
|
|
111400
|
+
return NEW_CHANNEL_THREAD_KEY;
|
|
111401
|
+
}
|
|
111402
|
+
});
|
|
110723
111403
|
Object.defineProperty(exports, "NotificationsStorage", {
|
|
110724
111404
|
enumerable: true,
|
|
110725
111405
|
get: function() {
|
|
@@ -110822,6 +111502,12 @@ Object.defineProperty(exports, "PromptInjectionDetector", {
|
|
|
110822
111502
|
return PromptInjectionDetector;
|
|
110823
111503
|
}
|
|
110824
111504
|
});
|
|
111505
|
+
Object.defineProperty(exports, "REPLY_TOOL_NAME", {
|
|
111506
|
+
enumerable: true,
|
|
111507
|
+
get: function() {
|
|
111508
|
+
return REPLY_TOOL_NAME;
|
|
111509
|
+
}
|
|
111510
|
+
});
|
|
110825
111511
|
Object.defineProperty(exports, "RESPONSE_CACHE_CONTEXT_KEY", {
|
|
110826
111512
|
enumerable: true,
|
|
110827
111513
|
get: function() {
|
|
@@ -112478,6 +113164,12 @@ Object.defineProperty(exports, "mapVariable", {
|
|
|
112478
113164
|
return mapVariable;
|
|
112479
113165
|
}
|
|
112480
113166
|
});
|
|
113167
|
+
Object.defineProperty(exports, "markNewChannelThread", {
|
|
113168
|
+
enumerable: true,
|
|
113169
|
+
get: function() {
|
|
113170
|
+
return markNewChannelThread;
|
|
113171
|
+
}
|
|
113172
|
+
});
|
|
112481
113173
|
Object.defineProperty(exports, "matchesRunFence", {
|
|
112482
113174
|
enumerable: true,
|
|
112483
113175
|
get: function() {
|
|
@@ -112772,6 +113464,12 @@ Object.defineProperty(exports, "resolveAgentById", {
|
|
|
112772
113464
|
return resolveAgentById;
|
|
112773
113465
|
}
|
|
112774
113466
|
});
|
|
113467
|
+
Object.defineProperty(exports, "resolveChannelRenderContext", {
|
|
113468
|
+
enumerable: true,
|
|
113469
|
+
get: function() {
|
|
113470
|
+
return resolveChannelRenderContext;
|
|
113471
|
+
}
|
|
113472
|
+
});
|
|
112775
113473
|
Object.defineProperty(exports, "resolveChannelToolsSettings", {
|
|
112776
113474
|
enumerable: true,
|
|
112777
113475
|
get: function() {
|