@floless/app 0.141.1 → 0.142.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 +2478 -1798
- package/dist/web/app.css +1 -0
- package/dist/web/aware.js +10 -5
- package/dist/web/chat.css +21 -0
- package/dist/web/chat.js +512 -38
- package/dist/web/commands-revit.js +1 -1
- package/dist/web/commands-shell.js +22 -4
- package/dist/web/commands-steel.js +4 -0
- package/dist/web/left-pane.js +43 -0
- package/dist/web/model-clip-session.js +2 -3
- package/dist/web/model-navigation-controls.js +17 -3
- package/dist/web/model-orientation-overlay.js +2 -3
- package/dist/web/model-panel-bridge.js +15 -3
- package/dist/web/model-viewport-revit-adapter.js +1 -0
- package/dist/web/model-viewport-toolbar.js +0 -2
- package/dist/web/revit-editor.js +4 -6
- package/dist/web/steel-3d-view.js +79 -45
- package/dist/web/steel-editor.html +167 -15
- package/dist/web/steel-filter.html +13 -4
- package/dist/web/steel-model-commands.js +0 -1
- package/dist/web/workspaces.js +28 -8
- package/package.json +1 -1
package/dist/web/chat.js
CHANGED
|
@@ -41,10 +41,13 @@
|
|
|
41
41
|
// The "not sent" sentence of a Drawing Filter message refused while FloLess sets its AI up, kept in
|
|
42
42
|
// the hint while the setup card still shows the setup it was refused for (#1650): { key, sentence }.
|
|
43
43
|
filterSetupNote: null,
|
|
44
|
+
// The last sentence report() put under the box, held there until the person acts on it (#1683):
|
|
45
|
+
// { message, scope, chatId, draft, attachments, blocked }. See heldReport().
|
|
46
|
+
reportHold: null,
|
|
44
47
|
// A Tekla model library carried over from a Graft receipt but not yet bound to its chat. It is
|
|
45
48
|
// browser-only until Send: opening, editing or removing it never calls the binding route.
|
|
46
49
|
// pendingTeklaLibrary waits for the provider chooser to create the chat it belongs to.
|
|
47
|
-
teklaDraft: null, pendingTeklaLibrary: null, teklaRemoveError: null,
|
|
50
|
+
teklaDraft: null, pendingTeklaLibrary: null, teklaRemoveError: null, teklaRevokingChatId: null, teklaNewestBinding: new Map(),
|
|
48
51
|
};
|
|
49
52
|
// A short-window resize can shrink the bounded tray after a decision card was painted.
|
|
50
53
|
// Keep its actions in view only while the reader was already at the bottom; preserve a
|
|
@@ -222,6 +225,8 @@
|
|
|
222
225
|
'chat-knowledge-unscoped': 'Knowledge is available only inside a project conversation. Open a project and try again.',
|
|
223
226
|
'chat-knowledge-page-missing': 'That Knowledge page is no longer available in this project. Refresh the conversation.',
|
|
224
227
|
'approval-explicit-only': 'This read needs its own approval. Choose Approve once or Deny.',
|
|
228
|
+
'approval-not-chat-allowable': 'Only Tekla reads can be allowed for the whole chat. Choose Approve once or Deny.',
|
|
229
|
+
'tekla-allowance-changed': 'The Tekla read permission for this chat changed. Choose again.',
|
|
225
230
|
};
|
|
226
231
|
if (code === 'chat-followup-refused' && error?.reason === 'chat-session-required') {
|
|
227
232
|
return 'Your FloLess session expired before this message was sent. Copy the draft, reload, then paste and send it again.';
|
|
@@ -343,6 +348,64 @@
|
|
|
343
348
|
announce(message);
|
|
344
349
|
ui.hint.textContent = message;
|
|
345
350
|
ui.hint.classList.add('error');
|
|
351
|
+
holdReport(message);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Every repaint of the composer (a poll, a status change, the setup card's tick) rewrites the hint,
|
|
356
|
+
* which used to wipe a reported sentence within seconds (#1683). It is the only visible reason nothing
|
|
357
|
+
* happened, so it is held, with what the composer looked like when it was said, until the person acts
|
|
358
|
+
* on it (heldReport). The Drawing Filter setup sentence is not: filterSetupHint gives it its own,
|
|
359
|
+
* longer lifetime, tied to the setup card.
|
|
360
|
+
*/
|
|
361
|
+
function holdReport(message) {
|
|
362
|
+
state.reportHold = message === state.filterSetupNote?.sentence ? null : {
|
|
363
|
+
message, scope: scopeKey(state.scope), chatId: state.chat?.chatId ?? null,
|
|
364
|
+
draft: ui.input.value, attachments: attachmentKey(), blocked: sendBlocker(),
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/** New or resolved send blockers supersede a reported sentence; keep every active reason so a change in either direction counts. */
|
|
369
|
+
function sendBlocker() {
|
|
370
|
+
const reasons = [];
|
|
371
|
+
if (state.chat?.state === 'recovery') reasons.push('recovery');
|
|
372
|
+
if (state.chat?.activeTurn?.local) reasons.push('local-turn');
|
|
373
|
+
if (state.chat?.archivedAt) reasons.push('archived');
|
|
374
|
+
if (requestExecutionBlocked()) reasons.push('execution');
|
|
375
|
+
if (state.followupUnknownId || hasUnknownFollowup()) reasons.push('unknown-followup');
|
|
376
|
+
return reasons.join('|') || null;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function attachmentKey() {
|
|
380
|
+
return state.attachments.map((attachment) => attachment.attachmentId).join('\n');
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* The reported sentence while nothing has superseded it, else null (and it is dropped for good). The
|
|
385
|
+
* person acting on it ends it: the words in the box changed (typed, sent, restored), the attachments
|
|
386
|
+
* changed, another conversation, or another chat control used (releaseReportOnControl) — each of
|
|
387
|
+
* which either works or reports its own sentence. A blocker that arose since (another AI Chat
|
|
388
|
+
* changing this project, a follow-up FloLess could not confirm) ends it too: that is now the reason.
|
|
389
|
+
*/
|
|
390
|
+
function heldReport() {
|
|
391
|
+
const hold = state.reportHold;
|
|
392
|
+
if (!hold) return null;
|
|
393
|
+
const blocker = sendBlocker();
|
|
394
|
+
if (hold.scope === scopeKey(state.scope) && hold.chatId === (state.chat?.chatId ?? null)
|
|
395
|
+
&& hold.draft === ui.input.value && hold.attachments === attachmentKey() && blocker === hold.blocked) {
|
|
396
|
+
return hold.message;
|
|
397
|
+
}
|
|
398
|
+
state.reportHold = null;
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** A click or choice on a chat control is the person acting: it supersedes a held sentence (#1683). */
|
|
403
|
+
function releaseReportOnControl(event) {
|
|
404
|
+
const control = event.target?.closest?.('button, a[href], select, input, [role="button"], [role="option"], [role="menuitem"]');
|
|
405
|
+
if (control && control !== ui.send && !control.disabled && control.getAttribute('aria-disabled') !== 'true') {
|
|
406
|
+
state.reportHold = null;
|
|
407
|
+
clearReport();
|
|
408
|
+
}
|
|
346
409
|
}
|
|
347
410
|
|
|
348
411
|
// A Drawing Filter message refused while FloLess sets its AI up (#1650) keeps its sentence in the hint
|
|
@@ -361,6 +424,14 @@
|
|
|
361
424
|
|
|
362
425
|
function clearReport() {
|
|
363
426
|
ui.hint.classList.remove('error');
|
|
427
|
+
const held = heldReport();
|
|
428
|
+
if (held) {
|
|
429
|
+
ui.hint.classList.remove('working');
|
|
430
|
+
ui.hint.removeAttribute('aria-label');
|
|
431
|
+
ui.hint.textContent = held;
|
|
432
|
+
ui.hint.classList.add('error');
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
364
435
|
const filterNote = filterSetupHint();
|
|
365
436
|
const message = requestExecutionBlocked()
|
|
366
437
|
? 'Another AI Chat is changing this project or workflow. Wait for it to finish or stop it before sending here.'
|
|
@@ -1617,6 +1688,12 @@
|
|
|
1617
1688
|
item.append(gallery);
|
|
1618
1689
|
}
|
|
1619
1690
|
}
|
|
1691
|
+
const about = role === 'user' && event.payload?.subjects ? subjectsLine(event.payload?.subjects) : '';
|
|
1692
|
+
if (about) {
|
|
1693
|
+
const line = document.createElement('span'); line.className = 'ai-chat-message-subjects';
|
|
1694
|
+
line.textContent = about;
|
|
1695
|
+
item.append(line);
|
|
1696
|
+
}
|
|
1620
1697
|
if (role === 'user' && (event.payload?.followup || event.payload?.deliveryState)) {
|
|
1621
1698
|
const delivery = followupDelivery(event);
|
|
1622
1699
|
const deliveryReceipt = [...state.events].reverse().find((candidate) => candidate.type === 'followup-status'
|
|
@@ -1972,7 +2049,8 @@
|
|
|
1972
2049
|
});
|
|
1973
2050
|
}
|
|
1974
2051
|
|
|
1975
|
-
function renderedAnswerTarget(events, eventId, turnId) {
|
|
2052
|
+
function renderedAnswerTarget(events, eventId, turnId, type = 'assistant-message') {
|
|
2053
|
+
if (type === 'user-message') return events.find((event) => event.eventId === eventId && event.type === 'user-message') || null;
|
|
1976
2054
|
if (turnId) {
|
|
1977
2055
|
return [...events].reverse().find((event) => event.turnId === turnId && event.type === 'assistant-message') || null;
|
|
1978
2056
|
}
|
|
@@ -2155,17 +2233,24 @@
|
|
|
2155
2233
|
shell.dataset.approvalPending = String(Boolean(approval) && !deciding);
|
|
2156
2234
|
document.dispatchEvent(new CustomEvent('floless:chat-indicator'));
|
|
2157
2235
|
if (!approval || deciding) { existing?.remove(); return; }
|
|
2158
|
-
// Keep the same buttons during polling so keyboard focus and pointer clicks survive.
|
|
2159
|
-
|
|
2236
|
+
// Keep the same buttons during polling so keyboard focus and pointer clicks survive. A Tekla card
|
|
2237
|
+
// also carries the permission view it offers "Allow for this chat" on, so a change repaints it.
|
|
2238
|
+
const teklaBinding = teklaAllowableApproval(approval) ? currentTeklaBinding(state.chat) : null;
|
|
2239
|
+
const allowanceRevision = teklaBinding ? String(teklaAllowanceRevision(teklaBinding)) : '';
|
|
2240
|
+
if (existing?.dataset.approvalId === approval.approvalId && (existing.dataset.allowanceRevision || '') === allowanceRevision) return;
|
|
2241
|
+
// A permission change repaints the same approval: keep keyboard focus on the same control.
|
|
2242
|
+
const refocus = existing?.dataset.approvalId === approval.approvalId && existing.contains(document.activeElement)
|
|
2243
|
+
? document.activeElement.dataset?.commandId : null;
|
|
2160
2244
|
existing?.remove();
|
|
2161
2245
|
const card = document.createElement('section'); card.className = 'ai-chat-approval';
|
|
2162
2246
|
card.dataset.approvalId = approval.approvalId;
|
|
2247
|
+
if (teklaBinding) card.dataset.allowanceRevision = allowanceRevision;
|
|
2163
2248
|
const heading = document.createElement('strong'); heading.textContent = 'Approval needed';
|
|
2164
2249
|
const copy = document.createElement('p'); copy.textContent = approval.summary;
|
|
2165
2250
|
const actions = document.createElement('div'); actions.className = 'ai-chat-approval-actions';
|
|
2166
2251
|
const deny = button('Deny', 'shell.chat-approval-deny');
|
|
2167
2252
|
const allow = button('Approve once', 'shell.chat-approval-allow', 'allow');
|
|
2168
|
-
// A Tekla
|
|
2253
|
+
// A Tekla read is never covered by a request-wide grant; it may instead be allowed for the whole chat (below).
|
|
2169
2254
|
const explicitOnly = approvalIsExplicitOnly(approval);
|
|
2170
2255
|
const allowRequest = explicitOnly ? null : button('Approve for this request', 'shell.chat-approval-request', 'allow');
|
|
2171
2256
|
const scope = document.createElement('span');
|
|
@@ -2174,16 +2259,29 @@
|
|
|
2174
2259
|
deny.addEventListener('click', () => decideApproval('deny'));
|
|
2175
2260
|
allow.addEventListener('click', () => decideApproval('allow'));
|
|
2176
2261
|
if (allowRequest) {
|
|
2177
|
-
scope.textContent = 'Approve access actions until this response finishes. Your permission setting stays unchanged. Review checkpoints and Tekla
|
|
2262
|
+
scope.textContent = 'Approve access actions until this response finishes. Your permission setting stays unchanged. Review checkpoints still ask every time, and Tekla reads ask unless you allow them for this chat.';
|
|
2178
2263
|
allowRequest.dataset.tip = scope.textContent;
|
|
2179
2264
|
allowRequest.setAttribute('aria-describedby', scope.id);
|
|
2180
2265
|
allowRequest.addEventListener('click', () => decideApproval('allow-request'));
|
|
2181
2266
|
actions.append(deny, allow, allowRequest); card.append(heading, copy, actions, scope);
|
|
2267
|
+
} else if (teklaBinding) {
|
|
2268
|
+
// A Tekla read may instead be allowed for the whole chat, covering every read the chat is bound for.
|
|
2269
|
+
card.dataset.explicitOnly = 'true';
|
|
2270
|
+
const allowChat = button('Allow for this chat', 'shell.chat-tekla-allow-chat', 'allow');
|
|
2271
|
+
const help = document.createElement('span');
|
|
2272
|
+
help.className = 'sr-only';
|
|
2273
|
+
help.id = `chat-approval-tekla-scope-help-${approval.approvalId}`;
|
|
2274
|
+
help.textContent = `Let Chat read ${teklaReadsCopy(teklaBinding.operations, ' and ')} whenever it asks in this conversation, without asking you each time. FloLess still checks Tekla live and shows every result. Revoke it from the Tekla box above the message.`;
|
|
2275
|
+
allowChat.dataset.tip = help.textContent;
|
|
2276
|
+
allowChat.setAttribute('aria-describedby', help.id);
|
|
2277
|
+
allowChat.addEventListener('click', () => decideApproval('allow-chat', Number(allowanceRevision)));
|
|
2278
|
+
actions.append(deny, allow, allowChat); card.append(heading, copy, actions, help);
|
|
2182
2279
|
} else {
|
|
2183
2280
|
card.dataset.explicitOnly = 'true';
|
|
2184
2281
|
actions.append(deny, allow); card.append(heading, copy, actions);
|
|
2185
2282
|
}
|
|
2186
2283
|
ui.approvalTray.append(card);
|
|
2284
|
+
if (refocus) [...card.querySelectorAll('button')].find((node) => node.dataset.commandId === refocus)?.focus();
|
|
2187
2285
|
// When a request-wide grant notice is also present, keep the decision nearest the composer.
|
|
2188
2286
|
ui.approvalTray.scrollTop = ui.approvalTray.scrollHeight;
|
|
2189
2287
|
}
|
|
@@ -2217,7 +2315,7 @@
|
|
|
2217
2315
|
const explanation = document.createElement('span');
|
|
2218
2316
|
explanation.className = 'sr-only';
|
|
2219
2317
|
explanation.id = `chat-approval-scope-help-${turn.turnId}`;
|
|
2220
|
-
explanation.textContent = 'Your permission setting is unchanged. Review checkpoints and Tekla
|
|
2318
|
+
explanation.textContent = 'Your permission setting is unchanged. Review checkpoints still ask every time, and Tekla reads ask unless you allow them for this chat. Revoke asks before future access actions in this request; actions already approved may finish.';
|
|
2221
2319
|
const revoke = button('Revoke', 'shell.chat-approval-revoke');
|
|
2222
2320
|
revoke.dataset.tip = explanation.textContent;
|
|
2223
2321
|
revoke.setAttribute('aria-describedby', explanation.id);
|
|
@@ -2380,11 +2478,106 @@
|
|
|
2380
2478
|
}).catch(() => {});
|
|
2381
2479
|
}
|
|
2382
2480
|
|
|
2481
|
+
/**
|
|
2482
|
+
* What the paperclip says it takes, right now.
|
|
2483
|
+
*
|
|
2484
|
+
* SEPARATE FROM `paintAttachments` BECAUSE IT DEPENDS ON THE SURFACE, NOT ONLY ON THE
|
|
2485
|
+
* ATTACHMENTS. On the Drawing Filter the answer is written by a headless AI that can only look at
|
|
2486
|
+
* pictures, so a PDF is refused — and that has to be on the control BEFORE the message is typed,
|
|
2487
|
+
* not at Send. `paintAttachments` runs when the attachments change; opening the Drawing Filter
|
|
2488
|
+
* changes neither, so a tooltip painted only there keeps the previous surface's wording. Measured
|
|
2489
|
+
* in the browser: the filter reported ready on S-203 while the paperclip still offered PDFs.
|
|
2490
|
+
* `updateSendState` runs on every repaint, including the surface switch, so both call this.
|
|
2491
|
+
*/
|
|
2492
|
+
function paintAttachControl() {
|
|
2493
|
+
const imageCount = state.attachments.filter((attachment) => attachment.mediaType.startsWith('image/')).length;
|
|
2494
|
+
const kinds = filterSurface().state === 'off' ? 'image or PDF' : 'a picture';
|
|
2495
|
+
ui.attach.dataset.tip = `Attach ${kinds} · ${imageCount} of ${MAX_IMAGES_PER_MESSAGE} images in this message`;
|
|
2496
|
+
ui.attach.setAttribute('aria-label', `Attach ${kinds} · ${imageCount} of ${MAX_IMAGES_PER_MESSAGE} images`);
|
|
2497
|
+
}
|
|
2498
|
+
|
|
2499
|
+
/* #1653: the Steel Model objects selected when a question is sent are attached to it. The pill shows what
|
|
2500
|
+
would go with the next NEW question — never with a follow-up to a running response, never on the Drawing
|
|
2501
|
+
Filter, never in a workflow's conversation — and one click leaves them out until the selection changes. */
|
|
2502
|
+
const MAX_LISTED_SUBJECTS = 200;
|
|
2503
|
+
const MAX_SUBJECT_SAMPLE = 50;
|
|
2504
|
+
|
|
2505
|
+
function subjectsKey(selection) {
|
|
2506
|
+
return selection ? `${selection.source}|${selection.key || selection.items.map((item) => `${item.kind}:${item.id}`).sort().join('\n')}` : '';
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2509
|
+
function composerSelection() {
|
|
2510
|
+
if (!state.chat || state.scope?.owner?.kind !== 'project' || turnIsVisiblyActive()) return null;
|
|
2511
|
+
if (filterSurface().state !== 'off') return null;
|
|
2512
|
+
let selection = null;
|
|
2513
|
+
try { selection = window.flolessLeftPane?.readSelection?.() || null; } catch { selection = null; }
|
|
2514
|
+
if (!selection || selection.source !== 'steel' || !selection.items?.length) return null;
|
|
2515
|
+
if (state.subjectsDismissed && state.subjectsDismissed === subjectsKey(selection)) return null;
|
|
2516
|
+
return selection;
|
|
2517
|
+
}
|
|
2518
|
+
|
|
2519
|
+
/** The selection as the server stores it: up to 200 objects one by one, more as a counted sample. */
|
|
2520
|
+
function subjectsPayload(selection) {
|
|
2521
|
+
if (!selection) return null;
|
|
2522
|
+
const pick = (item) => ({ kind: item.kind, id: item.id, label: item.label });
|
|
2523
|
+
if (selection.total > MAX_LISTED_SUBJECTS) {
|
|
2524
|
+
return { source: selection.source, revision: selection.revision, group: { count: selection.total, sample: selection.items.slice(0, MAX_SUBJECT_SAMPLE).map(pick) } };
|
|
2525
|
+
}
|
|
2526
|
+
return { source: selection.source, revision: selection.revision, items: selection.items.slice(0, MAX_LISTED_SUBJECTS).map(pick) };
|
|
2527
|
+
}
|
|
2528
|
+
|
|
2529
|
+
function subjectLabels(items, total, shown = 3) {
|
|
2530
|
+
const names = items.slice(0, shown).map((item) => item.label || item.id);
|
|
2531
|
+
const more = total - names.length;
|
|
2532
|
+
return more > 0 ? `${names.join(', ')} and ${more} more` : names.join(', ');
|
|
2533
|
+
}
|
|
2534
|
+
|
|
2535
|
+
/** The line under a sent question naming what it was about, or '' — for a listed selection or a counted group. */
|
|
2536
|
+
function subjectsLine(subjects) {
|
|
2537
|
+
if (!subjects || typeof subjects !== 'object') return '';
|
|
2538
|
+
const listed = Array.isArray(subjects.items) ? subjects.items : Array.isArray(subjects.group?.sample) ? subjects.group.sample : [];
|
|
2539
|
+
const count = Array.isArray(subjects.items) ? subjects.items.length : Number(subjects.group?.count) || listed.length;
|
|
2540
|
+
if (!count) return '';
|
|
2541
|
+
return `About ${count} Steel object${count === 1 ? '' : 's'}${listed.length ? `: ${subjectLabels(listed, count)}` : ''}`;
|
|
2542
|
+
}
|
|
2543
|
+
|
|
2544
|
+
// A question was saved with objects: the model editor's object card reads its links again.
|
|
2545
|
+
function subjectLinksSaved(subjects) {
|
|
2546
|
+
if (!subjects) return;
|
|
2547
|
+
try { window.flolessLeftPane?.chatLinksChanged?.(); } catch { /* the card refreshes on its next read */ }
|
|
2548
|
+
}
|
|
2549
|
+
|
|
2550
|
+
function paintSubjectsPill() {
|
|
2551
|
+
const selection = composerSelection();
|
|
2552
|
+
if (!selection) return false;
|
|
2553
|
+
const count = selection.total;
|
|
2554
|
+
const chip = document.createElement('span'); chip.className = 'ai-chat-attachment ai-chat-subjects';
|
|
2555
|
+
const label = button(`${count} object${count === 1 ? '' : 's'} selected`, 'shell.chat-subjects', 'ai-chat-subjects-label');
|
|
2556
|
+
label.dataset.tip = count > MAX_LISTED_SUBJECTS
|
|
2557
|
+
? `More than ${MAX_LISTED_SUBJECTS} objects are selected, so FloLess attaches them to your next question as one set instead of listing each one.`
|
|
2558
|
+
: `${subjectLabels(selection.items, count, 5)}. Attached to your next question.`;
|
|
2559
|
+
label.setAttribute('aria-label', `${count} Steel Model object${count === 1 ? '' : 's'} selected, attached to your next question`);
|
|
2560
|
+
label.addEventListener('click', () => { announce(label.dataset.tip); });
|
|
2561
|
+
const remove = button('×', 'shell.chat-subjects-remove');
|
|
2562
|
+
remove.setAttribute('aria-label', 'Leave the selected objects out of your next question');
|
|
2563
|
+
remove.dataset.tip = 'Leave out of the next question';
|
|
2564
|
+
remove.addEventListener('click', () => {
|
|
2565
|
+
state.subjectsDismissed = subjectsKey(selection);
|
|
2566
|
+
paintAttachments();
|
|
2567
|
+
ui.input.focus();
|
|
2568
|
+
announce('The selected objects will not be attached to your next question.');
|
|
2569
|
+
});
|
|
2570
|
+
chip.append(label, remove);
|
|
2571
|
+
ui.attachments.append(chip);
|
|
2572
|
+
return true;
|
|
2573
|
+
}
|
|
2574
|
+
|
|
2383
2575
|
function paintAttachments() {
|
|
2384
2576
|
ui.attachments.replaceChildren();
|
|
2385
|
-
const
|
|
2386
|
-
|
|
2387
|
-
|
|
2577
|
+
const pill = paintSubjectsPill();
|
|
2578
|
+
// paintAttachControl, not the two lines #1653 had here: it says the same thing but asks the
|
|
2579
|
+
// SURFACE what may be attached, so the Drawing Filter reads “Attach a picture” (#1681).
|
|
2580
|
+
paintAttachControl();
|
|
2388
2581
|
for (const attachment of state.attachments) {
|
|
2389
2582
|
const chip = document.createElement('span'); chip.className = 'ai-chat-attachment';
|
|
2390
2583
|
if (attachment.mediaType.startsWith('image/')) {
|
|
@@ -2410,7 +2603,7 @@
|
|
|
2410
2603
|
});
|
|
2411
2604
|
chip.append(name, remove); ui.attachments.append(chip);
|
|
2412
2605
|
}
|
|
2413
|
-
ui.attachments.hidden = state.attachments.length === 0;
|
|
2606
|
+
ui.attachments.hidden = state.attachments.length === 0 && !pill;
|
|
2414
2607
|
}
|
|
2415
2608
|
|
|
2416
2609
|
function selectedModel() {
|
|
@@ -2906,7 +3099,9 @@
|
|
|
2906
3099
|
if (!options.preserveDiscoveryDraft) { state.discoveryDraft = null; state.pendingTeklaLibrary = null; }
|
|
2907
3100
|
clearProviderChoice();
|
|
2908
3101
|
const selection = ++state.selectionGeneration;
|
|
2909
|
-
|
|
3102
|
+
// An Instructor answer, or a question an object card links to (#1653): both open at that one message.
|
|
3103
|
+
const exactQuestion = typeof options.messageEventId === 'string' ? options.messageEventId : null;
|
|
3104
|
+
const exactAnswer = exactQuestion || (typeof options.answerEventId === 'string' ? options.answerEventId : null);
|
|
2910
3105
|
clearAnswerJump();
|
|
2911
3106
|
if (!exactAnswer) {
|
|
2912
3107
|
closeSource(); closePicker();
|
|
@@ -2930,10 +3125,14 @@
|
|
|
2930
3125
|
if (generation !== state.scopeGeneration || selection !== state.selectionGeneration) return;
|
|
2931
3126
|
const answerTarget = exactAnswer
|
|
2932
3127
|
? renderedAnswerTarget(snapshot.events || [], exactAnswer,
|
|
2933
|
-
typeof options.answerTurnId === 'string' ? options.answerTurnId : null
|
|
3128
|
+
exactQuestion ? null : typeof options.answerTurnId === 'string' ? options.answerTurnId : null,
|
|
3129
|
+
exactQuestion ? 'user-message' : 'assistant-message')
|
|
2934
3130
|
: null;
|
|
2935
3131
|
if (exactAnswer && !answerTarget) {
|
|
2936
|
-
|
|
3132
|
+
const gone = exactQuestion ? 'That question is no longer in this conversation.' : 'That Instructor answer is no longer available.';
|
|
3133
|
+
announce(gone);
|
|
3134
|
+
// A question is opened from an object card in the model panel, away from the chat's own status line.
|
|
3135
|
+
if (exactQuestion) window.showToast?.(gone, 'info');
|
|
2937
3136
|
return;
|
|
2938
3137
|
}
|
|
2939
3138
|
const [capability, desktop] = await Promise.all([readCapability(chat), readDesktopCapability(chat)]);
|
|
@@ -2970,7 +3169,7 @@
|
|
|
2970
3169
|
}).catch(() => { /* a missed warm-up only means a slower first message */ });
|
|
2971
3170
|
if (answerTarget) {
|
|
2972
3171
|
markReadThrough(chat, answerTarget.sequence);
|
|
2973
|
-
announce(`Opened Instructor answer in ${state.chat.title}.`);
|
|
3172
|
+
announce(exactQuestion ? `Opened your question in ${state.chat.title}.` : `Opened Instructor answer in ${state.chat.title}.`);
|
|
2974
3173
|
} else {
|
|
2975
3174
|
markRead();
|
|
2976
3175
|
// Only move focus when nothing has taken it since the selection began: the history was not
|
|
@@ -3046,8 +3245,10 @@
|
|
|
3046
3245
|
clearLiveStream(true);
|
|
3047
3246
|
closeSource(); closePicker();
|
|
3048
3247
|
clearProviderChoice();
|
|
3248
|
+
const scopeChanged = scopeKey(scope) !== scopeKey(state.scope);
|
|
3049
3249
|
state.scope = scope;
|
|
3050
3250
|
state.scopeInitialized = true;
|
|
3251
|
+
if (scopeChanged) { try { window.flolessLeftPane?.chatLinksChanged?.(); } catch { /* the card refreshes on its next read */ } }
|
|
3051
3252
|
state.chat = null; state.chats = []; state.archivedChats = []; state.unreadableChats = []; state.events = []; state.capability = null; state.desktop = null; state.attachments = []; state.integrations = null;
|
|
3052
3253
|
// A published filter answer still lands in its own project's conversation; reopening it resumes.
|
|
3053
3254
|
for (const entry of state.filterPending.values()) clearTimeout(entry.timer);
|
|
@@ -3389,12 +3590,19 @@
|
|
|
3389
3590
|
const settingUp = Boolean(state.capability?.runtime && state.capability.runtime.state !== 'installed');
|
|
3390
3591
|
const uploading = Boolean(state.chat?.chatId && state.uploadingChatIds.has(state.chat.chatId));
|
|
3391
3592
|
ui.input.disabled = state.followupSubmitting || !state.chat || Boolean(state.chat?.archivedAt) || recovery || blocked;
|
|
3392
|
-
const filterMode = paintFilterComposer().state !== 'off';
|
|
3393
3593
|
ui.send.disabled = state.loading || state.followupSubmitting || state.filterSending || Boolean(state.followupUnknownId) || hasUnknownFollowup() || uploading || !state.chat || blocked || frozen
|
|
3394
3594
|
|| (!ui.input.value.trim() && state.attachments.length === 0) || settingUp;
|
|
3395
|
-
// Drawing Filter
|
|
3396
|
-
|
|
3397
|
-
|
|
3595
|
+
// A Drawing Filter message carries the filter's own context AND whatever pictures the person
|
|
3596
|
+
// attached (#1681). The paperclip used to be disabled here, which is the "I can't add
|
|
3597
|
+
// attachments" in that issue; the only attachment rule left is the one in `filterSendRefusal`,
|
|
3598
|
+
// and it is about the file type, not about the surface.
|
|
3599
|
+
// `state.filterSending` belongs here BECAUSE the shared tooltip below already stamps "wait for it
|
|
3600
|
+
// to appear" on this control: without it the paperclip says blocked and stays clickable, and a
|
|
3601
|
+
// picture attached mid-send is not in the set `sendFilterAi` puts back if the send fails.
|
|
3602
|
+
ui.attach.disabled = state.loading || state.followupSubmitting || state.filterSending || Boolean(state.followupUnknownId) || hasUnknownFollowup() || uploading || !state.chat || blocked || frozen;
|
|
3603
|
+
// Repainted here too: this runs on a surface switch, which changes what may be attached without
|
|
3604
|
+
// changing the attachments themselves.
|
|
3605
|
+
paintAttachControl();
|
|
3398
3606
|
const unknownReason = state.followupUnknownId || hasUnknownFollowup()
|
|
3399
3607
|
? 'FloLess could not confirm a follow-up. Review that message before sending or attaching another file.' : null;
|
|
3400
3608
|
const sendingReason = state.followupSubmitting
|
|
@@ -3404,7 +3612,6 @@
|
|
|
3404
3612
|
if (unknownReason || sendingReason) control.dataset.blockedReason = unknownReason || sendingReason;
|
|
3405
3613
|
else delete control.dataset.blockedReason;
|
|
3406
3614
|
}
|
|
3407
|
-
if (filterMode && !unknownReason && !sendingReason) ui.attach.dataset.blockedReason = 'Drawing Filter messages do not include attachments. Attach files from another tab.';
|
|
3408
3615
|
ui.stop.hidden = !active || Boolean(state.chat?.activeTurn?.local);
|
|
3409
3616
|
ui.send.hidden = false;
|
|
3410
3617
|
// Session recovery must remain available even while provider capability discovery is loading
|
|
@@ -3636,15 +3843,42 @@
|
|
|
3636
3843
|
return state.events.some((event) => event.type === 'assistant-message' && event.payload?.requestId === requestId);
|
|
3637
3844
|
}
|
|
3638
3845
|
|
|
3846
|
+
/**
|
|
3847
|
+
* The only length limit on a Drawing Filter message, and the same number the server enforces
|
|
3848
|
+
* (`MAX_SUBJECT_CHARS` in `server/instructor-request.ts`).
|
|
3849
|
+
*
|
|
3850
|
+
* It was 300 — short enough that an ordinary question naming two layers was refused, which is the
|
|
3851
|
+
* complaint #1681 opens with. It is deliberately still A limit: the message becomes the request's
|
|
3852
|
+
* subject, and an unbounded field there is its own failure.
|
|
3853
|
+
*/
|
|
3854
|
+
const FILTER_MESSAGE_LIMIT = 4000;
|
|
3855
|
+
|
|
3639
3856
|
/** Why a filter message cannot be sent right now, or null. Checked before the draft is touched. */
|
|
3640
3857
|
function filterSendRefusal(surface, text) {
|
|
3641
3858
|
const chat = state.chat;
|
|
3642
3859
|
if (surface.state !== 'ready') return 'The Drawing Filter is still loading. Wait until its layers appear, then send again. Nothing was sent.';
|
|
3643
3860
|
if (turnIsVisiblyActive(chat) || chat.activeTurn) return 'Wait for the current AI reply to finish before asking about the filter. Your message was not sent.';
|
|
3644
3861
|
if (filterPendingIn(chat.chatId)) return 'Wait for the current Drawing Filter answer before sending another. Your message was not sent.';
|
|
3645
|
-
|
|
3862
|
+
// Pictures ride along (#1681). A PDF cannot: the AI answering a Drawing Filter message looks at
|
|
3863
|
+
// images handed to it on the command line and has no file access of its own, so a PDF here would
|
|
3864
|
+
// be stored and never opened. Say that plainly rather than accept it and answer around it.
|
|
3865
|
+
const nonImage = state.attachments.find((item) => !String(item.mediaType || '').startsWith('image/'));
|
|
3866
|
+
if (nonImage) {
|
|
3867
|
+
return `“${nonImage.fileName}” can’t be sent with a Drawing Filter message — the AI answering here can only look at pictures. `
|
|
3868
|
+
+ 'Attach a screenshot of the page you mean, or ask about it in the main conversation instead. Nothing was sent.';
|
|
3869
|
+
}
|
|
3870
|
+
// A PICTURE ONLY REACHES CODEX. It travels on the command line of the headless run, and a
|
|
3871
|
+
// read-only Claude run has no tool that could open one and a relay that returns text only — so
|
|
3872
|
+
// on a Claude conversation the answer would be written having seen nothing. The run route
|
|
3873
|
+
// refuses this too, but by then a request exists and has to be unwound; the independent QA saw
|
|
3874
|
+
// exactly that, with a queued request and an "attachment ready" composer. Refuse here, before
|
|
3875
|
+
// anything is created.
|
|
3876
|
+
if (state.attachments.length && chat.provider !== 'codex') {
|
|
3877
|
+
return `${providerLabels[chat.provider] || 'This AI'} can’t be shown a picture in a Drawing Filter message. `
|
|
3878
|
+
+ 'Remove the picture to send the question on its own, or ask in a conversation with the other AI. Nothing was sent.';
|
|
3879
|
+
}
|
|
3646
3880
|
// Counted exactly as the filter page counts it, so the two limits can never disagree.
|
|
3647
|
-
if (text.length >
|
|
3881
|
+
if (text.length > FILTER_MESSAGE_LIMIT) return `Shorten your message to ${FILTER_MESSAGE_LIMIT} characters, then send it again. Nothing was sent.`;
|
|
3648
3882
|
return null;
|
|
3649
3883
|
}
|
|
3650
3884
|
|
|
@@ -3883,6 +4117,77 @@
|
|
|
3883
4117
|
return { installed: false, sentence };
|
|
3884
4118
|
}
|
|
3885
4119
|
|
|
4120
|
+
/**
|
|
4121
|
+
* Read the pictures on the composer into the data URLs `/api/guide` stores beside the request.
|
|
4122
|
+
*
|
|
4123
|
+
* A COPY, ON PURPOSE. The headless run gets its own leased file under the requests directory —
|
|
4124
|
+
* it never reaches into the conversation's attachment store — so the picture the AI was shown
|
|
4125
|
+
* stays exactly the picture that was attached, whatever happens to the chat afterwards.
|
|
4126
|
+
*
|
|
4127
|
+
* Throws a refusal on the first unreadable one rather than sending a shorter list: a message that
|
|
4128
|
+
* quietly carries two of three pictures is answered as if the third never existed.
|
|
4129
|
+
*/
|
|
4130
|
+
async function filterAiPictures(attachments, chatId, owner) {
|
|
4131
|
+
const pictures = [];
|
|
4132
|
+
for (const attachment of attachments) {
|
|
4133
|
+
let dataUrl;
|
|
4134
|
+
try {
|
|
4135
|
+
const response = await fetch(
|
|
4136
|
+
`/api/chat/conversations/${encodeURIComponent(chatId)}/attachments/${encodeURIComponent(attachment.attachmentId)}?${ownerQuery(owner)}`,
|
|
4137
|
+
{ signal: AbortSignal.timeout(20000) });
|
|
4138
|
+
if (!response.ok) throw new Error(`attachment read failed (${response.status})`);
|
|
4139
|
+
const blob = await response.blob();
|
|
4140
|
+
dataUrl = await new Promise((resolve, reject) => {
|
|
4141
|
+
const reader = new FileReader();
|
|
4142
|
+
reader.onerror = () => reject(reader.error || new Error('attachment could not be read'));
|
|
4143
|
+
reader.onload = () => resolve(String(reader.result || ''));
|
|
4144
|
+
reader.readAsDataURL(blob);
|
|
4145
|
+
});
|
|
4146
|
+
} catch (error) {
|
|
4147
|
+
console.error('[chat] a Drawing Filter attachment could not be read:', error);
|
|
4148
|
+
throw filterRefusal(`FloLess could not read “${attachment.fileName}”, so nothing was sent. Attach it again, then send the message.`);
|
|
4149
|
+
}
|
|
4150
|
+
pictures.push({ name: attachment.fileName, dataUrl, role: 'reference' });
|
|
4151
|
+
}
|
|
4152
|
+
return pictures;
|
|
4153
|
+
}
|
|
4154
|
+
|
|
4155
|
+
/**
|
|
4156
|
+
* Drop the composer rows whose bytes are now copied onto the request.
|
|
4157
|
+
*
|
|
4158
|
+
* Local state alone is not enough: reopening the conversation repaints the composer from the
|
|
4159
|
+
* chat's own pending attachments, so a row left behind would come back and be sent twice.
|
|
4160
|
+
*/
|
|
4161
|
+
async function discardSentFilterAttachments(attachments, chatId, owner) {
|
|
4162
|
+
const cleared = new Set();
|
|
4163
|
+
const stranded = [];
|
|
4164
|
+
for (const attachment of attachments) {
|
|
4165
|
+
try {
|
|
4166
|
+
await request(`/api/chat/conversations/${encodeURIComponent(chatId)}/attachments/${encodeURIComponent(attachment.attachmentId)}`, {
|
|
4167
|
+
method: 'DELETE', timeoutMs: 10000, body: JSON.stringify({ owner }),
|
|
4168
|
+
});
|
|
4169
|
+
cleared.add(attachment.attachmentId);
|
|
4170
|
+
} catch (error) {
|
|
4171
|
+
console.warn('[chat] a sent Drawing Filter attachment was not cleared:', error);
|
|
4172
|
+
stranded.push(attachment.fileName);
|
|
4173
|
+
}
|
|
4174
|
+
}
|
|
4175
|
+
// BOTH LISTS, as the chip's own remove handler does. `state.chat.attachments` is what the
|
|
4176
|
+
// conversation-wide budget counts (ten files, fifty megabytes), so pruning only the composer
|
|
4177
|
+
// would spend that budget on pictures that no longer exist and refuse the next real one.
|
|
4178
|
+
if (state.chat?.chatId === chatId) {
|
|
4179
|
+
state.chat.attachments = (state.chat.attachments || []).filter((item) => !cleared.has(item.attachmentId));
|
|
4180
|
+
}
|
|
4181
|
+
// A row that would not delete is still on the server, and the composer is repainted from the
|
|
4182
|
+
// server on the next refresh — so it comes back and rides the person's NEXT, unrelated message.
|
|
4183
|
+
// They are the only one who can clear it, so say so rather than leaving it in the console.
|
|
4184
|
+
if (stranded.length) {
|
|
4185
|
+
report(filterRefusal(`Your message was sent, but ${stranded.map((name) => `“${name}”`).join(' and ')} `
|
|
4186
|
+
+ `${stranded.length > 1 ? 'are' : 'is'} still attached to this conversation. Remove `
|
|
4187
|
+
+ `${stranded.length > 1 ? 'them' : 'it'} from the box below so ${stranded.length > 1 ? 'they do' : 'it does'} not go with your next message.`));
|
|
4188
|
+
}
|
|
4189
|
+
}
|
|
4190
|
+
|
|
3886
4191
|
async function sendFilterAi(surface) {
|
|
3887
4192
|
const snapshot = captureChat();
|
|
3888
4193
|
if (!snapshot || state.filterSending) return;
|
|
@@ -3900,7 +4205,14 @@
|
|
|
3900
4205
|
clearTimeout(state.draftTimer);
|
|
3901
4206
|
state.localDraft = { chatId: snapshot.chatId, text: '' };
|
|
3902
4207
|
state.backgroundDrafts.delete(snapshot.chatId);
|
|
4208
|
+
// Captured before the composer is cleared, and put back by the catch below if nothing was sent —
|
|
4209
|
+
// the same contract the words get.
|
|
4210
|
+
const attached = state.attachments.slice();
|
|
4211
|
+
// Set the moment the rows are handed to the server for deletion, so the catch below never offers
|
|
4212
|
+
// back a chip whose record is gone — its preview would 404 and every later send would refuse.
|
|
4213
|
+
let discarded = false;
|
|
3903
4214
|
ui.input.value = ''; autosize();
|
|
4215
|
+
state.attachments = []; paintAttachments();
|
|
3904
4216
|
state.filterSending = true; updateSendState();
|
|
3905
4217
|
let requestId = null;
|
|
3906
4218
|
let failure = null;
|
|
@@ -3928,9 +4240,14 @@
|
|
|
3928
4240
|
}
|
|
3929
4241
|
// The promise belongs to the filter page. A page thrown away mid-request never settles it, so
|
|
3930
4242
|
// the chat keeps its own deadline rather than leaving Send blocked in every conversation.
|
|
4243
|
+
const pictures = attached.length ? await filterAiPictures(attached, snapshot.chatId, snapshot.scope.owner) : [];
|
|
3931
4244
|
const created = await Promise.race([
|
|
3932
|
-
surface.bridge.createRequest(kind, text),
|
|
3933
|
-
|
|
4245
|
+
surface.bridge.createRequest(kind, text, pictures),
|
|
4246
|
+
// ONE DEADLINE, and it must not be shorter than the filter page's own: that page waits 60s
|
|
4247
|
+
// when pictures ride in the body (they are megabytes, not a few hundred bytes of narration).
|
|
4248
|
+
// Racing it at 20s declared failure while the request was still being written, leaving a real
|
|
4249
|
+
// request in Requests while the composer invited a retry that would duplicate it.
|
|
4250
|
+
new Promise((resolve) => { setTimeout(resolve, pictures.length ? 60000 : 20000, { ok: false, message: FILTER_CREATE_TIMEOUT }); }),
|
|
3934
4251
|
]);
|
|
3935
4252
|
if (!created?.ok) {
|
|
3936
4253
|
throw filterRefusal([401, 402, 403].includes(created?.status)
|
|
@@ -3988,6 +4305,7 @@
|
|
|
3988
4305
|
void writeChatDraft(snapshot.chatId, snapshot.scope.owner, draft)
|
|
3989
4306
|
.catch((error) => { if (sameChat(snapshot)) report(error, 'Draft was not saved'); });
|
|
3990
4307
|
}
|
|
4308
|
+
// The bytes are on the request now, so the composer rows have done their job.
|
|
3991
4309
|
const entry = { requestId, chatId: snapshot.chatId, kind, appId: created.request.appId || '', project: created.request.project || '', failures: 0, note: '' };
|
|
3992
4310
|
state.filterPending.set(requestId, entry);
|
|
3993
4311
|
state.filterNotices.delete(requestId);
|
|
@@ -4012,12 +4330,27 @@
|
|
|
4012
4330
|
}
|
|
4013
4331
|
return;
|
|
4014
4332
|
}
|
|
4333
|
+
// The bytes are on the request AND the run is under way, so the composer rows have done their
|
|
4334
|
+
// job. Deliberately after `startFilterRun`: a refusal above gives the pictures back with the
|
|
4335
|
+
// words, which it could not do once these rows are gone.
|
|
4336
|
+
if (attached.length) { discarded = true; await discardSentFilterAttachments(attached, snapshot.chatId, snapshot.scope.owner); }
|
|
4015
4337
|
if (started === 'unconfirmed') entry.note = 'Checking whether AI started…';
|
|
4016
4338
|
announce(FILTER_PENDING);
|
|
4017
4339
|
if (sameChat(snapshot)) paintEvents({ forceBottom: true });
|
|
4018
4340
|
scheduleFilterPoll(entry, 0);
|
|
4019
4341
|
} catch (error) {
|
|
4020
4342
|
failure = error;
|
|
4343
|
+
// Nothing was sent, so the pictures go back to the composer with the words — but ONLY while
|
|
4344
|
+
// their server records still exist. Several awaits run after the discard (the run start, the
|
|
4345
|
+
// event merge, a refusal's own restore), and a throw in any of them lands here; handing back
|
|
4346
|
+
// deleted rows would render chips whose previews 404 and make every later send refuse.
|
|
4347
|
+
// MERGED, not assigned: a second tab's row can reach this state, and overwriting would make it
|
|
4348
|
+
// disappear from the composer with nothing said.
|
|
4349
|
+
if (attached.length && !discarded && sameChat(snapshot)) {
|
|
4350
|
+
const returning = new Set(attached.map((item) => item.attachmentId));
|
|
4351
|
+
state.attachments = [...attached, ...state.attachments.filter((item) => !returning.has(item.attachmentId))];
|
|
4352
|
+
paintAttachments();
|
|
4353
|
+
}
|
|
4021
4354
|
await restoreBackgroundDraft(snapshot, text, submissionId);
|
|
4022
4355
|
} finally {
|
|
4023
4356
|
state.filterSending = false;
|
|
@@ -4212,6 +4545,10 @@
|
|
|
4212
4545
|
// normal turn, not even while the filter page is still loading.
|
|
4213
4546
|
const filter = filterSurface();
|
|
4214
4547
|
if (filter.state !== 'off') { await sendFilterAi(filter); return; }
|
|
4548
|
+
// Decided once, at the click, from what the pill showed: a follow-up that falls back to a new turn below
|
|
4549
|
+
// must not attach objects the person was never shown (#1653).
|
|
4550
|
+
const subjects = subjectsPayload(composerSelection());
|
|
4551
|
+
const subjectsField = subjects ? { subjects } : {};
|
|
4215
4552
|
if (turnIsVisiblyActive() && !state.chat.activeTurn?.local) {
|
|
4216
4553
|
const followup = await sendFollowup();
|
|
4217
4554
|
if (followup?.outcome !== 'turn-ended') return;
|
|
@@ -4234,7 +4571,7 @@
|
|
|
4234
4571
|
const optimisticEvent = {
|
|
4235
4572
|
eventId: `local:${clientSubmissionId}`, sequence: Math.max(0, ...state.events.map((event) => Number(event.sequence) || 0)) + .5,
|
|
4236
4573
|
chatId, turnId: clientSubmissionId, clientSubmissionId, providerItemId: null, type: 'user-message',
|
|
4237
|
-
payload: { text, attachmentIds }, createdAt: new Date().toISOString(), optimistic: true,
|
|
4574
|
+
payload: { text, attachmentIds, ...subjectsField }, createdAt: new Date().toISOString(), optimistic: true,
|
|
4238
4575
|
};
|
|
4239
4576
|
clearTimeout(state.draftTimer);
|
|
4240
4577
|
state.localDraft = { chatId, text: '' };
|
|
@@ -4253,10 +4590,11 @@
|
|
|
4253
4590
|
// The server alone appends this context to the provider copy. The submitted text and
|
|
4254
4591
|
// durable transcript must remain exactly what the user typed.
|
|
4255
4592
|
owner: snapshot.scope.owner, clientSubmissionId, text, displayText: text, uiContext, attachmentIds,
|
|
4256
|
-
modifying: previousChat.settings.permissionProfile !== 'read-only',
|
|
4593
|
+
modifying: previousChat.settings.permissionProfile !== 'read-only', ...subjectsField,
|
|
4257
4594
|
}),
|
|
4258
4595
|
});
|
|
4259
|
-
if (!sameChat(snapshot)) return;
|
|
4596
|
+
if (!sameChat(snapshot)) return void subjectLinksSaved(subjects);
|
|
4597
|
+
subjectLinksSaved(subjects);
|
|
4260
4598
|
state.pendingSubmissionId = null;
|
|
4261
4599
|
state.events = state.events.filter((event) => event.eventId !== optimisticEvent.eventId);
|
|
4262
4600
|
state.chat = result.chat;
|
|
@@ -4638,7 +4976,7 @@
|
|
|
4638
4976
|
}
|
|
4639
4977
|
}
|
|
4640
4978
|
|
|
4641
|
-
async function decideApproval(decision) {
|
|
4979
|
+
async function decideApproval(decision, allowanceRevision) {
|
|
4642
4980
|
const approval = state.chat?.pendingApproval;
|
|
4643
4981
|
if (!approval) return;
|
|
4644
4982
|
const snapshot = captureChat();
|
|
@@ -4653,11 +4991,13 @@
|
|
|
4653
4991
|
announce('Applying your choice…');
|
|
4654
4992
|
try {
|
|
4655
4993
|
await request(`/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/approvals/${encodeURIComponent(approvalId)}`, {
|
|
4656
|
-
method: 'POST', body: JSON.stringify({ owner: snapshot.scope.owner, decision
|
|
4994
|
+
method: 'POST', body: JSON.stringify({ owner: snapshot.scope.owner, decision,
|
|
4995
|
+
...(decision === 'allow-chat' ? { allowanceRevision } : {}) }),
|
|
4657
4996
|
});
|
|
4658
4997
|
if (!sameChat(snapshot)) return;
|
|
4659
4998
|
announce(decision === 'allow-request' ? 'Access auto-approval is on for this request.'
|
|
4660
|
-
: decision === 'allow' ? '
|
|
4999
|
+
: decision === 'allow-chat' ? 'Tekla reads are allowed for this chat. Revoke them from the Tekla box above the message.'
|
|
5000
|
+
: decision === 'allow' ? 'Approved once.' : 'Action denied.');
|
|
4661
5001
|
await refreshConversation(snapshot.chatId, false);
|
|
4662
5002
|
} catch (error) {
|
|
4663
5003
|
if (!sameChat(snapshot)) return;
|
|
@@ -4701,6 +5041,28 @@
|
|
|
4701
5041
|
});
|
|
4702
5042
|
}
|
|
4703
5043
|
|
|
5044
|
+
/**
|
|
5045
|
+
* Why these files cannot be attached on the surface the person is on, or null.
|
|
5046
|
+
*
|
|
5047
|
+
* REFUSED AT THE CHOOSER, not at Send. The AI answering a Drawing Filter message is handed
|
|
5048
|
+
* pictures on a command line and has no way to open a document, so a PDF attached there could
|
|
5049
|
+
* only be uploaded, counted against the conversation's budget, and then refused after the whole
|
|
5050
|
+
* message had been written around it. `paintAttachControl` already says "Attach a picture" on that
|
|
5051
|
+
* surface; this is the half that makes the control's word good.
|
|
5052
|
+
*
|
|
5053
|
+
* A NAMED FUNCTION rather than an inline block, because `attachFiles` is held to a guard that
|
|
5054
|
+
* requires its `captureChat()` and `sameChat(snapshot)` to stay within reach of each other — the
|
|
5055
|
+
* ownership pattern every in-flight action follows. Inlining this pushed them apart and turned
|
|
5056
|
+
* that guard red, which is the guard doing its job.
|
|
5057
|
+
*/
|
|
5058
|
+
function filterAttachRefusal(incoming) {
|
|
5059
|
+
if (filterSurface().state === 'off') return null;
|
|
5060
|
+
const document = incoming.find((file) => !String(file.type || '').startsWith('image/'));
|
|
5061
|
+
if (!document) return null;
|
|
5062
|
+
return `“${document.name}” can’t be sent with a Drawing Filter message — the AI answering here can only look at pictures. `
|
|
5063
|
+
+ 'Attach a screenshot of the page you mean, or ask about it in the main conversation instead. Nothing was attached.';
|
|
5064
|
+
}
|
|
5065
|
+
|
|
4704
5066
|
async function attachFiles(files) {
|
|
4705
5067
|
if (!state.chat || state.chat.activeTurn?.local || state.chat.state === 'recovery' || state.followupSubmitting || state.followupUnknownId || hasUnknownFollowup()) return;
|
|
4706
5068
|
const snapshot = captureChat();
|
|
@@ -4711,6 +5073,8 @@
|
|
|
4711
5073
|
// an image, selecting that same file again must fire a fresh change event.
|
|
4712
5074
|
ui.file.value = '';
|
|
4713
5075
|
if (incoming.some((file) => !allowedTypes.has(file.type))) { report(new Error('Attach a PNG, JPEG, WebP, or PDF')); return; }
|
|
5076
|
+
const filterRefused = filterAttachRefusal(incoming);
|
|
5077
|
+
if (filterRefused) { report(filterRefusal(filterRefused)); return; }
|
|
4714
5078
|
const imageCount = state.attachments.filter((attachment) => attachment.mediaType.startsWith('image/')).length
|
|
4715
5079
|
+ incoming.filter((file) => file.type.startsWith('image/')).length;
|
|
4716
5080
|
if (imageCount > MAX_IMAGES_PER_MESSAGE) {
|
|
@@ -4792,6 +5156,9 @@
|
|
|
4792
5156
|
const fetchedSequence = Number(active.lastEventSequence) || 0;
|
|
4793
5157
|
if (fetchedSequence >= knownSequence) Object.assign(state.chat, active);
|
|
4794
5158
|
}
|
|
5159
|
+
// A Tekla read allowance granted or revoked in another window changes only the chat record,
|
|
5160
|
+
// never the event stream: this poll is how the Tekla box and any open card learn of it.
|
|
5161
|
+
paintTeklaChip();
|
|
4795
5162
|
// SSE delivers messages immediately, while this poll is what confirms that the provider has
|
|
4796
5163
|
// finished. Keep the Rename chat control in step with that durable active-turn state.
|
|
4797
5164
|
ui.rename.hidden = !state.chat || Boolean(state.chat.activeTurn) || Boolean(state.chat.archivedAt);
|
|
@@ -4924,15 +5291,20 @@
|
|
|
4924
5291
|
return result;
|
|
4925
5292
|
}
|
|
4926
5293
|
|
|
4927
|
-
async function openConversation(chatId) {
|
|
5294
|
+
async function openConversation(chatId, options = {}) {
|
|
4928
5295
|
await refreshScope();
|
|
4929
5296
|
if (!state.scope?.owner) throw new Error('Open this conversation’s project or workflow, then try again.');
|
|
5297
|
+
// An object card names its project; a conversation is only ever asked for in that project's scope (#1653).
|
|
5298
|
+
if (typeof options.projectId === 'string' && (state.scope.owner.kind !== 'project' || state.scope.owner.projectId !== options.projectId)) {
|
|
5299
|
+
throw new Error('Open this project in Workspaces to see that conversation.');
|
|
5300
|
+
}
|
|
4930
5301
|
window.flolessBridge?.revealAiChat?.();
|
|
4931
5302
|
ui.tab.click();
|
|
4932
5303
|
const listed = await request(`/api/chat/conversations?${ownerQuery()}`);
|
|
4933
5304
|
state.chats = listed.chats || [];
|
|
4934
5305
|
paintHistory(); paintUnread();
|
|
4935
|
-
|
|
5306
|
+
const messageEventId = typeof options.messageEventId === 'string' ? options.messageEventId : undefined;
|
|
5307
|
+
await selectConversation(chatId, { focus: !messageEventId, replaceProviderChoice: true, ...(messageEventId ? { messageEventId } : {}) });
|
|
4936
5308
|
}
|
|
4937
5309
|
|
|
4938
5310
|
const TEKLA_OPERATION = 'Tekla.Structures.Model.Model.GetInfo().ModelName';
|
|
@@ -4953,7 +5325,7 @@
|
|
|
4953
5325
|
if (!node) return;
|
|
4954
5326
|
const chat = state.chat;
|
|
4955
5327
|
const draft = teklaDraftForChat(chat);
|
|
4956
|
-
const bound = chat
|
|
5328
|
+
const bound = currentTeklaBinding(chat);
|
|
4957
5329
|
const library = draft?.library || bound;
|
|
4958
5330
|
if (!chat || !library) {
|
|
4959
5331
|
if (!node.hidden || node.childElementCount) { node.replaceChildren(); node.hidden = true; delete node.dataset.key; }
|
|
@@ -4963,7 +5335,11 @@
|
|
|
4963
5335
|
const frozen = !draft && teklaBindingFrozen(chat);
|
|
4964
5336
|
const error = draft?.error || (state.teklaRemoveError?.chatId === chat.chatId ? state.teklaRemoveError.message : null);
|
|
4965
5337
|
const reads = teklaReadsCopy(library.operations);
|
|
4966
|
-
|
|
5338
|
+
// A standing allowance exists only on the server's bound record, never on a local draft.
|
|
5339
|
+
const allowed = !draft && Boolean(bound?.allowedForChat);
|
|
5340
|
+
const revoking = allowed && state.teklaRevokingChatId === chat.chatId;
|
|
5341
|
+
const key = [chat.chatId, library.sourcePath, library.hostVersion, reads, status, frozen, error || '',
|
|
5342
|
+
allowed, revoking, teklaAllowanceRevision(bound)].join('|');
|
|
4967
5343
|
// Keep the same Remove button across polls so keyboard focus survives a repaint.
|
|
4968
5344
|
if (node.dataset.key === key && !node.hidden) return;
|
|
4969
5345
|
node.dataset.key = key;
|
|
@@ -4974,8 +5350,14 @@
|
|
|
4974
5350
|
const copy = document.createElement('span'); copy.className = 'ai-chat-tekla-chip-copy';
|
|
4975
5351
|
copy.id = `chat-tekla-context-copy-${chat.chatId}`;
|
|
4976
5352
|
const lead = document.createElement('strong'); lead.textContent = `Tekla ${library.hostVersion} model library`;
|
|
4977
|
-
copy.append(lead, document.createTextNode(
|
|
4978
|
-
|
|
5353
|
+
copy.append(lead, document.createTextNode(allowed
|
|
5354
|
+
? ` · Chat may ask to read ${reads} — FloLess checks live each time and shows every result`
|
|
5355
|
+
: ` · Chat may ask to read ${reads} — FloLess asks you first and checks live each time`));
|
|
5356
|
+
if (allowed) {
|
|
5357
|
+
const pill = document.createElement('span'); pill.className = 'ai-chat-tekla-allowed';
|
|
5358
|
+
pill.textContent = 'Allowed for this chat';
|
|
5359
|
+
copy.append(document.createTextNode(' '), pill);
|
|
5360
|
+
} else if (status === 'bound') {
|
|
4979
5361
|
const suffix = document.createElement('span'); suffix.className = 'ai-chat-tekla-chip-state';
|
|
4980
5362
|
suffix.textContent = ' · added to this chat';
|
|
4981
5363
|
copy.append(suffix);
|
|
@@ -4997,6 +5379,17 @@
|
|
|
4997
5379
|
remove.addEventListener('click', () => { void removeTeklaChip(); });
|
|
4998
5380
|
chip.append(remove);
|
|
4999
5381
|
}
|
|
5382
|
+
if (allowed) {
|
|
5383
|
+
const revoke = button(revoking ? 'Revoking…' : 'Revoke', 'shell.chat-tekla-allowance-revoke', 'ai-chat-tekla-remove');
|
|
5384
|
+
revoke.setAttribute('aria-label', 'Revoke allowing Tekla reads in this chat');
|
|
5385
|
+
revoke.setAttribute('aria-describedby', copy.id);
|
|
5386
|
+
revoke.dataset.tip = 'Chat will ask you again before each Tekla read. A read already running may finish.';
|
|
5387
|
+
revoke.disabled = revoking;
|
|
5388
|
+
revoke.setAttribute('aria-busy', String(revoking));
|
|
5389
|
+
if (revoking) revoke.dataset.blockedReason = 'FloLess is revoking this permission.';
|
|
5390
|
+
revoke.addEventListener('click', () => { void revokeTeklaAllowance(); });
|
|
5391
|
+
chip.append(revoke);
|
|
5392
|
+
}
|
|
5000
5393
|
node.append(chip);
|
|
5001
5394
|
if (error) {
|
|
5002
5395
|
const reason = document.createElement('p'); reason.className = 'ai-chat-tekla-error';
|
|
@@ -5044,19 +5437,86 @@
|
|
|
5044
5437
|
}
|
|
5045
5438
|
}
|
|
5046
5439
|
|
|
5440
|
+
// Ends this chat's standing Tekla read allowance. Nothing to confirm: it only removes permission.
|
|
5441
|
+
async function revokeTeklaAllowance() {
|
|
5442
|
+
const chat = state.chat;
|
|
5443
|
+
const snapshot = captureChat();
|
|
5444
|
+
// Revoke is idempotent on the server, so a click always asks it: a local view that already reads
|
|
5445
|
+
// "not allowed" must never turn Revoke into a silent no-op while the server still allows reads.
|
|
5446
|
+
if (!chat?.teklaModelRead || !snapshot || state.teklaRevokingChatId === chat.chatId) return;
|
|
5447
|
+
state.teklaRemoveError = null;
|
|
5448
|
+
state.teklaRevokingChatId = chat.chatId;
|
|
5449
|
+
paintTeklaChip();
|
|
5450
|
+
try {
|
|
5451
|
+
const result = await request(`/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/tekla-model-read/allowance/revoke`, {
|
|
5452
|
+
method: 'POST', body: JSON.stringify({ owner: snapshot.scope.owner }),
|
|
5453
|
+
});
|
|
5454
|
+
if (!sameChat(snapshot)) return;
|
|
5455
|
+
// Only the server's own record, with no allowance left, may say it ended.
|
|
5456
|
+
const updated = result?.chat;
|
|
5457
|
+
if (!updated || updated.chatId !== snapshot.chatId || updated.teklaModelRead?.allowedForChat) {
|
|
5458
|
+
state.teklaRemoveError = { chatId: snapshot.chatId, message: 'FloLess could not confirm that Tekla reads will ask again. Try Revoke again.' };
|
|
5459
|
+
return;
|
|
5460
|
+
}
|
|
5461
|
+
state.chat = { ...state.chat, teklaModelRead: updated.teklaModelRead };
|
|
5462
|
+
currentTeklaBinding(state.chat);
|
|
5463
|
+
announce('Tekla reads will ask you again in this chat.');
|
|
5464
|
+
} catch (error) {
|
|
5465
|
+
if (!sameChat(snapshot)) return;
|
|
5466
|
+
state.teklaRemoveError = { chatId: snapshot.chatId, message: errorMessage(error) };
|
|
5467
|
+
} finally {
|
|
5468
|
+
if (state.teklaRevokingChatId === snapshot.chatId) state.teklaRevokingChatId = null;
|
|
5469
|
+
if (sameChat(snapshot)) {
|
|
5470
|
+
const hadFocus = ui.teklaChip?.contains(document.activeElement);
|
|
5471
|
+
paintTeklaChip();
|
|
5472
|
+
// The Revoke button is gone: keep focus in the Tekla box instead of dropping it to the page.
|
|
5473
|
+
if (hadFocus || document.activeElement === document.body) {
|
|
5474
|
+
const target = ui.teklaChip?.querySelector('[data-command-id="shell.chat-tekla-allowance-revoke"]')
|
|
5475
|
+
|| ui.teklaChip?.querySelector('.ai-chat-tekla-chip-copy');
|
|
5476
|
+
if (target && !target.matches('button')) target.setAttribute('tabindex', '-1');
|
|
5477
|
+
target?.focus();
|
|
5478
|
+
}
|
|
5479
|
+
}
|
|
5480
|
+
}
|
|
5481
|
+
}
|
|
5482
|
+
|
|
5483
|
+
// A pending approval that may be allowed for the whole chat: a Tekla read the bound library permits.
|
|
5484
|
+
function teklaAllowableApproval(approval) {
|
|
5485
|
+
const binding = currentTeklaBinding(state.chat);
|
|
5486
|
+
const tool = approval?.tool ?? state.events?.find((event) => event.type === 'approval-requested'
|
|
5487
|
+
&& event.payload?.approvalId === approval?.approvalId)?.payload?.tool;
|
|
5488
|
+
return Boolean(binding && approvalIsExplicitOnly(approval) && typeof tool === 'string'
|
|
5489
|
+
&& tool.startsWith('floless_tekla_') && !teklaDraftForChat(state.chat));
|
|
5490
|
+
}
|
|
5491
|
+
// The chat's Tekla binding, never older than one this page has already seen. A poll that left before
|
|
5492
|
+
// a grant or revoke can land after it; the allowance revision only ever rises for one binding, so the
|
|
5493
|
+
// higher one is the newer truth and a stale snapshot cannot bring back a revoked pill.
|
|
5494
|
+
function currentTeklaBinding(chat) {
|
|
5495
|
+
const binding = chat?.teklaModelRead || null;
|
|
5496
|
+
if (!binding) return null;
|
|
5497
|
+
const key = `${chat.chatId}|${binding.sourcePath}|${binding.boundAt}`;
|
|
5498
|
+
const seen = state.teklaNewestBinding.get(key);
|
|
5499
|
+
if (seen && teklaAllowanceRevision(seen) > teklaAllowanceRevision(binding)) return seen;
|
|
5500
|
+
state.teklaNewestBinding.set(key, binding);
|
|
5501
|
+
return binding;
|
|
5502
|
+
}
|
|
5503
|
+
function teklaAllowanceRevision(binding) {
|
|
5504
|
+
return Number.isSafeInteger(binding?.allowanceRevision) ? binding.allowanceRevision : 0;
|
|
5505
|
+
}
|
|
5506
|
+
|
|
5047
5507
|
// The reads a library binding permits, as the chip names them. A binding stored before the
|
|
5048
5508
|
// selection read existed has no list and permits the model name only.
|
|
5049
5509
|
// The closed list the server accepts, in its canonical order: [model name, selection].
|
|
5050
5510
|
function teklaChatReads() {
|
|
5051
5511
|
return ['Tekla.Structures.Model.Model.GetInfo().ModelName', 'Tekla.Structures.Model.UI.ModelObjectSelector.GetSelectedObjects()'];
|
|
5052
5512
|
}
|
|
5053
|
-
function teklaReadsCopy(operations) {
|
|
5513
|
+
function teklaReadsCopy(operations, joiner = ' or ') {
|
|
5054
5514
|
const [modelRead, selectionRead] = teklaChatReads();
|
|
5055
5515
|
const list = Array.isArray(operations) ? operations : [modelRead];
|
|
5056
5516
|
const names = [];
|
|
5057
5517
|
if (list.includes(modelRead)) names.push('the open model name');
|
|
5058
5518
|
if (list.includes(selectionRead)) names.push('the parts you have selected');
|
|
5059
|
-
return names.join(
|
|
5519
|
+
return names.join(joiner);
|
|
5060
5520
|
}
|
|
5061
5521
|
function sameTeklaReads(a, b) {
|
|
5062
5522
|
const [modelRead] = teklaChatReads();
|
|
@@ -5234,6 +5694,9 @@
|
|
|
5234
5694
|
ui.integrations.addEventListener('click', openIntegrations);
|
|
5235
5695
|
ui.send.addEventListener('click', sendTurn);
|
|
5236
5696
|
// The Drawing Filter page reports every change that can alter what the chat shows about it.
|
|
5697
|
+
// The surface decides what may be attached, so repaint the paperclip the moment the step changes
|
|
5698
|
+
// rather than waiting for the next unrelated repaint.
|
|
5699
|
+
window.addEventListener('floless:workspace-step-changed', () => { paintAttachControl(); });
|
|
5237
5700
|
window.addEventListener('floless:filter-ai-changed', () => {
|
|
5238
5701
|
state.filterCardMessages.clear();
|
|
5239
5702
|
paintFloLessContext(); refreshFilterCards(); updateSendState();
|
|
@@ -5249,6 +5712,8 @@
|
|
|
5249
5712
|
if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) { event.preventDefault(); sendTurn(); }
|
|
5250
5713
|
else if (event.key === 'Escape') { ui.skills.hidden = true; closePicker(); }
|
|
5251
5714
|
});
|
|
5715
|
+
// Capture phase: the control's own handler runs after, so a sentence it reports is held afresh.
|
|
5716
|
+
shell.addEventListener('click', releaseReportOnControl, true);
|
|
5252
5717
|
shell.addEventListener('dragover', (event) => { if (event.dataTransfer?.types.includes('Files')) event.preventDefault(); });
|
|
5253
5718
|
shell.addEventListener('drop', (event) => { if (event.dataTransfer?.files?.length) { event.preventDefault(); attachFiles(event.dataTransfer.files); } });
|
|
5254
5719
|
ui.input.addEventListener('paste', (event) => {
|
|
@@ -5279,10 +5744,19 @@
|
|
|
5279
5744
|
|
|
5280
5745
|
state.refreshTimer = setInterval(pollChatsTick, 5000);
|
|
5281
5746
|
window.addEventListener('pagehide', () => { closeSource(); contextObserver.disconnect(); activityResizeObserver.disconnect(); clearInterval(state.refreshTimer); clearTimeout(state.draftTimer); });
|
|
5747
|
+
// A new selection is a new decision: a pill left out for the old one comes back for it.
|
|
5748
|
+
window.addEventListener('floless:model-selection', () => {
|
|
5749
|
+
let selection = null;
|
|
5750
|
+
try { selection = window.flolessLeftPane?.readSelection?.() || null; } catch { selection = null; }
|
|
5751
|
+
if (state.subjectsDismissed && subjectsKey(selection) !== state.subjectsDismissed) state.subjectsDismissed = null;
|
|
5752
|
+
paintAttachments();
|
|
5753
|
+
});
|
|
5282
5754
|
window.flolessChat = {
|
|
5283
5755
|
refreshScope, refreshActivity, refreshIndex, startRequest, openConversation, openDraft, openVerifiedTeklaDraft,
|
|
5284
5756
|
startProjectIntake, resumeProjectIntake,
|
|
5285
5757
|
currentProvider: () => state.chat?.provider ?? null,
|
|
5758
|
+
// The project this panel's conversations belong to; an object card offers Show in chat only for it (#1653).
|
|
5759
|
+
scopeProjectId: () => (state.scope?.owner?.kind === 'project' ? state.scope.owner.projectId : null),
|
|
5286
5760
|
// The New project dialog's AI choice (#1605) words each provider's sign-in the way this
|
|
5287
5761
|
// panel's own chooser does, so the two ways into a conversation read the same.
|
|
5288
5762
|
providerAccountLabel,
|