@floless/app 0.154.0 → 0.155.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.
Files changed (47) hide show
  1. package/dist/floless-server.cjs +49492 -37984
  2. package/dist/schemas/steel.model.v2.schema.json +19 -5
  3. package/dist/skills/floless-app-onboarding/SKILL.md +22 -13
  4. package/dist/skills/floless-app-onboarding/references/floless-surfaces.md +12 -8
  5. package/dist/skills/floless-app-steel-model/SKILL.md +23 -2
  6. package/dist/skills/floless-app-steel-takeoff/SKILL.md +158 -65
  7. package/dist/skills/floless-app-workflows/SKILL.md +23 -5
  8. package/dist/skills/floless-app-workflows/references/blender-exec.md +183 -0
  9. package/dist/skills/floless-app-workflows/references/dev-server-and-run-trace.md +27 -12
  10. package/dist/templates/blender-construction-sequence.flo +96 -0
  11. package/dist/web/agents.js +33 -13
  12. package/dist/web/app.css +275 -33
  13. package/dist/web/aware.js +745 -82
  14. package/dist/web/chat-question-card.js +477 -0
  15. package/dist/web/chat.css +177 -12
  16. package/dist/web/chat.js +1537 -717
  17. package/dist/web/commands-shell.js +424 -7
  18. package/dist/web/commands-steel.js +105 -4
  19. package/dist/web/guide.js +4 -3
  20. package/dist/web/index.html +96 -7
  21. package/dist/web/instructor.js +10 -9
  22. package/dist/web/left-pane.js +40 -3
  23. package/dist/web/media-player.js +234 -0
  24. package/dist/web/model-editor-contract.js +2 -0
  25. package/dist/web/model-editor-revit-adapter.js +1 -0
  26. package/dist/web/model-editor-steel-adapter.js +89 -1
  27. package/dist/web/model-panel-bridge.js +16 -2
  28. package/dist/web/model-view-query.js +590 -0
  29. package/dist/web/model-viewport-revit-adapter.js +15 -1
  30. package/dist/web/model-viewport-toolbar.js +5 -2
  31. package/dist/web/pages.js +592 -0
  32. package/dist/web/panels.js +2 -1
  33. package/dist/web/revit-editor.js +181 -16
  34. package/dist/web/run-progress.js +193 -0
  35. package/dist/web/run-strip.js +173 -0
  36. package/dist/web/steel-3d-core.js +70 -0
  37. package/dist/web/steel-editor.html +2751 -219
  38. package/dist/web/steel-frames-core.js +958 -0
  39. package/dist/web/steel-last-seen.js +315 -0
  40. package/dist/web/steel-marks-core.js +530 -0
  41. package/dist/web/steel-model-slim.js +95 -0
  42. package/dist/web/steel-model-v2-client-validation.js +14 -2
  43. package/dist/web/steel-model-v2-commands.js +258 -27
  44. package/dist/web/steel-model-v2-projection.js +78 -18
  45. package/dist/web/steel-read-confidence.js +11 -2
  46. package/dist/web/workspaces.js +416 -26
  47. package/package.json +3 -2
@@ -0,0 +1,477 @@
1
+ /* ──────────────────────────────────────────────────────────────────────────
2
+ #2223 — the AI's question card, a shared component.
3
+
4
+ Owner ruling 2026-10-12: "when AI asks something, it always should give a card
5
+ with answers (first is always recommendation) and Other.. at the end so user
6
+ can type other answer - exactly same as Claude is doing". The card shows one
7
+ question at a time ("1 of 3" when the AI asked several): a small header chip,
8
+ the question, the AI's answers as numbered rows (each with its one-line
9
+ description, the recommended one first and marked), and a last row Other…
10
+ that opens a box to type an answer of one's own, with a paperclip (paste and
11
+ drop work too). Number keys pick a row, Up/Down move, Enter chooses. A single
12
+ single-choice question sends as soon as an answer is chosen, as Claude does;
13
+ several questions, or a multi-choice one, end with Submit.
14
+
15
+ It is a component on purpose (#2239: the Drawing Filter cards move onto it):
16
+ it owns no server call and no state of its own. The caller keeps the DRAFT
17
+ (createDraft) across repaints, repaints it with paint(), and is told
18
+ onSubmit(). Every control carries an Instructor id under shell.chat-ask-*,
19
+ keyed by the card's id and opaque local indexes, never a provider string.
20
+ ────────────────────────────────────────────────────────────────────────── */
21
+ (function () {
22
+ 'use strict';
23
+
24
+ /** The AI's options in the order the card shows them: the recommended one first, then the rest in the AI's order. */
25
+ function order(question) {
26
+ const all = question.options.map((_, index) => index);
27
+ const first = Number.isInteger(question.recommended) ? question.recommended : null;
28
+ return first === null ? all : [first, ...all.filter((index) => index !== first)];
29
+ }
30
+
31
+ /** A fresh draft for a card: per question, the chosen option indexes and the person's own answer. */
32
+ function createDraft(questions) {
33
+ return {
34
+ step: 0,
35
+ rows: questions.map(() => ({ choices: [], other: '', otherOpen: false })),
36
+ /** Which row of the current step has keyboard focus, as a position in the shown order (Other is last). */
37
+ cursor: 0,
38
+ };
39
+ }
40
+
41
+ /** Whether one question has an answer: an option, or the person's own words, or a file on their own answer. */
42
+ function answered(question, row, files) {
43
+ const own = row.otherOpen && (row.other.trim() || files > 0);
44
+ return question.multiSelect ? row.choices.length > 0 || Boolean(own) : row.choices.length === 1 || Boolean(own);
45
+ }
46
+
47
+ /** What the server is sent: per question id, the option indexes and the person's own answer and files. */
48
+ function answersFor(questions, draft, filesOf) {
49
+ const out = {};
50
+ questions.forEach((question, index) => {
51
+ const row = draft.rows[index];
52
+ const files = row.otherOpen ? filesOf(index) : [];
53
+ const other = row.otherOpen ? row.other.trim() : '';
54
+ const entry = { choices: [...row.choices].sort((a, b) => a - b) };
55
+ if (other) entry.other = other;
56
+ if (files.length) entry.files = files.map((file) => file.attachmentId);
57
+ Object.defineProperty(out, question.id, { value: entry, enumerable: true, writable: true, configurable: true });
58
+ });
59
+ return out;
60
+ }
61
+
62
+ /** How long after arrival the choosing keys wait (Enter, Space, digits). */
63
+ const ARM_MS = 400;
64
+
65
+ const PAPERCLIP = 'm16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551';
66
+
67
+ function el(tag, className, text) {
68
+ const node = document.createElement(tag);
69
+ if (className) node.className = className;
70
+ if (text !== undefined) node.textContent = text;
71
+ return node;
72
+ }
73
+
74
+ function control(tag, commandId, instance, className, text) {
75
+ const node = el(tag, className, text);
76
+ if (tag === 'button') node.type = 'button';
77
+ if (commandId && typeof commandId === 'object') {
78
+ instance = commandId.instance || instance;
79
+ commandId = commandId.id;
80
+ }
81
+ node.dataset.commandId = commandId;
82
+ if (instance) node.dataset.commandInstanceLabel = instance;
83
+ return node;
84
+ }
85
+
86
+ /** Disabled the way every FloLess control is: still focusable and explainable, its reason on hover and to `?`. */
87
+ function block(node, reason) {
88
+ if (!reason) return;
89
+ node.setAttribute('aria-disabled', 'true');
90
+ node.dataset.blockedReason = reason;
91
+ node.dataset.tip = reason;
92
+ }
93
+
94
+ /**
95
+ * Paint the card into `card` (a section the caller keeps, so the arrival ring does not restart on every repaint).
96
+ * opts: {
97
+ * id, questions, draft,
98
+ * busy: a sentence while an answer is on its way (every control waits), or '',
99
+ * error: the last refusal, in words, or '',
100
+ * files: { list(q) → [{ attachmentId, fileName, url }], uploading(q) → n, error(q) → '', attach(q, files),
101
+ * remove(q, file), max } — optional; without it the Other… box has no paperclip,
102
+ * otherHint: what the Other… row says under its name, when not the default (optional),
103
+ * repaint(), submit(),
104
+ * }
105
+ */
106
+ function paint(card, opts) {
107
+ const { id, questions, draft } = opts;
108
+ const step = Math.max(0, Math.min(draft.step, questions.length - 1));
109
+ draft.step = step;
110
+ const question = questions[step];
111
+ const row = draft.rows[step];
112
+ const files = opts.files;
113
+ const fileCount = (index) => (files ? files.list(index).length : 0);
114
+ const busy = opts.busy || (draft.pending ? 'Saving your answer…' : '');
115
+ const perStep = opts.mode === 'per-step';
116
+ const single = questions.length === 1 && !question.multiSelect;
117
+ const last = step === questions.length - 1;
118
+ const shown = order(question);
119
+ const key = (what, extra) => opts.carrier ? opts.carrier(what, step, extra)
120
+ : `shell.chat-ask-${what}#${id} ${step}${extra === undefined ? '' : ` ${extra}`}`;
121
+ const selected = () => question.options[row.choices[0]];
122
+ const needsConfirm = () => question.confirmSelection || Boolean(selected()?.statement || selected()?.requiresNote);
123
+ function refusal() {
124
+ if (perStep && files?.uploading(step)) return 'Wait for the picture to finish attaching.';
125
+ if (selected()?.requiresNote && !row.reason?.trim()) return 'Add a short note first, so the read knows what to do instead.';
126
+ return opts.validate ? opts.validate(step, draft) || '' : '';
127
+ }
128
+ async function advance() {
129
+ if (busy || draft.pending) return;
130
+ const error = refusal();
131
+ if (error) { draft.error = error; opts.repaint(); return; }
132
+ if (!answered(question, row, fileCount(step)) && !(perStep && opts.validate)) return;
133
+ if (perStep) {
134
+ const answer = answersFor([question], { rows: [row] }, () => files ? files.list(step) : [])[question.id];
135
+ if (row.reason?.trim()) answer.reason = row.reason.trim();
136
+ draft.pending = true; draft.error = '';
137
+ let saved = false;
138
+ try {
139
+ // The caller can capture the original editable field before its busy paint replaces it.
140
+ const pendingSave = opts.commitStep(step, answer);
141
+ opts.repaint();
142
+ saved = await pendingSave;
143
+ }
144
+ catch (error) { draft.error = error?.message || 'FloLess could not save this answer. Try again.'; }
145
+ finally { draft.pending = false; }
146
+ if (saved !== false && saved !== undefined && !last) { draft.step = step + 1; draft.cursor = 0; }
147
+ opts.repaint(); return;
148
+ }
149
+ if (single || last) { opts.submit(); return; }
150
+ draft.step = step + 1; draft.cursor = 0; opts.repaint();
151
+ }
152
+
153
+ card.classList.add('ai-chat-ask');
154
+ card.setAttribute('role', 'group');
155
+ if (busy) card.setAttribute('aria-busy', 'true');
156
+ else card.removeAttribute('aria-busy');
157
+ for (const node of [...card.children]) if (!node.classList.contains('ai-chat-approval-flo')) node.remove();
158
+
159
+ const head = el('div', 'ai-chat-ask-head');
160
+ if (question.header) head.append(el('span', 'ai-chat-ask-chip', question.header));
161
+ if (questions.length > 1) head.append(el('span', 'ai-chat-ask-step', `${step + 1} of ${questions.length}`));
162
+ else if (question.progress) head.append(el('span', 'ai-chat-ask-step', `${question.progress.index + 1} of ${question.progress.total}`));
163
+ const text = el('p', 'ai-chat-ask-question', question.question);
164
+ text.id = `chat-ask-question-${id}-${step}`;
165
+ card.setAttribute('aria-labelledby', text.id);
166
+
167
+ // A listbox, not a radiogroup: arrow keys only move here, and choosing an answer may send it (UX review).
168
+ const list = el('div', 'ai-chat-ask-options');
169
+ list.setAttribute('role', 'listbox');
170
+ if (question.multiSelect) list.setAttribute('aria-multiselectable', 'true');
171
+ list.setAttribute('aria-labelledby', text.id);
172
+ const rows = [];
173
+ shown.forEach((optionIndex, position) => {
174
+ const option = question.options[optionIndex];
175
+ const chosen = row.choices.includes(optionIndex);
176
+ const recommended = optionIndex === question.recommended && question.options.length > 1;
177
+ const button = control('button', key('option', optionIndex), option.shown,
178
+ `ai-chat-ask-option${chosen ? ' is-chosen' : ''}${recommended ? ' is-recommended' : ''}`);
179
+ button.setAttribute('role', 'option');
180
+ button.setAttribute('aria-selected', String(chosen));
181
+ const number = el('span', 'ai-chat-ask-key', String(position + 1));
182
+ number.setAttribute('aria-hidden', 'true');
183
+ const body = el('span', 'ai-chat-ask-text');
184
+ const label = el('span', 'ai-chat-ask-label', option.shown);
185
+ // A label that had to keep its own "(Recommended)" (stripping it would have matched another answer) is not marked twice.
186
+ if (recommended && !/\(\s*recommended\s*\)\s*$/iu.test(option.shown)) label.append(el('span', 'ai-chat-ask-rec', ' (Recommended)'));
187
+ body.append(label);
188
+ if (option.tag) body.append(el('span', 'ai-chat-ask-chip ai-chat-ask-tag', option.tag));
189
+ if (option.description) {
190
+ const description = el('span', 'ai-chat-ask-desc', option.description);
191
+ // Clamped to two lines in a short panel; the whole of it is one hover away, never cut silently.
192
+ description.dataset.tip = option.description;
193
+ body.append(description);
194
+ }
195
+ button.append(number, body);
196
+ if (question.multiSelect) {
197
+ const box = el('span', 'ai-chat-ask-box');
198
+ box.setAttribute('aria-hidden', 'true');
199
+ button.append(box);
200
+ }
201
+ block(button, busy);
202
+ button.addEventListener('click', () => {
203
+ if (busy) return;
204
+ draft.cursor = position;
205
+ if (question.multiSelect) {
206
+ row.choices = chosen ? row.choices.filter((value) => value !== optionIndex) : [...row.choices, optionIndex];
207
+ opts.repaint();
208
+ return;
209
+ }
210
+ // One answer per single-choice question: choosing an option sets aside the person's own answer.
211
+ row.choices = [optionIndex];
212
+ row.otherOpen = false;
213
+ if (needsConfirm()) { opts.repaint(); return; }
214
+ if (perStep || single) { void advance(); return; }
215
+ if (!last) { draft.step = step + 1; draft.cursor = 0; }
216
+ opts.repaint();
217
+ });
218
+ rows.push(button);
219
+ });
220
+ const otherPosition = shown.length;
221
+ const other = control('button', key('other'), 'Other', `ai-chat-ask-option ai-chat-ask-other-row${row.otherOpen ? ' is-chosen' : ''}`);
222
+ other.setAttribute('role', 'option');
223
+ other.setAttribute('aria-selected', String(row.otherOpen));
224
+ const otherKey = el('span', 'ai-chat-ask-key', String(otherPosition + 1));
225
+ otherKey.setAttribute('aria-hidden', 'true');
226
+ const otherBody = el('span', 'ai-chat-ask-text');
227
+ otherBody.append(el('span', 'ai-chat-ask-label', 'Other…'),
228
+ el('span', 'ai-chat-ask-desc', opts.otherHint || (files ? 'Type your own answer, or attach a screenshot or PDF' : 'Type your own answer')));
229
+ other.append(otherKey, otherBody);
230
+ if (question.multiSelect) { const box = el('span', 'ai-chat-ask-box'); box.setAttribute('aria-hidden', 'true'); other.append(box); }
231
+ block(other, busy);
232
+ other.addEventListener('click', () => {
233
+ if (busy) return;
234
+ draft.cursor = otherPosition;
235
+ if (question.multiSelect && row.otherOpen) { row.otherOpen = false; opts.repaint(); return; }
236
+ row.otherOpen = true;
237
+ if (!question.multiSelect) row.choices = [];
238
+ opts.repaint();
239
+ card.querySelector('.ai-chat-ask-other-input')?.focus({ preventScroll: true });
240
+ });
241
+ if (question.allowOther !== false) rows.push(other);
242
+ list.append(...rows);
243
+ if (question.multiSelect) {
244
+ const groups = [...new Set(question.options.map((option) => option.group).filter(Boolean))];
245
+ groups.forEach((group, index) => {
246
+ const members = shown.filter((optionIndex) => question.options[optionIndex].group === group);
247
+ const all = members.every((optionIndex) => row.choices.includes(optionIndex));
248
+ const heading = el('div', 'ai-chat-height-group');
249
+ heading.append(el('span', 'ai-chat-height-group-name', group));
250
+ const toggle = control('button', key('group', index), group, 'ai-chat-height-change', all ? 'Clear group' : 'Select group');
251
+ block(toggle, busy);
252
+ toggle.addEventListener('click', () => { if (busy) return;
253
+ row.choices = all ? row.choices.filter((value) => !members.includes(value)) : [...new Set([...row.choices, ...members])]; opts.repaint(); });
254
+ heading.append(toggle); list.insertBefore(heading, rows[shown.indexOf(members[0])]);
255
+ });
256
+ }
257
+
258
+ let box = null;
259
+ if (row.otherOpen) {
260
+ box = el('div', 'ai-chat-ask-other');
261
+ const line = el('div', 'ai-chat-ask-other-line');
262
+ const input = control('input', key('other-input'), question.header || 'your answer', 'ai-chat-ask-other-input');
263
+ input.type = 'text'; input.autocomplete = 'off'; input.maxLength = 1000; input.spellcheck = true;
264
+ input.placeholder = 'Type your answer';
265
+ input.setAttribute('aria-label', `Your own answer to: ${question.question}`);
266
+ input.value = row.other;
267
+ if (busy) input.readOnly = true;
268
+ block(input, busy);
269
+ input.addEventListener('input', () => {
270
+ row.other = input.value;
271
+ // No repaint while typing (the caret stays); only the buttons that depend on it change.
272
+ refreshActions();
273
+ });
274
+ input.addEventListener('keydown', (event) => {
275
+ if (event.key !== 'Enter' || event.shiftKey || event.isComposing) return;
276
+ event.preventDefault();
277
+ if (event.repeat) return;
278
+ if (busy || (!answered(question, row, fileCount(step)) && !(perStep && opts.validate && !refusal()))) return;
279
+ const everyone = questions.every((q, index) => answered(q, draft.rows[index], fileCount(index)));
280
+ if (perStep || (everyone && (single || last))) { void advance(); return; }
281
+ // Not finished: the next question still waiting for an answer (R7).
282
+ const next = questions.findIndex((q, index) => index !== step && !answered(q, draft.rows[index], fileCount(index)));
283
+ draft.step = next >= 0 ? next : questions.length - 1;
284
+ draft.cursor = 0;
285
+ opts.repaint();
286
+ });
287
+ line.append(input);
288
+ if (files && !opts.source) {
289
+ const clip = control('button', key('attach'), question.header || 'your answer', 'ai-chat-answer-clip ai-chat-ask-clip');
290
+ clip.setAttribute('aria-label', 'Attach a screenshot or PDF to your answer');
291
+ clip.dataset.tip = 'Attach a screenshot or PDF (you can also paste or drop it here)';
292
+ const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
293
+ svg.setAttribute('viewBox', '0 0 24 24'); svg.setAttribute('aria-hidden', 'true'); svg.setAttribute('focusable', 'false');
294
+ const path = document.createElementNS('http://www.w3.org/2000/svg', 'path'); path.setAttribute('d', PAPERCLIP);
295
+ svg.append(path); clip.append(svg);
296
+ const picker = control('input', key('attach-input'), question.header || 'your answer');
297
+ picker.type = 'file'; picker.multiple = true; picker.hidden = true; picker.accept = 'image/png,image/jpeg,image/webp,application/pdf';
298
+ picker.addEventListener('change', () => { const chosen = [...picker.files]; picker.value = ''; files.attach(step, chosen); });
299
+ const full = fileCount(step) >= files.max;
300
+ block(clip, busy || (full ? `An answer can carry at most ${files.max} files` : ''));
301
+ clip.addEventListener('click', () => { if (clip.getAttribute('aria-disabled') !== 'true') picker.click(); });
302
+ line.append(clip, picker);
303
+ // Paste and drop, like the message box: a screenshot pasted while this box has focus attaches to the answer.
304
+ box.addEventListener('paste', (event) => {
305
+ const pasted = [...(event.clipboardData?.files || [])];
306
+ if (pasted.length && !busy) { event.preventDefault(); files.attach(step, pasted); }
307
+ });
308
+ box.addEventListener('dragover', (event) => { if (event.dataTransfer?.types?.includes('Files')) { event.preventDefault(); box.classList.add('drop'); } });
309
+ box.addEventListener('dragleave', () => box.classList.remove('drop'));
310
+ box.addEventListener('drop', (event) => {
311
+ box.classList.remove('drop');
312
+ const dropped = [...(event.dataTransfer?.files || [])];
313
+ // Focus stays in this box, as after a paste or the paperclip, so the repaint keeps the new chip in sight.
314
+ if (dropped.length && !busy) { event.preventDefault(); input.focus({ preventScroll: true }); files.attach(step, dropped); }
315
+ });
316
+ }
317
+ box.append(line);
318
+ if (files && !opts.source) {
319
+ const attached = files.list(step);
320
+ const uploading = files.uploading(step);
321
+ if (attached.length || uploading) {
322
+ const chips = el('div', 'ai-chat-answer-files ai-chat-ask-files');
323
+ attached.forEach((file, index) => {
324
+ const chip = el('span', 'ai-chat-attachment');
325
+ if (file.url) { const img = el('img'); img.alt = ''; img.src = file.url; chip.append(img); }
326
+ chip.append(el('span', '', file.fileName));
327
+ const remove = control('button', key('file-remove', index), file.fileName, '', '×');
328
+ remove.setAttribute('aria-label', `Remove ${file.fileName} from your answer`);
329
+ remove.dataset.tip = 'Remove from your answer';
330
+ block(remove, busy);
331
+ remove.addEventListener('click', () => { if (!busy) files.remove(step, file); });
332
+ chip.append(remove);
333
+ chips.append(chip);
334
+ });
335
+ if (uploading) { const status = el('span', 'ai-chat-answer-lead', 'Attaching…'); status.setAttribute('role', 'status'); chips.append(status); }
336
+ box.append(chips);
337
+ }
338
+ const fileError = files.error(step);
339
+ if (fileError) { const warn = el('p', 'ai-chat-ask-error', fileError); warn.setAttribute('role', 'alert'); box.append(warn); }
340
+ }
341
+ }
342
+
343
+ const actions = el('div', 'ai-chat-ask-actions');
344
+ if (question.allowClear && question.multiSelect) {
345
+ const clear = control('button', key('clear'), question.header || 'the selected ends', 'ai-chat-ask-back', 'Clear selection');
346
+ block(clear, busy); clear.addEventListener('click', () => { if (busy) return; row.choices = []; opts.repaint(); }); actions.append(clear);
347
+ }
348
+ let back = null;
349
+ if (step > 0 || opts.back) {
350
+ back = control('button', key('back'), `question ${step + 1}`, 'ai-chat-ask-back', 'Back');
351
+ back.setAttribute('aria-label', opts.back ? 'Back to the previous item' : `Back to question ${step}`);
352
+ block(back, busy);
353
+ back.addEventListener('click', () => { if (busy) return; if (opts.back) { opts.back(); return; } draft.step = step - 1; draft.cursor = 0; opts.repaint(); });
354
+ actions.append(back);
355
+ }
356
+ // A single single-choice question sends as soon as an option is chosen; its button is only for an answer of one's own.
357
+ const needsButton = !single || row.otherOpen || needsConfirm();
358
+ const finishing = last || single;
359
+ let primary = null;
360
+ if (needsButton) {
361
+ primary = control('button', opts.carrier ? key('send') : finishing ? `shell.chat-ask-send#${id}` : key('next'), finishing ? 'the answers' : `question ${step + 1}`,
362
+ 'allow ai-chat-ask-primary', busy || selected()?.confirmLabel || question.confirmLabel || (finishing ? 'Submit' : 'Next'));
363
+ primary.addEventListener('click', () => {
364
+ if (primary.getAttribute('aria-disabled') === 'true') return;
365
+ void advance();
366
+ });
367
+ actions.append(primary);
368
+ }
369
+ function refreshActions() {
370
+ if (!primary) return;
371
+ if (opts.carrier) {
372
+ const carrier = key('send');
373
+ primary.dataset.commandId = typeof carrier === 'object' ? carrier.id : carrier;
374
+ if (carrier.instance) primary.dataset.commandInstanceLabel = carrier.instance;
375
+ }
376
+ const done = questions.every((q, index) => answered(q, draft.rows[index], fileCount(index)));
377
+ const here = answered(question, row, fileCount(step)) || Boolean(perStep && opts.validate && !refusal());
378
+ const reason = busy || refusal() || (perStep ? (here ? '' : 'Answer this question first') : finishing
379
+ ? (done ? '' : questions.length > 1 ? 'Answer every question first' : 'Choose an answer, or type your own')
380
+ : (here ? '' : 'Answer this question first'));
381
+ primary.removeAttribute('aria-disabled'); delete primary.dataset.blockedReason; delete primary.dataset.tip;
382
+ block(primary, reason);
383
+ }
384
+ refreshActions();
385
+
386
+ if (busy) {
387
+ // Said in words (and to a screen reader), never only by greying the card out.
388
+ const status = el('span', 'ai-chat-ask-status', busy);
389
+ status.setAttribute('role', 'status');
390
+ actions.prepend(status);
391
+ }
392
+ // Mouse first, then the keys (UX review): it says what a click does here, since a single question sends at once.
393
+ const keys = `1-${otherPosition + 1}`;
394
+ const hint = el('p', 'ai-chat-ask-hint', question.hint || (perStep
395
+ ? question.multiSelect ? 'Tick the ends that should share an answer, then Submit.'
396
+ : needsConfirm() ? 'Choose an option, check it, then use the confirmation below.'
397
+ : question.allowOther === false ? 'Choose an answer to save it.'
398
+ : !question.options.length ? 'Choose Other… to type your answer or attach a source, then Submit.'
399
+ : 'Choose an answer to save it, or choose Other… and then Submit.'
400
+ : question.multiSelect
401
+ ? `Tick all that apply, then ${finishing ? 'Submit' : 'Next'}. Keys ${keys} tick too.`
402
+ : single ? `Click an answer to send it, or press ${keys}.`
403
+ : last ? `Click an answer, then Submit. Keys ${keys} choose too.` : `Click an answer to go on, or press ${keys}.`));
404
+ hint.setAttribute('aria-hidden', 'true');
405
+
406
+ if (question.layout === 'grid') list.classList.add('ai-chat-ask-grid');
407
+ card.append(head, text);
408
+ for (const context of question.context || []) card.append(el('p', 'ai-chat-filter-note ai-chat-ask-context', context));
409
+ card.append(list);
410
+ if (selected()?.statement) { const statement = el('p', 'ai-chat-setup-statement ai-chat-ask-statement', selected().statement); statement.setAttribute('role', 'status'); card.append(statement); }
411
+ if (selected()?.requiresNote) {
412
+ const field = control('input', key('reason'), question.header || 'your reason', 'ai-chat-ask-other-input ai-chat-ask-reason-input');
413
+ field.type = 'text'; field.placeholder = selected().requiresNote.placeholder || 'Add a short note';
414
+ field.maxLength = selected().requiresNote.max || 160; field.value = row.reason || '';
415
+ field.id = `chat-ask-reason-${id}-${step}`;
416
+ field.setAttribute('aria-label', `Why: ${selected().shown}`); field.readOnly = Boolean(busy);
417
+ block(field, busy);
418
+ field.addEventListener('input', () => { row.reason = field.value; refreshActions(); });
419
+ field.addEventListener('keydown', (event) => { if (event.key === 'Enter' && !event.isComposing) { event.preventDefault(); if (!event.repeat) void advance(); } });
420
+ const label = el('label', 'ai-chat-ask-reason-label', 'Reason (required)'); label.htmlFor = field.id;
421
+ card.append(label, field);
422
+ }
423
+ if (opts.source) { const source = opts.source(step, refreshActions); if (source) (box || card).append(source); }
424
+ if (box && opts.source && files) {
425
+ box.addEventListener('paste', (event) => { if (event.defaultPrevented || busy) return; const attached = [...(event.clipboardData?.files || [])]; if (attached.length) { event.preventDefault(); files.attach(step, attached); } });
426
+ box.addEventListener('dragover', (event) => { if (event.dataTransfer?.types?.includes('Files')) { event.preventDefault(); box.classList.add('drop'); } });
427
+ box.addEventListener('dragleave', () => box.classList.remove('drop'));
428
+ box.addEventListener('drop', (event) => { box.classList.remove('drop'); if (event.defaultPrevented || busy) return; const attached = [...(event.dataTransfer?.files || [])]; if (attached.length) { event.preventDefault(); files.attach(step, attached); } });
429
+ }
430
+ if (box) card.append(box);
431
+ if (opts.error || draft.error) { const warn = el('p', 'ai-chat-ask-error', opts.error || draft.error); warn.setAttribute('role', 'alert'); card.append(warn); }
432
+ card.append(hint);
433
+ // Last, so it can stick to the bottom of the tray in a short panel.
434
+ if (actions.childElementCount) card.append(actions);
435
+
436
+ // Roving focus: one tab stop for the rows, Up/Down move, number keys choose.
437
+ rows.forEach((button, position) => { button.tabIndex = position === Math.min(draft.cursor, rows.length - 1) ? 0 : -1; });
438
+ // The card arrives with focus on the recommended answer: a key already on its way (an Enter that sent the person's
439
+ // last message) must not choose for them, so choosing keys wait a moment after arrival.
440
+ if (!card.dataset.armedAt) card.dataset.armedAt = String(Date.now() + ARM_MS);
441
+ if (card.askKeydown) card.removeEventListener('keydown', card.askKeydown);
442
+ card.askKeydown = (event) => {
443
+ const choosing = event.key === 'Enter' || event.key === ' ' || /^[1-9]$/.test(event.key);
444
+ const typing = event.target instanceof HTMLElement && event.target.matches('input, textarea, [contenteditable="true"]');
445
+ if (event.repeat) { if (choosing && !typing) event.preventDefault(); return; }
446
+ if (busy || event.altKey || event.ctrlKey || event.metaKey) return;
447
+ if (typing) return;
448
+ if (choosing && Date.now() < Number(card.dataset.armedAt)) { event.preventDefault(); return; }
449
+ const at = rows.indexOf(document.activeElement);
450
+ if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || (question.layout === 'grid' && (event.key === 'ArrowLeft' || event.key === 'ArrowRight'))) {
451
+ event.preventDefault();
452
+ const from = at >= 0 ? at : draft.cursor;
453
+ const next = (from + (event.key === 'ArrowDown' || event.key === 'ArrowRight' ? 1 : -1) + rows.length) % rows.length;
454
+ draft.cursor = next;
455
+ rows.forEach((button, position) => { button.tabIndex = position === next ? 0 : -1; });
456
+ rows[next].focus({ preventScroll: true });
457
+ rows[next].scrollIntoView?.({ block: 'nearest' }); // the cursor never lands on a row nobody can see
458
+ return;
459
+ }
460
+ if (/^[1-9]$/.test(event.key)) {
461
+ const position = Number(event.key) - 1;
462
+ if (position < rows.length) { event.preventDefault(); rows[position].click(); }
463
+ }
464
+ };
465
+ card.addEventListener('keydown', card.askKeydown);
466
+ return card;
467
+ }
468
+
469
+ /** Put keyboard focus on the row the cursor names (the recommended answer when the card arrives). */
470
+ function focusCursor(card) {
471
+ const rows = [...card.querySelectorAll('.ai-chat-ask-option')];
472
+ const target = rows.find((button) => button.tabIndex === 0) || rows[0];
473
+ target?.focus({ preventScroll: true });
474
+ }
475
+
476
+ window.FlolessQuestionCard = { order, createDraft, answered, answersFor, paint, focusCursor };
477
+ })();