@mastra/core 1.87.0-alpha.0 → 1.87.0-alpha.10

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 (503) hide show
  1. package/dist/_types/@ai-sdk_anthropic@3.0.137/dist/index.d.ts +2 -2
  2. package/dist/_types/@ai-sdk_google@3.0.140/dist/index.d.ts +2 -2
  3. package/dist/_types/@ai-sdk_openai@3.0.135/dist/index.d.ts +2 -2
  4. package/dist/_types/@ai-sdk_openai@4.0.106/dist/index.d.ts +2034 -0
  5. package/dist/_types/@ai-sdk_openai@4.0.106/package.json +1 -0
  6. package/dist/a2a/index.cjs +1 -1
  7. package/dist/a2a/index.js +1 -1
  8. package/dist/agent/agent.d.ts +3 -1
  9. package/dist/agent/durable/index.cjs +2 -1
  10. package/dist/agent/durable/index.d.ts +1 -0
  11. package/dist/agent/durable/index.js +2 -2
  12. package/dist/agent/durable/run-message-refs.d.ts +3 -2
  13. package/dist/agent/durable/run-registry.d.ts +12 -1
  14. package/dist/agent/durable/types.d.ts +2 -0
  15. package/dist/agent/durable/workflows/finalize-run.d.ts +2 -1
  16. package/dist/agent/index.cjs +5 -4
  17. package/dist/agent/index.d.ts +2 -0
  18. package/dist/agent/index.js +5 -5
  19. package/dist/agent/merge-persona.d.ts +15 -0
  20. package/dist/agent/message-list/adapters/AIV5Adapter.d.ts +15 -1
  21. package/dist/agent/message-list/index.cjs +2 -2
  22. package/dist/agent/message-list/index.js +2 -2
  23. package/dist/agent/message-list/state/types.d.ts +5 -1
  24. package/dist/agent/message-list/types.d.ts +1 -1
  25. package/dist/agent/message-list/utils/provider-compat.d.ts +9 -1
  26. package/dist/agent/thread-stream-runtime.d.ts +3 -1
  27. package/dist/agent-builder/ee/index.cjs +1 -1
  28. package/dist/agent-builder/ee/index.js +1 -1
  29. package/dist/agent-controller/agent-controller.d.ts +6 -0
  30. package/dist/agent-controller/index.cjs +2 -2
  31. package/dist/agent-controller/index.js +2 -2
  32. package/dist/agent-controller/worker-run-binding.d.ts +15 -0
  33. package/dist/{agent-controller-B8LoFdtu.js → agent-controller--gKWI81G.js} +50 -8
  34. package/dist/{agent-controller-DSnFynpa.cjs → agent-controller-BolLBwDm.cjs} +50 -8
  35. package/dist/background-tasks/index.cjs +2 -1
  36. package/dist/background-tasks/index.d.ts +1 -1
  37. package/dist/background-tasks/index.js +1 -1
  38. package/dist/background-tasks/resolve-config.d.ts +30 -1
  39. package/dist/background-tasks/system-prompt.d.ts +8 -2
  40. package/dist/background-tasks/types.d.ts +47 -1
  41. package/dist/{background-tasks-IW7M4iD2.js → background-tasks-CgzXjBfE.js} +156 -33
  42. package/dist/{background-tasks-Ci5h0dhj.cjs → background-tasks-DYtlijQ1.cjs} +167 -32
  43. package/dist/browser/index.cjs +2 -2
  44. package/dist/browser/index.js +2 -2
  45. package/dist/{builder-14Uptu8y.cjs → builder-Dz-g-9CZ.cjs} +2 -2
  46. package/dist/{builder-DI2c2xjy.js → builder-emNPaIaC.js} +2 -2
  47. package/dist/capabilities/302ai.json +202 -202
  48. package/dist/capabilities/abliteratedllm.json +36 -27
  49. package/dist/capabilities/abliteration-ai.json +12 -12
  50. package/dist/capabilities/above.json +14 -14
  51. package/dist/capabilities/adaption.json +9 -9
  52. package/dist/capabilities/adzuki.json +26 -26
  53. package/dist/capabilities/agentrouter.json +4 -4
  54. package/dist/capabilities/agnes.json +2 -2
  55. package/dist/capabilities/ai-router.json +5 -5
  56. package/dist/capabilities/aiand.json +11 -11
  57. package/dist/capabilities/aigrow.json +14 -14
  58. package/dist/capabilities/aimlapi.json +154 -158
  59. package/dist/capabilities/aixy.json +21 -21
  60. package/dist/capabilities/aki-io.json +14 -14
  61. package/dist/capabilities/alibaba-cn.json +107 -101
  62. package/dist/capabilities/alibaba-coding-plan-cn.json +3 -3
  63. package/dist/capabilities/alibaba-coding-plan.json +3 -3
  64. package/dist/capabilities/alibaba-token-plan-cn.json +53 -53
  65. package/dist/capabilities/alibaba-token-plan.json +53 -53
  66. package/dist/capabilities/alibaba.json +99 -65
  67. package/dist/capabilities/ambient.json +14 -7
  68. package/dist/capabilities/amd.json +8 -8
  69. package/dist/capabilities/anthropic.json +47 -47
  70. package/dist/capabilities/anyapi.json +19 -19
  71. package/dist/capabilities/apiko.json +2 -2
  72. package/dist/capabilities/arcee.json +4 -4
  73. package/dist/capabilities/augure.json +5 -5
  74. package/dist/capabilities/auriko.json +22 -22
  75. package/dist/capabilities/bailing.json +3 -3
  76. package/dist/capabilities/baseten.json +25 -25
  77. package/dist/capabilities/bee.json +5 -5
  78. package/dist/capabilities/berget.json +14 -1
  79. package/dist/capabilities/bothub.json +17 -17
  80. package/dist/capabilities/boundless.json +31 -31
  81. package/dist/capabilities/bumo.json +40 -40
  82. package/dist/capabilities/byteplus.json +29 -29
  83. package/dist/capabilities/cheapaimodel.json +9 -9
  84. package/dist/capabilities/cheapest-token.json +30 -30
  85. package/dist/capabilities/chutes.json +9 -9
  86. package/dist/capabilities/claudinio.json +10 -1
  87. package/dist/capabilities/cline-pass.json +40 -40
  88. package/dist/capabilities/cloudcode.json +8 -15
  89. package/dist/capabilities/cloudflare-workers-ai.json +8 -8
  90. package/dist/capabilities/commandcode.json +145 -145
  91. package/dist/capabilities/concentrate.json +272 -289
  92. package/dist/capabilities/cortecs.json +110 -110
  93. package/dist/capabilities/crossmodel.json +182 -182
  94. package/dist/capabilities/crusoe.json +37 -8
  95. package/dist/capabilities/daoxe.json +8 -8
  96. package/dist/capabilities/databricks.json +130 -130
  97. package/dist/capabilities/deepinfra.json +92 -83
  98. package/dist/capabilities/digitalocean.json +112 -112
  99. package/dist/capabilities/dothoosh.json +31 -31
  100. package/dist/capabilities/doubleword.json +22 -22
  101. package/dist/capabilities/edenai.json +898 -1743
  102. package/dist/capabilities/empiriolabs.json +168 -168
  103. package/dist/capabilities/engy.json +19 -19
  104. package/dist/capabilities/entrim.json +2 -2
  105. package/dist/capabilities/evroc.json +12 -12
  106. package/dist/capabilities/ezkielyna.json +11 -11
  107. package/dist/capabilities/fastrouter.json +82 -82
  108. package/dist/capabilities/fireworks-ai.json +125 -64
  109. package/dist/capabilities/fortytwo.json +9 -3
  110. package/dist/capabilities/freemodel.json +19 -19
  111. package/dist/capabilities/friendli.json +8 -8
  112. package/dist/capabilities/frogbot.json +100 -100
  113. package/dist/capabilities/gisoo.json +20 -20
  114. package/dist/capabilities/gmicloud.json +23 -23
  115. package/dist/capabilities/google.json +50 -50
  116. package/dist/capabilities/graphn.json +13 -13
  117. package/dist/capabilities/greenpt.json +35 -35
  118. package/dist/capabilities/groq.json +3 -3
  119. package/dist/capabilities/helicone.json +84 -84
  120. package/dist/capabilities/hetzner.json +35 -3
  121. package/dist/capabilities/hostinger-router.json +15 -15
  122. package/dist/capabilities/hpc-ai.json +12 -12
  123. package/dist/capabilities/huawei-maas.json +14 -14
  124. package/dist/capabilities/hubris.json +33 -33
  125. package/dist/capabilities/huggingface.json +108 -158
  126. package/dist/capabilities/humain.json +2 -2
  127. package/dist/capabilities/hyper.json +20 -28
  128. package/dist/capabilities/impossibl.json +152 -152
  129. package/dist/capabilities/inception.json +2 -2
  130. package/dist/capabilities/inceptron.json +6 -6
  131. package/dist/capabilities/inco.json +5 -5
  132. package/dist/capabilities/infer.json +20 -20
  133. package/dist/capabilities/inferall.json +10 -10
  134. package/dist/capabilities/inference-coop.json +15 -15
  135. package/dist/capabilities/inferenceapis.json +11 -11
  136. package/dist/capabilities/inferris.json +3 -3
  137. package/dist/capabilities/infersia.json +11 -11
  138. package/dist/capabilities/infomaniak.json +2 -2
  139. package/dist/capabilities/iteracompute.json +48 -48
  140. package/dist/capabilities/jad-ai.json +2 -2
  141. package/dist/capabilities/jalapeno.json +12 -12
  142. package/dist/capabilities/jiekou.json +58 -58
  143. package/dist/capabilities/jzstoken.json +53 -54
  144. package/dist/capabilities/keln.json +13 -13
  145. package/dist/capabilities/kenari.json +119 -127
  146. package/dist/capabilities/kilo.json +643 -647
  147. package/dist/capabilities/kimi-code-plan-cn.json +6 -6
  148. package/dist/capabilities/kimi-code-plan-global.json +6 -6
  149. package/dist/capabilities/kitani.json +6 -6
  150. package/dist/capabilities/klavo.json +14 -14
  151. package/dist/capabilities/korouter.json +34 -34
  152. package/dist/capabilities/kunavo.json +7 -7
  153. package/dist/capabilities/liquid.json +11 -11
  154. package/dist/capabilities/lithosai.json +3 -3
  155. package/dist/capabilities/llmgateway-providers.json +949 -880
  156. package/dist/capabilities/llmgateway.json +344 -343
  157. package/dist/capabilities/llmtr.json +29 -29
  158. package/dist/capabilities/longcat.json +2 -2
  159. package/dist/capabilities/lowrouter.json +53 -53
  160. package/dist/capabilities/lyceum.json +17 -9
  161. package/dist/capabilities/melious.json +14 -14
  162. package/dist/capabilities/merge-gateway.json +303 -301
  163. package/dist/capabilities/meta.json +9 -9
  164. package/dist/capabilities/mistral.json +20 -20
  165. package/dist/capabilities/mixlayer.json +2 -2
  166. package/dist/capabilities/modal.json +10 -10
  167. package/dist/capabilities/model-oracle-ai.json +23 -23
  168. package/dist/capabilities/modelis.json +22 -22
  169. package/dist/capabilities/modular.json +31 -9
  170. package/dist/capabilities/moneo.json +13 -13
  171. package/dist/capabilities/moonshotai-cn.json +6 -6
  172. package/dist/capabilities/moonshotai.json +6 -6
  173. package/dist/capabilities/morph.json +15 -15
  174. package/dist/capabilities/munito.json +2 -2
  175. package/dist/capabilities/nan.json +24 -24
  176. package/dist/capabilities/nano-gpt.json +595 -580
  177. package/dist/capabilities/nearai.json +101 -101
  178. package/dist/capabilities/nebius.json +26 -26
  179. package/dist/capabilities/neon.json +125 -125
  180. package/dist/capabilities/neuralwatt.json +43 -43
  181. package/dist/capabilities/nokeep.json +4 -4
  182. package/dist/capabilities/novita-ai.json +123 -123
  183. package/dist/capabilities/nvidia.json +39 -22
  184. package/dist/capabilities/oathbreaker.json +26 -3
  185. package/dist/capabilities/obscurify.json +22 -22
  186. package/dist/capabilities/oci.json +5 -5
  187. package/dist/capabilities/ofox.json +327 -327
  188. package/dist/capabilities/ollama-cloud.json +58 -58
  189. package/dist/capabilities/openai.json +57 -57
  190. package/dist/capabilities/opencode-go.json +90 -90
  191. package/dist/capabilities/openreason.json +5 -5
  192. package/dist/capabilities/openrouter.json +561 -557
  193. package/dist/capabilities/opper.json +30 -30
  194. package/dist/capabilities/orcarouter.json +238 -238
  195. package/dist/capabilities/outerlabs.json +29 -29
  196. package/dist/capabilities/ovhcloud.json +20 -20
  197. package/dist/capabilities/pareto.json +4 -4
  198. package/dist/capabilities/pendra.json +4 -4
  199. package/dist/capabilities/perplexity-agent.json +63 -63
  200. package/dist/capabilities/phala.json +22 -22
  201. package/dist/capabilities/pioneer.json +26 -26
  202. package/dist/capabilities/poe.json +134 -134
  203. package/dist/capabilities/poolside.json +3 -3
  204. package/dist/capabilities/powerspring.json +8 -8
  205. package/dist/capabilities/primalabs.json +8 -8
  206. package/dist/capabilities/prime.json +133 -123
  207. package/dist/capabilities/privatemode-ai.json +13 -13
  208. package/dist/capabilities/proxystacks.json +6 -6
  209. package/dist/capabilities/qiniu-ai.json +15 -15
  210. package/dist/capabilities/refuseless.json +6 -6
  211. package/dist/capabilities/regolo-ai.json +9 -9
  212. package/dist/capabilities/requesty.json +386 -171
  213. package/dist/capabilities/ruapi.json +29 -13
  214. package/dist/capabilities/runcrate.json +8 -8
  215. package/dist/capabilities/runinfra.json +9 -9
  216. package/dist/capabilities/sakana.json +3 -3
  217. package/dist/capabilities/sambanova.json +5 -5
  218. package/dist/capabilities/sandbase.json +17 -17
  219. package/dist/capabilities/sarvam.json +14 -14
  220. package/dist/capabilities/scaleway.json +13 -13
  221. package/dist/capabilities/scnet-token-plan.json +12 -12
  222. package/dist/capabilities/scx-ai.json +22 -22
  223. package/dist/capabilities/sensenova.json +10 -10
  224. package/dist/capabilities/siliconflow-cn.json +49 -49
  225. package/dist/capabilities/siliconflow.json +54 -54
  226. package/dist/capabilities/snowflake-cortex.json +17 -17
  227. package/dist/capabilities/sokkan.json +5 -5
  228. package/dist/capabilities/sparrowcodes.json +23 -23
  229. package/dist/capabilities/standardcompute.json +94 -94
  230. package/dist/capabilities/steadyrouter.json +40 -40
  231. package/dist/capabilities/stepfun-ai-step-plan.json +5 -5
  232. package/dist/capabilities/stepfun-ai.json +5 -5
  233. package/dist/capabilities/stepfun-step-plan.json +5 -5
  234. package/dist/capabilities/stepfun.json +5 -5
  235. package/dist/capabilities/stepping-stone.json +9 -9
  236. package/dist/capabilities/subconscious.json +2 -2
  237. package/dist/capabilities/synthetic.json +10 -10
  238. package/dist/capabilities/synthorai.json +22 -22
  239. package/dist/capabilities/teamorouter.json +23 -23
  240. package/dist/capabilities/teapot-router.json +12 -12
  241. package/dist/capabilities/tencent-token-plan-intl.json +126 -0
  242. package/dist/capabilities/tencent-token-plan.json +35 -35
  243. package/dist/capabilities/tencent-tokenhub.json +51 -36
  244. package/dist/capabilities/tensorx.json +44 -44
  245. package/dist/capabilities/tenstorrent.json +6 -6
  246. package/dist/capabilities/the-grid-ai.json +32 -32
  247. package/dist/capabilities/thinkingmachines.json +48 -48
  248. package/dist/capabilities/tinfoil.json +11 -11
  249. package/dist/capabilities/toapis.json +2 -2
  250. package/dist/capabilities/togetherai.json +40 -40
  251. package/dist/capabilities/tokengo.json +25 -25
  252. package/dist/capabilities/tokenify.json +9 -9
  253. package/dist/capabilities/tokenwatt.json +10 -2
  254. package/dist/capabilities/trustedrouter.json +6 -6
  255. package/dist/capabilities/trustedtokens.json +13 -13
  256. package/dist/capabilities/umans-ai-coding-plan.json +14 -14
  257. package/dist/capabilities/umans-ai.json +12 -12
  258. package/dist/capabilities/uncensuredai.json +2 -2
  259. package/dist/capabilities/unrestricted.json +8 -8
  260. package/dist/capabilities/uplinkswitch.json +18 -18
  261. package/dist/capabilities/upstage.json +6 -6
  262. package/dist/capabilities/vancine.json +18 -18
  263. package/dist/capabilities/vercel.json +590 -587
  264. package/dist/capabilities/vivgrid.json +87 -78
  265. package/dist/capabilities/volcengine-coding-plan.json +32 -23
  266. package/dist/capabilities/volcengine.json +31 -30
  267. package/dist/capabilities/vultr.json +26 -26
  268. package/dist/capabilities/wafer.ai.json +18 -18
  269. package/dist/capabilities/wallaby.json +5 -5
  270. package/dist/capabilities/wally.json +10 -10
  271. package/dist/capabilities/wandb.json +10 -10
  272. package/dist/capabilities/watt.json +26 -26
  273. package/dist/capabilities/xai.json +4 -4
  274. package/dist/capabilities/xiaomi-token-plan-ams.json +2 -2
  275. package/dist/capabilities/xiaomi-token-plan-cn.json +2 -2
  276. package/dist/capabilities/xiaomi-token-plan-sgp.json +2 -2
  277. package/dist/capabilities/xiaomi.json +2 -2
  278. package/dist/capabilities/xpersona.json +13 -13
  279. package/dist/capabilities/xxapi.json +28 -28
  280. package/dist/capabilities/zai-coding-plan.json +18 -18
  281. package/dist/capabilities/zai.json +30 -30
  282. package/dist/capabilities/zenifra.json +30 -30
  283. package/dist/capabilities/zenmux.json +205 -205
  284. package/dist/capabilities/zerogpu.json +11 -11
  285. package/dist/capabilities/zhipuai-coding-plan.json +2 -2
  286. package/dist/capabilities/zhipuai.json +30 -30
  287. package/dist/capabilities/zro.json +4 -4
  288. package/dist/channels/agent-channels.d.ts +29 -0
  289. package/dist/channels/attach-file-tool.d.ts +22 -0
  290. package/dist/channels/index.cjs +11 -2
  291. package/dist/channels/index.d.ts +10 -0
  292. package/dist/channels/index.js +3 -3
  293. package/dist/channels/output-processor.d.ts +12 -0
  294. package/dist/channels/reply-guidance-processor.d.ts +26 -0
  295. package/dist/channels/reply-mode.d.ts +66 -0
  296. package/dist/channels/reply-reminder-processor.d.ts +23 -0
  297. package/dist/channels/reply-tool.d.ts +43 -0
  298. package/dist/channels/state-adapter.d.ts +3 -1
  299. package/dist/channels/stream-helpers.d.ts +17 -0
  300. package/dist/channels/thread-link-processor.d.ts +48 -0
  301. package/dist/channels/thread-lookup.d.ts +16 -0
  302. package/dist/channels/tool-announcement-processor.d.ts +29 -0
  303. package/dist/channels/types.d.ts +25 -0
  304. package/dist/{channels-tVV_de9Q.cjs → channels-BVnDIsZS.cjs} +122 -1
  305. package/dist/{channels-Wh32drgu.js → channels-CndspFXP.js} +99 -2
  306. package/dist/coding-agent/index.cjs +2 -2
  307. package/dist/coding-agent/index.js +2 -2
  308. package/dist/{constants-B9ZDvXZ4.cjs → constants-Bou0hEgY.cjs} +4 -0
  309. package/dist/{constants-BmdTvEYN.js → constants-CFWgIaqA.js} +4 -0
  310. package/dist/datasets/experiment/index.d.ts +1 -1
  311. package/dist/datasets/experiment/item.d.ts +4 -3
  312. package/dist/datasets/experiment/scorer.d.ts +45 -11
  313. package/dist/datasets/index.cjs +3 -2
  314. package/dist/datasets/index.js +3 -3
  315. package/dist/{dist-ByO0vuJJ-BjMue5_p.cjs → dist-CufwpBZM-CwERFaas.cjs} +4 -4
  316. package/dist/{dist-ByO0vuJJ-CCXLBnvJ.js → dist-CufwpBZM-DK14Qe0Z.js} +4 -4
  317. package/dist/docs/SKILL.md +3 -1
  318. package/dist/docs/assets/SOURCE_MAP.json +1070 -1055
  319. package/dist/docs/references/docs-agents-code-mode.md +36 -0
  320. package/dist/docs/references/docs-agents-networks.md +1 -1
  321. package/dist/docs/references/docs-agents-tools.md +6 -0
  322. package/dist/docs/references/docs-auth-simple-auth.md +8 -8
  323. package/dist/docs/references/docs-browser.md +3 -1
  324. package/dist/docs/references/docs-channels.md +43 -0
  325. package/dist/docs/references/docs-evals-custom-scorers.md +1 -1
  326. package/dist/docs/references/docs-evals-experiments.md +13 -3
  327. package/dist/docs/references/docs-harness-background-tasks.md +38 -0
  328. package/dist/docs/references/docs-knowledge-agents-and-tools.md +2 -0
  329. package/dist/docs/references/docs-mastra-platform-observability-overview.md +3 -189
  330. package/dist/docs/references/docs-memory-message-history.md +25 -0
  331. package/dist/docs/references/docs-sandbox-lsp.md +5 -6
  332. package/dist/docs/references/docs-sandbox-overview.md +20 -0
  333. package/dist/docs/references/docs-sandbox-skills.md +2 -0
  334. package/dist/docs/references/docs-signals-sending-signals.md +1 -1
  335. package/dist/docs/references/integrations.md +1 -0
  336. package/dist/docs/references/reference-agent-controller-session.md +1 -1
  337. package/dist/docs/references/reference-agents-durable-agent.md +2 -0
  338. package/dist/docs/references/reference-agents-generate.md +1 -1
  339. package/dist/docs/references/reference-agents-network.md +1 -1
  340. package/dist/docs/references/reference-channels-thread-link.md +67 -0
  341. package/dist/docs/references/reference-configuration.md +8 -8
  342. package/dist/docs/references/reference-core-getWorkspaceById.md +37 -0
  343. package/dist/docs/references/reference-evals-create-scorer.md +5 -5
  344. package/dist/docs/references/reference-evals-run-evals.md +1 -1
  345. package/dist/docs/references/reference-knowledge-knowledge-tools.md +3 -3
  346. package/dist/docs/references/reference-manual-install.md +1 -1
  347. package/dist/docs/references/reference-memory-observational-memory.md +8 -0
  348. package/dist/docs/references/reference-observability-tracing-interfaces.md +10 -6
  349. package/dist/docs/references/reference-processors-processor-interface.md +3 -2
  350. package/dist/docs/references/reference-processors-system-prompt-scrubber.md +1 -1
  351. package/dist/docs/references/reference-processors-tool-search-processor.md +3 -3
  352. package/dist/docs/references/reference-pubsub-base.md +5 -3
  353. package/dist/docs/references/reference-pubsub-caching-pubsub.md +3 -1
  354. package/dist/docs/references/reference-storage-overview.md +1 -1
  355. package/dist/docs/references/reference-storage-retention.md +20 -20
  356. package/dist/docs/references/reference-tools-create-code-mode.md +22 -0
  357. package/dist/docs/references/reference-tools-vector-query-tool.md +8 -0
  358. package/dist/docs/references/reference-voice-overview.md +11 -26
  359. package/dist/docs/references/reference-voice-speech-to-speech.md +1 -1
  360. package/dist/docs/references/reference-voice-voice.listen.md +1 -0
  361. package/dist/docs/references/reference-voice-voice.speak.md +1 -3
  362. package/dist/docs/references/reference-workspace-factory-sandbox.md +8 -7
  363. package/dist/docs/references/reference-workspace-sandbox.md +14 -0
  364. package/dist/docs/references/reference.md +2 -0
  365. package/dist/evals/index.cjs +2 -2
  366. package/dist/evals/index.js +2 -2
  367. package/dist/evals/scoreTraces/index.cjs +2 -2
  368. package/dist/evals/scoreTraces/index.js +2 -2
  369. package/dist/events/index.cjs +1 -1
  370. package/dist/events/index.js +1 -1
  371. package/dist/harness/index.cjs +2 -2
  372. package/dist/harness/index.js +2 -2
  373. package/dist/index.cjs +1 -1
  374. package/dist/index.js +1 -1
  375. package/dist/knowledge/agent-scopes.d.ts +17 -0
  376. package/dist/knowledge/declarations.d.ts +2 -0
  377. package/dist/knowledge/held-scopes-state-processor.d.ts +50 -0
  378. package/dist/knowledge/importers/host.d.ts +7 -1
  379. package/dist/knowledge/importers/runner.d.ts +12 -0
  380. package/dist/knowledge/importers/types.d.ts +4 -0
  381. package/dist/knowledge/index.cjs +209 -38
  382. package/dist/knowledge/index.d.ts +12 -2
  383. package/dist/knowledge/index.js +208 -39
  384. package/dist/knowledge/page-tools.d.ts +23 -0
  385. package/dist/knowledge/pinned-state-processor.d.ts +2 -2
  386. package/dist/knowledge/run.d.ts +5 -0
  387. package/dist/knowledge/scope-runtime.d.ts +6 -0
  388. package/dist/llm/index.cjs +3 -3
  389. package/dist/llm/index.js +3 -3
  390. package/dist/llm/model/base.types.d.ts +3 -1
  391. package/dist/llm/model/mastra-gateway-provider-tools.d.ts +9 -6
  392. package/dist/llm/model/model.d.ts +1 -1
  393. package/dist/llm/model/model.loop.d.ts +1 -1
  394. package/dist/llm/model/model.loop.types.d.ts +3 -1
  395. package/dist/llm/model/provider-options.d.ts +4 -3
  396. package/dist/llm/model/provider-types.generated.d.ts +7091 -7163
  397. package/dist/{llm-BAiOsNAP.cjs → llm-B1semiTO.cjs} +38 -78
  398. package/dist/{llm-B1zaFLYZ.js → llm-CytL7cpw.js} +38 -78
  399. package/dist/loop/index.cjs +2 -2
  400. package/dist/loop/index.js +2 -2
  401. package/dist/{manager-BVX9nVrM.cjs → manager-BwyfS4ha.cjs} +220 -93
  402. package/dist/{manager-ChK9GdGz.js → manager-DnTzA9GL.js} +215 -94
  403. package/dist/mastra/index.cjs +1 -1
  404. package/dist/mastra/index.js +1 -1
  405. package/dist/{mastra-CUGfgEpZ.js → mastra-DTkZPpch.js} +17 -17
  406. package/dist/{mastra-HSmofHEJ.cjs → mastra-Dj35Lj_J.cjs} +17 -17
  407. package/dist/memory/index.cjs +3 -3
  408. package/dist/memory/index.js +3 -3
  409. package/dist/{message-list-KRbg-TnI.js → message-list-BGm1DCiG.js} +231 -130
  410. package/dist/{message-list-Cj0Sq_JP.cjs → message-list-vR3uLAHL.cjs} +351 -250
  411. package/dist/{model-C47BJRtR.js → model-DyQ07rPH.js} +4 -3
  412. package/dist/{model-WahorgzJ.cjs → model-eDfetuno.cjs} +4 -3
  413. package/dist/{netlify-D99AnEhW.cjs → netlify-BC4v7Ufv.cjs} +41377 -30474
  414. package/dist/{netlify-CfDXkuLf.js → netlify-BUvdxfHe.js} +41373 -30476
  415. package/dist/notifications/index.cjs +1 -1
  416. package/dist/notifications/index.js +1 -1
  417. package/dist/observability/types/tracing.d.ts +1 -1
  418. package/dist/processor-provider/index.cjs +1 -1
  419. package/dist/processor-provider/index.js +1 -1
  420. package/dist/processors/index.cjs +2 -2
  421. package/dist/processors/index.js +2 -2
  422. package/dist/processors/processors/tool-search.d.ts +2 -2
  423. package/dist/processors/runner.d.ts +12 -0
  424. package/dist/{provider-registry-CO1NVbO5.cjs → provider-registry-Bn01gq9y.cjs} +22180 -22242
  425. package/dist/{provider-registry-CR385GJ4.js → provider-registry-CP_5SNiw.js} +22181 -22243
  426. package/dist/provider-registry.json +22417 -22539
  427. package/dist/{registry-generator-B3erRqYS.js → registry-generator-CDPyxbzt.js} +1 -1
  428. package/dist/{registry-generator-Cvp34qcB.cjs → registry-generator-CNFKGRFQ.cjs} +1 -1
  429. package/dist/{rehydrate-CJBLrZxs.js → rehydrate-CnGNY2zq.js} +2 -2
  430. package/dist/{rehydrate-Da4hNuaK.cjs → rehydrate-DExpzlNS.cjs} +2 -2
  431. package/dist/relevance/index.cjs +2 -2
  432. package/dist/relevance/index.js +2 -2
  433. package/dist/{run-registry-DdeEBsVW.js → run-registry-BL_kKvFE.js} +1559 -298
  434. package/dist/{run-registry-TOOfO3hT.cjs → run-registry-CibQoN6K.cjs} +1637 -298
  435. package/dist/storage/constants.cjs +1 -1
  436. package/dist/storage/constants.js +1 -1
  437. package/dist/storage/domains/knowledge/base.d.ts +16 -1
  438. package/dist/storage/domains/knowledge/importers-inmemory.d.ts +1 -0
  439. package/dist/storage/domains/knowledge/importers.d.ts +8 -0
  440. package/dist/storage/domains/knowledge/inmemory.d.ts +1 -0
  441. package/dist/storage/domains/knowledge/pages-inmemory.d.ts +5 -1
  442. package/dist/storage/index.cjs +3 -3
  443. package/dist/storage/index.js +3 -3
  444. package/dist/storage/types.d.ts +8 -0
  445. package/dist/stream/index.cjs +2 -2
  446. package/dist/stream/index.js +2 -2
  447. package/dist/{stream-C5PagEDs.js → stream-1DGoEkG2.js} +37 -14
  448. package/dist/{stream-DH7Qgz8l.cjs → stream-D_7tMaJe.cjs} +37 -14
  449. package/dist/test-utils/llm-mock.cjs +1 -1
  450. package/dist/test-utils/llm-mock.js +1 -1
  451. package/dist/{to-prompt-B9eZo2U5.cjs → to-prompt-CG-LyaBY.cjs} +9 -0
  452. package/dist/{to-prompt-BsDtVXrf.js → to-prompt-CMlVGYxC.js} +9 -0
  453. package/dist/tool-loop-agent/index.cjs +1 -1
  454. package/dist/tool-loop-agent/index.js +1 -1
  455. package/dist/{tool-loop-agent-DVYJXlQJ.js → tool-loop-agent-BXya_RYj.js} +4 -4
  456. package/dist/{tool-loop-agent-CJTs4T8b.cjs → tool-loop-agent-CLB1r3X3.cjs} +4 -4
  457. package/dist/tools/code-mode/index.d.ts +2 -0
  458. package/dist/tools/code-mode/log-collector.d.ts +49 -0
  459. package/dist/tools/code-mode/types.d.ts +71 -0
  460. package/dist/tools/index.cjs +3 -1
  461. package/dist/tools/index.js +2 -2
  462. package/dist/{tools-CGF5Ik6j.cjs → tools-BEYxowf0.cjs} +429 -61
  463. package/dist/{tools-CDfyMpzN.js → tools-tPy2FwMI.js} +418 -62
  464. package/dist/{utils-xJi_N6Tx.cjs → utils-B-KOMA_Q.cjs} +7 -6
  465. package/dist/{utils-D8upuTwy.js → utils-C55ZdVaj.js} +7 -6
  466. package/dist/utils.cjs +1 -1
  467. package/dist/utils.js +1 -1
  468. package/dist/{validate-DTkW3Vlp.js → validate-BDfYr72F.js} +1 -1
  469. package/dist/{validate-6eZ8Wssn.cjs → validate-CmZhnsmX.cjs} +1 -1
  470. package/dist/vector/index.cjs +2 -2
  471. package/dist/vector/index.js +2 -2
  472. package/dist/worker/index.cjs +1 -1
  473. package/dist/worker/index.js +1 -1
  474. package/dist/worker/workers/orchestration-worker.d.ts +1 -0
  475. package/dist/{worker-DbcFkKJO.js → worker-BG1rw_dg.js} +5 -5
  476. package/dist/{worker-24ORi-wV.cjs → worker-BoybIUTI.cjs} +10 -4
  477. package/dist/{worker-Dqubrnf8.js → worker-CuK2RaC0.js} +2 -2
  478. package/dist/{worker-BO3u_WjZ.cjs → worker-D2B-x7Le.cjs} +2 -2
  479. package/dist/{workflow-wXOf72fO.js → workflow-Bt09PcH1.js} +3 -3
  480. package/dist/{workflow-D5Fc5ieC.cjs → workflow-CTKqeRXU.cjs} +3 -3
  481. package/dist/workflows/builder/index.cjs +1 -1
  482. package/dist/workflows/builder/index.js +1 -1
  483. package/dist/workflows/evented/index.cjs +1 -1
  484. package/dist/workflows/evented/index.js +1 -1
  485. package/dist/workflows/index.cjs +4 -4
  486. package/dist/workflows/index.js +4 -4
  487. package/dist/workflows/step.d.ts +2 -0
  488. package/dist/workflows/workflow.d.ts +2 -0
  489. package/dist/workspace/index.cjs +3 -1
  490. package/dist/workspace/index.d.ts +1 -1
  491. package/dist/workspace/index.js +2 -2
  492. package/dist/workspace/lsp/manager.d.ts +19 -4
  493. package/dist/workspace/sandbox/mastra-sandbox.d.ts +17 -0
  494. package/dist/workspace/sandbox/teardown-context.d.ts +74 -0
  495. package/dist/workspace/tools/index.d.ts +1 -0
  496. package/dist/workspace/tools/media.d.ts +20 -1
  497. package/dist/workspace/tools/recreate-sandbox.d.ts +24 -0
  498. package/dist/{workspace-X2RHJZU9.cjs → workspace-C8Zo5_qK.cjs} +387 -109
  499. package/dist/{workspace-DY2Nxiyi.js → workspace-DOAil8mG.js} +376 -110
  500. package/package.json +8 -8
  501. package/src/llm/model/provider-types.generated.d.ts +7091 -7163
  502. /package/dist/_types/{@ai-sdk_provider-utils@4.0.66 → @ai-sdk_provider-utils@4.0.67}/dist/index.d.ts +0 -0
  503. /package/dist/_types/{@ai-sdk_provider-utils@4.0.66 → @ai-sdk_provider-utils@4.0.67}/package.json +0 -0
@@ -1,5 +1,5 @@
1
1
  import { t as MastraBase } from "../base-CKLWBhDo.js";
2
- import { Ai as MAX_KNOWLEDGE_PAGE_LINKS, An as buildKnowledgeInstructions, Bi as knowledgePositionBetween, Bo as augmentWithInit, Ci as KnowledgePageHasChildrenError, Cn as compileKnowledgeScopes, Di as MAX_KNOWLEDGE_PAGE_BODY_LINKS, Dn as strongerKnowledgeRole, Ei as MAX_KNOWLEDGE_NOTE_TOKENS, En as knowledgeScopeAddress, Fi as assertKnowledgePageDescriptionWithinBound, Hi as parseKnowledgePageRef, Ii as canonicalKnowledgeName, Li as knowledgeLinkRefKey, Mi as MAX_KNOWLEDGE_PAGE_LIST_LIMIT, Ni as MAX_KNOWLEDGE_PIN_LIST_DEPTH, Oi as MAX_KNOWLEDGE_PAGE_DEPTH, On as decodeKnowledgeScopeId, Pi as assertKnowledgeNoteTextWithinBound, Ri as knowledgePagePath, Si as KnowledgePageDepthError, Sn as KnowledgeDeclarationError, Ti as MAX_KNOWLEDGE_MOVE_PAGES, Tn as knowledgeRunScopes, Ui as KnowledgeInvalidCursorError, Vi as knowledgeScopeReadable, Vo as getStorageSource, _i as assertKnowledgeSchemaCompatible, _n as syncKnowledgePageBodyLinks, _r as knowledgeVisibleScopeKeys, ai as InMemoryKnowledgeStorage, an as addKnowledgeNote, ar as MAX_KNOWLEDGE_SCOPE_TAGS, bi as parseKnowledgeWikilinks, bn as knowledgeReadScopeFor, ci as KnowledgeImportersStorage, cn as removeKnowledgePage, cr as assertKnowledgeRecordTextWithinBound, di as KnowledgeConflictError, dn as KnowledgeSemanticIndex, dr as createKnowledgeNodeCursor, en as PINNED_READ_MEMO_KEY, fi as KnowledgeNotFoundError, fr as expandKnowledgeScope, gi as KnowledgeUnsupportedCapabilityError, gn as reindexKnowledgeLinks, gr as knowledgeSemanticIdempotencyKey, hi as KnowledgeTransactionDeadlineError, hn as refreshKnowledgeLinksTo, hr as knowledgeSemanticDocumentId, in as knowledgeRunPrincipals, ir as MAX_KNOWLEDGE_RECORD_TEXT_LENGTH, ji as MAX_KNOWLEDGE_PAGE_LINK_REF_LENGTH, ki as MAX_KNOWLEDGE_PAGE_DESCRIPTION_TOKENS, kn as encodeKnowledgeScopeId, li as KNOWLEDGE_STORAGE_CONTRACT_VERSION, ln as updateKnowledgeNote, lr as assertKnowledgeScopeWithinCeiling, mi as KnowledgeStorage, mn as knowledgeSubtree, mr as knowledgeScopeKey, nn as buildKnowledgePageTools, oi as KnowledgeImporterBindingConflictError, on as moveKnowledgePage, or as assertKnowledgeCeilingRaised, pi as KnowledgeSchemaResetRequiredError, pn as KnowledgeLinkRefreshIncompleteError, pr as isKnowledgeScopeVisible, rn as KnowledgeRun, rr as MAX_KNOWLEDGE_NODE_DESCRIPTION_LENGTH, si as KnowledgeImporterRunStateError, sn as removeKnowledgeNote, sr as assertKnowledgeDescriptionWithinBound, tn as knowledgeDeliveredPins, ui as KNOWLEDGE_STORAGE_SCHEMA_VERSION, un as upsertKnowledgePage, ur as canonicalizeKnowledgeScope, vi as createKnowledgeUlid, vn as updateKnowledgeLinks, vr as parseKnowledgeNodeCursor, wi as KnowledgePageKeyConflictError, wn as knowledgeMemoryScopes, xi as KnowledgeMoveTooLargeError, xn as knowledgeRoleOn, yi as inspectKnowledgeSchema, yn as knowledgeAccessGrants, zi as knowledgePinDepth } from "../run-registry-DdeEBsVW.js";
2
+ import { $t as PINNED_READ_MEMO_KEY, Ai as KnowledgePageDepthError, An as strongerKnowledgeRole, Bi as MAX_KNOWLEDGE_PAGE_LIST_LIMIT, Ci as KnowledgeTransactionDeadlineError, Cn as knowledgeReadScopeFor, Cr as knowledgeSemanticDocumentId, Di as inspectKnowledgeSchema, Dn as knowledgeMemoryScopes, Ei as createKnowledgeUlid, En as compileKnowledgeScopes, Er as parseKnowledgeNodeCursor, Fi as MAX_KNOWLEDGE_PAGE_BODY_LINKS, Gi as knowledgeLinkRefKey, Hi as assertKnowledgeNoteTextWithinBound, Ii as MAX_KNOWLEDGE_PAGE_DEPTH, Ji as knowledgePositionBetween, Jo as augmentWithInit, Ki as knowledgePagePath, Li as MAX_KNOWLEDGE_PAGE_DESCRIPTION_TOKENS, Mi as KnowledgePageKeyConflictError, Mn as encodeKnowledgeScopeId, Ni as MAX_KNOWLEDGE_MOVE_PAGES, Nn as buildKnowledgeInstructions, Oi as parseKnowledgeWikilinks, On as knowledgeRunScopes, Pi as MAX_KNOWLEDGE_NOTE_TOKENS, Ri as MAX_KNOWLEDGE_PAGE_LINKS, Si as KnowledgeStorage, Sn as knowledgeAccessGrants, Sr as knowledgeScopeKey, Ti as assertKnowledgeSchemaCompatible, Tn as KnowledgeDeclarationError, Tr as knowledgeVisibleScopeKeys, Ui as assertKnowledgePageDescriptionWithinBound, Vi as MAX_KNOWLEDGE_PIN_LIST_DEPTH, Wi as canonicalKnowledgeName, Xi as parseKnowledgePageRef, Yi as knowledgeScopeReadable, Yo as getStorageSource, Zi as KnowledgeInvalidCursorError, _i as KNOWLEDGE_STORAGE_CONTRACT_VERSION, _n as knowledgeSubtree, _r as assertKnowledgeScopeWithinCeiling, an as knowledgeRunPrincipals, bi as KnowledgeNotFoundError, bn as syncKnowledgePageBodyLinks, br as expandKnowledgeScope, cn as addKnowledgeNote, dn as removeKnowledgePage, dr as MAX_KNOWLEDGE_NODE_DESCRIPTION_LENGTH, en as knowledgeDeliveredPins, fn as updateKnowledgeNote, fr as MAX_KNOWLEDGE_RECORD_TEXT_LENGTH, gi as KnowledgeImportersStorage, gn as KnowledgeLinkRefreshIncompleteError, gr as assertKnowledgeRecordTextWithinBound, hi as KnowledgeImporterRunStateError, hr as assertKnowledgeDescriptionWithinBound, in as KnowledgeRunScopesError, ji as KnowledgePageHasChildrenError, jn as decodeKnowledgeScopeId, ki as KnowledgeMoveTooLargeError, kn as knowledgeScopeAddress, ln as moveKnowledgePage, mi as KnowledgeImporterBindingConflictError, mn as KnowledgeSemanticIndex, mr as assertKnowledgeCeilingRaised, nn as heldScopes, on as knowledgeAgentScopes, pi as InMemoryKnowledgeStorage, pn as upsertKnowledgePage, pr as MAX_KNOWLEDGE_SCOPE_TAGS, qi as knowledgePinDepth, rn as KnowledgeRun, sn as knowledgePersonaScopes, tn as buildKnowledgePageTools, un as removeKnowledgeNote, vi as KNOWLEDGE_STORAGE_SCHEMA_VERSION, vn as refreshKnowledgeLinksTo, vr as canonicalizeKnowledgeScope, wi as KnowledgeUnsupportedCapabilityError, wn as knowledgeRoleOn, wr as knowledgeSemanticIdempotencyKey, xi as KnowledgeSchemaResetRequiredError, xn as updateKnowledgeLinks, xr as isKnowledgeScopeVisible, yi as KnowledgeConflictError, yn as reindexKnowledgeLinks, yr as createKnowledgeNodeCursor, zi as MAX_KNOWLEDGE_PAGE_LINK_REF_LENGTH } from "../run-registry-BL_kKvFE.js";
3
3
  import { standardSchemaToJSONSchema, toStandardSchema } from "../schema/index.js";
4
4
  import { i as createStandardSchemaIssuesError } from "../tool-Z3bykc1m.js";
5
5
  import { randomUUID } from "crypto";
@@ -173,6 +173,7 @@ const KNOWLEDGE_IMPORTER_ERROR_CODES = [
173
173
  "credential_missing",
174
174
  "importer_missing_from_deploy",
175
175
  "importer_error",
176
+ "flush_too_large",
176
177
  "stopped",
177
178
  "lease_expired",
178
179
  "deadline_exceeded"
@@ -670,17 +671,22 @@ function sourceError(error) {
670
671
  * @experimental
671
672
  */
672
673
  async function runKnowledgeImport(options) {
673
- const { host, budgetMs = 15e5, graceMs = 18e4, maxPasses = 200, bufferSize = 200, flushAfterMs = 3e4, heartbeatMs = 3e4, maxRetries = 8, hostCallTimeoutMs = 6e4, retryDelayMs = (attempt) => Math.min(250 * 2 ** attempt, 1e4) } = options;
674
+ const { host, budgetMs = 15e5, graceMs = 18e4, maxPasses = 200, bufferSize = 200, maxFlushBytes: ownMaxFlushBytes = Infinity, flushAfterMs = 3e4, heartbeatMs = 3e4, maxRetries = 8, hostCallTimeoutMs = 6e4, retryDelayMs = (attempt) => Math.min(250 * 2 ** attempt, 1e4) } = options;
674
675
  if (!Number.isFinite(flushAfterMs) || flushAfterMs <= 0 || flushAfterMs > 2 ** 31 - 1) throw new TypeError(`flushAfterMs must be a positive number of milliseconds up to 2147483647, got ${flushAfterMs}`);
676
+ if (ownMaxFlushBytes !== Infinity && !(Number.isInteger(ownMaxFlushBytes) && ownMaxFlushBytes > 0)) throw new TypeError(`maxFlushBytes must be a positive whole number of bytes, got ${ownMaxFlushBytes}`);
675
677
  const started = await within(host.startRun(options.bindingId, options.start), hostCallTimeoutMs, () => new KnowledgeImporterHostError("host call timed out"));
676
678
  if (started.status === "skipped") return started;
677
679
  const { runId, generation } = started;
680
+ const hostMaxFlushBytes = started.maxFlushBytes;
681
+ const maxFlushBytes = typeof hostMaxFlushBytes === "number" && Number.isInteger(hostMaxFlushBytes) && hostMaxFlushBytes > 0 ? Math.min(ownMaxFlushBytes, hostMaxFlushBytes) : ownMaxFlushBytes;
678
682
  const startedAt = Date.now();
679
683
  let lastSeq = started.lastSeq;
680
684
  /** A flush sent but never acknowledged: it may have committed. */
681
685
  let unsettledSeq;
682
686
  let state = { ...started.state };
683
687
  let buffer = [];
688
+ /** Encoded bytes of the ops in `buffer`, without the commas between them. */
689
+ let bufferBytes = 0;
684
690
  let stop;
685
691
  /** Armed while the buffer holds ops; sends them once the oldest has waited `flushAfterMs`. */
686
692
  let flushTimer;
@@ -731,6 +737,7 @@ async function runKnowledgeImport(options) {
731
737
  disarm();
732
738
  const ops = buffer;
733
739
  buffer = [];
740
+ bufferBytes = 0;
734
741
  const next = flushing.then(async () => {
735
742
  if (stop) throw stop;
736
743
  if (ops.length === 0 && !staged && !settle) return;
@@ -755,6 +762,11 @@ async function runKnowledgeImport(options) {
755
762
  digest,
756
763
  ...body
757
764
  };
765
+ if (maxFlushBytes !== Infinity && encodedBytes(request) > maxFlushBytes) {
766
+ flushFailure = { code: "flush_too_large" };
767
+ halt("flush");
768
+ throw stop;
769
+ }
758
770
  unsettledSeq = seq;
759
771
  try {
760
772
  const receipt = await withRetries(() => host.flush(request), "mutation");
@@ -779,14 +791,70 @@ async function runKnowledgeImport(options) {
779
791
  flushing = next.catch(() => {});
780
792
  return next;
781
793
  }
782
- const push = async (op) => {
794
+ /** The request around the ops, at the longest `seq` it can have; `ops` empty, no `state`. */
795
+ const envelopeBytes = encodedBytes({
796
+ runId,
797
+ generation,
798
+ seq: Number.MAX_SAFE_INTEGER,
799
+ digest: "0".repeat(64),
800
+ ops: []
801
+ });
802
+ /**
803
+ * The envelope at the shortest `seq` the next request can have. A request's `seq` is only known
804
+ * when it is sent, so splitting plans for the longest; refusing what can never fit uses the
805
+ * shortest, and the request as sent is measured again before it goes.
806
+ */
807
+ const shortestEnvelopeBytes = () => envelopeBytes - String(Number.MAX_SAFE_INTEGER).length + String(lastSeq + 1).length;
808
+ /** Bytes of a request holding the buffer plus `extra` more ops' bytes over `more` ops, and a state. */
809
+ const requestBytes = (extra, more, stateBytes) => {
810
+ const count = buffer.length + more;
811
+ const commas = Math.max(count - 1, 0);
812
+ const state = stateBytes === void 0 ? 0 : 9 + stateBytes;
813
+ return envelopeBytes + bufferBytes + extra + commas + state;
814
+ };
815
+ /**
816
+ * Measures what the importer hands over and returns a copy decoded from that encoding, so a value
817
+ * the importer changes after handing it over can't outgrow its measured size. Anything
818
+ * unencodable or too big ends the run here.
819
+ */
820
+ const measure = (value, alone) => {
821
+ let json;
822
+ let bytes;
823
+ try {
824
+ json = JSON.stringify(value);
825
+ bytes = new TextEncoder().encode(json).byteLength;
826
+ } catch (error) {
827
+ flushFailure = { code: "importer_error" };
828
+ halt("flush");
829
+ throw error;
830
+ }
831
+ if (alone(bytes) > maxFlushBytes) {
832
+ flushFailure = { code: "flush_too_large" };
833
+ halt("flush");
834
+ throw stop;
835
+ }
836
+ return {
837
+ bytes,
838
+ copy: JSON.parse(json)
839
+ };
840
+ };
841
+ const push = async (handed) => {
783
842
  if (stop) throw stop;
843
+ let op = handed;
844
+ let sending;
845
+ if (maxFlushBytes !== Infinity) {
846
+ const { bytes, copy } = measure(handed, (opBytes) => shortestEnvelopeBytes() + opBytes);
847
+ op = copy;
848
+ if (buffer.length > 0 && requestBytes(bytes, 1) > maxFlushBytes) sending = flush();
849
+ bufferBytes += bytes;
850
+ }
784
851
  buffer.push(op);
785
- if (buffer.length >= bufferSize) await flush();
786
- else if (!flushTimer) {
852
+ if (!flushTimer && buffer.length < bufferSize) {
787
853
  flushTimer = setTimeout(() => flush().catch(() => {}), flushAfterMs);
788
854
  flushTimer.unref?.();
789
855
  }
856
+ if (sending) await sending;
857
+ if (buffer.length >= bufferSize) await flush();
790
858
  };
791
859
  const finish = async (request) => {
792
860
  const result = await finishRun(host, {
@@ -850,7 +918,12 @@ async function runKnowledgeImport(options) {
850
918
  get: async (key) => state[key],
851
919
  set: async (key, value) => {
852
920
  if (stop) throw stop;
853
- await flush({ [key]: value });
921
+ const staged = { [key]: value };
922
+ if (maxFlushBytes !== Infinity) {
923
+ const { bytes } = measure(staged, (stateBytes) => shortestEnvelopeBytes() + 9 + stateBytes);
924
+ if (requestBytes(0, 0, bytes) > maxFlushBytes) flush().catch(() => {});
925
+ }
926
+ await flush(staged);
854
927
  }
855
928
  },
856
929
  items: {
@@ -956,6 +1029,9 @@ async function finishRun(host, request, lastSeq, unsettledSeq, withRetries) {
956
1029
  lastSeq
957
1030
  };
958
1031
  }
1032
+ function encodedBytes(value) {
1033
+ return new TextEncoder().encode(JSON.stringify(value)).byteLength;
1034
+ }
959
1035
  // src/knowledge/importers/sink.ts
960
1036
  /**
961
1037
  * Applies one flush's ops to pages and the node map, on a transaction view. Pages are found by id
@@ -1116,7 +1192,8 @@ async function applyKnowledgeImportFlush(input) {
1116
1192
  unchanged: 0,
1117
1193
  moved: 0,
1118
1194
  removed: 0,
1119
- stubbed: 0
1195
+ stubbed: 0,
1196
+ merged: 0
1120
1197
  },
1121
1198
  refused: [],
1122
1199
  changes: [],
@@ -1136,20 +1213,24 @@ async function applyKnowledgeImportFlush(input) {
1136
1213
  const keyPath = async (page) => {
1137
1214
  const keys = [];
1138
1215
  const ids = [];
1139
- let at = page;
1140
- while (at && !at.isScope) {
1216
+ if (page.isScope) return page.id === scope.id ? {
1217
+ keys,
1218
+ ids
1219
+ } : null;
1220
+ const parents = page.parentId ? await storage.getPageParents({
1221
+ parentId: page.parentId,
1222
+ read: "all"
1223
+ }) : [];
1224
+ for (const at of [page, ...parents]) {
1225
+ if (at.isScope) return at.id === scope.id ? {
1226
+ keys,
1227
+ ids
1228
+ } : null;
1141
1229
  if (!live(at) || at.key === void 0) return null;
1142
1230
  keys.unshift(at.key);
1143
1231
  ids.unshift(at.id);
1144
- at = at.parentId ? await storage.getPage({
1145
- id: at.parentId,
1146
- read: "all"
1147
- }) : null;
1148
1232
  }
1149
- return at?.id === scope.id ? {
1150
- keys,
1151
- ids
1152
- } : null;
1233
+ return null;
1153
1234
  };
1154
1235
  const sameKeys = (a, b) => a.length === b.length && a.every((key, i) => key === b[i]);
1155
1236
  /**
@@ -1296,12 +1377,13 @@ async function applyKnowledgeImportFlush(input) {
1296
1377
  };
1297
1378
  };
1298
1379
  const nodeOf = async (sourceId) => sourceId ? importers.getNode(binding.id, sourceId) : null;
1299
- const gone = async (node) => {
1380
+ const stateOf = async (node) => {
1300
1381
  const page = await storage.getPage({
1301
1382
  id: node.pageId,
1302
1383
  read: "all"
1303
1384
  });
1304
- return !page || !!page.deletedAt && !page.mergedInto || live(page) && page.scopeId !== scope.id;
1385
+ if (page?.mergedInto) return "merged";
1386
+ return !page || !!page.deletedAt || page.scopeId !== scope.id ? "gone" : "live";
1305
1387
  };
1306
1388
  /**
1307
1389
  * Drops the node of a page that is gone, so its item is written again as new. Pages that linked to
@@ -1357,11 +1439,10 @@ async function applyKnowledgeImportFlush(input) {
1357
1439
  };
1358
1440
  const liveNodeOf = async (sourceId) => {
1359
1441
  const node = await nodeOf(sourceId);
1360
- return node && !await gone(node) ? node : null;
1442
+ return node && await stateOf(node) === "live" ? node : null;
1361
1443
  };
1362
1444
  const ref = (keys) => `${target.scope}#${keys.join("/")}`;
1363
- const linkLine = async (link) => {
1364
- const node = await importers.getNode(binding.id, link.sourceId);
1445
+ const linkLine = async (link, node) => {
1365
1446
  const page = node ? await storage.getPage({
1366
1447
  id: node.pageId,
1367
1448
  read: "all"
@@ -1372,11 +1453,30 @@ async function applyKnowledgeImportFlush(input) {
1372
1453
  const renderLinks = async (links) => {
1373
1454
  const lines = [];
1374
1455
  const unresolved = [];
1456
+ const getNodes = async (sourceIds) => {
1457
+ if (!sourceIds.length) return [];
1458
+ if (importers.getNodes) return importers.getNodes(binding.id, sourceIds);
1459
+ const nodes = [];
1460
+ for (const sourceId of new Set(sourceIds)) {
1461
+ const node = await importers.getNode(binding.id, sourceId);
1462
+ if (node) nodes.push(node);
1463
+ }
1464
+ return nodes;
1465
+ };
1466
+ const read = async (sourceIds) => new Map((await getNodes(sourceIds)).map((node) => [node.sourceId, node]));
1467
+ const before = await read(links.map((link) => link.sourceId));
1468
+ const rendered = [];
1375
1469
  for (const link of links) {
1376
- const line = await linkLine(link);
1377
- if (line) lines.push(line);
1378
- else unresolved.push(encodeLink(link));
1470
+ const node = before.get(link.sourceId);
1471
+ rendered.push({
1472
+ link,
1473
+ line: await linkLine(link, node),
1474
+ pageId: node?.pageId
1475
+ });
1379
1476
  }
1477
+ const after = await read(rendered.filter((each) => each.line).map((each) => each.link.sourceId));
1478
+ for (const { link, line, pageId } of rendered) if (line && after.get(link.sourceId)?.pageId === pageId) lines.push(line);
1479
+ else unresolved.push(encodeLink(link));
1380
1480
  return {
1381
1481
  section: linkSection(lines),
1382
1482
  unresolved
@@ -1518,12 +1618,17 @@ async function applyKnowledgeImportFlush(input) {
1518
1618
  };
1519
1619
  const write = async (item, hasBody) => {
1520
1620
  let existing = await importers.getNode(binding.id, item.sourceId);
1521
- if (existing && await gone(existing)) {
1621
+ const state = existing ? await stateOf(existing) : null;
1622
+ if (state === "merged") return null;
1623
+ if (existing && state === "gone") {
1522
1624
  await forget(existing);
1523
1625
  existing = null;
1524
1626
  }
1525
- const sourceParent = await liveNodeOf(item.parent);
1526
- const misplaced = !!item.parent && !sourceParent;
1627
+ const parentRecord = await nodeOf(item.parent);
1628
+ const parentState = parentRecord ? await stateOf(parentRecord) : null;
1629
+ const sourceParent = parentState === "live" ? parentRecord : null;
1630
+ const parentMerged = parentState === "merged";
1631
+ const misplaced = !!item.parent && !sourceParent && !parentMerged;
1527
1632
  const parentNode = sourceParent ?? await liveNodeOf(item.fallbackParent);
1528
1633
  const destination = parentNode ? await owned(parentNode.pageId, parentNode.sourceId) : anchor;
1529
1634
  if (existing && destination.page.id === existing.pageId) throw new KnowledgeImportRefusalError("invalid");
@@ -1577,7 +1682,7 @@ async function applyKnowledgeImportFlush(input) {
1577
1682
  const current = await owned(existing.pageId, item.sourceId);
1578
1683
  page = current.page;
1579
1684
  if (existing.stub && existing.adopted && !REMOVED_BODIES.has(page.body ?? "")) await keepBody(page.id, page.body ?? "");
1580
- if (!current.outside && page.parentId !== destination.page.id) {
1685
+ if (!current.outside && !parentMerged && page.parentId !== destination.page.id) {
1581
1686
  if (destination.keys.length > current.keys.length && sameKeys(destination.keys.slice(0, current.keys.length), current.keys)) throw new KnowledgeImportRefusalError("invalid");
1582
1687
  ({page, relinked} = await moveOwned(item.sourceId, page, destination));
1583
1688
  moved = true;
@@ -1657,7 +1762,9 @@ async function applyKnowledgeImportFlush(input) {
1657
1762
  if (op.op === "remove") {
1658
1763
  const node = await importers.getNode(binding.id, sourceId);
1659
1764
  if (!node) return;
1660
- if (await gone(node)) {
1765
+ const state = await stateOf(node);
1766
+ if (state === "merged") return;
1767
+ if (state === "gone") {
1661
1768
  await forget(node);
1662
1769
  result.applied = true;
1663
1770
  return;
@@ -1729,7 +1836,12 @@ async function applyKnowledgeImportFlush(input) {
1729
1836
  result.applied = true;
1730
1837
  return;
1731
1838
  }
1732
- const { page, change, moved, relinked } = await write(op.item, op.op === "upsert");
1839
+ const written = await write(op.item, op.op === "upsert");
1840
+ if (!written) {
1841
+ result.counts.merged++;
1842
+ return;
1843
+ }
1844
+ const { page, change, moved, relinked } = written;
1733
1845
  recordRelinked(relinked, embeds);
1734
1846
  if (change === "unchanged") {
1735
1847
  result.counts.unchanged++;
@@ -1848,12 +1960,24 @@ async function applyKnowledgeImportFlush(input) {
1848
1960
  moved: false,
1849
1961
  relinked: false
1850
1962
  };
1963
+ if (await stateOf(node) === "merged") {
1964
+ await importers.saveNode({
1965
+ ...node,
1966
+ unsettled: false
1967
+ });
1968
+ return {
1969
+ moved: false,
1970
+ relinked: false
1971
+ };
1972
+ }
1851
1973
  const current = await owned(node.pageId, sourceId);
1852
1974
  let { page, keys } = current;
1853
1975
  let moved = false;
1854
1976
  let relinked = false;
1855
- const parent = current.outside ? null : await nodeOf(node.parentSourceId);
1856
- let misplaced = !current.outside && !!node.parentSourceId && !parent;
1977
+ const sourceParent = current.outside ? null : await nodeOf(node.parentSourceId);
1978
+ const parentMerged = !!sourceParent && await stateOf(sourceParent) === "merged";
1979
+ const parent = parentMerged ? null : sourceParent;
1980
+ let misplaced = !current.outside && !!node.parentSourceId && !parent && !parentMerged;
1857
1981
  if (parent && canMove) {
1858
1982
  const destination = await owned(parent.pageId, parent.sourceId);
1859
1983
  if (page.parentId !== destination.page.id) {
@@ -2254,6 +2378,14 @@ function hostError(error) {
2254
2378
  failure.cause = error;
2255
2379
  return failure;
2256
2380
  }
2381
+ /** A committed receipt as replayed; receipts written before the `merged` count existed read it as 0. */
2382
+ const storedReceipt = (receipt) => {
2383
+ const stored = receipt;
2384
+ return {
2385
+ ...stored,
2386
+ merged: stored.merged ?? 0
2387
+ };
2388
+ };
2257
2389
  const receiptCounts = (counts) => ({
2258
2390
  created: counts.created ?? 0,
2259
2391
  updated: counts.updated ?? 0,
@@ -2261,6 +2393,7 @@ const receiptCounts = (counts) => ({
2261
2393
  moved: counts.moved ?? 0,
2262
2394
  removed: counts.removed ?? 0,
2263
2395
  stubbed: counts.stubbed ?? 0,
2396
+ merged: counts.merged ?? 0,
2264
2397
  refused: counts.refused ?? 0
2265
2398
  });
2266
2399
  const runReceipt = (run) => {
@@ -2515,7 +2648,7 @@ function createLocalKnowledgeImporterHost(writer, options) {
2515
2648
  });
2516
2649
  if (replayed) {
2517
2650
  if (replayed.digest !== digest) throw conflict("digest_mismatch", "This seq was committed with other content.");
2518
- return replayed.receipt;
2651
+ return storedReceipt(replayed.receipt);
2519
2652
  }
2520
2653
  const [peek, peekRun] = await Promise.all([rootImporters.readWriterGuard(), rootImporters.getRun(flush.runId)]).catch((error) => {
2521
2654
  throw hostError(error);
@@ -2540,7 +2673,7 @@ function createLocalKnowledgeImporterHost(writer, options) {
2540
2673
  const stored = await importers.getFlush(flush.runId, flush.generation, flush.seq);
2541
2674
  if (stored) {
2542
2675
  if (stored.digest !== digest) throw conflict("digest_mismatch", "This seq was committed with other content.");
2543
- return stored.receipt;
2676
+ return storedReceipt(stored.receipt);
2544
2677
  }
2545
2678
  if (!run || run.status !== "running") throw conflict("run_not_active", "The run is not running.");
2546
2679
  if (run.generation !== flush.generation || guard.generation !== flush.generation) throw conflict("stale_generation", "The run belongs to an older writer generation.");
@@ -3323,6 +3456,19 @@ var KnowledgeScopeRuntime = class {
3323
3456
  };
3324
3457
  for (const address of addresses) await this.#materialize(address, principals, provenance, [], run);
3325
3458
  }
3459
+ /**
3460
+ * The parent address a first write would place a not-yet-created scope under, as `#materialize`
3461
+ * chooses it: a template child's own parent, or the one held `belongsTo` candidate. Undefined when
3462
+ * the scope would stay unlinked.
3463
+ */
3464
+ firstWriteParentAddress(address, principals) {
3465
+ const match = this.compiled.match(address);
3466
+ if (!match) return void 0;
3467
+ if (match.compiled.child) return address.slice(0, address.lastIndexOf("/"));
3468
+ if (!match.compiled.belongsTo) return void 0;
3469
+ const candidates = this.#belongsToCandidates(match, this.#held(principals));
3470
+ return candidates.length === 1 && candidates[0] !== address ? candidates[0] : void 0;
3471
+ }
3326
3472
  /** The run's distinct principals grouped by declaration key, matched once. */
3327
3473
  #held(principals) {
3328
3474
  const held = /* @__PURE__ */ new Map();
@@ -4268,9 +4414,24 @@ var Knowledge = class extends MastraBase {
4268
4414
  write
4269
4415
  };
4270
4416
  }
4271
- /** The run's principals as a stable key; throws when the run has none or holds an undeclared scope. @internal */
4272
- __principalsKey(context) {
4273
- return knowledgeRunPrincipals(this.#runtime, context).sort().join("\n");
4417
+ /** Whether the resolved mint declarations need metadata.persona. @internal */
4418
+ async __needsAgentPersona() {
4419
+ await this.#runtime.resolve();
4420
+ return [...this.#runtime.compiled.declarations.values()].some((declaration) => declaration.declaration.mint === "run-identity" && declaration.pattern.params.some((param) => param === "role" || param === "teamId"));
4421
+ }
4422
+ /**
4423
+ * The run's principals as a stable key, or `undefined` when the run has no Knowledge view (no scopes,
4424
+ * or an undeclared scope). Loads the store's declarations first, so a scope only the store declares
4425
+ * counts; a failure loading them rejects. @internal
4426
+ */
4427
+ async __principalsKey(context) {
4428
+ await this.#runtime.resolve();
4429
+ try {
4430
+ return knowledgeRunPrincipals(this.#runtime, context).sort().join("\n");
4431
+ } catch (error) {
4432
+ if (error instanceof KnowledgeRunScopesError || error instanceof KnowledgeDeclarationError) return void 0;
4433
+ throw error;
4434
+ }
4274
4435
  }
4275
4436
  /**
4276
4437
  * The pinned pages a host-run caller with these principals receives, rendered as an agent run
@@ -4297,6 +4458,14 @@ var Knowledge = class extends MastraBase {
4297
4458
  const run = await KnowledgeRun.start(this.#runtime, await this.getStorage(), context);
4298
4459
  return knowledgeDeliveredPins(run, budget, this.#groups().read);
4299
4460
  }
4461
+ /** The scopes a run holds a role on this turn, with that role. @internal */
4462
+ async __heldScopes(context) {
4463
+ const run = await KnowledgeRun.start(this.#runtime, await this.getStorage(), context);
4464
+ return (await heldScopes(run)).flatMap(({ address, role }) => role ? [{
4465
+ address,
4466
+ role
4467
+ }] : []);
4468
+ }
4300
4469
  /** @internal */
4301
4470
  __registerMastra(_mastra) {}
4302
4471
  /** @internal */
@@ -4413,4 +4582,4 @@ var Knowledge = class extends MastraBase {
4413
4582
  function createKnowledgeImporterHost(knowledge, options) {
4414
4583
  return createLocalKnowledgeImporterHost(hostWriterOf(knowledge), options);
4415
4584
  }
4416
- export { DEFAULT_KNOWLEDGE_PAGE_GRAPH_LIMITS, InMemoryKnowledgeStorage, KNOWLEDGE_IMPORTER_ERROR_CODES, REMOVED_PARENT_BODY as KNOWLEDGE_IMPORT_REMOVED_PARENT_BODY, KNOWLEDGE_STORAGE_CONTRACT_VERSION, KNOWLEDGE_STORAGE_SCHEMA_VERSION, Knowledge, KnowledgeConflictError, KnowledgeDeclarationError, KnowledgeImporter, KnowledgeImporterBase, KnowledgeImporterBindingConflictError, KnowledgeImporterCredentialsError, KnowledgeImporterDefinitionError, KnowledgeImporterHostConflictError, KnowledgeImporterHostError, KnowledgeImporterRunStateError, KnowledgeImporterSettingsError, KnowledgeImporterSourceError, KnowledgeImportersStorage, KnowledgeInvalidCursorError, KnowledgeMoveTooLargeError, KnowledgeNotFoundError, KnowledgePageDepthError, KnowledgePageHasChildrenError, KnowledgePageKeyConflictError, KnowledgeSchemaResetRequiredError, KnowledgeStorage, KnowledgeTransactionDeadlineError, KnowledgeUnsupportedCapabilityError, MAX_KNOWLEDGE_EXPLORER_PAGE_LINKS, MAX_KNOWLEDGE_LINK_COUNT_PAGES, MAX_KNOWLEDGE_MOVE_PAGES, MAX_KNOWLEDGE_NODE_DESCRIPTION_LENGTH, MAX_KNOWLEDGE_NOTE_TOKENS, MAX_KNOWLEDGE_PAGE_BODY_LINKS, MAX_KNOWLEDGE_PAGE_DEPTH, MAX_KNOWLEDGE_PAGE_DESCRIPTION_TOKENS, MAX_KNOWLEDGE_PAGE_LINKS, MAX_KNOWLEDGE_PAGE_LINK_REF_LENGTH, MAX_KNOWLEDGE_PAGE_LIST_LIMIT, MAX_KNOWLEDGE_PIN_LIST_DEPTH, MAX_KNOWLEDGE_RECORD_TEXT_LENGTH, MAX_KNOWLEDGE_SCOPE_TAGS, assertKnowledgeCeilingRaised, assertKnowledgeDescriptionWithinBound, assertKnowledgeNoteTextWithinBound, assertKnowledgePageDescriptionWithinBound, assertKnowledgeRecordTextWithinBound, assertKnowledgeSchemaCompatible, assertKnowledgeScopeWithinCeiling, canonicalJson, canonicalKnowledgeName, canonicalizeKnowledgeScope, createKnowledgeImporterHost, createKnowledgeNodeCursor, createKnowledgeUlid, decodeKnowledgeScopeId, encodeKnowledgeScopeId, expandKnowledgeScope, importerHostConformance, inspectKnowledgeSchema, isKnowledgeScopeVisible, knowledgeImportKey, knowledgeImporterFlushDigest, knowledgeImporterRegistry, knowledgeLinkRefKey, knowledgeMemoryScopes, knowledgePagePath, knowledgePinDepth, knowledgePositionBetween, knowledgeScopeAddress, knowledgeScopeKey, knowledgeScopeReadable, knowledgeSemanticDocumentId, knowledgeSemanticIdempotencyKey, knowledgeVisibleScopeKeys, listKnowledgeTreeChildren, normalizeKnowledgeImporterFinish, parseKnowledgeImporterFlushBody, parseKnowledgeNodeCursor, parseKnowledgePageRef, parseKnowledgeWikilinks, readKnowledgePage, readKnowledgePageActivity, readKnowledgePageGraph, readKnowledgePageLinkCounts, readKnowledgePageLinks, readKnowledgeScopeGrants, runKnowledgeImport, searchKnowledgeExplorerPages };
4585
+ export { DEFAULT_KNOWLEDGE_PAGE_GRAPH_LIMITS, InMemoryKnowledgeStorage, KNOWLEDGE_IMPORTER_ERROR_CODES, REMOVED_PARENT_BODY as KNOWLEDGE_IMPORT_REMOVED_PARENT_BODY, KNOWLEDGE_STORAGE_CONTRACT_VERSION, KNOWLEDGE_STORAGE_SCHEMA_VERSION, Knowledge, KnowledgeConflictError, KnowledgeDeclarationError, KnowledgeImporter, KnowledgeImporterBase, KnowledgeImporterBindingConflictError, KnowledgeImporterCredentialsError, KnowledgeImporterDefinitionError, KnowledgeImporterHostConflictError, KnowledgeImporterHostError, KnowledgeImporterRunStateError, KnowledgeImporterSettingsError, KnowledgeImporterSourceError, KnowledgeImportersStorage, KnowledgeInvalidCursorError, KnowledgeMoveTooLargeError, KnowledgeNotFoundError, KnowledgePageDepthError, KnowledgePageHasChildrenError, KnowledgePageKeyConflictError, KnowledgeSchemaResetRequiredError, KnowledgeStorage, KnowledgeTransactionDeadlineError, KnowledgeUnsupportedCapabilityError, MAX_KNOWLEDGE_EXPLORER_PAGE_LINKS, MAX_KNOWLEDGE_LINK_COUNT_PAGES, MAX_KNOWLEDGE_MOVE_PAGES, MAX_KNOWLEDGE_NODE_DESCRIPTION_LENGTH, MAX_KNOWLEDGE_NOTE_TOKENS, MAX_KNOWLEDGE_PAGE_BODY_LINKS, MAX_KNOWLEDGE_PAGE_DEPTH, MAX_KNOWLEDGE_PAGE_DESCRIPTION_TOKENS, MAX_KNOWLEDGE_PAGE_LINKS, MAX_KNOWLEDGE_PAGE_LINK_REF_LENGTH, MAX_KNOWLEDGE_PAGE_LIST_LIMIT, MAX_KNOWLEDGE_PIN_LIST_DEPTH, MAX_KNOWLEDGE_RECORD_TEXT_LENGTH, MAX_KNOWLEDGE_SCOPE_TAGS, assertKnowledgeCeilingRaised, assertKnowledgeDescriptionWithinBound, assertKnowledgeNoteTextWithinBound, assertKnowledgePageDescriptionWithinBound, assertKnowledgeRecordTextWithinBound, assertKnowledgeSchemaCompatible, assertKnowledgeScopeWithinCeiling, canonicalJson, canonicalKnowledgeName, canonicalizeKnowledgeScope, createKnowledgeImporterHost, createKnowledgeNodeCursor, createKnowledgeUlid, decodeKnowledgeScopeId, encodeKnowledgeScopeId, expandKnowledgeScope, importerHostConformance, inspectKnowledgeSchema, isKnowledgeScopeVisible, knowledgeAgentScopes, knowledgeImportKey, knowledgeImporterFlushDigest, knowledgeImporterRegistry, knowledgeLinkRefKey, knowledgeMemoryScopes, knowledgePagePath, knowledgePersonaScopes, knowledgePinDepth, knowledgePositionBetween, knowledgeScopeAddress, knowledgeScopeKey, knowledgeScopeReadable, knowledgeSemanticDocumentId, knowledgeSemanticIdempotencyKey, knowledgeVisibleScopeKeys, listKnowledgeTreeChildren, normalizeKnowledgeImporterFinish, parseKnowledgeImporterFlushBody, parseKnowledgeNodeCursor, parseKnowledgePageRef, parseKnowledgeWikilinks, readKnowledgePage, readKnowledgePageActivity, readKnowledgePageGraph, readKnowledgePageLinkCounts, readKnowledgePageLinks, readKnowledgeScopeGrants, runKnowledgeImport, searchKnowledgeExplorerPages };
@@ -1,5 +1,6 @@
1
1
  import type { KnowledgePage, KnowledgeStorage } from '../storage/domains/knowledge/index.js';
2
2
  import type { ToolAction } from '../tools/index.js';
3
+ import type { KnowledgeRole } from './declarations.js';
3
4
  import { KnowledgeRun } from './run.js';
4
5
  import type { KnowledgeScopeRuntime } from './scope-runtime.js';
5
6
  import type { KnowledgeSemanticIndex } from './semantic.js';
@@ -24,6 +25,22 @@ export interface KnowledgePageToolGroups {
24
25
  pins: boolean;
25
26
  }
26
27
  type Tools = Record<string, ToolAction<any, any, any>>;
28
+ /** What a run can do in a scope it holds: contributors and up can write, viewers only read. */
29
+ type HeldScopeAccess = 'write' | 'read' | 'none';
30
+ /** A scope the run holds, whether or not it has a scope page yet. */
31
+ type HeldScope = {
32
+ address: string;
33
+ page?: KnowledgePage;
34
+ role: KnowledgeRole | null;
35
+ can: HeldScopeAccess;
36
+ };
37
+ /**
38
+ * Every scope the run holds, in principal order, with its role and what it can do there. A held scope
39
+ * gets its page on the first write, so before that its role comes from the declarations and the parent
40
+ * that write would link it under: without it a model sees no scopes on its first turn and concludes it
41
+ * has nowhere to write. A stored scope it can't read keeps only its address.
42
+ */
43
+ export declare function heldScopes(run: KnowledgeRun): Promise<HeldScope[]>;
27
44
  /** One entry of a `knowledge_list` result. */
28
45
  export interface ListEntry {
29
46
  ref: string;
@@ -34,6 +51,12 @@ export interface ListEntry {
34
51
  /** Readable child pages, plus readable child scopes for a scope. */
35
52
  children: number;
36
53
  scope?: true;
54
+ /** Held scopes only (a listing without `from`): the run's role there, if any. */
55
+ role?: KnowledgeRole;
56
+ /** Held scopes only: what the run can do there. */
57
+ can?: HeldScopeAccess;
58
+ /** Held scopes only: no page there this run can read yet. */
59
+ empty?: true;
37
60
  }
38
61
  /** What {@link listKnowledgeTree} found: the entries in tree order, and where the listing stopped. */
39
62
  export interface KnowledgeTreeListing {
@@ -34,8 +34,8 @@ export declare function applyPinOps(pins: PinEntry[], ops: PinDeltaOp[]): PinEnt
34
34
  export declare function effectivePriorPins(args: ComputeStateSignalArgs): PinEntry[];
35
35
  export declare function diffPins(prior: PinEntry[], current: PinEntry[]): PinDeltaOp[];
36
36
  export interface PinnedStateProcessorDeps {
37
- /** A key identifying the run's principals, for the per-turn memo. Throws when the run has no Knowledge view. */
38
- principalsKey(context: KnowledgeRunContext): string;
37
+ /** A key identifying the run's principals, for the per-turn memo; `undefined` when the run has no Knowledge view, so it gets no pins. */
38
+ principalsKey(context: KnowledgeRunContext): Promise<string | undefined> | string | undefined;
39
39
  /** The pins the run receives. */
40
40
  readPins(context: KnowledgeRunContext): Promise<PinEntry[]>;
41
41
  /** Whether the agent has `knowledge_search`, `knowledge_read` and `knowledge_list`; when `false` the guidance, the overflow suffix and pin descriptions name no read tool. Defaults to `true`. */
@@ -7,6 +7,7 @@ export type KnowledgeRunContext = {
7
7
  threadId?: string;
8
8
  resourceId?: string;
9
9
  agentId?: string;
10
+ persona?: unknown;
10
11
  };
11
12
  requestContext?: {
12
13
  get(key: string): unknown;
@@ -16,6 +17,10 @@ export type KnowledgeRunContext = {
16
17
  export declare class KnowledgeNotFoundError extends Error {
17
18
  constructor(ref: string, closeMatches?: string[]);
18
19
  }
20
+ /** A run with no scopes and no Memory identity: it has no Knowledge view. @internal */
21
+ export declare class KnowledgeRunScopesError extends Error {
22
+ constructor();
23
+ }
19
24
  /**
20
25
  * One call's view of Knowledge: the run's principals, its read scope and its provenance. Built per
21
26
  * tool call from the run's own scopes, so access always follows the current declarations.
@@ -77,5 +77,11 @@ export declare class KnowledgeScopeRuntime {
77
77
  * `belongsTo` link, has its child scopes and declares no template pages; warnings fire as before.
78
78
  */
79
79
  materializeScopes(addresses: readonly string[], principals: readonly string[], provenance: KnowledgeProvenance): Promise<void>;
80
+ /**
81
+ * The parent address a first write would place a not-yet-created scope under, as `#materialize`
82
+ * chooses it: a template child's own parent, or the one held `belongsTo` candidate. Undefined when
83
+ * the scope would stay unlinked.
84
+ */
85
+ firstWriteParentAddress(address: string, principals: readonly string[]): string | undefined;
80
86
  }
81
87
  //# sourceMappingURL=scope-runtime.d.ts.map
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_llm = require("../llm-BAiOsNAP.cjs");
3
- const require_netlify = require("../netlify-D99AnEhW.cjs");
4
- const require_provider_registry = require("../provider-registry-CO1NVbO5.cjs");
2
+ const require_llm = require("../llm-B1semiTO.cjs");
3
+ const require_netlify = require("../netlify-BC4v7Ufv.cjs");
4
+ const require_provider_registry = require("../provider-registry-Bn01gq9y.cjs");
5
5
  exports.AzureOpenAIGateway = require_llm.AzureOpenAIGateway;
6
6
  exports.EMBEDDING_MODELS = require_llm.EMBEDDING_MODELS;
7
7
  exports.GATEWAY_AUTH_HEADER = require_netlify.GATEWAY_AUTH_HEADER;
package/dist/llm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as ModelRouterLanguageModel, c as AzureOpenAIGateway, i as resolveModelConfig, l as defaultGateways, n as ModelRouterEmbeddingModel, r as resolveModelAuth, t as EMBEDDING_MODELS } from "../llm-B1zaFLYZ.js";
2
- import { c as GATEWAY_AUTH_HEADER, f as findGatewayForModel, p as getGatewayId, r as ModelsDevGateway, t as NetlifyGateway, v as MastraModelGateway } from "../netlify-CfDXkuLf.js";
3
- import { c as modelSupportsStructuredOutput, f as MastraGateway, i as getProviderConfig, l as modelSupportsTemperature, n as PROVIDER_REGISTRY, r as getModelReasoningOptions, s as modelSupportsAttachments, t as GatewayRegistry, u as parseModelString } from "../provider-registry-CR385GJ4.js";
1
+ import { a as ModelRouterLanguageModel, c as AzureOpenAIGateway, i as resolveModelConfig, l as defaultGateways, n as ModelRouterEmbeddingModel, r as resolveModelAuth, t as EMBEDDING_MODELS } from "../llm-CytL7cpw.js";
2
+ import { l as GATEWAY_AUTH_HEADER, m as getGatewayId, p as findGatewayForModel, r as ModelsDevGateway, t as NetlifyGateway, y as MastraModelGateway } from "../netlify-BUvdxfHe.js";
3
+ import { c as modelSupportsStructuredOutput, f as MastraGateway, i as getProviderConfig, l as modelSupportsTemperature, n as PROVIDER_REGISTRY, r as getModelReasoningOptions, s as modelSupportsAttachments, t as GatewayRegistry, u as parseModelString } from "../provider-registry-CP_5SNiw.js";
4
4
  export { AzureOpenAIGateway, EMBEDDING_MODELS, GATEWAY_AUTH_HEADER, GatewayRegistry, MastraGateway, MastraModelGateway, ModelRouterEmbeddingModel, ModelRouterLanguageModel, ModelsDevGateway, NetlifyGateway, PROVIDER_REGISTRY, defaultGateways, findGatewayForModel, getGatewayId, getModelReasoningOptions, getProviderConfig, modelSupportsAttachments, modelSupportsStructuredOutput, modelSupportsTemperature, parseModelString, resolveModelAuth, resolveModelConfig };
@@ -2,7 +2,7 @@ import type { UIMessage, CoreMessage, GenerateTextResult as OriginalGenerateText
2
2
  import type { JSONSchema7 } from 'json-schema';
3
3
  import type { MessageList } from '../../agent/types.js';
4
4
  import type { ScorerRunInputForAgent, ScorerRunOutputForAgent } from '../../evals/index.js';
5
- import type { ObservabilityContext, TracingProperties } from '../../observability/index.js';
5
+ import type { ModelGenerationAttributes, ObservabilityContext, TracingProperties } from '../../observability/index.js';
6
6
  import type { OutputProcessorOrWorkflow } from '../../processors/index.js';
7
7
  import type { RequestContext } from '../../request-context/index.js';
8
8
  import type { ZodSchema } from '../../schema/index.js';
@@ -59,6 +59,8 @@ type GenerateTextOptions<Tools extends ToolSet, Output extends ZodSchema | JSONS
59
59
  export type GenerateTextWithMessagesArgs<Tools extends ToolSet, Output extends ZodSchema | JSONSchema7 | undefined = undefined> = {
60
60
  messages: UIMessage[] | CoreMessage[];
61
61
  output?: never;
62
+ /** What this call produces, when it is not part of the conversation. Recorded on the MODEL_GENERATION span. */
63
+ resultType?: ModelGenerationAttributes['resultType'];
62
64
  } & GenerateTextOptions<Tools, Output>;
63
65
  export type GenerateTextResult<Tools extends ToolSet, Output extends ZodSchema | JSONSchema7 | undefined = undefined> = Omit<OriginalGenerateTextResult<Tools, inferOutput<Output>>, 'experimental_output'> & {
64
66
  object?: Output extends undefined ? never : inferOutput<Output>;
@@ -1,8 +1,8 @@
1
- import type { LanguageModelV2CallOptions } from '../../_types/@ai-sdk_provider@2.0.5/dist/index.js';
2
- /** True for the gateway's OpenRouter chat models, false for its native Anthropic OAuth models. */
3
- export declare function isOpenRouterModel(model: {
4
- provider?: unknown;
5
- }): boolean;
1
+ type GatewayTool = {
2
+ type: string;
3
+ id?: string;
4
+ args?: Record<string, unknown>;
5
+ };
6
6
  /**
7
7
  * The Mastra gateway's chat endpoint only runs `openrouter:*` server tools. Another provider's
8
8
  * native tool is rejected with a 400 (OpenAI, xAI models) or dropped without an error (Anthropic,
@@ -11,5 +11,8 @@ export declare function isOpenRouterModel(model: {
11
11
  * A native web search tool with no arguments is swapped for the gateway's web search, which works
12
12
  * for every tool-calling model. Any other native tool fails here with an actionable message.
13
13
  */
14
- export declare function prepareToolsForMastraGateway(options: LanguageModelV2CallOptions, routerId: string): LanguageModelV2CallOptions;
14
+ export declare function prepareToolsForMastraGateway<T extends {
15
+ tools?: GatewayTool[];
16
+ }>(options: T, routerId: string): T;
17
+ export {};
15
18
  //# sourceMappingURL=mastra-gateway-provider-tools.d.ts.map
@@ -19,7 +19,7 @@ export declare class MastraLLMV1 extends MastraBase {
19
19
  getModelId(): string;
20
20
  getModel(): LanguageModel;
21
21
  private _applySchemaCompat;
22
- __text<Tools extends ToolSet, Z extends ZodSchema | JSONSchema7 | undefined>({ runId, messages, maxSteps, tools, temperature, toolChoice, onStepFinish, experimental_output, threadId, resourceId, requestContext, ...rest }: GenerateTextWithMessagesArgs<Tools, Z>): Promise<GenerateTextResult<Tools, Z>>;
22
+ __text<Tools extends ToolSet, Z extends ZodSchema | JSONSchema7 | undefined>({ runId, messages, maxSteps, tools, temperature, toolChoice, onStepFinish, experimental_output, threadId, resourceId, requestContext, resultType, ...rest }: GenerateTextWithMessagesArgs<Tools, Z>): Promise<GenerateTextResult<Tools, Z>>;
23
23
  __textObject<Z extends ZodSchema | JSONSchema7>({ messages, structuredOutput, runId, threadId, resourceId, requestContext, ...rest }: GenerateObjectWithMessagesArgs<Z>): Promise<GenerateObjectResult<Z>>;
24
24
  __stream<Tools extends ToolSet, Z extends ZodSchema | JSONSchema7 | undefined = undefined>({ messages, onStepFinish, onFinish, maxSteps, tools, runId, temperature, toolChoice, experimental_output, threadId, resourceId, requestContext, ...rest }: StreamTextWithMessagesArgs<Tools, Z>): StreamTextResult<Tools, Z>;
25
25
  __streamObject<T extends ZodSchema | JSONSchema7>({ messages, runId, requestContext, threadId, resourceId, onFinish, structuredOutput, ...rest }: StreamObjectWithMessagesArgs<T>): StreamObjectResult<T>;