@floless/app 0.159.0 → 0.161.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/dist/floless-server.cjs +76823 -65608
- package/dist/schemas/steel.model.v2.schema.json +24 -0
- package/dist/skills/floless-app-onboarding/SKILL.md +4 -3
- package/dist/skills/floless-app-onboarding/references/floless-surfaces.md +1 -2
- package/dist/skills/floless-app-rfi/SKILL.md +44 -3
- package/dist/skills/floless-app-steel-model/SKILL.md +2 -2
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +417 -261
- package/dist/templates/steel-model.flo +6 -2
- package/dist/templates/viewer-3d-demo.flo +8 -2
- package/dist/web/app.css +342 -160
- package/dist/web/app.js +17 -51
- package/dist/web/aware.js +656 -574
- package/dist/web/chat-question-card.js +27 -1
- package/dist/web/chat.css +185 -30
- package/dist/web/chat.js +2099 -255
- package/dist/web/commands-drawing-check.js +1 -0
- package/dist/web/commands-filter.js +11 -0
- package/dist/web/commands-shell.js +1118 -134
- package/dist/web/commands-steel.js +41 -38
- package/dist/web/drawing-check-editor.js +76 -3
- package/dist/web/guide.js +8 -0
- package/dist/web/index.html +68 -42
- package/dist/web/instructor.js +17 -6
- package/dist/web/pages.js +158 -30
- package/dist/web/panels.js +19 -1
- package/dist/web/project-history.js +349 -0
- package/dist/web/project-reconciliation.js +1 -0
- package/dist/web/project-rfis.js +954 -0
- package/dist/web/project-workflows.js +236 -4
- package/dist/web/run-history.js +198 -0
- package/dist/web/run-page-view.js +12 -2
- package/dist/web/startup-admission.js +53 -7
- package/dist/web/steel-3d-core.js +144 -7
- package/dist/web/steel-3d-view.js +61 -5
- package/dist/web/steel-editor.html +510 -128
- package/dist/web/steel-filter.html +139 -0
- package/dist/web/steel-model-v2-commands.js +3 -3
- package/dist/web/steel-model-v2-projection.js +139 -4
- package/dist/web/steel-plan-transform.js +78 -0
- package/dist/web/tool-updates.js +5 -0
- package/dist/web/workspaces.js +1438 -159
- package/launch.mjs +36 -5
- package/package.json +7 -4
package/dist/web/chat.js
CHANGED
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
connectors: el('chat-connectors'),
|
|
34
34
|
changeAllowance: el('chat-change-allowance'),
|
|
35
35
|
scopeControls: el('chat-scope-controls'), scopeToggle: el('chat-scope-toggle'),
|
|
36
|
-
scopePicker: el('chat-scope-picker'),
|
|
36
|
+
scopePicker: el('chat-scope-picker'), accessChip: el('chat-access-chip'), accessMenu: el('chat-access-menu'),
|
|
37
37
|
checkAllowance: el('chat-check-allowance'),
|
|
38
38
|
grants: el('chat-grants'),
|
|
39
39
|
workspaceUnits: el('chat-units'),
|
|
@@ -54,9 +54,8 @@
|
|
|
54
54
|
|
|
55
55
|
const state = {
|
|
56
56
|
// #2438: the picks waiting to go with the next message (per conversation), and the open @ list.
|
|
57
|
-
mentions: {}, mentionMenu: null, mentionDismissed: null,
|
|
57
|
+
mentions: {}, mentionMenu: null, mentionDismissed: null, sourcePicker: null,
|
|
58
58
|
scopeView: null, scopeViewChatId: null, scopeChoice: null, scopeEditing: false, scopePickerOpen: false,
|
|
59
|
-
accessExplanationExpanded: readAccessExplanationPreference(),
|
|
60
59
|
// signInPending is keyed by provider: a wait started in one conversation must not paint an
|
|
61
60
|
// unrelated conversation's button as Waiting for sign-in… for the next two minutes.
|
|
62
61
|
// #1798: the chat owner's display units as the server last answered them (null = not known yet), and the
|
|
@@ -85,7 +84,6 @@
|
|
|
85
84
|
reportHold: null,
|
|
86
85
|
// Only this exact report announcement may be removed when its composer reason ends (#1704).
|
|
87
86
|
reportLiveMessage: null,
|
|
88
|
-
pendingSettings: null,
|
|
89
87
|
// A Tekla model library carried over from a Graft receipt but not yet bound to its chat. It is
|
|
90
88
|
// browser-only until Send: opening, editing or removing it never calls the binding route.
|
|
91
89
|
// pendingTeklaLibrary waits for the provider chooser to create the chat it belongs to.
|
|
@@ -106,10 +104,23 @@
|
|
|
106
104
|
keepApprovalTrayDecisionVisible(ui.approvalTray);
|
|
107
105
|
// #2223: a card opening above the message box shrinks the conversation. A reader who was at its end stays at its end,
|
|
108
106
|
// so the AI's reply to their answer is in sight; one who scrolled up stays where they were.
|
|
107
|
+
// The feed moving up, away from its end, is the reader leaving the end, however few pixels it has moved yet: a smooth
|
|
108
|
+
// scroll starts with one or two, and a repaint or resize in between used to pull it back down (owner, 2026-10-23:
|
|
109
|
+
// "bouncing up and down" while the AI worked). The feed's own movement covers wheel, keys, scrollbar and touch alike, and
|
|
110
|
+
// never a list scrolling inside a card. A clamp (a card closing, the end shrinking) leaves it AT the end, so it is not a
|
|
111
|
+
// leave. They follow again once back at the very end. paintEvents reads the same flag.
|
|
112
|
+
// Movement is counted net of content that shrank (scroll anchoring moves scrollTop by exactly that much), and tiny
|
|
113
|
+
// upward steps (a precision touchpad's fractions of a pixel) add up against the same starting point until they count.
|
|
109
114
|
function keepFeedFollowing(feed) {
|
|
110
115
|
let atEnd = true;
|
|
116
|
+
let fromTop = feed.scrollTop, fromHeight = feed.scrollHeight;
|
|
111
117
|
feed.addEventListener('scroll', () => {
|
|
112
|
-
|
|
118
|
+
const distance = feed.scrollHeight - feed.scrollTop - feed.clientHeight;
|
|
119
|
+
const movedUp = (fromTop - feed.scrollTop) - (fromHeight - feed.scrollHeight);
|
|
120
|
+
if (movedUp > 0.5 && distance > 0.5) state.feedLeftEnd = true;
|
|
121
|
+
else if (distance < 2) state.feedLeftEnd = false;
|
|
122
|
+
if (!(movedUp > 0 && movedUp <= 0.5)) { fromTop = feed.scrollTop; fromHeight = feed.scrollHeight; }
|
|
123
|
+
atEnd = !state.feedLeftEnd && distance < 56;
|
|
113
124
|
});
|
|
114
125
|
new ResizeObserver(() => {
|
|
115
126
|
if (atEnd && !state.answerJump) feed.scrollTop = feed.scrollHeight;
|
|
@@ -145,6 +156,9 @@
|
|
|
145
156
|
const ATTACHMENT_KIND_LABELS = { 'application/pdf': 'PDF', 'application/x-step': 'IFC', 'application/dxf': 'DXF', 'text/plain': 'Data' };
|
|
146
157
|
const MB = 1024 * 1024;
|
|
147
158
|
|
|
159
|
+
/** The project this conversation is about, when it is a project's chat (#2777: where a drawing place can be opened). */
|
|
160
|
+
const chatProjectId = () => (state.scope?.owner?.kind === 'project' && typeof state.scope.owner.projectId === 'string' ? state.scope.owner.projectId : null);
|
|
161
|
+
|
|
148
162
|
function ownerQuery(owner = state.scope?.owner) {
|
|
149
163
|
if (!owner) return '';
|
|
150
164
|
const ownerId = owner.kind === 'project' ? owner.projectId : owner.kind === 'workflow' ? owner.workflowId : 'workspace';
|
|
@@ -578,7 +592,10 @@
|
|
|
578
592
|
: 'Enter to send · Shift+Enter for a new line';
|
|
579
593
|
if (turnIsVisiblyActive() && !state.followupUnknownId && !hasUnknownFollowup()
|
|
580
594
|
&& state.imageLimitChatId !== state.chat?.chatId) {
|
|
581
|
-
|
|
595
|
+
// #2651: after the person changed Access during this reply, a message sent now waits for the next turn.
|
|
596
|
+
const nextAccess = accessChangedDuringReply(state.chat);
|
|
597
|
+
if (nextAccess) ui.hint.textContent = `AI is working · your next message uses ${nextAccess.next}`;
|
|
598
|
+
else ui.hint.textContent = 'AI is working · send a follow-up without stopping';
|
|
582
599
|
ui.hint.classList.remove('working');
|
|
583
600
|
ui.hint.removeAttribute('aria-label');
|
|
584
601
|
} else {
|
|
@@ -633,6 +650,7 @@
|
|
|
633
650
|
drawings: 'drawing-filter', model: 'project-model', exports: 'project-exports',
|
|
634
651
|
history: 'project-history', knowledge: 'project-knowledge', pages: 'project-pages',
|
|
635
652
|
workflows: 'project-workflows', // #2470 R6.2
|
|
653
|
+
rfis: 'project-rfis', // #2470 R6.6 (General's pane) and R6.6c (a steel project's RFI page, in the editor frame)
|
|
636
654
|
}[selectedStep || ''] || 'project-list';
|
|
637
655
|
const workspaceProjectOpen = document.getElementById('ws-project')?.hidden === false;
|
|
638
656
|
const dashboardVisible = document.getElementById('dashboard')?.hidden === false;
|
|
@@ -679,6 +697,8 @@
|
|
|
679
697
|
case 'project-knowledge': return shellText('ws-knowledge');
|
|
680
698
|
case 'project-pages': return shellText('ws-pages');
|
|
681
699
|
case 'project-workflows': return shellText('ws-workflows');
|
|
700
|
+
// A General project's RFIs are a shell pane; a steel project's are the editor's own RFI page in the model frame.
|
|
701
|
+
case 'project-rfis': return document.getElementById('ws-rfis')?.hidden === false ? shellText('ws-rfis') : readVisibleFrameText('ws-frame-model');
|
|
682
702
|
case 'project-list': return shellText('ws-landing');
|
|
683
703
|
case 'workflow-list': return shellText('wf-landing');
|
|
684
704
|
case 'agent-list': case 'agent-page': return shellText('agents-surface');
|
|
@@ -694,7 +714,7 @@
|
|
|
694
714
|
function floLessContextLabel(context = currentFloLessContext()) {
|
|
695
715
|
const labels = {
|
|
696
716
|
'drawing-filter': 'Drawing Filter', 'project-model': 'project model', 'project-exports': 'project exports',
|
|
697
|
-
'project-history': 'project history', 'project-knowledge': 'project Knowledge', 'project-pages': 'project Pages', 'project-workflows': 'project Workflows', 'project-list': 'project list',
|
|
717
|
+
'project-history': 'project history', 'project-knowledge': 'project Knowledge', 'project-pages': 'project Pages', 'project-workflows': 'project Workflows', 'project-rfis': 'project RFIs', 'project-list': 'project list',
|
|
698
718
|
'workflow-canvas': 'workflow canvas', dashboard: 'dashboard', report: 'report', '3d-report': '3D report',
|
|
699
719
|
'model-editor': 'model editor', 'workflow-list': 'workflow list', 'agent-list': 'list of agents', 'agent-page': 'agent page',
|
|
700
720
|
};
|
|
@@ -2046,9 +2066,78 @@
|
|
|
2046
2066
|
const CITE_ANCHOR = /^[a-z0-9-]{1,16}$/;
|
|
2047
2067
|
const INLINE_DIRECTIVE = /:(cite|assume)\[([^\]\n]{1,120})\]/g;
|
|
2048
2068
|
|
|
2069
|
+
/*
|
|
2070
|
+
* #2725: emphasis by CommonMark's delimiter rules, one line at a time, so a `*` or `_` inside a word stays what it is:
|
|
2071
|
+
* `BL15*120` keeps its star, `floless_scope_add` its underscores, and `**BL15*120**` is bold BL15*120. A run of `*` or
|
|
2072
|
+
* `_` opens only when it is left-flanking and closes only when right-flanking, and neither opens or closes inside a
|
|
2073
|
+
* word: CommonMark allows that for `*`, but it would turn `305*165*40` into 305<em>165</em>40. Runs on escaped HTML,
|
|
2074
|
+
* where an entity's `&` and `;` count as the punctuation they stand for.
|
|
2075
|
+
*/
|
|
2049
2076
|
function markdownEmphasis(html) {
|
|
2050
|
-
return html.
|
|
2051
|
-
|
|
2077
|
+
return html.split('\n').map(markdownEmphasisLine).join('\n');
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
function markdownEmphasisLine(line) {
|
|
2081
|
+
const space = (character) => character === undefined || /\s/.test(character);
|
|
2082
|
+
// An inline slot's private-use markers stand for a citation or assumption, so they bound emphasis like punctuation.
|
|
2083
|
+
const punct = (character) => character !== undefined && /[\p{P}\p{S}\uE000\uE001]/u.test(character);
|
|
2084
|
+
const parts = [];
|
|
2085
|
+
let last = 0;
|
|
2086
|
+
for (const run of line.matchAll(/\*+|_+/g)) {
|
|
2087
|
+
parts.push(line.slice(last, run.index));
|
|
2088
|
+
// Neighbours are read whole, so an emoji beside `**Done**🎉` is the symbol it is, not half a surrogate pair.
|
|
2089
|
+
const pair = run.index > 1 && /[\uDC00-\uDFFF]/.test(line[run.index - 1]);
|
|
2090
|
+
const before = run.index > 0 ? line.slice(run.index - (pair ? 2 : 1), run.index) : undefined;
|
|
2091
|
+
const end = run.index + run[0].length;
|
|
2092
|
+
const after = end < line.length ? String.fromCodePoint(line.codePointAt(end)) : undefined;
|
|
2093
|
+
const left = !space(after) && (!punct(after) || space(before) || punct(before));
|
|
2094
|
+
const right = !space(before) && (!punct(before) || space(after) || punct(after));
|
|
2095
|
+
parts.push({
|
|
2096
|
+
mark: run[0][0], length: run[0].length, count: run[0].length, opens: [], closes: [],
|
|
2097
|
+
canOpen: left && (!right || punct(before)),
|
|
2098
|
+
canClose: right && (!left || punct(after)),
|
|
2099
|
+
});
|
|
2100
|
+
last = run.index + run[0].length;
|
|
2101
|
+
}
|
|
2102
|
+
if (parts.length === 0) return line;
|
|
2103
|
+
parts.push(line.slice(last));
|
|
2104
|
+
// The openers still waiting, oldest first; `floor` remembers, per kind of closer, the newest opener already found
|
|
2105
|
+
// useless for it, so each search starts above it and the whole line is processed in near-linear time.
|
|
2106
|
+
const openers = [];
|
|
2107
|
+
const floor = new Map();
|
|
2108
|
+
let sequence = 0;
|
|
2109
|
+
for (const closer of parts) {
|
|
2110
|
+
if (typeof closer === 'string') continue;
|
|
2111
|
+
closer.sequence = sequence += 1;
|
|
2112
|
+
if (closer.canClose) {
|
|
2113
|
+
const kind = `${closer.mark}${closer.canOpen ? 1 : 0}${closer.length % 3}`;
|
|
2114
|
+
while (closer.count > 0) {
|
|
2115
|
+
let at = openers.length - 1;
|
|
2116
|
+
for (; at >= 0 && openers[at].sequence > (floor.get(kind) ?? 0); at -= 1) {
|
|
2117
|
+
const opener = openers[at];
|
|
2118
|
+
const oddMatch = (opener.canClose || closer.canOpen) && (opener.length + closer.length) % 3 === 0
|
|
2119
|
+
&& !(opener.length % 3 === 0 && closer.length % 3 === 0);
|
|
2120
|
+
if (opener.mark === closer.mark && !oddMatch) break;
|
|
2121
|
+
}
|
|
2122
|
+
if (at < 0 || openers[at].sequence <= (floor.get(kind) ?? 0)) {
|
|
2123
|
+
floor.set(kind, openers.length ? openers[openers.length - 1].sequence : 0);
|
|
2124
|
+
break;
|
|
2125
|
+
}
|
|
2126
|
+
const opener = openers[at];
|
|
2127
|
+
const tag = opener.count >= 2 && closer.count >= 2 ? 'strong' : 'em';
|
|
2128
|
+
const used = tag === 'strong' ? 2 : 1;
|
|
2129
|
+
opener.count -= used;
|
|
2130
|
+
closer.count -= used;
|
|
2131
|
+
opener.opens.push(`<${tag}>`);
|
|
2132
|
+
closer.closes.push(`</${tag}>`);
|
|
2133
|
+
// Delimiters between the pair can no longer open anything; an exhausted opener leaves too.
|
|
2134
|
+
openers.length = opener.count > 0 ? at + 1 : at;
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
if (closer.canOpen && closer.count > 0) openers.push(closer);
|
|
2138
|
+
}
|
|
2139
|
+
return parts.map((part) => (typeof part === 'string' ? part
|
|
2140
|
+
: `${part.closes.join('')}${part.mark.repeat(part.count)}${part.opens.reverse().join('')}`)).join('');
|
|
2052
2141
|
}
|
|
2053
2142
|
|
|
2054
2143
|
/** Plain text with emphasis and (inside an answer) directive slots; the slot markers are characters no text can hold. */
|
|
@@ -2250,42 +2339,165 @@
|
|
|
2250
2339
|
chatId: state.chat?.chatId ?? null, owner: ownerQuery(), ownerObject: state.scope?.owner ?? null });
|
|
2251
2340
|
});
|
|
2252
2341
|
}
|
|
2342
|
+
for (const record of citationAssumptions(turnId)) { const row = byAnchor.get(record.anchor); if (row) row.assumption = record; }
|
|
2343
|
+
// #2643: the sources the person chose. The latest is the claim's current one while the AI has given it none; the
|
|
2344
|
+
// earlier ones are its history. A chosen source is numbered like a cited one: the "?" becomes a number.
|
|
2345
|
+
for (const [anchor, made] of citationChoices(turnId)) {
|
|
2346
|
+
const row = byAnchor.get(anchor);
|
|
2347
|
+
if (!row) continue;
|
|
2348
|
+
row.choices = made;
|
|
2349
|
+
if (row.entry.status !== 'resolved') row.choice = made[made.length - 1];
|
|
2350
|
+
}
|
|
2253
2351
|
let n = 0;
|
|
2254
|
-
for (const anchor of order) { const row = byAnchor.get(anchor); row.number = row.entry.status === 'resolved' ? ++n : 0; }
|
|
2352
|
+
for (const anchor of order) { const row = byAnchor.get(anchor); row.number = row.entry.status === 'resolved' || row.choice ? ++n : 0; }
|
|
2255
2353
|
return { byAnchor, order };
|
|
2256
2354
|
}
|
|
2257
2355
|
|
|
2356
|
+
/**
|
|
2357
|
+
* #2643: the sources the person chose for this answer's claims, by anchor, in the order made — the server's validity
|
|
2358
|
+
* rule (`validCitationChoices`): every field the route writes, through the same checks, and the citation it names is
|
|
2359
|
+
* this turn's and holds the anchor. An invalid row is skipped, so it can never stand in for the person's choice.
|
|
2360
|
+
*/
|
|
2361
|
+
function citationChoices(turnId) {
|
|
2362
|
+
const out = new Map();
|
|
2363
|
+
if (!turnId) return out;
|
|
2364
|
+
const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
2365
|
+
for (const event of state.events) {
|
|
2366
|
+
if (event.type !== 'citation-choice') continue;
|
|
2367
|
+
const p = event.payload || {};
|
|
2368
|
+
if (p.turnId !== turnId || typeof p.turnId !== 'string' || !uuid.test(p.turnId) || typeof p.citationId !== 'string' || !uuid.test(p.citationId)
|
|
2369
|
+
|| typeof p.anchor !== 'string' || !CITE_ANCHOR.test(p.anchor) || !(p.claim === null || citeText(p.claim, 300))
|
|
2370
|
+
|| !citeText(p.chosenBy, 200) || !citeText(p.chosenAt, 40) || Number.isNaN(Date.parse(p.chosenAt)) || p.via !== 'chip') continue;
|
|
2371
|
+
const source = chosenSourceOf(p.source);
|
|
2372
|
+
if (!source) continue;
|
|
2373
|
+
const cited = state.events.find((row) => row.type === 'citation' && row.eventId === p.citationId);
|
|
2374
|
+
if (!cited || cited.turnId !== turnId || !(cited.payload?.entries ?? []).some((entry) => entry?.anchor === p.anchor)) continue;
|
|
2375
|
+
const made = out.get(p.anchor) ?? [];
|
|
2376
|
+
made.push({ eventId: event.eventId, anchor: p.anchor, chosenBy: p.chosenBy, chosenAt: p.chosenAt, source });
|
|
2377
|
+
out.set(p.anchor, made);
|
|
2378
|
+
}
|
|
2379
|
+
return out;
|
|
2380
|
+
}
|
|
2381
|
+
|
|
2382
|
+
function citeText(x, max) { return typeof x === 'string' && x.length > 0 && x.length <= max && !/[\u0000-\u001F\u007F]/.test(x); }
|
|
2383
|
+
|
|
2384
|
+
/**
|
|
2385
|
+
* A chosen source as the server stores it (`normalizeChosenSource`): a sheet with the picture digest kept at choosing, a
|
|
2386
|
+
* member, #2692 a Knowledge page at a version with its content digest, or a file of this conversation (no project).
|
|
2387
|
+
*/
|
|
2388
|
+
function chosenSourceOf(value) {
|
|
2389
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).some((key) => !['kind', 'label', 'ref'].includes(key))) return null;
|
|
2390
|
+
const r = value.ref;
|
|
2391
|
+
const hex = /^[0-9a-f]{64}$/;
|
|
2392
|
+
if (!r || typeof r !== 'object' || Array.isArray(r) || !citeText(value.label, 160)) return null;
|
|
2393
|
+
if (value.kind === 'attachment') {
|
|
2394
|
+
if (Object.keys(r).some((key) => !['attachmentId', 'fileName', 'mediaType', 'bytes', 'digest'].includes(key))
|
|
2395
|
+
|| typeof r.attachmentId !== 'string' || !/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(r.attachmentId)
|
|
2396
|
+
|| !citeText(r.fileName, 255) || !citeText(r.mediaType, 120) || !Number.isSafeInteger(r.bytes) || r.bytes < 1
|
|
2397
|
+
|| typeof r.digest !== 'string' || !hex.test(r.digest)) return null;
|
|
2398
|
+
return { kind: 'attachment', label: value.label, ref: r };
|
|
2399
|
+
}
|
|
2400
|
+
if (!citeText(r.projectId, 200) || !citeText(r.projectUuid, 200)) return null;
|
|
2401
|
+
if (value.kind === 'kb-page') {
|
|
2402
|
+
if (Object.keys(r).some((key) => !['projectId', 'projectUuid', 'generationId', 'slug', 'contentDigest'].includes(key))
|
|
2403
|
+
|| typeof r.generationId !== 'string' || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(r.generationId)
|
|
2404
|
+
|| typeof r.slug !== 'string' || !/^[a-z0-9][a-z0-9._-]*$/.test(r.slug) || typeof r.contentDigest !== 'string' || !hex.test(r.contentDigest)) return null;
|
|
2405
|
+
return { kind: 'kb-page', label: value.label, ref: r };
|
|
2406
|
+
}
|
|
2407
|
+
if (value.kind === 'sheet') {
|
|
2408
|
+
if (Object.keys(r).some((key) => !['projectId', 'projectUuid', 'appId', 'pageId', 'sourceHash', 'sheet', 'pageNumber', 'representation', 'imageDigests'].includes(key))
|
|
2409
|
+
|| !citeText(r.appId, 100) || !citeText(r.pageId, 200) || typeof r.sourceHash !== 'string' || !hex.test(r.sourceHash) || !citeText(r.sheet, 200)
|
|
2410
|
+
|| !(r.pageNumber === null || (Number.isSafeInteger(r.pageNumber) && r.pageNumber >= 1)) || r.representation !== 'sheet'
|
|
2411
|
+
|| !Array.isArray(r.imageDigests) || r.imageDigests.length !== 1 || typeof r.imageDigests[0] !== 'string' || !hex.test(r.imageDigests[0])) return null;
|
|
2412
|
+
return { kind: 'sheet', label: value.label, ref: r };
|
|
2413
|
+
}
|
|
2414
|
+
if (value.kind === 'member') {
|
|
2415
|
+
const views = r.views;
|
|
2416
|
+
if (Object.keys(r).some((key) => !['projectId', 'projectUuid', 'memberId', 'mark', 'profile', 'modelEtag', 'views'].includes(key))
|
|
2417
|
+
|| !citeText(r.memberId, 200) || !(r.mark === null || citeText(r.mark, 120)) || !(r.profile === null || citeText(r.profile, 120)) || !citeText(r.modelEtag, 200)
|
|
2418
|
+
|| !Array.isArray(views) || views.length > 4 || views.some((v) => !v || typeof v !== 'object' || Array.isArray(v)
|
|
2419
|
+
|| Object.keys(v).some((key) => key !== 'sheet' && key !== 'title') || !citeText(v.sheet, 120) || !(v.title === null || citeText(v.title, 120)))) return null;
|
|
2420
|
+
return { kind: 'member', label: value.label, ref: r };
|
|
2421
|
+
}
|
|
2422
|
+
return null;
|
|
2423
|
+
}
|
|
2424
|
+
|
|
2425
|
+
/** The chosen source as a chip opens it: its own record (the choice event, index 0), labelled as chosen, never as read. */
|
|
2426
|
+
function chosenViewRow(row, choice) {
|
|
2427
|
+
return { ...row, citationId: choice.eventId, index: 0, entry: { ...choice.source, status: 'resolved', chosen: choice } };
|
|
2428
|
+
}
|
|
2429
|
+
|
|
2430
|
+
/**
|
|
2431
|
+
* #2642: the person's "go on with this as an assumption" on this answer's claims — the server's validity rule
|
|
2432
|
+
* (`liveCitationAssumptions`): the citation it names is this turn's and holds the anchor; the first record per claim wins.
|
|
2433
|
+
*/
|
|
2434
|
+
function citationAssumptions(turnId) {
|
|
2435
|
+
const out = new Map();
|
|
2436
|
+
if (!turnId) return [];
|
|
2437
|
+
const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
2438
|
+
const text = (x, max) => typeof x === 'string' && x.length > 0 && x.length <= max && !/[\u0000-\u001F\u007F]/.test(x);
|
|
2439
|
+
for (const event of state.events) {
|
|
2440
|
+
if (event.type !== 'citation-assumption') continue;
|
|
2441
|
+
const p = event.payload || {};
|
|
2442
|
+
// Every check `normalizeCitationAssumption` makes: a row the server would not tell the AI about is never shown as one.
|
|
2443
|
+
if (p.turnId !== turnId || typeof p.turnId !== 'string' || !uuid.test(p.turnId) || typeof p.citationId !== 'string' || !uuid.test(p.citationId)
|
|
2444
|
+
|| typeof p.anchor !== 'string' || !CITE_ANCHOR.test(p.anchor) || out.has(p.anchor) || !(p.claim === null || text(p.claim, 300))
|
|
2445
|
+
|| !text(p.assumedBy, 200) || !text(p.assumedAt, 40) || Number.isNaN(Date.parse(p.assumedAt)) || p.via !== 'chip') continue;
|
|
2446
|
+
const cited = state.events.find((row) => row.type === 'citation' && row.eventId === p.citationId);
|
|
2447
|
+
if (!cited || cited.turnId !== turnId || !(cited.payload?.entries ?? []).some((entry) => entry?.anchor === p.anchor)) continue;
|
|
2448
|
+
out.set(p.anchor, { anchor: p.anchor, assumedBy: p.assumedBy, assumedAt: p.assumedAt });
|
|
2449
|
+
}
|
|
2450
|
+
return [...out.values()];
|
|
2451
|
+
}
|
|
2452
|
+
|
|
2453
|
+
/** Who and when, in words: an account id is "you" (FloLess holds no display name), a date is "23 Oct 2026". */
|
|
2454
|
+
function assumedWho(record) {
|
|
2455
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-/i.test(record.assumedBy) || record.assumedBy === 'You' ? 'you' : record.assumedBy;
|
|
2456
|
+
}
|
|
2457
|
+
function assumedWhen(record) {
|
|
2458
|
+
return new Date(record.assumedAt).toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric' });
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2258
2461
|
/**
|
|
2259
2462
|
* #2471: what "Read by AI" says, by kind — each kind has its own receipts. A member counts only by its @-mention line in
|
|
2260
2463
|
* the person's message; a file only by a look that showed it, and one that merely went with the question says so.
|
|
2261
2464
|
*/
|
|
2262
2465
|
function citationReadWords(entry) {
|
|
2263
2466
|
if (entry.kind === 'member') return entry.read === 'mentioned' ? 'yes, its @-mention was in your message' : 'not recorded';
|
|
2467
|
+
// #2701: FloLess keeps the AI's request to read a file of the project folder, never what came back, so it is not "yes".
|
|
2468
|
+
if (entry.kind === 'project-file') return entry.read === 'requested' ? 'not confirmed, the AI asked to read it but FloLess has no record of what came back' : 'not recorded';
|
|
2264
2469
|
if (entry.kind === 'attachment') {
|
|
2265
2470
|
if (entry.read === 'looked') {
|
|
2266
2471
|
const pages = Array.isArray(entry.ref?.pagesLooked) ? entry.ref.pagesLooked : [];
|
|
2267
2472
|
return pages.length ? `yes, ${pages.length === 1 ? 'page' : 'pages'} ${pages.join(', ')}` : 'yes';
|
|
2268
2473
|
}
|
|
2269
|
-
// In the message itself: a
|
|
2270
|
-
|
|
2474
|
+
// In the message itself, checked against the attached file: a picture as its bytes (#2580), a data file as its text
|
|
2475
|
+
// cut at 16,000 characters.
|
|
2476
|
+
if (entry.read === 'in-message') {
|
|
2477
|
+
return String(entry.ref?.mediaType || '').startsWith('image/') ? 'yes, the picture was in your message'
|
|
2478
|
+
: 'yes, its text was in your message (up to the first 16,000 characters)';
|
|
2479
|
+
}
|
|
2271
2480
|
return entry.read === 'sent' ? 'not recorded, it went with your question' : 'not recorded';
|
|
2272
2481
|
}
|
|
2273
2482
|
return CITATION_READ[entry.read] || CITATION_READ.no;
|
|
2274
2483
|
}
|
|
2275
2484
|
|
|
2276
2485
|
function citationProvenance(entry) {
|
|
2486
|
+
// #2643: a source the person chose says who chose it, and claims no AI read: the choice records none.
|
|
2487
|
+
if (entry.chosen) return `Found: yes · Chosen by ${assumedWho({ assumedBy: entry.chosen.chosenBy })}, ${assumedWhen({ assumedAt: entry.chosen.chosenAt })} · Read by AI: this choice records none · Checked: no`;
|
|
2277
2488
|
return `Found: yes · Read by AI: ${citationReadWords(entry)} · Checked: no`;
|
|
2278
2489
|
}
|
|
2279
2490
|
|
|
2280
2491
|
/** The chip's tag, in words: never a colour or a tick. */
|
|
2281
2492
|
function citationMarks(entry) {
|
|
2493
|
+
if (entry.chosen) return `FOUND · CHOSEN BY ${assumedWho({ assumedBy: entry.chosen.chosenBy }).toUpperCase()}`;
|
|
2282
2494
|
if (entry.kind === 'attachment' && entry.read === 'sent') return 'FOUND · SENT WITH QUESTION';
|
|
2283
2495
|
return ['whole-sheet', 'tiles', 'yes', 'mentioned', 'looked', 'in-message'].includes(entry.read) ? 'FOUND · READ BY AI' : 'FOUND';
|
|
2284
2496
|
}
|
|
2285
2497
|
|
|
2286
2498
|
/** A member is named with its profile, which is what tells it from a member with a like mark. */
|
|
2287
2499
|
function citationLabel(entry) {
|
|
2288
|
-
return entry.kind === 'member' && entry.status === 'resolved' && entry.ref?.profile ? `${entry.label} · ${entry.ref.profile}` : entry.label;
|
|
2500
|
+
return entry.kind === 'member' && (entry.status === 'resolved' || entry.chosen) && entry.ref?.profile ? `${entry.label} · ${entry.ref.profile}` : entry.label;
|
|
2289
2501
|
}
|
|
2290
2502
|
|
|
2291
2503
|
function citationUrl(row, what, extra = '') {
|
|
@@ -2317,24 +2529,51 @@
|
|
|
2317
2529
|
}
|
|
2318
2530
|
const row = index.byAnchor.get(spec.anchor) ?? null;
|
|
2319
2531
|
const resolved = row?.entry.status === 'resolved';
|
|
2320
|
-
|
|
2532
|
+
// #2643: a source the person chose numbers the claim like a cited one, and says who chose it.
|
|
2533
|
+
const chosen = !resolved && row?.choice ? row.choice : null;
|
|
2534
|
+
const sourced = resolved || !!chosen;
|
|
2535
|
+
const marker = button(sourced ? String(row.number) : '?', 'shell.chat-cite-anchor', `ai-chat-cite${sourced ? '' : ' unresolved'}`);
|
|
2321
2536
|
marker.dataset.turnId = turnId || '';
|
|
2322
2537
|
marker.dataset.anchor = spec.anchor;
|
|
2323
|
-
const
|
|
2538
|
+
const assumed = !sourced && row?.assumption ? row.assumption : null;
|
|
2539
|
+
const label = resolved ? citationLabel(row.entry) : chosen ? citationLabel(chosenViewRow(row, chosen).entry) : assumed ? 'assumption, no source' : 'no source';
|
|
2324
2540
|
// No citation for this anchor on this page is "none recorded", not "none found": the AI may have given none, or the
|
|
2325
2541
|
// record has not reached this page yet.
|
|
2326
|
-
const missing =
|
|
2542
|
+
const missing = assumed ? `No source. Assumed by ${assumedWho(assumed)} on ${assumedWhen(assumed)}`
|
|
2543
|
+
: row ? 'No source was found for this claim' : 'No source is recorded for this claim';
|
|
2544
|
+
if (assumed) marker.classList.add('assumed');
|
|
2545
|
+
if (chosen) marker.classList.add('chosen');
|
|
2327
2546
|
marker.dataset.commandInstanceLabel = label;
|
|
2328
|
-
|
|
2329
|
-
marker.
|
|
2547
|
+
const chosenTip = chosen ? `Source chosen by ${assumedWho({ assumedBy: chosen.chosenBy })}: ${label}. No AI read is recorded for this choice, and nothing checked the claim` : '';
|
|
2548
|
+
marker.setAttribute('aria-label', resolved ? `Source ${row.number}: ${label}` : chosen ? `Source ${row.number}: ${chosenTip}` : missing);
|
|
2549
|
+
marker.dataset.tip = resolved ? `${label} · ${citationProvenance(row.entry)}` : chosen ? chosenTip : missing;
|
|
2330
2550
|
marker.addEventListener('click', () => {
|
|
2331
2551
|
const chip = [...ui.feed.querySelectorAll('.ai-chat-source')].find((node) => node.dataset.turnId === turnId && node.dataset.anchor === spec.anchor);
|
|
2332
|
-
if (!chip) { announce(
|
|
2552
|
+
if (!chip) { announce(sourced ? 'Its source is listed under the answer.' : 'The AI gave no source for this claim.'); return; }
|
|
2333
2553
|
chip.scrollIntoView({ block: 'nearest' });
|
|
2334
2554
|
chip.classList.remove('answer-jump'); void chip.offsetWidth; chip.classList.add('answer-jump');
|
|
2335
2555
|
(chip.querySelector('button') ?? chip).focus({ preventScroll: true });
|
|
2336
2556
|
});
|
|
2337
2557
|
slot.replaceWith(marker);
|
|
2558
|
+
if (assumed) {
|
|
2559
|
+
// The person's decision, beside the "?" that stays: it is still not a source. A solid edge tells it from the AI's own tag.
|
|
2560
|
+
const tag = document.createElement('span'); tag.className = 'ai-chat-assume by-person';
|
|
2561
|
+
tag.textContent = 'Assumption';
|
|
2562
|
+
tag.dataset.tip = `${assumedWho(assumed) === 'you' ? 'You' : assumedWho(assumed)} chose to go on with this as an assumption (${assumedWhen(assumed)}). It has no source.`;
|
|
2563
|
+
marker.after(tag);
|
|
2564
|
+
}
|
|
2565
|
+
}
|
|
2566
|
+
// The AI often marks the same claim with its own Assumption tag just after the "?": one tag then says both, rather
|
|
2567
|
+
// than two identical words side by side. It takes the person's edge, and its tip names both authors.
|
|
2568
|
+
for (const mine of body.querySelectorAll('.ai-chat-assume.by-person')) {
|
|
2569
|
+
// Only the tag right beside it, with nothing but spaces between: an AI tag on another claim further on is not
|
|
2570
|
+
// the person's decision, and must never be shown as one.
|
|
2571
|
+
let theirs = mine.nextSibling;
|
|
2572
|
+
while (theirs && theirs.nodeType === 3 && !theirs.textContent.trim()) theirs = theirs.nextSibling;
|
|
2573
|
+
if (!theirs?.matches?.('.ai-chat-assume:not(.by-person)')) continue;
|
|
2574
|
+
theirs.classList.add('by-person');
|
|
2575
|
+
theirs.dataset.tip = `${mine.dataset.tip} ${theirs.dataset.tip}`;
|
|
2576
|
+
mine.remove();
|
|
2338
2577
|
}
|
|
2339
2578
|
}
|
|
2340
2579
|
|
|
@@ -2347,18 +2586,40 @@
|
|
|
2347
2586
|
const number = document.createElement('span'); number.className = 'ai-chat-source-n';
|
|
2348
2587
|
number.textContent = row.number ? String(row.number) : '?';
|
|
2349
2588
|
chip.append(number);
|
|
2589
|
+
if (row.entry.status !== 'resolved' && row.choice) return chosenChip(chip, turnId, row);
|
|
2350
2590
|
const entry = row.entry;
|
|
2351
2591
|
if (entry.status !== 'resolved') {
|
|
2352
|
-
chip.classList.add('unresolved');
|
|
2353
2592
|
const why = document.createElement('span'); why.className = 'ai-chat-source-why';
|
|
2354
|
-
why.textContent = `No source: ${entry.reason}`;
|
|
2355
2593
|
const ask = button('Ask for the source', 'shell.chat-cite-ask', 'ai-chat-source-action');
|
|
2356
2594
|
ask.dataset.tip = 'Puts a question in the message box asking where this comes from. Nothing is sent until you press Send';
|
|
2357
|
-
ask.addEventListener('click', () => addToMessageBox(`${unsourcedClaim(turnId, row.anchor)}: which sheet, model member, attached file or Knowledge page does it come from? Cite it, or say plainly that it is an assumption.`));
|
|
2595
|
+
ask.addEventListener('click', () => addToMessageBox(`${unsourcedClaim(turnId, row.anchor)}: which sheet, model member, attached file, project file or Knowledge page does it come from? Cite it, or say plainly that it is an assumption.`));
|
|
2596
|
+
// #2643: the person names the source themself: a sheet, model member or (#2692) Knowledge page of a project in this
|
|
2597
|
+
// conversation, or a file sent with one of its messages.
|
|
2598
|
+
const choose = button('Choose a source…', 'shell.chat-cite-choose', 'ai-chat-source-action');
|
|
2599
|
+
choose.dataset.tip = 'Pick the sheet, model member, Knowledge page or attached file this claim comes from. It is recorded as chosen by you, with the date; nothing checks the claim';
|
|
2600
|
+
choose.setAttribute('aria-haspopup', 'dialog');
|
|
2601
|
+
choose.addEventListener('click', () => openSourcePicker(row, turnId, null));
|
|
2602
|
+
if (row.assumption) {
|
|
2603
|
+
// #2642: the person's recorded decision. Still "?" — an assumption is not a source, and nothing was checked.
|
|
2604
|
+
chip.classList.add('assumed');
|
|
2605
|
+
number.setAttribute('aria-label', 'Assumption, no source');
|
|
2606
|
+
why.textContent = `Assumed by ${assumedWho(row.assumption)}, ${assumedWhen(row.assumption)}, no source.`;
|
|
2607
|
+
const marks = document.createElement('span'); marks.className = 'ai-chat-source-marks';
|
|
2608
|
+
marks.textContent = 'ASSUMPTION';
|
|
2609
|
+
marks.dataset.tip = 'Your decision to go on without a source. Nothing was found or checked for this claim. The AI is reminded of it with each message you send';
|
|
2610
|
+
chip.append(why, marks, sourceActions(ask, choose));
|
|
2611
|
+
return chip;
|
|
2612
|
+
}
|
|
2613
|
+
chip.classList.add('unresolved');
|
|
2614
|
+
// What was cited, in the AI's own words, so the person knows which source FloLess could not match.
|
|
2615
|
+
const cited = document.createElement('span'); cited.className = 'ai-chat-source-cited';
|
|
2616
|
+
cited.textContent = entry.label;
|
|
2617
|
+
cited.dataset.tip = 'What the AI cited';
|
|
2618
|
+
why.textContent = `No source: ${entry.reason}`;
|
|
2358
2619
|
const assume = button('Go on with this as an assumption', 'shell.chat-cite-assume', 'ai-chat-source-action');
|
|
2359
|
-
assume.dataset.tip = '
|
|
2360
|
-
assume.addEventListener('click', () =>
|
|
2361
|
-
chip.append(why, ask, assume);
|
|
2620
|
+
assume.dataset.tip = 'Records that you chose to go on without a source, with your name and the date. The claim is labelled Assumption, and the AI is told with your next message. Nothing is sent now';
|
|
2621
|
+
assume.addEventListener('click', () => assumeClaim(row, turnId, chip, assume));
|
|
2622
|
+
chip.append(cited, why, sourceActions(ask, choose, assume));
|
|
2362
2623
|
return chip;
|
|
2363
2624
|
}
|
|
2364
2625
|
if (entry.kind === 'sheet') {
|
|
@@ -2380,9 +2641,521 @@
|
|
|
2380
2641
|
const marks = document.createElement('span'); marks.className = 'ai-chat-source-marks';
|
|
2381
2642
|
marks.textContent = citationMarks(entry);
|
|
2382
2643
|
chip.append(open, marks);
|
|
2644
|
+
// A source cited after the person went on without one, or chose one: their decision stays visible, and the source
|
|
2645
|
+
// is still unchecked.
|
|
2646
|
+
const before = [row.assumption ? `Earlier assumed by ${assumedWho(row.assumption)}, ${assumedWhen(row.assumption)}` : '',
|
|
2647
|
+
row.choices?.length ? `Earlier ${assumedWho({ assumedBy: row.choices.at(-1).chosenBy }) === 'you' ? 'you' : assumedWho({ assumedBy: row.choices.at(-1).chosenBy })} chose ${row.choices.at(-1).source.label}` : '']
|
|
2648
|
+
.filter(Boolean);
|
|
2649
|
+
if (before.length) {
|
|
2650
|
+
const earlier = document.createElement('span'); earlier.className = 'ai-chat-source-note';
|
|
2651
|
+
earlier.textContent = before.join(' · ');
|
|
2652
|
+
chip.append(earlier);
|
|
2653
|
+
}
|
|
2654
|
+
return chip;
|
|
2655
|
+
}
|
|
2656
|
+
|
|
2657
|
+
/** The person's ways on from a claim with no source, in one row that wraps between buttons, never inside one. */
|
|
2658
|
+
function sourceActions(...buttons) {
|
|
2659
|
+
const actions = document.createElement('span'); actions.className = 'ai-chat-source-actions';
|
|
2660
|
+
actions.append(...buttons);
|
|
2661
|
+
return actions;
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
/**
|
|
2665
|
+
* #2643: a claim whose source the person chose. Numbered like a cited source, opening the source the server resolved
|
|
2666
|
+
* and recorded; its tag says who chose it and never that the AI read it. "Change…" picks another (the record keeps both).
|
|
2667
|
+
*/
|
|
2668
|
+
function chosenChip(chip, turnId, row) {
|
|
2669
|
+
const view = chosenViewRow(row, row.choice);
|
|
2670
|
+
const entry = view.entry;
|
|
2671
|
+
chip.classList.add('chosen');
|
|
2672
|
+
if (entry.kind === 'sheet') {
|
|
2673
|
+
const thumb = document.createElement('img'); thumb.alt = ''; thumb.loading = 'lazy';
|
|
2674
|
+
// Only the picture FloLess held when it was chosen, byte for byte (never a render); a changed picture has none.
|
|
2675
|
+
const preview = citationUrl(view, 'image', '&thumb=1');
|
|
2676
|
+
if (preview) {
|
|
2677
|
+
thumb.src = preview;
|
|
2678
|
+
thumb.addEventListener('error', () => thumb.remove(), { once: true });
|
|
2679
|
+
chip.append(thumb);
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
const label = citationLabel(entry);
|
|
2683
|
+
const open = button(label, 'shell.chat-cite-open-chosen', 'ai-chat-answer-open ai-chat-source-open');
|
|
2684
|
+
open.dataset.commandInstanceLabel = label;
|
|
2685
|
+
open.setAttribute('aria-label', `Open ${label}`);
|
|
2686
|
+
open.dataset.tip = citationProvenance(entry);
|
|
2687
|
+
open.addEventListener('click', () => openCitedSource(view, turnId));
|
|
2688
|
+
const marks = document.createElement('span'); marks.className = 'ai-chat-source-marks';
|
|
2689
|
+
marks.textContent = citationMarks(entry);
|
|
2690
|
+
marks.dataset.tip = 'A person picked this source. No AI read is recorded for this choice, and nothing checked the claim';
|
|
2691
|
+
const change = button('Change…', 'shell.chat-cite-change', 'ai-chat-source-action quiet');
|
|
2692
|
+
change.setAttribute('aria-label', 'Change the source for this claim');
|
|
2693
|
+
change.setAttribute('aria-haspopup', 'dialog');
|
|
2694
|
+
change.dataset.tip = 'Pick a different source. The earlier choice stays in the record';
|
|
2695
|
+
change.addEventListener('click', () => openSourcePicker(row, turnId, row.choice.eventId));
|
|
2696
|
+
chip.append(open, marks, change);
|
|
2697
|
+
const earlier = row.choices.length > 1 ? row.choices[row.choices.length - 2] : null;
|
|
2698
|
+
const before = [row.assumption ? `Earlier assumed by ${assumedWho(row.assumption)}, ${assumedWhen(row.assumption)}` : '',
|
|
2699
|
+
earlier ? `Changed from ${earlier.source.label}` : ''].filter(Boolean);
|
|
2700
|
+
if (before.length) {
|
|
2701
|
+
const note = document.createElement('span'); note.className = 'ai-chat-source-note';
|
|
2702
|
+
note.textContent = before.join(' · ');
|
|
2703
|
+
chip.append(note);
|
|
2704
|
+
}
|
|
2383
2705
|
return chip;
|
|
2384
2706
|
}
|
|
2385
2707
|
|
|
2708
|
+
/**
|
|
2709
|
+
* #2642: record the person's "go on with this as an assumption". Nothing goes in the message box and nothing is sent;
|
|
2710
|
+
* the server writes it with the signed-in account and the date. The conversation is the one the chip was painted for:
|
|
2711
|
+
* a reply that lands after the person moved to another conversation changes nothing on screen.
|
|
2712
|
+
*/
|
|
2713
|
+
async function assumeClaim(row, turnId, chip, assume) {
|
|
2714
|
+
if (assume.getAttribute('aria-busy') === 'true' || !row.chatId) return;
|
|
2715
|
+
chip.querySelector('.ai-chat-source-note')?.remove();
|
|
2716
|
+
// Busy, not disabled: a disabled button drops the keyboard focus to the page.
|
|
2717
|
+
assume.setAttribute('aria-busy', 'true'); assume.setAttribute('aria-disabled', 'true');
|
|
2718
|
+
assume.textContent = 'Saving…';
|
|
2719
|
+
const claim = unsourcedClaimWords(turnId, row.anchor);
|
|
2720
|
+
let saved = null; let problem = '';
|
|
2721
|
+
try {
|
|
2722
|
+
const result = await request(`/api/chat/conversations/${encodeURIComponent(row.chatId)}/citations/${encodeURIComponent(row.citationId)}/assume`, {
|
|
2723
|
+
method: 'POST', body: JSON.stringify({ owner: row.ownerObject, turnId, anchor: row.anchor, claim: claim || null }),
|
|
2724
|
+
});
|
|
2725
|
+
saved = result?.event ?? null;
|
|
2726
|
+
} catch (error) {
|
|
2727
|
+
// The server's own sentence when it says why nothing was recorded; anything else is a plain "try again".
|
|
2728
|
+
problem = ['chat-cite-assume-stale', 'chat-cite-assume-unknown', 'chat-cite-assume-unreadable'].includes(error?.code)
|
|
2729
|
+
? String(error.message) : 'Could not save your choice. Try again.';
|
|
2730
|
+
}
|
|
2731
|
+
if (state.chat?.chatId !== row.chatId) return;
|
|
2732
|
+
if (saved && !state.events.some((known) => known.eventId === saved.eventId)) state.events.push(saved);
|
|
2733
|
+
if (saved) {
|
|
2734
|
+
paintEvents();
|
|
2735
|
+
const after = [...ui.feed.querySelectorAll('.ai-chat-source')].find((node) => node.dataset.turnId === (turnId || '') && node.dataset.anchor === row.anchor);
|
|
2736
|
+
after?.querySelector('[data-command-id="shell.chat-cite-ask"]')?.focus({ preventScroll: true });
|
|
2737
|
+
const record = citationIndex(turnId).byAnchor.get(row.anchor)?.assumption;
|
|
2738
|
+
announce(record ? `Marked as an assumption by ${assumedWho(record)}, ${assumedWhen(record)}. No source.` : 'Your choice was saved.');
|
|
2739
|
+
return;
|
|
2740
|
+
}
|
|
2741
|
+
assume.removeAttribute('aria-busy'); assume.removeAttribute('aria-disabled');
|
|
2742
|
+
assume.textContent = 'Go on with this as an assumption';
|
|
2743
|
+
const note = document.createElement('span'); note.className = 'ai-chat-source-note warn'; note.setAttribute('role', 'status');
|
|
2744
|
+
note.textContent = problem;
|
|
2745
|
+
chip.append(note);
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2748
|
+
/** #2692: what the picker can list, in order: the project's drawings and model, its Knowledge, and this conversation's files. */
|
|
2749
|
+
const SOURCE_KINDS = [
|
|
2750
|
+
{ id: 'refs', label: 'Drawings & model', search: 'Search sheets and model members', list: 'Sheets and model members' },
|
|
2751
|
+
{ id: 'kb', label: 'Knowledge', search: 'Search this project’s Knowledge', list: 'Knowledge pages' },
|
|
2752
|
+
{ id: 'files', label: 'Attached files', search: 'Search attached files by name', list: 'Attached files' },
|
|
2753
|
+
];
|
|
2754
|
+
|
|
2755
|
+
/**
|
|
2756
|
+
* #2643: "Choose a source…" — the @ list's sources (the project's sheets and model members, the same rows and the same
|
|
2757
|
+
* read) and, #2692, the project's published Knowledge pages and the files sent with this conversation's messages, in a
|
|
2758
|
+
* small dialog under the claim's chip. Not the message box's @ list: nothing goes in the message. The pick is sent by
|
|
2759
|
+
* identity with a request id made when it is picked (a retry sends the same one); the server resolves the source from
|
|
2760
|
+
* FloLess's own records. Everything the save needs is taken now, from the chip as painted: a reply that lands after the
|
|
2761
|
+
* person moved on (another conversation, the list closed) changes nothing on screen.
|
|
2762
|
+
*/
|
|
2763
|
+
function openSourcePicker(row, turnId, replaces) {
|
|
2764
|
+
closeSourcePicker(false);
|
|
2765
|
+
if (!row.chatId) { announce('Open this conversation again to choose a source.'); return; }
|
|
2766
|
+
const command = replaces ? 'shell.chat-cite-change' : 'shell.chat-cite-choose';
|
|
2767
|
+
const picker = { row, turnId, replaces, command, chatId: row.chatId, projects: null, projectId: null, kind: null, query: '', items: [], more: [],
|
|
2768
|
+
status: 'loading', note: '', active: -1, seq: 0, timer: null, saving: null, problem: '', pending: null };
|
|
2769
|
+
state.sourcePicker = picker;
|
|
2770
|
+
const dialog = document.createElement('div'); dialog.className = 'ai-chat-source-picker';
|
|
2771
|
+
dialog.setAttribute('role', 'dialog'); dialog.setAttribute('aria-label', 'Choose a source');
|
|
2772
|
+
const head = Object.assign(document.createElement('p'), { className: 'ai-chat-source-picker-head', textContent: 'Choose the source for this claim' });
|
|
2773
|
+
const kinds = document.createElement('div'); kinds.className = 'ai-chat-source-picker-kinds'; kinds.hidden = true;
|
|
2774
|
+
kinds.setAttribute('role', 'group'); kinds.setAttribute('aria-label', 'What to choose from');
|
|
2775
|
+
const projects = document.createElement('div'); projects.className = 'ai-chat-source-picker-projects'; projects.hidden = true;
|
|
2776
|
+
projects.setAttribute('role', 'group'); projects.setAttribute('aria-label', 'Project');
|
|
2777
|
+
const input = document.createElement('input');
|
|
2778
|
+
input.type = 'search'; input.className = 'ai-chat-source-picker-input'; input.placeholder = SOURCE_KINDS[0].search;
|
|
2779
|
+
input.setAttribute('role', 'combobox'); input.setAttribute('aria-autocomplete', 'list'); input.setAttribute('aria-expanded', 'true');
|
|
2780
|
+
input.setAttribute('aria-label', SOURCE_KINDS[0].search); input.autocomplete = 'off'; input.spellcheck = false;
|
|
2781
|
+
const list = document.createElement('div'); list.className = 'ai-chat-source-picker-list'; list.id = 'chat-source-picker-list';
|
|
2782
|
+
list.setAttribute('role', 'listbox'); list.setAttribute('aria-label', SOURCE_KINDS[0].list);
|
|
2783
|
+
input.setAttribute('aria-controls', list.id);
|
|
2784
|
+
const foot = document.createElement('p'); foot.className = 'ai-chat-source-picker-foot'; foot.setAttribute('role', 'status');
|
|
2785
|
+
// What choosing is, and is not: a record of the person's pick, never a check of the claim.
|
|
2786
|
+
const hint = Object.assign(document.createElement('p'), { className: 'ai-chat-source-picker-limit',
|
|
2787
|
+
textContent: 'Choosing records that you picked this source. It does not show the claim is correct.' });
|
|
2788
|
+
dialog.append(head, kinds, projects, input, list, foot, hint);
|
|
2789
|
+
picker.dialog = dialog; picker.input = input; picker.list = list; picker.foot = foot; picker.projectRow = projects; picker.kindRow = kinds;
|
|
2790
|
+
(ui.feed.closest('.ai-chat-shell') || document.body).append(dialog);
|
|
2791
|
+
input.addEventListener('input', () => { picker.query = input.value; searchSources(picker, picker.kind === 'files' ? 0 : 200); });
|
|
2792
|
+
input.addEventListener('keydown', (event) => sourcePickerKey(picker, event));
|
|
2793
|
+
dialog.addEventListener('keydown', (event) => { if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); closeSourcePicker(true); } });
|
|
2794
|
+
// A click elsewhere closes it and leaves the focus where the person clicked.
|
|
2795
|
+
picker.outside = (event) => { if (!dialog.contains(event.target)) closeSourcePicker(false); };
|
|
2796
|
+
picker.place = () => placeSourcePicker(picker);
|
|
2797
|
+
document.addEventListener('pointerdown', picker.outside, true);
|
|
2798
|
+
ui.feed.addEventListener('scroll', picker.place, { passive: true });
|
|
2799
|
+
window.addEventListener('resize', picker.place);
|
|
2800
|
+
paintSourcePicker(picker);
|
|
2801
|
+
input.focus({ preventScroll: true });
|
|
2802
|
+
loadSourceProjects(picker);
|
|
2803
|
+
}
|
|
2804
|
+
|
|
2805
|
+
function closeSourcePicker(refocus) {
|
|
2806
|
+
const picker = state.sourcePicker;
|
|
2807
|
+
if (!picker) return;
|
|
2808
|
+
state.sourcePicker = null;
|
|
2809
|
+
clearTimeout(picker.timer);
|
|
2810
|
+
document.removeEventListener('pointerdown', picker.outside, true);
|
|
2811
|
+
ui.feed.removeEventListener('scroll', picker.place);
|
|
2812
|
+
window.removeEventListener('resize', picker.place);
|
|
2813
|
+
picker.dialog.remove();
|
|
2814
|
+
if (refocus) {
|
|
2815
|
+
const chip = sourceChip(picker.turnId, picker.row.anchor);
|
|
2816
|
+
[...(chip?.querySelectorAll('button') ?? [])].find((control) => control.dataset.commandId === picker.command)?.focus({ preventScroll: true });
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
|
|
2820
|
+
function sourceChip(turnId, anchor) {
|
|
2821
|
+
return [...ui.feed.querySelectorAll('.ai-chat-source')].find((node) => node.dataset.turnId === (turnId || '') && node.dataset.anchor === anchor) ?? null;
|
|
2822
|
+
}
|
|
2823
|
+
|
|
2824
|
+
/** Under the claim's chip as it is now (the feed repaints), above it when there is no room below; inside the window. */
|
|
2825
|
+
function placeSourcePicker(picker) {
|
|
2826
|
+
const chip = sourceChip(picker.turnId, picker.row.anchor);
|
|
2827
|
+
if (!chip) { closeSourcePicker(false); return; }
|
|
2828
|
+
const at = chip.getBoundingClientRect();
|
|
2829
|
+
const box = picker.dialog;
|
|
2830
|
+
const width = Math.min(360, window.innerWidth - 32);
|
|
2831
|
+
box.style.width = `${width}px`;
|
|
2832
|
+
box.style.left = `${Math.round(Math.max(16, Math.min(at.left, window.innerWidth - width - 16)))}px`;
|
|
2833
|
+
const height = box.offsetHeight;
|
|
2834
|
+
const below = at.bottom + 4;
|
|
2835
|
+
box.style.top = `${Math.round(below + height <= window.innerHeight - 8 ? below : Math.max(8, at.top - height - 4))}px`;
|
|
2836
|
+
}
|
|
2837
|
+
|
|
2838
|
+
/**
|
|
2839
|
+
* #2692: the files a person may choose — those sent with a message, never a draft not yet sent and never a picture given as
|
|
2840
|
+
* an answer to a question card (the server's `choosableAttachments`), newest first.
|
|
2841
|
+
*/
|
|
2842
|
+
function choosableFiles() {
|
|
2843
|
+
return (state.chat?.attachments ?? []).filter((file) => file && file.turnId !== null && file.turnId !== undefined && file.purpose !== 'answer-evidence')
|
|
2844
|
+
.slice().sort((a, b) => String(b.createdAt).localeCompare(String(a.createdAt)));
|
|
2845
|
+
}
|
|
2846
|
+
|
|
2847
|
+
function fileSizeLabel(bytes) {
|
|
2848
|
+
const n = Number(bytes) || 0;
|
|
2849
|
+
if (n < 1024) return `${n} bytes`;
|
|
2850
|
+
if (n < 1024 * 1024) return `${Math.max(1, Math.round(n / 1024))} KB`;
|
|
2851
|
+
return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
2852
|
+
}
|
|
2853
|
+
|
|
2854
|
+
/**
|
|
2855
|
+
* #2692: one row of the list, whatever its kind: what is shown, and what is sent — the pick by identity, the project it is
|
|
2856
|
+
* in (none for a file) and the decision's key. Everything is taken from the answer that listed the row, never from the
|
|
2857
|
+
* picker's state at the moment of the click, so a Knowledge page carries the version it was listed from.
|
|
2858
|
+
*/
|
|
2859
|
+
function sourceItemOf(kind, value, projectId, generationId) {
|
|
2860
|
+
if (kind === 'files') {
|
|
2861
|
+
const pick = { kind: 'attachment', attachmentId: value.attachmentId };
|
|
2862
|
+
const name = value.fileName;
|
|
2863
|
+
return { key: JSON.stringify(['file', String(value.attachmentId).toLowerCase()]), pick, projectId: null, label: name, name,
|
|
2864
|
+
meta: `${fileSizeLabel(value.bytes)} · sent ${assumedWhen({ assumedAt: value.createdAt })}`, tip: `${name} · attached to this conversation` };
|
|
2865
|
+
}
|
|
2866
|
+
if (kind === 'kb') {
|
|
2867
|
+
const pick = { kind: 'kb-page', slug: value.slug, generationId };
|
|
2868
|
+
const name = value.title || value.slug;
|
|
2869
|
+
return { key: JSON.stringify(['kb', projectId, generationId, value.slug]), pick, projectId, label: name, name, meta: value.slug,
|
|
2870
|
+
tip: `Knowledge page ${name} · ${value.slug}` };
|
|
2871
|
+
}
|
|
2872
|
+
const item = mentionOf(value);
|
|
2873
|
+
return { key: JSON.stringify(['ref', projectId, item.key]), pick: item.pick, projectId, label: item.label,
|
|
2874
|
+
name: `${value.kind === 'sheet' ? 'Sheet' : 'Member'} ${item.label}`, meta: refDetail(value), tip: item.tip };
|
|
2875
|
+
}
|
|
2876
|
+
|
|
2877
|
+
async function loadSourceProjects(picker) {
|
|
2878
|
+
let projects = null;
|
|
2879
|
+
try {
|
|
2880
|
+
const result = await request(`/api/chat/conversations/${encodeURIComponent(picker.chatId)}/scope?${picker.row.owner}`, { timeoutMs: 15000 });
|
|
2881
|
+
projects = Array.isArray(result?.scope?.projects) ? result.scope.projects : [];
|
|
2882
|
+
} catch { projects = null; }
|
|
2883
|
+
if (state.sourcePicker !== picker || state.chat?.chatId !== picker.chatId) return;
|
|
2884
|
+
if (!projects) { picker.status = 'error'; picker.note = 'FloLess could not read which projects are in this conversation.'; paintSourcePicker(picker); return; }
|
|
2885
|
+
picker.projects = projects;
|
|
2886
|
+
picker.projectId = projects[0]?.projectId ?? null;
|
|
2887
|
+
// A conversation with a project starts on its drawings and model; one with only files, on its files.
|
|
2888
|
+
if (!projects.length && !choosableFiles().length) {
|
|
2889
|
+
picker.status = 'note';
|
|
2890
|
+
picker.note = 'Nothing to choose from yet: this conversation has no project and no file sent with a message. Ask for the source instead.';
|
|
2891
|
+
paintSourcePicker(picker);
|
|
2892
|
+
return;
|
|
2893
|
+
}
|
|
2894
|
+
setSourceKind(picker, projects.length ? 'refs' : 'files', false);
|
|
2895
|
+
}
|
|
2896
|
+
|
|
2897
|
+
/** Switches what the list shows. The search starts again, empty, and the focus stays where the person is. */
|
|
2898
|
+
function setSourceKind(picker, kind, keepFocus = true) {
|
|
2899
|
+
picker.kind = kind;
|
|
2900
|
+
picker.query = ''; picker.input.value = '';
|
|
2901
|
+
picker.items = []; picker.more = []; picker.active = -1; picker.problem = '';
|
|
2902
|
+
picker.status = 'loading';
|
|
2903
|
+
paintSourcePicker(picker);
|
|
2904
|
+
searchSources(picker, 0);
|
|
2905
|
+
if (!keepFocus) picker.input.focus({ preventScroll: true });
|
|
2906
|
+
}
|
|
2907
|
+
|
|
2908
|
+
function searchSources(picker, delay = 150) {
|
|
2909
|
+
clearTimeout(picker.timer);
|
|
2910
|
+
const seq = ++picker.seq;
|
|
2911
|
+
const kind = picker.kind;
|
|
2912
|
+
if (!kind) return;
|
|
2913
|
+
picker.stale = true;
|
|
2914
|
+
const settle = (fill) => {
|
|
2915
|
+
// A newer search, another kind or project, a closed list or another conversation: this answer is for a question
|
|
2916
|
+
// nobody is asking now.
|
|
2917
|
+
if (state.sourcePicker !== picker || picker.seq !== seq || picker.kind !== kind || state.chat?.chatId !== picker.chatId) return;
|
|
2918
|
+
picker.stale = false;
|
|
2919
|
+
picker.items = []; picker.more = [];
|
|
2920
|
+
fill();
|
|
2921
|
+
if (picker.status === 'options' && !picker.items.length) picker.status = 'empty';
|
|
2922
|
+
picker.active = picker.status === 'options' ? 0 : -1;
|
|
2923
|
+
paintSourcePicker(picker);
|
|
2924
|
+
announce(picker.status === 'options' ? `${picker.items.length} ${picker.items.length === 1 ? 'match' : 'matches'}`
|
|
2925
|
+
: picker.status === 'empty' ? 'No matches' : picker.note);
|
|
2926
|
+
};
|
|
2927
|
+
if (kind === 'files') {
|
|
2928
|
+
const q = picker.query.trim().toLowerCase();
|
|
2929
|
+
settle(() => {
|
|
2930
|
+
const files = choosableFiles();
|
|
2931
|
+
if (!files.length) { picker.status = 'note'; picker.note = 'No file has been sent with a message in this conversation yet. A file appears here once it is sent.'; return; }
|
|
2932
|
+
picker.items = files.filter((file) => !q || String(file.fileName).toLowerCase().includes(q)).map((file) => sourceItemOf('files', file, null, null));
|
|
2933
|
+
picker.status = 'options';
|
|
2934
|
+
});
|
|
2935
|
+
return;
|
|
2936
|
+
}
|
|
2937
|
+
const projectId = picker.projectId;
|
|
2938
|
+
if (!projectId) {
|
|
2939
|
+
settle(() => { picker.status = 'note'; picker.note = kind === 'kb' ? 'This conversation has no project, so there is no Knowledge to choose from.'
|
|
2940
|
+
: 'This conversation has no project, so there are no sheets or model members to choose from.'; });
|
|
2941
|
+
return;
|
|
2942
|
+
}
|
|
2943
|
+
picker.timer = setTimeout(async () => {
|
|
2944
|
+
let body = null;
|
|
2945
|
+
const url = kind === 'kb'
|
|
2946
|
+
? `/api/chat/conversations/${encodeURIComponent(picker.chatId)}/knowledge?${picker.row.owner}&projectId=${encodeURIComponent(projectId)}&q=${encodeURIComponent(picker.query)}&limit=20`
|
|
2947
|
+
: `/api/projects/${encodeURIComponent(projectId)}/refs?q=${encodeURIComponent(picker.query)}&kinds=sheet,member`;
|
|
2948
|
+
try { body = await request(url); } catch { body = null; }
|
|
2949
|
+
if (picker.projectId !== projectId) return;
|
|
2950
|
+
settle(() => {
|
|
2951
|
+
if (!body) {
|
|
2952
|
+
picker.status = 'error';
|
|
2953
|
+
picker.note = kind === 'kb' ? 'FloLess could not read this project’s Knowledge just now.' : 'FloLess could not list this project’s sheets and members just now.';
|
|
2954
|
+
} else if (kind === 'kb') {
|
|
2955
|
+
const generationId = body.generation?.generationId;
|
|
2956
|
+
if (!generationId) { picker.status = 'note'; picker.note = 'This project has no published Knowledge yet.'; return; }
|
|
2957
|
+
if (body.needsQuery) { picker.status = 'note'; picker.note = 'Type to search this project’s Knowledge.'; return; }
|
|
2958
|
+
picker.items = (Array.isArray(body.pages) ? body.pages : []).filter((page) => page && typeof page.slug === 'string')
|
|
2959
|
+
.map((page) => sourceItemOf('kb', page, projectId, generationId));
|
|
2960
|
+
// A search that could not look at every page, or found more than it lists, says so: "no match" is never claimed.
|
|
2961
|
+
if (body.incomplete) picker.more.push('FloLess could not look through every page just now, so some may be missing.');
|
|
2962
|
+
if (body.moreMatches) picker.more.push('More pages match. Type more of the name to narrow the list.');
|
|
2963
|
+
picker.status = 'options';
|
|
2964
|
+
if (!picker.items.length && picker.more.length) { picker.status = 'note'; picker.note = picker.more.shift(); }
|
|
2965
|
+
} else if (body.status && body.status !== 'ok') { picker.status = 'note'; picker.note = String(body.note || ''); }
|
|
2966
|
+
else {
|
|
2967
|
+
picker.items = (Array.isArray(body.refs) ? body.refs : []).map((ref) => sourceItemOf('refs', ref, projectId, null));
|
|
2968
|
+
const heldBack = Number(body.heldBack) || 0;
|
|
2969
|
+
if (heldBack) picker.more.push(`${heldBack} more match. Type more of the name to narrow the list.`);
|
|
2970
|
+
picker.status = 'options';
|
|
2971
|
+
}
|
|
2972
|
+
});
|
|
2973
|
+
}, delay);
|
|
2974
|
+
}
|
|
2975
|
+
|
|
2976
|
+
function paintSourcePicker(picker) {
|
|
2977
|
+
const { list, foot, input, projectRow, kindRow } = picker;
|
|
2978
|
+
const kind = SOURCE_KINDS.find((row) => row.id === picker.kind) ?? SOURCE_KINDS[0];
|
|
2979
|
+
// The two rows are rebuilt on every paint: a person on one of their buttons stays on it (by what it does).
|
|
2980
|
+
const focused = document.activeElement;
|
|
2981
|
+
const refocus = focused && (kindRow.contains(focused) || projectRow.contains(focused)) ? focused.dataset.commandId : null;
|
|
2982
|
+
kindRow.replaceChildren();
|
|
2983
|
+
kindRow.hidden = !picker.kind;
|
|
2984
|
+
for (const option of picker.kind ? SOURCE_KINDS : []) {
|
|
2985
|
+
const pick = button(option.label, `shell.chat-cite-choose-kind#${option.id}`, 'ai-chat-source-picker-project');
|
|
2986
|
+
pick.setAttribute('aria-pressed', String(option.id === picker.kind));
|
|
2987
|
+
pick.addEventListener('click', () => { if (picker.kind !== option.id && !picker.saving) setSourceKind(picker, option.id); });
|
|
2988
|
+
kindRow.append(pick);
|
|
2989
|
+
}
|
|
2990
|
+
projectRow.replaceChildren();
|
|
2991
|
+
const listsProjects = picker.kind !== 'files' && picker.projects?.length > 1;
|
|
2992
|
+
projectRow.hidden = !listsProjects;
|
|
2993
|
+
for (const project of listsProjects ? picker.projects : []) {
|
|
2994
|
+
const pick = button(project.label || 'Project', `shell.chat-cite-choose-project#${project.projectId}`, 'ai-chat-source-picker-project');
|
|
2995
|
+
pick.setAttribute('aria-pressed', String(project.projectId === picker.projectId));
|
|
2996
|
+
pick.addEventListener('click', () => {
|
|
2997
|
+
if (picker.saving) return;
|
|
2998
|
+
picker.projectId = project.projectId; picker.status = 'loading'; picker.items = []; picker.more = [];
|
|
2999
|
+
paintSourcePicker(picker); searchSources(picker, 0); input.focus();
|
|
3000
|
+
});
|
|
3001
|
+
projectRow.append(pick);
|
|
3002
|
+
}
|
|
3003
|
+
if (refocus) [...kindRow.children, ...projectRow.children].find((node) => node.dataset.commandId === refocus)?.focus({ preventScroll: true });
|
|
3004
|
+
input.placeholder = kind.search; input.setAttribute('aria-label', kind.search);
|
|
3005
|
+
list.setAttribute('aria-label', kind.list);
|
|
3006
|
+
list.replaceChildren();
|
|
3007
|
+
const status = (text) => {
|
|
3008
|
+
const line = Object.assign(document.createElement('div'), { className: 'ai-chat-mention-status', textContent: text });
|
|
3009
|
+
line.setAttribute('role', 'option'); line.setAttribute('aria-disabled', 'true');
|
|
3010
|
+
list.append(line);
|
|
3011
|
+
};
|
|
3012
|
+
let activeId = '';
|
|
3013
|
+
if (picker.status === 'loading') {
|
|
3014
|
+
status(picker.kind === 'kb' ? 'Looking through this project’s Knowledge…' : picker.kind === 'files' ? 'Listing attached files…'
|
|
3015
|
+
: picker.kind ? 'Loading the project’s sheets and members…' : 'Loading what you can choose from…');
|
|
3016
|
+
} else if (picker.status === 'note') status(picker.note);
|
|
3017
|
+
else if (picker.status === 'empty') {
|
|
3018
|
+
status(picker.query ? `Nothing matches “${picker.query}”.` : picker.kind === 'kb' ? 'This project’s Knowledge has no pages.'
|
|
3019
|
+
: 'This project has no sheets or model members yet.');
|
|
3020
|
+
} else if (picker.status === 'error') {
|
|
3021
|
+
status(picker.note);
|
|
3022
|
+
const retry = button('Try again', 'shell.chat-cite-choose-retry', 'ai-chat-choice');
|
|
3023
|
+
retry.setAttribute('role', 'option');
|
|
3024
|
+
retry.addEventListener('click', () => { picker.status = 'loading'; paintSourcePicker(picker); if (picker.projects) searchSources(picker, 0); else loadSourceProjects(picker); });
|
|
3025
|
+
list.append(retry);
|
|
3026
|
+
} else {
|
|
3027
|
+
picker.items.forEach((item, index) => {
|
|
3028
|
+
const option = button('', `shell.chat-cite-choose-pick#${item.key}`, 'ai-chat-choice ai-chat-mention-option');
|
|
3029
|
+
option.id = `chat-source-option-${index}`; option.tabIndex = -1;
|
|
3030
|
+
option.setAttribute('role', 'option'); option.setAttribute('aria-selected', String(index === picker.active));
|
|
3031
|
+
option.dataset.commandInstanceLabel = item.label;
|
|
3032
|
+
option.dataset.tip = item.tip;
|
|
3033
|
+
const busy = picker.saving?.key === item.key;
|
|
3034
|
+
if (picker.saving) option.setAttribute('aria-disabled', 'true');
|
|
3035
|
+
if (busy) option.setAttribute('aria-busy', 'true');
|
|
3036
|
+
const name = Object.assign(document.createElement('span'), { className: 'ai-chat-mention-name', textContent: item.name });
|
|
3037
|
+
const meta = Object.assign(document.createElement('small'), { className: 'ai-chat-skill-origin', textContent: item.meta });
|
|
3038
|
+
option.append(name, meta);
|
|
3039
|
+
option.addEventListener('pointerdown', (event) => event.preventDefault()); // the search box keeps focus
|
|
3040
|
+
option.addEventListener('click', () => chooseSource(picker, item));
|
|
3041
|
+
list.append(option);
|
|
3042
|
+
if (index === picker.active) activeId = option.id;
|
|
3043
|
+
});
|
|
3044
|
+
for (const line of picker.more) status(line);
|
|
3045
|
+
}
|
|
3046
|
+
if (activeId) { input.setAttribute('aria-activedescendant', activeId); document.getElementById(activeId)?.scrollIntoView?.({ block: 'nearest' }); }
|
|
3047
|
+
else input.removeAttribute('aria-activedescendant');
|
|
3048
|
+
foot.textContent = picker.saving ? 'Saving your choice…' : picker.problem;
|
|
3049
|
+
foot.classList.toggle('warn', !picker.saving && !!picker.problem);
|
|
3050
|
+
placeSourcePicker(picker);
|
|
3051
|
+
}
|
|
3052
|
+
|
|
3053
|
+
function sourcePickerKey(picker, event) {
|
|
3054
|
+
if (event.isComposing) return;
|
|
3055
|
+
const count = picker.status === 'options' ? picker.items.length : 0;
|
|
3056
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
3057
|
+
event.preventDefault();
|
|
3058
|
+
if (count) { picker.active = (picker.active + (event.key === 'ArrowDown' ? 1 : -1) + count) % count; paintSourcePicker(picker); }
|
|
3059
|
+
} else if (event.key === 'Enter') {
|
|
3060
|
+
event.preventDefault();
|
|
3061
|
+
if (count && picker.items[picker.active]) chooseSource(picker, picker.items[picker.active]);
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
3064
|
+
|
|
3065
|
+
/** Records the pick. A failure keeps the list open with the server's sentence; the claim stays as it was. */
|
|
3066
|
+
async function chooseSource(picker, item) {
|
|
3067
|
+
if (picker.saving) return;
|
|
3068
|
+
if (picker.stale) { announce('Still looking. Pick again when the list updates.'); return; }
|
|
3069
|
+
// The same pick again after a failure is the same decision, so it keeps its request id; another pick is a new one.
|
|
3070
|
+
// The key holds the project (the same sheet identity can be in two projects) and, for a page, the version.
|
|
3071
|
+
if (picker.pending?.key !== item.key) picker.pending = { key: item.key, requestId: crypto.randomUUID() };
|
|
3072
|
+
picker.saving = { key: item.key }; picker.problem = '';
|
|
3073
|
+
paintSourcePicker(picker);
|
|
3074
|
+
const { row, turnId } = picker;
|
|
3075
|
+
let saved = null; let problem = '';
|
|
3076
|
+
try {
|
|
3077
|
+
const result = await request(`/api/chat/conversations/${encodeURIComponent(row.chatId)}/citations/${encodeURIComponent(row.citationId)}/choose`, {
|
|
3078
|
+
method: 'POST', body: JSON.stringify({ owner: row.ownerObject, turnId, anchor: row.anchor, claim: unsourcedClaimWords(turnId, row.anchor) || null,
|
|
3079
|
+
projectId: item.projectId, pick: item.pick, requestId: picker.pending.requestId, replaces: picker.replaces }),
|
|
3080
|
+
});
|
|
3081
|
+
saved = result?.event ?? null;
|
|
3082
|
+
} catch (error) {
|
|
3083
|
+
problem = String(error?.code || '').startsWith('chat-cite-choose-') && error.message ? String(error.message) : 'Could not save your choice. Try again.';
|
|
3084
|
+
}
|
|
3085
|
+
// Another conversation, or a list the person closed or replaced meanwhile: this reply moves nothing on screen and
|
|
3086
|
+
// takes no focus. A saved choice still reaches the page through the conversation's own event stream.
|
|
3087
|
+
if (state.chat?.chatId !== row.chatId || state.sourcePicker !== picker) return;
|
|
3088
|
+
if (saved && !state.events.some((known) => known.eventId === saved.eventId)) state.events.push(saved);
|
|
3089
|
+
if (saved) {
|
|
3090
|
+
closeSourcePicker(false);
|
|
3091
|
+
paintEvents();
|
|
3092
|
+
liveCitationOpener(turnId, row.anchor)?.focus({ preventScroll: true });
|
|
3093
|
+
const current = citationIndex(turnId).byAnchor.get(row.anchor)?.choice;
|
|
3094
|
+
announce(current ? `Source ${current.source.label} recorded as chosen by ${assumedWho({ assumedBy: current.chosenBy })}.` : 'Your choice was saved.');
|
|
3095
|
+
return;
|
|
3096
|
+
}
|
|
3097
|
+
picker.saving = null; picker.problem = `Couldn't record your choice: ${problem} The claim is still as it was.`;
|
|
3098
|
+
paintSourcePicker(picker);
|
|
3099
|
+
picker.input.focus({ preventScroll: true });
|
|
3100
|
+
}
|
|
3101
|
+
|
|
3102
|
+
/*
|
|
3103
|
+
* #2777 slices B and C: the places the AI asked FloLess to show (`floless_place`), as one strip under its answer, above
|
|
3104
|
+
* the question it asks about them. FloLess resolved every place itself; the event carries each place with the digest
|
|
3105
|
+
* its picture link must name, so a chip can only open what FloLess found. An entry it could not place says why.
|
|
3106
|
+
*/
|
|
3107
|
+
/** Whether a label names this sheet as a whole token: "S1" is not named by a label about "S10". */
|
|
3108
|
+
const namesSheet = (label, sheet) => new RegExp(`(?<![A-Za-z0-9])${sheet.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?![A-Za-z0-9])`).test(label);
|
|
3109
|
+
const placeBox = (v) => Array.isArray(v) && v.length === 4 && v.every((n) => typeof n === 'number' && Number.isFinite(n));
|
|
3110
|
+
function placeOfEntry(entry) {
|
|
3111
|
+
const place = entry && typeof entry === 'object' ? entry.place : null;
|
|
3112
|
+
if (!place || typeof place !== 'object' || (place.kind !== 'region' && place.kind !== 'sheet')) return null;
|
|
3113
|
+
if (typeof place.sheet !== 'string' || !place.sheet || !Number.isInteger(place.page) || typeof place.pageId !== 'string'
|
|
3114
|
+
|| !/^[0-9a-f]{64}$/.test(String(place.sourceHash || '')) || !placeBox(place.pageBounds)) return null;
|
|
3115
|
+
if (place.kind === 'region' && !placeBox(place.region)) return null;
|
|
3116
|
+
return typeof entry.digest === 'string' && /^[0-9a-f]{64}$/.test(entry.digest) ? place : null;
|
|
3117
|
+
}
|
|
3118
|
+
function renderPlaceStrip(event) {
|
|
3119
|
+
const entries = Array.isArray(event.payload?.entries) ? event.payload.entries.slice(0, 8) : [];
|
|
3120
|
+
if (!entries.length || !state.chat?.chatId) return null;
|
|
3121
|
+
const wrap = document.createElement('div'); wrap.className = 'ai-chat-sources ai-chat-place-strip';
|
|
3122
|
+
const head = document.createElement('span'); head.className = 'ai-chat-sources-head'; head.textContent = 'Where this is on the drawings';
|
|
3123
|
+
head.dataset.tip = 'FloLess found each place on this read’s drawings. It shows where to look, not that what the AI says about it is right.';
|
|
3124
|
+
const list = document.createElement('div'); list.className = 'ai-chat-sources-list';
|
|
3125
|
+
const notes = [];
|
|
3126
|
+
entries.forEach((entry, ix) => {
|
|
3127
|
+
const label = typeof entry?.label === 'string' && entry.label.trim() ? entry.label.trim().slice(0, 120) : `Place ${ix + 1}`;
|
|
3128
|
+
const place = placeOfEntry(entry);
|
|
3129
|
+
if (!place) {
|
|
3130
|
+
notes.push(`${label}: ${typeof entry?.unplaced === 'string' && entry.unplaced ? entry.unplaced : 'FloLess could not show this place.'}`);
|
|
3131
|
+
return;
|
|
3132
|
+
}
|
|
3133
|
+
const marked = place.kind === 'region';
|
|
3134
|
+
const chip = button('', `shell.chat-place-open#${event.eventId} ${ix}`, 'ai-chat-source-chip ai-chat-place-chip');
|
|
3135
|
+
chip.dataset.commandInstanceLabel = `${label} on ${place.sheet}`;
|
|
3136
|
+
chip.setAttribute('aria-label', `Open sheet ${place.sheet}: ${label}`);
|
|
3137
|
+
chip.dataset.tip = marked ? `Opens sheet ${place.sheet} with this place outlined` : `Opens sheet ${place.sheet}; no area is marked`;
|
|
3138
|
+
chip.append(Object.assign(document.createElement('span'), { className: 'ai-chat-place-chip-label', textContent: label }),
|
|
3139
|
+
Object.assign(document.createElement('span'), { className: 'ai-chat-readiness-place-sheet', textContent: place.sheet }));
|
|
3140
|
+
const url = `/api/chat/places/${encodeURIComponent(state.chat.chatId)}/${encodeURIComponent(event.eventId)}/${ix}?${new URLSearchParams({ digest: entry.digest })}&${ownerQuery()}`;
|
|
3141
|
+
// A label that already names the sheet is not told it again ("Column line on S-301 on S-301").
|
|
3142
|
+
const titled = namesSheet(label, place.sheet) ? label : `${label} on ${place.sheet}`;
|
|
3143
|
+
chip.addEventListener('click', () => openDrawingPlace(place, {
|
|
3144
|
+
title: titled, opener: chip, url,
|
|
3145
|
+
note: marked ? `FloLess outlined, on page ${place.page} of ${place.sheet}, the place the AI named. It shows where to look, not that what the AI says about it is right.`
|
|
3146
|
+
: `The read marked this sheet but not a spot on it, so no area is outlined. Look over the whole sheet.`,
|
|
3147
|
+
commands: { close: 'shell.chat-place-close', view: 'shell.chat-place-view' },
|
|
3148
|
+
again: { label: 'Ask the AI to show it again', commandId: 'shell.chat-place-again', tip: 'Puts the request in the message box. Nothing is sent until you press Send',
|
|
3149
|
+
run: () => { addToMessageBox(`Show me again where "${label}" is on the drawings.`); ui.input.focus?.(); } },
|
|
3150
|
+
...(chatProjectId() ? { filter: { projectId: chatProjectId(), commandId: 'shell.chat-place-open-filter' } } : {}),
|
|
3151
|
+
}));
|
|
3152
|
+
list.append(chip);
|
|
3153
|
+
});
|
|
3154
|
+
wrap.append(head, list);
|
|
3155
|
+
for (const text of notes) wrap.append(Object.assign(document.createElement('p'), { className: 'ai-chat-filter-note ai-chat-height-unplaced', textContent: `Not placed on the drawings: ${text}` }));
|
|
3156
|
+
return wrap;
|
|
3157
|
+
}
|
|
3158
|
+
|
|
2386
3159
|
/** The Sources row of one answer, shown once, under the answer, after its last citation. */
|
|
2387
3160
|
function renderCitationSources(event) {
|
|
2388
3161
|
const last = state.events.filter((candidate) => candidate.type === 'citation' && candidate.turnId === event.turnId).at(-1);
|
|
@@ -2417,8 +3190,12 @@
|
|
|
2417
3190
|
function citationRow(chips) {
|
|
2418
3191
|
const wrap = document.createElement('div'); wrap.className = 'ai-chat-sources';
|
|
2419
3192
|
const head = document.createElement('span'); head.className = 'ai-chat-sources-head';
|
|
2420
|
-
|
|
2421
|
-
|
|
3193
|
+
// #2643: a source a person chose is not one the AI gave, so a row holding one says neither.
|
|
3194
|
+
const chosen = chips.some((chip) => chip.classList.contains('chosen'));
|
|
3195
|
+
head.textContent = chosen ? 'Sources for this answer' : 'Sources the AI gave for this answer';
|
|
3196
|
+
head.dataset.tip = chosen
|
|
3197
|
+
? 'FloLess found each source. It says whether the AI was shown one it cited, and marks one a person chose as chosen. It does not check that a source supports the claim.'
|
|
3198
|
+
: 'FloLess found each source and says whether the AI was shown it. It does not check that a source supports the claim.';
|
|
2422
3199
|
const list = document.createElement('div'); list.className = 'ai-chat-sources-list';
|
|
2423
3200
|
list.append(...chips);
|
|
2424
3201
|
wrap.append(head, list);
|
|
@@ -2435,6 +3212,14 @@
|
|
|
2435
3212
|
const answer = marker?.closest('.ai-chat-message')
|
|
2436
3213
|
?? [...ui.feed.querySelectorAll('.ai-chat-message.assistant')].filter((node) => node.dataset.turnId === turnId).at(-1);
|
|
2437
3214
|
const when = answer?.querySelector('time')?.textContent?.trim();
|
|
3215
|
+
const claim = unsourcedClaimWords(turnId, anchor);
|
|
3216
|
+
const where = when ? `in your answer of ${when}` : 'in your answer';
|
|
3217
|
+
return claim ? `For this claim ${where}, which has no source: “${claim}”` : `For the claim with no source ${where}`;
|
|
3218
|
+
}
|
|
3219
|
+
|
|
3220
|
+
/** The words just before a claim's "?" marker (the last 90 characters), or '' when the answer shows no marker for it. */
|
|
3221
|
+
function unsourcedClaimWords(turnId, anchor) {
|
|
3222
|
+
const marker = [...ui.feed.querySelectorAll('button.ai-chat-cite')].find((node) => node.dataset.turnId === (turnId || '') && node.dataset.anchor === anchor);
|
|
2438
3223
|
const block = marker?.closest('p, li, h1, h2, h3, blockquote');
|
|
2439
3224
|
let before = '';
|
|
2440
3225
|
if (block && marker) {
|
|
@@ -2450,9 +3235,7 @@
|
|
|
2450
3235
|
before = parts.join('').replace(/\s+/g, ' ').trim();
|
|
2451
3236
|
}
|
|
2452
3237
|
const words = [...before];
|
|
2453
|
-
|
|
2454
|
-
const where = when ? `in your answer of ${when}` : 'in your answer';
|
|
2455
|
-
return claim ? `For this claim ${where}, which has no source: “${claim}”` : `For the claim with no source ${where}`;
|
|
3238
|
+
return words.length > 90 ? `…${words.slice(-90).join('').trimStart()}` : before;
|
|
2456
3239
|
}
|
|
2457
3240
|
|
|
2458
3241
|
/** Never overwrites what the person is writing: the text goes after it. */
|
|
@@ -2471,6 +3254,8 @@
|
|
|
2471
3254
|
return chip?.querySelector('.ai-chat-source-open') ?? null;
|
|
2472
3255
|
}
|
|
2473
3256
|
|
|
3257
|
+
const CHOSEN_NOT_AS_ATTACHED = 'This file is no longer the plain file that was attached: it was changed, or something else now stands in its place. FloLess does not open it as the file you chose. Attach the file again if you still need it.';
|
|
3258
|
+
|
|
2474
3259
|
async function openCitedSource(row, turnId) {
|
|
2475
3260
|
const entry = row.entry;
|
|
2476
3261
|
const dialog = document.createElement('dialog'); dialog.className = 'ai-chat-source-viewer';
|
|
@@ -2504,16 +3289,28 @@
|
|
|
2504
3289
|
const refused = async (response) => {
|
|
2505
3290
|
if (response.status === 404) return 'FloLess no longer holds this source, or its project is no longer part of this conversation.';
|
|
2506
3291
|
if (response.status === 410) {
|
|
2507
|
-
|
|
3292
|
+
// #2692: a chosen source says it changed since the person chose it, never since an answer cited it.
|
|
3293
|
+
if (entry.kind !== 'attachment') {
|
|
3294
|
+
return entry.chosen ? 'This Knowledge page has changed since you chose it, so FloLess does not show it as the page you chose.'
|
|
3295
|
+
: 'This Knowledge page has changed since the answer, so FloLess does not show it as the page the answer cited.';
|
|
3296
|
+
}
|
|
2508
3297
|
// Changed bytes, or no longer the plain file that was attached: the server says which.
|
|
2509
3298
|
const said = await response.json().catch(() => null);
|
|
3299
|
+
if (entry.chosen && said?.code === 'citation-source-changed') return 'This file has changed since you chose it, so FloLess does not show it as the file you chose.';
|
|
3300
|
+
if (entry.chosen && said?.code === 'citation-source-not-as-attached') return CHOSEN_NOT_AS_ATTACHED;
|
|
2510
3301
|
return typeof said?.message === 'string' && said.message ? said.message : 'This file has changed since the answer cited it, so FloLess does not show it as the cited file.';
|
|
2511
3302
|
}
|
|
2512
3303
|
// 503: FloLess could not check it just now; anything else is said as "try again", never as "gone".
|
|
2513
3304
|
const said = await response.json().catch(() => null);
|
|
2514
3305
|
return typeof said?.message === 'string' && said.message ? said.message : 'FloLess could not open this source right now. Try again in a moment.';
|
|
2515
3306
|
};
|
|
2516
|
-
|
|
3307
|
+
// #2643: a chosen sheet's picture is the one FloLess held when the person chose it; the AI was not shown it by that.
|
|
3308
|
+
const SHOWN = entry.chosen ? {
|
|
3309
|
+
'as-seen': 'The sheet picture FloLess held when you chose it.',
|
|
3310
|
+
'from-source:changed': 'Rendered from the source drawing: the sheet picture FloLess holds has changed since you chose it.',
|
|
3311
|
+
'from-source:missing': 'Rendered from the source drawing: FloLess no longer holds the sheet picture it held when you chose it.',
|
|
3312
|
+
'from-source:unchecked': 'Rendered from the source drawing: FloLess could not check the stored sheet picture just now.',
|
|
3313
|
+
} : {
|
|
2517
3314
|
'as-seen': 'The sheet picture the AI was shown.',
|
|
2518
3315
|
'from-source:tiles': 'The whole sheet, rendered from its source drawing. The AI saw this sheet enlarged in tiles.',
|
|
2519
3316
|
'from-source:changed': 'Rendered from the source drawing: the sheet picture FloLess holds has changed since the AI looked at it.',
|
|
@@ -2539,6 +3336,24 @@
|
|
|
2539
3336
|
return;
|
|
2540
3337
|
}
|
|
2541
3338
|
if (entry.kind === 'member') { await showCitedMember(row, { dialog, body, status, finish, refused, done: () => finished }); return; }
|
|
3339
|
+
if (entry.kind === 'project-file') {
|
|
3340
|
+
// #2701: a file of the project's folder, checked now against the size and digest it was cited with.
|
|
3341
|
+
const response = await fetch(citationUrl(row, 'project-file'), { credentials: 'same-origin', cache: 'no-store' });
|
|
3342
|
+
if (!response.ok) { const why = await refused(response); if (!finished) status.textContent = why; return; }
|
|
3343
|
+
const { file } = await response.json();
|
|
3344
|
+
if (finished) return;
|
|
3345
|
+
if (!file) { status.textContent = 'FloLess could not open this source right now. Try again in a moment.'; return; }
|
|
3346
|
+
if (file.state === 'refused') status.textContent = `FloLess does not open ${file.path} as the cited file: ${file.reason}.`;
|
|
3347
|
+
else if (file.state === 'gone') status.textContent = `${file.path} is no longer in the project folder.`;
|
|
3348
|
+
else if (file.state === 'changed') status.textContent = `${file.path} has changed since the answer cited it, so FloLess does not show it as the cited file.`;
|
|
3349
|
+
else if (typeof file.text === 'string') {
|
|
3350
|
+
status.textContent = `${file.path} in the project folder, as it was cited${file.truncated ? '. Showing the start of the file' : ''}.`;
|
|
3351
|
+
const pre = Object.assign(document.createElement('pre'), { className: 'ai-chat-source-viewer-text', tabIndex: 0, textContent: file.text });
|
|
3352
|
+
pre.setAttribute('aria-label', `Text of ${entry.label}`);
|
|
3353
|
+
body.append(pre);
|
|
3354
|
+
} else status.textContent = `${file.path} in the project folder, as it was cited (${Number(file.bytes).toLocaleString()} bytes). FloLess does not show this kind of file here.`;
|
|
3355
|
+
return;
|
|
3356
|
+
}
|
|
2542
3357
|
if (entry.kind === 'attachment') {
|
|
2543
3358
|
const response = await fetch(citationUrl(row, 'attachment'), { credentials: 'same-origin', cache: 'no-store' });
|
|
2544
3359
|
if (!response.ok) { const why = await refused(response); if (!finished) status.textContent = why; return; }
|
|
@@ -2553,7 +3368,9 @@
|
|
|
2553
3368
|
const text = await response.text();
|
|
2554
3369
|
if (finished) return;
|
|
2555
3370
|
// A data file reaches the AI cut to its first 16,000 characters (attachment-text.ts MAX_TEXT_CHARS): said, never hidden.
|
|
2556
|
-
|
|
3371
|
+
// #2692: a file the person chose says nothing about what the AI was given: the choice records no read.
|
|
3372
|
+
status.textContent = entry.chosen ? 'The file as it was attached.'
|
|
3373
|
+
: 'The file as it was attached. The AI is given at most the first 16,000 characters of a data file.';
|
|
2557
3374
|
const shown = [...text];
|
|
2558
3375
|
const pre = Object.assign(document.createElement('pre'), { className: 'ai-chat-source-viewer-text', tabIndex: 0,
|
|
2559
3376
|
textContent: shown.length > 16000 ? shown.slice(0, 16000).join('') : text });
|
|
@@ -2578,8 +3395,9 @@
|
|
|
2578
3395
|
const why = {
|
|
2579
3396
|
'chat-page-closed': 'This conversation is no longer the one open here. Open it again, then press Open in its default app.',
|
|
2580
3397
|
'citation-source-unavailable': 'FloLess no longer holds this file in this conversation, so there is nothing to open.',
|
|
2581
|
-
'citation-source-changed': 'This file has changed since
|
|
2582
|
-
|
|
3398
|
+
'citation-source-changed': entry.chosen ? 'This file has changed since you chose it, so FloLess does not open it as the file you chose.'
|
|
3399
|
+
: 'This file has changed since the answer cited it, so FloLess does not open it as the cited file.',
|
|
3400
|
+
'citation-source-not-as-attached': entry.chosen ? CHOSEN_NOT_AS_ATTACHED : 'This file is no longer the plain file that was attached, so FloLess does not open it as the cited file. Attach the file again if you still need it.',
|
|
2583
3401
|
'citation-source-unreadable': 'FloLess could not check this file just now. Try again in a moment.',
|
|
2584
3402
|
}[error?.code] || '';
|
|
2585
3403
|
if (!why) console.error('[chat] a cited file could not be opened in its app', error);
|
|
@@ -2593,7 +3411,7 @@
|
|
|
2593
3411
|
if (!response.ok) { const why = await refused(response); if (!finished) status.textContent = why; return; }
|
|
2594
3412
|
const { page } = await response.json();
|
|
2595
3413
|
if (finished) return;
|
|
2596
|
-
status.textContent = 'The Knowledge page as it was when the answer cited it.';
|
|
3414
|
+
status.textContent = entry.chosen ? 'The Knowledge page as it was when you chose it.' : 'The Knowledge page as it was when the answer cited it.';
|
|
2597
3415
|
const article = document.createElement('div'); article.className = 'ai-chat-message-body ai-chat-source-viewer-page';
|
|
2598
3416
|
article.innerHTML = markdownHtml(page.body);
|
|
2599
3417
|
const knowledge = button('Open in Knowledge', 'shell.chat-cite-open-knowledge', 'ai-chat-source-viewer-knowledge');
|
|
@@ -2628,11 +3446,15 @@
|
|
|
2628
3446
|
fact('Mark', member.mark ?? 'No mark');
|
|
2629
3447
|
fact('Profile', member.profile ?? 'Not recorded');
|
|
2630
3448
|
const views = Array.isArray(member.views) ? member.views : [];
|
|
2631
|
-
|
|
2632
|
-
|
|
3449
|
+
// #2643: a member the person chose is described as it was when chosen, never as the answer citing it. "Read on" is
|
|
3450
|
+
// the drawings the model's read found it on; for a chosen member it says "On sheets", so no read is put near the AI.
|
|
3451
|
+
const chosen = !!row.entry?.chosen;
|
|
3452
|
+
fact(chosen ? 'On sheets' : 'Read on', views.length ? views.map((v) => (v.title ? `${v.sheet} (${v.title})` : v.sheet)).join(', ') : 'No sheet recorded');
|
|
3453
|
+
body.insertBefore(Object.assign(document.createElement('p'), { className: 'ai-chat-source-viewer-sub', textContent: chosen ? 'As it was when you chose it' : 'As the answer cited it' }), status);
|
|
2633
3454
|
body.insertBefore(facts, status);
|
|
2634
|
-
status.textContent = member.model === 'same' ? 'The model is the same version as when the answer cited it.'
|
|
2635
|
-
: member.model === 'changed' ? 'The model has changed since this
|
|
3455
|
+
status.textContent = member.model === 'same' ? (chosen ? 'The model is the same version as when you chose this member.' : 'The model is the same version as when the answer cited it.')
|
|
3456
|
+
: member.model === 'changed' ? (chosen ? 'The model has changed since you chose this member; the member is still in it. Its size or position may differ from when you chose it.'
|
|
3457
|
+
: 'The model has changed since this answer; the member is still in it. Its size or position may differ from what the answer described.')
|
|
2636
3458
|
: member.model === 'no-model' ? 'This project has no steel model FloLess can show now, so the member cannot be shown in it.'
|
|
2637
3459
|
: 'This member is no longer in the model.';
|
|
2638
3460
|
if (member.model === 'gone' || member.model === 'no-model') return;
|
|
@@ -2839,12 +3661,10 @@
|
|
|
2839
3661
|
label.textContent = requestTypeLabels[payload.requestType] || String(payload.requestType || 'Request').replace(/-/g, ' ');
|
|
2840
3662
|
const status = document.createElement('span'); status.className = 'ai-chat-request-status';
|
|
2841
3663
|
status.textContent = requestStatusLabels[payload.requestStatus] || String(payload.requestStatus || 'pending').replace(/-/g, ' ');
|
|
2842
|
-
// #2185: always-visible ✕ - hides the card, and on a request that is still waiting also sets the request aside (with Undo).
|
|
2843
|
-
const hide = document.createElement('button'); hide.type = 'button'; hide.className = 'ai-chat-request-dismiss'; hide.textContent = '×';
|
|
2844
|
-
hide.dataset.commandId = `shell.chat-request-dismiss#${payload.requestId || 'linked request'}`;
|
|
2845
|
-
hide.setAttribute('aria-label', 'Dismiss this request');
|
|
2846
3664
|
status.setAttribute('role', 'status');
|
|
2847
|
-
|
|
3665
|
+
// #2678: the card's chevron (on its shell, like every other card in the conversation) only folds it; setting the request aside
|
|
3666
|
+
// is Dismiss, named, below. It used to be the ×, which made hiding a waiting request also turn it down.
|
|
3667
|
+
head.append(label, status);
|
|
2848
3668
|
const body = document.createElement('p'); body.textContent = payloadText(event);
|
|
2849
3669
|
item.append(head, body);
|
|
2850
3670
|
if (Array.isArray(payload.sourceNames) && payload.sourceNames.length) {
|
|
@@ -2855,10 +3675,13 @@
|
|
|
2855
3675
|
item.append(sources);
|
|
2856
3676
|
}
|
|
2857
3677
|
const actions = document.createElement('div'); actions.className = 'ai-chat-request-actions';
|
|
3678
|
+
const dismiss = button('Dismiss', `shell.chat-request-dismiss#${payload.requestId || 'linked request'}`, 'ai-chat-request-dismiss');
|
|
3679
|
+
dismiss.dataset.tip = 'Set this request aside. It stays in Requests → Done, and you can undo it';
|
|
3680
|
+
dismiss.setAttribute('aria-label', 'Dismiss this request');
|
|
2858
3681
|
const open = button('Open Requests', `shell.requests-open#${payload.requestId || 'linked request'}`);
|
|
2859
3682
|
open.dataset.tip = 'Open the linked request and its detailed progress';
|
|
2860
3683
|
open.addEventListener('click', () => window.flolessBridge?.openRequest?.(payload.requestId));
|
|
2861
|
-
actions.append(open); item.append(actions);
|
|
3684
|
+
actions.append(dismiss, open); item.append(actions);
|
|
2862
3685
|
// Its live state replaces the frozen copy above as soon as it is known (and again whenever Requests changes).
|
|
2863
3686
|
initRequestCard(item, event);
|
|
2864
3687
|
return item;
|
|
@@ -2867,13 +3690,29 @@
|
|
|
2867
3690
|
/*
|
|
2868
3691
|
* #2185 - the request card tells the truth about its request, now. The frozen copy in the event says "Queued" for ever; the
|
|
2869
3692
|
* server's projection says Waiting for the AI / The AI is working / The AI has a question / Done / Dismissed / Expired.
|
|
2870
|
-
*
|
|
2871
|
-
* working on it the card ASKS - stop that work and dismiss, or keep it.
|
|
3693
|
+
* Dismiss is there until the request is finished: on a request that is only waiting it sets the request aside (Undo puts
|
|
3694
|
+
* it back); when the AI is working on it the card ASKS - stop that work and dismiss, or keep it. (#2678: hiding the card is
|
|
3695
|
+
* its chevron on the shell, and decides nothing.)
|
|
2872
3696
|
*/
|
|
2873
3697
|
const REQUEST_CARD_WORDS = { dismissed: 'Dismissed', expired: 'Expired', settled: 'Done' };
|
|
2874
3698
|
const REQUEST_CARD_HIDDEN_KEY = 'floless:chat-hidden-request-cards';
|
|
2875
3699
|
state.requestCards = state.requestCards || new Map();
|
|
2876
3700
|
state.requestCardsAt = state.requestCardsAt || 0;
|
|
3701
|
+
// Click state belongs to the request, not the article replaced by every stream/poll repaint (#2694).
|
|
3702
|
+
const requestCardUi = new Map();
|
|
3703
|
+
function requestCardEntry(requestId) {
|
|
3704
|
+
if (!requestCardUi.has(requestId)) requestCardUi.set(requestId, { busy: null, hold: null, note: '', askError: '' });
|
|
3705
|
+
return requestCardUi.get(requestId);
|
|
3706
|
+
}
|
|
3707
|
+
function liveRequestCard(requestId) {
|
|
3708
|
+
return [...(ui.feed?.querySelectorAll('.ai-chat-request-card[data-request-id]') || [])]
|
|
3709
|
+
.find((card) => card.dataset.requestId === requestId) || null;
|
|
3710
|
+
}
|
|
3711
|
+
function repaintRequestCard(requestId) {
|
|
3712
|
+
const card = liveRequestCard(requestId);
|
|
3713
|
+
if (card) paintRequestCard(card);
|
|
3714
|
+
return card;
|
|
3715
|
+
}
|
|
2877
3716
|
|
|
2878
3717
|
function hiddenRequestCards() {
|
|
2879
3718
|
try {
|
|
@@ -2881,10 +3720,11 @@
|
|
|
2881
3720
|
return new Set(Array.isArray(parsed) ? parsed.filter((id) => typeof id === 'string') : []);
|
|
2882
3721
|
} catch { return new Set(); }
|
|
2883
3722
|
}
|
|
2884
|
-
|
|
3723
|
+
/** #2678: a card opened again drops the hide #2185's × remembered for it (nothing is written for any other card). */
|
|
3724
|
+
function forgetHiddenRequestCard(eventId) {
|
|
2885
3725
|
const ids = hiddenRequestCards();
|
|
2886
|
-
if (
|
|
2887
|
-
try { localStorage.setItem(REQUEST_CARD_HIDDEN_KEY, JSON.stringify([...ids]
|
|
3726
|
+
if (!ids.delete(eventId)) return;
|
|
3727
|
+
try { localStorage.setItem(REQUEST_CARD_HIDDEN_KEY, JSON.stringify([...ids])); } catch { /* private mode: it starts folded again next time */ }
|
|
2888
3728
|
}
|
|
2889
3729
|
|
|
2890
3730
|
/** The word for a request's live state, or '' when nothing live is known yet (the frozen word stays). */
|
|
@@ -2915,26 +3755,40 @@
|
|
|
2915
3755
|
item.querySelector('.ai-chat-request-actions')?.prepend(undo);
|
|
2916
3756
|
}
|
|
2917
3757
|
} else if (undo) undo.remove();
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
3758
|
+
// Nothing is left to set aside once the request is finished, dismissed or gone; its card still folds (its chevron).
|
|
3759
|
+
const finished = Boolean(live && (live.found === false || set));
|
|
3760
|
+
const dismiss = item.querySelector('.ai-chat-request-dismiss');
|
|
3761
|
+
if (dismiss) dismiss.hidden = finished;
|
|
3762
|
+
// #2678: what a hidden card's line says still waits: the person (the server's "needs you", except a request only waiting
|
|
3763
|
+
// for the AI to start it), or the AI. The line says the card's own live word either way.
|
|
3764
|
+
if (finished) item.dataset.waits = 'done';
|
|
3765
|
+
else item.dataset.waits = live?.attention?.state === 'needs-you' && live.attention.code !== 'waiting-to-start' ? 'you' : 'ai';
|
|
3766
|
+
const entry = requestCardEntry(requestId);
|
|
3767
|
+
// A fresh terminal verdict retires this choice, not the whole entry: an old Stop must never
|
|
3768
|
+
// survive after the server says there is no work left. Unknown/in-flight status keeps it.
|
|
3769
|
+
if (live && (live.found === false || set)) { entry.hold = null; entry.askError = ''; }
|
|
3770
|
+
if (dismiss) dismiss.disabled = Boolean(entry.busy || entry.hold);
|
|
3771
|
+
if (undo) undo.disabled = Boolean(entry.busy);
|
|
3772
|
+
let note = item.querySelector('.ai-chat-request-note');
|
|
3773
|
+
if (entry.note) {
|
|
3774
|
+
if (!note) { note = document.createElement('p'); note.className = 'ai-chat-request-note'; note.setAttribute('role', 'status'); item.append(note); }
|
|
3775
|
+
note.textContent = entry.note;
|
|
3776
|
+
} else note?.remove();
|
|
3777
|
+
if (entry.hold) paintRequestAsk(item, entry);
|
|
3778
|
+
else item.querySelector('.ai-chat-request-ask')?.remove();
|
|
2924
3779
|
}
|
|
2925
3780
|
|
|
2926
3781
|
function initRequestCard(item, event) {
|
|
2927
3782
|
item.dataset.cardEventId = event.eventId;
|
|
2928
|
-
|
|
2929
|
-
const hide = item.querySelector('.ai-chat-request-dismiss');
|
|
2930
|
-
hide?.addEventListener('click', () => { void dismissRequestFromCard(item, event.eventId); });
|
|
3783
|
+
item.querySelector('.ai-chat-request-dismiss')?.addEventListener('click', () => { void dismissRequestFromCard(item); });
|
|
2931
3784
|
paintRequestCard(item);
|
|
2932
3785
|
queueMicrotask(() => { void refreshRequestCards(); });
|
|
2933
3786
|
}
|
|
2934
3787
|
|
|
2935
3788
|
async function refreshRequestCards({ force = false } = {}) {
|
|
2936
3789
|
if (!ui.feed) return;
|
|
2937
|
-
|
|
3790
|
+
// #2678: a hidden card's one line carries its request too, so the request is still polled and the line stays current.
|
|
3791
|
+
const cards = [...ui.feed.querySelectorAll('.ai-chat-request-card[data-request-id], .ai-chat-feed-hidden[data-request-id]')].filter((card) => card.dataset.requestId);
|
|
2938
3792
|
if (!cards.length) return;
|
|
2939
3793
|
if (!force && Date.now() - state.requestCardsAt < 2500) return;
|
|
2940
3794
|
state.requestCardsAt = Date.now();
|
|
@@ -2944,6 +3798,9 @@
|
|
|
2944
3798
|
catch { return; /* the card keeps what it last knew; the next poll tries again */ }
|
|
2945
3799
|
if (!Array.isArray(statuses)) return;
|
|
2946
3800
|
for (const live of statuses) if (live?.id) state.requestCards.set(live.id, live);
|
|
3801
|
+
// Only an authoritative removal retires transient state; folding or a conversation repaint does not.
|
|
3802
|
+
for (const live of statuses) if (live?.id && live.found === false) requestCardUi.delete(live.id);
|
|
3803
|
+
// A hidden card's line reads these on the conversation's next repaint (the chat poll, every 5 s).
|
|
2947
3804
|
for (const card of ui.feed.querySelectorAll('.ai-chat-request-card[data-request-id]')) paintRequestCard(card);
|
|
2948
3805
|
}
|
|
2949
3806
|
|
|
@@ -2955,63 +3812,109 @@
|
|
|
2955
3812
|
return { ok: response.ok && body.ok !== false, status: response.status, body };
|
|
2956
3813
|
}
|
|
2957
3814
|
|
|
2958
|
-
async function dismissRequestFromCard(item
|
|
3815
|
+
async function dismissRequestFromCard(item) {
|
|
2959
3816
|
const requestId = item.dataset.requestId;
|
|
2960
3817
|
if (!requestId) return;
|
|
3818
|
+
const entry = requestCardEntry(requestId);
|
|
3819
|
+
if (entry.busy || entry.hold) return;
|
|
3820
|
+
// #2678: the person's own click holds the card open (its Undo, its ask, its note stay in front of them), counted from
|
|
3821
|
+
// the click so a collapse while it is answered still wins.
|
|
3822
|
+
openFeedCard(item.dataset.cardEventId);
|
|
2961
3823
|
const live = state.requestCards.get(requestId);
|
|
2962
|
-
//
|
|
3824
|
+
// Finished, set aside or gone since the card was drawn: nothing to dismiss. The card catches up (Dismiss goes), says so,
|
|
3825
|
+
// and keeps the keyboard on the card's other button.
|
|
2963
3826
|
if (live && (live.found === false || live.lifecycle)) {
|
|
2964
|
-
|
|
2965
|
-
item.hidden
|
|
3827
|
+
paintRequestCard(item);
|
|
3828
|
+
item.querySelector('.ai-chat-request-actions button:not([hidden])')?.focus();
|
|
3829
|
+
announce('This request is already finished, so there is nothing to dismiss.');
|
|
2966
3830
|
return;
|
|
2967
3831
|
}
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
item.querySelector('.ai-chat-request-note')?.remove(); // a new try replaces the last failure's note
|
|
3832
|
+
entry.busy = 'dismiss'; entry.note = '';
|
|
3833
|
+
paintRequestCard(item);
|
|
2971
3834
|
try {
|
|
3835
|
+
// Learn the current choices before asking the server to dismiss: being held is an ordinary
|
|
3836
|
+
// choice, not a knowingly failed write. The POST below still owns its atomic race check.
|
|
3837
|
+
const projection = await request(`/api/requests/status?ids=${encodeURIComponent(requestId)}`, { timeoutMs: 10000 });
|
|
3838
|
+
const fresh = Array.isArray(projection?.statuses) ? projection.statuses.find((row) => row?.id === requestId) : null;
|
|
3839
|
+
if (!fresh || typeof fresh.found !== 'boolean' || !Object.hasOwn(fresh, 'hold') || !Object.hasOwn(fresh, 'lifecycle')
|
|
3840
|
+
|| (fresh.lifecycle !== null && (typeof fresh.lifecycle !== 'object' || !REQUEST_CARD_WORDS[fresh.lifecycle.state]))
|
|
3841
|
+
|| (fresh.hold !== null && (typeof fresh.hold !== 'object' || Array.isArray(fresh.hold)
|
|
3842
|
+
|| typeof fresh.hold.kind !== 'string' || typeof fresh.hold.why !== 'string' || !Object.hasOwn(fresh.hold, 'stop')))) {
|
|
3843
|
+
cardNotice(requestId, 'FloLess couldn’t check whether this request is being worked on. Nothing was dismissed; try Dismiss again.');
|
|
3844
|
+
return;
|
|
3845
|
+
}
|
|
3846
|
+
state.requestCards.set(requestId, fresh);
|
|
3847
|
+
item = liveRequestCard(requestId);
|
|
3848
|
+
if (!fresh.found || fresh.lifecycle) {
|
|
3849
|
+
entry.busy = null;
|
|
3850
|
+
repaintRequestCard(requestId)?.querySelector('.ai-chat-request-actions button:not([hidden])')?.focus();
|
|
3851
|
+
announce('This request is already finished, so there is nothing to dismiss.');
|
|
3852
|
+
return;
|
|
3853
|
+
}
|
|
3854
|
+
if (fresh.hold) { entry.busy = null; askStopThenDismiss(requestId, fresh.hold); return; }
|
|
2972
3855
|
const done = await lifecycleCall(requestId, 'dismiss');
|
|
3856
|
+
item = liveRequestCard(requestId);
|
|
2973
3857
|
if (done.ok) {
|
|
3858
|
+
entry.busy = null;
|
|
2974
3859
|
state.requestCards.set(requestId, { id: requestId, found: true, lifecycle: { state: 'dismissed' }, attention: { state: 'not-now', code: 'dismissed', label: 'Dismissed' } });
|
|
2975
|
-
|
|
2976
|
-
item.querySelector('.ai-chat-request-undo')?.focus();
|
|
3860
|
+
repaintRequestCard(requestId)?.querySelector('.ai-chat-request-undo')?.focus();
|
|
2977
3861
|
announce('Request dismissed. Undo is on the card.');
|
|
2978
3862
|
return;
|
|
2979
3863
|
}
|
|
2980
|
-
if (done.body?.code === 'request-held' && done.body.hold) { askStopThenDismiss(
|
|
3864
|
+
if (done.body?.code === 'request-held' && done.body.hold) { entry.busy = null; askStopThenDismiss(requestId, done.body.hold); return; }
|
|
2981
3865
|
if (done.status === 404 || done.body?.code === 'request-already-set-aside') { void refreshRequestCards({ force: true }); return; }
|
|
2982
|
-
cardNotice(
|
|
3866
|
+
cardNotice(requestId, done.body?.error || 'FloLess couldn’t dismiss that request. It is still in Requests; try Dismiss again.');
|
|
2983
3867
|
} catch {
|
|
2984
|
-
cardNotice(
|
|
3868
|
+
cardNotice(requestId, 'FloLess couldn’t reach the server, so the request was not dismissed. Try Dismiss again in a moment.');
|
|
2985
3869
|
} finally {
|
|
2986
|
-
|
|
3870
|
+
entry.busy = null; repaintRequestCard(requestId);
|
|
2987
3871
|
}
|
|
2988
3872
|
}
|
|
2989
3873
|
|
|
2990
3874
|
/** A failure said where the person is looking (on the card) as well as to a screen reader: never only one of the two. */
|
|
2991
|
-
function cardNotice(
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
note.className = 'ai-chat-request-note'; note.setAttribute('role', 'status'); note.textContent = text;
|
|
2995
|
-
item.append(note);
|
|
3875
|
+
function cardNotice(requestId, text) {
|
|
3876
|
+
requestCardEntry(requestId).note = text;
|
|
3877
|
+
repaintRequestCard(requestId);
|
|
2996
3878
|
announce(text);
|
|
2997
3879
|
}
|
|
2998
3880
|
|
|
2999
3881
|
/** The AI is working on it: ask - stop that work and dismiss, or keep the request. Nothing happened yet. */
|
|
3000
|
-
function askStopThenDismiss(
|
|
3001
|
-
|
|
3882
|
+
function askStopThenDismiss(requestId, hold) {
|
|
3883
|
+
const entry = requestCardEntry(requestId);
|
|
3884
|
+
entry.hold = hold; entry.askError = '';
|
|
3885
|
+
repaintRequestCard(requestId)?.querySelector('.ai-chat-request-ask button')?.focus();
|
|
3886
|
+
}
|
|
3887
|
+
function paintRequestAsk(item, entry) {
|
|
3888
|
+
const requestId = item.dataset.requestId;
|
|
3889
|
+
const hold = entry.hold;
|
|
3890
|
+
const existing = item.querySelector('.ai-chat-request-ask');
|
|
3891
|
+
if (existing) {
|
|
3892
|
+
existing.querySelector('p').textContent = entry.askError || `${hold.why || 'The AI is working on this request.'} Nothing was changed.`;
|
|
3893
|
+
for (const button of existing.querySelectorAll('button')) button.disabled = Boolean(entry.busy);
|
|
3894
|
+
return;
|
|
3895
|
+
}
|
|
3002
3896
|
const ask = document.createElement('div'); ask.className = 'ai-chat-request-ask'; ask.setAttribute('role', 'group'); ask.setAttribute('aria-label', 'This request is being worked on');
|
|
3897
|
+
const keepRequest = () => {
|
|
3898
|
+
if (entry.busy) return;
|
|
3899
|
+
entry.hold = null; entry.askError = '';
|
|
3900
|
+
repaintRequestCard(requestId)?.querySelector('.ai-chat-request-dismiss')?.focus();
|
|
3901
|
+
};
|
|
3003
3902
|
// Escape means Keep it: the safe default.
|
|
3004
|
-
ask.addEventListener('keydown', (event) => { if (event.key === 'Escape') { event.stopPropagation();
|
|
3005
|
-
const why = document.createElement('p'); why.textContent = `${hold.why || 'The AI is working on this request.'} Nothing was changed.`;
|
|
3903
|
+
ask.addEventListener('keydown', (event) => { if (event.key === 'Escape') { event.stopPropagation(); keepRequest(); } });
|
|
3904
|
+
const why = document.createElement('p'); why.textContent = entry.askError || `${hold.why || 'The AI is working on this request.'} Nothing was changed.`;
|
|
3006
3905
|
const row = document.createElement('div'); row.className = 'ai-chat-request-ask-actions';
|
|
3007
3906
|
const keep = button('Keep it', `shell.chat-request-keep#${item.dataset.requestId || 'linked request'}`);
|
|
3008
|
-
keep.
|
|
3907
|
+
keep.disabled = Boolean(entry.busy);
|
|
3908
|
+
keep.addEventListener('click', keepRequest);
|
|
3009
3909
|
row.append(keep);
|
|
3010
3910
|
const stop = hold.stop;
|
|
3011
3911
|
if (stop) {
|
|
3012
3912
|
const go = button('Stop it and dismiss', `shell.chat-request-stop-dismiss#${item.dataset.requestId || 'linked request'}`, 'danger');
|
|
3913
|
+
go.disabled = Boolean(entry.busy);
|
|
3013
3914
|
go.addEventListener('click', async () => {
|
|
3014
|
-
|
|
3915
|
+
if (entry.busy) return;
|
|
3916
|
+
entry.busy = 'stop'; entry.askError = ''; repaintRequestCard(requestId);
|
|
3917
|
+
openFeedCard(item.dataset.cardEventId); // #2678: as Dismiss: the Undo it offers stays in front of them
|
|
3015
3918
|
let stopped = true; // a stale stop means the work had already ended or changed: never claimed as "stopped"
|
|
3016
3919
|
try {
|
|
3017
3920
|
if (stop.kind === 'chat') {
|
|
@@ -3023,43 +3926,52 @@
|
|
|
3023
3926
|
await request(`/api/requests/${encodeURIComponent(stop.requestId)}/run/stop`, { method: 'POST', body: JSON.stringify(stop.leaseId ? { expectLeaseId: stop.leaseId } : {}) });
|
|
3024
3927
|
}
|
|
3025
3928
|
} catch (error) {
|
|
3026
|
-
if (error?.code !== 'stop-stale') {
|
|
3929
|
+
if (error?.code !== 'stop-stale') {
|
|
3930
|
+
entry.askError = 'FloLess couldn’t stop that work, so the request was not dismissed.';
|
|
3931
|
+
entry.busy = null; repaintRequestCard(requestId); announce(entry.askError); return;
|
|
3932
|
+
}
|
|
3027
3933
|
stopped = false;
|
|
3028
3934
|
}
|
|
3029
|
-
const again = await lifecycleCall(
|
|
3935
|
+
const again = await lifecycleCall(requestId, 'dismiss').catch(() => null);
|
|
3936
|
+
entry.busy = null;
|
|
3030
3937
|
if (again?.ok) {
|
|
3031
|
-
|
|
3032
|
-
state.requestCards.set(
|
|
3033
|
-
|
|
3034
|
-
item.querySelector('.ai-chat-request-undo')?.focus();
|
|
3938
|
+
entry.hold = null; entry.askError = '';
|
|
3939
|
+
state.requestCards.set(requestId, { id: requestId, found: true, lifecycle: { state: 'dismissed' }, attention: { state: 'not-now', code: 'dismissed', label: 'Dismissed' } });
|
|
3940
|
+
repaintRequestCard(requestId)?.querySelector('.ai-chat-request-undo')?.focus();
|
|
3035
3941
|
} else {
|
|
3036
3942
|
// A stop that went through is said, so the person does not think the AI is still working; a stale one is not claimed.
|
|
3037
|
-
|
|
3943
|
+
entry.askError = again?.body?.code === 'request-held'
|
|
3038
3944
|
? (stopped ? 'The work was stopped and is still winding down. Try again in a moment.' : 'Something is still working on this request. Try again in a moment.')
|
|
3039
3945
|
: `${stopped ? 'The work was stopped, but the request' : 'The request'} couldn’t be set aside. It is still in Requests; try again.`;
|
|
3040
|
-
|
|
3946
|
+
repaintRequestCard(requestId); announce(entry.askError);
|
|
3041
3947
|
}
|
|
3042
3948
|
});
|
|
3043
3949
|
row.append(go);
|
|
3044
3950
|
}
|
|
3045
3951
|
ask.append(why, row);
|
|
3046
3952
|
item.append(ask);
|
|
3047
|
-
keep.focus();
|
|
3048
3953
|
}
|
|
3049
3954
|
|
|
3050
3955
|
async function restoreRequestFromCard(item) {
|
|
3051
3956
|
const requestId = item.dataset.requestId;
|
|
3052
|
-
const
|
|
3053
|
-
if (
|
|
3054
|
-
|
|
3957
|
+
const entry = requestCardEntry(requestId);
|
|
3958
|
+
if (entry.busy) return;
|
|
3959
|
+
entry.busy = 'restore'; entry.note = ''; paintRequestCard(item);
|
|
3960
|
+
let restored = false;
|
|
3055
3961
|
try {
|
|
3056
3962
|
const done = await lifecycleCall(requestId, 'restore');
|
|
3057
|
-
if (!done.ok) { cardNotice(
|
|
3058
|
-
|
|
3963
|
+
if (!done.ok) { cardNotice(requestId, done.body?.error || 'FloLess couldn’t put that request back. It is still in Requests → Done; try Undo again.'); return; }
|
|
3964
|
+
item = liveRequestCard(requestId);
|
|
3965
|
+
if (item) forgetHiddenRequestCard(item.dataset.cardEventId);
|
|
3059
3966
|
await refreshRequestCards({ force: true });
|
|
3967
|
+
restored = true;
|
|
3060
3968
|
} catch {
|
|
3061
|
-
cardNotice(
|
|
3062
|
-
} finally {
|
|
3969
|
+
cardNotice(requestId, 'FloLess couldn’t reach the server, so the request was not put back. Try Undo again in a moment.');
|
|
3970
|
+
} finally {
|
|
3971
|
+
entry.busy = null;
|
|
3972
|
+
const card = repaintRequestCard(requestId);
|
|
3973
|
+
if (restored) card?.querySelector('.ai-chat-request-dismiss:not([hidden])')?.focus();
|
|
3974
|
+
}
|
|
3063
3975
|
}
|
|
3064
3976
|
|
|
3065
3977
|
// #1907: the plain name of one of the person's connectors — the same rule the server words its cards with.
|
|
@@ -3092,7 +4004,7 @@
|
|
|
3092
4004
|
// #2037: a Codex auto-review decision is a receipt, not a failure: approved is information, held back is a notice.
|
|
3093
4005
|
const review = event.payload?.tool === 'auto-review' ? event.payload.decision : null;
|
|
3094
4006
|
// #2035: a step declined because nobody was watching a scheduled run is a notice the person reads later, not an error.
|
|
3095
|
-
const unattended = event.payload?.tool === 'unattended-decline' || event.payload?.tool === 'unattended-question';
|
|
4007
|
+
const unattended = event.payload?.tool === 'unattended-decline' || event.payload?.tool === 'unattended-question' || event.payload?.tool === 'approval-dropped';
|
|
3096
4008
|
// #2058: an account command Codex ran without asking FloLess already ran; its line says the result is unchecked.
|
|
3097
4009
|
const unchecked = event.payload?.tool === 'unchecked-command';
|
|
3098
4010
|
item.className = review === 'approved' ? 'ai-chat-event auto-review' : review || unattended || unchecked ? 'ai-chat-event auto-review held' : 'ai-chat-event error';
|
|
@@ -3101,7 +4013,7 @@
|
|
|
3101
4013
|
const label = document.createElement('strong');
|
|
3102
4014
|
// #2223: a question the AI asked while nobody was watching went unanswered, not declined.
|
|
3103
4015
|
label.textContent = review === 'approved' ? 'Auto-approved' : review ? 'Held back'
|
|
3104
|
-
: unattended ? (event.payload?.tool === 'unattended-question' ? 'Not asked' : 'Declined') : unchecked ? 'Not checked' : 'Not done';
|
|
4016
|
+
: unattended ? (event.payload?.tool === 'unattended-question' ? 'Not asked' : event.payload?.tool === 'approval-dropped' ? 'Not answered' : 'Declined') : unchecked ? 'Not checked' : 'Not done';
|
|
3105
4017
|
item.append(label, document.createTextNode(` · ${event.payload.message}`));
|
|
3106
4018
|
return item;
|
|
3107
4019
|
}
|
|
@@ -3448,7 +4360,9 @@
|
|
|
3448
4360
|
notNow.disabled = entry.busy;
|
|
3449
4361
|
notNow.addEventListener('click', () => { void setConnectionDismissed(event, true); });
|
|
3450
4362
|
// Nothing is left to set aside once it is connected (#2185); Change account is still there.
|
|
3451
|
-
|
|
4363
|
+
// #2678: not connected yet, it waits for the person; a hidden card's line says the card's own sentence about where it is.
|
|
4364
|
+
if (!connected) { actions.append(notNow); entry.seenOpen = true; card.dataset.waits = 'you'; card.dataset.waitsSays = stateLine.textContent; }
|
|
4365
|
+
else card.dataset.waits = 'done';
|
|
3452
4366
|
card.append(stateLine, ...(keyCode ? [keyCode] : []), actions, confirmHost, receiptHost, said, error);
|
|
3453
4367
|
return card;
|
|
3454
4368
|
}
|
|
@@ -3834,6 +4748,13 @@
|
|
|
3834
4748
|
// A request that has been answered no longer "needs your OK": the eyebrow says where it ended up.
|
|
3835
4749
|
// #2427: a step that left the last click to the person is theirs to finish, not a failure and not yet done.
|
|
3836
4750
|
const handedOver = current.state === 'done' && current.result?.code === 'step-handed-over';
|
|
4751
|
+
// #2678: what a hidden card's line says still waits: the person's choice, their last click, a result to check, or the
|
|
4752
|
+
// work running. The line's words follow the card's, never the kind's when they would not be true.
|
|
4753
|
+
const waitsSays = handedOver ? 'The last step is yours. Expand it to finish.'
|
|
4754
|
+
: { failed: 'Could not finish. Expand it to see why.', unknown: 'Outcome unknown. Expand it to check the result.' }[current.state];
|
|
4755
|
+
if (current.state === 'proposed' || waitsSays) card.dataset.waits = 'you';
|
|
4756
|
+
else card.dataset.waits = current.state === 'executing' ? 'ai' : 'done';
|
|
4757
|
+
if (waitsSays) card.dataset.waitsSays = waitsSays;
|
|
3837
4758
|
eyebrow.textContent = handedOver ? 'Waiting for you'
|
|
3838
4759
|
: { executing: actionId === 'workflows.run' || actionId === 'routines.run' ? 'Running' : 'Working', done: 'Finished', failed: 'Could not finish', unknown: 'Outcome unknown' }[current.state] || ACTION_EYEBROWS[risk];
|
|
3839
4760
|
const strong = document.createElement('strong');
|
|
@@ -4339,7 +5260,8 @@
|
|
|
4339
5260
|
/** The crop of the page around a place: the area and some room around it, never smaller than a fifth of the page. */
|
|
4340
5261
|
function evidenceCrop(place) {
|
|
4341
5262
|
const [px0, py0, px1, py1] = place.pageBounds;
|
|
4342
|
-
|
|
5263
|
+
// #2777: a place with no marked area (an RFI on a sheet, a level read from its picture) is the whole sheet.
|
|
5264
|
+
const [rx0, ry0, rx1, ry1] = Array.isArray(place.region) ? place.region : place.pageBounds;
|
|
4343
5265
|
const grow = (lo, hi, min, max) => {
|
|
4344
5266
|
const pad = Math.max((hi - lo) * 0.15, (max - min) * 0.01);
|
|
4345
5267
|
let a = lo - pad, b = hi + pad;
|
|
@@ -4355,12 +5277,63 @@
|
|
|
4355
5277
|
}
|
|
4356
5278
|
|
|
4357
5279
|
/** The place's page in the cited-source viewer, cropped to the place, with the whole sheet a press away. */
|
|
4358
|
-
|
|
4359
|
-
|
|
5280
|
+
function openReadinessEvidence(place, row, card, opener) {
|
|
5281
|
+
return openDrawingPlace(place, {
|
|
5282
|
+
title: String(place.title || place.label), note: EVIDENCE_ORIGIN[place.origin].note(place), opener,
|
|
5283
|
+
url: `/api/projects/${encodeURIComponent(card.projectId)}/connections/${encodeURIComponent(row.jointId)}/evidence/drawing?key=${encodeURIComponent(place.key)}&digest=${encodeURIComponent(place.digest)}`,
|
|
5284
|
+
commands: { close: 'shell.chat-readiness-evidence-close', view: 'shell.chat-readiness-evidence-view' },
|
|
5285
|
+
again: { label: 'Ask for the readiness card again', commandId: 'shell.chat-readiness-evidence-again', tip: 'Puts the request in the message box. Nothing is sent until you press Send',
|
|
5286
|
+
run: () => { addToMessageBox(`Show the readiness of connection ${row.jointId} again.`); ui.input.focus?.(); } },
|
|
5287
|
+
...(place.sourceHash && place.pageId ? { filter: { projectId: card.projectId, commandId: 'shell.chat-place-open-filter' } } : {}),
|
|
5288
|
+
});
|
|
5289
|
+
}
|
|
5290
|
+
|
|
5291
|
+
/**
|
|
5292
|
+
* #2777 slice D: "Open in Drawing Filter" for a place. The Drawing Filter does the showing; the viewer says what it did,
|
|
5293
|
+
* never more: it waits for the Filter's own outcome (as "Open in the model" waits for the editor's), closes once the place
|
|
5294
|
+
* is shown, and otherwise stays open with the reason in sight, so a place that could not be shown is never silent.
|
|
5295
|
+
*/
|
|
5296
|
+
function drawingFilterButton(place, filter, { shown, refused }) {
|
|
5297
|
+
const open = button('Open in Drawing Filter', filter.commandId, 'ai-chat-evidence-view ai-chat-evidence-filter');
|
|
5298
|
+
open.dataset.tip = 'Opens this sheet in the project\u2019s Drawing Filter with the place marked. Nothing changes';
|
|
5299
|
+
if (filter.instanceLabel) open.dataset.commandInstanceLabel = filter.instanceLabel;
|
|
5300
|
+
open.addEventListener('click', async () => {
|
|
5301
|
+
if (open.getAttribute('aria-busy') === 'true') return;
|
|
5302
|
+
const unreachable = 'FloLess could not open the Drawing Filter from here. Open the project’s Drawings step from Workspaces, then try again.';
|
|
5303
|
+
open.setAttribute('aria-busy', 'true');
|
|
5304
|
+
let said;
|
|
5305
|
+
try {
|
|
5306
|
+
if (typeof window.flolessWorkspaces?.openDrawingAt !== 'function') said = unreachable;
|
|
5307
|
+
else {
|
|
5308
|
+
const outcome = await window.flolessWorkspaces.openDrawingAt({ projectId: filter.projectId, place: {
|
|
5309
|
+
sourceHash: place.sourceHash, pageId: place.pageId, sheet: place.sheet, ...(Array.isArray(place.region) ? { region: place.region } : {}) } });
|
|
5310
|
+
if (outcome?.superseded) return;
|
|
5311
|
+
if (outcome?.ok === true) { shown(); announce(`Showing the place on sheet ${place.sheet} in the Drawing Filter.`); return; }
|
|
5312
|
+
said = outcome?.said || `The place on sheet ${place.sheet} was not shown. Open the Drawings step, then press Open in Drawing Filter again.`;
|
|
5313
|
+
}
|
|
5314
|
+
} catch (error) {
|
|
5315
|
+
if (error?.plain !== true) console.error('[chat] Open in Drawing Filter failed', error);
|
|
5316
|
+
said = error?.plain === true && error.message ? error.message : unreachable;
|
|
5317
|
+
} finally {
|
|
5318
|
+
open.removeAttribute('aria-busy');
|
|
5319
|
+
}
|
|
5320
|
+
if (said) refused(said);
|
|
5321
|
+
});
|
|
5322
|
+
return open;
|
|
5323
|
+
}
|
|
5324
|
+
|
|
5325
|
+
/**
|
|
5326
|
+
* A page of a drawing in the cited-source viewer, cropped to a place (`pageBounds`, `region`, `sheet`, `page`), with the
|
|
5327
|
+
* whole sheet a press away. Shared by the readiness card (#2451) and the height card (#2777); `again` is the way on
|
|
5328
|
+
* when the place changed or is gone, never something done for the person. A place with no `region` is a whole sheet:
|
|
5329
|
+
* it opens on the sheet and offers no "This area", since there is no area to show. `filter` (#2777 slice D) adds
|
|
5330
|
+
* "Open in Drawing Filter", which shows the same place in the project's Drawing Filter.
|
|
5331
|
+
*/
|
|
5332
|
+
async function openDrawingPlace(place, { title, note: noteText, url, opener, commands, again, filter }) {
|
|
4360
5333
|
const dialog = document.createElement('dialog'); dialog.className = 'ai-chat-source-viewer ai-chat-evidence-viewer';
|
|
4361
5334
|
dialog.setAttribute('aria-label', title);
|
|
4362
5335
|
const head = document.createElement('div'); head.className = 'ai-chat-source-viewer-head';
|
|
4363
|
-
const close = button('Close',
|
|
5336
|
+
const close = button('Close', commands.close, 'ai-chat-source-viewer-close');
|
|
4364
5337
|
let picture = null;
|
|
4365
5338
|
let finished = false;
|
|
4366
5339
|
const finish = () => {
|
|
@@ -4374,50 +5347,150 @@
|
|
|
4374
5347
|
close.addEventListener('click', finish);
|
|
4375
5348
|
dialog.addEventListener('close', finish);
|
|
4376
5349
|
head.append(Object.assign(document.createElement('strong'), { textContent: title }), close);
|
|
4377
|
-
const note = Object.assign(document.createElement('span'), { className: 'ai-chat-source-viewer-note', textContent:
|
|
5350
|
+
const note = Object.assign(document.createElement('span'), { className: 'ai-chat-source-viewer-note', textContent: noteText });
|
|
5351
|
+
const filterNote = Object.assign(document.createElement('p'), { className: 'ai-chat-evidence-filter-note', hidden: true });
|
|
5352
|
+
filterNote.setAttribute('role', 'status');
|
|
4378
5353
|
const views = document.createElement('div'); views.className = 'ai-chat-evidence-views'; views.setAttribute('role', 'group'); views.setAttribute('aria-label', 'How much of the sheet to show');
|
|
4379
|
-
const area = button('This area',
|
|
4380
|
-
const whole = button('Whole sheet',
|
|
5354
|
+
const area = button('This area', commands.view, 'ai-chat-evidence-view');
|
|
5355
|
+
const whole = button('Whole sheet', commands.view, 'ai-chat-evidence-view');
|
|
4381
5356
|
area.dataset.commandInstanceLabel = 'this area'; whole.dataset.commandInstanceLabel = 'the whole sheet';
|
|
4382
|
-
|
|
5357
|
+
const marked = Array.isArray(place.region);
|
|
5358
|
+
views.append(...(marked ? [area, whole] : [whole]));
|
|
5359
|
+
// Not one of the views: it leaves this viewer for another screen, so it sits beside the group, never in it.
|
|
5360
|
+
const bar = document.createElement('div'); bar.className = 'ai-chat-evidence-bar';
|
|
5361
|
+
bar.append(views);
|
|
5362
|
+
if (filter?.projectId && filter.commandId) {
|
|
5363
|
+
bar.append(drawingFilterButton(place, filter, {
|
|
5364
|
+
shown: () => finish(),
|
|
5365
|
+
// Said where the person clicked, and read out: the picture stays, so they can still look at the place here.
|
|
5366
|
+
refused: (said) => { if (finished) return; filterNote.textContent = said; filterNote.hidden = false; announce(said); },
|
|
5367
|
+
}));
|
|
5368
|
+
}
|
|
4383
5369
|
const body = document.createElement('div'); body.className = 'ai-chat-source-viewer-body';
|
|
4384
5370
|
const status = Object.assign(document.createElement('p'), { className: 'ai-chat-source-viewer-status', textContent: 'Loading the drawing…' });
|
|
4385
5371
|
status.setAttribute('role', 'status');
|
|
4386
5372
|
const crop = evidenceCrop(place);
|
|
4387
5373
|
const frame = document.createElement('div'); frame.className = 'ai-chat-evidence-frame';
|
|
5374
|
+
/*
|
|
5375
|
+
* What the frame shows, in page units, always shaped like the frame so the drawing is never stretched. "This area" and
|
|
5376
|
+
* "Whole sheet" set it; zoom (the buttons, the wheel, a double-click, + and -) and pan (a drag, the arrow keys) move
|
|
5377
|
+
* it. It may zoom out until the whole sheet fits and in to a fiftieth of the sheet's width, and never pans the page
|
|
5378
|
+
* out of the frame.
|
|
5379
|
+
*/
|
|
5380
|
+
let view = null;
|
|
5381
|
+
const paintView = () => {
|
|
5382
|
+
const image = frame.querySelector('img');
|
|
5383
|
+
if (image && view) Object.assign(image.style, { width: `${(crop.pageW / view.w) * 100}%`, left: `${(-(view.x0 - crop.px0) / view.w) * 100}%`, top: `${(-(view.y0 - crop.py0) / view.h) * 100}%` });
|
|
5384
|
+
if (!view) return;
|
|
5385
|
+
const ratio = view.h / view.w;
|
|
5386
|
+
zoomIn.disabled = view.w <= crop.pageW / 50 + 1e-9;
|
|
5387
|
+
zoomOut.disabled = view.w >= Math.max(crop.pageW, crop.pageH / ratio) - 1e-9;
|
|
5388
|
+
};
|
|
5389
|
+
const clampView = (v) => {
|
|
5390
|
+
const ratio = v.h / v.w;
|
|
5391
|
+
const w = Math.min(Math.max(v.w, crop.pageW / 50), Math.max(crop.pageW, crop.pageH / ratio));
|
|
5392
|
+
const h = w * ratio;
|
|
5393
|
+
// Smaller than the page on an axis: kept on the page. Larger: the page centred, so nothing drifts off.
|
|
5394
|
+
const fit = (lo, size, min, extent) => (size >= extent ? min + (extent - size) / 2 : Math.min(Math.max(lo, min), min + extent - size));
|
|
5395
|
+
return { x0: fit(v.x0, w, crop.px0, crop.pageW), y0: fit(v.y0, h, crop.py0, crop.pageH), w, h };
|
|
5396
|
+
};
|
|
5397
|
+
const moved = () => { area.setAttribute('aria-pressed', 'false'); whole.setAttribute('aria-pressed', 'false'); frame.dataset.view = 'zoomed'; };
|
|
5398
|
+
/** Zoom by `factor` (above 1 is in) about a point of the frame, given as fractions of its width and height. */
|
|
5399
|
+
const zoomAt = (factor, fx = 0.5, fy = 0.5) => {
|
|
5400
|
+
if (!view) return;
|
|
5401
|
+
const px = view.x0 + fx * view.w, py = view.y0 + fy * view.h;
|
|
5402
|
+
const next = clampView({ x0: 0, y0: 0, w: view.w / factor, h: view.h / factor });
|
|
5403
|
+
view = clampView({ x0: px - fx * next.w, y0: py - fy * next.h, w: next.w, h: next.h });
|
|
5404
|
+
moved(); paintView();
|
|
5405
|
+
};
|
|
5406
|
+
const panBy = (dx, dy) => { if (!view) return; view = clampView({ ...view, x0: view.x0 + dx, y0: view.y0 + dy }); moved(); paintView(); };
|
|
5407
|
+
// The view "0" goes back to: the last one chosen with This area or Whole sheet.
|
|
5408
|
+
let shownAll = !marked;
|
|
4388
5409
|
const show = (all) => {
|
|
5410
|
+
shownAll = all;
|
|
4389
5411
|
area.setAttribute('aria-pressed', String(!all)); whole.setAttribute('aria-pressed', String(all));
|
|
4390
5412
|
frame.dataset.view = all ? 'sheet' : 'area';
|
|
4391
5413
|
const c = all ? { x0: crop.px0, y0: crop.py0, w: crop.pageW, h: crop.pageH } : crop;
|
|
4392
5414
|
// Shaped like the crop and never taller than most of the window: narrowed, not squashed, so the picture stays true.
|
|
4393
5415
|
frame.style.aspectRatio = `${c.w} / ${c.h}`;
|
|
4394
5416
|
frame.style.width = `min(100%, calc(62vh * ${c.w / c.h}))`;
|
|
4395
|
-
|
|
4396
|
-
|
|
5417
|
+
view = { x0: c.x0, y0: c.y0, w: c.w, h: c.h };
|
|
5418
|
+
paintView();
|
|
4397
5419
|
};
|
|
5420
|
+
const zoom = document.createElement('div'); zoom.className = 'ai-chat-evidence-zoom'; zoom.setAttribute('role', 'group'); zoom.setAttribute('aria-label', 'Zoom the drawing');
|
|
5421
|
+
const zoomOut = button('−', 'shell.chat-drawing-zoom-out', 'ai-chat-evidence-zoom-out');
|
|
5422
|
+
const zoomIn = button('+', 'shell.chat-drawing-zoom-in', 'ai-chat-evidence-zoom-in');
|
|
5423
|
+
zoomOut.setAttribute('aria-label', 'Zoom out'); zoomOut.dataset.tip = 'Zoom out (or scroll down on the drawing, or press -)';
|
|
5424
|
+
zoomIn.setAttribute('aria-label', 'Zoom in'); zoomIn.dataset.tip = 'Zoom in (or scroll up on the drawing, or press +)';
|
|
5425
|
+
zoomOut.addEventListener('click', () => zoomAt(1 / 1.5));
|
|
5426
|
+
zoomIn.addEventListener('click', () => zoomAt(1.5));
|
|
5427
|
+
zoom.append(zoomOut, zoomIn);
|
|
5428
|
+
bar.insertBefore(zoom, views.nextSibling);
|
|
5429
|
+
// The drawing itself: scroll to zoom where the pointer is, drag to move it, double-click to zoom in there.
|
|
5430
|
+
frame.tabIndex = 0;
|
|
5431
|
+
frame.setAttribute('role', 'group');
|
|
5432
|
+
frame.setAttribute('aria-label', 'Drawing. Drag or use the arrow keys to move it; scroll, or press + and -, to zoom; 0 goes back.');
|
|
5433
|
+
frame.dataset.commandId = 'shell.chat-drawing-pan';
|
|
5434
|
+
const fraction = (event) => { const r = frame.getBoundingClientRect(); return [Math.min(1, Math.max(0, (event.clientX - r.left) / r.width)), Math.min(1, Math.max(0, (event.clientY - r.top) / r.height))]; };
|
|
5435
|
+
frame.addEventListener('wheel', (event) => {
|
|
5436
|
+
// A sideways swipe is not a zoom, and at the limit the wheel scrolls the dialog as it would anywhere else.
|
|
5437
|
+
if (!view || !event.deltaY) return;
|
|
5438
|
+
const zoomingIn = event.deltaY < 0;
|
|
5439
|
+
if (zoomingIn ? zoomIn.disabled : zoomOut.disabled) return;
|
|
5440
|
+
event.preventDefault();
|
|
5441
|
+
zoomAt(zoomingIn ? 1.2 : 1 / 1.2, ...fraction(event));
|
|
5442
|
+
}, { passive: false });
|
|
5443
|
+
frame.addEventListener('dblclick', (event) => { event.preventDefault(); zoomAt(1.5, ...fraction(event)); });
|
|
5444
|
+
let drag = null;
|
|
5445
|
+
frame.addEventListener('pointerdown', (event) => {
|
|
5446
|
+
if (!view || event.button !== 0) return;
|
|
5447
|
+
event.preventDefault();
|
|
5448
|
+
// preventDefault (no text selection, no image drag) also stops the click focusing the drawing, so it is focused here:
|
|
5449
|
+
// after a click the arrow keys, + / - and 0 act on it.
|
|
5450
|
+
frame.focus({ preventScroll: true });
|
|
5451
|
+
frame.setPointerCapture?.(event.pointerId);
|
|
5452
|
+
drag = { id: event.pointerId, x: event.clientX, y: event.clientY, from: { ...view } };
|
|
5453
|
+
frame.classList.add('dragging');
|
|
5454
|
+
});
|
|
5455
|
+
frame.addEventListener('pointermove', (event) => {
|
|
5456
|
+
if (!drag || event.pointerId !== drag.id) return;
|
|
5457
|
+
const r = frame.getBoundingClientRect();
|
|
5458
|
+
view = clampView({ ...drag.from, x0: drag.from.x0 - ((event.clientX - drag.x) / r.width) * drag.from.w, y0: drag.from.y0 - ((event.clientY - drag.y) / r.height) * drag.from.h });
|
|
5459
|
+
moved(); paintView();
|
|
5460
|
+
});
|
|
5461
|
+
const endDrag = (event) => { if (!drag || event.pointerId !== drag.id) return; drag = null; frame.classList.remove('dragging'); };
|
|
5462
|
+
frame.addEventListener('pointerup', endDrag);
|
|
5463
|
+
frame.addEventListener('pointercancel', endDrag);
|
|
5464
|
+
frame.addEventListener('keydown', (event) => {
|
|
5465
|
+
if (!view) return;
|
|
5466
|
+
const step = 0.1;
|
|
5467
|
+
const keys = { ArrowLeft: () => panBy(-view.w * step, 0), ArrowRight: () => panBy(view.w * step, 0), ArrowUp: () => panBy(0, -view.h * step), ArrowDown: () => panBy(0, view.h * step),
|
|
5468
|
+
'+': () => zoomAt(1.5), '=': () => zoomAt(1.5), '-': () => zoomAt(1 / 1.5), '0': () => show(shownAll) };
|
|
5469
|
+
// The numpad's keys, and a layout whose + needs Shift, still zoom.
|
|
5470
|
+
const byCode = { NumpadAdd: '+', NumpadSubtract: '-', Equal: '+', Minus: '-' };
|
|
5471
|
+
const run = keys[event.key] || keys[byCode[event.code]];
|
|
5472
|
+
if (!run) return;
|
|
5473
|
+
event.preventDefault();
|
|
5474
|
+
run();
|
|
5475
|
+
});
|
|
4398
5476
|
area.addEventListener('click', () => show(false));
|
|
4399
5477
|
whole.addEventListener('click', () => show(true));
|
|
4400
|
-
show(
|
|
5478
|
+
show(!marked);
|
|
4401
5479
|
body.append(status, frame);
|
|
4402
|
-
dialog.append(head, note,
|
|
5480
|
+
dialog.append(head, note, bar, filterNote, body);
|
|
4403
5481
|
const hide = showChatViewer(dialog, finish);
|
|
4404
5482
|
close.focus({ preventScroll: true });
|
|
4405
5483
|
// A place that changed or is gone says so and offers the way on: the card asked for again, never sent for the person.
|
|
4406
5484
|
const offerAgain = (why) => {
|
|
4407
5485
|
if (finished) return;
|
|
4408
5486
|
status.textContent = why;
|
|
4409
|
-
frame.remove();
|
|
4410
|
-
const
|
|
4411
|
-
again.dataset.tip =
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
addToMessageBox(`Show the readiness of connection ${row.jointId} again.`);
|
|
4415
|
-
ui.input.focus?.();
|
|
4416
|
-
});
|
|
4417
|
-
dialog.append(again);
|
|
5487
|
+
frame.remove(); bar.remove(); filterNote.remove();
|
|
5488
|
+
const way = button(again.label, again.commandId, 'ai-chat-source-viewer-knowledge');
|
|
5489
|
+
if (again.tip) way.dataset.tip = again.tip;
|
|
5490
|
+
way.addEventListener('click', () => { finish(); again.run(); });
|
|
5491
|
+
dialog.append(way);
|
|
4418
5492
|
};
|
|
4419
5493
|
try {
|
|
4420
|
-
const url = `/api/projects/${encodeURIComponent(card.projectId)}/connections/${encodeURIComponent(row.jointId)}/evidence/drawing?key=${encodeURIComponent(place.key)}&digest=${encodeURIComponent(place.digest)}`;
|
|
4421
5494
|
const response = await fetch(url, { credentials: 'same-origin', cache: 'no-store' });
|
|
4422
5495
|
if (finished) return;
|
|
4423
5496
|
if (!response.ok) {
|
|
@@ -4428,9 +5501,10 @@
|
|
|
4428
5501
|
const bytes = await response.blob();
|
|
4429
5502
|
if (finished) return;
|
|
4430
5503
|
picture = URL.createObjectURL(bytes);
|
|
4431
|
-
const image = Object.assign(document.createElement('img'), { src: picture, alt: `${title}, page ${place.page}, with the area outlined` });
|
|
5504
|
+
const image = Object.assign(document.createElement('img'), { src: picture, alt: marked ? `${title}, page ${place.page}, with the area outlined` : `${title}, page ${place.page}` });
|
|
5505
|
+
image.draggable = false;
|
|
4432
5506
|
frame.append(image);
|
|
4433
|
-
|
|
5507
|
+
paintView();
|
|
4434
5508
|
status.textContent = `${place.sheet} · page ${place.page}`;
|
|
4435
5509
|
} catch (error) {
|
|
4436
5510
|
console.error('[chat] a drawing place could not be opened', error);
|
|
@@ -4474,7 +5548,13 @@
|
|
|
4474
5548
|
const body = document.createElement('div'); body.className = 'ai-chat-readiness-body'; body.tabIndex = 0;
|
|
4475
5549
|
body.setAttribute('aria-label', 'Connections and their checks');
|
|
4476
5550
|
for (const row of rows) body.append(readinessRow(row, card));
|
|
4477
|
-
node.append(head, limits
|
|
5551
|
+
node.append(head, limits);
|
|
5552
|
+
// #2521 row 5: measured on a Quick model (or one whose AI decisions could not be read): said with the card, which
|
|
5553
|
+
// outlives the project screen, in the server's own words.
|
|
5554
|
+
const quick = card.quick && (card.quick.state === 'quick' || card.quick.state === 'unknown') && typeof card.quick.label === 'string' ? card.quick : null;
|
|
5555
|
+
if (quick) node.append(Object.assign(document.createElement('p'), { className: 'ai-chat-readiness-limits ai-chat-readiness-quick',
|
|
5556
|
+
textContent: `The model measured here: ${quick.label}. ${quick.tip || ''}`.trim() }));
|
|
5557
|
+
node.append(body);
|
|
4478
5558
|
const notes = [];
|
|
4479
5559
|
// The card names at most a few of each; the rest are counted, never dropped.
|
|
4480
5560
|
const andMore = (list, more) => `${list.join(', ')}${more ? `, and ${more} more` : ''}`;
|
|
@@ -5028,6 +6108,14 @@
|
|
|
5028
6108
|
const fact = 'fact' in server ? server.fact : payload.fact;
|
|
5029
6109
|
const blocking = cardClass === 'blocking' || cardClass === 'resume';
|
|
5030
6110
|
if (!blocking) card.classList.add('is-idea');
|
|
6111
|
+
// #2678: only a read whose result came back is settled (it folds by itself). A failed or unknown outcome, or a card
|
|
6112
|
+
// offered again, is the person's to look at; its line says which.
|
|
6113
|
+
const read = server.state === 'used' ? entry.result : null;
|
|
6114
|
+
card.dataset.waits = read?.ok ? 'done' : 'you';
|
|
6115
|
+
const waitsSays = read ? (read.ok ? 'Done. Expand it to see the result.' : 'Did not complete. Expand it to see why.')
|
|
6116
|
+
: server.state === 'used' && server.outcome === 'indeterminate' ? 'Outcome unknown. Expand it to check the result.'
|
|
6117
|
+
: entry.error ? 'Could not finish. Expand it to see why.' : '';
|
|
6118
|
+
if (waitsSays) card.dataset.waitsSays = waitsSays;
|
|
5031
6119
|
const head = assistantNode('div', 'ai-chat-filter-card-head');
|
|
5032
6120
|
const named = assistantNode('div', 'ai-chat-action-named');
|
|
5033
6121
|
const strong = assistantNode('strong', '', text.title);
|
|
@@ -5212,6 +6300,9 @@
|
|
|
5212
6300
|
async function useAssistantCard(entry, text) {
|
|
5213
6301
|
if (entry.busy) return;
|
|
5214
6302
|
const chatId = entry.event.chatId;
|
|
6303
|
+
// #2678: the person's own click holds the card open (a read's result is shown on it), counted from the click so a
|
|
6304
|
+
// collapse while it is answered still wins.
|
|
6305
|
+
openFeedCard(entry.event.eventId);
|
|
5215
6306
|
entry.busy = 'use'; entry.error = '';
|
|
5216
6307
|
repaintAssistantCard(entry);
|
|
5217
6308
|
let answer = null;
|
|
@@ -5356,6 +6447,9 @@
|
|
|
5356
6447
|
|
|
5357
6448
|
/** The request a card made arrives as its own card below (an event): its Confirm gets the keyboard once it is drawn. */
|
|
5358
6449
|
function focusProposalConfirm(proposalId, onMissing = () => {}, tries = 40) {
|
|
6450
|
+
// #2678: Show the request is the person asking for the proposal card: a folded one opens, and stays open.
|
|
6451
|
+
const asked = state.events.find((event) => event.type === 'action-proposal' && String(event.payload?.proposalId || event.eventId) === proposalId);
|
|
6452
|
+
if (asked) { openFeedCard(asked.eventId); paintEvents(); }
|
|
5359
6453
|
const proposal = ui.feed?.querySelector(`.ai-chat-action-card[data-proposal-id="${CSS.escape(proposalId)}"]`);
|
|
5360
6454
|
if (proposal) {
|
|
5361
6455
|
// Its Confirm (or a person-only step's Open); a request already answered has neither, so its own line.
|
|
@@ -5489,6 +6583,187 @@
|
|
|
5489
6583
|
return fold;
|
|
5490
6584
|
}
|
|
5491
6585
|
|
|
6586
|
+
/*
|
|
6587
|
+
* #2678 — EVERY CARD IN THE CONVERSATION FOLDS TO ONE LINE. Owner, 2026-10-23: "Any card should have that functionality",
|
|
6588
|
+
* once the cards above the message box could (#2684). Its chevron (or Esc) folds a card to one line that says what it was
|
|
6589
|
+
* and what still waits; the line's chevron opens it again with nothing lost, showing where it stands now. Owner,
|
|
6590
|
+
* 2026-10-24: a card arrives open, and once it is answered or settled it folds by itself ("follow what Claude does"),
|
|
6591
|
+
* still one click from open; so does one still waiting for the person once they send a message after it ("someone
|
|
6592
|
+
* answered it into the general chat box ... this card should also disappear"), the drawing card's rule (#2684). A card
|
|
6593
|
+
* the person opens stays open (one still waiting, until they send another message). Nothing leaves the conversation: the
|
|
6594
|
+
* line says what happened, or what still waits. Folding applies, answers, dismisses or declines nothing: a suggestion
|
|
6595
|
+
* stays unapplied, a request keeps whatever state it is in. The chevron sits on a shell kept per card rather than in the
|
|
6596
|
+
* card, because several cards repaint themselves in place (replaceWith, the Guide's replaceChildren) and would drop it.
|
|
6597
|
+
* A one-line row (a receipt, a notice, a line the AI ran) and an ordinary message have none: folding one line to another
|
|
6598
|
+
* saves nothing (UX review; #2684 left the one-line auto-approval strip alone for the same reason). A fold by hand is not
|
|
6599
|
+
* remembered: a reload shows every card as it arrives (open, or folded by itself once settled), as above the message
|
|
6600
|
+
* box, except a request card #2185's × hid for good (below).
|
|
6601
|
+
* A card says what waits with data-waits, set by its own renderer: "you" (the person's choice or answer), "ai" (the AI
|
|
6602
|
+
* or the read still works) or "done" (answered or settled: it folds by itself); data-waits-says, when set, is what its
|
|
6603
|
+
* line says about it instead of the kind's words. A card with no mark (a result, a card still loading) stays as it is.
|
|
6604
|
+
*/
|
|
6605
|
+
// Cards the person folded by hand (and #2185's hidden requests, below), until they open them.
|
|
6606
|
+
const hiddenFeedCards = new Set();
|
|
6607
|
+
// Cards the person opened, each with the messages there were then (folded again by hand: hiddenFeedCards). Their choice
|
|
6608
|
+
// wins over folding by itself, until they send another message.
|
|
6609
|
+
const openedFeedCards = new Map();
|
|
6610
|
+
// Cards folded because the person wrote in the message box after them.
|
|
6611
|
+
const movedPastFeedCards = new Set();
|
|
6612
|
+
// #2185's × hid a finished request card for good, remembered in this browser: those cards start folded instead, until opened.
|
|
6613
|
+
for (const id of hiddenRequestCards()) hiddenFeedCards.add(id);
|
|
6614
|
+
const feedCardShells = new Map();
|
|
6615
|
+
const feedCardLines = new Map();
|
|
6616
|
+
let feedCardsChat = null;
|
|
6617
|
+
|
|
6618
|
+
/**
|
|
6619
|
+
* What a feed card is, for its chevron and its line: { label, name, waits, working } (waits: what its line says while the
|
|
6620
|
+
* person's choice is open; working: while the AI's side works), or null for an event whose node never hides.
|
|
6621
|
+
*/
|
|
6622
|
+
function feedCardKind(event) {
|
|
6623
|
+
const payload = event?.payload || {};
|
|
6624
|
+
const choice = 'It waits for your choice.';
|
|
6625
|
+
switch (event?.type) {
|
|
6626
|
+
case 'filter-proposal': return { label: 'Drawing Filter', name: 'the Drawing Filter suggestion', waits: `Not applied yet. ${choice}` };
|
|
6627
|
+
case 'user-message':
|
|
6628
|
+
if (payload.source !== 'request') return null;
|
|
6629
|
+
return payload.filterAi ? { label: 'Drawing Filter', name: 'your Drawing Filter question' } : { label: 'Request', name: 'the request card' };
|
|
6630
|
+
case 'assistant-message':
|
|
6631
|
+
return payload.filterAi && !payload.delta ? { label: 'Drawing Filter', name: 'the Drawing Filter answer', waits: `Not applied yet. ${choice}` } : null;
|
|
6632
|
+
case 'action-proposal': return { label: 'Action', name: 'the suggested action', waits: `Not run yet. ${choice}` };
|
|
6633
|
+
case 'action-call': return { label: 'Result', name: 'the result the AI showed' };
|
|
6634
|
+
case 'connection-proposal': return { label: 'Connection', name: 'the connection suggestion', waits: choice };
|
|
6635
|
+
case 'connection-check': return { label: 'Connection', name: 'the connection check' };
|
|
6636
|
+
case 'next-move': return { label: 'Next step', name: 'the suggested next step', waits: choice };
|
|
6637
|
+
case 'tekla-read': return { label: 'Model read', name: 'the model read' };
|
|
6638
|
+
case 'height-question': return { label: 'Heights', name: 'the height question', waits: 'Still waiting for your answer.', working: 'Your answers are with the read.' };
|
|
6639
|
+
case 'setup-question': return { label: 'Read setup', name: 'the read setup question', waits: 'Still waiting for your answer.', working: 'Your answers are with the read.' };
|
|
6640
|
+
default: return null;
|
|
6641
|
+
}
|
|
6642
|
+
}
|
|
6643
|
+
|
|
6644
|
+
const feedCardRow = (node) => node.matches('.ai-chat-event, .ai-chat-action-row');
|
|
6645
|
+
/**
|
|
6646
|
+
* The person wrote in the message box after this card (and after they last opened it): they moved on, so a card that
|
|
6647
|
+
* waits for them folds, still saying it waits. Only a message FloLess says was not sent does not count (#2684's rule).
|
|
6648
|
+
*/
|
|
6649
|
+
function feedCardAnsweredInChat(event, id) {
|
|
6650
|
+
const seen = openedFeedCards.get(id);
|
|
6651
|
+
return state.events.some((other) => other.type === 'user-message' && !other.payload?.source && Number(other.sequence) > Number(event.sequence)
|
|
6652
|
+
&& !seen?.has(messageId(other)) && !((other.payload?.followup || other.payload?.deliveryState) && followupDelivery(other) === 'not-sent'));
|
|
6653
|
+
}
|
|
6654
|
+
/** The element that says what waits on a card: the card itself, or the suggestion card inside an answer. */
|
|
6655
|
+
const feedCardMark = (node) => (node.matches('[data-waits]') ? node : node.querySelector('[data-waits]'));
|
|
6656
|
+
/** A card already folded to one quiet line of its own (set aside, Not now, used): nothing to fold (its chevron is hidden by CSS). */
|
|
6657
|
+
const feedCardFolded = (card) => Boolean(card?.matches('.is-collapsed, .is-dismissed') || card?.querySelector(':scope > .ai-chat-connection-collapsed'));
|
|
6658
|
+
/**
|
|
6659
|
+
* What the line says: the card's name or title, cut at a word, then what waits (the card's own words, else its kind's)
|
|
6660
|
+
* or the state word the card shows ("Applied", "Done", "Dismissed"). A request says its own live word either way.
|
|
6661
|
+
*/
|
|
6662
|
+
function feedCardSentence(node, kind, mark) {
|
|
6663
|
+
const words = String((node.matches('.ai-chat-request-card') ? node.querySelector('p')?.textContent
|
|
6664
|
+
: node.getAttribute('aria-label') || node.querySelector('strong, .ai-chat-message-body, p')?.textContent) || node.textContent || '')
|
|
6665
|
+
.replace(/\s+/g, ' ').trim();
|
|
6666
|
+
const cut = (text, max) => (text.length > max ? `${text.slice(0, max).replace(/\s+\S*$/, '').replace(/[\s·,;:.-]+$/, '')}…` : text);
|
|
6667
|
+
const title = cut(words, 70);
|
|
6668
|
+
// A state word, cut too: the readiness card's chip is a whole summary.
|
|
6669
|
+
const shown = cut(node.querySelector('.ai-chat-request-status, .ai-chat-filter-state, .guide-move-eyebrow')?.textContent.trim() || '', 48);
|
|
6670
|
+
const waits = mark?.dataset.waits || '';
|
|
6671
|
+
const tail = mark?.dataset.waitsSays || (waits === 'you' && kind.waits) || (waits === 'ai' && kind.working)
|
|
6672
|
+
|| (shown && `${shown.charAt(0).toUpperCase()}${shown.slice(1)}`);
|
|
6673
|
+
return { sentence: [title, tail].filter(Boolean).join(' · '), full: words };
|
|
6674
|
+
}
|
|
6675
|
+
|
|
6676
|
+
/** A feed card in its shell (with its chevron), or the one line it leaves while folded. Any other node comes back as it was. */
|
|
6677
|
+
function feedCard(node, event) {
|
|
6678
|
+
const kind = node && event?.eventId ? feedCardKind(event) : null;
|
|
6679
|
+
// A card its renderer keeps hidden (an assistant card whose state is still loading) shows nothing, so it gets no chevron.
|
|
6680
|
+
if (!kind || feedCardRow(node) || node.hidden) return node;
|
|
6681
|
+
const chatId = state.chat?.chatId || '';
|
|
6682
|
+
if (feedCardsChat !== chatId) { feedCardShells.clear(); feedCardLines.clear(); feedCardsChat = chatId; }
|
|
6683
|
+
const id = event.eventId;
|
|
6684
|
+
const mark = feedCardMark(node);
|
|
6685
|
+
const waits = mark?.dataset.waits || '';
|
|
6686
|
+
// Answered or settled folds by itself, unless the person opened it; so does one waiting for them once they write in the
|
|
6687
|
+
// message box. A card already one quiet line of its own stays as it is.
|
|
6688
|
+
// Once a message folds it, it stays folded while that message counts, whatever the card turns into meanwhile (its line
|
|
6689
|
+
// follows); a message refused or not sent stops counting, and the card is back.
|
|
6690
|
+
const movedPast = (waits === 'you' || movedPastFeedCards.has(id)) && feedCardAnsweredInChat(event, id);
|
|
6691
|
+
if (movedPast) movedPastFeedCards.add(id);
|
|
6692
|
+
const byItself = !feedCardFolded(node) && ((waits === 'done' && !openedFeedCards.has(id)) || movedPast);
|
|
6693
|
+
if (hiddenFeedCards.has(id) || byItself) {
|
|
6694
|
+
const { sentence, full } = feedCardSentence(node, kind, mark);
|
|
6695
|
+
// Amber while the person's choice waits, blue while the AI or the read still works, quiet once it is finished.
|
|
6696
|
+
const line = paintHiddenLine(feedCardLines.get(id), null, {
|
|
6697
|
+
className: `ai-chat-feed-hidden${waits === 'you' ? ' is-decision' : waits === 'ai' ? ' is-open' : ''}`, label: kind.label, sentence,
|
|
6698
|
+
commandId: `shell.chat-feed-card-show#${id}`, instance: kind.name, tip: full.length > 70 ? full : '', show: () => showFeedCard(id, kind),
|
|
6699
|
+
});
|
|
6700
|
+
// It opens a card that is no longer in the page, so it controls nothing: the state is in its name instead.
|
|
6701
|
+
line.removeAttribute('aria-expanded');
|
|
6702
|
+
line.setAttribute('aria-label', `Expand ${kind.name}. ${sentence}`);
|
|
6703
|
+
// A request's line follows its live state, which the request cards poll for (refreshRequestCards).
|
|
6704
|
+
if (node.matches('.ai-chat-request-card')) line.dataset.requestId = node.dataset.requestId || ''; else delete line.dataset.requestId;
|
|
6705
|
+
feedCardLines.set(id, line);
|
|
6706
|
+
return line;
|
|
6707
|
+
}
|
|
6708
|
+
let shell = feedCardShells.get(id);
|
|
6709
|
+
if (!shell) {
|
|
6710
|
+
shell = document.createElement('div');
|
|
6711
|
+
shell.className = 'ai-chat-feed-card';
|
|
6712
|
+
// The chevron of an open card (the receipt fold's own, turned down); the folded line's points right (paintHiddenLine).
|
|
6713
|
+
const hide = button('›', `shell.chat-feed-card-hide#${id}`, 'ai-chat-card-hide');
|
|
6714
|
+
// A double click is one hide: its second click would land on the line that took the card's place and show it again.
|
|
6715
|
+
hide.addEventListener('click', (click) => { if (!(click.detail > 1)) hideFeedCard(id); });
|
|
6716
|
+
shell.addEventListener('keydown', (key) => {
|
|
6717
|
+
if (!window.FlolessQuestionCard?.escapeHides(key) || feedCardFolded(shell.firstElementChild)) return;
|
|
6718
|
+
key.preventDefault(); key.stopPropagation(); hideFeedCard(id);
|
|
6719
|
+
});
|
|
6720
|
+
shell.hideButton = hide;
|
|
6721
|
+
shell.feedCardId = id;
|
|
6722
|
+
feedCardShells.set(id, shell);
|
|
6723
|
+
}
|
|
6724
|
+
const hide = shell.hideButton;
|
|
6725
|
+
hide.dataset.commandInstanceLabel = kind.name;
|
|
6726
|
+
hide.setAttribute('aria-label', `Collapse ${kind.name}`);
|
|
6727
|
+
hide.dataset.tip = waits === 'you' ? 'Collapse to one line. Nothing is applied or answered, and it keeps waiting for you.' : 'Collapse to one line. Expand it any time.';
|
|
6728
|
+
if (shell.firstChild !== node || shell.lastChild !== hide) shell.replaceChildren(node, hide);
|
|
6729
|
+
return shell;
|
|
6730
|
+
}
|
|
6731
|
+
/** Keyboard into a card: on the control `commandId` names, else its first usable control in sight, else its first control, else the card itself. */
|
|
6732
|
+
function focusFeedCard(card, commandId = null) {
|
|
6733
|
+
const controls = [...card.querySelectorAll('button, a[href], input, select, textarea, [tabindex="0"]')].filter((node) => !node.disabled && !node.closest('[hidden]'));
|
|
6734
|
+
// Not a control scrolled out of its card's list, even partly: the list stays where the person left it, so focus would be
|
|
6735
|
+
// out of sight. A control `commandId` names is used even when out of sight.
|
|
6736
|
+
const inSight = (node) => {
|
|
6737
|
+
const list = node.closest('.ai-chat-height-rows'); if (!list?.getBoundingClientRect) return true;
|
|
6738
|
+
const at = node.getBoundingClientRect(), box = list.getBoundingClientRect();
|
|
6739
|
+
return at.top >= box.top && at.bottom <= box.bottom;
|
|
6740
|
+
};
|
|
6741
|
+
const target = (commandId && controls.find((node) => node.dataset.commandId === commandId)) || controls.find(inSight) || controls[0] || card;
|
|
6742
|
+
if (target === card && !card.hasAttribute('tabindex')) card.tabIndex = -1;
|
|
6743
|
+
target.focus({ preventScroll: true });
|
|
6744
|
+
return target;
|
|
6745
|
+
}
|
|
6746
|
+
function hideFeedCard(eventId) {
|
|
6747
|
+
hiddenFeedCards.add(eventId); openedFeedCards.delete(eventId);
|
|
6748
|
+
paintEvents();
|
|
6749
|
+
feedCardLines.get(eventId)?.focus({ preventScroll: true });
|
|
6750
|
+
}
|
|
6751
|
+
/** The person opens a card: it stays open until they fold it (one still waiting, until their next message). */
|
|
6752
|
+
function openFeedCard(eventId) {
|
|
6753
|
+
hiddenFeedCards.delete(eventId); movedPastFeedCards.delete(eventId); openedFeedCards.set(eventId, drawingMessageIds());
|
|
6754
|
+
forgetHiddenRequestCard(eventId); // a card #2185's × hid for good stays open after a reload too, once opened
|
|
6755
|
+
}
|
|
6756
|
+
function showFeedCard(eventId, kind) {
|
|
6757
|
+
openFeedCard(eventId);
|
|
6758
|
+
paintEvents();
|
|
6759
|
+
const card = feedCardShells.get(eventId)?.firstElementChild;
|
|
6760
|
+
if (!card || card.classList.contains('ai-chat-card-hide')) return;
|
|
6761
|
+
// The keyboard lands on the card's first control (or the card), and a screen reader hears which card came back.
|
|
6762
|
+
focusFeedCard(card);
|
|
6763
|
+
card.scrollIntoView?.({ block: 'nearest' });
|
|
6764
|
+
announce(`${kind.label} card expanded.`);
|
|
6765
|
+
}
|
|
6766
|
+
|
|
5492
6767
|
function renderEvent(event) {
|
|
5493
6768
|
if (event.type === 'user-message' && event.payload?.source === 'request' && event.payload?.filterAi) return renderFilterQuestion(event);
|
|
5494
6769
|
if (event.type === 'user-message' && event.payload?.source === 'request') return renderRequestCard(event);
|
|
@@ -5506,6 +6781,8 @@
|
|
|
5506
6781
|
// #1900: a connection the AI suggested, the result of a check it asked for, and a check run under "Allow for this chat".
|
|
5507
6782
|
if (event.type === 'connection-proposal') return renderConnectionProposal(event);
|
|
5508
6783
|
if (event.type === 'connection-proposal-update') return null;
|
|
6784
|
+
// #2642/#2643: the person's assumption or chosen source on an unsourced claim is shown on that claim's chip and in its text, never as a row.
|
|
6785
|
+
if (event.type === 'citation-assumption' || event.type === 'citation-choice') return null;
|
|
5509
6786
|
if (event.type === 'connection-check') return renderConnectionCheck(event);
|
|
5510
6787
|
// #2046: a next move the Guide suggested; web/guide.js paints it and owns its button.
|
|
5511
6788
|
// #2399 PR C2: a next step the assistant suggested in a project, workflow or workspace chat; this file paints it.
|
|
@@ -5675,7 +6952,11 @@
|
|
|
5675
6952
|
|
|
5676
6953
|
const heightEndKey = (row) => `${row.memberId}\u0000${row.end}`;
|
|
5677
6954
|
const heightEndWord = (row) => (row.endWord === 'from' ? 'start' : 'end');
|
|
5678
|
-
|
|
6955
|
+
// #2788: a confirmed proposal keeps where it came from, so a derived height never reads as one taken off a drawing.
|
|
6956
|
+
const heightProposalSaid = (proposal) => (!proposal ? '' : proposal.how === 'derived' ? `, which the read derived from ${proposal.basis}`
|
|
6957
|
+
: proposal.how === 'measured' ? `, which the read measured on the drawings${proposal.basis ? ` (${proposal.basis})` : ''}`
|
|
6958
|
+
: proposal.basis ? `, read off the drawings (${proposal.basis})` : ', read off the drawings');
|
|
6959
|
+
const heightAnswerText = (answer) => (answer?.how === 'typed' ? `You typed ${answer.typed}` : `Confirmed ${answer?.shownAs || ''}${heightProposalSaid(answer?.proposal)}`);
|
|
5679
6960
|
/*
|
|
5680
6961
|
* #1903: a row about a member ALREADY in the model. The server snapshotted that end when the question was
|
|
5681
6962
|
* asked; the card says what it held THEN (the model can change before the person answers, and the review
|
|
@@ -5733,9 +7014,16 @@
|
|
|
5733
7014
|
const caret = focused ? textCaret(document.activeElement) : null;
|
|
5734
7015
|
const next = rememberCard(entry, paintHeightCard(entry, old.dataset.eventId, old.dataset.eventSequence), old.dataset.eventId, old.dataset.eventSequence);
|
|
5735
7016
|
old.replaceWith(next);
|
|
7017
|
+
keepRowsScroll(next);
|
|
5736
7018
|
if (focused) focusHeightControl(next, focused, caret);
|
|
5737
7019
|
}
|
|
5738
7020
|
|
|
7021
|
+
/** A rebuilt card's list goes back where the person left it: only a shown list can scroll (paintEvents does the same). */
|
|
7022
|
+
function keepRowsScroll(card) {
|
|
7023
|
+
const list = card.querySelector('.ai-chat-height-rows');
|
|
7024
|
+
if (list && typeof list.keptScrollTop === 'number') list.scrollTop = list.keptScrollTop;
|
|
7025
|
+
}
|
|
7026
|
+
|
|
5739
7027
|
/** The caret of a focused text field, or null (a radio or checkbox has none, and reading it can throw). */
|
|
5740
7028
|
function textCaret(control) {
|
|
5741
7029
|
try {
|
|
@@ -5785,6 +7073,128 @@
|
|
|
5785
7073
|
return paintDrawingHistory('height', entry, eventId, sequence);
|
|
5786
7074
|
}
|
|
5787
7075
|
|
|
7076
|
+
/*
|
|
7077
|
+
* #2777: where on the drawings a height question means. FloLess outlined the drawing element the read took the end from
|
|
7078
|
+
* (or, for a member already in the model, the one the model was read from); the picture opens that sheet at the place,
|
|
7079
|
+
* whole sheet a press away. An end FloLess could not place says so, and nothing pretends a whole sheet is the spot.
|
|
7080
|
+
*/
|
|
7081
|
+
/*
|
|
7082
|
+
* One picture at a time: only the answer step shows one, so only the current place's page is held. Moving to another
|
|
7083
|
+
* place lets the last one go; a load the person moved on from keeps nothing. (Review stop signal, operator 2026-10-26:
|
|
7084
|
+
* rebuilt from a many-picture cache whose eviction kept finding new ways to hold or drop bytes.)
|
|
7085
|
+
*/
|
|
7086
|
+
let heightPlacePicture = null;
|
|
7087
|
+
const HEIGHT_PLACE_RETRY_MS = 15000;
|
|
7088
|
+
/** The server's own answer about the place (it changed, its drawing is gone, the link is wrong): shown, not retried. */
|
|
7089
|
+
const HEIGHT_PLACE_FINAL = new Set([400, 404, 409, 413, 415]);
|
|
7090
|
+
const heightPlaceUrl = (entry, row) => `/api/chat/height-questions/${encodeURIComponent(entry.requestId)}/${encodeURIComponent(entry.questionId)}/place?${new URLSearchParams({ memberId: row.memberId, end: String(row.end), digest: row.placeDigest, chatId: entry.chatId || '' })}`;
|
|
7091
|
+
const heightPlaced = (row) => Boolean(row.place && row.placeDigest);
|
|
7092
|
+
const heightUnplacedText = (row) => (row.unplaced ? `Not placed on the drawings: ${row.unplaced}` : 'The read did not say where on the drawings it read this end.');
|
|
7093
|
+
function openHeightPlace(entry, row, opener) {
|
|
7094
|
+
const place = row.place;
|
|
7095
|
+
return openDrawingPlace(place, {
|
|
7096
|
+
title: `${row.label} on ${place.sheet}`, opener, url: heightPlaceUrl(entry, row),
|
|
7097
|
+
note: `FloLess outlined, on page ${place.page} of ${place.sheet}, the drawing element ${place.by === 'model' ? 'this member was read from' : 'the read took this height from'}. It shows where to look, not that the height is right.`,
|
|
7098
|
+
commands: { close: 'shell.chat-height-place-close', view: 'shell.chat-height-place-view' },
|
|
7099
|
+
again: { label: 'Reload the height card', commandId: 'shell.chat-height-place-again', run: () => loadHeightQuestion(entry) },
|
|
7100
|
+
filter: { projectId: chatProjectId(), commandId: 'shell.chat-place-open-filter' },
|
|
7101
|
+
});
|
|
7102
|
+
}
|
|
7103
|
+
/** The picture of the place, fetched once per place the card showed (its digest), shared by every repaint of the card. */
|
|
7104
|
+
function paintHeightPlacePicture(entry, row, frame) {
|
|
7105
|
+
paintPlacePicture({ digest: row.placeDigest, url: heightPlaceUrl(entry, row), place: row.place }, frame);
|
|
7106
|
+
}
|
|
7107
|
+
/**
|
|
7108
|
+
* The answer step's place picture (#2777), for the height card and the setup card alike. One slot: only one answer step
|
|
7109
|
+
* is on screen, so only its picture is held; a place the card no longer shows lets go of the one before.
|
|
7110
|
+
*/
|
|
7111
|
+
function paintPlacePicture({ digest, url, place }, frame) {
|
|
7112
|
+
const paint = (target, record) => {
|
|
7113
|
+
target.dataset.state = record.state;
|
|
7114
|
+
target.setAttribute('aria-busy', String(record.state === 'loading'));
|
|
7115
|
+
target.replaceChildren();
|
|
7116
|
+
if (record.state === 'ready') {
|
|
7117
|
+
const crop = evidenceCrop(place);
|
|
7118
|
+
const image = Object.assign(document.createElement('img'), { src: record.url, alt: '' });
|
|
7119
|
+
Object.assign(image.style, { width: `${(crop.pageW / crop.w) * 100}%`, left: `${(-(crop.x0 - crop.px0) / crop.w) * 100}%`, top: `${(-(crop.y0 - crop.py0) / crop.h) * 100}%` });
|
|
7120
|
+
target.append(image);
|
|
7121
|
+
} else if (record.state === 'error') {
|
|
7122
|
+
target.append(Object.assign(document.createElement('span'), { className: 'ai-chat-height-place-missing', textContent: record.said }));
|
|
7123
|
+
}
|
|
7124
|
+
};
|
|
7125
|
+
const unavailable = 'Preview unavailable just now. Opening the sheet may still work.';
|
|
7126
|
+
let record = heightPlacePicture;
|
|
7127
|
+
const retry = record?.digest === digest && record.state === 'error' && record.retryAt && Date.now() >= record.retryAt;
|
|
7128
|
+
if (!record || record.digest !== digest || retry) {
|
|
7129
|
+
if (record?.url) URL.revokeObjectURL(record.url);
|
|
7130
|
+
record = heightPlacePicture = { digest, state: 'loading', frame: null };
|
|
7131
|
+
const loading = record;
|
|
7132
|
+
const current = () => heightPlacePicture === loading;
|
|
7133
|
+
fetch(url, { credentials: 'same-origin', cache: 'no-store' })
|
|
7134
|
+
.then(async (response) => {
|
|
7135
|
+
if (!current()) return;
|
|
7136
|
+
if (response.ok) {
|
|
7137
|
+
const bytes = await response.blob();
|
|
7138
|
+
if (current()) Object.assign(loading, { url: URL.createObjectURL(bytes), state: 'ready' });
|
|
7139
|
+
return;
|
|
7140
|
+
}
|
|
7141
|
+
const said = await response.json().catch(() => null);
|
|
7142
|
+
Object.assign(loading, { state: 'error' }, HEIGHT_PLACE_FINAL.has(response.status)
|
|
7143
|
+
? { said: typeof said?.error === 'string' && said.error ? said.error : 'FloLess could not show this place on the drawings.' }
|
|
7144
|
+
: { said: unavailable, retryAt: Date.now() + HEIGHT_PLACE_RETRY_MS });
|
|
7145
|
+
})
|
|
7146
|
+
.catch((error) => {
|
|
7147
|
+
console.warn('[chat] the picture of a question\'s place on the drawings could not be loaded', error);
|
|
7148
|
+
if (current()) Object.assign(loading, { state: 'error', said: unavailable, retryAt: Date.now() + HEIGHT_PLACE_RETRY_MS });
|
|
7149
|
+
})
|
|
7150
|
+
.finally(() => { if (current() && loading.frame?.isConnected) paint(loading.frame, loading); loading.frame = null; });
|
|
7151
|
+
}
|
|
7152
|
+
// Only the frame painted last waits for the picture: an earlier paint's frame is no longer on screen.
|
|
7153
|
+
if (record.state === 'loading') record.frame = frame;
|
|
7154
|
+
paint(frame, record);
|
|
7155
|
+
}
|
|
7156
|
+
/** The answer step's picture: the cropped sheet with the place outlined, one button that opens it; or why there is none. */
|
|
7157
|
+
function heightPlaceFigure(entry, row) {
|
|
7158
|
+
if (!heightPlaced(row)) return Object.assign(document.createElement('p'), { className: 'ai-chat-filter-note ai-chat-ask-context ai-chat-height-unplaced', textContent: heightUnplacedText(row) });
|
|
7159
|
+
const open = button('', `shell.chat-height-open-place#${entry.questionId} ${row.memberId} ${row.endWord}`, 'ai-chat-height-place');
|
|
7160
|
+
open.dataset.commandInstanceLabel = `${row.label} on ${row.place.sheet}`;
|
|
7161
|
+
open.setAttribute('aria-label', `Open sheet ${row.place.sheet} at ${row.label}`);
|
|
7162
|
+
open.dataset.tip = `Opens sheet ${row.place.sheet} with this place outlined`;
|
|
7163
|
+
const crop = evidenceCrop(row.place);
|
|
7164
|
+
const frame = document.createElement('span'); frame.className = 'ai-chat-height-place-frame';
|
|
7165
|
+
// Shaped like the crop, never taller than a short picture: narrowed, not squashed, so the drawing stays true.
|
|
7166
|
+
frame.style.aspectRatio = `${crop.w} / ${crop.h}`;
|
|
7167
|
+
frame.style.width = `min(100%, calc(110px * ${crop.w / crop.h}))`;
|
|
7168
|
+
const caption = document.createElement('span'); caption.className = 'ai-chat-height-place-caption';
|
|
7169
|
+
caption.append(Object.assign(document.createElement('strong'), { textContent: 'Open on sheet' }),
|
|
7170
|
+
Object.assign(document.createElement('span'), { className: 'ai-chat-readiness-place-sheet', textContent: `${row.place.sheet} · page ${row.place.page}` }),
|
|
7171
|
+
Object.assign(document.createElement('span'), { textContent: row.place.by === 'model' ? 'FloLess outlined where this member was read' : 'FloLess outlined where the read took this height' }));
|
|
7172
|
+
open.append(frame, caption);
|
|
7173
|
+
open.addEventListener('click', () => openHeightPlace(entry, row, open));
|
|
7174
|
+
paintHeightPlacePicture(entry, row, frame);
|
|
7175
|
+
return open;
|
|
7176
|
+
}
|
|
7177
|
+
/** A row's sheet, as a small button in the card's list: the same place, no picture, so a long list stays short. */
|
|
7178
|
+
function heightPlaceChip(entry, row) {
|
|
7179
|
+
if (!heightPlaced(row)) return null;
|
|
7180
|
+
const chip = button(row.place.sheet, `shell.chat-height-row-place#${entry.questionId} ${row.memberId} ${row.endWord}`, 'ai-chat-height-sheet');
|
|
7181
|
+
chip.dataset.commandInstanceLabel = `${row.label} on ${row.place.sheet}`;
|
|
7182
|
+
chip.setAttribute('aria-label', `Open sheet ${row.place.sheet} at ${row.label}`);
|
|
7183
|
+
chip.dataset.tip = `Opens sheet ${row.place.sheet} with this place outlined`;
|
|
7184
|
+
chip.addEventListener('click', () => openHeightPlace(entry, row, chip));
|
|
7185
|
+
return chip;
|
|
7186
|
+
}
|
|
7187
|
+
/** #2774: where a proposed height came from, in the option's own words. A derived one is an assumption and says how. */
|
|
7188
|
+
function heightProposalWords(proposed) {
|
|
7189
|
+
// #2802: an elevation printed on the sheet and measured from a datum shows the conversion, so the person confirms it.
|
|
7190
|
+
const datum = proposed.datum ? ` (${proposed.asRead} on ${proposed.datum.name} = ${proposed.datum.asDrawn}, world ${proposed.datum.worldZMm} mm, is ${proposed.value} mm)` : '';
|
|
7191
|
+
if (proposed.how === 'derived') return { description: `Derived, an assumption: ${proposed.basis}${datum}`, tag: 'DERIVED' };
|
|
7192
|
+
if (proposed.how === 'measured') return { description: `Measured on the drawings${proposed.basis ? `: ${proposed.basis}` : ''}${datum}`, tag: 'MEASURED' };
|
|
7193
|
+
if (proposed.how === 'read') return { description: `Read off the drawings${proposed.basis ? `: ${proposed.basis}` : ''}${datum}` };
|
|
7194
|
+
return { description: `Use the value proposed for this member end${datum}` };
|
|
7195
|
+
}
|
|
7196
|
+
const heightNoProposalText = (row) => (row.noProposal ? `No height proposed: ${row.noProposal}` : 'The read proposed no height and gave no reason.');
|
|
7197
|
+
|
|
5788
7198
|
function paintHeightRow(entry, row, open) {
|
|
5789
7199
|
const key = heightEndKey(row);
|
|
5790
7200
|
const item = document.createElement('li'); item.className = 'ai-chat-height-row';
|
|
@@ -5796,6 +7206,8 @@
|
|
|
5796
7206
|
const label = document.createElement('div'); label.className = 'ai-chat-height-label'; label.textContent = row.label;
|
|
5797
7207
|
label.dataset.tip = row.label;
|
|
5798
7208
|
labelLine.append(label);
|
|
7209
|
+
const chip = heightPlaceChip(entry, row);
|
|
7210
|
+
if (chip) labelLine.append(chip);
|
|
5799
7211
|
const meta = document.createElement('div'); meta.className = 'ai-chat-height-meta';
|
|
5800
7212
|
// #1903: an existing member's PROFILE comes from the model, not from the read's label, so a label that
|
|
5801
7213
|
// names the wrong member is visibly at odds with what the id really is.
|
|
@@ -5852,6 +7264,8 @@
|
|
|
5852
7264
|
*/
|
|
5853
7265
|
async function submitHeightAnswers(entry, answers, rowKey, sharedScope) {
|
|
5854
7266
|
if (entry.busy) return false;
|
|
7267
|
+
// The messages there are as the person answers on the card, in its own chat (see drawingMessagesSeen).
|
|
7268
|
+
const seenAtAnswer = drawingEntryCurrent(entry) ? drawingMessageIds() : null;
|
|
5855
7269
|
const ownedSlot = drawingEntryCurrent(entry) && ui.approvalTray?.querySelector('.ai-chat-drawing-step')?.dataset.drawingStep;
|
|
5856
7270
|
const ownedNode = ownedSlot ? ui.approvalTray.querySelector('.ai-chat-drawing-step') : null;
|
|
5857
7271
|
const pendingFocusId = ownedNode?.contains(document.activeElement) ? document.activeElement.dataset.commandId : null;
|
|
@@ -5871,7 +7285,8 @@
|
|
|
5871
7285
|
...[entry.view, result.question].flatMap((view) => (view?.ends || []).flatMap((row) => [...row.answer?.evidence || [], ...row.inherited || []])).map((ref) => ref.attachmentId),
|
|
5872
7286
|
]);
|
|
5873
7287
|
entry.view = result.question;
|
|
5874
|
-
|
|
7288
|
+
// Answering on the card means the person is on it: a message sent while its save kept failing does not fold it now.
|
|
7289
|
+
saved = true; entry.saveFailed = false; if (seenAtAnswer) drawingMessagesSeen(entry.chatId, seenAtAnswer);
|
|
5875
7290
|
for (const answer of answers) {
|
|
5876
7291
|
const key = heightEndKey(answer);
|
|
5877
7292
|
entry.changing.delete(key); entry.drafts.delete(key); entry.selected.delete(key);
|
|
@@ -5905,6 +7320,8 @@
|
|
|
5905
7320
|
} catch (error) {
|
|
5906
7321
|
let message = heightErrorText(error, 'FloLess could not save this height. Try again.');
|
|
5907
7322
|
if (error?.code === 'answer-evidence-unknown') message = dropStaleAnswerFiles([...new Set(answers.map(scopeOf))], entry);
|
|
7323
|
+
// A failed save, apart from the card's other notices: the hidden line says so and the card never hides by itself.
|
|
7324
|
+
entry.saveFailed = true;
|
|
5908
7325
|
// Dropped, not kept: a reload that fails must show its own error and Try again, which only an
|
|
5909
7326
|
// empty card does — an old view would hide both behind rows that are out of date.
|
|
5910
7327
|
if (HEIGHT_STALE.has(error?.code)) { entry.cardError = message; entry.view = null; loadHeightQuestion(entry); }
|
|
@@ -6343,9 +7760,116 @@
|
|
|
6343
7760
|
function drawingSlotRepaint() {
|
|
6344
7761
|
paintDrawingQuestionSlot();
|
|
6345
7762
|
}
|
|
7763
|
+
/*
|
|
7764
|
+
* Owner, 2026-10-23: "if card stays and I answer into the main chat, this card doesn't disappear. And it just taking half
|
|
7765
|
+
* of the screen." The question slot HIDES to one line above the message box: by hand (× or Esc on the card), and by itself
|
|
7766
|
+
* once the person sends a message after the card was posted or last shown. Every waiting drawing card hides together, so
|
|
7767
|
+
* hiding one never brings up the next; a card posted later arrives open. Nothing is dropped: drafts and answers stay, the
|
|
7768
|
+
* line says what still waits for the person, Show (or Answer / Change on the transcript card) brings it back, and a card
|
|
7769
|
+
* whose last answer did not save never hides by itself. A reload forgets a hide by hand; one after a message holds.
|
|
7770
|
+
* The workspace units question shares the slot and hides by hand only ("Any card should have that functionality").
|
|
7771
|
+
*/
|
|
7772
|
+
const drawingHidden = new Map();
|
|
7773
|
+
let drawingHiddenLine = null;
|
|
7774
|
+
function lastEventSequence() { return Math.max(0, ...state.events.map((event) => Number(event.sequence) || 0)); }
|
|
7775
|
+
function messageId(event) { return event.clientSubmissionId || event.eventId; }
|
|
7776
|
+
function drawingMessageIds() { return new Set(state.events.filter((event) => event.type === 'user-message').map(messageId)); }
|
|
7777
|
+
function drawingCardHidden(entry) {
|
|
7778
|
+
const hidden = drawingHidden.get(entry.chatId) || { at: 0, byHand: false, shown: null };
|
|
7779
|
+
if (entry.key.startsWith('units/')) return hidden.byHand;
|
|
7780
|
+
if (hidden.at && entry.sequence <= hidden.at) return true;
|
|
7781
|
+
if (entry.saveFailed) return false;
|
|
7782
|
+
// Moved on the moment they send, while a follow-up still waits for the AI (E2E: an AI held on an approval kept one
|
|
7783
|
+
// "Sending to AI"); only a message FloLess says was not sent brings the card back.
|
|
7784
|
+
return state.events.some((event) => Number(event.sequence) > entry.sequence && event.type === 'user-message' && !event.payload?.source
|
|
7785
|
+
&& !hidden.shown?.has(messageId(event))
|
|
7786
|
+
&& !((event.payload?.followup || event.payload?.deliveryState) && followupDelivery(event) === 'not-sent'));
|
|
7787
|
+
}
|
|
7788
|
+
/**
|
|
7789
|
+
* Messages put behind the card, by identity. A sequence would not hold: a message sent a moment before carries a
|
|
7790
|
+
* stand-in sequence until the server confirms it with a higher one (Codex review). Show puts every message so far
|
|
7791
|
+
* behind it and clears a hide by hand; an answer adds the messages there were when it was given, in its own chat, and
|
|
7792
|
+
* keeps a hide by hand (Codex review round 2: taken when the save ENDED, a message sent meanwhile, or another chat's
|
|
7793
|
+
* messages after a switch, counted as seen).
|
|
7794
|
+
*/
|
|
7795
|
+
function drawingMessagesSeen(chatId, ids, keep = true) {
|
|
7796
|
+
const current = keep ? drawingHidden.get(chatId) : null;
|
|
7797
|
+
drawingHidden.set(chatId, { at: current?.at || 0, byHand: Boolean(current?.byHand), shown: new Set([...(current?.shown || []), ...ids]) });
|
|
7798
|
+
}
|
|
7799
|
+
function showDrawingSlot(chatId) { drawingMessagesSeen(chatId, drawingMessageIds(), false); }
|
|
7800
|
+
function hideDrawingByHand(chatId) {
|
|
7801
|
+
drawingHidden.set(chatId, { at: lastEventSequence(), byHand: true, shown: null });
|
|
7802
|
+
// Removed first, so the line knows the person hid it and can take the focus the card had.
|
|
7803
|
+
ui.approvalTray?.querySelector('.ai-chat-drawing-step')?.remove();
|
|
7804
|
+
paintDrawingQuestionSlot();
|
|
7805
|
+
drawingHiddenLine?.focus({ preventScroll: true });
|
|
7806
|
+
}
|
|
7807
|
+
function showDrawingByHand(chatId) {
|
|
7808
|
+
showDrawingSlot(chatId);
|
|
7809
|
+
// The Enter or Space that pressed Show must not also choose an answer on the card it opens.
|
|
7810
|
+
for (const entry of [...setupCards.values(), ...heightCards.values(), ...(state.workspaceUnitsQuestions?.values() || [])]) {
|
|
7811
|
+
if (entry.slotNode) delete entry.slotNode.dataset.armedAt;
|
|
7812
|
+
}
|
|
7813
|
+
paintDrawingQuestionSlot();
|
|
7814
|
+
const card = ui.approvalTray?.querySelector('.ai-chat-drawing-step.ai-chat-ask-card');
|
|
7815
|
+
if (card) card.dataset.reshown = 'true'; // no arrival pulse for a card brought back (kept across its repaints)
|
|
7816
|
+
if (card && !(card.lastDrawingField && focusHeightControl(card, card.lastDrawingField, null))) window.FlolessQuestionCard.focusCursor(card);
|
|
7817
|
+
}
|
|
7818
|
+
function paintDrawingHiddenLine(tray, showing, hidden) {
|
|
7819
|
+
const names = { height: 'Heights', setup: 'Read setup', units: 'Units' };
|
|
7820
|
+
const waiting = { height: 0, setup: 0, units: 0 };
|
|
7821
|
+
for (const { kind, entry } of hidden) waiting[kind] += drawingRows(kind, entry).filter((row) => drawingRowOpen(kind, entry, row)).length;
|
|
7822
|
+
const kinds = [...new Set(hidden.map(({ kind }) => kind))], reads = kinds.filter((kind) => kind !== 'units');
|
|
7823
|
+
const asked = reads.filter((kind) => waiting[kind]);
|
|
7824
|
+
const count = (n, kind) => (kind === 'setup' ? `${n} ${n === 1 ? 'question still needs' : 'questions still need'}` : `${n} ${n === 1 ? 'end still needs' : 'ends still need'}`);
|
|
7825
|
+
const sentence = [
|
|
7826
|
+
hidden.some(({ entry }) => entry.saveFailed) ? 'Your last answer did not save.' : '',
|
|
7827
|
+
!reads.length ? '' : !asked.length ? 'Answers recorded. Tell the read what to look at next.'
|
|
7828
|
+
: reads.length === 1 ? `${count(waiting[asked[0]], asked[0])} your answer.`
|
|
7829
|
+
: `${asked.map((kind) => `${names[kind]} (${waiting[kind]})`).join(' and ')} still ${asked.length === 1 && waiting[asked[0]] === 1 ? 'needs' : 'need'} your answer.`,
|
|
7830
|
+
kinds.includes('units') ? 'Choose the units AI uses here.' : '',
|
|
7831
|
+
hidden.some(({ entry }) => [...(entry.slotDrafts?.values() || [])].some((draft) => draft.rows[0].other.trim())) ? 'Your typing is kept.' : '',
|
|
7832
|
+
].filter(Boolean).join(' ');
|
|
7833
|
+
const { entry } = hidden[0], key = `hidden/${entry.chatId}`;
|
|
7834
|
+
if (showing && showing.dataset.drawingStep !== key) showing.remove();
|
|
7835
|
+
drawingHiddenLine = paintHiddenLine(drawingHiddenLine, tray, {
|
|
7836
|
+
className: 'ai-chat-drawing-step', label: kinds.length === 1 ? names[kinds[0]] : 'The read', sentence,
|
|
7837
|
+
commandId: reads.length ? `shell.chat-drawing-show#${entry.questionId}` : 'shell.chat-card-show#units',
|
|
7838
|
+
instance: `the ${kinds.map((kind) => names[kind].toLowerCase()).join(' and ')} question${kinds.length > 1 ? 's' : ''}`,
|
|
7839
|
+
show: () => showDrawingByHand(entry.chatId),
|
|
7840
|
+
});
|
|
7841
|
+
drawingHiddenLine.dataset.drawingStep = key;
|
|
7842
|
+
return true;
|
|
7843
|
+
}
|
|
7844
|
+
/**
|
|
7845
|
+
* The one line a hidden card leaves above the message box (or, with no tray, in the conversation, where paintEvents
|
|
7846
|
+
* places it): what still waits, and Show. One button, so it is one tab stop and one Instructor carrier. Above the message
|
|
7847
|
+
* box it is rebuilt only when what it says changes, so a repaint keeps the focus on it; in the conversation the feed is
|
|
7848
|
+
* rebuilt on every paint, the same button is reused, and paintEvents puts the focus back on it.
|
|
7849
|
+
*/
|
|
7850
|
+
function paintHiddenLine(node, tray, { className, label, sentence, commandId, instance, show, tip = '' }) {
|
|
7851
|
+
node ||= document.createElement('button');
|
|
7852
|
+
const sig = JSON.stringify([className, label, sentence, commandId, tip]);
|
|
7853
|
+
// A double click is one expand: its second click would land on the card's own chevron where the line was (#2678).
|
|
7854
|
+
node.onclick = (click) => { if (!(click?.detail > 1)) show(); };
|
|
7855
|
+
if (node.isConnected && node.dataset.sig === sig) return node;
|
|
7856
|
+
node.type = 'button'; node.className = `ai-chat-hidden-line ${className}`; node.dataset.sig = sig;
|
|
7857
|
+
node.dataset.commandId = commandId; node.dataset.commandInstanceLabel = instance;
|
|
7858
|
+
if (tip) node.dataset.tip = tip; else delete node.dataset.tip;
|
|
7859
|
+
node.setAttribute('aria-expanded', 'false');
|
|
7860
|
+
const chip = document.createElement('span'); chip.className = 'ai-chat-ask-chip'; chip.textContent = label;
|
|
7861
|
+
const text = document.createElement('span'); text.className = 'ai-chat-hidden-line-text'; text.textContent = sentence;
|
|
7862
|
+
// Owner, 2026-10-24: an icon, not the word Show: the chevron of a fold that is closed (the same glyph as the receipt fold).
|
|
7863
|
+
const more = document.createElement('span'); more.className = 'ai-chat-hidden-line-toggle'; more.textContent = '›';
|
|
7864
|
+
more.setAttribute('aria-hidden', 'true');
|
|
7865
|
+
node.replaceChildren(chip, text, more);
|
|
7866
|
+
if (!node.isConnected && tray) tray.append(node);
|
|
7867
|
+
return node;
|
|
7868
|
+
}
|
|
6346
7869
|
function reopenDrawingItem(kind, entry, key) {
|
|
6347
7870
|
const row = drawingRows(kind, entry).find((row) => drawingRowKey(kind, row) === key);
|
|
6348
7871
|
if (entry.busy || !entry.view?.open || !row || row.frozen || row.status === 'superseded') return;
|
|
7872
|
+
showDrawingSlot(entry.chatId);
|
|
6349
7873
|
entry.changing.add(key); entry.activeItem = key; entry.finishActive = false; entry.reopenedAt = (state.drawingActivationOrder = (state.drawingActivationOrder || 0) + 1);
|
|
6350
7874
|
if (row.answer?.note && row.answer.how !== 'none') { const source = answerSource(`${kind === 'setup' ? 's' : 'h'}:${entry.questionId}:${key}`); source.open = true; source.note ||= row.answer.note; }
|
|
6351
7875
|
entry.slotPhase = 'row';
|
|
@@ -6366,6 +7890,9 @@
|
|
|
6366
7890
|
const allAnswered = live.length > 0 && answered.length === live.length;
|
|
6367
7891
|
card.dataset.state = !entry.view ? (entry.finished ? 'closed' : 'loading') : !entry.view.open ? 'closed'
|
|
6368
7892
|
: allAnswered ? (settled === live.length ? 'answered' : 'waiting-for-read') : 'open';
|
|
7893
|
+
// #2678: a hidden card's line says what still waits: the person's answers, or the read.
|
|
7894
|
+
const waits = { open: 'you', 'waiting-for-read': 'ai', answered: 'done', closed: 'done' }[card.dataset.state];
|
|
7895
|
+
if (waits) card.dataset.waits = waits;
|
|
6369
7896
|
const head = document.createElement('div'); head.className = 'ai-chat-filter-card-head';
|
|
6370
7897
|
const heading = document.createElement('strong'); heading.textContent = title;
|
|
6371
7898
|
const chip = document.createElement('span'); chip.className = 'ai-chat-filter-state'; chip.textContent = card.dataset.state;
|
|
@@ -6387,6 +7914,10 @@
|
|
|
6387
7914
|
? 'Only you can answer these heights. For a new member, what you confirm or type goes straight into the model; for one already in the model, it is proposed in the review.'
|
|
6388
7915
|
: 'Only you can answer these heights. What you confirm or type goes straight into the model.';
|
|
6389
7916
|
card.append(note);
|
|
7917
|
+
// #2774: the person asked for a height on every end; any end without one says why, and the card counts them.
|
|
7918
|
+
const bare = entry.view.proposeAll ? live.filter((row) => !row.proposed && !row.answer).length : 0;
|
|
7919
|
+
if (bare) card.append(Object.assign(document.createElement('p'), { className: 'ai-chat-filter-note ai-chat-height-unproposed',
|
|
7920
|
+
textContent: `You asked for a height on every end. The read could not propose ${bare === 1 ? 'one end' : `${bare} ends`}; each says why.` }));
|
|
6390
7921
|
}
|
|
6391
7922
|
if (entry.view.open && allAnswered) {
|
|
6392
7923
|
const next = heightActionButton('Tell / send to the read', `shell.chat-${kind}-next-step#${entry.questionId}`, `${kind === 'setup' ? 'setup' : 'height'} question ${entry.view.n}`, 'ai-chat-height-change', entry.busy ? 'An answer is still being saved — wait for it to finish' : null);
|
|
@@ -6394,11 +7925,19 @@
|
|
|
6394
7925
|
next.addEventListener('click', () => {
|
|
6395
7926
|
if (entry.busy) return;
|
|
6396
7927
|
for (const other of [...setupCards.values(), ...heightCards.values()]) other.finishActive = false;
|
|
7928
|
+
showDrawingSlot(entry.chatId);
|
|
6397
7929
|
entry.finishActive = true; entry.reopenedAt = (state.drawingActivationOrder = (state.drawingActivationOrder || 0) + 1); drawingSlotRepaint();
|
|
6398
7930
|
});
|
|
6399
7931
|
card.append(next);
|
|
6400
7932
|
}
|
|
6401
7933
|
const list = document.createElement('ol'); list.className = 'ai-chat-height-rows';
|
|
7934
|
+
// Every repaint builds a new list (Answer, Back, a saved answer, a feed repaint of a changed card), and a new list
|
|
7935
|
+
// starts at its top. The list carries where the person left it, and keepRowsScroll or paintEvents puts it back once
|
|
7936
|
+
// it is in the page (owner, 2026-10-25: Answer on row 21 of 48 jumped to row 1). A hidden list (AI Chat collapsed)
|
|
7937
|
+
// reads 0 and forgets its place, so only a shown list records it, and it goes back there when it shows again.
|
|
7938
|
+
list.addEventListener('scroll', () => { if (list.clientHeight) entry.rowsScroll = list.scrollTop; }, { passive: true });
|
|
7939
|
+
list.keptScrollTop = entry.rowsScroll || 0;
|
|
7940
|
+
if (typeof ResizeObserver === 'function') new ResizeObserver(() => { if (list.clientHeight) list.scrollTop = entry.rowsScroll || 0; }).observe(list);
|
|
6402
7941
|
for (const row of rows) {
|
|
6403
7942
|
const key = drawingRowKey(kind, row);
|
|
6404
7943
|
let item;
|
|
@@ -6410,6 +7949,9 @@
|
|
|
6410
7949
|
} else {
|
|
6411
7950
|
item = document.createElement('li'); item.className = 'ai-chat-height-row'; item.dataset.status = row.status; item.dataset.key = key;
|
|
6412
7951
|
const label = document.createElement('span'); label.textContent = row.label || (row.kind === 'origin' ? 'Model origin' : viewName(row)); item.append(label);
|
|
7952
|
+
const firstPlace = kind === 'setup' && row.kind === 'level' ? setupPlaceItems(row)[0] : null;
|
|
7953
|
+
const chip = kind === 'height' ? heightPlaceChip(entry, row) : firstPlace ? setupPlaceChip(entry, row, firstPlace) : null;
|
|
7954
|
+
if (chip) item.append(chip);
|
|
6413
7955
|
if (entry.view.open) {
|
|
6414
7956
|
const answer = heightActionButton('Answer', `shell.chat-${kind}-change#${entry.questionId} ${key}`, label.textContent, 'ai-chat-height-change', null);
|
|
6415
7957
|
answer.addEventListener('click', () => reopenDrawingItem(kind, entry, key)); item.append(answer);
|
|
@@ -6431,12 +7973,31 @@
|
|
|
6431
7973
|
label, instance: label, idFor, inherited: row?.inherited, busyReason: entry.busy ? 'An answer is still being saved — wait for it to finish' : null,
|
|
6432
7974
|
allowPictureOnly: false, onDraftChange, alwaysOpen: Boolean(entry.slotDrafts?.get(entry.slotQuestionKey)?.rows[0]?.otherOpen) });
|
|
6433
7975
|
}
|
|
7976
|
+
/**
|
|
7977
|
+
* The card's last step ("Tell the read what to look at next") has nothing left to do once a message saying so went to
|
|
7978
|
+
* the read after the card's last answer (owner, 2026-10-23: the card stayed while the AI was already working on it).
|
|
7979
|
+
* Only a message that was sent counts: an ordinary one, or a follow-up the chat accepted or queued. Changing an answer
|
|
7980
|
+
* after that brings the step back, since the read has not been told about the change. The message must name THIS card
|
|
7981
|
+
* ("the second read setup card"), so telling one card never ends another's step.
|
|
7982
|
+
* ponytail: matched on the card's current wording; a later card renames "the read setup card" to "the first …",
|
|
7983
|
+
* which brings the step back on the earlier card. Harmless: it only offers the message again.
|
|
7984
|
+
*/
|
|
7985
|
+
function drawingFinishTold(kind, entry, live) {
|
|
7986
|
+
const told = (kind === 'setup' ? setupTellText(entry) : heightTellText(entry)).replace(/\.$/, '');
|
|
7987
|
+
const lastAnswer = Math.max(0, ...live.map((row) => Date.parse(row.answer?.answeredAt || '') || 0));
|
|
7988
|
+
return state.events.some((event) => event.type === 'user-message' && !event.payload?.source
|
|
7989
|
+
&& (Date.parse(event.createdAt || '') || 0) > lastAnswer
|
|
7990
|
+
&& (!(event.payload?.followup || event.payload?.deliveryState) || ['accepted', 'queued-next'].includes(followupDelivery(event)))
|
|
7991
|
+
&& String(event.payload?.text || '').includes(told));
|
|
7992
|
+
}
|
|
7993
|
+
|
|
6434
7994
|
function drawingStep(kind, entry) {
|
|
6435
7995
|
const open = drawingRows(kind, entry).filter((row) => drawingRowOpen(kind, entry, row));
|
|
6436
7996
|
const row = open.find((row) => drawingRowKey(kind, row) === entry.activeItem) || open[0];
|
|
6437
7997
|
if (!row) {
|
|
6438
7998
|
const live = drawingRows(kind, entry).filter((row) => row.status !== 'superseded');
|
|
6439
7999
|
if (!entry.view?.open || !live.length || !live.every((row) => row.answer)) return null;
|
|
8000
|
+
if (drawingFinishTold(kind, entry, live)) return null;
|
|
6440
8001
|
return { key: 'finish', question: { id: 'finish', header: kind === 'setup' ? 'Read setup' : 'Heights', question: 'Your answers are recorded. Tell the read what to look at next.', allowOther: false,
|
|
6441
8002
|
hint: 'Tell the read puts a message in the box. Send to the read sends it now.',
|
|
6442
8003
|
options: [{ shown: 'Tell the read', description: 'Put the message in the box so you can add to it' }, { shown: 'Send to the read', description: 'Send it now, keeping your words and files' }] },
|
|
@@ -6457,7 +8018,9 @@
|
|
|
6457
8018
|
);
|
|
6458
8019
|
}
|
|
6459
8020
|
else q.context.push(`${row.memberId} · ${heightEndWord(row)}. Only you can answer. What you confirm or type goes straight into the model.`);
|
|
6460
|
-
if (row.proposed) { q.options.push({ shown: `Confirm ${row.proposed.asRead}`,
|
|
8021
|
+
if (row.proposed) { q.options.push({ shown: `Confirm ${row.proposed.asRead}`, ...heightProposalWords(row.proposed) }); choices.push({ memberId: row.memberId, end: row.end, action: 'confirm', shown: row.proposed.value }); q.recommended = 0; }
|
|
8022
|
+
else q.context.push(heightNoProposalText(row));
|
|
8023
|
+
q.figure = () => heightPlaceFigure(entry, row);
|
|
6461
8024
|
if (row.fromEvidence) q.context.push(row.inherited?.length ? 'The read’s reading of your picture. Check it before you confirm.' : 'The read’s reading of your note. Check it before you confirm.');
|
|
6462
8025
|
} else if (row.kind === 'origin') {
|
|
6463
8026
|
q.question = 'Which grid crossing is the model’s origin (0, 0)?'; q.layout = 'grid'; q.confirmSelection = true;
|
|
@@ -6468,6 +8031,9 @@
|
|
|
6468
8031
|
} else {
|
|
6469
8032
|
if (row.clue) q.context.push(row.clue);
|
|
6470
8033
|
if (row.noSingleLevel) q.context.push(`No single level on the drawings: ${row.noSingleLevel.why}`);
|
|
8034
|
+
// Options follow row.proposals in order, so the selected option's index names its proposal.
|
|
8035
|
+
// A choice past the proposals ("No single level") has no place of its own, so it gets no picture.
|
|
8036
|
+
if (row.kind === 'level') q.figure = (choice) => setupPlaceFigure(entry, row, Number.isInteger(choice) ? (row.proposals[choice] ?? SETUP_NO_PROPOSAL) : null);
|
|
6471
8037
|
row.proposals.forEach((proposal) => { q.options.push({ shown: row.kind === 'scale' ? `${proposal.pageFit ? 'Use for this plan' : 'Confirm'}: ${proposal.standard} · ${proposal.mmPerPx} mm per drawing point` : `Confirm ${proposal.asRead}`,
|
|
6472
8038
|
description: row.kind === 'scale' ? proposal.evidence : levelEvidence(proposal), tag: (row.kind === 'scale' ? scaleTag : levelTag)[proposal.source] || 'PROPOSED' }); choices.push({ key, action: 'confirm', choice: proposal.id, shown: row.kind === 'scale' ? proposal.mmPerPx : proposal.value }); });
|
|
6473
8039
|
}
|
|
@@ -6478,7 +8044,7 @@
|
|
|
6478
8044
|
const previous = live.slice(0, live.indexOf(row)).filter((item) => !item.frozen).at(-1);
|
|
6479
8045
|
const backToMode = kind === 'height' && !previous && open.length > 1;
|
|
6480
8046
|
return { key, question: q, scope, row, label, actions: choices, backToMode,
|
|
6481
|
-
back: previous ? () => reopenDrawingItem(kind, entry, drawingRowKey(kind, previous)) : backToMode ? () => { entry.slotPhase = null; entry.activeItem = null; entry.slotSig = null; drawingSlotRepaint(); } : null,
|
|
8047
|
+
back: previous ? () => reopenDrawingItem(kind, entry, drawingRowKey(kind, previous)) : backToMode ? () => { entry.slotPhase = null; entry.activeItem = null; entry.slotSig = null; engageDrawingEntry(entry); drawingSlotRepaint(); } : null,
|
|
6482
8048
|
source: (_index, onDraftChange) => drawingSource(kind, entry, scope, label, idFor, row, onDraftChange),
|
|
6483
8049
|
validate: (_step, draft) => {
|
|
6484
8050
|
const answer = draft.rows[0]; if (answer.choices.length) return '';
|
|
@@ -6508,9 +8074,9 @@
|
|
|
6508
8074
|
source: confirmable ? (_index, onDraftChange) => drawingSource('height', entry, scope, label, idFor, { inherited }, onDraftChange) : null,
|
|
6509
8075
|
question: { ...base, question: 'How would you like to answer these heights?', options, recommended: confirmable ? 0 : null,
|
|
6510
8076
|
hint: confirmable ? 'Confirm all saves these values. The other choices only choose how to answer.' : 'Choose how to answer; no heights are saved yet.',
|
|
6511
|
-
context: [...rows.map((row) => `${row.label} · ${row.inModel?.profile ? `${row.inModel.profile} · ` : ''}${row.memberId} · ${heightEndWord(row)}.${row.proposed ? ` Proposed: ${row.proposed.asRead} (${row.proposed.value} mm).` : ''} ${row.inModel ? `${heightInModelText(row.inModel, entry.view.units)} ${HEIGHT_PROPOSED_TEXT}` : 'What you confirm or type goes straight into the model.'}${row.fromEvidence ? ` The read’s reading of your ${row.inherited?.length ? 'picture' : 'note'}. Check it before you confirm.` : ''}`), ...(confirmable ? [`Optional source for all ${rows.length} heights. Each end keeps its own proposed value.`] : [])] }, commit: async (answer) => {
|
|
8077
|
+
context: [...rows.map((row) => `${row.label} · ${row.inModel?.profile ? `${row.inModel.profile} · ` : ''}${row.memberId} · ${heightEndWord(row)}.${heightPlaced(row) ? ` On ${row.place.sheet}.` : ''}${row.proposed ? ` Proposed: ${row.proposed.asRead} (${row.proposed.value} mm)${row.proposed.how === 'derived' ? `, derived, an assumption: ${row.proposed.basis}` : ''}.` : ` ${heightNoProposalText(row).replace(/[^.!?]$/, '$&.')}`} ${row.inModel ? `${heightInModelText(row.inModel, entry.view.units)} ${HEIGHT_PROPOSED_TEXT}` : 'What you confirm or type goes straight into the model.'}${row.fromEvidence ? ` The read’s reading of your ${row.inherited?.length ? 'picture' : 'note'}. Check it before you confirm.` : ''}`), ...(confirmable ? [`Optional source for all ${rows.length} heights. Each end keeps its own proposed value.`] : [])] }, commit: async (answer) => {
|
|
6512
8078
|
if (confirmable && answer.choices[0] === 0) return submitHeightAnswers(entry, rows.map((row) => ({ memberId: row.memberId, end: row.end, action: 'confirm', shown: row.proposed.value })), null, hasAnswerSource(scope) ? scope : null);
|
|
6513
|
-
entry.slotPhase = answer.choices[0] === options.length - 1 ? 'row' : 'select'; return true;
|
|
8079
|
+
entry.slotPhase = answer.choices[0] === options.length - 1 ? 'row' : 'select'; engageDrawingEntry(entry); return true;
|
|
6514
8080
|
} };
|
|
6515
8081
|
}
|
|
6516
8082
|
if (entry.slotPhase === 'select') {
|
|
@@ -6520,7 +8086,7 @@
|
|
|
6520
8086
|
return { key: 'batch-select', rows: ordered, question: { ...base, allowClear: true, hint: 'Select ends, then Submit. No heights are saved yet.', question: 'Which member ends should share one answer?', multiSelect: true, options: ordered.map((row) => ({ shown: row.label, group: row.group, description: `${row.memberId} · ${heightEndWord(row)}` })) },
|
|
6521
8087
|
initial: ordered.map((row, index) => entry.selected.size ? entry.selected.has(heightEndKey(row)) ? index : -1 : index).filter((index) => index >= 0),
|
|
6522
8088
|
back: () => { entry.slotPhase = null; entry.slotSig = null; drawingSlotRepaint(); },
|
|
6523
|
-
commit: async (answer) => { entry.selected = new Set(answer.choices.map((index) => heightEndKey(ordered[index]))); entry.slotPhase = 'value'; return true; } };
|
|
8089
|
+
commit: async (answer) => { entry.selected = new Set(answer.choices.map((index) => heightEndKey(ordered[index]))); entry.slotPhase = 'value'; engageDrawingEntry(entry); return true; } };
|
|
6524
8090
|
}
|
|
6525
8091
|
const chosen = rows.filter((row) => entry.selected.has(heightEndKey(row)));
|
|
6526
8092
|
if (!chosen.length) { entry.slotPhase = 'select'; return drawingHeightBatch(entry, rows); }
|
|
@@ -6538,23 +8104,38 @@
|
|
|
6538
8104
|
if (saved) { entry.slotPhase = null; entry.slotDrafts?.delete('batch-value'); entry.slotDrafts?.delete('batch-select'); }
|
|
6539
8105
|
return saved; } };
|
|
6540
8106
|
}
|
|
8107
|
+
/*
|
|
8108
|
+
* #2793: the card the person last acted in keeps the tray, until they act in another. Going Back to a card's own
|
|
8109
|
+
* "How would you like to answer…" step is acting in it: without this, the tray fell back to the OLDEST open card.
|
|
8110
|
+
*/
|
|
8111
|
+
function engageDrawingEntry(entry) {
|
|
8112
|
+
// Another card's "Tell the read" step was shown because the person last acted there; acting here moves on from it.
|
|
8113
|
+
for (const other of [...setupCards.values(), ...heightCards.values()]) if (other !== entry) other.finishActive = false;
|
|
8114
|
+
entry.engaged = true; entry.reopenedAt = (state.drawingActivationOrder = (state.drawingActivationOrder || 0) + 1);
|
|
8115
|
+
}
|
|
8116
|
+
const drawingEntryHeld = (entry) => Boolean(entry.finishActive || entry.engaged || entry.changing.has(entry.activeItem));
|
|
6541
8117
|
function paintDrawingQuestionSlot() {
|
|
6542
8118
|
const tray = ui.approvalTray; if (!tray || !window.FlolessQuestionCard) return false;
|
|
6543
8119
|
const showing = tray.querySelector('.ai-chat-drawing-step');
|
|
6544
8120
|
const heldFocus = showing?.contains(document.activeElement) ? document.activeElement : null;
|
|
6545
|
-
|
|
8121
|
+
// A hidden approval or AI question still holds the slot (Codex review round 3): its line is not an .ai-chat-approval.
|
|
8122
|
+
if (state.chat?.pendingApproval || tray.querySelector('.ai-chat-approval:not(.ai-chat-approval-scope):not(.ai-chat-drawing-step), .ai-chat-approval-hidden')) { showing?.remove(); return false; }
|
|
6546
8123
|
const entries = [...setupCards.values()].map((entry) => ({ kind: 'setup', entry })).concat([...heightCards.values()].map((entry) => ({ kind: 'height', entry })))
|
|
6547
8124
|
.filter(({ entry }) => drawingEntryCurrent(entry) && entry.view?.open && !entry.reloadPending && !entry.loading)
|
|
6548
|
-
.sort((a, b) => ((b.entry
|
|
6549
|
-
|
|
6550
|
-
const
|
|
6551
|
-
const
|
|
6552
|
-
|
|
8125
|
+
.sort((a, b) => (drawingEntryHeld(b.entry) ? b.entry.reopenedAt || 0 : 0) - (drawingEntryHeld(a.entry) ? a.entry.reopenedAt || 0 : 0) || a.entry.sequence - b.entry.sequence);
|
|
8126
|
+
const waiting = entries.map(({ kind, entry }) => ({ kind, entry, step: drawingStep(kind, entry) })).filter(({ step }) => step);
|
|
8127
|
+
const hidden = waiting.filter(({ entry }) => drawingCardHidden(entry));
|
|
8128
|
+
const candidates = waiting.filter((candidate) => !hidden.includes(candidate));
|
|
8129
|
+
const units = drawingUnitsCandidate(); if (units) (drawingCardHidden(units.entry) ? hidden : candidates).push(units);
|
|
8130
|
+
// A card's "Tell the read" step wins only while that card is the one the person acted in last (#2793): candidates
|
|
8131
|
+
// are sorted newest action first, so a finish step further down was left behind when they moved to another card.
|
|
8132
|
+
let chosen = candidates.find(({ entry, step }, index) => entry.finishActive && step.key === 'finish' && index === 0) || candidates.find(({ step }) => step.key !== 'finish') || candidates[0];
|
|
6553
8133
|
if (heldFocus && personIsTyping()) {
|
|
6554
8134
|
const current = candidates.find(({ entry, step }) => `${entry.chatId}/${entry.key}/${step.key}` === showing.dataset.drawingStep);
|
|
6555
8135
|
const activated = chosen?.entry.finishActive || (chosen?.entry.reopenedAt || 0) > (current?.entry.reopenedAt || 0);
|
|
6556
8136
|
if (current && !activated) chosen = current;
|
|
6557
8137
|
}
|
|
8138
|
+
if (!chosen && hidden.length) return paintDrawingHiddenLine(tray, showing, hidden);
|
|
6558
8139
|
if (!chosen) { showing?.remove(); return false; }
|
|
6559
8140
|
const { kind, entry, step } = chosen, key = `${entry.chatId}/${entry.key}/${step.key}`;
|
|
6560
8141
|
if (showing && showing.dataset.drawingStep !== key) showing.remove();
|
|
@@ -6594,6 +8175,9 @@
|
|
|
6594
8175
|
removeFile: (file) => request(`/api/chat/answer-evidence/${encodeURIComponent(entry.requestId)}/${encodeURIComponent(file.attachmentId)}`, { method: 'DELETE', body: JSON.stringify({ chatId: entry.chatId }) }) }, files),
|
|
6595
8176
|
remove: (_index, file) => removeAnswerFile(step.scope, { requestId: entry.requestId, chatId: entry.chatId, repaint: drawingSlotRepaint }, file) } : null,
|
|
6596
8177
|
carrier: (what, _index, extra) => drawingCarrier(kind, entry, step, draft, what, extra),
|
|
8178
|
+
hide: { run: () => hideDrawingByHand(entry.chatId), ...(kind === 'units'
|
|
8179
|
+
? { carrier: { id: 'shell.chat-card-hide#units', instance: 'the units question' }, tip: 'Collapse for now. Nothing is chosen for you.' }
|
|
8180
|
+
: { carrier: { id: `shell.chat-drawing-hide#${entry.questionId}`, instance: kind === 'setup' ? 'the read setup' : `height question ${entry.view.n}` } }) },
|
|
6597
8181
|
repaint: () => { entry.slotSig = null; drawingSlotRepaint(); }, commitStep: async (_index, answer) => { const saved = await step.commit(answer); entry.slotSig = null; return saved; },
|
|
6598
8182
|
});
|
|
6599
8183
|
entry.slotSig = sig;
|
|
@@ -6662,6 +8246,98 @@
|
|
|
6662
8246
|
return entry;
|
|
6663
8247
|
}
|
|
6664
8248
|
|
|
8249
|
+
|
|
8250
|
+
/*
|
|
8251
|
+
* #2777 slice B: a level on the setup card shows where the read took it from. Each proposal carries the places of the
|
|
8252
|
+
* readings it stands for (`places`: `{ place, digest }` FloLess resolved, or `{ unplaced }` with the reason); a place with
|
|
8253
|
+
* no `region` is a whole sheet (a level read from the picture of a sheet, not from its text). The answer step shows the
|
|
8254
|
+
* first place as a picture labelled with its level, and every other place as a chip labelled with its level and sheet,
|
|
8255
|
+
* so no picture ever stands unlabelled for a choice it is not.
|
|
8256
|
+
*/
|
|
8257
|
+
/** The answer step's "No single level" (or any choice that is not a proposal): it has no place to show. */
|
|
8258
|
+
const SETUP_NO_PROPOSAL = Object.freeze({ none: true });
|
|
8259
|
+
const setupPlaceUrl = (entry, row, item) => `/api/chat/setup-questions/${encodeURIComponent(entry.requestId)}/${encodeURIComponent(entry.questionId)}/place?${new URLSearchParams({
|
|
8260
|
+
key: row.key, proposal: item.proposal.id, ix: String(item.ix), digest: item.digest, chatId: entry.chatId || '' })}`;
|
|
8261
|
+
function setupPlaceItems(row, only) {
|
|
8262
|
+
const items = [];
|
|
8263
|
+
for (const proposal of row.proposals || []) {
|
|
8264
|
+
if (only && proposal !== only) continue;
|
|
8265
|
+
(Array.isArray(proposal.places) ? proposal.places : []).forEach((entry, ix) => {
|
|
8266
|
+
if (entry && entry.place && entry.digest) items.push({ proposal, ix, place: entry.place, digest: entry.digest });
|
|
8267
|
+
});
|
|
8268
|
+
}
|
|
8269
|
+
return items;
|
|
8270
|
+
}
|
|
8271
|
+
const setupUnplaced = (row) => (row.proposals || []).flatMap((proposal) => (proposal.places || []).filter((entry) => entry && entry.unplaced)
|
|
8272
|
+
.map((entry) => `${proposal.asRead}: ${entry.unplaced}`));
|
|
8273
|
+
const setupPlaceInstance = (item) => `${item.proposal.asRead} on ${item.place.sheet}`;
|
|
8274
|
+
function openSetupPlace(entry, row, item, opener) {
|
|
8275
|
+
const marked = Array.isArray(item.place.region);
|
|
8276
|
+
return openDrawingPlace(item.place, {
|
|
8277
|
+
title: `Level ${item.proposal.asRead} on ${item.place.sheet}`, opener, url: setupPlaceUrl(entry, row, item),
|
|
8278
|
+
note: marked ? `FloLess outlined, on page ${item.place.page} of ${item.place.sheet}, the text the read took this level from. It shows where to look, not that the level is right.`
|
|
8279
|
+
: `The read took this level from its picture of ${item.place.sheet}, not from text on it, so no area is marked. Check the sheet yourself.`,
|
|
8280
|
+
commands: { close: 'shell.chat-setup-place-close', view: 'shell.chat-setup-place-view' },
|
|
8281
|
+
again: { label: 'Reload the setup card', commandId: 'shell.chat-setup-place-again', run: () => loadSetupQuestion(entry) },
|
|
8282
|
+
filter: { projectId: chatProjectId(), commandId: 'shell.chat-place-open-filter' },
|
|
8283
|
+
});
|
|
8284
|
+
}
|
|
8285
|
+
function setupPlaceChip(entry, row, item) {
|
|
8286
|
+
const chip = button(`${item.proposal.asRead} · ${item.place.sheet}`, `shell.chat-setup-row-place#${entry.questionId} ${row.key} ${item.proposal.id} ${item.ix}`, 'ai-chat-height-sheet');
|
|
8287
|
+
chip.dataset.commandInstanceLabel = setupPlaceInstance(item);
|
|
8288
|
+
chip.setAttribute('aria-label', `Open sheet ${item.place.sheet} where the read took level ${item.proposal.asRead}`);
|
|
8289
|
+
chip.dataset.tip = Array.isArray(item.place.region) ? `Opens sheet ${item.place.sheet} with this place outlined` : `Opens sheet ${item.place.sheet}; no area is marked`;
|
|
8290
|
+
chip.addEventListener('click', () => openSetupPlace(entry, row, item, chip));
|
|
8291
|
+
return chip;
|
|
8292
|
+
}
|
|
8293
|
+
/**
|
|
8294
|
+
* The setup answer step's picture for a level row: the selected level's first place (or, with nothing selected, the first
|
|
8295
|
+
* level's), labelled with its level; every other place as a chip labelled with its level and sheet; or why there is none.
|
|
8296
|
+
*/
|
|
8297
|
+
function setupPlaceFigure(entry, row, chosen) {
|
|
8298
|
+
if (chosen === SETUP_NO_PROPOSAL) return null;
|
|
8299
|
+
const all = setupPlaceItems(row);
|
|
8300
|
+
// The selected level with no place of its own says so; it never borrows another level's picture.
|
|
8301
|
+
if (chosen && !all.some((item) => item.proposal === chosen)) {
|
|
8302
|
+
const why = (chosen.places || []).filter((entry) => entry && entry.unplaced).map((entry) => entry.unplaced);
|
|
8303
|
+
return Object.assign(document.createElement('p'), { className: 'ai-chat-filter-note ai-chat-ask-context ai-chat-height-unplaced',
|
|
8304
|
+
textContent: why.length ? `Not placed on the drawings: ${why.join(' ')}` : `The read did not say where on the drawings it took ${chosen.asRead}.` });
|
|
8305
|
+
}
|
|
8306
|
+
const items = chosen ? [...all.filter((item) => item.proposal === chosen), ...all.filter((item) => item.proposal !== chosen)] : all;
|
|
8307
|
+
const unplaced = setupUnplaced(row);
|
|
8308
|
+
if (!items.length) {
|
|
8309
|
+
if (!unplaced.length) return null;
|
|
8310
|
+
return Object.assign(document.createElement('p'), { className: 'ai-chat-filter-note ai-chat-ask-context ai-chat-height-unplaced', textContent: `Not placed on the drawings: ${unplaced.join(' ')}` });
|
|
8311
|
+
}
|
|
8312
|
+
const wrap = document.createElement('div'); wrap.className = 'ai-chat-setup-places';
|
|
8313
|
+
const first = items[0];
|
|
8314
|
+
const marked = Array.isArray(first.place.region);
|
|
8315
|
+
const open = button('', `shell.chat-setup-open-place#${entry.questionId} ${row.key} ${first.proposal.id} ${first.ix}`, 'ai-chat-height-place');
|
|
8316
|
+
open.dataset.commandInstanceLabel = setupPlaceInstance(first);
|
|
8317
|
+
open.setAttribute('aria-label', `Open sheet ${first.place.sheet} where the read took level ${first.proposal.asRead}`);
|
|
8318
|
+
open.dataset.tip = marked ? `Opens sheet ${first.place.sheet} with this place outlined` : `Opens sheet ${first.place.sheet}; no area is marked`;
|
|
8319
|
+
const crop = evidenceCrop(first.place);
|
|
8320
|
+
const frame = document.createElement('span'); frame.className = 'ai-chat-height-place-frame';
|
|
8321
|
+
frame.style.aspectRatio = `${crop.w} / ${crop.h}`;
|
|
8322
|
+
frame.style.width = `min(100%, calc(110px * ${crop.w / crop.h}))`;
|
|
8323
|
+
const caption = document.createElement('span'); caption.className = 'ai-chat-height-place-caption';
|
|
8324
|
+
caption.append(Object.assign(document.createElement('strong'), { textContent: 'Open on sheet' }),
|
|
8325
|
+
Object.assign(document.createElement('span'), { className: 'ai-chat-readiness-place-sheet', textContent: `${first.place.sheet} · page ${first.place.page}` }),
|
|
8326
|
+
Object.assign(document.createElement('span'), { textContent: `${items.length > 1 ? `Place 1 of ${items.length}: ` : ''}where the read took ${first.proposal.asRead}${chosen ? '' : ' (the first choice; pick one to see its place)'}${marked ? '' : ' (no area marked)'}` }));
|
|
8327
|
+
open.append(frame, caption);
|
|
8328
|
+
open.addEventListener('click', () => openSetupPlace(entry, row, first, open));
|
|
8329
|
+
paintPlacePicture({ digest: first.digest, url: setupPlaceUrl(entry, row, first), place: first.place }, frame);
|
|
8330
|
+
wrap.append(open);
|
|
8331
|
+
if (items.length > 1) {
|
|
8332
|
+
const more = document.createElement('div'); more.className = 'ai-chat-setup-place-chips';
|
|
8333
|
+
more.setAttribute('role', 'group'); more.setAttribute('aria-label', 'Other places the read took these levels from');
|
|
8334
|
+
for (const item of items.slice(1)) more.append(setupPlaceChip(entry, row, item));
|
|
8335
|
+
wrap.append(more);
|
|
8336
|
+
}
|
|
8337
|
+
if (unplaced.length) wrap.append(Object.assign(document.createElement('p'), { className: 'ai-chat-filter-note ai-chat-height-unplaced', textContent: `Not placed on the drawings: ${unplaced.join(' ')}` }));
|
|
8338
|
+
return wrap;
|
|
8339
|
+
}
|
|
8340
|
+
|
|
6665
8341
|
function loadSetupQuestion(entry) {
|
|
6666
8342
|
if (entry.loading) return;
|
|
6667
8343
|
entry.loading = true;
|
|
@@ -6681,6 +8357,7 @@
|
|
|
6681
8357
|
const caret = focused ? textCaret(document.activeElement) : null;
|
|
6682
8358
|
const next = rememberCard(entry, paintSetupCard(entry, old.dataset.eventId, old.dataset.eventSequence), old.dataset.eventId, old.dataset.eventSequence);
|
|
6683
8359
|
old.replaceWith(next);
|
|
8360
|
+
keepRowsScroll(next);
|
|
6684
8361
|
if (focused) focusHeightControl(next, focused, caret);
|
|
6685
8362
|
}
|
|
6686
8363
|
|
|
@@ -6697,7 +8374,7 @@
|
|
|
6697
8374
|
|
|
6698
8375
|
const setupSettled = (row) => row.status === 'settled';
|
|
6699
8376
|
const setupLive = (row) => row.status !== 'superseded';
|
|
6700
|
-
const scaleTag = { floless: 'FLOLESS FIT', 'floless-candidate': 'FLOLESS CANDIDATE', read: 'THE READ’S MEASUREMENT', 'read-of-picture': 'THE READ’S READING OF YOUR PICTURE' };
|
|
8377
|
+
const scaleTag = { floless: 'FLOLESS FIT', 'floless-candidate': 'FLOLESS CANDIDATE', 'floless-scale-bar': 'THE SHEET’S SCALE BAR', read: 'THE READ’S MEASUREMENT', 'read-of-picture': 'THE READ’S READING OF YOUR PICTURE' };
|
|
6701
8378
|
const levelTag = { 'drawing-text': 'ON THE DRAWING', 'drawing-picture': 'READ OFF THE PICTURE · NOT CHECKED', 'read-of-picture': 'THE READ’S READING OF YOUR PICTURE' };
|
|
6702
8379
|
const originText = (o) => `${o.xLabel}/${o.yLabel}`;
|
|
6703
8380
|
const viewName = (row) => `${row.view.sheet}${row.view.title ? ` · ${row.view.title}` : ''}`;
|
|
@@ -6763,6 +8440,12 @@
|
|
|
6763
8440
|
const text = document.createElement('span');
|
|
6764
8441
|
text.textContent = row.status === 'needs-new-choices' ? `${setupAnswerText(row)}. Waiting for the read to offer other points.` : setupAnswerText(row);
|
|
6765
8442
|
done.append(glyph, text);
|
|
8443
|
+
// #2777: the place of the level the person confirmed, the same chip the list shows.
|
|
8444
|
+
// By the proposal the person confirmed; an answer recorded before that was kept counts only when its value is unique.
|
|
8445
|
+
const sameValue = row.kind === 'level' && row.answer?.how === 'confirmed' ? (row.proposals || []).filter((proposal) => proposal.value === row.answer.value) : [];
|
|
8446
|
+
const chosen = row.answer?.proposalId ? (row.proposals || []).find((proposal) => proposal.id === row.answer.proposalId) : sameValue.length === 1 ? sameValue[0] : null;
|
|
8447
|
+
const chosenPlace = chosen ? setupPlaceItems(row, chosen)[0] : null;
|
|
8448
|
+
if (chosenPlace) done.append(setupPlaceChip(entry, row, chosenPlace));
|
|
6766
8449
|
if (open && !row.frozen) {
|
|
6767
8450
|
const change = heightActionButton('Change', idFor('change'), instance, 'ai-chat-height-change', entry.busy ? 'An answer is still being saved — wait for it to finish' : null);
|
|
6768
8451
|
change.setAttribute('aria-label', `Change your answer for ${instance}`);
|
|
@@ -6826,6 +8509,7 @@
|
|
|
6826
8509
|
|
|
6827
8510
|
async function submitSetupAnswers(entry, answers, rowKey) {
|
|
6828
8511
|
if (entry.busy) return false;
|
|
8512
|
+
const seenAtAnswer = drawingEntryCurrent(entry) ? drawingMessageIds() : null;
|
|
6829
8513
|
const ownedSlot = drawingEntryCurrent(entry) && ui.approvalTray?.querySelector('.ai-chat-drawing-step')?.dataset.drawingStep;
|
|
6830
8514
|
const ownedNode = ownedSlot ? ui.approvalTray.querySelector('.ai-chat-drawing-step') : null;
|
|
6831
8515
|
const pendingFocusId = ownedNode?.contains(document.activeElement) ? document.activeElement.dataset.commandId : null;
|
|
@@ -6848,7 +8532,7 @@
|
|
|
6848
8532
|
method: 'POST', body: JSON.stringify({ chatId: entry.chatId, answers: withSource }),
|
|
6849
8533
|
});
|
|
6850
8534
|
entry.view = result.question;
|
|
6851
|
-
saved = true;
|
|
8535
|
+
saved = true; entry.saveFailed = false; if (seenAtAnswer) drawingMessagesSeen(entry.chatId, seenAtAnswer);
|
|
6852
8536
|
for (const answer of answers) {
|
|
6853
8537
|
entry.changing.delete(answer.key); entry.drafts.delete(answer.key); entry.drafts.delete(`${answer.key}\u0000none`);
|
|
6854
8538
|
if (entry.activeItem === answer.key) { entry.activeItem = null; entry.reopenedAt = 0; }
|
|
@@ -6860,6 +8544,7 @@
|
|
|
6860
8544
|
let message = heightErrorText(error, 'FloLess could not save this answer. Try again.');
|
|
6861
8545
|
if (error?.code === 'setup-answer-off-grid') message = 'This point isn’t a crossing of two straight grid lines. Choose the matching numbered off-grid option above, check the straight-grid crossing it maps to, then press Confirm.';
|
|
6862
8546
|
if (error?.code === 'answer-evidence-unknown') message = dropStaleAnswerFiles(answers.map((answer) => `s:${entry.questionId}:${answer.key}`), entry);
|
|
8547
|
+
entry.saveFailed = true;
|
|
6863
8548
|
if (SETUP_STALE.has(error?.code)) { entry.cardError = message; entry.view = null; loadSetupQuestion(entry); }
|
|
6864
8549
|
else if (rowKey) entry.rowErrors.set(rowKey, message);
|
|
6865
8550
|
else entry.cardError = message;
|
|
@@ -7367,8 +9052,8 @@
|
|
|
7367
9052
|
|
|
7368
9053
|
function updateOffscreenActivity() {
|
|
7369
9054
|
const liveDots = ui.feed.querySelector('.ai-chat-live-status');
|
|
7370
|
-
//
|
|
7371
|
-
//
|
|
9055
|
+
// The badge sits over the bottom of the feed (chat.css), so showing it never resizes the feed. A feed too short to
|
|
9056
|
+
// hold it over its content does not show it; the higher bar to show than to keep stops it flickering at that size.
|
|
7372
9057
|
const minimumFeedHeight = ui.offscreenActivity.hidden ? 88 : 48;
|
|
7373
9058
|
ui.offscreenActivity.hidden = !turnIsVisiblyActive() || state.historyOpen || !liveDots
|
|
7374
9059
|
|| ui.feed.clientHeight < minimumFeedHeight
|
|
@@ -7396,7 +9081,13 @@
|
|
|
7396
9081
|
? document.activeElement?.dataset?.commandId : null;
|
|
7397
9082
|
// A card painted once and reused across repaints (a connection suggestion, #1900) keeps its own control focused.
|
|
7398
9083
|
const focusedNode = ui.feed.contains(document.activeElement) ? document.activeElement : null;
|
|
7399
|
-
const
|
|
9084
|
+
const chipNode = focusedNode?.closest?.('.ai-chat-source');
|
|
9085
|
+
// #2678: a card in its shell (kept per card) that this repaint rebuilds keeps the keyboard: on the same control, else the card.
|
|
9086
|
+
const focusedShell = focusedNode?.closest?.('.ai-chat-feed-card') || null;
|
|
9087
|
+
const focusedLine = focusedNode?.matches?.('.ai-chat-feed > .ai-chat-feed-hidden') ? String(focusedNode.dataset.commandId || '').replace('shell.chat-feed-card-show#', '') : '';
|
|
9088
|
+
const focusedChip = chipNode ? { turnId: chipNode.dataset.turnId, anchor: chipNode.dataset.anchor, command: focusedNode.dataset?.commandId || '' } : null;
|
|
9089
|
+
if (options.forceBottom) state.feedLeftEnd = false; // the person just sent: the end is where they are going
|
|
9090
|
+
const nearBottom = !state.feedLeftEnd && ui.feed.scrollHeight - ui.feed.scrollTop - ui.feed.clientHeight < 56;
|
|
7400
9091
|
const scrollTop = ui.feed.scrollTop;
|
|
7401
9092
|
// #2163 / #2166: the rebuild below forgets two things only a detach loses: the caret of the field being typed in
|
|
7402
9093
|
// and each card list's scroll position. A card that did not change is the very same node (see `cardSignature`),
|
|
@@ -7428,6 +9119,8 @@
|
|
|
7428
9119
|
};
|
|
7429
9120
|
const flushLinks = () => { if (links.length) { ui.feed.append(...receiptFold(links)); links = []; } };
|
|
7430
9121
|
for (const event of state.events) {
|
|
9122
|
+
// #2642/#2643: the person's assumption or chosen source is painted on its claim's chip; it never starts or ends an answer group (it has no turn).
|
|
9123
|
+
if (event.type === 'citation-assumption' || event.type === 'citation-choice') continue;
|
|
7431
9124
|
// A follow-up can share its provider turn with the preceding answer. Its question still
|
|
7432
9125
|
// starts a new visible answer group, after that answer's text and held receipts (#2505).
|
|
7433
9126
|
if (event.type === 'user-message' || (links.length && event.turnId !== links[0].turnId)) { flushAssistant(); flushLinks(); }
|
|
@@ -7470,14 +9163,14 @@
|
|
|
7470
9163
|
continue;
|
|
7471
9164
|
}
|
|
7472
9165
|
if (event.type === 'connection-proposal-update' || event.type === 'view-command-update') continue;
|
|
7473
|
-
if (event.type === 'connection-proposal' || event.type === 'connection-check') { links.push({ turnId: event.turnId, node: renderEvent(event) }); continue; }
|
|
9166
|
+
if (event.type === 'connection-proposal' || event.type === 'connection-check') { links.push({ turnId: event.turnId, node: feedCard(renderEvent(event), event) }); continue; }
|
|
7474
9167
|
// #2046: the Guide's next-move cards are held under the answer they were suggested in, like the cards above.
|
|
7475
|
-
if (event.type === 'next-move') { const node = renderEvent(event); if (node) links.push({ turnId: event.turnId, node }); continue; }
|
|
9168
|
+
if (event.type === 'next-move') { const node = feedCard(renderEvent(event), event); if (node) links.push({ turnId: event.turnId, node }); continue; }
|
|
7476
9169
|
if (event.type === 'next-move-update') { renderEvent(event); continue; }
|
|
7477
9170
|
// #2247: an action suggestion or an action the AI ran is held under the answer, like the cards above; an update
|
|
7478
9171
|
// only changes its card (which reads it when it repaints).
|
|
7479
9172
|
if (event.type === 'action-proposal-update') continue;
|
|
7480
|
-
if (event.type === 'action-proposal' || event.type === 'action-call') { links.push({ turnId: event.turnId, node: renderEvent(event) }); continue; }
|
|
9173
|
+
if (event.type === 'action-proposal' || event.type === 'action-call') { links.push({ turnId: event.turnId, node: feedCard(renderEvent(event), event) }); continue; }
|
|
7481
9174
|
// #2255: a model view change is written mid-answer while the tool waits, so it is held under the answer too.
|
|
7482
9175
|
if (event.type === 'view-command') { links.push({ turnId: event.turnId, node: renderEvent(event), event }); continue; }
|
|
7483
9176
|
// #2437 / #2436: an answer's sources are held under it, like the receipts below; one row per answer.
|
|
@@ -7486,12 +9179,16 @@
|
|
|
7486
9179
|
if (node) links.push({ turnId: event.turnId, node });
|
|
7487
9180
|
continue;
|
|
7488
9181
|
}
|
|
9182
|
+
// #2777: the places an answer showed on the drawings, held under it like its sources.
|
|
9183
|
+
if (event.type === 'place') { const node = renderPlaceStrip(event); if (node) links.push({ turnId: event.turnId, node }); continue; }
|
|
7489
9184
|
if (['tool', 'usage', 'attachment', 'compaction', 'state'].includes(event.type)) continue;
|
|
7490
9185
|
// FloLess's own receipts (object links #1653; evidence looks and suggestion cards #1859) are written mid-answer while a tool runs:
|
|
7491
9186
|
// held and shown under the answer, so they never cut one answer into fragments.
|
|
7492
|
-
if (event.type === 'chat-subjects' || event.type === 'evidence-read' || event.type === 'filter-proposal') { links.push({ turnId: event.turnId, node: renderEvent(event), event }); continue; }
|
|
9187
|
+
if (event.type === 'chat-subjects' || event.type === 'evidence-read' || event.type === 'filter-proposal') { links.push({ turnId: event.turnId, node: feedCard(renderEvent(event), event), event }); continue; }
|
|
7493
9188
|
flushAssistant();
|
|
7494
|
-
|
|
9189
|
+
// #2678: a card comes in its shell, with its chevron, or as the one line it left (an ordinary message or a one-line row comes
|
|
9190
|
+
// as it is).
|
|
9191
|
+
const node = feedCard(renderEvent(event), event);
|
|
7495
9192
|
if (node) ui.feed.append(node);
|
|
7496
9193
|
}
|
|
7497
9194
|
flushAssistant();
|
|
@@ -7504,27 +9201,56 @@
|
|
|
7504
9201
|
// never looks like a failed response. Recovery deliberately has no live indicator.
|
|
7505
9202
|
if (turnIsVisiblyActive()) ui.feed.append(renderLiveStatus());
|
|
7506
9203
|
}
|
|
9204
|
+
// Lists first, so a card that takes the keyboard below lands on a control the person can see (focusFeedCard).
|
|
9205
|
+
for (const list of ui.feed.querySelectorAll('.ai-chat-height-rows, .ai-chat-readiness-body, .ai-chat-readiness-table')) {
|
|
9206
|
+
if (typeof list.keptScrollTop === 'number' && list.scrollTop !== list.keptScrollTop) list.scrollTop = list.keptScrollTop;
|
|
9207
|
+
if (typeof list.keptScrollLeft === 'number' && list.scrollLeft !== list.keptScrollLeft) list.scrollLeft = list.keptScrollLeft;
|
|
9208
|
+
}
|
|
7507
9209
|
let refocused = null;
|
|
7508
9210
|
if (focusedNode?.isConnected && ui.feed.contains(focusedNode)) {
|
|
7509
9211
|
if (document.activeElement !== focusedNode) focusedNode.focus({ preventScroll: true });
|
|
7510
9212
|
refocused = focusedNode;
|
|
9213
|
+
} else if (focusedChip) {
|
|
9214
|
+
// #2642: a source chip is rebuilt on every repaint; the keyboard stays on the same claim's chip, on the same button
|
|
9215
|
+
// when it is still there (a recorded assumption leaves "Ask for the source", never a jump to the top of the feed).
|
|
9216
|
+
const chip = [...ui.feed.querySelectorAll('.ai-chat-source')].find((node) => node.dataset.turnId === focusedChip.turnId && node.dataset.anchor === focusedChip.anchor);
|
|
9217
|
+
refocused = [...(chip?.querySelectorAll('button') ?? [])].find((control) => control.dataset.commandId === focusedChip.command) ?? chip?.querySelector('button') ?? null;
|
|
9218
|
+
refocused?.focus({ preventScroll: true });
|
|
9219
|
+
} else if (focusedShell?.isConnected && ui.feed.contains(focusedShell) && focusedShell.firstElementChild !== focusedShell.hideButton) {
|
|
9220
|
+
refocused = focusFeedCard(focusedShell.firstElementChild, focusedCommand);
|
|
9221
|
+
} else if (focusedLine && feedCardShells.get(focusedLine)?.isConnected) {
|
|
9222
|
+
// #2678: the line had the keyboard and its card is back (a message that folded it was not sent): the card takes it.
|
|
9223
|
+
refocused = focusFeedCard(feedCardShells.get(focusedLine).firstElementChild);
|
|
9224
|
+
} else if (focusedShell && feedCardLines.get(focusedShell.feedCardId)?.isConnected) {
|
|
9225
|
+
// #2678: the card folded by itself (answered) under the keyboard: the keyboard stays with it, on its line.
|
|
9226
|
+
refocused = feedCardLines.get(focusedShell.feedCardId);
|
|
9227
|
+
refocused.focus({ preventScroll: true });
|
|
7511
9228
|
} else refocused = restoreFeedFocus(focusedCommand);
|
|
9229
|
+
// #2643: an open "Choose a source…" list lives outside the feed, so a repaint keeps it (and what is typed in it); it
|
|
9230
|
+
// follows its claim's rebuilt chip, and closes with its conversation.
|
|
9231
|
+
if (state.sourcePicker) {
|
|
9232
|
+
if (state.sourcePicker.chatId !== state.chat?.chatId) closeSourcePicker(false);
|
|
9233
|
+
else placeSourcePicker(state.sourcePicker);
|
|
9234
|
+
}
|
|
7512
9235
|
if (refocused && caret) {
|
|
7513
9236
|
try { refocused.setSelectionRange(caret.start, caret.end, caret.direction); } catch { /* no caret on this control */ }
|
|
7514
9237
|
}
|
|
7515
|
-
for (const list of ui.feed.querySelectorAll('.ai-chat-height-rows, .ai-chat-readiness-body, .ai-chat-readiness-table')) {
|
|
7516
|
-
if (typeof list.keptScrollTop === 'number' && list.scrollTop !== list.keptScrollTop) list.scrollTop = list.keptScrollTop;
|
|
7517
|
-
if (typeof list.keptScrollLeft === 'number' && list.scrollLeft !== list.keptScrollLeft) list.scrollLeft = list.keptScrollLeft;
|
|
7518
|
-
}
|
|
7519
9238
|
// Removing a focused control makes the browser lay out the half-built feed, which clamps its scroll near the top.
|
|
7520
|
-
// Scrolled up, the reader stays where they were.
|
|
9239
|
+
// Scrolled up, the reader stays where they were. At the end, they are put back there now, before any scroll event
|
|
9240
|
+
// can read that clamp as the reader moving up (keepFeedFollowing); the frame below settles late layout.
|
|
7521
9241
|
if (!nearBottom) ui.feed.scrollTop = scrollTop;
|
|
9242
|
+
else if (!state.answerJump) ui.feed.scrollTop = ui.feed.scrollHeight;
|
|
7522
9243
|
restoreAnswerJump();
|
|
7523
9244
|
updateOffscreenActivity();
|
|
7524
9245
|
if (!state.answerJump && (nearBottom || options.forceBottom)) requestAnimationFrame(() => {
|
|
9246
|
+
if (state.feedLeftEnd || state.answerJump) return; // the reader moved up, or another conversation jumped to an answer
|
|
7525
9247
|
ui.feed.scrollTop = ui.feed.scrollHeight;
|
|
7526
9248
|
// A control that kept keyboard focus across the repaint (the questions card sits above the answer) stays in sight.
|
|
7527
|
-
|
|
9249
|
+
// In a card's own list it is the list that is brought into sight: scrolling to the control would pull a list the
|
|
9250
|
+
// person scrolled away from back to it, under their pointer, on every 5 s poll.
|
|
9251
|
+
if (ui.feed.contains(document.activeElement)) {
|
|
9252
|
+
(document.activeElement.closest('.ai-chat-height-rows') || document.activeElement).scrollIntoView({ block: 'nearest' });
|
|
9253
|
+
}
|
|
7528
9254
|
updateOffscreenActivity();
|
|
7529
9255
|
});
|
|
7530
9256
|
}
|
|
@@ -7611,10 +9337,66 @@
|
|
|
7611
9337
|
return signIn;
|
|
7612
9338
|
}
|
|
7613
9339
|
|
|
9340
|
+
/*
|
|
9341
|
+
* Owner, 2026-10-23: "Any card should have that functionality". An approval, a proposal or the AI's own question above the
|
|
9342
|
+
* message box hides to one line by hand (× or Esc), like a drawing read's card. Hiding answers, allows or denies nothing:
|
|
9343
|
+
* the AI keeps waiting, the chat keeps its "approval needed" mark, and the line says what waits. A reload shows it again.
|
|
9344
|
+
* ponytail: ids of settled approvals stay in the set; harmless, an id is never reused.
|
|
9345
|
+
*/
|
|
9346
|
+
const hiddenApprovals = new Set();
|
|
9347
|
+
let approvalHiddenLine = null;
|
|
9348
|
+
function hideApprovalByHand(approvalId) {
|
|
9349
|
+
hiddenApprovals.add(approvalId);
|
|
9350
|
+
paintApproval();
|
|
9351
|
+
approvalHiddenLine?.focus({ preventScroll: true });
|
|
9352
|
+
}
|
|
9353
|
+
function showApprovalByHand(approvalId) {
|
|
9354
|
+
hiddenApprovals.delete(approvalId);
|
|
9355
|
+
paintApproval();
|
|
9356
|
+
const card = [...ui.approvalTray.querySelectorAll('.ai-chat-approval')].find((node) => node.dataset.approvalId === approvalId);
|
|
9357
|
+
if (card) card.dataset.reshown = 'true'; // its arrival pulse is for a card that is new, not one brought back
|
|
9358
|
+
// A question card puts focus on its recommended answer itself; a decision starts on Deny, the safe default.
|
|
9359
|
+
if (card && !card.contains(document.activeElement)) {
|
|
9360
|
+
(card.querySelector('[data-command-id="shell.chat-approval-deny"]') || card.querySelector('button:not(.ai-chat-card-hide)'))?.focus({ preventScroll: true });
|
|
9361
|
+
}
|
|
9362
|
+
}
|
|
9363
|
+
function paintApprovalHiddenLine(approval, existing) {
|
|
9364
|
+
if (existing && existing !== approvalHiddenLine) existing.remove();
|
|
9365
|
+
const question = approval.kind === 'question' || approval.async;
|
|
9366
|
+
const draft = questionDrafts.get(approval.approvalId)?.draft;
|
|
9367
|
+
const asked = approval.question?.questions?.[draft?.step || 0] || approval.question?.questions?.[0];
|
|
9368
|
+
// An async question is answered by the person's next message, so the line says what it asks (UX review), cut at a word.
|
|
9369
|
+
const words = String(asked?.question || '');
|
|
9370
|
+
const quoted = words.length > 90 ? `${words.slice(0, 90).replace(/\s+\S*$/, '')}…` : words;
|
|
9371
|
+
approvalHiddenLine = paintHiddenLine(approvalHiddenLine, ui.approvalTray, {
|
|
9372
|
+
className: `ai-chat-approval-hidden${question ? '' : ' is-decision'}`, label: question ? asked?.header || 'Question' : 'Approval',
|
|
9373
|
+
sentence: [approval.async ? `The AI asked “${quoted}”${/[.?!…]$/.test(quoted) ? '' : '.'} Your next message answers it.`
|
|
9374
|
+
: question ? 'The AI is waiting for your answer.' : 'The AI is waiting for your decision.',
|
|
9375
|
+
draft?.rows.some((row) => row.choices.length || row.other.trim()) ? 'What you chose or typed is kept.' : ''].filter(Boolean).join(' '),
|
|
9376
|
+
commandId: `shell.chat-card-show#${approval.approvalId}`, instance: question ? 'the AI’s question' : 'the approval',
|
|
9377
|
+
tip: approval.async && quoted !== words ? words : '', show: () => showApprovalByHand(approval.approvalId),
|
|
9378
|
+
});
|
|
9379
|
+
}
|
|
9380
|
+
/** The × on an approval or proposal card, and Esc anywhere inside it. */
|
|
9381
|
+
function approvalHideControl(card, approval) {
|
|
9382
|
+
const hide = button('›', `shell.chat-card-hide#${approval.approvalId}`, 'ai-chat-card-hide');
|
|
9383
|
+
hide.dataset.commandInstanceLabel = 'the approval';
|
|
9384
|
+
hide.setAttribute('aria-label', 'Collapse this approval for now');
|
|
9385
|
+
hide.dataset.tip = 'Collapse for now. The AI keeps waiting for your decision.';
|
|
9386
|
+
hide.addEventListener('click', () => hideApprovalByHand(approval.approvalId));
|
|
9387
|
+
card.addEventListener('keydown', (event) => {
|
|
9388
|
+
if (!window.FlolessQuestionCard?.escapeHides(event)) return;
|
|
9389
|
+
event.preventDefault(); event.stopPropagation(); hideApprovalByHand(approval.approvalId);
|
|
9390
|
+
});
|
|
9391
|
+
card.append(hide);
|
|
9392
|
+
}
|
|
9393
|
+
|
|
7614
9394
|
function paintApproval() {
|
|
7615
9395
|
clearSettledQuestionDrafts(state.events, state.chat);
|
|
7616
9396
|
paintApprovalScope();
|
|
7617
|
-
|
|
9397
|
+
// A hidden drawing question's one line holds the slot like its card does, so an approval or question replaces it too.
|
|
9398
|
+
// Only the tray's own line: a card hidden in the conversation leaves one too (#2678), and it is not this slot's.
|
|
9399
|
+
const existing = shell.querySelector('.ai-chat-approval:not(.ai-chat-approval-scope), .ai-chat-approval-tray > .ai-chat-hidden-line');
|
|
7618
9400
|
const approval = state.chat?.pendingApproval;
|
|
7619
9401
|
const deciding = Boolean(approval && state.decidingApprovalIds.has(approval.approvalId));
|
|
7620
9402
|
shell.dataset.approvalPending = String(Boolean(approval) && !deciding);
|
|
@@ -7623,6 +9405,8 @@
|
|
|
7623
9405
|
const asking = approval ? null : openAsyncQuestion(state.events, state.chat);
|
|
7624
9406
|
if (asking) shell.dataset.approvalPending = 'true';
|
|
7625
9407
|
document.dispatchEvent(new CustomEvent('floless:chat-indicator'));
|
|
9408
|
+
const waiting = asking || (approval && !deciding ? approval : null);
|
|
9409
|
+
if (waiting && hiddenApprovals.has(waiting.approvalId)) { paintApprovalHiddenLine(waiting, existing); return; }
|
|
7626
9410
|
if (asking && window.FlolessQuestionCard) {
|
|
7627
9411
|
if (existing?.dataset.approvalId === asking.approvalId && existing.classList.contains('ai-chat-ask-card')) return;
|
|
7628
9412
|
existing?.remove();
|
|
@@ -7666,6 +9450,7 @@
|
|
|
7666
9450
|
card.classList.add('has-flo'); card.append(flo);
|
|
7667
9451
|
floAvatar(flo, { size: 28, mood: 'yourcall', hat: true });
|
|
7668
9452
|
}
|
|
9453
|
+
approvalHideControl(card, approval);
|
|
7669
9454
|
card.dataset.allowanceRevision = allowanceRevision;
|
|
7670
9455
|
// #1890 PR 3a: the AI asking to create a workflow, with where it would go.
|
|
7671
9456
|
const create = approval.create && typeof approval.create === 'object' ? approval.create : null;
|
|
@@ -7689,7 +9474,7 @@
|
|
|
7689
9474
|
const allow = button(scope.allowsFileChanges ? readOnly ? 'Add scope for later file changes' : 'Add scope and allow file changes' : 'Approve once', 'shell.chat-scope-add-approve', 'allow');
|
|
7690
9475
|
deny.addEventListener('click', () => decideApproval('deny'));
|
|
7691
9476
|
allow.addEventListener('click', () => decideApproval('allow'));
|
|
7692
|
-
actions.append(deny, allow); card.append(heading, copy, actions, ...widerChoices(approval, offer));
|
|
9477
|
+
actions.append(deny, allow); card.append(heading, copy, actions, ...widerChoices(approval, offer, actions));
|
|
7693
9478
|
ui.approvalTray.append(card);
|
|
7694
9479
|
if (refocus) [...card.querySelectorAll('button')].find((node) => node.dataset.commandId === refocus)?.focus();
|
|
7695
9480
|
ui.approvalTray.scrollTop = ui.approvalTray.scrollHeight;
|
|
@@ -7760,7 +9545,7 @@
|
|
|
7760
9545
|
block.append(code);
|
|
7761
9546
|
nodes.push(block);
|
|
7762
9547
|
}
|
|
7763
|
-
card.append(...nodes, actions, ...widerChoices(approval, offer));
|
|
9548
|
+
card.append(...nodes, actions, ...widerChoices(approval, offer, actions));
|
|
7764
9549
|
ui.approvalTray.append(card);
|
|
7765
9550
|
if (refocus) [...card.querySelectorAll('button')].find((node) => node.dataset.commandId === refocus)?.focus();
|
|
7766
9551
|
// When a request-wide grant notice is also present, keep the decision nearest the composer.
|
|
@@ -7855,6 +9640,8 @@
|
|
|
7855
9640
|
files: approval.async ? null : questionFiles(approval),
|
|
7856
9641
|
...(approval.async ? { otherHint: 'Type your own answer, or write it in the message box below to attach a file' } : {}),
|
|
7857
9642
|
repaint: () => paintQuestionCard(approval, card),
|
|
9643
|
+
hide: { run: () => hideApprovalByHand(approval.approvalId), carrier: { id: `shell.chat-card-hide#${approval.approvalId}`, instance: 'the AI’s question' },
|
|
9644
|
+
tip: approval.async ? 'Collapse for now. Your typing is kept.' : 'Collapse for now. The AI keeps waiting, and your typing is kept.' },
|
|
7858
9645
|
submit: () => { void (approval.async ? submitAsyncQuestion(approval) : submitQuestion(approval)); },
|
|
7859
9646
|
});
|
|
7860
9647
|
const target = refocus ? [...card.querySelectorAll('[data-command-id]')].find((node) => node.dataset.commandId === refocus) : null;
|
|
@@ -8121,7 +9908,7 @@
|
|
|
8121
9908
|
}
|
|
8122
9909
|
// Deny and Approve once already answer through paintApproval's own listeners.
|
|
8123
9910
|
actions.append(deny, allow);
|
|
8124
|
-
const nodes = [heading, copy, ...extra, actions, ...widerChoices(approval, offer)];
|
|
9911
|
+
const nodes = [heading, copy, ...extra, actions, ...widerChoices(approval, offer, actions)];
|
|
8125
9912
|
card.append(...nodes);
|
|
8126
9913
|
}
|
|
8127
9914
|
|
|
@@ -8186,7 +9973,7 @@
|
|
|
8186
9973
|
deny.addEventListener('click', () => decideApproval('deny'));
|
|
8187
9974
|
allow.addEventListener('click', () => decideApproval('allow'));
|
|
8188
9975
|
actions.append(deny, allow);
|
|
8189
|
-
card.append(heading, copy, ...(change.owners?.length ? [changeOwnerList(change)] : []), actions, ...widerChoices(approval, offer));
|
|
9976
|
+
card.append(heading, copy, ...(change.owners?.length ? [changeOwnerList(change)] : []), actions, ...widerChoices(approval, offer, actions));
|
|
8190
9977
|
}
|
|
8191
9978
|
|
|
8192
9979
|
/** Why a workflow the AI asked to create can only be dismissed (#1890 PR 3a); the server says the same to the AI. */
|
|
@@ -8258,7 +10045,7 @@
|
|
|
8258
10045
|
deny.addEventListener('click', () => decideApproval('deny'));
|
|
8259
10046
|
allow.addEventListener('click', () => decideApproval('allow'));
|
|
8260
10047
|
actions.append(deny, allow);
|
|
8261
|
-
card.append(heading, copy, list, actions, ...widerChoices(approval, offer));
|
|
10048
|
+
card.append(heading, copy, list, actions, ...widerChoices(approval, offer, actions));
|
|
8262
10049
|
}
|
|
8263
10050
|
|
|
8264
10051
|
/** Each project or workflow the change touches, with up to five of its files. */
|
|
@@ -8388,21 +10175,13 @@
|
|
|
8388
10175
|
}
|
|
8389
10176
|
|
|
8390
10177
|
/**
|
|
8391
|
-
* The two wider choices
|
|
8392
|
-
*
|
|
8393
|
-
*
|
|
10178
|
+
* The two wider choices join the card's one row of buttons, after Deny and Approve once (owner, 2026-10-23: "all button
|
|
10179
|
+
* should be inlined, move the text explanation to tooltip"). What each one covers is its themed tooltip, and a hidden
|
|
10180
|
+
* line the button is described by reads it to screen readers. Returns what still needs a line of its own: the warning
|
|
10181
|
+
* that a choice covers more than this one call.
|
|
8394
10182
|
*/
|
|
8395
|
-
function widerChoices(approval, offer) {
|
|
10183
|
+
function widerChoices(approval, offer, actions) {
|
|
8396
10184
|
if (!offer) return [];
|
|
8397
|
-
const group = document.createElement('div');
|
|
8398
|
-
group.className = 'ai-chat-approval-wide';
|
|
8399
|
-
group.setAttribute('role', 'group');
|
|
8400
|
-
const caption = document.createElement('span');
|
|
8401
|
-
caption.className = 'ai-chat-approval-wide-caption';
|
|
8402
|
-
caption.id = `chat-approval-wide-caption-${approval.approvalId}`;
|
|
8403
|
-
caption.textContent = 'Or allow more than this one action';
|
|
8404
|
-
group.setAttribute('aria-labelledby', caption.id);
|
|
8405
|
-
group.append(caption);
|
|
8406
10185
|
const rows = [
|
|
8407
10186
|
{ which: 'request', label: 'Approve for this request', decision: 'allow-request', revision: offer.requestRevision, commandId: 'shell.chat-approval-request',
|
|
8408
10187
|
text: `${offer.what}, until this reply ends.` },
|
|
@@ -8410,27 +10189,22 @@
|
|
|
8410
10189
|
text: `${offer.conversationWhat || offer.what}${offer.conversationExtra || ''}, for the rest of this conversation, until you revoke it above the message box.` },
|
|
8411
10190
|
];
|
|
8412
10191
|
for (const row of rows) {
|
|
8413
|
-
const line = document.createElement('div');
|
|
8414
|
-
line.className = 'ai-chat-approval-wide-row';
|
|
8415
10192
|
const choice = button(row.label, row.commandId);
|
|
8416
10193
|
if (offer.instance && row.which === 'conversation') choice.dataset.commandInstanceLabel = offer.instance;
|
|
8417
10194
|
const covers = document.createElement('span');
|
|
8418
|
-
covers.className = 'ai-chat-approval-covers';
|
|
10195
|
+
covers.className = 'ai-chat-approval-covers sr-only';
|
|
8419
10196
|
covers.id = `chat-approval-covers-${row.which}-${approval.approvalId}`;
|
|
8420
10197
|
covers.textContent = `${row.text}${offer.protectedNote || ''}`;
|
|
8421
10198
|
choice.dataset.tip = covers.textContent;
|
|
8422
10199
|
choice.setAttribute('aria-describedby', covers.id);
|
|
8423
10200
|
choice.addEventListener('click', () => decideApproval(row.decision, row.revision));
|
|
8424
|
-
|
|
8425
|
-
group.append(line);
|
|
10201
|
+
actions.append(choice, covers);
|
|
8426
10202
|
}
|
|
8427
|
-
if (offer.warning)
|
|
8428
|
-
|
|
8429
|
-
|
|
8430
|
-
|
|
8431
|
-
|
|
8432
|
-
}
|
|
8433
|
-
return [group];
|
|
10203
|
+
if (!offer.warning) return [];
|
|
10204
|
+
const warning = document.createElement('p');
|
|
10205
|
+
warning.className = 'ai-chat-approval-warning';
|
|
10206
|
+
warning.textContent = offer.warning;
|
|
10207
|
+
return [warning];
|
|
8434
10208
|
}
|
|
8435
10209
|
|
|
8436
10210
|
function approvalIsExplicitOnly(approval) {
|
|
@@ -9311,7 +11085,7 @@
|
|
|
9311
11085
|
ui.permission.querySelector('strong').textContent = instructorChat ? 'No tools' : permissionLabel(chat?.settings.permissionProfile);
|
|
9312
11086
|
ui.permission.dataset.tip = instructorChat
|
|
9313
11087
|
? 'This chat answers an Instructor question, so the AI can’t read files, run commands, search the web or use your connectors. Choose an Access to turn it into an ordinary chat. FloLess asks first.'
|
|
9314
|
-
:
|
|
11088
|
+
: accessTip(chat);
|
|
9315
11089
|
// #2234: the Guide's Access is chosen like any conversation's (it starts Read only). Its own controls — the morning
|
|
9316
11090
|
// briefing, set-aside suggestions, Turn off and Delete history — keep their cell, shown only in a Guide conversation.
|
|
9317
11091
|
const guideChat = chat?.initiator?.kind === 'guide';
|
|
@@ -9325,9 +11099,10 @@
|
|
|
9325
11099
|
: 'Not using one';
|
|
9326
11100
|
const frozen = !chat || Boolean(chat.activeTurn) || !state.capability?.available;
|
|
9327
11101
|
// #2336: Access and the connectors switch do not depend on the provider's model list, so a provider check that failed
|
|
9328
|
-
// or is slow never locks them
|
|
11102
|
+
// or is slow never locks them. Model and effort need the list. #2651: Access can change during a reply too (it applies
|
|
11103
|
+
// from the next message); the connectors switch still waits for the reply.
|
|
9329
11104
|
const settled = !chat || Boolean(chat.activeTurn);
|
|
9330
|
-
ui.model.disabled = frozen; ui.effort.disabled = frozen; ui.permission.disabled =
|
|
11105
|
+
ui.model.disabled = frozen; ui.effort.disabled = frozen; ui.permission.disabled = !chat;
|
|
9331
11106
|
ui.integrations.disabled = frozen || Boolean(chat?.nativeSessionId) || instructorChat;
|
|
9332
11107
|
const integrationBlocked = instructorChat
|
|
9333
11108
|
? 'An Instructor answer uses no tools, so it cannot use a connected account. Start a new chat to use one.'
|
|
@@ -9441,7 +11216,6 @@
|
|
|
9441
11216
|
ui.stop.hidden = !active || Boolean(chat.activeTurn?.local);
|
|
9442
11217
|
ui.send.hidden = false;
|
|
9443
11218
|
paintSettings(); paintRecovery(); paintApproval(); paintRuntime(); paintAttachments(); paintEvents(); paintHistory(); updateSendState();
|
|
9444
|
-
applyPendingSettings();
|
|
9445
11219
|
}
|
|
9446
11220
|
|
|
9447
11221
|
function draftForChat(chat) {
|
|
@@ -9767,6 +11541,7 @@
|
|
|
9767
11541
|
clearLiveStream(true);
|
|
9768
11542
|
state.chat = null; state.events = []; state.capability = null; state.desktop = null;
|
|
9769
11543
|
state.attachments = []; state.followupUnknownId = null; state.integrations = null;
|
|
11544
|
+
state.feedLeftEnd = false; // the feed is rebuilt from nothing: a conversation, re-opened or not, opens at its end
|
|
9770
11545
|
updateOffscreenActivity();
|
|
9771
11546
|
// The header switches to the next conversation now; the previous provider's setup card and composer
|
|
9772
11547
|
// hint must not stay under it while that conversation opens.
|
|
@@ -9923,7 +11698,9 @@
|
|
|
9923
11698
|
}
|
|
9924
11699
|
|
|
9925
11700
|
async function applyProviderDefaults(chatId) {
|
|
9926
|
-
|
|
11701
|
+
// #2651: not while a reply runs: the model and effort change only between replies, and that reply starts the provider
|
|
11702
|
+
// session on its own default anyway.
|
|
11703
|
+
if (!state.chat || state.chat.chatId !== chatId || state.chat.nativeSessionId || state.chat.activeTurn || !state.capability?.available) return;
|
|
9927
11704
|
const defaults = preferredSettings(state.chat.provider, state.capability);
|
|
9928
11705
|
if (!defaults?.model) return;
|
|
9929
11706
|
const patch = {};
|
|
@@ -10374,6 +12151,7 @@
|
|
|
10374
12151
|
+ (connectors
|
|
10375
12152
|
? `If you turn on your ${provider} connectors, it becomes an ordinary chat, and its next replies can use the tools its Access allows as well as your connectors (each call still asks you first).`
|
|
10376
12153
|
: `If you change Access to ${chosen}, it becomes an ordinary chat, and its next replies can use the tools ${chosen} allows.`)
|
|
12154
|
+
+ (state.chat?.activeTurn ? ' The reply that is running now stays on No tools.' : '')
|
|
10377
12155
|
+ ' Earlier answers stay as they were. You can’t switch it back to no tools: ask the Instructor again for that.';
|
|
10378
12156
|
go.textContent = connectors ? 'Turn on connectors' : `Change to ${chosen}`;
|
|
10379
12157
|
const done = (value) => {
|
|
@@ -10409,21 +12187,24 @@
|
|
|
10409
12187
|
// #2059: giving an Instructor answer tools asks first; the server refuses it without this confirmation.
|
|
10410
12188
|
let release = false;
|
|
10411
12189
|
if (widensInstructorAnswer(patch)) {
|
|
10412
|
-
|
|
10413
|
-
if (!options.releaseConfirmed && !await confirmInstructorRelease(patch)) return;
|
|
12190
|
+
if (!await confirmInstructorRelease(patch)) return;
|
|
10414
12191
|
if (!sameChat(snapshot)) return;
|
|
10415
12192
|
// The settings may have moved on while the question was open: apply the choice to what is current now.
|
|
10416
12193
|
snapshot = captureChat();
|
|
10417
12194
|
if (!snapshot) return;
|
|
10418
12195
|
release = true;
|
|
10419
12196
|
}
|
|
10420
|
-
|
|
12197
|
+
// #2651: a pick sends only what it changes; the server keeps the rest as it is NOW. This page's copy may be older: an
|
|
12198
|
+
// Access it carried back could undo a change made meanwhile (in another window, or by the AI's own card), and a model
|
|
12199
|
+
// it carried back would be a model change, which waits for a running reply.
|
|
12200
|
+
const settings = { ...patch };
|
|
10421
12201
|
if ('model' in patch && !('effort' in patch)) settings.effort = null;
|
|
10422
12202
|
// A model the runtime stopped listing (an update renamed it) is saved as the row the picker shows for it, the one
|
|
10423
|
-
// running the same model where there is one (coveringModel), so changing Effort
|
|
12203
|
+
// running the same model where there is one (coveringModel), so changing Effort is never refused.
|
|
10424
12204
|
// Only against a list the provider actually returned: an empty one (the check failed) proves nothing about the model.
|
|
10425
|
-
|
|
10426
|
-
|
|
12205
|
+
const stored = state.chat.settings.model;
|
|
12206
|
+
if ('effort' in patch && !('model' in patch) && stored && state.capability?.available && state.capability.models.length
|
|
12207
|
+
&& !state.capability.models.some((model) => model.id === stored)) {
|
|
10427
12208
|
const shown = selectedModel();
|
|
10428
12209
|
settings.model = shown?.id ?? null;
|
|
10429
12210
|
if (!shown?.efforts?.includes(settings.effort)) settings.effort = null;
|
|
@@ -10435,34 +12216,22 @@
|
|
|
10435
12216
|
if (!sameChat(snapshot)) return;
|
|
10436
12217
|
state.chat = chat;
|
|
10437
12218
|
paintConversation();
|
|
12219
|
+
// #2651: said once, here, never from a repaint. Decided by the saved record: a reply that ended meanwhile has no "next".
|
|
12220
|
+
const accessSaid = 'permissionProfile' in patch
|
|
12221
|
+
? `Access changed to ${permissionLabel(chat.settings.permissionProfile)}.${chat.activeTurn ? ' It applies from your next message.' : ''}` : '';
|
|
10438
12222
|
if (release) {
|
|
10439
12223
|
announce(patch.useOwnConnectors === true && !('permissionProfile' in patch)
|
|
10440
|
-
? 'Connectors on. This is now an ordinary chat.' :
|
|
12224
|
+
? 'Connectors on. This is now an ordinary chat.' : `${accessSaid} This is now an ordinary chat.`);
|
|
10441
12225
|
// The transcript line the server wrote is shown now, not on the next poll.
|
|
10442
12226
|
void refreshConversation(snapshot.chatId, false);
|
|
10443
|
-
} else if (options.announce !== false) announce('Chat settings updated.');
|
|
12227
|
+
} else if (options.announce !== false) announce(accessSaid || 'Chat settings updated.');
|
|
10444
12228
|
} catch (error) {
|
|
10445
12229
|
if (!sameChat(snapshot)) return;
|
|
10446
|
-
//
|
|
10447
|
-
// the level that is really in force, and apply the choice by itself the moment the reply finishes (paintConversation).
|
|
10448
|
-
if (error?.code === 'chat-turn-active') {
|
|
10449
|
-
const earlier = state.pendingSettings?.chatId === snapshot.chatId ? state.pendingSettings : null;
|
|
10450
|
-
state.pendingSettings = { chatId: snapshot.chatId, patch: { ...(earlier?.patch || {}), ...patch }, releaseConfirmed: release || earlier?.releaseConfirmed === true };
|
|
10451
|
-
report(error, '', { 'chat-turn-active': pendingSettingsSentence(patch) });
|
|
10452
|
-
return;
|
|
10453
|
-
}
|
|
12230
|
+
// The control stays on the level that is really in force (state.chat was not replaced); the hint says why.
|
|
10454
12231
|
report(error, 'Could not update settings', settingsSaveMessages(error));
|
|
10455
12232
|
}
|
|
10456
12233
|
}
|
|
10457
12234
|
|
|
10458
|
-
/** #2336: said when a settings choice has to wait for the running reply; it applies by itself afterwards. */
|
|
10459
|
-
function pendingSettingsSentence(patch) {
|
|
10460
|
-
const what = 'permissionProfile' in patch ? `Access to ${permissionLabel(patch.permissionProfile)}`
|
|
10461
|
-
: 'useOwnConnectors' in patch ? (patch.useOwnConnectors === true ? 'your connectors to on' : 'your connectors to off')
|
|
10462
|
-
: 'model' in patch ? 'the model' : 'effort';
|
|
10463
|
-
return `The AI is still replying, so ${what} will change as soon as this reply finishes. Nothing else to do.`;
|
|
10464
|
-
}
|
|
10465
|
-
|
|
10466
12235
|
/** #2336: the sentences for a settings change that could not be stored (the shared sentences say "Stop the response", which is wrong here). */
|
|
10467
12236
|
function settingsSaveMessages(error) {
|
|
10468
12237
|
const code = String(error && error.code || '');
|
|
@@ -10473,16 +12242,6 @@
|
|
|
10473
12242
|
return null;
|
|
10474
12243
|
}
|
|
10475
12244
|
|
|
10476
|
-
/** #2336: applies a choice that waited for a running reply, once that reply is over and only to the chat it was made in. */
|
|
10477
|
-
function applyPendingSettings() {
|
|
10478
|
-
const pending = state.pendingSettings;
|
|
10479
|
-
if (!pending) return;
|
|
10480
|
-
if (state.chat?.chatId !== pending.chatId) { state.pendingSettings = null; return; }
|
|
10481
|
-
if (state.chat.activeTurn || state.chat.archivedAt) return;
|
|
10482
|
-
state.pendingSettings = null;
|
|
10483
|
-
void saveSettings(pending.patch, { releaseConfirmed: pending.releaseConfirmed === true });
|
|
10484
|
-
}
|
|
10485
|
-
|
|
10486
12245
|
function modelChoices() {
|
|
10487
12246
|
const models = state.capability?.models || [];
|
|
10488
12247
|
const shown = selectedModel()?.id;
|
|
@@ -10534,6 +12293,26 @@
|
|
|
10534
12293
|
return `Access: ${label}. ${permissionMeta(value || 'read-only')}`;
|
|
10535
12294
|
}
|
|
10536
12295
|
|
|
12296
|
+
/**
|
|
12297
|
+
* #2651: while a reply runs after the person changed Access, the level the next message uses and the one the reply
|
|
12298
|
+
* keeps (from the record, so a reload, another window and the AI's own change all show it); otherwise null.
|
|
12299
|
+
*/
|
|
12300
|
+
function accessChangedDuringReply(chat) {
|
|
12301
|
+
const turn = chat?.activeTurn;
|
|
12302
|
+
if (!turn || turn.local || (turn.accessRevision ?? 0) === (chat.accessRevision ?? 0)) return null;
|
|
12303
|
+
return {
|
|
12304
|
+
next: isInstructorAnswer(chat) ? 'No tools' : permissionLabel(chat.settings?.permissionProfile),
|
|
12305
|
+
kept: turn.answerOnly ? 'No tools' : turn.permissionProfile ? permissionLabel(turn.permissionProfile) : null,
|
|
12306
|
+
};
|
|
12307
|
+
}
|
|
12308
|
+
|
|
12309
|
+
/** #2651: the Access tooltip of the chip and the settings row; during a reply it says when a change applies. */
|
|
12310
|
+
function accessTip(chat) {
|
|
12311
|
+
const changed = accessChangedDuringReply(chat);
|
|
12312
|
+
if (changed) return `Access: ${changed.next}, from your next message. This reply keeps ${changed.kept || 'the Access it started with'}.`;
|
|
12313
|
+
return `${permissionTip(chat?.settings?.permissionProfile)}${chat?.activeTurn ? ' Changes apply from your next message.' : ''}`;
|
|
12314
|
+
}
|
|
12315
|
+
|
|
10537
12316
|
function permissionChoices() {
|
|
10538
12317
|
// #2234 (owner ruling 2026-10-12): every conversation offers all four levels — the workspace's and the Guide's too.
|
|
10539
12318
|
return Object.keys(permissionLabels).map((value) => ({
|
|
@@ -10601,6 +12380,10 @@
|
|
|
10601
12380
|
|
|
10602
12381
|
function integrationReason(row) {
|
|
10603
12382
|
const code = typeof row?.reasonCode === 'string' ? row.reasonCode : '';
|
|
12383
|
+
// #2649: Google's file access is the Drive checkbox on its card; other services keep the general sentence.
|
|
12384
|
+
if (code === 'scope-missing' && row?.integration === 'google-workspace') {
|
|
12385
|
+
return 'This account was connected without permission to read these files. In Integrations, tick the Drive file list on Google Workspace and click Reconnect.';
|
|
12386
|
+
}
|
|
10604
12387
|
if (Object.hasOwn(INTEGRATION_REASON_COPY, code)) return INTEGRATION_REASON_COPY[code];
|
|
10605
12388
|
const raw = String(row?.reason || '');
|
|
10606
12389
|
if (!raw) return 'This connected account is unavailable.';
|
|
@@ -11025,6 +12808,12 @@
|
|
|
11025
12808
|
if (server.disposition === 'stale') info.note = server.reason || SERVER_PROPOSAL_NOTES.stale;
|
|
11026
12809
|
}
|
|
11027
12810
|
const disposition = info.known ? info.disposition : 'pending';
|
|
12811
|
+
// #2678: an undecided suggestion still waits for the person when its card is hidden (repainted in place, so it is cleared
|
|
12812
|
+
// too). One from an earlier view, or one that suggests no change, offers no buttons, so nothing waits on it.
|
|
12813
|
+
// Applied with nothing left to undo, kept, undone or out of date: settled, so the card folds by itself.
|
|
12814
|
+
if (info.known && disposition === 'pending' && hasChanges) card.dataset.waits = 'you';
|
|
12815
|
+
else if (info.known && (['kept', 'undone', 'stale'].includes(disposition) || (disposition === 'applied' && !info.undo))) card.dataset.waits = 'done';
|
|
12816
|
+
else delete card.dataset.waits;
|
|
11028
12817
|
// An unknown record (reload, another window) claims no outcome, only that it predates this view.
|
|
11029
12818
|
// "not saved" only while this suggestion's own Undo is live: Save and later edits retire it.
|
|
11030
12819
|
const chip = card.querySelector('.ai-chat-filter-state');
|
|
@@ -11555,7 +13344,8 @@
|
|
|
11555
13344
|
if (mentionItems.length) restoreRefusedMentions(chatId, mentionItems);
|
|
11556
13345
|
ui.input.value = text; autosize(); paintAttachments(); saveDraftSoon(); paintConversation();
|
|
11557
13346
|
// #2061: the project is busy — ask (wait / open it / stop it) instead of only saying it failed. Nothing was sent.
|
|
11558
|
-
|
|
13347
|
+
// A provider refusal carries its reason (a check that timed out on a busy computer is not a sign-out).
|
|
13348
|
+
if (!askIfProjectBusy(error, busyMessage)) report(error, 'Message was not sent', { 'chat-provider-unavailable': capabilityMessage(state.chat?.provider, error?.message) });
|
|
11559
13349
|
} finally { if (sameChat(snapshot)) { setBusy(false); updateSendState(); } }
|
|
11560
13350
|
}
|
|
11561
13351
|
|
|
@@ -13009,22 +14799,54 @@
|
|
|
13009
14799
|
}
|
|
13010
14800
|
}
|
|
13011
14801
|
|
|
13012
|
-
|
|
13013
|
-
|
|
13014
|
-
|
|
14802
|
+
/**
|
|
14803
|
+
* The composer's Access chip is a quick switch, like the AI terminals' own: the four levels, each with its one-line
|
|
14804
|
+
* note and a check on the current one. A pick saves through saveSettings, so it takes the same path as the settings
|
|
14805
|
+
* row (an Instructor answer still asks first). What a level means in full stays in this conversation's Scope view.
|
|
14806
|
+
*/
|
|
14807
|
+
function openAccessMenu() {
|
|
14808
|
+
const chip = ui.accessChip, menu = ui.accessMenu;
|
|
14809
|
+
if (!chip || !menu || chip.disabled || !state.chat) return;
|
|
14810
|
+
if (!menu.hidden) { closeAccessMenu(); return; }
|
|
14811
|
+
closePicker(); closeScopePicker();
|
|
14812
|
+
const head = document.createElement('div'); head.className = 'ai-chat-access-menu-head'; head.id = 'chat-access-menu-head';
|
|
14813
|
+
head.textContent = accessMenuHead(state.chat);
|
|
14814
|
+
menu.replaceChildren(head);
|
|
14815
|
+
for (const choice of permissionChoices()) {
|
|
14816
|
+
const value = choice.patch.permissionProfile;
|
|
14817
|
+
const item = button('', `shell.chat-access-choose#${commandInstance(value)}`);
|
|
14818
|
+
item.dataset.commandInstanceLabel = choice.label; item.dataset.value = value;
|
|
14819
|
+
item.setAttribute('role', 'menuitemradio'); item.setAttribute('aria-checked', String(choice.selected));
|
|
14820
|
+
const label = document.createElement('strong'); label.textContent = choice.label;
|
|
14821
|
+
const meta = document.createElement('small'); meta.textContent = choice.meta;
|
|
14822
|
+
item.append(label, meta);
|
|
14823
|
+
item.addEventListener('click', () => {
|
|
14824
|
+
const current = item.getAttribute('aria-checked') === 'true';
|
|
14825
|
+
closeAccessMenu(true);
|
|
14826
|
+
if (!current) void saveSettings(choice.patch);
|
|
14827
|
+
});
|
|
14828
|
+
menu.append(item);
|
|
14829
|
+
}
|
|
14830
|
+
state.accessMenuChatId = state.chat.chatId;
|
|
14831
|
+
menu.hidden = false; chip.setAttribute('aria-expanded', 'true');
|
|
14832
|
+
(menu.querySelector('[aria-checked="true"]') || menu.querySelector('button'))?.focus();
|
|
13015
14833
|
}
|
|
13016
14834
|
|
|
13017
|
-
|
|
13018
|
-
|
|
13019
|
-
|
|
13020
|
-
|
|
14835
|
+
/** #2651: during a reply a pick applies from the next message, and the menu says so before the click. */
|
|
14836
|
+
function accessMenuHead(chat) { return chat?.activeTurn ? 'Access · from your next message' : 'Access · this chat'; }
|
|
14837
|
+
|
|
14838
|
+
function closeAccessMenu(focusChip = false) {
|
|
14839
|
+
if (!ui.accessMenu || ui.accessMenu.hidden) return;
|
|
14840
|
+
ui.accessMenu.hidden = true; ui.accessMenu.replaceChildren();
|
|
14841
|
+
ui.accessChip?.setAttribute('aria-expanded', 'false');
|
|
14842
|
+
if (focusChip) ui.accessChip?.focus();
|
|
13021
14843
|
}
|
|
13022
14844
|
|
|
13023
14845
|
function paintScopeControl() {
|
|
13024
14846
|
if (!ui.scopeControls) return;
|
|
13025
14847
|
const chat = state.chat;
|
|
13026
14848
|
ui.scopeControls.hidden = !chat || Boolean(chat.archivedAt);
|
|
13027
|
-
if (!chat) { closeScopePicker(); return; }
|
|
14849
|
+
if (!chat) { closeScopePicker(); closeAccessMenu(); return; }
|
|
13028
14850
|
if (state.scopeViewChatId !== chat.chatId) { state.scopeView = null; closeScopePicker(); }
|
|
13029
14851
|
if (state.scopeView && state.scopeView.scope.revision !== (chat.scopeRevision ?? 0)) {
|
|
13030
14852
|
state.scopeView = null; closeScopePicker();
|
|
@@ -13045,23 +14867,28 @@
|
|
|
13045
14867
|
ui.scopeToggle.disabled = state.loading;
|
|
13046
14868
|
if (ui.scopeToggle.disabled) ui.scopeToggle.dataset.blockedReason = 'The conversation is still loading.';
|
|
13047
14869
|
else delete ui.scopeToggle.dataset.blockedReason;
|
|
13048
|
-
|
|
13049
|
-
|
|
13050
|
-
: chat.settings?.permissionProfile
|
|
13051
|
-
|
|
13052
|
-
:
|
|
13053
|
-
|
|
13054
|
-
|
|
13055
|
-
|
|
13056
|
-
|
|
13057
|
-
|
|
13058
|
-
ui.
|
|
13059
|
-
|
|
13060
|
-
|
|
13061
|
-
|
|
13062
|
-
ui.
|
|
13063
|
-
|
|
13064
|
-
|
|
14870
|
+
if (ui.accessChip) {
|
|
14871
|
+
const instructor = isInstructorAnswer(chat);
|
|
14872
|
+
const label = instructor ? 'No tools' : permissionLabel(chat.settings?.permissionProfile);
|
|
14873
|
+
ui.accessChip.querySelector('strong').textContent = label;
|
|
14874
|
+
// #2651: Access can change at any time, a reply included: it shows the level the next message uses.
|
|
14875
|
+
const changed = accessChangedDuringReply(chat);
|
|
14876
|
+
ui.accessChip.setAttribute('aria-label', changed ? `Access: ${label} from your next message. Change access` : `Access: ${label}. Change access`);
|
|
14877
|
+
ui.accessChip.disabled = false;
|
|
14878
|
+
delete ui.accessChip.dataset.blockedReason;
|
|
14879
|
+
// One line, like the menu; what the level means in full is in this conversation's Scope view.
|
|
14880
|
+
ui.accessChip.dataset.tip = instructor
|
|
14881
|
+
? 'This chat answers an Instructor question, so the AI can’t read files, run commands, search the web or use your connectors. Choose an Access to turn it into an ordinary chat. FloLess asks first.'
|
|
14882
|
+
: `${accessTip(chat)} Click to change.`;
|
|
14883
|
+
if (state.accessMenuChatId !== chat.chatId) closeAccessMenu();
|
|
14884
|
+
else if (!ui.accessMenu.hidden) {
|
|
14885
|
+
// A repaint moves the check and the head only; the items stay, so focus stays where it is.
|
|
14886
|
+
const head = ui.accessMenu.querySelector('#chat-access-menu-head');
|
|
14887
|
+
if (head && head.textContent !== accessMenuHead(chat)) head.textContent = accessMenuHead(chat);
|
|
14888
|
+
for (const item of ui.accessMenu.querySelectorAll('[role="menuitemradio"]')) {
|
|
14889
|
+
item.setAttribute('aria-checked', String(!isInstructorAnswer(chat) && item.dataset.value === chat.settings?.permissionProfile));
|
|
14890
|
+
}
|
|
14891
|
+
}
|
|
13065
14892
|
}
|
|
13066
14893
|
// Poll/SSE can change permissions or pause a reply while Scope stays open. Refresh only when
|
|
13067
14894
|
// these states change, retaining its selected add choice and focus on an enabled control.
|
|
@@ -13877,12 +15704,29 @@
|
|
|
13877
15704
|
else if (event.key === 'Escape') { ui.skills.hidden = true; closePicker(); }
|
|
13878
15705
|
});
|
|
13879
15706
|
ui.scopeToggle?.addEventListener('click', () => { void openScopePicker(); });
|
|
13880
|
-
ui.
|
|
15707
|
+
ui.accessChip?.addEventListener('click', openAccessMenu);
|
|
15708
|
+
ui.accessChip?.addEventListener('keydown', (event) => {
|
|
15709
|
+
if (event.key === 'Escape' && !ui.accessMenu.hidden) { event.preventDefault(); event.stopPropagation(); closeAccessMenu(true); }
|
|
15710
|
+
});
|
|
15711
|
+
ui.accessMenu?.addEventListener('keydown', (event) => {
|
|
15712
|
+
const items = [...ui.accessMenu.querySelectorAll('button')];
|
|
15713
|
+
const at = items.indexOf(document.activeElement);
|
|
15714
|
+
// Keys the menu uses stop here: Home is also the canvas's fit-to-screen shortcut (web/app.js).
|
|
15715
|
+
if (['Escape', 'ArrowDown', 'ArrowUp', 'Home', 'End'].includes(event.key)) { event.preventDefault(); event.stopPropagation(); }
|
|
15716
|
+
if (event.key === 'Escape') closeAccessMenu(true);
|
|
15717
|
+
else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') items[(at + (event.key === 'ArrowDown' ? 1 : items.length - 1)) % items.length]?.focus();
|
|
15718
|
+
else if (event.key === 'Home' || event.key === 'End') items[event.key === 'Home' ? 0 : items.length - 1]?.focus();
|
|
15719
|
+
});
|
|
15720
|
+
// Focus leaving both the chip and the menu (Tab away) closes it.
|
|
15721
|
+
for (const node of [ui.accessChip, ui.accessMenu]) node?.addEventListener('focusout', (event) => {
|
|
15722
|
+
if (!ui.accessMenu.hidden && !ui.accessChip.contains(event.relatedTarget) && !ui.accessMenu.contains(event.relatedTarget)) closeAccessMenu();
|
|
15723
|
+
});
|
|
13881
15724
|
ui.scopePicker?.addEventListener('keydown', (event) => {
|
|
13882
15725
|
if (event.key === 'Escape') { event.preventDefault(); closeScopePicker(true); }
|
|
13883
15726
|
});
|
|
13884
15727
|
document.addEventListener('pointerdown', (event) => {
|
|
13885
15728
|
if (state.scopePickerOpen && !ui.scopeControls?.contains(event.target)) closeScopePicker();
|
|
15729
|
+
if (ui.accessMenu && !ui.accessMenu.hidden && !ui.accessMenu.contains(event.target) && !ui.accessChip.contains(event.target)) closeAccessMenu();
|
|
13886
15730
|
});
|
|
13887
15731
|
// Capture phase: the control's own handler runs after, so a sentence it reports is held afresh.
|
|
13888
15732
|
shell.addEventListener('click', releaseReportOnControl, true);
|