@khanglvm/relay 0.17.1 → 0.19.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 +10 -0
- package/docs/A2UI.md +221 -0
- package/docs/AGENT.md +34 -0
- package/package.json +39 -4
- package/schema/spec.v1.json +1368 -0
- package/skills/relay/SKILL.md +19 -0
- package/src/a2ui/catalog.json +630 -0
- package/src/a2ui/compile.js +257 -0
- package/src/a2ui/examples.json +217 -0
- package/src/a2ui/guide.md +50 -0
- package/src/a2ui/vendor/LICENSE +227 -0
- package/src/a2ui/vendor/VERSION +1 -0
- package/src/a2ui/vendor/a2ui-agent.mjs +193 -0
- package/src/a2ui/vendor/antlr4ng-LICENSE.txt +29 -0
- package/src/cli.js +68 -19
- package/src/index.js +104 -0
- package/src/link.js +121 -0
- package/src/mcp.js +5 -5
- package/src/server.js +73 -16
- package/src/spec.js +28 -2
- package/src/store.js +6 -0
- package/src/ui/a2ui-state.js +89 -0
- package/src/ui/a2ui.css +106 -0
- package/src/ui/a2ui.js +289 -0
- package/src/ui/blocks.js +4 -0
- package/types/a2ui/compile.d.ts +40 -0
- package/types/index.d.ts +181 -0
- package/types/mcp.d.ts +31 -0
- package/types/spec.d.ts +1191 -0
- package/types/store.d.ts +29 -0
- package/types/util.d.ts +6 -0
package/src/server.js
CHANGED
|
@@ -17,6 +17,8 @@ import {
|
|
|
17
17
|
} from './store.js';
|
|
18
18
|
import { openUrl } from './open.js';
|
|
19
19
|
import { assertSpecReady } from './spec.js';
|
|
20
|
+
import { assertSafeJson } from './a2ui/compile.js';
|
|
21
|
+
import { resolveLink } from './link.js';
|
|
20
22
|
import { splitFileReference, filePreview, mediaType } from './file-preview.js';
|
|
21
23
|
|
|
22
24
|
const UI_DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), 'ui');
|
|
@@ -154,9 +156,9 @@ function shareHost() {
|
|
|
154
156
|
function buildPage(record, rev, { access = null, draftRev = 0 } = {}) {
|
|
155
157
|
const html = fs.readFileSync(path.join(UI_DIR, 'index.html'), 'utf8');
|
|
156
158
|
const css = readUi('style.css');
|
|
157
|
-
const blocksCss = readUi('blocks.css');
|
|
159
|
+
const blocksCss = readUi('blocks.css') + '\n' + readUi('a2ui.css');
|
|
158
160
|
const annotateCss = readUi('annotate.css');
|
|
159
|
-
const blocksJs = readUi('blocks.js');
|
|
161
|
+
const blocksJs = readUi('a2ui-state.js') + '\n' + readUi('a2ui.js') + '\n' + readUi('blocks.js');
|
|
160
162
|
const annotateJs = readUi('annotate.js');
|
|
161
163
|
const appJs = readUi('app.js');
|
|
162
164
|
const spec = record.spec;
|
|
@@ -314,8 +316,7 @@ function sanitizeAnnotationTarget(value, boardId) {
|
|
|
314
316
|
if (clean.x + clean.w > 1) clean.w = 1 - clean.x;
|
|
315
317
|
if (clean.y + clean.h > 1) clean.h = 1 - clean.y;
|
|
316
318
|
clean.label = limitString(clean.label, 200);
|
|
317
|
-
if (clean.side
|
|
318
|
-
else delete clean.side;
|
|
319
|
+
if (clean.side !== 'before' && clean.side !== 'after') delete clean.side;
|
|
319
320
|
const crop = sanitizeAnnotationCrop(clean.crop, boardId);
|
|
320
321
|
if (crop) clean.crop = crop;
|
|
321
322
|
else delete clean.crop;
|
|
@@ -406,6 +407,29 @@ function sanitizeDiffReview(value) {
|
|
|
406
407
|
return Object.keys(out.hunks).length ? out : null;
|
|
407
408
|
}
|
|
408
409
|
|
|
410
|
+
// An a2ui block's state: the widget's data model (inputs the user changed) and
|
|
411
|
+
// the button events they fired, in order. Bounded like every other edit.
|
|
412
|
+
const A2UI_STATE_MAX_BYTES = 64 * 1024;
|
|
413
|
+
const A2UI_EVENTS_MAX = 50;
|
|
414
|
+
function sanitizeA2uiState(value) {
|
|
415
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || value.type !== 'a2ui') return null;
|
|
416
|
+
try {
|
|
417
|
+
assertSafeJson(value.data ?? {}, 'a2ui state');
|
|
418
|
+
const events = (Array.isArray(value.events) ? value.events : []).slice(-A2UI_EVENTS_MAX).flatMap((e) => {
|
|
419
|
+
if (!e || typeof e !== 'object' || typeof e.name !== 'string' || !/^[a-z][a-z0-9_-]{0,39}$/.test(e.name)) return [];
|
|
420
|
+
const context = e.context && typeof e.context === 'object' && !Array.isArray(e.context) ? e.context : {};
|
|
421
|
+
assertSafeJson(context, 'a2ui event');
|
|
422
|
+
if (JSON.stringify(context).length > 4096) return [];
|
|
423
|
+
return [{ name: e.name, context, at: limitString(e.at, 40) }];
|
|
424
|
+
});
|
|
425
|
+
const data = value.data && typeof value.data === 'object' && !Array.isArray(value.data) ? value.data : {};
|
|
426
|
+
if (JSON.stringify(data).length > A2UI_STATE_MAX_BYTES) return null;
|
|
427
|
+
return { type: 'a2ui', data, events };
|
|
428
|
+
} catch {
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
409
433
|
// Validates + sanitizes an incoming blockEdits map (from draft/submit).
|
|
410
434
|
// String values are editable Mermaid source. Structured git-conflict-resolution
|
|
411
435
|
// and diff-review values carry bounded per-hunk choices. Caps prevent a draft
|
|
@@ -422,7 +446,7 @@ function sanitizeBlockEdits(value) {
|
|
|
422
446
|
if (v.length > 20000) continue;
|
|
423
447
|
out[key] = v;
|
|
424
448
|
} else {
|
|
425
|
-
const edit = sanitizeConflictResolution(v) || sanitizeDiffReview(v);
|
|
449
|
+
const edit = sanitizeConflictResolution(v) || sanitizeDiffReview(v) || sanitizeA2uiState(v);
|
|
426
450
|
if (!edit) continue;
|
|
427
451
|
out[key] = edit;
|
|
428
452
|
}
|
|
@@ -544,15 +568,28 @@ function buildOpenAllowlist(spec, baseCwd) {
|
|
|
544
568
|
return set;
|
|
545
569
|
}
|
|
546
570
|
|
|
571
|
+
const PROXY_HEADERS = ['forwarded', 'x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto', 'x-real-ip'];
|
|
572
|
+
|
|
573
|
+
// Security: a local reverse proxy can send a loopback Host (the devlink gateway
|
|
574
|
+
// sends `Host: localhost:PORT`), so a request carrying proxy headers is never the
|
|
575
|
+
// tokenless owner. A proxy that adds none is covered by the control token runBoard
|
|
576
|
+
// requires for the owner while a link is set.
|
|
577
|
+
function isDirectLocalRequest(req) {
|
|
578
|
+
const host = String(req.headers.host || '').split(':')[0];
|
|
579
|
+
if (host !== '127.0.0.1' && host !== 'localhost') return false;
|
|
580
|
+
return !PROXY_HEADERS.some((name) => req.headers[name] !== undefined);
|
|
581
|
+
}
|
|
582
|
+
|
|
547
583
|
// True when an Origin header (if present) belongs to this board's own server.
|
|
548
584
|
// Same-origin fetches send no Origin or our own; a foreign Origin is a
|
|
549
585
|
// cross-site POST and must not be allowed to open a local file.
|
|
550
|
-
function sameOrigin(req, port, extraHosts = []) {
|
|
586
|
+
function sameOrigin(req, port, extraHosts = [], extraOrigins = []) {
|
|
551
587
|
if (req.headers['sec-fetch-site'] === 'cross-site') return false;
|
|
552
588
|
const origin = req.headers.origin;
|
|
553
589
|
if (!origin) return true;
|
|
554
590
|
try {
|
|
555
591
|
const u = new URL(origin);
|
|
592
|
+
if (extraOrigins.includes(u.origin)) return true;
|
|
556
593
|
if (u.port !== String(port)) return false;
|
|
557
594
|
return new Set(['127.0.0.1', 'localhost', ...extraHosts.filter(Boolean)]).has(u.hostname);
|
|
558
595
|
} catch {
|
|
@@ -746,7 +783,7 @@ function runOnResult(cmd, result, { quiet = false } = {}) {
|
|
|
746
783
|
// (submitted / acknowledged / timeout / cancelled). The result is also
|
|
747
784
|
// persisted into the board record so `rly wait` / `rly result` can read it
|
|
748
785
|
// from another process.
|
|
749
|
-
export async function runBoard({ id, port = 0, open = true, timeoutSec = 86400, quiet = false, keepAliveOnTimeout = false }) {
|
|
786
|
+
export async function runBoard({ id, port = 0, open = true, timeoutSec = 86400, quiet = false, keepAliveOnTimeout = false, link = { mode: 'off' } }) {
|
|
750
787
|
const record = loadBoard(id);
|
|
751
788
|
if (!record) throw new Error(`board ${id} not found`);
|
|
752
789
|
const spec = record.spec;
|
|
@@ -813,10 +850,11 @@ export async function runBoard({ id, port = 0, open = true, timeoutSec = 86400,
|
|
|
813
850
|
const presenceByRole = { owner: null, collab: null, review: null, read: null };
|
|
814
851
|
let actualPort = 0;
|
|
815
852
|
let url = '';
|
|
853
|
+
// The cross-device origin from a link setting (devlink or a URL template), once resolved.
|
|
854
|
+
let publicLink = null;
|
|
816
855
|
const advertisedHost = shareHost();
|
|
817
856
|
const accessFor = (req, reqUrl = null) => {
|
|
818
|
-
|
|
819
|
-
if (host === '127.0.0.1' || host === 'localhost') {
|
|
857
|
+
if (isDirectLocalRequest(req) && (!publicLink || req.headers['x-relay-token'] === token)) {
|
|
820
858
|
return {
|
|
821
859
|
role: 'owner',
|
|
822
860
|
canShare: true,
|
|
@@ -885,7 +923,10 @@ export async function runBoard({ id, port = 0, open = true, timeoutSec = 86400,
|
|
|
885
923
|
canFinalize: false,
|
|
886
924
|
};
|
|
887
925
|
};
|
|
888
|
-
const shareUrlFor = (role) =>
|
|
926
|
+
const shareUrlFor = (role) => {
|
|
927
|
+
const base = publicLink ? publicLink.origin : advertisedHost ? `http://${advertisedHost}:${actualPort}` : null;
|
|
928
|
+
return base ? `${base}/?share=${role}&token=${shareTokens[role]}` : null;
|
|
929
|
+
};
|
|
889
930
|
const persistShareState = () => {
|
|
890
931
|
record.share = {
|
|
891
932
|
version: SHARE_STATE_VERSION,
|
|
@@ -1017,7 +1058,7 @@ export async function runBoard({ id, port = 0, open = true, timeoutSec = 86400,
|
|
|
1017
1058
|
res.end(Buffer.from(m[2], 'base64'));
|
|
1018
1059
|
} else if (req.method === 'POST' && pathname === '/api/artifact') {
|
|
1019
1060
|
if (record.spec.responseRequired === false) return sendJson(res, 409, { error: 'display-only boards do not collect feedback' });
|
|
1020
|
-
if (!sameOrigin(req, actualPort, [advertisedHost])) return sendJson(res, 403, { error: 'cross-origin artifact upload rejected' });
|
|
1061
|
+
if (!sameOrigin(req, actualPort, [advertisedHost], [publicLink?.origin])) return sendJson(res, 403, { error: 'cross-origin artifact upload rejected' });
|
|
1021
1062
|
const access = accessFor(req, reqUrl);
|
|
1022
1063
|
if (!access.canComment) return sendJson(res, 403, { error: 'this share cannot add comments' });
|
|
1023
1064
|
const body = JSON.parse((await readBody(req, 6 * 1024 * 1024)) || '{}');
|
|
@@ -1076,7 +1117,7 @@ export async function runBoard({ id, port = 0, open = true, timeoutSec = 86400,
|
|
|
1076
1117
|
(['GET', 'HEAD'].includes(req.method) && pathname === '/api/file-content')) {
|
|
1077
1118
|
// Preview, stream, or open only a board-referenced local file. All three
|
|
1078
1119
|
// paths share the same origin, role, and reference allowlist checks.
|
|
1079
|
-
if (!sameOrigin(req, actualPort, [advertisedHost])) return sendJson(res, 403, { error: 'cross-origin requests cannot open files' });
|
|
1120
|
+
if (!sameOrigin(req, actualPort, [advertisedHost], [publicLink?.origin])) return sendJson(res, 403, { error: 'cross-origin requests cannot open files' });
|
|
1080
1121
|
const access = accessFor(req, reqUrl);
|
|
1081
1122
|
if (access.role !== 'owner' && access.role !== 'collab') return sendJson(res, 403, { error: 'this share cannot open local files' });
|
|
1082
1123
|
const body = req.method === 'POST' ? JSON.parse((await readBody(req)) || '{}') : { path: reqUrl.searchParams.get('path') };
|
|
@@ -1237,7 +1278,7 @@ export async function runBoard({ id, port = 0, open = true, timeoutSec = 86400,
|
|
|
1237
1278
|
// listening socket through a short close grace, so a stop-then-reopen on the
|
|
1238
1279
|
// same port can briefly hit EADDRINUSE — retry for ~2s to ride that out before
|
|
1239
1280
|
// giving up. Only then fall back to a random free port rather than failing.
|
|
1240
|
-
await new Promise((resolve, reject) => {
|
|
1281
|
+
await new Promise((/** @type {(value?: unknown) => void} */ resolve, reject) => {
|
|
1241
1282
|
const RETRY_MS = 200;
|
|
1242
1283
|
const MAX_RETRIES = 10; // ~2s — covers a prior server's ~600ms close grace
|
|
1243
1284
|
let retries = 0;
|
|
@@ -1261,8 +1302,21 @@ export async function runBoard({ id, port = 0, open = true, timeoutSec = 86400,
|
|
|
1261
1302
|
};
|
|
1262
1303
|
bind(port, true);
|
|
1263
1304
|
});
|
|
1264
|
-
actualPort = server.address().port;
|
|
1265
|
-
|
|
1305
|
+
actualPort = /** @type {import('node:net').AddressInfo} */ (server.address()).port;
|
|
1306
|
+
const localUrl = `http://127.0.0.1:${actualPort}/`;
|
|
1307
|
+
url = localUrl;
|
|
1308
|
+
try {
|
|
1309
|
+
publicLink = await resolveLink(link, actualPort);
|
|
1310
|
+
} catch (err) {
|
|
1311
|
+
server.close();
|
|
1312
|
+
throw err;
|
|
1313
|
+
}
|
|
1314
|
+
if (publicLink) {
|
|
1315
|
+
// Requests through the link are never the owner; the collaborator token in
|
|
1316
|
+
// the URL is what lets the owner's browsers answer and submit.
|
|
1317
|
+
activeShares.collab = true;
|
|
1318
|
+
url = shareUrlFor('collab');
|
|
1319
|
+
}
|
|
1266
1320
|
// Remember the port this board last bound, so `rly rescue <id>` can re-serve
|
|
1267
1321
|
// on the SAME port — letting a still-open (but disconnected) browser tab
|
|
1268
1322
|
// reconnect to its relative /api/* URLs without the user touching anything.
|
|
@@ -1275,6 +1329,8 @@ export async function runBoard({ id, port = 0, open = true, timeoutSec = 86400,
|
|
|
1275
1329
|
pid: process.pid,
|
|
1276
1330
|
port: actualPort,
|
|
1277
1331
|
url,
|
|
1332
|
+
localUrl,
|
|
1333
|
+
link: publicLink ? publicLink.kind : null,
|
|
1278
1334
|
title: spec.title,
|
|
1279
1335
|
token,
|
|
1280
1336
|
startedAt: new Date().toISOString(),
|
|
@@ -1336,6 +1392,7 @@ export async function runBoard({ id, port = 0, open = true, timeoutSec = 86400,
|
|
|
1336
1392
|
// and auto-closes first). The result is assumed already persisted.
|
|
1337
1393
|
function closeServer(result) {
|
|
1338
1394
|
removeRunning(record.id);
|
|
1395
|
+
if (publicLink) publicLink.release();
|
|
1339
1396
|
if (timer) clearTimeout(timer);
|
|
1340
1397
|
process.removeListener('SIGINT', onSignal);
|
|
1341
1398
|
process.removeListener('SIGTERM', onSignal);
|
|
@@ -1372,7 +1429,7 @@ export async function runBoard({ id, port = 0, open = true, timeoutSec = 86400,
|
|
|
1372
1429
|
runOnResult(record.onResult, result, { quiet });
|
|
1373
1430
|
}
|
|
1374
1431
|
|
|
1375
|
-
if (open) openUrl(url);
|
|
1432
|
+
if (open && !publicLink) openUrl(url);
|
|
1376
1433
|
if (!quiet) {
|
|
1377
1434
|
process.stderr.write(
|
|
1378
1435
|
`[relay] ${record.id} open: ${url} (waiting for submit; timeout: ${timeoutSec > 0 ? `${timeoutSec}s` : 'none'})\n`
|
package/src/spec.js
CHANGED
|
@@ -3,6 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import vm from 'node:vm';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
import { CliError } from './util.js';
|
|
6
|
+
import { assertSafeJson, guardExpress, resolveA2uiBlock, validateSurface } from './a2ui/compile.js';
|
|
6
7
|
|
|
7
8
|
export const TYPES = ['single', 'multi', 'yesno', 'text', 'textarea', 'scale', 'color', 'rank', 'checklist', 'allocate'];
|
|
8
9
|
|
|
@@ -41,7 +42,7 @@ const HTML_HEIGHT = { min: 100, max: 2400, boardDefault: 400, questionDefault: 3
|
|
|
41
42
|
|
|
42
43
|
// Block heights clamp to the same window; defaults vary per block type.
|
|
43
44
|
const BLOCK_HEIGHT = { min: 100, max: 2400 };
|
|
44
|
-
export const BLOCK_TYPES = ['markdown', 'mermaid', 'graphviz', 'plantuml', 'chart', 'table', 'code', 'diff', 'git-conflict', 'video', 'pdf', 'html', 'image', 'palette', 'kpi', 'typography', 'compare'];
|
|
45
|
+
export const BLOCK_TYPES = ['markdown', 'mermaid', 'graphviz', 'plantuml', 'chart', 'table', 'code', 'diff', 'git-conflict', 'video', 'pdf', 'html', 'image', 'palette', 'kpi', 'typography', 'compare', 'a2ui'];
|
|
45
46
|
const CHART_KINDS = ['bar', 'line', 'pie', 'doughnut', 'radar', 'scatter'];
|
|
46
47
|
|
|
47
48
|
// code/diff blocks may load their text from a local file (like htmlFile). Caps
|
|
@@ -412,6 +413,7 @@ export async function assertSpecReady(spec) {
|
|
|
412
413
|
if (spec.__relayReady === true) return spec;
|
|
413
414
|
for (const { block, where } of allBlocks(spec)) {
|
|
414
415
|
if (block && block.type === 'mermaid') await assertMermaidSyntax(block.code || '', where);
|
|
416
|
+
if (block && block.type === 'a2ui') await resolveA2uiBlock(block, `${where} (a2ui)`);
|
|
415
417
|
}
|
|
416
418
|
Object.defineProperty(spec, '__relayReady', { value: true, enumerable: false, configurable: true });
|
|
417
419
|
return spec;
|
|
@@ -761,6 +763,25 @@ function normalizeBlock(rawBlock, id, cwd, where) {
|
|
|
761
763
|
return block;
|
|
762
764
|
}
|
|
763
765
|
|
|
766
|
+
if (type === 'a2ui') {
|
|
767
|
+
// A live A2UI v1.0 widget: Express text (compiled in assertSpecReady) or
|
|
768
|
+
// ready JSON components, checked against Relay's catalog either way.
|
|
769
|
+
const hasExpress = rawBlock.express !== undefined && rawBlock.express !== null;
|
|
770
|
+
const hasComponents = rawBlock.components !== undefined && rawBlock.components !== null;
|
|
771
|
+
if (hasExpress === hasComponents) throw new CliError(`${where}: a2ui block needs exactly one of "express" (A2UI Express text) or "components" (JSON list).`);
|
|
772
|
+
const block = { id, type: 'a2ui' };
|
|
773
|
+
if (rawBlock.title !== undefined) block.title = asStr(rawBlock.title);
|
|
774
|
+
if (hasHeight) block.height = clampInt(rawBlock.height, BLOCK_HEIGHT.min, BLOCK_HEIGHT.max, undefined);
|
|
775
|
+
if (hasExpress) {
|
|
776
|
+
if (rawBlock.dataModel !== undefined) throw new CliError(`${where}: with "express", set data with \`$/path = value\` lines, not "dataModel".`);
|
|
777
|
+
block.express = guardExpress(rawBlock.express, where);
|
|
778
|
+
return block;
|
|
779
|
+
}
|
|
780
|
+
assertSafeJson(rawBlock.components, where);
|
|
781
|
+
const surface = validateSurface({ components: rawBlock.components, dataModel: rawBlock.dataModel }, where);
|
|
782
|
+
return Object.assign(block, surface);
|
|
783
|
+
}
|
|
784
|
+
|
|
764
785
|
if (type === 'palette') {
|
|
765
786
|
// Accept either { palettes: [{name, colors:[…]}, …] } or a single-palette
|
|
766
787
|
// shorthand { name?, colors:[…] }. Each palette needs a non-empty colors
|
|
@@ -1046,6 +1067,9 @@ const BLOCK_SCHEMA = {
|
|
|
1046
1067
|
review: { type: 'boolean', description: 'diff: when true, render per-hunk Apply / Skip / Hold controls and return choices in result.blockEdits[blockId] as {type:"diff-review", hunks:{...}}. Used by `rly git cherry-pick --code`.' },
|
|
1047
1068
|
reviewKind: { type: 'string', description: 'diff review: optional label for the review workflow, such as "cherry-pick" or "pick".' },
|
|
1048
1069
|
commit: { type: 'string', description: 'diff review: optional commit SHA associated with this diff.' },
|
|
1070
|
+
express: { type: 'string', description: 'a2ui: a live widget in A2UI Express, e.g. `$/jobs = [{title:"Build",tone:"ok"}]` then `root = Card("CI", [List($/jobs), Button("Retry", action=Event("retry"))])`. Compiled by the A2UI SDK against Relay\'s catalog (run `rly a2ui` for the grammar and every component). Button events, input values come back in result.blockEdits[blockId] as {type:"a2ui", data, events}.' },
|
|
1071
|
+
components: { type: 'array', description: 'a2ui: the same widget as flat A2UI v1.0 JSON components (root id "root", a Card) instead of "express".', items: { type: 'object' } },
|
|
1072
|
+
dataModel: { type: 'object', description: 'a2ui: the data model for "components" (use `$/path = value` lines with "express" instead).' },
|
|
1049
1073
|
content: { type: 'string', description: 'git-conflict: inline file content containing conflict markers (<<<<<<< / ======= / >>>>>>>). The board auto-detects each hunk and returns resolutions in result.blockEdits[blockId].' },
|
|
1050
1074
|
text: { type: 'string', description: 'git-conflict: alias for inline "content".' },
|
|
1051
1075
|
file: { type: 'string', description: 'git-conflict: local conflicted file path to load, parse, and resolve. Resolved against the CWD.' },
|
|
@@ -1121,6 +1145,8 @@ export const SPEC_SCHEMA = {
|
|
|
1121
1145
|
description:
|
|
1122
1146
|
'A relay board. Renders an optional intro, board-level blocks, then questions (each with optional per-question blocks), then a submit button. The result JSON contains "answers", "comment", per-question "notes", "annotations" (element-level comments the user attached to any block — see the annotation shape below), and "blockEdits" (a map blockId→edited source for any editable mermaid block the user changed, null when none).',
|
|
1123
1147
|
properties: {
|
|
1148
|
+
version: { const: 1, description: 'Spec version. Optional: a spec without it is read as version 1.' },
|
|
1149
|
+
$schema: { type: 'string', description: 'Optional URL of this schema, for editor completion. Relay ignores it.' },
|
|
1124
1150
|
title: { type: 'string', description: 'Board title (default "Relay")' },
|
|
1125
1151
|
intro: { type: 'string', description: 'Intro text shown under the title. Newlines preserved.' },
|
|
1126
1152
|
blocks: BLOCK_SCHEMA,
|
|
@@ -1191,7 +1217,7 @@ export const SPEC_SCHEMA = {
|
|
|
1191
1217
|
type: 'object',
|
|
1192
1218
|
readOnly: true,
|
|
1193
1219
|
description:
|
|
1194
|
-
'Returned in the result (not part of the input spec). A map blockId→edited block payload. Editable mermaid blocks return edited source strings. git-conflict blocks return {type:"git-conflict-resolution", resolutions, content, resolved, filename, file}. diff review blocks return {type:"diff-review", hunks, resolved, commit}. null when the user made no edits.',
|
|
1220
|
+
'Returned in the result (not part of the input spec). A map blockId→edited block payload. Editable mermaid blocks return edited source strings. git-conflict blocks return {type:"git-conflict-resolution", resolutions, content, resolved, filename, file}. diff review blocks return {type:"diff-review", hunks, resolved, commit}. a2ui blocks return {type:"a2ui", data (the widget data model with the user input values), events:[{name, context, at}] (each button click, in order)}. null when the user made no edits.',
|
|
1195
1221
|
},
|
|
1196
1222
|
},
|
|
1197
1223
|
anyOf: [{ required: ['questions'] }, { required: ['blocks'] }, { required: ['html'] }, { required: ['htmlFile'] }],
|
package/src/store.js
CHANGED
|
@@ -121,6 +121,12 @@ export function loadRunning(id) {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
// The URL this machine uses to talk to a running board. `url` may be a
|
|
125
|
+
// cross-device link (devlink, a proxy) that only people open.
|
|
126
|
+
export function controlUrl(running) {
|
|
127
|
+
return running.localUrl || running.url;
|
|
128
|
+
}
|
|
129
|
+
|
|
124
130
|
export function removeRunning(id) {
|
|
125
131
|
try {
|
|
126
132
|
fs.unlinkSync(runningPath(id));
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// a2ui-state.js — window.RelayA2uiState: the data model and event log behind one
|
|
2
|
+
// a2ui block. Pure data, no DOM, so it is testable on its own. a2ui.js draws it.
|
|
3
|
+
(() => {
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
const UNSAFE = new Set(['__proto__', 'constructor', 'prototype']);
|
|
7
|
+
const MAX_EVENTS = 50;
|
|
8
|
+
|
|
9
|
+
// '/a/b' -> ['a','b'], '' or '/' -> [], null when a segment could reach the prototype chain.
|
|
10
|
+
function segments(pointer) {
|
|
11
|
+
if (typeof pointer !== 'string' || (pointer && pointer[0] !== '/')) return null;
|
|
12
|
+
const parts = pointer.split('/').slice(1).filter((s) => s !== '');
|
|
13
|
+
return parts.some((s) => UNSAFE.has(s)) ? null : parts;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const isContainer = (v) => v !== null && typeof v === 'object';
|
|
17
|
+
|
|
18
|
+
function get(data, pointer) {
|
|
19
|
+
const parts = segments(pointer);
|
|
20
|
+
if (!parts) return undefined;
|
|
21
|
+
let cur = data;
|
|
22
|
+
for (const key of parts) {
|
|
23
|
+
if (!isContainer(cur) || !Object.hasOwn(cur, key)) return undefined;
|
|
24
|
+
cur = cur[key];
|
|
25
|
+
}
|
|
26
|
+
return cur;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Writes value at pointer, creating plain objects on the way. Returns false for an unsafe path.
|
|
30
|
+
function set(data, pointer, value) {
|
|
31
|
+
const parts = segments(pointer);
|
|
32
|
+
if (!parts || !parts.length) return false;
|
|
33
|
+
let cur = data;
|
|
34
|
+
for (const key of parts.slice(0, -1)) {
|
|
35
|
+
if (!isContainer(cur[key]) || !Object.hasOwn(cur, key)) cur[key] = {};
|
|
36
|
+
cur = cur[key];
|
|
37
|
+
}
|
|
38
|
+
cur[parts[parts.length - 1]] = value;
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const clone = (v) => (v === undefined ? undefined : JSON.parse(JSON.stringify(v)));
|
|
43
|
+
const isBinding = (v) => isContainer(v) && !Array.isArray(v) && typeof v['@path'] === 'string';
|
|
44
|
+
|
|
45
|
+
// A prop that is a literal or a {"@path": "/x"} binding, read against the current data.
|
|
46
|
+
function resolve(data, value) {
|
|
47
|
+
return isBinding(value) ? get(data, value['@path']) : value;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The state of one block. `restored` is the {data, events} the board saved
|
|
52
|
+
* before (a page reload); `onChange(snapshot)` runs after the user changes an
|
|
53
|
+
* input or fires an event, never for the first render.
|
|
54
|
+
*/
|
|
55
|
+
function createStore(initialData, restored, onChange) {
|
|
56
|
+
const data = clone(restored && restored.data && typeof restored.data === 'object' ? restored.data : initialData) || {};
|
|
57
|
+
const events = restored && Array.isArray(restored.events) ? restored.events.slice(-MAX_EVENTS) : [];
|
|
58
|
+
const listeners = [];
|
|
59
|
+
const snapshot = () => ({ type: 'a2ui', data: clone(data), events: clone(events) });
|
|
60
|
+
const touch = () => {
|
|
61
|
+
listeners.forEach((fn) => fn());
|
|
62
|
+
if (onChange) onChange(snapshot());
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
data,
|
|
66
|
+
get: (pointer) => get(data, pointer),
|
|
67
|
+
resolve: (value) => resolve(data, value),
|
|
68
|
+
subscribe: (fn) => listeners.push(fn),
|
|
69
|
+
set(pointer, value) {
|
|
70
|
+
if (set(data, pointer, value)) touch();
|
|
71
|
+
},
|
|
72
|
+
// An Event(name, {context}) action: context bindings are read now, so the agent sees the values at click time.
|
|
73
|
+
fire(name, context) {
|
|
74
|
+
const resolved = {};
|
|
75
|
+
for (const [key, value] of Object.entries(context || {})) {
|
|
76
|
+
if (!UNSAFE.has(key)) resolved[key] = clone(resolve(data, value));
|
|
77
|
+
}
|
|
78
|
+
events.push({ name, context: resolved, at: new Date().toISOString() });
|
|
79
|
+
if (events.length > MAX_EVENTS) events.shift();
|
|
80
|
+
touch();
|
|
81
|
+
},
|
|
82
|
+
eventCount: () => events.length,
|
|
83
|
+
snapshot,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const api = { get, set, clone, resolve, isBinding, createStore };
|
|
88
|
+
(typeof window !== 'undefined' ? window : globalThis).RelayA2uiState = api;
|
|
89
|
+
})();
|
package/src/ui/a2ui.css
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/* a2ui.css — the `a2ui` block: A2UI components drawn in the board's own theme. */
|
|
2
|
+
.a2 {
|
|
3
|
+
--a2-ok: var(--ok);
|
|
4
|
+
--a2-info: #4a6c98;
|
|
5
|
+
--a2-warn: #946a1c;
|
|
6
|
+
--a2-error: var(--danger);
|
|
7
|
+
--a2-needs: var(--accent);
|
|
8
|
+
}
|
|
9
|
+
[data-theme="dark"] .a2 { --a2-info: #88b4e8; --a2-warn: #e3c46a; }
|
|
10
|
+
@media (prefers-color-scheme: dark) {
|
|
11
|
+
:root:not([data-theme="light"]) .a2 { --a2-info: #88b4e8; --a2-warn: #e3c46a; }
|
|
12
|
+
}
|
|
13
|
+
.a2-tone-ok { --a2-tone: var(--a2-ok); }
|
|
14
|
+
.a2-tone-info { --a2-tone: var(--a2-info); }
|
|
15
|
+
.a2-tone-warn { --a2-tone: var(--a2-warn); }
|
|
16
|
+
.a2-tone-error { --a2-tone: var(--a2-error); }
|
|
17
|
+
.a2-tone-needs { --a2-tone: var(--a2-needs); }
|
|
18
|
+
|
|
19
|
+
.blk-a2ui { margin: 4px 0; }
|
|
20
|
+
.a2-card {
|
|
21
|
+
display: flex; flex-direction: column; gap: 12px; padding: 16px;
|
|
22
|
+
background: var(--card); border-radius: 14px; box-shadow: var(--shadow-card);
|
|
23
|
+
}
|
|
24
|
+
.a2-card-title { font-weight: 650; font-size: 1.05rem; }
|
|
25
|
+
.a2-stack { display: flex; min-width: 0; }
|
|
26
|
+
.a2-col { flex-direction: column; }
|
|
27
|
+
.a2-row { flex-direction: row; flex-wrap: wrap; align-items: center; }
|
|
28
|
+
.a2-grid { display: grid; min-width: 0; }
|
|
29
|
+
.a2-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
30
|
+
.a2-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
|
31
|
+
.a2-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
|
|
32
|
+
@media (max-width: 480px) {
|
|
33
|
+
.a2-cols-3, .a2-cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
34
|
+
}
|
|
35
|
+
.a2-muted { color: var(--muted); font-size: 0.82rem; }
|
|
36
|
+
.a2-text-body { line-height: 1.5; overflow-wrap: anywhere; }
|
|
37
|
+
.a2-text-title { font-weight: 600; }
|
|
38
|
+
.a2-text-muted { color: var(--muted); font-size: 0.88rem; }
|
|
39
|
+
|
|
40
|
+
.a2-pill {
|
|
41
|
+
display: inline-block; max-width: 100%; padding: 2px 10px; border-radius: 999px;
|
|
42
|
+
font-size: 0.8rem; font-weight: 600; line-height: 1.5; white-space: nowrap;
|
|
43
|
+
color: var(--a2-tone, var(--fg-2)); background: color-mix(in srgb, var(--a2-tone, var(--fg-2)) 14%, transparent);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.a2-metric { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 10px; background: var(--bg-sunken); min-width: 0; }
|
|
47
|
+
.a2-metric-label { color: var(--muted); font-size: 0.82rem; }
|
|
48
|
+
.a2-metric-value { font-family: var(--serif); font-size: 1.6rem; line-height: 1.1; letter-spacing: -0.02em; overflow-wrap: anywhere; }
|
|
49
|
+
|
|
50
|
+
.a2-list { display: flex; flex-direction: column; }
|
|
51
|
+
.a2-item {
|
|
52
|
+
display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 12px;
|
|
53
|
+
padding: 10px 0; border-top: 1px solid var(--border); min-height: 44px;
|
|
54
|
+
}
|
|
55
|
+
.a2-item:first-child { border-top: 0; }
|
|
56
|
+
.a2-row-main { min-width: 0; flex: 1; }
|
|
57
|
+
.a2-row-title { font-weight: 550; overflow-wrap: anywhere; color: var(--fg); text-decoration: none; }
|
|
58
|
+
a.a2-row-title { text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px; }
|
|
59
|
+
.a2-row-sub { color: var(--muted); font-size: 0.84rem; overflow-wrap: anywhere; }
|
|
60
|
+
.a2-row-trail { color: var(--fg-2); font-size: 0.88rem; white-space: nowrap; }
|
|
61
|
+
.a2-row-more { color: var(--muted); font-size: 0.84rem; padding-top: 8px; }
|
|
62
|
+
|
|
63
|
+
.a2-progress { display: flex; flex-direction: column; gap: 6px; }
|
|
64
|
+
.a2-progress-head { display: flex; justify-content: space-between; gap: 12px; font-weight: 550; }
|
|
65
|
+
.a2-bar { height: 8px; border-radius: 999px; background: var(--bg-sunken); overflow: hidden; }
|
|
66
|
+
.a2-bar-fill { height: 100%; border-radius: 999px; background: var(--a2-tone, var(--accent)); transition: width 0.25s var(--ease); }
|
|
67
|
+
|
|
68
|
+
.a2-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
|
|
69
|
+
.a2-table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
|
|
70
|
+
.a2-table th, .a2-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
|
|
71
|
+
.a2-table th { color: var(--muted); font-weight: 600; font-size: 0.8rem; }
|
|
72
|
+
|
|
73
|
+
.a2-code { margin: 0; padding: 12px; border-radius: 10px; background: var(--bg-sunken); overflow-x: auto; font-size: 0.85rem; line-height: 1.5; }
|
|
74
|
+
.a2-image { max-width: 100%; height: auto; border-radius: 10px; }
|
|
75
|
+
.a2-divider { border: 0; border-top: 1px solid var(--border); margin: 0; width: 100%; }
|
|
76
|
+
.a2-icon { width: 18px; height: 18px; flex: none; color: var(--a2-tone, currentColor); }
|
|
77
|
+
|
|
78
|
+
.a2-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
|
|
79
|
+
.a2-field-inline { flex-direction: row; align-items: center; min-height: 44px; }
|
|
80
|
+
.a2-field-inline .a2-field-label { order: 2; }
|
|
81
|
+
.a2-field-label { font-size: 0.85rem; color: var(--fg-2); }
|
|
82
|
+
/* 16px keeps iOS Safari from zooming the page when an input takes focus. */
|
|
83
|
+
.a2-input {
|
|
84
|
+
font: inherit; font-size: 16px; color: var(--fg); background: var(--bg-sunken);
|
|
85
|
+
border: 1px solid var(--border-strong); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%;
|
|
86
|
+
}
|
|
87
|
+
.a2-input:focus-visible, .a2-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
88
|
+
.a2-check { width: 22px; height: 22px; accent-color: var(--accent); }
|
|
89
|
+
.a2-range { width: 100%; min-height: 44px; accent-color: var(--accent); }
|
|
90
|
+
|
|
91
|
+
.a2-btn {
|
|
92
|
+
display: inline-flex; align-items: center; gap: 6px; justify-content: center;
|
|
93
|
+
font: inherit; font-size: 0.95rem; font-weight: 600; color: var(--fg); background: var(--bg-sunken);
|
|
94
|
+
border: 1px solid var(--border-strong); border-radius: 10px; padding: 10px 16px; min-height: 44px; cursor: pointer;
|
|
95
|
+
transition: background 0.15s var(--ease), transform 0.1s var(--ease);
|
|
96
|
+
}
|
|
97
|
+
.a2-btn:active { transform: scale(0.97); }
|
|
98
|
+
.a2-btn-primary { color: var(--accent-fg); background: var(--accent); border-color: transparent; }
|
|
99
|
+
.a2-btn-primary:hover { background: var(--accent-hover); }
|
|
100
|
+
.a2-btn-sent { box-shadow: 0 0 0 2px var(--a2-ok); }
|
|
101
|
+
.a2-btn:disabled, .a2-input:disabled { opacity: 0.55; cursor: not-allowed; }
|
|
102
|
+
.a2-status:empty { display: none; }
|
|
103
|
+
.a2-status { margin-top: 6px; }
|
|
104
|
+
@media (prefers-reduced-motion: reduce) {
|
|
105
|
+
.a2-btn, .a2-bar-fill { transition: none; }
|
|
106
|
+
}
|