@khanglvm/relay 0.19.0 → 0.20.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/README.md +11 -4
- package/bin/rly.js +1 -1
- package/package.json +4 -4
- package/src/cli/args.js +46 -0
- package/src/cli/ask.js +12 -0
- package/src/cli/boards.js +326 -0
- package/src/cli/config.js +56 -0
- package/src/cli/context.js +13 -0
- package/src/cli/git.js +183 -0
- package/src/cli/help.js +91 -0
- package/src/cli/index.js +103 -0
- package/src/cli/install.js +197 -0
- package/src/cli/io.js +186 -0
- package/src/cli/mcp.js +94 -0
- package/src/cli/share.js +45 -0
- package/src/cli/skill.js +192 -0
- package/src/cli/upgrade.js +130 -0
- package/src/cli/wait.js +172 -0
- package/src/file-preview.js +1 -1
- package/src/index.js +1 -1
- package/src/link.js +57 -9
- package/src/mcp-ui/board/block-ctx.js +43 -0
- package/src/mcp-ui/board/bridge.js +165 -0
- package/src/mcp-ui/board/controls.js +310 -0
- package/src/mcp-ui/board/core.js +20 -0
- package/src/mcp-ui/board/lifecycle.js +118 -0
- package/src/mcp-ui/board/normalize.js +95 -0
- package/src/mcp-ui/board/render.js +200 -0
- package/src/mcp-ui/board/state.js +106 -0
- package/src/mcp-ui/board/vendors.js +86 -0
- package/src/mcp.js +12 -18
- package/src/{server.js → server/board.js} +16 -779
- package/src/server/files.js +141 -0
- package/src/server/http.js +114 -0
- package/src/server/index.js +2 -0
- package/src/server/page.js +183 -0
- package/src/server/paths.js +7 -0
- package/src/server/result.js +58 -0
- package/src/server/reviews.js +41 -0
- package/src/server/sanitize.js +231 -0
- package/src/spec/blocks/a2ui.js +25 -0
- package/src/spec/blocks/chart.js +49 -0
- package/src/spec/blocks/code.js +38 -0
- package/src/spec/blocks/diagram.js +39 -0
- package/src/spec/blocks/git-conflict.js +106 -0
- package/src/spec/blocks/image.js +32 -0
- package/src/spec/blocks/index.js +33 -0
- package/src/spec/blocks/markdown.js +13 -0
- package/src/spec/blocks/pdf.js +38 -0
- package/src/spec/blocks/table.js +122 -0
- package/src/spec/blocks/video.js +68 -0
- package/src/spec/blocks/widgets.js +98 -0
- package/src/spec/constants.js +65 -0
- package/src/spec/index.js +5 -0
- package/src/spec/normalize.js +285 -0
- package/src/spec/ready.js +106 -0
- package/src/spec/schema.js +182 -0
- package/src/spec/sources.js +83 -0
- package/src/store.js +1 -1
- package/src/ui/annotate/api.js +149 -0
- package/src/ui/annotate/badges.js +77 -0
- package/src/ui/annotate/chrome.js +158 -0
- package/src/ui/annotate/core.js +134 -0
- package/src/ui/annotate/highlights.js +129 -0
- package/src/ui/annotate/mutations.js +127 -0
- package/src/ui/annotate/popover.js +206 -0
- package/src/ui/annotate/summary.js +67 -0
- package/src/ui/app/annotations.js +88 -0
- package/src/ui/app/autosave.js +44 -0
- package/src/ui/app/core.js +74 -0
- package/src/ui/app/drafts.js +201 -0
- package/src/ui/app/heartbeat.js +150 -0
- package/src/ui/app/iframe-bridge.js +64 -0
- package/src/ui/app/persistence.js +117 -0
- package/src/ui/app/prefilled.js +21 -0
- package/src/ui/app/presence.js +38 -0
- package/src/ui/app/question-color.js +67 -0
- package/src/ui/app/questions.js +360 -0
- package/src/ui/app/render.js +135 -0
- package/src/ui/app/share.js +108 -0
- package/src/ui/app/submit.js +109 -0
- package/src/ui/app/theme.js +63 -0
- package/src/ui/blocks/api.js +1 -0
- package/src/ui/blocks/chart.js +222 -0
- package/src/ui/blocks/code.js +138 -0
- package/src/ui/blocks/compare.js +82 -0
- package/src/ui/blocks/core.js +74 -0
- package/src/ui/blocks/diff.js +361 -0
- package/src/ui/blocks/dispatch.js +111 -0
- package/src/ui/blocks/file-links.js +180 -0
- package/src/ui/blocks/git-conflict.js +151 -0
- package/src/ui/blocks/graphviz.js +57 -0
- package/src/ui/blocks/html.js +45 -0
- package/src/ui/blocks/image.js +371 -0
- package/src/ui/blocks/kpi.js +26 -0
- package/src/ui/blocks/markdown.js +223 -0
- package/src/ui/blocks/mermaid.js +242 -0
- package/src/ui/blocks/palette.js +59 -0
- package/src/ui/blocks/pdf.js +21 -0
- package/src/ui/blocks/plantuml.js +152 -0
- package/src/ui/blocks/table.js +155 -0
- package/src/ui/blocks/typography.js +25 -0
- package/src/ui/blocks/vendor.js +43 -0
- package/src/ui/blocks/video.js +43 -0
- package/src/ui/blocks/viewer-fullscreen.js +146 -0
- package/src/ui/blocks/viewer.js +324 -0
- package/src/ui/kit.js +1 -0
- package/src/ui/manifest.js +140 -0
- package/types/index.d.ts +1 -1
- package/types/spec/blocks/a2ui.d.ts +4 -0
- package/types/spec/blocks/chart.d.ts +4 -0
- package/types/spec/blocks/code.d.ts +10 -0
- package/types/spec/blocks/diagram.d.ts +15 -0
- package/types/spec/blocks/git-conflict.d.ts +7 -0
- package/types/spec/blocks/image.d.ts +5 -0
- package/types/spec/blocks/index.d.ts +30 -0
- package/types/spec/blocks/markdown.d.ts +5 -0
- package/types/spec/blocks/pdf.d.ts +4 -0
- package/types/spec/blocks/table.d.ts +9 -0
- package/types/spec/blocks/video.d.ts +4 -0
- package/types/spec/blocks/widgets.d.ts +21 -0
- package/types/spec/constants.d.ts +67 -0
- package/types/spec/index.d.ts +4 -0
- package/types/spec/normalize.d.ts +17 -0
- package/types/spec/ready.d.ts +1 -0
- package/types/{spec.d.ts → spec/schema.d.ts} +0 -20
- package/types/spec/sources.d.ts +14 -0
- package/types/ui/manifest.d.ts +62 -0
- package/src/cli.js +0 -1767
- package/src/mcp-ui/board.js +0 -1162
- package/src/spec.js +0 -1224
- package/src/ui/annotate.js +0 -1055
- package/src/ui/app.js +0 -1643
- package/src/ui/blocks.js +0 -3260
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
function clearErr(qid) { if (cards[qid]) cards[qid].classList.remove('error'); }
|
|
2
|
+
|
|
3
|
+
function syncOptSel(group) {
|
|
4
|
+
for (const lab of group.querySelectorAll('label.opt')) {
|
|
5
|
+
const input = lab.querySelector('input');
|
|
6
|
+
lab.classList.toggle('sel', input.checked);
|
|
7
|
+
const wrap = lab.closest('.optwrap');
|
|
8
|
+
if (wrap) wrap.classList.toggle('sel', input.checked);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function withOptionBlocks(labelEl, o, questionId) {
|
|
12
|
+
if (!Array.isArray(o.blocks) || !o.blocks.length) return labelEl;
|
|
13
|
+
const wrap = el('div', { class: 'optwrap' + (labelEl.classList.contains('sel') ? ' sel' : '') }, labelEl);
|
|
14
|
+
renderBlocks(wrap, o.blocks, questionId);
|
|
15
|
+
return wrap;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function controlSingle(q) {
|
|
19
|
+
const group = el('div');
|
|
20
|
+
const entries = [];
|
|
21
|
+
let otherRadio = null;
|
|
22
|
+
const otherOn = () => Boolean(state.other[q.id] && state.other[q.id].on);
|
|
23
|
+
const syncSingle = () => {
|
|
24
|
+
for (const { input, value } of entries) input.checked = state.answers[q.id] === value && !otherOn();
|
|
25
|
+
if (otherRadio) otherRadio.checked = otherOn();
|
|
26
|
+
syncOptSel(group);
|
|
27
|
+
clearErr(q.id);
|
|
28
|
+
};
|
|
29
|
+
for (const o of q.options) {
|
|
30
|
+
const input = el('input', { type: 'radio', name: q.id });
|
|
31
|
+
entries.push({ input, value: o.value });
|
|
32
|
+
input.checked = state.answers[q.id] === o.value && !otherOn();
|
|
33
|
+
input.addEventListener('click', (e) => {
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
if (state.answers[q.id] === o.value && !otherOn()) delete state.answers[q.id];
|
|
36
|
+
else { state.answers[q.id] = o.value; if (state.other[q.id]) state.other[q.id].on = false; }
|
|
37
|
+
setTimeout(syncSingle, 0);
|
|
38
|
+
});
|
|
39
|
+
input.addEventListener('change', () => {
|
|
40
|
+
if (!input.checked) return;
|
|
41
|
+
state.answers[q.id] = o.value;
|
|
42
|
+
if (state.other[q.id]) state.other[q.id].on = false;
|
|
43
|
+
syncSingle();
|
|
44
|
+
});
|
|
45
|
+
group.append(withOptionBlocks(
|
|
46
|
+
el('label', { class: 'opt' + (input.checked ? ' sel' : '') }, input,
|
|
47
|
+
el('div', {}, el('div', { class: 'ol' }, o.label), o.description ? el('div', { class: 'od' }, o.description) : null)),
|
|
48
|
+
o, q.id));
|
|
49
|
+
}
|
|
50
|
+
if (q.other) {
|
|
51
|
+
otherRadio = el('input', { type: 'radio', name: q.id });
|
|
52
|
+
const text = el('textarea', { class: 'otherinput', rows: '2', placeholder: 'your own answer…' });
|
|
53
|
+
text.value = (state.other[q.id] && state.other[q.id].text) || '';
|
|
54
|
+
otherRadio.checked = otherOn();
|
|
55
|
+
const ensureOther = () => state.other[q.id] || (state.other[q.id] = { on: false, text: text.value });
|
|
56
|
+
otherRadio.addEventListener('click', (e) => { e.preventDefault(); const oth = ensureOther(); oth.on = !oth.on; if (oth.on) delete state.answers[q.id]; setTimeout(syncSingle, 0); });
|
|
57
|
+
otherRadio.addEventListener('change', () => { if (!otherRadio.checked) return; const oth = ensureOther(); oth.on = true; delete state.answers[q.id]; syncSingle(); });
|
|
58
|
+
text.addEventListener('input', () => { const oth = ensureOther(); oth.text = text.value; if (!oth.on) { oth.on = true; delete state.answers[q.id]; } syncSingle(); });
|
|
59
|
+
group.append(el('label', { class: 'opt' + (otherRadio.checked ? ' sel' : '') }, otherRadio,
|
|
60
|
+
el('div', { style: 'flex:1' }, el('div', { class: 'ol' }, 'Other'), el('div', { class: 'otherbox' }, text))));
|
|
61
|
+
}
|
|
62
|
+
return group;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function controlMulti(q) {
|
|
66
|
+
const group = el('div');
|
|
67
|
+
const selected = new Set(Array.isArray(state.answers[q.id]) ? state.answers[q.id] : []);
|
|
68
|
+
const readChecked = () => {
|
|
69
|
+
state.answers[q.id] = [...group.querySelectorAll('input[data-val]')].filter((i) => i.checked).map((i) => i.dataset.val);
|
|
70
|
+
syncOptSel(group);
|
|
71
|
+
clearErr(q.id);
|
|
72
|
+
};
|
|
73
|
+
for (const o of q.options) {
|
|
74
|
+
const input = el('input', { type: 'checkbox', 'data-val': o.value });
|
|
75
|
+
input.checked = selected.has(o.value);
|
|
76
|
+
input.addEventListener('change', readChecked);
|
|
77
|
+
group.append(withOptionBlocks(
|
|
78
|
+
el('label', { class: 'opt' + (input.checked ? ' sel' : '') }, input,
|
|
79
|
+
el('div', {}, el('div', { class: 'ol' }, o.label), o.description ? el('div', { class: 'od' }, o.description) : null)),
|
|
80
|
+
o, q.id));
|
|
81
|
+
}
|
|
82
|
+
if (q.other) {
|
|
83
|
+
const oth = state.other[q.id];
|
|
84
|
+
const box = el('input', { type: 'checkbox' });
|
|
85
|
+
const text = el('textarea', { class: 'otherinput', rows: '2', placeholder: 'your own answer…' });
|
|
86
|
+
box.checked = Boolean(oth && oth.on);
|
|
87
|
+
text.value = (oth && oth.text) || '';
|
|
88
|
+
const sync = () => { state.other[q.id] = { on: box.checked, text: text.value }; syncOptSel(group); clearErr(q.id); };
|
|
89
|
+
box.addEventListener('change', sync);
|
|
90
|
+
text.addEventListener('input', () => { if (!box.checked) box.checked = true; sync(); });
|
|
91
|
+
group.append(el('label', { class: 'opt' + (box.checked ? ' sel' : '') }, box,
|
|
92
|
+
el('div', { style: 'flex:1' }, el('div', { class: 'ol' }, 'Other'), el('div', { class: 'otherbox' }, text))));
|
|
93
|
+
}
|
|
94
|
+
return group;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function segButtons(q, values, labels) {
|
|
98
|
+
const seg = el('div', { class: q.type === 'scale' ? 'scale' : 'seg' });
|
|
99
|
+
const buttons = [];
|
|
100
|
+
values.forEach((v, i) => {
|
|
101
|
+
const b = el('button', { type: 'button' }, labels[i]);
|
|
102
|
+
if (state.answers[q.id] === v) b.classList.add('sel');
|
|
103
|
+
b.addEventListener('click', () => {
|
|
104
|
+
if (state.answers[q.id] === v) delete state.answers[q.id];
|
|
105
|
+
else state.answers[q.id] = v;
|
|
106
|
+
for (const x of buttons) x.classList.toggle('sel', state.answers[q.id] === values[buttons.indexOf(x)]);
|
|
107
|
+
clearErr(q.id);
|
|
108
|
+
});
|
|
109
|
+
buttons.push(b);
|
|
110
|
+
seg.append(b);
|
|
111
|
+
});
|
|
112
|
+
return seg;
|
|
113
|
+
}
|
|
114
|
+
function controlScale(q) {
|
|
115
|
+
const values = [];
|
|
116
|
+
for (let i = q.min; i <= q.max; i++) values.push(i);
|
|
117
|
+
const seg = segButtons(q, values, values.map(String));
|
|
118
|
+
const row = el('div', { class: 'scale' });
|
|
119
|
+
if (q.minLabel) row.append(el('span', { class: 'slabel' }, q.minLabel));
|
|
120
|
+
row.append(...seg.children);
|
|
121
|
+
if (q.maxLabel) row.append(el('span', { class: 'slabel' }, q.maxLabel));
|
|
122
|
+
return row;
|
|
123
|
+
}
|
|
124
|
+
function controlText(q, multiline) {
|
|
125
|
+
const input = multiline
|
|
126
|
+
? el('textarea', { placeholder: q.placeholder || '' })
|
|
127
|
+
: el('input', { type: 'text', placeholder: q.placeholder || '' });
|
|
128
|
+
input.value = typeof state.answers[q.id] === 'string' ? state.answers[q.id] : '';
|
|
129
|
+
input.addEventListener('input', () => { state.answers[q.id] = input.value; clearErr(q.id); });
|
|
130
|
+
return input;
|
|
131
|
+
}
|
|
132
|
+
// Checklist / allocate — see the browser board's controls (no autosave here).
|
|
133
|
+
function controlChecklist(q) {
|
|
134
|
+
const wrap = el('div', { class: 'checklist' });
|
|
135
|
+
const cur = () => (state.answers[q.id] && typeof state.answers[q.id] === 'object' && !Array.isArray(state.answers[q.id])
|
|
136
|
+
? state.answers[q.id] : (state.answers[q.id] = {}));
|
|
137
|
+
for (const o of q.options) {
|
|
138
|
+
const seg = el('div', { class: 'chk-seg' });
|
|
139
|
+
const buttons = [];
|
|
140
|
+
for (const s of q.statuses) {
|
|
141
|
+
const b = el('button', { type: 'button', class: 'chk-status' + (s.tone ? ' tone-' + s.tone : '') }, s.label);
|
|
142
|
+
if (cur()[o.value] === s.value) b.classList.add('sel');
|
|
143
|
+
b.addEventListener('click', () => {
|
|
144
|
+
const m = cur();
|
|
145
|
+
if (m[o.value] === s.value) delete m[o.value];
|
|
146
|
+
else m[o.value] = s.value;
|
|
147
|
+
for (const x of buttons) x.btn.classList.toggle('sel', m[o.value] === x.val);
|
|
148
|
+
clearErr(q.id);
|
|
149
|
+
});
|
|
150
|
+
buttons.push({ btn: b, val: s.value });
|
|
151
|
+
seg.append(b);
|
|
152
|
+
}
|
|
153
|
+
wrap.append(el('div', { class: 'chk-row' },
|
|
154
|
+
el('div', { class: 'chk-body' }, el('div', { class: 'ol' }, o.label), o.description ? el('div', { class: 'od' }, o.description) : null),
|
|
155
|
+
seg));
|
|
156
|
+
}
|
|
157
|
+
return wrap;
|
|
158
|
+
}
|
|
159
|
+
function controlAllocate(q) {
|
|
160
|
+
const wrap = el('div', { class: 'allocate' });
|
|
161
|
+
const total = q.total || 100;
|
|
162
|
+
const unit = q.unit ? ' ' + q.unit : '';
|
|
163
|
+
const cur = () => (state.answers[q.id] = seedAllocate(q, state.answers[q.id]));
|
|
164
|
+
const sumEl = el('span', { class: 'alloc-sum' });
|
|
165
|
+
const fill = el('div', { class: 'alloc-bar-fill' });
|
|
166
|
+
const nums = [];
|
|
167
|
+
const refresh = () => {
|
|
168
|
+
const m = cur();
|
|
169
|
+
const sum = (q.options || []).reduce((a, o) => a + (Number(m[o.value]) || 0), 0);
|
|
170
|
+
const tail = sum > total ? ' (over by ' + (sum - total) + ')' : sum < total ? ' (' + (total - sum) + ' left)' : ' ✓';
|
|
171
|
+
sumEl.textContent = sum + ' / ' + total + unit + tail;
|
|
172
|
+
sumEl.classList.toggle('over', sum > total);
|
|
173
|
+
sumEl.classList.toggle('exact', sum === total);
|
|
174
|
+
fill.style.width = Math.min(100, (sum / total) * 100) + '%';
|
|
175
|
+
fill.classList.toggle('over', sum > total);
|
|
176
|
+
for (const n of nums) n.el.textContent = String(m[n.value] || 0);
|
|
177
|
+
};
|
|
178
|
+
for (const o of q.options) {
|
|
179
|
+
const m = cur();
|
|
180
|
+
const range = el('input', { type: 'range', min: '0', max: String(total), step: '1', class: 'alloc-range', 'aria-label': o.label });
|
|
181
|
+
range.value = String(m[o.value] || 0);
|
|
182
|
+
const num = el('span', { class: 'alloc-num' }, String(m[o.value] || 0));
|
|
183
|
+
range.addEventListener('input', () => { cur()[o.value] = Number(range.value) || 0; refresh(); clearErr(q.id); });
|
|
184
|
+
nums.push({ value: o.value, el: num });
|
|
185
|
+
wrap.append(el('div', { class: 'alloc-row' },
|
|
186
|
+
el('div', { class: 'alloc-rowhead' }, el('div', { class: 'ol' }, o.label), num),
|
|
187
|
+
range,
|
|
188
|
+
o.description ? el('div', { class: 'od' }, o.description) : null));
|
|
189
|
+
}
|
|
190
|
+
wrap.append(el('div', { class: 'alloc-total' },
|
|
191
|
+
el('div', { class: 'alloc-bar' }, fill),
|
|
192
|
+
el('div', { class: 'alloc-sumwrap' }, 'Total: ', sumEl)));
|
|
193
|
+
refresh();
|
|
194
|
+
return wrap;
|
|
195
|
+
}
|
|
196
|
+
// Reorderable priority list — see the browser board's controlRank. Answer is
|
|
197
|
+
// the ordered array of option values (highest first); always a full permutation.
|
|
198
|
+
function controlRank(q) {
|
|
199
|
+
const wrap = el('div', { class: 'rank' });
|
|
200
|
+
const byVal = new Map(q.options.map((o) => [o.value, o]));
|
|
201
|
+
let dragFrom = null;
|
|
202
|
+
function move(from, to) {
|
|
203
|
+
const arr = state.answers[q.id];
|
|
204
|
+
if (!Array.isArray(arr) || to < 0 || to >= arr.length || from === to) return;
|
|
205
|
+
const [x] = arr.splice(from, 1);
|
|
206
|
+
arr.splice(to, 0, x);
|
|
207
|
+
paint();
|
|
208
|
+
clearErr(q.id);
|
|
209
|
+
}
|
|
210
|
+
function paint() {
|
|
211
|
+
wrap.replaceChildren();
|
|
212
|
+
const order = state.answers[q.id] || [];
|
|
213
|
+
order.forEach((val, i) => {
|
|
214
|
+
const o = byVal.get(val);
|
|
215
|
+
if (!o) return;
|
|
216
|
+
const up = el('button', { type: 'button', class: 'rank-btn', title: 'Move up', 'aria-label': 'Move "' + o.label + '" up' }, '↑');
|
|
217
|
+
const down = el('button', { type: 'button', class: 'rank-btn', title: 'Move down', 'aria-label': 'Move "' + o.label + '" down' }, '↓');
|
|
218
|
+
up.disabled = i === 0;
|
|
219
|
+
down.disabled = i === order.length - 1;
|
|
220
|
+
up.addEventListener('click', () => move(i, i - 1));
|
|
221
|
+
down.addEventListener('click', () => move(i, i + 1));
|
|
222
|
+
const item = el('div', { class: 'rank-item', draggable: 'true' },
|
|
223
|
+
el('span', { class: 'rank-badge', 'aria-hidden': 'true' }, String(i + 1)),
|
|
224
|
+
el('div', { class: 'rank-body' },
|
|
225
|
+
el('div', { class: 'ol' }, o.label),
|
|
226
|
+
o.description ? el('div', { class: 'od' }, o.description) : null),
|
|
227
|
+
el('div', { class: 'rank-ctrls' }, up, down)
|
|
228
|
+
);
|
|
229
|
+
item.addEventListener('dragstart', (e) => {
|
|
230
|
+
dragFrom = i; item.classList.add('dragging');
|
|
231
|
+
try { e.dataTransfer.effectAllowed = 'move'; e.dataTransfer.setData('text/plain', String(i)); } catch (_) {}
|
|
232
|
+
});
|
|
233
|
+
item.addEventListener('dragend', () => { dragFrom = null; item.classList.remove('dragging'); });
|
|
234
|
+
item.addEventListener('dragover', (e) => { if (dragFrom !== null) { e.preventDefault(); item.classList.add('drop-into'); } });
|
|
235
|
+
item.addEventListener('dragleave', () => item.classList.remove('drop-into'));
|
|
236
|
+
item.addEventListener('drop', (e) => {
|
|
237
|
+
e.preventDefault();
|
|
238
|
+
const from = dragFrom; dragFrom = null;
|
|
239
|
+
if (from !== null && from !== i) move(from, i);
|
|
240
|
+
});
|
|
241
|
+
wrap.append(item);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
paint();
|
|
245
|
+
return wrap;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Resolve any CSS color (named/rgb/hsl/hex) to #rrggbb via the browser parser.
|
|
249
|
+
function cssColorToHex(str) {
|
|
250
|
+
const s = String(str || '').trim();
|
|
251
|
+
let m = /^#?([0-9a-fA-F]{6})$/.exec(s);
|
|
252
|
+
if (m) return '#' + m[1].toLowerCase();
|
|
253
|
+
m = /^#?([0-9a-fA-F]{3})$/.exec(s);
|
|
254
|
+
if (m) return '#' + m[1].split('').map((x) => x + x).join('').toLowerCase();
|
|
255
|
+
try {
|
|
256
|
+
const d = document.createElement('div');
|
|
257
|
+
d.style.color = '';
|
|
258
|
+
d.style.color = s;
|
|
259
|
+
if (!d.style.color) return null;
|
|
260
|
+
d.style.display = 'none';
|
|
261
|
+
document.body.appendChild(d);
|
|
262
|
+
const rgb = getComputedStyle(d).color;
|
|
263
|
+
document.body.removeChild(d);
|
|
264
|
+
const mm = rgb.match(/(\d+)[,\s]+(\d+)[,\s]+(\d+)/);
|
|
265
|
+
if (!mm) return null;
|
|
266
|
+
const h = (n) => Math.max(0, Math.min(255, Number(n))).toString(16).padStart(2, '0');
|
|
267
|
+
return '#' + h(mm[1]) + h(mm[2]) + h(mm[3]);
|
|
268
|
+
} catch { return null; }
|
|
269
|
+
}
|
|
270
|
+
function toHex6(c) { return cssColorToHex(c) || '#000000'; }
|
|
271
|
+
function controlColor(q) {
|
|
272
|
+
const wrap = el('div', { class: 'colorpick' });
|
|
273
|
+
const init = (typeof state.answers[q.id] === 'string' && state.answers[q.id]) || (typeof q.default === 'string' ? q.default : '');
|
|
274
|
+
const swatch = el('input', { type: 'color', class: 'colorswatch' });
|
|
275
|
+
const hex = el('input', { type: 'text', class: 'colorhex', placeholder: q.placeholder || '#rrggbb / rgb() / name', spellcheck: 'false', autocapitalize: 'off' });
|
|
276
|
+
swatch.value = toHex6(init || '#888888');
|
|
277
|
+
if (init) { hex.value = init; state.answers[q.id] = init; }
|
|
278
|
+
let syncPaletteSel = () => {};
|
|
279
|
+
const set = (val) => { state.answers[q.id] = val; syncPaletteSel(); clearErr(q.id); };
|
|
280
|
+
swatch.addEventListener('input', () => { hex.value = swatch.value; set(swatch.value); });
|
|
281
|
+
hex.addEventListener('input', () => { const v = hex.value.trim(); const h = cssColorToHex(v); if (h) swatch.value = h; set(v); });
|
|
282
|
+
if (Array.isArray(q.palette) && q.palette.length) {
|
|
283
|
+
const grid = el('div', { class: 'colorpalette' });
|
|
284
|
+
const cards = [];
|
|
285
|
+
for (const p of q.palette) {
|
|
286
|
+
const labelled = p.label && p.label !== p.value;
|
|
287
|
+
const card = el('button', { type: 'button', class: 'colorpal-sw', style: 'background:' + p.value, title: (labelled ? p.label + ' · ' : '') + p.value });
|
|
288
|
+
if (labelled) card.append(el('span', { class: 'colorpal-label' }, p.label));
|
|
289
|
+
card.addEventListener('click', () => { const h = cssColorToHex(p.value); if (h) swatch.value = h; hex.value = p.value; set(p.value); });
|
|
290
|
+
if (Annotate && !composing) Annotate.register(card, { blockId: null, questionId: q.id, target: { kind: 'swatch', label: (labelled ? p.label + ' · ' : '') + p.value } });
|
|
291
|
+
cards.push({ card, val: p.value });
|
|
292
|
+
grid.append(card);
|
|
293
|
+
}
|
|
294
|
+
syncPaletteSel = () => { for (const c of cards) c.card.classList.toggle('sel', state.answers[q.id] === c.val); };
|
|
295
|
+
wrap.append(grid);
|
|
296
|
+
}
|
|
297
|
+
wrap.append(el('div', { class: 'colorrow' }, swatch, hex));
|
|
298
|
+
if (Array.isArray(q.presets) && q.presets.length) {
|
|
299
|
+
const presets = el('div', { class: 'colorpresets' });
|
|
300
|
+
for (const c of q.presets) {
|
|
301
|
+
const b = el('button', { type: 'button', class: 'colorpreset', style: 'background:' + c, title: c });
|
|
302
|
+
b.addEventListener('click', () => { const h = cssColorToHex(c); if (h) swatch.value = h; hex.value = c; set(c); });
|
|
303
|
+
presets.append(b);
|
|
304
|
+
}
|
|
305
|
+
wrap.append(presets);
|
|
306
|
+
}
|
|
307
|
+
syncPaletteSel();
|
|
308
|
+
return wrap;
|
|
309
|
+
}
|
|
310
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const BOOT = (() => {
|
|
2
|
+
try { return JSON.parse(document.getElementById('boot').textContent); } catch { return {}; }
|
|
3
|
+
})();
|
|
4
|
+
const PROTOCOL = '2025-06-18';
|
|
5
|
+
|
|
6
|
+
// ---------- tiny DOM helper (mirrors app.js / blocks.js) ----------
|
|
7
|
+
function el(tag, attrs = {}, ...children) {
|
|
8
|
+
const n = document.createElement(tag);
|
|
9
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
10
|
+
if (v === undefined || v === null) continue;
|
|
11
|
+
if (k === 'class') n.className = v;
|
|
12
|
+
else if (k.startsWith('on')) n.addEventListener(k.slice(2), v);
|
|
13
|
+
else n.setAttribute(k, v);
|
|
14
|
+
}
|
|
15
|
+
for (const c of children.flat()) {
|
|
16
|
+
if (c !== null && c !== undefined) n.append(c.nodeType ? c : document.createTextNode(c));
|
|
17
|
+
}
|
|
18
|
+
return n;
|
|
19
|
+
}
|
|
20
|
+
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// ======================================================================
|
|
2
|
+
// boot
|
|
3
|
+
// ======================================================================
|
|
4
|
+
function setStatus(text) {
|
|
5
|
+
const s = document.getElementById('mcp-status');
|
|
6
|
+
if (s) s.textContent = text;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
let booted = false;
|
|
10
|
+
async function boot(rawOrNormalized, alreadyNormalized) {
|
|
11
|
+
if (booted || submitted) return;
|
|
12
|
+
const next = alreadyNormalized ? rawOrNormalized : clientNormalize(rawOrNormalized);
|
|
13
|
+
if (!next || (!Array.isArray(next.questions)) ) { return; }
|
|
14
|
+
if (!next.questions.length && !(Array.isArray(next.blocks) && next.blocks.length)) return;
|
|
15
|
+
booted = true;
|
|
16
|
+
composing = false;
|
|
17
|
+
if (previewTimer) { clearTimeout(previewTimer); previewTimer = null; }
|
|
18
|
+
spec = next;
|
|
19
|
+
QS = spec.questions || [];
|
|
20
|
+
seedDefaults();
|
|
21
|
+
indexHtmlBlocks(spec);
|
|
22
|
+
setStatus('Preparing…');
|
|
23
|
+
if (Annotate && spec.responseRequired !== false) {
|
|
24
|
+
Annotate.init({ initial: [], onChange: (a) => { state.annotations = Array.isArray(a) ? a : []; } });
|
|
25
|
+
} else if (Annotate && typeof Annotate.teardown === 'function') {
|
|
26
|
+
Annotate.teardown();
|
|
27
|
+
}
|
|
28
|
+
try { await preloadVendors(spec); } catch { /* render anyway; blocks degrade individually */ }
|
|
29
|
+
render();
|
|
30
|
+
applyDisplayMode();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Progressive preview: the host MAY stream the tool call's JSON as the agent
|
|
34
|
+
// writes it (ui/notifications/tool-input-partial — unclosed JSON auto-closed
|
|
35
|
+
// into a valid object). We render whatever blocks/questions are already valid
|
|
36
|
+
// so the board appears incrementally instead of only after the whole spec is
|
|
37
|
+
// generated. It's a read-only preview — submit is withheld until the final
|
|
38
|
+
// input/result arrives. Degrades to nothing on hosts that don't stream.
|
|
39
|
+
let composing = false;
|
|
40
|
+
let previewTimer = null;
|
|
41
|
+
let vendorsKicked = false;
|
|
42
|
+
function renderPreview(rawArgs) {
|
|
43
|
+
if (booted || submitted) return;
|
|
44
|
+
const next = clientNormalize(rawArgs);
|
|
45
|
+
if (!next) return;
|
|
46
|
+
const hasContent = (next.questions && next.questions.length) || (Array.isArray(next.blocks) && next.blocks.length);
|
|
47
|
+
if (!hasContent) return;
|
|
48
|
+
spec = next;
|
|
49
|
+
QS = spec.questions || [];
|
|
50
|
+
composing = true;
|
|
51
|
+
indexHtmlBlocks(spec);
|
|
52
|
+
if (!vendorsKicked) { vendorsKicked = true; preloadVendors(spec).catch(() => {}); }
|
|
53
|
+
if (previewTimer) return; // coalesce a burst of partials into one paint
|
|
54
|
+
previewTimer = setTimeout(() => { previewTimer = null; if (!booted && !submitted) render(); }, 120);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// The spec can arrive as the tool RESULT (preferred — server-normalized) or,
|
|
58
|
+
// on a leaner host, as the tool INPUT (raw). Prefer the result: when raw input
|
|
59
|
+
// lands first, hold briefly for a result before falling back to the input.
|
|
60
|
+
let rawInputTimer = null;
|
|
61
|
+
onNotify('ui/notifications/tool-result', (p) => {
|
|
62
|
+
if (rawInputTimer) { clearTimeout(rawInputTimer); rawInputTimer = null; }
|
|
63
|
+
const sc = p && p.structuredContent;
|
|
64
|
+
if (sc && sc.spec) return boot(sc.spec, true);
|
|
65
|
+
// Some hosts may echo the spec at the top level of structuredContent.
|
|
66
|
+
if (sc && Array.isArray(sc.questions)) return boot(sc, true);
|
|
67
|
+
});
|
|
68
|
+
onNotify('ui/notifications/tool-input', (p) => {
|
|
69
|
+
const args = p && p.arguments;
|
|
70
|
+
if (!args || typeof args !== 'object' || booted || rawInputTimer) return;
|
|
71
|
+
rawInputTimer = setTimeout(() => { rawInputTimer = null; boot(args, false); }, 250);
|
|
72
|
+
});
|
|
73
|
+
onNotify('ui/notifications/tool-input-partial', (p) => {
|
|
74
|
+
const args = p && p.arguments;
|
|
75
|
+
if (args && typeof args === 'object') renderPreview(args);
|
|
76
|
+
});
|
|
77
|
+
onNotify('ui/notifications/host-context-changed', (p) => {
|
|
78
|
+
if (p && typeof p === 'object') {
|
|
79
|
+
if ('theme' in p) host.theme = p.theme;
|
|
80
|
+
if ('styles' in p) host.styles = p.styles;
|
|
81
|
+
if ('platform' in p) host.platform = p.platform;
|
|
82
|
+
if ('safeAreaInsets' in p) host.safeAreaInsets = p.safeAreaInsets;
|
|
83
|
+
if ('deviceCapabilities' in p) host.deviceCapabilities = p.deviceCapabilities;
|
|
84
|
+
if (p.displayMode === 'inline' || p.displayMode === 'fullscreen' || p.displayMode === 'pip') {
|
|
85
|
+
displayMode = p.displayMode;
|
|
86
|
+
applyDisplayMode();
|
|
87
|
+
}
|
|
88
|
+
adoptHostStyles();
|
|
89
|
+
applyHostEnv();
|
|
90
|
+
applyTheme();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Kick off the handshake. Proceed even if the host doesn't answer init.
|
|
95
|
+
// SEP-1865 lifecycle: ui/initialize → (host reply) → ui/notifications/initialized.
|
|
96
|
+
// The host MUST NOT send tool-input / tool-result (i.e. the board spec) until
|
|
97
|
+
// it receives `initialized`, so this notification is mandatory — without it the
|
|
98
|
+
// board never gets its spec and never renders.
|
|
99
|
+
(async () => {
|
|
100
|
+
try {
|
|
101
|
+
const res = await request('ui/initialize', {
|
|
102
|
+
protocolVersion: PROTOCOL,
|
|
103
|
+
capabilities: {},
|
|
104
|
+
clientInfo: { name: 'relay', version: String(BOOT.version || '0') },
|
|
105
|
+
appCapabilities: { availableDisplayModes: ['inline', 'fullscreen'] },
|
|
106
|
+
});
|
|
107
|
+
host = (res && res.hostContext) || {};
|
|
108
|
+
} catch {
|
|
109
|
+
host = {};
|
|
110
|
+
}
|
|
111
|
+
if (host.displayMode === 'fullscreen' || host.displayMode === 'pip') displayMode = host.displayMode;
|
|
112
|
+
notify('ui/notifications/initialized', {});
|
|
113
|
+
adoptHostStyles();
|
|
114
|
+
applyHostEnv();
|
|
115
|
+
applyTheme();
|
|
116
|
+
setStatus('Waiting for the board…');
|
|
117
|
+
reportSize();
|
|
118
|
+
})();
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// ======================================================================
|
|
2
|
+
// client-side spec normalization (resilience)
|
|
3
|
+
// ----------------------------------------------------------------------
|
|
4
|
+
// The host normally hands us the SERVER-normalized spec via the tool result
|
|
5
|
+
// (structuredContent.spec) — options as {value,label}, blocks with ids, etc.
|
|
6
|
+
// If a host only forwards the raw tool input, this brings it close enough to
|
|
7
|
+
// render: it assigns ids and coerces option/column shapes. File-backed blocks
|
|
8
|
+
// (codeFile/htmlFile/local images) can't be resolved client-side and are left
|
|
9
|
+
// to the server path.
|
|
10
|
+
function clientNormalize(raw) {
|
|
11
|
+
if (!raw || typeof raw !== 'object') return null;
|
|
12
|
+
const spec = {
|
|
13
|
+
title: String(raw.title || 'Relay'),
|
|
14
|
+
intro: typeof raw.intro === 'string' ? raw.intro : '',
|
|
15
|
+
blocks: normBlocks(raw.blocks, ''),
|
|
16
|
+
allowPartial: raw.allowPartial !== false,
|
|
17
|
+
note: raw.note !== false,
|
|
18
|
+
autoClose: raw.autoClose !== false,
|
|
19
|
+
responseRequired: raw.responseRequired !== false,
|
|
20
|
+
questions: [],
|
|
21
|
+
submitLabel: typeof raw.submitLabel === 'string' ? raw.submitLabel : '',
|
|
22
|
+
};
|
|
23
|
+
const qs = Array.isArray(raw.questions) ? raw.questions : [];
|
|
24
|
+
qs.forEach((rq, i) => {
|
|
25
|
+
if (!rq || typeof rq !== 'object') return;
|
|
26
|
+
const id = String(rq.id || 'q' + (i + 1));
|
|
27
|
+
const type = String(rq.type || 'text');
|
|
28
|
+
const q = {
|
|
29
|
+
id, type,
|
|
30
|
+
label: String(rq.label || rq.question || rq.text || ''),
|
|
31
|
+
description: typeof rq.description === 'string' ? rq.description : '',
|
|
32
|
+
required: rq.required === true,
|
|
33
|
+
note: rq.note === undefined ? (type === 'single' || type === 'rank' || type === 'checklist' || type === 'allocate') : rq.note === true,
|
|
34
|
+
placeholder: typeof rq.placeholder === 'string' ? rq.placeholder : '',
|
|
35
|
+
blocks: normBlocks(rq.blocks, id + '-'),
|
|
36
|
+
};
|
|
37
|
+
if (type === 'single' || type === 'multi' || type === 'rank' || type === 'checklist' || type === 'allocate') {
|
|
38
|
+
const opts = Array.isArray(rq.options) ? rq.options : [];
|
|
39
|
+
q.options = opts.map((o, j) => {
|
|
40
|
+
if (typeof o === 'string' || typeof o === 'number') return { value: String(o), label: String(o) };
|
|
41
|
+
if (o && typeof o === 'object') {
|
|
42
|
+
const value = String(o.value != null ? o.value : o.label != null ? o.label : '');
|
|
43
|
+
const out = { value, label: String(o.label != null ? o.label : value) };
|
|
44
|
+
if (o.description) out.description = String(o.description);
|
|
45
|
+
const ob = normBlocks(o.blocks, id + '-o' + (j + 1) + '-');
|
|
46
|
+
if (ob.length) out.blocks = ob;
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
return { value: String(o), label: String(o) };
|
|
50
|
+
});
|
|
51
|
+
if (type === 'single' || type === 'multi') q.other = type === 'single' ? rq.other !== false : rq.other === true;
|
|
52
|
+
}
|
|
53
|
+
if (type === 'checklist') {
|
|
54
|
+
const rawSt = Array.isArray(rq.statuses) && rq.statuses.length ? rq.statuses
|
|
55
|
+
: [{ value: 'pass', label: 'Pass', tone: 'ok' }, { value: 'fail', label: 'Fail', tone: 'bad' }, { value: 'na', label: 'N/A', tone: 'muted' }];
|
|
56
|
+
q.statuses = rawSt.map((s) => typeof s === 'object' && s
|
|
57
|
+
? { value: String(s.value != null ? s.value : s.label || ''), label: String(s.label != null ? s.label : s.value || ''), tone: s.tone ? String(s.tone) : undefined }
|
|
58
|
+
: { value: String(s), label: String(s) === 'na' ? 'N/A' : String(s) });
|
|
59
|
+
}
|
|
60
|
+
if (type === 'allocate') {
|
|
61
|
+
q.total = Number.isFinite(rq.total) && rq.total > 0 ? Math.floor(rq.total) : 100;
|
|
62
|
+
if (rq.unit !== undefined) q.unit = String(rq.unit);
|
|
63
|
+
}
|
|
64
|
+
if (type === 'scale') {
|
|
65
|
+
q.min = Number.isFinite(rq.min) ? rq.min : 1;
|
|
66
|
+
q.max = Number.isFinite(rq.max) ? rq.max : Math.max(5, q.min + 1);
|
|
67
|
+
q.minLabel = typeof rq.minLabel === 'string' ? rq.minLabel : '';
|
|
68
|
+
q.maxLabel = typeof rq.maxLabel === 'string' ? rq.maxLabel : '';
|
|
69
|
+
}
|
|
70
|
+
if (type === 'color' && Array.isArray(rq.presets)) {
|
|
71
|
+
q.presets = rq.presets.map((c) => String(c)).filter(Boolean);
|
|
72
|
+
}
|
|
73
|
+
if (type === 'color' && Array.isArray(rq.palette)) {
|
|
74
|
+
q.palette = rq.palette.map((p) => typeof p === 'object' && p
|
|
75
|
+
? { value: String(p.value != null ? p.value : p.color || ''), label: String(p.label != null ? p.label : (p.name != null ? p.name : (p.value != null ? p.value : p.color || ''))) }
|
|
76
|
+
: { value: String(p), label: String(p) }).filter((p) => p.value);
|
|
77
|
+
}
|
|
78
|
+
if (rq.default !== undefined) q.default = rq.default;
|
|
79
|
+
spec.questions.push(q);
|
|
80
|
+
});
|
|
81
|
+
if (!spec.submitLabel) spec.submitLabel = spec.questions.length ? 'Submit' : 'Acknowledge';
|
|
82
|
+
return spec;
|
|
83
|
+
}
|
|
84
|
+
function normBlocks(blocks, prefix) {
|
|
85
|
+
if (!Array.isArray(blocks)) return [];
|
|
86
|
+
let n = 0;
|
|
87
|
+
const out = [];
|
|
88
|
+
for (const b of blocks) {
|
|
89
|
+
if (!b || typeof b !== 'object' || !b.type) continue;
|
|
90
|
+
out.push(b.id ? b : { ...b, id: prefix + 'b' + (++n) });
|
|
91
|
+
if (b.id) n++;
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
|