@floless/app 0.154.0 → 0.155.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/floless-server.cjs +49492 -37984
- package/dist/schemas/steel.model.v2.schema.json +19 -5
- package/dist/skills/floless-app-onboarding/SKILL.md +22 -13
- package/dist/skills/floless-app-onboarding/references/floless-surfaces.md +12 -8
- package/dist/skills/floless-app-steel-model/SKILL.md +23 -2
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +158 -65
- package/dist/skills/floless-app-workflows/SKILL.md +23 -5
- package/dist/skills/floless-app-workflows/references/blender-exec.md +183 -0
- package/dist/skills/floless-app-workflows/references/dev-server-and-run-trace.md +27 -12
- package/dist/templates/blender-construction-sequence.flo +96 -0
- package/dist/web/agents.js +33 -13
- package/dist/web/app.css +275 -33
- package/dist/web/aware.js +745 -82
- package/dist/web/chat-question-card.js +477 -0
- package/dist/web/chat.css +177 -12
- package/dist/web/chat.js +1537 -717
- package/dist/web/commands-shell.js +424 -7
- package/dist/web/commands-steel.js +105 -4
- package/dist/web/guide.js +4 -3
- package/dist/web/index.html +96 -7
- package/dist/web/instructor.js +10 -9
- package/dist/web/left-pane.js +40 -3
- package/dist/web/media-player.js +234 -0
- package/dist/web/model-editor-contract.js +2 -0
- package/dist/web/model-editor-revit-adapter.js +1 -0
- package/dist/web/model-editor-steel-adapter.js +89 -1
- package/dist/web/model-panel-bridge.js +16 -2
- package/dist/web/model-view-query.js +590 -0
- package/dist/web/model-viewport-revit-adapter.js +15 -1
- package/dist/web/model-viewport-toolbar.js +5 -2
- package/dist/web/pages.js +592 -0
- package/dist/web/panels.js +2 -1
- package/dist/web/revit-editor.js +181 -16
- package/dist/web/run-progress.js +193 -0
- package/dist/web/run-strip.js +173 -0
- package/dist/web/steel-3d-core.js +70 -0
- package/dist/web/steel-editor.html +2751 -219
- package/dist/web/steel-frames-core.js +958 -0
- package/dist/web/steel-last-seen.js +315 -0
- package/dist/web/steel-marks-core.js +530 -0
- package/dist/web/steel-model-slim.js +95 -0
- package/dist/web/steel-model-v2-client-validation.js +14 -2
- package/dist/web/steel-model-v2-commands.js +258 -27
- package/dist/web/steel-model-v2-projection.js +78 -18
- package/dist/web/steel-read-confidence.js +11 -2
- package/dist/web/workspaces.js +416 -26
- package/package.json +3 -2
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'), scopeDisclosure: el('chat-scope-disclosure'),
|
|
36
|
+
scopePicker: el('chat-scope-picker'), scopeDisclosure: el('chat-scope-disclosure'), accessExplanation: el('chat-access-explanation'),
|
|
37
37
|
checkAllowance: el('chat-check-allowance'),
|
|
38
38
|
grants: el('chat-grants'),
|
|
39
39
|
workspaceUnits: el('chat-units'),
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
|
|
44
44
|
const state = {
|
|
45
45
|
scopeView: null, scopeViewChatId: null, scopeChoice: null, scopeEditing: false, scopePickerOpen: false,
|
|
46
|
+
accessExplanationExpanded: readAccessExplanationPreference(),
|
|
46
47
|
// signInPending is keyed by provider: a wait started in one conversation must not paint an
|
|
47
48
|
// unrelated conversation's button as Waiting for sign-in… for the next two minutes.
|
|
48
49
|
// #1798: the chat owner's display units as the server last answered them (null = not known yet), and the
|
|
@@ -54,8 +55,8 @@
|
|
|
54
55
|
source: null, eventReconnectTimer: null, eventReconnectAttempt: 0, eventReconnectChatId: null, attachments: [], imageLimitChatId: null, followupSubmitting: false, followupUnknownId: null, resolvingFollowupIds: new Set(), retryingFollowupIds: new Set(), integrations: null, historyOpen: false, historyOpenings: 0, historyFilter: 'all', archivedHistoryOpen: false,
|
|
55
56
|
instructorAnswers: [], historyLoading: false, historyRequestGeneration: 0, picker: null, loading: false,
|
|
56
57
|
draftTimer: null, localDraft: null, backgroundDrafts: new Map(), draftWrites: new Map(), draftVersions: new Map(), unknownFollowups: new Map(), refreshTimer: null, scopeGeneration: 0, selectionGeneration: 0, openInGeneration: 0, choosingProvider: false,
|
|
57
|
-
answerJump: null, answerJumpTimer: null, scopeInitialized: false, renaming: null, historyRename: null, pendingSubmissionId: null, recoveryMessage: null, recoveryCanEnd: false,
|
|
58
|
-
stream: null, liveStatusTurnId: null, liveFlo: null, decidingApprovalIds: new Set(), revokingApprovalTurns: new Set(), uploadingChatIds: new Set(),
|
|
58
|
+
answerJump: null, answerJumpTimer: null, scopeInitialized: false, renaming: null, historyRename: null, pendingSubmissionId: null, recoveryMessage: null, recoveryCanEnd: false, recoveryTurnId: null,
|
|
59
|
+
stream: null, liveStatusTurnId: null, liveFlo: null, decidingApprovalIds: new Set(), revokingApprovalTurns: new Set(), uploadingChatIds: new Set(), pendingStops: new Map(),
|
|
59
60
|
// #1653 stage 4: this chat owner's (project or workflow, #1890) questions linked to live Tekla parts, the card's open lists, and the receipt showing it.
|
|
60
61
|
teklaLinks: { ownerKey: '', state: 'idle', links: [], partial: false, inflight: false, again: false }, teklaHistoryUi: {}, teklaHistoryHost: null,
|
|
61
62
|
// Latched so the 5 s account poll logs an outage once instead of twelve times a minute; cleared
|
|
@@ -88,6 +89,18 @@
|
|
|
88
89
|
}).observe(tray);
|
|
89
90
|
}
|
|
90
91
|
keepApprovalTrayDecisionVisible(ui.approvalTray);
|
|
92
|
+
// #2223: a card opening above the message box shrinks the conversation. A reader who was at its end stays at its end,
|
|
93
|
+
// so the AI's reply to their answer is in sight; one who scrolled up stays where they were.
|
|
94
|
+
function keepFeedFollowing(feed) {
|
|
95
|
+
let atEnd = true;
|
|
96
|
+
feed.addEventListener('scroll', () => {
|
|
97
|
+
atEnd = feed.scrollHeight - feed.scrollTop - feed.clientHeight < 56;
|
|
98
|
+
});
|
|
99
|
+
new ResizeObserver(() => {
|
|
100
|
+
if (atEnd && !state.answerJump) feed.scrollTop = feed.scrollHeight;
|
|
101
|
+
}).observe(feed);
|
|
102
|
+
}
|
|
103
|
+
keepFeedFollowing(ui.feed);
|
|
91
104
|
// #2037: safest to widest; Auto is the default for a project or workflow conversation.
|
|
92
105
|
const permissionLabels = {
|
|
93
106
|
'read-only': 'Read only', auto: 'Auto', 'workspace-write': 'Working folder write', 'full-access': 'Full access',
|
|
@@ -241,7 +254,6 @@
|
|
|
241
254
|
// #2059: an Instructor answer uses no tools until the person confirms a wider Access.
|
|
242
255
|
'chat-instructor-answer-access': 'This chat is an Instructor answer, so the AI uses no tools. Confirm the Access change to turn it into an ordinary chat.',
|
|
243
256
|
'chat-instructor-answer-accounts': 'An Instructor answer uses no tools, so it cannot use a connected account. Start a new chat to use one.',
|
|
244
|
-
'chat-guide-read-only': 'The Guide only reads, so its Access stays Read only. To let the AI change things, use a regular conversation.',
|
|
245
257
|
// Damage the user can act on, unlike the refusals below it: the conversation history lists this
|
|
246
258
|
// same record as a row offering Discard, so the sentence sends them there (#1629). Without an
|
|
247
259
|
// entry here the code fell through to the generic "could not complete this chat action", which
|
|
@@ -2449,14 +2461,16 @@
|
|
|
2449
2461
|
// #2037: a Codex auto-review decision is a receipt, not a failure: approved is information, held back is a notice.
|
|
2450
2462
|
const review = event.payload?.tool === 'auto-review' ? event.payload.decision : null;
|
|
2451
2463
|
// #2035: a step declined because nobody was watching a scheduled run is a notice the person reads later, not an error.
|
|
2452
|
-
const unattended = event.payload?.tool === 'unattended-decline';
|
|
2464
|
+
const unattended = event.payload?.tool === 'unattended-decline' || event.payload?.tool === 'unattended-question';
|
|
2453
2465
|
// #2058: an account command Codex ran without asking FloLess already ran; its line says the result is unchecked.
|
|
2454
2466
|
const unchecked = event.payload?.tool === 'unchecked-command';
|
|
2455
2467
|
item.className = review === 'approved' ? 'ai-chat-event auto-review' : review || unattended || unchecked ? 'ai-chat-event auto-review held' : 'ai-chat-event error';
|
|
2456
2468
|
item.dataset.eventSequence = String(event.sequence);
|
|
2457
2469
|
item.dataset.eventId = event.eventId;
|
|
2458
2470
|
const label = document.createElement('strong');
|
|
2459
|
-
|
|
2471
|
+
// #2223: a question the AI asked while nobody was watching went unanswered, not declined.
|
|
2472
|
+
label.textContent = review === 'approved' ? 'Auto-approved' : review ? 'Held back'
|
|
2473
|
+
: unattended ? (event.payload?.tool === 'unattended-question' ? 'Not asked' : 'Declined') : unchecked ? 'Not checked' : 'Not done';
|
|
2460
2474
|
item.append(label, document.createTextNode(` · ${event.payload.message}`));
|
|
2461
2475
|
return item;
|
|
2462
2476
|
}
|
|
@@ -2840,6 +2854,331 @@
|
|
|
2840
2854
|
}
|
|
2841
2855
|
}
|
|
2842
2856
|
|
|
2857
|
+
// ── #2247: FloLess actions the AI ran or suggested ────────────────────────────────────────────────────────────
|
|
2858
|
+
// A proposal card asks the person to confirm one action (a real run, a change suggested from a Guide or Read only
|
|
2859
|
+
// chat), or — for something only a person does — opens the screen where they do it. Nothing runs from the AI's
|
|
2860
|
+
// side: Confirm is the person's click, and the server re-checks that the approved version is still the one shown.
|
|
2861
|
+
const actionCards = new Map();
|
|
2862
|
+
const ACTION_CARDS_KEPT = 200;
|
|
2863
|
+
const ACTION_CONFIRM_VERBS = { 'workflows.run': 'Run it', 'routines.run': 'Run it', 'projects.archive': 'Archive it',
|
|
2864
|
+
'projects.unarchive': 'Bring it back', 'workflows.stop': 'Stop it' };
|
|
2865
|
+
const ACTION_EYEBROWS = { write: 'Suggested change', destructive: 'Needs your OK', 'human-only': 'Your decision' };
|
|
2866
|
+
const ACTION_FINAL = new Set(['done', 'failed', 'cancelled', 'declined', 'expired', 'superseded', 'unknown']);
|
|
2867
|
+
|
|
2868
|
+
/** The newest state the conversation records for a proposal: its card event, then its updates, then this tab's own answer. */
|
|
2869
|
+
function actionProposalState(proposalId) {
|
|
2870
|
+
const entry = actionCards.get(proposalId);
|
|
2871
|
+
let latest = null;
|
|
2872
|
+
for (const event of state.events) {
|
|
2873
|
+
if (event.type === 'action-proposal-update' && event.payload?.proposalId === proposalId) latest = event.payload;
|
|
2874
|
+
}
|
|
2875
|
+
const fromServer = latest ? { state: latest.state, result: latest.result || null, supersededBy: latest.supersededBy || null, next: latest.next || null } : null;
|
|
2876
|
+
// A click's own answer is newer than the journal until the journal catches up; a final journal state always wins.
|
|
2877
|
+
if (entry?.local && !(fromServer && ACTION_FINAL.has(fromServer.state))) return entry.local;
|
|
2878
|
+
return fromServer || { state: 'proposed', result: null, supersededBy: null };
|
|
2879
|
+
}
|
|
2880
|
+
|
|
2881
|
+
function renderActionProposal(event) {
|
|
2882
|
+
const payload = event.payload || {};
|
|
2883
|
+
const proposalId = String(payload.proposalId || event.eventId || '');
|
|
2884
|
+
let entry = actionCards.get(proposalId);
|
|
2885
|
+
if (!entry) {
|
|
2886
|
+
entry = { node: null, signature: '', busy: '', error: '', local: null };
|
|
2887
|
+
actionCards.set(proposalId, entry);
|
|
2888
|
+
while (actionCards.size > ACTION_CARDS_KEPT) actionCards.delete(actionCards.keys().next().value);
|
|
2889
|
+
}
|
|
2890
|
+
const current = actionProposalState(proposalId);
|
|
2891
|
+
const signature = JSON.stringify([event.eventId, current.state, current.result?.message || null, current.supersededBy, current.next || null, entry.busy, entry.error]);
|
|
2892
|
+
if (entry.node && entry.signature === signature) return entry.node;
|
|
2893
|
+
entry.node = paintActionProposal(event, payload, proposalId, entry, current);
|
|
2894
|
+
entry.signature = signature;
|
|
2895
|
+
return entry.node;
|
|
2896
|
+
}
|
|
2897
|
+
|
|
2898
|
+
function repaintActionCards(focusProposal) {
|
|
2899
|
+
for (const old of ui.feed?.querySelectorAll('.ai-chat-action-card[data-proposal-id]') || []) {
|
|
2900
|
+
const event = state.events.find((known) => known.eventId === old.dataset.eventId);
|
|
2901
|
+
if (!event) continue;
|
|
2902
|
+
const next = renderActionProposal(event);
|
|
2903
|
+
if (next !== old) old.replaceWith(next);
|
|
2904
|
+
}
|
|
2905
|
+
if (focusProposal) {
|
|
2906
|
+
const card = ui.feed?.querySelector(`.ai-chat-action-card[data-proposal-id="${CSS.escape(focusProposal)}"]`);
|
|
2907
|
+
const target = card?.querySelector('[data-command-id^="shell.chat-action-stop"]') || card?.querySelector('.ai-chat-action-status');
|
|
2908
|
+
target?.focus({ preventScroll: true });
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
|
|
2912
|
+
/** A card button. Its Instructor instance is the proposal (two cards for one action never share a carrier), and it
|
|
2913
|
+
* is narrated by what the card asks, e.g. "Run dummy-report with its default inputs". */
|
|
2914
|
+
function actionButton(label, commandId, proposalId, summary, className = '') {
|
|
2915
|
+
const control = button(label, `${commandId}#${proposalId}`, className);
|
|
2916
|
+
control.dataset.commandInstanceLabel = summary;
|
|
2917
|
+
return control;
|
|
2918
|
+
}
|
|
2919
|
+
|
|
2920
|
+
/** Open the screen a human-only action names, or the one showing what a finished action made. Nothing runs. */
|
|
2921
|
+
async function openActionScreen(screen) {
|
|
2922
|
+
if (screen?.view === 'page' && screen.pageHome && screen.pageId && typeof window.flolessPages?.open === 'function') {
|
|
2923
|
+
return await window.flolessPages.open(screen.pageHome, screen.pageId);
|
|
2924
|
+
}
|
|
2925
|
+
if (screen?.view === 'chat' && screen.chatId && screen.owner) {
|
|
2926
|
+
await openConversation(screen.chatId, { owner: screen.owner });
|
|
2927
|
+
return state.chat?.chatId === screen.chatId;
|
|
2928
|
+
}
|
|
2929
|
+
if (screen?.view === 'workflow-report' && screen.workflowId && typeof window.flolessBridge?.openAppReport === 'function') {
|
|
2930
|
+
await window.flolessBridge.openAppReport(screen.workflowId, screen.runId || null); return true;
|
|
2931
|
+
}
|
|
2932
|
+
if (screen?.view === 'workflow' && screen.workflowId && typeof window.flolessBridge?.openApp === 'function') {
|
|
2933
|
+
await window.flolessBridge.openApp(screen.workflowId); return true;
|
|
2934
|
+
}
|
|
2935
|
+
if (screen?.view === 'project' && screen.projectId && typeof window.flolessWorkspaces?.openChatOwner === 'function') {
|
|
2936
|
+
await window.flolessWorkspaces.openChatOwner({ kind: 'project', projectId: screen.projectId }); return true;
|
|
2937
|
+
}
|
|
2938
|
+
if (['workspaces', 'workflows'].includes(screen?.view) && typeof window.flolessWorkspaces?.setMode === 'function') {
|
|
2939
|
+
await window.flolessWorkspaces.setMode(screen.view); return true;
|
|
2940
|
+
}
|
|
2941
|
+
return false;
|
|
2942
|
+
}
|
|
2943
|
+
|
|
2944
|
+
async function sendActionProposal(proposalId, verb) {
|
|
2945
|
+
const response = await fetch(`/api/actions/proposals/${encodeURIComponent(proposalId)}/${verb}`, {
|
|
2946
|
+
method: 'POST', credentials: 'same-origin', headers: { 'content-type': 'application/json' }, body: '{}',
|
|
2947
|
+
});
|
|
2948
|
+
let body = null;
|
|
2949
|
+
try { body = await response.json(); } catch { body = null; }
|
|
2950
|
+
return { ok: response.ok && body?.ok === true, body: body || {} };
|
|
2951
|
+
}
|
|
2952
|
+
|
|
2953
|
+
async function actOnProposal(event, proposalId, verb) {
|
|
2954
|
+
const entry = actionCards.get(proposalId);
|
|
2955
|
+
if (!entry || entry.busy) return;
|
|
2956
|
+
const title = String(event.payload?.title || 'the action');
|
|
2957
|
+
entry.busy = verb; entry.error = '';
|
|
2958
|
+
repaintActionCards();
|
|
2959
|
+
let focus = proposalId;
|
|
2960
|
+
try {
|
|
2961
|
+
const { ok, body } = await sendActionProposal(proposalId, verb);
|
|
2962
|
+
if (ok) {
|
|
2963
|
+
entry.local = { state: body.proposal?.state || (verb === 'decline' ? 'declined' : 'executing'), result: body.proposal?.result || null, supersededBy: null };
|
|
2964
|
+
announce(verb === 'confirm' ? `${title}: started.` : verb === 'decline' ? `Not now: ${title}.` : `Asked ${title} to stop.`);
|
|
2965
|
+
} else if (body.fresh) {
|
|
2966
|
+
// The target changed or the offer ended: the old card says so, and a fresh card shows the current state.
|
|
2967
|
+
entry.local = { state: body.proposal?.state || 'superseded', result: null, supersededBy: body.fresh.id };
|
|
2968
|
+
announce(body.error || 'It changed after it was suggested. A new card shows the current state.');
|
|
2969
|
+
} else {
|
|
2970
|
+
if (body.proposal?.state) entry.local = { state: body.proposal.state, result: body.proposal.result || null, supersededBy: body.proposal.supersededBy || null };
|
|
2971
|
+
entry.error = body.error || 'FloLess could not do that just now. Try again in a moment.';
|
|
2972
|
+
}
|
|
2973
|
+
} catch {
|
|
2974
|
+
entry.error = 'FloLess could not be reached. Check that it is still running, then try again.';
|
|
2975
|
+
} finally {
|
|
2976
|
+
entry.busy = '';
|
|
2977
|
+
repaintActionCards(focus);
|
|
2978
|
+
}
|
|
2979
|
+
}
|
|
2980
|
+
|
|
2981
|
+
function paintActionProposal(event, payload, proposalId, entry, current) {
|
|
2982
|
+
const actionId = String(payload.actionId || 'action');
|
|
2983
|
+
const title = String(payload.title || 'A FloLess action');
|
|
2984
|
+
const summaryText = String(payload.summary || title);
|
|
2985
|
+
const risk = ['write', 'destructive', 'human-only'].includes(payload.risk) ? payload.risk : 'write';
|
|
2986
|
+
const card = document.createElement('section');
|
|
2987
|
+
card.className = `ai-chat-filter-card ai-chat-action-card risk-${risk}`;
|
|
2988
|
+
card.dataset.eventId = event.eventId;
|
|
2989
|
+
card.dataset.eventSequence = String(event.sequence);
|
|
2990
|
+
card.dataset.proposalId = proposalId;
|
|
2991
|
+
card.dataset.state = current.state;
|
|
2992
|
+
card.setAttribute('role', 'group');
|
|
2993
|
+
const status = document.createElement('p');
|
|
2994
|
+
status.className = 'ai-chat-filter-note ai-chat-action-status';
|
|
2995
|
+
status.setAttribute('role', 'status');
|
|
2996
|
+
status.tabIndex = -1;
|
|
2997
|
+
const titleId = `chat-action-title-${proposalId}`;
|
|
2998
|
+
card.setAttribute('aria-labelledby', titleId);
|
|
2999
|
+
|
|
3000
|
+
// Finished, set aside or replaced: one quiet line that says honestly what happened.
|
|
3001
|
+
const collapsed = {
|
|
3002
|
+
declined: `Not now: ${title}`,
|
|
3003
|
+
expired: `Offer ended: ${title}. Ask again if you still want it.`,
|
|
3004
|
+
superseded: `Replaced by a newer suggestion: ${title}`,
|
|
3005
|
+
cancelled: `Stopped: ${title}. Work already sent to the host may remain.`,
|
|
3006
|
+
}[current.state];
|
|
3007
|
+
if (collapsed) {
|
|
3008
|
+
card.classList.add('is-collapsed');
|
|
3009
|
+
const line = document.createElement('p');
|
|
3010
|
+
line.className = 'ai-chat-action-line';
|
|
3011
|
+
line.id = titleId;
|
|
3012
|
+
line.textContent = collapsed;
|
|
3013
|
+
card.append(line);
|
|
3014
|
+
return card;
|
|
3015
|
+
}
|
|
3016
|
+
|
|
3017
|
+
const head = document.createElement('div');
|
|
3018
|
+
head.className = 'ai-chat-filter-card-head';
|
|
3019
|
+
const eyebrow = document.createElement('span');
|
|
3020
|
+
eyebrow.className = 'guide-move-eyebrow';
|
|
3021
|
+
eyebrow.textContent = ACTION_EYEBROWS[risk];
|
|
3022
|
+
const strong = document.createElement('strong');
|
|
3023
|
+
strong.id = titleId;
|
|
3024
|
+
strong.textContent = title;
|
|
3025
|
+
const named = document.createElement('div');
|
|
3026
|
+
named.className = 'ai-chat-action-named';
|
|
3027
|
+
named.append(eyebrow, strong);
|
|
3028
|
+
head.append(named);
|
|
3029
|
+
const badgeText = { executing: 'Running', done: 'Done', failed: 'Not done', unknown: 'Unknown' }[current.state];
|
|
3030
|
+
if (badgeText) {
|
|
3031
|
+
const badge = document.createElement('span');
|
|
3032
|
+
badge.className = 'ai-chat-filter-state';
|
|
3033
|
+
badge.textContent = badgeText;
|
|
3034
|
+
head.append(badge);
|
|
3035
|
+
}
|
|
3036
|
+
card.append(head);
|
|
3037
|
+
if (payload.changedNote) {
|
|
3038
|
+
const changed = document.createElement('p');
|
|
3039
|
+
changed.className = 'ai-chat-filter-note ai-chat-action-changed';
|
|
3040
|
+
changed.textContent = String(payload.changedNote);
|
|
3041
|
+
card.append(changed);
|
|
3042
|
+
}
|
|
3043
|
+
const summary = document.createElement('p');
|
|
3044
|
+
summary.className = 'ai-chat-action-summary';
|
|
3045
|
+
summary.textContent = summaryText;
|
|
3046
|
+
card.append(summary);
|
|
3047
|
+
|
|
3048
|
+
if (current.state === 'done') {
|
|
3049
|
+
card.classList.add('is-done');
|
|
3050
|
+
status.textContent = current.next ? 'Done. Its result is ready to view.' : String(payload.doneNote || 'Done.');
|
|
3051
|
+
if (current.next) {
|
|
3052
|
+
// What the finished action made (a run's report): opening it only shows it, it runs nothing again.
|
|
3053
|
+
const actions = document.createElement('div');
|
|
3054
|
+
actions.className = 'ai-chat-filter-actions';
|
|
3055
|
+
const view = actionButton(String(current.next.label || 'View result'), 'shell.chat-action-view', proposalId, summaryText);
|
|
3056
|
+
view.dataset.tip = 'Opens what this made. Nothing runs again.';
|
|
3057
|
+
view.addEventListener('click', async () => {
|
|
3058
|
+
entry.error = '';
|
|
3059
|
+
try { if (!(await openActionScreen(current.next))) entry.error = 'FloLess couldn’t open that from here. Open the workflow from Workflows instead.'; }
|
|
3060
|
+
catch (error) { entry.error = error?.message || 'FloLess couldn’t open that from here.'; }
|
|
3061
|
+
if (entry.error) status.textContent = entry.error;
|
|
3062
|
+
});
|
|
3063
|
+
actions.append(view);
|
|
3064
|
+
card.append(actions);
|
|
3065
|
+
}
|
|
3066
|
+
card.append(status);
|
|
3067
|
+
return card;
|
|
3068
|
+
}
|
|
3069
|
+
if (current.state === 'failed') {
|
|
3070
|
+
card.classList.add('is-failed');
|
|
3071
|
+
status.textContent = `${current.result?.message || 'It did not complete.'} You can ask the AI to suggest it again.`;
|
|
3072
|
+
card.append(status);
|
|
3073
|
+
return card;
|
|
3074
|
+
}
|
|
3075
|
+
if (current.state === 'unknown') {
|
|
3076
|
+
status.textContent = 'FloLess restarted while this was running, so how it ended is not known. Check the result, and ask the AI to suggest it again if you still want it.';
|
|
3077
|
+
card.append(status);
|
|
3078
|
+
return card;
|
|
3079
|
+
}
|
|
3080
|
+
if (payload.riskReason) {
|
|
3081
|
+
const reason = document.createElement('p');
|
|
3082
|
+
reason.className = 'ai-chat-filter-note ai-chat-action-reason';
|
|
3083
|
+
reason.textContent = String(payload.riskReason);
|
|
3084
|
+
card.append(reason);
|
|
3085
|
+
}
|
|
3086
|
+
if (payload.why) {
|
|
3087
|
+
const why = document.createElement('p');
|
|
3088
|
+
why.className = 'ai-chat-filter-why ai-chat-action-why';
|
|
3089
|
+
why.textContent = `Why: ${String(payload.why)}`;
|
|
3090
|
+
card.append(why);
|
|
3091
|
+
}
|
|
3092
|
+
const actions = document.createElement('div');
|
|
3093
|
+
actions.className = 'ai-chat-filter-actions';
|
|
3094
|
+
if (current.state === 'executing') {
|
|
3095
|
+
status.textContent = actionId === 'workflows.run' || actionId === 'routines.run' ? 'Running…' : 'Working…';
|
|
3096
|
+
if (actionId === 'workflows.run') {
|
|
3097
|
+
const stop = actionButton('Stop', 'shell.chat-action-stop', proposalId, summaryText);
|
|
3098
|
+
stop.dataset.tip = 'Asks the run to stop. Work already sent to the host may remain.';
|
|
3099
|
+
stop.disabled = Boolean(entry.busy);
|
|
3100
|
+
stop.addEventListener('click', () => { void actOnProposal(event, proposalId, 'cancel'); });
|
|
3101
|
+
actions.append(stop);
|
|
3102
|
+
}
|
|
3103
|
+
card.append(actions, status);
|
|
3104
|
+
return card;
|
|
3105
|
+
}
|
|
3106
|
+
if (risk === 'human-only') {
|
|
3107
|
+
const screen = payload.screen || {};
|
|
3108
|
+
const open = actionButton(String(screen.label || 'Open it'), 'shell.chat-action-open', proposalId, summaryText, 'ai-chat-filter-apply');
|
|
3109
|
+
open.dataset.tip = 'Opens the screen where you do this yourself. Nothing runs from this card.';
|
|
3110
|
+
open.addEventListener('click', async () => {
|
|
3111
|
+
entry.error = '';
|
|
3112
|
+
try { if (!(await openActionScreen(screen))) entry.error = screen.view === 'chat'
|
|
3113
|
+
? 'FloLess couldn’t open that conversation. Find it in AI Chat history and try again.'
|
|
3114
|
+
: 'FloLess couldn’t open that from here. Open it from Workflows or Workspaces instead.'; }
|
|
3115
|
+
catch (error) { entry.error = error?.message || 'FloLess couldn’t open that from here.'; }
|
|
3116
|
+
if (entry.error) { status.textContent = entry.error; }
|
|
3117
|
+
});
|
|
3118
|
+
const later = actionButton('Not now', 'shell.chat-action-not-now', proposalId, summaryText);
|
|
3119
|
+
later.dataset.tip = 'Sets this suggestion aside. Nothing changes.';
|
|
3120
|
+
later.disabled = Boolean(entry.busy);
|
|
3121
|
+
later.addEventListener('click', () => { void actOnProposal(event, proposalId, 'decline'); });
|
|
3122
|
+
actions.append(later, open);
|
|
3123
|
+
const note = document.createElement('p');
|
|
3124
|
+
note.className = 'ai-chat-filter-note';
|
|
3125
|
+
note.textContent = 'Only you can do this. Nothing runs from here.';
|
|
3126
|
+
status.textContent = entry.error;
|
|
3127
|
+
card.append(actions, note, status);
|
|
3128
|
+
return card;
|
|
3129
|
+
}
|
|
3130
|
+
const later = actionButton('Not now', 'shell.chat-action-not-now', proposalId, summaryText);
|
|
3131
|
+
later.dataset.tip = 'Sets this suggestion aside. Nothing runs.';
|
|
3132
|
+
later.disabled = Boolean(entry.busy);
|
|
3133
|
+
later.addEventListener('click', () => { void actOnProposal(event, proposalId, 'decline'); });
|
|
3134
|
+
const confirm = actionButton(entry.busy === 'confirm' ? 'Starting…' : (ACTION_CONFIRM_VERBS[actionId] || 'Do it'), 'shell.chat-action-confirm', proposalId, summaryText, 'ai-chat-filter-apply');
|
|
3135
|
+
confirm.dataset.tip = risk === 'destructive' ? 'Runs it now, for real. FloLess checks first that nothing changed since this was suggested.'
|
|
3136
|
+
: 'Makes this change now. FloLess checks first that nothing changed since this was suggested.';
|
|
3137
|
+
confirm.disabled = Boolean(entry.busy);
|
|
3138
|
+
if (entry.busy === 'confirm') confirm.setAttribute('aria-busy', 'true');
|
|
3139
|
+
confirm.addEventListener('click', () => { void actOnProposal(event, proposalId, 'confirm'); });
|
|
3140
|
+
actions.append(later, confirm);
|
|
3141
|
+
const meta = document.createElement('p');
|
|
3142
|
+
meta.className = 'ai-chat-filter-note ai-chat-action-meta';
|
|
3143
|
+
meta.textContent = payload.revision === 'bound' ? 'Uses the approved version as it is now; if it changes first, you will be asked again.'
|
|
3144
|
+
: 'Acts on things as they are when you confirm.';
|
|
3145
|
+
status.textContent = entry.error;
|
|
3146
|
+
card.append(actions, meta, status);
|
|
3147
|
+
return card;
|
|
3148
|
+
}
|
|
3149
|
+
|
|
3150
|
+
/** One line per action the AI ran itself from this conversation: what it was, and how it ended. */
|
|
3151
|
+
function renderActionRow(event) {
|
|
3152
|
+
const payload = event.payload || {};
|
|
3153
|
+
const row = document.createElement('div');
|
|
3154
|
+
const outcome = payload.outcome === 'ok' ? 'ok' : payload.outcome === 'cancelled' ? 'stopped' : 'failed';
|
|
3155
|
+
row.className = `ai-chat-action-row is-${outcome}`;
|
|
3156
|
+
row.dataset.eventId = event.eventId;
|
|
3157
|
+
row.dataset.eventSequence = String(event.sequence);
|
|
3158
|
+
const glyph = document.createElement('span');
|
|
3159
|
+
glyph.className = 'ai-chat-action-row-glyph';
|
|
3160
|
+
glyph.setAttribute('aria-hidden', 'true');
|
|
3161
|
+
glyph.textContent = outcome === 'ok' ? '✓' : outcome === 'stopped' ? '■' : '!';
|
|
3162
|
+
const verb = document.createElement('span');
|
|
3163
|
+
verb.className = 'ai-chat-action-row-verb';
|
|
3164
|
+
verb.textContent = payload.risk === 'read' ? 'Read' : 'Changed';
|
|
3165
|
+
const title = document.createElement('span');
|
|
3166
|
+
title.className = 'ai-chat-action-row-title';
|
|
3167
|
+
title.textContent = String(payload.title || payload.actionId || 'A FloLess action');
|
|
3168
|
+
const state = document.createElement('span');
|
|
3169
|
+
state.className = 'ai-chat-filter-state';
|
|
3170
|
+
state.textContent = outcome === 'ok' ? 'Done' : outcome === 'stopped' ? 'Stopped' : 'Not done';
|
|
3171
|
+
row.append(glyph, verb, title, state);
|
|
3172
|
+
if (outcome === 'failed' && payload.message) {
|
|
3173
|
+
const reason = document.createElement('span');
|
|
3174
|
+
reason.className = 'ai-chat-action-row-reason';
|
|
3175
|
+
reason.textContent = String(payload.message);
|
|
3176
|
+
row.append(reason);
|
|
3177
|
+
}
|
|
3178
|
+
row.setAttribute('aria-label', `${verb.textContent}: ${title.textContent}, ${state.textContent.toLowerCase()}${outcome === 'failed' && payload.message ? `. ${payload.message}` : ''}`);
|
|
3179
|
+
return row;
|
|
3180
|
+
}
|
|
3181
|
+
|
|
2843
3182
|
/** The result of a check the person approved in chat: the same receipt Discover and Integrations show. */
|
|
2844
3183
|
function renderConnectionCheck(event) {
|
|
2845
3184
|
const payload = event.payload || {};
|
|
@@ -2930,6 +3269,13 @@
|
|
|
2930
3269
|
if (event.type === 'user-message') return withFilterNotShared(renderMessage(event, 'user', payloadText(event)), event);
|
|
2931
3270
|
if (event.type === 'filter-proposal') return renderServerProposal(event);
|
|
2932
3271
|
if (event.type === 'filter-proposal-update') return null;
|
|
3272
|
+
// #2247: a FloLess action the AI suggested (a card) or ran (a line); an update only repaints its card.
|
|
3273
|
+
if (event.type === 'action-proposal') return renderActionProposal(event);
|
|
3274
|
+
if (event.type === 'action-proposal-update') return null;
|
|
3275
|
+
if (event.type === 'action-call') return renderActionRow(event);
|
|
3276
|
+
// #2255: a change the AI made to the model view; its outcome repaints the same line.
|
|
3277
|
+
if (event.type === 'view-command') return renderViewCommand(event);
|
|
3278
|
+
if (event.type === 'view-command-update') return null;
|
|
2933
3279
|
// #1900: a connection the AI suggested, the result of a check it asked for, and a check run under "Allow for this chat".
|
|
2934
3280
|
if (event.type === 'connection-proposal') return renderConnectionProposal(event);
|
|
2935
3281
|
if (event.type === 'connection-proposal-update') return null;
|
|
@@ -2939,6 +3285,8 @@
|
|
|
2939
3285
|
// #2185: what came of a card's button repaints that card; it is never a line of its own.
|
|
2940
3286
|
if (event.type === 'next-move-update') { window.flolessGuide?.applyMoveUpdate?.(event); return null; }
|
|
2941
3287
|
if (event.type === 'approval-decided' && event.payload?.automatic === true && event.payload?.connectionCheck) return renderConnectionCheckAllowed(event);
|
|
3288
|
+
// #2223 Revision 6: a question whose words already streamed carries only its card (above the message box): no empty bubble.
|
|
3289
|
+
if (event.type === 'assistant-message' && event.payload?.asyncQuestion && !payloadText(event)) return null;
|
|
2942
3290
|
if (event.type === 'assistant-message') return renderMessage(event, 'assistant', payloadText(event), Boolean(event.payload?.delta));
|
|
2943
3291
|
// #1907: a connector call that ran under "Allow for this chat" leaves a visible receipt; every other decision is audit only.
|
|
2944
3292
|
if (event.type === 'approval-decided' && event.payload?.automatic === true && event.payload?.connector) return renderConnectorReceipt(event);
|
|
@@ -2949,6 +3297,8 @@
|
|
|
2949
3297
|
// A Tekla read already leaves its own result card, so it gets no second line here.
|
|
2950
3298
|
if (event.type === 'approval-decided' && event.payload?.automatic === true && !event.payload?.unattended && event.payload?.decision === 'allow'
|
|
2951
3299
|
&& !String(event.payload?.tool || '').startsWith('floless_tekla_')) return renderAutoReceipt(event);
|
|
3300
|
+
// #2223: how a question card closed: the person's answer, or why it never reached the AI.
|
|
3301
|
+
if (event.type === 'approval-decided' && event.payload?.kind === 'question') return renderQuestionAnswered(event);
|
|
2952
3302
|
if (event.type === 'approval-requested' || event.type === 'approval-decided' || event.type === 'state' || event.type === 'followup-status') return null;
|
|
2953
3303
|
if (event.type === 'tool' && ['agent', 'guide', 'instructor'].includes(event.payload?.tool) && typeof event.payload?.message === 'string') return renderAgentRunLine(event);
|
|
2954
3304
|
if (event.type === 'tekla-read') return renderTeklaReadEvent(event);
|
|
@@ -3060,7 +3410,7 @@
|
|
|
3060
3410
|
* Typed text is not in the signature on purpose: it lives in the field and in `drafts`, and a keystroke is not a
|
|
3061
3411
|
* reason to rebuild. Everything else a card paints from belongs in it.
|
|
3062
3412
|
*/
|
|
3063
|
-
const CARD_SIGNATURE_SKIP = new Set(['node', 'nodeSig', 'drafts', 'bulkDraft', 'rowsScroll', 'bodyScroll', 'reloadPending', 'loading']);
|
|
3413
|
+
const CARD_SIGNATURE_SKIP = new Set(['node', 'nodeSig', 'drafts', 'bulkDraft', 'rowsScroll', 'bodyScroll', 'reloadPending', 'loading', 'slotNode', 'slotDrafts', 'slotSig']);
|
|
3064
3414
|
function cardSignature(entry, eventId, sequence) {
|
|
3065
3415
|
settleNotSent(entry);
|
|
3066
3416
|
const sources = [];
|
|
@@ -3148,7 +3498,7 @@
|
|
|
3148
3498
|
|
|
3149
3499
|
function repaintHeightCard(entry) {
|
|
3150
3500
|
const old = ui.feed?.querySelector(`[data-height-question="${CSS.escape(entry.key)}"]`);
|
|
3151
|
-
if (!old) return;
|
|
3501
|
+
if (!old) { drawingSlotRepaint(); return; }
|
|
3152
3502
|
const focused = old.contains(document.activeElement) ? document.activeElement.dataset.commandId : null;
|
|
3153
3503
|
const caret = focused ? textCaret(document.activeElement) : null;
|
|
3154
3504
|
const next = rememberCard(entry, paintHeightCard(entry, old.dataset.eventId, old.dataset.eventSequence), old.dataset.eventId, old.dataset.eventSequence);
|
|
@@ -3202,209 +3552,10 @@
|
|
|
3202
3552
|
}
|
|
3203
3553
|
|
|
3204
3554
|
function paintHeightCard(entry, eventId, sequence) {
|
|
3205
|
-
|
|
3206
|
-
const card = document.createElement('section');
|
|
3207
|
-
card.className = 'ai-chat-filter-card ai-chat-height-card';
|
|
3208
|
-
card.dataset.heightQuestion = entry.key;
|
|
3209
|
-
card.dataset.eventId = eventId || '';
|
|
3210
|
-
card.dataset.eventSequence = sequence || '';
|
|
3211
|
-
card.setAttribute('aria-label', view?.n ? `Confirm member heights, question ${view.n}` : 'Confirm member heights');
|
|
3212
|
-
const rows = view ? view.ends : [];
|
|
3213
|
-
const live = rows.filter((row) => row.status !== 'superseded');
|
|
3214
|
-
// A picture-only answer ("see snap") is answered by the person but waits on the READ, which only looks
|
|
3215
|
-
// once told; it counts here so Tell the read is offered (E2E #1906).
|
|
3216
|
-
const answered = live.filter((row) => row.answer && (row.status === 'confirmed' || row.status === 'typed' || row.status === 'evidence'));
|
|
3217
|
-
const open = Boolean(view?.open);
|
|
3218
|
-
const allAnswered = live.length > 0 && answered.length === live.length;
|
|
3219
|
-
card.dataset.state = !view ? (entry.finished ? 'closed' : 'loading') : !open ? 'closed' : allAnswered ? 'answered' : 'open';
|
|
3220
|
-
|
|
3221
|
-
const head = document.createElement('div'); head.className = 'ai-chat-filter-card-head';
|
|
3222
|
-
const title = document.createElement('strong'); title.textContent = 'Confirm member heights';
|
|
3223
|
-
const chip = document.createElement('span'); chip.className = 'ai-chat-filter-state';
|
|
3224
|
-
chip.textContent = !view ? (entry.finished ? 'closed' : 'loading') : !open ? 'closed' : allAnswered ? 'answered' : 'needs you';
|
|
3225
|
-
head.append(title, chip);
|
|
3226
|
-
card.append(head);
|
|
3227
|
-
|
|
3228
|
-
const note = document.createElement('p'); note.className = 'ai-chat-filter-note';
|
|
3229
|
-
note.textContent = !view
|
|
3230
|
-
? (entry.finished ? CARD_FINISHED_TEXT : entry.loadError || 'Loading the heights this read is asking about…')
|
|
3231
|
-
: open
|
|
3232
|
-
? (rows.some((row) => row.inModel)
|
|
3233
|
-
// #1903: never say "straight into the model" about a member already in it — that answer is proposed.
|
|
3234
|
-
// Neutral about the drawings: an existing member's end may well be drawn, and the person is being
|
|
3235
|
-
// asked whether it still holds (code review).
|
|
3236
|
-
? 'Only you can answer these heights — the AI can’t fill this in. 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.'
|
|
3237
|
-
: 'The drawings don’t settle these heights. Only you can answer — the AI can’t fill this in. What you confirm or type goes straight into the model.')
|
|
3238
|
-
: 'This read is no longer waiting for an answer.';
|
|
3239
|
-
card.append(note);
|
|
3240
|
-
if (!view) {
|
|
3241
|
-
if (entry.loadError) {
|
|
3242
|
-
const actions = document.createElement('div'); actions.className = 'ai-chat-filter-actions';
|
|
3243
|
-
const retry = heightActionButton('Try again', `shell.chat-height-retry#${entry.questionId}`, 'this height question', '');
|
|
3244
|
-
retry.addEventListener('click', () => { entry.loadError = ''; repaintHeightCard(entry); loadHeightQuestion(entry); });
|
|
3245
|
-
actions.append(retry); card.append(actions);
|
|
3246
|
-
}
|
|
3247
|
-
return card;
|
|
3248
|
-
}
|
|
3249
|
-
|
|
3250
|
-
const questionLabel = `height question ${view.n}`;
|
|
3251
|
-
const count = document.createElement('p'); count.className = 'ai-chat-height-count'; count.setAttribute('aria-live', 'polite');
|
|
3252
|
-
count.textContent = `${answered.length} of ${live.length} answered`;
|
|
3253
|
-
card.append(count);
|
|
3254
|
-
|
|
3255
|
-
// #1906: rows the read grouped ("W10x33 column bases") sit under a header that selects them together.
|
|
3256
|
-
const selectable = (row) => open && row.status !== 'superseded' && !(row.answer && (row.status === 'confirmed' || row.status === 'typed') && !entry.changing.has(heightEndKey(row)));
|
|
3257
|
-
for (const key of [...entry.selected]) if (!rows.some((row) => heightEndKey(row) === key && selectable(row))) entry.selected.delete(key);
|
|
3258
|
-
const list = document.createElement('ol'); list.className = 'ai-chat-height-rows';
|
|
3259
|
-
list.setAttribute('role', 'region'); list.setAttribute('aria-label', 'Heights to confirm'); list.tabIndex = 0;
|
|
3260
|
-
list.dataset.commandId = `shell.chat-height-rows#${entry.questionId}`;
|
|
3261
|
-
list.dataset.commandInstanceLabel = questionLabel;
|
|
3262
|
-
const groups = [];
|
|
3263
|
-
for (const row of rows) {
|
|
3264
|
-
const name = row.group || '';
|
|
3265
|
-
let group = groups.find((g) => g.name === name);
|
|
3266
|
-
if (!group) { group = { name, rows: [] }; groups.push(group); }
|
|
3267
|
-
group.rows.push(row);
|
|
3268
|
-
}
|
|
3269
|
-
for (const group of groups) {
|
|
3270
|
-
if (group.name) list.append(paintHeightGroup(entry, group, selectable));
|
|
3271
|
-
for (const row of group.rows) list.append(paintHeightRow(entry, row, open, selectable(row)));
|
|
3272
|
-
}
|
|
3273
|
-
card.append(list);
|
|
3274
|
-
// The feed repaints on every streamed word; a person scrolled halfway down a long card stays there.
|
|
3275
|
-
list.addEventListener('scroll', () => { entry.rowsScroll = list.scrollTop; }, { passive: true });
|
|
3276
|
-
if (entry.rowsScroll) requestAnimationFrame(() => { if (list.isConnected) list.scrollTop = entry.rowsScroll; });
|
|
3277
|
-
|
|
3278
|
-
if (open && entry.selected.size) card.append(paintHeightBulk(entry, rows, questionLabel));
|
|
3279
|
-
|
|
3280
|
-
const error = document.createElement('p'); error.className = 'ai-chat-height-error'; error.setAttribute('role', 'alert');
|
|
3281
|
-
error.textContent = entry.cardError || '';
|
|
3282
|
-
card.append(error);
|
|
3283
|
-
|
|
3284
|
-
const actions = document.createElement('div'); actions.className = 'ai-chat-filter-actions';
|
|
3285
|
-
const confirmable = live.filter((row) => !row.answer && row.proposed);
|
|
3286
|
-
if (open && !allAnswered && !entry.selected.size && confirmable.length >= 2 && confirmable.length === live.filter((row) => !row.answer).length) {
|
|
3287
|
-
const all = heightActionButton(`Confirm all ${confirmable.length}`, `shell.chat-height-confirm-all#${entry.questionId}`, questionLabel, '',
|
|
3288
|
-
entry.busy ? 'A height is still being saved — wait for it to finish' : null);
|
|
3289
|
-
all.addEventListener('click', () => {
|
|
3290
|
-
if (all.getAttribute('aria-disabled') === 'true') return;
|
|
3291
|
-
submitHeightAnswers(entry, confirmable.map((row) => ({ memberId: row.memberId, end: row.end, action: 'confirm', shown: row.proposed.value })), null);
|
|
3292
|
-
});
|
|
3293
|
-
actions.append(all);
|
|
3294
|
-
}
|
|
3295
|
-
if (open && allAnswered) {
|
|
3296
|
-
const done = document.createElement('p'); done.className = 'ai-chat-height-done';
|
|
3297
|
-
// No paint-time state about the composer: it changes without this card repainting, so anything
|
|
3298
|
-
// painted here about it would go stale. The click decides (owner ruling 2026-10-02).
|
|
3299
|
-
done.textContent = 'All answered. Tell the read puts the message in the box so you can add to it; Send to the read sends it now.';
|
|
3300
|
-
card.append(done);
|
|
3301
|
-
const tell = heightActionButton('Tell the read', `shell.chat-height-tell-read#${entry.questionId}`, questionLabel, 'ai-chat-filter-apply', null);
|
|
3302
|
-
tell.addEventListener('click', () => tellReadHeightsAnswered(entry));
|
|
3303
|
-
const send = heightActionButton('Send to the read', `shell.chat-height-send-read#${entry.questionId}`, questionLabel, '', null);
|
|
3304
|
-
send.addEventListener('click', () => { void sendToReadAnswered(entry, heightTellText(entry), repaintHeightCard); });
|
|
3305
|
-
actions.append(tell, send);
|
|
3306
|
-
}
|
|
3307
|
-
actions.hidden = !actions.childNodes.length;
|
|
3308
|
-
card.append(actions);
|
|
3309
|
-
return card;
|
|
3310
|
-
}
|
|
3311
|
-
|
|
3312
|
-
/** A themed checkbox (the native box never shows, in either theme). */
|
|
3313
|
-
function themedCheck(commandId, instance, checked, ariaLabel, disabledReason, onChange) {
|
|
3314
|
-
const box = document.createElement('input');
|
|
3315
|
-
box.type = 'checkbox'; box.className = 'ai-chat-check';
|
|
3316
|
-
box.dataset.commandId = commandId; box.dataset.commandInstanceLabel = instance;
|
|
3317
|
-
box.checked = checked;
|
|
3318
|
-
box.setAttribute('aria-label', ariaLabel);
|
|
3319
|
-
if (disabledReason) { box.disabled = true; box.dataset.blockedReason = disabledReason; }
|
|
3320
|
-
box.addEventListener('change', () => onChange(box.checked));
|
|
3321
|
-
return box;
|
|
3322
|
-
}
|
|
3323
|
-
|
|
3324
|
-
function paintHeightGroup(entry, group, selectable) {
|
|
3325
|
-
const header = document.createElement('li'); header.className = 'ai-chat-height-group';
|
|
3326
|
-
const name = document.createElement('span'); name.className = 'ai-chat-height-group-name'; name.textContent = group.name; name.dataset.tip = group.name;
|
|
3327
|
-
const tally = document.createElement('span'); tally.className = 'ai-chat-height-meta'; tally.textContent = `${group.rows.length} ${group.rows.length === 1 ? 'end' : 'ends'}`;
|
|
3328
|
-
header.append(name, tally);
|
|
3329
|
-
const open = group.rows.filter(selectable);
|
|
3330
|
-
if (open.length) {
|
|
3331
|
-
const all = open.every((row) => entry.selected.has(heightEndKey(row)));
|
|
3332
|
-
const toggle = heightActionButton(all ? 'Clear group' : 'Select group', `shell.chat-height-select-group#${entry.questionId} ${group.name}`, group.name, 'ai-chat-height-change',
|
|
3333
|
-
entry.busy ? 'A height is still being saved — wait for it to finish' : null);
|
|
3334
|
-
toggle.setAttribute('aria-label', `${all ? 'Clear' : 'Select'} every open end in ${group.name}`);
|
|
3335
|
-
toggle.addEventListener('click', () => {
|
|
3336
|
-
if (toggle.getAttribute('aria-disabled') === 'true') return;
|
|
3337
|
-
for (const row of open) { if (all) entry.selected.delete(heightEndKey(row)); else entry.selected.add(heightEndKey(row)); }
|
|
3338
|
-
repaintHeightCard(entry);
|
|
3339
|
-
});
|
|
3340
|
-
header.append(toggle);
|
|
3341
|
-
}
|
|
3342
|
-
return header;
|
|
3555
|
+
return paintDrawingHistory('height', entry, eventId, sequence);
|
|
3343
3556
|
}
|
|
3344
3557
|
|
|
3345
|
-
|
|
3346
|
-
function paintHeightBulk(entry, rows, questionLabel) {
|
|
3347
|
-
const chosen = rows.filter((row) => entry.selected.has(heightEndKey(row)));
|
|
3348
|
-
const n = chosen.length;
|
|
3349
|
-
const busyReason = entry.busy ? 'A height is still being saved — wait for it to finish' : null;
|
|
3350
|
-
const bar = document.createElement('div'); bar.className = 'ai-chat-height-bulk';
|
|
3351
|
-
const top = document.createElement('div'); top.className = 'ai-chat-height-bulk-top';
|
|
3352
|
-
const tally = document.createElement('span'); tally.setAttribute('aria-live', 'polite'); tally.setAttribute('aria-atomic', 'true');
|
|
3353
|
-
tally.textContent = `${n} selected`;
|
|
3354
|
-
const clear = heightActionButton('Clear', `shell.chat-height-bulk-clear#${entry.questionId}`, questionLabel, 'ai-chat-height-change', null);
|
|
3355
|
-
clear.setAttribute('aria-label', 'Clear the selection');
|
|
3356
|
-
clear.addEventListener('click', () => { entry.selected.clear(); repaintHeightCard(entry); });
|
|
3357
|
-
top.append(tally, clear);
|
|
3358
|
-
bar.append(top);
|
|
3359
|
-
const shared = chosen.every((row) => row.proposed && chosen[0].proposed && row.proposed.value === chosen[0].proposed.value);
|
|
3360
|
-
if (shared && chosen[0]?.proposed) {
|
|
3361
|
-
// Offered only when every ticked end has the SAME proposal — never shown disabled (design review).
|
|
3362
|
-
const line = document.createElement('div'); line.className = 'ai-chat-height-proposal';
|
|
3363
|
-
const value = document.createElement('span'); value.textContent = `Proposed ${chosen[0].proposed.asRead}`;
|
|
3364
|
-
const confirm = heightActionButton(`Confirm proposed for ${n}`, `shell.chat-height-bulk-confirm#${entry.questionId}`, questionLabel, 'ai-chat-filter-apply', busyReason);
|
|
3365
|
-
confirm.addEventListener('click', () => {
|
|
3366
|
-
if (confirm.getAttribute('aria-disabled') === 'true') return;
|
|
3367
|
-
submitHeightAnswers(entry, chosen.map((row) => ({ memberId: row.memberId, end: row.end, action: 'confirm', shown: row.proposed.value })), null, `hb:${entry.questionId}`);
|
|
3368
|
-
});
|
|
3369
|
-
line.append(value, confirm);
|
|
3370
|
-
bar.append(line);
|
|
3371
|
-
}
|
|
3372
|
-
const field = document.createElement('div'); field.className = 'ai-chat-height-field';
|
|
3373
|
-
const input = document.createElement('input');
|
|
3374
|
-
input.type = 'text'; input.className = 'ai-chat-height-input'; input.autocomplete = 'off'; input.spellcheck = false;
|
|
3375
|
-
input.dataset.commandId = `shell.chat-height-bulk-input#${entry.questionId}`; input.dataset.commandInstanceLabel = questionLabel;
|
|
3376
|
-
input.placeholder = entry.view?.units === 'mm' ? 'one height for all, e.g. 4870 mm' : 'one height for all, e.g. 16\'-6"';
|
|
3377
|
-
input.setAttribute('aria-label', `One height for the ${n} selected ends`);
|
|
3378
|
-
input.value = entry.bulkDraft || '';
|
|
3379
|
-
input.addEventListener('input', () => { entry.bulkDraft = input.value; entry.cardError = ''; });
|
|
3380
|
-
if (busyReason) { input.readOnly = true; input.setAttribute('aria-disabled', 'true'); input.dataset.blockedReason = busyReason; }
|
|
3381
|
-
const use = heightActionButton(`Use for ${n}`, `shell.chat-height-bulk-use#${entry.questionId}`, questionLabel, shared ? '' : 'ai-chat-filter-apply', busyReason);
|
|
3382
|
-
use.setAttribute('aria-label', `Use the typed height for the ${n} selected ends`);
|
|
3383
|
-
const submit = () => {
|
|
3384
|
-
if (use.getAttribute('aria-disabled') === 'true') return;
|
|
3385
|
-
const typed = input.value.trim();
|
|
3386
|
-
if (!typed) {
|
|
3387
|
-
// #2167: no height, but a note or a picture, is an honest answer: "I don't know it, look here".
|
|
3388
|
-
if (hasAnswerSource(`hb:${entry.questionId}`)) {
|
|
3389
|
-
submitHeightAnswers(entry, chosen.map((row) => ({ memberId: row.memberId, end: row.end, action: 'evidence' })), null, `hb:${entry.questionId}`);
|
|
3390
|
-
return;
|
|
3391
|
-
}
|
|
3392
|
-
entry.cardError = NO_HEIGHT_NO_SOURCE; repaintHeightCard(entry); return;
|
|
3393
|
-
}
|
|
3394
|
-
submitHeightAnswers(entry, chosen.map((row) => ({ memberId: row.memberId, end: row.end, action: 'type', typed })), null, `hb:${entry.questionId}`);
|
|
3395
|
-
};
|
|
3396
|
-
input.addEventListener('keydown', (event) => { if (event.key === 'Enter' && !event.isComposing) { event.preventDefault(); submit(); } });
|
|
3397
|
-
use.addEventListener('click', submit);
|
|
3398
|
-
field.append(input, use);
|
|
3399
|
-
bar.append(field);
|
|
3400
|
-
bar.append(paintAnswerSource(`hb:${entry.questionId}`, {
|
|
3401
|
-
requestId: entry.requestId, chatId: entry.chatId, repaint: () => repaintHeightCard(entry), label: `the ${n} selected ends`, instance: questionLabel,
|
|
3402
|
-
idFor: (what, extra) => `shell.chat-answer-${what}#${entry.questionId} bulk${extra ? ` ${extra}` : ''}`, busyReason, allowPictureOnly: false,
|
|
3403
|
-
}));
|
|
3404
|
-
return bar;
|
|
3405
|
-
}
|
|
3406
|
-
|
|
3407
|
-
function paintHeightRow(entry, row, open, selectable) {
|
|
3558
|
+
function paintHeightRow(entry, row, open) {
|
|
3408
3559
|
const key = heightEndKey(row);
|
|
3409
3560
|
const item = document.createElement('li'); item.className = 'ai-chat-height-row';
|
|
3410
3561
|
item.dataset.status = row.status;
|
|
@@ -3412,11 +3563,6 @@
|
|
|
3412
3563
|
const idFor = (what) => `shell.chat-height-${what}#${entry.questionId} ${row.memberId} ${row.endWord}`;
|
|
3413
3564
|
const sourceIdFor = (what, extra) => `shell.chat-answer-${what}#${entry.questionId} ${row.memberId} ${row.endWord}${extra ? ` ${extra}` : ''}`;
|
|
3414
3565
|
const labelLine = document.createElement('div'); labelLine.className = 'ai-chat-height-labelline';
|
|
3415
|
-
if (selectable) {
|
|
3416
|
-
labelLine.append(themedCheck(idFor('select'), instance, entry.selected.has(key), `Select ${row.label} to answer several ends at once`,
|
|
3417
|
-
entry.busy ? 'A height is still being saved — wait for it to finish' : null,
|
|
3418
|
-
(checked) => { if (checked) entry.selected.add(key); else entry.selected.delete(key); repaintHeightCard(entry); }));
|
|
3419
|
-
}
|
|
3420
3566
|
const label = document.createElement('div'); label.className = 'ai-chat-height-label'; label.textContent = row.label;
|
|
3421
3567
|
label.dataset.tip = row.label;
|
|
3422
3568
|
labelLine.append(label);
|
|
@@ -3452,11 +3598,8 @@
|
|
|
3452
3598
|
change.setAttribute('aria-label', picture ? `Answer the height for ${row.label} yourself instead` : `Change the height for ${row.label}`);
|
|
3453
3599
|
change.addEventListener('click', () => {
|
|
3454
3600
|
if (change.getAttribute('aria-disabled') === 'true') return;
|
|
3455
|
-
entry.changing.add(key);
|
|
3456
3601
|
if (!entry.drafts.has(key) && row.answer.how === 'typed') entry.drafts.set(key, row.answer.typed);
|
|
3457
|
-
|
|
3458
|
-
const card = ui.feed.querySelector(`[data-height-question="${CSS.escape(entry.key)}"]`);
|
|
3459
|
-
if (card) focusHeightControl(card, idFor('input'));
|
|
3602
|
+
reopenDrawingItem('height', entry, key);
|
|
3460
3603
|
});
|
|
3461
3604
|
done.append(change);
|
|
3462
3605
|
}
|
|
@@ -3470,61 +3613,6 @@
|
|
|
3470
3613
|
item.append(none);
|
|
3471
3614
|
return item;
|
|
3472
3615
|
}
|
|
3473
|
-
const busyReason = entry.busy ? 'A height is still being saved — wait for it to finish' : null;
|
|
3474
|
-
if (row.proposed) {
|
|
3475
|
-
const proposal = document.createElement('div'); proposal.className = 'ai-chat-height-proposal';
|
|
3476
|
-
const value = document.createElement('span'); value.textContent = `Proposed ${row.proposed.asRead}`;
|
|
3477
|
-
const confirm = heightActionButton('Confirm', idFor('confirm'), instance, 'ai-chat-filter-apply', busyReason);
|
|
3478
|
-
confirm.setAttribute('aria-label', `Confirm ${row.proposed.asRead} for ${row.label}`);
|
|
3479
|
-
confirm.addEventListener('click', () => {
|
|
3480
|
-
if (confirm.getAttribute('aria-disabled') === 'true') return;
|
|
3481
|
-
submitHeightAnswers(entry, [{ memberId: row.memberId, end: row.end, action: 'confirm', shown: row.proposed.value }], key);
|
|
3482
|
-
});
|
|
3483
|
-
proposal.append(value, confirm);
|
|
3484
|
-
item.append(proposal);
|
|
3485
|
-
if (row.fromEvidence) {
|
|
3486
|
-
// #1906 "see snap": the proposal is the READ's reading of the person's picture, said as such.
|
|
3487
|
-
const tag = document.createElement('div'); tag.className = 'ai-chat-setup-evidence';
|
|
3488
|
-
const t = document.createElement('span'); t.className = 'ai-chat-setup-tag';
|
|
3489
|
-
t.textContent = !row.inherited?.length ? 'THE READ’S READING OF YOUR NOTE' : 'THE READ’S READING OF YOUR PICTURE';
|
|
3490
|
-
tag.append(t, document.createTextNode(' Check it before you confirm.'));
|
|
3491
|
-
item.append(tag);
|
|
3492
|
-
}
|
|
3493
|
-
}
|
|
3494
|
-
const field = document.createElement('div'); field.className = 'ai-chat-height-field';
|
|
3495
|
-
const input = document.createElement('input');
|
|
3496
|
-
input.type = 'text'; input.className = 'ai-chat-height-input'; input.autocomplete = 'off'; input.spellcheck = false;
|
|
3497
|
-
input.dataset.commandId = idFor('input');
|
|
3498
|
-
input.dataset.commandInstanceLabel = instance;
|
|
3499
|
-
input.placeholder = entry.view?.units === 'mm' ? 'e.g. 4870 mm' : 'e.g. 15\'-11 3/4"';
|
|
3500
|
-
input.setAttribute('aria-label', `${row.proposed ? 'Or type the height' : 'Type the height'} for ${row.label}`);
|
|
3501
|
-
input.value = entry.drafts.get(key) || '';
|
|
3502
|
-
input.addEventListener('input', () => { entry.drafts.set(key, input.value); entry.rowErrors.delete(key); });
|
|
3503
|
-
if (busyReason) { input.readOnly = true; input.setAttribute('aria-disabled', 'true'); input.dataset.blockedReason = busyReason; }
|
|
3504
|
-
const use = heightActionButton('Use', idFor('use'), instance, row.proposed ? '' : 'ai-chat-filter-apply', busyReason);
|
|
3505
|
-
use.setAttribute('aria-label', `Use the typed height for ${row.label}`);
|
|
3506
|
-
const submitTyped = () => {
|
|
3507
|
-
if (use.getAttribute('aria-disabled') === 'true') return;
|
|
3508
|
-
const typed = input.value.trim();
|
|
3509
|
-
if (!typed) {
|
|
3510
|
-
// #2167: a note or a picture without a height is an answer too; the AI works the height out from it.
|
|
3511
|
-
if (hasAnswerSource(`h:${entry.questionId}:${key}`)) { submitHeightAnswers(entry, [{ memberId: row.memberId, end: row.end, action: 'evidence' }], key); return; }
|
|
3512
|
-
entry.rowErrors.set(key, NO_HEIGHT_NO_SOURCE); repaintHeightCard(entry); return;
|
|
3513
|
-
}
|
|
3514
|
-
submitHeightAnswers(entry, [{ memberId: row.memberId, end: row.end, action: 'type', typed }], key);
|
|
3515
|
-
};
|
|
3516
|
-
input.addEventListener('keydown', (event) => { if (event.key === 'Enter' && !event.isComposing) { event.preventDefault(); submitTyped(); } });
|
|
3517
|
-
use.addEventListener('click', submitTyped);
|
|
3518
|
-
field.append(input, use);
|
|
3519
|
-
item.append(field);
|
|
3520
|
-
item.append(paintAnswerSource(`h:${entry.questionId}:${key}`, {
|
|
3521
|
-
requestId: entry.requestId, chatId: entry.chatId, repaint: () => repaintHeightCard(entry), label: row.label, instance,
|
|
3522
|
-
idFor: sourceIdFor, inherited: row.inherited, busyReason, allowPictureOnly: true,
|
|
3523
|
-
onPictureOnly: () => submitHeightAnswers(entry, [{ memberId: row.memberId, end: row.end, action: 'evidence' }], key),
|
|
3524
|
-
}));
|
|
3525
|
-
const rowError = document.createElement('p'); rowError.className = 'ai-chat-height-error'; rowError.setAttribute('role', 'alert');
|
|
3526
|
-
rowError.textContent = entry.rowErrors.get(key) || '';
|
|
3527
|
-
item.append(rowError);
|
|
3528
3616
|
return item;
|
|
3529
3617
|
}
|
|
3530
3618
|
|
|
@@ -3533,7 +3621,13 @@
|
|
|
3533
3621
|
* several ends are answered at once (`sharedScope`).
|
|
3534
3622
|
*/
|
|
3535
3623
|
async function submitHeightAnswers(entry, answers, rowKey, sharedScope) {
|
|
3536
|
-
if (entry.busy) return;
|
|
3624
|
+
if (entry.busy) return false;
|
|
3625
|
+
const ownedSlot = drawingEntryCurrent(entry) && ui.approvalTray?.querySelector('.ai-chat-drawing-step')?.dataset.drawingStep;
|
|
3626
|
+
const ownedNode = ownedSlot ? ui.approvalTray.querySelector('.ai-chat-drawing-step') : null;
|
|
3627
|
+
const pendingFocusId = ownedNode?.contains(document.activeElement) ? document.activeElement.dataset.commandId : null;
|
|
3628
|
+
const failedField = ownedNode && ([...ownedNode.querySelectorAll('input')].find((field) => field.dataset.commandId === ownedNode.lastDrawingField) || ownedNode.querySelector('.ai-chat-ask-other-input'));
|
|
3629
|
+
const failedFieldId = failedField?.dataset.commandId, failedCaret = failedField ? textCaret(failedField) : null;
|
|
3630
|
+
let saved = false;
|
|
3537
3631
|
const scopeOf = (answer) => sharedScope || `h:${entry.questionId}:${heightEndKey(answer)}`;
|
|
3538
3632
|
const withSource = answers.map((answer) => ({ ...answer, ...answerSourcePayload(scopeOf(answer)) }));
|
|
3539
3633
|
entry.busy = true; entry.cardError = ''; if (rowKey) entry.rowErrors.delete(rowKey);
|
|
@@ -3542,11 +3636,40 @@
|
|
|
3542
3636
|
const result = await request(`/api/chat/height-questions/${encodeURIComponent(entry.requestId)}/${encodeURIComponent(entry.questionId)}/answers`, {
|
|
3543
3637
|
method: 'POST', body: JSON.stringify({ chatId: entry.chatId, answers: withSource }),
|
|
3544
3638
|
});
|
|
3639
|
+
const keptPictures = new Set([
|
|
3640
|
+
...withSource.flatMap((answer) => answer.evidence || []),
|
|
3641
|
+
...[entry.view, result.question].flatMap((view) => (view?.ends || []).flatMap((row) => [...row.answer?.evidence || [], ...row.inherited || []])).map((ref) => ref.attachmentId),
|
|
3642
|
+
]);
|
|
3545
3643
|
entry.view = result.question;
|
|
3644
|
+
saved = true;
|
|
3546
3645
|
for (const answer of answers) {
|
|
3547
3646
|
const key = heightEndKey(answer);
|
|
3548
3647
|
entry.changing.delete(key); entry.drafts.delete(key); entry.selected.delete(key);
|
|
3648
|
+
if (entry.activeItem === key) { entry.activeItem = null; entry.reopenedAt = 0; }
|
|
3549
3649
|
clearAnswerSource(scopeOf(answer));
|
|
3650
|
+
if (sharedScope) {
|
|
3651
|
+
const rowScope = `h:${entry.questionId}:${key}`, source = answerSources.get(rowScope);
|
|
3652
|
+
if (source) {
|
|
3653
|
+
source.note = '';
|
|
3654
|
+
for (const file of [...source.files]) {
|
|
3655
|
+
if (keptPictures.has(file.attachmentId)) {
|
|
3656
|
+
source.files = source.files.filter((held) => held !== file);
|
|
3657
|
+
if (file.url) URL.revokeObjectURL(file.url);
|
|
3658
|
+
continue;
|
|
3659
|
+
}
|
|
3660
|
+
await removeAnswerFile(rowScope, {
|
|
3661
|
+
requestId: entry.requestId, chatId: entry.chatId, repaint: () => repaintHeightCard(entry),
|
|
3662
|
+
removeFile: async (unused) => {
|
|
3663
|
+
try { await request(evidenceUrl(entry.requestId, unused.attachmentId), { method: 'DELETE', body: JSON.stringify({ chatId: entry.chatId }) }); }
|
|
3664
|
+
catch (error) { if (error?.code !== 'answer-evidence-cited') throw error; }
|
|
3665
|
+
},
|
|
3666
|
+
}, file);
|
|
3667
|
+
if (source.files.includes(file)) file.cleanupPending = true;
|
|
3668
|
+
}
|
|
3669
|
+
if (!source.files.length) clearAnswerSource(rowScope);
|
|
3670
|
+
else { source.open = true; source.error = `Unused pictures could not be removed: ${source.files.filter((file) => file.cleanupPending).map((file) => file.fileName).join(', ')}. Remove these pictures to retry.`; }
|
|
3671
|
+
}
|
|
3672
|
+
}
|
|
3550
3673
|
}
|
|
3551
3674
|
if (sharedScope) entry.bulkDraft = '';
|
|
3552
3675
|
} catch (error) {
|
|
@@ -3561,8 +3684,14 @@
|
|
|
3561
3684
|
entry.busy = false;
|
|
3562
3685
|
repaintHeightCard(entry);
|
|
3563
3686
|
settlePendingReload(entry, loadHeightQuestion);
|
|
3564
|
-
|
|
3687
|
+
const currentSlot = ui.approvalTray?.querySelector('.ai-chat-drawing-step');
|
|
3688
|
+
if (ownedSlot && drawingEntryCurrent(entry) && ownedSlot === currentSlot?.dataset.drawingStep
|
|
3689
|
+
&& pendingFocusId && currentSlot.contains(document.activeElement) && document.activeElement.dataset.commandId === pendingFocusId) {
|
|
3690
|
+
if (saved) focusNextHeightControl(entry);
|
|
3691
|
+
else if (failedFieldId) focusHeightControl(currentSlot, failedFieldId, failedCaret);
|
|
3692
|
+
}
|
|
3565
3693
|
}
|
|
3694
|
+
return saved;
|
|
3566
3695
|
}
|
|
3567
3696
|
|
|
3568
3697
|
// After an answer, keyboard focus moves to the next row still waiting, or to Tell the read.
|
|
@@ -3668,14 +3797,25 @@
|
|
|
3668
3797
|
ctx.repaint(); return;
|
|
3669
3798
|
}
|
|
3670
3799
|
for (const file of incoming) {
|
|
3800
|
+
if (answerSources.get(scope) !== source) break;
|
|
3671
3801
|
source.uploading += 1; ctx.repaint();
|
|
3672
3802
|
try {
|
|
3673
3803
|
const data = await fileBase64(file);
|
|
3674
|
-
|
|
3804
|
+
// #2223: the AI's question card keeps its files through its own person-only route (`ctx.upload`).
|
|
3805
|
+
const result = ctx.upload ? await ctx.upload(file, data) : await request(`/api/chat/answer-evidence/${encodeURIComponent(ctx.requestId)}`, {
|
|
3675
3806
|
method: 'POST', timeoutMs: 120000,
|
|
3676
3807
|
body: JSON.stringify({ chatId: ctx.chatId, fileName: file.name || 'screenshot.png', mediaType: file.type, data }),
|
|
3677
3808
|
});
|
|
3678
3809
|
const ref = result.evidence;
|
|
3810
|
+
if (answerSources.get(scope) !== source) {
|
|
3811
|
+
if (ctx.removeFile) {
|
|
3812
|
+
try { await ctx.removeFile(ref); }
|
|
3813
|
+
catch (error) {
|
|
3814
|
+
if (error?.code !== 'answer-evidence-unknown') console.warn('[chat] a closed question\u2019s unused picture could not be released', ref.attachmentId, error?.message);
|
|
3815
|
+
}
|
|
3816
|
+
}
|
|
3817
|
+
continue;
|
|
3818
|
+
}
|
|
3679
3819
|
source.files.push({ ...ref, url: file.type.startsWith('image/') ? URL.createObjectURL(file) : '' });
|
|
3680
3820
|
} catch (error) {
|
|
3681
3821
|
source.error = error?.message || `FloLess could not attach “${file.name}”. Try again.`;
|
|
@@ -3690,16 +3830,18 @@
|
|
|
3690
3830
|
const drop = () => {
|
|
3691
3831
|
source.files = source.files.filter((row) => row.attachmentId !== file.attachmentId);
|
|
3692
3832
|
if (file.url) URL.revokeObjectURL(file.url);
|
|
3693
|
-
source.
|
|
3833
|
+
const unused = source.files.filter((held) => held.cleanupPending);
|
|
3834
|
+
source.error = unused.length ? `Unused pictures could not be removed: ${unused.map((held) => held.fileName).join(', ')}. Remove these pictures to retry.` : '';
|
|
3694
3835
|
};
|
|
3695
3836
|
try {
|
|
3696
|
-
|
|
3837
|
+
if (ctx.removeFile) await ctx.removeFile(file);
|
|
3838
|
+
else await request(evidenceUrl(ctx.requestId, file.attachmentId), { method: 'DELETE', body: JSON.stringify({ chatId: ctx.chatId }) });
|
|
3697
3839
|
drop();
|
|
3698
3840
|
} catch (error) {
|
|
3699
3841
|
// Already gone on the server (review #1906): the chip goes too, or it would ride on every later
|
|
3700
3842
|
// answer and be refused each time, with the paperclip stuck at the file limit.
|
|
3701
3843
|
if (error?.code === 'answer-evidence-unknown') drop();
|
|
3702
|
-
else source.error = error?.message || 'FloLess could not remove that file. Try again.';
|
|
3844
|
+
else source.error = file.cleanupPending ? `Unused pictures could not be removed: ${source.files.filter((held) => held.cleanupPending).map((held) => held.fileName).join(', ')}. Remove these pictures to retry.` : error?.message || 'FloLess could not remove that file. Try again.';
|
|
3703
3845
|
}
|
|
3704
3846
|
ctx.repaint();
|
|
3705
3847
|
}
|
|
@@ -3781,7 +3923,7 @@
|
|
|
3781
3923
|
kept.append(lead, ...ctx.inherited.map((ref) => answerPictureChip(ctx.requestId, ref, ctx.idFor('picture-open', ref.attachmentId), ctx.instance)));
|
|
3782
3924
|
wrap.append(kept);
|
|
3783
3925
|
}
|
|
3784
|
-
const hasDraft = source.open || source.note || source.files.length || source.uploading;
|
|
3926
|
+
const hasDraft = ctx.alwaysOpen || source.open || source.note || source.files.length || source.uploading;
|
|
3785
3927
|
if (!hasDraft) {
|
|
3786
3928
|
const add = button('+ Add source', ctx.idFor('source'), 'ai-chat-answer-add');
|
|
3787
3929
|
add.dataset.commandInstanceLabel = ctx.instance;
|
|
@@ -3789,7 +3931,7 @@
|
|
|
3789
3931
|
add.dataset.tip = 'Say where your answer comes from: a note like “per 7/S-502”, or a screenshot or PDF';
|
|
3790
3932
|
add.addEventListener('click', () => {
|
|
3791
3933
|
source.open = true; ctx.repaint();
|
|
3792
|
-
[...(ui.feed?.querySelectorAll('[data-command-id]') || [])].find((node) => node.dataset.commandId === ctx.idFor('note'))?.focus({ preventScroll: true });
|
|
3934
|
+
[...(ui.approvalTray?.querySelectorAll('[data-command-id]') || []), ...(ui.feed?.querySelectorAll('[data-command-id]') || [])].find((node) => node.dataset.commandId === ctx.idFor('note'))?.focus({ preventScroll: true });
|
|
3793
3935
|
});
|
|
3794
3936
|
wrap.append(add);
|
|
3795
3937
|
return wrap;
|
|
@@ -3802,7 +3944,8 @@
|
|
|
3802
3944
|
note.dataset.commandId = ctx.idFor('note'); note.dataset.commandInstanceLabel = ctx.instance;
|
|
3803
3945
|
note.setAttribute('aria-label', `Source note for ${ctx.label}`);
|
|
3804
3946
|
note.value = source.note;
|
|
3805
|
-
note.
|
|
3947
|
+
if (ctx.busyReason) { note.readOnly = true; note.setAttribute('aria-disabled', 'true'); note.dataset.blockedReason = ctx.busyReason; note.dataset.tip = ctx.busyReason; }
|
|
3948
|
+
note.addEventListener('input', () => { source.note = note.value; ctx.onDraftChange?.(); });
|
|
3806
3949
|
const clip = document.createElement('button');
|
|
3807
3950
|
clip.type = 'button'; clip.className = 'ai-chat-answer-clip';
|
|
3808
3951
|
clip.dataset.commandId = ctx.idFor('attach'); clip.dataset.commandInstanceLabel = ctx.instance;
|
|
@@ -3816,16 +3959,16 @@
|
|
|
3816
3959
|
picker.type = 'file'; picker.multiple = true; picker.hidden = true; picker.accept = 'image/png,image/jpeg,image/webp,application/pdf';
|
|
3817
3960
|
picker.dataset.commandId = ctx.idFor('attach-input'); picker.dataset.commandInstanceLabel = ctx.instance;
|
|
3818
3961
|
picker.addEventListener('change', () => { const files = [...picker.files]; picker.value = ''; attachAnswerFiles(scope, ctx, files); });
|
|
3819
|
-
clip.addEventListener('click', () => picker.click());
|
|
3962
|
+
clip.addEventListener('click', () => { if (clip.getAttribute('aria-disabled') !== 'true') picker.click(); });
|
|
3820
3963
|
if (ctx.busyReason || source.files.length >= MAX_ANSWER_FILES) {
|
|
3821
3964
|
const why = ctx.busyReason || `An answer can carry at most ${MAX_ANSWER_FILES} files`;
|
|
3822
3965
|
clip.setAttribute('aria-disabled', 'true'); clip.dataset.blockedReason = why; clip.dataset.tip = why;
|
|
3823
|
-
clip.onclick = (event) => event.stopImmediatePropagation();
|
|
3824
3966
|
}
|
|
3825
3967
|
line.append(note, clip, picker);
|
|
3826
3968
|
box.append(line);
|
|
3827
3969
|
// Paste and drop, like the composer: a screenshot pasted while this box has focus attaches to the answer.
|
|
3828
3970
|
box.addEventListener('paste', (event) => {
|
|
3971
|
+
if (ctx.busyReason) return;
|
|
3829
3972
|
const files = [...(event.clipboardData?.files || [])];
|
|
3830
3973
|
if (files.length) { event.preventDefault(); attachAnswerFiles(scope, ctx, files); }
|
|
3831
3974
|
});
|
|
@@ -3833,6 +3976,7 @@
|
|
|
3833
3976
|
box.addEventListener('dragleave', () => box.classList.remove('drop'));
|
|
3834
3977
|
box.addEventListener('drop', (event) => {
|
|
3835
3978
|
box.classList.remove('drop');
|
|
3979
|
+
if (ctx.busyReason) return;
|
|
3836
3980
|
const files = [...(event.dataTransfer?.files || [])];
|
|
3837
3981
|
if (files.length) { event.preventDefault(); attachAnswerFiles(scope, ctx, files); }
|
|
3838
3982
|
});
|
|
@@ -3841,12 +3985,13 @@
|
|
|
3841
3985
|
for (const file of source.files) {
|
|
3842
3986
|
const chip = document.createElement('span'); chip.className = 'ai-chat-attachment';
|
|
3843
3987
|
if (file.url) { const img = document.createElement('img'); img.alt = ''; img.src = file.url; chip.append(img); }
|
|
3844
|
-
const name = document.createElement('span'); name.textContent = file.fileName;
|
|
3988
|
+
const name = document.createElement('span'); name.textContent = file.cleanupPending ? `Removal pending: ${file.fileName}` : file.fileName;
|
|
3845
3989
|
const remove = button('×', ctx.idFor('picture-remove', file.attachmentId));
|
|
3846
3990
|
remove.dataset.commandInstanceLabel = file.fileName;
|
|
3847
|
-
remove.setAttribute('aria-label', `Remove ${file.fileName} from this answer`);
|
|
3848
|
-
remove.dataset.tip = 'Remove from this answer';
|
|
3849
|
-
remove.
|
|
3991
|
+
remove.setAttribute('aria-label', file.cleanupPending ? `Retry removing unused picture ${file.fileName}` : `Remove ${file.fileName} from this answer`);
|
|
3992
|
+
remove.dataset.tip = file.cleanupPending ? 'Retry removing this unused picture' : 'Remove from this answer';
|
|
3993
|
+
if (ctx.busyReason) { remove.setAttribute('aria-disabled', 'true'); remove.dataset.blockedReason = ctx.busyReason; remove.dataset.tip = ctx.busyReason; }
|
|
3994
|
+
remove.addEventListener('click', () => { if (!ctx.busyReason) removeAnswerFile(scope, ctx, file); });
|
|
3850
3995
|
chip.append(name, remove); chips.append(chip);
|
|
3851
3996
|
}
|
|
3852
3997
|
if (source.uploading) {
|
|
@@ -3866,7 +4011,8 @@
|
|
|
3866
4011
|
box.append(only);
|
|
3867
4012
|
}
|
|
3868
4013
|
const error = document.createElement('p'); error.className = 'ai-chat-height-error'; error.setAttribute('role', 'alert');
|
|
3869
|
-
|
|
4014
|
+
const unused = source.files.filter((file) => file.cleanupPending);
|
|
4015
|
+
error.textContent = source.error || (unused.length ? `Unused pictures could not be removed: ${unused.map((file) => file.fileName).join(', ')}. Remove these pictures to retry.` : '');
|
|
3870
4016
|
box.append(error);
|
|
3871
4017
|
wrap.append(box);
|
|
3872
4018
|
return wrap;
|
|
@@ -3953,6 +4099,325 @@
|
|
|
3953
4099
|
* use exactly what is settled here, and asks again on a new card if anything conflicts.
|
|
3954
4100
|
*/
|
|
3955
4101
|
const setupCards = new Map();
|
|
4102
|
+
|
|
4103
|
+
/** Drawing answers share the question slot; their server-owned records remain in the transcript. */
|
|
4104
|
+
function drawingRows(kind, entry) { return kind === 'setup' ? entry.view?.items || [] : entry.view?.ends || []; }
|
|
4105
|
+
function drawingRowKey(kind, row) { return kind === 'setup' ? row.key : heightEndKey(row); }
|
|
4106
|
+
function drawingRowOpen(kind, entry, row) {
|
|
4107
|
+
if (!entry.view?.open || row.status === 'superseded' || row.frozen) return false;
|
|
4108
|
+
const key = drawingRowKey(kind, row);
|
|
4109
|
+
if (entry.changing.has(key)) return true;
|
|
4110
|
+
return kind === 'setup' ? row.status === 'open' : !row.answer;
|
|
4111
|
+
}
|
|
4112
|
+
function drawingEntryCurrent(entry) { return entry.chatId === state.chat?.chatId; }
|
|
4113
|
+
function drawingSlotRepaint() {
|
|
4114
|
+
paintDrawingQuestionSlot();
|
|
4115
|
+
}
|
|
4116
|
+
function reopenDrawingItem(kind, entry, key) {
|
|
4117
|
+
const row = drawingRows(kind, entry).find((row) => drawingRowKey(kind, row) === key);
|
|
4118
|
+
if (entry.busy || !entry.view?.open || !row || row.frozen || row.status === 'superseded') return;
|
|
4119
|
+
entry.changing.add(key); entry.activeItem = key; entry.finishActive = false; entry.reopenedAt = (state.drawingActivationOrder = (state.drawingActivationOrder || 0) + 1);
|
|
4120
|
+
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; }
|
|
4121
|
+
entry.slotPhase = 'row';
|
|
4122
|
+
(kind === 'setup' ? repaintSetupCard : repaintHeightCard)(entry);
|
|
4123
|
+
drawingSlotRepaint();
|
|
4124
|
+
}
|
|
4125
|
+
function paintDrawingHistory(kind, entry, eventId, sequence) {
|
|
4126
|
+
entry.eventId = eventId || entry.eventId || ''; entry.sequence = Number(sequence || entry.sequence || 0);
|
|
4127
|
+
const card = document.createElement('section');
|
|
4128
|
+
card.className = `ai-chat-filter-card ai-chat-height-card${kind === 'setup' ? ' ai-chat-setup-card' : ''}`;
|
|
4129
|
+
card.dataset[kind === 'setup' ? 'setupQuestion' : 'heightQuestion'] = entry.key;
|
|
4130
|
+
card.dataset.eventId = eventId || ''; card.dataset.eventSequence = sequence || '';
|
|
4131
|
+
const title = kind === 'setup' ? 'Read setup' : 'Confirm member heights';
|
|
4132
|
+
card.setAttribute('aria-label', entry.view?.n ? `${title}, question ${entry.view.n}` : title);
|
|
4133
|
+
const rows = drawingRows(kind, entry), live = rows.filter((row) => row.status !== 'superseded');
|
|
4134
|
+
const answered = live.filter((row) => row.answer);
|
|
4135
|
+
const settled = kind === 'setup' ? live.filter(setupSettled).length : live.filter((row) => row.status === 'confirmed' || row.status === 'typed').length;
|
|
4136
|
+
const allAnswered = live.length > 0 && answered.length === live.length;
|
|
4137
|
+
card.dataset.state = !entry.view ? (entry.finished ? 'closed' : 'loading') : !entry.view.open ? 'closed'
|
|
4138
|
+
: allAnswered ? (settled === live.length ? 'answered' : 'waiting-for-read') : 'open';
|
|
4139
|
+
const head = document.createElement('div'); head.className = 'ai-chat-filter-card-head';
|
|
4140
|
+
const heading = document.createElement('strong'); heading.textContent = title;
|
|
4141
|
+
const chip = document.createElement('span'); chip.className = 'ai-chat-filter-state'; chip.textContent = card.dataset.state;
|
|
4142
|
+
head.append(heading, chip); card.append(head);
|
|
4143
|
+
if (!entry.view) {
|
|
4144
|
+
const note = document.createElement('p'); note.className = 'ai-chat-filter-note';
|
|
4145
|
+
note.textContent = entry.finished ? CARD_FINISHED_TEXT : entry.loadError || `Loading ${kind === 'setup' ? 'the read setup' : 'the heights this read is asking about'}…`;
|
|
4146
|
+
card.append(note);
|
|
4147
|
+
if (entry.loadError) {
|
|
4148
|
+
const retry = heightActionButton('Try again', `shell.chat-${kind}-retry#${entry.questionId}`, title, '');
|
|
4149
|
+
retry.addEventListener('click', () => { entry.loadError = ''; (kind === 'setup' ? loadSetupQuestion : loadHeightQuestion)(entry); }); card.append(retry);
|
|
4150
|
+
}
|
|
4151
|
+
} else {
|
|
4152
|
+
const count = document.createElement('p'); count.className = 'ai-chat-height-count'; count.setAttribute('aria-live', 'polite');
|
|
4153
|
+
count.textContent = `${kind === 'setup' ? settled : answered.length} of ${live.length} ${kind === 'setup' ? 'settled' : 'answered'}`; card.append(count);
|
|
4154
|
+
if (kind === 'height' && entry.view.open) {
|
|
4155
|
+
const note = document.createElement('p'); note.className = 'ai-chat-filter-note';
|
|
4156
|
+
note.textContent = rows.some((row) => row.inModel)
|
|
4157
|
+
? '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.'
|
|
4158
|
+
: 'Only you can answer these heights. What you confirm or type goes straight into the model.';
|
|
4159
|
+
card.append(note);
|
|
4160
|
+
}
|
|
4161
|
+
if (entry.view.open && allAnswered) {
|
|
4162
|
+
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);
|
|
4163
|
+
next.dataset.tip = 'Choose whether to put the message in the box or send it now';
|
|
4164
|
+
next.addEventListener('click', () => {
|
|
4165
|
+
if (entry.busy) return;
|
|
4166
|
+
for (const other of [...setupCards.values(), ...heightCards.values()]) other.finishActive = false;
|
|
4167
|
+
entry.finishActive = true; entry.reopenedAt = (state.drawingActivationOrder = (state.drawingActivationOrder || 0) + 1); drawingSlotRepaint();
|
|
4168
|
+
});
|
|
4169
|
+
card.append(next);
|
|
4170
|
+
}
|
|
4171
|
+
const list = document.createElement('ol'); list.className = 'ai-chat-height-rows';
|
|
4172
|
+
for (const row of rows) {
|
|
4173
|
+
const key = drawingRowKey(kind, row);
|
|
4174
|
+
let item;
|
|
4175
|
+
if (row.answer || row.status === 'superseded' || row.frozen) {
|
|
4176
|
+
// Existing answer/source renderers retain pictures, provenance and recovery wording. There is only one place to answer.
|
|
4177
|
+
const changing = entry.changing.has(key); entry.changing.delete(key);
|
|
4178
|
+
item = kind === 'setup' ? paintSetupRow(entry, row, Boolean(entry.view.open)) : paintHeightRow(entry, row, Boolean(entry.view.open), false);
|
|
4179
|
+
if (changing) entry.changing.add(key);
|
|
4180
|
+
} else {
|
|
4181
|
+
item = document.createElement('li'); item.className = 'ai-chat-height-row'; item.dataset.status = row.status; item.dataset.key = key;
|
|
4182
|
+
const label = document.createElement('span'); label.textContent = row.label || (row.kind === 'origin' ? 'Model origin' : viewName(row)); item.append(label);
|
|
4183
|
+
if (entry.view.open) {
|
|
4184
|
+
const answer = heightActionButton('Answer', `shell.chat-${kind}-change#${entry.questionId} ${key}`, label.textContent, 'ai-chat-height-change', null);
|
|
4185
|
+
answer.addEventListener('click', () => reopenDrawingItem(kind, entry, key)); item.append(answer);
|
|
4186
|
+
}
|
|
4187
|
+
}
|
|
4188
|
+
list.append(item);
|
|
4189
|
+
}
|
|
4190
|
+
card.append(list);
|
|
4191
|
+
}
|
|
4192
|
+
const unused = kind === 'height' ? drawingRows(kind, entry).filter((row) => answerSources.get(`h:${entry.questionId}:${heightEndKey(row)}`)?.files.some((file) => file.cleanupPending)) : [];
|
|
4193
|
+
const cleanup = unused.length ? `Your heights were saved. Some unused pictures could not be removed. Choose Change for each listed end, then Remove on its unused pictures: ${unused.map((row) => `${row.label} · ${row.memberId} · ${heightEndWord(row)}`).join('; ')}. You do not need to submit the heights again.` : '';
|
|
4194
|
+
const error = document.createElement('p'); error.className = 'ai-chat-height-error'; error.setAttribute('role', 'alert'); error.textContent = [entry.cardError, cleanup].filter(Boolean).join(' '); card.append(error);
|
|
4195
|
+
drawingSlotRepaint();
|
|
4196
|
+
return card;
|
|
4197
|
+
}
|
|
4198
|
+
function drawingSource(kind, entry, scope, label, idFor, row, onDraftChange) {
|
|
4199
|
+
return paintAnswerSource(scope, { requestId: entry.requestId, chatId: entry.chatId, repaint: () => { (kind === 'setup' ? repaintSetupCard : repaintHeightCard)(entry); drawingSlotRepaint(); },
|
|
4200
|
+
removeFile: (file) => request(`/api/chat/answer-evidence/${encodeURIComponent(entry.requestId)}/${encodeURIComponent(file.attachmentId)}`, { method: 'DELETE', body: JSON.stringify({ chatId: entry.chatId }) }),
|
|
4201
|
+
label, instance: label, idFor, inherited: row?.inherited, busyReason: entry.busy ? 'An answer is still being saved — wait for it to finish' : null,
|
|
4202
|
+
allowPictureOnly: false, onDraftChange, alwaysOpen: Boolean(entry.slotDrafts?.get(entry.slotQuestionKey)?.rows[0]?.otherOpen) });
|
|
4203
|
+
}
|
|
4204
|
+
function drawingStep(kind, entry) {
|
|
4205
|
+
const open = drawingRows(kind, entry).filter((row) => drawingRowOpen(kind, entry, row));
|
|
4206
|
+
const row = open.find((row) => drawingRowKey(kind, row) === entry.activeItem) || open[0];
|
|
4207
|
+
if (!row) {
|
|
4208
|
+
const live = drawingRows(kind, entry).filter((row) => row.status !== 'superseded');
|
|
4209
|
+
if (!entry.view?.open || !live.length || !live.every((row) => row.answer)) return null;
|
|
4210
|
+
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,
|
|
4211
|
+
hint: 'Tell the read puts a message in the box. Send to the read sends it now.',
|
|
4212
|
+
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' }] },
|
|
4213
|
+
commit: async (answer) => { const text = kind === 'setup' ? setupTellText(entry) : heightTellText(entry); const repaint = kind === 'setup' ? repaintSetupCard : repaintHeightCard;
|
|
4214
|
+
if (answer.choices[0] === 0) tellReadAnswered(entry, text, repaint); else await sendToReadAnswered(entry, text, repaint); return false; } };
|
|
4215
|
+
}
|
|
4216
|
+
if (kind === 'height' && open.length > 1 && entry.slotPhase !== 'row') return drawingHeightBatch(entry, open);
|
|
4217
|
+
const key = drawingRowKey(kind, row), scope = `${kind === 'setup' ? 's' : 'h'}:${entry.questionId}:${key}`;
|
|
4218
|
+
const label = row.label || (row.kind === 'origin' ? 'the model origin' : viewName(row));
|
|
4219
|
+
const q = { id: key, header: kind === 'setup' ? 'Read setup' : 'Height', question: label, options: [], recommended: null, context: [] };
|
|
4220
|
+
const live = drawingRows(kind, entry).filter((item) => item.status !== 'superseded');
|
|
4221
|
+
q.progress = { index: live.indexOf(row), total: live.length };
|
|
4222
|
+
const choices = [];
|
|
4223
|
+
if (kind === 'height') {
|
|
4224
|
+
if (row.inModel) {
|
|
4225
|
+
q.context.push(
|
|
4226
|
+
`${row.inModel.profile || ''} · ${row.memberId} · ${heightEndWord(row)}. ${heightInModelText(row.inModel, entry.view.units)} ${HEIGHT_PROPOSED_TEXT}`
|
|
4227
|
+
);
|
|
4228
|
+
}
|
|
4229
|
+
else q.context.push(`${row.memberId} · ${heightEndWord(row)}. Only you can answer. What you confirm or type goes straight into the model.`);
|
|
4230
|
+
if (row.proposed) { q.options.push({ shown: `Confirm ${row.proposed.asRead}`, description: 'Use the value proposed for this member end' }); choices.push({ memberId: row.memberId, end: row.end, action: 'confirm', shown: row.proposed.value }); q.recommended = 0; }
|
|
4231
|
+
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.');
|
|
4232
|
+
} else if (row.kind === 'origin') {
|
|
4233
|
+
q.question = 'Which grid crossing is the model’s origin (0, 0)?'; q.layout = 'grid'; q.confirmSelection = true;
|
|
4234
|
+
row.choices.forEach((choice, index) => { q.options.push({ shown: originText(choice), description: 'A straight grid crossing in the model', confirmLabel: `Confirm ${originText(choice)} as the model origin`, tag: row.proposed === index ? 'THE READ SUGGESTS' : '' }); choices.push({ key, action: 'confirm', choice: `c${index}`, shown: originText(choice) }); });
|
|
4235
|
+
row.offGrid.forEach((point, index) => { const target = row.choices[point.same]; q.options.push({ shown: point.as, description: 'Not a straight grid line; check the read’s mapping', confirmLabel: `Confirm ${originText(target)} as the model origin`, statement: `${point.as} is not a straight grid line in the model. The read says it is the same point as ${originText(target)} (${point.why}). This is the read’s claim; FloLess has not checked it.` }); choices.push({ key, action: 'confirm', choice: `o${index}`, shown: originText(target) }); });
|
|
4236
|
+
q.recommended = Number.isInteger(row.proposed) ? row.proposed : null;
|
|
4237
|
+
if (row.fromEvidence) q.context.push('The read’s reading of your picture. Check it before you confirm.');
|
|
4238
|
+
} else {
|
|
4239
|
+
if (row.clue) q.context.push(row.clue);
|
|
4240
|
+
if (row.noSingleLevel) q.context.push(`No single level on the drawings: ${row.noSingleLevel.why}`);
|
|
4241
|
+
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}`,
|
|
4242
|
+
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 }); });
|
|
4243
|
+
}
|
|
4244
|
+
if (kind === 'setup' && row.kind !== 'scale') { q.options.push({ shown: row.kind === 'origin' ? 'None of these' : 'No single level', description: 'Tell the read what to use instead', requiresNote: { placeholder: 'Add a short reason', max: MAX_ANSWER_NOTE } }); choices.push({ key, action: 'none' }); }
|
|
4245
|
+
if (kind === 'setup') { const banner = setupConflictBanner(row); if (banner) q.context.push(banner.textContent); }
|
|
4246
|
+
const controlKey = kind === 'height' ? `${row.memberId} ${row.endWord}` : key;
|
|
4247
|
+
const idFor = (what, extra) => `shell.chat-answer-${what}#${entry.questionId} ${controlKey}${extra === undefined ? '' : ` ${extra}`}`;
|
|
4248
|
+
const previous = live.slice(0, live.indexOf(row)).filter((item) => !item.frozen).at(-1);
|
|
4249
|
+
const backToMode = kind === 'height' && !previous && open.length > 1;
|
|
4250
|
+
return { key, question: q, scope, row, label, actions: choices, backToMode,
|
|
4251
|
+
back: previous ? () => reopenDrawingItem(kind, entry, drawingRowKey(kind, previous)) : backToMode ? () => { entry.slotPhase = null; entry.activeItem = null; entry.slotSig = null; drawingSlotRepaint(); } : null,
|
|
4252
|
+
source: (_index, onDraftChange) => drawingSource(kind, entry, scope, label, idFor, row, onDraftChange),
|
|
4253
|
+
validate: (_step, draft) => {
|
|
4254
|
+
const answer = draft.rows[0]; if (answer.choices.length) return '';
|
|
4255
|
+
if (answer.other.trim()) return '';
|
|
4256
|
+
if (kind === 'height' && hasAnswerSource(scope)) return '';
|
|
4257
|
+
return answerSource(scope).files.length ? '' : kind === 'setup' ? 'Type a value, or attach a picture first.' : NO_HEIGHT_NO_SOURCE;
|
|
4258
|
+
},
|
|
4259
|
+
commit: async (answer) => {
|
|
4260
|
+
let payload;
|
|
4261
|
+
if (answer.choices.length) { payload = { ...choices[answer.choices[0]] }; if (payload.action === 'none') payload.note = answer.reason; }
|
|
4262
|
+
else if (answer.other) payload = kind === 'setup' ? { key, action: 'type', typed: answer.other } : { memberId: row.memberId, end: row.end, action: 'type', typed: answer.other };
|
|
4263
|
+
else payload = kind === 'setup' ? { key, action: 'evidence' } : { memberId: row.memberId, end: row.end, action: 'evidence' };
|
|
4264
|
+
return kind === 'setup' ? submitSetupAnswers(entry, [payload], key) : submitHeightAnswers(entry, [payload], key);
|
|
4265
|
+
} };
|
|
4266
|
+
}
|
|
4267
|
+
function drawingHeightBatch(entry, rows) {
|
|
4268
|
+
const base = { header: 'Heights', allowOther: false, id: 'batch', recommended: null };
|
|
4269
|
+
if (!entry.slotPhase) {
|
|
4270
|
+
const confirmable = rows.every((row) => !row.answer && row.proposed);
|
|
4271
|
+
const scope = `hb:${entry.questionId}`, label = `all ${rows.length} proposed member ends`;
|
|
4272
|
+
const idFor = (what, extra) => `shell.chat-answer-${what}#${entry.questionId} bulk${extra === undefined ? '' : ` ${extra}`}`;
|
|
4273
|
+
const inherited = [...new Map(rows.flatMap((row) => row.inherited || []).map((ref) => [ref.attachmentId, ref])).values()];
|
|
4274
|
+
const options = [];
|
|
4275
|
+
if (confirmable) options.push({ shown: `Confirm all ${rows.length} proposed heights`, description: 'Save the values listed above, one for each member end' });
|
|
4276
|
+
options.push({ shown: 'Answer several together', description: 'Choose ends from any group and give them one value or source' }, { shown: 'Answer one by one', description: 'Answer each member end separately' });
|
|
4277
|
+
return { key: 'batch-intro', scope: confirmable ? scope : null, label,
|
|
4278
|
+
source: confirmable ? (_index, onDraftChange) => drawingSource('height', entry, scope, label, idFor, { inherited }, onDraftChange) : null,
|
|
4279
|
+
question: { ...base, question: 'How would you like to answer these heights?', options, recommended: confirmable ? 0 : null,
|
|
4280
|
+
hint: confirmable ? 'Confirm all saves these values. The other choices only choose how to answer.' : 'Choose how to answer; no heights are saved yet.',
|
|
4281
|
+
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) => {
|
|
4282
|
+
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);
|
|
4283
|
+
entry.slotPhase = answer.choices[0] === options.length - 1 ? 'row' : 'select'; return true;
|
|
4284
|
+
} };
|
|
4285
|
+
}
|
|
4286
|
+
if (entry.slotPhase === 'select') {
|
|
4287
|
+
const groups = new Map();
|
|
4288
|
+
for (const row of rows) { const members = groups.get(row.group) || []; members.push(row); groups.set(row.group, members); }
|
|
4289
|
+
const ordered = [...groups.values()].flat();
|
|
4290
|
+
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)}` })) },
|
|
4291
|
+
initial: ordered.map((row, index) => entry.selected.size ? entry.selected.has(heightEndKey(row)) ? index : -1 : index).filter((index) => index >= 0),
|
|
4292
|
+
back: () => { entry.slotPhase = null; entry.slotSig = null; drawingSlotRepaint(); },
|
|
4293
|
+
commit: async (answer) => { entry.selected = new Set(answer.choices.map((index) => heightEndKey(ordered[index]))); entry.slotPhase = 'value'; return true; } };
|
|
4294
|
+
}
|
|
4295
|
+
const chosen = rows.filter((row) => entry.selected.has(heightEndKey(row)));
|
|
4296
|
+
if (!chosen.length) { entry.slotPhase = 'select'; return drawingHeightBatch(entry, rows); }
|
|
4297
|
+
const shared = chosen.every((row) => row.proposed && row.proposed.value === chosen[0].proposed?.value);
|
|
4298
|
+
const scope = `hb:${entry.questionId}`, label = `${chosen.length} selected member ends`, idFor = (what, extra) => `shell.chat-answer-${what}#${entry.questionId} bulk${extra === undefined ? '' : ` ${extra}`}`;
|
|
4299
|
+
const inherited = [...new Map(chosen.flatMap((row) => row.inherited || []).map((ref) => [ref.attachmentId, ref])).values()];
|
|
4300
|
+
const context = chosen.filter((row) => row.inModel).map((row) => `${row.label}: ${row.inModel.profile || ''}. ${heightInModelText(row.inModel, entry.view.units)} ${HEIGHT_PROPOSED_TEXT}`);
|
|
4301
|
+
if (chosen.some((row) => row.fromEvidence)) context.push(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.');
|
|
4302
|
+
return { key: 'batch-value', scope, label, back: () => { entry.slotPhase = 'select'; entry.slotSig = null; drawingSlotRepaint(); },
|
|
4303
|
+
question: { ...base, allowOther: true, context, question: `What height should the ${chosen.length} selected ends use?`,
|
|
4304
|
+
options: shared ? [{ shown: `Confirm ${chosen[0].proposed.asRead} for ${chosen.length}`, description: 'Every selected end has this same proposed value' }] : [], recommended: shared ? 0 : null },
|
|
4305
|
+
source: (_index, onDraftChange) => drawingSource('height', entry, scope, label, idFor, { inherited }, onDraftChange), validate: (_step, draft) => draft.rows[0].choices.length || draft.rows[0].other.trim() || hasAnswerSource(scope) ? '' : NO_HEIGHT_NO_SOURCE,
|
|
4306
|
+
commit: async (answer) => { const answers = chosen.map((row) => ({ memberId: row.memberId, end: row.end, ...(answer.choices.length ? { action: 'confirm', shown: row.proposed.value } : answer.other ? { action: 'type', typed: answer.other } : { action: 'evidence' }) }));
|
|
4307
|
+
const saved = await submitHeightAnswers(entry, answers, null, scope);
|
|
4308
|
+
if (saved) { entry.slotPhase = null; entry.slotDrafts?.delete('batch-value'); entry.slotDrafts?.delete('batch-select'); }
|
|
4309
|
+
return saved; } };
|
|
4310
|
+
}
|
|
4311
|
+
function paintDrawingQuestionSlot() {
|
|
4312
|
+
const tray = ui.approvalTray; if (!tray || !window.FlolessQuestionCard) return false;
|
|
4313
|
+
const showing = tray.querySelector('.ai-chat-drawing-step');
|
|
4314
|
+
const heldFocus = showing?.contains(document.activeElement) ? document.activeElement : null;
|
|
4315
|
+
if (state.chat?.pendingApproval || tray.querySelector('.ai-chat-approval:not(.ai-chat-approval-scope):not(.ai-chat-drawing-step)')) { showing?.remove(); return false; }
|
|
4316
|
+
const entries = [...setupCards.values()].map((entry) => ({ kind: 'setup', entry })).concat([...heightCards.values()].map((entry) => ({ kind: 'height', entry })))
|
|
4317
|
+
.filter(({ entry }) => drawingEntryCurrent(entry) && entry.view?.open && !entry.reloadPending && !entry.loading)
|
|
4318
|
+
.sort((a, b) => ((b.entry.finishActive || b.entry.changing.has(b.entry.activeItem)) ? b.entry.reopenedAt || 0 : 0)
|
|
4319
|
+
- ((a.entry.finishActive || a.entry.changing.has(a.entry.activeItem)) ? a.entry.reopenedAt || 0 : 0) || a.entry.sequence - b.entry.sequence);
|
|
4320
|
+
const candidates = entries.map(({ kind, entry }) => ({ kind, entry, step: drawingStep(kind, entry) })).filter(({ step }) => step);
|
|
4321
|
+
const units = drawingUnitsCandidate(); if (units) candidates.push(units);
|
|
4322
|
+
let chosen = candidates.find(({ entry, step }) => entry.finishActive && step.key === 'finish') || candidates.find(({ step }) => step.key !== 'finish') || candidates[0];
|
|
4323
|
+
if (heldFocus && personIsTyping()) {
|
|
4324
|
+
const current = candidates.find(({ entry, step }) => `${entry.chatId}/${entry.key}/${step.key}` === showing.dataset.drawingStep);
|
|
4325
|
+
const activated = chosen?.entry.finishActive || (chosen?.entry.reopenedAt || 0) > (current?.entry.reopenedAt || 0);
|
|
4326
|
+
if (current && !activated) chosen = current;
|
|
4327
|
+
}
|
|
4328
|
+
if (!chosen) { showing?.remove(); return false; }
|
|
4329
|
+
const { kind, entry, step } = chosen, key = `${entry.chatId}/${entry.key}/${step.key}`;
|
|
4330
|
+
if (showing && showing.dataset.drawingStep !== key) showing.remove();
|
|
4331
|
+
entry.slotDrafts ??= new Map();
|
|
4332
|
+
let draft = entry.slotDrafts.get(step.key);
|
|
4333
|
+
if (!draft) {
|
|
4334
|
+
draft = window.FlolessQuestionCard.createDraft([step.question]);
|
|
4335
|
+
if (step.initial) draft.rows[0].choices = step.initial;
|
|
4336
|
+
if (step.row?.answer?.how === 'typed' && entry.changing.has(step.key)) { draft.rows[0].otherOpen = true; draft.rows[0].other = step.row.answer.typed; }
|
|
4337
|
+
entry.slotDrafts.set(step.key, draft);
|
|
4338
|
+
}
|
|
4339
|
+
const choiceSignature = JSON.stringify(step.question.options);
|
|
4340
|
+
if (draft.choiceSignature && draft.choiceSignature !== choiceSignature) draft.rows[0].choices = [];
|
|
4341
|
+
draft.choiceSignature = choiceSignature;
|
|
4342
|
+
const source = step.scope ? answerSource(step.scope) : null;
|
|
4343
|
+
entry.slotQuestionKey = step.key;
|
|
4344
|
+
const sig = JSON.stringify([key, entry.view, entry.busy, entry.cardError, [...entry.rowErrors], [...entry.changing], [...entry.selected || []], entry.slotPhase,
|
|
4345
|
+
// Typing refreshes Submit availability/carrier in place; note text must not invalidate the live field on a poll.
|
|
4346
|
+
source && [source.open, source.files.map((file) => file.attachmentId), source.uploading, source.error], draft.pending, draft.rows[0].choices, draft.rows[0].otherOpen]);
|
|
4347
|
+
const node = entry.slotNode || document.createElement('section'); entry.slotNode = node;
|
|
4348
|
+
if (node.isConnected && entry.slotSig === sig) return true;
|
|
4349
|
+
const editingSelections = [...node.querySelectorAll('input[data-command-id]')].map((field) => ({ id: field.dataset.commandId, caret: textCaret(field) })).filter(({ caret }) => caret);
|
|
4350
|
+
const focused = node.contains(document.activeElement) ? document.activeElement : heldFocus;
|
|
4351
|
+
const focusId = focused?.dataset.commandId, caret = focused ? textCaret(focused) : null;
|
|
4352
|
+
const freshStep = node.dataset.drawingStep !== key;
|
|
4353
|
+
const sameStepScroll = freshStep ? null : tray.scrollTop;
|
|
4354
|
+
if (freshStep) { delete node.dataset.armedAt; node.lastDrawingField = null; }
|
|
4355
|
+
if (!node.drawingFieldFocus) {
|
|
4356
|
+
node.drawingFieldFocus = (event) => { if (event.target.tagName === 'INPUT' && (event.target.type === 'text' || !event.target.type)) node.lastDrawingField = event.target.dataset.commandId; };
|
|
4357
|
+
node.addEventListener('focusin', node.drawingFieldFocus);
|
|
4358
|
+
}
|
|
4359
|
+
node.className = 'ai-chat-approval ai-chat-ask-card ai-chat-drawing-step'; node.dataset.drawingStep = key;
|
|
4360
|
+
if (!node.isConnected) tray.append(node);
|
|
4361
|
+
window.FlolessQuestionCard.paint(node, { id: encodeURIComponent(key), questions: [step.question], draft, mode: 'per-step', busy: entry.busy ? 'Saving your answer…' : '', error: entry.rowErrors.get(step.key) || entry.cardError,
|
|
4362
|
+
source: step.source, back: step.back, validate: step.validate, files: source ? { list: () => source.files, uploading: () => source.uploading, error: () => source.error,
|
|
4363
|
+
attach: (_index, files) => attachAnswerFiles(step.scope, { requestId: entry.requestId, chatId: entry.chatId, repaint: drawingSlotRepaint,
|
|
4364
|
+
removeFile: (file) => request(`/api/chat/answer-evidence/${encodeURIComponent(entry.requestId)}/${encodeURIComponent(file.attachmentId)}`, { method: 'DELETE', body: JSON.stringify({ chatId: entry.chatId }) }) }, files),
|
|
4365
|
+
remove: (_index, file) => removeAnswerFile(step.scope, { requestId: entry.requestId, chatId: entry.chatId, repaint: drawingSlotRepaint }, file) } : null,
|
|
4366
|
+
carrier: (what, _index, extra) => drawingCarrier(kind, entry, step, draft, what, extra),
|
|
4367
|
+
repaint: () => { entry.slotSig = null; drawingSlotRepaint(); }, commitStep: async (_index, answer) => { const saved = await step.commit(answer); entry.slotSig = null; return saved; },
|
|
4368
|
+
});
|
|
4369
|
+
entry.slotSig = sig;
|
|
4370
|
+
// Rebuilding the same question temporarily shrinks the tray and clamps its scroll position.
|
|
4371
|
+
if (sameStepScroll !== null) tray.scrollTop = sameStepScroll;
|
|
4372
|
+
for (const { id, caret } of editingSelections) {
|
|
4373
|
+
const field = [...node.querySelectorAll('input[data-command-id]')].find((control) => control.dataset.commandId === id);
|
|
4374
|
+
field?.setSelectionRange?.(Math.min(caret.start, field.value.length), Math.min(caret.end, field.value.length), caret.direction);
|
|
4375
|
+
}
|
|
4376
|
+
if (focusId) {
|
|
4377
|
+
focusHeightControl(node, focusId, caret);
|
|
4378
|
+
if (![...node.querySelectorAll('[data-command-id]')].some((control) => control.dataset.commandId === focusId)) window.FlolessQuestionCard.focusCursor(node);
|
|
4379
|
+
} else if (freshStep && !personIsTyping()) window.FlolessQuestionCard.focusCursor(node);
|
|
4380
|
+
return true;
|
|
4381
|
+
}
|
|
4382
|
+
function drawingCarrier(kind, entry, step, draft, what, extra) {
|
|
4383
|
+
const prefix = kind === 'setup' ? 'shell.chat-setup' : 'shell.chat-height';
|
|
4384
|
+
const rowKey = step.row && kind === 'height' ? `${step.row.memberId} ${step.row.endWord}` : step.key;
|
|
4385
|
+
let name = what, suffix = rowKey, instance = step.label || step.question.header;
|
|
4386
|
+
if (kind === 'units') return { id: `shell.chat-units-choose#${extra === 0 ? 'ft-in' : 'mm'}`, instance: extra === 0 ? 'feet and inches' : 'metric (mm)' };
|
|
4387
|
+
if (step.key === 'finish') name = extra === 0 ? 'tell-read' : 'send-read';
|
|
4388
|
+
else if (what === 'option') {
|
|
4389
|
+
if (step.key === 'batch-intro') { name = extra === 0 && step.question.recommended === 0 ? 'confirm-all' : 'mode'; if (name === 'mode') suffix += ` ${extra}`; }
|
|
4390
|
+
else if (step.key === 'batch-select') { name = 'select'; const row = step.rows[extra]; suffix = `${row.memberId} ${row.endWord}`; instance = row.label; }
|
|
4391
|
+
else if (step.key === 'batch-value') name = 'bulk-confirm';
|
|
4392
|
+
else if (step.row?.kind === 'origin' && step.actions[extra]?.action === 'confirm') { name = 'origin-choice'; suffix += ` ${step.actions[extra].choice}`; instance = step.question.options[extra].shown; }
|
|
4393
|
+
else if (step.actions?.[extra]?.action === 'none') name = 'none';
|
|
4394
|
+
else { name = 'confirm'; if (step.actions?.[extra]?.choice) suffix += ` ${step.actions[extra].choice}`; }
|
|
4395
|
+
} else if (what === 'group') { name = 'select-group'; const groups = [...new Set(step.rows.map((row) => row.group).filter(Boolean))]; suffix = groups[extra]; instance = suffix; }
|
|
4396
|
+
else if (what === 'other-input') name = step.key === 'batch-value' ? 'bulk-input' : 'input';
|
|
4397
|
+
else if (what === 'reason') name = 'none-note';
|
|
4398
|
+
else if (what === 'clear') name = 'bulk-clear';
|
|
4399
|
+
else if (what === 'back' && (step.key.startsWith('batch-') || step.backToMode)) name = 'bulk-back';
|
|
4400
|
+
else if (what === 'send') {
|
|
4401
|
+
if (step.key === 'batch-select') name = 'bulk-next';
|
|
4402
|
+
else if (step.key === 'batch-value') name = !draft.rows[0].choices.length && !draft.rows[0].other.trim() && hasAnswerSource(step.scope) ? 'bulk-evidence' : 'bulk-use';
|
|
4403
|
+
else if (step.actions?.[draft.rows[0].choices[0]]?.action === 'none') name = 'none-save';
|
|
4404
|
+
else if (!draft.rows[0].choices.length && !draft.rows[0].other.trim() && hasAnswerSource(step.scope)) name = 'evidence';
|
|
4405
|
+
else name = step.row?.kind === 'origin' && !draft.rows[0].otherOpen ? 'origin-confirm' : 'use';
|
|
4406
|
+
}
|
|
4407
|
+
return { id: `${prefix}-${name}#${entry.questionId} ${suffix}`, instance };
|
|
4408
|
+
}
|
|
4409
|
+
function drawingUnitsCandidate() {
|
|
4410
|
+
const chat = state.chat;
|
|
4411
|
+
if (state.scope?.owner?.kind !== 'workspace' || !chat || chat.archivedAt || (chat.workspaceUnits?.chosen && !state.workspaceUnitsEditing)) return null;
|
|
4412
|
+
state.workspaceUnitsQuestions ??= new Map();
|
|
4413
|
+
let entry = state.workspaceUnitsQuestions.get(chat.chatId);
|
|
4414
|
+
if (!entry) { entry = { key: `units/${chat.chatId}`, chatId: chat.chatId, questionId: chat.chatId, view: { open: true }, rowErrors: new Map(), changing: new Set(), selected: new Set() }; state.workspaceUnitsQuestions.set(chat.chatId, entry); }
|
|
4415
|
+
const values = ['ft-in', 'mm'], suggested = values.indexOf(chat.workspaceUnits?.suggested);
|
|
4416
|
+
const step = { key: 'units', question: { id: 'units', header: 'Units', question: 'Which units should AI use here?', allowOther: false,
|
|
4417
|
+
options: [{ shown: 'Feet and inches', description: 'Show lengths in feet and inches' }, { shown: 'Metric (mm)', description: 'Show lengths in millimetres' }], recommended: suggested < 0 ? null : suggested },
|
|
4418
|
+
commit: async (answer) => Boolean(await chooseWorkspaceUnits(values[answer.choices[0]])) };
|
|
4419
|
+
return { kind: 'units', entry, step };
|
|
4420
|
+
}
|
|
3956
4421
|
const SETUP_STALE = new Set(['setup-question-changed', 'height-question-closed', 'setup-question-superseded', 'setup-answer-frozen']);
|
|
3957
4422
|
const SETUP_SECTIONS = [['scale', 'Drawing scale'], ['origin', 'Model origin'], ['level', 'Plan levels']];
|
|
3958
4423
|
|
|
@@ -3981,7 +4446,7 @@
|
|
|
3981
4446
|
|
|
3982
4447
|
function repaintSetupCard(entry) {
|
|
3983
4448
|
const old = ui.feed?.querySelector(`[data-setup-question="${CSS.escape(entry.key)}"]`);
|
|
3984
|
-
if (!old) return;
|
|
4449
|
+
if (!old) { drawingSlotRepaint(); return; }
|
|
3985
4450
|
const focused = old.contains(document.activeElement) ? document.activeElement.dataset.commandId : null;
|
|
3986
4451
|
const caret = focused ? textCaret(document.activeElement) : null;
|
|
3987
4452
|
const next = rememberCard(entry, paintSetupCard(entry, old.dataset.eventId, old.dataset.eventSequence), old.dataset.eventId, old.dataset.eventSequence);
|
|
@@ -4020,113 +4485,10 @@
|
|
|
4020
4485
|
}
|
|
4021
4486
|
|
|
4022
4487
|
function paintSetupCard(entry, eventId, sequence) {
|
|
4023
|
-
|
|
4024
|
-
const card = document.createElement('section');
|
|
4025
|
-
card.className = 'ai-chat-filter-card ai-chat-height-card ai-chat-setup-card';
|
|
4026
|
-
card.dataset.setupQuestion = entry.key;
|
|
4027
|
-
card.dataset.eventId = eventId || '';
|
|
4028
|
-
card.dataset.eventSequence = sequence || '';
|
|
4029
|
-
card.setAttribute('aria-label', view?.n ? `Read setup, question ${view.n}` : 'Read setup');
|
|
4030
|
-
const rows = view ? view.items : [];
|
|
4031
|
-
const live = rows.filter(setupLive);
|
|
4032
|
-
const settled = live.filter(setupSettled);
|
|
4033
|
-
const open = Boolean(view?.open);
|
|
4034
|
-
const allSettled = live.length > 0 && settled.length === live.length;
|
|
4035
|
-
// Every row the person can answer is answered, but some wait on the READ (a picture to read, or new
|
|
4036
|
-
// choices to offer): the person still has to tell it, or the read never looks (E2E #1906).
|
|
4037
|
-
const waitsOnRead = (row) => row.status === 'picture' || row.status === 'needs-new-choices';
|
|
4038
|
-
const allAnswered = !allSettled && live.length > 0 && live.every((row) => setupSettled(row) || waitsOnRead(row));
|
|
4039
|
-
card.dataset.state = !view ? (entry.finished ? 'closed' : 'loading') : !open ? 'closed' : allSettled ? 'answered' : allAnswered ? 'waiting-for-read' : 'open';
|
|
4040
|
-
|
|
4041
|
-
const head = document.createElement('div'); head.className = 'ai-chat-filter-card-head';
|
|
4042
|
-
const title = document.createElement('strong'); title.textContent = 'Read setup';
|
|
4043
|
-
const chip = document.createElement('span'); chip.className = 'ai-chat-filter-state';
|
|
4044
|
-
chip.textContent = !view ? (entry.finished ? 'closed' : 'loading') : !open ? 'closed' : allSettled ? 'settled' : allAnswered ? 'with the read' : 'needs you';
|
|
4045
|
-
head.append(title, chip);
|
|
4046
|
-
card.append(head);
|
|
4047
|
-
const note = document.createElement('p'); note.className = 'ai-chat-filter-note';
|
|
4048
|
-
note.textContent = !view
|
|
4049
|
-
? (entry.finished ? CARD_FINISHED_TEXT : entry.loadError || 'Loading the read setup…')
|
|
4050
|
-
: open
|
|
4051
|
-
? 'These shape the whole model: each plan’s drawing scale, the model origin and each plan’s level. Only you can answer, and the read uses exactly what you settle here. If something conflicts, it asks you again here.'
|
|
4052
|
-
: 'This read is no longer waiting for an answer.';
|
|
4053
|
-
card.append(note);
|
|
4054
|
-
if (!view) {
|
|
4055
|
-
if (entry.loadError) {
|
|
4056
|
-
const actions = document.createElement('div'); actions.className = 'ai-chat-filter-actions';
|
|
4057
|
-
const retry = heightActionButton('Try again', `shell.chat-setup-retry#${entry.questionId}`, 'the read setup', '');
|
|
4058
|
-
retry.addEventListener('click', () => { entry.loadError = ''; repaintSetupCard(entry); loadSetupQuestion(entry); });
|
|
4059
|
-
actions.append(retry); card.append(actions);
|
|
4060
|
-
}
|
|
4061
|
-
return card;
|
|
4062
|
-
}
|
|
4063
|
-
const questionLabel = `setup question ${view.n}`;
|
|
4064
|
-
const count = document.createElement('p'); count.className = 'ai-chat-height-count'; count.setAttribute('aria-live', 'polite'); count.setAttribute('aria-atomic', 'true');
|
|
4065
|
-
count.textContent = `${settled.length} of ${live.length} settled`;
|
|
4066
|
-
card.append(count);
|
|
4067
|
-
|
|
4068
|
-
const body = document.createElement('div'); body.className = 'ai-chat-height-rows ai-chat-setup-body';
|
|
4069
|
-
body.setAttribute('role', 'region'); body.setAttribute('aria-label', 'Read setup questions'); body.tabIndex = 0;
|
|
4070
|
-
body.dataset.commandId = `shell.chat-setup-body#${entry.questionId}`;
|
|
4071
|
-
body.dataset.commandInstanceLabel = questionLabel;
|
|
4072
|
-
for (const [kind, name] of SETUP_SECTIONS) {
|
|
4073
|
-
const items = rows.filter((row) => row.kind === kind);
|
|
4074
|
-
if (!items.length) continue;
|
|
4075
|
-
body.append(paintSetupSection(entry, kind, name, items, open));
|
|
4076
|
-
}
|
|
4077
|
-
card.append(body);
|
|
4078
|
-
body.addEventListener('scroll', () => { entry.bodyScroll = body.scrollTop; }, { passive: true });
|
|
4079
|
-
if (entry.bodyScroll) requestAnimationFrame(() => { if (body.isConnected) body.scrollTop = entry.bodyScroll; });
|
|
4080
|
-
|
|
4081
|
-
const error = document.createElement('p'); error.className = 'ai-chat-height-error'; error.setAttribute('role', 'alert');
|
|
4082
|
-
error.textContent = entry.cardError || '';
|
|
4083
|
-
card.append(error);
|
|
4084
|
-
const actions = document.createElement('div'); actions.className = 'ai-chat-filter-actions';
|
|
4085
|
-
if (open && (allSettled || allAnswered)) {
|
|
4086
|
-
const done = document.createElement('p'); done.className = 'ai-chat-height-done';
|
|
4087
|
-
done.textContent = allSettled
|
|
4088
|
-
? 'All settled. Tell the read puts the message in the box so you can add to it; Send to the read sends it now.'
|
|
4089
|
-
: 'All answered. Tell the read puts the message in the box so you can add to it; Send to the read sends it now. The read then looks at what you sent and asks you to confirm its reading here.';
|
|
4090
|
-
card.append(done);
|
|
4091
|
-
const tell = heightActionButton('Tell the read', `shell.chat-setup-tell-read#${entry.questionId}`, questionLabel, 'ai-chat-filter-apply', null);
|
|
4092
|
-
tell.addEventListener('click', () => tellReadAnswered(entry, setupTellText(entry), repaintSetupCard));
|
|
4093
|
-
const send = heightActionButton('Send to the read', `shell.chat-setup-send-read#${entry.questionId}`, questionLabel, '', null);
|
|
4094
|
-
send.addEventListener('click', () => { void sendToReadAnswered(entry, setupTellText(entry), repaintSetupCard); });
|
|
4095
|
-
actions.append(tell, send);
|
|
4096
|
-
}
|
|
4097
|
-
actions.hidden = !actions.childNodes.length;
|
|
4098
|
-
card.append(actions);
|
|
4099
|
-
return card;
|
|
4488
|
+
return paintDrawingHistory('setup', entry, eventId, sequence);
|
|
4100
4489
|
}
|
|
4101
4490
|
|
|
4102
|
-
|
|
4103
|
-
const section = document.createElement('div'); section.className = 'ai-chat-setup-section';
|
|
4104
|
-
const live = items.filter(setupLive);
|
|
4105
|
-
const settled = live.filter(setupSettled).length;
|
|
4106
|
-
// The first section with something open starts expanded; a settled one collapses to one line.
|
|
4107
|
-
const expanded = entry.expanded.has(kind) ? entry.expanded.get(kind) : (settled < live.length || !open);
|
|
4108
|
-
const toggle = document.createElement('button');
|
|
4109
|
-
toggle.type = 'button'; toggle.className = 'ai-chat-setup-section-head';
|
|
4110
|
-
toggle.dataset.commandId = `shell.chat-setup-section#${entry.questionId} ${kind}`;
|
|
4111
|
-
toggle.dataset.commandInstanceLabel = name;
|
|
4112
|
-
toggle.setAttribute('aria-expanded', String(expanded));
|
|
4113
|
-
const label = document.createElement('span'); label.textContent = name;
|
|
4114
|
-
const tally = document.createElement('span'); tally.className = 'ai-chat-filter-state';
|
|
4115
|
-
tally.textContent = settled === live.length ? '✓ settled' : `${settled}/${live.length}`;
|
|
4116
|
-
toggle.append(label, tally);
|
|
4117
|
-
toggle.addEventListener('click', () => { entry.expanded.set(kind, !expanded); repaintSetupCard(entry); });
|
|
4118
|
-
section.append(toggle);
|
|
4119
|
-
if (!expanded) {
|
|
4120
|
-
const summary = document.createElement('p'); summary.className = 'ai-chat-setup-summary';
|
|
4121
|
-
summary.textContent = live.map((row) => `${row.kind === 'origin' ? 'Origin' : row.view.sheet} ${setupAnswerText(row) || 'open'}`).join(' · ');
|
|
4122
|
-
section.append(summary);
|
|
4123
|
-
return section;
|
|
4124
|
-
}
|
|
4125
|
-
const list = document.createElement('ol'); list.className = 'ai-chat-setup-list';
|
|
4126
|
-
for (const row of items) list.append(paintSetupRow(entry, row, open));
|
|
4127
|
-
section.append(list);
|
|
4128
|
-
return section;
|
|
4129
|
-
}
|
|
4491
|
+
|
|
4130
4492
|
|
|
4131
4493
|
function setupConflictBanner(row) {
|
|
4132
4494
|
if (!row.conflict) return null;
|
|
@@ -4176,10 +4538,7 @@
|
|
|
4176
4538
|
change.setAttribute('aria-label', `Change your answer for ${instance}`);
|
|
4177
4539
|
change.addEventListener('click', () => {
|
|
4178
4540
|
if (change.getAttribute('aria-disabled') === 'true') return;
|
|
4179
|
-
entry
|
|
4180
|
-
// A "none" answer's note is the person's REASON, not a source: it is not put in the source box.
|
|
4181
|
-
if (row.answer.note && row.answer.how !== 'none') { const source = answerSource(`s:${entry.questionId}:${row.key}`); source.open = true; source.note = source.note || row.answer.note; }
|
|
4182
|
-
repaintSetupCard(entry);
|
|
4541
|
+
reopenDrawingItem('setup', entry, row.key);
|
|
4183
4542
|
});
|
|
4184
4543
|
done.append(change);
|
|
4185
4544
|
}
|
|
@@ -4197,7 +4556,7 @@
|
|
|
4197
4556
|
if (open) {
|
|
4198
4557
|
const change = heightActionButton('Answer now', idFor('change'), instance, 'ai-chat-height-change', null);
|
|
4199
4558
|
change.setAttribute('aria-label', `Answer ${instance} yourself instead`);
|
|
4200
|
-
change.addEventListener('click', () =>
|
|
4559
|
+
change.addEventListener('click', () => reopenDrawingItem('setup', entry, row.key));
|
|
4201
4560
|
wait.append(change);
|
|
4202
4561
|
}
|
|
4203
4562
|
item.append(wait);
|
|
@@ -4211,73 +4570,14 @@
|
|
|
4211
4570
|
return item;
|
|
4212
4571
|
}
|
|
4213
4572
|
if (row.frozen) { const frozen = document.createElement('p'); frozen.className = 'ai-chat-setup-frozen'; frozen.textContent = row.frozen; item.append(frozen); return item; }
|
|
4214
|
-
const busyReason = entry.busy ? 'An answer is still being saved — wait for it to finish' : null;
|
|
4215
|
-
const scope = `s:${entry.questionId}:${row.key}`;
|
|
4216
|
-
if (row.kind === 'scale') paintScaleControls(entry, row, item, instance, idFor, busyReason, scope);
|
|
4217
|
-
else if (row.kind === 'level') paintLevelControls(entry, row, item, instance, idFor, busyReason, scope);
|
|
4218
|
-
else paintOriginControls(entry, row, item, instance, idFor, busyReason, scope);
|
|
4219
|
-
item.append(paintAnswerSource(scope, {
|
|
4220
|
-
requestId: entry.requestId, chatId: entry.chatId, repaint: () => repaintSetupCard(entry), label: instance, instance,
|
|
4221
|
-
idFor: sourceIdFor, inherited: row.inherited, busyReason, allowPictureOnly: true,
|
|
4222
|
-
onPictureOnly: () => submitSetupAnswers(entry, [{ key: row.key, action: 'evidence' }], row.key),
|
|
4223
|
-
}));
|
|
4224
|
-
const rowError = document.createElement('p'); rowError.className = 'ai-chat-height-error'; rowError.setAttribute('role', 'alert');
|
|
4225
|
-
rowError.textContent = entry.rowErrors.get(row.key) || '';
|
|
4226
|
-
item.append(rowError);
|
|
4227
4573
|
return item;
|
|
4228
4574
|
}
|
|
4229
4575
|
|
|
4230
|
-
function setupProposal(valueText, tag, evidence, confirm) {
|
|
4231
|
-
const box = document.createElement('div'); box.className = 'ai-chat-setup-proposal';
|
|
4232
|
-
const line = document.createElement('div'); line.className = 'ai-chat-height-proposal';
|
|
4233
|
-
const value = document.createElement('span'); value.textContent = valueText;
|
|
4234
|
-
line.append(value, confirm);
|
|
4235
|
-
const source = document.createElement('div'); source.className = 'ai-chat-setup-evidence';
|
|
4236
|
-
const label = document.createElement('span'); label.className = 'ai-chat-setup-tag'; label.textContent = tag;
|
|
4237
|
-
source.append(label, document.createTextNode(` ${evidence}`));
|
|
4238
|
-
source.dataset.tip = `${tag}: ${evidence}`;
|
|
4239
|
-
box.append(line, source);
|
|
4240
|
-
return box;
|
|
4241
|
-
}
|
|
4242
4576
|
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
input.dataset.commandId = idFor('input'); input.dataset.commandInstanceLabel = instance;
|
|
4248
|
-
input.placeholder = placeholder;
|
|
4249
|
-
input.setAttribute('aria-label', `${ariaWhat} for ${instance}`);
|
|
4250
|
-
input.value = entry.drafts.get(row.key) || '';
|
|
4251
|
-
input.addEventListener('input', () => { entry.drafts.set(row.key, input.value); entry.rowErrors.delete(row.key); if (row.kind === 'origin' && input.value) entry.originPick = null; });
|
|
4252
|
-
if (busyReason) { input.readOnly = true; input.setAttribute('aria-disabled', 'true'); input.dataset.blockedReason = busyReason; }
|
|
4253
|
-
const use = heightActionButton('Use', idFor('use'), instance, primary ? 'ai-chat-filter-apply' : '', busyReason);
|
|
4254
|
-
use.setAttribute('aria-label', `Use what you typed for ${instance}`);
|
|
4255
|
-
const submit = () => {
|
|
4256
|
-
if (use.getAttribute('aria-disabled') === 'true') return;
|
|
4257
|
-
const typed = input.value.trim();
|
|
4258
|
-
if (!typed) { entry.rowErrors.set(row.key, 'Type an answer first.'); repaintSetupCard(entry); return; }
|
|
4259
|
-
submitSetupAnswers(entry, [{ key: row.key, action: 'type', typed }], row.key);
|
|
4260
|
-
};
|
|
4261
|
-
input.addEventListener('keydown', (event) => { if (event.key === 'Enter' && !event.isComposing) { event.preventDefault(); submit(); } });
|
|
4262
|
-
use.addEventListener('click', submit);
|
|
4263
|
-
field.append(input, use);
|
|
4264
|
-
item.append(field);
|
|
4265
|
-
}
|
|
4266
|
-
|
|
4267
|
-
function paintScaleControls(entry, row, item, instance, idFor, busyReason, scope) {
|
|
4268
|
-
if (row.clue) { const clue = document.createElement('p'); clue.className = 'ai-chat-setup-why'; clue.textContent = row.clue; item.append(clue); }
|
|
4269
|
-
for (const proposal of row.proposals) {
|
|
4270
|
-
const confirm = heightActionButton(proposal.pageFit ? 'Use for this plan' : 'Confirm', idFor('confirm', proposal.id), instance, 'ai-chat-filter-apply', busyReason);
|
|
4271
|
-
confirm.setAttribute('aria-label', `${proposal.pageFit ? 'Use' : 'Confirm'} ${proposal.standard} for ${instance}`);
|
|
4272
|
-
confirm.addEventListener('click', () => {
|
|
4273
|
-
if (confirm.getAttribute('aria-disabled') === 'true') return;
|
|
4274
|
-
submitSetupAnswers(entry, [{ key: row.key, action: 'confirm', choice: proposal.id, shown: proposal.mmPerPx }], row.key);
|
|
4275
|
-
});
|
|
4276
|
-
// The Confirm records mmPerPx, so the exact number is shown beside the standard (Codex review #1906).
|
|
4277
|
-
item.append(setupProposal(`${proposal.standard} · ${scaleNumber(proposal.mmPerPx)} mm per drawing point`, scaleTag[proposal.source] || 'PROPOSED', proposal.evidence, confirm));
|
|
4278
|
-
}
|
|
4279
|
-
setupTypedField(entry, row, item, instance, idFor, busyReason, 'or type a scale, e.g. 1/4" = 1\'-0" or 1:100', 'Type the scale', !row.proposals.length);
|
|
4280
|
-
}
|
|
4577
|
+
|
|
4578
|
+
|
|
4579
|
+
|
|
4580
|
+
|
|
4281
4581
|
|
|
4282
4582
|
const scaleNumber = (mmPerPx) => String(Number(Number(mmPerPx).toFixed(6)));
|
|
4283
4583
|
|
|
@@ -4288,143 +4588,47 @@
|
|
|
4288
4588
|
return 'Read from the picture you sent. Check it before you confirm.';
|
|
4289
4589
|
}
|
|
4290
4590
|
|
|
4291
|
-
function paintLevelControls(entry, row, item, instance, idFor, busyReason, scope) {
|
|
4292
|
-
if (row.noSingleLevel) { const why = document.createElement('p'); why.className = 'ai-chat-setup-why'; why.textContent = `No single level on the drawings: ${row.noSingleLevel.why}`; item.append(why); }
|
|
4293
|
-
const units = entry.view?.units;
|
|
4294
|
-
for (const proposal of row.proposals) {
|
|
4295
|
-
const confirm = heightActionButton('Confirm', idFor('confirm', proposal.id), instance, 'ai-chat-filter-apply', busyReason);
|
|
4296
|
-
confirm.setAttribute('aria-label', `Confirm ${proposal.asRead} for ${instance}`);
|
|
4297
|
-
confirm.addEventListener('click', () => {
|
|
4298
|
-
if (confirm.getAttribute('aria-disabled') === 'true') return;
|
|
4299
|
-
submitSetupAnswers(entry, [{ key: row.key, action: 'confirm', choice: proposal.id, shown: proposal.value }], row.key);
|
|
4300
|
-
});
|
|
4301
|
-
item.append(setupProposal(proposal.asRead, levelTag[proposal.source] || 'PROPOSED', levelEvidence(proposal), confirm));
|
|
4302
|
-
}
|
|
4303
|
-
setupTypedField(entry, row, item, instance, idFor, busyReason, units === 'mm' ? 'or type a level, e.g. 4870 mm' : 'or type a level, e.g. 16\'-6"', 'Type the level', !row.proposals.length);
|
|
4304
|
-
paintNoneControl(entry, row, item, instance, idFor, busyReason, 'No single level', 'Short note (required), e.g. 1\'-6" TOF west, 0\'-0" east', 'Save: no single level');
|
|
4305
|
-
}
|
|
4306
4591
|
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
none.addEventListener('click', () => {
|
|
4312
|
-
if (none.getAttribute('aria-disabled') === 'true') return;
|
|
4313
|
-
entry.noneOpen.add(row.key); repaintSetupCard(entry);
|
|
4314
|
-
const card = ui.feed.querySelector(`[data-setup-question="${CSS.escape(entry.key)}"]`);
|
|
4315
|
-
if (card) focusHeightControl(card, idFor('none-note'));
|
|
4316
|
-
});
|
|
4317
|
-
item.append(none);
|
|
4318
|
-
return;
|
|
4319
|
-
}
|
|
4320
|
-
const field = document.createElement('div'); field.className = 'ai-chat-height-field';
|
|
4321
|
-
const note = document.createElement('input');
|
|
4322
|
-
note.type = 'text'; note.className = 'ai-chat-height-input'; note.maxLength = 160; note.autocomplete = 'off';
|
|
4323
|
-
note.dataset.commandId = idFor('none-note'); note.dataset.commandInstanceLabel = instance;
|
|
4324
|
-
note.placeholder = placeholder;
|
|
4325
|
-
note.setAttribute('aria-label', `Why: ${label.toLowerCase()} for ${instance}`);
|
|
4326
|
-
note.required = true;
|
|
4327
|
-
const noteKey = `${row.key}\u0000none`;
|
|
4328
|
-
note.value = entry.drafts.get(noteKey) || '';
|
|
4329
|
-
note.addEventListener('input', () => { entry.drafts.set(noteKey, note.value); entry.rowErrors.delete(row.key); });
|
|
4330
|
-
const save = heightActionButton(saveLabel, idFor('none-save'), instance, '', busyReason);
|
|
4331
|
-
const submit = () => {
|
|
4332
|
-
if (save.getAttribute('aria-disabled') === 'true') return;
|
|
4333
|
-
const text = note.value.trim();
|
|
4334
|
-
if (!text) { entry.rowErrors.set(row.key, 'Add a short note first, so the read knows what to do instead.'); repaintSetupCard(entry); return; }
|
|
4335
|
-
submitSetupAnswers(entry, [{ key: row.key, action: 'none', note: text }], row.key);
|
|
4336
|
-
};
|
|
4337
|
-
note.addEventListener('keydown', (event) => { if (event.key === 'Enter' && !event.isComposing) { event.preventDefault(); submit(); } });
|
|
4338
|
-
save.addEventListener('click', submit);
|
|
4339
|
-
field.append(note, save);
|
|
4340
|
-
item.append(field);
|
|
4341
|
-
}
|
|
4342
|
-
|
|
4343
|
-
function paintOriginControls(entry, row, item, instance, idFor, busyReason, scope) {
|
|
4344
|
-
const group = document.createElement('fieldset'); group.className = 'ai-chat-setup-origin';
|
|
4345
|
-
group.setAttribute('role', 'radiogroup');
|
|
4346
|
-
const legend = document.createElement('legend'); legend.textContent = 'Which grid crossing is the model’s origin (0, 0)?';
|
|
4347
|
-
group.append(legend);
|
|
4348
|
-
const radio = (choiceId, text, tag) => {
|
|
4349
|
-
const label = document.createElement('label'); label.className = 'ai-chat-setup-choice';
|
|
4350
|
-
const input = document.createElement('input');
|
|
4351
|
-
input.type = 'radio'; input.name = `origin-${entry.questionId}`; input.value = choiceId;
|
|
4352
|
-
input.dataset.commandId = idFor('origin-choice', choiceId); input.dataset.commandInstanceLabel = text;
|
|
4353
|
-
input.checked = entry.originPick === choiceId;
|
|
4354
|
-
if (busyReason) { input.disabled = true; }
|
|
4355
|
-
input.addEventListener('change', () => { entry.originPick = choiceId; entry.drafts.delete(row.key); entry.rowErrors.delete(row.key); repaintSetupCard(entry); });
|
|
4356
|
-
const name = document.createElement('span'); name.className = 'ai-chat-setup-choice-name'; name.textContent = text;
|
|
4357
|
-
label.append(input, name);
|
|
4358
|
-
if (tag) { const t = document.createElement('span'); t.className = 'ai-chat-setup-tag'; t.textContent = tag; label.append(t); }
|
|
4359
|
-
return label;
|
|
4360
|
-
};
|
|
4361
|
-
const straight = document.createElement('div'); straight.className = 'ai-chat-setup-choices';
|
|
4362
|
-
row.choices.forEach((choice, i) => straight.append(radio(`c${i}`, originText(choice), row.proposed === i ? (row.fromEvidence ? 'THE READ’S READING OF YOUR PICTURE' : 'THE READ SUGGESTS') : '')));
|
|
4363
|
-
group.append(straight);
|
|
4364
|
-
if (row.offGrid.length) {
|
|
4365
|
-
const also = document.createElement('fieldset'); also.className = 'ai-chat-setup-also';
|
|
4366
|
-
const legend2 = document.createElement('legend'); legend2.textContent = 'Also on the drawing (not straight grid lines)';
|
|
4367
|
-
also.append(legend2);
|
|
4368
|
-
row.offGrid.forEach((point, i) => also.append(radio(`o${i}`, point.as, '')));
|
|
4369
|
-
group.append(also);
|
|
4370
|
-
}
|
|
4371
|
-
item.append(group);
|
|
4372
|
-
const pick = entry.originPick;
|
|
4373
|
-
let target = null;
|
|
4374
|
-
if (pick && pick.startsWith('c')) target = row.choices[Number(pick.slice(1))] || null;
|
|
4375
|
-
let statement = null;
|
|
4376
|
-
if (pick && pick.startsWith('o')) {
|
|
4377
|
-
const point = row.offGrid[Number(pick.slice(1))];
|
|
4378
|
-
target = point ? row.choices[point.same] : null;
|
|
4379
|
-
if (point && target) {
|
|
4380
|
-
// Said BEFORE the confirm, and the confirm itself names the straight intersection that lands.
|
|
4381
|
-
statement = document.createElement('div'); statement.className = 'ai-chat-setup-statement';
|
|
4382
|
-
statement.setAttribute('role', 'status');
|
|
4383
|
-
statement.id = `setup-statement-${entry.questionId}`;
|
|
4384
|
-
statement.textContent = `${point.as} is not a straight grid line in the model, so it cannot be the origin. The read says it is the same point as ${originText(target)} (${point.why}). This is the read’s claim; FloLess has not checked it.`;
|
|
4385
|
-
item.append(statement);
|
|
4386
|
-
}
|
|
4387
|
-
}
|
|
4388
|
-
const confirmLabel = target ? `Confirm ${originText(target)} as the model origin` : 'Confirm the model origin';
|
|
4389
|
-
const confirm = heightActionButton(confirmLabel, idFor('origin-confirm'), instance, 'ai-chat-filter-apply', busyReason || (target ? null : 'Pick a point first'));
|
|
4390
|
-
if (statement) confirm.setAttribute('aria-describedby', statement.id);
|
|
4391
|
-
confirm.addEventListener('click', () => {
|
|
4392
|
-
if (confirm.getAttribute('aria-disabled') === 'true' || !target) return;
|
|
4393
|
-
submitSetupAnswers(entry, [{ key: row.key, action: 'confirm', choice: pick, shown: originText(target) }], row.key);
|
|
4394
|
-
});
|
|
4395
|
-
const actions = document.createElement('div'); actions.className = 'ai-chat-height-proposal';
|
|
4396
|
-
actions.append(confirm);
|
|
4397
|
-
item.append(actions);
|
|
4398
|
-
setupTypedField(entry, row, item, instance, idFor, busyReason, 'or type a point, e.g. K/1.1', 'Type the grid point', false);
|
|
4399
|
-
paintNoneControl(entry, row, item, instance, idFor, busyReason, 'None of these', 'Short note (required), e.g. use the corner at C/0.5', 'Save: none of these');
|
|
4400
|
-
}
|
|
4592
|
+
|
|
4593
|
+
|
|
4594
|
+
|
|
4595
|
+
|
|
4401
4596
|
|
|
4402
4597
|
async function submitSetupAnswers(entry, answers, rowKey) {
|
|
4403
|
-
if (entry.busy) return;
|
|
4598
|
+
if (entry.busy) return false;
|
|
4599
|
+
const ownedSlot = drawingEntryCurrent(entry) && ui.approvalTray?.querySelector('.ai-chat-drawing-step')?.dataset.drawingStep;
|
|
4600
|
+
const ownedNode = ownedSlot ? ui.approvalTray.querySelector('.ai-chat-drawing-step') : null;
|
|
4601
|
+
const pendingFocusId = ownedNode?.contains(document.activeElement) ? document.activeElement.dataset.commandId : null;
|
|
4602
|
+
const failedField = ownedNode && ([...ownedNode.querySelectorAll('input')].find((field) => field.dataset.commandId === ownedNode.lastDrawingField) || ownedNode.querySelector('.ai-chat-ask-other-input'));
|
|
4603
|
+
const failedFieldId = failedField?.dataset.commandId, failedCaret = failedField ? textCaret(failedField) : null;
|
|
4604
|
+
let saved = false;
|
|
4404
4605
|
const withSource = answers.map((answer) => withAnswerSource(answer, answerSourcePayload(`s:${entry.questionId}:${answer.key}`)));
|
|
4405
|
-
const tooLong = withSource.find((answer) => answer.note && answer.note.length > MAX_ANSWER_NOTE);
|
|
4406
|
-
if (tooLong) {
|
|
4407
|
-
entry.rowErrors.set(rowKey, `Your reason and your source note together are longer than ${MAX_ANSWER_NOTE} characters. Shorten one of them.`);
|
|
4408
|
-
repaintSetupCard(entry); return;
|
|
4409
|
-
}
|
|
4410
|
-
if (withSource.some((answer) => answer.action === 'evidence' && !answer.evidence?.length)) {
|
|
4411
|
-
entry.rowErrors.set(rowKey, 'Attach a picture first.'); repaintSetupCard(entry); return;
|
|
4412
|
-
}
|
|
4413
|
-
entry.busy = true; entry.cardError = ''; if (rowKey) entry.rowErrors.delete(rowKey);
|
|
4414
|
-
repaintSetupCard(entry);
|
|
4415
4606
|
try {
|
|
4607
|
+
const tooLong = withSource.find((answer) => answer.note && answer.note.length > MAX_ANSWER_NOTE);
|
|
4608
|
+
if (tooLong) {
|
|
4609
|
+
entry.rowErrors.set(rowKey, `Your reason and your source note together are longer than ${MAX_ANSWER_NOTE} characters. Shorten one of them.`);
|
|
4610
|
+
return false;
|
|
4611
|
+
}
|
|
4612
|
+
if (withSource.some((answer) => answer.action === 'evidence' && !answer.evidence?.length)) {
|
|
4613
|
+
entry.rowErrors.set(rowKey, 'Attach a picture first.'); return false;
|
|
4614
|
+
}
|
|
4615
|
+
entry.busy = true; entry.cardError = ''; if (rowKey) entry.rowErrors.delete(rowKey);
|
|
4616
|
+
repaintSetupCard(entry);
|
|
4416
4617
|
const result = await request(`/api/chat/setup-questions/${encodeURIComponent(entry.requestId)}/${encodeURIComponent(entry.questionId)}/answers`, {
|
|
4417
4618
|
method: 'POST', body: JSON.stringify({ chatId: entry.chatId, answers: withSource }),
|
|
4418
4619
|
});
|
|
4419
4620
|
entry.view = result.question;
|
|
4621
|
+
saved = true;
|
|
4420
4622
|
for (const answer of answers) {
|
|
4421
4623
|
entry.changing.delete(answer.key); entry.drafts.delete(answer.key); entry.drafts.delete(`${answer.key}\u0000none`);
|
|
4624
|
+
if (entry.activeItem === answer.key) { entry.activeItem = null; entry.reopenedAt = 0; }
|
|
4422
4625
|
entry.noneOpen.delete(answer.key);
|
|
4423
4626
|
if (answer.key === 'origin') entry.originPick = null;
|
|
4424
4627
|
clearAnswerSource(`s:${entry.questionId}:${answer.key}`);
|
|
4425
4628
|
}
|
|
4426
4629
|
} catch (error) {
|
|
4427
4630
|
let message = heightErrorText(error, 'FloLess could not save this answer. Try again.');
|
|
4631
|
+
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.';
|
|
4428
4632
|
if (error?.code === 'answer-evidence-unknown') message = dropStaleAnswerFiles(answers.map((answer) => `s:${entry.questionId}:${answer.key}`), entry);
|
|
4429
4633
|
if (SETUP_STALE.has(error?.code)) { entry.cardError = message; entry.view = null; loadSetupQuestion(entry); }
|
|
4430
4634
|
else if (rowKey) entry.rowErrors.set(rowKey, message);
|
|
@@ -4433,8 +4637,14 @@
|
|
|
4433
4637
|
entry.busy = false;
|
|
4434
4638
|
repaintSetupCard(entry);
|
|
4435
4639
|
settlePendingReload(entry, loadSetupQuestion);
|
|
4436
|
-
|
|
4640
|
+
const currentSlot = ui.approvalTray?.querySelector('.ai-chat-drawing-step');
|
|
4641
|
+
if (ownedSlot && drawingEntryCurrent(entry) && ownedSlot === currentSlot?.dataset.drawingStep
|
|
4642
|
+
&& pendingFocusId && currentSlot.contains(document.activeElement) && document.activeElement.dataset.commandId === pendingFocusId) {
|
|
4643
|
+
if (saved) focusNextSetupControl(entry);
|
|
4644
|
+
else if (failedFieldId) focusHeightControl(currentSlot, failedFieldId, failedCaret);
|
|
4645
|
+
}
|
|
4437
4646
|
}
|
|
4647
|
+
return saved;
|
|
4438
4648
|
}
|
|
4439
4649
|
|
|
4440
4650
|
// After an answer, keyboard focus moves to the next row still open, or to Tell the read.
|
|
@@ -5016,11 +5226,17 @@
|
|
|
5016
5226
|
ui.feed.append(renderAgentRunLine(event));
|
|
5017
5227
|
continue;
|
|
5018
5228
|
}
|
|
5019
|
-
if (event.type === 'connection-proposal-update') continue;
|
|
5229
|
+
if (event.type === 'connection-proposal-update' || event.type === 'view-command-update') continue;
|
|
5020
5230
|
if (event.type === 'connection-proposal' || event.type === 'connection-check') { links.push({ turnId: event.turnId, node: renderEvent(event) }); continue; }
|
|
5021
5231
|
// #2046: the Guide's next-move cards are held under the answer they were suggested in, like the cards above.
|
|
5022
5232
|
if (event.type === 'next-move') { const node = renderEvent(event); if (node) links.push({ turnId: event.turnId, node }); continue; }
|
|
5023
5233
|
if (event.type === 'next-move-update') { renderEvent(event); continue; }
|
|
5234
|
+
// #2247: an action suggestion or an action the AI ran is held under the answer, like the cards above; an update
|
|
5235
|
+
// only changes its card (which reads it when it repaints).
|
|
5236
|
+
if (event.type === 'action-proposal-update') continue;
|
|
5237
|
+
if (event.type === 'action-proposal' || event.type === 'action-call') { links.push({ turnId: event.turnId, node: renderEvent(event) }); continue; }
|
|
5238
|
+
// #2255: a model view change is written mid-answer while the tool waits, so it is held under the answer too.
|
|
5239
|
+
if (event.type === 'view-command') { links.push({ turnId: event.turnId, node: renderEvent(event) }); continue; }
|
|
5024
5240
|
if (['tool', 'usage', 'knowledge-citation', 'attachment', 'compaction', 'state'].includes(event.type)) continue;
|
|
5025
5241
|
// FloLess's own receipts (object links #1653; evidence looks and suggestion cards #1859) are written mid-answer while a tool runs:
|
|
5026
5242
|
// held and shown under the answer, so they never cut one answer into fragments.
|
|
@@ -5140,13 +5356,36 @@
|
|
|
5140
5356
|
}
|
|
5141
5357
|
|
|
5142
5358
|
function paintApproval() {
|
|
5359
|
+
clearSettledQuestionDrafts(state.events, state.chat);
|
|
5143
5360
|
paintApprovalScope();
|
|
5144
5361
|
const existing = shell.querySelector('.ai-chat-approval:not(.ai-chat-approval-scope)');
|
|
5145
5362
|
const approval = state.chat?.pendingApproval;
|
|
5146
5363
|
const deciding = Boolean(approval && state.decidingApprovalIds.has(approval.approvalId));
|
|
5147
5364
|
shell.dataset.approvalPending = String(Boolean(approval) && !deciding);
|
|
5365
|
+
// #2223 Revision 6: a question Codex asked without waiting, while no approval holds the slot — a blocking question or an
|
|
5366
|
+
// action the AI is waiting on always goes first, and this one shows once it has settled. The chat is waiting on the person.
|
|
5367
|
+
const asking = approval ? null : openAsyncQuestion(state.events, state.chat);
|
|
5368
|
+
if (asking) shell.dataset.approvalPending = 'true';
|
|
5148
5369
|
document.dispatchEvent(new CustomEvent('floless:chat-indicator'));
|
|
5149
|
-
if (
|
|
5370
|
+
if (asking && window.FlolessQuestionCard) {
|
|
5371
|
+
if (existing?.dataset.approvalId === asking.approvalId && existing.classList.contains('ai-chat-ask-card')) return;
|
|
5372
|
+
existing?.remove();
|
|
5373
|
+
paintQuestionCard(asking, null);
|
|
5374
|
+
return;
|
|
5375
|
+
}
|
|
5376
|
+
if (!approval || deciding) {
|
|
5377
|
+
if (existing && !existing.classList.contains('ai-chat-drawing-step')) existing.remove();
|
|
5378
|
+
if (!paintDrawingQuestionSlot()) existing?.remove();
|
|
5379
|
+
return;
|
|
5380
|
+
}
|
|
5381
|
+
// #2223: the AI is asking the person. Its card keeps the person's draft across repaints, so a card already showing this
|
|
5382
|
+
// question repaints only from its own changes (a choice, a file, sending), never from a poll.
|
|
5383
|
+
if (approval.kind === 'question' && approval.question && window.FlolessQuestionCard) {
|
|
5384
|
+
if (existing?.dataset.approvalId === approval.approvalId && existing.classList.contains('ai-chat-ask-card')) return;
|
|
5385
|
+
existing?.remove();
|
|
5386
|
+
paintQuestionCard(approval, null);
|
|
5387
|
+
return;
|
|
5388
|
+
}
|
|
5150
5389
|
// Keep the same buttons during polling so keyboard focus and pointer clicks survive. A card also carries the
|
|
5151
5390
|
// permission views its wider choices are offered on (epic #2185 Slice A), so a change to any of them repaints it.
|
|
5152
5391
|
const teklaBinding = teklaAllowableApproval(approval) ? currentTeklaBinding(state.chat) : null;
|
|
@@ -5184,10 +5423,9 @@
|
|
|
5184
5423
|
card.setAttribute('aria-labelledby', heading.id);
|
|
5185
5424
|
const copy = document.createElement('p');
|
|
5186
5425
|
const readOnly = state.chat?.settings?.permissionProfile === 'read-only';
|
|
5187
|
-
const writeProfile = state.chat?.owner?.kind === 'workspace' ? 'Make changes (asks first)' : 'Working folder write';
|
|
5188
5426
|
copy.textContent = readOnly
|
|
5189
5427
|
? 'The AI’s file tools cannot change files while Read only is on. Commands keep their own approvals and may authorize file changes.'
|
|
5190
|
-
+ (scope.allowsFileChanges ?
|
|
5428
|
+
+ (scope.allowsFileChanges ? ' If you choose Working folder write, file changes here will also be allowed without asking.' : '')
|
|
5191
5429
|
: scope.allowsFileChanges ? 'File changes here will also be allowed without asking. Commands and tools keep their own approvals.'
|
|
5192
5430
|
: 'Adds this folder to the conversation. Your current file approval setting stays unchanged.';
|
|
5193
5431
|
const actions = document.createElement('div'); actions.className = 'ai-chat-approval-actions';
|
|
@@ -5267,6 +5505,321 @@
|
|
|
5267
5505
|
ui.approvalTray.scrollTop = ui.approvalTray.scrollHeight;
|
|
5268
5506
|
}
|
|
5269
5507
|
|
|
5508
|
+
/*
|
|
5509
|
+
* #2223 — the AI's question card (web/chat-question-card.js), above the message box. The draft lives here, by approval
|
|
5510
|
+
* id, so a repaint, a reconnect or a refused send never loses what the person chose or typed (R12, Revision 2). Sending
|
|
5511
|
+
* shows "Sending…" on the card instead of removing it: only the server's answer closes it.
|
|
5512
|
+
*/
|
|
5513
|
+
const questionDrafts = new Map();
|
|
5514
|
+
const questionScope = (approvalId, index) => `ask:${approvalId}:${index}`;
|
|
5515
|
+
|
|
5516
|
+
function questionEntry(approval) {
|
|
5517
|
+
let entry = questionDrafts.get(approval.approvalId);
|
|
5518
|
+
if (!entry) {
|
|
5519
|
+
entry = { chatId: state.chat?.chatId, async: Boolean(approval.async), draft: window.FlolessQuestionCard.createDraft(approval.question.questions), busy: '', error: '' };
|
|
5520
|
+
questionDrafts.set(approval.approvalId, entry);
|
|
5521
|
+
}
|
|
5522
|
+
return entry;
|
|
5523
|
+
}
|
|
5524
|
+
|
|
5525
|
+
/** Forget closed questions and their previews, keeping a still-open card even behind another approval. */
|
|
5526
|
+
function clearSettledQuestionDrafts(events, chat) {
|
|
5527
|
+
if (!chat) return;
|
|
5528
|
+
const observed = Array.isArray(events) ? events : [];
|
|
5529
|
+
for (const [id, entry] of questionDrafts) {
|
|
5530
|
+
if (entry.chatId !== chat.chatId) continue;
|
|
5531
|
+
// An older or partial snapshot may omit a live card. Only its recorded settlement is proof it closed.
|
|
5532
|
+
const askedAt = entry.async ? observed.findIndex((event) => event.eventId === id && event.type === 'assistant-message' && event.payload?.asyncQuestion) : -1;
|
|
5533
|
+
const settled = entry.async
|
|
5534
|
+
? askedAt >= 0 && observed.slice(askedAt + 1).some((event) => (event.type === 'user-message' && !event.optimistic) || (event.type === 'assistant-message' && event.payload?.asyncQuestion))
|
|
5535
|
+
: observed.some((event) => event.type === 'approval-decided' && event.payload?.kind === 'question' && event.payload.approvalId === id);
|
|
5536
|
+
if (!chat.archivedAt && !settled) continue;
|
|
5537
|
+
questionDrafts.delete(id);
|
|
5538
|
+
for (let index = 0; index < entry.draft.rows.length; index += 1) clearAnswerSource(questionScope(id, index));
|
|
5539
|
+
}
|
|
5540
|
+
}
|
|
5541
|
+
|
|
5542
|
+
function questionCardNode(approvalId) {
|
|
5543
|
+
return [...ui.approvalTray.querySelectorAll('.ai-chat-ask-card')].find((node) => node.dataset.approvalId === approvalId) || null;
|
|
5544
|
+
}
|
|
5545
|
+
|
|
5546
|
+
/** The Other… box's files, through the Drawing Filter answer source's machinery (types, sizes, three per answer). */
|
|
5547
|
+
function questionFiles(approval) {
|
|
5548
|
+
const snapshot = captureChat();
|
|
5549
|
+
const base = () => `/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/questions/${encodeURIComponent(approval.approvalId)}/files`;
|
|
5550
|
+
const repaint = () => { const card = questionCardNode(approval.approvalId); if (card && sameChat(snapshot)) paintQuestionCard(approval, card); };
|
|
5551
|
+
const ctx = {
|
|
5552
|
+
chatId: snapshot?.chatId, requestId: null, repaint,
|
|
5553
|
+
upload: (file, data) => request(base(), { method: 'POST', timeoutMs: 120000,
|
|
5554
|
+
body: JSON.stringify({ owner: snapshot.scope.owner, fileName: file.name || 'screenshot.png', mediaType: file.type, data }) }),
|
|
5555
|
+
removeFile: (file) => request(`${base()}/${encodeURIComponent(file.attachmentId)}`, { method: 'DELETE', body: JSON.stringify({ owner: snapshot.scope.owner }) }),
|
|
5556
|
+
};
|
|
5557
|
+
return {
|
|
5558
|
+
max: MAX_ANSWER_FILES,
|
|
5559
|
+
list: (index) => answerSource(questionScope(approval.approvalId, index)).files,
|
|
5560
|
+
uploading: (index) => answerSource(questionScope(approval.approvalId, index)).uploading,
|
|
5561
|
+
error: (index) => answerSource(questionScope(approval.approvalId, index)).error,
|
|
5562
|
+
attach: (index, files) => { if (snapshot) void attachAnswerFiles(questionScope(approval.approvalId, index), ctx, files); },
|
|
5563
|
+
remove: (index, file) => { if (snapshot) void removeAnswerFile(questionScope(approval.approvalId, index), ctx, file); },
|
|
5564
|
+
};
|
|
5565
|
+
}
|
|
5566
|
+
|
|
5567
|
+
function paintQuestionCard(approval, existing) {
|
|
5568
|
+
const entry = questionEntry(approval);
|
|
5569
|
+
const fresh = !existing;
|
|
5570
|
+
const card = existing || document.createElement('section');
|
|
5571
|
+
if (fresh) {
|
|
5572
|
+
card.className = 'ai-chat-approval ai-chat-ask-card';
|
|
5573
|
+
card.dataset.approvalId = approval.approvalId;
|
|
5574
|
+
if (approval.async) card.dataset.askAsync = 'true';
|
|
5575
|
+
// #2079: Flo, hat on, faces the person: the AI is asking, and the person decides.
|
|
5576
|
+
if (typeof floAvatar === 'function') {
|
|
5577
|
+
const flo = document.createElement('span'); flo.className = 'ai-chat-approval-flo';
|
|
5578
|
+
card.classList.add('has-flo'); card.append(flo);
|
|
5579
|
+
floAvatar(flo, { size: 28, mood: 'yourcall', hat: true });
|
|
5580
|
+
}
|
|
5581
|
+
ui.approvalTray.append(card);
|
|
5582
|
+
}
|
|
5583
|
+
// A repaint keeps keyboard focus (and the caret in the answer box) on the same control.
|
|
5584
|
+
const focused = !fresh && card.contains(document.activeElement) ? document.activeElement : null;
|
|
5585
|
+
const refocus = focused?.dataset?.commandId || null;
|
|
5586
|
+
let caret = null;
|
|
5587
|
+
try { if (focused && typeof focused.selectionStart === 'number') caret = [focused.selectionStart, focused.selectionEnd]; } catch { caret = null; }
|
|
5588
|
+
window.FlolessQuestionCard.paint(card, {
|
|
5589
|
+
id: approval.approvalId, questions: approval.question.questions, draft: entry.draft, busy: entry.busy, error: entry.error,
|
|
5590
|
+
// #2223 Revision 6: an async question's answer is the person's next message, its files that message's files.
|
|
5591
|
+
// Operator ruling 2026-10-12 (review round 4): an async question's answer is the person's next message, so its files
|
|
5592
|
+
// go with a message from the box, whose paperclip attaches them; its Other… box takes words only.
|
|
5593
|
+
files: approval.async ? null : questionFiles(approval),
|
|
5594
|
+
...(approval.async ? { otherHint: 'Type your own answer, or write it in the message box below to attach a file' } : {}),
|
|
5595
|
+
repaint: () => paintQuestionCard(approval, card),
|
|
5596
|
+
submit: () => { void (approval.async ? submitAsyncQuestion(approval) : submitQuestion(approval)); },
|
|
5597
|
+
});
|
|
5598
|
+
const target = refocus ? [...card.querySelectorAll('[data-command-id]')].find((node) => node.dataset.commandId === refocus) : null;
|
|
5599
|
+
if (target) {
|
|
5600
|
+
target.focus({ preventScroll: true });
|
|
5601
|
+
if (caret) { try { target.setSelectionRange(caret[0], caret[1]); } catch { /* no caret on this control */ } }
|
|
5602
|
+
} else if (focused || (fresh && !personIsTyping())) {
|
|
5603
|
+
// A new question: the recommended answer has focus, unless the person is typing a message.
|
|
5604
|
+
window.FlolessQuestionCard.focusCursor(card);
|
|
5605
|
+
if (fresh && !card.contains(document.activeElement)) focusQuestionWhenShown(card);
|
|
5606
|
+
}
|
|
5607
|
+
// A new card opens at its top, where the question and the recommended answer are: scrolled to its end, a card taller
|
|
5608
|
+
// than the tray hid both (UX review). A repaint keeps the control in use in sight; the actions row sticks anyway.
|
|
5609
|
+
const tray = ui.approvalTray;
|
|
5610
|
+
if (fresh) tray.scrollTop += card.getBoundingClientRect().top - tray.getBoundingClientRect().top;
|
|
5611
|
+
// In the Other… box that is the whole box, so a file just attached shows its chip (E2E 2026-10-12: it landed out of sight).
|
|
5612
|
+
else if (card.contains(document.activeElement)) {
|
|
5613
|
+
(document.activeElement.closest('.ai-chat-ask-other') || document.activeElement).scrollIntoView?.({ block: 'nearest' });
|
|
5614
|
+
}
|
|
5615
|
+
}
|
|
5616
|
+
|
|
5617
|
+
/**
|
|
5618
|
+
* A question that arrives while AI Chat is collapsed (or the page is reloaded with the chat closed) cannot take focus
|
|
5619
|
+
* — a hidden element refuses it — so the number keys would do nothing once the person opens the chat (E2E 2026-10-12).
|
|
5620
|
+
* It takes focus the first time it is shown, unless the person is typing somewhere by then.
|
|
5621
|
+
*/
|
|
5622
|
+
/**
|
|
5623
|
+
* Someone is writing: words in the message box, or any other text field (a chat being renamed, a search). A new question
|
|
5624
|
+
* card never takes focus from them, or the next digit they type would choose an answer (code review 2026-10-12). An empty
|
|
5625
|
+
* message box is where the person just sent from, so the card may take focus from it.
|
|
5626
|
+
*/
|
|
5627
|
+
function personIsTyping() {
|
|
5628
|
+
const active = document.activeElement;
|
|
5629
|
+
if (!active || active === document.body) return false;
|
|
5630
|
+
if (active === ui.input) return Boolean(ui.input.value);
|
|
5631
|
+
return Boolean(active.isContentEditable) || /^(INPUT|TEXTAREA|SELECT)$/.test(active.tagName);
|
|
5632
|
+
}
|
|
5633
|
+
|
|
5634
|
+
function focusQuestionWhenShown(card) {
|
|
5635
|
+
const Observer = window.IntersectionObserver;
|
|
5636
|
+
if (typeof Observer !== 'function') return;
|
|
5637
|
+
const watch = new Observer((entries) => {
|
|
5638
|
+
if (!entries.some((entry) => entry.isIntersecting)) return;
|
|
5639
|
+
watch.disconnect();
|
|
5640
|
+
if (card.isConnected && !personIsTyping()) window.FlolessQuestionCard.focusCursor(card);
|
|
5641
|
+
});
|
|
5642
|
+
watch.observe(card);
|
|
5643
|
+
}
|
|
5644
|
+
|
|
5645
|
+
async function submitQuestion(approval) {
|
|
5646
|
+
const entry = questionEntry(approval);
|
|
5647
|
+
const snapshot = captureChat();
|
|
5648
|
+
if (!snapshot || entry.busy) return;
|
|
5649
|
+
const questions = approval.question.questions;
|
|
5650
|
+
const repaint = () => { const card = questionCardNode(approval.approvalId); if (card) paintQuestionCard(approval, card); };
|
|
5651
|
+
if (questions.some((_, index) => answerSource(questionScope(approval.approvalId, index)).uploading)) {
|
|
5652
|
+
entry.error = 'A file is still attaching. Wait for it to finish, then send.';
|
|
5653
|
+
repaint(); return;
|
|
5654
|
+
}
|
|
5655
|
+
const answers = window.FlolessQuestionCard.answersFor(questions, entry.draft, (index) => answerSource(questionScope(approval.approvalId, index)).files);
|
|
5656
|
+
entry.busy = 'Sending…'; entry.error = '';
|
|
5657
|
+
repaint();
|
|
5658
|
+
announce('Sending your answer to the AI…');
|
|
5659
|
+
try {
|
|
5660
|
+
const result = await request(`/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/approvals/${encodeURIComponent(approval.approvalId)}`, {
|
|
5661
|
+
method: 'POST', body: JSON.stringify({ owner: snapshot.scope.owner, decision: 'answer', answers }),
|
|
5662
|
+
});
|
|
5663
|
+
const outcome = result?.outcome;
|
|
5664
|
+
// The files now belong to the answer (or to a card that closed): forget the drafts and the chips' previews. The
|
|
5665
|
+
// card's state is settled even when the person has moved to another chat (code review 2026-10-12: returning first
|
|
5666
|
+
// left it saying "Sending…" for good); only what is painted and said waits for this chat.
|
|
5667
|
+
questionDrafts.delete(approval.approvalId);
|
|
5668
|
+
questions.forEach((_, index) => clearAnswerSource(questionScope(approval.approvalId, index)));
|
|
5669
|
+
if (!sameChat(snapshot)) return;
|
|
5670
|
+
// Code review 2026-10-12: the AI stopped before the answer reached it, so the person's own words go back in the
|
|
5671
|
+
// message box (after anything already there) to send once it can take them; the conversation's record keeps them too.
|
|
5672
|
+
const kept = outcome?.outcome === 'lost' && typeof outcome.otherText === 'string' && outcome.otherText ? outcome.otherText : '';
|
|
5673
|
+
if (kept) {
|
|
5674
|
+
const words = ui.input.value.trim();
|
|
5675
|
+
ui.input.value = words ? `${words}\n\n${kept}` : kept;
|
|
5676
|
+
ui.input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
5677
|
+
}
|
|
5678
|
+
announce(outcome?.delivered ? 'Your answer was handed to the AI.'
|
|
5679
|
+
: `${outcome?.message || 'The question closed before your answer reached the AI.'}${kept ? ' Your words are back in the message box.' : ''}`);
|
|
5680
|
+
await refreshConversation(snapshot.chatId, false);
|
|
5681
|
+
} catch (error) {
|
|
5682
|
+
entry.busy = '';
|
|
5683
|
+
// The server says what happened in words; anything else (FloLess unreachable) gets a sentence of its own.
|
|
5684
|
+
entry.error = error?.code && error?.message ? error.message
|
|
5685
|
+
: 'FloLess could not send your answer just now. Make sure FloLess is still running, then send it again.';
|
|
5686
|
+
if (error?.code === 'answer-evidence-unknown') {
|
|
5687
|
+
for (const [index] of questions.entries()) {
|
|
5688
|
+
const source = answerSources.get(questionScope(approval.approvalId, index));
|
|
5689
|
+
if (!source) continue;
|
|
5690
|
+
for (const file of source.files) if (file.url) URL.revokeObjectURL(file.url);
|
|
5691
|
+
source.files = [];
|
|
5692
|
+
}
|
|
5693
|
+
}
|
|
5694
|
+
if (!sameChat(snapshot)) return;
|
|
5695
|
+
repaint();
|
|
5696
|
+
announce(entry.error);
|
|
5697
|
+
await refreshConversation(snapshot.chatId, false);
|
|
5698
|
+
}
|
|
5699
|
+
}
|
|
5700
|
+
|
|
5701
|
+
/**
|
|
5702
|
+
* #2223: the conversation's record of a question card: the question, ✓ the person's answer, the files they attached —
|
|
5703
|
+
* or, when the card closed without their answer reaching the AI, the plain sentence the server wrote.
|
|
5704
|
+
*/
|
|
5705
|
+
function renderQuestionAnswered(event) {
|
|
5706
|
+
const payload = event.payload || {};
|
|
5707
|
+
const answered = payload.outcome === 'answered';
|
|
5708
|
+
const item = document.createElement('div');
|
|
5709
|
+
item.className = `ai-chat-event ai-chat-ask-answered${answered ? '' : ' is-unanswered'}`;
|
|
5710
|
+
item.dataset.eventSequence = String(event.sequence);
|
|
5711
|
+
item.dataset.eventId = event.eventId;
|
|
5712
|
+
const rows = Array.isArray(payload.answers) ? payload.answers : [];
|
|
5713
|
+
const filesOf = (row) => (Array.isArray(row?.files) ? row.files.filter((file) => file && typeof file.attachmentId === 'string') : []);
|
|
5714
|
+
const gave = (row) => Boolean(typeof row?.answer === 'string' && row.answer) || filesOf(row).length > 0;
|
|
5715
|
+
// Code review 2026-10-12: an answer that did not reach the AI, or may not have, keeps what the person gave; the note
|
|
5716
|
+
// below says what became of it. Only a delivered answer carries the tick.
|
|
5717
|
+
const kept = !answered && rows.some(gave);
|
|
5718
|
+
const label = document.createElement('strong');
|
|
5719
|
+
label.textContent = answered ? 'You answered' : kept ? 'Your answer' : 'Not answered';
|
|
5720
|
+
item.append(label);
|
|
5721
|
+
for (const row of rows) {
|
|
5722
|
+
const line = document.createElement('div'); line.className = 'ai-chat-ask-answered-row';
|
|
5723
|
+
const asked = document.createElement('span'); asked.className = 'ai-chat-ask-answered-q';
|
|
5724
|
+
asked.textContent = typeof row?.question === 'string' ? row.question : '';
|
|
5725
|
+
line.append(asked);
|
|
5726
|
+
const files = answered || kept ? filesOf(row) : [];
|
|
5727
|
+
if (answered || (kept && gave(row))) {
|
|
5728
|
+
const reply = document.createElement('span'); reply.className = 'ai-chat-ask-answered-a';
|
|
5729
|
+
if (answered) {
|
|
5730
|
+
const tick = document.createElement('span'); tick.className = 'ai-chat-ask-tick'; tick.setAttribute('aria-hidden', 'true'); tick.textContent = '✓';
|
|
5731
|
+
reply.append(tick);
|
|
5732
|
+
}
|
|
5733
|
+
reply.append(document.createTextNode(typeof row?.answer === 'string' && row.answer ? row.answer : files.length ? 'See the attached file' : 'Answered'));
|
|
5734
|
+
line.append(reply);
|
|
5735
|
+
}
|
|
5736
|
+
if (files.length) {
|
|
5737
|
+
const chips = document.createElement('div'); chips.className = 'ai-chat-message-attachments ai-chat-ask-answered-files';
|
|
5738
|
+
chips.append(...files.map((file) => renderChatAttachment({ attachmentId: file.attachmentId, fileName: String(file.fileName || 'file'),
|
|
5739
|
+
mediaType: String(file.mediaType || '') })));
|
|
5740
|
+
line.append(chips);
|
|
5741
|
+
}
|
|
5742
|
+
item.append(line);
|
|
5743
|
+
}
|
|
5744
|
+
if (!answered && typeof payload.message === 'string' && payload.message) {
|
|
5745
|
+
const note = document.createElement('p'); note.className = 'ai-chat-ask-answered-note'; note.textContent = payload.message;
|
|
5746
|
+
item.append(note);
|
|
5747
|
+
}
|
|
5748
|
+
return item;
|
|
5749
|
+
}
|
|
5750
|
+
|
|
5751
|
+
/*
|
|
5752
|
+
* #2223 Revision 6 — Codex's async question (measured 2026-10-12, codex-cli 0.162.1). Codex can ask without waiting: the
|
|
5753
|
+
* question rides on the assistant message that asks it (`asyncQuestion`, shaped by the server like any card), the reply
|
|
5754
|
+
* goes on, and Codex's own app sends the person's answer as their next message. So the question stays open until the
|
|
5755
|
+
* person's next message: the latest such message with no message of the person's after it, in a conversation that is not
|
|
5756
|
+
* archived. A message still on its way (optimistic) does not close it, so a send that fails leaves the card as it was;
|
|
5757
|
+
* the message the person types in the box instead is an answer too, and closes it the same way. Reading the
|
|
5758
|
+
* conversation again (a reload) finds it again: it is all in the stored events.
|
|
5759
|
+
*/
|
|
5760
|
+
function openAsyncQuestion(events, chat) {
|
|
5761
|
+
if (!chat || chat.archivedAt || !Array.isArray(events)) return null;
|
|
5762
|
+
for (let index = events.length - 1; index >= 0; index -= 1) {
|
|
5763
|
+
const event = events[index];
|
|
5764
|
+
if (event?.type === 'user-message' && !event.optimistic) return null;
|
|
5765
|
+
const set = event?.type === 'assistant-message' ? event.payload?.asyncQuestion : null;
|
|
5766
|
+
if (!set) continue;
|
|
5767
|
+
// The latest question decides: one the card cannot show is no card, never an older one in its place.
|
|
5768
|
+
const shown = Array.isArray(set.questions) && set.questions.length > 0 && set.questions.every((question) => question
|
|
5769
|
+
&& typeof question.id === 'string' && typeof question.question === 'string' && Array.isArray(question.options)
|
|
5770
|
+
&& question.options.every((option) => option && typeof option.label === 'string' && typeof option.shown === 'string'));
|
|
5771
|
+
return shown ? { approvalId: event.eventId, async: true, question: { questions: set.questions } } : null;
|
|
5772
|
+
}
|
|
5773
|
+
return null;
|
|
5774
|
+
}
|
|
5775
|
+
|
|
5776
|
+
/**
|
|
5777
|
+
* The answer as the message Codex's own app would send: the chosen answer's own label (as the AI wrote it), or the
|
|
5778
|
+
* person's words; with several questions, one line each, "<question>: <answer>".
|
|
5779
|
+
*/
|
|
5780
|
+
function asyncAnswerMessage(questions, draft) {
|
|
5781
|
+
const answers = questions.map((question, index) => {
|
|
5782
|
+
const row = draft.rows[index];
|
|
5783
|
+
const parts = [...row.choices].sort((a, b) => a - b).map((choice) => question.options[choice]?.shown).filter(Boolean);
|
|
5784
|
+
const own = row.otherOpen ? row.other.trim() : '';
|
|
5785
|
+
if (own) parts.push(own);
|
|
5786
|
+
return parts.join(', ');
|
|
5787
|
+
});
|
|
5788
|
+
return questions.length === 1 ? answers[0]
|
|
5789
|
+
: questions.map((question, index) => `${question.question.replace(/\s+/g, ' ').trim()}: ${answers[index]}`).join('\n');
|
|
5790
|
+
}
|
|
5791
|
+
|
|
5792
|
+
|
|
5793
|
+
/**
|
|
5794
|
+
* Sending an async question's answer: an ordinary message through the chat's own send (a new turn, or a follow-up while
|
|
5795
|
+
* the reply still runs). The card shows "Sending…" and closes when that message is in the conversation; one that did not
|
|
5796
|
+
* go keeps the card and the draft, and says why on the card.
|
|
5797
|
+
*/
|
|
5798
|
+
async function submitAsyncQuestion(approval) {
|
|
5799
|
+
const entry = questionEntry(approval);
|
|
5800
|
+
const snapshot = captureChat();
|
|
5801
|
+
if (!snapshot || entry.busy) return;
|
|
5802
|
+
const questions = approval.question.questions;
|
|
5803
|
+
const repaint = () => { const card = questionCardNode(approval.approvalId); if (card) paintQuestionCard(approval, card); };
|
|
5804
|
+
const text = asyncAnswerMessage(questions, entry.draft);
|
|
5805
|
+
entry.busy = 'Sending…'; entry.error = '';
|
|
5806
|
+
repaint();
|
|
5807
|
+
let result;
|
|
5808
|
+
try { result = await sendTurn({ message: { text, attachments: [] } }); }
|
|
5809
|
+
catch (error) { result = { sent: false, message: errorMessage(error) }; }
|
|
5810
|
+
// Settled whichever chat is open now; only painting and announcing wait for this one (code review 2026-10-12).
|
|
5811
|
+
entry.busy = '';
|
|
5812
|
+
if (result?.sent === true) {
|
|
5813
|
+
questionDrafts.delete(approval.approvalId);
|
|
5814
|
+
if (sameChat(snapshot)) paintApproval();
|
|
5815
|
+
return;
|
|
5816
|
+
}
|
|
5817
|
+
entry.error = result?.message || 'Your answer was not sent. Send it again.';
|
|
5818
|
+
if (!sameChat(snapshot)) return;
|
|
5819
|
+
repaint();
|
|
5820
|
+
announce(entry.error);
|
|
5821
|
+
}
|
|
5822
|
+
|
|
5270
5823
|
/**
|
|
5271
5824
|
* #1900 — the card for a connection check the AI asked for. The server's summary is the whole question; the two
|
|
5272
5825
|
* things that decide it (a tool FloLess has not reviewed, a key sent to an address) are pulled out onto their own
|
|
@@ -5989,16 +6542,27 @@
|
|
|
5989
6542
|
function selectedModel() {
|
|
5990
6543
|
if (!state.capability) return null;
|
|
5991
6544
|
return state.capability.models.find((model) => model.id === state.chat?.settings.model)
|
|
6545
|
+
|| coveringModel(state.capability.models, state.chat?.settings.model)
|
|
5992
6546
|
|| preferredModel(state.chat?.provider, state.capability.models)
|
|
5993
6547
|
|| state.capability.models.find((model) => model.isDefault)
|
|
5994
6548
|
|| state.capability.models[0] || null;
|
|
5995
6549
|
}
|
|
5996
6550
|
|
|
6551
|
+
// #2232: a stored id the runtime stopped listing (`opus[1m]`, `claude-fable-5-1[1m]` before Claude Code 2.1.296) is the
|
|
6552
|
+
// offered row that runs the same model; the 1M variant is no longer offered, so its `[1m]` suffix is set aside.
|
|
6553
|
+
function coveringModel(models, stored) {
|
|
6554
|
+
const base = typeof stored === 'string' ? stored.replace(/\[1m\]$/i, '') : '';
|
|
6555
|
+
if (!base) return null;
|
|
6556
|
+
// The exact id first; then a named row running that model, never `default`, whose model changes between releases.
|
|
6557
|
+
return models.find((model) => model.id === base)
|
|
6558
|
+
|| models.find((model) => model.id !== 'default' && model.resolvedModel === base) || null;
|
|
6559
|
+
}
|
|
6560
|
+
|
|
5997
6561
|
// In order of preference; keep in step with PREFERRED_MODELS in server/chat-routes.ts. Without
|
|
5998
|
-
// GPT-6-Sol nothing is preferred, so the provider's own default row is shown and used.
|
|
6562
|
+
// GPT-6.1-Sol or GPT-6-Sol nothing is preferred, so the provider's own default row is shown and used.
|
|
5999
6563
|
function preferredModel(provider, models) {
|
|
6000
6564
|
if (!provider || !Array.isArray(models)) return null;
|
|
6001
|
-
const patterns = provider === 'codex' ? [/gpt[- .]?6[- .]?sol/i] : [/opus[- .]?5\.5/i, /opus/i];
|
|
6565
|
+
const patterns = provider === 'codex' ? [/gpt[- .]?6\.1[- .]?sol/i, /gpt[- .]?6[- .]?sol/i] : [/opus[- .]?5\.5/i, /opus/i];
|
|
6002
6566
|
for (const pattern of patterns) {
|
|
6003
6567
|
const found = models.find((model) => pattern.test(`${model.id} ${model.label}`));
|
|
6004
6568
|
if (found) return found;
|
|
@@ -6160,9 +6724,9 @@
|
|
|
6160
6724
|
ui.permission.dataset.tip = instructorChat
|
|
6161
6725
|
? '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.'
|
|
6162
6726
|
: permissionTip(chat?.settings.permissionProfile);
|
|
6163
|
-
// #
|
|
6727
|
+
// #2234: the Guide's Access is chosen like any conversation's (it starts Read only). Its own controls — the morning
|
|
6728
|
+
// briefing, set-aside suggestions, Turn off and Delete history — keep their cell, shown only in a Guide conversation.
|
|
6164
6729
|
const guideChat = chat?.initiator?.kind === 'guide';
|
|
6165
|
-
ui.permission.hidden = guideChat;
|
|
6166
6730
|
if (ui.guideAccess) ui.guideAccess.hidden = !guideChat;
|
|
6167
6731
|
// #2053: the Guide's morning briefing lives here too; web/guide.js paints it (only when something changed).
|
|
6168
6732
|
if (guideChat) window.flolessGuide?.paintBriefing?.();
|
|
@@ -6248,13 +6812,21 @@
|
|
|
6248
6812
|
|
|
6249
6813
|
function paintRecovery() {
|
|
6250
6814
|
paintMoveNotice();
|
|
6815
|
+
// Recovery authority/explanations belong to one UUID turn, never to the shared panel.
|
|
6816
|
+
if (state.recoveryTurnId !== state.chat?.activeTurn?.turnId) {
|
|
6817
|
+
state.recoveryCanEnd = false;
|
|
6818
|
+
state.recoveryMessage = null;
|
|
6819
|
+
state.recoveryTurnId = null;
|
|
6820
|
+
}
|
|
6251
6821
|
const recovery = state.chat?.state === 'recovery';
|
|
6252
6822
|
ui.recovery.hidden = !recovery;
|
|
6253
6823
|
ui.recoveryStop.hidden = !recovery;
|
|
6254
6824
|
ui.recoveryStop.textContent = state.recoveryCanEnd ? 'End recovery' : 'Stop response';
|
|
6825
|
+
ui.recoveryStop.dataset.commandId = state.recoveryCanEnd ? 'shell.chat-end-recovery' : 'shell.chat-stop';
|
|
6255
6826
|
ui.recoveryCopy.textContent = recovery
|
|
6256
6827
|
? (state.recoveryMessage || 'FloLess needs to check the last AI response before sending another message.')
|
|
6257
6828
|
: '';
|
|
6829
|
+
paintStopState();
|
|
6258
6830
|
}
|
|
6259
6831
|
|
|
6260
6832
|
function paintConversation() {
|
|
@@ -6371,6 +6943,9 @@
|
|
|
6371
6943
|
if (event.type === 'chat-subjects') subjectLinksSaved(event.payload);
|
|
6372
6944
|
// So does the Tekla questions card, once any selection receipt in this pane has shown one (#1653 stage 4).
|
|
6373
6945
|
if (event.type === 'chat-subjects' && state.teklaHistoryHost) void loadTeklaLinks(true);
|
|
6946
|
+
// #2255: only an event new to this window is taken; one read from history never is.
|
|
6947
|
+
if (event.type === 'view-command') takeViewCommand(event);
|
|
6948
|
+
if (event.type === 'view-command-update' && typeof event.payload?.line === 'string') announce(`Model view. ${event.payload.line.replace(/ · /g, '. ')}`);
|
|
6374
6949
|
state.events.sort((a, b) => a.sequence - b.sequence);
|
|
6375
6950
|
state.chat.lastEventSequence = Math.max(state.chat.lastEventSequence || 0, event.sequence || 0);
|
|
6376
6951
|
const listChat = state.chats.find((item) => item.chatId === chatId);
|
|
@@ -6401,6 +6976,8 @@
|
|
|
6401
6976
|
if (notices[event.payload?.deliveryState]) announce(notices[event.payload.deliveryState]);
|
|
6402
6977
|
}
|
|
6403
6978
|
paintEvents(); paintUnread();
|
|
6979
|
+
// #2223 Revision 6: a message that asks a question without waiting opens its card; the person's next message closes it.
|
|
6980
|
+
if (event.type === 'user-message' || event.payload?.asyncQuestion) paintApproval();
|
|
6404
6981
|
if (!document.hidden && !ui.feed.closest('[hidden]')) markRead();
|
|
6405
6982
|
if (['approval-requested', 'approval-decided', 'error', 'interrupted', 'state', 'followup-status'].includes(event.type)
|
|
6406
6983
|
|| (event.type === 'user-message' && event.payload?.followup)) {
|
|
@@ -6508,6 +7085,7 @@
|
|
|
6508
7085
|
}
|
|
6509
7086
|
if (!sameChat(snapshot)) return;
|
|
6510
7087
|
state.chat = chat;
|
|
7088
|
+
// #2223 Revision 6: a file on the open question card's answer goes with that answer, not with the box's next message.
|
|
6511
7089
|
state.attachments = composerDrafts(chat);
|
|
6512
7090
|
const index = state.chats.findIndex((item) => item.chatId === chatId);
|
|
6513
7091
|
if (index >= 0) state.chats[index] = chat;
|
|
@@ -6789,7 +7367,7 @@
|
|
|
6789
7367
|
const label = (value) => (value === 'mm' ? 'Metric (mm)' : 'ft-in');
|
|
6790
7368
|
// Settings repaint on every chat event; rebuilding unchanged buttons would swap them out from under a click.
|
|
6791
7369
|
const painted = `${chat.chatId}|${chosen}|${units.suggested ?? null}|${Boolean(state.workspaceUnitsEditing)}`;
|
|
6792
|
-
if (
|
|
7370
|
+
if (host.dataset.painted === painted) return;
|
|
6793
7371
|
host.dataset.painted = painted;
|
|
6794
7372
|
host.hidden = false;
|
|
6795
7373
|
host.replaceChildren();
|
|
@@ -6804,48 +7382,16 @@
|
|
|
6804
7382
|
change.setAttribute('aria-label', 'Change units');
|
|
6805
7383
|
change.dataset.commandId = 'shell.chat-units-change';
|
|
6806
7384
|
change.dataset.tip = 'Choose the units AI answers in, in this conversation';
|
|
6807
|
-
change.addEventListener('click', () => { state.workspaceUnitsEditing = true; paintWorkspaceUnits();
|
|
7385
|
+
change.addEventListener('click', () => { state.workspaceUnitsEditing = true; paintWorkspaceUnits();
|
|
7386
|
+
const entry = state.workspaceUnitsQuestions?.get(chat.chatId);
|
|
7387
|
+
if (entry?.slotNode?.isConnected) window.FlolessQuestionCard.focusCursor(entry.slotNode);
|
|
7388
|
+
});
|
|
6808
7389
|
host.append(text, change);
|
|
6809
7390
|
return;
|
|
6810
7391
|
}
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
|
|
6814
|
-
question.textContent = 'Which units should AI use here?';
|
|
6815
|
-
const group = document.createElement('div');
|
|
6816
|
-
group.className = 'ai-chat-units-options';
|
|
6817
|
-
group.setAttribute('role', 'radiogroup');
|
|
6818
|
-
group.setAttribute('aria-labelledby', 'chat-units-question');
|
|
6819
|
-
const suggested = units.suggested === 'mm' || units.suggested === 'ft-in' ? units.suggested : null;
|
|
6820
|
-
const options = ['ft-in', 'mm'];
|
|
6821
|
-
for (const value of options) {
|
|
6822
|
-
const option = document.createElement('button');
|
|
6823
|
-
option.type = 'button';
|
|
6824
|
-
option.className = 'ai-chat-units-option';
|
|
6825
|
-
option.setAttribute('role', 'radio');
|
|
6826
|
-
const checked = chosen ? chosen === value : suggested === value;
|
|
6827
|
-
option.setAttribute('aria-checked', String(Boolean(chosen && chosen === value)));
|
|
6828
|
-
option.tabIndex = checked || (!chosen && !suggested && value === 'ft-in') ? 0 : -1;
|
|
6829
|
-
option.dataset.commandId = `shell.chat-units-choose#${value}`;
|
|
6830
|
-
option.dataset.commandInstanceLabel = label(value);
|
|
6831
|
-
if (suggested === value && !chosen) option.classList.add('is-suggested');
|
|
6832
|
-
option.textContent = label(value);
|
|
6833
|
-
if (suggested === value && !chosen) {
|
|
6834
|
-
const hint = document.createElement('span');
|
|
6835
|
-
hint.className = 'ai-chat-units-hint';
|
|
6836
|
-
hint.textContent = ' · last project';
|
|
6837
|
-
option.append(hint);
|
|
6838
|
-
}
|
|
6839
|
-
option.addEventListener('click', () => { void chooseWorkspaceUnits(value); });
|
|
6840
|
-
option.addEventListener('keydown', (event) => {
|
|
6841
|
-
if (event.key !== 'ArrowRight' && event.key !== 'ArrowLeft' && event.key !== 'ArrowDown' && event.key !== 'ArrowUp') return;
|
|
6842
|
-
event.preventDefault();
|
|
6843
|
-
const next = group.querySelectorAll('[role="radio"]')[value === 'ft-in' ? 1 : 0];
|
|
6844
|
-
next?.focus();
|
|
6845
|
-
});
|
|
6846
|
-
group.append(option);
|
|
6847
|
-
}
|
|
6848
|
-
host.append(question, group);
|
|
7392
|
+
host.hidden = true;
|
|
7393
|
+
drawingSlotRepaint();
|
|
7394
|
+
return;
|
|
6849
7395
|
}
|
|
6850
7396
|
|
|
6851
7397
|
async function chooseWorkspaceUnits(value) {
|
|
@@ -6855,15 +7401,17 @@
|
|
|
6855
7401
|
const updated = await request(`/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/workspace-units`, {
|
|
6856
7402
|
method: 'PUT', body: JSON.stringify({ owner: snapshot.scope.owner, units: value }),
|
|
6857
7403
|
});
|
|
6858
|
-
if (!sameChat(snapshot)) return;
|
|
7404
|
+
if (!sameChat(snapshot)) return updated.workspaceUnits;
|
|
6859
7405
|
state.chat = { ...state.chat, workspaceUnits: updated.workspaceUnits };
|
|
6860
7406
|
state.workspaceUnitsEditing = false;
|
|
6861
7407
|
paintWorkspaceUnits();
|
|
6862
7408
|
void refreshDisplayUnits();
|
|
6863
7409
|
announce(`Units set to ${value === 'mm' ? 'metric (millimetres)' : 'feet and inches'}.`);
|
|
6864
7410
|
ui.workspaceUnits?.querySelector('.ai-chat-units-change')?.focus();
|
|
7411
|
+
return updated.workspaceUnits;
|
|
6865
7412
|
} catch (error) {
|
|
6866
7413
|
report(error, 'Could not save the units for this conversation');
|
|
7414
|
+
return false;
|
|
6867
7415
|
}
|
|
6868
7416
|
}
|
|
6869
7417
|
|
|
@@ -6881,7 +7429,7 @@
|
|
|
6881
7429
|
const chat = await request('/api/chat/conversations', {
|
|
6882
7430
|
method: 'POST', body: JSON.stringify({
|
|
6883
7431
|
owner, provider, title: 'New chat',
|
|
6884
|
-
// #2037: no access level — the server starts
|
|
7432
|
+
// #2037/#2234: no access level — the server starts every new conversation in Auto.
|
|
6885
7433
|
settings: { model: null, effort: null },
|
|
6886
7434
|
initiator: { kind: 'user' },
|
|
6887
7435
|
...(displayUnitsSuggestion ? { displayUnitsSuggestion } : {}),
|
|
@@ -7010,7 +7558,6 @@
|
|
|
7010
7558
|
|
|
7011
7559
|
function closePicker() {
|
|
7012
7560
|
state.picker = null; state.pickerOpener = null; ui.picker.hidden = true; ui.picker.replaceChildren();
|
|
7013
|
-
ui.picker.removeAttribute('aria-describedby');
|
|
7014
7561
|
for (const control of [ui.model, ui.effort, ui.permission, ui.integrations]) control.setAttribute('aria-expanded', 'false');
|
|
7015
7562
|
}
|
|
7016
7563
|
|
|
@@ -7022,7 +7569,7 @@
|
|
|
7022
7569
|
if (opener?.isConnected && !opener.disabled) opener.focus();
|
|
7023
7570
|
}
|
|
7024
7571
|
|
|
7025
|
-
function openPicker(kind, anchor, choices
|
|
7572
|
+
function openPicker(kind, anchor, choices) {
|
|
7026
7573
|
if (anchor.disabled) return;
|
|
7027
7574
|
if (state.picker === kind) { closePicker(); return; }
|
|
7028
7575
|
toggleHistory(false); closePicker(); state.picker = kind; state.pickerOpener = anchor;
|
|
@@ -7037,11 +7584,6 @@
|
|
|
7037
7584
|
row.addEventListener('click', async () => { closePicker(); await saveSettings(choice.patch); anchor.focus(); });
|
|
7038
7585
|
ui.picker.append(row);
|
|
7039
7586
|
}
|
|
7040
|
-
// A quiet line after the choices says why one is missing; it is not an option, so the list is described by it.
|
|
7041
|
-
if (note) {
|
|
7042
|
-
const line = document.createElement('div'); line.className = 'ai-chat-picker-note'; line.id = 'chat-picker-note'; line.textContent = note;
|
|
7043
|
-
ui.picker.append(line); ui.picker.setAttribute('aria-describedby', line.id);
|
|
7044
|
-
}
|
|
7045
7587
|
ui.picker.hidden = false; anchor.setAttribute('aria-expanded', 'true');
|
|
7046
7588
|
const selected = ui.picker.querySelector('[aria-selected="true"]') || ui.picker.querySelector('button');
|
|
7047
7589
|
selected?.focus();
|
|
@@ -7121,6 +7663,15 @@
|
|
|
7121
7663
|
}
|
|
7122
7664
|
const settings = { ...state.chat.settings, ...patch };
|
|
7123
7665
|
if ('model' in patch && !('effort' in patch)) settings.effort = null;
|
|
7666
|
+
// A model the runtime stopped listing (an update renamed it) is saved as the row the picker shows for it, the one
|
|
7667
|
+
// running the same model where there is one (coveringModel), so changing Effort or Access is never refused.
|
|
7668
|
+
// Only against a list the provider actually returned: an empty one (the check failed) proves nothing about the model.
|
|
7669
|
+
if (!('model' in patch) && settings.model && state.capability?.available && state.capability.models.length
|
|
7670
|
+
&& !state.capability.models.some((model) => model.id === settings.model)) {
|
|
7671
|
+
const shown = selectedModel();
|
|
7672
|
+
settings.model = shown?.id ?? null;
|
|
7673
|
+
if (!shown?.efforts?.includes(settings.effort)) settings.effort = null;
|
|
7674
|
+
}
|
|
7124
7675
|
try {
|
|
7125
7676
|
const chat = await request(`/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/settings`, {
|
|
7126
7677
|
method: 'PUT', body: JSON.stringify({ owner: snapshot.scope.owner, ...settings, ...(release ? { releaseInstructorAnswer: true } : {}) }),
|
|
@@ -7139,9 +7690,11 @@
|
|
|
7139
7690
|
|
|
7140
7691
|
function modelChoices() {
|
|
7141
7692
|
const models = state.capability?.models || [];
|
|
7142
|
-
|
|
7693
|
+
const shown = selectedModel()?.id;
|
|
7694
|
+
// #2232: an older model the provider's own picker no longer offers is listed only for a chat already on it.
|
|
7695
|
+
return models.filter((model) => !model.legacy || model.id === shown).map((model) => ({
|
|
7143
7696
|
id: `model:${model.id}`, label: model.label, meta: model.detail || '',
|
|
7144
|
-
selected:
|
|
7697
|
+
selected: shown === model.id, patch: { model: model.id },
|
|
7145
7698
|
}));
|
|
7146
7699
|
}
|
|
7147
7700
|
|
|
@@ -7151,9 +7704,8 @@
|
|
|
7151
7704
|
selected: (state.chat.settings.effort || 'medium').toLowerCase() === effort.toLowerCase(), patch: { effort } }));
|
|
7152
7705
|
}
|
|
7153
7706
|
|
|
7154
|
-
/** #
|
|
7707
|
+
/** #2234 (owner ruling 2026-10-12, one Access vocabulary everywhere): the same label in every conversation. */
|
|
7155
7708
|
function permissionLabel(value) {
|
|
7156
|
-
if (state.scope?.owner?.kind === 'workspace' && value === 'workspace-write') return 'Make changes (asks first)';
|
|
7157
7709
|
return permissionLabels[value] || 'Read only';
|
|
7158
7710
|
}
|
|
7159
7711
|
|
|
@@ -7167,7 +7719,7 @@
|
|
|
7167
7719
|
return state.chat?.provider === 'claude' && selectedModel()?.autoMode === false ? 'model' : null;
|
|
7168
7720
|
}
|
|
7169
7721
|
|
|
7170
|
-
function permissionMeta(value
|
|
7722
|
+
function permissionMeta(value) {
|
|
7171
7723
|
if (value === 'read-only') return 'Looks and answers. Changes nothing.';
|
|
7172
7724
|
if (value === 'auto') {
|
|
7173
7725
|
const why = autoUnavailable();
|
|
@@ -7175,36 +7727,39 @@
|
|
|
7175
7727
|
if (why === 'accounts') return 'With a FloLess account selected, the AI asks you before steps that need approval.';
|
|
7176
7728
|
return why ? 'Not available with this model. It asks before changes.' : 'Does safe work by itself. Checks risky steps first.';
|
|
7177
7729
|
}
|
|
7178
|
-
if (value === 'workspace-write') return
|
|
7730
|
+
if (value === 'workspace-write') return 'Asks you whenever the AI needs approval.';
|
|
7179
7731
|
return 'Can change any file on this computer.';
|
|
7180
7732
|
}
|
|
7181
7733
|
|
|
7182
7734
|
function permissionTip(value) {
|
|
7183
|
-
if (state.scope?.owner?.kind === 'workspace') return `Access: ${permissionLabel(value)}. Full access and Auto are offered only inside a project or workflow.`;
|
|
7184
7735
|
const why = value === 'auto' ? autoUnavailable() : null;
|
|
7185
7736
|
const label = why === 'connectors' ? 'Auto (asking first while your connectors are on)'
|
|
7186
7737
|
: why === 'accounts' ? 'Auto (asking first while a FloLess account is selected)'
|
|
7187
7738
|
: why ? 'Auto (asking first with this model)' : permissionLabel(value);
|
|
7188
|
-
return `Access: ${label}. ${permissionMeta(value || 'read-only'
|
|
7739
|
+
return `Access: ${label}. ${permissionMeta(value || 'read-only')}`;
|
|
7189
7740
|
}
|
|
7190
7741
|
|
|
7191
7742
|
function permissionChoices() {
|
|
7192
|
-
// #
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
const offered = workspace
|
|
7196
|
-
? Object.keys(permissionLabels).filter((value) => value !== 'full-access' && value !== 'auto')
|
|
7197
|
-
: Object.keys(permissionLabels);
|
|
7198
|
-
return offered.map((value) => ({
|
|
7199
|
-
id: `permission:${value}`, label: permissionLabel(value), meta: permissionMeta(value, workspace),
|
|
7743
|
+
// #2234 (owner ruling 2026-10-12): every conversation offers all four levels — the workspace's and the Guide's too.
|
|
7744
|
+
return Object.keys(permissionLabels).map((value) => ({
|
|
7745
|
+
id: `permission:${value}`, label: permissionLabel(value), meta: permissionMeta(value),
|
|
7200
7746
|
// #2059: an Instructor answer has none of these yet ("No tools" is a state, not a choice).
|
|
7201
7747
|
selected: !isInstructorAnswer(state.chat) && state.chat.settings.permissionProfile === value, patch: { permissionProfile: value },
|
|
7202
7748
|
}));
|
|
7203
7749
|
}
|
|
7204
7750
|
|
|
7205
|
-
/**
|
|
7206
|
-
|
|
7207
|
-
|
|
7751
|
+
/**
|
|
7752
|
+
* #2234 (plan R2.3): said once, in the notes every conversation shares, wherever the AI may change files outside its
|
|
7753
|
+
* home folder without asking (Auto, Full access): such a change is not held back for a workflow run or other work on
|
|
7754
|
+
* the same files. Not said where Auto asks instead (autoUnavailable): there it would be untrue.
|
|
7755
|
+
*/
|
|
7756
|
+
function unaskedChangesNote() {
|
|
7757
|
+
return 'If the AI changes something outside your home folder without asking, that change is not held back while a workflow run or other work is using the same files.';
|
|
7758
|
+
}
|
|
7759
|
+
|
|
7760
|
+
/** Full access in this conversation's Scope view. */
|
|
7761
|
+
function fullAccessScopeNote() {
|
|
7762
|
+
return `Full access is on. The AI can change files without asking. ${unaskedChangesNote()}`;
|
|
7208
7763
|
}
|
|
7209
7764
|
|
|
7210
7765
|
/** #2037: what Auto means in this conversation's Scope view; Codex's review may approve a change outside the folder. */
|
|
@@ -7214,8 +7769,8 @@
|
|
|
7214
7769
|
if (why === 'accounts') return 'Auto: while a FloLess account is selected for this chat, the AI asks you — instead of its own review — before any step that needs approval, so that account stays its only way to reach the service. Scope does not limit file reads.';
|
|
7215
7770
|
if (why) return 'Auto isn’t available with this model, so the AI asks before changes. File edits outside your home folder ask for approval. Scope does not limit file reads.';
|
|
7216
7771
|
return state.chat?.provider === 'codex'
|
|
7217
|
-
?
|
|
7218
|
-
:
|
|
7772
|
+
? `Auto: Codex’s built-in review checks each step. Safe changes go ahead; risky ones, like deleting, are held back. Its review may also approve a change outside your home folder on its own — each decision is noted in the conversation. ${unaskedChangesNote()} Scope does not limit file reads.`
|
|
7773
|
+
: `Auto: Claude checks each step itself. Safe changes in your home folder go ahead. A file edit outside it asks you first; a command Claude’s check judges safe can run without asking, and risky steps like deleting are held back. ${unaskedChangesNote()} Scope does not limit file reads.`;
|
|
7219
7774
|
}
|
|
7220
7775
|
|
|
7221
7776
|
async function loadIntegrations() {
|
|
@@ -7367,6 +7922,7 @@
|
|
|
7367
7922
|
else delete control.dataset.blockedReason;
|
|
7368
7923
|
}
|
|
7369
7924
|
ui.stop.hidden = !active || Boolean(state.chat?.activeTurn?.local);
|
|
7925
|
+
paintStopState();
|
|
7370
7926
|
ui.send.hidden = false;
|
|
7371
7927
|
// Session recovery must remain available even while provider capability discovery is loading
|
|
7372
7928
|
// or has failed; it is the escape hatch for that exact state.
|
|
@@ -7779,6 +8335,97 @@
|
|
|
7779
8335
|
return item;
|
|
7780
8336
|
}
|
|
7781
8337
|
|
|
8338
|
+
/* -- #2255: the AI's changes to the model view ---------------------------------------------------------------------
|
|
8339
|
+
The tool waits on the server. A window showing that project's model, ready, claims the command (the server gives one
|
|
8340
|
+
window the claim), sends it to the editor, and settles it with the editor's report. One command at a time per chat,
|
|
8341
|
+
so the editor receives them in the order the AI asked. The line is FloLess's own, from the server's update. */
|
|
8342
|
+
const VIEW_LINE_WORKING = 'Changing the model view…';
|
|
8343
|
+
const VIEW_LINE_NO_RESULT = 'No result was recorded. The model view may or may not have changed, so check it on screen.';
|
|
8344
|
+
/** A model still opening gets this long to become ready before the window gives the command up (the server waits 15 s). */
|
|
8345
|
+
const VIEW_READY_WAIT_MS = 12000;
|
|
8346
|
+
/** The editor's own answer must arrive before the server stops waiting (10 s after the claim). */
|
|
8347
|
+
const VIEW_APPLY_WAIT_MS = 9000;
|
|
8348
|
+
const viewCommandChains = new Map();
|
|
8349
|
+
|
|
8350
|
+
function renderViewCommand(event) {
|
|
8351
|
+
const commandId = event.payload?.commandId;
|
|
8352
|
+
let update = null;
|
|
8353
|
+
for (const item of state.events) if (item.type === 'view-command-update' && item.payload?.commandId === commandId) update = item;
|
|
8354
|
+
// Working only while the reply that asked is still running; after a restart its turn is in recovery, not running.
|
|
8355
|
+
const working = !update && ['running', 'awaiting-approval'].includes(state.chat?.state) && state.chat?.activeTurn?.turnId === event.turnId;
|
|
8356
|
+
const status = update?.payload?.status || (working ? 'working' : 'no-result');
|
|
8357
|
+
const item = document.createElement('div');
|
|
8358
|
+
// Accent when it applied; amber when something was not done or cannot be confirmed; plain when the reply ended.
|
|
8359
|
+
const tone = status === 'applied' ? 'done' : status === 'working' ? 'working' : status === 'cancelled' ? 'ended' : 'held';
|
|
8360
|
+
item.className = `ai-chat-event view-command ${tone}`;
|
|
8361
|
+
item.dataset.eventSequence = String(event.sequence);
|
|
8362
|
+
item.dataset.eventId = event.eventId;
|
|
8363
|
+
item.dataset.viewStatus = status;
|
|
8364
|
+
const label = document.createElement('strong');
|
|
8365
|
+
label.textContent = 'Model view';
|
|
8366
|
+
const line = typeof update?.payload?.line === 'string' ? update.payload.line : working ? VIEW_LINE_WORKING : VIEW_LINE_NO_RESULT;
|
|
8367
|
+
item.append(label, document.createTextNode(` · ${line}`));
|
|
8368
|
+
return item;
|
|
8369
|
+
}
|
|
8370
|
+
|
|
8371
|
+
function takeViewCommand(event) {
|
|
8372
|
+
const snapshot = captureChat();
|
|
8373
|
+
const payload = event.payload || {};
|
|
8374
|
+
if (!snapshot || typeof payload.commandId !== 'string') return;
|
|
8375
|
+
if (state.events.some((item) => item.type === 'view-command-update' && item.payload?.commandId === payload.commandId)) return;
|
|
8376
|
+
const previous = viewCommandChains.get(snapshot.chatId) || Promise.resolve();
|
|
8377
|
+
const next = previous.then(() => runViewCommand(snapshot, payload))
|
|
8378
|
+
.catch((error) => console.warn('[chat] a model view request could not be handled', error));
|
|
8379
|
+
viewCommandChains.set(snapshot.chatId, next);
|
|
8380
|
+
void next.then(() => { if (viewCommandChains.get(snapshot.chatId) === next) viewCommandChains.delete(snapshot.chatId); });
|
|
8381
|
+
}
|
|
8382
|
+
|
|
8383
|
+
async function runViewCommand(snapshot, payload) {
|
|
8384
|
+
// A model that is still opening (or was just switched to) becomes ready in a moment: wait for it, briefly.
|
|
8385
|
+
const settled = () => state.events.some((item) => item.type === 'view-command-update' && item.payload?.commandId === payload.commandId);
|
|
8386
|
+
let target = window.flolessLeftPane?.viewTarget?.();
|
|
8387
|
+
for (const started = Date.now(); !target && Date.now() - started < VIEW_READY_WAIT_MS && sameChat(snapshot) && !settled();) {
|
|
8388
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
8389
|
+
target = window.flolessLeftPane?.viewTarget?.();
|
|
8390
|
+
}
|
|
8391
|
+
// Not this project's model, or not ready here: another window may show it, and the server says so if none does.
|
|
8392
|
+
if (!target || target.projectId !== payload.projectId || target.source !== payload.source) return;
|
|
8393
|
+
const path = `/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/view-commands/${encodeURIComponent(payload.commandId)}`;
|
|
8394
|
+
const owner = snapshot.scope.owner;
|
|
8395
|
+
let claim;
|
|
8396
|
+
try { claim = await request(`${path}/claim`, { method: 'POST', body: JSON.stringify({ owner, target }) }); }
|
|
8397
|
+
catch (error) {
|
|
8398
|
+
// Another window took it, the reply ended, or this reply's changes go to another view: nothing for this one to do.
|
|
8399
|
+
// Anything else is kept in the console; the server still answers the AI when its wait ends.
|
|
8400
|
+
const expected = (error?.status === 409 && ['chat-view-command-taken', 'chat-view-command-ended', 'chat-view-command-other-view'].includes(error.code))
|
|
8401
|
+
|| (error?.status === 404 && error.code === 'chat-view-command-missing');
|
|
8402
|
+
if (!expected) console.warn('[chat] a model view request could not be taken', { status: error?.status ?? null, code: error?.code ?? null, message: error?.message });
|
|
8403
|
+
return;
|
|
8404
|
+
}
|
|
8405
|
+
let body;
|
|
8406
|
+
try {
|
|
8407
|
+
const answer = await window.flolessLeftPane.applyView({ command: claim.command, target, timeoutMs: VIEW_APPLY_WAIT_MS });
|
|
8408
|
+
// Never asked (still loading): nothing changed. Asked and answered without a report: it may have changed something.
|
|
8409
|
+
body = answer?.ran === false ? { result: viewNotApplied('loading') } : answer?.ok && answer.result ? { result: answer.result } : { unconfirmed: true };
|
|
8410
|
+
} catch (error) {
|
|
8411
|
+
body = error?.dispatched === false ? { result: viewNotApplied('failed') } : { unconfirmed: true };
|
|
8412
|
+
}
|
|
8413
|
+
const settle = () => request(`${path}/settle`, { method: 'POST', body: JSON.stringify({ owner, claimToken: claim.claimToken, ...body }) });
|
|
8414
|
+
try { await settle(); }
|
|
8415
|
+
catch (error) {
|
|
8416
|
+
console.warn('[chat] what the model view did could not be recorded', { status: error?.status ?? null, code: error?.code ?? null });
|
|
8417
|
+
if (error?.status === 410 || error?.status === 400) return; // the server already ended it, and wrote its own line
|
|
8418
|
+
try { await settle(); }
|
|
8419
|
+
catch { announce('FloLess could not record what happened in the model view. Check the model on screen.'); }
|
|
8420
|
+
}
|
|
8421
|
+
}
|
|
8422
|
+
|
|
8423
|
+
/** A report for a change that never reached the editor: nothing changed. */
|
|
8424
|
+
function viewNotApplied(reason) {
|
|
8425
|
+
return { status: 'not-applied', reason, total: 0, matched: 0, selectionApplied: 0, selectedFinal: 0, notDrawable: 0, noField: 0, unchecked: 0,
|
|
8426
|
+
overCap: false, framed: false, display: null, skipped: [], assumptions: [], references: [], samples: [] };
|
|
8427
|
+
}
|
|
8428
|
+
|
|
7782
8429
|
function renderFilterQuestion(event) {
|
|
7783
8430
|
// A Drawing Filter question from before #1859: the person's own words, like any message. Nothing
|
|
7784
8431
|
// waits on it any more; its answer, if one was published, is its own event.
|
|
@@ -7939,41 +8586,95 @@
|
|
|
7939
8586
|
if (reason) state.filterNotShared.set(clientSubmissionId, reason);
|
|
7940
8587
|
}
|
|
7941
8588
|
|
|
8589
|
+
/**
|
|
8590
|
+
* #2223 Revision 6: sendTurn's `message` is an answer written outside the message box (on an AI question card). It goes
|
|
8591
|
+
* through the same send, as a new turn or a follow-up to a running reply; the box, its files, its selection and its draft
|
|
8592
|
+
* stay exactly as they are, and the caller is told { sent, message } to say on the card, never a report under the box.
|
|
8593
|
+
* This is why the chat cannot take such a message right now, in words — Send's own reasons, less the two that are only
|
|
8594
|
+
* about the box (nothing typed in it, a file of its own still attaching); '' when it can. The conditions are written out
|
|
8595
|
+
* as updateSendState has them, because several harnesses run that function on its own.
|
|
8596
|
+
*/
|
|
8597
|
+
function givenMessageBlocked() {
|
|
8598
|
+
const chat = state.chat;
|
|
8599
|
+
if (!chat || chat.archivedAt) return 'This conversation can’t take a message right now. Open it again, then send your answer.';
|
|
8600
|
+
if (state.loading || state.followupSubmitting || chat.activeTurn?.local) return 'FloLess is still sending your last message. Wait a moment, then send your answer again.';
|
|
8601
|
+
if (state.followupUnknownId || hasUnknownFollowup()) return 'FloLess could not confirm your last message reached the AI. Check it in the conversation, then send your answer.';
|
|
8602
|
+
if (chat.state === 'recovery') return 'This conversation is reconnecting to the AI. Send your answer once it is ready.';
|
|
8603
|
+
if (requestExecutionBlocked()) return 'Another AI Chat is changing this project or workflow. Wait for it to finish or stop it, then send your answer.';
|
|
8604
|
+
if (state.capability?.runtime && state.capability.runtime.state !== 'installed') return 'FloLess is still setting up the AI. Send your answer once it is ready.';
|
|
8605
|
+
if (chat.rehome && ['freezing', 'copying', 'publishing'].includes(chat.rehome.state) && state.scope?.owner?.kind === 'workspace') {
|
|
8606
|
+
return 'This conversation is moving into its workflow. Send your answer once it has moved.';
|
|
8607
|
+
}
|
|
8608
|
+
return '';
|
|
8609
|
+
}
|
|
8610
|
+
|
|
8611
|
+
/** An answer written outside the box that did not go: what the card is told, in words. */
|
|
8612
|
+
function givenNotSent(sentence) {
|
|
8613
|
+
return { sent: false, message: sentence || 'Your answer was not sent. Send it again.' };
|
|
8614
|
+
}
|
|
8615
|
+
|
|
8616
|
+
/**
|
|
8617
|
+
* What an answer written outside the box is told when the server would not take it. A busy project is asked about only
|
|
8618
|
+
* from the box (its question and wait send what is in the box), so the answer says where that choice is.
|
|
8619
|
+
*/
|
|
8620
|
+
function givenRefusal(error) {
|
|
8621
|
+
return PROJECT_BUSY_CODES.has(String(error?.code || ''))
|
|
8622
|
+
? 'Other work is using this project right now, so your answer was not sent. It is kept here: send it again once that work finishes, or type it in the message box below to choose what happens to that work.'
|
|
8623
|
+
: errorMessage(error);
|
|
8624
|
+
}
|
|
8625
|
+
|
|
8626
|
+
/**
|
|
8627
|
+
* #2223 Revision 6: the server empties a conversation's saved draft when it takes a message. A message written outside
|
|
8628
|
+
* the box (an answer on a question card) was not the box's words, so the box keeps them, saved again.
|
|
8629
|
+
*/
|
|
8630
|
+
function keepComposerDraft() {
|
|
8631
|
+
if (!state.chat) return;
|
|
8632
|
+
state.chat.draft = ui.input.value;
|
|
8633
|
+
if (ui.input.value) saveDraftSoon();
|
|
8634
|
+
}
|
|
8635
|
+
|
|
7942
8636
|
async function sendTurn(options) {
|
|
7943
8637
|
// #2061: `override` — the person chose to send now over a background request that was waiting first.
|
|
7944
8638
|
const sendOverride = options?.override === true;
|
|
7945
|
-
|
|
8639
|
+
// #2223 Revision 6: `message` — an answer written outside the message box (see givenMessageBlocked).
|
|
8640
|
+
const given = options?.message || null;
|
|
8641
|
+
const blocked = given ? givenMessageBlocked() : '';
|
|
8642
|
+
if (blocked) return givenNotSent(blocked);
|
|
8643
|
+
if (!given && (!state.chat || ui.send.disabled)) return;
|
|
7946
8644
|
// ONE AI CHAT (#1859, owner ruling 2026-10-01/02): the open Drawing Filter never changes where a message goes.
|
|
7947
8645
|
// It is a turn, or a follow-up to a running reply (a drawing read included), exactly as anywhere else; the
|
|
7948
8646
|
// filter only adds its context (`filterContextForSend`) and the AI may answer with a suggestion card.
|
|
7949
8647
|
// Decided once, at the click, from what the pill showed: a follow-up that falls back to a new turn below
|
|
7950
8648
|
// must not attach objects the person was never shown (#1653).
|
|
7951
|
-
const subjects = subjectsPayload(composerSelection());
|
|
8649
|
+
const subjects = given ? null : subjectsPayload(composerSelection()); // the box's selection rides with the box's message
|
|
7952
8650
|
const subjectsField = subjects ? { subjects } : {};
|
|
7953
8651
|
const filterContext = filterContextForSend();
|
|
7954
8652
|
if (turnIsVisiblyActive() && !state.chat.activeTurn?.local) {
|
|
7955
|
-
const followup = await sendFollowup();
|
|
7956
|
-
if (followup?.outcome !== 'turn-ended') return;
|
|
8653
|
+
const followup = await sendFollowup(given);
|
|
8654
|
+
if (followup?.outcome !== 'turn-ended') return given ? followup || givenNotSent() : undefined;
|
|
7957
8655
|
// #1616: the response finished while this follow-up was on its way, so the server refused it
|
|
7958
8656
|
// before saving anything. Re-read the conversation and, if it is now idle and the composer still
|
|
7959
8657
|
// holds exactly that message, send it once as a new turn instead of asking for a second click.
|
|
7960
|
-
if (!(await resendAfterTurnEnded(followup)))
|
|
8658
|
+
if (!(await resendAfterTurnEnded(followup))) {
|
|
8659
|
+
return given ? givenNotSent(givenMessageBlocked() || 'The AI’s reply ended while your answer was on its way, so it was not sent. Send it again.') : undefined;
|
|
8660
|
+
}
|
|
7961
8661
|
}
|
|
7962
8662
|
const snapshot = captureChat();
|
|
7963
|
-
if (!snapshot) return;
|
|
8663
|
+
if (!snapshot) return given ? givenNotSent() : undefined;
|
|
7964
8664
|
// Bind a carried-over Tekla library first; a refused binding keeps the message unsent.
|
|
7965
|
-
if (!(await bindPendingTeklaRead(snapshot))) return;
|
|
7966
|
-
const text = ui.input.value.trim();
|
|
8665
|
+
if (!(await bindPendingTeklaRead(snapshot))) return given ? givenNotSent('Wait for the Tekla library change to finish, then send your answer again.') : undefined;
|
|
8666
|
+
const text = given ? given.text : ui.input.value.trim();
|
|
7967
8667
|
const uiContext = currentFloLessContext();
|
|
7968
8668
|
const chatId = snapshot.chatId;
|
|
7969
|
-
const attachmentIds = state.attachments.map((item) => item.attachmentId);
|
|
8669
|
+
const attachmentIds = (given ? given.attachments : state.attachments).map((item) => item.attachmentId);
|
|
7970
8670
|
// #2061: the message as it was asked about, should the project turn out to be busy (see askIfProjectBusy).
|
|
7971
8671
|
const busyMessage = { chatId, text, attachmentIds, subjectsField, filterField: filterContext.field };
|
|
7972
|
-
|
|
7973
|
-
|
|
8672
|
+
// The busy-project question and its wait send what is in the box; an answer written elsewhere is told the refusal instead.
|
|
8673
|
+
const askedBusy = !sendOverride && !given && await projectBusyBeforeSend(snapshot, busyMessage);
|
|
8674
|
+
if (askedBusy || !sameChat(snapshot)) return given ? givenNotSent() : undefined;
|
|
7974
8675
|
// Edited while FloLess checked — or already sent by an earlier click, which empties the box — nothing is sent over
|
|
7975
8676
|
// the box's text now; it stays for the next Send.
|
|
7976
|
-
if (ui.input.value.trim() !== text || JSON.stringify(state.attachments.map((item) => item.attachmentId)) !== JSON.stringify(attachmentIds)) return;
|
|
8677
|
+
if (!given && (ui.input.value.trim() !== text || JSON.stringify(state.attachments.map((item) => item.attachmentId)) !== JSON.stringify(attachmentIds))) return;
|
|
7977
8678
|
const clientSubmissionId = crypto.randomUUID();
|
|
7978
8679
|
const previousChat = state.chat;
|
|
7979
8680
|
const previousAttachments = state.attachments;
|
|
@@ -7982,13 +8683,15 @@
|
|
|
7982
8683
|
chatId, turnId: clientSubmissionId, clientSubmissionId, providerItemId: null, type: 'user-message',
|
|
7983
8684
|
payload: { text, attachmentIds, ...subjectsField }, createdAt: new Date().toISOString(), optimistic: true,
|
|
7984
8685
|
};
|
|
7985
|
-
|
|
7986
|
-
|
|
7987
|
-
|
|
8686
|
+
if (!given) {
|
|
8687
|
+
clearTimeout(state.draftTimer);
|
|
8688
|
+
state.localDraft = { chatId, text: '' };
|
|
8689
|
+
state.backgroundDrafts.delete(chatId);
|
|
8690
|
+
}
|
|
7988
8691
|
state.pendingSubmissionId = clientSubmissionId;
|
|
7989
8692
|
state.events.push(optimisticEvent);
|
|
7990
|
-
state.chat = { ...previousChat, draft: '', state: 'starting', activeTurn: { turnId: clientSubmissionId, local: true } };
|
|
7991
|
-
ui.input.value = ''; autosize(); state.attachments = []; paintAttachments();
|
|
8693
|
+
state.chat = { ...previousChat, draft: given ? previousChat.draft : '', state: 'starting', activeTurn: { turnId: clientSubmissionId, local: true } };
|
|
8694
|
+
if (!given) { ui.input.value = ''; autosize(); state.attachments = []; paintAttachments(); }
|
|
7992
8695
|
setBusy(true); paintConversation(); announce('Message sent.');
|
|
7993
8696
|
try {
|
|
7994
8697
|
// A debounced save already in flight must finish before the server clears
|
|
@@ -8002,30 +8705,41 @@
|
|
|
8002
8705
|
modifying: previousChat.settings.permissionProfile !== 'read-only', ...subjectsField, ...filterContext.field,
|
|
8003
8706
|
// #2061: the person chose "Send my message now" over a request that was waiting first.
|
|
8004
8707
|
...(sendOverride ? { overrideWaiting: true } : {}),
|
|
8708
|
+
// #2223 Revision 7: a message written on a card leaves the box's saved draft as it is.
|
|
8709
|
+
...(given ? { keepDraft: true } : {}),
|
|
8005
8710
|
}),
|
|
8006
8711
|
});
|
|
8007
8712
|
if (sameChat(snapshot)) endProjectBusy();
|
|
8008
8713
|
if (!sameChat(snapshot)) {
|
|
8009
8714
|
noteFilterContext(clientSubmissionId, filterContext, result?.filterContext);
|
|
8010
|
-
|
|
8715
|
+
subjectLinksSaved(subjects);
|
|
8716
|
+
// Code review 2026-10-12: a card's answer admitted after the person moved on was still sent; saying otherwise invited
|
|
8717
|
+
// a second copy. The server kept the box's saved draft (keepDraft), so there is nothing to put back.
|
|
8718
|
+
if (given) return { sent: true };
|
|
8719
|
+
return;
|
|
8011
8720
|
}
|
|
8012
8721
|
noteFilterContext(clientSubmissionId, filterContext, result?.filterContext);
|
|
8013
8722
|
subjectLinksSaved(subjects);
|
|
8014
8723
|
state.pendingSubmissionId = null;
|
|
8015
8724
|
state.events = state.events.filter((event) => event.eventId !== optimisticEvent.eventId);
|
|
8016
8725
|
state.chat = result.chat;
|
|
8726
|
+
// The server kept the saved draft (keepDraft); the box's own words, newer than any save, stay in the box and its record.
|
|
8727
|
+
if (given) keepComposerDraft();
|
|
8017
8728
|
for (const event of result.events || []) if (!state.events.some((item) => item.eventId === event.eventId)) state.events.push(event);
|
|
8018
8729
|
paintConversation();
|
|
8019
8730
|
// The server accepts a turn only from a ready provider, so a warning from an earlier check is stale.
|
|
8020
8731
|
if (!providerReady()) void loadCapability().then(() => { if (sameChat(snapshot)) { paintSettings(); updateSendState(); } });
|
|
8732
|
+
if (given) return { sent: true };
|
|
8021
8733
|
} catch (error) {
|
|
8022
8734
|
if (!sameChat(snapshot)) {
|
|
8735
|
+
if (given) return givenNotSent();
|
|
8023
8736
|
if (initialTurnDefinitelyRefused(error)) await restoreBackgroundDraft(snapshot, text, clientSubmissionId);
|
|
8024
8737
|
return;
|
|
8025
8738
|
}
|
|
8026
8739
|
state.pendingSubmissionId = null;
|
|
8027
8740
|
state.events = state.events.filter((event) => event.eventId !== optimisticEvent.eventId);
|
|
8028
8741
|
state.chat = previousChat;
|
|
8742
|
+
if (given) { paintConversation(); return givenNotSent(givenRefusal(error)); }
|
|
8029
8743
|
state.attachments = previousAttachments;
|
|
8030
8744
|
ui.input.value = text; autosize(); paintAttachments(); saveDraftSoon(); paintConversation();
|
|
8031
8745
|
// #2061: the project is busy — ask (wait / open it / stop it) instead of only saying it failed. Nothing was sent.
|
|
@@ -8348,13 +9062,15 @@
|
|
|
8348
9062
|
* usable, which already rules out recovery, an unconfirmed message, an upload and a provider still
|
|
8349
9063
|
* being set up. Otherwise the original notice is shown and the draft stays for the user to decide.
|
|
8350
9064
|
*/
|
|
8351
|
-
async function resendAfterTurnEnded({ snapshot, text, attachmentIds, error }) {
|
|
9065
|
+
async function resendAfterTurnEnded({ snapshot, text, attachmentIds, error, given }) {
|
|
8352
9066
|
state.followupSubmitting = true;
|
|
8353
9067
|
updateSendState();
|
|
8354
9068
|
try { await refreshConversation(snapshot.chatId); }
|
|
8355
9069
|
finally { state.followupSubmitting = false; }
|
|
8356
9070
|
if (!sameChat(snapshot)) return false;
|
|
8357
9071
|
updateSendState();
|
|
9072
|
+
// #2223 Revision 6: an answer written outside the box is the same message whatever the box holds; its writer is told.
|
|
9073
|
+
if (given) return !turnIsVisiblyActive() && !givenMessageBlocked();
|
|
8358
9074
|
if (!turnIsVisiblyActive() && !ui.send.disabled
|
|
8359
9075
|
&& ui.input.value.trim() === text
|
|
8360
9076
|
&& JSON.stringify(state.attachments.map((item) => item.attachmentId)) === JSON.stringify(attachmentIds)) return true;
|
|
@@ -8368,14 +9084,18 @@
|
|
|
8368
9084
|
|| sessionNeedsRenewal(error) || error?.status === 413;
|
|
8369
9085
|
}
|
|
8370
9086
|
|
|
8371
|
-
async function sendFollowup() {
|
|
8372
|
-
|
|
9087
|
+
async function sendFollowup(given = null) {
|
|
9088
|
+
// #2223 Revision 6: `given` is a message written outside the box (see sendTurn); the box stays as it is, and the result
|
|
9089
|
+
// says { sent, message } — or hands back a reply that ended first, as it does for the box.
|
|
9090
|
+
const notSent = (sentence) => (given ? givenNotSent(sentence) : undefined);
|
|
9091
|
+
if (!state.chat || !turnIsVisiblyActive() || state.followupSubmitting) return notSent();
|
|
8373
9092
|
const snapshot = captureChat();
|
|
8374
|
-
if (!snapshot) return;
|
|
8375
|
-
const text = ui.input.value.trim();
|
|
8376
|
-
const attachmentIds = state.attachments.map((item) => item.attachmentId);
|
|
8377
|
-
if (!text && !attachmentIds.length) return;
|
|
9093
|
+
if (!snapshot) return notSent();
|
|
9094
|
+
const text = given ? given.text : ui.input.value.trim();
|
|
9095
|
+
const attachmentIds = (given ? given.attachments : state.attachments).map((item) => item.attachmentId);
|
|
9096
|
+
if (!text && !attachmentIds.length) return notSent();
|
|
8378
9097
|
if (new TextEncoder().encode(text).length > 128 * 1024) {
|
|
9098
|
+
if (given) return notSent(errorMessage({ code: 'chat-message-too-long' }));
|
|
8379
9099
|
report({ code: 'chat-message-too-long' }, 'Message was not sent');
|
|
8380
9100
|
return;
|
|
8381
9101
|
}
|
|
@@ -8393,13 +9113,15 @@
|
|
|
8393
9113
|
payload: { text, attachmentIds, followup: true, deliveryState: 'pending' },
|
|
8394
9114
|
createdAt: new Date().toISOString(), optimistic: true,
|
|
8395
9115
|
};
|
|
8396
|
-
|
|
8397
|
-
|
|
8398
|
-
|
|
9116
|
+
if (!given) {
|
|
9117
|
+
clearTimeout(state.draftTimer);
|
|
9118
|
+
state.localDraft = { chatId: snapshot.chatId, text: '' };
|
|
9119
|
+
state.backgroundDrafts.delete(snapshot.chatId);
|
|
9120
|
+
}
|
|
8399
9121
|
state.followupSubmitting = true;
|
|
8400
|
-
state.chat.draft = '';
|
|
9122
|
+
if (!given) state.chat.draft = '';
|
|
8401
9123
|
state.events.push(optimisticEvent);
|
|
8402
|
-
ui.input.value = ''; autosize(); state.attachments = []; paintAttachments();
|
|
9124
|
+
if (!given) { ui.input.value = ''; autosize(); state.attachments = []; paintAttachments(); }
|
|
8403
9125
|
paintEvents({ forceBottom: true }); updateSendState();
|
|
8404
9126
|
try {
|
|
8405
9127
|
await state.draftWrites.get(snapshot.chatId)?.catch(() => {});
|
|
@@ -8407,14 +9129,17 @@
|
|
|
8407
9129
|
method: 'POST', body: JSON.stringify({
|
|
8408
9130
|
owner: snapshot.scope.owner, clientSubmissionId, text,
|
|
8409
9131
|
uiContext: currentFloLessContext(), attachmentIds, ...filterContext.field,
|
|
9132
|
+
...(given ? { keepDraft: true } : {}), // #2223 Revision 7: see sendTurn
|
|
8410
9133
|
}),
|
|
8411
9134
|
});
|
|
8412
9135
|
noteFilterContext(clientSubmissionId, filterContext, result?.filterContext);
|
|
8413
|
-
if (!sameChat(snapshot)) return;
|
|
9136
|
+
if (!sameChat(snapshot)) return given ? { sent: true } : undefined;
|
|
8414
9137
|
state.events = state.events.filter((event) => event.eventId !== optimisticEvent.eventId);
|
|
8415
9138
|
for (const event of result.events || []) if (!state.events.some((item) => item.eventId === event.eventId)) state.events.push(event);
|
|
8416
9139
|
state.events.sort((a, b) => a.sequence - b.sequence);
|
|
8417
9140
|
state.chat = result.chat;
|
|
9141
|
+
// The server kept the saved draft (keepDraft); the box's own words, newer than any save, stay in the box and its record.
|
|
9142
|
+
if (given) { keepComposerDraft(); outcome = { sent: true }; }
|
|
8418
9143
|
announce(result.followup?.deliveryState === 'queued-next'
|
|
8419
9144
|
? 'Message queued for the next AI response.'
|
|
8420
9145
|
: result.followup?.deliveryState === 'accepted'
|
|
@@ -8425,6 +9150,7 @@
|
|
|
8425
9150
|
paintConversation();
|
|
8426
9151
|
} catch (error) {
|
|
8427
9152
|
if (!sameChat(snapshot)) {
|
|
9153
|
+
if (given && followupDefinitelyRefused(error)) return notSent();
|
|
8428
9154
|
if (followupDefinitelyRefused(error)) await restoreBackgroundDraft(snapshot, text, clientSubmissionId);
|
|
8429
9155
|
else {
|
|
8430
9156
|
optimisticEvent.payload.deliveryState = 'unknown';
|
|
@@ -8436,13 +9162,13 @@
|
|
|
8436
9162
|
paintEvents(); updateSendState();
|
|
8437
9163
|
}
|
|
8438
9164
|
}
|
|
8439
|
-
return;
|
|
9165
|
+
return notSent();
|
|
8440
9166
|
}
|
|
8441
9167
|
if (state.events.some((event) => !event.optimistic && event.clientSubmissionId === clientSubmissionId
|
|
8442
9168
|
&& event.type === 'user-message')) {
|
|
8443
9169
|
state.events = state.events.filter((event) => event.eventId !== optimisticEvent.eventId);
|
|
8444
9170
|
announce('Follow-up saved. Waiting for AI.'); paintEvents();
|
|
8445
|
-
return;
|
|
9171
|
+
return given ? { sent: true } : undefined;
|
|
8446
9172
|
}
|
|
8447
9173
|
const definitiveRefusal = followupDefinitelyRefused(error);
|
|
8448
9174
|
// A lost HTTP reply does not prove the provider missed the message. Keep the submission
|
|
@@ -8455,14 +9181,20 @@
|
|
|
8455
9181
|
}
|
|
8456
9182
|
// An uncertain request may already own these files. Keep them on its
|
|
8457
9183
|
// message, and restore chips only when the server definitely refused it.
|
|
8458
|
-
|
|
8459
|
-
|
|
8460
|
-
|
|
8461
|
-
|
|
9184
|
+
if (!given) {
|
|
9185
|
+
state.attachments = definitiveRefusal ? previousAttachments : [];
|
|
9186
|
+
ui.input.value = text; autosize(); paintAttachments();
|
|
9187
|
+
if (definitiveRefusal) saveDraftSoon();
|
|
9188
|
+
else state.localDraft = { chatId: snapshot.chatId, text };
|
|
9189
|
+
}
|
|
9190
|
+
paintEvents();
|
|
8462
9191
|
// The response ended before this arrived (#1616). sendTurn resends it as a new turn, and
|
|
8463
9192
|
// shows this refusal only if it cannot.
|
|
8464
9193
|
if (definitiveRefusal && error?.code === 'chat-followup-refused' && error?.reason === 'chat-turn-stale') {
|
|
8465
|
-
outcome = { outcome: 'turn-ended', snapshot, text, attachmentIds, error };
|
|
9194
|
+
outcome = { outcome: 'turn-ended', snapshot, text, attachmentIds, error, given };
|
|
9195
|
+
} else if (given) {
|
|
9196
|
+
outcome = notSent(definitiveRefusal ? givenRefusal(error)
|
|
9197
|
+
: 'FloLess couldn’t confirm your answer reached the AI. Check the conversation before you answer again.');
|
|
8466
9198
|
} else failedDelivery = { error, prefix: definitiveRefusal ? '' : 'Could not confirm the follow-up' };
|
|
8467
9199
|
} finally {
|
|
8468
9200
|
state.followupSubmitting = false;
|
|
@@ -8567,17 +9299,43 @@
|
|
|
8567
9299
|
}
|
|
8568
9300
|
}
|
|
8569
9301
|
|
|
9302
|
+
function stopRequestKey(chat = state.chat, scope = state.scope) {
|
|
9303
|
+
return JSON.stringify([scopeKey(scope), chat?.chatId, chat?.activeTurn?.turnId]);
|
|
9304
|
+
}
|
|
9305
|
+
|
|
9306
|
+
// These carriers are shared by all conversations. Derive their state from the visible turn,
|
|
9307
|
+
// even when a request from a conversation the person has left is the one that just settled.
|
|
9308
|
+
function paintStopState() {
|
|
9309
|
+
const pending = state.chat && state.pendingStops.get(stopRequestKey());
|
|
9310
|
+
for (const control of [ui.stop, ui.recoveryStop]) {
|
|
9311
|
+
control.disabled = Boolean(pending);
|
|
9312
|
+
if (pending) {
|
|
9313
|
+
control.setAttribute('aria-busy', 'true');
|
|
9314
|
+
control.dataset.blockedReason = pending.kind === 'recovery'
|
|
9315
|
+
? 'FloLess is ending recovery for this response. Wait for it to finish.'
|
|
9316
|
+
: 'FloLess is stopping this response. Wait for it to finish.';
|
|
9317
|
+
} else {
|
|
9318
|
+
control.removeAttribute('aria-busy');
|
|
9319
|
+
delete control.dataset.blockedReason;
|
|
9320
|
+
}
|
|
9321
|
+
}
|
|
9322
|
+
}
|
|
9323
|
+
|
|
8570
9324
|
async function stopTurn() {
|
|
8571
9325
|
if (!state.chat?.activeTurn) return;
|
|
8572
9326
|
const snapshot = captureChat();
|
|
8573
9327
|
if (!snapshot) return;
|
|
8574
9328
|
const chatId = snapshot.chatId;
|
|
8575
9329
|
const owner = snapshot.scope.owner;
|
|
9330
|
+
const turnId = state.chat.activeTurn.turnId;
|
|
9331
|
+
const key = stopRequestKey();
|
|
9332
|
+
if (state.pendingStops.has(key)) return;
|
|
9333
|
+
const pending = { kind: 'stop' };
|
|
9334
|
+
state.pendingStops.set(key, pending);
|
|
8576
9335
|
const stop = () => request(`/api/chat/conversations/${encodeURIComponent(chatId)}/stop`, {
|
|
8577
|
-
method: 'POST', body: JSON.stringify({ owner }),
|
|
9336
|
+
method: 'POST', body: JSON.stringify({ owner, expectTurnId: turnId }),
|
|
8578
9337
|
});
|
|
8579
|
-
|
|
8580
|
-
ui.recoveryStop.disabled = true;
|
|
9338
|
+
paintStopState();
|
|
8581
9339
|
announce('Stopping the current response…');
|
|
8582
9340
|
try {
|
|
8583
9341
|
try { await stop(); }
|
|
@@ -8590,17 +9348,24 @@
|
|
|
8590
9348
|
if (!sameChat(snapshot)) return;
|
|
8591
9349
|
await refreshConversation(chatId, false);
|
|
8592
9350
|
if (!sameChat(snapshot)) return;
|
|
9351
|
+
if (state.chat.activeTurn && state.chat.activeTurn.turnId !== turnId) return;
|
|
8593
9352
|
announce('The current response was stopped.');
|
|
8594
9353
|
} catch (error) {
|
|
8595
9354
|
if (!sameChat(snapshot)) return;
|
|
9355
|
+
if (error?.code === 'stop-stale') { await refreshConversation(chatId, false); return; }
|
|
9356
|
+
if (state.chat.activeTurn && state.chat.activeTurn.turnId !== turnId) return;
|
|
8596
9357
|
if (error?.code === 'chat-stop-uncertain') {
|
|
8597
9358
|
state.recoveryCanEnd = true;
|
|
9359
|
+
state.recoveryTurnId = turnId;
|
|
8598
9360
|
state.recoveryMessage = 'FloLess cannot stop this response remotely because the AI app no longer recognizes it. End recovery unlocks this chat; any late response will not appear here.';
|
|
8599
9361
|
paintRecovery();
|
|
8600
9362
|
announce('FloLess could not stop the response remotely. You can end its local recovery lock.');
|
|
8601
9363
|
} else report(error, 'Could not stop the response');
|
|
8602
9364
|
}
|
|
8603
|
-
finally {
|
|
9365
|
+
finally {
|
|
9366
|
+
if (state.pendingStops.get(key) === pending) state.pendingStops.delete(key);
|
|
9367
|
+
paintStopState();
|
|
9368
|
+
}
|
|
8604
9369
|
}
|
|
8605
9370
|
|
|
8606
9371
|
async function refreshChatSession() {
|
|
@@ -8635,21 +9400,49 @@
|
|
|
8635
9400
|
async function endRecovery() {
|
|
8636
9401
|
const snapshot = captureChat();
|
|
8637
9402
|
if (!snapshot) return;
|
|
8638
|
-
|
|
9403
|
+
const key = stopRequestKey();
|
|
9404
|
+
if (state.pendingStops.has(key)) return;
|
|
9405
|
+
const turnId = state.chat.activeTurn?.turnId;
|
|
9406
|
+
const pending = { kind: 'recovery' };
|
|
9407
|
+
state.pendingStops.set(key, pending);
|
|
9408
|
+
paintStopState();
|
|
8639
9409
|
announce('Ending recovery for this response…');
|
|
8640
9410
|
try {
|
|
8641
9411
|
const result = await request(`/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/end-recovery`, {
|
|
8642
|
-
method: 'POST', body: JSON.stringify({ owner: snapshot.scope.owner }),
|
|
9412
|
+
method: 'POST', body: JSON.stringify({ owner: snapshot.scope.owner, expectTurnId: turnId }),
|
|
8643
9413
|
});
|
|
8644
9414
|
if (!sameChat(snapshot)) return;
|
|
9415
|
+
if (state.chat.activeTurn && state.chat.activeTurn.turnId !== turnId) return;
|
|
9416
|
+
// The visible row still belongs to the initiating response (or its terminal refresh).
|
|
9417
|
+
// Its End authority is obsolete even when the POST already carries a replacement response.
|
|
8645
9418
|
state.recoveryCanEnd = false;
|
|
8646
9419
|
state.recoveryMessage = null;
|
|
9420
|
+
state.recoveryTurnId = null;
|
|
9421
|
+
if (result.chat.activeTurn && result.chat.activeTurn.turnId !== turnId) {
|
|
9422
|
+
paintRecovery();
|
|
9423
|
+
return;
|
|
9424
|
+
}
|
|
9425
|
+
// A terminal SSE refresh may beat this acknowledgement. Clear this turn's recovery authority,
|
|
9426
|
+
// but keep that newer conversation row rather than replacing it with the older POST result.
|
|
9427
|
+
if (!state.chat.activeTurn) {
|
|
9428
|
+
paintRecovery();
|
|
9429
|
+
announce('Recovery ended. You can continue this chat. The AI may still be working; any late reply will not appear here.');
|
|
9430
|
+
return;
|
|
9431
|
+
}
|
|
8647
9432
|
state.chat = result.chat;
|
|
8648
9433
|
await refreshConversation(snapshot.chatId, false);
|
|
8649
9434
|
if (!sameChat(snapshot)) return;
|
|
8650
|
-
|
|
8651
|
-
|
|
8652
|
-
|
|
9435
|
+
if (state.chat.activeTurn && state.chat.activeTurn.turnId !== turnId) return;
|
|
9436
|
+
announce('Recovery ended. You can continue this chat. The AI may still be working; any late reply will not appear here.');
|
|
9437
|
+
} catch (error) {
|
|
9438
|
+
if (error.code === 'chat-recovery-stale') {
|
|
9439
|
+
if (sameChat(snapshot)) await refreshConversation(snapshot.chatId, false);
|
|
9440
|
+
} else if (sameChat(snapshot) && state.chat.activeTurn?.turnId === turnId) report(error, 'Could not end recovery');
|
|
9441
|
+
}
|
|
9442
|
+
finally {
|
|
9443
|
+
if (state.pendingStops.get(key) === pending) state.pendingStops.delete(key);
|
|
9444
|
+
paintStopState();
|
|
9445
|
+
}
|
|
8653
9446
|
}
|
|
8654
9447
|
|
|
8655
9448
|
async function reconcile() {
|
|
@@ -8664,6 +9457,7 @@
|
|
|
8664
9457
|
ui.reconcile.textContent = 'Checking…';
|
|
8665
9458
|
state.recoveryMessage = null;
|
|
8666
9459
|
state.recoveryCanEnd = false;
|
|
9460
|
+
state.recoveryTurnId = state.chat.activeTurn?.turnId;
|
|
8667
9461
|
ui.recoveryCopy.textContent = 'Checking the last AI response now. You can continue when FloLess confirms it is safe.';
|
|
8668
9462
|
announce('Checking the last AI response…');
|
|
8669
9463
|
try {
|
|
@@ -9390,6 +10184,17 @@
|
|
|
9390
10184
|
}
|
|
9391
10185
|
}
|
|
9392
10186
|
|
|
10187
|
+
// This is a browser presentation preference, never a conversation permission or approval.
|
|
10188
|
+
function readAccessExplanationPreference() {
|
|
10189
|
+
try { return localStorage.getItem('floless:chat-access-explanation') === 'expanded'; } catch { return false; }
|
|
10190
|
+
}
|
|
10191
|
+
|
|
10192
|
+
function toggleAccessExplanation() {
|
|
10193
|
+
state.accessExplanationExpanded = !state.accessExplanationExpanded;
|
|
10194
|
+
try { localStorage.setItem('floless:chat-access-explanation', state.accessExplanationExpanded ? 'expanded' : 'collapsed'); } catch { /* private mode: retain the choice for this page */ }
|
|
10195
|
+
paintScopeControl();
|
|
10196
|
+
}
|
|
10197
|
+
|
|
9393
10198
|
function paintScopeControl() {
|
|
9394
10199
|
if (!ui.scopeControls) return;
|
|
9395
10200
|
const chat = state.chat;
|
|
@@ -9406,12 +10211,24 @@
|
|
|
9406
10211
|
ui.scopeToggle.disabled = state.loading;
|
|
9407
10212
|
if (ui.scopeToggle.disabled) ui.scopeToggle.dataset.blockedReason = 'The conversation is still loading.';
|
|
9408
10213
|
else delete ui.scopeToggle.dataset.blockedReason;
|
|
9409
|
-
const disclosure = chat
|
|
10214
|
+
const disclosure = isInstructorAnswer(chat)
|
|
10215
|
+
? '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.'
|
|
10216
|
+
: chat.settings?.permissionProfile === 'read-only'
|
|
9410
10217
|
? 'Read only: the AI’s file tools cannot change files. Commands keep their own approvals and may authorize file changes.'
|
|
9411
|
-
: chat.settings?.permissionProfile === 'full-access' ?
|
|
10218
|
+
: chat.settings?.permissionProfile === 'full-access' ? fullAccessScopeNote()
|
|
9412
10219
|
: chat.settings?.permissionProfile === 'auto' ? autoScopeNote()
|
|
9413
|
-
: chat.changeAllowance?.allowedForChat ? 'File changes in scope, including folders you add later, are allowed for this chat.' :
|
|
10220
|
+
: chat.changeAllowance?.allowedForChat ? 'File changes in scope, including folders you add later, are allowed for this chat.' : permissionTip(chat.settings?.permissionProfile);
|
|
9414
10221
|
if (ui.scopeDisclosure.textContent !== disclosure) ui.scopeDisclosure.textContent = disclosure;
|
|
10222
|
+
if (ui.accessExplanation) {
|
|
10223
|
+
const label = isInstructorAnswer(chat) ? 'No tools' : permissionLabel(chat.settings?.permissionProfile);
|
|
10224
|
+
ui.accessExplanation.querySelector('strong').textContent = label;
|
|
10225
|
+
ui.accessExplanation.setAttribute('aria-label', `Explain ${label} access`);
|
|
10226
|
+
ui.accessExplanation.setAttribute('aria-expanded', String(Boolean(state.accessExplanationExpanded)));
|
|
10227
|
+
ui.accessExplanation.dataset.tip = state.accessExplanationExpanded ? 'Explanation shown. Hide the access explanation.' : 'Explanation hidden. Show what this access level allows.';
|
|
10228
|
+
ui.accessExplanation.dataset.commandInstanceLabel = state.accessExplanationExpanded ? 'shown' : 'hidden';
|
|
10229
|
+
ui.accessExplanation.dataset.commandId = `shell.chat-access-explanation#${state.accessExplanationExpanded ? 'shown' : 'hidden'}`;
|
|
10230
|
+
ui.scopeDisclosure.hidden = !state.accessExplanationExpanded || !disclosure;
|
|
10231
|
+
}
|
|
9415
10232
|
// Poll/SSE can change permissions or pause a reply while Scope stays open. Refresh only when
|
|
9416
10233
|
// these states change, retaining its selected add choice and focus on an enabled control.
|
|
9417
10234
|
const picker = ui.scopePicker;
|
|
@@ -9471,7 +10288,7 @@
|
|
|
9471
10288
|
const note = document.createElement('p'); note.className = 'ai-chat-scope-note';
|
|
9472
10289
|
note.textContent = readOnly ? 'The AI’s file tools cannot change files while Read only is on. Commands keep their own approvals and may authorize file changes. Scope adds folders and project data; it does not limit file reads.'
|
|
9473
10290
|
+ (globalAllowance ? ' Your saved file-change allowance does not override Read only.' : '')
|
|
9474
|
-
: profile === 'full-access' ?
|
|
10291
|
+
: profile === 'full-access' ? fullAccessScopeNote()
|
|
9475
10292
|
: profile === 'auto' ? autoScopeNote()
|
|
9476
10293
|
: globalAllowance ? 'File changes in this scope, including folders you add later, are allowed without asking. Commands and tools keep their own approvals. Scope does not limit file reads.'
|
|
9477
10294
|
: 'File edits outside your home folder ask for approval unless you allow file changes for this chat. Scope adds folders and project data to this conversation; it does not limit file reads. Your home folder keeps its native provider permissions.';
|
|
@@ -9507,9 +10324,8 @@
|
|
|
9507
10324
|
const choice = state.scopeChoice;
|
|
9508
10325
|
const choiceKey = choice.target.kind === 'project' ? choice.target.projectId : choice.target.workflowId;
|
|
9509
10326
|
const question = document.createElement('p'); question.className = 'ai-chat-scope-note';
|
|
9510
|
-
const writeProfile = state.chat?.owner?.kind === 'workspace' ? 'Make changes (asks first)' : 'Working folder write';
|
|
9511
10327
|
question.textContent = `Add ${choice.target.kind} “${choice.label}” to this conversation?${globalAllowance ? readOnly
|
|
9512
|
-
?
|
|
10328
|
+
? ' If you choose Working folder write, file changes here will also be allowed without asking.'
|
|
9513
10329
|
: ' File changes here will also be allowed without asking.' : ''}`;
|
|
9514
10330
|
const add = button(globalAllowance ? readOnly ? 'Add scope for later file changes' : 'Add scope and allow file changes' : 'Add scope', `shell.chat-scope-add#${commandInstance(`${choice.target.kind}:${choiceKey}`)}`, 'ai-chat-scope-action');
|
|
9515
10331
|
add.dataset.commandInstanceLabel = choice.label; add.disabled = state.scopeEditing || Boolean(state.chat?.activeTurn);
|
|
@@ -10123,7 +10939,7 @@
|
|
|
10123
10939
|
ui.model.addEventListener('click', () => openPicker('model', ui.model, modelChoices()));
|
|
10124
10940
|
ui.switchAccount.addEventListener('click', () => { void switchAccount(); });
|
|
10125
10941
|
ui.effort.addEventListener('click', () => openPicker('effort', ui.effort, effortChoices()));
|
|
10126
|
-
ui.permission.addEventListener('click', () => openPicker('permission', ui.permission, permissionChoices()
|
|
10942
|
+
ui.permission.addEventListener('click', () => openPicker('permission', ui.permission, permissionChoices()));
|
|
10127
10943
|
// #2046: the Guide's own controls (web/guide.js does the work and says what happened).
|
|
10128
10944
|
el('chat-guide-off')?.addEventListener('click', () => { void window.flolessGuide?.turnOff?.(); });
|
|
10129
10945
|
el('chat-guide-delete')?.addEventListener('click', () => { void window.flolessGuide?.deleteHistory?.(); });
|
|
@@ -10144,7 +10960,10 @@
|
|
|
10144
10960
|
});
|
|
10145
10961
|
document.getElementById('ws-frame-drawings')?.addEventListener('load', () => { paintFloLessContext(); refreshFilterCards(); updateSendState(); });
|
|
10146
10962
|
ui.stop.addEventListener('click', stopTurn);
|
|
10147
|
-
ui.recoveryStop.addEventListener('click', () => {
|
|
10963
|
+
ui.recoveryStop.addEventListener('click', () => {
|
|
10964
|
+
paintRecovery();
|
|
10965
|
+
void (state.recoveryCanEnd ? endRecovery() : stopTurn());
|
|
10966
|
+
});
|
|
10148
10967
|
ui.reconcile.addEventListener('click', reconcile);
|
|
10149
10968
|
ui.attach.addEventListener('click', () => ui.file.click());
|
|
10150
10969
|
ui.file.addEventListener('change', () => attachFiles(ui.file.files));
|
|
@@ -10154,6 +10973,7 @@
|
|
|
10154
10973
|
else if (event.key === 'Escape') { ui.skills.hidden = true; closePicker(); }
|
|
10155
10974
|
});
|
|
10156
10975
|
ui.scopeToggle?.addEventListener('click', () => { void openScopePicker(); });
|
|
10976
|
+
ui.accessExplanation?.addEventListener('click', toggleAccessExplanation);
|
|
10157
10977
|
ui.scopePicker?.addEventListener('keydown', (event) => {
|
|
10158
10978
|
if (event.key === 'Escape') { event.preventDefault(); closeScopePicker(true); }
|
|
10159
10979
|
});
|