@floless/app 0.149.0 → 0.150.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 +102295 -88314
- package/dist/schemas/drawing-check.profile.v1.schema.json +45 -2
- package/dist/schemas/steel.model.v2.schema.json +9 -0
- package/dist/skills/floless-app-approval/SKILL.md +79 -4
- package/dist/skills/floless-app-onboarding/SKILL.md +4 -4
- package/dist/skills/floless-app-onboarding/references/aware-runtime.md +1 -1
- package/dist/skills/floless-app-onboarding/references/floless-app-tour.md +15 -13
- package/dist/skills/floless-app-routines/SKILL.md +4 -1
- package/dist/skills/floless-app-routines/references/routines-api.md +14 -2
- package/dist/skills/floless-app-steel-model/SKILL.md +4 -2
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +14 -9
- package/dist/skills/floless-app-workflows/SKILL.md +2 -2
- package/dist/templates/tekla-parser.flo +13 -3
- package/dist/web/agents.js +887 -0
- package/dist/web/app.css +458 -23
- package/dist/web/app.js +20 -5
- package/dist/web/aware.js +1339 -134
- package/dist/web/chat.css +68 -4
- package/dist/web/chat.js +1770 -55
- package/dist/web/commands-drawing-check.js +15 -0
- package/dist/web/commands-revit.js +5 -0
- package/dist/web/commands-shell.js +785 -50
- package/dist/web/commands-tekla-parser.js +8 -1
- package/dist/web/connections.js +57 -14
- package/dist/web/drawing-check-editor.html +10 -2
- package/dist/web/drawing-check-editor.js +569 -40
- package/dist/web/drawing-check-overlay.js +45 -2
- package/dist/web/index.html +102 -27
- package/dist/web/instructor.js +85 -8
- package/dist/web/leave-guard.js +1 -0
- package/dist/web/left-pane.js +20 -1
- package/dist/web/local-discovery.js +12 -2
- package/dist/web/model-editor.css +32 -32
- package/dist/web/model-panel-bridge.js +11 -3
- package/dist/web/model-viewport-lighting.js +4 -2
- package/dist/web/model-viewport-revit-adapter.js +3 -0
- package/dist/web/model-viewport-toolbar.js +6 -3
- package/dist/web/model-viewport.js +11 -1
- package/dist/web/revit-editor.css +14 -14
- package/dist/web/revit-editor.js +64 -12
- package/dist/web/steel-3d-core.js +133 -0
- package/dist/web/steel-3d-view.js +10 -0
- package/dist/web/steel-editor.html +171 -39
- package/dist/web/steel-model-v2-client-validation.js +11 -0
- package/dist/web/steel-model-v2-commands.js +80 -5
- package/dist/web/tool-updates.js +367 -0
- package/dist/web/workspaces.js +679 -59
- package/package.json +1 -1
package/dist/web/chat.js
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
historyToggle: el('chat-history-toggle'), newChat: el('chat-new'), refresh: el('chat-refresh'), history: el('chat-history'),
|
|
20
20
|
title: el('chat-title'), rename: el('chat-rename'), scope: el('chat-scope'), settingsToggle: el('chat-settings-toggle'),
|
|
21
21
|
settings: el('chat-settings'), provider: el('chat-provider'), switchAccount: el('chat-switch-account'), model: el('chat-model'),
|
|
22
|
-
effort: el('chat-effort'), permission: el('chat-permission'), integrations: el('chat-integrations'),
|
|
22
|
+
effort: el('chat-effort'), permission: el('chat-permission'), integrations: el('chat-integrations'), ownConnectors: el('chat-own-connectors'),
|
|
23
23
|
desktopValue: el('chat-desktop-value'), desktopReason: el('chat-desktop-reason'), picker: el('chat-picker'),
|
|
24
24
|
feed: el('chat-feed'), offscreenActivity: el('chat-offscreen-activity'), recovery: el('chat-recovery'),
|
|
25
25
|
approvalTray: el('chat-approval-tray'), recoveryCopy: el('chat-recovery-copy'),
|
|
@@ -30,19 +30,29 @@
|
|
|
30
30
|
unread: el('chat-unread'), tab: el('narrative-tab'),
|
|
31
31
|
context: el('left-chat-context'),
|
|
32
32
|
teklaChip: el('chat-tekla-context'),
|
|
33
|
+
connectors: el('chat-connectors'),
|
|
34
|
+
changeAllowance: el('chat-change-allowance'),
|
|
35
|
+
scopeControls: el('chat-scope-controls'), scopeToggle: el('chat-scope-toggle'),
|
|
36
|
+
scopePicker: el('chat-scope-picker'), scopeDisclosure: el('chat-scope-disclosure'),
|
|
37
|
+
checkAllowance: el('chat-check-allowance'),
|
|
33
38
|
workspaceUnits: el('chat-units'),
|
|
39
|
+
moveNotice: el('chat-move-notice'), moveCopy: el('chat-move-copy'), movePrimary: el('chat-move-primary'),
|
|
40
|
+
moveSecondary: el('chat-move-secondary'), moveDismiss: el('chat-move-dismiss'),
|
|
34
41
|
};
|
|
35
42
|
|
|
36
43
|
const state = {
|
|
44
|
+
scopeView: null, scopeViewChatId: null, scopeChoice: null, scopeEditing: false, scopePickerOpen: false,
|
|
37
45
|
// signInPending is keyed by provider: a wait started in one conversation must not paint an
|
|
38
46
|
// unrelated conversation's button as Waiting for sign-in… for the next two minutes.
|
|
39
47
|
// #1798: the chat owner's display units as the server last answered them (null = not known yet), and the
|
|
40
48
|
// generation that answer belongs to. Receipts show recorded kilograms until they are known.
|
|
41
49
|
displayUnits: null, displayUnitsGeneration: 0,
|
|
50
|
+
// #1890 PR 3b: the workspace history's pointer rows, the move notice on screen, and moves being followed now.
|
|
51
|
+
movedChats: [], movedChatsKnown: null, moveNotice: null, moveNoticeTimer: null, followingMoves: new Set(), movingPoll: null,
|
|
42
52
|
sessionReady: false, scope: null, chats: [], archivedChats: [], unreadableChats: [], chat: null, events: [], capability: null, signInPending: new Set(), desktop: null,
|
|
43
53
|
source: null, eventReconnectTimer: null, eventReconnectAttempt: 0, eventReconnectChatId: null, attachments: [], imageLimitChatId: null, followupSubmitting: false, followupUnknownId: null, resolvingFollowupIds: new Set(), retryingFollowupIds: new Set(), integrations: null, historyOpen: false, historyOpenings: 0, historyFilter: 'all', archivedHistoryOpen: false,
|
|
44
54
|
instructorAnswers: [], historyLoading: false, historyRequestGeneration: 0, picker: null, loading: false,
|
|
45
|
-
draftTimer: null, localDraft: null, backgroundDrafts: new Map(), draftWrites: new Map(), draftVersions: new Map(), unknownFollowups: new Map(), refreshTimer: null, scopeGeneration: 0, selectionGeneration: 0, choosingProvider: false,
|
|
55
|
+
draftTimer: null, localDraft: null, backgroundDrafts: new Map(), draftWrites: new Map(), draftVersions: new Map(), unknownFollowups: new Map(), refreshTimer: null, scopeGeneration: 0, selectionGeneration: 0, openInGeneration: 0, choosingProvider: false,
|
|
46
56
|
answerJump: null, answerJumpTimer: null, scopeInitialized: false, renaming: null, historyRename: null, pendingSubmissionId: null, recoveryMessage: null, recoveryCanEnd: false,
|
|
47
57
|
stream: null, liveStatusTurnId: null, decidingApprovalIds: new Set(), revokingApprovalTurns: new Set(), uploadingChatIds: new Set(),
|
|
48
58
|
// #1653 stage 4: this chat owner's (project or workflow, #1890) questions linked to live Tekla parts, the card's open lists, and the receipt showing it.
|
|
@@ -146,6 +156,11 @@
|
|
|
146
156
|
error.reason = body?.reason || null;
|
|
147
157
|
error.recovery = Array.isArray(body?.recovery) ? body.recovery : null;
|
|
148
158
|
error.status = response.status;
|
|
159
|
+
// #1890 PR 3b: the conversation moved — wherever this was asked from, the open tab follows it.
|
|
160
|
+
if (error.code === 'chat-moved' && body?.to?.chatId) {
|
|
161
|
+
error.movedTo = body.to;
|
|
162
|
+
queueMicrotask(() => { void followMovedChat(body.to); });
|
|
163
|
+
}
|
|
149
164
|
throw error;
|
|
150
165
|
}
|
|
151
166
|
return body;
|
|
@@ -194,7 +209,14 @@
|
|
|
194
209
|
// request() writes the timeout's sentence itself. Without this it fell through to the generic "could
|
|
195
210
|
// not complete this chat action", which hid the one fact the user could act on (#1604).
|
|
196
211
|
if (code === 'local-timeout' && raw) return raw;
|
|
212
|
+
// #1907: the server marks a not-sent reason it already wrote for the person; it is shown as is.
|
|
213
|
+
if (code === 'chat-send-refused-plain' && raw) return raw;
|
|
197
214
|
const codeMessages = {
|
|
215
|
+
// #1890 PR 3b: the server's own sentences name the workflow.
|
|
216
|
+
'chat-moving': raw,
|
|
217
|
+
'chat-moved': raw,
|
|
218
|
+
'chat-arriving': raw,
|
|
219
|
+
'chat-move-busy': raw,
|
|
198
220
|
'chat-origin-refused': 'This chat can only be used from the FloLess app. Reload the page and try again.',
|
|
199
221
|
'chat-owner-stale': 'This conversation no longer matches the current project or workflow folder. Reopen the project or workflow, then try again.',
|
|
200
222
|
'chat-cwd-stale': 'This conversation no longer matches the current project or workflow folder. Reopen the project or workflow, then try again.',
|
|
@@ -257,8 +279,9 @@
|
|
|
257
279
|
'chat-knowledge-unscoped': 'Knowledge is available only inside a project conversation. Open a project and try again.',
|
|
258
280
|
'chat-knowledge-page-missing': 'That Knowledge page is no longer available in this project. Refresh the conversation.',
|
|
259
281
|
'approval-explicit-only': 'This read needs its own approval. Choose Approve once or Deny.',
|
|
260
|
-
'approval-not-chat-allowable': '
|
|
282
|
+
'approval-not-chat-allowable': 'This can only be approved once. Choose Approve once or Deny.',
|
|
261
283
|
'tekla-allowance-changed': 'The Tekla read permission for this chat changed. Choose again.',
|
|
284
|
+
'connector-allowance-changed': 'The connectors allowed for this chat changed. Choose again.',
|
|
262
285
|
};
|
|
263
286
|
if (code === 'chat-followup-refused' && error?.reason === 'chat-session-required') {
|
|
264
287
|
return 'Your FloLess session expired before this message was sent. Copy the draft, reload, then paste and send it again.';
|
|
@@ -367,6 +390,8 @@
|
|
|
367
390
|
|
|
368
391
|
function report(error, prefix = '', messages = null) {
|
|
369
392
|
const code = String(error && error.code || '');
|
|
393
|
+
// #1890 PR 3b: a conversation that moved is not a failure — request() already follows it into its workflow.
|
|
394
|
+
if (code === 'chat-moved' && error?.movedTo) return;
|
|
370
395
|
const message = `${prefix}${prefix ? ': ' : ''}${messages?.[code] || errorMessage(error)}`;
|
|
371
396
|
// Keep the raw cause (#1604): the user-facing sentence deliberately drops it, and without it a
|
|
372
397
|
// failure could only be diagnosed from the server log. A timeout, a network failure or a server
|
|
@@ -532,13 +557,15 @@
|
|
|
532
557
|
const dashboardVisible = document.getElementById('dashboard')?.hidden === false;
|
|
533
558
|
// #1890: the Workflows landing (the list of workflows), not the canvas of the workflow loaded underneath.
|
|
534
559
|
const workflowLanding = document.getElementById('wf-landing')?.hidden === false;
|
|
535
|
-
|
|
560
|
+
// #2007: the Agents tab is its own surface; where you are adds context only.
|
|
561
|
+
const agentsMode = document.body.classList.contains('mode-agents');
|
|
562
|
+
const surface = agentsMode && !reportOpen ? (window.flolessAgents?.surface?.() || 'agent-list') : reportOpen ? (threeDimensionalReport ? '3d-report' : 'report')
|
|
536
563
|
: editorOpen ? 'model-editor'
|
|
537
564
|
: workspaceMode ? (workspaceProjectOpen ? workspaceSurface : 'project-list')
|
|
538
565
|
: workflowLanding ? 'workflow-list' : dashboardVisible ? 'dashboard' : 'workflow-canvas';
|
|
539
566
|
if (options.surfaceOnly) return { surface };
|
|
540
567
|
return {
|
|
541
|
-
mode: workspaceMode ? 'workspaces' : workflowMode ? 'workflows' : 'canvas',
|
|
568
|
+
mode: agentsMode ? 'agents' : workspaceMode ? 'workspaces' : workflowMode ? 'workflows' : 'canvas',
|
|
542
569
|
surface,
|
|
543
570
|
activity: workflowRunning ? 'workflow-running' : 'idle',
|
|
544
571
|
visibleText: visibleFloLessSurfaceText(surface),
|
|
@@ -571,6 +598,7 @@
|
|
|
571
598
|
case 'project-knowledge': return shellText('ws-knowledge');
|
|
572
599
|
case 'project-list': return shellText('ws-landing');
|
|
573
600
|
case 'workflow-list': return shellText('wf-landing');
|
|
601
|
+
case 'agent-list': case 'agent-page': return shellText('agents-surface');
|
|
574
602
|
case 'workflow-canvas': return shellText('canvas-main', 'inspect');
|
|
575
603
|
case 'dashboard': return shellText('dashboard');
|
|
576
604
|
case 'report': return boundedVisibleText(readVisibleFrameText('report-frame'), shellText('report-title', 'report-sub', 'report-overlay'));
|
|
@@ -585,7 +613,7 @@
|
|
|
585
613
|
'drawing-filter': 'Drawing Filter', 'project-model': 'project model', 'project-exports': 'project exports',
|
|
586
614
|
'project-history': 'project history', 'project-knowledge': 'project Knowledge', 'project-list': 'project list',
|
|
587
615
|
'workflow-canvas': 'workflow canvas', dashboard: 'dashboard', report: 'report', '3d-report': '3D report',
|
|
588
|
-
'model-editor': 'model editor', 'workflow-list': 'workflow list',
|
|
616
|
+
'model-editor': 'model editor', 'workflow-list': 'workflow list', 'agent-list': 'list of agents', 'agent-page': 'agent page',
|
|
589
617
|
};
|
|
590
618
|
return `${labels[context.surface] || 'FloLess'} · visible state${context.activity === 'workflow-running' ? ' · workflow running' : ''}`;
|
|
591
619
|
}
|
|
@@ -775,6 +803,21 @@
|
|
|
775
803
|
ui.disclosure.hidden = options.opening === true || Boolean(state.chat) || !state.scope?.owner;
|
|
776
804
|
}
|
|
777
805
|
|
|
806
|
+
// Everything a conversation paints above the composer is painted from `state.chat`, which is null on the
|
|
807
|
+
// chooser. Repaint each one so none of it is left over from another conversation: the pending approval card
|
|
808
|
+
// and its Deny / Approve buttons (#1958 — they did nothing, with no chat to decide on, and the shell still
|
|
809
|
+
// reported an approval waiting), the "Auto-approval on" scope card, the library chip ("added to this chat"),
|
|
810
|
+
// the "connectors are on" line and allowances (#1907), the allowed changes (#1890) and checks (#1956), and the
|
|
811
|
+
// scope control. Each paints itself back when its conversation is opened again.
|
|
812
|
+
function clearOtherConversationLines() {
|
|
813
|
+
paintApproval();
|
|
814
|
+
paintTeklaChip();
|
|
815
|
+
paintConnectorAllowance();
|
|
816
|
+
paintChangeAllowance();
|
|
817
|
+
paintScopeControl();
|
|
818
|
+
paintCheckAllowance();
|
|
819
|
+
}
|
|
820
|
+
|
|
778
821
|
function providerChooser() {
|
|
779
822
|
paintComposerDisclosure();
|
|
780
823
|
// Without a conversation owner there is no provider, history, or refresh to offer: none of those
|
|
@@ -783,6 +826,11 @@
|
|
|
783
826
|
// conversation must go with it — and so must the previous conversation's units line.
|
|
784
827
|
shell.querySelector('.ai-chat-runtime')?.remove(); stopRuntimePoll();
|
|
785
828
|
if (ui.workspaceUnits) { ui.workspaceUnits.hidden = true; ui.workspaceUnits.replaceChildren(); delete ui.workspaceUnits.dataset.painted; }
|
|
829
|
+
// And its recovery banner, with its Stop response / Check again (#1921). The banner is painted from
|
|
830
|
+
// the selected conversation, so it is repainted here — on every way onto the chooser, not only + New
|
|
831
|
+
// conversation — and paints itself back when that conversation is opened again.
|
|
832
|
+
paintRecovery();
|
|
833
|
+
clearOtherConversationLines();
|
|
786
834
|
if (!state.scope?.owner) { showUnscoped(); return; }
|
|
787
835
|
ui.feed.replaceChildren();
|
|
788
836
|
updateOffscreenActivity();
|
|
@@ -980,7 +1028,7 @@
|
|
|
980
1028
|
clearProviderChoice();
|
|
981
1029
|
closeSource();
|
|
982
1030
|
clearLiveStream(true);
|
|
983
|
-
state.chats = []; state.archivedChats = []; state.unreadableChats = []; state.chat = null; state.events = []; state.capability = null; state.attachments = []; state.followupUnknownId = null;
|
|
1031
|
+
state.chats = []; state.archivedChats = []; state.unreadableChats = []; state.movedChats = []; state.movedChatsKnown = null; state.chat = null; state.events = []; state.capability = null; state.attachments = []; state.followupUnknownId = null;
|
|
984
1032
|
ui.feed.replaceChildren();
|
|
985
1033
|
updateOffscreenActivity();
|
|
986
1034
|
const empty = document.createElement('div');
|
|
@@ -1165,8 +1213,10 @@
|
|
|
1165
1213
|
const archivedChats = state.archivedChats.filter((chat) => Boolean(chat.archivedAt));
|
|
1166
1214
|
const unreadableChats = state.unreadableChats || [];
|
|
1167
1215
|
if (unreadableChats.length) appendUnreadableChats(unreadableChats, ui.history);
|
|
1216
|
+
const movedChats = state.scope.owner.kind === 'workspace' ? (state.movedChats || []) : [];
|
|
1217
|
+
if (movedChats.length) appendMovedChats(movedChats, ui.history);
|
|
1168
1218
|
if (!state.chats.length && !archivedChats.length) {
|
|
1169
|
-
if (unreadableChats.length) { restoreHistoryFocus(focusedCommand); return; }
|
|
1219
|
+
if (unreadableChats.length || movedChats.length) { restoreHistoryFocus(focusedCommand); return; }
|
|
1170
1220
|
const empty = document.createElement('div'); empty.className = 'ai-chat-history-empty';
|
|
1171
1221
|
empty.textContent = 'No conversations here yet.';
|
|
1172
1222
|
ui.history.append(empty); return;
|
|
@@ -1276,6 +1326,240 @@
|
|
|
1276
1326
|
// A conversation whose saved file is damaged (#1619). The server knows nothing trustworthy about it
|
|
1277
1327
|
// beyond its id — no title, no provider — so the row says what happened and offers the one thing
|
|
1278
1328
|
// that can be done here. It opens nothing, so it is not a button; only Discard acts.
|
|
1329
|
+
/*
|
|
1330
|
+
* #1890 PR 3b: a conversation that moved into the workflow it built. Its old home keeps a pointer row that opens it
|
|
1331
|
+
* there; a row whose new home is gone says so and offers Remove (the pointer only, never a conversation).
|
|
1332
|
+
*/
|
|
1333
|
+
function appendMovedChats(entries, destination) {
|
|
1334
|
+
const group = document.createElement('section'); group.className = 'ai-chat-history-group ai-chat-history-moved';
|
|
1335
|
+
group.setAttribute('aria-label', 'Conversations that moved into a workflow');
|
|
1336
|
+
const label = document.createElement('div'); label.className = 'ai-chat-history-label'; label.textContent = 'Moved';
|
|
1337
|
+
group.append(label);
|
|
1338
|
+
for (const entry of entries) {
|
|
1339
|
+
if (entry.targetGone) {
|
|
1340
|
+
const row = document.createElement('div');
|
|
1341
|
+
row.className = 'ai-chat-history-row unreadable moved-gone';
|
|
1342
|
+
row.dataset.chatId = entry.chatId;
|
|
1343
|
+
const title = document.createElement('span'); title.className = 'ai-chat-history-title'; title.textContent = entry.title;
|
|
1344
|
+
const meta = document.createElement('span'); meta.className = 'ai-chat-history-meta';
|
|
1345
|
+
meta.textContent = 'This conversation’s workflow is no longer here.';
|
|
1346
|
+
const actions = document.createElement('span'); actions.className = 'ai-chat-history-actions always-on';
|
|
1347
|
+
const remove = document.createElement('button');
|
|
1348
|
+
remove.type = 'button'; remove.className = 'ai-chat-history-moved-remove'; remove.textContent = 'Remove';
|
|
1349
|
+
remove.dataset.commandId = `shell.chat-moved-remove#${entry.chatId}`;
|
|
1350
|
+
remove.dataset.commandInstanceLabel = entry.title;
|
|
1351
|
+
remove.setAttribute('aria-label', `Remove ${entry.title}`);
|
|
1352
|
+
remove.dataset.tip = 'Removes only this row';
|
|
1353
|
+
remove.addEventListener('click', (event) => { event.preventDefault(); event.stopPropagation(); void removeMovedPointer(entry, remove); });
|
|
1354
|
+
actions.append(remove);
|
|
1355
|
+
row.append(title, meta, actions);
|
|
1356
|
+
group.append(row);
|
|
1357
|
+
continue;
|
|
1358
|
+
}
|
|
1359
|
+
const row = button('', `shell.chat-moved-open#${entry.chatId}`, 'ai-chat-history-row moved');
|
|
1360
|
+
row.dataset.commandInstanceLabel = `${entry.title} · ${entry.to.label}`;
|
|
1361
|
+
row.setAttribute('aria-label', `${entry.title}, moved to workflow ${entry.to.label}. Open it there`);
|
|
1362
|
+
const title = document.createElement('span'); title.className = 'ai-chat-history-title'; title.textContent = entry.title;
|
|
1363
|
+
const meta = document.createElement('span'); meta.className = 'ai-chat-history-meta'; meta.textContent = `Moved to workflow ${entry.to.label}`;
|
|
1364
|
+
row.append(title, meta);
|
|
1365
|
+
row.addEventListener('click', () => { void openMovedChat(movedTarget(entry)).catch((error) => report(error, 'Could not open that conversation')); });
|
|
1366
|
+
group.append(row);
|
|
1367
|
+
}
|
|
1368
|
+
destination.append(group);
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
async function removeMovedPointer(entry, trigger) {
|
|
1372
|
+
const snapshot = captureScope();
|
|
1373
|
+
if (!snapshot) return;
|
|
1374
|
+
trigger.hidden = true;
|
|
1375
|
+
try {
|
|
1376
|
+
await request(`/api/chat/conversations/${encodeURIComponent(entry.chatId)}/moved-pointer`, {
|
|
1377
|
+
method: 'DELETE', body: JSON.stringify({ owner: snapshot.scope.owner }),
|
|
1378
|
+
});
|
|
1379
|
+
if (!sameScope(snapshot.scope, snapshot.generation)) return;
|
|
1380
|
+
state.movedChats = (state.movedChats || []).filter((item) => item.chatId !== entry.chatId);
|
|
1381
|
+
paintHistory();
|
|
1382
|
+
announce(`Removed ${entry.title} from this list.`);
|
|
1383
|
+
(ui.history.querySelector('.ai-chat-history-row:not(.unreadable)') || ui.history.querySelector('button'))?.focus();
|
|
1384
|
+
} catch (error) {
|
|
1385
|
+
trigger.hidden = false;
|
|
1386
|
+
report(error, 'Could not remove that row');
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
/** New pointer rows since the last history read: a conversation not on screen moved — say so, with Open workflow. */
|
|
1391
|
+
function noteMovedChats(rows) {
|
|
1392
|
+
const list = Array.isArray(rows) ? rows : [];
|
|
1393
|
+
const known = state.movedChatsKnown;
|
|
1394
|
+
state.movedChats = list;
|
|
1395
|
+
state.movedChatsKnown = new Set(list.map((row) => row.chatId));
|
|
1396
|
+
if (!known) return;
|
|
1397
|
+
const fresh = list.find((row) => !known.has(row.chatId) && !row.targetGone && !state.followingMoves.has(row.chatId));
|
|
1398
|
+
if (!fresh) return;
|
|
1399
|
+
showMoveNotice({
|
|
1400
|
+
neutral: true, text: `${fresh.title} moved into workflow ${fresh.to.label}.`,
|
|
1401
|
+
primary: { label: 'Open workflow', command: 'shell.chat-move-open', run: () => openMovedChat(movedTarget(fresh)) }, dismiss: true,
|
|
1402
|
+
});
|
|
1403
|
+
announce(`${fresh.title} moved into workflow ${fresh.to.label}.`);
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
/** Where a pointer row's conversation lives now, in the shape the server's "moved" answer uses. */
|
|
1407
|
+
function movedTarget(pointer) {
|
|
1408
|
+
return { owner: { kind: 'workflow', workflowId: pointer.to.workflowId }, chatId: pointer.chatId, label: pointer.to.label };
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
/**
|
|
1412
|
+
* #2007: show one conversation of any owner — an agent run's — without the location changing. Loads that owner's
|
|
1413
|
+
* history when it is not the one on screen, then selects the conversation. The last call wins.
|
|
1414
|
+
*/
|
|
1415
|
+
async function openConversationIn(scope, chatId) {
|
|
1416
|
+
const ticket = ++state.openInGeneration;
|
|
1417
|
+
if (!scope?.owner || typeof chatId !== 'string') return false;
|
|
1418
|
+
if (scopeKey(scope) !== scopeKey(state.scope)) await loadScope({ ...scope, chatId });
|
|
1419
|
+
else if (scope.label && state.scope && scope.label !== state.scope.label) { state.scope = { ...state.scope, label: scope.label }; ui.scope.textContent = scope.label; }
|
|
1420
|
+
if (ticket !== state.openInGeneration) return false;
|
|
1421
|
+
if (state.chat?.chatId !== chatId) await selectConversation(chatId, { replaceProviderChoice: true, focus: false });
|
|
1422
|
+
return ticket === state.openInGeneration && state.chat?.chatId === chatId;
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
/** Open a moved conversation in its new home: the workflow (published or draft), then the conversation there. */
|
|
1426
|
+
async function openMovedChat(to) {
|
|
1427
|
+
const bridge = window.flolessBridge;
|
|
1428
|
+
if (typeof bridge?.openOwnedWorkflow !== 'function') throw new Error('Open the workflow from Workflows to see this conversation.');
|
|
1429
|
+
await bridge.openOwnedWorkflow(to.owner.workflowId);
|
|
1430
|
+
await refreshScope(true);
|
|
1431
|
+
if (state.scope?.owner?.kind !== 'workflow' || state.scope.owner.workflowId !== to.owner.workflowId) return false;
|
|
1432
|
+
await selectConversation(to.chatId, { replaceProviderChoice: true, focus: false });
|
|
1433
|
+
return true;
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
/*
|
|
1437
|
+
* The conversation on screen moved (its stream said so, or a request was answered 410): follow it into the workflow,
|
|
1438
|
+
* keep the person's unsent text — it wins over the copied draft — and keep their focus where it was.
|
|
1439
|
+
*/
|
|
1440
|
+
async function followMovedChat(to) {
|
|
1441
|
+
const chatId = to?.chatId;
|
|
1442
|
+
if (!chatId || state.followingMoves.has(chatId)) return;
|
|
1443
|
+
if (state.chat?.chatId !== chatId || state.scope?.owner?.kind !== 'workspace') return;
|
|
1444
|
+
state.followingMoves.add(chatId);
|
|
1445
|
+
// The newest text the person typed wins — including anything typed while the workflow opens. Loading clears the
|
|
1446
|
+
// box without an input event, so only the person's own typing updates this.
|
|
1447
|
+
let draft = ui.input.value;
|
|
1448
|
+
let typed = false;
|
|
1449
|
+
const keepTyping = () => { draft = ui.input.value; typed = true; };
|
|
1450
|
+
ui.input.addEventListener('input', keepTyping);
|
|
1451
|
+
const hadFocus = document.activeElement === ui.input || ui.feed.contains(document.activeElement);
|
|
1452
|
+
closeSource();
|
|
1453
|
+
try {
|
|
1454
|
+
let opened;
|
|
1455
|
+
try { opened = await openMovedChat(to); } finally { ui.input.removeEventListener('input', keepTyping); }
|
|
1456
|
+
if (!opened) return;
|
|
1457
|
+
if ((draft || typed) && state.chat?.chatId === chatId && ui.input.value !== draft) {
|
|
1458
|
+
ui.input.value = draft; autosize(); saveDraftSoon(); updateSendState();
|
|
1459
|
+
}
|
|
1460
|
+
if (hadFocus && state.chat?.chatId === chatId) ui.input.focus({ preventScroll: true });
|
|
1461
|
+
showMoveNotice({ neutral: true, text: `This conversation moved into workflow ${to.label}.`, autoDismissMs: 8000 });
|
|
1462
|
+
announce(`This conversation moved into workflow ${to.label}.`);
|
|
1463
|
+
} catch (error) {
|
|
1464
|
+
report(error, 'Could not open the workflow this conversation moved into');
|
|
1465
|
+
} finally { state.followingMoves.delete(chatId); }
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
/*
|
|
1469
|
+
* While the conversation on screen moves: look at the history list, never at the conversation itself — once the move
|
|
1470
|
+
* lands its old address answers "moved", which the browser would log as a failed request. The list says either that it
|
|
1471
|
+
* is still moving (its row) or where it went (its pointer row), and the tab follows from the pointer.
|
|
1472
|
+
*/
|
|
1473
|
+
async function checkMoveProgress(chatId) {
|
|
1474
|
+
const snapshot = captureChat();
|
|
1475
|
+
if (!snapshot || snapshot.chatId !== chatId) return;
|
|
1476
|
+
let listed;
|
|
1477
|
+
try { listed = await request(`/api/chat/conversations?${ownerQuery(snapshot.scope.owner)}`); }
|
|
1478
|
+
catch { if (sameChat(snapshot)) updateSendState(); return; }
|
|
1479
|
+
if (!sameChat(snapshot)) return;
|
|
1480
|
+
const pointer = (listed.movedChats || []).find((row) => row.chatId === chatId);
|
|
1481
|
+
if (pointer) {
|
|
1482
|
+
void followMovedChat(movedTarget(pointer));
|
|
1483
|
+
return;
|
|
1484
|
+
}
|
|
1485
|
+
const row = (listed.chats || []).find((item) => item.chatId === chatId);
|
|
1486
|
+
if (row && state.chat) {
|
|
1487
|
+
state.chat = { ...state.chat, ...row };
|
|
1488
|
+
paintConversation();
|
|
1489
|
+
}
|
|
1490
|
+
updateSendState();
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
function showMoveNotice(notice) {
|
|
1494
|
+
clearTimeout(state.moveNoticeTimer);
|
|
1495
|
+
state.moveNotice = notice;
|
|
1496
|
+
if (notice?.autoDismissMs) {
|
|
1497
|
+
state.moveNoticeTimer = setTimeout(() => { if (state.moveNotice === notice) { state.moveNotice = null; paintMoveNotice(); } }, notice.autoDismissMs);
|
|
1498
|
+
}
|
|
1499
|
+
paintMoveNotice();
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
/** A waiting move with a warning, for the conversation on screen: the sentence and the person's choices. */
|
|
1503
|
+
function moveNoticeForChat(chat) {
|
|
1504
|
+
const rehome = chat?.rehome;
|
|
1505
|
+
if (!rehome || state.scope?.owner?.kind !== 'workspace' || rehome.state !== 'pending' || !rehome.warning) return null;
|
|
1506
|
+
const keep = { label: 'Keep it here', command: 'shell.chat-move-keep', run: () => keepConversationHere(chat.chatId) };
|
|
1507
|
+
const retry = { label: 'Try again', command: 'shell.chat-move-retry', run: () => retryConversationMove(chat.chatId) };
|
|
1508
|
+
return rehome.targetGone
|
|
1509
|
+
? { neutral: false, text: rehome.warning, primary: keep, secondary: retry, chatId: chat.chatId }
|
|
1510
|
+
: { neutral: false, text: rehome.warning, primary: retry, chatId: chat.chatId };
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
function paintMoveNotice() {
|
|
1514
|
+
if (!ui.moveNotice) return;
|
|
1515
|
+
const notice = (state.moveBusy && state.moveBusy.chatId === state.chat?.chatId ? state.moveBusy : null)
|
|
1516
|
+
|| moveNoticeForChat(state.chat) || state.moveNotice;
|
|
1517
|
+
ui.moveNotice.hidden = !notice;
|
|
1518
|
+
if (!notice) return;
|
|
1519
|
+
ui.moveNotice.classList.toggle('neutral', Boolean(notice.neutral));
|
|
1520
|
+
const text = notice.busyText || notice.text;
|
|
1521
|
+
if (ui.moveCopy.textContent !== text) ui.moveCopy.textContent = text;
|
|
1522
|
+
for (const [control, action] of [[ui.movePrimary, notice.primary], [ui.moveSecondary, notice.secondary]]) {
|
|
1523
|
+
// A choice that cannot apply right now is hidden, not disabled.
|
|
1524
|
+
control.hidden = !action || Boolean(notice.busyText);
|
|
1525
|
+
if (!action) continue;
|
|
1526
|
+
control.textContent = action.label;
|
|
1527
|
+
control.dataset.commandId = action.command;
|
|
1528
|
+
control.onclick = () => { void runMoveAction(notice, action); };
|
|
1529
|
+
}
|
|
1530
|
+
ui.moveDismiss.hidden = !notice.dismiss;
|
|
1531
|
+
ui.moveDismiss.onclick = () => { state.moveNotice = null; paintMoveNotice(); ui.input.focus({ preventScroll: true }); };
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
async function runMoveAction(notice, action) {
|
|
1535
|
+
state.moveBusy = { ...notice, chatId: notice.chatId ?? state.chat?.chatId ?? null, busyText: action.label === 'Try again' ? 'Trying again…' : 'One moment…' };
|
|
1536
|
+
paintMoveNotice();
|
|
1537
|
+
try { await action.run(); }
|
|
1538
|
+
catch (error) { report(error, 'Could not do that'); }
|
|
1539
|
+
finally {
|
|
1540
|
+
state.moveBusy = null;
|
|
1541
|
+
if (state.moveNotice === notice) state.moveNotice = null;
|
|
1542
|
+
paintMoveNotice();
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
async function retryConversationMove(chatId) {
|
|
1547
|
+
const snapshot = captureChat();
|
|
1548
|
+
const result = await request(`/api/chat/conversations/${encodeURIComponent(chatId)}/move/retry`, {
|
|
1549
|
+
method: 'POST', body: JSON.stringify({ owner: { kind: 'workspace' } }),
|
|
1550
|
+
});
|
|
1551
|
+
if (result?.outcome !== 'moved' && snapshot && sameChat(snapshot)) await refreshConversation(chatId, false);
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
async function keepConversationHere(chatId) {
|
|
1555
|
+
await request(`/api/chat/conversations/${encodeURIComponent(chatId)}/move/keep`, {
|
|
1556
|
+
method: 'POST', body: JSON.stringify({ owner: { kind: 'workspace' } }),
|
|
1557
|
+
});
|
|
1558
|
+
await refreshConversation(chatId, false);
|
|
1559
|
+
announce('This conversation stays in the workspace.');
|
|
1560
|
+
ui.input.focus({ preventScroll: true });
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1279
1563
|
function appendUnreadableChats(entries, destination) {
|
|
1280
1564
|
const group = document.createElement('section'); group.className = 'ai-chat-history-group ai-chat-history-unreadable';
|
|
1281
1565
|
group.setAttribute('aria-label', 'Conversations that can’t be opened');
|
|
@@ -1905,6 +2189,427 @@
|
|
|
1905
2189
|
return item;
|
|
1906
2190
|
}
|
|
1907
2191
|
|
|
2192
|
+
// #1907: the plain name of one of the person's connectors — the same rule the server words its cards with.
|
|
2193
|
+
function connectorLabel(connector) {
|
|
2194
|
+
// A Claude.ai connector is named "claude.ai <Name>"; the prefix names the channel, not the connector.
|
|
2195
|
+
const raw = String(connector?.app || connector?.server || 'A connector').replace(/^claude[._ ]ai[_ ]/i, '');
|
|
2196
|
+
return raw.replace(/[_-]+/g, ' ').replace(/\b\w/g, (letter) => letter.toUpperCase()).slice(0, 80);
|
|
2197
|
+
}
|
|
2198
|
+
|
|
2199
|
+
function connectorKey(connector) {
|
|
2200
|
+
return `${connector.provider}:${connector.server}:${connector.app || ''}`;
|
|
2201
|
+
}
|
|
2202
|
+
|
|
2203
|
+
function renderConnectorReceipt(event) {
|
|
2204
|
+
const item = document.createElement('div');
|
|
2205
|
+
item.className = 'ai-chat-event connector';
|
|
2206
|
+
item.dataset.eventSequence = String(event.sequence);
|
|
2207
|
+
item.dataset.eventId = event.eventId;
|
|
2208
|
+
const label = document.createElement('strong');
|
|
2209
|
+
label.textContent = 'Allowed for this chat';
|
|
2210
|
+
const connector = event.payload.connector;
|
|
2211
|
+
const tool = typeof connector.tool === 'string' ? connector.tool : 'a tool';
|
|
2212
|
+
item.append(label, document.createTextNode(` · ${connectorLabel(connector)} ran ${tool}`));
|
|
2213
|
+
return item;
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2216
|
+
/** A refusal FloLess wrote for the person (`plain`), shown as is: what happened, why, and what to do next. */
|
|
2217
|
+
function renderPlainNotice(event) {
|
|
2218
|
+
const item = document.createElement('div');
|
|
2219
|
+
item.className = 'ai-chat-event error';
|
|
2220
|
+
item.dataset.eventSequence = String(event.sequence);
|
|
2221
|
+
item.dataset.eventId = event.eventId;
|
|
2222
|
+
const label = document.createElement('strong');
|
|
2223
|
+
label.textContent = 'Not done';
|
|
2224
|
+
item.append(label, document.createTextNode(` · ${event.payload.message}`));
|
|
2225
|
+
return item;
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
/** #2007: the first line of an agent run — who started it and the scope it was given. Information, not a refusal. */
|
|
2229
|
+
function renderAgentRunLine(event) {
|
|
2230
|
+
const item = document.createElement('div');
|
|
2231
|
+
item.className = 'ai-chat-event connector agent-run';
|
|
2232
|
+
item.dataset.eventSequence = String(event.sequence);
|
|
2233
|
+
item.dataset.eventId = event.eventId;
|
|
2234
|
+
const label = document.createElement('strong');
|
|
2235
|
+
label.textContent = 'Agent run';
|
|
2236
|
+
item.append(label, document.createTextNode(` · ${String(event.payload.message || '')}`));
|
|
2237
|
+
return item;
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2240
|
+
function renderChangeReceipt(event) {
|
|
2241
|
+
const item = document.createElement('div');
|
|
2242
|
+
item.className = 'ai-chat-event connector';
|
|
2243
|
+
item.dataset.eventSequence = String(event.sequence);
|
|
2244
|
+
item.dataset.eventId = event.eventId;
|
|
2245
|
+
const change = event.payload.change;
|
|
2246
|
+
const label = document.createElement('strong');
|
|
2247
|
+
if (event.payload.reason) {
|
|
2248
|
+
label.textContent = 'Not changed';
|
|
2249
|
+
item.append(label, document.createTextNode(' · FloLess could not confirm this change could still go ahead. Ask the AI to check the current files and scope, then try again.'));
|
|
2250
|
+
return item;
|
|
2251
|
+
}
|
|
2252
|
+
label.textContent = event.payload.coveredBy === 'create' ? 'Part of creating the workflow' : 'Allowed for this chat';
|
|
2253
|
+
// The receipt records the approval FloLess gave; whether the file was then written is the AI's own reply to report.
|
|
2254
|
+
const owners = Array.isArray(change?.owners) ? change.owners : [];
|
|
2255
|
+
const paths = owners.flatMap((owner) => owner.paths || []);
|
|
2256
|
+
const detail = paths.length === 1 ? `Approved a change to ${paths[0]}`
|
|
2257
|
+
: owners.length === 1 ? `Approved changes to ${paths.length} files in ${owners[0].label}` : `Approved changes to ${paths.length} files in ${changeNames(change)}`;
|
|
2258
|
+
item.append(label, document.createTextNode(` · ${detail}`));
|
|
2259
|
+
return item;
|
|
2260
|
+
}
|
|
2261
|
+
|
|
2262
|
+
/*
|
|
2263
|
+
* #1900 — the AI suggests connecting something to FloLess. The card never connects anything: every button is the
|
|
2264
|
+
* person's own act on a part A surface (Check it works, or Integrations). It shows what is connected NOW, read live
|
|
2265
|
+
* from /api/connections/services when painted and again when the person comes back to it, never the state the AI saw.
|
|
2266
|
+
* The feed repaints on every streamed word, so each card is painted once per state and reused: a check in progress,
|
|
2267
|
+
* its inline question and its result all live in the card itself and survive the repaint.
|
|
2268
|
+
*/
|
|
2269
|
+
const connectionCards = new Map();
|
|
2270
|
+
const CONNECTION_CARDS_KEPT = 200;
|
|
2271
|
+
const connectionLive = { services: null, loading: false, loadedAt: 0, error: '' };
|
|
2272
|
+
const connectionsApi = () => window.flolessConnections || null;
|
|
2273
|
+
|
|
2274
|
+
/** Re-reads what is connected (and the latest checks) when the copy on screen is older than `maxAgeMs`. */
|
|
2275
|
+
function refreshConnectionLive(maxAgeMs = 15000) {
|
|
2276
|
+
const api = connectionsApi();
|
|
2277
|
+
if (!api || connectionLive.loading) return;
|
|
2278
|
+
if (connectionLive.loadedAt && Date.now() - connectionLive.loadedAt < maxAgeMs) return;
|
|
2279
|
+
connectionLive.loading = true;
|
|
2280
|
+
Promise.all([api.loadServices(), api.loadReceipts()])
|
|
2281
|
+
.then(([services]) => { connectionLive.services = services; connectionLive.error = ''; })
|
|
2282
|
+
.catch((error) => { connectionLive.error = api.sentenceOf(error); })
|
|
2283
|
+
.finally(() => { connectionLive.loading = false; connectionLive.loadedAt = Date.now(); repaintConnectionCards(); });
|
|
2284
|
+
}
|
|
2285
|
+
|
|
2286
|
+
function repaintConnectionCards() {
|
|
2287
|
+
for (const old of ui.feed?.querySelectorAll('.ai-chat-connection-card[data-proposal-id]') || []) {
|
|
2288
|
+
const event = state.events.find((known) => known.eventId === old.dataset.eventId);
|
|
2289
|
+
if (!event) continue;
|
|
2290
|
+
const next = renderConnectionProposal(event);
|
|
2291
|
+
if (next !== old) {
|
|
2292
|
+
const focused = old.contains(document.activeElement) ? document.activeElement.dataset.commandId : null;
|
|
2293
|
+
old.replaceWith(next);
|
|
2294
|
+
if (focused) [...next.querySelectorAll('[data-command-id]')].find((node) => node.dataset.commandId === focused && !node.disabled)?.focus({ preventScroll: true });
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
|
|
2299
|
+
window.addEventListener('focus', () => { if (ui.feed?.querySelector('.ai-chat-connection-card[data-proposal-id]')) refreshConnectionLive(0); });
|
|
2300
|
+
|
|
2301
|
+
/**
|
|
2302
|
+
* Did the person answer Not now to this target? Dismissal is per target. The newest Not now / Show again in the
|
|
2303
|
+
* transcript decides; with none loaded, the conversation record's own list does.
|
|
2304
|
+
*/
|
|
2305
|
+
function connectionDismissed(target) {
|
|
2306
|
+
let latest = null;
|
|
2307
|
+
for (const event of state.events) {
|
|
2308
|
+
if (event.type === 'connection-proposal-update' && event.payload?.target === target) latest = event;
|
|
2309
|
+
}
|
|
2310
|
+
if (latest) return latest.payload.dismissed === true;
|
|
2311
|
+
return Array.isArray(state.chat?.connectionDismissals) && state.chat.connectionDismissals.some((row) => row.target === target);
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
function renderConnectionProposal(event) {
|
|
2315
|
+
const payload = event.payload || {};
|
|
2316
|
+
const proposalId = String(payload.proposalId || event.eventId || '');
|
|
2317
|
+
refreshConnectionLive();
|
|
2318
|
+
let entry = connectionCards.get(proposalId);
|
|
2319
|
+
if (!entry) {
|
|
2320
|
+
entry = { node: null, signature: '', error: '', said: '', busy: false };
|
|
2321
|
+
connectionCards.set(proposalId, entry);
|
|
2322
|
+
while (connectionCards.size > CONNECTION_CARDS_KEPT) connectionCards.delete(connectionCards.keys().next().value);
|
|
2323
|
+
}
|
|
2324
|
+
const dismissed = connectionDismissed(payload.target);
|
|
2325
|
+
const services = connectionLive.services;
|
|
2326
|
+
const service = payload.targetKind === 'host' || !services ? null : services.find((row) => row.id === payload.target) || null;
|
|
2327
|
+
const alias = payload.targetKind === 'host' ? null : service?.choice?.source === 'floless' ? (service.choice.alias ?? null) : undefined;
|
|
2328
|
+
const receipt = payload.checkAgent && alias !== undefined ? connectionsApi()?.cachedReceipt(payload.checkAgent, alias) : null;
|
|
2329
|
+
const signature = JSON.stringify([event.eventId, dismissed, service, Boolean(services?.choicesUnreadable), Boolean(services),
|
|
2330
|
+
connectionLive.error, receipt?.probedAt || null, receipt?.state || null, entry.error, entry.busy]);
|
|
2331
|
+
if (entry.node && entry.signature === signature) return entry.node;
|
|
2332
|
+
// A check running, or its inline question open, lives in this node: keep it until it settles.
|
|
2333
|
+
if (entry.node && entry.node.querySelector('[aria-busy="true"], [aria-expanded="true"]')) return entry.node;
|
|
2334
|
+
entry.node = paintConnectionProposal(event, payload, proposalId, entry, { dismissed, service, alias });
|
|
2335
|
+
entry.signature = signature;
|
|
2336
|
+
return entry.node;
|
|
2337
|
+
}
|
|
2338
|
+
|
|
2339
|
+
function connectionButton(label, commandId, target, name, className = '') {
|
|
2340
|
+
const control = button(label, `${commandId}#${target}`, className);
|
|
2341
|
+
control.dataset.commandInstanceLabel = name;
|
|
2342
|
+
return control;
|
|
2343
|
+
}
|
|
2344
|
+
|
|
2345
|
+
function paintConnectionProposal(event, payload, proposalId, entry, { dismissed, service, alias }) {
|
|
2346
|
+
const api = connectionsApi();
|
|
2347
|
+
const target = String(payload.target || '');
|
|
2348
|
+
const name = String(payload.name || target || 'this');
|
|
2349
|
+
const card = document.createElement('section');
|
|
2350
|
+
card.className = 'ai-chat-filter-card ai-chat-connection-card';
|
|
2351
|
+
card.dataset.eventId = event.eventId;
|
|
2352
|
+
card.dataset.eventSequence = String(event.sequence);
|
|
2353
|
+
card.dataset.proposalId = proposalId;
|
|
2354
|
+
card.dataset.target = target;
|
|
2355
|
+
// Coming back to the card (after Integrations, say) reads what is connected again.
|
|
2356
|
+
card.addEventListener('focusin', () => refreshConnectionLive(3000));
|
|
2357
|
+
card.addEventListener('pointerenter', () => refreshConnectionLive(3000));
|
|
2358
|
+
const error = document.createElement('p');
|
|
2359
|
+
error.className = 'ai-chat-filter-note ai-chat-connection-error';
|
|
2360
|
+
error.setAttribute('role', 'status');
|
|
2361
|
+
error.textContent = entry.error;
|
|
2362
|
+
if (dismissed) {
|
|
2363
|
+
card.classList.add('is-dismissed');
|
|
2364
|
+
card.setAttribute('aria-label', `Suggestion to connect ${name}, set aside`);
|
|
2365
|
+
const line = document.createElement('div');
|
|
2366
|
+
line.className = 'ai-chat-connection-collapsed';
|
|
2367
|
+
const text = document.createElement('span');
|
|
2368
|
+
text.textContent = 'Not now — you can ask again any time';
|
|
2369
|
+
const again = connectionButton('Show again', 'shell.chat-connection-show-again', target, name);
|
|
2370
|
+
again.setAttribute('aria-label', `Show the suggestion to connect ${name} again`);
|
|
2371
|
+
again.dataset.tip = `Shows this card again, so you can connect ${name} or check it.`;
|
|
2372
|
+
again.disabled = entry.busy;
|
|
2373
|
+
again.addEventListener('click', () => { void setConnectionDismissed(event, false); });
|
|
2374
|
+
line.append(text, again);
|
|
2375
|
+
card.append(line, error);
|
|
2376
|
+
return card;
|
|
2377
|
+
}
|
|
2378
|
+
const head = document.createElement('div'); head.className = 'ai-chat-filter-card-head';
|
|
2379
|
+
const title = document.createElement('strong');
|
|
2380
|
+
title.id = `chat-connection-title-${proposalId}`;
|
|
2381
|
+
title.textContent = `Would you like me to connect ${name} to FloLess?`;
|
|
2382
|
+
card.setAttribute('aria-labelledby', title.id);
|
|
2383
|
+
head.append(title);
|
|
2384
|
+
card.append(head);
|
|
2385
|
+
// The AI's own words: plain text only.
|
|
2386
|
+
const why = typeof payload.why === 'string' ? payload.why.trim() : '';
|
|
2387
|
+
if (why) {
|
|
2388
|
+
const reason = document.createElement('p'); reason.className = 'ai-chat-filter-why';
|
|
2389
|
+
reason.textContent = why;
|
|
2390
|
+
card.append(reason);
|
|
2391
|
+
}
|
|
2392
|
+
const stateLine = document.createElement('p'); stateLine.className = 'ai-chat-filter-note ai-chat-connection-state';
|
|
2393
|
+
const actions = document.createElement('div'); actions.className = 'ai-chat-filter-actions';
|
|
2394
|
+
const confirmHost = document.createElement('div'); confirmHost.className = 'conn-confirm-host';
|
|
2395
|
+
const receiptHost = document.createElement('div'); receiptHost.className = 'conn-receipt-host';
|
|
2396
|
+
receiptHost.setAttribute('role', 'status');
|
|
2397
|
+
const said = document.createElement('p'); said.className = 'ai-chat-filter-note ai-chat-connection-said';
|
|
2398
|
+
said.setAttribute('role', 'status');
|
|
2399
|
+
said.textContent = entry.said;
|
|
2400
|
+
const say = (text) => { entry.said = text; said.textContent = text; };
|
|
2401
|
+
const integrations = (label, commandId, tip, primary = false) => {
|
|
2402
|
+
const control = connectionButton(label, commandId, target, name, primary ? 'ai-chat-filter-apply' : '');
|
|
2403
|
+
control.setAttribute('aria-label', `${label}: open Integrations at ${name}`);
|
|
2404
|
+
control.dataset.tip = tip;
|
|
2405
|
+
control.addEventListener('click', () => {
|
|
2406
|
+
if (typeof window.openIntegrations === 'function') window.openIntegrations(target);
|
|
2407
|
+
else say('FloLess couldn’t open Integrations. Open it from the menu, then find ' + name + '.');
|
|
2408
|
+
});
|
|
2409
|
+
return control;
|
|
2410
|
+
};
|
|
2411
|
+
const check = (checkAlias, pinned) => {
|
|
2412
|
+
const control = api.checkButton({ commandId: 'shell.chat-connection-check', agent: payload.checkAgent, alias: checkAlias, label: name, receiptHost, confirmHost, announce: say,
|
|
2413
|
+
onReceipt: () => repaintConnectionCards(), ...pinned });
|
|
2414
|
+
control.classList.add('ai-chat-filter-apply');
|
|
2415
|
+
const latest = api.cachedReceipt(payload.checkAgent, checkAlias);
|
|
2416
|
+
if (latest) receiptHost.replaceChildren(api.receiptNode(latest));
|
|
2417
|
+
return control;
|
|
2418
|
+
};
|
|
2419
|
+
const services = connectionLive.services;
|
|
2420
|
+
let keyCode = null;
|
|
2421
|
+
if (payload.targetKind === 'host') {
|
|
2422
|
+
if (payload.checkAgent && api) {
|
|
2423
|
+
actions.append(check(null, {}));
|
|
2424
|
+
stateLine.textContent = receiptHost.childElementCount ? `The last check of ${name} is below.` : `${name} has not been checked yet. Check it works runs a read-only check on this computer.`;
|
|
2425
|
+
} else {
|
|
2426
|
+
stateLine.textContent = `FloLess can’t check ${name} from here. Open Discover Local Tools to connect it.`;
|
|
2427
|
+
}
|
|
2428
|
+
} else if (!api || (!services && connectionLive.error)) {
|
|
2429
|
+
stateLine.textContent = connectionLive.error || 'FloLess couldn’t load what is connected. Try again.';
|
|
2430
|
+
const retry = connectionButton('Try again', 'shell.chat-connection-retry', target, name);
|
|
2431
|
+
retry.dataset.tip = 'Reads again what is connected to FloLess.';
|
|
2432
|
+
retry.addEventListener('click', () => refreshConnectionLive(0));
|
|
2433
|
+
if (api) actions.append(retry);
|
|
2434
|
+
} else if (!services) {
|
|
2435
|
+
stateLine.textContent = 'Checking what is connected…';
|
|
2436
|
+
} else if (!service) {
|
|
2437
|
+
stateLine.textContent = `FloLess can’t find ${name} in its connections right now. Open Integrations to see what is connected.`;
|
|
2438
|
+
actions.append(integrations('Open Integrations', 'shell.chat-connection-connect', `Opens Integrations at ${name}.`, true));
|
|
2439
|
+
} else if (service.statusUnknown) {
|
|
2440
|
+
stateLine.textContent = `FloLess couldn’t read whether the key for ${name} is saved. Open Integrations to see it.`;
|
|
2441
|
+
actions.append(integrations('Open Integrations', 'shell.chat-connection-connect', `Opens Integrations at ${name}.`, true));
|
|
2442
|
+
} else if (service.kind === 'key' && !service.connected) {
|
|
2443
|
+
// A key is added in a terminal, never typed into FloLess: the command, and a button that copies it.
|
|
2444
|
+
const command = `aware credential put ${service.id}`;
|
|
2445
|
+
stateLine.textContent = `${name} needs a key from the service. Run this in a terminal, then paste your key when it asks:`;
|
|
2446
|
+
keyCode = document.createElement('code'); keyCode.className = 'conn-code ai-chat-connection-command';
|
|
2447
|
+
keyCode.textContent = command;
|
|
2448
|
+
const copyLabel = 'Copy the command';
|
|
2449
|
+
const copy = connectionButton(copyLabel, 'shell.chat-connection-copy-key', target, name, 'ai-chat-filter-apply');
|
|
2450
|
+
copy.setAttribute('aria-label', `Copy the command that adds your key for ${name}`);
|
|
2451
|
+
copy.dataset.tip = 'Copies the terminal command. FloLess never sees the key you paste.';
|
|
2452
|
+
copy.addEventListener('click', async () => {
|
|
2453
|
+
try {
|
|
2454
|
+
await navigator.clipboard.writeText(command);
|
|
2455
|
+
say('Command copied. Run it in a terminal, then paste your key when it asks.');
|
|
2456
|
+
} catch { say('FloLess couldn’t copy the command. Select it and copy it yourself.'); }
|
|
2457
|
+
});
|
|
2458
|
+
actions.append(copy);
|
|
2459
|
+
} else if (!services.choicesUnreadable && service.choice?.source === 'native') {
|
|
2460
|
+
// Their own Claude/Codex connection is the choice, whatever FloLess's own accounts look like (#1900 review): the
|
|
2461
|
+
// way out is Change account, never Connect or Reconnect of an account FloLess was told not to use.
|
|
2462
|
+
stateLine.textContent = `FloLess uses your Claude or Codex connection for ${name}. FloLess can’t see or check that connection.`;
|
|
2463
|
+
actions.append(integrations('Change account', 'shell.chat-connection-change-account', `Opens Integrations at ${name}, where you choose the account FloLess uses.`));
|
|
2464
|
+
} else if (api.signInExpired(service)) {
|
|
2465
|
+
stateLine.textContent = `The sign-in for ${name} expired. Reconnect it in Integrations, then check it works.`;
|
|
2466
|
+
actions.append(integrations('Reconnect', 'shell.chat-connection-connect', `Opens Integrations at ${name} so you can sign in again.`, true));
|
|
2467
|
+
} else if (!service.connected) {
|
|
2468
|
+
stateLine.textContent = `${name} is not connected yet. Connect opens Integrations, where you sign in.`;
|
|
2469
|
+
actions.append(integrations('Connect', 'shell.chat-connection-connect', `Opens Integrations at ${name} so you can connect it.`, true));
|
|
2470
|
+
} else if (services.choicesUnreadable) {
|
|
2471
|
+
stateLine.textContent = `FloLess couldn’t read which account it uses for ${name}. Open Integrations to choose it again.`;
|
|
2472
|
+
actions.append(integrations('Open Integrations', 'shell.chat-connection-change-account', `Opens Integrations at ${name}.`, true));
|
|
2473
|
+
} else if (service.choice?.source === 'floless') {
|
|
2474
|
+
stateLine.textContent = `FloLess uses ${service.choice.alias ? service.choice.alias : 'the default account'} for ${name}.`;
|
|
2475
|
+
// The card checks the CHOSEN account at the choice it was painted on: the server refuses a card that is out of date.
|
|
2476
|
+
if (payload.checkAgent && alias !== undefined) {
|
|
2477
|
+
actions.append(check(alias, { integration: target, expectedChoiceRevision: service.choice.revision }));
|
|
2478
|
+
}
|
|
2479
|
+
actions.append(integrations('Change account', 'shell.chat-connection-change-account', `Opens Integrations at ${name}, where you choose the account FloLess uses.`));
|
|
2480
|
+
} else {
|
|
2481
|
+
const count = (service.accounts || []).length;
|
|
2482
|
+
stateLine.textContent = `${count === 1 ? 'An account is' : `${count} accounts are`} already connected for ${name}, but FloLess hasn’t been told which one to use. Integrations is where you choose it.`;
|
|
2483
|
+
actions.append(
|
|
2484
|
+
integrations('Use existing connection', 'shell.chat-connection-use-existing', `Opens Integrations at ${name}, where you choose the account FloLess uses.`, true),
|
|
2485
|
+
integrations('Set up a separate connection', 'shell.chat-connection-set-up-separate', `Opens Integrations at ${name}, where you can connect another account for FloLess.`),
|
|
2486
|
+
);
|
|
2487
|
+
}
|
|
2488
|
+
const notNow = connectionButton('Not now', 'shell.chat-connection-not-now', target, name);
|
|
2489
|
+
notNow.setAttribute('aria-label', `Not now: don’t connect ${name}`);
|
|
2490
|
+
notNow.dataset.tip = `Sets this suggestion aside. The AI won’t suggest ${name} again in this chat unless you choose Show again.`;
|
|
2491
|
+
notNow.disabled = entry.busy;
|
|
2492
|
+
notNow.addEventListener('click', () => { void setConnectionDismissed(event, true); });
|
|
2493
|
+
actions.append(notNow);
|
|
2494
|
+
card.append(stateLine, ...(keyCode ? [keyCode] : []), actions, confirmHost, receiptHost, said, error);
|
|
2495
|
+
return card;
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2498
|
+
async function setConnectionDismissed(event, dismiss) {
|
|
2499
|
+
const payload = event.payload || {};
|
|
2500
|
+
const proposalId = String(payload.proposalId || '');
|
|
2501
|
+
const entry = connectionCards.get(proposalId);
|
|
2502
|
+
const snapshot = captureChat();
|
|
2503
|
+
if (!snapshot || !entry || entry.busy || !proposalId) return;
|
|
2504
|
+
const name = String(payload.name || payload.target || 'this');
|
|
2505
|
+
entry.busy = true; entry.error = '';
|
|
2506
|
+
repaintConnectionCards();
|
|
2507
|
+
try {
|
|
2508
|
+
const result = await request(`/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/connection-proposals/${encodeURIComponent(proposalId)}/${dismiss ? 'dismiss' : 'undismiss'}`, {
|
|
2509
|
+
method: 'POST', body: JSON.stringify({ owner: snapshot.scope.owner }),
|
|
2510
|
+
});
|
|
2511
|
+
if (!sameChat(snapshot)) return;
|
|
2512
|
+
if (result?.chat?.chatId === snapshot.chatId) state.chat = { ...state.chat, connectionDismissals: result.chat.connectionDismissals ?? [] };
|
|
2513
|
+
if (result?.event && !state.events.some((known) => known.eventId === result.event.eventId)) state.events.push(result.event);
|
|
2514
|
+
announce(dismiss ? `Not now. The AI won’t suggest connecting ${name} again in this chat unless you choose Show again.`
|
|
2515
|
+
: `The suggestion to connect ${name} is back.`);
|
|
2516
|
+
} catch (error) {
|
|
2517
|
+
if (sameChat(snapshot)) entry.error = errorMessage(error);
|
|
2518
|
+
} finally {
|
|
2519
|
+
entry.busy = false;
|
|
2520
|
+
if (sameChat(snapshot)) {
|
|
2521
|
+
repaintConnectionCards();
|
|
2522
|
+
// The pressed button is gone with the card's old face: keep the keyboard on this card.
|
|
2523
|
+
const card = ui.feed?.querySelector(`.ai-chat-connection-card[data-proposal-id="${CSS.escape(proposalId)}"]`);
|
|
2524
|
+
const next = card?.querySelector(entry.error ? 'button' : dismiss ? '[data-command-id^="shell.chat-connection-show-again"]' : '.ai-chat-filter-actions button');
|
|
2525
|
+
next?.focus({ preventScroll: true });
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
|
|
2530
|
+
/** The result of a check the person approved in chat: the same receipt Discover and Integrations show. */
|
|
2531
|
+
function renderConnectionCheck(event) {
|
|
2532
|
+
const payload = event.payload || {};
|
|
2533
|
+
const api = connectionsApi();
|
|
2534
|
+
const name = String(payload.name || payload.agent || 'this tool');
|
|
2535
|
+
const card = document.createElement('section');
|
|
2536
|
+
card.className = 'ai-chat-filter-card ai-chat-connection-card ai-chat-connection-receipt';
|
|
2537
|
+
card.dataset.eventId = event.eventId;
|
|
2538
|
+
card.dataset.eventSequence = String(event.sequence);
|
|
2539
|
+
const head = document.createElement('div'); head.className = 'ai-chat-filter-card-head';
|
|
2540
|
+
const title = document.createElement('strong');
|
|
2541
|
+
title.id = `chat-connection-check-${event.eventId}`;
|
|
2542
|
+
title.textContent = `Connection check · ${name}`;
|
|
2543
|
+
card.setAttribute('aria-labelledby', title.id);
|
|
2544
|
+
head.append(title);
|
|
2545
|
+
card.append(head);
|
|
2546
|
+
const receipt = payload.receipt && typeof payload.receipt === 'object' ? payload.receipt : null;
|
|
2547
|
+
const identity = receipt?.reported?.identity || 'a different account';
|
|
2548
|
+
if (receipt && api) {
|
|
2549
|
+
// The transcript is a record: a check reads "Checked · when", never "Verified". Whether it still holds is shown
|
|
2550
|
+
// live on the suggestion card, Discover and Integrations (#1900 review, owner ruling: history only).
|
|
2551
|
+
const shown = { ...receipt, historical: true };
|
|
2552
|
+
// A changed account gets its own line below, worded for this moment, instead of the receipt's general one.
|
|
2553
|
+
card.append(api.receiptNode(payload.changedTarget ? { ...shown, previousIdentity: null } : shown,
|
|
2554
|
+
payload.ok ? null : (typeof payload.error === 'string' && payload.error) || null));
|
|
2555
|
+
}
|
|
2556
|
+
if (payload.changedTarget) {
|
|
2557
|
+
const changed = document.createElement('p');
|
|
2558
|
+
changed.className = 'ai-chat-filter-note ai-chat-approval-warning';
|
|
2559
|
+
changed.textContent = `The account behind ${name} is now ${identity}, not ${payload.previousIdentity || 'the one checked before'}. Nothing else was read.`;
|
|
2560
|
+
card.append(changed);
|
|
2561
|
+
}
|
|
2562
|
+
if (payload.restarted) {
|
|
2563
|
+
const restarted = document.createElement('p');
|
|
2564
|
+
restarted.className = 'ai-chat-filter-note';
|
|
2565
|
+
restarted.textContent = 'The program was restarted since the last check.';
|
|
2566
|
+
card.append(restarted);
|
|
2567
|
+
}
|
|
2568
|
+
if (!payload.ok && !(receipt && api)) {
|
|
2569
|
+
const failed = document.createElement('p');
|
|
2570
|
+
// A check that was stopped is not a failed one (#1900): its outcome is unknown, said plainly, not in error red.
|
|
2571
|
+
failed.className = payload.stopped === true ? 'ai-chat-filter-note' : 'ai-chat-filter-note ai-chat-connection-error';
|
|
2572
|
+
failed.textContent = (typeof payload.error === 'string' && payload.error) || `The check of ${name} did not succeed. Ask the AI to try again.`;
|
|
2573
|
+
card.append(failed);
|
|
2574
|
+
}
|
|
2575
|
+
return card;
|
|
2576
|
+
}
|
|
2577
|
+
|
|
2578
|
+
/** A check that ran under "Allow checks … for this chat": one line, like a connector's receipt. */
|
|
2579
|
+
function renderConnectionCheckAllowed(event) {
|
|
2580
|
+
const item = document.createElement('div');
|
|
2581
|
+
item.className = 'ai-chat-event connector';
|
|
2582
|
+
item.dataset.eventSequence = String(event.sequence);
|
|
2583
|
+
item.dataset.eventId = event.eventId;
|
|
2584
|
+
const label = document.createElement('strong');
|
|
2585
|
+
label.textContent = 'Allowed for this chat';
|
|
2586
|
+
const name = String(event.payload.connectionCheck?.name || event.payload.connectionCheck?.agent || 'a connection');
|
|
2587
|
+
item.append(label, document.createTextNode(` · checked ${name}`));
|
|
2588
|
+
return item;
|
|
2589
|
+
}
|
|
2590
|
+
|
|
2591
|
+
/** One line for a decided workflow create (#1890 PR 3a): approved, denied, or stopped at FloLess's last check. */
|
|
2592
|
+
function renderCreateReceipt(event) {
|
|
2593
|
+
const item = document.createElement('div');
|
|
2594
|
+
item.className = 'ai-chat-event connector';
|
|
2595
|
+
item.dataset.eventSequence = String(event.sequence);
|
|
2596
|
+
item.dataset.eventId = event.eventId;
|
|
2597
|
+
const create = event.payload.create;
|
|
2598
|
+
const label = document.createElement('strong');
|
|
2599
|
+
const what = `the workflow “${create.name}” ${createWhere(create)}`;
|
|
2600
|
+
if (event.payload.reason) {
|
|
2601
|
+
label.textContent = 'Not created';
|
|
2602
|
+
item.append(label, document.createTextNode(` · ${event.payload.reason}`));
|
|
2603
|
+
} else if (event.payload.decision === 'allow') {
|
|
2604
|
+
label.textContent = 'Approved once';
|
|
2605
|
+
item.append(label, document.createTextNode(` · Create ${what}`));
|
|
2606
|
+
} else {
|
|
2607
|
+
label.textContent = 'Not created';
|
|
2608
|
+
item.append(label, document.createTextNode(` · ${what}`));
|
|
2609
|
+
}
|
|
2610
|
+
return item;
|
|
2611
|
+
}
|
|
2612
|
+
|
|
1908
2613
|
function renderEvent(event) {
|
|
1909
2614
|
if (event.type === 'user-message' && event.payload?.source === 'request' && event.payload?.filterAi) return renderFilterQuestion(event);
|
|
1910
2615
|
if (event.type === 'user-message' && event.payload?.source === 'request') return renderRequestCard(event);
|
|
@@ -1912,8 +2617,20 @@
|
|
|
1912
2617
|
if (event.type === 'user-message') return withFilterNotShared(renderMessage(event, 'user', payloadText(event)), event);
|
|
1913
2618
|
if (event.type === 'filter-proposal') return renderServerProposal(event);
|
|
1914
2619
|
if (event.type === 'filter-proposal-update') return null;
|
|
2620
|
+
// #1900: a connection the AI suggested, the result of a check it asked for, and a check run under "Allow for this chat".
|
|
2621
|
+
if (event.type === 'connection-proposal') return renderConnectionProposal(event);
|
|
2622
|
+
if (event.type === 'connection-proposal-update') return null;
|
|
2623
|
+
if (event.type === 'connection-check') return renderConnectionCheck(event);
|
|
2624
|
+
if (event.type === 'approval-decided' && event.payload?.automatic === true && event.payload?.connectionCheck) return renderConnectionCheckAllowed(event);
|
|
1915
2625
|
if (event.type === 'assistant-message') return renderMessage(event, 'assistant', payloadText(event), Boolean(event.payload?.delta));
|
|
2626
|
+
// #1907: a connector call that ran under "Allow for this chat" leaves a visible receipt; every other decision is audit only.
|
|
2627
|
+
if (event.type === 'approval-decided' && event.payload?.automatic === true && event.payload?.connector) return renderConnectorReceipt(event);
|
|
2628
|
+
// #1890 PR 2b: a workspace change that ran under "Allow for this chat", or one FloLess stopped at the last check.
|
|
2629
|
+
if (event.type === 'approval-decided' && event.payload?.change && (event.payload?.automatic === true || event.payload?.reason)) return renderChangeReceipt(event);
|
|
2630
|
+
// #1890 PR 3a: a decided workflow create stays visible as one line, so a reload never shows it as pending.
|
|
2631
|
+
if (event.type === 'approval-decided' && event.payload?.create) return renderCreateReceipt(event);
|
|
1916
2632
|
if (event.type === 'approval-requested' || event.type === 'approval-decided' || event.type === 'state' || event.type === 'followup-status') return null;
|
|
2633
|
+
if (event.type === 'tool' && event.payload?.tool === 'agent' && typeof event.payload?.message === 'string') return renderAgentRunLine(event);
|
|
1917
2634
|
if (event.type === 'tekla-read') return renderTeklaReadEvent(event);
|
|
1918
2635
|
if (event.type === 'height-question') return renderHeightQuestion(event);
|
|
1919
2636
|
if (event.type === 'setup-question') return renderSetupQuestion(event);
|
|
@@ -1949,7 +2666,10 @@
|
|
|
1949
2666
|
return item;
|
|
1950
2667
|
}
|
|
1951
2668
|
label.textContent = event.type === 'error' && payload.outcome === 'not-sent' ? 'Not sent' : labels[event.type] || event.type;
|
|
1952
|
-
|
|
2669
|
+
// #1907: a not-sent reason the server wrote for the person (`plain`) is shown as is.
|
|
2670
|
+
let detail = event.type === 'error'
|
|
2671
|
+
? (payload.plain === true && typeof payload.message === 'string' && payload.message ? payload.message : errorMessage(payloadText(event)))
|
|
2672
|
+
: payloadText(event);
|
|
1953
2673
|
if (!detail && event.type === 'tool') {
|
|
1954
2674
|
const toolLabels = { provider: 'AI provider', integration: 'Connected service', attachment: 'Attachment', knowledge: 'Knowledge', filesystem: 'Project files' };
|
|
1955
2675
|
const statusLabels = { started: 'started', completed: 'completed', failed: 'failed', denied: 'not allowed' };
|
|
@@ -2015,6 +2735,22 @@
|
|
|
2015
2735
|
const heightEndKey = (row) => `${row.memberId}\u0000${row.end}`;
|
|
2016
2736
|
const heightEndWord = (row) => (row.endWord === 'from' ? 'start' : 'end');
|
|
2017
2737
|
const heightAnswerText = (answer) => (answer?.how === 'typed' ? `You typed ${answer.typed}` : `Confirmed ${answer?.shownAs || ''}`);
|
|
2738
|
+
/*
|
|
2739
|
+
* #1903: a row about a member ALREADY in the model. The server snapshotted that end when the question was
|
|
2740
|
+
* asked; the card says what it held THEN (the model can change before the person answers, and the review
|
|
2741
|
+
* always compares against the model as it is when the read is staged), and that the answer is only
|
|
2742
|
+
* proposed. The number is shown in the question's own units through the shared helper; until that helper
|
|
2743
|
+
* has loaded it reads in millimetres rather than not at all.
|
|
2744
|
+
*/
|
|
2745
|
+
const heightInModelValue = (mm, units) => (displayUnitsModule ? displayUnitsModule.formatElevation(mm, units) : `${Math.round(mm)} mm`);
|
|
2746
|
+
const heightInModelText = (snapshot, units) => {
|
|
2747
|
+
if (!snapshot) return '';
|
|
2748
|
+
if (snapshot.state === 'unknown' || typeof snapshot.value !== 'number') return 'In the model when asked: no height.';
|
|
2749
|
+
const value = heightInModelValue(snapshot.value, units);
|
|
2750
|
+
const tail = snapshot.state === 'assumed' ? ' (placed, not from the drawings)' : snapshot.state === 'answered' ? ' (your earlier answer)' : '';
|
|
2751
|
+
return `In the model when asked: ${value}${tail}.`;
|
|
2752
|
+
};
|
|
2753
|
+
const HEIGHT_PROPOSED_TEXT = 'Proposed in the review; the model changes only if you accept it there.';
|
|
2018
2754
|
// The server's sentence, then what to do next when it names a step (a damaged record says to discard the read).
|
|
2019
2755
|
const heightErrorText = (error, fallback) => {
|
|
2020
2756
|
const next = (error?.recovery || []).map((step) => step && typeof step.action === 'string' ? step.action : '').filter(Boolean);
|
|
@@ -2033,7 +2769,13 @@
|
|
|
2033
2769
|
if (entry.loading) return;
|
|
2034
2770
|
entry.loading = true;
|
|
2035
2771
|
request(`/api/chat/height-questions/${encodeURIComponent(entry.requestId)}/${encodeURIComponent(entry.questionId)}?${new URLSearchParams({ chatId: entry.chatId || '' })}`)
|
|
2036
|
-
.then((result) => {
|
|
2772
|
+
.then((result) => {
|
|
2773
|
+
if (result?.readClosed) { entry.finished = true; entry.view = null; } else entry.view = result.question;
|
|
2774
|
+
entry.loadError = '';
|
|
2775
|
+
// #1903: an existing member's "in the model" height is shown in the question's units, which needs
|
|
2776
|
+
// the shared helper; repaint once it has loaded.
|
|
2777
|
+
if (entry.view?.ends?.some((row) => row.inModel) && !displayUnitsModule) loadDisplayUnitsModule().then(() => repaintHeightCard(entry));
|
|
2778
|
+
})
|
|
2037
2779
|
.catch((error) => {
|
|
2038
2780
|
if (CARD_READ_FINISHED.has(error?.code)) { entry.finished = true; entry.loadError = ''; return; }
|
|
2039
2781
|
entry.loadError = heightErrorText(error, 'FloLess could not load this height question.');
|
|
@@ -2108,7 +2850,12 @@
|
|
|
2108
2850
|
note.textContent = !view
|
|
2109
2851
|
? (entry.finished ? CARD_FINISHED_TEXT : entry.loadError || 'Loading the heights this read is asking about…')
|
|
2110
2852
|
: open
|
|
2111
|
-
?
|
|
2853
|
+
? (rows.some((row) => row.inModel)
|
|
2854
|
+
// #1903: never say "straight into the model" about a member already in it — that answer is proposed.
|
|
2855
|
+
// Neutral about the drawings: an existing member's end may well be drawn, and the person is being
|
|
2856
|
+
// asked whether it still holds (code review).
|
|
2857
|
+
? 'Only you can answer these heights — the AI can’t fill this in. For a new member, what you confirm or type goes straight into the model; for one already in the model, it is proposed in the review.'
|
|
2858
|
+
: 'The drawings don’t settle these heights. Only you can answer — the AI can’t fill this in. What you confirm or type goes straight into the model.')
|
|
2112
2859
|
: 'This read is no longer waiting for an answer.';
|
|
2113
2860
|
card.append(note);
|
|
2114
2861
|
if (!view) {
|
|
@@ -2286,8 +3033,15 @@
|
|
|
2286
3033
|
label.dataset.tip = row.label;
|
|
2287
3034
|
labelLine.append(label);
|
|
2288
3035
|
const meta = document.createElement('div'); meta.className = 'ai-chat-height-meta';
|
|
2289
|
-
|
|
3036
|
+
// #1903: an existing member's PROFILE comes from the model, not from the read's label, so a label that
|
|
3037
|
+
// names the wrong member is visibly at odds with what the id really is.
|
|
3038
|
+
meta.textContent = [row.inModel?.profile, row.memberId, heightEndWord(row)].filter(Boolean).join(' · ');
|
|
2290
3039
|
item.append(labelLine, meta);
|
|
3040
|
+
if (row.inModel) {
|
|
3041
|
+
const inModel = document.createElement('div'); inModel.className = 'ai-chat-height-inmodel';
|
|
3042
|
+
inModel.textContent = `${heightInModelText(row.inModel, entry.view?.units)} ${HEIGHT_PROPOSED_TEXT}`;
|
|
3043
|
+
item.append(inModel);
|
|
3044
|
+
}
|
|
2291
3045
|
|
|
2292
3046
|
if (row.status === 'superseded') {
|
|
2293
3047
|
const gone = document.createElement('div'); gone.className = 'ai-chat-height-answered';
|
|
@@ -2424,7 +3178,21 @@
|
|
|
2424
3178
|
target?.focus({ preventScroll: true });
|
|
2425
3179
|
}
|
|
2426
3180
|
|
|
2427
|
-
|
|
3181
|
+
/*
|
|
3182
|
+
* The words the person sees for a card in "Tell the read" (#1911): its place among the cards of its own kind
|
|
3183
|
+
* actually shown in this conversation, never the ledger's running record number (`view.n`, which also counts
|
|
3184
|
+
* answers and so jumps from 1 to 13). The read does not need the number: it reads the ledger, never the
|
|
3185
|
+
* prose (#1882 plan), so the visible text carries no id at all.
|
|
3186
|
+
*/
|
|
3187
|
+
const CARD_ORDINALS = ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth'];
|
|
3188
|
+
function cardPlace(entry, attribute, noun) {
|
|
3189
|
+
const keys = [...(ui.feed?.querySelectorAll(`[${attribute}]`) || [])].map((node) => node.getAttribute(attribute));
|
|
3190
|
+
const at = keys.indexOf(entry.key);
|
|
3191
|
+
if (keys.length < 2 || at < 0) return `the ${noun}`;
|
|
3192
|
+
return at < CARD_ORDINALS.length ? `the ${CARD_ORDINALS[at]} ${noun}` : `${noun} ${at + 1} of ${keys.length}`;
|
|
3193
|
+
}
|
|
3194
|
+
const heightTellText = (entry) => `I've answered ${cardPlace(entry, 'data-height-question', 'height card')}.`;
|
|
3195
|
+
const setupTellText = (entry) => `I've answered ${cardPlace(entry, 'data-setup-question', 'read setup card')}.`;
|
|
2428
3196
|
|
|
2429
3197
|
/*
|
|
2430
3198
|
* TELL THE READ puts one short message in the composer and moves focus to Send; the PERSON sends it
|
|
@@ -2878,7 +3646,7 @@
|
|
|
2878
3646
|
: 'All answered. Press Tell the read, then Send: the read looks at what you sent and asks you to confirm its reading here.';
|
|
2879
3647
|
card.append(done);
|
|
2880
3648
|
const tell = heightActionButton('Tell the read', `shell.chat-setup-tell-read#${entry.questionId}`, questionLabel, 'ai-chat-filter-apply', null);
|
|
2881
|
-
tell.addEventListener('click', () => tellReadAnswered(entry,
|
|
3649
|
+
tell.addEventListener('click', () => tellReadAnswered(entry, setupTellText(entry), repaintSetupCard));
|
|
2882
3650
|
actions.append(tell);
|
|
2883
3651
|
}
|
|
2884
3652
|
actions.hidden = !actions.childNodes.length;
|
|
@@ -3264,7 +4032,7 @@
|
|
|
3264
4032
|
fact('Library', payload.library);
|
|
3265
4033
|
fact('Checked', checkedTime(payload.checkedAt));
|
|
3266
4034
|
card.append(facts);
|
|
3267
|
-
const note = document.createElement('p'); note.textContent = 'The generated
|
|
4035
|
+
const note = document.createElement('p'); note.textContent = 'The generated tool\'s commands remain unverified.';
|
|
3268
4036
|
card.append(note);
|
|
3269
4037
|
} else {
|
|
3270
4038
|
const message = document.createElement('p');
|
|
@@ -3712,6 +4480,8 @@
|
|
|
3712
4480
|
announceLiveResponseOnce();
|
|
3713
4481
|
const focusedCommand = ui.feed.contains(document.activeElement)
|
|
3714
4482
|
? document.activeElement?.dataset?.commandId : null;
|
|
4483
|
+
// A card painted once and reused across repaints (a connection suggestion, #1900) keeps its own control focused.
|
|
4484
|
+
const focusedNode = ui.feed.contains(document.activeElement) ? document.activeElement : null;
|
|
3715
4485
|
const nearBottom = ui.feed.scrollHeight - ui.feed.scrollTop - ui.feed.clientHeight < 56;
|
|
3716
4486
|
const scrollTop = ui.feed.scrollTop;
|
|
3717
4487
|
ui.feed.replaceChildren();
|
|
@@ -3744,8 +4514,26 @@
|
|
|
3744
4514
|
}
|
|
3745
4515
|
continue;
|
|
3746
4516
|
}
|
|
4517
|
+
// Something FloLess itself refused during the answer (a file change it declined, a connector it turned away,
|
|
4518
|
+
// #1890 PR 2b / #1907), written for the person: held and shown under the answer, like the receipts below.
|
|
4519
|
+
if (event.type === 'tool' && event.payload?.plain === true && event.payload?.tool !== 'agent'
|
|
4520
|
+
&& typeof event.payload?.message === 'string' && event.payload.message) {
|
|
4521
|
+
links.push({ turnId: event.turnId, node: renderPlainNotice(event) });
|
|
4522
|
+
continue;
|
|
4523
|
+
}
|
|
3747
4524
|
// Provider tools commonly split one answer into before/after chunks. They are not prose,
|
|
3748
4525
|
// so keep collecting same-turn deltas across them instead of rendering abandoned fragments.
|
|
4526
|
+
// #1900: a connection suggestion's Not now / Show again only changes its card, never a reason to split the answer;
|
|
4527
|
+
// the suggestion and a check's result are receipts like the ones below, held under the answer they were written during.
|
|
4528
|
+
// #2007: an agent run's first line (who started it, its scope) is a tool event too, but it is the conversation's
|
|
4529
|
+
// opening line, not a tool: shown where it was written, before the instructions.
|
|
4530
|
+
if (event.type === 'tool' && event.payload?.tool === 'agent' && typeof event.payload?.message === 'string') {
|
|
4531
|
+
flushAssistant();
|
|
4532
|
+
ui.feed.append(renderAgentRunLine(event));
|
|
4533
|
+
continue;
|
|
4534
|
+
}
|
|
4535
|
+
if (event.type === 'connection-proposal-update') continue;
|
|
4536
|
+
if (event.type === 'connection-proposal' || event.type === 'connection-check') { links.push({ turnId: event.turnId, node: renderEvent(event) }); continue; }
|
|
3749
4537
|
if (['tool', 'usage', 'knowledge-citation', 'attachment', 'compaction', 'state'].includes(event.type)) continue;
|
|
3750
4538
|
// FloLess's own receipts (object links #1653; evidence looks and suggestion cards #1859) are written mid-answer while a tool runs:
|
|
3751
4539
|
// held and shown under the answer, so they never cut one answer into fragments.
|
|
@@ -3761,7 +4549,9 @@
|
|
|
3761
4549
|
// never looks like a failed response. Recovery deliberately has no live indicator.
|
|
3762
4550
|
if (turnIsVisiblyActive()) ui.feed.append(renderLiveStatus());
|
|
3763
4551
|
}
|
|
3764
|
-
|
|
4552
|
+
if (focusedNode?.isConnected && ui.feed.contains(focusedNode)) {
|
|
4553
|
+
if (document.activeElement !== focusedNode) focusedNode.focus({ preventScroll: true });
|
|
4554
|
+
} else restoreFeedFocus(focusedCommand);
|
|
3765
4555
|
// Removing a focused control makes the browser lay out the half-built feed, which clamps its scroll near the top.
|
|
3766
4556
|
// Scrolled up, the reader stays where they were.
|
|
3767
4557
|
if (!nearBottom) ui.feed.scrollTop = scrollTop;
|
|
@@ -3865,7 +4655,16 @@
|
|
|
3865
4655
|
// Keep the same buttons during polling so keyboard focus and pointer clicks survive. A Tekla card
|
|
3866
4656
|
// also carries the permission view it offers "Allow for this chat" on, so a change repaints it.
|
|
3867
4657
|
const teklaBinding = teklaAllowableApproval(approval) ? currentTeklaBinding(state.chat) : null;
|
|
3868
|
-
|
|
4658
|
+
// #1890 PR 2b: a workspace conversation's file change, with the projects/workflows it touches.
|
|
4659
|
+
const change = approval.change && typeof approval.change === 'object' ? approval.change : null;
|
|
4660
|
+
// #1907: a call to one of the person's connectors FloLess could identify may be allowed for the whole chat.
|
|
4661
|
+
const connector = approval.connector?.verified ? approval.connector : null;
|
|
4662
|
+
// #1900: a connection check the AI asked for; "Allow for this chat" only when the server says it may be.
|
|
4663
|
+
const connectionCheck = approval.connectionCheck && typeof approval.connectionCheck === 'object' ? approval.connectionCheck : null;
|
|
4664
|
+
const allowanceRevision = connectionCheck ? String(state.chat?.integrationReadAllowance?.revision ?? 0)
|
|
4665
|
+
: change ? String(state.chat?.changeAllowance?.revision ?? 0)
|
|
4666
|
+
: teklaBinding ? String(teklaAllowanceRevision(teklaBinding))
|
|
4667
|
+
: connector ? String(state.chat?.connectorAllowance?.revision ?? 0) : '';
|
|
3869
4668
|
if (existing?.dataset.approvalId === approval.approvalId && (existing.dataset.allowanceRevision || '') === allowanceRevision) return;
|
|
3870
4669
|
// A permission change repaints the same approval: keep keyboard focus on the same control.
|
|
3871
4670
|
const refocus = existing?.dataset.approvalId === approval.approvalId && existing.contains(document.activeElement)
|
|
@@ -3873,14 +4672,57 @@
|
|
|
3873
4672
|
existing?.remove();
|
|
3874
4673
|
const card = document.createElement('section'); card.className = 'ai-chat-approval';
|
|
3875
4674
|
card.dataset.approvalId = approval.approvalId;
|
|
3876
|
-
if (teklaBinding) card.dataset.allowanceRevision = allowanceRevision;
|
|
4675
|
+
if (teklaBinding || connector || change || connectionCheck) card.dataset.allowanceRevision = allowanceRevision;
|
|
4676
|
+
// #1890 PR 3a: the AI asking to create a workflow, with where it would go.
|
|
4677
|
+
const create = approval.create && typeof approval.create === 'object' ? approval.create : null;
|
|
4678
|
+
if (approval.scopeAdd) {
|
|
4679
|
+
const scope = approval.scopeAdd;
|
|
4680
|
+
card.classList.add('ai-chat-scope-add');
|
|
4681
|
+
card.setAttribute('role', 'group');
|
|
4682
|
+
const heading = document.createElement('strong');
|
|
4683
|
+
heading.id = `chat-scope-add-heading-${approval.approvalId}`;
|
|
4684
|
+
heading.textContent = `Let this conversation also work on ${scope.target.kind} “${scope.label}”?`;
|
|
4685
|
+
card.setAttribute('aria-labelledby', heading.id);
|
|
4686
|
+
const copy = document.createElement('p');
|
|
4687
|
+
const readOnly = state.chat?.settings?.permissionProfile === 'read-only';
|
|
4688
|
+
const writeProfile = state.chat?.owner?.kind === 'workspace' ? 'Make changes (asks first)' : 'Working folder write';
|
|
4689
|
+
copy.textContent = readOnly
|
|
4690
|
+
? 'The AI’s file tools cannot change files while Read only is on. Commands keep their own approvals and may authorize file changes.'
|
|
4691
|
+
+ (scope.allowsFileChanges ? ` If you choose ${writeProfile}, file changes here will also be allowed without asking.` : '')
|
|
4692
|
+
: scope.allowsFileChanges ? 'File changes here will also be allowed without asking. Commands and tools keep their own approvals.'
|
|
4693
|
+
: 'Adds this folder to the conversation. Your current file approval setting stays unchanged.';
|
|
4694
|
+
const actions = document.createElement('div'); actions.className = 'ai-chat-approval-actions';
|
|
4695
|
+
const deny = button('Deny', 'shell.chat-approval-deny');
|
|
4696
|
+
const allow = button(scope.allowsFileChanges ? readOnly ? 'Add scope for later file changes' : 'Add scope and allow file changes' : 'Approve once', 'shell.chat-scope-add-approve', 'allow');
|
|
4697
|
+
deny.addEventListener('click', () => decideApproval('deny'));
|
|
4698
|
+
allow.addEventListener('click', () => decideApproval('allow'));
|
|
4699
|
+
actions.append(deny, allow); card.append(heading, copy, actions);
|
|
4700
|
+
ui.approvalTray.append(card);
|
|
4701
|
+
if (refocus) [...card.querySelectorAll('button')].find((node) => node.dataset.commandId === refocus)?.focus();
|
|
4702
|
+
ui.approvalTray.scrollTop = ui.approvalTray.scrollHeight;
|
|
4703
|
+
return;
|
|
4704
|
+
}
|
|
4705
|
+
if (create) {
|
|
4706
|
+
paintCreateCard(card, approval, create);
|
|
4707
|
+
ui.approvalTray.append(card);
|
|
4708
|
+
if (refocus) [...card.querySelectorAll('button')].find((node) => node.dataset.commandId === refocus)?.focus();
|
|
4709
|
+
ui.approvalTray.scrollTop = ui.approvalTray.scrollHeight;
|
|
4710
|
+
return;
|
|
4711
|
+
}
|
|
4712
|
+
if (change) {
|
|
4713
|
+
paintChangeCard(card, approval, change, Number(allowanceRevision));
|
|
4714
|
+
ui.approvalTray.append(card);
|
|
4715
|
+
if (refocus) [...card.querySelectorAll('button')].find((node) => node.dataset.commandId === refocus)?.focus();
|
|
4716
|
+
ui.approvalTray.scrollTop = ui.approvalTray.scrollHeight;
|
|
4717
|
+
return;
|
|
4718
|
+
}
|
|
3877
4719
|
const heading = document.createElement('strong'); heading.textContent = 'Approval needed';
|
|
3878
4720
|
const copy = document.createElement('p'); copy.textContent = approval.summary;
|
|
3879
4721
|
const actions = document.createElement('div'); actions.className = 'ai-chat-approval-actions';
|
|
3880
4722
|
const deny = button('Deny', 'shell.chat-approval-deny');
|
|
3881
4723
|
const allow = button('Approve once', 'shell.chat-approval-allow', 'allow');
|
|
3882
4724
|
// A Tekla read is never covered by a request-wide grant; it may instead be allowed for the whole chat (below).
|
|
3883
|
-
const explicitOnly = approvalIsExplicitOnly(approval);
|
|
4725
|
+
const explicitOnly = approvalIsExplicitOnly(approval) || Boolean(connectionCheck);
|
|
3884
4726
|
const allowRequest = explicitOnly ? null : button('Approve for this request', 'shell.chat-approval-request', 'allow');
|
|
3885
4727
|
const scope = document.createElement('span');
|
|
3886
4728
|
scope.className = 'sr-only';
|
|
@@ -3893,6 +4735,35 @@
|
|
|
3893
4735
|
allowRequest.setAttribute('aria-describedby', scope.id);
|
|
3894
4736
|
allowRequest.addEventListener('click', () => decideApproval('allow-request'));
|
|
3895
4737
|
actions.append(deny, allow, allowRequest); card.append(heading, copy, actions, scope);
|
|
4738
|
+
} else if (connectionCheck) {
|
|
4739
|
+
paintConnectionCheckApproval(card, approval, connectionCheck, { heading, copy, actions, deny, allow }, Number(allowanceRevision));
|
|
4740
|
+
ui.approvalTray.append(card);
|
|
4741
|
+
if (refocus) [...card.querySelectorAll('button')].find((node) => node.dataset.commandId === refocus)?.focus();
|
|
4742
|
+
// A new question: Deny is the safe default, unless the person is typing a message.
|
|
4743
|
+
else if (existing?.dataset.approvalId !== approval.approvalId && !(document.activeElement === ui.input && ui.input.value)) deny.focus({ preventScroll: true });
|
|
4744
|
+
ui.approvalTray.scrollTop = ui.approvalTray.scrollHeight;
|
|
4745
|
+
return;
|
|
4746
|
+
} else if (connector) {
|
|
4747
|
+
card.dataset.explicitOnly = 'true';
|
|
4748
|
+
// The warning is the part that decides it: on its own line, not at the end of the question.
|
|
4749
|
+
const split = approval.summary.indexOf(' FloLess cannot check');
|
|
4750
|
+
const warning = document.createElement('p');
|
|
4751
|
+
warning.className = 'ai-chat-approval-warning';
|
|
4752
|
+
if (split > 0) {
|
|
4753
|
+
copy.textContent = approval.summary.slice(0, split);
|
|
4754
|
+
warning.textContent = approval.summary.slice(split + 1);
|
|
4755
|
+
}
|
|
4756
|
+
const who = connectorLabel(connector);
|
|
4757
|
+
const allowChat = button(`Allow ${who} for this chat`, `shell.chat-connector-allow-chat#${connectorKey(connector)}`, 'allow');
|
|
4758
|
+
allowChat.dataset.commandInstanceLabel = who;
|
|
4759
|
+
const help = document.createElement('span');
|
|
4760
|
+
help.className = 'sr-only';
|
|
4761
|
+
help.id = `chat-approval-connector-scope-help-${approval.approvalId}`;
|
|
4762
|
+
help.textContent = `Let ${who} run whenever Chat asks in this conversation, without asking you each time. Each run is shown in the chat. Revoke it above the message box.`;
|
|
4763
|
+
allowChat.dataset.tip = help.textContent;
|
|
4764
|
+
allowChat.setAttribute('aria-describedby', help.id);
|
|
4765
|
+
allowChat.addEventListener('click', () => decideApproval('allow-chat', Number(allowanceRevision)));
|
|
4766
|
+
actions.append(deny, allow, allowChat); card.append(heading, copy, ...(warning.textContent ? [warning] : []), actions, help);
|
|
3896
4767
|
} else if (teklaBinding) {
|
|
3897
4768
|
// A Tekla read may instead be allowed for the whole chat, covering every read the chat is bound for.
|
|
3898
4769
|
card.dataset.explicitOnly = 'true';
|
|
@@ -3915,6 +4786,253 @@
|
|
|
3915
4786
|
ui.approvalTray.scrollTop = ui.approvalTray.scrollHeight;
|
|
3916
4787
|
}
|
|
3917
4788
|
|
|
4789
|
+
/**
|
|
4790
|
+
* #1900 — the card for a connection check the AI asked for. The server's summary is the whole question; the two
|
|
4791
|
+
* things that decide it (a tool FloLess has not reviewed, a key sent to an address) are pulled out onto their own
|
|
4792
|
+
* lines. Never "Approve for this request": each check is approved once, or allowed for this chat when the server
|
|
4793
|
+
* says that is safe (reviewed, no custom key, an identified account, a pinned tool).
|
|
4794
|
+
*/
|
|
4795
|
+
const CONNECTION_UNREVIEWED_SENTENCE = 'This check comes from a tool FloLess has not reviewed.';
|
|
4796
|
+
|
|
4797
|
+
function paintConnectionCheckApproval(card, approval, check, parts, allowanceRevision) {
|
|
4798
|
+
const { heading, copy, actions, deny, allow } = parts;
|
|
4799
|
+
card.dataset.explicitOnly = 'true';
|
|
4800
|
+
card.classList.add('ai-chat-connection-approval');
|
|
4801
|
+
const name = String(check.name || check.agent || 'this tool');
|
|
4802
|
+
const keySentence = check.sendsCustomKey && check.origin ? `Your ${check.credentialHandle} key will be sent to ${check.origin}.` : '';
|
|
4803
|
+
copy.textContent = String(approval.summary || `Check ${name}.`)
|
|
4804
|
+
.replace(CONNECTION_UNREVIEWED_SENTENCE, '').replace(keySentence || '\u0000', '').replace(/\s{2,}/g, ' ').trim();
|
|
4805
|
+
const extra = [];
|
|
4806
|
+
if (check.reviewed === false) {
|
|
4807
|
+
const badge = document.createElement('span');
|
|
4808
|
+
badge.className = 'local-discovery-found conn-chip is-chat-warning ai-chat-connection-badge';
|
|
4809
|
+
badge.textContent = 'Not reviewed';
|
|
4810
|
+
heading.append(' ', badge);
|
|
4811
|
+
const warning = document.createElement('p');
|
|
4812
|
+
warning.className = 'ai-chat-approval-warning';
|
|
4813
|
+
warning.textContent = 'FloLess has not reviewed the tool this check comes from, so it can’t confirm the check only reads.';
|
|
4814
|
+
extra.push(warning);
|
|
4815
|
+
}
|
|
4816
|
+
if (check.sendsCustomKey) {
|
|
4817
|
+
const warning = document.createElement('p');
|
|
4818
|
+
warning.className = 'ai-chat-approval-warning';
|
|
4819
|
+
const handle = check.credentialHandle ? `${check.credentialHandle} ` : '';
|
|
4820
|
+
if (check.origin) {
|
|
4821
|
+
const address = document.createElement('code'); address.className = 'conn-code'; address.textContent = check.origin;
|
|
4822
|
+
warning.append(`Your ${handle}key will be sent to `, address, '. Only approve if you trust that address.');
|
|
4823
|
+
} else warning.textContent = `Your ${handle}key will be sent to an address this tool chose. Only approve if you trust it.`;
|
|
4824
|
+
extra.push(warning);
|
|
4825
|
+
}
|
|
4826
|
+
// Deny and Approve once already answer through paintApproval's own listeners.
|
|
4827
|
+
actions.append(deny, allow);
|
|
4828
|
+
const nodes = [heading, copy, ...extra, actions];
|
|
4829
|
+
if (check.chatAllowable === true) {
|
|
4830
|
+
const label = check.kind === 'host' ? `Allow checks of ${name} for this chat` : `Allow checks of ${name} with this account for this chat`;
|
|
4831
|
+
const key = `${check.agent}${check.alias ? `.${check.alias}` : ''}`;
|
|
4832
|
+
const allowChat = button(label, `shell.chat-connection-check-allow-chat#${key}`, 'allow');
|
|
4833
|
+
allowChat.dataset.commandInstanceLabel = name;
|
|
4834
|
+
const help = document.createElement('span');
|
|
4835
|
+
help.className = 'sr-only';
|
|
4836
|
+
help.id = `chat-approval-check-scope-help-${approval.approvalId}`;
|
|
4837
|
+
help.textContent = `Let Chat check ${name}${check.kind === 'host' ? '' : ' with this account'} whenever it asks in this conversation, without asking you each time. Each check is shown in the chat. Revoke it above the message box.`;
|
|
4838
|
+
allowChat.dataset.tip = help.textContent;
|
|
4839
|
+
allowChat.setAttribute('aria-describedby', help.id);
|
|
4840
|
+
allowChat.addEventListener('click', () => decideApproval('allow-chat', allowanceRevision));
|
|
4841
|
+
actions.append(allowChat);
|
|
4842
|
+
nodes.push(help);
|
|
4843
|
+
}
|
|
4844
|
+
card.append(...nodes);
|
|
4845
|
+
}
|
|
4846
|
+
|
|
4847
|
+
// #1890 PR 2b — why a workspace change can only be dismissed. Mirrors the server's reasons in plain words.
|
|
4848
|
+
const CHANGE_REFUSED_COPY = {
|
|
4849
|
+
'outside-workspace': 'This file is outside your FloLess workspace folder, so nothing was changed. Ask the AI to keep the change inside a project or workflow.',
|
|
4850
|
+
'conversation-records': 'This would change FloLess’s own conversation records, which the AI never changes, so nothing was changed. Ask the AI to put the change in a project or workflow.',
|
|
4851
|
+
'not-in-project': 'FloLess can’t tell which project or workflow this file belongs to, so nothing was changed. Ask the AI to save it in a project or workflow folder instead.',
|
|
4852
|
+
'unreadable-path': 'FloLess couldn’t confirm where this file really is, because the path goes through a folder link, so nothing was changed. Ask the AI to use the project’s own folder.',
|
|
4853
|
+
'ambiguous-path': 'FloLess cannot confirm how the provider expands this path, so nothing was changed. Use an absolute file path in the intended project or workflow, then retry.',
|
|
4854
|
+
'provider-settings': 'FloLess doesn’t let the AI change its own settings files, so nothing was changed. Ask it to make the change somewhere else.',
|
|
4855
|
+
'too-many': 'This change touches too many files to review at once, so nothing was changed. Ask the AI to make it in smaller steps.',
|
|
4856
|
+
};
|
|
4857
|
+
const CHANGE_PATHS_SHOWN = 5;
|
|
4858
|
+
|
|
4859
|
+
function changeFileCount(change) {
|
|
4860
|
+
return (change.owners || []).reduce((sum, owner) => sum + (owner.paths?.length || 0), 0);
|
|
4861
|
+
}
|
|
4862
|
+
|
|
4863
|
+
function changeNames(change) {
|
|
4864
|
+
const names = (change.owners || []).map((owner) => owner.label);
|
|
4865
|
+
return names.length <= 1 ? (names[0] || 'this project') : `${names.slice(0, -1).join(', ')} and ${names.at(-1)}`;
|
|
4866
|
+
}
|
|
4867
|
+
|
|
4868
|
+
/** The card for a workspace conversation's file change: where it lands, then Deny / Approve once / Allow for this chat. */
|
|
4869
|
+
function paintChangeCard(card, approval, change, allowanceRevision) {
|
|
4870
|
+
card.dataset.explicitOnly = 'true';
|
|
4871
|
+
card.classList.add('ai-chat-change');
|
|
4872
|
+
card.setAttribute('role', 'group');
|
|
4873
|
+
const id = approval.approvalId;
|
|
4874
|
+
const denyOnly = Boolean(change.refused || change.busy);
|
|
4875
|
+
const heading = document.createElement('strong');
|
|
4876
|
+
heading.id = `chat-change-heading-${id}`;
|
|
4877
|
+
heading.textContent = denyOnly ? 'Can’t change this' : 'Approval needed';
|
|
4878
|
+
card.setAttribute('aria-labelledby', heading.id);
|
|
4879
|
+
const provider = providerLabels[state.chat?.provider] || 'The AI';
|
|
4880
|
+
const files = changeFileCount(change);
|
|
4881
|
+
const copy = document.createElement('p');
|
|
4882
|
+
copy.id = `chat-change-copy-${id}`;
|
|
4883
|
+
copy.textContent = files === 1 ? `${provider} wants to change a file in your workspace.`
|
|
4884
|
+
: files > 1 ? `${provider} wants to change these ${files} files in your workspace.` : `${provider} wants to change files in your workspace.`;
|
|
4885
|
+
card.setAttribute('aria-describedby', copy.id);
|
|
4886
|
+
const actions = document.createElement('div'); actions.className = 'ai-chat-approval-actions';
|
|
4887
|
+
if (denyOnly) {
|
|
4888
|
+
// Nothing is waiting for approval: one way out, and a plain reason why.
|
|
4889
|
+
card.setAttribute('role', 'status');
|
|
4890
|
+
const reason = document.createElement('p');
|
|
4891
|
+
reason.className = 'ai-chat-change-reason';
|
|
4892
|
+
reason.textContent = change.refused
|
|
4893
|
+
? (CHANGE_REFUSED_COPY[change.refused] || CHANGE_REFUSED_COPY['not-in-project'])
|
|
4894
|
+
: change.busy?.chatTitle
|
|
4895
|
+
? `${changeNames(change)} ${change.owners.length > 1 ? 'are' : 'is'} being changed by another conversation (“${change.busy.chatTitle}”), so nothing was changed here. Ask again when it’s finished.`
|
|
4896
|
+
: `${changeNames(change)} ${change.owners.length > 1 ? 'are' : 'is'} being changed by other work right now, so nothing was changed here. Ask again when it’s finished.`;
|
|
4897
|
+
const dismiss = button('Dismiss', 'shell.chat-approval-deny');
|
|
4898
|
+
dismiss.addEventListener('click', () => decideApproval('deny'));
|
|
4899
|
+
actions.append(dismiss);
|
|
4900
|
+
card.append(heading, ...(change.owners?.length ? [copy, changeOwnerList(change)] : []), reason, actions);
|
|
4901
|
+
return;
|
|
4902
|
+
}
|
|
4903
|
+
const deny = button('Deny', 'shell.chat-approval-deny');
|
|
4904
|
+
const allow = button('Approve once', 'shell.chat-approval-allow', 'allow');
|
|
4905
|
+
deny.addEventListener('click', () => decideApproval('deny'));
|
|
4906
|
+
allow.addEventListener('click', () => decideApproval('allow'));
|
|
4907
|
+
actions.append(deny, allow);
|
|
4908
|
+
if (change.owners?.length) {
|
|
4909
|
+
const label = 'Allow file changes for this chat';
|
|
4910
|
+
const key = change.owners.map((owner) => owner.key).join('+');
|
|
4911
|
+
const allowChat = button(label, `shell.chat-change-allow-chat#${key}`, 'allow');
|
|
4912
|
+
allowChat.dataset.commandInstanceLabel = changeNames(change);
|
|
4913
|
+
const help = document.createElement('span');
|
|
4914
|
+
help.className = 'ai-chat-change-scope-help';
|
|
4915
|
+
help.id = `chat-change-scope-help-${id}`;
|
|
4916
|
+
help.textContent = 'Allows file changes in this conversation’s scope, including folders you add later, without asking you each time. Commands and tools still ask. Your home folder keeps its current permission setting. Revoke it above the message box.';
|
|
4917
|
+
allowChat.dataset.tip = help.textContent;
|
|
4918
|
+
allowChat.setAttribute('aria-describedby', help.id);
|
|
4919
|
+
allowChat.addEventListener('click', () => decideApproval('allow-chat', allowanceRevision));
|
|
4920
|
+
actions.append(allowChat);
|
|
4921
|
+
card.append(heading, copy, changeOwnerList(change), actions, help);
|
|
4922
|
+
return;
|
|
4923
|
+
}
|
|
4924
|
+
card.append(heading, copy, actions);
|
|
4925
|
+
}
|
|
4926
|
+
|
|
4927
|
+
/** Why a workflow the AI asked to create can only be dismissed (#1890 PR 3a); the server says the same to the AI. */
|
|
4928
|
+
const CREATE_REFUSED_COPY = {
|
|
4929
|
+
'bad-name': 'A workflow name needs 1 to 120 characters you can see, so nothing was created. Ask the AI for a shorter or plainer name.',
|
|
4930
|
+
'project-missing': 'That project isn’t in your workspace any more (it may have been archived or renamed), so nothing was created. Ask the AI to pick another project, or to create the workflow on its own.',
|
|
4931
|
+
};
|
|
4932
|
+
|
|
4933
|
+
function createWhere(create) {
|
|
4934
|
+
return create.destination?.kind === 'project' ? `in project ${create.destination.label}` : 'on its own, outside any project';
|
|
4935
|
+
}
|
|
4936
|
+
|
|
4937
|
+
/** The card for the AI asking to create a workflow: what and where, then Deny / Create workflow. Approve once only. */
|
|
4938
|
+
function paintCreateCard(card, approval, create) {
|
|
4939
|
+
card.dataset.explicitOnly = 'true';
|
|
4940
|
+
card.classList.add('ai-chat-change', 'ai-chat-create');
|
|
4941
|
+
card.setAttribute('role', 'group');
|
|
4942
|
+
const id = approval.approvalId;
|
|
4943
|
+
const denyOnly = Boolean(create.refused || create.busy);
|
|
4944
|
+
const heading = document.createElement('strong');
|
|
4945
|
+
heading.id = `chat-create-heading-${id}`;
|
|
4946
|
+
heading.textContent = denyOnly ? 'Can’t create this yet' : 'Create a workflow?';
|
|
4947
|
+
card.setAttribute('aria-labelledby', heading.id);
|
|
4948
|
+
const provider = providerLabels[state.chat?.provider] || 'The AI';
|
|
4949
|
+
const copy = document.createElement('p');
|
|
4950
|
+
copy.id = `chat-create-copy-${id}`;
|
|
4951
|
+
copy.textContent = `${provider} wants to create a workflow.`;
|
|
4952
|
+
card.setAttribute('aria-describedby', copy.id);
|
|
4953
|
+
// One row in the change card's own style: the new workflow's name, and where it would go.
|
|
4954
|
+
const list = document.createElement('ul');
|
|
4955
|
+
list.className = 'ai-chat-change-owners';
|
|
4956
|
+
const row = document.createElement('li');
|
|
4957
|
+
const name = document.createElement('span');
|
|
4958
|
+
name.className = 'ai-chat-change-owner';
|
|
4959
|
+
const strong = document.createElement('b');
|
|
4960
|
+
strong.textContent = create.name;
|
|
4961
|
+
strong.dataset.tip = create.name;
|
|
4962
|
+
const kind = document.createElement('span');
|
|
4963
|
+
kind.className = 'ai-chat-change-kind';
|
|
4964
|
+
kind.textContent = 'new workflow';
|
|
4965
|
+
name.append(strong, kind);
|
|
4966
|
+
const where = document.createElement('span');
|
|
4967
|
+
where.className = 'ai-chat-change-paths';
|
|
4968
|
+
const whereLine = document.createElement('span');
|
|
4969
|
+
whereLine.className = 'ai-chat-change-path ai-chat-create-where';
|
|
4970
|
+
whereLine.textContent = createWhere(create);
|
|
4971
|
+
where.append(whereLine);
|
|
4972
|
+
row.append(name, where);
|
|
4973
|
+
list.append(row);
|
|
4974
|
+
const actions = document.createElement('div'); actions.className = 'ai-chat-approval-actions';
|
|
4975
|
+
if (denyOnly) {
|
|
4976
|
+
card.setAttribute('role', 'status');
|
|
4977
|
+
const reason = document.createElement('p');
|
|
4978
|
+
reason.className = 'ai-chat-change-reason';
|
|
4979
|
+
const place = create.destination?.kind === 'project' ? create.destination.label : 'that workflow';
|
|
4980
|
+
reason.textContent = create.refused
|
|
4981
|
+
? (CREATE_REFUSED_COPY[create.refused] || CREATE_REFUSED_COPY['project-missing'])
|
|
4982
|
+
: create.busy?.chatTitle
|
|
4983
|
+
? `Another conversation (“${create.busy.chatTitle}”) is changing ${place} right now, so nothing was created. Ask again when it’s finished.`
|
|
4984
|
+
: `Other work is changing ${place} right now, so nothing was created. Ask again when it’s finished.`;
|
|
4985
|
+
const dismiss = button('Dismiss', 'shell.chat-approval-deny');
|
|
4986
|
+
dismiss.addEventListener('click', () => decideApproval('deny'));
|
|
4987
|
+
actions.append(dismiss);
|
|
4988
|
+
card.append(heading, copy, list, reason, actions);
|
|
4989
|
+
return;
|
|
4990
|
+
}
|
|
4991
|
+
const deny = button('Deny', 'shell.chat-approval-deny');
|
|
4992
|
+
const allow = button('Create workflow', 'shell.chat-workflow-create-approve', 'allow');
|
|
4993
|
+
deny.addEventListener('click', () => decideApproval('deny'));
|
|
4994
|
+
allow.addEventListener('click', () => decideApproval('allow'));
|
|
4995
|
+
actions.append(deny, allow);
|
|
4996
|
+
card.append(heading, copy, list, actions);
|
|
4997
|
+
}
|
|
4998
|
+
|
|
4999
|
+
/** Each project or workflow the change touches, with up to five of its files. */
|
|
5000
|
+
function changeOwnerList(change) {
|
|
5001
|
+
const list = document.createElement('ul');
|
|
5002
|
+
list.className = 'ai-chat-change-owners';
|
|
5003
|
+
for (const owner of change.owners || []) {
|
|
5004
|
+
const row = document.createElement('li');
|
|
5005
|
+
const name = document.createElement('span');
|
|
5006
|
+
name.className = 'ai-chat-change-owner';
|
|
5007
|
+
const strong = document.createElement('b');
|
|
5008
|
+
strong.textContent = owner.label;
|
|
5009
|
+
const kind = document.createElement('span');
|
|
5010
|
+
kind.className = 'ai-chat-change-kind';
|
|
5011
|
+
kind.textContent = owner.kind === 'workflow' ? 'workflow' : 'project';
|
|
5012
|
+
name.append(strong, kind);
|
|
5013
|
+
const paths = document.createElement('span');
|
|
5014
|
+
paths.className = 'ai-chat-change-paths';
|
|
5015
|
+
const shown = (owner.paths || []).slice(0, CHANGE_PATHS_SHOWN);
|
|
5016
|
+
for (const path of shown) {
|
|
5017
|
+
const line = document.createElement('span');
|
|
5018
|
+
line.className = 'ai-chat-change-path';
|
|
5019
|
+
line.textContent = path;
|
|
5020
|
+
line.dataset.tip = path;
|
|
5021
|
+
paths.append(line);
|
|
5022
|
+
}
|
|
5023
|
+
const more = (owner.paths?.length || 0) - shown.length;
|
|
5024
|
+
if (more > 0) {
|
|
5025
|
+
const extra = document.createElement('span');
|
|
5026
|
+
extra.className = 'ai-chat-change-more';
|
|
5027
|
+
extra.textContent = `and ${more} more file${more === 1 ? '' : 's'}`;
|
|
5028
|
+
paths.append(extra);
|
|
5029
|
+
}
|
|
5030
|
+
row.append(name, paths);
|
|
5031
|
+
list.append(row);
|
|
5032
|
+
}
|
|
5033
|
+
return list;
|
|
5034
|
+
}
|
|
5035
|
+
|
|
3918
5036
|
function approvalIsExplicitOnly(approval) {
|
|
3919
5037
|
if (!approval) return false;
|
|
3920
5038
|
if (approval.explicitOnly === true) return true;
|
|
@@ -4396,6 +5514,7 @@
|
|
|
4396
5514
|
}
|
|
4397
5515
|
|
|
4398
5516
|
function paintSettings() {
|
|
5517
|
+
if (ui.scopeControls) paintScopeControl();
|
|
4399
5518
|
const chat = state.chat;
|
|
4400
5519
|
ui.settingsToggle.disabled = !chat;
|
|
4401
5520
|
const answer = capabilityAnswer(state.capability);
|
|
@@ -4421,14 +5540,14 @@
|
|
|
4421
5540
|
ui.model.querySelector('strong').textContent = chat?.settings.model ? (model?.label || chat.settings.model) : (model?.label || 'Choose model');
|
|
4422
5541
|
const medium = (model?.efforts || []).find((effort) => effort.toLowerCase() === 'medium');
|
|
4423
5542
|
ui.effort.querySelector('strong').textContent = effortLabel(chat?.settings.effort || medium || model?.efforts?.[0]) || 'Choose effort';
|
|
4424
|
-
ui.permission.querySelector('strong').textContent =
|
|
4425
|
-
if (state.scope?.owner?.kind === 'workspace') ui.permission.dataset.tip = 'From the workspace, AI Chat
|
|
5543
|
+
ui.permission.querySelector('strong').textContent = permissionLabel(chat?.settings.permissionProfile);
|
|
5544
|
+
if (state.scope?.owner?.kind === 'workspace') ui.permission.dataset.tip = 'From the workspace, AI Chat asks before it changes a file in a project or workflow. Full access isn’t offered here.';
|
|
4426
5545
|
else delete ui.permission.dataset.tip;
|
|
4427
5546
|
paintWorkspaceUnits();
|
|
4428
5547
|
const bindings = chat?.integrationBindings || [];
|
|
4429
5548
|
ui.integrations.querySelector('strong').textContent = bindings.length
|
|
4430
5549
|
? `${bindings.length} FloLess account${bindings.length === 1 ? '' : 's'}`
|
|
4431
|
-
:
|
|
5550
|
+
: 'Not using one';
|
|
4432
5551
|
const frozen = !chat || Boolean(chat.activeTurn) || !state.capability?.available;
|
|
4433
5552
|
ui.model.disabled = frozen; ui.effort.disabled = frozen; ui.permission.disabled = frozen;
|
|
4434
5553
|
ui.integrations.disabled = frozen || Boolean(chat?.nativeSessionId);
|
|
@@ -4441,9 +5560,39 @@
|
|
|
4441
5560
|
ui.integrations.dataset.tip = integrationBlocked || 'Choose which connected account this chat can use';
|
|
4442
5561
|
if (integrationBlocked) ui.integrations.dataset.blockedReason = integrationBlocked;
|
|
4443
5562
|
else delete ui.integrations.dataset.blockedReason;
|
|
5563
|
+
paintOwnConnectorsSetting(chat, frozen);
|
|
4444
5564
|
paintDesktopStatus();
|
|
4445
5565
|
}
|
|
4446
5566
|
|
|
5567
|
+
/** #1907: the per-conversation switch for the AI's own connectors (off for every new conversation). */
|
|
5568
|
+
function paintOwnConnectorsSetting(chat, frozen) {
|
|
5569
|
+
const control = ui.ownConnectors;
|
|
5570
|
+
if (!control) return;
|
|
5571
|
+
const provider = providerLabels[chat?.provider] || 'Claude or Codex';
|
|
5572
|
+
const usesAccount = Boolean(chat?.integrationBindings?.length);
|
|
5573
|
+
const on = chat?.settings?.useOwnConnectors === true && !usesAccount;
|
|
5574
|
+
control.querySelector('span').textContent = `Use my ${provider} connectors in this chat`;
|
|
5575
|
+
control.querySelector('strong').textContent = on ? 'On' : 'Off';
|
|
5576
|
+
control.setAttribute('aria-checked', String(on));
|
|
5577
|
+
const blocked = !chat ? 'Open a conversation first.'
|
|
5578
|
+
: usesAccount ? 'This chat uses a FloLess connected account, so your own connectors stay off.'
|
|
5579
|
+
: chat.activeTurn ? 'Wait for the current AI reply to finish before changing this.'
|
|
5580
|
+
: !state.capability?.available ? capabilityMessage(chat.provider, state.capability?.reason)
|
|
5581
|
+
: frozen ? 'This setting cannot change right now.' : '';
|
|
5582
|
+
control.disabled = Boolean(blocked);
|
|
5583
|
+
control.dataset.tip = blocked || `Lets the AI use the connectors you added to ${provider}, such as Google Drive. Each call still asks you first. Off in every new chat.`;
|
|
5584
|
+
if (blocked) control.dataset.blockedReason = blocked; else delete control.dataset.blockedReason;
|
|
5585
|
+
}
|
|
5586
|
+
|
|
5587
|
+
async function setOwnConnectors(on, options = {}) {
|
|
5588
|
+
if (!state.chat) return;
|
|
5589
|
+
const provider = providerLabels[state.chat.provider] || 'Claude or Codex';
|
|
5590
|
+
await saveSettings({ useOwnConnectors: on }, { announce: false });
|
|
5591
|
+
if (state.chat?.settings?.useOwnConnectors === true !== on) return;
|
|
5592
|
+
announce(on ? `Your ${provider} connectors are on for this chat. Each call asks you first.` : `Your ${provider} connectors are off for this chat.`);
|
|
5593
|
+
if (options.focusInput) ui.input?.focus();
|
|
5594
|
+
}
|
|
5595
|
+
|
|
4447
5596
|
function paintDesktopStatus() {
|
|
4448
5597
|
const desktop = state.desktop;
|
|
4449
5598
|
if (!state.chat) {
|
|
@@ -4473,6 +5622,7 @@
|
|
|
4473
5622
|
}
|
|
4474
5623
|
|
|
4475
5624
|
function paintRecovery() {
|
|
5625
|
+
paintMoveNotice();
|
|
4476
5626
|
const recovery = state.chat?.state === 'recovery';
|
|
4477
5627
|
ui.recovery.hidden = !recovery;
|
|
4478
5628
|
ui.recoveryStop.hidden = !recovery;
|
|
@@ -4483,8 +5633,12 @@
|
|
|
4483
5633
|
}
|
|
4484
5634
|
|
|
4485
5635
|
function paintConversation() {
|
|
5636
|
+
paintScopeControl();
|
|
4486
5637
|
paintComposerDisclosure();
|
|
4487
5638
|
paintTeklaChip();
|
|
5639
|
+
paintConnectorAllowance();
|
|
5640
|
+
paintChangeAllowance();
|
|
5641
|
+
paintCheckAllowance();
|
|
4488
5642
|
const chat = state.chat;
|
|
4489
5643
|
if (!chat) { providerChooser(); paintHistory(); return; }
|
|
4490
5644
|
ui.historyToggle.disabled = false;
|
|
@@ -4617,7 +5771,20 @@
|
|
|
4617
5771
|
paintEvents(); paintUnread();
|
|
4618
5772
|
if (!document.hidden && !ui.feed.closest('[hidden]')) markRead();
|
|
4619
5773
|
if (['approval-requested', 'approval-decided', 'error', 'interrupted', 'state', 'followup-status'].includes(event.type)
|
|
4620
|
-
|| (event.type === 'user-message' && event.payload?.followup))
|
|
5774
|
+
|| (event.type === 'user-message' && event.payload?.followup)) {
|
|
5775
|
+
// #1890 PR 3b: a reply ending in a conversation waiting to move is when it moves; read the history list then,
|
|
5776
|
+
// because the conversation's own address answers "moved" the moment the move lands.
|
|
5777
|
+
const moveDue = state.scope?.owner?.kind === 'workspace' && state.chat?.rehome?.state === 'pending'
|
|
5778
|
+
&& ['state', 'error', 'interrupted'].includes(event.type);
|
|
5779
|
+
if (moveDue) void checkMoveProgress(chatId); else refreshConversation(chatId, false);
|
|
5780
|
+
}
|
|
5781
|
+
});
|
|
5782
|
+
// #1890 PR 3b: the conversation moved into the workflow it built; the stream closes and the tab follows.
|
|
5783
|
+
source.addEventListener('chat-moved', (message) => {
|
|
5784
|
+
if (state.source !== source) return;
|
|
5785
|
+
let payload = null;
|
|
5786
|
+
try { payload = JSON.parse(message.data); } catch { return; }
|
|
5787
|
+
if (payload?.to?.chatId) void followMovedChat(payload.to);
|
|
4621
5788
|
});
|
|
4622
5789
|
source.addEventListener('ready', () => {
|
|
4623
5790
|
if (state.source !== source || !sameScope(scope, generation) || state.chat?.chatId !== chatId) return;
|
|
@@ -4914,7 +6081,7 @@
|
|
|
4914
6081
|
state.scope = scope;
|
|
4915
6082
|
state.scopeInitialized = true;
|
|
4916
6083
|
if (scopeChanged) { try { window.flolessLeftPane?.chatLinksChanged?.(); } catch { /* the card refreshes on its next read */ } }
|
|
4917
|
-
state.chat = null; state.chats = []; state.archivedChats = []; state.unreadableChats = []; state.events = []; state.capability = null; state.desktop = null; state.attachments = []; state.integrations = null;
|
|
6084
|
+
state.chat = null; state.chats = []; state.archivedChats = []; state.unreadableChats = []; state.movedChats = []; state.movedChatsKnown = null; state.events = []; state.capability = null; state.desktop = null; state.attachments = []; state.integrations = null;
|
|
4918
6085
|
if (scopeChanged) clearReport();
|
|
4919
6086
|
state.filterCardMessages.clear();
|
|
4920
6087
|
updateOffscreenActivity();
|
|
@@ -4931,17 +6098,19 @@
|
|
|
4931
6098
|
const result = await request(`/api/chat/conversations?${ownerQuery(scope.owner)}`);
|
|
4932
6099
|
if (generation !== state.scopeGeneration) return;
|
|
4933
6100
|
state.chats = result.chats || [];
|
|
4934
|
-
state.unreadableChats = result.unreadableChats || [];
|
|
6101
|
+
state.unreadableChats = result.unreadableChats || []; noteMovedChats(result.movedChats);
|
|
4935
6102
|
seedReadCursors(state.chats, scope.owner);
|
|
4936
6103
|
paintHistory(); paintUnread();
|
|
4937
|
-
|
|
6104
|
+
// #2007: a scope may name the conversation it is for (an agent run's); otherwise the newest one opens.
|
|
6105
|
+
const wanted = scope.chatId && state.chats.some((chat) => chat.chatId === scope.chatId) ? scope.chatId : state.chats[0]?.chatId;
|
|
6106
|
+
if (wanted) await selectConversation(wanted);
|
|
4938
6107
|
else providerChooser();
|
|
4939
6108
|
} catch (error) {
|
|
4940
6109
|
if (generation === state.scopeGeneration) {
|
|
4941
6110
|
// A history read can fail independently of the selected project (for example while an
|
|
4942
6111
|
// older, stale conversation is being recovered). Do not erase the scope and disable the
|
|
4943
6112
|
// whole panel: the user can still start a new conversation in the project that is open.
|
|
4944
|
-
state.chats = []; state.archivedChats = []; state.unreadableChats = []; state.chat = null; state.events = []; state.capability = null;
|
|
6113
|
+
state.chats = []; state.archivedChats = []; state.unreadableChats = []; state.movedChats = []; state.movedChatsKnown = null; state.chat = null; state.events = []; state.capability = null;
|
|
4945
6114
|
updateOffscreenActivity();
|
|
4946
6115
|
ui.scope.textContent = scope.label;
|
|
4947
6116
|
ui.context.textContent = scope.owner.kind === 'project' ? 'Project conversation' : scope.owner.kind === 'workflow' ? 'Workflow conversation' : 'Workspace conversation';
|
|
@@ -5114,7 +6283,7 @@
|
|
|
5114
6283
|
const result = await request(`/api/chat/conversations?${ownerQuery()}&filter=instructor-answers`);
|
|
5115
6284
|
if (requestGeneration !== state.historyRequestGeneration || scopeGeneration !== state.scopeGeneration) return;
|
|
5116
6285
|
state.chats = result.chats || [];
|
|
5117
|
-
state.unreadableChats = result.unreadableChats || [];
|
|
6286
|
+
state.unreadableChats = result.unreadableChats || []; noteMovedChats(result.movedChats);
|
|
5118
6287
|
state.instructorAnswers = result.instructorAnswers || [];
|
|
5119
6288
|
} catch (error) {
|
|
5120
6289
|
if (requestGeneration === state.historyRequestGeneration) report(error, 'Could not load Instructor answers');
|
|
@@ -5260,13 +6429,22 @@
|
|
|
5260
6429
|
selected: (state.chat.settings.effort || 'medium').toLowerCase() === effort.toLowerCase(), patch: { effort } }));
|
|
5261
6430
|
}
|
|
5262
6431
|
|
|
6432
|
+
/** #1890 PR 2b: in a workspace conversation, "Make changes" — every change outside the AI's own folder asks first. */
|
|
6433
|
+
function permissionLabel(value) {
|
|
6434
|
+
if (state.scope?.owner?.kind === 'workspace' && value === 'workspace-write') return 'Make changes (asks first)';
|
|
6435
|
+
return permissionLabels[value] || 'Read only';
|
|
6436
|
+
}
|
|
6437
|
+
|
|
5263
6438
|
function permissionChoices() {
|
|
5264
|
-
// #1890: from the workspace,
|
|
5265
|
-
const
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
6439
|
+
// #1890 PR 2b: from the workspace, Full access is not offered — it would remove the approvals each change needs.
|
|
6440
|
+
const workspace = state.scope?.owner?.kind === 'workspace';
|
|
6441
|
+
const offered = workspace
|
|
6442
|
+
? Object.keys(permissionLabels).filter((value) => value !== 'full-access')
|
|
6443
|
+
: Object.keys(permissionLabels);
|
|
6444
|
+
return offered.map((value) => ({
|
|
6445
|
+
id: `permission:${value}`, label: permissionLabel(value),
|
|
6446
|
+
meta: value === 'full-access' ? 'all local files'
|
|
6447
|
+
: value === 'workspace-write' ? (workspace ? 'asks before changing project files' : 'project or workflow folder') : 'no file changes',
|
|
5270
6448
|
selected: state.chat.settings.permissionProfile === value, patch: { permissionProfile: value },
|
|
5271
6449
|
}));
|
|
5272
6450
|
}
|
|
@@ -5307,7 +6485,9 @@
|
|
|
5307
6485
|
const lead = document.createElement('strong');
|
|
5308
6486
|
const detail = document.createTextNode(state.chat?.integrationBindings?.length
|
|
5309
6487
|
? ' When you select a FloLess account, this chat uses it for that service instead of the account connected in Claude or Codex.'
|
|
5310
|
-
:
|
|
6488
|
+
: state.chat?.settings?.useOwnConnectors === true
|
|
6489
|
+
? ` Until you select a FloLess account here, ${providerLabels[state.chat.provider] || 'the AI'} uses your own connectors, and each call asks you first.`
|
|
6490
|
+
: ` Your own ${providerLabels[state.chat?.provider] || 'Claude or Codex'} connectors are off in this chat, so select a FloLess account to use a service.`);
|
|
5311
6491
|
lead.textContent = state.chat?.integrationBindings?.length ? 'This chat will use the FloLess account you selected.' : 'Choose a connected account for this chat.';
|
|
5312
6492
|
note.append(lead, detail); ui.picker.append(note);
|
|
5313
6493
|
const rows = data?.rows || [];
|
|
@@ -5361,7 +6541,7 @@
|
|
|
5361
6541
|
state.chat = chat;
|
|
5362
6542
|
const index = state.chats.findIndex((item) => item.chatId === chatId); if (index >= 0) state.chats[index] = state.chat;
|
|
5363
6543
|
await loadIntegrations(); paintSettings(); paintIntegrationPicker();
|
|
5364
|
-
announce(row.selected ? `${row.label}
|
|
6544
|
+
announce(row.selected ? `${row.label} is no longer selected for this chat.` : `${integrationAccountLabel(row)} selected in FloLess.`);
|
|
5365
6545
|
} catch (error) { if (sameChat(snapshot)) { report(error, 'Could not change the connected account'); paintIntegrationPicker(); } }
|
|
5366
6546
|
}
|
|
5367
6547
|
|
|
@@ -5374,8 +6554,21 @@
|
|
|
5374
6554
|
const settingUp = Boolean(state.capability?.runtime && state.capability.runtime.state !== 'installed');
|
|
5375
6555
|
const uploading = Boolean(state.chat?.chatId && state.uploadingChatIds.has(state.chat.chatId));
|
|
5376
6556
|
ui.input.disabled = state.followupSubmitting || !state.chat || Boolean(state.chat?.archivedAt) || recovery || blocked;
|
|
6557
|
+
// #1890 PR 3b: while the conversation moves, typing goes on (the draft is kept) and Send waits. Inline, not a helper:
|
|
6558
|
+
// several harnesses run this function on its own.
|
|
6559
|
+
const movingTo = state.chat?.rehome && ['freezing', 'copying', 'publishing'].includes(state.chat.rehome.state)
|
|
6560
|
+
&& state.scope?.owner?.kind === 'workspace' ? state.chat.rehome.to.label : null;
|
|
6561
|
+
const moving = Boolean(movingTo);
|
|
6562
|
+
if (moving) {
|
|
6563
|
+
ui.hint.textContent = `Moving this conversation into workflow ${movingTo} — one moment.`;
|
|
6564
|
+
if (!state.movingPoll) {
|
|
6565
|
+
const movingChatId = state.chat.chatId;
|
|
6566
|
+
state.movingPoll = setTimeout(() => { state.movingPoll = null; void checkMoveProgress(movingChatId); }, 800);
|
|
6567
|
+
}
|
|
6568
|
+
}
|
|
5377
6569
|
ui.send.disabled = state.loading || state.followupSubmitting || Boolean(state.followupUnknownId) || hasUnknownFollowup() || uploading || !state.chat || blocked || frozen
|
|
5378
6570
|
|| (!ui.input.value.trim() && state.attachments.length === 0) || settingUp;
|
|
6571
|
+
if (moving) ui.send.disabled = true;
|
|
5379
6572
|
// The paperclip is the same on every surface, the Drawing Filter included (#1681, #1859): a message
|
|
5380
6573
|
// there carries the filter's context AND whatever the person attached, under the general rules only.
|
|
5381
6574
|
ui.attach.disabled = state.loading || state.followupSubmitting || Boolean(state.followupUnknownId) || hasUnknownFollowup() || uploading || !state.chat || blocked || frozen;
|
|
@@ -6400,12 +7593,22 @@
|
|
|
6400
7593
|
paintConversation();
|
|
6401
7594
|
announce('Applying your choice…');
|
|
6402
7595
|
try {
|
|
6403
|
-
await request(`/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/approvals/${encodeURIComponent(approvalId)}`, {
|
|
7596
|
+
const result = await request(`/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/approvals/${encodeURIComponent(approvalId)}`, {
|
|
6404
7597
|
method: 'POST', body: JSON.stringify({ owner: snapshot.scope.owner, decision,
|
|
6405
7598
|
...(decision === 'allow-chat' ? { allowanceRevision } : {}) }),
|
|
6406
7599
|
});
|
|
6407
7600
|
if (!sameChat(snapshot)) return;
|
|
6408
|
-
|
|
7601
|
+
// #1890 PR 2b: the server says what it actually did. A change it refused at its last check is announced with the
|
|
7602
|
+
// reason it gave, never as allowed.
|
|
7603
|
+
const outcome = result?.outcome;
|
|
7604
|
+
const refusal = typeof outcome?.reason === 'string' && outcome.reason ? outcome.reason : '';
|
|
7605
|
+
announce(refusal ? refusal
|
|
7606
|
+
// The request ended before the choice reached the AI (it was stopped or withdrawn): claim nothing about it.
|
|
7607
|
+
: outcome?.delivered === false ? 'This request ended before your choice reached the AI.'
|
|
7608
|
+
: decision === 'allow-request' ? 'Access auto-approval is on for this request.'
|
|
7609
|
+
: decision === 'allow-chat' && approval.change ? 'File changes in this conversation’s scope are allowed for this chat. Commands and tools still ask. Revoke above the message box.'
|
|
7610
|
+
: decision === 'allow-chat' && approval.connectionCheck ? `Checks of ${approval.connectionCheck.name || 'this tool'} are allowed for this chat. Revoke them above the message box.`
|
|
7611
|
+
: decision === 'allow-chat' && approval.connector ? `${connectorLabel(approval.connector)} is allowed for this chat. Revoke it above the message box.`
|
|
6409
7612
|
: decision === 'allow-chat' ? 'Tekla reads are allowed for this chat. Revoke them from the Tekla box above the message.'
|
|
6410
7613
|
: decision === 'allow' ? 'Approved once.' : 'Action denied.');
|
|
6411
7614
|
await refreshConversation(snapshot.chatId, false);
|
|
@@ -6448,12 +7651,15 @@
|
|
|
6448
7651
|
}
|
|
6449
7652
|
|
|
6450
7653
|
/**
|
|
6451
|
-
* The cut a large data file gets, said on its chip, or ''. Measured in
|
|
6452
|
-
*
|
|
6453
|
-
*
|
|
7654
|
+
* The cut a large data file gets, said on its chip, or ''. Measured in the characters the server decoded
|
|
7655
|
+
* (`textChars`), because a UTF-16 file has about half as many characters as bytes and is read whole well
|
|
7656
|
+
* past 16,000 bytes (#1889). A file stored before that was recorded falls back to bytes: a UTF-8 file never
|
|
7657
|
+
* has more characters than bytes, so one at or under the limit is always read whole, and "up to" keeps the
|
|
7658
|
+
* sentence true for one just over it.
|
|
6454
7659
|
*/
|
|
6455
7660
|
function dataCutTip(attachment) {
|
|
6456
|
-
|
|
7661
|
+
const size = Number.isFinite(attachment.textChars) ? attachment.textChars : (attachment.bytes || 0);
|
|
7662
|
+
if (!DATA_TYPES.has(attachment.mediaType) || size <= MAX_DATA_TEXT_CHARS) return '';
|
|
6457
7663
|
return 'Large file. The AI reads up to its first 16,000 characters.';
|
|
6458
7664
|
}
|
|
6459
7665
|
|
|
@@ -6461,19 +7667,42 @@
|
|
|
6461
7667
|
* Can FloLess read this data file, and what is it? The browser-side twin of server/attachment-text.ts
|
|
6462
7668
|
* (isDwg + sniffTextKind), run on the WHOLE file before anything in the batch uploads, so a refused
|
|
6463
7669
|
* file never reaches the server (#1853). A parity test runs both over the same fixtures.
|
|
6464
|
-
* Returns 'dwg', 'ifc', 'dxf', 'text', or null for a file that is not readable text.
|
|
7670
|
+
* Returns 'dwg', 'ifc', 'dxf', 'text', 'utf16' (a UTF-16 file that could not be read), or null for a file that is not readable text.
|
|
6465
7671
|
*/
|
|
6466
7672
|
function sniffDataFile(bytes) {
|
|
6467
7673
|
// A DWG is named only when the file is not text: a CSV may begin "AC1234,…" (isDwg).
|
|
6468
7674
|
const dwg = bytes.length >= 6 && bytes[0] === 0x41 && bytes[1] === 0x43
|
|
6469
7675
|
&& [2, 3, 4, 5].every((i) => bytes[i] >= 0x30 && bytes[i] <= 0x39);
|
|
6470
7676
|
const kind = sniffTextBytes(bytes);
|
|
6471
|
-
|
|
7677
|
+
if (kind) return kind;
|
|
7678
|
+
// A UTF-16 file (FF FE / FE FF) the sniffer could not read is named, so the refusal can say "save it as CSV UTF-8" (#1889).
|
|
7679
|
+
if (bytes.length >= 2 && ((bytes[0] === 0xff && bytes[1] === 0xfe) || (bytes[0] === 0xfe && bytes[1] === 0xff))) return 'utf16';
|
|
7680
|
+
return dwg ? 'dwg' : null;
|
|
6472
7681
|
}
|
|
6473
7682
|
|
|
6474
7683
|
/** The text half of sniffDataFile: 'ifc', 'dxf', 'text', or null (server/attachment-text.ts sniffTextKind). */
|
|
6475
7684
|
function sniffTextBytes(bytes) {
|
|
6476
|
-
if (!bytes.length
|
|
7685
|
+
if (!bytes.length) return null;
|
|
7686
|
+
const headKind = (head) => head.startsWith('ISO-10303-21') ? 'ifc' : /^\s*0\s*[\r\n]+\s*SECTION/.test(head) ? 'dxf' : 'text';
|
|
7687
|
+
// A UTF-16 file (Excel "Unicode Text") is full of NULs by design: judge its DECODED text (server decodeUtf16, #1889).
|
|
7688
|
+
if ((bytes[0] === 0xff && bytes[1] === 0xfe) || (bytes[0] === 0xfe && bytes[1] === 0xff)) {
|
|
7689
|
+
let body = bytes.subarray(2);
|
|
7690
|
+
if (body.length % 2) return null;
|
|
7691
|
+
if (bytes[0] === 0xfe) {
|
|
7692
|
+
body = new Uint8Array(body);
|
|
7693
|
+
for (let i = 0; i < body.length; i += 2) { const t = body[i]; body[i] = body[i + 1]; body[i + 1] = t; }
|
|
7694
|
+
}
|
|
7695
|
+
let text;
|
|
7696
|
+
try { text = new TextDecoder('utf-16le', { fatal: true }).decode(body); } catch { return null; }
|
|
7697
|
+
if (!text.length || text.includes('\0')) return null;
|
|
7698
|
+
let readable = 0;
|
|
7699
|
+
for (let i = 0; i < text.length; i++) {
|
|
7700
|
+
const c = text.charCodeAt(i);
|
|
7701
|
+
if (c === 0x09 || c === 0x0a || c === 0x0d || (c >= 0x20 && c !== 0x7f)) readable++;
|
|
7702
|
+
}
|
|
7703
|
+
return readable / text.length <= 0.9 ? null : headKind(text.slice(0, 512));
|
|
7704
|
+
}
|
|
7705
|
+
if (bytes.includes(0)) return null;
|
|
6477
7706
|
let printable = 0;
|
|
6478
7707
|
for (const byte of bytes) {
|
|
6479
7708
|
if (byte === 0x09 || byte === 0x0a || byte === 0x0d || (byte >= 0x20 && byte !== 0x7f)) printable++;
|
|
@@ -6484,9 +7713,7 @@
|
|
|
6484
7713
|
if (!utf8 && bytes.filter((byte) => byte >= 0x80).length / bytes.length > 0.3) return null;
|
|
6485
7714
|
let head = '';
|
|
6486
7715
|
for (const byte of bytes.subarray(0, 512)) head += String.fromCharCode(byte);
|
|
6487
|
-
|
|
6488
|
-
if (/^\s*0\s*[\r\n]+\s*SECTION/.test(head)) return 'dxf';
|
|
6489
|
-
return 'text';
|
|
7716
|
+
return headKind(head);
|
|
6490
7717
|
}
|
|
6491
7718
|
|
|
6492
7719
|
/**
|
|
@@ -6503,6 +7730,7 @@
|
|
|
6503
7730
|
return `“${file.name}” could not be read. Check that the file is still there, then attach it again. Nothing was attached.`;
|
|
6504
7731
|
}
|
|
6505
7732
|
if (kind === 'dwg') return `“${file.name}” is a DWG, which FloLess can’t read. Export it as IFC or PDF and attach that instead. Nothing was sent.`;
|
|
7733
|
+
if (kind === 'utf16') return `“${file.name}” is a UTF-16 text file that FloLess couldn’t read. Save it as “CSV UTF-8” and attach that instead. Nothing was sent.`;
|
|
6506
7734
|
if (kind) return null;
|
|
6507
7735
|
if (String(file.type || '').startsWith('image/')) {
|
|
6508
7736
|
return `“${file.name}” is a picture format FloLess can’t send. Save it as PNG, JPEG or WebP and attach that instead. Nothing was sent.`;
|
|
@@ -6510,6 +7738,33 @@
|
|
|
6510
7738
|
return `“${file.name}” isn’t a file type FloLess can read. Attach a picture, PDF, IFC, DXF, or a text file such as CSV. Nothing was sent.`;
|
|
6511
7739
|
}
|
|
6512
7740
|
|
|
7741
|
+
/**
|
|
7742
|
+
* The browser twin of server/attachment-text.ts pictureMismatchSentence (#1888): a file the browser
|
|
7743
|
+
* calls a picture or PDF is only that when its first bytes say so, so a DWG renamed .pdf is turned
|
|
7744
|
+
* away at the chooser. Returns the plain sentence, or null when the bytes match the declared type.
|
|
7745
|
+
*/
|
|
7746
|
+
async function pictureFileRefusal(file) {
|
|
7747
|
+
let bytes;
|
|
7748
|
+
try { bytes = new Uint8Array(await file.slice(0, 1024).arrayBuffer()); }
|
|
7749
|
+
catch (error) {
|
|
7750
|
+
console.warn('[ai-chat] a chosen file could not be read', error);
|
|
7751
|
+
return `“${file.name}” could not be read. Check that the file is still there, then attach it again. Nothing was attached.`;
|
|
7752
|
+
}
|
|
7753
|
+
const at = (offset, sig) => sig.every((byte, i) => bytes[offset + i] === byte);
|
|
7754
|
+
const ascii = (text) => [...text].map((ch) => ch.charCodeAt(0));
|
|
7755
|
+
// A PDF may carry a short preamble: the header can sit anywhere in the first 1024 bytes (server twin).
|
|
7756
|
+
const hasPdfHeader = () => { for (let i = 0; i + 5 <= bytes.length; i++) if (at(i, ascii('%PDF-'))) return true; return false; };
|
|
7757
|
+
const kind = at(0, [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]) ? 'image/png'
|
|
7758
|
+
: at(0, [0xff, 0xd8, 0xff]) ? 'image/jpeg'
|
|
7759
|
+
: at(0, ascii('RIFF')) && at(8, ascii('WEBP')) ? 'image/webp'
|
|
7760
|
+
: hasPdfHeader() ? 'application/pdf' : null;
|
|
7761
|
+
if (kind === file.type) return null;
|
|
7762
|
+
const dwg = bytes.length >= 6 && bytes[0] === 0x41 && bytes[1] === 0x43 && [2, 3, 4, 5].every((i) => bytes[i] >= 0x30 && bytes[i] <= 0x39);
|
|
7763
|
+
if (dwg) return `“${file.name}” is a DWG, which FloLess can’t read. Export it as IFC or PDF and attach that instead. Nothing was sent.`;
|
|
7764
|
+
const words = { 'image/png': 'a real PNG picture', 'image/jpeg': 'a real JPEG picture', 'image/webp': 'a real WebP picture', 'application/pdf': 'a real PDF' }[file.type] || 'a real picture';
|
|
7765
|
+
return `“${file.name}” doesn’t look like ${words} inside, so FloLess can’t send it. Save or export it again from the program that made it, then attach it. Nothing was sent.`;
|
|
7766
|
+
}
|
|
7767
|
+
|
|
6513
7768
|
/**
|
|
6514
7769
|
* An error whose message is already the whole plain sentence the person should read. Without the mark
|
|
6515
7770
|
* errorMessage() replaces an unrecognised message with "FloLess could not complete this chat action",
|
|
@@ -6562,6 +7817,11 @@
|
|
|
6562
7817
|
if (!sameChat(snapshot)) return;
|
|
6563
7818
|
if (refusal) { report(plainError(refusal)); return; }
|
|
6564
7819
|
}
|
|
7820
|
+
for (const file of incoming.filter((item) => !isData(item))) {
|
|
7821
|
+
const refusal = await pictureFileRefusal(file);
|
|
7822
|
+
if (!sameChat(snapshot)) return;
|
|
7823
|
+
if (refusal) { report(plainError(refusal)); return; }
|
|
7824
|
+
}
|
|
6565
7825
|
for (const file of incoming) {
|
|
6566
7826
|
const data = await fileBase64(file);
|
|
6567
7827
|
if (!sameChat(snapshot)) return;
|
|
@@ -6618,7 +7878,7 @@
|
|
|
6618
7878
|
}
|
|
6619
7879
|
if (!sameScope(scope, generation)) return;
|
|
6620
7880
|
state.chats = result.chats || [];
|
|
6621
|
-
state.unreadableChats = result.unreadableChats || [];
|
|
7881
|
+
state.unreadableChats = result.unreadableChats || []; noteMovedChats(result.movedChats);
|
|
6622
7882
|
const active = state.chats.find((item) => item.chatId === state.chat?.chatId);
|
|
6623
7883
|
if (active && state.chat) {
|
|
6624
7884
|
// An event-stream completion can win the race against this list request. Never let a
|
|
@@ -6765,9 +8025,22 @@
|
|
|
6765
8025
|
|
|
6766
8026
|
async function openConversation(chatId, options = {}) {
|
|
6767
8027
|
await refreshScope();
|
|
8028
|
+
if (options.owner !== undefined) {
|
|
8029
|
+
const owner = options.owner;
|
|
8030
|
+
const validId = (id) => typeof id === 'string' && !!id && id.length <= 200;
|
|
8031
|
+
if (!owner || typeof owner !== 'object'
|
|
8032
|
+
|| !(owner.kind === 'workspace' || owner.kind === 'project' && validId(owner.projectId)
|
|
8033
|
+
|| owner.kind === 'workflow' && validId(owner.workflowId))) throw new Error('That conversation has no valid home to open.');
|
|
8034
|
+
if (scopeKey({ owner }) !== scopeKey(state.scope)) {
|
|
8035
|
+
if (typeof window.flolessWorkspaces?.openChatOwner !== 'function') throw new Error('Open the project or workflow this conversation belongs to, then choose Show in chat again.');
|
|
8036
|
+
await window.flolessWorkspaces.openChatOwner(owner);
|
|
8037
|
+
await refreshScope(true);
|
|
8038
|
+
}
|
|
8039
|
+
if (scopeKey({ owner }) !== scopeKey(state.scope)) throw new Error('The conversation’s home could not be opened. Try Show in chat again.');
|
|
8040
|
+
}
|
|
6768
8041
|
if (!state.scope?.owner) throw new Error('Open this conversation’s project or workflow, then try again.');
|
|
6769
|
-
//
|
|
6770
|
-
if (typeof options.projectId === 'string' && (state.scope.owner.kind !== 'project' || state.scope.owner.projectId !== options.projectId)) {
|
|
8042
|
+
// Legacy object cards name only their project. New cross-project pins carry the server-resolved chat home.
|
|
8043
|
+
if (options.owner === undefined && typeof options.projectId === 'string' && (state.scope.owner.kind !== 'project' || state.scope.owner.projectId !== options.projectId)) {
|
|
6771
8044
|
throw new Error('Open this project in Workspaces to see that conversation.');
|
|
6772
8045
|
}
|
|
6773
8046
|
if (typeof options.ownerKey === 'string' && scopeKey(state.scope) !== options.ownerKey) {
|
|
@@ -6775,7 +8048,9 @@
|
|
|
6775
8048
|
}
|
|
6776
8049
|
window.flolessBridge?.revealAiChat?.();
|
|
6777
8050
|
ui.tab.click();
|
|
8051
|
+
const requestedScope = scopeKey(state.scope);
|
|
6778
8052
|
const listed = await request(`/api/chat/conversations?${ownerQuery()}`);
|
|
8053
|
+
if (scopeKey(state.scope) !== requestedScope) throw new Error('The project or workflow changed while this conversation was opening. Choose Show in chat again.');
|
|
6779
8054
|
state.chats = listed.chats || [];
|
|
6780
8055
|
paintHistory(); paintUnread();
|
|
6781
8056
|
const messageEventId = typeof options.messageEventId === 'string' ? options.messageEventId : undefined;
|
|
@@ -6913,6 +8188,434 @@
|
|
|
6913
8188
|
}
|
|
6914
8189
|
|
|
6915
8190
|
// Ends this chat's standing Tekla read allowance. Nothing to confirm: it only removes permission.
|
|
8191
|
+
// #1907: the connectors allowed for this conversation, each with its own Revoke. Repainted only when the list changes,
|
|
8192
|
+
// so a click is never swapped out from under the pointer.
|
|
8193
|
+
function paintConnectorAllowance() {
|
|
8194
|
+
const host = ui.connectors;
|
|
8195
|
+
if (!host) return;
|
|
8196
|
+
const chat = state.chat;
|
|
8197
|
+
// #1907: the line exists only while this chat's own connectors are on; with them off, nothing can call.
|
|
8198
|
+
const on = Boolean(chat && !chat.archivedAt && chat.settings?.useOwnConnectors === true && !chat.integrationBindings?.length);
|
|
8199
|
+
const allowed = on && Array.isArray(chat.connectorAllowance?.allowed) ? chat.connectorAllowance.allowed : [];
|
|
8200
|
+
const busy = Boolean(chat?.activeTurn) || state.ownConnectorsSaving === true;
|
|
8201
|
+
const painted = `${chat?.chatId || ''}|${on}|${busy}|${chat?.provider || ''}|${allowed.map(connectorKey).join(',')}|${state.connectorRevoking || ''}`;
|
|
8202
|
+
if (host.dataset.painted === painted) return;
|
|
8203
|
+
host.dataset.painted = painted;
|
|
8204
|
+
host.replaceChildren();
|
|
8205
|
+
host.hidden = !on;
|
|
8206
|
+
if (!on) return;
|
|
8207
|
+
const provider = providerLabels[chat.provider] || 'Claude or Codex';
|
|
8208
|
+
const status = document.createElement('span');
|
|
8209
|
+
status.className = 'ai-chat-connectors-status';
|
|
8210
|
+
status.textContent = `Your ${provider} connectors are on`;
|
|
8211
|
+
const off = button('Turn off', 'shell.chat-own-connectors-off', 'ai-chat-units-change');
|
|
8212
|
+
off.setAttribute('aria-label', `Turn off your ${provider} connectors for this chat`);
|
|
8213
|
+
off.disabled = busy;
|
|
8214
|
+
const offBlocked = busy ? 'Wait for the current AI reply to finish before changing this.' : '';
|
|
8215
|
+
off.dataset.tip = offBlocked || 'The AI stops using your own connectors in this chat. You can turn them on again in chat settings.';
|
|
8216
|
+
if (offBlocked) off.dataset.blockedReason = offBlocked;
|
|
8217
|
+
off.addEventListener('click', () => { void turnOffOwnConnectors(); });
|
|
8218
|
+
host.append(status, off);
|
|
8219
|
+
if (!allowed.length) return;
|
|
8220
|
+
const title = document.createElement('span');
|
|
8221
|
+
title.className = 'ai-chat-connectors-title';
|
|
8222
|
+
title.textContent = 'Allowed for this chat:';
|
|
8223
|
+
host.append(title);
|
|
8224
|
+
for (const entry of allowed) {
|
|
8225
|
+
const pill = document.createElement('span');
|
|
8226
|
+
pill.className = 'ai-chat-connector-pill';
|
|
8227
|
+
const name = document.createElement('span');
|
|
8228
|
+
name.textContent = connectorLabel(entry);
|
|
8229
|
+
const key = connectorKey(entry);
|
|
8230
|
+
const revoke = button('Revoke', `shell.chat-connector-allowance-revoke#${key}`, 'ai-chat-connector-revoke');
|
|
8231
|
+
revoke.dataset.commandInstanceLabel = connectorLabel(entry);
|
|
8232
|
+
revoke.setAttribute('aria-label', `Revoke ${connectorLabel(entry)} for this chat`);
|
|
8233
|
+
revoke.dataset.tip = `${connectorLabel(entry)} will ask you again before it runs in this chat.`;
|
|
8234
|
+
revoke.disabled = state.connectorRevoking === key;
|
|
8235
|
+
revoke.addEventListener('click', () => { void revokeConnectorAllowance(entry); });
|
|
8236
|
+
pill.append(name, revoke);
|
|
8237
|
+
host.append(pill);
|
|
8238
|
+
}
|
|
8239
|
+
}
|
|
8240
|
+
|
|
8241
|
+
function paintScopeControl() {
|
|
8242
|
+
if (!ui.scopeControls) return;
|
|
8243
|
+
const chat = state.chat;
|
|
8244
|
+
ui.scopeControls.hidden = !chat || Boolean(chat.archivedAt);
|
|
8245
|
+
if (!chat) { closeScopePicker(); return; }
|
|
8246
|
+
if (state.scopeViewChatId !== chat.chatId) { state.scopeView = null; closeScopePicker(); }
|
|
8247
|
+
if (state.scopeView && state.scopeView.scope.revision !== (chat.scopeRevision ?? 0)) {
|
|
8248
|
+
state.scopeView = null; closeScopePicker();
|
|
8249
|
+
}
|
|
8250
|
+
const count = Array.isArray(chat.scopeExtensions) ? chat.scopeExtensions.length : 0;
|
|
8251
|
+
const home = state.scopeView?.scope?.home?.label || state.scope?.label || 'Home';
|
|
8252
|
+
ui.scopeToggle.textContent = `Scope · ${home}${count ? ` + ${count}` : ''}`;
|
|
8253
|
+
ui.scopeToggle.dataset.tip = 'See the conversation’s home folder and add or remove other projects and workflows.';
|
|
8254
|
+
ui.scopeToggle.disabled = state.loading;
|
|
8255
|
+
if (ui.scopeToggle.disabled) ui.scopeToggle.dataset.blockedReason = 'The conversation is still loading.';
|
|
8256
|
+
else delete ui.scopeToggle.dataset.blockedReason;
|
|
8257
|
+
const disclosure = chat.settings?.permissionProfile === 'read-only'
|
|
8258
|
+
? 'Read only: the AI’s file tools cannot change files. Commands keep their own approvals and may authorize file changes.'
|
|
8259
|
+
: chat.settings?.permissionProfile === 'full-access' ? 'Full access is on. The AI can change files without asking.'
|
|
8260
|
+
: chat.changeAllowance?.allowedForChat ? 'File changes in scope, including folders you add later, are allowed for this chat.' : '';
|
|
8261
|
+
if (ui.scopeDisclosure.textContent !== disclosure) ui.scopeDisclosure.textContent = disclosure;
|
|
8262
|
+
// Poll/SSE can change permissions or pause a reply while Scope stays open. Refresh only when
|
|
8263
|
+
// these states change, retaining its selected add choice and focus on an enabled control.
|
|
8264
|
+
const picker = ui.scopePicker;
|
|
8265
|
+
const availability = JSON.stringify([Boolean(chat.activeTurn), Boolean(chat.pendingApproval), Boolean(state.scopeEditing), chat.settings?.permissionProfile, Boolean(chat.changeAllowance?.allowedForChat)]);
|
|
8266
|
+
if (state.scopePickerOpen && state.scopeView && picker?.dataset.availability !== availability) {
|
|
8267
|
+
const focused = picker.contains(document.activeElement) ? document.activeElement?.dataset?.commandId : null;
|
|
8268
|
+
paintScopePicker();
|
|
8269
|
+
if (focused) {
|
|
8270
|
+
const buttons = [...picker.querySelectorAll('button')];
|
|
8271
|
+
const target = buttons.find((node) => node.dataset.commandId === focused && !node.disabled)
|
|
8272
|
+
|| buttons.find((node) => !node.disabled);
|
|
8273
|
+
target?.focus();
|
|
8274
|
+
}
|
|
8275
|
+
}
|
|
8276
|
+
}
|
|
8277
|
+
|
|
8278
|
+
function closeScopePicker(restoreFocus = false) {
|
|
8279
|
+
state.scopePickerOpen = false; state.scopeChoice = null;
|
|
8280
|
+
if (ui.scopePicker) { ui.scopePicker.hidden = true; ui.scopePicker.replaceChildren(); }
|
|
8281
|
+
ui.scopeToggle?.setAttribute('aria-expanded', 'false');
|
|
8282
|
+
if (restoreFocus) ui.scopeToggle?.focus();
|
|
8283
|
+
}
|
|
8284
|
+
|
|
8285
|
+
async function openScopePicker() {
|
|
8286
|
+
if (state.scopePickerOpen) { closeScopePicker(true); return; }
|
|
8287
|
+
const snapshot = captureChat();
|
|
8288
|
+
if (!snapshot || state.chat.archivedAt) return;
|
|
8289
|
+
closePicker(); state.scopeChoice = null; state.scopePickerOpen = true; state.scopeViewChatId = snapshot.chatId;
|
|
8290
|
+
ui.scopePicker.hidden = false; ui.scopeToggle.setAttribute('aria-expanded', 'true');
|
|
8291
|
+
ui.scopePicker.textContent = 'Loading conversation scope…';
|
|
8292
|
+
try {
|
|
8293
|
+
const result = await request(`/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/scope?${ownerQuery(snapshot.scope.owner)}`);
|
|
8294
|
+
if (!sameChat(snapshot) || !state.scopePickerOpen) return;
|
|
8295
|
+
state.scopeView = result; state.scopeViewChatId = snapshot.chatId;
|
|
8296
|
+
state.chat = { ...state.chat, scopeExtensions: result.scope.extensions.map((entry) => entry.target), scopeRevision: result.scope.revision, changeAllowance: result.changeAllowance };
|
|
8297
|
+
paintScopePicker(); paintScopeControl();
|
|
8298
|
+
ui.scopePicker.querySelector('button')?.focus();
|
|
8299
|
+
} catch (error) {
|
|
8300
|
+
if (sameChat(snapshot) && state.scopePickerOpen) { closeScopePicker(true); report(error, 'Could not load conversation scope'); }
|
|
8301
|
+
}
|
|
8302
|
+
}
|
|
8303
|
+
|
|
8304
|
+
function paintScopePicker() {
|
|
8305
|
+
const host = ui.scopePicker;
|
|
8306
|
+
if (!host || !state.scopePickerOpen || !state.scopeView) return;
|
|
8307
|
+
const view = state.scopeView;
|
|
8308
|
+
const profile = state.chat?.settings?.permissionProfile;
|
|
8309
|
+
const readOnly = profile === 'read-only';
|
|
8310
|
+
const globalAllowance = Boolean(state.chat?.changeAllowance?.allowedForChat);
|
|
8311
|
+
host.dataset.availability = JSON.stringify([Boolean(state.chat?.activeTurn), Boolean(state.chat?.pendingApproval), Boolean(state.scopeEditing), profile, globalAllowance]);
|
|
8312
|
+
host.replaceChildren();
|
|
8313
|
+
const heading = document.createElement('strong'); heading.textContent = 'Conversation scope';
|
|
8314
|
+
const close = button('×', 'shell.chat-scope-close', 'ai-chat-scope-close');
|
|
8315
|
+
close.setAttribute('aria-label', 'Close conversation scope'); close.dataset.tip = 'Close conversation scope';
|
|
8316
|
+
close.addEventListener('click', () => closeScopePicker(true));
|
|
8317
|
+
const head = document.createElement('div'); head.className = 'ai-chat-scope-head'; head.append(heading, close); host.append(head);
|
|
8318
|
+
const note = document.createElement('p'); note.className = 'ai-chat-scope-note';
|
|
8319
|
+
note.textContent = readOnly ? 'The AI’s file tools cannot change files while Read only is on. Commands keep their own approvals and may authorize file changes. Scope adds folders and project data; it does not limit file reads.'
|
|
8320
|
+
+ (globalAllowance ? ' Your saved file-change allowance does not override Read only.' : '')
|
|
8321
|
+
: profile === 'full-access' ? 'Full access is on. The AI can change files without asking.'
|
|
8322
|
+
: globalAllowance ? 'File changes in this scope, including folders you add later, are allowed without asking. Commands and tools keep their own approvals. Scope does not limit file reads.'
|
|
8323
|
+
: 'File edits outside your home folder ask for approval unless you allow file changes for this chat. Scope adds folders and project data to this conversation; it does not limit file reads. Your home folder keeps its native provider permissions.';
|
|
8324
|
+
host.append(note);
|
|
8325
|
+
if (view.scope.dropped?.length) {
|
|
8326
|
+
const dropped = document.createElement('p'); dropped.className = 'ai-chat-scope-note'; dropped.setAttribute('role', 'status');
|
|
8327
|
+
dropped.textContent = 'An added project or workflow is no longer available and has been removed from this conversation’s scope.';
|
|
8328
|
+
host.append(dropped);
|
|
8329
|
+
}
|
|
8330
|
+
const home = document.createElement('div'); home.className = 'ai-chat-scope-row';
|
|
8331
|
+
const homeName = document.createElement('span'); homeName.textContent = view.scope.home.label;
|
|
8332
|
+
const pinned = document.createElement('small'); pinned.textContent = 'Home'; home.append(homeName, pinned); host.append(home);
|
|
8333
|
+
for (const entry of view.scope.extensions) {
|
|
8334
|
+
const row = document.createElement('div'); row.className = 'ai-chat-scope-row';
|
|
8335
|
+
const name = document.createElement('span'); name.textContent = `${entry.target.kind === 'project' ? 'Project' : 'Workflow'} · ${entry.label}`;
|
|
8336
|
+
const targetId = entry.target.kind === 'project' ? entry.target.projectId : entry.target.workflowId;
|
|
8337
|
+
const remove = button('Remove', `shell.chat-scope-remove#${commandInstance(`${entry.target.kind}:${targetId}`)}`, 'ai-chat-scope-action');
|
|
8338
|
+
remove.dataset.commandInstanceLabel = entry.label;
|
|
8339
|
+
remove.setAttribute('aria-label', `Remove ${entry.target.kind} ${entry.label} from this conversation’s scope`);
|
|
8340
|
+
const removeBlocked = state.scopeEditing ? 'Saving conversation scope…'
|
|
8341
|
+
: state.chat?.activeTurn && !state.chat?.pendingApproval ? 'Wait for the current reply to finish before removing scope.' : '';
|
|
8342
|
+
remove.disabled = Boolean(removeBlocked);
|
|
8343
|
+
if (removeBlocked) { remove.dataset.blockedReason = removeBlocked; remove.dataset.tip = removeBlocked; }
|
|
8344
|
+
remove.addEventListener('click', () => { void mutateScope('remove', entry.target, entry.label); });
|
|
8345
|
+
row.append(name, remove); host.append(row);
|
|
8346
|
+
}
|
|
8347
|
+
if (state.chat?.activeTurn) {
|
|
8348
|
+
const busy = document.createElement('p'); busy.className = 'ai-chat-scope-note';
|
|
8349
|
+
busy.textContent = state.chat.pendingApproval ? 'You can remove a folder while this reply waits for approval. Add folders after the reply finishes.' : 'Wait for the current reply to finish before changing scope.';
|
|
8350
|
+
host.append(busy);
|
|
8351
|
+
}
|
|
8352
|
+
if (state.scopeChoice) {
|
|
8353
|
+
const choice = state.scopeChoice;
|
|
8354
|
+
const choiceKey = choice.target.kind === 'project' ? choice.target.projectId : choice.target.workflowId;
|
|
8355
|
+
const question = document.createElement('p'); question.className = 'ai-chat-scope-note';
|
|
8356
|
+
const writeProfile = state.chat?.owner?.kind === 'workspace' ? 'Make changes (asks first)' : 'Working folder write';
|
|
8357
|
+
question.textContent = `Add ${choice.target.kind} “${choice.label}” to this conversation?${globalAllowance ? readOnly
|
|
8358
|
+
? ` If you choose ${writeProfile}, file changes here will also be allowed without asking.`
|
|
8359
|
+
: ' File changes here will also be allowed without asking.' : ''}`;
|
|
8360
|
+
const add = button(globalAllowance ? readOnly ? 'Add scope for later file changes' : 'Add scope and allow file changes' : 'Add scope', `shell.chat-scope-add#${commandInstance(`${choice.target.kind}:${choiceKey}`)}`, 'ai-chat-scope-action');
|
|
8361
|
+
add.dataset.commandInstanceLabel = choice.label; add.disabled = state.scopeEditing || Boolean(state.chat?.activeTurn);
|
|
8362
|
+
if (add.disabled) { add.dataset.blockedReason = state.scopeEditing ? 'Saving conversation scope…' : 'Wait for the current reply to finish before adding scope.'; add.dataset.tip = add.dataset.blockedReason; }
|
|
8363
|
+
add.addEventListener('click', () => { void mutateScope('add', choice.target, choice.label); });
|
|
8364
|
+
const back = button('Back', 'shell.chat-scope-back', 'ai-chat-scope-action'); back.disabled = state.scopeEditing;
|
|
8365
|
+
if (back.disabled) { back.dataset.blockedReason = 'Saving conversation scope…'; back.dataset.tip = back.dataset.blockedReason; }
|
|
8366
|
+
back.addEventListener('click', () => { state.scopeChoice = null; paintScopePicker(); host.querySelector('button')?.focus(); });
|
|
8367
|
+
host.append(question, add, back);
|
|
8368
|
+
} else {
|
|
8369
|
+
const title = document.createElement('strong'); title.textContent = 'Add project or workflow'; host.append(title);
|
|
8370
|
+
const options = (view.options || []).filter((option) => !option.inScope);
|
|
8371
|
+
if (!options.length) {
|
|
8372
|
+
const empty = document.createElement('p'); empty.className = 'ai-chat-scope-note'; empty.textContent = 'No other projects or workflows to add.'; host.append(empty);
|
|
8373
|
+
}
|
|
8374
|
+
for (const option of options) {
|
|
8375
|
+
const key = option.target.kind === 'project' ? option.target.projectId : option.target.workflowId;
|
|
8376
|
+
const choose = button(`${option.target.kind === 'project' ? 'Project' : 'Workflow'} · ${option.label}`, `shell.chat-scope-choose#${commandInstance(`${option.target.kind}:${key}`)}`, 'ai-chat-choice');
|
|
8377
|
+
choose.dataset.commandInstanceLabel = option.label; choose.disabled = state.scopeEditing || Boolean(state.chat?.activeTurn);
|
|
8378
|
+
if (choose.disabled) { choose.dataset.blockedReason = state.scopeEditing ? 'Saving conversation scope…' : 'Wait for the current reply to finish before adding scope.'; choose.dataset.tip = choose.dataset.blockedReason; }
|
|
8379
|
+
choose.addEventListener('click', () => { state.scopeChoice = option; paintScopePicker(); host.querySelector('[data-command-id^="shell.chat-scope-add#"]')?.focus(); });
|
|
8380
|
+
host.append(choose);
|
|
8381
|
+
}
|
|
8382
|
+
}
|
|
8383
|
+
}
|
|
8384
|
+
|
|
8385
|
+
async function mutateScope(verb, target, label) {
|
|
8386
|
+
const snapshot = captureChat();
|
|
8387
|
+
if (!snapshot || state.scopeEditing || !state.scopeView) return;
|
|
8388
|
+
const view = state.scopeView;
|
|
8389
|
+
state.scopeEditing = true; paintScopePicker();
|
|
8390
|
+
try {
|
|
8391
|
+
const result = await request(`/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/scope/${verb}`, {
|
|
8392
|
+
method: 'POST', body: JSON.stringify({ owner: snapshot.scope.owner, target, revision: view.scope.revision,
|
|
8393
|
+
...(verb === 'add' ? { allowanceRevision: view.changeAllowance?.revision ?? 0 } : {}) }),
|
|
8394
|
+
});
|
|
8395
|
+
if (!sameChat(snapshot)) return;
|
|
8396
|
+
state.scopeView = result; state.scopeViewChatId = snapshot.chatId; state.scopeChoice = null;
|
|
8397
|
+
state.chat = { ...state.chat, scopeExtensions: result.scope.extensions.map((entry) => entry.target), scopeRevision: result.scope.revision, changeAllowance: result.changeAllowance };
|
|
8398
|
+
announce(verb === 'add' ? `${label} added to this conversation’s scope.` : `${label} removed from this conversation’s scope. Changes already made are kept.`);
|
|
8399
|
+
paintScopeControl(); paintChangeAllowance();
|
|
8400
|
+
} catch (error) {
|
|
8401
|
+
if (sameChat(snapshot)) {
|
|
8402
|
+
report(error, 'Could not change conversation scope');
|
|
8403
|
+
// A different tab can change either revision while this confirmation is open.
|
|
8404
|
+
// Refresh the disclosed permission before offering another Add; never retry silently.
|
|
8405
|
+
if (error?.status === 409 && state.scopePickerOpen) {
|
|
8406
|
+
try {
|
|
8407
|
+
const current = await request(`/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/scope?${ownerQuery(snapshot.scope.owner)}`);
|
|
8408
|
+
if (sameChat(snapshot) && state.scopePickerOpen) {
|
|
8409
|
+
state.scopeView = current; state.scopeChoice = null;
|
|
8410
|
+
state.chat = { ...state.chat, scopeExtensions: current.scope.extensions.map((entry) => entry.target), scopeRevision: current.scope.revision, changeAllowance: current.changeAllowance };
|
|
8411
|
+
paintScopeControl(); paintChangeAllowance();
|
|
8412
|
+
}
|
|
8413
|
+
} catch { /* Keep the original refusal visible; the person can reopen Scope to retry. */ }
|
|
8414
|
+
}
|
|
8415
|
+
}
|
|
8416
|
+
} finally {
|
|
8417
|
+
state.scopeEditing = false;
|
|
8418
|
+
if (sameChat(snapshot) && state.scopePickerOpen) { paintScopePicker(); ui.scopePicker.querySelector('button')?.focus(); }
|
|
8419
|
+
}
|
|
8420
|
+
}
|
|
8421
|
+
|
|
8422
|
+
// Legacy per-owner allowances remain removable when no conversation-wide file allowance covers them.
|
|
8423
|
+
function paintChangeAllowance() {
|
|
8424
|
+
const host = ui.changeAllowance;
|
|
8425
|
+
if (!host) return;
|
|
8426
|
+
const chat = state.chat;
|
|
8427
|
+
const allowed = chat && !chat.archivedAt && Array.isArray(chat.changeAllowance?.allowed)
|
|
8428
|
+
? chat.changeAllowance.allowed : [];
|
|
8429
|
+
const global = chat && !chat.archivedAt && chat.changeAllowance?.allowedForChat;
|
|
8430
|
+
const readOnly = chat?.settings?.permissionProfile === 'read-only';
|
|
8431
|
+
const painted = `${chat?.chatId || ''}|${allowed.map((entry) => entry.key).join(',')}|${Boolean(global)}|${readOnly}|${state.changeRevoking || ''}`;
|
|
8432
|
+
if (host.dataset.painted === painted) return;
|
|
8433
|
+
host.dataset.painted = painted;
|
|
8434
|
+
host.replaceChildren();
|
|
8435
|
+
host.hidden = !allowed.length && !global;
|
|
8436
|
+
if (!allowed.length && !global) return;
|
|
8437
|
+
if (global) {
|
|
8438
|
+
const copy = document.createElement('span'); copy.textContent = readOnly ? 'File-change allowance saved; Read only blocks file tools' : 'File changes allowed for this chat';
|
|
8439
|
+
const revoke = button('Revoke', 'shell.chat-change-allowance-revoke-all', 'ai-chat-connector-revoke');
|
|
8440
|
+
revoke.dataset.tip = 'Future file changes will ask again where your permission setting requires approval. Your home folder keeps its current permissions.';
|
|
8441
|
+
revoke.disabled = state.changeRevoking === 'all';
|
|
8442
|
+
if (revoke.disabled) revoke.dataset.blockedReason = 'Revoking file-change allowance…';
|
|
8443
|
+
revoke.addEventListener('click', () => { void revokeChangeAllowance({ key: null, label: 'file changes in this chat' }); });
|
|
8444
|
+
host.append(copy, revoke);
|
|
8445
|
+
// A legacy owner-specific Revoke would imply that folder stops being allowed, but the
|
|
8446
|
+
// conversation-wide grant still covers it. Its one Revoke ends every standing file grant.
|
|
8447
|
+
return;
|
|
8448
|
+
}
|
|
8449
|
+
const title = document.createElement('span');
|
|
8450
|
+
title.className = 'ai-chat-connectors-title';
|
|
8451
|
+
title.textContent = readOnly ? 'Saved change allowances; Read only blocks file tools:' : 'Changes allowed for this chat:';
|
|
8452
|
+
host.append(title);
|
|
8453
|
+
for (const entry of allowed) {
|
|
8454
|
+
const pill = document.createElement('span');
|
|
8455
|
+
pill.className = 'ai-chat-connector-pill';
|
|
8456
|
+
const name = document.createElement('span');
|
|
8457
|
+
name.textContent = entry.label;
|
|
8458
|
+
const revoke = button('Revoke', `shell.chat-change-allowance-revoke#${entry.key}`, 'ai-chat-connector-revoke');
|
|
8459
|
+
revoke.dataset.commandInstanceLabel = entry.label;
|
|
8460
|
+
revoke.setAttribute('aria-label', `Stop allowing changes to ${entry.label}`);
|
|
8461
|
+
revoke.dataset.tip = readOnly ? `Remove the saved allowance for ${entry.label}. Read only continues to block file tools.` : `The AI will ask you again before it changes ${entry.label}.`;
|
|
8462
|
+
revoke.disabled = state.changeRevoking === entry.key;
|
|
8463
|
+
if (revoke.disabled) revoke.dataset.blockedReason = 'Revoking file-change allowance…';
|
|
8464
|
+
revoke.addEventListener('click', () => { void revokeChangeAllowance(entry); });
|
|
8465
|
+
pill.append(name, revoke);
|
|
8466
|
+
host.append(pill);
|
|
8467
|
+
}
|
|
8468
|
+
}
|
|
8469
|
+
|
|
8470
|
+
async function revokeChangeAllowance(entry) {
|
|
8471
|
+
const snapshot = captureChat();
|
|
8472
|
+
if (!snapshot) return;
|
|
8473
|
+
const revokingKey = entry.key ?? 'all';
|
|
8474
|
+
state.changeRevoking = revokingKey;
|
|
8475
|
+
paintChangeAllowance();
|
|
8476
|
+
try {
|
|
8477
|
+
const result = await request(`/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/change-allowance/revoke`, {
|
|
8478
|
+
method: 'POST', body: JSON.stringify({ owner: snapshot.scope.owner, key: entry.key }),
|
|
8479
|
+
});
|
|
8480
|
+
if (!sameChat(snapshot)) return;
|
|
8481
|
+
// Only the server's own record, without that project, may say it ended.
|
|
8482
|
+
const updated = result?.chat;
|
|
8483
|
+
if (!updated || updated.chatId !== snapshot.chatId || (entry.key === null
|
|
8484
|
+
? updated.changeAllowance?.allowedForChat || (updated.changeAllowance?.allowed || []).length
|
|
8485
|
+
: (updated.changeAllowance?.allowed || []).some((row) => row.key === entry.key))) {
|
|
8486
|
+
report(new Error(`FloLess could not confirm that ${entry.label} will ask again. Choose Revoke again.`), 'Could not revoke');
|
|
8487
|
+
return;
|
|
8488
|
+
}
|
|
8489
|
+
state.chat = { ...state.chat, changeAllowance: updated.changeAllowance };
|
|
8490
|
+
if (state.scopeViewChatId === snapshot.chatId && state.scopeView) state.scopeView.changeAllowance = updated.changeAllowance;
|
|
8491
|
+
announce(entry.key === null ? 'File change approval is restored where your permission setting requires it. Your home folder keeps its current permissions. Actions already approved may finish.' : `The AI will ask you again before it changes ${entry.label}.`);
|
|
8492
|
+
state.changeRevoking = null;
|
|
8493
|
+
paintChangeAllowance();
|
|
8494
|
+
(ui.changeAllowance?.querySelector('.ai-chat-connector-revoke') || ui.input)?.focus();
|
|
8495
|
+
} catch (error) {
|
|
8496
|
+
if (sameChat(snapshot)) report(error, 'Could not revoke');
|
|
8497
|
+
} finally {
|
|
8498
|
+
if (state.changeRevoking === revokingKey) state.changeRevoking = null;
|
|
8499
|
+
paintChangeAllowance();
|
|
8500
|
+
}
|
|
8501
|
+
}
|
|
8502
|
+
|
|
8503
|
+
// #1900: the connection checks this conversation may run without asking, each with its own Revoke (and Revoke all).
|
|
8504
|
+
function checkGrantKey(grant) { return `${grant.agent}${grant.alias ? `.${grant.alias}` : ''}`; }
|
|
8505
|
+
function checkGrantLabel(grant) { return `${grant.name || grant.agent} · ${grant.identity || grant.alias || 'this computer'}`; }
|
|
8506
|
+
|
|
8507
|
+
function paintCheckAllowance() {
|
|
8508
|
+
const host = ui.checkAllowance;
|
|
8509
|
+
if (!host) return;
|
|
8510
|
+
const chat = state.chat;
|
|
8511
|
+
const grants = chat && !chat.archivedAt && Array.isArray(chat.integrationReadAllowance?.grants) ? chat.integrationReadAllowance.grants : [];
|
|
8512
|
+
const painted = `${chat?.chatId || ''}|${grants.map((grant) => `${checkGrantKey(grant)}:${grant.identity || ''}`).join(',')}|${state.checkRevoking || ''}`;
|
|
8513
|
+
if (host.dataset.painted === painted) return;
|
|
8514
|
+
host.dataset.painted = painted;
|
|
8515
|
+
host.replaceChildren();
|
|
8516
|
+
host.hidden = !grants.length;
|
|
8517
|
+
if (!grants.length) return;
|
|
8518
|
+
const title = document.createElement('span');
|
|
8519
|
+
title.className = 'ai-chat-connectors-title';
|
|
8520
|
+
title.textContent = 'Checks allowed for this chat:';
|
|
8521
|
+
host.append(title);
|
|
8522
|
+
for (const grant of grants) {
|
|
8523
|
+
const pill = document.createElement('span');
|
|
8524
|
+
pill.className = 'ai-chat-connector-pill';
|
|
8525
|
+
const name = document.createElement('span');
|
|
8526
|
+
name.textContent = checkGrantLabel(grant);
|
|
8527
|
+
const key = checkGrantKey(grant);
|
|
8528
|
+
const who = grant.name || grant.agent;
|
|
8529
|
+
const revoke = button('Revoke', `shell.chat-check-allowance-revoke#${key}`, 'ai-chat-connector-revoke');
|
|
8530
|
+
revoke.dataset.commandInstanceLabel = checkGrantLabel(grant);
|
|
8531
|
+
revoke.setAttribute('aria-label', `Stop allowing checks of ${checkGrantLabel(grant)}`);
|
|
8532
|
+
revoke.dataset.tip = `Chat will ask you again before it checks ${who}.`;
|
|
8533
|
+
revoke.disabled = Boolean(state.checkRevoking);
|
|
8534
|
+
revoke.addEventListener('click', () => { void revokeCheckAllowance(grant); });
|
|
8535
|
+
pill.append(name, revoke);
|
|
8536
|
+
host.append(pill);
|
|
8537
|
+
}
|
|
8538
|
+
if (grants.length > 1) {
|
|
8539
|
+
const all = button('Revoke all', 'shell.chat-check-allowance-revoke-all', 'ai-chat-connector-revoke');
|
|
8540
|
+
all.setAttribute('aria-label', 'Stop allowing every connection check in this chat');
|
|
8541
|
+
all.dataset.tip = 'Chat will ask you again before every connection check in this conversation.';
|
|
8542
|
+
all.disabled = Boolean(state.checkRevoking);
|
|
8543
|
+
all.addEventListener('click', () => { void revokeCheckAllowance(null); });
|
|
8544
|
+
host.append(all);
|
|
8545
|
+
}
|
|
8546
|
+
}
|
|
8547
|
+
|
|
8548
|
+
/** Ends one grant (or, with none named, all of them). Only the server's own record, without it, may say it ended. */
|
|
8549
|
+
async function revokeCheckAllowance(grant) {
|
|
8550
|
+
const snapshot = captureChat();
|
|
8551
|
+
if (!snapshot || state.checkRevoking) return;
|
|
8552
|
+
const key = grant ? checkGrantKey(grant) : '*';
|
|
8553
|
+
state.checkRevoking = key;
|
|
8554
|
+
paintCheckAllowance();
|
|
8555
|
+
try {
|
|
8556
|
+
const result = await request(`/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/integration-read-allowance/revoke`, {
|
|
8557
|
+
method: 'POST', body: JSON.stringify(grant ? { owner: snapshot.scope.owner, agent: grant.agent, alias: grant.alias ?? null } : { owner: snapshot.scope.owner }),
|
|
8558
|
+
});
|
|
8559
|
+
if (!sameChat(snapshot)) return;
|
|
8560
|
+
const updated = result?.chat;
|
|
8561
|
+
const left = updated?.integrationReadAllowance?.grants || [];
|
|
8562
|
+
if (!updated || updated.chatId !== snapshot.chatId || (grant ? left.some((row) => checkGrantKey(row) === key) : left.length)) {
|
|
8563
|
+
report(new Error(grant ? `FloLess could not confirm that checks of ${grant.name || grant.agent} will ask again. Choose Revoke again.`
|
|
8564
|
+
: 'FloLess could not confirm that every connection check will ask again. Choose Revoke all again.'), 'Could not revoke');
|
|
8565
|
+
return;
|
|
8566
|
+
}
|
|
8567
|
+
state.chat = { ...state.chat, integrationReadAllowance: updated.integrationReadAllowance };
|
|
8568
|
+
announce(grant ? `Chat will ask you again before it checks ${grant.name || grant.agent}.` : 'Chat will ask you again before every connection check.');
|
|
8569
|
+
state.checkRevoking = null;
|
|
8570
|
+
paintCheckAllowance();
|
|
8571
|
+
// The pressed Revoke is gone with its pill: keep keyboard focus on the next one, or on the message box.
|
|
8572
|
+
(ui.checkAllowance?.querySelector('.ai-chat-connector-revoke') || ui.input)?.focus();
|
|
8573
|
+
} catch (error) {
|
|
8574
|
+
if (sameChat(snapshot)) report(error, 'Could not revoke');
|
|
8575
|
+
} finally {
|
|
8576
|
+
if (state.checkRevoking === key) state.checkRevoking = null;
|
|
8577
|
+
paintCheckAllowance();
|
|
8578
|
+
}
|
|
8579
|
+
}
|
|
8580
|
+
|
|
8581
|
+
async function turnOffOwnConnectors() {
|
|
8582
|
+
state.ownConnectorsSaving = true;
|
|
8583
|
+
paintConnectorAllowance();
|
|
8584
|
+
try { await setOwnConnectors(false, { focusInput: true }); }
|
|
8585
|
+
finally { state.ownConnectorsSaving = false; paintConnectorAllowance(); }
|
|
8586
|
+
}
|
|
8587
|
+
|
|
8588
|
+
async function revokeConnectorAllowance(entry) {
|
|
8589
|
+
const snapshot = captureChat();
|
|
8590
|
+
if (!snapshot) return;
|
|
8591
|
+
const key = connectorKey(entry);
|
|
8592
|
+
state.connectorRevoking = key;
|
|
8593
|
+
paintConnectorAllowance();
|
|
8594
|
+
try {
|
|
8595
|
+
const result = await request(`/api/chat/conversations/${encodeURIComponent(snapshot.chatId)}/connector-allowance/revoke`, {
|
|
8596
|
+
method: 'POST', body: JSON.stringify({ owner: snapshot.scope.owner, connector: { provider: entry.provider, server: entry.server, app: entry.app ?? null } }),
|
|
8597
|
+
});
|
|
8598
|
+
if (!sameChat(snapshot)) return;
|
|
8599
|
+
// Only the server's own record, without that connector, may say it ended.
|
|
8600
|
+
const updated = result?.chat;
|
|
8601
|
+
if (!updated || updated.chatId !== snapshot.chatId || (updated.connectorAllowance?.allowed || []).some((row) => connectorKey(row) === key)) {
|
|
8602
|
+
report(new Error('FloLess could not confirm that this connector will ask again. Choose Revoke again.'), 'Could not revoke');
|
|
8603
|
+
return;
|
|
8604
|
+
}
|
|
8605
|
+
state.chat = { ...state.chat, connectorAllowance: updated.connectorAllowance };
|
|
8606
|
+
announce(`${connectorLabel(entry)} will ask you again in this chat.`);
|
|
8607
|
+
state.connectorRevoking = null;
|
|
8608
|
+
paintConnectorAllowance();
|
|
8609
|
+
// The pressed Revoke is gone with its pill: keep keyboard focus on the next one, or on the message box.
|
|
8610
|
+
(ui.connectors?.querySelector('.ai-chat-connector-revoke') || ui.input)?.focus();
|
|
8611
|
+
} catch (error) {
|
|
8612
|
+
if (sameChat(snapshot)) report(error, 'Could not revoke');
|
|
8613
|
+
} finally {
|
|
8614
|
+
if (state.connectorRevoking === key) state.connectorRevoking = null;
|
|
8615
|
+
paintConnectorAllowance();
|
|
8616
|
+
}
|
|
8617
|
+
}
|
|
8618
|
+
|
|
6916
8619
|
async function revokeTeklaAllowance() {
|
|
6917
8620
|
const chat = state.chat;
|
|
6918
8621
|
const snapshot = captureChat();
|
|
@@ -7051,7 +8754,7 @@
|
|
|
7051
8754
|
// The earlier model name is deliberately left out: the open model may have changed since, and
|
|
7052
8755
|
// the AI would repeat a stale name as current. A fresh read shows the name at that moment.
|
|
7053
8756
|
return `Earlier FloLess check: reading the open model name through the Tekla model library at ${receipt.sourcePath} `
|
|
7054
|
-
+ `worked (Tekla ${receipt.hostVersion}${checked}). The generated
|
|
8757
|
+
+ `worked (Tekla ${receipt.hostVersion}${checked}). The generated tool's commands remain unverified. `
|
|
7055
8758
|
+ 'You can ask to read the open model name or the parts I have selected in Tekla. Help me use these reads in this project.';
|
|
7056
8759
|
}
|
|
7057
8760
|
|
|
@@ -7064,8 +8767,8 @@
|
|
|
7064
8767
|
closeSource(); clearLiveStream(true);
|
|
7065
8768
|
state.chat = null; state.events = []; state.attachments = []; state.integrations = null; state.capability = null;
|
|
7066
8769
|
updateOffscreenActivity();
|
|
7067
|
-
//
|
|
7068
|
-
|
|
8770
|
+
// What the left chat painted above the composer is cleared by providerChooser(), which every route onto
|
|
8771
|
+
// the chooser runs (#1958) — not only this one.
|
|
7069
8772
|
}
|
|
7070
8773
|
|
|
7071
8774
|
// Graft receipt → unsent Chat draft. Opening performs no binding, sends nothing and never
|
|
@@ -7166,6 +8869,11 @@
|
|
|
7166
8869
|
ui.switchAccount.addEventListener('click', () => { void switchAccount(); });
|
|
7167
8870
|
ui.effort.addEventListener('click', () => openPicker('effort', ui.effort, effortChoices()));
|
|
7168
8871
|
ui.permission.addEventListener('click', () => openPicker('permission', ui.permission, permissionChoices()));
|
|
8872
|
+
ui.ownConnectors?.addEventListener('click', () => {
|
|
8873
|
+
if (ui.ownConnectors.disabled || !state.chat) return;
|
|
8874
|
+
closePicker();
|
|
8875
|
+
void setOwnConnectors(state.chat.settings?.useOwnConnectors !== true);
|
|
8876
|
+
});
|
|
7169
8877
|
ui.integrations.addEventListener('click', openIntegrations);
|
|
7170
8878
|
ui.send.addEventListener('click', sendTurn);
|
|
7171
8879
|
// The Drawing Filter page reports every change that can alter what the chat shows about it.
|
|
@@ -7187,6 +8895,13 @@
|
|
|
7187
8895
|
if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) { event.preventDefault(); sendTurn(); }
|
|
7188
8896
|
else if (event.key === 'Escape') { ui.skills.hidden = true; closePicker(); }
|
|
7189
8897
|
});
|
|
8898
|
+
ui.scopeToggle?.addEventListener('click', () => { void openScopePicker(); });
|
|
8899
|
+
ui.scopePicker?.addEventListener('keydown', (event) => {
|
|
8900
|
+
if (event.key === 'Escape') { event.preventDefault(); closeScopePicker(true); }
|
|
8901
|
+
});
|
|
8902
|
+
document.addEventListener('pointerdown', (event) => {
|
|
8903
|
+
if (state.scopePickerOpen && !ui.scopeControls?.contains(event.target)) closeScopePicker();
|
|
8904
|
+
});
|
|
7190
8905
|
// Capture phase: the control's own handler runs after, so a sentence it reports is held afresh.
|
|
7191
8906
|
shell.addEventListener('click', releaseReportOnControl, true);
|
|
7192
8907
|
shell.addEventListener('dragover', (event) => { if (event.dataTransfer?.types.includes('Files')) event.preventDefault(); });
|
|
@@ -7244,7 +8959,7 @@
|
|
|
7244
8959
|
paintAttachments();
|
|
7245
8960
|
});
|
|
7246
8961
|
window.flolessChat = {
|
|
7247
|
-
refreshScope, refreshActivity, refreshIndex, startRequest, openConversation, openDraft, openVerifiedTeklaDraft,
|
|
8962
|
+
refreshScope, refreshActivity, refreshIndex, startRequest, openConversation, openConversationIn, openDraft, openVerifiedTeklaDraft,
|
|
7248
8963
|
startProjectIntake, resumeProjectIntake,
|
|
7249
8964
|
// The plain-English sentence for a refusal the chat routes named, so a Start outside this panel
|
|
7250
8965
|
// (the upload modal, Requests) says what happened and what to do next instead of a generic toast (#1779).
|