@dooc-dev/dooc 0.0.7 → 0.0.8
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/client.global.js +1 -0
- package/dist/code-worker.global.js +11 -11
- package/dist/code.global.js +75 -75
- package/dist/edit.global.js +234 -231
- package/dist/{compiler → engine/compiler}/bundle-urls.js +1 -4
- package/dist/{compiler → engine/compiler}/check-prose.d.ts +1 -1
- package/dist/{compiler → engine/compiler}/check-prose.js +1 -1
- package/dist/{compiler → engine/compiler}/check.js +15 -27
- package/dist/{compiler → engine/compiler}/code-blocks.js +3 -1
- package/dist/{compiler → engine/compiler}/code-languages.js +1 -2
- package/dist/{compiler → engine/compiler}/compile.d.ts +5 -4
- package/dist/{compiler → engine/compiler}/compile.js +91 -32
- package/dist/{compiler → engine/compiler}/config.js +1 -3
- package/dist/{compiler → engine/compiler}/dialect.d.ts +1 -3
- package/dist/{compiler → engine/compiler}/dialect.js +8 -52
- package/dist/{compiler → engine/compiler}/dxf.js +1 -1
- package/dist/{compiler → engine/compiler}/export.js +15 -8
- package/dist/{compiler → engine/compiler}/figures.js +26 -22
- package/dist/{compiler → engine/compiler}/file-cache.d.ts +1 -2
- package/dist/{compiler → engine/compiler}/file-cache.js +8 -15
- package/dist/{compiler → engine/compiler}/files.js +49 -38
- package/dist/{compiler → engine/compiler}/fonts.js +1 -3
- package/dist/{compiler → engine/compiler}/from-mdast.js +1 -1
- package/dist/engine/compiler/host.d.ts +10 -0
- package/dist/engine/compiler/host.js +16 -0
- package/dist/{compiler → engine/compiler}/icons.d.ts +3 -0
- package/dist/{compiler → engine/compiler}/icons.js +28 -10
- package/dist/{compiler → engine/compiler}/ignored-files.d.ts +2 -0
- package/dist/{compiler → engine/compiler}/ignored-files.js +12 -3
- package/dist/{compiler → engine/compiler}/locales.js +2 -8
- package/dist/{compiler → engine/compiler}/manifest.d.ts +3 -2
- package/dist/engine/compiler/manifest.js +46 -0
- package/dist/{compiler → engine/compiler}/ops.d.ts +4 -1
- package/dist/{compiler → engine/compiler}/ops.js +36 -21
- package/dist/engine/compiler/schema-file-references.d.ts +2 -0
- package/dist/engine/compiler/schema-file-references.js +82 -0
- package/dist/engine/compiler/serialize.d.ts +2 -0
- package/dist/engine/compiler/serialize.js +5 -0
- package/dist/{compiler → engine/compiler}/subformat-schema.js +1 -3
- package/dist/{compiler → engine/compiler}/subformats.d.ts +10 -0
- package/dist/{compiler → engine/compiler}/subformats.js +122 -18
- package/dist/{compiler → engine/compiler}/textfile-remote.js +1 -2
- package/dist/{compiler → engine/compiler}/textfile.js +4 -6
- package/dist/{compiler → engine/compiler}/theme-variants.js +1 -1
- package/dist/{compiler → engine/compiler}/zip.js +1 -1
- package/dist/{core → engine/core}/blocks.d.ts +6 -4
- package/dist/{core → engine/core}/content-metadata.d.ts +6 -1
- package/dist/{core → engine/core}/content-metadata.js +84 -18
- package/dist/{core → engine/core}/content-types.d.ts +4 -2
- package/dist/{core → engine/core}/html.d.ts +7 -0
- package/dist/{core → engine/core}/html.js +44 -3
- package/dist/{core → engine/core}/icons.d.ts +3 -0
- package/dist/engine/core/icons.js +20 -0
- package/dist/{core → engine/core}/routing.d.ts +2 -0
- package/dist/{core → engine/core}/routing.js +9 -0
- package/dist/{core → engine/core}/schema-refs.d.ts +1 -1
- package/dist/{core → engine/core}/schema-refs.js +3 -1
- package/dist/engine/core/subformat-references.d.ts +5 -0
- package/dist/engine/core/subformat-references.js +33 -0
- package/dist/{core → engine/core}/subformats.d.ts +7 -0
- package/dist/{core → engine/core}/subformats.js +5 -1
- package/dist/{core → engine/core}/taxonomy.d.ts +2 -3
- package/dist/{core → engine/core}/taxonomy.js +1 -5
- package/dist/flow.global.js +306 -306
- package/dist/frontend/application-request.d.ts +14 -0
- package/dist/frontend/application-request.js +36 -0
- package/dist/frontend/document-application.d.ts +200 -0
- package/dist/{viewer/serve.js → frontend/document-application.js} +1611 -1670
- package/dist/frontend/figure-preview.d.ts +4 -0
- package/dist/{viewer → frontend}/figure-preview.js +4 -4
- package/dist/{viewer → frontend}/file-references.d.ts +1 -1
- package/dist/{viewer → frontend}/file-references.js +3 -3
- package/dist/{viewer → frontend}/font-picker.d.ts +1 -1
- package/dist/{viewer → frontend}/font-settings.d.ts +1 -1
- package/dist/{viewer → frontend}/language-picker.js +112 -18
- package/dist/{viewer → frontend}/locales/eng.json +16 -2
- package/dist/{viewer → frontend}/locales/jpn.json +16 -2
- package/dist/{viewer → frontend}/locales/zho.json +16 -2
- package/dist/{viewer → frontend}/nav-focus.js +2 -0
- package/dist/{viewer → frontend}/plugin-blocks.js +2 -2
- package/dist/{viewer → frontend}/resize.js +14 -2
- package/dist/frontend/resource-download.d.ts +2 -0
- package/dist/frontend/resource-download.js +43 -0
- package/dist/{viewer → frontend}/resource-library.d.ts +9 -2
- package/dist/{viewer → frontend}/resource-library.js +133 -37
- package/dist/{core → frontend}/schema-graph-flow.d.ts +1 -1
- package/dist/{core → frontend}/schema-graph-flow.js +1 -1
- package/dist/{viewer → frontend}/search.d.ts +2 -2
- package/dist/{viewer → frontend}/search.js +26 -8
- package/dist/graph/schema-graph-global.js +17 -17
- package/dist/install.sh +68 -0
- package/dist/plugins.global.js +62 -62
- package/dist/{viewer → server}/assets.d.ts +2 -0
- package/dist/server/assets.js +7 -0
- package/dist/{viewer → server}/build-plugins.js +4 -4
- package/dist/{viewer → server}/build.d.ts +2 -1
- package/dist/{viewer → server}/build.js +31 -15
- package/dist/{cli.js → server/cli.js} +199 -66
- package/dist/server/editor-tools.d.ts +1 -0
- package/dist/server/editor-tools.js +1 -0
- package/dist/{viewer → server}/extension-pack.js +2 -2
- package/dist/{viewer → server}/extensions.d.ts +1 -1
- package/dist/{viewer → server}/extensions.js +3 -3
- package/dist/server/git-diff.d.ts +10 -0
- package/dist/{viewer → server}/git-diff.js +45 -10
- package/dist/server/git-origin.d.ts +4 -0
- package/dist/server/git-origin.js +103 -0
- package/dist/server/git.d.ts +9 -0
- package/dist/{viewer → server}/git.js +50 -6
- package/dist/server/history.d.ts +14 -0
- package/dist/server/history.js +205 -0
- package/dist/{viewer → server}/hmr.d.ts +0 -22
- package/dist/server/hmr.js +168 -0
- package/dist/server/index.d.ts +17 -0
- package/dist/{index.js → server/index.js} +16 -16
- package/dist/{viewer → server}/ja-lint.d.ts +1 -1
- package/dist/{viewer → server}/languages.d.ts +1 -1
- package/dist/{viewer → server}/languages.js +3 -3
- package/dist/{mcp.d.ts → server/mcp.d.ts} +2 -2
- package/dist/{mcp.js → server/mcp.js} +60 -21
- package/dist/{viewer → server}/plugin-config.d.ts +2 -2
- package/dist/{viewer → server}/plugin-config.js +2 -2
- package/dist/{plugins → server/plugins}/local-storage.d.ts +1 -1
- package/dist/{plugins → server/plugins}/local-storage.js +1 -1
- package/dist/{plugins → server/plugins}/runtime.d.ts +4 -4
- package/dist/{plugins → server/plugins}/runtime.js +4 -4
- package/dist/{viewer → server}/plugins.d.ts +3 -3
- package/dist/{viewer → server}/plugins.js +14 -13
- package/dist/server/resource-library.d.ts +1 -0
- package/dist/server/resource-library.js +1 -0
- package/dist/server/self.d.ts +5 -0
- package/dist/server/self.js +98 -0
- package/dist/server/serve.d.ts +61 -0
- package/dist/server/serve.js +503 -0
- package/dist/server/static-client.d.ts +4 -0
- package/dist/server/static-client.js +117 -0
- package/dist/server/workspace-server.d.ts +16 -0
- package/dist/server/workspace-server.js +266 -0
- package/dist/{viewer → server}/workspace.d.ts +6 -1
- package/dist/{viewer → server}/workspace.js +46 -0
- package/dist/subformats.global.js +92 -6
- package/dist/ui.global.js +85 -72
- package/dist/workspace/client.d.ts +13 -0
- package/dist/workspace/client.js +114 -0
- package/dist/{viewer → workspace}/code-file.d.ts +1 -1
- package/dist/{viewer → workspace}/code-file.js +7 -7
- package/dist/workspace/connection.d.ts +27 -0
- package/dist/workspace/connection.js +38 -0
- package/dist/{viewer → workspace}/editor-tools.d.ts +7 -1
- package/dist/{viewer → workspace}/editor-tools.js +12 -9
- package/dist/{viewer → workspace}/git-types.d.ts +7 -0
- package/dist/workspace/github.d.ts +4 -0
- package/dist/workspace/github.js +99 -0
- package/dist/workspace/history.d.ts +46 -0
- package/dist/workspace/history.js +86 -0
- package/dist/workspace/protocol.d.ts +38 -0
- package/dist/workspace/protocol.js +20 -0
- package/dist/workspace/resource-download.d.ts +1 -0
- package/dist/workspace/resource-download.js +8 -0
- package/dist/workspace/server.d.ts +9 -0
- package/dist/workspace/server.js +48 -0
- package/dist/{viewer → workspace}/site-icon.js +9 -10
- package/dist/{viewer → workspace}/site-title.js +6 -7
- package/dist/{viewer → workspace}/textfile.d.ts +1 -1
- package/dist/{viewer → workspace}/textfile.js +5 -5
- package/dist/workspace-worker.global.js +2859 -0
- package/package.json +34 -20
- package/dist/compiler/manifest.js +0 -37
- package/dist/compiler/serialize.d.ts +0 -3
- package/dist/compiler/serialize.js +0 -16
- package/dist/core/icons.js +0 -5
- package/dist/index.d.ts +0 -17
- package/dist/viewer/assets.js +0 -3
- package/dist/viewer/figure-preview.d.ts +0 -4
- package/dist/viewer/git-diff.d.ts +0 -6
- package/dist/viewer/git.d.ts +0 -5
- package/dist/viewer/hmr.js +0 -341
- package/dist/viewer/serve.d.ts +0 -216
- /package/dist/{compiler → engine/compiler}/asset-references.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/asset-references.js +0 -0
- /package/dist/{compiler → engine/compiler}/bundle-urls.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/check-types.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/check-types.js +0 -0
- /package/dist/{compiler → engine/compiler}/check.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/code-blocks.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/code-languages.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/config.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/drawio.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/drawio.js +0 -0
- /package/dist/{compiler → engine/compiler}/dxf.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/export.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/figures.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/files.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/fonts.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/format.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/format.js +0 -0
- /package/dist/{compiler → engine/compiler}/from-mdast.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/language-codes.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/language-codes.js +0 -0
- /package/dist/{compiler → engine/compiler}/locales.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/public-file.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/public-file.js +0 -0
- /package/dist/{compiler → engine/compiler}/subformat-schema.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/terms.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/terms.js +0 -0
- /package/dist/{compiler → engine/compiler}/textfile-remote.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/textfile.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/theme-variants.d.ts +0 -0
- /package/dist/{compiler → engine/compiler}/zip.d.ts +0 -0
- /package/dist/{core → engine/core}/blocks.js +0 -0
- /package/dist/{core → engine/core}/code-file.d.ts +0 -0
- /package/dist/{core → engine/core}/code-file.js +0 -0
- /package/dist/{core → engine/core}/code-grammars.d.ts +0 -0
- /package/dist/{core → engine/core}/code-grammars.js +0 -0
- /package/dist/{core → engine/core}/content-types.js +0 -0
- /package/dist/{core → engine/core}/escape-html.d.ts +0 -0
- /package/dist/{core → engine/core}/escape-html.js +0 -0
- /package/dist/{core → engine/core}/extension-package.d.ts +0 -0
- /package/dist/{core → engine/core}/extension-package.js +0 -0
- /package/dist/{core → engine/core}/figure-frame.d.ts +0 -0
- /package/dist/{core → engine/core}/figure-frame.js +0 -0
- /package/dist/{core → engine/core}/file-embed.d.ts +0 -0
- /package/dist/{core → engine/core}/file-embed.js +0 -0
- /package/dist/{core → engine/core}/files.d.ts +0 -0
- /package/dist/{core → engine/core}/files.js +0 -0
- /package/dist/{core → engine/core}/graph-common.d.ts +0 -0
- /package/dist/{core → engine/core}/graph-common.js +0 -0
- /package/dist/{core → engine/core}/graph.d.ts +0 -0
- /package/dist/{core → engine/core}/graph.js +0 -0
- /package/dist/{core → engine/core}/inline.d.ts +0 -0
- /package/dist/{core → engine/core}/inline.js +0 -0
- /package/dist/{core → engine/core}/json-tools.d.ts +0 -0
- /package/dist/{core → engine/core}/json-tools.js +0 -0
- /package/dist/{core → engine/core}/language.d.ts +0 -0
- /package/dist/{core → engine/core}/language.js +0 -0
- /package/dist/{core → engine/core}/languages/ja.d.ts +0 -0
- /package/dist/{core → engine/core}/languages/ja.js +0 -0
- /package/dist/{core → engine/core}/markdown.d.ts +0 -0
- /package/dist/{core → engine/core}/markdown.js +0 -0
- /package/dist/{core → engine/core}/previewers.d.ts +0 -0
- /package/dist/{core → engine/core}/previewers.js +0 -0
- /package/dist/{core → engine/core}/schema-comments.d.ts +0 -0
- /package/dist/{core → engine/core}/schema-comments.js +0 -0
- /package/dist/{core → engine/core}/schema-fields.d.ts +0 -0
- /package/dist/{core → engine/core}/schema-fields.js +0 -0
- /package/dist/{core → engine/core}/schema-graph.d.ts +0 -0
- /package/dist/{core → engine/core}/schema-graph.js +0 -0
- /package/dist/{core → engine/core}/subformat-record.d.ts +0 -0
- /package/dist/{core → engine/core}/subformat-record.js +0 -0
- /package/dist/{core → engine/core}/term-reference.d.ts +0 -0
- /package/dist/{core → engine/core}/term-reference.js +0 -0
- /package/dist/{core → engine/core}/textfile.d.ts +0 -0
- /package/dist/{core → engine/core}/textfile.js +0 -0
- /package/dist/{core → engine/core}/theme-variants.d.ts +0 -0
- /package/dist/{core → engine/core}/theme-variants.js +0 -0
- /package/dist/{core → engine/core}/workspace.d.ts +0 -0
- /package/dist/{core → engine/core}/workspace.js +0 -0
- /package/dist/{viewer → frontend}/bundle-network.d.ts +0 -0
- /package/dist/{viewer → frontend}/bundle-network.js +0 -0
- /package/dist/{core → frontend}/flow-base-css.generated.d.ts +0 -0
- /package/dist/{core → frontend}/flow-base-css.generated.js +0 -0
- /package/dist/{core → frontend}/flow-css.d.ts +0 -0
- /package/dist/{core → frontend}/flow-css.js +0 -0
- /package/dist/{viewer → frontend}/font-picker.js +0 -0
- /package/dist/{viewer → frontend}/font-settings.js +0 -0
- /package/dist/{viewer → frontend}/i18n.d.ts +0 -0
- /package/dist/{viewer → frontend}/i18n.js +0 -0
- /package/dist/{viewer → frontend}/language-picker.d.ts +0 -0
- /package/dist/{viewer → frontend}/lazy-preview.d.ts +0 -0
- /package/dist/{viewer → frontend}/lazy-preview.js +0 -0
- /package/dist/{viewer → frontend}/nav-focus.d.ts +0 -0
- /package/dist/{viewer → frontend}/nav-update.d.ts +0 -0
- /package/dist/{viewer → frontend}/nav-update.js +0 -0
- /package/dist/{viewer → frontend}/plugin-blocks.d.ts +0 -0
- /package/dist/{viewer → frontend}/plugin-style.d.ts +0 -0
- /package/dist/{viewer → frontend}/plugin-style.js +0 -0
- /package/dist/{viewer → frontend}/plugin-view.d.ts +0 -0
- /package/dist/{viewer → frontend}/plugin-view.js +0 -0
- /package/dist/{viewer → frontend}/resize.d.ts +0 -0
- /package/dist/{core → frontend}/schema-graph-mount.d.ts +0 -0
- /package/dist/{core → frontend}/schema-graph-mount.js +0 -0
- /package/dist/{core → frontend}/table-ui.d.ts +0 -0
- /package/dist/{core → frontend}/table-ui.js +0 -0
- /package/dist/{core → frontend}/terms-ui.d.ts +0 -0
- /package/dist/{core → frontend}/terms-ui.js +0 -0
- /package/dist/{viewer → frontend}/theme-picker.d.ts +0 -0
- /package/dist/{viewer → frontend}/theme-picker.js +0 -0
- /package/dist/{core → frontend}/toc-ui.d.ts +0 -0
- /package/dist/{core → frontend}/toc-ui.js +0 -0
- /package/dist/{core → frontend}/video-ui.d.ts +0 -0
- /package/dist/{core → frontend}/video-ui.js +0 -0
- /package/dist/{viewer → server}/build-plugins.d.ts +0 -0
- /package/dist/{cli.d.ts → server/cli.d.ts} +0 -0
- /package/dist/{viewer → server}/extension-pack.d.ts +0 -0
- /package/dist/{viewer → server}/fonts/LICENSE.txt +0 -0
- /package/dist/{viewer → server}/fonts/udev-gothic-regular.woff2 +0 -0
- /package/dist/{viewer → server}/fonts.d.ts +0 -0
- /package/dist/{viewer → server}/fonts.js +0 -0
- /package/dist/{viewer → server}/ja-lint.js +0 -0
- /package/dist/{viewer → workspace}/git-types.js +0 -0
- /package/dist/{viewer → workspace}/site-icon.d.ts +0 -0
- /package/dist/{viewer → workspace}/site-title.d.ts +0 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// HMR for the dev server (shared by preview / edit). Classifies and watches changes; serve.ts
|
|
2
|
+
// broadcasts them as workspace "change" events and hmr-client.ts applies them. By source:
|
|
3
|
+
// data side (content/*.md, dooc.yaml, figures/*) = picked up by this module's watcher;
|
|
4
|
+
// preview swaps only the main body + nav (keeping scroll). edit likewise does a partial
|
|
5
|
+
// update of just the body + nav (no reload; keeps CodeMirror cursor/scroll/undo and
|
|
6
|
+
// unsaved content) — only on pages where edit-client.ts registered `onContent`
|
|
7
|
+
// (unregistered, e.g. the new page, reloads).
|
|
8
|
+
// client bundle side (src/viewer/edit-client.ts, src/core/*.tsx = bundle sources of the schema
|
|
9
|
+
// graph interaction layer `/assets/graph.js`) = not imported by the server (esbuild
|
|
10
|
+
// bundles them on demand), so tsx watch doesn't react → the data-side watcher picks
|
|
11
|
+
// them up as "client" and triggers a reload.
|
|
12
|
+
// server side (all other src/*.ts) = tsx watch restarts the whole process, so not watched.
|
|
13
|
+
// The client notices the swap from the bootId difference in `hello` on reconnect and
|
|
14
|
+
// reloads.
|
|
15
|
+
// All content events reach the editor, which compares disk contents with its saved base.
|
|
16
|
+
import { existsSync, readFileSync, realpathSync, unwatchFile, watch, watchFile } from "node:fs";
|
|
17
|
+
import { dirname, join, resolve } from "node:path";
|
|
18
|
+
import { managedFile } from "../engine/compiler/files.js";
|
|
19
|
+
import { textfilePath } from "../engine/compiler/textfile.js";
|
|
20
|
+
import { isManifestFile } from "../engine/core/content-metadata.js";
|
|
21
|
+
import { isRemoteTextfile } from "../engine/core/textfile.js";
|
|
22
|
+
import { prebuilt } from "./assets.js";
|
|
23
|
+
import { gitHeadFile } from "./workspace.js";
|
|
24
|
+
/**
|
|
25
|
+
* Changed path (repo-root relative) → HMR kind. undefined for out-of-scope files
|
|
26
|
+
* (dist output, temp files etc.).
|
|
27
|
+
*/
|
|
28
|
+
export const classifyChange = (rel) => {
|
|
29
|
+
const p = rel.replace(/\\/g, "/");
|
|
30
|
+
// Browser-only sources are bundled per request, not imported by the server, so `tsx watch`
|
|
31
|
+
// never restarts for them; classify them as "client" to trigger a reload. Everything else
|
|
32
|
+
// under packages/ is server-side: the restart changes the boot id and the page reloads.
|
|
33
|
+
if (/^packages\/frontend\/src\/.+\.(tsx?|json)$/.test(p) ||
|
|
34
|
+
p === "packages/workspace/src/client.ts") {
|
|
35
|
+
return "client";
|
|
36
|
+
}
|
|
37
|
+
// content = body text (.md) and dooc.yaml (= SoT for hierarchy and ordering).
|
|
38
|
+
if (isManifestFile(p) || (p.startsWith("content/") && p.endsWith(".md"))) {
|
|
39
|
+
return "content";
|
|
40
|
+
}
|
|
41
|
+
if (p.startsWith("locales/") && p.endsWith(".md"))
|
|
42
|
+
return "content";
|
|
43
|
+
if (p.startsWith("figures/") && /\.(svg|html|png|webp|jpe?g)$/.test(p)) {
|
|
44
|
+
return "content";
|
|
45
|
+
}
|
|
46
|
+
// icons/<id>.svg (doc icons) is data side too = partial update.
|
|
47
|
+
if (p.startsWith("icons/") && p.endsWith(".svg")) {
|
|
48
|
+
return "content";
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Folders to watch. The docs-side ones are relative to docsRoot, src to pkgRoot (only files that
|
|
54
|
+
* classifyChange marks "client" count).
|
|
55
|
+
*/
|
|
56
|
+
/**
|
|
57
|
+
* Notifies data-side changes batched by kind. An editor save fires multiple events
|
|
58
|
+
* (rename + change), so debounce collapses them into one. Referenced text files can be added
|
|
59
|
+
* as drafts are compiled; close() releases all watchers.
|
|
60
|
+
*/
|
|
61
|
+
export const watchProject = (docsRoot, pkgRoot, onChange, debounceMs = 60) => {
|
|
62
|
+
const pending = new Map();
|
|
63
|
+
let timer;
|
|
64
|
+
const flush = () => {
|
|
65
|
+
timer = undefined;
|
|
66
|
+
const byKind = new Map();
|
|
67
|
+
for (const [file, kind] of pending) {
|
|
68
|
+
byKind.set(kind, [...(byKind.get(kind) ?? []), file]);
|
|
69
|
+
}
|
|
70
|
+
pending.clear();
|
|
71
|
+
for (const [kind, files] of byKind) {
|
|
72
|
+
onChange(kind, files);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const note = (rel, kind = classifyChange(rel)) => {
|
|
76
|
+
if (!kind) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
pending.set(rel, kind);
|
|
80
|
+
if (!timer) {
|
|
81
|
+
timer = setTimeout(flush, debounceMs);
|
|
82
|
+
timer.unref();
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
// Skip missing folders (checkouts / test fixtures without optional asset folders) to avoid ENOENT.
|
|
86
|
+
const dirs = [["packages", join(pkgRoot, "packages")]];
|
|
87
|
+
const watchers = dirs
|
|
88
|
+
.filter(([, abs]) => !prebuilt && existsSync(abs))
|
|
89
|
+
.map(([dir, abs]) => watch(abs, { recursive: true }, (_event, name) => {
|
|
90
|
+
if (name) {
|
|
91
|
+
note(`${dir}/${String(name)}`);
|
|
92
|
+
}
|
|
93
|
+
}));
|
|
94
|
+
// Watch the directory so atomic replacements of the manifest are detected too.
|
|
95
|
+
watchers.push(watch(docsRoot, { recursive: true }, (_event, name) => {
|
|
96
|
+
if (!name)
|
|
97
|
+
return;
|
|
98
|
+
const path = String(name).replaceAll("\\", "/");
|
|
99
|
+
if (isManifestFile(path) ||
|
|
100
|
+
path.startsWith("locales/") ||
|
|
101
|
+
/(^|\/)\.gitignore$/.test(path))
|
|
102
|
+
note(path, "content");
|
|
103
|
+
else if (managedFile(path) && !path.startsWith("src/") && !/\.(tmp|swp)$/.test(path))
|
|
104
|
+
note(path, "content");
|
|
105
|
+
}));
|
|
106
|
+
const textfiles = new Map();
|
|
107
|
+
const headFile = gitHeadFile(docsRoot);
|
|
108
|
+
if (headFile) {
|
|
109
|
+
for (let parent = realpathSync(docsRoot); !existsSync(join(parent, ".git"));) {
|
|
110
|
+
const next = dirname(parent);
|
|
111
|
+
if (next === parent)
|
|
112
|
+
break;
|
|
113
|
+
parent = next;
|
|
114
|
+
watchers.push(watch(parent, (_event, name) => {
|
|
115
|
+
if (String(name) === ".gitignore")
|
|
116
|
+
note(".gitignore", "content");
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
const directory = dirname(headFile);
|
|
120
|
+
const common = join(directory, "commondir");
|
|
121
|
+
const directories = new Set([
|
|
122
|
+
directory,
|
|
123
|
+
existsSync(common)
|
|
124
|
+
? resolve(directory, readFileSync(common, "utf8").trim())
|
|
125
|
+
: directory,
|
|
126
|
+
]);
|
|
127
|
+
for (const path of directories)
|
|
128
|
+
watchers.push(watch(path, { recursive: true }, (_event, name) => {
|
|
129
|
+
const file = String(name).replaceAll("\\", "/");
|
|
130
|
+
if (file === "HEAD" || file === "packed-refs" || file.startsWith("refs/"))
|
|
131
|
+
note(".git/HEAD", "content");
|
|
132
|
+
else if (file === "index" || file === "info/exclude" || file === "config")
|
|
133
|
+
note(`.git/${file}`, "content");
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
// shortcut: keep encountered file watches until shutdown; prune if sessions collect many removed references.
|
|
137
|
+
const watchTextfiles = (files) => {
|
|
138
|
+
for (const file of files) {
|
|
139
|
+
if (isRemoteTextfile(file))
|
|
140
|
+
continue;
|
|
141
|
+
try {
|
|
142
|
+
textfilePath(docsRoot, file);
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const path = resolve(docsRoot, file);
|
|
148
|
+
if (textfiles.has(path))
|
|
149
|
+
continue;
|
|
150
|
+
const changed = () => note(file.replace(/^(\.\/)+/, ""), "content");
|
|
151
|
+
// Poll referenced paths so atomic saves, deletion and creation are all detected.
|
|
152
|
+
watchFile(path, { persistent: false, interval: 200 }, changed);
|
|
153
|
+
textfiles.set(path, changed);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const close = () => {
|
|
157
|
+
if (timer) {
|
|
158
|
+
clearTimeout(timer);
|
|
159
|
+
timer = undefined;
|
|
160
|
+
}
|
|
161
|
+
for (const w of watchers) {
|
|
162
|
+
w.close();
|
|
163
|
+
}
|
|
164
|
+
for (const [path, listener] of textfiles)
|
|
165
|
+
unwatchFile(path, listener);
|
|
166
|
+
};
|
|
167
|
+
return { close, watchTextfiles };
|
|
168
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from "../engine/core/blocks.js";
|
|
2
|
+
export * from "../engine/core/content-metadata.js";
|
|
3
|
+
export type * from "../engine/core/content-types.js";
|
|
4
|
+
export * from "../engine/core/figure-frame.js";
|
|
5
|
+
export * from "../engine/core/graph.js";
|
|
6
|
+
export * from "../engine/core/graph-common.js";
|
|
7
|
+
export * from "../engine/core/html.js";
|
|
8
|
+
export * from "../engine/core/inline.js";
|
|
9
|
+
export * from "../engine/core/language.js";
|
|
10
|
+
export * from "../engine/core/languages/ja.js";
|
|
11
|
+
export * from "../engine/core/previewers.js";
|
|
12
|
+
export * from "../engine/core/routing.js";
|
|
13
|
+
export * from "../engine/core/schema-graph.js";
|
|
14
|
+
export * from "../engine/core/taxonomy.js";
|
|
15
|
+
export { mountThemeVariants, themeVariantFile } from "../engine/core/theme-variants.js";
|
|
16
|
+
export * from "../engine/core/workspace.js";
|
|
17
|
+
export * from "../frontend/terms-ui.js";
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
// Browser-safe content types, parsers and rendering helpers. No project data is bundled.
|
|
2
|
-
export * from "
|
|
3
|
-
export * from "
|
|
2
|
+
export * from "../engine/core/blocks.js";
|
|
3
|
+
export * from "../engine/core/content-metadata.js";
|
|
4
4
|
// Isolated figure rendering (sandboxed iframe) and its parent-side mount (theme following /
|
|
5
5
|
// html figure height).
|
|
6
|
-
export * from "
|
|
6
|
+
export * from "../engine/core/figure-frame.js";
|
|
7
7
|
// node / edge DSL (`graphth`): parse / graph model / deterministic layout via Dagre.
|
|
8
8
|
// graph-common.js is the SoT for the geometry parts shared with the schema graph (text width
|
|
9
9
|
// estimation / orthogonal routing / uid).
|
|
10
|
-
export * from "
|
|
11
|
-
export * from "
|
|
10
|
+
export * from "../engine/core/graph.js";
|
|
11
|
+
export * from "../engine/core/graph-common.js";
|
|
12
12
|
// Block AST → HTML renderer, shared with the viewer.
|
|
13
|
-
export * from "
|
|
14
|
-
export * from "
|
|
13
|
+
export * from "../engine/core/html.js";
|
|
14
|
+
export * from "../engine/core/inline.js";
|
|
15
15
|
// Language socket: the adapter interface + generic rules, and the built-in Japanese adapter
|
|
16
16
|
// (browser-safe part; its prose lint is Node-only and lives in the viewer).
|
|
17
|
-
export * from "
|
|
18
|
-
export * from "
|
|
19
|
-
export * from "
|
|
20
|
-
export * from "
|
|
17
|
+
export * from "../engine/core/language.js";
|
|
18
|
+
export * from "../engine/core/languages/ja.js";
|
|
19
|
+
export * from "../engine/core/previewers.js";
|
|
20
|
+
export * from "../engine/core/routing.js";
|
|
21
21
|
// table DSL (`schemath`): parse / graph model / deterministic layout. html.ts uses it for
|
|
22
22
|
// rendering, and it also serves as the model source when consumers build their own UI
|
|
23
23
|
// (interactive graphs etc.).
|
|
24
|
-
export * from "
|
|
24
|
+
export * from "../engine/core/schema-graph.js";
|
|
25
25
|
// The schema graph's interactive UI (React Flow) requires react, so it is imported not from
|
|
26
26
|
// this react-free entry but from the subpath export `./flow` (dist/core/schema-graph-mount.js)
|
|
27
27
|
// and, for script tags, `./flow.global.js`.
|
|
28
|
-
export * from "
|
|
29
|
-
export
|
|
30
|
-
export
|
|
31
|
-
export * from "
|
|
28
|
+
export * from "../engine/core/taxonomy.js";
|
|
29
|
+
export { mountThemeVariants, themeVariantFile } from "../engine/core/theme-variants.js";
|
|
30
|
+
export * from "../engine/core/workspace.js";
|
|
31
|
+
export * from "../frontend/terms-ui.js";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { LintFinding } from "../core/language.js";
|
|
1
|
+
import type { LintFinding } from "../engine/core/language.js";
|
|
2
2
|
/** Lints body (md content without front matter) and returns typo findings with offsets. */
|
|
3
3
|
export declare const lintJa: (body: string) => Promise<LintFinding[]>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LanguageRegistration } from "shiki/core";
|
|
2
|
-
import type { LanguageAdapter } from "../core/language.js";
|
|
2
|
+
import type { LanguageAdapter } from "../engine/core/language.js";
|
|
3
3
|
export declare const BUILTIN_LANGUAGES: readonly LanguageAdapter[];
|
|
4
4
|
export interface SiteLanguages {
|
|
5
5
|
languages: readonly LanguageAdapter[];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Built-in language adapters for the Node tools (viewer / CLI / MCP): the browser-safe core
|
|
2
2
|
// adapters plus their Node-only prose lint. docs.config.mjs adapters take precedence.
|
|
3
|
-
import { loadCodeLanguages } from "../compiler/code-languages.js";
|
|
4
|
-
import { loadDocsConfig } from "../compiler/config.js";
|
|
5
|
-
import { ja } from "../core/languages/ja.js";
|
|
3
|
+
import { loadCodeLanguages } from "../engine/compiler/code-languages.js";
|
|
4
|
+
import { loadDocsConfig } from "../engine/compiler/config.js";
|
|
5
|
+
import { ja } from "../engine/core/languages/ja.js";
|
|
6
6
|
export const BUILTIN_LANGUAGES = [
|
|
7
7
|
// textlint is heavy; load it on the first lint request.
|
|
8
8
|
{ ...ja, lint: async (body) => (await import("./ja-lint.js")).lintJa(body) },
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type CompileOptions } from "
|
|
2
|
-
import type { GitOrigin } from "
|
|
1
|
+
import { type CompileOptions } from "../engine/compiler/compile.js";
|
|
2
|
+
import type { GitOrigin } from "../workspace/git-types.js";
|
|
3
3
|
type Args = Record<string, unknown>;
|
|
4
4
|
interface Property {
|
|
5
5
|
type: string | string[];
|
|
@@ -5,21 +5,23 @@ import { randomUUID } from "node:crypto";
|
|
|
5
5
|
import { mkdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { dirname, join, relative } from "node:path";
|
|
7
7
|
import { createInterface } from "node:readline";
|
|
8
|
-
import { checkSite } from "
|
|
9
|
-
import { CHECK_KINDS } from "
|
|
10
|
-
import { createCompiler } from "
|
|
11
|
-
import { exportBundle } from "
|
|
12
|
-
import { filesSnapshot, updateFiles, uploadFile } from "
|
|
13
|
-
import { addProjectFont, listProjectFonts, removeProjectFont } from "
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import { localFile } from "
|
|
19
|
-
import { docDisplayName } from "
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
8
|
+
import { checkSite } from "../engine/compiler/check.js";
|
|
9
|
+
import { CHECK_KINDS } from "../engine/compiler/check-types.js";
|
|
10
|
+
import { createCompiler } from "../engine/compiler/compile.js";
|
|
11
|
+
import { exportBundle } from "../engine/compiler/export.js";
|
|
12
|
+
import { filesSnapshot, updateFiles, uploadFile } from "../engine/compiler/files.js";
|
|
13
|
+
import { addProjectFont, listProjectFonts, removeProjectFont, } from "../engine/compiler/fonts.js";
|
|
14
|
+
import { manifestFile } from "../engine/compiler/manifest.js";
|
|
15
|
+
import { createDocOps, isOpError } from "../engine/compiler/ops.js";
|
|
16
|
+
import { validateSubformatFile } from "../engine/compiler/subformats.js";
|
|
17
|
+
import { readTextfile, textfilePath, writeTextfile } from "../engine/compiler/textfile.js";
|
|
18
|
+
import { localFile } from "../engine/core/files.js";
|
|
19
|
+
import { docDisplayName } from "../engine/core/taxonomy.js";
|
|
20
|
+
import { parsePerson } from "../workspace/history.js";
|
|
21
|
+
import { buildBundle } from "./build.js";
|
|
22
|
+
import { createGitHandler, validateGitOrigin } from "./git.js";
|
|
23
|
+
import { folderHistory, gitHistory, workspaceHistory } from "./history.js";
|
|
24
|
+
import { resourceIndex } from "./resource-library.js";
|
|
23
25
|
const str = { type: "string" };
|
|
24
26
|
const num = { type: "integer", minimum: 0 };
|
|
25
27
|
const bool = { type: "boolean" };
|
|
@@ -70,6 +72,10 @@ export const createTools = (root, options = {}) => {
|
|
|
70
72
|
url_preview: { ...str, enum: ["embed", "network"] },
|
|
71
73
|
mode: { ...str, enum: ["static", "live"] },
|
|
72
74
|
auth: { ...str, enum: ["external"] },
|
|
75
|
+
easy_download: {
|
|
76
|
+
type: "boolean",
|
|
77
|
+
description: "Enable individual resource downloads in HTML (default: false).",
|
|
78
|
+
},
|
|
73
79
|
source_url: {
|
|
74
80
|
...str,
|
|
75
81
|
description: "Public source directory URL for card copy links in HTML, relative to dooc.yaml.",
|
|
@@ -85,6 +91,7 @@ export const createTools = (root, options = {}) => {
|
|
|
85
91
|
mode: a.mode,
|
|
86
92
|
auth: a.auth,
|
|
87
93
|
sourceUrl: a.source_url,
|
|
94
|
+
easyDownload: a.easy_download,
|
|
88
95
|
previews: options.previews,
|
|
89
96
|
});
|
|
90
97
|
const path = textfilePath(root, file);
|
|
@@ -149,7 +156,7 @@ export const createTools = (root, options = {}) => {
|
|
|
149
156
|
run: (a) => updateFiles(root, a),
|
|
150
157
|
},
|
|
151
158
|
list_resources: {
|
|
152
|
-
description: "List
|
|
159
|
+
description: "List Library: codeblocks (including term definitions and local text-file embeds, with normalized format and reference locations), URLs from Markdown links, and URL previews from Markdown images, with source files and line numbers.",
|
|
153
160
|
props: {},
|
|
154
161
|
run: () => resourceIndex(root, filesSnapshot(root).files.map((file) => file.path), options.previews?.domains),
|
|
155
162
|
},
|
|
@@ -213,6 +220,35 @@ export const createTools = (root, options = {}) => {
|
|
|
213
220
|
required: ["action"],
|
|
214
221
|
run: git,
|
|
215
222
|
},
|
|
223
|
+
history: {
|
|
224
|
+
description: "Edit history as workspace snapshots. list (default) returns snapshots newest first from both stores: source=git (commits, co-authors from Co-authored-by trailers) and source=dooc (copies under .dooc/snapshots); user keeps only snapshots that person or agent authored or co-authored. snapshot records the current files with message, credited to user (e.g. the agent's name).",
|
|
225
|
+
props: {
|
|
226
|
+
action: { ...str, enum: ["list", "snapshot"] },
|
|
227
|
+
source: { ...str, enum: ["git", "dooc"] },
|
|
228
|
+
user: { ...str, description: "Author name, case-insensitive" },
|
|
229
|
+
message: str,
|
|
230
|
+
},
|
|
231
|
+
run: async (a) => {
|
|
232
|
+
const user = optStr(a.user);
|
|
233
|
+
if (a.action === "snapshot") {
|
|
234
|
+
const message = optStr(a.message)?.trim();
|
|
235
|
+
if (!message)
|
|
236
|
+
throw new Error("A snapshot needs a message");
|
|
237
|
+
return workspaceHistory(root).snapshot(message, user ? { author: parsePerson({ name: user }) } : undefined);
|
|
238
|
+
}
|
|
239
|
+
const name = user?.toLowerCase();
|
|
240
|
+
const stores = { git: gitHistory(root), dooc: folderHistory(root) };
|
|
241
|
+
// shortcut: filters the newest 200 commits, page through git log when a user's older edits are needed.
|
|
242
|
+
const snapshots = (await Promise.all(["git", "dooc"]
|
|
243
|
+
.filter((source) => !a.source || a.source === source)
|
|
244
|
+
.map(async (source) => (await stores[source].list()).map((s) => ({ source, ...s })))))
|
|
245
|
+
.flat()
|
|
246
|
+
.filter((s) => !name ||
|
|
247
|
+
[s.author, ...(s.coAuthors ?? [])].some((person) => person?.toLowerCase() === name))
|
|
248
|
+
.sort((x, y) => Date.parse(y.time) - Date.parse(x.time));
|
|
249
|
+
return { snapshots };
|
|
250
|
+
},
|
|
251
|
+
},
|
|
216
252
|
list_docs: {
|
|
217
253
|
description: "The doc tree (in manifest display order) and figures. Each doc has id / file / title / parent / depth.",
|
|
218
254
|
props: {},
|
|
@@ -225,7 +261,8 @@ export const createTools = (root, options = {}) => {
|
|
|
225
261
|
depth.set(d.id, dep);
|
|
226
262
|
return {
|
|
227
263
|
id: d.id,
|
|
228
|
-
file: d.subformat ?
|
|
264
|
+
file: d.subformat || d.library ? manifestFile(root) : d.file,
|
|
265
|
+
...(d.library ? { library: d.library } : {}),
|
|
229
266
|
...(d.subformat ? { subformat: d.subformat.ext } : {}),
|
|
230
267
|
title: docDisplayName(d, d.id),
|
|
231
268
|
parent: d.parent,
|
|
@@ -258,16 +295,18 @@ export const createTools = (root, options = {}) => {
|
|
|
258
295
|
},
|
|
259
296
|
},
|
|
260
297
|
read_doc: {
|
|
261
|
-
description: "A doc's raw md
|
|
298
|
+
description: "A doc's raw md and its validation errors. Figure links use file paths; list_docs maps each file to its read_figure name.",
|
|
262
299
|
props: { id: { ...str, description: "doc id" } },
|
|
263
300
|
required: ["id"],
|
|
264
301
|
run: (a) => {
|
|
265
302
|
const id = String(a.id);
|
|
266
303
|
const compiled = compiler.compile();
|
|
267
304
|
const doc = compiled.docs.find((d) => d.id === id);
|
|
305
|
+
if (doc?.library)
|
|
306
|
+
return { file: manifestFile(root), library: doc.library, errors: [] };
|
|
268
307
|
if (doc?.subformat)
|
|
269
308
|
return {
|
|
270
|
-
file:
|
|
309
|
+
file: manifestFile(root),
|
|
271
310
|
subformat: doc.subformat,
|
|
272
311
|
errors: compiled.sources.get(doc.file)?.errors ?? [],
|
|
273
312
|
};
|
|
@@ -321,10 +360,10 @@ export const createTools = (root, options = {}) => {
|
|
|
321
360
|
run: (a) => ops.add(String(a.id), String(a.title), optStr(a.parent)),
|
|
322
361
|
},
|
|
323
362
|
write_doc: {
|
|
324
|
-
description: "Overwrite the entire raw text of an existing doc
|
|
363
|
+
description: "Overwrite the entire raw text of an existing doc. Titles live in dooc.yaml. Returns the validation errors after writing.",
|
|
325
364
|
props: {
|
|
326
365
|
id: { ...str, description: "doc id" },
|
|
327
|
-
content: { ...str, description: "Full md text
|
|
366
|
+
content: { ...str, description: "Full md text" },
|
|
328
367
|
},
|
|
329
368
|
required: ["id", "content"],
|
|
330
369
|
run: (a) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type WorkspaceSource } from "../core/workspace.js";
|
|
2
1
|
import type { DataPlugin } from "../plugins/types.js";
|
|
3
|
-
import type
|
|
2
|
+
import { type WorkspaceSource } from "../engine/core/workspace.js";
|
|
3
|
+
import type { GitOrigin } from "../workspace/git-types.js";
|
|
4
4
|
export interface PluginMock {
|
|
5
5
|
origin: string;
|
|
6
6
|
/** Complete local mock authorization automatically when displaying a preview. */
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { isAbsolute, resolve } from "node:path";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
|
-
import { parsePreviewSettings } from "../core/previewers.js";
|
|
5
|
-
import { parseWorkspaceSource } from "../core/workspace.js";
|
|
6
4
|
import { httpsUrl, validatePlugins } from "../plugins/oauth.js";
|
|
5
|
+
import { parsePreviewSettings } from "../engine/core/previewers.js";
|
|
6
|
+
import { parseWorkspaceSource } from "../engine/core/workspace.js";
|
|
7
7
|
import { validateGitOrigin } from "./git.js";
|
|
8
8
|
/** Viewer modules are explicitly injected; document roots never select executable plugins. */
|
|
9
9
|
export const loadViewerPlugins = async (specifier) => {
|
|
@@ -3,7 +3,7 @@ import { lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync }
|
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { setTimeout as delay } from "node:timers/promises";
|
|
6
|
-
import { parseOAuthToken } from "
|
|
6
|
+
import { parseOAuthToken } from "../../plugins/oauth.js";
|
|
7
7
|
/** Personal state is outside document roots and never included in exported bundles. */
|
|
8
8
|
export const createLocalPluginStorage = (userDir = process.env.DOOC_USER_DIR ?? join(homedir(), ".dooc")) => {
|
|
9
9
|
const folder = join(userDir, "plugins");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type PluginActionResult } from "
|
|
1
|
+
import { type PluginActionResult } from "../../plugins/actions.js";
|
|
2
|
+
import type { DataPlugin, PluginUser } from "../../plugins/types.js";
|
|
2
3
|
import type { PluginCredentialStore } from "./local-storage.js";
|
|
3
|
-
import type { DataPlugin, PluginUser } from "./types.js";
|
|
4
4
|
export declare const createPluginRuntime: (definitions: readonly DataPlugin[], transport?: typeof fetch, credentials?: PluginCredentialStore) => {
|
|
5
5
|
resolve(source: unknown): string | undefined;
|
|
6
6
|
register(plugin: DataPlugin): void;
|
|
@@ -19,11 +19,11 @@ export declare const createPluginRuntime: (definitions: readonly DataPlugin[], t
|
|
|
19
19
|
status(id: string, pluginId: string): PluginUser | undefined;
|
|
20
20
|
read(id: string, pluginId: string, source: unknown): Promise<{
|
|
21
21
|
user: PluginUser;
|
|
22
|
-
view: import("
|
|
22
|
+
view: import("../../plugins/view.js").PluginView;
|
|
23
23
|
}>;
|
|
24
24
|
actions(id: string, pluginId: string, source: unknown): Promise<{
|
|
25
25
|
user: PluginUser;
|
|
26
|
-
actions: import("
|
|
26
|
+
actions: import("../../plugins/actions.js").PluginAction[];
|
|
27
27
|
}>;
|
|
28
28
|
act(id: string, pluginId: string, source: unknown, input: unknown, requestId: unknown): Promise<{
|
|
29
29
|
user: PluginUser;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash, randomBytes } from "node:crypto";
|
|
2
|
-
import { validatePluginActionRequest, validatePluginActions, validatePluginActionValues, } from "
|
|
3
|
-
import { fetchPluginJson, httpsUrl, isPluginError, PluginError, parseOAuthToken, validatePlugins, } from "
|
|
4
|
-
import { parsePluginUrl, validatePluginView } from "
|
|
2
|
+
import { validatePluginActionRequest, validatePluginActions, validatePluginActionValues, } from "../../plugins/actions.js";
|
|
3
|
+
import { fetchPluginJson, httpsUrl, isPluginError, PluginError, parseOAuthToken, validatePlugins, } from "../../plugins/oauth.js";
|
|
4
|
+
import { parsePluginUrl, validatePluginView } from "../../plugins/view.js";
|
|
5
5
|
const nonce = () => randomBytes(32).toString("base64url");
|
|
6
6
|
const expired = () => new PluginError(401, "Connect this plugin again");
|
|
7
7
|
const expiry = (token) => token.expires_in === undefined ? Infinity : Date.now() + token.expires_in * 1000;
|
|
@@ -252,7 +252,7 @@ export const createPluginRuntime = (definitions, transport, credentials) => {
|
|
|
252
252
|
if (plugin.oauth.deviceAuthorizationUrl)
|
|
253
253
|
throw new PluginError(400, "Use device authorization for this plugin");
|
|
254
254
|
const redirect = new URL(redirectUri);
|
|
255
|
-
if (
|
|
255
|
+
if (!["http:", "https:"].includes(redirect.protocol) ||
|
|
256
256
|
!["localhost", "127.0.0.1", "[::1]"].includes(redirect.hostname) ||
|
|
257
257
|
redirect.username ||
|
|
258
258
|
redirect.password ||
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
-
import type { PluginCredentialStore } from "../plugins/local-storage.js";
|
|
3
2
|
import type { DataPlugin } from "../plugins/types.js";
|
|
4
|
-
|
|
3
|
+
import type { PluginCredentialStore } from "./plugins/local-storage.js";
|
|
4
|
+
export type { GitWorkspace, StorageWorkspace, WorkspaceSource, } from "../engine/core/workspace.js";
|
|
5
5
|
import { type ViewerPluginRegistry, type ViewerPlugins } from "./plugin-config.js";
|
|
6
|
-
export type { GitContext, GitOrigin, GitOriginAction, GitOriginState, GitPullRequest, } from "
|
|
6
|
+
export type { GitContext, GitOrigin, GitOriginAction, GitOriginState, GitPullRequest, } from "../workspace/git-types.js";
|
|
7
7
|
export type { PluginMock, ViewerPluginRegistry, ViewerPlugins, ViewerRuntime, } from "./plugin-config.js";
|
|
8
8
|
/** Local viewer only: the cookie identifies a browser session, never a document-supplied user. */
|
|
9
9
|
export declare const createPluginHandler: (plugins: readonly DataPlugin[], presentation?: Pick<ViewerPlugins, "mocks">, credentials?: PluginCredentialStore) => ((req: IncomingMessage, res: ServerResponse) => Promise<boolean>) & ViewerPluginRegistry & {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
|
-
import { escapeHtml } from "../core/escape-html.js";
|
|
3
2
|
import { isPluginError, PluginError } from "../plugins/oauth.js";
|
|
4
|
-
import {
|
|
5
|
-
import { isLocalToolRequest } from "./editor-tools.js";
|
|
3
|
+
import { escapeHtml } from "../engine/core/escape-html.js";
|
|
4
|
+
import { isLocalToolRequest, requestScheme } from "./editor-tools.js";
|
|
5
|
+
import { createPluginRuntime } from "./plugins/runtime.js";
|
|
6
6
|
import { validateViewerPlugins, } from "./plugin-config.js";
|
|
7
7
|
const readBody = (req) => new Promise((resolve, reject) => {
|
|
8
8
|
let body = "";
|
|
@@ -96,15 +96,15 @@ export const createPluginHandler = (plugins, presentation = { mocks: {} }, crede
|
|
|
96
96
|
tickets.set(ticket, { plugin, origin, expires: Date.now() + 10 * 60 * 1000 });
|
|
97
97
|
return `${origin}/api/plugins/login/${plugin}?ticket=${ticket}`;
|
|
98
98
|
};
|
|
99
|
-
const authorizationUrl = async (session, plugin,
|
|
99
|
+
const authorizationUrl = async (session, plugin, base) => {
|
|
100
100
|
if (config.plugins.find((item) => item.id === plugin)?.oauth.deviceAuthorizationUrl) {
|
|
101
101
|
const state = await runtime.connectDevice(session, plugin);
|
|
102
|
-
return
|
|
102
|
+
return `${base}/api/plugins/device/${plugin}?state=${state}`;
|
|
103
103
|
}
|
|
104
|
-
const authorization = new URL(runtime.connect(session, plugin,
|
|
104
|
+
const authorization = new URL(runtime.connect(session, plugin, `${base}/api/plugins/callback/${plugin}`));
|
|
105
105
|
const mock = origins.get(authorization.origin);
|
|
106
106
|
return mock
|
|
107
|
-
?
|
|
107
|
+
? `${base}/api/plugins/mock/${mock.id}${authorization.pathname}${authorization.search}`
|
|
108
108
|
: authorization.href;
|
|
109
109
|
};
|
|
110
110
|
const handle = async (req, res) => {
|
|
@@ -121,6 +121,7 @@ export const createPluginHandler = (plugins, presentation = { mocks: {} }, crede
|
|
|
121
121
|
};
|
|
122
122
|
try {
|
|
123
123
|
const host = req.headers.host ?? "";
|
|
124
|
+
const base = `${requestScheme(req)}://${host}`;
|
|
124
125
|
if (!["localhost", "127.0.0.1", "[::1]"].some((name) => host === `${name}:${req.socket.localPort}`))
|
|
125
126
|
throw new PluginError(403, "Plugins require the local viewer");
|
|
126
127
|
if (req.method === "GET" && url.pathname === "/api/plugins/events") {
|
|
@@ -142,7 +143,7 @@ export const createPluginHandler = (plugins, presentation = { mocks: {} }, crede
|
|
|
142
143
|
throw new PluginError(404, "Mock authorization is not configured");
|
|
143
144
|
if (req.method !== "GET" &&
|
|
144
145
|
(req.method !== "POST" ||
|
|
145
|
-
req.headers.origin !==
|
|
146
|
+
req.headers.origin !== base ||
|
|
146
147
|
req.headers["content-type"]?.split(";")[0] !==
|
|
147
148
|
"application/x-www-form-urlencoded"))
|
|
148
149
|
throw new PluginError(403, "Mock consent requires a same-origin request");
|
|
@@ -156,7 +157,7 @@ export const createPluginHandler = (plugins, presentation = { mocks: {} }, crede
|
|
|
156
157
|
: {}),
|
|
157
158
|
}));
|
|
158
159
|
const location = response.headers.get("location");
|
|
159
|
-
if (location && !location.startsWith(
|
|
160
|
+
if (location && !location.startsWith(`${base}/api/plugins/callback/`))
|
|
160
161
|
throw new PluginError(400, "Invalid mock callback");
|
|
161
162
|
// Preserve the Origin header on local consent form submissions.
|
|
162
163
|
res.setHeader("referrer-policy", "same-origin");
|
|
@@ -184,13 +185,13 @@ export const createPluginHandler = (plugins, presentation = { mocks: {} }, crede
|
|
|
184
185
|
if (!ticket ||
|
|
185
186
|
ticket.expires <= Date.now() ||
|
|
186
187
|
ticket.plugin !== login[1] ||
|
|
187
|
-
ticket.origin !==
|
|
188
|
+
ticket.origin !== base)
|
|
188
189
|
throw new PluginError(400, "Invalid or expired login link");
|
|
189
190
|
tickets.delete(key);
|
|
190
191
|
if (!runtime.hasSession(session))
|
|
191
192
|
createSession();
|
|
192
193
|
res.writeHead(303, {
|
|
193
|
-
location: await authorizationUrl(session, ticket.plugin,
|
|
194
|
+
location: await authorizationUrl(session, ticket.plugin, base),
|
|
194
195
|
});
|
|
195
196
|
res.end();
|
|
196
197
|
return true;
|
|
@@ -235,7 +236,7 @@ setTimeout(poll, ${pending.retryAfter * 1000});
|
|
|
235
236
|
if (req.method === "GET" && callback?.[1]) {
|
|
236
237
|
let cancelled = false;
|
|
237
238
|
try {
|
|
238
|
-
await runtime.callback(session, callback[1],
|
|
239
|
+
await runtime.callback(session, callback[1], `${base}${url.pathname}`, url.searchParams);
|
|
239
240
|
}
|
|
240
241
|
catch (error) {
|
|
241
242
|
if (!isPluginError(error) ||
|
|
@@ -274,7 +275,7 @@ setTimeout(poll, ${pending.retryAfter * 1000});
|
|
|
274
275
|
(credentials || input.action === "connect" || input.action === "status"))
|
|
275
276
|
createSession();
|
|
276
277
|
if (input.action === "connect") {
|
|
277
|
-
send(200, { url: await authorizationUrl(session, input.plugin,
|
|
278
|
+
send(200, { url: await authorizationUrl(session, input.plugin, base) });
|
|
278
279
|
}
|
|
279
280
|
else if (input.action === "status") {
|
|
280
281
|
send(200, { user: runtime.status(session, input.plugin) ?? null });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../frontend/resource-library.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../frontend/resource-library.js";
|