@floless/app 0.101.5 → 0.103.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.
@@ -112,6 +112,9 @@
112
112
  }
113
113
 
114
114
  let exportState = null; // kind → { path, exportedAt } after a successful list; null = unknown/failed
115
+ let teklaReadinessState = null; // latest machine-readable readiness result; {state:'checking'} while probing
116
+ const exportReceipts = new Map(); // projectId:kind → reconciled receipt counts for this browser session
117
+ const exportBusy = new Set(); // projectId:kind → one in-flight export
115
118
  if (!$switch || !$landing || !$app) return; // markup absent — nothing to wire
116
119
 
117
120
  // The picker menu is a `.menu` (display:none by default; `.menu.show` → display:block, which
@@ -535,6 +538,8 @@
535
538
  // matching the create-card skip. wsApp() would return null for it and the frame wiring would fail.
536
539
  if (!WORKSPACE_APPS[p.app]) { showToast('This project’s app isn’t available as a workspace.', 'warn'); return; }
537
540
  current = p;
541
+ exportState = null;
542
+ teklaReadinessState = null;
538
543
  track('workspace_project_opened', { app: p.app }); // a real open (card click or post-create landing)
539
544
  lastRevState = 'none'; stopRevisionPoll(); // fresh project — drop any prior revision-poll state
540
545
  $projName.textContent = p.name;
@@ -557,6 +562,8 @@
557
562
  }
558
563
  function closeProject() {
559
564
  current = null;
565
+ exportState = null;
566
+ teklaReadinessState = null;
560
567
  stopRevisionPoll();
561
568
  stopKnowledgePoll(); kbCloseConfirm(); kbResetViewer(); knowledgeState = null; // the KB pane is per-project — never carry it across
562
569
  lastRevState = 'none'; $revisionCard.hidden = true; closeProjMenu(); applyMode(); syncWorkspaceGuide();
@@ -1838,12 +1845,85 @@
1838
1845
  return `${base}/export-tekla${qs}`; // tekla
1839
1846
  }
1840
1847
 
1848
+ const receiptKey = (kind) => `${current ? current.id : ''}:${kind}`;
1849
+
1850
+ function receiptItemText(prefix, value) {
1851
+ if (typeof value === 'string') return `${prefix}: ${value}`;
1852
+ if (!value || typeof value !== 'object') return `${prefix}: ${String(value)}`;
1853
+ const parts = [value.id, value.code, value.message].filter((part) => typeof part === 'string' && part.trim());
1854
+ if (parts.length) return `${prefix}: ${parts.join(' · ')}`;
1855
+ try { return `${prefix}: ${JSON.stringify(value)}`; }
1856
+ catch { return `${prefix}: detail unavailable`; }
1857
+ }
1858
+
1859
+ function receiptSummary(receipt, kind) {
1860
+ if (!receipt || !receipt.counts) return null;
1861
+ const c = receipt.counts;
1862
+ const parts = [`${Number(c.emitted) || 0} emitted`];
1863
+ if (kind === 'tekla' && Number.isFinite(Number(c.native))) parts.push(`${Number(c.native)} native`);
1864
+ if (Number(c.unsupported)) parts.push(`${Number(c.unsupported)} unsupported`);
1865
+ if (Number(c.warnings)) parts.push(`${Number(c.warnings)} warning${Number(c.warnings) === 1 ? '' : 's'}`);
1866
+ return {
1867
+ text: parts.join(' · '),
1868
+ partial: Number(c.unsupported) > 0 || Number(c.warnings) > 0,
1869
+ details: [
1870
+ ...(Array.isArray(receipt.unsupported) ? receipt.unsupported.map((row) => receiptItemText('Unsupported', row)) : []),
1871
+ ...(Array.isArray(receipt.warnings) ? receipt.warnings.map((warning) => receiptItemText('Warning', warning)) : []),
1872
+ ].join('\n'),
1873
+ };
1874
+ }
1875
+
1876
+ function receiptHtml(kind, approved) {
1877
+ const receipt = exportReceipts.get(receiptKey(kind));
1878
+ if (!approved || !receipt || receipt.approvedAt !== current.approvedAt) return '';
1879
+ const summary = receiptSummary(receipt, kind);
1880
+ if (!summary) return '';
1881
+ return `<div class="e-receipt${summary.partial ? ' partial' : ''}">` +
1882
+ `<span role="status" aria-live="polite">Last export${summary.partial ? ' with gaps' : ''} · ${escapeHtml(summary.text)}</span>` +
1883
+ (summary.details ? `<button type="button" class="e-receipt-details" data-export-details="${escapeAttr(kind)}">View details</button>` : '') +
1884
+ `</div>`;
1885
+ }
1886
+
1887
+ function teklaCardState(approved) {
1888
+ if (!approved) return {
1889
+ meta: '<span class="e-status">Available after approval</span>',
1890
+ disabled: true,
1891
+ tip: 'Approve this version first',
1892
+ };
1893
+ const readiness = teklaReadinessState;
1894
+ if (!readiness || readiness.state === 'checking') return {
1895
+ meta: '<span class="e-readiness checking" role="status" aria-live="polite"><span class="rtn-spinner" aria-hidden="true"></span> Checking Tekla readiness…</span>',
1896
+ disabled: true,
1897
+ tip: 'Checking AWARE, the Tekla bridge, and the open model',
1898
+ };
1899
+ if (readiness.ok && readiness.state === 'ready') {
1900
+ const version = readiness.host && readiness.host.version ? ` · Tekla ${readiness.host.version}` : '';
1901
+ return {
1902
+ meta: `<span class="e-readiness ready" role="status" aria-live="polite">Ready${escapeHtml(version)}</span>`,
1903
+ disabled: false,
1904
+ tip: 'Create native parts in the open Tekla model',
1905
+ };
1906
+ }
1907
+ const recovery = readiness.recovery || { action: 'retry', label: 'Check again' };
1908
+ const label = recovery.action === 'open-tekla' || recovery.action === 'open-model' || recovery.action === 'retry'
1909
+ ? 'Check again'
1910
+ : recovery.label;
1911
+ return {
1912
+ meta: `<span class="e-readiness blocked" role="status" aria-live="polite">${escapeHtml(readiness.message || 'Tekla readiness could not be verified.')}</span>` +
1913
+ `<button type="button" class="e-recovery" data-tekla-recovery="${escapeAttr(recovery.action)}">${escapeHtml(label)}</button>`,
1914
+ disabled: true,
1915
+ tip: readiness.message || 'Resolve the Tekla readiness check first',
1916
+ };
1917
+ }
1918
+
1841
1919
  function cardHtml(c, approved) {
1842
1920
  let meta;
1843
- if (!approved) {
1921
+ const busy = exportBusy.has(`${current.id}:${c.kind}`);
1922
+ const tekla = c.kind === 'tekla' ? teklaCardState(approved) : null;
1923
+ if (tekla) {
1924
+ meta = tekla.meta;
1925
+ } else if (!approved) {
1844
1926
  meta = `<span class="e-status">Available after approval</span>`;
1845
- } else if (!c.file) {
1846
- meta = `<span class="e-status">Creates parts in the open Tekla model</span>`;
1847
1927
  } else if (exportState == null) {
1848
1928
  // The listing failed — say so honestly; never a fake "not exported yet" (silent-failure rule).
1849
1929
  meta = `<span class="e-status">Status unavailable</span>`;
@@ -1860,74 +1940,206 @@
1860
1940
  }
1861
1941
  }
1862
1942
  const exported = approved && c.file && exportState && exportState[c.kind] && exportState[c.kind].exportedAt;
1863
- const label = exported ? 'Re-export' : c.verb;
1864
- const dis = approved ? '' : ' disabled data-tip="Approve this version first"';
1943
+ const label = busy ? (c.kind === 'tekla' ? 'Sending…' : 'Exporting…') : (exported ? 'Re-export' : c.verb);
1944
+ const disabled = tekla ? tekla.disabled : !approved;
1945
+ const tip = busy ? (c.kind === 'tekla' ? 'Sending the approved model to Tekla' : 'Export in progress')
1946
+ : tekla ? tekla.tip : (approved ? '' : 'Approve this version first');
1947
+ const dis = `${disabled && !busy ? ' disabled' : ''}${busy ? ' aria-disabled="true" aria-busy="true"' : ''}${tip ? ` data-tip="${escapeAttr(tip)}"` : ''}`;
1865
1948
  return `<div class="ecard">` +
1866
1949
  `<div class="e-top"><div class="e-ico">${escapeHtml(c.ico)}</div>` +
1867
1950
  `<div><div class="e-name">${escapeHtml(c.name)}</div><div class="e-fmt">${escapeHtml(c.fmt)}</div></div></div>` +
1868
- `<div class="e-meta">${meta}</div>` +
1951
+ `<div class="e-meta${tekla ? ' e-meta-tekla' : ''}">${meta}</div>` +
1952
+ receiptHtml(c.kind, approved) +
1869
1953
  `<div class="e-act"><button type="button" data-export="${escapeAttr(c.kind)}"${dis}>↗ ${escapeHtml(label)}</button></div>` +
1870
1954
  `</div>`;
1871
1955
  }
1872
1956
 
1957
+ const EXPORT_FOCUS_ATTRS = [
1958
+ 'data-export',
1959
+ 'data-openfile',
1960
+ 'data-reveal',
1961
+ 'data-export-details',
1962
+ 'data-tekla-recovery',
1963
+ ];
1964
+
1965
+ function exportFocusIdentity(element) {
1966
+ if (!element || !$wsExports.contains(element)) return null;
1967
+ const cardKind = element.closest('.ecard')?.querySelector('[data-export]')?.dataset.export || null;
1968
+ for (const attr of EXPORT_FOCUS_ATTRS) {
1969
+ if (element.hasAttribute(attr)) return { attr, value: element.getAttribute(attr), cardKind };
1970
+ }
1971
+ return element.id === 'ws-exports-approve' ? { id: element.id, cardKind: null } : null;
1972
+ }
1973
+
1974
+ function restoreExportFocus(identity) {
1975
+ if (!identity) return;
1976
+ const replacement = identity.id
1977
+ ? $wsExports.querySelector(`#${identity.id}`)
1978
+ : Array.from($wsExports.querySelectorAll(`[${identity.attr}]`))
1979
+ .find((candidate) => candidate.getAttribute(identity.attr) === identity.value);
1980
+ if (replacement && !replacement.disabled) {
1981
+ replacement.focus();
1982
+ return;
1983
+ }
1984
+ if (!identity.cardKind) return;
1985
+ const card = Array.from($wsExports.querySelectorAll('.ecard'))
1986
+ .find((candidate) => candidate.querySelector('[data-export]')?.dataset.export === identity.cardKind);
1987
+ card?.querySelector('.e-recovery:not([disabled]), [data-export]:not([disabled])')?.focus();
1988
+ }
1989
+
1990
+ function paintExports(approvedAt, requestedRestoreKind) {
1991
+ const restoreIdentity = requestedRestoreKind
1992
+ ? { attr: 'data-export', value: requestedRestoreKind, cardKind: requestedRestoreKind }
1993
+ : exportFocusIdentity(document.activeElement);
1994
+ const approved = !!approvedAt;
1995
+ let html = '';
1996
+ if (!approved) {
1997
+ html += `<div class="ws-exports-gate">Exports go out after sign-off — ` +
1998
+ `<button type="button" id="ws-exports-approve">Approve this version</button> to enable them.</div>`;
1999
+ }
2000
+ html += `<div class="exports-note"><b>Export at any stage</b> — polishing is optional. ` +
2001
+ `Each writes to this project’s <code>exports</code> folder.</div>`;
2002
+ const cards = (wsApp() && wsApp().exports) || [];
2003
+ html += '<div class="export-grid">' + cards.map((c) => cardHtml(c, approved)).join('') + '</div>';
2004
+ $wsExports.innerHTML = html;
2005
+ restoreExportFocus(restoreIdentity);
2006
+ }
2007
+
1873
2008
  async function renderExports() {
1874
2009
  if (!current) return;
1875
2010
  const id = current.id, app = current.app;
1876
- $wsExports.innerHTML = '<div class="exports-note">Loading exports…</div>'; // avoid a blank flash
2011
+ const cards = (wsApp() && wsApp().exports) || [];
2012
+ const hasTekla = cards.some((card) => card.kind === 'tekla');
2013
+ teklaReadinessState = hasTekla ? { ok: false, state: 'checking' } : null;
2014
+ paintExports(current.approvedAt);
1877
2015
  let state = null;
1878
2016
  let approvedAt = current.approvedAt; // fallback if the fetch fails (best-known)
1879
- try {
1880
- const r = await api(`/api/contract/${encodeURIComponent(app)}/exports?project=${encodeURIComponent(id)}`);
2017
+ const exportPromise = api(`/api/contract/${encodeURIComponent(app)}/exports?project=${encodeURIComponent(id)}`);
2018
+ const readinessPromise = hasTekla ? api('/api/tekla-readiness') : Promise.resolve(null);
2019
+ const [exportResult, readinessResult] = await Promise.allSettled([exportPromise, readinessPromise]);
2020
+ if (exportResult.status === 'fulfilled') {
2021
+ const r = exportResult.value;
1881
2022
  state = {};
1882
2023
  for (const e of r.exports || []) state[e.kind] = e;
1883
2024
  // Authoritative gate state: an in-session edit clears approvedAt server-side, so trust the
1884
2025
  // server, not the possibly-stale current.approvedAt — and re-sync current to match.
1885
2026
  approvedAt = r.approvedAt || undefined;
1886
2027
  current.approvedAt = approvedAt;
1887
- } catch (err) {
2028
+ } else {
2029
+ const err = exportResult.reason;
1888
2030
  // Surface the load failure — don't let it read as "nothing exported yet" (a lie).
1889
2031
  showToast('Couldn’t load export status: ' + (err && err.message || err), 'warn');
1890
2032
  state = null;
1891
2033
  }
2034
+ if (hasTekla) {
2035
+ teklaReadinessState = readinessResult.status === 'fulfilled'
2036
+ ? readinessResult.value.readiness
2037
+ : {
2038
+ ok: false,
2039
+ state: 'error',
2040
+ message: readinessResult.reason && readinessResult.reason.message
2041
+ ? readinessResult.reason.message
2042
+ : 'Could not verify Tekla readiness.',
2043
+ recovery: { action: 'retry', label: 'Check again' },
2044
+ };
2045
+ }
1892
2046
  // The user may have switched project/step during the await — don't paint stale.
1893
2047
  if (!current || current.id !== id || $wsExports.hidden) return;
1894
2048
  exportState = state;
1895
2049
  syncWorkspaceGuide(); // fresh approve/export state → tick the Export (and re-sync Approve) guide rows
1896
- const approved = !!approvedAt;
1897
- let html = '';
1898
- if (!approved) {
1899
- html += `<div class="ws-exports-gate">Exports go out after sign-off — ` +
1900
- `<button type="button" id="ws-exports-approve">Approve this version</button> to enable them.</div>`;
1901
- }
1902
- html += `<div class="exports-note"><b>Export at any stage</b> — polishing is optional. ` +
1903
- `Each writes to this project’s <code>exports</code> folder.</div>`;
1904
- const cards = (wsApp() && wsApp().exports) || [];
1905
- html += '<div class="export-grid">' + cards.map((c) => cardHtml(c, approved)).join('') + '</div>';
1906
- $wsExports.innerHTML = html;
2050
+ paintExports(approvedAt);
1907
2051
  }
1908
2052
 
1909
2053
  async function doExport(kind) {
1910
2054
  if (!current) return;
1911
- const app = current.app; // capture — the user may switch projects during the await
1912
- const btn = $wsExports.querySelector(`[data-export="${kind}"]`);
1913
- const prev = btn ? btn.textContent : '';
1914
- if (btn) { btn.disabled = true; btn.textContent = kind === 'tekla' ? 'Baking…' : 'Exporting…'; }
2055
+ const app = current.app, projectId = current.id, approvedAt = current.approvedAt; // capture — the user may switch projects during the await
2056
+ const busyKey = `${projectId}:${kind}`;
2057
+ if (exportBusy.has(busyKey)) return;
2058
+ exportBusy.add(busyKey);
2059
+ // The delegated click can report BODY as active by the time this synchronous repaint runs.
2060
+ // Carry the activated kind through the first replacement explicitly; later repaints infer
2061
+ // focus normally, so moving elsewhere during a long export is still respected.
2062
+ paintExports(current.approvedAt, kind);
1915
2063
  try {
1916
2064
  const res = await api(exportUrl(kind), { method: 'POST' });
1917
2065
  track('workspace_export', { app, kind }); // a successful export/bake (e.g. { app:'vectorize', kind:'svg' })
2066
+ if (res.counts) exportReceipts.set(`${projectId}:${kind}`, {
2067
+ counts: res.counts,
2068
+ warnings: res.warnings || [],
2069
+ unsupported: res.receipt && Array.isArray(res.receipt.unsupported) ? res.receipt.unsupported : [],
2070
+ approvedAt,
2071
+ });
2072
+ const summary = receiptSummary(exportReceipts.get(`${projectId}:${kind}`), kind);
1918
2073
  if (kind === 'tekla') {
1919
- const dropped = Array.isArray(res.skipped) ? res.skipped.length : 0;
1920
- showToast((res.message || 'Baked into the Tekla model.') + (dropped ? ` · ${dropped} RFI member(s) skipped` : ''), 'ok');
2074
+ showToast(summary && summary.partial
2075
+ ? `Sent to Tekla with gaps — ${summary.text}`
2076
+ : (res.message || 'Baked into the Tekla model.'),
2077
+ summary && summary.partial ? 'warn' : 'ok');
1921
2078
  } else {
1922
- showToast(`Exported — ${res.filename || kind}`, 'ok');
1923
- return renderExports(); // repaint with the new "✓ exported HH:MM" + Open/Reveal
2079
+ showToast(summary && summary.partial
2080
+ ? `Exported with gaps — ${summary.text}`
2081
+ : `Exported — ${res.filename || kind}`,
2082
+ summary && summary.partial ? 'warn' : 'ok');
1924
2083
  }
2084
+ return renderExports(); // repaint status + the authoritative receipt summary
1925
2085
  } catch (err) {
2086
+ // The durable export listing may still show the previously published file, but its in-session
2087
+ // receipt must not masquerade as the result of this failed attempt.
2088
+ exportReceipts.delete(`${projectId}:${kind}`);
1926
2089
  const needsTekla = err && err.body && err.body.needsTekla;
2090
+ if (kind === 'tekla' && err && err.body && err.body.readiness) teklaReadinessState = err.body.readiness;
1927
2091
  showToast(err && err.message ? err.message : String(err), needsTekla ? 'info' : 'warn');
2092
+ if (kind === 'tekla' && current && current.id === projectId) paintExports(current.approvedAt);
1928
2093
  } finally {
1929
- if (btn && btn.isConnected) { btn.disabled = false; btn.textContent = prev; }
2094
+ exportBusy.delete(busyKey);
2095
+ if (current && current.id === projectId) paintExports(current.approvedAt);
2096
+ }
2097
+ }
2098
+
2099
+ function showExportReceiptDetails(kind, returnFocusTo) {
2100
+ const projectId = current && current.id;
2101
+ const receipt = exportReceipts.get(receiptKey(kind));
2102
+ const summary = receiptSummary(receipt, kind);
2103
+ if (!summary || !summary.details || !bridge.formModal) return;
2104
+ bridge.formModal({
2105
+ title: `${kind === 'tekla' ? 'Tekla' : 'IFC'} export details`,
2106
+ sub: 'Details from the last successful export for this approved version.',
2107
+ fields: [{ name: 'details', label: 'Receipt details', type: 'note', value: summary.details }],
2108
+ okLabel: 'Close',
2109
+ hideCancel: true,
2110
+ returnFocusTo,
2111
+ returnFocusFallback: () => current && current.id === projectId
2112
+ ? $wsExports.querySelector(`[data-export-details="${kind}"]`)
2113
+ : null,
2114
+ });
2115
+ }
2116
+
2117
+ async function recoverTekla(action) {
2118
+ if (!current) return;
2119
+ if (action === 'open-tekla' || action === 'open-model' || action === 'retry') {
2120
+ return renderExports();
2121
+ }
2122
+ teklaReadinessState = { ok: false, state: 'checking' };
2123
+ paintExports(current.approvedAt);
2124
+ try {
2125
+ if (action === 'update-aware') {
2126
+ if (!bridge.formModal) throw new Error('Could not open the AWARE update dialog.');
2127
+ const go = await bridge.formModal({
2128
+ title: 'Update AWARE runtime',
2129
+ sub: 'Installs the current AWARE release in place. FloLess stays open.',
2130
+ fields: [],
2131
+ okLabel: 'Update AWARE',
2132
+ });
2133
+ if (!go) return renderExports();
2134
+ await api('/api/aware/update/apply', { method: 'POST', signal: AbortSignal.timeout(120000) });
2135
+ } else if (action === 'install-bridge') {
2136
+ await api('/api/tekla-readiness/setup', { method: 'POST' });
2137
+ }
2138
+ showToast(action === 'update-aware' ? 'AWARE updated.' : 'Tekla bridge installed.', 'ok');
2139
+ } catch (err) {
2140
+ showToast(err && err.message ? err.message : String(err), 'warn');
1930
2141
  }
2142
+ return renderExports();
1931
2143
  }
1932
2144
 
1933
2145
  async function fileAction(endpoint, kind, failMsg) {
@@ -1943,6 +2155,10 @@
1943
2155
 
1944
2156
  $wsExports.addEventListener('click', (e) => {
1945
2157
  if (e.target.closest('#ws-exports-approve')) { approveProject(); return; }
2158
+ const details = e.target.closest('[data-export-details]');
2159
+ if (details) { showExportReceiptDetails(details.dataset.exportDetails, details); return; }
2160
+ const recovery = e.target.closest('[data-tekla-recovery]');
2161
+ if (recovery) { recoverTekla(recovery.dataset.teklaRecovery); return; }
1946
2162
  const exp = e.target.closest('[data-export]');
1947
2163
  if (exp && !exp.disabled) { doExport(exp.dataset.export); return; }
1948
2164
  const open = e.target.closest('[data-openfile]');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floless/app",
3
- "version": "0.101.5",
3
+ "version": "0.103.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": {