@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
@@ -1,5 +1,5 @@
1
1
  import { t as MastraBase } from "../base-CKLWBhDo.js";
2
- import { $i as parseKnowledgePageRef, $o as getStorageSource, $t as PINNED_READ_MEMO_KEY, Ai as inspectKnowledgeSchema, An as knowledgeMemoryScopes, Bi as MAX_KNOWLEDGE_PAGE_DESCRIPTION_TOKENS, Ci as KnowledgeNotFoundError, Cn as syncKnowledgePageBodyLinks, Cr as expandKnowledgeScope, Di as KnowledgeUnsupportedCapabilityError, Dn as knowledgeRoleOn, Dr as knowledgeSemanticIdempotencyKey, Ei as KnowledgeTransactionDeadlineError, En as knowledgeReadScopeFor, Er as knowledgeSemanticDocumentId, Fi as KnowledgePageKeyConflictError, Fn as encodeKnowledgeScopeId, Gi as assertKnowledgeNoteTextWithinBound, Hi as MAX_KNOWLEDGE_PAGE_LINK_REF_LENGTH, Ii as MAX_KNOWLEDGE_MOVE_PAGES, In as buildKnowledgeInstructions, Ji as knowledgeLinkRefKey, Ki as assertKnowledgePageDescriptionWithinBound, Li as MAX_KNOWLEDGE_NOTE_TOKENS, Mi as KnowledgeMoveTooLargeError, Mn as knowledgeScopeAddress, Ni as KnowledgePageDepthError, Nn as strongerKnowledgeRole, Oi as assertKnowledgeSchemaCompatible, On as KnowledgeDeclarationError, Or as knowledgeVisibleScopeKeys, Pi as KnowledgePageHasChildrenError, Pn as decodeKnowledgeScopeId, Qi as knowledgeScopeReadable, Qo as augmentWithInit, Ri as MAX_KNOWLEDGE_PAGE_BODY_LINKS, Si as KnowledgeConflictError, Sn as repairKnowledgeLinks, Sr as createKnowledgeNodeCursor, Ti as KnowledgeStorage, Tn as knowledgeAccessGrants, Tr as knowledgeScopeKey, Ui as MAX_KNOWLEDGE_PAGE_LIST_LIMIT, Vi as MAX_KNOWLEDGE_PAGE_LINKS, Wi as MAX_KNOWLEDGE_PIN_LIST_DEPTH, Xi as knowledgePinDepth, Yi as knowledgePagePath, Zi as knowledgePositionBetween, _i as KnowledgeImporterBindingConflictError, _n as KnowledgeLinkRepairUnsupportedError, _r as assertKnowledgeCeilingRaised, an as knowledgeRunPrincipals, bi as KNOWLEDGE_STORAGE_CONTRACT_VERSION, bn as refreshKnowledgeLinksTo, br as assertKnowledgeScopeWithinCeiling, cn as addKnowledgeNote, dn as removeKnowledgePage, ea as KnowledgeInvalidCursorError, en as knowledgeDeliveredPins, fn as updateKnowledgeNote, gi as InMemoryKnowledgeStorage, gn as KnowledgeLinkRefreshIncompleteError, gr as MAX_KNOWLEDGE_SCOPE_TAGS, hr as MAX_KNOWLEDGE_RECORD_TEXT_LENGTH, in as KnowledgeRunScopesError, ji as parseKnowledgeWikilinks, jn as knowledgeRunScopes, ki as createKnowledgeUlid, kn as compileKnowledgeScopes, kr as parseKnowledgeNodeCursor, ln as moveKnowledgePage, mn as KnowledgeSemanticIndex, mr as MAX_KNOWLEDGE_NODE_DESCRIPTION_LENGTH, nn as heldScopes, on as knowledgeAgentScopes, pn as upsertKnowledgePage, qi as canonicalKnowledgeName, rn as KnowledgeRun, sn as knowledgePersonaScopes, ta as knowledgePageKeyProblem, tn as buildKnowledgePageTools, un as removeKnowledgeNote, vi as KnowledgeImporterRunStateError, vn as canRepairKnowledgeLinksInBatch, vr as assertKnowledgeDescriptionWithinBound, wi as KnowledgeSchemaResetRequiredError, wn as updateKnowledgeLinks, wr as isKnowledgeScopeVisible, xi as KNOWLEDGE_STORAGE_SCHEMA_VERSION, xn as reindexKnowledgeLinks, xr as canonicalizeKnowledgeScope, yi as KnowledgeImportersStorage, yn as knowledgeSubtree, yr as assertKnowledgeRecordTextWithinBound, zi as MAX_KNOWLEDGE_PAGE_DEPTH } from "../run-registry-D22IF5SK.js";
2
+ import { $i as parseKnowledgePageRef, $o as getStorageSource, $t as PINNED_READ_MEMO_KEY, Ai as inspectKnowledgeSchema, An as knowledgeMemoryScopes, Bi as MAX_KNOWLEDGE_PAGE_DESCRIPTION_TOKENS, Ci as KnowledgeNotFoundError, Cn as syncKnowledgePageBodyLinks, Cr as expandKnowledgeScope, Di as KnowledgeUnsupportedCapabilityError, Dn as knowledgeRoleOn, Dr as knowledgeSemanticIdempotencyKey, Ei as KnowledgeTransactionDeadlineError, En as knowledgeReadScopeFor, Er as knowledgeSemanticDocumentId, Fi as KnowledgePageKeyConflictError, Fn as encodeKnowledgeScopeId, Gi as assertKnowledgeNoteTextWithinBound, Hi as MAX_KNOWLEDGE_PAGE_LINK_REF_LENGTH, Ii as MAX_KNOWLEDGE_MOVE_PAGES, In as buildKnowledgeInstructions, Ji as knowledgeLinkRefKey, Ki as assertKnowledgePageDescriptionWithinBound, Li as MAX_KNOWLEDGE_NOTE_TOKENS, Mi as KnowledgeMoveTooLargeError, Mn as knowledgeScopeAddress, Ni as KnowledgePageDepthError, Nn as strongerKnowledgeRole, Oi as assertKnowledgeSchemaCompatible, On as KnowledgeDeclarationError, Or as knowledgeVisibleScopeKeys, Pi as KnowledgePageHasChildrenError, Pn as decodeKnowledgeScopeId, Qi as knowledgeScopeReadable, Qo as augmentWithInit, Ri as MAX_KNOWLEDGE_PAGE_BODY_LINKS, Si as KnowledgeConflictError, Sn as repairKnowledgeLinks, Sr as createKnowledgeNodeCursor, Ti as KnowledgeStorage, Tn as knowledgeAccessGrants, Tr as knowledgeScopeKey, Ui as MAX_KNOWLEDGE_PAGE_LIST_LIMIT, Vi as MAX_KNOWLEDGE_PAGE_LINKS, Wi as MAX_KNOWLEDGE_PIN_LIST_DEPTH, Xi as knowledgePinDepth, Yi as knowledgePagePath, Zi as knowledgePositionBetween, _i as KnowledgeImporterBindingConflictError, _n as KnowledgeLinkRepairUnsupportedError, _r as assertKnowledgeCeilingRaised, an as knowledgeRunPrincipals, bi as KNOWLEDGE_STORAGE_CONTRACT_VERSION, bn as refreshKnowledgeLinksTo, br as assertKnowledgeScopeWithinCeiling, cn as addKnowledgeNote, dn as removeKnowledgePage, ea as KnowledgeInvalidCursorError, en as knowledgeDeliveredPins, fn as updateKnowledgeNote, gi as InMemoryKnowledgeStorage, gn as KnowledgeLinkRefreshIncompleteError, gr as MAX_KNOWLEDGE_SCOPE_TAGS, hr as MAX_KNOWLEDGE_RECORD_TEXT_LENGTH, in as KnowledgeRunScopesError, ji as parseKnowledgeWikilinks, jn as knowledgeRunScopes, ki as createKnowledgeUlid, kn as compileKnowledgeScopes, kr as parseKnowledgeNodeCursor, ln as moveKnowledgePage, mn as KnowledgeSemanticIndex, mr as MAX_KNOWLEDGE_NODE_DESCRIPTION_LENGTH, nn as heldScopes, on as knowledgeAgentScopes, pn as upsertKnowledgePage, qi as canonicalKnowledgeName, rn as KnowledgeRun, sn as knowledgePersonaScopes, ta as knowledgePageKeyProblem, tn as buildKnowledgePageTools, un as removeKnowledgeNote, vi as KnowledgeImporterRunStateError, vn as canRepairKnowledgeLinksInBatch, vr as assertKnowledgeDescriptionWithinBound, wi as KnowledgeSchemaResetRequiredError, wn as updateKnowledgeLinks, wr as isKnowledgeScopeVisible, xi as KNOWLEDGE_STORAGE_SCHEMA_VERSION, xn as reindexKnowledgeLinks, xr as canonicalizeKnowledgeScope, yi as KnowledgeImportersStorage, yn as knowledgeSubtree, yr as assertKnowledgeRecordTextWithinBound, zi as MAX_KNOWLEDGE_PAGE_DEPTH } from "../run-registry-sTm40Ecv.js";
3
3
  import { standardSchemaToJSONSchema, toStandardSchema } from "../schema/index.js";
4
4
  import { i as createStandardSchemaIssuesError } from "../tool-Z3bykc1m.js";
5
5
  import { randomUUID } from "crypto";
@@ -324,7 +324,8 @@ const DECLARATION_FIELDS = {
324
324
  required: true
325
325
  },
326
326
  parent: { kind: "nullableString" },
327
- fallbackParent: { kind: "nonEmpty" }
327
+ fallbackParent: { kind: "nonEmpty" },
328
+ path: { kind: "segments" }
328
329
  };
329
330
  const ITEM_FIELDS = {
330
331
  ...DECLARATION_FIELDS,
@@ -370,6 +371,9 @@ function checkFields(value, fields, where) {
370
371
  case "aliases":
371
372
  out[key] = checkDenseArray(field, at).map((alias, index) => checkString(alias, `${at}[${index}]`, true));
372
373
  break;
374
+ case "segments":
375
+ out[key] = checkDenseArray(field, at).map((segment, index) => checkString(segment, `${at}[${index}]`));
376
+ break;
373
377
  case "links": out[key] = checkDenseArray(field, at).map((link, index) => checkFields(link, {
374
378
  sourceId: {
375
379
  kind: "nonEmpty",
@@ -1093,6 +1097,16 @@ var KnowledgeImportNotGatheredError = class extends Error {
1093
1097
  }
1094
1098
  };
1095
1099
  /** The flush needs a call the overlay doesn't model: it falls back to the per-op path. */
1100
+ /**
1101
+ * The gather read the rows once, its plan writing pages only in place, and the decide pass went to
1102
+ * create, move or delete a page anyway: one more pass reads them again under the lock.
1103
+ */
1104
+ var KnowledgeImportRereadRequiredError = class extends Error {
1105
+ constructor(what) {
1106
+ super(`The batched import flush needs its rows read again under the lock: ${what}`);
1107
+ this.name = "KnowledgeImportRereadRequiredError";
1108
+ }
1109
+ };
1096
1110
  var KnowledgeImportBatchUnsupportedError = class extends Error {
1097
1111
  call;
1098
1112
  constructor(call) {
@@ -1102,7 +1116,31 @@ var KnowledgeImportBatchUnsupportedError = class extends Error {
1102
1116
  }
1103
1117
  };
1104
1118
  const nodeKey = (bindingId, sourceId) => `${bindingId}\u0000${sourceId}`;
1105
- const pathKey = (scopeId, path) => JSON.stringify([scopeId, ...path]);
1119
+ /** The key {@link ImportOverlayRows.paths} holds a scope path under. */
1120
+ const importPathKey = (scopeId, path) => JSON.stringify([scopeId, ...path]);
1121
+ const pathKey = importPathKey;
1122
+ /**
1123
+ * The key path of each live page whose whole chain to its scope is among `pages`, to that page: a
1124
+ * path a read chain already answers, with no `getPagesByPaths`. One key path has one live page.
1125
+ */
1126
+ function importChainPaths(pages) {
1127
+ const out = /* @__PURE__ */ new Map();
1128
+ for (const page of pages.values()) {
1129
+ if (!page || page.isScope) continue;
1130
+ const path = [];
1131
+ let at = page;
1132
+ while (at && !at.isScope) {
1133
+ if (at.key === void 0 || at.deletedAt || at.mergedInto || path.length >= 10) {
1134
+ at = void 0;
1135
+ break;
1136
+ }
1137
+ path.unshift(at.key);
1138
+ at = at.parentId ? pages.get(at.parentId) : null;
1139
+ }
1140
+ if (at) out.set(pathKey(at.id, path), page.id);
1141
+ }
1142
+ return out;
1143
+ }
1106
1144
  const childKey = (parentId, key) => `${parentId}\u0000${key}`;
1107
1145
  const byPosition = (a, b) => a.position < b.position ? -1 : a.position > b.position ? 1 : a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
1108
1146
  /** UTF-8 byte order, as the stores sort source IDs. */
@@ -1146,7 +1184,9 @@ const copyRows = (rows) => ({
1146
1184
  tooLarge: new Set(rows.tooLarge),
1147
1185
  linkTargets: new Set(rows.linkTargets),
1148
1186
  tooManyLinkers: new Set(rows.tooManyLinkers),
1149
- ...rows.bindings ? { bindings: rows.bindings } : {}
1187
+ ...rows.bindings ? { bindings: rows.bindings } : {},
1188
+ ...rows.inPlace ? { inPlace: true } : {},
1189
+ ...rows.readOnce ? { readOnce: true } : {}
1150
1190
  });
1151
1191
  const copyState = (state) => ({
1152
1192
  rows: copyRows(state.rows),
@@ -1267,6 +1307,17 @@ var ImportOverlay = class {
1267
1307
  #setPage(id, page) {
1268
1308
  this.#state.rows.pages.set(id, page);
1269
1309
  this.#childIndex = void 0;
1310
+ this.#chainPaths = void 0;
1311
+ }
1312
+ /** {@link importChainPaths} of the working copy, kept like the child index. */
1313
+ #chainPaths;
1314
+ #pathFromChains(key) {
1315
+ const { pages } = this.#state.rows;
1316
+ if (this.#chainPaths?.pages !== pages) this.#chainPaths = {
1317
+ pages,
1318
+ byPath: importChainPaths(pages)
1319
+ };
1320
+ return this.#chainPaths.byPath.get(key);
1270
1321
  }
1271
1322
  /** Live ordinary children by position, once gathered. */
1272
1323
  #children(parentId) {
@@ -1369,6 +1420,8 @@ var ImportOverlay = class {
1369
1420
  if (path.length === 0) return null;
1370
1421
  const key = pathKey(scopeId, path);
1371
1422
  if (!rows().paths.has(key)) {
1423
+ const id = this.#pathFromChains(key);
1424
+ if (id) return this.#page(id);
1372
1425
  this.missing.paths.set(key, {
1373
1426
  scopeId,
1374
1427
  path
@@ -1384,6 +1437,7 @@ var ImportOverlay = class {
1384
1437
  for (const id of unlocked) this.missing.locks.add(id);
1385
1438
  throw new KnowledgeImportNotGatheredError(`locks ${unlocked.join(", ")}`);
1386
1439
  }
1440
+ return [];
1387
1441
  },
1388
1442
  listNotes: async ({ pageId }) => {
1389
1443
  if (!rows().notes.has(pageId)) {
@@ -1393,6 +1447,7 @@ var ImportOverlay = class {
1393
1447
  return { notes: rows().notes.get(pageId).filter((note) => !note.deletedAt) };
1394
1448
  },
1395
1449
  createPage: async (input) => {
1450
+ if (rows().readOnce) throw new KnowledgeImportRereadRequiredError("createPage");
1396
1451
  if (input.id !== void 0 || input.position !== void 0) throw new KnowledgeImportBatchUnsupportedError("createPage with id or position");
1397
1452
  if (!input.name.trim()) throw new Error("Knowledge page name must not be empty");
1398
1453
  assertKnowledgePageDescriptionWithinBound(input.description || void 0);
@@ -1523,6 +1578,7 @@ var ImportOverlay = class {
1523
1578
  return ids;
1524
1579
  },
1525
1580
  movePage: async (input) => {
1581
+ if (rows().readOnce) throw new KnowledgeImportRereadRequiredError("movePage");
1526
1582
  if (input.position !== void 0) throw new KnowledgeImportBatchUnsupportedError("movePage with a position");
1527
1583
  const page = this.#livePage(input.id);
1528
1584
  if (page.isScope) throw new Error(`Knowledge scope page ${page.id} can't be moved`);
@@ -1543,7 +1599,12 @@ var ImportOverlay = class {
1543
1599
  if (parentDepth + 1 + Math.max(...subtree.map((entry) => entry.depth)) > 10) throw new KnowledgePageDepthError(page.id);
1544
1600
  const scopeId = parent.isScope ? parent.id : parent.scopeId;
1545
1601
  if (scopeId !== page.scopeId) throw new KnowledgeImportBatchUnsupportedError("movePage across scopes");
1546
- if (page.key !== void 0) {
1602
+ const key = input.key ?? page.key;
1603
+ if (input.key !== void 0) {
1604
+ const problem = knowledgePageKeyProblem(input.key);
1605
+ if (problem) throw new Error(problem);
1606
+ }
1607
+ if (key !== void 0) {
1547
1608
  const parentKeys = parent.isScope ? {
1548
1609
  scopeId: parent.id,
1549
1610
  path: []
@@ -1551,10 +1612,10 @@ var ImportOverlay = class {
1551
1612
  if (!parentKeys) throw new KnowledgeImportBatchUnsupportedError("movePage under a broken chain");
1552
1613
  const clash = await impl.getPageByPath({
1553
1614
  scopeId,
1554
- path: [...parentKeys.path, page.key],
1615
+ path: [...parentKeys.path, key],
1555
1616
  read: "all"
1556
1617
  });
1557
- if (clash && clash.id !== page.id) throw new KnowledgePageKeyConflictError(page.key, parent.id);
1618
+ if (clash && clash.id !== page.id) throw new KnowledgePageKeyConflictError(key, parent.id);
1558
1619
  }
1559
1620
  if (this.#state.moved.has(page.id)) throw new KnowledgeImportBatchUnsupportedError("a second move of a page");
1560
1621
  const position = this.#nextPosition(parent.id);
@@ -1562,6 +1623,7 @@ var ImportOverlay = class {
1562
1623
  const at = now();
1563
1624
  const moved = {
1564
1625
  ...page,
1626
+ ...key !== void 0 ? { key } : {},
1565
1627
  parentId: parent.id,
1566
1628
  position,
1567
1629
  version: page.version + 1,
@@ -1581,6 +1643,7 @@ var ImportOverlay = class {
1581
1643
  fromScopeId: page.scopeId,
1582
1644
  expectedVersion: input.expectedVersion,
1583
1645
  parentId: parent.id,
1646
+ ...input.key !== void 0 ? { key: input.key } : {},
1584
1647
  scopeId,
1585
1648
  depth: parentDepth + 1,
1586
1649
  position,
@@ -1589,6 +1652,7 @@ var ImportOverlay = class {
1589
1652
  return structuredClone(moved);
1590
1653
  },
1591
1654
  deletePage: async (input) => {
1655
+ if (rows().readOnce) throw new KnowledgeImportRereadRequiredError("deletePage");
1592
1656
  const page = this.#livePage(input.id);
1593
1657
  if (page.isScope) throw new Error(`Knowledge scope page ${page.id} can't be deleted`);
1594
1658
  if (page.version !== input.expectedVersion) throw new KnowledgeConflictError(page.id);
@@ -1711,6 +1775,17 @@ var ImportOverlay = class {
1711
1775
  const key = rows().nodesByPage.get(pageId);
1712
1776
  return key ? structuredClone(this.#node(key)) : null;
1713
1777
  },
1778
+ getNodesByPages: async (pageIds) => {
1779
+ const unread = [...new Set(pageIds)].filter((pageId) => !rows().nodesByPage.has(pageId));
1780
+ if (unread.length) {
1781
+ for (const pageId of unread) this.missing.nodesByPage.add(pageId);
1782
+ throw new KnowledgeImportNotGatheredError(`nodes of pages ${unread.join(", ")}`);
1783
+ }
1784
+ return [...new Set(pageIds)].flatMap((pageId) => {
1785
+ const node = rows().nodesByPage.get(pageId) ? this.#node(rows().nodesByPage.get(pageId)) : null;
1786
+ return node ? [structuredClone(node)] : [];
1787
+ });
1788
+ },
1714
1789
  saveNode: async (node) => {
1715
1790
  const key = nodeKey(node.bindingId, node.sourceId);
1716
1791
  const mapped = rows().nodesByPage.get(node.pageId);
@@ -1817,36 +1892,84 @@ async function readImportRows(input) {
1817
1892
  ...missing?.pages ?? [],
1818
1893
  ...missing?.locks ?? []
1819
1894
  ]));
1820
- const plan = input.plan(rows);
1821
- const roots = [.../* @__PURE__ */ new Set([...plan.subtrees, ...missing?.subtrees ?? []])].filter((id) => !rows.complete.has(id));
1895
+ let plan = input.plan(rows);
1822
1896
  const carried = [];
1823
- if (roots.length) {
1824
- const subtrees = await storage.getPageSubtrees({
1825
- rootIds: roots,
1826
- limit: 499
1827
- });
1828
- for (const root of roots) {
1829
- const pages = subtrees[root];
1830
- if (!pages) {
1831
- rows.tooLarge.add(root);
1832
- continue;
1897
+ let held = [];
1898
+ let settled = false;
1899
+ for (let stage = 0; stage < GATHER_PLAN_STAGES; stage++) {
1900
+ if (stage) plan = input.plan(rows);
1901
+ const before = rows.pages.size + rows.paths.size + rows.complete.size;
1902
+ const roots = [.../* @__PURE__ */ new Set([...plan.subtrees, ...stage ? [] : missing?.subtrees ?? []])].filter((id) => !rows.complete.has(id) && !rows.tooLarge.has(id));
1903
+ if (roots.length) {
1904
+ const subtrees = await storage.getPageSubtrees({
1905
+ rootIds: roots,
1906
+ limit: 499
1907
+ });
1908
+ for (const root of roots) {
1909
+ const pages = subtrees[root];
1910
+ if (!pages) {
1911
+ rows.tooLarge.add(root);
1912
+ continue;
1913
+ }
1914
+ rows.complete.add(root);
1915
+ for (const page of pages) {
1916
+ rows.pages.set(page.id, page);
1917
+ rows.complete.add(page.id);
1918
+ carried.push(page.id);
1919
+ }
1833
1920
  }
1834
- rows.complete.add(root);
1835
- for (const page of pages) {
1836
- rows.pages.set(page.id, page);
1837
- rows.complete.add(page.id);
1838
- carried.push(page.id);
1921
+ const unmapped = carried.filter((id) => !rows.nodesByPage.has(id));
1922
+ if (unmapped.length) {
1923
+ for (const id of unmapped) rows.nodesByPage.set(id, null);
1924
+ for (const node of await importers.getNodesByPages(unmapped)) {
1925
+ const key = nodeKey(node.bindingId, node.sourceId);
1926
+ rows.nodes.set(key, node);
1927
+ rows.nodesByPage.set(node.pageId, key);
1928
+ }
1839
1929
  }
1840
1930
  }
1841
- const unmapped = carried.filter((id) => !rows.nodesByPage.has(id));
1842
- if (unmapped.length) {
1843
- for (const id of unmapped) rows.nodesByPage.set(id, null);
1844
- for (const node of await importers.getNodesByPages(unmapped)) {
1931
+ const paths = new Map(plan.paths.map((each) => [pathKey(each.scopeId, each.path), each]));
1932
+ if (!stage) for (const [key, each] of missing?.paths ?? []) paths.set(key, each);
1933
+ for (const key of [...paths.keys()]) if (rows.paths.has(key)) paths.delete(key);
1934
+ const byScope = /* @__PURE__ */ new Map();
1935
+ for (const [key, { scopeId, path }] of paths) {
1936
+ if (path.length === 0) continue;
1937
+ byScope.set(scopeId, [...byScope.get(scopeId) ?? [], {
1938
+ key,
1939
+ path
1940
+ }]);
1941
+ }
1942
+ for (const [scopeId, entries] of byScope) {
1943
+ const found = await storage.getPagesByPaths({
1944
+ scopeId,
1945
+ paths: entries.map((each) => each.path),
1946
+ read: "all"
1947
+ });
1948
+ entries.forEach((each, i) => {
1949
+ const page = found[i] ?? null;
1950
+ rows.paths.set(each.key, page?.id ?? null);
1951
+ if (page && !rows.pages.has(page.id)) rows.pages.set(page.id, page);
1952
+ });
1953
+ }
1954
+ held = [...rows.paths.values()].filter((id) => !!id);
1955
+ await addChains(new Set(held.map((id) => rows.pages.get(id)?.parentId).filter((id) => !!id)));
1956
+ const byPage = [...new Set([
1957
+ ...held,
1958
+ ...plan.holders ?? [],
1959
+ ...stage ? [] : missing?.nodesByPage ?? []
1960
+ ].filter((id) => !rows.nodesByPage.has(id)))];
1961
+ if (byPage.length) {
1962
+ for (const id of byPage) rows.nodesByPage.set(id, null);
1963
+ for (const node of await importers.getNodesByPages(byPage)) {
1845
1964
  const key = nodeKey(node.bindingId, node.sourceId);
1846
1965
  rows.nodes.set(key, node);
1847
1966
  rows.nodesByPage.set(node.pageId, key);
1848
1967
  }
1849
1968
  }
1969
+ if (rows.pages.size + rows.paths.size + rows.complete.size === before) {
1970
+ settled = true;
1971
+ break;
1972
+ }
1850
1973
  }
1851
1974
  const targets = new Set(plan.linkTargets);
1852
1975
  for (const id of carried) {
@@ -1878,39 +2001,6 @@ async function readImportRows(input) {
1878
2001
  await addChains(new Set([...linkers, ...reached].map((node) => node.pageId)));
1879
2002
  }
1880
2003
  if (plan.bindings || missing?.bindings.size) rows.bindings ??= await importers.listBindings();
1881
- const paths = new Map(plan.paths.map((each) => [pathKey(each.scopeId, each.path), each]));
1882
- for (const [key, each] of missing?.paths ?? []) paths.set(key, each);
1883
- const byScope = /* @__PURE__ */ new Map();
1884
- for (const [key, { scopeId, path }] of paths) {
1885
- if (path.length === 0) continue;
1886
- byScope.set(scopeId, [...byScope.get(scopeId) ?? [], {
1887
- key,
1888
- path
1889
- }]);
1890
- }
1891
- for (const [scopeId, entries] of byScope) {
1892
- const found = await storage.getPagesByPaths({
1893
- scopeId,
1894
- paths: entries.map((each) => each.path),
1895
- read: "all"
1896
- });
1897
- entries.forEach((each, i) => {
1898
- const page = found[i] ?? null;
1899
- rows.paths.set(each.key, page?.id ?? null);
1900
- if (page && !rows.pages.has(page.id)) rows.pages.set(page.id, page);
1901
- });
1902
- }
1903
- const held = [...rows.paths.values()].filter((id) => !!id);
1904
- await addChains(new Set(held.map((id) => rows.pages.get(id)?.parentId).filter((id) => !!id)));
1905
- const byPage = [...new Set([...held, ...missing?.nodesByPage ?? []].filter((id) => !rows.nodesByPage.has(id)))];
1906
- if (byPage.length) {
1907
- for (const id of byPage) rows.nodesByPage.set(id, null);
1908
- for (const node of await importers.getNodesByPages(byPage)) {
1909
- const key = nodeKey(node.bindingId, node.sourceId);
1910
- rows.nodes.set(key, node);
1911
- rows.nodesByPage.set(node.pageId, key);
1912
- }
1913
- }
1914
2004
  const notes = [.../* @__PURE__ */ new Set([
1915
2005
  ...plan.notes,
1916
2006
  ...held,
@@ -1928,8 +2018,11 @@ async function readImportRows(input) {
1928
2018
  const last = await storage.getLastChildPositions({ parentIds: positions });
1929
2019
  for (const id of positions) rows.positions.set(id, last[id] ?? null);
1930
2020
  }
2021
+ rows.inPlace = settled && !!plan.inPlace;
1931
2022
  return rows;
1932
2023
  }
2024
+ /** Times one gather plans again from what it read (path folders, then the page at the path, then its children). */
2025
+ const GATHER_PLAN_STAGES = 4;
1933
2026
  /** Most linking nodes one gather reads; past it, a flush that lists them is saved op by op. */
1934
2027
  const LINKING_NODES_READ = 500;
1935
2028
  /** Live, non-scope pages among the rows: the ones a decide pass may lock. */
@@ -1943,14 +2036,27 @@ const lockable = (rows) => [...rows.pages.values()].filter((page) => !!page && !
1943
2036
  async function gatherImportRows(input) {
1944
2037
  const locked = new Set(input.locked ?? []);
1945
2038
  let rows = await readImportRows(input);
2039
+ if (input.storage.getCapabilities().serializedWriteTransactions && rows.notes.size === 0) {
2040
+ for (const id of lockable(rows)) locked.add(id);
2041
+ rows.locked = locked;
2042
+ return rows;
2043
+ }
1946
2044
  for (let round = 0; round < (input.rounds ?? 3); round++) {
1947
2045
  const unlocked = lockable(rows).filter((id) => !locked.has(id));
1948
2046
  if (!unlocked.length) {
1949
2047
  rows.locked = locked;
1950
2048
  return rows;
1951
2049
  }
1952
- await input.storage.lockPages(unlocked.sort());
2050
+ const versions = await input.storage.lockPages(unlocked.sort());
1953
2051
  for (const id of unlocked) locked.add(id);
2052
+ if (round === 0 && !input.reread && rows.inPlace && rows.notes.size === 0 && Array.isArray(versions) && versions.length === unlocked.length) {
2053
+ const read = new Map(versions.map((row) => [row.id, row.version]));
2054
+ if (unlocked.every((id) => read.get(id) === rows.pages.get(id)?.version)) {
2055
+ rows.locked = locked;
2056
+ rows.readOnce = true;
2057
+ return rows;
2058
+ }
2059
+ }
1954
2060
  rows = await readImportRows(input);
1955
2061
  }
1956
2062
  return null;
@@ -2051,6 +2157,24 @@ function knowledgeImportKey(sourceId) {
2051
2157
  return sourceId.replace(/[/#%:~]/g, (char) => `~${char.charCodeAt(0).toString(16).toUpperCase()}`);
2052
2158
  }
2053
2159
  const live = (page) => !!page && !page.deletedAt && !page.mergedInto;
2160
+ /** Source IDs the host keeps for the folders it makes on an item's path; importers can't send them. */
2161
+ const KNOWLEDGE_IMPORT_PATH_STUB_PREFIX = "~path:";
2162
+ /**
2163
+ * Why an item can never land, whatever the store holds: a reserved `sourceId`, or a `path` the host
2164
+ * can't place (with `parent` or `fallbackParent`, empty, an empty or blank segment, a page key too long to
2165
+ * link to, or deeper than a page can sit under a target `targetDepth` keys deep). Null when it can.
2166
+ */
2167
+ function knowledgeImportItemProblem(item, targetDepth) {
2168
+ if (item.sourceId.startsWith("~path:")) return `sourceId must not start with "${KNOWLEDGE_IMPORT_PATH_STUB_PREFIX}"`;
2169
+ const { path } = item;
2170
+ if (path === void 0) return null;
2171
+ if (item.parent != null || item.fallbackParent !== void 0) return "path is not allowed with parent or fallbackParent";
2172
+ if (path.length === 0) return "path must have at least one segment";
2173
+ if (path.some((segment) => !segment.trim())) return "path segments must not be empty or blank";
2174
+ if (path.some((segment) => knowledgeImportKey(segment).length > 512)) return `path segment keys must be at most 512 characters`;
2175
+ if (targetDepth + path.length > 10) return `path would sit more than 10 levels below the scope`;
2176
+ return null;
2177
+ }
2054
2178
  /** Core errors that mean "this op can't land here", by name: an adapter may carry its own core copy. */
2055
2179
  function refusalFor(error) {
2056
2180
  if (error instanceof KnowledgeImportRefusalError) return error.reason;
@@ -2086,11 +2210,17 @@ function order(ops) {
2086
2210
  const id = op.op === "remove" ? op.sourceId : op.item.sourceId;
2087
2211
  const before = last.get(id);
2088
2212
  if (op.op === "declare" && before?.op === "upsert") {
2213
+ const { parent, fallbackParent, path, ...rest } = before.item;
2214
+ const kept = op.item.path !== void 0 ? rest : op.item.parent !== void 0 || op.item.fallbackParent !== void 0 ? {
2215
+ ...rest,
2216
+ ...parent !== void 0 ? { parent } : {},
2217
+ ...fallbackParent !== void 0 ? { fallbackParent } : {}
2218
+ } : before.item;
2089
2219
  last.delete(id);
2090
2220
  last.set(id, {
2091
2221
  op: "upsert",
2092
2222
  item: {
2093
- ...before.item,
2223
+ ...kept,
2094
2224
  ...op.item
2095
2225
  }
2096
2226
  });
@@ -2154,7 +2284,19 @@ async function applyKnowledgeImportFlush(input) {
2154
2284
  embeds: [],
2155
2285
  applied: false
2156
2286
  };
2157
- const ops = order(input.ops);
2287
+ const rekey = !!storage.getCapabilities().supportsPageRekey;
2288
+ let ops = order(input.ops).filter((op) => {
2289
+ const sourceId = op.op === "remove" ? op.sourceId : op.item.sourceId;
2290
+ const problem = op.op === "remove" ? sourceId.startsWith(KNOWLEDGE_IMPORT_PATH_STUB_PREFIX) : !!knowledgeImportItemProblem(op.item, 1);
2291
+ const unplaceable = op.op !== "remove" && op.item.path !== void 0 && !rekey;
2292
+ if (!problem && !unplaceable) return true;
2293
+ if (!problem) result.pathsUnsupported = true;
2294
+ result.refused.push({
2295
+ sourceId,
2296
+ reason: "invalid"
2297
+ });
2298
+ return false;
2299
+ });
2158
2300
  if (ops.length === 0 && !(input.settle && binding.anchorPageId)) {
2159
2301
  if (input.settle) result.settle = {
2160
2302
  pending: false,
@@ -2167,9 +2309,11 @@ async function applyKnowledgeImportFlush(input) {
2167
2309
  const keyPath = async (page) => {
2168
2310
  const keys = [];
2169
2311
  const ids = [];
2312
+ const versions = [];
2170
2313
  if (page.isScope) return page.id === scope.id ? {
2171
2314
  keys,
2172
- ids
2315
+ ids,
2316
+ versions
2173
2317
  } : null;
2174
2318
  const parents = page.parentId ? await storage.getPageParents({
2175
2319
  parentId: page.parentId,
@@ -2178,11 +2322,13 @@ async function applyKnowledgeImportFlush(input) {
2178
2322
  for (const at of [page, ...parents]) {
2179
2323
  if (at.isScope) return at.id === scope.id ? {
2180
2324
  keys,
2181
- ids
2325
+ ids,
2326
+ versions
2182
2327
  } : null;
2183
2328
  if (!live(at) || at.key === void 0) return null;
2184
2329
  keys.unshift(at.key);
2185
2330
  ids.unshift(at.id);
2331
+ versions.unshift(at.version);
2186
2332
  }
2187
2333
  return null;
2188
2334
  };
@@ -2215,8 +2361,17 @@ async function applyKnowledgeImportFlush(input) {
2215
2361
  read: "all"
2216
2362
  });
2217
2363
  const path = live(page) ? await keyPath(page) : null;
2364
+ if (page && path && storage.getCapabilities().serializedWriteTransactions) return {
2365
+ page,
2366
+ keys: path.keys
2367
+ };
2218
2368
  if (page && path) {
2219
- await storage.lockPages(path.ids);
2369
+ const read = new Map(path.ids.map((id, i) => [id, path.versions[i]]));
2370
+ const locked = await storage.lockPages(path.ids);
2371
+ if (Array.isArray(locked) && locked.length === read.size && locked.every((row) => read.get(row.id) === row.version)) return {
2372
+ page,
2373
+ keys: path.keys
2374
+ };
2220
2375
  const fresh = await storage.getPage({
2221
2376
  id: page.id,
2222
2377
  read: "all"
@@ -2297,6 +2452,15 @@ async function applyKnowledgeImportFlush(input) {
2297
2452
  return result;
2298
2453
  }
2299
2454
  const anchorPath = anchor?.keys ?? [];
2455
+ ops = ops.filter((op) => {
2456
+ if (op.op === "remove" || !op.item.path) return true;
2457
+ if (anchorPath.length + op.item.path.length <= 10) return true;
2458
+ result.refused.push({
2459
+ sourceId: op.item.sourceId,
2460
+ reason: "invalid"
2461
+ });
2462
+ return false;
2463
+ });
2300
2464
  /**
2301
2465
  * A page this binding owns, checked after locking: live, in the target's scope, mapped back to the
2302
2466
  * node. A person may have moved it out of the anchor, under anyone's pages: it is still the
@@ -2396,6 +2560,90 @@ async function applyKnowledgeImportFlush(input) {
2396
2560
  return node && await stateOf(node) === "live" ? node : null;
2397
2561
  };
2398
2562
  const ref = (keys) => `${target.scope}#${keys.join("/")}`;
2563
+ /** The folders an op's path made, counted as created once the op lands. */
2564
+ let madeFolders = [];
2565
+ /**
2566
+ * The page a path item goes under: the anchor, then each segment but the last. A live page at a
2567
+ * segment is used as it is, whoever wrote it; a missing one (a merged page reads as missing, as a
2568
+ * merged parent does for a new child) becomes an empty folder this binding owns, keyed
2569
+ * `~path:<keys>`, that the item sending that path takes over. Returns the node the item is under,
2570
+ * when it is this binding's.
2571
+ */
2572
+ const pathFolders = async (path) => {
2573
+ let at = anchor;
2574
+ let parentSourceId = null;
2575
+ let holderOf = null;
2576
+ const readHolder = async () => {
2577
+ if (!holderOf) return;
2578
+ const holder = await importers.getNodeByPage(holderOf.id);
2579
+ parentSourceId = holder?.bindingId === binding.id ? holder.sourceId : null;
2580
+ holderOf = null;
2581
+ };
2582
+ const relative = [];
2583
+ for (const segment of path.slice(0, -1)) {
2584
+ const key = knowledgeImportKey(segment);
2585
+ relative.push(key);
2586
+ const keys = [...at.keys, key];
2587
+ const found = await storage.getPageByPath({
2588
+ scopeId: scope.id,
2589
+ path: keys,
2590
+ read: "all"
2591
+ });
2592
+ if (found) {
2593
+ await storage.lockPages([found.id]);
2594
+ const fresh = await storage.getPage({
2595
+ id: found.id,
2596
+ read: "all"
2597
+ });
2598
+ if (!live(fresh) || fresh.parentId !== at.page.id || fresh.key !== key) throw new KnowledgeImportRefusalError("conflict");
2599
+ holderOf = fresh;
2600
+ at = {
2601
+ page: fresh,
2602
+ keys
2603
+ };
2604
+ continue;
2605
+ }
2606
+ await readHolder();
2607
+ const sourceId = KNOWLEDGE_IMPORT_PATH_STUB_PREFIX + relative.join("/");
2608
+ const page = await storage.createPage({
2609
+ parentId: at.page.id,
2610
+ key,
2611
+ name: segment,
2612
+ body: "",
2613
+ provenance
2614
+ });
2615
+ await importers.saveNode({
2616
+ bindingId: binding.id,
2617
+ sourceId,
2618
+ pageId: page.id,
2619
+ kind: null,
2620
+ parentSourceId,
2621
+ aliases: [],
2622
+ unresolvedLinks: [],
2623
+ links: [],
2624
+ linkSection: null,
2625
+ stub: false,
2626
+ adopted: false,
2627
+ unsettled: false
2628
+ });
2629
+ await links(page, { pages: [page] });
2630
+ madeFolders.push({
2631
+ sourceId,
2632
+ page,
2633
+ keys
2634
+ });
2635
+ parentSourceId = sourceId;
2636
+ at = {
2637
+ page,
2638
+ keys
2639
+ };
2640
+ }
2641
+ await readHolder();
2642
+ return {
2643
+ destination: at,
2644
+ parentSourceId
2645
+ };
2646
+ };
2399
2647
  const linkLine = async (link, node) => {
2400
2648
  const page = node ? await storage.getPage({
2401
2649
  id: node.pageId,
@@ -2501,7 +2749,7 @@ async function applyKnowledgeImportFlush(input) {
2501
2749
  * and the pages it rewrote; the caller counts them once its op lands.
2502
2750
  */
2503
2751
  let deferredLinkers = false;
2504
- const moveOwned = async (self, page, parent) => {
2752
+ const moveOwned = async (self, page, parent, key) => {
2505
2753
  const targets = [];
2506
2754
  const othersTargets = /* @__PURE__ */ new Map();
2507
2755
  await storage.lockSubtree(page.id);
@@ -2515,6 +2763,7 @@ async function applyKnowledgeImportFlush(input) {
2515
2763
  id: page.id,
2516
2764
  expectedVersion: page.version,
2517
2765
  parentId: parent.page.id,
2766
+ ...key !== void 0 && key !== page.key ? { key } : {},
2518
2767
  provenance
2519
2768
  });
2520
2769
  const keys = [...parent.keys, moved.key];
@@ -2570,6 +2819,97 @@ async function applyKnowledgeImportFlush(input) {
2570
2819
  });
2571
2820
  }
2572
2821
  };
2822
+ /**
2823
+ * Frees `key` under `destination` for a path item's own page to move onto. A folder of this binding's
2824
+ * that holds the path is absorbed: its children move under the item's page in order, their nodes
2825
+ * point at the item, a body a person wrote in it is kept in a note on the item's page, and the empty
2826
+ * folder goes. A folder someone left notes on, or whose body would replace a body the item's page
2827
+ * already keeps, is not absorbed: the item is refused `occupied`, as for any other page at the path.
2828
+ * An item inside the folder, sent at the folder's path, leaves it first under a key no item uses, so
2829
+ * it never moves under itself; the move after this one gives it the folder's key. Returns whether it
2830
+ * kept a body (the item then holds a person's text, so its removal gives that back) and the item's
2831
+ * page as it is now.
2832
+ */
2833
+ const absorbAt = async (self, destination, key, page) => {
2834
+ const held = await storage.getPageByPath({
2835
+ scopeId: scope.id,
2836
+ path: [...destination.keys, key],
2837
+ read: "all"
2838
+ });
2839
+ if (!held || held.id === page.id) return {
2840
+ kept: false,
2841
+ page
2842
+ };
2843
+ await storage.lockPages([held.id]);
2844
+ const stub = await storage.getPage({
2845
+ id: held.id,
2846
+ read: "all"
2847
+ });
2848
+ if (!live(stub) || stub.parentId !== destination.page.id || stub.key !== key) throw new KnowledgeImportRefusalError("occupied");
2849
+ const holder = await importers.getNodeByPage(stub.id);
2850
+ if (holder?.bindingId !== binding.id || !holder.sourceId.startsWith("~path:")) throw new KnowledgeImportRefusalError("occupied");
2851
+ if ((await storage.listNotes({
2852
+ pageId: stub.id,
2853
+ read: "all",
2854
+ limit: 1
2855
+ })).notes.length > 0) throw new KnowledgeImportRefusalError("occupied");
2856
+ if (stub.body && (await keptBodyNotes(page.id)).length > 0) throw new KnowledgeImportRefusalError("occupied");
2857
+ const children = [];
2858
+ let cursor;
2859
+ do {
2860
+ const out = await storage.listChildPages({
2861
+ parentId: stub.id,
2862
+ read: "all",
2863
+ ...cursor ? { cursor } : {}
2864
+ });
2865
+ children.push(...out.pages);
2866
+ cursor = out.nextCursor;
2867
+ } while (cursor);
2868
+ let inside = page.parentId;
2869
+ while (inside && inside !== stub.id) inside = (await storage.getPage({
2870
+ id: inside,
2871
+ read: "all"
2872
+ }))?.parentId ?? null;
2873
+ if (inside) {
2874
+ await storage.lockSubtree(page.id);
2875
+ page = await storage.movePage({
2876
+ id: page.id,
2877
+ expectedVersion: page.version,
2878
+ parentId: destination.page.id,
2879
+ key: `~absorbing-${randomUUID()}`,
2880
+ provenance
2881
+ });
2882
+ }
2883
+ for (const child of children.filter((child) => child.id !== page.id)) {
2884
+ await storage.lockSubtree(child.id);
2885
+ await storage.movePage({
2886
+ id: child.id,
2887
+ expectedVersion: child.version,
2888
+ parentId: page.id,
2889
+ provenance
2890
+ });
2891
+ const node = await importers.getNodeByPage(child.id);
2892
+ if (node?.bindingId === binding.id && node.parentSourceId === holder.sourceId) await importers.saveNode({
2893
+ ...node,
2894
+ parentSourceId: self
2895
+ });
2896
+ }
2897
+ if (stub.body) await keepBody(page.id, stub.body);
2898
+ const emptied = await storage.getPage({
2899
+ id: stub.id,
2900
+ read: "all"
2901
+ });
2902
+ await storage.deletePage({
2903
+ id: stub.id,
2904
+ expectedVersion: emptied.version,
2905
+ deletedBy: provenance.author
2906
+ });
2907
+ await importers.deleteNode(binding.id, holder.sourceId);
2908
+ return {
2909
+ kept: !!stub.body,
2910
+ page
2911
+ };
2912
+ };
2573
2913
  const write = async (item, hasBody) => {
2574
2914
  let existing = await importers.getNode(binding.id, item.sourceId);
2575
2915
  const state = existing ? await stateOf(existing) : null;
@@ -2584,7 +2924,19 @@ async function applyKnowledgeImportFlush(input) {
2584
2924
  const parentMerged = parentState === "merged";
2585
2925
  const misplaced = !!item.parent && !sourceParent && !parentMerged;
2586
2926
  const parentNode = sourceParent ?? await liveNodeOf(item.fallbackParent);
2587
- const destination = parentNode ? await owned(parentNode.pageId, parentNode.sourceId) : anchor;
2927
+ let destination = parentNode ? await owned(parentNode.pageId, parentNode.sourceId) : anchor;
2928
+ let key = knowledgeImportKey(item.sourceId);
2929
+ let parentSourceId = item.parent ?? null;
2930
+ if (item.path) {
2931
+ const current = existing ? await owned(existing.pageId, item.sourceId) : null;
2932
+ if (current?.outside) {
2933
+ key = current.page.key;
2934
+ parentSourceId = existing.parentSourceId;
2935
+ } else {
2936
+ ({destination, parentSourceId} = await pathFolders(item.path));
2937
+ key = knowledgeImportKey(item.path.at(-1));
2938
+ }
2939
+ }
2588
2940
  if (existing && destination.page.id === existing.pageId) throw new KnowledgeImportRefusalError("invalid");
2589
2941
  let rendered = hasBody ? await renderBody(item) : void 0;
2590
2942
  let fields = {
@@ -2592,7 +2944,6 @@ async function applyKnowledgeImportFlush(input) {
2592
2944
  ...item.description !== void 0 ? { description: item.description } : {},
2593
2945
  ...rendered ? { body: rendered.body } : {}
2594
2946
  };
2595
- const key = knowledgeImportKey(item.sourceId);
2596
2947
  let page;
2597
2948
  let change;
2598
2949
  let moved = false;
@@ -2612,9 +2963,34 @@ async function applyKnowledgeImportFlush(input) {
2612
2963
  read: "all"
2613
2964
  });
2614
2965
  if (!live(fresh) || fresh.parentId !== destination.page.id || fresh.key !== key) throw new KnowledgeImportRefusalError("occupied");
2615
- const imported = await release(fresh.id);
2966
+ const holder = await importers.getNodeByPage(fresh.id);
2616
2967
  renamed = fields.name !== fresh.name;
2617
- if (!imported) await keepBody(fresh.id, fresh.body ?? "");
2968
+ if (holder?.bindingId === binding.id) {
2969
+ if (!holder.sourceId.startsWith("~path:")) throw new KnowledgeImportRefusalError("occupied");
2970
+ const childIds = [];
2971
+ let cursor;
2972
+ do {
2973
+ const out = await storage.listChildPages({
2974
+ parentId: fresh.id,
2975
+ read: "all",
2976
+ ...cursor ? { cursor } : {}
2977
+ });
2978
+ childIds.push(...out.pages.map((child) => child.id));
2979
+ cursor = out.nextCursor;
2980
+ } while (cursor);
2981
+ const childNodes = importers.getNodesByPages ? await importers.getNodesByPages(childIds) : (await Promise.all(childIds.map((id) => importers.getNodeByPage(id)))).filter((n) => !!n);
2982
+ await importers.deleteNode(binding.id, holder.sourceId);
2983
+ for (const child of childNodes) if (child.bindingId === binding.id && child.parentSourceId === holder.sourceId) await importers.saveNode({
2984
+ ...child,
2985
+ parentSourceId: item.sourceId
2986
+ });
2987
+ if (fresh.body) await keepBody(fresh.id, fresh.body);
2988
+ adopted = !!fresh.body;
2989
+ } else {
2990
+ await release(fresh.id);
2991
+ if (!holder) await keepBody(fresh.id, fresh.body ?? "");
2992
+ adopted = true;
2993
+ }
2618
2994
  page = await storage.updatePage({
2619
2995
  id: fresh.id,
2620
2996
  expectedVersion: fresh.version,
@@ -2622,7 +2998,6 @@ async function applyKnowledgeImportFlush(input) {
2622
2998
  provenance
2623
2999
  });
2624
3000
  change = "updated";
2625
- adopted = true;
2626
3001
  } else if (!existing) {
2627
3002
  page = await storage.createPage({
2628
3003
  parentId: destination.page.id,
@@ -2636,9 +3011,15 @@ async function applyKnowledgeImportFlush(input) {
2636
3011
  const current = await owned(existing.pageId, item.sourceId);
2637
3012
  page = current.page;
2638
3013
  if (existing.stub && existing.adopted && !REMOVED_BODIES.has(page.body ?? "")) await keepBody(page.id, page.body ?? "");
2639
- if (!current.outside && !parentMerged && page.parentId !== destination.page.id) {
3014
+ const rekey = !!item.path && !current.outside && page.key !== key;
3015
+ if (!current.outside && !parentMerged && (page.parentId !== destination.page.id || rekey)) {
2640
3016
  if (destination.keys.length > current.keys.length && sameKeys(destination.keys.slice(0, current.keys.length), current.keys)) throw new KnowledgeImportRefusalError("invalid");
2641
- ({page, relinked} = await moveOwned(item.sourceId, page, destination));
3017
+ if (item.path) {
3018
+ const absorbed = await absorbAt(item.sourceId, destination, key, page);
3019
+ page = absorbed.page;
3020
+ if (absorbed.kept) adopted = true;
3021
+ }
3022
+ ({page, relinked} = await moveOwned(item.sourceId, page, destination, item.path ? key : void 0));
2642
3023
  moved = true;
2643
3024
  if (hasBody) {
2644
3025
  rendered = await renderBody(item);
@@ -2675,7 +3056,7 @@ async function applyKnowledgeImportFlush(input) {
2675
3056
  sourceId: item.sourceId,
2676
3057
  pageId: page.id,
2677
3058
  kind: item.kind ?? existing?.kind ?? null,
2678
- parentSourceId: item.parent ?? null,
3059
+ parentSourceId,
2679
3060
  aliases: item.aliases ?? existing?.aliases ?? [],
2680
3061
  unresolvedLinks: rendered ? rendered.unresolved : existing?.unresolvedLinks ?? [],
2681
3062
  links: rendered ? rendered.links : existing?.links ?? [],
@@ -2712,6 +3093,7 @@ async function applyKnowledgeImportFlush(input) {
2712
3093
  for (const op of [...writes, ...removes]) {
2713
3094
  const sourceId = op.op === "remove" ? op.sourceId : op.item.sourceId;
2714
3095
  const embeds = [];
3096
+ madeFolders = [];
2715
3097
  try {
2716
3098
  await storage.transaction(async () => {
2717
3099
  if (op.op === "remove") {
@@ -2789,6 +3171,21 @@ async function applyKnowledgeImportFlush(input) {
2789
3171
  return;
2790
3172
  }
2791
3173
  const written = await write(op.item, op.op === "upsert");
3174
+ for (const folder of madeFolders) {
3175
+ result.applied = true;
3176
+ result.counts.created++;
3177
+ embeds.push({
3178
+ kind: "index",
3179
+ pageId: folder.page.id
3180
+ });
3181
+ result.changes.push({
3182
+ sourceId: folder.sourceId,
3183
+ pageId: folder.page.id,
3184
+ change: "created",
3185
+ title: folder.page.name,
3186
+ path: ref(folder.keys)
3187
+ });
3188
+ }
2792
3189
  if (!written) {
2793
3190
  result.counts.merged++;
2794
3191
  return;
@@ -2872,6 +3269,11 @@ async function applyKnowledgeImportFlush(input) {
2872
3269
  }
2873
3270
  return keys;
2874
3271
  };
3272
+ const chains = importChainPaths(rows.pages);
3273
+ const pageAt = (keys) => {
3274
+ const key = importPathKey(scope.id, keys);
3275
+ return rows.paths.has(key) ? rows.paths.get(key) : chains.get(key);
3276
+ };
2875
3277
  const at = (sourceId, seen) => {
2876
3278
  if (!sourceId) return null;
2877
3279
  const node = rows.nodes.get(`${binding.id}\u0000${sourceId}`);
@@ -2887,35 +3289,79 @@ async function applyKnowledgeImportFlush(input) {
2887
3289
  if (!op || seen.has(sourceId)) return null;
2888
3290
  return {
2889
3291
  id: null,
2890
- keys: [...destinationOf(op, /* @__PURE__ */ new Set([...seen, sourceId])).keys, knowledgeImportKey(sourceId)]
3292
+ keys: [...destinationOf(op, /* @__PURE__ */ new Set([...seen, sourceId])).keys, leafOf(op)]
2891
3293
  };
2892
3294
  };
2893
- const destinationOf = (op, seen) => at(op.item.parent, seen) ?? at(op.item.fallbackParent, seen) ?? {
2894
- id: folder.id,
2895
- keys: anchorPath
3295
+ const leafOf = (op) => knowledgeImportKey(op.item.path?.at(-1) ?? op.item.sourceId);
3296
+ const destinationOf = (op, seen) => {
3297
+ if (op.item.path) {
3298
+ const keys = [...anchorPath, ...op.item.path.slice(0, -1).map(knowledgeImportKey)];
3299
+ return {
3300
+ id: op.item.path.length === 1 ? folder.id : pageAt(keys),
3301
+ keys
3302
+ };
3303
+ }
3304
+ return at(op.item.parent, seen) ?? at(op.item.fallbackParent, seen) ?? {
3305
+ id: folder.id,
3306
+ keys: anchorPath
3307
+ };
2896
3308
  };
2897
3309
  const out = {
2898
3310
  paths: [],
2899
3311
  positions: [],
2900
3312
  notes: [],
3313
+ holders: [],
2901
3314
  subtrees: [],
2902
3315
  linkTargets: removed,
2903
- bindings: removed.length > 0
3316
+ bindings: removed.length > 0,
3317
+ inPlace: removed.length === 0
2904
3318
  };
2905
3319
  const nodeAt = (sourceId) => rows.nodes.get(`${binding.id}\u0000${sourceId}`);
2906
3320
  const left = /* @__PURE__ */ new Set();
2907
3321
  for (const op of writeOps.values()) {
2908
3322
  const destination = destinationOf(op, /* @__PURE__ */ new Set([op.item.sourceId]));
3323
+ const leaf = [...destination.keys, leafOf(op)];
3324
+ const page = rows.pages.get(nodeAt(op.item.sourceId)?.pageId ?? "");
3325
+ if (destination.id && live(page ?? null) && page.parentId === destination.id && (!op.item.path || page.key === leafOf(op))) {
3326
+ if (op.item.path && op.item.path.length > 1) out.holders.push(destination.id);
3327
+ continue;
3328
+ }
3329
+ out.inPlace = false;
2909
3330
  out.paths.push({
2910
3331
  scopeId: scope.id,
2911
- path: [...destination.keys, knowledgeImportKey(op.item.sourceId)]
3332
+ path: leaf
2912
3333
  });
2913
3334
  if (destination.id) out.positions.push(destination.id);
2914
- const page = rows.pages.get(nodeAt(op.item.sourceId)?.pageId ?? "");
2915
- if (live(page ?? null) && page.parentId !== destination.id) {
3335
+ if (destination.id !== void 0 && live(page ?? null) && (page.parentId !== destination.id || op.item.path && page.key !== leafOf(op))) {
2916
3336
  out.subtrees.push(page.id);
2917
3337
  if (page.parentId) left.add(page.parentId);
2918
3338
  }
3339
+ if (!op.item.path) continue;
3340
+ out.positions.push(folder.id);
3341
+ for (let i = anchorPath.length + 1; i < leaf.length; i++) {
3342
+ out.paths.push({
3343
+ scopeId: scope.id,
3344
+ path: leaf.slice(0, i)
3345
+ });
3346
+ const prefix = pageAt(leaf.slice(0, i));
3347
+ if (prefix) out.positions.push(prefix);
3348
+ }
3349
+ const held = pageAt(leaf);
3350
+ if (held && held !== page?.id) {
3351
+ out.subtrees.push(held);
3352
+ out.notes.push(held);
3353
+ if (page) {
3354
+ out.notes.push(page.id);
3355
+ out.positions.push(page.id);
3356
+ const keys = keysOf(page);
3357
+ if (keys) {
3358
+ for (const child of rows.pages.values()) if (child?.parentId === held && live(child) && child.key !== void 0) out.paths.push({
3359
+ scopeId: scope.id,
3360
+ path: [...keys, child.key]
3361
+ });
3362
+ }
3363
+ }
3364
+ }
2919
3365
  }
2920
3366
  for (const id of out.positions) if (left.has(id)) out.subtrees.push(id);
2921
3367
  for (const sourceId of removed) {
@@ -2948,6 +3394,7 @@ async function applyKnowledgeImportFlush(input) {
2948
3394
  };
2949
3395
  const missing = emptyImportOverlayMissing();
2950
3396
  let locked = /* @__PURE__ */ new Set();
3397
+ let reread = false;
2951
3398
  try {
2952
3399
  return await real.storage.transaction(async () => {
2953
3400
  for (let pass = 0; pass < BATCH_DECIDE_PASSES; pass++) {
@@ -2959,7 +3406,8 @@ async function applyKnowledgeImportFlush(input) {
2959
3406
  pageIds: folder ? [folder.id] : [],
2960
3407
  plan,
2961
3408
  missing,
2962
- locked
3409
+ locked,
3410
+ reread
2963
3411
  });
2964
3412
  if (!rows) throw new BatchFallback("lock-churn");
2965
3413
  locked = rows.locked;
@@ -2979,6 +3427,10 @@ async function applyKnowledgeImportFlush(input) {
2979
3427
  }
2980
3428
  continue;
2981
3429
  }
3430
+ if (error instanceof KnowledgeImportRereadRequiredError) {
3431
+ reread = true;
3432
+ continue;
3433
+ }
2982
3434
  if (error instanceof KnowledgeImportBatchUnsupportedError) throw new BatchFallback(error.call);
2983
3435
  throw error;
2984
3436
  } finally {
@@ -3721,6 +4173,7 @@ function createLocalKnowledgeImporterHost(writer, options) {
3721
4173
  /** Store time (epoch ms) at which a running run stops being live under `leaseMs`. */
3722
4174
  const liveUntil = (run) => Math.min((run.heartbeatAt ?? run.startedAt).getTime() + (leaseMs ?? Infinity), run.deadlineAt?.getTime() ?? Infinity);
3723
4175
  const listBindings = async () => typeof options.bindings === "function" ? await options.bindings() : options.bindings;
4176
+ const pathWarned = /* @__PURE__ */ new Set();
3724
4177
  const storageAndImporters = async () => {
3725
4178
  const storage = await writer.getStorage();
3726
4179
  const importers = storage.importers;
@@ -3774,6 +4227,7 @@ function createLocalKnowledgeImporterHost(writer, options) {
3774
4227
  finish,
3775
4228
  status: finish.outcome === "canceled" ? "canceled" : "failed"
3776
4229
  });
4230
+ pathWarned.delete(run.id);
3777
4231
  return true;
3778
4232
  };
3779
4233
  const reclaimStaleRuns = async (importers, bindingId) => {
@@ -3931,9 +4385,11 @@ function createLocalKnowledgeImporterHost(writer, options) {
3931
4385
  let embeds = [];
3932
4386
  let settling = false;
3933
4387
  let fallbackWarning;
4388
+ let pathsUnsupported = false;
3934
4389
  try {
3935
4390
  const write = (deadlineAt) => storage.transaction(async (tx) => {
3936
4391
  fallbackWarning = void 0;
4392
+ pathsUnsupported = false;
3937
4393
  const importers = tx.importers;
3938
4394
  const guard = await importers.lockWriterGuard(peek.firstWriteAt ? "share" : "update");
3939
4395
  const run = await importers.lockRun(flush.runId);
@@ -3979,6 +4435,7 @@ function createLocalKnowledgeImporterHost(writer, options) {
3979
4435
  } } : {}
3980
4436
  });
3981
4437
  if (applied.fallback) fallbackWarning = `Knowledge importer: flush ${flush.seq} of run ${run.id} saved op by op instead of batched (${applied.fallback})`;
4438
+ pathsUnsupported = !!applied.pathsUnsupported;
3982
4439
  const settled = applied.settle;
3983
4440
  const hostUpdates = {};
3984
4441
  if (settled && (settled.cursor ?? "") !== (hostState[SETTLE_CURSOR_KEY] ?? "")) hostUpdates[SETTLE_CURSOR_KEY] = settled.cursor ?? "";
@@ -4028,6 +4485,10 @@ function createLocalKnowledgeImporterHost(writer, options) {
4028
4485
  deadlineAt = Math.min(budgetAt, error.cutoff - LEASE_CUTOFF_MARGIN_MS);
4029
4486
  }
4030
4487
  if (fallbackWarning) writer.warn(fallbackWarning);
4488
+ if (pathsUnsupported && !pathWarned.has(flush.runId)) {
4489
+ pathWarned.add(flush.runId);
4490
+ writer.warn(`Knowledge importer: run ${flush.runId} refused items placed by path: path placement needs a store that supports page re-key; ${Object.getPrototypeOf(storage).constructor.name} does not`);
4491
+ }
4031
4492
  await runEmbeds(storage, embeds);
4032
4493
  return receipt;
4033
4494
  } catch (error) {
@@ -4119,7 +4580,7 @@ function createLocalKnowledgeImporterHost(writer, options) {
4119
4580
  }
4120
4581
  const { storage } = await storageAndImporters();
4121
4582
  try {
4122
- return await storage.transaction(async (tx) => {
4583
+ const receipt = await storage.transaction(async (tx) => {
4123
4584
  const importers = tx.importers;
4124
4585
  const guard = await importers.lockWriterGuard("share");
4125
4586
  const run = await importers.lockRun(request.runId);
@@ -4163,6 +4624,8 @@ function createLocalKnowledgeImporterHost(writer, options) {
4163
4624
  });
4164
4625
  return runReceipt(finished);
4165
4626
  });
4627
+ pathWarned.delete(request.runId);
4628
+ return receipt;
4166
4629
  } catch (error) {
4167
4630
  throw hostError(error);
4168
4631
  }
@@ -5540,7 +6003,8 @@ var Knowledge = class extends MastraBase {
5540
6003
  warn: (message) => this.logger.warn(message),
5541
6004
  maxTokens: this.#tools.maxTokens,
5542
6005
  ...principals ? { principals } : {},
5543
- ...options?.author ? { author: options.author } : {}
6006
+ ...options?.author ? { author: options.author } : {},
6007
+ ...options?.requireExpectedVersion ? { requireExpectedVersion: true } : {}
5544
6008
  }, this.#groups(options), (context) => context?.requestContext?.delete?.(PINNED_READ_MEMO_KEY));
5545
6009
  }
5546
6010
  /**