@howaboua/pi-agent-board 0.0.0-stage → 0.0.2

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/INTEGRATION.md +31 -0
  3. package/LICENSE +21 -0
  4. package/README.md +112 -2
  5. package/changelog.ts +337 -0
  6. package/dist/viewer/archive.js +242 -0
  7. package/dist/viewer/config.js +85 -0
  8. package/dist/viewer/contracts.js +1 -0
  9. package/dist/viewer/server.js +172 -0
  10. package/dist/viewer/source.js +29 -0
  11. package/dist/viewer/web/app.js +515 -0
  12. package/dist/viewer/web/index.html +41 -0
  13. package/dist/viewer/web/style.css +517 -0
  14. package/index.ts +122 -0
  15. package/package.json +68 -5
  16. package/src/activity.ts +274 -0
  17. package/src/archive.ts +108 -0
  18. package/src/awareness.ts +184 -0
  19. package/src/briefing.ts +24 -0
  20. package/src/config.ts +182 -0
  21. package/src/context-briefing.ts +227 -0
  22. package/src/contract.ts +246 -0
  23. package/src/delivery.ts +85 -0
  24. package/src/identity.ts +174 -0
  25. package/src/integration.ts +54 -0
  26. package/src/paging.ts +54 -0
  27. package/src/protocol.ts +78 -0
  28. package/src/queries.ts +171 -0
  29. package/src/response.ts +56 -0
  30. package/src/runtime.ts +614 -0
  31. package/src/search.ts +93 -0
  32. package/src/store.ts +391 -0
  33. package/src/summaries.ts +118 -0
  34. package/src/summarizer.ts +199 -0
  35. package/src/tool.ts +22 -0
  36. package/src/turns.ts +101 -0
  37. package/src/viewer/archive.ts +301 -0
  38. package/src/viewer/config.ts +111 -0
  39. package/src/viewer/contracts.ts +98 -0
  40. package/src/viewer/index.ts +158 -0
  41. package/src/viewer/server.ts +199 -0
  42. package/src/viewer/source.ts +33 -0
  43. package/src/viewer/web/app.js +515 -0
  44. package/src/viewer/web/index.html +41 -0
  45. package/src/viewer/web/style.css +517 -0
  46. package/tsconfig.json +5 -0
@@ -0,0 +1,242 @@
1
+ import { statSync } from "node:fs";
2
+ import { DatabaseSync, } from "node:sqlite";
3
+ import { caseFold } from "unicode-case-folding";
4
+ function text(row, key) {
5
+ const value = row[key];
6
+ if (typeof value !== "string")
7
+ throw new Error(`Invalid board archive field: ${key}`);
8
+ return value;
9
+ }
10
+ function count(row, key) {
11
+ const value = row[key];
12
+ if (typeof value !== "number" || !Number.isSafeInteger(value))
13
+ throw new Error(`Invalid board archive count: ${key}`);
14
+ return value;
15
+ }
16
+ function nullableText(row, key) {
17
+ return row[key] === null ? null : text(row, key);
18
+ }
19
+ function post(row) {
20
+ return {
21
+ id: text(row, "id"),
22
+ channel: text(row, "channel"),
23
+ author: text(row, "author"),
24
+ createdAt: text(row, "created_at"),
25
+ text: text(row, "text"),
26
+ };
27
+ }
28
+ /** The archive is opened read-only; no migrations, board creation or subscriptions. */
29
+ export class Archive {
30
+ db;
31
+ source;
32
+ constructor(source) {
33
+ this.source = source;
34
+ try {
35
+ statSync(source.databasePath);
36
+ }
37
+ catch (error) {
38
+ if (error instanceof Error && "code" in error && error.code === "ENOENT")
39
+ return;
40
+ throw error;
41
+ }
42
+ const db = new DatabaseSync(source.databasePath, { readOnly: true });
43
+ try {
44
+ db.exec("PRAGMA busy_timeout=2000; PRAGMA query_only=ON; BEGIN");
45
+ if (db.prepare("PRAGMA user_version").get()?.["user_version"] !== 1)
46
+ throw new Error("Unsupported board archive version");
47
+ this.db = db;
48
+ }
49
+ catch (error) {
50
+ db.close();
51
+ throw error;
52
+ }
53
+ }
54
+ close() {
55
+ this.db?.close();
56
+ }
57
+ all(sql, ...args) {
58
+ return this.db?.prepare(sql).all(...args) ?? [];
59
+ }
60
+ hasTable(name) {
61
+ return (this.all("SELECT name FROM sqlite_master WHERE type='table' AND name=?", name).length > 0);
62
+ }
63
+ status(id, threadId) {
64
+ if (!this.hasTable("thread_statuses"))
65
+ return "open";
66
+ const value = this.all("SELECT status FROM thread_statuses WHERE board_id=? AND thread_id=?", id, threadId)[0]?.["status"];
67
+ return value === "completed" || value === "abandoned" ? value : "open";
68
+ }
69
+ summary(id, threadId) {
70
+ if (!this.hasTable("thread_summaries"))
71
+ return null;
72
+ const row = this.all(`SELECT s.*, EXISTS(SELECT 1 FROM posts p WHERE p.board_id=s.board_id AND p.root=s.thread_id
73
+ AND p.seq>(SELECT seq FROM posts covered WHERE covered.board_id=s.board_id AND covered.id=s.through_message_id)) AS has_newer_posts
74
+ FROM thread_summaries s WHERE s.board_id=? AND s.thread_id=?`, id, threadId)[0];
75
+ return row
76
+ ? {
77
+ text: text(row, "text"),
78
+ createdAt: text(row, "created_at"),
79
+ throughMessageId: text(row, "through_message_id"),
80
+ hasNewerPosts: count(row, "has_newer_posts") === 1,
81
+ provider: text(row, "provider"),
82
+ model: text(row, "model"),
83
+ reasoning: text(row, "reasoning"),
84
+ }
85
+ : null;
86
+ }
87
+ index() {
88
+ const { databasePath: _path, ...context } = this.source;
89
+ const boards = this.all(`SELECT b.board_id,b.root_session_id,b.created_at,
90
+ (SELECT MAX(created_at) FROM posts WHERE board_id=b.board_id) AS last_activity,
91
+ (SELECT COUNT(*) FROM channels WHERE board_id=b.board_id) AS channels,
92
+ (SELECT COUNT(*) FROM posts WHERE board_id=b.board_id) AS posts,
93
+ (SELECT COUNT(DISTINCT author) FROM posts WHERE board_id=b.board_id) AS agents
94
+ FROM boards b WHERE owner_folder=? ORDER BY COALESCE(last_activity,b.created_at) DESC`, this.source.folder).map((row) => ({
95
+ id: text(row, "board_id"),
96
+ rootSessionId: text(row, "root_session_id"),
97
+ createdAt: text(row, "created_at"),
98
+ lastActivity: nullableText(row, "last_activity"),
99
+ channels: count(row, "channels"),
100
+ posts: count(row, "posts"),
101
+ agents: count(row, "agents"),
102
+ }));
103
+ if (!boards.some((board) => board.id === context.boardId))
104
+ boards.unshift({
105
+ id: context.boardId,
106
+ rootSessionId: context.sessionId,
107
+ createdAt: null,
108
+ lastActivity: null,
109
+ channels: 0,
110
+ posts: 0,
111
+ agents: 0,
112
+ });
113
+ return { context, boards };
114
+ }
115
+ board(id) {
116
+ const board = this.index().boards.find((board) => board.id === id);
117
+ if (!board)
118
+ throw new Error("Board not found in this folder");
119
+ return board;
120
+ }
121
+ detail(id) {
122
+ const board = this.board(id);
123
+ const channels = this.all(`SELECT c.name,c.author,c.created_at,COUNT(p.id) AS posts,
124
+ COUNT(CASE WHEN p.id=p.root THEN 1 END) AS threads,MAX(p.created_at) AS last_activity
125
+ FROM channels c LEFT JOIN posts p ON p.board_id=c.board_id AND p.channel=c.name
126
+ WHERE c.board_id=? GROUP BY c.name ORDER BY COALESCE(last_activity,c.created_at) DESC,c.name`, id).map((row) => ({
127
+ name: text(row, "name"),
128
+ author: text(row, "author"),
129
+ createdAt: text(row, "created_at"),
130
+ posts: count(row, "posts"),
131
+ threads: count(row, "threads"),
132
+ lastActivity: nullableText(row, "last_activity"),
133
+ }));
134
+ const agents = this.all("SELECT author,COUNT(*) AS posts,MAX(created_at) AS last_activity FROM posts WHERE board_id=? GROUP BY author ORDER BY posts DESC,author", id).map((row) => ({
135
+ name: text(row, "author"),
136
+ posts: count(row, "posts"),
137
+ lastActivity: text(row, "last_activity"),
138
+ }));
139
+ const subscriptions = this.all("SELECT target,agent,enabled FROM subscriptions WHERE board_id=? ORDER BY target,agent", id).map((row) => ({
140
+ target: text(row, "target"),
141
+ agent: text(row, "agent"),
142
+ enabled: count(row, "enabled") === 1,
143
+ }));
144
+ return { board, channels, agents, subscriptions };
145
+ }
146
+ threads(id, params) {
147
+ this.board(id);
148
+ const channel = params.get("channel");
149
+ const query = params.get("q");
150
+ const author = params.get("author");
151
+ const summaries = this.hasTable("thread_summaries") && params.get("full") !== "true";
152
+ if (query && query.length > 1000)
153
+ throw new Error("Search is too long");
154
+ const where = ["r.board_id=?", "r.id=r.root"];
155
+ const args = [id];
156
+ if (channel !== null) {
157
+ where.push("r.channel=?");
158
+ args.push(channel);
159
+ }
160
+ if (query || author) {
161
+ const match = ["m.board_id=r.board_id", "m.root=r.id"];
162
+ if (query) {
163
+ match.push("instr(m.body_search,?)>0");
164
+ args.push(caseFold(query));
165
+ }
166
+ if (author) {
167
+ match.push("m.author=?");
168
+ args.push(author);
169
+ }
170
+ const originals = `EXISTS(SELECT 1 FROM posts m WHERE ${match.join(" AND ")})`;
171
+ if (summaries) {
172
+ const summaryMatch = ["s.board_id=r.board_id", "s.thread_id=r.id"];
173
+ if (query) {
174
+ summaryMatch.push("instr(s.body_search,?)>0");
175
+ args.push(caseFold(query));
176
+ }
177
+ if (author) {
178
+ summaryMatch.push("EXISTS(SELECT 1 FROM posts a WHERE a.board_id=r.board_id AND a.root=r.id AND a.author=?)");
179
+ args.push(author);
180
+ }
181
+ where.push(`((NOT EXISTS(SELECT 1 FROM thread_summaries s WHERE s.board_id=r.board_id AND s.thread_id=r.id) AND ${originals}) OR EXISTS(SELECT 1 FROM thread_summaries s WHERE ${summaryMatch.join(" AND ")}))`);
182
+ }
183
+ else
184
+ where.push(originals);
185
+ }
186
+ const cursor = this.cursor(params);
187
+ const rows = this.all(`SELECT r.id,r.channel,r.author,r.text,r.created_at,
188
+ MAX(p.created_at) AS last_activity,MAX(p.seq) AS last_seq,COUNT(*)-1 AS replies
189
+ FROM posts r JOIN posts p ON p.board_id=r.board_id AND p.root=r.id
190
+ WHERE ${where.join(" AND ")} GROUP BY r.id HAVING MAX(p.seq)<? ORDER BY last_seq DESC LIMIT 41`, ...args, cursor ?? Number.MAX_SAFE_INTEGER);
191
+ const visible = rows.slice(0, 40);
192
+ const last = visible.at(-1);
193
+ return {
194
+ threads: visible.map((row) => {
195
+ const threadId = text(row, "id");
196
+ const summary = this.summary(id, threadId);
197
+ return {
198
+ status: this.status(id, threadId),
199
+ summarized: summary !== null,
200
+ id: threadId,
201
+ channel: text(row, "channel"),
202
+ author: text(row, "author"),
203
+ preview: (params.get("full") === "true"
204
+ ? text(row, "text")
205
+ : (summary?.text ?? text(row, "text"))).slice(0, 600),
206
+ createdAt: text(row, "created_at"),
207
+ lastActivity: text(row, "last_activity"),
208
+ replies: count(row, "replies"),
209
+ };
210
+ }),
211
+ nextCursor: rows.length > 40 && last ? String(count(last, "last_seq")) : null,
212
+ };
213
+ }
214
+ thread(id, threadId, params) {
215
+ this.board(id);
216
+ const root = this.all("SELECT id,channel,author,created_at,text FROM posts WHERE board_id=? AND id=? AND root=id", id, threadId)[0];
217
+ if (!root)
218
+ throw new Error("Thread not found in this board");
219
+ const summary = this.summary(id, threadId);
220
+ const status = this.status(id, threadId);
221
+ if (summary && params.get("full") !== "true")
222
+ return { status, summary, root: null, replies: [], nextCursor: null };
223
+ const rows = this.all("SELECT seq,id,channel,author,created_at,text FROM posts WHERE board_id=? AND root=? AND id<>root AND seq>? ORDER BY seq LIMIT 81", id, threadId, this.cursor(params) ?? 0);
224
+ const visible = rows.slice(0, 80);
225
+ const last = visible.at(-1);
226
+ return {
227
+ status,
228
+ summary,
229
+ root: post(root),
230
+ replies: visible.map(post),
231
+ nextCursor: rows.length > 80 && last ? String(count(last, "seq")) : null,
232
+ };
233
+ }
234
+ cursor(params) {
235
+ const value = params.get("cursor");
236
+ if (value === null)
237
+ return undefined;
238
+ if (!/^[0-9]+$/.test(value) || !Number.isSafeInteger(Number(value)))
239
+ throw new Error("Invalid page cursor");
240
+ return Number(value);
241
+ }
242
+ }
@@ -0,0 +1,85 @@
1
+ import { randomBytes } from "node:crypto";
2
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
3
+ import { homedir } from "node:os";
4
+ import { join } from "node:path";
5
+ export function stateDirectory() {
6
+ return join(process.env["PI_CODING_AGENT_DIR"] || join(homedir(), ".pi", "agent"), "board-viewer");
7
+ }
8
+ function configPath() {
9
+ return join(stateDirectory(), "config.json");
10
+ }
11
+ export async function loadConfig() {
12
+ let value;
13
+ try {
14
+ value = JSON.parse(await readFile(configPath(), "utf8"));
15
+ }
16
+ catch (error) {
17
+ if (!(error instanceof Error && "code" in error && error.code === "ENOENT"))
18
+ throw error;
19
+ value = {};
20
+ }
21
+ if (!value || typeof value !== "object" || Array.isArray(value))
22
+ throw new Error("Viewer config must be an object");
23
+ const config = value;
24
+ const host = config["host"] ?? "127.0.0.1";
25
+ const port = config["port"] ?? 47984;
26
+ if (typeof host !== "string" || !["127.0.0.1", "0.0.0.0"].includes(host))
27
+ throw new Error("Viewer host must be 127.0.0.1 or 0.0.0.0");
28
+ if (typeof port !== "number" ||
29
+ !Number.isInteger(port) ||
30
+ port < 1024 ||
31
+ port > 65535)
32
+ throw new Error("Viewer port must be an integer from 1024 to 65535");
33
+ const publicUrl = config["publicUrl"] ?? `http://127.0.0.1:${port}`;
34
+ if (typeof publicUrl !== "string")
35
+ throw new Error("Viewer publicUrl must be an HTTP or HTTPS origin");
36
+ const url = new URL(publicUrl);
37
+ if (!["http:", "https:"].includes(url.protocol) ||
38
+ url.username ||
39
+ url.password ||
40
+ url.pathname !== "/" ||
41
+ url.search ||
42
+ url.hash)
43
+ throw new Error("Viewer publicUrl must be an HTTP or HTTPS origin without a path");
44
+ const command = config["openCommand"];
45
+ if (command !== undefined &&
46
+ command !== null &&
47
+ (!Array.isArray(command) ||
48
+ !command.length ||
49
+ !command.every((part) => typeof part === "string" && part.length > 0)))
50
+ throw new Error("Viewer openCommand must be an argument array, or null for link only");
51
+ const defaultCommand = process.platform === "darwin"
52
+ ? ["open"]
53
+ : process.platform === "win32"
54
+ ? ["rundll32", "url.dll,FileProtocolHandler"]
55
+ : ["xdg-open"];
56
+ return {
57
+ host,
58
+ port,
59
+ publicUrl: url.origin,
60
+ openCommand: command === null
61
+ ? null
62
+ : command === undefined
63
+ ? defaultCommand
64
+ : command,
65
+ };
66
+ }
67
+ export async function accessKey() {
68
+ const directory = stateDirectory();
69
+ await mkdir(directory, { recursive: true, mode: 0o700 });
70
+ const path = join(directory, "access-key");
71
+ try {
72
+ await writeFile(path, randomBytes(32).toString("hex"), {
73
+ flag: "wx",
74
+ mode: 0o600,
75
+ });
76
+ }
77
+ catch (error) {
78
+ if (!(error instanceof Error && "code" in error && error.code === "EEXIST"))
79
+ throw error;
80
+ }
81
+ const key = (await readFile(path, "utf8")).trim();
82
+ if (!/^[a-f0-9]{64}$/.test(key))
83
+ throw new Error("Invalid viewer access key; remove the access-key file and restart the viewer");
84
+ return key;
85
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,172 @@
1
+ import { randomBytes, timingSafeEqual } from "node:crypto";
2
+ import { readFile } from "node:fs/promises";
3
+ import { createServer, } from "node:http";
4
+ import { pathToFileURL } from "node:url";
5
+ import { Archive } from "./archive.js";
6
+ import { accessKey, loadConfig } from "./config.js";
7
+ import { parseSource } from "./source.js";
8
+ export const PROTOCOL = "pi-board-viewer/1";
9
+ const assets = new Map([
10
+ ["/", ["web/index.html", "text/html; charset=utf-8"]],
11
+ ["/app.js", ["web/app.js", "text/javascript; charset=utf-8"]],
12
+ ["/style.css", ["web/style.css", "text/css; charset=utf-8"]],
13
+ [
14
+ "/vendor/marked.js",
15
+ [import.meta.resolve("marked"), "text/javascript; charset=utf-8"],
16
+ ],
17
+ [
18
+ "/vendor/purify.js",
19
+ [import.meta.resolve("dompurify"), "text/javascript; charset=utf-8"],
20
+ ],
21
+ ]);
22
+ function authenticated(req, secret) {
23
+ const value = req.headers.authorization;
24
+ if (!value?.startsWith("Bearer "))
25
+ return false;
26
+ const provided = Buffer.from(value.slice(7));
27
+ const expected = Buffer.from(secret);
28
+ return (provided.length === expected.length && timingSafeEqual(provided, expected));
29
+ }
30
+ async function body(req) {
31
+ const chunks = [];
32
+ let length = 0;
33
+ for await (const chunk of req) {
34
+ const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
35
+ length += bytes.length;
36
+ if (length > 16_384)
37
+ throw new Error("Viewer request is too large");
38
+ chunks.push(bytes);
39
+ }
40
+ return JSON.parse(Buffer.concat(chunks).toString("utf8"));
41
+ }
42
+ function json(res, status, value) {
43
+ res.writeHead(status, { "Content-Type": "application/json; charset=utf-8" });
44
+ res.end(JSON.stringify(value));
45
+ }
46
+ export async function startServer(config, key) {
47
+ const views = new Map();
48
+ const registered = new Map();
49
+ const server = createServer((req, res) => {
50
+ res.setHeader("Cache-Control", "no-store");
51
+ res.setHeader("Referrer-Policy", "no-referrer");
52
+ res.setHeader("X-Content-Type-Options", "nosniff");
53
+ res.setHeader("Content-Security-Policy", "default-src 'none'; script-src 'self'; style-src 'self'; connect-src 'self'; img-src 'self' data:; font-src 'self'; base-uri 'none'; frame-ancestors 'none'; form-action 'none'");
54
+ void handle(req, res).catch((error) => {
55
+ if (res.headersSent) {
56
+ res.destroy();
57
+ return;
58
+ }
59
+ json(res, 400, {
60
+ error: error instanceof Error ? error.message : "Viewer request failed",
61
+ });
62
+ });
63
+ });
64
+ server.headersTimeout = 10_000;
65
+ server.requestTimeout = 10_000;
66
+ server.maxHeadersCount = 50;
67
+ async function handle(req, res) {
68
+ const url = new URL(req.url ?? "/", "http://localhost");
69
+ if (req.method === "GET" && url.pathname === "/api/health") {
70
+ json(res, 200, {
71
+ protocol: PROTOCOL,
72
+ host: config.host,
73
+ publicUrl: config.publicUrl,
74
+ pid: process.pid,
75
+ });
76
+ return;
77
+ }
78
+ if (req.method === "POST" && url.pathname === "/api/open") {
79
+ // Only the local extension may register filesystem sources. View links cannot.
80
+ if (req.socket.remoteAddress !== "127.0.0.1" ||
81
+ !authenticated(req, key)) {
82
+ json(res, 403, {
83
+ error: "Only the local Pi extension can open a board archive",
84
+ });
85
+ return;
86
+ }
87
+ const source = parseSource(await body(req));
88
+ const archive = new Archive(source);
89
+ try {
90
+ archive.index();
91
+ }
92
+ finally {
93
+ archive.close();
94
+ }
95
+ const identity = JSON.stringify(source);
96
+ const token = registered.get(identity) ?? randomBytes(32).toString("hex");
97
+ registered.set(identity, token);
98
+ views.set(token, source);
99
+ json(res, 200, { url: `${config.publicUrl}/#view=${token}` });
100
+ return;
101
+ }
102
+ if (req.method !== "GET") {
103
+ json(res, 405, { error: "The board viewer is read-only" });
104
+ return;
105
+ }
106
+ if (url.pathname.startsWith("/api/")) {
107
+ const token = req.headers.authorization?.replace(/^Bearer /, "") ?? "";
108
+ const source = views.get(token);
109
+ if (!source) {
110
+ json(res, 401, {
111
+ error: "This viewer link has expired. Run /board in Pi for a new link.",
112
+ });
113
+ return;
114
+ }
115
+ const archive = new Archive(source);
116
+ try {
117
+ const board = url.searchParams.get("boardId") ?? source.boardId;
118
+ let result;
119
+ switch (url.pathname) {
120
+ case "/api/boards":
121
+ result = archive.index();
122
+ break;
123
+ case "/api/board":
124
+ result = archive.detail(board);
125
+ break;
126
+ case "/api/threads":
127
+ result = archive.threads(board, url.searchParams);
128
+ break;
129
+ case "/api/thread":
130
+ result = archive.thread(board, url.searchParams.get("id") ?? "", url.searchParams);
131
+ break;
132
+ default:
133
+ json(res, 404, { error: "Unknown viewer request" });
134
+ return;
135
+ }
136
+ json(res, 200, result);
137
+ }
138
+ finally {
139
+ archive.close();
140
+ }
141
+ return;
142
+ }
143
+ const asset = assets.get(url.pathname);
144
+ if (!asset) {
145
+ json(res, 404, { error: "Page not found" });
146
+ return;
147
+ }
148
+ const content = await readFile(new URL(asset[0], import.meta.url));
149
+ res.writeHead(200, { "Content-Type": asset[1] });
150
+ res.end(content);
151
+ }
152
+ await new Promise((resolve, reject) => {
153
+ server.once("error", reject);
154
+ server.listen(config.port, config.host, () => {
155
+ server.removeListener("error", reject);
156
+ resolve();
157
+ });
158
+ });
159
+ return server;
160
+ }
161
+ if (process.argv[1] &&
162
+ import.meta.url === pathToFileURL(process.argv[1]).href) {
163
+ const config = await loadConfig();
164
+ const server = await startServer(config, await accessKey());
165
+ console.log(`Board viewer listening on ${config.host}:${config.port} (PID ${process.pid})`);
166
+ const stop = () => {
167
+ server.close();
168
+ server.closeAllConnections();
169
+ };
170
+ process.once("SIGTERM", stop);
171
+ process.once("SIGINT", stop);
172
+ }
@@ -0,0 +1,29 @@
1
+ import { isAbsolute } from "node:path";
2
+ export function parseSource(value) {
3
+ if (!value || typeof value !== "object" || Array.isArray(value))
4
+ throw new Error("Invalid viewer source");
5
+ const fields = value;
6
+ const required = (key) => {
7
+ const field = fields[key];
8
+ if (typeof field !== "string" ||
9
+ !field.length ||
10
+ field.length > 4096 ||
11
+ field.includes("\0"))
12
+ throw new Error(`Invalid viewer ${key}`);
13
+ return field;
14
+ };
15
+ const folder = required("folder");
16
+ const databasePath = required("databasePath");
17
+ if (!isAbsolute(folder) || !isAbsolute(databasePath))
18
+ throw new Error("Viewer source paths must be absolute");
19
+ const sessionName = fields["sessionName"];
20
+ if (sessionName !== null && typeof sessionName !== "string")
21
+ throw new Error("Invalid viewer session name");
22
+ return {
23
+ sessionId: required("sessionId"),
24
+ boardId: required("boardId"),
25
+ sessionName,
26
+ folder,
27
+ databasePath,
28
+ };
29
+ }