@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.
- package/dist/agent/active-run-signal-queues.d.ts +49 -0
- package/dist/agent/agent.d.ts +17 -1
- package/dist/agent/durable/abort-transport.d.ts +1 -1
- package/dist/agent/durable/durable-agent.d.ts +1 -0
- package/dist/agent/durable/execution-engine.d.ts +12 -0
- package/dist/agent/durable/index.cjs +1 -1
- package/dist/agent/durable/index.js +1 -1
- package/dist/agent/durable/preparation.d.ts +17 -0
- package/dist/agent/durable/stored-signal-drain.d.ts +100 -0
- package/dist/agent/durable/types.d.ts +37 -0
- package/dist/agent/durable/utils/resolve-runtime.d.ts +11 -0
- package/dist/agent/durable/utils/serialize-state.d.ts +1 -0
- package/dist/agent/durable/workflows/create-durable-agentic-workflow.d.ts +1 -0
- package/dist/agent/durable/workflows/durable-loop-builder.d.ts +5 -0
- package/dist/agent/durable/workflows/finalize-run.d.ts +6 -0
- package/dist/agent/durable/workflows/shared/message-list-state.d.ts +6 -2
- package/dist/agent/durable/workflows/shared/schemas.d.ts +2 -0
- package/dist/agent/durable/workflows/steps/llm-execution.d.ts +1 -0
- package/dist/agent/index.cjs +2 -2
- package/dist/agent/index.js +2 -2
- package/dist/agent/signals.d.ts +7 -3
- package/dist/agent/stored-run-signals.d.ts +93 -0
- package/dist/agent/stored-signals.d.ts +40 -0
- package/dist/agent/streams/abort-transport.d.ts +10 -1
- package/dist/agent/streams/constants.d.ts +9 -0
- package/dist/agent/streams/publisher.d.ts +3 -1
- package/dist/agent/thread-stream-runtime.d.ts +46 -4
- package/dist/agent/tool-name.d.ts +21 -0
- package/dist/agent-builder/ee/index.cjs +1 -1
- package/dist/agent-builder/ee/index.js +1 -1
- package/dist/agent-controller/index.cjs +1 -1
- package/dist/agent-controller/index.js +1 -1
- package/dist/agent-controller/types.d.ts +6 -0
- package/dist/{agent-controller-DfeTRuBc.js → agent-controller-FSjSZ_iD.js} +11 -9
- package/dist/{agent-controller-BcN7r3yI.cjs → agent-controller-k4B293tu.cjs} +11 -9
- package/dist/background-tasks/index.cjs +1 -1
- package/dist/background-tasks/index.js +1 -1
- package/dist/background-tasks/manager.d.ts +3 -1
- package/dist/background-tasks/workflow-id.d.ts +42 -0
- package/dist/{background-tasks-BcU--rXL.js → background-tasks-ClI6oF60.js} +239 -28
- package/dist/{background-tasks-DRUHnQOk.cjs → background-tasks-D40Y_iLc.cjs} +262 -27
- package/dist/browser/index.cjs +2 -2
- package/dist/browser/index.js +2 -2
- package/dist/{builder-Bufqrcz3.cjs → builder-C_I6l0US.cjs} +2 -2
- package/dist/{builder-TuIc5l7X.js → builder-D00XMm41.js} +2 -2
- package/dist/capabilities/302ai.json +197 -197
- package/dist/capabilities/abliteratedllm.json +33 -33
- package/dist/capabilities/abliteration-ai.json +10 -10
- package/dist/capabilities/above.json +22 -22
- package/dist/capabilities/adaption.json +7 -7
- package/dist/capabilities/adzuki.json +31 -31
- package/dist/capabilities/agentrouter.json +4 -4
- package/dist/capabilities/agnes.json +4 -4
- package/dist/capabilities/ai-router.json +6 -6
- package/dist/capabilities/aiand.json +22 -22
- package/dist/capabilities/aigrow.json +11 -11
- package/dist/capabilities/aimlapi.json +146 -146
- package/dist/capabilities/aipg.json +2 -2
- package/dist/capabilities/aixy.json +20 -20
- package/dist/capabilities/aki-io.json +13 -13
- package/dist/capabilities/alibaba-cn.json +126 -90
- package/dist/capabilities/alibaba-coding-plan-cn.json +6 -11
- package/dist/capabilities/alibaba-coding-plan.json +6 -11
- package/dist/capabilities/alibaba-token-plan-cn.json +49 -49
- package/dist/capabilities/alibaba-token-plan.json +54 -54
- package/dist/capabilities/alibaba.json +87 -61
- package/dist/capabilities/ambient.json +14 -14
- package/dist/capabilities/amd.json +8 -8
- package/dist/capabilities/anthropic.json +42 -42
- package/dist/capabilities/anyapi.json +16 -16
- package/dist/capabilities/apiko.json +5 -5
- package/dist/capabilities/arcee.json +11 -11
- package/dist/capabilities/auriko.json +15 -15
- package/dist/capabilities/bailing.json +5 -5
- package/dist/capabilities/baseten.json +35 -35
- package/dist/capabilities/bee.json +3 -3
- package/dist/capabilities/berget.json +8 -8
- package/dist/capabilities/bothub.json +16 -16
- package/dist/capabilities/boundless.json +34 -34
- package/dist/capabilities/bumo.json +37 -37
- package/dist/capabilities/byteplus.json +29 -29
- package/dist/capabilities/cerebras.json +4 -4
- package/dist/capabilities/cheapaimodel.json +10 -10
- package/dist/capabilities/cheapest-token.json +29 -29
- package/dist/capabilities/chutes.json +58 -10
- package/dist/capabilities/cline-pass.json +38 -38
- package/dist/capabilities/cloudcode.json +6 -6
- package/dist/capabilities/cloudferro-sherlock.json +4 -4
- package/dist/capabilities/cloudflare-workers-ai.json +16 -16
- package/dist/capabilities/commandcode.json +147 -147
- package/dist/capabilities/concentrate.json +277 -277
- package/dist/capabilities/cortecs.json +102 -102
- package/dist/capabilities/crossmodel.json +183 -183
- package/dist/capabilities/crusoe.json +17 -17
- package/dist/capabilities/daoxe.json +8 -8
- package/dist/capabilities/databricks.json +124 -124
- package/dist/capabilities/deepinfra.json +101 -101
- package/dist/capabilities/deepseek.json +3 -3
- package/dist/capabilities/digitalocean.json +116 -116
- package/dist/capabilities/dothoosh.json +32 -32
- package/dist/capabilities/doubleword.json +30 -30
- package/dist/capabilities/edenai.json +290 -290
- package/dist/capabilities/empiriolabs.json +162 -162
- package/dist/capabilities/engy.json +19 -19
- package/dist/capabilities/entrim.json +8 -8
- package/dist/capabilities/evroc.json +13 -13
- package/dist/capabilities/ezkielyna.json +12 -12
- package/dist/capabilities/fastrouter.json +86 -86
- package/dist/capabilities/fireworks-ai.json +99 -99
- package/dist/capabilities/fortytwo.json +4 -4
- package/dist/capabilities/freemodel.json +14 -14
- package/dist/capabilities/friendli.json +12 -12
- package/dist/capabilities/frogbot.json +91 -91
- package/dist/capabilities/gisoo.json +18 -18
- package/dist/capabilities/gmicloud.json +19 -19
- package/dist/capabilities/google.json +52 -52
- package/dist/capabilities/graphn.json +12 -12
- package/dist/capabilities/greenpt.json +34 -34
- package/dist/capabilities/groq.json +6 -6
- package/dist/capabilities/helicone.json +87 -87
- package/dist/capabilities/hetzner.json +4 -4
- package/dist/capabilities/hopper.json +2 -2
- package/dist/capabilities/hostinger-router.json +13 -20
- package/dist/capabilities/hpc-ai.json +10 -10
- package/dist/capabilities/huawei-maas.json +11 -11
- package/dist/capabilities/hubris.json +28 -28
- package/dist/capabilities/huggingface.json +92 -85
- package/dist/capabilities/hyper.json +18 -18
- package/dist/capabilities/impossibl.json +146 -146
- package/dist/capabilities/inception.json +2 -2
- package/dist/capabilities/inceptron.json +8 -8
- package/dist/capabilities/inco.json +4 -4
- package/dist/capabilities/infer.json +14 -14
- package/dist/capabilities/inferall.json +6 -6
- package/dist/capabilities/inference-coop.json +12 -12
- package/dist/capabilities/inferenceapis.json +26 -26
- package/dist/capabilities/inferris.json +4 -4
- package/dist/capabilities/infersia.json +10 -10
- package/dist/capabilities/inferx.json +3 -3
- package/dist/capabilities/infomaniak.json +3 -3
- package/dist/capabilities/io-net.json +4 -4
- package/dist/capabilities/isoquant.json +4 -4
- package/dist/capabilities/iteracompute.json +55 -55
- package/dist/capabilities/jad-ai.json +2 -2
- package/dist/capabilities/jalapeno.json +10 -10
- package/dist/capabilities/jiekou.json +58 -58
- package/dist/capabilities/joingonka.json +4 -4
- package/dist/capabilities/jzstoken.json +51 -51
- package/dist/capabilities/keln.json +22 -22
- package/dist/capabilities/kenari.json +141 -116
- package/dist/capabilities/kilo.json +629 -645
- package/dist/capabilities/kimi-code-plan-cn.json +6 -6
- package/dist/capabilities/kimi-code-plan-global.json +6 -6
- package/dist/capabilities/kitani.json +6 -6
- package/dist/capabilities/klavo.json +26 -26
- package/dist/capabilities/korouter.json +27 -27
- package/dist/capabilities/kunavo.json +9 -9
- package/dist/capabilities/liquid.json +12 -12
- package/dist/capabilities/lithosai.json +3 -3
- package/dist/capabilities/llmgateway-providers.json +920 -928
- package/dist/capabilities/llmgateway.json +357 -349
- package/dist/capabilities/llmtr.json +32 -32
- package/dist/capabilities/logits.json +2 -2
- package/dist/capabilities/lowrouter.json +48 -48
- package/dist/capabilities/lyceum.json +14 -14
- package/dist/capabilities/melious.json +9 -9
- package/dist/capabilities/merge-gateway.json +276 -276
- package/dist/capabilities/meta.json +10 -10
- package/dist/capabilities/minimax-cn-coding-plan.json +5 -5
- package/dist/capabilities/minimax-cn.json +5 -5
- package/dist/capabilities/minimax-coding-plan.json +5 -5
- package/dist/capabilities/minimax.json +5 -5
- package/dist/capabilities/mistral.json +19 -19
- package/dist/capabilities/mixlayer.json +4 -4
- package/dist/capabilities/modal.json +14 -14
- package/dist/capabilities/model-oracle-ai.json +26 -26
- package/dist/capabilities/modelis.json +17 -17
- package/dist/capabilities/modular.json +13 -13
- package/dist/capabilities/moneo.json +16 -16
- package/dist/capabilities/moonshotai-cn.json +6 -6
- package/dist/capabilities/moonshotai.json +6 -6
- package/dist/capabilities/morph.json +17 -17
- package/dist/capabilities/munito-eu.json +6 -6
- package/dist/capabilities/munito.json +10 -10
- package/dist/capabilities/nan.json +30 -30
- package/dist/capabilities/nano-gpt.json +595 -596
- package/dist/capabilities/nearai.json +99 -99
- package/dist/capabilities/nebius.json +31 -31
- package/dist/capabilities/neon.json +126 -126
- package/dist/capabilities/neuralwatt.json +43 -43
- package/dist/capabilities/nokeep.json +4 -4
- package/dist/capabilities/novita-ai.json +123 -123
- package/dist/capabilities/nvidia.json +33 -33
- package/dist/capabilities/oathbreaker.json +4 -4
- package/dist/capabilities/obscurify.json +29 -29
- package/dist/capabilities/oci.json +9 -9
- package/dist/capabilities/ofox.json +243 -607
- package/dist/capabilities/ollama-cloud.json +55 -55
- package/dist/capabilities/openai.json +55 -55
- package/dist/capabilities/opencode-go.json +96 -94
- package/dist/capabilities/openreason.json +4 -4
- package/dist/capabilities/openrouter.json +529 -543
- package/dist/capabilities/opper.json +29 -29
- package/dist/capabilities/orcarouter.json +436 -178
- package/dist/capabilities/outerlabs.json +28 -28
- package/dist/capabilities/ovhcloud.json +21 -22
- package/dist/capabilities/pareto.json +6 -6
- package/dist/capabilities/perplexity-agent.json +63 -63
- package/dist/capabilities/phala.json +30 -30
- package/dist/capabilities/pioneer.json +23 -23
- package/dist/capabilities/poe.json +140 -140
- package/dist/capabilities/poolside.json +3 -3
- package/dist/capabilities/powerspring.json +14 -14
- package/dist/capabilities/primalabs.json +7 -7
- package/dist/capabilities/prime.json +119 -119
- package/dist/capabilities/privatemode-ai.json +10 -10
- package/dist/capabilities/proxystacks.json +7 -7
- package/dist/capabilities/qiniu-ai.json +15 -15
- package/dist/capabilities/refuseless.json +5 -5
- package/dist/capabilities/regolo-ai.json +8 -8
- package/dist/capabilities/requesty.json +204 -204
- package/dist/capabilities/ruapi.json +24 -24
- package/dist/capabilities/runcrate.json +15 -15
- package/dist/capabilities/runinfra.json +16 -16
- package/dist/capabilities/sakana.json +5 -5
- package/dist/capabilities/sambanova.json +7 -7
- package/dist/capabilities/sandbase.json +21 -21
- package/dist/capabilities/sarvam.json +11 -11
- package/dist/capabilities/scaleway.json +15 -15
- package/dist/capabilities/scnet-token-plan.json +14 -14
- package/dist/capabilities/scx-ai.json +26 -26
- package/dist/capabilities/sensenova.json +12 -12
- package/dist/capabilities/siliconflow-cn.json +54 -54
- package/dist/capabilities/siliconflow.json +66 -66
- package/dist/capabilities/snowflake-cortex.json +22 -22
- package/dist/capabilities/sokkan.json +7 -7
- package/dist/capabilities/sparrowcodes.json +23 -23
- package/dist/capabilities/standardcompute.json +96 -96
- package/dist/capabilities/steadyrouter.json +38 -38
- package/dist/capabilities/stepfun-ai-step-plan.json +15 -9
- package/dist/capabilities/stepfun-ai.json +22 -8
- package/dist/capabilities/stepfun-step-plan.json +15 -8
- package/dist/capabilities/stepfun.json +22 -8
- package/dist/capabilities/stepping-stone.json +25 -25
- package/dist/capabilities/synthetic.json +10 -10
- package/dist/capabilities/synthorai.json +24 -24
- package/dist/capabilities/teamorouter.json +18 -18
- package/dist/capabilities/teapot-router.json +12 -12
- package/dist/capabilities/tencent-token-plan-intl.json +20 -20
- package/dist/capabilities/tencent-token-plan.json +38 -38
- package/dist/capabilities/tencent-tokenhub.json +46 -46
- package/dist/capabilities/tensorx.json +52 -52
- package/dist/capabilities/tenstorrent.json +8 -8
- package/dist/capabilities/the-grid-ai.json +35 -35
- package/dist/capabilities/thinkingmachines.json +78 -78
- package/dist/capabilities/tinfoil.json +5 -5
- package/dist/capabilities/toapis.json +2 -2
- package/dist/capabilities/togetherai.json +53 -61
- package/dist/capabilities/tokengo.json +23 -23
- package/dist/capabilities/tokenify.json +9 -9
- package/dist/capabilities/trustedrouter.json +5 -5
- package/dist/capabilities/trustedtokens.json +19 -19
- package/dist/capabilities/umans-ai-coding-plan.json +15 -15
- package/dist/capabilities/umans-ai.json +11 -11
- package/dist/capabilities/unrestricted.json +8 -8
- package/dist/capabilities/uplinkswitch.json +22 -22
- package/dist/capabilities/upstage.json +4 -4
- package/dist/capabilities/vancine.json +19 -19
- package/dist/capabilities/vercel.json +520 -513
- package/dist/capabilities/verda.json +8 -1
- package/dist/capabilities/vivgrid.json +81 -81
- package/dist/capabilities/volcengine-coding-plan.json +29 -29
- package/dist/capabilities/volcengine.json +21 -21
- package/dist/capabilities/vultr.json +26 -26
- package/dist/capabilities/wafer.ai.json +13 -13
- package/dist/capabilities/wallaby.json +4 -4
- package/dist/capabilities/wally.json +13 -13
- package/dist/capabilities/wandb.json +17 -17
- package/dist/capabilities/watt.json +24 -24
- package/dist/capabilities/xai.json +4 -4
- package/dist/capabilities/xiaomi-token-plan-ams.json +2 -2
- package/dist/capabilities/xiaomi-token-plan-cn.json +2 -2
- package/dist/capabilities/xiaomi-token-plan-sgp.json +2 -2
- package/dist/capabilities/xiaomi.json +2 -2
- package/dist/capabilities/xpersona.json +10 -10
- package/dist/capabilities/xxapi.json +28 -28
- package/dist/capabilities/zai-coding-plan.json +13 -13
- package/dist/capabilities/zai.json +28 -28
- package/dist/capabilities/zenifra.json +29 -29
- package/dist/capabilities/zenmux.json +178 -178
- package/dist/capabilities/zerogpu.json +15 -15
- package/dist/capabilities/zhipuai-coding-plan.json +6 -6
- package/dist/capabilities/zhipuai.json +25 -25
- package/dist/capabilities/zro.json +5 -5
- package/dist/channels/index.cjs +2 -2
- package/dist/channels/index.js +2 -2
- package/dist/{channels-MsOnUvU6.cjs → channels-BU5_kAUO.cjs} +1 -1
- package/dist/{channels-Cdsqdajh.js → channels-DMSae7xD.js} +1 -1
- package/dist/coding-agent/index.cjs +3 -3
- package/dist/coding-agent/index.js +3 -3
- package/dist/{constants-Bou0hEgY.cjs → constants-CFO8w780.cjs} +8 -0
- package/dist/{constants-CFWgIaqA.js → constants-CUv0mU2y.js} +8 -0
- package/dist/datasets/index.cjs +2 -2
- package/dist/datasets/index.js +2 -2
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +1044 -1009
- package/dist/docs/references/docs-agents-code-mode.md +2 -2
- package/dist/docs/references/docs-agents-human-in-the-loop.md +2 -2
- package/dist/docs/references/docs-agents-networks.md +1 -1
- package/dist/docs/references/docs-agents-overview.md +6 -6
- package/dist/docs/references/docs-agents-processors.md +9 -9
- package/dist/docs/references/docs-agents-resumable-streams.md +2 -2
- package/dist/docs/references/docs-agents-structured-output.md +6 -6
- package/dist/docs/references/docs-agents-tools.md +9 -9
- package/dist/docs/references/docs-browser.md +1 -1
- package/dist/docs/references/docs-channels.md +5 -5
- package/dist/docs/references/docs-classifier.md +1 -1
- package/dist/docs/references/docs-connections-a2a.md +1 -1
- package/dist/docs/references/docs-connections-acp.md +2 -2
- package/dist/docs/references/docs-connections-overview.md +1 -1
- package/dist/docs/references/docs-connections-sdk-agents.md +6 -6
- package/dist/docs/references/docs-deployment-workers.md +1 -1
- package/dist/docs/references/docs-develop.md +1 -1
- package/dist/docs/references/docs-evals-custom-scorers.md +1 -1
- package/dist/docs/references/docs-evals-multi-turn.md +2 -2
- package/dist/docs/references/docs-guides-build-an-eval-loop.md +2 -2
- package/dist/docs/references/docs-guides-context-engineering.md +3 -3
- package/dist/docs/references/docs-guides-streaming.md +1 -1
- package/dist/docs/references/docs-harness-agent-controller.md +6 -3
- package/dist/docs/references/docs-harness-background-tasks.md +2 -2
- package/dist/docs/references/docs-harness-durable-agents.md +5 -5
- package/dist/docs/references/docs-harness-goals.md +2 -2
- package/dist/docs/references/docs-harness-schedules.md +35 -1
- package/dist/docs/references/docs-knowledge-agents-and-tools.md +2 -2
- package/dist/docs/references/docs-knowledge-importers.md +22 -1
- package/dist/docs/references/docs-knowledge-overview.md +1 -1
- package/dist/docs/references/docs-knowledge-scopes-and-access.md +1 -1
- package/dist/docs/references/docs-memory-memory-processors.md +8 -8
- package/dist/docs/references/docs-memory-message-history.md +3 -3
- package/dist/docs/references/docs-memory-observational-memory.md +1 -1
- package/dist/docs/references/docs-memory-semantic-recall.md +2 -2
- package/dist/docs/references/docs-memory-working-memory.md +3 -2
- package/dist/docs/references/docs-sandbox-overview.md +2 -2
- package/dist/docs/references/docs-sandbox-skills.md +1 -1
- package/dist/docs/references/docs-server-mastra-client.md +1 -1
- package/dist/docs/references/docs-server-mcp.md +23 -0
- package/dist/docs/references/docs-server-pubsub.md +21 -1
- package/dist/docs/references/docs-server-request-context.md +4 -4
- package/dist/docs/references/docs-signals-notifications.md +2 -2
- package/dist/docs/references/docs-signals-overview.md +1 -1
- package/dist/docs/references/docs-signals-running-across-processes.md +3 -0
- package/dist/docs/references/docs-signals-sending-signals.md +7 -7
- package/dist/docs/references/docs-signals-signal-providers.md +18 -2
- package/dist/docs/references/docs-signals-state-signals.md +1 -0
- package/dist/docs/references/docs-signals-thread-streams.md +12 -0
- package/dist/docs/references/docs-skills.md +4 -4
- package/dist/docs/references/docs-storage.md +12 -12
- package/dist/docs/references/docs-studio-editor.md +2 -2
- package/dist/docs/references/docs-subagents.md +26 -3
- package/dist/docs/references/integrations-agentic-ui-copilotkit.md +1 -1
- package/dist/docs/references/integrations-agentic-ui-openui.md +1 -1
- package/dist/docs/references/integrations-channels-discord.md +1 -1
- package/dist/docs/references/integrations-channels-github.md +1 -1
- package/dist/docs/references/integrations-channels-imessage.md +2 -2
- package/dist/docs/references/integrations-channels-ring.md +2 -2
- package/dist/docs/references/integrations-channels-slack.md +1 -1
- package/dist/docs/references/integrations-channels-teams.md +1 -1
- package/dist/docs/references/integrations-channels-telegram.md +1 -1
- package/dist/docs/references/integrations-channels-whatsapp.md +1 -1
- package/dist/docs/references/integrations-tools-firecrawl.md +1 -1
- package/dist/docs/references/reference-acp-acp-agent.md +1 -1
- package/dist/docs/references/reference-acp-create-acp-tool.md +1 -1
- package/dist/docs/references/reference-agent-controller-agent-controller-class.md +3 -1
- package/dist/docs/references/reference-agent-controller-session.md +5 -5
- package/dist/docs/references/reference-agents-agent.md +40 -14
- package/dist/docs/references/reference-agents-channels.md +11 -11
- package/dist/docs/references/reference-agents-durable-agent.md +2 -2
- package/dist/docs/references/reference-agents-getLLM.md +2 -2
- package/dist/docs/references/reference-agents-getMetadata.md +2 -2
- package/dist/docs/references/reference-agents-network.md +2 -2
- package/dist/docs/references/reference-browser-mastra-browser.md +1 -1
- package/dist/docs/references/reference-channels-thread-link.md +1 -1
- package/dist/docs/references/reference-classifier-classifier.md +2 -0
- package/dist/docs/references/reference-coding-agent-build-base-prompt.md +1 -1
- package/dist/docs/references/reference-coding-agent-create-coding-agent.md +7 -7
- package/dist/docs/references/reference-configuration.md +15 -14
- package/dist/docs/references/reference-core-getAgentById.md +1 -1
- package/dist/docs/references/reference-core-mastra-model-gateway.md +1 -1
- package/dist/docs/references/reference-datasets-startExperiment.md +1 -1
- package/dist/docs/references/reference-editor-mastra-editor.md +2 -2
- package/dist/docs/references/reference-file-based-agents-config.md +3 -3
- package/dist/docs/references/reference-file-based-agents-schedules.md +1 -1
- package/dist/docs/references/reference-file-based-agents-subagents.md +3 -3
- package/dist/docs/references/reference-file-based-agents-workspace.md +1 -1
- package/dist/docs/references/reference-knowledge-knowledge-class.md +12 -0
- package/dist/docs/references/reference-manual-install.md +1 -1
- package/dist/docs/references/reference-memory-memory-class.md +3 -3
- package/dist/docs/references/reference-memory-observational-memory.md +3 -3
- package/dist/docs/references/reference-observability-tracing-bridges-datadog.md +12 -11
- package/dist/docs/references/reference-observability-tracing-configuration.md +2 -2
- package/dist/docs/references/reference-observability-tracing-exporters-datadog.md +14 -12
- package/dist/docs/references/reference-processors-batch-parts-processor.md +1 -1
- package/dist/docs/references/reference-processors-classifier-processor.md +2 -2
- package/dist/docs/references/reference-processors-cyber-refusal-handler.md +1 -1
- package/dist/docs/references/reference-processors-language-detector.md +1 -1
- package/dist/docs/references/reference-processors-message-history-processor.md +1 -1
- package/dist/docs/references/reference-processors-model-selection-processor.md +3 -3
- package/dist/docs/references/reference-processors-moderation-processor.md +4 -4
- package/dist/docs/references/reference-processors-pii-detector.md +2 -2
- package/dist/docs/references/reference-processors-prefill-error-handler.md +2 -2
- package/dist/docs/references/reference-processors-processor-interface.md +19 -8
- package/dist/docs/references/reference-processors-prompt-injection-detector.md +1 -1
- package/dist/docs/references/reference-processors-provider-history-compat.md +1 -1
- package/dist/docs/references/reference-processors-response-cache.md +1 -1
- package/dist/docs/references/reference-processors-semantic-recall-processor.md +1 -1
- package/dist/docs/references/reference-processors-skill-search-processor.md +1 -1
- package/dist/docs/references/reference-processors-skills-processor.md +1 -1
- package/dist/docs/references/reference-processors-stream-error-retry-processor.md +3 -3
- package/dist/docs/references/reference-processors-system-prompt-scrubber.md +1 -1
- package/dist/docs/references/reference-processors-token-limiter-processor.md +3 -3
- package/dist/docs/references/reference-processors-tool-call-filter.md +2 -2
- package/dist/docs/references/reference-processors-tool-search-processor.md +3 -3
- package/dist/docs/references/reference-processors-unicode-normalizer.md +1 -1
- package/dist/docs/references/reference-processors-working-memory-processor.md +1 -1
- package/dist/docs/references/reference-rag-chunking-and-embedding.md +1 -1
- package/dist/docs/references/reference-rag-graph-rag-guide.md +2 -2
- package/dist/docs/references/reference-rag-retrieval.md +13 -13
- package/dist/docs/references/reference-signals-create-notification-inbox-tool.md +1 -1
- package/dist/docs/references/reference-signals-time-signal-provider.md +102 -0
- package/dist/docs/references/reference-storage-composite.md +4 -0
- package/dist/docs/references/reference-storage-overview.md +29 -29
- package/dist/docs/references/reference-tools-create-code-mode.md +1 -1
- package/dist/docs/references/reference-tools-vector-query-tool.md +3 -3
- package/dist/docs/references/reference-voice-overview.md +28 -28
- package/dist/docs/references/reference-voice-speech-to-speech.md +10 -10
- package/dist/docs/references/reference-voice-speech-to-text.md +1 -1
- package/dist/docs/references/reference-voice-text-to-speech.md +1 -1
- package/dist/docs/references/reference-voice-voice.addInstructions.md +1 -1
- package/dist/docs/references/reference-voice-voice.listen.md +1 -1
- package/dist/docs/references/reference-workers-overview.md +3 -1
- package/dist/docs/references/reference-workflows-step.md +1 -1
- package/dist/docs/references/reference-workflows-workflow-methods-map.md +1 -1
- package/dist/docs/references/reference-workflows-workflow.md +1 -1
- package/dist/docs/references/reference-workspace-factory-sandbox.md +2 -0
- package/dist/docs/references/reference-workspace-local-filesystem.md +1 -1
- package/dist/docs/references/reference-workspace-local-sandbox.md +1 -1
- package/dist/docs/references/reference.md +1 -0
- package/dist/evals/index.cjs +2 -2
- package/dist/evals/index.js +2 -2
- package/dist/evals/scoreTraces/index.cjs +2 -2
- package/dist/evals/scoreTraces/index.js +2 -2
- package/dist/harness/index.cjs +1 -1
- package/dist/harness/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/knowledge/importers/overlay.d.ts +32 -0
- package/dist/knowledge/importers/sink.d.ts +11 -1
- package/dist/knowledge/importers/types.d.ts +9 -0
- package/dist/knowledge/index.cjs +551 -87
- package/dist/knowledge/index.d.ts +6 -0
- package/dist/knowledge/index.js +551 -87
- package/dist/knowledge/page-tools.d.ts +2 -0
- package/dist/llm/index.cjs +3 -3
- package/dist/llm/index.js +3 -3
- package/dist/llm/model/provider-types.generated.d.ts +7865 -7877
- package/dist/{llm-CS6YY_IV.cjs → llm-C1aiWB6O.cjs} +2 -2
- package/dist/{llm-zjtMQn7M.js → llm-D5rGQSnS.js} +2 -2
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +2 -2
- package/dist/loop/loop-runtime.d.ts +1 -1
- package/dist/loop/shared/signal-outcome.d.ts +1 -1
- package/dist/loop/shared/steps/signal-drain-core.d.ts +9 -3
- package/dist/{manager-BU_lY6kl.cjs → manager-B2z5f39G.cjs} +3 -3
- package/dist/{manager-Do0MENhH.js → manager-DxwPLhYJ.js} +3 -3
- package/dist/mastra/index.cjs +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/{mastra-C-1zIyS5.js → mastra-CHd7UnbI.js} +17 -17
- package/dist/{mastra-DYVjsXTO.cjs → mastra-WMuI7TZD.cjs} +17 -17
- package/dist/memory/index.cjs +2 -2
- package/dist/memory/index.js +2 -2
- package/dist/{model-DIzIjDej.js → model-B8DlLHex.js} +1 -1
- package/dist/{model-DGFc1hw3.cjs → model-C2CTzjMk.cjs} +1 -1
- package/dist/{netlify-CyL6FNsw.cjs → netlify-Dhs0UJul.cjs} +1 -1
- package/dist/{netlify-B9mLgxJs.js → netlify-xQFmVbr4.js} +1 -1
- package/dist/notifications/index.cjs +1 -1
- package/dist/notifications/index.js +1 -1
- package/dist/processor-provider/index.cjs +1 -1
- package/dist/processor-provider/index.js +1 -1
- package/dist/processors/index.cjs +2 -2
- package/dist/processors/index.js +2 -2
- package/dist/{provider-registry-g9m_fyV8.cjs → provider-registry-CSQPAFzz.cjs} +22244 -22307
- package/dist/{provider-registry-DdQoO_jd.js → provider-registry-FxVHWmht.js} +22244 -22307
- package/dist/provider-registry.json +22283 -22350
- package/dist/{registry-generator-CX6Ev697.js → registry-generator-BzsrHxrr.js} +1 -1
- package/dist/{registry-generator-At8J4ZOR.cjs → registry-generator-Dsh7xcz9.cjs} +1 -1
- package/dist/{rehydrate-BzD6UX8f.cjs → rehydrate-8q7KX4rD.cjs} +2 -2
- package/dist/{rehydrate-DEDxsr6E.js → rehydrate-DV1iO9eZ.js} +2 -2
- package/dist/relevance/index.cjs +2 -2
- package/dist/relevance/index.js +2 -2
- package/dist/{run-registry-PiQTSx2Y.cjs → run-registry-DOlZccsr.cjs} +4703 -2233
- package/dist/{run-registry-D22IF5SK.js → run-registry-sTm40Ecv.js} +4704 -2234
- package/dist/{scheduler-B-VZUvv_.js → scheduler-0ShtMM1I.js} +71 -21
- package/dist/{scheduler-D00X03jQ.cjs → scheduler-CMjK0LoQ.cjs} +82 -20
- package/dist/server/types.d.ts +6 -0
- package/dist/signals/index.cjs +2 -1
- package/dist/signals/index.d.ts +1 -0
- package/dist/signals/index.js +2 -2
- package/dist/signals/time-signal-provider.d.ts +62 -0
- package/dist/signals-BTfT-6DE.js +280 -0
- package/dist/signals-CIwzgkvN.cjs +291 -0
- package/dist/{source-BVOi8Xhp.cjs → source-BC8Et5qZ.cjs} +7 -0
- package/dist/{source-fNa6u1kH.js → source-DYZMfjv3.js} +7 -0
- package/dist/storage/constants.cjs +1 -1
- package/dist/storage/constants.js +1 -1
- package/dist/storage/domains/agents/index.cjs +1 -1
- package/dist/storage/domains/agents/index.js +1 -1
- package/dist/storage/domains/inmemory-db.d.ts +6 -0
- package/dist/storage/domains/knowledge/base.d.ts +22 -4
- package/dist/storage/domains/knowledge/inmemory.d.ts +2 -0
- package/dist/storage/domains/knowledge/pages.d.ts +8 -0
- package/dist/storage/domains/memory/base.d.ts +107 -0
- package/dist/storage/domains/memory/index.d.ts +1 -0
- package/dist/storage/domains/memory/inmemory.d.ts +36 -0
- package/dist/storage/domains/memory/queue-thread.d.ts +36 -0
- package/dist/storage/domains/schedules/base.d.ts +31 -2
- package/dist/storage/domains/schedules/inmemory.d.ts +9 -2
- package/dist/storage/domains/workflows/base.d.ts +14 -0
- package/dist/storage/domains/workflows/inmemory.d.ts +4 -1
- package/dist/storage/index.cjs +9 -4
- package/dist/storage/index.js +5 -5
- package/dist/stream/index.cjs +2 -2
- package/dist/stream/index.js +2 -2
- package/dist/{stream-BbPZavop.cjs → stream-aGuW9AL8.cjs} +88 -2
- package/dist/{stream-CoQTdzLm.js → stream-k-Q1NLUs.js} +59 -3
- package/dist/test-utils/llm-mock.cjs +1 -1
- package/dist/test-utils/llm-mock.js +1 -1
- package/dist/tool-loop-agent/index.cjs +1 -1
- package/dist/tool-loop-agent/index.js +1 -1
- package/dist/{tool-loop-agent-DhQkNDaR.js → tool-loop-agent-CJrysPOR.js} +3 -3
- package/dist/{tool-loop-agent-8lyD6O4o.cjs → tool-loop-agent-WcRtGJHn.cjs} +3 -3
- package/dist/{utils-DtmyBuBT.cjs → utils-DEzQLxWP.cjs} +1 -1
- package/dist/{utils-B-3lET9S.js → utils-DamF4CfD.js} +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +1 -1
- package/dist/{validate-vucjWXcz.cjs → validate-CDlONK0o.cjs} +1 -1
- package/dist/{validate-CO4rWYyH.js → validate-rum3NMFA.js} +1 -1
- package/dist/vector/index.cjs +1 -1
- package/dist/vector/index.js +1 -1
- package/dist/worker/index.cjs +1 -1
- package/dist/worker/index.js +1 -1
- package/dist/{worker-BgifMkOw.cjs → worker-6MiKMAqB.cjs} +3 -3
- package/dist/{worker-B6CpapAF.js → worker-BnXipQth.js} +2 -2
- package/dist/{worker-eUT7GgQ9.cjs → worker-rwal1zI8.cjs} +2 -2
- package/dist/{worker-CCpSrXBY.js → worker-st16x0my.js} +3 -3
- package/dist/{workflow-B4Tn58DD.js → workflow-BzhYKgc_.js} +25 -33
- package/dist/{workflow-BJSrGEEL.cjs → workflow-D2-gn0U0.cjs} +25 -33
- package/dist/workflows/builder/index.cjs +1 -1
- package/dist/workflows/builder/index.js +1 -1
- package/dist/workflows/evented/execution-engine.d.ts +3 -1
- package/dist/workflows/evented/index.cjs +1 -1
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/evented/setup-warning.d.ts +11 -0
- package/dist/workflows/evented/workflow-event-processor/index.d.ts +10 -2
- package/dist/workflows/evented/workflow-event-processor/loop.d.ts +1 -1
- package/dist/workflows/evented/workflow-event-processor/parallel.d.ts +2 -2
- package/dist/workflows/evented/workflow-event-processor/sleep.d.ts +2 -2
- package/dist/workflows/evented/workflow.d.ts +6 -2
- package/dist/workflows/handlers/entry.d.ts +8 -0
- package/dist/workflows/index.cjs +7 -5
- package/dist/workflows/index.js +6 -6
- package/dist/workflows/run-storage.d.ts +11 -2
- package/dist/workflows/scheduler/claim.d.ts +51 -0
- package/dist/workflows/scheduler/index.d.ts +2 -0
- package/dist/workflows/types.d.ts +6 -0
- package/dist/workflows/workflow.d.ts +85 -10
- package/dist/workspace/filesystem/local-filesystem.d.ts +13 -0
- package/dist/workspace/index.cjs +1 -1
- package/dist/workspace/index.js +1 -1
- package/dist/{workspace-CnmmMou8.js → workspace-Ct2kAiDv.js} +50 -11
- package/dist/{workspace-C5lXteRU.cjs → workspace-CzzrnE6Q.cjs} +50 -11
- package/package.json +7 -7
- package/src/llm/model/provider-types.generated.d.ts +7865 -7877
- package/dist/signals-B1JSj-Ew.cjs +0 -58
- package/dist/signals-De9VnwL2.js +0 -53
package/dist/knowledge/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_base = require("../base-BIzR1D3_.cjs");
|
|
3
|
-
const require_run_registry = require("../run-registry-
|
|
3
|
+
const require_run_registry = require("../run-registry-DOlZccsr.cjs");
|
|
4
4
|
const require_tool = require("../tool-CYlT2UA-.cjs");
|
|
5
5
|
let crypto = require("crypto");
|
|
6
6
|
let _mastra_schema_compat_schema = require("@mastra/schema-compat/schema");
|
|
@@ -325,7 +325,8 @@ const DECLARATION_FIELDS = {
|
|
|
325
325
|
required: true
|
|
326
326
|
},
|
|
327
327
|
parent: { kind: "nullableString" },
|
|
328
|
-
fallbackParent: { kind: "nonEmpty" }
|
|
328
|
+
fallbackParent: { kind: "nonEmpty" },
|
|
329
|
+
path: { kind: "segments" }
|
|
329
330
|
};
|
|
330
331
|
const ITEM_FIELDS = {
|
|
331
332
|
...DECLARATION_FIELDS,
|
|
@@ -371,6 +372,9 @@ function checkFields(value, fields, where) {
|
|
|
371
372
|
case "aliases":
|
|
372
373
|
out[key] = checkDenseArray(field, at).map((alias, index) => checkString(alias, `${at}[${index}]`, true));
|
|
373
374
|
break;
|
|
375
|
+
case "segments":
|
|
376
|
+
out[key] = checkDenseArray(field, at).map((segment, index) => checkString(segment, `${at}[${index}]`));
|
|
377
|
+
break;
|
|
374
378
|
case "links": out[key] = checkDenseArray(field, at).map((link, index) => checkFields(link, {
|
|
375
379
|
sourceId: {
|
|
376
380
|
kind: "nonEmpty",
|
|
@@ -1094,6 +1098,16 @@ var KnowledgeImportNotGatheredError = class extends Error {
|
|
|
1094
1098
|
}
|
|
1095
1099
|
};
|
|
1096
1100
|
/** The flush needs a call the overlay doesn't model: it falls back to the per-op path. */
|
|
1101
|
+
/**
|
|
1102
|
+
* The gather read the rows once, its plan writing pages only in place, and the decide pass went to
|
|
1103
|
+
* create, move or delete a page anyway: one more pass reads them again under the lock.
|
|
1104
|
+
*/
|
|
1105
|
+
var KnowledgeImportRereadRequiredError = class extends Error {
|
|
1106
|
+
constructor(what) {
|
|
1107
|
+
super(`The batched import flush needs its rows read again under the lock: ${what}`);
|
|
1108
|
+
this.name = "KnowledgeImportRereadRequiredError";
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1097
1111
|
var KnowledgeImportBatchUnsupportedError = class extends Error {
|
|
1098
1112
|
call;
|
|
1099
1113
|
constructor(call) {
|
|
@@ -1103,7 +1117,31 @@ var KnowledgeImportBatchUnsupportedError = class extends Error {
|
|
|
1103
1117
|
}
|
|
1104
1118
|
};
|
|
1105
1119
|
const nodeKey = (bindingId, sourceId) => `${bindingId}\u0000${sourceId}`;
|
|
1106
|
-
|
|
1120
|
+
/** The key {@link ImportOverlayRows.paths} holds a scope path under. */
|
|
1121
|
+
const importPathKey = (scopeId, path) => JSON.stringify([scopeId, ...path]);
|
|
1122
|
+
const pathKey = importPathKey;
|
|
1123
|
+
/**
|
|
1124
|
+
* The key path of each live page whose whole chain to its scope is among `pages`, to that page: a
|
|
1125
|
+
* path a read chain already answers, with no `getPagesByPaths`. One key path has one live page.
|
|
1126
|
+
*/
|
|
1127
|
+
function importChainPaths(pages) {
|
|
1128
|
+
const out = /* @__PURE__ */ new Map();
|
|
1129
|
+
for (const page of pages.values()) {
|
|
1130
|
+
if (!page || page.isScope) continue;
|
|
1131
|
+
const path = [];
|
|
1132
|
+
let at = page;
|
|
1133
|
+
while (at && !at.isScope) {
|
|
1134
|
+
if (at.key === void 0 || at.deletedAt || at.mergedInto || path.length >= 10) {
|
|
1135
|
+
at = void 0;
|
|
1136
|
+
break;
|
|
1137
|
+
}
|
|
1138
|
+
path.unshift(at.key);
|
|
1139
|
+
at = at.parentId ? pages.get(at.parentId) : null;
|
|
1140
|
+
}
|
|
1141
|
+
if (at) out.set(pathKey(at.id, path), page.id);
|
|
1142
|
+
}
|
|
1143
|
+
return out;
|
|
1144
|
+
}
|
|
1107
1145
|
const childKey = (parentId, key) => `${parentId}\u0000${key}`;
|
|
1108
1146
|
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;
|
|
1109
1147
|
/** UTF-8 byte order, as the stores sort source IDs. */
|
|
@@ -1147,7 +1185,9 @@ const copyRows = (rows) => ({
|
|
|
1147
1185
|
tooLarge: new Set(rows.tooLarge),
|
|
1148
1186
|
linkTargets: new Set(rows.linkTargets),
|
|
1149
1187
|
tooManyLinkers: new Set(rows.tooManyLinkers),
|
|
1150
|
-
...rows.bindings ? { bindings: rows.bindings } : {}
|
|
1188
|
+
...rows.bindings ? { bindings: rows.bindings } : {},
|
|
1189
|
+
...rows.inPlace ? { inPlace: true } : {},
|
|
1190
|
+
...rows.readOnce ? { readOnce: true } : {}
|
|
1151
1191
|
});
|
|
1152
1192
|
const copyState = (state) => ({
|
|
1153
1193
|
rows: copyRows(state.rows),
|
|
@@ -1268,6 +1308,17 @@ var ImportOverlay = class {
|
|
|
1268
1308
|
#setPage(id, page) {
|
|
1269
1309
|
this.#state.rows.pages.set(id, page);
|
|
1270
1310
|
this.#childIndex = void 0;
|
|
1311
|
+
this.#chainPaths = void 0;
|
|
1312
|
+
}
|
|
1313
|
+
/** {@link importChainPaths} of the working copy, kept like the child index. */
|
|
1314
|
+
#chainPaths;
|
|
1315
|
+
#pathFromChains(key) {
|
|
1316
|
+
const { pages } = this.#state.rows;
|
|
1317
|
+
if (this.#chainPaths?.pages !== pages) this.#chainPaths = {
|
|
1318
|
+
pages,
|
|
1319
|
+
byPath: importChainPaths(pages)
|
|
1320
|
+
};
|
|
1321
|
+
return this.#chainPaths.byPath.get(key);
|
|
1271
1322
|
}
|
|
1272
1323
|
/** Live ordinary children by position, once gathered. */
|
|
1273
1324
|
#children(parentId) {
|
|
@@ -1370,6 +1421,8 @@ var ImportOverlay = class {
|
|
|
1370
1421
|
if (path.length === 0) return null;
|
|
1371
1422
|
const key = pathKey(scopeId, path);
|
|
1372
1423
|
if (!rows().paths.has(key)) {
|
|
1424
|
+
const id = this.#pathFromChains(key);
|
|
1425
|
+
if (id) return this.#page(id);
|
|
1373
1426
|
this.missing.paths.set(key, {
|
|
1374
1427
|
scopeId,
|
|
1375
1428
|
path
|
|
@@ -1385,6 +1438,7 @@ var ImportOverlay = class {
|
|
|
1385
1438
|
for (const id of unlocked) this.missing.locks.add(id);
|
|
1386
1439
|
throw new KnowledgeImportNotGatheredError(`locks ${unlocked.join(", ")}`);
|
|
1387
1440
|
}
|
|
1441
|
+
return [];
|
|
1388
1442
|
},
|
|
1389
1443
|
listNotes: async ({ pageId }) => {
|
|
1390
1444
|
if (!rows().notes.has(pageId)) {
|
|
@@ -1394,6 +1448,7 @@ var ImportOverlay = class {
|
|
|
1394
1448
|
return { notes: rows().notes.get(pageId).filter((note) => !note.deletedAt) };
|
|
1395
1449
|
},
|
|
1396
1450
|
createPage: async (input) => {
|
|
1451
|
+
if (rows().readOnce) throw new KnowledgeImportRereadRequiredError("createPage");
|
|
1397
1452
|
if (input.id !== void 0 || input.position !== void 0) throw new KnowledgeImportBatchUnsupportedError("createPage with id or position");
|
|
1398
1453
|
if (!input.name.trim()) throw new Error("Knowledge page name must not be empty");
|
|
1399
1454
|
require_run_registry.assertKnowledgePageDescriptionWithinBound(input.description || void 0);
|
|
@@ -1524,6 +1579,7 @@ var ImportOverlay = class {
|
|
|
1524
1579
|
return ids;
|
|
1525
1580
|
},
|
|
1526
1581
|
movePage: async (input) => {
|
|
1582
|
+
if (rows().readOnce) throw new KnowledgeImportRereadRequiredError("movePage");
|
|
1527
1583
|
if (input.position !== void 0) throw new KnowledgeImportBatchUnsupportedError("movePage with a position");
|
|
1528
1584
|
const page = this.#livePage(input.id);
|
|
1529
1585
|
if (page.isScope) throw new Error(`Knowledge scope page ${page.id} can't be moved`);
|
|
@@ -1544,7 +1600,12 @@ var ImportOverlay = class {
|
|
|
1544
1600
|
if (parentDepth + 1 + Math.max(...subtree.map((entry) => entry.depth)) > 10) throw new require_run_registry.KnowledgePageDepthError(page.id);
|
|
1545
1601
|
const scopeId = parent.isScope ? parent.id : parent.scopeId;
|
|
1546
1602
|
if (scopeId !== page.scopeId) throw new KnowledgeImportBatchUnsupportedError("movePage across scopes");
|
|
1547
|
-
|
|
1603
|
+
const key = input.key ?? page.key;
|
|
1604
|
+
if (input.key !== void 0) {
|
|
1605
|
+
const problem = require_run_registry.knowledgePageKeyProblem(input.key);
|
|
1606
|
+
if (problem) throw new Error(problem);
|
|
1607
|
+
}
|
|
1608
|
+
if (key !== void 0) {
|
|
1548
1609
|
const parentKeys = parent.isScope ? {
|
|
1549
1610
|
scopeId: parent.id,
|
|
1550
1611
|
path: []
|
|
@@ -1552,10 +1613,10 @@ var ImportOverlay = class {
|
|
|
1552
1613
|
if (!parentKeys) throw new KnowledgeImportBatchUnsupportedError("movePage under a broken chain");
|
|
1553
1614
|
const clash = await impl.getPageByPath({
|
|
1554
1615
|
scopeId,
|
|
1555
|
-
path: [...parentKeys.path,
|
|
1616
|
+
path: [...parentKeys.path, key],
|
|
1556
1617
|
read: "all"
|
|
1557
1618
|
});
|
|
1558
|
-
if (clash && clash.id !== page.id) throw new require_run_registry.KnowledgePageKeyConflictError(
|
|
1619
|
+
if (clash && clash.id !== page.id) throw new require_run_registry.KnowledgePageKeyConflictError(key, parent.id);
|
|
1559
1620
|
}
|
|
1560
1621
|
if (this.#state.moved.has(page.id)) throw new KnowledgeImportBatchUnsupportedError("a second move of a page");
|
|
1561
1622
|
const position = this.#nextPosition(parent.id);
|
|
@@ -1563,6 +1624,7 @@ var ImportOverlay = class {
|
|
|
1563
1624
|
const at = now();
|
|
1564
1625
|
const moved = {
|
|
1565
1626
|
...page,
|
|
1627
|
+
...key !== void 0 ? { key } : {},
|
|
1566
1628
|
parentId: parent.id,
|
|
1567
1629
|
position,
|
|
1568
1630
|
version: page.version + 1,
|
|
@@ -1582,6 +1644,7 @@ var ImportOverlay = class {
|
|
|
1582
1644
|
fromScopeId: page.scopeId,
|
|
1583
1645
|
expectedVersion: input.expectedVersion,
|
|
1584
1646
|
parentId: parent.id,
|
|
1647
|
+
...input.key !== void 0 ? { key: input.key } : {},
|
|
1585
1648
|
scopeId,
|
|
1586
1649
|
depth: parentDepth + 1,
|
|
1587
1650
|
position,
|
|
@@ -1590,6 +1653,7 @@ var ImportOverlay = class {
|
|
|
1590
1653
|
return structuredClone(moved);
|
|
1591
1654
|
},
|
|
1592
1655
|
deletePage: async (input) => {
|
|
1656
|
+
if (rows().readOnce) throw new KnowledgeImportRereadRequiredError("deletePage");
|
|
1593
1657
|
const page = this.#livePage(input.id);
|
|
1594
1658
|
if (page.isScope) throw new Error(`Knowledge scope page ${page.id} can't be deleted`);
|
|
1595
1659
|
if (page.version !== input.expectedVersion) throw new require_run_registry.KnowledgeConflictError(page.id);
|
|
@@ -1712,6 +1776,17 @@ var ImportOverlay = class {
|
|
|
1712
1776
|
const key = rows().nodesByPage.get(pageId);
|
|
1713
1777
|
return key ? structuredClone(this.#node(key)) : null;
|
|
1714
1778
|
},
|
|
1779
|
+
getNodesByPages: async (pageIds) => {
|
|
1780
|
+
const unread = [...new Set(pageIds)].filter((pageId) => !rows().nodesByPage.has(pageId));
|
|
1781
|
+
if (unread.length) {
|
|
1782
|
+
for (const pageId of unread) this.missing.nodesByPage.add(pageId);
|
|
1783
|
+
throw new KnowledgeImportNotGatheredError(`nodes of pages ${unread.join(", ")}`);
|
|
1784
|
+
}
|
|
1785
|
+
return [...new Set(pageIds)].flatMap((pageId) => {
|
|
1786
|
+
const node = rows().nodesByPage.get(pageId) ? this.#node(rows().nodesByPage.get(pageId)) : null;
|
|
1787
|
+
return node ? [structuredClone(node)] : [];
|
|
1788
|
+
});
|
|
1789
|
+
},
|
|
1715
1790
|
saveNode: async (node) => {
|
|
1716
1791
|
const key = nodeKey(node.bindingId, node.sourceId);
|
|
1717
1792
|
const mapped = rows().nodesByPage.get(node.pageId);
|
|
@@ -1818,36 +1893,84 @@ async function readImportRows(input) {
|
|
|
1818
1893
|
...missing?.pages ?? [],
|
|
1819
1894
|
...missing?.locks ?? []
|
|
1820
1895
|
]));
|
|
1821
|
-
|
|
1822
|
-
const roots = [.../* @__PURE__ */ new Set([...plan.subtrees, ...missing?.subtrees ?? []])].filter((id) => !rows.complete.has(id));
|
|
1896
|
+
let plan = input.plan(rows);
|
|
1823
1897
|
const carried = [];
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1898
|
+
let held = [];
|
|
1899
|
+
let settled = false;
|
|
1900
|
+
for (let stage = 0; stage < GATHER_PLAN_STAGES; stage++) {
|
|
1901
|
+
if (stage) plan = input.plan(rows);
|
|
1902
|
+
const before = rows.pages.size + rows.paths.size + rows.complete.size;
|
|
1903
|
+
const roots = [.../* @__PURE__ */ new Set([...plan.subtrees, ...stage ? [] : missing?.subtrees ?? []])].filter((id) => !rows.complete.has(id) && !rows.tooLarge.has(id));
|
|
1904
|
+
if (roots.length) {
|
|
1905
|
+
const subtrees = await storage.getPageSubtrees({
|
|
1906
|
+
rootIds: roots,
|
|
1907
|
+
limit: 499
|
|
1908
|
+
});
|
|
1909
|
+
for (const root of roots) {
|
|
1910
|
+
const pages = subtrees[root];
|
|
1911
|
+
if (!pages) {
|
|
1912
|
+
rows.tooLarge.add(root);
|
|
1913
|
+
continue;
|
|
1914
|
+
}
|
|
1915
|
+
rows.complete.add(root);
|
|
1916
|
+
for (const page of pages) {
|
|
1917
|
+
rows.pages.set(page.id, page);
|
|
1918
|
+
rows.complete.add(page.id);
|
|
1919
|
+
carried.push(page.id);
|
|
1920
|
+
}
|
|
1834
1921
|
}
|
|
1835
|
-
rows.
|
|
1836
|
-
|
|
1837
|
-
rows.
|
|
1838
|
-
|
|
1839
|
-
|
|
1922
|
+
const unmapped = carried.filter((id) => !rows.nodesByPage.has(id));
|
|
1923
|
+
if (unmapped.length) {
|
|
1924
|
+
for (const id of unmapped) rows.nodesByPage.set(id, null);
|
|
1925
|
+
for (const node of await importers.getNodesByPages(unmapped)) {
|
|
1926
|
+
const key = nodeKey(node.bindingId, node.sourceId);
|
|
1927
|
+
rows.nodes.set(key, node);
|
|
1928
|
+
rows.nodesByPage.set(node.pageId, key);
|
|
1929
|
+
}
|
|
1840
1930
|
}
|
|
1841
1931
|
}
|
|
1842
|
-
const
|
|
1843
|
-
if (
|
|
1844
|
-
|
|
1845
|
-
|
|
1932
|
+
const paths = new Map(plan.paths.map((each) => [pathKey(each.scopeId, each.path), each]));
|
|
1933
|
+
if (!stage) for (const [key, each] of missing?.paths ?? []) paths.set(key, each);
|
|
1934
|
+
for (const key of [...paths.keys()]) if (rows.paths.has(key)) paths.delete(key);
|
|
1935
|
+
const byScope = /* @__PURE__ */ new Map();
|
|
1936
|
+
for (const [key, { scopeId, path }] of paths) {
|
|
1937
|
+
if (path.length === 0) continue;
|
|
1938
|
+
byScope.set(scopeId, [...byScope.get(scopeId) ?? [], {
|
|
1939
|
+
key,
|
|
1940
|
+
path
|
|
1941
|
+
}]);
|
|
1942
|
+
}
|
|
1943
|
+
for (const [scopeId, entries] of byScope) {
|
|
1944
|
+
const found = await storage.getPagesByPaths({
|
|
1945
|
+
scopeId,
|
|
1946
|
+
paths: entries.map((each) => each.path),
|
|
1947
|
+
read: "all"
|
|
1948
|
+
});
|
|
1949
|
+
entries.forEach((each, i) => {
|
|
1950
|
+
const page = found[i] ?? null;
|
|
1951
|
+
rows.paths.set(each.key, page?.id ?? null);
|
|
1952
|
+
if (page && !rows.pages.has(page.id)) rows.pages.set(page.id, page);
|
|
1953
|
+
});
|
|
1954
|
+
}
|
|
1955
|
+
held = [...rows.paths.values()].filter((id) => !!id);
|
|
1956
|
+
await addChains(new Set(held.map((id) => rows.pages.get(id)?.parentId).filter((id) => !!id)));
|
|
1957
|
+
const byPage = [...new Set([
|
|
1958
|
+
...held,
|
|
1959
|
+
...plan.holders ?? [],
|
|
1960
|
+
...stage ? [] : missing?.nodesByPage ?? []
|
|
1961
|
+
].filter((id) => !rows.nodesByPage.has(id)))];
|
|
1962
|
+
if (byPage.length) {
|
|
1963
|
+
for (const id of byPage) rows.nodesByPage.set(id, null);
|
|
1964
|
+
for (const node of await importers.getNodesByPages(byPage)) {
|
|
1846
1965
|
const key = nodeKey(node.bindingId, node.sourceId);
|
|
1847
1966
|
rows.nodes.set(key, node);
|
|
1848
1967
|
rows.nodesByPage.set(node.pageId, key);
|
|
1849
1968
|
}
|
|
1850
1969
|
}
|
|
1970
|
+
if (rows.pages.size + rows.paths.size + rows.complete.size === before) {
|
|
1971
|
+
settled = true;
|
|
1972
|
+
break;
|
|
1973
|
+
}
|
|
1851
1974
|
}
|
|
1852
1975
|
const targets = new Set(plan.linkTargets);
|
|
1853
1976
|
for (const id of carried) {
|
|
@@ -1879,39 +2002,6 @@ async function readImportRows(input) {
|
|
|
1879
2002
|
await addChains(new Set([...linkers, ...reached].map((node) => node.pageId)));
|
|
1880
2003
|
}
|
|
1881
2004
|
if (plan.bindings || missing?.bindings.size) rows.bindings ??= await importers.listBindings();
|
|
1882
|
-
const paths = new Map(plan.paths.map((each) => [pathKey(each.scopeId, each.path), each]));
|
|
1883
|
-
for (const [key, each] of missing?.paths ?? []) paths.set(key, each);
|
|
1884
|
-
const byScope = /* @__PURE__ */ new Map();
|
|
1885
|
-
for (const [key, { scopeId, path }] of paths) {
|
|
1886
|
-
if (path.length === 0) continue;
|
|
1887
|
-
byScope.set(scopeId, [...byScope.get(scopeId) ?? [], {
|
|
1888
|
-
key,
|
|
1889
|
-
path
|
|
1890
|
-
}]);
|
|
1891
|
-
}
|
|
1892
|
-
for (const [scopeId, entries] of byScope) {
|
|
1893
|
-
const found = await storage.getPagesByPaths({
|
|
1894
|
-
scopeId,
|
|
1895
|
-
paths: entries.map((each) => each.path),
|
|
1896
|
-
read: "all"
|
|
1897
|
-
});
|
|
1898
|
-
entries.forEach((each, i) => {
|
|
1899
|
-
const page = found[i] ?? null;
|
|
1900
|
-
rows.paths.set(each.key, page?.id ?? null);
|
|
1901
|
-
if (page && !rows.pages.has(page.id)) rows.pages.set(page.id, page);
|
|
1902
|
-
});
|
|
1903
|
-
}
|
|
1904
|
-
const held = [...rows.paths.values()].filter((id) => !!id);
|
|
1905
|
-
await addChains(new Set(held.map((id) => rows.pages.get(id)?.parentId).filter((id) => !!id)));
|
|
1906
|
-
const byPage = [...new Set([...held, ...missing?.nodesByPage ?? []].filter((id) => !rows.nodesByPage.has(id)))];
|
|
1907
|
-
if (byPage.length) {
|
|
1908
|
-
for (const id of byPage) rows.nodesByPage.set(id, null);
|
|
1909
|
-
for (const node of await importers.getNodesByPages(byPage)) {
|
|
1910
|
-
const key = nodeKey(node.bindingId, node.sourceId);
|
|
1911
|
-
rows.nodes.set(key, node);
|
|
1912
|
-
rows.nodesByPage.set(node.pageId, key);
|
|
1913
|
-
}
|
|
1914
|
-
}
|
|
1915
2005
|
const notes = [.../* @__PURE__ */ new Set([
|
|
1916
2006
|
...plan.notes,
|
|
1917
2007
|
...held,
|
|
@@ -1929,8 +2019,11 @@ async function readImportRows(input) {
|
|
|
1929
2019
|
const last = await storage.getLastChildPositions({ parentIds: positions });
|
|
1930
2020
|
for (const id of positions) rows.positions.set(id, last[id] ?? null);
|
|
1931
2021
|
}
|
|
2022
|
+
rows.inPlace = settled && !!plan.inPlace;
|
|
1932
2023
|
return rows;
|
|
1933
2024
|
}
|
|
2025
|
+
/** Times one gather plans again from what it read (path folders, then the page at the path, then its children). */
|
|
2026
|
+
const GATHER_PLAN_STAGES = 4;
|
|
1934
2027
|
/** Most linking nodes one gather reads; past it, a flush that lists them is saved op by op. */
|
|
1935
2028
|
const LINKING_NODES_READ = 500;
|
|
1936
2029
|
/** Live, non-scope pages among the rows: the ones a decide pass may lock. */
|
|
@@ -1944,14 +2037,27 @@ const lockable = (rows) => [...rows.pages.values()].filter((page) => !!page && !
|
|
|
1944
2037
|
async function gatherImportRows(input) {
|
|
1945
2038
|
const locked = new Set(input.locked ?? []);
|
|
1946
2039
|
let rows = await readImportRows(input);
|
|
2040
|
+
if (input.storage.getCapabilities().serializedWriteTransactions && rows.notes.size === 0) {
|
|
2041
|
+
for (const id of lockable(rows)) locked.add(id);
|
|
2042
|
+
rows.locked = locked;
|
|
2043
|
+
return rows;
|
|
2044
|
+
}
|
|
1947
2045
|
for (let round = 0; round < (input.rounds ?? 3); round++) {
|
|
1948
2046
|
const unlocked = lockable(rows).filter((id) => !locked.has(id));
|
|
1949
2047
|
if (!unlocked.length) {
|
|
1950
2048
|
rows.locked = locked;
|
|
1951
2049
|
return rows;
|
|
1952
2050
|
}
|
|
1953
|
-
await input.storage.lockPages(unlocked.sort());
|
|
2051
|
+
const versions = await input.storage.lockPages(unlocked.sort());
|
|
1954
2052
|
for (const id of unlocked) locked.add(id);
|
|
2053
|
+
if (round === 0 && !input.reread && rows.inPlace && rows.notes.size === 0 && Array.isArray(versions) && versions.length === unlocked.length) {
|
|
2054
|
+
const read = new Map(versions.map((row) => [row.id, row.version]));
|
|
2055
|
+
if (unlocked.every((id) => read.get(id) === rows.pages.get(id)?.version)) {
|
|
2056
|
+
rows.locked = locked;
|
|
2057
|
+
rows.readOnce = true;
|
|
2058
|
+
return rows;
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
1955
2061
|
rows = await readImportRows(input);
|
|
1956
2062
|
}
|
|
1957
2063
|
return null;
|
|
@@ -2052,6 +2158,24 @@ function knowledgeImportKey(sourceId) {
|
|
|
2052
2158
|
return sourceId.replace(/[/#%:~]/g, (char) => `~${char.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
2053
2159
|
}
|
|
2054
2160
|
const live = (page) => !!page && !page.deletedAt && !page.mergedInto;
|
|
2161
|
+
/** Source IDs the host keeps for the folders it makes on an item's path; importers can't send them. */
|
|
2162
|
+
const KNOWLEDGE_IMPORT_PATH_STUB_PREFIX = "~path:";
|
|
2163
|
+
/**
|
|
2164
|
+
* Why an item can never land, whatever the store holds: a reserved `sourceId`, or a `path` the host
|
|
2165
|
+
* can't place (with `parent` or `fallbackParent`, empty, an empty or blank segment, a page key too long to
|
|
2166
|
+
* link to, or deeper than a page can sit under a target `targetDepth` keys deep). Null when it can.
|
|
2167
|
+
*/
|
|
2168
|
+
function knowledgeImportItemProblem(item, targetDepth) {
|
|
2169
|
+
if (item.sourceId.startsWith("~path:")) return `sourceId must not start with "${KNOWLEDGE_IMPORT_PATH_STUB_PREFIX}"`;
|
|
2170
|
+
const { path } = item;
|
|
2171
|
+
if (path === void 0) return null;
|
|
2172
|
+
if (item.parent != null || item.fallbackParent !== void 0) return "path is not allowed with parent or fallbackParent";
|
|
2173
|
+
if (path.length === 0) return "path must have at least one segment";
|
|
2174
|
+
if (path.some((segment) => !segment.trim())) return "path segments must not be empty or blank";
|
|
2175
|
+
if (path.some((segment) => knowledgeImportKey(segment).length > 512)) return `path segment keys must be at most 512 characters`;
|
|
2176
|
+
if (targetDepth + path.length > 10) return `path would sit more than 10 levels below the scope`;
|
|
2177
|
+
return null;
|
|
2178
|
+
}
|
|
2055
2179
|
/** Core errors that mean "this op can't land here", by name: an adapter may carry its own core copy. */
|
|
2056
2180
|
function refusalFor(error) {
|
|
2057
2181
|
if (error instanceof KnowledgeImportRefusalError) return error.reason;
|
|
@@ -2087,11 +2211,17 @@ function order(ops) {
|
|
|
2087
2211
|
const id = op.op === "remove" ? op.sourceId : op.item.sourceId;
|
|
2088
2212
|
const before = last.get(id);
|
|
2089
2213
|
if (op.op === "declare" && before?.op === "upsert") {
|
|
2214
|
+
const { parent, fallbackParent, path, ...rest } = before.item;
|
|
2215
|
+
const kept = op.item.path !== void 0 ? rest : op.item.parent !== void 0 || op.item.fallbackParent !== void 0 ? {
|
|
2216
|
+
...rest,
|
|
2217
|
+
...parent !== void 0 ? { parent } : {},
|
|
2218
|
+
...fallbackParent !== void 0 ? { fallbackParent } : {}
|
|
2219
|
+
} : before.item;
|
|
2090
2220
|
last.delete(id);
|
|
2091
2221
|
last.set(id, {
|
|
2092
2222
|
op: "upsert",
|
|
2093
2223
|
item: {
|
|
2094
|
-
...
|
|
2224
|
+
...kept,
|
|
2095
2225
|
...op.item
|
|
2096
2226
|
}
|
|
2097
2227
|
});
|
|
@@ -2155,7 +2285,19 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2155
2285
|
embeds: [],
|
|
2156
2286
|
applied: false
|
|
2157
2287
|
};
|
|
2158
|
-
const
|
|
2288
|
+
const rekey = !!storage.getCapabilities().supportsPageRekey;
|
|
2289
|
+
let ops = order(input.ops).filter((op) => {
|
|
2290
|
+
const sourceId = op.op === "remove" ? op.sourceId : op.item.sourceId;
|
|
2291
|
+
const problem = op.op === "remove" ? sourceId.startsWith(KNOWLEDGE_IMPORT_PATH_STUB_PREFIX) : !!knowledgeImportItemProblem(op.item, 1);
|
|
2292
|
+
const unplaceable = op.op !== "remove" && op.item.path !== void 0 && !rekey;
|
|
2293
|
+
if (!problem && !unplaceable) return true;
|
|
2294
|
+
if (!problem) result.pathsUnsupported = true;
|
|
2295
|
+
result.refused.push({
|
|
2296
|
+
sourceId,
|
|
2297
|
+
reason: "invalid"
|
|
2298
|
+
});
|
|
2299
|
+
return false;
|
|
2300
|
+
});
|
|
2159
2301
|
if (ops.length === 0 && !(input.settle && binding.anchorPageId)) {
|
|
2160
2302
|
if (input.settle) result.settle = {
|
|
2161
2303
|
pending: false,
|
|
@@ -2168,9 +2310,11 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2168
2310
|
const keyPath = async (page) => {
|
|
2169
2311
|
const keys = [];
|
|
2170
2312
|
const ids = [];
|
|
2313
|
+
const versions = [];
|
|
2171
2314
|
if (page.isScope) return page.id === scope.id ? {
|
|
2172
2315
|
keys,
|
|
2173
|
-
ids
|
|
2316
|
+
ids,
|
|
2317
|
+
versions
|
|
2174
2318
|
} : null;
|
|
2175
2319
|
const parents = page.parentId ? await storage.getPageParents({
|
|
2176
2320
|
parentId: page.parentId,
|
|
@@ -2179,11 +2323,13 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2179
2323
|
for (const at of [page, ...parents]) {
|
|
2180
2324
|
if (at.isScope) return at.id === scope.id ? {
|
|
2181
2325
|
keys,
|
|
2182
|
-
ids
|
|
2326
|
+
ids,
|
|
2327
|
+
versions
|
|
2183
2328
|
} : null;
|
|
2184
2329
|
if (!live(at) || at.key === void 0) return null;
|
|
2185
2330
|
keys.unshift(at.key);
|
|
2186
2331
|
ids.unshift(at.id);
|
|
2332
|
+
versions.unshift(at.version);
|
|
2187
2333
|
}
|
|
2188
2334
|
return null;
|
|
2189
2335
|
};
|
|
@@ -2216,8 +2362,17 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2216
2362
|
read: "all"
|
|
2217
2363
|
});
|
|
2218
2364
|
const path = live(page) ? await keyPath(page) : null;
|
|
2365
|
+
if (page && path && storage.getCapabilities().serializedWriteTransactions) return {
|
|
2366
|
+
page,
|
|
2367
|
+
keys: path.keys
|
|
2368
|
+
};
|
|
2219
2369
|
if (page && path) {
|
|
2220
|
-
|
|
2370
|
+
const read = new Map(path.ids.map((id, i) => [id, path.versions[i]]));
|
|
2371
|
+
const locked = await storage.lockPages(path.ids);
|
|
2372
|
+
if (Array.isArray(locked) && locked.length === read.size && locked.every((row) => read.get(row.id) === row.version)) return {
|
|
2373
|
+
page,
|
|
2374
|
+
keys: path.keys
|
|
2375
|
+
};
|
|
2221
2376
|
const fresh = await storage.getPage({
|
|
2222
2377
|
id: page.id,
|
|
2223
2378
|
read: "all"
|
|
@@ -2298,6 +2453,15 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2298
2453
|
return result;
|
|
2299
2454
|
}
|
|
2300
2455
|
const anchorPath = anchor?.keys ?? [];
|
|
2456
|
+
ops = ops.filter((op) => {
|
|
2457
|
+
if (op.op === "remove" || !op.item.path) return true;
|
|
2458
|
+
if (anchorPath.length + op.item.path.length <= 10) return true;
|
|
2459
|
+
result.refused.push({
|
|
2460
|
+
sourceId: op.item.sourceId,
|
|
2461
|
+
reason: "invalid"
|
|
2462
|
+
});
|
|
2463
|
+
return false;
|
|
2464
|
+
});
|
|
2301
2465
|
/**
|
|
2302
2466
|
* A page this binding owns, checked after locking: live, in the target's scope, mapped back to the
|
|
2303
2467
|
* node. A person may have moved it out of the anchor, under anyone's pages: it is still the
|
|
@@ -2397,6 +2561,90 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2397
2561
|
return node && await stateOf(node) === "live" ? node : null;
|
|
2398
2562
|
};
|
|
2399
2563
|
const ref = (keys) => `${target.scope}#${keys.join("/")}`;
|
|
2564
|
+
/** The folders an op's path made, counted as created once the op lands. */
|
|
2565
|
+
let madeFolders = [];
|
|
2566
|
+
/**
|
|
2567
|
+
* The page a path item goes under: the anchor, then each segment but the last. A live page at a
|
|
2568
|
+
* segment is used as it is, whoever wrote it; a missing one (a merged page reads as missing, as a
|
|
2569
|
+
* merged parent does for a new child) becomes an empty folder this binding owns, keyed
|
|
2570
|
+
* `~path:<keys>`, that the item sending that path takes over. Returns the node the item is under,
|
|
2571
|
+
* when it is this binding's.
|
|
2572
|
+
*/
|
|
2573
|
+
const pathFolders = async (path) => {
|
|
2574
|
+
let at = anchor;
|
|
2575
|
+
let parentSourceId = null;
|
|
2576
|
+
let holderOf = null;
|
|
2577
|
+
const readHolder = async () => {
|
|
2578
|
+
if (!holderOf) return;
|
|
2579
|
+
const holder = await importers.getNodeByPage(holderOf.id);
|
|
2580
|
+
parentSourceId = holder?.bindingId === binding.id ? holder.sourceId : null;
|
|
2581
|
+
holderOf = null;
|
|
2582
|
+
};
|
|
2583
|
+
const relative = [];
|
|
2584
|
+
for (const segment of path.slice(0, -1)) {
|
|
2585
|
+
const key = knowledgeImportKey(segment);
|
|
2586
|
+
relative.push(key);
|
|
2587
|
+
const keys = [...at.keys, key];
|
|
2588
|
+
const found = await storage.getPageByPath({
|
|
2589
|
+
scopeId: scope.id,
|
|
2590
|
+
path: keys,
|
|
2591
|
+
read: "all"
|
|
2592
|
+
});
|
|
2593
|
+
if (found) {
|
|
2594
|
+
await storage.lockPages([found.id]);
|
|
2595
|
+
const fresh = await storage.getPage({
|
|
2596
|
+
id: found.id,
|
|
2597
|
+
read: "all"
|
|
2598
|
+
});
|
|
2599
|
+
if (!live(fresh) || fresh.parentId !== at.page.id || fresh.key !== key) throw new KnowledgeImportRefusalError("conflict");
|
|
2600
|
+
holderOf = fresh;
|
|
2601
|
+
at = {
|
|
2602
|
+
page: fresh,
|
|
2603
|
+
keys
|
|
2604
|
+
};
|
|
2605
|
+
continue;
|
|
2606
|
+
}
|
|
2607
|
+
await readHolder();
|
|
2608
|
+
const sourceId = KNOWLEDGE_IMPORT_PATH_STUB_PREFIX + relative.join("/");
|
|
2609
|
+
const page = await storage.createPage({
|
|
2610
|
+
parentId: at.page.id,
|
|
2611
|
+
key,
|
|
2612
|
+
name: segment,
|
|
2613
|
+
body: "",
|
|
2614
|
+
provenance
|
|
2615
|
+
});
|
|
2616
|
+
await importers.saveNode({
|
|
2617
|
+
bindingId: binding.id,
|
|
2618
|
+
sourceId,
|
|
2619
|
+
pageId: page.id,
|
|
2620
|
+
kind: null,
|
|
2621
|
+
parentSourceId,
|
|
2622
|
+
aliases: [],
|
|
2623
|
+
unresolvedLinks: [],
|
|
2624
|
+
links: [],
|
|
2625
|
+
linkSection: null,
|
|
2626
|
+
stub: false,
|
|
2627
|
+
adopted: false,
|
|
2628
|
+
unsettled: false
|
|
2629
|
+
});
|
|
2630
|
+
await links(page, { pages: [page] });
|
|
2631
|
+
madeFolders.push({
|
|
2632
|
+
sourceId,
|
|
2633
|
+
page,
|
|
2634
|
+
keys
|
|
2635
|
+
});
|
|
2636
|
+
parentSourceId = sourceId;
|
|
2637
|
+
at = {
|
|
2638
|
+
page,
|
|
2639
|
+
keys
|
|
2640
|
+
};
|
|
2641
|
+
}
|
|
2642
|
+
await readHolder();
|
|
2643
|
+
return {
|
|
2644
|
+
destination: at,
|
|
2645
|
+
parentSourceId
|
|
2646
|
+
};
|
|
2647
|
+
};
|
|
2400
2648
|
const linkLine = async (link, node) => {
|
|
2401
2649
|
const page = node ? await storage.getPage({
|
|
2402
2650
|
id: node.pageId,
|
|
@@ -2502,7 +2750,7 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2502
2750
|
* and the pages it rewrote; the caller counts them once its op lands.
|
|
2503
2751
|
*/
|
|
2504
2752
|
let deferredLinkers = false;
|
|
2505
|
-
const moveOwned = async (self, page, parent) => {
|
|
2753
|
+
const moveOwned = async (self, page, parent, key) => {
|
|
2506
2754
|
const targets = [];
|
|
2507
2755
|
const othersTargets = /* @__PURE__ */ new Map();
|
|
2508
2756
|
await storage.lockSubtree(page.id);
|
|
@@ -2516,6 +2764,7 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2516
2764
|
id: page.id,
|
|
2517
2765
|
expectedVersion: page.version,
|
|
2518
2766
|
parentId: parent.page.id,
|
|
2767
|
+
...key !== void 0 && key !== page.key ? { key } : {},
|
|
2519
2768
|
provenance
|
|
2520
2769
|
});
|
|
2521
2770
|
const keys = [...parent.keys, moved.key];
|
|
@@ -2571,6 +2820,97 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2571
2820
|
});
|
|
2572
2821
|
}
|
|
2573
2822
|
};
|
|
2823
|
+
/**
|
|
2824
|
+
* Frees `key` under `destination` for a path item's own page to move onto. A folder of this binding's
|
|
2825
|
+
* that holds the path is absorbed: its children move under the item's page in order, their nodes
|
|
2826
|
+
* point at the item, a body a person wrote in it is kept in a note on the item's page, and the empty
|
|
2827
|
+
* folder goes. A folder someone left notes on, or whose body would replace a body the item's page
|
|
2828
|
+
* already keeps, is not absorbed: the item is refused `occupied`, as for any other page at the path.
|
|
2829
|
+
* An item inside the folder, sent at the folder's path, leaves it first under a key no item uses, so
|
|
2830
|
+
* it never moves under itself; the move after this one gives it the folder's key. Returns whether it
|
|
2831
|
+
* kept a body (the item then holds a person's text, so its removal gives that back) and the item's
|
|
2832
|
+
* page as it is now.
|
|
2833
|
+
*/
|
|
2834
|
+
const absorbAt = async (self, destination, key, page) => {
|
|
2835
|
+
const held = await storage.getPageByPath({
|
|
2836
|
+
scopeId: scope.id,
|
|
2837
|
+
path: [...destination.keys, key],
|
|
2838
|
+
read: "all"
|
|
2839
|
+
});
|
|
2840
|
+
if (!held || held.id === page.id) return {
|
|
2841
|
+
kept: false,
|
|
2842
|
+
page
|
|
2843
|
+
};
|
|
2844
|
+
await storage.lockPages([held.id]);
|
|
2845
|
+
const stub = await storage.getPage({
|
|
2846
|
+
id: held.id,
|
|
2847
|
+
read: "all"
|
|
2848
|
+
});
|
|
2849
|
+
if (!live(stub) || stub.parentId !== destination.page.id || stub.key !== key) throw new KnowledgeImportRefusalError("occupied");
|
|
2850
|
+
const holder = await importers.getNodeByPage(stub.id);
|
|
2851
|
+
if (holder?.bindingId !== binding.id || !holder.sourceId.startsWith("~path:")) throw new KnowledgeImportRefusalError("occupied");
|
|
2852
|
+
if ((await storage.listNotes({
|
|
2853
|
+
pageId: stub.id,
|
|
2854
|
+
read: "all",
|
|
2855
|
+
limit: 1
|
|
2856
|
+
})).notes.length > 0) throw new KnowledgeImportRefusalError("occupied");
|
|
2857
|
+
if (stub.body && (await keptBodyNotes(page.id)).length > 0) throw new KnowledgeImportRefusalError("occupied");
|
|
2858
|
+
const children = [];
|
|
2859
|
+
let cursor;
|
|
2860
|
+
do {
|
|
2861
|
+
const out = await storage.listChildPages({
|
|
2862
|
+
parentId: stub.id,
|
|
2863
|
+
read: "all",
|
|
2864
|
+
...cursor ? { cursor } : {}
|
|
2865
|
+
});
|
|
2866
|
+
children.push(...out.pages);
|
|
2867
|
+
cursor = out.nextCursor;
|
|
2868
|
+
} while (cursor);
|
|
2869
|
+
let inside = page.parentId;
|
|
2870
|
+
while (inside && inside !== stub.id) inside = (await storage.getPage({
|
|
2871
|
+
id: inside,
|
|
2872
|
+
read: "all"
|
|
2873
|
+
}))?.parentId ?? null;
|
|
2874
|
+
if (inside) {
|
|
2875
|
+
await storage.lockSubtree(page.id);
|
|
2876
|
+
page = await storage.movePage({
|
|
2877
|
+
id: page.id,
|
|
2878
|
+
expectedVersion: page.version,
|
|
2879
|
+
parentId: destination.page.id,
|
|
2880
|
+
key: `~absorbing-${(0, crypto.randomUUID)()}`,
|
|
2881
|
+
provenance
|
|
2882
|
+
});
|
|
2883
|
+
}
|
|
2884
|
+
for (const child of children.filter((child) => child.id !== page.id)) {
|
|
2885
|
+
await storage.lockSubtree(child.id);
|
|
2886
|
+
await storage.movePage({
|
|
2887
|
+
id: child.id,
|
|
2888
|
+
expectedVersion: child.version,
|
|
2889
|
+
parentId: page.id,
|
|
2890
|
+
provenance
|
|
2891
|
+
});
|
|
2892
|
+
const node = await importers.getNodeByPage(child.id);
|
|
2893
|
+
if (node?.bindingId === binding.id && node.parentSourceId === holder.sourceId) await importers.saveNode({
|
|
2894
|
+
...node,
|
|
2895
|
+
parentSourceId: self
|
|
2896
|
+
});
|
|
2897
|
+
}
|
|
2898
|
+
if (stub.body) await keepBody(page.id, stub.body);
|
|
2899
|
+
const emptied = await storage.getPage({
|
|
2900
|
+
id: stub.id,
|
|
2901
|
+
read: "all"
|
|
2902
|
+
});
|
|
2903
|
+
await storage.deletePage({
|
|
2904
|
+
id: stub.id,
|
|
2905
|
+
expectedVersion: emptied.version,
|
|
2906
|
+
deletedBy: provenance.author
|
|
2907
|
+
});
|
|
2908
|
+
await importers.deleteNode(binding.id, holder.sourceId);
|
|
2909
|
+
return {
|
|
2910
|
+
kept: !!stub.body,
|
|
2911
|
+
page
|
|
2912
|
+
};
|
|
2913
|
+
};
|
|
2574
2914
|
const write = async (item, hasBody) => {
|
|
2575
2915
|
let existing = await importers.getNode(binding.id, item.sourceId);
|
|
2576
2916
|
const state = existing ? await stateOf(existing) : null;
|
|
@@ -2585,7 +2925,19 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2585
2925
|
const parentMerged = parentState === "merged";
|
|
2586
2926
|
const misplaced = !!item.parent && !sourceParent && !parentMerged;
|
|
2587
2927
|
const parentNode = sourceParent ?? await liveNodeOf(item.fallbackParent);
|
|
2588
|
-
|
|
2928
|
+
let destination = parentNode ? await owned(parentNode.pageId, parentNode.sourceId) : anchor;
|
|
2929
|
+
let key = knowledgeImportKey(item.sourceId);
|
|
2930
|
+
let parentSourceId = item.parent ?? null;
|
|
2931
|
+
if (item.path) {
|
|
2932
|
+
const current = existing ? await owned(existing.pageId, item.sourceId) : null;
|
|
2933
|
+
if (current?.outside) {
|
|
2934
|
+
key = current.page.key;
|
|
2935
|
+
parentSourceId = existing.parentSourceId;
|
|
2936
|
+
} else {
|
|
2937
|
+
({destination, parentSourceId} = await pathFolders(item.path));
|
|
2938
|
+
key = knowledgeImportKey(item.path.at(-1));
|
|
2939
|
+
}
|
|
2940
|
+
}
|
|
2589
2941
|
if (existing && destination.page.id === existing.pageId) throw new KnowledgeImportRefusalError("invalid");
|
|
2590
2942
|
let rendered = hasBody ? await renderBody(item) : void 0;
|
|
2591
2943
|
let fields = {
|
|
@@ -2593,7 +2945,6 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2593
2945
|
...item.description !== void 0 ? { description: item.description } : {},
|
|
2594
2946
|
...rendered ? { body: rendered.body } : {}
|
|
2595
2947
|
};
|
|
2596
|
-
const key = knowledgeImportKey(item.sourceId);
|
|
2597
2948
|
let page;
|
|
2598
2949
|
let change;
|
|
2599
2950
|
let moved = false;
|
|
@@ -2613,9 +2964,34 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2613
2964
|
read: "all"
|
|
2614
2965
|
});
|
|
2615
2966
|
if (!live(fresh) || fresh.parentId !== destination.page.id || fresh.key !== key) throw new KnowledgeImportRefusalError("occupied");
|
|
2616
|
-
const
|
|
2967
|
+
const holder = await importers.getNodeByPage(fresh.id);
|
|
2617
2968
|
renamed = fields.name !== fresh.name;
|
|
2618
|
-
if (
|
|
2969
|
+
if (holder?.bindingId === binding.id) {
|
|
2970
|
+
if (!holder.sourceId.startsWith("~path:")) throw new KnowledgeImportRefusalError("occupied");
|
|
2971
|
+
const childIds = [];
|
|
2972
|
+
let cursor;
|
|
2973
|
+
do {
|
|
2974
|
+
const out = await storage.listChildPages({
|
|
2975
|
+
parentId: fresh.id,
|
|
2976
|
+
read: "all",
|
|
2977
|
+
...cursor ? { cursor } : {}
|
|
2978
|
+
});
|
|
2979
|
+
childIds.push(...out.pages.map((child) => child.id));
|
|
2980
|
+
cursor = out.nextCursor;
|
|
2981
|
+
} while (cursor);
|
|
2982
|
+
const childNodes = importers.getNodesByPages ? await importers.getNodesByPages(childIds) : (await Promise.all(childIds.map((id) => importers.getNodeByPage(id)))).filter((n) => !!n);
|
|
2983
|
+
await importers.deleteNode(binding.id, holder.sourceId);
|
|
2984
|
+
for (const child of childNodes) if (child.bindingId === binding.id && child.parentSourceId === holder.sourceId) await importers.saveNode({
|
|
2985
|
+
...child,
|
|
2986
|
+
parentSourceId: item.sourceId
|
|
2987
|
+
});
|
|
2988
|
+
if (fresh.body) await keepBody(fresh.id, fresh.body);
|
|
2989
|
+
adopted = !!fresh.body;
|
|
2990
|
+
} else {
|
|
2991
|
+
await release(fresh.id);
|
|
2992
|
+
if (!holder) await keepBody(fresh.id, fresh.body ?? "");
|
|
2993
|
+
adopted = true;
|
|
2994
|
+
}
|
|
2619
2995
|
page = await storage.updatePage({
|
|
2620
2996
|
id: fresh.id,
|
|
2621
2997
|
expectedVersion: fresh.version,
|
|
@@ -2623,7 +2999,6 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2623
2999
|
provenance
|
|
2624
3000
|
});
|
|
2625
3001
|
change = "updated";
|
|
2626
|
-
adopted = true;
|
|
2627
3002
|
} else if (!existing) {
|
|
2628
3003
|
page = await storage.createPage({
|
|
2629
3004
|
parentId: destination.page.id,
|
|
@@ -2637,9 +3012,15 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2637
3012
|
const current = await owned(existing.pageId, item.sourceId);
|
|
2638
3013
|
page = current.page;
|
|
2639
3014
|
if (existing.stub && existing.adopted && !REMOVED_BODIES.has(page.body ?? "")) await keepBody(page.id, page.body ?? "");
|
|
2640
|
-
|
|
3015
|
+
const rekey = !!item.path && !current.outside && page.key !== key;
|
|
3016
|
+
if (!current.outside && !parentMerged && (page.parentId !== destination.page.id || rekey)) {
|
|
2641
3017
|
if (destination.keys.length > current.keys.length && sameKeys(destination.keys.slice(0, current.keys.length), current.keys)) throw new KnowledgeImportRefusalError("invalid");
|
|
2642
|
-
|
|
3018
|
+
if (item.path) {
|
|
3019
|
+
const absorbed = await absorbAt(item.sourceId, destination, key, page);
|
|
3020
|
+
page = absorbed.page;
|
|
3021
|
+
if (absorbed.kept) adopted = true;
|
|
3022
|
+
}
|
|
3023
|
+
({page, relinked} = await moveOwned(item.sourceId, page, destination, item.path ? key : void 0));
|
|
2643
3024
|
moved = true;
|
|
2644
3025
|
if (hasBody) {
|
|
2645
3026
|
rendered = await renderBody(item);
|
|
@@ -2676,7 +3057,7 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2676
3057
|
sourceId: item.sourceId,
|
|
2677
3058
|
pageId: page.id,
|
|
2678
3059
|
kind: item.kind ?? existing?.kind ?? null,
|
|
2679
|
-
parentSourceId
|
|
3060
|
+
parentSourceId,
|
|
2680
3061
|
aliases: item.aliases ?? existing?.aliases ?? [],
|
|
2681
3062
|
unresolvedLinks: rendered ? rendered.unresolved : existing?.unresolvedLinks ?? [],
|
|
2682
3063
|
links: rendered ? rendered.links : existing?.links ?? [],
|
|
@@ -2713,6 +3094,7 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2713
3094
|
for (const op of [...writes, ...removes]) {
|
|
2714
3095
|
const sourceId = op.op === "remove" ? op.sourceId : op.item.sourceId;
|
|
2715
3096
|
const embeds = [];
|
|
3097
|
+
madeFolders = [];
|
|
2716
3098
|
try {
|
|
2717
3099
|
await storage.transaction(async () => {
|
|
2718
3100
|
if (op.op === "remove") {
|
|
@@ -2790,6 +3172,21 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2790
3172
|
return;
|
|
2791
3173
|
}
|
|
2792
3174
|
const written = await write(op.item, op.op === "upsert");
|
|
3175
|
+
for (const folder of madeFolders) {
|
|
3176
|
+
result.applied = true;
|
|
3177
|
+
result.counts.created++;
|
|
3178
|
+
embeds.push({
|
|
3179
|
+
kind: "index",
|
|
3180
|
+
pageId: folder.page.id
|
|
3181
|
+
});
|
|
3182
|
+
result.changes.push({
|
|
3183
|
+
sourceId: folder.sourceId,
|
|
3184
|
+
pageId: folder.page.id,
|
|
3185
|
+
change: "created",
|
|
3186
|
+
title: folder.page.name,
|
|
3187
|
+
path: ref(folder.keys)
|
|
3188
|
+
});
|
|
3189
|
+
}
|
|
2793
3190
|
if (!written) {
|
|
2794
3191
|
result.counts.merged++;
|
|
2795
3192
|
return;
|
|
@@ -2873,6 +3270,11 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2873
3270
|
}
|
|
2874
3271
|
return keys;
|
|
2875
3272
|
};
|
|
3273
|
+
const chains = importChainPaths(rows.pages);
|
|
3274
|
+
const pageAt = (keys) => {
|
|
3275
|
+
const key = importPathKey(scope.id, keys);
|
|
3276
|
+
return rows.paths.has(key) ? rows.paths.get(key) : chains.get(key);
|
|
3277
|
+
};
|
|
2876
3278
|
const at = (sourceId, seen) => {
|
|
2877
3279
|
if (!sourceId) return null;
|
|
2878
3280
|
const node = rows.nodes.get(`${binding.id}\u0000${sourceId}`);
|
|
@@ -2888,35 +3290,79 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2888
3290
|
if (!op || seen.has(sourceId)) return null;
|
|
2889
3291
|
return {
|
|
2890
3292
|
id: null,
|
|
2891
|
-
keys: [...destinationOf(op, /* @__PURE__ */ new Set([...seen, sourceId])).keys,
|
|
3293
|
+
keys: [...destinationOf(op, /* @__PURE__ */ new Set([...seen, sourceId])).keys, leafOf(op)]
|
|
2892
3294
|
};
|
|
2893
3295
|
};
|
|
2894
|
-
const
|
|
2895
|
-
|
|
2896
|
-
|
|
3296
|
+
const leafOf = (op) => knowledgeImportKey(op.item.path?.at(-1) ?? op.item.sourceId);
|
|
3297
|
+
const destinationOf = (op, seen) => {
|
|
3298
|
+
if (op.item.path) {
|
|
3299
|
+
const keys = [...anchorPath, ...op.item.path.slice(0, -1).map(knowledgeImportKey)];
|
|
3300
|
+
return {
|
|
3301
|
+
id: op.item.path.length === 1 ? folder.id : pageAt(keys),
|
|
3302
|
+
keys
|
|
3303
|
+
};
|
|
3304
|
+
}
|
|
3305
|
+
return at(op.item.parent, seen) ?? at(op.item.fallbackParent, seen) ?? {
|
|
3306
|
+
id: folder.id,
|
|
3307
|
+
keys: anchorPath
|
|
3308
|
+
};
|
|
2897
3309
|
};
|
|
2898
3310
|
const out = {
|
|
2899
3311
|
paths: [],
|
|
2900
3312
|
positions: [],
|
|
2901
3313
|
notes: [],
|
|
3314
|
+
holders: [],
|
|
2902
3315
|
subtrees: [],
|
|
2903
3316
|
linkTargets: removed,
|
|
2904
|
-
bindings: removed.length > 0
|
|
3317
|
+
bindings: removed.length > 0,
|
|
3318
|
+
inPlace: removed.length === 0
|
|
2905
3319
|
};
|
|
2906
3320
|
const nodeAt = (sourceId) => rows.nodes.get(`${binding.id}\u0000${sourceId}`);
|
|
2907
3321
|
const left = /* @__PURE__ */ new Set();
|
|
2908
3322
|
for (const op of writeOps.values()) {
|
|
2909
3323
|
const destination = destinationOf(op, /* @__PURE__ */ new Set([op.item.sourceId]));
|
|
3324
|
+
const leaf = [...destination.keys, leafOf(op)];
|
|
3325
|
+
const page = rows.pages.get(nodeAt(op.item.sourceId)?.pageId ?? "");
|
|
3326
|
+
if (destination.id && live(page ?? null) && page.parentId === destination.id && (!op.item.path || page.key === leafOf(op))) {
|
|
3327
|
+
if (op.item.path && op.item.path.length > 1) out.holders.push(destination.id);
|
|
3328
|
+
continue;
|
|
3329
|
+
}
|
|
3330
|
+
out.inPlace = false;
|
|
2910
3331
|
out.paths.push({
|
|
2911
3332
|
scopeId: scope.id,
|
|
2912
|
-
path:
|
|
3333
|
+
path: leaf
|
|
2913
3334
|
});
|
|
2914
3335
|
if (destination.id) out.positions.push(destination.id);
|
|
2915
|
-
|
|
2916
|
-
if (live(page ?? null) && page.parentId !== destination.id) {
|
|
3336
|
+
if (destination.id !== void 0 && live(page ?? null) && (page.parentId !== destination.id || op.item.path && page.key !== leafOf(op))) {
|
|
2917
3337
|
out.subtrees.push(page.id);
|
|
2918
3338
|
if (page.parentId) left.add(page.parentId);
|
|
2919
3339
|
}
|
|
3340
|
+
if (!op.item.path) continue;
|
|
3341
|
+
out.positions.push(folder.id);
|
|
3342
|
+
for (let i = anchorPath.length + 1; i < leaf.length; i++) {
|
|
3343
|
+
out.paths.push({
|
|
3344
|
+
scopeId: scope.id,
|
|
3345
|
+
path: leaf.slice(0, i)
|
|
3346
|
+
});
|
|
3347
|
+
const prefix = pageAt(leaf.slice(0, i));
|
|
3348
|
+
if (prefix) out.positions.push(prefix);
|
|
3349
|
+
}
|
|
3350
|
+
const held = pageAt(leaf);
|
|
3351
|
+
if (held && held !== page?.id) {
|
|
3352
|
+
out.subtrees.push(held);
|
|
3353
|
+
out.notes.push(held);
|
|
3354
|
+
if (page) {
|
|
3355
|
+
out.notes.push(page.id);
|
|
3356
|
+
out.positions.push(page.id);
|
|
3357
|
+
const keys = keysOf(page);
|
|
3358
|
+
if (keys) {
|
|
3359
|
+
for (const child of rows.pages.values()) if (child?.parentId === held && live(child) && child.key !== void 0) out.paths.push({
|
|
3360
|
+
scopeId: scope.id,
|
|
3361
|
+
path: [...keys, child.key]
|
|
3362
|
+
});
|
|
3363
|
+
}
|
|
3364
|
+
}
|
|
3365
|
+
}
|
|
2920
3366
|
}
|
|
2921
3367
|
for (const id of out.positions) if (left.has(id)) out.subtrees.push(id);
|
|
2922
3368
|
for (const sourceId of removed) {
|
|
@@ -2949,6 +3395,7 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2949
3395
|
};
|
|
2950
3396
|
const missing = emptyImportOverlayMissing();
|
|
2951
3397
|
let locked = /* @__PURE__ */ new Set();
|
|
3398
|
+
let reread = false;
|
|
2952
3399
|
try {
|
|
2953
3400
|
return await real.storage.transaction(async () => {
|
|
2954
3401
|
for (let pass = 0; pass < BATCH_DECIDE_PASSES; pass++) {
|
|
@@ -2960,7 +3407,8 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2960
3407
|
pageIds: folder ? [folder.id] : [],
|
|
2961
3408
|
plan,
|
|
2962
3409
|
missing,
|
|
2963
|
-
locked
|
|
3410
|
+
locked,
|
|
3411
|
+
reread
|
|
2964
3412
|
});
|
|
2965
3413
|
if (!rows) throw new BatchFallback("lock-churn");
|
|
2966
3414
|
locked = rows.locked;
|
|
@@ -2980,6 +3428,10 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
2980
3428
|
}
|
|
2981
3429
|
continue;
|
|
2982
3430
|
}
|
|
3431
|
+
if (error instanceof KnowledgeImportRereadRequiredError) {
|
|
3432
|
+
reread = true;
|
|
3433
|
+
continue;
|
|
3434
|
+
}
|
|
2983
3435
|
if (error instanceof KnowledgeImportBatchUnsupportedError) throw new BatchFallback(error.call);
|
|
2984
3436
|
throw error;
|
|
2985
3437
|
} finally {
|
|
@@ -3722,6 +4174,7 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
3722
4174
|
/** Store time (epoch ms) at which a running run stops being live under `leaseMs`. */
|
|
3723
4175
|
const liveUntil = (run) => Math.min((run.heartbeatAt ?? run.startedAt).getTime() + (leaseMs ?? Infinity), run.deadlineAt?.getTime() ?? Infinity);
|
|
3724
4176
|
const listBindings = async () => typeof options.bindings === "function" ? await options.bindings() : options.bindings;
|
|
4177
|
+
const pathWarned = /* @__PURE__ */ new Set();
|
|
3725
4178
|
const storageAndImporters = async () => {
|
|
3726
4179
|
const storage = await writer.getStorage();
|
|
3727
4180
|
const importers = storage.importers;
|
|
@@ -3775,6 +4228,7 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
3775
4228
|
finish,
|
|
3776
4229
|
status: finish.outcome === "canceled" ? "canceled" : "failed"
|
|
3777
4230
|
});
|
|
4231
|
+
pathWarned.delete(run.id);
|
|
3778
4232
|
return true;
|
|
3779
4233
|
};
|
|
3780
4234
|
const reclaimStaleRuns = async (importers, bindingId) => {
|
|
@@ -3932,9 +4386,11 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
3932
4386
|
let embeds = [];
|
|
3933
4387
|
let settling = false;
|
|
3934
4388
|
let fallbackWarning;
|
|
4389
|
+
let pathsUnsupported = false;
|
|
3935
4390
|
try {
|
|
3936
4391
|
const write = (deadlineAt) => storage.transaction(async (tx) => {
|
|
3937
4392
|
fallbackWarning = void 0;
|
|
4393
|
+
pathsUnsupported = false;
|
|
3938
4394
|
const importers = tx.importers;
|
|
3939
4395
|
const guard = await importers.lockWriterGuard(peek.firstWriteAt ? "share" : "update");
|
|
3940
4396
|
const run = await importers.lockRun(flush.runId);
|
|
@@ -3980,6 +4436,7 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
3980
4436
|
} } : {}
|
|
3981
4437
|
});
|
|
3982
4438
|
if (applied.fallback) fallbackWarning = `Knowledge importer: flush ${flush.seq} of run ${run.id} saved op by op instead of batched (${applied.fallback})`;
|
|
4439
|
+
pathsUnsupported = !!applied.pathsUnsupported;
|
|
3983
4440
|
const settled = applied.settle;
|
|
3984
4441
|
const hostUpdates = {};
|
|
3985
4442
|
if (settled && (settled.cursor ?? "") !== (hostState[SETTLE_CURSOR_KEY] ?? "")) hostUpdates[SETTLE_CURSOR_KEY] = settled.cursor ?? "";
|
|
@@ -4029,6 +4486,10 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
4029
4486
|
deadlineAt = Math.min(budgetAt, error.cutoff - LEASE_CUTOFF_MARGIN_MS);
|
|
4030
4487
|
}
|
|
4031
4488
|
if (fallbackWarning) writer.warn(fallbackWarning);
|
|
4489
|
+
if (pathsUnsupported && !pathWarned.has(flush.runId)) {
|
|
4490
|
+
pathWarned.add(flush.runId);
|
|
4491
|
+
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`);
|
|
4492
|
+
}
|
|
4032
4493
|
await runEmbeds(storage, embeds);
|
|
4033
4494
|
return receipt;
|
|
4034
4495
|
} catch (error) {
|
|
@@ -4120,7 +4581,7 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
4120
4581
|
}
|
|
4121
4582
|
const { storage } = await storageAndImporters();
|
|
4122
4583
|
try {
|
|
4123
|
-
|
|
4584
|
+
const receipt = await storage.transaction(async (tx) => {
|
|
4124
4585
|
const importers = tx.importers;
|
|
4125
4586
|
const guard = await importers.lockWriterGuard("share");
|
|
4126
4587
|
const run = await importers.lockRun(request.runId);
|
|
@@ -4164,6 +4625,8 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
4164
4625
|
});
|
|
4165
4626
|
return runReceipt(finished);
|
|
4166
4627
|
});
|
|
4628
|
+
pathWarned.delete(request.runId);
|
|
4629
|
+
return receipt;
|
|
4167
4630
|
} catch (error) {
|
|
4168
4631
|
throw hostError(error);
|
|
4169
4632
|
}
|
|
@@ -5541,7 +6004,8 @@ var Knowledge = class extends require_base.MastraBase {
|
|
|
5541
6004
|
warn: (message) => this.logger.warn(message),
|
|
5542
6005
|
maxTokens: this.#tools.maxTokens,
|
|
5543
6006
|
...principals ? { principals } : {},
|
|
5544
|
-
...options?.author ? { author: options.author } : {}
|
|
6007
|
+
...options?.author ? { author: options.author } : {},
|
|
6008
|
+
...options?.requireExpectedVersion ? { requireExpectedVersion: true } : {}
|
|
5545
6009
|
}, this.#groups(options), (context) => context?.requestContext?.delete?.(require_run_registry.PINNED_READ_MEMO_KEY));
|
|
5546
6010
|
}
|
|
5547
6011
|
/**
|