@floless/app 0.152.1 → 0.153.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -350,6 +350,12 @@
350
350
  const $revisionCard = document.getElementById('ws-revision-card');
351
351
  const $revisionFile = document.getElementById('ws-revision-file');
352
352
  const $sourcePlaceholder = document.getElementById('ws-source-placeholder'); // shown for a filter-less Source step
353
+ // While a Revit or Tekla read is in flight the Source pane shows Flo working, hat on, as over a running workflow
354
+ // (#2079). It sits in the hidden .ws-source-spin slot that data-importing reveals, and only moves while on screen.
355
+ {
356
+ const slot = $sourcePlaceholder?.querySelector('.ws-source-spin');
357
+ if (slot && typeof floAvatar === 'function') { slot.classList.add('ws-source-flo'); floAvatar(slot, { size: 40, mood: 'working', hat: true }); }
358
+ }
353
359
  const $revitSourceActions = document.getElementById('ws-source-actions');
354
360
  const $revitOpenModel = document.getElementById('ws-revit-open-model');
355
361
  const $revitReplace = document.getElementById('ws-revit-replace');
@@ -1533,7 +1539,7 @@
1533
1539
  // project open" for the whole pending window and close the project the user asked to stay in —
1534
1540
  // and the read would then drop them in Workflows anyway.
1535
1541
  const pending = $switch.getAttribute('aria-busy') === 'true';
1536
- if (!pending && b.dataset.mode === 'workspaces' && mode === 'workspaces' && current) { closeProject(); return; }
1542
+ if (!pending && b.dataset.mode === 'workspaces' && mode === 'workspaces' && current) { void leaveProjectToList(b); return; }
1537
1543
  // #1890: the active Workflows tab goes home to the Workflows landing, the same way.
1538
1544
  if (!pending && b.dataset.mode === 'workflows' && mode === 'workflows' && bridge.showWorkflowsLanding) { bridge.showWorkflowsLanding(); return; }
1539
1545
  // #2007: and the active Agents tab goes home to the list of agents.
@@ -2041,7 +2047,7 @@
2041
2047
  // UNPROMPTED. Tracked separately rather than smuggled in here.
2042
2048
  const target = mine.id;
2043
2049
  try {
2044
- await openProject(target, currentStep);
2050
+ await openProject(target, currentStep, { skipLeaveGuard: true });
2045
2051
  } catch (err) {
2046
2052
  // THE REJECTING TWIN of the branch below, and it needs the same sentence: `openProject`
2047
2053
  // reassigns `current` and repaints the header BEFORE it re-srcs the frames, so a throw in
@@ -3111,7 +3117,11 @@
3111
3117
  if (current?.id !== project.id) return;
3112
3118
  if (!state?.canReplace) throw new Error('Tekla Parser replacement access is unavailable.');
3113
3119
  const operation = await uploadTeklaForProject(project, source, state.generation);
3114
- if (current?.id === project.id) pollRevitImport(operation.operationId, project.id);
3120
+ if (current?.id === project.id) {
3121
+ // As a new project's read does: the copy check is over, so its "cannot be cancelled" no longer stands.
3122
+ paintRevitSourceState('Waiting for AWARE', 'Your copied Tekla source is waiting for the entitled read-only parser.');
3123
+ pollRevitImport(operation.operationId, project.id);
3124
+ }
3115
3125
  } catch (error) {
3116
3126
  if (current?.id !== project.id) return;
3117
3127
  if (error?.name === 'AbortError') {
@@ -4559,6 +4569,14 @@
4559
4569
  if (activeImportPolls.has(pollKey)) return;
4560
4570
  activeImportPolls.add(pollKey);
4561
4571
  const isCurrentImport = () => current?.id === projectId && revitActiveOperation?.operationId === operationId;
4572
+ // Every live state of the read shows it in flight, with its Cancel, from the moment it is admitted. A project
4573
+ // opened just as its upload was admitted can drop its own in-flight paint (refreshRevitSourceState yields to the
4574
+ // newer operation), leaving the idle glyph under "Reading model"; a Tekla read still carries the copy check's
4575
+ // 'uploading' paint, which has no Cancel although the admitted operation has a cancel route.
4576
+ const showReadInFlight = () => {
4577
+ if ($revitCancel?.hidden || $sourcePlaceholder?.getAttribute('data-importing') !== 'true') paintRevitSourceActions('active', true);
4578
+ };
4579
+ if (isCurrentImport()) showReadInFlight();
4562
4580
  try {
4563
4581
  for (;;) {
4564
4582
  await new Promise((resolve) => setTimeout(resolve, 800));
@@ -4594,7 +4612,7 @@
4594
4612
  validating: ['Checking model integrity', 'Verifying the signed source and display packages…'],
4595
4613
  publishing: ['Publishing draft', 'Saving the verified read-only model snapshot…'],
4596
4614
  }[operation.state];
4597
- if (copy) { paintRevitSourceState(copy[0], copy[1]); continue; }
4615
+ if (copy) { paintRevitSourceState(copy[0], copy[1]); showReadInFlight(); continue; }
4598
4616
  if (operation.state === 'ready') {
4599
4617
  revitActiveOperation = null;
4600
4618
  paintRevitSourceState(tekla ? 'Read-only snapshot ready to review' : 'Model ready to review', 'The model is available on the Model tab. It is not approved yet.');
@@ -4711,9 +4729,18 @@
4711
4729
  }
4712
4730
 
4713
4731
  // ── open project ────────────────────────────────────────────────────────────
4714
- async function openProject(id, initialStep = 'model') {
4732
+ // `opts.skipLeaveGuard` is for the rename re-open only (the project is the same one under a new id and
4733
+ // its old id is already gone, so there is nothing to save to). Every other open of a DIFFERENT project
4734
+ // while one is open asks about unsaved work first — the card click, the switcher, Show in chat, Open
4735
+ // knowledge, create/import — so no path replaces the editors behind the user's back.
4736
+ let openNavSeq = 0;
4737
+ async function openProject(id, initialStep = 'model', opts) {
4738
+ const nav = opts || {};
4739
+ // Latest navigation wins from the first line: an older open still waiting on a lookup must not replace a newer one.
4740
+ const navToken = ++openNavSeq;
4715
4741
  let p = projects.find((x) => x.id === id);
4716
4742
  if (!p) { try { p = (await api('/api/projects')).projects.find((x) => x.id === id); } catch { /* fall through */ } }
4743
+ if (navToken !== openNavSeq) return STAYED_IN_PROJECT;
4717
4744
  if (!p) { showToast('Project not found — it may have been archived.', 'warn'); return loadProjects(); }
4718
4745
  // Never a broken open (spec §3.2): a project whose app has no client descriptor can't be rendered
4719
4746
  // — toast and bail BEFORE mutating any view state, matching the create-card skip. wsApp() would
@@ -4727,6 +4754,8 @@
4727
4754
  showToast('Workspaces has no view for this project’s app yet — ask the AI to add one.', 'warn');
4728
4755
  return;
4729
4756
  }
4757
+ if (!nav.skipLeaveGuard && current && current.id !== p.id && !(await leaveOpenProject(nav.returnFocus))) return STAYED_IN_PROJECT;
4758
+ if (navToken !== openNavSeq) return STAYED_IN_PROJECT;
4730
4759
  current = p;
4731
4760
  // #1890: a new workspace conversation suggests this project's units (the one opened last).
4732
4761
  try { localStorage.setItem('floless:last-project', p.id); } catch { /* private mode: no suggestion */ }
@@ -4907,6 +4936,46 @@
4907
4936
  $revisionCard.className = 'ws-revision-card';
4908
4937
  return true;
4909
4938
  }
4939
+ /**
4940
+ * Leaving the open project for another one, or for the project list, replaces its editors, so
4941
+ * anything the Drawing Filter or the model editor has not saved would be lost with them. Ask first
4942
+ * — but only when something is actually unsaved. A drawing read running in AI Chat is not part of
4943
+ * the question: it keeps running on the server and its conversation, cards and approvals are there
4944
+ * again when this project is reopened. (Switching tab to Workflows or Agents only hides the editors,
4945
+ * so it needs no question.)
4946
+ */
4947
+ async function confirmLeaveProject(returnFocus) {
4948
+ const guard = window.flolessLeaveGuard;
4949
+ if (!guard || typeof guard.confirmIfUnsaved !== 'function' || !current) return true;
4950
+ // No `only`: action 'project' filters to this project's editor frames inside the guard itself.
4951
+ return guard.confirmIfUnsaved({ action: 'project', returnFocus });
4952
+ }
4953
+ /**
4954
+ * The ONE gate for replacing the open project's editors (another project, or the list). Latest
4955
+ * navigation wins: each call takes a token, and a call whose token has been superseded by the time
4956
+ * its question is answered resolves false, so two quick choices can never open the earlier one last.
4957
+ * The source project is held by id; if it is no longer the open one when the answer arrives (closed
4958
+ * or replaced meanwhile) the question is asked afresh for whatever is open now. Resolves true only
4959
+ * when nothing in the open project is unsaved at that moment, or the user chose to go on.
4960
+ */
4961
+ let leaveNavSeq = 0;
4962
+ async function leaveOpenProject(returnFocus) {
4963
+ const token = ++leaveNavSeq;
4964
+ for (let round = 0; round < 3; round++) {
4965
+ const sourceId = current ? current.id : null;
4966
+ if (!sourceId) return true;
4967
+ if (!(await confirmLeaveProject(returnFocus))) return false;
4968
+ if (token !== leaveNavSeq) return false;
4969
+ if ((current ? current.id : null) === sourceId) return true;
4970
+ }
4971
+ return false;
4972
+ }
4973
+ /** What openProject returns when the user chose to stay: callers that open on someone's behalf say so. */
4974
+ const STAYED_IN_PROJECT = Object.freeze({ stayed: true });
4975
+ async function leaveProjectToList(returnFocus) {
4976
+ if (!(await leaveOpenProject(returnFocus))) return;
4977
+ closeProject();
4978
+ }
4910
4979
  function closeProject() {
4911
4980
  current = null;
4912
4981
  approvalStateGen++;
@@ -4937,7 +5006,7 @@
4937
5006
  pendingPresenceToast = null;
4938
5007
  closeProjMenu(); applyMode(); syncWorkspaceGuide(); // revision state cleared by resetRevisionState() above
4939
5008
  }
4940
- document.getElementById('ws-back').addEventListener('click', closeProject);
5009
+ document.getElementById('ws-back').addEventListener('click', (e) => { void leaveProjectToList(e.currentTarget); });
4941
5010
 
4942
5011
  // Paint the step-tab LABELS from the current app's descriptor (Source/Traced for vectorize,
4943
5012
  // Drawings/Model for steel). The data-step KEYS stay stable (drawings/model/exports/history) so
@@ -5050,6 +5119,10 @@
5050
5119
  .map((item) => progressText(item.note))
5051
5120
  .filter(Boolean);
5052
5121
  const caution = cautions.length ? cautions.join(' · ') : null;
5122
+ // The read runs in AI Chat when the request is chat-owned; only a terminal-run read has a terminal session to return to (#2164).
5123
+ const inChat = req?.chatConversation?.executionOwner === 'chat';
5124
+ const backTo = inChat ? 'AI Chat' : 'the same terminal AI';
5125
+ const backToSession = inChat ? 'AI Chat' : 'the same terminal AI session that prepared it';
5053
5126
  let state = progress.status;
5054
5127
  let heading = 'Creating the first steel model';
5055
5128
  let nowLabel = 'Now';
@@ -5063,7 +5136,7 @@
5063
5136
  heading = 'Model creation is blocked';
5064
5137
  nowLabel = 'Blocked';
5065
5138
  now = progressText(progress.items.find((item) => item.state === 'blocked')?.note)
5066
- || 'Return to the same terminal AI for the blocking details.';
5139
+ || `Return to ${backTo} for the blocking details.`;
5067
5140
  } else if (progress.status === 'complete') {
5068
5141
  // A finished checklist is NOT a verified model: this request is still pending, nothing has
5069
5142
  // been submitted, and no audit has run. Only a signed post-audit surface may say the model
@@ -5071,11 +5144,11 @@
5071
5144
  heading = 'Drawing read finished';
5072
5145
  nowLabel = 'Done';
5073
5146
  now = null;
5074
- next = 'Return to the same terminal AI session that prepared it and let it submit the read.';
5147
+ next = `Return to ${backToSession} and let it submit the read.`;
5075
5148
  } else if (progress.status === 'cancelled') {
5076
5149
  heading = 'Model creation stopped';
5077
5150
  nowLabel = 'Stopped';
5078
- now = 'Return to the same terminal AI for next steps.';
5151
+ now = `Return to ${backTo} for next steps.`;
5079
5152
  next = null;
5080
5153
  }
5081
5154
  // A heartbeat nobody can refresh is not a heartbeat. Both arms below replace the forward-looking
@@ -5091,12 +5164,12 @@
5091
5164
  state = 'waiting';
5092
5165
  heading = 'No progress update in the last 8 minutes';
5093
5166
  nowLabel = 'Last reported';
5094
- next = 'Return to the same terminal AI session that prepared this read and ask it to continue.';
5167
+ next = inChat ? 'Ask the read in AI Chat to continue.' : 'Return to the same terminal AI session that prepared this read and ask it to continue.';
5095
5168
  } else if (stale && progress.status === 'complete') {
5096
5169
  state = 'waiting';
5097
5170
  heading = 'The drawing read finished but has not been submitted';
5098
5171
  nowLabel = 'Done';
5099
- next = 'Return to the same terminal AI session that prepared it and tell it to submit the read.';
5172
+ next = `Return to ${backToSession} and tell it to submit the read.`;
5100
5173
  }
5101
5174
  return {
5102
5175
  state,
@@ -14326,7 +14399,7 @@
14326
14399
  frontProject(project, id);
14327
14400
  // If the renamed project was the OPEN one, its editor iframes still carry ?project=<old id> —
14328
14401
  // re-open so they re-src to the new id (a stale id 404s the next contract read/write/autosave).
14329
- if (wasCurrent) await openProject(project.id);
14402
+ if (wasCurrent) await openProject(project.id, 'model', { skipLeaveGuard: true });
14330
14403
  showToast(`Renamed to "${project.name}"`, 'ok');
14331
14404
  } else if (action === 'duplicate') {
14332
14405
  dismissProgress = showToast(`Duplicating “${proj ? proj.name : 'project'}”…`, 'progress');
@@ -14713,10 +14786,10 @@
14713
14786
  projComboClearHighlight();
14714
14787
  if (focusTrigger && $projTrigger) $projTrigger.focus();
14715
14788
  }
14716
- function selectProjById(id) {
14789
+ async function selectProjById(id) {
14717
14790
  closeProjCombo(true);
14718
14791
  if (current && current.id === id) return; // already open — no-op, matches selectComboById
14719
- openProject(id);
14792
+ openProject(id, 'model', { returnFocus: $projTrigger }); // openProject asks about unsaved work itself
14720
14793
  }
14721
14794
  if ($projTrigger) {
14722
14795
  $projTrigger.addEventListener('click', (e) => {
@@ -14782,7 +14855,8 @@
14782
14855
  async function openKnowledgeStep(projectId) {
14783
14856
  if (typeof projectId !== 'string' || !projectId) throw new Error('That project could not be opened. Open it from Workspaces.');
14784
14857
  await setMode('workspaces');
14785
- await openProject(projectId, 'knowledge');
14858
+ const opened = await openProject(projectId, 'knowledge');
14859
+ if (opened === STAYED_IN_PROJECT) throw new Error('You stayed in this project, so the other one was not opened.');
14786
14860
  if (current?.id !== projectId) throw new Error('That project could not be opened. Open it from Workspaces.');
14787
14861
  }
14788
14862
 
@@ -14799,9 +14873,13 @@
14799
14873
  }
14800
14874
  await setMode('workspaces');
14801
14875
  if (owner.kind === 'project') {
14802
- await openProject(owner.projectId);
14876
+ const opened = await openProject(owner.projectId);
14877
+ if (opened === STAYED_IN_PROJECT) throw new Error('You stayed in this project, so the other one was not opened.');
14803
14878
  if (current?.id !== owner.projectId) throw new Error('That project could not be opened. Try Show in chat again after opening its project in Workspaces.');
14804
- } else closeProject();
14879
+ } else {
14880
+ await leaveProjectToList(null);
14881
+ if (current) throw new Error('You stayed in this project, so the conversation was not opened.');
14882
+ }
14805
14883
  }
14806
14884
 
14807
14885
  window.flolessWorkspaces = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floless/app",
3
- "version": "0.152.1",
3
+ "version": "0.153.0",
4
4
  "type": "module",
5
5
  "description": "Thin localhost host for floless.app — serves web/ and shells the aware CLI. No engine, no LLM.",
6
6
  "bin": {