daigram 0.0.0-stage → 0.1.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/LICENSE +661 -0
- package/LICENSE-MIT +21 -0
- package/NOTICE +11 -0
- package/README.md +788 -2
- package/assets/fonts/CascadiaCode-Regular.ttf +0 -0
- package/assets/fonts/Excalifont-Regular.ttf +0 -0
- package/assets/fonts/LICENSES.md +63 -0
- package/assets/fonts/LiberationSans-Regular.ttf +0 -0
- package/assets/fonts/Virgil-Regular.ttf +0 -0
- package/dist/ai/config.d.ts +11 -0
- package/dist/ai/config.d.ts.map +1 -0
- package/dist/ai/config.js +59 -0
- package/dist/ai/config.js.map +1 -0
- package/dist/ai/providers/anthropic.d.ts +3 -0
- package/dist/ai/providers/anthropic.d.ts.map +1 -0
- package/dist/ai/providers/anthropic.js +71 -0
- package/dist/ai/providers/anthropic.js.map +1 -0
- package/dist/ai/providers/openai-compatible.d.ts +3 -0
- package/dist/ai/providers/openai-compatible.d.ts.map +1 -0
- package/dist/ai/providers/openai-compatible.js +95 -0
- package/dist/ai/providers/openai-compatible.js.map +1 -0
- package/dist/ai/request-settings.d.ts +9 -0
- package/dist/ai/request-settings.d.ts.map +1 -0
- package/dist/ai/request-settings.js +56 -0
- package/dist/ai/request-settings.js.map +1 -0
- package/dist/ai/routes.d.ts +7 -0
- package/dist/ai/routes.d.ts.map +1 -0
- package/dist/ai/routes.js +192 -0
- package/dist/ai/routes.js.map +1 -0
- package/dist/ai/runner.d.ts +19 -0
- package/dist/ai/runner.d.ts.map +1 -0
- package/dist/ai/runner.js +77 -0
- package/dist/ai/runner.js.map +1 -0
- package/dist/ai/sse.d.ts +4 -0
- package/dist/ai/sse.d.ts.map +1 -0
- package/dist/ai/sse.js +53 -0
- package/dist/ai/sse.js.map +1 -0
- package/dist/ai/system.d.ts +2 -0
- package/dist/ai/system.d.ts.map +1 -0
- package/dist/ai/system.js +17 -0
- package/dist/ai/system.js.map +1 -0
- package/dist/ai/tools.d.ts +10 -0
- package/dist/ai/tools.d.ts.map +1 -0
- package/dist/ai/tools.js +134 -0
- package/dist/ai/tools.js.map +1 -0
- package/dist/ai/types.d.ts +72 -0
- package/dist/ai/types.d.ts.map +1 -0
- package/dist/ai/types.js +2 -0
- package/dist/ai/types.js.map +1 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +52 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli/args.d.ts +15 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +78 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/commands/ai.d.ts +2 -0
- package/dist/cli/commands/ai.d.ts.map +1 -0
- package/dist/cli/commands/ai.js +45 -0
- package/dist/cli/commands/ai.js.map +1 -0
- package/dist/cli/commands/arrange.d.ts +2 -0
- package/dist/cli/commands/arrange.d.ts.map +1 -0
- package/dist/cli/commands/arrange.js +103 -0
- package/dist/cli/commands/arrange.js.map +1 -0
- package/dist/cli/commands/canvases.d.ts +2 -0
- package/dist/cli/commands/canvases.d.ts.map +1 -0
- package/dist/cli/commands/canvases.js +38 -0
- package/dist/cli/commands/canvases.js.map +1 -0
- package/dist/cli/commands/check.d.ts +2 -0
- package/dist/cli/commands/check.d.ts.map +1 -0
- package/dist/cli/commands/check.js +15 -0
- package/dist/cli/commands/check.js.map +1 -0
- package/dist/cli/commands/comment.d.ts +2 -0
- package/dist/cli/commands/comment.d.ts.map +1 -0
- package/dist/cli/commands/comment.js +76 -0
- package/dist/cli/commands/comment.js.map +1 -0
- package/dist/cli/commands/elements.d.ts +8 -0
- package/dist/cli/commands/elements.d.ts.map +1 -0
- package/dist/cli/commands/elements.js +285 -0
- package/dist/cli/commands/elements.js.map +1 -0
- package/dist/cli/commands/frame.d.ts +2 -0
- package/dist/cli/commands/frame.d.ts.map +1 -0
- package/dist/cli/commands/frame.js +58 -0
- package/dist/cli/commands/frame.js.map +1 -0
- package/dist/cli/commands/install-skill.d.ts +2 -0
- package/dist/cli/commands/install-skill.d.ts.map +1 -0
- package/dist/cli/commands/install-skill.js +108 -0
- package/dist/cli/commands/install-skill.js.map +1 -0
- package/dist/cli/commands/layout.d.ts +2 -0
- package/dist/cli/commands/layout.d.ts.map +1 -0
- package/dist/cli/commands/layout.js +15 -0
- package/dist/cli/commands/layout.js.map +1 -0
- package/dist/cli/commands/render.d.ts +2 -0
- package/dist/cli/commands/render.d.ts.map +1 -0
- package/dist/cli/commands/render.js +64 -0
- package/dist/cli/commands/render.js.map +1 -0
- package/dist/cli/commands/scene.d.ts +8 -0
- package/dist/cli/commands/scene.d.ts.map +1 -0
- package/dist/cli/commands/scene.js +147 -0
- package/dist/cli/commands/scene.js.map +1 -0
- package/dist/cli/commands/server.d.ts +4 -0
- package/dist/cli/commands/server.d.ts.map +1 -0
- package/dist/cli/commands/server.js +66 -0
- package/dist/cli/commands/server.js.map +1 -0
- package/dist/cli/commands/snapshot.d.ts +2 -0
- package/dist/cli/commands/snapshot.d.ts.map +1 -0
- package/dist/cli/commands/snapshot.js +41 -0
- package/dist/cli/commands/snapshot.js.map +1 -0
- package/dist/cli/image-options.d.ts +43 -0
- package/dist/cli/image-options.d.ts.map +1 -0
- package/dist/cli/image-options.js +71 -0
- package/dist/cli/image-options.js.map +1 -0
- package/dist/cli/run.d.ts +2 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +115 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/cli/util.d.ts +5 -0
- package/dist/cli/util.d.ts.map +1 -0
- package/dist/cli/util.js +35 -0
- package/dist/cli/util.js.map +1 -0
- package/dist/core/arrow-routing.d.ts +31 -0
- package/dist/core/arrow-routing.d.ts.map +1 -0
- package/dist/core/arrow-routing.js +244 -0
- package/dist/core/arrow-routing.js.map +1 -0
- package/dist/core/bulk-ops.d.ts +55 -0
- package/dist/core/bulk-ops.d.ts.map +1 -0
- package/dist/core/bulk-ops.js +181 -0
- package/dist/core/bulk-ops.js.map +1 -0
- package/dist/core/canvas-client.d.ts +110 -0
- package/dist/core/canvas-client.d.ts.map +1 -0
- package/dist/core/canvas-client.js +416 -0
- package/dist/core/canvas-client.js.map +1 -0
- package/dist/core/canvas-id.d.ts +4 -0
- package/dist/core/canvas-id.d.ts.map +1 -0
- package/dist/core/canvas-id.js +5 -0
- package/dist/core/canvas-id.js.map +1 -0
- package/dist/core/canvas-persistence.d.ts +30 -0
- package/dist/core/canvas-persistence.d.ts.map +1 -0
- package/dist/core/canvas-persistence.js +854 -0
- package/dist/core/canvas-persistence.js.map +1 -0
- package/dist/core/canvas-registry.d.ts +36 -0
- package/dist/core/canvas-registry.d.ts.map +1 -0
- package/dist/core/canvas-registry.js +161 -0
- package/dist/core/canvas-registry.js.map +1 -0
- package/dist/core/canvas-routes.d.ts +5 -0
- package/dist/core/canvas-routes.d.ts.map +1 -0
- package/dist/core/canvas-routes.js +29 -0
- package/dist/core/canvas-routes.js.map +1 -0
- package/dist/core/canvas-state.d.ts +14 -0
- package/dist/core/canvas-state.d.ts.map +1 -0
- package/dist/core/canvas-state.js +20 -0
- package/dist/core/canvas-state.js.map +1 -0
- package/dist/core/canvas.d.ts +13 -0
- package/dist/core/canvas.d.ts.map +1 -0
- package/dist/core/canvas.js +4 -0
- package/dist/core/canvas.js.map +1 -0
- package/dist/core/comment-ops.d.ts +3 -0
- package/dist/core/comment-ops.d.ts.map +1 -0
- package/dist/core/comment-ops.js +36 -0
- package/dist/core/comment-ops.js.map +1 -0
- package/dist/core/comments.d.ts +5 -0
- package/dist/core/comments.d.ts.map +1 -0
- package/dist/core/comments.js +137 -0
- package/dist/core/comments.js.map +1 -0
- package/dist/core/compact.d.ts +13 -0
- package/dist/core/compact.d.ts.map +1 -0
- package/dist/core/compact.js +20 -0
- package/dist/core/compact.js.map +1 -0
- package/dist/core/config.d.ts +8 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +18 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/describe.d.ts +3 -0
- package/dist/core/describe.d.ts.map +1 -0
- package/dist/core/describe.js +94 -0
- package/dist/core/describe.js.map +1 -0
- package/dist/core/design-guide.d.ts +2 -0
- package/dist/core/design-guide.d.ts.map +1 -0
- package/dist/core/design-guide.js +115 -0
- package/dist/core/design-guide.js.map +1 -0
- package/dist/core/diagram-layout.d.ts +64 -0
- package/dist/core/diagram-layout.d.ts.map +1 -0
- package/dist/core/diagram-layout.js +238 -0
- package/dist/core/diagram-layout.js.map +1 -0
- package/dist/core/diagram-ops.d.ts +165 -0
- package/dist/core/diagram-ops.d.ts.map +1 -0
- package/dist/core/diagram-ops.js +46 -0
- package/dist/core/diagram-ops.js.map +1 -0
- package/dist/core/entry.d.ts +3 -0
- package/dist/core/entry.d.ts.map +1 -0
- package/dist/core/entry.js +35 -0
- package/dist/core/entry.js.map +1 -0
- package/dist/core/expand-elements.d.ts +9 -0
- package/dist/core/expand-elements.d.ts.map +1 -0
- package/dist/core/expand-elements.js +277 -0
- package/dist/core/expand-elements.js.map +1 -0
- package/dist/core/frame-ops.d.ts +60 -0
- package/dist/core/frame-ops.d.ts.map +1 -0
- package/dist/core/frame-ops.js +90 -0
- package/dist/core/frame-ops.js.map +1 -0
- package/dist/core/frames.d.ts +31 -0
- package/dist/core/frames.d.ts.map +1 -0
- package/dist/core/frames.js +95 -0
- package/dist/core/frames.js.map +1 -0
- package/dist/core/geometry.d.ts +30 -0
- package/dist/core/geometry.d.ts.map +1 -0
- package/dist/core/geometry.js +167 -0
- package/dist/core/geometry.js.map +1 -0
- package/dist/core/layout-check.d.ts +30 -0
- package/dist/core/layout-check.d.ts.map +1 -0
- package/dist/core/layout-check.js +181 -0
- package/dist/core/layout-check.js.map +1 -0
- package/dist/core/local-origin.d.ts +4 -0
- package/dist/core/local-origin.d.ts.map +1 -0
- package/dist/core/local-origin.js +27 -0
- package/dist/core/local-origin.js.map +1 -0
- package/dist/core/mcp-dispatch.d.ts +9 -0
- package/dist/core/mcp-dispatch.d.ts.map +1 -0
- package/dist/core/mcp-dispatch.js +741 -0
- package/dist/core/mcp-dispatch.js.map +1 -0
- package/dist/core/mcp-http.d.ts +3 -0
- package/dist/core/mcp-http.d.ts.map +1 -0
- package/dist/core/mcp-http.js +38 -0
- package/dist/core/mcp-http.js.map +1 -0
- package/dist/core/mcp-server.d.ts +19 -0
- package/dist/core/mcp-server.d.ts.map +1 -0
- package/dist/core/mcp-server.js +57 -0
- package/dist/core/mcp-server.js.map +1 -0
- package/dist/core/mcp-tools.d.ts +3 -0
- package/dist/core/mcp-tools.d.ts.map +1 -0
- package/dist/core/mcp-tools.js +723 -0
- package/dist/core/mcp-tools.js.map +1 -0
- package/dist/core/normalize.d.ts +26 -0
- package/dist/core/normalize.d.ts.map +1 -0
- package/dist/core/normalize.js +134 -0
- package/dist/core/normalize.js.map +1 -0
- package/dist/core/obsidian-md.d.ts +4 -0
- package/dist/core/obsidian-md.d.ts.map +1 -0
- package/dist/core/obsidian-md.js +227 -0
- package/dist/core/obsidian-md.js.map +1 -0
- package/dist/core/pidfile.d.ts +5 -0
- package/dist/core/pidfile.d.ts.map +1 -0
- package/dist/core/pidfile.js +51 -0
- package/dist/core/pidfile.js.map +1 -0
- package/dist/core/png-scene.d.ts +4 -0
- package/dist/core/png-scene.d.ts.map +1 -0
- package/dist/core/png-scene.js +176 -0
- package/dist/core/png-scene.js.map +1 -0
- package/dist/core/render/excalidraw-node/dom.d.ts +29 -0
- package/dist/core/render/excalidraw-node/dom.d.ts.map +1 -0
- package/dist/core/render/excalidraw-node/dom.js +132 -0
- package/dist/core/render/excalidraw-node/dom.js.map +1 -0
- package/dist/core/render/excalidraw-node/index.d.ts +11 -0
- package/dist/core/render/excalidraw-node/index.d.ts.map +1 -0
- package/dist/core/render/excalidraw-node/index.js +77 -0
- package/dist/core/render/excalidraw-node/index.js.map +1 -0
- package/dist/core/render/fonts.d.ts +34 -0
- package/dist/core/render/fonts.d.ts.map +1 -0
- package/dist/core/render/fonts.js +133 -0
- package/dist/core/render/fonts.js.map +1 -0
- package/dist/core/render/index.d.ts +40 -0
- package/dist/core/render/index.d.ts.map +1 -0
- package/dist/core/render/index.js +135 -0
- package/dist/core/render/index.js.map +1 -0
- package/dist/core/render/png-worker.d.ts +2 -0
- package/dist/core/render/png-worker.d.ts.map +1 -0
- package/dist/core/render/png-worker.js +65 -0
- package/dist/core/render/png-worker.js.map +1 -0
- package/dist/core/render/png.d.ts +15 -0
- package/dist/core/render/png.d.ts.map +1 -0
- package/dist/core/render/png.js +128 -0
- package/dist/core/render/png.js.map +1 -0
- package/dist/core/render/text-metrics.d.ts +2 -0
- package/dist/core/render/text-metrics.d.ts.map +1 -0
- package/dist/core/render/text-metrics.js +136 -0
- package/dist/core/render/text-metrics.js.map +1 -0
- package/dist/core/request-canvas.d.ts +9 -0
- package/dist/core/request-canvas.d.ts.map +1 -0
- package/dist/core/request-canvas.js +2 -0
- package/dist/core/request-canvas.js.map +1 -0
- package/dist/core/request-headers.d.ts +5 -0
- package/dist/core/request-headers.d.ts.map +1 -0
- package/dist/core/request-headers.js +80 -0
- package/dist/core/request-headers.js.map +1 -0
- package/dist/core/scene-input.d.ts +2 -0
- package/dist/core/scene-input.d.ts.map +1 -0
- package/dist/core/scene-input.js +11 -0
- package/dist/core/scene-input.js.map +1 -0
- package/dist/core/scene-io.d.ts +16 -0
- package/dist/core/scene-io.d.ts.map +1 -0
- package/dist/core/scene-io.js +95 -0
- package/dist/core/scene-io.js.map +1 -0
- package/dist/core/share-url.d.ts +3 -0
- package/dist/core/share-url.d.ts.map +1 -0
- package/dist/core/share-url.js +77 -0
- package/dist/core/share-url.js.map +1 -0
- package/dist/core/spawn.d.ts +41 -0
- package/dist/core/spawn.d.ts.map +1 -0
- package/dist/core/spawn.js +153 -0
- package/dist/core/spawn.js.map +1 -0
- package/dist/core/version.d.ts +2 -0
- package/dist/core/version.d.ts.map +1 -0
- package/dist/core/version.js +14 -0
- package/dist/core/version.js.map +1 -0
- package/dist/frontend/assets/Assistant-Bold-gm-uSS1B.woff2 +0 -0
- package/dist/frontend/assets/Assistant-Medium-DrcxCXg3.woff2 +0 -0
- package/dist/frontend/assets/Assistant-Regular-DVxZuzxb.woff2 +0 -0
- package/dist/frontend/assets/Assistant-SemiBold-SCI4bEL9.woff2 +0 -0
- package/dist/frontend/assets/Tableau10-CvOaoHrI.js +1 -0
- package/dist/frontend/assets/_commonjs-dynamic-modules-TDtrdbi3.js +1 -0
- package/dist/frontend/assets/abnfDiagram-VCTEODGH-CO_aNPe5.js +1 -0
- package/dist/frontend/assets/advancedFormat-DE2dNp0u.js +1 -0
- package/dist/frontend/assets/ar-SA-G6X2FPQ2-Bq4yiKbc.js +10 -0
- package/dist/frontend/assets/arc--vhPzIZC.js +1 -0
- package/dist/frontend/assets/architectureDiagram-5GKGNRK7-aHYJQElw.js +36 -0
- package/dist/frontend/assets/array-BKyUJesY.js +1 -0
- package/dist/frontend/assets/az-AZ-76LH7QW2-BB3yat67.js +1 -0
- package/dist/frontend/assets/band-dPffDWoQ.js +1 -0
- package/dist/frontend/assets/bg-BG-XCXSNQG7-DmC2FjQc.js +5 -0
- package/dist/frontend/assets/blockDiagram-68f4deed-Bn83vchM.js +118 -0
- package/dist/frontend/assets/blockDiagram-NRAW4CY4-CxaW-TzC.js +129 -0
- package/dist/frontend/assets/bn-BD-2XOGV67Q-DpCbZMS6.js +5 -0
- package/dist/frontend/assets/c4Diagram-15b5d702-Bq7Ko0Vs.js +10 -0
- package/dist/frontend/assets/c4Diagram-UCG6FXSJ-Dh883fAO.js +38 -0
- package/dist/frontend/assets/ca-ES-6MX7JW3Y-CBOshpbV.js +8 -0
- package/dist/frontend/assets/channel-DYvM7vRx.js +1 -0
- package/dist/frontend/assets/chunk-2Q5K7J3B-DaFhLtFc.js +1 -0
- package/dist/frontend/assets/chunk-5VM5RSS4-CyLfaWw7.js +15 -0
- package/dist/frontend/assets/chunk-F27PBJKO-BHNc-edD.js +1 -0
- package/dist/frontend/assets/chunk-G27WJ6UU-BBKiZxqf.js +231 -0
- package/dist/frontend/assets/chunk-JWPE2WC7-7twsn51D.js +1 -0
- package/dist/frontend/assets/chunk-LCL6LL3I-BTwZuXJ6.js +206 -0
- package/dist/frontend/assets/chunk-POPQ4Y6H-CaHDxqyV.js +1 -0
- package/dist/frontend/assets/chunk-SVP7TREG-B8-zByXy.js +88 -0
- package/dist/frontend/assets/chunk-XXDRQBXY-DQLro-7R.js +1 -0
- package/dist/frontend/assets/classDiagram-DTDB5LWJ-Dpwx6IJK.js +1 -0
- package/dist/frontend/assets/classDiagram-d40c83e7-BPxlcZuc.js +2 -0
- package/dist/frontend/assets/classDiagram-v2-JRS7N3AN-Dpwx6IJK.js +1 -0
- package/dist/frontend/assets/classDiagram-v2-d5a6b087-Cyz34qAK.js +2 -0
- package/dist/frontend/assets/clone-Iw0eB1Cb.js +1 -0
- package/dist/frontend/assets/cose-bilkent-JH36ORCC-C4ZX1Xvi.js +1 -0
- package/dist/frontend/assets/createText-d213de94-CDH1rzxH.js +7 -0
- package/dist/frontend/assets/cs-CZ-2BRQDIVT-CGAN69M4.js +11 -0
- package/dist/frontend/assets/cynefin-OW5HDTMX-B8XT9png.js +178 -0
- package/dist/frontend/assets/cynefinDiagram-5FMLGOSQ-COTZjqlj.js +62 -0
- package/dist/frontend/assets/cytoscape-cose-bilkent-D4yGolDn.js +1 -0
- package/dist/frontend/assets/cytoscape.esm-BjAbmLdb.js +331 -0
- package/dist/frontend/assets/da-DK-5WZEPLOC-FIDoeOAn.js +5 -0
- package/dist/frontend/assets/dagre-3AP2YEHR-v8EtxNwx.js +4 -0
- package/dist/frontend/assets/de-DE-XR44H4JA-Hquyrt1G.js +8 -0
- package/dist/frontend/assets/defaultLocale-C4B-KCzX.js +1 -0
- package/dist/frontend/assets/diagram-S7CK7UJ4-BiwOlZBI.js +30 -0
- package/dist/frontend/assets/diagram-UQ7AKVKN-DIfzNs7s.js +41 -0
- package/dist/frontend/assets/diagram-VSXAHHWV-kKkEHy5z.js +3 -0
- package/dist/frontend/assets/diagram-VX7I27RA-zTp2qGKo.js +24 -0
- package/dist/frontend/assets/diagram-Z3DM3KII-hUxSr-QT.js +24 -0
- package/dist/frontend/assets/directory-open-01563666-DWU9wJ6I.js +1 -0
- package/dist/frontend/assets/directory-open-4ed118d0-CunoC1EB.js +1 -0
- package/dist/frontend/assets/ebnfDiagram-PWID7BFC-CRwXBVzS.js +1 -0
- package/dist/frontend/assets/edges-332bd1c7-CbPhghy3.js +4 -0
- package/dist/frontend/assets/el-GR-BZB4AONW-CWRJJANX.js +10 -0
- package/dist/frontend/assets/erDiagram-880f2ed8-CY1dU-f9.js +51 -0
- package/dist/frontend/assets/erDiagram-SSCWMZ5O-BfDW8Lxf.js +99 -0
- package/dist/frontend/assets/es-ES-U4NZUMDT-BwZWIjT5.js +9 -0
- package/dist/frontend/assets/eu-ES-A7QVB2H4-B9suQ9BE.js +11 -0
- package/dist/frontend/assets/fa-IR-HGAKTJCU-tgrKvE4J.js +8 -0
- package/dist/frontend/assets/fi-FI-Z5N7JZ37-Ddoc7R-q.js +6 -0
- package/dist/frontend/assets/file-open-002ab408-DIuFHtCF.js +1 -0
- package/dist/frontend/assets/file-open-7c801643-684qeFg4.js +1 -0
- package/dist/frontend/assets/file-save-3189631c-C1wFhQhH.js +1 -0
- package/dist/frontend/assets/file-save-745eba88-Bb9F9Kg7.js +1 -0
- package/dist/frontend/assets/flowDb-7c981674-DkYacLUz.js +10 -0
- package/dist/frontend/assets/flowDiagram-A5DVABFB-CCBuG42p.js +168 -0
- package/dist/frontend/assets/flowDiagram-cbd28bf7-DhhBmCsw.js +4 -0
- package/dist/frontend/assets/flowDiagram-v2-ffc7f31a-BICbZ5-w.js +1 -0
- package/dist/frontend/assets/flowchart-elk-definition-36e2d292-BsyTsM2Q.js +139 -0
- package/dist/frontend/assets/fr-FR-RHASNOE6-Bzn_6dcd.js +9 -0
- package/dist/frontend/assets/ganttDiagram-04f9e578-CCKAlfpJ.js +257 -0
- package/dist/frontend/assets/ganttDiagram-EL5Y4UJY-B8CXkutd.js +292 -0
- package/dist/frontend/assets/gitGraphDiagram-21fc4d3e-DBAYEQql.js +70 -0
- package/dist/frontend/assets/gitGraphDiagram-WWUBYQGX-Ge5QWjv2.js +106 -0
- package/dist/frontend/assets/gl-ES-HMX3MZ6V-vcZHbFum.js +10 -0
- package/dist/frontend/assets/graph-87dI2d0Q.js +1 -0
- package/dist/frontend/assets/has-D7z5cd7K.js +1 -0
- package/dist/frontend/assets/he-IL-6SHJWFNN-CK07fY3l.js +10 -0
- package/dist/frontend/assets/hi-IN-IWLTKZ5I-CDZ0p7Jv.js +4 -0
- package/dist/frontend/assets/hu-HU-A5ZG7DT2-FH5SLnWy.js +7 -0
- package/dist/frontend/assets/id-ID-SAP4L64H-MjXIXb2f.js +10 -0
- package/dist/frontend/assets/image-blob-reduce.esm-HwCm7IZ0.js +7 -0
- package/dist/frontend/assets/index-6079d271-DiB2AL6F.js +1 -0
- package/dist/frontend/assets/index-BcAUh2Nm.css +1 -0
- package/dist/frontend/assets/index-Biw8Vgb3.js +320 -0
- package/dist/frontend/assets/index-fTyH8AV3.js +354 -0
- package/dist/frontend/assets/infoDiagram-4a4f5b27-BOdJmCUU.js +7 -0
- package/dist/frontend/assets/infoDiagram-RXCK75RN-CNm06Rxs.js +2 -0
- package/dist/frontend/assets/init-Gi6I4Gst.js +1 -0
- package/dist/frontend/assets/ishikawaDiagram-5VMMS53U-DoLWy3n2.js +70 -0
- package/dist/frontend/assets/it-IT-JPQ66NNP-D3n0iaPa.js +11 -0
- package/dist/frontend/assets/ja-JP-DBVTYXUO-ejSNO7M9.js +8 -0
- package/dist/frontend/assets/journeyDiagram-29694f62-Cm6qVjA9.js +139 -0
- package/dist/frontend/assets/journeyDiagram-EYS64GPL-ByZmvOcj.js +139 -0
- package/dist/frontend/assets/kaa-6HZHGXH3-D8l_gwno.js +1 -0
- package/dist/frontend/assets/kab-KAB-ZGHBKWFO-CCdAUgdW.js +8 -0
- package/dist/frontend/assets/kanban-definition-3QL26DDD-Y5ylzca9.js +89 -0
- package/dist/frontend/assets/katex-C5jXJg4s.js +257 -0
- package/dist/frontend/assets/kk-KZ-P5N5QNE5-DeuZqHeo.js +1 -0
- package/dist/frontend/assets/km-KH-HSX4SM5Z-CiG2k5fk.js +11 -0
- package/dist/frontend/assets/ko-KR-MTYHY66A-KQOGYf_l.js +9 -0
- package/dist/frontend/assets/ku-TR-6OUDTVRD-iPec9Wpx.js +9 -0
- package/dist/frontend/assets/layout-ChryVliD.js +1 -0
- package/dist/frontend/assets/layout-chXYHUIV.js +1 -0
- package/dist/frontend/assets/line-V0o6yOnB.js +1 -0
- package/dist/frontend/assets/linear-BvV3B0Vg.js +1 -0
- package/dist/frontend/assets/lt-LT-XHIRWOB4-CATjC2gQ.js +3 -0
- package/dist/frontend/assets/lv-LV-5QDEKY6T-BsDP-7Dd.js +7 -0
- package/dist/frontend/assets/mindmap-definition-FBJOCRG2-z4KcwRlx.js +96 -0
- package/dist/frontend/assets/mindmap-definition-ac74a2e8-C1QU2vBv.js +95 -0
- package/dist/frontend/assets/mr-IN-CRQNXWMA-DWJhwvxv.js +13 -0
- package/dist/frontend/assets/my-MM-5M5IBNSE-DckXEMN8.js +1 -0
- package/dist/frontend/assets/nb-NO-T6EIAALU-HaOR9ZeX.js +10 -0
- package/dist/frontend/assets/nl-NL-IS3SIHDZ-ef_ywpFu.js +8 -0
- package/dist/frontend/assets/nn-NO-6E72VCQL-Bg7QdVqf.js +8 -0
- package/dist/frontend/assets/oc-FR-POXYY2M6-D5HmBPnC.js +8 -0
- package/dist/frontend/assets/ordinal-Cboi1Yqb.js +1 -0
- package/dist/frontend/assets/pa-IN-N4M65BXN-BHYM0tZp.js +4 -0
- package/dist/frontend/assets/path-CbwjOpE9.js +1 -0
- package/dist/frontend/assets/pegDiagram-XKGWAZYB-BL0-JiYs.js +1 -0
- package/dist/frontend/assets/pica-CHpl3DYP.js +7 -0
- package/dist/frontend/assets/pie-b97pL0mM.js +1 -0
- package/dist/frontend/assets/pieDiagram-421022e6-DiRybrxD.js +35 -0
- package/dist/frontend/assets/pieDiagram-E7YTZNPT-VybkpWmu.js +39 -0
- package/dist/frontend/assets/pl-PL-T2D74RX3-uZIVDHgu.js +9 -0
- package/dist/frontend/assets/pt-BR-5N22H2LF-dJVfhAeV.js +9 -0
- package/dist/frontend/assets/pt-PT-UZXXM6DQ-DjJzcznP.js +9 -0
- package/dist/frontend/assets/quadrantDiagram-0957ecba-BHJpECv1.js +7 -0
- package/dist/frontend/assets/quadrantDiagram-AXDQQJYC-RAG8nSkZ.js +7 -0
- package/dist/frontend/assets/railroadDiagram-O6MQD6OU-lCMtporN.js +1 -0
- package/dist/frontend/assets/requirementDiagram-23d650b8-mSFTWSrD.js +52 -0
- package/dist/frontend/assets/requirementDiagram-EFPCY7ZU-B8YnTqPO.js +84 -0
- package/dist/frontend/assets/ro-RO-JPDTUUEW-B5X8VOmp.js +11 -0
- package/dist/frontend/assets/roundRect-0PYZxl1G.js +1 -0
- package/dist/frontend/assets/ru-RU-B4JR7IUQ-Czv9kfuz.js +9 -0
- package/dist/frontend/assets/sankeyDiagram-23345273-B3g3P-D1.js +8 -0
- package/dist/frontend/assets/sankeyDiagram-P5KCCOFB-DRm9HHoQ.js +40 -0
- package/dist/frontend/assets/sankeyLinkHorizontal-CgO6js3K.js +1 -0
- package/dist/frontend/assets/sequenceDiagram-17ac3bff-DzZiSttS.js +122 -0
- package/dist/frontend/assets/sequenceDiagram-WJ2MYXX4-BrSDYDx-.js +162 -0
- package/dist/frontend/assets/si-LK-N5RQ5JYF-DFWOZdgD.js +1 -0
- package/dist/frontend/assets/sizeCapture-X5ZJPWSS-CbaN7yeQ.js +1 -0
- package/dist/frontend/assets/sk-SK-C5VTKIMK-B8VlFn2Z.js +6 -0
- package/dist/frontend/assets/sl-SI-NN7IZMDC-CJeSgLEg.js +6 -0
- package/dist/frontend/assets/stateDiagram-9c5f0230-Dzm1fyzw.js +1 -0
- package/dist/frontend/assets/stateDiagram-HBIQ2CUA-B5Nv-PBX.js +1 -0
- package/dist/frontend/assets/stateDiagram-v2-4QOOHH4V-B72hUL6s.js +1 -0
- package/dist/frontend/assets/stateDiagram-v2-51a3dcff-DvLAYBjA.js +1 -0
- package/dist/frontend/assets/styles-2ab5d517-D6473lhT.js +116 -0
- package/dist/frontend/assets/styles-5f03d8d2-CZ5U9u1n.js +160 -0
- package/dist/frontend/assets/styles-edf9a4b0-DzQC88FF.js +207 -0
- package/dist/frontend/assets/subset-shared.chunk.js +84 -0
- package/dist/frontend/assets/subset-worker.chunk.js +1 -0
- package/dist/frontend/assets/sv-SE-XGPEYMSR-BKMKxZWF.js +10 -0
- package/dist/frontend/assets/svgDrawCommon-3ba9043b-CQsuw6x4.js +1 -0
- package/dist/frontend/assets/swimlanes-XN3QIQJK-D6c81JTS.js +1 -0
- package/dist/frontend/assets/swimlanesDiagram-VK2B7HYN-SMIGSMWR.js +8 -0
- package/dist/frontend/assets/ta-IN-2NMHFXQM-BtPPl3RQ.js +9 -0
- package/dist/frontend/assets/th-TH-HPSO5L25-CSjFGi1j.js +2 -0
- package/dist/frontend/assets/timeline-definition-24CTP7MA-DTBgPsOR.js +120 -0
- package/dist/frontend/assets/timeline-definition-7e6b55e7-D44e8lHF.js +61 -0
- package/dist/frontend/assets/tr-TR-DEFEU3FU-BS1kZ0-G.js +7 -0
- package/dist/frontend/assets/uk-UA-QMV73CPH--ucRdDwc.js +6 -0
- package/dist/frontend/assets/union-DI_iry4-.js +1 -0
- package/dist/frontend/assets/vennDiagram-4TSXK5OY-DDIUJU_f.js +34 -0
- package/dist/frontend/assets/vi-VN-M7AON7JQ-BcGYkPOn.js +5 -0
- package/dist/frontend/assets/wardleyDiagram-VM6X3IG4-TfvrOirV.js +78 -0
- package/dist/frontend/assets/xychartDiagram-S5SC5T6Z-DaSdOJbv.js +7 -0
- package/dist/frontend/assets/xychartDiagram-b6496bcd-VIsyqEG1.js +7 -0
- package/dist/frontend/assets/zh-CN-LNUGB5OW-RL4CyEYU.js +10 -0
- package/dist/frontend/assets/zh-HK-E62DVLB3-DKGVR3J1.js +1 -0
- package/dist/frontend/assets/zh-TW-RAJ6MFWO-C7djgh-M.js +9 -0
- package/dist/frontend/assets/zipObject-Bl99JdSU.js +1 -0
- package/dist/frontend/index.html +569 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +74 -0
- package/dist/index.js.map +1 -0
- package/dist/render/excalidraw-node.mjs +540 -0
- package/dist/server.d.ts +5 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +1684 -0
- package/dist/server.js.map +1 -0
- package/dist/types.d.ts +263 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +49 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/logger.d.ts +4 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +63 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +127 -4
- package/skills/excalidraw-skill/SKILL.md +331 -0
- package/skills/excalidraw-skill/evals/evals.json +35 -0
- package/skills/excalidraw-skill/references/cheatsheet.md +217 -0
- package/src/ai/config.ts +58 -0
- package/src/ai/providers/anthropic.ts +62 -0
- package/src/ai/providers/openai-compatible.ts +84 -0
- package/src/ai/request-settings.ts +50 -0
- package/src/ai/routes.ts +157 -0
- package/src/ai/runner.ts +80 -0
- package/src/ai/sse.ts +40 -0
- package/src/ai/system.ts +16 -0
- package/src/ai/tools.ts +130 -0
- package/src/ai/types.ts +48 -0
- package/src/bin.ts +56 -0
- package/src/cli/args.ts +97 -0
- package/src/cli/commands/ai.ts +40 -0
- package/src/cli/commands/arrange.ts +112 -0
- package/src/cli/commands/canvases.ts +37 -0
- package/src/cli/commands/check.ts +15 -0
- package/src/cli/commands/comment.ts +72 -0
- package/src/cli/commands/elements.ts +299 -0
- package/src/cli/commands/frame.ts +55 -0
- package/src/cli/commands/install-skill.ts +116 -0
- package/src/cli/commands/layout.ts +14 -0
- package/src/cli/commands/render.ts +68 -0
- package/src/cli/commands/scene.ts +168 -0
- package/src/cli/commands/server.ts +71 -0
- package/src/cli/commands/snapshot.ts +45 -0
- package/src/cli/image-options.ts +77 -0
- package/src/cli/run.ts +123 -0
- package/src/cli/util.ts +39 -0
- package/src/core/arrow-routing.ts +256 -0
- package/src/core/bulk-ops.ts +183 -0
- package/src/core/canvas-client.ts +525 -0
- package/src/core/canvas-id.ts +8 -0
- package/src/core/canvas-persistence.ts +1067 -0
- package/src/core/canvas-registry.ts +180 -0
- package/src/core/canvas-routes.ts +34 -0
- package/src/core/canvas-state.ts +37 -0
- package/src/core/canvas.ts +18 -0
- package/src/core/comment-ops.ts +36 -0
- package/src/core/comments.ts +142 -0
- package/src/core/compact.ts +21 -0
- package/src/core/config.ts +24 -0
- package/src/core/describe.ts +100 -0
- package/src/core/design-guide.ts +114 -0
- package/src/core/diagram-layout.ts +278 -0
- package/src/core/diagram-ops.ts +48 -0
- package/src/core/entry.ts +37 -0
- package/src/core/expand-elements.ts +316 -0
- package/src/core/frame-ops.ts +112 -0
- package/src/core/frames.ts +113 -0
- package/src/core/geometry.ts +213 -0
- package/src/core/layout-check.ts +200 -0
- package/src/core/local-origin.ts +27 -0
- package/src/core/mcp-dispatch.ts +858 -0
- package/src/core/mcp-http.ts +38 -0
- package/src/core/mcp-server.ts +72 -0
- package/src/core/mcp-tools.ts +725 -0
- package/src/core/normalize.ts +158 -0
- package/src/core/obsidian-md.ts +231 -0
- package/src/core/pidfile.ts +52 -0
- package/src/core/png-scene.ts +177 -0
- package/src/core/render/excalidraw-node/dom.ts +159 -0
- package/src/core/render/excalidraw-node/index.ts +100 -0
- package/src/core/render/fonts.ts +173 -0
- package/src/core/render/index.ts +198 -0
- package/src/core/render/png-worker.ts +75 -0
- package/src/core/render/png.ts +148 -0
- package/src/core/render/text-metrics.ts +141 -0
- package/src/core/request-canvas.ts +10 -0
- package/src/core/request-headers.ts +79 -0
- package/src/core/scene-input.ts +11 -0
- package/src/core/scene-io.ts +125 -0
- package/src/core/share-url.ts +99 -0
- package/src/core/spawn.ts +186 -0
- package/src/core/version.ts +13 -0
- package/src/index.ts +86 -0
- package/src/server.ts +1873 -0
- package/src/types.ts +384 -0
- package/src/utils/logger.ts +77 -0
|
@@ -0,0 +1,854 @@
|
|
|
1
|
+
import { closeSync, existsSync, fsyncSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmdirSync, unlinkSync, writeFileSync, } from 'node:fs';
|
|
2
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
|
+
const STATE_SCHEMA_VERSION = 1;
|
|
5
|
+
export const STATE_FILE_NAME = 'canvas-state-v1.json';
|
|
6
|
+
const LOCK_FILE_NAME = 'canvas-state.lock';
|
|
7
|
+
const BLOB_DIRECTORY_NAME = 'blobs';
|
|
8
|
+
const SHA256_PATTERN = /^[a-f0-9]{64}$/;
|
|
9
|
+
const DATA_URL_MIME_PATTERN = /^data:([^;,]+)(?:;[^,]*)?,/i;
|
|
10
|
+
export class CanvasPersistenceError extends Error {
|
|
11
|
+
name = 'CanvasPersistenceError';
|
|
12
|
+
constructor(cause) {
|
|
13
|
+
// Surface the cause: this message is the route's error response.
|
|
14
|
+
const detail = cause instanceof Error ? cause.message : String(cause);
|
|
15
|
+
super(`Failed to checkpoint canvas state: ${detail}`, { cause });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
class CanvasCheckpointPublicationError extends Error {
|
|
19
|
+
constructor(cause) {
|
|
20
|
+
super('Checkpoint was published but its directory flush failed; restart required', { cause });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class CanvasFileImmutabilityError extends Error {
|
|
24
|
+
name = 'CanvasFileImmutabilityError';
|
|
25
|
+
constructor(fileId) {
|
|
26
|
+
super(`Canvas file ${fileId} is immutable and cannot be replaced`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export class CanvasFileReferenceError extends Error {
|
|
30
|
+
name = 'CanvasFileReferenceError';
|
|
31
|
+
constructor(fileId) {
|
|
32
|
+
super(`Canvas image references missing file ${fileId}; upload the file before the element`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
let ownedLock = null;
|
|
36
|
+
const loadedCanvases = new WeakSet();
|
|
37
|
+
// A canvas whose checkpoint was published but failed after the rename stays fenced until a restart.
|
|
38
|
+
const fencedCanvases = new WeakSet();
|
|
39
|
+
// Cache verified/published immutable blob metadata. Entries intentionally
|
|
40
|
+
// survive runtime deletion because orphan blobs are retained and a file id may
|
|
41
|
+
// never be rebound to different bytes later in the same authority. A cheap
|
|
42
|
+
// lstat on later mutations avoids re-reading unchanged base64 payloads while
|
|
43
|
+
// still detecting missing/replaced files during the running process.
|
|
44
|
+
const knownDurableBlobs = new Map();
|
|
45
|
+
export function durableStateDirectory() {
|
|
46
|
+
const configured = process.env.EXCALIDRAW_DATA_DIR?.trim();
|
|
47
|
+
return configured ? resolve(configured) : null;
|
|
48
|
+
}
|
|
49
|
+
export function durableStateEnabled() {
|
|
50
|
+
return durableStateDirectory() !== null;
|
|
51
|
+
}
|
|
52
|
+
function compareStrings(left, right) {
|
|
53
|
+
if (left < right)
|
|
54
|
+
return -1;
|
|
55
|
+
if (left > right)
|
|
56
|
+
return 1;
|
|
57
|
+
return 0;
|
|
58
|
+
}
|
|
59
|
+
function sha256(value) {
|
|
60
|
+
return createHash('sha256').update(value, 'utf8').digest('hex');
|
|
61
|
+
}
|
|
62
|
+
function blobRelativePath(fileId) {
|
|
63
|
+
return `${BLOB_DIRECTORY_NAME}/${sha256(fileId)}.blob`;
|
|
64
|
+
}
|
|
65
|
+
// A removed canvas's directory may be created again, and its cached blobs would then look missing.
|
|
66
|
+
export function forgetDurableBlobs(dataDirectory) {
|
|
67
|
+
for (const key of knownDurableBlobs.keys()) {
|
|
68
|
+
if (key.startsWith(`${dataDirectory}\0`))
|
|
69
|
+
knownDurableBlobs.delete(key);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function durableFileCacheKey(dataDirectory, fileId) {
|
|
73
|
+
return `${dataDirectory}\0${fileId}`;
|
|
74
|
+
}
|
|
75
|
+
function isRecord(value) {
|
|
76
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
77
|
+
}
|
|
78
|
+
function assertExactKeys(value, expected, label) {
|
|
79
|
+
const actual = Object.keys(value).sort();
|
|
80
|
+
const canonicalExpected = [...expected].sort();
|
|
81
|
+
if (actual.length !== canonicalExpected.length ||
|
|
82
|
+
actual.some((key, index) => key !== canonicalExpected[index])) {
|
|
83
|
+
throw new Error(`${label} has unsupported fields: ${actual.join(', ')}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function assertFiniteNumber(value, label) {
|
|
87
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
88
|
+
throw new Error(`${label} must be a finite number`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function assertNonNegativeSafeInteger(value, label) {
|
|
92
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
93
|
+
throw new Error(`${label} must be a non-negative safe integer`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function canonicalize(value, stack = new Set()) {
|
|
97
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean') {
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
if (typeof value === 'number') {
|
|
101
|
+
if (!Number.isFinite(value)) {
|
|
102
|
+
throw new Error('Canvas state contains a non-finite number');
|
|
103
|
+
}
|
|
104
|
+
return Object.is(value, -0) ? 0 : value;
|
|
105
|
+
}
|
|
106
|
+
if (typeof value === 'undefined') {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
if (typeof value !== 'object') {
|
|
110
|
+
throw new Error(`Canvas state contains an unsupported ${typeof value} value`);
|
|
111
|
+
}
|
|
112
|
+
if (stack.has(value)) {
|
|
113
|
+
throw new Error('Canvas state contains a cyclic value');
|
|
114
|
+
}
|
|
115
|
+
stack.add(value);
|
|
116
|
+
try {
|
|
117
|
+
if (Array.isArray(value)) {
|
|
118
|
+
return value.map(item => {
|
|
119
|
+
const canonical = canonicalize(item, stack);
|
|
120
|
+
return canonical === undefined ? null : canonical;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
const prototype = Object.getPrototypeOf(value);
|
|
124
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
125
|
+
throw new Error('Canvas state contains a non-plain object');
|
|
126
|
+
}
|
|
127
|
+
// A null-prototype object preserves literal keys such as `__proto__`
|
|
128
|
+
// instead of invoking Object.prototype setters during canonicalization.
|
|
129
|
+
const result = Object.create(null);
|
|
130
|
+
for (const key of Object.keys(value).sort()) {
|
|
131
|
+
const canonical = canonicalize(value[key], stack);
|
|
132
|
+
if (canonical !== undefined) {
|
|
133
|
+
result[key] = canonical;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
stack.delete(value);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function stableStringify(value) {
|
|
143
|
+
return `${JSON.stringify(canonicalize(value), null, 2)}\n`;
|
|
144
|
+
}
|
|
145
|
+
function fsyncDirectory(directory) {
|
|
146
|
+
if (process.platform === 'win32')
|
|
147
|
+
return;
|
|
148
|
+
const descriptor = openSync(directory, 'r');
|
|
149
|
+
try {
|
|
150
|
+
fsyncSync(descriptor);
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
closeSync(descriptor);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function assertRealDirectory(directory, label) {
|
|
157
|
+
const metadata = lstatSync(directory);
|
|
158
|
+
if (!metadata.isDirectory() || metadata.isSymbolicLink()) {
|
|
159
|
+
throw new Error(`${label} is not a real directory: ${directory}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function ensurePrivateDirectory(directory) {
|
|
163
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
164
|
+
assertRealDirectory(directory, 'Canvas durable path');
|
|
165
|
+
}
|
|
166
|
+
function assertRegularFile(path, label) {
|
|
167
|
+
const metadata = lstatSync(path);
|
|
168
|
+
if (!metadata.isFile() || metadata.isSymbolicLink()) {
|
|
169
|
+
throw new Error(`${label} is not a regular file: ${path}`);
|
|
170
|
+
}
|
|
171
|
+
return metadata;
|
|
172
|
+
}
|
|
173
|
+
function rememberDurableBlob(cacheKey, digest, metadata) {
|
|
174
|
+
knownDurableBlobs.set(cacheKey, {
|
|
175
|
+
digest,
|
|
176
|
+
size: metadata.size,
|
|
177
|
+
mtimeMs: metadata.mtimeMs,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
function removeIfPresent(path) {
|
|
181
|
+
try {
|
|
182
|
+
unlinkSync(path);
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
if (error.code !== 'ENOENT')
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function validateRuntimeFile(file) {
|
|
190
|
+
if (!file || typeof file !== 'object') {
|
|
191
|
+
throw new Error('Canvas files map contains a non-object value');
|
|
192
|
+
}
|
|
193
|
+
if (typeof file.id !== 'string' || file.id.length === 0) {
|
|
194
|
+
throw new Error('Canvas file has an invalid id');
|
|
195
|
+
}
|
|
196
|
+
if (typeof file.dataURL !== 'string' || file.dataURL.length === 0) {
|
|
197
|
+
throw new Error(`Canvas file ${file.id} has an invalid dataURL`);
|
|
198
|
+
}
|
|
199
|
+
if (typeof file.mimeType !== 'string' || file.mimeType.length === 0) {
|
|
200
|
+
throw new Error(`Canvas file ${file.id} has an invalid mimeType`);
|
|
201
|
+
}
|
|
202
|
+
const encodedMimeType = DATA_URL_MIME_PATTERN.exec(file.dataURL)?.[1];
|
|
203
|
+
if (!encodedMimeType || encodedMimeType.toLowerCase() !== file.mimeType.toLowerCase()) {
|
|
204
|
+
throw new Error(`Canvas file ${file.id} dataURL does not match its mimeType`);
|
|
205
|
+
}
|
|
206
|
+
assertNonNegativeSafeInteger(file.created, `Canvas file ${file.id} created`);
|
|
207
|
+
}
|
|
208
|
+
function verifyBlob(path, dataDirectory, fileId, expectedDataURL, expectedDigest) {
|
|
209
|
+
const metadata = assertRegularFile(path, `Canvas file ${fileId}`);
|
|
210
|
+
const actualDataURL = readFileSync(path, 'utf8');
|
|
211
|
+
const actualDigest = sha256(actualDataURL);
|
|
212
|
+
if (actualDigest !== expectedDigest || actualDataURL !== expectedDataURL) {
|
|
213
|
+
throw new CanvasFileImmutabilityError(fileId);
|
|
214
|
+
}
|
|
215
|
+
rememberDurableBlob(durableFileCacheKey(dataDirectory, fileId), actualDigest, metadata);
|
|
216
|
+
}
|
|
217
|
+
function ensureBlobDurable(file, dataDirectory) {
|
|
218
|
+
validateRuntimeFile(file);
|
|
219
|
+
const blobDirectory = join(dataDirectory, BLOB_DIRECTORY_NAME);
|
|
220
|
+
ensurePrivateDirectory(blobDirectory);
|
|
221
|
+
const relativePath = blobRelativePath(file.id);
|
|
222
|
+
const finalPath = join(dataDirectory, relativePath);
|
|
223
|
+
const contentDigest = sha256(file.dataURL);
|
|
224
|
+
const cacheKey = durableFileCacheKey(dataDirectory, file.id);
|
|
225
|
+
const knownBlob = knownDurableBlobs.get(cacheKey);
|
|
226
|
+
if (knownBlob !== undefined) {
|
|
227
|
+
if (knownBlob.digest !== contentDigest) {
|
|
228
|
+
throw new CanvasFileImmutabilityError(file.id);
|
|
229
|
+
}
|
|
230
|
+
if (!existsSync(finalPath)) {
|
|
231
|
+
throw new Error(`Canvas file ${file.id} is missing or unreadable`);
|
|
232
|
+
}
|
|
233
|
+
const metadata = assertRegularFile(finalPath, `Canvas file ${file.id}`);
|
|
234
|
+
if (metadata.size !== knownBlob.size || metadata.mtimeMs !== knownBlob.mtimeMs) {
|
|
235
|
+
verifyBlob(finalPath, dataDirectory, file.id, file.dataURL, contentDigest);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else if (existsSync(finalPath)) {
|
|
239
|
+
verifyBlob(finalPath, dataDirectory, file.id, file.dataURL, contentDigest);
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
const temporaryPath = join(blobDirectory, `.tmp-${process.pid}-${randomUUID()}.blob`);
|
|
243
|
+
let descriptor = null;
|
|
244
|
+
try {
|
|
245
|
+
descriptor = openSync(temporaryPath, 'wx', 0o600);
|
|
246
|
+
writeFileSync(descriptor, file.dataURL, 'utf8');
|
|
247
|
+
fsyncSync(descriptor);
|
|
248
|
+
closeSync(descriptor);
|
|
249
|
+
descriptor = null;
|
|
250
|
+
try {
|
|
251
|
+
// Hard-link publication gives us atomic no-clobber semantics. If a
|
|
252
|
+
// competing process somehow published first, verify the immutable
|
|
253
|
+
// target rather than overwriting it.
|
|
254
|
+
linkSync(temporaryPath, finalPath);
|
|
255
|
+
fsyncDirectory(blobDirectory);
|
|
256
|
+
rememberDurableBlob(cacheKey, contentDigest, lstatSync(finalPath));
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
if (error.code !== 'EEXIST')
|
|
260
|
+
throw error;
|
|
261
|
+
verifyBlob(finalPath, dataDirectory, file.id, file.dataURL, contentDigest);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
finally {
|
|
265
|
+
if (descriptor !== null)
|
|
266
|
+
closeSync(descriptor);
|
|
267
|
+
removeIfPresent(temporaryPath);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
id: file.id,
|
|
272
|
+
blob: relativePath,
|
|
273
|
+
sha256: contentDigest,
|
|
274
|
+
mimeType: file.mimeType,
|
|
275
|
+
created: file.created,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function currentDurableState(canvas, dataDirectory) {
|
|
279
|
+
const { elements, files, snapshots, comments } = canvas;
|
|
280
|
+
const durableElements = Array.from(elements.entries()).map(([key, element]) => {
|
|
281
|
+
if (element.id !== key) {
|
|
282
|
+
throw new Error(`Canvas elements map key does not match element id: ${key}`);
|
|
283
|
+
}
|
|
284
|
+
return element;
|
|
285
|
+
});
|
|
286
|
+
validateElementArray(durableElements, 'Canvas runtime elements');
|
|
287
|
+
const durableSnapshots = Array.from(snapshots.entries())
|
|
288
|
+
.map(([key, snapshot]) => {
|
|
289
|
+
if (snapshot.name !== key) {
|
|
290
|
+
throw new Error(`Canvas snapshots map key does not match snapshot name: ${key}`);
|
|
291
|
+
}
|
|
292
|
+
return snapshot;
|
|
293
|
+
})
|
|
294
|
+
.sort((left, right) => compareStrings(left.name, right.name));
|
|
295
|
+
validateSnapshotArray(durableSnapshots, 'Canvas runtime snapshots');
|
|
296
|
+
const runtimeFileEntries = Array.from(files.entries())
|
|
297
|
+
.sort(([left], [right]) => compareStrings(left, right));
|
|
298
|
+
for (const [key, file] of runtimeFileEntries) {
|
|
299
|
+
if (file.id !== key) {
|
|
300
|
+
throw new Error(`Canvas files map key does not match file id: ${key}`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
validateFileReferences(durableElements, durableSnapshots, new Set(runtimeFileEntries.map(([fileId]) => fileId)), 'Canvas runtime');
|
|
304
|
+
const durableFiles = runtimeFileEntries.map(([, file]) => ensureBlobDurable(file, dataDirectory));
|
|
305
|
+
return {
|
|
306
|
+
schemaVersion: STATE_SCHEMA_VERSION,
|
|
307
|
+
// Map insertion order is the server's scene order and therefore must be
|
|
308
|
+
// preserved. Canonicalization sorts object keys inside each element only.
|
|
309
|
+
elements: durableElements,
|
|
310
|
+
files: durableFiles,
|
|
311
|
+
snapshots: durableSnapshots,
|
|
312
|
+
comments: validateCommentArray(Array.from(comments.values()), 'Canvas runtime comments'),
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
function writeStateFile(canvas, dataDirectory) {
|
|
316
|
+
const statePath = join(dataDirectory, STATE_FILE_NAME);
|
|
317
|
+
const serialized = stableStringify(currentDurableState(canvas, dataDirectory));
|
|
318
|
+
const temporaryPath = join(dataDirectory, `.tmp-${process.pid}-${randomUUID()}.json`);
|
|
319
|
+
let descriptor = null;
|
|
320
|
+
let published = false;
|
|
321
|
+
try {
|
|
322
|
+
descriptor = openSync(temporaryPath, 'wx', 0o600);
|
|
323
|
+
writeFileSync(descriptor, serialized, 'utf8');
|
|
324
|
+
fsyncSync(descriptor);
|
|
325
|
+
closeSync(descriptor);
|
|
326
|
+
descriptor = null;
|
|
327
|
+
renameSync(temporaryPath, statePath);
|
|
328
|
+
published = true;
|
|
329
|
+
fsyncDirectory(dataDirectory);
|
|
330
|
+
}
|
|
331
|
+
catch (error) {
|
|
332
|
+
if (descriptor !== null)
|
|
333
|
+
closeSync(descriptor);
|
|
334
|
+
removeIfPresent(temporaryPath);
|
|
335
|
+
if (published)
|
|
336
|
+
throw new CanvasCheckpointPublicationError(error);
|
|
337
|
+
throw error;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
function processIsRunning(pid) {
|
|
341
|
+
try {
|
|
342
|
+
process.kill(pid, 0);
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
catch (error) {
|
|
346
|
+
return error.code !== 'ESRCH';
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
function lockOwnerFileName(token) {
|
|
350
|
+
return `owner-${token}.json`;
|
|
351
|
+
}
|
|
352
|
+
function readLockOwner(lockDirectory) {
|
|
353
|
+
assertRealDirectory(lockDirectory, 'Canvas data-directory lock');
|
|
354
|
+
let entries;
|
|
355
|
+
try {
|
|
356
|
+
entries = readdirSync(lockDirectory);
|
|
357
|
+
}
|
|
358
|
+
catch (error) {
|
|
359
|
+
throw new Error(`Canvas data directory has an unreadable lock directory: ${error.message}`);
|
|
360
|
+
}
|
|
361
|
+
// An empty directory can exist only in the short interval between atomic
|
|
362
|
+
// mkdir and owner-file publication (or after a crash in that interval).
|
|
363
|
+
// Removing it is safe: a concurrent acquirer whose empty shell is removed
|
|
364
|
+
// will fail its owner-file write and retry without ever claiming ownership.
|
|
365
|
+
if (entries.length === 0)
|
|
366
|
+
return null;
|
|
367
|
+
if (entries.length !== 1) {
|
|
368
|
+
throw new Error('Canvas data directory has an invalid lock directory');
|
|
369
|
+
}
|
|
370
|
+
const ownerFileName = entries[0];
|
|
371
|
+
const match = /^owner-([0-9a-f-]{36})\.json$/.exec(ownerFileName);
|
|
372
|
+
if (!match) {
|
|
373
|
+
throw new Error('Canvas data directory has an invalid lock directory');
|
|
374
|
+
}
|
|
375
|
+
const tokenFromName = match[1];
|
|
376
|
+
const ownerPath = join(lockDirectory, ownerFileName);
|
|
377
|
+
assertRegularFile(ownerPath, 'Canvas data-directory lock owner');
|
|
378
|
+
let value;
|
|
379
|
+
try {
|
|
380
|
+
value = JSON.parse(readFileSync(ownerPath, 'utf8'));
|
|
381
|
+
}
|
|
382
|
+
catch (error) {
|
|
383
|
+
throw new Error(`Canvas data directory has an unreadable lock owner: ${error.message}`);
|
|
384
|
+
}
|
|
385
|
+
if (!isRecord(value)) {
|
|
386
|
+
throw new Error('Canvas data directory has an invalid lock owner');
|
|
387
|
+
}
|
|
388
|
+
try {
|
|
389
|
+
assertExactKeys(value, ['pid', 'token'], 'Canvas data directory lock owner');
|
|
390
|
+
}
|
|
391
|
+
catch {
|
|
392
|
+
throw new Error('Canvas data directory has an invalid lock owner');
|
|
393
|
+
}
|
|
394
|
+
if (!Number.isSafeInteger(value.pid) || value.pid <= 0 ||
|
|
395
|
+
typeof value.token !== 'string' || value.token !== tokenFromName) {
|
|
396
|
+
throw new Error('Canvas data directory has an invalid lock owner');
|
|
397
|
+
}
|
|
398
|
+
return {
|
|
399
|
+
pid: value.pid,
|
|
400
|
+
token: value.token,
|
|
401
|
+
ownerPath,
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
function removeEmptyLockDirectory(lockDirectory) {
|
|
405
|
+
try {
|
|
406
|
+
rmdirSync(lockDirectory);
|
|
407
|
+
fsyncDirectory(dirname(lockDirectory));
|
|
408
|
+
return true;
|
|
409
|
+
}
|
|
410
|
+
catch (error) {
|
|
411
|
+
const code = error.code;
|
|
412
|
+
if (code === 'ENOENT' || code === 'ENOTEMPTY' || code === 'EEXIST') {
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
415
|
+
throw error;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
export function acquireDurableStateLock() {
|
|
419
|
+
const dataDirectory = durableStateDirectory();
|
|
420
|
+
if (!dataDirectory)
|
|
421
|
+
return;
|
|
422
|
+
if (ownedLock) {
|
|
423
|
+
throw new Error('Canvas data directory lock was already acquired in this process');
|
|
424
|
+
}
|
|
425
|
+
ensurePrivateDirectory(dataDirectory);
|
|
426
|
+
const lockDirectory = join(dataDirectory, LOCK_FILE_NAME);
|
|
427
|
+
const token = randomUUID();
|
|
428
|
+
const ownerPath = join(lockDirectory, lockOwnerFileName(token));
|
|
429
|
+
for (let attempt = 0; attempt < 12; attempt += 1) {
|
|
430
|
+
let createdDirectory = false;
|
|
431
|
+
let descriptor = null;
|
|
432
|
+
try {
|
|
433
|
+
// mkdir is the cross-platform, atomic no-clobber ownership primitive.
|
|
434
|
+
// The token-specific owner filename makes stale reclamation race-safe:
|
|
435
|
+
// a reclaimer can unlink only the owner it actually observed, never a
|
|
436
|
+
// newer process's owner file created after the directory was recycled.
|
|
437
|
+
mkdirSync(lockDirectory, { mode: 0o700 });
|
|
438
|
+
createdDirectory = true;
|
|
439
|
+
descriptor = openSync(ownerPath, 'wx', 0o600);
|
|
440
|
+
writeFileSync(descriptor, stableStringify({ pid: process.pid, token }), 'utf8');
|
|
441
|
+
fsyncSync(descriptor);
|
|
442
|
+
closeSync(descriptor);
|
|
443
|
+
descriptor = null;
|
|
444
|
+
fsyncDirectory(lockDirectory);
|
|
445
|
+
fsyncDirectory(dataDirectory);
|
|
446
|
+
ownedLock = { directory: lockDirectory, ownerPath, token };
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
catch (error) {
|
|
450
|
+
if (descriptor !== null)
|
|
451
|
+
closeSync(descriptor);
|
|
452
|
+
const code = error.code;
|
|
453
|
+
if (createdDirectory) {
|
|
454
|
+
removeIfPresent(ownerPath);
|
|
455
|
+
removeEmptyLockDirectory(lockDirectory);
|
|
456
|
+
// A concurrent stale reclaimer may remove the just-created empty
|
|
457
|
+
// directory before our owner file is published. Retrying is safe.
|
|
458
|
+
if (code === 'ENOENT' || code === 'EEXIST')
|
|
459
|
+
continue;
|
|
460
|
+
throw error;
|
|
461
|
+
}
|
|
462
|
+
if (code !== 'EEXIST')
|
|
463
|
+
throw error;
|
|
464
|
+
const owner = readLockOwner(lockDirectory);
|
|
465
|
+
if (owner === null) {
|
|
466
|
+
removeEmptyLockDirectory(lockDirectory);
|
|
467
|
+
continue;
|
|
468
|
+
}
|
|
469
|
+
if (processIsRunning(owner.pid)) {
|
|
470
|
+
throw new Error(`Canvas data directory is already owned by process ${owner.pid}`);
|
|
471
|
+
}
|
|
472
|
+
// Delete exactly the stale token-specific owner observed above. If a
|
|
473
|
+
// different process has already recycled the directory, this unlink
|
|
474
|
+
// targets a path that no longer exists and cannot remove the new owner.
|
|
475
|
+
try {
|
|
476
|
+
unlinkSync(owner.ownerPath);
|
|
477
|
+
}
|
|
478
|
+
catch (unlinkError) {
|
|
479
|
+
if (unlinkError.code !== 'ENOENT') {
|
|
480
|
+
throw unlinkError;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
removeEmptyLockDirectory(lockDirectory);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
throw new Error('Failed to acquire canvas data directory lock');
|
|
487
|
+
}
|
|
488
|
+
export function releaseDurableStateLock() {
|
|
489
|
+
if (!ownedLock)
|
|
490
|
+
return;
|
|
491
|
+
const lock = ownedLock;
|
|
492
|
+
ownedLock = null;
|
|
493
|
+
try {
|
|
494
|
+
if (!existsSync(lock.directory))
|
|
495
|
+
return;
|
|
496
|
+
const currentOwner = readLockOwner(lock.directory);
|
|
497
|
+
if (currentOwner?.token !== lock.token || currentOwner.ownerPath !== lock.ownerPath) {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
unlinkSync(lock.ownerPath);
|
|
501
|
+
removeEmptyLockDirectory(lock.directory);
|
|
502
|
+
}
|
|
503
|
+
catch (error) {
|
|
504
|
+
if (error.code !== 'ENOENT')
|
|
505
|
+
throw error;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
function validateElementArray(value, label) {
|
|
509
|
+
if (!Array.isArray(value)) {
|
|
510
|
+
throw new Error(`${label} must be an array`);
|
|
511
|
+
}
|
|
512
|
+
const seen = new Set();
|
|
513
|
+
for (const element of value) {
|
|
514
|
+
if (!isRecord(element) ||
|
|
515
|
+
typeof element.id !== 'string' || element.id.length === 0 ||
|
|
516
|
+
// Any non-empty type: the sync endpoint accepts native Excalidraw
|
|
517
|
+
// types the server enum omits (embeddable, iframe, magicframe), and a
|
|
518
|
+
// checkpoint must be able to hold whatever the canvas accepted.
|
|
519
|
+
typeof element.type !== 'string' || element.type.length === 0 ||
|
|
520
|
+
typeof element.x !== 'number' || !Number.isFinite(element.x) ||
|
|
521
|
+
typeof element.y !== 'number' || !Number.isFinite(element.y)) {
|
|
522
|
+
throw new Error(`${label} contains an invalid element`);
|
|
523
|
+
}
|
|
524
|
+
if (seen.has(element.id)) {
|
|
525
|
+
throw new Error(`${label} contains duplicate element id ${element.id}`);
|
|
526
|
+
}
|
|
527
|
+
seen.add(element.id);
|
|
528
|
+
}
|
|
529
|
+
return value;
|
|
530
|
+
}
|
|
531
|
+
function referencedImageFileIds(value, label) {
|
|
532
|
+
const result = new Set();
|
|
533
|
+
for (const element of value) {
|
|
534
|
+
if (element.type !== 'image' || element.isDeleted === true)
|
|
535
|
+
continue;
|
|
536
|
+
const fileId = element.fileId;
|
|
537
|
+
if (typeof fileId !== 'string' || fileId.length === 0) {
|
|
538
|
+
throw new Error(`${label} contains an image with an invalid fileId`);
|
|
539
|
+
}
|
|
540
|
+
result.add(fileId);
|
|
541
|
+
}
|
|
542
|
+
return result;
|
|
543
|
+
}
|
|
544
|
+
function validateFileReferences(sceneElements, sceneSnapshots, availableFileIds, label) {
|
|
545
|
+
const referenced = referencedImageFileIds(sceneElements, `${label} elements`);
|
|
546
|
+
for (const snapshot of sceneSnapshots) {
|
|
547
|
+
for (const fileId of referencedImageFileIds(snapshot.elements, `${label} snapshot ${snapshot.name}`)) {
|
|
548
|
+
referenced.add(fileId);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
for (const fileId of referenced) {
|
|
552
|
+
if (!availableFileIds.has(fileId)) {
|
|
553
|
+
throw new CanvasFileReferenceError(fileId);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
function parseFileRecord(value) {
|
|
558
|
+
if (!isRecord(value)) {
|
|
559
|
+
throw new Error('Canvas state contains an invalid file record');
|
|
560
|
+
}
|
|
561
|
+
assertExactKeys(value, ['id', 'blob', 'sha256', 'mimeType', 'created'], 'Canvas file record');
|
|
562
|
+
if (typeof value.id !== 'string' || value.id.length === 0) {
|
|
563
|
+
throw new Error('Canvas file record has an invalid id');
|
|
564
|
+
}
|
|
565
|
+
if (typeof value.blob !== 'string' || value.blob !== blobRelativePath(value.id)) {
|
|
566
|
+
throw new Error(`Canvas file ${value.id} has an invalid blob reference`);
|
|
567
|
+
}
|
|
568
|
+
if (typeof value.sha256 !== 'string' || !SHA256_PATTERN.test(value.sha256)) {
|
|
569
|
+
throw new Error(`Canvas file ${value.id} has an invalid sha256`);
|
|
570
|
+
}
|
|
571
|
+
if (typeof value.mimeType !== 'string' || value.mimeType.length === 0) {
|
|
572
|
+
throw new Error(`Canvas file ${value.id} has an invalid mimeType`);
|
|
573
|
+
}
|
|
574
|
+
assertNonNegativeSafeInteger(value.created, `Canvas file ${value.id} created`);
|
|
575
|
+
return {
|
|
576
|
+
id: value.id,
|
|
577
|
+
blob: value.blob,
|
|
578
|
+
sha256: value.sha256,
|
|
579
|
+
mimeType: value.mimeType,
|
|
580
|
+
created: value.created,
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
function validateSnapshotArray(value, label) {
|
|
584
|
+
if (!Array.isArray(value)) {
|
|
585
|
+
throw new Error(`${label} must be an array`);
|
|
586
|
+
}
|
|
587
|
+
const seen = new Set();
|
|
588
|
+
return value.map((snapshot, index) => {
|
|
589
|
+
if (!isRecord(snapshot)) {
|
|
590
|
+
throw new Error(`${label} contains an invalid snapshot at index ${index}`);
|
|
591
|
+
}
|
|
592
|
+
assertExactKeys(snapshot, ['name', 'elements', 'createdAt'], 'Canvas snapshot');
|
|
593
|
+
if (typeof snapshot.name !== 'string' || snapshot.name.length === 0 ||
|
|
594
|
+
typeof snapshot.createdAt !== 'string' || snapshot.createdAt.length === 0) {
|
|
595
|
+
throw new Error(`${label} contains an invalid snapshot at index ${index}`);
|
|
596
|
+
}
|
|
597
|
+
if (seen.has(snapshot.name)) {
|
|
598
|
+
throw new Error(`${label} contains duplicate snapshot ${snapshot.name}`);
|
|
599
|
+
}
|
|
600
|
+
seen.add(snapshot.name);
|
|
601
|
+
validateElementArray(snapshot.elements, `Canvas snapshot ${snapshot.name} elements`);
|
|
602
|
+
return snapshot;
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
function validateCommentArray(value, label) {
|
|
606
|
+
if (!Array.isArray(value)) {
|
|
607
|
+
throw new Error(`${label} must be an array`);
|
|
608
|
+
}
|
|
609
|
+
const seen = new Set();
|
|
610
|
+
return value.map((comment, index) => {
|
|
611
|
+
if (!isRecord(comment)) {
|
|
612
|
+
throw new Error(`${label} contains an invalid comment at index ${index}`);
|
|
613
|
+
}
|
|
614
|
+
const anchored = 'anchorElementId' in comment;
|
|
615
|
+
assertExactKeys(comment, ['id', 'x', 'y', 'status', 'messages', 'createdAt', 'updatedAt', ...(anchored ? ['anchorElementId', 'dx', 'dy'] : [])], 'Canvas comment');
|
|
616
|
+
assertFiniteNumber(comment.x, 'Canvas comment x');
|
|
617
|
+
assertFiniteNumber(comment.y, 'Canvas comment y');
|
|
618
|
+
if (anchored) {
|
|
619
|
+
assertFiniteNumber(comment.dx, 'Canvas comment dx');
|
|
620
|
+
assertFiniteNumber(comment.dy, 'Canvas comment dy');
|
|
621
|
+
}
|
|
622
|
+
if (typeof comment.id !== 'string' || comment.id.length === 0 ||
|
|
623
|
+
(anchored && (typeof comment.anchorElementId !== 'string' || comment.anchorElementId.length === 0)) ||
|
|
624
|
+
(comment.status !== 'open' && comment.status !== 'resolved') ||
|
|
625
|
+
typeof comment.createdAt !== 'string' || typeof comment.updatedAt !== 'string' ||
|
|
626
|
+
!Array.isArray(comment.messages) || comment.messages.length === 0) {
|
|
627
|
+
throw new Error(`${label} contains an invalid comment at index ${index}`);
|
|
628
|
+
}
|
|
629
|
+
if (seen.has(comment.id)) {
|
|
630
|
+
throw new Error(`${label} contains duplicate comment ${comment.id}`);
|
|
631
|
+
}
|
|
632
|
+
seen.add(comment.id);
|
|
633
|
+
for (const message of comment.messages) {
|
|
634
|
+
if (!isRecord(message))
|
|
635
|
+
throw new Error(`Canvas comment ${comment.id} has an invalid message`);
|
|
636
|
+
assertExactKeys(message, ['from', 'text', 'at'], 'Canvas comment message');
|
|
637
|
+
if ((message.from !== 'user' && message.from !== 'agent') ||
|
|
638
|
+
typeof message.text !== 'string' || typeof message.at !== 'string') {
|
|
639
|
+
throw new Error(`Canvas comment ${comment.id} has an invalid message`);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
return comment;
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
function parseSnapshotArray(value) {
|
|
646
|
+
return validateSnapshotArray(value, 'Canvas state snapshots');
|
|
647
|
+
}
|
|
648
|
+
function parseDurableState(raw) {
|
|
649
|
+
let value;
|
|
650
|
+
try {
|
|
651
|
+
value = JSON.parse(raw);
|
|
652
|
+
}
|
|
653
|
+
catch (error) {
|
|
654
|
+
throw new Error(`Canvas state is not valid JSON: ${error.message}`);
|
|
655
|
+
}
|
|
656
|
+
if (!isRecord(value)) {
|
|
657
|
+
throw new Error('Canvas state must be a JSON object');
|
|
658
|
+
}
|
|
659
|
+
// Checkpoints written before comments existed have no comments field.
|
|
660
|
+
assertExactKeys(value, ['schemaVersion', 'elements', 'files', 'snapshots', ...('comments' in value ? ['comments'] : [])], 'Canvas state');
|
|
661
|
+
if (value.schemaVersion !== STATE_SCHEMA_VERSION) {
|
|
662
|
+
throw new Error(`Unsupported canvas state schema: ${String(value.schemaVersion)}`);
|
|
663
|
+
}
|
|
664
|
+
if (!Array.isArray(value.files)) {
|
|
665
|
+
throw new Error('Canvas state files must be an array');
|
|
666
|
+
}
|
|
667
|
+
const parsedFiles = value.files.map(parseFileRecord);
|
|
668
|
+
const seenFileIds = new Set();
|
|
669
|
+
for (const file of parsedFiles) {
|
|
670
|
+
if (seenFileIds.has(file.id)) {
|
|
671
|
+
throw new Error(`Canvas state contains duplicate file id ${file.id}`);
|
|
672
|
+
}
|
|
673
|
+
seenFileIds.add(file.id);
|
|
674
|
+
}
|
|
675
|
+
const parsedElements = validateElementArray(value.elements, 'Canvas state elements');
|
|
676
|
+
const parsedSnapshots = parseSnapshotArray(value.snapshots);
|
|
677
|
+
validateFileReferences(parsedElements, parsedSnapshots, seenFileIds, 'Canvas state');
|
|
678
|
+
return {
|
|
679
|
+
schemaVersion: STATE_SCHEMA_VERSION,
|
|
680
|
+
elements: parsedElements,
|
|
681
|
+
files: parsedFiles,
|
|
682
|
+
snapshots: parsedSnapshots,
|
|
683
|
+
comments: validateCommentArray('comments' in value ? value.comments : [], 'Canvas state comments'),
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
function hydrateFile(record, dataDirectory) {
|
|
687
|
+
const blobPath = join(dataDirectory, record.blob);
|
|
688
|
+
if (!existsSync(blobPath)) {
|
|
689
|
+
throw new Error(`Canvas file ${record.id} is missing or unreadable`);
|
|
690
|
+
}
|
|
691
|
+
assertRegularFile(blobPath, `Canvas file ${record.id}`);
|
|
692
|
+
let dataURL;
|
|
693
|
+
try {
|
|
694
|
+
dataURL = readFileSync(blobPath, 'utf8');
|
|
695
|
+
}
|
|
696
|
+
catch (error) {
|
|
697
|
+
throw new Error(`Canvas file ${record.id} is missing or unreadable: ${error.message}`);
|
|
698
|
+
}
|
|
699
|
+
if (sha256(dataURL) !== record.sha256) {
|
|
700
|
+
throw new Error(`Canvas file ${record.id} failed blob integrity verification`);
|
|
701
|
+
}
|
|
702
|
+
const hydrated = {
|
|
703
|
+
id: record.id,
|
|
704
|
+
dataURL,
|
|
705
|
+
mimeType: record.mimeType,
|
|
706
|
+
created: record.created,
|
|
707
|
+
};
|
|
708
|
+
validateRuntimeFile(hydrated);
|
|
709
|
+
rememberDurableBlob(durableFileCacheKey(dataDirectory, record.id), record.sha256, lstatSync(blobPath));
|
|
710
|
+
return hydrated;
|
|
711
|
+
}
|
|
712
|
+
function replaceMap(target, source) {
|
|
713
|
+
target.clear();
|
|
714
|
+
source.forEach((value, key) => target.set(key, value));
|
|
715
|
+
}
|
|
716
|
+
function captureRuntimeState({ elements, files, snapshots, comments }) {
|
|
717
|
+
return {
|
|
718
|
+
elements: structuredClone(elements),
|
|
719
|
+
// File payload strings are immutable; clone each record object without
|
|
720
|
+
// duplicating every base64 payload on unrelated element mutations.
|
|
721
|
+
files: new Map(Array.from(files, ([fileId, file]) => [fileId, { ...file }])),
|
|
722
|
+
snapshots: structuredClone(snapshots),
|
|
723
|
+
comments: structuredClone(comments),
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
function restoreRuntimeState({ elements, files, snapshots, comments }, backup) {
|
|
727
|
+
replaceMap(elements, backup.elements);
|
|
728
|
+
replaceMap(files, backup.files);
|
|
729
|
+
replaceMap(snapshots, backup.snapshots);
|
|
730
|
+
replaceMap(comments, backup.comments);
|
|
731
|
+
}
|
|
732
|
+
function requireOwnedLock() {
|
|
733
|
+
const dataDirectory = durableStateDirectory();
|
|
734
|
+
if (dataDirectory && ownedLock?.directory !== join(dataDirectory, LOCK_FILE_NAME)) {
|
|
735
|
+
throw new Error('Canvas durable state lock must be held before loading or checkpointing');
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
function requireInitializedState(canvas) {
|
|
739
|
+
const dataDirectory = durableStateDirectory();
|
|
740
|
+
if (!dataDirectory ||
|
|
741
|
+
ownedLock?.directory !== join(dataDirectory, LOCK_FILE_NAME) ||
|
|
742
|
+
!loadedCanvases.has(canvas)) {
|
|
743
|
+
throw new Error('Canvas durable state must be locked and loaded before mutations');
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
export function commitCanvasMutation(canvas, mutate) {
|
|
747
|
+
const dataDirectory = canvas.dir;
|
|
748
|
+
if (!dataDirectory)
|
|
749
|
+
return mutate();
|
|
750
|
+
if (fencedCanvases.has(canvas)) {
|
|
751
|
+
throw new CanvasPersistenceError(new Error('Canvas persistence requires a restart after a publication failure'));
|
|
752
|
+
}
|
|
753
|
+
requireInitializedState(canvas);
|
|
754
|
+
const backup = captureRuntimeState(canvas);
|
|
755
|
+
let value;
|
|
756
|
+
try {
|
|
757
|
+
value = mutate();
|
|
758
|
+
}
|
|
759
|
+
catch (error) {
|
|
760
|
+
restoreRuntimeState(canvas, backup);
|
|
761
|
+
throw error;
|
|
762
|
+
}
|
|
763
|
+
try {
|
|
764
|
+
// currentDurableState() publishes any new immutable blobs before the
|
|
765
|
+
// checkpoint that references them. Before-publication failures restore the
|
|
766
|
+
// runtime maps; already-durable unreferenced blobs are safe.
|
|
767
|
+
writeStateFile(canvas, dataDirectory);
|
|
768
|
+
}
|
|
769
|
+
catch (error) {
|
|
770
|
+
if (error instanceof CanvasCheckpointPublicationError) {
|
|
771
|
+
// rename already made this scene visible on disk. Rolling back only the
|
|
772
|
+
// maps would make the running scene disagree with restart recovery. Keep
|
|
773
|
+
// the published scene, reject this request, and fence further mutations
|
|
774
|
+
// until an operator restarts and validates the store. No success or
|
|
775
|
+
// broadcast escapes the caller's error path.
|
|
776
|
+
fencedCanvases.add(canvas);
|
|
777
|
+
throw new CanvasPersistenceError(error);
|
|
778
|
+
}
|
|
779
|
+
restoreRuntimeState(canvas, backup);
|
|
780
|
+
if (error instanceof CanvasFileImmutabilityError ||
|
|
781
|
+
error instanceof CanvasFileReferenceError) {
|
|
782
|
+
throw error;
|
|
783
|
+
}
|
|
784
|
+
throw new CanvasPersistenceError(error);
|
|
785
|
+
}
|
|
786
|
+
return value;
|
|
787
|
+
}
|
|
788
|
+
export function loadDurableState(canvas) {
|
|
789
|
+
const { elements, files, snapshots, comments } = canvas;
|
|
790
|
+
if (loadedCanvases.has(canvas)) {
|
|
791
|
+
throw new Error('Canvas durable state was already loaded in this process');
|
|
792
|
+
}
|
|
793
|
+
const dataDirectory = canvas.dir;
|
|
794
|
+
if (!dataDirectory) {
|
|
795
|
+
loadedCanvases.add(canvas);
|
|
796
|
+
return {
|
|
797
|
+
enabled: false,
|
|
798
|
+
loaded: false,
|
|
799
|
+
path: null,
|
|
800
|
+
elements: elements.size,
|
|
801
|
+
files: files.size,
|
|
802
|
+
snapshots: snapshots.size,
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
requireOwnedLock();
|
|
806
|
+
const statePath = join(dataDirectory, STATE_FILE_NAME);
|
|
807
|
+
let hasCheckpoint = true;
|
|
808
|
+
try {
|
|
809
|
+
assertRegularFile(statePath, 'Canvas state path');
|
|
810
|
+
}
|
|
811
|
+
catch (error) {
|
|
812
|
+
if (error.code === 'ENOENT') {
|
|
813
|
+
hasCheckpoint = false;
|
|
814
|
+
}
|
|
815
|
+
else {
|
|
816
|
+
throw error;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
if (!hasCheckpoint) {
|
|
820
|
+
// A configured directory with no checkpoint is a new empty authority.
|
|
821
|
+
// Do not inherit module-level state prepared before the lock was acquired.
|
|
822
|
+
elements.clear();
|
|
823
|
+
files.clear();
|
|
824
|
+
snapshots.clear();
|
|
825
|
+
comments.clear();
|
|
826
|
+
loadedCanvases.add(canvas);
|
|
827
|
+
return {
|
|
828
|
+
enabled: true,
|
|
829
|
+
loaded: false,
|
|
830
|
+
path: statePath,
|
|
831
|
+
elements: 0,
|
|
832
|
+
files: 0,
|
|
833
|
+
snapshots: 0,
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
const state = parseDurableState(readFileSync(statePath, 'utf8'));
|
|
837
|
+
const restoredElements = new Map(state.elements.map(element => [element.id, element]));
|
|
838
|
+
const restoredFiles = new Map(state.files.map(record => [record.id, hydrateFile(record, dataDirectory)]));
|
|
839
|
+
const restoredSnapshots = new Map(state.snapshots.map(snapshot => [snapshot.name, snapshot]));
|
|
840
|
+
replaceMap(elements, restoredElements);
|
|
841
|
+
replaceMap(files, restoredFiles);
|
|
842
|
+
replaceMap(snapshots, restoredSnapshots);
|
|
843
|
+
replaceMap(comments, new Map(state.comments.map(comment => [comment.id, comment])));
|
|
844
|
+
loadedCanvases.add(canvas);
|
|
845
|
+
return {
|
|
846
|
+
enabled: true,
|
|
847
|
+
loaded: true,
|
|
848
|
+
path: statePath,
|
|
849
|
+
elements: elements.size,
|
|
850
|
+
files: files.size,
|
|
851
|
+
snapshots: snapshots.size,
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
//# sourceMappingURL=canvas-persistence.js.map
|