@khanglvm/relay 0.18.0 → 0.20.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/bin/rly.js +1 -1
- package/package.json +39 -4
- package/schema/spec.v1.json +1368 -0
- package/src/a2ui/compile.js +2 -0
- 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 +90 -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 +104 -0
- package/src/link.js +1 -0
- 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 +15 -21
- package/src/{server.js → server/board.js} +17 -781
- 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/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/a2ui/compile.d.ts +40 -0
- package/types/index.d.ts +181 -0
- package/types/mcp.d.ts +31 -0
- 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/schema.d.ts +1171 -0
- package/types/spec/sources.d.ts +14 -0
- package/types/store.d.ts +29 -0
- package/types/ui/manifest.d.ts +62 -0
- package/types/util.d.ts +6 -0
- package/src/cli.js +0 -1766
- package/src/mcp-ui/board.js +0 -1162
- package/src/spec.js +0 -1222
- package/src/ui/annotate.js +0 -1055
- package/src/ui/app.js +0 -1643
- package/src/ui/blocks.js +0 -3260
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
function blockCtx(questionId) {
|
|
2
|
+
return {
|
|
3
|
+
theme: effectiveTheme,
|
|
4
|
+
htmlSrc: (blockId) => htmlBlobSrc(blockId),
|
|
5
|
+
questionId: questionId == null ? null : questionId,
|
|
6
|
+
// No annotation during the streaming preview (it re-renders); on the final
|
|
7
|
+
// interactive render, wire the engine so blocks register their targets.
|
|
8
|
+
annotate: composing || (spec && spec.responseRequired === false) ? null : Annotate,
|
|
9
|
+
canComment: Boolean(spec && spec.responseRequired !== false),
|
|
10
|
+
saveArtifact: async ({ dataUrl, mime, width, height }) => {
|
|
11
|
+
const comma = typeof dataUrl === 'string' ? dataUrl.indexOf(',') : -1;
|
|
12
|
+
if (comma < 0) throw new Error('invalid image crop');
|
|
13
|
+
return { data: dataUrl.slice(comma + 1), mime: mime || 'image/png', width, height };
|
|
14
|
+
},
|
|
15
|
+
edits: state.blockEdits,
|
|
16
|
+
onBlockEdit: (blockId, codeOrNull) => {
|
|
17
|
+
if (codeOrNull === null || codeOrNull === undefined) delete state.blockEdits[blockId];
|
|
18
|
+
else state.blockEdits[blockId] = codeOrNull;
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
document.addEventListener('relay:block-edit', (e) => {
|
|
23
|
+
const d = e.detail || {};
|
|
24
|
+
if (!d.blockId) return;
|
|
25
|
+
if (d.value === null || d.value === undefined) delete state.blockEdits[d.blockId];
|
|
26
|
+
else state.blockEdits[d.blockId] = d.value;
|
|
27
|
+
});
|
|
28
|
+
function renderBlocks(container, blocks, questionId) {
|
|
29
|
+
if (!Array.isArray(blocks) || !blocks.length) return;
|
|
30
|
+
const target = el('div', { class: 'blocks' });
|
|
31
|
+
container.append(target);
|
|
32
|
+
if (!window.RelayBlocks) {
|
|
33
|
+
target.append(el('div', { class: 'blk' }, el('div', { class: 'blk-error' }, 'block failed to render')));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
Promise.resolve()
|
|
37
|
+
.then(() => window.RelayBlocks.render(target, blocks, blockCtx(questionId)))
|
|
38
|
+
.then(reportSize)
|
|
39
|
+
.catch(() => {
|
|
40
|
+
target.append(el('div', { class: 'blk' }, el('div', { class: 'blk-error' }, 'block failed to render')));
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// ======================================================================
|
|
2
|
+
// MCP Apps postMessage / JSON-RPC bridge
|
|
3
|
+
// ======================================================================
|
|
4
|
+
const pending = new Map();
|
|
5
|
+
let rpcSeq = 0;
|
|
6
|
+
const notifyHandlers = Object.create(null);
|
|
7
|
+
function onNotify(method, fn) {
|
|
8
|
+
(notifyHandlers[method] || (notifyHandlers[method] = [])).push(fn);
|
|
9
|
+
}
|
|
10
|
+
function post(msg) {
|
|
11
|
+
try {
|
|
12
|
+
(window.parent && window.parent !== window ? window.parent : window).postMessage(msg, '*');
|
|
13
|
+
} catch {
|
|
14
|
+
// host frame gone — nothing we can do
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function request(method, params) {
|
|
18
|
+
const id = 'rly-' + (++rpcSeq);
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
pending.set(id, { resolve, reject });
|
|
21
|
+
post({ jsonrpc: '2.0', id, method, params: params || {} });
|
|
22
|
+
// Don't hang forever if a host ignores a method — resolve-less reject.
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
if (pending.has(id)) {
|
|
25
|
+
pending.delete(id);
|
|
26
|
+
reject(new Error('timeout: ' + method));
|
|
27
|
+
}
|
|
28
|
+
}, 15000);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function notify(method, params) {
|
|
32
|
+
post({ jsonrpc: '2.0', method, params: params || {} });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
window.addEventListener('message', (e) => {
|
|
36
|
+
const msg = e.data;
|
|
37
|
+
if (!msg || typeof msg !== 'object' || msg.jsonrpc !== '2.0') return;
|
|
38
|
+
// A response to one of our requests.
|
|
39
|
+
if (msg.id !== undefined && msg.id !== null && (('result' in msg) || ('error' in msg))) {
|
|
40
|
+
const p = pending.get(msg.id);
|
|
41
|
+
if (!p) return;
|
|
42
|
+
pending.delete(msg.id);
|
|
43
|
+
if (msg.error) p.reject(Object.assign(new Error(msg.error.message || 'rpc error'), { rpc: msg.error }));
|
|
44
|
+
else p.resolve(msg.result);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// A notification or request FROM the host.
|
|
48
|
+
if (typeof msg.method === 'string') {
|
|
49
|
+
const hs = notifyHandlers[msg.method] || [];
|
|
50
|
+
for (const h of hs) {
|
|
51
|
+
try { h(msg.params || {}, msg); } catch { /* handler errors never break the bridge */ }
|
|
52
|
+
}
|
|
53
|
+
// Host requests we must acknowledge.
|
|
54
|
+
if (msg.id !== undefined && msg.id !== null) {
|
|
55
|
+
if (msg.method === 'ui/resource-teardown') post({ jsonrpc: '2.0', id: msg.id, result: {} });
|
|
56
|
+
else post({ jsonrpc: '2.0', id: msg.id, result: {} });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// ======================================================================
|
|
62
|
+
// theme + size
|
|
63
|
+
// ======================================================================
|
|
64
|
+
let host = {};
|
|
65
|
+
function effectiveTheme() {
|
|
66
|
+
if (host.theme === 'dark' || host.theme === 'light') return host.theme;
|
|
67
|
+
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
68
|
+
}
|
|
69
|
+
function applyTheme() {
|
|
70
|
+
const t = host.theme;
|
|
71
|
+
if (t === 'dark' || t === 'light') {
|
|
72
|
+
document.documentElement.dataset.theme = t;
|
|
73
|
+
// Pin color-scheme so the host's light-dark() style variables resolve to
|
|
74
|
+
// the side the host actually picked (not whatever the OS prefers).
|
|
75
|
+
document.documentElement.style.colorScheme = t;
|
|
76
|
+
} else {
|
|
77
|
+
delete document.documentElement.dataset.theme;
|
|
78
|
+
document.documentElement.style.colorScheme = 'light dark';
|
|
79
|
+
}
|
|
80
|
+
if (window.RelayBlocks && typeof RelayBlocks.onThemeChange === 'function') {
|
|
81
|
+
try { RelayBlocks.onThemeChange(effectiveTheme()); } catch { /* not rendered yet */ }
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Full color-blend: map the host's standardized style variables (SEP-1865
|
|
86
|
+
// theming) onto relay's own custom properties so the board adopts the app's
|
|
87
|
+
// surfaces, text, borders, primary-action color and fonts — reading as part of
|
|
88
|
+
// Claude/Codex rather than a foreign page. Every mapping is conditional: a
|
|
89
|
+
// token the host omits keeps relay's own default, so it degrades gracefully on
|
|
90
|
+
// leaner hosts (where the warm terracotta identity simply stays).
|
|
91
|
+
const HOST_VAR_MAP = {
|
|
92
|
+
'--bg': '--color-background-primary',
|
|
93
|
+
'--card': '--color-background-secondary',
|
|
94
|
+
'--bg-sunken': '--color-background-tertiary',
|
|
95
|
+
'--fg': '--color-text-primary',
|
|
96
|
+
'--fg-2': '--color-text-secondary',
|
|
97
|
+
'--muted': '--color-text-tertiary',
|
|
98
|
+
'--border': '--color-border-primary',
|
|
99
|
+
'--border-strong': '--color-border-secondary',
|
|
100
|
+
'--accent': '--color-background-inverse',
|
|
101
|
+
'--accent-hover': '--color-background-inverse',
|
|
102
|
+
'--accent-fg': '--color-text-inverse',
|
|
103
|
+
'--accent-soft': '--color-background-tertiary',
|
|
104
|
+
'--danger': '--color-text-danger',
|
|
105
|
+
'--ok': '--color-text-success',
|
|
106
|
+
'--sans': '--font-sans',
|
|
107
|
+
'--mono': '--font-mono',
|
|
108
|
+
};
|
|
109
|
+
let hostFontStyleEl = null;
|
|
110
|
+
function adoptHostStyles() {
|
|
111
|
+
const styles = host && host.styles;
|
|
112
|
+
if (!styles || typeof styles !== 'object') return;
|
|
113
|
+
const v = styles.variables && typeof styles.variables === 'object' ? styles.variables : {};
|
|
114
|
+
const root = document.documentElement.style;
|
|
115
|
+
for (const [ours, theirs] of Object.entries(HOST_VAR_MAP)) {
|
|
116
|
+
if (typeof v[theirs] === 'string' && v[theirs]) root.setProperty(ours, v[theirs]);
|
|
117
|
+
}
|
|
118
|
+
const fonts = styles.css && typeof styles.css.fonts === 'string' ? styles.css.fonts : '';
|
|
119
|
+
if (fonts) {
|
|
120
|
+
if (!hostFontStyleEl) { hostFontStyleEl = document.createElement('style'); document.head.appendChild(hostFontStyleEl); }
|
|
121
|
+
hostFontStyleEl.textContent = fonts;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Platform awareness: reflect the host's surface so the board (and CSS) can
|
|
126
|
+
// adapt — a data-platform hint, a touch flag, and the host's safe-area insets
|
|
127
|
+
// applied as padding so content clears notches / home indicators on mobile.
|
|
128
|
+
function applyHostEnv() {
|
|
129
|
+
const root = document.documentElement;
|
|
130
|
+
if (host.platform === 'web' || host.platform === 'desktop' || host.platform === 'mobile') {
|
|
131
|
+
root.dataset.platform = host.platform;
|
|
132
|
+
}
|
|
133
|
+
root.classList.toggle('mcp-touch', Boolean(host.deviceCapabilities && host.deviceCapabilities.touch));
|
|
134
|
+
const sai = host.safeAreaInsets;
|
|
135
|
+
if (sai && typeof sai === 'object') {
|
|
136
|
+
const px = (n) => (Number.isFinite(n) ? n : 0) + 'px';
|
|
137
|
+
root.style.setProperty('--mcp-safe-top', px(sai.top));
|
|
138
|
+
root.style.setProperty('--mcp-safe-right', px(sai.right));
|
|
139
|
+
root.style.setProperty('--mcp-safe-bottom', px(sai.bottom));
|
|
140
|
+
root.style.setProperty('--mcp-safe-left', px(sai.left));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
let sizeTimer = null;
|
|
145
|
+
function measureHeight() {
|
|
146
|
+
return Math.max(document.documentElement.scrollHeight, document.body ? document.body.scrollHeight : 0);
|
|
147
|
+
}
|
|
148
|
+
function sendSize() {
|
|
149
|
+
notify('ui/notifications/size-changed', { width: document.documentElement.scrollWidth, height: measureHeight() });
|
|
150
|
+
}
|
|
151
|
+
function reportSize() {
|
|
152
|
+
if (sizeTimer) return;
|
|
153
|
+
sizeTimer = setTimeout(() => { sizeTimer = null; sendSize(); }, 60);
|
|
154
|
+
}
|
|
155
|
+
// Immediate, un-debounced report — used when the board shrinks (e.g. after
|
|
156
|
+
// submit) so the host collapses the iframe right away instead of waiting.
|
|
157
|
+
function reportSizeNow() {
|
|
158
|
+
if (sizeTimer) { clearTimeout(sizeTimer); sizeTimer = null; }
|
|
159
|
+
sendSize();
|
|
160
|
+
}
|
|
161
|
+
window.addEventListener('resize', reportSize);
|
|
162
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
163
|
+
try { new ResizeObserver(reportSize).observe(document.documentElement); } catch { /* older host */ }
|
|
164
|
+
}
|
|
165
|
+
|
|
@@ -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
|
+
})();
|