@mastra/core 1.87.0-alpha.2 → 1.87.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (446) hide show
  1. package/dist/_types/@ai-sdk_openai@4.0.106/dist/index.d.ts +2034 -0
  2. package/dist/_types/@ai-sdk_openai@4.0.106/package.json +1 -0
  3. package/dist/a2a/index.cjs +1 -1
  4. package/dist/a2a/index.js +1 -1
  5. package/dist/agent/durable/index.cjs +1 -1
  6. package/dist/agent/durable/index.js +1 -1
  7. package/dist/agent/durable/run-message-refs.d.ts +3 -2
  8. package/dist/agent/index.cjs +4 -4
  9. package/dist/agent/index.js +4 -4
  10. package/dist/agent/message-list/adapters/AIV5Adapter.d.ts +15 -1
  11. package/dist/agent/message-list/index.cjs +2 -2
  12. package/dist/agent/message-list/index.js +2 -2
  13. package/dist/agent/message-list/state/types.d.ts +5 -1
  14. package/dist/agent/message-list/types.d.ts +1 -1
  15. package/dist/agent/message-list/utils/provider-compat.d.ts +9 -1
  16. package/dist/agent-builder/ee/index.cjs +1 -1
  17. package/dist/agent-builder/ee/index.js +1 -1
  18. package/dist/agent-controller/agent-controller.d.ts +6 -0
  19. package/dist/agent-controller/index.cjs +2 -2
  20. package/dist/agent-controller/index.js +2 -2
  21. package/dist/agent-controller/worker-run-binding.d.ts +15 -0
  22. package/dist/{agent-controller-Dc58ARqw.js → agent-controller-CDwoELRq.js} +50 -8
  23. package/dist/{agent-controller-v64JbuDa.cjs → agent-controller-DEB1G03O.cjs} +50 -8
  24. package/dist/background-tasks/index.cjs +1 -1
  25. package/dist/background-tasks/index.js +1 -1
  26. package/dist/{background-tasks-DgiQNKh7.cjs → background-tasks-B40g_Guf.cjs} +1 -1
  27. package/dist/{background-tasks-E-Jjxks4.js → background-tasks-CBp2178j.js} +1 -1
  28. package/dist/browser/index.cjs +2 -2
  29. package/dist/browser/index.js +2 -2
  30. package/dist/{builder-Dh175HnQ.js → builder-DTEXPju5.js} +2 -2
  31. package/dist/{builder-Dfp6Ckjr.cjs → builder-tuHJooMG.cjs} +2 -2
  32. package/dist/capabilities/302ai.json +191 -191
  33. package/dist/capabilities/abliteratedllm.json +39 -39
  34. package/dist/capabilities/abliteration-ai.json +10 -10
  35. package/dist/capabilities/above.json +20 -20
  36. package/dist/capabilities/adaption.json +15 -15
  37. package/dist/capabilities/adzuki.json +20 -20
  38. package/dist/capabilities/agentrouter.json +9 -9
  39. package/dist/capabilities/agnes.json +3 -3
  40. package/dist/capabilities/ai-router.json +6 -6
  41. package/dist/capabilities/aiand.json +25 -25
  42. package/dist/capabilities/aigrow.json +15 -15
  43. package/dist/capabilities/aimlapi.json +140 -143
  44. package/dist/capabilities/aixy.json +22 -22
  45. package/dist/capabilities/aki-io.json +12 -12
  46. package/dist/capabilities/alibaba-cn.json +98 -98
  47. package/dist/capabilities/alibaba-coding-plan-cn.json +3 -3
  48. package/dist/capabilities/alibaba-coding-plan.json +3 -3
  49. package/dist/capabilities/alibaba-token-plan-cn.json +48 -48
  50. package/dist/capabilities/alibaba-token-plan.json +51 -51
  51. package/dist/capabilities/alibaba.json +99 -65
  52. package/dist/capabilities/ambient.json +23 -16
  53. package/dist/capabilities/amd.json +7 -7
  54. package/dist/capabilities/anthropic.json +43 -43
  55. package/dist/capabilities/anyapi.json +13 -13
  56. package/dist/capabilities/apiko.json +2 -2
  57. package/dist/capabilities/arcee.json +9 -9
  58. package/dist/capabilities/augure.json +7 -7
  59. package/dist/capabilities/auriko.json +20 -20
  60. package/dist/capabilities/bailing.json +5 -5
  61. package/dist/capabilities/baseten.json +32 -32
  62. package/dist/capabilities/bee.json +3 -3
  63. package/dist/capabilities/berget.json +8 -8
  64. package/dist/capabilities/bothub.json +17 -17
  65. package/dist/capabilities/boundless.json +39 -39
  66. package/dist/capabilities/bumo.json +38 -38
  67. package/dist/capabilities/byteplus.json +32 -32
  68. package/dist/capabilities/cerebras.json +4 -4
  69. package/dist/capabilities/cheapaimodel.json +10 -10
  70. package/dist/capabilities/cheapest-token.json +30 -30
  71. package/dist/capabilities/chutes.json +10 -10
  72. package/dist/capabilities/clarifai.json +2 -2
  73. package/dist/capabilities/cline-pass.json +36 -36
  74. package/dist/capabilities/cloudcode.json +9 -9
  75. package/dist/capabilities/cloudflare-workers-ai.json +19 -19
  76. package/dist/capabilities/commandcode.json +145 -145
  77. package/dist/capabilities/concentrate.json +278 -295
  78. package/dist/capabilities/cortecs.json +109 -109
  79. package/dist/capabilities/crossmodel.json +200 -200
  80. package/dist/capabilities/crusoe.json +10 -10
  81. package/dist/capabilities/daoxe.json +6 -6
  82. package/dist/capabilities/databricks.json +124 -124
  83. package/dist/capabilities/deepinfra.json +98 -89
  84. package/dist/capabilities/deepseek.json +4 -4
  85. package/dist/capabilities/digitalocean.json +113 -113
  86. package/dist/capabilities/dothoosh.json +27 -27
  87. package/dist/capabilities/doubleword.json +23 -23
  88. package/dist/capabilities/edenai.json +283 -292
  89. package/dist/capabilities/empiriolabs.json +159 -159
  90. package/dist/capabilities/engy.json +23 -23
  91. package/dist/capabilities/entrim.json +2 -2
  92. package/dist/capabilities/evroc.json +16 -16
  93. package/dist/capabilities/ezkielyna.json +10 -10
  94. package/dist/capabilities/fastrouter.json +82 -82
  95. package/dist/capabilities/fireworks-ai.json +126 -65
  96. package/dist/capabilities/freemodel.json +15 -15
  97. package/dist/capabilities/friendli.json +8 -8
  98. package/dist/capabilities/frogbot.json +95 -95
  99. package/dist/capabilities/gisoo.json +15 -15
  100. package/dist/capabilities/gmicloud.json +13 -13
  101. package/dist/capabilities/google.json +54 -54
  102. package/dist/capabilities/graphn.json +16 -16
  103. package/dist/capabilities/greenpt.json +35 -35
  104. package/dist/capabilities/groq.json +9 -9
  105. package/dist/capabilities/helicone.json +84 -84
  106. package/dist/capabilities/hopper.json +2 -2
  107. package/dist/capabilities/hostinger-router.json +11 -11
  108. package/dist/capabilities/hpc-ai.json +7 -7
  109. package/dist/capabilities/huawei-maas.json +15 -15
  110. package/dist/capabilities/hubris.json +32 -32
  111. package/dist/capabilities/huggingface.json +118 -78
  112. package/dist/capabilities/hyper.json +20 -28
  113. package/dist/capabilities/impossibl.json +123 -123
  114. package/dist/capabilities/inception.json +3 -3
  115. package/dist/capabilities/inceptron.json +2 -2
  116. package/dist/capabilities/inco.json +5 -5
  117. package/dist/capabilities/infer.json +16 -16
  118. package/dist/capabilities/inferall.json +14 -14
  119. package/dist/capabilities/inference-coop.json +8 -8
  120. package/dist/capabilities/inferenceapis.json +15 -15
  121. package/dist/capabilities/inferris.json +2 -2
  122. package/dist/capabilities/infersia.json +9 -9
  123. package/dist/capabilities/inferx.json +2 -2
  124. package/dist/capabilities/infomaniak.json +4 -4
  125. package/dist/capabilities/io-net.json +2 -2
  126. package/dist/capabilities/isoquant.json +4 -4
  127. package/dist/capabilities/iteracompute.json +54 -54
  128. package/dist/capabilities/jalapeno.json +11 -11
  129. package/dist/capabilities/jiekou.json +63 -63
  130. package/dist/capabilities/jzstoken.json +50 -50
  131. package/dist/capabilities/keln.json +18 -18
  132. package/dist/capabilities/kenari.json +118 -126
  133. package/dist/capabilities/kilo.json +632 -638
  134. package/dist/capabilities/kimi-code-plan-cn.json +5 -5
  135. package/dist/capabilities/kimi-code-plan-global.json +5 -5
  136. package/dist/capabilities/klavo.json +20 -20
  137. package/dist/capabilities/korouter.json +34 -34
  138. package/dist/capabilities/kunavo.json +10 -10
  139. package/dist/capabilities/liquid.json +13 -13
  140. package/dist/capabilities/lithosai.json +2 -2
  141. package/dist/capabilities/llmgateway-providers.json +973 -917
  142. package/dist/capabilities/llmgateway.json +333 -333
  143. package/dist/capabilities/llmtr.json +29 -29
  144. package/dist/capabilities/logits.json +2 -2
  145. package/dist/capabilities/lowrouter.json +54 -54
  146. package/dist/capabilities/lyceum.json +14 -14
  147. package/dist/capabilities/melious.json +15 -15
  148. package/dist/capabilities/merge-gateway.json +244 -244
  149. package/dist/capabilities/meta.json +8 -8
  150. package/dist/capabilities/minimax-cn-coding-plan.json +5 -5
  151. package/dist/capabilities/minimax-cn.json +5 -5
  152. package/dist/capabilities/minimax-coding-plan.json +5 -5
  153. package/dist/capabilities/minimax.json +5 -5
  154. package/dist/capabilities/mistral.json +17 -17
  155. package/dist/capabilities/mixlayer.json +2 -2
  156. package/dist/capabilities/modal.json +10 -10
  157. package/dist/capabilities/model-oracle-ai.json +25 -25
  158. package/dist/capabilities/modelis.json +24 -24
  159. package/dist/capabilities/modelscope.json +2 -2
  160. package/dist/capabilities/modular.json +9 -9
  161. package/dist/capabilities/moneo.json +14 -14
  162. package/dist/capabilities/moonshotai-cn.json +7 -7
  163. package/dist/capabilities/moonshotai.json +7 -7
  164. package/dist/capabilities/morph.json +13 -13
  165. package/dist/capabilities/munito-eu.json +8 -8
  166. package/dist/capabilities/munito.json +8 -8
  167. package/dist/capabilities/nan.json +25 -25
  168. package/dist/capabilities/nano-gpt.json +573 -554
  169. package/dist/capabilities/nearai.json +89 -89
  170. package/dist/capabilities/nebius.json +30 -30
  171. package/dist/capabilities/neon.json +128 -128
  172. package/dist/capabilities/neuralwatt.json +41 -41
  173. package/dist/capabilities/novita-ai.json +171 -171
  174. package/dist/capabilities/nvidia.json +40 -40
  175. package/dist/capabilities/oathbreaker.json +2 -2
  176. package/dist/capabilities/obscurify.json +21 -21
  177. package/dist/capabilities/oci.json +10 -10
  178. package/dist/capabilities/ofox.json +375 -375
  179. package/dist/capabilities/ollama-cloud.json +51 -51
  180. package/dist/capabilities/openai.json +53 -53
  181. package/dist/capabilities/opencode-go.json +86 -86
  182. package/dist/capabilities/openreason.json +5 -5
  183. package/dist/capabilities/openrouter.json +557 -546
  184. package/dist/capabilities/opper.json +29 -29
  185. package/dist/capabilities/orcarouter.json +254 -254
  186. package/dist/capabilities/outerlabs.json +29 -29
  187. package/dist/capabilities/ovhcloud.json +23 -23
  188. package/dist/capabilities/pendra.json +4 -4
  189. package/dist/capabilities/perplexity-agent.json +55 -55
  190. package/dist/capabilities/perplexity.json +2 -2
  191. package/dist/capabilities/phala.json +34 -34
  192. package/dist/capabilities/pioneer.json +30 -30
  193. package/dist/capabilities/poe.json +126 -126
  194. package/dist/capabilities/powerspring.json +11 -11
  195. package/dist/capabilities/primalabs.json +10 -10
  196. package/dist/capabilities/prime.json +120 -119
  197. package/dist/capabilities/privatemode-ai.json +10 -10
  198. package/dist/capabilities/proxystacks.json +7 -7
  199. package/dist/capabilities/qiniu-ai.json +14 -14
  200. package/dist/capabilities/refuseless.json +9 -9
  201. package/dist/capabilities/regolo-ai.json +5 -5
  202. package/dist/capabilities/requesty.json +167 -190
  203. package/dist/capabilities/ruapi.json +17 -17
  204. package/dist/capabilities/runcrate.json +9 -9
  205. package/dist/capabilities/runinfra.json +10 -10
  206. package/dist/capabilities/sakana.json +6 -6
  207. package/dist/capabilities/sambanova.json +8 -8
  208. package/dist/capabilities/sandbase.json +21 -21
  209. package/dist/capabilities/sarvam.json +5 -5
  210. package/dist/capabilities/scaleway.json +18 -18
  211. package/dist/capabilities/scnet-token-plan.json +10 -10
  212. package/dist/capabilities/scx-ai.json +32 -32
  213. package/dist/capabilities/sensenova.json +14 -14
  214. package/dist/capabilities/siliconflow-cn.json +44 -44
  215. package/dist/capabilities/siliconflow.json +53 -53
  216. package/dist/capabilities/snowflake-cortex.json +22 -22
  217. package/dist/capabilities/sokkan.json +9 -9
  218. package/dist/capabilities/sparrowcodes.json +19 -19
  219. package/dist/capabilities/standardcompute.json +90 -90
  220. package/dist/capabilities/steadyrouter.json +42 -42
  221. package/dist/capabilities/stepfun-ai-step-plan.json +2 -2
  222. package/dist/capabilities/stepfun-ai.json +2 -2
  223. package/dist/capabilities/stepfun-step-plan.json +2 -2
  224. package/dist/capabilities/stepfun.json +2 -2
  225. package/dist/capabilities/stepping-stone.json +19 -19
  226. package/dist/capabilities/synthetic.json +10 -10
  227. package/dist/capabilities/synthorai.json +24 -24
  228. package/dist/capabilities/teamorouter.json +23 -23
  229. package/dist/capabilities/teapot-router.json +12 -12
  230. package/dist/capabilities/tencent-token-plan-intl.json +126 -0
  231. package/dist/capabilities/tencent-token-plan.json +39 -39
  232. package/dist/capabilities/tencent-tokenhub.json +56 -41
  233. package/dist/capabilities/tensorx.json +50 -50
  234. package/dist/capabilities/tenstorrent.json +6 -6
  235. package/dist/capabilities/the-grid-ai.json +33 -33
  236. package/dist/capabilities/thinkingmachines.json +77 -77
  237. package/dist/capabilities/tinfoil.json +12 -12
  238. package/dist/capabilities/toapis.json +2 -2
  239. package/dist/capabilities/togetherai.json +41 -41
  240. package/dist/capabilities/tokengo.json +22 -22
  241. package/dist/capabilities/tokenify.json +3 -3
  242. package/dist/capabilities/trustedrouter.json +7 -7
  243. package/dist/capabilities/trustedtokens.json +17 -17
  244. package/dist/capabilities/umans-ai-coding-plan.json +11 -11
  245. package/dist/capabilities/umans-ai.json +8 -8
  246. package/dist/capabilities/uncensuredai.json +5 -5
  247. package/dist/capabilities/unrestricted.json +4 -4
  248. package/dist/capabilities/uplinkswitch.json +21 -21
  249. package/dist/capabilities/upstage.json +6 -6
  250. package/dist/capabilities/vancine.json +24 -24
  251. package/dist/capabilities/vercel.json +582 -582
  252. package/dist/capabilities/vivgrid.json +86 -86
  253. package/dist/capabilities/volcengine-coding-plan.json +29 -29
  254. package/dist/capabilities/volcengine.json +23 -23
  255. package/dist/capabilities/vultr.json +27 -27
  256. package/dist/capabilities/wafer.ai.json +18 -18
  257. package/dist/capabilities/wallaby.json +2 -2
  258. package/dist/capabilities/wally.json +11 -11
  259. package/dist/capabilities/wandb.json +21 -21
  260. package/dist/capabilities/watt.json +20 -20
  261. package/dist/capabilities/xai.json +5 -5
  262. package/dist/capabilities/xiaomi-token-plan-ams.json +2 -2
  263. package/dist/capabilities/xiaomi-token-plan-cn.json +2 -2
  264. package/dist/capabilities/xiaomi-token-plan-sgp.json +2 -2
  265. package/dist/capabilities/xiaomi.json +2 -2
  266. package/dist/capabilities/xpersona.json +10 -10
  267. package/dist/capabilities/xxapi.json +28 -28
  268. package/dist/capabilities/zai-coding-plan.json +18 -18
  269. package/dist/capabilities/zai.json +27 -27
  270. package/dist/capabilities/zenifra.json +26 -26
  271. package/dist/capabilities/zenmux.json +200 -200
  272. package/dist/capabilities/zerogpu.json +13 -13
  273. package/dist/capabilities/zhipuai-coding-plan.json +8 -8
  274. package/dist/capabilities/zhipuai.json +26 -26
  275. package/dist/capabilities/zro.json +7 -7
  276. package/dist/channels/agent-channels.d.ts +22 -0
  277. package/dist/channels/index.cjs +2 -2
  278. package/dist/channels/index.js +2 -2
  279. package/dist/channels/output-processor.d.ts +12 -0
  280. package/dist/channels/state-adapter.d.ts +3 -1
  281. package/dist/channels/stream-helpers.d.ts +17 -0
  282. package/dist/{channels-0AO7PMJF.js → channels-CC2Z4adP.js} +1 -1
  283. package/dist/{channels-BZL9RT2i.cjs → channels-Drxs9g13.cjs} +1 -1
  284. package/dist/coding-agent/index.cjs +2 -2
  285. package/dist/coding-agent/index.js +2 -2
  286. package/dist/{constants-B9ZDvXZ4.cjs → constants-Bou0hEgY.cjs} +4 -0
  287. package/dist/{constants-BmdTvEYN.js → constants-CFWgIaqA.js} +4 -0
  288. package/dist/datasets/experiment/scorer.d.ts +16 -5
  289. package/dist/datasets/index.cjs +2 -2
  290. package/dist/datasets/index.js +2 -2
  291. package/dist/docs/SKILL.md +2 -1
  292. package/dist/docs/assets/SOURCE_MAP.json +1032 -1032
  293. package/dist/docs/references/docs-agents-networks.md +1 -1
  294. package/dist/docs/references/docs-agents-tools.md +6 -0
  295. package/dist/docs/references/docs-auth-simple-auth.md +8 -8
  296. package/dist/docs/references/docs-evals-custom-scorers.md +1 -1
  297. package/dist/docs/references/docs-mastra-platform-observability-overview.md +3 -189
  298. package/dist/docs/references/docs-memory-message-history.md +25 -0
  299. package/dist/docs/references/docs-sandbox-lsp.md +5 -6
  300. package/dist/docs/references/docs-sandbox-overview.md +20 -0
  301. package/dist/docs/references/docs-sandbox-skills.md +2 -0
  302. package/dist/docs/references/docs-signals-sending-signals.md +1 -1
  303. package/dist/docs/references/reference-agent-controller-session.md +1 -1
  304. package/dist/docs/references/reference-agents-generate.md +1 -1
  305. package/dist/docs/references/reference-agents-network.md +1 -1
  306. package/dist/docs/references/reference-configuration.md +8 -8
  307. package/dist/docs/references/reference-core-getWorkspaceById.md +37 -0
  308. package/dist/docs/references/reference-evals-create-scorer.md +5 -5
  309. package/dist/docs/references/reference-evals-run-evals.md +1 -1
  310. package/dist/docs/references/reference-knowledge-knowledge-tools.md +3 -3
  311. package/dist/docs/references/reference-manual-install.md +1 -1
  312. package/dist/docs/references/reference-memory-observational-memory.md +8 -0
  313. package/dist/docs/references/reference-observability-tracing-interfaces.md +10 -6
  314. package/dist/docs/references/reference-processors-processor-interface.md +3 -2
  315. package/dist/docs/references/reference-processors-system-prompt-scrubber.md +1 -1
  316. package/dist/docs/references/reference-pubsub-base.md +5 -3
  317. package/dist/docs/references/reference-pubsub-caching-pubsub.md +3 -1
  318. package/dist/docs/references/reference-storage-overview.md +1 -1
  319. package/dist/docs/references/reference-storage-retention.md +20 -20
  320. package/dist/docs/references/reference-tools-vector-query-tool.md +8 -0
  321. package/dist/docs/references/reference-voice-overview.md +11 -26
  322. package/dist/docs/references/reference-voice-speech-to-speech.md +1 -1
  323. package/dist/docs/references/reference-voice-voice.listen.md +1 -0
  324. package/dist/docs/references/reference-voice-voice.speak.md +1 -3
  325. package/dist/docs/references/reference-workspace-factory-sandbox.md +6 -6
  326. package/dist/docs/references/reference-workspace-sandbox.md +14 -0
  327. package/dist/docs/references/reference.md +1 -0
  328. package/dist/evals/index.cjs +2 -2
  329. package/dist/evals/index.js +2 -2
  330. package/dist/evals/scoreTraces/index.cjs +2 -2
  331. package/dist/evals/scoreTraces/index.js +2 -2
  332. package/dist/harness/index.cjs +2 -2
  333. package/dist/harness/index.js +2 -2
  334. package/dist/index.cjs +1 -1
  335. package/dist/index.js +1 -1
  336. package/dist/knowledge/index.cjs +51 -16
  337. package/dist/knowledge/index.js +51 -16
  338. package/dist/knowledge/page-tools.d.ts +9 -0
  339. package/dist/knowledge/scope-runtime.d.ts +6 -0
  340. package/dist/llm/index.cjs +3 -3
  341. package/dist/llm/index.js +3 -3
  342. package/dist/llm/model/base.types.d.ts +3 -1
  343. package/dist/llm/model/mastra-gateway-provider-tools.d.ts +9 -6
  344. package/dist/llm/model/model.d.ts +1 -1
  345. package/dist/llm/model/model.loop.d.ts +1 -1
  346. package/dist/llm/model/model.loop.types.d.ts +3 -1
  347. package/dist/llm/model/provider-options.d.ts +4 -3
  348. package/dist/llm/model/provider-types.generated.d.ts +7932 -7894
  349. package/dist/{llm-B4AeSFvV.cjs → llm-CbpBEabY.cjs} +38 -78
  350. package/dist/{llm-B46V7Mi7.js → llm-D3y8qOKL.js} +38 -78
  351. package/dist/loop/index.cjs +2 -2
  352. package/dist/loop/index.js +2 -2
  353. package/dist/{manager-BwDxA1Nn.cjs → manager-BOn6RJwA.cjs} +106 -35
  354. package/dist/{manager-BRAvwB9b.js → manager-elIuArZa.js} +106 -35
  355. package/dist/mastra/index.cjs +1 -1
  356. package/dist/mastra/index.js +1 -1
  357. package/dist/{mastra-DBhdD172.cjs → mastra-CDQJWY6v.cjs} +16 -16
  358. package/dist/{mastra-CIx6qEq2.js → mastra-DQjco6Bt.js} +16 -16
  359. package/dist/memory/index.cjs +3 -3
  360. package/dist/memory/index.js +3 -3
  361. package/dist/{message-list-wI71UGxk.js → message-list-BGm1DCiG.js} +230 -129
  362. package/dist/{message-list-DfN9mWeN.cjs → message-list-vR3uLAHL.cjs} +230 -129
  363. package/dist/{model-CJMsDU8w.js → model-BjyU1L4I.js} +4 -3
  364. package/dist/{model-CYhAa5qO.cjs → model-C4aI7k-i.cjs} +4 -3
  365. package/dist/{netlify-Bw7Vd58y.cjs → netlify-BjuUEMrL.cjs} +41364 -30461
  366. package/dist/{netlify-C9aJA6Cv.js → netlify-BpB7PtZV.js} +41361 -30464
  367. package/dist/notifications/index.cjs +1 -1
  368. package/dist/notifications/index.js +1 -1
  369. package/dist/observability/types/tracing.d.ts +1 -1
  370. package/dist/processor-provider/index.cjs +1 -1
  371. package/dist/processor-provider/index.js +1 -1
  372. package/dist/processors/index.cjs +2 -2
  373. package/dist/processors/index.js +2 -2
  374. package/dist/{provider-registry-DOfYSEju.js → provider-registry-BjdxtGZZ.js} +22658 -22514
  375. package/dist/{provider-registry-Bn_7VvZ8.cjs → provider-registry-bkFdaY45.cjs} +22657 -22513
  376. package/dist/provider-registry.json +22617 -22527
  377. package/dist/{registry-generator-BnK5Npgr.cjs → registry-generator-BORKO0_T.cjs} +1 -1
  378. package/dist/{registry-generator-Cw594Ttt.js → registry-generator-CPF318Kc.js} +1 -1
  379. package/dist/{rehydrate-BWnd_TEx.cjs → rehydrate-Cps4MTph.cjs} +2 -2
  380. package/dist/{rehydrate-Dgqkw7Py.js → rehydrate-Cw2Id-Uz.js} +2 -2
  381. package/dist/relevance/index.cjs +2 -2
  382. package/dist/relevance/index.js +2 -2
  383. package/dist/{run-registry-lLRc7EE6.cjs → run-registry-BTFPEkXT.cjs} +368 -92
  384. package/dist/{run-registry-DhOKJtlb.js → run-registry-D5z2YVqJ.js} +356 -92
  385. package/dist/storage/constants.cjs +1 -1
  386. package/dist/storage/constants.js +1 -1
  387. package/dist/storage/domains/knowledge/base.d.ts +16 -1
  388. package/dist/storage/domains/knowledge/importers-inmemory.d.ts +1 -0
  389. package/dist/storage/domains/knowledge/importers.d.ts +8 -0
  390. package/dist/storage/domains/knowledge/inmemory.d.ts +1 -0
  391. package/dist/storage/domains/knowledge/pages-inmemory.d.ts +5 -1
  392. package/dist/storage/index.cjs +3 -3
  393. package/dist/storage/index.js +3 -3
  394. package/dist/storage/types.d.ts +8 -0
  395. package/dist/stream/index.cjs +2 -2
  396. package/dist/stream/index.js +2 -2
  397. package/dist/{stream-BIDts1fZ.cjs → stream-D1OnBHDi.cjs} +3 -3
  398. package/dist/{stream-C8HKG3qC.js → stream-DB5efioT.js} +3 -3
  399. package/dist/test-utils/llm-mock.cjs +1 -1
  400. package/dist/test-utils/llm-mock.js +1 -1
  401. package/dist/{to-prompt-B9eZo2U5.cjs → to-prompt-CG-LyaBY.cjs} +9 -0
  402. package/dist/{to-prompt-BsDtVXrf.js → to-prompt-CMlVGYxC.js} +9 -0
  403. package/dist/tool-loop-agent/index.cjs +1 -1
  404. package/dist/tool-loop-agent/index.js +1 -1
  405. package/dist/{tool-loop-agent-DM5V_0XS.js → tool-loop-agent-DkhFVx0h.js} +4 -4
  406. package/dist/{tool-loop-agent-PEY5a1R6.cjs → tool-loop-agent-Ote8gJMn.cjs} +4 -4
  407. package/dist/tools/index.cjs +1 -1
  408. package/dist/tools/index.js +1 -1
  409. package/dist/{tools-CDfyMpzN.js → tools-DDfA_ES4.js} +113 -31
  410. package/dist/{tools-CGF5Ik6j.cjs → tools-n9lqzDNe.cjs} +113 -31
  411. package/dist/{utils-DcnKVK34.js → utils-BTKpGHA6.js} +1 -1
  412. package/dist/{utils-CxMSu_wc.cjs → utils-Dl_UFejV.cjs} +1 -1
  413. package/dist/utils.cjs +1 -1
  414. package/dist/utils.js +1 -1
  415. package/dist/{validate-Dn750ciE.js → validate-D6fUqYGz.js} +1 -1
  416. package/dist/{validate-RVKgazCf.cjs → validate-DdDuQRoZ.cjs} +1 -1
  417. package/dist/vector/index.cjs +2 -2
  418. package/dist/vector/index.js +2 -2
  419. package/dist/worker/index.cjs +1 -1
  420. package/dist/worker/index.js +1 -1
  421. package/dist/{worker-Dx0ZHMGX.cjs → worker-B27B9RlK.cjs} +2 -2
  422. package/dist/{worker-SDi9jbP5.js → worker-Bo_hTQJC.js} +2 -2
  423. package/dist/{worker-DJPAdazC.js → worker-DC269pGx.js} +2 -2
  424. package/dist/{worker-CFPu9qwV.cjs → worker-mq-oiLa5.cjs} +2 -2
  425. package/dist/{workflow-ZFOz_365.cjs → workflow-D61dV4AC.cjs} +3 -3
  426. package/dist/{workflow-DkBqNn7X.js → workflow-D97r3h2-.js} +3 -3
  427. package/dist/workflows/builder/index.cjs +1 -1
  428. package/dist/workflows/builder/index.js +1 -1
  429. package/dist/workflows/evented/index.cjs +1 -1
  430. package/dist/workflows/evented/index.js +1 -1
  431. package/dist/workflows/index.cjs +4 -4
  432. package/dist/workflows/index.js +4 -4
  433. package/dist/workflows/step.d.ts +2 -0
  434. package/dist/workflows/workflow.d.ts +2 -0
  435. package/dist/workspace/index.cjs +3 -1
  436. package/dist/workspace/index.d.ts +1 -1
  437. package/dist/workspace/index.js +2 -2
  438. package/dist/workspace/lsp/manager.d.ts +19 -4
  439. package/dist/workspace/sandbox/mastra-sandbox.d.ts +17 -0
  440. package/dist/workspace/tools/index.d.ts +1 -0
  441. package/dist/workspace/tools/media.d.ts +20 -1
  442. package/dist/workspace/tools/recreate-sandbox.d.ts +24 -0
  443. package/dist/{workspace-DY2Nxiyi.js → workspace-BK9ltbSa.js} +270 -105
  444. package/dist/{workspace-X2RHJZU9.cjs → workspace-Pv3J8K0c.cjs} +281 -104
  445. package/package.json +9 -9
  446. package/src/llm/model/provider-types.generated.d.ts +7932 -7894
@@ -4,18 +4,18 @@ 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-BIDts1fZ.cjs");
7
+ const require_stream = require("./stream-D1OnBHDi.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-DfN9mWeN.cjs");
10
+ const require_message_list = require("./message-list-vR3uLAHL.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-B4AeSFvV.cjs");
14
+ const require_llm = require("./llm-CbpBEabY.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");
18
- const require_to_prompt = require("./to-prompt-B9eZo2U5.cjs");
18
+ const require_to_prompt = require("./to-prompt-CG-LyaBY.cjs");
19
19
  const require_dist = require("./dist-P2rjrlmj.cjs");
20
20
  const require_dist$1 = require("./dist-CXeCeeW7.cjs");
21
21
  const require_deep_equal = require("./deep-equal-TMDmByBC.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-Bn_7VvZ8.cjs");
26
+ const require_provider_registry = require("./provider-registry-bkFdaY45.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-CYhAa5qO.cjs");
30
- const require_utils$1 = require("./utils-CxMSu_wc.cjs");
29
+ const require_model$1 = require("./model-C4aI7k-i.cjs");
30
+ const require_utils$1 = require("./utils-Dl_UFejV.cjs");
31
31
  const require_ee_iTj2bRDt = require("./ee-iTj2bRDt-D3-QLGDF.cjs");
32
- const require_background_tasks = require("./background-tasks-DgiQNKh7.cjs");
32
+ const require_background_tasks = require("./background-tasks-B40g_Guf.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");
@@ -38,11 +38,11 @@ const require_workflows_constants = require("./workflows/constants.cjs");
38
38
  const require_hooks = require("./hooks-D7VDBETj.cjs");
39
39
  const require_schedules = require("./schedules-BZS8McF7.cjs");
40
40
  const require_state_processor = require("./state-processor-kRNZ38Nf.cjs");
41
- const require_constants = require("./constants-B9ZDvXZ4.cjs");
41
+ const require_constants = require("./constants-Bou0hEgY.cjs");
42
42
  const require_signal_provider = require("./signal-provider-BFAvh_AJ.cjs");
43
43
  const require_slugify = require("./slugify-B_WzG9IY.cjs");
44
- const require_workspace = require("./workspace-X2RHJZU9.cjs");
45
- const require_tools = require("./tools-CGF5Ik6j.cjs");
44
+ const require_workspace = require("./workspace-Pv3J8K0c.cjs");
45
+ const require_tools = require("./tools-n9lqzDNe.cjs");
46
46
  const require_workspace_skills = require("./workspace-skills-BcquhPDn.cjs");
47
47
  const require_filesystem_versioned = require("./filesystem-versioned-BavRtYWJ.cjs");
48
48
  const require_features_index = require("./features/index.cjs");
@@ -65,12 +65,12 @@ let stream_web = require("stream/web");
65
65
  let _ai_sdk_provider_utils_v6 = require("@ai-sdk/provider-utils-v6");
66
66
  let zod = require("zod");
67
67
  let crypto$1 = require("crypto");
68
- let _mastra_schema_compat = require("@mastra/schema-compat");
69
- let fs = require("fs");
70
- let path = require("path");
71
68
  let zod_v4_core = require("zod/v4/core");
72
69
  let zod_v4_locales_en_js = require("zod/v4/locales/en.js");
73
70
  zod_v4_locales_en_js = require_rolldown_runtime.__toESM(zod_v4_locales_en_js, 1);
71
+ let _mastra_schema_compat = require("@mastra/schema-compat");
72
+ let fs = require("fs");
73
+ let path = require("path");
74
74
  let _mastra_schema_compat_json_to_zod = require("@mastra/schema-compat/json-to-zod");
75
75
  let async_hooks = require("async_hooks");
76
76
  let fastq = require("fastq");
@@ -7617,6 +7617,7 @@ function createStepFromProcessor$1(processor) {
7617
7617
  };
7618
7618
  const step = {
7619
7619
  id: `processor:${processor.id}`,
7620
+ processorId: processor.id,
7620
7621
  description: processor.name ?? `Processor ${processor.id}`,
7621
7622
  inputSchema: (0, _mastra_schema_compat_schema.toStandardSchema)(ProcessorStepInputSchema),
7622
7623
  outputSchema: (0, _mastra_schema_compat_schema.toStandardSchema)(ProcessorStepOutputSchema),
@@ -8262,7 +8263,8 @@ function cloneStep$1(step, opts) {
8262
8263
  retries: step.retries,
8263
8264
  scorers: step.scorers,
8264
8265
  component: step.component,
8265
- metadata: step.metadata
8266
+ metadata: step.metadata,
8267
+ processorId: step.processorId
8266
8268
  };
8267
8269
  }
8268
8270
  /**
@@ -11712,6 +11714,21 @@ function warnUnsupportedEventedSetup(mastra, workflowsStore) {
11712
11714
  warnedHosts.add(mastra);
11713
11715
  mastra.getLogger()?.warn(`Evented workflows and agents aren't supported on several processes with this setup: ${missing}. See ${DOCS_URL}`);
11714
11716
  }
11717
+ // src/agent-controller/worker-run-binding.ts
11718
+ const CONTROLLER_RUN_BINDING_KEY = "mastra__controllerRunBinding";
11719
+ const controllerRunBindingSchema = zod_v4.z.object({
11720
+ controllerId: zod_v4.z.string().min(1),
11721
+ agentId: zod_v4.z.string().min(1),
11722
+ sessionId: zod_v4.z.string().min(1),
11723
+ ownerId: zod_v4.z.string(),
11724
+ resourceId: zod_v4.z.string().min(1),
11725
+ threadId: zod_v4.z.string().min(1),
11726
+ modeId: zod_v4.z.string().min(1)
11727
+ });
11728
+ const restoredWorkerControllerContexts = /* @__PURE__ */ new WeakSet();
11729
+ function isRestoredWorkerControllerContext(value) {
11730
+ return typeof value === "object" && value !== null && restoredWorkerControllerContexts.has(value);
11731
+ }
11715
11732
  // src/agent/scopes.ts
11716
11733
  /**
11717
11734
  * Scope types Memory reads as the run's identity. Every other scope type is
@@ -12000,6 +12017,7 @@ function snapshotRequestContextEntries(requestContext, onEntryOmitted) {
12000
12017
  if (key === "mastra__versions") continue;
12001
12018
  if (key === "mastra__durableExecutions") continue;
12002
12019
  if (key === "mastra__durableSegments") continue;
12020
+ if (key === "__mastra_chat_channel_render") continue;
12003
12021
  const json = require_utils_safe_stringify.boundedStringify(value);
12004
12022
  if (json === void 0) {
12005
12023
  onEntryOmitted?.();
@@ -12026,6 +12044,8 @@ function restoreRequestContext(entries, runLevel, liveRunContext) {
12026
12044
  if (liveRunContext) return liveRunContext;
12027
12045
  if (entries) {
12028
12046
  const restored = new require_request_context.RequestContext([...Object.entries(require_request_context.withoutLiveRequestKeys(entries)), ...liveRequestEntries(runLevel)]);
12047
+ const controller = runLevel?.get("controller");
12048
+ if (isRestoredWorkerControllerContext(controller)) restored.set("controller", controller);
12029
12049
  restoreRunAgentScopes(restored);
12030
12050
  return restored;
12031
12051
  }
@@ -15489,7 +15509,8 @@ var StepExecutor = class extends require_base.MastraBase {
15489
15509
  return require_stream.storageV2StepResultAccessors((step) => require_stream.getHydratedStepResult(stepResults, step, hydrate));
15490
15510
  }
15491
15511
  async execute(params) {
15492
- const { entry, stepResults, runId, requestContext, retryCount = 0, perStep } = params;
15512
+ const { entry, stepResults, runId, retryCount = 0, perStep } = params;
15513
+ let { requestContext } = params;
15493
15514
  const stepId = getEntryId(entry);
15494
15515
  const errorAttemptId = `${runId}:${stepId}:${params.foreachIdx ?? ""}:attempt:${retryCount}`;
15495
15516
  const schemas = getEntrySchemas(entry, this.mastra);
@@ -15545,6 +15566,18 @@ var StepExecutor = class extends require_base.MastraBase {
15545
15566
  const stepTracingContext = workflowStepSpan ? { currentSpan: workflowStepSpan } : params.tracingContext ?? {};
15546
15567
  try {
15547
15568
  if (validationError) throw validationError;
15569
+ if (params.workflowId === DurableStepIds.AGENTIC_LOOP || params.workflowId === DurableStepIds.AGENTIC_EXECUTION) {
15570
+ const live = requestContext.get("controller");
15571
+ const initial = stepResults.input;
15572
+ const binding = initial?.requestContextEntries?.[CONTROLLER_RUN_BINDING_KEY];
15573
+ if (initial && binding !== void 0 && typeof live?.getState !== "function") {
15574
+ const parsed = controllerRunBindingSchema.parse(binding);
15575
+ if (initial.agentId !== parsed.agentId || initial.state?.threadId !== parsed.threadId || initial.state.resourceId !== parsed.resourceId) throw new Error("Controller binding does not match this durable run");
15576
+ const controller = this.mastra?.getAgentControllerById(parsed.controllerId);
15577
+ if (!controller) throw new Error("Controller is not registered on this worker");
15578
+ requestContext = await controller.__restoreWorkerRequestContext(requestContext, parsed, abortController.signal, initial.runId);
15579
+ }
15580
+ }
15548
15581
  const callId = globalThis.crypto.randomUUID();
15549
15582
  const outputWriter = this.createOutputWriter(runId);
15550
15583
  const stepOutput = await require_utils.executeWithContext({
@@ -21341,7 +21374,8 @@ function cloneStep(step, opts) {
21341
21374
  retries: step.retries,
21342
21375
  scorers: step.scorers,
21343
21376
  metadata: step.metadata,
21344
- component: step.component
21377
+ component: step.component,
21378
+ processorId: step.processorId
21345
21379
  };
21346
21380
  }
21347
21381
  function isToolStep(input) {
@@ -21601,6 +21635,7 @@ function createStepFromProcessor(processor) {
21601
21635
  };
21602
21636
  return {
21603
21637
  id: `processor:${processor.id}`,
21638
+ processorId: processor.id,
21604
21639
  description: processor.name ?? `Processor ${processor.id}`,
21605
21640
  inputSchema: (0, _mastra_schema_compat_schema.toStandardSchema)(ProcessorStepSchema),
21606
21641
  outputSchema: (0, _mastra_schema_compat_schema.toStandardSchema)(ProcessorStepOutputSchema),
@@ -27750,12 +27785,14 @@ async function partitionMessages(messagesDescending, limits, tokenCounter, initi
27750
27785
  if (maxTokens !== void 0 && !tokenCounter) throw new Error("A token counter is required to load token-limited message history");
27751
27786
  let messageCount = 0;
27752
27787
  let tokenCount = initialTokens;
27788
+ let loadedTokens = initialTokens;
27753
27789
  let reachedLimit = false;
27754
27790
  let overflowReason;
27755
27791
  const retainedIds = /* @__PURE__ */ new Set();
27756
27792
  for (const group of groupLinkedToolMessages(messagesDescending)) {
27757
27793
  let groupTokens = 0;
27758
27794
  if (tokenCounter) for (const message of group) groupTokens += await tokenCounter.countMessage(message);
27795
+ loadedTokens += groupTokens;
27759
27796
  const exceedsMessageLimit = limits.maxMessages !== void 0 && messageCount + group.length > limits.maxMessages;
27760
27797
  const exceedsTokenLimit = maxTokens !== void 0 && tokenCount + groupTokens > maxTokens;
27761
27798
  if (reachedLimit || exceedsMessageLimit || exceedsTokenLimit) {
@@ -27770,7 +27807,8 @@ async function partitionMessages(messagesDescending, limits, tokenCounter, initi
27770
27807
  return {
27771
27808
  messages: messagesDescending.filter((message) => retainedIds.has(message.id)).reverse(),
27772
27809
  overflow: messagesDescending.filter((message) => !retainedIds.has(message.id)).reverse(),
27773
- overflowReason
27810
+ overflowReason,
27811
+ loadedTokens
27774
27812
  };
27775
27813
  }
27776
27814
  function laterDate(left, right) {
@@ -27832,15 +27870,15 @@ async function loadMessageHistory(args) {
27832
27870
  const newestOverflow = partitioned.overflow.at(-1);
27833
27871
  if (newestOverflow) cutoffTimestamp = newestOverflow.createdAt.getTime();
27834
27872
  const oldestTimestamp = result.messages.at(-1)?.createdAt.getTime();
27835
- const crossedCutoff = cutoffTimestamp !== void 0 && oldestTimestamp !== void 0 && oldestTimestamp < cutoffTimestamp;
27873
+ const crossedCutoff = cutoffTimestamp !== void 0 && oldestTimestamp !== void 0 && oldestTimestamp < cutoffTimestamp && (!args.includeOverflow || partitioned.overflowReason !== "tokens" || partitioned.loadedTokens > (args.maxTokens ?? 0));
27836
27874
  const reachedBoundary = args.boundary !== void 0 && oldestTimestamp !== void 0 && oldestTimestamp < new Date(args.boundary.createdAt).getTime();
27837
- if (!result.hasMore || crossedCutoff || reachedBoundary || result.messages.length === 0) return args.includeOverflow && partitioned.overflowReason === "tokens" ? partitioned : {
27875
+ if (!result.hasMore || crossedCutoff || reachedBoundary || result.messages.length === 0) return {
27838
27876
  messages: partitioned.messages,
27839
- overflow: []
27877
+ overflow: args.includeOverflow && partitioned.overflowReason === "tokens" ? partitioned.overflow : []
27840
27878
  };
27841
- if (oldestTimestamp === void 0) return args.includeOverflow && partitioned.overflowReason === "tokens" ? partitioned : {
27879
+ if (oldestTimestamp === void 0) return {
27842
27880
  messages: partitioned.messages,
27843
- overflow: []
27881
+ overflow: args.includeOverflow && partitioned.overflowReason === "tokens" ? partitioned.overflow : []
27844
27882
  };
27845
27883
  if (end?.getTime() === oldestTimestamp && added === 0) page++;
27846
27884
  else {
@@ -38729,6 +38767,7 @@ var ExperimentsInMemory = class extends ExperimentsStorage {
38729
38767
  targetType: input.targetType ?? null,
38730
38768
  targetId: input.targetId ?? null,
38731
38769
  scorerIds: input.scorerIds ?? null,
38770
+ scorerVersions: input.scorerVersions ?? null,
38732
38771
  name: input.name,
38733
38772
  description: input.description,
38734
38773
  metadata: input.metadata,
@@ -39635,6 +39674,31 @@ var KnowledgeStorage = class extends require_filesystem_versioned.StorageDomain
39635
39674
  getPages(_input) {
39636
39675
  return Promise.reject(new KnowledgeUnsupportedCapabilityError("getPages"));
39637
39676
  }
39677
+ /**
39678
+ * The page `parentId` and its ancestors, nearest first: for each row what {@link getPage} would
39679
+ * return with the same `read`, deleted rows included. Stops after the first scope page, before
39680
+ * the first row `getPage` would return null for, or after {@link MAX_KNOWLEDGE_PAGE_DEPTH} + 1
39681
+ * rows. Lets a caller holding a page walk its parents in one call instead of one per level.
39682
+ *
39683
+ * The base class reads one {@link getPage} per level; adapters that can read the chain in one
39684
+ * query override it.
39685
+ *
39686
+ * @experimental
39687
+ */
39688
+ async getPageParents(input) {
39689
+ const parents = [];
39690
+ let id = input.parentId;
39691
+ while (id && parents.length <= 10) {
39692
+ const page = await this.getPage({
39693
+ id,
39694
+ read: input.read
39695
+ });
39696
+ if (!page) break;
39697
+ parents.push(page);
39698
+ id = page.isScope ? null : page.parentId;
39699
+ }
39700
+ return parents;
39701
+ }
39638
39702
  getPageByPath(_input) {
39639
39703
  return Promise.reject(new KnowledgeUnsupportedCapabilityError("getPageByPath"));
39640
39704
  }
@@ -39952,6 +40016,12 @@ var InMemoryKnowledgeImportersStorage = class extends KnowledgeImportersStorage
39952
40016
  const node = this.#s.nodes.get(key(bindingId, sourceId));
39953
40017
  return node ? structuredClone(node) : null;
39954
40018
  }
40019
+ async getNodes(bindingId, sourceIds) {
40020
+ return [...new Set(sourceIds)].flatMap((sourceId) => {
40021
+ const node = this.#s.nodes.get(key(bindingId, sourceId));
40022
+ return node ? [structuredClone(node)] : [];
40023
+ });
40024
+ }
39955
40025
  async getNodeByPage(pageId) {
39956
40026
  const node = [...this.#s.nodes.values()].find((n) => n.pageId === pageId);
39957
40027
  return node ? structuredClone(node) : null;
@@ -40342,6 +40412,15 @@ var InMemoryKnowledgePageStore = class {
40342
40412
  const page = this.#pages.get(input.id);
40343
40413
  return page && this.#pageReadable(page, input.read) ? clone$1(page) : null;
40344
40414
  }
40415
+ async getPageParents(input) {
40416
+ const parents = [];
40417
+ let page = this.#pages.get(input.parentId);
40418
+ while (page && this.#pageReadable(page, input.read) && parents.length <= 10) {
40419
+ parents.push(clone$1(page));
40420
+ page = page.isScope || !page.parentId ? void 0 : this.#pages.get(page.parentId);
40421
+ }
40422
+ return parents;
40423
+ }
40345
40424
  async getPages(input) {
40346
40425
  return [...new Set(input.ids)].map((id) => this.#pages.get(id)).filter((page) => !!page && !page.deletedAt && this.#pageReadable(page, input.read)).map(clone$1);
40347
40426
  }
@@ -40849,6 +40928,9 @@ var InMemoryKnowledgeStorage = class extends KnowledgeStorage {
40849
40928
  getPage(input) {
40850
40929
  return this.#pageStore.getPage(input);
40851
40930
  }
40931
+ getPageParents(input) {
40932
+ return this.#pageStore.getPageParents(input);
40933
+ }
40852
40934
  listScopeDeclarations() {
40853
40935
  return this.#pageStore.listScopeDeclarations();
40854
40936
  }
@@ -47890,6 +47972,32 @@ function chunkToFallbackMessage(chunk) {
47890
47972
  if (chunk.type === "plan_update") return chunk.title && chunk.title.length > 0 ? chunk.title : null;
47891
47973
  return null;
47892
47974
  }
47975
+ /** Whitespace plus the meaningful joiners ZWNJ (U+200C) and ZWJ (U+200D). */
47976
+ const EDGE_PADDING = /[\s\u200C\u200D]/;
47977
+ /**
47978
+ * Sanitize a buffered channel reply before posting.
47979
+ *
47980
+ * Zero-width space (U+200B) and the byte-order mark (U+FEFF) are invisible
47981
+ * padding and are removed everywhere. Whitespace and the joiners ZWNJ
47982
+ * (U+200C) / ZWJ (U+200D) are trimmed only at the edges, so internal joiners
47983
+ * in compound emoji (🏄🏼‍♂️, 👨‍👩‍👧) and scripts such as Persian (می‌خواهم)
47984
+ * survive — the bug behind #31205. Invisible-only input collapses to '' so
47985
+ * callers skip posting it entirely.
47986
+ *
47987
+ * The edge trim is a single-pass scan rather than
47988
+ * `.replace(/^[\s\u200C\u200D]+|[\s\u200C\u200D]+$/g, '')`: that anchored
47989
+ * alternation backtracks quadratically over a long interior run of the class
47990
+ * (a 300k-character run of model-controlled output took ~80s), while this
47991
+ * scan is O(n).
47992
+ */
47993
+ function cleanBufferedText(input) {
47994
+ const stripped = input.replace(/[\u200B\uFEFF]/g, "");
47995
+ let start = 0;
47996
+ let end = stripped.length;
47997
+ while (start < end && EDGE_PADDING.test(stripped.charAt(start))) start++;
47998
+ while (end > start && EDGE_PADDING.test(stripped.charAt(end - 1))) end--;
47999
+ return start === 0 && end === stripped.length ? stripped : stripped.slice(start, end);
48000
+ }
47893
48001
  // src/channels/chat-driver-static.ts
47894
48002
  /**
47895
48003
  * Static (non-streaming) driver: consumes `AgentChunkType<any>` chunks and
@@ -47934,7 +48042,7 @@ async function runStaticDriver({ stream, chatThread, adapter, toolDisplay, toolD
47934
48042
  let textBuffer = "";
47935
48043
  const toolMessageIds = /* @__PURE__ */ new Map();
47936
48044
  const flushText = async () => {
47937
- const cleaned = textBuffer.replace(/[\u200B-\u200D\uFEFF]/g, "").trim();
48045
+ const cleaned = cleanBufferedText(textBuffer);
47938
48046
  if (cleaned) try {
47939
48047
  await chatThread.post(textFormat === "plain" ? cleaned : { markdown: cleaned });
47940
48048
  } catch (e) {
@@ -48269,7 +48377,7 @@ async function runStreamingDriver({ stream, chatThread, adapter, toolDisplay, to
48269
48377
  if (closed) break;
48270
48378
  await waitForNext();
48271
48379
  }
48272
- const cleaned = fallback.replace(/[\u200B-\u200D\uFEFF]/g, "").trim();
48380
+ const cleaned = cleanBufferedText(fallback);
48273
48381
  if (cleaned) try {
48274
48382
  await chatThread.post(textFormat === "plain" ? cleaned : { markdown: cleaned });
48275
48383
  } catch (postErr) {
@@ -48752,6 +48860,20 @@ const TEXT_CHUNK_TYPES = /* @__PURE__ */ new Set([
48752
48860
  /** Key the processor reads off `requestContext` to locate its render deps. */
48753
48861
  const CHAT_CHANNEL_RENDER_CONTEXT_KEY = "__mastra_chat_channel_render";
48754
48862
  /**
48863
+ * Whether a `requestContext` entry is a live render context rather than the
48864
+ * method-less husk a JSON snapshot round-trip leaves behind (issue #31310).
48865
+ * `wrapStream` is the first method the session calls, so its presence is the
48866
+ * signal that the object is usable.
48867
+ *
48868
+ * Every reader that treats a stashed render context as a live object (the
48869
+ * output processor, `resolveChannelRenderContext`, `AgentChannels.resolveRunRender`
48870
+ * and the generative-UI processor) guards with this, so a husk on a replica's
48871
+ * restored `requestContext` always falls through to a rebuild from the thread.
48872
+ */
48873
+ function isUsableRenderContext(value) {
48874
+ return typeof value === "object" && value !== null && typeof value.wrapStream === "function";
48875
+ }
48876
+ /**
48755
48877
  * Single-producer / single-consumer async queue. The processor pushes chunks
48756
48878
  * synchronously from `processOutputStream`; the driver consumes them via the
48757
48879
  * async iterable. `close()` ends the iteration after pending items are drained.
@@ -48885,7 +49007,7 @@ var ChatChannelOutputProcessor = class {
48885
49007
  async #resolveRenderContext(state, requestContext) {
48886
49008
  if (state.render !== void 0) return state.render;
48887
49009
  const fromRequest = requestContext?.get(CHAT_CHANNEL_RENDER_CONTEXT_KEY);
48888
- if (fromRequest) {
49010
+ if (isUsableRenderContext(fromRequest)) {
48889
49011
  state.render = fromRequest;
48890
49012
  return fromRequest;
48891
49013
  }
@@ -49058,7 +49180,7 @@ var ChatChannelGenerativeUIProcessor = class {
49058
49180
  }
49059
49181
  async #resolve(requestContext, state) {
49060
49182
  const inbound = requestContext?.get(CHAT_CHANNEL_RENDER_CONTEXT_KEY);
49061
- if (inbound) return inbound;
49183
+ if (isUsableRenderContext(inbound)) return inbound;
49062
49184
  if (state && "render" in state) return state.render ?? void 0;
49063
49185
  const threadId = require_stream.parseMemoryRequestContext(requestContext)?.thread?.id;
49064
49186
  const render = threadId && this.#channels ? await this.#channels.buildRenderContextForThread(threadId) : null;
@@ -49212,6 +49334,8 @@ async function headContentType(url, logger) {
49212
49334
  }
49213
49335
  }
49214
49336
  // src/channels/processor.ts
49337
+ /** Per-run `state` key caching a thread's display mode recovered without a render context. */
49338
+ const RECOVERED_DISPLAY_KEY = "threadTextHidden";
49215
49339
  /**
49216
49340
  * Input processor that injects channel context (platform, bot identity, DM vs.
49217
49341
  * public-channel guidance) into the agent's system prompt on every step.
@@ -49245,19 +49369,37 @@ var ChatChannelProcessor = class {
49245
49369
  }
49246
49370
  async #resolve(requestContext, state) {
49247
49371
  const channel = requestContext?.get("channel");
49248
- if (channel) return {
49249
- channel,
49250
- textHidden: (requestContext?.get(CHAT_CHANNEL_RENDER_CONTEXT_KEY))?.textDisplay === "hidden"
49251
- };
49372
+ if (channel) {
49373
+ const render = requestContext?.get(CHAT_CHANNEL_RENDER_CONTEXT_KEY);
49374
+ return {
49375
+ channel,
49376
+ textHidden: isUsableRenderContext(render) ? render.textDisplay === "hidden" : await this.#recoverTextHidden(requestContext, state)
49377
+ };
49378
+ }
49252
49379
  if (state && "thread" in state) return state.thread ?? void 0;
49380
+ const resolved = await this.#resolveThread(requestContext);
49381
+ if (state) state.thread = resolved;
49382
+ return resolved ?? void 0;
49383
+ }
49384
+ /** The channel-backed context of the run's memory thread, or `null` when it has none. */
49385
+ async #resolveThread(requestContext) {
49253
49386
  const threadId = require_stream.parseMemoryRequestContext(requestContext)?.thread?.id;
49254
49387
  const found = threadId && this.#channels ? await this.#channels.buildChannelContextForThread(threadId) : null;
49255
- const resolved = found ? {
49388
+ return found ? {
49256
49389
  channel: found.channel,
49257
49390
  textHidden: found.render.textDisplay === "hidden"
49258
49391
  } : null;
49259
- if (state) state.thread = resolved;
49260
- return resolved ?? void 0;
49392
+ }
49393
+ /**
49394
+ * Display mode of a channel-backed thread whose render context is no longer on the
49395
+ * restored request context. Cached per run like the thread lookup above, so later
49396
+ * steps of the same run read the thread once.
49397
+ */
49398
+ async #recoverTextHidden(requestContext, state) {
49399
+ if (state && RECOVERED_DISPLAY_KEY in state) return state[RECOVERED_DISPLAY_KEY] === true;
49400
+ const textHidden = (await this.#resolveThread(requestContext))?.textHidden ?? false;
49401
+ if (state) state[RECOVERED_DISPLAY_KEY] = textHidden;
49402
+ return textHidden;
49261
49403
  }
49262
49404
  };
49263
49405
  function channelLines(ctx, textHidden, tools) {
@@ -49780,15 +49922,17 @@ var ChannelReplyModeProcessor = class {
49780
49922
  var MastraStateAdapter = class {
49781
49923
  memoryStore;
49782
49924
  getOwnerId;
49925
+ logger;
49783
49926
  connected = false;
49784
49927
  connectPromise = null;
49785
49928
  cache = /* @__PURE__ */ new Map();
49786
49929
  locks = /* @__PURE__ */ new Map();
49787
49930
  lists = /* @__PURE__ */ new Map();
49788
49931
  queues = /* @__PURE__ */ new Map();
49789
- constructor(memoryStore, getOwnerId) {
49932
+ constructor(memoryStore, getOwnerId, logger) {
49790
49933
  this.memoryStore = memoryStore;
49791
49934
  this.getOwnerId = getOwnerId;
49935
+ this.logger = logger;
49792
49936
  }
49793
49937
  async connect() {
49794
49938
  if (this.connected) return;
@@ -49807,7 +49951,10 @@ var MastraStateAdapter = class {
49807
49951
  }
49808
49952
  async subscribe(threadId) {
49809
49953
  const thread = await this.findThreadByExternalId(threadId);
49810
- if (!thread) return;
49954
+ if (!thread) {
49955
+ this.logger?.warn(`subscribe(${threadId}) ignored: no Mastra thread is mapped to this chat thread. Use AgentChannels.subscribeThread() for threads the bot started itself.`);
49956
+ return;
49957
+ }
49811
49958
  await this.memoryStore.patchThread({
49812
49959
  id: thread.id,
49813
49960
  metadata: {
@@ -50199,7 +50346,7 @@ function formatLegacyHistoryBlock(history, chatThread, platform) {
50199
50346
  async function resolveChannelRenderContext(requestContext, channels) {
50200
50347
  if (!requestContext) return void 0;
50201
50348
  const stashed = requestContext.get(CHAT_CHANNEL_RENDER_CONTEXT_KEY);
50202
- if (stashed) return stashed;
50349
+ if (isUsableRenderContext(stashed)) return stashed;
50203
50350
  const threadId = requestContext.get("controller")?.threadId ?? require_stream.parseMemoryRequestContext(requestContext)?.thread?.id;
50204
50351
  if (!threadId) return void 0;
50205
50352
  return await channels?.()?.buildRenderContextForThread(threadId) ?? void 0;
@@ -50643,7 +50790,7 @@ var AgentChannels = class {
50643
50790
  const storage = mastra.getStorage();
50644
50791
  const memoryStore = storage ? await storage.getStore("memory") : void 0;
50645
50792
  if (!memoryStore) throw new Error("Channels require storage to be configured on the Mastra instance. Configure a storage provider like LibSQLStore.");
50646
- this.stateAdapter = new MastraStateAdapter(memoryStore, () => this.getOwnerId());
50793
+ this.stateAdapter = new MastraStateAdapter(memoryStore, () => this.getOwnerId(), this.logger);
50647
50794
  this.log("info", "Using MastraStateAdapter (subscriptions persist across restarts)");
50648
50795
  }
50649
50796
  const { Chat, Message: ChatMessage, ThreadImpl } = await getChatModule();
@@ -50871,25 +51018,30 @@ var AgentChannels = class {
50871
51018
  runId = stashed.runId;
50872
51019
  toolName = stashed.toolName;
50873
51020
  toolArgs = stashed.args;
50874
- } else {
51021
+ }
51022
+ if (!requesterId) {
50875
51023
  const { result: lookup } = await this.lookupPersistedApproval({
50876
51024
  mastra,
50877
51025
  card,
50878
51026
  platform
50879
51027
  });
50880
- if (lookup.status === "answered") {
50881
- this.log("info", "Tool approval already answered", actionEventContext);
50882
- return;
51028
+ if (!stashed?.runId) {
51029
+ if (lookup.status === "answered") {
51030
+ this.log("info", "Tool approval already answered", actionEventContext);
51031
+ return;
51032
+ }
51033
+ if (lookup.status === "pending") {
51034
+ runId = lookup.runId;
51035
+ toolName = lookup.toolName;
51036
+ toolArgs = lookup.args;
51037
+ }
50883
51038
  }
50884
51039
  if (lookup.status === "pending") {
50885
- runId = lookup.runId;
50886
- toolName = lookup.toolName;
50887
- toolArgs = lookup.args;
50888
- if (adapterConfig?.toolApprovers !== "anyone" && !requesterId && lookup.authors.length > 1) {
51040
+ if (adapterConfig?.toolApprovers !== "anyone" && lookup.authors.length > 1) {
50889
51041
  this.log("info", "Ignoring tool approval action: requester is ambiguous", actionEventContext);
50890
51042
  return;
50891
51043
  }
50892
- requesterId ??= lookup.authors[0];
51044
+ requesterId = lookup.authors[0];
50893
51045
  }
50894
51046
  }
50895
51047
  if (!runId) {
@@ -51194,7 +51346,7 @@ var AgentChannels = class {
51194
51346
  */
51195
51347
  async resolveRunRender(requestContext, state) {
51196
51348
  const inbound = requestContext?.get(CHAT_CHANNEL_RENDER_CONTEXT_KEY);
51197
- if (inbound) return inbound;
51349
+ if (isUsableRenderContext(inbound)) return inbound;
51198
51350
  if (state && "render" in state) return state.render ?? void 0;
51199
51351
  const render = await resolveChannelRenderContext(requestContext, () => this);
51200
51352
  if (state) state.render = render ?? null;
@@ -51223,8 +51375,8 @@ var AgentChannels = class {
51223
51375
  const has = (id) => configuredProcessors.some((p) => !require_stream.isProcessorWorkflow(p) && p.id === id);
51224
51376
  const processors = [];
51225
51377
  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);
51378
+ const platform = requestContext.get("channel")?.platform ?? requestContext.get("__mastra_chat_channel_render")?.platform;
51379
+ return platform ? threadLinkOptions(this.adapterConfigs[platform]?.threadLink) : void 0;
51228
51380
  }));
51229
51381
  if (!has("chat-channel-render")) processors.push(new ChatChannelOutputProcessor(this));
51230
51382
  if (this.replyModeEnabled && !has(REPLY_STREAM_PROCESSOR_ID)) processors.push(new ChannelReplyStreamProcessor((requestContext) => this.resolveRunRender(requestContext)));
@@ -52406,6 +52558,36 @@ var AgentChannels = class {
52406
52558
  };
52407
52559
  }
52408
52560
  /**
52561
+ * Map a chat thread to a Mastra thread (creating the mapping if needed) and
52562
+ * subscribe to it, so follow-up replies reach the agent without a mention.
52563
+ *
52564
+ * Use this for threads the bot started itself, e.g. a scheduled digest posted
52565
+ * to Slack. Inbound messages create the mapping automatically, but a thread
52566
+ * the bot opened has none until someone mentions it. An existing mapping is
52567
+ * reused and keeps its original owner.
52568
+ *
52569
+ * @example
52570
+ * ```ts
52571
+ * const sent = await channel.post('Daily digest');
52572
+ * await agent.getChannels()!.subscribeThread({ thread: sent.thread, resourceId: 'digest-bot' });
52573
+ * ```
52574
+ */
52575
+ async subscribeThread({ thread, resourceId, threadId }) {
52576
+ const mastra = this.getMastra();
52577
+ if (!mastra) throw new Error("subscribeThread requires the agent to be registered with a Mastra instance.");
52578
+ await this.initialize(mastra);
52579
+ const mastraThread = await this.getOrCreateThread({
52580
+ externalThreadId: thread.id,
52581
+ channelId: thread.channelId,
52582
+ platform: thread.adapter.name,
52583
+ resourceId,
52584
+ threadId: threadId ? () => threadId : void 0,
52585
+ mastra
52586
+ });
52587
+ await this.stateAdapter.subscribe(thread.id);
52588
+ return mastraThread;
52589
+ }
52590
+ /**
52409
52591
  * Resolves an existing Mastra thread for the given external IDs, or creates one.
52410
52592
  */
52411
52593
  async getOrCreateThread({ externalThreadId, channelId, platform, resourceId, threadId, onCreate, mastra }) {
@@ -53391,17 +53573,19 @@ async function pageRefKeys(storage, page) {
53391
53573
  if (page.address) keys.push(knowledgeLinkRefKey(page.address));
53392
53574
  return keys;
53393
53575
  }
53576
+ if (!page.key || !page.parentId) return keys;
53394
53577
  const path = [];
53395
- let current = page;
53396
- while (current && !current.isScope) {
53578
+ for (const current of [page, ...await storage.getPageParents({
53579
+ parentId: page.parentId,
53580
+ read: "all"
53581
+ })]) {
53582
+ if (current.isScope) {
53583
+ if (current.address) keys.push(knowledgeLinkRefKey(`${current.address}#${path.join("/")}`));
53584
+ return keys;
53585
+ }
53397
53586
  if (!current.key || !current.parentId) return keys;
53398
53587
  path.unshift(current.key);
53399
- current = await storage.getPage({
53400
- id: current.parentId,
53401
- read: "all"
53402
- });
53403
53588
  }
53404
- if (current?.address) keys.push(knowledgeLinkRefKey(`${current.address}#${path.join("/")}`));
53405
53589
  return keys;
53406
53590
  }
53407
53591
  /** The page and its live ordinary descendants, at most {@link MAX_KNOWLEDGE_MOVE_PAGES} + 1. */
@@ -63429,6 +63613,30 @@ async function noteSummaries(run, notes, cache = /* @__PURE__ */ new Map()) {
63429
63613
  for (const note of notes) summaries.push(noteSummary(note, await noteMentions(run, note, cache)));
63430
63614
  return summaries;
63431
63615
  }
63616
+ /**
63617
+ * Every scope the run holds, in principal order, with its role and what it can do there. A held scope
63618
+ * gets its page on the first write, so before that its role comes from the declarations and the parent
63619
+ * that write would link it under: without it a model sees no scopes on its first turn and concludes it
63620
+ * has nowhere to write. A stored scope it can't read keeps only its address.
63621
+ */
63622
+ async function heldScopes(run) {
63623
+ const stored = await run.storage.getScopesByAddress(run.principals);
63624
+ return Promise.all(run.principals.map(async (address) => {
63625
+ const found = stored.find((scope) => scope.address === address);
63626
+ const page = found && knowledgeScopeReadable(found, run.read) ? found : void 0;
63627
+ const role = found ? await run.roleOn(found) : knowledgeRoleOn(run.runtime.compiled, run.principals, {
63628
+ address,
63629
+ parentAddress: run.runtime.firstWriteParentAddress(address, run.principals)
63630
+ });
63631
+ const can = !role ? "none" : knowledgeRoleAtLeast(role, "contributor") ? "write" : "read";
63632
+ return {
63633
+ address,
63634
+ ...page ? { page } : {},
63635
+ role,
63636
+ can
63637
+ };
63638
+ }));
63639
+ }
63432
63640
  /** Scope pages for addresses the run names; each must be readable. */
63433
63641
  async function readableScopes(run, addresses) {
63434
63642
  const page = addresses.find((address) => address.includes("#"));
@@ -63709,7 +63917,7 @@ function bodyView(body, input) {
63709
63917
  function readTool(host, canEdit) {
63710
63918
  return require_tool.createTool({
63711
63919
  id: "knowledge_read",
63712
- description: `Read a page: its body, its notes, its child pages and the notes on other pages that mention it. Read a scope address (org:acme) to browse that scope. Without \`page\`, lists the scopes this run holds. When a page's notes, or the notes mentioning it, come to more than ${KNOWLEDGE_READ_INLINE_TOKENS.toLocaleString("en-US")} tokens, a whole read leaves them out and counts them in \`more\`; read them on their own with \`notes\` or \`mentionedIn\`. A body returns at most ${maxTokensOf(host).toLocaleString("en-US")} tokens at a time. A body that fits comes whole as \`body\`; a longer one comes as numbered \`lines\` (\`12\u2502text\`) with the \`range\` they cover, and \`more\` says where to read on; a first read of a long page shows every heading with its line number and the first lines under it, so you can pick the part to read. For a long page, ask for its \`outline\` of headings with their line numbers, read one \`section\`, or \`match\` terms to see only the lines that contain them, with \`context\` lines around each. Those part reads return just that part of the body.` + (canEdit ? " To edit part of a long body, pass the `range` a read gave you to knowledge_page." : ""),
63920
+ description: `Read a page: its body, its notes, its child pages and the notes on other pages that mention it. Read a scope address (org:acme) to browse that scope. Without \`page\`, lists every scope this run holds, with its role and whether it can read or write there, including scopes with no page this run can read yet (\`empty\`). When a page's notes, or the notes mentioning it, come to more than ${KNOWLEDGE_READ_INLINE_TOKENS.toLocaleString("en-US")} tokens, a whole read leaves them out and counts them in \`more\`; read them on their own with \`notes\` or \`mentionedIn\`. A body returns at most ${maxTokensOf(host).toLocaleString("en-US")} tokens at a time. A body that fits comes whole as \`body\`; a longer one comes as numbered \`lines\` (\`12\u2502text\`) with the \`range\` they cover, and \`more\` says where to read on; a first read of a long page shows every heading with its line number and the first lines under it, so you can pick the part to read. For a long page, ask for its \`outline\` of headings with their line numbers, read one \`section\`, or \`match\` terms to see only the lines that contain them, with \`context\` lines around each. Those part reads return just that part of the body.` + (canEdit ? " To edit part of a long body, pass the `range` a read gave you to knowledge_page." : ""),
63713
63921
  inputSchema: {
63714
63922
  type: "object",
63715
63923
  properties: {
@@ -63791,10 +63999,13 @@ function readTool(host, canEdit) {
63791
63999
  if (outline && from) throw new Error("knowledge_read: an outline covers the whole body; pass it without from.");
63792
64000
  const run = await start(host, context);
63793
64001
  const limit = limitOf(requested);
63794
- if (!ref) return { scopes: (await run.storage.getScopesByAddress(run.principals)).filter((scope) => knowledgeScopeReadable(scope, run.read)).map((scope) => ({
63795
- address: scope.address,
63796
- name: scope.name,
63797
- ...scope.description ? { description: scope.description } : {}
64002
+ if (!ref) return { scopes: (await heldScopes(run)).map(({ address, page, role, can }) => ({
64003
+ address,
64004
+ name: page?.name ?? address,
64005
+ ...page?.description ? { description: page.description } : {},
64006
+ ...role ? { role } : {},
64007
+ can,
64008
+ ...page ? {} : { empty: true }
63798
64009
  })) };
63799
64010
  const page = await run.pageOrCloseMatches(ref);
63800
64011
  if (outline || section || match || from) {
@@ -64008,12 +64219,13 @@ async function listKnowledgeTree(run, { origin, depth, limit, cursor, descriptio
64008
64219
  let scopes = [];
64009
64220
  if (!origin) {
64010
64221
  if (cursor?.startsWith("p")) throw new Error("knowledge_list: a page cursor needs the `from` it came from.");
64011
- const held = await run.storage.getScopesByAddress(run.principals);
64012
- const order = (scope) => run.principals.indexOf(scope.address ?? "");
64013
- scopes = held.filter((scope) => knowledgeScopeReadable(scope, run.read)).sort((a, b) => order(a) - order(b));
64222
+ scopes = (await heldScopes(run)).map((held) => ({
64223
+ ...held.page ? { page: held.page } : {},
64224
+ held
64225
+ }));
64014
64226
  } else {
64015
64227
  originRef = (await pageRefs(run, [origin])).refs.get(origin.id) ?? origin.id;
64016
- if (origin.isScope && !cursor?.startsWith("p")) scopes = await childScopes(origin.id);
64228
+ if (origin.isScope && !cursor?.startsWith("p")) scopes = (await childScopes(origin.id)).map((page) => ({ page }));
64017
64229
  }
64018
64230
  const shownScopes = scopes.slice(scopeOffset, scopeOffset + limit);
64019
64231
  let roots = shownScopes;
@@ -64023,7 +64235,7 @@ async function listKnowledgeTree(run, { origin, depth, limit, cursor, descriptio
64023
64235
  const room = limit - shownScopes.length;
64024
64236
  if (room > 0) {
64025
64237
  const pages = await childPages(origin.id, room, pageCursor);
64026
- roots = [...shownScopes, ...pages.pages];
64238
+ roots = [...shownScopes, ...pages.pages.map((page) => ({ page }))];
64027
64239
  if (pages.nextCursor) nextCursor = `p${pages.nextCursor}`;
64028
64240
  } else if ((await run.storage.countChildPages({
64029
64241
  parentIds: [origin.id],
@@ -64037,10 +64249,19 @@ async function listKnowledgeTree(run, { origin, depth, limit, cursor, descriptio
64037
64249
  children: 0,
64038
64250
  below: []
64039
64251
  });
64040
- const top = roots.map((page) => nodeOf(page, origin && originRef ? childRef(origin, originRef, page) : page.address ?? page.id, 1));
64252
+ const top = roots.map(({ page, held }) => page ? {
64253
+ ...nodeOf(page, origin && originRef ? childRef(origin, originRef, page) : page.address ?? page.id, 1),
64254
+ ...held ? { held } : {}
64255
+ } : {
64256
+ held,
64257
+ ref: held.address,
64258
+ depth: 1,
64259
+ children: 0,
64260
+ below: []
64261
+ });
64041
64262
  let budget = Math.max(limit - top.length, 0);
64042
64263
  let truncated = false;
64043
- let level = top;
64264
+ let level = top.filter((node) => node.page);
64044
64265
  for (let current = 1; current <= depth && level.length; current++) {
64045
64266
  const parentIds = level.map((node) => node.page.id);
64046
64267
  const scopeParents = level.filter((node) => node.page.isScope).map((node) => node.page.id);
@@ -64064,22 +64285,30 @@ async function listKnowledgeTree(run, { origin, depth, limit, cursor, descriptio
64064
64285
  budget -= scopes.length;
64065
64286
  const pages = budget > 0 ? (await childPages(node.page.id, budget)).pages : [];
64066
64287
  budget -= pages.length;
64067
- node.below = [...scopes, ...pages].map((child) => nodeOf(child, childRef(node.page, node.ref, child), current + 1));
64068
- if (node.below.length < node.children) truncated = true;
64069
- nextLevel.push(...node.below);
64288
+ const below = [...scopes, ...pages].map((child) => ({
64289
+ ...nodeOf(child, childRef(node.page, node.ref, child), current + 1),
64290
+ page: child
64291
+ }));
64292
+ node.below = below;
64293
+ if (below.length < node.children) truncated = true;
64294
+ nextLevel.push(...below);
64070
64295
  }
64071
64296
  level = nextLevel;
64072
64297
  }
64073
64298
  const entries = [];
64074
64299
  const flatten = (nodes) => {
64075
64300
  for (const node of nodes) {
64301
+ const { page, held } = node;
64076
64302
  entries.push({
64077
64303
  ref: node.ref,
64078
- name: node.page.name,
64079
- ...descriptions && node.page.description ? { description: node.page.description } : {},
64304
+ name: page?.name ?? node.ref,
64305
+ ...descriptions && page?.description ? { description: page.description } : {},
64080
64306
  depth: node.depth,
64081
64307
  children: node.children,
64082
- ...node.page.isScope ? { scope: true } : {}
64308
+ ...!page || page.isScope ? { scope: true } : {},
64309
+ ...held?.role ? { role: held.role } : {},
64310
+ ...held ? { can: held.can } : {},
64311
+ ...page ? {} : { empty: true }
64083
64312
  });
64084
64313
  flatten(node.below);
64085
64314
  }
@@ -64096,7 +64325,7 @@ function listTool(host) {
64096
64325
  const maxTokens = maxTokensOf(host);
64097
64326
  return require_tool.createTool({
64098
64327
  id: "knowledge_list",
64099
- description: `List the page tree under a starting point: each child with its ref (pass it to knowledge_read or knowledge_list), name and how many children it has. Pass \`descriptions: true\` to include page descriptions too. Without \`from\`, lists the scopes this run can read. Use it to find your way around a scope before searching or reading. One result holds at most \`limit\` entries and about ${maxTokens.toLocaleString("en-US")} tokens of them; when it stops early, \`more\` says how many entries were left out and gives the \`cursor\` to list the rest (pass the same \`from\`).`,
64328
+ description: `List the page tree under a starting point: each child with its ref (pass it to knowledge_read or knowledge_list), name and how many children it has. Pass \`descriptions: true\` to include page descriptions too. Without \`from\`, lists every scope this run holds, with its role and whether it can read or write there, including scopes with no page this run can read yet (\`empty\`). Use it to find your way around a scope before searching or reading. One result holds at most \`limit\` entries and about ${maxTokens.toLocaleString("en-US")} tokens of them; when it stops early, \`more\` says how many entries were left out and gives the \`cursor\` to list the rest (pass the same \`from\`).`,
64100
64329
  inputSchema: {
64101
64330
  type: "object",
64102
64331
  properties: {
@@ -67193,7 +67422,7 @@ var MastraLLMVNext = class extends require_base.MastraBase {
67193
67422
  content: messages
67194
67423
  }];
67195
67424
  }
67196
- stream({ resumeContext, runId, stopWhen, maxSteps, tools = {}, modelSettings, toolChoice = "auto", threadId, resourceId, structuredOutput, options, inputProcessors, llmRequestInputProcessors, outputProcessors, errorProcessors, hasConfiguredErrorProcessors, returnScorerData, providerOptions, messageList, requireToolApproval, toolCallConcurrency, eagerToolExecution, streamPublisher, _internal, onTracingTripwire, onTracingTerminalError, tracingScope = require_stream.createRunScope(), agentId, agentVersionId, resolvedScopes, agentName, toolCallId, requestContext, actor, mcp, methodType, includeRawChunks, experimentalTransform, hideSignals, autoResumeSuspendedTools, maxProcessorRetries, processorStates, activeTools, isTaskComplete, goal, onIterationComplete, workspace, agentRunSpan, agent, ...rest }) {
67425
+ stream({ resumeContext, runId, stopWhen, maxSteps, tools = {}, modelSettings, toolChoice = "auto", threadId, resourceId, structuredOutput, options, inputProcessors, llmRequestInputProcessors, outputProcessors, errorProcessors, hasConfiguredErrorProcessors, returnScorerData, providerOptions, messageList, requireToolApproval, toolCallConcurrency, eagerToolExecution, streamPublisher, _internal, onTracingTripwire, onTracingTerminalError, tracingScope = require_stream.createRunScope(), agentId, agentVersionId, resolvedScopes, agentName, toolCallId, requestContext, actor, mcp, methodType, includeRawChunks, experimentalTransform, hideSignals, autoResumeSuspendedTools, maxProcessorRetries, processorStates, activeTools, isTaskComplete, goal, onIterationComplete, workspace, agentRunSpan, agent, resultType, ...rest }) {
67197
67426
  const observabilityContext = require_observability.resolveObservabilityContext(rest);
67198
67427
  let stopWhenToUse;
67199
67428
  if (maxSteps && typeof maxSteps === "number") {
@@ -67219,7 +67448,8 @@ var MastraLLMVNext = class extends require_base.MastraBase {
67219
67448
  provider: firstModel.provider,
67220
67449
  streaming: true,
67221
67450
  parameters: modelSettings,
67222
- ...toolDefinitions ? { tools: toolDefinitions } : {}
67451
+ ...toolDefinitions ? { tools: toolDefinitions } : {},
67452
+ ...resultType ? { resultType } : {}
67223
67453
  },
67224
67454
  metadata: {
67225
67455
  runId,
@@ -73571,8 +73801,9 @@ function releaseRunMessageRefs(runId) {
73571
73801
  /**
73572
73802
  * A `SaveQueueManager` `onSaved` callback that records the rows a run saved,
73573
73803
  * so its persisted transcript references them instead of repeating them. Only
73574
- * runs that store refs hold an entry (the transcript store creates it), so saves
73575
- * for other runs, or landing after the run released its entry, are not kept.
73804
+ * runs that store refs hold an entry (created before the run saves its input,
73805
+ * else by the transcript store), so saves for other runs, or landing after the
73806
+ * run released its entry, are not kept.
73576
73807
  */
73577
73808
  function recordRunSavedMessages(runId) {
73578
73809
  return (rows) => {
@@ -73594,6 +73825,15 @@ function recordRunSavedMessages(runId) {
73594
73825
  };
73595
73826
  }
73596
73827
  // src/agent/durable/utils/resolve-runtime.ts
73828
+ async function restoreWorkerToolsets(mastra, context, names) {
73829
+ const controller = context.get("controller");
73830
+ if (!isRestoredWorkerControllerContext(controller) || !names?.length) return;
73831
+ const toolsets = await mastra.getAgentControllerById(controller.controllerId)?.__restoreWorkerToolsets(context);
73832
+ if (!toolsets) return;
73833
+ const allowed = new Set(names);
73834
+ for (const [key, tools] of Object.entries(toolsets)) if (tools) toolsets[key] = Object.fromEntries(Object.entries(tools).filter(([name]) => allowed.has(name)));
73835
+ return toolsets;
73836
+ }
73597
73837
  /**
73598
73838
  * Build a SaveQueueManager for a run's memory, or `undefined` when no memory
73599
73839
  * is configured. Shared by `resolveRuntimeDependencies` and
@@ -73756,6 +73996,7 @@ async function resolveRuntimeDependencies(options) {
73756
73996
  backgroundTasks = resolveBackgroundTasks(mastra, agent, input.options);
73757
73997
  tools = await agent.getToolsForExecution({
73758
73998
  runId,
73999
+ toolsets: await restoreWorkerToolsets(mastra, resolveRequestContext, input.options?.toolsetToolNames),
73759
74000
  threadId: input.state.threadId,
73760
74001
  resourceId: input.state.resourceId,
73761
74002
  requestContext: resolveRequestContext,
@@ -73877,6 +74118,7 @@ async function rebuildRunToolsFromMastra(options) {
73877
74118
  const backgroundTasks = resolveBackgroundTasks(mastra, agent, execOptions);
73878
74119
  const tools = await agent.getToolsForExecution({
73879
74120
  runId,
74121
+ toolsets: await restoreWorkerToolsets(mastra, resolveRequestContext, execOptions?.toolsetToolNames),
73880
74122
  threadId: state.threadId,
73881
74123
  resourceId: state.resourceId,
73882
74124
  requestContext: resolveRequestContext,
@@ -74346,7 +74588,11 @@ function mergeRequestContextForFinalization(entries, fallback, liveRunContext) {
74346
74588
  if (liveRunContext) return liveRunContext;
74347
74589
  if (!entries) return fallback ?? new require_request_context.RequestContext();
74348
74590
  const restored = new require_request_context.RequestContext(fallback?.entries());
74349
- for (const [key, value] of Object.entries(require_request_context.withoutLiveRequestKeys(entries))) restored.set(key, value);
74591
+ const controller = fallback?.get("controller");
74592
+ for (const [key, value] of Object.entries(require_request_context.withoutLiveRequestKeys(entries))) {
74593
+ if (key === "controller" && isRestoredWorkerControllerContext(controller)) continue;
74594
+ restored.set(key, value);
74595
+ }
74350
74596
  restoreRunAgentScopes(restored);
74351
74597
  return restored;
74352
74598
  }
@@ -74387,6 +74633,7 @@ async function runDurableFinishSideEffects({ runId, initData, messageListState,
74387
74633
  ...initData,
74388
74634
  messageListState
74389
74635
  },
74636
+ requestContext,
74390
74637
  logger: effectiveLogger
74391
74638
  });
74392
74639
  rebuiltSaveQueueManager = resolved.saveQueueManager;
@@ -76391,6 +76638,15 @@ function buildMessagesFromChunks({ chunks, messageId, responseModelMetadata, too
76391
76638
  });
76392
76639
  break;
76393
76640
  }
76641
+ case "custom": {
76642
+ const p = chunk.payload;
76643
+ parts.push({
76644
+ type: "custom",
76645
+ kind: p.kind,
76646
+ ...p.providerMetadata ? { providerMetadata: p.providerMetadata } : {}
76647
+ });
76648
+ break;
76649
+ }
76394
76650
  case "tool-call": {
76395
76651
  const p = chunk.payload;
76396
76652
  const toolDef = tools?.[p.toolName] || findProviderToolByName(tools, p.toolName);
@@ -83725,15 +83981,21 @@ async function persistDurableRunInput(runId, workflowInput, mastra, beforeSave)
83725
83981
  await beforeSave();
83726
83982
  }
83727
83983
  const inputCopy = entry.messageList.clone();
83728
- await entry.saveQueueManager.flushMessages(inputCopy, state.threadId, state.memoryConfig, {
83729
- throwOnError: true,
83730
- beforePersist: () => assertExecutionOwned({
83731
- runId,
83732
- agentId: workflowInput.agentId,
83733
- mastra,
83734
- requestContext
83735
- })
83736
- });
83984
+ if (state.fixedMemory) getRunMessageRefs(runId);
83985
+ try {
83986
+ await entry.saveQueueManager.flushMessages(inputCopy, state.threadId, state.memoryConfig, {
83987
+ throwOnError: true,
83988
+ beforePersist: () => assertExecutionOwned({
83989
+ runId,
83990
+ agentId: workflowInput.agentId,
83991
+ mastra,
83992
+ requestContext
83993
+ })
83994
+ });
83995
+ } catch (error) {
83996
+ if (state.fixedMemory) releaseRunMessageRefs(runId);
83997
+ throw error;
83998
+ }
83737
83999
  const embedded = entry.messageList.getEmbeddedMessages();
83738
84000
  for (const [messageId, textHash] of inputCopy.getEmbeddedMessages()) embedded.set(messageId, textHash);
83739
84001
  }
@@ -84060,7 +84322,7 @@ async function prepareForDurableExecution(options) {
84060
84322
  });
84061
84323
  let tripwireData;
84062
84324
  if (inputProcessors.length > 0) try {
84063
- const { ProcessorRunner } = await Promise.resolve().then(() => require("./stream-BIDts1fZ.cjs")).then((n) => n.runner_exports);
84325
+ const { ProcessorRunner } = await Promise.resolve().then(() => require("./stream-D1OnBHDi.cjs")).then((n) => n.runner_exports);
84064
84326
  await new ProcessorRunner({
84065
84327
  inputProcessors,
84066
84328
  outputProcessors,
@@ -88525,11 +88787,13 @@ var Agent = class Agent extends require_base.MastraBase {
88525
88787
  ...observabilityContext,
88526
88788
  messageList,
88527
88789
  agentId: this.id,
88528
- agentName: this.name
88790
+ agentName: this.name,
88791
+ resultType: "title_generation"
88529
88792
  }).text;
88530
88793
  } else text = (await llm.__text({
88531
88794
  requestContext,
88532
88795
  ...observabilityContext,
88796
+ resultType: "title_generation",
88533
88797
  messages: [{
88534
88798
  role: "system",
88535
88799
  content: systemInstructions
@@ -110812,6 +111076,12 @@ Object.defineProperty(exports, "CONTINUE_RUN_MESSAGE", {
110812
111076
  return CONTINUE_RUN_MESSAGE;
110813
111077
  }
110814
111078
  });
111079
+ Object.defineProperty(exports, "CONTROLLER_RUN_BINDING_KEY", {
111080
+ enumerable: true,
111081
+ get: function() {
111082
+ return CONTROLLER_RUN_BINDING_KEY;
111083
+ }
111084
+ });
110815
111085
  Object.defineProperty(exports, "ChannelSessionRejectedError", {
110816
111086
  enumerable: true,
110817
111087
  get: function() {
@@ -113560,6 +113830,12 @@ Object.defineProperty(exports, "resolveWaitUntil", {
113560
113830
  return resolveWaitUntil;
113561
113831
  }
113562
113832
  });
113833
+ Object.defineProperty(exports, "restoredWorkerControllerContexts", {
113834
+ enumerable: true,
113835
+ get: function() {
113836
+ return restoredWorkerControllerContexts;
113837
+ }
113838
+ });
113563
113839
  Object.defineProperty(exports, "retentionCutoffMs", {
113564
113840
  enumerable: true,
113565
113841
  get: function() {