@floless/app 0.147.0 → 0.148.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/dist/web/chat.js CHANGED
@@ -5,6 +5,12 @@
5
5
  if (!shell) return;
6
6
 
7
7
  const el = (id) => document.getElementById(id);
8
+ /**
9
+ * What the composer says when a message typed on the Drawing Filter will go to a waiting read (#1776).
10
+ * Painted BEFORE Send, over a draft, so it says where the message WILL go — never "Sent to …", which
11
+ * claimed delivery of something not yet sent.
12
+ */
13
+ const READ_REPLY_HINT = 'Your reply will go to the drawing read, which is waiting on your answer.';
8
14
  const ui = {
9
15
  historyToggle: el('chat-history-toggle'), newChat: el('chat-new'), refresh: el('chat-refresh'), history: el('chat-history'),
10
16
  title: el('chat-title'), rename: el('chat-rename'), scope: el('chat-scope'), settingsToggle: el('chat-settings-toggle'),
@@ -31,6 +37,8 @@
31
37
  draftTimer: null, localDraft: null, backgroundDrafts: new Map(), draftWrites: new Map(), draftVersions: new Map(), unknownFollowups: new Map(), refreshTimer: null, scopeGeneration: 0, selectionGeneration: 0, choosingProvider: false,
32
38
  answerJump: null, answerJumpTimer: null, scopeInitialized: false, renaming: null, historyRename: null, pendingSubmissionId: null, recoveryMessage: null, recoveryCanEnd: false,
33
39
  stream: null, liveStatusTurnId: null, decidingApprovalIds: new Set(), revokingApprovalTurns: new Set(), uploadingChatIds: new Set(),
40
+ // #1653 stage 4: the project's questions linked to live Tekla parts, the card's open lists, and the receipt showing it.
41
+ teklaLinks: { projectId: null, state: 'idle', links: [], partial: false, inflight: false, again: false }, teklaHistoryUi: {}, teklaHistoryHost: null,
34
42
  // Latched so the 5 s account poll logs an outage once instead of twelve times a minute; cleared
35
43
  // on the next successful read, so a later, separate outage is logged too.
36
44
  accountReadWarned: false,
@@ -451,6 +459,9 @@
451
459
  ? 'Check the last AI response before continuing.'
452
460
  : !state.scope?.owner
453
461
  ? 'Open a project or workflow to start chatting.'
462
+ // #1776: on the Drawing Filter, the one place a message would otherwise go to its own AI.
463
+ : paintFilterComposer().replyToRead
464
+ ? READ_REPLY_HINT
454
465
  : 'Enter to send · Shift+Enter for a new line';
455
466
  if (turnIsVisiblyActive() && !state.followupUnknownId && !hasUnknownFollowup()
456
467
  && state.imageLimitChatId !== state.chat?.chatId) {
@@ -580,11 +591,13 @@
580
591
  ? floLessContextLabel(currentFloLessContext())
581
592
  : filter.state === 'ready' ? `Drawing Filter · partial view of ${filter.summary.sheet || 'this sheet'} and its selection`
582
593
  : 'Drawing Filter · loading…';
594
+ // #1776: where the message goes, when that is not where this surface would send it.
595
+ const destination = filter.replyToRead ? `${READ_REPLY_HINT} ` : '';
583
596
  // A live region: rewritten only when the text changes, or every keystroke would re-announce it.
584
- if (ui.contextNote.textContent !== `Sharing with AI: ${shared}`) {
597
+ if (ui.contextNote.textContent !== `${destination}Sharing with AI: ${shared}`) {
585
598
  const prefix = document.createElement('strong');
586
599
  prefix.textContent = 'Sharing with AI: ';
587
- ui.contextNote.replaceChildren(prefix, document.createTextNode(shared));
600
+ ui.contextNote.replaceChildren(...(destination ? [document.createTextNode(destination)] : []), prefix, document.createTextNode(shared));
588
601
  }
589
602
  // Send is icon-only, so its tooltip names the action before saying what goes with the message.
590
603
  ui.send.dataset.tip = `Send message · ${ui.contextNote.textContent}`;
@@ -1967,16 +1980,18 @@
1967
1980
  summary.className = 'ai-chat-tekla-summary';
1968
1981
  summary.setAttribute('role', 'status');
1969
1982
  card.append(summary);
1983
+ // A read with nothing selected can still find a linked part gone: the history goes on every way out.
1984
+ const finish = () => { appendTeklaHistory(card, event); return card; };
1970
1985
  if (count === 0 && payload.complete === false) {
1971
1986
  // Stopped before reaching any part: that is not "nothing selected".
1972
1987
  note(`The selection is larger than FloLess reads at once, so it stopped before reaching any part${others > 0 ? ` (${teklaCount(others)} other ${others === 1 ? 'object' : 'objects'} read)` : ''}. Select fewer objects, then ask again.`, '', summary);
1973
- return card;
1988
+ return finish();
1974
1989
  }
1975
1990
  if (count === 0) {
1976
1991
  note(others > 0
1977
1992
  ? `No parts were selected in Tekla when checked. ${teklaCount(others)} other selected ${others === 1 ? 'object is' : 'objects are'} not a part (bolts, welds and similar), so nothing is listed.`
1978
1993
  : 'Nothing was selected in Tekla when checked.', '', summary);
1979
- return card;
1994
+ return finish();
1980
1995
  }
1981
1996
  for (const line of teklaSelectionSummary(payload, parts.length)) note(line, '', summary);
1982
1997
  const scroller = document.createElement('div');
@@ -2020,7 +2035,151 @@
2020
2035
  card.append(scroller);
2021
2036
  note('Selected assemblies are listed by their parts when checked.');
2022
2037
  if (others > 0) note(`${teklaCount(others)} other selected ${others === 1 ? 'object is' : 'objects are'} not a part (bolts, welds and similar) and ${others === 1 ? 'is' : 'are'} not listed.`);
2023
- return card;
2038
+ // The store wrote this link with the receipt itself (#1653 stage 4), so the sentence is exactly as durable as the link.
2039
+ if (payload.linkedQuestion) note('Linked to this question. The next time these parts are checked, this question is listed with them.');
2040
+ return finish();
2041
+ }
2042
+
2043
+ /* #1653 stage 4: the questions asked in chat about the parts a live Tekla selection read listed. They show on the
2044
+ newest verified selection receipt only, so the card and its controls exist once; older receipts stay plain records
2045
+ of what was selected when they were checked. Rows and words are the shared card's (web/model-chat-questions.js),
2046
+ the same one the model viewers show; loaded on first need. */
2047
+ let chatQuestionsModule = null;
2048
+ let chatQuestionsLoading = null;
2049
+ let chatQuestionsFailed = false;
2050
+
2051
+ // The shared card is loaded on first use. A failed load says so on the receipt, with Retry, instead of showing nothing.
2052
+ function loadChatQuestionsModule() {
2053
+ chatQuestionsLoading ??= import('./model-chat-questions.js').then(
2054
+ (module) => { chatQuestionsModule = module; chatQuestionsFailed = false; },
2055
+ (error) => { chatQuestionsLoading = null; chatQuestionsFailed = true; console.warn('[chat] the questions card could not be loaded', error); });
2056
+ return chatQuestionsLoading;
2057
+ }
2058
+
2059
+ function chatQuestionsLoadFailed() {
2060
+ const box = document.createElement('section'); box.className = 'chat-questions'; box.setAttribute('aria-label', 'Questions in chat');
2061
+ const line = document.createElement('div'); line.className = 'hint chat-q-failed'; line.textContent = 'Questions in chat could not be loaded.';
2062
+ const retry = document.createElement('button'); retry.type = 'button'; retry.className = 'ghost'; retry.textContent = 'Retry';
2063
+ retry.dataset.commandId = 'shell.chat-questions-retry';
2064
+ retry.onclick = () => { void loadChatQuestionsModule().then(paintTeklaHistory); };
2065
+ line.append(' ', retry); box.append(line); return box;
2066
+ }
2067
+
2068
+ function teklaOrphanTitle(count) {
2069
+ return `Questions about parts not found in the model when checked (${count})`;
2070
+ }
2071
+
2072
+ function newestTeklaSelectionId(events) {
2073
+ for (let index = events.length - 1; index >= 0; index -= 1) {
2074
+ const event = events[index];
2075
+ if (event?.type === 'tekla-read' && event.payload?.status === 'verified-for-selection-read') return event.eventId;
2076
+ }
2077
+ return null;
2078
+ }
2079
+
2080
+ // The card for one receipt, or null. A question shows under a listed part only while the read did not find that
2081
+ // part missing, and a part the read did not check is never claimed missing. The receipt's own question is left out:
2082
+ // it is on screen right above.
2083
+ function teklaHistoryCard(payload) {
2084
+ const module = chatQuestionsModule;
2085
+ if (!module) return chatQuestionsFailed ? chatQuestionsLoadFailed() : null;
2086
+ const parts = (Array.isArray(payload.parts) ? payload.parts : []).filter((part) => typeof part?.guid === 'string');
2087
+ const missing = new Set(Array.isArray(payload.missingLinkedParts) ? payload.missingLinkedParts : []);
2088
+ if (!parts.length && !missing.size) return null;
2089
+ const labels = new Map(parts.map((part) => [part.guid, module.subjectLabelText(module.modelSubjectLabel('tekla', part))]));
2090
+ const projectId = state.scope?.owner?.kind === 'project' ? state.scope.owner.projectId : null;
2091
+ const loaded = state.teklaLinks.projectId === projectId ? state.teklaLinks : { state: 'idle', links: [], partial: false };
2092
+ const own = payload.linkedQuestion?.messageEventId;
2093
+ const chatLinks = loaded.state === 'ready' ? { ...loaded, links: loaded.links.filter((link) => link.messageEventId !== own) } : loaded;
2094
+ return module.renderChatQuestions({
2095
+ doc: document, chatLinks, selected: parts.map((part) => ({ kind: 'part', id: part.guid })),
2096
+ resolves: (link) => !missing.has(link.id), currentLabel: (link) => labels.get(link.id) || '', commandPrefix: 'shell',
2097
+ onShow: showTeklaQuestion, onRetry: () => { void loadTeklaLinks(true); }, toast: (text) => window.showToast?.(text, 'info'),
2098
+ ui: state.teklaHistoryUi, orphans: 'also', orphanTitle: teklaOrphanTitle,
2099
+ });
2100
+ }
2101
+
2102
+ function showTeklaQuestion(link) {
2103
+ const projectId = state.scope?.owner?.kind === 'project' ? state.scope.owner.projectId : null;
2104
+ if (!projectId) return false;
2105
+ Promise.resolve(openConversation(link.chatId, { messageEventId: link.messageEventId, projectId }))
2106
+ .catch((error) => { window.showToast?.(error?.message || 'That conversation could not be opened. Try Show in chat again.', 'info'); });
2107
+ return true;
2108
+ }
2109
+
2110
+ function appendTeklaHistory(card, event) {
2111
+ if (state.scope?.owner?.kind !== 'project' || event.eventId !== newestTeklaSelectionId(state.events)) return;
2112
+ const host = document.createElement('div');
2113
+ host.className = 'ai-chat-tekla-history';
2114
+ host.hidden = true;
2115
+ card.append(host);
2116
+ // A newer receipt, or another conversation's, reads the links again; a repaint of the same one reuses them.
2117
+ const fresh = state.teklaHistoryHost?.eventId !== event.eventId;
2118
+ state.teklaHistoryHost = { host, eventId: event.eventId, payload: event.payload || {} };
2119
+ if (chatQuestionsModule) paintTeklaHistory();
2120
+ else void loadChatQuestionsModule().then(paintTeklaHistory);
2121
+ void loadTeklaLinks(fresh);
2122
+ }
2123
+
2124
+ // Painted whether or not the receipt is on the page yet: renderEvent builds the receipt before the feed appends it,
2125
+ // and a repaint that finds the links already loaded asks nothing more, so this paint is the one that fills it.
2126
+ function paintTeklaHistory() {
2127
+ const ref = state.teklaHistoryHost;
2128
+ if (!ref?.host) return;
2129
+ const payload = ref.payload;
2130
+ const node = teklaHistoryCard(payload);
2131
+ ref.host.replaceChildren();
2132
+ if (node) ref.host.append(node);
2133
+ const unchecked = Number(payload.linkedPartsUnchecked) || 0;
2134
+ if (Array.isArray(payload.missingLinkedParts) && unchecked > 0) {
2135
+ const checked = Number(payload.linkedPartsChecked) || 0;
2136
+ const line = document.createElement('p');
2137
+ line.className = 'ai-chat-tekla-history-note';
2138
+ line.textContent = `FloLess checked the ${teklaCount(checked)} most recently linked parts. ${teklaCount(unchecked)} earlier ${unchecked === 1 ? 'part was' : 'parts were'} not checked this time, so questions about ${unchecked === 1 ? 'it' : 'them'} may be missing here.`;
2139
+ ref.host.append(line);
2140
+ }
2141
+ // The check fell short for another reason: the receipt must never look like "no linked part is missing".
2142
+ const shortfall = {
2143
+ unavailable: 'FloLess could not check this time whether the parts linked to earlier questions are still in the model, so questions about removed parts are not listed here. Ask again to check them.',
2144
+ partial: 'Some conversations in this project can’t be opened, so the parts linked to questions in them were not checked, and questions about removed parts may be missing here. History lists those conversations.',
2145
+ }[payload.linkedPartsCheck];
2146
+ if (shortfall) {
2147
+ const line = document.createElement('p');
2148
+ line.className = 'ai-chat-tekla-history-note';
2149
+ line.textContent = shortfall;
2150
+ ref.host.append(line);
2151
+ }
2152
+ ref.host.hidden = !ref.host.childElementCount;
2153
+ window.__instructor?.notifyChanged?.();
2154
+ }
2155
+
2156
+ async function loadTeklaLinks(force = false) {
2157
+ const projectId = state.scope?.owner?.kind === 'project' ? state.scope.owner.projectId : null;
2158
+ if (!projectId) return;
2159
+ const current = state.teklaLinks;
2160
+ const same = current.projectId === projectId;
2161
+ // Only a real change (a new receipt, a link written live, Retry) asks again; a repaint while an answer streams must
2162
+ // not queue one read after another.
2163
+ if (same && current.inflight) { if (force) current.again = true; return; }
2164
+ if (same && !force && current.state !== 'idle') return;
2165
+ const next = { projectId, state: same ? current.state : 'idle', links: same ? current.links : [], partial: same && current.partial,
2166
+ inflight: true, again: false };
2167
+ state.teklaLinks = next;
2168
+ try {
2169
+ const result = await request(`/api/chat/subject-links?ownerKind=project&ownerId=${encodeURIComponent(projectId)}&source=tekla`);
2170
+ if (state.teklaLinks === next) {
2171
+ Object.assign(next, { state: 'ready', links: Array.isArray(result?.links) ? result.links : [], partial: Boolean(result?.partial) });
2172
+ }
2173
+ } catch (error) {
2174
+ // The card says the questions could not be loaded and offers Retry; the cause is kept for whoever debugs it.
2175
+ if (state.teklaLinks === next) { next.state = 'failed'; console.warn('[chat] the questions linked to Tekla parts could not be loaded', error); }
2176
+ } finally {
2177
+ if (state.teklaLinks === next) {
2178
+ next.inflight = false;
2179
+ paintTeklaHistory();
2180
+ if (next.again) void loadTeklaLinks(true);
2181
+ }
2182
+ }
2024
2183
  }
2025
2184
 
2026
2185
  function checkedTime(value) {
@@ -2115,7 +2274,7 @@
2115
2274
  // That button is `aria-disabled`, not `disabled`, so it passes the filter (#1514).
2116
2275
  function restoreFeedFocus(focusedCommand) {
2117
2276
  if (!focusedCommand?.startsWith('shell.chat-followup-') && !focusedCommand?.startsWith('shell.chat-filter-')
2118
- && focusedCommand !== 'shell.chat-sign-in') return;
2277
+ && !focusedCommand?.startsWith('shell.chat-question') && focusedCommand !== 'shell.chat-sign-in') return;
2119
2278
  [...ui.feed.querySelectorAll('[data-command-id]')]
2120
2279
  .find(control => control.dataset.commandId === focusedCommand && !control.disabled)?.focus({ preventScroll: true });
2121
2280
  }
@@ -2125,6 +2284,7 @@
2125
2284
  const focusedCommand = ui.feed.contains(document.activeElement)
2126
2285
  ? document.activeElement?.dataset?.commandId : null;
2127
2286
  const nearBottom = ui.feed.scrollHeight - ui.feed.scrollTop - ui.feed.clientHeight < 56;
2287
+ const scrollTop = ui.feed.scrollTop;
2128
2288
  ui.feed.replaceChildren();
2129
2289
  if (!state.events.length) {
2130
2290
  ui.feed.append(emptyFeedNotice());
@@ -2171,10 +2331,15 @@
2171
2331
  if (turnIsVisiblyActive()) ui.feed.append(renderLiveStatus());
2172
2332
  }
2173
2333
  restoreFeedFocus(focusedCommand);
2334
+ // Removing a focused control makes the browser lay out the half-built feed, which clamps its scroll near the top.
2335
+ // Scrolled up, the reader stays where they were.
2336
+ if (!nearBottom) ui.feed.scrollTop = scrollTop;
2174
2337
  restoreAnswerJump();
2175
2338
  updateOffscreenActivity();
2176
2339
  if (!state.answerJump && (nearBottom || options.forceBottom)) requestAnimationFrame(() => {
2177
2340
  ui.feed.scrollTop = ui.feed.scrollHeight;
2341
+ // A control that kept keyboard focus across the repaint (the questions card sits above the answer) stays in sight.
2342
+ if (ui.feed.contains(document.activeElement)) document.activeElement.scrollIntoView({ block: 'nearest' });
2178
2343
  updateOffscreenActivity();
2179
2344
  });
2180
2345
  }
@@ -2513,7 +2678,9 @@
2513
2678
  *
2514
2679
  * SEPARATE FROM `paintAttachments` BECAUSE IT DEPENDS ON THE SURFACE, NOT ONLY ON THE
2515
2680
  * ATTACHMENTS. On the Drawing Filter the answer is written by a headless AI that can only look at
2516
- * pictures, so a PDF is refused — and that has to be on the control BEFORE the message is typed,
2681
+ * pictures, so a PDF is refused (except while a drawing read in this chat is waiting on your answer,
2682
+ * #1776: the message is then a normal turn to that read and takes PDFs like any other) — and that
2683
+ * has to be on the control BEFORE the message is typed,
2517
2684
  * not at Send. `paintAttachments` runs when the attachments change; opening the Drawing Filter
2518
2685
  * changes neither, so a tooltip painted only there keeps the previous surface's wording. Measured
2519
2686
  * in the browser: the filter reported ready on S-203 while the paperclip still offered PDFs.
@@ -2521,7 +2688,8 @@
2521
2688
  */
2522
2689
  function paintAttachControl() {
2523
2690
  const imageCount = state.attachments.filter((attachment) => attachment.mediaType.startsWith('image/')).length;
2524
- const kinds = filterSurface().state === 'off' ? 'image or PDF' : 'a picture';
2691
+ // A reply to a drawing read waiting on the person is a normal turn, and takes what any message takes (#1776).
2692
+ const kinds = filterSurface().state === 'off' || paintFilterComposer().replyToRead ? 'image or PDF' : 'a picture';
2525
2693
  ui.attach.dataset.tip = `Attach ${kinds} · ${imageCount} of ${MAX_IMAGES_PER_MESSAGE} images in this message`;
2526
2694
  ui.attach.setAttribute('aria-label', `Attach ${kinds} · ${imageCount} of ${MAX_IMAGES_PER_MESSAGE} images`);
2527
2695
  }
@@ -2976,6 +3144,8 @@
2976
3144
  state.events.push(event);
2977
3145
  // The chat model linked objects during this answer: an open Steel card reads its links again (#1653).
2978
3146
  if (event.type === 'chat-subjects') subjectLinksSaved(event.payload);
3147
+ // So does the Tekla questions card, once any selection receipt in this pane has shown one (#1653 stage 4).
3148
+ if (event.type === 'chat-subjects' && state.teklaHistoryHost) void loadTeklaLinks(true);
2979
3149
  state.events.sort((a, b) => a.sequence - b.sequence);
2980
3150
  state.chat.lastEventSequence = Math.max(state.chat.lastEventSequence || 0, event.sequence || 0);
2981
3151
  const listChat = state.chats.find((item) => item.chatId === chatId);
@@ -3828,6 +3998,7 @@
3828
3998
  const FILTER_CHECK_RETRY = 'FloLess could not check the answer yet. Trying again.';
3829
3999
  const FILTER_CHECK_STOPPED = 'FloLess stopped checking this answer after several tries. A late answer may still appear here or in Requests. Check those before sending it again. Nothing changed.';
3830
4000
  let filterBridgeWarned = false;
4001
+ let readCheckWarned = false;
3831
4002
 
3832
4003
  function filterRefusal(message) {
3833
4004
  return Object.assign(new Error(message), { filterRefusal: true });
@@ -3873,12 +4044,38 @@
3873
4044
  * hard-codes `kind = 'change'`, and a comment on this screen saying otherwise is how the next
3874
4045
  * reader gets it backwards.) What still announces it is `paintFloLessContext`'s "Sharing with AI:
3875
4046
  * Drawing Filter · partial view of <sheet> and its selection" — which is the better cue anyway,
3876
- * because it NAMES THE SHEET, and it sits directly under the box. (The compose hint does not: its
3877
- * chain in `clearReport` has no filter branch, and the attach control's blocked reason only speaks
3878
- * once someone tries to attach. An earlier draft of this comment credited the hint; it was wrong.)
4047
+ * because it NAMES THE SHEET, and it sits directly under the box. (The compose hint does not
4048
+ * announce the filter mode: the only branch of its chain in `clearReport` that depends on this
4049
+ * function is the #1776 read-reply hint below, which names where a message goes when it is NOT the
4050
+ * filter mode; and the attach control's blocked reason only speaks once someone tries to attach.)
4051
+ *
4052
+ * RETURNS the raw `filterSurface()` result — `{ state: 'off' | 'loading' }` or `{ state: 'ready',
4053
+ * bridge, summary }` — except when a drawing read in this conversation is waiting on the person's
4054
+ * answer (#1776): then `{ state: 'off', replyToRead: true }`, even though the Drawing Filter IS
4055
+ * open. Callers that route or label a message must ask this, never `filterSurface()` directly.
3879
4056
  */
3880
4057
  function paintFilterComposer() {
3881
- return filterSurface();
4058
+ const surface = filterSurface();
4059
+ // #1776: a drawing read in THIS conversation whose turn has stopped is waiting on the person, so
4060
+ // what they type is its answer. Sent to the Drawing Filter's AI instead, the answer reached a
4061
+ // listener that never asked, and the read sat idle with nothing on screen saying why. The read
4062
+ // wins, and the composer says so while it does: the hint beside Send (`clearReport`, when no
4063
+ // higher-priority notice holds it) and the context note under the box (`paintFloLessContext`),
4064
+ // which also feeds Send's tooltip. With no read waiting, nothing changes.
4065
+ if (surface.state !== 'off' && !turnIsVisiblyActive() && readAwaitingReply()) return { state: 'off', replyToRead: true };
4066
+ return surface;
4067
+ }
4068
+
4069
+ /** The drawing read this conversation is running, from the shell's server-owned request rows (#1776). */
4070
+ function readAwaitingReply() {
4071
+ const chatId = state.chat?.chatId;
4072
+ if (!chatId) return null;
4073
+ try { return window.flolessBridge?.readInChat?.(chatId) || null; } catch (error) {
4074
+ // Painted on every keystroke, so said once. Unknown means no read claims the message, as before #1776.
4075
+ if (!readCheckWarned) console.error('[chat] could not check whether a drawing read is waiting in this conversation:', error);
4076
+ readCheckWarned = true;
4077
+ return null;
4078
+ }
3882
4079
  }
3883
4080
 
3884
4081
  function filterPendingIn(chatId) {
@@ -4589,8 +4786,9 @@
4589
4786
  if (!state.chat || ui.send.disabled) return;
4590
4787
  // On the Drawing Filter, Send asks about the filter; a filter-intended message is never sent as a
4591
4788
  // normal turn, not even while the filter page is still loading.
4789
+ // Unless a drawing read here is waiting on the person's answer: then the message is that answer (#1776).
4592
4790
  const filter = filterSurface();
4593
- if (filter.state !== 'off') { await sendFilterAi(filter); return; }
4791
+ if (filter.state !== 'off' && !paintFilterComposer().replyToRead) { await sendFilterAi(filter); return; }
4594
4792
  // Decided once, at the click, from what the pill showed: a follow-up that falls back to a new turn below
4595
4793
  // must not attach objects the person was never shown (#1653).
4596
4794
  const subjects = subjectsPayload(composerSelection());
@@ -5094,7 +5292,9 @@
5094
5292
  * pictures on a command line and has no way to open a document, so a PDF attached there could
5095
5293
  * only be uploaded, counted against the conversation's budget, and then refused after the whole
5096
5294
  * message had been written around it. `paintAttachControl` already says "Attach a picture" on that
5097
- * surface; this is the half that makes the control's word good.
5295
+ * surface; this is the half that makes the control's word good. (Except while a drawing read in
5296
+ * this chat is waiting on your answer, #1776: the message then goes to that read as a normal turn,
5297
+ * so nothing is refused here and the control offers PDFs too.)
5098
5298
  *
5099
5299
  * A NAMED FUNCTION rather than an inline block, because `attachFiles` is held to a guard that
5100
5300
  * requires its `captureChat()` and `sameChat(snapshot)` to stay within reach of each other — the
@@ -5102,7 +5302,7 @@
5102
5302
  * that guard red, which is the guard doing its job.
5103
5303
  */
5104
5304
  function filterAttachRefusal(incoming) {
5105
- if (filterSurface().state === 'off') return null;
5305
+ if (filterSurface().state === 'off' || paintFilterComposer().replyToRead) return null;
5106
5306
  const document = incoming.find((file) => !String(file.type || '').startsWith('image/'));
5107
5307
  if (!document) return null;
5108
5308
  return `“${document.name}” can’t be sent with a Drawing Filter message — the AI answering here can only look at pictures. `
@@ -5800,6 +6000,9 @@
5800
6000
  window.flolessChat = {
5801
6001
  refreshScope, refreshActivity, refreshIndex, startRequest, openConversation, openDraft, openVerifiedTeklaDraft,
5802
6002
  startProjectIntake, resumeProjectIntake,
6003
+ // The plain-English sentence for a refusal the chat routes named, so a Start outside this panel
6004
+ // (the upload modal, Requests) says what happened and what to do next instead of a generic toast (#1779).
6005
+ describeError: errorMessage,
5803
6006
  currentProvider: () => state.chat?.provider ?? null,
5804
6007
  // The project this panel's conversations belong to; an object card offers Show in chat only for it (#1653).
5805
6008
  scopeProjectId: () => (state.scope?.owner?.kind === 'project' ? state.scope.owner.projectId : null),
@@ -1294,13 +1294,13 @@
1294
1294
 
1295
1295
  def('shell.revision-filter-open', {
1296
1296
  label: 'Open Drawing Filter',
1297
- actsOn: 'Moves focus to the next required Drawing Filter action for this drawing read',
1297
+ actsOn: 'Opens the Drawing Filter and moves focus to the next required Drawing Filter action for this drawing read, including a confirmation still waiting for your answer or the explanation of a save that could not finish',
1298
1298
  group: 'In the project workspace',
1299
1299
  persistence: 'none',
1300
1300
  interaction: 'instant',
1301
1301
  risk: [],
1302
1302
  guidance: 'on-demand',
1303
- why: 'The drawing read is paused until you review the selected lines and press Save filter.',
1303
+ why: 'The drawing read is paused until you review the selected lines, press Save filter, and answer any confirmation it asks.',
1304
1304
  });
1305
1305
 
1306
1306
  def('shell.revision-request-copy', {
@@ -1584,11 +1584,11 @@
1584
1584
  group: 'In AI Chat', key: 'Enter sends · Shift + Enter starts a new line', persistence: 'working', interaction: 'instant', risk: [], guidance: 'on-demand',
1585
1585
  });
1586
1586
  def('shell.chat-attach', {
1587
- label: 'Attach file', actsOn: 'Adds images (up to five per message) or PDFs from this computer to the next message or follow-up; on the Drawing Filter only pictures can be sent and a PDF is turned away as soon as it is chosen, because the AI answering there cannot open one',
1587
+ label: 'Attach file', actsOn: 'Adds images (up to five per message) or PDFs from this computer to the next message or follow-up; on the Drawing Filter only pictures can be sent and a PDF is turned away as soon as it is chosen, because the AI answering there cannot open one — unless a drawing read in this conversation is waiting on your answer, when the message goes to that read and takes images or PDFs',
1588
1588
  group: 'In AI Chat', persistence: 'working', interaction: 'dialog', risk: [], guidance: 'on-demand',
1589
1589
  });
1590
1590
  def('shell.chat-attach-input', {
1591
- label: 'Choose attachments', actsOn: 'Selects images (up to five per message) or PDFs to add to the next message or follow-up; on the Drawing Filter a PDF is turned away as soon as it is chosen, because the AI answering there cannot open one',
1591
+ label: 'Choose attachments', actsOn: 'Selects images (up to five per message) or PDFs to add to the next message or follow-up; on the Drawing Filter a PDF is turned away as soon as it is chosen, because the AI answering there cannot open one — unless a drawing read in this conversation is waiting on your answer, when the message goes to that read and takes images or PDFs',
1592
1592
  group: 'In AI Chat', persistence: 'working', interaction: 'dialog', risk: [], guidance: 'on-demand',
1593
1593
  });
1594
1594
  def('shell.chat-subjects', {
@@ -1600,6 +1600,29 @@
1600
1600
  label: 'Leave selected objects out', actsOn: 'Sends your next question without the selected Steel Model objects, until the selection changes',
1601
1601
  group: 'In AI Chat', persistence: 'none', interaction: 'instant', risk: [], guidance: 'on-demand',
1602
1602
  });
1603
+ // Questions in chat about the parts a Tekla selection read listed (#1653 stage 4): the shared card on the newest receipt.
1604
+ def('shell.chat-question-show', {
1605
+ label: 'Show in chat', actsOn: 'Opens the conversation at the question “{instance}”', anyInstance: 'a question asked about these Tekla parts',
1606
+ group: 'In AI Chat', persistence: 'none', interaction: 'instant', risk: [], guidance: 'on-demand',
1607
+ why: 'When AI Chat reads the parts selected in Tekla, the question is linked to them, so reading them again lists it.',
1608
+ });
1609
+ def('shell.chat-questions-more', {
1610
+ label: 'Show more questions', actsOn: 'Shows the older questions asked in AI Chat about the parts this Tekla read listed',
1611
+ group: 'In AI Chat', persistence: 'none', interaction: 'instant', risk: [], guidance: 'on-demand',
1612
+ });
1613
+ def('shell.chat-questions-orphans', {
1614
+ label: 'Questions about parts not found in the model', actsOn: 'Shows the questions about linked parts this Tekla read did not find in the open model, with the name each had when asked',
1615
+ group: 'In AI Chat', persistence: 'none', interaction: 'instant', risk: [], guidance: 'on-demand',
1616
+ why: 'A question is never moved to another part, even one with the same mark.',
1617
+ });
1618
+ def('shell.chat-questions-orphans-more', {
1619
+ label: 'Show more questions about missing parts', actsOn: 'Shows the older questions about linked parts this Tekla read did not find',
1620
+ group: 'In AI Chat', persistence: 'none', interaction: 'instant', risk: [], guidance: 'on-demand',
1621
+ });
1622
+ def('shell.chat-questions-retry', {
1623
+ label: 'Retry loading questions', actsOn: 'Reads the questions asked in AI Chat about this project’s Tekla parts again',
1624
+ group: 'In AI Chat', persistence: 'none', interaction: 'instant', risk: [], guidance: 'on-demand',
1625
+ });
1603
1626
  def('shell.chat-attachment-remove', {
1604
1627
  label: 'Remove pending attachment', actsOn: 'Leaves {instance} out of the next message',
1605
1628
  group: 'In AI Chat', persistence: 'none', interaction: 'instant', risk: [], guidance: 'on-demand',
@@ -659,7 +659,8 @@
659
659
  function collect(doc, origin) {
660
660
  if (!doc || !doc.querySelectorAll) return;
661
661
  Array.prototype.forEach.call(doc.querySelectorAll('[data-command-id]'), function (el) {
662
- if ((el.closest && el.closest('#command-sheet')) || !isOnScreen(el)) return;
662
+ // One activate() can reach by opening its container (a collapsed row's <details>, a closed menu) counts too.
663
+ if ((el.closest && el.closest('#command-sheet')) || !(isOnScreen(el) || revealableCarrier(el, doc))) return;
663
664
  var raw = el.getAttribute('data-command-id') || '';
664
665
  var parts = window.Commands.split ? window.Commands.split(raw) : null;
665
666
  if (!parts || parts.template !== cmd.id || !parts.instance || seen[raw]) return;
@@ -866,14 +867,12 @@
866
867
  function revealableCarrier(el, doc) {
867
868
  var chain = revealChain(el);
868
869
  for (var i = 0; i < chain.length; i++) {
869
- if (isOnScreen(chain[i])) continue;
870
+ if (!revealShut(chain[i])) continue;
870
871
  for (var n = el; n && n !== chain[i]; n = n.parentElement) {
871
- if (n.getAttribute && n.getAttribute('data-reveal-by') !== null) continue; // opened on the way in
872
+ if (chain.indexOf(n) !== -1) continue; // opened on the way in
872
873
  if (hiddenByItself(n)) return false;
873
874
  }
874
- var opener = null;
875
- try { opener = doc.querySelector(chain[i].getAttribute('data-reveal-by')); }
876
- catch (e) { opener = null; }
875
+ var opener = revealOpener(chain[i], doc);
877
876
  return !!(opener && opener.getAttribute('data-cancels-pick') === null && isOnScreen(opener));
878
877
  }
879
878
  return false;
@@ -1243,7 +1242,22 @@
1243
1242
  continues out through a child document's frame, so an editor frame inside a covered region
1244
1243
  is covered too. */
1245
1244
  function isOnScreen(el) {
1246
- return !!(el.offsetParent || (el.getClientRects && el.getClientRects().length)) && !coveredByInert(el);
1245
+ return !!(el.offsetParent || (el.getClientRects && el.getClientRects().length)) && !coveredByInert(el)
1246
+ && !insideClosedDetails(el);
1247
+ }
1248
+ /* Chromium keeps a layout box for the content of a CLOSED <details> (it hides it with content-visibility), so
1249
+ offsetParent and getClientRects both say "on screen" and focus() even lands there, out of sight. Only the
1250
+ <summary> shows while a <details> is shut; everything else in it is hidden until it opens. */
1251
+ function insideClosedDetails(el) {
1252
+ for (var n = el; n && n.parentElement; n = n.parentElement) {
1253
+ var p = n.parentElement;
1254
+ if (p.tagName === 'DETAILS' && !p.hasAttribute('open') && n !== detailsSummary(p)) return true;
1255
+ }
1256
+ return false;
1257
+ }
1258
+ function detailsSummary(details) {
1259
+ for (var c = details.firstElementChild; c; c = c.nextElementSibling) if (c.tagName === 'SUMMARY') return c;
1260
+ return null;
1247
1261
  }
1248
1262
  function coveredByInert(el) {
1249
1263
  for (var n = el; n; ) {
@@ -1260,14 +1274,28 @@
1260
1274
  return !!inertBefore && inertBefore.some(function (pair) { return pair[0] === n && !pair[1]; });
1261
1275
  }
1262
1276
 
1263
- /* Every ancestor that declares `data-reveal-by`, open or closed, OUTERMOST first. */
1277
+ /* Every ancestor that can hide `el` until it is opened, open or closed, OUTERMOST first: one that declares
1278
+ `data-reveal-by`, and a <details> that holds it outside its <summary> (the <summary> is its opener). */
1264
1279
  function revealChain(el) {
1265
1280
  var chain = [];
1266
- for (var n = el.parentElement; n; n = n.parentElement) {
1267
- if (n.getAttribute && n.getAttribute('data-reveal-by') !== null) chain.unshift(n);
1281
+ for (var n = el; n.parentElement; n = n.parentElement) {
1282
+ var p = n.parentElement;
1283
+ if ((p.getAttribute && p.getAttribute('data-reveal-by') !== null) || (p.tagName === 'DETAILS' && n !== detailsSummary(p))) {
1284
+ chain.unshift(p);
1285
+ }
1268
1286
  }
1269
1287
  return chain;
1270
1288
  }
1289
+ /* A container on the way to a control is shut until it shows: a <details> until it is open, a menu until it is laid out. */
1290
+ function revealShut(box) {
1291
+ return box.tagName === 'DETAILS' ? !box.hasAttribute('open') : !isOnScreen(box);
1292
+ }
1293
+ /* What opens it: the selector it names, or a <details>'s own <summary>. */
1294
+ function revealOpener(box, doc) {
1295
+ if (box.getAttribute('data-reveal-by') === null) return box.tagName === 'DETAILS' ? detailsSummary(box) : null;
1296
+ try { return doc.querySelector(box.getAttribute('data-reveal-by')); }
1297
+ catch (e) { return null; }
1298
+ }
1271
1299
 
1272
1300
  /* #1199 — the first control for this command that is NOT on screen but sits inside at
1273
1301
  least one container declaring its opener. Same two documents, same order and same
@@ -1290,9 +1318,9 @@
1290
1318
  }
1291
1319
 
1292
1320
  /* Open every closed container around `el`, outermost first, by clicking the opener its
1293
- `data-reveal-by` names (a selector in the same document), then focus the control. The
1294
- page's real opener runs, so whatever it does on open — sync its state, build its rows,
1295
- arm its outside-click close — happens exactly as for a person's click. A container
1321
+ `data-reveal-by` names (a selector in the same document) or a closed <details>'s own <summary>,
1322
+ then focus the control. The page's real opener runs, so whatever it does on open — sync its
1323
+ state, build its rows, arm its outside-click close — happens exactly as for a person's click. A container
1296
1324
  already open is skipped (its opener is usually a toggle, and clicking it would shut it).
1297
1325
  Clicks nothing at an opener marked `data-cancels-pick`: while a pick is armed, Clip,
1298
1326
  Plane and Insert CANCEL it instead of opening, which would silently throw the user's pick
@@ -1326,7 +1354,7 @@
1326
1354
  }
1327
1355
  function giveUp() {
1328
1356
  for (var j = opened.length - 1; j >= 0; j--) {
1329
- if (isOnScreen(opened[j].box) && isOnScreen(opened[j].opener)) opened[j].opener.click();
1357
+ if (!revealShut(opened[j].box) && isOnScreen(opened[j].opener)) opened[j].opener.click();
1330
1358
  }
1331
1359
  // Some openers move focus into their menu (Visibility, View): closing it would strand focus on the body.
1332
1360
  if (opened.length && focusBefore && focusBefore.focus) focusBefore.focus();
@@ -1334,13 +1362,11 @@
1334
1362
  }
1335
1363
  for (var i = 0; i < chain.length; i++) {
1336
1364
  var box = chain[i];
1337
- if (isOnScreen(box)) continue;
1338
- var opener = null;
1339
- try { opener = doc.querySelector(box.getAttribute('data-reveal-by')); }
1340
- catch (e) { opener = null; }
1365
+ if (!revealShut(box)) continue;
1366
+ var opener = revealOpener(box, doc);
1341
1367
  if (!opener || typeof opener.click !== 'function' || opener.getAttribute('data-cancels-pick') !== null || !reachable(opener)) return giveUp();
1342
1368
  opener.click();
1343
- if (!isOnScreen(box)) return giveUp();
1369
+ if (revealShut(box)) return giveUp();
1344
1370
  opened.push({ box: box, opener: opener });
1345
1371
  }
1346
1372
  if (!isOnScreen(el)) {