@khanglvm/relay 0.21.0 → 0.22.1
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/docs/AGENT.md +14 -2
- package/package.json +6 -1
- package/schema/spec.v1.json +55 -3
- package/skills/relay/SKILL.md +2 -1
- package/src/a2ui/board-catalog.json +1004 -0
- package/src/a2ui/board-constants.js +35 -0
- package/src/a2ui/board.js +5 -0
- package/src/a2ui/from-a2ui.js +71 -0
- package/src/a2ui/negotiate.js +38 -0
- package/src/a2ui/to-a2ui.js +147 -0
- package/src/cli/args.js +4 -2
- package/src/cli/ask.js +4 -3
- package/src/cli/boards.js +10 -7
- package/src/cli/git.js +5 -3
- package/src/cli/help.js +3 -1
- package/src/cli/io.js +21 -0
- package/src/cli/mcp.js +31 -2
- package/src/file-access.js +117 -0
- package/src/file-preview.js +1 -1
- package/src/mcp/boards.js +30 -7
- package/src/mcp/constants.js +3 -1
- package/src/mcp/schemas.js +5 -2
- package/src/mcp/serve.js +4 -4
- package/src/mcp/server.js +2 -1
- package/src/mcp/store.js +2 -2
- package/src/mcp/token.js +33 -8
- package/src/mcp/tools.js +16 -7
- package/src/mcp-ui/board/normalize.js +12 -0
- package/src/mcp-ui/board/render.js +2 -1
- package/src/mcp-ui/board/state.js +3 -0
- package/src/server/board.js +30 -22
- package/src/server/files.js +10 -0
- package/src/server/http.js +19 -0
- package/src/server/page.js +4 -0
- package/src/spec/blocks/a2ui.js +1 -1
- package/src/spec/blocks/chart.js +1 -1
- package/src/spec/blocks/code.js +4 -4
- package/src/spec/blocks/diagram.js +3 -3
- package/src/spec/blocks/git-conflict.js +2 -2
- package/src/spec/blocks/image.js +6 -5
- package/src/spec/blocks/markdown.js +2 -2
- package/src/spec/blocks/pdf.js +4 -10
- package/src/spec/blocks/table.js +5 -4
- package/src/spec/blocks/video.js +4 -10
- package/src/spec/blocks/widgets.js +6 -6
- package/src/spec/constants.js +13 -1
- package/src/spec/index.js +1 -0
- package/src/spec/lookup.js +1 -0
- package/src/spec/normalize.js +20 -10
- package/src/spec/pick.js +104 -0
- package/src/spec/schema.js +26 -3
- package/src/spec/sources.js +19 -24
- package/src/store.js +6 -1
- package/src/ui/app/drafts.js +3 -0
- package/src/ui/app/render.js +1 -0
- package/src/ui/app/submit.js +1 -1
- package/src/ui/manifest.js +2 -1
- package/src/ui/pick.css +32 -0
- package/src/ui/pick.js +246 -0
- package/types/a2ui/board-constants.d.ts +24 -0
- package/types/a2ui/from-a2ui.d.ts +16 -0
- package/types/a2ui/negotiate.d.ts +17 -0
- package/types/a2ui/to-a2ui.d.ts +12 -0
- package/types/file-access.d.ts +62 -0
- package/types/mcp/boards.d.ts +13 -2
- package/types/mcp/schemas.d.ts +5 -2
- package/types/mcp/serve.d.ts +5 -2
- package/types/mcp/store.d.ts +6 -3
- package/types/mcp/token.d.ts +5 -1
- package/types/mcp/tools.d.ts +2 -0
- package/types/spec/blocks/a2ui.d.ts +1 -1
- package/types/spec/blocks/chart.d.ts +1 -1
- package/types/spec/blocks/code.d.ts +2 -2
- package/types/spec/blocks/diagram.d.ts +3 -3
- package/types/spec/blocks/git-conflict.d.ts +1 -1
- package/types/spec/blocks/image.d.ts +2 -2
- package/types/spec/blocks/markdown.d.ts +1 -1
- package/types/spec/blocks/pdf.d.ts +1 -1
- package/types/spec/blocks/table.d.ts +1 -1
- package/types/spec/blocks/video.d.ts +1 -1
- package/types/spec/blocks/widgets.d.ts +4 -4
- package/types/spec/constants.d.ts +9 -0
- package/types/spec/index.d.ts +1 -0
- package/types/spec/lookup.d.ts +2 -1
- package/types/spec/normalize.d.ts +7 -1
- package/types/spec/pick.d.ts +25 -0
- package/types/spec/schema.d.ts +48 -0
- package/types/spec/sources.d.ts +5 -4
- package/types/store.d.ts +8 -1
|
@@ -4,7 +4,7 @@ import { asStr, clampInt } from '../sources.js';
|
|
|
4
4
|
import { BLOCK_HEIGHT } from '../constants.js';
|
|
5
5
|
|
|
6
6
|
// Normalizes one mermaid block. `id` is the already-assigned block id.
|
|
7
|
-
export function normalizeMermaidBlock(rawBlock, id,
|
|
7
|
+
export function normalizeMermaidBlock(rawBlock, id, files, where, hasHeight) {
|
|
8
8
|
const code = asStr(rawBlock.code);
|
|
9
9
|
if (!code.trim()) throw new CliError(`${where}: mermaid block needs a non-empty "code" string.`);
|
|
10
10
|
const block = { id, type: 'mermaid', code };
|
|
@@ -14,7 +14,7 @@ export function normalizeMermaidBlock(rawBlock, id, cwd, where, hasHeight) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
// Normalizes one graphviz block. `id` is the already-assigned block id.
|
|
17
|
-
export function normalizeGraphvizBlock(rawBlock, id,
|
|
17
|
+
export function normalizeGraphvizBlock(rawBlock, id, files, where, hasHeight) {
|
|
18
18
|
const dot = asStr(rawBlock.dot);
|
|
19
19
|
if (!dot.trim()) throw new CliError(`${where}: graphviz block needs a non-empty "dot" string.`);
|
|
20
20
|
const block = { id, type: 'graphviz', dot };
|
|
@@ -23,7 +23,7 @@ export function normalizeGraphvizBlock(rawBlock, id, cwd, where, hasHeight) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// Normalizes one plantuml block. `id` is the already-assigned block id.
|
|
26
|
-
export function normalizePlantumlBlock(rawBlock, id,
|
|
26
|
+
export function normalizePlantumlBlock(rawBlock, id, files, where, hasHeight) {
|
|
27
27
|
const code = asStr(rawBlock.code);
|
|
28
28
|
if (!code.trim()) throw new CliError(`${where}: plantuml block needs a non-empty "code" string.`);
|
|
29
29
|
const block = { id, type: 'plantuml', code };
|
|
@@ -80,8 +80,8 @@ function parseGitConflictContent(content, where) {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
// Normalizes one git-conflict block. `id` is the already-assigned block id.
|
|
83
|
-
export function normalizeGitConflictBlock(rawBlock, id,
|
|
84
|
-
const src = readAnyTextSource(rawBlock, ['content', 'text'], ['file', 'path', 'src'],
|
|
83
|
+
export function normalizeGitConflictBlock(rawBlock, id, files, where, hasHeight) {
|
|
84
|
+
const src = readAnyTextSource(rawBlock, ['content', 'text'], ['file', 'path', 'src'], files, where, 'git conflict file');
|
|
85
85
|
if (!src.text.trim()) {
|
|
86
86
|
throw new CliError(`${where}: git-conflict block needs inline "content"/"text" or a readable local "file"/"path".`);
|
|
87
87
|
}
|
package/src/spec/blocks/image.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// The image block, and the image reader that compare blocks share.
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
+
import { resolveReadable } from '../../file-access.js';
|
|
4
5
|
import { CliError } from '../../util.js';
|
|
5
6
|
import { asStr, clampInt } from '../sources.js';
|
|
6
7
|
import { BLOCK_HEIGHT, IMAGE_MAX_BYTES, IMAGE_MIMES } from '../constants.js';
|
|
@@ -8,14 +9,14 @@ import { BLOCK_HEIGHT, IMAGE_MAX_BYTES, IMAGE_MIMES } from '../constants.js';
|
|
|
8
9
|
// Resolve an image source (shared by the `image` and `compare` blocks): an
|
|
9
10
|
// http(s)/data URL passes through; a local file is read + embedded as a data
|
|
10
11
|
// URI (capped) so the board stays self-contained offline.
|
|
11
|
-
export function resolveImageSrc(srcRaw,
|
|
12
|
+
export function resolveImageSrc(srcRaw, files, where, field) {
|
|
12
13
|
const src = asStr(srcRaw).trim();
|
|
13
14
|
if (!src) throw new CliError(`${where}: ${field} needs a "src" (http(s)/data URL or local file path).`);
|
|
14
15
|
if (/^(https?:|data:)/i.test(src)) return src;
|
|
15
|
-
const
|
|
16
|
-
const ext = path.extname(p).slice(1).toLowerCase();
|
|
16
|
+
const ext = path.extname(src).slice(1).toLowerCase();
|
|
17
17
|
const mime = IMAGE_MIMES[ext];
|
|
18
18
|
if (!mime) throw new CliError(`${where}: ${field}: unsupported image extension ".${ext}" — use ${Object.keys(IMAGE_MIMES).join('/')}, or an http(s)/data URL.`);
|
|
19
|
+
const { file: p } = resolveReadable(files, src, where, field);
|
|
19
20
|
let buf;
|
|
20
21
|
try { buf = fs.readFileSync(p); } catch { throw new CliError(`${where}: ${field}: cannot read image "${src}" (resolved: ${p})`); }
|
|
21
22
|
if (buf.length > IMAGE_MAX_BYTES) throw new CliError(`${where}: ${field}: image "${src}" is ${(buf.length / 1024 / 1024).toFixed(1)}MB — max ${IMAGE_MAX_BYTES / 1024 / 1024}MB.`);
|
|
@@ -23,9 +24,9 @@ export function resolveImageSrc(srcRaw, cwd, where, field) {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
// Normalizes one image block. `id` is the already-assigned block id.
|
|
26
|
-
export function normalizeImageBlock(rawBlock, id,
|
|
27
|
+
export function normalizeImageBlock(rawBlock, id, files, where, hasHeight) {
|
|
27
28
|
const block = { id, type: 'image' };
|
|
28
|
-
block.src = resolveImageSrc(rawBlock.src ?? rawBlock.file ?? rawBlock.url,
|
|
29
|
+
block.src = resolveImageSrc(rawBlock.src ?? rawBlock.file ?? rawBlock.url, files, where, 'image block');
|
|
29
30
|
if (rawBlock.alt !== undefined) block.alt = asStr(rawBlock.alt);
|
|
30
31
|
if (hasHeight) block.height = clampInt(rawBlock.height, BLOCK_HEIGHT.min, BLOCK_HEIGHT.max, undefined);
|
|
31
32
|
return block;
|
|
@@ -4,8 +4,8 @@ import { clampInt, readTextSource } from '../sources.js';
|
|
|
4
4
|
import { BLOCK_HEIGHT } from '../constants.js';
|
|
5
5
|
|
|
6
6
|
// Normalizes one markdown block. `id` is the already-assigned block id.
|
|
7
|
-
export function normalizeMarkdownBlock(rawBlock, id,
|
|
8
|
-
const md = readTextSource(rawBlock, 'md', 'mdFile',
|
|
7
|
+
export function normalizeMarkdownBlock(rawBlock, id, files, where, hasHeight) {
|
|
8
|
+
const md = readTextSource(rawBlock, 'md', 'mdFile', files, where);
|
|
9
9
|
if (!md.trim()) throw new CliError(`${where}: markdown block needs a non-empty "md" string or a readable "mdFile".`);
|
|
10
10
|
const block = { id, type: 'markdown', md };
|
|
11
11
|
if (hasHeight) block.height = clampInt(rawBlock.height, BLOCK_HEIGHT.min, BLOCK_HEIGHT.max, undefined);
|
package/src/spec/blocks/pdf.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// The pdf block.
|
|
2
|
-
import fs from 'node:fs';
|
|
3
2
|
import path from 'node:path';
|
|
3
|
+
import { resolveReadable } from '../../file-access.js';
|
|
4
4
|
import { CliError } from '../../util.js';
|
|
5
5
|
import { asStr, clampInt } from '../sources.js';
|
|
6
6
|
import { BLOCK_HEIGHT, PDF_MAX_BYTES, PDF_MIME } from '../constants.js';
|
|
7
7
|
|
|
8
8
|
// Normalizes one pdf block. `id` is the already-assigned block id.
|
|
9
|
-
export function normalizePdfBlock(rawBlock, id,
|
|
9
|
+
export function normalizePdfBlock(rawBlock, id, files, where, hasHeight) {
|
|
10
10
|
const src = asStr(rawBlock.src ?? rawBlock.file ?? rawBlock.url).trim();
|
|
11
11
|
if (!src) throw new CliError(`${where}: pdf block needs a "src" (http(s) PDF URL or local .pdf file path).`);
|
|
12
12
|
const block = { id, type: 'pdf' };
|
|
@@ -19,15 +19,9 @@ export function normalizePdfBlock(rawBlock, id, cwd, where, hasHeight) {
|
|
|
19
19
|
if (!block.title) block.title = path.basename(src.split(/[?#]/)[0]) || 'PDF';
|
|
20
20
|
return block;
|
|
21
21
|
}
|
|
22
|
-
const
|
|
23
|
-
const ext = path.extname(p).slice(1).toLowerCase();
|
|
22
|
+
const ext = path.extname(src).slice(1).toLowerCase();
|
|
24
23
|
if (ext !== 'pdf') throw new CliError(`${where}: unsupported pdf extension ".${ext}" — use a local .pdf file or an http(s) PDF URL.`);
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
stat = fs.statSync(p);
|
|
28
|
-
} catch {
|
|
29
|
-
throw new CliError(`${where}: cannot read pdf "${src}" (resolved: ${p})`);
|
|
30
|
-
}
|
|
24
|
+
const { file: p, stat } = resolveReadable(files, src, where, 'pdf');
|
|
31
25
|
if (stat.size > PDF_MAX_BYTES) {
|
|
32
26
|
throw new CliError(`${where}: pdf "${src}" is ${(stat.size / 1024 / 1024).toFixed(0)}MB — max ${PDF_MAX_BYTES / 1024 / 1024}MB.`);
|
|
33
27
|
}
|
package/src/spec/blocks/table.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// The table block: CSV, TSV and JSON row files, and normalization.
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
+
import { resolveReadable } from '../../file-access.js';
|
|
4
5
|
import { CliError } from '../../util.js';
|
|
5
6
|
import { BLOCK_HEIGHT, TEXT_FILE_MAX_BYTES } from '../constants.js';
|
|
6
7
|
import { asStr, clampInt } from '../sources.js';
|
|
@@ -38,8 +39,8 @@ function parseDelimited(text, delim) {
|
|
|
38
39
|
// Load table {columns, rows} from a local .csv/.tsv/.json file (rowsFile).
|
|
39
40
|
// CSV/TSV: first row = header → column keys. JSON: an array of objects (columns
|
|
40
41
|
// from the union of keys) or arrays (needs explicit "columns").
|
|
41
|
-
function loadRowsFile(file,
|
|
42
|
-
const p =
|
|
42
|
+
function loadRowsFile(file, files, where) {
|
|
43
|
+
const { file: p } = resolveReadable(files, file, where, 'rowsFile');
|
|
43
44
|
let buf;
|
|
44
45
|
try { buf = fs.readFileSync(p); } catch { throw new CliError(`${where}: cannot read rowsFile "${file}" (resolved: ${p})`); }
|
|
45
46
|
if (buf.length > TEXT_FILE_MAX_BYTES) {
|
|
@@ -71,12 +72,12 @@ function loadRowsFile(file, cwd, where) {
|
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
// Normalizes one table block. `id` is the already-assigned block id.
|
|
74
|
-
export function normalizeTableBlock(rawBlock, id,
|
|
75
|
+
export function normalizeTableBlock(rawBlock, id, files, where, hasHeight) {
|
|
75
76
|
// Rows/columns may come from a local .csv/.tsv/.json file instead of inline.
|
|
76
77
|
let rawColumns = rawBlock.columns;
|
|
77
78
|
let rawRows = rawBlock.rows;
|
|
78
79
|
if (typeof rawBlock.rowsFile === 'string' && rawBlock.rowsFile.trim() && !Array.isArray(rawRows)) {
|
|
79
|
-
const loaded = loadRowsFile(rawBlock.rowsFile,
|
|
80
|
+
const loaded = loadRowsFile(rawBlock.rowsFile, files, where);
|
|
80
81
|
rawRows = loaded.rows;
|
|
81
82
|
if (!Array.isArray(rawColumns) || !rawColumns.length) rawColumns = loaded.columns;
|
|
82
83
|
}
|
package/src/spec/blocks/video.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The video block: embed detection for YouTube and Vimeo, local and direct media.
|
|
2
|
-
import fs from 'node:fs';
|
|
3
2
|
import path from 'node:path';
|
|
3
|
+
import { resolveReadable } from '../../file-access.js';
|
|
4
4
|
import { CliError } from '../../util.js';
|
|
5
5
|
import { asStr, clampInt } from '../sources.js';
|
|
6
6
|
import { BLOCK_HEIGHT, VIDEO_MAX_BYTES, VIDEO_MIMES } from '../constants.js';
|
|
@@ -24,7 +24,7 @@ function parseVideoEmbed(src) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// Normalizes one video block. `id` is the already-assigned block id.
|
|
27
|
-
export function normalizeVideoBlock(rawBlock, id,
|
|
27
|
+
export function normalizeVideoBlock(rawBlock, id, files, where, hasHeight) {
|
|
28
28
|
const src = asStr(rawBlock.src ?? rawBlock.file ?? rawBlock.url).trim();
|
|
29
29
|
if (!src) throw new CliError(`${where}: video block needs a "src" (YouTube/Vimeo URL, http(s) media URL, or local file path).`);
|
|
30
30
|
const block = { id, type: 'video' };
|
|
@@ -46,18 +46,12 @@ export function normalizeVideoBlock(rawBlock, id, cwd, where, hasHeight) {
|
|
|
46
46
|
}
|
|
47
47
|
// local file — kept as an absolute path the server streams (never embedded
|
|
48
48
|
// in the payload). The client only learns a flag + mime via /video/b/<id>.
|
|
49
|
-
const
|
|
50
|
-
const ext = path.extname(p).slice(1).toLowerCase();
|
|
49
|
+
const ext = path.extname(src).slice(1).toLowerCase();
|
|
51
50
|
const mime = VIDEO_MIMES[ext];
|
|
52
51
|
if (!mime) {
|
|
53
52
|
throw new CliError(`${where}: unsupported video extension ".${ext}" — use ${Object.keys(VIDEO_MIMES).join('/')}, a YouTube/Vimeo URL, or an http(s) media URL.`);
|
|
54
53
|
}
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
stat = fs.statSync(p);
|
|
58
|
-
} catch {
|
|
59
|
-
throw new CliError(`${where}: cannot read video "${src}" (resolved: ${p})`);
|
|
60
|
-
}
|
|
54
|
+
const { file: p, stat } = resolveReadable(files, src, where, 'video');
|
|
61
55
|
if (stat.size > VIDEO_MAX_BYTES) {
|
|
62
56
|
throw new CliError(`${where}: video "${src}" is ${(stat.size / 1024 / 1024).toFixed(0)}MB — max ${VIDEO_MAX_BYTES / 1024 / 1024}MB.`);
|
|
63
57
|
}
|
|
@@ -5,7 +5,7 @@ import { resolveImageSrc } from './image.js';
|
|
|
5
5
|
import { BLOCK_HEIGHT } from '../constants.js';
|
|
6
6
|
|
|
7
7
|
// Normalizes one kpi block. `id` is the already-assigned block id.
|
|
8
|
-
export function normalizeKpiBlock(rawBlock, id,
|
|
8
|
+
export function normalizeKpiBlock(rawBlock, id, files, where, hasHeight) {
|
|
9
9
|
// Stat cards: a row of big-number metrics, each with an optional delta
|
|
10
10
|
// (up/down tinted) and sublabel. For "revenue ↑12%" at a glance, no chart.
|
|
11
11
|
const rawItems = Array.isArray(rawBlock.items) ? rawBlock.items : [];
|
|
@@ -25,7 +25,7 @@ export function normalizeKpiBlock(rawBlock, id, cwd, where, hasHeight) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
// Normalizes one typography block. `id` is the already-assigned block id.
|
|
28
|
-
export function normalizeTypographyBlock(rawBlock, id,
|
|
28
|
+
export function normalizeTypographyBlock(rawBlock, id, files, where, hasHeight) {
|
|
29
29
|
// Type specimens: render sample text at given size/weight/font so a designer
|
|
30
30
|
// can react to type choices the way they react to a palette.
|
|
31
31
|
const raw = Array.isArray(rawBlock.specimens) ? rawBlock.specimens : (Array.isArray(rawBlock.samples) ? rawBlock.samples : []);
|
|
@@ -50,14 +50,14 @@ export function normalizeTypographyBlock(rawBlock, id, cwd, where, hasHeight) {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// Normalizes one compare block. `id` is the already-assigned block id.
|
|
53
|
-
export function normalizeCompareBlock(rawBlock, id,
|
|
53
|
+
export function normalizeCompareBlock(rawBlock, id, files, where, hasHeight) {
|
|
54
54
|
// Before/after: two images with a draggable divider to compare a redesign.
|
|
55
55
|
const beforeRaw = rawBlock.before && typeof rawBlock.before === 'object' ? rawBlock.before.src : (rawBlock.before ?? rawBlock.beforeSrc);
|
|
56
56
|
const afterRaw = rawBlock.after && typeof rawBlock.after === 'object' ? rawBlock.after.src : (rawBlock.after ?? rawBlock.afterSrc);
|
|
57
57
|
const block = {
|
|
58
58
|
id, type: 'compare',
|
|
59
|
-
before: resolveImageSrc(beforeRaw,
|
|
60
|
-
after: resolveImageSrc(afterRaw,
|
|
59
|
+
before: resolveImageSrc(beforeRaw, files, where, '"before"'),
|
|
60
|
+
after: resolveImageSrc(afterRaw, files, where, '"after"'),
|
|
61
61
|
};
|
|
62
62
|
block.beforeLabel = asStr(rawBlock.beforeLabel ?? (rawBlock.before && rawBlock.before.label) ?? 'Before') || 'Before';
|
|
63
63
|
block.afterLabel = asStr(rawBlock.afterLabel ?? (rawBlock.after && rawBlock.after.label) ?? 'After') || 'After';
|
|
@@ -66,7 +66,7 @@ export function normalizeCompareBlock(rawBlock, id, cwd, where, hasHeight) {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
// Normalizes one palette block. `id` is the already-assigned block id.
|
|
69
|
-
export function normalizePaletteBlock(rawBlock, id,
|
|
69
|
+
export function normalizePaletteBlock(rawBlock, id, files, where, hasHeight) {
|
|
70
70
|
// Accept either { palettes: [{name, colors:[…]}, …] } or a single-palette
|
|
71
71
|
// shorthand { name?, colors:[…] }. Each palette needs a non-empty colors
|
|
72
72
|
// array of CSS color strings (#rrggbb, rgb(), hsl(), named — kept as given).
|
package/src/spec/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Limits, allowed values and aliases that the spec readers share.
|
|
2
2
|
|
|
3
|
-
export const TYPES = ['single', 'multi', 'yesno', 'text', 'textarea', 'scale', 'color', 'rank', 'checklist', 'allocate'];
|
|
3
|
+
export const TYPES = ['single', 'multi', 'yesno', 'text', 'textarea', 'scale', 'color', 'rank', 'checklist', 'allocate', 'pick'];
|
|
4
4
|
|
|
5
5
|
export const ALIASES = {
|
|
6
6
|
radio: 'single',
|
|
@@ -31,6 +31,9 @@ export const ALIASES = {
|
|
|
31
31
|
budget: 'allocate',
|
|
32
32
|
distribute: 'allocate',
|
|
33
33
|
points: 'allocate',
|
|
34
|
+
tiles: 'pick',
|
|
35
|
+
gallery: 'pick',
|
|
36
|
+
shortlist: 'pick',
|
|
34
37
|
};
|
|
35
38
|
|
|
36
39
|
// Block type names agents reach for that mean one of ours. A chart kind used as
|
|
@@ -82,3 +85,12 @@ export const IMAGE_MIMES = {
|
|
|
82
85
|
webp: 'image/webp', svg: 'image/svg+xml', avif: 'image/avif', bmp: 'image/bmp',
|
|
83
86
|
};
|
|
84
87
|
export const IMAGE_MAX_BYTES = 8 * 1024 * 1024;
|
|
88
|
+
|
|
89
|
+
// pick questions: media tiles the person chooses among. Local images are embedded
|
|
90
|
+
// as data URIs like image blocks, so the total is capped, not just each file.
|
|
91
|
+
export const PICK = {
|
|
92
|
+
maxItems: 60,
|
|
93
|
+
maxImageBytes: 24 * 1024 * 1024,
|
|
94
|
+
maxNoteChars: 2000,
|
|
95
|
+
maxOverallChars: 5000,
|
|
96
|
+
};
|
package/src/spec/index.js
CHANGED
package/src/spec/lookup.js
CHANGED
|
@@ -46,6 +46,7 @@ export const QUESTION_FIELDS = {
|
|
|
46
46
|
rank: ['options', 'default'],
|
|
47
47
|
checklist: ['options', 'statuses', 'default'],
|
|
48
48
|
allocate: ['options', 'total', 'unit', 'default'],
|
|
49
|
+
pick: ['items', 'min', 'max', 'itemNote', 'overall', 'default'],
|
|
49
50
|
};
|
|
50
51
|
|
|
51
52
|
function pick(props, names) {
|
package/src/spec/normalize.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
// Turns an agent-written spec into the normalized shape that boards,
|
|
2
2
|
// the server and the MCP App read.
|
|
3
|
+
import { createFileAccess } from '../file-access.js';
|
|
3
4
|
import { CliError } from '../util.js';
|
|
4
5
|
import { asStr, clampInt, readBlockHtml, readHtml } from './sources.js';
|
|
5
6
|
import { ALIASES, BLOCK_ALIASES, BLOCK_HEIGHT, BLOCK_TYPES, CHART_KINDS, HTML_HEIGHT, TYPES } from './constants.js';
|
|
6
7
|
import { BLOCK_NORMALIZERS } from './blocks/index.js';
|
|
8
|
+
import { normalizePick } from './pick.js';
|
|
7
9
|
|
|
8
10
|
// Normalizes one block object. `id` is the already-assigned block id.
|
|
9
11
|
// Returns the normalized block (with a guaranteed string `type` + `id`).
|
|
10
|
-
function normalizeBlock(rawBlock, id,
|
|
12
|
+
function normalizeBlock(rawBlock, id, files, where) {
|
|
11
13
|
if (rawBlock === null || typeof rawBlock !== 'object' || Array.isArray(rawBlock)) {
|
|
12
14
|
throw new CliError(`${where}: must be an object with a "type".`);
|
|
13
15
|
}
|
|
@@ -58,9 +60,9 @@ function normalizeBlock(rawBlock, id, cwd, where) {
|
|
|
58
60
|
|
|
59
61
|
// type === 'html'
|
|
60
62
|
const normalizer = BLOCK_NORMALIZERS[type];
|
|
61
|
-
if (normalizer) return normalizer(rawBlock, id,
|
|
63
|
+
if (normalizer) return normalizer(rawBlock, id, files, where, hasHeight);
|
|
62
64
|
|
|
63
|
-
const html = readBlockHtml(rawBlock,
|
|
65
|
+
const html = readBlockHtml(rawBlock, files, where);
|
|
64
66
|
if (!html) {
|
|
65
67
|
throw new CliError(`${where}: html block needs an "html" string or readable "htmlFile".`);
|
|
66
68
|
}
|
|
@@ -75,13 +77,13 @@ function normalizeBlock(rawBlock, id, cwd, where) {
|
|
|
75
77
|
// Builds the normalized block list for a scope (board or question).
|
|
76
78
|
// Legacy html/htmlFile become a PREPENDED html block; ids are assigned in
|
|
77
79
|
// final order with `prefix` ('' for board → b1,b2…; '<qid>-' for questions).
|
|
78
|
-
function buildBlocks(rawObj,
|
|
80
|
+
function buildBlocks(rawObj, files, where, prefix) {
|
|
79
81
|
const blocks = [];
|
|
80
82
|
let n = 0;
|
|
81
83
|
const nextId = () => `${prefix}b${++n}`;
|
|
82
84
|
|
|
83
85
|
// Legacy html/htmlFile → a single prepended html block. htmlHeight applies.
|
|
84
|
-
const legacyHtml = readHtml(rawObj,
|
|
86
|
+
const legacyHtml = readHtml(rawObj, files, where);
|
|
85
87
|
if (legacyHtml) {
|
|
86
88
|
const def = prefix ? HTML_HEIGHT.questionDefault : HTML_HEIGHT.boardDefault;
|
|
87
89
|
blocks.push({
|
|
@@ -95,7 +97,7 @@ function buildBlocks(rawObj, cwd, where, prefix) {
|
|
|
95
97
|
if (rawObj.blocks !== undefined && rawObj.blocks !== null) {
|
|
96
98
|
if (!Array.isArray(rawObj.blocks)) throw new CliError(`${where}.blocks: must be an array.`);
|
|
97
99
|
rawObj.blocks.forEach((b, i) => {
|
|
98
|
-
const nb = normalizeBlock(b, nextId(),
|
|
100
|
+
const nb = normalizeBlock(b, nextId(), files, `${where}.blocks[${i}]`);
|
|
99
101
|
// Cross-block fields handled uniformly so every block type supports them:
|
|
100
102
|
// `ref` = a stable name a markdown reference link can open in a modal;
|
|
101
103
|
// `pins` = enable coordinate pin-comments on an image.
|
|
@@ -109,14 +111,20 @@ function buildBlocks(rawObj, cwd, where, prefix) {
|
|
|
109
111
|
return blocks;
|
|
110
112
|
}
|
|
111
113
|
|
|
112
|
-
|
|
114
|
+
/**
|
|
115
|
+
* @param {Record<string, any>} raw
|
|
116
|
+
* @param {{ cwd?: string, fileRoots?: string[] }} [options] `fileRoots` limits which local files the spec may read
|
|
117
|
+
* (default: `cwd` only); `[]` allows none, for a spec that came from a remote client.
|
|
118
|
+
*/
|
|
119
|
+
export function normalizeSpec(raw, { cwd = process.cwd(), fileRoots = [cwd] } = {}) {
|
|
120
|
+
const files = createFileAccess({ cwd, roots: fileRoots });
|
|
113
121
|
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
114
122
|
throw new CliError('Spec must be a JSON object. Run `rly agent` for the schema and examples.');
|
|
115
123
|
}
|
|
116
124
|
const spec = {
|
|
117
125
|
title: asStr(raw.title).trim() || 'Relay',
|
|
118
126
|
intro: asStr(raw.intro),
|
|
119
|
-
blocks: buildBlocks(raw,
|
|
127
|
+
blocks: buildBlocks(raw, files, 'board', ''),
|
|
120
128
|
allowPartial: raw.allowPartial !== false,
|
|
121
129
|
note: raw.note !== false,
|
|
122
130
|
autoClose: raw.autoClose !== false,
|
|
@@ -159,7 +167,7 @@ export function normalizeSpec(raw, { cwd = process.cwd() } = {}) {
|
|
|
159
167
|
note: rq.note === undefined
|
|
160
168
|
? (type === 'single' || type === 'rank' || type === 'checklist' || type === 'allocate')
|
|
161
169
|
: rq.note === true,
|
|
162
|
-
blocks: buildBlocks(rq,
|
|
170
|
+
blocks: buildBlocks(rq, files, where, `${id}-`),
|
|
163
171
|
placeholder: asStr(rq.placeholder),
|
|
164
172
|
};
|
|
165
173
|
|
|
@@ -178,7 +186,7 @@ export function normalizeSpec(raw, { cwd = process.cwd() } = {}) {
|
|
|
178
186
|
// Per-option visuals: any block type, rendered inside the option card
|
|
179
187
|
// (ids <qid>-o<n>-b<m>). Lets a choice show its example instead of
|
|
180
188
|
// making the user read-and-guess.
|
|
181
|
-
const oblocks = buildBlocks(o,
|
|
189
|
+
const oblocks = buildBlocks(o, files, `${where}.options[${j}]`, `${id}-o${j + 1}-`);
|
|
182
190
|
if (oblocks.length) out.blocks = oblocks;
|
|
183
191
|
return out;
|
|
184
192
|
}
|
|
@@ -197,6 +205,8 @@ export function normalizeSpec(raw, { cwd = process.cwd() } = {}) {
|
|
|
197
205
|
}
|
|
198
206
|
}
|
|
199
207
|
|
|
208
|
+
if (type === 'pick') normalizePick(q, rq, where, files);
|
|
209
|
+
|
|
200
210
|
if (type === 'checklist') {
|
|
201
211
|
// Per-item status control. Default Pass / Fail / N/A; override with
|
|
202
212
|
// "statuses" (strings or {value,label,tone?}). tone colors the chip.
|
package/src/spec/pick.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// The `pick` question: media tiles the person chooses among. This file reads the
|
|
2
|
+
// tiles an agent wrote and cleans the answer a board sends back; drawing is
|
|
3
|
+
// src/ui/pick.js.
|
|
4
|
+
import { CliError } from '../util.js';
|
|
5
|
+
import { resolveImageSrc } from './blocks/image.js';
|
|
6
|
+
import { PICK } from './constants.js';
|
|
7
|
+
import { asStr, clampInt } from './sources.js';
|
|
8
|
+
|
|
9
|
+
const HTTP_URL = /^https?:\/\/\S+$/i;
|
|
10
|
+
const ID_MAX = 80;
|
|
11
|
+
|
|
12
|
+
function httpUrl(raw, where, field) {
|
|
13
|
+
const url = asStr(raw).trim();
|
|
14
|
+
if (!HTTP_URL.test(url)) throw new CliError(`${where}: "${field}" must be an http(s) URL${field === 'video' ? ' (a YouTube/Vimeo link or a media file URL; a local video file cannot be a tile)' : ''}.`);
|
|
15
|
+
return url;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function normalizeTile(raw, j, where, files) {
|
|
19
|
+
if (typeof raw === 'string' || typeof raw === 'number') return { id: String(raw), title: String(raw) };
|
|
20
|
+
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
21
|
+
throw new CliError(`${where}.items[${j}]: must be a string or {id, title, image?, video?, url?, caption?}.`);
|
|
22
|
+
}
|
|
23
|
+
const at = `${where}.items[${j}]`;
|
|
24
|
+
const id = asStr(raw.id ?? raw.value ?? raw.title ?? raw.label).trim();
|
|
25
|
+
if (!id) throw new CliError(`${at}: needs an "id" or a "title".`);
|
|
26
|
+
if (id.length > ID_MAX) throw new CliError(`${at}: id is longer than ${ID_MAX} characters.`);
|
|
27
|
+
const tile = { id, title: asStr(raw.title ?? raw.label).trim() || id };
|
|
28
|
+
const caption = asStr(raw.caption ?? raw.description).trim();
|
|
29
|
+
if (caption) tile.caption = caption;
|
|
30
|
+
const image = raw.image ?? raw.src ?? raw.img;
|
|
31
|
+
if (image !== undefined && image !== null && image !== '') tile.image = resolveImageSrc(image, files, at, '"image"');
|
|
32
|
+
if (raw.video !== undefined && raw.video !== null && raw.video !== '') tile.video = httpUrl(raw.video, at, 'video');
|
|
33
|
+
if (raw.url !== undefined && raw.url !== null && raw.url !== '') tile.url = httpUrl(raw.url, at, 'url');
|
|
34
|
+
return tile;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Adds the pick fields to a normalized question: `items`, `min`, `max`, `itemNote`, `overall`.
|
|
39
|
+
* The generic per-question note stays off: a pick carries its own notes.
|
|
40
|
+
* @param {Record<string, any>} q the question being built
|
|
41
|
+
* @param {Record<string, any>} rq what the agent wrote
|
|
42
|
+
*/
|
|
43
|
+
export function normalizePick(q, rq, where, files) {
|
|
44
|
+
const rawItems = Array.isArray(rq.items) ? rq.items : Array.isArray(rq.options) ? rq.options : Array.isArray(rq.choices) ? rq.choices : [];
|
|
45
|
+
if (!rawItems.length) throw new CliError(`${where}: type "pick" needs "items", the tiles to choose among: [{id, title, image?, video?, url?, caption?}].`);
|
|
46
|
+
if (rawItems.length > PICK.maxItems) throw new CliError(`${where}: a pick takes at most ${PICK.maxItems} items.`);
|
|
47
|
+
q.items = rawItems.map((raw, j) => normalizeTile(raw, j, where, files));
|
|
48
|
+
const seen = new Set();
|
|
49
|
+
for (const tile of q.items) {
|
|
50
|
+
if (seen.has(tile.id)) throw new CliError(`${where}: duplicate item id "${tile.id}".`);
|
|
51
|
+
seen.add(tile.id);
|
|
52
|
+
}
|
|
53
|
+
const imageBytes = q.items.reduce((sum, t) => sum + (t.image ? t.image.length : 0), 0);
|
|
54
|
+
if (imageBytes > PICK.maxImageBytes) throw new CliError(`${where}: the embedded images add up to ${(imageBytes / 1024 / 1024).toFixed(0)}MB; the limit is ${PICK.maxImageBytes / 1024 / 1024}MB. Use https image URLs or smaller files.`);
|
|
55
|
+
const count = q.items.length;
|
|
56
|
+
q.min = clampInt(rq.min, 0, count, rq.required === true ? 1 : 0);
|
|
57
|
+
q.max = clampInt(rq.max, Math.max(1, q.min), count, count);
|
|
58
|
+
if (q.min > 0) q.required = true;
|
|
59
|
+
q.itemNote = rq.itemNote !== false;
|
|
60
|
+
q.overall = rq.overall !== false;
|
|
61
|
+
q.note = false;
|
|
62
|
+
delete q.placeholder;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const asObject = (v) => (v && typeof v === 'object' && !Array.isArray(v) ? v : {});
|
|
66
|
+
const limit = (v, max) => (typeof v === 'string' ? v.trim().slice(0, max) : '');
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The answer to a pick question, cut down to what the question allows: known ids
|
|
70
|
+
* once each, at most `max` of them in the order picked, notes only when the tiles
|
|
71
|
+
* take them. Returns undefined when nothing is left, which reads as skipped.
|
|
72
|
+
* @returns {{ picks: Array<{ id: string, note?: string }>, overall?: string } | undefined}
|
|
73
|
+
*/
|
|
74
|
+
export function cleanPick(q, value) {
|
|
75
|
+
const raw = asObject(value);
|
|
76
|
+
const known = new Set((q.items || []).map((t) => t.id));
|
|
77
|
+
const seen = new Set();
|
|
78
|
+
const picks = [];
|
|
79
|
+
for (const entry of Array.isArray(raw.picks) ? raw.picks : []) {
|
|
80
|
+
const id = typeof entry === 'string' ? entry : asObject(entry).id;
|
|
81
|
+
if (typeof id !== 'string' || !known.has(id) || seen.has(id) || picks.length >= q.max) continue;
|
|
82
|
+
seen.add(id);
|
|
83
|
+
const note = q.itemNote === false || typeof entry === 'string' ? '' : limit(entry.note, PICK.maxNoteChars);
|
|
84
|
+
picks.push(note ? { id, note } : { id });
|
|
85
|
+
}
|
|
86
|
+
const overall = q.overall === false ? '' : limit(raw.overall, PICK.maxOverallChars);
|
|
87
|
+
if (!picks.length && !overall) return undefined;
|
|
88
|
+
return overall ? { picks, overall } : { picks };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* A copy of a board's answers in which every pick answer is cleaned. Other
|
|
93
|
+
* answers pass through as sent, which is how every board already treats them.
|
|
94
|
+
*/
|
|
95
|
+
export function cleanAnswers(spec, answers) {
|
|
96
|
+
const out = { ...answers };
|
|
97
|
+
for (const q of spec.questions) {
|
|
98
|
+
if (q.type !== 'pick' || !(q.id in out)) continue;
|
|
99
|
+
const cleaned = cleanPick(q, out[q.id]);
|
|
100
|
+
if (cleaned) out[q.id] = cleaned;
|
|
101
|
+
else delete out[q.id];
|
|
102
|
+
}
|
|
103
|
+
return out;
|
|
104
|
+
}
|
package/src/spec/schema.js
CHANGED
|
@@ -123,7 +123,7 @@ export const SPEC_SCHEMA = {
|
|
|
123
123
|
required: ['label'],
|
|
124
124
|
properties: {
|
|
125
125
|
id: { type: 'string', description: 'Answer key in the result JSON. Defaults to q1, q2, …' },
|
|
126
|
-
type: { type: 'string', enum: ['single', 'multi', 'yesno', 'text', 'textarea', 'scale', 'color', 'rank', 'checklist', 'allocate'], default: 'text' },
|
|
126
|
+
type: { type: 'string', enum: ['single', 'multi', 'yesno', 'text', 'textarea', 'scale', 'color', 'rank', 'checklist', 'allocate', 'pick'], default: 'text' },
|
|
127
127
|
label: { type: 'string' },
|
|
128
128
|
description: { type: 'string' },
|
|
129
129
|
required: { type: 'boolean', default: false },
|
|
@@ -145,12 +145,35 @@ export const SPEC_SCHEMA = {
|
|
|
145
145
|
],
|
|
146
146
|
},
|
|
147
147
|
},
|
|
148
|
+
items: {
|
|
149
|
+
type: 'array',
|
|
150
|
+
description: 'pick only: the tiles to choose among, 1 to 60. Strings, or {id, title, image?, video?, url?, caption?}. "image" is an https/data URL or a local file (embedded); "video" is an https YouTube/Vimeo link or media URL, shown as a link or a muted preview; "url" opens a page. The answer is {picks:[{id, note?}], overall?}: ids in the order picked, a note per tile, one overall note.',
|
|
151
|
+
items: {
|
|
152
|
+
anyOf: [
|
|
153
|
+
{ type: 'string' },
|
|
154
|
+
{
|
|
155
|
+
type: 'object',
|
|
156
|
+
required: ['id'],
|
|
157
|
+
properties: {
|
|
158
|
+
id: { type: 'string', description: 'Answer key for this tile (default: its title).' },
|
|
159
|
+
title: { type: 'string' },
|
|
160
|
+
caption: { type: 'string' },
|
|
161
|
+
image: { type: 'string', description: 'https/data URL, or a local image file (embedded).' },
|
|
162
|
+
video: { type: 'string', description: 'https YouTube/Vimeo link or media file URL.' },
|
|
163
|
+
url: { type: 'string', description: 'https page the tile links to.' },
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
itemNote: { type: 'boolean', default: true, description: 'pick only: a note field on each picked tile. Set false to hide it.' },
|
|
170
|
+
overall: { type: 'boolean', default: true, description: 'pick only: one overall note under the tiles. Set false to hide it.' },
|
|
148
171
|
other: { type: 'boolean', description: 'Add a free-text "Other" option (a multi-line textarea); its text is returned verbatim as the value. Defaults ON for "single" (radio) questions so the user is never boxed in — set other:false to remove it; "multi" stays opt-in (other:true).' },
|
|
149
172
|
note: { type: 'boolean', description: 'Small optional free-text field under the question (to qualify an answer). Returned separately as result.notes[questionId]. Defaults to true for the decision types — single, rank, checklist, allocate — so users can qualify their pick; false for other types. Set note:false to hide it, note:true to add it.' },
|
|
150
173
|
placeholder: { type: 'string', description: 'For text/textarea.' },
|
|
151
174
|
default: { description: 'Pre-selected value. Shape matches the answer shape for the type.' },
|
|
152
|
-
min: { type: 'integer', default: 1, description: 'scale
|
|
153
|
-
max: { type: 'integer', default: 5, maximum: 10, description: 'scale
|
|
175
|
+
min: { type: 'integer', default: 1, description: 'scale: lowest value. pick: fewest tiles to pick (default 0; 1 or more makes the question required).' },
|
|
176
|
+
max: { type: 'integer', default: 5, maximum: 10, description: 'scale: highest value, at most 10. pick: most tiles to pick (default: all of them; 1 makes it a single choice).' },
|
|
154
177
|
minLabel: { type: 'string', description: 'scale only' },
|
|
155
178
|
maxLabel: { type: 'string', description: 'scale only' },
|
|
156
179
|
presets: { type: 'array', items: { type: 'string' }, description: 'color only: optional small preset swatches (CSS colors) shown beside the native picker for one-click selection. The answer is returned as a color string.' },
|
package/src/spec/sources.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Readers for text that a block takes inline or from a file next to the spec.
|
|
2
2
|
import fs from 'node:fs';
|
|
3
|
-
import
|
|
3
|
+
import { resolveReadable } from '../file-access.js';
|
|
4
4
|
import { CliError } from '../util.js';
|
|
5
5
|
import { TEXT_FILE_MAX_BYTES } from './constants.js';
|
|
6
6
|
|
|
@@ -12,40 +12,35 @@ export function clampInt(v, min, max, def) {
|
|
|
12
12
|
return Math.min(max, Math.max(min, n));
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
/** Reads `htmlFile` through the file roots; an inline `html` string wins. */
|
|
16
|
+
export function readHtml(obj, files, where) {
|
|
16
17
|
if (typeof obj.html === 'string' && obj.html.trim()) return obj.html;
|
|
17
|
-
|
|
18
|
-
const p = path.resolve(cwd, obj.htmlFile);
|
|
19
|
-
try {
|
|
20
|
-
return fs.readFileSync(p, 'utf8');
|
|
21
|
-
} catch {
|
|
22
|
-
throw new CliError(`${where}: cannot read htmlFile "${obj.htmlFile}" (resolved: ${p})`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return '';
|
|
18
|
+
return readHtmlFile(obj, files, where);
|
|
26
19
|
}
|
|
27
20
|
|
|
28
21
|
// Reads an html-block body from either an inline string or a file path.
|
|
29
|
-
export function readBlockHtml(block,
|
|
22
|
+
export function readBlockHtml(block, files, where) {
|
|
30
23
|
if (typeof block.html === 'string' && block.html) return block.html;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
return readHtmlFile(block, files, where);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function readHtmlFile(obj, files, where) {
|
|
28
|
+
if (typeof obj.htmlFile !== 'string' || !obj.htmlFile.trim()) return '';
|
|
29
|
+
const { file } = resolveReadable(files, obj.htmlFile, where, 'htmlFile');
|
|
30
|
+
try {
|
|
31
|
+
return fs.readFileSync(file, 'utf8');
|
|
32
|
+
} catch {
|
|
33
|
+
throw new CliError(`${where}: cannot read htmlFile "${obj.htmlFile}" (resolved: ${file})`);
|
|
38
34
|
}
|
|
39
|
-
return '';
|
|
40
35
|
}
|
|
41
36
|
|
|
42
37
|
// Reads a code/diff block body from an inline string field or a local file.
|
|
43
38
|
// `inlineKey` is the inline field (e.g. "code"/"diff"); `fileKey` its file
|
|
44
39
|
// twin (e.g. "codeFile"/"diffFile"). Returns '' when neither is present.
|
|
45
|
-
export function readTextSource(block, inlineKey, fileKey,
|
|
40
|
+
export function readTextSource(block, inlineKey, fileKey, files, where) {
|
|
46
41
|
if (typeof block[inlineKey] === 'string' && block[inlineKey] !== '') return block[inlineKey];
|
|
47
42
|
if (typeof block[fileKey] === 'string' && block[fileKey].trim()) {
|
|
48
|
-
const p =
|
|
43
|
+
const { file: p } = resolveReadable(files, block[fileKey], where, fileKey);
|
|
49
44
|
let buf;
|
|
50
45
|
try {
|
|
51
46
|
buf = fs.readFileSync(p);
|
|
@@ -60,13 +55,13 @@ export function readTextSource(block, inlineKey, fileKey, cwd, where) {
|
|
|
60
55
|
return '';
|
|
61
56
|
}
|
|
62
57
|
|
|
63
|
-
export function readAnyTextSource(block, inlineKeys, fileKeys,
|
|
58
|
+
export function readAnyTextSource(block, inlineKeys, fileKeys, files, where, label) {
|
|
64
59
|
for (const key of inlineKeys) {
|
|
65
60
|
if (typeof block[key] === 'string' && block[key] !== '') return { text: block[key], sourceKey: key };
|
|
66
61
|
}
|
|
67
62
|
for (const key of fileKeys) {
|
|
68
63
|
if (typeof block[key] === 'string' && block[key].trim()) {
|
|
69
|
-
const p =
|
|
64
|
+
const { file: p } = resolveReadable(files, block[key], where, label);
|
|
70
65
|
let buf;
|
|
71
66
|
try {
|
|
72
67
|
buf = fs.readFileSync(p);
|