easel-canvas 0.5.0 → 0.6.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/README.md +27 -1
- package/bin/server.mjs +3 -2
- package/dist/assets/index-DE0ohrot.js +75 -0
- package/dist/assets/{index-0pl9ILre.css → index-yigh_b3W.css} +1 -1
- package/dist/favicon.svg +1 -0
- package/dist/index.html +3 -2
- package/package.json +3 -2
- package/server/args.mjs +4 -2
- package/server/export.mjs +10 -3
- package/server/index.mjs +20 -1
- package/server/live/dispatch.mjs +168 -0
- package/server/live/inventory.mjs +101 -0
- package/server/live/live.mjs +366 -0
- package/server/live/proto.mjs +101 -0
- package/server/live/routes.mjs +49 -0
- package/server/routes.mjs +16 -3
- package/dist/assets/index-BRuM-YIO.js +0 -75
- package/dist/viewer/viewer.css +0 -1
- package/dist/viewer/viewer.js +0 -56
package/dist/index.html
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
<meta charset="utf-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
6
|
<title>Easel</title>
|
|
7
|
+
<link rel="icon" href="/_app/favicon.svg" type="image/svg+xml" />
|
|
7
8
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/variable/pretendardvariable-dynamic-subset.min.css" />
|
|
8
|
-
<script type="module" crossorigin src="/_app/assets/index-
|
|
9
|
-
<link rel="stylesheet" crossorigin href="/_app/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/_app/assets/index-DE0ohrot.js"></script>
|
|
10
|
+
<link rel="stylesheet" crossorigin href="/_app/assets/index-yigh_b3W.css">
|
|
10
11
|
</head>
|
|
11
12
|
<body>
|
|
12
13
|
<div id="root"></div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easel-canvas",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Easel: an HTML design canvas for AI agents. Shows screens/*.html as boards and edits the source directly, with Claude Code / Codex via MCP",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Hyun Park",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
"start": "node bin/server.mjs",
|
|
22
22
|
"demo": "node bin/server.mjs --dir examples/demo --open",
|
|
23
|
-
"build": "vite build app --config vite.config.mjs && vite build app --config vite.config.mjs --mode viewer",
|
|
23
|
+
"build": "vite build app --config vite.config.mjs && vite build app --config vite.config.mjs --mode viewer && vite build app --config vite.config.mjs --mode guest && node tools/live-build.mjs",
|
|
24
24
|
"prepack": "npm run build",
|
|
25
25
|
"version": "node tools/plugin-sync.mjs && git add plugin",
|
|
26
26
|
"mcp": "node bin/mcp.mjs",
|
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
"bin/",
|
|
73
73
|
"server/",
|
|
74
74
|
"dist/",
|
|
75
|
+
"!dist/live/",
|
|
75
76
|
"examples/demo/",
|
|
76
77
|
"README.md",
|
|
77
78
|
"LICENSE"
|
package/server/args.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// AI-generated with Claude Code, 2026-10-09, reviewed by Hyun Park
|
|
2
2
|
// Command-line args: [connect|export|up|status] [--dir <design folder>] [--port 4317] [--open] [--demo] [--init] [--help] [--version],
|
|
3
3
|
// plus --agents a,b and --dry-run for connect, --json for up and status, --out, --page, --boards a,b, --single-file, --pdf, --png for export,
|
|
4
|
-
// and --chat / --permission for easel-mcp (the server of an in-app chat run: canvas tools and its permission tool / that tool only).
|
|
4
|
+
// --relay <wss url> for live share, and --chat / --permission for easel-mcp (the server of an in-app chat run: canvas tools and its permission tool / that tool only).
|
|
5
5
|
// Default design folder: <repo>/docs/design when Easel lives in <repo>/tools/<name> (submodule); otherwise
|
|
6
6
|
// ./docs/design or the current folder if it has screens/ (npx).
|
|
7
7
|
import { existsSync } from "node:fs";
|
|
@@ -25,7 +25,7 @@ export const DEFAULT_DIR = defaultDir();
|
|
|
25
25
|
const expand = (p) => path.resolve(p.replace(/^~(?=\/)/, process.env.HOME ?? "~"));
|
|
26
26
|
|
|
27
27
|
export function parseArgs(argv = process.argv.slice(2)) {
|
|
28
|
-
const out = { command: null, dir: null, port: DEFAULT_PORT, portGiven: false, dirGiven: false, agents: null, dryRun: false, json: false, out: null, page: null, boards: null, singleFile: false, pdf: false, png: false, permission: false, chat: false, open: false, noOpen: false, demo: false, init: false, help: false, version: false, prod: false };
|
|
28
|
+
const out = { command: null, dir: null, port: DEFAULT_PORT, portGiven: false, dirGiven: false, agents: null, dryRun: false, json: false, out: null, page: null, boards: null, singleFile: false, pdf: false, png: false, permission: false, chat: false, open: false, noOpen: false, demo: false, init: false, help: false, version: false, prod: false, relay: null };
|
|
29
29
|
for (let i = 0; i < argv.length; i++) {
|
|
30
30
|
const a = argv[i];
|
|
31
31
|
const next = () => argv[++i];
|
|
@@ -33,6 +33,8 @@ export function parseArgs(argv = process.argv.slice(2)) {
|
|
|
33
33
|
else if (a.startsWith("--dir=")) out.dir = expand(a.slice(6));
|
|
34
34
|
else if (a === "--port") out.port = Number(next());
|
|
35
35
|
else if (a.startsWith("--port=")) out.port = Number(a.slice(7));
|
|
36
|
+
else if (a === "--relay") out.relay = next() ?? null;
|
|
37
|
+
else if (a.startsWith("--relay=")) out.relay = a.slice(8);
|
|
36
38
|
else if (a === "--agents") out.agents = next();
|
|
37
39
|
else if (a.startsWith("--agents=")) out.agents = a.slice(9);
|
|
38
40
|
else if (a === "--dry-run") out.dryRun = true;
|
package/server/export.mjs
CHANGED
|
@@ -305,12 +305,19 @@ const scriptJson = (v) => JSON.stringify(v).replace(/</g, "\\u003c");
|
|
|
305
305
|
async function viewerBuild() {
|
|
306
306
|
const d = path.join(TOOL_ROOT, "dist", "viewer");
|
|
307
307
|
try {
|
|
308
|
-
return { js: await fs.readFile(path.join(d, "viewer.js"), "utf8"), css: await fs.readFile(path.join(d, "viewer.css"), "utf8") };
|
|
308
|
+
return { js: await fs.readFile(path.join(d, "viewer.js"), "utf8"), css: await fs.readFile(path.join(d, "viewer.css"), "utf8"), icon: await faviconLink() };
|
|
309
309
|
} catch {
|
|
310
310
|
throw fail(500, "No viewer build found (run npm run build)");
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
313
|
|
|
314
|
+
/** The app's favicon (app/public/favicon.svg, copied into dist/ by the build) as an inline data: URI, so an exported copy asks
|
|
315
|
+
* nothing of the network. Empty when the build has no favicon. */
|
|
316
|
+
async function faviconLink() {
|
|
317
|
+
const svg = await fs.readFile(path.join(TOOL_ROOT, "dist", "favicon.svg"), "utf8").catch(() => "");
|
|
318
|
+
return svg ? `<link rel="icon" type="image/svg+xml" href="data:image/svg+xml;base64,${Buffer.from(svg.trim()).toString("base64")}">\n` : "";
|
|
319
|
+
}
|
|
320
|
+
|
|
314
321
|
const page = ({ title, head, body }) =>
|
|
315
322
|
`<!doctype html>\n<html lang="en">\n<head>\n<meta charset="utf-8">\n<meta name="viewport" content="width=device-width, initial-scale=1">\n<meta name="generator" content="Easel">\n<title>${escHtml(title)} — view only</title>\n${head}\n</head>\n<body>\n<div id="root"></div>\n${body}\n</body>\n</html>\n`;
|
|
316
323
|
|
|
@@ -521,7 +528,7 @@ export async function exportDesign({ dir, out, store, format = "web", singleFile
|
|
|
521
528
|
main = singleName(dir);
|
|
522
529
|
const html = page({
|
|
523
530
|
title: board.title,
|
|
524
|
-
head:
|
|
531
|
+
head: `${viewer.icon}<style>${viewer.css.replace(/<\/style/gi, "<\\/style")}</style>`,
|
|
525
532
|
body: `<script>window.EASEL_EXPORT=${scriptJson(data)};</script>\n<script>${viewer.js.replace(/<\/script/gi, "<\\/script")}</script>`,
|
|
526
533
|
});
|
|
527
534
|
entries.push({ rel: main, data: html });
|
|
@@ -534,7 +541,7 @@ export async function exportDesign({ dir, out, store, format = "web", singleFile
|
|
|
534
541
|
const ours = new Set(["index.html", ".nojekyll"]);
|
|
535
542
|
for (const e of entries) if (ours.has(e.rel) || e.rel.startsWith(VIEWER + "/")) throw fail(409, `The design folder has ${e.rel}, which the viewer needs for itself`);
|
|
536
543
|
entries.push(
|
|
537
|
-
{ rel: "index.html", data: page({ title: board.title, head:
|
|
544
|
+
{ rel: "index.html", data: page({ title: board.title, head: `${viewer.icon}<link rel="stylesheet" href="${VIEWER}/viewer.css">`, body: `<script src="${VIEWER}/data.js"></script>\n<script src="${VIEWER}/viewer.js"></script>` }) },
|
|
538
545
|
{ rel: `${VIEWER}/viewer.js`, data: viewer.js },
|
|
539
546
|
{ rel: `${VIEWER}/viewer.css`, data: viewer.css },
|
|
540
547
|
{ rel: `${VIEWER}/data.js`, data: `window.EASEL_EXPORT=${scriptJson(data)};\n` },
|
package/server/index.mjs
CHANGED
|
@@ -58,13 +58,22 @@ export async function readBody(req, limit = 4 * 1024 * 1024) {
|
|
|
58
58
|
/** Host names a browser uses for this local server; anything else is a DNS-rebinding page */
|
|
59
59
|
const LOCAL_HOST = /^(localhost|127\.0\.0\.1|\[::1\]|[a-z0-9.-]+\.localhost)(:\d+)?$/i;
|
|
60
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Every request and the WebSocket: the Host must be a loopback name (localhost, 127.0.0.1, [::1], *.localhost). A page on another
|
|
63
|
+
* name that resolves to 127.0.0.1 (DNS rebinding) is its own origin, so the browser would let it read our answers; refusing its Host
|
|
64
|
+
* stops that for reads as well as writes. The port is not compared: a port forward (ssh -L) keeps the name but changes the port.
|
|
65
|
+
*/
|
|
66
|
+
export function hostAllowed(headers) {
|
|
67
|
+
return LOCAL_HOST.test(String(headers.host ?? ""));
|
|
68
|
+
}
|
|
69
|
+
|
|
61
70
|
/**
|
|
62
71
|
* State-changing requests and the WebSocket: refused when they come from another web page in the user's browser.
|
|
63
72
|
* No Origin header (CLI, MCP server, curl) or the page's own origin is allowed; the Host must be a local name.
|
|
64
73
|
*/
|
|
65
74
|
export function originAllowed(headers) {
|
|
66
75
|
const host = String(headers.host ?? "");
|
|
67
|
-
if (!
|
|
76
|
+
if (!hostAllowed(headers)) return false;
|
|
68
77
|
const o = headers.origin;
|
|
69
78
|
if (o == null) return true;
|
|
70
79
|
try {
|
|
@@ -322,7 +331,15 @@ export async function createServer({ dir, port, dev = true, extraRoutes = [], au
|
|
|
322
331
|
...extraRoutes.map((r) => [r[0], r[1], (req, res, url) => (r[0] !== "GET" && LOCKED.test(r[1]) ? store.exclusive(() => r[2](req, res, url, ctx)) : r[2](req, res, url, ctx))]),
|
|
323
332
|
];
|
|
324
333
|
|
|
334
|
+
// Every "METHOD /path" this server answers: the live-share inventory test checks each one is classified (server/live/inventory.mjs)
|
|
335
|
+
ctx.routeTable = routes.map(([m, p]) => `${m} ${p}`);
|
|
336
|
+
|
|
325
337
|
const server = http.createServer(async (req, res) => {
|
|
338
|
+
// Reads too (board files, thumbnails, GET /api/*): a foreign Host name is a rebinding page, refused before anything is read
|
|
339
|
+
if (!hostAllowed(req.headers)) {
|
|
340
|
+
res.writeHead(403, { "Content-Type": "text/plain; charset=utf-8", "Cache-Control": "no-store" });
|
|
341
|
+
return res.end("Easel answers on localhost only");
|
|
342
|
+
}
|
|
326
343
|
const url = new URL(req.url ?? "/", `http://${req.headers.host ?? "localhost"}`);
|
|
327
344
|
try {
|
|
328
345
|
// Design folder: static files like /screens/*, /assets/* (same origin, so iframes can access contentDocument)
|
|
@@ -380,6 +397,8 @@ export async function createServer({ dir, port, dev = true, extraRoutes = [], au
|
|
|
380
397
|
} catch {
|
|
381
398
|
return;
|
|
382
399
|
}
|
|
400
|
+
// The owner's cursor on the canvas, for live-share guests (ignored when no room is on)
|
|
401
|
+
if (m?.type === "live-cursor") return ctx.live?.ownerCursor(m.at ?? null);
|
|
383
402
|
if (m?.type !== "editing") return;
|
|
384
403
|
const file = m.file == null ? null : isTrackedRel(`screens/${m.file}`) ? m.file : undefined;
|
|
385
404
|
if (file === undefined) return;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// AI-generated with Claude Code, 2026-12-05, reviewed by Hyun Park
|
|
2
|
+
// What a live-share guest may ask, and the answers. Guest requests never go through the app's HTTP routes: each allowed request is
|
|
3
|
+
// answered here, in process, by a handler written for guests (local paths and owner-only fields left out, the guest's name and
|
|
4
|
+
// role decided by the owner's side). Anything not in GUEST_ROUTES or the static rules is 403 and no app code runs for it.
|
|
5
|
+
// Every app route must be classified in inventory.mjs (a test fails when a new route is not).
|
|
6
|
+
import fs from "node:fs/promises";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
|
|
9
|
+
import { MIME, injectProbe, safeJoin } from "../index.mjs";
|
|
10
|
+
import { readComments, writeComments } from "../routes.mjs";
|
|
11
|
+
|
|
12
|
+
const enc = new TextEncoder();
|
|
13
|
+
const json = (status, body) => ({ status, type: MIME[".json"], body: enc.encode(JSON.stringify(body)) });
|
|
14
|
+
const deny = (status = 403, why = "not allowed") => json(status, { error: why });
|
|
15
|
+
/** The largest file a guest is sent */
|
|
16
|
+
export const MAX_FILE = 32 * 1024 * 1024;
|
|
17
|
+
/** Comment text and reply length */
|
|
18
|
+
export const MAX_TEXT = 4000;
|
|
19
|
+
const ROLE_RANK = { view: 1, comment: 2 };
|
|
20
|
+
/** Files at the design folder's root that guests get through the API only (filtered), never as files */
|
|
21
|
+
const PRIVATE_ROOT = new Set(["comments.json", "board.json"]);
|
|
22
|
+
|
|
23
|
+
/** A comment as a guest sees it: no AI request state, no addressing, nothing but what the canvas shows */
|
|
24
|
+
function guestComment(c) {
|
|
25
|
+
const out = { id: c.id, file: c.file, path: c.path ?? "", text: c.text, author: c.author, createdAt: c.createdAt, resolved: !!c.resolved };
|
|
26
|
+
if (c.guest) out.guest = true;
|
|
27
|
+
if (Array.isArray(c.replies)) out.replies = c.replies.map((r) => ({ id: r.id, author: r.author, text: r.text, createdAt: r.createdAt, ...(r.guest ? { guest: true } : {}) }));
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** [method, path, least role, handler(ctx, guest, body)] */
|
|
32
|
+
export const GUEST_ROUTES = [
|
|
33
|
+
[
|
|
34
|
+
"GET",
|
|
35
|
+
"/api/board",
|
|
36
|
+
"view",
|
|
37
|
+
async (ctx) => {
|
|
38
|
+
const { board, files, missing } = await ctx.store.syncBoard();
|
|
39
|
+
return json(200, { board, files, missing, stamps: await ctx.stamps.stampAll(files) });
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
[
|
|
43
|
+
"GET",
|
|
44
|
+
"/api/comments",
|
|
45
|
+
"view",
|
|
46
|
+
// Comments for AI are the owner's requests to their agents: not shown to guests
|
|
47
|
+
async (ctx) => json(200, { comments: (await readComments(ctx)).filter((c) => !c.forAgent).map(guestComment) }),
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
"POST",
|
|
51
|
+
"/api/comments",
|
|
52
|
+
"comment",
|
|
53
|
+
async (ctx, guest, body) => {
|
|
54
|
+
let b;
|
|
55
|
+
try {
|
|
56
|
+
b = JSON.parse(new TextDecoder().decode(body ?? new Uint8Array(0)) || "{}");
|
|
57
|
+
} catch {
|
|
58
|
+
return deny(400, "bad body");
|
|
59
|
+
}
|
|
60
|
+
if (!guest.name) return deny(403, "name first");
|
|
61
|
+
const text = String(b.text ?? "").trim();
|
|
62
|
+
if (!text || text.length > MAX_TEXT) return deny(400, "text is required (at most 4000 characters)");
|
|
63
|
+
const now = new Date().toISOString();
|
|
64
|
+
const rand = () => Math.random().toString(36).slice(2, 5);
|
|
65
|
+
// The author is the name the guest gave, never a field of the request; a guest comment is never a request for AI
|
|
66
|
+
return ctx.store.exclusive(async () => {
|
|
67
|
+
const list = await readComments(ctx);
|
|
68
|
+
if (b.action === "reply") {
|
|
69
|
+
const c = list.find((x) => x.id === b.id && !x.forAgent);
|
|
70
|
+
if (!c) return deny(404, "Comment not found");
|
|
71
|
+
const r = { id: `r${Date.now().toString(36)}${rand()}`, author: guest.name, text, createdAt: now, guest: true, guestKey: guest.key };
|
|
72
|
+
c.replies = [...(c.replies ?? []), r];
|
|
73
|
+
await writeComments(ctx, list);
|
|
74
|
+
return json(200, { comment: guestComment(c) });
|
|
75
|
+
}
|
|
76
|
+
if (b.action != null) return deny(403, "guests can add comments and replies only");
|
|
77
|
+
const board = await ctx.store.readBoard();
|
|
78
|
+
const file = String(b.file ?? "");
|
|
79
|
+
if (!board.boards[file]) return deny(400, "no such board");
|
|
80
|
+
const p = String(b.path ?? "");
|
|
81
|
+
if (!/^[0-9/]{0,200}$/.test(p)) return deny(400, "bad element path");
|
|
82
|
+
const c = { id: `c${Date.now().toString(36)}${rand()}`, file, path: p, text, author: guest.name, createdAt: now, resolved: false, guest: true, guestKey: guest.key };
|
|
83
|
+
list.push(c);
|
|
84
|
+
await writeComments(ctx, list);
|
|
85
|
+
return json(200, { comment: guestComment(c) });
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
/** "/screens/a b.html?x" → ["screens", "a b.html"], or null for anything with an empty, "." or ".." segment or a dot-name */
|
|
92
|
+
export function splitPath(p) {
|
|
93
|
+
let s;
|
|
94
|
+
try {
|
|
95
|
+
s = decodeURIComponent(String(p ?? "").split(/[?#]/)[0]);
|
|
96
|
+
} catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
if (!s.startsWith("/") || s.includes("\\") || s.includes("\0")) return null;
|
|
100
|
+
const parts = s.slice(1).split("/");
|
|
101
|
+
if (!parts.length || parts.some((x) => !x || x.startsWith("."))) return null;
|
|
102
|
+
return parts;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function sendFile(file, { probe = false } = {}) {
|
|
106
|
+
const ext = path.extname(file).toLowerCase();
|
|
107
|
+
if (!MIME[ext]) return null;
|
|
108
|
+
const st = await fs.stat(file).catch(() => null);
|
|
109
|
+
if (!st?.isFile()) return null;
|
|
110
|
+
if (st.size > MAX_FILE) return deny(413, "file too large");
|
|
111
|
+
if (probe && ext === ".html") return { status: 200, type: MIME[".html"], body: enc.encode(injectProbe(await fs.readFile(file, "utf8"))) };
|
|
112
|
+
return { status: 200, type: MIME[ext], body: new Uint8Array(await fs.readFile(file)) };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Board documents and what they load: screens/** (HTML with the error probe, as the app serves it), assets/**, and a board's
|
|
117
|
+
* root paths ("/x.css": the file in screens/ when there is one, else in the design folder) except the private root files
|
|
118
|
+
*/
|
|
119
|
+
async function staticFile(ctx, parts) {
|
|
120
|
+
if (parts[0] === "screens" && parts.length > 1) {
|
|
121
|
+
const p = safeJoin(ctx.store.screensDir, parts.slice(1).join("/"));
|
|
122
|
+
return p ? sendFile(p, { probe: true }) : null;
|
|
123
|
+
}
|
|
124
|
+
if (parts[0] === "assets" && parts.length > 1) {
|
|
125
|
+
const p = safeJoin(ctx.dir, parts.join("/"));
|
|
126
|
+
return p ? sendFile(p) : null;
|
|
127
|
+
}
|
|
128
|
+
if (!path.extname(parts.at(-1))) return null;
|
|
129
|
+
const inScreens = safeJoin(ctx.store.screensDir, parts.join("/"));
|
|
130
|
+
const hit = inScreens && (await sendFile(inScreens, { probe: true }));
|
|
131
|
+
if (hit) return hit;
|
|
132
|
+
if (parts.length === 1 && PRIVATE_ROOT.has(parts[0].toLowerCase())) return null;
|
|
133
|
+
const inDir = safeJoin(ctx.dir, parts.join("/"));
|
|
134
|
+
return inDir ? sendFile(inDir) : null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* One guest request. guest: { role, name, key } decided by the owner's side (the link the guest came by); req: { m, p, body }.
|
|
139
|
+
* Resolves to { status, type, body: Uint8Array }
|
|
140
|
+
*/
|
|
141
|
+
export async function dispatch(ctx, guest, req) {
|
|
142
|
+
if (req.tooBig) return deny(413, "request too large");
|
|
143
|
+
const m = String(req.m ?? "");
|
|
144
|
+
const p = String(req.p ?? "");
|
|
145
|
+
const pathname = p.split(/[?#]/)[0];
|
|
146
|
+
const route = GUEST_ROUTES.find(([rm, rp]) => rm === m && rp === pathname);
|
|
147
|
+
if (route) {
|
|
148
|
+
if ((ROLE_RANK[guest.role] ?? 0) < ROLE_RANK[route[2]]) return deny(403, "this link cannot do that");
|
|
149
|
+
return route[3](ctx, guest, req.body);
|
|
150
|
+
}
|
|
151
|
+
if (m !== "GET" || pathname.startsWith("/api/")) return deny();
|
|
152
|
+
const parts = splitPath(p);
|
|
153
|
+
if (!parts) return deny();
|
|
154
|
+
return (await staticFile(ctx, parts)) ?? json(404, { error: "not found" });
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Canvas events guests get (others are the owner's: AI runs, selection, errors, updates…). Fields that name local things go */
|
|
158
|
+
export function guestEvent(msg) {
|
|
159
|
+
if (!msg || typeof msg !== "object") return null;
|
|
160
|
+
if (msg.type === "file-changed") {
|
|
161
|
+
const { type, file, kind, hash, stamp, via } = msg;
|
|
162
|
+
// via: the stylesheet, image or page that changed under this board, so the guest drops just that one from its cache
|
|
163
|
+
return { type, file, kind, ...(hash ? { hash } : {}), ...(stamp ? { stamp } : {}), ...(typeof via === "string" ? { via } : {}) };
|
|
164
|
+
}
|
|
165
|
+
if (msg.type === "board-changed") return { type: "board-changed", source: null };
|
|
166
|
+
if (msg.type === "comments-changed") return { type: "comments-changed" };
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// AI-generated with Claude Code, 2026-12-05, reviewed by Hyun Park
|
|
2
|
+
// Every app route, classified for live share. "view"/"comment": a guest with that link gets a guest version of it (dispatch.mjs
|
|
3
|
+
// GUEST_ROUTES must implement exactly these). "later": a guest may get it in a later stage (editing). "owner": never reaches a
|
|
4
|
+
// guest. test/live-inventory.test.mjs fails when the server has a route this table does not name, so a new route is a decision.
|
|
5
|
+
// Static files (screens/**, assets/**, a board's root paths) are served by dispatch.mjs staticFile, not by this table.
|
|
6
|
+
export const INVENTORY = {
|
|
7
|
+
// index.mjs
|
|
8
|
+
"GET /api/update": "owner",
|
|
9
|
+
"POST /api/update": "owner",
|
|
10
|
+
"GET /api/health": "owner", // dir, root, pid
|
|
11
|
+
"GET /api/projects": "owner",
|
|
12
|
+
"GET /api/board": "view", // guest version: no dir, no screens path
|
|
13
|
+
"GET /api/file": "later",
|
|
14
|
+
// routes.mjs
|
|
15
|
+
"POST /api/edit": "later", // stage 2: setText and setStyle only, guarded
|
|
16
|
+
"POST /api/undo": "owner",
|
|
17
|
+
"POST /api/redo": "owner",
|
|
18
|
+
"GET /api/thumb": "later", // renders with a headless browser on the owner's machine
|
|
19
|
+
"GET /api/assets": "later",
|
|
20
|
+
"POST /api/assets": "owner",
|
|
21
|
+
"GET /api/element": "later",
|
|
22
|
+
"GET /api/file-hash": "later",
|
|
23
|
+
"GET /api/outline": "later",
|
|
24
|
+
"GET /api/selection": "owner", // the owner's selection for AI
|
|
25
|
+
"PUT /api/selection": "owner",
|
|
26
|
+
"GET /api/comments": "view", // guest version: no requests for AI
|
|
27
|
+
"POST /api/comments": "comment", // guest version: add and reply, author set by the owner's side, never for AI
|
|
28
|
+
"POST /api/screenshot": "owner",
|
|
29
|
+
"POST /api/place": "owner",
|
|
30
|
+
// boards.mjs
|
|
31
|
+
"PUT /api/board": "owner",
|
|
32
|
+
"POST /api/boards/create": "owner",
|
|
33
|
+
"GET /api/boards/templates": "owner",
|
|
34
|
+
"POST /api/boards/delete": "owner",
|
|
35
|
+
"POST /api/boards/duplicate": "owner",
|
|
36
|
+
"GET /api/boards/refs": "owner",
|
|
37
|
+
"POST /api/boards/rename": "owner",
|
|
38
|
+
"POST /api/history/undo": "owner",
|
|
39
|
+
"POST /api/history/redo": "owner",
|
|
40
|
+
"GET /api/history": "owner",
|
|
41
|
+
"POST /api/notes": "owner",
|
|
42
|
+
"POST /api/pages": "owner",
|
|
43
|
+
// forks.mjs
|
|
44
|
+
"GET /api/boards/occupancy": "later",
|
|
45
|
+
"POST /api/boards/write": "owner",
|
|
46
|
+
"POST /api/boards/claim": "owner",
|
|
47
|
+
"POST /api/boards/release": "owner",
|
|
48
|
+
"POST /api/boards/use": "owner",
|
|
49
|
+
"POST /api/boards/keep": "owner",
|
|
50
|
+
// activity.mjs
|
|
51
|
+
"GET /api/activity": "owner",
|
|
52
|
+
"POST /api/history/goto": "owner",
|
|
53
|
+
"POST /api/history/undo-steps": "owner",
|
|
54
|
+
"GET /api/history/step-file": "owner",
|
|
55
|
+
// chat.mjs: local AI agents
|
|
56
|
+
"POST /api/chat": "owner",
|
|
57
|
+
"POST /api/chat/cancel": "owner",
|
|
58
|
+
"GET /api/chat": "owner",
|
|
59
|
+
"POST /api/chat/permission": "owner",
|
|
60
|
+
"GET /api/chat/permission": "owner",
|
|
61
|
+
"POST /api/chat/permission/answer": "owner",
|
|
62
|
+
"POST /api/chat/revert": "owner",
|
|
63
|
+
"POST /api/chat/undo-run": "owner",
|
|
64
|
+
"POST /api/chat/redo-run": "owner",
|
|
65
|
+
"GET /api/chat/runs": "owner",
|
|
66
|
+
"GET /api/chat/run-file": "owner",
|
|
67
|
+
"GET /api/agents": "owner",
|
|
68
|
+
"POST /api/agents/custom": "owner",
|
|
69
|
+
"POST /api/refs": "owner",
|
|
70
|
+
"PUT /api/context": "owner",
|
|
71
|
+
"PUT /api/errors": "owner",
|
|
72
|
+
"GET /api/errors": "owner",
|
|
73
|
+
// requests.mjs
|
|
74
|
+
"POST /api/agents/hello": "owner",
|
|
75
|
+
"POST /api/agents/bye": "owner",
|
|
76
|
+
"GET /api/agents/connected": "owner",
|
|
77
|
+
"GET /api/requests/settings": "owner",
|
|
78
|
+
"POST /api/requests/settings": "owner",
|
|
79
|
+
"GET /api/requests": "owner",
|
|
80
|
+
"POST /api/requests": "owner",
|
|
81
|
+
"POST /api/pick/resolve": "owner",
|
|
82
|
+
// tokens.mjs
|
|
83
|
+
"GET /api/tokens": "later",
|
|
84
|
+
"PUT /api/tokens": "owner",
|
|
85
|
+
"GET /api/lint": "owner",
|
|
86
|
+
// snapshot.mjs
|
|
87
|
+
"GET /api/me": "owner", // git user.name
|
|
88
|
+
"GET /api/snapshots": "owner",
|
|
89
|
+
"POST /api/snapshot": "owner",
|
|
90
|
+
// export.mjs
|
|
91
|
+
"GET /api/export": "owner",
|
|
92
|
+
"POST /api/export": "owner",
|
|
93
|
+
"POST /api/export/estimate": "owner",
|
|
94
|
+
"POST /api/export/reveal": "owner",
|
|
95
|
+
// live share itself (server/live/routes.mjs)
|
|
96
|
+
"GET /api/live": "owner",
|
|
97
|
+
"POST /api/live/start": "owner",
|
|
98
|
+
"POST /api/live/stop": "owner",
|
|
99
|
+
"POST /api/live/rotate": "owner",
|
|
100
|
+
"POST /api/live/owner": "owner",
|
|
101
|
+
};
|