@floless/app 0.149.1 → 0.151.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 +104263 -88361
- package/dist/schemas/drawing-check.profile.v1.schema.json +45 -2
- package/dist/schemas/steel.model.v2.schema.json +9 -0
- package/dist/skills/floless-app-approval/SKILL.md +79 -4
- package/dist/skills/floless-app-onboarding/SKILL.md +200 -87
- package/dist/skills/floless-app-onboarding/references/aware-runtime.md +27 -18
- package/dist/skills/floless-app-onboarding/references/floless-surfaces.md +207 -0
- package/dist/skills/floless-app-routines/SKILL.md +4 -1
- package/dist/skills/floless-app-routines/references/routines-api.md +14 -2
- package/dist/skills/floless-app-steel-model/SKILL.md +4 -2
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +14 -9
- package/dist/skills/floless-app-workflows/SKILL.md +2 -2
- package/dist/templates/tekla-parser.flo +13 -3
- package/dist/web/agents.js +983 -0
- package/dist/web/app.css +556 -43
- package/dist/web/app.js +34 -112
- package/dist/web/aware.js +1774 -169
- package/dist/web/chat.css +62 -1
- package/dist/web/chat.js +1666 -59
- package/dist/web/commands-drawing-check.js +15 -0
- package/dist/web/commands-revit.js +5 -0
- package/dist/web/commands-shell.js +955 -53
- package/dist/web/commands-tekla-parser.js +8 -1
- package/dist/web/connections.js +57 -14
- package/dist/web/drawing-check-editor.html +10 -2
- package/dist/web/drawing-check-editor.js +569 -40
- package/dist/web/drawing-check-overlay.js +45 -2
- package/dist/web/guide.js +675 -0
- package/dist/web/index.html +162 -31
- package/dist/web/instructor.js +91 -8
- package/dist/web/leave-guard.js +1 -0
- package/dist/web/left-pane.js +20 -1
- package/dist/web/local-discovery.js +12 -2
- package/dist/web/model-editor.css +32 -32
- package/dist/web/model-panel-bridge.js +11 -3
- package/dist/web/model-viewport-lighting.js +4 -2
- package/dist/web/model-viewport-revit-adapter.js +3 -0
- package/dist/web/model-viewport-toolbar.js +6 -3
- package/dist/web/model-viewport.js +11 -1
- package/dist/web/revit-editor.css +14 -14
- package/dist/web/revit-editor.js +64 -12
- package/dist/web/steel-3d-core.js +133 -0
- package/dist/web/steel-3d-view.js +10 -0
- package/dist/web/steel-editor.html +171 -39
- package/dist/web/steel-model-v2-client-validation.js +11 -0
- package/dist/web/steel-model-v2-commands.js +80 -5
- package/dist/web/tool-updates.js +533 -0
- package/dist/web/workspaces.js +896 -123
- package/package.json +2 -2
- package/dist/skills/floless-app-onboarding/references/floless-app-tour.md +0 -156
package/dist/web/aware.js
CHANGED
|
@@ -68,6 +68,8 @@
|
|
|
68
68
|
// so reading `apps.get(id).ownedWorkflow` found nothing and a workflow's AI Chat scope and Units never resolved.
|
|
69
69
|
const workflowOwners = new Map();
|
|
70
70
|
function ownedWorkflowOf(id) { return (id && workflowOwners.get(id)) || null; }
|
|
71
|
+
/** What a workflow is called on screen: an owned workflow's own name, never its runtime app id (#1890 PR 3b-0). */
|
|
72
|
+
function workflowLabelOf(id) { return ownedWorkflowOf(id)?.ownedWorkflow?.displayName || id; }
|
|
71
73
|
function rememberWorkflowOwners(list) {
|
|
72
74
|
workflowOwners.clear();
|
|
73
75
|
for (const row of list) {
|
|
@@ -143,7 +145,7 @@
|
|
|
143
145
|
// ever changes and the pattern misses, we just fall back to the raw note.
|
|
144
146
|
function humanizeNote(text) {
|
|
145
147
|
const missing = missingAgentId(text);
|
|
146
|
-
if (missing) return `${agentDisplayName(missing)} is not installed. Install this
|
|
148
|
+
if (missing) return `${agentDisplayName(missing)} is not installed. Install this tool to use this step.`;
|
|
147
149
|
const m = /command\s+(\S+)\s+(?:not found|is mode-overridable);\s*using author-declared mode:\s*(read|write)/i.exec(text);
|
|
148
150
|
if (m) {
|
|
149
151
|
const cmd = m[1];
|
|
@@ -166,6 +168,19 @@
|
|
|
166
168
|
if (/executable lock does not match the trusted compiled lock/i.test(message)) {
|
|
167
169
|
return 'FloLess stopped this run because the workflow no longer matches the version that was approved. Ask your AI assistant to restore and approve the workflow, then try again.';
|
|
168
170
|
}
|
|
171
|
+
// #1996: FloLess's own run admission for a published workflow whose installed files changed (for example an
|
|
172
|
+
// approval carried forward outside FloLess). The server's words are internal; say what happened and what to do.
|
|
173
|
+
if (/active workflow publication is missing or changed/i.test(message)) {
|
|
174
|
+
return 'This workflow no longer matches the version FloLess published, so it did not run. Ask AI Chat to publish it again, then run it.';
|
|
175
|
+
}
|
|
176
|
+
// #1912: the adapter's own words for a run AWARE ended without a reason FloLess recognises.
|
|
177
|
+
// Never show them bare — say what is known and how to get help.
|
|
178
|
+
if (/^AWARE workflow run (?:failed|did not finish)$/i.test(String(message).trim())) {
|
|
179
|
+
// Same sentence as the server's plainRunFailureMessage (run-refusal.ts) — this is the backstop
|
|
180
|
+
// for a server that still sends the adapter's words.
|
|
181
|
+
return 'The workflow stopped before it finished, and FloLess cannot explain the reason in plain words yet. '
|
|
182
|
+
+ 'Run it again, and if it stops again, report this problem so we can look into it.';
|
|
183
|
+
}
|
|
169
184
|
return message;
|
|
170
185
|
}
|
|
171
186
|
|
|
@@ -220,15 +235,15 @@
|
|
|
220
235
|
const busyLabel = installed.has(id) ? 'Checking' : 'Installing';
|
|
221
236
|
const busyDetail = installed.has(id) ? 'Checking the installed version. Please wait.' : 'Installation is in progress. Please wait.';
|
|
222
237
|
return `<li class="missing-agent-row"><div><strong>${escapeHtml(agentDisplayName(id))}</strong>` +
|
|
223
|
-
`<div class="missing-agent-detail">${busy ? busyDetail : failure ? 'Installation needs attention.' : done ? 'Installed. Compile the workflow to refresh its checks.' : check ? 'Installed on this computer. Check that its version matches this workflow.' : 'Install this
|
|
238
|
+
`<div class="missing-agent-detail">${busy ? busyDetail : failure ? 'Installation needs attention.' : done ? 'Installed. Compile the workflow to refresh its checks.' : check ? 'Installed on this computer. Check that its version matches this workflow.' : 'Install this tool to use these steps.'} Used by: ${escapeHtml([...nodes].join(', '))}.</div>` +
|
|
224
239
|
(failure ? `<div class="missing-agent-error" role="status">Could not install: ${escapeHtml(failure)}</div>` : '') +
|
|
225
|
-
`</div><button class="btn small" type="button" data-note-install="${escapeAttr(id)}" data-command-id="shell.workflow-agent-install#${escapeAttr(id)}" data-command-instance-label="${escapeAttr(agentDisplayName(id))}" aria-label="${check ? `Check ${escapeAttr(agentDisplayName(id))} installation` : `${busy ? busyLabel : done ? 'Installed' : failure ? 'Try installing again:' : 'Install'} ${escapeAttr(agentDisplayName(id))}`}" ${busy || done ? `disabled data-blocked-reason="${busy ? busyDetail : 'This
|
|
240
|
+
`</div><button class="btn small" type="button" data-note-install="${escapeAttr(id)}" data-command-id="shell.workflow-agent-install#${escapeAttr(id)}" data-command-instance-label="${escapeAttr(agentDisplayName(id))}" aria-label="${check ? `Check ${escapeAttr(agentDisplayName(id))} installation` : `${busy ? busyLabel : done ? 'Installed' : failure ? 'Try installing again:' : 'Install'} ${escapeAttr(agentDisplayName(id))}`}" ${busy || done ? `disabled data-blocked-reason="${busy ? busyDetail : 'This tool is installed. Compile the workflow to refresh its checks.'}"` : ''} aria-busy="${busy}">${busy ? `<span class="rtn-spinner"></span> ${busyLabel}…` : done ? 'Installed' : failure ? 'Try again' : check ? 'Check installation' : 'Install'}</button></li>`;
|
|
226
241
|
}).join('');
|
|
227
242
|
}
|
|
228
243
|
|
|
229
244
|
function missingAgentsBulkButton(pending, canInstall) {
|
|
230
245
|
if (pending.length <= 1) return '';
|
|
231
|
-
return `<button class="btn small" type="button" data-note-install-all data-command-id="shell.workflow-agents-install-all" aria-label="Install all missing
|
|
246
|
+
return `<button class="btn small" type="button" data-note-install-all data-command-id="shell.workflow-agents-install-all" aria-label="Install all missing tools" aria-busy="${!canInstall.length}" ${canInstall.length ? '' : 'disabled data-blocked-reason="Tool installations are in progress. Please wait."'}>${canInstall.length ? `Install all (${canInstall.length})` : 'Installing…'}</button>`;
|
|
232
247
|
}
|
|
233
248
|
|
|
234
249
|
const AGENT_ICONS = {
|
|
@@ -416,7 +431,7 @@
|
|
|
416
431
|
const capBadges = sk.capabilities.map((c) => `<span class="cap-badge">${escapeHtml(c)}</span>`).join(' ');
|
|
417
432
|
const inputsObj = Object.fromEntries(sk.inputs.map((i) => [i.name, inputSummary(i)]));
|
|
418
433
|
const docs = sk.homepage && /^https?:\/\//i.test(sk.homepage)
|
|
419
|
-
? `<p class="skill-docs-row"><a class="skill-docs" href="${escapeHtml(sk.homepage)}" target="_blank" rel="noopener">
|
|
434
|
+
? `<p class="skill-docs-row"><a class="skill-docs" href="${escapeHtml(sk.homepage)}" target="_blank" rel="noopener">Tool documentation ↗</a></p>`
|
|
420
435
|
: '';
|
|
421
436
|
const outputs = sk.outputs
|
|
422
437
|
? `<p><strong>Returns</strong> · ${escapeHtml(sk.outputs.type)}</p>${Object.keys(sk.outputs.schema).length ? kvTable(sk.outputs.schema) : ''}`
|
|
@@ -534,7 +549,7 @@
|
|
|
534
549
|
_frozen: !!n.frozen, // source node carries a `frozen:` block → card badge + Unfreeze menu
|
|
535
550
|
icon: iconFor(n.agent),
|
|
536
551
|
iconTip: iconTipFor(n.agent),
|
|
537
|
-
kind: n.kind === 'agent' && n.agent ? `${agentLabel}
|
|
552
|
+
kind: n.kind === 'agent' && n.agent ? `${agentLabel} tool` : escapeHtml(n.kind),
|
|
538
553
|
version: pin ? `v${escapeHtml(String(pin))}` : '—',
|
|
539
554
|
title: escapeHtml(n.id),
|
|
540
555
|
subtitle: `${agentLabel}${cmd ? '/' + cmd : ''} · ${mode}`,
|
|
@@ -591,7 +606,13 @@
|
|
|
591
606
|
];
|
|
592
607
|
if (app.notes.length) narration.push(`ℹ ${app.notes.length} workflow notice${app.notes.length === 1 ? '' : 's'} — review them above the canvas.`);
|
|
593
608
|
const maintainedDrift = app.publisher === 'floless' && !app.forked && app.runState === 'drift';
|
|
594
|
-
narration.push(app
|
|
609
|
+
narration.push(gateStateFor(app) === 'agent-changed'
|
|
610
|
+
? (app.approvalCheck && app.approvalCheck.remedy === 'needs-you'
|
|
611
|
+
? 'A tool version this workflow was approved with is not available. Choose in the notice above the canvas: reinstall that version, or **Compile** again.'
|
|
612
|
+
: Array.isArray(app.agentPinChanges) && app.agentPinChanges.length
|
|
613
|
+
? `A tool this workflow uses has changed since it was approved (${app.agentPinChanges.map((c) => escapeHtml(c.agentDisplayName)).join(', ')}). Click **Compile** before running it.`
|
|
614
|
+
: 'This workflow needs to be compiled again before it can run. Click **Compile**, then run it.')
|
|
615
|
+
: app.runnable
|
|
595
616
|
? 'The workflow matches its approved version. Review any notices before running.'
|
|
596
617
|
: maintainedDrift
|
|
597
618
|
? 'The workflow logic changed since it was last approved. **Restore** the official version, or **Customize** it to make it your own.'
|
|
@@ -615,6 +636,18 @@
|
|
|
615
636
|
function runStatePresentation(runState, activity = {}) {
|
|
616
637
|
const gate = {
|
|
617
638
|
ready: { label: 'Ready to run', className: 'ready' },
|
|
639
|
+
// #1912: the lock still matches the .flo, but it approved a different version of a tool than
|
|
640
|
+
// the one installed now — AWARE will refuse the run until it is compiled again.
|
|
641
|
+
'agent-changed': { label: 'Needs compile', className: 'drift' },
|
|
642
|
+
// #1996: ready, but part of the approval record is missing — it still runs; the attention colour
|
|
643
|
+
// asks the person to look. Presentation only: the gate itself (and the Instructor's runState) is 'ready'.
|
|
644
|
+
'ready-check-record': { label: 'Ready to run · check record', className: 'drift' },
|
|
645
|
+
// #1996: a published FloLess workflow whose approval changed outside FloLess. Compile is refused for a
|
|
646
|
+
// publication, so the pill names the step that works. Presentation only: the gate is 'agent-changed'.
|
|
647
|
+
'needs-publish': { label: 'Needs publishing', className: 'drift' },
|
|
648
|
+
// #1998: the exact tool version this workflow was approved with cannot run; the person chooses (reinstall
|
|
649
|
+
// it, or Compile again). Presentation only: the gate is 'agent-changed'.
|
|
650
|
+
'needs-you': { label: 'Needs you', className: 'drift' },
|
|
618
651
|
drift: { label: 'Needs refresh', className: 'drift' },
|
|
619
652
|
uncompiled: { label: 'Not set up', className: 'uncompiled' },
|
|
620
653
|
};
|
|
@@ -632,6 +665,443 @@
|
|
|
632
665
|
return gate[runState] || { label: '', className: '' };
|
|
633
666
|
}
|
|
634
667
|
|
|
668
|
+
// The gate the person sees. `runState` is the .flo↔.lock comparison and stays exactly that; a lock
|
|
669
|
+
// that still matches its source but pinned a tool version that is no longer installed (#1912) is
|
|
670
|
+
// shown as its own state, because AWARE will refuse that run until it is compiled again. Run stays
|
|
671
|
+
// enabled — AWARE's own gate refuses, and the failure card then says why.
|
|
672
|
+
//
|
|
673
|
+
// #1987: on AWARE >= 0.149 the server adds `approvalCheck` — AWARE's own answer to "would the run
|
|
674
|
+
// accept this approval?" (`aware app check`). It replaces the version comparison: an approved
|
|
675
|
+
// workflow keeps running on the tool files it was approved with after a tool update, so a newer
|
|
676
|
+
// installed version alone is no reason to compile. Without it (older AWARE, or the check could not
|
|
677
|
+
// answer), the version comparison stands.
|
|
678
|
+
function gateStateFor(app) {
|
|
679
|
+
const changed = app.approvalCheck
|
|
680
|
+
? app.approvalCheck.current === false
|
|
681
|
+
: Array.isArray(app.agentPinChanges) && app.agentPinChanges.length > 0;
|
|
682
|
+
return app.runState === 'ready' && changed ? 'agent-changed' : app.runState;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
function approvalCheckTip(check) {
|
|
686
|
+
const reasons = Array.isArray(check.reasons) && check.reasons.length
|
|
687
|
+
? check.reasons
|
|
688
|
+
: ['Something this workflow was approved with has changed.'];
|
|
689
|
+
// #1996: a missing part of the approval record is worth knowing even when it is not why the run waits.
|
|
690
|
+
const lines = [...reasons, ...(Array.isArray(check.recordWarnings) ? check.recordWarnings : [])].join('\n');
|
|
691
|
+
// #1996: the server names the remedy when it is not simply Compile; the words for it live here.
|
|
692
|
+
if (check.remedy === 'publish') {
|
|
693
|
+
// The server's reason already says FloLess will not run it as it is; no second line saying the same.
|
|
694
|
+
return `Needs publishing.\n${lines}\nAsk AI Chat to publish this workflow again, then Run workflow.`;
|
|
695
|
+
}
|
|
696
|
+
if (check.remedy === 'unconfirmed') {
|
|
697
|
+
return `Needs compile.\nFloLess could not confirm this workflow's approval just now.\n${lines}\nReopen the workflow to ask again, or press Compile to approve it again, then Run workflow.`;
|
|
698
|
+
}
|
|
699
|
+
if (check.remedy === 'needs-you') {
|
|
700
|
+
return `Needs you.\nA tool version this workflow was approved with is not available, and FloLess will not move the workflow to another version on its own.\n${lines}\nChoose in the notice above the canvas: reinstall that version, or Compile again.`;
|
|
701
|
+
}
|
|
702
|
+
if (check.remedy === 'update-aware') {
|
|
703
|
+
return `Needs compile.\nThis workflow will not run with the AWARE installed here.\n${lines}\nUpdate AWARE, or press Compile to approve the workflow again, then Run workflow.`;
|
|
704
|
+
}
|
|
705
|
+
return `Needs compile.\nThis workflow will not run yet, because something it was approved with has changed.\n${lines}\nPress Compile, then Run workflow.`;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// #1996: what the pill shows for a gate state. The gate itself (and the Instructor's runState) is unchanged;
|
|
709
|
+
// only the label can say more.
|
|
710
|
+
function presentedGateState(app, gateState) {
|
|
711
|
+
if (gateState === 'agent-changed' && app.approvalCheck && app.approvalCheck.remedy === 'publish') return 'needs-publish';
|
|
712
|
+
if (gateState === 'agent-changed' && app.approvalCheck && app.approvalCheck.remedy === 'needs-you') return 'needs-you';
|
|
713
|
+
if (gateState === 'ready' && app.approvalCheck && app.approvalCheck.bridgeWarnings && app.approvalCheck.bridgeWarnings.length) return 'needs-you';
|
|
714
|
+
return recordNeedsCheck(app, gateState) ? 'ready-check-record' : gateState;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
// #1996: the gate is ready, but part of an approval record (this workflow's, or one behind a tool) is
|
|
718
|
+
// missing. AWARE still runs it; the pill asks the person to look.
|
|
719
|
+
function recordNeedsCheck(app, gateState) {
|
|
720
|
+
return gateState === 'ready' && !!app.approvalCheck && app.approvalCheck.record === 'incomplete';
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
// #1996: the Ready tooltip for an approval AWARE moved to newer tool versions without a new Compile,
|
|
724
|
+
// and for any approval whose record is incomplete. AWARE's own label goes last, verbatim, so a long
|
|
725
|
+
// one never pushes the next step out of view. Returns null for a plain original approval.
|
|
726
|
+
function approvalRecordTip(check) {
|
|
727
|
+
if (!check) return null;
|
|
728
|
+
const carried = check.origin === 'successor';
|
|
729
|
+
const warnings = Array.isArray(check.recordWarnings) ? check.recordWarnings : [];
|
|
730
|
+
if (!carried && warnings.length === 0) return null;
|
|
731
|
+
const lines = ['Ready to run.'];
|
|
732
|
+
if (carried) lines.push('This workflow was approved with older tool versions. That approval has been moved to the versions it runs with now, so you do not need to compile again.');
|
|
733
|
+
lines.push(...warnings);
|
|
734
|
+
// Each warning already ends with its own next step (Compile this workflow, or the one behind a tool).
|
|
735
|
+
if (!warnings.length) lines.push('Optional: press Compile to approve it yourself.');
|
|
736
|
+
if (carried && check.label) lines.push(`Recorded by AWARE: ${check.label}`);
|
|
737
|
+
return lines.join('\n');
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
function agentPinChangeTip(changes) {
|
|
741
|
+
const lines = changes.map((c) => (c.approved
|
|
742
|
+
? `${c.agentDisplayName}: approved with version ${c.approved}, version ${c.installed} is installed now.`
|
|
743
|
+
: `${c.agentDisplayName}: version ${c.installed} is installed, but this workflow was approved without it.`));
|
|
744
|
+
return `Needs compile.\nA tool this workflow uses has changed since it was approved, so it will not run yet.\n${lines.join('\n')}\nPress Compile, then Run workflow.`;
|
|
745
|
+
}
|
|
746
|
+
// ── #1998: approval strip — "Needs you" choices, and where a carried-over approval came from ───────────
|
|
747
|
+
//
|
|
748
|
+
// Two states, one element above the canvas (beside the compiler notes):
|
|
749
|
+
// • needs-you (warn): the exact tool version this workflow was approved with cannot run. One row per
|
|
750
|
+
// tool, with the person's two choices — reinstall that version, or Compile again. FloLess never moves
|
|
751
|
+
// the workflow to another version on its own, and Run stays a choice (AWARE refuses and says why).
|
|
752
|
+
// • carried over (neutral provenance, like "Informed by"): AWARE moved the approval to a newer tool
|
|
753
|
+
// version without a new Compile. The summary is FloLess's plain words; AWARE's own record is shown
|
|
754
|
+
// verbatim in the details, because that record is the label — never "unchanged behaviour".
|
|
755
|
+
const $approvalStrip = document.getElementById('approval-strip');
|
|
756
|
+
let approvalStripReinstalling = null; // `${appId}\u0000${agent}` while a reinstall is in flight
|
|
757
|
+
|
|
758
|
+
function approvalStripState(app) {
|
|
759
|
+
const check = app && app.approvalCheck;
|
|
760
|
+
if (!check) return null;
|
|
761
|
+
if (gateStateFor(app) === 'agent-changed' && check.remedy === 'needs-you') return 'needs-you';
|
|
762
|
+
if (check.current && check.origin === 'successor' && Array.isArray(check.successors) && check.successors.length) return 'carried';
|
|
763
|
+
if (Array.isArray(check.bridgeWarnings) && check.bridgeWarnings.length) return 'bridge-warning';
|
|
764
|
+
return null;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
function bridgeWarningRows(check) {
|
|
768
|
+
const warnings = Array.isArray(check.bridgeWarnings) ? check.bridgeWarnings : [];
|
|
769
|
+
if (!warnings.length) return '';
|
|
770
|
+
return '<div class="approval-head">⚠ Needs you · Bridge needs attention</div>'
|
|
771
|
+
+ '<ul class="approval-rows">' + warnings.map((w) => '<li class="approval-row"><div class="approval-row-text">'
|
|
772
|
+
+ `<div><strong>${escapeHtml(w.via ? `${w.via} → ${w.name}` : w.name)}</strong>: ${escapeHtml(w.detail)}</div>`
|
|
773
|
+
+ '<ol>' + w.choices.map((choice) => `<li>${escapeHtml(choice)}</li>`).join('') + '</ol>'
|
|
774
|
+
+ '<div class="approval-row-note">This bridge warning does not block Run workflow. The run record will note this warning.</div></div></li>').join('') + '</ul>';
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/** "Verbot 1.0.0 → 1.0.1" for every tool this link moved. */
|
|
778
|
+
function carriedMoves(link) {
|
|
779
|
+
return (Array.isArray(link.moved) ? link.moved : [])
|
|
780
|
+
.map((m) => `${m.name || m.agent} ${m.from || '?'} → ${m.to || '?'}`).join(', ');
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
/** Who allowed a link, in plain words. AWARE records this as a claim, so the details quote its record. */
|
|
784
|
+
function carriedBy(link) {
|
|
785
|
+
if (link.byKind === 'policy') return link.actor ? `carried over under a policy allowed by ${link.actor}` : 'carried over under a policy';
|
|
786
|
+
return link.actor ? `approved by ${link.actor}` : 'approved by a person';
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
function unavailableSentence(u) {
|
|
790
|
+
const tool = `${u.name} ${u.version || ''}`.trim();
|
|
791
|
+
if (u.removedBy === 'gc') return `${tool} is no longer stored on this computer. AWARE cleaned it up because it did not see this workflow using it. This workflow was approved with exactly that version.`;
|
|
792
|
+
if (u.resolution === 'digest-mismatch') return `${tool} was changed after this workflow was approved with it.`;
|
|
793
|
+
if (u.resolution === 'missing') return `${u.name} is not installed. This workflow was approved with version ${u.version}.`;
|
|
794
|
+
return `${tool} is not installed any more. This workflow was approved with that exact version.`;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
function paintApprovalStrip(app) {
|
|
798
|
+
if (!$approvalStrip) return;
|
|
799
|
+
const state = app && app.id === currentId ? approvalStripState(app) : null;
|
|
800
|
+
if (!state) {
|
|
801
|
+
$approvalStrip.hidden = true;
|
|
802
|
+
$approvalStrip.innerHTML = '';
|
|
803
|
+
delete $approvalStrip.dataset.state;
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
const check = app.approvalCheck;
|
|
807
|
+
$approvalStrip.hidden = false;
|
|
808
|
+
$approvalStrip.dataset.state = state;
|
|
809
|
+
$approvalStrip.dataset.appId = app.id;
|
|
810
|
+
const bridgeRows = bridgeWarningRows(check);
|
|
811
|
+
if (state === 'bridge-warning') {
|
|
812
|
+
$approvalStrip.className = 'approval-strip approval-needs-you';
|
|
813
|
+
$approvalStrip.setAttribute('role', 'note');
|
|
814
|
+
$approvalStrip.setAttribute('aria-label', 'Bridge needs attention; this warning does not block Run workflow');
|
|
815
|
+
$approvalStrip.innerHTML = bridgeRows;
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
if (state === 'needs-you') {
|
|
819
|
+
const rows = (check.unavailable || []).filter((u) => u.reinstall);
|
|
820
|
+
$approvalStrip.className = 'approval-strip approval-needs-you';
|
|
821
|
+
$approvalStrip.setAttribute('role', 'group');
|
|
822
|
+
$approvalStrip.setAttribute('aria-label', 'A tool version needs your decision');
|
|
823
|
+
$approvalStrip.innerHTML = bridgeRows + `<div class="approval-head">⚠ Needs you</div>`
|
|
824
|
+
+ `<ul class="approval-rows">${rows.map((u) => {
|
|
825
|
+
const busy = approvalStripReinstalling === `${app.id}\u0000${u.agent}`;
|
|
826
|
+
const installedNote = u.storeOnly
|
|
827
|
+
? `Reinstalling puts ${escapeHtml(u.name)} ${escapeHtml(u.version)} back so this workflow can run.${u.installed ? ` ${escapeHtml(u.name)} ${escapeHtml(u.installed)} stays installed.` : ''}`
|
|
828
|
+
: u.installed
|
|
829
|
+
? `Reinstalling makes ${escapeHtml(u.version)} the installed version again. Workflows approved with ${escapeHtml(u.installed)} keep running as they do now.`
|
|
830
|
+
: `Reinstalling installs ${escapeHtml(u.name)} ${escapeHtml(u.version)}.`;
|
|
831
|
+
return `<li class="approval-row" data-agent="${escapeAttr(u.agent)}">`
|
|
832
|
+
+ `<div class="approval-row-text"><div>${escapeHtml(unavailableSentence(u))} FloLess won’t switch it to another version for you.</div>`
|
|
833
|
+
+ `<div class="approval-row-note">${installedNote} Compiling again means you approve the workflow again, with the version installed at that moment.</div>`
|
|
834
|
+
+ `<div class="approval-row-error" role="status" aria-live="polite"></div></div>`
|
|
835
|
+
+ `<div class="approval-row-actions">`
|
|
836
|
+
+ `<button type="button" class="btn primary" data-approval-reinstall data-agent="${escapeAttr(u.agent)}" data-version="${escapeAttr(u.version)}"`
|
|
837
|
+
+ ` data-command-id="workflow.reinstall-approved-tool#${escapeAttr(u.agent)}" data-command-instance-label="${escapeAttr(`${u.name} ${u.version}`)}"`
|
|
838
|
+
+ ` data-tip="${escapeAttr(u.storeOnly ? `Put ${u.name} ${u.version} back, so this workflow runs with the version it was approved with. The installed version does not change` : `Install ${u.name} ${u.version} again, so this workflow runs with the version it was approved with`)}"`
|
|
839
|
+
+ `${busy ? ' disabled aria-busy="true"' : ''}>${busy ? 'Reinstalling…' : escapeHtml(`Reinstall ${u.name} ${u.version}`)}</button>`
|
|
840
|
+
+ `<button type="button" class="btn" data-approval-compile data-command-id="workflow.approval-compile-again"`
|
|
841
|
+
+ ` data-tip="Approve this workflow again with the tool versions installed when it compiles"${approvalStripReinstalling ? ' disabled' : ''}>Compile again</button>`
|
|
842
|
+
+ `</div></li>`;
|
|
843
|
+
}).join('')}</ul>`;
|
|
844
|
+
return;
|
|
845
|
+
}
|
|
846
|
+
// carried over: neutral, quiet; the details hold every link with AWARE's own words.
|
|
847
|
+
const links = check.successors;
|
|
848
|
+
const last = links[links.length - 1];
|
|
849
|
+
$approvalStrip.className = 'approval-strip approval-carried';
|
|
850
|
+
$approvalStrip.setAttribute('role', 'note');
|
|
851
|
+
$approvalStrip.setAttribute('aria-label', 'Where this workflow’s approval came from');
|
|
852
|
+
$approvalStrip.innerHTML = bridgeRows + `<details class="approval-details">`
|
|
853
|
+
+ `<summary data-command-id="workflow.approval-carried-details" data-tip="Show where this approval came from">`
|
|
854
|
+
+ `<span class="approval-carried-label">Approval carried over</span>`
|
|
855
|
+
+ `<span class="approval-carried-sep">·</span><span>${escapeHtml(carriedMoves(last))}</span>`
|
|
856
|
+
+ `<span class="approval-carried-sep">·</span><span>${escapeHtml(carriedBy(last))}</span></summary>`
|
|
857
|
+
+ `<div class="approval-carried-body">`
|
|
858
|
+
+ `<p>This workflow’s approval was moved to the tool version it runs with now, without compiling again. Each step is listed below with AWARE’s own record of who allowed it and what was checked. Compile again at any time to approve it yourself.</p>`
|
|
859
|
+
+ links.map((link) => `<div class="approval-link"><div class="approval-link-head">${escapeHtml(carriedMoves(link))}`
|
|
860
|
+
+ `${link.promotedAt ? ` · ${escapeHtml(absTimeOf(link.promotedAt))}` : ''}`
|
|
861
|
+
+ `${link.kind === 'reverted' ? ' · moved back to an earlier approved version' : ''}</div>`
|
|
862
|
+
+ `<div class="approval-link-label-head">AWARE’s record (exact words)</div>`
|
|
863
|
+
+ `<blockquote class="approval-link-label">${escapeHtml(link.label || check.label || '')}</blockquote></div>`).join('')
|
|
864
|
+
+ `</div></details>`;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
function absTimeOf(iso) {
|
|
868
|
+
const d = new Date(iso);
|
|
869
|
+
return isNaN(d.getTime()) ? '' : d.toLocaleString();
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/** The Execution log's run-start line: which approval the run ran under, when it was carried over. */
|
|
873
|
+
function runStartApprovalNote(ev) {
|
|
874
|
+
const cfg = (ev && (ev.config || ev.run_config)) || null;
|
|
875
|
+
const a = cfg && cfg.approval;
|
|
876
|
+
const rows = cfg && cfg['agent-resolution'];
|
|
877
|
+
const bridge = rows && typeof rows === 'object' ? Object.entries(rows).map(([agent, row]) => {
|
|
878
|
+
const w = row && row.bridge;
|
|
879
|
+
if (!w || !['bridge-too-old', 'bridge-too-new', 'declaration-invalid'].includes(w.status) || typeof w.detail !== 'string') return '';
|
|
880
|
+
const label = w.status === 'declaration-invalid' ? 'Ran with an invalid bridge declaration' : 'Ran with a bridge mismatch';
|
|
881
|
+
return ` · ${label}: ${escapeHtml(agent.replaceAll('>', ' → '))}. ${escapeHtml(w.detail)}`;
|
|
882
|
+
}).join('') : '';
|
|
883
|
+
if (!a || a.origin === 'original') return bridge;
|
|
884
|
+
if (a.origin !== 'successor') return ` · an approval FloLess does not recognise — AWARE’s record: ${escapeHtml(a.label || 'none')}${bridge}`;
|
|
885
|
+
return ` · approval carried over — AWARE’s record: ${escapeHtml(a.label || 'carried forward')}${bridge}`;
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
if ($approvalStrip) {
|
|
889
|
+
$approvalStrip.addEventListener('click', async (e) => {
|
|
890
|
+
const compile = e.target.closest && e.target.closest('[data-approval-compile]');
|
|
891
|
+
if (compile && !compile.disabled) { $compileBtn.click(); return; }
|
|
892
|
+
const btn = e.target.closest && e.target.closest('[data-approval-reinstall]');
|
|
893
|
+
if (!btn || btn.disabled || !currentId) return;
|
|
894
|
+
const id = currentId;
|
|
895
|
+
// The selection as it stands now: a workflow opened (or still loading) after this click must never be
|
|
896
|
+
// replaced by this one when the reinstall finishes.
|
|
897
|
+
const ticketAtClick = selectionTicket;
|
|
898
|
+
const stillHere = () => currentId === id && selectionTicket === ticketAtClick;
|
|
899
|
+
// Whatever is on screen when this finishes is repainted, so no strip is left showing "Reinstalling…"
|
|
900
|
+
// with its buttons disabled; only a RELOAD is held back for a workflow the person has left.
|
|
901
|
+
const repaintShown = () => { const shown = currentId && apps.get(currentId); if (shown) paintApprovalStrip(shown); };
|
|
902
|
+
const agent = btn.dataset.agent;
|
|
903
|
+
const version = btn.dataset.version;
|
|
904
|
+
approvalStripReinstalling = `${id}\u0000${agent}`;
|
|
905
|
+
const wasCompileDisabled = $compileBtn.disabled;
|
|
906
|
+
$compileBtn.disabled = true; // never approve whichever copy happens to be installed mid-swap
|
|
907
|
+
const app = apps.get(id);
|
|
908
|
+
if (app) paintApprovalStrip(app);
|
|
909
|
+
let res = null;
|
|
910
|
+
let error = null;
|
|
911
|
+
try {
|
|
912
|
+
res = await api(`/api/app/${encodeURIComponent(id)}/reinstall-approved-tool`, { method: 'POST', body: JSON.stringify({ agent, version }) });
|
|
913
|
+
} catch (err) {
|
|
914
|
+
error = err;
|
|
915
|
+
} finally {
|
|
916
|
+
approvalStripReinstalling = null;
|
|
917
|
+
$compileBtn.disabled = wasCompileDisabled;
|
|
918
|
+
}
|
|
919
|
+
if (error && error.body && error.body.app) {
|
|
920
|
+
// The state moved on; repaint from it (only if the person is still on this workflow).
|
|
921
|
+
if (stillHere()) await loadApp(id).catch(reportErr);
|
|
922
|
+
else repaintShown();
|
|
923
|
+
showToast(error.message, 'info');
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
if (error) {
|
|
927
|
+
repaintShown();
|
|
928
|
+
const row = stillHere() && $approvalStrip.querySelector(`.approval-row[data-agent="${CSS.escape(agent)}"] .approval-row-error`);
|
|
929
|
+
if (row) row.textContent = (error.body && error.body.code === 'reinstall-failed') ? `${error.message} You can try again, or Compile again.` : error.message;
|
|
930
|
+
else showToast(error.message, 'warn'); // the person moved on: the failure still reaches them
|
|
931
|
+
return;
|
|
932
|
+
}
|
|
933
|
+
if (stillHere()) await loadApp(id).catch(reportErr);
|
|
934
|
+
else repaintShown();
|
|
935
|
+
if (typeof loadAgentCatalog === 'function') {
|
|
936
|
+
loadAgentCatalog().catch((err) => console.warn('[floless] the Agents list could not be refreshed after a reinstall', err));
|
|
937
|
+
}
|
|
938
|
+
showToast(res.message, res.reinstalled === true ? 'ok' : 'warn');
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// ── #1998: the one-time carry-forward policy (first approval, and ≡ → Automatic tool updates…) ──────────────────
|
|
943
|
+
//
|
|
944
|
+
// The words come from the server, which hashes them; Allow sends that hash back, so what is recorded is
|
|
945
|
+
// exactly what was read. It is recorded from a person's click here; the server refuses a request without
|
|
946
|
+
// the browser's same-origin headers, an accident guard against a stray terminal request, not proof of a
|
|
947
|
+
// click (owner decision 1, #1985). "Not now" is remembered so the question is asked once.
|
|
948
|
+
const $policyModal = document.getElementById('policy-modal');
|
|
949
|
+
let policyView = null;
|
|
950
|
+
let policyMode = 'settings';
|
|
951
|
+
let policyReturnFocus = null;
|
|
952
|
+
|
|
953
|
+
function renderPolicyModal() {
|
|
954
|
+
const v = policyView;
|
|
955
|
+
const $body = document.getElementById('policy-body');
|
|
956
|
+
const $actions = document.getElementById('policy-actions');
|
|
957
|
+
const $title = document.getElementById('policy-title');
|
|
958
|
+
$title.textContent = policyMode === 'first' ? 'Let FloLess keep approved workflows up to date?' : 'Automatic tool updates';
|
|
959
|
+
if (!v) { $body.innerHTML = '<p class="policy-dim">Loading…</p>'; $actions.innerHTML = ''; return; }
|
|
960
|
+
if (v.loadError) {
|
|
961
|
+
// Never "off": a policy may well be active while FloLess cannot read it.
|
|
962
|
+
$body.innerHTML = `<p>FloLess could not read this setting just now, so it cannot say whether it is on: ${escapeHtml(v.loadError)}</p>`
|
|
963
|
+
+ '<p class="policy-dim">Try again in a moment.</p>';
|
|
964
|
+
$actions.innerHTML = '<button type="button" class="btn" data-policy-close data-command-id="shell.dialog-cancel#Automatic tool updates">Close</button>'
|
|
965
|
+
+ '<button type="button" class="btn primary" data-policy-retry data-command-id="shell.policy-retry">Try again</button>';
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
968
|
+
if (!v.supported) {
|
|
969
|
+
$body.innerHTML = `<p>${escapeHtml(v.message || 'This needs a newer AWARE.')}</p><p class="policy-dim">Until then, every tool update asks you first.</p>`;
|
|
970
|
+
$actions.innerHTML = '<button type="button" class="btn" data-policy-close data-command-id="shell.dialog-cancel#Automatic tool updates">Close</button>';
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
973
|
+
const lines = String(v.statement || '').split('\n');
|
|
974
|
+
const intro = lines.filter((l) => !l.startsWith('•'));
|
|
975
|
+
const bullets = lines.filter((l) => l.startsWith('•')).map((l) => l.replace(/^•\s*/, ''));
|
|
976
|
+
const statement = `<div class="policy-statement" id="policy-statement"><p>${escapeHtml(intro[0] || '')}</p>`
|
|
977
|
+
+ `<ul>${bullets.map((b) => `<li>${escapeHtml(b)}</li>`).join('')}</ul>`
|
|
978
|
+
+ `<p>${escapeHtml(intro.slice(1).join(' '))}</p></div>`;
|
|
979
|
+
const active = (v.policies || []).filter((p) => p.state === 'active');
|
|
980
|
+
let status = '';
|
|
981
|
+
if (policyMode === 'settings') {
|
|
982
|
+
const p = active[0];
|
|
983
|
+
status = `<div class="policy-status"><span class="policy-badge ${v.on ? 'on' : 'off'}">${v.on ? 'On' : 'Off'}</span>`
|
|
984
|
+
+ `<span>${v.on
|
|
985
|
+
? escapeHtml(`Allowed by ${p && p.approvedBy ? p.approvedBy : 'a person'}${p && p.approvedAt ? ` on ${absTimeOf(p.approvedAt)}` : ''}`)
|
|
986
|
+
: 'Every tool update asks you first.'}</span></div>`
|
|
987
|
+
+ (active.length ? `<details class="policy-record"><summary data-command-id="shell.policy-record">AWARE’s record (exact words)</summary>`
|
|
988
|
+
+ active.map((a) => `<blockquote class="approval-link-label">${escapeHtml(a.label || a.id)}</blockquote>`).join('') + '</details>' : '');
|
|
989
|
+
}
|
|
990
|
+
const advanced = policyMode === 'settings'
|
|
991
|
+
? '<details class="policy-advanced"><summary data-command-id="shell.policy-advanced">Advanced</summary>'
|
|
992
|
+
+ '<p>Bigger updates, and workflows that change your models, always ask you first. AWARE cannot carry those over on its own yet, so there is nothing to switch on here.</p></details>'
|
|
993
|
+
: '';
|
|
994
|
+
$body.innerHTML = status + statement + advanced + '<div class="policy-error" role="status" aria-live="polite"></div>';
|
|
995
|
+
if (policyMode === 'first') {
|
|
996
|
+
$actions.innerHTML = '<span class="policy-dim policy-later">You can decide later in ≡ → Automatic tool updates.</span>'
|
|
997
|
+
+ '<button type="button" class="btn" data-policy-notnow data-command-id="shell.policy-not-now">Not now</button>'
|
|
998
|
+
+ '<button type="button" class="btn primary" data-policy-allow data-command-id="shell.policy-allow">Allow</button>';
|
|
999
|
+
} else {
|
|
1000
|
+
$actions.innerHTML = '<button type="button" class="btn" data-policy-close data-command-id="shell.dialog-cancel#Automatic tool updates">Close</button>'
|
|
1001
|
+
+ (v.on
|
|
1002
|
+
? '<button type="button" class="btn" data-policy-off data-command-id="shell.policy-turn-off">Turn off</button>'
|
|
1003
|
+
: '<button type="button" class="btn primary" data-policy-allow data-command-id="shell.policy-allow">Turn on</button>');
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
async function openPolicyModal(mode) {
|
|
1008
|
+
if (!$policyModal) return;
|
|
1009
|
+
policyMode = mode;
|
|
1010
|
+
policyReturnFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
1011
|
+
policyView = null;
|
|
1012
|
+
renderPolicyModal();
|
|
1013
|
+
showModal($policyModal);
|
|
1014
|
+
try { policyView = await api('/api/migration-policy'); }
|
|
1015
|
+
catch (err) {
|
|
1016
|
+
policyView = { loadError: err.message };
|
|
1017
|
+
}
|
|
1018
|
+
renderPolicyModal();
|
|
1019
|
+
const first = $policyModal.querySelector('.modal-title');
|
|
1020
|
+
if (first) first.focus();
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
function closePolicyModal() {
|
|
1024
|
+
if (!$policyModal || !$policyModal.classList.contains('show')) return;
|
|
1025
|
+
hideModal($policyModal);
|
|
1026
|
+
if (policyReturnFocus && document.contains(policyReturnFocus)) policyReturnFocus.focus();
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
async function answerPolicyNotNow() {
|
|
1030
|
+
try { await api('/api/migration-policy/prompt', { method: 'POST', body: JSON.stringify({ decision: 'not-now' }) }); }
|
|
1031
|
+
catch (err) { console.warn('[floless] "Not now" could not be saved; the question comes back at the next approval', err); }
|
|
1032
|
+
closePolicyModal();
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
/** After a person's approval (Compile, Approve): ask once, if AWARE can record the answer. */
|
|
1036
|
+
async function maybeAskPolicyAfterApproval() {
|
|
1037
|
+
if (!$policyModal || $policyModal.classList.contains('show')) return;
|
|
1038
|
+
let v;
|
|
1039
|
+
try { v = await api('/api/migration-policy'); }
|
|
1040
|
+
catch (err) { console.warn('[floless] could not read the carry-forward setting after an approval', err); return; }
|
|
1041
|
+
if (!v || !v.supported || v.on || (v.prompt && v.prompt.answered)) return;
|
|
1042
|
+
// Let the "compiled" message land first; the question never covers it.
|
|
1043
|
+
setTimeout(() => { if (!$policyModal.classList.contains('show')) openPolicyModal('first'); }, 900);
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
if ($policyModal) {
|
|
1047
|
+
$policyModal.addEventListener('click', async (e) => {
|
|
1048
|
+
const t = e.target.closest ? e.target.closest('button') : null;
|
|
1049
|
+
if (!t || t.disabled) return;
|
|
1050
|
+
const $err = $policyModal.querySelector('.policy-error');
|
|
1051
|
+
if (t.hasAttribute('data-policy-close')) { closePolicyModal(); return; }
|
|
1052
|
+
if (t.hasAttribute('data-policy-retry')) { const mode = policyMode; closePolicyModal(); openPolicyModal(mode); return; }
|
|
1053
|
+
if (t.hasAttribute('data-policy-notnow')) { await answerPolicyNotNow(); return; }
|
|
1054
|
+
if (t.hasAttribute('data-policy-allow') || t.hasAttribute('data-policy-off')) {
|
|
1055
|
+
const off = t.hasAttribute('data-policy-off');
|
|
1056
|
+
const prev = t.textContent;
|
|
1057
|
+
t.disabled = true; t.setAttribute('aria-busy', 'true'); t.textContent = off ? 'Turning off…' : 'Saving…';
|
|
1058
|
+
try {
|
|
1059
|
+
policyView = off
|
|
1060
|
+
? await api('/api/migration-policy/revoke', { method: 'POST', body: '{}' })
|
|
1061
|
+
: await api('/api/migration-policy', { method: 'POST', body: JSON.stringify({ statementSha256: policyView && policyView.statementSha256 }) });
|
|
1062
|
+
if (off) showToast('Automatic tool updates are off. Every update asks you first.', 'ok');
|
|
1063
|
+
else if (policyView && policyView.on) showToast('Allowed. Small read-only tool fixes carry your approval over.', 'ok');
|
|
1064
|
+
else {
|
|
1065
|
+
// AWARE took the record but does not treat any policy as active (e.g. it reads it as invalid): say so.
|
|
1066
|
+
const problem = policyView && (policyView.policies || []).map((p) => p.problem).find(Boolean);
|
|
1067
|
+
showToast(`AWARE did not turn automatic tool updates on${problem ? `: ${problem}` : ''}. Every update still asks you first.`, 'warn');
|
|
1068
|
+
}
|
|
1069
|
+
if (policyMode === 'first') { closePolicyModal(); return; }
|
|
1070
|
+
renderPolicyModal();
|
|
1071
|
+
const title = $policyModal.querySelector('.modal-title');
|
|
1072
|
+
if (title) title.focus();
|
|
1073
|
+
} catch (err) {
|
|
1074
|
+
if (err.body && err.body.statement && policyView) { policyView.statement = err.body.statement; policyView.statementSha256 = err.body.statementSha256; renderPolicyModal(); }
|
|
1075
|
+
t.disabled = false; t.removeAttribute('aria-busy'); t.textContent = prev;
|
|
1076
|
+
const $e = $policyModal.querySelector('.policy-error') || $err;
|
|
1077
|
+
if ($e) $e.textContent = err.message;
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
});
|
|
1081
|
+
// On the document, not the dialog: a re-render (Turn off → Turn on) replaces the focused button, and focus
|
|
1082
|
+
// then sits on <body>, where a dialog-level listener would never hear Esc.
|
|
1083
|
+
document.addEventListener('keydown', (e) => {
|
|
1084
|
+
if (!$policyModal.classList.contains('show')) return;
|
|
1085
|
+
if (e.key === 'Escape') {
|
|
1086
|
+
e.preventDefault();
|
|
1087
|
+
e.stopPropagation();
|
|
1088
|
+
if (policyMode === 'first') answerPolicyNotNow(); else closePolicyModal();
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
if (e.key === 'Tab') {
|
|
1092
|
+
const items = [...$policyModal.querySelectorAll('button:not([disabled]), summary, [tabindex="-1"].modal-title')].filter((el) => el.offsetParent !== null);
|
|
1093
|
+
if (!items.length) return;
|
|
1094
|
+
const firstEl = items[0]; const lastEl = items[items.length - 1];
|
|
1095
|
+
if (e.shiftKey && document.activeElement === firstEl) { e.preventDefault(); lastEl.focus(); }
|
|
1096
|
+
else if (!e.shiftKey && document.activeElement === lastEl) { e.preventDefault(); firstEl.focus(); }
|
|
1097
|
+
else if (!$policyModal.contains(document.activeElement)) { e.preventDefault(); firstEl.focus(); }
|
|
1098
|
+
}
|
|
1099
|
+
}, true); // capture: the dialog owns Esc/Tab while it is open, ahead of the shell's own Esc handling
|
|
1100
|
+
onBackdropDismiss($policyModal, () => { if (policyMode === 'first') answerPolicyNotNow(); else closePolicyModal(); });
|
|
1101
|
+
}
|
|
1102
|
+
window.openToolUpdatePolicy = () => openPolicyModal('settings');
|
|
1103
|
+
|
|
1104
|
+
|
|
635
1105
|
let reportRunning = false;
|
|
636
1106
|
let cancelRequested = false;
|
|
637
1107
|
let runningSimulation = false;
|
|
@@ -640,7 +1110,8 @@
|
|
|
640
1110
|
let foregroundStopping = false;
|
|
641
1111
|
|
|
642
1112
|
function paintRunState(app) {
|
|
643
|
-
const
|
|
1113
|
+
const gateState = gateStateFor(app);
|
|
1114
|
+
const status = runStatePresentation(presentedGateState(app, gateState), {
|
|
644
1115
|
reportRunning,
|
|
645
1116
|
stateRunning: state.running,
|
|
646
1117
|
simulating: runningSimulation,
|
|
@@ -663,7 +1134,20 @@
|
|
|
663
1134
|
'Listening…': 'The live trigger session is listening for the next host event.',
|
|
664
1135
|
'Cancelling…': 'The current run is being cancelled.',
|
|
665
1136
|
};
|
|
666
|
-
|
|
1137
|
+
if (gateState === 'agent-changed') {
|
|
1138
|
+
gateTips['agent-changed'] = app.approvalCheck ? approvalCheckTip(app.approvalCheck) : agentPinChangeTip(app.agentPinChanges);
|
|
1139
|
+
}
|
|
1140
|
+
// A lock from an older AWARE approved tool VERSIONS, not exact files. It runs; say quietly how to
|
|
1141
|
+
// tighten it, without turning it into a state the person has to act on.
|
|
1142
|
+
if (gateState === 'ready' && app.approvalCheck && app.approvalCheck.kind === 'version-only') {
|
|
1143
|
+
gateTips.ready += '\nOptional: compile again so this workflow is tied to the exact tool files it runs with, not just their version numbers.';
|
|
1144
|
+
}
|
|
1145
|
+
const recordTip = gateState === 'ready' ? approvalRecordTip(app.approvalCheck) : null;
|
|
1146
|
+
if (recordTip) gateTips.ready = recordTip;
|
|
1147
|
+
if (gateState === 'ready' && app.approvalCheck && app.approvalCheck.bridgeWarnings && app.approvalCheck.bridgeWarnings.length) {
|
|
1148
|
+
gateTips.ready += '\nBridge needs attention. Review the warning and choices above the canvas. Run workflow is still available; the run record will note the warning.';
|
|
1149
|
+
}
|
|
1150
|
+
$runState.dataset.tip = activeTips[status.label] || gateTips[gateState] || '';
|
|
667
1151
|
|
|
668
1152
|
// Push a snapshot to the Instructor band. One-way: the band renders what it
|
|
669
1153
|
// is handed and never reaches back into workflow state.
|
|
@@ -671,9 +1155,13 @@
|
|
|
671
1155
|
const inputs = Array.isArray(app.inputs) ? app.inputs : [];
|
|
672
1156
|
const values = typeof currentInputs === 'function' ? currentInputs() || {} : {};
|
|
673
1157
|
window.Instructor.setWorkflow({
|
|
674
|
-
name: app.name || app.id,
|
|
675
|
-
runState:
|
|
1158
|
+
name: workflowLabelOf(app.id) === app.id ? (app.name || app.id) : workflowLabelOf(app.id),
|
|
1159
|
+
runState: gateState,
|
|
676
1160
|
statusLabel: status.label,
|
|
1161
|
+
// #1996: what the Instructor says for a not-confirmed carried-forward approval or an incomplete record.
|
|
1162
|
+
remedy: (app.approvalCheck && app.approvalCheck.remedy) || null,
|
|
1163
|
+
recordIncomplete: recordNeedsCheck(app, gateState),
|
|
1164
|
+
bridgeWarning: !!(app.approvalCheck && app.approvalCheck.bridgeWarnings && app.approvalCheck.bridgeWarnings.length),
|
|
677
1165
|
totalInputs: inputs.length,
|
|
678
1166
|
inputsSet: inputs.filter((i) => {
|
|
679
1167
|
const v = values[i.name];
|
|
@@ -687,6 +1175,7 @@
|
|
|
687
1175
|
// Task-language label (AEC users don't know "lock"/"drift"); the tooltip carries
|
|
688
1176
|
// the why + the Compile step.
|
|
689
1177
|
paintRunState(app);
|
|
1178
|
+
paintApprovalStrip(app);
|
|
690
1179
|
|
|
691
1180
|
// Keep Run disabled (and the header Stop shown) if a gate re-paint lands mid-run (#39) —
|
|
692
1181
|
// never let a re-render re-arm Run while a run is still in flight.
|
|
@@ -697,13 +1186,26 @@
|
|
|
697
1186
|
$runBtn.disabled = !app.runnable || reportRunning || state.running || foregroundStarting || foregroundStopping || !!foregroundTrigger;
|
|
698
1187
|
if ($stopRunBtn) $stopRunBtn.hidden = !(reportRunning || state.running || foregroundStopping || foregroundTrigger);
|
|
699
1188
|
if ($reportStop) $reportStop.hidden = !foregroundTrigger;
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
?
|
|
704
|
-
|
|
1189
|
+
const agentChanged = gateStateFor(app) === 'agent-changed';
|
|
1190
|
+
$runBtn.dataset.tip = agentChanged
|
|
1191
|
+
? (app.approvalCheck
|
|
1192
|
+
? (app.approvalCheck.remedy === 'publish'
|
|
1193
|
+
? 'This workflow changed outside FloLess since it was published — ask AI Chat to publish it again first'
|
|
1194
|
+
: app.approvalCheck.remedy === 'needs-you'
|
|
1195
|
+
? 'A tool version this workflow was approved with is not available — choose in the notice above the canvas'
|
|
1196
|
+
: app.approvalCheck.remedy === 'update-aware'
|
|
1197
|
+
? 'This workflow needs a newer AWARE — update AWARE, or press Compile first'
|
|
1198
|
+
: app.approvalCheck.remedy === 'unconfirmed'
|
|
1199
|
+
? 'FloLess could not confirm this approval just now — reopen the workflow, or press Compile first'
|
|
1200
|
+
: 'Something this workflow was approved with has changed — press Compile first')
|
|
1201
|
+
: 'A tool this workflow uses has changed since it was approved — press Compile first')
|
|
1202
|
+
: app.runnable
|
|
1203
|
+
? 'Run the approved workflow'
|
|
1204
|
+
: app.runState === 'drift'
|
|
1205
|
+
? 'Blocked: the .flo changed since the last approve — Compile first'
|
|
1206
|
+
: 'Blocked: not compiled — Compile first';
|
|
705
1207
|
|
|
706
|
-
const needsCompile = app.runState !== 'ready';
|
|
1208
|
+
const needsCompile = app.runState !== 'ready' || agentChanged;
|
|
707
1209
|
$compileBtn.disabled = false;
|
|
708
1210
|
$compileBtn.textContent = needsCompile ? '⎙ Compile *' : '⎙ Compile';
|
|
709
1211
|
|
|
@@ -727,12 +1229,12 @@
|
|
|
727
1229
|
// what the server reads to mirror inputs). Disabled-with-tooltip (teach the
|
|
728
1230
|
// path), not hidden. Label flips to "Re-bake" when already exposed-as-agent.
|
|
729
1231
|
if ($menuBakeItem) {
|
|
730
|
-
$menuBakeLabel.textContent = app.baked ? 'Re-bake
|
|
1232
|
+
$menuBakeLabel.textContent = app.baked ? 'Re-bake tool' : 'Bake into tool';
|
|
731
1233
|
$menuBakeItem.disabled = !app.runnable;
|
|
732
1234
|
$menuBakeItem.dataset.tip = app.runnable
|
|
733
1235
|
? (app.baked
|
|
734
|
-
? 'Already a reusable
|
|
735
|
-
: 'Package this workflow as a reusable
|
|
1236
|
+
? 'Already a reusable tool. Re-bake to refresh its exposed interface after edits.'
|
|
1237
|
+
: 'Package this workflow as a reusable tool — drop it as a single node in any other workflow.')
|
|
736
1238
|
: app.runState === 'drift'
|
|
737
1239
|
? 'Compile first — the .flo changed since the last approve, so Bake is blocked.'
|
|
738
1240
|
: 'Compile first — there is no approved lock yet, so Bake is blocked.';
|
|
@@ -760,7 +1262,7 @@
|
|
|
760
1262
|
$notesStrip.classList.remove('sev-info', 'sev-warn', 'sev-error');
|
|
761
1263
|
$notesStrip.classList.add('sev-' + worst);
|
|
762
1264
|
$notesStrip.innerHTML =
|
|
763
|
-
`<div class="notes-head"><span class="notes-title">${icon} ${missing.size ? (pending.length ? `${pending.length}
|
|
1265
|
+
`<div class="notes-head"><span class="notes-title">${icon} ${missing.size ? (pending.length ? `${pending.length} tool${pending.length === 1 ? ' needs' : 's need'} ${nextAction}` : unchecked ? 'Check tool installations before compiling' : 'Tools installed — compile to refresh checks') : `${n} workflow notice${n === 1 ? '' : 's'}`}</span>` +
|
|
764
1266
|
missingAgentsBulkButton(pending, canInstall) +
|
|
765
1267
|
`<button class="notes-dismiss" type="button" aria-label="Collapse compiler notes" data-tip="Collapse">×</button></div>` +
|
|
766
1268
|
(missing.size ? `<ul class="missing-agent-list" aria-live="polite">${missingAgentRows(missing)}</ul>` : '') +
|
|
@@ -978,12 +1480,13 @@
|
|
|
978
1480
|
const ico = $b.querySelector('.guide-beacon-ico');
|
|
979
1481
|
const label = $b.querySelector('.guide-beacon-label');
|
|
980
1482
|
if (ico) ico.textContent = isNew ? '✦' : '?';
|
|
981
|
-
|
|
1483
|
+
// #2046: "Guide" is the onboarding agent now; at rest this beacon is about the open project.
|
|
1484
|
+
if (label) label.textContent = isNew ? 'Start here' : 'About this project';
|
|
982
1485
|
// No "workflow"/"Run" vocabulary — this is a document project.
|
|
983
1486
|
$b.dataset.tip = isNew
|
|
984
1487
|
? 'New here? See what this project does and how to take it from drawing to export.'
|
|
985
|
-
: '
|
|
986
|
-
$b.setAttribute('aria-label', (isNew ? 'Start here —
|
|
1488
|
+
: 'See what this project does and how to use it.';
|
|
1489
|
+
$b.setAttribute('aria-label', (isNew ? 'Start here — about ' : 'About ') + (ctx.name || ctx.displayName || ctx.app));
|
|
987
1490
|
}
|
|
988
1491
|
|
|
989
1492
|
function paintBeacon(app) {
|
|
@@ -1001,11 +1504,12 @@
|
|
|
1001
1504
|
// Monochrome dingbats (✦ / ?), not colour emoji — the locked baseline uses text
|
|
1002
1505
|
// glyphs (★, ▸); the pulse, not an emoji, is the "new" signal.
|
|
1003
1506
|
if (ico) ico.textContent = isNew ? '✦' : '?';
|
|
1004
|
-
|
|
1507
|
+
// #2046: "Guide" is the onboarding agent now; at rest this beacon is about the open workflow.
|
|
1508
|
+
if (label) label.textContent = isNew ? 'Start here' : 'About this workflow';
|
|
1005
1509
|
$b.dataset.tip = isNew
|
|
1006
1510
|
? 'New here? See what this workflow does and how to run it.'
|
|
1007
|
-
: '
|
|
1008
|
-
$b.setAttribute('aria-label', (isNew ? 'Start here —
|
|
1511
|
+
: 'See what this workflow does and how to run it.';
|
|
1512
|
+
$b.setAttribute('aria-label', (isNew ? 'Start here — about ' : 'About ') + (app.displayName || app.id));
|
|
1009
1513
|
}
|
|
1010
1514
|
|
|
1011
1515
|
// Record a completed real run → the workflow is no longer new; calm the beacon (and
|
|
@@ -1033,7 +1537,7 @@
|
|
|
1033
1537
|
});
|
|
1034
1538
|
steps.push({ label: 'Set inputs', note: 'the values this workflow runs with', done: allSet });
|
|
1035
1539
|
}
|
|
1036
|
-
steps.push({ label: 'Compile', note: 'freeze the approved lock', done: app
|
|
1540
|
+
steps.push({ label: 'Compile', note: 'freeze the approved lock', done: gateStateFor(app) === 'ready' });
|
|
1037
1541
|
steps.push({ label: 'Run', note: 'against the live host — results render here', done: !!guideFor(app.id).firstRunDone });
|
|
1038
1542
|
return steps;
|
|
1039
1543
|
}
|
|
@@ -1328,7 +1832,7 @@
|
|
|
1328
1832
|
// ≡ menu "New workflow…" — create the durable owner BEFORE asking the terminal AI to author.
|
|
1329
1833
|
// The UI chooses only a display name and owner; the server mints the UUID and derives the actual
|
|
1330
1834
|
// directory. That makes a queued request project-safe without turning the browser into an author.
|
|
1331
|
-
async function requestNewWorkflow() {
|
|
1835
|
+
async function requestNewWorkflow(prefill = {}) {
|
|
1332
1836
|
try {
|
|
1333
1837
|
const { projects = [] } = await api('/api/projects');
|
|
1334
1838
|
const ownerOptions = workflowOwnerOptions(projects);
|
|
@@ -1339,6 +1843,8 @@
|
|
|
1339
1843
|
{
|
|
1340
1844
|
name: 'name', label: 'Workflow name', placeholder: 'e.g. Weekly model review',
|
|
1341
1845
|
commandId: 'shell.new-workflow-name', required: true,
|
|
1846
|
+
// #2046: a Guide suggestion opens this with its name filled in; the person still chooses and confirms.
|
|
1847
|
+
...(typeof prefill.name === 'string' && prefill.name ? { value: prefill.name } : {}),
|
|
1342
1848
|
},
|
|
1343
1849
|
{
|
|
1344
1850
|
name: 'owner', label: 'Location', type: 'select', value: 'standalone',
|
|
@@ -1361,6 +1867,9 @@
|
|
|
1361
1867
|
});
|
|
1362
1868
|
const copied = await copyToClipboard(markedInstruction(request));
|
|
1363
1869
|
showToast(copied ? `${name} is ready · prompt copied` : `${name} is ready to discuss`, 'ok');
|
|
1870
|
+
// #1890 PR 3b-0: the new draft opens, so it is somewhere to come back to — not only a toast.
|
|
1871
|
+
try { ({ workflows: wfOwned } = await api('/api/workflows/owned')); openDraftWorkflow(workflow.workflowId); }
|
|
1872
|
+
catch { /* the draft is still on the Workflows page after the next refresh */ }
|
|
1364
1873
|
appendNarration(`Created <strong>${escapeHtml(name)}</strong> in its chosen location and asked your terminal AI to start there — watch the glowing <strong>requests</strong> pill (bottom-right), or switch to your terminal.${copied ? ' The prompt is also on your clipboard.' : ''}`);
|
|
1365
1874
|
loadRequests();
|
|
1366
1875
|
} catch (e) { reportErr(e); }
|
|
@@ -1370,6 +1879,11 @@
|
|
|
1370
1879
|
// Dims the canvas, raises the beacon, and points a small caption at it; Esc /
|
|
1371
1880
|
// click-away / either button dismiss it for good. Slice 2 of the onboarding beacon.
|
|
1372
1881
|
let _spotlightKey = null;
|
|
1882
|
+
let _spotlightResize = null;
|
|
1883
|
+
// The spotlight points at the workflow canvas, so it lives only while that canvas is on screen (#2007): it is held
|
|
1884
|
+
// back (not used up) while Workspaces, Agents or the Workflows list covers it, and syncSpotlightToMode() follows
|
|
1885
|
+
// every tab switch and the list closing.
|
|
1886
|
+
const canvasHidden = () => document.body.classList.contains('mode-agents') || inWorkspacesMode() || wfLanding;
|
|
1373
1887
|
function maybeSpotlight(app) {
|
|
1374
1888
|
if (!app) return;
|
|
1375
1889
|
const g = guideFor(app.id);
|
|
@@ -1377,12 +1891,38 @@
|
|
|
1377
1891
|
if (document.querySelector('.modal-backdrop.show')) return; // don't pile on a dialog
|
|
1378
1892
|
if ($contractEditor && !$contractEditor.hidden) return;
|
|
1379
1893
|
setTimeout(() => {
|
|
1380
|
-
|
|
1894
|
+
// Checked when it would open, so a workflow loaded behind Workspaces or Agents keeps its spotlight for later.
|
|
1895
|
+
if (currentId !== app.id || canvasHidden()) return; // switched away during the delay
|
|
1381
1896
|
if (guideFor(app.id).spotlightShown) return;
|
|
1382
1897
|
if (document.querySelector('.modal-backdrop.show')) return;
|
|
1898
|
+
if ($contractEditor && !$contractEditor.hidden) return; // the editor opened during the delay
|
|
1383
1899
|
showSpotlight(app);
|
|
1384
1900
|
}, 700);
|
|
1385
1901
|
}
|
|
1902
|
+
// Where the first-open caption bubble sits: just under the anchor (right-aligned to it), clamped so the
|
|
1903
|
+
// whole bubble stays inside the viewport. A zero-sized / missing anchor (the beacon is not laid out on
|
|
1904
|
+
// the landing) falls back to the top-right corner instead of the window origin (#2020).
|
|
1905
|
+
function spotlightBubblePosition(anchor, vw, vh, bw, bh) {
|
|
1906
|
+
const M = 8;
|
|
1907
|
+
const clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, v));
|
|
1908
|
+
const laidOut = !!anchor && Number.isFinite(anchor.right) && Number.isFinite(anchor.bottom)
|
|
1909
|
+
&& (anchor.width > 0 || anchor.height > 0);
|
|
1910
|
+
const left = laidOut ? anchor.right - bw : vw - bw - 16;
|
|
1911
|
+
const top = laidOut ? anchor.bottom + 10 : 64;
|
|
1912
|
+
return { left: clamp(left, M, Math.max(M, vw - bw - M)), top: clamp(top, M, Math.max(M, vh - bh - M)) };
|
|
1913
|
+
}
|
|
1914
|
+
// Anchor the caption bubble just under the beacon, right-aligned to it, and keep the whole bubble
|
|
1915
|
+
// (so its Got it / Show me buttons) inside the window even when the beacon is not laid out (#2020).
|
|
1916
|
+
function placeSpotlightBubble($sp, $b) {
|
|
1917
|
+
const bubble = $sp.querySelector('.guide-spotlight-bubble');
|
|
1918
|
+
if (!bubble) return;
|
|
1919
|
+
bubble.style.maxWidth = Math.max(0, Math.min(280, window.innerWidth - 16)) + 'px';
|
|
1920
|
+
bubble.style.left = '0px'; bubble.style.top = '0px'; bubble.style.right = 'auto';
|
|
1921
|
+
const pos = spotlightBubblePosition($b.getBoundingClientRect(), window.innerWidth, window.innerHeight,
|
|
1922
|
+
bubble.offsetWidth, bubble.offsetHeight);
|
|
1923
|
+
bubble.style.left = pos.left + 'px';
|
|
1924
|
+
bubble.style.top = pos.top + 'px';
|
|
1925
|
+
}
|
|
1386
1926
|
function showSpotlight(app) {
|
|
1387
1927
|
const $sp = document.getElementById('guide-spotlight');
|
|
1388
1928
|
const $b = document.getElementById('guide-beacon');
|
|
@@ -1390,23 +1930,32 @@
|
|
|
1390
1930
|
setGuide(app.id, { spotlightShown: true });
|
|
1391
1931
|
$b.classList.add('spotlit');
|
|
1392
1932
|
$sp.hidden = false;
|
|
1393
|
-
// Anchor the caption bubble just under the beacon, right-aligned to it.
|
|
1394
1933
|
const bubble = $sp.querySelector('.guide-spotlight-bubble');
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1934
|
+
placeSpotlightBubble($sp, $b);
|
|
1935
|
+
// The window can narrow while the tip is open: re-clamp so Got it / Show me never leave the screen (#2020).
|
|
1936
|
+
releaseSpotlightListeners(); // a repeated show (guide state could not be saved) must not stack listeners
|
|
1937
|
+
_spotlightResize = () => placeSpotlightBubble($sp, $b);
|
|
1938
|
+
window.addEventListener('resize', _spotlightResize);
|
|
1400
1939
|
_spotlightKey = (e) => { if (e.key === 'Escape') { e.preventDefault(); hideSpotlight(); } };
|
|
1401
1940
|
document.addEventListener('keydown', _spotlightKey);
|
|
1402
1941
|
if (bubble) { try { bubble.focus(); } catch { /* */ } }
|
|
1403
1942
|
}
|
|
1943
|
+
// Called by workspaces.js after every tab switch: leaving Workflows closes an open spotlight; coming back offers one
|
|
1944
|
+
// that was held back while the canvas was hidden. One already shown stays shown-once.
|
|
1945
|
+
function syncSpotlightToMode() {
|
|
1946
|
+
if (canvasHidden()) { hideSpotlight(); return; }
|
|
1947
|
+
maybeSpotlight(currentId && apps.get(currentId));
|
|
1948
|
+
}
|
|
1404
1949
|
function hideSpotlight() {
|
|
1405
1950
|
const $sp = document.getElementById('guide-spotlight');
|
|
1406
1951
|
const $b = document.getElementById('guide-beacon');
|
|
1407
1952
|
if ($sp) $sp.hidden = true;
|
|
1408
1953
|
if ($b) $b.classList.remove('spotlit');
|
|
1954
|
+
releaseSpotlightListeners();
|
|
1955
|
+
}
|
|
1956
|
+
function releaseSpotlightListeners() {
|
|
1409
1957
|
if (_spotlightKey) { document.removeEventListener('keydown', _spotlightKey); _spotlightKey = null; }
|
|
1958
|
+
if (_spotlightResize) { window.removeEventListener('resize', _spotlightResize); _spotlightResize = null; }
|
|
1410
1959
|
}
|
|
1411
1960
|
|
|
1412
1961
|
// ── load / select / compile / run ───────────────────────────────────────────
|
|
@@ -1444,15 +1993,19 @@
|
|
|
1444
1993
|
|
|
1445
1994
|
async function loadApp(id) {
|
|
1446
1995
|
hideSpotlight(); // a spotlight pointing at the previous app's beacon must clear on switch
|
|
1996
|
+
const ticket = ++selectionTicket;
|
|
1447
1997
|
const payload = api(`/api/app/${encodeURIComponent(id)}`);
|
|
1448
1998
|
const read = beginPublicationAvailabilityRead(id, payload);
|
|
1449
1999
|
const { app, contractState } = await payload;
|
|
2000
|
+
if (ticket !== selectionTicket) return; // something newer was opened while this one loaded
|
|
2001
|
+
closeDraftView();
|
|
1450
2002
|
apps.set(id, app);
|
|
1451
2003
|
// A PARALLEL map, never a key on `app`. The app object is AWARE's app spec — `transform()`,
|
|
1452
2004
|
// `seedAppInputs()` and `paintGate()` all take it — and FloLess's reading OF that app does not
|
|
1453
2005
|
// belong inside it. Set unconditionally (including to undefined) so a workflow that stops being a
|
|
1454
2006
|
// publication clears, rather than keeping the previous answer forever.
|
|
1455
2007
|
await commitPublicationAvailability(id, read, contractState);
|
|
2008
|
+
if (ticket !== selectionTicket) return; // a newer selection also wins during the availability wait
|
|
1456
2009
|
currentId = id;
|
|
1457
2010
|
workflowSelectionGeneration += 1;
|
|
1458
2011
|
if (id === 'tekla-model-report' || id === 'floless-workspace-model-report') {
|
|
@@ -1469,7 +2022,7 @@
|
|
|
1469
2022
|
state.selectedAgentId = null;
|
|
1470
2023
|
state.hasRun = false;
|
|
1471
2024
|
if ($promptSel.value !== id) $promptSel.value = id;
|
|
1472
|
-
setComboTriggerLabel(id);
|
|
2025
|
+
setComboTriggerLabel(workflowLabelOf(id));
|
|
1473
2026
|
setComboSelected(id);
|
|
1474
2027
|
renderChat();
|
|
1475
2028
|
renderTopology(); // selects first node + renderInspect
|
|
@@ -1528,7 +2081,7 @@
|
|
|
1528
2081
|
]).then(() => {});
|
|
1529
2082
|
}
|
|
1530
2083
|
|
|
1531
|
-
async function loadApps() {
|
|
2084
|
+
async function loadApps({ preserveSelection = false } = {}) {
|
|
1532
2085
|
// …and mean it: the trigger said "loading…" but stayed CLICKABLE, so a click during the fetch
|
|
1533
2086
|
// opened the popover onto an empty #wf-list — the exact "picker opens and stays empty, it never
|
|
1534
2087
|
// says loading, it just looks broken" report in #358. buildWorkflowCombo() re-enables it once
|
|
@@ -1539,19 +2092,64 @@
|
|
|
1539
2092
|
// with no re-enable path — worst on delete, which clears the open workflow first. So a failed
|
|
1540
2093
|
// refresh restores what the user had; only a load that never had a list stays disabled.
|
|
1541
2094
|
const wasUsable = !!$wfTrigger && !$wfTrigger.disabled;
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
2095
|
+
if (!preserveSelection) {
|
|
2096
|
+
setComboTriggerLabel('loading…');
|
|
2097
|
+
if ($wfTrigger) $wfTrigger.disabled = true;
|
|
2098
|
+
renderCanvasPlaceholder('loading');
|
|
2099
|
+
}
|
|
1545
2100
|
let list;
|
|
2101
|
+
// #1890 PR 3b-0: the owned workflow open now, read before the owner map is refreshed — if its installed copy is
|
|
2102
|
+
// gone after this refresh, it shows its own recovery view instead of falling back to another workflow.
|
|
2103
|
+
const openOwned = currentId ? ownedWorkflowOf(currentId)?.ownedWorkflow ?? null : null;
|
|
2104
|
+
const openId = currentId;
|
|
2105
|
+
const generation = ++appsLoadGeneration;
|
|
2106
|
+
let owned = null;
|
|
1546
2107
|
try {
|
|
1547
2108
|
({ apps: list } = await api('/api/workflows/library'));
|
|
2109
|
+
try { ({ workflows: owned } = await api('/api/workflows/owned?archived=1')); }
|
|
2110
|
+
catch { /* the owned list is additive here: a failed read keeps the drafts last shown */ }
|
|
2111
|
+
// An older refresh that finishes after a newer one must not overwrite what the newer one showed.
|
|
2112
|
+
if (generation !== appsLoadGeneration) return;
|
|
2113
|
+
if (owned) wfOwned = owned;
|
|
1548
2114
|
list = list.filter((a) => a.execution !== 'internal');
|
|
1549
2115
|
rememberWorkflowOwners(list);
|
|
1550
2116
|
wfLibrary = list;
|
|
1551
2117
|
} catch (e) {
|
|
1552
|
-
|
|
2118
|
+
// Usable before THIS refresh, or built by an earlier one (an overlapping refresh disabled it first, and its
|
|
2119
|
+
// own success was then superseded): a failed refresh never strands a picker that has workflows in it.
|
|
2120
|
+
if (!preserveSelection) {
|
|
2121
|
+
if ((wasUsable || $promptSel.options.length > 0) && $wfTrigger) $wfTrigger.disabled = false;
|
|
2122
|
+
}
|
|
1553
2123
|
throw e;
|
|
1554
2124
|
}
|
|
2125
|
+
if (preserveSelection) {
|
|
2126
|
+
// Read the current selection AFTER the requests: a person may have opened something newer.
|
|
2127
|
+
// Refreshing a restored workflow's catalogue must not change that canvas, label or picker value.
|
|
2128
|
+
const selected = $promptSel.value;
|
|
2129
|
+
const selectedText = Array.from($promptSel.options).find((option) => option.value === selected)?.textContent || selected;
|
|
2130
|
+
$promptSel.innerHTML = '';
|
|
2131
|
+
for (const entry of list) {
|
|
2132
|
+
const option = document.createElement('option');
|
|
2133
|
+
option.value = entry.id;
|
|
2134
|
+
option.textContent = `${entry.ownedWorkflow ? entry.ownedWorkflow.displayName : entry.id} · ${entry.nodes} node${entry.nodes === 1 ? '' : 's'} · ${entry.layout}`;
|
|
2135
|
+
$promptSel.appendChild(option);
|
|
2136
|
+
}
|
|
2137
|
+
if (selected && !list.some((entry) => entry.id === selected)) {
|
|
2138
|
+
const option = document.createElement('option');
|
|
2139
|
+
option.value = selected; option.textContent = selectedText; option.hidden = true;
|
|
2140
|
+
$promptSel.appendChild(option);
|
|
2141
|
+
}
|
|
2142
|
+
$promptSel.value = selected;
|
|
2143
|
+
buildWorkflowCombo(list);
|
|
2144
|
+
// A pending older refresh may have disabled the picker. Its transient flag is not
|
|
2145
|
+
// readiness: this fresh catalogue owns enablement, and a hidden selection is not a choice.
|
|
2146
|
+
if ($wfTrigger) $wfTrigger.disabled = !list.length;
|
|
2147
|
+
setComboSelected(currentId || selected);
|
|
2148
|
+
const count = document.getElementById('apps-count');
|
|
2149
|
+
if (count) count.textContent = list.length;
|
|
2150
|
+
if (wfLanding) renderWorkflowsLanding();
|
|
2151
|
+
return;
|
|
2152
|
+
}
|
|
1555
2153
|
$promptSel.innerHTML = '';
|
|
1556
2154
|
if (!list.length) {
|
|
1557
2155
|
// The guided empty-state panel owns the "install a workflow" message now —
|
|
@@ -1562,6 +2160,7 @@
|
|
|
1562
2160
|
workflowSelectionGeneration += 1;
|
|
1563
2161
|
refreshKbInformed(null); // invalidate any in-flight app read and remove workflow-only provenance
|
|
1564
2162
|
void refreshWorkflowUnits(null);
|
|
2163
|
+
if (draftWorkflow) { resolveOpenDraft(); return; }
|
|
1565
2164
|
notifyChatScope(); // the last workflow went away (archive/delete): AI Chat must let go of it too
|
|
1566
2165
|
$runBtn.disabled = true;
|
|
1567
2166
|
$compileBtn.disabled = true;
|
|
@@ -1587,12 +2186,41 @@
|
|
|
1587
2186
|
buildWorkflowCombo(list); // searchable, provider-grouped picker over the hidden select
|
|
1588
2187
|
// Restore the last-opened app (remembered across refresh); fall back to the
|
|
1589
2188
|
// first app when there's no saved choice or it's no longer installed.
|
|
2189
|
+
// #1890 PR 3b-0: an open draft keeps its view and its chat through every refresh; only its own publication
|
|
2190
|
+
// or archive moves it on.
|
|
2191
|
+
if (draftWorkflow) {
|
|
2192
|
+
await resolveOpenDraft();
|
|
2193
|
+
if (wfLanding) renderWorkflowsLanding();
|
|
2194
|
+
return;
|
|
2195
|
+
}
|
|
2196
|
+
if (openOwned?.workflowId && openId && !list.some((a) => a.id === openId)) {
|
|
2197
|
+
const stillOwned = wfOwned.find((row) => row.workflowId === openOwned.workflowId && row.status !== 'archived');
|
|
2198
|
+
if (stillOwned?.activePublication) {
|
|
2199
|
+
openDraftWorkflow(stillOwned.workflowId);
|
|
2200
|
+
if (wfLanding) renderWorkflowsLanding();
|
|
2201
|
+
return;
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
1590
2204
|
let startId = list[0].id;
|
|
1591
2205
|
try {
|
|
1592
2206
|
const saved = localStorage.getItem(LS_LAST_APP);
|
|
1593
2207
|
if (saved && list.some((a) => a.id === saved)) startId = saved;
|
|
1594
2208
|
} catch { /* ignore */ }
|
|
1595
|
-
|
|
2209
|
+
const ticketBefore = selectionTicket;
|
|
2210
|
+
try {
|
|
2211
|
+
await loadApp(startId);
|
|
2212
|
+
} catch (error) {
|
|
2213
|
+
// #1890 PR 3b-0: an owned workflow being uninstalled outside FloLess can still be listed for a moment (its lock is
|
|
2214
|
+
// gone, its folder not yet), so loading it fails. Its installed copy is missing: show its recovery view now —
|
|
2215
|
+
// unless something newer was opened meanwhile, which wins.
|
|
2216
|
+
const owned = ownedWorkflowOf(startId)?.ownedWorkflow;
|
|
2217
|
+
if (error?.status === 404 && owned?.workflowId) {
|
|
2218
|
+
if (selectionTicket !== ticketBefore + 1 || generation !== appsLoadGeneration) return; // a newer open or refresh won
|
|
2219
|
+
const row = wfOwned.find((item) => item.workflowId === owned.workflowId && item.status !== 'archived');
|
|
2220
|
+
if (row) { openDraftWorkflow(row.workflowId); return; }
|
|
2221
|
+
}
|
|
2222
|
+
throw error;
|
|
2223
|
+
}
|
|
1596
2224
|
// #1890: the Workflows tab starts on its landing (owner: people start there and tell AI Chat what they want); a
|
|
1597
2225
|
// later refresh (rename, delete, apps-changed) keeps whatever is showing.
|
|
1598
2226
|
if (!wfLandingBooted) { wfLandingBooted = true; showWorkflowsLanding(true); }
|
|
@@ -1642,6 +2270,17 @@
|
|
|
1642
2270
|
let wfLanding = false;
|
|
1643
2271
|
let wfLandingBooted = false;
|
|
1644
2272
|
let wfLibrary = [];
|
|
2273
|
+
// #1890 PR 3b-0: every owned workflow, drafts included (/api/workflows/owned), and the draft open in the canvas
|
|
2274
|
+
// area, if any. A draft has no runtime app, so it is never `currentId` and never goes to loadApp.
|
|
2275
|
+
let wfOwned = [];
|
|
2276
|
+
const restoringWorkflows = new Set();
|
|
2277
|
+
let draftWorkflow = null;
|
|
2278
|
+
// Opening anything (a workflow or a draft) takes a new ticket; a workflow load that finishes after a newer open
|
|
2279
|
+
// is dropped, so a slow load can never land on top of a draft opened meanwhile (#1890 PR 3b-0 review).
|
|
2280
|
+
let selectionTicket = 0;
|
|
2281
|
+
// Each loadApps() takes a number; only the newest may change the lists or what is open.
|
|
2282
|
+
let appsLoadGeneration = 0;
|
|
2283
|
+
let wsTitleKind = null; // #2007: 'agents' while the Agents tab is on screen (it reuses this title/Instructor seam)
|
|
1645
2284
|
let wsTitleName = null; // open Workspaces project name, or 'Workspaces' on its landing; null = Workflows mode
|
|
1646
2285
|
let wsTitleLanding = false; // explicit because a project may itself be named "Workspaces"
|
|
1647
2286
|
let wsTitleProjectId = null; // identity: two projects may legitimately share a display name
|
|
@@ -1698,7 +2337,7 @@
|
|
|
1698
2337
|
const actions = owned
|
|
1699
2338
|
? `<button type="button" class="wf-act act-edit" data-wf-act="rename" data-command-id="workflow.rename-owned#${escapeAttr(ownedId)}" data-command-instance-label="${escapeAttr(workflowName)}" data-id="${aid}" tabindex="-1" data-tip="Rename" aria-label="Rename ${escapeAttr(workflowName)}">✎</button>`
|
|
1700
2339
|
+ `<button type="button" class="wf-act act-dup" data-wf-act="duplicate" data-command-id="workflow.copy-owned#${escapeAttr(ownedId)}" data-command-instance-label="${escapeAttr(workflowName)}" data-id="${aid}" tabindex="-1" data-tip="Copy" aria-label="Copy ${escapeAttr(workflowName)}">⧉</button>`
|
|
1701
|
-
+ `<button type="button" class="wf-act act-del" data-wf-act="delete" data-command-id="workflow.archive#${escapeAttr(ownedId)}" data-command-instance-label="${escapeAttr(workflowName)}" data-id="${aid}" tabindex="-1" data-tip="Archive" aria-label="Archive ${escapeAttr(workflowName)}">×</button>`
|
|
2340
|
+
+ `<button type="button" class="wf-act act-del" data-wf-act="delete" data-command-id="workflow.archive#${escapeAttr(ownedId)}" data-command-instance-label="${escapeAttr(workflowName)}" data-id="${aid}" tabindex="-1" data-tip="Archive — restore from Archived on the Workflows page" aria-label="Archive ${escapeAttr(workflowName)}">×</button>`
|
|
1702
2341
|
: `<button type="button" class="wf-act act-edit" data-wf-act="rename" data-command-id="workflow.rename#${escapeAttr(aid)}" data-id="${aid}" tabindex="-1" data-tip="Rename" aria-label="Rename ${escapeAttr(workflowName)}">✎</button>`
|
|
1703
2342
|
+ `<button type="button" class="wf-act act-dup" data-wf-act="duplicate" data-command-id="workflow.duplicate#${escapeAttr(aid)}" data-id="${aid}" tabindex="-1" data-tip="Duplicate" aria-label="Duplicate ${escapeAttr(workflowName)}">⧉</button>`
|
|
1704
2343
|
+ `<button type="button" class="wf-act act-del" data-wf-act="delete" data-command-id="workflow.delete#${escapeAttr(aid)}" data-id="${aid}" tabindex="-1" data-tip="Delete" aria-label="Delete ${escapeAttr(workflowName)}">×</button>`;
|
|
@@ -1803,7 +2442,7 @@
|
|
|
1803
2442
|
// #1890: the workflow under the landing is already loaded; picking it only leaves the landing.
|
|
1804
2443
|
showWorkflowsLanding(false);
|
|
1805
2444
|
}
|
|
1806
|
-
setComboTriggerLabel(id);
|
|
2445
|
+
setComboTriggerLabel(workflowLabelOf(id));
|
|
1807
2446
|
}
|
|
1808
2447
|
|
|
1809
2448
|
if ($wfTrigger) {
|
|
@@ -1939,7 +2578,7 @@
|
|
|
1939
2578
|
closeCombo(false);
|
|
1940
2579
|
const res = await formModal({
|
|
1941
2580
|
title: 'Archive workflow?',
|
|
1942
|
-
sub: `Hide “${name}” from Workflows and block new runs. Its source, chat, history and publications stay on this computer
|
|
2581
|
+
sub: `Hide “${name}” from Workflows and block new runs. Its source, chat, history and publications stay on this computer. Restore it from Archived on the Workflows page.`,
|
|
1943
2582
|
fields: [], okLabel: 'Archive', safeDefault: true,
|
|
1944
2583
|
});
|
|
1945
2584
|
if (!res) return;
|
|
@@ -1947,8 +2586,10 @@
|
|
|
1947
2586
|
await api(`/api/workflows/owned/${encodeURIComponent(workflowId)}/archive`, {
|
|
1948
2587
|
method: 'POST', body: JSON.stringify({ archived: true }),
|
|
1949
2588
|
});
|
|
2589
|
+
const wasOpenDraft = draftWorkflow?.workflowId === workflowId;
|
|
1950
2590
|
await loadApps();
|
|
1951
|
-
|
|
2591
|
+
// An open draft already said so when the refresh closed it (resolveOpenDraft) — one message, not two.
|
|
2592
|
+
if (!(wasOpenDraft && !draftWorkflow)) showToast(`Archived “${name}”`, 'ok');
|
|
1952
2593
|
} catch (e) { reportErr(e); }
|
|
1953
2594
|
}
|
|
1954
2595
|
|
|
@@ -1978,7 +2619,7 @@
|
|
|
1978
2619
|
// Warn (informed consent) — not a blocker; the user may be renaming an unreferenced
|
|
1979
2620
|
// one (#226 UX review).
|
|
1980
2621
|
const sub = 'This is the name you pick here, and what .flo files and your terminal AI use to refer to it.'
|
|
1981
|
-
+ (baked ? ' Renaming a baked workflow also renames its synthesized
|
|
2622
|
+
+ (baked ? ' Renaming a baked workflow also renames its synthesized tool — other workflows that use it as a node will need updating.' : '');
|
|
1982
2623
|
const res = await formModal({
|
|
1983
2624
|
title: 'Rename workflow',
|
|
1984
2625
|
sub,
|
|
@@ -2992,6 +3633,19 @@
|
|
|
2992
3633
|
// endpoint owns approval/account filtering and a signed, revision-bound cursor. A single retry
|
|
2993
3634
|
// state survives every full-list restart, so alternating session loss and picker changes cannot
|
|
2994
3635
|
// reset each other's bounds and mix more than one replacement snapshot into the result.
|
|
3636
|
+
// #1840: an approved Tekla version that accepted open import findings says so wherever it is picked
|
|
3637
|
+
// (Run inputs, routine inputs, scheduled runs). Empty for every other version.
|
|
3638
|
+
function acceptedFindingsMeta(version) {
|
|
3639
|
+
const open = Number(version && version.acceptedImportFindings && version.acceptedImportFindings.open);
|
|
3640
|
+
return Number.isSafeInteger(open) && open > 0 ? `${open.toLocaleString('en-US')} ${open === 1 ? 'finding' : 'findings'} accepted` : '';
|
|
3641
|
+
}
|
|
3642
|
+
/** The "Latest approved" choice resolves to the newest version, so it carries that version's label. */
|
|
3643
|
+
function latestAcceptedFindingsMeta(versions) {
|
|
3644
|
+
const newest = (versions || []).slice().sort((a, b) => Number(b.approvalVersion) - Number(a.approvalVersion))[0];
|
|
3645
|
+
const meta = acceptedFindingsMeta(newest);
|
|
3646
|
+
return meta ? `v${newest.approvalVersion} has ${meta}` : '';
|
|
3647
|
+
}
|
|
3648
|
+
|
|
2995
3649
|
async function fetchApprovedModelRevisions(module = 'revit', retries = Object.freeze({ auth: 0, changed: 0 })) {
|
|
2996
3650
|
try {
|
|
2997
3651
|
const projects = new Map();
|
|
@@ -3140,19 +3794,21 @@
|
|
|
3140
3794
|
const exact = project.versions.slice().sort((a, b) => Number(b.approvalVersion) - Number(a.approvalVersion)).map((version) => {
|
|
3141
3795
|
const date = version.approvedAt ? new Date(version.approvedAt).toLocaleDateString(undefined, { day: 'numeric', month: 'short', year: 'numeric' }) : 'Date unavailable';
|
|
3142
3796
|
const short = String(version.approvedRevisionId).slice(0, 10);
|
|
3797
|
+
const accepted = acceptedFindingsMeta(version);
|
|
3143
3798
|
return {
|
|
3144
3799
|
value: selection({ approvedRevisionId: version.approvedRevisionId, approvalVersion: version.approvalVersion }),
|
|
3145
3800
|
group: project.name, groupMeta: `${selectedModelName} model`, label: `Approved v${version.approvalVersion}`,
|
|
3146
|
-
triggerLabel: `${project.name} · approved v${version.approvalVersion} · ${short}`,
|
|
3147
|
-
meta: `${date} · ${short}`,
|
|
3148
|
-
ariaLabel: `${project.name}, ${selectedModelName} model, approved version ${version.approvalVersion}, ${date}, revision ${version.approvedRevisionId}`,
|
|
3801
|
+
triggerLabel: `${project.name} · approved v${version.approvalVersion} · ${short}${accepted ? ` · ${accepted}` : ''}`,
|
|
3802
|
+
meta: `${date} · ${short}${accepted ? ` · ${accepted}` : ''}`,
|
|
3803
|
+
ariaLabel: `${project.name}, ${selectedModelName} model, approved version ${version.approvalVersion}, ${date}, revision ${version.approvedRevisionId}${accepted ? `, approved with ${accepted.replace(/ accepted$/, '')} accepted as stated assumptions` : ''}`,
|
|
3149
3804
|
search: `${project.name} ${selectedModelName} approved version ${version.approvalVersion} ${date} ${version.approvedRevisionId}`,
|
|
3150
3805
|
};
|
|
3151
3806
|
});
|
|
3807
|
+
const latestAccepted = latestAcceptedFindingsMeta(project.versions);
|
|
3152
3808
|
return [...exact, {
|
|
3153
3809
|
value: selection({ latestApproved: true }), group: project.name, groupMeta: `${selectedModelName} model`, volatile: true,
|
|
3154
|
-
label: 'Latest approved', triggerLabel: `${project.name} · latest approved (volatile)`,
|
|
3155
|
-
meta:
|
|
3810
|
+
label: 'Latest approved', triggerLabel: `${project.name} · latest approved (volatile)${latestAccepted ? ` · ${latestAccepted}` : ''}`,
|
|
3811
|
+
meta: `changes when approvals change${latestAccepted ? ` · ${latestAccepted}` : ''}`,
|
|
3156
3812
|
ariaLabel: `${project.name}, ${selectedModelName} model, latest approved, changes when approvals change`,
|
|
3157
3813
|
search: `${project.name} ${selectedModelName} latest approved changes approvals volatile`,
|
|
3158
3814
|
}];
|
|
@@ -3391,8 +4047,18 @@
|
|
|
3391
4047
|
$reportShare.hidden = true;
|
|
3392
4048
|
showSavedPathActions('');
|
|
3393
4049
|
$reportOverlay.hidden = true; $reportOverlay.replaceChildren();
|
|
4050
|
+
// #1840: the caption says when the report's approved version accepted open import findings (the
|
|
4051
|
+
// server's sentence). The report body comes from AWARE's report protocol, which appears to have no
|
|
4052
|
+
// field for it (inferred from its parser's messages, not reproduced). When the server could not
|
|
4053
|
+
// read that approval's record, the caption says so instead of reading as a plain approval.
|
|
3394
4054
|
$reportSub.textContent = report.scheduledCaption
|
|
3395
4055
|
|| `Complete read-only report · ${count} objects · ${properties} properties · approved revision ${String(index.revisionId).slice(0, 12)} · source unchanged.`;
|
|
4056
|
+
if (typeof index.acceptedImportFindingsNote === 'string') $reportSub.textContent += ` ${index.acceptedImportFindingsNote}`;
|
|
4057
|
+
else if (index.approvalDetailsUnavailable === true) $reportSub.textContent += ' Approval details unavailable.';
|
|
4058
|
+
// What the report rests on comes first (a scheduled "Latest approved" run that read an older
|
|
4059
|
+
// approved version says which), never after the counts where it would read as a footnote.
|
|
4060
|
+
const warnings = Array.isArray(index.warnings) ? index.warnings.filter((warning) => typeof warning === 'string' && warning) : [];
|
|
4061
|
+
if (warnings.length) $reportSub.textContent = `${warnings.join(' ')} ${$reportSub.textContent}`;
|
|
3396
4062
|
} catch (error) {
|
|
3397
4063
|
if (request !== reportSectionRequest) return;
|
|
3398
4064
|
clearCompleteReportView();
|
|
@@ -4148,6 +4814,7 @@
|
|
|
4148
4814
|
}
|
|
4149
4815
|
await api(`/api/contract/${encodeURIComponent(appId)}/approve`, { method: 'POST' });
|
|
4150
4816
|
showToast('Approved — lock baked. Run is armed.', 'ok');
|
|
4817
|
+
maybeAskPolicyAfterApproval();
|
|
4151
4818
|
} catch (e) {
|
|
4152
4819
|
showToast('We couldn’t approve this workflow because FloLess could not save the approval. Try again.', 'warn');
|
|
4153
4820
|
} finally {
|
|
@@ -4241,9 +4908,7 @@
|
|
|
4241
4908
|
// Other recoverable failures (host not attached, stale lock, …): show it
|
|
4242
4909
|
// in the viewer overlay + a toast. No console.error — the server returns the
|
|
4243
4910
|
// failure in-band, so a failed run isn't a console-worthy fault.
|
|
4244
|
-
|
|
4245
|
-
$reportSub.textContent = 'The report could not be created.';
|
|
4246
|
-
showToast(runFailureMessage(msg), 'warn');
|
|
4911
|
+
showRunFailure(e.body || {}, runFailureMessage(msg), app);
|
|
4247
4912
|
}
|
|
4248
4913
|
}
|
|
4249
4914
|
} finally {
|
|
@@ -4268,6 +4933,58 @@
|
|
|
4268
4933
|
return n;
|
|
4269
4934
|
}
|
|
4270
4935
|
|
|
4936
|
+
// A run that failed for any reason other than Stop or an expired sign-in (#1912, #1851): the
|
|
4937
|
+
// plain sentence the server or runFailureMessage produced, the fix when there is one (Compile, for
|
|
4938
|
+
// an approval AWARE refused), and Report this problem every time. Reuses the reconnect card's
|
|
4939
|
+
// amber-topped layout; built with textContent only, so nothing the server says becomes markup.
|
|
4940
|
+
function showRunFailure(body, message, app) {
|
|
4941
|
+
const code = body && typeof body.code === 'string' ? body.code : '';
|
|
4942
|
+
const compileFix = (code === 'agent-version-changed' || code === 'needs-compile') && !$compileBtn.hidden;
|
|
4943
|
+
const reinstall = code === 'agent-files-changed';
|
|
4944
|
+
clearReportFrames();
|
|
4945
|
+
$reportShare.hidden = true;
|
|
4946
|
+
$reportOverlay.hidden = false;
|
|
4947
|
+
$reportOverlay.replaceChildren();
|
|
4948
|
+
$reportSub.textContent = 'The report could not be created.';
|
|
4949
|
+
|
|
4950
|
+
const card = mkEl('div', 'cred-fail-card run-fail-card');
|
|
4951
|
+
card.setAttribute('role', 'status');
|
|
4952
|
+
const status = mkEl('div', 'cred-fail-status');
|
|
4953
|
+
const icon = mkEl('span', 'cred-fail-icon', '⚠');
|
|
4954
|
+
icon.setAttribute('aria-hidden', 'true');
|
|
4955
|
+
status.append(icon, document.createTextNode(compileFix ? 'Needs compiling' : reinstall ? 'Tool changed' : 'Run stopped'));
|
|
4956
|
+
const headline = mkEl('div', 'cred-fail-headline', compileFix
|
|
4957
|
+
? 'This workflow needs compiling again'
|
|
4958
|
+
: reinstall ? 'A tool needs reinstalling' : 'The workflow stopped before it finished');
|
|
4959
|
+
const text = mkEl('div', 'cred-fail-body', message);
|
|
4960
|
+
for (const warning of (body && body.bridgeWarnings) || []) {
|
|
4961
|
+
const label = warning.status === 'declaration-invalid' ? 'Ran with an invalid bridge declaration' : 'Ran with a bridge mismatch';
|
|
4962
|
+
text.append(mkEl('p', '', `${label}: ${warning.via ? warning.via + ' → ' : ''}${warning.name}. ${warning.detail}`));
|
|
4963
|
+
}
|
|
4964
|
+
const actions = mkEl('div', 'cred-fail-actions');
|
|
4965
|
+
if (compileFix) {
|
|
4966
|
+
const compile = mkEl('button', 'primary cred-reconnect run-fail-compile', 'Compile now');
|
|
4967
|
+
compile.type = 'button';
|
|
4968
|
+
compile.dataset.commandId = 'shell.run-failure-compile';
|
|
4969
|
+
compile.onclick = () => { hideModal($reportModal); $compileBtn.click(); };
|
|
4970
|
+
actions.append(compile);
|
|
4971
|
+
}
|
|
4972
|
+
const report = mkEl('button', 'cred-open-integrations run-fail-report', 'Report this problem');
|
|
4973
|
+
report.type = 'button';
|
|
4974
|
+
report.dataset.commandId = 'shell.run-failure-report';
|
|
4975
|
+
report.onclick = () => window.dispatchEvent(new CustomEvent('floless:report-run-issue', {
|
|
4976
|
+
// AWARE's own words (`reason`) go only into the report the person reviews before sending —
|
|
4977
|
+
// never onto the card, which must stay plain.
|
|
4978
|
+
detail: { workflow: (app && app.displayName) || currentId || '', message,
|
|
4979
|
+
reason: body && typeof body.reason === 'string' ? body.reason : '', returnFocus: report },
|
|
4980
|
+
}));
|
|
4981
|
+
actions.append(report);
|
|
4982
|
+
card.append(status, headline, text, actions);
|
|
4983
|
+
$reportOverlay.append(card);
|
|
4984
|
+
showToast(message, 'warn');
|
|
4985
|
+
(actions.querySelector('button') || report).focus();
|
|
4986
|
+
}
|
|
4987
|
+
|
|
4271
4988
|
const CRED_BODY_IDLE = 'Sign in again and then run the workflow — it takes about 30 seconds.';
|
|
4272
4989
|
|
|
4273
4990
|
function showCredentialReconnect(cred) {
|
|
@@ -5117,7 +5834,7 @@
|
|
|
5117
5834
|
|| $body.querySelector('.fm-files .fm-drop, .fm-file .fm-drop, .fm-images .fm-drop')
|
|
5118
5835
|
|| $body.querySelector('[data-fm-empty-action]:not([disabled])');
|
|
5119
5836
|
if (first) { first.focus(); if (first.select) first.select(); }
|
|
5120
|
-
else if ((danger || $ok.disabled) && !hideCancel) $cancel.focus();
|
|
5837
|
+
else if ((danger || safeDefault || $ok.disabled) && !hideCancel) $cancel.focus();
|
|
5121
5838
|
else $ok.focus();
|
|
5122
5839
|
const collect = () => {
|
|
5123
5840
|
const out = {};
|
|
@@ -5460,6 +6177,8 @@
|
|
|
5460
6177
|
? 'Workflow compiled. Review any notices above the canvas before running.'
|
|
5461
6178
|
: `Compiled, but ${app.notes.length} notice(s) remain — review them above the canvas.`);
|
|
5462
6179
|
showToast('Workflow compiled', 'ok');
|
|
6180
|
+
// #1998: a person just approved a workflow — the moment to ask, once, about small read-only tool fixes.
|
|
6181
|
+
maybeAskPolicyAfterApproval();
|
|
5463
6182
|
} catch (e) {
|
|
5464
6183
|
$compileBtn.textContent = prev;
|
|
5465
6184
|
$compileBtn.disabled = false;
|
|
@@ -5477,18 +6196,18 @@
|
|
|
5477
6196
|
if (!currentId || ($menuBakeItem && $menuBakeItem.disabled)) return;
|
|
5478
6197
|
const app = apps.get(currentId);
|
|
5479
6198
|
if (!app) return;
|
|
5480
|
-
document.getElementById('bake-title').textContent = app.baked ? 'Re-bake
|
|
6199
|
+
document.getElementById('bake-title').textContent = app.baked ? 'Re-bake tool' : 'Bake into tool';
|
|
5481
6200
|
const inps = app.inputs || [];
|
|
5482
6201
|
const inputsHtml = inps.length
|
|
5483
6202
|
? inps.map((i) => `<span class="ni-pair"><span class="ni-key">${escapeHtml(i.name)}</span><span class="ni-val">${escapeHtml(i.type)}</span></span>`).join('')
|
|
5484
|
-
: '<span class="bake-noinputs">No inputs — this
|
|
6203
|
+
: '<span class="bake-noinputs">No inputs — this tool is called with no parameters.</span>';
|
|
5485
6204
|
// Rebuild the whole body each open — a prior runBake() replaces it with the
|
|
5486
6205
|
// spinner (destroying #bake-name/#bake-inputs), so we can't assume they exist.
|
|
5487
6206
|
const $body = document.getElementById('bake-body');
|
|
5488
6207
|
$body.classList.remove('busy');
|
|
5489
6208
|
$body.innerHTML =
|
|
5490
|
-
`<div class="modal-field"><label>
|
|
5491
|
-
`<div class="modal-field"><label>
|
|
6209
|
+
`<div class="modal-field"><label>Tool name</label><div id="bake-name" class="bake-name"><code>${escapeHtml(app.id)}</code></div></div>` +
|
|
6210
|
+
`<div class="modal-field"><label>Tool inputs</label><div id="bake-inputs" class="bake-inputs">${inputsHtml}</div></div>`;
|
|
5492
6211
|
const $confirm = document.getElementById('bake-confirm');
|
|
5493
6212
|
const $cancel = document.getElementById('bake-cancel');
|
|
5494
6213
|
$confirm.disabled = false; $cancel.disabled = false;
|
|
@@ -5506,17 +6225,17 @@
|
|
|
5506
6225
|
$confirm.disabled = true; $cancel.disabled = true;
|
|
5507
6226
|
$confirm.textContent = '⊙ Baking…';
|
|
5508
6227
|
$body.classList.add('busy');
|
|
5509
|
-
$body.innerHTML = '<div class="bake-progress"><span class="rtn-spinner"></span><span>Reinstalling as
|
|
6228
|
+
$body.innerHTML = '<div class="bake-progress"><span class="rtn-spinner"></span><span>Reinstalling as a tool — this takes a few seconds…</span></div>';
|
|
5510
6229
|
try {
|
|
5511
6230
|
await api('/api/bake', { method: 'POST', body: JSON.stringify({ id }) });
|
|
5512
6231
|
hideModal($bakeModal);
|
|
5513
6232
|
await loadApp(id);
|
|
5514
|
-
appendNarration(`Baked <strong>${escapeHtml(id)}</strong> as a reusable
|
|
5515
|
-
showToast(`Baked — now in the
|
|
6233
|
+
appendNarration(`Baked <strong>${escapeHtml(id)}</strong> as a reusable tool — find it in the Tools library (<strong>≡ menu → Tools</strong>).`);
|
|
6234
|
+
showToast(`Baked — now in the Tools library as “${id}”`, 'ok');
|
|
5516
6235
|
} catch (e) {
|
|
5517
6236
|
hideModal($bakeModal);
|
|
5518
6237
|
// The server restores the original install on failure (recoverable) → warn, not err.
|
|
5519
|
-
showToast('We couldn’t save this as
|
|
6238
|
+
showToast('We couldn’t save this as a tool because FloLess could not finish the setup. Try again.', 'warn');
|
|
5520
6239
|
}
|
|
5521
6240
|
}
|
|
5522
6241
|
|
|
@@ -5614,10 +6333,11 @@
|
|
|
5614
6333
|
for (const control of [$graftPrimary, $graftBack, $graftCancel]) control.removeAttribute('data-blocked-reason');
|
|
5615
6334
|
$graftCancel.textContent = 'Cancel';
|
|
5616
6335
|
$graftCancel.setAttribute('data-command-id', 'shell.dialog-cancel#building an agent');
|
|
6336
|
+
$graftCancel.setAttribute('data-command-instance-label', 'building a tool');
|
|
5617
6337
|
const supported = prefill && GRAFT_KINDS.some((item) => item.kind === prefill.kind)
|
|
5618
6338
|
&& typeof prefill.ref === 'string' && prefill.ref.trim();
|
|
5619
6339
|
graftState = { kind: supported ? prefill.kind : 'dlls', ref: supported ? prefill.ref : '', decompile: false, showMore: false, preview: null, stagedRef: null, verifyInFlight: false, commitInFlight: false, probe: null, focusCheckRow: false, onPrimary: runGraftIntrospect, onBack: null };
|
|
5620
|
-
document.getElementById('graft-title').textContent = 'Graft into
|
|
6340
|
+
document.getElementById('graft-title').textContent = 'Graft into tool';
|
|
5621
6341
|
document.getElementById('graft-sub').textContent = 'Choose a DLL, package, or API spec. AWARE will inspect it and prepare command descriptions for your review.';
|
|
5622
6342
|
$graftBack.disabled = false; $graftCancel.disabled = false;
|
|
5623
6343
|
graftRenderPicker();
|
|
@@ -5749,7 +6469,7 @@
|
|
|
5749
6469
|
function graftRenderPreview(preview) {
|
|
5750
6470
|
clearGraftInstructorNote();
|
|
5751
6471
|
document.getElementById('graft-title').textContent = 'Review generated commands';
|
|
5752
|
-
document.getElementById('graft-sub').textContent = 'AWARE listed commands from this source. None has been run. Create the
|
|
6472
|
+
document.getElementById('graft-sub').textContent = 'AWARE listed commands from this source. None has been run. Create the tool only if you want it in your Tools library.';
|
|
5753
6473
|
const tekla = preview.recipe === 'tekla-plugin';
|
|
5754
6474
|
const badge = tekla
|
|
5755
6475
|
? '<div class="graft-badge tekla">⊕ Tekla plug-in recipe</div>'
|
|
@@ -5772,14 +6492,14 @@
|
|
|
5772
6492
|
&& /[\\/]Tekla\.Structures\.Model\.dll$/i.test(preview.sourceRef);
|
|
5773
6493
|
const verify = modelRead
|
|
5774
6494
|
? `<div class="graft-read-review"><strong>Check one live Tekla read</strong>` +
|
|
5775
|
-
`<p id="graft-verify-help">This reads the open model name using the selected library. It does not test the generated
|
|
6495
|
+
`<p id="graft-verify-help">This reads the open model name using the selected library. It does not test the generated tool or its other commands.</p>` +
|
|
5776
6496
|
`<dl class="graft-identity"><dt>Library</dt><dd>${escapeHtml(preview.sourceRef)}</dd>` +
|
|
5777
6497
|
`<dt>Operation</dt><dd>Model.GetInfo().ModelName</dd></dl>` +
|
|
5778
6498
|
`<button type="button" class="graft-verify-button" id="graft-verify-read" data-command-id="shell.graft-verify-tekla-read" aria-describedby="graft-verify-help">Verify model read</button>` +
|
|
5779
6499
|
`<div id="graft-verify-result" role="status" aria-live="polite"></div></div>` : '';
|
|
5780
6500
|
graftFill(graftBodyEl(),
|
|
5781
6501
|
badge + hero + verify + graftConnectionHtml(preview) + warnings + cmds + skills +
|
|
5782
|
-
`<div class="modal-field"><label>
|
|
6502
|
+
`<div class="modal-field"><label>Tool name</label><div class="bake-name"><code>${escapeHtml(preview.agentId)}</code></div></div>`);
|
|
5783
6503
|
const verifyButton = document.getElementById('graft-verify-read');
|
|
5784
6504
|
verifyButton?.addEventListener('click', () => runGraftVerifyRead(preview));
|
|
5785
6505
|
wireGraftAddCheck(preview);
|
|
@@ -5791,7 +6511,7 @@
|
|
|
5791
6511
|
}
|
|
5792
6512
|
graftState.onBack = graftRenderPicker;
|
|
5793
6513
|
graftState.onPrimary = () => runGraftCommit(false);
|
|
5794
|
-
graftFooter({ backShown: true, primaryLabel: 'Create
|
|
6514
|
+
graftFooter({ backShown: true, primaryLabel: 'Create tool', primaryDisabled: preview.commands.length === 0, primaryCommand: 'shell.graft-create-agent' });
|
|
5795
6515
|
}
|
|
5796
6516
|
|
|
5797
6517
|
/** What the tool needs to connect, and its connection check (#1899). Plain words, no internals. */
|
|
@@ -5933,7 +6653,7 @@
|
|
|
5933
6653
|
receiptHost.setAttribute('role', 'status');
|
|
5934
6654
|
if (preview?.probe && window.flolessConnections) {
|
|
5935
6655
|
actions.append(window.flolessConnections.checkButton({
|
|
5936
|
-
agent: agentId, label: agentId, receiptHost, confirmHost, announce: (text) => { status.textContent = text; },
|
|
6656
|
+
commandId: 'shell.graft-connection-check', agent: agentId, label: agentId, receiptHost, confirmHost, announce: (text) => { status.textContent = text; },
|
|
5937
6657
|
}));
|
|
5938
6658
|
}
|
|
5939
6659
|
if (!actions.childElementCount && !needs.length) return null;
|
|
@@ -5998,7 +6718,7 @@
|
|
|
5998
6718
|
`<dt>Tekla host</dt><dd>${escapeHtml(proof.hostVersion)} · PID ${escapeHtml(String(proof.hostPid))}</dd>` +
|
|
5999
6719
|
`<dt>Library used</dt><dd>${escapeHtml(proof.sourcePath)}</dd>` +
|
|
6000
6720
|
`<dt>Checked</dt><dd>${escapeHtml(proof.verifiedAt)}</dd></dl>` +
|
|
6001
|
-
`<p>The generated
|
|
6721
|
+
`<p>The generated tool's commands remain unverified.</p>` +
|
|
6002
6722
|
`<button type="button" class="graft-verify-button graft-continue-chat" id="graft-continue-chat" data-command-id="shell.graft-continue-chat">Continue in AI Chat</button></div>`);
|
|
6003
6723
|
// Only the successful receipt carries this action. It hands the receipt to Chat as an
|
|
6004
6724
|
// editable, unsent draft; opening Chat never re-runs the Tekla read.
|
|
@@ -6021,6 +6741,7 @@
|
|
|
6021
6741
|
$graftBack.removeAttribute('data-blocked-reason');
|
|
6022
6742
|
$graftCancel.textContent = 'Cancel';
|
|
6023
6743
|
$graftCancel.setAttribute('data-command-id', 'shell.dialog-cancel#building an agent');
|
|
6744
|
+
$graftCancel.setAttribute('data-command-instance-label', 'building a tool');
|
|
6024
6745
|
if ($graftInstructorNote.dataset.commandId) {
|
|
6025
6746
|
const focused = document.activeElement;
|
|
6026
6747
|
if (![button, $graftCancel, $graftPrimary, $graftBack].includes(focused) || !window.Instructor?.refreshCarrier(focused)) clearGraftInstructorNote();
|
|
@@ -6062,23 +6783,23 @@
|
|
|
6062
6783
|
primaryCommand: force ? 'shell.graft-overwrite-agent' : 'shell.graft-create-agent' });
|
|
6063
6784
|
$graftBack.disabled = true; $graftCancel.disabled = true;
|
|
6064
6785
|
for (const control of [$graftPrimary, $graftBack, $graftCancel]) {
|
|
6065
|
-
control.setAttribute('data-blocked-reason', '
|
|
6786
|
+
control.setAttribute('data-blocked-reason', 'Tool creation is in progress. Wait for it to finish.');
|
|
6066
6787
|
}
|
|
6067
6788
|
const verifyButton = document.getElementById('graft-verify-read');
|
|
6068
6789
|
if (verifyButton) {
|
|
6069
6790
|
verifyButton.disabled = true;
|
|
6070
|
-
verifyButton.setAttribute('data-blocked-reason', '
|
|
6791
|
+
verifyButton.setAttribute('data-blocked-reason', 'Tool creation is in progress. Wait for it to finish.');
|
|
6071
6792
|
}
|
|
6072
6793
|
const continueButton = document.getElementById('graft-continue-chat');
|
|
6073
6794
|
if (continueButton) {
|
|
6074
6795
|
continueButton.disabled = true;
|
|
6075
|
-
continueButton.setAttribute('data-blocked-reason', '
|
|
6796
|
+
continueButton.setAttribute('data-blocked-reason', 'Tool creation is in progress. Wait for it to finish.');
|
|
6076
6797
|
}
|
|
6077
6798
|
try {
|
|
6078
6799
|
const body = { stagedRef: graftState.stagedRef };
|
|
6079
6800
|
if (force) body.force = true;
|
|
6080
6801
|
const res = await api('/api/graft/commit', { method: 'POST', body: JSON.stringify(body) });
|
|
6081
|
-
graftFill(graftBodyEl(), `<div class="graft-success"><div class="gs-icon">⊕</div><div class="gs-msg" id="graft-success-msg" tabindex="-1">
|
|
6802
|
+
graftFill(graftBodyEl(), `<div class="graft-success"><div class="gs-icon">⊕</div><div class="gs-msg" id="graft-success-msg" tabindex="-1">Tool created — now in the Tools library as <code>${escapeHtml(res.agentId)}</code>.</div></div>`);
|
|
6082
6803
|
const nextSteps = graftSuccessActions(graftState.preview, res.agentId);
|
|
6083
6804
|
if (nextSteps) graftBodyEl().append(nextSteps);
|
|
6084
6805
|
document.getElementById('graft-success-msg')?.focus();
|
|
@@ -6086,8 +6807,8 @@
|
|
|
6086
6807
|
$graftPrimary.setAttribute('data-command-id', 'shell.graft-done');
|
|
6087
6808
|
graftState.onPrimary = closeGraftModal;
|
|
6088
6809
|
loadAgentCatalog().catch(() => {}); // refresh count immediately (SSE also fires for other tabs)
|
|
6089
|
-
appendNarration(`Grafted <strong>${escapeHtml(res.agentId)}</strong> from ${escapeHtml(graftState.preview.sourceRef)} — find it in the
|
|
6090
|
-
showToast(`
|
|
6810
|
+
appendNarration(`Grafted <strong>${escapeHtml(res.agentId)}</strong> from ${escapeHtml(graftState.preview.sourceRef)} — find it in the Tools library (<strong>≡ menu → Tools</strong>).`);
|
|
6811
|
+
showToast(`Tool created — “${res.agentId}” is now in the Tools library`, 'ok');
|
|
6091
6812
|
} catch (e) {
|
|
6092
6813
|
$graftBack.disabled = false; $graftCancel.disabled = false;
|
|
6093
6814
|
const msg = (e && e.message) ? e.message : 'Create failed';
|
|
@@ -6102,9 +6823,9 @@
|
|
|
6102
6823
|
graftBodyEl().prepend(warn);
|
|
6103
6824
|
}
|
|
6104
6825
|
} else {
|
|
6105
|
-
graftFooter({ backShown: true, primaryLabel: 'Create
|
|
6826
|
+
graftFooter({ backShown: true, primaryLabel: 'Create tool', primaryDisabled: false, primaryCommand: 'shell.graft-create-agent' });
|
|
6106
6827
|
graftState.onPrimary = () => runGraftCommit(false);
|
|
6107
|
-
showToast('We couldn’t create this
|
|
6828
|
+
showToast('We couldn’t create this tool because FloLess could not finish the setup. Try again.', 'warn');
|
|
6108
6829
|
}
|
|
6109
6830
|
} finally {
|
|
6110
6831
|
state.commitInFlight = false;
|
|
@@ -6272,7 +6993,7 @@
|
|
|
6272
6993
|
if (!el) return;
|
|
6273
6994
|
el.className = `import-failed-agent-status is-${state}`;
|
|
6274
6995
|
el.textContent = state === 'updated' ? `✓ Updated to v${detail}`
|
|
6275
|
-
: state === 'current' ? 'Nothing to update — already the latest version. This
|
|
6996
|
+
: state === 'current' ? 'Nothing to update — already the latest version. This tool hasn’t been released as runnable yet.'
|
|
6276
6997
|
// We captured no "before" version, so we cannot honestly claim a change happened. Report what
|
|
6277
6998
|
// AWARE now has and say nothing we do not know.
|
|
6278
6999
|
: state === 'done' ? `AWARE finished — it reports v${detail || '?'} installed.`
|
|
@@ -6321,9 +7042,9 @@
|
|
|
6321
7042
|
// (the case in #314), versus one upstream has genuinely not shipped a runnable build for yet.
|
|
6322
7043
|
// Promising a fix that then changes nothing is worse than the honest "we don't know" tier.
|
|
6323
7044
|
$sub.textContent = agents.length === 1
|
|
6324
|
-
? `This workflow needs the ${named}
|
|
6325
|
-
+ ' Updating usually fixes it. If there is nothing to update, that
|
|
6326
|
-
: `This workflow needs ${agents.length}
|
|
7045
|
+
? `This workflow needs the ${named} tool, which isn’t runnable yet on this machine.`
|
|
7046
|
+
+ ' Updating usually fixes it. If there is nothing to update, that tool hasn’t been released yet — this workflow can’t run here until it is.'
|
|
7047
|
+
: `This workflow needs ${agents.length} tools that aren’t runnable yet on this machine: ${named}.`
|
|
6327
7048
|
+ ' Updating usually fixes it. Any that report nothing to update haven’t been released yet — this workflow can’t run here until they are.';
|
|
6328
7049
|
$rows.append(...agents.map(importFailedCmdRow)); // one command per agent, never a guessed multi-agent form
|
|
6329
7050
|
// ONE retry offer for the whole dialog, not one per row: "retry THE import" is singular, and N
|
|
@@ -8005,6 +8726,11 @@
|
|
|
8005
8726
|
} else {
|
|
8006
8727
|
// A failed run is an expected, recoverable outcome (the server returns it
|
|
8007
8728
|
// in-band) — surface it as a toast + narration, not a console error.
|
|
8729
|
+
// (#1996 E2E: `msg` was never defined here, so every refused run threw a ReferenceError and the
|
|
8730
|
+
// person saw nothing — the node stayed "running".)
|
|
8731
|
+
const msg = e && e.message ? e.message : String(e);
|
|
8732
|
+
// #1998: AWARE refused before anything started (an approval it will not run): no node is "running".
|
|
8733
|
+
if (e && e.body && e.body.refusal) clearNodeStatus();
|
|
8008
8734
|
showToast((simulate ? 'Simulate failed' : 'Run failed') + ': ' + runFailureMessage(msg), 'warn');
|
|
8009
8735
|
appendNarration(simulate
|
|
8010
8736
|
? `Simulate couldn't validate <code>${escapeHtml(currentId)}</code> — it stubs each node from its output-schema, but exec nodes have none, so the cross-node templates render undefined. Use <strong>▶ Run workflow</strong> for a live run against the host.`
|
|
@@ -8076,7 +8802,7 @@
|
|
|
8076
8802
|
let lvl = 'info';
|
|
8077
8803
|
let msg;
|
|
8078
8804
|
switch (ev.kind) {
|
|
8079
|
-
case 'run-start': msg = `run start · ${escapeHtml(ev.app || '')} (${escapeHtml(ev.instance || 'default')})`; break;
|
|
8805
|
+
case 'run-start': msg = `run start · ${escapeHtml(ev.app || '')} (${escapeHtml(ev.instance || 'default')})${runStartApprovalNote(ev)}`; break;
|
|
8080
8806
|
case 'node-start': lvl = 'event'; msg = `node ${node} · ${agent}${cmd}`; break;
|
|
8081
8807
|
case 'would-write': lvl = 'warn'; msg = `would-write ${node} · ${escapeHtml(JSON.stringify(ev.proposed_inputs || {}))}`; break;
|
|
8082
8808
|
case 'node-output': case 'output': case 'write': lvl = 'ok'; msg = `${escapeHtml(ev.kind)} ${node}`.trim(); break;
|
|
@@ -8746,6 +9472,9 @@
|
|
|
8746
9472
|
state.hasRun = true;
|
|
8747
9473
|
} else if (m.type === 'templates-changed') {
|
|
8748
9474
|
loadTemplates().catch(() => {});
|
|
9475
|
+
} else if (m.type === 'tool-updates-changed') {
|
|
9476
|
+
// #1997: relayed for tool-updates.js (the footer pill + Approve updated workflows), its only listener.
|
|
9477
|
+
window.dispatchEvent(new CustomEvent('floless:tool-updates-changed', { detail: m }));
|
|
8749
9478
|
} else if (m.type === 'apps-changed') {
|
|
8750
9479
|
// A workflow was imported (here or in another tab) → refresh the picker (#66).
|
|
8751
9480
|
loadApps().catch(() => {});
|
|
@@ -8854,6 +9583,7 @@
|
|
|
8854
9583
|
runningRoutines.delete(m.id);
|
|
8855
9584
|
loadRoutinesData();
|
|
8856
9585
|
if (window.flolessPanels) window.flolessPanels.refreshData(); // routine runs also refresh bindings
|
|
9586
|
+
window.flolessAgents?.refreshRuns?.(); // #2035: an open agent page shows the run its routine just started
|
|
8857
9587
|
} else if (m.type === 'trigger-session-changed') {
|
|
8858
9588
|
// A foreground live-run session (▶ Run on a streaming app) shares this SSE
|
|
8859
9589
|
// event with background routines; its server-namespaced id routes it to the
|
|
@@ -8897,7 +9627,10 @@
|
|
|
8897
9627
|
// apps-changed handler already refreshes the picker, and reloading a gone id
|
|
8898
9628
|
// would 404. dropClientAppState() removes it from `apps` before this fires.
|
|
8899
9629
|
if (!currentId || !apps.has(currentId)) return;
|
|
8900
|
-
|
|
9630
|
+
// #1890 PR 3b-0: an owned workflow's installed copy can vanish (uninstalled outside FloLess); the refresh
|
|
9631
|
+
// decides — reloading it if still installed, its recovery view if not — so a gone copy is never fetched.
|
|
9632
|
+
if (ownedWorkflowOf(currentId)) loadApps().catch(reportErr);
|
|
9633
|
+
else loadApp(currentId).catch(reportErr);
|
|
8901
9634
|
}, 250);
|
|
8902
9635
|
} else if (m.type === 'seat-taken') {
|
|
8903
9636
|
// This session's seat was lost. m.reason (normalized server-side) says why — only a
|
|
@@ -10683,6 +11416,123 @@
|
|
|
10683
11416
|
*/
|
|
10684
11417
|
const AUDIT_OWNER_ORDER = { user: 0, reader: 1, server: 2, none: 3, unknown: 4 };
|
|
10685
11418
|
|
|
11419
|
+
/**
|
|
11420
|
+
* #1874 — a drawing read whose discard record cannot be read. It used to vanish from Requests; now it
|
|
11421
|
+
* stays, every ordinary action is withheld (the server stamps them off), and the person decides here.
|
|
11422
|
+
* Keep is the primary choice because it can be undone; Discard asks once more before it removes
|
|
11423
|
+
* anything. A Discard that was cut short is only offered as "finish": part of the read may be gone.
|
|
11424
|
+
*/
|
|
11425
|
+
function requestHasDiscardQuestion(r) {
|
|
11426
|
+
return !!r && r.type === 'revision-read' && !!r.discardRecordUnreadable;
|
|
11427
|
+
}
|
|
11428
|
+
|
|
11429
|
+
function discardRecordQuestionHtml(r, commandInstance) {
|
|
11430
|
+
if (!requestHasDiscardQuestion(r)) return '';
|
|
11431
|
+
const id = escapeAttr(r.id);
|
|
11432
|
+
const leadId = `req-discard-q-${id}`;
|
|
11433
|
+
const finishing = r.discardRecordRecovery?.choice === 'discarding';
|
|
11434
|
+
const lead = finishing
|
|
11435
|
+
? 'FloLess was part-way through discarding this read.'
|
|
11436
|
+
: 'We couldn’t tell if this read was discarded.';
|
|
11437
|
+
const body = finishing
|
|
11438
|
+
? 'You chose to discard it and some of its files may already be gone, so it can’t be carried on. Finish discarding it.'
|
|
11439
|
+
: (r.discardRecordUnreadable.kind === 'unopenable'
|
|
11440
|
+
? 'FloLess couldn’t open its discard record, so it left the read as it is. It checks again whenever Requests refreshes.'
|
|
11441
|
+
: 'Its discard record is damaged, so FloLess left the read as it is.')
|
|
11442
|
+
+ ' Keep it to carry on where you left off, or discard it if you’d already thrown it away.';
|
|
11443
|
+
// The step lives outside the DOM: the list repaints on every poll, and a confirmation or a request in
|
|
11444
|
+
// flight must survive that rather than silently snapping back to the first question.
|
|
11445
|
+
const ui = discardRecordUi.get(r.id) || {};
|
|
11446
|
+
const busy = ui.step === 'keeping' || ui.step === 'discarding';
|
|
11447
|
+
// Shared tail of every button: who it names for Instructor, and its busy state.
|
|
11448
|
+
const rest = (kind) => `data-id="${id}" data-command-instance-label="${escapeAttr(commandInstance)}"${busy ? ' disabled' : ''}${busy && ui.pressed === kind ? ' aria-busy="true"' : ''}`;
|
|
11449
|
+
const confirming = ui.step === 'confirm' || ui.step === 'discarding';
|
|
11450
|
+
const actions = confirming
|
|
11451
|
+
? `<button type="button" class="req-chat-action" data-discard-record="cancel" data-command-id="shell.requests-discard-record-cancel#${escapeAttr(r.id)}" ${rest('cancel')}>Cancel</button>`
|
|
11452
|
+
+ `<button type="button" class="req-chat-action danger" data-discard-record="discard" data-command-id="shell.requests-discard-record-confirm#${escapeAttr(r.id)}" ${rest('discard')}>${ui.step === 'discarding' ? 'Discarding…' : 'Discard for good'}</button>`
|
|
11453
|
+
: (finishing ? '' : `<button type="button" class="req-chat-action primary" data-discard-record="keep" data-command-id="shell.requests-discard-record-keep#${escapeAttr(r.id)}" data-tip="Carry on with this read. The unreadable record is kept for diagnosis, not deleted." ${rest('keep')}>${ui.step === 'keeping' ? 'Keeping…' : 'Keep this read'}</button>`)
|
|
11454
|
+
+ `<button type="button" class="req-chat-action" data-discard-record="ask" data-command-id="shell.requests-discard-record-discard#${escapeAttr(r.id)}" data-tip="Remove this read and its working files" ${rest('ask')}>${finishing ? 'Finish discarding' : 'Discard…'}</button>`;
|
|
11455
|
+
const status = ui.status || (confirming ? 'Discard this read for good? This can’t be undone.' : '');
|
|
11456
|
+
return `<div class="req-discard-q" role="group" aria-labelledby="${leadId}">
|
|
11457
|
+
<p class="req-discard-q-lead" id="${leadId}">${escapeHtml(lead)}</p>
|
|
11458
|
+
<p class="req-discard-q-body">${escapeHtml(body)}</p>
|
|
11459
|
+
<div class="req-discard-q-actions">${actions}</div>
|
|
11460
|
+
<p class="req-discard-q-status" role="status" aria-live="polite">${escapeHtml(status)}</p>
|
|
11461
|
+
</div>`;
|
|
11462
|
+
}
|
|
11463
|
+
|
|
11464
|
+
function discardRecordKeptNoteHtml(r) {
|
|
11465
|
+
const recovery = r && r.type === 'revision-read' && !requestHasDiscardQuestion(r) ? r.discardRecordRecovery : null;
|
|
11466
|
+
if (!recovery || recovery.choice !== 'kept') return '';
|
|
11467
|
+
const missing = Number(recovery.missingAttachments) || 0;
|
|
11468
|
+
const extra = missing ? ` ${missing === 1 ? '1 attached drawing was' : `${missing} attached drawings were`} already missing.` : '';
|
|
11469
|
+
return `<p class="req-discard-kept">Kept after its discard record couldn’t be read.${escapeHtml(extra)}</p>`;
|
|
11470
|
+
}
|
|
11471
|
+
|
|
11472
|
+
/** Per-read step of the question above: `confirm`, `keeping`, `discarding`, plus a failure sentence. */
|
|
11473
|
+
const discardRecordUi = new Map();
|
|
11474
|
+
|
|
11475
|
+
function focusDiscardRecordControl(id, kind) {
|
|
11476
|
+
const el = document.querySelector(`#requests-list [data-discard-record="${kind}"][data-id="${CSS.escape(id)}"]`);
|
|
11477
|
+
if (el) el.focus();
|
|
11478
|
+
return !!el;
|
|
11479
|
+
}
|
|
11480
|
+
|
|
11481
|
+
async function sendDiscardRecordChoice(id, choice) {
|
|
11482
|
+
discardRecordUi.set(id, { step: choice === 'keep' ? 'keeping' : 'discarding', pressed: choice === 'keep' ? 'keep' : 'discard' });
|
|
11483
|
+
renderRequests();
|
|
11484
|
+
let said;
|
|
11485
|
+
try {
|
|
11486
|
+
const res = await api(`/api/requests/${encodeURIComponent(id)}/discard-record`, {
|
|
11487
|
+
method: 'POST', body: JSON.stringify({ choice }),
|
|
11488
|
+
});
|
|
11489
|
+
said = res?.outcome === 'kept' ? 'Read kept.'
|
|
11490
|
+
: res?.outcome === 'discarded' ? 'Read discarded.'
|
|
11491
|
+
: res?.outcome === 'already-discarded' ? 'Its discard record could be read again: this read had been discarded.'
|
|
11492
|
+
: 'Its discard record could be read again, so there was nothing to decide.';
|
|
11493
|
+
discardRecordUi.delete(id);
|
|
11494
|
+
} catch (error) {
|
|
11495
|
+
discardRecordUi.set(id, { status: error?.message || 'That didn’t work. Try again.' });
|
|
11496
|
+
await loadRequests().catch(() => {});
|
|
11497
|
+
renderRequests();
|
|
11498
|
+
focusDiscardRecordControl(id, choice === 'keep' ? 'keep' : 'ask');
|
|
11499
|
+
return;
|
|
11500
|
+
}
|
|
11501
|
+
await loadRequests().catch(() => {});
|
|
11502
|
+
renderRequests();
|
|
11503
|
+
const actionStatus = document.getElementById('requests-action-status');
|
|
11504
|
+
if (actionStatus) actionStatus.textContent = said;
|
|
11505
|
+
// The question is gone either way; land focus on the kept row, or on the list, never on <body>.
|
|
11506
|
+
const row = document.querySelector(`#requests-list .req-item[data-id="${CSS.escape(id)}"]`);
|
|
11507
|
+
const target = row || document.getElementById('requests-list');
|
|
11508
|
+
if (target) {
|
|
11509
|
+
if (!target.hasAttribute('tabindex')) target.setAttribute('tabindex', '-1');
|
|
11510
|
+
target.focus();
|
|
11511
|
+
}
|
|
11512
|
+
}
|
|
11513
|
+
|
|
11514
|
+
function wireDiscardRecordQuestions($list) {
|
|
11515
|
+
$list.querySelectorAll('[data-discard-record]').forEach((button) => {
|
|
11516
|
+
const id = button.dataset.id;
|
|
11517
|
+
const kind = button.dataset.discardRecord;
|
|
11518
|
+
button.onclick = () => {
|
|
11519
|
+
if (kind === 'keep') return void sendDiscardRecordChoice(id, 'keep');
|
|
11520
|
+
if (kind === 'discard') return void sendDiscardRecordChoice(id, 'discard');
|
|
11521
|
+
if (kind === 'ask') {
|
|
11522
|
+
// A second, explicit step: Discard removes the read for good. Cancel takes focus so Enter is safe.
|
|
11523
|
+
discardRecordUi.set(id, { step: 'confirm' });
|
|
11524
|
+
renderRequests();
|
|
11525
|
+
focusDiscardRecordControl(id, 'cancel');
|
|
11526
|
+
return undefined;
|
|
11527
|
+
}
|
|
11528
|
+
discardRecordUi.delete(id);
|
|
11529
|
+
renderRequests();
|
|
11530
|
+
focusDiscardRecordControl(id, 'ask');
|
|
11531
|
+
return undefined;
|
|
11532
|
+
};
|
|
11533
|
+
});
|
|
11534
|
+
}
|
|
11535
|
+
|
|
10686
11536
|
function auditRefusalHtml(r) {
|
|
10687
11537
|
const retry = r && r.auditRetry;
|
|
10688
11538
|
if (!retry || !Object.prototype.hasOwnProperty.call(AUDIT_REFUSAL_LEAD, retry.code)) return '';
|
|
@@ -10735,6 +11585,8 @@
|
|
|
10735
11585
|
/** One exact next step above the request rows; automatic start is offered only when policy allows it. */
|
|
10736
11586
|
function drawingRequestGuidance(r) {
|
|
10737
11587
|
if (!r) return '';
|
|
11588
|
+
// #1874: the row's own question is the only next step; "copy this request" would contradict it.
|
|
11589
|
+
if (requestHasDiscardQuestion(r)) return '';
|
|
10738
11590
|
if (r.status && r.status !== 'pending') return '';
|
|
10739
11591
|
if (r.preparationState === 'blocked') {
|
|
10740
11592
|
return 'FloLess could not finish drawing preparation. Restart FloLess; if this remains blocked, open the detailed instructions in Requests. Your drawings are still attached. Do not retry, copy, clear, or attach them again.';
|
|
@@ -11179,6 +12031,8 @@
|
|
|
11179
12031
|
// ✕ goes away while a run is live, for the same reason it goes away on a knowledge-organize:
|
|
11180
12032
|
// deleting the request out from under a working agent leaves it unable to clear its own work,
|
|
11181
12033
|
// and the run then lands in `exited-unresolved` for a reason the user caused and cannot see.
|
|
12034
|
+
// #1874: a read nobody can say is discarded or not offers only Keep / Discard, in its own block.
|
|
12035
|
+
const discardQuestion = requestHasDiscardQuestion(r);
|
|
11182
12036
|
const del = lifecycleOwned
|
|
11183
12037
|
? '<span class="req-lifecycle" data-tip="This clears itself when your terminal AI finishes or fails the organize">finishing in your terminal</span>'
|
|
11184
12038
|
: inFlight || desktopClaimed
|
|
@@ -11212,14 +12066,14 @@
|
|
|
11212
12066
|
const inChatScope = hasChatOwner && requestMatchesChatScope(r);
|
|
11213
12067
|
const chatLabel = `${label}${owner ? ` for ${owner}` : ''}`;
|
|
11214
12068
|
const hasLinkedChat = Boolean(r.chatConversation?.chatId);
|
|
11215
|
-
const discussBtn = chatProvider && inChatScope
|
|
12069
|
+
const discussBtn = chatProvider && inChatScope && !discardQuestion
|
|
11216
12070
|
? `<button class="req-chat-action" data-request-chat="discuss" data-id="${escapeAttr(r.id)}" data-command-id="shell.requests-discuss#${escapeAttr(r.id)}" data-command-instance-label="${escapeAttr(commandInstance)}" aria-label="${hasLinkedChat ? 'Open' : 'Discuss'} ${escapeAttr(chatLabel)} in AI Chat" data-tip="${hasLinkedChat ? 'Open the linked conversation in AI Chat' : 'Open this request in AI Chat without starting the AI'}">${hasLinkedChat ? 'Open AI Chat' : 'Discuss in AI Chat'}</button>`
|
|
11217
12071
|
: '';
|
|
11218
12072
|
const starting = requestChatStarts.get(r.id)?.label;
|
|
11219
12073
|
const startChatBtn = chatProvider && inChatScope && canRunNow && !filterGuide
|
|
11220
12074
|
? `<button class="req-chat-action primary" data-request-chat="start" data-id="${escapeAttr(r.id)}" data-command-id="shell.requests-start-chat#${escapeAttr(r.id)}" data-command-instance-label="${escapeAttr(commandInstance)}" aria-label="Start ${escapeAttr(chatLabel)} in AI Chat" data-tip="Start this request in AI Chat and continue there"${starting ? ' disabled aria-busy="true"' : ''}>${escapeHtml(starting || 'Start in AI Chat')}</button>`
|
|
11221
12075
|
: '';
|
|
11222
|
-
const chatMeta = chatProvider && inChatScope
|
|
12076
|
+
const chatMeta = discardQuestion ? '' : chatProvider && inChatScope
|
|
11223
12077
|
? `<span class="req-chat-meta">AI Chat · ${escapeHtml(runtimeLabel(chatProvider))} · ${r.type === 'guide' || (r.type === 'tweak-contract' && r.mode === 'query') ? 'Read only' : 'Working folder write'}</span>`
|
|
11224
12078
|
: chatProvider && hasChatOwner
|
|
11225
12079
|
? `<span class="req-chat-elsewhere" data-tip="Open ${escapeAttr(owner)} to discuss or start this request in AI Chat">Open ${escapeHtml(owner)} for AI Chat</span>`
|
|
@@ -11237,14 +12091,16 @@
|
|
|
11237
12091
|
${runStatusHtml(run, resumeCommand, desktopHandoffs, r.id, commandInstance, ownRecoverySurface,
|
|
11238
12092
|
filterGuide
|
|
11239
12093
|
? (r.instructorContext.commandId === 'filter.ask-ai-change' ? 'change' : 'question') : null, r.filterAiNotStarted === true)}
|
|
11240
|
-
${r.status === 'pending' && !revisionReadHasTerminalOwner(r) && !r.canRun && r.runWhy && (anyRunnable || r.type === 'revision-read') ? `<div class="req-why-not">Why there is no automatic start: ${escapeHtml(r.runWhy)}</div>` : ''}
|
|
12094
|
+
${!discardQuestion && r.status === 'pending' && !revisionReadHasTerminalOwner(r) && !r.canRun && r.runWhy && (anyRunnable || r.type === 'revision-read') ? `<div class="req-why-not">Why there is no automatic start: ${escapeHtml(r.runWhy)}</div>` : ''}
|
|
11241
12095
|
${auditRefusalHtml(r)}
|
|
12096
|
+
${discardRecordQuestionHtml(r, commandInstance)}
|
|
12097
|
+
${discardRecordKeptNoteHtml(r)}
|
|
11242
12098
|
</div>
|
|
11243
12099
|
<div class="req-actions">${chatMeta}
|
|
11244
12100
|
${discussBtn}
|
|
11245
12101
|
${runBtn}
|
|
11246
12102
|
${desktopHandoffs || resumeCommand || !requestCanCopy(r) ? '' : `<button class="req-copy" data-id="${escapeAttr(r.id)}" data-command-id="shell.requests-copy#${escapeAttr(r.id)}" data-command-instance-label="${escapeAttr(commandInstance)}" data-tip="${r.preparationRetryable ? 'Copy this retry request for your terminal AI' : 'Copy this request for your terminal AI'}" aria-label="${r.preparationRetryable ? 'Copy retry request' : 'Copy this request for your terminal AI'}">⧉</button>`}
|
|
11247
|
-
${del.replace('<button class="req-del"', '<button aria-label="Clear this request" class="req-del"')}
|
|
12103
|
+
${discardQuestion ? '' : del.replace('<button class="req-del"', '<button aria-label="Clear this request" class="req-del"')}
|
|
11248
12104
|
${startChatBtn}
|
|
11249
12105
|
</div>
|
|
11250
12106
|
</div>`;
|
|
@@ -11451,6 +12307,7 @@
|
|
|
11451
12307
|
};
|
|
11452
12308
|
});
|
|
11453
12309
|
$list.querySelectorAll('.req-del').forEach((b) => { b.onclick = () => deleteOneRequest(b.dataset.id); });
|
|
12310
|
+
wireDiscardRecordQuestions($list);
|
|
11454
12311
|
$list.querySelectorAll('.req-thumb').forEach((b) => {
|
|
11455
12312
|
b.onclick = () => window.open(`/api/requests/${encodeURIComponent(b.dataset.id)}/snapshot/${b.dataset.n}`, '_blank');
|
|
11456
12313
|
});
|
|
@@ -11682,12 +12539,28 @@
|
|
|
11682
12539
|
refreshAgentNotes();
|
|
11683
12540
|
}
|
|
11684
12541
|
|
|
11685
|
-
|
|
12542
|
+
// `focusId` (a connection check's "Update" offer, #1986): open on top of the dialog that asked, showing just that
|
|
12543
|
+
// tool on the Installed tab, where its own Update button lives — the update itself stays the library's.
|
|
12544
|
+
// `{ tab: 'available' }` (the Guide's install suggestion, #2046): the tool is not installed yet, so show it on the
|
|
12545
|
+
// Available tab, where its Install button lives — the install itself stays the library's.
|
|
12546
|
+
let libOpener = null; // the offer button that opened the library on top of its dialog, to return focus to
|
|
12547
|
+
openLibrary = function openLibraryReal(focusId, opts) {
|
|
12548
|
+
const focus = typeof focusId === 'string' ? focusId : '';
|
|
12549
|
+
const toAvailable = !!focus && opts?.tab === 'available';
|
|
12550
|
+
$libModal.classList.toggle('lib-front', !!focus);
|
|
12551
|
+
libOpener = focus ? document.activeElement : null;
|
|
11686
12552
|
$libSearch.value = '';
|
|
11687
|
-
if ($libAvailSearch) $libAvailSearch.value = '';
|
|
11688
|
-
switchLibTab('installed'); //
|
|
12553
|
+
if ($libAvailSearch) $libAvailSearch.value = toAvailable ? focus : '';
|
|
12554
|
+
switchLibTab(toAvailable ? 'available' : 'installed'); // Installed is the primary job, unless asked otherwise
|
|
12555
|
+
if (!toAvailable) $libSearch.value = focus;
|
|
11689
12556
|
renderLibrary();
|
|
11690
12557
|
$libModal.classList.add('show');
|
|
12558
|
+
// Focus moves into the library NOW (not on the tab switch's next tick), so even an immediate Escape lands on the
|
|
12559
|
+
// library's own handler instead of the dialog underneath.
|
|
12560
|
+
// Focus moves to the open tab's search. On Available, an AWARE too old to list tools hides that search: renderAvailable
|
|
12561
|
+
// then hands focus on to its "Update AWARE" button, whether it knew that already or learns it when the reply lands.
|
|
12562
|
+
if (focus) (toAvailable && $libAvailSearch ? $libAvailSearch : $libSearch).focus();
|
|
12563
|
+
if (toAvailable && $libAvailSearch?.hidden) availableFocusFallback();
|
|
11691
12564
|
if (!agentCatalog.length) loadAgentCatalog().then(renderLibrary).catch(reportErr);
|
|
11692
12565
|
// Load the registry catalog too, so the Installed tab can flag outdated agents
|
|
11693
12566
|
// with an "Update" button (and the Available tab is instant when switched to).
|
|
@@ -11697,6 +12570,23 @@
|
|
|
11697
12570
|
});
|
|
11698
12571
|
};
|
|
11699
12572
|
|
|
12573
|
+
// Opened on top of another dialog: Escape closes ONLY the library (the document-level Escape handlers would also
|
|
12574
|
+
// close Integrations), and focus goes back to the button that opened it.
|
|
12575
|
+
const closeFrontLibrary = () => {
|
|
12576
|
+
$libModal.classList.remove('show', 'lib-front');
|
|
12577
|
+
const opener = libOpener;
|
|
12578
|
+
libOpener = null;
|
|
12579
|
+
if (opener && opener.isConnected && typeof opener.focus === 'function') opener.focus();
|
|
12580
|
+
};
|
|
12581
|
+
$libModal.addEventListener('keydown', (e) => {
|
|
12582
|
+
if (e.key !== 'Escape' || !$libModal.classList.contains('lib-front')) return;
|
|
12583
|
+
e.stopPropagation();
|
|
12584
|
+
closeFrontLibrary();
|
|
12585
|
+
});
|
|
12586
|
+
document.getElementById('lib-close')?.addEventListener('click', () => {
|
|
12587
|
+
if ($libModal.classList.contains('lib-front')) closeFrontLibrary();
|
|
12588
|
+
});
|
|
12589
|
+
|
|
11700
12590
|
// Compare two dotted version strings numerically, segment by segment (missing
|
|
11701
12591
|
// segments = 0). Returns 1 if a>b, -1 if a<b, 0 if equal — so the Installed tab
|
|
11702
12592
|
// only offers an "Update" when the registry is STRICTLY ahead (never a downgrade).
|
|
@@ -11756,7 +12646,7 @@
|
|
|
11756
12646
|
<div class="lib-item">
|
|
11757
12647
|
<div class="info">
|
|
11758
12648
|
<div class="name">${escapeHtml(a.id)}</div>
|
|
11759
|
-
<div class="meta"><span class="lib-ver">v${escapeHtml(String(a.version))}</span> ${escapeHtml(a.kind || '
|
|
12649
|
+
<div class="meta"><span class="lib-ver">v${escapeHtml(String(a.version))}</span> ${escapeHtml(a.kind || 'tool')} · ${a.commands} command${a.commands === 1 ? '' : 's'} · ${a.skills} skill${a.skills === 1 ? '' : 's'}</div>
|
|
11760
12650
|
</div>
|
|
11761
12651
|
<div class="lib-actions">
|
|
11762
12652
|
${updateBtn}
|
|
@@ -11766,7 +12656,7 @@
|
|
|
11766
12656
|
${failureHtml}
|
|
11767
12657
|
<div class="lib-commands" id="cmds-${id}" hidden></div>
|
|
11768
12658
|
</div>`;
|
|
11769
|
-
}).join('') || '<div class="empty-state">No
|
|
12659
|
+
}).join('') || '<div class="empty-state">No tools match.</div>';
|
|
11770
12660
|
$libList.querySelectorAll('[data-expand]').forEach((btn) => {
|
|
11771
12661
|
btn.onclick = () => expandAgent(btn.dataset.expand);
|
|
11772
12662
|
});
|
|
@@ -11886,27 +12776,35 @@
|
|
|
11886
12776
|
</div>`;
|
|
11887
12777
|
}
|
|
11888
12778
|
|
|
12779
|
+
// The Available search can be hidden while it holds focus (#2049): focus then goes to a visible control in the same
|
|
12780
|
+
// tab, so it never sits on a hidden input outside the library's own Escape handling.
|
|
12781
|
+
function availableFocusFallback() {
|
|
12782
|
+
(document.getElementById('lib-avail-update') || $libTabs.querySelector('[data-libtab="available"]'))?.focus();
|
|
12783
|
+
}
|
|
12784
|
+
|
|
11889
12785
|
function renderAvailable() {
|
|
11890
12786
|
// Degradation (i): CLI predates `agent catalog` entirely — hide search, show notice.
|
|
11891
12787
|
if (availableUnsupported) {
|
|
12788
|
+
const searchHadFocus = document.activeElement === $libAvailSearch;
|
|
11892
12789
|
$libAvailSearch.hidden = true;
|
|
11893
12790
|
$libAvailList.innerHTML =
|
|
11894
|
-
'<div class="empty-state">Browsing available
|
|
12791
|
+
'<div class="empty-state">Browsing available tools needs AWARE 0.54 or later.' +
|
|
11895
12792
|
'<br><button class="lib-update-link" id="lib-avail-update">Update AWARE →</button></div>';
|
|
11896
12793
|
const up = document.getElementById('lib-avail-update');
|
|
11897
12794
|
if (up) up.onclick = () => {
|
|
11898
12795
|
hideModal($libModal);
|
|
11899
12796
|
const pill = document.getElementById('aware-update');
|
|
11900
12797
|
if (pill && !pill.hidden) pill.click();
|
|
11901
|
-
else showToast('Update AWARE (@aware-aeco/cli) to 0.54+ to browse available
|
|
12798
|
+
else showToast('Update AWARE (@aware-aeco/cli) to 0.54+ to browse available tools', 'info');
|
|
11902
12799
|
};
|
|
11903
12800
|
$libAvailCount.textContent = '';
|
|
12801
|
+
if (searchHadFocus) availableFocusFallback();
|
|
11904
12802
|
return;
|
|
11905
12803
|
}
|
|
11906
12804
|
$libAvailSearch.hidden = false;
|
|
11907
12805
|
|
|
11908
12806
|
if (!availableLoaded) {
|
|
11909
|
-
$libAvailList.innerHTML = '<div class="empty-state"><span class="rtn-spinner"></span> Loading available
|
|
12807
|
+
$libAvailList.innerHTML = '<div class="empty-state"><span class="rtn-spinner"></span> Loading available tools…</div>';
|
|
11910
12808
|
$libAvailCount.textContent = '';
|
|
11911
12809
|
return;
|
|
11912
12810
|
}
|
|
@@ -11921,10 +12819,10 @@
|
|
|
11921
12819
|
|| (a.vendor || '').toLowerCase().includes(q)
|
|
11922
12820
|
|| (a.keywords || []).some((k) => k.toLowerCase().includes(q));
|
|
11923
12821
|
const items = notInstalled.filter(match);
|
|
11924
|
-
$libAvailCount.textContent = `${items.length}
|
|
12822
|
+
$libAvailCount.textContent = `${items.length} tool${items.length === 1 ? '' : 's'}`;
|
|
11925
12823
|
|
|
11926
12824
|
if (!items.length) {
|
|
11927
|
-
$libAvailList.innerHTML = '<div class="empty-state">No
|
|
12825
|
+
$libAvailList.innerHTML = '<div class="empty-state">No tools match.</div>';
|
|
11928
12826
|
return;
|
|
11929
12827
|
}
|
|
11930
12828
|
|
|
@@ -12022,7 +12920,7 @@
|
|
|
12022
12920
|
loadAvailableAgents()
|
|
12023
12921
|
.then(() => { if (onLoaded) onLoaded(); })
|
|
12024
12922
|
.catch((e) => {
|
|
12025
|
-
$libAvailList.innerHTML = '<div class="empty-state">Could not load available
|
|
12923
|
+
$libAvailList.innerHTML = '<div class="empty-state">Could not load available tools.</div>';
|
|
12026
12924
|
$libAvailCount.textContent = '';
|
|
12027
12925
|
reportErr(e);
|
|
12028
12926
|
})
|
|
@@ -12487,6 +13385,31 @@
|
|
|
12487
13385
|
}).observe($integrationsList);
|
|
12488
13386
|
}
|
|
12489
13387
|
|
|
13388
|
+
/**
|
|
13389
|
+
* The xeoRVT card's sentence for its state. On "Needs setup" it is the server's setup remedy when there
|
|
13390
|
+
* is one (#1965 review) — what the person can fix, the same sentence the Workspace card shows — and
|
|
13391
|
+
* otherwise the safe line for the setup category the server named.
|
|
13392
|
+
*/
|
|
13393
|
+
function revitIntegrationDetail(i) {
|
|
13394
|
+
const setupDetails = {
|
|
13395
|
+
'aware-unavailable': 'FloLess couldn’t start the service used by Revit projects.',
|
|
13396
|
+
'core-workflow-provisioning': 'FloLess couldn’t prepare the built-in Workspace workflows.',
|
|
13397
|
+
'reader-verification': 'FloLess couldn’t verify the installed Revit reader.',
|
|
13398
|
+
'workspace-bootstrap': 'FloLess couldn’t prepare the Workspace connection used by Revit workflows.',
|
|
13399
|
+
'revit-workflow-provisioning': 'FloLess couldn’t prepare the Revit project workflows.',
|
|
13400
|
+
'reader-release-unavailable': 'FloLess can’t set up Revit because the required reader version is unavailable. Report this issue, then try setup again after FloLess restores it.',
|
|
13401
|
+
unknown: 'FloLess couldn’t finish Revit setup.',
|
|
13402
|
+
};
|
|
13403
|
+
if (i.status === 'ready') return 'Open your Revit projects and use their model data in FloLess workflows.';
|
|
13404
|
+
if (i.status === 'needs-attention') {
|
|
13405
|
+
const setupRemedy = typeof i.setup?.setupRemedy === 'string' ? i.setup.setupRemedy.trim() : '';
|
|
13406
|
+
return setupRemedy || setupDetails[i.setup && i.setup.category] || setupDetails.unknown;
|
|
13407
|
+
}
|
|
13408
|
+
if (i.status === 'account-selection-required') return 'Choose the FloLess account you want to use before opening Revit projects.';
|
|
13409
|
+
if (i.status === 'check-unavailable') return 'FloLess couldn’t check Revit access. Check your connection and try again.';
|
|
13410
|
+
return 'Revit Parser is not included for this account. Ask the account owner to enable it.';
|
|
13411
|
+
}
|
|
13412
|
+
|
|
12490
13413
|
renderIntegrations = function renderIntegrationsReal() {
|
|
12491
13414
|
if (integrationsLoadState === 'loading' || integrationsLoadState === 'idle') {
|
|
12492
13415
|
$integrationsList.innerHTML = '<div class="empty-state">Checking integrations…</div>';
|
|
@@ -12508,26 +13431,9 @@
|
|
|
12508
13431
|
const needsAccount = i.status === 'account-selection-required';
|
|
12509
13432
|
const checkUnavailable = i.status === 'check-unavailable';
|
|
12510
13433
|
const missingReader = needsAttention && i.setup?.category === 'reader-release-unavailable';
|
|
12511
|
-
const setupDetails = {
|
|
12512
|
-
'aware-unavailable': 'FloLess couldn’t start the service used by Revit projects.',
|
|
12513
|
-
'core-workflow-provisioning': 'FloLess couldn’t prepare the built-in Workspace workflows.',
|
|
12514
|
-
'reader-verification': 'FloLess couldn’t verify the installed Revit reader.',
|
|
12515
|
-
'workspace-bootstrap': 'FloLess couldn’t prepare the Workspace connection used by Revit workflows.',
|
|
12516
|
-
'revit-workflow-provisioning': 'FloLess couldn’t prepare the Revit project workflows.',
|
|
12517
|
-
'reader-release-unavailable': 'FloLess can’t set up Revit because the required reader version is unavailable. Report this issue, then try setup again after FloLess restores it.',
|
|
12518
|
-
unknown: 'FloLess couldn’t finish Revit setup.',
|
|
12519
|
-
};
|
|
12520
13434
|
const badge = ready ? 'Ready' : needsAttention ? 'Needs setup'
|
|
12521
13435
|
: needsAccount ? 'Choose an account' : checkUnavailable ? 'Couldn’t check access' : 'Revit access required';
|
|
12522
|
-
const detail =
|
|
12523
|
-
? 'Open your Revit projects and use their model data in FloLess workflows.'
|
|
12524
|
-
: needsAttention
|
|
12525
|
-
? (setupDetails[i.setup && i.setup.category] || setupDetails.unknown)
|
|
12526
|
-
: needsAccount
|
|
12527
|
-
? 'Choose the FloLess account you want to use before opening Revit projects.'
|
|
12528
|
-
: checkUnavailable
|
|
12529
|
-
? 'FloLess couldn’t check Revit access. Check your connection and try again.'
|
|
12530
|
-
: 'Revit Parser is not included for this account. Ask the account owner to enable it.';
|
|
13436
|
+
const detail = revitIntegrationDetail(i);
|
|
12531
13437
|
const checkLabel = needsAttention ? 'Try setup again' : needsAccount ? 'Choose account'
|
|
12532
13438
|
: ready ? 'Check status' : 'Check access again';
|
|
12533
13439
|
// The Revit detail is always a sentence the person must finish reading (#1524), so it
|
|
@@ -12542,7 +13448,7 @@
|
|
|
12542
13448
|
<span class="int-recovery-actions">
|
|
12543
13449
|
${ready ? '<button class="int-action" data-xeorvt-action="open">Open Revit projects</button>' : ''}
|
|
12544
13450
|
${missingReader ? '<button class="int-action" data-xeorvt-action="report" data-command-id="shell.revit-report-setup-issue" aria-label="Report issue: missing Revit reader" aria-describedby="xeorvt-setup-detail">Report issue</button>' : ''}
|
|
12545
|
-
<button class="int-action" data-xeorvt-action="${needsAccount ? 'account' : 'check'}" data-xeorvt-retry="${needsAttention ? 'true' : 'false'}"${needsAttention ? ' aria-describedby="xeorvt-setup-detail"' : ''}>${checkLabel}</button>
|
|
13451
|
+
<button class="int-action" data-xeorvt-action="${needsAccount ? 'account' : 'check'}" data-xeorvt-retry="${needsAttention ? 'true' : 'false'}"${needsAttention ? ' data-command-id="shell.integrations-revit-retry-setup" aria-describedby="xeorvt-setup-detail"' : ''}>${checkLabel}</button>
|
|
12546
13452
|
</span></div></div></div>`;
|
|
12547
13453
|
}
|
|
12548
13454
|
const action = i.status === 'connected' ? 'Disconnect' : i.status === 'expired' ? 'Reconnect' : 'Connect';
|
|
@@ -12553,7 +13459,7 @@
|
|
|
12553
13459
|
<div class="int-icon" aria-hidden="true">${escapeHtml(VENDOR_ICON[i.vendor] || (i.name[0] || '?'))}</div>
|
|
12554
13460
|
<div class="int-info">
|
|
12555
13461
|
<div class="int-name">${escapeHtml(i.name)}</div>
|
|
12556
|
-
<div class="int-kind">${i.agent === 'first-party' ? 'Built-in integration' : `${escapeHtml(i.vendor || 'integration')} ·
|
|
13462
|
+
<div class="int-kind">${i.agent === 'first-party' ? 'Built-in integration' : `${escapeHtml(i.vendor || 'integration')} · tool <code>${escapeHtml(i.agent)}</code>`}</div>
|
|
12557
13463
|
<div class="int-scopes">${escapeHtml((i.network || []).join(' · ') || '—')}</div>
|
|
12558
13464
|
<div class="int-meta">${escapeHtml(meta)}</div>
|
|
12559
13465
|
${renderIntegrationAccounts(i)}
|
|
@@ -12590,21 +13496,25 @@
|
|
|
12590
13496
|
const hadFocus = document.activeElement === btn;
|
|
12591
13497
|
btn.disabled = true;
|
|
12592
13498
|
btn.textContent = 'Setting up…';
|
|
13499
|
+
// `?` on the busy button says why it cannot be pressed; the next render of the list replaces the button.
|
|
13500
|
+
btn.setAttribute('data-blocked-reason', 'Revit Parser setup retry is already in progress.');
|
|
12593
13501
|
let retryAnnouncement = 'Revit setup is ready.';
|
|
13502
|
+
// What a failed retry says, toasted and announced alike: the server's remedy when there is one
|
|
13503
|
+
// (written for the person, naming their folders, so shown as written), else the safe category line.
|
|
13504
|
+
const failedRetry = (setup) => {
|
|
13505
|
+
const remedy = typeof setup?.setupRemedy === 'string' ? setup.setupRemedy.trim() : '';
|
|
13506
|
+
const message = remedy || (setup?.category === 'reader-release-unavailable'
|
|
13507
|
+
? 'The required Revit reader is unavailable. Choose Report issue; try setup again after FloLess restores it.'
|
|
13508
|
+
: 'Revit setup couldn’t finish. Try setup again.');
|
|
13509
|
+
retryAnnouncement = message;
|
|
13510
|
+
showToast(remedy ? authoredToastCopy(remedy) : message, 'warn');
|
|
13511
|
+
};
|
|
12594
13512
|
try {
|
|
12595
13513
|
const setup = await api('/api/rvt-defaults/retry', { method: 'POST' });
|
|
12596
|
-
if (setup.status !== 'ready')
|
|
12597
|
-
retryAnnouncement = 'Revit setup could not finish. The Integrations card shows what to do next.';
|
|
12598
|
-
showToast(setup.category === 'reader-release-unavailable'
|
|
12599
|
-
? 'The required Revit reader is unavailable. Choose Report issue; try setup again after FloLess restores it.'
|
|
12600
|
-
: 'Revit setup couldn’t finish. Try setup again.', 'warn');
|
|
12601
|
-
}
|
|
13514
|
+
if (setup.status !== 'ready') failedRetry(setup);
|
|
12602
13515
|
}
|
|
12603
13516
|
catch (error) {
|
|
12604
|
-
|
|
12605
|
-
showToast(error?.body?.category === 'reader-release-unavailable'
|
|
12606
|
-
? 'The required Revit reader is unavailable. Choose Report issue; try setup again after FloLess restores it.'
|
|
12607
|
-
: 'Revit setup couldn’t finish. Try setup again.', 'warn');
|
|
13517
|
+
failedRetry(error?.body);
|
|
12608
13518
|
}
|
|
12609
13519
|
await refreshIntegrations();
|
|
12610
13520
|
document.getElementById('integrations-status').textContent = retryAnnouncement;
|
|
@@ -12773,6 +13683,12 @@
|
|
|
12773
13683
|
let editWorkflows = []; // app list for the workflow <select>, cached per edit-open
|
|
12774
13684
|
let editTriggerSource = null; // picked workflow's triggerSource (null = not trigger-eligible)
|
|
12775
13685
|
let editRoutineMode = 'schedule'; // 'schedule' | 'trigger' — chosen kind in the edit form
|
|
13686
|
+
let editTarget = 'workflow'; // #2035: 'workflow' | 'agent' — what the routine being edited runs
|
|
13687
|
+
let editAgents = []; // #2035: this folder's agents for the Agent <select>, cached per edit-open
|
|
13688
|
+
let editAgentAi = 'claude'; // #2035: the AI an agent routine starts (Claude | Codex), like the Run sheet's choice
|
|
13689
|
+
let editReturnFocus = null; // #2035: where focus goes back when the editor was opened from an agent's page
|
|
13690
|
+
const routineAgentNames = new Map(); // #2035: agentId → name, for "Agent · <name>" rows
|
|
13691
|
+
const routineAgentRunState = new Map(); // #2035: routine id → how its last agent run is going, read from that run
|
|
12776
13692
|
const runningRoutines = new Set(); // ids executing now (SSE start → ended)
|
|
12777
13693
|
|
|
12778
13694
|
function isCompleteReportRoutine(r) {
|
|
@@ -13023,8 +13939,28 @@
|
|
|
13023
13939
|
function lastRunTip(r) {
|
|
13024
13940
|
if (!r.lastRun) return 'Never run yet';
|
|
13025
13941
|
const lr = r.lastRun;
|
|
13942
|
+
// #2035: an agent routine only starts the agent; how that run went is the agent run's own record.
|
|
13943
|
+
if (r.agent) {
|
|
13944
|
+
const when = absTime(lr.at);
|
|
13945
|
+
if (lr.status === 'starting') return `Starting the agent · ${when}`;
|
|
13946
|
+
if (lr.status === 'started') return `Started the agent · ${when}${routineAgentRunState.get(r.id) ? ` · ${routineAgentRunState.get(r.id)}` : ''}`;
|
|
13947
|
+
// A skip reason already begins "Skipped — …" (the server's sentence), so it is shown as is.
|
|
13948
|
+
if (lr.status === 'skipped') return `${lr.reason || 'Skipped'} · ${when}`;
|
|
13949
|
+
return `Didn’t start${lr.reason ? ' — ' + lr.reason : ''} · ${when}`;
|
|
13950
|
+
}
|
|
13026
13951
|
const dur = lr.durationMs != null ? ` · ${(lr.durationMs / 1000).toFixed(1)} s` : '';
|
|
13027
|
-
|
|
13952
|
+
// A run that finished on a stated assumption says so with its outcome, never only in the report.
|
|
13953
|
+
const warnings = Array.isArray(lr.warnings) ? lr.warnings.filter((warning) => typeof warning === 'string' && warning) : [];
|
|
13954
|
+
// #1998: a run made under an approval carried forward to newer tool versions says so, in AWARE's words.
|
|
13955
|
+
const carried = lr.approval && lr.approval.origin === 'successor'
|
|
13956
|
+
? `\nApproval carried over to a newer tool version. AWARE's record: ${lr.approval.label || 'carried forward'}` : '';
|
|
13957
|
+
const bridgeWarnings = Array.isArray(lr.bridgeWarnings) ? lr.bridgeWarnings.filter((w) => w && typeof w === 'object'
|
|
13958
|
+
&& ['bridge-too-old', 'bridge-too-new', 'declaration-invalid'].includes(w.status)
|
|
13959
|
+
&& typeof w.agent === 'string' && w.agent.trim() && typeof w.name === 'string' && w.name.trim()
|
|
13960
|
+
&& typeof w.detail === 'string' && w.detail.trim() && (w.via === null || typeof w.via === 'string')
|
|
13961
|
+
&& Array.isArray(w.choices) && w.choices.every((choice) => typeof choice === 'string')) : [];
|
|
13962
|
+
const bridge = bridgeWarnings.map((w) => `\n${w.status === 'declaration-invalid' ? 'Ran with an invalid bridge declaration' : 'Ran with a bridge mismatch'}: ${w.via ? w.via + ' → ' : ''}${w.name}. ${w.detail}`).join('');
|
|
13963
|
+
return `Last run ${lr.status}${lr.reason ? ' — ' + lr.reason : ''}${warnings.length ? ' — ' + warnings.join(' ') : ''} · ${absTime(lr.at)}${dur}${carried}${bridge}`;
|
|
13028
13964
|
}
|
|
13029
13965
|
|
|
13030
13966
|
// ── Trigger-routine row helpers ─────────────────────────────────────────────
|
|
@@ -13083,6 +14019,10 @@
|
|
|
13083
14019
|
async function loadRoutinesData() {
|
|
13084
14020
|
try {
|
|
13085
14021
|
const res = await api('/api/routines');
|
|
14022
|
+
// The Workflows landing repaints only when the routines its "Scheduled" chips read change, not on every
|
|
14023
|
+
// scheduler tick.
|
|
14024
|
+
const chipKey = (list) => JSON.stringify(list.filter((r) => r.enabled && !r.broken).map((r) => [r.workflow, r.name]));
|
|
14025
|
+
const chipsChanged = chipKey(routinesData) !== chipKey(res.routines || []);
|
|
13086
14026
|
routinesData = res.routines || [];
|
|
13087
14027
|
routinesMax = res.max || 15;
|
|
13088
14028
|
// Reconcile running indicators from the server's authoritative state (queued/
|
|
@@ -13095,8 +14035,40 @@
|
|
|
13095
14035
|
completeReportDiscoveryEpoch.set(id, (completeReportDiscoveryEpoch.get(id) || 0) + 1);
|
|
13096
14036
|
}
|
|
13097
14037
|
for (const id of live) void refreshRoutineReportDiscovery(id);
|
|
14038
|
+
if (routinesData.some((r) => r.agent)) void refreshRoutineAgents();
|
|
13098
14039
|
if ($routinesModal.classList.contains('show')) renderRoutinesList();
|
|
13099
|
-
|
|
14040
|
+
// Last, and on its own: a landing repaint that throws must not skip the reconcile above.
|
|
14041
|
+
if (wfLanding && chipsChanged) {
|
|
14042
|
+
try { renderWorkflowsLanding(); } catch (err) { console.error('Workflows landing repaint failed', err); }
|
|
14043
|
+
}
|
|
14044
|
+
} catch (err) { console.warn('Routines could not be loaded', err); }
|
|
14045
|
+
}
|
|
14046
|
+
|
|
14047
|
+
/** #2035: one line on how an agent run is going, from the run the routine started (never a copied count). */
|
|
14048
|
+
function agentRunStateText(run) {
|
|
14049
|
+
if (!run) return '';
|
|
14050
|
+
const lives = run.targets.map((t) => t.live);
|
|
14051
|
+
const declined = run.targets.reduce((sum, t) => sum + (t.declines ? t.declines.list.filter((d) => d.state === 'declined').length + t.declines.moreDeclined : 0), 0);
|
|
14052
|
+
const tail = declined ? ` · ${declined} step${declined === 1 ? '' : 's'} declined — see Questions for you on the Agents page` : '';
|
|
14053
|
+
if (lives.some((l) => l === 'working' || l === 'starting' || l === 'waiting')) return `Running${tail}`;
|
|
14054
|
+
if (lives.some((l) => l === 'failed' || l === 'failed-reply' || l === 'uncertain' || l === 'needs-recovery')) return `Needs a look on the Agents page${tail}`;
|
|
14055
|
+
return `Done${tail}`;
|
|
14056
|
+
}
|
|
14057
|
+
|
|
14058
|
+
async function refreshRoutineAgents() {
|
|
14059
|
+
const agentsApi = window.flolessAgents;
|
|
14060
|
+
if (!agentsApi?.list) return;
|
|
14061
|
+
try {
|
|
14062
|
+
for (const agent of await agentsApi.list()) routineAgentNames.set(agent.agentId, agent.name);
|
|
14063
|
+
} catch (err) { console.warn('Agent names for routines could not be loaded', err); }
|
|
14064
|
+
await Promise.all(routinesData.filter((r) => r.agent && r.lastRun?.agentRunId).map(async (r) => {
|
|
14065
|
+
try {
|
|
14066
|
+
const body = await agentsApi.runs(r.agent.agentId);
|
|
14067
|
+
const run = (body.runs || []).find((row) => row.runId === r.lastRun.agentRunId);
|
|
14068
|
+
routineAgentRunState.set(r.id, run ? agentRunStateText(run) : '');
|
|
14069
|
+
} catch { routineAgentRunState.delete(r.id); }
|
|
14070
|
+
}));
|
|
14071
|
+
if ($routinesModal.classList.contains('show')) renderRoutinesList();
|
|
13100
14072
|
}
|
|
13101
14073
|
|
|
13102
14074
|
// SSE: a trigger routine's live session snapshot changed. Update the in-memory
|
|
@@ -13385,7 +14357,11 @@
|
|
|
13385
14357
|
: discovery?.error
|
|
13386
14358
|
? `<div class="rtn-report-note warn" role="status">${escapeHtml(discovery.error)}</div>`
|
|
13387
14359
|
: discovery?.report
|
|
13388
|
-
|
|
14360
|
+
// What the saved report rests on (a scheduled "Latest approved" run that read an older
|
|
14361
|
+
// approved version) is said first, above the report it labels.
|
|
14362
|
+
? (Array.isArray(discovery.report.warnings) ? discovery.report.warnings.filter((warning) => typeof warning === 'string' && warning) : [])
|
|
14363
|
+
.map((warning) => `<div class="rtn-report-note warn" role="status">${escapeHtml(warning)}</div>`).join('')
|
|
14364
|
+
+ `<div class="rtn-report-note">${discovery.earlierReport ? 'Earlier report' : 'Latest report'} · ${escapeHtml(new Date(discovery.report.at).toLocaleString())} · ${Number(discovery.report.summary.objectCount)} objects</div>`
|
|
13389
14365
|
+ (discovery.latestAttempt?.status === 'failed' || discovery.latestAttempt?.status === 'recovery'
|
|
13390
14366
|
? `<div class="rtn-report-note warn" role="status">${discovery.latestAttempt.status === 'recovery' ? 'Recovery needed' : 'Latest attempt failed'} · ${escapeHtml(discovery.latestAttempt.reason || 'Run it again.')}</div>` : '')
|
|
13391
14367
|
: `<div class="rtn-report-note">${discovery?.latestAttempt?.status === 'failed' || discovery?.latestAttempt?.status === 'recovery'
|
|
@@ -13402,11 +14378,13 @@
|
|
|
13402
14378
|
} else {
|
|
13403
14379
|
statusEl = running
|
|
13404
14380
|
? '<span class="rtn-spinner" data-tip="Running now…"></span>'
|
|
13405
|
-
: `<span class="rtn-status ${escapeAttr(r.lastRun ? r.lastRun.status : '')}" data-tip="${escapeAttr(lastRunTip(r))}"></span>`;
|
|
14381
|
+
: `<span class="rtn-status ${escapeAttr(r.lastRun ? ({ started: 'ok', starting: '' }[r.lastRun.status] ?? r.lastRun.status) : '')}" data-tip="${escapeAttr(lastRunTip(r))}"></span>`;
|
|
13406
14382
|
nextTip = r.nextFireAt ? `Next run: ${absTime(r.nextFireAt)}` : (r.broken ? r.broken.reason : r.enabled ? 'Not scheduled' : 'Disabled');
|
|
13407
14383
|
nextLabel = !r.enabled ? 'disabled' : r.broken ? 'broken' : relTime(r.nextFireAt);
|
|
13408
14384
|
}
|
|
13409
14385
|
const whenText = isTrigger ? triggerWhenText(r) : scheduleText(r.schedule);
|
|
14386
|
+
// #2035: an agent routine names its agent, not a workflow id.
|
|
14387
|
+
const whatText = r.agent ? `Agent · ${routineAgentNames.get(r.agent.agentId) || 'agent'}` : r.workflow;
|
|
13410
14388
|
const toggleTip = isTrigger ? (r.enabled ? 'Stop listening' : 'Start listening') : `${r.enabled ? 'Disable' : 'Enable'} this routine`;
|
|
13411
14389
|
// One sentence for all three surfaces a blocked ▶ speaks through: the hover tip, the `?`
|
|
13412
14390
|
// band (which reads data-blocked-reason), and the toast when a click still reaches the
|
|
@@ -13425,7 +14403,7 @@
|
|
|
13425
14403
|
<div class="rtn-item ${isTrigger ? 'trigger ' : ''}${r.enabled ? '' : 'disabled'} ${running ? 'running' : ''}" data-id="${escapeAttr(r.id)}">
|
|
13426
14404
|
<div class="rtn-main">
|
|
13427
14405
|
<div class="rtn-name">${escapeHtml(r.name)}</div>
|
|
13428
|
-
<div class="rtn-sub"><span class="rtn-wf">${escapeHtml(
|
|
14406
|
+
<div class="rtn-sub"><span class="rtn-wf">${escapeHtml(whatText)}</span><span class="rtn-dot">·</span><span>${escapeHtml(whenText)}</span>${broken}</div>
|
|
13429
14407
|
${reportLine}
|
|
13430
14408
|
</div>
|
|
13431
14409
|
<div class="rtn-meta"${isTrigger ? ' aria-live="polite" aria-atomic="true"' : ''}>
|
|
@@ -13439,6 +14417,7 @@
|
|
|
13439
14417
|
</label>
|
|
13440
14418
|
${isTrigger ? '' : `<button class="rtn-act" data-rtn-run="${escapeAttr(r.id)}" data-command-id="shell.routine-run#${escapeAttr(r.id)}" data-command-instance-label="${escapeAttr(r.name)}" aria-label="Run ${escapeAttr(r.name)} now" data-tip="${escapeAttr(runTip)}"${running ? ` disabled data-blocked-reason="${escapeAttr(RTN_ALREADY_RUNNING)}"` : ''}>▶</button>`}
|
|
13441
14419
|
${isCompleteReport && discovery?.report && !discovery.checking ? `<button class="rtn-act rtn-report-view" data-rtn-report="${escapeAttr(r.id)}" data-command-id="shell.routine-view-report#${escapeAttr(r.id)}" data-command-instance-label="${escapeAttr(r.name)}" aria-label="View saved report for ${escapeAttr(r.name)}" data-tip="View the verified, read-only report">View report</button>` : ''}
|
|
14420
|
+
${r.agent ? `<button class="rtn-act" data-rtn-agent="${escapeAttr(r.agent.agentId)}" data-command-id="shell.routine-open-agent#${escapeAttr(r.id)}" data-command-instance-label="${escapeAttr(r.name)}" aria-label="Open the agent that ${escapeAttr(r.name)} runs" data-tip="Open this agent and its runs on the Agents page">Agent</button>` : ''}
|
|
13442
14421
|
<button class="rtn-act" data-rtn-edit="${escapeAttr(r.id)}" data-tip="Edit">✎</button>
|
|
13443
14422
|
<button class="rtn-act rtn-del-act" data-rtn-del="${escapeAttr(r.id)}" data-tip="Delete">×</button>
|
|
13444
14423
|
</div>
|
|
@@ -13448,6 +14427,7 @@
|
|
|
13448
14427
|
$list.querySelectorAll('[data-rtn-run]').forEach((b) => { b.onclick = () => runRoutineNow(b.dataset.rtnRun); });
|
|
13449
14428
|
$list.querySelectorAll('[data-rtn-report]').forEach((b) => { b.onclick = () => { void viewScheduledCompleteReport(b.dataset.rtnReport); }; });
|
|
13450
14429
|
$list.querySelectorAll('[data-rtn-edit]').forEach((b) => { b.onclick = () => openRoutineEdit(b.dataset.rtnEdit); });
|
|
14430
|
+
$list.querySelectorAll('[data-rtn-agent]').forEach((b) => { b.onclick = () => { hideModal($routinesModal); void window.flolessAgents?.open?.(b.dataset.rtnAgent); }; });
|
|
13451
14431
|
$list.querySelectorAll('[data-rtn-del]').forEach((b) => { b.onclick = () => deleteRoutineUi(b.dataset.rtnDel); });
|
|
13452
14432
|
}
|
|
13453
14433
|
|
|
@@ -13515,6 +14495,89 @@
|
|
|
13515
14495
|
} catch (e) { reportErr(e); }
|
|
13516
14496
|
}
|
|
13517
14497
|
|
|
14498
|
+
/** #2035: what the routine runs — a workflow, or an agent (always on a schedule, no inputs). */
|
|
14499
|
+
function setRoutineTarget(target) {
|
|
14500
|
+
editTarget = target === 'agent' ? 'agent' : 'workflow';
|
|
14501
|
+
const agent = editTarget === 'agent';
|
|
14502
|
+
document.querySelectorAll('#rtn-target-field .rtn-mode-btn').forEach((b) => {
|
|
14503
|
+
const on = b.dataset.target === editTarget;
|
|
14504
|
+
b.classList.toggle('active', on);
|
|
14505
|
+
b.setAttribute('aria-pressed', on ? 'true' : 'false');
|
|
14506
|
+
});
|
|
14507
|
+
document.getElementById('rtn-workflow-field').hidden = agent;
|
|
14508
|
+
document.getElementById('rtn-agent-field').hidden = !agent;
|
|
14509
|
+
document.getElementById('rtn-edit-sub').textContent = agent
|
|
14510
|
+
? 'Pick an agent and when it should run. Nobody watches a scheduled run, so anything that would ask you is declined and listed for you afterwards.'
|
|
14511
|
+
: 'Pick a workflow and when it should run.';
|
|
14512
|
+
if (agent) {
|
|
14513
|
+
document.getElementById('rtn-inputs-field').hidden = true;
|
|
14514
|
+
document.getElementById('rtn-mode-field').hidden = true;
|
|
14515
|
+
setRoutineMode('schedule');
|
|
14516
|
+
paintRoutineAgentNote();
|
|
14517
|
+
} else {
|
|
14518
|
+
// Back to the workflow: what it already loaded comes straight back (#2035 QA), nothing is fetched again.
|
|
14519
|
+
document.getElementById('rtn-inputs-field').hidden = !document.getElementById('rtn-inputs').children.length;
|
|
14520
|
+
applyRoutineModeAvailability();
|
|
14521
|
+
}
|
|
14522
|
+
}
|
|
14523
|
+
|
|
14524
|
+
function setRoutineAgentAi(ai) {
|
|
14525
|
+
editAgentAi = ai === 'codex' ? 'codex' : 'claude';
|
|
14526
|
+
document.querySelectorAll('#rtn-agent-ai .rtn-mode-btn').forEach((b) => {
|
|
14527
|
+
const on = b.dataset.ai === editAgentAi;
|
|
14528
|
+
b.classList.toggle('active', on);
|
|
14529
|
+
b.setAttribute('aria-pressed', on ? 'true' : 'false');
|
|
14530
|
+
});
|
|
14531
|
+
}
|
|
14532
|
+
|
|
14533
|
+
/** The AI a new agent routine starts with: the agent's own, else the one last chosen to run an agent by hand. */
|
|
14534
|
+
function defaultRoutineAgentAi(agent) {
|
|
14535
|
+
if (agent?.provider) return agent.provider;
|
|
14536
|
+
try { const last = localStorage.getItem('floless:agents-provider'); if (last === 'codex' || last === 'claude') return last; } catch { /* private mode */ }
|
|
14537
|
+
return 'claude';
|
|
14538
|
+
}
|
|
14539
|
+
|
|
14540
|
+
function paintRoutineAgentNote() {
|
|
14541
|
+
const $note = document.getElementById('rtn-agent-note');
|
|
14542
|
+
const agent = editAgents.find((a) => a.agentId === document.getElementById('rtn-agent').value);
|
|
14543
|
+
if (!agent) { $note.textContent = ''; return; }
|
|
14544
|
+
const access = agent.allowChanges
|
|
14545
|
+
? 'Can change files, so it runs in Auto. Anything that would ask you is declined and listed afterwards on the Agents page.'
|
|
14546
|
+
: 'Read only. It reads and reports.';
|
|
14547
|
+
$note.textContent = access;
|
|
14548
|
+
}
|
|
14549
|
+
|
|
14550
|
+
async function loadRoutineAgents(selectedId, fixed) {
|
|
14551
|
+
const $agent = document.getElementById('rtn-agent');
|
|
14552
|
+
const $empty = document.getElementById('rtn-agent-empty');
|
|
14553
|
+
try { editAgents = (await window.flolessAgents?.list?.()) || []; }
|
|
14554
|
+
catch { editAgents = null; }
|
|
14555
|
+
const usable = (editAgents || []).filter((a) => !a.archivedAt || a.agentId === selectedId);
|
|
14556
|
+
for (const a of usable) routineAgentNames.set(a.agentId, a.name);
|
|
14557
|
+
// Editing a routine whose agent is gone: say so, never show another agent's name in the locked picker.
|
|
14558
|
+
const gone = fixed && selectedId && editAgents && !usable.some((a) => a.agentId === selectedId);
|
|
14559
|
+
$agent.innerHTML = (gone ? `<option value="${escapeAttr(selectedId)}">This agent no longer exists</option>` : '')
|
|
14560
|
+
+ usable.map((a) => `<option value="${escapeAttr(a.agentId)}">${escapeHtml(a.name)}${a.allowChanges ? '' : ' (read only)'}</option>`).join('');
|
|
14561
|
+
if (selectedId) $agent.value = selectedId;
|
|
14562
|
+
const shown = usable.length > 0 || Boolean(gone);
|
|
14563
|
+
// The select is shown as the shared themed combobox, its next sibling: hide that, not the hidden native control.
|
|
14564
|
+
const combo = $agent.nextElementSibling?.classList.contains('sel-combo') ? $agent.nextElementSibling : null;
|
|
14565
|
+
if (combo) combo.style.display = shown ? '' : 'none';
|
|
14566
|
+
$agent.hidden = !shown;
|
|
14567
|
+
$empty.hidden = shown;
|
|
14568
|
+
if (editAgents === null) {
|
|
14569
|
+
$empty.hidden = false;
|
|
14570
|
+
$empty.firstChild.textContent = 'FloLess couldn’t list your agents just now. Close this and open it again, or ';
|
|
14571
|
+
} else {
|
|
14572
|
+
$empty.firstChild.textContent = 'No agents in this workspace folder yet. ';
|
|
14573
|
+
}
|
|
14574
|
+
document.getElementById('rtn-agent-ai').hidden = !usable.length;
|
|
14575
|
+
$agent.disabled = Boolean(fixed);
|
|
14576
|
+
if (fixed) $agent.setAttribute('data-tip', 'The agent is fixed — create a new routine to run a different one');
|
|
14577
|
+
else $agent.removeAttribute('data-tip');
|
|
14578
|
+
paintRoutineAgentNote();
|
|
14579
|
+
}
|
|
14580
|
+
|
|
13518
14581
|
// Schedule builder: reveal only the fields the chosen kind needs.
|
|
13519
14582
|
// Switch the edit form between schedule and trigger layouts. Hides the schedule
|
|
13520
14583
|
// builder and shows the read-only trigger-source line for 'trigger' (only honored
|
|
@@ -13574,7 +14637,9 @@
|
|
|
13574
14637
|
|
|
13575
14638
|
// Render the chosen workflow's declared inputs (seeded from defaults / the routine's
|
|
13576
14639
|
// saved values). Hidden when the workflow declares none.
|
|
14640
|
+
let routineInputsLoad = 0; // #2035: only the newest load builds the inputs; an older one that returns late is dropped
|
|
13577
14641
|
async function loadRoutineInputs(workflowId, prefill) {
|
|
14642
|
+
const load = ++routineInputsLoad;
|
|
13578
14643
|
const $field = document.getElementById('rtn-inputs-field');
|
|
13579
14644
|
const $inputs = document.getElementById('rtn-inputs');
|
|
13580
14645
|
$inputs.innerHTML = '';
|
|
@@ -13582,8 +14647,9 @@
|
|
|
13582
14647
|
editTriggerSource = null;
|
|
13583
14648
|
if (!workflowId) { applyRoutineModeAvailability(); return; }
|
|
13584
14649
|
let app;
|
|
13585
|
-
try { ({ app } = await api(`/api/app/${encodeURIComponent(workflowId)}`)); } catch { applyRoutineModeAvailability(); return; }
|
|
14650
|
+
try { ({ app } = await api(`/api/app/${encodeURIComponent(workflowId)}`)); } catch { if (editTarget === 'workflow') applyRoutineModeAvailability(); return; }
|
|
13586
14651
|
if (document.getElementById('rtn-workflow').value !== workflowId) return; // a newer workflow selection superseded this fetch
|
|
14652
|
+
if (load !== routineInputsLoad || editTarget !== 'workflow') return; // #2035: superseded, or switched to An agent meanwhile
|
|
13587
14653
|
editTriggerSource = (app && app.triggerSource) || null;
|
|
13588
14654
|
applyRoutineModeAvailability(); // reveal/hide the schedule-vs-trigger chooser
|
|
13589
14655
|
const inps = (app && app.inputs) || [];
|
|
@@ -13593,7 +14659,7 @@
|
|
|
13593
14659
|
const routineModelModule = inps.find((inp) => inp.widget === 'workspace-model-revision')?.workspaceModule === 'tekla' ? 'tekla' : 'revit';
|
|
13594
14660
|
const bootstrap = await bootstrapEditorSession();
|
|
13595
14661
|
routineModelRevisions = bootstrap.ok ? await fetchApprovedModelRevisions(routineModelModule) : unavailableModelRevisionResult(bootstrap.error);
|
|
13596
|
-
if (document.getElementById('rtn-workflow').value !== workflowId) return;
|
|
14662
|
+
if (document.getElementById('rtn-workflow').value !== workflowId || load !== routineInputsLoad || editTarget !== 'workflow') return;
|
|
13597
14663
|
}
|
|
13598
14664
|
$field.hidden = false;
|
|
13599
14665
|
// The DOM id is index-based (not the workflow-controlled input name) so a crafted
|
|
@@ -13608,10 +14674,11 @@
|
|
|
13608
14674
|
const selection = (extra) => JSON.stringify({ schemaVersion: 'floless.workspace-model-selection/v1', projectUuid: project.projectUuid, ...extra });
|
|
13609
14675
|
const exact = project.versions.slice().sort((a, b) => Number(b.approvalVersion) - Number(a.approvalVersion)).map((version) => ({
|
|
13610
14676
|
value: selection({ approvedRevisionId: version.approvedRevisionId, approvalVersion: version.approvalVersion }),
|
|
13611
|
-
group: project.name, groupMeta: `${name} model`, label: `Approved v${version.approvalVersion}`,
|
|
14677
|
+
group: project.name, groupMeta: `${name} model`, label: `Approved v${version.approvalVersion}${acceptedFindingsMeta(version) ? ` · ${acceptedFindingsMeta(version)}` : ''}`,
|
|
13612
14678
|
meta: version.approvedAt ? new Date(version.approvedAt).toLocaleDateString() : 'Date unavailable',
|
|
13613
14679
|
}));
|
|
13614
|
-
|
|
14680
|
+
const latestAccepted = latestAcceptedFindingsMeta(project.versions);
|
|
14681
|
+
return [...exact, { value: selection({ latestApproved: true }), group: project.name, groupMeta: `${name} model`, label: `Latest approved${latestAccepted ? ` · ${latestAccepted}` : ''}`, meta: 'updates when approvals change' }];
|
|
13615
14682
|
});
|
|
13616
14683
|
const selected = choices.find((choice) => String(choice.value) === String(val));
|
|
13617
14684
|
return `<div class="modal-field"><label>${name} model</label><div class="field-help">Choose the Workspace project and approved revision this scheduled run will read.</div>`
|
|
@@ -13631,8 +14698,10 @@
|
|
|
13631
14698
|
const selection = (extra) => JSON.stringify({ schemaVersion: 'floless.workspace-model-selection/v1', projectUuid: project.projectUuid, ...extra });
|
|
13632
14699
|
return [...project.versions.slice().sort((a, b) => Number(b.approvalVersion) - Number(a.approvalVersion)).map((version) => ({
|
|
13633
14700
|
value: selection({ approvedRevisionId: version.approvedRevisionId, approvalVersion: version.approvalVersion }), group: project.name,
|
|
13634
|
-
groupMeta: `${modelName} model`, label: `Approved v${version.approvalVersion}`,
|
|
13635
|
-
|
|
14701
|
+
groupMeta: `${modelName} model`, label: `Approved v${version.approvalVersion}`,
|
|
14702
|
+
meta: `${version.approvedAt ? new Date(version.approvedAt).toLocaleDateString() : 'Date unavailable'}${acceptedFindingsMeta(version) ? ` · ${acceptedFindingsMeta(version)}` : ''}`,
|
|
14703
|
+
})), { value: selection({ latestApproved: true }), group: project.name, groupMeta: `${modelName} model`, label: 'Latest approved',
|
|
14704
|
+
meta: `updates when approvals change${latestAcceptedFindingsMeta(project.versions) ? ` · ${latestAcceptedFindingsMeta(project.versions)}` : ''}` }];
|
|
13636
14705
|
});
|
|
13637
14706
|
const picked = await formModal({ title: `Choose ${modelName} model`, sub: 'Select a Workspace project and the approved revision this routine will read.', fields: [{
|
|
13638
14707
|
name: 'selection', label: `${modelName} model`, type: 'select', options: choices, value: input.value, required: true,
|
|
@@ -13656,9 +14725,10 @@
|
|
|
13656
14725
|
return out;
|
|
13657
14726
|
}
|
|
13658
14727
|
|
|
13659
|
-
async function openRoutineEdit(id) {
|
|
14728
|
+
async function openRoutineEdit(id, opts = {}) {
|
|
13660
14729
|
editingRoutineId = id || null;
|
|
13661
14730
|
const r = id ? routinesData.find((x) => x.id === id) : null;
|
|
14731
|
+
editReturnFocus = opts.returnFocus || null;
|
|
13662
14732
|
const $wf = document.getElementById('rtn-workflow');
|
|
13663
14733
|
try {
|
|
13664
14734
|
const { apps: list } = await api('/api/apps');
|
|
@@ -13667,7 +14737,12 @@
|
|
|
13667
14737
|
$wf.innerHTML = editWorkflows.map((a) => `<option value="${escapeAttr(a.id)}">${escapeHtml(a.id)}</option>`).join('');
|
|
13668
14738
|
document.getElementById('rtn-edit-title').textContent = r ? 'Edit routine' : 'New routine';
|
|
13669
14739
|
document.getElementById('rtn-name').value = r ? r.name : '';
|
|
13670
|
-
|
|
14740
|
+
// #2046: a Guide suggestion names the workflow; it is preselected only when it is one of the choices.
|
|
14741
|
+
const suggested = !r && opts.workflowId && editWorkflows.some((a) => a.id === opts.workflowId) ? opts.workflowId : null;
|
|
14742
|
+
if (!r && opts.workflowId && !suggested) {
|
|
14743
|
+
showToast(`${opts.workflowId} can’t be scheduled from here, so no workflow is chosen yet. Pick the one to run in the list.`, 'warn');
|
|
14744
|
+
}
|
|
14745
|
+
const wfId = r ? r.workflow : opts.workflowId && !suggested ? '' : (suggested || (editWorkflows[0] ? editWorkflows[0].id : ''));
|
|
13671
14746
|
$wf.value = wfId;
|
|
13672
14747
|
// Workflow is fixed after create (inputs are coerced against it) — disable on edit.
|
|
13673
14748
|
$wf.disabled = !!r;
|
|
@@ -13684,19 +14759,38 @@
|
|
|
13684
14759
|
renderDayChips(sched.kind === 'weekly' ? (sched.days || []) : []);
|
|
13685
14760
|
applySchedKind(sched.kind);
|
|
13686
14761
|
document.getElementById('rtn-enabled').checked = r ? r.enabled : true;
|
|
13687
|
-
|
|
14762
|
+
// #2035: what it runs is fixed after create, like the workflow.
|
|
14763
|
+
const agentId = r?.agent?.agentId || opts.agentId || null;
|
|
14764
|
+
document.getElementById('rtn-target-field').hidden = Boolean(r);
|
|
14765
|
+
await loadRoutineAgents(agentId, Boolean(r));
|
|
14766
|
+
setRoutineAgentAi(r?.agent?.provider || defaultRoutineAgentAi((editAgents || []).find((a) => a.agentId === document.getElementById('rtn-agent').value)));
|
|
14767
|
+
if (agentId) setRoutineTarget('agent');
|
|
14768
|
+
else {
|
|
14769
|
+
setRoutineTarget('workflow');
|
|
14770
|
+
await loadRoutineInputs(wfId, r ? r.inputs : null);
|
|
14771
|
+
}
|
|
13688
14772
|
showModal($routineEditModal);
|
|
13689
14773
|
setTimeout(() => document.getElementById('rtn-name').focus(), 0);
|
|
13690
14774
|
}
|
|
13691
14775
|
|
|
14776
|
+
function closeRoutineEdit() {
|
|
14777
|
+
hideModal($routineEditModal);
|
|
14778
|
+
const back = editReturnFocus;
|
|
14779
|
+
editReturnFocus = null;
|
|
14780
|
+
if (back && back.isConnected) setTimeout(() => back.focus(), 0);
|
|
14781
|
+
}
|
|
14782
|
+
|
|
13692
14783
|
async function saveRoutine() {
|
|
13693
14784
|
const name = document.getElementById('rtn-name').value.trim();
|
|
13694
14785
|
if (!name) { showToast('Name is required', 'warn'); return; }
|
|
14786
|
+
const asAgent = editTarget === 'agent';
|
|
14787
|
+
const agentId = document.getElementById('rtn-agent').value;
|
|
14788
|
+
if (asAgent && !agentId && !editingRoutineId) { showToast('Pick an agent — or create one on the Agents page first', 'warn'); return; }
|
|
13695
14789
|
const workflow = document.getElementById('rtn-workflow').value;
|
|
13696
|
-
if (!workflow) { showToast('Pick a workflow', 'warn'); return; }
|
|
13697
|
-
const inputs = collectRoutineInputs();
|
|
14790
|
+
if (!asAgent && !workflow) { showToast('Pick a workflow', 'warn'); return; }
|
|
14791
|
+
const inputs = asAgent ? {} : collectRoutineInputs();
|
|
13698
14792
|
const enabled = document.getElementById('rtn-enabled').checked;
|
|
13699
|
-
const asTrigger = editRoutineMode === 'trigger' && !!editTriggerSource;
|
|
14793
|
+
const asTrigger = !asAgent && editRoutineMode === 'trigger' && !!editTriggerSource;
|
|
13700
14794
|
let schedule;
|
|
13701
14795
|
if (!asTrigger) {
|
|
13702
14796
|
const kind = document.getElementById('rtn-kind').value;
|
|
@@ -13720,23 +14814,43 @@
|
|
|
13720
14814
|
}
|
|
13721
14815
|
try {
|
|
13722
14816
|
if (editingRoutineId) {
|
|
13723
|
-
const body = asTrigger ? { name, inputs, enabled } : { name, schedule, inputs, enabled };
|
|
14817
|
+
const body = asAgent ? { name, schedule, enabled, provider: editAgentAi } : asTrigger ? { name, inputs, enabled } : { name, schedule, inputs, enabled };
|
|
13724
14818
|
await api(`/api/routines/${encodeURIComponent(editingRoutineId)}`, { method: 'PATCH', body: JSON.stringify(body) });
|
|
13725
14819
|
showToast('Routine updated', 'ok');
|
|
13726
14820
|
} else {
|
|
13727
|
-
const body =
|
|
14821
|
+
const body = asAgent ? { name, agentId, provider: editAgentAi, schedule, enabled }
|
|
14822
|
+
: asTrigger ? { kind: 'trigger', name, workflow, inputs, enabled } : { name, workflow, schedule, inputs, enabled };
|
|
13728
14823
|
await api('/api/routines', { method: 'POST', body: JSON.stringify(body) });
|
|
13729
14824
|
showToast('Routine created', 'ok');
|
|
13730
14825
|
}
|
|
13731
|
-
|
|
14826
|
+
closeRoutineEdit();
|
|
13732
14827
|
await loadRoutinesData();
|
|
13733
|
-
} catch (e) {
|
|
14828
|
+
} catch (e) {
|
|
14829
|
+
// #2035: the server words an agent routine's refusal for the person (archived, another folder…); say that.
|
|
14830
|
+
const said = asAgent && typeof e?.body?.error === 'string' && e.status < 500 ? e.body.error : null;
|
|
14831
|
+
showToast(said || 'We couldn’t save this routine because FloLess could not save the change. Try again.', 'err');
|
|
14832
|
+
}
|
|
14833
|
+
}
|
|
14834
|
+
|
|
14835
|
+
// #2035 (PR #2045 review): a routine only starts its agent, so "how the run is going" changes long after the routine's
|
|
14836
|
+
// own events. While the dialog is open, and an agent run it started may still be going, ask again every few seconds.
|
|
14837
|
+
let routineAgentPoll = null;
|
|
14838
|
+
function pollRoutineAgents() {
|
|
14839
|
+
clearTimeout(routineAgentPoll);
|
|
14840
|
+
routineAgentPoll = setTimeout(async () => {
|
|
14841
|
+
if (!$routinesModal.classList.contains('show')) return;
|
|
14842
|
+
const going = routinesData.some((r) => r.agent && (r.lastRun?.status === 'starting'
|
|
14843
|
+
|| (r.lastRun?.status === 'started' && !/^(Done|Needs a look)/.test(routineAgentRunState.get(r.id) || ''))));
|
|
14844
|
+
if (going) await refreshRoutineAgents();
|
|
14845
|
+
pollRoutineAgents();
|
|
14846
|
+
}, 8000);
|
|
13734
14847
|
}
|
|
13735
14848
|
|
|
13736
14849
|
openRoutines = function openRoutinesReal() {
|
|
13737
14850
|
renderRoutinesList();
|
|
13738
14851
|
showModal($routinesModal);
|
|
13739
14852
|
loadRoutinesData();
|
|
14853
|
+
pollRoutineAgents();
|
|
13740
14854
|
};
|
|
13741
14855
|
|
|
13742
14856
|
// Wiring (the modal elements are static in index.html, present when this runs).
|
|
@@ -13745,15 +14859,52 @@
|
|
|
13745
14859
|
document.getElementById('routines-close').onclick = () => hideModal($routinesModal);
|
|
13746
14860
|
onBackdropDismiss($routinesModal, () => hideModal($routinesModal));
|
|
13747
14861
|
document.getElementById('rtn-add').onclick = () => openRoutineEdit(null);
|
|
13748
|
-
document.getElementById('rtn-edit-cancel').onclick = () =>
|
|
14862
|
+
document.getElementById('rtn-edit-cancel').onclick = () => closeRoutineEdit();
|
|
13749
14863
|
document.getElementById('rtn-edit-save').onclick = () => saveRoutine();
|
|
13750
|
-
onBackdropDismiss($routineEditModal, () =>
|
|
14864
|
+
onBackdropDismiss($routineEditModal, () => closeRoutineEdit());
|
|
13751
14865
|
document.getElementById('rtn-kind').onchange = (e) => applySchedKind(e.target.value);
|
|
13752
14866
|
document.querySelectorAll('#rtn-mode-field .rtn-mode-btn').forEach((b) => { b.onclick = () => setRoutineMode(b.dataset.mode); });
|
|
13753
14867
|
document.getElementById('rtn-workflow').onchange = (e) => { if (!editingRoutineId) loadRoutineInputs(e.target.value, null); };
|
|
14868
|
+
document.querySelectorAll('#rtn-target-field .rtn-mode-btn').forEach((b) => {
|
|
14869
|
+
b.onclick = () => {
|
|
14870
|
+
setRoutineTarget(b.dataset.target);
|
|
14871
|
+
if (editTarget === 'agent') (document.getElementById('rtn-agent-combo-trigger') || document.getElementById('rtn-agent')).focus();
|
|
14872
|
+
// A load the switch to An agent cut short left nothing to restore: load it now (the newest load wins).
|
|
14873
|
+
else if (!document.getElementById('rtn-inputs').children.length) void loadRoutineInputs(document.getElementById('rtn-workflow').value, null);
|
|
14874
|
+
};
|
|
14875
|
+
});
|
|
14876
|
+
document.getElementById('rtn-agent').onchange = () => {
|
|
14877
|
+
paintRoutineAgentNote();
|
|
14878
|
+
if (!editingRoutineId) setRoutineAgentAi(defaultRoutineAgentAi((editAgents || []).find((a) => a.agentId === document.getElementById('rtn-agent').value)));
|
|
14879
|
+
};
|
|
14880
|
+
document.querySelectorAll('#rtn-agent-ai .rtn-mode-btn').forEach((b) => { b.onclick = () => setRoutineAgentAi(b.dataset.ai); });
|
|
14881
|
+
document.getElementById('rtn-agent-create').onclick = () => {
|
|
14882
|
+
closeRoutineEdit(); hideModal($routinesModal);
|
|
14883
|
+
void window.flolessWorkspaces?.setMode?.('agents');
|
|
14884
|
+
};
|
|
14885
|
+
// #2035: an agent's page opens a new routine with that agent chosen.
|
|
14886
|
+
window.flolessRoutines = {
|
|
14887
|
+
/** #2046: a Guide suggestion — a new routine for this workflow, opened for the person to finish. */
|
|
14888
|
+
async editForWorkflow(workflowId, returnFocus) {
|
|
14889
|
+
await loadRoutinesData();
|
|
14890
|
+
if (routinesData.length >= routinesMax) {
|
|
14891
|
+
showToast(`You already have ${routinesMax} routines. Delete one in Routines (≡ menu), then schedule this workflow.`, 'warn');
|
|
14892
|
+
return;
|
|
14893
|
+
}
|
|
14894
|
+
await openRoutineEdit(null, { workflowId, returnFocus });
|
|
14895
|
+
},
|
|
14896
|
+
async editForAgent(agentId, returnFocus) {
|
|
14897
|
+
await loadRoutinesData();
|
|
14898
|
+
if (routinesData.length >= routinesMax) {
|
|
14899
|
+
showToast(`You already have ${routinesMax} routines. Delete one in Routines (≡ menu), then schedule this agent.`, 'warn');
|
|
14900
|
+
return;
|
|
14901
|
+
}
|
|
14902
|
+
await openRoutineEdit(null, { agentId, returnFocus });
|
|
14903
|
+
},
|
|
14904
|
+
};
|
|
13754
14905
|
document.addEventListener('keydown', (e) => {
|
|
13755
14906
|
if (e.key !== 'Escape') return;
|
|
13756
|
-
if ($routineEditModal.classList.contains('show'))
|
|
14907
|
+
if ($routineEditModal.classList.contains('show')) closeRoutineEdit();
|
|
13757
14908
|
else if ($routinesModal.classList.contains('show')) hideModal($routinesModal);
|
|
13758
14909
|
});
|
|
13759
14910
|
|
|
@@ -13938,6 +15089,20 @@
|
|
|
13938
15089
|
}
|
|
13939
15090
|
});
|
|
13940
15091
|
|
|
15092
|
+
// #1912: a failed workflow run's "Report this problem" — pre-filled with what failed and the plain
|
|
15093
|
+
// reason the person was shown. Versions and the open workflow ride along as for every report.
|
|
15094
|
+
window.addEventListener('floless:report-run-issue', (event) => {
|
|
15095
|
+
const detail = event.detail || {};
|
|
15096
|
+
openReportIssue();
|
|
15097
|
+
if (detail.returnFocus instanceof HTMLElement) riReturnFocus = detail.returnFocus;
|
|
15098
|
+
const workflow = typeof detail.workflow === 'string' ? detail.workflow : '';
|
|
15099
|
+
$riTitle.value = `Workflow run failed${workflow ? `: ${workflow}` : ''}`.slice(0, 200);
|
|
15100
|
+
const reason = typeof detail.reason === 'string' ? detail.reason.trim().slice(0, 1500) : '';
|
|
15101
|
+
$riDesc.value = `My workflow run failed. FloLess showed: “${typeof detail.message === 'string' ? detail.message : 'the run failed'}”`
|
|
15102
|
+
+ (reason ? `\n\nAWARE's own message:\n${reason}` : '');
|
|
15103
|
+
riSyncSend();
|
|
15104
|
+
});
|
|
15105
|
+
|
|
13941
15106
|
window.addEventListener('floless:report-revit-setup-issue', (event) => {
|
|
13942
15107
|
openReportIssue();
|
|
13943
15108
|
const card = event.detail?.returnFocus;
|
|
@@ -14078,7 +15243,7 @@
|
|
|
14078
15243
|
try {
|
|
14079
15244
|
if (!localStorage.getItem('floless.hint.menuMoved')) {
|
|
14080
15245
|
localStorage.setItem('floless.hint.menuMoved', '1');
|
|
14081
|
-
showToast('
|
|
15246
|
+
showToast('Tools and Routines live in the ≡ menu — press Ctrl+G or Ctrl+R to open them.', 'info');
|
|
14082
15247
|
}
|
|
14083
15248
|
} catch { /* private mode — skip the hint */ }
|
|
14084
15249
|
|
|
@@ -14651,10 +15816,16 @@
|
|
|
14651
15816
|
// #1890: AI Chat is always on. Where no project or owned workflow is open — the Workspaces landing, the Workflows
|
|
14652
15817
|
// landing, an installed (not owned) workflow — the conversation belongs to the workspace, with what is open as context.
|
|
14653
15818
|
function currentChatScope() {
|
|
15819
|
+
// #2007: on the Agents tab AI Chat is the workspace conversation, or the run conversation the person selected.
|
|
15820
|
+
const agentsScope = document.body.classList.contains('mode-agents') ? window.flolessAgents?.chatScope?.() : null;
|
|
15821
|
+
if (agentsScope) return agentsScope;
|
|
14654
15822
|
if (wsTitleName) {
|
|
14655
15823
|
if (wsTitleLanding || !wsTitleProjectId) return { owner: { kind: 'workspace' }, label: 'All projects and workflows' };
|
|
14656
15824
|
return { owner: { kind: 'project', projectId: wsTitleProjectId }, label: wsTitleName };
|
|
14657
15825
|
}
|
|
15826
|
+
if (!wfLanding && draftWorkflow) {
|
|
15827
|
+
return { owner: { kind: 'workflow', workflowId: draftWorkflow.workflowId }, label: draftWorkflow.displayName };
|
|
15828
|
+
}
|
|
14658
15829
|
if (wfLanding || !currentId) return { owner: { kind: 'workspace' }, label: 'All projects and workflows' };
|
|
14659
15830
|
const app = currentId ? apps.get(currentId) : null;
|
|
14660
15831
|
const owned = ownedWorkflowOf(currentId)?.ownedWorkflow;
|
|
@@ -14669,16 +15840,74 @@
|
|
|
14669
15840
|
}
|
|
14670
15841
|
|
|
14671
15842
|
// ── Workflows landing (#1890) ─────────────────────────────────────────────────
|
|
15843
|
+
async function restoreOwnedWorkflow(workflowId) {
|
|
15844
|
+
const row = wfOwned.find((item) => item.workflowId === workflowId && item.status === 'archived');
|
|
15845
|
+
if (!row || restoringWorkflows.has(workflowId)) return;
|
|
15846
|
+
const selectionAtStart = selectionTicket;
|
|
15847
|
+
const ownsFocus = (element) => element?.dataset?.wfRestore === workflowId;
|
|
15848
|
+
let returnFocus = ownsFocus(document.activeElement);
|
|
15849
|
+
const trackFocus = (event) => {
|
|
15850
|
+
if (event.target !== document.body && !ownsFocus(event.target)) returnFocus = false;
|
|
15851
|
+
};
|
|
15852
|
+
document.addEventListener('focusin', trackFocus);
|
|
15853
|
+
let restored = false;
|
|
15854
|
+
restoringWorkflows.add(workflowId);
|
|
15855
|
+
renderWorkflowsLanding();
|
|
15856
|
+
try {
|
|
15857
|
+
const { workflow } = await api(`/api/workflows/owned/${encodeURIComponent(workflowId)}/archive`, {
|
|
15858
|
+
method: 'POST', body: JSON.stringify({ archived: false }),
|
|
15859
|
+
});
|
|
15860
|
+
restored = true;
|
|
15861
|
+
appsLoadGeneration += 1; // a listing started before this committed restore cannot erase it
|
|
15862
|
+
if (selectionTicket === selectionAtStart) selectionTicket += 1;
|
|
15863
|
+
const committed = { ...row, ...workflow, restoreRefreshState: 'pending' };
|
|
15864
|
+
wfOwned = wfOwned.filter((item) => item.workflowId !== workflowId).concat(committed);
|
|
15865
|
+
if (wfLanding) renderWorkflowsLanding();
|
|
15866
|
+
let refreshFailed = false;
|
|
15867
|
+
try { await loadApps({ preserveSelection: true }); }
|
|
15868
|
+
catch { refreshFailed = true; }
|
|
15869
|
+
// An unavailable additive owned list is deliberately tolerated by loadApps, but is still
|
|
15870
|
+
// not a fresh confirmation. The POST succeeded regardless of that later read's outcome.
|
|
15871
|
+
if (refreshFailed || wfOwned.some((item) => item.workflowId === workflowId && item.restoreRefreshState)) {
|
|
15872
|
+
wfOwned = wfOwned.map((item) => item.workflowId === workflowId && item.status !== 'archived'
|
|
15873
|
+
? { ...item, restoreRefreshState: 'failed' } : item);
|
|
15874
|
+
showToast(`Restored “${row.displayName}”. The list could not refresh. Reload this page to show it.`, 'warn');
|
|
15875
|
+
} else showToast(`Restored “${row.displayName}”`, 'ok');
|
|
15876
|
+
} catch (error) { reportErr(error); }
|
|
15877
|
+
finally {
|
|
15878
|
+
restoringWorkflows.delete(workflowId);
|
|
15879
|
+
document.removeEventListener('focusin', trackFocus);
|
|
15880
|
+
if (wfLanding) {
|
|
15881
|
+
renderWorkflowsLanding();
|
|
15882
|
+
if (returnFocus && (document.activeElement === document.body || ownsFocus(document.activeElement))
|
|
15883
|
+
&& !document.getElementById('app')?.classList.contains('mode-workspaces')) {
|
|
15884
|
+
const publication = wfLibrary.find((item) => item.ownedWorkflow?.workflowId === workflowId);
|
|
15885
|
+
const target = restored
|
|
15886
|
+
? $wfLanding.querySelector(`[data-wf-restored="${CSS.escape(workflowId)}"]`)
|
|
15887
|
+
|| $wfLanding.querySelector(publication ? `[data-wf-id="${CSS.escape(publication.id)}"]` : `[data-wf-draft="${CSS.escape(workflowId)}"]`)
|
|
15888
|
+
: $wfLanding.querySelector(`[data-wf-restore="${CSS.escape(workflowId)}"]`);
|
|
15889
|
+
(target && !target.hidden ? target : document.getElementById('wf-landing-title'))?.focus();
|
|
15890
|
+
}
|
|
15891
|
+
}
|
|
15892
|
+
}
|
|
15893
|
+
}
|
|
14672
15894
|
// The Workflows tab's home, the counterpart of the Workspaces landing: a create card and one card per workflow. It
|
|
14673
15895
|
// renders AWARE's library listing; it composes nothing.
|
|
14674
15896
|
const $wfLanding = document.getElementById('wf-landing');
|
|
15897
|
+
// The landing search's query, kept outside the input because the landing re-renders with innerHTML.
|
|
15898
|
+
let wfLandingQuery = '';
|
|
14675
15899
|
function showWorkflowsLanding(on) {
|
|
14676
15900
|
const next = Boolean(on);
|
|
14677
15901
|
if (next === wfLanding && (!next || $wfLanding?.childElementCount)) { if (next) renderWorkflowsLanding(); return; }
|
|
15902
|
+
if (next && !wfLanding) wfLandingQuery = ''; // a fresh visit starts unfiltered
|
|
14678
15903
|
wfLanding = next;
|
|
15904
|
+
if (wfLanding) closeDraftView();
|
|
14679
15905
|
document.body.classList.toggle('wf-landing-open', wfLanding);
|
|
14680
15906
|
if ($wfLanding) $wfLanding.hidden = !wfLanding;
|
|
14681
|
-
|
|
15907
|
+
// Nothing reads routines at startup (only the Routines window, routine events and a few report paths do), so the
|
|
15908
|
+
// cards' "Scheduled" chips need a read here.
|
|
15909
|
+
if (wfLanding) { hideSpotlight(); renderWorkflowsLanding(); void loadRoutinesData(); }
|
|
15910
|
+
else syncSpotlightToMode(); // the canvas is back: a spotlight held back while the list covered it is offered
|
|
14682
15911
|
syncTabTitle();
|
|
14683
15912
|
notifyChatScope();
|
|
14684
15913
|
}
|
|
@@ -14689,34 +15918,133 @@
|
|
|
14689
15918
|
return `${nodes} node${nodes === 1 ? '' : 's'}${provider ? ` · ${provider}` : ''}`;
|
|
14690
15919
|
}
|
|
14691
15920
|
|
|
15921
|
+
// The card's "Scheduled" chip and its tip ('' = no chip). A routine runs the installed app it names, which is the
|
|
15922
|
+
// card's row id. Only an enabled routine that is not broken counts: a paused one, or one whose workflow can no longer
|
|
15923
|
+
// run (the server gives it no next run), never runs on its own.
|
|
15924
|
+
function scheduledRoutineTip(routines, workflowId) {
|
|
15925
|
+
const names = routines.filter((r) => r.enabled && !r.broken && r.workflow === workflowId).map((r) => `“${r.name}”`);
|
|
15926
|
+
if (!names.length) return '';
|
|
15927
|
+
return names.length === 1 ? `Runs automatically from the routine ${names[0]}.`
|
|
15928
|
+
: `Runs automatically from ${names.length} routines: ${names.join(', ')}.`;
|
|
15929
|
+
}
|
|
15930
|
+
|
|
14692
15931
|
function renderWorkflowsLanding() {
|
|
14693
15932
|
if (!$wfLanding) return;
|
|
14694
15933
|
const focusedId = document.activeElement?.closest?.('#wf-landing [data-wf-id]')?.dataset.wfId || null;
|
|
15934
|
+
const search = document.activeElement?.id === 'wf-landing-search' ? document.activeElement : null;
|
|
15935
|
+
const keepCaret = search ? [search.selectionStart, search.selectionEnd] : null;
|
|
15936
|
+
const clearFocused = document.activeElement?.id === 'wf-search-clear';
|
|
15937
|
+
const focusedDraft = document.activeElement?.closest?.('#wf-landing [data-wf-draft]')?.dataset.wfDraft || null;
|
|
15938
|
+
const focusedRestore = document.activeElement?.closest?.('[data-wf-restore]')?.dataset.wfRestore || null;
|
|
15939
|
+
const focusedRestored = document.activeElement?.closest?.('[data-wf-restored]')?.dataset.wfRestored || null;
|
|
14695
15940
|
const esc = (s) => String(s ?? '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
14696
|
-
const
|
|
15941
|
+
const restoredRows = wfOwned.filter((row) => row.status !== 'archived' && row.restoreRefreshState);
|
|
15942
|
+
const restoredIds = new Set(restoredRows.map((row) => row.workflowId));
|
|
15943
|
+
const owned = wfLibrary.filter((row) => row.ownedWorkflow && !restoredIds.has(row.ownedWorkflow.workflowId));
|
|
14697
15944
|
const installed = wfLibrary.filter((row) => !row.ownedWorkflow);
|
|
15945
|
+
// #1890 PR 3b-0: owned workflows the library does not list — drafts, and ones whose installed copy is gone.
|
|
15946
|
+
const unlisted = unlistedOwnedWorkflows().filter((row) => !restoredIds.has(row.workflowId));
|
|
15947
|
+
const archived = wfOwned.filter((row) => row.status === 'archived');
|
|
15948
|
+
const restoredCard = (row) => `<div class="ws-card wf-card wf-card-archived" tabindex="-1" data-wf-restored="${esc(row.workflowId)}">`
|
|
15949
|
+
+ `<div class="ws-body"><div class="wf-card-text"><span class="ws-kind wf-kind is-draft">Restored</span>`
|
|
15950
|
+
+ `<div class="ws-name">${esc(row.displayName)}</div><div class="ws-meta">${esc(row.ownerLabel || 'Standalone')}</div>`
|
|
15951
|
+
+ `<p class="wf-draft-body" role="status">${row.restoreRefreshState === 'failed'
|
|
15952
|
+
? 'Workflow restored. The list could not refresh. Reload this page to show it.' : 'Workflow restored. Refreshing workflow list…'}</p>`
|
|
15953
|
+
+ `</div></div></div>`;
|
|
15954
|
+
const archivedCard = (row) => {
|
|
15955
|
+
const busy = restoringWorkflows.has(row.workflowId);
|
|
15956
|
+
return `<div class="ws-card wf-card wf-card-archived" data-wf-archived="${esc(row.workflowId)}">`
|
|
15957
|
+
+ `<div class="ws-body"><div class="wf-card-text"><span class="ws-kind wf-kind is-draft">Archived</span>`
|
|
15958
|
+
+ `<div class="ws-name">${esc(row.displayName)}</div><div class="ws-meta">${esc(row.ownerLabel || 'Standalone')}</div>`
|
|
15959
|
+
+ `<div class="wf-draft-actions"><button type="button" data-wf-restore="${esc(row.workflowId)}" data-command-id="workflow.unarchive#${esc(row.workflowId)}" data-command-instance-label="${esc(row.displayName)}" data-tip="Restore this workflow to the Workflows page with its files, chat and history"${busy ? ' disabled aria-busy="true"' : ''}>${busy ? 'Restoring…' : 'Restore'}</button></div>`
|
|
15960
|
+
+ `</div></div></div>`;
|
|
15961
|
+
};
|
|
15962
|
+
const draftCard = (row) => {
|
|
15963
|
+
const recompile = Boolean(row.activePublication);
|
|
15964
|
+
const name = row.displayName;
|
|
15965
|
+
const chip = recompile ? 'Needs compiling' : 'Draft';
|
|
15966
|
+
const meta = `${recompile ? 'Compiled copy missing' : 'Not compiled yet'} · ${row.ownerLabel || 'Standalone'}`;
|
|
15967
|
+
return `<div class="ws-card wf-card wf-card-draft" role="button" tabindex="0" data-wf-draft="${esc(row.workflowId)}" data-command-id="shell.workflows-landing-open-draft#${esc(name)}" data-command-instance-label="${esc(name)}">`
|
|
15968
|
+
+ `<div class="ws-body"><div class="wf-card-text"><span class="ws-kind wf-kind is-draft">${chip}</span>`
|
|
15969
|
+
+ `<div class="ws-name">${esc(name)}</div><div class="ws-meta">${esc(meta)}</div></div></div></div>`;
|
|
15970
|
+
};
|
|
14698
15971
|
const card = (row) => {
|
|
14699
15972
|
const ownedRow = row.ownedWorkflow;
|
|
14700
15973
|
const name = ownedRow ? ownedRow.displayName : (row.displayName || row.name || row.id);
|
|
14701
15974
|
const chip = ownedRow ? 'Yours' : 'Installed';
|
|
14702
15975
|
const where = ownedRow ? (row.ownerLabel || 'Standalone') : (PROVIDER_LABELS[row.provider] || 'Installed workflow');
|
|
15976
|
+
const scheduledTip = scheduledRoutineTip(routinesData, row.id);
|
|
14703
15977
|
return `<div class="ws-card wf-card" role="button" tabindex="0" data-wf-id="${esc(row.id)}" data-command-id="shell.workflows-landing-open#${esc(name)}" data-command-instance-label="${esc(name)}">`
|
|
14704
15978
|
+ `<div class="ws-body"><div class="wf-card-text"><span class="ws-kind wf-kind">${chip}</span>`
|
|
15979
|
+
+ (scheduledTip ? `<span class="ws-kind wf-kind wf-scheduled" data-tip="${esc(scheduledTip)}">Scheduled</span>` : '')
|
|
14705
15980
|
+ `<div class="ws-name">${esc(name)}</div><div class="ws-meta">${esc(where)}</div>`
|
|
14706
15981
|
+ `<div class="ws-meta wf-card-nodes">${esc(workflowCardMeta(row))}</div></div></div></div>`;
|
|
14707
15982
|
};
|
|
14708
15983
|
const group = (title, rows, show) => (rows.length
|
|
14709
15984
|
? `${show ? `<div class="wf-group-label">${esc(title)} (${rows.length})</div>` : ''}<div class="ws-grid">${rows.map(card).join('')}</div>` : '');
|
|
14710
|
-
const
|
|
15985
|
+
const yours = unlisted.length + owned.length + restoredRows.length;
|
|
15986
|
+
const both = yours > 0 && installed.length > 0;
|
|
15987
|
+
const yoursGroup = yours
|
|
15988
|
+
? `${both ? `<div class="wf-group-label">Your workflows (${yours})</div>` : ''}<div class="ws-grid">${unlisted.map(draftCard).join('')}${owned.map(card).join('')}${restoredRows.map(restoredCard).join('')}</div>`
|
|
15989
|
+
: '';
|
|
14711
15990
|
$wfLanding.innerHTML = `<div class="ws-head"><div class="ws-head-text"><h2 tabindex="-1" id="wf-landing-title">Workflows</h2>`
|
|
14712
|
-
+ `<p class="ws-sub">Build, run and manage the workflows behind your projects. Ask AI Chat on the left to build one with you.</p></div
|
|
14713
|
-
+ `<div class="ws-
|
|
15991
|
+
+ `<p class="ws-sub">Build, run and manage the workflows behind your projects. Ask AI Chat on the left to build one with you.</p></div>`
|
|
15992
|
+
+ (wfLibrary.length || unlisted.length || archived.length || restoredRows.length ? `<div class="ws-head-actions"><input type="search" id="wf-landing-search" class="ws-landing-search" data-command-id="shell.workflows-landing-search" placeholder="Search workflows" aria-label="Search workflows by name, project or tool" autocomplete="off" spellcheck="false" value="${esc(wfLandingQuery)}"></div>` : '')
|
|
15993
|
+
+ `</div>`
|
|
15994
|
+
+ `<div class="ws-create-grid"><div class="ws-card ws-create ws-card-create wf-create" role="button" tabindex="0" data-wf-new="1" data-command-id="shell.workflows-landing-new">`
|
|
14714
15995
|
+ `<div class="ws-thumb">+</div><div class="ws-body"><div><div class="ws-name">New workflow</div>`
|
|
14715
15996
|
+ `<div class="ws-meta">Name it and choose where it belongs. AI builds it with you.</div></div></div></div></div>`
|
|
14716
|
-
+ (wfLibrary.length
|
|
14717
|
-
?
|
|
14718
|
-
|
|
15997
|
+
+ (wfLibrary.length || unlisted.length || archived.length || restoredRows.length
|
|
15998
|
+
? yoursGroup + group('Installed', installed, both)
|
|
15999
|
+
+ '<div class="ws-empty-note ws-search-empty" id="wf-search-empty" role="status" aria-live="polite"></div>'
|
|
16000
|
+
: '<div class="ws-empty-note">No active workflows yet. Start with New workflow, or ask AI Chat on the left.</div>')
|
|
16001
|
+
+ (archived.length ? `<div class="wf-group-label">Archived (${archived.length})</div><div class="ws-grid">${archived.map(archivedCard).join('')}</div>` : '');
|
|
14719
16002
|
if (focusedId) $wfLanding.querySelector(`[data-wf-id="${CSS.escape(focusedId)}"]`)?.focus();
|
|
16003
|
+
if (focusedDraft) $wfLanding.querySelector(`[data-wf-draft="${CSS.escape(focusedDraft)}"]`)?.focus();
|
|
16004
|
+
if (focusedRestore) $wfLanding.querySelector(`[data-wf-restore="${CSS.escape(focusedRestore)}"]:not(:disabled)`)?.focus();
|
|
16005
|
+
if (focusedRestored) $wfLanding.querySelector(`[data-wf-restored="${CSS.escape(focusedRestored)}"]`)?.focus();
|
|
16006
|
+
if (keepCaret) $wfLanding.querySelector('#wf-landing-search')?.focus();
|
|
16007
|
+
applyWorkflowsLandingSearch(keepCaret);
|
|
16008
|
+
if (clearFocused) $wfLanding.querySelector('#wf-search-clear')?.focus(); // it only exists once the filter ran
|
|
16009
|
+
}
|
|
16010
|
+
|
|
16011
|
+
/** Hide the workflow cards that don't match the landing search: every typed word must appear somewhere in the
|
|
16012
|
+
* card's name or the line under it (its project, or the tool an installed workflow runs on), never in its
|
|
16013
|
+
* "N nodes · tool" line, which every card has. New workflow is an action,
|
|
16014
|
+
* not a result, so it stays. A group with nothing left hides its label; a shown label counts "1 of 3". */
|
|
16015
|
+
function applyWorkflowsLandingSearch(caret) {
|
|
16016
|
+
const input = $wfLanding.querySelector('#wf-landing-search');
|
|
16017
|
+
if (!input) return;
|
|
16018
|
+
const terms = wfLandingQuery.trim().toLowerCase().split(/\s+/).filter(Boolean);
|
|
16019
|
+
let shownAll = 0;
|
|
16020
|
+
for (const grid of $wfLanding.querySelectorAll('.ws-grid')) {
|
|
16021
|
+
const cards = grid.querySelectorAll('.wf-card[data-wf-id], .wf-card[data-wf-draft], .wf-card[data-wf-archived], .wf-card[data-wf-restored]');
|
|
16022
|
+
let shown = 0;
|
|
16023
|
+
for (const card of cards) {
|
|
16024
|
+
const hay = Array.from(card.querySelectorAll('.ws-name, .ws-meta:not(.wf-card-nodes)'), (el) => el.textContent).join(' ').toLowerCase();
|
|
16025
|
+
card.hidden = !terms.every((t) => hay.includes(t));
|
|
16026
|
+
if (!card.hidden) shown++;
|
|
16027
|
+
}
|
|
16028
|
+
grid.hidden = !shown;
|
|
16029
|
+
const label = grid.previousElementSibling?.classList.contains('wf-group-label') ? grid.previousElementSibling : null;
|
|
16030
|
+
if (label) {
|
|
16031
|
+
label.hidden = !shown;
|
|
16032
|
+
label.textContent = label.textContent.replace(/\(\d+(?: of \d+)?\)$/, terms.length ? `(${shown} of ${cards.length})` : `(${cards.length})`);
|
|
16033
|
+
}
|
|
16034
|
+
shownAll += shown;
|
|
16035
|
+
}
|
|
16036
|
+
const note = $wfLanding.querySelector('#wf-search-empty');
|
|
16037
|
+
if (note) {
|
|
16038
|
+
note.textContent = shownAll ? '' : `No workflows match “${wfLandingQuery.trim()}”. `; // text, never markup: it echoes what was typed
|
|
16039
|
+
if (!shownAll) note.insertAdjacentHTML('beforeend', '<button type="button" id="wf-search-clear" data-command-id="shell.workflows-landing-search-clear">Clear search</button>');
|
|
16040
|
+
}
|
|
16041
|
+
if (caret) input.setSelectionRange(caret[0], caret[1]);
|
|
16042
|
+
}
|
|
16043
|
+
function setWorkflowsLandingQuery(q) {
|
|
16044
|
+
wfLandingQuery = q;
|
|
16045
|
+
const input = $wfLanding.querySelector('#wf-landing-search');
|
|
16046
|
+
if (input) input.value = q;
|
|
16047
|
+
applyWorkflowsLandingSearch();
|
|
14720
16048
|
}
|
|
14721
16049
|
|
|
14722
16050
|
// One card opens at a time: loadApp has no ordering of its own, so a second quick click could land first and then
|
|
@@ -14727,18 +16055,256 @@
|
|
|
14727
16055
|
landingOpening = true;
|
|
14728
16056
|
// Leave the landing once the workflow has loaded, so the previous one never flashes up in between; a failed
|
|
14729
16057
|
// load keeps the landing and reports why.
|
|
14730
|
-
|
|
16058
|
+
const loading = loadApp(id);
|
|
16059
|
+
const ticket = selectionTicket;
|
|
16060
|
+
loading.then(() => {
|
|
16061
|
+
if (ticket === selectionTicket && currentId === id) showWorkflowsLanding(false);
|
|
16062
|
+
}).catch(reportErr).finally(() => { landingOpening = false; });
|
|
16063
|
+
}
|
|
16064
|
+
|
|
16065
|
+
// ── Draft workflows (#1890 PR 3b-0) ──────────────────────────────────────────────
|
|
16066
|
+
// A workflow that has no installed copy yet — just created by AI Chat or New workflow, or one whose installed copy
|
|
16067
|
+
// is gone — opens here: what it is, where it lives, and Compile when it has a workflow file. Its AI Chat is the
|
|
16068
|
+
// workflow's own. It renders the owned-workflow record; compiling is the existing publish verb, pressed by a person.
|
|
16069
|
+
const $wfDraft = document.getElementById('wf-draft');
|
|
16070
|
+
|
|
16071
|
+
/** Owned workflows the published library does not list: drafts, and ones whose installed copy is missing. */
|
|
16072
|
+
function unlistedOwnedWorkflows() {
|
|
16073
|
+
const listed = new Set(wfLibrary.map((row) => row.ownedWorkflow?.workflowId).filter(Boolean));
|
|
16074
|
+
const rows = wfOwned.filter((row) => row.status !== 'archived' && !listed.has(row.workflowId));
|
|
16075
|
+
// Drafts first (the newest are what someone just made), then the ones needing compiling again.
|
|
16076
|
+
return rows.sort((a, b) => (Boolean(a.activePublication) - Boolean(b.activePublication))
|
|
16077
|
+
|| String(b.updatedAt || '').localeCompare(String(a.updatedAt || '')));
|
|
16078
|
+
}
|
|
16079
|
+
|
|
16080
|
+
function openDraftWorkflow(workflowId) {
|
|
16081
|
+
const row = wfOwned.find((item) => item.workflowId === workflowId && item.status !== 'archived');
|
|
16082
|
+
if (!row || !$wfDraft) return;
|
|
16083
|
+
selectionTicket += 1;
|
|
16084
|
+
if (draftWorkflow) closeDraftView();
|
|
16085
|
+
draftWorkflow = { workflowId: row.workflowId, displayName: row.displayName, ownerLabel: row.ownerLabel || 'Standalone',
|
|
16086
|
+
hasSource: Boolean(row.hasSource), recompile: Boolean(row.activePublication), compiling: false, busy: false,
|
|
16087
|
+
failed: false, note: null, watch: new AbortController() };
|
|
16088
|
+
currentId = null;
|
|
16089
|
+
workflowSelectionGeneration += 1;
|
|
16090
|
+
if (wfLanding) {
|
|
16091
|
+
wfLanding = false;
|
|
16092
|
+
document.body.classList.remove('wf-landing-open');
|
|
16093
|
+
if ($wfLanding) $wfLanding.hidden = true;
|
|
16094
|
+
}
|
|
16095
|
+
document.body.classList.add('wf-draft-open');
|
|
16096
|
+
$wfDraft.hidden = false;
|
|
16097
|
+
hideSpotlight();
|
|
16098
|
+
paintBeacon(null);
|
|
16099
|
+
renderDraftView();
|
|
16100
|
+
paintDraftChrome();
|
|
16101
|
+
syncTabTitle();
|
|
16102
|
+
notifyChatScope();
|
|
16103
|
+
void watchDraft(draftWorkflow);
|
|
16104
|
+
document.getElementById('wf-draft-title')?.focus();
|
|
16105
|
+
}
|
|
16106
|
+
|
|
16107
|
+
// The AI writes a draft's workflow file from its chat, which raises no workflow event, so an open draft re-reads
|
|
16108
|
+
// its own record every few seconds — that is what reveals Compile once the file exists (#1890 PR 3b-0, rebuilt at the
|
|
16109
|
+
// review stop signal, Fable + Codex). One loop per open draft: the next read starts only after the previous read and
|
|
16110
|
+
// any refresh it started have finished, so this loop never overlaps itself; it pauses while Compile and its own
|
|
16111
|
+
// refresh run (`busy`), and closing the draft ends it and aborts its pending read. Overlap with refreshes started
|
|
16112
|
+
// elsewhere (apps-changed, Compile) is the loadApps generation guard's job, not this loop's.
|
|
16113
|
+
const DRAFT_WATCH_MS = 4000;
|
|
16114
|
+
const sleep = (ms) => new Promise((resolve) => { setTimeout(resolve, ms); });
|
|
16115
|
+
|
|
16116
|
+
async function watchDraft(d) {
|
|
16117
|
+
while (draftWorkflow === d) {
|
|
16118
|
+
await sleep(DRAFT_WATCH_MS);
|
|
16119
|
+
if (draftWorkflow !== d) return;
|
|
16120
|
+
if (d.busy) continue;
|
|
16121
|
+
await readDraftOnce(d);
|
|
16122
|
+
}
|
|
16123
|
+
}
|
|
16124
|
+
|
|
16125
|
+
async function readDraftOnce(d) {
|
|
16126
|
+
let workflow;
|
|
16127
|
+
try {
|
|
16128
|
+
({ workflow } = await api(`/api/workflows/owned/${encodeURIComponent(d.workflowId)}`, { signal: d.watch.signal }));
|
|
16129
|
+
} catch { return; /* aborted on close, or a missed read: the next turn of the loop tries again */ }
|
|
16130
|
+
if (draftWorkflow !== d || d.busy) return;
|
|
16131
|
+
if (workflow.status === 'archived' || (workflow.activePublication?.runtimeAppId && !d.recompile)) {
|
|
16132
|
+
// Its own publication or archive: the refresh decides (resolveOpenDraft), inside this turn of the loop.
|
|
16133
|
+
try { await loadApps(); } catch (error) { if (draftWorkflow === d) reportErr(error); }
|
|
16134
|
+
return;
|
|
16135
|
+
}
|
|
16136
|
+
if (Boolean(workflow.hasSource) !== d.hasSource || workflow.displayName !== d.displayName) {
|
|
16137
|
+
d.hasSource = Boolean(workflow.hasSource);
|
|
16138
|
+
d.displayName = workflow.displayName;
|
|
16139
|
+
renderDraftView();
|
|
16140
|
+
paintDraftChrome();
|
|
16141
|
+
}
|
|
16142
|
+
}
|
|
16143
|
+
|
|
16144
|
+
function closeDraftView() {
|
|
16145
|
+
if (!draftWorkflow) return;
|
|
16146
|
+
draftWorkflow.watch.abort();
|
|
16147
|
+
draftWorkflow = null;
|
|
16148
|
+
document.body.classList.remove('wf-draft-open');
|
|
16149
|
+
if ($wfDraft) { $wfDraft.hidden = true; $wfDraft.innerHTML = ''; }
|
|
16150
|
+
}
|
|
16151
|
+
|
|
16152
|
+
/** The header picker, the tab title and the Instructor band name the draft, not the workflow open before it. */
|
|
16153
|
+
function paintDraftChrome() {
|
|
16154
|
+
const d = draftWorkflow;
|
|
16155
|
+
if (!d) return;
|
|
16156
|
+
setComboTriggerLabel(d.displayName);
|
|
16157
|
+
setComboSelected(null);
|
|
16158
|
+
window.Instructor?.setWorkflow({ name: d.displayName, runState: 'draft', statusLabel: 'Draft', hasSource: d.hasSource,
|
|
16159
|
+
totalInputs: 0, inputsSet: 0 });
|
|
16160
|
+
}
|
|
16161
|
+
|
|
16162
|
+
function renderDraftView() {
|
|
16163
|
+
if (!$wfDraft || !draftWorkflow) return;
|
|
16164
|
+
const d = draftWorkflow;
|
|
16165
|
+
const esc = (s) => String(s ?? '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
16166
|
+
const where = d.ownerLabel === 'Standalone' ? 'Standalone' : `In ${d.ownerLabel}`;
|
|
16167
|
+
const state = d.recompile ? 'Needs compiling again' : 'Draft';
|
|
16168
|
+
let body;
|
|
16169
|
+
let action = '';
|
|
16170
|
+
if (!d.hasSource) {
|
|
16171
|
+
body = d.recompile
|
|
16172
|
+
? 'This workflow’s file is missing. Ask the AI in this chat to write it again.'
|
|
16173
|
+
: 'This workflow has no workflow file yet. Ask the AI in this chat to write it.';
|
|
16174
|
+
} else {
|
|
16175
|
+
body = d.recompile
|
|
16176
|
+
? 'The compiled copy of this workflow is missing or no longer matches. Compile it again to run it.'
|
|
16177
|
+
: 'Not compiled yet. Compile it to run it.';
|
|
16178
|
+
const busy = d.compiling ? ' aria-disabled="true"' : '';
|
|
16179
|
+
action = d.recompile
|
|
16180
|
+
? `<button type="button" class="primary" id="wf-draft-compile" data-command-id="shell.workflow-draft-compile-again"${busy}>${d.compiling ? 'Compiling…' : 'Compile again'}</button>`
|
|
16181
|
+
: `<button type="button" class="primary" id="wf-draft-compile" data-command-id="shell.workflow-draft-compile"${busy}>${d.compiling ? 'Compiling…' : 'Compile'}</button>`;
|
|
16182
|
+
}
|
|
16183
|
+
const failure = d.failed
|
|
16184
|
+
? `<div class="wf-draft-failure" role="alert" tabindex="-1" id="wf-draft-failure">FloLess couldn’t compile this workflow, so it isn’t ready to run yet. Ask the AI in this chat to check the workflow file, then try again.`
|
|
16185
|
+
+ `<div class="wf-draft-actions"><button type="button" class="primary" id="wf-draft-ask" data-command-id="shell.workflow-draft-ask-ai">Ask AI to fix</button>`
|
|
16186
|
+
+ `<button type="button" id="wf-draft-retry" data-command-id="shell.workflow-draft-retry">Try again</button></div></div>`
|
|
16187
|
+
: '';
|
|
16188
|
+
$wfDraft.innerHTML = `<div class="wf-draft-panel">`
|
|
16189
|
+
+ `<h2 class="wf-draft-title" id="wf-draft-title" tabindex="-1">${esc(d.displayName)}</h2>`
|
|
16190
|
+
+ `<div class="wf-draft-where">${esc(where)} · <span class="ws-kind wf-kind is-draft">${state}</span></div>`
|
|
16191
|
+
+ `<p class="wf-draft-body">${esc(body)}</p>`
|
|
16192
|
+
+ (failure || (action ? `<div class="wf-draft-actions">${action}</div>` : ''))
|
|
16193
|
+
+ (d.note ? `<p class="wf-draft-body" role="status">${esc(d.note)}</p>` : '')
|
|
16194
|
+
// #1949: the same Archive the published workflow has in the picker — same command, same confirm — so a draft
|
|
16195
|
+
// someone no longer wants can leave the Workflows page from its own view. Quiet (not primary): it is the exit,
|
|
16196
|
+
// not the next step.
|
|
16197
|
+
+ `<div class="wf-draft-actions wf-draft-exit"><button type="button" class="wf-draft-archive" id="wf-draft-archive" data-command-id="workflow.archive#${esc(d.workflowId)}" data-command-instance-label="${esc(d.displayName)}" data-tip="Hide this workflow from the Workflows page. Its files stay on this computer. Restore it from Archived.">Archive</button></div>`
|
|
16198
|
+
+ `<div class="sr-only" role="status" aria-live="polite" id="wf-draft-status">${d.compiling ? 'Compiling…' : ''}</div>`
|
|
16199
|
+
+ `</div>`;
|
|
16200
|
+
}
|
|
16201
|
+
|
|
16202
|
+
async function compileDraftWorkflow() {
|
|
16203
|
+
const d = draftWorkflow;
|
|
16204
|
+
if (!d || d.compiling || !d.hasSource) return;
|
|
16205
|
+
d.busy = true; // the watch loop stays out until Compile and its own refresh have finished
|
|
16206
|
+
d.compiling = true;
|
|
16207
|
+
d.failed = false;
|
|
16208
|
+
d.note = null;
|
|
16209
|
+
renderDraftView();
|
|
16210
|
+
document.getElementById('wf-draft-compile')?.focus();
|
|
16211
|
+
try {
|
|
16212
|
+
await api(`/api/workflows/owned/${encodeURIComponent(d.workflowId)}/publish`, { method: 'POST' });
|
|
16213
|
+
} catch {
|
|
16214
|
+
// The route's own wording is internal; the person gets the plain sentence and two ways on.
|
|
16215
|
+
d.busy = false;
|
|
16216
|
+
if (draftWorkflow !== d) return;
|
|
16217
|
+
d.compiling = false;
|
|
16218
|
+
d.failed = true;
|
|
16219
|
+
renderDraftView();
|
|
16220
|
+
document.getElementById('wf-draft-failure')?.focus();
|
|
16221
|
+
return;
|
|
16222
|
+
}
|
|
16223
|
+
// Compiled. The refresh finds this draft's own publication and opens it, keeping its chat (resolveOpenDraft).
|
|
16224
|
+
d.compiling = false;
|
|
16225
|
+
try {
|
|
16226
|
+
await loadApps();
|
|
16227
|
+
} catch (error) {
|
|
16228
|
+
reportErr(error);
|
|
16229
|
+
} finally {
|
|
16230
|
+
d.busy = false;
|
|
16231
|
+
}
|
|
16232
|
+
if (draftWorkflow === d) {
|
|
16233
|
+
// Still here: compiled, but not opened yet — say so truthfully, never "couldn't compile".
|
|
16234
|
+
d.note = `${d.displayName} is compiled. FloLess couldn’t open it yet — open it from the Workflows page.`;
|
|
16235
|
+
renderDraftView();
|
|
16236
|
+
}
|
|
16237
|
+
}
|
|
16238
|
+
|
|
16239
|
+
/**
|
|
16240
|
+
* After a refresh, the open draft's own fate only (#1890 PR 3b-0): published now → open the published workflow,
|
|
16241
|
+
* its chat staying; archived or gone → back to the landing, saying so; otherwise it stays, its file state refreshed.
|
|
16242
|
+
*/
|
|
16243
|
+
async function resolveOpenDraft() {
|
|
16244
|
+
const d = draftWorkflow;
|
|
16245
|
+
if (!d) return;
|
|
16246
|
+
const published = wfLibrary.find((row) => row.ownedWorkflow?.workflowId === d.workflowId);
|
|
16247
|
+
if (published) { await loadApp(published.id); return; }
|
|
16248
|
+
const row = wfOwned.find((item) => item.workflowId === d.workflowId);
|
|
16249
|
+
if (!row || row.status === 'archived') {
|
|
16250
|
+
const name = d.displayName;
|
|
16251
|
+
closeDraftView();
|
|
16252
|
+
showWorkflowsLanding(true);
|
|
16253
|
+
document.getElementById('wf-landing-title')?.focus();
|
|
16254
|
+
showToast(`${name} was archived or removed.`, 'info');
|
|
16255
|
+
return;
|
|
16256
|
+
}
|
|
16257
|
+
d.hasSource = Boolean(row.hasSource);
|
|
16258
|
+
d.recompile = Boolean(row.activePublication);
|
|
16259
|
+
d.displayName = row.displayName;
|
|
16260
|
+
d.ownerLabel = row.ownerLabel || d.ownerLabel;
|
|
16261
|
+
if (!d.compiling) renderDraftView();
|
|
16262
|
+
paintDraftChrome();
|
|
16263
|
+
}
|
|
16264
|
+
|
|
16265
|
+
if ($wfDraft) {
|
|
16266
|
+
$wfDraft.addEventListener('click', (event) => {
|
|
16267
|
+
if (event.target.closest('#wf-draft-compile, #wf-draft-retry')) { void compileDraftWorkflow(); return; }
|
|
16268
|
+
if (event.target.closest('#wf-draft-archive') && draftWorkflow) { void archiveOwnedWorkflow(draftWorkflow.workflowId, draftWorkflow.displayName); return; }
|
|
16269
|
+
if (event.target.closest('#wf-draft-ask') && draftWorkflow) {
|
|
16270
|
+
const name = draftWorkflow.displayName;
|
|
16271
|
+
void window.flolessChat?.openDraft?.(`FloLess couldn't compile the workflow "${name}". Please check its workflow file and fix what stops it compiling.`)?.catch(reportErr);
|
|
16272
|
+
}
|
|
16273
|
+
});
|
|
14731
16274
|
}
|
|
14732
16275
|
|
|
14733
16276
|
if ($wfLanding) {
|
|
14734
16277
|
$wfLanding.addEventListener('click', (event) => {
|
|
16278
|
+
const restore = event.target.closest('[data-wf-restore]');
|
|
16279
|
+
if (restore) {
|
|
16280
|
+
if (!restore.disabled) {
|
|
16281
|
+
// Canvas panning cancels native mouse focus. This activated control owns the return
|
|
16282
|
+
// focus; restoreOwnedWorkflow still yields it if the person moves elsewhere while waiting.
|
|
16283
|
+
restore.focus();
|
|
16284
|
+
void restoreOwnedWorkflow(restore.dataset.wfRestore);
|
|
16285
|
+
}
|
|
16286
|
+
return;
|
|
16287
|
+
}
|
|
14735
16288
|
if (event.target.closest('[data-wf-new]')) { requestNewWorkflow(); return; }
|
|
16289
|
+
// Clearing empties the message the button sits in, so focus goes back to the search box.
|
|
16290
|
+
if (event.target.closest('#wf-search-clear')) { setWorkflowsLandingQuery(''); $wfLanding.querySelector('#wf-landing-search')?.focus(); return; }
|
|
16291
|
+
const draftEl = event.target.closest('[data-wf-draft]');
|
|
16292
|
+
if (draftEl) { if (!landingOpening) openDraftWorkflow(draftEl.dataset.wfDraft); return; }
|
|
14736
16293
|
const cardEl = event.target.closest('[data-wf-id]');
|
|
14737
16294
|
if (cardEl) openWorkflowFromLanding(cardEl.dataset.wfId);
|
|
14738
16295
|
});
|
|
16296
|
+
$wfLanding.addEventListener('input', (event) => {
|
|
16297
|
+
if (event.target.id !== 'wf-landing-search') return;
|
|
16298
|
+
wfLandingQuery = event.target.value;
|
|
16299
|
+
applyWorkflowsLandingSearch();
|
|
16300
|
+
});
|
|
14739
16301
|
$wfLanding.addEventListener('keydown', (event) => {
|
|
16302
|
+
// Esc clears a search that has text; an empty box lets Esc through to whatever else listens for it.
|
|
16303
|
+
if (event.key === 'Escape' && event.target.id === 'wf-landing-search' && event.target.value) {
|
|
16304
|
+
event.preventDefault(); event.stopPropagation(); setWorkflowsLandingQuery(''); return;
|
|
16305
|
+
}
|
|
14740
16306
|
if (event.key !== 'Enter' && event.key !== ' ') return;
|
|
14741
|
-
const target = event.target.closest('[data-wf-id], [data-wf-new]');
|
|
16307
|
+
const target = event.target.closest('[data-wf-id], [data-wf-new], [data-wf-draft]');
|
|
14742
16308
|
if (!target || target !== event.target) return;
|
|
14743
16309
|
event.preventDefault();
|
|
14744
16310
|
target.click();
|
|
@@ -14751,6 +16317,8 @@
|
|
|
14751
16317
|
|
|
14752
16318
|
window.flolessBridge = {
|
|
14753
16319
|
api,
|
|
16320
|
+
/** #2046: the ≡ menu's New workflow, opened from a Guide suggestion with its name filled in. */
|
|
16321
|
+
newWorkflow: (prefill) => requestNewWorkflow(prefill),
|
|
14754
16322
|
requestScopeLabel(projectId) {
|
|
14755
16323
|
return wsRequestScope?.kind === 'project' && wsRequestScope.project === projectId
|
|
14756
16324
|
? wsRequestScope.label : null;
|
|
@@ -14772,6 +16340,37 @@
|
|
|
14772
16340
|
return openRequests(requestId || null);
|
|
14773
16341
|
},
|
|
14774
16342
|
preferredChatProvider,
|
|
16343
|
+
// #1997: open an installed workflow by its AWARE app id (the "Open workflow" next step of Approve updated
|
|
16344
|
+
// workflows, e.g. "open it and press Compile").
|
|
16345
|
+
// Only a workflow the Workflows page lists can be opened; one installed outside FloLess (from a terminal) is not.
|
|
16346
|
+
canOpenApp: (appId) => wfLibrary.some((row) => row.id === appId),
|
|
16347
|
+
async openApp(appId) {
|
|
16348
|
+
await window.flolessWorkspaces?.setMode?.('workflows');
|
|
16349
|
+
await loadApps();
|
|
16350
|
+
if (!wfLibrary.some((row) => row.id === appId)) {
|
|
16351
|
+
throw new Error('That workflow is not on your Workflows page, so FloLess cannot open it. Compile it from the terminal that installed it.');
|
|
16352
|
+
}
|
|
16353
|
+
await loadApp(appId);
|
|
16354
|
+
showWorkflowsLanding(false);
|
|
16355
|
+
return true;
|
|
16356
|
+
},
|
|
16357
|
+
// #1890 PR 3b: open a FloLess-owned workflow by its id — its published app when it has one, otherwise its draft
|
|
16358
|
+
// view — so a conversation that moved into it can be followed there. Throws a plain sentence when it is gone.
|
|
16359
|
+
async openOwnedWorkflow(workflowId) {
|
|
16360
|
+
await window.flolessWorkspaces?.setMode?.('workflows');
|
|
16361
|
+
await loadApps();
|
|
16362
|
+
const published = wfLibrary.find((row) => row.ownedWorkflow?.workflowId === workflowId);
|
|
16363
|
+
if (published) {
|
|
16364
|
+
await loadApp(published.id);
|
|
16365
|
+
showWorkflowsLanding(false);
|
|
16366
|
+
return true;
|
|
16367
|
+
}
|
|
16368
|
+
if (wfOwned.some((row) => row.workflowId === workflowId && row.status !== 'archived')) {
|
|
16369
|
+
openDraftWorkflow(workflowId);
|
|
16370
|
+
return true;
|
|
16371
|
+
}
|
|
16372
|
+
throw new Error('That workflow is no longer here, so its conversation can’t be opened.');
|
|
16373
|
+
},
|
|
14775
16374
|
// The New project dialog's AI choice (#1605): the installed Claude/Codex rows as last read, and
|
|
14776
16375
|
// a fresh read of them. The same shared runtime state preferredChatProvider() answers from, so
|
|
14777
16376
|
// the dialog's default and its options can never disagree.
|
|
@@ -14872,14 +16471,15 @@
|
|
|
14872
16471
|
// Tab title: workspaces.js owns which project is open, aware.js owns document.title (one
|
|
14873
16472
|
// writer — the workflow combo keeps updating underneath in Workspaces mode). Pass the open
|
|
14874
16473
|
// project's name, 'Workspaces' on the landing, or null to hand the tab back to the workflow.
|
|
14875
|
-
setWorkspaceTitle(name, landing = false, projectId = null) {
|
|
16474
|
+
setWorkspaceTitle(name, landing = false, projectId = null, kind = null) {
|
|
14876
16475
|
wsTitleName = name || null;
|
|
16476
|
+
wsTitleKind = wsTitleName && kind === 'agents' ? 'agents' : null;
|
|
14877
16477
|
wsTitleLanding = !!(wsTitleName && landing);
|
|
14878
16478
|
wsTitleProjectId = wsTitleName && !wsTitleLanding ? projectId || null : null;
|
|
14879
16479
|
syncTabTitle();
|
|
14880
16480
|
if (window.Instructor && typeof window.Instructor.setWorkspace === 'function') {
|
|
14881
16481
|
window.Instructor.setWorkspace(wsTitleName
|
|
14882
|
-
? { name: wsTitleName, landing: wsTitleLanding, projectId: wsTitleProjectId }
|
|
16482
|
+
? { name: wsTitleName, landing: wsTitleLanding, projectId: wsTitleProjectId, ...(wsTitleKind ? { kind: wsTitleKind } : {}) }
|
|
14883
16483
|
: null);
|
|
14884
16484
|
}
|
|
14885
16485
|
notifyChatScope();
|
|
@@ -14888,13 +16488,18 @@
|
|
|
14888
16488
|
// Instructor mounts, so expose the last visible title for a one-time initialization replay.
|
|
14889
16489
|
getWorkspaceContext() {
|
|
14890
16490
|
return wsTitleName
|
|
14891
|
-
? { name: wsTitleName, landing: wsTitleLanding, projectId: wsTitleProjectId }
|
|
16491
|
+
? { name: wsTitleName, landing: wsTitleLanding, projectId: wsTitleProjectId, ...(wsTitleKind ? { kind: wsTitleKind } : {}) }
|
|
14892
16492
|
: null;
|
|
14893
16493
|
},
|
|
14894
16494
|
getChatScope() {
|
|
14895
16495
|
return currentChatScope();
|
|
14896
16496
|
},
|
|
16497
|
+
// #2007: the workflow spotlight follows the tab switch (see syncSpotlightToMode).
|
|
16498
|
+
syncGuideSpotlight: () => syncSpotlightToMode(),
|
|
14897
16499
|
// #1890: the active Workflows tab is the way home to the Workflows landing (as Workspaces' is to its own).
|
|
16500
|
+
// workspaces.js calls this when the user switches back into Workflows: the landing stays mounted behind
|
|
16501
|
+
// Workspaces, so showWorkflowsLanding's own fresh-visit reset never runs on that path.
|
|
16502
|
+
resetWorkflowsLandingSearch() { if ($wfLanding) setWorkflowsLandingQuery(''); },
|
|
14898
16503
|
showWorkflowsLanding() {
|
|
14899
16504
|
showWorkflowsLanding(true);
|
|
14900
16505
|
document.getElementById('wf-landing-title')?.focus();
|