@floless/app 0.157.0 → 0.159.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 +7 -0
- package/dist/floless-server.cjs +188306 -155284
- package/dist/schemas/drawing-check.profile.v1.schema.json +33 -1
- package/dist/skills/floless-app-actions/SKILL.md +26 -5
- package/dist/skills/floless-app-bridge/SKILL.md +5 -3
- package/dist/skills/floless-app-knowledge/SKILL.md +14 -1
- package/dist/skills/floless-app-knowledge/references/schema.md +4 -1
- package/dist/skills/floless-app-onboarding/SKILL.md +67 -4
- package/dist/skills/floless-app-onboarding/references/floless-surfaces.md +7 -4
- package/dist/skills/floless-app-queue/SKILL.md +3 -1
- package/dist/skills/floless-app-steel-model/SKILL.md +41 -1
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +71 -1
- package/dist/skills/floless-app-workflows/SKILL.md +6 -3
- package/dist/web/agents.js +12 -5
- package/dist/web/app.css +229 -27
- package/dist/web/app.js +6 -0
- package/dist/web/aware.js +275 -64
- package/dist/web/chat.css +60 -22
- package/dist/web/chat.js +396 -59
- package/dist/web/commands-shell.js +546 -11
- package/dist/web/commands-steel.js +1 -0
- package/dist/web/drawing-check-editor.html +10 -0
- package/dist/web/drawing-check-editor.js +44 -0
- package/dist/web/guide.js +4 -2
- package/dist/web/index.html +66 -12
- package/dist/web/instructor.js +21 -9
- package/dist/web/kb-categories.js +351 -0
- package/dist/web/kb-graph-worker.js +73 -0
- package/dist/web/pages.js +185 -19
- package/dist/web/project-access.js +67 -8
- package/dist/web/project-modules.js +474 -0
- package/dist/web/project-workflows.js +274 -0
- package/dist/web/run-page-view.js +353 -0
- package/dist/web/steel-3d-core.js +46 -0
- package/dist/web/steel-3d-view.js +8 -38
- package/dist/web/steel-editor.html +225 -43
- package/dist/web/tab-signal.js +323 -0
- package/dist/web/terminal-requests.js +48 -7
- package/dist/web/workspace-root-recovery.js +119 -0
- package/dist/web/workspaces.js +1597 -220
- package/launch-starting-page.mjs +184 -0
- package/launch.mjs +214 -73
- package/package.json +7 -1
- package/dist/web/report-files.js +0 -50
|
@@ -0,0 +1,274 @@
|
|
|
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
|
+
case 'none': return 'This version hasn’t run yet';
|
|
49
|
+
case 'ok': return when ? `This version last ran ${when} and finished` : 'This version’s last run finished';
|
|
50
|
+
case 'failed': return when ? `This version last ran ${when} and failed` : 'This version’s last run failed';
|
|
51
|
+
default: return when ? `This version last ran ${when}; its result isn’t recorded` : 'This version’s last run couldn’t be read';
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function chip(w) {
|
|
56
|
+
if (w.status === 'archived') return '<span class="pw-chip is-muted">Archived</span>';
|
|
57
|
+
if (!w.activePublication) return '<span class="pw-chip is-muted">Draft</span>';
|
|
58
|
+
return '<span class="pw-chip">Published</span>';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function rowHtml(w, now) {
|
|
62
|
+
const archived = w.status === 'archived';
|
|
63
|
+
const at = w.runFacts && w.runFacts.checked && w.runFacts.lastRunAt ? ` data-tip="${esc(exact(w.runFacts.lastRunAt))}"` : '';
|
|
64
|
+
const tip = archived ? 'Shows this workflow under Archived on the Workflows page, where you can restore it'
|
|
65
|
+
: w.activePublication ? 'Opens this workflow on the Workflows tab' : 'Opens this draft on the Workflows tab';
|
|
66
|
+
// Each command id is written whole; only the instance after "#" varies.
|
|
67
|
+
const carrier = archived
|
|
68
|
+
? `data-pw-archived="1" data-command-id="shell.project-workflow-open-archived#${esc(w.workflowId)}"`
|
|
69
|
+
: `data-command-id="shell.project-workflow-open#${esc(w.workflowId)}"`;
|
|
70
|
+
return `<div class="pg-row pw-row" role="listitem">
|
|
71
|
+
<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)}">
|
|
72
|
+
<span class="pg-row-line"><span class="pg-row-title">${esc(w.displayName)}</span>${chip(w)}</span>
|
|
73
|
+
<span class="pg-row-meta"${at}>${esc(runLine(w, now))}</span>
|
|
74
|
+
</button>
|
|
75
|
+
</div>`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const LOAD_FAILED = 'FloLess couldn’t read the workflow list just now. Check that FloLess is still running, then try again.';
|
|
79
|
+
/**
|
|
80
|
+
* The sentence a failed read shows. FloLess's own "could not be reached" / "took too long" answers (no HTTP status) are
|
|
81
|
+
* written for people; anything the server answered with a status gets the fixed sentence, never its raw text.
|
|
82
|
+
*/
|
|
83
|
+
const loadFailure = (error) => (!error?.status && typeof error?.message === 'string' && /^FloLess /.test(error.message) ? error.message : LOAD_FAILED);
|
|
84
|
+
|
|
85
|
+
/** The step's markup for one answer. `view`: { status: 'loading' | 'ready' | 'failed', rows, error, archivedOpen, busyNew }. */
|
|
86
|
+
function html(view, now = Date.now()) {
|
|
87
|
+
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"' : ''}
|
|
88
|
+
data-tip="Name a new workflow for this project. AI builds it with you; nothing is made until you confirm.">New workflow…</button>`;
|
|
89
|
+
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>
|
|
90
|
+
<p class="pg-sub">Repeatable checks and reports that belong to this project. Agents, schedules and other workflows that
|
|
91
|
+
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"
|
|
92
|
+
data-tip="Shows every Agent, schedule and workflow that reaches into this project">Project access</button>.</p>`;
|
|
93
|
+
if (view.status === 'loading') return `${head}<p class="pg-loading-line">Loading this project’s workflows…</p>`;
|
|
94
|
+
if (view.status === 'gone') {
|
|
95
|
+
return `${head}<div class="pg-empty pw-failed"><p class="pg-empty-title">FloLess couldn’t find this project any more.</p>
|
|
96
|
+
<p>It may have been archived or removed. Go back to your projects to open it again.</p></div>`;
|
|
97
|
+
}
|
|
98
|
+
if (view.status === 'failed') {
|
|
99
|
+
return `${head}<div class="pg-empty pw-failed"><p class="pg-empty-title">FloLess couldn’t load this project’s workflows.</p>
|
|
100
|
+
<p>${esc(view.error || LOAD_FAILED)}</p>
|
|
101
|
+
<p><button type="button" class="ghost" data-pw-retry="1" data-command-id="shell.project-workflows-retry">Try again</button></p></div>`;
|
|
102
|
+
}
|
|
103
|
+
const active = view.rows.filter((w) => w.status !== 'archived');
|
|
104
|
+
const archived = view.rows.filter((w) => w.status === 'archived');
|
|
105
|
+
const list = active.length
|
|
106
|
+
? `<div class="pg-list" role="list" aria-label="Workflows in this project">${active.map((w) => rowHtml(w, now)).join('')}</div>`
|
|
107
|
+
: `<div class="pg-empty pw-empty"><p class="pg-empty-title">No workflows in this project yet</p>
|
|
108
|
+
<p>Build one with New workflow…, or ask AI Chat to build one for this project.</p><p>${newBtn('pw-new-empty')}</p></div>`;
|
|
109
|
+
const archivedHtml = archived.length
|
|
110
|
+
? `<details class="ws-archived pw-archived"${view.archivedOpen ? ' open' : ''}>
|
|
111
|
+
<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>
|
|
112
|
+
<div class="pg-list" role="list" aria-label="Archived workflows">${archived.map((w) => rowHtml(w, now)).join('')}</div></details>`
|
|
113
|
+
: '';
|
|
114
|
+
return head + list + archivedHtml;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// One pane, one project at a time: a read that answers after the person left the project or the step is dropped.
|
|
118
|
+
let state = null; // { pane, project, generation, view, inflight, again }
|
|
119
|
+
let opening = false;
|
|
120
|
+
|
|
121
|
+
// The live region stays mounted across re-renders (a fresh one each time is often not announced); only the body below
|
|
122
|
+
// it is redrawn. Found by class among the pane's own children.
|
|
123
|
+
const ownChild = (pane, cls) => [...pane.children].find((el) => el.classList.contains(cls)) || null;
|
|
124
|
+
const announce = (pane, text) => { const live = ownChild(pane, 'pw-live'); if (live) live.textContent = text; };
|
|
125
|
+
|
|
126
|
+
function paint() {
|
|
127
|
+
const { pane, view } = state;
|
|
128
|
+
const active = pane.contains(document.activeElement) && document.activeElement !== document.body ? document.activeElement : null;
|
|
129
|
+
// The heading carries no Instructor id; it is where Project access's "Show on the Workflows step" sends the keyboard,
|
|
130
|
+
// often while the list is still loading, so it is kept across the redraw too.
|
|
131
|
+
const focused = active?.hasAttribute('data-pw-heading') ? 'heading' : active?.getAttribute('data-command-id') ?? null;
|
|
132
|
+
let body = ownChild(pane, 'pw-body');
|
|
133
|
+
if (!body) {
|
|
134
|
+
pane.innerHTML = '<span class="sr-only pw-live" role="status" aria-live="polite"></span><div class="pw-body"></div>';
|
|
135
|
+
body = ownChild(pane, 'pw-body');
|
|
136
|
+
}
|
|
137
|
+
body.innerHTML = html(view);
|
|
138
|
+
if (focused === 'heading') body.querySelector('[data-pw-heading]')?.focus({ preventScroll: true });
|
|
139
|
+
else if (focused) {
|
|
140
|
+
const again = [...body.querySelectorAll('[data-command-id]')].find((el) => el.getAttribute('data-command-id') === focused);
|
|
141
|
+
if (again) again.focus({ preventScroll: true });
|
|
142
|
+
// Try again is gone once the list is back: the keyboard lands on the step's heading, not on the page.
|
|
143
|
+
else if (focused === 'shell.project-workflows-retry') body.querySelector('[data-pw-heading]')?.focus({ preventScroll: true });
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async function load() {
|
|
148
|
+
if (!state) return;
|
|
149
|
+
if (state.inflight) { state.again = true; return; }
|
|
150
|
+
const mine = state;
|
|
151
|
+
const generation = mine.generation;
|
|
152
|
+
mine.inflight = true;
|
|
153
|
+
try {
|
|
154
|
+
const body = await api(`/api/workflows/owned?archived=1&projectId=${encodeURIComponent(mine.project.id)}`);
|
|
155
|
+
if (state !== mine || mine.generation !== generation) return;
|
|
156
|
+
mine.view = { ...mine.view, status: 'ready', rows: Array.isArray(body.workflows) ? body.workflows : [], error: null };
|
|
157
|
+
const n = mine.view.rows.filter((w) => w.status !== 'archived').length;
|
|
158
|
+
paint();
|
|
159
|
+
announce(mine.pane, n === 0 ? 'No workflows in this project yet' : `${n} workflow${n === 1 ? '' : 's'} in this project`);
|
|
160
|
+
} catch (error) {
|
|
161
|
+
if (state !== mine || mine.generation !== generation) return;
|
|
162
|
+
const gone = error?.status === 404 && error?.body?.code === 'unknown-project';
|
|
163
|
+
mine.view = { ...mine.view, status: gone ? 'gone' : 'failed', error: gone ? null : loadFailure(error) };
|
|
164
|
+
paint();
|
|
165
|
+
announce(mine.pane, gone ? 'FloLess couldn’t find this project any more.' : 'FloLess couldn’t load this project’s workflows.');
|
|
166
|
+
} finally {
|
|
167
|
+
mine.inflight = false;
|
|
168
|
+
// A change that arrived meanwhile is read once more; a dialog in progress holds it until it settles.
|
|
169
|
+
if (state === mine && mine.again && !mine.view.busyNew) { mine.again = false; void load(); }
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function render(pane, project) {
|
|
174
|
+
if (!pane || !project) return;
|
|
175
|
+
const same = state && state.pane === pane && state.project.id === project.id;
|
|
176
|
+
const keepOpen = same ? state.view.archivedOpen : false;
|
|
177
|
+
state = { pane, project, generation: (state?.generation || 0) + 1, view: { status: 'loading', rows: [], archivedOpen: keepOpen, busyNew: false },
|
|
178
|
+
inflight: false, again: false, stale: false };
|
|
179
|
+
paint();
|
|
180
|
+
if (!same) watchVisibility(pane);
|
|
181
|
+
void load();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// On screen: the pane itself is shown AND the Workspaces view around it is (switching to the Workflows tab hides the
|
|
185
|
+
// whole view, not the pane). A DOM without layout (a test harness) counts as shown unless the pane is hidden.
|
|
186
|
+
const shown = (pane) => !pane.hidden
|
|
187
|
+
&& (typeof pane.checkVisibility === 'function' ? pane.checkVisibility() : pane.offsetParent !== null);
|
|
188
|
+
|
|
189
|
+
/** A workflow changed or a run ended: re-read while the step is on screen, otherwise when it is next shown. */
|
|
190
|
+
function refresh() {
|
|
191
|
+
if (!state) return;
|
|
192
|
+
if (!shown(state.pane)) { state.stale = true; return; }
|
|
193
|
+
if (state.view.busyNew) { state.again = true; return; }
|
|
194
|
+
void load();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Coming back to the step after it was out of view (the Workflows tab, where its workflows are run) always re-reads:
|
|
198
|
+
// a change message sent while the event stream was reconnecting is never seen, so being told is not relied on.
|
|
199
|
+
let observer = null;
|
|
200
|
+
function watchVisibility(pane) {
|
|
201
|
+
observer?.disconnect();
|
|
202
|
+
if (typeof IntersectionObserver !== 'function') return;
|
|
203
|
+
observer = new IntersectionObserver((entries) => {
|
|
204
|
+
if (state?.pane !== pane) return;
|
|
205
|
+
const inView = entries[entries.length - 1].isIntersecting;
|
|
206
|
+
if (!inView) { state.stale = true; return; }
|
|
207
|
+
if (state.stale) { state.stale = false; refresh(); }
|
|
208
|
+
});
|
|
209
|
+
observer.observe(pane);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async function openRow(button) {
|
|
213
|
+
if (opening) return;
|
|
214
|
+
opening = true;
|
|
215
|
+
const id = button.getAttribute('data-pw-open');
|
|
216
|
+
try {
|
|
217
|
+
const b = bridge();
|
|
218
|
+
const fn = button.hasAttribute('data-pw-archived') ? b.openArchivedWorkflow : b.openOwnedWorkflow;
|
|
219
|
+
if (typeof fn !== 'function') throw new Error('this window cannot open workflows');
|
|
220
|
+
await fn.call(b, id);
|
|
221
|
+
} catch (error) {
|
|
222
|
+
// Opening switches to the Workflows tab first, so the step may be hidden: a toast is seen wherever the person is.
|
|
223
|
+
console.warn('[project-workflows] a workflow could not be opened', error);
|
|
224
|
+
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');
|
|
225
|
+
refresh();
|
|
226
|
+
} finally { opening = false; }
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async function newWorkflow(button) {
|
|
230
|
+
const mine = state;
|
|
231
|
+
if (!mine || mine.view.busyNew) return;
|
|
232
|
+
mine.view = { ...mine.view, busyNew: true };
|
|
233
|
+
paint();
|
|
234
|
+
try {
|
|
235
|
+
if (typeof bridge().newWorkflow !== 'function') throw new Error('Use ≡ → New workflow and choose this project as its location.');
|
|
236
|
+
await bridge().newWorkflow({ ownerProjectId: mine.project.id });
|
|
237
|
+
} catch (error) {
|
|
238
|
+
toast(error?.message || 'FloLess couldn’t open New workflow.', 'warn');
|
|
239
|
+
} finally {
|
|
240
|
+
if (state === mine) {
|
|
241
|
+
mine.view = { ...mine.view, busyNew: false };
|
|
242
|
+
mine.again = false;
|
|
243
|
+
paint();
|
|
244
|
+
void load();
|
|
245
|
+
if (!mine.pane.hidden) mine.pane.querySelector('[data-pw-new]')?.focus({ preventScroll: true });
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
document.addEventListener('click', (event) => {
|
|
251
|
+
if (!state || !state.pane.contains(event.target)) return;
|
|
252
|
+
const open = event.target.closest('[data-pw-open]');
|
|
253
|
+
if (open) { event.preventDefault(); void openRow(open); return; }
|
|
254
|
+
const create = event.target.closest('[data-pw-new]');
|
|
255
|
+
if (create) { event.preventDefault(); void newWorkflow(create); return; }
|
|
256
|
+
const access = event.target.closest('[data-pw-access]');
|
|
257
|
+
if (access) {
|
|
258
|
+
event.preventDefault();
|
|
259
|
+
if (typeof window.flolessProjectAccess?.open === 'function') window.flolessProjectAccess.open(access);
|
|
260
|
+
else toast('Use Project access in the project’s header to see what else reaches this project.', 'warn');
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (event.target.closest('[data-pw-retry]')) { event.preventDefault(); state.view = { ...state.view, status: 'loading' }; paint(); void load(); }
|
|
264
|
+
});
|
|
265
|
+
// The Archived section's open/closed state survives a re-read.
|
|
266
|
+
document.addEventListener('toggle', (event) => {
|
|
267
|
+
if (state && event.target?.matches?.('.pw-archived') && state.pane.contains(event.target)) {
|
|
268
|
+
state.view.archivedOpen = event.target.hasAttribute('open');
|
|
269
|
+
}
|
|
270
|
+
}, true);
|
|
271
|
+
window.addEventListener('floless:apps-changed', refresh);
|
|
272
|
+
|
|
273
|
+
window.flolessProjectWorkflows = { render, refresh, html, runLine };
|
|
274
|
+
})();
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The run viewer's view of a report that carries files (`report_folder`, #2262 slice 3c; follow-up #2476).
|
|
3
|
+
*
|
|
4
|
+
* Such a report refers to its pictures and files as `assets/…`, which resolve only inside its saved Page version. While
|
|
5
|
+
* that version is being saved the viewer shows the report's inert copy (the server made it; this file never touches a
|
|
6
|
+
* report's HTML) with a plain note, then switches to the version's own isolated frame once that frame says it is ready.
|
|
7
|
+
* What it says at every moment comes from the SERVER's answer about this exact run — never a guess:
|
|
8
|
+
*
|
|
9
|
+
* pending inert copy, "Saving this report…" (after 90 s: "Still saving…"); polled every 10 s, never an endless spinner
|
|
10
|
+
* saved with files: the Page version's frame, once it posts `floless-page-ready` for THIS navigation;
|
|
11
|
+
* without files: inert copy and the stored reason
|
|
12
|
+
* failed inert copy and the server's words
|
|
13
|
+
* none provisional for 30 s after the report arrived (a sender that could not queue first), then terminal
|
|
14
|
+
* frame did not become ready within 20 s, or reported itself unavailable: inert copy and "could not be shown here"
|
|
15
|
+
*
|
|
16
|
+
* Ordering: every answer and every piece of news carries `rev` and the server process's `epoch`. A state applies only if
|
|
17
|
+
* its `rev` is higher than the one held in the same epoch; a new epoch (FloLess restarted) resets what is held and
|
|
18
|
+
* reconciles from a new lookup. Only the newest lookup's answer may apply, and a new epoch invalidates every older one.
|
|
19
|
+
* One paint GENERATION fences every asynchronous step: a later paint, close, or workspace switch makes them do nothing.
|
|
20
|
+
*
|
|
21
|
+
* Loaded as a classic script before aware.js; tested by server/run-page-view-ui.test.ts with a fake clock.
|
|
22
|
+
*/
|
|
23
|
+
(function (root) {
|
|
24
|
+
'use strict';
|
|
25
|
+
|
|
26
|
+
var READY_WAIT_MS = 20000;
|
|
27
|
+
var POLL_MS = 10000;
|
|
28
|
+
var STILL_SAVING_MS = 90000;
|
|
29
|
+
var NONE_PROVISIONAL_MS = 30000;
|
|
30
|
+
var LOOKUP_TIMEOUT_MS = 15000;
|
|
31
|
+
var NEWS_KEPT = 64;
|
|
32
|
+
|
|
33
|
+
var NOTES = {
|
|
34
|
+
pending: 'Saving this report with its pictures and files to the workflow’s Page. It switches to that version when it is saved.',
|
|
35
|
+
still: 'Still saving this report to the workflow’s Page — large files take longer. It switches by itself when it is saved.',
|
|
36
|
+
opening: 'Opening the saved version of this report with its pictures and files…',
|
|
37
|
+
none: 'No saved version of this run was found on the workflow’s Page, so its pictures and files cannot be shown here. Run the workflow again to save it.',
|
|
38
|
+
frame: 'The saved version could not be shown here. Use Open in Pages to see it with its pictures and files.',
|
|
39
|
+
links: 'This report has links or content that open only in Pages. Use Open in Pages.',
|
|
40
|
+
};
|
|
41
|
+
var WITHHELD_NEXT = 'Run the workflow again to save them with it; if this keeps happening, ask AI Chat to check the workflow’s report folder.';
|
|
42
|
+
var FAILED_TAIL = 'Its pictures and files are not shown here.';
|
|
43
|
+
var PAGE_REQUESTS = ['floless-page-open', 'floless-page-link-unsupported', 'floless-page-blocked'];
|
|
44
|
+
|
|
45
|
+
function sentence(text) {
|
|
46
|
+
var t = String(text || '').trim();
|
|
47
|
+
return t && !/[.!?]$/.test(t) ? t + '.' : t;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function create(env) {
|
|
51
|
+
var win = env.win || root;
|
|
52
|
+
var now = env.now || function () { return Date.now(); };
|
|
53
|
+
var setTimer = env.setTimeout || function (fn, ms) { return root.setTimeout(fn, ms); };
|
|
54
|
+
var clearTimer = env.clearTimeout || function (id) { root.clearTimeout(id); };
|
|
55
|
+
var token = env.token || function () {
|
|
56
|
+
var bytes = new Uint8Array(16);
|
|
57
|
+
root.crypto.getRandomValues(bytes);
|
|
58
|
+
var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-';
|
|
59
|
+
var out = '';
|
|
60
|
+
for (var i = 0; i < 16; i += 1) out += alphabet.charAt(bytes[i] % 64);
|
|
61
|
+
return out;
|
|
62
|
+
};
|
|
63
|
+
var inert = env.inert;
|
|
64
|
+
var page = env.page;
|
|
65
|
+
var noteEl = env.note;
|
|
66
|
+
|
|
67
|
+
var gen = 0;
|
|
68
|
+
var view = null;
|
|
69
|
+
var news = new Map(); // "app\nrun\nfire" → newest answer heard (any window state)
|
|
70
|
+
|
|
71
|
+
function nkey(app, runId, fire) { return app + '\n' + runId + '\n' + (fire || ''); }
|
|
72
|
+
|
|
73
|
+
function setNote(text) {
|
|
74
|
+
if (!noteEl) return;
|
|
75
|
+
noteEl.hidden = !text;
|
|
76
|
+
noteEl.textContent = text || '';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function clearTimers(v) {
|
|
80
|
+
if (!v) return;
|
|
81
|
+
[v.pollTimer, v.stillTimer, v.readyTimer].forEach(function (t) { if (t != null) clearTimer(t); });
|
|
82
|
+
v.pollTimer = v.stillTimer = v.readyTimer = null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function blankPageFrame() {
|
|
86
|
+
page.hidden = true;
|
|
87
|
+
if (page.hasAttribute('src')) {
|
|
88
|
+
// Navigate away first so a hidden document stops running, then drop the address.
|
|
89
|
+
page.setAttribute('src', 'about:blank');
|
|
90
|
+
page.removeAttribute('src');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Whatever was on screen is over: every pending step does nothing, the Page frame is empty, the inert copy is back. */
|
|
95
|
+
function invalidate() {
|
|
96
|
+
gen += 1;
|
|
97
|
+
clearTimers(view);
|
|
98
|
+
view = null;
|
|
99
|
+
blankPageFrame();
|
|
100
|
+
if (inert) inert.hidden = false;
|
|
101
|
+
setNote('');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function reset() {
|
|
105
|
+
invalidate();
|
|
106
|
+
news.clear();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Has this step been overtaken (another paint, a close, a workspace switch, another workflow)? */
|
|
110
|
+
function stale(v, g) { return v !== view || v.gen !== g || gen !== g || env.currentApp() !== v.app; }
|
|
111
|
+
|
|
112
|
+
// ── applying what the server says ──────────────────────────────────────────────────────────────────────
|
|
113
|
+
|
|
114
|
+
function normalise(raw) {
|
|
115
|
+
if (!raw || typeof raw !== 'object') return null;
|
|
116
|
+
if (['pending', 'saved', 'failed', 'none'].indexOf(raw.state) < 0) return null;
|
|
117
|
+
if (!Number.isInteger(raw.rev) || typeof raw.epoch !== 'string' || !raw.epoch) return null;
|
|
118
|
+
return {
|
|
119
|
+
state: raw.state, rev: raw.rev, epoch: raw.epoch,
|
|
120
|
+
version: Number.isInteger(raw.version) ? raw.version : null,
|
|
121
|
+
files: Number.isInteger(raw.files) ? raw.files : null,
|
|
122
|
+
filesWithheld: typeof raw.filesWithheld === 'string' ? raw.filesWithheld : '',
|
|
123
|
+
reason: typeof raw.reason === 'string' ? raw.reason : '',
|
|
124
|
+
frameUrl: typeof raw.frameUrl === 'string' && raw.frameUrl.charAt(0) === '/' && raw.frameUrl.indexOf('//') !== 0 ? raw.frameUrl : '',
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** `workflow-page-captured` news → the same shape as a lookup answer (or null when it says nothing about a capture). */
|
|
129
|
+
function fromNews(m) {
|
|
130
|
+
if (!m || typeof m.app !== 'string' || typeof m.runId !== 'string' || !m.runId) return null;
|
|
131
|
+
if (typeof m.warning === 'string') return normalise({ state: 'failed', rev: m.rev, epoch: m.epoch, reason: m.warning });
|
|
132
|
+
if (Number.isInteger(m.version) && m.version >= 1) {
|
|
133
|
+
return normalise({ state: 'saved', rev: m.rev, epoch: m.epoch, version: m.version, files: m.files, filesWithheld: m.filesWithheld });
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function noteNews(key, a) {
|
|
139
|
+
var prev = news.get(key);
|
|
140
|
+
if (prev && prev.epoch === a.epoch && prev.rev >= a.rev) return;
|
|
141
|
+
news.delete(key);
|
|
142
|
+
news.set(key, a);
|
|
143
|
+
if (news.size > NEWS_KEPT) news.delete(news.keys().next().value);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** The ordering gate. Returns true when `a` was applied. */
|
|
147
|
+
function apply(v, a, fromNewsItem) {
|
|
148
|
+
if (v.sticky) return false;
|
|
149
|
+
var h = v.held;
|
|
150
|
+
if (h.epoch !== null && a.epoch !== h.epoch) {
|
|
151
|
+
// FloLess restarted (or an answer from another process): what was held no longer orders anything, and every
|
|
152
|
+
// lookup still out was asked of the old process.
|
|
153
|
+
h.epoch = null; h.rev = 0; h.answer = null;
|
|
154
|
+
if (fromNewsItem) startLookup(v); // a new lookup supersedes (and so invalidates) every one still out
|
|
155
|
+
}
|
|
156
|
+
if (h.epoch === null) h.epoch = a.epoch;
|
|
157
|
+
var before = h.answer;
|
|
158
|
+
if (a.rev < h.rev) return false;
|
|
159
|
+
if (before && a.rev === h.rev && a.state !== before.state) return false;
|
|
160
|
+
var sameRev = !!before && a.rev === h.rev;
|
|
161
|
+
h.rev = a.rev;
|
|
162
|
+
// An answer of the same state at the same rev only ever adds (a lookup brings the frame address the news lacks).
|
|
163
|
+
h.answer = sameRev
|
|
164
|
+
? { state: a.state, rev: a.rev, epoch: a.epoch, version: a.version != null ? a.version : before.version,
|
|
165
|
+
files: a.files != null ? a.files : before.files, filesWithheld: a.filesWithheld || before.filesWithheld,
|
|
166
|
+
reason: a.reason || before.reason, frameUrl: a.frameUrl || before.frameUrl }
|
|
167
|
+
: a;
|
|
168
|
+
render(v);
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function pendingNote(v) { return now() - v.startedAt >= STILL_SAVING_MS ? NOTES.still : NOTES.pending; }
|
|
173
|
+
|
|
174
|
+
function render(v) {
|
|
175
|
+
if (v.sticky || v.shown) return;
|
|
176
|
+
var a = v.held.answer;
|
|
177
|
+
if (!a || a.state === 'pending') { setNote(pendingNote(v)); ensurePoll(v); return; }
|
|
178
|
+
if (a.state === 'none') {
|
|
179
|
+
if (now() - v.startedAt < NONE_PROVISIONAL_MS) { setNote(pendingNote(v)); ensurePoll(v); return; }
|
|
180
|
+
setNote(NOTES.none); stopPoll(v); return;
|
|
181
|
+
}
|
|
182
|
+
if (a.state === 'failed') {
|
|
183
|
+
setNote(a.reason ? sentence(a.reason) + ' ' + FAILED_TAIL : 'This report could not be saved to the workflow’s Page. ' + FAILED_TAIL);
|
|
184
|
+
stopPoll(v); return;
|
|
185
|
+
}
|
|
186
|
+
// saved
|
|
187
|
+
if (a.files > 0) {
|
|
188
|
+
// It IS saved (never "saving"). One 20 s deadline covers finding its frame's address AND the frame saying it is
|
|
189
|
+
// ready, however many answers or redraws come in between; past it the viewer says so and points to Pages.
|
|
190
|
+
setNote(NOTES.opening);
|
|
191
|
+
startOpeningDeadline(v);
|
|
192
|
+
if (a.frameUrl) { stopPoll(v); showVersion(v, a); return; }
|
|
193
|
+
// Asked once straight away (a lookup already out may predate the save, and a new one supersedes it); after that the
|
|
194
|
+
// poll keeps asking, so repeated news or redraws never add lookups.
|
|
195
|
+
if (!v.addressAsked) { v.addressAsked = true; startLookup(v); }
|
|
196
|
+
ensurePoll(v);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
stopPoll(v);
|
|
200
|
+
// What happened, why, and what to do next (#2476 review: the reason alone left the person without a way forward).
|
|
201
|
+
setNote((a.filesWithheld
|
|
202
|
+
? 'Saved to the workflow’s Page without its pictures and files: ' + a.filesWithheld.replace(/[.\s]+$/, '') + '.'
|
|
203
|
+
: 'Saved to the workflow’s Page without its pictures and files.') + ' ' + WITHHELD_NEXT);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function stopPoll(v) { if (v.pollTimer != null) { clearTimer(v.pollTimer); v.pollTimer = null; } }
|
|
207
|
+
|
|
208
|
+
function ensurePoll(v) {
|
|
209
|
+
if (v.pollTimer != null || v.sticky || v.shown) return;
|
|
210
|
+
var g = v.gen;
|
|
211
|
+
v.pollTimer = setTimer(function () {
|
|
212
|
+
v.pollTimer = null;
|
|
213
|
+
if (stale(v, g)) return;
|
|
214
|
+
startLookup(v);
|
|
215
|
+
}, POLL_MS);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// ── asking the server ──────────────────────────────────────────────────────────────────────────────────
|
|
219
|
+
|
|
220
|
+
function startLookup(v) {
|
|
221
|
+
var g = v.gen;
|
|
222
|
+
var seq = (v.lookupSeq += 1);
|
|
223
|
+
v.lookupBusy = true;
|
|
224
|
+
var url = '/api/pages/workflow?app=' + encodeURIComponent(v.app) + '&run=' + encodeURIComponent(v.runId)
|
|
225
|
+
+ (v.fire ? '&fire=' + encodeURIComponent(v.fire) : '');
|
|
226
|
+
var asking;
|
|
227
|
+
try { asking = Promise.resolve(env.api(url, { timeoutMs: LOOKUP_TIMEOUT_MS })); } catch (e) { asking = Promise.reject(e); }
|
|
228
|
+
asking.then(function (body) {
|
|
229
|
+
if (stale(v, g) || v.lookupSeq !== seq) return;
|
|
230
|
+
v.lookupBusy = false;
|
|
231
|
+
var a = normalise(body && body.run);
|
|
232
|
+
if (!a) { if (!v.held.answer || v.held.answer.state !== 'saved') ensurePoll(v); return; }
|
|
233
|
+
if (a.state === 'saved' && a.version != null && body && typeof body.home === 'string' && body.page && typeof body.page.id === 'string') {
|
|
234
|
+
try { env.onSaved({ app: v.app, runId: v.runId, fire: v.fire, home: body.home, pageId: body.page.id, version: a.version }); }
|
|
235
|
+
catch (e) { /* the header link is a convenience; the frame below does not depend on it */ }
|
|
236
|
+
}
|
|
237
|
+
apply(v, a, false);
|
|
238
|
+
}).catch(function () {
|
|
239
|
+
if (stale(v, g)) return;
|
|
240
|
+
if (v.lookupSeq === seq) v.lookupBusy = false;
|
|
241
|
+
// The question could not be answered (offline, slow): keep what is shown and ask again while it matters.
|
|
242
|
+
var a = v.held.answer;
|
|
243
|
+
if (!a || a.state === 'pending' || a.state === 'none' || (a.state === 'saved' && a.files > 0 && !a.frameUrl)) ensurePoll(v);
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// ── the Page version's frame ───────────────────────────────────────────────────────────────────────────
|
|
248
|
+
|
|
249
|
+
/** Started once, when the version is known saved with files; never restarted by later answers or the frame's load. */
|
|
250
|
+
function startOpeningDeadline(v) {
|
|
251
|
+
if (v.readyTimer != null) return;
|
|
252
|
+
var g = v.gen;
|
|
253
|
+
v.readyTimer = setTimer(function () {
|
|
254
|
+
v.readyTimer = null;
|
|
255
|
+
// Only while it is still "saved with files, not yet shown": a newer answer (failed, saved without files) keeps its own note.
|
|
256
|
+
var a = v.held.answer;
|
|
257
|
+
if (!stale(v, g) && !v.shown && a && a.state === 'saved' && a.files > 0) fallback(v);
|
|
258
|
+
}, READY_WAIT_MS);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function showVersion(v, a) {
|
|
262
|
+
if (v.navUrl === a.frameUrl) return;
|
|
263
|
+
v.navUrl = a.frameUrl;
|
|
264
|
+
var nav = token();
|
|
265
|
+
v.nav = { token: nav };
|
|
266
|
+
startOpeningDeadline(v);
|
|
267
|
+
page.hidden = true;
|
|
268
|
+
page.setAttribute('src', a.frameUrl + '?nav=' + nav);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function fallback(v) {
|
|
272
|
+
if (v.readyTimer != null) { clearTimer(v.readyTimer); v.readyTimer = null; }
|
|
273
|
+
v.sticky = true;
|
|
274
|
+
v.shown = false;
|
|
275
|
+
v.nav = null;
|
|
276
|
+
stopPoll(v);
|
|
277
|
+
blankPageFrame();
|
|
278
|
+
if (inert) inert.hidden = false;
|
|
279
|
+
setNote(NOTES.frame);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function becameReady(v) {
|
|
283
|
+
if (v.readyTimer != null) { clearTimer(v.readyTimer); v.readyTimer = null; }
|
|
284
|
+
v.shown = true;
|
|
285
|
+
stopPoll(v);
|
|
286
|
+
if (v.stillTimer != null) { clearTimer(v.stillTimer); v.stillTimer = null; }
|
|
287
|
+
page.hidden = false;
|
|
288
|
+
if (inert) inert.hidden = true;
|
|
289
|
+
setNote('');
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function onMessage(event) {
|
|
293
|
+
var v = view;
|
|
294
|
+
if (!v || !page || event.source !== page.contentWindow || !event.source) return;
|
|
295
|
+
var d = event.data;
|
|
296
|
+
if (!d || typeof d.type !== 'string') return;
|
|
297
|
+
if (d.type === 'floless-page-ready' || d.type === 'floless-page-unavailable') {
|
|
298
|
+
// Only the CURRENT navigation of the CURRENT paint: a message queued by an earlier document carries its token.
|
|
299
|
+
if (!v.nav || d.nav !== v.nav.token || stale(v, v.gen)) return;
|
|
300
|
+
if (d.type === 'floless-page-ready') becameReady(v); else fallback(v);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
if (PAGE_REQUESTS.indexOf(d.type) >= 0 && v.shown && !v.linksNoted) {
|
|
304
|
+
// A link ask or a blocked site needs the Pages screen's consent step; this view does not host it.
|
|
305
|
+
v.linksNoted = true;
|
|
306
|
+
setNote(NOTES.links);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
win.addEventListener('message', onMessage);
|
|
310
|
+
|
|
311
|
+
// ── the entry points aware.js calls ────────────────────────────────────────────────────────────────────
|
|
312
|
+
|
|
313
|
+
/** Show a report that carries files. `entry`: { runId, captureKey?, fireKey? } of the report on screen. */
|
|
314
|
+
function paint(entry) {
|
|
315
|
+
invalidate();
|
|
316
|
+
var app = env.currentApp();
|
|
317
|
+
var runId = entry && typeof entry.runId === 'string' && entry.runId ? entry.runId : null;
|
|
318
|
+
var fire = entry && typeof entry.fireKey === 'string' && entry.fireKey ? entry.fireKey : null;
|
|
319
|
+
if (!fire && entry && typeof entry.captureKey === 'string' && entry.captureKey.indexOf('#') > 0) {
|
|
320
|
+
fire = entry.captureKey.slice(entry.captureKey.indexOf('#') + 1) || null;
|
|
321
|
+
runId = runId || entry.captureKey.slice(0, entry.captureKey.indexOf('#'));
|
|
322
|
+
}
|
|
323
|
+
if (inert) inert.hidden = false;
|
|
324
|
+
if (!app || !runId) { setNote(NOTES.none); return; }
|
|
325
|
+
var v = view = {
|
|
326
|
+
gen: gen, app: app, runId: runId, fire: fire, nk: nkey(app, runId, fire), startedAt: now(),
|
|
327
|
+
held: { epoch: null, rev: 0, answer: null }, lookupSeq: 0, lookupBusy: false, addressAsked: false,
|
|
328
|
+
pollTimer: null, stillTimer: null, readyTimer: null, nav: null, navUrl: '', sticky: false, shown: false, linksNoted: false,
|
|
329
|
+
};
|
|
330
|
+
var g = v.gen;
|
|
331
|
+
// The "still saving" wording takes over by itself, with no news needed.
|
|
332
|
+
v.stillTimer = setTimer(function () { v.stillTimer = null; if (!stale(v, g)) render(v); }, STILL_SAVING_MS);
|
|
333
|
+
var heard = news.get(v.nk);
|
|
334
|
+
if (heard) apply(v, heard, false); else render(v);
|
|
335
|
+
if (!v.lookupBusy) startLookup(v);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** `workflow-page-captured` news from the server. */
|
|
339
|
+
function onNews(m) {
|
|
340
|
+
var a = fromNews(m);
|
|
341
|
+
if (!a) return;
|
|
342
|
+
var key = nkey(m.app, m.runId, typeof m.fireKey === 'string' ? m.fireKey : '');
|
|
343
|
+
noteNews(key, a);
|
|
344
|
+
if (view && view.nk === key && env.currentApp() === view.app && view.gen === gen) apply(view, a, true);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return { paint: paint, invalidate: invalidate, reset: reset, onNews: onNews,
|
|
348
|
+
/** For tests and diagnostics: what the view holds. */
|
|
349
|
+
inspect: function () { return view && { gen: view.gen, state: view.held.answer && view.held.answer.state, epoch: view.held.epoch, rev: view.held.rev, shown: view.shown, sticky: view.sticky, lookupSeq: view.lookupSeq }; } };
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
root.FlolessRunPageView = { create: create, NOTES: NOTES, READY_WAIT_MS: READY_WAIT_MS, POLL_MS: POLL_MS, STILL_SAVING_MS: STILL_SAVING_MS, NONE_PROVISIONAL_MS: NONE_PROVISIONAL_MS };
|
|
353
|
+
})(typeof window !== 'undefined' ? window : globalThis);
|