@floless/app 0.155.2 → 0.157.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/cli-actions.mjs +392 -0
- package/dist/floless-server.cjs +182734 -141519
- package/dist/schemas/drawing-check.profile.v1.schema.json +15 -2
- package/dist/schemas/steel.model.v2.schema.json +25 -1
- package/dist/skills/floless-app-actions/SKILL.md +199 -0
- package/dist/skills/floless-app-approval/SKILL.md +8 -5
- package/dist/skills/floless-app-bridge/SKILL.md +12 -9
- package/dist/skills/floless-app-knowledge/SKILL.md +50 -14
- package/dist/skills/floless-app-new-workflow/SKILL.md +26 -10
- package/dist/skills/floless-app-onboarding/SKILL.md +31 -1
- package/dist/skills/floless-app-onboarding/references/aware-runtime.md +4 -4
- package/dist/skills/floless-app-queue/SKILL.md +10 -6
- package/dist/skills/floless-app-report-issue/SKILL.md +15 -12
- package/dist/skills/floless-app-rfi/SKILL.md +98 -73
- package/dist/skills/floless-app-routines/SKILL.md +27 -15
- package/dist/skills/floless-app-routines/references/routines-api.md +8 -2
- package/dist/skills/floless-app-steel-model/SKILL.md +1 -1
- package/dist/skills/floless-app-steel-model/references/detail-from-a-screenshot.md +4 -2
- package/dist/skills/floless-app-tweak-contract/SKILL.md +25 -5
- package/dist/skills/floless-app-workflows/SKILL.md +50 -13
- package/dist/skills/floless-app-workflows/references/agent-steps.md +119 -0
- package/dist/web/agent-steps.js +1750 -0
- package/dist/web/agents.js +33 -8
- package/dist/web/app.css +681 -4
- package/dist/web/app.js +111 -11
- package/dist/web/aware-update-client.js +1 -0
- package/dist/web/aware.js +1257 -202
- package/dist/web/chat-landing-scene.js +372 -0
- package/dist/web/chat.css +254 -1
- package/dist/web/chat.js +2657 -87
- package/dist/web/commands-drawing-check.js +17 -0
- package/dist/web/commands-shell.js +1108 -4
- package/dist/web/commands-steel.js +6 -0
- package/dist/web/connections.js +1 -0
- package/dist/web/drawing-check-editor.html +33 -5
- package/dist/web/drawing-check-editor.js +538 -22
- package/dist/web/drawing-check-overlay.js +13 -0
- package/dist/web/flo-avatar.js +28 -3
- package/dist/web/guide.js +7 -2
- package/dist/web/index.html +171 -7
- package/dist/web/instructor.js +6 -4
- package/dist/web/leave-guard.js +4 -2
- package/dist/web/left-pane.js +8 -3
- package/dist/web/model-revit-module.js +15 -0
- package/dist/web/model-view-query.js +12 -2
- package/dist/web/model-viewport-revit-adapter.js +3 -1
- package/dist/web/pages.js +891 -36
- package/dist/web/panels.js +8 -5
- package/dist/web/parser-setup-recovery.js +12 -4
- package/dist/web/project-access.js +549 -0
- package/dist/web/project-reconciliation.js +357 -0
- package/dist/web/report-files.js +50 -0
- package/dist/web/revit-editor.js +116 -27
- package/dist/web/startup-admission.js +132 -0
- package/dist/web/steel-3d-core.js +9 -0
- package/dist/web/steel-editor.html +642 -22
- package/dist/web/steel-model-v2-commands.js +63 -5
- package/dist/web/step-rename.js +287 -0
- package/dist/web/terminal-requests.js +590 -0
- package/dist/web/tool-updates.js +148 -13
- package/dist/web/workspace-root-management.js +39 -0
- package/dist/web/workspaces.js +1879 -74
- package/launch.mjs +82 -2
- package/package.json +3 -1
package/dist/web/panels.js
CHANGED
|
@@ -15,8 +15,11 @@
|
|
|
15
15
|
const bridge = window.flolessBridge || {};
|
|
16
16
|
// aware.js always loads first and provides api; this fallback only guards a
|
|
17
17
|
// pathological load order so the file can't throw at parse time.
|
|
18
|
-
const api = bridge.api || (async (path, opts) => {
|
|
19
|
-
|
|
18
|
+
const api = bridge.api || (async (path, opts = {}) => {
|
|
19
|
+
await globalThis.flolessStartupAdmission?.admit(path, { method: opts?.method, signal: opts?.signal });
|
|
20
|
+
const { timeoutMs, ...requestOptions } = opts;
|
|
21
|
+
if (!requestOptions.signal && Number.isFinite(timeoutMs)) requestOptions.signal = AbortSignal.timeout(timeoutMs);
|
|
22
|
+
const res = await fetch(path, { headers: { 'content-type': 'application/json' }, ...requestOptions });
|
|
20
23
|
const body = await res.json().catch(() => ({ ok: false, error: `HTTP ${res.status}` }));
|
|
21
24
|
if (!res.ok || body.ok === false) {
|
|
22
25
|
const err = new Error(body.error || `HTTP ${res.status}`);
|
|
@@ -642,7 +645,7 @@
|
|
|
642
645
|
} catch (err) {
|
|
643
646
|
const b = err && err.body;
|
|
644
647
|
if (b) setUndoRedoEnabled(b.canUndo, b.canRedo);
|
|
645
|
-
if (b && b.
|
|
648
|
+
if (b && b.code === 'nothing-to-undo') showToast('Nothing to undo', 'info');
|
|
646
649
|
else showToast('We couldn’t undo that change. Nothing else was changed. Try again.', 'warn');
|
|
647
650
|
return false;
|
|
648
651
|
}
|
|
@@ -658,7 +661,7 @@
|
|
|
658
661
|
} catch (err) {
|
|
659
662
|
const b = err && err.body;
|
|
660
663
|
if (b) setUndoRedoEnabled(b.canUndo, b.canRedo);
|
|
661
|
-
if (b && b.
|
|
664
|
+
if (b && b.code === 'nothing-to-redo') showToast('Nothing to redo', 'info');
|
|
662
665
|
else showToast('We couldn’t redo that change. Nothing else was changed. Try again.', 'warn');
|
|
663
666
|
return false;
|
|
664
667
|
}
|
|
@@ -712,7 +715,7 @@
|
|
|
712
715
|
} catch (err) {
|
|
713
716
|
const b = err && err.body;
|
|
714
717
|
if (b) setUndoRedoEnabled(b.canUndo, b.canRedo);
|
|
715
|
-
if (b && b.
|
|
718
|
+
if (b && b.code === 'already-default') showToast('Already the default dashboard', 'info');
|
|
716
719
|
else showToast('We couldn’t reset the dashboard. Your current layout is still here. Try again.', 'warn');
|
|
717
720
|
}
|
|
718
721
|
};
|
|
@@ -212,7 +212,8 @@
|
|
|
212
212
|
try {
|
|
213
213
|
preview = await api('/api/parser-setup/preview', { appId: selected });
|
|
214
214
|
if (modal) { renderPreview(); error(notice); }
|
|
215
|
-
|
|
215
|
+
return true;
|
|
216
|
+
} catch (failure) { if (modal) renderFailure(failure); return false; }
|
|
216
217
|
finally { updateBusy(false); modal?.querySelector('.modal-actions button')?.focus(); refreshFocused(); }
|
|
217
218
|
}
|
|
218
219
|
async function retry() {
|
|
@@ -238,13 +239,20 @@
|
|
|
238
239
|
finally { modal?.querySelector('[data-setup-status]')?.replaceChildren(); updateBusy(false); }
|
|
239
240
|
}
|
|
240
241
|
window.flolessParserSetupRecovery = { open: async (id, opener) => {
|
|
241
|
-
|
|
242
|
+
// A card that asked for this review is told when a setup is already running, instead of reading as opened.
|
|
243
|
+
if (busy) return 'A parser setup is already running. Let it finish, then ask again.';
|
|
244
|
+
create(id, opener); updateBusy(true);
|
|
242
245
|
try {
|
|
243
246
|
// Use the established browser session once. Recreating it between preview and confirm
|
|
244
247
|
// would invalidate the exact local UI decision; desktop IPC sessions already carry it.
|
|
245
248
|
const response = await fetch('/api/editor/session', { method: 'POST', credentials: 'same-origin' });
|
|
246
249
|
if (!response.ok && response.status !== 403) throw new Error('The local browser session could not be opened. Close this dialog and sign in again.');
|
|
247
|
-
|
|
248
|
-
|
|
250
|
+
// The review shows why a preview failed; a card that opened it is told it did not load.
|
|
251
|
+
if (!(await load())) return 'The setup review opened but could not load. It says why in FloLess.';
|
|
252
|
+
} catch (failure) {
|
|
253
|
+
renderFailure(failure);
|
|
254
|
+
// A card that opened this is told it did not load, so it never reads as opened and ready.
|
|
255
|
+
return 'The setup review opened but could not load. It says why in FloLess.';
|
|
256
|
+
}
|
|
249
257
|
} };
|
|
250
258
|
})();
|
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
/* Project access (spec docs/superpowers/specs/2026-10-19-project-access-panel-PLAN.md).
|
|
2
|
+
*
|
|
3
|
+
* The "Project access · N" chip in an open project's header and the sheet it opens: which Agents may work in this project,
|
|
4
|
+
* which schedules run a workflow on it, and which workflows use it. Read from GET /api/projects/:id/access.
|
|
5
|
+
*
|
|
6
|
+
* The switches write through the routes that already own those records — an Agent's "Where it works" list
|
|
7
|
+
* (PUT /api/chat/agents/:id) and a routine's on/off (PATCH /api/routines/:id) — so this sheet adds no new kind of
|
|
8
|
+
* permission. Workflows have no switch: what pins them to the project lives in the approved workflow, so their rows
|
|
9
|
+
* link to it instead. Nothing here composes or edits a workflow.
|
|
10
|
+
*/
|
|
11
|
+
(() => {
|
|
12
|
+
const $chip = document.getElementById('ws-access');
|
|
13
|
+
const $count = document.getElementById('ws-access-count');
|
|
14
|
+
const $sheet = document.getElementById('project-access-sheet');
|
|
15
|
+
const $panel = $sheet && $sheet.querySelector('.pa-sheet');
|
|
16
|
+
const $sub = document.getElementById('pa-sub');
|
|
17
|
+
const $body = document.getElementById('pa-body');
|
|
18
|
+
const $bar = document.getElementById('pa-bar');
|
|
19
|
+
if (!$chip || !$sheet || !$body || !$bar) return;
|
|
20
|
+
|
|
21
|
+
const state = {
|
|
22
|
+
project: null, // { id, name, uuid } of the open project
|
|
23
|
+
data: null, // the last answer from /access
|
|
24
|
+
loading: false,
|
|
25
|
+
error: '',
|
|
26
|
+
seq: 0,
|
|
27
|
+
selected: new Set(), // 'agent:<id>' / 'schedule:<id>'
|
|
28
|
+
confirm: null, // { kind: 'agent', id } | { kind: 'bulk' }
|
|
29
|
+
rowError: new Map(), // key -> sentence
|
|
30
|
+
busy: new Set(), // keys being written
|
|
31
|
+
// Agents switched off while the sheet is open stay listed (switched off) so they can be turned back on.
|
|
32
|
+
// Once the sheet closes they are gone from it: the project is no longer in their list.
|
|
33
|
+
turnedOff: new Map(),
|
|
34
|
+
returnFocus: null,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
38
|
+
const keyOf = (kind, id) => `${kind}:${id}`;
|
|
39
|
+
const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
40
|
+
const toast = (text, kind) => { if (typeof showToast === 'function') showToast(text, kind); };
|
|
41
|
+
|
|
42
|
+
async function api(path, options = {}) {
|
|
43
|
+
const res = await fetch(path, {
|
|
44
|
+
method: options.method || 'GET',
|
|
45
|
+
headers: options.body ? { 'Content-Type': 'application/json' } : undefined,
|
|
46
|
+
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
47
|
+
});
|
|
48
|
+
const body = await res.json().catch(() => null);
|
|
49
|
+
if (!res.ok || !body || body.ok === false) {
|
|
50
|
+
const error = new Error('request failed');
|
|
51
|
+
error.status = res.status; error.code = body && body.code; error.body = body;
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
return body;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ── data ─────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
58
|
+
|
|
59
|
+
function liveCount(data) {
|
|
60
|
+
if (!data) return null;
|
|
61
|
+
return data.agents.filter((a) => !a.archived).length
|
|
62
|
+
+ data.schedules.filter((s) => s.enabled && !s.broken).length
|
|
63
|
+
+ data.workflows.filter((w) => !w.archived).length;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function paintChip() {
|
|
67
|
+
const n = state.loading && !state.data ? null : liveCount(state.data);
|
|
68
|
+
$count.textContent = n === null ? '' : String(n);
|
|
69
|
+
$count.hidden = n === null;
|
|
70
|
+
$chip.setAttribute('aria-label', n === null ? 'Project access' : `Project access: ${plural(n, 'thing reaches', 'things reach')} into this project`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function load() {
|
|
74
|
+
if (!state.project) return;
|
|
75
|
+
const seq = ++state.seq;
|
|
76
|
+
state.loading = true;
|
|
77
|
+
// Only the first read shows the loading state; a refresh keeps the rows on screen and repaints them only when the
|
|
78
|
+
// answer changed — rebuilding rows under the pointer would swallow the click the person is making.
|
|
79
|
+
const first = !state.data;
|
|
80
|
+
if (first) { state.error = ''; paintChip(); if (isOpen()) paint(); }
|
|
81
|
+
let changed = false;
|
|
82
|
+
try {
|
|
83
|
+
const body = await api(`/api/projects/${encodeURIComponent(state.project.id)}/access`);
|
|
84
|
+
if (seq !== state.seq) return;
|
|
85
|
+
changed = !state.data || JSON.stringify(state.data) !== JSON.stringify(body) || !!state.error;
|
|
86
|
+
state.data = body; state.error = '';
|
|
87
|
+
if (body.project?.uuid) state.project = { ...state.project, uuid: body.project.uuid };
|
|
88
|
+
} catch (error) {
|
|
89
|
+
if (seq !== state.seq) return;
|
|
90
|
+
changed = true;
|
|
91
|
+
state.error = error.status === 404
|
|
92
|
+
? 'FloLess cannot find this project any more. It may have been archived or removed.'
|
|
93
|
+
: 'FloLess could not read what has access to this project just now. Try again in a moment.';
|
|
94
|
+
} finally {
|
|
95
|
+
if (seq === state.seq) {
|
|
96
|
+
state.loading = false;
|
|
97
|
+
paintChip();
|
|
98
|
+
if (isOpen() && (changed || first)) paint();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// ── view ─────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
104
|
+
|
|
105
|
+
const isOpen = () => $sheet.classList.contains('show');
|
|
106
|
+
|
|
107
|
+
// `on`: true when the project is in the Agent's own list; false only for an Agent switched off in this sheet; undefined
|
|
108
|
+
// for an Agent that reaches the project only through a workflow it lists — that row has no switch, because the switch
|
|
109
|
+
// edits the Agent's own list, and turning it "on" would grant access the person never had.
|
|
110
|
+
function agentRows() {
|
|
111
|
+
const offHere = (id) => state.turnedOff.get(id)?.projectId === state.project?.id;
|
|
112
|
+
const rows = (state.data?.agents || []).map((a) => ({ ...a, on: a.direct ? true : (offHere(a.agentId) ? false : undefined) }));
|
|
113
|
+
for (const [id, snapshot] of state.turnedOff) {
|
|
114
|
+
if (snapshot.projectId === state.project?.id && !rows.some((r) => r.agentId === id)) rows.push({ ...snapshot, on: false });
|
|
115
|
+
}
|
|
116
|
+
return rows.sort((a, b) => a.name.localeCompare(b.name));
|
|
117
|
+
}
|
|
118
|
+
const switchable = (row) => !row.archived && (row.on === true || row.on === false);
|
|
119
|
+
|
|
120
|
+
function workflowNames(refs) {
|
|
121
|
+
const names = refs.map((r) => `“${r.name}”`);
|
|
122
|
+
return names.length <= 1 ? names.join('') : `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function scheduleWhen(s) {
|
|
126
|
+
if (s.broken) return 'Cannot run: its workflow is missing or changed';
|
|
127
|
+
if (!s.enabled) return 'Switched off';
|
|
128
|
+
if (s.kind === 'trigger') return 'Runs when its trigger fires';
|
|
129
|
+
if (s.nextFireAt) {
|
|
130
|
+
const when = new Date(s.nextFireAt);
|
|
131
|
+
if (!Number.isNaN(when.getTime())) return `Next run ${when.toLocaleString(undefined, { weekday: 'short', day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit' })}`;
|
|
132
|
+
}
|
|
133
|
+
return 'Runs on a schedule';
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const BINDING_LABEL = { owner: 'Belongs to this project', 'agent-step': 'Has an Agent step on this project', knowledge: 'Built using this project’s Knowledge' };
|
|
137
|
+
|
|
138
|
+
function confirmHtml(row) {
|
|
139
|
+
const project = esc(state.project?.name || 'this project');
|
|
140
|
+
const steps = row.stepWorkflows || [];
|
|
141
|
+
const through = row.through || [];
|
|
142
|
+
const stepNote = steps.length
|
|
143
|
+
? `<p class="pa-confirm-warn">${esc(workflowNames(steps))} ${steps.length === 1 ? 'has an Agent step that uses' : 'have Agent steps that use'} “${esc(row.name)}” on this project. ${steps.length === 1 ? 'That step keeps' : 'Those steps keep'} reading the project, because the places a step reads are written into the workflow itself. To stop ${steps.length === 1 ? 'it' : 'them'}, open the workflow and change the step.</p>`
|
|
144
|
+
: '';
|
|
145
|
+
const throughNote = through.length
|
|
146
|
+
? `<p class="pa-confirm-warn">It can still work here through ${esc(workflowNames(through))}, because ${through.length === 1 ? 'that workflow is' : 'those workflows are'} in its list. Remove ${through.length === 1 ? 'it' : 'them'} on the Agents tab to stop that.</p>`
|
|
147
|
+
: '';
|
|
148
|
+
const outcome = through.length ? 'This project leaves its list.' : 'It will stop working here.';
|
|
149
|
+
return `<div class="pa-confirm" role="group" aria-label="Confirm turning off ${esc(row.name)}">
|
|
150
|
+
<p>Remove “${esc(row.name)}”’s access to “${project}”? ${outcome} You can turn it back on any time.</p>${throughNote}${stepNote}
|
|
151
|
+
<div class="pa-confirm-actions">
|
|
152
|
+
<button type="button" class="pa-btn" data-pa-keep data-command-id="shell.project-access-keep">Keep on</button>
|
|
153
|
+
<button type="button" class="pa-btn danger" data-pa-confirm data-command-id="shell.project-access-confirm">Turn off</button>
|
|
154
|
+
</div></div>`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Instructor ids carry the row's stable key (two rows can share a name); the name is the label Instructor reads out.
|
|
158
|
+
function checkbox(key, name) {
|
|
159
|
+
return `<input type="checkbox" class="pa-check" data-pa-select="${esc(key)}" aria-label="Select ${esc(name)}"`
|
|
160
|
+
+ ` data-command-id="shell.project-access-select#${esc(key)}" data-command-instance-label="${esc(name)}"${state.selected.has(key) ? ' checked' : ''}>`;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function sw(key, kind, name, on, label) {
|
|
164
|
+
const busy = state.busy.has(key);
|
|
165
|
+
return `<button type="button" class="kb-toggle pa-switch" role="switch" aria-checked="${on ? 'true' : 'false'}" aria-label="${esc(label)}: ${esc(name)}"`
|
|
166
|
+
+ ` data-pa-switch="${esc(key)}" ${kind === 'agent' ? `data-command-id="shell.project-access-agent#${esc(key)}"` : `data-command-id="shell.project-access-schedule#${esc(key)}"`} data-command-instance-label="${esc(name)}"${busy ? ' aria-busy="true"' : ''}`
|
|
167
|
+
+ ` data-tip="${esc(on ? `${label} — turn off` : `${label} — turn on`)}"></button>`;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function openBtn(key, name) {
|
|
171
|
+
return `<button type="button" class="pa-open" data-pa-open="${esc(key)}" aria-label="Open ${esc(name)}" data-command-id="shell.project-access-open#${esc(key)}" data-command-instance-label="${esc(name)}">Open</button>`;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function agentRow(row) {
|
|
175
|
+
const key = keyOf('agent', row.agentId);
|
|
176
|
+
const how = [];
|
|
177
|
+
if (row.on === false) how.push('Switched off for this project');
|
|
178
|
+
else if (row.on === true) how.push('Can read and work in this project');
|
|
179
|
+
if (row.through?.length) how.push(`Through ${workflowNames(row.through)}`);
|
|
180
|
+
if (row.scheduled) how.push('Has its own schedule');
|
|
181
|
+
const chips = [row.paused ? '<span class="pa-chip">Paused everywhere</span>' : '', row.archived ? '<span class="pa-chip">Archived</span>' : ''].join('');
|
|
182
|
+
const canSwitch = switchable(row);
|
|
183
|
+
const error = state.rowError.get(key);
|
|
184
|
+
return `<li class="pa-row${row.archived ? ' dim' : ''}" data-pa-row="${esc(key)}">
|
|
185
|
+
<span class="pa-sel">${canSwitch ? checkbox(key, row.name) : ''}</span>
|
|
186
|
+
<span class="pa-main"><span class="pa-name">${esc(row.name)}${chips}</span><span class="pa-how">${esc(how.join(' · '))}</span>
|
|
187
|
+
${error ? `<span class="pa-row-error" role="alert">${esc(error)}</span>` : ''}</span>
|
|
188
|
+
<span class="pa-ctl">${canSwitch ? sw(key, 'agent', row.name, row.on === true, 'Allowed in this project') : ''}${openBtn(key, row.name)}</span>
|
|
189
|
+
${state.confirm?.kind === 'agent' && state.confirm.id === row.agentId ? confirmHtml(row) : ''}
|
|
190
|
+
</li>`;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function scheduleRow(s) {
|
|
194
|
+
const key = keyOf('schedule', s.routineId);
|
|
195
|
+
const error = state.rowError.get(key);
|
|
196
|
+
return `<li class="pa-row${s.broken ? ' dim' : ''}" data-pa-row="${esc(key)}">
|
|
197
|
+
<span class="pa-sel">${s.broken ? '' : checkbox(key, s.name)}</span>
|
|
198
|
+
<span class="pa-main"><span class="pa-name">${esc(s.name)}</span>
|
|
199
|
+
<span class="pa-how">${esc(s.certain === false
|
|
200
|
+
? `May run on this project: its workflow “${s.workflow.name}” could not be read, so FloLess cannot tell. ${scheduleWhen(s)}`
|
|
201
|
+
: `Runs “${s.workflow.name}” · ${scheduleWhen(s)}`)}</span>
|
|
202
|
+
${error ? `<span class="pa-row-error" role="alert">${esc(error)}</span>` : ''}</span>
|
|
203
|
+
<span class="pa-ctl">${s.broken ? '' : sw(key, 'schedule', s.name, s.enabled, 'Runs on schedule')}${openBtn(key, s.name)}</span>
|
|
204
|
+
</li>`;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function workflowRow(w) {
|
|
208
|
+
const key = keyOf('workflow', w.workflowId || w.appId);
|
|
209
|
+
const tags = w.bindings.map((b) => `<span class="pa-tag">${esc(BINDING_LABEL[b] || b)}</span>`).join('');
|
|
210
|
+
const changeable = w.bindings.some((b) => b !== 'owner');
|
|
211
|
+
return `<li class="pa-row${w.archived ? ' dim' : ''}" data-pa-row="${esc(key)}">
|
|
212
|
+
<span class="pa-sel"></span>
|
|
213
|
+
<span class="pa-main"><span class="pa-name">${esc(w.name)}${w.archived ? '<span class="pa-chip">Archived</span>' : ''}</span>
|
|
214
|
+
<span class="pa-tags">${tags}</span>
|
|
215
|
+
${changeable && !w.archived ? '<span class="pa-how">To change how it uses this project, open the workflow, edit it and approve it again.</span>' : ''}</span>
|
|
216
|
+
<span class="pa-ctl">${openBtn(key, w.name)}</span>
|
|
217
|
+
</li>`;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function group(id, title, rows, renderRow, selectable) {
|
|
221
|
+
if (!rows.length) return '';
|
|
222
|
+
const keys = selectable ? rows.map(selectable).filter(Boolean) : [];
|
|
223
|
+
const all = keys.length > 0 && keys.every((k) => state.selected.has(k));
|
|
224
|
+
const head = keys.length
|
|
225
|
+
? `<label class="pa-group-all"><input type="checkbox" class="pa-check" data-pa-select-group="${id}" aria-label="Select all ${esc(title.toLowerCase())}" data-command-id="shell.project-access-select-group#${esc(id)}"${all ? ' checked' : ''}></label>`
|
|
226
|
+
: '';
|
|
227
|
+
return `<section class="pa-group" aria-labelledby="pa-g-${id}">
|
|
228
|
+
<h3 class="pa-group-title" id="pa-g-${id}">${head}<span>${esc(title)}</span><span class="pa-group-count">${rows.length}</span></h3>
|
|
229
|
+
<ul class="pa-list">${rows.map(renderRow).join('')}</ul></section>`;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function skeleton() {
|
|
233
|
+
const row = '<li class="pa-row pa-skel" aria-hidden="true"><span class="pa-sel"></span><span class="pa-main"><span class="pa-bone w60"></span><span class="pa-bone w40"></span></span></li>';
|
|
234
|
+
return ['Agents that can work here', 'Schedules that run on this project', 'Workflows that use it'].map((t) =>
|
|
235
|
+
`<section class="pa-group"><h3 class="pa-group-title"><span>${t}</span></h3><ul class="pa-list">${row}${row}</ul></section>`).join('');
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const SOURCE_NAMES = { agents: 'Agents', schedules: 'schedules', workflows: 'workflows', knowledge: 'Knowledge links' };
|
|
239
|
+
|
|
240
|
+
// The list is kept on screen after a refresh failed, so it says it may be out of date and offers to read it again.
|
|
241
|
+
function staleHtml() {
|
|
242
|
+
if (!state.error || !state.data) return '';
|
|
243
|
+
return `<div class="pa-note pa-stale" role="alert"><p>${esc(state.error)} What you see here may be out of date.</p>
|
|
244
|
+
<button type="button" class="pa-btn" data-pa-retry data-command-id="shell.project-access-retry">Try again</button></div>`;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// What the server could not check, said out loud: a short list must not read as "nothing else reaches this project".
|
|
248
|
+
function uncheckedHtml() {
|
|
249
|
+
const u = state.data?.unchecked;
|
|
250
|
+
if (!u) return '';
|
|
251
|
+
const lines = [];
|
|
252
|
+
if (u.sources?.length) lines.push(`FloLess could not read the saved ${u.sources.map((k) => SOURCE_NAMES[k] || k).join(' and ')} just now, so this list may be missing some. Try again in a moment.`);
|
|
253
|
+
if (u.agents) lines.push(`${plural(u.agents, 'saved Agent', 'saved Agents')} could not be read, so ${u.agents === 1 ? 'it is' : 'they are'} not listed. ${u.agents === 1 ? 'It' : 'They'} may also work here.`);
|
|
254
|
+
if (u.workflows) lines.push(`${plural(u.workflows, 'workflow', 'workflows')} could not be read, so FloLess cannot tell whether ${u.workflows === 1 ? 'it has' : 'they have'} an Agent step that uses this project.`);
|
|
255
|
+
if (u.schedules) lines.push(`${plural(u.schedules, 'schedule', 'schedules')} could not be checked: ${u.schedules === 1 ? 'its' : 'their'} workflow could not be read, so FloLess cannot tell whether ${u.schedules === 1 ? 'it runs' : 'they run'} on this project.`);
|
|
256
|
+
if (u.knowledgePins) lines.push(`${plural(u.knowledgePins, 'saved Knowledge link', 'saved Knowledge links')} could not be read, so ${u.knowledgePins === 1 ? 'it is' : 'they are'} not listed.`);
|
|
257
|
+
return lines.length ? `<div class="pa-note" role="status">${lines.map((line) => `<p>${esc(line)}</p>`).join('')}</div>` : '';
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function paint() {
|
|
261
|
+
$sub.textContent = `Agents, schedules and workflows that reach into “${state.project?.name || 'this project'}”.`;
|
|
262
|
+
if (state.loading && !state.data) { $body.innerHTML = skeleton(); $body.setAttribute('aria-busy', 'true'); paintBar(); return; }
|
|
263
|
+
$body.removeAttribute('aria-busy');
|
|
264
|
+
if (state.error && !state.data) {
|
|
265
|
+
$body.innerHTML = `<div class="pa-empty" role="alert"><p>${esc(state.error)}</p>
|
|
266
|
+
<button type="button" class="pa-btn" data-pa-retry data-command-id="shell.project-access-retry">Try again</button></div>`;
|
|
267
|
+
paintBar(); return;
|
|
268
|
+
}
|
|
269
|
+
const agents = agentRows();
|
|
270
|
+
const schedules = state.data?.schedules || [];
|
|
271
|
+
const workflows = state.data?.workflows || [];
|
|
272
|
+
const notes = staleHtml() + uncheckedHtml();
|
|
273
|
+
if (!agents.length && !schedules.length && !workflows.length && notes) {
|
|
274
|
+
// Nothing listed, but something could not be read: say that, never "nothing has access".
|
|
275
|
+
$body.innerHTML = notes; paintBar(); return;
|
|
276
|
+
}
|
|
277
|
+
if (!agents.length && !schedules.length && !workflows.length) {
|
|
278
|
+
$body.innerHTML = `<div class="pa-empty"><p class="pa-empty-title">Nothing has access to this project yet.</p>
|
|
279
|
+
<p>Add it to an Agent’s “Where it works” on the Agents tab, or schedule a workflow on it.</p>
|
|
280
|
+
<div class="pa-empty-actions">
|
|
281
|
+
<button type="button" class="pa-btn" data-pa-go="agents" data-command-id="shell.project-access-go-agents">Open Agents</button>
|
|
282
|
+
<button type="button" class="pa-btn" data-pa-go="routines" data-command-id="shell.project-access-go-routines">Open Routines</button>
|
|
283
|
+
</div></div>`;
|
|
284
|
+
paintBar(); return;
|
|
285
|
+
}
|
|
286
|
+
$body.innerHTML = staleHtml() + uncheckedHtml()
|
|
287
|
+
+ group('agents', 'Agents that can work here', agents, agentRow, (r) => (switchable(r) ? keyOf('agent', r.agentId) : null))
|
|
288
|
+
+ group('schedules', 'Schedules that run on this project', schedules, scheduleRow, (s) => (s.broken ? null : keyOf('schedule', s.routineId)))
|
|
289
|
+
+ group('workflows', 'Workflows that use it', workflows, workflowRow, null);
|
|
290
|
+
paintBar();
|
|
291
|
+
// A repaint replaces the control that had focus; keep focus inside the sheet so Escape and Tab still work there.
|
|
292
|
+
if (isOpen() && (!document.activeElement || document.activeElement === document.body)) $panel?.focus();
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// What the selection is, read the way the switches are: which of the ticked rows are on, which off.
|
|
296
|
+
function selection() {
|
|
297
|
+
const rows = [];
|
|
298
|
+
for (const key of state.selected) {
|
|
299
|
+
const [kind, id] = [key.slice(0, key.indexOf(':')), key.slice(key.indexOf(':') + 1)];
|
|
300
|
+
if (kind === 'agent') { const r = agentRows().find((a) => a.agentId === id); if (r && switchable(r)) rows.push({ key, kind, row: r, on: r.on !== false }); }
|
|
301
|
+
if (kind === 'schedule') { const s = (state.data?.schedules || []).find((x) => x.routineId === id); if (s && !s.broken) rows.push({ key, kind, row: s, on: s.enabled }); }
|
|
302
|
+
}
|
|
303
|
+
return rows;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function paintBar() {
|
|
307
|
+
const rows = selection();
|
|
308
|
+
if (!rows.length) { $bar.hidden = true; $bar.innerHTML = ''; return; }
|
|
309
|
+
$bar.hidden = false;
|
|
310
|
+
if (state.confirm?.kind === 'bulk') {
|
|
311
|
+
const on = rows.filter((r) => r.on);
|
|
312
|
+
const agents = on.filter((r) => r.kind === 'agent').length, schedules = on.filter((r) => r.kind === 'schedule').length;
|
|
313
|
+
const parts = [agents ? `${plural(agents, 'Agent', 'Agents')} lose${agents === 1 ? 's' : ''} this project from “Where it works”` : '',
|
|
314
|
+
schedules ? `${plural(schedules, 'schedule stops', 'schedules stop')} running` : ''].filter(Boolean);
|
|
315
|
+
const steps = on.filter((r) => r.kind === 'agent' && r.row.stepWorkflows?.length);
|
|
316
|
+
$bar.innerHTML = `<div class="pa-confirm" role="group" aria-label="Confirm turning off the selected items">
|
|
317
|
+
<p>Turn off ${plural(on.length, 'item', 'items')}? ${esc(parts.join('; '))}. You can turn them back on any time.</p>
|
|
318
|
+
${steps.length ? `<p class="pa-confirm-warn">Some of these Agents are used by Agent steps in workflows. Those steps keep reading this project until you open the workflow and change the step.</p>` : ''}
|
|
319
|
+
${on.some((r) => r.kind === 'agent' && r.row.through?.length) ? `<p class="pa-confirm-warn">Some of these Agents also reach this project through a workflow in their list, and keep that access until you remove the workflow on the Agents tab.</p>` : ''}
|
|
320
|
+
<div class="pa-confirm-actions">
|
|
321
|
+
<button type="button" class="pa-btn" data-pa-keep data-command-id="shell.project-access-keep">Keep on</button>
|
|
322
|
+
<button type="button" class="pa-btn danger" data-pa-confirm data-command-id="shell.project-access-confirm">Turn off</button>
|
|
323
|
+
</div></div>`;
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const anyOn = rows.some((r) => r.on), anyOff = rows.some((r) => !r.on);
|
|
327
|
+
$bar.innerHTML = `<span class="pa-bar-count">${rows.length} selected</span>
|
|
328
|
+
${anyOn ? '<button type="button" class="pa-btn" data-pa-bulk="off" data-command-id="shell.project-access-bulk-off">Turn off</button>' : ''}
|
|
329
|
+
${anyOff ? '<button type="button" class="pa-btn" data-pa-bulk="on" data-command-id="shell.project-access-bulk-on">Turn on</button>' : ''}
|
|
330
|
+
<button type="button" class="pa-btn ghost" data-pa-clear data-command-id="shell.project-access-bulk-clear">Clear</button>`;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// ── writes ───────────────────────────────────────────────────────────────────────────────────────────────────
|
|
334
|
+
|
|
335
|
+
// Every write names the project it started on, captured when the person confirmed: a save that finishes after the sheet
|
|
336
|
+
// moved to another project still edits the project the person was looking at, never the one open now.
|
|
337
|
+
const projectItem = (target) => ({ kind: 'project', projectId: target.id, projectUuid: target.uuid });
|
|
338
|
+
const isProject = (target) => (s) => s.kind === 'project' && s.projectId === target.id
|
|
339
|
+
&& String(s.projectUuid).toLowerCase() === String(target.uuid).toLowerCase();
|
|
340
|
+
|
|
341
|
+
async function setAgent(row, on, target) {
|
|
342
|
+
const { agent } = await api(`/api/chat/agents/${encodeURIComponent(row.agentId)}`);
|
|
343
|
+
// Archived meanwhile: the Agent route refuses to edit an archived Agent, so say so instead of offering a save that fails.
|
|
344
|
+
if (agent.archivedAt) { const error = new Error('archived'); error.code = 'agent-archived'; error.agent = agent; throw error; }
|
|
345
|
+
// Changed since this list was read (renamed, re-scoped, new instructions): nothing is saved; the list is read again.
|
|
346
|
+
if (agent.revision !== row.revision) { const error = new Error('changed'); error.code = 'agent-changed-since-read'; error.agent = agent; throw error; }
|
|
347
|
+
const here = isProject(target);
|
|
348
|
+
const scope = on ? (agent.scope.some(here) ? agent.scope : [...agent.scope, projectItem(target)]) : agent.scope.filter((s) => !here(s));
|
|
349
|
+
const draft = { name: agent.name, instructions: agent.instructions, scope, mode: agent.mode, allowChanges: agent.allowChanges, provider: agent.provider ?? null };
|
|
350
|
+
const saved = await api(`/api/chat/agents/${encodeURIComponent(row.agentId)}`, { method: 'PUT', body: { agent: draft, revision: agent.revision } });
|
|
351
|
+
const revision = saved.agent?.revision ?? agent.revision + 1;
|
|
352
|
+
// Only the sheet still showing the project this write was for keeps the switched-off row: another project's sheet
|
|
353
|
+
// must never show (and offer to switch on) an Agent that was switched off somewhere else.
|
|
354
|
+
if (!state.project || state.project.id !== target.id) return;
|
|
355
|
+
if (on) state.turnedOff.delete(row.agentId);
|
|
356
|
+
else state.turnedOff.set(row.agentId, { ...row, revision, projectId: target.id, direct: false, through: [] });
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
async function setSchedule(s, on) {
|
|
360
|
+
await api(`/api/routines/${encodeURIComponent(s.routineId)}`, { method: 'PATCH', body: { enabled: on, expectedUpdated: s.updated } });
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Written after the list was read again, so it only claims "the list shows it as saved" when that read worked.
|
|
364
|
+
function failureSentence(kind, on, error, reread) {
|
|
365
|
+
const thing = kind === 'agent' ? 'This Agent' : 'This schedule';
|
|
366
|
+
if (error?.code === 'agent-archived') {
|
|
367
|
+
return on
|
|
368
|
+
? 'This Agent was archived somewhere else, so it cannot be switched on here. Restore it on the Agents tab, then switch it on.'
|
|
369
|
+
: 'This Agent was archived somewhere else, so nothing was changed here. Restore it on the Agents tab to change where it works.';
|
|
370
|
+
}
|
|
371
|
+
if (error && (error.code === 'agent-changed-since-read' || error.code === 'agent-revision-stale' || error.status === 409)) {
|
|
372
|
+
return reread
|
|
373
|
+
? `${thing} was changed somewhere else since this list was read, so nothing was saved. The list now shows it as it is; switch it again if you still want to.`
|
|
374
|
+
: `${thing} was changed somewhere else since this list was read, so nothing was saved. Read the list again before switching it.`;
|
|
375
|
+
}
|
|
376
|
+
// The Agent route answers a refused save with a plain sentence of its own (for example its project limit); show that.
|
|
377
|
+
if (kind === 'agent' && error?.status === 400 && typeof error.body?.error === 'string' && error.body.error.length < 240) return error.body.error;
|
|
378
|
+
return on ? 'Couldn’t turn this on. Try again.' : 'Couldn’t turn this off. Try again.';
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
async function apply(items, on) {
|
|
382
|
+
const target = state.project ? { ...state.project } : null;
|
|
383
|
+
if (!target) return;
|
|
384
|
+
for (const item of items) { state.busy.add(item.key); state.rowError.delete(item.key); }
|
|
385
|
+
paint();
|
|
386
|
+
const failures = [];
|
|
387
|
+
for (const item of items) {
|
|
388
|
+
try {
|
|
389
|
+
if (item.kind === 'agent') await setAgent(item.row, on, target); else await setSchedule(item.row, on);
|
|
390
|
+
state.selected.delete(item.key);
|
|
391
|
+
} catch (error) {
|
|
392
|
+
failures.push({ item, error });
|
|
393
|
+
} finally { state.busy.delete(item.key); }
|
|
394
|
+
}
|
|
395
|
+
// The sheet moved to another project meanwhile: the writes above went to the right one; nothing to show here.
|
|
396
|
+
if (!state.project || state.project.id !== target.id) return;
|
|
397
|
+
state.confirm = null;
|
|
398
|
+
await load();
|
|
399
|
+
// A switched-off row is not in the answer any more, so a re-read cannot refresh it: bring its snapshot up to date from
|
|
400
|
+
// the Agent just read, so "the list now shows it as it is" is true and switching it again works.
|
|
401
|
+
for (const { item, error } of failures) {
|
|
402
|
+
const snap = item.kind === 'agent' ? state.turnedOff.get(item.row.agentId) : null;
|
|
403
|
+
if (snap && error?.agent) state.turnedOff.set(item.row.agentId, { ...snap, name: error.agent.name, revision: error.agent.revision, archived: !!error.agent.archivedAt });
|
|
404
|
+
}
|
|
405
|
+
const reread = !state.error;
|
|
406
|
+
for (const { item, error } of failures) state.rowError.set(item.key, failureSentence(item.kind, on, error, reread));
|
|
407
|
+
if (isOpen()) paint(); // the person's own change: show its outcome (and any row error) even when the list read back the same
|
|
408
|
+
const done = items.length - failures.length;
|
|
409
|
+
if (items.length > 1) {
|
|
410
|
+
if (done) toast(`${on ? 'Turned on' : 'Turned off'} ${plural(done, 'item', 'items')}${failures.length ? `; ${failures.length} could not be changed` : ''}.`, failures.length ? 'warn' : 'ok');
|
|
411
|
+
else toast(`None of the ${items.length} items could be changed. Each row says why.`, 'warn');
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// ── open / close ─────────────────────────────────────────────────────────────────────────────────────────────
|
|
416
|
+
|
|
417
|
+
function open(returnFocus) {
|
|
418
|
+
if (!state.project) return;
|
|
419
|
+
state.returnFocus = returnFocus || document.activeElement;
|
|
420
|
+
$sheet.classList.add('show');
|
|
421
|
+
$chip.setAttribute('aria-expanded', 'true');
|
|
422
|
+
paint();
|
|
423
|
+
void load();
|
|
424
|
+
requestAnimationFrame(() => $panel?.focus());
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function close() {
|
|
428
|
+
if (!isOpen()) return;
|
|
429
|
+
$sheet.classList.remove('show');
|
|
430
|
+
$chip.setAttribute('aria-expanded', 'false');
|
|
431
|
+
state.selected.clear(); state.confirm = null; state.rowError.clear(); state.turnedOff.clear();
|
|
432
|
+
const target = state.returnFocus;
|
|
433
|
+
state.returnFocus = null;
|
|
434
|
+
if (target && document.contains(target)) target.focus();
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
async function openItem(key) {
|
|
438
|
+
const [kind, id] = [key.slice(0, key.indexOf(':')), key.slice(key.indexOf(':') + 1)];
|
|
439
|
+
const w = kind === 'workflow' ? (state.data?.workflows || []).find((x) => (x.workflowId || x.appId) === id) : null;
|
|
440
|
+
const go = kind === 'agent' ? (window.flolessAgents?.open && (() => window.flolessAgents.open(id)))
|
|
441
|
+
: kind === 'schedule' ? (window.flolessRoutines?.open && (() => window.flolessRoutines.open(id)))
|
|
442
|
+
: w?.workflowId && w.archived && window.flolessBridge?.openArchivedWorkflow ? () => window.flolessBridge.openArchivedWorkflow(w.workflowId)
|
|
443
|
+
: w?.workflowId && window.flolessBridge?.openOwnedWorkflow ? () => window.flolessBridge.openOwnedWorkflow(w.workflowId)
|
|
444
|
+
: w?.appId && window.flolessBridge?.openApp ? () => window.flolessBridge.openApp(w.appId) : null;
|
|
445
|
+
// Close only when there is somewhere to go: otherwise the sheet would vanish and nothing would open.
|
|
446
|
+
if (!go) { toast('FloLess cannot open that from here. Find it on the Agents or Workflows tab, or in Routines.', 'warn'); return; }
|
|
447
|
+
close();
|
|
448
|
+
try {
|
|
449
|
+
await go();
|
|
450
|
+
} catch (error) {
|
|
451
|
+
toast(error instanceof Error && error.message && !/request failed/.test(error.message) ? error.message : 'FloLess could not open that just now. Try again.', 'warn');
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// ── events ───────────────────────────────────────────────────────────────────────────────────────────────────
|
|
456
|
+
|
|
457
|
+
$chip.addEventListener('click', () => (isOpen() ? close() : open($chip)));
|
|
458
|
+
document.getElementById('pa-close')?.addEventListener('click', close);
|
|
459
|
+
if (typeof onBackdropDismiss === 'function') onBackdropDismiss($sheet, close);
|
|
460
|
+
document.addEventListener('keydown', (e) => {
|
|
461
|
+
if (e.key !== 'Escape' || !isOpen()) return;
|
|
462
|
+
e.stopPropagation();
|
|
463
|
+
if (state.confirm) { state.confirm = null; paint(); return; }
|
|
464
|
+
close();
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
$sheet.addEventListener('change', (e) => {
|
|
468
|
+
const target = e.target;
|
|
469
|
+
if (!(target instanceof HTMLInputElement)) return;
|
|
470
|
+
if (target.dataset.paSelect) {
|
|
471
|
+
if (target.checked) state.selected.add(target.dataset.paSelect); else state.selected.delete(target.dataset.paSelect);
|
|
472
|
+
if (state.confirm?.kind === 'bulk') state.confirm = null;
|
|
473
|
+
paint();
|
|
474
|
+
} else if (target.dataset.paSelectGroup) {
|
|
475
|
+
const group = target.dataset.paSelectGroup;
|
|
476
|
+
const keys = group === 'agents'
|
|
477
|
+
? agentRows().filter(switchable).map((r) => keyOf('agent', r.agentId))
|
|
478
|
+
: (state.data?.schedules || []).filter((s) => !s.broken).map((s) => keyOf('schedule', s.routineId));
|
|
479
|
+
for (const k of keys) { if (target.checked) state.selected.add(k); else state.selected.delete(k); }
|
|
480
|
+
if (state.confirm?.kind === 'bulk') state.confirm = null;
|
|
481
|
+
paint();
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
$sheet.addEventListener('click', (e) => {
|
|
486
|
+
const el = e.target instanceof Element ? e.target.closest('button') : null;
|
|
487
|
+
if (!el || !$sheet.contains(el)) return;
|
|
488
|
+
if (el.dataset.paSwitch) {
|
|
489
|
+
if (state.busy.has(el.dataset.paSwitch)) return;
|
|
490
|
+
const key = el.dataset.paSwitch;
|
|
491
|
+
const kind = key.slice(0, key.indexOf(':')), id = key.slice(key.indexOf(':') + 1);
|
|
492
|
+
const on = el.getAttribute('aria-checked') !== 'true';
|
|
493
|
+
if (kind === 'agent') {
|
|
494
|
+
const row = agentRows().find((r) => r.agentId === id);
|
|
495
|
+
if (!row) return;
|
|
496
|
+
if (!on) { state.confirm = { kind: 'agent', id }; paint(); $body.querySelector('[data-pa-keep]')?.focus(); return; }
|
|
497
|
+
void apply([{ key, kind, row }], true);
|
|
498
|
+
} else {
|
|
499
|
+
const s = (state.data?.schedules || []).find((x) => x.routineId === id);
|
|
500
|
+
if (s) void apply([{ key, kind, row: s }], on);
|
|
501
|
+
}
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
if (el.hasAttribute('data-pa-keep')) { state.confirm = null; paint(); return; }
|
|
505
|
+
if (el.hasAttribute('data-pa-confirm')) {
|
|
506
|
+
if (state.confirm?.kind === 'agent') {
|
|
507
|
+
const row = agentRows().find((r) => r.agentId === state.confirm.id);
|
|
508
|
+
if (row) void apply([{ key: keyOf('agent', row.agentId), kind: 'agent', row }], false);
|
|
509
|
+
} else if (state.confirm?.kind === 'bulk') {
|
|
510
|
+
void apply(selection().filter((r) => r.on), false);
|
|
511
|
+
}
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
if (el.dataset.paBulk === 'off') {
|
|
515
|
+
const items = selection().filter((r) => r.on);
|
|
516
|
+
// Agents lose this project from their list, so the bulk turn-off asks first, as the single one does.
|
|
517
|
+
if (items.some((r) => r.kind === 'agent')) { state.confirm = { kind: 'bulk' }; paintBar(); $bar.querySelector('[data-pa-keep]')?.focus(); }
|
|
518
|
+
else void apply(items, false);
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
if (el.dataset.paBulk === 'on') { void apply(selection().filter((r) => !r.on), true); return; }
|
|
522
|
+
if (el.hasAttribute('data-pa-clear')) { state.selected.clear(); state.confirm = null; paint(); return; }
|
|
523
|
+
if (el.dataset.paOpen) { void openItem(el.dataset.paOpen); return; }
|
|
524
|
+
if (el.hasAttribute('data-pa-retry')) { void load(); return; }
|
|
525
|
+
if (el.dataset.paGo === 'agents') { close(); void window.flolessWorkspaces?.setMode?.('agents'); return; }
|
|
526
|
+
if (el.dataset.paGo === 'routines') { close(); if (typeof openRoutines === 'function') openRoutines(); }
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
// Something else changed the projects or the workflows: the chip (and an open sheet) read again.
|
|
530
|
+
for (const name of ['floless:projects-changed', 'floless:apps-changed']) window.addEventListener(name, () => { if (state.project) void load(); });
|
|
531
|
+
|
|
532
|
+
window.flolessProjectAccess = {
|
|
533
|
+
/** workspaces.js: the project now open in the Workspaces tab, or null when none is. */
|
|
534
|
+
setProject(project) {
|
|
535
|
+
const next = project && project.id ? { id: project.id, name: project.name || project.id, uuid: project.uuid } : null;
|
|
536
|
+
// The same project shown again (a mode switch back to Workspaces, a rename): read again, since the Agents tab
|
|
537
|
+
// or Routines may have changed what reaches it meanwhile.
|
|
538
|
+
if (next && state.project && next.id === state.project.id) { state.project = { ...state.project, name: next.name }; if (!isOpen()) void load(); return; }
|
|
539
|
+
close();
|
|
540
|
+
state.project = next; state.data = null; state.error = ''; state.seq += 1;
|
|
541
|
+
$chip.hidden = !next;
|
|
542
|
+
paintChip();
|
|
543
|
+
if (next) void load();
|
|
544
|
+
},
|
|
545
|
+
open, close, refresh: load, isOpen,
|
|
546
|
+
};
|
|
547
|
+
const current = window.flolessWorkspaces?.currentProject?.();
|
|
548
|
+
if (current) window.flolessProjectAccess.setProject(current);
|
|
549
|
+
})();
|