@floless/app 0.158.0 → 0.160.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 +140655 -117708
- package/dist/schemas/drawing-check.profile.v1.schema.json +33 -1
- package/dist/schemas/steel.model.v2.schema.json +1 -0
- package/dist/skills/floless-app-actions/SKILL.md +23 -5
- package/dist/skills/floless-app-bridge/SKILL.md +5 -3
- package/dist/skills/floless-app-onboarding/SKILL.md +69 -5
- package/dist/skills/floless-app-onboarding/references/floless-surfaces.md +8 -6
- package/dist/skills/floless-app-queue/SKILL.md +3 -1
- package/dist/skills/floless-app-rfi/SKILL.md +29 -1
- package/dist/skills/floless-app-steel-model/SKILL.md +11 -5
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +28 -8
- package/dist/skills/floless-app-workflows/SKILL.md +6 -3
- package/dist/web/agents.js +12 -5
- package/dist/web/app.css +266 -159
- package/dist/web/app.js +23 -51
- package/dist/web/aware.js +533 -546
- package/dist/web/chat-question-card.js +24 -1
- package/dist/web/chat.css +170 -48
- package/dist/web/chat.js +1406 -208
- package/dist/web/commands-shell.js +1104 -177
- package/dist/web/commands-steel.js +2 -0
- package/dist/web/drawing-check-editor.html +10 -0
- package/dist/web/drawing-check-editor.js +44 -0
- package/dist/web/guide.js +12 -2
- package/dist/web/index.html +62 -48
- package/dist/web/instructor.js +33 -12
- package/dist/web/pages.js +186 -31
- package/dist/web/panels.js +19 -1
- package/dist/web/project-access.js +67 -8
- package/dist/web/project-modules.js +474 -0
- package/dist/web/project-rfis.js +715 -0
- package/dist/web/project-workflows.js +506 -0
- package/dist/web/run-history.js +198 -0
- package/dist/web/run-page-view.js +12 -2
- package/dist/web/steel-3d-core.js +75 -1
- package/dist/web/steel-3d-view.js +8 -38
- package/dist/web/steel-editor.html +263 -59
- package/dist/web/steel-model-v2-projection.js +7 -0
- package/dist/web/workspace-root-recovery.js +119 -0
- package/dist/web/workspaces.js +493 -161
- package/launch-starting-page.mjs +5 -2
- package/launch.mjs +136 -78
- package/package.json +6 -1
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A project's Workflows step (#2470 R6.2): the workflows this project owns, each with its state and how its current
|
|
3
|
+
* version last ran; New workflow… with this project chosen; archived ones in a closed section.
|
|
4
|
+
*
|
|
5
|
+
* It renders what GET /api/workflows/owned?projectId= answers and opens what already exists — the workflow's canvas or
|
|
6
|
+
* draft view (flolessBridge.openOwnedWorkflow), an archived one's Restore card (openArchivedWorkflow), the New workflow
|
|
7
|
+
* dialog (flolessBridge.newWorkflow). It builds nothing and runs nothing. Spec:
|
|
8
|
+
* docs/superpowers/specs/2026-10-22-2470-r6-2-workflows-tab-PLAN.md.
|
|
9
|
+
*/
|
|
10
|
+
(() => {
|
|
11
|
+
const bridge = () => window.flolessBridge || {};
|
|
12
|
+
const api = (path) => {
|
|
13
|
+
if (typeof bridge().api === 'function') return bridge().api(path);
|
|
14
|
+
return fetch(path).then(async (res) => {
|
|
15
|
+
const body = await res.json().catch(() => ({}));
|
|
16
|
+
if (!res.ok || body.ok === false) { const err = new Error(body.error || `HTTP ${res.status}`); err.status = res.status; err.body = body; throw err; }
|
|
17
|
+
return body;
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
|
21
|
+
const toast = (msg, kind) => { if (typeof window.showToast === 'function') window.showToast(msg, kind); };
|
|
22
|
+
|
|
23
|
+
function ago(iso, now = Date.now()) {
|
|
24
|
+
const t = Date.parse(iso);
|
|
25
|
+
if (!Number.isFinite(t)) return '';
|
|
26
|
+
const s = Math.max(0, Math.round((now - t) / 1000));
|
|
27
|
+
if (s < 60) return 'just now';
|
|
28
|
+
const m = Math.round(s / 60);
|
|
29
|
+
if (m < 60) return `${m} min ago`;
|
|
30
|
+
const h = Math.round(m / 60);
|
|
31
|
+
if (h < 24) return `${h} h ago`;
|
|
32
|
+
const d = Math.round(h / 24);
|
|
33
|
+
return d === 1 ? 'yesterday' : `${d} days ago`;
|
|
34
|
+
}
|
|
35
|
+
const exact = (iso) => { const t = Date.parse(iso); return Number.isFinite(t) ? new Date(t).toLocaleString() : ''; };
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The line under a row's name. Runs belong to the CURRENT published version (its runtime id changes on every
|
|
39
|
+
* publish), so it says "this version" and never "never run"; a row the server did not check says just that.
|
|
40
|
+
*/
|
|
41
|
+
function runLine(w, now) {
|
|
42
|
+
if (w.status === 'archived') return 'Archived. Restore it from the Workflows page to use it again.';
|
|
43
|
+
if (!w.activePublication) return 'Not compiled yet';
|
|
44
|
+
const f = w.runFacts;
|
|
45
|
+
if (!f || f.checked === false) return 'Last run not checked';
|
|
46
|
+
const when = f.lastRunAt ? ago(f.lastRunAt, now) : '';
|
|
47
|
+
switch (f.lastRun) {
|
|
48
|
+
// #2644: a Drawing Checker or Steel Model workflow this account's plan does not include: its run is not shown.
|
|
49
|
+
case 'locked': return 'Locked: its module isn’t active for this account, so its last run isn’t shown';
|
|
50
|
+
case 'none': return 'This version hasn’t run yet';
|
|
51
|
+
case 'ok': return when ? `This version last ran ${when} and finished` : 'This version’s last run finished';
|
|
52
|
+
case 'failed': return when ? `This version last ran ${when} and failed` : 'This version’s last run failed';
|
|
53
|
+
default: return when ? `This version last ran ${when}; its result isn’t recorded` : 'This version’s last run couldn’t be read';
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function chip(w) {
|
|
58
|
+
if (w.status === 'archived') return '<span class="pw-chip is-muted">Archived</span>';
|
|
59
|
+
if (!w.activePublication) return '<span class="pw-chip is-muted">Draft</span>';
|
|
60
|
+
return '<span class="pw-chip">Published</span>';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function rowHtml(w, now) {
|
|
64
|
+
const archived = w.status === 'archived';
|
|
65
|
+
const at = w.runFacts && w.runFacts.checked && w.runFacts.lastRunAt ? ` data-tip="${esc(exact(w.runFacts.lastRunAt))}"` : '';
|
|
66
|
+
const tip = archived ? 'Shows this workflow under Archived on the Workflows page, where you can restore it'
|
|
67
|
+
: w.activePublication ? 'Opens this workflow on the Workflows tab' : 'Opens this draft on the Workflows tab';
|
|
68
|
+
// Each command id is written whole; only the instance after "#" varies.
|
|
69
|
+
const carrier = archived
|
|
70
|
+
? `data-pw-archived="1" data-command-id="shell.project-workflow-open-archived#${esc(w.workflowId)}"`
|
|
71
|
+
: `data-command-id="shell.project-workflow-open#${esc(w.workflowId)}"`;
|
|
72
|
+
return `<div class="pg-row pw-row" role="listitem">
|
|
73
|
+
<button type="button" class="pw-row-open" data-pw-open="${esc(w.workflowId)}" ${carrier} data-command-instance-label="${esc(w.displayName)}" data-tip="${esc(tip)}">
|
|
74
|
+
<span class="pg-row-line"><span class="pg-row-title">${esc(w.displayName)}</span>${chip(w)}</span>
|
|
75
|
+
<span class="pg-row-meta"${at}>${esc(runLine(w, now))}</span>
|
|
76
|
+
</button>
|
|
77
|
+
</div>`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* #2603: a workflow folder whose details name another owner. FloLess no longer lists it as a workflow, and nothing
|
|
82
|
+
* runs or edits it until the person chooses; neither choice deletes anything. Shown on the project's Workflows step
|
|
83
|
+
* (`where: 'step'`) and, for folders no project step shows — the standalone workflows, a folder no project lives in —
|
|
84
|
+
* on the Workflows page (`where: 'landing'`). Each place has its own Instructor ids; the instance is the workflow id.
|
|
85
|
+
*/
|
|
86
|
+
const SET_APART_WHY = {
|
|
87
|
+
'misplaced': (x) => `Its details name “${x}”, but it was found in this folder.`,
|
|
88
|
+
'foreign-root': () => 'Its details name a project in a different Workspace.',
|
|
89
|
+
'owner-missing': (x) => `Its details name “${x}”, which can’t be found any more.`,
|
|
90
|
+
'incarnation-mismatch': (x) => `Its details name an earlier copy of “${x}”, not the project as it is now.`,
|
|
91
|
+
};
|
|
92
|
+
const noProjectHere = (q) => q.folder && q.folder.kind === 'project' && !q.folder.projectId;
|
|
93
|
+
/** One set-apart folder: where it is AND its workflow id — copies of one workflow can sit in several folders. */
|
|
94
|
+
const setApartKey = (q) => (q.folder.kind === 'standalone' ? `standalone/${q.workflowId}` : `project/${q.folder.locator}/${q.workflowId}`);
|
|
95
|
+
function setApartRowHtml(q, row, where) {
|
|
96
|
+
const name = q.displayName || 'Unnamed workflow';
|
|
97
|
+
const why = (SET_APART_WHY[q.reason] || SET_APART_WHY.misplaced)(q.claimedOwnerLabel || 'another project');
|
|
98
|
+
const notes = [];
|
|
99
|
+
if (where === 'landing') notes.push(q.folder.kind === 'standalone' ? 'Among the standalone workflows.' : `In the folder “${q.folderLabel || q.folder.locator}”, where no project lives now.`);
|
|
100
|
+
notes.push(why);
|
|
101
|
+
if (!q.hasSource) notes.push('It has no workflow file, so the draft would start empty.');
|
|
102
|
+
if (q.archived) notes.push('It was archived, and stays archived if you keep it.');
|
|
103
|
+
if (q.hasConversations) notes.push('Its chats stay with the old folder, and while they are kept FloLess keeps older Knowledge versions instead of cleaning them up.');
|
|
104
|
+
const key = esc(setApartKey(q));
|
|
105
|
+
const label = `data-command-instance-label="${esc(name)}"`;
|
|
106
|
+
const busy = row.busy ? ' disabled' : '';
|
|
107
|
+
// The command ids are written whole; only the instance after "#" varies.
|
|
108
|
+
const keep = noProjectHere(q) ? ''
|
|
109
|
+
: row.unreadable
|
|
110
|
+
? (where === 'landing'
|
|
111
|
+
? `<button type="button" class="ghost" data-pw-setapart="keep-empty" data-pw-setapart-id="${key}" data-command-id="shell.workflows-setapart-keep-empty#${esc(setApartKey(q))}" ${label}${busy}
|
|
112
|
+
data-tip="Makes an empty draft with this name. The old folder is kept aside, so the file can still be recovered.">${row.busy === 'keep-empty' ? 'Keeping…' : 'Keep without its workflow file'}</button>`
|
|
113
|
+
: `<button type="button" class="ghost" data-pw-setapart="keep-empty" data-pw-setapart-id="${key}" data-command-id="shell.project-workflow-setapart-keep-empty#${esc(setApartKey(q))}" ${label}${busy}
|
|
114
|
+
data-tip="Makes an empty draft with this name. The old folder is kept aside, so the file can still be recovered.">${row.busy === 'keep-empty' ? 'Keeping…' : 'Keep without its workflow file'}</button>`)
|
|
115
|
+
: (where === 'landing'
|
|
116
|
+
? `<button type="button" class="ghost" data-pw-setapart="keep" data-pw-setapart-id="${key}" data-command-id="shell.workflows-setapart-keep#${esc(setApartKey(q))}" ${label}${busy}
|
|
117
|
+
data-tip="Moves the old folder aside, then makes a new draft from its name and workflow file.">${row.busy === 'keep' ? 'Keeping…' : 'Keep as a workflow here'}</button>`
|
|
118
|
+
: `<button type="button" class="ghost" data-pw-setapart="keep" data-pw-setapart-id="${key}" data-command-id="shell.project-workflow-setapart-keep#${esc(setApartKey(q))}" ${label}${busy}
|
|
119
|
+
data-tip="Moves the old folder aside, then makes a new draft in this project from its name and workflow file.">${row.busy === 'keep' ? 'Keeping…' : 'Keep as a workflow here'}</button>`);
|
|
120
|
+
const asideTip = 'Moves the folder aside and keeps it on this computer. It is not listed as a workflow, and it is not included when the project is exported or duplicated.';
|
|
121
|
+
const aside = where === 'landing'
|
|
122
|
+
? `<button type="button" class="ghost" data-pw-setapart="set-aside" data-pw-setapart-id="${key}" data-command-id="shell.workflows-setapart-aside#${esc(setApartKey(q))}" ${label}${busy}
|
|
123
|
+
data-tip="${asideTip}">${row.busy === 'set-aside' ? 'Setting aside…' : 'Set it aside'}</button>`
|
|
124
|
+
: `<button type="button" class="ghost" data-pw-setapart="set-aside" data-pw-setapart-id="${key}" data-command-id="shell.project-workflow-setapart-aside#${esc(setApartKey(q))}" ${label}${busy}
|
|
125
|
+
data-tip="${asideTip}">${row.busy === 'set-aside' ? 'Setting aside…' : 'Set it aside'}</button>`;
|
|
126
|
+
const note = row.unreadable
|
|
127
|
+
? '<p class="pm-note">FloLess couldn’t read this workflow’s file, so it hasn’t made a draft and nothing was moved.</p>'
|
|
128
|
+
: row.error ? `<p class="pm-note">${esc(row.error)}</p>` : '';
|
|
129
|
+
return `<div class="pm-strip-row pw-setapart-row"${row.busy ? ' aria-busy="true"' : ''}>
|
|
130
|
+
<span><span class="pg-row-title">${esc(name)}</span>${q.archived ? ' <span class="pw-chip is-muted">Archived</span>' : ''}
|
|
131
|
+
<span class="pg-row-meta">${esc(notes.join(' '))}</span>${note}</span>
|
|
132
|
+
<span class="pm-strip-acts">${keep}${aside}</span></div>`;
|
|
133
|
+
}
|
|
134
|
+
function setApartHtml(view, where = 'step') {
|
|
135
|
+
const items = view.setApart || [];
|
|
136
|
+
if (!items.length) return '';
|
|
137
|
+
const title = items.length === 1 ? '1 workflow folder was set apart' : `${items.length} workflow folders were set apart`;
|
|
138
|
+
return `<div class="pg-empty pm-strip pw-setapart" role="group" aria-label="Workflow folders set apart">
|
|
139
|
+
<p class="pg-empty-title">${title}</p>
|
|
140
|
+
<p class="pg-row-meta">Their details name a different owner from the folder they are in, so FloLess isn’t listing them as workflows. Nothing can run or edit them until you choose. Nothing is deleted.</p>
|
|
141
|
+
${items.map((q) => setApartRowHtml(q, (view.setApartRows || {})[setApartKey(q)] || {}, where)).join('')}</div>`;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const LOAD_FAILED = 'FloLess couldn’t read the workflow list just now. Check that FloLess is still running, then try again.';
|
|
145
|
+
/**
|
|
146
|
+
* The sentence a failed read shows. FloLess's own "could not be reached" / "took too long" answers (no HTTP status) are
|
|
147
|
+
* written for people; anything the server answered with a status gets the fixed sentence, never its raw text.
|
|
148
|
+
*/
|
|
149
|
+
const loadFailure = (error) => (!error?.status && typeof error?.message === 'string' && /^FloLess /.test(error.message) ? error.message : LOAD_FAILED);
|
|
150
|
+
|
|
151
|
+
/** The step's markup for one answer. `view`: { status: 'loading' | 'ready' | 'failed', rows, error, archivedOpen, busyNew }. */
|
|
152
|
+
function html(view, now = Date.now()) {
|
|
153
|
+
const newBtn = (cls) => `<button type="button" class="ghost ${cls}" data-pw-new="1" data-command-id="shell.project-workflow-new"${view.busyNew ? ' disabled aria-busy="true"' : ''}
|
|
154
|
+
data-tip="Name a new workflow for this project. AI builds it with you; nothing is made until you confirm.">New workflow…</button>`;
|
|
155
|
+
const head = `<div class="step-head"><span tabindex="-1" data-pw-heading="1">Workflows</span>${view.status === 'ready' && view.rows.some((w) => w.status !== 'archived') ? newBtn('pw-new') : ''}</div>
|
|
156
|
+
<p class="pg-sub">Repeatable checks and reports that belong to this project. Agents, schedules and other workflows that
|
|
157
|
+
use this project are under <button type="button" class="pw-access" data-pw-access="1" aria-haspopup="dialog" data-command-id="shell.project-workflows-access"
|
|
158
|
+
data-tip="Shows every Agent, schedule and workflow that reaches into this project">Project access</button>.</p>`;
|
|
159
|
+
if (view.status === 'loading') return `${head}<p class="pg-loading-line">Loading this project’s workflows…</p>`;
|
|
160
|
+
if (view.status === 'gone') {
|
|
161
|
+
return `${head}<div class="pg-empty pw-failed"><p class="pg-empty-title">FloLess couldn’t find this project any more.</p>
|
|
162
|
+
<p>It may have been archived or removed. Go back to your projects to open it again.</p></div>`;
|
|
163
|
+
}
|
|
164
|
+
if (view.status === 'failed') {
|
|
165
|
+
return `${head}<div class="pg-empty pw-failed"><p class="pg-empty-title">FloLess couldn’t load this project’s workflows.</p>
|
|
166
|
+
<p>${esc(view.error || LOAD_FAILED)}</p>
|
|
167
|
+
<p><button type="button" class="ghost" data-pw-retry="1" data-command-id="shell.project-workflows-retry">Try again</button></p></div>`;
|
|
168
|
+
}
|
|
169
|
+
const active = view.rows.filter((w) => w.status !== 'archived');
|
|
170
|
+
const archived = view.rows.filter((w) => w.status === 'archived');
|
|
171
|
+
const setApart = setApartHtml(view);
|
|
172
|
+
const list = active.length
|
|
173
|
+
? `<div class="pg-list" role="list" aria-label="Workflows in this project">${active.map((w) => rowHtml(w, now)).join('')}</div>`
|
|
174
|
+
: `<div class="pg-empty pw-empty"><p class="pg-empty-title">No workflows in this project yet</p>
|
|
175
|
+
<p>Build one with New workflow…, or ask AI Chat to build one for this project.</p><p>${newBtn('pw-new-empty')}</p></div>`;
|
|
176
|
+
const archivedHtml = archived.length
|
|
177
|
+
? `<details class="ws-archived pw-archived"${view.archivedOpen ? ' open' : ''}>
|
|
178
|
+
<summary class="ws-archived-summary" data-command-id="shell.project-workflows-archived"><span class="ws-archived-caret hd-caret" aria-hidden="true">▸</span>Archived <span class="ws-archived-count">${archived.length}</span></summary>
|
|
179
|
+
<div class="pg-list" role="list" aria-label="Archived workflows">${archived.map((w) => rowHtml(w, now)).join('')}</div></details>`
|
|
180
|
+
: '';
|
|
181
|
+
return head + setApart + list + archivedHtml;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// One pane, one project at a time: a read that answers after the person left the project or the step is dropped.
|
|
185
|
+
let state = null; // { pane, project, generation, view, inflight, again }
|
|
186
|
+
let opening = false;
|
|
187
|
+
|
|
188
|
+
// The live region stays mounted across re-renders (a fresh one each time is often not announced); only the body below
|
|
189
|
+
// it is redrawn. Found by class among the pane's own children.
|
|
190
|
+
const ownChild = (pane, cls) => [...pane.children].find((el) => el.classList.contains(cls)) || null;
|
|
191
|
+
const announce = (pane, text) => { const live = ownChild(pane, 'pw-live'); if (live) live.textContent = text; };
|
|
192
|
+
|
|
193
|
+
function paint() {
|
|
194
|
+
const { pane, view } = state;
|
|
195
|
+
const active = pane.contains(document.activeElement) && document.activeElement !== document.body ? document.activeElement : null;
|
|
196
|
+
// The heading carries no Instructor id; it is where Project access's "Show on the Workflows step" sends the keyboard,
|
|
197
|
+
// often while the list is still loading, so it is kept across the redraw too.
|
|
198
|
+
const focused = active?.hasAttribute('data-pw-heading') ? 'heading' : active?.getAttribute('data-command-id') ?? null;
|
|
199
|
+
let body = ownChild(pane, 'pw-body');
|
|
200
|
+
if (!body) {
|
|
201
|
+
pane.innerHTML = '<span class="sr-only pw-live" role="status" aria-live="polite"></span><div class="pw-body"></div>';
|
|
202
|
+
body = ownChild(pane, 'pw-body');
|
|
203
|
+
}
|
|
204
|
+
body.innerHTML = html(view);
|
|
205
|
+
if (focused === 'heading') body.querySelector('[data-pw-heading]')?.focus({ preventScroll: true });
|
|
206
|
+
else if (focused) {
|
|
207
|
+
const again = [...body.querySelectorAll('[data-command-id]')].find((el) => el.getAttribute('data-command-id') === focused);
|
|
208
|
+
if (again) again.focus({ preventScroll: true });
|
|
209
|
+
// Try again is gone once the list is back: the keyboard lands on the step's heading, not on the page.
|
|
210
|
+
else if (focused === 'shell.project-workflows-retry') body.querySelector('[data-pw-heading]')?.focus({ preventScroll: true });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async function load() {
|
|
215
|
+
if (!state) return;
|
|
216
|
+
if (state.inflight) { state.again = true; return; }
|
|
217
|
+
const mine = state;
|
|
218
|
+
const generation = mine.generation;
|
|
219
|
+
mine.inflight = true;
|
|
220
|
+
try {
|
|
221
|
+
const body = await api(`/api/workflows/owned?archived=1&projectId=${encodeURIComponent(mine.project.id)}`);
|
|
222
|
+
if (state !== mine || mine.generation !== generation) return;
|
|
223
|
+
const setApart = Array.isArray(body.quarantined) ? body.quarantined : [];
|
|
224
|
+
// A row's follow-up (its file couldn't be read, or what the last answer said) is kept while it is still listed.
|
|
225
|
+
const rowsState = Object.fromEntries(Object.entries(mine.view.setApartRows || {})
|
|
226
|
+
.filter(([id, row]) => (row.unreadable || row.error) && setApart.some((q) => setApartKey(q) === id))
|
|
227
|
+
.map(([id, row]) => [id, { ...(row.unreadable ? { unreadable: true } : {}), ...(row.error ? { error: row.error } : {}) }]));
|
|
228
|
+
mine.view = { ...mine.view, status: 'ready', rows: Array.isArray(body.workflows) ? body.workflows : [], setApart, setApartRows: rowsState, error: null };
|
|
229
|
+
const n = mine.view.rows.filter((w) => w.status !== 'archived').length;
|
|
230
|
+
paint();
|
|
231
|
+
if (mine.focusAfterSetApart) {
|
|
232
|
+
// The answered row is gone: the keyboard goes to the next set-apart row, else to the step's heading.
|
|
233
|
+
mine.focusAfterSetApart = false;
|
|
234
|
+
(mine.pane.querySelector('[data-pw-setapart]') || mine.pane.querySelector('[data-pw-heading]'))?.focus({ preventScroll: true });
|
|
235
|
+
}
|
|
236
|
+
const said = n === 0 ? 'No workflows in this project yet' : `${n} workflow${n === 1 ? '' : 's'} in this project`;
|
|
237
|
+
announce(mine.pane, setApart.length
|
|
238
|
+
? `${said}. ${setApart.length} set-apart folder${setApart.length === 1 ? ' needs' : 's need'} your decision.` : said);
|
|
239
|
+
} catch (error) {
|
|
240
|
+
if (state !== mine || mine.generation !== generation) return;
|
|
241
|
+
const gone = error?.status === 404 && error?.body?.code === 'unknown-project';
|
|
242
|
+
mine.view = { ...mine.view, status: gone ? 'gone' : 'failed', error: gone ? null : loadFailure(error) };
|
|
243
|
+
paint();
|
|
244
|
+
announce(mine.pane, gone ? 'FloLess couldn’t find this project any more.' : 'FloLess couldn’t load this project’s workflows.');
|
|
245
|
+
} finally {
|
|
246
|
+
mine.inflight = false;
|
|
247
|
+
// A change that arrived meanwhile is read once more; a dialog in progress holds it until it settles.
|
|
248
|
+
if (state === mine && mine.again && !mine.view.busyNew) { mine.again = false; void load(); }
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function render(pane, project) {
|
|
253
|
+
if (!pane || !project) return;
|
|
254
|
+
const same = state && state.pane === pane && state.project.id === project.id;
|
|
255
|
+
const keepOpen = same ? state.view.archivedOpen : false;
|
|
256
|
+
state = { pane, project, generation: (state?.generation || 0) + 1, view: { status: 'loading', rows: [], archivedOpen: keepOpen, busyNew: false },
|
|
257
|
+
inflight: false, again: false, stale: false };
|
|
258
|
+
paint();
|
|
259
|
+
if (!same) watchVisibility(pane);
|
|
260
|
+
void load();
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// On screen: the pane itself is shown AND the Workspaces view around it is (switching to the Workflows tab hides the
|
|
264
|
+
// whole view, not the pane). A DOM without layout (a test harness) counts as shown unless the pane is hidden.
|
|
265
|
+
const shown = (pane) => !pane.hidden
|
|
266
|
+
&& (typeof pane.checkVisibility === 'function' ? pane.checkVisibility() : pane.offsetParent !== null);
|
|
267
|
+
|
|
268
|
+
/** A workflow changed or a run ended: re-read while the step is on screen, otherwise when it is next shown. */
|
|
269
|
+
function refresh() {
|
|
270
|
+
if (!state) return;
|
|
271
|
+
if (!shown(state.pane)) { state.stale = true; return; }
|
|
272
|
+
if (state.view.busyNew) { state.again = true; return; }
|
|
273
|
+
void load();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Coming back to the step after it was out of view (the Workflows tab, where its workflows are run) always re-reads:
|
|
277
|
+
// a change message sent while the event stream was reconnecting is never seen, so being told is not relied on.
|
|
278
|
+
let observer = null;
|
|
279
|
+
function watchVisibility(pane) {
|
|
280
|
+
observer?.disconnect();
|
|
281
|
+
if (typeof IntersectionObserver !== 'function') return;
|
|
282
|
+
observer = new IntersectionObserver((entries) => {
|
|
283
|
+
if (state?.pane !== pane) return;
|
|
284
|
+
const inView = entries[entries.length - 1].isIntersecting;
|
|
285
|
+
if (!inView) { state.stale = true; return; }
|
|
286
|
+
if (state.stale) { state.stale = false; refresh(); }
|
|
287
|
+
});
|
|
288
|
+
observer.observe(pane);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
async function openRow(button) {
|
|
292
|
+
if (opening) return;
|
|
293
|
+
opening = true;
|
|
294
|
+
const id = button.getAttribute('data-pw-open');
|
|
295
|
+
try {
|
|
296
|
+
const b = bridge();
|
|
297
|
+
const fn = button.hasAttribute('data-pw-archived') ? b.openArchivedWorkflow : b.openOwnedWorkflow;
|
|
298
|
+
if (typeof fn !== 'function') throw new Error('this window cannot open workflows');
|
|
299
|
+
await fn.call(b, id);
|
|
300
|
+
} catch (error) {
|
|
301
|
+
// Opening switches to the Workflows tab first, so the step may be hidden: a toast is seen wherever the person is.
|
|
302
|
+
console.warn('[project-workflows] a workflow could not be opened', error);
|
|
303
|
+
toast('FloLess couldn’t open that workflow. It may have been moved or archived meanwhile. Try again, or open it from the Workflows page.', 'warn');
|
|
304
|
+
refresh();
|
|
305
|
+
} finally { opening = false; }
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const post = (path, body) => fetch(path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) })
|
|
309
|
+
.then(async (res) => {
|
|
310
|
+
const answer = await res.json().catch(() => ({}));
|
|
311
|
+
if (!res.ok || answer.ok === false) { const err = new Error(answer.error || `HTTP ${res.status}`); err.status = res.status; err.body = answer; throw err; }
|
|
312
|
+
return answer;
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* #2603: the person's answer about one set-apart folder. The server re-checks it is the folder they were shown and
|
|
317
|
+
* moves the folder aside before it makes anything, so a failure says exactly what did and didn't change. `ctx` is
|
|
318
|
+
* the place it was answered in (the project step or the Workflows page): its rows, how to repaint and re-read it.
|
|
319
|
+
*/
|
|
320
|
+
async function answerSetApart(button, ctx) {
|
|
321
|
+
const id = button.getAttribute('data-pw-setapart-id');
|
|
322
|
+
const choice = button.getAttribute('data-pw-setapart');
|
|
323
|
+
const q = ctx.items().find((item) => setApartKey(item) === id);
|
|
324
|
+
if (!q || ctx.rows()[id]?.busy) return;
|
|
325
|
+
const name = q.displayName || 'Unnamed workflow';
|
|
326
|
+
const here = q.folder.kind === 'standalone' ? 'among the standalone workflows' : ctx.where === 'step' ? 'in this project' : 'here';
|
|
327
|
+
ctx.setRow(id, { ...(ctx.rows()[id] || {}), busy: choice, error: null });
|
|
328
|
+
ctx.repaint();
|
|
329
|
+
ctx.announce(choice === 'set-aside' ? `Setting “${name}” aside…` : `Keeping “${name}” as a workflow ${here}…`);
|
|
330
|
+
try {
|
|
331
|
+
const folder = q.folder.kind === 'standalone' ? { kind: 'standalone' } : { kind: 'project', locator: q.folder.locator };
|
|
332
|
+
const answer = await post('/api/workflows/quarantined/repair', { folder, workflowId: q.workflowId, metadataDigest: q.metadataDigest, choice });
|
|
333
|
+
// Said wherever the person is now: the change happened even if they left this place.
|
|
334
|
+
toast(answer.outcome === 'set-aside' ? `“${name}” was set aside. Nothing was deleted.`
|
|
335
|
+
: answer.alreadyKept ? `An identical copy of “${name}” is already a workflow ${here}, so FloLess used it. The old folder was set aside.`
|
|
336
|
+
: answer.withoutSource ? `“${name}” is now an empty draft ${here}. The old folder was set aside, with its file.`
|
|
337
|
+
: `“${name}” is now a ${q.archived ? 'workflow (archived)' : 'draft'} ${here}. The old folder was set aside.`, 'ok');
|
|
338
|
+
if (!ctx.alive()) return;
|
|
339
|
+
ctx.afterAnswer();
|
|
340
|
+
void ctx.reload();
|
|
341
|
+
} catch (error) {
|
|
342
|
+
const code = error?.body?.code;
|
|
343
|
+
const unreadable = code === 'source-unreadable';
|
|
344
|
+
// The server's own sentence when it wrote one (it says what changed); a fixed one only when nothing answered.
|
|
345
|
+
const said = typeof error?.body?.error === 'string' && error.body.error ? error.body.error : null;
|
|
346
|
+
if (!said) console.error('[project-workflows] a set-apart folder could not be answered', error);
|
|
347
|
+
const message = unreadable ? null : said || 'FloLess couldn’t reach the server just now. Look at the list again before trying once more.';
|
|
348
|
+
if (!ctx.alive()) return;
|
|
349
|
+
ctx.setRow(id, { unreadable: unreadable || !!ctx.rows()[id]?.unreadable, error: message });
|
|
350
|
+
ctx.repaint();
|
|
351
|
+
ctx.announce(unreadable ? 'FloLess couldn’t read this workflow’s file, so it hasn’t made a draft and nothing was moved.' : message);
|
|
352
|
+
[...ctx.host().querySelectorAll('[data-pw-setapart-id]')].find((el) => el.getAttribute('data-pw-setapart-id') === id)?.focus({ preventScroll: true });
|
|
353
|
+
// Whatever the answer was, the list is read again so it shows what is true now.
|
|
354
|
+
void ctx.reload();
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** The project step as a place to answer set-apart folders. */
|
|
359
|
+
function stepContext(mine) {
|
|
360
|
+
return {
|
|
361
|
+
where: 'step',
|
|
362
|
+
items: () => mine.view.setApart || [],
|
|
363
|
+
rows: () => mine.view.setApartRows || {},
|
|
364
|
+
setRow: (id, row) => { mine.view = { ...mine.view, setApartRows: { ...(mine.view.setApartRows || {}), [id]: row } }; },
|
|
365
|
+
repaint: () => paint(),
|
|
366
|
+
announce: (text) => announce(mine.pane, text),
|
|
367
|
+
alive: () => state === mine,
|
|
368
|
+
host: () => mine.pane,
|
|
369
|
+
afterAnswer: () => { mine.focusAfterSetApart = true; },
|
|
370
|
+
reload: () => load(),
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* #2603: the Workflows page shows the set-apart folders no project step can — the standalone workflows' and those in
|
|
376
|
+
* a folder no project lives in. aware.js owns the page and calls this after each paint with the slot and the list.
|
|
377
|
+
*/
|
|
378
|
+
const landing = { host: null, items: [], rows: {}, reload: null, focusNext: false };
|
|
379
|
+
function landingContext() {
|
|
380
|
+
return {
|
|
381
|
+
where: 'landing',
|
|
382
|
+
items: () => landing.items,
|
|
383
|
+
rows: () => landing.rows,
|
|
384
|
+
setRow: (id, row) => { landing.rows = { ...landing.rows, [id]: row }; },
|
|
385
|
+
repaint: () => paintLanding(),
|
|
386
|
+
announce: (text) => { const live = landing.host?.querySelector('.pw-live'); if (live) live.textContent = text; },
|
|
387
|
+
alive: () => !!landing.host && landing.host.isConnected,
|
|
388
|
+
host: () => landing.host,
|
|
389
|
+
afterAnswer: () => { landing.focusNext = true; },
|
|
390
|
+
reload: () => (typeof landing.reload === 'function' ? landing.reload() : undefined),
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
function paintLanding() {
|
|
394
|
+
if (!landing.host) return;
|
|
395
|
+
const active = landing.host.contains(document.activeElement) ? document.activeElement?.getAttribute('data-command-id') : null;
|
|
396
|
+
landing.host.innerHTML = '<span class="sr-only pw-live" role="status" aria-live="polite"></span>'
|
|
397
|
+
+ setApartHtml({ setApart: landing.items, setApartRows: landing.rows }, 'landing');
|
|
398
|
+
const again = active ? [...landing.host.querySelectorAll('[data-command-id]')].find((el) => el.getAttribute('data-command-id') === active) : null;
|
|
399
|
+
if (again) again.focus({ preventScroll: true });
|
|
400
|
+
else if (landing.focusNext) landing.host.querySelector('[data-pw-setapart]')?.focus({ preventScroll: true });
|
|
401
|
+
landing.focusNext = false;
|
|
402
|
+
}
|
|
403
|
+
function renderLandingSetApart(host, quarantined, reload) {
|
|
404
|
+
if (!host) return;
|
|
405
|
+
const items = (Array.isArray(quarantined) ? quarantined : []).filter((q) => q && q.folder && (q.folder.kind === 'standalone' || !q.folder.projectId));
|
|
406
|
+
const keep = new Set(items.map((q) => setApartKey(q)));
|
|
407
|
+
landing.rows = Object.fromEntries(Object.entries(landing.rows).filter(([id, row]) => keep.has(id) && (row.unreadable || row.error))
|
|
408
|
+
.map(([id, row]) => [id, { ...row, busy: undefined }]));
|
|
409
|
+
landing.host = host;
|
|
410
|
+
landing.items = items;
|
|
411
|
+
landing.reload = reload;
|
|
412
|
+
paintLanding();
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
async function newWorkflow(button) {
|
|
416
|
+
const mine = state;
|
|
417
|
+
if (!mine || mine.view.busyNew) return;
|
|
418
|
+
mine.view = { ...mine.view, busyNew: true };
|
|
419
|
+
paint();
|
|
420
|
+
try {
|
|
421
|
+
if (typeof bridge().newWorkflow !== 'function') throw new Error('Use ≡ → New workflow and choose this project as its location.');
|
|
422
|
+
await bridge().newWorkflow({ ownerProjectId: mine.project.id });
|
|
423
|
+
} catch (error) {
|
|
424
|
+
toast(error?.message || 'FloLess couldn’t open New workflow.', 'warn');
|
|
425
|
+
} finally {
|
|
426
|
+
if (state === mine) {
|
|
427
|
+
mine.view = { ...mine.view, busyNew: false };
|
|
428
|
+
mine.again = false;
|
|
429
|
+
paint();
|
|
430
|
+
void load();
|
|
431
|
+
if (!mine.pane.hidden) mine.pane.querySelector('[data-pw-new]')?.focus({ preventScroll: true });
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
document.addEventListener('click', (event) => {
|
|
437
|
+
const onLanding = landing.host && landing.host.contains(event.target) ? event.target.closest('[data-pw-setapart]') : null;
|
|
438
|
+
if (onLanding) { event.preventDefault(); void answerSetApart(onLanding, landingContext()); return; }
|
|
439
|
+
if (!state || !state.pane.contains(event.target)) return;
|
|
440
|
+
const open = event.target.closest('[data-pw-open]');
|
|
441
|
+
if (open) { event.preventDefault(); void openRow(open); return; }
|
|
442
|
+
const answer = event.target.closest('[data-pw-setapart]');
|
|
443
|
+
if (answer) { event.preventDefault(); void answerSetApart(answer, stepContext(state)); return; }
|
|
444
|
+
const create = event.target.closest('[data-pw-new]');
|
|
445
|
+
if (create) { event.preventDefault(); void newWorkflow(create); return; }
|
|
446
|
+
const access = event.target.closest('[data-pw-access]');
|
|
447
|
+
if (access) {
|
|
448
|
+
event.preventDefault();
|
|
449
|
+
if (typeof window.flolessProjectAccess?.open === 'function') window.flolessProjectAccess.open(access);
|
|
450
|
+
else toast('Use Project access in the project’s header to see what else reaches this project.', 'warn');
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
if (event.target.closest('[data-pw-retry]')) { event.preventDefault(); state.view = { ...state.view, status: 'loading' }; paint(); void load(); }
|
|
454
|
+
});
|
|
455
|
+
// The Archived section's open/closed state survives a re-read.
|
|
456
|
+
document.addEventListener('toggle', (event) => {
|
|
457
|
+
if (state && event.target?.matches?.('.pw-archived') && state.pane.contains(event.target)) {
|
|
458
|
+
state.view.archivedOpen = event.target.hasAttribute('open');
|
|
459
|
+
}
|
|
460
|
+
}, true);
|
|
461
|
+
window.addEventListener('floless:apps-changed', refresh);
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* #2603: the sentence a Duplicate or Import adds about the project's workflows, from the transfer's `workflowTransfer`.
|
|
465
|
+
* Null when there is nothing to say (no workflows, or an answer without the field). `warn` when any were not copied.
|
|
466
|
+
*/
|
|
467
|
+
const NOT_COPIED_WHY = {
|
|
468
|
+
'not-this-projects': 'it names another project as its owner',
|
|
469
|
+
'metadata-unreadable': 'its details couldn’t be read',
|
|
470
|
+
'source-unreadable': 'its workflow file couldn’t be read',
|
|
471
|
+
'ambiguous': 'the archive holds two different versions of it',
|
|
472
|
+
'unavailable': 'FloLess couldn’t read them just now',
|
|
473
|
+
};
|
|
474
|
+
function transferNote(raw, operation = 'duplicate') {
|
|
475
|
+
if (!raw || typeof raw !== 'object' || !Number.isInteger(raw.copied) || !Array.isArray(raw.notCopied)) return null;
|
|
476
|
+
const keeps = operation === 'import' ? 'They are still in the archive.' : 'The original keeps them.';
|
|
477
|
+
if (raw.outcome === 'unavailable') {
|
|
478
|
+
return { text: `FloLess couldn’t copy its workflows just now, so it has none. ${keeps}`, warn: true };
|
|
479
|
+
}
|
|
480
|
+
const parts = [];
|
|
481
|
+
if (raw.copied > 0) {
|
|
482
|
+
const archived = Number.isInteger(raw.archivedCopied) && raw.archivedCopied > 0 ? `, ${raw.archivedCopied} archived` : '';
|
|
483
|
+
parts.push(`${raw.copied} ${raw.copied === 1 ? 'workflow' : 'workflows'} copied as ${raw.copied === 1 ? 'a draft' : 'drafts'}${archived}.`);
|
|
484
|
+
}
|
|
485
|
+
const left = Number.isInteger(raw.leftBehindFiles) ? raw.leftBehindFiles : 0;
|
|
486
|
+
if (left > 0) parts.push(`${left} other ${left === 1 ? 'file' : 'files'} in the workflow folders, such as chats, ${left === 1 ? 'wasn’t' : 'weren’t'} carried.`);
|
|
487
|
+
if (raw.notCopied.length) {
|
|
488
|
+
const groups = new Map();
|
|
489
|
+
for (const row of raw.notCopied) {
|
|
490
|
+
const why = NOT_COPIED_WHY[row && row.reason] || 'FloLess couldn’t read it';
|
|
491
|
+
if (!groups.has(why)) groups.set(why, []);
|
|
492
|
+
groups.get(why).push(row && typeof row.displayName === 'string' && row.displayName ? `“${row.displayName}”` : null);
|
|
493
|
+
}
|
|
494
|
+
const said = [...groups].map(([why, names]) => {
|
|
495
|
+
const named = names.filter(Boolean).slice(0, 2);
|
|
496
|
+
const rest = names.length - named.length;
|
|
497
|
+
const who = named.length ? `${named.join(' and ')}${rest ? ` and ${rest} more` : ''}` : `${rest} ${rest === 1 ? 'workflow' : 'workflows'}`;
|
|
498
|
+
return `${who} (${why})`;
|
|
499
|
+
});
|
|
500
|
+
parts.push(`Not copied: ${said.join('; ')}. ${operation === 'import' ? `${raw.notCopied.length === 1 ? 'It is' : 'They are'} still in the archive.` : `The original keeps ${raw.notCopied.length === 1 ? 'it' : 'them'}.`}`);
|
|
501
|
+
}
|
|
502
|
+
return parts.length ? { text: parts.join(' '), warn: raw.notCopied.length > 0 } : null;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
window.flolessProjectWorkflows = { render, refresh, html, runLine, transferNote, renderLandingSetApart };
|
|
506
|
+
})();
|