@floless/app 0.141.1 → 0.143.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 +71730 -58472
- package/dist/web/app.css +1 -0
- package/dist/web/app.js +5 -4
- package/dist/web/aware.js +27 -5
- package/dist/web/chat.css +23 -0
- package/dist/web/chat.js +549 -41
- 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/filter-ai-context.js +35 -6
- package/dist/web/filter-ai-proposal.js +40 -4
- package/dist/web/instructor.js +13 -11
- 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 +185 -15
- package/dist/web/steel-filter.html +30 -7
- 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,15 @@
|
|
|
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,
|
|
47
|
+
// Only this exact report announcement may be removed when its composer reason ends (#1704).
|
|
48
|
+
reportLiveMessage: null,
|
|
44
49
|
// A Tekla model library carried over from a Graft receipt but not yet bound to its chat. It is
|
|
45
50
|
// browser-only until Send: opening, editing or removing it never calls the binding route.
|
|
46
51
|
// pendingTeklaLibrary waits for the provider chooser to create the chat it belongs to.
|
|
47
|
-
teklaDraft: null, pendingTeklaLibrary: null, teklaRemoveError: null,
|
|
52
|
+
teklaDraft: null, pendingTeklaLibrary: null, teklaRemoveError: null, teklaRevokingChatId: null, teklaNewestBinding: new Map(),
|
|
48
53
|
};
|
|
49
54
|
// A short-window resize can shrink the bounded tray after a decision card was painted.
|
|
50
55
|
// Keep its actions in view only while the reader was already at the bottom; preserve a
|
|
@@ -124,9 +129,9 @@
|
|
|
124
129
|
return body;
|
|
125
130
|
}
|
|
126
131
|
|
|
127
|
-
function announce(message) {
|
|
132
|
+
function announce(message, stillCurrent = () => true) {
|
|
128
133
|
ui.status.textContent = '';
|
|
129
|
-
requestAnimationFrame(() => { ui.status.textContent = message; });
|
|
134
|
+
requestAnimationFrame(() => { if (stillCurrent()) ui.status.textContent = message; });
|
|
130
135
|
}
|
|
131
136
|
|
|
132
137
|
function setBusy(busy) {
|
|
@@ -222,6 +227,8 @@
|
|
|
222
227
|
'chat-knowledge-unscoped': 'Knowledge is available only inside a project conversation. Open a project and try again.',
|
|
223
228
|
'chat-knowledge-page-missing': 'That Knowledge page is no longer available in this project. Refresh the conversation.',
|
|
224
229
|
'approval-explicit-only': 'This read needs its own approval. Choose Approve once or Deny.',
|
|
230
|
+
'approval-not-chat-allowable': 'Only Tekla reads can be allowed for the whole chat. Choose Approve once or Deny.',
|
|
231
|
+
'tekla-allowance-changed': 'The Tekla read permission for this chat changed. Choose again.',
|
|
225
232
|
};
|
|
226
233
|
if (code === 'chat-followup-refused' && error?.reason === 'chat-session-required') {
|
|
227
234
|
return 'Your FloLess session expired before this message was sent. Copy the draft, reload, then paste and send it again.';
|
|
@@ -340,9 +347,68 @@
|
|
|
340
347
|
|| error?.name === 'TypeError' || error?.name === 'SyntaxError';
|
|
341
348
|
if (unexpected) console.error(`[ai-chat] ${message}`, error?.cause ?? '', error);
|
|
342
349
|
else if (status !== null) console.warn(`[ai-chat] ${message}`, error);
|
|
343
|
-
|
|
350
|
+
state.reportLiveMessage = message;
|
|
351
|
+
announce(message, () => state.reportLiveMessage === message);
|
|
344
352
|
ui.hint.textContent = message;
|
|
345
353
|
ui.hint.classList.add('error');
|
|
354
|
+
holdReport(message);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Every repaint of the composer (a poll, a status change, the setup card's tick) rewrites the hint,
|
|
359
|
+
* which used to wipe a reported sentence within seconds (#1683). It is the only visible reason nothing
|
|
360
|
+
* happened, so it is held, with what the composer looked like when it was said, until the person acts
|
|
361
|
+
* on it (heldReport). The Drawing Filter setup sentence is not: filterSetupHint gives it its own,
|
|
362
|
+
* longer lifetime, tied to the setup card.
|
|
363
|
+
*/
|
|
364
|
+
function holdReport(message) {
|
|
365
|
+
state.reportHold = message === state.filterSetupNote?.sentence ? null : {
|
|
366
|
+
message, scope: scopeKey(state.scope), chatId: state.chat?.chatId ?? null,
|
|
367
|
+
draft: ui.input.value, attachments: attachmentKey(), blocked: sendBlocker(),
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** New or resolved send blockers supersede a reported sentence; keep every active reason so a change in either direction counts. */
|
|
372
|
+
function sendBlocker() {
|
|
373
|
+
const reasons = [];
|
|
374
|
+
if (state.chat?.state === 'recovery') reasons.push('recovery');
|
|
375
|
+
if (state.chat?.activeTurn?.local) reasons.push('local-turn');
|
|
376
|
+
if (state.chat?.archivedAt) reasons.push('archived');
|
|
377
|
+
if (requestExecutionBlocked()) reasons.push('execution');
|
|
378
|
+
if (state.followupUnknownId || hasUnknownFollowup()) reasons.push('unknown-followup');
|
|
379
|
+
return reasons.join('|') || null;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function attachmentKey() {
|
|
383
|
+
return state.attachments.map((attachment) => attachment.attachmentId).join('\n');
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* The reported sentence while nothing has superseded it, else null (and it is dropped for good). The
|
|
388
|
+
* person acting on it ends it: the words in the box changed (typed, sent, restored), the attachments
|
|
389
|
+
* changed, another conversation, or another chat control used (releaseReportOnControl) — each of
|
|
390
|
+
* which either works or reports its own sentence. A blocker that arose since (another AI Chat
|
|
391
|
+
* changing this project, a follow-up FloLess could not confirm) ends it too: that is now the reason.
|
|
392
|
+
*/
|
|
393
|
+
function heldReport() {
|
|
394
|
+
const hold = state.reportHold;
|
|
395
|
+
if (!hold) return null;
|
|
396
|
+
const blocker = sendBlocker();
|
|
397
|
+
if (hold.scope === scopeKey(state.scope) && hold.chatId === (state.chat?.chatId ?? null)
|
|
398
|
+
&& hold.draft === ui.input.value && hold.attachments === attachmentKey() && blocker === hold.blocked) {
|
|
399
|
+
return hold.message;
|
|
400
|
+
}
|
|
401
|
+
state.reportHold = null;
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/** A click or choice on a chat control is the person acting: it supersedes a held sentence (#1683). */
|
|
406
|
+
function releaseReportOnControl(event) {
|
|
407
|
+
const control = event.target?.closest?.('button, a[href], select, input, [role="button"], [role="option"], [role="menuitem"]');
|
|
408
|
+
if (control && control !== ui.send && !control.disabled && control.getAttribute('aria-disabled') !== 'true') {
|
|
409
|
+
state.reportHold = null;
|
|
410
|
+
clearReport();
|
|
411
|
+
}
|
|
346
412
|
}
|
|
347
413
|
|
|
348
414
|
// A Drawing Filter message refused while FloLess sets its AI up (#1650) keeps its sentence in the hint
|
|
@@ -361,6 +427,14 @@
|
|
|
361
427
|
|
|
362
428
|
function clearReport() {
|
|
363
429
|
ui.hint.classList.remove('error');
|
|
430
|
+
const held = heldReport();
|
|
431
|
+
if (held) {
|
|
432
|
+
ui.hint.classList.remove('working');
|
|
433
|
+
ui.hint.removeAttribute('aria-label');
|
|
434
|
+
ui.hint.textContent = held;
|
|
435
|
+
ui.hint.classList.add('error');
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
364
438
|
const filterNote = filterSetupHint();
|
|
365
439
|
const message = requestExecutionBlocked()
|
|
366
440
|
? 'Another AI Chat is changing this project or workflow. Wait for it to finish or stop it before sending here.'
|
|
@@ -390,6 +464,16 @@
|
|
|
390
464
|
// Painted as it was reported, so the poll does not restyle it.
|
|
391
465
|
if (filterNote && message === filterNote) ui.hint.classList.add('error');
|
|
392
466
|
}
|
|
467
|
+
// The refusal no longer describes the composer. Only remove that exact announcement:
|
|
468
|
+
// a response may have since claimed the same live region (#1704).
|
|
469
|
+
if (state.reportLiveMessage && ui.hint.textContent !== state.reportLiveMessage) {
|
|
470
|
+
retireReportAnnouncement();
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function retireReportAnnouncement() {
|
|
475
|
+
if (ui.status.textContent === state.reportLiveMessage) ui.status.textContent = '';
|
|
476
|
+
state.reportLiveMessage = null;
|
|
393
477
|
}
|
|
394
478
|
|
|
395
479
|
function scopeKey(scope) {
|
|
@@ -1617,6 +1701,12 @@
|
|
|
1617
1701
|
item.append(gallery);
|
|
1618
1702
|
}
|
|
1619
1703
|
}
|
|
1704
|
+
const about = role === 'user' && event.payload?.subjects ? subjectsLine(event.payload?.subjects) : '';
|
|
1705
|
+
if (about) {
|
|
1706
|
+
const line = document.createElement('span'); line.className = 'ai-chat-message-subjects';
|
|
1707
|
+
line.textContent = about;
|
|
1708
|
+
item.append(line);
|
|
1709
|
+
}
|
|
1620
1710
|
if (role === 'user' && (event.payload?.followup || event.payload?.deliveryState)) {
|
|
1621
1711
|
const delivery = followupDelivery(event);
|
|
1622
1712
|
const deliveryReceipt = [...state.events].reverse().find((candidate) => candidate.type === 'followup-status'
|
|
@@ -1741,6 +1831,15 @@
|
|
|
1741
1831
|
compaction: 'Conversation summary updated', 'knowledge-citation': 'Knowledge cited', state: 'Status', request: 'Request',
|
|
1742
1832
|
};
|
|
1743
1833
|
const payload = event.payload || {};
|
|
1834
|
+
if (event.type === 'chat-subjects') {
|
|
1835
|
+
// The chat model linked Steel objects to this question (#1653). Its note is untrusted text: textContent only.
|
|
1836
|
+
item.classList.add('links');
|
|
1837
|
+
const count = Array.isArray(payload.items) ? payload.items.length : 0;
|
|
1838
|
+
label.textContent = payload.role === 'answer' ? 'Named in answer' : 'Linked objects';
|
|
1839
|
+
const note = typeof payload.aiNote === 'string' ? payload.aiNote : '';
|
|
1840
|
+
item.append(label, document.createTextNode(` · ${count} object${count === 1 ? '' : 's'}${note ? ` · AI note: ${note}` : ''}`));
|
|
1841
|
+
return item;
|
|
1842
|
+
}
|
|
1744
1843
|
label.textContent = event.type === 'error' && payload.outcome === 'not-sent' ? 'Not sent' : labels[event.type] || event.type;
|
|
1745
1844
|
let detail = event.type === 'error' ? errorMessage(payloadText(event)) : payloadText(event);
|
|
1746
1845
|
if (!detail && event.type === 'tool') {
|
|
@@ -1972,7 +2071,8 @@
|
|
|
1972
2071
|
});
|
|
1973
2072
|
}
|
|
1974
2073
|
|
|
1975
|
-
function renderedAnswerTarget(events, eventId, turnId) {
|
|
2074
|
+
function renderedAnswerTarget(events, eventId, turnId, type = 'assistant-message') {
|
|
2075
|
+
if (type === 'user-message') return events.find((event) => event.eventId === eventId && event.type === 'user-message') || null;
|
|
1976
2076
|
if (turnId) {
|
|
1977
2077
|
return [...events].reverse().find((event) => event.turnId === turnId && event.type === 'assistant-message') || null;
|
|
1978
2078
|
}
|
|
@@ -2029,13 +2129,18 @@
|
|
|
2029
2129
|
ui.feed.append(emptyFeedNotice());
|
|
2030
2130
|
} else {
|
|
2031
2131
|
let assistant = null;
|
|
2132
|
+
// The chat model's object links (#1653) are written while it answers. They wait until the turn's answer
|
|
2133
|
+
// has been shown and follow it, so an answer is never split by one or pushed below its own receipts.
|
|
2134
|
+
let links = [];
|
|
2032
2135
|
const flushAssistant = () => {
|
|
2033
2136
|
if (!assistant) return;
|
|
2034
2137
|
const rendered = renderedLiveAssistantText(assistant.event, assistant.text);
|
|
2035
2138
|
ui.feed.append(renderMessage(assistant.event, 'assistant', rendered.text, rendered.streaming));
|
|
2036
2139
|
assistant = null;
|
|
2037
2140
|
};
|
|
2141
|
+
const flushLinks = () => { if (links.length) { ui.feed.append(...links.map((link) => link.node)); links = []; } };
|
|
2038
2142
|
for (const event of state.events) {
|
|
2143
|
+
if (links.length && event.turnId !== links[0].turnId) { flushAssistant(); flushLinks(); }
|
|
2039
2144
|
if (event.type === 'assistant-message' && event.payload?.delta) {
|
|
2040
2145
|
// Codex keeps a stable item id while Claude's SDK may assign one per stream packet.
|
|
2041
2146
|
// Consecutive deltas in the same turn are one visible answer; a tool or other event
|
|
@@ -2052,11 +2157,13 @@
|
|
|
2052
2157
|
// Provider tools commonly split one answer into before/after chunks. They are not prose,
|
|
2053
2158
|
// so keep collecting same-turn deltas across them instead of rendering abandoned fragments.
|
|
2054
2159
|
if (['tool', 'usage', 'knowledge-citation', 'attachment', 'compaction', 'state'].includes(event.type)) continue;
|
|
2160
|
+
if (event.type === 'chat-subjects') { links.push({ turnId: event.turnId, node: renderEvent(event) }); continue; }
|
|
2055
2161
|
flushAssistant();
|
|
2056
2162
|
const node = renderEvent(event);
|
|
2057
2163
|
if (node) ui.feed.append(node);
|
|
2058
2164
|
}
|
|
2059
2165
|
flushAssistant();
|
|
2166
|
+
flushLinks();
|
|
2060
2167
|
// A provider can send text before it finishes tools, usage, or its terminal turn signal.
|
|
2061
2168
|
// Keep this fixed activity row visible for the full durable turn so an intermittent stream
|
|
2062
2169
|
// never looks like a failed response. Recovery deliberately has no live indicator.
|
|
@@ -2155,17 +2262,24 @@
|
|
|
2155
2262
|
shell.dataset.approvalPending = String(Boolean(approval) && !deciding);
|
|
2156
2263
|
document.dispatchEvent(new CustomEvent('floless:chat-indicator'));
|
|
2157
2264
|
if (!approval || deciding) { existing?.remove(); return; }
|
|
2158
|
-
// Keep the same buttons during polling so keyboard focus and pointer clicks survive.
|
|
2159
|
-
|
|
2265
|
+
// Keep the same buttons during polling so keyboard focus and pointer clicks survive. A Tekla card
|
|
2266
|
+
// also carries the permission view it offers "Allow for this chat" on, so a change repaints it.
|
|
2267
|
+
const teklaBinding = teklaAllowableApproval(approval) ? currentTeklaBinding(state.chat) : null;
|
|
2268
|
+
const allowanceRevision = teklaBinding ? String(teklaAllowanceRevision(teklaBinding)) : '';
|
|
2269
|
+
if (existing?.dataset.approvalId === approval.approvalId && (existing.dataset.allowanceRevision || '') === allowanceRevision) return;
|
|
2270
|
+
// A permission change repaints the same approval: keep keyboard focus on the same control.
|
|
2271
|
+
const refocus = existing?.dataset.approvalId === approval.approvalId && existing.contains(document.activeElement)
|
|
2272
|
+
? document.activeElement.dataset?.commandId : null;
|
|
2160
2273
|
existing?.remove();
|
|
2161
2274
|
const card = document.createElement('section'); card.className = 'ai-chat-approval';
|
|
2162
2275
|
card.dataset.approvalId = approval.approvalId;
|
|
2276
|
+
if (teklaBinding) card.dataset.allowanceRevision = allowanceRevision;
|
|
2163
2277
|
const heading = document.createElement('strong'); heading.textContent = 'Approval needed';
|
|
2164
2278
|
const copy = document.createElement('p'); copy.textContent = approval.summary;
|
|
2165
2279
|
const actions = document.createElement('div'); actions.className = 'ai-chat-approval-actions';
|
|
2166
2280
|
const deny = button('Deny', 'shell.chat-approval-deny');
|
|
2167
2281
|
const allow = button('Approve once', 'shell.chat-approval-allow', 'allow');
|
|
2168
|
-
// A Tekla
|
|
2282
|
+
// A Tekla read is never covered by a request-wide grant; it may instead be allowed for the whole chat (below).
|
|
2169
2283
|
const explicitOnly = approvalIsExplicitOnly(approval);
|
|
2170
2284
|
const allowRequest = explicitOnly ? null : button('Approve for this request', 'shell.chat-approval-request', 'allow');
|
|
2171
2285
|
const scope = document.createElement('span');
|
|
@@ -2174,16 +2288,29 @@
|
|
|
2174
2288
|
deny.addEventListener('click', () => decideApproval('deny'));
|
|
2175
2289
|
allow.addEventListener('click', () => decideApproval('allow'));
|
|
2176
2290
|
if (allowRequest) {
|
|
2177
|
-
scope.textContent = 'Approve access actions until this response finishes. Your permission setting stays unchanged. Review checkpoints and Tekla
|
|
2291
|
+
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
2292
|
allowRequest.dataset.tip = scope.textContent;
|
|
2179
2293
|
allowRequest.setAttribute('aria-describedby', scope.id);
|
|
2180
2294
|
allowRequest.addEventListener('click', () => decideApproval('allow-request'));
|
|
2181
2295
|
actions.append(deny, allow, allowRequest); card.append(heading, copy, actions, scope);
|
|
2296
|
+
} else if (teklaBinding) {
|
|
2297
|
+
// A Tekla read may instead be allowed for the whole chat, covering every read the chat is bound for.
|
|
2298
|
+
card.dataset.explicitOnly = 'true';
|
|
2299
|
+
const allowChat = button('Allow for this chat', 'shell.chat-tekla-allow-chat', 'allow');
|
|
2300
|
+
const help = document.createElement('span');
|
|
2301
|
+
help.className = 'sr-only';
|
|
2302
|
+
help.id = `chat-approval-tekla-scope-help-${approval.approvalId}`;
|
|
2303
|
+
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.`;
|
|
2304
|
+
allowChat.dataset.tip = help.textContent;
|
|
2305
|
+
allowChat.setAttribute('aria-describedby', help.id);
|
|
2306
|
+
allowChat.addEventListener('click', () => decideApproval('allow-chat', Number(allowanceRevision)));
|
|
2307
|
+
actions.append(deny, allow, allowChat); card.append(heading, copy, actions, help);
|
|
2182
2308
|
} else {
|
|
2183
2309
|
card.dataset.explicitOnly = 'true';
|
|
2184
2310
|
actions.append(deny, allow); card.append(heading, copy, actions);
|
|
2185
2311
|
}
|
|
2186
2312
|
ui.approvalTray.append(card);
|
|
2313
|
+
if (refocus) [...card.querySelectorAll('button')].find((node) => node.dataset.commandId === refocus)?.focus();
|
|
2187
2314
|
// When a request-wide grant notice is also present, keep the decision nearest the composer.
|
|
2188
2315
|
ui.approvalTray.scrollTop = ui.approvalTray.scrollHeight;
|
|
2189
2316
|
}
|
|
@@ -2217,7 +2344,7 @@
|
|
|
2217
2344
|
const explanation = document.createElement('span');
|
|
2218
2345
|
explanation.className = 'sr-only';
|
|
2219
2346
|
explanation.id = `chat-approval-scope-help-${turn.turnId}`;
|
|
2220
|
-
explanation.textContent = 'Your permission setting is unchanged. Review checkpoints and Tekla
|
|
2347
|
+
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
2348
|
const revoke = button('Revoke', 'shell.chat-approval-revoke');
|
|
2222
2349
|
revoke.dataset.tip = explanation.textContent;
|
|
2223
2350
|
revoke.setAttribute('aria-describedby', explanation.id);
|
|
@@ -2380,11 +2507,106 @@
|
|
|
2380
2507
|
}).catch(() => {});
|
|
2381
2508
|
}
|
|
2382
2509
|
|
|
2510
|
+
/**
|
|
2511
|
+
* What the paperclip says it takes, right now.
|
|
2512
|
+
*
|
|
2513
|
+
* SEPARATE FROM `paintAttachments` BECAUSE IT DEPENDS ON THE SURFACE, NOT ONLY ON THE
|
|
2514
|
+
* ATTACHMENTS. On the Drawing Filter the answer is written by a headless AI that can only look at
|
|
2515
|
+
* pictures, so a PDF is refused — and that has to be on the control BEFORE the message is typed,
|
|
2516
|
+
* not at Send. `paintAttachments` runs when the attachments change; opening the Drawing Filter
|
|
2517
|
+
* changes neither, so a tooltip painted only there keeps the previous surface's wording. Measured
|
|
2518
|
+
* in the browser: the filter reported ready on S-203 while the paperclip still offered PDFs.
|
|
2519
|
+
* `updateSendState` runs on every repaint, including the surface switch, so both call this.
|
|
2520
|
+
*/
|
|
2521
|
+
function paintAttachControl() {
|
|
2522
|
+
const imageCount = state.attachments.filter((attachment) => attachment.mediaType.startsWith('image/')).length;
|
|
2523
|
+
const kinds = filterSurface().state === 'off' ? 'image or PDF' : 'a picture';
|
|
2524
|
+
ui.attach.dataset.tip = `Attach ${kinds} · ${imageCount} of ${MAX_IMAGES_PER_MESSAGE} images in this message`;
|
|
2525
|
+
ui.attach.setAttribute('aria-label', `Attach ${kinds} · ${imageCount} of ${MAX_IMAGES_PER_MESSAGE} images`);
|
|
2526
|
+
}
|
|
2527
|
+
|
|
2528
|
+
/* #1653: the Steel Model objects selected when a question is sent are attached to it. The pill shows what
|
|
2529
|
+
would go with the next NEW question — never with a follow-up to a running response, never on the Drawing
|
|
2530
|
+
Filter, never in a workflow's conversation — and one click leaves them out until the selection changes. */
|
|
2531
|
+
const MAX_LISTED_SUBJECTS = 200;
|
|
2532
|
+
const MAX_SUBJECT_SAMPLE = 50;
|
|
2533
|
+
|
|
2534
|
+
function subjectsKey(selection) {
|
|
2535
|
+
return selection ? `${selection.source}|${selection.key || selection.items.map((item) => `${item.kind}:${item.id}`).sort().join('\n')}` : '';
|
|
2536
|
+
}
|
|
2537
|
+
|
|
2538
|
+
function composerSelection() {
|
|
2539
|
+
if (!state.chat || state.scope?.owner?.kind !== 'project' || turnIsVisiblyActive()) return null;
|
|
2540
|
+
if (filterSurface().state !== 'off') return null;
|
|
2541
|
+
let selection = null;
|
|
2542
|
+
try { selection = window.flolessLeftPane?.readSelection?.() || null; } catch { selection = null; }
|
|
2543
|
+
if (!selection || selection.source !== 'steel' || !selection.items?.length) return null;
|
|
2544
|
+
if (state.subjectsDismissed && state.subjectsDismissed === subjectsKey(selection)) return null;
|
|
2545
|
+
return selection;
|
|
2546
|
+
}
|
|
2547
|
+
|
|
2548
|
+
/** The selection as the server stores it: up to 200 objects one by one, more as a counted sample. */
|
|
2549
|
+
function subjectsPayload(selection) {
|
|
2550
|
+
if (!selection) return null;
|
|
2551
|
+
const pick = (item) => ({ kind: item.kind, id: item.id, label: item.label });
|
|
2552
|
+
if (selection.total > MAX_LISTED_SUBJECTS) {
|
|
2553
|
+
return { source: selection.source, revision: selection.revision, group: { count: selection.total, sample: selection.items.slice(0, MAX_SUBJECT_SAMPLE).map(pick) } };
|
|
2554
|
+
}
|
|
2555
|
+
return { source: selection.source, revision: selection.revision, items: selection.items.slice(0, MAX_LISTED_SUBJECTS).map(pick) };
|
|
2556
|
+
}
|
|
2557
|
+
|
|
2558
|
+
function subjectLabels(items, total, shown = 3) {
|
|
2559
|
+
const names = items.slice(0, shown).map((item) => item.label || item.id);
|
|
2560
|
+
const more = total - names.length;
|
|
2561
|
+
return more > 0 ? `${names.join(', ')} and ${more} more` : names.join(', ');
|
|
2562
|
+
}
|
|
2563
|
+
|
|
2564
|
+
/** The line under a sent question naming what it was about, or '' — for a listed selection or a counted group. */
|
|
2565
|
+
function subjectsLine(subjects) {
|
|
2566
|
+
if (!subjects || typeof subjects !== 'object') return '';
|
|
2567
|
+
const listed = Array.isArray(subjects.items) ? subjects.items : Array.isArray(subjects.group?.sample) ? subjects.group.sample : [];
|
|
2568
|
+
const count = Array.isArray(subjects.items) ? subjects.items.length : Number(subjects.group?.count) || listed.length;
|
|
2569
|
+
if (!count) return '';
|
|
2570
|
+
return `About ${count} Steel object${count === 1 ? '' : 's'}${listed.length ? `: ${subjectLabels(listed, count)}` : ''}`;
|
|
2571
|
+
}
|
|
2572
|
+
|
|
2573
|
+
// A question was saved with objects: the model editor's object card reads its links again.
|
|
2574
|
+
function subjectLinksSaved(subjects) {
|
|
2575
|
+
if (!subjects) return;
|
|
2576
|
+
try { window.flolessLeftPane?.chatLinksChanged?.(); } catch { /* the card refreshes on its next read */ }
|
|
2577
|
+
}
|
|
2578
|
+
|
|
2579
|
+
function paintSubjectsPill() {
|
|
2580
|
+
const selection = composerSelection();
|
|
2581
|
+
if (!selection) return false;
|
|
2582
|
+
const count = selection.total;
|
|
2583
|
+
const chip = document.createElement('span'); chip.className = 'ai-chat-attachment ai-chat-subjects';
|
|
2584
|
+
const label = button(`${count} object${count === 1 ? '' : 's'} selected`, 'shell.chat-subjects', 'ai-chat-subjects-label');
|
|
2585
|
+
label.dataset.tip = count > MAX_LISTED_SUBJECTS
|
|
2586
|
+
? `More than ${MAX_LISTED_SUBJECTS} objects are selected, so FloLess attaches them to your next question as one set instead of listing each one.`
|
|
2587
|
+
: `${subjectLabels(selection.items, count, 5)}. Attached to your next question.`;
|
|
2588
|
+
label.setAttribute('aria-label', `${count} Steel Model object${count === 1 ? '' : 's'} selected, attached to your next question`);
|
|
2589
|
+
label.addEventListener('click', () => { announce(label.dataset.tip); });
|
|
2590
|
+
const remove = button('×', 'shell.chat-subjects-remove');
|
|
2591
|
+
remove.setAttribute('aria-label', 'Leave the selected objects out of your next question');
|
|
2592
|
+
remove.dataset.tip = 'Leave out of the next question';
|
|
2593
|
+
remove.addEventListener('click', () => {
|
|
2594
|
+
state.subjectsDismissed = subjectsKey(selection);
|
|
2595
|
+
paintAttachments();
|
|
2596
|
+
ui.input.focus();
|
|
2597
|
+
announce('The selected objects will not be attached to your next question.');
|
|
2598
|
+
});
|
|
2599
|
+
chip.append(label, remove);
|
|
2600
|
+
ui.attachments.append(chip);
|
|
2601
|
+
return true;
|
|
2602
|
+
}
|
|
2603
|
+
|
|
2383
2604
|
function paintAttachments() {
|
|
2384
2605
|
ui.attachments.replaceChildren();
|
|
2385
|
-
const
|
|
2386
|
-
|
|
2387
|
-
|
|
2606
|
+
const pill = paintSubjectsPill();
|
|
2607
|
+
// paintAttachControl, not the two lines #1653 had here: it says the same thing but asks the
|
|
2608
|
+
// SURFACE what may be attached, so the Drawing Filter reads “Attach a picture” (#1681).
|
|
2609
|
+
paintAttachControl();
|
|
2388
2610
|
for (const attachment of state.attachments) {
|
|
2389
2611
|
const chip = document.createElement('span'); chip.className = 'ai-chat-attachment';
|
|
2390
2612
|
if (attachment.mediaType.startsWith('image/')) {
|
|
@@ -2410,7 +2632,7 @@
|
|
|
2410
2632
|
});
|
|
2411
2633
|
chip.append(name, remove); ui.attachments.append(chip);
|
|
2412
2634
|
}
|
|
2413
|
-
ui.attachments.hidden = state.attachments.length === 0;
|
|
2635
|
+
ui.attachments.hidden = state.attachments.length === 0 && !pill;
|
|
2414
2636
|
}
|
|
2415
2637
|
|
|
2416
2638
|
function selectedModel() {
|
|
@@ -2743,6 +2965,8 @@
|
|
|
2743
2965
|
}
|
|
2744
2966
|
if (state.events.some((item) => item.eventId === event.eventId)) return;
|
|
2745
2967
|
state.events.push(event);
|
|
2968
|
+
// The chat model linked objects during this answer: an open Steel card reads its links again (#1653).
|
|
2969
|
+
if (event.type === 'chat-subjects') subjectLinksSaved(event.payload);
|
|
2746
2970
|
state.events.sort((a, b) => a.sequence - b.sequence);
|
|
2747
2971
|
state.chat.lastEventSequence = Math.max(state.chat.lastEventSequence || 0, event.sequence || 0);
|
|
2748
2972
|
const listChat = state.chats.find((item) => item.chatId === chatId);
|
|
@@ -2906,7 +3130,9 @@
|
|
|
2906
3130
|
if (!options.preserveDiscoveryDraft) { state.discoveryDraft = null; state.pendingTeklaLibrary = null; }
|
|
2907
3131
|
clearProviderChoice();
|
|
2908
3132
|
const selection = ++state.selectionGeneration;
|
|
2909
|
-
|
|
3133
|
+
// An Instructor answer, or a question an object card links to (#1653): both open at that one message.
|
|
3134
|
+
const exactQuestion = typeof options.messageEventId === 'string' ? options.messageEventId : null;
|
|
3135
|
+
const exactAnswer = exactQuestion || (typeof options.answerEventId === 'string' ? options.answerEventId : null);
|
|
2910
3136
|
clearAnswerJump();
|
|
2911
3137
|
if (!exactAnswer) {
|
|
2912
3138
|
closeSource(); closePicker();
|
|
@@ -2930,10 +3156,14 @@
|
|
|
2930
3156
|
if (generation !== state.scopeGeneration || selection !== state.selectionGeneration) return;
|
|
2931
3157
|
const answerTarget = exactAnswer
|
|
2932
3158
|
? renderedAnswerTarget(snapshot.events || [], exactAnswer,
|
|
2933
|
-
typeof options.answerTurnId === 'string' ? options.answerTurnId : null
|
|
3159
|
+
exactQuestion ? null : typeof options.answerTurnId === 'string' ? options.answerTurnId : null,
|
|
3160
|
+
exactQuestion ? 'user-message' : 'assistant-message')
|
|
2934
3161
|
: null;
|
|
2935
3162
|
if (exactAnswer && !answerTarget) {
|
|
2936
|
-
|
|
3163
|
+
const gone = exactQuestion ? 'That question is no longer in this conversation.' : 'That Instructor answer is no longer available.';
|
|
3164
|
+
announce(gone);
|
|
3165
|
+
// A question is opened from an object card in the model panel, away from the chat's own status line.
|
|
3166
|
+
if (exactQuestion) window.showToast?.(gone, 'info');
|
|
2937
3167
|
return;
|
|
2938
3168
|
}
|
|
2939
3169
|
const [capability, desktop] = await Promise.all([readCapability(chat), readDesktopCapability(chat)]);
|
|
@@ -2970,7 +3200,7 @@
|
|
|
2970
3200
|
}).catch(() => { /* a missed warm-up only means a slower first message */ });
|
|
2971
3201
|
if (answerTarget) {
|
|
2972
3202
|
markReadThrough(chat, answerTarget.sequence);
|
|
2973
|
-
announce(`Opened Instructor answer in ${state.chat.title}.`);
|
|
3203
|
+
announce(exactQuestion ? `Opened your question in ${state.chat.title}.` : `Opened Instructor answer in ${state.chat.title}.`);
|
|
2974
3204
|
} else {
|
|
2975
3205
|
markRead();
|
|
2976
3206
|
// Only move focus when nothing has taken it since the selection began: the history was not
|
|
@@ -3046,9 +3276,14 @@
|
|
|
3046
3276
|
clearLiveStream(true);
|
|
3047
3277
|
closeSource(); closePicker();
|
|
3048
3278
|
clearProviderChoice();
|
|
3279
|
+
const scopeChanged = scopeKey(scope) !== scopeKey(state.scope);
|
|
3280
|
+
// The new project's history may take time to load. Its old project's refusal is already false.
|
|
3281
|
+
if (scopeChanged) retireReportAnnouncement();
|
|
3049
3282
|
state.scope = scope;
|
|
3050
3283
|
state.scopeInitialized = true;
|
|
3284
|
+
if (scopeChanged) { try { window.flolessLeftPane?.chatLinksChanged?.(); } catch { /* the card refreshes on its next read */ } }
|
|
3051
3285
|
state.chat = null; state.chats = []; state.archivedChats = []; state.unreadableChats = []; state.events = []; state.capability = null; state.desktop = null; state.attachments = []; state.integrations = null;
|
|
3286
|
+
if (scopeChanged) clearReport();
|
|
3052
3287
|
// A published filter answer still lands in its own project's conversation; reopening it resumes.
|
|
3053
3288
|
for (const entry of state.filterPending.values()) clearTimeout(entry.timer);
|
|
3054
3289
|
state.filterPending.clear(); state.filterNotices.clear(); state.filterCardMessages.clear();
|
|
@@ -3389,12 +3624,19 @@
|
|
|
3389
3624
|
const settingUp = Boolean(state.capability?.runtime && state.capability.runtime.state !== 'installed');
|
|
3390
3625
|
const uploading = Boolean(state.chat?.chatId && state.uploadingChatIds.has(state.chat.chatId));
|
|
3391
3626
|
ui.input.disabled = state.followupSubmitting || !state.chat || Boolean(state.chat?.archivedAt) || recovery || blocked;
|
|
3392
|
-
const filterMode = paintFilterComposer().state !== 'off';
|
|
3393
3627
|
ui.send.disabled = state.loading || state.followupSubmitting || state.filterSending || Boolean(state.followupUnknownId) || hasUnknownFollowup() || uploading || !state.chat || blocked || frozen
|
|
3394
3628
|
|| (!ui.input.value.trim() && state.attachments.length === 0) || settingUp;
|
|
3395
|
-
// Drawing Filter
|
|
3396
|
-
|
|
3397
|
-
|
|
3629
|
+
// A Drawing Filter message carries the filter's own context AND whatever pictures the person
|
|
3630
|
+
// attached (#1681). The paperclip used to be disabled here, which is the "I can't add
|
|
3631
|
+
// attachments" in that issue; the only attachment rule left is the one in `filterSendRefusal`,
|
|
3632
|
+
// and it is about the file type, not about the surface.
|
|
3633
|
+
// `state.filterSending` belongs here BECAUSE the shared tooltip below already stamps "wait for it
|
|
3634
|
+
// to appear" on this control: without it the paperclip says blocked and stays clickable, and a
|
|
3635
|
+
// picture attached mid-send is not in the set `sendFilterAi` puts back if the send fails.
|
|
3636
|
+
ui.attach.disabled = state.loading || state.followupSubmitting || state.filterSending || Boolean(state.followupUnknownId) || hasUnknownFollowup() || uploading || !state.chat || blocked || frozen;
|
|
3637
|
+
// Repainted here too: this runs on a surface switch, which changes what may be attached without
|
|
3638
|
+
// changing the attachments themselves.
|
|
3639
|
+
paintAttachControl();
|
|
3398
3640
|
const unknownReason = state.followupUnknownId || hasUnknownFollowup()
|
|
3399
3641
|
? 'FloLess could not confirm a follow-up. Review that message before sending or attaching another file.' : null;
|
|
3400
3642
|
const sendingReason = state.followupSubmitting
|
|
@@ -3404,7 +3646,6 @@
|
|
|
3404
3646
|
if (unknownReason || sendingReason) control.dataset.blockedReason = unknownReason || sendingReason;
|
|
3405
3647
|
else delete control.dataset.blockedReason;
|
|
3406
3648
|
}
|
|
3407
|
-
if (filterMode && !unknownReason && !sendingReason) ui.attach.dataset.blockedReason = 'Drawing Filter messages do not include attachments. Attach files from another tab.';
|
|
3408
3649
|
ui.stop.hidden = !active || Boolean(state.chat?.activeTurn?.local);
|
|
3409
3650
|
ui.send.hidden = false;
|
|
3410
3651
|
// Session recovery must remain available even while provider capability discovery is loading
|
|
@@ -3636,15 +3877,42 @@
|
|
|
3636
3877
|
return state.events.some((event) => event.type === 'assistant-message' && event.payload?.requestId === requestId);
|
|
3637
3878
|
}
|
|
3638
3879
|
|
|
3880
|
+
/**
|
|
3881
|
+
* The only length limit on a Drawing Filter message, and the same number the server enforces
|
|
3882
|
+
* (`MAX_SUBJECT_CHARS` in `server/instructor-request.ts`).
|
|
3883
|
+
*
|
|
3884
|
+
* It was 300 — short enough that an ordinary question naming two layers was refused, which is the
|
|
3885
|
+
* complaint #1681 opens with. It is deliberately still A limit: the message becomes the request's
|
|
3886
|
+
* subject, and an unbounded field there is its own failure.
|
|
3887
|
+
*/
|
|
3888
|
+
const FILTER_MESSAGE_LIMIT = 4000;
|
|
3889
|
+
|
|
3639
3890
|
/** Why a filter message cannot be sent right now, or null. Checked before the draft is touched. */
|
|
3640
3891
|
function filterSendRefusal(surface, text) {
|
|
3641
3892
|
const chat = state.chat;
|
|
3642
3893
|
if (surface.state !== 'ready') return 'The Drawing Filter is still loading. Wait until its layers appear, then send again. Nothing was sent.';
|
|
3643
3894
|
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
3895
|
if (filterPendingIn(chat.chatId)) return 'Wait for the current Drawing Filter answer before sending another. Your message was not sent.';
|
|
3645
|
-
|
|
3896
|
+
// Pictures ride along (#1681). A PDF cannot: the AI answering a Drawing Filter message looks at
|
|
3897
|
+
// images handed to it on the command line and has no file access of its own, so a PDF here would
|
|
3898
|
+
// be stored and never opened. Say that plainly rather than accept it and answer around it.
|
|
3899
|
+
const nonImage = state.attachments.find((item) => !String(item.mediaType || '').startsWith('image/'));
|
|
3900
|
+
if (nonImage) {
|
|
3901
|
+
return `“${nonImage.fileName}” can’t be sent with a Drawing Filter message — the AI answering here can only look at pictures. `
|
|
3902
|
+
+ 'Attach a screenshot of the page you mean, or ask about it in the main conversation instead. Nothing was sent.';
|
|
3903
|
+
}
|
|
3904
|
+
// A PICTURE ONLY REACHES CODEX. It travels on the command line of the headless run, and a
|
|
3905
|
+
// read-only Claude run has no tool that could open one and a relay that returns text only — so
|
|
3906
|
+
// on a Claude conversation the answer would be written having seen nothing. The run route
|
|
3907
|
+
// refuses this too, but by then a request exists and has to be unwound; the independent QA saw
|
|
3908
|
+
// exactly that, with a queued request and an "attachment ready" composer. Refuse here, before
|
|
3909
|
+
// anything is created.
|
|
3910
|
+
if (state.attachments.length && chat.provider !== 'codex') {
|
|
3911
|
+
return `${providerLabels[chat.provider] || 'This AI'} can’t be shown a picture in a Drawing Filter message. `
|
|
3912
|
+
+ 'Remove the picture to send the question on its own, or ask in a conversation with the other AI. Nothing was sent.';
|
|
3913
|
+
}
|
|
3646
3914
|
// Counted exactly as the filter page counts it, so the two limits can never disagree.
|
|
3647
|
-
if (text.length >
|
|
3915
|
+
if (text.length > FILTER_MESSAGE_LIMIT) return `Shorten your message to ${FILTER_MESSAGE_LIMIT} characters, then send it again. Nothing was sent.`;
|
|
3648
3916
|
return null;
|
|
3649
3917
|
}
|
|
3650
3918
|
|
|
@@ -3883,6 +4151,77 @@
|
|
|
3883
4151
|
return { installed: false, sentence };
|
|
3884
4152
|
}
|
|
3885
4153
|
|
|
4154
|
+
/**
|
|
4155
|
+
* Read the pictures on the composer into the data URLs `/api/guide` stores beside the request.
|
|
4156
|
+
*
|
|
4157
|
+
* A COPY, ON PURPOSE. The headless run gets its own leased file under the requests directory —
|
|
4158
|
+
* it never reaches into the conversation's attachment store — so the picture the AI was shown
|
|
4159
|
+
* stays exactly the picture that was attached, whatever happens to the chat afterwards.
|
|
4160
|
+
*
|
|
4161
|
+
* Throws a refusal on the first unreadable one rather than sending a shorter list: a message that
|
|
4162
|
+
* quietly carries two of three pictures is answered as if the third never existed.
|
|
4163
|
+
*/
|
|
4164
|
+
async function filterAiPictures(attachments, chatId, owner) {
|
|
4165
|
+
const pictures = [];
|
|
4166
|
+
for (const attachment of attachments) {
|
|
4167
|
+
let dataUrl;
|
|
4168
|
+
try {
|
|
4169
|
+
const response = await fetch(
|
|
4170
|
+
`/api/chat/conversations/${encodeURIComponent(chatId)}/attachments/${encodeURIComponent(attachment.attachmentId)}?${ownerQuery(owner)}`,
|
|
4171
|
+
{ signal: AbortSignal.timeout(20000) });
|
|
4172
|
+
if (!response.ok) throw new Error(`attachment read failed (${response.status})`);
|
|
4173
|
+
const blob = await response.blob();
|
|
4174
|
+
dataUrl = await new Promise((resolve, reject) => {
|
|
4175
|
+
const reader = new FileReader();
|
|
4176
|
+
reader.onerror = () => reject(reader.error || new Error('attachment could not be read'));
|
|
4177
|
+
reader.onload = () => resolve(String(reader.result || ''));
|
|
4178
|
+
reader.readAsDataURL(blob);
|
|
4179
|
+
});
|
|
4180
|
+
} catch (error) {
|
|
4181
|
+
console.error('[chat] a Drawing Filter attachment could not be read:', error);
|
|
4182
|
+
throw filterRefusal(`FloLess could not read “${attachment.fileName}”, so nothing was sent. Attach it again, then send the message.`);
|
|
4183
|
+
}
|
|
4184
|
+
pictures.push({ name: attachment.fileName, dataUrl, role: 'reference' });
|
|
4185
|
+
}
|
|
4186
|
+
return pictures;
|
|
4187
|
+
}
|
|
4188
|
+
|
|
4189
|
+
/**
|
|
4190
|
+
* Drop the composer rows whose bytes are now copied onto the request.
|
|
4191
|
+
*
|
|
4192
|
+
* Local state alone is not enough: reopening the conversation repaints the composer from the
|
|
4193
|
+
* chat's own pending attachments, so a row left behind would come back and be sent twice.
|
|
4194
|
+
*/
|
|
4195
|
+
async function discardSentFilterAttachments(attachments, chatId, owner) {
|
|
4196
|
+
const cleared = new Set();
|
|
4197
|
+
const stranded = [];
|
|
4198
|
+
for (const attachment of attachments) {
|
|
4199
|
+
try {
|
|
4200
|
+
await request(`/api/chat/conversations/${encodeURIComponent(chatId)}/attachments/${encodeURIComponent(attachment.attachmentId)}`, {
|
|
4201
|
+
method: 'DELETE', timeoutMs: 10000, body: JSON.stringify({ owner }),
|
|
4202
|
+
});
|
|
4203
|
+
cleared.add(attachment.attachmentId);
|
|
4204
|
+
} catch (error) {
|
|
4205
|
+
console.warn('[chat] a sent Drawing Filter attachment was not cleared:', error);
|
|
4206
|
+
stranded.push(attachment.fileName);
|
|
4207
|
+
}
|
|
4208
|
+
}
|
|
4209
|
+
// BOTH LISTS, as the chip's own remove handler does. `state.chat.attachments` is what the
|
|
4210
|
+
// conversation-wide budget counts (ten files, fifty megabytes), so pruning only the composer
|
|
4211
|
+
// would spend that budget on pictures that no longer exist and refuse the next real one.
|
|
4212
|
+
if (state.chat?.chatId === chatId) {
|
|
4213
|
+
state.chat.attachments = (state.chat.attachments || []).filter((item) => !cleared.has(item.attachmentId));
|
|
4214
|
+
}
|
|
4215
|
+
// A row that would not delete is still on the server, and the composer is repainted from the
|
|
4216
|
+
// server on the next refresh — so it comes back and rides the person's NEXT, unrelated message.
|
|
4217
|
+
// They are the only one who can clear it, so say so rather than leaving it in the console.
|
|
4218
|
+
if (stranded.length) {
|
|
4219
|
+
report(filterRefusal(`Your message was sent, but ${stranded.map((name) => `“${name}”`).join(' and ')} `
|
|
4220
|
+
+ `${stranded.length > 1 ? 'are' : 'is'} still attached to this conversation. Remove `
|
|
4221
|
+
+ `${stranded.length > 1 ? 'them' : 'it'} from the box below so ${stranded.length > 1 ? 'they do' : 'it does'} not go with your next message.`));
|
|
4222
|
+
}
|
|
4223
|
+
}
|
|
4224
|
+
|
|
3886
4225
|
async function sendFilterAi(surface) {
|
|
3887
4226
|
const snapshot = captureChat();
|
|
3888
4227
|
if (!snapshot || state.filterSending) return;
|
|
@@ -3900,7 +4239,14 @@
|
|
|
3900
4239
|
clearTimeout(state.draftTimer);
|
|
3901
4240
|
state.localDraft = { chatId: snapshot.chatId, text: '' };
|
|
3902
4241
|
state.backgroundDrafts.delete(snapshot.chatId);
|
|
4242
|
+
// Captured before the composer is cleared, and put back by the catch below if nothing was sent —
|
|
4243
|
+
// the same contract the words get.
|
|
4244
|
+
const attached = state.attachments.slice();
|
|
4245
|
+
// Set the moment the rows are handed to the server for deletion, so the catch below never offers
|
|
4246
|
+
// back a chip whose record is gone — its preview would 404 and every later send would refuse.
|
|
4247
|
+
let discarded = false;
|
|
3903
4248
|
ui.input.value = ''; autosize();
|
|
4249
|
+
state.attachments = []; paintAttachments();
|
|
3904
4250
|
state.filterSending = true; updateSendState();
|
|
3905
4251
|
let requestId = null;
|
|
3906
4252
|
let failure = null;
|
|
@@ -3928,9 +4274,14 @@
|
|
|
3928
4274
|
}
|
|
3929
4275
|
// The promise belongs to the filter page. A page thrown away mid-request never settles it, so
|
|
3930
4276
|
// the chat keeps its own deadline rather than leaving Send blocked in every conversation.
|
|
4277
|
+
const pictures = attached.length ? await filterAiPictures(attached, snapshot.chatId, snapshot.scope.owner) : [];
|
|
3931
4278
|
const created = await Promise.race([
|
|
3932
|
-
surface.bridge.createRequest(kind, text),
|
|
3933
|
-
|
|
4279
|
+
surface.bridge.createRequest(kind, text, pictures),
|
|
4280
|
+
// ONE DEADLINE, and it must not be shorter than the filter page's own: that page waits 60s
|
|
4281
|
+
// when pictures ride in the body (they are megabytes, not a few hundred bytes of narration).
|
|
4282
|
+
// Racing it at 20s declared failure while the request was still being written, leaving a real
|
|
4283
|
+
// request in Requests while the composer invited a retry that would duplicate it.
|
|
4284
|
+
new Promise((resolve) => { setTimeout(resolve, pictures.length ? 60000 : 20000, { ok: false, message: FILTER_CREATE_TIMEOUT }); }),
|
|
3934
4285
|
]);
|
|
3935
4286
|
if (!created?.ok) {
|
|
3936
4287
|
throw filterRefusal([401, 402, 403].includes(created?.status)
|
|
@@ -3988,6 +4339,7 @@
|
|
|
3988
4339
|
void writeChatDraft(snapshot.chatId, snapshot.scope.owner, draft)
|
|
3989
4340
|
.catch((error) => { if (sameChat(snapshot)) report(error, 'Draft was not saved'); });
|
|
3990
4341
|
}
|
|
4342
|
+
// The bytes are on the request now, so the composer rows have done their job.
|
|
3991
4343
|
const entry = { requestId, chatId: snapshot.chatId, kind, appId: created.request.appId || '', project: created.request.project || '', failures: 0, note: '' };
|
|
3992
4344
|
state.filterPending.set(requestId, entry);
|
|
3993
4345
|
state.filterNotices.delete(requestId);
|
|
@@ -4012,12 +4364,27 @@
|
|
|
4012
4364
|
}
|
|
4013
4365
|
return;
|
|
4014
4366
|
}
|
|
4367
|
+
// The bytes are on the request AND the run is under way, so the composer rows have done their
|
|
4368
|
+
// job. Deliberately after `startFilterRun`: a refusal above gives the pictures back with the
|
|
4369
|
+
// words, which it could not do once these rows are gone.
|
|
4370
|
+
if (attached.length) { discarded = true; await discardSentFilterAttachments(attached, snapshot.chatId, snapshot.scope.owner); }
|
|
4015
4371
|
if (started === 'unconfirmed') entry.note = 'Checking whether AI started…';
|
|
4016
4372
|
announce(FILTER_PENDING);
|
|
4017
4373
|
if (sameChat(snapshot)) paintEvents({ forceBottom: true });
|
|
4018
4374
|
scheduleFilterPoll(entry, 0);
|
|
4019
4375
|
} catch (error) {
|
|
4020
4376
|
failure = error;
|
|
4377
|
+
// Nothing was sent, so the pictures go back to the composer with the words — but ONLY while
|
|
4378
|
+
// their server records still exist. Several awaits run after the discard (the run start, the
|
|
4379
|
+
// event merge, a refusal's own restore), and a throw in any of them lands here; handing back
|
|
4380
|
+
// deleted rows would render chips whose previews 404 and make every later send refuse.
|
|
4381
|
+
// MERGED, not assigned: a second tab's row can reach this state, and overwriting would make it
|
|
4382
|
+
// disappear from the composer with nothing said.
|
|
4383
|
+
if (attached.length && !discarded && sameChat(snapshot)) {
|
|
4384
|
+
const returning = new Set(attached.map((item) => item.attachmentId));
|
|
4385
|
+
state.attachments = [...attached, ...state.attachments.filter((item) => !returning.has(item.attachmentId))];
|
|
4386
|
+
paintAttachments();
|
|
4387
|
+
}
|
|
4021
4388
|
await restoreBackgroundDraft(snapshot, text, submissionId);
|
|
4022
4389
|
} finally {
|
|
4023
4390
|
state.filterSending = false;
|
|
@@ -4212,6 +4579,10 @@
|
|
|
4212
4579
|
// normal turn, not even while the filter page is still loading.
|
|
4213
4580
|
const filter = filterSurface();
|
|
4214
4581
|
if (filter.state !== 'off') { await sendFilterAi(filter); return; }
|
|
4582
|
+
// Decided once, at the click, from what the pill showed: a follow-up that falls back to a new turn below
|
|
4583
|
+
// must not attach objects the person was never shown (#1653).
|
|
4584
|
+
const subjects = subjectsPayload(composerSelection());
|
|
4585
|
+
const subjectsField = subjects ? { subjects } : {};
|
|
4215
4586
|
if (turnIsVisiblyActive() && !state.chat.activeTurn?.local) {
|
|
4216
4587
|
const followup = await sendFollowup();
|
|
4217
4588
|
if (followup?.outcome !== 'turn-ended') return;
|
|
@@ -4234,7 +4605,7 @@
|
|
|
4234
4605
|
const optimisticEvent = {
|
|
4235
4606
|
eventId: `local:${clientSubmissionId}`, sequence: Math.max(0, ...state.events.map((event) => Number(event.sequence) || 0)) + .5,
|
|
4236
4607
|
chatId, turnId: clientSubmissionId, clientSubmissionId, providerItemId: null, type: 'user-message',
|
|
4237
|
-
payload: { text, attachmentIds }, createdAt: new Date().toISOString(), optimistic: true,
|
|
4608
|
+
payload: { text, attachmentIds, ...subjectsField }, createdAt: new Date().toISOString(), optimistic: true,
|
|
4238
4609
|
};
|
|
4239
4610
|
clearTimeout(state.draftTimer);
|
|
4240
4611
|
state.localDraft = { chatId, text: '' };
|
|
@@ -4253,10 +4624,11 @@
|
|
|
4253
4624
|
// The server alone appends this context to the provider copy. The submitted text and
|
|
4254
4625
|
// durable transcript must remain exactly what the user typed.
|
|
4255
4626
|
owner: snapshot.scope.owner, clientSubmissionId, text, displayText: text, uiContext, attachmentIds,
|
|
4256
|
-
modifying: previousChat.settings.permissionProfile !== 'read-only',
|
|
4627
|
+
modifying: previousChat.settings.permissionProfile !== 'read-only', ...subjectsField,
|
|
4257
4628
|
}),
|
|
4258
4629
|
});
|
|
4259
|
-
if (!sameChat(snapshot)) return;
|
|
4630
|
+
if (!sameChat(snapshot)) return void subjectLinksSaved(subjects);
|
|
4631
|
+
subjectLinksSaved(subjects);
|
|
4260
4632
|
state.pendingSubmissionId = null;
|
|
4261
4633
|
state.events = state.events.filter((event) => event.eventId !== optimisticEvent.eventId);
|
|
4262
4634
|
state.chat = result.chat;
|
|
@@ -4638,7 +5010,7 @@
|
|
|
4638
5010
|
}
|
|
4639
5011
|
}
|
|
4640
5012
|
|
|
4641
|
-
async function decideApproval(decision) {
|
|
5013
|
+
async function decideApproval(decision, allowanceRevision) {
|
|
4642
5014
|
const approval = state.chat?.pendingApproval;
|
|
4643
5015
|
if (!approval) return;
|
|
4644
5016
|
const snapshot = captureChat();
|
|
@@ -4653,11 +5025,13 @@
|
|
|
4653
5025
|
announce('Applying your choice…');
|
|
4654
5026
|
try {
|
|
4655
5027
|
await request(`/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/approvals/${encodeURIComponent(approvalId)}`, {
|
|
4656
|
-
method: 'POST', body: JSON.stringify({ owner: snapshot.scope.owner, decision
|
|
5028
|
+
method: 'POST', body: JSON.stringify({ owner: snapshot.scope.owner, decision,
|
|
5029
|
+
...(decision === 'allow-chat' ? { allowanceRevision } : {}) }),
|
|
4657
5030
|
});
|
|
4658
5031
|
if (!sameChat(snapshot)) return;
|
|
4659
5032
|
announce(decision === 'allow-request' ? 'Access auto-approval is on for this request.'
|
|
4660
|
-
: decision === 'allow' ? '
|
|
5033
|
+
: decision === 'allow-chat' ? 'Tekla reads are allowed for this chat. Revoke them from the Tekla box above the message.'
|
|
5034
|
+
: decision === 'allow' ? 'Approved once.' : 'Action denied.');
|
|
4661
5035
|
await refreshConversation(snapshot.chatId, false);
|
|
4662
5036
|
} catch (error) {
|
|
4663
5037
|
if (!sameChat(snapshot)) return;
|
|
@@ -4701,6 +5075,28 @@
|
|
|
4701
5075
|
});
|
|
4702
5076
|
}
|
|
4703
5077
|
|
|
5078
|
+
/**
|
|
5079
|
+
* Why these files cannot be attached on the surface the person is on, or null.
|
|
5080
|
+
*
|
|
5081
|
+
* REFUSED AT THE CHOOSER, not at Send. The AI answering a Drawing Filter message is handed
|
|
5082
|
+
* pictures on a command line and has no way to open a document, so a PDF attached there could
|
|
5083
|
+
* only be uploaded, counted against the conversation's budget, and then refused after the whole
|
|
5084
|
+
* message had been written around it. `paintAttachControl` already says "Attach a picture" on that
|
|
5085
|
+
* surface; this is the half that makes the control's word good.
|
|
5086
|
+
*
|
|
5087
|
+
* A NAMED FUNCTION rather than an inline block, because `attachFiles` is held to a guard that
|
|
5088
|
+
* requires its `captureChat()` and `sameChat(snapshot)` to stay within reach of each other — the
|
|
5089
|
+
* ownership pattern every in-flight action follows. Inlining this pushed them apart and turned
|
|
5090
|
+
* that guard red, which is the guard doing its job.
|
|
5091
|
+
*/
|
|
5092
|
+
function filterAttachRefusal(incoming) {
|
|
5093
|
+
if (filterSurface().state === 'off') return null;
|
|
5094
|
+
const document = incoming.find((file) => !String(file.type || '').startsWith('image/'));
|
|
5095
|
+
if (!document) return null;
|
|
5096
|
+
return `“${document.name}” can’t be sent with a Drawing Filter message — the AI answering here can only look at pictures. `
|
|
5097
|
+
+ 'Attach a screenshot of the page you mean, or ask about it in the main conversation instead. Nothing was attached.';
|
|
5098
|
+
}
|
|
5099
|
+
|
|
4704
5100
|
async function attachFiles(files) {
|
|
4705
5101
|
if (!state.chat || state.chat.activeTurn?.local || state.chat.state === 'recovery' || state.followupSubmitting || state.followupUnknownId || hasUnknownFollowup()) return;
|
|
4706
5102
|
const snapshot = captureChat();
|
|
@@ -4711,6 +5107,8 @@
|
|
|
4711
5107
|
// an image, selecting that same file again must fire a fresh change event.
|
|
4712
5108
|
ui.file.value = '';
|
|
4713
5109
|
if (incoming.some((file) => !allowedTypes.has(file.type))) { report(new Error('Attach a PNG, JPEG, WebP, or PDF')); return; }
|
|
5110
|
+
const filterRefused = filterAttachRefusal(incoming);
|
|
5111
|
+
if (filterRefused) { report(filterRefusal(filterRefused)); return; }
|
|
4714
5112
|
const imageCount = state.attachments.filter((attachment) => attachment.mediaType.startsWith('image/')).length
|
|
4715
5113
|
+ incoming.filter((file) => file.type.startsWith('image/')).length;
|
|
4716
5114
|
if (imageCount > MAX_IMAGES_PER_MESSAGE) {
|
|
@@ -4792,6 +5190,9 @@
|
|
|
4792
5190
|
const fetchedSequence = Number(active.lastEventSequence) || 0;
|
|
4793
5191
|
if (fetchedSequence >= knownSequence) Object.assign(state.chat, active);
|
|
4794
5192
|
}
|
|
5193
|
+
// A Tekla read allowance granted or revoked in another window changes only the chat record,
|
|
5194
|
+
// never the event stream: this poll is how the Tekla box and any open card learn of it.
|
|
5195
|
+
paintTeklaChip();
|
|
4795
5196
|
// SSE delivers messages immediately, while this poll is what confirms that the provider has
|
|
4796
5197
|
// finished. Keep the Rename chat control in step with that durable active-turn state.
|
|
4797
5198
|
ui.rename.hidden = !state.chat || Boolean(state.chat.activeTurn) || Boolean(state.chat.archivedAt);
|
|
@@ -4924,15 +5325,20 @@
|
|
|
4924
5325
|
return result;
|
|
4925
5326
|
}
|
|
4926
5327
|
|
|
4927
|
-
async function openConversation(chatId) {
|
|
5328
|
+
async function openConversation(chatId, options = {}) {
|
|
4928
5329
|
await refreshScope();
|
|
4929
5330
|
if (!state.scope?.owner) throw new Error('Open this conversation’s project or workflow, then try again.');
|
|
5331
|
+
// An object card names its project; a conversation is only ever asked for in that project's scope (#1653).
|
|
5332
|
+
if (typeof options.projectId === 'string' && (state.scope.owner.kind !== 'project' || state.scope.owner.projectId !== options.projectId)) {
|
|
5333
|
+
throw new Error('Open this project in Workspaces to see that conversation.');
|
|
5334
|
+
}
|
|
4930
5335
|
window.flolessBridge?.revealAiChat?.();
|
|
4931
5336
|
ui.tab.click();
|
|
4932
5337
|
const listed = await request(`/api/chat/conversations?${ownerQuery()}`);
|
|
4933
5338
|
state.chats = listed.chats || [];
|
|
4934
5339
|
paintHistory(); paintUnread();
|
|
4935
|
-
|
|
5340
|
+
const messageEventId = typeof options.messageEventId === 'string' ? options.messageEventId : undefined;
|
|
5341
|
+
await selectConversation(chatId, { focus: !messageEventId, replaceProviderChoice: true, ...(messageEventId ? { messageEventId } : {}) });
|
|
4936
5342
|
}
|
|
4937
5343
|
|
|
4938
5344
|
const TEKLA_OPERATION = 'Tekla.Structures.Model.Model.GetInfo().ModelName';
|
|
@@ -4953,7 +5359,7 @@
|
|
|
4953
5359
|
if (!node) return;
|
|
4954
5360
|
const chat = state.chat;
|
|
4955
5361
|
const draft = teklaDraftForChat(chat);
|
|
4956
|
-
const bound = chat
|
|
5362
|
+
const bound = currentTeklaBinding(chat);
|
|
4957
5363
|
const library = draft?.library || bound;
|
|
4958
5364
|
if (!chat || !library) {
|
|
4959
5365
|
if (!node.hidden || node.childElementCount) { node.replaceChildren(); node.hidden = true; delete node.dataset.key; }
|
|
@@ -4963,7 +5369,11 @@
|
|
|
4963
5369
|
const frozen = !draft && teklaBindingFrozen(chat);
|
|
4964
5370
|
const error = draft?.error || (state.teklaRemoveError?.chatId === chat.chatId ? state.teklaRemoveError.message : null);
|
|
4965
5371
|
const reads = teklaReadsCopy(library.operations);
|
|
4966
|
-
|
|
5372
|
+
// A standing allowance exists only on the server's bound record, never on a local draft.
|
|
5373
|
+
const allowed = !draft && Boolean(bound?.allowedForChat);
|
|
5374
|
+
const revoking = allowed && state.teklaRevokingChatId === chat.chatId;
|
|
5375
|
+
const key = [chat.chatId, library.sourcePath, library.hostVersion, reads, status, frozen, error || '',
|
|
5376
|
+
allowed, revoking, teklaAllowanceRevision(bound)].join('|');
|
|
4967
5377
|
// Keep the same Remove button across polls so keyboard focus survives a repaint.
|
|
4968
5378
|
if (node.dataset.key === key && !node.hidden) return;
|
|
4969
5379
|
node.dataset.key = key;
|
|
@@ -4974,8 +5384,14 @@
|
|
|
4974
5384
|
const copy = document.createElement('span'); copy.className = 'ai-chat-tekla-chip-copy';
|
|
4975
5385
|
copy.id = `chat-tekla-context-copy-${chat.chatId}`;
|
|
4976
5386
|
const lead = document.createElement('strong'); lead.textContent = `Tekla ${library.hostVersion} model library`;
|
|
4977
|
-
copy.append(lead, document.createTextNode(
|
|
4978
|
-
|
|
5387
|
+
copy.append(lead, document.createTextNode(allowed
|
|
5388
|
+
? ` · Chat may ask to read ${reads} — FloLess checks live each time and shows every result`
|
|
5389
|
+
: ` · Chat may ask to read ${reads} — FloLess asks you first and checks live each time`));
|
|
5390
|
+
if (allowed) {
|
|
5391
|
+
const pill = document.createElement('span'); pill.className = 'ai-chat-tekla-allowed';
|
|
5392
|
+
pill.textContent = 'Allowed for this chat';
|
|
5393
|
+
copy.append(document.createTextNode(' '), pill);
|
|
5394
|
+
} else if (status === 'bound') {
|
|
4979
5395
|
const suffix = document.createElement('span'); suffix.className = 'ai-chat-tekla-chip-state';
|
|
4980
5396
|
suffix.textContent = ' · added to this chat';
|
|
4981
5397
|
copy.append(suffix);
|
|
@@ -4997,6 +5413,17 @@
|
|
|
4997
5413
|
remove.addEventListener('click', () => { void removeTeklaChip(); });
|
|
4998
5414
|
chip.append(remove);
|
|
4999
5415
|
}
|
|
5416
|
+
if (allowed) {
|
|
5417
|
+
const revoke = button(revoking ? 'Revoking…' : 'Revoke', 'shell.chat-tekla-allowance-revoke', 'ai-chat-tekla-remove');
|
|
5418
|
+
revoke.setAttribute('aria-label', 'Revoke allowing Tekla reads in this chat');
|
|
5419
|
+
revoke.setAttribute('aria-describedby', copy.id);
|
|
5420
|
+
revoke.dataset.tip = 'Chat will ask you again before each Tekla read. A read already running may finish.';
|
|
5421
|
+
revoke.disabled = revoking;
|
|
5422
|
+
revoke.setAttribute('aria-busy', String(revoking));
|
|
5423
|
+
if (revoking) revoke.dataset.blockedReason = 'FloLess is revoking this permission.';
|
|
5424
|
+
revoke.addEventListener('click', () => { void revokeTeklaAllowance(); });
|
|
5425
|
+
chip.append(revoke);
|
|
5426
|
+
}
|
|
5000
5427
|
node.append(chip);
|
|
5001
5428
|
if (error) {
|
|
5002
5429
|
const reason = document.createElement('p'); reason.className = 'ai-chat-tekla-error';
|
|
@@ -5044,19 +5471,86 @@
|
|
|
5044
5471
|
}
|
|
5045
5472
|
}
|
|
5046
5473
|
|
|
5474
|
+
// Ends this chat's standing Tekla read allowance. Nothing to confirm: it only removes permission.
|
|
5475
|
+
async function revokeTeklaAllowance() {
|
|
5476
|
+
const chat = state.chat;
|
|
5477
|
+
const snapshot = captureChat();
|
|
5478
|
+
// Revoke is idempotent on the server, so a click always asks it: a local view that already reads
|
|
5479
|
+
// "not allowed" must never turn Revoke into a silent no-op while the server still allows reads.
|
|
5480
|
+
if (!chat?.teklaModelRead || !snapshot || state.teklaRevokingChatId === chat.chatId) return;
|
|
5481
|
+
state.teklaRemoveError = null;
|
|
5482
|
+
state.teklaRevokingChatId = chat.chatId;
|
|
5483
|
+
paintTeklaChip();
|
|
5484
|
+
try {
|
|
5485
|
+
const result = await request(`/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/tekla-model-read/allowance/revoke`, {
|
|
5486
|
+
method: 'POST', body: JSON.stringify({ owner: snapshot.scope.owner }),
|
|
5487
|
+
});
|
|
5488
|
+
if (!sameChat(snapshot)) return;
|
|
5489
|
+
// Only the server's own record, with no allowance left, may say it ended.
|
|
5490
|
+
const updated = result?.chat;
|
|
5491
|
+
if (!updated || updated.chatId !== snapshot.chatId || updated.teklaModelRead?.allowedForChat) {
|
|
5492
|
+
state.teklaRemoveError = { chatId: snapshot.chatId, message: 'FloLess could not confirm that Tekla reads will ask again. Try Revoke again.' };
|
|
5493
|
+
return;
|
|
5494
|
+
}
|
|
5495
|
+
state.chat = { ...state.chat, teklaModelRead: updated.teklaModelRead };
|
|
5496
|
+
currentTeklaBinding(state.chat);
|
|
5497
|
+
announce('Tekla reads will ask you again in this chat.');
|
|
5498
|
+
} catch (error) {
|
|
5499
|
+
if (!sameChat(snapshot)) return;
|
|
5500
|
+
state.teklaRemoveError = { chatId: snapshot.chatId, message: errorMessage(error) };
|
|
5501
|
+
} finally {
|
|
5502
|
+
if (state.teklaRevokingChatId === snapshot.chatId) state.teklaRevokingChatId = null;
|
|
5503
|
+
if (sameChat(snapshot)) {
|
|
5504
|
+
const hadFocus = ui.teklaChip?.contains(document.activeElement);
|
|
5505
|
+
paintTeklaChip();
|
|
5506
|
+
// The Revoke button is gone: keep focus in the Tekla box instead of dropping it to the page.
|
|
5507
|
+
if (hadFocus || document.activeElement === document.body) {
|
|
5508
|
+
const target = ui.teklaChip?.querySelector('[data-command-id="shell.chat-tekla-allowance-revoke"]')
|
|
5509
|
+
|| ui.teklaChip?.querySelector('.ai-chat-tekla-chip-copy');
|
|
5510
|
+
if (target && !target.matches('button')) target.setAttribute('tabindex', '-1');
|
|
5511
|
+
target?.focus();
|
|
5512
|
+
}
|
|
5513
|
+
}
|
|
5514
|
+
}
|
|
5515
|
+
}
|
|
5516
|
+
|
|
5517
|
+
// A pending approval that may be allowed for the whole chat: a Tekla read the bound library permits.
|
|
5518
|
+
function teklaAllowableApproval(approval) {
|
|
5519
|
+
const binding = currentTeklaBinding(state.chat);
|
|
5520
|
+
const tool = approval?.tool ?? state.events?.find((event) => event.type === 'approval-requested'
|
|
5521
|
+
&& event.payload?.approvalId === approval?.approvalId)?.payload?.tool;
|
|
5522
|
+
return Boolean(binding && approvalIsExplicitOnly(approval) && typeof tool === 'string'
|
|
5523
|
+
&& tool.startsWith('floless_tekla_') && !teklaDraftForChat(state.chat));
|
|
5524
|
+
}
|
|
5525
|
+
// The chat's Tekla binding, never older than one this page has already seen. A poll that left before
|
|
5526
|
+
// a grant or revoke can land after it; the allowance revision only ever rises for one binding, so the
|
|
5527
|
+
// higher one is the newer truth and a stale snapshot cannot bring back a revoked pill.
|
|
5528
|
+
function currentTeklaBinding(chat) {
|
|
5529
|
+
const binding = chat?.teklaModelRead || null;
|
|
5530
|
+
if (!binding) return null;
|
|
5531
|
+
const key = `${chat.chatId}|${binding.sourcePath}|${binding.boundAt}`;
|
|
5532
|
+
const seen = state.teklaNewestBinding.get(key);
|
|
5533
|
+
if (seen && teklaAllowanceRevision(seen) > teklaAllowanceRevision(binding)) return seen;
|
|
5534
|
+
state.teklaNewestBinding.set(key, binding);
|
|
5535
|
+
return binding;
|
|
5536
|
+
}
|
|
5537
|
+
function teklaAllowanceRevision(binding) {
|
|
5538
|
+
return Number.isSafeInteger(binding?.allowanceRevision) ? binding.allowanceRevision : 0;
|
|
5539
|
+
}
|
|
5540
|
+
|
|
5047
5541
|
// The reads a library binding permits, as the chip names them. A binding stored before the
|
|
5048
5542
|
// selection read existed has no list and permits the model name only.
|
|
5049
5543
|
// The closed list the server accepts, in its canonical order: [model name, selection].
|
|
5050
5544
|
function teklaChatReads() {
|
|
5051
5545
|
return ['Tekla.Structures.Model.Model.GetInfo().ModelName', 'Tekla.Structures.Model.UI.ModelObjectSelector.GetSelectedObjects()'];
|
|
5052
5546
|
}
|
|
5053
|
-
function teklaReadsCopy(operations) {
|
|
5547
|
+
function teklaReadsCopy(operations, joiner = ' or ') {
|
|
5054
5548
|
const [modelRead, selectionRead] = teklaChatReads();
|
|
5055
5549
|
const list = Array.isArray(operations) ? operations : [modelRead];
|
|
5056
5550
|
const names = [];
|
|
5057
5551
|
if (list.includes(modelRead)) names.push('the open model name');
|
|
5058
5552
|
if (list.includes(selectionRead)) names.push('the parts you have selected');
|
|
5059
|
-
return names.join(
|
|
5553
|
+
return names.join(joiner);
|
|
5060
5554
|
}
|
|
5061
5555
|
function sameTeklaReads(a, b) {
|
|
5062
5556
|
const [modelRead] = teklaChatReads();
|
|
@@ -5234,6 +5728,9 @@
|
|
|
5234
5728
|
ui.integrations.addEventListener('click', openIntegrations);
|
|
5235
5729
|
ui.send.addEventListener('click', sendTurn);
|
|
5236
5730
|
// The Drawing Filter page reports every change that can alter what the chat shows about it.
|
|
5731
|
+
// The surface decides what may be attached, so repaint the paperclip the moment the step changes
|
|
5732
|
+
// rather than waiting for the next unrelated repaint.
|
|
5733
|
+
window.addEventListener('floless:workspace-step-changed', () => { paintAttachControl(); });
|
|
5237
5734
|
window.addEventListener('floless:filter-ai-changed', () => {
|
|
5238
5735
|
state.filterCardMessages.clear();
|
|
5239
5736
|
paintFloLessContext(); refreshFilterCards(); updateSendState();
|
|
@@ -5249,6 +5746,8 @@
|
|
|
5249
5746
|
if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) { event.preventDefault(); sendTurn(); }
|
|
5250
5747
|
else if (event.key === 'Escape') { ui.skills.hidden = true; closePicker(); }
|
|
5251
5748
|
});
|
|
5749
|
+
// Capture phase: the control's own handler runs after, so a sentence it reports is held afresh.
|
|
5750
|
+
shell.addEventListener('click', releaseReportOnControl, true);
|
|
5252
5751
|
shell.addEventListener('dragover', (event) => { if (event.dataTransfer?.types.includes('Files')) event.preventDefault(); });
|
|
5253
5752
|
shell.addEventListener('drop', (event) => { if (event.dataTransfer?.files?.length) { event.preventDefault(); attachFiles(event.dataTransfer.files); } });
|
|
5254
5753
|
ui.input.addEventListener('paste', (event) => {
|
|
@@ -5279,10 +5778,19 @@
|
|
|
5279
5778
|
|
|
5280
5779
|
state.refreshTimer = setInterval(pollChatsTick, 5000);
|
|
5281
5780
|
window.addEventListener('pagehide', () => { closeSource(); contextObserver.disconnect(); activityResizeObserver.disconnect(); clearInterval(state.refreshTimer); clearTimeout(state.draftTimer); });
|
|
5781
|
+
// A new selection is a new decision: a pill left out for the old one comes back for it.
|
|
5782
|
+
window.addEventListener('floless:model-selection', () => {
|
|
5783
|
+
let selection = null;
|
|
5784
|
+
try { selection = window.flolessLeftPane?.readSelection?.() || null; } catch { selection = null; }
|
|
5785
|
+
if (state.subjectsDismissed && subjectsKey(selection) !== state.subjectsDismissed) state.subjectsDismissed = null;
|
|
5786
|
+
paintAttachments();
|
|
5787
|
+
});
|
|
5282
5788
|
window.flolessChat = {
|
|
5283
5789
|
refreshScope, refreshActivity, refreshIndex, startRequest, openConversation, openDraft, openVerifiedTeklaDraft,
|
|
5284
5790
|
startProjectIntake, resumeProjectIntake,
|
|
5285
5791
|
currentProvider: () => state.chat?.provider ?? null,
|
|
5792
|
+
// The project this panel's conversations belong to; an object card offers Show in chat only for it (#1653).
|
|
5793
|
+
scopeProjectId: () => (state.scope?.owner?.kind === 'project' ? state.scope.owner.projectId : null),
|
|
5286
5794
|
// The New project dialog's AI choice (#1605) words each provider's sign-in the way this
|
|
5287
5795
|
// panel's own chooser does, so the two ways into a conversation read the same.
|
|
5288
5796
|
providerAccountLabel,
|