@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.
Files changed (89) hide show
  1. package/docs/AGENT.md +14 -2
  2. package/package.json +6 -1
  3. package/schema/spec.v1.json +55 -3
  4. package/skills/relay/SKILL.md +2 -1
  5. package/src/a2ui/board-catalog.json +1004 -0
  6. package/src/a2ui/board-constants.js +35 -0
  7. package/src/a2ui/board.js +5 -0
  8. package/src/a2ui/from-a2ui.js +71 -0
  9. package/src/a2ui/negotiate.js +38 -0
  10. package/src/a2ui/to-a2ui.js +147 -0
  11. package/src/cli/args.js +4 -2
  12. package/src/cli/ask.js +4 -3
  13. package/src/cli/boards.js +10 -7
  14. package/src/cli/git.js +5 -3
  15. package/src/cli/help.js +3 -1
  16. package/src/cli/io.js +21 -0
  17. package/src/cli/mcp.js +31 -2
  18. package/src/file-access.js +117 -0
  19. package/src/file-preview.js +1 -1
  20. package/src/mcp/boards.js +30 -7
  21. package/src/mcp/constants.js +3 -1
  22. package/src/mcp/schemas.js +5 -2
  23. package/src/mcp/serve.js +4 -4
  24. package/src/mcp/server.js +2 -1
  25. package/src/mcp/store.js +2 -2
  26. package/src/mcp/token.js +33 -8
  27. package/src/mcp/tools.js +16 -7
  28. package/src/mcp-ui/board/normalize.js +12 -0
  29. package/src/mcp-ui/board/render.js +2 -1
  30. package/src/mcp-ui/board/state.js +3 -0
  31. package/src/server/board.js +30 -22
  32. package/src/server/files.js +10 -0
  33. package/src/server/http.js +19 -0
  34. package/src/server/page.js +4 -0
  35. package/src/spec/blocks/a2ui.js +1 -1
  36. package/src/spec/blocks/chart.js +1 -1
  37. package/src/spec/blocks/code.js +4 -4
  38. package/src/spec/blocks/diagram.js +3 -3
  39. package/src/spec/blocks/git-conflict.js +2 -2
  40. package/src/spec/blocks/image.js +6 -5
  41. package/src/spec/blocks/markdown.js +2 -2
  42. package/src/spec/blocks/pdf.js +4 -10
  43. package/src/spec/blocks/table.js +5 -4
  44. package/src/spec/blocks/video.js +4 -10
  45. package/src/spec/blocks/widgets.js +6 -6
  46. package/src/spec/constants.js +13 -1
  47. package/src/spec/index.js +1 -0
  48. package/src/spec/lookup.js +1 -0
  49. package/src/spec/normalize.js +20 -10
  50. package/src/spec/pick.js +104 -0
  51. package/src/spec/schema.js +26 -3
  52. package/src/spec/sources.js +19 -24
  53. package/src/store.js +6 -1
  54. package/src/ui/app/drafts.js +3 -0
  55. package/src/ui/app/render.js +1 -0
  56. package/src/ui/app/submit.js +1 -1
  57. package/src/ui/manifest.js +2 -1
  58. package/src/ui/pick.css +32 -0
  59. package/src/ui/pick.js +246 -0
  60. package/types/a2ui/board-constants.d.ts +24 -0
  61. package/types/a2ui/from-a2ui.d.ts +16 -0
  62. package/types/a2ui/negotiate.d.ts +17 -0
  63. package/types/a2ui/to-a2ui.d.ts +12 -0
  64. package/types/file-access.d.ts +62 -0
  65. package/types/mcp/boards.d.ts +13 -2
  66. package/types/mcp/schemas.d.ts +5 -2
  67. package/types/mcp/serve.d.ts +5 -2
  68. package/types/mcp/store.d.ts +6 -3
  69. package/types/mcp/token.d.ts +5 -1
  70. package/types/mcp/tools.d.ts +2 -0
  71. package/types/spec/blocks/a2ui.d.ts +1 -1
  72. package/types/spec/blocks/chart.d.ts +1 -1
  73. package/types/spec/blocks/code.d.ts +2 -2
  74. package/types/spec/blocks/diagram.d.ts +3 -3
  75. package/types/spec/blocks/git-conflict.d.ts +1 -1
  76. package/types/spec/blocks/image.d.ts +2 -2
  77. package/types/spec/blocks/markdown.d.ts +1 -1
  78. package/types/spec/blocks/pdf.d.ts +1 -1
  79. package/types/spec/blocks/table.d.ts +1 -1
  80. package/types/spec/blocks/video.d.ts +1 -1
  81. package/types/spec/blocks/widgets.d.ts +4 -4
  82. package/types/spec/constants.d.ts +9 -0
  83. package/types/spec/index.d.ts +1 -0
  84. package/types/spec/lookup.d.ts +2 -1
  85. package/types/spec/normalize.d.ts +7 -1
  86. package/types/spec/pick.d.ts +25 -0
  87. package/types/spec/schema.d.ts +48 -0
  88. package/types/spec/sources.d.ts +5 -4
  89. package/types/store.d.ts +8 -1
package/src/store.js CHANGED
@@ -36,7 +36,11 @@ export function saveBoardArtifact(id, bytes, ext = 'png') {
36
36
  return target;
37
37
  }
38
38
 
39
- export function createBoard(spec) {
39
+ /**
40
+ * @param {any} spec a normalized spec
41
+ * @param {{ fileRoots?: string[] }} [options] the roots the spec was read under; the live server opens only files inside them
42
+ */
43
+ export function createBoard(spec, { fileRoots } = {}) {
40
44
  ensureDirs();
41
45
  const record = {
42
46
  id: newId(),
@@ -46,6 +50,7 @@ export function createBoard(spec) {
46
50
  // writes into the spec (markdown links, ~/… paths) resolve against this, so
47
51
  // the live server can open them in the user's default app (POST /api/open).
48
52
  cwd: process.cwd(),
53
+ fileRoots: fileRoots ?? [process.cwd()],
49
54
  spec,
50
55
  draft: null,
51
56
  result: null,
@@ -135,6 +135,7 @@
135
135
  for (const q of QS) if (q.type === 'rank') state.answers[q.id] = seedRankOrder(q, state.answers[q.id]);
136
136
  for (const q of QS) if (q.type === 'allocate') state.answers[q.id] = seedAllocate(q, state.answers[q.id]);
137
137
  for (const q of QS) if (q.type === 'checklist') state.answers[q.id] = seedChecklist(q, state.answers[q.id]);
138
+ for (const q of QS) if (q.type === 'pick') state.answers[q.id] = window.RelayPick.seed(q, state.answers[q.id]);
138
139
  // If the local mirror was newer than the server (or the server had nothing),
139
140
  // the in-memory state now holds input the server hasn't seen — flush it once
140
141
  // the rest of the app is wired (see the post-init flush near the heartbeat).
@@ -174,6 +175,8 @@
174
175
  const sum = Object.values(m).reduce((a, n) => a + (Number(n) || 0), 0);
175
176
  return sum > 0 ? { ...m } : undefined;
176
177
  }
178
+ case 'pick':
179
+ return window.RelayPick.value(q, v);
177
180
  default: {
178
181
  const t = typeof v === 'string' ? v.trim() : '';
179
182
  return t || undefined;
@@ -89,6 +89,7 @@
89
89
  else if (q.type === 'rank') control.append(controlRank(q));
90
90
  else if (q.type === 'checklist') control.append(controlChecklist(q));
91
91
  else if (q.type === 'allocate') control.append(controlAllocate(q));
92
+ else if (q.type === 'pick') control.append(window.RelayPick.control(q, state, { canEdit: access.canEditAnswers, onChange: () => { clearErr(q.id); scheduleSave(); } }));
92
93
  else control.append(controlText(q, q.type === 'textarea'));
93
94
  card.append(control);
94
95
  if (q.note) {
@@ -3,7 +3,7 @@
3
3
  let firstBad = null;
4
4
  for (const q of QS) {
5
5
  const required = q.required || !spec.allowPartial;
6
- const bad = required && getValue(q) === undefined;
6
+ const bad = required && (getValue(q) === undefined || (q.type === 'pick' && window.RelayPick.short(q, state.answers[q.id])));
7
7
  cards[q.id].classList.toggle('error', bad);
8
8
  if (bad && !firstBad) firstBad = cards[q.id];
9
9
  }
@@ -25,12 +25,13 @@ const plain = (file) => ({ open: '', files: [file], close: '' });
25
25
  const iife = (open, files) => ({ open, files, close: IIFE_CLOSE });
26
26
 
27
27
  export const STYLE_PARTS = [plain('ui/style.css')];
28
- export const BLOCKS_STYLE_PARTS = [plain('ui/blocks.css'), plain('ui/a2ui.css')];
28
+ export const BLOCKS_STYLE_PARTS = [plain('ui/blocks.css'), plain('ui/a2ui.css'), plain('ui/pick.css')];
29
29
  export const ANNOTATE_STYLE_PARTS = [plain('ui/annotate.css')];
30
30
 
31
31
  export const BLOCKS_SCRIPT_PARTS = [
32
32
  plain('ui/a2ui-state.js'),
33
33
  plain('ui/a2ui.js'),
34
+ plain('ui/pick.js'),
34
35
  iife(BLOCKS_OPEN, [
35
36
  'ui/blocks/core.js',
36
37
  'ui/blocks/markdown.js',
@@ -0,0 +1,32 @@
1
+ /* pick question: a grid of media tiles. Used by the web board and the MCP App page. */
2
+ .pk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); gap: 12px; }
3
+ .pk-tile { display: flex; flex-direction: column; gap: 6px; min-width: 0; padding: 8px; border: 1px solid var(--border, #ece9e4); border-radius: 12px; background: var(--card, #fff); transition: border-color 0.15s var(--ease, ease), background 0.15s var(--ease, ease); }
4
+ .pk-tile:hover { border-color: var(--accent, #c2674b); }
5
+ .pk-tile.sel { border-color: var(--accent, #c2674b); background: var(--accent-soft, #f5e9e3); }
6
+ .pk-pick { display: flex; flex-direction: column; gap: 6px; width: 100%; padding: 0; border: 0; border-radius: 8px; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
7
+ .pk-pick:disabled { cursor: default; }
8
+ .pk-pick:focus-visible, .pk-open:focus-visible { outline: 2px solid var(--accent, #c2674b); outline-offset: 2px; }
9
+ .pk-pick[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
10
+ .pk-media { position: relative; display: flex; align-items: center; justify-content: center; aspect-ratio: 4 / 3; overflow: hidden; border-radius: 8px; background: var(--bg-sunken, #f6f4f0); color: var(--muted, #8a8580); }
11
+ .pk-img { width: 100%; height: 100%; object-fit: cover; }
12
+ .pk-nomedia .pk-icon { width: 28px; height: 28px; }
13
+ .pk-badge { position: absolute; right: 8px; bottom: 8px; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: rgba(28, 27, 25, 0.62); color: #fff; }
14
+ .pk-badge .pk-icon { width: 14px; height: 14px; }
15
+ .pk-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
16
+ .pk-title { min-width: 0; font-weight: 500; overflow-wrap: anywhere; }
17
+ .pk-caption { color: var(--muted, #8a8580); font-size: 0.85rem; overflow-wrap: anywhere; }
18
+ .pk-check { position: relative; flex: none; display: grid; place-items: center; width: 22px; height: 22px; border: 1.5px solid var(--border-strong, #e0dcd5); border-radius: 50%; color: transparent; }
19
+ .pk-tile.sel .pk-check { border-color: var(--accent, #c2674b); background: var(--accent, #c2674b); color: var(--accent-fg, #fcfaf7); }
20
+ .pk-check .pk-icon { width: 13px; height: 13px; }
21
+ .pk-order { position: absolute; top: -8px; right: -8px; min-width: 16px; padding: 0 4px; border-radius: 8px; background: var(--fg, #1c1b19); color: var(--bg, #fcfbf9); font-size: 0.7rem; line-height: 16px; text-align: center; }
22
+ .pk-order:empty { display: none; }
23
+ .pk-open { display: inline-flex; align-items: center; gap: 4px; align-self: flex-start; color: var(--fg-2, #57534e); font-size: 0.82rem; text-decoration: none; }
24
+ .pk-open:hover { color: var(--accent, #c2674b); text-decoration: underline; }
25
+ .pk-open .pk-icon { width: 13px; height: 13px; }
26
+ .pk-notewrap[hidden] { display: none; }
27
+ .pk-note, .pk-overall { width: 100%; box-sizing: border-box; font-size: 0.88rem; resize: vertical; }
28
+ .pk-note { padding: 8px 10px; min-height: 52px; }
29
+ .pk-overall { margin-top: 10px; padding: 8px 12px; min-height: 64px; }
30
+ .pk-status { margin: 10px 0 0; color: var(--muted, #8a8580); font-size: 0.85rem; }
31
+ @media (max-width: 480px) { .pk-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; } }
32
+ @media (prefers-reduced-motion: reduce) { .pk-tile { transition: none; } }
package/src/ui/pick.js ADDED
@@ -0,0 +1,246 @@
1
+ // pick.js — window.RelayPick: the `pick` question for both pages (web board and MCP App).
2
+ // A grid of media tiles; a tile is one button (Tab to reach it, Space or Enter to pick),
3
+ // with an optional note under each picked tile and one overall note under the grid.
4
+ // The answer is {picks:[{id, note?}], overall?}, ids in the order picked. Every string is
5
+ // set through textContent and every link is http(s) only, so agent text never becomes markup.
6
+ (() => {
7
+ 'use strict';
8
+
9
+ const SVG_NS = 'http://www.w3.org/2000/svg';
10
+ const HTTP = /^https?:\/\//i;
11
+ const MEDIA_FILE = /\.(mp4|webm|mov|m4v|ogv)(\?|#|$)/i;
12
+ const NOTE_MAX = 2000;
13
+ const OVERALL_MAX = 5000;
14
+ const PATHS = {
15
+ check: 'M20 6 9 17l-5-5',
16
+ external: 'M15 3h6v6M10 14 21 3M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6',
17
+ play: 'm6 3 14 9-14 9z',
18
+ link: 'M10 13a5 5 0 0 0 7.5.5l3-3a5 5 0 0 0-7-7l-1.7 1.7M14 11a5 5 0 0 0-7.5-.5l-3 3a5 5 0 0 0 7 7l1.7-1.7',
19
+ };
20
+
21
+ function h(tag, cls, text) {
22
+ const n = document.createElement(tag);
23
+ if (cls) n.className = cls;
24
+ if (text !== undefined && text !== null) n.textContent = String(text);
25
+ return n;
26
+ }
27
+
28
+ function icon(name) {
29
+ const svg = document.createElementNS(SVG_NS, 'svg');
30
+ svg.setAttribute('viewBox', '0 0 24 24');
31
+ svg.setAttribute('class', 'pk-icon');
32
+ svg.setAttribute('aria-hidden', 'true');
33
+ svg.setAttribute('fill', 'none');
34
+ svg.setAttribute('stroke', 'currentColor');
35
+ svg.setAttribute('stroke-width', '2');
36
+ svg.setAttribute('stroke-linecap', 'round');
37
+ svg.setAttribute('stroke-linejoin', 'round');
38
+ const path = document.createElementNS(SVG_NS, 'path');
39
+ path.setAttribute('d', PATHS[name]);
40
+ svg.append(path);
41
+ return svg;
42
+ }
43
+
44
+ const asObject = (v) => (v && typeof v === 'object' && !Array.isArray(v) ? v : {});
45
+ const clip = (v, max) => (typeof v === 'string' ? v.trim().slice(0, max) : '');
46
+ const limitOf = (q) => (Number.isInteger(q.max) && q.max > 0 ? q.max : (q.items || []).length);
47
+
48
+ /** Cuts a stored or default answer down to what the question allows. */
49
+ function seed(q, prior) {
50
+ const raw = asObject(prior);
51
+ const known = new Set((q.items || []).map((t) => t.id));
52
+ const seen = new Set();
53
+ const picks = [];
54
+ for (const entry of Array.isArray(raw.picks) ? raw.picks : []) {
55
+ const id = typeof entry === 'string' ? entry : asObject(entry).id;
56
+ if (typeof id !== 'string' || !known.has(id) || seen.has(id) || picks.length >= limitOf(q)) continue;
57
+ seen.add(id);
58
+ picks.push({ id, note: typeof entry === 'string' || q.itemNote === false ? '' : clip(entry.note, NOTE_MAX) });
59
+ }
60
+ return { picks, overall: q.overall === false ? '' : clip(raw.overall, OVERALL_MAX) };
61
+ }
62
+
63
+ /** The answer to submit, or undefined while the question counts as unanswered. */
64
+ function value(q, stored) {
65
+ const s = seed(q, stored);
66
+ if (!s.picks.length && !s.overall) return undefined;
67
+ const out = { picks: s.picks.map((p) => (p.note ? { id: p.id, note: p.note } : { id: p.id })) };
68
+ if (s.overall) out.overall = s.overall;
69
+ return out;
70
+ }
71
+
72
+ /** True while fewer tiles are picked than the question asks for. */
73
+ function short(q, stored) {
74
+ return seed(q, stored).picks.length < (q.min || 0);
75
+ }
76
+
77
+ const safeUrl = (u) => (typeof u === 'string' && HTTP.test(u) ? u : '');
78
+
79
+ function mediaOf(q, tile) {
80
+ const wrap = h('span', 'pk-media');
81
+ const src = tile.image || (tile.hasImage ? `/img/p/${encodeURIComponent(q.id)}/${encodeURIComponent(tile.id)}` : '');
82
+ if (src) {
83
+ const img = h('img', 'pk-img');
84
+ img.loading = 'lazy';
85
+ img.decoding = 'async';
86
+ img.alt = '';
87
+ img.src = src;
88
+ wrap.append(img);
89
+ } else if (tile.video && MEDIA_FILE.test(tile.video)) {
90
+ const vid = h('video', 'pk-img');
91
+ vid.muted = true;
92
+ vid.loop = true;
93
+ vid.playsInline = true;
94
+ vid.preload = 'metadata';
95
+ vid.src = safeUrl(tile.video);
96
+ vid.setAttribute('aria-hidden', 'true');
97
+ wrap.append(vid);
98
+ const badge = h('span', 'pk-badge');
99
+ badge.append(icon('play'));
100
+ wrap.append(badge);
101
+ wrap.addEventListener('mouseenter', () => vid.play().catch(() => {}));
102
+ wrap.addEventListener('mouseleave', () => vid.pause());
103
+ } else {
104
+ wrap.classList.add('pk-nomedia');
105
+ wrap.append(icon(tile.video ? 'play' : 'link'));
106
+ }
107
+ return wrap;
108
+ }
109
+
110
+ function openLink(tile) {
111
+ const href = safeUrl(tile.url) || safeUrl(tile.video);
112
+ if (!href) return null;
113
+ const a = h('a', 'pk-open');
114
+ a.href = href;
115
+ a.target = '_blank';
116
+ a.rel = 'noopener noreferrer';
117
+ a.setAttribute('aria-label', `Open ${tile.title} in a new tab`);
118
+ a.append(h('span', null, tile.url ? 'Open page' : 'Watch'), icon('external'));
119
+ return a;
120
+ }
121
+
122
+ /** One tile: the pick button, its link, and the note that shows while it is picked. */
123
+ function tileCell(q, tile, { cur, canEdit, toggle, onChange }) {
124
+ const btn = h('button', 'pk-pick');
125
+ btn.type = 'button';
126
+ btn.disabled = !canEdit;
127
+ btn.setAttribute('aria-pressed', 'false');
128
+ const order = h('span', 'pk-order');
129
+ order.setAttribute('aria-hidden', 'true');
130
+ const check = h('span', 'pk-check');
131
+ check.append(icon('check'));
132
+ check.append(order);
133
+ const head = h('span', 'pk-head');
134
+ head.append(h('span', 'pk-title', tile.title), check);
135
+ btn.append(mediaOf(q, tile), head);
136
+ if (tile.caption) btn.append(h('span', 'pk-caption', tile.caption));
137
+ btn.addEventListener('click', () => toggle(tile.id));
138
+
139
+ const noteWrap = h('div', 'pk-notewrap');
140
+ const note = h('textarea', 'pk-note');
141
+ note.rows = 2;
142
+ note.placeholder = 'Why this one? (optional)';
143
+ note.setAttribute('aria-label', `Note on ${tile.title}`);
144
+ const pickOf = () => cur().picks.find((p) => p.id === tile.id);
145
+ note.value = (pickOf() && pickOf().note) || '';
146
+ note.disabled = !canEdit;
147
+ note.addEventListener('input', () => {
148
+ const p = pickOf();
149
+ if (!p) return;
150
+ p.note = note.value;
151
+ if (onChange) onChange();
152
+ });
153
+ noteWrap.append(note);
154
+
155
+ const root = h('div', 'pk-tile');
156
+ root.append(btn);
157
+ const link = openLink(tile);
158
+ if (link) root.append(link);
159
+ root.append(noteWrap);
160
+ return { root, btn, order, noteWrap, note };
161
+ }
162
+
163
+ /**
164
+ * Builds the control for one pick question.
165
+ * @param {object} q normalized question
166
+ * @param {{ answers: Record<string, any> }} state the page's answer state; this control owns state.answers[q.id]
167
+ * @param {{ canEdit?: boolean, onChange?: () => void }} [hooks]
168
+ */
169
+ function control(q, state, hooks = {}) {
170
+ const canEdit = hooks.canEdit !== false;
171
+ const limit = limitOf(q);
172
+ const items = q.items || [];
173
+ state.answers[q.id] = seed(q, state.answers[q.id]);
174
+ const cur = () => state.answers[q.id];
175
+
176
+ const root = h('div', 'pk');
177
+ const status = h('p', 'pk-status');
178
+ status.setAttribute('role', 'status');
179
+ status.setAttribute('aria-live', 'polite');
180
+ const grid = h('div', 'pk-grid');
181
+ grid.setAttribute('role', 'group');
182
+ grid.setAttribute('aria-label', q.label || 'Choices');
183
+ const cells = new Map();
184
+
185
+ const rule = () => {
186
+ const min = q.min || 0;
187
+ if (limit === 1) return 'Pick one.';
188
+ if (min && min === limit) return `Pick ${min}.`;
189
+ if (min) return `Pick ${min} to ${limit}.`;
190
+ return limit < items.length ? `Pick up to ${limit}.` : 'Pick any number.';
191
+ };
192
+
193
+ function paint() {
194
+ const picks = cur().picks;
195
+ const full = picks.length >= limit && limit > 1;
196
+ for (const [id, cell] of cells) {
197
+ const at = picks.findIndex((p) => p.id === id);
198
+ const on = at >= 0;
199
+ cell.root.classList.toggle('sel', on);
200
+ cell.btn.setAttribute('aria-pressed', on ? 'true' : 'false');
201
+ cell.btn.setAttribute('aria-disabled', !on && full ? 'true' : 'false');
202
+ cell.order.textContent = on && limit > 1 ? String(at + 1) : '';
203
+ cell.noteWrap.hidden = !(on && q.itemNote !== false);
204
+ if (!on) cell.note.value = '';
205
+ }
206
+ status.textContent = `${picks.length} picked. ${rule()}`;
207
+ }
208
+
209
+ function toggle(id) {
210
+ if (!canEdit) return;
211
+ const picks = cur().picks;
212
+ const at = picks.findIndex((p) => p.id === id);
213
+ if (at >= 0) picks.splice(at, 1);
214
+ else if (limit === 1) picks.splice(0, picks.length, { id, note: '' });
215
+ else if (picks.length < limit) picks.push({ id, note: '' });
216
+ else return;
217
+ paint();
218
+ if (hooks.onChange) hooks.onChange();
219
+ }
220
+
221
+ for (const tile of items) {
222
+ const cell = tileCell(q, tile, { cur, canEdit, toggle, onChange: hooks.onChange });
223
+ cells.set(tile.id, cell);
224
+ grid.append(cell.root);
225
+ }
226
+
227
+ root.append(grid, status);
228
+ if (q.overall !== false) {
229
+ const overall = h('textarea', 'pk-overall');
230
+ overall.rows = 3;
231
+ overall.placeholder = 'Anything to add about the whole set? (optional)';
232
+ overall.setAttribute('aria-label', 'Overall note');
233
+ overall.value = cur().overall || '';
234
+ overall.disabled = !canEdit;
235
+ overall.addEventListener('input', () => {
236
+ cur().overall = overall.value;
237
+ if (hooks.onChange) hooks.onChange();
238
+ });
239
+ root.append(overall);
240
+ }
241
+ paint();
242
+ return root;
243
+ }
244
+
245
+ window.RelayPick = { control, seed, value, short };
246
+ })();
@@ -0,0 +1,24 @@
1
+ /** Relay's own id for the board catalog; a renderer lists it in `supportedCatalogIds`. */
2
+ export declare const BOARD_CATALOG_ID = "https://github.com/khanglvm/relay/a2ui/catalog/board/v1";
3
+ export declare const A2UI_PROTOCOL_VERSION = "1.0";
4
+ /** The MIME a surface is sent as, then the other spelling a host may declare it under. */
5
+ export declare const A2UI_MIME = "application/a2ui+json";
6
+ export declare const A2UI_MIMES: string[];
7
+ /** The tool a host calls with a renderer event. */
8
+ export declare const A2UI_ACTION_TOOL = "a2ui_action";
9
+ export declare const ACTION_SUBMIT = "relay.submit";
10
+ export declare const ACTION_DRAFT = "relay.draft";
11
+ /** Where the person's input lives in the surface's data model. */
12
+ export declare const DATA_ROOT: {
13
+ answers: string;
14
+ notes: string;
15
+ comment: string;
16
+ annotations: string;
17
+ blockEdits: string;
18
+ };
19
+ /** Ids that would reach Object.prototype if used as a data-model key. */
20
+ export declare const UNSAFE_KEYS: string[];
21
+ /** Escapes one data-model path segment (RFC 6901). */
22
+ export declare const pointerSegment: (key: any) => string;
23
+ /** The data-model pointer for one entry under a root: `/answers/q1`. */
24
+ export declare const dataPath: (root: any, key: any) => string;
@@ -0,0 +1,16 @@
1
+ /** The value to submit for one answer, or undefined while the question counts as unanswered. */
2
+ export declare function answeredValue(q: any, raw: any): any;
3
+ /**
4
+ * @param {Record<string, any>} dataModel the surface's data model: /answers, /notes, /comment, /annotations, /blockEdits
5
+ * @param {Record<string, any>} spec the normalized spec the surface was made from
6
+ * @returns {{ answers: Record<string, unknown>, comment: string, notes: Record<string, string>, annotations: object[], blockEdits: Record<string, unknown> }}
7
+ */
8
+ export declare function fromA2ui(dataModel: Record<string, any>, spec: Record<string, any>, { now }?: {
9
+ now?: string;
10
+ }): {
11
+ answers: Record<string, unknown>;
12
+ comment: string;
13
+ notes: Record<string, string>;
14
+ annotations: object[];
15
+ blockEdits: Record<string, unknown>;
16
+ };
@@ -0,0 +1,17 @@
1
+ /** True when the client declared the board catalog when it connected. */
2
+ export declare const capabilitiesDeclareBoardCatalog: (capabilities: any) => boolean;
3
+ /**
4
+ * True when a declaration lists the board catalog for protocol 1.0:
5
+ * `{"1.0": {supportedCatalogIds: [...]}}`. A declaration that names the MIME
6
+ * types it accepts must include one Relay sends.
7
+ */
8
+ export declare function declaresBoardCatalog(declaration: any): boolean;
9
+ /**
10
+ * Whether a call should get A2UI messages: the call's own `_meta.a2ui` decides first,
11
+ * then the capabilities the client declared when it connected.
12
+ * @param {{ capabilities?: any, meta?: any }} caller
13
+ */
14
+ export declare function wantsA2ui({ capabilities, meta }: {
15
+ capabilities?: any;
16
+ meta?: any;
17
+ }): boolean;
@@ -0,0 +1,12 @@
1
+ /** The plain text a renderer shows for a block it cannot draw. */
2
+ export declare function fallbackText(block: any): string;
3
+ /**
4
+ * The three messages that make up a board's surface: createSurface, updateComponents, updateDataModel.
5
+ * @param {Record<string, any>} spec a normalized spec
6
+ * @param {{ surfaceId?: string, draft?: Record<string, any> | null }} [options]
7
+ * @returns {Array<Record<string, any>>}
8
+ */
9
+ export declare function toA2ui(spec: Record<string, any>, { surfaceId, draft }?: {
10
+ surfaceId?: string;
11
+ draft?: Record<string, any> | null;
12
+ }): Array<Record<string, any>>;
@@ -0,0 +1,62 @@
1
+ import fs from 'node:fs';
2
+ export type FileAccess = {
3
+ /**
4
+ * Directory that relative spec paths resolve against.
5
+ */
6
+ cwd: string;
7
+ /**
8
+ * Real paths a spec may read from; a root may be a single file.
9
+ */
10
+ roots: string[];
11
+ };
12
+ /**
13
+ * @typedef {object} FileAccess
14
+ * @property {string} cwd Directory that relative spec paths resolve against.
15
+ * @property {string[]} roots Real paths a spec may read from; a root may be a single file.
16
+ */
17
+ /** Env var with extra roots, separated by the platform's path delimiter (":" on macOS and Linux). */
18
+ export declare const FILE_ROOTS_ENV = "RLY_FILE_ROOTS";
19
+ /** Expands a leading `~` to the home directory. */
20
+ export declare function expandHome(p: any): any;
21
+ /** Real paths of the roots that exist; a root that does not exist grants nothing. */
22
+ export declare function realRoots(list: any, cwd: any): any[];
23
+ /** Roots named by `RLY_FILE_ROOTS`. */
24
+ export declare function envFileRoots(env?: NodeJS.ProcessEnv): string[];
25
+ /**
26
+ * @param {{ cwd?: string, roots?: string[] }} [options] `roots` of `[]` means no local file may be read.
27
+ * @returns {FileAccess}
28
+ */
29
+ export declare function createFileAccess({ cwd, roots }?: {
30
+ cwd?: string;
31
+ roots?: string[];
32
+ }): FileAccess;
33
+ /** True when `target` is a root or lies under one. Both are real paths. */
34
+ export declare function isInsideRoots(target: any, roots: any): any;
35
+ /**
36
+ * Resolves a path a spec names and says whether it may be read.
37
+ * @param {FileAccess} access
38
+ * @param {unknown} raw the path as written; `~` and relative paths are expanded
39
+ * @param {{ allowDirectory?: boolean }} [options] directories are refused unless a caller opens them in an app
40
+ * @returns {{ ok: boolean, file?: string, stat?: fs.Stats, reason?: 'invalid' | 'outside' | 'missing' | 'not-file', resolved?: string }} `file` and `stat` when ok; otherwise `reason` and the real path it was refused at
41
+ */
42
+ export declare function checkReadable(access: FileAccess, raw: unknown, { allowDirectory }?: {
43
+ allowDirectory?: boolean;
44
+ }): {
45
+ ok: boolean;
46
+ file?: string;
47
+ stat?: fs.Stats;
48
+ reason?: 'invalid' | 'outside' | 'missing' | 'not-file';
49
+ resolved?: string;
50
+ };
51
+ /**
52
+ * The real path of a file a spec names, or a CliError worded for the agent.
53
+ * @param {FileAccess} access
54
+ * @param {unknown} raw
55
+ * @param {string} where which block, e.g. `board.blocks[0]`
56
+ * @param {string} field which field, e.g. `codeFile`
57
+ * @returns {{ file: string, stat: fs.Stats }}
58
+ */
59
+ export declare function resolveReadable(access: FileAccess, raw: unknown, where: string, field: string): {
60
+ file: string;
61
+ stat: fs.Stats;
62
+ };
@@ -5,10 +5,11 @@ export declare const modeOf: (spec: any) => "ask" | "show";
5
5
  * CliError so the tool can answer with an isError result the model can fix.
6
6
  * @param {import('./store.js').RelayStore} store
7
7
  * @param {Record<string, any>} args
8
- * @param {{ displayOnly?: boolean }} [options]
8
+ * @param {{ displayOnly?: boolean, fileRoots?: string[] }} [options] `fileRoots` are the only places a spec may read local files from; none by default
9
9
  */
10
10
  export declare function createMcpBoard(store: import('./store.js').RelayStore, args: Record<string, any>, options?: {
11
11
  displayOnly?: boolean;
12
+ fileRoots?: string[];
12
13
  }): Promise<{
13
14
  record: import("./store.js").BoardRecord;
14
15
  spec: {
@@ -142,7 +143,7 @@ export declare function specError(err: any): {
142
143
  isError?: boolean;
143
144
  };
144
145
  /** Saves the person's answers so far, so relay_result can show them before the final submit. */
145
- export declare function saveDraft(store: any, id: any, draft: any): Promise<any>;
146
+ export declare function saveDraft(store: any, id: any, draft: any, spec: any): Promise<any>;
146
147
  /**
147
148
  * Stores the final answers. A second submit is refused so a stray click cannot
148
149
  * overwrite what the agent may already have read.
@@ -163,6 +164,16 @@ export declare function recordEvent(store: any, record: any, event: any): Promis
163
164
  entry?: object;
164
165
  error?: string;
165
166
  }>;
167
+ /**
168
+ * A renderer event from an A2UI surface. `relay.submit` and `relay.draft` carry the surface's
169
+ * data model and store it as a submit or a draft; any other name is a widget button click.
170
+ * @returns {Promise<{ ok: boolean, status?: string, error?: string }>}
171
+ */
172
+ export declare function handleSurfaceAction(store: any, record: any, args: any): Promise<{
173
+ ok: boolean;
174
+ status?: string;
175
+ error?: string;
176
+ }>;
166
177
  /** What relay_result reports for a board right now. */
167
178
  export declare function resultOf(record: any): any;
168
179
  export declare const isFinal: (record: any) => boolean;
@@ -23,12 +23,15 @@ export declare const submitInput: z.ZodObject<{
23
23
  token: z.ZodString;
24
24
  payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
25
25
  }, z.core.$strip>;
26
+ /** A widget button click (`blockId`, `name`, `context`), or a renderer event (`action`, plus the surface's `dataModel`). */
26
27
  export declare const actionInput: z.ZodObject<{
27
28
  boardId: z.ZodString;
28
29
  token: z.ZodString;
29
- blockId: z.ZodString;
30
- name: z.ZodString;
30
+ blockId: z.ZodOptional<z.ZodString>;
31
+ name: z.ZodOptional<z.ZodString>;
31
32
  context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
33
+ action: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
34
+ dataModel: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
32
35
  }, z.core.$strip>;
33
36
  export declare const assetInput: z.ZodObject<{
34
37
  name: z.ZodString;
@@ -1,5 +1,7 @@
1
1
  /** Serves MCP over this process's stdin and stdout until the host closes stdin. */
2
- export declare function runMcp(): Promise<any>;
2
+ export declare function runMcp({ fileRoots }?: {
3
+ fileRoots?: any[];
4
+ }): Promise<any>;
3
5
  /** A browser Origin is trusted when it is local or the one the operator allowed. A client with no Origin is not a browser. */
4
6
  export declare function originAllowed(origin: any, allowOrigin: any): boolean;
5
7
  /** Constant-time string comparison for the bearer token. */
@@ -8,8 +10,9 @@ export declare function safeEqual(a: any, b: any): boolean;
8
10
  * Serves MCP over Streamable HTTP. Localhost by default; a bearer token and an
9
11
  * allowed Origin are the controls for anything wider.
10
12
  */
11
- export declare function runMcpHttp({ port, host, token, allowOrigin }?: {
13
+ export declare function runMcpHttp({ port, host, token, allowOrigin, fileRoots }?: {
12
14
  allowOrigin?: string;
15
+ fileRoots?: any[];
13
16
  host?: string;
14
17
  port?: number;
15
18
  token?: string;
@@ -18,7 +18,9 @@ export type BoardRecord = {
18
18
  events?: any[];
19
19
  };
20
20
  export type RelayStore = {
21
- create: (spec: any) => BoardRecord | Promise<BoardRecord>;
21
+ create: (spec: any, options?: {
22
+ fileRoots?: string[];
23
+ }) => BoardRecord | Promise<BoardRecord>;
22
24
  get: (id: string) => BoardRecord | null | Promise<BoardRecord | null>;
23
25
  update: (id: string, patch: Partial<BoardRecord>) => BoardRecord | null | Promise<BoardRecord | null>;
24
26
  };
@@ -32,17 +34,18 @@ export type RelayStore = {
32
34
  */
33
35
  /**
34
36
  * @typedef {object} RelayStore
35
- * @property {(spec: any) => BoardRecord | Promise<BoardRecord>} create
37
+ * @property {(spec: any, options?: { fileRoots?: string[] }) => BoardRecord | Promise<BoardRecord>} create
36
38
  * @property {(id: string) => BoardRecord | null | Promise<BoardRecord | null>} get
37
39
  * @property {(id: string, patch: Partial<BoardRecord>) => BoardRecord | null | Promise<BoardRecord | null>} update
38
40
  */
39
41
  /** The default store: one JSON file per board under the relay home, shared with the CLI. */
40
42
  export declare function fileStore(): {
41
- create: (spec: any) => {
43
+ create: (spec: any, options: any) => {
42
44
  id: string;
43
45
  createdAt: string;
44
46
  title: any;
45
47
  cwd: string;
48
+ fileRoots: string[];
46
49
  spec: any;
47
50
  draft: any;
48
51
  result: any;
@@ -1,4 +1,8 @@
1
- /** The server's HMAC key: a random value kept in the relay home, created on first use. */
1
+ /**
2
+ * The server's HMAC key: a random value kept in the relay home, created on first use.
3
+ * Two servers starting together both try to create it; the exclusive create lets one
4
+ * win and the other read what the winner wrote, so they never hold different keys.
5
+ */
2
6
  export declare function loadServerKey(file?: string): string;
3
7
  export declare const boardToken: (key: any, boardId: any) => string;
4
8
  /** Constant-time comparison, so a wrong token leaks nothing about the right one. */
@@ -4,6 +4,7 @@
4
4
  * @param {any} server an McpServer
5
5
  * @param {object} [options]
6
6
  * @param {import('./store.js').RelayStore} [options.store] where boards live; defaults to the relay home on disk
7
+ * @param {string[]} [options.fileRoots] folders a spec may read local files from (`codeFile`, images, `rowsFile`...); none by default, so a remote client cannot read the server's disk
7
8
  * @param {string | Buffer} [options.tokenKey] the secret behind board tokens; defaults to a key file in the relay home
8
9
  * @param {(name: string) => string} [options.assetUrl] URL of a vendor file, for hosts that can fetch it
9
10
  * @param {(boardId: string) => string} [options.linkUrl] a URL where a person can open the board outside the host
@@ -11,6 +12,7 @@
11
12
  */
12
13
  export declare function registerRelay(server: any, options?: {
13
14
  store?: import('./store.js').RelayStore;
15
+ fileRoots?: string[];
14
16
  tokenKey?: string | Buffer;
15
17
  assetUrl?: (name: string) => string;
16
18
  linkUrl?: (boardId: string) => string;
@@ -1,4 +1,4 @@
1
- export declare function normalizeA2uiBlock(rawBlock: any, id: any, cwd: any, where: any, hasHeight: any): {
1
+ export declare function normalizeA2uiBlock(rawBlock: any, id: any, files: any, where: any, hasHeight: any): {
2
2
  id: any;
3
3
  type: string;
4
4
  };
@@ -1,4 +1,4 @@
1
- export declare function normalizeChartBlock(raw: any, id: any, cwd: any, where: any, hasHeight: any): {
1
+ export declare function normalizeChartBlock(raw: any, id: any, files: any, where: any, hasHeight: any): {
2
2
  id: any;
3
3
  type: string;
4
4
  };
@@ -1,9 +1,9 @@
1
- export declare function normalizeCodeBlock(rawBlock: any, id: any, cwd: any, where: any, hasHeight: any): {
1
+ export declare function normalizeCodeBlock(rawBlock: any, id: any, files: any, where: any, hasHeight: any): {
2
2
  id: any;
3
3
  type: string;
4
4
  code: any;
5
5
  };
6
- export declare function normalizeDiffBlock(rawBlock: any, id: any, cwd: any, where: any, hasHeight: any): {
6
+ export declare function normalizeDiffBlock(rawBlock: any, id: any, files: any, where: any, hasHeight: any): {
7
7
  id: any;
8
8
  type: string;
9
9
  diff: any;