@mastra/core 1.87.0-alpha.12 → 1.87.0-alpha.14

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 (584) hide show
  1. package/dist/agent/active-run-signal-queues.d.ts +49 -0
  2. package/dist/agent/agent.d.ts +17 -1
  3. package/dist/agent/durable/abort-transport.d.ts +1 -1
  4. package/dist/agent/durable/durable-agent.d.ts +1 -0
  5. package/dist/agent/durable/execution-engine.d.ts +12 -0
  6. package/dist/agent/durable/index.cjs +1 -1
  7. package/dist/agent/durable/index.js +1 -1
  8. package/dist/agent/durable/preparation.d.ts +17 -0
  9. package/dist/agent/durable/stored-signal-drain.d.ts +100 -0
  10. package/dist/agent/durable/types.d.ts +37 -0
  11. package/dist/agent/durable/utils/resolve-runtime.d.ts +11 -0
  12. package/dist/agent/durable/utils/serialize-state.d.ts +1 -0
  13. package/dist/agent/durable/workflows/create-durable-agentic-workflow.d.ts +1 -0
  14. package/dist/agent/durable/workflows/durable-loop-builder.d.ts +5 -0
  15. package/dist/agent/durable/workflows/finalize-run.d.ts +6 -0
  16. package/dist/agent/durable/workflows/shared/message-list-state.d.ts +6 -2
  17. package/dist/agent/durable/workflows/shared/schemas.d.ts +2 -0
  18. package/dist/agent/durable/workflows/steps/llm-execution.d.ts +1 -0
  19. package/dist/agent/index.cjs +2 -2
  20. package/dist/agent/index.js +2 -2
  21. package/dist/agent/signals.d.ts +7 -3
  22. package/dist/agent/stored-run-signals.d.ts +93 -0
  23. package/dist/agent/stored-signals.d.ts +40 -0
  24. package/dist/agent/streams/abort-transport.d.ts +10 -1
  25. package/dist/agent/streams/constants.d.ts +9 -0
  26. package/dist/agent/streams/publisher.d.ts +3 -1
  27. package/dist/agent/thread-stream-runtime.d.ts +46 -4
  28. package/dist/agent/tool-name.d.ts +21 -0
  29. package/dist/agent-builder/ee/index.cjs +1 -1
  30. package/dist/agent-builder/ee/index.js +1 -1
  31. package/dist/agent-controller/index.cjs +1 -1
  32. package/dist/agent-controller/index.js +1 -1
  33. package/dist/agent-controller/types.d.ts +6 -0
  34. package/dist/{agent-controller-DfeTRuBc.js → agent-controller-FSjSZ_iD.js} +11 -9
  35. package/dist/{agent-controller-BcN7r3yI.cjs → agent-controller-k4B293tu.cjs} +11 -9
  36. package/dist/background-tasks/index.cjs +1 -1
  37. package/dist/background-tasks/index.js +1 -1
  38. package/dist/background-tasks/manager.d.ts +3 -1
  39. package/dist/background-tasks/workflow-id.d.ts +42 -0
  40. package/dist/{background-tasks-BcU--rXL.js → background-tasks-ClI6oF60.js} +239 -28
  41. package/dist/{background-tasks-DRUHnQOk.cjs → background-tasks-D40Y_iLc.cjs} +262 -27
  42. package/dist/browser/index.cjs +2 -2
  43. package/dist/browser/index.js +2 -2
  44. package/dist/{builder-Bufqrcz3.cjs → builder-C_I6l0US.cjs} +2 -2
  45. package/dist/{builder-TuIc5l7X.js → builder-D00XMm41.js} +2 -2
  46. package/dist/capabilities/302ai.json +197 -197
  47. package/dist/capabilities/abliteratedllm.json +33 -33
  48. package/dist/capabilities/abliteration-ai.json +10 -10
  49. package/dist/capabilities/above.json +22 -22
  50. package/dist/capabilities/adaption.json +7 -7
  51. package/dist/capabilities/adzuki.json +31 -31
  52. package/dist/capabilities/agentrouter.json +4 -4
  53. package/dist/capabilities/agnes.json +4 -4
  54. package/dist/capabilities/ai-router.json +6 -6
  55. package/dist/capabilities/aiand.json +22 -22
  56. package/dist/capabilities/aigrow.json +11 -11
  57. package/dist/capabilities/aimlapi.json +146 -146
  58. package/dist/capabilities/aipg.json +2 -2
  59. package/dist/capabilities/aixy.json +20 -20
  60. package/dist/capabilities/aki-io.json +13 -13
  61. package/dist/capabilities/alibaba-cn.json +126 -90
  62. package/dist/capabilities/alibaba-coding-plan-cn.json +6 -11
  63. package/dist/capabilities/alibaba-coding-plan.json +6 -11
  64. package/dist/capabilities/alibaba-token-plan-cn.json +49 -49
  65. package/dist/capabilities/alibaba-token-plan.json +54 -54
  66. package/dist/capabilities/alibaba.json +87 -61
  67. package/dist/capabilities/ambient.json +14 -14
  68. package/dist/capabilities/amd.json +8 -8
  69. package/dist/capabilities/anthropic.json +42 -42
  70. package/dist/capabilities/anyapi.json +16 -16
  71. package/dist/capabilities/apiko.json +5 -5
  72. package/dist/capabilities/arcee.json +11 -11
  73. package/dist/capabilities/auriko.json +15 -15
  74. package/dist/capabilities/bailing.json +5 -5
  75. package/dist/capabilities/baseten.json +35 -35
  76. package/dist/capabilities/bee.json +3 -3
  77. package/dist/capabilities/berget.json +8 -8
  78. package/dist/capabilities/bothub.json +16 -16
  79. package/dist/capabilities/boundless.json +34 -34
  80. package/dist/capabilities/bumo.json +37 -37
  81. package/dist/capabilities/byteplus.json +29 -29
  82. package/dist/capabilities/cerebras.json +4 -4
  83. package/dist/capabilities/cheapaimodel.json +10 -10
  84. package/dist/capabilities/cheapest-token.json +29 -29
  85. package/dist/capabilities/chutes.json +58 -10
  86. package/dist/capabilities/cline-pass.json +38 -38
  87. package/dist/capabilities/cloudcode.json +6 -6
  88. package/dist/capabilities/cloudferro-sherlock.json +4 -4
  89. package/dist/capabilities/cloudflare-workers-ai.json +16 -16
  90. package/dist/capabilities/commandcode.json +147 -147
  91. package/dist/capabilities/concentrate.json +277 -277
  92. package/dist/capabilities/cortecs.json +102 -102
  93. package/dist/capabilities/crossmodel.json +183 -183
  94. package/dist/capabilities/crusoe.json +17 -17
  95. package/dist/capabilities/daoxe.json +8 -8
  96. package/dist/capabilities/databricks.json +124 -124
  97. package/dist/capabilities/deepinfra.json +101 -101
  98. package/dist/capabilities/deepseek.json +3 -3
  99. package/dist/capabilities/digitalocean.json +116 -116
  100. package/dist/capabilities/dothoosh.json +32 -32
  101. package/dist/capabilities/doubleword.json +30 -30
  102. package/dist/capabilities/edenai.json +290 -290
  103. package/dist/capabilities/empiriolabs.json +162 -162
  104. package/dist/capabilities/engy.json +19 -19
  105. package/dist/capabilities/entrim.json +8 -8
  106. package/dist/capabilities/evroc.json +13 -13
  107. package/dist/capabilities/ezkielyna.json +12 -12
  108. package/dist/capabilities/fastrouter.json +86 -86
  109. package/dist/capabilities/fireworks-ai.json +99 -99
  110. package/dist/capabilities/fortytwo.json +4 -4
  111. package/dist/capabilities/freemodel.json +14 -14
  112. package/dist/capabilities/friendli.json +12 -12
  113. package/dist/capabilities/frogbot.json +91 -91
  114. package/dist/capabilities/gisoo.json +18 -18
  115. package/dist/capabilities/gmicloud.json +19 -19
  116. package/dist/capabilities/google.json +52 -52
  117. package/dist/capabilities/graphn.json +12 -12
  118. package/dist/capabilities/greenpt.json +34 -34
  119. package/dist/capabilities/groq.json +6 -6
  120. package/dist/capabilities/helicone.json +87 -87
  121. package/dist/capabilities/hetzner.json +4 -4
  122. package/dist/capabilities/hopper.json +2 -2
  123. package/dist/capabilities/hostinger-router.json +13 -20
  124. package/dist/capabilities/hpc-ai.json +10 -10
  125. package/dist/capabilities/huawei-maas.json +11 -11
  126. package/dist/capabilities/hubris.json +28 -28
  127. package/dist/capabilities/huggingface.json +92 -85
  128. package/dist/capabilities/hyper.json +18 -18
  129. package/dist/capabilities/impossibl.json +146 -146
  130. package/dist/capabilities/inception.json +2 -2
  131. package/dist/capabilities/inceptron.json +8 -8
  132. package/dist/capabilities/inco.json +4 -4
  133. package/dist/capabilities/infer.json +14 -14
  134. package/dist/capabilities/inferall.json +6 -6
  135. package/dist/capabilities/inference-coop.json +12 -12
  136. package/dist/capabilities/inferenceapis.json +26 -26
  137. package/dist/capabilities/inferris.json +4 -4
  138. package/dist/capabilities/infersia.json +10 -10
  139. package/dist/capabilities/inferx.json +3 -3
  140. package/dist/capabilities/infomaniak.json +3 -3
  141. package/dist/capabilities/io-net.json +4 -4
  142. package/dist/capabilities/isoquant.json +4 -4
  143. package/dist/capabilities/iteracompute.json +55 -55
  144. package/dist/capabilities/jad-ai.json +2 -2
  145. package/dist/capabilities/jalapeno.json +10 -10
  146. package/dist/capabilities/jiekou.json +58 -58
  147. package/dist/capabilities/joingonka.json +4 -4
  148. package/dist/capabilities/jzstoken.json +51 -51
  149. package/dist/capabilities/keln.json +22 -22
  150. package/dist/capabilities/kenari.json +141 -116
  151. package/dist/capabilities/kilo.json +629 -645
  152. package/dist/capabilities/kimi-code-plan-cn.json +6 -6
  153. package/dist/capabilities/kimi-code-plan-global.json +6 -6
  154. package/dist/capabilities/kitani.json +6 -6
  155. package/dist/capabilities/klavo.json +26 -26
  156. package/dist/capabilities/korouter.json +27 -27
  157. package/dist/capabilities/kunavo.json +9 -9
  158. package/dist/capabilities/liquid.json +12 -12
  159. package/dist/capabilities/lithosai.json +3 -3
  160. package/dist/capabilities/llmgateway-providers.json +920 -928
  161. package/dist/capabilities/llmgateway.json +357 -349
  162. package/dist/capabilities/llmtr.json +32 -32
  163. package/dist/capabilities/logits.json +2 -2
  164. package/dist/capabilities/lowrouter.json +48 -48
  165. package/dist/capabilities/lyceum.json +14 -14
  166. package/dist/capabilities/melious.json +9 -9
  167. package/dist/capabilities/merge-gateway.json +276 -276
  168. package/dist/capabilities/meta.json +10 -10
  169. package/dist/capabilities/minimax-cn-coding-plan.json +5 -5
  170. package/dist/capabilities/minimax-cn.json +5 -5
  171. package/dist/capabilities/minimax-coding-plan.json +5 -5
  172. package/dist/capabilities/minimax.json +5 -5
  173. package/dist/capabilities/mistral.json +19 -19
  174. package/dist/capabilities/mixlayer.json +4 -4
  175. package/dist/capabilities/modal.json +14 -14
  176. package/dist/capabilities/model-oracle-ai.json +26 -26
  177. package/dist/capabilities/modelis.json +17 -17
  178. package/dist/capabilities/modular.json +13 -13
  179. package/dist/capabilities/moneo.json +16 -16
  180. package/dist/capabilities/moonshotai-cn.json +6 -6
  181. package/dist/capabilities/moonshotai.json +6 -6
  182. package/dist/capabilities/morph.json +17 -17
  183. package/dist/capabilities/munito-eu.json +6 -6
  184. package/dist/capabilities/munito.json +10 -10
  185. package/dist/capabilities/nan.json +30 -30
  186. package/dist/capabilities/nano-gpt.json +595 -596
  187. package/dist/capabilities/nearai.json +99 -99
  188. package/dist/capabilities/nebius.json +31 -31
  189. package/dist/capabilities/neon.json +126 -126
  190. package/dist/capabilities/neuralwatt.json +43 -43
  191. package/dist/capabilities/nokeep.json +4 -4
  192. package/dist/capabilities/novita-ai.json +123 -123
  193. package/dist/capabilities/nvidia.json +33 -33
  194. package/dist/capabilities/oathbreaker.json +4 -4
  195. package/dist/capabilities/obscurify.json +29 -29
  196. package/dist/capabilities/oci.json +9 -9
  197. package/dist/capabilities/ofox.json +243 -607
  198. package/dist/capabilities/ollama-cloud.json +55 -55
  199. package/dist/capabilities/openai.json +55 -55
  200. package/dist/capabilities/opencode-go.json +96 -94
  201. package/dist/capabilities/openreason.json +4 -4
  202. package/dist/capabilities/openrouter.json +529 -543
  203. package/dist/capabilities/opper.json +29 -29
  204. package/dist/capabilities/orcarouter.json +436 -178
  205. package/dist/capabilities/outerlabs.json +28 -28
  206. package/dist/capabilities/ovhcloud.json +21 -22
  207. package/dist/capabilities/pareto.json +6 -6
  208. package/dist/capabilities/perplexity-agent.json +63 -63
  209. package/dist/capabilities/phala.json +30 -30
  210. package/dist/capabilities/pioneer.json +23 -23
  211. package/dist/capabilities/poe.json +140 -140
  212. package/dist/capabilities/poolside.json +3 -3
  213. package/dist/capabilities/powerspring.json +14 -14
  214. package/dist/capabilities/primalabs.json +7 -7
  215. package/dist/capabilities/prime.json +119 -119
  216. package/dist/capabilities/privatemode-ai.json +10 -10
  217. package/dist/capabilities/proxystacks.json +7 -7
  218. package/dist/capabilities/qiniu-ai.json +15 -15
  219. package/dist/capabilities/refuseless.json +5 -5
  220. package/dist/capabilities/regolo-ai.json +8 -8
  221. package/dist/capabilities/requesty.json +204 -204
  222. package/dist/capabilities/ruapi.json +24 -24
  223. package/dist/capabilities/runcrate.json +15 -15
  224. package/dist/capabilities/runinfra.json +16 -16
  225. package/dist/capabilities/sakana.json +5 -5
  226. package/dist/capabilities/sambanova.json +7 -7
  227. package/dist/capabilities/sandbase.json +21 -21
  228. package/dist/capabilities/sarvam.json +11 -11
  229. package/dist/capabilities/scaleway.json +15 -15
  230. package/dist/capabilities/scnet-token-plan.json +14 -14
  231. package/dist/capabilities/scx-ai.json +26 -26
  232. package/dist/capabilities/sensenova.json +12 -12
  233. package/dist/capabilities/siliconflow-cn.json +54 -54
  234. package/dist/capabilities/siliconflow.json +66 -66
  235. package/dist/capabilities/snowflake-cortex.json +22 -22
  236. package/dist/capabilities/sokkan.json +7 -7
  237. package/dist/capabilities/sparrowcodes.json +23 -23
  238. package/dist/capabilities/standardcompute.json +96 -96
  239. package/dist/capabilities/steadyrouter.json +38 -38
  240. package/dist/capabilities/stepfun-ai-step-plan.json +15 -9
  241. package/dist/capabilities/stepfun-ai.json +22 -8
  242. package/dist/capabilities/stepfun-step-plan.json +15 -8
  243. package/dist/capabilities/stepfun.json +22 -8
  244. package/dist/capabilities/stepping-stone.json +25 -25
  245. package/dist/capabilities/synthetic.json +10 -10
  246. package/dist/capabilities/synthorai.json +24 -24
  247. package/dist/capabilities/teamorouter.json +18 -18
  248. package/dist/capabilities/teapot-router.json +12 -12
  249. package/dist/capabilities/tencent-token-plan-intl.json +20 -20
  250. package/dist/capabilities/tencent-token-plan.json +38 -38
  251. package/dist/capabilities/tencent-tokenhub.json +46 -46
  252. package/dist/capabilities/tensorx.json +52 -52
  253. package/dist/capabilities/tenstorrent.json +8 -8
  254. package/dist/capabilities/the-grid-ai.json +35 -35
  255. package/dist/capabilities/thinkingmachines.json +78 -78
  256. package/dist/capabilities/tinfoil.json +5 -5
  257. package/dist/capabilities/toapis.json +2 -2
  258. package/dist/capabilities/togetherai.json +53 -61
  259. package/dist/capabilities/tokengo.json +23 -23
  260. package/dist/capabilities/tokenify.json +9 -9
  261. package/dist/capabilities/trustedrouter.json +5 -5
  262. package/dist/capabilities/trustedtokens.json +19 -19
  263. package/dist/capabilities/umans-ai-coding-plan.json +15 -15
  264. package/dist/capabilities/umans-ai.json +11 -11
  265. package/dist/capabilities/unrestricted.json +8 -8
  266. package/dist/capabilities/uplinkswitch.json +22 -22
  267. package/dist/capabilities/upstage.json +4 -4
  268. package/dist/capabilities/vancine.json +19 -19
  269. package/dist/capabilities/vercel.json +520 -513
  270. package/dist/capabilities/verda.json +8 -1
  271. package/dist/capabilities/vivgrid.json +81 -81
  272. package/dist/capabilities/volcengine-coding-plan.json +29 -29
  273. package/dist/capabilities/volcengine.json +21 -21
  274. package/dist/capabilities/vultr.json +26 -26
  275. package/dist/capabilities/wafer.ai.json +13 -13
  276. package/dist/capabilities/wallaby.json +4 -4
  277. package/dist/capabilities/wally.json +13 -13
  278. package/dist/capabilities/wandb.json +17 -17
  279. package/dist/capabilities/watt.json +24 -24
  280. package/dist/capabilities/xai.json +4 -4
  281. package/dist/capabilities/xiaomi-token-plan-ams.json +2 -2
  282. package/dist/capabilities/xiaomi-token-plan-cn.json +2 -2
  283. package/dist/capabilities/xiaomi-token-plan-sgp.json +2 -2
  284. package/dist/capabilities/xiaomi.json +2 -2
  285. package/dist/capabilities/xpersona.json +10 -10
  286. package/dist/capabilities/xxapi.json +28 -28
  287. package/dist/capabilities/zai-coding-plan.json +13 -13
  288. package/dist/capabilities/zai.json +28 -28
  289. package/dist/capabilities/zenifra.json +29 -29
  290. package/dist/capabilities/zenmux.json +178 -178
  291. package/dist/capabilities/zerogpu.json +15 -15
  292. package/dist/capabilities/zhipuai-coding-plan.json +6 -6
  293. package/dist/capabilities/zhipuai.json +25 -25
  294. package/dist/capabilities/zro.json +5 -5
  295. package/dist/channels/index.cjs +2 -2
  296. package/dist/channels/index.js +2 -2
  297. package/dist/{channels-MsOnUvU6.cjs → channels-BU5_kAUO.cjs} +1 -1
  298. package/dist/{channels-Cdsqdajh.js → channels-DMSae7xD.js} +1 -1
  299. package/dist/coding-agent/index.cjs +3 -3
  300. package/dist/coding-agent/index.js +3 -3
  301. package/dist/{constants-Bou0hEgY.cjs → constants-CFO8w780.cjs} +8 -0
  302. package/dist/{constants-CFWgIaqA.js → constants-CUv0mU2y.js} +8 -0
  303. package/dist/datasets/index.cjs +2 -2
  304. package/dist/datasets/index.js +2 -2
  305. package/dist/docs/SKILL.md +2 -1
  306. package/dist/docs/assets/SOURCE_MAP.json +1044 -1009
  307. package/dist/docs/references/docs-agents-code-mode.md +2 -2
  308. package/dist/docs/references/docs-agents-human-in-the-loop.md +2 -2
  309. package/dist/docs/references/docs-agents-networks.md +1 -1
  310. package/dist/docs/references/docs-agents-overview.md +6 -6
  311. package/dist/docs/references/docs-agents-processors.md +9 -9
  312. package/dist/docs/references/docs-agents-resumable-streams.md +2 -2
  313. package/dist/docs/references/docs-agents-structured-output.md +6 -6
  314. package/dist/docs/references/docs-agents-tools.md +9 -9
  315. package/dist/docs/references/docs-browser.md +1 -1
  316. package/dist/docs/references/docs-channels.md +5 -5
  317. package/dist/docs/references/docs-classifier.md +1 -1
  318. package/dist/docs/references/docs-connections-a2a.md +1 -1
  319. package/dist/docs/references/docs-connections-acp.md +2 -2
  320. package/dist/docs/references/docs-connections-overview.md +1 -1
  321. package/dist/docs/references/docs-connections-sdk-agents.md +6 -6
  322. package/dist/docs/references/docs-deployment-workers.md +1 -1
  323. package/dist/docs/references/docs-develop.md +1 -1
  324. package/dist/docs/references/docs-evals-custom-scorers.md +1 -1
  325. package/dist/docs/references/docs-evals-multi-turn.md +2 -2
  326. package/dist/docs/references/docs-guides-build-an-eval-loop.md +2 -2
  327. package/dist/docs/references/docs-guides-context-engineering.md +3 -3
  328. package/dist/docs/references/docs-guides-streaming.md +1 -1
  329. package/dist/docs/references/docs-harness-agent-controller.md +6 -3
  330. package/dist/docs/references/docs-harness-background-tasks.md +2 -2
  331. package/dist/docs/references/docs-harness-durable-agents.md +5 -5
  332. package/dist/docs/references/docs-harness-goals.md +2 -2
  333. package/dist/docs/references/docs-harness-schedules.md +35 -1
  334. package/dist/docs/references/docs-knowledge-agents-and-tools.md +2 -2
  335. package/dist/docs/references/docs-knowledge-importers.md +22 -1
  336. package/dist/docs/references/docs-knowledge-overview.md +1 -1
  337. package/dist/docs/references/docs-knowledge-scopes-and-access.md +1 -1
  338. package/dist/docs/references/docs-memory-memory-processors.md +8 -8
  339. package/dist/docs/references/docs-memory-message-history.md +3 -3
  340. package/dist/docs/references/docs-memory-observational-memory.md +1 -1
  341. package/dist/docs/references/docs-memory-semantic-recall.md +2 -2
  342. package/dist/docs/references/docs-memory-working-memory.md +3 -2
  343. package/dist/docs/references/docs-sandbox-overview.md +2 -2
  344. package/dist/docs/references/docs-sandbox-skills.md +1 -1
  345. package/dist/docs/references/docs-server-mastra-client.md +1 -1
  346. package/dist/docs/references/docs-server-mcp.md +23 -0
  347. package/dist/docs/references/docs-server-pubsub.md +21 -1
  348. package/dist/docs/references/docs-server-request-context.md +4 -4
  349. package/dist/docs/references/docs-signals-notifications.md +2 -2
  350. package/dist/docs/references/docs-signals-overview.md +1 -1
  351. package/dist/docs/references/docs-signals-running-across-processes.md +3 -0
  352. package/dist/docs/references/docs-signals-sending-signals.md +7 -7
  353. package/dist/docs/references/docs-signals-signal-providers.md +18 -2
  354. package/dist/docs/references/docs-signals-state-signals.md +1 -0
  355. package/dist/docs/references/docs-signals-thread-streams.md +12 -0
  356. package/dist/docs/references/docs-skills.md +4 -4
  357. package/dist/docs/references/docs-storage.md +12 -12
  358. package/dist/docs/references/docs-studio-editor.md +2 -2
  359. package/dist/docs/references/docs-subagents.md +26 -3
  360. package/dist/docs/references/integrations-agentic-ui-copilotkit.md +1 -1
  361. package/dist/docs/references/integrations-agentic-ui-openui.md +1 -1
  362. package/dist/docs/references/integrations-channels-discord.md +1 -1
  363. package/dist/docs/references/integrations-channels-github.md +1 -1
  364. package/dist/docs/references/integrations-channels-imessage.md +2 -2
  365. package/dist/docs/references/integrations-channels-ring.md +2 -2
  366. package/dist/docs/references/integrations-channels-slack.md +1 -1
  367. package/dist/docs/references/integrations-channels-teams.md +1 -1
  368. package/dist/docs/references/integrations-channels-telegram.md +1 -1
  369. package/dist/docs/references/integrations-channels-whatsapp.md +1 -1
  370. package/dist/docs/references/integrations-tools-firecrawl.md +1 -1
  371. package/dist/docs/references/reference-acp-acp-agent.md +1 -1
  372. package/dist/docs/references/reference-acp-create-acp-tool.md +1 -1
  373. package/dist/docs/references/reference-agent-controller-agent-controller-class.md +3 -1
  374. package/dist/docs/references/reference-agent-controller-session.md +5 -5
  375. package/dist/docs/references/reference-agents-agent.md +40 -14
  376. package/dist/docs/references/reference-agents-channels.md +11 -11
  377. package/dist/docs/references/reference-agents-durable-agent.md +2 -2
  378. package/dist/docs/references/reference-agents-getLLM.md +2 -2
  379. package/dist/docs/references/reference-agents-getMetadata.md +2 -2
  380. package/dist/docs/references/reference-agents-network.md +2 -2
  381. package/dist/docs/references/reference-browser-mastra-browser.md +1 -1
  382. package/dist/docs/references/reference-channels-thread-link.md +1 -1
  383. package/dist/docs/references/reference-classifier-classifier.md +2 -0
  384. package/dist/docs/references/reference-coding-agent-build-base-prompt.md +1 -1
  385. package/dist/docs/references/reference-coding-agent-create-coding-agent.md +7 -7
  386. package/dist/docs/references/reference-configuration.md +15 -14
  387. package/dist/docs/references/reference-core-getAgentById.md +1 -1
  388. package/dist/docs/references/reference-core-mastra-model-gateway.md +1 -1
  389. package/dist/docs/references/reference-datasets-startExperiment.md +1 -1
  390. package/dist/docs/references/reference-editor-mastra-editor.md +2 -2
  391. package/dist/docs/references/reference-file-based-agents-config.md +3 -3
  392. package/dist/docs/references/reference-file-based-agents-schedules.md +1 -1
  393. package/dist/docs/references/reference-file-based-agents-subagents.md +3 -3
  394. package/dist/docs/references/reference-file-based-agents-workspace.md +1 -1
  395. package/dist/docs/references/reference-knowledge-knowledge-class.md +12 -0
  396. package/dist/docs/references/reference-manual-install.md +1 -1
  397. package/dist/docs/references/reference-memory-memory-class.md +3 -3
  398. package/dist/docs/references/reference-memory-observational-memory.md +3 -3
  399. package/dist/docs/references/reference-observability-tracing-bridges-datadog.md +12 -11
  400. package/dist/docs/references/reference-observability-tracing-configuration.md +2 -2
  401. package/dist/docs/references/reference-observability-tracing-exporters-datadog.md +14 -12
  402. package/dist/docs/references/reference-processors-batch-parts-processor.md +1 -1
  403. package/dist/docs/references/reference-processors-classifier-processor.md +2 -2
  404. package/dist/docs/references/reference-processors-cyber-refusal-handler.md +1 -1
  405. package/dist/docs/references/reference-processors-language-detector.md +1 -1
  406. package/dist/docs/references/reference-processors-message-history-processor.md +1 -1
  407. package/dist/docs/references/reference-processors-model-selection-processor.md +3 -3
  408. package/dist/docs/references/reference-processors-moderation-processor.md +4 -4
  409. package/dist/docs/references/reference-processors-pii-detector.md +2 -2
  410. package/dist/docs/references/reference-processors-prefill-error-handler.md +2 -2
  411. package/dist/docs/references/reference-processors-processor-interface.md +19 -8
  412. package/dist/docs/references/reference-processors-prompt-injection-detector.md +1 -1
  413. package/dist/docs/references/reference-processors-provider-history-compat.md +1 -1
  414. package/dist/docs/references/reference-processors-response-cache.md +1 -1
  415. package/dist/docs/references/reference-processors-semantic-recall-processor.md +1 -1
  416. package/dist/docs/references/reference-processors-skill-search-processor.md +1 -1
  417. package/dist/docs/references/reference-processors-skills-processor.md +1 -1
  418. package/dist/docs/references/reference-processors-stream-error-retry-processor.md +3 -3
  419. package/dist/docs/references/reference-processors-system-prompt-scrubber.md +1 -1
  420. package/dist/docs/references/reference-processors-token-limiter-processor.md +3 -3
  421. package/dist/docs/references/reference-processors-tool-call-filter.md +2 -2
  422. package/dist/docs/references/reference-processors-tool-search-processor.md +3 -3
  423. package/dist/docs/references/reference-processors-unicode-normalizer.md +1 -1
  424. package/dist/docs/references/reference-processors-working-memory-processor.md +1 -1
  425. package/dist/docs/references/reference-rag-chunking-and-embedding.md +1 -1
  426. package/dist/docs/references/reference-rag-graph-rag-guide.md +2 -2
  427. package/dist/docs/references/reference-rag-retrieval.md +13 -13
  428. package/dist/docs/references/reference-signals-create-notification-inbox-tool.md +1 -1
  429. package/dist/docs/references/reference-signals-time-signal-provider.md +102 -0
  430. package/dist/docs/references/reference-storage-composite.md +4 -0
  431. package/dist/docs/references/reference-storage-overview.md +29 -29
  432. package/dist/docs/references/reference-tools-create-code-mode.md +1 -1
  433. package/dist/docs/references/reference-tools-vector-query-tool.md +3 -3
  434. package/dist/docs/references/reference-voice-overview.md +28 -28
  435. package/dist/docs/references/reference-voice-speech-to-speech.md +10 -10
  436. package/dist/docs/references/reference-voice-speech-to-text.md +1 -1
  437. package/dist/docs/references/reference-voice-text-to-speech.md +1 -1
  438. package/dist/docs/references/reference-voice-voice.addInstructions.md +1 -1
  439. package/dist/docs/references/reference-voice-voice.listen.md +1 -1
  440. package/dist/docs/references/reference-workers-overview.md +3 -1
  441. package/dist/docs/references/reference-workflows-step.md +1 -1
  442. package/dist/docs/references/reference-workflows-workflow-methods-map.md +1 -1
  443. package/dist/docs/references/reference-workflows-workflow.md +1 -1
  444. package/dist/docs/references/reference-workspace-factory-sandbox.md +2 -0
  445. package/dist/docs/references/reference-workspace-local-filesystem.md +1 -1
  446. package/dist/docs/references/reference-workspace-local-sandbox.md +1 -1
  447. package/dist/docs/references/reference.md +1 -0
  448. package/dist/evals/index.cjs +2 -2
  449. package/dist/evals/index.js +2 -2
  450. package/dist/evals/scoreTraces/index.cjs +2 -2
  451. package/dist/evals/scoreTraces/index.js +2 -2
  452. package/dist/harness/index.cjs +1 -1
  453. package/dist/harness/index.js +1 -1
  454. package/dist/index.cjs +1 -1
  455. package/dist/index.js +1 -1
  456. package/dist/knowledge/importers/overlay.d.ts +32 -0
  457. package/dist/knowledge/importers/sink.d.ts +11 -1
  458. package/dist/knowledge/importers/types.d.ts +9 -0
  459. package/dist/knowledge/index.cjs +551 -87
  460. package/dist/knowledge/index.d.ts +6 -0
  461. package/dist/knowledge/index.js +551 -87
  462. package/dist/knowledge/page-tools.d.ts +2 -0
  463. package/dist/llm/index.cjs +3 -3
  464. package/dist/llm/index.js +3 -3
  465. package/dist/llm/model/provider-types.generated.d.ts +7865 -7877
  466. package/dist/{llm-CS6YY_IV.cjs → llm-C1aiWB6O.cjs} +2 -2
  467. package/dist/{llm-zjtMQn7M.js → llm-D5rGQSnS.js} +2 -2
  468. package/dist/loop/index.cjs +2 -2
  469. package/dist/loop/index.js +2 -2
  470. package/dist/loop/loop-runtime.d.ts +1 -1
  471. package/dist/loop/shared/signal-outcome.d.ts +1 -1
  472. package/dist/loop/shared/steps/signal-drain-core.d.ts +9 -3
  473. package/dist/{manager-BU_lY6kl.cjs → manager-B2z5f39G.cjs} +3 -3
  474. package/dist/{manager-Do0MENhH.js → manager-DxwPLhYJ.js} +3 -3
  475. package/dist/mastra/index.cjs +1 -1
  476. package/dist/mastra/index.js +1 -1
  477. package/dist/{mastra-C-1zIyS5.js → mastra-CHd7UnbI.js} +17 -17
  478. package/dist/{mastra-DYVjsXTO.cjs → mastra-WMuI7TZD.cjs} +17 -17
  479. package/dist/memory/index.cjs +2 -2
  480. package/dist/memory/index.js +2 -2
  481. package/dist/{model-DIzIjDej.js → model-B8DlLHex.js} +1 -1
  482. package/dist/{model-DGFc1hw3.cjs → model-C2CTzjMk.cjs} +1 -1
  483. package/dist/{netlify-CyL6FNsw.cjs → netlify-Dhs0UJul.cjs} +1 -1
  484. package/dist/{netlify-B9mLgxJs.js → netlify-xQFmVbr4.js} +1 -1
  485. package/dist/notifications/index.cjs +1 -1
  486. package/dist/notifications/index.js +1 -1
  487. package/dist/processor-provider/index.cjs +1 -1
  488. package/dist/processor-provider/index.js +1 -1
  489. package/dist/processors/index.cjs +2 -2
  490. package/dist/processors/index.js +2 -2
  491. package/dist/{provider-registry-g9m_fyV8.cjs → provider-registry-CSQPAFzz.cjs} +22244 -22307
  492. package/dist/{provider-registry-DdQoO_jd.js → provider-registry-FxVHWmht.js} +22244 -22307
  493. package/dist/provider-registry.json +22283 -22350
  494. package/dist/{registry-generator-CX6Ev697.js → registry-generator-BzsrHxrr.js} +1 -1
  495. package/dist/{registry-generator-At8J4ZOR.cjs → registry-generator-Dsh7xcz9.cjs} +1 -1
  496. package/dist/{rehydrate-BzD6UX8f.cjs → rehydrate-8q7KX4rD.cjs} +2 -2
  497. package/dist/{rehydrate-DEDxsr6E.js → rehydrate-DV1iO9eZ.js} +2 -2
  498. package/dist/relevance/index.cjs +2 -2
  499. package/dist/relevance/index.js +2 -2
  500. package/dist/{run-registry-PiQTSx2Y.cjs → run-registry-DOlZccsr.cjs} +4703 -2233
  501. package/dist/{run-registry-D22IF5SK.js → run-registry-sTm40Ecv.js} +4704 -2234
  502. package/dist/{scheduler-B-VZUvv_.js → scheduler-0ShtMM1I.js} +71 -21
  503. package/dist/{scheduler-D00X03jQ.cjs → scheduler-CMjK0LoQ.cjs} +82 -20
  504. package/dist/server/types.d.ts +6 -0
  505. package/dist/signals/index.cjs +2 -1
  506. package/dist/signals/index.d.ts +1 -0
  507. package/dist/signals/index.js +2 -2
  508. package/dist/signals/time-signal-provider.d.ts +62 -0
  509. package/dist/signals-BTfT-6DE.js +280 -0
  510. package/dist/signals-CIwzgkvN.cjs +291 -0
  511. package/dist/{source-BVOi8Xhp.cjs → source-BC8Et5qZ.cjs} +7 -0
  512. package/dist/{source-fNa6u1kH.js → source-DYZMfjv3.js} +7 -0
  513. package/dist/storage/constants.cjs +1 -1
  514. package/dist/storage/constants.js +1 -1
  515. package/dist/storage/domains/agents/index.cjs +1 -1
  516. package/dist/storage/domains/agents/index.js +1 -1
  517. package/dist/storage/domains/inmemory-db.d.ts +6 -0
  518. package/dist/storage/domains/knowledge/base.d.ts +22 -4
  519. package/dist/storage/domains/knowledge/inmemory.d.ts +2 -0
  520. package/dist/storage/domains/knowledge/pages.d.ts +8 -0
  521. package/dist/storage/domains/memory/base.d.ts +107 -0
  522. package/dist/storage/domains/memory/index.d.ts +1 -0
  523. package/dist/storage/domains/memory/inmemory.d.ts +36 -0
  524. package/dist/storage/domains/memory/queue-thread.d.ts +36 -0
  525. package/dist/storage/domains/schedules/base.d.ts +31 -2
  526. package/dist/storage/domains/schedules/inmemory.d.ts +9 -2
  527. package/dist/storage/domains/workflows/base.d.ts +14 -0
  528. package/dist/storage/domains/workflows/inmemory.d.ts +4 -1
  529. package/dist/storage/index.cjs +9 -4
  530. package/dist/storage/index.js +5 -5
  531. package/dist/stream/index.cjs +2 -2
  532. package/dist/stream/index.js +2 -2
  533. package/dist/{stream-BbPZavop.cjs → stream-aGuW9AL8.cjs} +88 -2
  534. package/dist/{stream-CoQTdzLm.js → stream-k-Q1NLUs.js} +59 -3
  535. package/dist/test-utils/llm-mock.cjs +1 -1
  536. package/dist/test-utils/llm-mock.js +1 -1
  537. package/dist/tool-loop-agent/index.cjs +1 -1
  538. package/dist/tool-loop-agent/index.js +1 -1
  539. package/dist/{tool-loop-agent-DhQkNDaR.js → tool-loop-agent-CJrysPOR.js} +3 -3
  540. package/dist/{tool-loop-agent-8lyD6O4o.cjs → tool-loop-agent-WcRtGJHn.cjs} +3 -3
  541. package/dist/{utils-DtmyBuBT.cjs → utils-DEzQLxWP.cjs} +1 -1
  542. package/dist/{utils-B-3lET9S.js → utils-DamF4CfD.js} +1 -1
  543. package/dist/utils.cjs +1 -1
  544. package/dist/utils.js +1 -1
  545. package/dist/{validate-vucjWXcz.cjs → validate-CDlONK0o.cjs} +1 -1
  546. package/dist/{validate-CO4rWYyH.js → validate-rum3NMFA.js} +1 -1
  547. package/dist/vector/index.cjs +1 -1
  548. package/dist/vector/index.js +1 -1
  549. package/dist/worker/index.cjs +1 -1
  550. package/dist/worker/index.js +1 -1
  551. package/dist/{worker-BgifMkOw.cjs → worker-6MiKMAqB.cjs} +3 -3
  552. package/dist/{worker-B6CpapAF.js → worker-BnXipQth.js} +2 -2
  553. package/dist/{worker-eUT7GgQ9.cjs → worker-rwal1zI8.cjs} +2 -2
  554. package/dist/{worker-CCpSrXBY.js → worker-st16x0my.js} +3 -3
  555. package/dist/{workflow-B4Tn58DD.js → workflow-BzhYKgc_.js} +25 -33
  556. package/dist/{workflow-BJSrGEEL.cjs → workflow-D2-gn0U0.cjs} +25 -33
  557. package/dist/workflows/builder/index.cjs +1 -1
  558. package/dist/workflows/builder/index.js +1 -1
  559. package/dist/workflows/evented/execution-engine.d.ts +3 -1
  560. package/dist/workflows/evented/index.cjs +1 -1
  561. package/dist/workflows/evented/index.js +1 -1
  562. package/dist/workflows/evented/setup-warning.d.ts +11 -0
  563. package/dist/workflows/evented/workflow-event-processor/index.d.ts +10 -2
  564. package/dist/workflows/evented/workflow-event-processor/loop.d.ts +1 -1
  565. package/dist/workflows/evented/workflow-event-processor/parallel.d.ts +2 -2
  566. package/dist/workflows/evented/workflow-event-processor/sleep.d.ts +2 -2
  567. package/dist/workflows/evented/workflow.d.ts +6 -2
  568. package/dist/workflows/handlers/entry.d.ts +8 -0
  569. package/dist/workflows/index.cjs +7 -5
  570. package/dist/workflows/index.js +6 -6
  571. package/dist/workflows/run-storage.d.ts +11 -2
  572. package/dist/workflows/scheduler/claim.d.ts +51 -0
  573. package/dist/workflows/scheduler/index.d.ts +2 -0
  574. package/dist/workflows/types.d.ts +6 -0
  575. package/dist/workflows/workflow.d.ts +85 -10
  576. package/dist/workspace/filesystem/local-filesystem.d.ts +13 -0
  577. package/dist/workspace/index.cjs +1 -1
  578. package/dist/workspace/index.js +1 -1
  579. package/dist/{workspace-CnmmMou8.js → workspace-Ct2kAiDv.js} +50 -11
  580. package/dist/{workspace-C5lXteRU.cjs → workspace-CzzrnE6Q.cjs} +50 -11
  581. package/package.json +7 -7
  582. package/src/llm/model/provider-types.generated.d.ts +7865 -7877
  583. package/dist/signals-B1JSj-Ew.cjs +0 -58
  584. package/dist/signals-De9VnwL2.js +0 -53
@@ -11,6 +11,56 @@ import { z } from "zod/v4";
11
11
  * workflow → evented → workflows/index → agent`.
12
12
  */
13
13
  const BACKGROUND_TASK_WORKFLOW_ID = "__background-task";
14
+ /** Path of the attempt step (inside the attempt loop) in a stored run's steps. */
15
+ const RUN_ATTEMPT_STEP_PATH = `${BACKGROUND_TASK_WORKFLOW_ID}__attempt.run-attempt`;
16
+ /**
17
+ * Marks the attempt step's suspend data as an envelope this workflow wrote:
18
+ * the data the run would have saved without one, kept as is, beside the
19
+ * attempt that saved it, which crash recovery checks.
20
+ */
21
+ const SUSPEND_ENVELOPE_KEY = "__backgroundTaskSuspension";
22
+ function isSuspendEnvelope(suspendData) {
23
+ return typeof suspendData === "object" && suspendData !== null && suspendData[SUSPEND_ENVELOPE_KEY] === 1 && isTaskAttempt(suspendData.attempt);
24
+ }
25
+ function isTaskAttempt(value) {
26
+ return typeof value === "object" && value !== null && typeof value.ownerId === "string" && typeof value.startedAt === "number";
27
+ }
28
+ function suspendEnvelope(data, attempt) {
29
+ return {
30
+ [SUSPEND_ENVELOPE_KEY]: 1,
31
+ attempt,
32
+ data
33
+ };
34
+ }
35
+ /** The attempt step's suspend data as the run saved it, out of its envelope if it has one. */
36
+ function unwrapSuspendData(suspendData) {
37
+ return isSuspendEnvelope(suspendData) ? suspendData.data : suspendData;
38
+ }
39
+ /**
40
+ * What the tool suspended with, from the attempt step's suspend data. That
41
+ * data may carry the internal `suspendedToolRunId` bridge for a delegated
42
+ * sub-agent (see `workflow.ts`); it is stripped back off.
43
+ */
44
+ function toolSuspendPayload(suspendData) {
45
+ const data = unwrapSuspendData(suspendData);
46
+ if (!data || typeof data !== "object" || !("suspendedToolRunId" in data)) return data;
47
+ const { suspendedToolRunId: _bridge, ...rest } = data;
48
+ return Object.keys(rest).length > 0 ? rest : void 0;
49
+ }
50
+ /** The attempt that saved a suspension, or `undefined` for data saved without an envelope. */
51
+ function suspendedAttempt(suspendData) {
52
+ return isSuspendEnvelope(suspendData) ? suspendData.attempt : void 0;
53
+ }
54
+ let lastAttemptStart = Number.NEGATIVE_INFINITY;
55
+ /**
56
+ * The `startedAt` for a task's next attempt: later than the task's last one,
57
+ * even when a worker's clock is behind, and never one this process already
58
+ * gave out, even within the same millisecond.
59
+ */
60
+ function nextAttemptStart(previous) {
61
+ lastAttemptStart = Math.max(Date.now(), (previous?.getTime() ?? Number.NEGATIVE_INFINITY) + 1, lastAttemptStart + 1);
62
+ return new Date(lastAttemptStart);
63
+ }
14
64
  // src/background-tasks/manager.ts
15
65
  const TOPIC_DISPATCH = "background-tasks";
16
66
  const TOPIC_RESULT = "background-tasks-result";
@@ -24,6 +74,18 @@ function workflowRunError(result) {
24
74
  if (result.tripwire?.reason) return new Error(result.tripwire.reason);
25
75
  return /* @__PURE__ */ new Error(`Background task workflow run ended with status '${result.status}'`);
26
76
  }
77
+ function isTerminalStatus(status) {
78
+ switch (status) {
79
+ case "completed":
80
+ case "failed":
81
+ case "cancelled":
82
+ case "timed_out": return true;
83
+ case "pending":
84
+ case "running":
85
+ case "suspended": return false;
86
+ default: return status;
87
+ }
88
+ }
27
89
  function toTaskError(err) {
28
90
  if (err && typeof err === "object" && typeof err.message === "string") {
29
91
  const { message, stack } = err;
@@ -100,6 +162,8 @@ var BackgroundTaskManager = class {
100
162
  pinSweepPage = 0;
101
163
  runningSweepPage = 0;
102
164
  #settlingRuns = /* @__PURE__ */ new Set();
165
+ #suspendPayloads = /* @__PURE__ */ new Map();
166
+ #executionHooks = /* @__PURE__ */ new Map();
103
167
  workerCallback;
104
168
  resultCallback;
105
169
  shuttingDown = false;
@@ -185,7 +249,7 @@ var BackgroundTaskManager = class {
185
249
  if (handled) await ack?.();
186
250
  };
187
251
  if (this.#mastra) {
188
- const { buildBackgroundTaskWorkflow } = await import("./workflow-B4Tn58DD.js");
252
+ const { buildBackgroundTaskWorkflow } = await import("./workflow-BzhYKgc_.js");
189
253
  const workflow = buildBackgroundTaskWorkflow(this);
190
254
  if (!this.#mastra.__hasInternalWorkflow("__background-task")) this.#mastra.__registerInternalWorkflow(workflow);
191
255
  }
@@ -244,6 +308,10 @@ var BackgroundTaskManager = class {
244
308
  this.activeAbortControllers.set(taskId, controller);
245
309
  return true;
246
310
  }
311
+ /** @internal — called by the workflow step when the task's tool calls `suspend()`. */
312
+ noteSuspendRequested(taskId, suspendPayload) {
313
+ this.#suspendPayloads.set(taskId, suspendPayload);
314
+ }
247
315
  /** @internal — read by workflow error classification during graceful shutdown. */
248
316
  isShuttingDown() {
249
317
  return this.shuttingDown;
@@ -351,12 +419,16 @@ var BackgroundTaskManager = class {
351
419
  }
352
420
  }
353
421
  async cancel(taskId) {
422
+ return this.#cancel(taskId, "request");
423
+ }
424
+ async #cancel(taskId, reason) {
354
425
  if (this.initPromise) await this.initPromise;
355
426
  const storage = await this.getStorage();
356
427
  let task = await storage.getTask(taskId);
357
428
  if (!task) throw new Error(`Task not found: ${taskId}`);
358
429
  while (true) {
359
- if (task.status === "completed" || task.status === "failed" || task.status === "cancelled" || task.status === "timed_out") return;
430
+ if (isTerminalStatus(task.status)) return;
431
+ if (reason === "shutdown" && (task.status === "suspended" || task.status === "running" && (task.maxRetries > 0 || this.#suspendPayloads.has(taskId)))) return;
360
432
  const previousStatus = task.status;
361
433
  const isProcessAffine = this.taskContexts.has(taskId);
362
434
  if (!await storage.updateTask(taskId, {
@@ -392,7 +464,7 @@ var BackgroundTaskManager = class {
392
464
  } catch (error) {
393
465
  this.#mastra?.getLogger?.()?.warn(`background-task cancellation callback failed for ${taskId}:`, error);
394
466
  }
395
- if (previousStatus === "suspended") await this.runLocalExecutionHook(cancelledTask);
467
+ if (previousStatus === "suspended") await this.#clearOpenRequest(cancelledTask);
396
468
  }
397
469
  this.deregisterTaskContext(taskId);
398
470
  if (previousStatus === "running") {
@@ -562,10 +634,9 @@ var BackgroundTaskManager = class {
562
634
  */
563
635
  async waitForNextTask(taskIds, options) {
564
636
  const storage = await this.getStorage();
565
- const isTerminal = (status) => status === "completed" || status === "failed" || status === "cancelled" || status === "timed_out";
566
637
  for (const id of taskIds) {
567
638
  const task = await storage.getTask(id);
568
- if (task && isTerminal(task.status)) return task;
639
+ if (task && isTerminalStatus(task.status)) return task;
569
640
  }
570
641
  return new Promise((resolve, reject) => {
571
642
  const startTime = Date.now();
@@ -597,7 +668,7 @@ var BackgroundTaskManager = class {
597
668
  pollInterval = setInterval(async () => {
598
669
  for (const id of taskIds) {
599
670
  const task = await storage.getTask(id);
600
- if (task && isTerminal(task.status)) {
671
+ if (task && isTerminalStatus(task.status)) {
601
672
  cleanup();
602
673
  resolve(task);
603
674
  return;
@@ -836,7 +907,7 @@ var BackgroundTaskManager = class {
836
907
  const ownedTaskIds = [...leasesToRelease];
837
908
  try {
838
909
  const storage = await this.getStorage();
839
- await this.#waitForShutdownStep("background task lease release", Promise.allSettled(ownedTaskIds.map((taskId) => storage.updateTask(taskId, {
910
+ await this.#waitForShutdownStep("background task lease release", Promise.allSettled(ownedTaskIds.map((taskId) => storage.updateTask(taskId, this.#suspendPayloads.has(taskId) ? { leaseExpiresAt: void 0 } : {
840
911
  ownerId: void 0,
841
912
  leaseExpiresAt: void 0
842
913
  }, { expectedOwnerId: this.workerId }))));
@@ -859,10 +930,10 @@ var BackgroundTaskManager = class {
859
930
  const storage = await this.getStorage();
860
931
  const task = await storage.getTask(taskId);
861
932
  if (task?.status !== "running") {
862
- await this.cancel(taskId);
933
+ await this.#cancel(taskId, "shutdown");
863
934
  return;
864
935
  }
865
- if (task.maxRetries > 0) return;
936
+ if (task.maxRetries > 0 || this.#suspendPayloads.has(taskId)) return;
866
937
  const fence = {
867
938
  expectedStatus: "running",
868
939
  expectedOwnerId: this.workerId
@@ -1006,16 +1077,20 @@ var BackgroundTaskManager = class {
1006
1077
  const isRunningRedelivery = task.status === "running" && deliveryAttempt > 1;
1007
1078
  if (!(isRestart ? task.status === "running" : task.status === "pending" || isRunningRedelivery)) return true;
1008
1079
  if (isRunningRedelivery && task.leaseExpiresAt && task.leaseExpiresAt.getTime() > Date.now()) return task.ownerId === this.workerId;
1080
+ if (isRunningRedelivery && !isRestart && await this.#recoverSavedSuspension(storage, task, {
1081
+ expectedStatus: "running",
1082
+ expectedOwnerId: task.ownerId ?? null,
1083
+ expectedLeaseExpiresAt: task.leaseExpiresAt ?? null
1084
+ })) return true;
1009
1085
  if (task.status === "pending" && task.ownerId && task.ownerId !== this.workerId) return true;
1010
1086
  const pinnedHere = task.status === "pending" && task.ownerId === this.workerId;
1011
1087
  const retryCount = task.status === "running" ? Math.max(task.retryCount, deliveryAttempt - 1) : task.retryCount;
1012
- const now = /* @__PURE__ */ new Date();
1013
1088
  if (!await storage.updateTask(taskId, {
1014
1089
  status: "running",
1015
- startedAt: now,
1090
+ startedAt: nextAttemptStart(task.startedAt),
1016
1091
  retryCount,
1017
1092
  ownerId: this.workerId,
1018
- leaseExpiresAt: new Date(now.getTime() + this.config.leaseDurationMs)
1093
+ leaseExpiresAt: new Date(Date.now() + this.config.leaseDurationMs)
1019
1094
  }, isRestart ? { expectedStatus: task.status } : pinnedHere ? {
1020
1095
  expectedStatus: "pending",
1021
1096
  expectedOwnerId: this.workerId
@@ -1051,7 +1126,7 @@ var BackgroundTaskManager = class {
1051
1126
  return true;
1052
1127
  }
1053
1128
  try {
1054
- if (runningTask) this.runLocalExecutionHook(runningTask);
1129
+ if (runningTask) this.#queueExecutionHook(taskId, () => this.runLocalExecutionHook(runningTask)).ran;
1055
1130
  const workflow = this.#mastra.__getInternalWorkflow(BACKGROUND_TASK_WORKFLOW_ID);
1056
1131
  const prevWorkflowRun = isRestart ? await workflow.getWorkflowRunById(taskId) : void 0;
1057
1132
  if (this.shuttingDown) return false;
@@ -1060,12 +1135,12 @@ var BackgroundTaskManager = class {
1060
1135
  if (this.shuttingDown) return false;
1061
1136
  const runPromise = shouldRestart ? run.restart() : run.start({ inputData: { taskId } });
1062
1137
  const action = shouldRestart ? "restart" : "start";
1138
+ const settled = { released: false };
1063
1139
  this.#trackSettlingRun(runPromise.then((result) => {
1064
- if (result.status !== "suspended") this.#deleteSettledRun(workflow, taskId);
1065
- if (result.status !== "success" && result.status !== "suspended") return this.failUnsettledTask(taskId, action, workflowRunError(result));
1140
+ if (result.status === "suspended") return this.#storeSuspension(workflow, taskId, action, settled);
1141
+ return this.#settleEndedRun(workflow, taskId, action, result);
1066
1142
  }, (err) => this.failUnsettledTask(taskId, action, err)).finally(() => {
1067
- this.ownedLeases.delete(taskId);
1068
- this.releaseLocalSlot(taskId);
1143
+ if (!settled.released) this.#releaseRun(taskId);
1069
1144
  this.drainPending();
1070
1145
  }));
1071
1146
  } catch (error) {
@@ -1111,7 +1186,7 @@ var BackgroundTaskManager = class {
1111
1186
  }
1112
1187
  if (!await storage.updateTask(taskId, {
1113
1188
  status: "running",
1114
- startedAt: /* @__PURE__ */ new Date(),
1189
+ startedAt: nextAttemptStart(task.startedAt),
1115
1190
  suspendPayload: void 0,
1116
1191
  suspendedAt: void 0,
1117
1192
  ownerId: this.workerId,
@@ -1129,7 +1204,7 @@ var BackgroundTaskManager = class {
1129
1204
  const resumedTask = await storage.getTask(taskId);
1130
1205
  if (resumedTask) {
1131
1206
  await this.publishLifecycleEvent("task.resumed", resumedTask);
1132
- await this.runLocalExecutionHook(resumedTask);
1207
+ await this.#clearOpenRequest(resumedTask);
1133
1208
  }
1134
1209
  if (!this.#mastra) {
1135
1210
  this.releaseLocalSlot(taskId);
@@ -1153,12 +1228,12 @@ var BackgroundTaskManager = class {
1153
1228
  });
1154
1229
  return false;
1155
1230
  }
1231
+ const settled = { released: false };
1156
1232
  this.#trackSettlingRun(run.resume({ resumeData }).then((result) => {
1157
- if (result.status !== "suspended") this.#deleteSettledRun(workflow, taskId);
1158
- if (result.status !== "success" && result.status !== "suspended") return this.failUnsettledTask(taskId, "resume", workflowRunError(result));
1233
+ if (result.status === "suspended") return this.#storeSuspension(workflow, taskId, "resume", settled);
1234
+ return this.#settleEndedRun(workflow, taskId, "resume", result);
1159
1235
  }, (err) => this.failUnsettledTask(taskId, "resume", err)).finally(() => {
1160
- this.ownedLeases.delete(taskId);
1161
- this.releaseLocalSlot(taskId);
1236
+ if (!settled.released) this.#releaseRun(taskId);
1162
1237
  this.drainPending();
1163
1238
  }));
1164
1239
  return true;
@@ -1171,6 +1246,82 @@ var BackgroundTaskManager = class {
1171
1246
  this.#mastra?.getLogger?.()?.error("Background task workflow run settlement failed:", error);
1172
1247
  });
1173
1248
  }
1249
+ /** Stops renewing a task's lease and frees its slot once its run no longer runs it. */
1250
+ #releaseRun(taskId) {
1251
+ this.#suspendPayloads.delete(taskId);
1252
+ this.ownedLeases.delete(taskId);
1253
+ this.releaseLocalSlot(taskId);
1254
+ }
1255
+ /**
1256
+ * Stores a task as `suspended` once its run's suspended snapshot is saved,
1257
+ * then runs the suspend hooks and publishes `task.suspended`. Storing it any
1258
+ * earlier lets a crash or shutdown catch a task the run can't resume (#30226).
1259
+ * The run's lease and slot are released as soon as it is stored, before the
1260
+ * hooks: an answer can arrive while they run, and its resumed run takes them.
1261
+ */
1262
+ async #storeSuspension(workflow, taskId, action, settled) {
1263
+ const suspendPayload = this.#suspendPayloads.get(taskId);
1264
+ const suspendedAt = /* @__PURE__ */ new Date();
1265
+ let suspended = false;
1266
+ try {
1267
+ suspended = await (await this.getStorage()).updateTask(taskId, {
1268
+ status: "suspended",
1269
+ suspendPayload,
1270
+ suspendedAt,
1271
+ ownerId: void 0,
1272
+ leaseExpiresAt: void 0
1273
+ }, {
1274
+ expectedStatus: "running",
1275
+ expectedOwnerId: this.workerId
1276
+ });
1277
+ if (suspended) {
1278
+ this.#releaseRun(taskId);
1279
+ settled.released = true;
1280
+ }
1281
+ } catch (error) {
1282
+ await this.failUnsettledTask(taskId, action, error);
1283
+ }
1284
+ const storage = await this.getStorage();
1285
+ if (!suspended) {
1286
+ const current = await storage.getTask(taskId);
1287
+ if (!current || isTerminalStatus(current.status)) this.#deleteSettledRun(workflow, taskId);
1288
+ return;
1289
+ }
1290
+ this.drainPending();
1291
+ const stillSuspended = async () => {
1292
+ const current = await storage.getTask(taskId);
1293
+ return current?.status === "suspended" && current.suspendedAt?.getTime() === suspendedAt.getTime() ? current : void 0;
1294
+ };
1295
+ const suspendedTask = await stillSuspended();
1296
+ if (!suspendedTask) return;
1297
+ try {
1298
+ await this.#queueExecutionHook(taskId, () => this.runLocalSuspendHooks(suspendedTask)).ran;
1299
+ } catch (error) {
1300
+ this.#mastra?.getLogger?.()?.warn(`background-task suspend hook failed for ${taskId}:`, error);
1301
+ }
1302
+ const announced = await stillSuspended();
1303
+ if (announced) await this.publishLifecycleEvent("task.suspended", announced);
1304
+ }
1305
+ /**
1306
+ * Settles a run that ended without suspending: fails the task if the run
1307
+ * left it unsettled, then deletes the stored run once the task has ended.
1308
+ */
1309
+ async #settleEndedRun(workflow, taskId, action, result) {
1310
+ if (result.status !== "success") await this.failUnsettledTask(taskId, action, workflowRunError(result));
1311
+ this.#deleteEndedRun(workflow, taskId);
1312
+ }
1313
+ /**
1314
+ * Deletes a run's stored state only once its task has ended or is gone. A
1315
+ * task that has not ended keeps it, even while this worker still holds it:
1316
+ * one left running for recovery can be restarted by another worker, whose
1317
+ * suspended snapshot a late delete from here would remove.
1318
+ */
1319
+ #deleteEndedRun(workflow, taskId) {
1320
+ this.#trackSettlingRun((async () => {
1321
+ const task = await (await this.getStorage()).getTask(taskId);
1322
+ if (!task || isTerminalStatus(task.status)) this.#deleteSettledRun(workflow, taskId);
1323
+ })());
1324
+ }
1174
1325
  #deleteSettledRun(workflow, taskId) {
1175
1326
  this.#trackSettlingRun(workflow.deleteWorkflowRunById(taskId).catch((error) => {
1176
1327
  this.#mastra?.getLogger?.()?.warn(`Failed to delete workflow run for background task ${taskId}:`, error);
@@ -1322,8 +1473,7 @@ var BackgroundTaskManager = class {
1322
1473
  });
1323
1474
  }
1324
1475
  /** @internal — also called by the workflow-engine step bodies in workflow.ts */
1325
- async runLocalExecutionHook(task) {
1326
- const ctx = this.taskContexts.get(task.id);
1476
+ async runLocalExecutionHook(task, ctx = this.taskContexts.get(task.id)) {
1327
1477
  if (!ctx) return;
1328
1478
  try {
1329
1479
  await ctx.onExecution?.({
@@ -1339,6 +1489,37 @@ var BackgroundTaskManager = class {
1339
1489
  } catch {}
1340
1490
  }
1341
1491
  /**
1492
+ * Runs a task's `onExecution` hook after the ones already queued for it. A
1493
+ * suspend hook records the open request after an await (an agent transforms
1494
+ * the payload first), so an answer or cancel arriving meanwhile clears it
1495
+ * only once it is written, instead of having it written back afterwards.
1496
+ * `queued` says whether the hook had to wait for an earlier one.
1497
+ */
1498
+ #queueExecutionHook(taskId, hook) {
1499
+ const previous = this.#executionHooks.get(taskId);
1500
+ const ran = previous ? previous.then(hook) : hook();
1501
+ const tail = ran.catch(() => {});
1502
+ this.#executionHooks.set(taskId, tail);
1503
+ tail.then(() => {
1504
+ if (this.#executionHooks.get(taskId) === tail) this.#executionHooks.delete(taskId);
1505
+ });
1506
+ return {
1507
+ ran,
1508
+ queued: previous !== void 0
1509
+ };
1510
+ }
1511
+ /**
1512
+ * Runs the execution hook that drops a task's open request, after any suspend
1513
+ * hook still recording it. It waits for that hook only through the queue:
1514
+ * an answer must not be held up by a suspend hook that never returns.
1515
+ */
1516
+ async #clearOpenRequest(task) {
1517
+ const ctx = this.taskContexts.get(task.id);
1518
+ if (!ctx) return;
1519
+ const { ran, queued } = this.#queueExecutionHook(task.id, () => this.runLocalExecutionHook(task, ctx));
1520
+ if (!queued) await ran;
1521
+ }
1522
+ /**
1342
1523
  * Another process cancelled a task this one dispatched. Run its execution
1343
1524
  * hook, so the dispatcher drops an open request it recorded for the task,
1344
1525
  * and release the task's context. A cancel made here has already done both.
@@ -1347,7 +1528,7 @@ var BackgroundTaskManager = class {
1347
1528
  if (!this.taskContexts.has(taskId)) return;
1348
1529
  const task = await (await this.getStorage()).getTask(taskId);
1349
1530
  if (task?.status !== "cancelled") return;
1350
- await this.runLocalExecutionHook(task);
1531
+ await this.#clearOpenRequest(task);
1351
1532
  this.deregisterTaskContext(taskId);
1352
1533
  }
1353
1534
  async handleResult(event) {
@@ -1669,12 +1850,12 @@ var BackgroundTaskManager = class {
1669
1850
  expectedOwnerId: task.ownerId ?? null,
1670
1851
  expectedLeaseExpiresAt: task.leaseExpiresAt ?? null
1671
1852
  };
1853
+ if (await this.#recoverSavedSuspension(storage, task, fence)) return false;
1672
1854
  const handedBack = !task.ownerId && task.maxRetries > 0;
1673
1855
  if (handedBack || task.retryCount < task.maxRetries) {
1674
1856
  const requeued = await storage.updateTask(task.id, {
1675
1857
  status: "pending",
1676
1858
  retryCount: handedBack ? task.retryCount : task.retryCount + 1,
1677
- startedAt: void 0,
1678
1859
  ownerId: void 0,
1679
1860
  leaseExpiresAt: void 0
1680
1861
  }, fence);
@@ -1684,6 +1865,36 @@ var BackgroundTaskManager = class {
1684
1865
  return false;
1685
1866
  }
1686
1867
  /**
1868
+ * A worker can die after its run saved the suspended snapshot but before it
1869
+ * stored the task as `suspended` (see `#storeSuspension`). That run can still
1870
+ * be resumed, so the suspension it saved is stored instead of failing the
1871
+ * task or running its tool from the start again. Only a suspension saved by
1872
+ * the attempt the task still names (its owner and `startedAt`) is restored:
1873
+ * a resume or a new claim names a new attempt, so a suspension already
1874
+ * answered or superseded is ignored. Returns whether the task was handled here (including by another
1875
+ * worker winning the fence).
1876
+ */
1877
+ async #recoverSavedSuspension(storage, task, fence) {
1878
+ if (!this.#mastra?.__hasInternalWorkflow("__background-task")) return false;
1879
+ const run = await this.#mastra.__getInternalWorkflow(BACKGROUND_TASK_WORKFLOW_ID).getWorkflowRunById(task.id, { fields: ["steps"] });
1880
+ if (!run || run.isFromInMemory || run.status !== "suspended") return false;
1881
+ const step = run.steps?.[RUN_ATTEMPT_STEP_PATH];
1882
+ if (!step || Array.isArray(step) || step.status !== "suspended" || step.suspendedAt === void 0) return false;
1883
+ const attempt = suspendedAttempt(step.suspendPayload);
1884
+ if (!attempt || attempt.ownerId !== task.ownerId || attempt.startedAt !== task.startedAt?.getTime()) return false;
1885
+ if (await storage.updateTask(task.id, {
1886
+ status: "suspended",
1887
+ suspendPayload: toolSuspendPayload(step.suspendPayload),
1888
+ suspendedAt: new Date(step.suspendedAt),
1889
+ ownerId: void 0,
1890
+ leaseExpiresAt: void 0
1891
+ }, fence)) {
1892
+ const suspended = await storage.getTask(task.id);
1893
+ if (suspended?.status === "suspended") await this.publishLifecycleEvent("task.suspended", suspended);
1894
+ }
1895
+ return true;
1896
+ }
1897
+ /**
1687
1898
  * Fails a task whose worker is gone and reports it with `task.failed`, so
1688
1899
  * `onTaskFailed` and stream subscribers hear about it like any other failure.
1689
1900
  * Only the caller whose fenced write lands publishes, so peers racing on the
@@ -2241,4 +2452,4 @@ ${GUIDELINES}
2241
2452
 
2242
2453
  ${EMPTY_FIELD_NOTE}`;
2243
2454
  }
2244
- export { isToolBackgroundEligible as a, createBackgroundTask as c, isModelBackgroundOverrideAllowed as i, BackgroundTaskManager as l, backgroundOverrideJsonSchema as n, resolveBackgroundConfig as o, backgroundOverrideZodSchema as r, sanitizeToolArguments as s, generateBackgroundTaskSystemPrompt as t, BACKGROUND_TASK_WORKFLOW_ID as u };
2455
+ export { isToolBackgroundEligible as a, createBackgroundTask as c, nextAttemptStart as d, suspendEnvelope as f, isModelBackgroundOverrideAllowed as i, BackgroundTaskManager as l, unwrapSuspendData as m, backgroundOverrideJsonSchema as n, resolveBackgroundConfig as o, toolSuspendPayload as p, backgroundOverrideZodSchema as r, sanitizeToolArguments as s, generateBackgroundTaskSystemPrompt as t, BACKGROUND_TASK_WORKFLOW_ID as u };