@mastra/core 1.87.0-alpha.9 → 1.88.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_types/{@internal_ai-sdk-v4@0.0.99 → @internal_ai-sdk-v4@0.0.100}/dist/index.d.ts +1 -1
- package/dist/_types/{@internal_ai-sdk-v5@0.0.99 → @internal_ai-sdk-v5@0.0.100}/dist/index.d.ts +1 -1
- package/dist/_types/{@internal_ai-v6@0.0.99 → @internal_ai-v6@0.0.100}/dist/index.d.ts +1 -1
- package/dist/_types/{@internal_ai-v7@0.0.99 → @internal_ai-v7@0.0.100}/dist/index.d.ts +1 -1
- package/dist/_types/@internal_core@0.1.4/dist/knowledge-compat/index.d.ts +79 -3
- package/dist/_types/{@internal_voice@0.0.48/dist/_types/@internal_ai-sdk-v5@0.0.99 → @internal_voice@0.0.49/dist/_types/@internal_ai-sdk-v5@0.0.100}/dist/index.d.ts +1 -1
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/voice/aisdk/speech.d.ts +1 -1
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/voice/aisdk/transcription.d.ts +1 -1
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/voice/composite-voice.d.ts +1 -1
- package/dist/a2a/index.cjs +1 -1
- package/dist/a2a/index.js +1 -1
- package/dist/agent/active-run-signal-queues.d.ts +49 -0
- package/dist/agent/agent-legacy.d.ts +1 -1
- package/dist/agent/agent.d.ts +30 -8
- package/dist/agent/agent.types.d.ts +2 -1
- package/dist/agent/durable/abort-transport.d.ts +1 -1
- package/dist/agent/durable/create-evented-agent.d.ts +2 -1
- package/dist/agent/durable/durable-agent.d.ts +4 -3
- package/dist/agent/durable/execution-engine.d.ts +14 -0
- package/dist/agent/durable/index.cjs +88 -87
- package/dist/agent/durable/index.js +4 -3
- package/dist/agent/durable/preparation.d.ts +17 -0
- package/dist/agent/durable/run-registry.d.ts +56 -25
- package/dist/agent/durable/segment-spans.d.ts +7 -0
- package/dist/agent/durable/stored-signal-drain.d.ts +100 -0
- package/dist/agent/durable/stream-adapter.d.ts +1 -1
- package/dist/agent/durable/types.d.ts +51 -2
- package/dist/agent/durable/utils/resolve-runtime.d.ts +16 -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 +7 -1
- 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 +17 -17
- package/dist/agent/index.d.ts +1 -0
- package/dist/agent/index.js +4 -4
- package/dist/agent/message-list/adapters/AIV4Adapter.d.ts +1 -1
- package/dist/agent/message-list/adapters/types.d.ts +1 -1
- package/dist/agent/message-list/cache/CacheKeyGenerator.d.ts +1 -1
- package/dist/agent/message-list/conversion/output-converter.d.ts +1 -1
- package/dist/agent/message-list/conversion/to-prompt.d.ts +1 -1
- package/dist/agent/message-list/conversion/utils.d.ts +1 -1
- package/dist/agent/message-list/detection/TypeDetector.d.ts +1 -1
- package/dist/agent/message-list/index.cjs +1 -1
- package/dist/agent/message-list/index.js +1 -1
- package/dist/agent/message-list/message-list.d.ts +2 -2
- package/dist/agent/message-list/prompt/attachments-to-parts.d.ts +1 -1
- package/dist/agent/message-list/prompt/convert-file.d.ts +1 -1
- package/dist/agent/message-list/prompt/data-content.d.ts +1 -1
- package/dist/agent/message-list/state/MessageStateManager.d.ts +6 -1
- package/dist/agent/message-list/state/types.d.ts +2 -2
- package/dist/agent/message-list/types.d.ts +9 -9
- package/dist/agent/message-list/utils/convert-messages.d.ts +3 -3
- package/dist/agent/message-list/utils/provider-compat.d.ts +1 -1
- package/dist/agent/request-context-snapshot.d.ts +5 -0
- package/dist/agent/scopes.d.ts +8 -0
- package/dist/agent/signals.d.ts +8 -4
- 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 +70 -6
- package/dist/agent/tool-name.d.ts +21 -0
- package/dist/agent/types.d.ts +4 -3
- package/dist/agent/workflows/prepare-stream/run-scope-keys.d.ts +1 -1
- package/dist/agent-builder/ee/index.cjs +1 -1
- package/dist/agent-builder/ee/index.js +1 -1
- package/dist/agent-controller/agent-controller.d.ts +8 -1
- package/dist/agent-controller/index.cjs +3 -3
- package/dist/agent-controller/index.js +3 -3
- package/dist/agent-controller/session.d.ts +38 -1
- package/dist/agent-controller/types.d.ts +6 -0
- package/dist/{agent-controller-fazk0U_b.js → agent-controller-CQDCmsFD.js} +126 -220
- package/dist/{agent-controller-ZCQy7cOG.cjs → agent-controller-NQKYmY0W.cjs} +150 -244
- package/dist/{agent-skills-resolver-BMoCDoaK.cjs → agent-skills-resolver-2d8k7ioj.cjs} +134 -109
- package/dist/{agent-skills-resolver-CUEIMDbx.js → agent-skills-resolver-D2HktP6Y.js} +134 -109
- package/dist/auth/defaults/index.d.ts +2 -2
- package/dist/auth/defaults/session/cookie.d.ts +2 -2
- package/dist/auth/defaults/session/index.d.ts +2 -2
- package/dist/auth/defaults/session/memory.d.ts +2 -2
- package/dist/auth/ee/capabilities.d.ts +1 -1
- package/dist/auth/ee/defaults/index.d.ts +1 -1
- package/dist/auth/ee/defaults/rbac/index.d.ts +1 -1
- package/dist/auth/ee/defaults/rbac/static.d.ts +1 -1
- package/dist/auth/ee/defaults/roles.d.ts +1 -1
- package/dist/auth/ee/fga-check.d.ts +1 -1
- package/dist/auth/ee/index.d.ts +1 -1
- package/dist/auth/ee/interfaces/acl.d.ts +1 -1
- package/dist/auth/ee/interfaces/fga.d.ts +1 -1
- package/dist/auth/ee/interfaces/index.d.ts +1 -1
- package/dist/auth/ee/interfaces/permissions.generated.d.ts +1 -1
- package/dist/auth/ee/interfaces/rbac.d.ts +1 -1
- package/dist/auth/ee/interfaces/user.d.ts +1 -1
- package/dist/auth/ee/license.d.ts +1 -1
- package/dist/auth/index.d.ts +2 -2
- package/dist/auth/interfaces/credentials.d.ts +1 -1
- package/dist/auth/interfaces/index.d.ts +2 -2
- package/dist/auth/interfaces/session.d.ts +1 -1
- package/dist/auth/interfaces/sso.d.ts +1 -1
- package/dist/auth/interfaces/user.d.ts +1 -1
- 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-DlLB_pJR.js → background-tasks-B7UygDdO.js} +239 -28
- package/dist/{background-tasks-B63welNM.cjs → background-tasks-CeARf1DK.cjs} +262 -27
- package/dist/browser/index.cjs +17 -8
- package/dist/browser/index.js +17 -8
- package/dist/browser/processor.d.ts +1 -0
- package/dist/{builder-D82iR2oQ.js → builder-CpAEmMdR.js} +2 -2
- package/dist/{builder-DCaL4xmU.cjs → builder-Dmf04g9P.cjs} +3 -3
- package/dist/bundler/index.d.ts +2 -2
- package/dist/capabilities/302ai.json +197 -197
- package/dist/capabilities/abacus.json +2 -96
- package/dist/capabilities/abliteratedllm.json +37 -37
- package/dist/capabilities/abliteration-ai.json +12 -12
- package/dist/capabilities/above.json +17 -17
- package/dist/capabilities/adaption.json +12 -12
- package/dist/capabilities/adzuki.json +20 -20
- package/dist/capabilities/agentrouter.json +8 -8
- package/dist/capabilities/agnes.json +4 -4
- package/dist/capabilities/ai-router.json +7 -7
- package/dist/capabilities/aiand.json +23 -31
- package/dist/capabilities/aigrow.json +14 -14
- package/dist/capabilities/aimlapi.json +143 -145
- package/dist/capabilities/aipg.json +2 -2
- package/dist/capabilities/aixy.json +11 -11
- package/dist/capabilities/aki-io.json +12 -12
- package/dist/capabilities/alibaba-cn.json +119 -128
- package/dist/capabilities/alibaba-coding-plan-cn.json +5 -10
- package/dist/capabilities/alibaba-coding-plan.json +5 -10
- package/dist/capabilities/alibaba-token-plan-cn.json +53 -49
- package/dist/capabilities/alibaba-token-plan.json +53 -49
- package/dist/capabilities/alibaba.json +101 -70
- package/dist/capabilities/ambient.json +10 -28
- package/dist/capabilities/amd-tokenlab.json +41 -0
- package/dist/capabilities/amd.json +11 -11
- package/dist/capabilities/anthropic.json +38 -62
- package/dist/capabilities/anyapi.json +18 -18
- package/dist/capabilities/arcee.json +7 -7
- package/dist/capabilities/augure.json +6 -6
- package/dist/capabilities/auriko.json +17 -17
- package/dist/capabilities/bailing.json +5 -5
- package/dist/capabilities/baseten.json +44 -35
- package/dist/capabilities/bee.json +5 -5
- package/dist/capabilities/berget.json +2 -35
- package/dist/capabilities/bothub.json +14 -14
- package/dist/capabilities/boundless.json +32 -32
- package/dist/capabilities/bumo.json +42 -42
- package/dist/capabilities/byteplus.json +30 -30
- package/dist/capabilities/cheapaimodel.json +8 -8
- package/dist/capabilities/cheapest-token.json +30 -30
- package/dist/capabilities/chutes.json +88 -7
- package/dist/capabilities/cline-pass.json +29 -42
- package/dist/capabilities/cloudcode.json +6 -6
- package/dist/capabilities/cloudflare-workers-ai.json +13 -13
- package/dist/capabilities/commandcode.json +141 -156
- package/dist/capabilities/concentrate.json +288 -271
- package/dist/capabilities/cortecs.json +105 -105
- package/dist/capabilities/crossmodel.json +177 -177
- package/dist/capabilities/crusoe.json +12 -12
- package/dist/capabilities/daoxe.json +9 -9
- package/dist/capabilities/databricks.json +136 -128
- package/dist/capabilities/deepinfra.json +105 -95
- package/dist/capabilities/deepseek.json +3 -3
- package/dist/capabilities/digitalocean.json +113 -114
- package/dist/capabilities/dinference.json +1 -2
- package/dist/capabilities/dothoosh.json +28 -28
- package/dist/capabilities/doubleword.json +26 -26
- package/dist/capabilities/edenai.json +298 -280
- package/dist/capabilities/empiriolabs.json +180 -171
- package/dist/capabilities/engy.json +23 -17
- package/dist/capabilities/entrim.json +6 -6
- package/dist/capabilities/evroc.json +12 -12
- package/dist/capabilities/ezkielyna.json +7 -7
- package/dist/capabilities/fastrouter.json +81 -85
- package/dist/capabilities/fireworks-ai.json +100 -100
- package/dist/capabilities/fortytwo.json +4 -4
- package/dist/capabilities/freemodel.json +7 -51
- package/dist/capabilities/friendli.json +26 -5
- package/dist/capabilities/frogbot.json +92 -100
- package/dist/capabilities/gisoo.json +19 -19
- package/dist/capabilities/gmicloud.json +11 -11
- package/dist/capabilities/google.json +43 -43
- package/dist/capabilities/graphn.json +14 -14
- package/dist/capabilities/greenpt.json +37 -37
- package/dist/capabilities/groq.json +7 -20
- package/dist/capabilities/helicone.json +80 -82
- package/dist/capabilities/hetzner.json +4 -4
- package/dist/capabilities/hostinger-router.json +9 -16
- package/dist/capabilities/hpc-ai.json +9 -25
- package/dist/capabilities/huawei-maas.json +12 -12
- package/dist/capabilities/hubris.json +29 -29
- package/dist/capabilities/huggingface.json +94 -85
- package/dist/capabilities/humain.json +2 -2
- package/dist/capabilities/hyper.json +22 -22
- package/dist/capabilities/impossibl.json +121 -168
- package/dist/capabilities/inception.json +3 -3
- package/dist/capabilities/inceptron.json +8 -8
- package/dist/capabilities/inco.json +5 -22
- package/dist/capabilities/infer.json +11 -11
- package/dist/capabilities/inferall.json +3 -19
- package/dist/capabilities/inference-coop.json +15 -15
- package/dist/capabilities/inference.json +2 -11
- package/dist/capabilities/inferenceapis.json +21 -21
- package/dist/capabilities/inferris.json +4 -4
- package/dist/capabilities/infersia.json +7 -7
- package/dist/capabilities/inferx.json +2 -2
- package/dist/capabilities/infomaniak.json +3 -3
- package/dist/capabilities/io-net.json +3 -13
- package/dist/capabilities/iteracompute.json +38 -76
- package/dist/capabilities/jalapeno.json +11 -11
- package/dist/capabilities/jiekou.json +19 -167
- package/dist/capabilities/joingonka.json +4 -4
- package/dist/capabilities/jzstoken.json +47 -47
- package/dist/capabilities/keln.json +22 -22
- package/dist/capabilities/kenari.json +129 -120
- package/dist/capabilities/kilo.json +629 -653
- package/dist/capabilities/kimchi.json +90 -0
- package/dist/capabilities/kimi-code-plan-cn.json +9 -9
- package/dist/capabilities/kimi-code-plan-global.json +9 -9
- package/dist/capabilities/kitani.json +6 -6
- package/dist/capabilities/klavo.json +24 -24
- package/dist/capabilities/korouter.json +34 -34
- package/dist/capabilities/kunavo.json +4 -4
- package/dist/capabilities/liquid.json +11 -11
- package/dist/capabilities/lithosai.json +2 -2
- package/dist/capabilities/llmgateway-providers.json +934 -943
- package/dist/capabilities/llmgateway.json +347 -324
- package/dist/capabilities/llmtr.json +22 -60
- package/dist/capabilities/longcat.json +2 -2
- package/dist/capabilities/lowrouter.json +51 -51
- package/dist/capabilities/lyceum.json +16 -16
- package/dist/capabilities/meganova.json +0 -1
- package/dist/capabilities/melious.json +12 -12
- package/dist/capabilities/merge-gateway.json +303 -281
- package/dist/capabilities/meta.json +11 -11
- package/dist/capabilities/minimax-cn-coding-plan.json +6 -6
- package/dist/capabilities/minimax-coding-plan.json +6 -6
- package/dist/capabilities/mistral.json +11 -27
- package/dist/capabilities/mixlayer.json +5 -5
- package/dist/capabilities/moark.json +0 -2
- package/dist/capabilities/modal.json +12 -12
- package/dist/capabilities/model-oracle-ai.json +18 -26
- package/dist/capabilities/modelis.json +17 -17
- package/dist/capabilities/modular.json +12 -12
- package/dist/capabilities/moneo.json +3 -34
- package/dist/capabilities/moonshotai-cn.json +7 -7
- package/dist/capabilities/moonshotai.json +7 -7
- package/dist/capabilities/morph.json +22 -14
- 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 +580 -596
- package/dist/capabilities/nearai.json +81 -81
- package/dist/capabilities/nebius.json +41 -34
- package/dist/capabilities/neon.json +135 -135
- package/dist/capabilities/neuralwatt.json +40 -40
- package/dist/capabilities/nokeep.json +2 -2
- package/dist/capabilities/novita-ai.json +106 -220
- package/dist/capabilities/nvidia.json +22 -80
- package/dist/capabilities/oathbreaker.json +5 -5
- package/dist/capabilities/obscurify.json +24 -24
- package/dist/capabilities/oci.json +9 -9
- package/dist/capabilities/ofox.json +205 -569
- package/dist/capabilities/ollama-cloud.json +57 -57
- package/dist/capabilities/openai.json +57 -60
- package/dist/capabilities/opencode-go.json +103 -95
- package/dist/capabilities/openreason.json +5 -5
- package/dist/capabilities/openrouter.json +551 -577
- package/dist/capabilities/opper.json +26 -31
- package/dist/capabilities/orcarouter.json +414 -199
- package/dist/capabilities/outerlabs.json +33 -33
- package/dist/capabilities/ovhcloud.json +16 -17
- package/dist/capabilities/pareto.json +2 -7
- package/dist/capabilities/perplexity-agent.json +101 -66
- package/dist/capabilities/perplexity.json +2 -2
- package/dist/capabilities/phala.json +34 -34
- package/dist/capabilities/pioneer.json +5 -122
- package/dist/capabilities/poe.json +140 -140
- package/dist/capabilities/poolside.json +3 -3
- package/dist/capabilities/powerspring.json +9 -9
- package/dist/capabilities/primalabs.json +7 -7
- package/dist/capabilities/prime.json +131 -115
- package/dist/capabilities/privatemode-ai.json +9 -37
- package/dist/capabilities/proxystacks.json +7 -7
- package/dist/capabilities/qihang-ai.json +3 -15
- package/dist/capabilities/qiniu-ai.json +14 -88
- package/dist/capabilities/refuseless.json +4 -11
- package/dist/capabilities/regolo-ai.json +6 -10
- package/dist/capabilities/requesty.json +249 -208
- package/dist/capabilities/routing-run.json +3 -40
- package/dist/capabilities/ruapi.json +17 -17
- package/dist/capabilities/runcrate.json +13 -13
- package/dist/capabilities/runinfra.json +15 -15
- package/dist/capabilities/sakana.json +6 -6
- package/dist/capabilities/sambanova.json +5 -5
- package/dist/capabilities/sandbase.json +23 -23
- package/dist/capabilities/sarvam.json +17 -8
- package/dist/capabilities/scaleway.json +14 -14
- package/dist/capabilities/scnet-token-plan.json +10 -10
- package/dist/capabilities/scx-ai.json +12 -28
- package/dist/capabilities/sensenova.json +9 -9
- package/dist/capabilities/siliconflow-cn.json +63 -97
- package/dist/capabilities/siliconflow.json +63 -63
- package/dist/capabilities/snowflake-cortex.json +28 -28
- package/dist/capabilities/sokkan.json +8 -20
- package/dist/capabilities/sparrowcodes.json +19 -19
- package/dist/capabilities/stackit.json +1 -2
- package/dist/capabilities/standardcompute.json +77 -113
- package/dist/capabilities/steadyrouter.json +45 -45
- package/dist/capabilities/stepfun-ai-step-plan.json +14 -8
- package/dist/capabilities/stepfun-ai.json +21 -7
- package/dist/capabilities/stepfun-step-plan.json +14 -7
- package/dist/capabilities/stepfun.json +21 -7
- package/dist/capabilities/stepping-stone.json +12 -12
- package/dist/capabilities/synthetic.json +9 -18
- package/dist/capabilities/synthorai.json +22 -22
- package/dist/capabilities/teamorouter.json +21 -21
- package/dist/capabilities/teapot-router.json +10 -10
- package/dist/capabilities/tencent-token-plan-intl.json +20 -20
- package/dist/capabilities/tencent-token-plan.json +45 -45
- package/dist/capabilities/tencent-tokenhub.json +47 -47
- package/dist/capabilities/tensorx.json +50 -50
- package/dist/capabilities/tenstorrent.json +6 -6
- package/dist/capabilities/the-grid-ai.json +28 -28
- package/dist/capabilities/thinkingmachines.json +61 -61
- package/dist/capabilities/tinfoil.json +12 -12
- package/dist/capabilities/toapis.json +3 -3
- package/dist/capabilities/togetherai.json +50 -58
- package/dist/capabilities/tokengo.json +21 -21
- package/dist/capabilities/tokenharbor.json +738 -0
- package/dist/capabilities/tokenify.json +2 -2
- package/dist/capabilities/trustedrouter.json +6 -6
- package/dist/capabilities/trustedtokens.json +12 -12
- package/dist/capabilities/umans-ai-coding-plan.json +14 -14
- package/dist/capabilities/umans-ai.json +11 -11
- package/dist/capabilities/uncensuredai.json +4 -4
- package/dist/capabilities/unorouter.json +1 -22
- package/dist/capabilities/unrestricted.json +6 -22
- package/dist/capabilities/uplinkswitch.json +20 -20
- package/dist/capabilities/upstage.json +3 -15
- package/dist/capabilities/vancine.json +21 -21
- package/dist/capabilities/vercel.json +628 -593
- package/dist/capabilities/verda.json +8 -1
- package/dist/capabilities/vivgrid.json +55 -135
- package/dist/capabilities/volcengine-coding-plan.json +25 -25
- package/dist/capabilities/volcengine.json +24 -24
- package/dist/capabilities/vultr.json +12 -65
- package/dist/capabilities/wafer.ai.json +17 -17
- package/dist/capabilities/wallaby.json +2 -2
- package/dist/capabilities/wally.json +9 -9
- package/dist/capabilities/wandb.json +21 -21
- package/dist/capabilities/watt.json +23 -23
- package/dist/capabilities/xai.json +6 -6
- package/dist/capabilities/xpersona.json +11 -11
- package/dist/capabilities/xxapi.json +25 -25
- package/dist/capabilities/zai-coding-plan.json +15 -15
- package/dist/capabilities/zai.json +37 -28
- package/dist/capabilities/zenifra.json +26 -26
- package/dist/capabilities/zenmux.json +151 -194
- package/dist/capabilities/zerogpu.json +12 -12
- package/dist/capabilities/zhipuai-coding-plan.json +5 -16
- package/dist/capabilities/zhipuai.json +44 -28
- package/dist/capabilities/zro.json +7 -7
- package/dist/channels/index.cjs +24 -24
- package/dist/channels/index.js +2 -2
- package/dist/channels/reply-tool.d.ts +5 -1
- package/dist/{channels-Bs8wDPDl.js → channels-BQ--aLCA.js} +2 -2
- package/dist/{channels-BXZbY7TL.cjs → channels-CTCBsS5M.cjs} +6 -6
- package/dist/coding-agent/index.cjs +7 -7
- package/dist/coding-agent/index.js +4 -4
- package/dist/{constants-Bou0hEgY.cjs → constants-B2FVV_2e.cjs} +9 -1
- package/dist/{constants-CFWgIaqA.js → constants-Dro9fuhk.js} +9 -1
- package/dist/datasets/index.cjs +9 -9
- package/dist/datasets/index.js +2 -2
- package/dist/deployer/index.d.ts +2 -2
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +1253 -1213
- package/dist/docs/references/docs-agents-code-mode.md +2 -2
- package/dist/docs/references/docs-agents-human-in-the-loop.md +3 -3
- package/dist/docs/references/docs-agents-networks.md +1 -1
- package/dist/docs/references/docs-agents-overview.md +15 -6
- package/dist/docs/references/docs-agents-processors.md +9 -9
- package/dist/docs/references/docs-agents-resumable-streams.md +5 -5
- package/dist/docs/references/docs-agents-structured-output.md +6 -6
- package/dist/docs/references/docs-agents-tools.md +11 -11
- package/dist/docs/references/docs-browser.md +1 -1
- package/dist/docs/references/docs-channels.md +13 -7
- 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 +11 -5
- 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 +10 -7
- package/dist/docs/references/docs-harness-durable-agents.md +22 -19
- 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-knowledge-search.md +1 -1
- package/dist/docs/references/docs-memory-memory-processors.md +8 -8
- package/dist/docs/references/docs-memory-message-history.md +5 -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 +91 -0
- package/dist/docs/references/docs-server-pubsub.md +45 -16
- 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 +12 -3
- package/dist/docs/references/docs-signals-sending-signals.md +20 -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 +8 -5
- 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/docs-workflows-overview.md +5 -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 +54 -7
- package/dist/docs/references/reference-agents-agent.md +43 -15
- package/dist/docs/references/reference-agents-channels.md +11 -11
- package/dist/docs/references/reference-agents-createSkill.md +20 -1
- package/dist/docs/references/reference-agents-durable-agent.md +5 -5
- 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 +75 -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-knowledge-knowledge-tools.md +1 -2
- package/dist/docs/references/reference-knowledge-limits.md +16 -16
- 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 +7 -3
- package/dist/docs/references/reference-observability-metrics-metrics-context.md +63 -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-pubsub-base.md +2 -2
- package/dist/docs/references/reference-pubsub-caching-pubsub.md +1 -1
- package/dist/docs/references/reference-pubsub-google-cloud-pubsub.md +13 -7
- package/dist/docs/references/reference-pubsub-lease-provider.md +4 -0
- package/dist/docs/references/reference-pubsub-redis-streams.md +21 -14
- package/dist/docs/references/reference-pubsub-valkey-streams.md +27 -9
- 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 +137 -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-templates-overview.md +31 -1
- 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-run-methods-restart.md +2 -0
- 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 +2 -0
- package/dist/evals/index.cjs +13 -13
- package/dist/evals/index.js +2 -2
- package/dist/evals/run/index.d.ts +1 -1
- package/dist/evals/scoreTraces/index.cjs +4 -4
- package/dist/evals/scoreTraces/index.js +2 -2
- package/dist/evals/types.d.ts +1 -1
- package/dist/events/caching-pubsub.d.ts +3 -11
- package/dist/events/index.cjs +1 -1
- package/dist/events/index.js +1 -1
- package/dist/events/pubsub.d.ts +3 -4
- package/dist/{run-registry-DX_EyboB.cjs → execution-fence-C8Q0wWkG.cjs} +12890 -8734
- package/dist/{run-registry-DKiudqVU.js → execution-fence-DGFyUV5h.js} +12380 -8260
- package/dist/harness/index.cjs +3 -3
- package/dist/harness/index.js +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/integration/index.cjs +1 -1
- package/dist/integration/index.js +1 -1
- package/dist/knowledge/importers/overlay.d.ts +170 -0
- package/dist/knowledge/importers/sink.d.ts +17 -1
- package/dist/knowledge/importers/types.d.ts +14 -0
- package/dist/knowledge/index.cjs +2047 -276
- package/dist/knowledge/index.d.ts +6 -0
- package/dist/knowledge/index.js +1929 -158
- package/dist/knowledge/links.d.ts +27 -0
- package/dist/knowledge/page-tools.d.ts +2 -0
- package/dist/llm/index.cjs +3 -3
- package/dist/llm/index.d.ts +2 -2
- package/dist/llm/index.js +3 -3
- package/dist/llm/model/aisdk/v4/model.d.ts +9 -9
- package/dist/llm/model/base.types.d.ts +2 -2
- package/dist/llm/model/embedding-router.d.ts +1 -1
- package/dist/llm/model/gateways/opencode-session-header.d.ts +28 -0
- package/dist/llm/model/mastra-gateway-provider-tools.d.ts +7 -0
- package/dist/llm/model/model-settings.d.ts +1 -1
- package/dist/llm/model/model.d.ts +1 -1
- package/dist/llm/model/model.loop.d.ts +1 -1
- package/dist/llm/model/model.loop.types.d.ts +1 -1
- package/dist/llm/model/provider-types.generated.d.ts +7162 -7416
- package/dist/llm/model/resolve-model.d.ts +1 -0
- package/dist/llm/model/shared.types.d.ts +2 -1
- package/dist/llm/reasoning/account-switch.d.ts +50 -0
- package/dist/llm/reasoning/anthropic-thinking.d.ts +5 -0
- package/dist/llm/reasoning/gemini-thinking.d.ts +24 -0
- package/dist/llm/reasoning/index.cjs +454 -0
- package/dist/llm/reasoning/index.d.ts +9 -0
- package/dist/llm/reasoning/index.js +422 -0
- package/dist/llm/reasoning/model-fallback.d.ts +75 -0
- package/dist/llm/reasoning/model-ids.d.ts +5 -0
- package/dist/llm/reasoning/thinking-provider-options.d.ts +10 -0
- package/dist/llm/reasoning/thinking-request.d.ts +14 -0
- package/dist/llm/reasoning/thinking.d.ts +37 -0
- package/dist/{llm-ypGNjEom.cjs → llm-RIAYOAtD.cjs} +34 -14
- package/dist/{llm-9xmy8HlF.js → llm-YNjDFSui.js} +34 -14
- package/dist/loop/index.cjs +15 -15
- package/dist/loop/index.js +2 -2
- package/dist/loop/loop-builder.d.ts +1 -1
- package/dist/loop/loop-runtime.d.ts +1 -1
- package/dist/loop/loop.d.ts +1 -1
- package/dist/loop/run-scope-keys.d.ts +1 -1
- package/dist/loop/server.cjs +1 -1
- package/dist/loop/server.js +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/loop/shared/transcript-step.d.ts +1 -1
- package/dist/loop/suspended-run-auto-resume.d.ts +15 -0
- package/dist/loop/types.d.ts +2 -2
- package/dist/loop/workflows/agentic-execution/background-task-check-step.d.ts +1 -1
- package/dist/loop/workflows/agentic-execution/build-messages-from-chunks.d.ts +1 -1
- package/dist/loop/workflows/agentic-execution/goal-step.d.ts +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +1 -1
- package/dist/loop/workflows/agentic-execution/is-task-complete-step.d.ts +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +1 -1
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +1 -1
- package/dist/loop/workflows/agentic-execution/tool-call-concurrency.d.ts +1 -1
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts +2 -2
- package/dist/loop/workflows/agentic-loop/index.d.ts +1 -1
- package/dist/loop/workflows/schema.d.ts +2 -2
- package/dist/loop/workflows/stream.d.ts +1 -1
- package/dist/{manager-B-QrBhhd.js → manager-DZhtdV6Q.js} +9 -7
- package/dist/{manager-CYXV5_vY.cjs → manager-Y-jYcS7T.cjs} +21 -19
- package/dist/mastra/index.cjs +1 -1
- package/dist/mastra/index.d.ts +67 -12
- package/dist/mastra/index.js +1 -1
- package/dist/{mastra-zszeli0N.cjs → mastra-B2-HBq1-.cjs} +211 -67
- package/dist/{mastra-DPSwJ5ae.js → mastra-BJ54VxOO.js} +171 -27
- package/dist/mastra-gateway-provider-tools-C-AjGZis.js +58 -0
- package/dist/mastra-gateway-provider-tools-WpH3Tmu4.cjs +81 -0
- package/dist/memory/index.cjs +25 -25
- package/dist/memory/index.js +3 -3
- package/dist/memory/memory.d.ts +1 -1
- package/dist/memory/mock.d.ts +2 -3
- package/dist/memory/om-events/index.cjs +189 -0
- package/dist/memory/om-events/index.d.ts +17 -0
- package/dist/memory/om-events/index.js +188 -0
- package/dist/memory/types.d.ts +2 -2
- package/dist/{message-list-vR3uLAHL.cjs → message-list-C0F2sDNC.cjs} +3 -2
- package/dist/{message-list-BGm1DCiG.js → message-list-RgFlLrxG.js} +3 -2
- package/dist/{model-UYJb8Zel.js → model-cS3d5rmF.js} +2 -2
- package/dist/{model-WLujr8OR.cjs → model-lzZPXaEV.cjs} +2 -2
- package/dist/{netlify-wZafLKoe.cjs → netlify-1lti1j4Z.cjs} +97 -3
- package/dist/{netlify-DTWAZGpA.js → netlify-ClBjc0Xg.js} +86 -4
- package/dist/notifications/index.cjs +18 -18
- package/dist/notifications/index.js +2 -2
- package/dist/observability/index.cjs +1 -1
- package/dist/observability/index.js +1 -1
- package/dist/{observability-D7RNOAPx.js → observability-DPDWibyH.js} +648 -648
- package/dist/{output-helpers-CVzhy1Y0.js → output-helpers-D-qplq22.js} +70 -74
- package/dist/{output-helpers-DgsH4aTb.cjs → output-helpers-D4O_oFne.cjs} +69 -73
- package/dist/processor-provider/index.cjs +10 -10
- package/dist/processor-provider/index.js +1 -1
- package/dist/processors/index.cjs +65 -65
- package/dist/processors/index.d.ts +2 -2
- package/dist/processors/index.js +2 -2
- package/dist/processors/runner.d.ts +1 -1
- package/dist/processors/step-schema.d.ts +1 -1
- package/dist/{provider-registry-BvpUdOiq.cjs → provider-registry-C6jd3Uxi.cjs} +20494 -21358
- package/dist/{provider-registry-COT79RLh.js → provider-registry-C_XQJvu2.js} +20493 -21357
- package/dist/provider-registry.json +22407 -23248
- package/dist/{registry-generator-Dn1Tuacv.cjs → registry-generator-BYdAlox6.cjs} +1 -1
- package/dist/{registry-generator-BKjTPD6B.js → registry-generator-DBrTbThj.js} +1 -1
- package/dist/{rehydrate-BK1v65H7.js → rehydrate-4xHubfOY.js} +2 -2
- package/dist/{rehydrate-C0xrJUBu.cjs → rehydrate-BtwY0ima.cjs} +14 -14
- package/dist/relevance/index.cjs +3 -3
- package/dist/relevance/index.js +2 -2
- package/dist/{scheduler-B-VZUvv_.js → scheduler-D1qdie5k.js} +75 -23
- package/dist/{scheduler-D00X03jQ.cjs → scheduler-DE5lcHJA.cjs} +86 -22
- package/dist/server/auth.d.ts +3 -3
- package/dist/server/composite-auth.d.ts +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/simple-auth.d.ts +1 -1
- package/dist/server/types.d.ts +64 -1
- package/dist/{signal-provider-BslnAjWG.js → signal-provider-B_mfW-J4.js} +1 -1
- package/dist/{signal-provider-BFAvh_AJ.cjs → signal-provider-D9gbevHN.cjs} +1 -1
- package/dist/signals/index.cjs +4 -3
- package/dist/signals/index.d.ts +1 -0
- package/dist/signals/index.js +4 -4
- package/dist/signals/time-signal-provider.d.ts +70 -0
- package/dist/signals-BwDXGqxc.cjs +358 -0
- package/dist/signals-TznxWfM3.js +347 -0
- package/dist/skills/create-skill.d.ts +3 -0
- package/dist/skills/index.cjs +1 -1
- package/dist/skills/index.js +1 -1
- package/dist/skills/inline-skill-source.d.ts +5 -1
- package/dist/skills/types.d.ts +16 -1
- package/dist/{source-fNa6u1kH.js → source-B3He4_mz.js} +7 -0
- package/dist/{source-BVOi8Xhp.cjs → source-C_nWbqI0.cjs} +7 -0
- package/dist/{state-processor-B9kxpM53.js → state-processor-B_KsS82m.js} +1 -1
- package/dist/{state-processor-kRNZ38Nf.cjs → state-processor-DaSmhVUX.cjs} +1 -1
- 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 +140 -5
- package/dist/storage/domains/knowledge/importers-inmemory.d.ts +9 -0
- package/dist/storage/domains/knowledge/importers.d.ts +31 -0
- package/dist/storage/domains/knowledge/inmemory.d.ts +11 -0
- package/dist/storage/domains/knowledge/pages-inmemory.d.ts +50 -12
- package/dist/storage/domains/knowledge/pages.d.ts +90 -1
- package/dist/storage/domains/memory/base.d.ts +122 -0
- package/dist/storage/domains/memory/index.d.ts +1 -0
- package/dist/storage/domains/memory/inmemory.d.ts +39 -0
- package/dist/storage/domains/memory/queue-thread.d.ts +42 -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 +32 -5
- package/dist/storage/domains/workflows/inmemory.d.ts +7 -6
- package/dist/storage/domains/workflows/journal.d.ts +16 -1
- package/dist/storage/index.cjs +192 -186
- package/dist/storage/index.js +6 -6
- package/dist/storage/types.d.ts +6 -0
- package/dist/storage/workflow-snapshot.d.ts +4 -0
- package/dist/storage/workflow-step-guard.d.ts +5 -0
- package/dist/stream/RunOutput.d.ts +1 -1
- package/dist/stream/aisdk/v4/input.d.ts +1 -1
- package/dist/stream/aisdk/v5/compat/content.d.ts +1 -1
- package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts +1 -1
- package/dist/stream/aisdk/v5/compat/ui-message.d.ts +1 -1
- package/dist/stream/aisdk/v5/compat/validation.d.ts +1 -1
- package/dist/stream/aisdk/v5/execute.d.ts +1 -1
- package/dist/stream/aisdk/v5/input.d.ts +1 -1
- package/dist/stream/aisdk/v5/output-helpers.d.ts +7 -7
- package/dist/stream/aisdk/v5/transform.d.ts +1 -1
- package/dist/stream/base/output.d.ts +12 -4
- package/dist/stream/base/schema.d.ts +1 -1
- package/dist/stream/index.cjs +2 -2
- package/dist/stream/index.js +2 -2
- package/dist/stream/types.d.ts +2 -2
- package/dist/{stream-BmtBm_-L.cjs → stream-DqKDB3nL.cjs} +144 -10
- package/dist/{stream-B4LzC6Sz.js → stream-H_wVxqdK.js} +103 -11
- package/dist/telemetry/index.cjs +1 -1
- package/dist/telemetry/index.js +1 -1
- package/dist/test-utils/llm-mock.cjs +1 -1
- package/dist/test-utils/llm-mock.d.ts +3 -3
- package/dist/test-utils/llm-mock.js +1 -1
- package/dist/{tool-Z3bykc1m.js → tool-DIFduuTw.js} +2 -5
- package/dist/{tool-CYlT2UA-.cjs → tool-Dn9WSDVn.cjs} +2 -5
- package/dist/tool-loop-agent/index.cjs +1 -1
- package/dist/tool-loop-agent/index.js +1 -1
- package/dist/tool-loop-agent/utils.d.ts +1 -1
- package/dist/{tool-loop-agent-BIbw3quM.cjs → tool-loop-agent-D4gSdYuN.cjs} +5 -5
- package/dist/{tool-loop-agent-CR2AgmkF.js → tool-loop-agent-DvZcOxWe.js} +4 -4
- package/dist/{toolchecks-DrsZdc3S.js → toolchecks-CRAfUe9H.js} +1 -1
- package/dist/{toolchecks-MFU48cit.cjs → toolchecks-DbBsQGHW.cjs} +1 -1
- package/dist/tools/builtin/web-search.d.ts +9 -1
- package/dist/tools/index.cjs +5 -5
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.js +5 -5
- package/dist/tools/is-vercel-tool.cjs +1 -1
- package/dist/tools/is-vercel-tool.js +1 -1
- package/dist/tools/provider-tool-utils.d.ts +1 -1
- package/dist/tools/tool-builder/builder.d.ts +1 -1
- package/dist/tools/tool-title.d.ts +1 -1
- package/dist/tools/tool.d.ts +2 -4
- package/dist/tools/types.d.ts +2 -1
- package/dist/{tools-BEYxowf0.cjs → tools-DZoVfKPl.cjs} +43 -18
- package/dist/{tools-tPy2FwMI.js → tools-FwJyNoyg.js} +42 -11
- package/dist/types/user.d.ts +1 -1
- package/dist/{utils-D2Bj0C2E.cjs → utils-Dd4m7z13.cjs} +6 -5
- package/dist/{utils-BnG4bq6k.js → utils-h5k_ChdS.js} +6 -5
- package/dist/utils.cjs +3 -3
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +3 -3
- package/dist/{validate-DHEGALaE.js → validate-DQB9spZ1.js} +1 -1
- package/dist/{validate-BxgKlbt7.cjs → validate-u6_TUYSo.cjs} +1 -1
- package/dist/vector/embed.d.ts +4 -4
- package/dist/vector/index.cjs +9 -9
- package/dist/vector/index.js +2 -2
- package/dist/vector/vector.d.ts +4 -4
- package/dist/voice/aisdk/index.d.ts +1 -1
- package/dist/voice/aisdk/speech.d.ts +1 -1
- package/dist/voice/aisdk/transcription.d.ts +1 -1
- package/dist/voice/composite-voice.d.ts +1 -1
- package/dist/voice/default-voice.d.ts +1 -1
- package/dist/voice/index.d.ts +2 -2
- package/dist/voice/voice.d.ts +1 -1
- package/dist/worker/index.cjs +1 -1
- package/dist/worker/index.d.ts +1 -1
- package/dist/worker/index.js +1 -1
- package/dist/worker/workers/orchestration-worker.d.ts +13 -0
- package/dist/{worker-BRKHC9hv.cjs → worker-0F7Nukyf.cjs} +3 -3
- package/dist/{worker-DYBrWSDX.cjs → worker-D-cq8McN.cjs} +129 -39
- package/dist/{worker-C-xoXGOt.js → worker-DWOK2M_5.js} +122 -32
- package/dist/{worker-1lHN6hT1.js → worker-DmUkyJY_.js} +2 -2
- package/dist/{workflow-DGRDgyhs.cjs → workflow-DXE15e-w.cjs} +30 -38
- package/dist/{workflow-79JneaJP.js → workflow-DamOke3z.js} +26 -34
- 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 +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/evented/setup-warning.d.ts +31 -0
- package/dist/workflows/evented/workflow-event-processor/index.d.ts +10 -4
- 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 +8 -3
- package/dist/workflows/handlers/entry.d.ts +8 -0
- package/dist/workflows/index.cjs +57 -55
- package/dist/workflows/index.js +6 -6
- package/dist/workflows/run-storage.d.ts +27 -3
- package/dist/workflows/scheduler/claim.d.ts +51 -0
- package/dist/workflows/scheduler/index.d.ts +2 -0
- package/dist/workflows/scheduler/types.d.ts +3 -0
- package/dist/workflows/types.d.ts +17 -1
- package/dist/workflows/workflow.d.ts +88 -11
- 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/sandbox/local-sandbox.d.ts +11 -0
- package/dist/workspace/sandbox/sandbox.d.ts +2 -0
- package/dist/workspace/tools/media.d.ts +2 -2
- package/dist/{workspace-C8Zo5_qK.cjs → workspace-BQD4tcQi.cjs} +227 -26
- package/dist/{workspace-DOAil8mG.js → workspace-sqcfdZRR.js} +226 -25
- package/llm/reasoning.d.ts +1 -0
- package/memory/om-events.d.ts +1 -0
- package/package.json +36 -15
- package/skills/mastra/SKILL.md +171 -0
- package/skills/mastra/references/common-errors.md +557 -0
- package/skills/mastra/references/core-concepts.md +21 -0
- package/skills/mastra/references/create-mastra.md +233 -0
- package/skills/mastra/references/embedded-docs.md +103 -0
- package/skills/mastra/references/feedback.md +69 -0
- package/skills/mastra/references/gateway.md +66 -0
- package/skills/mastra/references/mastra-api.md +222 -0
- package/skills/mastra/references/migration-guide.md +185 -0
- package/skills/mastra/references/model-selection.md +29 -0
- package/skills/mastra/references/platform.md +164 -0
- package/skills/mastra/references/remote-docs.md +193 -0
- package/skills/mastra/references/trace-query.md +150 -0
- package/skills/mastra/scripts/provider-registry.mjs +271 -0
- package/src/llm/model/provider-types.generated.d.ts +7162 -7416
- package/dist/capabilities/ai21.json +0 -4
- package/dist/capabilities/clarifai.json +0 -42
- package/dist/capabilities/jad-ai.json +0 -20
- package/dist/capabilities/llmtech.json +0 -16
- package/dist/signals-B1JSj-Ew.cjs +0 -58
- package/dist/signals-De9VnwL2.js +0 -53
- package/dist/_types/{@internal_ai-sdk-v4@0.0.99 → @internal_ai-sdk-v4@0.0.100}/dist/test.d.ts +0 -0
- package/dist/_types/{@internal_ai-sdk-v4@0.0.99 → @internal_ai-sdk-v4@0.0.100}/package.json +0 -0
- package/dist/_types/{@internal_ai-sdk-v5@0.0.99 → @internal_ai-sdk-v5@0.0.100}/dist/test.d.ts +0 -0
- package/dist/_types/{@internal_ai-sdk-v5@0.0.99 → @internal_ai-sdk-v5@0.0.100}/package.json +0 -0
- package/dist/_types/{@internal_ai-v6@0.0.99 → @internal_ai-v6@0.0.100}/package.json +0 -0
- package/dist/_types/{@internal_ai-v7@0.0.99 → @internal_ai-v7@0.0.100}/package.json +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/_types/@internal_core@0.1.4/dist/base/index.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/_types/@internal_core@0.1.4/dist/index-Diz1p9N7.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/ee/capabilities.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/ee/defaults/index.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/ee/defaults/rbac/index.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/ee/defaults/rbac/static.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/ee/defaults/roles.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/ee/fga-check.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/ee/index.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/ee/interfaces/acl.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/ee/interfaces/fga.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/ee/interfaces/index.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/ee/interfaces/permissions.generated.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/ee/interfaces/rbac.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/ee/interfaces/user.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/ee/license.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/index.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/provider/index.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/session/cookie.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/session/index.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/session/memory.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/dist/types/index.d.ts +0 -0
- package/dist/_types/{@internal_auth@0.0.40 → @internal_auth@0.0.41}/package.json +0 -0
- package/dist/_types/{@internal_deployer@0.0.5 → @internal_deployer@0.0.6}/dist/_types/@internal_core@0.1.4/dist/index-Diz1p9N7.d.ts +0 -0
- package/dist/_types/{@internal_deployer@0.0.5 → @internal_deployer@0.0.6}/dist/_types/@internal_core@0.1.4/dist/logger/index.d.ts +0 -0
- package/dist/_types/{@internal_deployer@0.0.5 → @internal_deployer@0.0.6}/dist/bundler.d.ts +0 -0
- package/dist/_types/{@internal_deployer@0.0.5 → @internal_deployer@0.0.6}/dist/deployer.d.ts +0 -0
- package/dist/_types/{@internal_deployer@0.0.5 → @internal_deployer@0.0.6}/dist/index.d.ts +0 -0
- package/dist/_types/{@internal_deployer@0.0.5 → @internal_deployer@0.0.6}/package.json +0 -0
- package/dist/_types/{@internal_external-types@0.0.102 → @internal_external-types@0.0.103}/dist/index.d.ts +0 -0
- package/dist/_types/{@internal_external-types@0.0.102 → @internal_external-types@0.0.103}/package.json +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/@internal_core@0.1.4/dist/base/index.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/@internal_core@0.1.4/dist/index-Diz1p9N7.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/@internal_core@0.1.4/dist/request-context/index.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/@internal_core@0.1.4/dist/types/index.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v3/ZodError.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v3/errors.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v3/external.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v3/helpers/enumUtil.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v3/helpers/errorUtil.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v3/helpers/parseUtil.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v3/helpers/partialUtil.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v3/helpers/typeAliases.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v3/helpers/util.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v3/index.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v3/locales/en.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v3/standard-schema.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v3/types.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/classic/checks.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/classic/coerce.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/classic/compat.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/classic/deep-partial.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/classic/errors.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/classic/external.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/classic/from-json-schema.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/classic/in-out.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/classic/index.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/classic/iso.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/classic/parse.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/classic/schemas.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/core/api.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/core/checks.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/core/compile.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/core/core.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/core/doc.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/core/errors.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/core/index.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/core/json-schema-generator.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/core/json-schema-processors.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/core/json-schema.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/core/memoizer.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/core/parse.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/core/regexes.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/core/registries.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/core/schemas.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/core/standard-schema.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/core/to-json-schema.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/core/util.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/core/versions.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/index.d.cts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/ar.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/az.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/be.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/bg.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/bn.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/ca.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/ckb.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/cs.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/da.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/de.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/el.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/en.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/eo.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/es.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/fa.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/fi.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/fr-CA.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/fr.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/gu.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/he.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/hi.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/hr.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/hu.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/hy.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/id.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/index.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/is.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/it.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/ja.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/ka.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/kh.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/km.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/kn.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/ko.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/lt.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/mk.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/ms.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/ne.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/nl.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/nn.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/no.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/ota.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/pl.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/ps.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/pt-BR.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/pt.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/ro.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/ru.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/sk.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/sl.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/sv.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/ta.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/tg.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/th.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/tk.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/tr.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/ua.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/uk.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/ur.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/uz.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/vi.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/yo.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/zh-CN.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/_types/zod@4.6.7/v4/locales/zh-TW.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/index.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/voice/aisdk/index.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/voice/default-voice.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/voice/index.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/dist/voice/voice.d.ts +0 -0
- package/dist/_types/{@internal_voice@0.0.48 → @internal_voice@0.0.49}/package.json +0 -0
- package/dist/{observability-B0R_D1PZ.cjs → observability-VaoaeadK.cjs} +647 -647
package/dist/knowledge/index.cjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_base = require("../base-BIzR1D3_.cjs");
|
|
3
|
-
const
|
|
4
|
-
const require_tool = require("../tool-
|
|
3
|
+
const require_execution_fence = require("../execution-fence-C8Q0wWkG.cjs");
|
|
4
|
+
const require_tool = require("../tool-Dn9WSDVn.cjs");
|
|
5
|
+
const require_workspace = require("../workspace-BQD4tcQi.cjs");
|
|
5
6
|
let crypto = require("crypto");
|
|
6
7
|
let _mastra_schema_compat_schema = require("@mastra/schema-compat/schema");
|
|
7
8
|
// src/knowledge/changes.ts
|
|
@@ -23,6 +24,39 @@ const note = (op) => (result) => {
|
|
|
23
24
|
noteId: id
|
|
24
25
|
};
|
|
25
26
|
};
|
|
27
|
+
/** The event each single write would emit for `write`, so a batch emits what its single writes would. */
|
|
28
|
+
function describePageWrite(write) {
|
|
29
|
+
switch (write.op) {
|
|
30
|
+
case "create":
|
|
31
|
+
case "update":
|
|
32
|
+
case "delete": return {
|
|
33
|
+
kind: "page",
|
|
34
|
+
op: write.op,
|
|
35
|
+
pageId: write.id,
|
|
36
|
+
scopeId: write.scopeId
|
|
37
|
+
};
|
|
38
|
+
case "move": return {
|
|
39
|
+
kind: "page",
|
|
40
|
+
op: "move",
|
|
41
|
+
pageId: write.id,
|
|
42
|
+
scopeId: write.scopeId,
|
|
43
|
+
fromScopeId: write.fromScopeId
|
|
44
|
+
};
|
|
45
|
+
case "add-note": return {
|
|
46
|
+
kind: "note",
|
|
47
|
+
op: "add",
|
|
48
|
+
pageId: write.pageId,
|
|
49
|
+
noteId: write.id
|
|
50
|
+
};
|
|
51
|
+
case "remove-note": return {
|
|
52
|
+
kind: "note",
|
|
53
|
+
op: "remove",
|
|
54
|
+
pageId: write.pageId,
|
|
55
|
+
noteId: write.id
|
|
56
|
+
};
|
|
57
|
+
case "replace-links": return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
26
60
|
/** The page-store writes that emit, and the event each one's result maps to. */
|
|
27
61
|
const WRITES = {
|
|
28
62
|
materializeScope: (result) => {
|
|
@@ -58,6 +92,7 @@ const WRITES = {
|
|
|
58
92
|
fromScopeId
|
|
59
93
|
};
|
|
60
94
|
},
|
|
95
|
+
applyPageWrites: (_result, input) => input.writes.map(describePageWrite).filter((change) => change !== null),
|
|
61
96
|
addNote: note("add"),
|
|
62
97
|
restampNote: note("restamp"),
|
|
63
98
|
removeNote: note("remove"),
|
|
@@ -143,9 +178,15 @@ function emitKnowledgeChanges(storage, emit, listening, onError, chain) {
|
|
|
143
178
|
}
|
|
144
179
|
const result = await value.call(target, input, ...rest);
|
|
145
180
|
if (!listening()) return result;
|
|
181
|
+
let changes = [];
|
|
146
182
|
try {
|
|
147
183
|
const change = describe(result, input, fromScopeId);
|
|
148
|
-
|
|
184
|
+
changes = Array.isArray(change) ? change : change ? [change] : [];
|
|
185
|
+
} catch (error) {
|
|
186
|
+
onError(error);
|
|
187
|
+
}
|
|
188
|
+
for (const one of changes) try {
|
|
189
|
+
report(one);
|
|
149
190
|
} catch (error) {
|
|
150
191
|
onError(error);
|
|
151
192
|
}
|
|
@@ -285,7 +326,8 @@ const DECLARATION_FIELDS = {
|
|
|
285
326
|
required: true
|
|
286
327
|
},
|
|
287
328
|
parent: { kind: "nullableString" },
|
|
288
|
-
fallbackParent: { kind: "nonEmpty" }
|
|
329
|
+
fallbackParent: { kind: "nonEmpty" },
|
|
330
|
+
path: { kind: "segments" }
|
|
289
331
|
};
|
|
290
332
|
const ITEM_FIELDS = {
|
|
291
333
|
...DECLARATION_FIELDS,
|
|
@@ -331,6 +373,9 @@ function checkFields(value, fields, where) {
|
|
|
331
373
|
case "aliases":
|
|
332
374
|
out[key] = checkDenseArray(field, at).map((alias, index) => checkString(alias, `${at}[${index}]`, true));
|
|
333
375
|
break;
|
|
376
|
+
case "segments":
|
|
377
|
+
out[key] = checkDenseArray(field, at).map((segment, index) => checkString(segment, `${at}[${index}]`));
|
|
378
|
+
break;
|
|
334
379
|
case "links": out[key] = checkDenseArray(field, at).map((link, index) => checkFields(link, {
|
|
335
380
|
sourceId: {
|
|
336
381
|
kind: "nonEmpty",
|
|
@@ -1033,6 +1078,991 @@ async function finishRun(host, request, lastSeq, unsettledSeq, withRetries) {
|
|
|
1033
1078
|
function encodedBytes(value) {
|
|
1034
1079
|
return new TextEncoder().encode(JSON.stringify(value)).byteLength;
|
|
1035
1080
|
}
|
|
1081
|
+
// src/knowledge/importers/overlay.ts
|
|
1082
|
+
/**
|
|
1083
|
+
* The working copy a batched importer flush decides over (batched-flush plan v3.1 §1). The sink's
|
|
1084
|
+
* rule code runs unchanged against {@link ImportOverlay.storage} and {@link ImportOverlay.importers}:
|
|
1085
|
+
* reads come from rows gathered in a few set-based queries and locked, writes are applied to the
|
|
1086
|
+
* working copy and kept, in call order, for one batched write after every op is decided.
|
|
1087
|
+
*
|
|
1088
|
+
* A read of something not gathered throws {@link KnowledgeImportNotGatheredError} and names it, so
|
|
1089
|
+
* the caller gathers it and decides again. A call the working copy can't model throws
|
|
1090
|
+
* {@link KnowledgeImportBatchUnsupportedError}, and the flush takes the per-op path instead.
|
|
1091
|
+
*
|
|
1092
|
+
* @internal
|
|
1093
|
+
*/
|
|
1094
|
+
/** The overlay was asked for a row it wasn't given. The caller gathers it and decides again. */
|
|
1095
|
+
var KnowledgeImportNotGatheredError = class extends Error {
|
|
1096
|
+
constructor(what) {
|
|
1097
|
+
super(`Not gathered for the batched import flush: ${what}`);
|
|
1098
|
+
this.name = "KnowledgeImportNotGatheredError";
|
|
1099
|
+
}
|
|
1100
|
+
};
|
|
1101
|
+
/** The flush needs a call the overlay doesn't model: it falls back to the per-op path. */
|
|
1102
|
+
/**
|
|
1103
|
+
* The gather read the rows once, its plan writing pages only in place, and the decide pass went to
|
|
1104
|
+
* create, move or delete a page anyway: one more pass reads them again under the lock.
|
|
1105
|
+
*/
|
|
1106
|
+
var KnowledgeImportRereadRequiredError = class extends Error {
|
|
1107
|
+
constructor(what) {
|
|
1108
|
+
super(`The batched import flush needs its rows read again under the lock: ${what}`);
|
|
1109
|
+
this.name = "KnowledgeImportRereadRequiredError";
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
var KnowledgeImportBatchUnsupportedError = class extends Error {
|
|
1113
|
+
call;
|
|
1114
|
+
constructor(call) {
|
|
1115
|
+
super(`Not supported by the batched import flush: ${call}`);
|
|
1116
|
+
this.call = call;
|
|
1117
|
+
this.name = "KnowledgeImportBatchUnsupportedError";
|
|
1118
|
+
}
|
|
1119
|
+
};
|
|
1120
|
+
const nodeKey = (bindingId, sourceId) => `${bindingId}\u0000${sourceId}`;
|
|
1121
|
+
/** The key {@link ImportOverlayRows.paths} holds a scope path under. */
|
|
1122
|
+
const importPathKey = (scopeId, path) => JSON.stringify([scopeId, ...path]);
|
|
1123
|
+
const pathKey = importPathKey;
|
|
1124
|
+
/**
|
|
1125
|
+
* The key path of each live page whose whole chain to its scope is among `pages`, to that page: a
|
|
1126
|
+
* path a read chain already answers, with no `getPagesByPaths`. One key path has one live page.
|
|
1127
|
+
*/
|
|
1128
|
+
function importChainPaths(pages) {
|
|
1129
|
+
const out = /* @__PURE__ */ new Map();
|
|
1130
|
+
for (const page of pages.values()) {
|
|
1131
|
+
if (!page || page.isScope) continue;
|
|
1132
|
+
const path = [];
|
|
1133
|
+
let at = page;
|
|
1134
|
+
while (at && !at.isScope) {
|
|
1135
|
+
if (at.key === void 0 || at.deletedAt || at.mergedInto || path.length >= 10) {
|
|
1136
|
+
at = void 0;
|
|
1137
|
+
break;
|
|
1138
|
+
}
|
|
1139
|
+
path.unshift(at.key);
|
|
1140
|
+
at = at.parentId ? pages.get(at.parentId) : null;
|
|
1141
|
+
}
|
|
1142
|
+
if (at) out.set(pathKey(at.id, path), page.id);
|
|
1143
|
+
}
|
|
1144
|
+
return out;
|
|
1145
|
+
}
|
|
1146
|
+
const childKey = (parentId, key) => `${parentId}\u0000${key}`;
|
|
1147
|
+
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;
|
|
1148
|
+
/** UTF-8 byte order, as the stores sort source IDs. */
|
|
1149
|
+
const byteOrder = (a, b) => Buffer.compare(Buffer.from(a), Buffer.from(b));
|
|
1150
|
+
const emptyImportOverlayMissing = () => ({
|
|
1151
|
+
pages: /* @__PURE__ */ new Set(),
|
|
1152
|
+
nodes: /* @__PURE__ */ new Set(),
|
|
1153
|
+
nodesByPage: /* @__PURE__ */ new Set(),
|
|
1154
|
+
paths: /* @__PURE__ */ new Map(),
|
|
1155
|
+
notes: /* @__PURE__ */ new Set(),
|
|
1156
|
+
positions: /* @__PURE__ */ new Set(),
|
|
1157
|
+
locks: /* @__PURE__ */ new Set(),
|
|
1158
|
+
subtrees: /* @__PURE__ */ new Set(),
|
|
1159
|
+
linkTargets: /* @__PURE__ */ new Set(),
|
|
1160
|
+
bindings: /* @__PURE__ */ new Set()
|
|
1161
|
+
});
|
|
1162
|
+
const emptyImportOverlayRows = () => ({
|
|
1163
|
+
pages: /* @__PURE__ */ new Map(),
|
|
1164
|
+
nodes: /* @__PURE__ */ new Map(),
|
|
1165
|
+
nodesByPage: /* @__PURE__ */ new Map(),
|
|
1166
|
+
paths: /* @__PURE__ */ new Map(),
|
|
1167
|
+
notes: /* @__PURE__ */ new Map(),
|
|
1168
|
+
positions: /* @__PURE__ */ new Map(),
|
|
1169
|
+
locked: /* @__PURE__ */ new Set(),
|
|
1170
|
+
complete: /* @__PURE__ */ new Set(),
|
|
1171
|
+
tooLarge: /* @__PURE__ */ new Set(),
|
|
1172
|
+
linkTargets: /* @__PURE__ */ new Set(),
|
|
1173
|
+
tooManyLinkers: /* @__PURE__ */ new Set()
|
|
1174
|
+
});
|
|
1175
|
+
/** The binding and targets of a deferred mark, so back-to-back marks for one binding run as one. */
|
|
1176
|
+
const markTargets = /* @__PURE__ */ new WeakMap();
|
|
1177
|
+
const copyRows = (rows) => ({
|
|
1178
|
+
pages: new Map(rows.pages),
|
|
1179
|
+
nodes: new Map(rows.nodes),
|
|
1180
|
+
nodesByPage: new Map(rows.nodesByPage),
|
|
1181
|
+
paths: new Map(rows.paths),
|
|
1182
|
+
notes: new Map(rows.notes),
|
|
1183
|
+
positions: new Map(rows.positions),
|
|
1184
|
+
locked: new Set(rows.locked),
|
|
1185
|
+
complete: new Set(rows.complete),
|
|
1186
|
+
tooLarge: new Set(rows.tooLarge),
|
|
1187
|
+
linkTargets: new Set(rows.linkTargets),
|
|
1188
|
+
tooManyLinkers: new Set(rows.tooManyLinkers),
|
|
1189
|
+
...rows.bindings ? { bindings: rows.bindings } : {},
|
|
1190
|
+
...rows.inPlace ? { inPlace: true } : {},
|
|
1191
|
+
...rows.readOnce ? { readOnce: true } : {}
|
|
1192
|
+
});
|
|
1193
|
+
const copyState = (state) => ({
|
|
1194
|
+
rows: copyRows(state.rows),
|
|
1195
|
+
writes: [...state.writes],
|
|
1196
|
+
touched: new Set(state.touched),
|
|
1197
|
+
marks: [...state.marks],
|
|
1198
|
+
links: [...state.links],
|
|
1199
|
+
moved: new Set(state.moved),
|
|
1200
|
+
freed: new Set(state.freed),
|
|
1201
|
+
stalePositions: new Set(state.stalePositions)
|
|
1202
|
+
});
|
|
1203
|
+
/** Every method the given implementation lacks throws {@link KnowledgeImportBatchUnsupportedError}. */
|
|
1204
|
+
function only(impl, name) {
|
|
1205
|
+
return new Proxy(impl, { get(target, prop, receiver) {
|
|
1206
|
+
if (prop in target) return Reflect.get(target, prop, receiver);
|
|
1207
|
+
if (typeof prop !== "string" || prop === "then") return void 0;
|
|
1208
|
+
return () => {
|
|
1209
|
+
throw new KnowledgeImportBatchUnsupportedError(`${name}.${prop}`);
|
|
1210
|
+
};
|
|
1211
|
+
} });
|
|
1212
|
+
}
|
|
1213
|
+
var ImportOverlay = class {
|
|
1214
|
+
missing = emptyImportOverlayMissing();
|
|
1215
|
+
#state;
|
|
1216
|
+
storage;
|
|
1217
|
+
importers;
|
|
1218
|
+
constructor(base, now = () => /* @__PURE__ */ new Date()) {
|
|
1219
|
+
this.#state = {
|
|
1220
|
+
rows: copyRows(base),
|
|
1221
|
+
writes: [],
|
|
1222
|
+
touched: /* @__PURE__ */ new Set(),
|
|
1223
|
+
marks: [],
|
|
1224
|
+
links: [],
|
|
1225
|
+
moved: /* @__PURE__ */ new Set(),
|
|
1226
|
+
freed: /* @__PURE__ */ new Set(),
|
|
1227
|
+
stalePositions: /* @__PURE__ */ new Set()
|
|
1228
|
+
};
|
|
1229
|
+
this.storage = this.#storage(now);
|
|
1230
|
+
this.importers = this.#importers();
|
|
1231
|
+
}
|
|
1232
|
+
get writes() {
|
|
1233
|
+
return this.#state.writes;
|
|
1234
|
+
}
|
|
1235
|
+
get marks() {
|
|
1236
|
+
return this.#state.marks;
|
|
1237
|
+
}
|
|
1238
|
+
get links() {
|
|
1239
|
+
return this.#state.links;
|
|
1240
|
+
}
|
|
1241
|
+
/** Link-index work the sink would run now; it runs, in one batch, after the batched write instead. */
|
|
1242
|
+
deferLinks(...work) {
|
|
1243
|
+
this.#state.links.push(...work);
|
|
1244
|
+
}
|
|
1245
|
+
/** The node writes decided: each touched node's last record, or a delete when it ends up gone. */
|
|
1246
|
+
nodeWrites(base) {
|
|
1247
|
+
const deletes = [];
|
|
1248
|
+
const saves = [];
|
|
1249
|
+
for (const key of this.#state.touched) {
|
|
1250
|
+
const node = this.#state.rows.nodes.get(key);
|
|
1251
|
+
if (node) {
|
|
1252
|
+
const { updatedAt: _updatedAt, ...record } = node;
|
|
1253
|
+
saves.push(record);
|
|
1254
|
+
} else if (base.nodes.get(key)) {
|
|
1255
|
+
const [bindingId, sourceId] = key.split("\0");
|
|
1256
|
+
deletes.push({
|
|
1257
|
+
bindingId,
|
|
1258
|
+
sourceId
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
return {
|
|
1263
|
+
deletes,
|
|
1264
|
+
saves
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
#page(id) {
|
|
1268
|
+
const { pages } = this.#state.rows;
|
|
1269
|
+
if (!pages.has(id)) {
|
|
1270
|
+
this.missing.pages.add(id);
|
|
1271
|
+
throw new KnowledgeImportNotGatheredError(`page ${id}`);
|
|
1272
|
+
}
|
|
1273
|
+
return pages.get(id);
|
|
1274
|
+
}
|
|
1275
|
+
#livePage(id) {
|
|
1276
|
+
const page = this.#page(id);
|
|
1277
|
+
if (!page || page.deletedAt || page.mergedInto) throw new require_execution_fence.KnowledgeNotFoundError("page", id);
|
|
1278
|
+
return page;
|
|
1279
|
+
}
|
|
1280
|
+
/** Levels below the home scope, from the working copy's chain. */
|
|
1281
|
+
#depth(page) {
|
|
1282
|
+
let depth = 0;
|
|
1283
|
+
let at = page;
|
|
1284
|
+
while (at && !at.isScope) {
|
|
1285
|
+
depth++;
|
|
1286
|
+
at = at.parentId ? this.#page(at.parentId) : null;
|
|
1287
|
+
}
|
|
1288
|
+
return depth;
|
|
1289
|
+
}
|
|
1290
|
+
/** The page's key path from its scope, or null when the chain doesn't reach one. */
|
|
1291
|
+
#keys(page) {
|
|
1292
|
+
const path = [];
|
|
1293
|
+
let at = page;
|
|
1294
|
+
while (at && !at.isScope) {
|
|
1295
|
+
if (at.key === void 0 || at.deletedAt || at.mergedInto) return null;
|
|
1296
|
+
path.unshift(at.key);
|
|
1297
|
+
at = at.parentId ? this.#page(at.parentId) : null;
|
|
1298
|
+
}
|
|
1299
|
+
return at ? {
|
|
1300
|
+
scopeId: at.id,
|
|
1301
|
+
path
|
|
1302
|
+
} : null;
|
|
1303
|
+
}
|
|
1304
|
+
/**
|
|
1305
|
+
* Live ordinary children by parent, sorted by position: built on first use, dropped on each page
|
|
1306
|
+
* write, and keyed by the pages map, which a rolled-back transaction replaces.
|
|
1307
|
+
*/
|
|
1308
|
+
#childIndex;
|
|
1309
|
+
#setPage(id, page) {
|
|
1310
|
+
this.#state.rows.pages.set(id, page);
|
|
1311
|
+
this.#childIndex = void 0;
|
|
1312
|
+
this.#chainPaths = void 0;
|
|
1313
|
+
}
|
|
1314
|
+
/** {@link importChainPaths} of the working copy, kept like the child index. */
|
|
1315
|
+
#chainPaths;
|
|
1316
|
+
#pathFromChains(key) {
|
|
1317
|
+
const { pages } = this.#state.rows;
|
|
1318
|
+
if (this.#chainPaths?.pages !== pages) this.#chainPaths = {
|
|
1319
|
+
pages,
|
|
1320
|
+
byPath: importChainPaths(pages)
|
|
1321
|
+
};
|
|
1322
|
+
return this.#chainPaths.byPath.get(key);
|
|
1323
|
+
}
|
|
1324
|
+
/** Live ordinary children by position, once gathered. */
|
|
1325
|
+
#children(parentId) {
|
|
1326
|
+
const { pages, complete } = this.#state.rows;
|
|
1327
|
+
if (!complete.has(parentId)) {
|
|
1328
|
+
this.missing.subtrees.add(parentId);
|
|
1329
|
+
throw new KnowledgeImportNotGatheredError(`children of ${parentId}`);
|
|
1330
|
+
}
|
|
1331
|
+
if (this.#childIndex?.pages !== pages) {
|
|
1332
|
+
const byParent = /* @__PURE__ */ new Map();
|
|
1333
|
+
for (const page of pages.values()) {
|
|
1334
|
+
if (!page || !page.parentId || page.isScope || page.deletedAt) continue;
|
|
1335
|
+
const siblings = byParent.get(page.parentId);
|
|
1336
|
+
if (siblings) siblings.push(page);
|
|
1337
|
+
else byParent.set(page.parentId, [page]);
|
|
1338
|
+
}
|
|
1339
|
+
for (const siblings of byParent.values()) siblings.sort(byPosition);
|
|
1340
|
+
this.#childIndex = {
|
|
1341
|
+
pages,
|
|
1342
|
+
byParent
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
1345
|
+
return [...this.#childIndex.byParent.get(parentId) ?? []];
|
|
1346
|
+
}
|
|
1347
|
+
/** The next position under a parent, as `createPage` and `movePage` would place a page. */
|
|
1348
|
+
#nextPosition(parentId) {
|
|
1349
|
+
const { positions, complete } = this.#state.rows;
|
|
1350
|
+
if (this.#state.stalePositions.has(parentId)) {
|
|
1351
|
+
if (!complete.has(parentId)) throw new KnowledgeImportBatchUnsupportedError("a position under a parent its last child left");
|
|
1352
|
+
return require_execution_fence.knowledgePositionBetween(this.#children(parentId).at(-1)?.position);
|
|
1353
|
+
}
|
|
1354
|
+
if (!positions.has(parentId)) {
|
|
1355
|
+
this.missing.positions.add(parentId);
|
|
1356
|
+
throw new KnowledgeImportNotGatheredError(`last child position of ${parentId}`);
|
|
1357
|
+
}
|
|
1358
|
+
return require_execution_fence.knowledgePositionBetween(positions.get(parentId) ?? void 0);
|
|
1359
|
+
}
|
|
1360
|
+
/** A page left `parentId`: its next position is still the gathered one unless it was the last child. */
|
|
1361
|
+
#left(parentId, position) {
|
|
1362
|
+
if (!parentId) return;
|
|
1363
|
+
const last = this.#state.rows.positions.get(parentId);
|
|
1364
|
+
if (last === void 0 || last === position) this.#state.stalePositions.add(parentId);
|
|
1365
|
+
}
|
|
1366
|
+
/** Points the path map at where `pages` are now; `before` holds their old paths. */
|
|
1367
|
+
#repath(pages, before) {
|
|
1368
|
+
const { paths } = this.#state.rows;
|
|
1369
|
+
const ids = new Set(pages.map((page) => page.id));
|
|
1370
|
+
for (const [key, id] of paths) if (id && ids.has(id)) paths.set(key, null);
|
|
1371
|
+
for (const old of before) if (old) paths.set(pathKey(old.scopeId, old.path), null);
|
|
1372
|
+
for (const page of pages) {
|
|
1373
|
+
const keys = this.#rowKeys(page);
|
|
1374
|
+
if (keys) paths.set(pathKey(keys.scopeId, keys.path), page.id);
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
/** {@link #keys} on the working copy's current row. */
|
|
1378
|
+
#rowKeys(page) {
|
|
1379
|
+
return this.#keys(this.#state.rows.pages.get(page.id) ?? page);
|
|
1380
|
+
}
|
|
1381
|
+
#node(key) {
|
|
1382
|
+
const { nodes } = this.#state.rows;
|
|
1383
|
+
if (!nodes.has(key)) {
|
|
1384
|
+
this.missing.nodes.add(key);
|
|
1385
|
+
throw new KnowledgeImportNotGatheredError(`node ${key}`);
|
|
1386
|
+
}
|
|
1387
|
+
return nodes.get(key);
|
|
1388
|
+
}
|
|
1389
|
+
#setNode(key, node) {
|
|
1390
|
+
const { nodes, nodesByPage } = this.#state.rows;
|
|
1391
|
+
const before = nodes.get(key);
|
|
1392
|
+
if (before && nodesByPage.get(before.pageId) === key) nodesByPage.set(before.pageId, null);
|
|
1393
|
+
nodes.set(key, node);
|
|
1394
|
+
if (node) nodesByPage.set(node.pageId, key);
|
|
1395
|
+
this.#state.touched.add(key);
|
|
1396
|
+
}
|
|
1397
|
+
#storage(now) {
|
|
1398
|
+
const rows = () => this.#state.rows;
|
|
1399
|
+
const impl = {
|
|
1400
|
+
transaction: async (fn) => {
|
|
1401
|
+
const saved = copyState(this.#state);
|
|
1402
|
+
try {
|
|
1403
|
+
return await fn(this.storage);
|
|
1404
|
+
} catch (error) {
|
|
1405
|
+
this.#state = saved;
|
|
1406
|
+
throw error;
|
|
1407
|
+
}
|
|
1408
|
+
},
|
|
1409
|
+
getPage: async ({ id }) => this.#page(id),
|
|
1410
|
+
getPageParents: async ({ parentId }) => {
|
|
1411
|
+
const parents = [];
|
|
1412
|
+
let id = parentId;
|
|
1413
|
+
while (id && parents.length <= 10) {
|
|
1414
|
+
const page = this.#page(id);
|
|
1415
|
+
if (!page) break;
|
|
1416
|
+
parents.push(page);
|
|
1417
|
+
id = page.parentId;
|
|
1418
|
+
}
|
|
1419
|
+
return parents;
|
|
1420
|
+
},
|
|
1421
|
+
getPageByPath: async ({ scopeId, path }) => {
|
|
1422
|
+
if (path.length === 0) return null;
|
|
1423
|
+
const key = pathKey(scopeId, path);
|
|
1424
|
+
if (!rows().paths.has(key)) {
|
|
1425
|
+
const id = this.#pathFromChains(key);
|
|
1426
|
+
if (id) return this.#page(id);
|
|
1427
|
+
this.missing.paths.set(key, {
|
|
1428
|
+
scopeId,
|
|
1429
|
+
path
|
|
1430
|
+
});
|
|
1431
|
+
throw new KnowledgeImportNotGatheredError(`path ${key}`);
|
|
1432
|
+
}
|
|
1433
|
+
const id = rows().paths.get(key);
|
|
1434
|
+
return id ? this.#page(id) : null;
|
|
1435
|
+
},
|
|
1436
|
+
lockPages: async (ids) => {
|
|
1437
|
+
const unlocked = ids.filter((id) => !rows().locked.has(id));
|
|
1438
|
+
if (unlocked.length) {
|
|
1439
|
+
for (const id of unlocked) this.missing.locks.add(id);
|
|
1440
|
+
throw new KnowledgeImportNotGatheredError(`locks ${unlocked.join(", ")}`);
|
|
1441
|
+
}
|
|
1442
|
+
return [];
|
|
1443
|
+
},
|
|
1444
|
+
listNotes: async ({ pageId }) => {
|
|
1445
|
+
if (!rows().notes.has(pageId)) {
|
|
1446
|
+
this.missing.notes.add(pageId);
|
|
1447
|
+
throw new KnowledgeImportNotGatheredError(`notes of ${pageId}`);
|
|
1448
|
+
}
|
|
1449
|
+
return { notes: rows().notes.get(pageId).filter((note) => !note.deletedAt) };
|
|
1450
|
+
},
|
|
1451
|
+
createPage: async (input) => {
|
|
1452
|
+
if (rows().readOnce) throw new KnowledgeImportRereadRequiredError("createPage");
|
|
1453
|
+
if (input.id !== void 0 || input.position !== void 0) throw new KnowledgeImportBatchUnsupportedError("createPage with id or position");
|
|
1454
|
+
if (!input.name.trim()) throw new Error("Knowledge page name must not be empty");
|
|
1455
|
+
require_execution_fence.assertKnowledgePageDescriptionWithinBound(input.description || void 0);
|
|
1456
|
+
const parent = this.#livePage(input.parentId);
|
|
1457
|
+
const scopeId = parent.isScope ? parent.id : parent.scopeId;
|
|
1458
|
+
const id = (0, crypto.randomUUID)();
|
|
1459
|
+
const depth = this.#depth(parent) + 1;
|
|
1460
|
+
if (depth > 10) throw new require_execution_fence.KnowledgePageDepthError(id);
|
|
1461
|
+
let path = null;
|
|
1462
|
+
if (input.key !== void 0) {
|
|
1463
|
+
const problem = require_execution_fence.knowledgePageKeyProblem(input.key);
|
|
1464
|
+
if (problem) throw new Error(problem);
|
|
1465
|
+
const parentKeys = parent.isScope ? {
|
|
1466
|
+
scopeId: parent.id,
|
|
1467
|
+
path: []
|
|
1468
|
+
} : this.#keys(parent);
|
|
1469
|
+
if (!parentKeys) throw new KnowledgeImportBatchUnsupportedError("createPage under a broken chain");
|
|
1470
|
+
path = [...parentKeys.path, input.key];
|
|
1471
|
+
if (await impl.getPageByPath({
|
|
1472
|
+
scopeId,
|
|
1473
|
+
path,
|
|
1474
|
+
read: "all"
|
|
1475
|
+
})) throw new require_execution_fence.KnowledgePageKeyConflictError(input.key, parent.id);
|
|
1476
|
+
}
|
|
1477
|
+
if (input.key !== void 0 && this.#state.freed.has(childKey(parent.id, input.key))) throw new KnowledgeImportBatchUnsupportedError("createPage at a key a move left");
|
|
1478
|
+
const position = this.#nextPosition(parent.id);
|
|
1479
|
+
const at = now();
|
|
1480
|
+
const page = {
|
|
1481
|
+
id,
|
|
1482
|
+
scopeId,
|
|
1483
|
+
parentId: parent.id,
|
|
1484
|
+
isScope: false,
|
|
1485
|
+
...input.key !== void 0 ? { key: input.key } : {},
|
|
1486
|
+
position,
|
|
1487
|
+
name: input.name,
|
|
1488
|
+
...input.description ? { description: input.description } : {},
|
|
1489
|
+
...input.body !== void 0 ? { body: input.body } : {},
|
|
1490
|
+
version: 1,
|
|
1491
|
+
createdBy: structuredClone(input.provenance),
|
|
1492
|
+
updatedBy: structuredClone(input.provenance),
|
|
1493
|
+
createdAt: at,
|
|
1494
|
+
updatedAt: at
|
|
1495
|
+
};
|
|
1496
|
+
const state = rows();
|
|
1497
|
+
this.#setPage(id, page);
|
|
1498
|
+
state.positions.set(parent.id, position);
|
|
1499
|
+
state.positions.set(id, null);
|
|
1500
|
+
state.notes.set(id, []);
|
|
1501
|
+
state.nodesByPage.set(id, null);
|
|
1502
|
+
state.locked.add(id);
|
|
1503
|
+
state.complete.add(id);
|
|
1504
|
+
if (path) state.paths.set(pathKey(scopeId, path), id);
|
|
1505
|
+
this.#state.writes.push({
|
|
1506
|
+
op: "create",
|
|
1507
|
+
id,
|
|
1508
|
+
scopeId,
|
|
1509
|
+
parentId: parent.id,
|
|
1510
|
+
...input.key !== void 0 ? { key: input.key } : {},
|
|
1511
|
+
name: input.name,
|
|
1512
|
+
...input.description !== void 0 ? { description: input.description } : {},
|
|
1513
|
+
...input.body !== void 0 ? { body: input.body } : {},
|
|
1514
|
+
position,
|
|
1515
|
+
depth,
|
|
1516
|
+
provenance: input.provenance
|
|
1517
|
+
});
|
|
1518
|
+
return structuredClone(page);
|
|
1519
|
+
},
|
|
1520
|
+
updatePage: async (input) => {
|
|
1521
|
+
const page = this.#livePage(input.id);
|
|
1522
|
+
if (page.version !== input.expectedVersion) throw new require_execution_fence.KnowledgeConflictError(page.id);
|
|
1523
|
+
if (input.name !== void 0 && !input.name.trim()) throw new Error("Knowledge page name must not be empty");
|
|
1524
|
+
require_execution_fence.assertKnowledgePageDescriptionWithinBound(input.description || void 0);
|
|
1525
|
+
const next = {
|
|
1526
|
+
...page,
|
|
1527
|
+
version: page.version + 1,
|
|
1528
|
+
updatedBy: structuredClone(input.provenance)
|
|
1529
|
+
};
|
|
1530
|
+
next.updatedAt = now();
|
|
1531
|
+
if (input.name !== void 0) next.name = input.name;
|
|
1532
|
+
if (input.description !== void 0) {
|
|
1533
|
+
if (input.description) next.description = input.description;
|
|
1534
|
+
else delete next.description;
|
|
1535
|
+
}
|
|
1536
|
+
if (input.body !== void 0) next.body = input.body;
|
|
1537
|
+
this.#setPage(page.id, next);
|
|
1538
|
+
this.#state.writes.push({
|
|
1539
|
+
op: "update",
|
|
1540
|
+
id: page.id,
|
|
1541
|
+
scopeId: page.scopeId,
|
|
1542
|
+
expectedVersion: input.expectedVersion,
|
|
1543
|
+
...input.name !== void 0 ? { name: input.name } : {},
|
|
1544
|
+
...input.description !== void 0 ? { description: input.description } : {},
|
|
1545
|
+
...input.body !== void 0 ? { body: input.body } : {},
|
|
1546
|
+
provenance: input.provenance
|
|
1547
|
+
});
|
|
1548
|
+
return structuredClone(next);
|
|
1549
|
+
},
|
|
1550
|
+
listChildPages: async ({ parentId, read, cursor, limit }) => {
|
|
1551
|
+
if (read !== "all") throw new KnowledgeImportBatchUnsupportedError("listChildPages with a read scope");
|
|
1552
|
+
const children = this.#children(parentId);
|
|
1553
|
+
const start = cursor ? Number(cursor) : 0;
|
|
1554
|
+
const end = limit === void 0 ? children.length : start + limit;
|
|
1555
|
+
return {
|
|
1556
|
+
pages: children.slice(start, end).map((page) => structuredClone(page)),
|
|
1557
|
+
...end < children.length ? { nextCursor: String(end) } : {}
|
|
1558
|
+
};
|
|
1559
|
+
},
|
|
1560
|
+
countChildPages: async ({ parentIds, read }) => {
|
|
1561
|
+
if (read !== "all") throw new KnowledgeImportBatchUnsupportedError("countChildPages with a read scope");
|
|
1562
|
+
return Object.fromEntries(parentIds.map((id) => [id, this.#children(id).length]));
|
|
1563
|
+
},
|
|
1564
|
+
lockSubtree: async (rootId) => {
|
|
1565
|
+
if (rows().tooLarge.has(rootId)) throw new require_execution_fence.KnowledgeMoveTooLargeError(rootId, 501);
|
|
1566
|
+
const ids = [];
|
|
1567
|
+
const parents = [rootId];
|
|
1568
|
+
while (parents.length) {
|
|
1569
|
+
for (const child of this.#children(parents.shift())) {
|
|
1570
|
+
ids.push(child.id);
|
|
1571
|
+
parents.push(child.id);
|
|
1572
|
+
}
|
|
1573
|
+
if (ids.length >= 500) throw new require_execution_fence.KnowledgeMoveTooLargeError(rootId, ids.length + 1);
|
|
1574
|
+
}
|
|
1575
|
+
const unlocked = ids.filter((id) => !rows().locked.has(id));
|
|
1576
|
+
if (unlocked.length) {
|
|
1577
|
+
for (const id of unlocked) this.missing.locks.add(id);
|
|
1578
|
+
throw new KnowledgeImportNotGatheredError(`locks ${unlocked.join(", ")}`);
|
|
1579
|
+
}
|
|
1580
|
+
return ids;
|
|
1581
|
+
},
|
|
1582
|
+
movePage: async (input) => {
|
|
1583
|
+
if (rows().readOnce) throw new KnowledgeImportRereadRequiredError("movePage");
|
|
1584
|
+
if (input.position !== void 0) throw new KnowledgeImportBatchUnsupportedError("movePage with a position");
|
|
1585
|
+
const page = this.#livePage(input.id);
|
|
1586
|
+
if (page.isScope) throw new Error(`Knowledge scope page ${page.id} can't be moved`);
|
|
1587
|
+
if (page.version !== input.expectedVersion) throw new require_execution_fence.KnowledgeConflictError(page.id);
|
|
1588
|
+
const parent = this.#livePage(input.parentId);
|
|
1589
|
+
const subtree = [];
|
|
1590
|
+
const visit = (at, depth) => {
|
|
1591
|
+
subtree.push({
|
|
1592
|
+
page: at,
|
|
1593
|
+
depth
|
|
1594
|
+
});
|
|
1595
|
+
for (const child of this.#children(at.id)) visit(child, depth + 1);
|
|
1596
|
+
};
|
|
1597
|
+
visit(page, 0);
|
|
1598
|
+
if (subtree.some((entry) => entry.page.id === parent.id)) throw new Error(`Knowledge page ${page.id} can't move under itself or its own subtree`);
|
|
1599
|
+
if (subtree.length > 500) throw new require_execution_fence.KnowledgeMoveTooLargeError(page.id, subtree.length);
|
|
1600
|
+
const parentDepth = parent.isScope ? 0 : this.#depth(parent);
|
|
1601
|
+
if (parentDepth + 1 + Math.max(...subtree.map((entry) => entry.depth)) > 10) throw new require_execution_fence.KnowledgePageDepthError(page.id);
|
|
1602
|
+
const scopeId = parent.isScope ? parent.id : parent.scopeId;
|
|
1603
|
+
if (scopeId !== page.scopeId) throw new KnowledgeImportBatchUnsupportedError("movePage across scopes");
|
|
1604
|
+
const key = input.key ?? page.key;
|
|
1605
|
+
if (input.key !== void 0) {
|
|
1606
|
+
const problem = require_execution_fence.knowledgePageKeyProblem(input.key);
|
|
1607
|
+
if (problem) throw new Error(problem);
|
|
1608
|
+
}
|
|
1609
|
+
if (key !== void 0) {
|
|
1610
|
+
const parentKeys = parent.isScope ? {
|
|
1611
|
+
scopeId: parent.id,
|
|
1612
|
+
path: []
|
|
1613
|
+
} : this.#keys(parent);
|
|
1614
|
+
if (!parentKeys) throw new KnowledgeImportBatchUnsupportedError("movePage under a broken chain");
|
|
1615
|
+
const clash = await impl.getPageByPath({
|
|
1616
|
+
scopeId,
|
|
1617
|
+
path: [...parentKeys.path, key],
|
|
1618
|
+
read: "all"
|
|
1619
|
+
});
|
|
1620
|
+
if (clash && clash.id !== page.id) throw new require_execution_fence.KnowledgePageKeyConflictError(key, parent.id);
|
|
1621
|
+
}
|
|
1622
|
+
if (this.#state.moved.has(page.id)) throw new KnowledgeImportBatchUnsupportedError("a second move of a page");
|
|
1623
|
+
const position = this.#nextPosition(parent.id);
|
|
1624
|
+
const before = subtree.map((entry) => this.#keys(entry.page));
|
|
1625
|
+
const at = now();
|
|
1626
|
+
const moved = {
|
|
1627
|
+
...page,
|
|
1628
|
+
...key !== void 0 ? { key } : {},
|
|
1629
|
+
parentId: parent.id,
|
|
1630
|
+
position,
|
|
1631
|
+
version: page.version + 1,
|
|
1632
|
+
updatedBy: structuredClone(input.provenance),
|
|
1633
|
+
updatedAt: at
|
|
1634
|
+
};
|
|
1635
|
+
const state = rows();
|
|
1636
|
+
this.#setPage(page.id, moved);
|
|
1637
|
+
state.positions.set(parent.id, position);
|
|
1638
|
+
this.#left(page.parentId, page.position);
|
|
1639
|
+
if (page.parentId && page.key !== void 0) this.#state.freed.add(childKey(page.parentId, page.key));
|
|
1640
|
+
this.#state.moved.add(page.id);
|
|
1641
|
+
this.#repath(subtree.map((entry) => state.pages.get(entry.page.id)), before);
|
|
1642
|
+
this.#state.writes.push({
|
|
1643
|
+
op: "move",
|
|
1644
|
+
id: page.id,
|
|
1645
|
+
fromScopeId: page.scopeId,
|
|
1646
|
+
expectedVersion: input.expectedVersion,
|
|
1647
|
+
parentId: parent.id,
|
|
1648
|
+
...input.key !== void 0 ? { key: input.key } : {},
|
|
1649
|
+
scopeId,
|
|
1650
|
+
depth: parentDepth + 1,
|
|
1651
|
+
position,
|
|
1652
|
+
provenance: input.provenance
|
|
1653
|
+
});
|
|
1654
|
+
return structuredClone(moved);
|
|
1655
|
+
},
|
|
1656
|
+
deletePage: async (input) => {
|
|
1657
|
+
if (rows().readOnce) throw new KnowledgeImportRereadRequiredError("deletePage");
|
|
1658
|
+
const page = this.#livePage(input.id);
|
|
1659
|
+
if (page.isScope) throw new Error(`Knowledge scope page ${page.id} can't be deleted`);
|
|
1660
|
+
if (page.version !== input.expectedVersion) throw new require_execution_fence.KnowledgeConflictError(page.id);
|
|
1661
|
+
if (this.#children(page.id).length) throw new require_execution_fence.KnowledgePageHasChildrenError(page.id);
|
|
1662
|
+
const at = now();
|
|
1663
|
+
const deleted = {
|
|
1664
|
+
...page,
|
|
1665
|
+
deletedAt: at,
|
|
1666
|
+
deletedBy: input.deletedBy,
|
|
1667
|
+
version: page.version + 1,
|
|
1668
|
+
updatedAt: at
|
|
1669
|
+
};
|
|
1670
|
+
this.#setPage(page.id, deleted);
|
|
1671
|
+
this.#left(page.parentId, page.position);
|
|
1672
|
+
for (const [key, id] of rows().paths) if (id === page.id) rows().paths.set(key, null);
|
|
1673
|
+
this.#state.writes.push({
|
|
1674
|
+
op: "delete",
|
|
1675
|
+
id: page.id,
|
|
1676
|
+
scopeId: page.scopeId,
|
|
1677
|
+
expectedVersion: input.expectedVersion,
|
|
1678
|
+
deletedBy: input.deletedBy
|
|
1679
|
+
});
|
|
1680
|
+
return structuredClone(deleted);
|
|
1681
|
+
},
|
|
1682
|
+
addNote: async (input) => {
|
|
1683
|
+
const page = this.#livePage(input.pageId);
|
|
1684
|
+
require_execution_fence.assertKnowledgeNoteTextWithinBound(input.text);
|
|
1685
|
+
if (input.mentions.length) throw new KnowledgeImportBatchUnsupportedError("addNote with mentions");
|
|
1686
|
+
const notes = this.#notesOf(page.id);
|
|
1687
|
+
const id = input.id ?? (0, crypto.randomUUID)();
|
|
1688
|
+
if (notes.some((note) => note.id === id)) throw new require_execution_fence.KnowledgeConflictError(id);
|
|
1689
|
+
const at = now();
|
|
1690
|
+
const note = {
|
|
1691
|
+
id,
|
|
1692
|
+
pageId: page.id,
|
|
1693
|
+
text: input.text,
|
|
1694
|
+
...input.when ? { when: new Date(input.when) } : {},
|
|
1695
|
+
stampScopeIds: [...new Set(input.stampScopeIds)],
|
|
1696
|
+
mentions: [],
|
|
1697
|
+
provenance: structuredClone(input.provenance),
|
|
1698
|
+
version: 1,
|
|
1699
|
+
createdAt: at,
|
|
1700
|
+
updatedAt: at
|
|
1701
|
+
};
|
|
1702
|
+
rows().notes.set(page.id, [...notes, note]);
|
|
1703
|
+
this.#state.writes.push({
|
|
1704
|
+
op: "add-note",
|
|
1705
|
+
id,
|
|
1706
|
+
pageId: page.id,
|
|
1707
|
+
scopeId: page.scopeId,
|
|
1708
|
+
text: input.text,
|
|
1709
|
+
...input.when ? { when: input.when } : {},
|
|
1710
|
+
stampScopeIds: input.stampScopeIds,
|
|
1711
|
+
mentions: [],
|
|
1712
|
+
provenance: input.provenance
|
|
1713
|
+
});
|
|
1714
|
+
return structuredClone(note);
|
|
1715
|
+
},
|
|
1716
|
+
removeNote: async (input) => {
|
|
1717
|
+
for (const [pageId, notes] of rows().notes) {
|
|
1718
|
+
const note = notes.find((each) => each.id === input.id);
|
|
1719
|
+
if (!note) continue;
|
|
1720
|
+
if (note.deletedAt) throw new require_execution_fence.KnowledgeNotFoundError("note", input.id);
|
|
1721
|
+
if (this.#state.writes.some((write) => write.op === "add-note" && write.id === input.id)) throw new KnowledgeImportBatchUnsupportedError("removeNote of a note this flush added");
|
|
1722
|
+
const page = this.#livePage(pageId);
|
|
1723
|
+
const at = now();
|
|
1724
|
+
const removed = {
|
|
1725
|
+
...note,
|
|
1726
|
+
deletedAt: at,
|
|
1727
|
+
deletedBy: input.deletedBy,
|
|
1728
|
+
version: note.version + 1,
|
|
1729
|
+
updatedAt: at
|
|
1730
|
+
};
|
|
1731
|
+
rows().notes.set(pageId, notes.map((each) => each.id === input.id ? removed : each));
|
|
1732
|
+
this.#state.writes.push({
|
|
1733
|
+
op: "remove-note",
|
|
1734
|
+
id: input.id,
|
|
1735
|
+
pageId,
|
|
1736
|
+
scopeId: page.scopeId,
|
|
1737
|
+
deletedBy: input.deletedBy,
|
|
1738
|
+
provenance: input.provenance
|
|
1739
|
+
});
|
|
1740
|
+
return structuredClone(removed);
|
|
1741
|
+
}
|
|
1742
|
+
throw new KnowledgeImportBatchUnsupportedError("removeNote of a note not gathered");
|
|
1743
|
+
}
|
|
1744
|
+
};
|
|
1745
|
+
return only(impl, "storage");
|
|
1746
|
+
}
|
|
1747
|
+
#notesOf(pageId) {
|
|
1748
|
+
const { notes } = this.#state.rows;
|
|
1749
|
+
if (!notes.has(pageId)) {
|
|
1750
|
+
this.missing.notes.add(pageId);
|
|
1751
|
+
throw new KnowledgeImportNotGatheredError(`notes of ${pageId}`);
|
|
1752
|
+
}
|
|
1753
|
+
return notes.get(pageId);
|
|
1754
|
+
}
|
|
1755
|
+
#importers() {
|
|
1756
|
+
const rows = () => this.#state.rows;
|
|
1757
|
+
return only({
|
|
1758
|
+
getNode: async (bindingId, sourceId) => structuredClone(this.#node(nodeKey(bindingId, sourceId))),
|
|
1759
|
+
getNodes: async (bindingId, sourceIds) => {
|
|
1760
|
+
const nodes = [];
|
|
1761
|
+
const unread = [...new Set(sourceIds)].filter((sourceId) => !rows().nodes.has(nodeKey(bindingId, sourceId)));
|
|
1762
|
+
if (unread.length) {
|
|
1763
|
+
for (const sourceId of unread) this.missing.nodes.add(nodeKey(bindingId, sourceId));
|
|
1764
|
+
throw new KnowledgeImportNotGatheredError(`nodes ${unread.join(", ")}`);
|
|
1765
|
+
}
|
|
1766
|
+
for (const sourceId of new Set(sourceIds)) {
|
|
1767
|
+
const node = rows().nodes.get(nodeKey(bindingId, sourceId));
|
|
1768
|
+
if (node) nodes.push(structuredClone(node));
|
|
1769
|
+
}
|
|
1770
|
+
return nodes;
|
|
1771
|
+
},
|
|
1772
|
+
getNodeByPage: async (pageId) => {
|
|
1773
|
+
if (!rows().nodesByPage.has(pageId)) {
|
|
1774
|
+
this.missing.nodesByPage.add(pageId);
|
|
1775
|
+
throw new KnowledgeImportNotGatheredError(`node of page ${pageId}`);
|
|
1776
|
+
}
|
|
1777
|
+
const key = rows().nodesByPage.get(pageId);
|
|
1778
|
+
return key ? structuredClone(this.#node(key)) : null;
|
|
1779
|
+
},
|
|
1780
|
+
getNodesByPages: async (pageIds) => {
|
|
1781
|
+
const unread = [...new Set(pageIds)].filter((pageId) => !rows().nodesByPage.has(pageId));
|
|
1782
|
+
if (unread.length) {
|
|
1783
|
+
for (const pageId of unread) this.missing.nodesByPage.add(pageId);
|
|
1784
|
+
throw new KnowledgeImportNotGatheredError(`nodes of pages ${unread.join(", ")}`);
|
|
1785
|
+
}
|
|
1786
|
+
return [...new Set(pageIds)].flatMap((pageId) => {
|
|
1787
|
+
const node = rows().nodesByPage.get(pageId) ? this.#node(rows().nodesByPage.get(pageId)) : null;
|
|
1788
|
+
return node ? [structuredClone(node)] : [];
|
|
1789
|
+
});
|
|
1790
|
+
},
|
|
1791
|
+
saveNode: async (node) => {
|
|
1792
|
+
const key = nodeKey(node.bindingId, node.sourceId);
|
|
1793
|
+
const mapped = rows().nodesByPage.get(node.pageId);
|
|
1794
|
+
if (mapped === void 0) {
|
|
1795
|
+
this.missing.nodesByPage.add(node.pageId);
|
|
1796
|
+
throw new KnowledgeImportNotGatheredError(`node of page ${node.pageId}`);
|
|
1797
|
+
}
|
|
1798
|
+
if (mapped && mapped !== key) throw new KnowledgeImportBatchUnsupportedError("saveNode onto a mapped page");
|
|
1799
|
+
this.#setNode(key, {
|
|
1800
|
+
...structuredClone(node),
|
|
1801
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
1802
|
+
});
|
|
1803
|
+
},
|
|
1804
|
+
deleteNode: async (bindingId, sourceId) => {
|
|
1805
|
+
const key = nodeKey(bindingId, sourceId);
|
|
1806
|
+
this.#node(key);
|
|
1807
|
+
this.#setNode(key, null);
|
|
1808
|
+
},
|
|
1809
|
+
markLinkingNodesUnsettled: async (bindingId, targetSourceIds) => {
|
|
1810
|
+
const targets = new Set(targetSourceIds);
|
|
1811
|
+
for (const [key, node] of rows().nodes) if (node && node.bindingId === bindingId && node.links.some((link) => targets.has(link.sourceId))) rows().nodes.set(key, {
|
|
1812
|
+
...node,
|
|
1813
|
+
unsettled: true
|
|
1814
|
+
});
|
|
1815
|
+
const marks = this.#state.marks;
|
|
1816
|
+
const last = marks.at(-1);
|
|
1817
|
+
const prior = last && markTargets.get(last);
|
|
1818
|
+
const all = prior?.bindingId === bindingId ? [.../* @__PURE__ */ new Set([...prior.targets, ...targetSourceIds])] : [...targetSourceIds];
|
|
1819
|
+
if (prior?.bindingId === bindingId) marks.pop();
|
|
1820
|
+
const mark = (_, importers) => importers.markLinkingNodesUnsettled(bindingId, all);
|
|
1821
|
+
markTargets.set(mark, {
|
|
1822
|
+
bindingId,
|
|
1823
|
+
targets: all
|
|
1824
|
+
});
|
|
1825
|
+
marks.push(mark);
|
|
1826
|
+
},
|
|
1827
|
+
setState: async (bindingId, state) => {
|
|
1828
|
+
this.#state.marks.push((_, importers) => importers.setState(bindingId, state));
|
|
1829
|
+
},
|
|
1830
|
+
listLinkingNodes: async (bindingId, targetSourceIds, options = {}) => {
|
|
1831
|
+
const keys = [...new Set(targetSourceIds)].map((sourceId) => nodeKey(bindingId, sourceId));
|
|
1832
|
+
if (keys.some((key) => rows().tooManyLinkers.has(key))) throw new KnowledgeImportBatchUnsupportedError("listLinkingNodes past the gathered linking nodes");
|
|
1833
|
+
const unread = keys.filter((key) => !rows().linkTargets.has(key));
|
|
1834
|
+
if (unread.length) {
|
|
1835
|
+
for (const key of unread) this.missing.linkTargets.add(key);
|
|
1836
|
+
throw new KnowledgeImportNotGatheredError(`linking nodes of ${unread.join(", ")}`);
|
|
1837
|
+
}
|
|
1838
|
+
const targets = new Set(targetSourceIds);
|
|
1839
|
+
const ids = [...rows().nodes.values()].filter((node) => !!node && node.bindingId === bindingId && node.links.some((link) => targets.has(link.sourceId))).map((node) => node.sourceId).filter((id) => options.after === void 0 || byteOrder(id, options.after) > 0).sort(byteOrder);
|
|
1840
|
+
const limit = options.limit ?? 500;
|
|
1841
|
+
const items = ids.slice(0, limit);
|
|
1842
|
+
return {
|
|
1843
|
+
items,
|
|
1844
|
+
next: ids.length > limit ? items[items.length - 1] : null
|
|
1845
|
+
};
|
|
1846
|
+
},
|
|
1847
|
+
listBindings: async () => {
|
|
1848
|
+
const { bindings } = rows();
|
|
1849
|
+
if (!bindings) {
|
|
1850
|
+
this.missing.bindings.add("bindings");
|
|
1851
|
+
throw new KnowledgeImportNotGatheredError("bindings");
|
|
1852
|
+
}
|
|
1853
|
+
return structuredClone(bindings);
|
|
1854
|
+
}
|
|
1855
|
+
}, "importers");
|
|
1856
|
+
}
|
|
1857
|
+
};
|
|
1858
|
+
/** True when the stores implement every set-based method the batched flush needs. */
|
|
1859
|
+
function canBatchImportFlush(storage, importers) {
|
|
1860
|
+
return !!(storage.getPageChains && storage.getPagesByPaths && storage.getLastChildPositions && storage.listNotesByPages && storage.getPageSubtrees && storage.applyPageWrites && require_execution_fence.canRepairKnowledgeLinksInBatch(storage) && importers.getNodes && importers.getNodesByPages && importers.writeNodes);
|
|
1861
|
+
}
|
|
1862
|
+
async function readImportRows(input) {
|
|
1863
|
+
const { storage, importers, bindingId, missing } = input;
|
|
1864
|
+
const rows = emptyImportOverlayRows();
|
|
1865
|
+
const sourceIds = new Set(input.sourceIds);
|
|
1866
|
+
for (const key of missing?.nodes ?? []) {
|
|
1867
|
+
const [binding, sourceId] = key.split("\0");
|
|
1868
|
+
if (binding === bindingId) sourceIds.add(sourceId);
|
|
1869
|
+
}
|
|
1870
|
+
const nodes = sourceIds.size ? await importers.getNodes(bindingId, [...sourceIds]) : [];
|
|
1871
|
+
for (const sourceId of sourceIds) rows.nodes.set(nodeKey(bindingId, sourceId), null);
|
|
1872
|
+
for (const node of nodes) {
|
|
1873
|
+
rows.nodes.set(nodeKey(node.bindingId, node.sourceId), node);
|
|
1874
|
+
rows.nodesByPage.set(node.pageId, nodeKey(node.bindingId, node.sourceId));
|
|
1875
|
+
}
|
|
1876
|
+
const addChains = async (ids) => {
|
|
1877
|
+
const wanted = [...ids].filter((id) => !rows.pages.has(id));
|
|
1878
|
+
if (!wanted.length) return;
|
|
1879
|
+
const chains = await storage.getPageChains({
|
|
1880
|
+
ids: wanted,
|
|
1881
|
+
read: "all"
|
|
1882
|
+
});
|
|
1883
|
+
for (const id of wanted) {
|
|
1884
|
+
const chain = chains[id] ?? [];
|
|
1885
|
+
if (!chain.length) rows.pages.set(id, null);
|
|
1886
|
+
for (const page of chain) rows.pages.set(page.id, page);
|
|
1887
|
+
const last = chain.at(-1);
|
|
1888
|
+
if (last?.parentId && chain.length <= 10 && !rows.pages.has(last.parentId)) rows.pages.set(last.parentId, null);
|
|
1889
|
+
}
|
|
1890
|
+
};
|
|
1891
|
+
await addChains(/* @__PURE__ */ new Set([
|
|
1892
|
+
...input.pageIds,
|
|
1893
|
+
...nodes.map((node) => node.pageId),
|
|
1894
|
+
...missing?.pages ?? [],
|
|
1895
|
+
...missing?.locks ?? []
|
|
1896
|
+
]));
|
|
1897
|
+
let plan = input.plan(rows);
|
|
1898
|
+
const carried = [];
|
|
1899
|
+
let held = [];
|
|
1900
|
+
let settled = false;
|
|
1901
|
+
for (let stage = 0; stage < GATHER_PLAN_STAGES; stage++) {
|
|
1902
|
+
if (stage) plan = input.plan(rows);
|
|
1903
|
+
const before = rows.pages.size + rows.paths.size + rows.complete.size;
|
|
1904
|
+
const roots = [.../* @__PURE__ */ new Set([...plan.subtrees, ...stage ? [] : missing?.subtrees ?? []])].filter((id) => !rows.complete.has(id) && !rows.tooLarge.has(id));
|
|
1905
|
+
if (roots.length) {
|
|
1906
|
+
const subtrees = await storage.getPageSubtrees({
|
|
1907
|
+
rootIds: roots,
|
|
1908
|
+
limit: 499
|
|
1909
|
+
});
|
|
1910
|
+
for (const root of roots) {
|
|
1911
|
+
const pages = subtrees[root];
|
|
1912
|
+
if (!pages) {
|
|
1913
|
+
rows.tooLarge.add(root);
|
|
1914
|
+
continue;
|
|
1915
|
+
}
|
|
1916
|
+
rows.complete.add(root);
|
|
1917
|
+
for (const page of pages) {
|
|
1918
|
+
rows.pages.set(page.id, page);
|
|
1919
|
+
rows.complete.add(page.id);
|
|
1920
|
+
carried.push(page.id);
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
const unmapped = carried.filter((id) => !rows.nodesByPage.has(id));
|
|
1924
|
+
if (unmapped.length) {
|
|
1925
|
+
for (const id of unmapped) rows.nodesByPage.set(id, null);
|
|
1926
|
+
for (const node of await importers.getNodesByPages(unmapped)) {
|
|
1927
|
+
const key = nodeKey(node.bindingId, node.sourceId);
|
|
1928
|
+
rows.nodes.set(key, node);
|
|
1929
|
+
rows.nodesByPage.set(node.pageId, key);
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
const paths = new Map(plan.paths.map((each) => [pathKey(each.scopeId, each.path), each]));
|
|
1934
|
+
if (!stage) for (const [key, each] of missing?.paths ?? []) paths.set(key, each);
|
|
1935
|
+
for (const key of [...paths.keys()]) if (rows.paths.has(key)) paths.delete(key);
|
|
1936
|
+
const byScope = /* @__PURE__ */ new Map();
|
|
1937
|
+
for (const [key, { scopeId, path }] of paths) {
|
|
1938
|
+
if (path.length === 0) continue;
|
|
1939
|
+
byScope.set(scopeId, [...byScope.get(scopeId) ?? [], {
|
|
1940
|
+
key,
|
|
1941
|
+
path
|
|
1942
|
+
}]);
|
|
1943
|
+
}
|
|
1944
|
+
for (const [scopeId, entries] of byScope) {
|
|
1945
|
+
const found = await storage.getPagesByPaths({
|
|
1946
|
+
scopeId,
|
|
1947
|
+
paths: entries.map((each) => each.path),
|
|
1948
|
+
read: "all"
|
|
1949
|
+
});
|
|
1950
|
+
entries.forEach((each, i) => {
|
|
1951
|
+
const page = found[i] ?? null;
|
|
1952
|
+
rows.paths.set(each.key, page?.id ?? null);
|
|
1953
|
+
if (page && !rows.pages.has(page.id)) rows.pages.set(page.id, page);
|
|
1954
|
+
});
|
|
1955
|
+
}
|
|
1956
|
+
held = [...rows.paths.values()].filter((id) => !!id);
|
|
1957
|
+
await addChains(new Set(held.map((id) => rows.pages.get(id)?.parentId).filter((id) => !!id)));
|
|
1958
|
+
const byPage = [...new Set([
|
|
1959
|
+
...held,
|
|
1960
|
+
...plan.holders ?? [],
|
|
1961
|
+
...stage ? [] : missing?.nodesByPage ?? []
|
|
1962
|
+
].filter((id) => !rows.nodesByPage.has(id)))];
|
|
1963
|
+
if (byPage.length) {
|
|
1964
|
+
for (const id of byPage) rows.nodesByPage.set(id, null);
|
|
1965
|
+
for (const node of await importers.getNodesByPages(byPage)) {
|
|
1966
|
+
const key = nodeKey(node.bindingId, node.sourceId);
|
|
1967
|
+
rows.nodes.set(key, node);
|
|
1968
|
+
rows.nodesByPage.set(node.pageId, key);
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
if (rows.pages.size + rows.paths.size + rows.complete.size === before) {
|
|
1972
|
+
settled = true;
|
|
1973
|
+
break;
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
const targets = new Set(plan.linkTargets);
|
|
1977
|
+
for (const id of carried) {
|
|
1978
|
+
const key = rows.nodesByPage.get(id);
|
|
1979
|
+
const node = key ? rows.nodes.get(key) : null;
|
|
1980
|
+
if (node?.bindingId === bindingId) targets.add(node.sourceId);
|
|
1981
|
+
}
|
|
1982
|
+
for (const key of missing?.linkTargets ?? []) {
|
|
1983
|
+
const [binding, sourceId] = key.split("\0");
|
|
1984
|
+
if (binding === bindingId) targets.add(sourceId);
|
|
1985
|
+
}
|
|
1986
|
+
const wanted = [...targets].filter((sourceId) => !rows.linkTargets.has(nodeKey(bindingId, sourceId)));
|
|
1987
|
+
if (wanted.length) {
|
|
1988
|
+
const linking = await importers.listLinkingNodes(bindingId, wanted, { limit: LINKING_NODES_READ });
|
|
1989
|
+
for (const sourceId of wanted) (linking.next ? rows.tooManyLinkers : rows.linkTargets).add(nodeKey(bindingId, sourceId));
|
|
1990
|
+
const readNodes = async (sourceIds) => {
|
|
1991
|
+
const unread = [...new Set(sourceIds)].filter((sourceId) => !rows.nodes.has(nodeKey(bindingId, sourceId)));
|
|
1992
|
+
if (!unread.length) return [];
|
|
1993
|
+
for (const sourceId of unread) rows.nodes.set(nodeKey(bindingId, sourceId), null);
|
|
1994
|
+
const read = await importers.getNodes(bindingId, unread);
|
|
1995
|
+
for (const node of read) {
|
|
1996
|
+
rows.nodes.set(nodeKey(node.bindingId, node.sourceId), node);
|
|
1997
|
+
rows.nodesByPage.set(node.pageId, nodeKey(node.bindingId, node.sourceId));
|
|
1998
|
+
}
|
|
1999
|
+
return read;
|
|
2000
|
+
};
|
|
2001
|
+
const linkers = await readNodes(linking.items);
|
|
2002
|
+
const reached = await readNodes(linking.items.map((sourceId) => rows.nodes.get(nodeKey(bindingId, sourceId))).filter((n) => !!n).flatMap((node) => [...node.links.map((link) => link.sourceId), ...node.parentSourceId ? [node.parentSourceId] : []]));
|
|
2003
|
+
await addChains(new Set([...linkers, ...reached].map((node) => node.pageId)));
|
|
2004
|
+
}
|
|
2005
|
+
if (plan.bindings || missing?.bindings.size) rows.bindings ??= await importers.listBindings();
|
|
2006
|
+
const notes = [.../* @__PURE__ */ new Set([
|
|
2007
|
+
...plan.notes,
|
|
2008
|
+
...held,
|
|
2009
|
+
...missing?.notes ?? []
|
|
2010
|
+
])];
|
|
2011
|
+
if (notes.length) {
|
|
2012
|
+
const listed = await storage.listNotesByPages({
|
|
2013
|
+
pageIds: notes,
|
|
2014
|
+
read: "all"
|
|
2015
|
+
});
|
|
2016
|
+
for (const id of notes) rows.notes.set(id, listed[id] ?? []);
|
|
2017
|
+
}
|
|
2018
|
+
const positions = [.../* @__PURE__ */ new Set([...plan.positions, ...missing?.positions ?? []])];
|
|
2019
|
+
if (positions.length) {
|
|
2020
|
+
const last = await storage.getLastChildPositions({ parentIds: positions });
|
|
2021
|
+
for (const id of positions) rows.positions.set(id, last[id] ?? null);
|
|
2022
|
+
}
|
|
2023
|
+
rows.inPlace = settled && !!plan.inPlace;
|
|
2024
|
+
return rows;
|
|
2025
|
+
}
|
|
2026
|
+
/** Times one gather plans again from what it read (path folders, then the page at the path, then its children). */
|
|
2027
|
+
const GATHER_PLAN_STAGES = 4;
|
|
2028
|
+
/** Most linking nodes one gather reads; past it, a flush that lists them is saved op by op. */
|
|
2029
|
+
const LINKING_NODES_READ = 500;
|
|
2030
|
+
/** Live, non-scope pages among the rows: the ones a decide pass may lock. */
|
|
2031
|
+
const lockable = (rows) => [...rows.pages.values()].filter((page) => !!page && !page.isScope && !page.deletedAt && !page.mergedInto).map((page) => page.id);
|
|
2032
|
+
/**
|
|
2033
|
+
* Reads every row a decide pass needs in a few set-based queries, locks the live pages among them
|
|
2034
|
+
* in one sorted call, and reads again under the lock: what the second read returns can't change
|
|
2035
|
+
* until commit (a new page at an empty path is refused by the unique key when written). Pages the
|
|
2036
|
+
* second read finds that the first didn't are locked too, and read again, up to `rounds` times.
|
|
2037
|
+
*/
|
|
2038
|
+
async function gatherImportRows(input) {
|
|
2039
|
+
const locked = new Set(input.locked ?? []);
|
|
2040
|
+
let rows = await readImportRows(input);
|
|
2041
|
+
if (input.storage.getCapabilities().serializedWriteTransactions && rows.notes.size === 0) {
|
|
2042
|
+
for (const id of lockable(rows)) locked.add(id);
|
|
2043
|
+
rows.locked = locked;
|
|
2044
|
+
return rows;
|
|
2045
|
+
}
|
|
2046
|
+
for (let round = 0; round < (input.rounds ?? 3); round++) {
|
|
2047
|
+
const unlocked = lockable(rows).filter((id) => !locked.has(id));
|
|
2048
|
+
if (!unlocked.length) {
|
|
2049
|
+
rows.locked = locked;
|
|
2050
|
+
return rows;
|
|
2051
|
+
}
|
|
2052
|
+
const versions = await input.storage.lockPages(unlocked.sort());
|
|
2053
|
+
for (const id of unlocked) locked.add(id);
|
|
2054
|
+
if (round === 0 && !input.reread && rows.inPlace && rows.notes.size === 0 && Array.isArray(versions) && versions.length === unlocked.length) {
|
|
2055
|
+
const read = new Map(versions.map((row) => [row.id, row.version]));
|
|
2056
|
+
if (unlocked.every((id) => read.get(id) === rows.pages.get(id)?.version)) {
|
|
2057
|
+
rows.locked = locked;
|
|
2058
|
+
rows.readOnce = true;
|
|
2059
|
+
return rows;
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
rows = await readImportRows(input);
|
|
2063
|
+
}
|
|
2064
|
+
return null;
|
|
2065
|
+
}
|
|
1036
2066
|
// src/knowledge/importers/sink.ts
|
|
1037
2067
|
/**
|
|
1038
2068
|
* Applies one flush's ops to pages and the node map, on a transaction view. Pages are found by id
|
|
@@ -1089,6 +2119,17 @@ const ownText = (body, section) => {
|
|
|
1089
2119
|
if (body === section) return "";
|
|
1090
2120
|
return body.endsWith(`\n\n${section}`) ? body.slice(0, body.length - section.length - 2) : null;
|
|
1091
2121
|
};
|
|
2122
|
+
/** Decide passes a batched flush makes before it falls back: each reads what the last one lacked. */
|
|
2123
|
+
const BATCH_DECIDE_PASSES = 4;
|
|
2124
|
+
/** The batched flush can't land this one: its savepoint rolls back and the ops go one by one. */
|
|
2125
|
+
var BatchFallback = class extends Error {
|
|
2126
|
+
reason;
|
|
2127
|
+
constructor(reason) {
|
|
2128
|
+
super(`Batched import flush fell back: ${reason}`);
|
|
2129
|
+
this.reason = reason;
|
|
2130
|
+
this.name = "BatchFallback";
|
|
2131
|
+
}
|
|
2132
|
+
};
|
|
1092
2133
|
/** A per-item refusal: its savepoint rolls back and the flush goes on. */
|
|
1093
2134
|
var KnowledgeImportRefusalError = class extends Error {
|
|
1094
2135
|
reason;
|
|
@@ -1118,6 +2159,47 @@ function knowledgeImportKey(sourceId) {
|
|
|
1118
2159
|
return sourceId.replace(/[/#%:~]/g, (char) => `~${char.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
1119
2160
|
}
|
|
1120
2161
|
const live = (page) => !!page && !page.deletedAt && !page.mergedInto;
|
|
2162
|
+
/** Source IDs the host keeps for the folders it makes on an item's path; importers can't send them. */
|
|
2163
|
+
const KNOWLEDGE_IMPORT_PATH_STUB_PREFIX = "~path:";
|
|
2164
|
+
/**
|
|
2165
|
+
* An item's description cut to the page bound, ending in `…`. Every store refuses a longer one, and
|
|
2166
|
+
* that error would roll back the whole flush, leaving the cursor on this item for every later run.
|
|
2167
|
+
* Cuts between code points, at the last word break when one is in the back half.
|
|
2168
|
+
*/
|
|
2169
|
+
function fitKnowledgeImportDescription(description) {
|
|
2170
|
+
if (require_workspace.estimateTokenCount(description) <= 100) return description;
|
|
2171
|
+
const chars = [...description];
|
|
2172
|
+
const cut = (length) => {
|
|
2173
|
+
let text = chars.slice(0, length).join("");
|
|
2174
|
+
const lastBreak = text.search(/\s\S*$/);
|
|
2175
|
+
if (lastBreak > text.length / 2) text = text.slice(0, lastBreak);
|
|
2176
|
+
return `${text.trimEnd()}\u2026`;
|
|
2177
|
+
};
|
|
2178
|
+
let low = 0;
|
|
2179
|
+
let high = chars.length - 1;
|
|
2180
|
+
while (low < high) {
|
|
2181
|
+
const mid = Math.ceil((low + high) / 2);
|
|
2182
|
+
if (require_workspace.estimateTokenCount(cut(mid)) <= 100) low = mid;
|
|
2183
|
+
else high = mid - 1;
|
|
2184
|
+
}
|
|
2185
|
+
return cut(low);
|
|
2186
|
+
}
|
|
2187
|
+
/**
|
|
2188
|
+
* Why an item can never land, whatever the store holds: a reserved `sourceId`, or a `path` the host
|
|
2189
|
+
* can't place (with `parent` or `fallbackParent`, empty, an empty or blank segment, a page key too long to
|
|
2190
|
+
* link to, or deeper than a page can sit under a target `targetDepth` keys deep). Null when it can.
|
|
2191
|
+
*/
|
|
2192
|
+
function knowledgeImportItemProblem(item, targetDepth) {
|
|
2193
|
+
if (item.sourceId.startsWith("~path:")) return `sourceId must not start with "${KNOWLEDGE_IMPORT_PATH_STUB_PREFIX}"`;
|
|
2194
|
+
const { path } = item;
|
|
2195
|
+
if (path === void 0) return null;
|
|
2196
|
+
if (item.parent != null || item.fallbackParent !== void 0) return "path is not allowed with parent or fallbackParent";
|
|
2197
|
+
if (path.length === 0) return "path must have at least one segment";
|
|
2198
|
+
if (path.some((segment) => !segment.trim())) return "path segments must not be empty or blank";
|
|
2199
|
+
if (path.some((segment) => knowledgeImportKey(segment).length > 512)) return `path segment keys must be at most 512 characters`;
|
|
2200
|
+
if (targetDepth + path.length > 10) return `path would sit more than 10 levels below the scope`;
|
|
2201
|
+
return null;
|
|
2202
|
+
}
|
|
1121
2203
|
/** Core errors that mean "this op can't land here", by name: an adapter may carry its own core copy. */
|
|
1122
2204
|
function refusalFor(error) {
|
|
1123
2205
|
if (error instanceof KnowledgeImportRefusalError) return error.reason;
|
|
@@ -1142,7 +2224,7 @@ async function syncLinks(work) {
|
|
|
1142
2224
|
try {
|
|
1143
2225
|
await work();
|
|
1144
2226
|
} catch (error) {
|
|
1145
|
-
if (error instanceof
|
|
2227
|
+
if (error instanceof require_execution_fence.KnowledgeUnsupportedCapabilityError || error instanceof require_execution_fence.KnowledgeLinkRefreshIncompleteError) return;
|
|
1146
2228
|
throw error;
|
|
1147
2229
|
}
|
|
1148
2230
|
}
|
|
@@ -1153,11 +2235,17 @@ function order(ops) {
|
|
|
1153
2235
|
const id = op.op === "remove" ? op.sourceId : op.item.sourceId;
|
|
1154
2236
|
const before = last.get(id);
|
|
1155
2237
|
if (op.op === "declare" && before?.op === "upsert") {
|
|
2238
|
+
const { parent, fallbackParent, path, ...rest } = before.item;
|
|
2239
|
+
const kept = op.item.path !== void 0 ? rest : op.item.parent !== void 0 || op.item.fallbackParent !== void 0 ? {
|
|
2240
|
+
...rest,
|
|
2241
|
+
...parent !== void 0 ? { parent } : {},
|
|
2242
|
+
...fallbackParent !== void 0 ? { fallbackParent } : {}
|
|
2243
|
+
} : before.item;
|
|
1156
2244
|
last.delete(id);
|
|
1157
2245
|
last.set(id, {
|
|
1158
2246
|
op: "upsert",
|
|
1159
2247
|
item: {
|
|
1160
|
-
...
|
|
2248
|
+
...kept,
|
|
1161
2249
|
...op.item
|
|
1162
2250
|
}
|
|
1163
2251
|
});
|
|
@@ -1184,7 +2272,27 @@ function order(ops) {
|
|
|
1184
2272
|
return [...sorted, ...removes];
|
|
1185
2273
|
}
|
|
1186
2274
|
async function applyKnowledgeImportFlush(input) {
|
|
1187
|
-
const {
|
|
2275
|
+
const { binding, scope, provenance } = input;
|
|
2276
|
+
let { storage, importers } = input;
|
|
2277
|
+
let overlay = null;
|
|
2278
|
+
/**
|
|
2279
|
+
* Link-index work for a written page: a sync of its body links, then maybe a refresh of the links to
|
|
2280
|
+
* it. Run now, or after the batched write in one repair when deciding over the working copy.
|
|
2281
|
+
*/
|
|
2282
|
+
const links = async (sync, refresh) => {
|
|
2283
|
+
if (overlay) {
|
|
2284
|
+
if (sync) overlay.deferLinks({ sync });
|
|
2285
|
+
for (const page of refresh?.pages ?? []) overlay.deferLinks({
|
|
2286
|
+
refresh: page,
|
|
2287
|
+
withDescendants: !!refresh.withDescendants
|
|
2288
|
+
});
|
|
2289
|
+
return;
|
|
2290
|
+
}
|
|
2291
|
+
await syncLinks(async () => {
|
|
2292
|
+
if (sync) await require_execution_fence.syncKnowledgePageBodyLinks(storage, sync);
|
|
2293
|
+
if (refresh) await require_execution_fence.refreshKnowledgeLinksTo(storage, refresh.pages, { withDescendants: refresh.withDescendants });
|
|
2294
|
+
});
|
|
2295
|
+
};
|
|
1188
2296
|
const target = parseKnowledgeImportTarget(binding.target);
|
|
1189
2297
|
const result = {
|
|
1190
2298
|
counts: {
|
|
@@ -1201,7 +2309,19 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
1201
2309
|
embeds: [],
|
|
1202
2310
|
applied: false
|
|
1203
2311
|
};
|
|
1204
|
-
const
|
|
2312
|
+
const rekey = !!storage.getCapabilities().supportsPageRekey;
|
|
2313
|
+
let ops = order(input.ops).filter((op) => {
|
|
2314
|
+
const sourceId = op.op === "remove" ? op.sourceId : op.item.sourceId;
|
|
2315
|
+
const problem = op.op === "remove" ? sourceId.startsWith(KNOWLEDGE_IMPORT_PATH_STUB_PREFIX) : !!knowledgeImportItemProblem(op.item, 1);
|
|
2316
|
+
const unplaceable = op.op !== "remove" && op.item.path !== void 0 && !rekey;
|
|
2317
|
+
if (!problem && !unplaceable) return true;
|
|
2318
|
+
if (!problem) result.pathsUnsupported = true;
|
|
2319
|
+
result.refused.push({
|
|
2320
|
+
sourceId,
|
|
2321
|
+
reason: "invalid"
|
|
2322
|
+
});
|
|
2323
|
+
return false;
|
|
2324
|
+
});
|
|
1205
2325
|
if (ops.length === 0 && !(input.settle && binding.anchorPageId)) {
|
|
1206
2326
|
if (input.settle) result.settle = {
|
|
1207
2327
|
pending: false,
|
|
@@ -1214,9 +2334,11 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
1214
2334
|
const keyPath = async (page) => {
|
|
1215
2335
|
const keys = [];
|
|
1216
2336
|
const ids = [];
|
|
2337
|
+
const versions = [];
|
|
1217
2338
|
if (page.isScope) return page.id === scope.id ? {
|
|
1218
2339
|
keys,
|
|
1219
|
-
ids
|
|
2340
|
+
ids,
|
|
2341
|
+
versions
|
|
1220
2342
|
} : null;
|
|
1221
2343
|
const parents = page.parentId ? await storage.getPageParents({
|
|
1222
2344
|
parentId: page.parentId,
|
|
@@ -1225,11 +2347,13 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
1225
2347
|
for (const at of [page, ...parents]) {
|
|
1226
2348
|
if (at.isScope) return at.id === scope.id ? {
|
|
1227
2349
|
keys,
|
|
1228
|
-
ids
|
|
2350
|
+
ids,
|
|
2351
|
+
versions
|
|
1229
2352
|
} : null;
|
|
1230
2353
|
if (!live(at) || at.key === void 0) return null;
|
|
1231
2354
|
keys.unshift(at.key);
|
|
1232
2355
|
ids.unshift(at.id);
|
|
2356
|
+
versions.unshift(at.version);
|
|
1233
2357
|
}
|
|
1234
2358
|
return null;
|
|
1235
2359
|
};
|
|
@@ -1262,8 +2386,17 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
1262
2386
|
read: "all"
|
|
1263
2387
|
});
|
|
1264
2388
|
const path = live(page) ? await keyPath(page) : null;
|
|
2389
|
+
if (page && path && storage.getCapabilities().serializedWriteTransactions) return {
|
|
2390
|
+
page,
|
|
2391
|
+
keys: path.keys
|
|
2392
|
+
};
|
|
1265
2393
|
if (page && path) {
|
|
1266
|
-
|
|
2394
|
+
const read = new Map(path.ids.map((id, i) => [id, path.versions[i]]));
|
|
2395
|
+
const locked = await storage.lockPages(path.ids);
|
|
2396
|
+
if (Array.isArray(locked) && locked.length === read.size && locked.every((row) => read.get(row.id) === row.version)) return {
|
|
2397
|
+
page,
|
|
2398
|
+
keys: path.keys
|
|
2399
|
+
};
|
|
1267
2400
|
const fresh = await storage.getPage({
|
|
1268
2401
|
id: page.id,
|
|
1269
2402
|
read: "all"
|
|
@@ -1344,6 +2477,15 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
1344
2477
|
return result;
|
|
1345
2478
|
}
|
|
1346
2479
|
const anchorPath = anchor?.keys ?? [];
|
|
2480
|
+
ops = ops.filter((op) => {
|
|
2481
|
+
if (op.op === "remove" || !op.item.path) return true;
|
|
2482
|
+
if (anchorPath.length + op.item.path.length <= 10) return true;
|
|
2483
|
+
result.refused.push({
|
|
2484
|
+
sourceId: op.item.sourceId,
|
|
2485
|
+
reason: "invalid"
|
|
2486
|
+
});
|
|
2487
|
+
return false;
|
|
2488
|
+
});
|
|
1347
2489
|
/**
|
|
1348
2490
|
* A page this binding owns, checked after locking: live, in the target's scope, mapped back to the
|
|
1349
2491
|
* node. A person may have moved it out of the anchor, under anyone's pages: it is still the
|
|
@@ -1436,13 +2578,97 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
1436
2578
|
});
|
|
1437
2579
|
await importers.markLinkingNodesUnsettled(binding.id, [node.sourceId]);
|
|
1438
2580
|
await importers.deleteNode(binding.id, node.sourceId);
|
|
1439
|
-
if (old) await
|
|
2581
|
+
if (old) await links(null, { pages: [old] });
|
|
1440
2582
|
};
|
|
1441
2583
|
const liveNodeOf = async (sourceId) => {
|
|
1442
2584
|
const node = await nodeOf(sourceId);
|
|
1443
2585
|
return node && await stateOf(node) === "live" ? node : null;
|
|
1444
2586
|
};
|
|
1445
2587
|
const ref = (keys) => `${target.scope}#${keys.join("/")}`;
|
|
2588
|
+
/** The folders an op's path made, counted as created once the op lands. */
|
|
2589
|
+
let madeFolders = [];
|
|
2590
|
+
/**
|
|
2591
|
+
* The page a path item goes under: the anchor, then each segment but the last. A live page at a
|
|
2592
|
+
* segment is used as it is, whoever wrote it; a missing one (a merged page reads as missing, as a
|
|
2593
|
+
* merged parent does for a new child) becomes an empty folder this binding owns, keyed
|
|
2594
|
+
* `~path:<keys>`, that the item sending that path takes over. Returns the node the item is under,
|
|
2595
|
+
* when it is this binding's.
|
|
2596
|
+
*/
|
|
2597
|
+
const pathFolders = async (path) => {
|
|
2598
|
+
let at = anchor;
|
|
2599
|
+
let parentSourceId = null;
|
|
2600
|
+
let holderOf = null;
|
|
2601
|
+
const readHolder = async () => {
|
|
2602
|
+
if (!holderOf) return;
|
|
2603
|
+
const holder = await importers.getNodeByPage(holderOf.id);
|
|
2604
|
+
parentSourceId = holder?.bindingId === binding.id ? holder.sourceId : null;
|
|
2605
|
+
holderOf = null;
|
|
2606
|
+
};
|
|
2607
|
+
const relative = [];
|
|
2608
|
+
for (const segment of path.slice(0, -1)) {
|
|
2609
|
+
const key = knowledgeImportKey(segment);
|
|
2610
|
+
relative.push(key);
|
|
2611
|
+
const keys = [...at.keys, key];
|
|
2612
|
+
const found = await storage.getPageByPath({
|
|
2613
|
+
scopeId: scope.id,
|
|
2614
|
+
path: keys,
|
|
2615
|
+
read: "all"
|
|
2616
|
+
});
|
|
2617
|
+
if (found) {
|
|
2618
|
+
await storage.lockPages([found.id]);
|
|
2619
|
+
const fresh = await storage.getPage({
|
|
2620
|
+
id: found.id,
|
|
2621
|
+
read: "all"
|
|
2622
|
+
});
|
|
2623
|
+
if (!live(fresh) || fresh.parentId !== at.page.id || fresh.key !== key) throw new KnowledgeImportRefusalError("conflict");
|
|
2624
|
+
holderOf = fresh;
|
|
2625
|
+
at = {
|
|
2626
|
+
page: fresh,
|
|
2627
|
+
keys
|
|
2628
|
+
};
|
|
2629
|
+
continue;
|
|
2630
|
+
}
|
|
2631
|
+
await readHolder();
|
|
2632
|
+
const sourceId = KNOWLEDGE_IMPORT_PATH_STUB_PREFIX + relative.join("/");
|
|
2633
|
+
const page = await storage.createPage({
|
|
2634
|
+
parentId: at.page.id,
|
|
2635
|
+
key,
|
|
2636
|
+
name: segment,
|
|
2637
|
+
body: "",
|
|
2638
|
+
provenance
|
|
2639
|
+
});
|
|
2640
|
+
await importers.saveNode({
|
|
2641
|
+
bindingId: binding.id,
|
|
2642
|
+
sourceId,
|
|
2643
|
+
pageId: page.id,
|
|
2644
|
+
kind: null,
|
|
2645
|
+
parentSourceId,
|
|
2646
|
+
aliases: [],
|
|
2647
|
+
unresolvedLinks: [],
|
|
2648
|
+
links: [],
|
|
2649
|
+
linkSection: null,
|
|
2650
|
+
stub: false,
|
|
2651
|
+
adopted: false,
|
|
2652
|
+
unsettled: false
|
|
2653
|
+
});
|
|
2654
|
+
await links(page, { pages: [page] });
|
|
2655
|
+
madeFolders.push({
|
|
2656
|
+
sourceId,
|
|
2657
|
+
page,
|
|
2658
|
+
keys
|
|
2659
|
+
});
|
|
2660
|
+
parentSourceId = sourceId;
|
|
2661
|
+
at = {
|
|
2662
|
+
page,
|
|
2663
|
+
keys
|
|
2664
|
+
};
|
|
2665
|
+
}
|
|
2666
|
+
await readHolder();
|
|
2667
|
+
return {
|
|
2668
|
+
destination: at,
|
|
2669
|
+
parentSourceId
|
|
2670
|
+
};
|
|
2671
|
+
};
|
|
1446
2672
|
const linkLine = async (link, node) => {
|
|
1447
2673
|
const page = node ? await storage.getPage({
|
|
1448
2674
|
id: node.pageId,
|
|
@@ -1523,7 +2749,7 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
1523
2749
|
body,
|
|
1524
2750
|
provenance
|
|
1525
2751
|
});
|
|
1526
|
-
await
|
|
2752
|
+
await links(page);
|
|
1527
2753
|
return {
|
|
1528
2754
|
page,
|
|
1529
2755
|
changed: true,
|
|
@@ -1548,11 +2774,11 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
1548
2774
|
* and the pages it rewrote; the caller counts them once its op lands.
|
|
1549
2775
|
*/
|
|
1550
2776
|
let deferredLinkers = false;
|
|
1551
|
-
const moveOwned = async (self, page, parent) => {
|
|
2777
|
+
const moveOwned = async (self, page, parent, key) => {
|
|
1552
2778
|
const targets = [];
|
|
1553
2779
|
const othersTargets = /* @__PURE__ */ new Map();
|
|
1554
2780
|
await storage.lockSubtree(page.id);
|
|
1555
|
-
for (const p of await
|
|
2781
|
+
for (const p of await require_execution_fence.knowledgeSubtree(storage, page)) {
|
|
1556
2782
|
const node = await importers.getNodeByPage(p.id);
|
|
1557
2783
|
if (!node) continue;
|
|
1558
2784
|
if (node.bindingId === binding.id) targets.push(node.sourceId);
|
|
@@ -1562,6 +2788,7 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
1562
2788
|
id: page.id,
|
|
1563
2789
|
expectedVersion: page.version,
|
|
1564
2790
|
parentId: parent.page.id,
|
|
2791
|
+
...key !== void 0 && key !== page.key ? { key } : {},
|
|
1565
2792
|
provenance
|
|
1566
2793
|
});
|
|
1567
2794
|
const keys = [...parent.keys, moved.key];
|
|
@@ -1617,6 +2844,97 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
1617
2844
|
});
|
|
1618
2845
|
}
|
|
1619
2846
|
};
|
|
2847
|
+
/**
|
|
2848
|
+
* Frees `key` under `destination` for a path item's own page to move onto. A folder of this binding's
|
|
2849
|
+
* that holds the path is absorbed: its children move under the item's page in order, their nodes
|
|
2850
|
+
* point at the item, a body a person wrote in it is kept in a note on the item's page, and the empty
|
|
2851
|
+
* folder goes. A folder someone left notes on, or whose body would replace a body the item's page
|
|
2852
|
+
* already keeps, is not absorbed: the item is refused `occupied`, as for any other page at the path.
|
|
2853
|
+
* An item inside the folder, sent at the folder's path, leaves it first under a key no item uses, so
|
|
2854
|
+
* it never moves under itself; the move after this one gives it the folder's key. Returns whether it
|
|
2855
|
+
* kept a body (the item then holds a person's text, so its removal gives that back) and the item's
|
|
2856
|
+
* page as it is now.
|
|
2857
|
+
*/
|
|
2858
|
+
const absorbAt = async (self, destination, key, page) => {
|
|
2859
|
+
const held = await storage.getPageByPath({
|
|
2860
|
+
scopeId: scope.id,
|
|
2861
|
+
path: [...destination.keys, key],
|
|
2862
|
+
read: "all"
|
|
2863
|
+
});
|
|
2864
|
+
if (!held || held.id === page.id) return {
|
|
2865
|
+
kept: false,
|
|
2866
|
+
page
|
|
2867
|
+
};
|
|
2868
|
+
await storage.lockPages([held.id]);
|
|
2869
|
+
const stub = await storage.getPage({
|
|
2870
|
+
id: held.id,
|
|
2871
|
+
read: "all"
|
|
2872
|
+
});
|
|
2873
|
+
if (!live(stub) || stub.parentId !== destination.page.id || stub.key !== key) throw new KnowledgeImportRefusalError("occupied");
|
|
2874
|
+
const holder = await importers.getNodeByPage(stub.id);
|
|
2875
|
+
if (holder?.bindingId !== binding.id || !holder.sourceId.startsWith("~path:")) throw new KnowledgeImportRefusalError("occupied");
|
|
2876
|
+
if ((await storage.listNotes({
|
|
2877
|
+
pageId: stub.id,
|
|
2878
|
+
read: "all",
|
|
2879
|
+
limit: 1
|
|
2880
|
+
})).notes.length > 0) throw new KnowledgeImportRefusalError("occupied");
|
|
2881
|
+
if (stub.body && (await keptBodyNotes(page.id)).length > 0) throw new KnowledgeImportRefusalError("occupied");
|
|
2882
|
+
const children = [];
|
|
2883
|
+
let cursor;
|
|
2884
|
+
do {
|
|
2885
|
+
const out = await storage.listChildPages({
|
|
2886
|
+
parentId: stub.id,
|
|
2887
|
+
read: "all",
|
|
2888
|
+
...cursor ? { cursor } : {}
|
|
2889
|
+
});
|
|
2890
|
+
children.push(...out.pages);
|
|
2891
|
+
cursor = out.nextCursor;
|
|
2892
|
+
} while (cursor);
|
|
2893
|
+
let inside = page.parentId;
|
|
2894
|
+
while (inside && inside !== stub.id) inside = (await storage.getPage({
|
|
2895
|
+
id: inside,
|
|
2896
|
+
read: "all"
|
|
2897
|
+
}))?.parentId ?? null;
|
|
2898
|
+
if (inside) {
|
|
2899
|
+
await storage.lockSubtree(page.id);
|
|
2900
|
+
page = await storage.movePage({
|
|
2901
|
+
id: page.id,
|
|
2902
|
+
expectedVersion: page.version,
|
|
2903
|
+
parentId: destination.page.id,
|
|
2904
|
+
key: `~absorbing-${(0, crypto.randomUUID)()}`,
|
|
2905
|
+
provenance
|
|
2906
|
+
});
|
|
2907
|
+
}
|
|
2908
|
+
for (const child of children.filter((child) => child.id !== page.id)) {
|
|
2909
|
+
await storage.lockSubtree(child.id);
|
|
2910
|
+
await storage.movePage({
|
|
2911
|
+
id: child.id,
|
|
2912
|
+
expectedVersion: child.version,
|
|
2913
|
+
parentId: page.id,
|
|
2914
|
+
provenance
|
|
2915
|
+
});
|
|
2916
|
+
const node = await importers.getNodeByPage(child.id);
|
|
2917
|
+
if (node?.bindingId === binding.id && node.parentSourceId === holder.sourceId) await importers.saveNode({
|
|
2918
|
+
...node,
|
|
2919
|
+
parentSourceId: self
|
|
2920
|
+
});
|
|
2921
|
+
}
|
|
2922
|
+
if (stub.body) await keepBody(page.id, stub.body);
|
|
2923
|
+
const emptied = await storage.getPage({
|
|
2924
|
+
id: stub.id,
|
|
2925
|
+
read: "all"
|
|
2926
|
+
});
|
|
2927
|
+
await storage.deletePage({
|
|
2928
|
+
id: stub.id,
|
|
2929
|
+
expectedVersion: emptied.version,
|
|
2930
|
+
deletedBy: provenance.author
|
|
2931
|
+
});
|
|
2932
|
+
await importers.deleteNode(binding.id, holder.sourceId);
|
|
2933
|
+
return {
|
|
2934
|
+
kept: !!stub.body,
|
|
2935
|
+
page
|
|
2936
|
+
};
|
|
2937
|
+
};
|
|
1620
2938
|
const write = async (item, hasBody) => {
|
|
1621
2939
|
let existing = await importers.getNode(binding.id, item.sourceId);
|
|
1622
2940
|
const state = existing ? await stateOf(existing) : null;
|
|
@@ -1631,15 +2949,26 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
1631
2949
|
const parentMerged = parentState === "merged";
|
|
1632
2950
|
const misplaced = !!item.parent && !sourceParent && !parentMerged;
|
|
1633
2951
|
const parentNode = sourceParent ?? await liveNodeOf(item.fallbackParent);
|
|
1634
|
-
|
|
2952
|
+
let destination = parentNode ? await owned(parentNode.pageId, parentNode.sourceId) : anchor;
|
|
2953
|
+
let key = knowledgeImportKey(item.sourceId);
|
|
2954
|
+
let parentSourceId = item.parent ?? null;
|
|
2955
|
+
if (item.path) {
|
|
2956
|
+
const current = existing ? await owned(existing.pageId, item.sourceId) : null;
|
|
2957
|
+
if (current?.outside) {
|
|
2958
|
+
key = current.page.key;
|
|
2959
|
+
parentSourceId = existing.parentSourceId;
|
|
2960
|
+
} else {
|
|
2961
|
+
({destination, parentSourceId} = await pathFolders(item.path));
|
|
2962
|
+
key = knowledgeImportKey(item.path.at(-1));
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
1635
2965
|
if (existing && destination.page.id === existing.pageId) throw new KnowledgeImportRefusalError("invalid");
|
|
1636
2966
|
let rendered = hasBody ? await renderBody(item) : void 0;
|
|
1637
2967
|
let fields = {
|
|
1638
2968
|
name: item.title,
|
|
1639
|
-
...item.description !== void 0 ? { description: item.description } : {},
|
|
2969
|
+
...item.description !== void 0 ? { description: fitKnowledgeImportDescription(item.description) } : {},
|
|
1640
2970
|
...rendered ? { body: rendered.body } : {}
|
|
1641
2971
|
};
|
|
1642
|
-
const key = knowledgeImportKey(item.sourceId);
|
|
1643
2972
|
let page;
|
|
1644
2973
|
let change;
|
|
1645
2974
|
let moved = false;
|
|
@@ -1659,9 +2988,34 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
1659
2988
|
read: "all"
|
|
1660
2989
|
});
|
|
1661
2990
|
if (!live(fresh) || fresh.parentId !== destination.page.id || fresh.key !== key) throw new KnowledgeImportRefusalError("occupied");
|
|
1662
|
-
const
|
|
2991
|
+
const holder = await importers.getNodeByPage(fresh.id);
|
|
1663
2992
|
renamed = fields.name !== fresh.name;
|
|
1664
|
-
if (
|
|
2993
|
+
if (holder?.bindingId === binding.id) {
|
|
2994
|
+
if (!holder.sourceId.startsWith("~path:")) throw new KnowledgeImportRefusalError("occupied");
|
|
2995
|
+
const childIds = [];
|
|
2996
|
+
let cursor;
|
|
2997
|
+
do {
|
|
2998
|
+
const out = await storage.listChildPages({
|
|
2999
|
+
parentId: fresh.id,
|
|
3000
|
+
read: "all",
|
|
3001
|
+
...cursor ? { cursor } : {}
|
|
3002
|
+
});
|
|
3003
|
+
childIds.push(...out.pages.map((child) => child.id));
|
|
3004
|
+
cursor = out.nextCursor;
|
|
3005
|
+
} while (cursor);
|
|
3006
|
+
const childNodes = importers.getNodesByPages ? await importers.getNodesByPages(childIds) : (await Promise.all(childIds.map((id) => importers.getNodeByPage(id)))).filter((n) => !!n);
|
|
3007
|
+
await importers.deleteNode(binding.id, holder.sourceId);
|
|
3008
|
+
for (const child of childNodes) if (child.bindingId === binding.id && child.parentSourceId === holder.sourceId) await importers.saveNode({
|
|
3009
|
+
...child,
|
|
3010
|
+
parentSourceId: item.sourceId
|
|
3011
|
+
});
|
|
3012
|
+
if (fresh.body) await keepBody(fresh.id, fresh.body);
|
|
3013
|
+
adopted = !!fresh.body;
|
|
3014
|
+
} else {
|
|
3015
|
+
await release(fresh.id);
|
|
3016
|
+
if (!holder) await keepBody(fresh.id, fresh.body ?? "");
|
|
3017
|
+
adopted = true;
|
|
3018
|
+
}
|
|
1665
3019
|
page = await storage.updatePage({
|
|
1666
3020
|
id: fresh.id,
|
|
1667
3021
|
expectedVersion: fresh.version,
|
|
@@ -1669,7 +3023,6 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
1669
3023
|
provenance
|
|
1670
3024
|
});
|
|
1671
3025
|
change = "updated";
|
|
1672
|
-
adopted = true;
|
|
1673
3026
|
} else if (!existing) {
|
|
1674
3027
|
page = await storage.createPage({
|
|
1675
3028
|
parentId: destination.page.id,
|
|
@@ -1683,9 +3036,15 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
1683
3036
|
const current = await owned(existing.pageId, item.sourceId);
|
|
1684
3037
|
page = current.page;
|
|
1685
3038
|
if (existing.stub && existing.adopted && !REMOVED_BODIES.has(page.body ?? "")) await keepBody(page.id, page.body ?? "");
|
|
1686
|
-
|
|
3039
|
+
const rekey = !!item.path && !current.outside && page.key !== key;
|
|
3040
|
+
if (!current.outside && !parentMerged && (page.parentId !== destination.page.id || rekey)) {
|
|
1687
3041
|
if (destination.keys.length > current.keys.length && sameKeys(destination.keys.slice(0, current.keys.length), current.keys)) throw new KnowledgeImportRefusalError("invalid");
|
|
1688
|
-
|
|
3042
|
+
if (item.path) {
|
|
3043
|
+
const absorbed = await absorbAt(item.sourceId, destination, key, page);
|
|
3044
|
+
page = absorbed.page;
|
|
3045
|
+
if (absorbed.kept) adopted = true;
|
|
3046
|
+
}
|
|
3047
|
+
({page, relinked} = await moveOwned(item.sourceId, page, destination, item.path ? key : void 0));
|
|
1689
3048
|
moved = true;
|
|
1690
3049
|
if (hasBody) {
|
|
1691
3050
|
rendered = await renderBody(item);
|
|
@@ -1722,7 +3081,7 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
1722
3081
|
sourceId: item.sourceId,
|
|
1723
3082
|
pageId: page.id,
|
|
1724
3083
|
kind: item.kind ?? existing?.kind ?? null,
|
|
1725
|
-
parentSourceId
|
|
3084
|
+
parentSourceId,
|
|
1726
3085
|
aliases: item.aliases ?? existing?.aliases ?? [],
|
|
1727
3086
|
unresolvedLinks: rendered ? rendered.unresolved : existing?.unresolvedLinks ?? [],
|
|
1728
3087
|
links: rendered ? rendered.links : existing?.links ?? [],
|
|
@@ -1731,10 +3090,10 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
1731
3090
|
adopted,
|
|
1732
3091
|
unsettled: misplaced || (rendered ? rendered.unresolved : existing?.unresolvedLinks ?? []).length > 0
|
|
1733
3092
|
});
|
|
1734
|
-
if (change !== "unchanged" || existing?.stub) await
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
});
|
|
3093
|
+
if (change !== "unchanged" || existing?.stub) await links(page, change === "created" || renamed || moved ? {
|
|
3094
|
+
pages: [page],
|
|
3095
|
+
withDescendants: moved
|
|
3096
|
+
} : void 0);
|
|
1738
3097
|
return {
|
|
1739
3098
|
page,
|
|
1740
3099
|
change,
|
|
@@ -1742,143 +3101,166 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
1742
3101
|
relinked
|
|
1743
3102
|
};
|
|
1744
3103
|
};
|
|
1745
|
-
const
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
const
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
if (
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
3104
|
+
const runOps = async () => {
|
|
3105
|
+
const depth = /* @__PURE__ */ new Map();
|
|
3106
|
+
for (const op of ops) {
|
|
3107
|
+
if (op.op !== "remove") continue;
|
|
3108
|
+
const node = await importers.getNode(binding.id, op.sourceId);
|
|
3109
|
+
const page = node ? await storage.getPage({
|
|
3110
|
+
id: node.pageId,
|
|
3111
|
+
read: "all"
|
|
3112
|
+
}) : null;
|
|
3113
|
+
const path = live(page) ? await keyPath(page) : null;
|
|
3114
|
+
depth.set(op.sourceId, path?.keys.length ?? 0);
|
|
3115
|
+
}
|
|
3116
|
+
const writes = ops.filter((op) => op.op !== "remove");
|
|
3117
|
+
const removes = ops.filter((op) => op.op === "remove").sort((a, b) => depth.get(b.sourceId) - depth.get(a.sourceId));
|
|
3118
|
+
for (const op of [...writes, ...removes]) {
|
|
3119
|
+
const sourceId = op.op === "remove" ? op.sourceId : op.item.sourceId;
|
|
3120
|
+
const embeds = [];
|
|
3121
|
+
madeFolders = [];
|
|
3122
|
+
try {
|
|
3123
|
+
await storage.transaction(async () => {
|
|
3124
|
+
if (op.op === "remove") {
|
|
3125
|
+
const node = await importers.getNode(binding.id, sourceId);
|
|
3126
|
+
if (!node) return;
|
|
3127
|
+
const state = await stateOf(node);
|
|
3128
|
+
if (state === "merged") return;
|
|
3129
|
+
if (state === "gone") {
|
|
3130
|
+
await forget(node);
|
|
3131
|
+
result.applied = true;
|
|
3132
|
+
return;
|
|
3133
|
+
}
|
|
3134
|
+
const current = await owned(node.pageId, sourceId);
|
|
3135
|
+
await storage.lockSubtree(current.page.id);
|
|
3136
|
+
const children = (await storage.countChildPages({
|
|
3137
|
+
parentIds: [current.page.id],
|
|
3138
|
+
read: "all"
|
|
3139
|
+
}))[current.page.id] ?? 0;
|
|
3140
|
+
const folder = (await importers.listBindings()).some((other) => other.id !== binding.id && other.anchorPageId === current.page.id);
|
|
3141
|
+
if (children > 0 || node.adopted || folder) {
|
|
3142
|
+
if (node.stub) return;
|
|
3143
|
+
const note = node.adopted ? (await keptBodyNotes(current.page.id)).at(-1) : void 0;
|
|
3144
|
+
const heading = ORIGINAL_BODY_NOTE_HEADINGS.find((h) => note?.text.startsWith(h));
|
|
3145
|
+
const original = heading ? note.text.slice(heading.length) : note?.text;
|
|
3146
|
+
const page = await storage.updatePage({
|
|
3147
|
+
id: current.page.id,
|
|
3148
|
+
expectedVersion: current.page.version,
|
|
3149
|
+
body: original || (children > 0 ? "Removed from the source. Kept because pages are still nested under it." : folder ? "Removed from the source. Kept because another importer writes under it." : "Removed from the source. Kept because the page was here before the import."),
|
|
3150
|
+
provenance
|
|
3151
|
+
});
|
|
3152
|
+
await importers.saveNode({
|
|
3153
|
+
...node,
|
|
3154
|
+
stub: true
|
|
3155
|
+
});
|
|
3156
|
+
await links(page);
|
|
3157
|
+
embeds.push({
|
|
3158
|
+
kind: "index",
|
|
3159
|
+
pageId: page.id
|
|
3160
|
+
});
|
|
3161
|
+
result.counts.stubbed++;
|
|
3162
|
+
result.changes.push({
|
|
3163
|
+
sourceId,
|
|
3164
|
+
pageId: page.id,
|
|
3165
|
+
change: "stubbed",
|
|
3166
|
+
title: page.name,
|
|
3167
|
+
path: ref(current.keys)
|
|
3168
|
+
});
|
|
3169
|
+
} else {
|
|
3170
|
+
const deleted = await storage.deletePage({
|
|
3171
|
+
id: current.page.id,
|
|
3172
|
+
expectedVersion: current.page.version,
|
|
3173
|
+
deletedBy: provenance.author
|
|
3174
|
+
});
|
|
3175
|
+
await importers.deleteNode(binding.id, sourceId);
|
|
3176
|
+
if ((await importers.listLinkingNodes(binding.id, [sourceId], { limit: 1 })).items.length > 0) {
|
|
3177
|
+
await importers.markLinkingNodesUnsettled(binding.id, [sourceId]);
|
|
3178
|
+
await importers.setState(binding.id, { [KNOWLEDGE_IMPORT_SETTLE_RESTART_KEY]: (0, crypto.randomUUID)() });
|
|
3179
|
+
deferredLinkers = true;
|
|
3180
|
+
}
|
|
3181
|
+
await links(deleted, { pages: [deleted] });
|
|
3182
|
+
embeds.push({
|
|
3183
|
+
kind: "remove",
|
|
3184
|
+
pageId: deleted.id
|
|
3185
|
+
});
|
|
3186
|
+
result.counts.removed++;
|
|
3187
|
+
result.changes.push({
|
|
3188
|
+
sourceId,
|
|
3189
|
+
pageId: null,
|
|
3190
|
+
change: "removed",
|
|
3191
|
+
title: deleted.name,
|
|
3192
|
+
path: ref(current.keys)
|
|
3193
|
+
});
|
|
3194
|
+
}
|
|
1770
3195
|
result.applied = true;
|
|
1771
3196
|
return;
|
|
1772
3197
|
}
|
|
1773
|
-
const
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
read: "all"
|
|
1778
|
-
}))[current.page.id] ?? 0;
|
|
1779
|
-
const folder = (await importers.listBindings()).some((other) => other.id !== binding.id && other.anchorPageId === current.page.id);
|
|
1780
|
-
if (children > 0 || node.adopted || folder) {
|
|
1781
|
-
if (node.stub) return;
|
|
1782
|
-
const note = node.adopted ? (await keptBodyNotes(current.page.id)).at(-1) : void 0;
|
|
1783
|
-
const heading = ORIGINAL_BODY_NOTE_HEADINGS.find((h) => note?.text.startsWith(h));
|
|
1784
|
-
const original = heading ? note.text.slice(heading.length) : note?.text;
|
|
1785
|
-
const page = await storage.updatePage({
|
|
1786
|
-
id: current.page.id,
|
|
1787
|
-
expectedVersion: current.page.version,
|
|
1788
|
-
body: original || (children > 0 ? "Removed from the source. Kept because pages are still nested under it." : folder ? "Removed from the source. Kept because another importer writes under it." : "Removed from the source. Kept because the page was here before the import."),
|
|
1789
|
-
provenance
|
|
1790
|
-
});
|
|
1791
|
-
await importers.saveNode({
|
|
1792
|
-
...node,
|
|
1793
|
-
stub: true
|
|
1794
|
-
});
|
|
1795
|
-
await syncLinks(() => require_run_registry.syncKnowledgePageBodyLinks(storage, page));
|
|
3198
|
+
const written = await write(op.item, op.op === "upsert");
|
|
3199
|
+
for (const folder of madeFolders) {
|
|
3200
|
+
result.applied = true;
|
|
3201
|
+
result.counts.created++;
|
|
1796
3202
|
embeds.push({
|
|
1797
3203
|
kind: "index",
|
|
1798
|
-
pageId: page.id
|
|
1799
|
-
});
|
|
1800
|
-
result.counts.stubbed++;
|
|
1801
|
-
result.changes.push({
|
|
1802
|
-
sourceId,
|
|
1803
|
-
pageId: page.id,
|
|
1804
|
-
change: "stubbed",
|
|
1805
|
-
title: page.name,
|
|
1806
|
-
path: ref(current.keys)
|
|
1807
|
-
});
|
|
1808
|
-
} else {
|
|
1809
|
-
const deleted = await storage.deletePage({
|
|
1810
|
-
id: current.page.id,
|
|
1811
|
-
expectedVersion: current.page.version,
|
|
1812
|
-
deletedBy: provenance.author
|
|
1813
|
-
});
|
|
1814
|
-
await importers.deleteNode(binding.id, sourceId);
|
|
1815
|
-
if ((await importers.listLinkingNodes(binding.id, [sourceId], { limit: 1 })).items.length > 0) {
|
|
1816
|
-
await importers.markLinkingNodesUnsettled(binding.id, [sourceId]);
|
|
1817
|
-
await importers.setState(binding.id, { [KNOWLEDGE_IMPORT_SETTLE_RESTART_KEY]: (0, crypto.randomUUID)() });
|
|
1818
|
-
deferredLinkers = true;
|
|
1819
|
-
}
|
|
1820
|
-
await syncLinks(async () => {
|
|
1821
|
-
await require_run_registry.syncKnowledgePageBodyLinks(storage, deleted);
|
|
1822
|
-
await require_run_registry.refreshKnowledgeLinksTo(storage, [deleted]);
|
|
1823
|
-
});
|
|
1824
|
-
embeds.push({
|
|
1825
|
-
kind: "remove",
|
|
1826
|
-
pageId: deleted.id
|
|
3204
|
+
pageId: folder.page.id
|
|
1827
3205
|
});
|
|
1828
|
-
result.counts.removed++;
|
|
1829
3206
|
result.changes.push({
|
|
1830
|
-
sourceId,
|
|
1831
|
-
pageId:
|
|
1832
|
-
change: "
|
|
1833
|
-
title:
|
|
1834
|
-
path: ref(
|
|
3207
|
+
sourceId: folder.sourceId,
|
|
3208
|
+
pageId: folder.page.id,
|
|
3209
|
+
change: "created",
|
|
3210
|
+
title: folder.page.name,
|
|
3211
|
+
path: ref(folder.keys)
|
|
1835
3212
|
});
|
|
1836
3213
|
}
|
|
3214
|
+
if (!written) {
|
|
3215
|
+
result.counts.merged++;
|
|
3216
|
+
return;
|
|
3217
|
+
}
|
|
3218
|
+
const { page, change, moved, relinked } = written;
|
|
3219
|
+
recordRelinked(relinked, embeds);
|
|
3220
|
+
if (change === "unchanged") {
|
|
3221
|
+
result.counts.unchanged++;
|
|
3222
|
+
return;
|
|
3223
|
+
}
|
|
1837
3224
|
result.applied = true;
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
result.counts.
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
kind: "index",
|
|
1854
|
-
pageId: page.id
|
|
3225
|
+
if (change !== "moved") embeds.push({
|
|
3226
|
+
kind: "index",
|
|
3227
|
+
pageId: page.id
|
|
3228
|
+
});
|
|
3229
|
+
if (change === "created") result.counts.created++;
|
|
3230
|
+
else if (change === "updated") result.counts.updated++;
|
|
3231
|
+
if (moved) result.counts.moved++;
|
|
3232
|
+
const path = await keyPath(page);
|
|
3233
|
+
result.changes.push({
|
|
3234
|
+
sourceId,
|
|
3235
|
+
pageId: page.id,
|
|
3236
|
+
change,
|
|
3237
|
+
title: page.name,
|
|
3238
|
+
path: path ? ref(path.keys) : ""
|
|
3239
|
+
});
|
|
1855
3240
|
});
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
result.
|
|
3241
|
+
result.embeds.push(...embeds);
|
|
3242
|
+
} catch (error) {
|
|
3243
|
+
const reason = refusalFor(error);
|
|
3244
|
+
if (!reason) throw error;
|
|
3245
|
+
result.refused.push({
|
|
1861
3246
|
sourceId,
|
|
1862
|
-
|
|
1863
|
-
change,
|
|
1864
|
-
title: page.name,
|
|
1865
|
-
path: path ? ref(path.keys) : ""
|
|
3247
|
+
reason
|
|
1866
3248
|
});
|
|
1867
|
-
}
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
3249
|
+
}
|
|
3250
|
+
}
|
|
3251
|
+
};
|
|
3252
|
+
if (!canBatchImportFlush(input.storage, input.importers)) await runOps();
|
|
3253
|
+
else if (ops.length) {
|
|
3254
|
+
const fallback = await applyBatched(anchor?.page ?? null);
|
|
3255
|
+
if (fallback) {
|
|
3256
|
+
result.fallback = fallback;
|
|
3257
|
+
await runOps();
|
|
1876
3258
|
}
|
|
1877
3259
|
}
|
|
1878
3260
|
if (input.settle) {
|
|
1879
3261
|
if (anchor) {
|
|
1880
3262
|
input.settle.onStart?.();
|
|
1881
|
-
result.settle = await settle(input.settle);
|
|
3263
|
+
result.settle = await settle(input.settle, anchor.page);
|
|
1882
3264
|
} else result.settle = {
|
|
1883
3265
|
pending: false,
|
|
1884
3266
|
cursor: null,
|
|
@@ -1888,13 +3270,369 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
1888
3270
|
}
|
|
1889
3271
|
return result;
|
|
1890
3272
|
/**
|
|
3273
|
+
* Decides every op over a working copy (overlay.ts) and writes what they decided in a few
|
|
3274
|
+
* set-based statements, all in one savepoint (batched-flush plan v3.1). Returns why it fell back,
|
|
3275
|
+
* with the savepoint rolled back and the result as before, or null once the ops landed.
|
|
3276
|
+
*/
|
|
3277
|
+
async function applyBatched(folder) {
|
|
3278
|
+
const writeOps = new Map(ops.flatMap((op) => op.op === "remove" ? [] : [[op.item.sourceId, op]]));
|
|
3279
|
+
const removed = ops.flatMap((op) => op.op === "remove" ? [op.sourceId] : []);
|
|
3280
|
+
const sourceIds = new Set(removed);
|
|
3281
|
+
for (const op of writeOps.values()) {
|
|
3282
|
+
sourceIds.add(op.item.sourceId);
|
|
3283
|
+
if (op.item.parent) sourceIds.add(op.item.parent);
|
|
3284
|
+
if (op.item.fallbackParent) sourceIds.add(op.item.fallbackParent);
|
|
3285
|
+
for (const link of ("links" in op.item ? op.item.links : void 0) ?? []) sourceIds.add(link.sourceId);
|
|
3286
|
+
}
|
|
3287
|
+
const plan = (rows) => {
|
|
3288
|
+
const keysOf = (page) => {
|
|
3289
|
+
const keys = [];
|
|
3290
|
+
for (let at = page; at && !at.isScope; at = at.parentId ? rows.pages.get(at.parentId) : null) {
|
|
3291
|
+
if (!live(at) || at.key === void 0) return null;
|
|
3292
|
+
keys.unshift(at.key);
|
|
3293
|
+
if (keys.length > 10) return null;
|
|
3294
|
+
}
|
|
3295
|
+
return keys;
|
|
3296
|
+
};
|
|
3297
|
+
const chains = importChainPaths(rows.pages);
|
|
3298
|
+
const pageAt = (keys) => {
|
|
3299
|
+
const key = importPathKey(scope.id, keys);
|
|
3300
|
+
return rows.paths.has(key) ? rows.paths.get(key) : chains.get(key);
|
|
3301
|
+
};
|
|
3302
|
+
const at = (sourceId, seen) => {
|
|
3303
|
+
if (!sourceId) return null;
|
|
3304
|
+
const node = rows.nodes.get(`${binding.id}\u0000${sourceId}`);
|
|
3305
|
+
const page = node ? rows.pages.get(node.pageId) : null;
|
|
3306
|
+
if (live(page ?? null) && page.scopeId === scope.id) {
|
|
3307
|
+
const keys = keysOf(page);
|
|
3308
|
+
if (keys) return {
|
|
3309
|
+
id: page.id,
|
|
3310
|
+
keys
|
|
3311
|
+
};
|
|
3312
|
+
}
|
|
3313
|
+
const op = writeOps.get(sourceId);
|
|
3314
|
+
if (!op || seen.has(sourceId)) return null;
|
|
3315
|
+
return {
|
|
3316
|
+
id: null,
|
|
3317
|
+
keys: [...destinationOf(op, /* @__PURE__ */ new Set([...seen, sourceId])).keys, leafOf(op)]
|
|
3318
|
+
};
|
|
3319
|
+
};
|
|
3320
|
+
const leafOf = (op) => knowledgeImportKey(op.item.path?.at(-1) ?? op.item.sourceId);
|
|
3321
|
+
const destinationOf = (op, seen) => {
|
|
3322
|
+
if (op.item.path) {
|
|
3323
|
+
const keys = [...anchorPath, ...op.item.path.slice(0, -1).map(knowledgeImportKey)];
|
|
3324
|
+
return {
|
|
3325
|
+
id: op.item.path.length === 1 ? folder.id : pageAt(keys),
|
|
3326
|
+
keys
|
|
3327
|
+
};
|
|
3328
|
+
}
|
|
3329
|
+
return at(op.item.parent, seen) ?? at(op.item.fallbackParent, seen) ?? {
|
|
3330
|
+
id: folder.id,
|
|
3331
|
+
keys: anchorPath
|
|
3332
|
+
};
|
|
3333
|
+
};
|
|
3334
|
+
const out = {
|
|
3335
|
+
paths: [],
|
|
3336
|
+
positions: [],
|
|
3337
|
+
notes: [],
|
|
3338
|
+
holders: [],
|
|
3339
|
+
subtrees: [],
|
|
3340
|
+
linkTargets: removed,
|
|
3341
|
+
bindings: removed.length > 0,
|
|
3342
|
+
inPlace: removed.length === 0
|
|
3343
|
+
};
|
|
3344
|
+
const nodeAt = (sourceId) => rows.nodes.get(`${binding.id}\u0000${sourceId}`);
|
|
3345
|
+
const left = /* @__PURE__ */ new Set();
|
|
3346
|
+
for (const op of writeOps.values()) {
|
|
3347
|
+
const destination = destinationOf(op, /* @__PURE__ */ new Set([op.item.sourceId]));
|
|
3348
|
+
const leaf = [...destination.keys, leafOf(op)];
|
|
3349
|
+
const page = rows.pages.get(nodeAt(op.item.sourceId)?.pageId ?? "");
|
|
3350
|
+
if (destination.id && live(page ?? null) && page.parentId === destination.id && (!op.item.path || page.key === leafOf(op))) {
|
|
3351
|
+
if (op.item.path && op.item.path.length > 1) out.holders.push(destination.id);
|
|
3352
|
+
continue;
|
|
3353
|
+
}
|
|
3354
|
+
out.inPlace = false;
|
|
3355
|
+
out.paths.push({
|
|
3356
|
+
scopeId: scope.id,
|
|
3357
|
+
path: leaf
|
|
3358
|
+
});
|
|
3359
|
+
if (destination.id) out.positions.push(destination.id);
|
|
3360
|
+
if (destination.id !== void 0 && live(page ?? null) && (page.parentId !== destination.id || op.item.path && page.key !== leafOf(op))) {
|
|
3361
|
+
out.subtrees.push(page.id);
|
|
3362
|
+
if (page.parentId) left.add(page.parentId);
|
|
3363
|
+
}
|
|
3364
|
+
if (!op.item.path) continue;
|
|
3365
|
+
out.positions.push(folder.id);
|
|
3366
|
+
for (let i = anchorPath.length + 1; i < leaf.length; i++) {
|
|
3367
|
+
out.paths.push({
|
|
3368
|
+
scopeId: scope.id,
|
|
3369
|
+
path: leaf.slice(0, i)
|
|
3370
|
+
});
|
|
3371
|
+
const prefix = pageAt(leaf.slice(0, i));
|
|
3372
|
+
if (prefix) out.positions.push(prefix);
|
|
3373
|
+
}
|
|
3374
|
+
const held = pageAt(leaf);
|
|
3375
|
+
if (held && held !== page?.id) {
|
|
3376
|
+
out.subtrees.push(held);
|
|
3377
|
+
out.notes.push(held);
|
|
3378
|
+
if (page) {
|
|
3379
|
+
out.notes.push(page.id);
|
|
3380
|
+
out.positions.push(page.id);
|
|
3381
|
+
const keys = keysOf(page);
|
|
3382
|
+
if (keys) {
|
|
3383
|
+
for (const child of rows.pages.values()) if (child?.parentId === held && live(child) && child.key !== void 0) out.paths.push({
|
|
3384
|
+
scopeId: scope.id,
|
|
3385
|
+
path: [...keys, child.key]
|
|
3386
|
+
});
|
|
3387
|
+
}
|
|
3388
|
+
}
|
|
3389
|
+
}
|
|
3390
|
+
}
|
|
3391
|
+
for (const id of out.positions) if (left.has(id)) out.subtrees.push(id);
|
|
3392
|
+
for (const sourceId of removed) {
|
|
3393
|
+
const node = nodeAt(sourceId);
|
|
3394
|
+
if (!node) continue;
|
|
3395
|
+
out.subtrees.push(node.pageId);
|
|
3396
|
+
if (node.adopted) out.notes.push(node.pageId);
|
|
3397
|
+
}
|
|
3398
|
+
for (const node of rows.nodes.values()) if (node?.stub && node.adopted) out.notes.push(node.pageId);
|
|
3399
|
+
return out;
|
|
3400
|
+
};
|
|
3401
|
+
return batchedOver(folder, sourceIds, plan, runOps);
|
|
3402
|
+
}
|
|
3403
|
+
/**
|
|
3404
|
+
* Runs `decide` over a working copy of the rows `plan` names, then writes what it decided in a few
|
|
3405
|
+
* set-based statements, all in one savepoint. Returns why it fell back, with the savepoint rolled
|
|
3406
|
+
* back and the result as before, or null once the writes landed.
|
|
3407
|
+
*/
|
|
3408
|
+
async function batchedOver(folder, sourceIds, plan, decide) {
|
|
3409
|
+
const real = {
|
|
3410
|
+
storage: input.storage,
|
|
3411
|
+
importers: input.importers
|
|
3412
|
+
};
|
|
3413
|
+
const before = structuredClone(result);
|
|
3414
|
+
const deferredBefore = deferredLinkers;
|
|
3415
|
+
const reset = () => {
|
|
3416
|
+
const copy = structuredClone(before);
|
|
3417
|
+
Object.assign(result, copy);
|
|
3418
|
+
deferredLinkers = deferredBefore;
|
|
3419
|
+
};
|
|
3420
|
+
const missing = emptyImportOverlayMissing();
|
|
3421
|
+
let locked = /* @__PURE__ */ new Set();
|
|
3422
|
+
let reread = false;
|
|
3423
|
+
try {
|
|
3424
|
+
return await real.storage.transaction(async () => {
|
|
3425
|
+
for (let pass = 0; pass < BATCH_DECIDE_PASSES; pass++) {
|
|
3426
|
+
const rows = await gatherImportRows({
|
|
3427
|
+
storage: real.storage,
|
|
3428
|
+
importers: real.importers,
|
|
3429
|
+
bindingId: binding.id,
|
|
3430
|
+
sourceIds,
|
|
3431
|
+
pageIds: folder ? [folder.id] : [],
|
|
3432
|
+
plan,
|
|
3433
|
+
missing,
|
|
3434
|
+
locked,
|
|
3435
|
+
reread
|
|
3436
|
+
});
|
|
3437
|
+
if (!rows) throw new BatchFallback("lock-churn");
|
|
3438
|
+
locked = rows.locked;
|
|
3439
|
+
const working = new ImportOverlay(rows);
|
|
3440
|
+
reset();
|
|
3441
|
+
overlay = working;
|
|
3442
|
+
storage = working.storage;
|
|
3443
|
+
importers = working.importers;
|
|
3444
|
+
try {
|
|
3445
|
+
await decide();
|
|
3446
|
+
} catch (error) {
|
|
3447
|
+
if (error instanceof KnowledgeImportNotGatheredError) {
|
|
3448
|
+
for (const [name, set] of Object.entries(working.missing)) {
|
|
3449
|
+
const into = missing[name];
|
|
3450
|
+
if (into instanceof Map) for (const [k, v] of set) into.set(k, v);
|
|
3451
|
+
else for (const k of set) into.add(k);
|
|
3452
|
+
}
|
|
3453
|
+
continue;
|
|
3454
|
+
}
|
|
3455
|
+
if (error instanceof KnowledgeImportRereadRequiredError) {
|
|
3456
|
+
reread = true;
|
|
3457
|
+
continue;
|
|
3458
|
+
}
|
|
3459
|
+
if (error instanceof KnowledgeImportBatchUnsupportedError) throw new BatchFallback(error.call);
|
|
3460
|
+
throw error;
|
|
3461
|
+
} finally {
|
|
3462
|
+
overlay = null;
|
|
3463
|
+
storage = real.storage;
|
|
3464
|
+
importers = real.importers;
|
|
3465
|
+
}
|
|
3466
|
+
try {
|
|
3467
|
+
if (working.writes.length) await real.storage.applyPageWrites({ writes: working.writes });
|
|
3468
|
+
} catch (error) {
|
|
3469
|
+
if (!refusalFor(error)) throw error;
|
|
3470
|
+
throw new BatchFallback(`page writes: ${error.name}`);
|
|
3471
|
+
}
|
|
3472
|
+
for (const work of working.marks) await work(real.storage, real.importers);
|
|
3473
|
+
const nodes = working.nodeWrites(rows);
|
|
3474
|
+
try {
|
|
3475
|
+
if (nodes.deletes.length || nodes.saves.length) await real.importers.writeNodes(nodes);
|
|
3476
|
+
} catch (error) {
|
|
3477
|
+
if (!refusalFor(error)) throw error;
|
|
3478
|
+
throw new BatchFallback(`node writes: ${error.name}`);
|
|
3479
|
+
}
|
|
3480
|
+
try {
|
|
3481
|
+
await require_execution_fence.repairKnowledgeLinks(real.storage, {
|
|
3482
|
+
synced: working.links.flatMap((work) => "sync" in work ? [work.sync] : []),
|
|
3483
|
+
refreshed: working.links.flatMap((work) => "refresh" in work ? [{
|
|
3484
|
+
page: work.refresh,
|
|
3485
|
+
withDescendants: work.withDescendants
|
|
3486
|
+
}] : [])
|
|
3487
|
+
});
|
|
3488
|
+
} catch (error) {
|
|
3489
|
+
if (error instanceof require_execution_fence.KnowledgeLinkRepairUnsupportedError) throw new BatchFallback(error.reason);
|
|
3490
|
+
if (error instanceof require_execution_fence.KnowledgeUnsupportedCapabilityError) throw new BatchFallback(`link repair: ${error.name}`);
|
|
3491
|
+
throw error;
|
|
3492
|
+
}
|
|
3493
|
+
return null;
|
|
3494
|
+
}
|
|
3495
|
+
throw new BatchFallback("gather passes");
|
|
3496
|
+
});
|
|
3497
|
+
} catch (error) {
|
|
3498
|
+
if (!(error instanceof BatchFallback)) throw error;
|
|
3499
|
+
reset();
|
|
3500
|
+
return error.reason;
|
|
3501
|
+
}
|
|
3502
|
+
}
|
|
3503
|
+
/**
|
|
1891
3504
|
* One settle slice (O3 §C, §C′): visits the binding's unsettled nodes after `budget.after`, each
|
|
1892
3505
|
* in its own savepoint, moving a page under a source parent that has arrived since and writing
|
|
1893
3506
|
* links whose targets now resolve. Stops at the candidate, move or time cap and leaves the rest
|
|
1894
3507
|
* for the next slice. A node it can't settle (refused, or still waiting) is skipped and stays
|
|
1895
3508
|
* unsettled; the pass ends when it reaches the last unsettled node.
|
|
1896
3509
|
*/
|
|
1897
|
-
async function settle(budget) {
|
|
3510
|
+
async function settle(budget, folder) {
|
|
3511
|
+
if (!canBatchImportFlush(input.storage, input.importers)) return settleNodeByNode(budget);
|
|
3512
|
+
const fromStart = (budget.after ?? void 0) === void 0;
|
|
3513
|
+
const window = [];
|
|
3514
|
+
let cursor = budget.after ?? void 0;
|
|
3515
|
+
let end = false;
|
|
3516
|
+
while (window.length < budget.candidates) {
|
|
3517
|
+
const page = await input.importers.listNodes(binding.id, {
|
|
3518
|
+
unsettled: true,
|
|
3519
|
+
...cursor !== void 0 ? { after: cursor } : {},
|
|
3520
|
+
limit: budget.candidates - window.length
|
|
3521
|
+
});
|
|
3522
|
+
window.push(...page.items);
|
|
3523
|
+
cursor = page.items.at(-1)?.sourceId ?? cursor;
|
|
3524
|
+
if (!page.next) {
|
|
3525
|
+
end = true;
|
|
3526
|
+
break;
|
|
3527
|
+
}
|
|
3528
|
+
}
|
|
3529
|
+
if (!window.length) return settleNodeByNode(budget);
|
|
3530
|
+
const parents = new Map((await input.importers.getNodes(binding.id, [...new Set(window.flatMap((node) => node.parentSourceId ? [node.parentSourceId] : []))])).map((node) => [node.sourceId, node]));
|
|
3531
|
+
const pages = new Map((await input.storage.getPages({
|
|
3532
|
+
ids: window.map((node) => node.pageId),
|
|
3533
|
+
read: "all"
|
|
3534
|
+
})).map((page) => [page.id, page]));
|
|
3535
|
+
const visit = [];
|
|
3536
|
+
const movers = [];
|
|
3537
|
+
for (const node of window) {
|
|
3538
|
+
visit.push(node);
|
|
3539
|
+
const parent = node.parentSourceId ? parents.get(node.parentSourceId) : void 0;
|
|
3540
|
+
const page = pages.get(node.pageId);
|
|
3541
|
+
if (parent && page && page.parentId !== parent.pageId) {
|
|
3542
|
+
movers.push({
|
|
3543
|
+
sourceId: node.sourceId,
|
|
3544
|
+
page,
|
|
3545
|
+
destination: parent.pageId
|
|
3546
|
+
});
|
|
3547
|
+
if (movers.length >= budget.moves) break;
|
|
3548
|
+
}
|
|
3549
|
+
}
|
|
3550
|
+
if (visit.length < window.length) end = false;
|
|
3551
|
+
const sourceIds = /* @__PURE__ */ new Set();
|
|
3552
|
+
for (const node of visit) {
|
|
3553
|
+
sourceIds.add(node.sourceId);
|
|
3554
|
+
if (node.parentSourceId) sourceIds.add(node.parentSourceId);
|
|
3555
|
+
for (const link of node.links) sourceIds.add(link.sourceId);
|
|
3556
|
+
}
|
|
3557
|
+
let outcome = null;
|
|
3558
|
+
const fallback = await batchedOver(folder, sourceIds, (rows) => ({
|
|
3559
|
+
paths: movers.flatMap((mover) => {
|
|
3560
|
+
const keys = [];
|
|
3561
|
+
for (let at = rows.pages.get(mover.destination); at && !at.isScope;) {
|
|
3562
|
+
if (at.key === void 0) return [];
|
|
3563
|
+
keys.unshift(at.key);
|
|
3564
|
+
at = at.parentId ? rows.pages.get(at.parentId) : null;
|
|
3565
|
+
}
|
|
3566
|
+
return mover.page.key === void 0 ? [] : [{
|
|
3567
|
+
scopeId: scope.id,
|
|
3568
|
+
path: [...keys, mover.page.key]
|
|
3569
|
+
}];
|
|
3570
|
+
}),
|
|
3571
|
+
positions: movers.map((mover) => mover.destination),
|
|
3572
|
+
notes: [],
|
|
3573
|
+
subtrees: movers.map((mover) => mover.page.id),
|
|
3574
|
+
linkTargets: movers.map((mover) => mover.sourceId),
|
|
3575
|
+
bindings: false
|
|
3576
|
+
}), async () => {
|
|
3577
|
+
outcome = await settleWindow(budget, visit, end, fromStart);
|
|
3578
|
+
});
|
|
3579
|
+
if (fallback === null && outcome) {
|
|
3580
|
+
const settledSlice = outcome;
|
|
3581
|
+
if (!settledSlice.pending && deferredLinkers) {
|
|
3582
|
+
if ((await input.importers.listNodes(binding.id, {
|
|
3583
|
+
unsettled: true,
|
|
3584
|
+
limit: 1
|
|
3585
|
+
})).items.length > 0) return {
|
|
3586
|
+
...settledSlice,
|
|
3587
|
+
pending: true
|
|
3588
|
+
};
|
|
3589
|
+
}
|
|
3590
|
+
return settledSlice;
|
|
3591
|
+
}
|
|
3592
|
+
result.fallback = result.fallback ? `${result.fallback}; settle: ${fallback}` : `settle: ${fallback}`;
|
|
3593
|
+
return settleNodeByNode(budget);
|
|
3594
|
+
}
|
|
3595
|
+
/**
|
|
3596
|
+
* The node-by-node loop over a window read ahead, for the batched slice: the same caps, the same
|
|
3597
|
+
* savepoint per node, over the working copy.
|
|
3598
|
+
*/
|
|
3599
|
+
async function settleWindow(budget, visit, end, fromStart) {
|
|
3600
|
+
let after = budget.after ?? void 0;
|
|
3601
|
+
let moves = 0;
|
|
3602
|
+
let settled = 0;
|
|
3603
|
+
const resumeAt = () => deferredLinkers ? null : after ?? null;
|
|
3604
|
+
for (const node of visit) {
|
|
3605
|
+
if (moves >= budget.moves || Date.now() >= budget.until) return {
|
|
3606
|
+
pending: true,
|
|
3607
|
+
cursor: resumeAt(),
|
|
3608
|
+
settled,
|
|
3609
|
+
fromStart
|
|
3610
|
+
};
|
|
3611
|
+
after = node.sourceId;
|
|
3612
|
+
const embeds = [];
|
|
3613
|
+
try {
|
|
3614
|
+
const outcome = await storage.transaction(() => settleNode(node.sourceId, embeds, moves < budget.moves));
|
|
3615
|
+
if (outcome.moved) moves++;
|
|
3616
|
+
if (outcome.moved || outcome.relinked) settled++;
|
|
3617
|
+
result.embeds.push(...embeds);
|
|
3618
|
+
} catch (error) {
|
|
3619
|
+
if (!refusalFor(error)) throw error;
|
|
3620
|
+
}
|
|
3621
|
+
}
|
|
3622
|
+
if (!end) return {
|
|
3623
|
+
pending: true,
|
|
3624
|
+
cursor: resumeAt(),
|
|
3625
|
+
settled,
|
|
3626
|
+
fromStart
|
|
3627
|
+
};
|
|
3628
|
+
return {
|
|
3629
|
+
pending: false,
|
|
3630
|
+
cursor: null,
|
|
3631
|
+
settled,
|
|
3632
|
+
fromStart
|
|
3633
|
+
};
|
|
3634
|
+
}
|
|
3635
|
+
async function settleNodeByNode(budget) {
|
|
1898
3636
|
let after = budget.after ?? void 0;
|
|
1899
3637
|
const fromStart = after === void 0;
|
|
1900
3638
|
let examined = 0;
|
|
@@ -1987,7 +3725,10 @@ async function applyKnowledgeImportFlush(input) {
|
|
|
1987
3725
|
({page, keys, relinked: rewrote} = await moveOwned(sourceId, page, destination));
|
|
1988
3726
|
recordRelinked(rewrote, embeds);
|
|
1989
3727
|
moved = true;
|
|
1990
|
-
await
|
|
3728
|
+
await links(null, {
|
|
3729
|
+
pages: [page],
|
|
3730
|
+
withDescendants: true
|
|
3731
|
+
});
|
|
1991
3732
|
}
|
|
1992
3733
|
} else if (parent) misplaced = true;
|
|
1993
3734
|
const out = await relink(node, page);
|
|
@@ -2374,7 +4115,7 @@ function transient(error) {
|
|
|
2374
4115
|
}
|
|
2375
4116
|
function hostError(error) {
|
|
2376
4117
|
if (error instanceof KnowledgeImporterHostConflictError || error instanceof KnowledgeImporterHostError) return error;
|
|
2377
|
-
if (error instanceof
|
|
4118
|
+
if (error instanceof require_execution_fence.KnowledgeImporterRunStateError) return runStateConflict(error);
|
|
2378
4119
|
const failure = new KnowledgeImporterHostError("The importer host could not apply the request; nothing was applied.", transient(error) ? 503 : 422);
|
|
2379
4120
|
failure.cause = error;
|
|
2380
4121
|
return failure;
|
|
@@ -2457,6 +4198,7 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
2457
4198
|
/** Store time (epoch ms) at which a running run stops being live under `leaseMs`. */
|
|
2458
4199
|
const liveUntil = (run) => Math.min((run.heartbeatAt ?? run.startedAt).getTime() + (leaseMs ?? Infinity), run.deadlineAt?.getTime() ?? Infinity);
|
|
2459
4200
|
const listBindings = async () => typeof options.bindings === "function" ? await options.bindings() : options.bindings;
|
|
4201
|
+
const pathWarned = /* @__PURE__ */ new Set();
|
|
2460
4202
|
const storageAndImporters = async () => {
|
|
2461
4203
|
const storage = await writer.getStorage();
|
|
2462
4204
|
const importers = storage.importers;
|
|
@@ -2500,7 +4242,10 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
2500
4242
|
* flushes and finish are refused as `run_not_active`; exact replays still return receipts.
|
|
2501
4243
|
*/
|
|
2502
4244
|
const staleAfter = leaseMs ?? options.staleRunAfterMs ?? DEFAULT_STALE_RUN_AFTER_MS;
|
|
2503
|
-
/**
|
|
4245
|
+
/**
|
|
4246
|
+
* Ends `run` if it isn't live; the caller holds the guard and the run's lock. The caller clears the
|
|
4247
|
+
* run's path-warning marker once its transaction commits: a rollback brings the run back.
|
|
4248
|
+
*/
|
|
2504
4249
|
const expireLocked = async (importers, run) => {
|
|
2505
4250
|
const why = lapsed(run, await clock(importers), staleAfter);
|
|
2506
4251
|
if (!why) return false;
|
|
@@ -2512,13 +4257,16 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
2512
4257
|
});
|
|
2513
4258
|
return true;
|
|
2514
4259
|
};
|
|
4260
|
+
/** Ends the binding's runs that aren't live, returning the ones it ended. */
|
|
2515
4261
|
const reclaimStaleRuns = async (importers, bindingId) => {
|
|
4262
|
+
const ended = [];
|
|
2516
4263
|
for (const candidate of await importers.listRuns(bindingId)) {
|
|
2517
4264
|
if (candidate.status !== "running") continue;
|
|
2518
4265
|
const run = await importers.lockRun(candidate.id);
|
|
2519
4266
|
if (!run || run.status !== "running") continue;
|
|
2520
|
-
await expireLocked(importers, run);
|
|
4267
|
+
if (await expireLocked(importers, run)) ended.push(run.id);
|
|
2521
4268
|
}
|
|
4269
|
+
return ended;
|
|
2522
4270
|
};
|
|
2523
4271
|
/**
|
|
2524
4272
|
* Counts a settle flush that timed out, outside its rolled-back transaction. Best effort, and
|
|
@@ -2575,7 +4323,7 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
2575
4323
|
importer: binding.importer,
|
|
2576
4324
|
target: binding.target
|
|
2577
4325
|
});
|
|
2578
|
-
await reclaimStaleRuns(importers, binding.id);
|
|
4326
|
+
const ended = await reclaimStaleRuns(importers, binding.id);
|
|
2579
4327
|
if (start?.admit) try {
|
|
2580
4328
|
await start.admit(unwrapKnowledgeStorage(tx));
|
|
2581
4329
|
} catch (error) {
|
|
@@ -2597,7 +4345,8 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
2597
4345
|
const saved = run.status === "started" ? await importers.getState(binding.id) : {};
|
|
2598
4346
|
return {
|
|
2599
4347
|
run,
|
|
2600
|
-
state: Object.fromEntries(Object.entries(saved).filter(([key]) => !key.startsWith(RESERVED_STATE_PREFIX)))
|
|
4348
|
+
state: Object.fromEntries(Object.entries(saved).filter(([key]) => !key.startsWith(RESERVED_STATE_PREFIX))),
|
|
4349
|
+
ended
|
|
2601
4350
|
};
|
|
2602
4351
|
});
|
|
2603
4352
|
let result;
|
|
@@ -2608,6 +4357,7 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
2608
4357
|
exclusive = true;
|
|
2609
4358
|
result = await attempt();
|
|
2610
4359
|
}
|
|
4360
|
+
for (const runId of result.ended) pathWarned.delete(runId);
|
|
2611
4361
|
if (result.run.status !== "started") return {
|
|
2612
4362
|
status: "skipped",
|
|
2613
4363
|
runId: result.run.run.id
|
|
@@ -2666,8 +4416,12 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
2666
4416
|
}
|
|
2667
4417
|
let embeds = [];
|
|
2668
4418
|
let settling = false;
|
|
4419
|
+
let fallbackWarning;
|
|
4420
|
+
let pathsUnsupported = false;
|
|
2669
4421
|
try {
|
|
2670
4422
|
const write = (deadlineAt) => storage.transaction(async (tx) => {
|
|
4423
|
+
fallbackWarning = void 0;
|
|
4424
|
+
pathsUnsupported = false;
|
|
2671
4425
|
const importers = tx.importers;
|
|
2672
4426
|
const guard = await importers.lockWriterGuard(peek.firstWriteAt ? "share" : "update");
|
|
2673
4427
|
const run = await importers.lockRun(flush.runId);
|
|
@@ -2712,6 +4466,8 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
2712
4466
|
}
|
|
2713
4467
|
} } : {}
|
|
2714
4468
|
});
|
|
4469
|
+
if (applied.fallback) fallbackWarning = `Knowledge importer: flush ${flush.seq} of run ${run.id} saved op by op instead of batched (${applied.fallback})`;
|
|
4470
|
+
pathsUnsupported = !!applied.pathsUnsupported;
|
|
2715
4471
|
const settled = applied.settle;
|
|
2716
4472
|
const hostUpdates = {};
|
|
2717
4473
|
if (settled && (settled.cursor ?? "") !== (hostState[SETTLE_CURSOR_KEY] ?? "")) hostUpdates[SETTLE_CURSOR_KEY] = settled.cursor ?? "";
|
|
@@ -2722,15 +4478,18 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
2722
4478
|
...hostUpdates
|
|
2723
4479
|
};
|
|
2724
4480
|
if (Object.keys(state).length) await importers.setState(binding.id, state);
|
|
2725
|
-
|
|
4481
|
+
const changes = applied.changes.map((change) => ({
|
|
2726
4482
|
runId: run.id,
|
|
2727
4483
|
...change
|
|
2728
|
-
});
|
|
4484
|
+
}));
|
|
4485
|
+
if (importers.recordRunChanges) await importers.recordRunChanges(changes);
|
|
4486
|
+
else for (const change of changes) await importers.recordRunChange(change);
|
|
2729
4487
|
const receipt = {
|
|
2730
4488
|
seq: flush.seq,
|
|
2731
4489
|
...applied.counts,
|
|
2732
4490
|
refused: applied.refused,
|
|
2733
|
-
pending: settled?.pending ?? false
|
|
4491
|
+
pending: settled?.pending ?? false,
|
|
4492
|
+
...applied.fallback ? { fallback: applied.fallback } : {}
|
|
2734
4493
|
};
|
|
2735
4494
|
await importers.recordFlush({
|
|
2736
4495
|
runId: run.id,
|
|
@@ -2741,7 +4500,8 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
2741
4500
|
counts: {
|
|
2742
4501
|
...applied.counts,
|
|
2743
4502
|
refused: applied.refused.length,
|
|
2744
|
-
settled: settled?.settled ?? 0
|
|
4503
|
+
settled: settled?.settled ?? 0,
|
|
4504
|
+
...applied.fallback ? { fallbacks: 1 } : {}
|
|
2745
4505
|
}
|
|
2746
4506
|
});
|
|
2747
4507
|
if (applied.applied && !guard.firstWriteAt) await importers.markFirstWrite();
|
|
@@ -2756,6 +4516,11 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
2756
4516
|
if (attempt >= MAX_LEASE_BOUND_ATTEMPTS) throw new KnowledgeImporterHostError("The flush could not be bounded by its run lease; resend it.", 503);
|
|
2757
4517
|
deadlineAt = Math.min(budgetAt, error.cutoff - LEASE_CUTOFF_MARGIN_MS);
|
|
2758
4518
|
}
|
|
4519
|
+
if (fallbackWarning) writer.warn(fallbackWarning);
|
|
4520
|
+
if (pathsUnsupported && !pathWarned.has(flush.runId)) {
|
|
4521
|
+
pathWarned.add(flush.runId);
|
|
4522
|
+
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`);
|
|
4523
|
+
}
|
|
2759
4524
|
await runEmbeds(storage, embeds);
|
|
2760
4525
|
return receipt;
|
|
2761
4526
|
} catch (error) {
|
|
@@ -2823,7 +4588,10 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
2823
4588
|
await importers.lockWriterGuard("share");
|
|
2824
4589
|
const run = await importers.lockRun(runId);
|
|
2825
4590
|
return !!run && run.status === "running" && await expireLocked(importers, run);
|
|
2826
|
-
}))
|
|
4591
|
+
})) {
|
|
4592
|
+
expired.push(runId);
|
|
4593
|
+
pathWarned.delete(runId);
|
|
4594
|
+
}
|
|
2827
4595
|
return { expired };
|
|
2828
4596
|
} catch (error) {
|
|
2829
4597
|
throw hostError(error);
|
|
@@ -2847,7 +4615,7 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
2847
4615
|
}
|
|
2848
4616
|
const { storage } = await storageAndImporters();
|
|
2849
4617
|
try {
|
|
2850
|
-
|
|
4618
|
+
const receipt = await storage.transaction(async (tx) => {
|
|
2851
4619
|
const importers = tx.importers;
|
|
2852
4620
|
const guard = await importers.lockWriterGuard("share");
|
|
2853
4621
|
const run = await importers.lockRun(request.runId);
|
|
@@ -2891,6 +4659,8 @@ function createLocalKnowledgeImporterHost(writer, options) {
|
|
|
2891
4659
|
});
|
|
2892
4660
|
return runReceipt(finished);
|
|
2893
4661
|
});
|
|
4662
|
+
pathWarned.delete(request.runId);
|
|
4663
|
+
return receipt;
|
|
2894
4664
|
} catch (error) {
|
|
2895
4665
|
throw hostError(error);
|
|
2896
4666
|
}
|
|
@@ -3139,7 +4909,7 @@ var KnowledgeScopeRuntime = class {
|
|
|
3139
4909
|
this.getStorage = getStorage;
|
|
3140
4910
|
this.warn = warn;
|
|
3141
4911
|
this.#config = structuredClone(declarations);
|
|
3142
|
-
this.#configCompiled =
|
|
4912
|
+
this.#configCompiled = require_execution_fence.compileKnowledgeScopes(structuredClone(declarations));
|
|
3143
4913
|
this.#resolved = {
|
|
3144
4914
|
stored: "{}",
|
|
3145
4915
|
compiled: this.#configCompiled,
|
|
@@ -3175,7 +4945,7 @@ var KnowledgeScopeRuntime = class {
|
|
|
3175
4945
|
...Object.fromEntries(entries)
|
|
3176
4946
|
};
|
|
3177
4947
|
try {
|
|
3178
|
-
compiled =
|
|
4948
|
+
compiled = require_execution_fence.compileKnowledgeScopes(structuredClone(next));
|
|
3179
4949
|
merged = next;
|
|
3180
4950
|
return true;
|
|
3181
4951
|
} catch (error) {
|
|
@@ -3228,7 +4998,7 @@ var KnowledgeScopeRuntime = class {
|
|
|
3228
4998
|
return entry;
|
|
3229
4999
|
}
|
|
3230
5000
|
validatePrincipals(principals) {
|
|
3231
|
-
for (const principal of principals) if (!this.compiled.match(principal)) throw new
|
|
5001
|
+
for (const principal of principals) if (!this.compiled.match(principal)) throw new require_execution_fence.KnowledgeDeclarationError(`Knowledge run scope "${principal}" does not match a declared scope type.`);
|
|
3232
5002
|
}
|
|
3233
5003
|
/**
|
|
3234
5004
|
* Fails when stored scope pages carry declaration keys neither the config nor the store declares: a
|
|
@@ -3261,19 +5031,19 @@ var KnowledgeScopeRuntime = class {
|
|
|
3261
5031
|
const stranded = orphans.filter(({ declaration }) => skippedKey(declaration) === key);
|
|
3262
5032
|
messages.push(`Knowledge skipped the store's scope declaration "${key}", so its stored scopes have none: ${list(stranded)}. ${this.#resolved.skipped.get(key)} Fix that declaration in the store, or declare the key, with its children, in scopes to override it.`);
|
|
3263
5033
|
}
|
|
3264
|
-
throw new
|
|
5034
|
+
throw new require_execution_fence.KnowledgeDeclarationError(messages.join(" "));
|
|
3265
5035
|
}
|
|
3266
5036
|
/** Re-keys stored scopes from declaration `from` to `to`. See {@link Knowledge.renameScopeDeclaration}. */
|
|
3267
5037
|
async renameScopeDeclaration(from, to) {
|
|
3268
|
-
if (this.compiled.declarations.has(from)) throw new
|
|
3269
|
-
if (!this.compiled.declarations.has(to)) throw new
|
|
5038
|
+
if (this.compiled.declarations.has(from)) throw new require_execution_fence.KnowledgeDeclarationError(`Can't rename scope declaration "${from}": it is still declared. Remove it from scopes first.`);
|
|
5039
|
+
if (!this.compiled.declarations.has(to)) throw new require_execution_fence.KnowledgeDeclarationError(`Can't rename scope declaration to "${to}": it isn't declared in scopes.`);
|
|
3270
5040
|
const renamed = await (await this.getStorage()).renameScopeDeclaration({
|
|
3271
5041
|
from,
|
|
3272
5042
|
to,
|
|
3273
5043
|
check: (scopes) => {
|
|
3274
5044
|
const mismatched = scopes.filter((scope) => this.compiled.match(scope.address)?.declaration !== scope.to);
|
|
3275
5045
|
if (mismatched.length === 0) return;
|
|
3276
|
-
throw new
|
|
5046
|
+
throw new require_execution_fence.KnowledgeDeclarationError(`Can't rename scope declaration "${from}" to "${to}": ` + mismatched.slice(0, 5).map((scope) => `"${scope.address}" doesn't match "${scope.to}"`).join(", ") + (mismatched.length > 5 ? `, and ${mismatched.length - 5} more` : "") + ". Nothing was renamed.");
|
|
3277
5047
|
}
|
|
3278
5048
|
});
|
|
3279
5049
|
this.#declarationsChecked = void 0;
|
|
@@ -3290,7 +5060,7 @@ var KnowledgeScopeRuntime = class {
|
|
|
3290
5060
|
}
|
|
3291
5061
|
#assertCurrent(scope) {
|
|
3292
5062
|
if (this.#isCurrent(scope)) return;
|
|
3293
|
-
throw new
|
|
5063
|
+
throw new require_execution_fence.KnowledgeDeclarationError(`Knowledge scope "${scope.address}" was created from "${scope.declaration}", which no longer matches it (scope params match one segment; encode colons in ids as %3A). It can't be used as a scope of "${this.compiled.match(scope.address)?.declaration}".`);
|
|
3294
5064
|
}
|
|
3295
5065
|
/** Refuses a stored scope row whose address now matches a different declaration, as materializing it would. */
|
|
3296
5066
|
assertCurrentScope(scope) {
|
|
@@ -3300,7 +5070,7 @@ var KnowledgeScopeRuntime = class {
|
|
|
3300
5070
|
this.validatePrincipals(principals);
|
|
3301
5071
|
await this.checkDeclarations();
|
|
3302
5072
|
const storage = await this.getStorage();
|
|
3303
|
-
const read = await
|
|
5073
|
+
const read = await require_execution_fence.knowledgeReadScopeFor(this.compiled, principals, async (addresses) => (await storage.getScopesByAddress(addresses)).filter((scope) => this.#isCurrent(scope)));
|
|
3304
5074
|
if (read.addresses.length === 0) return read;
|
|
3305
5075
|
const stale = new Set((await storage.getScopesByAddress(read.addresses)).filter((scope) => !this.#isCurrent(scope)).map((scope) => scope.address));
|
|
3306
5076
|
return stale.size ? {
|
|
@@ -3313,7 +5083,7 @@ var KnowledgeScopeRuntime = class {
|
|
|
3313
5083
|
if (!scope.isScope || !scope.address) throw new Error("Knowledge roles require a scope page.");
|
|
3314
5084
|
if (!this.#isCurrent(scope)) return null;
|
|
3315
5085
|
const storage = await this.getStorage();
|
|
3316
|
-
return
|
|
5086
|
+
return require_execution_fence.knowledgeRoleOn(this.compiled, principals, {
|
|
3317
5087
|
address: scope.address,
|
|
3318
5088
|
parentAddress: await this.#currentParentAddress(storage, scope)
|
|
3319
5089
|
});
|
|
@@ -3327,17 +5097,17 @@ var KnowledgeScopeRuntime = class {
|
|
|
3327
5097
|
return parent && this.#isCurrent(parent) ? parent.address ?? void 0 : void 0;
|
|
3328
5098
|
}
|
|
3329
5099
|
async explainAccess(runScopes, target) {
|
|
3330
|
-
const principals =
|
|
5100
|
+
const principals = require_execution_fence.knowledgeRunScopes(this.compiled, runScopes);
|
|
3331
5101
|
this.validatePrincipals(principals);
|
|
3332
5102
|
const storage = await this.getStorage();
|
|
3333
5103
|
let scope;
|
|
3334
5104
|
let page = null;
|
|
3335
5105
|
if ("scope" in target) {
|
|
3336
|
-
if (!this.compiled.match(target.scope)) throw new
|
|
5106
|
+
if (!this.compiled.match(target.scope)) throw new require_execution_fence.KnowledgeDeclarationError(`Knowledge scope "${target.scope}" does not match a declared scope type.`);
|
|
3337
5107
|
[scope] = await storage.getScopesByAddress([target.scope]);
|
|
3338
5108
|
} else {
|
|
3339
5109
|
if (target.page.indexOf("#") > 0) {
|
|
3340
|
-
const parsed =
|
|
5110
|
+
const parsed = require_execution_fence.parseKnowledgePageRef(target.page);
|
|
3341
5111
|
if (parsed) [scope] = await storage.getScopesByAddress([parsed.scope]);
|
|
3342
5112
|
page = parsed && scope ? await storage.getPageByPath({
|
|
3343
5113
|
scopeId: scope.id,
|
|
@@ -3362,12 +5132,12 @@ var KnowledgeScopeRuntime = class {
|
|
|
3362
5132
|
};
|
|
3363
5133
|
}
|
|
3364
5134
|
const address = scope?.address ?? target.scope;
|
|
3365
|
-
const reasons = scope && !this.#isCurrent(scope) ? [] :
|
|
5135
|
+
const reasons = scope && !this.#isCurrent(scope) ? [] : require_execution_fence.knowledgeAccessGrants(this.compiled, principals, {
|
|
3366
5136
|
address,
|
|
3367
5137
|
parentAddress: scope ? await this.#currentParentAddress(storage, scope) : void 0
|
|
3368
5138
|
});
|
|
3369
5139
|
let role = null;
|
|
3370
|
-
for (const reason of reasons) role =
|
|
5140
|
+
for (const reason of reasons) role = require_execution_fence.strongerKnowledgeRole(role, reason.role);
|
|
3371
5141
|
return {
|
|
3372
5142
|
role,
|
|
3373
5143
|
reasons,
|
|
@@ -3491,8 +5261,8 @@ var KnowledgeScopeRuntime = class {
|
|
|
3491
5261
|
}
|
|
3492
5262
|
async #materialize(address, principals, provenance, ancestors, run) {
|
|
3493
5263
|
const match = this.compiled.match(address);
|
|
3494
|
-
if (!match) throw new
|
|
3495
|
-
if (ancestors.includes(address)) throw new
|
|
5264
|
+
if (!match) throw new require_execution_fence.KnowledgeDeclarationError(`Knowledge scope "${address}" does not match a declared scope type.`);
|
|
5265
|
+
if (ancestors.includes(address)) throw new require_execution_fence.KnowledgeDeclarationError(`Knowledge scope placement cycle at "${address}".`);
|
|
3496
5266
|
const storage = run.storage ?? await this.getStorage();
|
|
3497
5267
|
const known = run.known;
|
|
3498
5268
|
const lookUp = async (scope) => known?.looked.has(scope) || known?.byAddress.has(scope) ? known.byAddress.get(scope) : (await storage.getScopesByAddress([scope]))[0];
|
|
@@ -3544,7 +5314,7 @@ var KnowledgeScopeRuntime = class {
|
|
|
3544
5314
|
});
|
|
3545
5315
|
this.#assertCurrent(result.scope);
|
|
3546
5316
|
if (!existing || result.created || templateCount > 0 || match.compiled.children.length > 0 || result.scope.parentId !== existing.parentId) run.wrote = true;
|
|
3547
|
-
if (result.created) await
|
|
5317
|
+
if (result.created) await require_execution_fence.updateKnowledgeLinks(this.warn, () => require_execution_fence.refreshKnowledgeLinksTo(storage, [result.scope], { withDescendants: true }));
|
|
3548
5318
|
if (result.parentConflict) this.warn(`Knowledge scope "${address}" was already linked by another run; keeping its persisted parent.`);
|
|
3549
5319
|
if (run.known) {
|
|
3550
5320
|
run.known.byAddress.set(address, result.scope);
|
|
@@ -3568,7 +5338,7 @@ var KnowledgeScopeRuntime = class {
|
|
|
3568
5338
|
/** Most scope pages one tree or ancestor walk looks at before it stops and reports truncation. */
|
|
3569
5339
|
const MAX_KNOWLEDGE_EXPLORER_SCOPE_SCAN = 1e3;
|
|
3570
5340
|
function scopeVisible(page, read) {
|
|
3571
|
-
return page.isScope &&
|
|
5341
|
+
return page.isScope && require_execution_fence.knowledgeScopeReadable(page, read);
|
|
3572
5342
|
}
|
|
3573
5343
|
async function allChildScopes(store, parentId, budget) {
|
|
3574
5344
|
const scopes = [];
|
|
@@ -3666,7 +5436,7 @@ async function withChildCounts(store, pages, read) {
|
|
|
3666
5436
|
read
|
|
3667
5437
|
});
|
|
3668
5438
|
} catch (error) {
|
|
3669
|
-
if (error instanceof
|
|
5439
|
+
if (error instanceof require_execution_fence.KnowledgeUnsupportedCapabilityError) return {
|
|
3670
5440
|
pages,
|
|
3671
5441
|
truncated: false
|
|
3672
5442
|
};
|
|
@@ -3732,13 +5502,13 @@ async function pageByIdOrRef(store, ref, read) {
|
|
|
3732
5502
|
read
|
|
3733
5503
|
});
|
|
3734
5504
|
if (byId || !ref.includes(":")) return byId;
|
|
3735
|
-
const parsed = ref.includes("#") ?
|
|
5505
|
+
const parsed = ref.includes("#") ? require_execution_fence.parseKnowledgePageRef(ref) : {
|
|
3736
5506
|
scope: ref,
|
|
3737
5507
|
path: []
|
|
3738
5508
|
};
|
|
3739
5509
|
if (!parsed) return null;
|
|
3740
5510
|
const [scope] = await store.getScopesByAddress([parsed.scope]);
|
|
3741
|
-
if (!scope || !
|
|
5511
|
+
if (!scope || !require_execution_fence.knowledgeScopeReadable(scope, read)) return null;
|
|
3742
5512
|
if (parsed.path.length === 0) return store.getPage({
|
|
3743
5513
|
id: scope.id,
|
|
3744
5514
|
read
|
|
@@ -3810,7 +5580,7 @@ async function countInBatches(pages, count) {
|
|
|
3810
5580
|
try {
|
|
3811
5581
|
for (let start = 0; start < pages.length; start += 100) Object.assign(counts, await count(pages.slice(start, start + 100).map((page) => page.id)));
|
|
3812
5582
|
} catch (error) {
|
|
3813
|
-
if (error instanceof
|
|
5583
|
+
if (error instanceof require_execution_fence.KnowledgeUnsupportedCapabilityError) return null;
|
|
3814
5584
|
throw error;
|
|
3815
5585
|
}
|
|
3816
5586
|
return counts;
|
|
@@ -4032,7 +5802,7 @@ async function readKnowledgeScopeGrants(store, input) {
|
|
|
4032
5802
|
for (const grant of wanted) {
|
|
4033
5803
|
const scope = scopes.get(grant.principal);
|
|
4034
5804
|
if (scope) {
|
|
4035
|
-
if (
|
|
5805
|
+
if (require_execution_fence.knowledgeScopeReadable(scope, read)) grants.push({
|
|
4036
5806
|
...grant,
|
|
4037
5807
|
principalId: scope.id
|
|
4038
5808
|
});
|
|
@@ -4059,7 +5829,7 @@ async function readKnowledgePageLinkCounts(store, input) {
|
|
|
4059
5829
|
read: input.read
|
|
4060
5830
|
});
|
|
4061
5831
|
} catch (error) {
|
|
4062
|
-
if (error instanceof
|
|
5832
|
+
if (error instanceof require_execution_fence.KnowledgeUnsupportedCapabilityError) return null;
|
|
4063
5833
|
throw error;
|
|
4064
5834
|
}
|
|
4065
5835
|
}
|
|
@@ -4085,7 +5855,7 @@ async function readKnowledgePageLinks(store, input) {
|
|
|
4085
5855
|
limit: 201
|
|
4086
5856
|
});
|
|
4087
5857
|
} catch (error) {
|
|
4088
|
-
if (error instanceof
|
|
5858
|
+
if (error instanceof require_execution_fence.KnowledgeUnsupportedCapabilityError) return null;
|
|
4089
5859
|
throw error;
|
|
4090
5860
|
}
|
|
4091
5861
|
const truncated = listed.length > 200;
|
|
@@ -4145,7 +5915,7 @@ var Knowledge = class extends require_base.MastraBase {
|
|
|
4145
5915
|
component: "STORAGE",
|
|
4146
5916
|
name: config?.name ?? config?.id ?? "Knowledge"
|
|
4147
5917
|
});
|
|
4148
|
-
if (!config?.scopes || typeof config.scopes !== "object") throw new
|
|
5918
|
+
if (!config?.scopes || typeof config.scopes !== "object") throw new require_execution_fence.KnowledgeDeclarationError("Knowledge needs `scopes`: declare the scopes its runs hold, e.g. `scopes: { ...knowledgeMemoryScopes() }`, or `{}` for none.");
|
|
4149
5919
|
this.id = config.id ?? (0, crypto.randomUUID)();
|
|
4150
5920
|
this.description = config.description;
|
|
4151
5921
|
const tools = config.tools;
|
|
@@ -4171,13 +5941,13 @@ var Knowledge = class extends require_base.MastraBase {
|
|
|
4171
5941
|
}
|
|
4172
5942
|
this.#importers = config.importers;
|
|
4173
5943
|
if (Boolean(config.vector) !== Boolean(config.embedder)) throw new Error("Knowledge semantic search needs both `vector` and `embedder`; pass both or neither.");
|
|
4174
|
-
if (config.vector && config.embedder) this.#semantic = new
|
|
5944
|
+
if (config.vector && config.embedder) this.#semantic = new require_execution_fence.KnowledgeSemanticIndex(config.vector, config.embedder, config.embedderOptions);
|
|
4175
5945
|
this.#runtime = new KnowledgeScopeRuntime(config.scopes, () => this.getStorage(), (message) => this.logger.warn(message));
|
|
4176
5946
|
if (this.#pins) this.#warnOnPinOvercommit(this.#pins);
|
|
4177
5947
|
this.hasOwnStorage = config.storage !== void 0;
|
|
4178
5948
|
if (config.storage) {
|
|
4179
|
-
this.#storageSource =
|
|
4180
|
-
this.#storage =
|
|
5949
|
+
this.#storageSource = require_execution_fence.getStorageSource(config.storage);
|
|
5950
|
+
this.#storage = require_execution_fence.augmentWithInit(config.storage);
|
|
4181
5951
|
}
|
|
4182
5952
|
}
|
|
4183
5953
|
/**
|
|
@@ -4225,9 +5995,9 @@ var Knowledge = class extends require_base.MastraBase {
|
|
|
4225
5995
|
*/
|
|
4226
5996
|
scopeGrants(scope) {
|
|
4227
5997
|
const strongest = /* @__PURE__ */ new Map();
|
|
4228
|
-
for (const grant of
|
|
5998
|
+
for (const grant of require_execution_fence.knowledgeAccessGrants(this.#runtime.compiled, "any", scope)) {
|
|
4229
5999
|
if (grant.via === "self") continue;
|
|
4230
|
-
strongest.set(grant.principal,
|
|
6000
|
+
strongest.set(grant.principal, require_execution_fence.strongerKnowledgeRole(strongest.get(grant.principal) ?? null, grant.role));
|
|
4231
6001
|
}
|
|
4232
6002
|
return [...strongest].map(([principal, role]) => ({
|
|
4233
6003
|
principal,
|
|
@@ -4261,15 +6031,16 @@ var Knowledge = class extends require_base.MastraBase {
|
|
|
4261
6031
|
/** Tools for explicit wiring; defaults to the groups configured on this Knowledge. */
|
|
4262
6032
|
createTools(options) {
|
|
4263
6033
|
const principals = options?.principals ? this.#hostPrincipals(options.principals) : void 0;
|
|
4264
|
-
return
|
|
6034
|
+
return require_execution_fence.buildKnowledgePageTools({
|
|
4265
6035
|
runtime: this.#runtime,
|
|
4266
6036
|
getStorage: () => this.getStorage(),
|
|
4267
6037
|
semantic: this.#semantic,
|
|
4268
6038
|
warn: (message) => this.logger.warn(message),
|
|
4269
6039
|
maxTokens: this.#tools.maxTokens,
|
|
4270
6040
|
...principals ? { principals } : {},
|
|
4271
|
-
...options?.author ? { author: options.author } : {}
|
|
4272
|
-
|
|
6041
|
+
...options?.author ? { author: options.author } : {},
|
|
6042
|
+
...options?.requireExpectedVersion ? { requireExpectedVersion: true } : {}
|
|
6043
|
+
}, this.#groups(options), (context) => context?.requestContext?.delete?.(require_execution_fence.PINNED_READ_MEMO_KEY));
|
|
4273
6044
|
}
|
|
4274
6045
|
/**
|
|
4275
6046
|
* Creates or updates the page at `scope#path`, for apps that sync content in from outside an agent
|
|
@@ -4285,7 +6056,7 @@ var Knowledge = class extends require_base.MastraBase {
|
|
|
4285
6056
|
* @experimental
|
|
4286
6057
|
*/
|
|
4287
6058
|
upsertPage(input) {
|
|
4288
|
-
return
|
|
6059
|
+
return require_execution_fence.upsertKnowledgePage(this.#hostWriter(), input);
|
|
4289
6060
|
}
|
|
4290
6061
|
/**
|
|
4291
6062
|
* Deletes the page at `scope#path`; `null` when there is none. Refuses a page with child pages
|
|
@@ -4297,7 +6068,7 @@ var Knowledge = class extends require_base.MastraBase {
|
|
|
4297
6068
|
* @experimental
|
|
4298
6069
|
*/
|
|
4299
6070
|
removePage(input) {
|
|
4300
|
-
return
|
|
6071
|
+
return require_execution_fence.removeKnowledgePage(this.#hostWriter(), input);
|
|
4301
6072
|
}
|
|
4302
6073
|
/**
|
|
4303
6074
|
* Moves the page at `scope#path`, with its subtree, under the page at `parent` (a key path; left
|
|
@@ -4311,7 +6082,7 @@ var Knowledge = class extends require_base.MastraBase {
|
|
|
4311
6082
|
* @experimental
|
|
4312
6083
|
*/
|
|
4313
6084
|
movePage(input) {
|
|
4314
|
-
return
|
|
6085
|
+
return require_execution_fence.moveKnowledgePage(this.#hostWriter(), input);
|
|
4315
6086
|
}
|
|
4316
6087
|
/**
|
|
4317
6088
|
* Adds a note to the page at `scope#path`; throws when there is no page there. Readers of the
|
|
@@ -4321,7 +6092,7 @@ var Knowledge = class extends require_base.MastraBase {
|
|
|
4321
6092
|
* @experimental
|
|
4322
6093
|
*/
|
|
4323
6094
|
addNote(input) {
|
|
4324
|
-
return
|
|
6095
|
+
return require_execution_fence.addKnowledgeNote(this.#hostWriter(), input);
|
|
4325
6096
|
}
|
|
4326
6097
|
/**
|
|
4327
6098
|
* Replaces a note's text. Notes are immutable, so this adds the new note and then removes the old
|
|
@@ -4331,7 +6102,7 @@ var Knowledge = class extends require_base.MastraBase {
|
|
|
4331
6102
|
* @experimental
|
|
4332
6103
|
*/
|
|
4333
6104
|
updateNote(input) {
|
|
4334
|
-
return
|
|
6105
|
+
return require_execution_fence.updateKnowledgeNote(this.#hostWriter(), input);
|
|
4335
6106
|
}
|
|
4336
6107
|
/**
|
|
4337
6108
|
* Removes a note; `null` when it is already gone. Host-only, like {@link Knowledge.upsertPage}.
|
|
@@ -4339,7 +6110,7 @@ var Knowledge = class extends require_base.MastraBase {
|
|
|
4339
6110
|
* @experimental
|
|
4340
6111
|
*/
|
|
4341
6112
|
removeNote(input) {
|
|
4342
|
-
return
|
|
6113
|
+
return require_execution_fence.removeKnowledgeNote(this.#hostWriter(), input);
|
|
4343
6114
|
}
|
|
4344
6115
|
/**
|
|
4345
6116
|
* The app's importers: `host` applies flushes to this Knowledge's storage, and `run` runs one
|
|
@@ -4380,7 +6151,7 @@ var Knowledge = class extends require_base.MastraBase {
|
|
|
4380
6151
|
* @experimental
|
|
4381
6152
|
*/
|
|
4382
6153
|
async reindexLinks() {
|
|
4383
|
-
return
|
|
6154
|
+
return require_execution_fence.reindexKnowledgeLinks(await this.getStorage());
|
|
4384
6155
|
}
|
|
4385
6156
|
/**
|
|
4386
6157
|
* Embeds pages and notes that already exist, without changing them: content written before a
|
|
@@ -4401,7 +6172,7 @@ var Knowledge = class extends require_base.MastraBase {
|
|
|
4401
6172
|
}
|
|
4402
6173
|
/** The usage block that goes with `createTools(options)`. */
|
|
4403
6174
|
getInstructions(options) {
|
|
4404
|
-
return
|
|
6175
|
+
return require_execution_fence.buildKnowledgeInstructions(this.#groups(options), this.#instructions);
|
|
4405
6176
|
}
|
|
4406
6177
|
/** Whether attached agents get pinned context delivered every turn. */
|
|
4407
6178
|
get pinnedContextEnabled() {
|
|
@@ -4428,9 +6199,9 @@ var Knowledge = class extends require_base.MastraBase {
|
|
|
4428
6199
|
async __principalsKey(context) {
|
|
4429
6200
|
await this.#runtime.resolve();
|
|
4430
6201
|
try {
|
|
4431
|
-
return
|
|
6202
|
+
return require_execution_fence.knowledgeRunPrincipals(this.#runtime, context).sort().join("\n");
|
|
4432
6203
|
} catch (error) {
|
|
4433
|
-
if (error instanceof
|
|
6204
|
+
if (error instanceof require_execution_fence.KnowledgeRunScopesError || error instanceof require_execution_fence.KnowledgeDeclarationError) return void 0;
|
|
4434
6205
|
throw error;
|
|
4435
6206
|
}
|
|
4436
6207
|
}
|
|
@@ -4444,8 +6215,8 @@ var Knowledge = class extends require_base.MastraBase {
|
|
|
4444
6215
|
const principals = this.#hostPrincipals(options.principals);
|
|
4445
6216
|
const budget = this.#pins || resolvePins(true);
|
|
4446
6217
|
if (!budget) return [];
|
|
4447
|
-
const run = await
|
|
4448
|
-
return
|
|
6218
|
+
const run = await require_execution_fence.KnowledgeRun.start(this.#runtime, await this.getStorage(), void 0, { principals });
|
|
6219
|
+
return require_execution_fence.knowledgeDeliveredPins(run, budget, this.#groups({ read: options.read }).read);
|
|
4449
6220
|
}
|
|
4450
6221
|
#hostPrincipals(principals) {
|
|
4451
6222
|
const unique = [...new Set(principals)];
|
|
@@ -4456,13 +6227,13 @@ var Knowledge = class extends require_base.MastraBase {
|
|
|
4456
6227
|
async __deliveredPins(context) {
|
|
4457
6228
|
const budget = this.#pins || resolvePins(true);
|
|
4458
6229
|
if (!budget) return [];
|
|
4459
|
-
const run = await
|
|
4460
|
-
return
|
|
6230
|
+
const run = await require_execution_fence.KnowledgeRun.start(this.#runtime, await this.getStorage(), context);
|
|
6231
|
+
return require_execution_fence.knowledgeDeliveredPins(run, budget, this.#groups().read);
|
|
4461
6232
|
}
|
|
4462
6233
|
/** The scopes a run holds a role on this turn, with that role. @internal */
|
|
4463
6234
|
async __heldScopes(context) {
|
|
4464
|
-
const run = await
|
|
4465
|
-
return (await
|
|
6235
|
+
const run = await require_execution_fence.KnowledgeRun.start(this.#runtime, await this.getStorage(), context);
|
|
6236
|
+
return (await require_execution_fence.heldScopes(run)).flatMap(({ address, role }) => role ? [{
|
|
4466
6237
|
address,
|
|
4467
6238
|
role
|
|
4468
6239
|
}] : []);
|
|
@@ -4479,7 +6250,7 @@ var Knowledge = class extends require_base.MastraBase {
|
|
|
4479
6250
|
}
|
|
4480
6251
|
/** @internal */
|
|
4481
6252
|
__usesStorage(storage) {
|
|
4482
|
-
const source =
|
|
6253
|
+
const source = require_execution_fence.getStorageSource(storage);
|
|
4483
6254
|
if (this.#storageSource === source) return true;
|
|
4484
6255
|
const domain = this.#storageSource?.stores?.knowledge;
|
|
4485
6256
|
const sourceDomain = source.stores?.knowledge;
|
|
@@ -4488,8 +6259,8 @@ var Knowledge = class extends require_base.MastraBase {
|
|
|
4488
6259
|
/** @internal */
|
|
4489
6260
|
setStorage(storage, source = storage) {
|
|
4490
6261
|
if (this.hasOwnStorage) return;
|
|
4491
|
-
this.#storageSource =
|
|
4492
|
-
this.#storage =
|
|
6262
|
+
this.#storageSource = require_execution_fence.getStorageSource(source);
|
|
6263
|
+
this.#storage = require_execution_fence.augmentWithInit(storage);
|
|
4493
6264
|
this.#storagePromise = void 0;
|
|
4494
6265
|
}
|
|
4495
6266
|
async getStorage() {
|
|
@@ -4584,90 +6355,90 @@ function createKnowledgeImporterHost(knowledge, options) {
|
|
|
4584
6355
|
return createLocalKnowledgeImporterHost(hostWriterOf(knowledge), options);
|
|
4585
6356
|
}
|
|
4586
6357
|
exports.DEFAULT_KNOWLEDGE_PAGE_GRAPH_LIMITS = DEFAULT_KNOWLEDGE_PAGE_GRAPH_LIMITS;
|
|
4587
|
-
exports.InMemoryKnowledgeStorage =
|
|
6358
|
+
exports.InMemoryKnowledgeStorage = require_execution_fence.InMemoryKnowledgeStorage;
|
|
4588
6359
|
exports.KNOWLEDGE_IMPORTER_ERROR_CODES = KNOWLEDGE_IMPORTER_ERROR_CODES;
|
|
4589
6360
|
exports.KNOWLEDGE_IMPORT_REMOVED_PARENT_BODY = REMOVED_PARENT_BODY;
|
|
4590
|
-
exports.KNOWLEDGE_STORAGE_CONTRACT_VERSION =
|
|
4591
|
-
exports.KNOWLEDGE_STORAGE_SCHEMA_VERSION =
|
|
6361
|
+
exports.KNOWLEDGE_STORAGE_CONTRACT_VERSION = require_execution_fence.KNOWLEDGE_STORAGE_CONTRACT_VERSION;
|
|
6362
|
+
exports.KNOWLEDGE_STORAGE_SCHEMA_VERSION = require_execution_fence.KNOWLEDGE_STORAGE_SCHEMA_VERSION;
|
|
4592
6363
|
exports.Knowledge = Knowledge;
|
|
4593
|
-
exports.KnowledgeConflictError =
|
|
4594
|
-
exports.KnowledgeDeclarationError =
|
|
6364
|
+
exports.KnowledgeConflictError = require_execution_fence.KnowledgeConflictError;
|
|
6365
|
+
exports.KnowledgeDeclarationError = require_execution_fence.KnowledgeDeclarationError;
|
|
4595
6366
|
exports.KnowledgeImporter = KnowledgeImporter;
|
|
4596
6367
|
exports.KnowledgeImporterBase = KnowledgeImporterBase;
|
|
4597
|
-
exports.KnowledgeImporterBindingConflictError =
|
|
6368
|
+
exports.KnowledgeImporterBindingConflictError = require_execution_fence.KnowledgeImporterBindingConflictError;
|
|
4598
6369
|
exports.KnowledgeImporterCredentialsError = KnowledgeImporterCredentialsError;
|
|
4599
6370
|
exports.KnowledgeImporterDefinitionError = KnowledgeImporterDefinitionError;
|
|
4600
6371
|
exports.KnowledgeImporterHostConflictError = KnowledgeImporterHostConflictError;
|
|
4601
6372
|
exports.KnowledgeImporterHostError = KnowledgeImporterHostError;
|
|
4602
|
-
exports.KnowledgeImporterRunStateError =
|
|
6373
|
+
exports.KnowledgeImporterRunStateError = require_execution_fence.KnowledgeImporterRunStateError;
|
|
4603
6374
|
exports.KnowledgeImporterSettingsError = KnowledgeImporterSettingsError;
|
|
4604
6375
|
exports.KnowledgeImporterSourceError = KnowledgeImporterSourceError;
|
|
4605
|
-
exports.KnowledgeImportersStorage =
|
|
4606
|
-
exports.KnowledgeInvalidCursorError =
|
|
4607
|
-
exports.KnowledgeMoveTooLargeError =
|
|
4608
|
-
exports.KnowledgeNotFoundError =
|
|
4609
|
-
exports.KnowledgePageDepthError =
|
|
4610
|
-
exports.KnowledgePageHasChildrenError =
|
|
4611
|
-
exports.KnowledgePageKeyConflictError =
|
|
4612
|
-
exports.KnowledgeSchemaResetRequiredError =
|
|
4613
|
-
exports.KnowledgeStorage =
|
|
4614
|
-
exports.KnowledgeTransactionDeadlineError =
|
|
4615
|
-
exports.KnowledgeUnsupportedCapabilityError =
|
|
6376
|
+
exports.KnowledgeImportersStorage = require_execution_fence.KnowledgeImportersStorage;
|
|
6377
|
+
exports.KnowledgeInvalidCursorError = require_execution_fence.KnowledgeInvalidCursorError;
|
|
6378
|
+
exports.KnowledgeMoveTooLargeError = require_execution_fence.KnowledgeMoveTooLargeError;
|
|
6379
|
+
exports.KnowledgeNotFoundError = require_execution_fence.KnowledgeNotFoundError;
|
|
6380
|
+
exports.KnowledgePageDepthError = require_execution_fence.KnowledgePageDepthError;
|
|
6381
|
+
exports.KnowledgePageHasChildrenError = require_execution_fence.KnowledgePageHasChildrenError;
|
|
6382
|
+
exports.KnowledgePageKeyConflictError = require_execution_fence.KnowledgePageKeyConflictError;
|
|
6383
|
+
exports.KnowledgeSchemaResetRequiredError = require_execution_fence.KnowledgeSchemaResetRequiredError;
|
|
6384
|
+
exports.KnowledgeStorage = require_execution_fence.KnowledgeStorage;
|
|
6385
|
+
exports.KnowledgeTransactionDeadlineError = require_execution_fence.KnowledgeTransactionDeadlineError;
|
|
6386
|
+
exports.KnowledgeUnsupportedCapabilityError = require_execution_fence.KnowledgeUnsupportedCapabilityError;
|
|
4616
6387
|
exports.MAX_KNOWLEDGE_EXPLORER_PAGE_LINKS = MAX_KNOWLEDGE_EXPLORER_PAGE_LINKS;
|
|
4617
6388
|
exports.MAX_KNOWLEDGE_LINK_COUNT_PAGES = MAX_KNOWLEDGE_LINK_COUNT_PAGES;
|
|
4618
|
-
exports.MAX_KNOWLEDGE_MOVE_PAGES =
|
|
4619
|
-
exports.MAX_KNOWLEDGE_NODE_DESCRIPTION_LENGTH =
|
|
4620
|
-
exports.MAX_KNOWLEDGE_NOTE_TOKENS =
|
|
4621
|
-
exports.MAX_KNOWLEDGE_PAGE_BODY_LINKS =
|
|
4622
|
-
exports.MAX_KNOWLEDGE_PAGE_DEPTH =
|
|
4623
|
-
exports.MAX_KNOWLEDGE_PAGE_DESCRIPTION_TOKENS =
|
|
4624
|
-
exports.MAX_KNOWLEDGE_PAGE_LINKS =
|
|
4625
|
-
exports.MAX_KNOWLEDGE_PAGE_LINK_REF_LENGTH =
|
|
4626
|
-
exports.MAX_KNOWLEDGE_PAGE_LIST_LIMIT =
|
|
4627
|
-
exports.MAX_KNOWLEDGE_PIN_LIST_DEPTH =
|
|
4628
|
-
exports.MAX_KNOWLEDGE_RECORD_TEXT_LENGTH =
|
|
4629
|
-
exports.MAX_KNOWLEDGE_SCOPE_TAGS =
|
|
4630
|
-
exports.assertKnowledgeCeilingRaised =
|
|
4631
|
-
exports.assertKnowledgeDescriptionWithinBound =
|
|
4632
|
-
exports.assertKnowledgeNoteTextWithinBound =
|
|
4633
|
-
exports.assertKnowledgePageDescriptionWithinBound =
|
|
4634
|
-
exports.assertKnowledgeRecordTextWithinBound =
|
|
4635
|
-
exports.assertKnowledgeSchemaCompatible =
|
|
4636
|
-
exports.assertKnowledgeScopeWithinCeiling =
|
|
6389
|
+
exports.MAX_KNOWLEDGE_MOVE_PAGES = require_execution_fence.MAX_KNOWLEDGE_MOVE_PAGES;
|
|
6390
|
+
exports.MAX_KNOWLEDGE_NODE_DESCRIPTION_LENGTH = require_execution_fence.MAX_KNOWLEDGE_NODE_DESCRIPTION_LENGTH;
|
|
6391
|
+
exports.MAX_KNOWLEDGE_NOTE_TOKENS = require_execution_fence.MAX_KNOWLEDGE_NOTE_TOKENS;
|
|
6392
|
+
exports.MAX_KNOWLEDGE_PAGE_BODY_LINKS = require_execution_fence.MAX_KNOWLEDGE_PAGE_BODY_LINKS;
|
|
6393
|
+
exports.MAX_KNOWLEDGE_PAGE_DEPTH = require_execution_fence.MAX_KNOWLEDGE_PAGE_DEPTH;
|
|
6394
|
+
exports.MAX_KNOWLEDGE_PAGE_DESCRIPTION_TOKENS = require_execution_fence.MAX_KNOWLEDGE_PAGE_DESCRIPTION_TOKENS;
|
|
6395
|
+
exports.MAX_KNOWLEDGE_PAGE_LINKS = require_execution_fence.MAX_KNOWLEDGE_PAGE_LINKS;
|
|
6396
|
+
exports.MAX_KNOWLEDGE_PAGE_LINK_REF_LENGTH = require_execution_fence.MAX_KNOWLEDGE_PAGE_LINK_REF_LENGTH;
|
|
6397
|
+
exports.MAX_KNOWLEDGE_PAGE_LIST_LIMIT = require_execution_fence.MAX_KNOWLEDGE_PAGE_LIST_LIMIT;
|
|
6398
|
+
exports.MAX_KNOWLEDGE_PIN_LIST_DEPTH = require_execution_fence.MAX_KNOWLEDGE_PIN_LIST_DEPTH;
|
|
6399
|
+
exports.MAX_KNOWLEDGE_RECORD_TEXT_LENGTH = require_execution_fence.MAX_KNOWLEDGE_RECORD_TEXT_LENGTH;
|
|
6400
|
+
exports.MAX_KNOWLEDGE_SCOPE_TAGS = require_execution_fence.MAX_KNOWLEDGE_SCOPE_TAGS;
|
|
6401
|
+
exports.assertKnowledgeCeilingRaised = require_execution_fence.assertKnowledgeCeilingRaised;
|
|
6402
|
+
exports.assertKnowledgeDescriptionWithinBound = require_execution_fence.assertKnowledgeDescriptionWithinBound;
|
|
6403
|
+
exports.assertKnowledgeNoteTextWithinBound = require_execution_fence.assertKnowledgeNoteTextWithinBound;
|
|
6404
|
+
exports.assertKnowledgePageDescriptionWithinBound = require_execution_fence.assertKnowledgePageDescriptionWithinBound;
|
|
6405
|
+
exports.assertKnowledgeRecordTextWithinBound = require_execution_fence.assertKnowledgeRecordTextWithinBound;
|
|
6406
|
+
exports.assertKnowledgeSchemaCompatible = require_execution_fence.assertKnowledgeSchemaCompatible;
|
|
6407
|
+
exports.assertKnowledgeScopeWithinCeiling = require_execution_fence.assertKnowledgeScopeWithinCeiling;
|
|
4637
6408
|
exports.canonicalJson = canonicalJson;
|
|
4638
|
-
exports.canonicalKnowledgeName =
|
|
4639
|
-
exports.canonicalizeKnowledgeScope =
|
|
6409
|
+
exports.canonicalKnowledgeName = require_execution_fence.canonicalKnowledgeName;
|
|
6410
|
+
exports.canonicalizeKnowledgeScope = require_execution_fence.canonicalizeKnowledgeScope;
|
|
4640
6411
|
exports.createKnowledgeImporterHost = createKnowledgeImporterHost;
|
|
4641
|
-
exports.createKnowledgeNodeCursor =
|
|
4642
|
-
exports.createKnowledgeUlid =
|
|
4643
|
-
exports.decodeKnowledgeScopeId =
|
|
4644
|
-
exports.encodeKnowledgeScopeId =
|
|
4645
|
-
exports.expandKnowledgeScope =
|
|
6412
|
+
exports.createKnowledgeNodeCursor = require_execution_fence.createKnowledgeNodeCursor;
|
|
6413
|
+
exports.createKnowledgeUlid = require_execution_fence.createKnowledgeUlid;
|
|
6414
|
+
exports.decodeKnowledgeScopeId = require_execution_fence.decodeKnowledgeScopeId;
|
|
6415
|
+
exports.encodeKnowledgeScopeId = require_execution_fence.encodeKnowledgeScopeId;
|
|
6416
|
+
exports.expandKnowledgeScope = require_execution_fence.expandKnowledgeScope;
|
|
4646
6417
|
exports.importerHostConformance = importerHostConformance;
|
|
4647
|
-
exports.inspectKnowledgeSchema =
|
|
4648
|
-
exports.isKnowledgeScopeVisible =
|
|
4649
|
-
exports.knowledgeAgentScopes =
|
|
6418
|
+
exports.inspectKnowledgeSchema = require_execution_fence.inspectKnowledgeSchema;
|
|
6419
|
+
exports.isKnowledgeScopeVisible = require_execution_fence.isKnowledgeScopeVisible;
|
|
6420
|
+
exports.knowledgeAgentScopes = require_execution_fence.knowledgeAgentScopes;
|
|
4650
6421
|
exports.knowledgeImportKey = knowledgeImportKey;
|
|
4651
6422
|
exports.knowledgeImporterFlushDigest = knowledgeImporterFlushDigest;
|
|
4652
6423
|
exports.knowledgeImporterRegistry = knowledgeImporterRegistry;
|
|
4653
|
-
exports.knowledgeLinkRefKey =
|
|
4654
|
-
exports.knowledgeMemoryScopes =
|
|
4655
|
-
exports.knowledgePagePath =
|
|
4656
|
-
exports.knowledgePersonaScopes =
|
|
4657
|
-
exports.knowledgePinDepth =
|
|
4658
|
-
exports.knowledgePositionBetween =
|
|
4659
|
-
exports.knowledgeScopeAddress =
|
|
4660
|
-
exports.knowledgeScopeKey =
|
|
4661
|
-
exports.knowledgeScopeReadable =
|
|
4662
|
-
exports.knowledgeSemanticDocumentId =
|
|
4663
|
-
exports.knowledgeSemanticIdempotencyKey =
|
|
4664
|
-
exports.knowledgeVisibleScopeKeys =
|
|
6424
|
+
exports.knowledgeLinkRefKey = require_execution_fence.knowledgeLinkRefKey;
|
|
6425
|
+
exports.knowledgeMemoryScopes = require_execution_fence.knowledgeMemoryScopes;
|
|
6426
|
+
exports.knowledgePagePath = require_execution_fence.knowledgePagePath;
|
|
6427
|
+
exports.knowledgePersonaScopes = require_execution_fence.knowledgePersonaScopes;
|
|
6428
|
+
exports.knowledgePinDepth = require_execution_fence.knowledgePinDepth;
|
|
6429
|
+
exports.knowledgePositionBetween = require_execution_fence.knowledgePositionBetween;
|
|
6430
|
+
exports.knowledgeScopeAddress = require_execution_fence.knowledgeScopeAddress;
|
|
6431
|
+
exports.knowledgeScopeKey = require_execution_fence.knowledgeScopeKey;
|
|
6432
|
+
exports.knowledgeScopeReadable = require_execution_fence.knowledgeScopeReadable;
|
|
6433
|
+
exports.knowledgeSemanticDocumentId = require_execution_fence.knowledgeSemanticDocumentId;
|
|
6434
|
+
exports.knowledgeSemanticIdempotencyKey = require_execution_fence.knowledgeSemanticIdempotencyKey;
|
|
6435
|
+
exports.knowledgeVisibleScopeKeys = require_execution_fence.knowledgeVisibleScopeKeys;
|
|
4665
6436
|
exports.listKnowledgeTreeChildren = listKnowledgeTreeChildren;
|
|
4666
6437
|
exports.normalizeKnowledgeImporterFinish = normalizeKnowledgeImporterFinish;
|
|
4667
6438
|
exports.parseKnowledgeImporterFlushBody = parseKnowledgeImporterFlushBody;
|
|
4668
|
-
exports.parseKnowledgeNodeCursor =
|
|
4669
|
-
exports.parseKnowledgePageRef =
|
|
4670
|
-
exports.parseKnowledgeWikilinks =
|
|
6439
|
+
exports.parseKnowledgeNodeCursor = require_execution_fence.parseKnowledgeNodeCursor;
|
|
6440
|
+
exports.parseKnowledgePageRef = require_execution_fence.parseKnowledgePageRef;
|
|
6441
|
+
exports.parseKnowledgeWikilinks = require_execution_fence.parseKnowledgeWikilinks;
|
|
4671
6442
|
exports.readKnowledgePage = readKnowledgePage;
|
|
4672
6443
|
exports.readKnowledgePageActivity = readKnowledgePageActivity;
|
|
4673
6444
|
exports.readKnowledgePageGraph = readKnowledgePageGraph;
|