@floless/app 0.138.2 → 0.139.1
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/autostart.mjs +6 -2
- package/desktop-access-production-manifest.mjs +7 -0
- package/dist/floless-server.cjs +157207 -70887
- package/dist/schemas/model.continuation.v1.schema.json +19 -0
- package/dist/schemas/model.continuation.v2.schema.json +19 -0
- package/dist/schemas/model.query-response.v1.schema.json +95 -0
- package/dist/schemas/model.query-response.v2.schema.json +80 -0
- package/dist/schemas/model.query.v1.schema.json +87 -0
- package/dist/schemas/model.query.v2.schema.json +87 -0
- package/dist/schemas/model.snap-candidate.v1.schema.json +48 -0
- package/dist/schemas/model.snap-constraint.v1.schema.json +18 -0
- package/dist/schemas/model.snap-query.v1.schema.json +24 -0
- package/dist/schemas/model.snap-result.v1.schema.json +33 -0
- package/dist/schemas/model.snapshot.v1.schema.json +136 -0
- package/dist/schemas/revit.model.v1.schema.json +24 -0
- package/dist/schemas/steel.model.v2.schema.json +45 -6
- package/dist/skills/floless-app-approval/SKILL.md +19 -5
- package/dist/skills/floless-app-bridge/SKILL.md +19 -6
- package/dist/skills/floless-app-knowledge/SKILL.md +22 -1
- package/dist/skills/floless-app-new-workflow/SKILL.md +31 -27
- package/dist/skills/floless-app-new-workflow/references/build-and-verify.md +13 -12
- package/dist/skills/floless-app-onboarding/SKILL.md +3 -3
- package/dist/skills/floless-app-onboarding/references/floless-app-tour.md +16 -9
- package/dist/skills/floless-app-steel-model/SKILL.md +11 -2
- package/dist/skills/floless-app-steel-model/references/detail-from-a-screenshot.md +95 -0
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +142 -21
- package/dist/skills/floless-app-steel-takeoff/references/elevation-registration.md +19 -0
- package/dist/skills/floless-app-tweak-contract/SKILL.md +42 -8
- package/dist/skills/floless-app-vectorize/SKILL.md +19 -6
- package/dist/skills/floless-app-workflows/SKILL.md +30 -3
- package/dist/skills/floless-app-workflows/references/workspace-data.md +77 -4
- package/dist/templates/floless-workspace-model-report.flo +77 -0
- package/dist/templates/revit-model.flo +111 -0
- package/dist/web/app.css +415 -177
- package/dist/web/app.js +302 -51
- package/dist/web/aware.js +1357 -1032
- package/dist/web/chat.css +692 -0
- package/dist/web/chat.js +2651 -0
- package/dist/web/commands-revit.js +42 -0
- package/dist/web/commands-shell.js +531 -70
- package/dist/web/commands-steel.js +344 -146
- package/dist/web/commands.js +1 -1
- package/dist/web/index.html +283 -77
- package/dist/web/instructor.js +217 -36
- package/dist/web/left-pane.js +636 -0
- package/dist/web/model-artifact-loader.js +75 -0
- package/dist/web/model-authoring-gestures.js +141 -0
- package/dist/web/model-cad-tools.js +20 -0
- package/dist/web/model-clip-gesture.js +148 -0
- package/dist/web/model-clip-list.js +156 -0
- package/dist/web/model-clip-session.js +274 -0
- package/dist/web/model-clip-three-overlay.js +295 -0
- package/dist/web/model-clip-three-preview.js +59 -0
- package/dist/web/model-editor-contract.js +519 -0
- package/dist/web/model-editor-revit-adapter.js +139 -0
- package/dist/web/model-editor-shell.js +271 -0
- package/dist/web/model-editor-state-recovery.js +44 -0
- package/dist/web/model-editor-steel-adapter.js +415 -0
- package/dist/web/model-editor.css +268 -0
- package/dist/web/model-frame.js +192 -0
- package/dist/web/model-inspector.js +128 -0
- package/dist/web/model-measure.js +390 -0
- package/dist/web/model-navigation-controls.js +246 -0
- package/dist/web/model-orientation-overlay.js +217 -0
- package/dist/web/model-panel-bridge.js +230 -0
- package/dist/web/model-pointer-dock.js +164 -0
- package/dist/web/model-revit-module.js +83 -0
- package/dist/web/model-selection-coordinator.js +151 -0
- package/dist/web/model-selection-tools.js +290 -0
- package/dist/web/model-snap-contract.js +267 -0
- package/dist/web/model-snapping.js +497 -0
- package/dist/web/model-spatial-panel.js +294 -0
- package/dist/web/model-spatial-tools.js +249 -0
- package/dist/web/model-tree.js +47 -0
- package/dist/web/model-viewport-lighting.js +166 -0
- package/dist/web/model-viewport-revit-adapter.js +1224 -0
- package/dist/web/model-viewport-state.js +505 -0
- package/dist/web/model-viewport-steel-adapter.js +150 -0
- package/dist/web/model-viewport-toolbar.js +516 -0
- package/dist/web/model-viewport.js +717 -0
- package/dist/web/panels.js +8 -15
- package/dist/web/renderers.js +3 -0
- package/dist/web/revit-editor.css +35 -0
- package/dist/web/revit-editor.html +74 -0
- package/dist/web/revit-editor.js +845 -0
- package/dist/web/steel-3d-core.js +16 -44
- package/dist/web/steel-3d-view.js +1384 -633
- package/dist/web/steel-canvas-guidance.js +3 -1
- package/dist/web/steel-editor.html +2145 -1255
- package/dist/web/steel-filter.html +5 -1
- package/dist/web/steel-model-v2-commands.js +80 -3
- package/dist/web/steel-split-view.js +5 -39
- package/dist/web/steel-view-generation.js +107 -17
- package/dist/web/vector-3d.html +12 -0
- package/dist/web/workspaces.js +2154 -283
- package/distribution-profile-active.mjs +2 -0
- package/distribution-profile-production.mjs +47 -0
- package/distribution-profile-shared.mjs +8 -0
- package/distribution-profile.mjs +18 -0
- package/distribution-resource-inventory.mjs +81 -0
- package/launch.mjs +18 -10
- package/log.mjs +2 -1
- package/managed-runtime-policy.mjs +104 -0
- package/model-reader-policy-active.mjs +7 -0
- package/network-policy-active.mjs +6 -0
- package/package.json +17 -2
- package/post-update-marker.mjs +3 -1
- package/rvt-production-uat-authority.mjs +60 -0
- package/teardown.mjs +4 -3
package/dist/web/aware.js
CHANGED
|
@@ -50,6 +50,8 @@
|
|
|
50
50
|
// Latest normalized app payload, keyed by id, so handlers can read mode/gate.
|
|
51
51
|
const apps = new Map();
|
|
52
52
|
let currentId = null;
|
|
53
|
+
let workflowSelectionGeneration = 0;
|
|
54
|
+
const inputDialogFlights = new Map();
|
|
53
55
|
let teklaReadinessState = null;
|
|
54
56
|
let teklaReadinessPromise = null;
|
|
55
57
|
// appId → one of FloLess's project-publication availability states, or undefined.
|
|
@@ -115,6 +117,8 @@
|
|
|
115
117
|
// Severity always comes from note.kind, never this text — so if the wording
|
|
116
118
|
// ever changes and the pattern misses, we just fall back to the raw note.
|
|
117
119
|
function humanizeNote(text) {
|
|
120
|
+
const missing = missingAgentId(text);
|
|
121
|
+
if (missing) return `${agentDisplayName(missing)} is not installed. Install this agent to use this step.`;
|
|
118
122
|
const m = /command\s+(\S+)\s+(?:not found|is mode-overridable);\s*using author-declared mode:\s*(read|write)/i.exec(text);
|
|
119
123
|
if (m) {
|
|
120
124
|
const cmd = m[1];
|
|
@@ -125,6 +129,83 @@
|
|
|
125
129
|
return text;
|
|
126
130
|
}
|
|
127
131
|
|
|
132
|
+
function missingAgentId(text) {
|
|
133
|
+
return /\bagent\s+['"]?([a-z0-9][a-z0-9._-]*)['"]?\s+(?:is\s+)?not installed\b/i.exec(text || '')?.[1] || null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function agentDisplayName(id) {
|
|
137
|
+
return ({ 'html-report': 'HTML Report', 'viewer-3d': '3D Viewer', file: 'File' })[id] || id;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function runFailureMessage(message) {
|
|
141
|
+
if (/executable lock does not match the trusted compiled lock/i.test(message)) {
|
|
142
|
+
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.';
|
|
143
|
+
}
|
|
144
|
+
return message;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const missingAgentFailures = new Map();
|
|
148
|
+
const completedAgentInstalls = new Set();
|
|
149
|
+
const pendingWorkflowAgentInstalls = new Map();
|
|
150
|
+
function workflowAgentKey(id, appId = currentId, sourceHash = apps.get(appId)?.source?.hash) { return JSON.stringify([appId, id, sourceHash]); }
|
|
151
|
+
function recordAgentInstallResult(m) {
|
|
152
|
+
if (m.action === 'update') {
|
|
153
|
+
for (const key of completedAgentInstalls) {
|
|
154
|
+
if (JSON.parse(key)[1] === m.id) completedAgentInstalls.delete(key);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (m.appId && typeof m.sourceHash === 'string') {
|
|
158
|
+
const key = workflowAgentKey(m.id, m.appId, m.sourceHash);
|
|
159
|
+
pendingWorkflowAgentInstalls.delete(key);
|
|
160
|
+
if (m.ok) {
|
|
161
|
+
missingAgentFailures.delete(key);
|
|
162
|
+
completedAgentInstalls.add(key);
|
|
163
|
+
} else {
|
|
164
|
+
completedAgentInstalls.delete(key);
|
|
165
|
+
missingAgentFailures.set(key, String(m.error || 'Please try again.'));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (m.busy || [...pendingWorkflowAgentInstalls.values()].includes(m.id)) installingIds.add(m.id);
|
|
169
|
+
else installingIds.delete(m.id);
|
|
170
|
+
}
|
|
171
|
+
function missingAgentGroups(notes) {
|
|
172
|
+
const groups = new Map();
|
|
173
|
+
for (const note of notes) {
|
|
174
|
+
const id = missingAgentId(note.text);
|
|
175
|
+
if (!id) continue;
|
|
176
|
+
if (!groups.has(id)) groups.set(id, new Set());
|
|
177
|
+
if (note.nodeId) groups.get(id).add(note.nodeId);
|
|
178
|
+
}
|
|
179
|
+
return groups;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function refreshAgentNotes() {
|
|
183
|
+
const app = apps.get(currentId);
|
|
184
|
+
if (app) paintGate(app);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function missingAgentRows(groups) {
|
|
188
|
+
const installed = installedIdSet();
|
|
189
|
+
return [...groups].map(([id, nodes]) => {
|
|
190
|
+
const busy = installingIds.has(id);
|
|
191
|
+
const key = workflowAgentKey(id);
|
|
192
|
+
const failure = missingAgentFailures.get(key);
|
|
193
|
+
const done = !busy && !failure && completedAgentInstalls.has(key);
|
|
194
|
+
const check = !busy && !failure && !done && installed.has(id);
|
|
195
|
+
const busyLabel = installed.has(id) ? 'Checking' : 'Installing';
|
|
196
|
+
const busyDetail = installed.has(id) ? 'Checking the installed version. Please wait.' : 'Installation is in progress. Please wait.';
|
|
197
|
+
return `<li class="missing-agent-row"><div><strong>${escapeHtml(agentDisplayName(id))}</strong>` +
|
|
198
|
+
`<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 agent to use these steps.'} Used by: ${escapeHtml([...nodes].join(', '))}.</div>` +
|
|
199
|
+
(failure ? `<div class="missing-agent-error" role="status">Could not install: ${escapeHtml(failure)}</div>` : '') +
|
|
200
|
+
`</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 agent 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>`;
|
|
201
|
+
}).join('');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function missingAgentsBulkButton(pending, canInstall) {
|
|
205
|
+
if (pending.length <= 1) return '';
|
|
206
|
+
return `<button class="btn small" type="button" data-note-install-all data-command-id="shell.workflow-agents-install-all" aria-label="Install all missing agents" aria-busy="${!canInstall.length}" ${canInstall.length ? '' : 'disabled data-blocked-reason="Agent installations are in progress. Please wait."'}>${canInstall.length ? `Install all (${canInstall.length})` : 'Installing…'}</button>`;
|
|
207
|
+
}
|
|
208
|
+
|
|
128
209
|
const AGENT_ICONS = {
|
|
129
210
|
tekla: '<line x1="4" y1="5" x2="20" y2="5"/><line x1="12" y1="5" x2="12" y2="20"/>',
|
|
130
211
|
file: '<path d="M13 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V9z"/><polyline points="13 2 13 9 20 9"/>',
|
|
@@ -153,755 +234,13 @@
|
|
|
153
234
|
// (fired before this script runs) would otherwise drip stale demo lines into
|
|
154
235
|
// our chat. Replace it with a synchronous version, and clear any stragglers
|
|
155
236
|
// already scheduled by the original before we took over.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const ANSWER_KNOWN_KEY = 'floless:instructor-answers:known';
|
|
159
|
-
const ANSWER_READ_KEY = 'floless:instructor-answers:read';
|
|
160
|
-
function storedAnswerIds(key) {
|
|
161
|
-
try {
|
|
162
|
-
const value = JSON.parse(localStorage.getItem(key) || '[]');
|
|
163
|
-
return new Set(Array.isArray(value) ? value.filter((id) => typeof id === 'string') : []);
|
|
164
|
-
} catch { return new Set(); }
|
|
165
|
-
}
|
|
166
|
-
function persistAnswerIds(key, ids) {
|
|
167
|
-
try { localStorage.setItem(key, JSON.stringify(Array.from(ids).slice(-500))); } catch { /* private mode/quota */ }
|
|
168
|
-
}
|
|
169
|
-
let hadAnswerKnownSnapshot = false;
|
|
170
|
-
try { hadAnswerKnownSnapshot = localStorage.getItem(ANSWER_KNOWN_KEY) !== null; } catch { /* private mode */ }
|
|
171
|
-
const notifiedInstructorAnswerIds = storedAnswerIds(ANSWER_KNOWN_KEY);
|
|
172
|
-
const arrivedInstructorAnswerIds = new Set();
|
|
173
|
-
const readInstructorAnswerIds = storedAnswerIds(ANSWER_READ_KEY);
|
|
174
|
-
let answerGlowTimer = null;
|
|
175
|
-
let leftPaneTab = 'narrative';
|
|
176
|
-
// Per-id collapse state (session only, never persisted): a card is collapsed iff its id is here.
|
|
177
|
-
// Keyed by id, never position — cards insert at the TOP, so an index would drift under new arrivals.
|
|
178
|
-
const collapsedAnswerIds = new Set();
|
|
179
|
-
// Deferred-commit removal. `×` hides the card immediately and starts a timer; the DELETE fires only
|
|
180
|
-
// when the timer elapses, so an Undo within the window is a pure client-side restore with no server
|
|
181
|
-
// round-trip. The id stays in `pendingDeleteAnswerIds` (filtered out of every render) until then.
|
|
182
|
-
const pendingDeleteAnswerIds = new Set();
|
|
183
|
-
const answerDeleteTimers = new Map();
|
|
184
|
-
const answerSessionLaunches = new Set();
|
|
185
|
-
// Exists only between the click and POST /api/guide returning. Once the server gives the question
|
|
186
|
-
// an id, `pendingRequests` is authoritative and this optimistic shell is removed.
|
|
187
|
-
const optimisticInstructorRequests = new Map();
|
|
188
|
-
let optimisticInstructorRequestSequence = 0;
|
|
189
|
-
const ANSWER_UNDO_MS = 6000;
|
|
190
|
-
|
|
191
|
-
function selectLeftPaneTab(tab, { focus = false, explicit = false } = {}) {
|
|
192
|
-
leftPaneTab = tab === 'answers' ? 'answers' : 'narrative';
|
|
193
|
-
const narrativeTab = document.getElementById('narrative-tab');
|
|
194
|
-
const answersTab = document.getElementById('ai-answers-tab');
|
|
195
|
-
const answersFeed = document.getElementById('ai-answers');
|
|
196
|
-
const showAnswers = leftPaneTab === 'answers';
|
|
197
|
-
$messages.hidden = showAnswers;
|
|
198
|
-
if (answersFeed) answersFeed.hidden = !showAnswers;
|
|
199
|
-
narrativeTab?.classList.toggle('active', !showAnswers);
|
|
200
|
-
answersTab?.classList.toggle('active', showAnswers);
|
|
201
|
-
narrativeTab?.setAttribute('aria-selected', String(!showAnswers));
|
|
202
|
-
answersTab?.setAttribute('aria-selected', String(showAnswers));
|
|
203
|
-
narrativeTab?.setAttribute('tabindex', showAnswers ? '-1' : '0');
|
|
204
|
-
answersTab?.setAttribute('tabindex', showAnswers ? '0' : '-1');
|
|
205
|
-
if (showAnswers && explicit) {
|
|
206
|
-
instructorAnswers.filter(answerInVisibleScope).forEach((answer) => readInstructorAnswerIds.add(answer.id));
|
|
207
|
-
persistAnswerIds(ANSWER_READ_KEY, readInstructorAnswerIds);
|
|
208
|
-
document.getElementById('answer-unread')?.setAttribute('hidden', '');
|
|
209
|
-
answersTab?.removeAttribute('aria-label');
|
|
210
|
-
}
|
|
211
|
-
if (focus) (showAnswers ? answersTab : narrativeTab)?.focus();
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function onLeftPaneTabKey(event) {
|
|
215
|
-
if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
|
|
216
|
-
event.preventDefault();
|
|
217
|
-
const answers = event.key === 'ArrowRight' || event.key === 'End';
|
|
218
|
-
selectLeftPaneTab(answers ? 'answers' : 'narrative', { focus: true, explicit: true });
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
document.getElementById('narrative-tab')?.addEventListener('click', () => selectLeftPaneTab('narrative', { explicit: true }));
|
|
222
|
-
document.getElementById('ai-answers-tab')?.addEventListener('click', () => selectLeftPaneTab('answers', { explicit: true }));
|
|
223
|
-
document.getElementById('narrative-tab')?.addEventListener('keydown', onLeftPaneTabKey);
|
|
224
|
-
document.getElementById('ai-answers-tab')?.addEventListener('keydown', onLeftPaneTabKey);
|
|
225
|
-
|
|
226
|
-
function answerInVisibleScope(answer) {
|
|
227
|
-
if (!answer || !answer.instructorContext) return false;
|
|
228
|
-
if (wsRequestScope) {
|
|
229
|
-
if (wsRequestScope.kind === 'project') return answer.project === wsRequestScope.project;
|
|
230
|
-
return !answer.project && !answer.appId && answer.instructorContext.surface === 'workspaces';
|
|
231
|
-
}
|
|
232
|
-
return !answer.project && !!currentId && answer.appId === currentId;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/* The terminal AI writes its answer as markdown, and the card used to render that markdown raw —
|
|
236
|
-
a reader met a literal `# Dimension` and `**Where this lives:**` where a heading and a bold lead
|
|
237
|
-
belonged. This handles the block shapes those answers actually contain; mdInline still does the
|
|
238
|
-
inline half (bold, code, italic).
|
|
239
|
-
|
|
240
|
-
ESCAPE FIRST, then build. Every branch below composes markup out of text that can no longer
|
|
241
|
-
carry any, which is the order the guide description in this file already uses and the reason the
|
|
242
|
-
`<img src=x onerror=…>` case in instructor-answers-rendered.test.ts stays inert prose.
|
|
243
|
-
|
|
244
|
-
ponytail: hand-rolled for the handful of line shapes these answers use rather than shipping a
|
|
245
|
-
markdown library into web/ — reach for one when answers start carrying tables, links, nested
|
|
246
|
-
lists, or 4-space-indented code (which flattens into a paragraph here; fenced blocks are what
|
|
247
|
-
the models actually emit, and indent-detection would misfire on list continuations). */
|
|
248
|
-
function answerProse(raw) {
|
|
249
|
-
const out = [];
|
|
250
|
-
let list = null;
|
|
251
|
-
let para = [];
|
|
252
|
-
let fence = null;
|
|
253
|
-
const closeList = () => { if (list) { out.push(`</${list}>`); list = null; } };
|
|
254
|
-
// Joined with <br>, not a space. The renderer this replaced turned EVERY newline into one, and a
|
|
255
|
-
// model that hard-wraps a paragraph, or writes `key: value` runs and unbulleted steps as bare
|
|
256
|
-
// lines, would otherwise have that structure silently collapse into one running sentence. Soft-
|
|
257
|
-
// wrap joining is the stricter markdown reading; fidelity to what the AI laid out matters more
|
|
258
|
-
// here, and a blank line still starts a real new paragraph.
|
|
259
|
-
const closePara = () => { if (para.length) { out.push(`<p>${mdInline(para.join('<br>'))}</p>`); para = []; } };
|
|
260
|
-
const openList = (kind) => { if (list !== kind) { closeList(); out.push(`<${kind}>`); list = kind; } };
|
|
261
|
-
|
|
262
|
-
for (const line of escapeHtml(raw || '').split(/\r?\n/)) {
|
|
263
|
-
if (/^\s*```/.test(line)) {
|
|
264
|
-
if (fence) { out.push(`<pre><code>${fence.join('\n')}</code></pre>`); fence = null; }
|
|
265
|
-
else { closePara(); closeList(); fence = []; }
|
|
266
|
-
continue;
|
|
267
|
-
}
|
|
268
|
-
if (fence) { fence.push(line); continue; }
|
|
269
|
-
|
|
270
|
-
// `\S` first: `"## "` with nothing after it would otherwise match, `.trim()` to empty, and emit
|
|
271
|
-
// an EMPTY heading — the characters gone from the screen and an accessibility failure ("heading
|
|
272
|
-
// must have content") in their place. Failing the match instead drops it to a paragraph, where
|
|
273
|
-
// the degenerate input at least stays visible as the text the model typed.
|
|
274
|
-
const heading = /^(#{1,6})\s+(\S.*)$/.exec(line);
|
|
275
|
-
if (heading) {
|
|
276
|
-
closePara(); closeList();
|
|
277
|
-
// Levels collapse to h3/h4/h5: this is a card in a narrow side panel, so a document h1 would
|
|
278
|
-
// be both oversized here and a lie about the page's outline.
|
|
279
|
-
const tag = heading[1].length === 1 ? 'h3' : heading[1].length === 2 ? 'h4' : 'h5';
|
|
280
|
-
out.push(`<${tag}>${mdInline(heading[2].trim())}</${tag}>`);
|
|
281
|
-
continue;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
const bullet = /^\s*[-*]\s+(.+)$/.exec(line);
|
|
285
|
-
const numbered = /^\s*\d+[.)]\s+(.+)$/.exec(line);
|
|
286
|
-
if (bullet || numbered) {
|
|
287
|
-
closePara();
|
|
288
|
-
openList(bullet ? 'ul' : 'ol');
|
|
289
|
-
out.push(`<li>${mdInline((bullet || numbered)[1].trim())}</li>`);
|
|
290
|
-
continue;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
if (!line.trim()) { closePara(); closeList(); continue; }
|
|
294
|
-
// closeList BEFORE the paragraph opens. A prose line after a list item used to append a <p>
|
|
295
|
-
// while the <ul> was still open — content the parser keeps but the list semantics lose, since
|
|
296
|
-
// <p> is not permitted content for <ul> and a screen reader stops reading it as part of the
|
|
297
|
-
// list. The line becomes a paragraph AFTER the list instead.
|
|
298
|
-
closeList();
|
|
299
|
-
para.push(line.trim());
|
|
300
|
-
}
|
|
301
|
-
// An unterminated fence still renders as the code block it was opening, rather than vanishing.
|
|
302
|
-
if (fence) out.push(`<pre><code>${fence.join('\n')}</code></pre>`);
|
|
303
|
-
closePara(); closeList();
|
|
304
|
-
return out.join('');
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
function answerSessionProviderLabel(provider) {
|
|
308
|
-
return provider === 'claude' ? 'Claude' : provider === 'codex' ? 'Codex' : 'terminal AI';
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// The exact session id, provider URI, compatibility tuple, and working folder remain private on
|
|
312
|
-
// the server. Both visible surfaces receive this deliberately small state projection and render it
|
|
313
|
-
// here, so Requests cannot promise something the answer card refuses (or vice versa).
|
|
314
|
-
function answerSessionControlHtml(answer, surface) {
|
|
315
|
-
const continuation = answer && answer.continuation;
|
|
316
|
-
if (!continuation) return '';
|
|
317
|
-
const provider = continuation.provider === 'claude' ? 'claude' : 'codex';
|
|
318
|
-
const label = answerSessionProviderLabel(provider);
|
|
319
|
-
const rawAnswerId = String(answer.id || '');
|
|
320
|
-
const answerId = escapeAttr(rawAnswerId);
|
|
321
|
-
const attemptId = escapeAttr(String(continuation.attemptId || ''));
|
|
322
|
-
const instance = escapeAttr(`${label} session for ${answer.instructorContext?.subject || 'this answer'}`);
|
|
323
|
-
const prefix = surface === 'requests' ? 'requests' : 'answer';
|
|
324
|
-
const attrs = `data-answer-id="${answerId}" data-attempt-id="${attemptId}" data-provider="${provider}" data-answer-surface="${prefix}"`;
|
|
325
|
-
// Keep the command half literal so the Instructor inventory can prove every carrier. Only the
|
|
326
|
-
// escaped instance after "#" is dynamic; raw answer ids must never reach attribute markup.
|
|
327
|
-
const openButton = (text, extra = '') => `<button type="button" class="answer-session-open" id="${prefix}-answer-session-${answerId}" data-command-id="shell.answer-session-open#${escapeAttr(`${prefix}:${rawAnswerId}`)}" data-command-instance-label="${instance}" ${attrs}${extra}>${text}</button>`;
|
|
328
|
-
const openAgainButton = (text) => `<button type="button" class="answer-session-open" id="${prefix}-answer-session-${answerId}" data-command-id="shell.answer-session-open-again#${escapeAttr(`${prefix}:${rawAnswerId}`)}" data-command-instance-label="${instance}" ${attrs}>${text}</button>`;
|
|
329
|
-
const retryUncertainButton = (text) => `<button type="button" class="answer-session-open" id="${prefix}-answer-session-${answerId}" data-command-id="shell.answer-session-retry-uncertain#${escapeAttr(`${prefix}:${rawAnswerId}`)}" data-command-instance-label="${instance}" ${attrs}>${text}</button>`;
|
|
330
|
-
let content = '';
|
|
331
|
-
if (continuation.state === 'preparing') {
|
|
332
|
-
content = '<span class="answer-session-status"><span class="answer-session-spinner" aria-hidden="true"></span>Saving this session…</span>';
|
|
333
|
-
} else if (continuation.state === 'available') {
|
|
334
|
-
content = openButton(`Continue in ${label}`);
|
|
335
|
-
} else if (continuation.state === 'dispatching') {
|
|
336
|
-
content = openButton(`Asking Windows to open ${label}…`, ' aria-disabled="true" aria-busy="true"');
|
|
337
|
-
} else if (continuation.state === 'asked-windows') {
|
|
338
|
-
content = `<span class="answer-session-status">FloLess asked Windows to open ${label}.</span>${openAgainButton('Open again')}`;
|
|
339
|
-
} else if (continuation.state === 'dispatch-uncertain') {
|
|
340
|
-
content = `<span class="answer-session-status answer-session-warning">Windows may already have received the earlier request.</span>${retryUncertainButton('Try opening again…')}`;
|
|
341
|
-
} else {
|
|
342
|
-
const copy = continuation.reason === 'unsupported-provider'
|
|
343
|
-
? `This answer is saved. Its ${label} session isn’t available to reopen.`
|
|
344
|
-
: continuation.reason === 'provider-version'
|
|
345
|
-
? `This version of ${label} can’t reopen the saved session.`
|
|
346
|
-
: continuation.reason === 'capture-failed'
|
|
347
|
-
? `This answer is saved, but its ${label} session could not be preserved.`
|
|
348
|
-
: 'No saved session is available for this answer.';
|
|
349
|
-
content = `<span class="answer-session-status answer-session-unavailable">${copy}</span>`;
|
|
350
|
-
}
|
|
351
|
-
return `<div class="answer-session-continuation" role="group" aria-label="Continue this AI session" ${attrs}>${content}</div>`;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
function replaceAnswerContinuation(answerId, attemptId, continuation) {
|
|
355
|
-
let changed = false;
|
|
356
|
-
instructorAnswers = instructorAnswers.map((answer) => {
|
|
357
|
-
if (answer.id !== answerId || answer.continuation?.attemptId !== attemptId) return answer;
|
|
358
|
-
changed = true;
|
|
359
|
-
return { ...answer, continuation };
|
|
360
|
-
});
|
|
361
|
-
return changed;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
function focusedAnswerSessionControl() {
|
|
365
|
-
const group = document.activeElement?.closest?.('.answer-session-continuation');
|
|
366
|
-
if (!group) return null;
|
|
367
|
-
return {
|
|
368
|
-
answerId: group.dataset.answerId || '', attemptId: group.dataset.attemptId || '',
|
|
369
|
-
surface: group.dataset.answerSurface === 'requests' ? 'requests' : 'answer',
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
function restoreAnswerSessionFocus(target) {
|
|
374
|
-
if (!target?.answerId || !target?.attemptId) return;
|
|
375
|
-
const selector = `[data-answer-id="${CSS.escape(target.answerId)}"]`
|
|
376
|
-
+ `[data-attempt-id="${CSS.escape(target.attemptId)}"]`
|
|
377
|
-
+ `[data-answer-surface="${CSS.escape(target.surface)}"]`;
|
|
378
|
-
const button = document.querySelector(`.answer-session-open${selector}`);
|
|
379
|
-
if (button) { button.focus({ preventScroll: true }); return; }
|
|
380
|
-
const group = document.querySelector(`.answer-session-continuation${selector}`);
|
|
381
|
-
if (group) {
|
|
382
|
-
group.tabIndex = -1;
|
|
383
|
-
group.focus({ preventScroll: true });
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
(target.surface === 'requests'
|
|
387
|
-
? document.querySelector('#requests-modal .modal.requests')
|
|
388
|
-
: document.getElementById('ai-answers-tab'))?.focus?.({ preventScroll: true });
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
function repaintAnswerSessionSurfaces(focusTarget = focusedAnswerSessionControl()) {
|
|
392
|
-
renderInstructorAnswers({ revealNew: false });
|
|
393
|
-
const requestsModal = document.getElementById('requests-modal');
|
|
394
|
-
if (requestsModal?.classList.contains('show')) renderRequests();
|
|
395
|
-
restoreAnswerSessionFocus(focusTarget);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
function announceAnswerSession(message, surface) {
|
|
399
|
-
if (surface === 'requests') {
|
|
400
|
-
const status = document.getElementById('requests-answer-session-status');
|
|
401
|
-
if (status) {
|
|
402
|
-
status.textContent = message;
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
announceAnswers(message);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
async function launchAnswerSession(button) {
|
|
410
|
-
const answerId = button.dataset.answerId || '';
|
|
411
|
-
const attemptId = button.dataset.attemptId || '';
|
|
412
|
-
const provider = button.dataset.provider === 'claude' ? 'claude' : 'codex';
|
|
413
|
-
const surface = button.dataset.answerSurface === 'requests' ? 'requests' : 'answer';
|
|
414
|
-
const focusTarget = { answerId, attemptId, surface };
|
|
415
|
-
const key = `${answerId}\0${attemptId}`;
|
|
416
|
-
if (!answerId || !attemptId || answerSessionLaunches.has(key) || button.getAttribute('aria-disabled') === 'true') return;
|
|
417
|
-
const answer = instructorAnswers.find((candidate) => candidate.id === answerId
|
|
418
|
-
&& candidate.continuation?.attemptId === attemptId);
|
|
419
|
-
if (!answer) return;
|
|
420
|
-
const prior = answer.continuation;
|
|
421
|
-
if (!['available', 'asked-windows', 'dispatch-uncertain'].includes(prior.state)) return;
|
|
422
|
-
const confirmUncertain = prior.state === 'dispatch-uncertain';
|
|
423
|
-
if (confirmUncertain) {
|
|
424
|
-
const label = answerSessionProviderLabel(provider);
|
|
425
|
-
const choice = await confirmUnsavedSwitch(
|
|
426
|
-
'',
|
|
427
|
-
`Windows may already have received the earlier request. Trying again can open the same session twice in ${label}.`,
|
|
428
|
-
`Try opening ${label} again?`,
|
|
429
|
-
{ confirm: 'Try opening again', hideDiscard: true, initialFocus: 'cancel' },
|
|
430
|
-
);
|
|
431
|
-
if (choice !== 'save') return;
|
|
432
|
-
}
|
|
433
|
-
answerSessionLaunches.add(key);
|
|
434
|
-
replaceAnswerContinuation(answerId, attemptId, { ...prior, state: 'dispatching' });
|
|
435
|
-
repaintAnswerSessionSurfaces(focusTarget);
|
|
436
|
-
announceAnswerSession(`Asking Windows to open ${answerSessionProviderLabel(provider)}`, surface);
|
|
437
|
-
try {
|
|
438
|
-
const response = await api(`/api/answers/${encodeURIComponent(answerId)}/desktop-session/launch`, {
|
|
439
|
-
method: 'POST', body: JSON.stringify({
|
|
440
|
-
attemptId, expectedState: prior.state, ...(confirmUncertain ? { confirmUncertain: true } : {}),
|
|
441
|
-
}),
|
|
442
|
-
});
|
|
443
|
-
replaceAnswerContinuation(answerId, attemptId, response.continuation);
|
|
444
|
-
announceAnswerSession(`FloLess asked Windows to open ${answerSessionProviderLabel(provider)}`, surface);
|
|
445
|
-
} catch (error) {
|
|
446
|
-
if (error?.body?.code === 'provider-version') {
|
|
447
|
-
replaceAnswerContinuation(answerId, attemptId, { ...prior, state: 'unavailable', reason: 'provider-version' });
|
|
448
|
-
announceAnswerSession(`This version of ${answerSessionProviderLabel(provider)} can’t reopen the saved session.`, surface);
|
|
449
|
-
} else if (error?.body?.code === 'confirm-uncertain') {
|
|
450
|
-
replaceAnswerContinuation(answerId, attemptId, { ...prior, state: 'dispatch-uncertain' });
|
|
451
|
-
announceAnswerSession('Windows may already have received the earlier request.', surface);
|
|
452
|
-
} else if (error?.body?.code === 'workspace-invalid') {
|
|
453
|
-
replaceAnswerContinuation(answerId, attemptId, { ...prior, state: 'unavailable', reason: 'capture-failed' });
|
|
454
|
-
announceAnswerSession('The saved session workspace is no longer available.', surface);
|
|
455
|
-
} else if (error?.body?.code === 'state-changed') {
|
|
456
|
-
await loadRequests();
|
|
457
|
-
announceAnswerSession('This saved answer session changed in another window.', surface);
|
|
458
|
-
} else {
|
|
459
|
-
replaceAnswerContinuation(answerId, attemptId, prior);
|
|
460
|
-
reportErr(error);
|
|
461
|
-
}
|
|
462
|
-
} finally {
|
|
463
|
-
answerSessionLaunches.delete(key);
|
|
464
|
-
repaintAnswerSessionSurfaces(focusTarget);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
function bindAnswerSessionControls(root) {
|
|
469
|
-
root.querySelectorAll('.answer-session-open').forEach((button) => {
|
|
470
|
-
button.onclick = () => { void launchAnswerSession(button); };
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
function answerCard(answer, isNew) {
|
|
475
|
-
const subjectText = answer.instructorContext.subject || 'this context';
|
|
476
|
-
const subject = escapeHtml(subjectText);
|
|
477
|
-
const prose = answerProse(answer.answer);
|
|
478
|
-
const runtime = answer.runtime === 'claude' ? 'Claude' : answer.runtime === 'codex' ? 'Codex' : 'terminal AI';
|
|
479
|
-
const card = msgEl(`aware instructor-answer${isNew ? ' instructor-answer-new' : ''}`,
|
|
480
|
-
`${runtime} · ${subject}`,
|
|
481
|
-
`<span class="answer-new-badge">New answer</span>${prose}`,
|
|
482
|
-
answer.finishedAt);
|
|
483
|
-
card.dataset.answerId = answer.id;
|
|
484
|
-
const body = card.querySelector('.body');
|
|
485
|
-
if (body && answer.continuation) {
|
|
486
|
-
body.insertAdjacentHTML('beforeend', answerSessionControlHtml(answer, 'answer'));
|
|
487
|
-
bindAnswerSessionControls(card);
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
// A fresh arrival always renders expanded — the glow-and-scroll is meant to reveal its content, so
|
|
491
|
-
// a card that lit up and then hid its own body would be actively confusing. Otherwise honour the
|
|
492
|
-
// per-id collapse the user set.
|
|
493
|
-
const collapsed = !isNew && collapsedAnswerIds.has(answer.id);
|
|
494
|
-
if (collapsed) card.classList.add('answer-collapsed');
|
|
495
|
-
const bodyId = `answer-body-${answer.id}`;
|
|
496
|
-
if (body) body.id = bodyId;
|
|
497
|
-
const who = card.querySelector('.who');
|
|
498
|
-
if (who) who.classList.add('answer-who');
|
|
499
|
-
|
|
500
|
-
// The chevron owns the disclosure and the × owns the removal — two independent buttons, never one
|
|
501
|
-
// nested in the other. A header that wraps a nested × steals the delete button's hit box the moment
|
|
502
|
-
// closest() routes a click (see reference_nested_control_in_role_button_card.md).
|
|
503
|
-
const chevron = document.createElement('button');
|
|
504
|
-
chevron.type = 'button';
|
|
505
|
-
chevron.className = 'answer-collapse-toggle';
|
|
506
|
-
chevron.textContent = '▸';
|
|
507
|
-
chevron.setAttribute('aria-controls', bodyId);
|
|
508
|
-
setCollapseToggleState(chevron, collapsed, `${runtime} · ${subjectText}`);
|
|
509
|
-
chevron.onclick = () => toggleAnswerCollapse(answer.id);
|
|
510
|
-
|
|
511
|
-
const del = answerCanDelete(answer) ? document.createElement('button') : null;
|
|
512
|
-
if (del) {
|
|
513
|
-
del.type = 'button';
|
|
514
|
-
del.className = 'answer-del';
|
|
515
|
-
del.textContent = '×';
|
|
516
|
-
del.setAttribute('aria-label', `Remove this answer, ${runtime} · ${subjectText}`);
|
|
517
|
-
del.setAttribute('data-tip', 'Remove this answer');
|
|
518
|
-
del.onclick = () => removeAnswerWithUndo(answer.id);
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
if (who) {
|
|
522
|
-
who.insertBefore(chevron, who.firstChild); // chevron | name … time | ×
|
|
523
|
-
if (del) who.appendChild(del);
|
|
524
|
-
}
|
|
525
|
-
return card;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
function answerCanDelete(answer) {
|
|
529
|
-
const key = `${answer?.id || ''}\0${answer?.continuation?.attemptId || ''}`;
|
|
530
|
-
return !answer?.continuation
|
|
531
|
-
|| (answer.continuation.state !== 'preparing'
|
|
532
|
-
&& answer.continuation.state !== 'dispatching'
|
|
533
|
-
&& !answerSessionLaunches.has(key));
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
// One place that writes the chevron's per-state ARIA/tooltip, so the toggle and the card class can
|
|
537
|
-
// never drift. `expanded` name folds the subject in so a screen reader tells the per-card toggles
|
|
538
|
-
// apart from each other and from the bulk one.
|
|
539
|
-
function setCollapseToggleState(chevron, collapsed, name) {
|
|
540
|
-
chevron.setAttribute('aria-expanded', String(!collapsed));
|
|
541
|
-
chevron.setAttribute('aria-label', `${collapsed ? 'Expand' : 'Collapse'} this answer, ${name}`);
|
|
542
|
-
chevron.setAttribute('data-tip', collapsed ? 'Expand this answer' : 'Collapse this answer');
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
function announceAnswers(message) {
|
|
546
|
-
const status = document.getElementById('narrative-answer-status');
|
|
547
|
-
if (status) status.textContent = message;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
// Toggle one card in place (no full re-render): flip the class + the chevron's ARIA, then re-derive
|
|
551
|
-
// the bulk button's aggregate label from what is now on screen.
|
|
552
|
-
function toggleAnswerCollapse(id) {
|
|
553
|
-
const willCollapse = !collapsedAnswerIds.has(id);
|
|
554
|
-
if (willCollapse) collapsedAnswerIds.add(id); else collapsedAnswerIds.delete(id);
|
|
555
|
-
const card = document.querySelector(`#ai-answers [data-answer-id="${CSS.escape(id)}"]`);
|
|
556
|
-
if (card) {
|
|
557
|
-
card.classList.toggle('answer-collapsed', willCollapse);
|
|
558
|
-
const chevron = card.querySelector('.answer-collapse-toggle');
|
|
559
|
-
const name = card.querySelector('.who-name')?.textContent || 'this context';
|
|
560
|
-
if (chevron) setCollapseToggleState(chevron, willCollapse, name);
|
|
561
|
-
}
|
|
562
|
-
syncAnswerBulkToggle();
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
// The bulk toggle's label is DERIVED, never stored: any card expanded → it offers "Collapse all";
|
|
566
|
-
// none expanded → "Expand all". A fresh arrival (always expanded) naturally returns it to the mixed
|
|
567
|
-
// state with no special-casing. Reads the live DOM so a single-card toggle keeps it honest too.
|
|
568
|
-
function syncAnswerBulkToggle() {
|
|
569
|
-
const button = document.getElementById('answers-collapse-all');
|
|
570
|
-
if (!button) return;
|
|
571
|
-
const cards = [...document.querySelectorAll('#ai-answers [data-answer-id]')];
|
|
572
|
-
const anyExpanded = cards.some((card) => !card.classList.contains('answer-collapsed'));
|
|
573
|
-
button.textContent = anyExpanded ? 'Collapse all' : 'Expand all';
|
|
574
|
-
button.setAttribute('aria-expanded', String(anyExpanded));
|
|
575
|
-
button.setAttribute('data-tip', anyExpanded ? 'Collapse every answer shown here' : 'Expand every answer shown here');
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
function toggleAllAnswers(visible) {
|
|
579
|
-
const anyExpanded = visible.some((answer) => !collapsedAnswerIds.has(answer.id));
|
|
580
|
-
for (const answer of visible) {
|
|
581
|
-
if (anyExpanded) collapsedAnswerIds.add(answer.id); else collapsedAnswerIds.delete(answer.id);
|
|
582
|
-
}
|
|
583
|
-
renderInstructorAnswers({ revealNew: false });
|
|
584
|
-
announceAnswers(`${anyExpanded ? 'Collapsed' : 'Expanded'} ${visible.length} answer${visible.length === 1 ? '' : 's'}`);
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
// The bulk row: a count on the left, the two actions on the right — the same shape as the Requests
|
|
588
|
-
// scope row. Built fresh each render (its handlers close over THIS paint's `visible`), which is also
|
|
589
|
-
// why "Clear all" acts on the snapshot the user is looking at, never a freshly re-derived scope.
|
|
590
|
-
function answersToolbar(visible) {
|
|
591
|
-
const bar = document.createElement('div');
|
|
592
|
-
bar.className = 'answers-toolbar';
|
|
593
|
-
bar.id = 'answers-toolbar';
|
|
594
|
-
|
|
595
|
-
const count = document.createElement('span');
|
|
596
|
-
count.className = 'answers-count';
|
|
597
|
-
count.textContent = `${visible.length} answer${visible.length === 1 ? '' : 's'}`;
|
|
598
|
-
|
|
599
|
-
const spacer = document.createElement('span');
|
|
600
|
-
spacer.className = 'answers-toolbar-spacer';
|
|
601
|
-
spacer.setAttribute('aria-hidden', 'true');
|
|
602
|
-
|
|
603
|
-
const collapseAll = document.createElement('button');
|
|
604
|
-
collapseAll.type = 'button';
|
|
605
|
-
collapseAll.id = 'answers-collapse-all';
|
|
606
|
-
collapseAll.className = 'answers-bulk';
|
|
607
|
-
collapseAll.setAttribute('data-command-id', 'shell.answers-collapse-all');
|
|
608
|
-
collapseAll.setAttribute('aria-label', 'Collapse or expand all answers');
|
|
609
|
-
collapseAll.textContent = 'Collapse all';
|
|
610
|
-
collapseAll.onclick = () => toggleAllAnswers(visible);
|
|
611
|
-
|
|
612
|
-
const clearable = visible.filter(answerCanDelete);
|
|
613
|
-
const clearAll = document.createElement('button');
|
|
614
|
-
clearAll.type = 'button';
|
|
615
|
-
clearAll.id = 'answers-clear-all';
|
|
616
|
-
clearAll.className = 'answers-bulk answers-clear';
|
|
617
|
-
clearAll.setAttribute('data-command-id', 'shell.answers-clear');
|
|
618
|
-
clearAll.textContent = clearable.length === visible.length ? 'Clear all' : 'Clear available';
|
|
619
|
-
clearAll.setAttribute('data-tip', clearable.length === 1 ? 'Remove this answer' : `Remove ${clearable.length} answers that are ready to clear`);
|
|
620
|
-
clearAll.onclick = () => clearAllAnswers(clearable);
|
|
621
|
-
clearAll.hidden = clearable.length === 0;
|
|
622
|
-
|
|
623
|
-
bar.append(count, spacer, collapseAll, clearAll);
|
|
624
|
-
return bar;
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
// `×` on a card: hide it now, offer Undo, and only commit the (permanent) server delete once the
|
|
628
|
-
// window elapses. Keyed by id throughout so a card arriving mid-window can't shift what a timer or a
|
|
629
|
-
// focus target points at.
|
|
630
|
-
function removeAnswerWithUndo(id) {
|
|
631
|
-
if (pendingDeleteAnswerIds.has(id)) return;
|
|
632
|
-
// The card that will take this one's on-screen slot, captured BEFORE the re-render, so focus never
|
|
633
|
-
// falls to <body>. nextElementSibling first (the one just below), else the one above — a heuristic
|
|
634
|
-
// that holds whatever the sort order is.
|
|
635
|
-
const removing = document.querySelector(`#ai-answers [data-answer-id="${CSS.escape(id)}"]`);
|
|
636
|
-
const neighbourId = removing?.nextElementSibling?.dataset?.answerId
|
|
637
|
-
|| removing?.previousElementSibling?.dataset?.answerId
|
|
638
|
-
|| null;
|
|
639
|
-
|
|
640
|
-
pendingDeleteAnswerIds.add(id);
|
|
641
|
-
renderInstructorAnswers({ revealNew: false });
|
|
642
|
-
const focusTarget = neighbourId
|
|
643
|
-
? document.querySelector(`#ai-answers [data-answer-id="${CSS.escape(neighbourId)}"] .answer-collapse-toggle`)
|
|
644
|
-
: (document.getElementById('answers-collapse-all') || document.querySelector('.ai-answers-empty'));
|
|
645
|
-
focusTarget?.focus?.({ preventScroll: true });
|
|
646
|
-
announceAnswers('Answer removed');
|
|
647
|
-
|
|
648
|
-
const commit = async () => {
|
|
649
|
-
answerDeleteTimers.delete(id);
|
|
650
|
-
// The reload is INSIDE the guard: a blip on loadRequests() after the DELETE already landed would
|
|
651
|
-
// otherwise reject this setTimeout-fired async fn as an unhandled rejection (no toast, no log) and
|
|
652
|
-
// strand the id in pendingDeleteAnswerIds forever. `finally` drops the pending id and repaints on
|
|
653
|
-
// every path, matching how deleteOneRequest wraps DELETE + reload + render in one try.
|
|
654
|
-
try {
|
|
655
|
-
await api(`/api/requests/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
656
|
-
await loadRequests(); // refreshes instructorAnswers (the row is gone server-side now)
|
|
657
|
-
} catch (error) {
|
|
658
|
-
reportErr(error);
|
|
659
|
-
} finally {
|
|
660
|
-
pendingDeleteAnswerIds.delete(id);
|
|
661
|
-
renderInstructorAnswers({ revealNew: false });
|
|
662
|
-
}
|
|
663
|
-
};
|
|
664
|
-
answerDeleteTimers.set(id, setTimeout(commit, ANSWER_UNDO_MS));
|
|
665
|
-
|
|
666
|
-
// Pass ANSWER_UNDO_MS so the visible toast and the commit window are ONE number, not two literals
|
|
667
|
-
// that happen to match — bump the constant and the toast follows.
|
|
668
|
-
showUndoToast('Answer removed', () => {
|
|
669
|
-
const timer = answerDeleteTimers.get(id);
|
|
670
|
-
if (!timer) return; // already committed — a late Undo is a safe no-op
|
|
671
|
-
clearTimeout(timer);
|
|
672
|
-
answerDeleteTimers.delete(id);
|
|
673
|
-
pendingDeleteAnswerIds.delete(id);
|
|
674
|
-
renderInstructorAnswers({ revealNew: false });
|
|
675
|
-
document.querySelector(`#ai-answers [data-answer-id="${CSS.escape(id)}"] .answer-collapse-toggle`)?.focus?.({ preventScroll: true });
|
|
676
|
-
announceAnswers('Removal undone');
|
|
677
|
-
}, ANSWER_UNDO_MS);
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
// "Clear all" removes every answer in the SHOWN scope, confirmed once. No undo here (that was the
|
|
681
|
-
// deliberate split: undo for a single mis-click, a confirm for the bulk wipe). Per-id DELETE in a
|
|
682
|
-
// loop, exactly how the Requests dialog clears a scoped set — an answer's id IS its request id.
|
|
683
|
-
async function clearAllAnswers(visible) {
|
|
684
|
-
const ids = visible.map((answer) => answer.id);
|
|
685
|
-
if (!ids.length) return;
|
|
686
|
-
if (!(await confirmClearAnswers(ids.length))) return;
|
|
687
|
-
try {
|
|
688
|
-
const results = await Promise.allSettled(ids.map((id) =>
|
|
689
|
-
api(`/api/requests/${encodeURIComponent(id)}`, { method: 'DELETE' })));
|
|
690
|
-
await loadRequests();
|
|
691
|
-
renderInstructorAnswers({ revealNew: false });
|
|
692
|
-
const cleared = results.filter((result) => result.status === 'fulfilled').length;
|
|
693
|
-
const failed = results.length - cleared;
|
|
694
|
-
announceAnswers(`${cleared ? `Cleared ${cleared} answer${cleared === 1 ? '' : 's'}` : 'No answers cleared'}${failed ? `; ${failed} kept` : ''}`);
|
|
695
|
-
showToast(
|
|
696
|
-
`${cleared ? `Cleared ${cleared} answer${cleared === 1 ? '' : 's'}` : 'No answers cleared'}${failed ? ` — kept ${failed}` : ''}`,
|
|
697
|
-
failed ? 'info' : 'ok',
|
|
698
|
-
);
|
|
699
|
-
const firstFailure = results.find((result) => result.status === 'rejected');
|
|
700
|
-
if (firstFailure?.status === 'rejected') reportErr(firstFailure.reason);
|
|
701
|
-
} catch (error) { reportErr(error); }
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
function confirmClearAnswers(count) {
|
|
705
|
-
return new Promise((resolve) => {
|
|
706
|
-
const modal = document.getElementById('answers-clear-modal');
|
|
707
|
-
const sub = document.getElementById('answers-clear-sub');
|
|
708
|
-
const confirm = document.getElementById('answers-clear-confirm');
|
|
709
|
-
const cancel = document.getElementById('answers-clear-cancel');
|
|
710
|
-
if (!modal || !confirm || !cancel) { resolve(false); return; }
|
|
711
|
-
if (sub) sub.textContent = `Remove ${count === 1 ? 'this answer' : `all ${count} answers`} shown here? This can’t be undone.`;
|
|
712
|
-
showModal(modal);
|
|
713
|
-
setTimeout(() => cancel.focus(), 0); // Cancel holds default focus, mirroring the routine delete
|
|
714
|
-
const done = (result) => {
|
|
715
|
-
hideModal(modal);
|
|
716
|
-
confirm.onclick = cancel.onclick = modal.onclick = null;
|
|
717
|
-
document.removeEventListener('keydown', onKey, true);
|
|
718
|
-
resolve(result);
|
|
719
|
-
};
|
|
720
|
-
const onKey = (event) => { if (event.key === 'Escape') { event.preventDefault(); done(false); } };
|
|
721
|
-
confirm.onclick = () => done(true);
|
|
722
|
-
cancel.onclick = () => done(false);
|
|
723
|
-
onBackdropDismiss(modal, () => done(false));
|
|
724
|
-
document.addEventListener('keydown', onKey, true);
|
|
725
|
-
});
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
function acceptInstructorAnswers(answers, { initial = false } = {}) {
|
|
729
|
-
instructorAnswers = answers;
|
|
730
|
-
if (initial) {
|
|
731
|
-
answers.forEach((answer) => {
|
|
732
|
-
notifiedInstructorAnswerIds.add(answer.id);
|
|
733
|
-
if (!hadAnswerKnownSnapshot) readInstructorAnswerIds.add(answer.id);
|
|
734
|
-
});
|
|
735
|
-
persistAnswerIds(ANSWER_KNOWN_KEY, notifiedInstructorAnswerIds);
|
|
736
|
-
if (!hadAnswerKnownSnapshot) persistAnswerIds(ANSWER_READ_KEY, readInstructorAnswerIds);
|
|
737
|
-
hadAnswerKnownSnapshot = true;
|
|
738
|
-
renderInstructorAnswers({ revealNew: false });
|
|
739
|
-
return;
|
|
740
|
-
}
|
|
741
|
-
// Arrival is recorded globally before scope filtering. An answer for another project stays
|
|
742
|
-
// unread there, but visiting that project later must not replay an old arrival as a new one.
|
|
743
|
-
answers.forEach((answer) => {
|
|
744
|
-
if (notifiedInstructorAnswerIds.has(answer.id)) return;
|
|
745
|
-
notifiedInstructorAnswerIds.add(answer.id);
|
|
746
|
-
if (answerInVisibleScope(answer)) arrivedInstructorAnswerIds.add(answer.id);
|
|
747
|
-
});
|
|
748
|
-
persistAnswerIds(ANSWER_KNOWN_KEY, notifiedInstructorAnswerIds);
|
|
749
|
-
renderInstructorAnswers({ revealNew: true });
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
function pendingInstructorStatus(request) {
|
|
753
|
-
const runtime = request.runtime || request.run?.runtime;
|
|
754
|
-
const provider = runtimeLabel(runtime || '');
|
|
755
|
-
if (request.optimistic) return { label: 'Sending your question…', active: true };
|
|
756
|
-
if (request.run?.state === 'running') return { label: `${provider} is working on your answer.`, active: true };
|
|
757
|
-
if (request.run?.state === 'queued') return { label: `Waiting for ${provider} to start.`, active: true };
|
|
758
|
-
if (['failed', 'stopped', 'interrupted', 'contract-violation', 'needs-you', 'exited-unresolved'].includes(request.run?.state)) {
|
|
759
|
-
return { label: `${provider} stopped before finishing. Open Requests for details.`, active: false };
|
|
760
|
-
}
|
|
761
|
-
return { label: `Question saved. Waiting for ${provider} to start.`, active: true };
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
function pendingInstructorCard(request) {
|
|
765
|
-
const subject = request.instructorContext?.subject || 'this context';
|
|
766
|
-
const runtime = request.runtime || request.run?.runtime;
|
|
767
|
-
const provider = runtimeLabel(runtime || '');
|
|
768
|
-
const status = pendingInstructorStatus(request);
|
|
769
|
-
const card = msgEl(
|
|
770
|
-
'aware instructor-answer instructor-answer-pending',
|
|
771
|
-
`${escapeHtml(provider)} · ${escapeHtml(subject)}`,
|
|
772
|
-
`<span class="instructor-answer-pending-status">${status.active ? '<span class="answer-session-spinner" aria-hidden="true"></span>' : ''}${escapeHtml(status.label)}</span>`,
|
|
773
|
-
request.createdAt,
|
|
774
|
-
);
|
|
775
|
-
card.dataset.pendingRequestId = request.id;
|
|
776
|
-
return card;
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
function instructorRequestClientFingerprint(request) {
|
|
780
|
-
const body = { instructorContext: request?.instructorContext };
|
|
781
|
-
if (request?.project) {
|
|
782
|
-
body.project = request.project;
|
|
783
|
-
body.projectLabel = request.projectLabel;
|
|
784
|
-
body.appId = request.appId;
|
|
785
|
-
} else if (request?.appId) body.appId = request.appId;
|
|
786
|
-
return JSON.stringify(body);
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
function visiblePendingInstructorRequests() {
|
|
790
|
-
// `/api/guide` broadcasts the durable row before its POST response settles. Prefer the
|
|
791
|
-
// optimistic card during that small overlap so one click never paints two copies of the same
|
|
792
|
-
// question; settlement then swaps it for the server-owned id without a flash.
|
|
793
|
-
const durable = pendingRequests.filter((request) => !optimisticInstructorRequests.has(instructorRequestClientFingerprint(request)));
|
|
794
|
-
return [...optimisticInstructorRequests.values(), ...durable]
|
|
795
|
-
.filter((request) => request?.type === 'guide' && answerInVisibleScope(request))
|
|
796
|
-
.filter((request) => request.optimistic || !instructorAnswers.some((answer) => answer.id === request.id));
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
function beginOptimisticInstructorRequest(body, runtime, fingerprint) {
|
|
800
|
-
const id = `sending-${++optimisticInstructorRequestSequence}`;
|
|
801
|
-
optimisticInstructorRequests.set(fingerprint, {
|
|
802
|
-
id, type: 'guide', optimistic: true, runtime,
|
|
803
|
-
createdAt: new Date().toISOString(), ...body,
|
|
804
|
-
});
|
|
805
|
-
renderInstructorAnswers({ revealNew: false });
|
|
806
|
-
if (!state.collapse.left) selectLeftPaneTab('answers');
|
|
807
|
-
else document.getElementById('ai-answers-tab')?.classList.add('instructor-answer-new');
|
|
808
|
-
announceAnswers('Sending your question. Pending work is shown in AI answers.');
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
function settleOptimisticInstructorRequest(fingerprint, request = null) {
|
|
812
|
-
const optimistic = optimisticInstructorRequests.get(fingerprint);
|
|
813
|
-
optimisticInstructorRequests.delete(fingerprint);
|
|
814
|
-
if (request?.id) {
|
|
815
|
-
const runtime = request.runtime || optimistic?.runtime;
|
|
816
|
-
const existing = pendingRequests.find((candidate) => candidate?.id === request.id);
|
|
817
|
-
if (!existing) {
|
|
818
|
-
pendingRequests = [{ ...request, ...(runtime ? { runtime } : {}) }, ...pendingRequests];
|
|
819
|
-
} else if (runtime && !existing.runtime) {
|
|
820
|
-
pendingRequests = pendingRequests.map((candidate) => candidate?.id === request.id
|
|
821
|
-
? { ...candidate, runtime }
|
|
822
|
-
: candidate);
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
renderInstructorAnswers({ revealNew: false });
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
function renderInstructorAnswers({ revealNew = true } = {}) {
|
|
829
|
-
const feed = document.getElementById('ai-answers');
|
|
830
|
-
if (!feed) return;
|
|
831
|
-
// A card mid-way through the deferred-delete window is filtered out of every render, so a poll
|
|
832
|
-
// that refreshes the feed can't flash it back into view before its Undo window closes.
|
|
833
|
-
const visible = instructorAnswers.filter(answerInVisibleScope).filter((answer) => !pendingDeleteAnswerIds.has(answer.id));
|
|
834
|
-
// Newest-first: the latest answer sits at the top. A blind reverse of the stored order would ride
|
|
835
|
-
// on filesystem read order; sorting on finishedAt is the ordering the user actually asked for.
|
|
836
|
-
const ordered = [...visible].sort((a, b) => String(b.finishedAt || '').localeCompare(String(a.finishedAt || '')));
|
|
837
|
-
const pending = visiblePendingInstructorRequests()
|
|
838
|
-
.sort((a, b) => String(b.createdAt || '').localeCompare(String(a.createdAt || '')));
|
|
839
|
-
const wasNearTop = feed.scrollTop < 72;
|
|
840
|
-
const unseen = revealNew ? visible.filter((answer) => arrivedInstructorAnswerIds.has(answer.id)) : [];
|
|
841
|
-
const unreadCount = visible.filter((answer) => !readInstructorAnswerIds.has(answer.id)).length;
|
|
842
|
-
const unreadBadge = document.getElementById('answer-unread');
|
|
843
|
-
const answersTab = document.getElementById('ai-answers-tab');
|
|
844
|
-
if (unreadBadge) {
|
|
845
|
-
unreadBadge.textContent = unreadCount > 9 ? '9+' : String(unreadCount);
|
|
846
|
-
unreadBadge.hidden = unreadCount === 0;
|
|
847
|
-
}
|
|
848
|
-
if (unreadCount) answersTab?.setAttribute('aria-label', `AI answers, ${unreadCount} unread`);
|
|
849
|
-
else answersTab?.removeAttribute('aria-label');
|
|
850
|
-
const newAnswer = unseen.length ? unseen[unseen.length - 1] : null;
|
|
851
|
-
feed.innerHTML = '';
|
|
852
|
-
if (!ordered.length && !pending.length) {
|
|
853
|
-
const scope = wsRequestScope?.kind === 'project' ? 'this project' : wsRequestScope ? 'Workspaces' : 'this workflow';
|
|
854
|
-
feed.innerHTML = `<div class="ai-answers-empty" tabindex="-1">No AI answers for ${scope} yet. Direct answers you start from Instructor will appear here.</div>`;
|
|
855
|
-
} else {
|
|
856
|
-
if (ordered.length) feed.appendChild(answersToolbar(ordered));
|
|
857
|
-
pending.forEach((request) => feed.appendChild(pendingInstructorCard(request)));
|
|
858
|
-
ordered.forEach((answer) => feed.appendChild(answerCard(answer, answer === newAnswer)));
|
|
859
|
-
}
|
|
860
|
-
syncAnswerBulkToggle();
|
|
861
|
-
if (!newAnswer) {
|
|
862
|
-
return;
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
const obscured = !!document.querySelector('.modal-backdrop.show') || !!($contractEditor && !$contractEditor.hidden);
|
|
866
|
-
const wasCollapsed = state.collapse.left;
|
|
867
|
-
if (wasCollapsed && !obscured) {
|
|
868
|
-
state.collapse.left = false;
|
|
869
|
-
applyCollapse(); // session reveal only; the user's saved collapse preference remains untouched
|
|
870
|
-
// No focus hand-off: the pane has ONE grip now, in its rail, and a focused grip stays focused. The
|
|
871
|
-
// collapsed-stub copy this used to move focus away from no longer exists.
|
|
872
|
-
}
|
|
873
|
-
const paneAlreadyOpenOnAnswers = !wasCollapsed && leftPaneTab === 'answers';
|
|
874
|
-
if (wasCollapsed && !obscured) selectLeftPaneTab('answers');
|
|
875
|
-
else if (!paneAlreadyOpenOnAnswers) {
|
|
876
|
-
if (unreadBadge) unreadBadge.hidden = false;
|
|
877
|
-
document.getElementById('ai-answers-tab')?.classList.add('instructor-answer-new');
|
|
878
|
-
}
|
|
879
|
-
const card = feed.querySelector(`[data-answer-id="${CSS.escape(newAnswer.id)}"]`);
|
|
880
|
-
// Newest-first puts the arrival at the TOP, so the auto-scroll follows a reader sitting near the
|
|
881
|
-
// top — not the bottom, which now holds the oldest answers someone may be mid-read of.
|
|
882
|
-
if (card && !obscured && (wasCollapsed || (paneAlreadyOpenOnAnswers && wasNearTop))) requestAnimationFrame(() => card.scrollIntoView({ block: 'nearest' }));
|
|
883
|
-
const status = document.getElementById('narrative-answer-status');
|
|
884
|
-
if (status) status.textContent = wasCollapsed && !obscured
|
|
885
|
-
? `Terminal AI answered about ${newAnswer.instructorContext.subject}. AI answers opened.`
|
|
886
|
-
: `New AI answer about ${newAnswer.instructorContext.subject}. Open AI answers.`;
|
|
887
|
-
unseen.forEach((answer) => arrivedInstructorAnswerIds.delete(answer.id));
|
|
888
|
-
if (answerGlowTimer) clearTimeout(answerGlowTimer);
|
|
889
|
-
answerGlowTimer = setTimeout(() => {
|
|
890
|
-
card?.classList.remove('instructor-answer-new');
|
|
891
|
-
document.getElementById('ai-answers-tab')?.classList.remove('instructor-answer-new');
|
|
892
|
-
if (status) status.textContent = '';
|
|
893
|
-
answerGlowTimer = null;
|
|
894
|
-
}, 2100);
|
|
895
|
-
}
|
|
896
|
-
|
|
237
|
+
// Production conversations own #messages. Older workflow code still calls renderChat()
|
|
238
|
+
// after a scope or app change, so this established seam refreshes durable AI Chat.
|
|
897
239
|
renderChat = function renderChatSync() {
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
(p.narration || []).forEach((line) => $messages.appendChild(msgEl('aware', 'claude', mdInline(line))));
|
|
903
|
-
}
|
|
904
|
-
$messages.scrollTop = $messages.scrollHeight;
|
|
240
|
+
// Production conversations own #messages. Older workflow code still calls renderChat()
|
|
241
|
+
// after a scope or app change, so turn that established seam into a scope refresh instead
|
|
242
|
+
// of letting demo narration erase a durable chat transcript.
|
|
243
|
+
window.flolessChat?.refreshScope?.();
|
|
905
244
|
};
|
|
906
245
|
|
|
907
246
|
// Declared here, above its first use in api(), rather than beside the recovery helper that reads
|
|
@@ -943,6 +282,7 @@
|
|
|
943
282
|
(body.code === 'maintenance-busy' && body.message) || body.error || `HTTP ${res.status}`,
|
|
944
283
|
);
|
|
945
284
|
err.body = body; // preserve the in-band payload (e.g. credentialIssue) for callers
|
|
285
|
+
err.status = res.status; // callers need to distinguish a terminal refusal from a transient outage
|
|
946
286
|
throw err;
|
|
947
287
|
}
|
|
948
288
|
return body;
|
|
@@ -1153,7 +493,7 @@
|
|
|
1153
493
|
const mode = escapeHtml(n.mode);
|
|
1154
494
|
const modeBadge = `<span class="lvl ${n.mode === 'write' ? 'warn' : 'info'}">${mode}</span>`;
|
|
1155
495
|
const notesHtml = n.notes.length
|
|
1156
|
-
? `<p><strong>
|
|
496
|
+
? `<p><strong>Workflow notices:</strong></p><ul>${n.notes.map((x) => `<li><span class="note-kind ${x.kind}">${x.kind}</span> ${escapeHtml(humanizeNote(x.text))}</li>`).join('')}</ul>`
|
|
1157
497
|
: '';
|
|
1158
498
|
const inputs = n.inputs && Object.keys(n.inputs).length ? n.inputs : n.config;
|
|
1159
499
|
// The exec node's Roslyn C# (the actual script the host runs). null for
|
|
@@ -1224,15 +564,15 @@
|
|
|
1224
564
|
`Reading **${escapeHtml(app.name)}** from \`~/.aware/apps/${escapeHtml(app.id)}\` — the canvas is a view of the real \`.flo\`.`,
|
|
1225
565
|
...app.nodes.map((n) => `**${escapeHtml(n.id)}** → \`${escapeHtml(n.agent || n.kind)}${n.command ? '/' + escapeHtml(n.command) : ''}\` · ${escapeHtml(n.mode)}`),
|
|
1226
566
|
];
|
|
1227
|
-
if (app.notes.length) narration.push(`ℹ ${app.notes.length}
|
|
567
|
+
if (app.notes.length) narration.push(`ℹ ${app.notes.length} workflow notice${app.notes.length === 1 ? '' : 's'} — review them above the canvas.`);
|
|
1228
568
|
const maintainedDrift = app.publisher === 'floless' && !app.forked && app.runState === 'drift';
|
|
1229
569
|
narration.push(app.runnable
|
|
1230
|
-
? '
|
|
570
|
+
? 'The workflow matches its approved version. Review any notices before running.'
|
|
1231
571
|
: maintainedDrift
|
|
1232
572
|
? 'The workflow logic changed since it was last approved. **Restore** the official version, or **Customize** it to make it your own.'
|
|
1233
573
|
: app.runState === 'drift'
|
|
1234
|
-
? 'The
|
|
1235
|
-
: '
|
|
574
|
+
? 'The workflow changed since it was approved. Click **Compile** before running it.'
|
|
575
|
+
: 'This workflow has not been compiled yet. Click **Compile** to prepare it for running.');
|
|
1236
576
|
|
|
1237
577
|
if (app.layout === 'dag') {
|
|
1238
578
|
PROMPTS[app.id] = { name: app.name, layout: 'dag', nodes: layoutDag(app.nodes, app.connections), connections: app.connections, userText, narration };
|
|
@@ -1375,6 +715,13 @@
|
|
|
1375
715
|
|
|
1376
716
|
if (app.notes.length) {
|
|
1377
717
|
const n = app.notes.length;
|
|
718
|
+
const missing = missingAgentGroups(app.notes);
|
|
719
|
+
const installed = installedIdSet();
|
|
720
|
+
const pending = [...missing.keys()].filter((id) => installingIds.has(id) || missingAgentFailures.has(workflowAgentKey(id)) || (!installed.has(id) && !completedAgentInstalls.has(workflowAgentKey(id))));
|
|
721
|
+
const canInstall = pending.filter((id) => !installingIds.has(id));
|
|
722
|
+
const unchecked = [...missing.keys()].some((id) => installed.has(id) && !completedAgentInstalls.has(workflowAgentKey(id)));
|
|
723
|
+
const nextAction = pending.some((id) => missingAgentFailures.has(workflowAgentKey(id))) ? 'attention' : 'installing';
|
|
724
|
+
const ordinaryNotes = app.notes.filter((nt) => !missingAgentId(nt.text));
|
|
1378
725
|
const sig = notesSig(app.notes);
|
|
1379
726
|
// Strip severity = worst note kind (info < warn < error). Drives colour +
|
|
1380
727
|
// icon; AWARE 0.48 tags each note with `kind` (#170) so we render by it
|
|
@@ -1388,9 +735,11 @@
|
|
|
1388
735
|
$notesStrip.classList.remove('sev-info', 'sev-warn', 'sev-error');
|
|
1389
736
|
$notesStrip.classList.add('sev-' + worst);
|
|
1390
737
|
$notesStrip.innerHTML =
|
|
1391
|
-
`<div class="notes-head"><span class="notes-title">${icon} ${n}
|
|
738
|
+
`<div class="notes-head"><span class="notes-title">${icon} ${missing.size ? (pending.length ? `${pending.length} agent${pending.length === 1 ? ' needs' : 's need'} ${nextAction}` : unchecked ? 'Check agent installations before compiling' : 'Agents installed — compile to refresh checks') : `${n} workflow notice${n === 1 ? '' : 's'}`}</span>` +
|
|
739
|
+
missingAgentsBulkButton(pending, canInstall) +
|
|
1392
740
|
`<button class="notes-dismiss" type="button" aria-label="Collapse compiler notes" data-tip="Collapse">×</button></div>` +
|
|
1393
|
-
|
|
741
|
+
(missing.size ? `<ul class="missing-agent-list" aria-live="polite">${missingAgentRows(missing)}</ul>` : '') +
|
|
742
|
+
(ordinaryNotes.length ? `<ul>${ordinaryNotes.map((nt) => `<li><span class="note-kind ${nt.kind}">${nt.kind}</span><code>${escapeHtml(nt.nodeId)}</code> — ${escapeHtml(humanizeNote(nt.text))}</li>`).join('')}</ul>` : '');
|
|
1394
743
|
// Collapse decision: a remembered choice for this exact note set wins;
|
|
1395
744
|
// otherwise default to collapsed for benign info-only sets (keep the canvas
|
|
1396
745
|
// quiet for AEC users) and expanded when anything is warn/error.
|
|
@@ -1736,11 +1085,24 @@
|
|
|
1736
1085
|
|
|
1737
1086
|
const activeInstructorRuns = new Map();
|
|
1738
1087
|
|
|
1739
|
-
function
|
|
1088
|
+
function instructorRequestClientFingerprint(request) {
|
|
1089
|
+
const body = { instructorContext: request?.instructorContext };
|
|
1090
|
+
if (request?.project) {
|
|
1091
|
+
body.project = request.project;
|
|
1092
|
+
body.projectLabel = request.projectLabel;
|
|
1093
|
+
body.appId = request.appId;
|
|
1094
|
+
} else if (request?.appId) {
|
|
1095
|
+
body.appId = request.appId;
|
|
1096
|
+
if (request.workflowId) body.workflowId = request.workflowId;
|
|
1097
|
+
}
|
|
1098
|
+
return JSON.stringify(body);
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
function reconcileActiveInstructorRuns(requests = [], publications = []) {
|
|
1740
1102
|
for (const [fingerprint, requestId] of activeInstructorRuns) {
|
|
1741
1103
|
const stillRunning = requests.some((request) => request?.id === requestId
|
|
1742
1104
|
&& (request.run?.state === 'queued' || request.run?.state === 'running'));
|
|
1743
|
-
const answered =
|
|
1105
|
+
const answered = publications.some((publication) => publication.requestId === requestId);
|
|
1744
1106
|
if (answered || !stillRunning) activeInstructorRuns.delete(fingerprint);
|
|
1745
1107
|
}
|
|
1746
1108
|
}
|
|
@@ -1758,6 +1120,8 @@
|
|
|
1758
1120
|
}
|
|
1759
1121
|
} else if (currentId) {
|
|
1760
1122
|
body.appId = currentId;
|
|
1123
|
+
const workflowId = apps.get(currentId)?.ownedWorkflow?.workflowId;
|
|
1124
|
+
if (workflowId) body.workflowId = workflowId;
|
|
1761
1125
|
}
|
|
1762
1126
|
return body;
|
|
1763
1127
|
}
|
|
@@ -1765,21 +1129,29 @@
|
|
|
1765
1129
|
async function instructorAskOptions() {
|
|
1766
1130
|
const info = await refreshHeadless();
|
|
1767
1131
|
const found = info && Array.isArray(info.runtimes)
|
|
1768
|
-
? info.runtimes.filter((runtime) => runtime && runtime.state === 'found'
|
|
1132
|
+
? info.runtimes.filter((runtime) => runtime && runtime.state === 'found'
|
|
1133
|
+
&& (runtime.id === 'claude' || runtime.id === 'codex'))
|
|
1769
1134
|
: [];
|
|
1770
1135
|
return { found, provider: info && info.provider };
|
|
1771
1136
|
}
|
|
1772
1137
|
|
|
1773
1138
|
async function startInstructorAnswer(request, runtime, fingerprint) {
|
|
1774
1139
|
activeInstructorRuns.set(fingerprint, request.id);
|
|
1775
|
-
renderInstructorAnswers({ revealNew: false });
|
|
1776
1140
|
try {
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1141
|
+
let chosen = runtime;
|
|
1142
|
+
if (chosen !== 'claude' && chosen !== 'codex') {
|
|
1143
|
+
const options = await instructorAskOptions();
|
|
1144
|
+
chosen = options.provider === 'claude' || options.provider === 'codex'
|
|
1145
|
+
? options.provider
|
|
1146
|
+
: options.found.find((candidate) => candidate.id === 'claude' || candidate.id === 'codex')?.id;
|
|
1147
|
+
}
|
|
1148
|
+
if ((chosen !== 'claude' && chosen !== 'codex') || typeof window.flolessChat?.startRequest !== 'function') {
|
|
1149
|
+
throw new Error('Claude or Codex chat is unavailable');
|
|
1150
|
+
}
|
|
1151
|
+
await window.flolessChat.startRequest(request.id, chosen);
|
|
1152
|
+
showToast(`Started in ${runtimeLabel(chosen)} — continue in AI Chat`, 'ok');
|
|
1782
1153
|
await loadRequests();
|
|
1154
|
+
activeInstructorRuns.delete(fingerprint);
|
|
1783
1155
|
return true;
|
|
1784
1156
|
} catch (error) {
|
|
1785
1157
|
const copied = await copyToClipboard(markedInstruction(request));
|
|
@@ -1809,21 +1181,22 @@
|
|
|
1809
1181
|
return true;
|
|
1810
1182
|
}
|
|
1811
1183
|
|
|
1812
|
-
if (mode === 'direct') beginOptimisticInstructorRequest(body, options.runtime, fingerprint);
|
|
1813
|
-
|
|
1814
1184
|
let request;
|
|
1815
1185
|
try {
|
|
1816
1186
|
({ request } = await api('/api/guide', { method: 'POST', body: JSON.stringify(body) }));
|
|
1817
1187
|
} catch (e) {
|
|
1818
|
-
settleOptimisticInstructorRequest(fingerprint);
|
|
1819
1188
|
console.error(e);
|
|
1820
|
-
|
|
1821
|
-
|
|
1189
|
+
// Only refusals with known, user-facing wording name their cause; any other failure (a network
|
|
1190
|
+
// error, a validation or server error whose text is technical) gets the connection advice.
|
|
1191
|
+
const code = e?.body?.error;
|
|
1192
|
+
const reason = e?.body?.code === 'maintenance-busy' && e.message ? ` ${e.message}`
|
|
1193
|
+
: code === 'subscription required' || code === 'no_subscription'
|
|
1194
|
+
? ' Your FloLess subscription isn’t active. Check your FloLess account, then try again.'
|
|
1195
|
+
: code === 'signed_out' ? ' Your FloLess sign-in has expired. Sign in again, then try again.' : '';
|
|
1196
|
+
showToast(reason ? `Couldn’t send this request.${reason}` : 'Couldn’t send this request. Check that FloLess is online, then try again.', 'err');
|
|
1822
1197
|
return false;
|
|
1823
1198
|
}
|
|
1824
1199
|
|
|
1825
|
-
settleOptimisticInstructorRequest(fingerprint, request);
|
|
1826
|
-
|
|
1827
1200
|
if (mode === 'direct') {
|
|
1828
1201
|
// The durable question is visible now; run admission continues independently. The Ask control
|
|
1829
1202
|
// must not sit on “Starting…” while Windows capability checks and workspace setup happen.
|
|
@@ -1857,7 +1230,7 @@
|
|
|
1857
1230
|
if (!found.length) return requestInstructorHelp(instructorContext, { mode: 'queue' });
|
|
1858
1231
|
const result = await formModal({
|
|
1859
1232
|
title: 'Choose terminal AI',
|
|
1860
|
-
sub: 'This read-only
|
|
1233
|
+
sub: 'This starts a read-only conversation in the current project or workflow’s AI Chat.',
|
|
1861
1234
|
fields: [{
|
|
1862
1235
|
name: 'runtime', label: 'Terminal AI', type: 'select', value: provider || found[0].id,
|
|
1863
1236
|
commandId: 'shell.instructor-ask-runtime',
|
|
@@ -1869,17 +1242,57 @@
|
|
|
1869
1242
|
return requestInstructorHelp(instructorContext, { mode: 'direct', runtime: result.runtime });
|
|
1870
1243
|
}
|
|
1871
1244
|
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1245
|
+
function workflowOwnerOptions(projects) {
|
|
1246
|
+
return [
|
|
1247
|
+
{ value: 'standalone', label: 'Standalone', meta: 'available from Workflows' },
|
|
1248
|
+
...(projects || [])
|
|
1249
|
+
.slice()
|
|
1250
|
+
.sort((a, b) => String(a.name || a.id).localeCompare(String(b.name || b.id)))
|
|
1251
|
+
.map((project) => ({
|
|
1252
|
+
value: `project:${project.id}`,
|
|
1253
|
+
label: project.name || project.id,
|
|
1254
|
+
meta: `${project.templateId || project.app || 'Workspace'} project`,
|
|
1255
|
+
})),
|
|
1256
|
+
];
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
// ≡ menu "New workflow…" — create the durable owner BEFORE asking the terminal AI to author.
|
|
1260
|
+
// The UI chooses only a display name and owner; the server mints the UUID and derives the actual
|
|
1261
|
+
// directory. That makes a queued request project-safe without turning the browser into an author.
|
|
1877
1262
|
async function requestNewWorkflow() {
|
|
1878
1263
|
try {
|
|
1879
|
-
const {
|
|
1264
|
+
const { projects = [] } = await api('/api/projects');
|
|
1265
|
+
const ownerOptions = workflowOwnerOptions(projects);
|
|
1266
|
+
const result = await formModal({
|
|
1267
|
+
title: 'Start a workflow',
|
|
1268
|
+
sub: 'Choose where it belongs. Its files, chat, history and AI working folder stay with that location.',
|
|
1269
|
+
fields: [
|
|
1270
|
+
{
|
|
1271
|
+
name: 'name', label: 'Workflow name', placeholder: 'e.g. Weekly model review',
|
|
1272
|
+
commandId: 'shell.new-workflow-name', required: true,
|
|
1273
|
+
},
|
|
1274
|
+
{
|
|
1275
|
+
name: 'owner', label: 'Location', type: 'select', value: 'standalone',
|
|
1276
|
+
commandId: 'shell.new-workflow-location', options: ownerOptions,
|
|
1277
|
+
},
|
|
1278
|
+
],
|
|
1279
|
+
okLabel: 'Start workflow',
|
|
1280
|
+
});
|
|
1281
|
+
if (!result) return;
|
|
1282
|
+
const name = String(result.name || '').trim();
|
|
1283
|
+
if (!name) { showToast('Enter a workflow name', 'warn'); return; }
|
|
1284
|
+
const owner = String(result.owner || '').startsWith('project:')
|
|
1285
|
+
? { kind: 'project', projectId: String(result.owner).slice('project:'.length) }
|
|
1286
|
+
: { kind: 'standalone' };
|
|
1287
|
+
const { workflow } = await api('/api/workflows/owned', {
|
|
1288
|
+
method: 'POST', body: JSON.stringify({ name, owner }),
|
|
1289
|
+
});
|
|
1290
|
+
const { request } = await api('/api/guide-new', {
|
|
1291
|
+
method: 'POST', body: JSON.stringify({ workflowId: workflow.workflowId }),
|
|
1292
|
+
});
|
|
1880
1293
|
const copied = await copyToClipboard(markedInstruction(request));
|
|
1881
|
-
showToast(copied ?
|
|
1882
|
-
appendNarration(`
|
|
1294
|
+
showToast(copied ? `${name} is ready · prompt copied` : `${name} is ready to discuss`, 'ok');
|
|
1295
|
+
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.' : ''}`);
|
|
1883
1296
|
loadRequests();
|
|
1884
1297
|
} catch (e) { reportErr(e); }
|
|
1885
1298
|
}
|
|
@@ -1972,6 +1385,8 @@
|
|
|
1972
1385
|
// publication clears, rather than keeping the previous answer forever.
|
|
1973
1386
|
await commitPublicationAvailability(id, read, contractState);
|
|
1974
1387
|
currentId = id;
|
|
1388
|
+
workflowSelectionGeneration += 1;
|
|
1389
|
+
notifyChatScope();
|
|
1975
1390
|
// The Templates strip also carries app-scoped quick actions. Templates may have
|
|
1976
1391
|
// loaded before this app did, so repaint it once the ownership boundary is known.
|
|
1977
1392
|
renderFavBar();
|
|
@@ -1985,7 +1400,6 @@
|
|
|
1985
1400
|
setComboTriggerLabel(id);
|
|
1986
1401
|
setComboSelected(id);
|
|
1987
1402
|
renderChat();
|
|
1988
|
-
renderInstructorAnswers({ revealNew: hydratedInstructorAnswers });
|
|
1989
1403
|
renderTopology(); // selects first node + renderInspect
|
|
1990
1404
|
paintModes();
|
|
1991
1405
|
markStars();
|
|
@@ -2057,7 +1471,8 @@
|
|
|
2057
1471
|
renderCanvasPlaceholder('loading');
|
|
2058
1472
|
let list;
|
|
2059
1473
|
try {
|
|
2060
|
-
({ apps: list } = await api('/api/
|
|
1474
|
+
({ apps: list } = await api('/api/workflows/library'));
|
|
1475
|
+
list = list.filter((a) => a.execution !== 'internal');
|
|
2061
1476
|
} catch (e) {
|
|
2062
1477
|
if (wasUsable && $wfTrigger) $wfTrigger.disabled = false;
|
|
2063
1478
|
throw e;
|
|
@@ -2069,6 +1484,7 @@
|
|
|
2069
1484
|
// notes, and a yellow band for a neutral first-run reads as a false alarm).
|
|
2070
1485
|
$notesStrip.hidden = true;
|
|
2071
1486
|
currentId = null;
|
|
1487
|
+
workflowSelectionGeneration += 1;
|
|
2072
1488
|
refreshKbInformed(null); // invalidate any in-flight app read and remove workflow-only provenance
|
|
2073
1489
|
$runBtn.disabled = true;
|
|
2074
1490
|
$compileBtn.disabled = true;
|
|
@@ -2085,7 +1501,7 @@
|
|
|
2085
1501
|
for (const a of list) {
|
|
2086
1502
|
const opt = document.createElement('option');
|
|
2087
1503
|
opt.value = a.id;
|
|
2088
|
-
opt.textContent = `${a.id} · ${a.nodes} node${a.nodes === 1 ? '' : 's'} · ${a.layout}`;
|
|
1504
|
+
opt.textContent = `${a.ownedWorkflow ? a.ownedWorkflow.displayName : a.id} · ${a.nodes} node${a.nodes === 1 ? '' : 's'} · ${a.layout}`;
|
|
2089
1505
|
$promptSel.appendChild(opt);
|
|
2090
1506
|
}
|
|
2091
1507
|
buildWorkflowCombo(list); // searchable, provider-grouped picker over the hidden select
|
|
@@ -2174,10 +1590,10 @@
|
|
|
2174
1590
|
];
|
|
2175
1591
|
let html = '';
|
|
2176
1592
|
for (const p of order) {
|
|
2177
|
-
const rows = groups.get(p).slice().sort((x, y) => x.id.localeCompare(y.id));
|
|
1593
|
+
const rows = groups.get(p).slice().sort((x, y) => String(x.ownedWorkflow?.displayName || x.id).localeCompare(String(y.ownedWorkflow?.displayName || y.id)));
|
|
2178
1594
|
html += `<div class="wf-group" role="group" aria-label="${escapeAttr(providerLabel(p))}"><div class="wf-group-header">${escapeHtml(providerLabel(p))}</div>`;
|
|
2179
1595
|
for (const a of rows) {
|
|
2180
|
-
const meta = `${escapeHtml(String(a.nodes))} node${a.nodes === 1 ? '' : 's'} · ${escapeHtml(String(a.layout))}`;
|
|
1596
|
+
const meta = `${a.ownedWorkflow ? `${escapeHtml(a.ownerLabel || 'Standalone')} · ` : ''}${escapeHtml(String(a.nodes))} node${a.nodes === 1 ? '' : 's'} · ${escapeHtml(String(a.layout))}`;
|
|
2181
1597
|
// A div (not a button) carries role="option" so the action icons can be real
|
|
2182
1598
|
// <button>s without nesting interactive elements (#85). Selection stays driven by
|
|
2183
1599
|
// the delegated $wfList click + comboMove highlight (aria-activedescendant).
|
|
@@ -2186,13 +1602,21 @@
|
|
|
2186
1602
|
// `<template>#<instance>`. The template is registered once (see
|
|
2187
1603
|
// web/commands-shell.js); instances register nothing, so the
|
|
2188
1604
|
// registry never churns with workflow data.
|
|
2189
|
-
|
|
2190
|
-
|
|
1605
|
+
const workflowName = a.ownedWorkflow?.displayName || a.id;
|
|
1606
|
+
const ownedId = a.ownedWorkflow?.workflowId || '';
|
|
1607
|
+
const owned = !!ownedId;
|
|
1608
|
+
const actions = owned
|
|
1609
|
+
? `<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>`
|
|
1610
|
+
+ `<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>`
|
|
1611
|
+
+ `<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>`
|
|
1612
|
+
: `<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>`
|
|
1613
|
+
+ `<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>`
|
|
1614
|
+
+ `<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>`;
|
|
1615
|
+
html += `<div class="wf-option" role="option" id="wf-opt-${aid}" data-id="${aid}" data-workflow-id="${escapeAttr(ownedId)}" data-workflow-name="${escapeAttr(workflowName)}" data-command-id="workflow.select#${escapeAttr(aid)}" data-baked="${a.baked ? '1' : ''}" data-search="${escapeAttr((workflowName + ' ' + a.id + ' ' + (a.ownerLabel || '') + ' ' + p).toLowerCase())}" tabindex="-1" aria-selected="false">`
|
|
1616
|
+
+ `<span class="wf-option-name">${escapeHtml(workflowName)}</span><span class="wf-option-meta">${meta}</span>`
|
|
2191
1617
|
+ (a.forked ? `<span class="wf-fork-badge" data-tip="You forked this workflow — it no longer receives FloLess updates. You own its output.">yours</span>` : '')
|
|
2192
1618
|
+ `<span class="wf-option-actions">`
|
|
2193
|
-
+
|
|
2194
|
-
+ `<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 ${aid}">⧉</button>`
|
|
2195
|
-
+ `<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 ${aid}">×</button>`
|
|
1619
|
+
+ actions
|
|
2196
1620
|
+ `</span></div>`;
|
|
2197
1621
|
}
|
|
2198
1622
|
html += '</div>';
|
|
@@ -2314,7 +1738,13 @@
|
|
|
2314
1738
|
const act = e.target.closest('[data-wf-act]');
|
|
2315
1739
|
if (act) {
|
|
2316
1740
|
const id = act.dataset.id;
|
|
2317
|
-
|
|
1741
|
+
const row = act.closest('.wf-option');
|
|
1742
|
+
const workflowId = row?.dataset.workflowId;
|
|
1743
|
+
const workflowName = row?.dataset.workflowName || id;
|
|
1744
|
+
if (workflowId && act.dataset.wfAct === 'rename') renameOwnedWorkflow(workflowId, workflowName);
|
|
1745
|
+
else if (workflowId && act.dataset.wfAct === 'duplicate') copyOwnedWorkflow(workflowId, workflowName);
|
|
1746
|
+
else if (workflowId && act.dataset.wfAct === 'delete') archiveOwnedWorkflow(workflowId, workflowName);
|
|
1747
|
+
else if (act.dataset.wfAct === 'rename') openRenameWorkflow(id, row?.dataset.baked === '1');
|
|
2318
1748
|
else if (act.dataset.wfAct === 'duplicate') openDuplicateWorkflow(id);
|
|
2319
1749
|
else if (act.dataset.wfAct === 'delete') confirmDeleteWorkflow(id);
|
|
2320
1750
|
return;
|
|
@@ -2353,6 +1783,82 @@
|
|
|
2353
1783
|
appInputValues.delete(id); dirtyBaseline.delete(id); apps.delete(id); contractStates.delete(id);
|
|
2354
1784
|
}
|
|
2355
1785
|
|
|
1786
|
+
async function renameOwnedWorkflow(workflowId, oldName) {
|
|
1787
|
+
closeCombo(false);
|
|
1788
|
+
const res = await formModal({
|
|
1789
|
+
title: 'Rename workflow',
|
|
1790
|
+
sub: 'Changes its name in FloLess. The working folder and published runtime identity stay the same.',
|
|
1791
|
+
fields: [{ name: 'name', label: 'Workflow name', value: oldName, required: true, commandId: 'shell.new-workflow-name' }],
|
|
1792
|
+
okLabel: 'Rename',
|
|
1793
|
+
});
|
|
1794
|
+
if (!res || String(res.name || '').trim() === oldName) return;
|
|
1795
|
+
try {
|
|
1796
|
+
const { workflow } = await api(`/api/workflows/owned/${encodeURIComponent(workflowId)}`, {
|
|
1797
|
+
method: 'PATCH', body: JSON.stringify({ name: String(res.name || '').trim() }),
|
|
1798
|
+
});
|
|
1799
|
+
await loadApps();
|
|
1800
|
+
showToast(`Renamed to “${workflow.displayName}”`, 'ok');
|
|
1801
|
+
} catch (e) { reportErr(e); }
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
async function copyOwnedWorkflow(workflowId, oldName) {
|
|
1805
|
+
closeCombo(false);
|
|
1806
|
+
try {
|
|
1807
|
+
const [{ review }, { projects = [] }, { workflow: source }] = await Promise.all([
|
|
1808
|
+
api(`/api/workflows/owned/${encodeURIComponent(workflowId)}/copy-review`),
|
|
1809
|
+
api('/api/projects'),
|
|
1810
|
+
api(`/api/workflows/owned/${encodeURIComponent(workflowId)}`),
|
|
1811
|
+
]);
|
|
1812
|
+
const findings = (review.findings || []).map((finding) => finding.summary);
|
|
1813
|
+
const defaultOwner = source.owner?.kind === 'project' ? `project:${source.owner.projectId}` : 'standalone';
|
|
1814
|
+
const fields = [
|
|
1815
|
+
{ name: 'name', label: 'Workflow name', value: `${oldName} copy`, required: true, commandId: 'shell.new-workflow-name' },
|
|
1816
|
+
{ name: 'owner', label: 'Location', type: 'select', value: defaultOwner, commandId: 'shell.new-workflow-location', options: workflowOwnerOptions(projects) },
|
|
1817
|
+
];
|
|
1818
|
+
if (findings.length) {
|
|
1819
|
+
fields.push({ name: 'review', label: 'Check before copying', type: 'note', value: findings.join('\n') });
|
|
1820
|
+
fields.push({ name: 'accept', label: 'I reviewed these project-specific references', type: 'checkbox', required: true });
|
|
1821
|
+
}
|
|
1822
|
+
const res = await formModal({
|
|
1823
|
+
title: 'Copy workflow',
|
|
1824
|
+
sub: findings.length
|
|
1825
|
+
? 'The copy gets a new identity. Review references that may still point to the original location.'
|
|
1826
|
+
: 'The copy gets a new identity and its own source, chat and history.',
|
|
1827
|
+
fields,
|
|
1828
|
+
okLabel: 'Copy workflow',
|
|
1829
|
+
});
|
|
1830
|
+
if (!res) return;
|
|
1831
|
+
const owner = String(res.owner || '').startsWith('project:')
|
|
1832
|
+
? { kind: 'project', projectId: String(res.owner).slice('project:'.length) }
|
|
1833
|
+
: { kind: 'standalone' };
|
|
1834
|
+
const { workflow } = await api(`/api/workflows/owned/${encodeURIComponent(workflowId)}/copy`, {
|
|
1835
|
+
method: 'POST',
|
|
1836
|
+
body: JSON.stringify({
|
|
1837
|
+
name: String(res.name || '').trim(), owner,
|
|
1838
|
+
reviewedSourceDigest: review.sourceDigest, acceptReview: true,
|
|
1839
|
+
}),
|
|
1840
|
+
});
|
|
1841
|
+
showToast(`Copied as “${workflow.displayName}”`, 'ok');
|
|
1842
|
+
} catch (e) { reportErr(e); }
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
async function archiveOwnedWorkflow(workflowId, name) {
|
|
1846
|
+
closeCombo(false);
|
|
1847
|
+
const res = await formModal({
|
|
1848
|
+
title: 'Archive workflow?',
|
|
1849
|
+
sub: `Hide “${name}” from Workflows and block new runs. Its source, chat, history and publications stay on this computer and can be restored.`,
|
|
1850
|
+
fields: [], okLabel: 'Archive', safeDefault: true,
|
|
1851
|
+
});
|
|
1852
|
+
if (!res) return;
|
|
1853
|
+
try {
|
|
1854
|
+
await api(`/api/workflows/owned/${encodeURIComponent(workflowId)}/archive`, {
|
|
1855
|
+
method: 'POST', body: JSON.stringify({ archived: true }),
|
|
1856
|
+
});
|
|
1857
|
+
await loadApps();
|
|
1858
|
+
showToast(`Archived “${name}”`, 'ok');
|
|
1859
|
+
} catch (e) { reportErr(e); }
|
|
1860
|
+
}
|
|
1861
|
+
|
|
2356
1862
|
/**
|
|
2357
1863
|
* What the SERVER said about where this workflow's contract lives — never inferred here.
|
|
2358
1864
|
*
|
|
@@ -2424,7 +1930,7 @@
|
|
|
2424
1930
|
}
|
|
2425
1931
|
} catch (e) {
|
|
2426
1932
|
console.error(e); // an unexpected client throw (not a clean server message) stays debuggable
|
|
2427
|
-
showToast(
|
|
1933
|
+
showToast('We couldn’t rename that workflow because FloLess could not save the change. Try again.', 'warn');
|
|
2428
1934
|
}
|
|
2429
1935
|
}
|
|
2430
1936
|
|
|
@@ -2448,7 +1954,7 @@
|
|
|
2448
1954
|
showToast(r.compiled ? `Duplicated as “${r.id}”` : `Duplicated as “${r.id}” — needs Compile`, r.compiled ? 'ok' : 'warn');
|
|
2449
1955
|
} catch (e) {
|
|
2450
1956
|
console.error(e);
|
|
2451
|
-
showToast(
|
|
1957
|
+
showToast('We couldn’t make a copy because FloLess could not save it. Try again.', 'warn');
|
|
2452
1958
|
}
|
|
2453
1959
|
}
|
|
2454
1960
|
|
|
@@ -2572,12 +2078,12 @@
|
|
|
2572
2078
|
await api(`/api/app/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
2573
2079
|
const wasOpen = currentId === id;
|
|
2574
2080
|
dropClientAppState(id);
|
|
2575
|
-
if (wasOpen) { currentId = null; try { localStorage.removeItem(LS_LAST_APP); } catch { /* ignore */ } }
|
|
2081
|
+
if (wasOpen) { currentId = null; workflowSelectionGeneration += 1; try { localStorage.removeItem(LS_LAST_APP); } catch { /* ignore */ } }
|
|
2576
2082
|
await loadApps();
|
|
2577
2083
|
showToast(`Deleted “${id}”`, 'ok');
|
|
2578
2084
|
} catch (e) {
|
|
2579
2085
|
console.error(e);
|
|
2580
|
-
showToast(
|
|
2086
|
+
showToast('We couldn’t delete that workflow because FloLess could not save the change. Try again.', 'err'); // a failed destructive delete reads as an error
|
|
2581
2087
|
}
|
|
2582
2088
|
}
|
|
2583
2089
|
|
|
@@ -2610,7 +2116,7 @@
|
|
|
2610
2116
|
showToast('Forked — this workflow is now yours to edit. Run ⎙ Compile when you’re ready.', 'ok');
|
|
2611
2117
|
} catch (e) {
|
|
2612
2118
|
console.error(e);
|
|
2613
|
-
showToast(
|
|
2119
|
+
showToast('We couldn’t create that branch because FloLess could not save it. Try again.', 'warn');
|
|
2614
2120
|
}
|
|
2615
2121
|
}
|
|
2616
2122
|
|
|
@@ -2632,7 +2138,7 @@
|
|
|
2632
2138
|
showToast('Restored to the official version.', 'ok');
|
|
2633
2139
|
} catch (e) {
|
|
2634
2140
|
console.error(e);
|
|
2635
|
-
showToast(
|
|
2141
|
+
showToast('We couldn’t restore that workflow because FloLess could not save it. Try again.', 'warn');
|
|
2636
2142
|
}
|
|
2637
2143
|
}
|
|
2638
2144
|
|
|
@@ -2751,14 +2257,8 @@
|
|
|
2751
2257
|
}
|
|
2752
2258
|
}
|
|
2753
2259
|
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
if (!value || typeof value !== 'object') return `${prefix}: ${String(value)}`;
|
|
2757
|
-
const parts = [value.id, value.code, value.message].filter((part) => typeof part === 'string' && part.trim());
|
|
2758
|
-
if (parts.length) return `${prefix}: ${parts.join(' · ')}`;
|
|
2759
|
-
try { return `${prefix}: ${JSON.stringify(value)}`; }
|
|
2760
|
-
catch { return `${prefix}: detail unavailable`; }
|
|
2761
|
-
}
|
|
2260
|
+
// `receiptItemText` is app.js's. This popover and the Workspaces export card render the SAME
|
|
2261
|
+
// server receipt, and each used to carry its own identical copy of this line renderer.
|
|
2762
2262
|
|
|
2763
2263
|
function exportReceiptDetails(receipt) {
|
|
2764
2264
|
if (!receipt) return '';
|
|
@@ -2992,7 +2492,7 @@
|
|
|
2992
2492
|
await api('/api/tekla-readiness/setup', { method: 'POST' });
|
|
2993
2493
|
showToast('Tekla bridge installed.', 'ok');
|
|
2994
2494
|
} catch (error) {
|
|
2995
|
-
showToast(
|
|
2495
|
+
showToast('We couldn’t install the Tekla connection because FloLess could not finish the setup. Try again.', 'warn');
|
|
2996
2496
|
}
|
|
2997
2497
|
}
|
|
2998
2498
|
teklaReadinessState = { ok: false, state: 'checking' };
|
|
@@ -3347,15 +2847,79 @@
|
|
|
3347
2847
|
} catch { return []; }
|
|
3348
2848
|
}
|
|
3349
2849
|
|
|
2850
|
+
const unavailableModelRevisionResult = (error = 'transient') => ({ projects: [], error });
|
|
2851
|
+
|
|
2852
|
+
async function bootstrapEditorSession() {
|
|
2853
|
+
try {
|
|
2854
|
+
const r = await fetch('/api/editor/session', {
|
|
2855
|
+
method: 'POST',
|
|
2856
|
+
credentials: 'same-origin',
|
|
2857
|
+
cache: 'no-store',
|
|
2858
|
+
});
|
|
2859
|
+
const j = await r.json().catch(() => null);
|
|
2860
|
+
if (r.ok && j && j.ok) return { ok: true };
|
|
2861
|
+
if (r.status === 403 && j && j.error === 'editor_session_unavailable') return { ok: false, error: 'unavailable' };
|
|
2862
|
+
return { ok: false, error: 'transient' };
|
|
2863
|
+
} catch { return { ok: false, error: 'transient' }; }
|
|
2864
|
+
}
|
|
2865
|
+
|
|
2866
|
+
// Exact approved Revit model revisions for `widget: workspace-model-revision`. The picker
|
|
2867
|
+
// endpoint owns approval/account filtering and a signed, revision-bound cursor. A single retry
|
|
2868
|
+
// state survives every full-list restart, so alternating session loss and picker changes cannot
|
|
2869
|
+
// reset each other's bounds and mix more than one replacement snapshot into the result.
|
|
2870
|
+
async function fetchApprovedModelRevisions(retries = Object.freeze({ auth: 0, changed: 0 })) {
|
|
2871
|
+
try {
|
|
2872
|
+
const projects = new Map();
|
|
2873
|
+
let continuation = null;
|
|
2874
|
+
for (let page = 0; page < 20; page += 1) {
|
|
2875
|
+
const url = '/api/workspace-projects/model-revisions' + (continuation ? `?continuation=${encodeURIComponent(continuation)}` : '');
|
|
2876
|
+
const r = await fetch(url, { credentials: 'same-origin', cache: 'no-store' });
|
|
2877
|
+
const j = await r.json().catch(() => null);
|
|
2878
|
+
if (r.status === 401 && retries.auth < 1) {
|
|
2879
|
+
const bootstrap = await bootstrapEditorSession();
|
|
2880
|
+
if (!bootstrap.ok) return unavailableModelRevisionResult(bootstrap.error);
|
|
2881
|
+
return fetchApprovedModelRevisions(Object.freeze({ ...retries, auth: retries.auth + 1 }));
|
|
2882
|
+
}
|
|
2883
|
+
if (r.status === 409 && j && j.code === 'picker-changed' && retries.changed < 1) {
|
|
2884
|
+
return fetchApprovedModelRevisions(Object.freeze({ ...retries, changed: retries.changed + 1 }));
|
|
2885
|
+
}
|
|
2886
|
+
if (!r.ok || !j || !j.ok || !Array.isArray(j.projects)) return unavailableModelRevisionResult();
|
|
2887
|
+
for (const project of j.projects) {
|
|
2888
|
+
if (!project || typeof project.projectUuid !== 'string' || !Array.isArray(project.versions)) continue;
|
|
2889
|
+
const current = projects.get(project.projectUuid) || { projectUuid: project.projectUuid, name: project.name || 'Untitled project', versions: [] };
|
|
2890
|
+
current.versions.push(...project.versions); projects.set(project.projectUuid, current);
|
|
2891
|
+
}
|
|
2892
|
+
continuation = typeof j.continuation === 'string' && j.continuation ? j.continuation : null;
|
|
2893
|
+
if (!continuation) return { projects: [...projects.values()], error: null };
|
|
2894
|
+
}
|
|
2895
|
+
return unavailableModelRevisionResult();
|
|
2896
|
+
} catch { return unavailableModelRevisionResult(); }
|
|
2897
|
+
}
|
|
2898
|
+
|
|
3350
2899
|
// Double-click the input node → styled dialog to set the declared inputs. Writes
|
|
3351
2900
|
// to appInputValues; the header "▶ Run workflow" uses them. No native window.prompt.
|
|
3352
|
-
|
|
3353
|
-
const
|
|
2901
|
+
function openInputsDialog() {
|
|
2902
|
+
const appId = currentId;
|
|
2903
|
+
const generation = workflowSelectionGeneration;
|
|
2904
|
+
if (!appId) return Promise.resolve();
|
|
2905
|
+
const active = inputDialogFlights.get(appId);
|
|
2906
|
+
if (active && active.generation === generation) return active.promise;
|
|
2907
|
+
const promise = openInputsDialogFor(appId, generation).finally(() => {
|
|
2908
|
+
if (inputDialogFlights.get(appId)?.promise === promise) inputDialogFlights.delete(appId);
|
|
2909
|
+
});
|
|
2910
|
+
inputDialogFlights.set(appId, { generation, promise });
|
|
2911
|
+
return promise;
|
|
2912
|
+
}
|
|
2913
|
+
|
|
2914
|
+
async function openInputsDialogFor(appId, generation) {
|
|
2915
|
+
const app = apps.get(appId);
|
|
3354
2916
|
if (!app || !Array.isArray(app.inputs) || !app.inputs.length) return;
|
|
2917
|
+
const isCurrent = () => currentId === appId && workflowSelectionGeneration === generation;
|
|
3355
2918
|
const cur = currentInputs();
|
|
3356
2919
|
const isVisual = (inp) => inp.widget === 'file' || inp.type === 'image' || inp.type === 'file';
|
|
3357
2920
|
const isProject = (inp) => inp.widget === 'workspace-project';
|
|
3358
2921
|
const isKnowledgeProject = (inp) => inp.widget === 'workspace-knowledge-project';
|
|
2922
|
+
const isModelRevision = (inp) => inp.widget === 'workspace-model-revision';
|
|
3359
2923
|
const visualNames = new Set(app.inputs.filter(isVisual).map((i) => i.name));
|
|
3360
2924
|
// A project-picker input needs the live list of approved projects. Fetch ONE list per DISTINCT
|
|
3361
2925
|
// `workspaceApp` filter and let the SERVER decide what matches, rather than fetching everything
|
|
@@ -3371,8 +2935,21 @@
|
|
|
3371
2935
|
const projectFilters = [...new Set(app.inputs.filter(isProject)
|
|
3372
2936
|
.map((i) => (typeof i.workspaceApp === 'string' && i.workspaceApp ? i.workspaceApp : '')))];
|
|
3373
2937
|
const approvedByFilter = new Map();
|
|
3374
|
-
for (const f of projectFilters)
|
|
2938
|
+
for (const f of projectFilters) {
|
|
2939
|
+
approvedByFilter.set(f, await fetchApprovedProjects(f || undefined));
|
|
2940
|
+
if (!isCurrent()) return;
|
|
2941
|
+
}
|
|
3375
2942
|
const knowledgeProjects = app.inputs.some(isKnowledgeProject) ? await fetchKnowledgeProjects() : [];
|
|
2943
|
+
if (!isCurrent()) return;
|
|
2944
|
+
const hasModelRevision = app.inputs.some(isModelRevision);
|
|
2945
|
+
if (hasModelRevision) showToast('Loading approved Revit models…');
|
|
2946
|
+
let modelRevisions = { projects: [], error: null };
|
|
2947
|
+
if (hasModelRevision) {
|
|
2948
|
+
const bootstrap = await bootstrapEditorSession();
|
|
2949
|
+
if (!isCurrent()) return;
|
|
2950
|
+
modelRevisions = bootstrap.ok ? await fetchApprovedModelRevisions() : unavailableModelRevisionResult(bootstrap.error);
|
|
2951
|
+
if (!isCurrent()) return;
|
|
2952
|
+
}
|
|
3376
2953
|
const fields = app.inputs.map((inp) => {
|
|
3377
2954
|
if (isVisual(inp)) return {
|
|
3378
2955
|
name: inp.name,
|
|
@@ -3424,6 +3001,53 @@
|
|
|
3424
3001
|
emptyNote: 'No Workspace project has published knowledge yet — open <strong>Workspaces</strong>, choose a project, and Organize its Knowledge step before running this workflow.',
|
|
3425
3002
|
};
|
|
3426
3003
|
}
|
|
3004
|
+
if (isModelRevision(inp)) {
|
|
3005
|
+
const options = modelRevisions.projects
|
|
3006
|
+
.slice().sort((a, b) => String(a.name).localeCompare(String(b.name)))
|
|
3007
|
+
.flatMap((project) => {
|
|
3008
|
+
const selection = (extra) => JSON.stringify({ schemaVersion: 'floless.workspace-model-selection/v1', projectUuid: project.projectUuid, ...extra });
|
|
3009
|
+
const exact = project.versions.slice().sort((a, b) => Number(b.approvalVersion) - Number(a.approvalVersion)).map((version) => {
|
|
3010
|
+
const date = version.approvedAt ? new Date(version.approvedAt).toLocaleDateString(undefined, { day: 'numeric', month: 'short', year: 'numeric' }) : 'Date unavailable';
|
|
3011
|
+
const short = String(version.approvedRevisionId).slice(0, 10);
|
|
3012
|
+
return {
|
|
3013
|
+
value: selection({ approvedRevisionId: version.approvedRevisionId, approvalVersion: version.approvalVersion }),
|
|
3014
|
+
group: project.name, groupMeta: 'Revit model', label: `Approved v${version.approvalVersion}`,
|
|
3015
|
+
triggerLabel: `${project.name} · approved v${version.approvalVersion} · ${short}`,
|
|
3016
|
+
meta: `${date} · ${short}`,
|
|
3017
|
+
ariaLabel: `${project.name}, Revit model, approved version ${version.approvalVersion}, ${date}, revision ${version.approvedRevisionId}`,
|
|
3018
|
+
search: `${project.name} Revit approved version ${version.approvalVersion} ${date} ${version.approvedRevisionId}`,
|
|
3019
|
+
};
|
|
3020
|
+
});
|
|
3021
|
+
return [...exact, {
|
|
3022
|
+
value: selection({ latestApproved: true }), group: project.name, groupMeta: 'Revit model', volatile: true,
|
|
3023
|
+
label: 'Latest approved', triggerLabel: `${project.name} · latest approved (volatile)`,
|
|
3024
|
+
meta: 'changes when approvals change',
|
|
3025
|
+
ariaLabel: `${project.name}, Revit model, latest approved, changes when approvals change`,
|
|
3026
|
+
search: `${project.name} Revit latest approved changes approvals volatile`,
|
|
3027
|
+
}];
|
|
3028
|
+
});
|
|
3029
|
+
const requestedValue = cur[inp.name] != null ? String(cur[inp.name]) : '';
|
|
3030
|
+
const value = options.some((option) => String(option.value) === requestedValue) ? requestedValue : '';
|
|
3031
|
+
return {
|
|
3032
|
+
name: inp.name,
|
|
3033
|
+
label: inp.name + (inp.description ? ` — ${inp.description}` : ''),
|
|
3034
|
+
type: 'select', options, value,
|
|
3035
|
+
required: true,
|
|
3036
|
+
commandId: 'workflow.select-model-revision',
|
|
3037
|
+
placeholder: 'Select an approved model version…',
|
|
3038
|
+
disabledLabel: modelRevisions.error === 'unavailable' ? 'Secure model access unavailable'
|
|
3039
|
+
: modelRevisions.error ? 'Approved models unavailable' : 'Approve a Revit model first',
|
|
3040
|
+
emptyNote: modelRevisions.error === 'unavailable'
|
|
3041
|
+
? 'Secure Revit model access is unavailable in this environment.'
|
|
3042
|
+
: modelRevisions.error
|
|
3043
|
+
? 'Couldn’t load approved Revit models. Reload approved models to try again.'
|
|
3044
|
+
: 'No approved Revit model is available — open <strong>Workspaces</strong>, import a Revit project, and Approve it first.',
|
|
3045
|
+
emptyActionLabel: modelRevisions.error === 'transient' ? 'Reload approved models' : '',
|
|
3046
|
+
onEmptyAction: modelRevisions.error === 'transient' ? () => openInputsDialog() : null,
|
|
3047
|
+
note: !modelRevisions.error && requestedValue && !value
|
|
3048
|
+
? 'That approved revision is no longer available. Choose another revision.' : '',
|
|
3049
|
+
};
|
|
3050
|
+
}
|
|
3427
3051
|
return {
|
|
3428
3052
|
name: inp.name,
|
|
3429
3053
|
label: inp.name + (inp.description ? ` — ${inp.description}` : ''),
|
|
@@ -3432,9 +3056,10 @@
|
|
|
3432
3056
|
};
|
|
3433
3057
|
});
|
|
3434
3058
|
const res = await formModal({ title: `Inputs · ${app.displayName}`, sub: 'Set the values this run uses, then ▶ Run workflow.', fields, okLabel: 'Set inputs' });
|
|
3435
|
-
if (!res) return;
|
|
3059
|
+
if (!res || !isCurrent()) return;
|
|
3436
3060
|
const store = {};
|
|
3437
3061
|
for (const inp of app.inputs) {
|
|
3062
|
+
if (!isCurrent()) return;
|
|
3438
3063
|
if (isVisual(inp)) {
|
|
3439
3064
|
const v = res[inp.name];
|
|
3440
3065
|
if (typeof v === 'string' && v.startsWith('data:')) {
|
|
@@ -3459,7 +3084,8 @@
|
|
|
3459
3084
|
if (inp.type === 'integer' || inp.type === 'number') { const num = Number(v); if (!Number.isNaN(num)) { store[inp.name] = num; continue; } }
|
|
3460
3085
|
store[inp.name] = v;
|
|
3461
3086
|
}
|
|
3462
|
-
|
|
3087
|
+
if (!isCurrent()) return;
|
|
3088
|
+
appInputValues.set(appId, store);
|
|
3463
3089
|
markSpecialNodes();
|
|
3464
3090
|
refreshDirtyIndicator(); // values changed → reflect unsaved state in the header/menu
|
|
3465
3091
|
const badge = Object.entries(store).map(([k, v]) => `${k}=${visualNames.has(k) ? String(v).split(/[\\/]/).pop() : v}`).join(' · ');
|
|
@@ -3648,9 +3274,32 @@
|
|
|
3648
3274
|
// Open the dedicated full-window editor for a node that emits a known contract
|
|
3649
3275
|
// type. Returns true if a renderer exists (so the caller can stop here instead
|
|
3650
3276
|
// of falling through to the report viewer); false → unknown type, caller continues.
|
|
3277
|
+
// A model editor whose tabs live in the left Model section (renderer `modelPanel`) still covers the whole
|
|
3278
|
+
// window, header and footer included, but the left panel stays above it (app.css .contract-editor-beside),
|
|
3279
|
+
// and the section speaks to that editor while it is open — the same tabs, by the same code, as the
|
|
3280
|
+
// workspace's Model step (web/model-panel-bridge.js).
|
|
3281
|
+
let contractEditorApp = null; // the workflow the editor was opened for: Approve bakes that one
|
|
3282
|
+
// The regions of #app the overlay covers. Covering them is not enough: Tab from the left panel would still reach
|
|
3283
|
+
// the header, canvas and footer under it. Cards drawn above the overlay (#fullscreen-nudge, #ix-ask-menu) are not
|
|
3284
|
+
// covered, so they are not listed and stay usable.
|
|
3285
|
+
const OVERLAY_COVERS = '#app > header, #canvas-main, #app > .pane-rail-right, #inspect-panel, #whats-new-panel, #instructor, #app > footer';
|
|
3286
|
+
let shellInertBefore = null; // each covered region, with the inert it had before
|
|
3287
|
+
function overlayModelPanel(on) {
|
|
3288
|
+
document.getElementById('app').classList.toggle('contract-editor-beside', on);
|
|
3289
|
+
if (on && !shellInertBefore) {
|
|
3290
|
+
shellInertBefore = [...document.querySelectorAll(OVERLAY_COVERS)]
|
|
3291
|
+
.map((region) => { const before = region.inert; region.inert = true; return [region, before]; });
|
|
3292
|
+
} else if (!on && shellInertBefore) {
|
|
3293
|
+
for (const [region, before] of shellInertBefore) region.inert = before;
|
|
3294
|
+
shellInertBefore = null;
|
|
3295
|
+
}
|
|
3296
|
+
window.flolessLeftPane?.useOverlayModelFrame(on ? $contractEditorFrame : null);
|
|
3297
|
+
}
|
|
3651
3298
|
function openContractEditor(appId, type) {
|
|
3652
3299
|
const r = window.CONTRACT_RENDERERS && window.CONTRACT_RENDERERS[type];
|
|
3653
3300
|
if (!r) return false;
|
|
3301
|
+
contractEditorApp = appId;
|
|
3302
|
+
overlayModelPanel(!!r.modelPanel);
|
|
3654
3303
|
// The editor bakes the .lock on Approve — that control belongs to an editable contract editor, not
|
|
3655
3304
|
// the filter view (own Save) nor a view-only renderer. Show it unless the renderer is viewOnly.
|
|
3656
3305
|
const ap0 = document.getElementById('contract-editor-approve'); if (ap0) ap0.hidden = !!r.viewOnly;
|
|
@@ -3659,8 +3308,12 @@
|
|
|
3659
3308
|
Object.assign(document.createElement('span'), { textContent: ' · ' + type, style: 'color:var(--text-muted)' }),
|
|
3660
3309
|
);
|
|
3661
3310
|
// Focus the iframe once it loads so its keyboard shortcuts (Ctrl+D, etc.) work without
|
|
3662
|
-
// the user first having to click inside it
|
|
3663
|
-
|
|
3311
|
+
// the user first having to click inside it — but never away from the left panel beside it: the steel
|
|
3312
|
+
// editor reloads itself after every AI edit, often while the person is typing in the chat.
|
|
3313
|
+
$contractEditorFrame.onload = () => {
|
|
3314
|
+
if (document.getElementById('chat-panel')?.contains(document.activeElement)) return;
|
|
3315
|
+
try { $contractEditorFrame.contentWindow.focus(); } catch (_) {}
|
|
3316
|
+
};
|
|
3664
3317
|
$contractEditorFrame.src = r.editorUrl(appId);
|
|
3665
3318
|
$contractEditor.hidden = false;
|
|
3666
3319
|
return true;
|
|
@@ -3670,6 +3323,7 @@
|
|
|
3670
3323
|
function openLocalViewer(appId, type) {
|
|
3671
3324
|
const r = window.CONTRACT_RENDERERS && window.CONTRACT_RENDERERS[type];
|
|
3672
3325
|
if (!r || !r.viewerUrl) return false;
|
|
3326
|
+
overlayModelPanel(false);
|
|
3673
3327
|
const ap = document.getElementById('contract-editor-approve'); if (ap) ap.hidden = true;
|
|
3674
3328
|
$contractEditorTitle.replaceChildren(
|
|
3675
3329
|
Object.assign(document.createElement('span'), { textContent: appId, style: 'color:var(--text);font-weight:600' }),
|
|
@@ -3684,6 +3338,7 @@
|
|
|
3684
3338
|
// steel-filter.html (layer/thickness/colour facets + eyedropper). Same seam as the editor: the
|
|
3685
3339
|
// iframe talks to /api/contract directly and Save writes contract.filter.
|
|
3686
3340
|
function openFilterView(appId) {
|
|
3341
|
+
overlayModelPanel(false);
|
|
3687
3342
|
// The filter view has its own Save; the overlay's "Approve & bake lock" (editor-only) would
|
|
3688
3343
|
// be a confusing no-op here, so hide it. openContractEditor restores it.
|
|
3689
3344
|
const ap = document.getElementById('contract-editor-approve'); if (ap) ap.hidden = true;
|
|
@@ -3710,6 +3365,7 @@
|
|
|
3710
3365
|
else if (choice === 'discard') { try { guard.discard(); } catch (_) {} } // silence the backstop
|
|
3711
3366
|
}
|
|
3712
3367
|
$contractEditor.hidden = true;
|
|
3368
|
+
overlayModelPanel(false); // the left Model section goes back to the workspace
|
|
3713
3369
|
$contractEditorFrame.src = 'about:blank'; // tear down the editor session + its draft listeners
|
|
3714
3370
|
}
|
|
3715
3371
|
document.getElementById('contract-editor-close').onclick = closeContractEditor;
|
|
@@ -3774,9 +3430,9 @@
|
|
|
3774
3430
|
lastReportByApp.set(currentId, { nodeId: res.report.nodeId, label: '3D', html, interactive: true });
|
|
3775
3431
|
$reportModal.dataset.html = '1';
|
|
3776
3432
|
} catch (e) {
|
|
3777
|
-
const
|
|
3778
|
-
$reportOverlay.innerHTML = `<div
|
|
3779
|
-
showToast(
|
|
3433
|
+
const recovery = 'We couldn’t create the 3D view because FloLess could not finish preparing it. Try again.';
|
|
3434
|
+
$reportOverlay.innerHTML = `<div>${escapeHtml(recovery)}</div>`;
|
|
3435
|
+
showToast(recovery, 'warn');
|
|
3780
3436
|
}
|
|
3781
3437
|
}
|
|
3782
3438
|
|
|
@@ -3851,7 +3507,7 @@
|
|
|
3851
3507
|
// A receipt describes the attempt the user just made. Keeping the prior session receipt here
|
|
3852
3508
|
// would make a failed re-export look successful, even though the durable file stays untouched.
|
|
3853
3509
|
exportReceiptsByApp.delete(exportReceiptKey(appId, 'ifc'));
|
|
3854
|
-
showToast('
|
|
3510
|
+
showToast('We couldn’t export the IFC file because FloLess could not finish preparing it. Try again.', 'warn');
|
|
3855
3511
|
} finally {
|
|
3856
3512
|
setExportActionBusy(appId, 'ifc', false);
|
|
3857
3513
|
}
|
|
@@ -3879,7 +3535,7 @@
|
|
|
3879
3535
|
setTimeout(() => URL.revokeObjectURL(url), 4000);
|
|
3880
3536
|
showToast(`BOM ${label} saved & downloaded — ${res.filename || appId + '-bom.' + format}`, 'ok');
|
|
3881
3537
|
} catch (e) {
|
|
3882
|
-
showToast(`
|
|
3538
|
+
showToast(`We couldn’t export the ${label} BOM because FloLess could not finish preparing it. Try again.`, 'warn');
|
|
3883
3539
|
}
|
|
3884
3540
|
}
|
|
3885
3541
|
|
|
@@ -4067,7 +3723,7 @@
|
|
|
4067
3723
|
const summary = exportReceiptText(appId, 'tekla');
|
|
4068
3724
|
const omissionText = hostBakeSuccessText(res, 'Tekla');
|
|
4069
3725
|
const partial = !!(res.reviewCounts && res.reviewCounts.omitted) || !!(summary && summary.partial);
|
|
4070
|
-
showToast(partial ? omissionText :
|
|
3726
|
+
showToast(partial ? omissionText : 'Your workflow was added to the Tekla model.', partial ? 'warn' : 'ok');
|
|
4071
3727
|
} catch (e) {
|
|
4072
3728
|
// Do not leave counts from an earlier successful send attached to this failed attempt.
|
|
4073
3729
|
exportReceiptsByApp.delete(exportReceiptKey(appId, 'tekla'));
|
|
@@ -4083,7 +3739,7 @@
|
|
|
4083
3739
|
? 'FloLess lost the Tekla response after dispatch. Check the open model before sending again.'
|
|
4084
3740
|
: reviewLost
|
|
4085
3741
|
? 'FloLess couldn’t finish reviewing the Tekla send. Nothing was sent; try the review again.'
|
|
4086
|
-
:
|
|
3742
|
+
: 'We couldn’t send this to Tekla because FloLess could not finish the request. Check that Tekla is open, then try again.', needsTekla ? 'info' : 'warn');
|
|
4087
3743
|
} finally {
|
|
4088
3744
|
setExportActionBusy(appId, 'tekla', false);
|
|
4089
3745
|
}
|
|
@@ -4194,7 +3850,7 @@
|
|
|
4194
3850
|
// latest in-memory edits, not a stale snapshot. api() throws on non-2xx, so
|
|
4195
3851
|
// any flush or bake failure surfaces through the catch as a warn toast.
|
|
4196
3852
|
document.getElementById('contract-editor-approve').onclick = async () => {
|
|
4197
|
-
const appId = currentId
|
|
3853
|
+
const appId = contractEditorApp; // not currentId: the left panel beside a model editor stays usable
|
|
4198
3854
|
if (!appId) return;
|
|
4199
3855
|
const btn = document.getElementById('contract-editor-approve');
|
|
4200
3856
|
const prev = btn.textContent;
|
|
@@ -4207,7 +3863,7 @@
|
|
|
4207
3863
|
await api(`/api/contract/${encodeURIComponent(appId)}/approve`, { method: 'POST' });
|
|
4208
3864
|
showToast('Approved — lock baked. Run is armed.', 'ok');
|
|
4209
3865
|
} catch (e) {
|
|
4210
|
-
showToast(
|
|
3866
|
+
showToast('We couldn’t approve this workflow because FloLess could not save the approval. Try again.', 'warn');
|
|
4211
3867
|
} finally {
|
|
4212
3868
|
btn.disabled = false; btn.textContent = prev;
|
|
4213
3869
|
}
|
|
@@ -4229,7 +3885,7 @@
|
|
|
4229
3885
|
const inputs = currentInputs();
|
|
4230
3886
|
const inputBadge = Object.entries(inputs).map(([k, v]) => `${k}=${v}`).join(' · ');
|
|
4231
3887
|
$reportTitle.textContent = `HTML Viewer · ${app.displayName}`;
|
|
4232
|
-
$reportSub.
|
|
3888
|
+
$reportSub.textContent = 'Running the workflow to create your report.';
|
|
4233
3889
|
clearReportFrames(); // clear any previous report (static or 3D) before this run paints a fresh one
|
|
4234
3890
|
$reportShare.hidden = true; // the frame is blank — only a painted report is shareable
|
|
4235
3891
|
$reportOverlay.hidden = false;
|
|
@@ -4261,6 +3917,7 @@
|
|
|
4261
3917
|
$reportSub.innerHTML = `Live 3D view from <code>${escapeHtml(nodeId)}</code>${inputBadge ? ' · ' + escapeHtml(inputBadge) : ''} — drag to orbit, scroll to zoom, click an element to inspect.`;
|
|
4262
3918
|
}
|
|
4263
3919
|
paintReport(html, interactive);
|
|
3920
|
+
if (!interactive) $reportSub.textContent = 'Report created from the latest workflow run.';
|
|
4264
3921
|
// If a node wrote an output file, the run reports its path — surface the
|
|
4265
3922
|
// ⧉ Open file / ▤ Reveal buttons and cache it so a later double-click restores them (#209).
|
|
4266
3923
|
const savedPath = res && typeof res.savedPath === 'string' ? res.savedPath : '';
|
|
@@ -4287,8 +3944,9 @@
|
|
|
4287
3944
|
// Other recoverable failures (host not attached, stale lock, …): show it
|
|
4288
3945
|
// in the viewer overlay + a toast. No console.error — the server returns the
|
|
4289
3946
|
// failure in-band, so a failed run isn't a console-worthy fault.
|
|
4290
|
-
$reportOverlay.innerHTML = `<div
|
|
4291
|
-
|
|
3947
|
+
$reportOverlay.innerHTML = `<div>${escapeHtml(runFailureMessage(msg))}</div>`;
|
|
3948
|
+
$reportSub.textContent = 'The report could not be created.';
|
|
3949
|
+
showToast(runFailureMessage(msg), 'warn');
|
|
4292
3950
|
}
|
|
4293
3951
|
}
|
|
4294
3952
|
} finally {
|
|
@@ -4672,31 +4330,38 @@
|
|
|
4672
4330
|
// list here (approved projects, unbounded) crosses the threshold on its own.
|
|
4673
4331
|
const searchable = opts.length > SELECT_SEARCH_MIN;
|
|
4674
4332
|
const trigLabel = disabled ? (f.disabledLabel || 'None available')
|
|
4675
|
-
: sel ? sel.label + (sel.meta ? ` (${sel.meta})` : '') : (f.placeholder || 'Select…');
|
|
4333
|
+
: sel ? (sel.triggerLabel || (sel.label + (sel.meta ? ` (${sel.meta})` : ''))) : (f.placeholder || 'Select…');
|
|
4676
4334
|
// Command IDs are literal registry identities. Only the selected runtime is dynamic;
|
|
4677
4335
|
// never interpolate an arbitrary form field into the Instructor trust boundary.
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4336
|
+
let commandCarrier = '';
|
|
4337
|
+
if (f.commandId === 'shell.instructor-ask-runtime') commandCarrier = ' data-command-id="shell.instructor-ask-runtime"';
|
|
4338
|
+
else if (f.commandId === 'shell.requests-runtime') commandCarrier = ' data-command-id="shell.requests-runtime"';
|
|
4339
|
+
else if (f.commandId === 'shell.new-workflow-location') commandCarrier = ' data-command-id="shell.new-workflow-location"';
|
|
4340
|
+
else if (f.commandId === 'workflow.select-model-revision') commandCarrier = ' data-command-id="workflow.select-model-revision"';
|
|
4341
|
+
let optionIndex = 0;
|
|
4342
|
+
const optionRow = (o) => `<div id="${id}-option-${optionIndex++}" class="wf-option${isOn(o) ? ' selected' : ''}${o.volatile ? ' volatile' : ''}" role="option" data-id="${escapeAttr(String(o.value))}" data-trigger-label="${escapeAttr(o.triggerLabel || '')}"${commandCarrier}${commandCarrier ? ` data-command-instance="${escapeAttr(String(o.value))}" data-command-instance-label="${escapeAttr(String(o.label))}"` : ''} data-search="${escapeAttr(String(o.search || o.label).toLowerCase())}" tabindex="-1" aria-label="${escapeAttr(o.ariaLabel || o.label)}" aria-selected="${isOn(o) ? 'true' : 'false'}"><span class="wf-option-name">${escapeHtml(o.label)}</span>${o.meta ? `<span class="wf-option-meta">${escapeHtml(o.meta)}</span>` : ''}</div>`;
|
|
4343
|
+
const grouped = opts.some((o) => o.group);
|
|
4344
|
+
const rows = grouped
|
|
4345
|
+
? [...new Set(opts.map((o) => o.group || 'Other'))].map((group, groupIndex) => { const members = opts.filter((o) => (o.group || 'Other') === group); const meta = members.find((o) => o.groupMeta)?.groupMeta; return `<div class="wf-group" role="group" aria-labelledby="${id}-group-${groupIndex}"><div class="wf-group-header" id="${id}-group-${groupIndex}">${escapeHtml(group)}${meta ? `<span>${escapeHtml(meta)}</span>` : ''}</div>${members.map(optionRow).join('')}</div>`; }).join('')
|
|
4346
|
+
: opts.map(optionRow).join('');
|
|
4685
4347
|
ctl = `<div class="wf-combo fm-select">
|
|
4686
4348
|
<input type="hidden" data-fm="${escapeHtml(f.name)}" value="${escapeAttr(val)}">
|
|
4687
|
-
<button type="button" class="wf-trigger fm-select-trigger"${commandCarrier}${commandCarrier && sel ? ` data-command-instance="${escapeAttr(String(sel.value))}"` : ''} aria-haspopup="listbox" aria-expanded="false"${disabled ? ' disabled' : ''}>
|
|
4349
|
+
<button type="button" class="wf-trigger fm-select-trigger"${commandCarrier}${commandCarrier && sel ? ` data-command-instance="${escapeAttr(String(sel.value))}" data-command-instance-label="${escapeAttr(String(sel.label))}"` : ''}${sel && sel.ariaLabel ? ` data-tip="${escapeAttr(sel.ariaLabel)}"` : ''} aria-haspopup="listbox" aria-controls="${id}-listbox" aria-expanded="false"${disabled ? ' disabled' : ''}>
|
|
4688
4350
|
<span class="wf-trigger-label fm-select-label"${sel ? '' : ' data-empty="1"'}>${escapeHtml(trigLabel)}</span>
|
|
4689
4351
|
<svg class="wf-caret" width="10" height="6" viewBox="0 0 10 6" aria-hidden="true"><path fill="currentColor" d="M0 0l5 6 5-6z"/></svg>
|
|
4690
4352
|
</button>
|
|
4691
|
-
<div class="wf-popover fm-select-popover" role="listbox" aria-label="${escapeAttr(f.label || f.name)}" hidden>
|
|
4692
|
-
${searchable ? '<div class="wf-search-wrap"><input class="wf-search fm-select-search" type="text" placeholder="Search…" autocomplete="off" aria-label="Search"></div>' : ''}
|
|
4353
|
+
<div id="${id}-listbox" class="wf-popover fm-select-popover" role="listbox" aria-label="${escapeAttr(f.label || f.name)}" hidden>
|
|
4354
|
+
${searchable ? '<div class="wf-search-wrap"><input class="wf-search fm-select-search" type="text" placeholder="Search projects or approved versions…" autocomplete="off" aria-label="Search projects or approved versions"></div>' : ''}
|
|
4693
4355
|
<div class="wf-list fm-select-list">${rows}${searchable ? '<div class="wf-empty-search" hidden>No matches</div>' : ''}</div>
|
|
4694
|
-
</div>${disabled && f.emptyNote ? `<div class="fm-select-note">${f.emptyNote}</div>` : ''}
|
|
4356
|
+
</div>${disabled && f.emptyNote ? `<div class="fm-select-note" role="status">${f.emptyNote}${f.emptyActionLabel ? `<div class="fm-select-actions"><button type="button" class="fm-select-reload" data-command-id="workflow.reload-model-revisions" data-fm-empty-action="${escapeAttr(f.name)}">${escapeHtml(f.emptyActionLabel)}</button></div>` : ''}</div>` : ''}${f.note ? `<div class="fm-select-note" role="status">${escapeHtml(f.note)}</div>` : ''}
|
|
4695
4357
|
</div>`;
|
|
4696
4358
|
} else {
|
|
4359
|
+
const fieldCommand = f.commandId === 'shell.new-workflow-name'
|
|
4360
|
+
? ' data-command-id="shell.new-workflow-name"'
|
|
4361
|
+
: '';
|
|
4697
4362
|
ctl = f.multiline
|
|
4698
|
-
? `<textarea id="${id}" rows="4" data-fm="${escapeHtml(f.name)}" placeholder="${ph}">${escapeHtml(val)}</textarea>`
|
|
4699
|
-
: `<input id="${id}" type="${f.type || 'text'}"${f.type === 'number' ? ' step="1"' : ''} data-fm="${escapeHtml(f.name)}" value="${escapeHtml(val)}" placeholder="${ph}">`;
|
|
4363
|
+
? `<textarea id="${id}" rows="4" data-fm="${escapeHtml(f.name)}" placeholder="${ph}"${fieldCommand}>${escapeHtml(val)}</textarea>`
|
|
4364
|
+
: `<input id="${id}" type="${f.type || 'text'}"${f.type === 'number' ? ' step="1"' : ''} data-fm="${escapeHtml(f.name)}" value="${escapeHtml(val)}" placeholder="${ph}"${fieldCommand}>`;
|
|
4700
4365
|
}
|
|
4701
4366
|
return `<div class="modal-field"><label for="${id}">${escapeHtml(f.label || f.name)}</label>${ctl}</div>`;
|
|
4702
4367
|
}).join('');
|
|
@@ -4730,27 +4395,6 @@
|
|
|
4730
4395
|
modal.setAttribute('aria-hidden', 'true');
|
|
4731
4396
|
});
|
|
4732
4397
|
showModal($formModal);
|
|
4733
|
-
// Prefer a real text input; else a select's trigger; else a file drop zone (so keyboard
|
|
4734
|
-
// users land somewhere actionable rather than a possibly-disabled OK button).
|
|
4735
|
-
//
|
|
4736
|
-
// `[type="hidden"]` must be excluded, and it is not theoretical: a `type: 'select'` field
|
|
4737
|
-
// renders its value carrier as a hidden input FIRST inside the control, so a dialog whose
|
|
4738
|
-
// fields are all selects matched that, `.focus()` did nothing, and the `$ok.focus()` fallback
|
|
4739
|
-
// was skipped because `first` was truthy. Focus then stayed on the button behind the
|
|
4740
|
-
// backdrop — and since the Esc/Tab handler is bound to $formModal, the dialog could not be
|
|
4741
|
-
// dismissed with Escape and the focus trap never engaged. The render options dialog is the
|
|
4742
|
-
// first all-select caller, so it hit this every single time.
|
|
4743
|
-
// `.wf-search` must be excluded too: a select renders a search box inside its POPOVER, which
|
|
4744
|
-
// is `hidden` until the trigger is opened. It is a visible-typed text input, so excluding
|
|
4745
|
-
// only `[type=hidden]` still selected it — and focusing an input inside a hidden container
|
|
4746
|
-
// is exactly as much of a no-op as focusing the hidden one. Caught by driving the dialog,
|
|
4747
|
-
// not by reading it: the DOM says both are inputs.
|
|
4748
|
-
const first = $body.querySelector('input:not(.fm-file-input):not([type="hidden"]):not(.wf-search),textarea')
|
|
4749
|
-
|| $body.querySelector('.fm-select-trigger:not([disabled])')
|
|
4750
|
-
|| $body.querySelector('.fm-files .fm-drop, .fm-file .fm-drop, .fm-images .fm-drop');
|
|
4751
|
-
if (first) { first.focus(); if (first.select) first.select(); }
|
|
4752
|
-
else if ((danger || safeDefault) && !hideCancel) $cancel.focus();
|
|
4753
|
-
else $ok.focus();
|
|
4754
4398
|
// OK-gate probes: required consent checks (below) AND required multi-file fields must be
|
|
4755
4399
|
// satisfied. Declared here so the fm-files setup can re-run the gate; wired after all setups.
|
|
4756
4400
|
let runGate = () => {};
|
|
@@ -5011,11 +4655,15 @@
|
|
|
5011
4655
|
let hi = -1;
|
|
5012
4656
|
const opts = () => [...list.querySelectorAll('.wf-option')];
|
|
5013
4657
|
const visible = () => opts().filter((o) => !o.hidden);
|
|
5014
|
-
const
|
|
4658
|
+
const syncActive = (option) => {
|
|
4659
|
+
[trigger, search].filter(Boolean).forEach((carrier) => option ? carrier.setAttribute('aria-activedescendant', option.id) : carrier.removeAttribute('aria-activedescendant'));
|
|
4660
|
+
};
|
|
4661
|
+
const clearHi = () => { list.querySelectorAll('.wf-option.highlighted').forEach((o) => o.classList.remove('highlighted')); hi = -1; syncActive(null); };
|
|
5015
4662
|
const filter = (q) => {
|
|
5016
4663
|
q = (q || '').toLowerCase().trim();
|
|
5017
4664
|
let any = false;
|
|
5018
4665
|
opts().forEach((o) => { const m = !q || o.dataset.search.includes(q); o.hidden = !m; if (m) any = true; });
|
|
4666
|
+
list.querySelectorAll('.wf-group').forEach((group) => { group.hidden = !group.querySelector('.wf-option:not([hidden])'); });
|
|
5019
4667
|
const empty = list.querySelector('.wf-empty-search'); if (empty) empty.hidden = any;
|
|
5020
4668
|
clearHi();
|
|
5021
4669
|
};
|
|
@@ -5023,18 +4671,31 @@
|
|
|
5023
4671
|
const vis = visible(); if (!vis.length) return;
|
|
5024
4672
|
hi = hi < 0 ? (d > 0 ? 0 : vis.length - 1) : Math.max(0, Math.min(vis.length - 1, hi + d));
|
|
5025
4673
|
vis.forEach((o, i) => o.classList.toggle('highlighted', i === hi));
|
|
4674
|
+
syncActive(vis[hi]);
|
|
5026
4675
|
vis[hi].scrollIntoView({ block: 'nearest' });
|
|
5027
4676
|
};
|
|
5028
|
-
const open = () => {
|
|
4677
|
+
const open = () => {
|
|
4678
|
+
popover.hidden = false; trigger.classList.add('open'); trigger.setAttribute('aria-expanded', 'true');
|
|
4679
|
+
if (search) { search.value = ''; filter(''); setTimeout(() => search.focus(), 0); }
|
|
4680
|
+
const vis = visible(); const selected = vis.findIndex((option) => option.classList.contains('selected'));
|
|
4681
|
+
hi = selected >= 0 ? selected : (vis.length ? 0 : -1);
|
|
4682
|
+
vis.forEach((option, index) => option.classList.toggle('highlighted', index === hi));
|
|
4683
|
+
if (hi >= 0) { syncActive(vis[hi]); vis[hi].scrollIntoView({ block: 'nearest' }); }
|
|
4684
|
+
};
|
|
5029
4685
|
const close = (focusTrig) => { popover.hidden = true; trigger.classList.remove('open'); trigger.setAttribute('aria-expanded', 'false'); clearHi(); if (focusTrig) trigger.focus(); };
|
|
5030
4686
|
const nameOf = (o) => { const n = o.querySelector('.wf-option-name'); return n ? n.textContent : o.dataset.id; };
|
|
5031
4687
|
const choose = (opt) => {
|
|
5032
4688
|
if (hidden) hidden.value = opt.dataset.id;
|
|
5033
|
-
if (trigger.dataset.commandId)
|
|
4689
|
+
if (trigger.dataset.commandId) {
|
|
4690
|
+
trigger.dataset.commandInstance = opt.dataset.id;
|
|
4691
|
+
trigger.dataset.commandInstanceLabel = nameOf(opt);
|
|
4692
|
+
}
|
|
5034
4693
|
opts().forEach((o) => { const s = o === opt; o.classList.toggle('selected', s); o.setAttribute('aria-selected', s ? 'true' : 'false'); });
|
|
5035
4694
|
const mt = opt.querySelector('.wf-option-meta');
|
|
5036
|
-
if (label) { label.textContent = nameOf(opt) + (mt ? ` (${mt.textContent})` : ''); label.removeAttribute('data-empty'); }
|
|
4695
|
+
if (label) { label.textContent = opt.dataset.triggerLabel || (nameOf(opt) + (mt ? ` (${mt.textContent})` : '')); label.removeAttribute('data-empty'); }
|
|
4696
|
+
const aria = opt.getAttribute('aria-label'); if (aria) trigger.setAttribute('data-tip', aria);
|
|
5037
4697
|
fireChange();
|
|
4698
|
+
runGate();
|
|
5038
4699
|
close(true);
|
|
5039
4700
|
};
|
|
5040
4701
|
// Close any OTHER expanded combo. These popovers expand in-line rather than overlaying, so
|
|
@@ -5065,6 +4726,8 @@
|
|
|
5065
4726
|
if (popover.hidden) return;
|
|
5066
4727
|
if (e.key === 'ArrowDown') { e.preventDefault(); e.stopPropagation(); move(1); }
|
|
5067
4728
|
else if (e.key === 'ArrowUp') { e.preventDefault(); e.stopPropagation(); move(-1); }
|
|
4729
|
+
else if (e.key === 'Home') { e.preventDefault(); e.stopPropagation(); hi = -1; move(1); }
|
|
4730
|
+
else if (e.key === 'End') { e.preventDefault(); e.stopPropagation(); hi = -1; move(-1); }
|
|
5068
4731
|
else if (e.key === 'Enter') { e.preventDefault(); e.stopPropagation(); const vis = visible(); if (hi >= 0 && vis[hi]) choose(vis[hi]); }
|
|
5069
4732
|
else if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); close(true); }
|
|
5070
4733
|
});
|
|
@@ -5130,17 +4793,35 @@
|
|
|
5130
4793
|
const f = fields.find((x) => x.name === el.dataset.fmCheck);
|
|
5131
4794
|
return f && f.required;
|
|
5132
4795
|
});
|
|
4796
|
+
const requiredValues = Array.from($body.querySelectorAll('[data-fm]')).filter((el) => {
|
|
4797
|
+
const f = fields.find((x) => x.name === el.dataset.fm);
|
|
4798
|
+
return f && f.required;
|
|
4799
|
+
});
|
|
5133
4800
|
// Unified OK gate: every required consent check ticked AND every required multi-file field
|
|
5134
4801
|
// has ≥1 ready file. (runGate was declared up top so fm-files callbacks can re-run it.)
|
|
5135
|
-
if (requiredChecks.length || fileGateProbes.length) {
|
|
4802
|
+
if (requiredChecks.length || requiredValues.length || fileGateProbes.length) {
|
|
5136
4803
|
runGate = () => {
|
|
5137
4804
|
const checksOk = !requiredChecks.some((el) => !el.checked);
|
|
4805
|
+
const valuesOk = !requiredValues.some((el) => !String(el.value || '').trim());
|
|
5138
4806
|
const filesOk = !fileGateProbes.some((getN) => getN() < 1);
|
|
5139
|
-
$ok.disabled = !(checksOk && filesOk);
|
|
4807
|
+
$ok.disabled = !(checksOk && valuesOk && filesOk);
|
|
5140
4808
|
};
|
|
5141
4809
|
requiredChecks.forEach((el) => { el.onchange = runGate; });
|
|
4810
|
+
requiredValues.forEach((el) => { el.addEventListener('input', runGate); });
|
|
5142
4811
|
runGate();
|
|
5143
4812
|
}
|
|
4813
|
+
// Prefer a real text input; else an enabled picker, file drop, or empty-state action. Hidden
|
|
4814
|
+
// select carriers and popover-only search inputs are excluded because focusing either is a
|
|
4815
|
+
// no-op. Gate first, then put focus on an enabled action. In an empty required picker, gating disables
|
|
4816
|
+
// OK; focusing it before this point made Chromium drop focus outside the modal and bypass the
|
|
4817
|
+
// Escape/Tab trap. The themed Reload action is the useful first stop when one is available.
|
|
4818
|
+
const first = $body.querySelector('input:not(.fm-file-input):not([type="hidden"]):not(.wf-search),textarea')
|
|
4819
|
+
|| $body.querySelector('.fm-select-trigger:not([disabled])')
|
|
4820
|
+
|| $body.querySelector('.fm-files .fm-drop, .fm-file .fm-drop, .fm-images .fm-drop')
|
|
4821
|
+
|| $body.querySelector('[data-fm-empty-action]:not([disabled])');
|
|
4822
|
+
if (first) { first.focus(); if (first.select) first.select(); }
|
|
4823
|
+
else if ((danger || $ok.disabled) && !hideCancel) $cancel.focus();
|
|
4824
|
+
else $ok.focus();
|
|
5144
4825
|
const collect = () => {
|
|
5145
4826
|
const out = {};
|
|
5146
4827
|
$body.querySelectorAll('[data-fm]').forEach((el) => { out[el.dataset.fm] = el.value; });
|
|
@@ -5191,6 +4872,13 @@
|
|
|
5191
4872
|
if (focusTarget instanceof HTMLElement && focusTarget.isConnected && !focusTarget.matches(':disabled,[aria-disabled="true"]')) focusTarget.focus();
|
|
5192
4873
|
resolve(result);
|
|
5193
4874
|
};
|
|
4875
|
+
$body.querySelectorAll('[data-fm-empty-action]').forEach((button) => {
|
|
4876
|
+
button.onclick = () => {
|
|
4877
|
+
const field = fields.find((candidate) => candidate.name === button.dataset.fmEmptyAction);
|
|
4878
|
+
done(null);
|
|
4879
|
+
if (field && typeof field.onEmptyAction === 'function') queueMicrotask(() => field.onEmptyAction());
|
|
4880
|
+
};
|
|
4881
|
+
});
|
|
5194
4882
|
$ok.onclick = () => done(collect());
|
|
5195
4883
|
$cancel.onclick = () => done(null);
|
|
5196
4884
|
onBackdropDismiss($formModal, () => done(null));
|
|
@@ -5399,9 +5087,9 @@
|
|
|
5399
5087
|
await loadApp(id);
|
|
5400
5088
|
const app = apps.get(id);
|
|
5401
5089
|
appendNarration(app.runnable
|
|
5402
|
-
?
|
|
5403
|
-
: `Compiled, but ${app.notes.length}
|
|
5404
|
-
showToast('
|
|
5090
|
+
? 'Workflow compiled. Review any notices above the canvas before running.'
|
|
5091
|
+
: `Compiled, but ${app.notes.length} notice(s) remain — review them above the canvas.`);
|
|
5092
|
+
showToast('Workflow compiled', 'ok');
|
|
5405
5093
|
} catch (e) {
|
|
5406
5094
|
$compileBtn.textContent = prev;
|
|
5407
5095
|
$compileBtn.disabled = false;
|
|
@@ -5458,8 +5146,7 @@
|
|
|
5458
5146
|
} catch (e) {
|
|
5459
5147
|
hideModal($bakeModal);
|
|
5460
5148
|
// The server restores the original install on failure (recoverable) → warn, not err.
|
|
5461
|
-
|
|
5462
|
-
showToast(`Bake failed: ${msg}`, 'warn');
|
|
5149
|
+
showToast('We couldn’t save this as an agent because FloLess could not finish the setup. Try again.', 'warn');
|
|
5463
5150
|
}
|
|
5464
5151
|
}
|
|
5465
5152
|
|
|
@@ -5680,7 +5367,7 @@
|
|
|
5680
5367
|
} else {
|
|
5681
5368
|
graftFooter({ backShown: true, primaryLabel: 'Create agent', primaryDisabled: false });
|
|
5682
5369
|
graftState.onPrimary = () => runGraftCommit(false);
|
|
5683
|
-
showToast(
|
|
5370
|
+
showToast('We couldn’t create this agent because FloLess could not finish the setup. Try again.', 'warn');
|
|
5684
5371
|
}
|
|
5685
5372
|
}
|
|
5686
5373
|
}
|
|
@@ -6018,7 +5705,6 @@
|
|
|
6018
5705
|
showToast(`Imported "${id}" — Compile to run`, 'ok');
|
|
6019
5706
|
} catch (e) {
|
|
6020
5707
|
const body = e && e.body;
|
|
6021
|
-
const msg = (body && body.error) || (e && e.message) || 'Import failed';
|
|
6022
5708
|
const reason = body && typeof body.reason === 'string' ? body.reason.trim() : '';
|
|
6023
5709
|
// Only an install refusal carries AWARE's output. A bad file or a name clash is a one-line
|
|
6024
5710
|
// problem the toast already states well — a dialog there would be ceremony.
|
|
@@ -6028,7 +5714,9 @@
|
|
|
6028
5714
|
openImportFailedModal(reason, Array.isArray(body.agentsUnavailable) ? body.agentsUnavailable : [], file);
|
|
6029
5715
|
return;
|
|
6030
5716
|
}
|
|
6031
|
-
showToast(
|
|
5717
|
+
showToast(body && body.code === 'exists'
|
|
5718
|
+
? 'A workflow with that name already exists. Choose a different name, then try again.'
|
|
5719
|
+
: 'We couldn’t import that workflow because FloLess could not read it. Check the file, then try again.', 'err');
|
|
6032
5720
|
}
|
|
6033
5721
|
} finally {
|
|
6034
5722
|
_importing = false; // every path, including an unreadable file and the dialog's early return
|
|
@@ -6494,7 +6182,7 @@
|
|
|
6494
6182
|
$appUpdate.disabled = false;
|
|
6495
6183
|
_updateApplying = null;
|
|
6496
6184
|
try { localStorage.removeItem('floless.whatsNew.pending'); } catch { /* private mode */ }
|
|
6497
|
-
showToast('
|
|
6185
|
+
showToast('We couldn’t update this workflow because FloLess could not save the change. Try again.', 'warn');
|
|
6498
6186
|
refreshUpdate();
|
|
6499
6187
|
}
|
|
6500
6188
|
}
|
|
@@ -6601,7 +6289,7 @@
|
|
|
6601
6289
|
await refreshWorkflowUpdates();
|
|
6602
6290
|
if (currentId === u.id) await loadApp(currentId); // reload to show the new structure
|
|
6603
6291
|
} catch (e) {
|
|
6604
|
-
showToast('
|
|
6292
|
+
showToast('We couldn’t update this workflow because FloLess could not save the change. Try again.', 'warn');
|
|
6605
6293
|
} finally {
|
|
6606
6294
|
_wfUpdateApplying = false;
|
|
6607
6295
|
if ($ok) { $ok.disabled = false; $ok.textContent = prev; }
|
|
@@ -7557,7 +7245,6 @@
|
|
|
7557
7245
|
: `Run complete · ${steps} node${steps === 1 ? '' : 's'} against the live model · see the <strong>Execution</strong> tab.`);
|
|
7558
7246
|
if (!simulate) markFirstRunDone(app.id); // a real run completed → calm the beacon (app captured pre-await)
|
|
7559
7247
|
} catch (e) {
|
|
7560
|
-
const msg = (e && e.message) ? e.message : String(e);
|
|
7561
7248
|
if (cancelRequested) {
|
|
7562
7249
|
clearNodeStatus();
|
|
7563
7250
|
showToast('Run cancelled', 'info');
|
|
@@ -7570,10 +7257,10 @@
|
|
|
7570
7257
|
} else {
|
|
7571
7258
|
// A failed run is an expected, recoverable outcome (the server returns it
|
|
7572
7259
|
// in-band) — surface it as a toast + narration, not a console error.
|
|
7573
|
-
showToast((simulate ? 'Simulate failed' : 'Run failed') + ': ' + msg, 'warn');
|
|
7260
|
+
showToast((simulate ? 'Simulate failed' : 'Run failed') + ': ' + runFailureMessage(msg), 'warn');
|
|
7574
7261
|
appendNarration(simulate
|
|
7575
7262
|
? `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.`
|
|
7576
|
-
: `Run failed: ${escapeHtml(msg)}
|
|
7263
|
+
: `Run failed: ${escapeHtml(runFailureMessage(msg))}`);
|
|
7577
7264
|
}
|
|
7578
7265
|
}
|
|
7579
7266
|
} finally {
|
|
@@ -7775,7 +7462,7 @@
|
|
|
7775
7462
|
// have is the exact bug this reason exists to prevent.
|
|
7776
7463
|
return "Couldn't check whether Node.js is installed — the check didn't finish, which usually means the machine was busy. Nothing is necessarily missing; try again.";
|
|
7777
7464
|
case 'aware-version-required':
|
|
7778
|
-
return 'This FloLess release needs AWARE 0.
|
|
7465
|
+
return 'This FloLess release needs AWARE 0.139.0 or newer. Update AWARE, then try again.';
|
|
7779
7466
|
case 'offline':
|
|
7780
7467
|
return 'No network connection was detected. Connect to the internet, then try again.';
|
|
7781
7468
|
case 'smoke-failed':
|
|
@@ -8154,9 +7841,30 @@
|
|
|
8154
7841
|
|
|
8155
7842
|
// Re-check the subscription after a seat-takeover and gate this session if it
|
|
8156
7843
|
// lost access. Re-uses the bootstrap gate panel.
|
|
8157
|
-
|
|
7844
|
+
function routeLicenseStatus(status) {
|
|
7845
|
+
const licensed = status && (status.state === 'valid' || status.state === 'offline-grace');
|
|
7846
|
+
// An account choice is needed only for xeoRVT. It must never block core
|
|
7847
|
+
// FloLess while the optional module service is unavailable.
|
|
7848
|
+
const accountGate = document.getElementById('account-gate');
|
|
7849
|
+
if (accountGate && licensed && status.desktopAccess?.state !== 'account-selection-required') {
|
|
7850
|
+
accountGate.remove();
|
|
7851
|
+
document.getElementById('app')?.removeAttribute('inert');
|
|
7852
|
+
}
|
|
7853
|
+
if (!licensed) {
|
|
7854
|
+
renderGate(status || { state: 'unlicensed' });
|
|
7855
|
+
return false;
|
|
7856
|
+
}
|
|
7857
|
+
return true;
|
|
7858
|
+
}
|
|
7859
|
+
|
|
7860
|
+
async function recheckLicenseAndGate({ forRevitAccountSelection = false } = {}) {
|
|
8158
7861
|
let s; try { s = await api('/api/license/status'); } catch { return; }
|
|
8159
|
-
if (s
|
|
7862
|
+
if (!routeLicenseStatus(s)) return;
|
|
7863
|
+
// Account choice controls only the optional xeoRVT module. Ask only after an
|
|
7864
|
+
// explicit Revit action; ordinary license polling must never interrupt FloLess.
|
|
7865
|
+
if (forRevitAccountSelection && s.desktopAccess?.state === 'account-selection-required') {
|
|
7866
|
+
renderAccountGate(s.desktopAccess.accounts, { moduleOnly: true });
|
|
7867
|
+
}
|
|
8160
7868
|
}
|
|
8161
7869
|
|
|
8162
7870
|
function connectSse() {
|
|
@@ -8229,6 +7937,11 @@
|
|
|
8229
7937
|
if (typeof m.appId !== 'string' || m.appId === currentId) {
|
|
8230
7938
|
refreshCurrentWorkflowAvailability().catch(reportErr);
|
|
8231
7939
|
}
|
|
7940
|
+
} else if (m.type === 'workspace-root-changed') {
|
|
7941
|
+
// Root identity/path belongs to the server's protected registry. Re-read it so every open tab
|
|
7942
|
+
// updates the landing scope label and unavailable state; projects-changed, sent beside this
|
|
7943
|
+
// event, independently reconciles any project that was open.
|
|
7944
|
+
if (window.flolessWorkspaceRoot) window.flolessWorkspaceRoot.refresh();
|
|
8232
7945
|
} else if (m.type === 'display-units-changed') {
|
|
8233
7946
|
/*
|
|
8234
7947
|
* A PROJECT'S DISPLAY UNITS CHANGED — here, in another tab, or from the terminal AI.
|
|
@@ -8290,20 +8003,22 @@
|
|
|
8290
8003
|
// under Installed; update: the new version replaces the old → its Update button
|
|
8291
8004
|
// disappears). On failure restore the card + surface why.
|
|
8292
8005
|
const isUpdate = m.action === 'update';
|
|
8293
|
-
|
|
8006
|
+
recordAgentInstallResult(m);
|
|
8007
|
+
refreshAgentNotes();
|
|
8294
8008
|
if (m.ok) {
|
|
8295
8009
|
if (isUpdate) agentUpdateFailures.delete(m.id);
|
|
8296
8010
|
if (isUpdate) {
|
|
8297
8011
|
showToast(`Updated “${m.id}”`, 'ok');
|
|
8298
8012
|
} else {
|
|
8299
8013
|
const a = availableCatalog.find((x) => x.id === m.id);
|
|
8300
|
-
showToast(`Installed “${a && a.display_name ? a.display_name : m.id}
|
|
8014
|
+
showToast(`Installed “${a && a.display_name ? a.display_name : m.id}”`, 'ok');
|
|
8301
8015
|
}
|
|
8302
8016
|
// `isUpdate` as well as the id. Without it, an INSTALL result for the same agent — started
|
|
8303
8017
|
// in another tab, and deduped server-side so our update produced no event of its own —
|
|
8304
8018
|
// would be reported as this dialog's update outcome.
|
|
8305
8019
|
const forDialog = isUpdate && _importFailedVersions.has(m.id);
|
|
8306
8020
|
loadAgentCatalog().then(() => {
|
|
8021
|
+
refreshAgentNotes();
|
|
8307
8022
|
// Report it in the import-failure dialog too, if that is where the update was started
|
|
8308
8023
|
// from. The catalogue has just been reloaded, so comparing against the version captured at
|
|
8309
8024
|
// click time is what distinguishes a real bump from "already the latest" — the result
|
|
@@ -8336,7 +8051,7 @@
|
|
|
8336
8051
|
agentUpdateFailures.set(m.id, String(m.error || `Could not update ${m.id}.`));
|
|
8337
8052
|
showToast(`Could not update ${m.id} — see the card for details.`, 'err');
|
|
8338
8053
|
} else {
|
|
8339
|
-
showToast(`
|
|
8054
|
+
showToast(`We couldn’t install ${m.id} because FloLess could not finish the setup. Try again.`, 'err');
|
|
8340
8055
|
}
|
|
8341
8056
|
if (_importFailedVersions.has(m.id)) {
|
|
8342
8057
|
// A failed update is NOT the "nothing to update" answer — say which it was, and re-arm the
|
|
@@ -8395,7 +8110,7 @@
|
|
|
8395
8110
|
if (m.status === 'connected') {
|
|
8396
8111
|
if (slot) slot.innerHTML = '';
|
|
8397
8112
|
showToast(`Connected ${m.id}`, 'ok');
|
|
8398
|
-
refreshIntegrations();
|
|
8113
|
+
refreshIntegrations(`Connected ${m.id}. Account readiness updated.`);
|
|
8399
8114
|
} else if (slot) {
|
|
8400
8115
|
slot.innerHTML = `Sign-in ${escapeHtml(m.status || 'failed')}${m.error ? ' — ' + escapeHtml(m.error) : ''}. Click Connect to retry.`;
|
|
8401
8116
|
}
|
|
@@ -8432,7 +8147,7 @@
|
|
|
8432
8147
|
function reportErr(e) {
|
|
8433
8148
|
if (awarePageUnloading && e instanceof TypeError && e.message === 'Failed to fetch') return;
|
|
8434
8149
|
console.error(e);
|
|
8435
|
-
showToast(
|
|
8150
|
+
showToast('We couldn’t finish that. Your work is still here. Try again. If it keeps happening, reopen FloLess.', 'err');
|
|
8436
8151
|
}
|
|
8437
8152
|
|
|
8438
8153
|
// True if `id` appears as a full path segment (avoids `foo` matching `foo-bar`).
|
|
@@ -8514,7 +8229,7 @@
|
|
|
8514
8229
|
const id = state.editingTemplateId;
|
|
8515
8230
|
const name = ($favName.value || '').trim();
|
|
8516
8231
|
const category = ($favCat.value || '').trim() || 'Uncategorized';
|
|
8517
|
-
if (!name) { showToast('
|
|
8232
|
+
if (!name) { showToast('Give this template a name, then save it.', 'warn'); return; }
|
|
8518
8233
|
try {
|
|
8519
8234
|
await api(`/api/templates/${encodeURIComponent(id)}`, { method: 'PATCH', body: JSON.stringify({ name, category }) });
|
|
8520
8235
|
$addFavModal.classList.remove('show');
|
|
@@ -8530,7 +8245,7 @@
|
|
|
8530
8245
|
const category = ($favCat.value || '').trim() || 'Uncategorized';
|
|
8531
8246
|
const app = apps.get(currentId);
|
|
8532
8247
|
const n = app && app.nodes.find((x) => x.id === nodeId);
|
|
8533
|
-
if (!n) { showToast('
|
|
8248
|
+
if (!n) { showToast('That workflow step is no longer available. Reopen the workflow, then try again.', 'err'); return; }
|
|
8534
8249
|
const node = {
|
|
8535
8250
|
agent: n.agent,
|
|
8536
8251
|
command: n.command,
|
|
@@ -8657,7 +8372,9 @@
|
|
|
8657
8372
|
// would still let that cross-tab gap copy a second writer's obsolete handoff.
|
|
8658
8373
|
if (req?.type === 'revision-read' && req.id) {
|
|
8659
8374
|
try {
|
|
8660
|
-
|
|
8375
|
+
// A dead local server must not leave a Copy button waiting forever. Keep the
|
|
8376
|
+
// authoritative revalidation, but fail closed after a short, user-action-sized wait.
|
|
8377
|
+
const latest = await api('/api/requests', { signal: AbortSignal.timeout(5000) });
|
|
8661
8378
|
current = Array.isArray(latest?.requests)
|
|
8662
8379
|
? latest.requests.find((candidate) => candidate && candidate.id === req.id)
|
|
8663
8380
|
: null;
|
|
@@ -8691,6 +8408,27 @@
|
|
|
8691
8408
|
? ['Nothing to copy — this request has no instruction', 'err']
|
|
8692
8409
|
: ['copy failed', 'err']);
|
|
8693
8410
|
|
|
8411
|
+
function setCopyBusy(button, busy) {
|
|
8412
|
+
if (!button) return;
|
|
8413
|
+
if (busy) {
|
|
8414
|
+
button.dataset.copyPreviousTip = button.dataset.tip || '';
|
|
8415
|
+
button.dataset.copyPreviousLabel = button.getAttribute('aria-label') || '';
|
|
8416
|
+
button.disabled = true;
|
|
8417
|
+
button.setAttribute('aria-busy', 'true');
|
|
8418
|
+
button.dataset.tip = 'Copying the instruction…';
|
|
8419
|
+
button.setAttribute('aria-label', 'Copying the instruction');
|
|
8420
|
+
} else {
|
|
8421
|
+
button.disabled = false;
|
|
8422
|
+
button.removeAttribute('aria-busy');
|
|
8423
|
+
if (button.dataset.copyPreviousTip) button.dataset.tip = button.dataset.copyPreviousTip;
|
|
8424
|
+
else delete button.dataset.tip;
|
|
8425
|
+
if (button.dataset.copyPreviousLabel) button.setAttribute('aria-label', button.dataset.copyPreviousLabel);
|
|
8426
|
+
else button.removeAttribute('aria-label');
|
|
8427
|
+
delete button.dataset.copyPreviousTip;
|
|
8428
|
+
delete button.dataset.copyPreviousLabel;
|
|
8429
|
+
}
|
|
8430
|
+
}
|
|
8431
|
+
|
|
8694
8432
|
// ── Headless runs (#571 slice 3) ────────────────────────────────────────────
|
|
8695
8433
|
// floless starting the user's OWN terminal AI on a queued request, instead of them pasting it.
|
|
8696
8434
|
// The browser holds NO copy of which request types may run: every row arrives carrying `canRun`
|
|
@@ -8718,6 +8456,15 @@
|
|
|
8718
8456
|
const headlessRuntimes = () => (headlessInfo && Array.isArray(headlessInfo.runtimes) ? headlessInfo.runtimes : []);
|
|
8719
8457
|
/** Zero runtimes found ⇒ no run affordance anywhere (§E4). Hidden, never disabled. */
|
|
8720
8458
|
const headlessReady = () => headlessRuntimes().some((r) => r && r.state === 'found');
|
|
8459
|
+
const preferredChatProvider = () => {
|
|
8460
|
+
const current = window.flolessChat?.currentProvider?.();
|
|
8461
|
+
if (current === 'claude' || current === 'codex') return current;
|
|
8462
|
+
const chosen = headlessInfo?.provider;
|
|
8463
|
+
if ((chosen === 'claude' || chosen === 'codex')
|
|
8464
|
+
&& headlessRuntimes().some((runtime) => runtime?.id === chosen && runtime.state === 'found')) return chosen;
|
|
8465
|
+
return headlessRuntimes().find((runtime) => (runtime?.id === 'claude' || runtime?.id === 'codex')
|
|
8466
|
+
&& runtime.state === 'found')?.id || null;
|
|
8467
|
+
};
|
|
8721
8468
|
const runtimeLabel = (id) => {
|
|
8722
8469
|
const m = headlessRuntimes().find((r) => r && r.id === id);
|
|
8723
8470
|
return (m && m.label) || String(id || 'your terminal AI');
|
|
@@ -8747,6 +8494,7 @@
|
|
|
8747
8494
|
'exited-unresolved': { badge: 'Finished, unconfirmed', cls: 'warn', note: (rt, offered) => offered ? 'Review and confirm this request in a desktop app.' : 'This request finished without confirming what it did.' },
|
|
8748
8495
|
failed: { badge: 'Failed', cls: 'err', note: () => 'The run failed.' },
|
|
8749
8496
|
stopped: { badge: 'Stopped', cls: 'muted', note: (rt, offered) => offered ? 'Continue this request in a desktop app.' : 'This request was stopped.' },
|
|
8497
|
+
answered: { badge: 'Answer ready', cls: 'active', note: () => 'AI Chat publication is being retried. Your answer is safe here.' },
|
|
8750
8498
|
};
|
|
8751
8499
|
|
|
8752
8500
|
// A parked run is a hand-off, not a browser-owned conversation (§G). The server stamps a command
|
|
@@ -8830,6 +8578,7 @@
|
|
|
8830
8578
|
<span class="req-run-badge req-run-badge-${v.cls}">${escapeHtml(v.badge)}</span>
|
|
8831
8579
|
</div>
|
|
8832
8580
|
${note ? `<p class="req-run-note">${escapeHtml(note)}</p>` : ''}
|
|
8581
|
+
${run.state === 'answered' && typeof run.answer === 'string' ? `<div class="req-run-answer">${escapeHtml(run.answer)}</div>` : ''}
|
|
8833
8582
|
${run.question ? `<p class="req-run-question">${escapeHtml(run.question)}</p>` : ''}
|
|
8834
8583
|
${desktop}
|
|
8835
8584
|
${terminalFallback}
|
|
@@ -8853,7 +8602,12 @@
|
|
|
8853
8602
|
// No folder yet (or one that has since gone) is not an error to report — it is the one
|
|
8854
8603
|
// question the user has not been asked. Ask it, pre-loaded with the server's own sentence.
|
|
8855
8604
|
if (code === 'no-folder' || code === 'bad-folder') { await openRunOptions(req, err.body.error); return null; }
|
|
8856
|
-
|
|
8605
|
+
// FloLess is still installing (or could not install) its tested copy of this AI tool: say so plainly.
|
|
8606
|
+
if (code === 'runtime-preparing' && typeof err.body.error === 'string') {
|
|
8607
|
+
showToast(err.body.error, err.body.runtime && err.body.runtime.state === 'failed' ? 'err' : 'warn');
|
|
8608
|
+
return null;
|
|
8609
|
+
}
|
|
8610
|
+
showToast('We couldn’t start this run because FloLess could not reach the workflow. Check your connection, then try again.', 'err');
|
|
8857
8611
|
return null;
|
|
8858
8612
|
}
|
|
8859
8613
|
}
|
|
@@ -8893,7 +8647,7 @@
|
|
|
8893
8647
|
try { info = await api(`/api/terminal-runtimes${key ? `?project=${encodeURIComponent(key)}` : ''}`); }
|
|
8894
8648
|
catch (e) { reportErr(e); return null; }
|
|
8895
8649
|
const found = (info.runtimes || []).filter((r) => r && r.state === 'found');
|
|
8896
|
-
if (!found.length) { showToast('No
|
|
8650
|
+
if (!found.length) { showToast('No supported AI provider is installed on this computer.', 'warn'); return null; }
|
|
8897
8651
|
let folder = info.folder || '';
|
|
8898
8652
|
let sub = problem || '';
|
|
8899
8653
|
// Tracked SEPARATELY from `sub`, because the two are different messages. `problem` on the first
|
|
@@ -8906,14 +8660,14 @@
|
|
|
8906
8660
|
// leaks nothing to the next caller — and without it the only thing that changes on a bad
|
|
8907
8661
|
// folder is one line of muted grey, in the same tier as the explanation it replaced.
|
|
8908
8662
|
title: refused ? 'That folder won’t work' : 'Start this request automatically',
|
|
8909
|
-
sub: sub || '
|
|
8663
|
+
sub: sub || 'FloLess starts your selected AI provider in the folder you choose and sends it this request. It runs on this computer using your account.',
|
|
8910
8664
|
fields: [
|
|
8911
8665
|
{
|
|
8912
8666
|
name: 'folder', label: 'Folder to work in', value: folder,
|
|
8913
8667
|
placeholder: 'C:\\Repos\\my-project',
|
|
8914
8668
|
},
|
|
8915
8669
|
{
|
|
8916
|
-
name: 'runtime', label: '
|
|
8670
|
+
name: 'runtime', label: 'AI provider', type: 'select', value: info.provider || found[0].id,
|
|
8917
8671
|
commandId: 'shell.requests-runtime',
|
|
8918
8672
|
options: found.map((r) => ({ value: r.id, label: r.label, meta: r.command })),
|
|
8919
8673
|
},
|
|
@@ -8941,8 +8695,11 @@
|
|
|
8941
8695
|
}
|
|
8942
8696
|
|
|
8943
8697
|
let requestHelpReq = null;
|
|
8698
|
+
let requestHelpCopied = false;
|
|
8944
8699
|
let requestHelpReturnFocus = null;
|
|
8945
8700
|
let requestHelpEpoch = 0;
|
|
8701
|
+
let requestHelpBusyMode = null;
|
|
8702
|
+
let requestHelpRunActive = false;
|
|
8946
8703
|
function closeRequestHelp({ restoreFocus = true } = {}) {
|
|
8947
8704
|
requestHelpEpoch += 1;
|
|
8948
8705
|
const $m = document.getElementById('request-help-modal');
|
|
@@ -8950,6 +8707,9 @@
|
|
|
8950
8707
|
const target = requestHelpReturnFocus;
|
|
8951
8708
|
requestHelpReturnFocus = null;
|
|
8952
8709
|
requestHelpReq = null;
|
|
8710
|
+
requestHelpCopied = false;
|
|
8711
|
+
requestHelpBusyMode = null;
|
|
8712
|
+
requestHelpRunActive = false;
|
|
8953
8713
|
if (restoreFocus && target && target.isConnected) {
|
|
8954
8714
|
try { target.focus(); } catch { /* focus is best-effort */ }
|
|
8955
8715
|
}
|
|
@@ -8961,6 +8721,7 @@
|
|
|
8961
8721
|
requestHelpReq = req;
|
|
8962
8722
|
requestHelpReturnFocus = opts.returnFocus || document.activeElement;
|
|
8963
8723
|
const copied = opts.copied !== false;
|
|
8724
|
+
requestHelpCopied = copied;
|
|
8964
8725
|
const n = Number(opts.fileCount || (req.sourceRefs && req.sourceRefs.length) || (req.snapshots && req.snapshots.length) || 1);
|
|
8965
8726
|
const sourceNames = Array.isArray(req.sourceRefs) ? req.sourceRefs.map((ref) => String(ref?.name || ref?.path || ref || '')) : [];
|
|
8966
8727
|
const allPdf = sourceNames.length > 0 && sourceNames.every((name) => /\.pdf$/i.test(name));
|
|
@@ -8981,10 +8742,10 @@
|
|
|
8981
8742
|
? `${n} ${fileKind} added to Requests. Open Requests to see the current status and recovery step.`
|
|
8982
8743
|
: isRevisionRead
|
|
8983
8744
|
? copied
|
|
8984
|
-
? `${n} ${fileKind} added to Requests.
|
|
8745
|
+
? `${n} ${fileKind} added to Requests. Start it in AI Chat here, or use the copied terminal instruction.`
|
|
8985
8746
|
: `${n} ${fileKind} added to Requests. Copy the request here or from the Requests panel.`
|
|
8986
8747
|
: copied
|
|
8987
|
-
? 'Your request was added to Requests,
|
|
8748
|
+
? 'Your request was added to Requests. Start it in AI Chat here, or use the copied terminal instruction.'
|
|
8988
8749
|
: 'Your request was added to Requests. Copy the instructions here or from the Requests panel.';
|
|
8989
8750
|
}
|
|
8990
8751
|
renderRequestHelpGuidance(req);
|
|
@@ -8993,6 +8754,7 @@
|
|
|
8993
8754
|
if ($copy) $copy.hidden = copied || !canUseManualHandoff;
|
|
8994
8755
|
// Back to the "not started" face on every open — the previous request's run status must never
|
|
8995
8756
|
// be the first thing the next one shows.
|
|
8757
|
+
setRequestHelpBusy(null);
|
|
8996
8758
|
setRequestHelpRunning(null);
|
|
8997
8759
|
showModal($m);
|
|
8998
8760
|
const shell = $m.querySelector('.modal.request-help');
|
|
@@ -9030,11 +8792,18 @@
|
|
|
9030
8792
|
const retainedRevisionWhy = retainedRevisionRecovery
|
|
9031
8793
|
? (req.clearWhy || 'FloLess cannot safely release this drawing read yet. Restart FloLess and open Requests again.')
|
|
9032
8794
|
: '';
|
|
8795
|
+
const canStartInChat = Boolean((req.project || req.workflowId) && preferredChatProvider()
|
|
8796
|
+
&& (!isRevisionRead || req.status === 'pending'));
|
|
8797
|
+
const ownerNoun = req.project ? 'project' : 'workflow';
|
|
9033
8798
|
const canStartUpdatedRead = isRevisionRead && req.status === 'pending' && !isInitial && req.canRun && headlessReady();
|
|
9034
8799
|
const $steps = document.getElementById('request-help-steps');
|
|
9035
8800
|
const $note = document.getElementById('request-help-note');
|
|
9036
8801
|
if ($steps) {
|
|
9037
|
-
$steps.innerHTML =
|
|
8802
|
+
$steps.innerHTML = canStartInChat
|
|
8803
|
+
? `<div class="request-help-step"><span>1</span><p>Choose Start in AI Chat below. The conversation opens in this ${ownerNoun}’s folder.</p></div>`
|
|
8804
|
+
+ `<div class="request-help-step"><span>2</span><p>Continue in AI Chat while Claude or Codex reads the ${allPdf ? 'PDF set' : 'drawing files'}.</p></div>`
|
|
8805
|
+
+ '<div class="request-help-step"><span>3</span><p>Review any question or proposed change in the same conversation before it continues.</p></div>'
|
|
8806
|
+
: canStartUpdatedRead
|
|
9038
8807
|
? '<div class="request-help-step"><span>1</span><p>Choose Start automatically below. FloLess will run the Drawing Filter preparation with your terminal AI.</p></div>'
|
|
9039
8808
|
+ '<div class="request-help-step"><span>2</span><p>Keep FloLess open. You can do other work while the updated drawing is prepared.</p></div>'
|
|
9040
8809
|
+ '<div class="request-help-step"><span>3</span><p>When it stops, open Drawing Filter, review the selected lines, then press Save filter in the top-right corner. After Save, return to the same terminal AI and tell it to continue the drawing read.</p></div>'
|
|
@@ -9054,7 +8823,9 @@
|
|
|
9054
8823
|
+ '<div class="request-help-step"><span>2</span><p>Paste the copied request and let your terminal AI apply it.</p></div>'
|
|
9055
8824
|
+ '<div class="request-help-step"><span>3</span><p>Return here to check the result in FloLess.</p></div>';
|
|
9056
8825
|
}
|
|
9057
|
-
if ($note) $note.textContent =
|
|
8826
|
+
if ($note) $note.textContent = canStartInChat
|
|
8827
|
+
? `The request and its conversation stay with this ${ownerNoun}. If chat cannot start, the request remains queued and the terminal copy remains available.`
|
|
8828
|
+
: isUnknownRevisionStatus
|
|
9058
8829
|
? retainedRevisionRecovery
|
|
9059
8830
|
? `FloLess does not recognize this drawing request status. Do not paste or start it again. Update FloLess, then open Requests again. ${retainedRevisionWhy} Do not attach the drawings again until this recovery is complete.`
|
|
9060
8831
|
: 'FloLess does not recognize this drawing request status. Do not paste or start it again. Open Requests for details and update FloLess; if the request cannot be recovered, attach the drawing set again.'
|
|
@@ -9079,13 +8850,44 @@
|
|
|
9079
8850
|
function syncRequestHelpRun() {
|
|
9080
8851
|
const $split = document.getElementById('request-help-run-split');
|
|
9081
8852
|
const $open = document.getElementById('request-help-open');
|
|
9082
|
-
|
|
9083
|
-
const
|
|
8853
|
+
const $chat = document.getElementById('request-help-chat');
|
|
8854
|
+
const $chatMeta = document.getElementById('request-help-chat-meta');
|
|
8855
|
+
if (!$split || !$open || !$chat || !$chatMeta) return;
|
|
8856
|
+
const can = !!(!requestHelpBusyMode && !requestHelpRunActive && requestHelpReq && requestHelpReq.canRun
|
|
9084
8857
|
&& (requestHelpReq.type !== 'revision-read' || requestHelpReq.status === 'pending') && headlessReady());
|
|
9085
8858
|
$split.hidden = !can;
|
|
9086
|
-
|
|
9087
|
-
|
|
9088
|
-
$
|
|
8859
|
+
const canChat = Boolean(!requestHelpRunActive && requestHelpReq && (requestHelpReq.project || requestHelpReq.workflowId)
|
|
8860
|
+
&& preferredChatProvider() && requestHelpReq.status === 'pending');
|
|
8861
|
+
$chat.hidden = !canChat;
|
|
8862
|
+
$chat.disabled = !!requestHelpBusyMode;
|
|
8863
|
+
const provider = canChat ? preferredChatProvider() : null;
|
|
8864
|
+
$chatMeta.hidden = !provider;
|
|
8865
|
+
$chatMeta.textContent = provider
|
|
8866
|
+
? `Starts with ${runtimeLabel(provider)} · ${requestHelpReq.type === 'guide' ? 'Read only' : 'Working folder write'}`
|
|
8867
|
+
: '';
|
|
8868
|
+
$open.classList.toggle('primary', !canChat);
|
|
8869
|
+
}
|
|
8870
|
+
|
|
8871
|
+
function setRequestHelpBusy(mode) {
|
|
8872
|
+
requestHelpBusyMode = mode || null;
|
|
8873
|
+
const modal = document.getElementById('request-help-modal');
|
|
8874
|
+
const shell = modal && modal.querySelector('.modal.request-help');
|
|
8875
|
+
const chat = document.getElementById('request-help-chat');
|
|
8876
|
+
const run = document.getElementById('request-help-run');
|
|
8877
|
+
if (shell) {
|
|
8878
|
+
if (requestHelpBusyMode) shell.setAttribute('aria-busy', 'true');
|
|
8879
|
+
else shell.removeAttribute('aria-busy');
|
|
8880
|
+
}
|
|
8881
|
+
if (modal) {
|
|
8882
|
+
modal.querySelectorAll('.modal-actions button').forEach((button) => { button.disabled = !!requestHelpBusyMode; });
|
|
8883
|
+
}
|
|
8884
|
+
if (chat) {
|
|
8885
|
+
chat.textContent = requestHelpBusyMode === 'chat' ? 'Starting…' : 'Start in AI Chat';
|
|
8886
|
+
if (requestHelpBusyMode === 'chat') chat.setAttribute('aria-busy', 'true');
|
|
8887
|
+
else chat.removeAttribute('aria-busy');
|
|
8888
|
+
}
|
|
8889
|
+
if (run) run.textContent = requestHelpBusyMode === 'background' ? 'Starting…' : '▶ Start in background';
|
|
8890
|
+
if (!requestHelpBusyMode) syncRequestHelpRun();
|
|
9089
8891
|
}
|
|
9090
8892
|
|
|
9091
8893
|
/** Fields whose change makes the upload handoff modal's guidance or Start policy stale. */
|
|
@@ -9108,6 +8910,7 @@
|
|
|
9108
8910
|
const $split = document.getElementById('request-help-run-split');
|
|
9109
8911
|
const $note = document.getElementById('request-help-note');
|
|
9110
8912
|
if (!$steps || !$status) return;
|
|
8913
|
+
requestHelpRunActive = !!run;
|
|
9111
8914
|
$steps.hidden = !!run;
|
|
9112
8915
|
$status.hidden = !run;
|
|
9113
8916
|
if (!run) {
|
|
@@ -9117,6 +8920,10 @@
|
|
|
9117
8920
|
return;
|
|
9118
8921
|
}
|
|
9119
8922
|
if ($split) $split.hidden = true; // it started; there is nothing left to start
|
|
8923
|
+
const $chat = document.getElementById('request-help-chat');
|
|
8924
|
+
const $copy = document.getElementById('request-help-copy');
|
|
8925
|
+
if ($chat) $chat.hidden = true;
|
|
8926
|
+
if ($copy) $copy.hidden = true;
|
|
9120
8927
|
// …which leaves the row with no emphasized action, so Open Requests takes the primary back.
|
|
9121
8928
|
// `syncRequestHelpRun` can't do this: it would re-show the split it just retired.
|
|
9122
8929
|
const $open = document.getElementById('request-help-open');
|
|
@@ -9124,7 +8931,7 @@
|
|
|
9124
8931
|
if ($title) {
|
|
9125
8932
|
$title.innerHTML = `Running in <strong>${escapeHtml(runtimeLabel(run.runtime))}</strong>${run.cwd ? ` · <code>${escapeHtml(run.cwd)}</code>` : ''}`;
|
|
9126
8933
|
}
|
|
9127
|
-
if ($note) $note.textContent = '
|
|
8934
|
+
if ($note) $note.textContent = 'FloLess keeps this request on this computer. Claude or Codex processes it through the account signed in to its app.';
|
|
9128
8935
|
}
|
|
9129
8936
|
|
|
9130
8937
|
async function useTemplate(templateId) {
|
|
@@ -9183,23 +8990,24 @@
|
|
|
9183
8990
|
// request it names is gone.
|
|
9184
8991
|
let pendingRevealId = null;
|
|
9185
8992
|
let requestFetchEpoch = 0;
|
|
8993
|
+
let publishedAnswerChatIds = null;
|
|
9186
8994
|
async function loadRequests() {
|
|
9187
8995
|
try {
|
|
9188
8996
|
const epoch = ++requestFetchEpoch;
|
|
9189
|
-
const { requests,
|
|
8997
|
+
const { requests, chatPublications = [] } = await api('/api/requests');
|
|
9190
8998
|
if (epoch !== requestFetchEpoch) return;
|
|
9191
|
-
|
|
9192
|
-
reconcileActiveInstructorRuns(requests, answers);
|
|
9193
|
-
if (!hydratedInstructorAnswers) {
|
|
9194
|
-
acceptInstructorAnswers(answers, { initial: true });
|
|
9195
|
-
hydratedInstructorAnswers = true;
|
|
9196
|
-
} else {
|
|
9197
|
-
acceptInstructorAnswers(answers);
|
|
9198
|
-
}
|
|
8999
|
+
reconcileActiveInstructorRuns(requests, chatPublications);
|
|
9199
9000
|
pendingRequests = requests;
|
|
9200
|
-
|
|
9201
|
-
|
|
9202
|
-
|
|
9001
|
+
const nextPublishedChatIds = new Set(chatPublications.map((publication) => publication?.chatId).filter(Boolean));
|
|
9002
|
+
const newlyPublishedHere = publishedAnswerChatIds !== null && chatPublications.some((publication) => {
|
|
9003
|
+
if (!publication?.chatId || publishedAnswerChatIds.has(publication.chatId)) return false;
|
|
9004
|
+
const scope = window.flolessBridge?.getChatScope?.();
|
|
9005
|
+
return scope?.owner?.kind === publication.ownerKind
|
|
9006
|
+
&& (scope.owner.projectId || scope.owner.workflowId) === publication.ownerId;
|
|
9007
|
+
});
|
|
9008
|
+
publishedAnswerChatIds = nextPublishedChatIds;
|
|
9009
|
+
if (newlyPublishedHere) void window.flolessChat?.refreshIndex?.();
|
|
9010
|
+
else window.flolessChat?.refreshActivity?.();
|
|
9203
9011
|
// The upload modal starts with the POST response, but polling owns the live request state. Do not
|
|
9204
9012
|
// leave an old Start button or first-step explanation visible after the request becomes prepared,
|
|
9205
9013
|
// staged, failed, or disappears. Move to the live row, which already renders every lifecycle state.
|
|
@@ -9247,7 +9055,6 @@
|
|
|
9247
9055
|
previousRequestIds = ids;
|
|
9248
9056
|
const $rm = document.getElementById('requests-modal');
|
|
9249
9057
|
if ($rm && $rm.classList.contains('show')) renderRequests(); // keep an open list live
|
|
9250
|
-
restoreAnswerSessionFocus(continuationFocus);
|
|
9251
9058
|
} catch { /* non-fatal */ }
|
|
9252
9059
|
}
|
|
9253
9060
|
|
|
@@ -9267,10 +9074,9 @@
|
|
|
9267
9074
|
* Does this queued request belong to what the user has open? (Pure — unit-tested.)
|
|
9268
9075
|
*
|
|
9269
9076
|
* Three cases, and the middle one is the whole point of the filter:
|
|
9270
|
-
* - A request with NEITHER appId nor project (
|
|
9271
|
-
*
|
|
9272
|
-
*
|
|
9273
|
-
* is worse than one extra row.
|
|
9077
|
+
* - A request with NEITHER appId nor project (dashboard customization or a standalone new
|
|
9078
|
+
* workflow) belongs to no open project/app scope, so it is always shown. A project-owned new
|
|
9079
|
+
* workflow carries `project` and follows the project rule below.
|
|
9274
9080
|
* - A PROJECT scope matches on project id only. A Workspaces tweak-contract carries both a
|
|
9275
9081
|
* project and its app, so matching on appId would pull in every OTHER project sharing that
|
|
9276
9082
|
* app — six 'steel-model' projects here all bleed into each other.
|
|
@@ -9312,7 +9118,15 @@
|
|
|
9312
9118
|
if (!r) return '';
|
|
9313
9119
|
if (r.project) return r.projectName || r.project;
|
|
9314
9120
|
if (r.appId) return r.appId;
|
|
9315
|
-
return r.type === 'ui-customize' ? 'your dashboard' : r.type === 'new-workflow' ? 'a new workflow' : '';
|
|
9121
|
+
return r.type === 'ui-customize' ? 'your dashboard' : r.type === 'new-workflow' ? (r.workflowName || 'a new workflow') : '';
|
|
9122
|
+
}
|
|
9123
|
+
|
|
9124
|
+
function requestMatchesChatScope(request) {
|
|
9125
|
+
const scope = currentChatScope();
|
|
9126
|
+
if (!scope?.owner || !request) return false;
|
|
9127
|
+
return scope.owner.kind === 'project'
|
|
9128
|
+
? request.project === scope.owner.projectId
|
|
9129
|
+
: request.workflowId === scope.owner.workflowId;
|
|
9316
9130
|
}
|
|
9317
9131
|
|
|
9318
9132
|
// Everything a search should match: the project/workflow the request belongs to, its badge
|
|
@@ -9332,17 +9146,6 @@
|
|
|
9332
9146
|
.filter(Boolean).join(' ');
|
|
9333
9147
|
}
|
|
9334
9148
|
|
|
9335
|
-
function answerSessionSearchText(answer) {
|
|
9336
|
-
return [
|
|
9337
|
-
answerSessionProviderLabel(answer?.continuation?.provider),
|
|
9338
|
-
answer?.instructorContext?.subject,
|
|
9339
|
-
answer?.appId,
|
|
9340
|
-
answer?.project,
|
|
9341
|
-
answer?.projectLabel,
|
|
9342
|
-
answer?.answer,
|
|
9343
|
-
].filter(Boolean).join(' ');
|
|
9344
|
-
}
|
|
9345
|
-
|
|
9346
9149
|
function requestLabel(r) {
|
|
9347
9150
|
if (r.type === 'revision-read') return (!r.baseVersion || r.baseVersion <= 0) ? 'initial drawing read' : 'updated drawing read';
|
|
9348
9151
|
return r.type === 'use-template' ? 'template' : r.type === 'ui-customize' ? 'dashboard' : r.type === 'rebake' ? 're-bake' : r.type === 'guide' ? 'guide' : r.type === 'new-workflow' ? 'new workflow' : r.type === 'knowledge-organize' ? 'organize' : r.type === 'knowledge-adjust' ? 'adjust' : r.type === 'knowledge-consult' ? 'knowledge' : r.type === 'tweak-contract' ? 'contract' : 'tweak';
|
|
@@ -9446,7 +9249,7 @@
|
|
|
9446
9249
|
return;
|
|
9447
9250
|
}
|
|
9448
9251
|
const copied = await copyToClipboard(lines.join('\n\n'));
|
|
9449
|
-
if (!copied) { showToast('copy
|
|
9252
|
+
if (!copied) { showToast('We couldn’t copy that request. Select the text and copy it manually.', 'err'); return; }
|
|
9450
9253
|
showToast(
|
|
9451
9254
|
bulkCopySuccessMessage({ lines, dropped, drawingSkipped, activeSkipped, preparationBlockedSkipped, preparationPublishedSkipped, incompleteSkipped }, shown.length),
|
|
9452
9255
|
dropped ? 'warn' : 'ok',
|
|
@@ -9454,40 +9257,40 @@
|
|
|
9454
9257
|
}
|
|
9455
9258
|
|
|
9456
9259
|
function bulkCopyEmptyMessage(plan, total) {
|
|
9457
|
-
if (plan.preparationBlockedSkipped === total) return 'Nothing to copy — drawing preparation
|
|
9458
|
-
if (plan.preparationPublishedSkipped === total) return 'Nothing to copy — drawing preparation is complete
|
|
9260
|
+
if (plan.preparationBlockedSkipped === total) return 'Nothing to copy — FloLess could not finish drawing preparation. Restart FloLess and try again.';
|
|
9261
|
+
if (plan.preparationPublishedSkipped === total) return 'Nothing to copy — drawing preparation is complete. Continue in the same AI conversation.';
|
|
9459
9262
|
if (plan.drawingSkipped === total) return 'Nothing to copy — these drawing reads need review, continuation, or reattachment';
|
|
9460
9263
|
if (plan.activeSkipped === total) return 'Nothing to copy — these requests are already running';
|
|
9461
9264
|
const blocked = plan.preparationBlockedSkipped
|
|
9462
|
-
? `${plan.preparationBlockedSkipped} drawing preparation${plan.preparationBlockedSkipped === 1 ? ' needs' : 's need'}
|
|
9265
|
+
? `${plan.preparationBlockedSkipped} drawing preparation${plan.preparationBlockedSkipped === 1 ? ' needs' : 's need'} FloLess to be restarted`
|
|
9463
9266
|
: '';
|
|
9464
9267
|
const published = plan.preparationPublishedSkipped
|
|
9465
|
-
? `${plan.preparationPublishedSkipped} drawing preparation${plan.preparationPublishedSkipped === 1 ? ' is' : 's are'} complete and
|
|
9268
|
+
? `${plan.preparationPublishedSkipped} drawing preparation${plan.preparationPublishedSkipped === 1 ? ' is' : 's are'} complete and can continue in the same AI conversation`
|
|
9466
9269
|
: '';
|
|
9467
9270
|
const drawing = plan.drawingSkipped
|
|
9468
9271
|
? `${plan.drawingSkipped} drawing read${plan.drawingSkipped === 1 ? ' needs' : 's need'} review, continuation, or reattachment`
|
|
9469
9272
|
: '';
|
|
9470
9273
|
const active = plan.activeSkipped ? `${plan.activeSkipped} already running` : '';
|
|
9471
|
-
const incomplete = plan.incompleteSkipped ? `${plan.incompleteSkipped}
|
|
9274
|
+
const incomplete = plan.incompleteSkipped ? `${plan.incompleteSkipped} did not have a complete instruction` : '';
|
|
9472
9275
|
const reasons = [blocked, published, drawing, active, incomplete].filter(Boolean);
|
|
9473
9276
|
return reasons.length
|
|
9474
9277
|
? `Nothing to copy — ${reasons.join(', ')}`
|
|
9475
|
-
: 'Nothing to copy — no complete
|
|
9278
|
+
: 'Nothing to copy — no complete instruction is available';
|
|
9476
9279
|
}
|
|
9477
9280
|
|
|
9478
9281
|
function bulkCopySuccessMessage(plan, total) {
|
|
9479
|
-
if (!plan.dropped) return `Copied ${plan.lines.length} request(s) — paste
|
|
9282
|
+
if (!plan.dropped) return `Copied ${plan.lines.length} request(s) — paste them into your AI provider`;
|
|
9480
9283
|
const drawing = plan.drawingSkipped
|
|
9481
9284
|
? `${plan.drawingSkipped} drawing read${plan.drawingSkipped === 1 ? ' needs' : 's need'} review, continuation, or reattachment`
|
|
9482
9285
|
: '';
|
|
9483
9286
|
const active = plan.activeSkipped ? `${plan.activeSkipped} already running` : '';
|
|
9484
9287
|
const blocked = plan.preparationBlockedSkipped
|
|
9485
|
-
? `${plan.preparationBlockedSkipped} drawing preparation${plan.preparationBlockedSkipped === 1 ? ' needs' : 's need'}
|
|
9288
|
+
? `${plan.preparationBlockedSkipped} drawing preparation${plan.preparationBlockedSkipped === 1 ? ' needs' : 's need'} FloLess to be restarted`
|
|
9486
9289
|
: '';
|
|
9487
9290
|
const published = plan.preparationPublishedSkipped
|
|
9488
|
-
? `${plan.preparationPublishedSkipped} drawing preparation${plan.preparationPublishedSkipped === 1 ? ' is' : 's are'} complete and
|
|
9291
|
+
? `${plan.preparationPublishedSkipped} drawing preparation${plan.preparationPublishedSkipped === 1 ? ' is' : 's are'} complete and can continue in the same AI conversation`
|
|
9489
9292
|
: '';
|
|
9490
|
-
const incomplete = plan.incompleteSkipped ? `${plan.incompleteSkipped}
|
|
9293
|
+
const incomplete = plan.incompleteSkipped ? `${plan.incompleteSkipped} did not have a complete instruction` : '';
|
|
9491
9294
|
return `Copied ${plan.lines.length} of ${total} — ${[drawing, active, blocked, published, incomplete].filter(Boolean).join(', ')}`;
|
|
9492
9295
|
}
|
|
9493
9296
|
|
|
@@ -9495,7 +9298,7 @@
|
|
|
9495
9298
|
function requestSummary(r) {
|
|
9496
9299
|
if (!r || r.type !== 'revision-read') return '';
|
|
9497
9300
|
if (r.preparationState === 'blocked') {
|
|
9498
|
-
return '
|
|
9301
|
+
return 'FloLess could not finish drawing preparation because it could not confirm that an earlier drawing reader stopped. Your drawings are still attached. Restart FloLess; if this remains blocked, open Requests and follow the detailed instructions.';
|
|
9499
9302
|
}
|
|
9500
9303
|
if (r.preparationState === 'manifest-published' && !r.prepassReady) {
|
|
9501
9304
|
return 'Drawing preparation is complete and the prepared data is saved. Return to the same terminal AI session and tell it to continue creating the Drawing Filter. Do not start or copy this request again.';
|
|
@@ -9663,7 +9466,7 @@
|
|
|
9663
9466
|
if (!r) return '';
|
|
9664
9467
|
if (r.status && r.status !== 'pending') return '';
|
|
9665
9468
|
if (r.preparationState === 'blocked') {
|
|
9666
|
-
return '
|
|
9469
|
+
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.';
|
|
9667
9470
|
}
|
|
9668
9471
|
if (r.preparationState === 'manifest-published' && !r.prepassReady) {
|
|
9669
9472
|
return 'Drawing preparation is complete and saved. Return to the same terminal AI session and tell it to continue creating the Drawing Filter. Do not start or copy this request again.';
|
|
@@ -9789,23 +9592,19 @@
|
|
|
9789
9592
|
// Drop the query WITH the box, and before anything is filtered by it: a hidden filter still
|
|
9790
9593
|
// filtering is how a list ends up inexplicably empty (the last two requests clear while a
|
|
9791
9594
|
// stale query is still narrowing).
|
|
9792
|
-
|
|
9793
|
-
|
|
9595
|
+
// Completed Request answers now publish into their owner-scoped AI Chat. Requests contains only
|
|
9596
|
+
// work still waiting for action; keeping a second answer-history surface here would split one
|
|
9597
|
+
// conversation across two places again.
|
|
9794
9598
|
if ($search) {
|
|
9795
|
-
$search.hidden = pendingRequests.length
|
|
9599
|
+
$search.hidden = pendingRequests.length < 2;
|
|
9796
9600
|
if ($search.hidden && requestQuery) { requestQuery = ''; $search.value = ''; }
|
|
9797
9601
|
}
|
|
9798
9602
|
const normalizedRequestQuery = requestQuery.trim();
|
|
9799
9603
|
const scope = activeRequestScope();
|
|
9800
9604
|
const inScope = visibleRequests(pendingRequests, scope, '', requestSearchText);
|
|
9801
9605
|
const shown = shownRequests(normalizedRequestQuery);
|
|
9802
|
-
const savedInScope = visibleRequests(continuations, scope, '', answerSessionSearchText);
|
|
9803
|
-
const savedAnswers = visibleRequests(
|
|
9804
|
-
continuations, requestScopeAll ? null : scope, normalizedRequestQuery, answerSessionSearchText,
|
|
9805
|
-
)
|
|
9806
|
-
.sort((a, b) => String(b.finishedAt || '').localeCompare(String(a.finishedAt || '')));
|
|
9807
9606
|
shownSnapshot = shown; // the bulk actions act on THIS paint — see the note on shownSnapshot
|
|
9808
|
-
const nothingQueued = pendingRequests.length === 0
|
|
9607
|
+
const nothingQueued = pendingRequests.length === 0;
|
|
9809
9608
|
|
|
9810
9609
|
// The scope tabs only earn their space when there is something to scope TO and something
|
|
9811
9610
|
// queued to scope. Counts live ON the tabs and explicitly say they count queued work;
|
|
@@ -9857,14 +9656,14 @@
|
|
|
9857
9656
|
: `Copy ${copyableShown.length} request${copyableShown.length === 1 ? '' : 's'} that still need to be started`);
|
|
9858
9657
|
}
|
|
9859
9658
|
|
|
9860
|
-
if (shown.length === 0
|
|
9659
|
+
if (shown.length === 0) {
|
|
9861
9660
|
// Three different nothings, and conflating them is what makes a filter feel broken: an
|
|
9862
9661
|
// empty queue, a queue with nothing for THIS project, and a search that missed.
|
|
9863
9662
|
const msg = nothingQueued
|
|
9864
9663
|
? 'No requests queued. Save a Template or ✎ Tweak a node to send a change to your terminal AI.'
|
|
9865
9664
|
: normalizedRequestQuery
|
|
9866
|
-
? `No request
|
|
9867
|
-
: `Nothing queued
|
|
9665
|
+
? `No request matches “${escapeHtml(normalizedRequestQuery)}”.${!requestScopeAll && inScope.length < pendingRequests.length ? ' Try All to search everything.' : ''}`
|
|
9666
|
+
: `Nothing queued for ${escapeHtml(scope ? scope.label : 'this')} — ${pendingRequests.length} item${pendingRequests.length === 1 ? '' : 's'} waiting elsewhere. <button type="button" class="req-showall">Show all</button>`;
|
|
9868
9667
|
$list.innerHTML = `<div class="empty-state">${msg}</div>`;
|
|
9869
9668
|
const $showAll = $list.querySelector('.req-showall');
|
|
9870
9669
|
if ($showAll) $showAll.onclick = () => setRequestScopeAll(true);
|
|
@@ -9937,57 +9736,86 @@
|
|
|
9937
9736
|
// `canRun` is server-owned policy, but persisted request JSON can outlive or be newer than this
|
|
9938
9737
|
// client. A revision lifecycle this build cannot name must never gain Start through a stale or
|
|
9939
9738
|
// malformed response; only the exact queued state is safe to launch.
|
|
9940
|
-
const
|
|
9739
|
+
const chatExecutionOwner = r.chatConversation?.executionOwner || null;
|
|
9740
|
+
const canRunNow = headlessReady() && r.canRun && (!chatExecutionOwner || chatExecutionOwner === 'discussion')
|
|
9741
|
+
&& (r.type !== 'revision-read' || r.status === 'pending')
|
|
9941
9742
|
&& !revisionReadHasTerminalOwner(r) && !inFlight && !desktopHandoffs && !resumeCommand;
|
|
9942
9743
|
const runBtn = inFlight
|
|
9943
9744
|
? `<button class="req-stop" data-id="${escapeAttr(r.id)}" data-command-id="shell.requests-stop#${escapeAttr(r.id)}" data-command-instance-label="${escapeAttr(commandInstance)}" data-tip="Stop this run" aria-label="Stop this run">■</button>`
|
|
9944
9745
|
: canRunNow
|
|
9945
9746
|
? r.preparationRetryable
|
|
9946
9747
|
? `<button class="req-run" data-id="${escapeAttr(r.id)}" data-command-id="shell.requests-retry#${escapeAttr(r.id)}" data-command-instance-label="${escapeAttr(commandInstance)}" aria-label="Retry preparation" data-tip="Retry Steel Filter preparation with the attached drawings">▶</button>`
|
|
9947
|
-
: `<button class="req-run" data-id="${escapeAttr(r.id)}" data-command-id="shell.requests-run#${escapeAttr(r.id)}" data-command-instance-label="${escapeAttr(commandInstance)}" aria-label="Start this request
|
|
9748
|
+
: `<button class="req-run" data-id="${escapeAttr(r.id)}" data-command-id="shell.requests-run#${escapeAttr(r.id)}" data-command-instance-label="${escapeAttr(commandInstance)}" aria-label="Start this request in the background" data-tip="Start this request in the background with your terminal AI">▶</button>`
|
|
9749
|
+
: '';
|
|
9750
|
+
const chatProvider = preferredChatProvider();
|
|
9751
|
+
const hasChatOwner = Boolean(r.project || r.workflowId);
|
|
9752
|
+
const inChatScope = hasChatOwner && requestMatchesChatScope(r);
|
|
9753
|
+
const chatLabel = `${label}${owner ? ` for ${owner}` : ''}`;
|
|
9754
|
+
const hasLinkedChat = Boolean(r.chatConversation?.chatId);
|
|
9755
|
+
const discussBtn = chatProvider && inChatScope
|
|
9756
|
+
? `<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>`
|
|
9757
|
+
: '';
|
|
9758
|
+
const startChatBtn = chatProvider && inChatScope && canRunNow
|
|
9759
|
+
? `<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">Start in AI Chat</button>`
|
|
9760
|
+
: '';
|
|
9761
|
+
const chatMeta = chatProvider && inChatScope
|
|
9762
|
+
? `<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>`
|
|
9763
|
+
: chatProvider && hasChatOwner
|
|
9764
|
+
? `<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>`
|
|
9948
9765
|
: '';
|
|
9949
9766
|
return `
|
|
9950
9767
|
<div class="req-item" data-id="${escapeAttr(r.id)}">
|
|
9951
9768
|
<div class="req-info">
|
|
9952
9769
|
<div class="req-head"><span class="${badgeCls}">${label}</span> ${owner ? `<span class="req-owner">${highlightQuery(owner, normalizedRequestQuery)}</span>` : ''}${time}</div>
|
|
9953
9770
|
${r.type === 'revision-read'
|
|
9954
|
-
? `<div class="req-instruction req-summary">${highlightQuery(requestSummary(r), normalizedRequestQuery)}</div><details class="req-technical"${normalizedRequestQuery && `${instructionFor(r)} ${r.preparationDiagnostic || ''}`.toLowerCase().includes(normalizedRequestQuery.toLowerCase()) ? ' open' : ''}><summary data-command-id="shell.requests-technical#${escapeAttr(r.id)}" data-command-instance-label="${escapeAttr(commandInstance)}">Show
|
|
9955
|
-
: `<div class="req-instruction">${highlightQuery(instructionFor(r), normalizedRequestQuery) || 'This request has no
|
|
9771
|
+
? `<div class="req-instruction req-summary">${highlightQuery(requestSummary(r), normalizedRequestQuery)}</div><details class="req-technical"${normalizedRequestQuery && `${instructionFor(r)} ${r.preparationDiagnostic || ''}`.toLowerCase().includes(normalizedRequestQuery.toLowerCase()) ? ' open' : ''}><summary data-command-id="shell.requests-technical#${escapeAttr(r.id)}" data-command-instance-label="${escapeAttr(commandInstance)}">Show detailed instructions</summary><div class="req-technical-body">${highlightQuery(`${instructionFor(r)}${r.preparationDiagnostic ? `\n\n${r.preparationDiagnostic}` : ''}`, normalizedRequestQuery)}</div></details>`
|
|
9772
|
+
: `<div class="req-instruction">${highlightQuery(instructionFor(r), normalizedRequestQuery) || 'This request has no instructions to send. Remove it and create the request again.'}</div>`}
|
|
9956
9773
|
${r.snapshots && r.snapshots.length ? `<div class="req-thumbs">${r.snapshots.map((sp, i) => { const pdf = /\.pdf$/i.test(String(sp)); return `<button type="button" class="req-thumb" data-id="${escapeAttr(r.id)}" data-n="${i}" aria-label="View ${pdf ? 'PDF' : 'screenshot'} ${i + 1}">${pdf ? '<span class="req-thumb-pdf">PDF</span>' : `<img src="/api/requests/${encodeURIComponent(r.id)}/snapshot/${i}" alt="">`}</button>`; }).join('')}</div>` : ''}
|
|
9957
9774
|
${runStatusHtml(run, resumeCommand, desktopHandoffs, r.id, commandInstance, ownRecoverySurface)}
|
|
9958
9775
|
${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>` : ''}
|
|
9959
9776
|
${auditRefusalHtml(r)}
|
|
9960
9777
|
</div>
|
|
9961
|
-
<div class="req-actions"
|
|
9778
|
+
<div class="req-actions">${chatMeta}
|
|
9779
|
+
${discussBtn}
|
|
9962
9780
|
${runBtn}
|
|
9963
9781
|
${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>`}
|
|
9964
9782
|
${del.replace('<button class="req-del"', '<button aria-label="Clear this request" class="req-del"')}
|
|
9783
|
+
${startChatBtn}
|
|
9965
9784
|
</div>
|
|
9966
9785
|
</div>`;
|
|
9967
9786
|
}).join('');
|
|
9968
|
-
|
|
9969
|
-
|
|
9970
|
-
|
|
9971
|
-
|
|
9972
|
-
|
|
9973
|
-
|
|
9974
|
-
|
|
9975
|
-
|
|
9976
|
-
|
|
9977
|
-
|
|
9978
|
-
|
|
9979
|
-
|
|
9980
|
-
|
|
9981
|
-
|
|
9982
|
-
${
|
|
9983
|
-
|
|
9984
|
-
})
|
|
9985
|
-
|
|
9986
|
-
|
|
9987
|
-
|
|
9988
|
-
|
|
9989
|
-
|
|
9990
|
-
|
|
9787
|
+
$list.innerHTML = queuedHtml;
|
|
9788
|
+
$list.querySelectorAll('[data-request-chat]').forEach((button) => {
|
|
9789
|
+
button.onclick = async () => {
|
|
9790
|
+
const request = pendingRequests.find((candidate) => candidate?.id === button.dataset.id);
|
|
9791
|
+
const provider = preferredChatProvider();
|
|
9792
|
+
if (!request || !provider || typeof window.flolessChat?.startRequest !== 'function') return;
|
|
9793
|
+
const original = button.textContent;
|
|
9794
|
+
button.disabled = true;
|
|
9795
|
+
button.setAttribute('aria-busy', 'true');
|
|
9796
|
+
button.textContent = button.dataset.requestChat === 'start' ? 'Starting…' : 'Opening…';
|
|
9797
|
+
const actionStatus = document.getElementById('requests-action-status');
|
|
9798
|
+
if (actionStatus) actionStatus.textContent = `${button.textContent} ${requestLabel(request)} for ${requestOwnerName(request)}.`;
|
|
9799
|
+
const slowTimer = setTimeout(() => {
|
|
9800
|
+
if (button.disabled && button.isConnected && actionStatus) {
|
|
9801
|
+
actionStatus.textContent = `Still opening ${requestLabel(request)} in AI Chat… FloLess is taking longer than expected.`;
|
|
9802
|
+
}
|
|
9803
|
+
}, 4000);
|
|
9804
|
+
try {
|
|
9805
|
+
await window.flolessChat.startRequest(request.id, provider, button.dataset.requestChat === 'start' ? 'start' : 'discuss');
|
|
9806
|
+
closeRequests();
|
|
9807
|
+
} catch (error) {
|
|
9808
|
+
reportErr(error);
|
|
9809
|
+
if (actionStatus) actionStatus.textContent = `Couldn’t ${button.dataset.requestChat === 'start' ? 'start' : 'open'} ${requestLabel(request)} in AI Chat. Try again.`;
|
|
9810
|
+
button.disabled = false;
|
|
9811
|
+
button.removeAttribute('aria-busy');
|
|
9812
|
+
button.textContent = original;
|
|
9813
|
+
button.focus();
|
|
9814
|
+
} finally {
|
|
9815
|
+
clearTimeout(slowTimer);
|
|
9816
|
+
}
|
|
9817
|
+
};
|
|
9818
|
+
});
|
|
9991
9819
|
$list.querySelectorAll('.req-run').forEach((b) => {
|
|
9992
9820
|
b.onclick = () => {
|
|
9993
9821
|
const r = pendingRequests.find((x) => x.id === b.dataset.id);
|
|
@@ -10009,10 +9837,15 @@
|
|
|
10009
9837
|
&& $list.__requestPaintOwner === paintOwner
|
|
10010
9838
|
&& !!modal?.classList.contains('show')
|
|
10011
9839
|
&& pendingRequests.some((candidate) => candidate && candidate.id === r.id);
|
|
10012
|
-
|
|
10013
|
-
|
|
10014
|
-
|
|
10015
|
-
|
|
9840
|
+
setCopyBusy(b, true);
|
|
9841
|
+
try {
|
|
9842
|
+
const res = await copyRequest(r, owns);
|
|
9843
|
+
if (res === 'stale' || !owns()) return;
|
|
9844
|
+
if (res === 'ok') showToast('Copied — paste it to your terminal AI', 'ok');
|
|
9845
|
+
else showToast(...copyFailToast(res));
|
|
9846
|
+
} finally {
|
|
9847
|
+
setCopyBusy(b, false);
|
|
9848
|
+
}
|
|
10016
9849
|
};
|
|
10017
9850
|
});
|
|
10018
9851
|
$list.querySelectorAll('.req-run-resume-command').forEach((b) => {
|
|
@@ -10334,6 +10167,7 @@
|
|
|
10334
10167
|
agentCatalog = agents;
|
|
10335
10168
|
const $ac = document.getElementById('agents-count');
|
|
10336
10169
|
if ($ac) $ac.textContent = agents.length;
|
|
10170
|
+
refreshAgentNotes();
|
|
10337
10171
|
}
|
|
10338
10172
|
|
|
10339
10173
|
openLibrary = function openLibraryReal() {
|
|
@@ -10610,9 +10444,13 @@
|
|
|
10610
10444
|
// take a minute — it downloads from the registry) and reports completion over SSE
|
|
10611
10445
|
// (`agent-install-result`), so we DON'T await it here — that's what made the button
|
|
10612
10446
|
// look hung. We flip the card to "Installing…" and let the SSE handler finish it.
|
|
10613
|
-
function installAgent(id, btn) {
|
|
10614
|
-
|
|
10447
|
+
function installAgent(id, btn, appId) {
|
|
10448
|
+
const sourceHash = appId ? apps.get(appId)?.source?.hash : undefined;
|
|
10449
|
+
const key = appId ? workflowAgentKey(id, appId, sourceHash) : null;
|
|
10450
|
+
if (key ? pendingWorkflowAgentInstalls.has(key) : installingIds.has(id)) return;
|
|
10615
10451
|
installingIds.add(id);
|
|
10452
|
+
if (key) { pendingWorkflowAgentInstalls.set(key, id); missingAgentFailures.delete(key); completedAgentInstalls.delete(key); }
|
|
10453
|
+
refreshAgentNotes();
|
|
10616
10454
|
const a = availableCatalog.find((x) => x.id === id);
|
|
10617
10455
|
const nice = a && a.display_name ? a.display_name : id;
|
|
10618
10456
|
if (btn) { // immediate feedback before the next render
|
|
@@ -10622,9 +10460,10 @@
|
|
|
10622
10460
|
btn.innerHTML = '<span class="rtn-spinner"></span>';
|
|
10623
10461
|
}
|
|
10624
10462
|
showToast(`Installing “${nice}” — this can take a minute or two`, 'info');
|
|
10625
|
-
api('/api/agents/install', { method: 'POST', body: JSON.stringify({ id }) })
|
|
10463
|
+
api('/api/agents/install', { method: 'POST', body: JSON.stringify({ id, ...(appId ? { appId, sourceHash } : {}) }) })
|
|
10626
10464
|
.catch((e) => { // the START failed (bad id / server) — completion errors arrive via SSE
|
|
10627
|
-
|
|
10465
|
+
recordAgentInstallResult({ id, appId, sourceHash, ok: false, error: e.message || 'Please try again.' });
|
|
10466
|
+
refreshAgentNotes();
|
|
10628
10467
|
if ($libModal && $libModal.classList.contains('show')) renderAvailable();
|
|
10629
10468
|
reportErr(e);
|
|
10630
10469
|
});
|
|
@@ -10700,15 +10539,38 @@
|
|
|
10700
10539
|
// ── Integrations: real connection state from the local vault ────────────────
|
|
10701
10540
|
const VENDOR_ICON = { microsoft: '▦', google: 'G', trimble: '◬', autodesk: 'A' };
|
|
10702
10541
|
let integrations = [];
|
|
10542
|
+
let integrationsLoadState = 'idle';
|
|
10543
|
+
let integrationsLoadError = '';
|
|
10703
10544
|
let runtimeSectionExpanded = false;
|
|
10545
|
+
let pendingIntegrationFocus = '';
|
|
10704
10546
|
|
|
10705
|
-
openIntegrations = function openIntegrationsReal() {
|
|
10547
|
+
openIntegrations = function openIntegrationsReal(focusId) {
|
|
10548
|
+
pendingIntegrationFocus = typeof focusId === 'string' ? focusId : '';
|
|
10706
10549
|
$integrationsModal.classList.add('show');
|
|
10707
|
-
|
|
10708
|
-
refreshIntegrations();
|
|
10550
|
+
void refreshIntegrations().then(focusPendingIntegration);
|
|
10709
10551
|
refreshHeadless().then(renderRuntimeSection);
|
|
10710
10552
|
};
|
|
10711
10553
|
|
|
10554
|
+
function focusPendingIntegration() {
|
|
10555
|
+
if (!pendingIntegrationFocus || !$integrationsModal.classList.contains('show')) return;
|
|
10556
|
+
const id = (window.CSS && CSS.escape) ? CSS.escape(pendingIntegrationFocus) : pendingIntegrationFocus;
|
|
10557
|
+
const row = $integrationsList.querySelector(`[data-integration-id="${id}"]`);
|
|
10558
|
+
if (!row) return;
|
|
10559
|
+
const target = row.querySelector('button:not([hidden])') || row;
|
|
10560
|
+
row.scrollIntoView({ block: 'nearest' });
|
|
10561
|
+
target.focus({ preventScroll: true });
|
|
10562
|
+
pendingIntegrationFocus = '';
|
|
10563
|
+
}
|
|
10564
|
+
|
|
10565
|
+
window.addEventListener('floless:open-revit-access', async (event) => {
|
|
10566
|
+
if (event.detail?.state === 'account-selection-required') {
|
|
10567
|
+
await recheckLicenseAndGate({ forRevitAccountSelection: true });
|
|
10568
|
+
window.dispatchEvent(new CustomEvent('floless:revit-capability-changed'));
|
|
10569
|
+
return;
|
|
10570
|
+
}
|
|
10571
|
+
openIntegrations('xeorvt');
|
|
10572
|
+
});
|
|
10573
|
+
|
|
10712
10574
|
function runtimeSectionSummary(runtimes, active, folder) {
|
|
10713
10575
|
const installed = runtimes.filter((runtime) => runtime.state === 'found');
|
|
10714
10576
|
const selected = installed.find((runtime) => runtime.id === active);
|
|
@@ -10723,7 +10585,7 @@
|
|
|
10723
10585
|
const $body = document.getElementById('int-runtimes-body');
|
|
10724
10586
|
if (!$toggle || !$body) return;
|
|
10725
10587
|
$toggle.setAttribute('aria-expanded', String(runtimeSectionExpanded));
|
|
10726
|
-
$toggle.setAttribute('data-tip', `${runtimeSectionExpanded ? 'Collapse' : 'Expand'}
|
|
10588
|
+
$toggle.setAttribute('data-tip', `${runtimeSectionExpanded ? 'Collapse' : 'Expand'} background run settings`);
|
|
10727
10589
|
$body.hidden = !runtimeSectionExpanded;
|
|
10728
10590
|
}
|
|
10729
10591
|
|
|
@@ -10802,8 +10664,8 @@
|
|
|
10802
10664
|
let sub = '';
|
|
10803
10665
|
for (;;) {
|
|
10804
10666
|
const res = await formModal({
|
|
10805
|
-
title: sub ? 'That folder won’t work' : 'Folder for
|
|
10806
|
-
sub: sub || 'Where
|
|
10667
|
+
title: sub ? 'That folder won’t work' : 'Folder for background runs',
|
|
10668
|
+
sub: sub || 'Where FloLess starts your AI provider when it runs a request for you. Individual projects can use their own folder.',
|
|
10807
10669
|
fields: [{ name: 'folder', label: 'Folder', value: folder, placeholder: 'C:\\Repos\\my-project' }],
|
|
10808
10670
|
footnote: 'Your terminal AI reads and edits this folder unattended, including any instructions it finds in files there. Point it at a folder you trust — and open your own terminal in the same folder later to pick a session up.',
|
|
10809
10671
|
okLabel: 'Save',
|
|
@@ -10822,32 +10684,131 @@
|
|
|
10822
10684
|
// Re-fetch live connection state from the local vault; re-render if the modal
|
|
10823
10685
|
// is open. Called on open and whenever a credential file changes (SSE), so an
|
|
10824
10686
|
// open window flips to Connected the moment `aware connect` writes the token.
|
|
10825
|
-
function refreshIntegrations() {
|
|
10687
|
+
function refreshIntegrations(announcement = '') {
|
|
10688
|
+
integrationsLoadState = 'loading';
|
|
10689
|
+
integrationsLoadError = '';
|
|
10690
|
+
if ($integrationsModal.classList.contains('show')) renderIntegrations();
|
|
10826
10691
|
return api('/api/integrations')
|
|
10827
10692
|
.then(({ integrations: list }) => {
|
|
10828
|
-
integrations = list;
|
|
10829
|
-
|
|
10693
|
+
integrations = Array.isArray(list) ? list : [];
|
|
10694
|
+
integrationsLoadState = 'loaded';
|
|
10695
|
+
if ($integrationsModal.classList.contains('show')) {
|
|
10696
|
+
renderIntegrations();
|
|
10697
|
+
if (announcement) document.getElementById('integrations-status').textContent = announcement;
|
|
10698
|
+
}
|
|
10699
|
+
window.dispatchEvent(new CustomEvent('floless:revit-capability-changed'));
|
|
10830
10700
|
})
|
|
10831
|
-
.catch(
|
|
10701
|
+
.catch((error) => {
|
|
10702
|
+
integrationsLoadState = 'failed';
|
|
10703
|
+
integrationsLoadError = error instanceof Error ? error.message : String(error);
|
|
10704
|
+
if ($integrationsModal.classList.contains('show')) renderIntegrations();
|
|
10705
|
+
reportErr(error);
|
|
10706
|
+
});
|
|
10707
|
+
}
|
|
10708
|
+
|
|
10709
|
+
function renderIntegrationAccounts(integration) {
|
|
10710
|
+
const slots = Array.isArray(integration.accountSlots) ? integration.accountSlots : [];
|
|
10711
|
+
if (!slots.length) return integration.chatSupported
|
|
10712
|
+
? `<div class="int-accounts"><div class="int-accounts-label">FLOLESS INTEGRATIONS</div><div class="int-account-empty">No FloLess account connected · Connect to use with AI Chat.</div></div>`
|
|
10713
|
+
: '';
|
|
10714
|
+
return `<div class="int-accounts" aria-label="FloLess integration accounts"><div class="int-accounts-label">FLOLESS INTEGRATIONS</div>${slots.map((slot) => {
|
|
10715
|
+
const principal = slot.verifiedPrincipal;
|
|
10716
|
+
const verified = principal != null;
|
|
10717
|
+
const supported = integration.chatSupported === true;
|
|
10718
|
+
const account = principal?.presentationLabel
|
|
10719
|
+
|| (principal?.stableId ? `Account ID · ${principal.stableId}` : verified ? 'Verified account' : 'Unverified account');
|
|
10720
|
+
const slotName = slot.alias ? `FloLess connection · ${slot.alias}` : 'Default FloLess account';
|
|
10721
|
+
// One precedence order for the badge and its explanation, so they can never contradict each
|
|
10722
|
+
// other: an integration AI Chat cannot use says so whatever the account's own state is.
|
|
10723
|
+
const ready = supported && slot.status === 'valid' && slot.callable === true && verified;
|
|
10724
|
+
let state = 'Unavailable in AI Chat';
|
|
10725
|
+
let stateClass = 'is-chat-unavailable';
|
|
10726
|
+
let why;
|
|
10727
|
+
if (!supported) { state = 'Not available in AI Chat'; why = 'AI Chat can’t use this integration yet.'; }
|
|
10728
|
+
else if (ready) { state = 'Ready for AI Chat'; stateClass = 'is-chat-ready'; why = 'This verified account can be selected in AI Chat.'; }
|
|
10729
|
+
else if (slot.status === 'expired') { state = 'Reconnect for AI Chat'; stateClass = 'is-chat-warning'; why = 'This account’s sign-in has expired. Reconnect it to use it in AI Chat.'; }
|
|
10730
|
+
else if (slot.status !== 'valid') { state = 'Connect for AI Chat'; stateClass = 'is-chat-warning'; }
|
|
10731
|
+
else if (!verified) { state = 'Reconnect to verify account'; stateClass = 'is-chat-warning'; why = 'FloLess could not verify this account. Reconnect it to use it in AI Chat.'; }
|
|
10732
|
+
if (!why) {
|
|
10733
|
+
// A server reason is shown only when it is ordinary language; internal wording gets the plain fallback.
|
|
10734
|
+
const raw = slot.unavailableReason || '';
|
|
10735
|
+
why = raw && !/identity|stableid|binding|registry|verify|principal|capability|operation|aware/i.test(raw)
|
|
10736
|
+
? raw : 'This account is not ready for AI Chat.';
|
|
10737
|
+
}
|
|
10738
|
+
return `<div class="int-account ${stateClass}">
|
|
10739
|
+
<div class="int-account-copy">
|
|
10740
|
+
<span class="int-account-name">${escapeHtml(account)}</span>
|
|
10741
|
+
<span class="int-account-origin">${escapeHtml(slotName)}</span>
|
|
10742
|
+
</div>
|
|
10743
|
+
<span class="int-chat-state">${state}</span>
|
|
10744
|
+
<span class="int-account-reason">${escapeHtml(why)}</span>
|
|
10745
|
+
</div>`;
|
|
10746
|
+
}).join('')}</div>`;
|
|
10832
10747
|
}
|
|
10833
10748
|
|
|
10834
10749
|
renderIntegrations = function renderIntegrationsReal() {
|
|
10750
|
+
if (integrationsLoadState === 'loading' || integrationsLoadState === 'idle') {
|
|
10751
|
+
$integrationsList.innerHTML = '<div class="empty-state">Checking integrations…</div>';
|
|
10752
|
+
return;
|
|
10753
|
+
}
|
|
10754
|
+
if (integrationsLoadState === 'failed') {
|
|
10755
|
+
$integrationsList.innerHTML = '<div class="empty-state int-load-failed"><span>FloLess couldn’t load your integration accounts. Check that FloLess is online, then try again.</span><button class="int-action" id="integrations-retry" data-command-id="shell.integrations-retry">Try again</button></div>';
|
|
10756
|
+
document.getElementById('integrations-retry').onclick = () => { void refreshIntegrations(); };
|
|
10757
|
+
return;
|
|
10758
|
+
}
|
|
10835
10759
|
if (!integrations.length) {
|
|
10836
|
-
$integrationsList.innerHTML = '<div class="empty-state">
|
|
10760
|
+
$integrationsList.innerHTML = '<div class="empty-state">No integrations are available on this machine.</div>';
|
|
10837
10761
|
return;
|
|
10838
10762
|
}
|
|
10839
10763
|
$integrationsList.innerHTML = integrations.map((i) => {
|
|
10764
|
+
if (i.kind === 'model-provider') {
|
|
10765
|
+
const ready = i.status === 'ready';
|
|
10766
|
+
const needsAttention = i.status === 'needs-attention';
|
|
10767
|
+
const needsAccount = i.status === 'account-selection-required';
|
|
10768
|
+
const checkUnavailable = i.status === 'check-unavailable';
|
|
10769
|
+
const setupDetails = {
|
|
10770
|
+
'aware-unavailable': 'FloLess couldn’t start the service used by Revit projects.',
|
|
10771
|
+
'core-workflow-provisioning': 'FloLess couldn’t prepare the built-in Workspace workflows.',
|
|
10772
|
+
'reader-verification': 'FloLess couldn’t verify the installed Revit reader.',
|
|
10773
|
+
'workspace-bootstrap': 'FloLess couldn’t prepare the Workspace connection used by Revit workflows.',
|
|
10774
|
+
'revit-workflow-provisioning': 'FloLess couldn’t prepare the Revit project workflows.',
|
|
10775
|
+
unknown: 'FloLess couldn’t finish Revit setup.',
|
|
10776
|
+
};
|
|
10777
|
+
const badge = ready ? 'Ready' : needsAttention ? 'Needs setup'
|
|
10778
|
+
: needsAccount ? 'Choose an account' : checkUnavailable ? 'Couldn’t check access' : 'Revit access required';
|
|
10779
|
+
const detail = ready
|
|
10780
|
+
? 'Open your Revit projects and use their model data in FloLess workflows.'
|
|
10781
|
+
: needsAttention
|
|
10782
|
+
? (setupDetails[i.setup && i.setup.category] || setupDetails.unknown)
|
|
10783
|
+
: needsAccount
|
|
10784
|
+
? 'Choose the FloLess account you want to use before opening Revit projects.'
|
|
10785
|
+
: checkUnavailable
|
|
10786
|
+
? 'FloLess couldn’t check Revit access. Check your connection and try again.'
|
|
10787
|
+
: 'Revit model access is not included for this account. Ask the account owner to add it.';
|
|
10788
|
+
const checkLabel = needsAttention ? 'Try setup again' : needsAccount ? 'Choose account'
|
|
10789
|
+
: ready ? 'Check status' : 'Check access again';
|
|
10790
|
+
return `<div class="int-item int-${escapeAttr(i.status)}" data-integration-id="xeorvt" tabindex="-1">
|
|
10791
|
+
<div class="int-icon">R</div><div class="int-info">
|
|
10792
|
+
<div class="int-name">${escapeHtml(i.name)}</div>
|
|
10793
|
+
<div class="int-kind">Revit project integration · provided by FloLess</div>
|
|
10794
|
+
<div class="int-scopes">${escapeHtml(detail)}</div>
|
|
10795
|
+
<div class="int-row"><span class="int-badge int-badge-${ready ? 'connected' : needsAttention ? 'expired' : 'disconnected'}">${badge}</span>
|
|
10796
|
+
${ready ? '<button class="int-action" data-xeorvt-action="open">Open Revit projects</button>' : ''}
|
|
10797
|
+
<button class="int-action" data-xeorvt-action="${needsAccount ? 'account' : 'check'}" data-xeorvt-retry="${needsAttention ? 'true' : 'false'}">${checkLabel}</button>
|
|
10798
|
+
</div></div></div>`;
|
|
10799
|
+
}
|
|
10840
10800
|
const action = i.status === 'connected' ? 'Disconnect' : i.status === 'expired' ? 'Reconnect' : 'Connect';
|
|
10841
10801
|
const badge = i.status === 'connected' ? 'Connected' : i.status === 'expired' ? 'Token expired' : 'Not connected';
|
|
10842
10802
|
const meta = i.status === 'disconnected' ? '—' : i.expiresAt ? `expires ${new Date(i.expiresAt).toLocaleString()}` : 'connected';
|
|
10843
10803
|
return `
|
|
10844
10804
|
<div class="int-item int-${i.status}">
|
|
10845
|
-
<div class="int-icon">${escapeHtml(VENDOR_ICON[i.vendor] || (i.name[0] || '?'))}</div>
|
|
10805
|
+
<div class="int-icon" aria-hidden="true">${escapeHtml(VENDOR_ICON[i.vendor] || (i.name[0] || '?'))}</div>
|
|
10846
10806
|
<div class="int-info">
|
|
10847
10807
|
<div class="int-name">${escapeHtml(i.name)}</div>
|
|
10848
10808
|
<div class="int-kind">${i.agent === 'first-party' ? 'Built-in integration' : `${escapeHtml(i.vendor || 'integration')} · agent <code>${escapeHtml(i.agent)}</code>`}</div>
|
|
10849
10809
|
<div class="int-scopes">${escapeHtml((i.network || []).join(' · ') || '—')}</div>
|
|
10850
10810
|
<div class="int-meta">${escapeHtml(meta)}</div>
|
|
10811
|
+
${renderIntegrationAccounts(i)}
|
|
10851
10812
|
<div class="int-row">
|
|
10852
10813
|
<span class="int-badge int-badge-${i.status}">${badge}</span>
|
|
10853
10814
|
<button class="int-action" data-int="${escapeAttr(i.id)}" data-int-action="${action.toLowerCase()}">${action}</button>
|
|
@@ -10860,7 +10821,31 @@
|
|
|
10860
10821
|
</div>
|
|
10861
10822
|
</div>`;
|
|
10862
10823
|
}).join('');
|
|
10863
|
-
$integrationsList.querySelectorAll('
|
|
10824
|
+
$integrationsList.querySelectorAll('[data-xeorvt-action]').forEach((btn) => {
|
|
10825
|
+
btn.onclick = async () => {
|
|
10826
|
+
if (btn.dataset.xeorvtAction === 'open') {
|
|
10827
|
+
$integrationsModal.classList.remove('show');
|
|
10828
|
+
if (window.flolessWorkspaces) await window.flolessWorkspaces.setMode('workspaces');
|
|
10829
|
+
} else if (btn.dataset.xeorvtAction === 'account') {
|
|
10830
|
+
await recheckLicenseAndGate({ forRevitAccountSelection: true });
|
|
10831
|
+
} else {
|
|
10832
|
+
if (btn.dataset.xeorvtRetry === 'true') {
|
|
10833
|
+
const hadFocus = document.activeElement === btn;
|
|
10834
|
+
btn.disabled = true;
|
|
10835
|
+
btn.textContent = 'Setting up…';
|
|
10836
|
+
try { await api('/api/rvt-defaults/retry', { method: 'POST' }); }
|
|
10837
|
+
catch { showToast('Revit setup couldn’t finish. Try setup again.', 'warn'); }
|
|
10838
|
+
await refreshIntegrations();
|
|
10839
|
+
if (hadFocus) $integrationsList.querySelector('[data-integration-id="xeorvt"] [data-xeorvt-action]:last-of-type')?.focus();
|
|
10840
|
+
return;
|
|
10841
|
+
} else {
|
|
10842
|
+
try { await api('/api/license/status'); } catch { /* refreshIntegrations shows the current safe state */ }
|
|
10843
|
+
}
|
|
10844
|
+
await refreshIntegrations();
|
|
10845
|
+
}
|
|
10846
|
+
};
|
|
10847
|
+
});
|
|
10848
|
+
$integrationsList.querySelectorAll('.int-action[data-int]').forEach((btn) => {
|
|
10864
10849
|
btn.onclick = async () => {
|
|
10865
10850
|
// Connect/Reconnect drive the device-code sign-in IN the app (AWARE owns
|
|
10866
10851
|
// the OAuth + token storage; we only show the code + reflect the result —
|
|
@@ -11245,9 +11230,9 @@
|
|
|
11245
11230
|
$reportSub.textContent = 'Live run blocked — a watcher already holds this host.';
|
|
11246
11231
|
showToast('Blocked — stop the active watcher in ⏱ Routines first', 'warn');
|
|
11247
11232
|
} else {
|
|
11248
|
-
$reportOverlay.append(mkEl('div', null,
|
|
11233
|
+
$reportOverlay.append(mkEl('div', null, 'We couldn’t start the live session because FloLess could not reach the host. Check that Tekla is open, then click ▶ Run workflow to try again.'));
|
|
11249
11234
|
$reportSub.textContent = 'Live session failed to start.';
|
|
11250
|
-
showToast('
|
|
11235
|
+
showToast('This live run stopped because FloLess could not finish it. Reopen the run, then try again.', 'warn');
|
|
11251
11236
|
}
|
|
11252
11237
|
} finally {
|
|
11253
11238
|
foregroundStarting = false;
|
|
@@ -11270,10 +11255,10 @@
|
|
|
11270
11255
|
$reportShare.hidden = true; // the error overlay is the primary content now
|
|
11271
11256
|
$reportOverlay.hidden = false;
|
|
11272
11257
|
$reportOverlay.replaceChildren();
|
|
11273
|
-
$reportOverlay.append(mkEl('div', null,
|
|
11258
|
+
$reportOverlay.append(mkEl('div', null, 'This live session ended because FloLess lost contact with the host. Check that Tekla is open and the workflow is compiled, then click ▶ Run workflow to try again.'));
|
|
11274
11259
|
$reportSub.textContent = 'Live session error.';
|
|
11275
11260
|
}
|
|
11276
|
-
showToast('
|
|
11261
|
+
showToast('This live session ended because FloLess lost contact with it. Reopen the session, then try again.', 'warn');
|
|
11277
11262
|
syncRunControls();
|
|
11278
11263
|
return;
|
|
11279
11264
|
}
|
|
@@ -11554,6 +11539,12 @@
|
|
|
11554
11539
|
applyRoutineModeAvailability(); // reveal/hide the schedule-vs-trigger chooser
|
|
11555
11540
|
const inps = (app && app.inputs) || [];
|
|
11556
11541
|
if (!inps.length) return;
|
|
11542
|
+
let routineModelRevisions = { projects: [], error: null };
|
|
11543
|
+
if (inps.some((inp) => inp.widget === 'workspace-model-revision')) {
|
|
11544
|
+
const bootstrap = await bootstrapEditorSession();
|
|
11545
|
+
routineModelRevisions = bootstrap.ok ? await fetchApprovedModelRevisions() : unavailableModelRevisionResult(bootstrap.error);
|
|
11546
|
+
if (document.getElementById('rtn-workflow').value !== workflowId) return;
|
|
11547
|
+
}
|
|
11557
11548
|
$field.hidden = false;
|
|
11558
11549
|
// The DOM id is index-based (not the workflow-controlled input name) so a crafted
|
|
11559
11550
|
// input name can't inject into the id/for attributes. The real key rides the
|
|
@@ -11561,10 +11552,47 @@
|
|
|
11561
11552
|
$inputs.innerHTML = inps.map((inp, i) => {
|
|
11562
11553
|
const id = `rtn-in-${i}`;
|
|
11563
11554
|
const val = prefill && inp.name in prefill ? prefill[inp.name] : (inp.default != null ? inp.default : '');
|
|
11555
|
+
if (inp.widget === 'workspace-model-revision') {
|
|
11556
|
+
const choices = routineModelRevisions.projects.slice().sort((a, b) => String(a.name).localeCompare(String(b.name))).flatMap((project) => {
|
|
11557
|
+
const selection = (extra) => JSON.stringify({ schemaVersion: 'floless.workspace-model-selection/v1', projectUuid: project.projectUuid, ...extra });
|
|
11558
|
+
const exact = project.versions.slice().sort((a, b) => Number(b.approvalVersion) - Number(a.approvalVersion)).map((version) => ({
|
|
11559
|
+
value: selection({ approvedRevisionId: version.approvedRevisionId, approvalVersion: version.approvalVersion }),
|
|
11560
|
+
group: project.name, groupMeta: 'Revit model', label: `Approved v${version.approvalVersion}`,
|
|
11561
|
+
meta: version.approvedAt ? new Date(version.approvedAt).toLocaleDateString() : 'Date unavailable',
|
|
11562
|
+
}));
|
|
11563
|
+
return [...exact, { value: selection({ latestApproved: true }), group: project.name, groupMeta: 'Revit model', label: 'Latest approved', meta: 'updates when approvals change' }];
|
|
11564
|
+
});
|
|
11565
|
+
const selected = choices.find((choice) => String(choice.value) === String(val));
|
|
11566
|
+
return `<div class="modal-field"><label>Revit model</label><div class="field-help">Choose the Workspace project and approved revision this scheduled run will read.</div>`
|
|
11567
|
+
+ `<input type="hidden" data-rtn-in="${escapeAttr(inp.name)}" value="${escapeAttr(String(val))}">`
|
|
11568
|
+
+ `<button type="button" class="fm-combo-trigger" data-rtn-model-picker="${escapeAttr(inp.name)}">${escapeHtml(selected ? `${selected.group} · ${selected.label}` : 'Choose a Revit model…')}</button></div>`;
|
|
11569
|
+
}
|
|
11564
11570
|
const type = inp.type === 'integer' || inp.type === 'number' ? 'number' : 'text';
|
|
11565
11571
|
return `<div class="modal-field"><label for="${id}">${escapeHtml(inp.name)}${inp.description ? ' — ' + escapeHtml(inp.description) : ''}</label>`
|
|
11566
11572
|
+ `<input id="${id}" type="${type}" data-rtn-in="${escapeAttr(inp.name)}" value="${escapeAttr(String(val))}"></div>`;
|
|
11567
11573
|
}).join('');
|
|
11574
|
+
$inputs.querySelectorAll('[data-rtn-model-picker]').forEach((button) => {
|
|
11575
|
+
button.onclick = async () => {
|
|
11576
|
+
const name = button.dataset.rtnModelPicker;
|
|
11577
|
+
const input = $inputs.querySelector(`[data-rtn-in="${CSS.escape(name)}"]`);
|
|
11578
|
+
const choices = routineModelRevisions.projects.slice().sort((a, b) => String(a.name).localeCompare(String(b.name))).flatMap((project) => {
|
|
11579
|
+
const selection = (extra) => JSON.stringify({ schemaVersion: 'floless.workspace-model-selection/v1', projectUuid: project.projectUuid, ...extra });
|
|
11580
|
+
return [...project.versions.slice().sort((a, b) => Number(b.approvalVersion) - Number(a.approvalVersion)).map((version) => ({
|
|
11581
|
+
value: selection({ approvedRevisionId: version.approvedRevisionId, approvalVersion: version.approvalVersion }), group: project.name,
|
|
11582
|
+
groupMeta: 'Revit model', label: `Approved v${version.approvalVersion}`, meta: version.approvedAt ? new Date(version.approvedAt).toLocaleDateString() : 'Date unavailable',
|
|
11583
|
+
})), { value: selection({ latestApproved: true }), group: project.name, groupMeta: 'Revit model', label: 'Latest approved', meta: 'updates when approvals change' }];
|
|
11584
|
+
});
|
|
11585
|
+
const picked = await formModal({ title: 'Choose Revit model', sub: 'Select a Workspace project and the approved revision this routine will read.', fields: [{
|
|
11586
|
+
name: 'selection', label: 'Revit model', type: 'select', options: choices, value: input.value, required: true,
|
|
11587
|
+
placeholder: 'Select an approved model version…', disabledLabel: 'Approve a Revit model first',
|
|
11588
|
+
emptyNote: 'No approved Revit model is available — open <strong>Workspaces</strong>, import a Revit project, and Approve it first.',
|
|
11589
|
+
}], okLabel: 'Use this model' });
|
|
11590
|
+
if (!picked) return;
|
|
11591
|
+
input.value = picked.selection;
|
|
11592
|
+
const choice = choices.find((row) => row.value === picked.selection);
|
|
11593
|
+
button.textContent = choice ? `${choice.group} · ${choice.label}` : 'Choose a Revit model…';
|
|
11594
|
+
};
|
|
11595
|
+
});
|
|
11568
11596
|
}
|
|
11569
11597
|
function collectRoutineInputs() {
|
|
11570
11598
|
const out = {};
|
|
@@ -11582,7 +11610,7 @@
|
|
|
11582
11610
|
const $wf = document.getElementById('rtn-workflow');
|
|
11583
11611
|
try {
|
|
11584
11612
|
const { apps: list } = await api('/api/apps');
|
|
11585
|
-
editWorkflows = list;
|
|
11613
|
+
editWorkflows = list.filter((a) => a.execution !== 'internal');
|
|
11586
11614
|
} catch { editWorkflows = []; }
|
|
11587
11615
|
$wf.innerHTML = editWorkflows.map((a) => `<option value="${escapeAttr(a.id)}">${escapeHtml(a.id)}</option>`).join('');
|
|
11588
11616
|
document.getElementById('rtn-edit-title').textContent = r ? 'Edit routine' : 'New routine';
|
|
@@ -11650,7 +11678,7 @@
|
|
|
11650
11678
|
}
|
|
11651
11679
|
hideModal($routineEditModal);
|
|
11652
11680
|
await loadRoutinesData();
|
|
11653
|
-
} catch (e) { showToast(
|
|
11681
|
+
} catch (e) { showToast('We couldn’t save this routine because FloLess could not save the change. Try again.', 'err'); }
|
|
11654
11682
|
}
|
|
11655
11683
|
|
|
11656
11684
|
openRoutines = function openRoutinesReal() {
|
|
@@ -11924,6 +11952,20 @@
|
|
|
11924
11952
|
// collapsed pill re-expands. Delegated (the strip's innerHTML is rebuilt each
|
|
11925
11953
|
// load). The choice is remembered per app+note-signature (see notesSig).
|
|
11926
11954
|
$notesStrip.addEventListener('click', (e) => {
|
|
11955
|
+
const install = e.target.closest('[data-note-install]');
|
|
11956
|
+
if (install) {
|
|
11957
|
+
if (!install.disabled) installAgent(install.dataset.noteInstall, undefined, currentId);
|
|
11958
|
+
return;
|
|
11959
|
+
}
|
|
11960
|
+
if (e.target.closest('[data-note-install-all]')) {
|
|
11961
|
+
const app = apps.get(currentId);
|
|
11962
|
+
if (!app) return;
|
|
11963
|
+
const installed = installedIdSet();
|
|
11964
|
+
for (const id of missingAgentGroups(app.notes).keys()) {
|
|
11965
|
+
if (missingAgentFailures.has(workflowAgentKey(id)) || (!installed.has(id) && !completedAgentInstalls.has(workflowAgentKey(id)))) installAgent(id, undefined, app.id);
|
|
11966
|
+
}
|
|
11967
|
+
return;
|
|
11968
|
+
}
|
|
11927
11969
|
if (e.target.closest('.notes-dismiss')) $notesStrip.classList.add('collapsed');
|
|
11928
11970
|
else if ($notesStrip.classList.contains('collapsed')) $notesStrip.classList.remove('collapsed');
|
|
11929
11971
|
else return; // click inside the expanded body — nothing to toggle
|
|
@@ -11999,6 +12041,7 @@
|
|
|
11999
12041
|
const $requestHelpOpen = document.getElementById('request-help-open');
|
|
12000
12042
|
const $requestHelpKeep = document.getElementById('request-help-keep');
|
|
12001
12043
|
const $requestHelpCopy = document.getElementById('request-help-copy');
|
|
12044
|
+
const $requestHelpChat = document.getElementById('request-help-chat');
|
|
12002
12045
|
if ($requestHelpOpen) $requestHelpOpen.onclick = () => {
|
|
12003
12046
|
// Read the id BEFORE closing — this button means "take me to the one I just queued", and only
|
|
12004
12047
|
// this entry point knows which that is.
|
|
@@ -12012,31 +12055,64 @@
|
|
|
12012
12055
|
const req = requestHelpReq;
|
|
12013
12056
|
if (!req) return;
|
|
12014
12057
|
// Via copyRequest, so an instruction-less type says so rather than "copy failed".
|
|
12015
|
-
|
|
12016
|
-
|
|
12017
|
-
|
|
12018
|
-
|
|
12019
|
-
|
|
12020
|
-
|
|
12021
|
-
|
|
12022
|
-
|
|
12023
|
-
|
|
12024
|
-
|
|
12025
|
-
|
|
12026
|
-
|
|
12027
|
-
$requestHelpCopy.hidden = true;
|
|
12028
|
-
|
|
12029
|
-
|
|
12058
|
+
setCopyBusy($requestHelpCopy, true);
|
|
12059
|
+
try {
|
|
12060
|
+
const res = await copyRequest(req, () => requestHelpReq === req);
|
|
12061
|
+
// Revalidation adds a real network wait. The modal may have closed or been reused for another
|
|
12062
|
+
// upload while it was in flight; only the request that initiated Copy may consume its result.
|
|
12063
|
+
if (requestHelpReq !== req) return;
|
|
12064
|
+
const copied = res === 'ok';
|
|
12065
|
+
if (copied) showToast('Copied — paste it to your terminal AI', 'ok');
|
|
12066
|
+
else showToast(...copyFailToast(res));
|
|
12067
|
+
// 'denied' keeps the button — a clipboard permission is worth retrying. 'empty' hides it exactly
|
|
12068
|
+
// as success does: there is no instruction body, so no number of clicks will ever produce one, and
|
|
12069
|
+
// leaving Copy there offers a retry that cannot succeed.
|
|
12070
|
+
if (res === 'empty') $requestHelpCopy.hidden = true;
|
|
12071
|
+
if (copied) {
|
|
12072
|
+
requestHelpCopied = true;
|
|
12073
|
+
$requestHelpCopy.hidden = true;
|
|
12074
|
+
const $sub = document.getElementById('request-help-sub');
|
|
12075
|
+
if ($sub) $sub.textContent = 'Terminal instructions copied. Open the terminal agent and paste them there.';
|
|
12076
|
+
}
|
|
12077
|
+
} finally {
|
|
12078
|
+
setCopyBusy($requestHelpCopy, false);
|
|
12030
12079
|
}
|
|
12031
12080
|
}
|
|
12032
12081
|
if ($requestHelpCopy) $requestHelpCopy.onclick = copyFromRequestHelp;
|
|
12082
|
+
if ($requestHelpChat) $requestHelpChat.onclick = async () => {
|
|
12083
|
+
const req = requestHelpReq;
|
|
12084
|
+
const provider = preferredChatProvider();
|
|
12085
|
+
if (!req || !provider || typeof window.flolessChat?.startRequest !== 'function') return;
|
|
12086
|
+
setRequestHelpBusy('chat');
|
|
12087
|
+
try {
|
|
12088
|
+
await window.flolessChat.startRequest(req.id, provider, 'start');
|
|
12089
|
+
closeRequestHelp({ restoreFocus: false });
|
|
12090
|
+
showToast(`Started in ${runtimeLabel(provider)} — continue in AI Chat`, 'ok');
|
|
12091
|
+
await loadRequests();
|
|
12092
|
+
} catch (error) {
|
|
12093
|
+
reportErr(error);
|
|
12094
|
+
setRequestHelpBusy(null);
|
|
12095
|
+
const sub = document.getElementById('request-help-sub');
|
|
12096
|
+
if (sub) sub.textContent = requestHelpCopied
|
|
12097
|
+
? 'The request is still in Requests. Try again, start it in the background, or use the copied instruction in your terminal.'
|
|
12098
|
+
: 'The request is still in Requests. Try again, start it in the background, or copy the terminal instruction.';
|
|
12099
|
+
if ($requestHelpCopy && !requestHelpCopied) $requestHelpCopy.hidden = false;
|
|
12100
|
+
$requestHelpChat.focus();
|
|
12101
|
+
}
|
|
12102
|
+
};
|
|
12033
12103
|
// ▶ runs with the resolved default; ▾ asks folder + which terminal AI first. Both leave the modal
|
|
12034
12104
|
// OPEN on success and swap its steps for the run status — closing it would hide the one sentence
|
|
12035
12105
|
// that says what floless just started on the user's behalf.
|
|
12036
12106
|
const runFromHelpModal = async (withOptions) => {
|
|
12037
12107
|
const req = requestHelpReq;
|
|
12038
12108
|
if (!req) return;
|
|
12039
|
-
|
|
12109
|
+
setRequestHelpBusy('background');
|
|
12110
|
+
let res;
|
|
12111
|
+
try {
|
|
12112
|
+
res = withOptions ? await openRunOptions(req) : await runRequestHeadless(req);
|
|
12113
|
+
} finally {
|
|
12114
|
+
if (requestHelpReq === req) setRequestHelpBusy(null);
|
|
12115
|
+
}
|
|
12040
12116
|
// Still the same request on screen? A slow spawn plus a fast second queue could otherwise
|
|
12041
12117
|
// stamp this run's status onto somebody else's modal.
|
|
12042
12118
|
if (res && res.run && requestHelpReq === req) setRequestHelpRunning(res.run);
|
|
@@ -12052,6 +12128,19 @@
|
|
|
12052
12128
|
closeRequestHelp();
|
|
12053
12129
|
return;
|
|
12054
12130
|
}
|
|
12131
|
+
if ($requestHelpModal && $requestHelpModal.classList.contains('show') && e.key === 'Tab') {
|
|
12132
|
+
const dialog = $requestHelpModal.querySelector('.modal.request-help');
|
|
12133
|
+
const focusable = Array.from($requestHelpModal.querySelectorAll('button:not([disabled]):not([hidden]), [tabindex]:not([tabindex="-1"])'))
|
|
12134
|
+
.filter((el) => el.offsetParent !== null);
|
|
12135
|
+
if (!focusable.length) { e.preventDefault(); dialog?.focus(); return; }
|
|
12136
|
+
const first = focusable[0]; const last = focusable[focusable.length - 1];
|
|
12137
|
+
if (e.shiftKey && (document.activeElement === dialog || document.activeElement === first || !$requestHelpModal.contains(document.activeElement))) {
|
|
12138
|
+
e.preventDefault(); last.focus();
|
|
12139
|
+
} else if (!e.shiftKey && (document.activeElement === last || !$requestHelpModal.contains(document.activeElement))) {
|
|
12140
|
+
e.preventDefault(); first.focus();
|
|
12141
|
+
}
|
|
12142
|
+
return;
|
|
12143
|
+
}
|
|
12055
12144
|
if ($reqModal && $reqModal.classList.contains('show')) {
|
|
12056
12145
|
if (e.key === 'Escape') { e.preventDefault(); closeRequests(); return; }
|
|
12057
12146
|
if (e.key === 'Tab') {
|
|
@@ -12121,6 +12210,161 @@
|
|
|
12121
12210
|
setTimeout(() => { if (currentId) renderChat(); }, 900);
|
|
12122
12211
|
}
|
|
12123
12212
|
|
|
12213
|
+
// A signed-in person can belong to more than one FloLess account. Desktop module authority is
|
|
12214
|
+
// account-bound, so never guess. This chooser is scoped to xeoRVT: core FloLess stays usable
|
|
12215
|
+
// while someone decides which of their accounts should supply Revit model authority.
|
|
12216
|
+
function renderAccountGate(accounts, { moduleOnly = false } = {}) {
|
|
12217
|
+
if (document.getElementById('account-gate')) return;
|
|
12218
|
+
const rows = Array.isArray(accounts) ? accounts : [];
|
|
12219
|
+
const returnFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
12220
|
+
const appRoot = document.getElementById('app');
|
|
12221
|
+
if (!moduleOnly && appRoot) appRoot.inert = true;
|
|
12222
|
+
if (!document.getElementById('account-gate-style')) {
|
|
12223
|
+
const style = document.createElement('style');
|
|
12224
|
+
style.id = 'account-gate-style';
|
|
12225
|
+
style.textContent = `
|
|
12226
|
+
#account-gate{position:fixed;inset:0;z-index:99999;display:flex;align-items:center;justify-content:center;
|
|
12227
|
+
padding:24px;background:var(--bg,#020817);color:var(--text,#f8fafc);font-family:var(--ui,system-ui,sans-serif);}
|
|
12228
|
+
#account-gate .ag-card{width:92vw;max-width:480px;padding:30px;border-radius:14px;
|
|
12229
|
+
background:var(--surface,#0b1424);border:1px solid var(--border,#1e293b);box-shadow:0 20px 60px rgba(0,0,0,.5);}
|
|
12230
|
+
#account-gate h1{font-size:20px;margin:0 0 8px;font-weight:600;}
|
|
12231
|
+
#account-gate .ag-copy{font-size:13px;line-height:1.55;color:var(--text-dim,#94a3b8);margin:0 0 18px;}
|
|
12232
|
+
#account-gate .ag-list{display:flex;flex-direction:column;gap:4px;max-height:min(320px,40vh);overflow-y:auto;
|
|
12233
|
+
padding:4px;border:1px solid var(--border,#1e293b);border-radius:8px;scrollbar-width:thin;
|
|
12234
|
+
scrollbar-color:var(--border-strong,#334155) transparent;}
|
|
12235
|
+
#account-gate .ag-list::-webkit-scrollbar{width:7px;} #account-gate .ag-list::-webkit-scrollbar-track{background:transparent;}
|
|
12236
|
+
#account-gate .ag-list::-webkit-scrollbar-thumb{background:var(--border-strong,#334155);border-radius:7px;}
|
|
12237
|
+
#account-gate .wf-option{width:100%;min-height:46px;border-left:3px solid transparent;border-radius:5px;}
|
|
12238
|
+
#account-gate .wf-option:focus-visible{outline:2px solid var(--accent,#3b82f6);outline-offset:1px;}
|
|
12239
|
+
#account-gate .ag-option-copy{display:flex;flex:1;min-width:0;flex-direction:column;gap:3px;}
|
|
12240
|
+
#account-gate .ag-option-copy .wf-option-name{flex:none;}
|
|
12241
|
+
#account-gate .ag-option-copy .wf-option-meta{white-space:normal;}
|
|
12242
|
+
#account-gate .ag-actions{display:flex;justify-content:flex-end;gap:8px;margin-top:18px;}
|
|
12243
|
+
#account-gate .ag-actions button{padding:8px 16px;}
|
|
12244
|
+
#account-gate .ag-actions .primary{border-color:var(--accent,#3b82f6);background:var(--accent,#3b82f6);color:#fff;font-weight:600;}
|
|
12245
|
+
#account-gate .ag-actions button:disabled{opacity:.5;cursor:default;}
|
|
12246
|
+
#account-gate .ag-status{min-height:19px;margin:12px 0 0;color:var(--text-dim,#94a3b8);font-size:12px;line-height:1.5;}
|
|
12247
|
+
#account-gate .ag-status.error{color:var(--err,#f87171);}
|
|
12248
|
+
#account-gate.module-only{pointer-events:none;background:transparent;}
|
|
12249
|
+
#account-gate.module-only .ag-card{pointer-events:auto;}
|
|
12250
|
+
@media(max-width:520px){#account-gate{padding:14px;}#account-gate .ag-card{padding:24px 20px;}
|
|
12251
|
+
#account-gate .ag-actions{flex-direction:column-reverse;}#account-gate .ag-actions button{width:100%;}}
|
|
12252
|
+
`;
|
|
12253
|
+
document.head.appendChild(style);
|
|
12254
|
+
}
|
|
12255
|
+
const duplicateNames = new Map();
|
|
12256
|
+
rows.forEach((account) => duplicateNames.set(account.displayName, (duplicateNames.get(account.displayName) || 0) + 1));
|
|
12257
|
+
const wrap = document.createElement('div');
|
|
12258
|
+
wrap.id = 'account-gate';
|
|
12259
|
+
if (moduleOnly) wrap.classList.add('module-only');
|
|
12260
|
+
const options = rows.map((account, index) => {
|
|
12261
|
+
const duplicate = duplicateNames.get(account.displayName) > 1;
|
|
12262
|
+
const role = account.role === 'owner' ? 'Owner' : 'Member';
|
|
12263
|
+
const discriminator = duplicate ? ` · account …${String(account.accountId).slice(-8)}` : '';
|
|
12264
|
+
return `<div class="wf-option" role="option" aria-selected="false" tabindex="${index === 0 ? '0' : '-1'}" data-account-id="${escapeHtml(account.accountId)}">
|
|
12265
|
+
<span class="ag-option-copy"><span class="wf-option-name">${escapeHtml(account.displayName)}</span>
|
|
12266
|
+
<span class="wf-option-meta">${role}${escapeHtml(discriminator)}</span></span></div>`;
|
|
12267
|
+
}).join('');
|
|
12268
|
+
wrap.innerHTML = `<section class="ag-card" role="dialog"${moduleOnly ? '' : ' aria-modal="true"'} aria-labelledby="ag-title" aria-describedby="ag-copy">
|
|
12269
|
+
<h1 id="ag-title">Choose an account</h1>
|
|
12270
|
+
<p class="ag-copy" id="ag-copy">Your sign-in belongs to more than one FloLess account. Choose which account to use for Revit model access.</p>
|
|
12271
|
+
${rows.length ? `<div class="ag-list" id="ag-list" role="listbox" aria-label="FloLess accounts">${options}</div>`
|
|
12272
|
+
: '<p class="ag-copy" role="alert">No account is available for this sign-in. Ask your FloLess account owner to add you, or sign in with a different account.</p>'}
|
|
12273
|
+
<div class="ag-actions">${moduleOnly ? '<button type="button" id="ag-not-now">Not now</button>' : '<button type="button" id="ag-signout">Sign out</button>'}
|
|
12274
|
+
${rows.length ? '<button type="button" class="primary" id="ag-use" disabled>Use this account</button>' : ''}</div>
|
|
12275
|
+
<p class="ag-status" id="ag-status" aria-live="polite"></p>
|
|
12276
|
+
</section>`;
|
|
12277
|
+
document.body.appendChild(wrap);
|
|
12278
|
+
wrap.querySelector('#ag-not-now')?.addEventListener('click', () => {
|
|
12279
|
+
wrap.remove();
|
|
12280
|
+
returnFocus?.focus({ preventScroll: true });
|
|
12281
|
+
});
|
|
12282
|
+
const optionEls = [...wrap.querySelectorAll('[role="option"]')];
|
|
12283
|
+
const use = wrap.querySelector('#ag-use');
|
|
12284
|
+
const status = wrap.querySelector('#ag-status');
|
|
12285
|
+
let selected = null; let submitting = false;
|
|
12286
|
+
const setStatus = (message, error = false) => {
|
|
12287
|
+
status.textContent = message;
|
|
12288
|
+
status.classList.toggle('error', error);
|
|
12289
|
+
if (error) status.setAttribute('role', 'alert'); else status.removeAttribute('role');
|
|
12290
|
+
};
|
|
12291
|
+
const select = (option) => {
|
|
12292
|
+
if (!option || submitting) return;
|
|
12293
|
+
selected = option;
|
|
12294
|
+
optionEls.forEach((row) => {
|
|
12295
|
+
const active = row === option;
|
|
12296
|
+
row.classList.toggle('selected', active);
|
|
12297
|
+
row.setAttribute('aria-selected', String(active));
|
|
12298
|
+
});
|
|
12299
|
+
if (use) use.disabled = false;
|
|
12300
|
+
setStatus('');
|
|
12301
|
+
};
|
|
12302
|
+
const moveFocus = (index) => {
|
|
12303
|
+
if (!optionEls.length) return;
|
|
12304
|
+
const next = optionEls[(index + optionEls.length) % optionEls.length];
|
|
12305
|
+
optionEls.forEach((row) => { row.tabIndex = row === next ? 0 : -1; });
|
|
12306
|
+
next.focus();
|
|
12307
|
+
};
|
|
12308
|
+
optionEls.forEach((option, index) => {
|
|
12309
|
+
option.addEventListener('click', () => select(option));
|
|
12310
|
+
option.addEventListener('keydown', (event) => {
|
|
12311
|
+
if (event.key === 'ArrowDown') { event.preventDefault(); moveFocus(index + 1); }
|
|
12312
|
+
else if (event.key === 'ArrowUp') { event.preventDefault(); moveFocus(index - 1); }
|
|
12313
|
+
else if (event.key === 'Home') { event.preventDefault(); moveFocus(0); }
|
|
12314
|
+
else if (event.key === 'End') { event.preventDefault(); moveFocus(optionEls.length - 1); }
|
|
12315
|
+
else if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); select(option); }
|
|
12316
|
+
});
|
|
12317
|
+
});
|
|
12318
|
+
if (use) use.addEventListener('click', async () => {
|
|
12319
|
+
if (!selected || submitting) return;
|
|
12320
|
+
submitting = true; use.disabled = true; use.textContent = 'Checking access…'; use.setAttribute('aria-busy', 'true');
|
|
12321
|
+
setStatus('Checking this account…');
|
|
12322
|
+
try {
|
|
12323
|
+
const response = await api('/api/license/account', { method: 'POST', body: JSON.stringify({ accountId: selected.dataset.accountId }) });
|
|
12324
|
+
const access = response.desktopAccess || {};
|
|
12325
|
+
if (access.state === 'active') {
|
|
12326
|
+
wrap.remove();
|
|
12327
|
+
if (appRoot) appRoot.inert = false;
|
|
12328
|
+
// The selection changes only optional Revit capability, so repaint both the
|
|
12329
|
+
// card that initiated it and the integration row immediately. bootWorkspace
|
|
12330
|
+
// alone reloads general data but leaves those visible module states stale.
|
|
12331
|
+
window.dispatchEvent(new CustomEvent('floless:revit-capability-changed'));
|
|
12332
|
+
void refreshIntegrations();
|
|
12333
|
+
bootWorkspace();
|
|
12334
|
+
return;
|
|
12335
|
+
}
|
|
12336
|
+
const reason = access.reason || '';
|
|
12337
|
+
if (reason === 'account-selection-invalid') setStatus('That account is no longer available. Choose another.', true);
|
|
12338
|
+
else if (reason === 'access-426') setStatus('This FloLess build needs an update before it can use this account. Update FloLess, then try again.', true);
|
|
12339
|
+
else if (reason === 'accounts-401' || reason === 'accounts-403') { location.reload(); return; }
|
|
12340
|
+
else setStatus('We couldn’t check your account. Check your connection and try again.', true);
|
|
12341
|
+
} catch (error) {
|
|
12342
|
+
if (error?.body?.code === 'signed-out') { location.reload(); return; }
|
|
12343
|
+
setStatus('We couldn’t check your account. Check your connection and try again.', true);
|
|
12344
|
+
} finally {
|
|
12345
|
+
if (document.body.contains(wrap)) {
|
|
12346
|
+
submitting = false; use.disabled = !selected; use.textContent = 'Use this account'; use.removeAttribute('aria-busy');
|
|
12347
|
+
}
|
|
12348
|
+
}
|
|
12349
|
+
});
|
|
12350
|
+
wrap.querySelector('#ag-signout')?.addEventListener('click', async () => {
|
|
12351
|
+
if (submitting) return;
|
|
12352
|
+
try { await api('/api/license/logout', { method: 'POST' }); } catch { /* reload still returns to the sign-in gate */ }
|
|
12353
|
+
location.reload();
|
|
12354
|
+
});
|
|
12355
|
+
if (!moduleOnly) {
|
|
12356
|
+
wrap.addEventListener('keydown', (event) => {
|
|
12357
|
+
if (event.key !== 'Tab') return;
|
|
12358
|
+
const focusable = [...wrap.querySelectorAll('[tabindex="0"],button:not([disabled])')];
|
|
12359
|
+
if (!focusable.length) return;
|
|
12360
|
+
const first = focusable[0]; const last = focusable.at(-1);
|
|
12361
|
+
if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); }
|
|
12362
|
+
else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); }
|
|
12363
|
+
});
|
|
12364
|
+
}
|
|
12365
|
+
(optionEls[0] || wrap.querySelector('#ag-not-now') || wrap.querySelector('#ag-signout'))?.focus();
|
|
12366
|
+
}
|
|
12367
|
+
|
|
12124
12368
|
// Subscription gate (the server enforces it on every /api/* with 402; the UI
|
|
12125
12369
|
// mirrors it so an ungated user sees a sign-in panel, not a broken workspace).
|
|
12126
12370
|
// We fetch NO workspace data while ungated. The license endpoints stay open.
|
|
@@ -12235,6 +12479,24 @@
|
|
|
12235
12479
|
// loads AFTER this file and reuses these seams instead of duplicating the fetch /
|
|
12236
12480
|
// report-viewer plumbing — the renderer composes nothing itself. Kept minimal on
|
|
12237
12481
|
// purpose; widen only when a panel block genuinely needs another seam.
|
|
12482
|
+
function currentChatScope() {
|
|
12483
|
+
if (wsTitleName) {
|
|
12484
|
+
if (wsTitleLanding || !wsTitleProjectId) return null;
|
|
12485
|
+
return { owner: { kind: 'project', projectId: wsTitleProjectId }, label: wsTitleName };
|
|
12486
|
+
}
|
|
12487
|
+
const app = currentId ? apps.get(currentId) : null;
|
|
12488
|
+
const owned = app?.ownedWorkflow;
|
|
12489
|
+
if (!owned?.workflowId) return null;
|
|
12490
|
+
return {
|
|
12491
|
+
owner: { kind: 'workflow', workflowId: owned.workflowId },
|
|
12492
|
+
label: owned.displayName || app.displayName || currentId,
|
|
12493
|
+
};
|
|
12494
|
+
}
|
|
12495
|
+
|
|
12496
|
+
function notifyChatScope() {
|
|
12497
|
+
window.dispatchEvent(new CustomEvent('floless:chat-scope-changed', { detail: currentChatScope() }));
|
|
12498
|
+
}
|
|
12499
|
+
|
|
12238
12500
|
window.flolessBridge = {
|
|
12239
12501
|
api,
|
|
12240
12502
|
// Open report HTML in the existing sandboxed HTML Viewer (same modal + srcdoc
|
|
@@ -12250,6 +12512,34 @@
|
|
|
12250
12512
|
},
|
|
12251
12513
|
// Refresh the footer requests counter after the Customize box queues a request.
|
|
12252
12514
|
loadRequests,
|
|
12515
|
+
openRequest(requestId) {
|
|
12516
|
+
return openRequests(requestId || null);
|
|
12517
|
+
},
|
|
12518
|
+
preferredChatProvider,
|
|
12519
|
+
async startRequestInChat(requestId, mode = 'start') {
|
|
12520
|
+
const provider = preferredChatProvider();
|
|
12521
|
+
if (!provider || typeof window.flolessChat?.startRequest !== 'function') {
|
|
12522
|
+
throw new Error('Sign in to Claude or Codex before starting this request in AI Chat.');
|
|
12523
|
+
}
|
|
12524
|
+
await window.flolessChat.refreshScope?.();
|
|
12525
|
+
return window.flolessChat.startRequest(requestId, provider, mode);
|
|
12526
|
+
},
|
|
12527
|
+
async startProjectChatIntake(submissionId, payload) {
|
|
12528
|
+
if (typeof window.flolessChat?.startProjectIntake !== 'function') {
|
|
12529
|
+
throw new Error('AI Chat is still starting. Try again in a moment.');
|
|
12530
|
+
}
|
|
12531
|
+
return window.flolessChat.startProjectIntake(submissionId, payload);
|
|
12532
|
+
},
|
|
12533
|
+
async resumeProjectChatIntake(submissionId) {
|
|
12534
|
+
if (typeof window.flolessChat?.resumeProjectIntake !== 'function') return null;
|
|
12535
|
+
return window.flolessChat.resumeProjectIntake(submissionId);
|
|
12536
|
+
},
|
|
12537
|
+
async openChatConversation(chatId) {
|
|
12538
|
+
if (typeof window.flolessChat?.openConversation !== 'function') {
|
|
12539
|
+
throw new Error('AI Chat is still starting. Try again in a moment.');
|
|
12540
|
+
}
|
|
12541
|
+
return window.flolessChat.openConversation(chatId);
|
|
12542
|
+
},
|
|
12253
12543
|
// Which project the Requests window filters to. workspaces.js owns the open project;
|
|
12254
12544
|
// aware.js owns the window. Called from applyMode() — the single funnel every path that
|
|
12255
12545
|
// changes the open project (open, close, rename, mode switch, boot) already ends at.
|
|
@@ -12267,7 +12557,6 @@
|
|
|
12267
12557
|
const $rm = document.getElementById('requests-modal');
|
|
12268
12558
|
if ($rm && $rm.classList.contains('show')) renderRequests();
|
|
12269
12559
|
renderChat();
|
|
12270
|
-
renderInstructorAnswers({ revealNew: hydratedInstructorAnswers });
|
|
12271
12560
|
},
|
|
12272
12561
|
refreshCurrentWorkflow() {
|
|
12273
12562
|
return refreshCurrentWorkflow();
|
|
@@ -12284,6 +12573,27 @@
|
|
|
12284
12573
|
instructionFor,
|
|
12285
12574
|
markedInstruction, // marked (paste-safe) form for clipboard copies — panels.js uses it (#73)
|
|
12286
12575
|
copyRequest, // copy ONE request, telling "no instruction body" apart from "clipboard refused"
|
|
12576
|
+
async runReadOnlyRequest(request, runtime) {
|
|
12577
|
+
if (!runtime || typeof window.flolessChat?.startRequest !== 'function') {
|
|
12578
|
+
throw new Error('AI Chat is not ready for this request.');
|
|
12579
|
+
}
|
|
12580
|
+
const res = await window.flolessChat.startRequest(request.id, runtime, 'start');
|
|
12581
|
+
await loadRequests();
|
|
12582
|
+
window.flolessBridge?.revealAiChat?.();
|
|
12583
|
+
return res;
|
|
12584
|
+
},
|
|
12585
|
+
async queueAndCopyRequest(request) {
|
|
12586
|
+
const copied = await copyToClipboard(markedInstruction(request));
|
|
12587
|
+
await loadRequests();
|
|
12588
|
+
return copied;
|
|
12589
|
+
},
|
|
12590
|
+
async readOnlyRequestOptions() {
|
|
12591
|
+
const info = await refreshHeadless();
|
|
12592
|
+
return {
|
|
12593
|
+
provider: info?.provider || null,
|
|
12594
|
+
found: headlessRuntimes().filter((runtime) => runtime && runtime.state === 'found' && runtime.canRunReadOnly === true),
|
|
12595
|
+
};
|
|
12596
|
+
},
|
|
12287
12597
|
showRequestQueuedModal,
|
|
12288
12598
|
formModal, // the shared styled prompt/form modal — workspaces.js reuses it (never a native prompt)
|
|
12289
12599
|
// One owner for runtime upgrades. Workspaces may open this surface but must
|
|
@@ -12304,6 +12614,7 @@
|
|
|
12304
12614
|
? { name: wsTitleName, landing: wsTitleLanding, projectId: wsTitleProjectId }
|
|
12305
12615
|
: null);
|
|
12306
12616
|
}
|
|
12617
|
+
notifyChatScope();
|
|
12307
12618
|
},
|
|
12308
12619
|
// Instructor loads after this bridge. Workspaces can restore its persisted mode before
|
|
12309
12620
|
// Instructor mounts, so expose the last visible title for a one-time initialization replay.
|
|
@@ -12312,6 +12623,21 @@
|
|
|
12312
12623
|
? { name: wsTitleName, landing: wsTitleLanding, projectId: wsTitleProjectId }
|
|
12313
12624
|
: null;
|
|
12314
12625
|
},
|
|
12626
|
+
getChatScope() {
|
|
12627
|
+
return currentChatScope();
|
|
12628
|
+
},
|
|
12629
|
+
revealAiChat() {
|
|
12630
|
+
window.flolessLeftPane?.showSection?.('narrative');
|
|
12631
|
+
if (state.collapse.left) {
|
|
12632
|
+
document.querySelector('.collapsed-stub .panel-toggle[data-side="left"]')?.click();
|
|
12633
|
+
}
|
|
12634
|
+
},
|
|
12635
|
+
isRequestChatBlocked(requestId) {
|
|
12636
|
+
const request = pendingRequests.find((candidate) => candidate?.id === requestId);
|
|
12637
|
+
return Boolean(request && request.type !== 'guide'
|
|
12638
|
+
&& (request.run?.state === 'queued' || request.run?.state === 'running' || request.run?.state === 'needs-you'
|
|
12639
|
+
|| request.run?.handoffReady || request.run?.recoveryReady || request.run?.processContained === false));
|
|
12640
|
+
},
|
|
12315
12641
|
// ── Workspaces guide beacon (the SAME #guide-beacon/#guide-modal, document variant) ──
|
|
12316
12642
|
// workspaces.js owns the open project + its lifecycle state; aware.js owns the beacon
|
|
12317
12643
|
// chrome. workspaces.js calls setWorkspaceGuide() with a small snapshot whenever the
|
|
@@ -12393,8 +12719,7 @@
|
|
|
12393
12719
|
if (effectivelyLicensed && !licensed) connectSse();
|
|
12394
12720
|
} catch { /* still failing — fall through to gate */ }
|
|
12395
12721
|
}
|
|
12396
|
-
if (
|
|
12397
|
-
else renderGate(effectiveStatus || { state: 'unlicensed' });
|
|
12722
|
+
if (routeLicenseStatus(effectiveStatus)) bootWorkspace();
|
|
12398
12723
|
};
|
|
12399
12724
|
|
|
12400
12725
|
// Setup-first: if AWARE isn't ready, show the overlay and DEFER routing until it
|