@floless/app 0.168.0 → 0.170.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli-actions.mjs +8 -1
- package/dist/floless-server.cjs +125533 -99597
- package/dist/schemas/drawing-check.profile.v1.schema.json +12 -2
- package/dist/schemas/steel.model.v2.schema.json +2 -1
- package/dist/skills/floless-app-knowledge/SKILL.md +43 -13
- package/dist/skills/floless-app-new-workflow/SKILL.md +8 -1
- package/dist/skills/floless-app-rfi/SKILL.md +4 -2
- package/dist/skills/floless-app-routines/SKILL.md +2 -2
- package/dist/skills/floless-app-routines/references/routines-api.md +20 -8
- package/dist/skills/floless-app-steel-model/SKILL.md +8 -5
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +31 -1
- package/dist/skills/floless-app-workflows/SKILL.md +22 -3
- package/dist/skills/floless-app-workflows/references/agent-steps.md +40 -6
- package/dist/skills/floless-app-workflows/references/exec-contract.md +27 -0
- package/dist/skills/floless-app-workflows/references/script-runner.md +105 -0
- package/dist/templates/college-phase-exporter.flo +7 -2
- package/dist/templates/trimble-list-projects.flo +10 -2
- package/dist/web/agent-steps.js +90 -19
- package/dist/web/agents.js +77 -31
- package/dist/web/app.css +267 -4
- package/dist/web/app.js +71 -7
- package/dist/web/aware-update-client.js +4 -4
- package/dist/web/aware.js +1277 -219
- package/dist/web/chat.css +10 -0
- package/dist/web/chat.js +407 -117
- package/dist/web/checkpoint-standard.js +5 -3
- package/dist/web/commands-drawing-check.js +4 -0
- package/dist/web/commands-shell.js +551 -15
- package/dist/web/commands-steel.js +68 -2
- package/dist/web/commands-vector.js +69 -0
- package/dist/web/drawing-check-editor.html +10 -0
- package/dist/web/drawing-check-editor.js +821 -237
- package/dist/web/failure-copy.js +50 -2
- package/dist/web/filter-ai-proposal.js +11 -8
- package/dist/web/flo-3d.js +310 -0
- package/dist/web/flo-card.js +72 -0
- package/dist/web/guide.js +33 -24
- package/dist/web/index.html +95 -5
- package/dist/web/instructor.js +102 -15
- package/dist/web/left-pane.js +4 -1
- package/dist/web/local-discovery.js +8 -7
- package/dist/web/missed-routines.js +239 -0
- package/dist/web/model-editor-steel-adapter.js +41 -1
- package/dist/web/model-measure.js +6 -0
- package/dist/web/model-spatial-panel.js +19 -4
- package/dist/web/model-spatial-tools.js +3 -3
- package/dist/web/model-viewport-revit-adapter.js +3 -3
- package/dist/web/model-viewport-toolbar.js +11 -0
- package/dist/web/origin-rule.js +155 -0
- package/dist/web/pages.js +17 -14
- package/dist/web/panels.js +1 -1
- package/dist/web/project-access.js +1 -1
- package/dist/web/project-history.js +2 -2
- package/dist/web/project-modules.js +5 -5
- package/dist/web/project-reconciliation.js +1 -1
- package/dist/web/project-rfis.js +8 -3
- package/dist/web/project-workflows.js +8 -6
- package/dist/web/renderers.js +6 -0
- package/dist/web/report-csp.js +68 -0
- package/dist/web/revit-editor.js +22 -8
- package/dist/web/run-history.js +14 -4
- package/dist/web/steel-3d-core.js +39 -9
- package/dist/web/steel-3d-flo.js +331 -0
- package/dist/web/steel-3d-view.js +164 -0
- package/dist/web/steel-ai-marks.js +3 -1
- package/dist/web/steel-editor.html +583 -129
- package/dist/web/steel-environments.js +297 -0
- package/dist/web/steel-filter.html +3 -2
- package/dist/web/steel-model-v2-client-validation.js +8 -1
- package/dist/web/steel-model-v2-commands.js +23 -9
- package/dist/web/steel-model-v2-projection.js +1 -1
- package/dist/web/step-rename.js +3 -2
- package/dist/web/terminal-requests.js +79 -1
- package/dist/web/tool-updates.js +9 -7
- package/dist/web/vector-3d.html +1 -1
- package/dist/web/vector-editor.html +50 -8
- package/dist/web/workspace-root-management.js +1 -1
- package/dist/web/workspaces.js +2334 -253
- package/launch.mjs +5 -0
- package/package.json +11 -8
package/dist/web/run-history.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
const api = bridge.api || (async (path) => {
|
|
9
9
|
const res = await fetch(path);
|
|
10
10
|
const body = await res.json().catch(() => ({}));
|
|
11
|
-
if (!res.ok) throw Object.assign(new Error(body
|
|
11
|
+
if (!res.ok) throw Object.assign(new Error(personText(body) || failureCopy({ status: res.status, body }, { action: 'load the run history', retrySafe: true }).text), { status: res.status, body });
|
|
12
12
|
return body;
|
|
13
13
|
});
|
|
14
14
|
const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
|
@@ -48,6 +48,16 @@
|
|
|
48
48
|
return `${Math.floor(s / 3600)} h ${Math.floor((s % 3600) / 60)} min`;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
// #3253: a run that went ahead although its FloLess steps were set to reach another FloLess on this computer (Run anyway),
|
|
52
|
+
// or where FloLess could not check. "Set to reach", never "reached": FloLess knows what the approved workflow names.
|
|
53
|
+
function elsewherePill(e) {
|
|
54
|
+
const port = Number.isInteger(e.port) ? ` (port ${e.port})` : '';
|
|
55
|
+
const tip = e.kind === 'foreign'
|
|
56
|
+
? `Run anyway: its FloLess steps were set to reach another FloLess on this computer${port}, so its project steps may have read that FloLess’s projects and its AI steps may not have started.`
|
|
57
|
+
: 'FloLess couldn’t check which FloLess this workflow’s steps reach, so it ran as normal.';
|
|
58
|
+
return `<span class="rh-pill" tabindex="0" data-tip="${esc(tip)}">${e.kind === 'foreign' ? 'Another FloLess' : 'Not checked'}</span>`;
|
|
59
|
+
}
|
|
60
|
+
|
|
51
61
|
function rowHtml(w, r) {
|
|
52
62
|
const key = r.runId || `${r.routine?.id || 'routine'}@${r.startedAt}`;
|
|
53
63
|
const label = `${w.name}, ${when(r.startedAt)}`;
|
|
@@ -58,6 +68,7 @@
|
|
|
58
68
|
r.routine ? `<span class="rh-pill" data-tip="${esc(`Started by the routine “${r.routine.name}”.`)}">Routine: ${esc(r.routine.name)}</span>` : '',
|
|
59
69
|
r.aiStep ? `<span class="pg-ai-badge rh-ai" tabindex="0" data-tip="${esc(AI_TIP)}">AI step</span>` : '',
|
|
60
70
|
r.simulated && r.outcome !== 'simulated' ? `<span class="rh-pill" data-tip="${esc(SIM_TIP)}">Simulated</span>` : '',
|
|
71
|
+
r.elsewhere ? elsewherePill(r.elsewhere) : '',
|
|
61
72
|
].join('');
|
|
62
73
|
const report = r.report && r.runId && !w.damaged && !w.missing
|
|
63
74
|
? `<button type="button" class="btn-mini rh-btn" data-rh-report="${esc(r.runId)}" data-rh-app="${esc(w.id)}" data-command-id="shell.workflows-history-report#${esc(r.runId)}" data-command-instance-label="${esc(label)}" aria-label="${esc(`View report: ${label}`)}" data-tip="Opens the report this run made">View report</button>` : '';
|
|
@@ -145,8 +156,7 @@
|
|
|
145
156
|
console.warn('The run history could not be read', err);
|
|
146
157
|
cache = null;
|
|
147
158
|
container.dataset.rhState = 'error';
|
|
148
|
-
const said =
|
|
149
|
-
: 'FloLess couldn’t read the run history. Check that FloLess is running, then try again.';
|
|
159
|
+
const said = personText(err?.body) || 'FloLess couldn’t read the run history. Check that FloLess is running, then try again.';
|
|
150
160
|
container.innerHTML = `<div class="pg-empty" role="alert"><p>${esc(said)}</p>`
|
|
151
161
|
+ `<p><button type="button" class="ghost rh-act" data-rh-act="retry" data-command-id="shell.workflows-history-retry">Try again</button></p></div>`;
|
|
152
162
|
return;
|
|
@@ -184,7 +194,7 @@
|
|
|
184
194
|
const report = event.target.closest('[data-rh-report]');
|
|
185
195
|
if (report) {
|
|
186
196
|
Promise.resolve(opts.openReport?.(report.dataset.rhApp, report.dataset.rhReport))
|
|
187
|
-
.catch((err) => toast(err
|
|
197
|
+
.catch((err) => toast(errorText(err, { action: 'open that run’s report', retrySafe: true }), 'warn'));
|
|
188
198
|
return;
|
|
189
199
|
}
|
|
190
200
|
const act = event.target.closest('[data-rh-act]');
|
|
@@ -34,6 +34,10 @@ export { clipSegmentToPlanes } from './model-viewport-state.js';
|
|
|
34
34
|
// conversion in disguise — which is why it spells the constant rather than the number, and why this
|
|
35
35
|
// file leaves the geometry guard's literal ratchet at zero.
|
|
36
36
|
import { FT_TO_MM, IN_TO_MM, LB_PER_FT_TO_KG_PER_M } from './steel-units.js';
|
|
37
|
+
import {
|
|
38
|
+
COLUMN_BELOW_REACH_MM_IMPERIAL, COLUMN_BELOW_REACH_MM_METRIC as REGISTRY_BELOW_METRIC,
|
|
39
|
+
COLUMN_NEAR_CUT_MM_IMPERIAL, COLUMN_NEAR_CUT_MM_METRIC as REGISTRY_NEAR_CUT_METRIC, traitsFor,
|
|
40
|
+
} from './steel-environments.js';
|
|
37
41
|
export { FT_TO_MM, IN_TO_MM, LB_PER_FT_TO_KG_PER_M };
|
|
38
42
|
|
|
39
43
|
/** Atomic capability marker: storage, readers, authoring and shipped guidance advance together. */
|
|
@@ -186,7 +190,19 @@ export function reexpressMemberPlacement(member, refFrom, refTo, target, extents
|
|
|
186
190
|
* EHS carries no entry either: an ellipse has no member of the SectionKind union, so it stays BOX here
|
|
187
191
|
* and is refused as geometry upstream (`displaySectionForRow` → unsupported-custom), never drawn.
|
|
188
192
|
*
|
|
189
|
-
*
|
|
193
|
+
* THE EU FAMILIES (EU epic #3197, EU-2) are the entries carrying a third element, `'token'`: they match the
|
|
194
|
+
* designation's whole leading LETTER RUN, not a prefix. Their names are one to three letters, and a prefix
|
|
195
|
+
* would read `KKB…` or `KU…` (cold-formed channels the EU catalogue does not retain) as `KK`, `NOTCH…` as
|
|
196
|
+
* `N`, `HLB…` as `HL`. `KK200/100/5` has the run `KK`; `KKB100` has `KKB`, which no entry names. Each maps
|
|
197
|
+
* to an EXISTING kind only: the I and H families to 'I', the channels to 'C', `L` to 'L' (the prefix entry
|
|
198
|
+
* above already covers it), the hollow `KK` (cold-formed) and `KW` (hot-finished) to 'TUBE', and the
|
|
199
|
+
* circular `N` also to 'TUBE' — its roundness is the catalogue row's (`section.round`), exactly as a `CHS`
|
|
200
|
+
* or `HSS6.625X0.280` is, never the designation's. The tees `T` and `GT` ride to 'I' for the reason the
|
|
201
|
+
* UK tees do: a resolved tee draws from its displaySection, this is only the fallback.
|
|
202
|
+
* The families the Tekla default environment adds sizes under are whole tokens too: `HD` to 'I', `USP` to 'C', and
|
|
203
|
+
* `CFRHS`/`HFRHS`/`HFSHS`/`CFCHS`/`HFCHS` to 'TUBE' (as prefixes the first two would read as the channel `C`).
|
|
204
|
+
*
|
|
205
|
+
* @type {ReadonlyArray<readonly [string, SectionKind] | readonly [string, SectionKind, 'token']>}
|
|
190
206
|
*/
|
|
191
207
|
export const SECTION_FAMILIES = [
|
|
192
208
|
['W', 'I'], ['M', 'I'], ['S', 'I'], ['HP', 'I'], // US I-family
|
|
@@ -198,6 +214,18 @@ export const SECTION_FAMILIES = [
|
|
|
198
214
|
['L', 'L'], ['UKA', 'L'], ['RSA', 'L'], // angles (UK equal/unequal + legacy RSA)
|
|
199
215
|
['HSS', 'TUBE'], ['PIPE', 'TUBE'], ['TS', 'TUBE'], ['TUBE', 'TUBE'], ['HSQ', 'TUBE'],
|
|
200
216
|
['SHS', 'TUBE'], ['RHS', 'TUBE'], ['CHS', 'TUBE'], // hollow sections
|
|
217
|
+
// EU (EN) families, whole letter-run only. IPE and L are reached by the prefix entries above (an equal-length
|
|
218
|
+
// token entry could never win, so none is listed); HEA/HEB/HEM/HEAA are longer than their `HE` prefix and are listed.
|
|
219
|
+
['HEA', 'I', 'token'], ['HEB', 'I', 'token'], ['HEM', 'I', 'token'], ['HEAA', 'I', 'token'],
|
|
220
|
+
['INP', 'I', 'token'], ['HL', 'I', 'token'],
|
|
221
|
+
['UPE', 'C', 'token'], ['UNP', 'C', 'token'], ['UAP', 'C', 'token'],
|
|
222
|
+
['KK', 'TUBE', 'token'], ['KW', 'TUBE', 'token'], ['N', 'TUBE', 'token'],
|
|
223
|
+
['T', 'I', 'token'], ['GT', 'I', 'token'],
|
|
224
|
+
// EU sizes added from the Tekla default environment (#3197): its own family spellings. Whole token for the
|
|
225
|
+
// same reason — as prefixes `CFRHS`/`CFCHS` would read as the channel `C`, `USP` as the I `S`, `HD` as nothing.
|
|
226
|
+
['HD', 'I', 'token'], ['USP', 'C', 'token'],
|
|
227
|
+
['CFRHS', 'TUBE', 'token'], ['HFRHS', 'TUBE', 'token'], ['HFSHS', 'TUBE', 'token'],
|
|
228
|
+
['CFCHS', 'TUBE', 'token'], ['HFCHS', 'TUBE', 'token'],
|
|
201
229
|
];
|
|
202
230
|
|
|
203
231
|
/**
|
|
@@ -235,10 +263,12 @@ export function sectionKindOf(profile) {
|
|
|
235
263
|
/** @type {SectionKind} */
|
|
236
264
|
let kind = 'BOX';
|
|
237
265
|
let best = 0;
|
|
266
|
+
// The designation's leading letter run, for the whole-token (EU) entries: `KK200/100/5` -> `KK`.
|
|
267
|
+
const run = /^[A-Z]+/.exec(p)?.[0] ?? '';
|
|
238
268
|
// No cast on `familyKind`: the table is annotated, so a bad entry is a problem at the table (where
|
|
239
269
|
// section-kind.test.ts checks for it) rather than something an assertion here quietly waves through.
|
|
240
|
-
for (const [prefix, familyKind] of SECTION_FAMILIES) {
|
|
241
|
-
if (prefix.length > best && p.startsWith(prefix)) {
|
|
270
|
+
for (const [prefix, familyKind, match] of SECTION_FAMILIES) {
|
|
271
|
+
if (prefix.length > best && (match === 'token' ? run === prefix : p.startsWith(prefix))) {
|
|
242
272
|
best = prefix.length;
|
|
243
273
|
kind = familyKind;
|
|
244
274
|
}
|
|
@@ -1148,7 +1178,7 @@ export function sheetIncludesElevation(fromZ, toZ, elevMm, tol = MODEL_V2_TOL.CU
|
|
|
1148
1178
|
* the read binds it). Smaller means a missed column that "Add to this view" fixes; larger means dashed
|
|
1149
1179
|
* clutter that cannot be removed from the sheet.
|
|
1150
1180
|
*/
|
|
1151
|
-
export const COLUMN_BELOW_REACH_MM =
|
|
1181
|
+
export const COLUMN_BELOW_REACH_MM = COLUMN_BELOW_REACH_MM_IMPERIAL; // 12" = one foot; the figure lives in the trait registry (steel-environments.js), which takes it from the one definition of the foot
|
|
1152
1182
|
|
|
1153
1183
|
/**
|
|
1154
1184
|
* The same convention for a project built to a metric standard: a round 300 mm, not the 304.8 a
|
|
@@ -1167,11 +1197,11 @@ export const COLUMN_BELOW_REACH_MM = FT_TO_MM; // 12" = one foot, from the one
|
|
|
1167
1197
|
* immutable, is a property of the project rather than of the reader, and is exactly the question
|
|
1168
1198
|
* "which standard is this built to".
|
|
1169
1199
|
*/
|
|
1170
|
-
export const COLUMN_BELOW_REACH_MM_METRIC = 300
|
|
1200
|
+
export const COLUMN_BELOW_REACH_MM_METRIC = REGISTRY_BELOW_METRIC; // 300 — declared once, in the trait registry
|
|
1171
1201
|
|
|
1172
1202
|
/** The default reach for a project built to `environment` — metric standards get the round number. */
|
|
1173
1203
|
export function defaultColumnBelowReach(environment) {
|
|
1174
|
-
return environment
|
|
1204
|
+
return traitsFor(environment).columnBelowReachMm;
|
|
1175
1205
|
}
|
|
1176
1206
|
|
|
1177
1207
|
/**
|
|
@@ -1251,10 +1281,10 @@ export function columnCutRelation(fromZ, toZ, cutMm, reach = COLUMN_BELOW_REACH_
|
|
|
1251
1281
|
* show them anyway. Keyed on the project's environment for the reason `defaultColumnBelowReach` is. Not in
|
|
1252
1282
|
* the frozen `MODEL_V2_TOL`, which is merge/refusal semantics.
|
|
1253
1283
|
*/
|
|
1254
|
-
export const COLUMN_NEAR_CUT_MM_METRIC = 50
|
|
1255
|
-
export const COLUMN_NEAR_CUT_MM =
|
|
1284
|
+
export const COLUMN_NEAR_CUT_MM_METRIC = REGISTRY_NEAR_CUT_METRIC; // 50 — declared once, in the trait registry
|
|
1285
|
+
export const COLUMN_NEAR_CUT_MM = COLUMN_NEAR_CUT_MM_IMPERIAL;
|
|
1256
1286
|
export function defaultColumnNearCut(environment) {
|
|
1257
|
-
return environment
|
|
1287
|
+
return traitsFor(environment).columnNearCutMm;
|
|
1258
1288
|
}
|
|
1259
1289
|
|
|
1260
1290
|
/**
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
// Flo on the steel model (3D). web/flo-3d.js builds and moves Flo; this decides where Flo stands and which mood
|
|
2
|
+
// it shows, from what is already true in the editor:
|
|
3
|
+
// - it perches on the model: on load, on the top of the highest member nearest the middle;
|
|
4
|
+
// - when the person selects a member, Flo hops onto it;
|
|
5
|
+
// - when AI Chat is working on this project, Flo shows the same mood the chat's own Flo shows (thinking or
|
|
6
|
+
// working), and Your call while the AI waits for the person's answer or approval (the shell pushes this);
|
|
7
|
+
// - after the model changed underneath the editor (the AI wrote it), Flo visits each member that changed.
|
|
8
|
+
// Flo is decoration and decides nothing: it is never picked as a member, never in Fit or snapping, and a click on
|
|
9
|
+
// it only tips its hat. Flo is off until the person turns it on (3D toolbar → Labels → Show Flo); the page owns that switch
|
|
10
|
+
// and the Minimize beside Flo, and tells this module only whether Flo is shown.
|
|
11
|
+
//
|
|
12
|
+
// Where Flo stands is reported to the caller (onPerch), so the view can show Flo's card about that member: on
|
|
13
|
+
// landing on a member the person selected (for as long as it stays selected) and at each stop of a tour of what
|
|
14
|
+
// changed. Never on the first drop onto the model, which is not about any member.
|
|
15
|
+
|
|
16
|
+
import { createFlo3D } from './flo-3d.js';
|
|
17
|
+
|
|
18
|
+
const MODEL_R_OF_DIAG = 0.011; // Flo's ring radius as a share of the model's diagonal...
|
|
19
|
+
const MODEL_R_MIN = 140, MODEL_R_MAX = 900; // ...in mm: a toy on a beam, never a giant on a shed
|
|
20
|
+
const MIN_SCREEN_R_PX = 13; // and never smaller than this on screen
|
|
21
|
+
const VISIT_MAX = 10; // a big change is shown by its first ten members, not all of them
|
|
22
|
+
const VISIT_DWELL_S = 1.2; // long enough on each changed member to read Flo's card about it
|
|
23
|
+
const SUCCESS_S = 2.4;
|
|
24
|
+
const REMEMBER_KEY = 'flo3d:before:'; // sessionStorage, per editor URL: the model as it was before a reload
|
|
25
|
+
const REMEMBER_TTL_MS = 120_000;
|
|
26
|
+
const SETTLE_MS = 250; // a click-through of members moves Flo once, when it stops
|
|
27
|
+
const ALONG = 0.3; // a beam's perch: this far along it, clear of the label and the ends
|
|
28
|
+
const LEAVE_S = 0.2; // Minimize: Flo shrinks away this fast (instant under reduced motion)
|
|
29
|
+
const HALF_WIDTH_R = 1.5; // Flo's reach either side of its middle, in r: the hat's brim (1.25 r) widened by a hop's squash
|
|
30
|
+
|
|
31
|
+
export function createSteelFlo({ THREE, scene, meshById, getCamera, getSceneBox, pxToWorldAt, floPose, reducedMotion, enabled: startEnabled = false, onPerch = () => {} }) {
|
|
32
|
+
const now = () => performance.now() / 1000;
|
|
33
|
+
const flo = createFlo3D(THREE, {
|
|
34
|
+
floPose, up: new THREE.Vector3(0, 0, 1), reducedMotion,
|
|
35
|
+
});
|
|
36
|
+
let enabled = !!startEnabled;
|
|
37
|
+
let perched = null; // the member whose card is showing (onPerch), or null
|
|
38
|
+
let placed = false, standingOn = null, modelR = 300, sizeK = 1; // sizeK: the person's Flo size (Labels menu), 1 = as designed
|
|
39
|
+
let shellMood = 'idle';
|
|
40
|
+
let tour = null; // { ids, i, waitUntil }
|
|
41
|
+
let successUntil = 0;
|
|
42
|
+
let leaving = null; // { t0 } while Flo shrinks away after Minimize
|
|
43
|
+
let reduced = !!reducedMotion;
|
|
44
|
+
let prevSel = new Set(), settleTimer = null;
|
|
45
|
+
const ray = new THREE.Raycaster();
|
|
46
|
+
const down = new THREE.Vector3(0, 0, -1);
|
|
47
|
+
|
|
48
|
+
flo.object.visible = enabled;
|
|
49
|
+
scene.add(flo.object);
|
|
50
|
+
|
|
51
|
+
// The point on top of a member where Flo stands: straight down onto the member, on the cap of a column, and on a
|
|
52
|
+
// beam or brace a third of the way along it, so Flo stays clear of the member's label (at its middle) and of
|
|
53
|
+
// the connections at its ends that the person is looking at. Null for a member that is not drawn, or a
|
|
54
|
+
// connection part (Flo never lands on bolts and plates).
|
|
55
|
+
function perchOf(id) {
|
|
56
|
+
const mesh = meshById.get(id);
|
|
57
|
+
if (!mesh || !mesh.visible || String(id).startsWith('det:') || mesh.userData.derived) return null;
|
|
58
|
+
mesh.updateMatrixWorld(true);
|
|
59
|
+
const box = new THREE.Box3().setFromObject(mesh);
|
|
60
|
+
if (box.isEmpty()) return null;
|
|
61
|
+
const c = box.getCenter(new THREE.Vector3()), size = box.getSize(new THREE.Vector3());
|
|
62
|
+
if (size.x > size.z * 1.5 || size.y > size.z * 1.5) {
|
|
63
|
+
if (size.x >= size.y) c.x = box.min.x + size.x * ALONG; else c.y = box.min.y + size.y * ALONG;
|
|
64
|
+
// a sloping member: the footprint's diagonal, so the point stays on it
|
|
65
|
+
if (Math.min(size.x, size.y) > Math.max(size.x, size.y) * 0.25) { c.x = box.min.x + size.x * ALONG; c.y = box.min.y + size.y * ALONG; }
|
|
66
|
+
}
|
|
67
|
+
ray.set(new THREE.Vector3(c.x, c.y, box.max.z + 10), down);
|
|
68
|
+
const hit = ray.intersectObject(mesh, false)[0];
|
|
69
|
+
if (hit) return hit.point.clone();
|
|
70
|
+
// a diagonal whose footprint runs the other way
|
|
71
|
+
const flip = box.min.y + size.y * (1 - ALONG);
|
|
72
|
+
ray.set(new THREE.Vector3(c.x, flip, box.max.z + 10), down);
|
|
73
|
+
const hit2 = ray.intersectObject(mesh, false)[0];
|
|
74
|
+
return hit2 ? hit2.point.clone() : new THREE.Vector3(c.x, c.y, box.max.z);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Where Flo starts: the highest member, and of those near the top the one nearest the middle of the model.
|
|
78
|
+
function home() {
|
|
79
|
+
const box = getSceneBox();
|
|
80
|
+
if (!box || box.isEmpty()) return null;
|
|
81
|
+
const mid = box.getCenter(new THREE.Vector3());
|
|
82
|
+
const span = Math.max(1, box.max.z - box.min.z);
|
|
83
|
+
let best = null, bestScore = Infinity;
|
|
84
|
+
for (const [id, mesh] of meshById) {
|
|
85
|
+
if (!mesh.visible || String(id).startsWith('det:') || mesh.userData.derived) continue;
|
|
86
|
+
const b = new THREE.Box3().setFromObject(mesh);
|
|
87
|
+
if (b.isEmpty()) continue;
|
|
88
|
+
const c = b.getCenter(new THREE.Vector3());
|
|
89
|
+
const score = (box.max.z - b.max.z) / span * 4 + Math.hypot(c.x - mid.x, c.y - mid.y) / Math.max(1, box.getSize(new THREE.Vector3()).length());
|
|
90
|
+
if (score < bestScore) { bestScore = score; best = id; }
|
|
91
|
+
}
|
|
92
|
+
return best;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function sizeFromModel() {
|
|
96
|
+
const box = getSceneBox();
|
|
97
|
+
if (!box || box.isEmpty()) return;
|
|
98
|
+
const diag = box.getSize(new THREE.Vector3()).length();
|
|
99
|
+
modelR = Math.min(MODEL_R_MAX, Math.max(MODEL_R_MIN, diag * MODEL_R_OF_DIAG));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function moodNow(t) {
|
|
103
|
+
if (tour) return 'working';
|
|
104
|
+
if (t < successUntil) return 'success';
|
|
105
|
+
return shellMood;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function perch(id, why) {
|
|
109
|
+
if (id === perched) return;
|
|
110
|
+
perched = id;
|
|
111
|
+
onPerch(id, why);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Hop onto a member; `why` ('select' or 'tour') shows Flo's card about it on landing, none shows no card.
|
|
115
|
+
function goTo(id, t, onLand, why) {
|
|
116
|
+
const p = perchOf(id);
|
|
117
|
+
if (!p) { if (onLand) onLand(); return false; }
|
|
118
|
+
standingOn = id;
|
|
119
|
+
perch(null);
|
|
120
|
+
flo.hopTo(p, () => { if (why && enabled && (why !== 'select' || prevSel.has(id))) perch(id, why); if (onLand) onLand(); }, t);
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// The geometry the person sees, per member, rounded to the millimetre: enough to tell which members a change
|
|
125
|
+
// touched without reading the contract.
|
|
126
|
+
function signature() {
|
|
127
|
+
const out = {};
|
|
128
|
+
const b = new THREE.Box3();
|
|
129
|
+
for (const [id, mesh] of meshById) {
|
|
130
|
+
if (String(id).startsWith('det:')) continue;
|
|
131
|
+
b.setFromObject(mesh);
|
|
132
|
+
if (b.isEmpty()) continue;
|
|
133
|
+
out[id] = [b.min.x, b.min.y, b.min.z, b.max.x, b.max.y, b.max.z].map(Math.round).join(',') + '|' + (mesh.userData.profile || '');
|
|
134
|
+
}
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Called just before the editor reloads for a change made elsewhere (the AI wrote the model): keep what the
|
|
139
|
+
// model looked like, so the reloaded Flo can visit what changed.
|
|
140
|
+
function remember() {
|
|
141
|
+
try { sessionStorage.setItem(REMEMBER_KEY + location.search, JSON.stringify({ at: Date.now(), sig: signature(), standingOn })); } catch { /* full or blocked: Flo just starts at home */ }
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function takeRemembered() {
|
|
145
|
+
let saved = null;
|
|
146
|
+
try {
|
|
147
|
+
const raw = sessionStorage.getItem(REMEMBER_KEY + location.search);
|
|
148
|
+
sessionStorage.removeItem(REMEMBER_KEY + location.search);
|
|
149
|
+
saved = raw ? JSON.parse(raw) : null;
|
|
150
|
+
} catch { saved = null; }
|
|
151
|
+
if (!saved || typeof saved.sig !== 'object' || Date.now() - saved.at > REMEMBER_TTL_MS) return null;
|
|
152
|
+
const cur = signature();
|
|
153
|
+
const changed = Object.keys(cur).filter((id) => saved.sig[id] !== cur[id]);
|
|
154
|
+
return { changed, standingOn: typeof saved.standingOn === 'string' ? saved.standingOn : null };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Visit members one hop at a time, nearest first from where Flo stands, then celebrate.
|
|
158
|
+
function startTour(ids, t) {
|
|
159
|
+
const left = ids.filter((id) => perchOf(id));
|
|
160
|
+
if (!left.length) return;
|
|
161
|
+
const order = [];
|
|
162
|
+
let at = flo.position.clone();
|
|
163
|
+
while (left.length && order.length < VISIT_MAX) {
|
|
164
|
+
let k = 0, d = Infinity;
|
|
165
|
+
left.forEach((id, i) => { const p = perchOf(id); const dd = p.distanceTo(at); if (dd < d) { d = dd; k = i; } });
|
|
166
|
+
const [id] = left.splice(k, 1); order.push(id); at = perchOf(id);
|
|
167
|
+
}
|
|
168
|
+
tour = { ids: order, i: 0, waitUntil: t };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function stepTour(t) {
|
|
172
|
+
if (!tour || flo.isBusy() || t < tour.waitUntil) return;
|
|
173
|
+
if (tour.i >= tour.ids.length) { tour = null; perch(null); successUntil = t + SUCCESS_S; flo.sayHello(t + SUCCESS_S - 0.9); return; }
|
|
174
|
+
const id = tour.ids[tour.i++];
|
|
175
|
+
if (!goTo(id, t, () => { if (tour) tour.waitUntil = now() + VISIT_DWELL_S; }, 'tour')) tour.waitUntil = t;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// After every rebuild: first time, arrive on the model; after a change, follow the member Flo stood on (or go
|
|
179
|
+
// home if it is gone) and visit whatever the change touched.
|
|
180
|
+
function modelChanged() {
|
|
181
|
+
sizeFromModel();
|
|
182
|
+
const t = now();
|
|
183
|
+
if (!placed) {
|
|
184
|
+
const was = takeRemembered();
|
|
185
|
+
const start = (was?.standingOn && perchOf(was.standingOn)) ? was.standingOn : home();
|
|
186
|
+
const p = start && perchOf(start);
|
|
187
|
+
if (!p) return;
|
|
188
|
+
placed = true; standingOn = start;
|
|
189
|
+
flo.setSize(modelR * sizeK);
|
|
190
|
+
if (was && was.changed.length) { flo.placeAt(p); startTour(was.changed, t + 0.4); }
|
|
191
|
+
else {
|
|
192
|
+
// drop in from above, so the first thing Flo does on the model is land on it
|
|
193
|
+
flo.placeAt(p.clone().add(new THREE.Vector3(0, 0, modelR * 7)));
|
|
194
|
+
flo.hopTo(p, null, t + 0.25, { drop: true });
|
|
195
|
+
}
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
// the card says what the member is now (a new profile, a new length): ask the view to read it again
|
|
199
|
+
const p = standingOn && perchOf(standingOn);
|
|
200
|
+
if (p) {
|
|
201
|
+
const why = prevSel.has(standingOn) ? 'select' : null;
|
|
202
|
+
if (p.distanceTo(flo.position) > 1) goTo(standingOn, t, null, why);
|
|
203
|
+
else if (perched) onPerch(perched, 'refresh');
|
|
204
|
+
} else { const h = home(); if (h) goTo(h, t); }
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function selectionChanged(set) {
|
|
208
|
+
const next = new Set(set);
|
|
209
|
+
const added = [...next].filter((id) => !prevSel.has(id) && !String(id).startsWith('det:'));
|
|
210
|
+
const prev = prevSel;
|
|
211
|
+
prevSel = next;
|
|
212
|
+
let target = added[added.length - 1];
|
|
213
|
+
// The member Flo stands on (or is hopping to) was deselected: its card goes, and Flo moves on to one still
|
|
214
|
+
// selected (the last), so it never stands over a member that is no longer part of the selection.
|
|
215
|
+
const on = perched || standingOn;
|
|
216
|
+
if (on && prev.has(on) && !next.has(on) && !tour) {
|
|
217
|
+
perch(null);
|
|
218
|
+
if (!target) target = [...next].filter((id) => !String(id).startsWith('det:')).pop();
|
|
219
|
+
}
|
|
220
|
+
if (!placed || !enabled || !target) return;
|
|
221
|
+
tour = null;
|
|
222
|
+
clearTimeout(settleTimer);
|
|
223
|
+
settleTimer = setTimeout(() => {
|
|
224
|
+
if (!prevSel.has(target)) return;
|
|
225
|
+
if (target === standingOn && !flo.isBusy()) perch(target, 'select'); // already standing on it: just say what it is
|
|
226
|
+
else goTo(target, now(), null, 'select');
|
|
227
|
+
}, SETTLE_MS);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function tick(cameraOverride) {
|
|
231
|
+
if ((!enabled && !leaving) || !placed) return;
|
|
232
|
+
const t = now();
|
|
233
|
+
stepTour(t);
|
|
234
|
+
flo.setMood(moodNow(t));
|
|
235
|
+
const camera = cameraOverride || getCamera();
|
|
236
|
+
let k = 1;
|
|
237
|
+
if (leaving) {
|
|
238
|
+
k = 1 - Math.min(1, (t - leaving.t0) / LEAVE_S);
|
|
239
|
+
if (k <= 0) { leaving = null; flo.object.visible = false; return; }
|
|
240
|
+
k = k * k;
|
|
241
|
+
}
|
|
242
|
+
flo.setSize(Math.max(modelR, pxToWorldAt(MIN_SCREEN_R_PX, flo.object.position)) * sizeK * k);
|
|
243
|
+
flo.tick(t, camera);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Is the pointer on Flo? (The page shows its Minimize chip while it is.)
|
|
247
|
+
function hover(ndc, camera) {
|
|
248
|
+
if (!enabled || !placed || !flo.object.visible || leaving) return false;
|
|
249
|
+
ray.setFromCamera(ndc, camera);
|
|
250
|
+
return flo.hit(ray);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Where the top of Flo's hat is on screen, in the canvas's own pixels, and how far Flo reaches either side of that
|
|
254
|
+
// point there (`half`), so a card beside Flo stands clear of it rather than over its brim (null when Flo is not drawn).
|
|
255
|
+
function hatScreen(camera, width, height) {
|
|
256
|
+
if (!enabled || !placed || !flo.object.visible) return null;
|
|
257
|
+
const top = flo.object.position.clone().add(new THREE.Vector3(0, 0, flo.r * 3.1));
|
|
258
|
+
const p = top.clone().project(camera);
|
|
259
|
+
if (p.z > 1) return null;
|
|
260
|
+
const edge = top.add(new THREE.Vector3().setFromMatrixColumn(camera.matrixWorld, 0).multiplyScalar(flo.r * HALF_WIDTH_R)).project(camera);
|
|
261
|
+
return { x: (p.x + 1) / 2 * width, y: (1 - p.y) / 2 * height, half: Math.abs(edge.x - p.x) / 2 * width };
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Where Flo's body is drawn on screen, in the canvas's own pixels: the box around every projected vertex, so the outline
|
|
265
|
+
// Flo actually has (null when Flo is not drawn). For the test probe, which measures the card against it; too slow for a frame.
|
|
266
|
+
function screenBox(camera, width, height) {
|
|
267
|
+
if (!enabled || !placed || !flo.object.visible) return null;
|
|
268
|
+
flo.object.updateMatrixWorld(true);
|
|
269
|
+
const v = new THREE.Vector3(), box = { left: Infinity, right: -Infinity, top: Infinity, bottom: -Infinity };
|
|
270
|
+
flo.body.traverse((o) => {
|
|
271
|
+
const pos = o.isMesh && o.visible && o.geometry.attributes.position;
|
|
272
|
+
if (!pos) return;
|
|
273
|
+
for (let i = 0; i < pos.count; i++) {
|
|
274
|
+
v.fromBufferAttribute(pos, i).applyMatrix4(o.matrixWorld).project(camera);
|
|
275
|
+
const x = (v.x + 1) / 2 * width, y = (1 - v.y) / 2 * height;
|
|
276
|
+
box.left = Math.min(box.left, x); box.right = Math.max(box.right, x); box.top = Math.min(box.top, y); box.bottom = Math.max(box.bottom, y);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
return box.left <= box.right ? box : null;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// A press on Flo: true when it was Flo (the caller then leaves the selection alone). Any press in the view stops
|
|
283
|
+
// a tour of what changed: the person has started working, and Flo stays where it is.
|
|
284
|
+
function pointerDown(ndc, camera) {
|
|
285
|
+
if (!enabled || !placed || !flo.object.visible) return false;
|
|
286
|
+
if (tour) { tour = null; successUntil = 0; if (!prevSel.has(perched)) perch(null); }
|
|
287
|
+
ray.setFromCamera(ndc, camera);
|
|
288
|
+
if (!flo.hit(ray)) return false;
|
|
289
|
+
flo.sayHello(now());
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Minimize shrinks Flo away; bringing it back drops it onto the member it stood on, as on arrival.
|
|
294
|
+
function setEnabled(on, { animate = false } = {}) {
|
|
295
|
+
const was = enabled;
|
|
296
|
+
enabled = !!on;
|
|
297
|
+
if (enabled === was) return;
|
|
298
|
+
tour = null;
|
|
299
|
+
if (!enabled) {
|
|
300
|
+
perch(null);
|
|
301
|
+
if (animate && !reduced && placed && flo.object.visible) leaving = { t0: now() };
|
|
302
|
+
else { leaving = null; flo.object.visible = false; }
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
leaving = null;
|
|
306
|
+
flo.object.visible = true;
|
|
307
|
+
const p = placed && standingOn && perchOf(standingOn);
|
|
308
|
+
if (!p) return;
|
|
309
|
+
// back on a member the person still has selected: its card comes back once Flo has landed
|
|
310
|
+
const land = prevSel.has(standingOn) ? () => perch(standingOn, 'select') : null;
|
|
311
|
+
if (animate && !reduced) {
|
|
312
|
+
flo.placeAt(p.clone().add(new THREE.Vector3(0, 0, modelR * 7)));
|
|
313
|
+
flo.hopTo(p, land, now(), { drop: true });
|
|
314
|
+
} else { flo.placeAt(p); if (land) land(); }
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function setShellMood(m) { shellMood = ['idle', 'thinking', 'working', 'yourcall'].includes(m) ? m : 'idle'; }
|
|
318
|
+
|
|
319
|
+
function probe() {
|
|
320
|
+
const p = flo.object.position;
|
|
321
|
+
return { enabled, placed, standingOn, perched, mood: flo.mood, busy: flo.isBusy(), touring: !!tour, leaving: !!leaving, visible: flo.object.visible, r: flo.r, at: [p.x, p.y, p.z] };
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return {
|
|
325
|
+
tick, modelChanged, selectionChanged, pointerDown, hover, hatScreen, screenBox, remember, setEnabled, setShellMood, probe,
|
|
326
|
+
setScale(k) { sizeK = Number.isFinite(k) && k > 0 ? k : 1; },
|
|
327
|
+
setReducedMotion: (on) => { reduced = !!on; flo.setReducedMotion(on); },
|
|
328
|
+
get enabled() { return enabled; },
|
|
329
|
+
dispose: () => { clearTimeout(settleTimer); flo.dispose(); },
|
|
330
|
+
};
|
|
331
|
+
}
|