@khanglvm/relay 0.12.1 → 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/AGENT.md +1 -1
- package/package.json +1 -1
- package/src/mcp-ui/board.js +27 -3
- package/src/mcp-ui/index.html +6 -1
- package/src/mcp.js +30 -5
- package/src/spec.js +5 -2
- package/src/ui/annotate.css +8 -4
- package/src/ui/annotate.js +11 -1
- package/src/ui/app.js +2 -2
- package/src/ui/style.css +2 -0
package/docs/AGENT.md
CHANGED
|
@@ -154,7 +154,7 @@ rly show --html-file prototype.html --title "Dashboard concept" --height 600
|
|
|
154
154
|
{ "value": "a", "label": "Approach A", "description": "fast, less flexible" },
|
|
155
155
|
"Approach B" // plain strings work too
|
|
156
156
|
],
|
|
157
|
-
"other":
|
|
157
|
+
"other": false }, // single: "Other" (free-text textarea) is ON by default — set false to remove it
|
|
158
158
|
{ "id": "scope", "type": "multi", "label": "Include which parts?", "options": ["api", "ui", "docs"],
|
|
159
159
|
"note": true }, // optional free-text under the question
|
|
160
160
|
// → returned as result.notes.scope
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanglvm/relay",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "Question boards with rich blocks (markdown, charts, mermaid, tables, code, diffs, video, sandboxed HTML), clickable local file-links, and element-level annotations for AI coding agents (Claude Code, Codex, …): ask users structured questions, present interactive visuals, collect inline comments, read answers as JSON — in a local browser board OR rendered INLINE inside the Claude & Codex apps as an MCP App (SEP-1865).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-agents",
|
package/src/mcp-ui/board.js
CHANGED
|
@@ -159,6 +159,25 @@
|
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
+
// Platform awareness: reflect the host's surface so the board (and CSS) can
|
|
163
|
+
// adapt — a data-platform hint, a touch flag, and the host's safe-area insets
|
|
164
|
+
// applied as padding so content clears notches / home indicators on mobile.
|
|
165
|
+
function applyHostEnv() {
|
|
166
|
+
const root = document.documentElement;
|
|
167
|
+
if (host.platform === 'web' || host.platform === 'desktop' || host.platform === 'mobile') {
|
|
168
|
+
root.dataset.platform = host.platform;
|
|
169
|
+
}
|
|
170
|
+
root.classList.toggle('mcp-touch', Boolean(host.deviceCapabilities && host.deviceCapabilities.touch));
|
|
171
|
+
const sai = host.safeAreaInsets;
|
|
172
|
+
if (sai && typeof sai === 'object') {
|
|
173
|
+
const px = (n) => (Number.isFinite(n) ? n : 0) + 'px';
|
|
174
|
+
root.style.setProperty('--mcp-safe-top', px(sai.top));
|
|
175
|
+
root.style.setProperty('--mcp-safe-right', px(sai.right));
|
|
176
|
+
root.style.setProperty('--mcp-safe-bottom', px(sai.bottom));
|
|
177
|
+
root.style.setProperty('--mcp-safe-left', px(sai.left));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
162
181
|
let sizeTimer = null;
|
|
163
182
|
function measureHeight() {
|
|
164
183
|
return Math.max(document.documentElement.scrollHeight, document.body ? document.body.scrollHeight : 0);
|
|
@@ -230,7 +249,7 @@
|
|
|
230
249
|
}
|
|
231
250
|
return { value: String(o), label: String(o) };
|
|
232
251
|
});
|
|
233
|
-
q.other = rq.other === true;
|
|
252
|
+
q.other = type === 'single' ? rq.other !== false : rq.other === true;
|
|
234
253
|
}
|
|
235
254
|
if (type === 'scale') {
|
|
236
255
|
q.min = Number.isFinite(rq.min) ? rq.min : 1;
|
|
@@ -496,7 +515,7 @@
|
|
|
496
515
|
}
|
|
497
516
|
if (q.other) {
|
|
498
517
|
otherRadio = el('input', { type: 'radio', name: q.id });
|
|
499
|
-
const text = el('
|
|
518
|
+
const text = el('textarea', { class: 'otherinput', rows: '2', placeholder: 'your own answer…' });
|
|
500
519
|
text.value = (state.other[q.id] && state.other[q.id].text) || '';
|
|
501
520
|
otherRadio.checked = otherOn();
|
|
502
521
|
const ensureOther = () => state.other[q.id] || (state.other[q.id] = { on: false, text: text.value });
|
|
@@ -529,7 +548,7 @@
|
|
|
529
548
|
if (q.other) {
|
|
530
549
|
const oth = state.other[q.id];
|
|
531
550
|
const box = el('input', { type: 'checkbox' });
|
|
532
|
-
const text = el('
|
|
551
|
+
const text = el('textarea', { class: 'otherinput', rows: '2', placeholder: 'your own answer…' });
|
|
533
552
|
box.checked = Boolean(oth && oth.on);
|
|
534
553
|
text.value = (oth && oth.text) || '';
|
|
535
554
|
const sync = () => { state.other[q.id] = { on: box.checked, text: text.value }; syncOptSel(group); clearErr(q.id); };
|
|
@@ -841,11 +860,15 @@
|
|
|
841
860
|
if (p && typeof p === 'object') {
|
|
842
861
|
if ('theme' in p) host.theme = p.theme;
|
|
843
862
|
if ('styles' in p) host.styles = p.styles;
|
|
863
|
+
if ('platform' in p) host.platform = p.platform;
|
|
864
|
+
if ('safeAreaInsets' in p) host.safeAreaInsets = p.safeAreaInsets;
|
|
865
|
+
if ('deviceCapabilities' in p) host.deviceCapabilities = p.deviceCapabilities;
|
|
844
866
|
if (p.displayMode === 'inline' || p.displayMode === 'fullscreen' || p.displayMode === 'pip') {
|
|
845
867
|
displayMode = p.displayMode;
|
|
846
868
|
applyDisplayMode();
|
|
847
869
|
}
|
|
848
870
|
adoptHostStyles();
|
|
871
|
+
applyHostEnv();
|
|
849
872
|
applyTheme();
|
|
850
873
|
}
|
|
851
874
|
});
|
|
@@ -870,6 +893,7 @@
|
|
|
870
893
|
if (host.displayMode === 'fullscreen' || host.displayMode === 'pip') displayMode = host.displayMode;
|
|
871
894
|
notify('ui/notifications/initialized', {});
|
|
872
895
|
adoptHostStyles();
|
|
896
|
+
applyHostEnv();
|
|
873
897
|
applyTheme();
|
|
874
898
|
setStatus('Waiting for the board…');
|
|
875
899
|
reportSize();
|
package/src/mcp-ui/index.html
CHANGED
|
@@ -13,7 +13,12 @@
|
|
|
13
13
|
:root{ color-scheme: light dark; }
|
|
14
14
|
html,body{ background:transparent; }
|
|
15
15
|
body{ margin:0; }
|
|
16
|
-
.wrap{ max-width:none; margin:0;
|
|
16
|
+
.wrap{ max-width:none; margin:0;
|
|
17
|
+
padding:
|
|
18
|
+
calc(14px + var(--mcp-safe-top, 0px))
|
|
19
|
+
calc(16px + var(--mcp-safe-right, 0px))
|
|
20
|
+
calc(18px + var(--mcp-safe-bottom, 0px))
|
|
21
|
+
calc(16px + var(--mcp-safe-left, 0px)); }
|
|
17
22
|
.mcp-status{ font:13px/1.5 var(--sans, -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif); color:var(--muted,#8a8580); padding:18px 16px; }
|
|
18
23
|
/* post-submit: a slim one-line confirmation so the iframe collapses small */
|
|
19
24
|
.mcp-done{ display:flex; align-items:center; gap:8px; padding:11px 16px; font:14px/1.4 var(--sans, -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif); color:var(--fg,#1c1b19); }
|
package/src/mcp.js
CHANGED
|
@@ -214,17 +214,42 @@ function callTool(params) {
|
|
|
214
214
|
const msg = err instanceof CliError ? err.message : String((err && err.message) || err);
|
|
215
215
|
return { content: [{ type: 'text', text: 'relay: invalid board spec — ' + msg }], isError: true };
|
|
216
216
|
}
|
|
217
|
-
const nQ = spec.questions.length;
|
|
218
|
-
const summary = nQ
|
|
219
|
-
? `Relay board "${spec.title}" is now displayed to the user (${nQ} question${nQ === 1 ? '' : 's'}). They will fill it in and submit; their answers will be delivered back to you. Do NOT re-ask these questions in plain text — wait for the submission.`
|
|
220
|
-
: `Relay board "${spec.title}" is now displayed to the user. They can review it and acknowledge; any feedback will be delivered back to you.`;
|
|
221
217
|
return {
|
|
222
|
-
content: [{ type: 'text', text:
|
|
218
|
+
content: [{ type: 'text', text: boardText(spec) }],
|
|
223
219
|
structuredContent: { spec, mode: name === 'relay_show' ? 'show' : 'ask' },
|
|
224
220
|
_meta: { ui: { resourceUri: BOARD_URI }, [UI_EXT]: { resourceUri: BOARD_URI } },
|
|
225
221
|
};
|
|
226
222
|
}
|
|
227
223
|
|
|
224
|
+
// The tool-result text. Beyond announcing the board, it carries a readable
|
|
225
|
+
// rendering of the questions as a GRACEFUL FALLBACK: on a surface that can't show
|
|
226
|
+
// the interactive board (some mobile/remote-control views), the user can still
|
|
227
|
+
// answer in chat and the model has the questions to work from. The model should
|
|
228
|
+
// PREFER the rendered board (wait for the submission) and only fall back to chat
|
|
229
|
+
// when the board clearly didn't render for the user.
|
|
230
|
+
function boardText(spec) {
|
|
231
|
+
const nQ = spec.questions.length;
|
|
232
|
+
if (!nQ) {
|
|
233
|
+
return `Relay board "${spec.title}" is now displayed to the user. They can review it and acknowledge; any feedback will be delivered back to you.`;
|
|
234
|
+
}
|
|
235
|
+
const lines = [];
|
|
236
|
+
lines.push(`Relay board "${spec.title}" is now displayed to the user (${nQ} question${nQ === 1 ? '' : 's'}). Prefer the interactive board — wait for their submission; do NOT re-ask in plain text.`);
|
|
237
|
+
lines.push('');
|
|
238
|
+
lines.push('If the board does NOT render on the user\'s surface (e.g. some mobile / remote views) they can answer in chat — the questions are:');
|
|
239
|
+
spec.questions.forEach((q, i) => {
|
|
240
|
+
let line = `${i + 1}. [${q.id}] ${q.label} (${q.type}`;
|
|
241
|
+
if (q.required || spec.allowPartial === false) line += ', required';
|
|
242
|
+
line += ')';
|
|
243
|
+
if (Array.isArray(q.options) && q.options.length) {
|
|
244
|
+
line += ' — options: ' + q.options.map((o) => o.label || o.value).join(' | ') + (q.other ? ' | Other (free text)' : '');
|
|
245
|
+
} else if (q.type === 'scale') {
|
|
246
|
+
line += ` — ${q.min}…${q.max}`;
|
|
247
|
+
}
|
|
248
|
+
lines.push(line);
|
|
249
|
+
});
|
|
250
|
+
return lines.join('\n');
|
|
251
|
+
}
|
|
252
|
+
|
|
228
253
|
// ---------- stdio loop ----------
|
|
229
254
|
export function runMcp() {
|
|
230
255
|
// The peer closing stdout (EPIPE) is the only reason to stop writing — NOT a
|
package/src/spec.js
CHANGED
|
@@ -510,7 +510,10 @@ export function normalizeSpec(raw, { cwd = process.cwd() } = {}) {
|
|
|
510
510
|
if (q.options.length < 1) {
|
|
511
511
|
throw new CliError(`${where}: type "${type}" needs at least 1 option.`);
|
|
512
512
|
}
|
|
513
|
-
|
|
513
|
+
// Radio (single) questions include an "Other" free-text option by default so
|
|
514
|
+
// the user is never boxed into the listed choices; opt out with other:false.
|
|
515
|
+
// Multi stays opt-in (checkbox lists are usually exhaustive on purpose).
|
|
516
|
+
q.other = type === 'single' ? rq.other !== false : rq.other === true;
|
|
514
517
|
}
|
|
515
518
|
|
|
516
519
|
if (type === 'scale') {
|
|
@@ -667,7 +670,7 @@ export const SPEC_SCHEMA = {
|
|
|
667
670
|
],
|
|
668
671
|
},
|
|
669
672
|
},
|
|
670
|
-
other: { type: 'boolean',
|
|
673
|
+
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).' },
|
|
671
674
|
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 "single" (radio) questions so users can comment on their pick, false for other types; set note:false to hide it on a single question.' },
|
|
672
675
|
placeholder: { type: 'string', description: 'For text/textarea.' },
|
|
673
676
|
default: { description: 'Pre-selected value. Shape matches the answer shape for the type.' },
|
package/src/ui/annotate.css
CHANGED
|
@@ -274,11 +274,15 @@
|
|
|
274
274
|
.ann-rail-list .ann-sum-row + .ann-sum-row { border-top: 1px solid var(--border); }
|
|
275
275
|
.ann-rail-list .ann-sum-row:hover { border-color: var(--accent); box-shadow: var(--shadow-card); }
|
|
276
276
|
|
|
277
|
-
/*
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
277
|
+
/* The rail always overlays the board (scrim dims, content never moves) — opening
|
|
278
|
+
it must NOT shift layout, on any width. It's reached only via the floating
|
|
279
|
+
Comments button, which flashes when a new comment lands. */
|
|
280
|
+
@keyframes ann-toggle-pulse {
|
|
281
|
+
0% { transform: scale(1); }
|
|
282
|
+
35% { transform: scale(1.12); box-shadow: 0 0 0 4px var(--accent-soft); }
|
|
283
|
+
100% { transform: scale(1); }
|
|
281
284
|
}
|
|
285
|
+
.ann-rail-toggle.pulse { animation: ann-toggle-pulse 600ms var(--ease); border-color: var(--accent); color: var(--accent); }
|
|
282
286
|
|
|
283
287
|
/* ---------- jump-to flash ---------- */
|
|
284
288
|
.ann-flash { animation: ann-flash 1s var(--ease); }
|
package/src/ui/annotate.js
CHANGED
|
@@ -367,6 +367,14 @@
|
|
|
367
367
|
if (railOpen) closeRail();
|
|
368
368
|
else openRail();
|
|
369
369
|
}
|
|
370
|
+
// Briefly flash the floating Comments button (used when a comment is added so
|
|
371
|
+
// the user sees it landed, without auto-opening the rail / shifting layout).
|
|
372
|
+
function pulseToggle() {
|
|
373
|
+
if (!dom || !dom.railToggle) return;
|
|
374
|
+
dom.railToggle.classList.remove('pulse');
|
|
375
|
+
void dom.railToggle.offsetWidth; // reflow so the animation restarts
|
|
376
|
+
dom.railToggle.classList.add('pulse');
|
|
377
|
+
}
|
|
370
378
|
// Sync the toggle badge + rail count with the live list; hide the whole rail
|
|
371
379
|
// affordance when there are no comments.
|
|
372
380
|
function refreshRailChrome() {
|
|
@@ -601,7 +609,9 @@
|
|
|
601
609
|
}
|
|
602
610
|
}
|
|
603
611
|
changed();
|
|
604
|
-
|
|
612
|
+
// Don't auto-open the rail — that shifts the board layout. Just flash the
|
|
613
|
+
// floating Comments button so the user notices, and opens it when they want.
|
|
614
|
+
pulseToggle();
|
|
605
615
|
}
|
|
606
616
|
|
|
607
617
|
// Append a user reply to a top-level annotation's thread (cap 50, like the
|
package/src/ui/app.js
CHANGED
|
@@ -597,7 +597,7 @@
|
|
|
597
597
|
}
|
|
598
598
|
if (q.other) {
|
|
599
599
|
otherRadio = el('input', { type: 'radio', name: q.id });
|
|
600
|
-
const text = el('
|
|
600
|
+
const text = el('textarea', { class: 'otherinput', rows: '2', placeholder: 'your own answer…' });
|
|
601
601
|
text.value = (state.other[q.id] && state.other[q.id].text) || '';
|
|
602
602
|
otherRadio.checked = otherOn();
|
|
603
603
|
const ensureOther = () => state.other[q.id] || (state.other[q.id] = { on: false, text: text.value });
|
|
@@ -666,7 +666,7 @@
|
|
|
666
666
|
if (q.other) {
|
|
667
667
|
const oth = state.other[q.id];
|
|
668
668
|
const box = el('input', { type: 'checkbox' });
|
|
669
|
-
const text = el('
|
|
669
|
+
const text = el('textarea', { class: 'otherinput', rows: '2', placeholder: 'your own answer…' });
|
|
670
670
|
box.checked = Boolean(oth && oth.on);
|
|
671
671
|
text.value = (oth && oth.text) || '';
|
|
672
672
|
const sync = () => {
|
package/src/ui/style.css
CHANGED
|
@@ -211,6 +211,8 @@ input[type="text"]:focus, textarea:focus {
|
|
|
211
211
|
box-shadow: 0 0 0 3px var(--accent-soft);
|
|
212
212
|
}
|
|
213
213
|
textarea { min-height: 90px; resize: vertical; }
|
|
214
|
+
/* the inline "Other" free-text is a compact 2-row textarea, not a tall one */
|
|
215
|
+
.otherbox .otherinput { min-height: 2.6em; padding: 8px 12px; }
|
|
214
216
|
|
|
215
217
|
.qnotewrap { margin-top: 10px; }
|
|
216
218
|
.qnotewrap .qnote { font-size: 0.88rem; padding: 8px 12px; min-height: 52px; resize: vertical; }
|