@floless/app 0.156.0 → 0.158.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli-actions.mjs +28 -5
- package/dist/floless-server.cjs +110947 -67461
- package/dist/schemas/drawing-check.profile.v1.schema.json +15 -2
- package/dist/schemas/steel.model.v2.schema.json +25 -1
- package/dist/skills/floless-app-actions/SKILL.md +82 -17
- package/dist/skills/floless-app-knowledge/SKILL.md +34 -2
- package/dist/skills/floless-app-knowledge/references/schema.md +4 -1
- package/dist/skills/floless-app-new-workflow/SKILL.md +23 -7
- package/dist/skills/floless-app-onboarding/SKILL.md +31 -1
- package/dist/skills/floless-app-report-issue/SKILL.md +3 -3
- package/dist/skills/floless-app-rfi/SKILL.md +40 -6
- package/dist/skills/floless-app-routines/SKILL.md +9 -2
- package/dist/skills/floless-app-steel-model/SKILL.md +35 -1
- package/dist/skills/floless-app-steel-model/references/detail-from-a-screenshot.md +4 -2
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +51 -1
- package/dist/skills/floless-app-tweak-contract/SKILL.md +25 -5
- package/dist/skills/floless-app-workflows/SKILL.md +46 -10
- package/dist/skills/floless-app-workflows/references/agent-steps.md +119 -0
- package/dist/web/agent-steps.js +864 -47
- package/dist/web/agents.js +28 -8
- package/dist/web/app.css +620 -17
- package/dist/web/app.js +110 -11
- package/dist/web/aware-update-client.js +1 -0
- package/dist/web/aware.js +921 -220
- package/dist/web/chat-landing-scene.js +372 -0
- package/dist/web/chat.css +263 -1
- package/dist/web/chat.js +2660 -86
- package/dist/web/commands-drawing-check.js +17 -0
- package/dist/web/commands-shell.js +1059 -8
- package/dist/web/commands-steel.js +6 -0
- package/dist/web/connections.js +1 -0
- package/dist/web/drawing-check-editor.html +33 -5
- package/dist/web/drawing-check-editor.js +538 -22
- package/dist/web/drawing-check-overlay.js +13 -0
- package/dist/web/flo-avatar.js +28 -3
- package/dist/web/guide.js +7 -2
- package/dist/web/index.html +143 -8
- package/dist/web/instructor.js +4 -4
- package/dist/web/kb-categories.js +351 -0
- package/dist/web/kb-graph-worker.js +73 -0
- package/dist/web/model-view-query.js +12 -2
- package/dist/web/pages.js +978 -39
- package/dist/web/panels.js +5 -2
- package/dist/web/parser-setup-recovery.js +12 -4
- package/dist/web/project-access.js +549 -0
- package/dist/web/run-page-view.js +353 -0
- package/dist/web/startup-admission.js +132 -0
- package/dist/web/steel-3d-core.js +9 -0
- package/dist/web/steel-editor.html +681 -22
- package/dist/web/steel-model-v2-commands.js +63 -5
- package/dist/web/step-rename.js +287 -0
- package/dist/web/tab-signal.js +323 -0
- package/dist/web/terminal-requests.js +103 -13
- package/dist/web/tool-updates.js +1 -0
- package/dist/web/workspace-root-management.js +39 -0
- package/dist/web/workspaces.js +2883 -146
- package/launch-starting-page.mjs +181 -0
- package/launch.mjs +97 -12
- package/package.json +5 -1
|
@@ -59,10 +59,38 @@ const carryAssumed = (prev, next) => (prev && prev.assumed === true
|
|
|
59
59
|
// the new number is no longer what they answered (and a typed elevation is their own statement anyway).
|
|
60
60
|
: prev && prev.answered && typeof prev.answered === 'object' && next && next.known === prev.known
|
|
61
61
|
? { ...next, answered: prev.answered }
|
|
62
|
-
:
|
|
62
|
+
// A height the AI DECIDED in a Quick build (#2521) rides along on every move, like a placed one: a
|
|
63
|
+
// translated AI height is still the AI's. Only a person typing an elevation replaces it.
|
|
64
|
+
: prev && prev.decided && typeof prev.decided === 'object' && next
|
|
65
|
+
? { ...next, decided: prev.decided }
|
|
66
|
+
: next);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The decision an end's height was DERIVED from (#2521): a copy, a split or a merge makes a new end whose height
|
|
70
|
+
* came from an AI decision about another end. It still rests on that decision, so the mark stays, but `derived`
|
|
71
|
+
* says it is not the decision's own subject, so Make precise never asks it as if it were.
|
|
72
|
+
*/
|
|
73
|
+
const derivedDecision = (decided) => ({ ...decided, derived: true });
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* One DERIVED decision standing for every AI decision a new end's height came from (#2521, Codex review): a split
|
|
77
|
+
* point between two AI heights, or a merge of members that each carry one, rests on all of them. The first is
|
|
78
|
+
* `decisionId`; the others are `alsoRestsOn`, so Make precise can ask every one. `null` when none is the AI's.
|
|
79
|
+
*/
|
|
80
|
+
function derivedFromAll(zs) {
|
|
81
|
+
const decided = zs.filter((z) => z && z.decided && typeof z.decided === 'object');
|
|
82
|
+
if (!decided.length) return null;
|
|
83
|
+
const first = decided[0].decided;
|
|
84
|
+
const others = [...new Set(decided.flatMap((z) => [z.decided.decisionId, ...(z.decided.alsoRestsOn || [])]))]
|
|
85
|
+
.filter((id) => id !== first.decisionId);
|
|
86
|
+
const { alsoRestsOn: _drop, ...rest } = first;
|
|
87
|
+
return { ...rest, derived: true, ...(others.length ? { alsoRestsOn: others } : {}) };
|
|
88
|
+
}
|
|
63
89
|
|
|
64
90
|
/** A copied member is a NEW member: an answer the person gave about the original is not an answer about it. */
|
|
65
|
-
const withoutAnswer = (z) => (z && z.answered ? { known: z.known }
|
|
91
|
+
const withoutAnswer = (z) => (z && z.answered ? { known: z.known }
|
|
92
|
+
: z && z.decided && typeof z.decided === 'object' ? { known: z.known, decided: derivedDecision(z.decided) }
|
|
93
|
+
: z);
|
|
66
94
|
|
|
67
95
|
/*
|
|
68
96
|
* The drag-start snapshot `moveWorkPoints` compares against — every field the gizmo's availability, its
|
|
@@ -552,6 +580,19 @@ function assertSplitInferredSupportAuthority(doc) {
|
|
|
552
580
|
}
|
|
553
581
|
}
|
|
554
582
|
|
|
583
|
+
/**
|
|
584
|
+
* The end whose mark a split point inherits: a placed end first (#1155), else an end the AI decided (#2521), as a
|
|
585
|
+
* DERIVED decision, since the split point is a new end, not the decision's own subject.
|
|
586
|
+
*/
|
|
587
|
+
function splitMarkSource(fromZ, toZ) {
|
|
588
|
+
// A placed end wins over an AI one: it is the weaker claim (unproven, left out of the BOM, asked), so the split
|
|
589
|
+
// point never reads as more settled than its least settled end.
|
|
590
|
+
if (fromZ.assumed === true) return fromZ;
|
|
591
|
+
if (toZ.assumed === true) return toZ;
|
|
592
|
+
const decided = derivedFromAll([fromZ, toZ]);
|
|
593
|
+
return decided ? { known: fromZ.known, decided } : fromZ;
|
|
594
|
+
}
|
|
595
|
+
|
|
555
596
|
function interpolatedSplitPoint(original, t) {
|
|
556
597
|
const point = {
|
|
557
598
|
x: quantizeMm(original.from.x + (original.to.x - original.from.x) * t),
|
|
@@ -562,7 +603,7 @@ function interpolatedSplitPoint(original, t) {
|
|
|
562
603
|
// new members with new ids that no diff against the original could catch.
|
|
563
604
|
z: isKnown(original.from.z) && isKnown(original.to.z)
|
|
564
605
|
? carryAssumed(
|
|
565
|
-
original.from.z
|
|
606
|
+
splitMarkSource(original.from.z, original.to.z),
|
|
566
607
|
{ known: quantizeMm(original.from.z.known + (original.to.z.known - original.from.z.known) * t) },
|
|
567
608
|
)
|
|
568
609
|
: { unknown: true },
|
|
@@ -600,6 +641,11 @@ function splitMemberAt(doc, memberId, t, expect, mintId, { requireKnownElevation
|
|
|
600
641
|
const first = clone(original), second = clone(original);
|
|
601
642
|
first.id = mintId(); second.id = mintId();
|
|
602
643
|
first.to = clone(split); second.from = clone(split);
|
|
644
|
+
// #2521: the halves are NEW members, so an AI decision on the original's outer ends is not their own subject.
|
|
645
|
+
for (const [half, key] of [[first, 'from'], [second, 'to']]) {
|
|
646
|
+
const z = half[key].z;
|
|
647
|
+
if (z && z.decided && typeof z.decided === 'object') half[key] = { ...half[key], z: { ...z, decided: derivedDecision(z.decided) } };
|
|
648
|
+
}
|
|
603
649
|
if (Array.isArray(original.ends)) {
|
|
604
650
|
first.ends = [clone(original.ends[0] || {}), {}];
|
|
605
651
|
second.ends = [{}, clone(original.ends[1] || {})];
|
|
@@ -749,7 +795,11 @@ function mergeMemberGroup(doc, sheet, memberIds, mergedPx, mintId, resolveSectio
|
|
|
749
795
|
// MERGE is split's inverse and needs the same rule: if either source end was placed rather than
|
|
750
796
|
// proven, so is the survivor's. The survivor gets a NEW id, so nothing downstream can compare it
|
|
751
797
|
// against the originals to notice the mark went missing.
|
|
752
|
-
|
|
798
|
+
// And an end the AI decided (#2521), carried as DERIVED: the survivor is a new member, not the decision's subject.
|
|
799
|
+
// Every source's decision, not only the first (Codex review). A placed end still wins: it is the weaker claim.
|
|
800
|
+
const allDecided = derivedFromAll(sources.flatMap((m) => [m.from.z, m.to.z]));
|
|
801
|
+
const anyAssumed = sources.flatMap((m) => [m.from.z, m.to.z]).find((z) => z && z.assumed === true)
|
|
802
|
+
|| (allDecided ? { known: 0, decided: allDecided } : null);
|
|
753
803
|
merged.from = {x:physical.from[0],y:physical.from[1],z:carryAssumed(anyAssumed,{known:physical.from[2]})};
|
|
754
804
|
merged.to = {x:physical.to[0],y:physical.to[1],z:carryAssumed(anyAssumed,{known:physical.to[2]})};
|
|
755
805
|
for (const joint of doc.joints || []) {
|
|
@@ -1194,6 +1244,11 @@ export function createV2CommandSession(model, options = {}) {
|
|
|
1194
1244
|
const member = memberById(doc, memberId);
|
|
1195
1245
|
if (member.role === 'column') return { changedIds: [] };
|
|
1196
1246
|
[member.from.z, member.to.z] = [member.to.z, member.from.z];
|
|
1247
|
+
// #2521: an AI decision names its end; swapped onto the other end it is no longer that end's own subject.
|
|
1248
|
+
for (const key of ['from', 'to']) {
|
|
1249
|
+
const z = member[key].z;
|
|
1250
|
+
if (z && z.decided && typeof z.decided === 'object') member[key].z = { ...z, decided: derivedDecision(z.decided) };
|
|
1251
|
+
}
|
|
1197
1252
|
if (member.ends) member.ends = [member.ends[1] || {}, member.ends[0] || {}];
|
|
1198
1253
|
for (const plan of doc.plans || []) for (const dim of plan.dims || []) {
|
|
1199
1254
|
for (const key of ['aRef', 'bRef']) {
|
|
@@ -1291,7 +1346,10 @@ export function createV2CommandSession(model, options = {}) {
|
|
|
1291
1346
|
const source = endpoint(member, from);
|
|
1292
1347
|
known(source.z, `${memberId}.${from}`);
|
|
1293
1348
|
known(endpoint(member, to).z, `${memberId}.${to}`);
|
|
1294
|
-
|
|
1349
|
+
// #2521: a height copied onto another end is not that end's own AI decision: it is derived from it.
|
|
1350
|
+
const copied = clone(source.z);
|
|
1351
|
+
setEndpoint(member, to, { ...endpoint(member, to), z: copied && copied.decided && typeof copied.decided === 'object'
|
|
1352
|
+
? { ...copied, decided: derivedDecision(copied.decided) } : copied });
|
|
1295
1353
|
member.ends = member.ends || [{}, {}];
|
|
1296
1354
|
member.ends[to] = clone(member.ends[from] || {});
|
|
1297
1355
|
return { changedIds: [memberId] };
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Two steps share one name (#2314, epic #2241 slice 3c).
|
|
3
|
+
*
|
|
4
|
+
* When AWARE refuses to compile a workflow because two steps resolve to the same name (`E_APP_AMBIGUOUS_NODE_ID`), the server
|
|
5
|
+
* answers Compile with an ask instead of a dead end. This dialog is that ask: which of the two steps to rename (AWARE's suggestion
|
|
6
|
+
* first), the new name, the exact change in the file (an AWARE dry run, nothing written), and anything FloLess cannot be sure
|
|
7
|
+
* about. The rename is applied only when the person presses the primary button, and only exactly as previewed: the server
|
|
8
|
+
* re-makes the preview under the source lock and refuses a different one. The primary's label carries any extra consent
|
|
9
|
+
* ("Rename anyway", "Rewrite and rename"). Afterwards the caller compiles again, so the workflow is approved again and an AI
|
|
10
|
+
* step's confirmation is asked of the person again; this file never approves anything.
|
|
11
|
+
*/
|
|
12
|
+
(function () {
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
const NOTE = 'Renaming edits the workflow file, so it needs compiling and approving again. If it has an AI step, you confirm that step again too.';
|
|
16
|
+
const PREVIEW_DELAY_MS = 300;
|
|
17
|
+
|
|
18
|
+
const esc = (value) => String(value ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
19
|
+
const routeOf = (target) => (target.kind === 'installed'
|
|
20
|
+
? `/api/app/${encodeURIComponent(target.id)}/steps`
|
|
21
|
+
: `/api/workflows/owned/${encodeURIComponent(target.workflowId)}/steps`);
|
|
22
|
+
|
|
23
|
+
/** How a step is named in the dialog: where it sits, in plain words, with its name in code type. */
|
|
24
|
+
function stepLabel(step) {
|
|
25
|
+
if (!step) return 'This step';
|
|
26
|
+
return step.where && step.where !== 'a top-level step'
|
|
27
|
+
? `The step <span class="sr-code">“${esc(step.id)}”</span> ${esc(step.where)}`
|
|
28
|
+
: `The top-level step <span class="sr-code">“${esc(step.id)}”</span>`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The same, as plain text (a radio's accessible name). */
|
|
32
|
+
function stepText(step, fallback) {
|
|
33
|
+
if (!step) return `The step “${fallback}”`;
|
|
34
|
+
return step.where && step.where !== 'a top-level step' ? `The step “${step.id}” ${step.where}` : `The top-level step “${step.id}”`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The words of the dialog for one preview. Pure: no DOM, so it can be tested on its own. */
|
|
38
|
+
function previewView(preview, step) {
|
|
39
|
+
const edits = Array.isArray(preview.edits) ? preview.edits : [];
|
|
40
|
+
const uncertain = Array.isArray(preview.uncertain) ? preview.uncertain : [];
|
|
41
|
+
// Every planned edit, in a scroll box: "Exact change in the file" is exactly that, never a sample.
|
|
42
|
+
const shown = edits.map((e) =>
|
|
43
|
+
`<span class="sr-was">Line ${esc(e.line)} before: ${esc(String(e.before).trim())}</span>\n<span class="sr-now">Line ${esc(e.line)} after: ${esc(String(e.after).trim())}</span>`).join('\n');
|
|
44
|
+
const sentence = `${stepLabel(step)} will be called <span class="sr-code">“${esc(preview.to)}”</span>.`
|
|
45
|
+
+ (edits.length > 1 ? ` ${edits.length} places in the file change.` : '');
|
|
46
|
+
const body = `<div>${sentence}</div>`
|
|
47
|
+
+ (edits.length ? `<div class="fm-note-label">Exact change in the file</div><pre class="sr-lines" tabindex="0" aria-label="Exact change in the file">${shown}</pre>` : '');
|
|
48
|
+
const warnings = [];
|
|
49
|
+
if (uncertain.length) {
|
|
50
|
+
warnings.push(`<b>Check these.</b> After the rename they may read a different step:<ul class="sr-warning-list">${uncertain.map((u) =>
|
|
51
|
+
`<li><span class="sr-code">“${esc(u.text)}”</span>${u.step ? ` in the “${esc(u.step)}” step` : ''}</li>`).join('')}</ul>`);
|
|
52
|
+
}
|
|
53
|
+
if (preview.needsRewrite) warnings.push('<b>Heads up.</b> Renaming rewrites the whole workflow file, which removes its comments.');
|
|
54
|
+
const primary = uncertain.length && preview.needsRewrite ? 'Rewrite and rename anyway'
|
|
55
|
+
: uncertain.length ? 'Rename anyway' : preview.needsRewrite ? 'Rewrite and rename' : 'Rename step';
|
|
56
|
+
return { body, warning: warnings.join('<br>'), primary };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function post(url, body) {
|
|
60
|
+
const response = await fetch(url, { method: 'POST', credentials: 'same-origin', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) });
|
|
61
|
+
const data = await response.json().catch(() => ({}));
|
|
62
|
+
return { status: response.status, data };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let isOpen = false;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Show the ask. Resolves `{ renamed: true, result }` once the server renamed the step, else `{ renamed: false }`.
|
|
69
|
+
* `ask` is the server's `ambiguous-step-name` ask; `ask.target` says which workflow file it is about.
|
|
70
|
+
*/
|
|
71
|
+
function open(ask) {
|
|
72
|
+
const root = document.getElementById('step-rename-modal');
|
|
73
|
+
if (!root || isOpen || !ask || !Array.isArray(ask.repairs) || !ask.repairs.length) return Promise.resolve({ renamed: false });
|
|
74
|
+
isOpen = true;
|
|
75
|
+
const $ = (id) => document.getElementById(id);
|
|
76
|
+
const ok = $('sr-ok'); const hint = $('sr-hint'); const err = $('sr-error'); const input = $('sr-name');
|
|
77
|
+
const msg = $('sr-name-msg'); const pv = $('sr-preview'); const warning = $('sr-warning');
|
|
78
|
+
const returnTo = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
79
|
+
const route = routeOf(ask.target);
|
|
80
|
+
const stepOf = (path) => (ask.steps || []).find((s) => s.path === path);
|
|
81
|
+
let choice = Math.max(0, ask.repairs.findIndex((r) => r.isDefault));
|
|
82
|
+
let dirty = false;
|
|
83
|
+
let preview = null;
|
|
84
|
+
let seq = 0;
|
|
85
|
+
let busy = false;
|
|
86
|
+
let timer = null;
|
|
87
|
+
|
|
88
|
+
return new Promise((resolve) => {
|
|
89
|
+
const setReady = (ready, why) => {
|
|
90
|
+
ok.setAttribute('aria-disabled', ready && !busy ? 'false' : 'true');
|
|
91
|
+
hint.textContent = ready ? '' : why || '';
|
|
92
|
+
hint.classList.remove('nudge');
|
|
93
|
+
};
|
|
94
|
+
const showError = (text) => { err.textContent = text || ''; err.hidden = !text; };
|
|
95
|
+
const setEditable = (on) => {
|
|
96
|
+
input.readOnly = !on;
|
|
97
|
+
root.querySelectorAll('input[name="sr-step"]').forEach((r) => { r.disabled = !on; });
|
|
98
|
+
};
|
|
99
|
+
const nameError = (text, suggestedId) => {
|
|
100
|
+
input.setAttribute('aria-invalid', text ? 'true' : 'false');
|
|
101
|
+
msg.classList.toggle('is-error', !!text);
|
|
102
|
+
// With a suggestion on offer the button asks the question, so the sentence drops its own "Use X instead?".
|
|
103
|
+
const shown = suggestedId ? String(text).replace(/\s*Use “[^”]*” instead\?\s*$/, '') : text;
|
|
104
|
+
msg.innerHTML = text ? esc(shown) + (suggestedId && suggestedId !== input.value.trim()
|
|
105
|
+
? ` <button type="button" class="sr-use" data-sr-use="${esc(suggestedId)}" data-command-id="shell.step-rename-use-suggested">Use “${esc(suggestedId)}”</button>` : '') : '';
|
|
106
|
+
};
|
|
107
|
+
const paintSteps = () => {
|
|
108
|
+
const many = (ask.steps || []).length > 2;
|
|
109
|
+
$('sr-sub').textContent = `${many ? `${ask.steps.length} steps are all` : 'Both are'} called “${ask.scopedId}”, so the workflow can’t tell which one is meant. Rename one of them, then compile again.`;
|
|
110
|
+
$('sr-steps').innerHTML = ask.repairs.map((r, i) => {
|
|
111
|
+
const step = stepOf(r.nodePath);
|
|
112
|
+
return `<label class="sr-step"><input type="radio" name="sr-step" value="${i}"${i === choice ? ' checked' : ''}`
|
|
113
|
+
+ ` data-command-id="shell.step-rename-choose#${esc(r.nodePath)}" data-command-instance-label="the step “${esc(step ? step.id : r.nodePath)}”"`
|
|
114
|
+
+ ` aria-label="${esc(stepText(step, r.nodePath))}${r.isDefault ? ' (suggested)' : ''}">`
|
|
115
|
+
+ `<span>${stepLabel(step)}${r.isDefault ? '<span class="sr-tag">Suggested</span>' : ''}</span></label>`;
|
|
116
|
+
}).join('');
|
|
117
|
+
};
|
|
118
|
+
const paintPreview = () => {
|
|
119
|
+
if (!preview) return;
|
|
120
|
+
const view = previewView(preview, stepOf(ask.repairs[choice].nodePath));
|
|
121
|
+
pv.removeAttribute('aria-busy');
|
|
122
|
+
pv.innerHTML = view.body;
|
|
123
|
+
warning.hidden = !view.warning;
|
|
124
|
+
warning.innerHTML = view.warning;
|
|
125
|
+
ok.textContent = view.primary;
|
|
126
|
+
setReady(true);
|
|
127
|
+
};
|
|
128
|
+
const checking = () => {
|
|
129
|
+
preview = null;
|
|
130
|
+
pv.setAttribute('aria-busy', 'true');
|
|
131
|
+
pv.textContent = 'Checking what will change…';
|
|
132
|
+
warning.hidden = true;
|
|
133
|
+
ok.textContent = 'Rename step';
|
|
134
|
+
setReady(false, 'Checking what will change…');
|
|
135
|
+
};
|
|
136
|
+
async function refresh() {
|
|
137
|
+
clearTimeout(timer);
|
|
138
|
+
const mine = ++seq;
|
|
139
|
+
const repair = ask.repairs[choice];
|
|
140
|
+
const newId = input.value.trim();
|
|
141
|
+
showError('');
|
|
142
|
+
if (!newId) { nameError('Type a name for the step.'); preview = null; pv.textContent = ''; setReady(false, 'Type a name first.'); return; }
|
|
143
|
+
// Only an error is cleared here: a "Suggested name" note stays, so the polite announcement is not wiped mid-read.
|
|
144
|
+
if (msg.classList.contains('is-error')) nameError('');
|
|
145
|
+
checking();
|
|
146
|
+
let answer;
|
|
147
|
+
try { answer = await post(`${route}/rename-preview`, { nodePath: repair.nodePath, newId }); }
|
|
148
|
+
catch { answer = null; }
|
|
149
|
+
if (mine !== seq || !isOpen) return; // a newer check (or a closed dialog) owns the screen
|
|
150
|
+
if (answer && answer.status === 200 && answer.data.ok && answer.data.preview) {
|
|
151
|
+
preview = answer.data.preview;
|
|
152
|
+
paintPreview();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
pv.removeAttribute('aria-busy');
|
|
156
|
+
const data = answer ? answer.data : {};
|
|
157
|
+
if (answer && /^step-name-|^step-not-found$/.test(String(data.code))) {
|
|
158
|
+
nameError(data.error || 'That name can’t be used here. Try another.', data.suggestedId);
|
|
159
|
+
pv.textContent = '';
|
|
160
|
+
setReady(false, 'Choose a free name first.');
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
// "Check again" only where trying again can help (a failed check, a lost connection); an older AWARE or a file FloLess
|
|
164
|
+
// will not edit is answered with its sentence alone.
|
|
165
|
+
const retryable = !answer || !data.code || ['step-rename-failed', 'step-names-unchecked', 'step-rename-preview-stale'].includes(String(data.code));
|
|
166
|
+
pv.innerHTML = esc(data.error || 'FloLess couldn’t check the change just now.')
|
|
167
|
+
+ (retryable ? ' <button type="button" class="sr-retry" data-sr-retry data-command-id="shell.step-rename-retry">Check again</button>' : '');
|
|
168
|
+
setReady(false, retryable ? 'FloLess needs to check the change first.' : 'This rename can’t go ahead here.');
|
|
169
|
+
}
|
|
170
|
+
const schedule = () => { clearTimeout(timer); checking(); timer = setTimeout(() => { void refresh(); }, PREVIEW_DELAY_MS); };
|
|
171
|
+
|
|
172
|
+
const close = (result) => {
|
|
173
|
+
clearTimeout(timer);
|
|
174
|
+
seq += 1;
|
|
175
|
+
document.removeEventListener('keydown', onKey, true);
|
|
176
|
+
root.removeEventListener('click', onClick);
|
|
177
|
+
root.removeEventListener('change', onChange);
|
|
178
|
+
input.removeEventListener('input', onInput);
|
|
179
|
+
root.classList.remove('show');
|
|
180
|
+
isOpen = false;
|
|
181
|
+
if (returnTo && returnTo.isConnected) returnTo.focus();
|
|
182
|
+
resolve(result);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
async function confirm() {
|
|
186
|
+
if (busy) return;
|
|
187
|
+
if (ok.getAttribute('aria-disabled') === 'true' || !preview) { hint.classList.add('nudge'); return; }
|
|
188
|
+
busy = true;
|
|
189
|
+
seq += 1; // an in-flight check can no longer repaint the dialog under "Renaming…"
|
|
190
|
+
clearTimeout(timer);
|
|
191
|
+
setEditable(false);
|
|
192
|
+
const label = ok.textContent;
|
|
193
|
+
ok.textContent = 'Renaming…';
|
|
194
|
+
setReady(false, 'Renaming…');
|
|
195
|
+
showError('');
|
|
196
|
+
const repair = ask.repairs[choice];
|
|
197
|
+
let answer;
|
|
198
|
+
try {
|
|
199
|
+
answer = await post(`${route}/rename`, {
|
|
200
|
+
nodePath: repair.nodePath, newId: input.value.trim(),
|
|
201
|
+
expectedSourceHash: preview.sourceHash, previewToken: preview.previewToken,
|
|
202
|
+
// The button the person pressed said "anyway" / "Rewrite": that is the acceptance, and only of what is shown.
|
|
203
|
+
acceptUncertain: Array.isArray(preview.uncertain) && preview.uncertain.length > 0,
|
|
204
|
+
rewriteFile: preview.needsRewrite === true,
|
|
205
|
+
});
|
|
206
|
+
} catch { answer = null; }
|
|
207
|
+
busy = false;
|
|
208
|
+
setEditable(true);
|
|
209
|
+
if (answer && answer.status === 200 && answer.data.ok) { close({ renamed: true, result: answer.data }); return; }
|
|
210
|
+
const data = answer ? answer.data : {};
|
|
211
|
+
if (answer && data.preview && /^step-rename-/.test(String(data.code))) {
|
|
212
|
+
if (data.preview.to !== input.value.trim() || data.preview.nodePath !== repair.nodePath) { void refresh(); showError(data.error || ''); return; }
|
|
213
|
+
preview = data.preview;
|
|
214
|
+
paintPreview();
|
|
215
|
+
showError(data.error || 'The workflow changed since the preview. Look at it again, then confirm.');
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
ok.textContent = label;
|
|
219
|
+
if (answer && /^step-name-|^step-not-found$/.test(String(data.code))) {
|
|
220
|
+
nameError(data.error, data.suggestedId);
|
|
221
|
+
setReady(false, 'Choose a free name first.');
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
setReady(!!preview);
|
|
225
|
+
showError(data.error || 'FloLess couldn’t rename the step, so the workflow is unchanged. Check that FloLess is running and try again.');
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const focusables = () => [...root.querySelectorAll('button, input, [tabindex="0"]')]
|
|
229
|
+
.filter((el) => !el.hidden && !el.closest('[hidden]') && !(el.type === 'radio' && !el.checked));
|
|
230
|
+
function onKey(event) {
|
|
231
|
+
if (!root.classList.contains('show')) return;
|
|
232
|
+
if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); if (!busy) close({ renamed: false }); return; }
|
|
233
|
+
if (event.key === 'Enter' && event.target === input) { event.preventDefault(); clearTimeout(timer); if (preview) void confirm(); else void refresh(); return; }
|
|
234
|
+
if (event.key !== 'Tab') return;
|
|
235
|
+
const list = focusables();
|
|
236
|
+
if (!list.length) return;
|
|
237
|
+
const first = list[0]; const last = list[list.length - 1];
|
|
238
|
+
if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); }
|
|
239
|
+
else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); }
|
|
240
|
+
else if (!root.contains(document.activeElement)) { event.preventDefault(); first.focus(); }
|
|
241
|
+
}
|
|
242
|
+
function onChange(event) {
|
|
243
|
+
const radio = event.target;
|
|
244
|
+
if (!(radio instanceof HTMLInputElement) || radio.name !== 'sr-step') return;
|
|
245
|
+
choice = Number(radio.value) || 0;
|
|
246
|
+
if (!dirty) {
|
|
247
|
+
input.value = ask.repairs[choice].newId;
|
|
248
|
+
msg.classList.remove('is-error');
|
|
249
|
+
msg.textContent = `Suggested name: “${input.value}”.`;
|
|
250
|
+
}
|
|
251
|
+
void refresh();
|
|
252
|
+
}
|
|
253
|
+
function onInput() { if (busy) return; dirty = true; nameError(''); schedule(); }
|
|
254
|
+
function onClick(event) {
|
|
255
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
256
|
+
if (!target) return;
|
|
257
|
+
const use = target.closest('[data-sr-use]');
|
|
258
|
+
if (use) { input.value = use.getAttribute('data-sr-use'); dirty = true; void refresh(); input.focus(); return; }
|
|
259
|
+
if (target.closest('[data-sr-retry]')) { void refresh(); return; }
|
|
260
|
+
const button = target.closest('button');
|
|
261
|
+
if (!button) return;
|
|
262
|
+
if (button.id === 'sr-ok') void confirm();
|
|
263
|
+
else if (button.id === 'sr-cancel' && !busy) close({ renamed: false });
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
input.value = ask.repairs[choice].newId;
|
|
267
|
+
input.setAttribute('aria-invalid', 'false');
|
|
268
|
+
msg.textContent = '';
|
|
269
|
+
showError('');
|
|
270
|
+
$('sr-note').textContent = NOTE;
|
|
271
|
+
paintSteps();
|
|
272
|
+
document.addEventListener('keydown', onKey, true);
|
|
273
|
+
root.addEventListener('click', onClick);
|
|
274
|
+
root.addEventListener('change', onChange);
|
|
275
|
+
input.addEventListener('input', onInput);
|
|
276
|
+
root.classList.add('show');
|
|
277
|
+
const checked = root.querySelector('input[name="sr-step"]:checked');
|
|
278
|
+
if (checked) checked.focus(); else $('sr-title').focus();
|
|
279
|
+
void refresh();
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** True when an api() error is the ask (the server attached one). */
|
|
284
|
+
const askOf = (error) => (error && error.body && error.body.code === 'ambiguous-step-name' && error.body.ask ? error.body.ask : null);
|
|
285
|
+
|
|
286
|
+
globalThis.flolessStepRename = { open, askOf, previewView, stepLabel, NOTE };
|
|
287
|
+
})();
|