@floless/app 0.111.3 → 0.112.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.
@@ -401,7 +401,7 @@ text.mlentx{fill:#e2e8f0;text-anchor:middle;dominant-baseline:central;font-famil
401
401
  body.in-workspace #moreMenu #revertB,body.in-workspace #moreMenu #revertSep{display:block}
402
402
  /* Same trap: "Send selection to Tekla" is hidden with an empty selection, and plain [hidden] loses
403
403
  to the #moreMenu rule above — without this it ships as a visible row that only scolds you. */
404
- #moreMenu #sendTeklaB[hidden]{display:none}
404
+ #moreMenu #sendTeklaB[hidden],#moreMenu #sendRevitB[hidden],#moreMenu #sendSketchupB[hidden]{display:none}
405
405
  #moreMenu button:disabled{opacity:.4;cursor:default;background:transparent}
406
406
  #moreMenu button.on{color:var(--brand)}
407
407
  button:focus-visible{outline:2px solid var(--brand);outline-offset:2px}
@@ -928,6 +928,8 @@ text.mlentx{fill:#e2e8f0;text-anchor:middle;dominant-baseline:central;font-famil
928
928
  <div class=msec-body>
929
929
  <button id=reloadB data-tip="Reloads this page and pulls in any changes your terminal AI made since you last opened it.">↻ Reload from server</button>
930
930
  <button id=sendTeklaB data-tip="Creates the selected members as native parts in the open Tekla model, at their real model coordinates. Same as Ctrl+Shift-dragging the selection out of the 3D view onto the Tekla window.">Send selection to Tekla</button>
931
+ <button id=sendRevitB data-tip="Creates the selected members as native Revit framing and columns in the open document, at their real model coordinates. Same as Ctrl+Shift-dragging the selection out of the 3D view onto the Revit window.">Send selection to Revit</button>
932
+ <button id=sendSketchupB data-tip="Creates the selected members as native groups in the open SketchUp model, at their real model coordinates. Same as Ctrl+Shift-dragging the selection out of the 3D view onto the SketchUp window.">Send selection to SketchUp</button>
931
933
  <button id=exp>Export contract…</button>
932
934
  </div>
933
935
  <hr id=revertSep>
@@ -1589,8 +1591,21 @@ async function boot() {
1589
1591
  // bearing on its own merits and stays.)
1590
1592
  const hasUnsaved = !!sv && (sv.classList.contains('dirty') || sv.classList.contains('err')
1591
1593
  || sv.classList.contains('conflict'));
1592
- if (hasUnsaved) showAiUpdateBanner('The AI updated this model — reload to see it (you have unsaved edits).');
1593
- else location.reload();
1594
+ if (hasUnsaved) {
1595
+ // WHAT happened, not a guess at who. Absent or unrecognised → today's wording byte for byte.
1596
+ // The contract PUT — the one writer that usually IS the terminal AI — deliberately sends no
1597
+ // reason, so the generic sentence stays correct for it; and a tab left open across an
1598
+ // auto-update can outlive its server, so a token from a NEWER build has to degrade quietly
1599
+ // rather than reach the bar.
1600
+ //
1601
+ // Read INSIDE this branch on purpose. Computed above the `if`, a `CHANGE_LEAD` that ever
1602
+ // became unreachable (P3 is actively refactoring `main()`'s closure) would throw here — and
1603
+ // an exception at this point means the tab neither banners NOR reloads, silently going deaf
1604
+ // to external writes with the error swallowed by the event loop. The reload path must not be
1605
+ // able to fail for a reason that only the banner path cares about.
1606
+ const lead = (typeof m.reason === 'string' && CHANGE_LEAD[m.reason]) || 'The AI updated this model';
1607
+ showAiUpdateBanner(lead + ' — reload to see it (you have unsaved edits).');
1608
+ } else location.reload();
1594
1609
  };
1595
1610
  es.onerror = () => {
1596
1611
  // Transient drops (readyState CONNECTING) auto-reconnect — ignore. A CLOSED channel is
@@ -1611,6 +1626,48 @@ async function boot() {
1611
1626
  }
1612
1627
  }
1613
1628
 
1629
+ /**
1630
+ * What to CALL the change that arrived, keyed by the server's `reason` token (server/mutation-id.ts,
1631
+ * `ContractChangeReason`).
1632
+ *
1633
+ * THE TOKEN IS THE SERVER'S; THE SENTENCE IS OURS. Nothing from the frame is ever rendered — the frame
1634
+ * only SELECTS a row from this table — so no value arriving over the wire can become copy on screen.
1635
+ * That is also why the wire tokens can stay terse and internal while these stay plain English.
1636
+ *
1637
+ * Each string matches the vocabulary of the control the user actually operated, because closing the loop
1638
+ * between what they clicked and what this bar says is the whole job here: History's button reads
1639
+ * "↺ Rollback" (workspaces.js), the conversion's reads "Convert to the 3D model →", and the History pane
1640
+ * already describes a re-read as "The AI read a revised drawing set". Copy that drifts from the control
1641
+ * it describes sends the user looking for a second, non-existent event.
1642
+ *
1643
+ * Only `revision-read` names an actor, and that asymmetry is deliberate rather than sloppy: a re-read
1644
+ * genuinely IS AI-authored (`author: 'AI'`, the History badge reads "AI read"), while a rollback and a
1645
+ * conversion are the user's own doing — saying "the AI" there is the untruth this table exists to fix.
1646
+ * Neither says "you", because this frame does not carry WHO, and a sentence that asserts the reader did
1647
+ * it would be guessing at the one fact the wire withheld.
1648
+ *
1649
+ * The staged confirm (`revision-routes.ts`, the second site) shares `revision-read` even though a human
1650
+ * picked which proposals to apply. Deliberate: the AI still authored the read, and the ledger records
1651
+ * both the same way (`author: 'AI'`, `kind: 'revision-read'`). That is unlike rollback, where blaming
1652
+ * the AI was flatly false rather than merely coarse. Split the token if the two ever want different
1653
+ * sentences — nothing here assumes they cannot.
1654
+ *
1655
+ * NULL PROTOTYPE, deliberately. A plain object literal answers `CHANGE_LEAD['constructor']` with a
1656
+ * FUNCTION, so a frame carrying `reason:"constructor"` would concatenate "function Object() { [native
1657
+ * code] }" into the banner. With no prototype there is nothing to inherit, and every unknown token —
1658
+ * malformed, hostile, or simply from a newer server — falls through to the generic sentence.
1659
+ */
1660
+ const CHANGE_LEAD = Object.assign(Object.create(null), {
1661
+ 'rollback': 'This model was rolled back',
1662
+ // "a revised" is a DEFAULT, not a proof. An initial read can reach this in principle — "initial" is
1663
+ // decided by the version ledger, not by the contract, and a seeded project has a contract before it
1664
+ // has a v1 (`workspaces.js` renders exactly that empty state). It is rare, and the frame carries no
1665
+ // base version to tell the two apart, so the common case wins. `workspaces.js` distinguishes them
1666
+ // ("the initial" vs "a revised") only because it has the ledger to hand; here we do not.
1667
+ 'revision-read': 'The AI read a revised drawing set into this model',
1668
+ 'migration': 'This project was converted to the 3D model',
1669
+ });
1670
+
1614
1671
  /**
1615
1672
  * The bottom bar for "this model changed underneath you".
1616
1673
  *
@@ -1641,7 +1698,11 @@ function showAiUpdateBanner(message, opts) {
1641
1698
 
1642
1699
  const msg = document.createElement('span');
1643
1700
  msg.style.cssText = 'flex:1';
1644
- msg.textContent = message || 'The AI updated this model — reload to see the latest version.';
1701
+ // The fallback is deliberately CAUSE-FREE. All five callers pass a message, so this is unreachable
1702
+ // today — but it was the last place in the file still asserting "the AI" about a change nobody has
1703
+ // established the AI made, which is the claim this bar stopped making. A caller that forgets its
1704
+ // message should say nothing it cannot support.
1705
+ msg.textContent = message || 'This model changed — reload to see the latest version.';
1645
1706
 
1646
1707
  const reloadBtn = document.createElement('button');
1647
1708
  reloadBtn.style.cssText = 'background:#3b82f6;color:#fff;border:1px solid #60a5fa;border-radius:6px;padding:5px 12px;cursor:pointer;font:13px system-ui';
@@ -5957,9 +6018,10 @@ function closeMore(){moreMenu.classList.remove('open');moreBtn.setAttribute('ari
5957
6018
  moreBtn.onclick=e=>{e.stopPropagation();if(moreOpen())closeMore();else{
5958
6019
  // "Send selection to Tekla" is hidden, not disabled, with nothing selected — there is no action to
5959
6020
  // offer yet, and a greyed row would read as a broken feature rather than an empty state.
5960
- document.getElementById('sendTeklaB').hidden=!selArr().length;
6021
+ {const anySel=!selArr().length;for(const bid of ['sendTeklaB','sendRevitB','sendSketchupB']){const b=document.getElementById(bid);if(b)b.hidden=anySel;}}
5961
6022
  moreMenu.classList.add('open');moreBtn.setAttribute('aria-expanded','true');document.addEventListener('mousedown',moreOutside,true);}};
5962
- document.getElementById('sendTeklaB').onclick=()=>{closeMore();sendSelectionToTekla(teklaSelectionIds());};
6023
+ for(const [bid,host] of [['sendTeklaB','tekla'],['sendRevitB','revit'],['sendSketchupB','sketchup']]){
6024
+ const b=document.getElementById(bid);if(b)b.onclick=()=>{closeMore();sendSelectionToHost(host,teklaSelectionIds());};}
5963
6025
  moreMenu.addEventListener('click',e=>{if(e.target.closest('button')&&!e.target.closest('.msnap')&&!e.target.closest('.dtog')&&!e.target.closest('.msec-hdr')&&!e.target.closest('.ins-in-menu'))closeMore();}); // an item's own handler runs (bubble) before this closes the menu; the snap toggles, section headers, and the Insert picker keep the menu open (settings, not one-shot actions)
5964
6026
  // "Snapping" is collapsible to save menu space — the header expands the running-snap switches below it
5965
6027
  // Every ⋯ section is a collapse/expand accordion (Snapping + Display + Detailing + …); state persists in localStorage.
@@ -6095,12 +6157,63 @@ let copesByMember={}, partsById={};
6095
6157
  // insert, so sending the same members twice puts them in twice (undo/delete in Tekla). ---
6096
6158
  let teklaSendBusy=false;
6097
6159
  const teklaSelectionIds=()=>selArr().map(m=>m.id); // members only: grid lines, dimensions and connection parts are never sent (selArr matches against real members)
6098
- async function sendSelectionToTekla(ids){
6160
+ // What the user calls each application. Copy NEVER says "sketchup-2026" or an agent id.
6161
+ const HOST_NAME={tekla:'Tekla',revit:'Revit',sketchup:'SketchUp'};
6162
+ // Tekla keeps its original route (its readiness probe can tell "open but no model loaded", which the
6163
+ // generic one cannot); Revit and SketchUp share the newer one. Same request body either way.
6164
+ const hostSendUrl=(host)=>'/api/contract/'+encodeURIComponent(APP_ID)+(host==='tekla'?'/export-tekla':'/export-host/'+encodeURIComponent(host))+PROJECT_QS;
6165
+
6166
+ /* Resolve where a drag-out was released and send there.
6167
+ The badge that followed the cursor read a snapshot taken when the drag STARTED, so it is a hint,
6168
+ not a decision — this asks the server what is under the release point right now. When that
6169
+ resolves nothing (the desktop, a taskbar, a window we don't know) we do not guess between two
6170
+ open applications: with exactly one running there is no ambiguity worth interrupting for, and
6171
+ with several the user is told to drop on the one they meant rather than having one picked. */
6172
+ async function resolveAndSend(payload){
6173
+ const ids=Array.isArray(payload&&payload.ids)?payload.ids:[];
6174
+ if(!ids.length){toast('Select the members you want to send first.');return;}
6175
+ let host=null,proc=null,pid=null,resolved=false,running=Array.isArray(payload.running)?payload.running:[];
6176
+ try{
6177
+ const r=await fetch('/api/host-at-point',{method:'POST',headers:{'content-type':'application/json'},
6178
+ body:JSON.stringify({screenX:payload.screenX,screenY:payload.screenY,dpr:payload.dpr})});
6179
+ const j=await r.json().catch(()=>({}));
6180
+ // The PID is the WINDOW the user released over. Two Revit sessions can be open, so sending only
6181
+ // "revit" would let the bridge pick the other one — the members would appear, just not where
6182
+ // they were dropped, which is the one promise this gesture makes.
6183
+ if(j&&j.ok){host=j.host||null;proc=j.processName||null;pid=(typeof j.pid==='number'?j.pid:null);
6184
+ resolved=j.resolved!==false;if(Array.isArray(j.running))running=j.running;}
6185
+ }catch(e){/* could not ask at all — treated as an unreadable desktop below */}
6186
+ if(!host){
6187
+ // A drop we READ as "nothing recognised" is the user's aim, and it is refused. "Release over the
6188
+ // app" is the promise this gesture makes, and someone who overshoots onto the desktop while a CAD
6189
+ // app happens to sit open from unrelated work must not get an insert into a model they never
6190
+ // pointed at. Refusing costs a re-drag; guessing costs a wrong model.
6191
+ if(resolved){
6192
+ toast(proc?('Released over '+proc+' — nothing sent. Drag it out again over Tekla, Revit or SketchUp.')
6193
+ :'Released over the desktop — nothing sent. Drag it out again over Tekla, Revit or SketchUp.');
6194
+ return;
6195
+ }
6196
+ // A drop we could NOT READ is a different fact — our failure, not their aim. With exactly one CAD
6197
+ // app open there is no choice to get wrong, so the send goes there rather than making the user pay
6198
+ // for our miss. With none or several we still refuse: a guess is only safe when there is nothing
6199
+ // to guess between.
6200
+ if(running.length!==1){
6201
+ toast(running.length>1
6202
+ ?'Couldn’t tell which app you dropped on — try again, or use ⋯ → Session to pick one.'
6203
+ :'Couldn’t tell what you dropped on — open Tekla, Revit or SketchUp and try again.');
6204
+ return;
6205
+ }
6206
+ host=running[0];pid=null;
6207
+ }
6208
+ return sendSelectionToHost(host,ids,pid);
6209
+ }
6210
+
6211
+ async function sendSelectionToHost(host,ids,hostPid){
6099
6212
  if(teklaSendBusy)return;
6100
6213
  const list=[...new Set((Array.isArray(ids)?ids:[]).filter(Boolean))];
6101
6214
  if(!list.length){toast('Select the members you want to send first.');return;}
6102
- const n=list.length,noun=n===1?'member':'members';
6103
- teklaSendBusy=true;toast('Sending '+n+' '+noun+' to Tekla…',true);
6215
+ const n=list.length,noun=n===1?'member':'members',NAME=HOST_NAME[host]||host;
6216
+ teklaSendBusy=true;toast('Sending '+n+' '+noun+' to '+NAME+'…',true);
6104
6217
  try{
6105
6218
  // Push the on-screen edits first, or a just-moved beam lands at its old place. NOT in a project:
6106
6219
  // there the server exports the APPROVED snapshot (not this draft), while every contract PUT clears
@@ -6112,8 +6225,9 @@ async function sendSelectionToTekla(ids){
6112
6225
  if(PROJECT){
6113
6226
  if(saveT!==null){toast('Approve this version before sending — your latest edits aren’t in the approved model yet.');return;}
6114
6227
  } else await window.flushContract();
6115
- const res=await fetch('/api/contract/'+encodeURIComponent(APP_ID)+'/export-tekla'+PROJECT_QS,
6116
- {method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({memberIds:list})});
6228
+ const res=await fetch(hostSendUrl(host),
6229
+ {method:'POST',headers:{'content-type':'application/json'},
6230
+ body:JSON.stringify(hostPid?{memberIds:list,hostPid:hostPid}:{memberIds:list})});
6117
6231
  const j=await res.json().catch(()=>({}));
6118
6232
  if(!res.ok||!j.ok)throw new Error(j.error||('send failed ('+res.status+')'));
6119
6233
  // Report what TEKLA received, never what we asked for: the server legitimately drops members it
@@ -6124,14 +6238,21 @@ async function sendSelectionToTekla(ids){
6124
6238
  const em=(j.receipt&&Array.isArray(j.receipt.emitted))?j.receipt.emitted:null;
6125
6239
  const got=em?em.filter(r=>r&&r.kind==='member').length:n;
6126
6240
  const gotNoun=got===1?'member':'members',missed=n-got;
6241
+ // A member can land as a generic placeholder solid when its section isn't loaded in the host —
6242
+ // report that rather than let the user find a grey block and assume the export is broken.
6243
+ // One sentence shape across all three hosts — "Inserted {got} of {n} … into {Host} — {why}." —
6244
+ // so only the reason clause varies by host, never the voice.
6245
+ const fell=em?em.filter(r=>r&&r.kind==='member'&&r.fallback).length:0;
6127
6246
  toast(missed>0
6128
- ?'Inserted '+got+' of '+n+' '+noun+' into Tekla — '+missed+' had no size to build yet.'
6129
- :'Inserted '+got+' '+gotNoun+' into Tekla.');
6247
+ ?'Inserted '+got+' of '+n+' '+noun+' into '+NAME+' — '+missed+' had no size to build yet.'
6248
+ :(fell>0
6249
+ ?'Inserted '+got+' of '+n+' '+noun+' into '+NAME+' — '+fell+' used a placeholder shape (their section isn’t loaded in '+NAME+').'
6250
+ :'Inserted '+got+' '+gotNoun+' into '+NAME+'.'));
6130
6251
  }catch(e){
6131
- console.error('send to Tekla failed',e);
6252
+ console.error('send to '+host+' failed',e);
6132
6253
  // The server's own messages are plain English; a transport failure ("Failed to fetch") is not.
6133
6254
  const msg=e&&e.message?e.message:'';
6134
- toast(/failed to fetch|networkerror|load failed/i.test(msg)?'Couldn’t reach the app to send — is it still running?':(msg||'Couldn’t insert into Tekla.'));
6255
+ toast(/failed to fetch|networkerror|load failed/i.test(msg)?'Couldn’t reach the app to send — is it still running?':(msg||('Couldn’t insert into '+NAME+'.')));
6135
6256
  }finally{teklaSendBusy=false;}
6136
6257
  }
6137
6258
 
@@ -6363,7 +6484,10 @@ const view3dApi={
6363
6484
  toast:(m)=>toast(m),
6364
6485
  teklaSelectionIds, // Ctrl+Shift drag-out: the sendable member ids (the badge count and the payload are the same list)
6365
6486
  teklaSendBusy:()=>teklaSendBusy, // one drop at a time — the view refuses to start a second drag mid-send
6366
- onSendToTekla:(ids)=>sendSelectionToTekla(ids),
6487
+ onSendToHost:(payload)=>resolveAndSend(payload),
6488
+ // The z-ordered window stack, fetched ONCE when a drag-out starts so the badge can name the
6489
+ // app under the cursor without a round-trip per pointer move. Advisory: the release re-resolves.
6490
+ hostWindows:async()=>{try{const r=await fetch('/api/host-windows');return await r.json();}catch(e){return null;}},
6367
6491
  // 3D Move/Copy: the 3D view reads the armed tool + counts, and hands commit offsets back in scene mm.
6368
6492
  cmState:()=>cmTool?{tool:cmTool,array:cmArrayMode,count:cmCount,countA:cmCountA,countB:cmCountB}:null,
6369
6493
  // mm → plan px (Y FLIPPED) + inches for dz, now owned by the model boundary. toDisplayOffsets MUTATES