@mastra/core 1.86.0 → 1.87.0-alpha.0

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/agent/durable/constants.d.ts +2 -0
  2. package/dist/agent/durable/evented-execution.d.ts +7 -0
  3. package/dist/agent/durable/execution-engine.d.ts +1 -0
  4. package/dist/agent/durable/execution-fence.d.ts +2 -0
  5. package/dist/agent/durable/index.cjs +3 -1
  6. package/dist/agent/durable/index.d.ts +1 -1
  7. package/dist/agent/durable/index.js +2 -2
  8. package/dist/agent/durable/run-registry.d.ts +2 -0
  9. package/dist/agent/durable/segment-spans.d.ts +54 -1
  10. package/dist/agent/durable/types.d.ts +10 -0
  11. package/dist/agent/durable/workflows/durable-loop-builder.d.ts +57 -2
  12. package/dist/agent/durable/workflows/finalize-run.d.ts +2 -0
  13. package/dist/agent/durable/workflows/shared/index.d.ts +1 -1
  14. package/dist/agent/durable/workflows/shared/reported-cost.d.ts +7 -0
  15. package/dist/agent/durable/workflows/shared/schemas.d.ts +16 -1
  16. package/dist/agent/durable/workflows/shared/tool-call-concurrency.d.ts +6 -0
  17. package/dist/agent/durable/workflows/steps/llm-execution.d.ts +5 -0
  18. package/dist/agent/durable/workflows/steps/llm-mapping.d.ts +6 -0
  19. package/dist/agent/durable/workflows/steps/tool-call.d.ts +20 -0
  20. package/dist/agent/index.cjs +2 -2
  21. package/dist/agent/index.js +2 -2
  22. package/dist/agent/request-context-snapshot.d.ts +3 -2
  23. package/dist/agent/streams/run-records.d.ts +9 -1
  24. package/dist/agent-builder/ee/index.cjs +1 -1
  25. package/dist/agent-builder/ee/index.js +1 -1
  26. package/dist/agent-controller/index.cjs +1 -1
  27. package/dist/agent-controller/index.js +1 -1
  28. package/dist/agent-controller/session-run-engine.d.ts +5 -2
  29. package/dist/agent-controller/session.d.ts +2 -0
  30. package/dist/agent-controller/types.d.ts +23 -0
  31. package/dist/{agent-controller-D5EKeS1H.js → agent-controller-B8LoFdtu.js} +43 -13
  32. package/dist/{agent-controller-D_5Dc8d3.cjs → agent-controller-DSnFynpa.cjs} +43 -13
  33. package/dist/background-tasks/index.cjs +1 -1
  34. package/dist/background-tasks/index.js +1 -1
  35. package/dist/background-tasks/manager.d.ts +4 -1
  36. package/dist/{background-tasks-BVxb0VGV.cjs → background-tasks-Ci5h0dhj.cjs} +139 -51
  37. package/dist/{background-tasks-idnlMbqD.js → background-tasks-IW7M4iD2.js} +139 -51
  38. package/dist/browser/index.cjs +1 -1
  39. package/dist/browser/index.js +1 -1
  40. package/dist/{builder-CBWoYNck.cjs → builder-14Uptu8y.cjs} +2 -2
  41. package/dist/{builder-Cuq-j2w3.js → builder-DI2c2xjy.js} +2 -2
  42. package/dist/cache/base.d.ts +40 -10
  43. package/dist/cache/index.cjs +1 -1
  44. package/dist/cache/index.js +1 -1
  45. package/dist/capabilities/302ai.json +200 -200
  46. package/dist/capabilities/abliteratedllm.json +34 -34
  47. package/dist/capabilities/abliteration-ai.json +8 -8
  48. package/dist/capabilities/above.json +24 -24
  49. package/dist/capabilities/adaption.json +15 -15
  50. package/dist/capabilities/adzuki.json +29 -29
  51. package/dist/capabilities/agentrouter.json +12 -12
  52. package/dist/capabilities/agnes.json +2 -2
  53. package/dist/capabilities/ai-router.json +5 -5
  54. package/dist/capabilities/aiand.json +25 -25
  55. package/dist/capabilities/aigrow.json +13 -13
  56. package/dist/capabilities/aimlapi.json +149 -152
  57. package/dist/capabilities/aixy.json +20 -20
  58. package/dist/capabilities/aki-io.json +10 -10
  59. package/dist/capabilities/alibaba-cn.json +85 -85
  60. package/dist/capabilities/alibaba-coding-plan-cn.json +5 -5
  61. package/dist/capabilities/alibaba-coding-plan.json +5 -5
  62. package/dist/capabilities/alibaba-token-plan-cn.json +44 -44
  63. package/dist/capabilities/alibaba-token-plan.json +47 -47
  64. package/dist/capabilities/alibaba.json +62 -62
  65. package/dist/capabilities/ambient.json +14 -14
  66. package/dist/capabilities/amd.json +8 -8
  67. package/dist/capabilities/anthropic.json +39 -39
  68. package/dist/capabilities/anyapi.json +13 -13
  69. package/dist/capabilities/apiko.json +5 -5
  70. package/dist/capabilities/arcee.json +11 -11
  71. package/dist/capabilities/augure.json +4 -4
  72. package/dist/capabilities/auriko.json +21 -21
  73. package/dist/capabilities/bailing.json +4 -4
  74. package/dist/capabilities/baseten.json +33 -33
  75. package/dist/capabilities/bee.json +5 -5
  76. package/dist/capabilities/berget.json +4 -4
  77. package/dist/capabilities/bothub.json +16 -16
  78. package/dist/capabilities/boundless.json +37 -37
  79. package/dist/capabilities/bumo.json +48 -48
  80. package/dist/capabilities/byteplus.json +25 -25
  81. package/dist/capabilities/cheapaimodel.json +5 -5
  82. package/dist/capabilities/cheapest-token.json +28 -28
  83. package/dist/capabilities/chutes.json +11 -14
  84. package/dist/capabilities/cline-pass.json +41 -41
  85. package/dist/capabilities/cloudcode.json +9 -9
  86. package/dist/capabilities/cloudferro-sherlock.json +4 -4
  87. package/dist/capabilities/cloudflare-workers-ai.json +18 -79
  88. package/dist/capabilities/commandcode.json +155 -155
  89. package/dist/capabilities/concentrate.json +279 -270
  90. package/dist/capabilities/cortecs.json +100 -100
  91. package/dist/capabilities/crossmodel.json +178 -178
  92. package/dist/capabilities/crusoe.json +9 -9
  93. package/dist/capabilities/daoxe.json +9 -9
  94. package/dist/capabilities/databricks.json +137 -137
  95. package/dist/capabilities/deepinfra.json +124 -61
  96. package/dist/capabilities/deepseek.json +3 -3
  97. package/dist/capabilities/digitalocean.json +113 -113
  98. package/dist/capabilities/dothoosh.json +32 -32
  99. package/dist/capabilities/doubleword.json +26 -26
  100. package/dist/capabilities/edenai.json +448 -473
  101. package/dist/capabilities/empiriolabs.json +163 -165
  102. package/dist/capabilities/engy.json +19 -19
  103. package/dist/capabilities/entrim.json +6 -6
  104. package/dist/capabilities/evroc.json +16 -16
  105. package/dist/capabilities/ezkielyna.json +12 -12
  106. package/dist/capabilities/fastrouter.json +73 -73
  107. package/dist/capabilities/fireworks-ai.json +83 -62
  108. package/dist/capabilities/freemodel.json +15 -15
  109. package/dist/capabilities/friendli.json +2 -2
  110. package/dist/capabilities/frogbot.json +99 -99
  111. package/dist/capabilities/gisoo.json +17 -17
  112. package/dist/capabilities/gmicloud.json +14 -14
  113. package/dist/capabilities/google.json +57 -57
  114. package/dist/capabilities/graphn.json +9 -9
  115. package/dist/capabilities/greenpt.json +36 -36
  116. package/dist/capabilities/groq.json +8 -8
  117. package/dist/capabilities/helicone.json +82 -82
  118. package/dist/capabilities/hopper.json +2 -2
  119. package/dist/capabilities/hostinger-router.json +10 -10
  120. package/dist/capabilities/hpc-ai.json +14 -14
  121. package/dist/capabilities/huawei-maas.json +16 -16
  122. package/dist/capabilities/hubris.json +29 -29
  123. package/dist/capabilities/huggingface.json +94 -84
  124. package/dist/capabilities/humain.json +2 -2
  125. package/dist/capabilities/hyper.json +23 -23
  126. package/dist/capabilities/impossibl.json +136 -136
  127. package/dist/capabilities/inception.json +2 -2
  128. package/dist/capabilities/inceptron.json +8 -8
  129. package/dist/capabilities/inco.json +2 -2
  130. package/dist/capabilities/infer.json +14 -14
  131. package/dist/capabilities/inferall.json +7 -7
  132. package/dist/capabilities/inference-coop.json +3 -3
  133. package/dist/capabilities/inferenceapis.json +20 -20
  134. package/dist/capabilities/inferris.json +3 -3
  135. package/dist/capabilities/infersia.json +8 -8
  136. package/dist/capabilities/inferx.json +3 -3
  137. package/dist/capabilities/infomaniak.json +2 -2
  138. package/dist/capabilities/io-net.json +4 -4
  139. package/dist/capabilities/isoquant.json +4 -4
  140. package/dist/capabilities/iteracompute.json +61 -61
  141. package/dist/capabilities/jalapeno.json +12 -12
  142. package/dist/capabilities/jiekou.json +60 -60
  143. package/dist/capabilities/joingonka.json +4 -4
  144. package/dist/capabilities/jzstoken.json +55 -55
  145. package/dist/capabilities/keln.json +25 -25
  146. package/dist/capabilities/kenari.json +122 -122
  147. package/dist/capabilities/kilo.json +633 -617
  148. package/dist/capabilities/kimi-code-plan-cn.json +6 -6
  149. package/dist/capabilities/kimi-code-plan-global.json +6 -6
  150. package/dist/capabilities/kitani.json +6 -6
  151. package/dist/capabilities/klavo.json +20 -20
  152. package/dist/capabilities/korouter.json +32 -32
  153. package/dist/capabilities/kunavo.json +9 -9
  154. package/dist/capabilities/liquid.json +12 -12
  155. package/dist/capabilities/lithosai.json +3 -3
  156. package/dist/capabilities/llmgateway-providers.json +912 -903
  157. package/dist/capabilities/llmgateway.json +346 -338
  158. package/dist/capabilities/llmtr.json +30 -30
  159. package/dist/capabilities/logits.json +2 -2
  160. package/dist/capabilities/lowrouter.json +53 -53
  161. package/dist/capabilities/lyceum.json +10 -10
  162. package/dist/capabilities/melious.json +12 -12
  163. package/dist/capabilities/merge-gateway.json +276 -276
  164. package/dist/capabilities/meta.json +10 -10
  165. package/dist/capabilities/mistral.json +21 -21
  166. package/dist/capabilities/mixlayer.json +2 -2
  167. package/dist/capabilities/modal.json +6 -6
  168. package/dist/capabilities/model-oracle-ai.json +25 -25
  169. package/dist/capabilities/modelis.json +15 -15
  170. package/dist/capabilities/modelscope.json +2 -2
  171. package/dist/capabilities/modular.json +6 -6
  172. package/dist/capabilities/moneo.json +14 -14
  173. package/dist/capabilities/moonshotai-cn.json +7 -7
  174. package/dist/capabilities/moonshotai.json +7 -7
  175. package/dist/capabilities/morph.json +16 -16
  176. package/dist/capabilities/munito-eu.json +6 -6
  177. package/dist/capabilities/munito.json +10 -10
  178. package/dist/capabilities/nan.json +24 -24
  179. package/dist/capabilities/nano-gpt.json +612 -579
  180. package/dist/capabilities/nearai.json +97 -97
  181. package/dist/capabilities/nebius.json +32 -32
  182. package/dist/capabilities/neon.json +131 -131
  183. package/dist/capabilities/neuralwatt.json +43 -43
  184. package/dist/capabilities/nokeep.json +4 -4
  185. package/dist/capabilities/novita-ai.json +148 -148
  186. package/dist/capabilities/nvidia.json +17 -49
  187. package/dist/capabilities/obscurify.json +26 -26
  188. package/dist/capabilities/oci.json +16 -7
  189. package/dist/capabilities/ofox.json +344 -344
  190. package/dist/capabilities/ollama-cloud.json +56 -56
  191. package/dist/capabilities/openai.json +81 -49
  192. package/dist/capabilities/opencode-go.json +90 -90
  193. package/dist/capabilities/openreason.json +5 -5
  194. package/dist/capabilities/openrouter.json +563 -547
  195. package/dist/capabilities/opper.json +29 -29
  196. package/dist/capabilities/orcarouter.json +252 -252
  197. package/dist/capabilities/outerlabs.json +33 -33
  198. package/dist/capabilities/ovhcloud.json +59 -5
  199. package/dist/capabilities/pareto.json +5 -5
  200. package/dist/capabilities/perplexity-agent.json +66 -66
  201. package/dist/capabilities/phala.json +30 -30
  202. package/dist/capabilities/pioneer.json +24 -24
  203. package/dist/capabilities/poe.json +117 -117
  204. package/dist/capabilities/poolside.json +2 -2
  205. package/dist/capabilities/powerspring.json +14 -14
  206. package/dist/capabilities/primalabs.json +11 -11
  207. package/dist/capabilities/prime.json +129 -113
  208. package/dist/capabilities/privatemode-ai.json +14 -14
  209. package/dist/capabilities/proxystacks.json +6 -6
  210. package/dist/capabilities/qiniu-ai.json +14 -14
  211. package/dist/capabilities/refuseless.json +5 -5
  212. package/dist/capabilities/regolo-ai.json +9 -9
  213. package/dist/capabilities/requesty.json +172 -172
  214. package/dist/capabilities/ruapi.json +18 -18
  215. package/dist/capabilities/runcrate.json +15 -15
  216. package/dist/capabilities/runinfra.json +16 -16
  217. package/dist/capabilities/sakana.json +6 -6
  218. package/dist/capabilities/sambanova.json +9 -9
  219. package/dist/capabilities/sandbase.json +21 -21
  220. package/dist/capabilities/sarvam.json +8 -8
  221. package/dist/capabilities/scaleway.json +18 -18
  222. package/dist/capabilities/scnet-token-plan.json +9 -9
  223. package/dist/capabilities/scx-ai.json +30 -30
  224. package/dist/capabilities/sensenova.json +8 -8
  225. package/dist/capabilities/siliconflow-cn.json +62 -62
  226. package/dist/capabilities/siliconflow.json +58 -58
  227. package/dist/capabilities/snowflake-cortex.json +22 -22
  228. package/dist/capabilities/sokkan.json +10 -10
  229. package/dist/capabilities/sparrowcodes.json +22 -22
  230. package/dist/capabilities/standardcompute.json +101 -101
  231. package/dist/capabilities/steadyrouter.json +43 -43
  232. package/dist/capabilities/stepfun-ai-step-plan.json +6 -6
  233. package/dist/capabilities/stepfun-ai.json +5 -5
  234. package/dist/capabilities/stepfun-step-plan.json +5 -5
  235. package/dist/capabilities/stepfun.json +5 -5
  236. package/dist/capabilities/stepping-stone.json +22 -22
  237. package/dist/capabilities/subconscious.json +2 -2
  238. package/dist/capabilities/superbot-gg.json +4 -4
  239. package/dist/capabilities/synthetic.json +14 -14
  240. package/dist/capabilities/synthorai.json +22 -22
  241. package/dist/capabilities/teamorouter.json +23 -23
  242. package/dist/capabilities/teapot-router.json +16 -16
  243. package/dist/capabilities/tencent-token-plan.json +57 -33
  244. package/dist/capabilities/tencent-tokenhub.json +48 -48
  245. package/dist/capabilities/tensorx.json +46 -46
  246. package/dist/capabilities/tenstorrent.json +2 -2
  247. package/dist/capabilities/the-grid-ai.json +31 -31
  248. package/dist/capabilities/thinkingmachines.json +44 -44
  249. package/dist/capabilities/tinfoil.json +11 -11
  250. package/dist/capabilities/toapis.json +3 -3
  251. package/dist/capabilities/togetherai.json +53 -51
  252. package/dist/capabilities/tokengo.json +24 -24
  253. package/dist/capabilities/tokenify.json +10 -10
  254. package/dist/capabilities/trustedrouter.json +6 -6
  255. package/dist/capabilities/trustedtokens.json +16 -16
  256. package/dist/capabilities/umans-ai-coding-plan.json +15 -15
  257. package/dist/capabilities/umans-ai.json +9 -9
  258. package/dist/capabilities/unrestricted.json +8 -8
  259. package/dist/capabilities/uplinkswitch.json +21 -21
  260. package/dist/capabilities/upstage.json +6 -6
  261. package/dist/capabilities/vancine.json +21 -21
  262. package/dist/capabilities/vercel.json +578 -578
  263. package/dist/capabilities/vivgrid.json +81 -81
  264. package/dist/capabilities/volcengine-coding-plan.json +26 -26
  265. package/dist/capabilities/volcengine.json +27 -27
  266. package/dist/capabilities/vultr.json +25 -25
  267. package/dist/capabilities/wafer.ai.json +18 -18
  268. package/dist/capabilities/wallaby.json +5 -5
  269. package/dist/capabilities/wally.json +12 -12
  270. package/dist/capabilities/wandb.json +19 -19
  271. package/dist/capabilities/watt.json +22 -22
  272. package/dist/capabilities/xai.json +7 -7
  273. package/dist/capabilities/xiaomi-token-plan-ams.json +2 -2
  274. package/dist/capabilities/xiaomi-token-plan-cn.json +2 -2
  275. package/dist/capabilities/xiaomi-token-plan-sgp.json +2 -2
  276. package/dist/capabilities/xiaomi.json +2 -2
  277. package/dist/capabilities/xpersona.json +11 -11
  278. package/dist/capabilities/xxapi.json +32 -32
  279. package/dist/capabilities/zai-coding-plan.json +16 -16
  280. package/dist/capabilities/zai.json +34 -32
  281. package/dist/capabilities/zenifra.json +26 -26
  282. package/dist/capabilities/zenmux.json +187 -187
  283. package/dist/capabilities/zerogpu.json +13 -13
  284. package/dist/capabilities/zhipuai-coding-plan.json +7 -7
  285. package/dist/capabilities/zhipuai.json +29 -29
  286. package/dist/capabilities/zro.json +6 -6
  287. package/dist/channels/agent-channels.d.ts +2 -1
  288. package/dist/channels/formatting.d.ts +8 -0
  289. package/dist/channels/index.cjs +4 -2
  290. package/dist/channels/index.d.ts +1 -1
  291. package/dist/channels/index.js +3 -3
  292. package/dist/channels/types.d.ts +5 -3
  293. package/dist/{channels-DSOCNoab.js → channels-Wh32drgu.js} +1 -1
  294. package/dist/{channels-D7bBM9xD.cjs → channels-tVV_de9Q.cjs} +1 -1
  295. package/dist/coding-agent/index.cjs +1 -1
  296. package/dist/coding-agent/index.js +1 -1
  297. package/dist/datasets/index.cjs +2 -2
  298. package/dist/datasets/index.js +2 -2
  299. package/dist/docs/SKILL.md +1 -1
  300. package/dist/docs/assets/SOURCE_MAP.json +789 -789
  301. package/dist/docs/references/docs-agents-resumable-streams.md +15 -6
  302. package/dist/docs/references/docs-deployment-workers.md +3 -1
  303. package/dist/docs/references/docs-harness-background-tasks.md +4 -4
  304. package/dist/docs/references/docs-harness-durable-agents.md +39 -48
  305. package/dist/docs/references/docs-knowledge-importers.md +1 -1
  306. package/dist/docs/references/docs-mastra-platform-observability-overview.md +1 -1
  307. package/dist/docs/references/docs-sandbox-overview.md +1 -0
  308. package/dist/docs/references/docs-server-pubsub.md +1 -1
  309. package/dist/docs/references/docs-workflows-overview.md +67 -3
  310. package/dist/docs/references/integrations-agentic-ui-assistant-ui.md +2 -0
  311. package/dist/docs/references/integrations-frameworks-angular.md +39 -0
  312. package/dist/docs/references/integrations-frameworks-astro.md +5 -2
  313. package/dist/docs/references/integrations-frameworks-electron.md +40 -0
  314. package/dist/docs/references/integrations-frameworks-next-js.md +5 -2
  315. package/dist/docs/references/integrations-frameworks-nuxt.md +5 -2
  316. package/dist/docs/references/integrations-frameworks-sveltekit.md +5 -2
  317. package/dist/docs/references/integrations-frameworks-vite-react.md +40 -0
  318. package/dist/docs/references/integrations.md +3 -0
  319. package/dist/docs/references/reference-agent-controller-agent-controller-class.md +6 -0
  320. package/dist/docs/references/reference-agents-channels.md +1 -1
  321. package/dist/docs/references/reference-agents-durable-agent.md +3 -3
  322. package/dist/docs/references/reference-agents-generate.md +2 -0
  323. package/dist/docs/references/reference-configuration.md +1 -1
  324. package/dist/docs/references/reference-core-mastra-class.md +2 -0
  325. package/dist/docs/references/reference-knowledge-knowledge-class.md +1 -1
  326. package/dist/docs/references/reference-knowledge-knowledge-tools.md +11 -5
  327. package/dist/docs/references/reference-pubsub-caching-pubsub.md +2 -2
  328. package/dist/docs/references/reference-pubsub-redis-streams.md +2 -2
  329. package/dist/docs/references/reference-pubsub-valkey-streams.md +2 -2
  330. package/dist/docs/references/reference-workers-overview.md +2 -0
  331. package/dist/docs/references/reference-workflows-workflow-methods-create-run.md +2 -0
  332. package/dist/docs/references/reference-workflows-workflow.md +2 -0
  333. package/dist/docs/references/reference.md +1 -0
  334. package/dist/error/index.cjs +2 -1
  335. package/dist/error/index.d.ts +1 -1
  336. package/dist/error/index.js +2 -2
  337. package/dist/error/provider-error.d.ts +2 -1
  338. package/dist/{error-BLwEXqOK.js → error-BC9Au-22.js} +13 -1
  339. package/dist/{error-BdEvO8za.cjs → error-L1V4uUbd.cjs} +18 -0
  340. package/dist/evals/index.cjs +1 -1
  341. package/dist/evals/index.js +1 -1
  342. package/dist/evals/scoreTraces/index.cjs +1 -1
  343. package/dist/evals/scoreTraces/index.js +1 -1
  344. package/dist/events/caching-pubsub.d.ts +28 -0
  345. package/dist/events/index.cjs +4 -1
  346. package/dist/events/index.js +2 -2
  347. package/dist/events/topics.d.ts +55 -9
  348. package/dist/harness/index.cjs +1 -1
  349. package/dist/harness/index.js +1 -1
  350. package/dist/index.cjs +1 -1
  351. package/dist/index.js +1 -1
  352. package/dist/{inmemory-BDD0w8gx.js → inmemory-BK3zLwvM.js} +42 -12
  353. package/dist/{inmemory-fgR8sq-U.cjs → inmemory-Dc86VWGB.cjs} +42 -12
  354. package/dist/knowledge/changes.d.ts +17 -5
  355. package/dist/knowledge/importers/runner.d.ts +6 -0
  356. package/dist/knowledge/index.cjs +78 -16
  357. package/dist/knowledge/index.d.ts +2 -2
  358. package/dist/knowledge/index.js +78 -16
  359. package/dist/knowledge/search-snippet.d.ts +30 -0
  360. package/dist/llm/index.cjs +3 -3
  361. package/dist/llm/index.js +3 -3
  362. package/dist/llm/model/provider-types.generated.d.ts +7986 -7970
  363. package/dist/{llm-DMNEZIV9.js → llm-B1zaFLYZ.js} +3 -3
  364. package/dist/{llm-BOQR5g0t.cjs → llm-BAiOsNAP.cjs} +3 -3
  365. package/dist/loop/index.cjs +2 -2
  366. package/dist/loop/index.js +2 -2
  367. package/dist/{manager-CyCR9IpR.cjs → manager-BVX9nVrM.cjs} +2 -2
  368. package/dist/{manager-BzNynLwT.js → manager-ChK9GdGz.js} +2 -2
  369. package/dist/mastra/index.cjs +1 -1
  370. package/dist/mastra/index.js +1 -1
  371. package/dist/{mastra-CqBmnzjM.js → mastra-CUGfgEpZ.js} +28 -18
  372. package/dist/{mastra-D2B01_gg.cjs → mastra-HSmofHEJ.cjs} +28 -18
  373. package/dist/memory/index.cjs +2 -2
  374. package/dist/memory/index.js +2 -2
  375. package/dist/{model-3AeJKHLU.js → model-C47BJRtR.js} +1 -1
  376. package/dist/{model-CrXDhcbw.cjs → model-WahorgzJ.cjs} +1 -1
  377. package/dist/{netlify-DUPSTzi6.js → netlify-CfDXkuLf.js} +2 -2
  378. package/dist/{netlify-DTXLQiG1.cjs → netlify-D99AnEhW.cjs} +2 -2
  379. package/dist/notifications/index.cjs +1 -1
  380. package/dist/notifications/index.js +1 -1
  381. package/dist/observability/index.cjs +1 -0
  382. package/dist/observability/index.d.ts +1 -1
  383. package/dist/observability/index.js +2 -2
  384. package/dist/{output-helpers-CedRCE17.js → output-helpers-CVzhy1Y0.js} +126 -56
  385. package/dist/{output-helpers-1Zu4Vt9C.cjs → output-helpers-DgsH4aTb.cjs} +143 -55
  386. package/dist/processor-provider/index.cjs +1 -1
  387. package/dist/processor-provider/index.js +1 -1
  388. package/dist/processors/index.cjs +2 -2
  389. package/dist/processors/index.js +2 -2
  390. package/dist/processors/runner.d.ts +2 -0
  391. package/dist/{provider-registry-B_rC-5aL.cjs → provider-registry-CO1NVbO5.cjs} +22281 -22258
  392. package/dist/{provider-registry-BeB8RQO8.js → provider-registry-CR385GJ4.js} +22281 -22258
  393. package/dist/provider-registry.json +22871 -22855
  394. package/dist/{registry-generator-Cv6GnxLG.js → registry-generator-B3erRqYS.js} +1 -1
  395. package/dist/{registry-generator-DbBoIOby.cjs → registry-generator-Cvp34qcB.cjs} +1 -1
  396. package/dist/{rehydrate-3f-i1Ga2.js → rehydrate-CJBLrZxs.js} +2 -2
  397. package/dist/{rehydrate-BWaa2eGN.cjs → rehydrate-Da4hNuaK.cjs} +2 -2
  398. package/dist/relevance/index.cjs +2 -2
  399. package/dist/relevance/index.js +2 -2
  400. package/dist/{run-registry-Bx06ZIN_.js → run-registry-DdeEBsVW.js} +1639 -568
  401. package/dist/{run-registry-Bk6QxNE4.cjs → run-registry-TOOfO3hT.cjs} +1668 -567
  402. package/dist/storage/domains/inmemory-db.d.ts +1 -0
  403. package/dist/storage/domains/knowledge/base.d.ts +5 -0
  404. package/dist/storage/domains/knowledge/inmemory.d.ts +1 -0
  405. package/dist/storage/domains/knowledge/pages-inmemory.d.ts +10 -2
  406. package/dist/storage/domains/knowledge/pages.d.ts +30 -0
  407. package/dist/storage/index.cjs +2 -2
  408. package/dist/storage/index.js +2 -2
  409. package/dist/storage/run-fencing.d.ts +5 -0
  410. package/dist/stream/index.cjs +2 -2
  411. package/dist/stream/index.js +2 -2
  412. package/dist/{stream-DVy0Z-m0.js → stream-C5PagEDs.js} +3 -3
  413. package/dist/{stream-BIXX67WE.cjs → stream-DH7Qgz8l.cjs} +3 -3
  414. package/dist/test-utils/llm-mock.cjs +1 -1
  415. package/dist/test-utils/llm-mock.js +1 -1
  416. package/dist/tool-loop-agent/index.cjs +1 -1
  417. package/dist/tool-loop-agent/index.js +1 -1
  418. package/dist/{tool-loop-agent-DDeKGwtr.cjs → tool-loop-agent-CJTs4T8b.cjs} +3 -3
  419. package/dist/{tool-loop-agent-PSKeNhuT.js → tool-loop-agent-DVYJXlQJ.js} +3 -3
  420. package/dist/{utils-BJiQF8Pi.js → utils-D8upuTwy.js} +1 -1
  421. package/dist/{utils-CAnUlnUm.cjs → utils-xJi_N6Tx.cjs} +1 -1
  422. package/dist/utils.cjs +1 -1
  423. package/dist/utils.js +1 -1
  424. package/dist/{validate-BMNxfs4Z.cjs → validate-6eZ8Wssn.cjs} +1 -1
  425. package/dist/{validate-BAVwAgtT.js → validate-DTkW3Vlp.js} +1 -1
  426. package/dist/vector/index.cjs +1 -1
  427. package/dist/vector/index.js +1 -1
  428. package/dist/worker/index.cjs +1 -1
  429. package/dist/worker/index.js +1 -1
  430. package/dist/{worker-CFUKBBCF.cjs → worker-24ORi-wV.cjs} +2 -2
  431. package/dist/{worker-Brwa-HqM.cjs → worker-BO3u_WjZ.cjs} +2 -2
  432. package/dist/{worker-BlvJM_Hu.js → worker-DbcFkKJO.js} +2 -2
  433. package/dist/{worker-CVoD3tts.js → worker-Dqubrnf8.js} +2 -2
  434. package/dist/{workflow-zvQGBMCM.cjs → workflow-D5Fc5ieC.cjs} +4 -4
  435. package/dist/{workflow-BSLS7_vB.js → workflow-wXOf72fO.js} +4 -4
  436. package/dist/workflows/builder/index.cjs +1 -1
  437. package/dist/workflows/builder/index.js +1 -1
  438. package/dist/workflows/evented/index.cjs +1 -1
  439. package/dist/workflows/evented/index.js +1 -1
  440. package/dist/workflows/index.cjs +4 -4
  441. package/dist/workflows/index.js +4 -4
  442. package/dist/workflows/run-ownership.d.ts +74 -8
  443. package/dist/workflows/types.d.ts +16 -0
  444. package/dist/workflows/workflow.d.ts +4 -0
  445. package/package.json +6 -6
  446. package/src/llm/model/provider-types.generated.d.ts +7986 -7970
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_run_registry = require("../run-registry-Bk6QxNE4.cjs");
2
+ const require_run_registry = require("../run-registry-TOOfO3hT.cjs");
3
3
  const require_constants = require("../constants-B9ZDvXZ4.cjs");
4
4
  const require_collect_tool_mocks = require("../collect-tool-mocks-k9fM6oDl.cjs");
5
5
  exports.MastraScorer = require_run_registry.MastraScorer;
@@ -1,4 +1,4 @@
1
- import { C as ScorerRunError, D as notScorable, Dc as SCORING_PREDICATE_ROOTS, E as isNotScorable, Oc as evaluateScoringPredicate, S as MastraScorer, T as filterRun, _ as runEvals, kc as validateScoringPredicate, w as createScorer, x as createClassifierScorer } from "../run-registry-Bx06ZIN_.js";
1
+ import { C as ScorerRunError, D as notScorable, Dc as validateScoringPredicate, E as isNotScorable, Ec as evaluateScoringPredicate, S as MastraScorer, T as filterRun, Tc as SCORING_PREDICATE_ROOTS, _ as runEvals, w as createScorer, x as createClassifierScorer } from "../run-registry-DdeEBsVW.js";
2
2
  import { Ar as scoringEntityTypeSchema, Cr as extractTrajectory, Dr as saveScorePayloadSchema, Er as listScoresResponseSchema, Fr as scoringInputWithExtractStepResultAndScoreAndReasonSchema, Ir as scoringInputWithExtractStepResultSchema, Lr as scoringPromptsSchema, Mr as scoringHookInputSchema, Nr as scoringInputSchema, Or as scoreResultSchema, Pr as scoringInputWithExtractStepResultAndAnalyzeStepResultSchema, Rr as scoringSourceSchema, Tr as extractWorkflowTrajectory, jr as scoringExtractStepResultSchema, kr as scoreRowDataSchema, wr as extractTrajectoryFromTrace, zr as scoringValueSchema } from "../constants-BmdTvEYN.js";
3
3
  import { t as collectToolMocks } from "../collect-tool-mocks-3s2BN8o7.js";
4
4
  export { MastraScorer, SCORING_PREDICATE_ROOTS, ScorerRunError, collectToolMocks, createClassifierScorer, createScorer, evaluateScoringPredicate, extractTrajectory, extractTrajectoryFromTrace, extractWorkflowTrajectory, filterRun, isNotScorable, listScoresResponseSchema, notScorable, runEvals, saveScorePayloadSchema, scoreResultSchema, scoreRowDataSchema, scoringEntityTypeSchema, scoringExtractStepResultSchema, scoringHookInputSchema, scoringInputSchema, scoringInputWithExtractStepResultAndAnalyzeStepResultSchema, scoringInputWithExtractStepResultAndScoreAndReasonSchema, scoringInputWithExtractStepResultSchema, scoringPromptsSchema, scoringSourceSchema, scoringValueSchema, validateScoringPredicate };
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_error = require("../../error-D90lJ6M7.cjs");
3
3
  const require_utils = require("../../utils-D-eNsgDM.cjs");
4
- const require_run_registry = require("../../run-registry-Bk6QxNE4.cjs");
4
+ const require_run_registry = require("../../run-registry-TOOfO3hT.cjs");
5
5
  const require_constants = require("../../constants-B9ZDvXZ4.cjs");
6
6
  let zod_v4 = require("zod/v4");
7
7
  // src/evals/scoreTraces/scoreTraces.ts
@@ -1,6 +1,6 @@
1
1
  import { i as MastraError, n as ErrorDomain, t as ErrorCategory } from "../../error-oh2DLsP2.js";
2
2
  import { i as getEntityTypeForSpan } from "../../utils-DU_pU5SK.js";
3
- import { Fs as createStep, Is as createWorkflow } from "../../run-registry-Bx06ZIN_.js";
3
+ import { Bs as createWorkflow, zs as createStep } from "../../run-registry-DdeEBsVW.js";
4
4
  import { Dr as saveScorePayloadSchema } from "../../constants-BmdTvEYN.js";
5
5
  import { z } from "zod/v4";
6
6
  // src/evals/scoreTraces/scoreTraces.ts
@@ -60,6 +60,19 @@ export interface CachingPubSubOptions {
60
60
  * ignored for compatibility.
61
61
  */
62
62
  source?: PubSub;
63
+ /**
64
+ * Retention stamped on `agent.stream.<runId>` logs with every append.
65
+ * Defaults to {@link DEFAULT_RUN_LOG_TTL_MS}. Size it to the longest quiet
66
+ * gap of a run that is still executing plus a reconnect window — storage is
67
+ * the system of record, and an expired log resyncs observers instead of
68
+ * breaking them.
69
+ */
70
+ runLogTtlMs?: number;
71
+ /**
72
+ * Retention stamped on `agent.thread-stream.<key>` logs with every append.
73
+ * Defaults to {@link DEFAULT_THREAD_STREAM_LOG_TTL_MS}.
74
+ */
75
+ threadStreamLogTtlMs?: number;
63
76
  }
64
77
  /**
65
78
  * A PubSub decorator that adds event caching and replay capabilities.
@@ -128,6 +141,7 @@ export declare class CachingPubSub extends PubSub {
128
141
  private readonly shouldCache?;
129
142
  private readonly extendExistingLogsOnly;
130
143
  private readonly onUnlogged?;
144
+ private readonly logTtls;
131
145
  /** Maps original callbacks to their wrapped versions for proper unsubscribe */
132
146
  private callbackMap;
133
147
  /**
@@ -181,6 +195,20 @@ export declare class CachingPubSub extends PubSub {
181
195
  *
182
196
  * Numbered entries are returned in index order, followed by unnumbered
183
197
  * ones, because a non-atomic append can store frames out of order.
198
+ *
199
+ * Sizing the slice from the last entry's index instead would be one read
200
+ * cheaper, but only if list order matched index order. It does not on the
201
+ * non-atomic composed fallback: for a list appended `[0, 1, 4, 2, 3]`, a
202
+ * tail sized from the last index (3) spans two entries and silently loses
203
+ * index 4, where walking back by the hole count reaches it.
204
+ *
205
+ * The hole count is not a complete defence either — it assumes an entry
206
+ * numbered `from` or later sits at position `from` or later, which an
207
+ * out-of-order append can also break for a high enough `from`. Reading from
208
+ * position 0 whenever the cache cannot promise index-ordered appends would
209
+ * close that, at the cost of a whole-log read per resume and per live gap;
210
+ * it needs a capability on `MastraServerCache` to avoid paying that on the
211
+ * atomic caches, which is tracked separately.
184
212
  */
185
213
  private readLogFrom;
186
214
  publish(topic: string, event: Omit<Event, 'id' | 'createdAt' | 'index'>, options?: {
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_rolldown_runtime = require("../rolldown-runtime-BrhgMLW6.cjs");
3
- const require_output_helpers = require("../output-helpers-1Zu4Vt9C.cjs");
3
+ const require_output_helpers = require("../output-helpers-DgsH4aTb.cjs");
4
4
  const require_file = require("../file-BEndQUN1.cjs");
5
5
  let crypto = require("crypto");
6
6
  let path = require("path");
@@ -1672,6 +1672,8 @@ var UnixSocketPubSub = class extends require_output_helpers.PubSub {
1672
1672
  }
1673
1673
  };
1674
1674
  exports.CachingPubSub = require_output_helpers.CachingPubSub;
1675
+ exports.DEFAULT_RUN_LOG_TTL_MS = require_output_helpers.DEFAULT_RUN_LOG_TTL_MS;
1676
+ exports.DEFAULT_THREAD_STREAM_LOG_TTL_MS = require_output_helpers.DEFAULT_THREAD_STREAM_LOG_TTL_MS;
1675
1677
  exports.EventEmitterPubSub = require_output_helpers.EventEmitterPubSub;
1676
1678
  exports.MAX_LOCAL_REDELIVERIES = MAX_LOCAL_REDELIVERIES;
1677
1679
  exports.NoopLeaseProvider = require_output_helpers.NoopLeaseProvider;
@@ -1682,6 +1684,7 @@ exports.UnixSocketPubSub = UnixSocketPubSub;
1682
1684
  exports.cachedLogTtlMs = require_output_helpers.cachedLogTtlMs;
1683
1685
  exports.isLeaseProvider = require_output_helpers.isLeaseProvider;
1684
1686
  exports.isRunLocalTopic = require_output_helpers.isRunLocalTopic;
1687
+ exports.streamTopicIdleTtlMs = require_output_helpers.streamTopicIdleTtlMs;
1685
1688
  exports.toCachedLogFrame = require_output_helpers.toCachedLogFrame;
1686
1689
  exports.withAck = require_output_helpers.withAck;
1687
1690
  exports.withCaching = require_output_helpers.withCaching;
@@ -1,4 +1,4 @@
1
- import { _ as PubSub, a as rehydrateError, c as RUN_LOG_TTL_MS, d as toCachedLogFrame, g as NoopLeaseProvider, h as EventEmitterPubSub, i as withCaching, l as cachedLogTtlMs, n as PublisherQueueLimitError, o as serializeError, r as CachingPubSub, s as RUN_LOCAL_TOPIC_PREFIXES, t as DefaultStepResult, u as isRunLocalTopic, v as isLeaseProvider, y as withAck } from "../output-helpers-CedRCE17.js";
1
+ import { S as withAck, _ as serializeError, a as DEFAULT_RUN_LOG_TTL_MS, b as PubSub, c as RUN_LOG_TTL_MS, d as streamTopicIdleTtlMs, f as toCachedLogFrame, g as rehydrateError, i as withCaching, l as cachedLogTtlMs, n as PublisherQueueLimitError, o as DEFAULT_THREAD_STREAM_LOG_TTL_MS, r as CachingPubSub, s as RUN_LOCAL_TOPIC_PREFIXES, t as DefaultStepResult, u as isRunLocalTopic, v as EventEmitterPubSub, x as isLeaseProvider, y as NoopLeaseProvider } from "../output-helpers-CVzhy1Y0.js";
2
2
  import { n as DefaultGeneratedFileWithType, t as DefaultGeneratedFile } from "../file-DGZrR5f7.js";
3
3
  import { createHash } from "crypto";
4
4
  import { basename, dirname, join, sep } from "path";
@@ -1668,4 +1668,4 @@ var UnixSocketPubSub = class extends PubSub {
1668
1668
  else if (frame.type === "publish") await this.#publishFromBroker(frame.topic, frame.event);
1669
1669
  }
1670
1670
  };
1671
- export { CachingPubSub, EventEmitterPubSub, MAX_LOCAL_REDELIVERIES, NoopLeaseProvider, PubSub, RUN_LOCAL_TOPIC_PREFIXES, RUN_LOG_TTL_MS, UnixSocketPubSub, cachedLogTtlMs, isLeaseProvider, isRunLocalTopic, toCachedLogFrame, withAck, withCaching };
1671
+ export { CachingPubSub, DEFAULT_RUN_LOG_TTL_MS, DEFAULT_THREAD_STREAM_LOG_TTL_MS, EventEmitterPubSub, MAX_LOCAL_REDELIVERIES, NoopLeaseProvider, PubSub, RUN_LOCAL_TOPIC_PREFIXES, RUN_LOG_TTL_MS, UnixSocketPubSub, cachedLogTtlMs, isLeaseProvider, isRunLocalTopic, streamTopicIdleTtlMs, toCachedLogFrame, withAck, withCaching };
@@ -22,18 +22,64 @@ export declare const RUN_LOCAL_TOPIC_PREFIXES: readonly ['workflow.events.v2.'];
22
22
  */
23
23
  export declare function isRunLocalTopic(topic: string): boolean;
24
24
  /**
25
- * How long a durable run's stream log (`agent.stream.<runId>`) is retained.
26
- *
27
- * The log is what `observe({ offset })` replays from, and its counter numbers
28
- * every frame. A run parked on a tool approval can wait far longer than a
29
- * cache's default TTL; if the log expired meanwhile, numbering would restart at
30
- * 0 while an attached observer still held the old cursor. The run's suspension
31
- * frame is its last append before it parks, so stamping this on every append
32
- * covers the parked window. Run cleanup deletes the log when the run ends.
25
+ * How long a run's stream log (`agent.stream.<runId>`) is retained after its
26
+ * last append, by default.
27
+ *
28
+ * This MUST match `AGENT_RUN_RECORD_TTL_MS` (`agent/streams/run-records.ts`;
29
+ * events cannot import from agent). A run parked on a tool approval appends
30
+ * nothing while it waits, so its retention is never refreshed — and its
31
+ * ownership record authorizes `observe()` for 24 hours. A log that expires
32
+ * sooner leaves that window authorized but empty: the observer hangs without
33
+ * ever receiving the approval request it is waiting to act on. The two
34
+ * lifetimes expire together, so an authorized run always still has its
35
+ * events.
36
+ *
37
+ * The log is a delivery buffer, not the system of record: messages and
38
+ * suspension snapshots live in storage. An expired log is recreated on the
39
+ * next append with indices past every index it could have issued before (see
40
+ * `MastraServerCache.listPushIndexed`), so attached observers resynchronise
41
+ * instead of dropping frames. Run cleanup deletes the log when the run ends;
42
+ * this retention bounds it when cleanup never runs.
33
43
  */
44
+ export declare const DEFAULT_RUN_LOG_TTL_MS: number;
45
+ /** @deprecated Use {@link DEFAULT_RUN_LOG_TTL_MS}, or configure `runLogTtlMs` on `CachingPubSub`. */
34
46
  export declare const RUN_LOG_TTL_MS: number;
47
+ /**
48
+ * How long a thread's event stream (`agent.thread-stream.<key>`) is retained
49
+ * after its last append, by default. Active threads re-stamp it on every
50
+ * publish; storage holds a thread's saved runs, and the runtime trims saved
51
+ * output off the topic, so an idle thread's leftover tail only needs to
52
+ * survive a reconnect window.
53
+ */
54
+ export declare const DEFAULT_THREAD_STREAM_LOG_TTL_MS: number;
55
+ /** Per-topic retention used when stamping a cached log's TTL on append. */
56
+ export interface CachedLogTtls {
57
+ /** Retention for `agent.stream.<runId>` logs. Defaults to {@link DEFAULT_RUN_LOG_TTL_MS}. */
58
+ runLogTtlMs?: number;
59
+ /** Retention for `agent.thread-stream.<key>` logs. Defaults to {@link DEFAULT_THREAD_STREAM_LOG_TTL_MS}. */
60
+ threadStreamLogTtlMs?: number;
61
+ }
35
62
  /** Minimum retention for a topic's cached log, or `undefined` for the cache default. */
36
- export declare function cachedLogTtlMs(topic: string): number | undefined;
63
+ export declare function cachedLogTtlMs(topic: string, ttls?: CachedLogTtls): number | undefined;
64
+ /**
65
+ * Idle retention for a topic that belongs to a single run or thread, or
66
+ * `undefined` for a topic a transport should bound with its own backstop.
67
+ *
68
+ * A persistent transport (Redis/Valkey Streams) needs a long idle backstop
69
+ * for work-queue topics, whose grouped consumers must still find their
70
+ * backlog after an outage. A run's topics have no such consumer: they are
71
+ * fan-out, their replay history is bounded by {@link cachedLogTtlMs} in the
72
+ * server cache, and the run record that authorizes reading them expires in a
73
+ * day. So they share the retention of the cached log they mirror — a day for
74
+ * run topics, matching the record (a run parked on an approval must stay
75
+ * readable for as long as it is authorizable), and an hour for thread
76
+ * streams. Holding them for the transport's multi-day backstop instead just
77
+ * leaves finished runs in the store for days.
78
+ *
79
+ * Run cleanup deletes these topics promptly when the owning process survives;
80
+ * this retention is what bounds them when it does not.
81
+ */
82
+ export declare function streamTopicIdleTtlMs(topic: string, ttls?: CachedLogTtls): number | undefined;
37
83
  /**
38
84
  * The copy of `event` a run's cached log keeps.
39
85
  *
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_state_processor = require("../state-processor-kRNZ38Nf.cjs");
3
3
  const require_tools = require("../tools-CGF5Ik6j.cjs");
4
- const require_agent_controller = require("../agent-controller-D_5Dc8d3.cjs");
4
+ const require_agent_controller = require("../agent-controller-DSnFynpa.cjs");
5
5
  // src/harness/index.ts
6
6
  /**
7
7
  * @deprecated Backwards-compatibility entrypoint.
@@ -1,6 +1,6 @@
1
1
  import { f as taskCheckTool, h as taskWriteTool, m as taskUpdateTool, o as assignTaskIds, p as taskCompleteTool } from "../state-processor-B9kxpM53.js";
2
2
  import { s as askUserTool, t as submitPlanTool } from "../tools-CDfyMpzN.js";
3
- import { a as Session, c as defaultDisplayState, l as defaultOMProgressState, n as parseSubagentMeta, t as AgentController } from "../agent-controller-D5EKeS1H.js";
3
+ import { a as Session, c as defaultDisplayState, l as defaultOMProgressState, n as parseSubagentMeta, t as AgentController } from "../agent-controller-B8LoFdtu.js";
4
4
  // src/harness/index.ts
5
5
  /**
6
6
  * @deprecated Backwards-compatibility entrypoint.
package/dist/index.cjs CHANGED
@@ -1,3 +1,3 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_mastra = require("./mastra-D2B01_gg.cjs");
2
+ const require_mastra = require("./mastra-HSmofHEJ.cjs");
3
3
  exports.Mastra = require_mastra.Mastra;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { t as Mastra } from "./mastra-CqBmnzjM.js";
1
+ export { t as Mastra } from "./mastra-CUGfgEpZ.js";
@@ -10,21 +10,51 @@ var MastraServerCache = class extends MastraBase {
10
10
  }
11
11
  /**
12
12
  * Atomically allocate the next index from `counterKey` and append `value`
13
- * (with `index` set to the 0-based allocated index) to the list at `listKey`.
13
+ * (with `index` set to the allocated index) to the list at `listKey`.
14
14
  * Returns the assigned index.
15
15
  *
16
- * The list and its counter must expire together: a counter that outlives its
17
- * list restarts at 0 while subscribers still expect the old numbering, and a
18
- * counter that expires first would start reusing indices already in the list.
19
- * Every append refreshes both keys to the same deadline.
16
+ * Indices are opaque cursors — not list positions, and not dense. Within
17
+ * one log's life they strictly increase and consecutive appends get
18
+ * consecutive indices; readers resume from `index + 1`, not from a frame
19
+ * count. A log recreated after its predecessor expired or was evicted
20
+ * should avoid reissuing an index a subscriber may still hold — but no
21
+ * implementation makes that absolute, so readers must not depend on it.
22
+ *
23
+ * How an implementation approaches it is up to it. The built-in Redis,
24
+ * Valkey and in-memory caches seed a counter they create from the clock in
25
+ * epoch MICROseconds — microseconds because a hot log appends faster than
26
+ * the millisecond clock advances, and an index must not outrun the next
27
+ * seed. Epoch microseconds stay well inside Number.MAX_SAFE_INTEGER (2^53
28
+ * ≈ year 2255). `ConvexServerCache` instead allocates `max(counter, list
29
+ * length)` inside one transaction. It and the generic fallback restart
30
+ * numbering from 0 when both list and counter are gone.
31
+ * A clock seed is only as monotonic as the clock: recreating a log
32
+ * within the seed's resolution, or after the clock moves backwards, can
33
+ * still repeat an index. The subscriber's fallback detection only
34
+ * recognises a log that restarts at 0 (the dense case); a log reseeded
35
+ * below a subscriber's cursor without reaching 0 goes unnoticed until that
36
+ * reader reattaches.
37
+ *
38
+ * The list and its counter must expire together: a counter that expires
39
+ * before its list would reuse indices already in the list. Every append
40
+ * refreshes both keys to the same deadline.
20
41
  *
21
42
  * @param ttlMs - Minimum lifetime for both keys, in milliseconds. A cache
22
- * whose own TTL is longer, or that never expires, keeps that instead. When
23
- * omitted, the cache's default TTL applies.
43
+ * whose own TTL is longer keeps that instead. An explicit `ttlMs` applies
44
+ * even when the cache's default expiry is disabled: the caller is stating
45
+ * a retention bound for this log, and a log that never expires is never
46
+ * reclaimed. When omitted, the cache's default TTL applies.
47
+ *
48
+ * The default implementation preserves the original zero-based numbering
49
+ * and composes `increment()` + `listPush()`. It is NOT atomic and ignores
50
+ * `ttlMs`. Concurrent appends can land out of index order, causing attached
51
+ * readers and offset replays to miss frames; an old offset can also skip
52
+ * a recreated log whose numbering restarted below it.
24
53
  *
25
- * The default implementation composes `increment()` + `listPush()` (two
26
- * round-trips) and is therefore NOT atomic, and ignores `ttlMs`. Overrides
27
- * should perform both steps in one server-side operation.
54
+ * Do not seed this fallback with `set()`: it can overwrite concurrent
55
+ * allocations, and a stored numeric value need not be an incrementable
56
+ * counter (Convex stores them as different types). Overrides should
57
+ * initialize the counter, allocate and append in one server-side operation.
28
58
  */
29
59
  async listPushIndexed(listKey, counterKey, value, _ttlMs) {
30
60
  const index = await this.increment(counterKey) - 1;
@@ -103,11 +133,11 @@ var InMemoryServerCache = class extends MastraServerCache {
103
133
  async listPushIndexed(listKey, counterKey, value, ttlMs) {
104
134
  const existingCounter = this.cache.get(counterKey);
105
135
  if (existingCounter !== void 0 && typeof existingCounter !== "number") throw new Error(`${counterKey} exists but is not a number`);
106
- const index = typeof existingCounter === "number" ? existingCounter : 0;
136
+ const index = typeof existingCounter === "number" ? existingCounter : Date.now() * 1e3;
107
137
  const existingList = this.cache.get(listKey);
108
138
  if (existingList !== void 0 && !Array.isArray(existingList)) throw new Error(`${listKey} exists but is not an array`);
109
139
  const list = Array.isArray(existingList) ? existingList : [];
110
- const ttl = this.ttlMs > 0 ? Math.max(this.ttlMs, ttlMs ?? 0) : Infinity;
140
+ const ttl = ttlMs !== void 0 && ttlMs > 0 ? Math.max(this.ttlMs, ttlMs) : this.ttlMs > 0 ? this.ttlMs : Infinity;
111
141
  this.cache.set(counterKey, index + 1, { ttl });
112
142
  list.push({
113
143
  ...value,
@@ -10,21 +10,51 @@ var MastraServerCache = class extends require_base.MastraBase {
10
10
  }
11
11
  /**
12
12
  * Atomically allocate the next index from `counterKey` and append `value`
13
- * (with `index` set to the 0-based allocated index) to the list at `listKey`.
13
+ * (with `index` set to the allocated index) to the list at `listKey`.
14
14
  * Returns the assigned index.
15
15
  *
16
- * The list and its counter must expire together: a counter that outlives its
17
- * list restarts at 0 while subscribers still expect the old numbering, and a
18
- * counter that expires first would start reusing indices already in the list.
19
- * Every append refreshes both keys to the same deadline.
16
+ * Indices are opaque cursors — not list positions, and not dense. Within
17
+ * one log's life they strictly increase and consecutive appends get
18
+ * consecutive indices; readers resume from `index + 1`, not from a frame
19
+ * count. A log recreated after its predecessor expired or was evicted
20
+ * should avoid reissuing an index a subscriber may still hold — but no
21
+ * implementation makes that absolute, so readers must not depend on it.
22
+ *
23
+ * How an implementation approaches it is up to it. The built-in Redis,
24
+ * Valkey and in-memory caches seed a counter they create from the clock in
25
+ * epoch MICROseconds — microseconds because a hot log appends faster than
26
+ * the millisecond clock advances, and an index must not outrun the next
27
+ * seed. Epoch microseconds stay well inside Number.MAX_SAFE_INTEGER (2^53
28
+ * ≈ year 2255). `ConvexServerCache` instead allocates `max(counter, list
29
+ * length)` inside one transaction. It and the generic fallback restart
30
+ * numbering from 0 when both list and counter are gone.
31
+ * A clock seed is only as monotonic as the clock: recreating a log
32
+ * within the seed's resolution, or after the clock moves backwards, can
33
+ * still repeat an index. The subscriber's fallback detection only
34
+ * recognises a log that restarts at 0 (the dense case); a log reseeded
35
+ * below a subscriber's cursor without reaching 0 goes unnoticed until that
36
+ * reader reattaches.
37
+ *
38
+ * The list and its counter must expire together: a counter that expires
39
+ * before its list would reuse indices already in the list. Every append
40
+ * refreshes both keys to the same deadline.
20
41
  *
21
42
  * @param ttlMs - Minimum lifetime for both keys, in milliseconds. A cache
22
- * whose own TTL is longer, or that never expires, keeps that instead. When
23
- * omitted, the cache's default TTL applies.
43
+ * whose own TTL is longer keeps that instead. An explicit `ttlMs` applies
44
+ * even when the cache's default expiry is disabled: the caller is stating
45
+ * a retention bound for this log, and a log that never expires is never
46
+ * reclaimed. When omitted, the cache's default TTL applies.
47
+ *
48
+ * The default implementation preserves the original zero-based numbering
49
+ * and composes `increment()` + `listPush()`. It is NOT atomic and ignores
50
+ * `ttlMs`. Concurrent appends can land out of index order, causing attached
51
+ * readers and offset replays to miss frames; an old offset can also skip
52
+ * a recreated log whose numbering restarted below it.
24
53
  *
25
- * The default implementation composes `increment()` + `listPush()` (two
26
- * round-trips) and is therefore NOT atomic, and ignores `ttlMs`. Overrides
27
- * should perform both steps in one server-side operation.
54
+ * Do not seed this fallback with `set()`: it can overwrite concurrent
55
+ * allocations, and a stored numeric value need not be an incrementable
56
+ * counter (Convex stores them as different types). Overrides should
57
+ * initialize the counter, allocate and append in one server-side operation.
28
58
  */
29
59
  async listPushIndexed(listKey, counterKey, value, _ttlMs) {
30
60
  const index = await this.increment(counterKey) - 1;
@@ -103,11 +133,11 @@ var InMemoryServerCache = class extends MastraServerCache {
103
133
  async listPushIndexed(listKey, counterKey, value, ttlMs) {
104
134
  const existingCounter = this.cache.get(counterKey);
105
135
  if (existingCounter !== void 0 && typeof existingCounter !== "number") throw new Error(`${counterKey} exists but is not a number`);
106
- const index = typeof existingCounter === "number" ? existingCounter : 0;
136
+ const index = typeof existingCounter === "number" ? existingCounter : Date.now() * 1e3;
107
137
  const existingList = this.cache.get(listKey);
108
138
  if (existingList !== void 0 && !Array.isArray(existingList)) throw new Error(`${listKey} exists but is not an array`);
109
139
  const list = Array.isArray(existingList) ? existingList : [];
110
- const ttl = this.ttlMs > 0 ? Math.max(this.ttlMs, ttlMs ?? 0) : Infinity;
140
+ const ttl = ttlMs !== void 0 && ttlMs > 0 ? Math.max(this.ttlMs, ttlMs) : this.ttlMs > 0 ? this.ttlMs : Infinity;
111
141
  this.cache.set(counterKey, index + 1, { ttl });
112
142
  list.push({
113
143
  ...value,
@@ -43,12 +43,24 @@ type Change = {
43
43
  kind: K;
44
44
  }>, 'knowledgeId' | 'at'>;
45
45
  }[KnowledgeChangeEvent['kind']];
46
+ /** The adapter's own store or transaction view under one {@link emitKnowledgeChanges} returned. Writes through it emit nothing. */
47
+ export declare function unwrapKnowledgeStorage(storage: KnowledgeStorage): KnowledgeStorage;
46
48
  /**
47
- * Wraps `storage` so each page-store write in {@link WRITES} calls `emit` after it resolves. Every
48
- * other member passes through, bound to the real store so adapters' private fields keep working.
49
- * Nothing extra happens while `listening()` is false. Describing or emitting an event never fails a
50
- * write that committed: errors go to `onError`.
49
+ * Wraps `storage` so each page-store write in {@link WRITES} calls `emit` after it resolves. Writes
50
+ * on a `transaction` view are held until that transaction commits and dropped if it rolls back; a
51
+ * nested `transaction` hands its writes to the outer one when it succeeds. While a nested
52
+ * transaction is open, writes through any view of that transaction chain belong to the innermost
53
+ * one (they run inside its savepoint), so they are kept or dropped with it. A chain tracks one
54
+ * innermost transaction, so concurrent nested transactions opened in the same chain are not
55
+ * supported: their events would cross. Every other member passes
56
+ * through, bound to the real store so adapters' private fields keep working. Nothing extra happens
57
+ * while `listening()` is false. Describing or emitting an event never fails a write that committed:
58
+ * errors go to `onError`.
51
59
  */
52
- export declare function emitKnowledgeChanges(storage: KnowledgeStorage, emit: (change: Change) => void, listening: () => boolean, onError: (error: unknown) => void): KnowledgeStorage;
60
+ export declare function emitKnowledgeChanges(storage: KnowledgeStorage, emit: (change: Change) => void, listening: () => boolean, onError: (error: unknown) => void,
61
+ /** Shared by every view of one top-level transaction: where their writes report now. */
62
+ chain?: {
63
+ report: (change: Change) => void;
64
+ }): KnowledgeStorage;
53
65
  export {};
54
66
  //# sourceMappingURL=changes.d.ts.map
@@ -21,6 +21,12 @@ export interface RunKnowledgeImportOptions {
21
21
  maxPasses?: number;
22
22
  /** Ops per flush. Default 200. */
23
23
  bufferSize?: number;
24
+ /**
25
+ * How long the oldest buffered op may wait before it is sent without waiting for a full buffer.
26
+ * A timed flush sends items only; the cursor is still saved only by `ctx.state.set`. A positive
27
+ * number of milliseconds, at most 2147483647. Default 30 seconds.
28
+ */
29
+ flushAfterMs?: number;
24
30
  /** Default 30 seconds. */
25
31
  heartbeatMs?: number;
26
32
  /** Resends of one flush or finish after a 5xx or network error. Default 8. */
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_base = require("../base-BIzR1D3_.cjs");
3
- const require_run_registry = require("../run-registry-Bk6QxNE4.cjs");
3
+ const require_run_registry = require("../run-registry-TOOfO3hT.cjs");
4
4
  const require_tool = require("../tool-CYlT2UA-.cjs");
5
5
  let crypto = require("crypto");
6
6
  let _mastra_schema_compat_schema = require("@mastra/schema-compat/schema");
@@ -79,15 +79,55 @@ const MOVED_PAGE = {
79
79
  mergePages: (input) => input.sourceId
80
80
  };
81
81
  /**
82
- * Wraps `storage` so each page-store write in {@link WRITES} calls `emit` after it resolves. Every
83
- * other member passes through, bound to the real store so adapters' private fields keep working.
84
- * Nothing extra happens while `listening()` is false. Describing or emitting an event never fails a
85
- * write that committed: errors go to `onError`.
82
+ * A view {@link emitKnowledgeChanges} returned answers this key with the store it wraps, so helpers
83
+ * that find a view by identity (`pgKnowledgeTransactionClient`) can look through it. `Symbol.for`, so
84
+ * a store package reads it without importing a newer core.
86
85
  */
87
- function emitKnowledgeChanges(storage, emit, listening, onError) {
86
+ const UNWRAP = Symbol.for("mastra.knowledge.unwrap");
87
+ /** The adapter's own store or transaction view under one {@link emitKnowledgeChanges} returned. Writes through it emit nothing. */
88
+ function unwrapKnowledgeStorage(storage) {
89
+ return storage[UNWRAP] ?? storage;
90
+ }
91
+ /**
92
+ * Wraps `storage` so each page-store write in {@link WRITES} calls `emit` after it resolves. Writes
93
+ * on a `transaction` view are held until that transaction commits and dropped if it rolls back; a
94
+ * nested `transaction` hands its writes to the outer one when it succeeds. While a nested
95
+ * transaction is open, writes through any view of that transaction chain belong to the innermost
96
+ * one (they run inside its savepoint), so they are kept or dropped with it. A chain tracks one
97
+ * innermost transaction, so concurrent nested transactions opened in the same chain are not
98
+ * supported: their events would cross. Every other member passes
99
+ * through, bound to the real store so adapters' private fields keep working. Nothing extra happens
100
+ * while `listening()` is false. Describing or emitting an event never fails a write that committed:
101
+ * errors go to `onError`.
102
+ */
103
+ function emitKnowledgeChanges(storage, emit, listening, onError, chain) {
104
+ const report = (change) => (chain ? chain.report : emit)(change);
88
105
  return new Proxy(storage, { get(target, property) {
106
+ if (property === UNWRAP) return target;
89
107
  const value = Reflect.get(target, property, target);
90
108
  if (typeof value !== "function") return value;
109
+ if (property === "transaction") return async (operation, ...rest) => {
110
+ let held = [];
111
+ const hold = (change) => void held.push(change);
112
+ const shared = chain ?? { report: hold };
113
+ const outer = shared.report;
114
+ let result;
115
+ try {
116
+ result = await value.call(target, (tx) => {
117
+ held = [];
118
+ shared.report = hold;
119
+ return operation(emitKnowledgeChanges(tx, hold, listening, onError, shared));
120
+ }, ...rest);
121
+ } finally {
122
+ shared.report = outer;
123
+ }
124
+ for (const change of held) try {
125
+ report(change);
126
+ } catch (error) {
127
+ onError(error);
128
+ }
129
+ return result;
130
+ };
91
131
  const describe = typeof property === "string" ? WRITES[property] : void 0;
92
132
  if (!describe) return value.bind(target);
93
133
  const moved = typeof property === "string" ? MOVED_PAGE[property] : void 0;
@@ -105,7 +145,7 @@ function emitKnowledgeChanges(storage, emit, listening, onError) {
105
145
  if (!listening()) return result;
106
146
  try {
107
147
  const change = describe(result, input, fromScopeId);
108
- if (change) emit(change);
148
+ if (change) report(change);
109
149
  } catch (error) {
110
150
  onError(error);
111
151
  }
@@ -631,7 +671,8 @@ function sourceError(error) {
631
671
  * @experimental
632
672
  */
633
673
  async function runKnowledgeImport(options) {
634
- const { host, budgetMs = 15e5, graceMs = 18e4, maxPasses = 200, bufferSize = 200, 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, flushAfterMs = 3e4, heartbeatMs = 3e4, maxRetries = 8, hostCallTimeoutMs = 6e4, retryDelayMs = (attempt) => Math.min(250 * 2 ** attempt, 1e4) } = options;
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}`);
635
676
  const started = await within(host.startRun(options.bindingId, options.start), hostCallTimeoutMs, () => new KnowledgeImporterHostError("host call timed out"));
636
677
  if (started.status === "skipped") return started;
637
678
  const { runId, generation } = started;
@@ -642,7 +683,14 @@ async function runKnowledgeImport(options) {
642
683
  let state = { ...started.state };
643
684
  let buffer = [];
644
685
  let stop;
645
- let hostFailure;
686
+ /** Armed while the buffer holds ops; sends them once the oldest has waited `flushAfterMs`. */
687
+ let flushTimer;
688
+ const disarm = () => {
689
+ clearTimeout(flushTimer);
690
+ flushTimer = void 0;
691
+ };
692
+ /** Why a flush ended the run. Every later flush is refused, so no cursor is saved past its ops. */
693
+ let flushFailure;
646
694
  const controller = new AbortController();
647
695
  let deadlineHit;
648
696
  /** Settles at the hard deadline; never otherwise. */
@@ -653,6 +701,7 @@ async function runKnowledgeImport(options) {
653
701
  const halt = (reason) => {
654
702
  if (reason === "stopped") deadlineHit();
655
703
  stop ??= new RunStop(reason);
704
+ disarm();
656
705
  controller.abort(stop);
657
706
  wake();
658
707
  };
@@ -680,6 +729,7 @@ async function runKnowledgeImport(options) {
680
729
  let flushing = Promise.resolve();
681
730
  /** `settle` sends an empty flush, which only runs the host's next settle slice. */
682
731
  function flush(staged, settle = false) {
732
+ disarm();
683
733
  const ops = buffer;
684
734
  buffer = [];
685
735
  const next = flushing.then(async () => {
@@ -690,7 +740,14 @@ async function runKnowledgeImport(options) {
690
740
  ...staged ? { state: staged } : {}
691
741
  };
692
742
  const seq = lastSeq + 1;
693
- const digest = await knowledgeImporterFlushDigest(body);
743
+ let digest;
744
+ try {
745
+ digest = await knowledgeImporterFlushDigest(body);
746
+ } catch (error) {
747
+ flushFailure = { code: "importer_error" };
748
+ halt("flush");
749
+ throw error;
750
+ }
694
751
  if (stop) throw stop;
695
752
  const request = {
696
753
  runId,
@@ -706,11 +763,11 @@ async function runKnowledgeImport(options) {
706
763
  refused.push(...receipt.refused.slice(0, MAX_RECEIPT_REFUSALS - refused.length));
707
764
  } catch (error) {
708
765
  if (!isRetryable(error)) unsettledSeq = void 0;
709
- hostFailure = {
766
+ flushFailure = {
710
767
  code: "importer_error",
711
768
  retryable: isRetryable(error)
712
769
  };
713
- halt("host");
770
+ halt("flush");
714
771
  throw stop;
715
772
  }
716
773
  unsettledSeq = void 0;
@@ -727,6 +784,10 @@ async function runKnowledgeImport(options) {
727
784
  if (stop) throw stop;
728
785
  buffer.push(op);
729
786
  if (buffer.length >= bufferSize) await flush();
787
+ else if (!flushTimer) {
788
+ flushTimer = setTimeout(() => flush().catch(() => {}), flushAfterMs);
789
+ flushTimer.unref?.();
790
+ }
730
791
  };
731
792
  const finish = async (request) => {
732
793
  const result = await finishRun(host, {
@@ -844,6 +905,7 @@ async function runKnowledgeImport(options) {
844
905
  }
845
906
  } finally {
846
907
  clearInterval(heartbeat);
908
+ disarm();
847
909
  }
848
910
  if (!stop || stop.reason !== "stopped") await Promise.race([flushing, deadlinePassed]);
849
911
  clearTimeout(hardStop);
@@ -856,7 +918,7 @@ async function runKnowledgeImport(options) {
856
918
  backlog: false,
857
919
  error: { code: "stopped" }
858
920
  });
859
- const error = stop?.reason === "host" ? hostFailure : failure;
921
+ const error = stop?.reason === "flush" ? flushFailure : failure;
860
922
  if (error) return finish({
861
923
  outcome: "failed",
862
924
  backlog: false,
@@ -2382,7 +2444,7 @@ function createLocalKnowledgeImporterHost(writer, options) {
2382
2444
  });
2383
2445
  await reclaimStaleRuns(importers, binding.id);
2384
2446
  if (start?.admit) try {
2385
- await start.admit(tx);
2447
+ await start.admit(unwrapKnowledgeStorage(tx));
2386
2448
  } catch (error) {
2387
2449
  throw new AdmitRefusal(error);
2388
2450
  }
@@ -4292,8 +4354,8 @@ var Knowledge = class extends require_base.MastraBase {
4292
4354
  }
4293
4355
  /**
4294
4356
  * Calls `listener` after each committed write made through this instance's store
4295
- * (`getStorage()`): tool writes, host writes and scope creation. Writes made on a store obtained
4296
- * some other way aren't seen. Events carry ids, not content and not access: anything that relays
4357
+ * (`getStorage()`): tool writes, host writes, importer runs and scope creation. Writes in a
4358
+ * transaction are reported once it commits. Writes made on a store obtained some other way aren't seen. Events carry ids, not content and not access: anything that relays
4297
4359
  * them to people must re-read each page under that person's read scope. Returns an unsubscribe.
4298
4360
  */
4299
4361
  onChange(listener) {