@floless/app 0.138.2 → 0.139.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/autostart.mjs +6 -2
- package/desktop-access-production-manifest.mjs +7 -0
- package/dist/floless-server.cjs +157202 -70901
- 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 +410 -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 +2121 -1253
- package/dist/web/steel-filter.html +5 -1
- package/dist/web/steel-model-v2-commands.js +72 -1
- 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
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
// Phase C wire and semantic contract for provider-neutral model snapping. This is intentionally pure:
|
|
2
|
+
// acquisition, camera projection, resolver policy and UI wiring are later consumers of these receipts.
|
|
3
|
+
export const MODEL_SNAP_SCHEMA = Object.freeze({
|
|
4
|
+
query: 'floless.model-snap-query/v1', candidate: 'floless.model-snap-candidate/v1',
|
|
5
|
+
result: 'floless.model-snap-result/v1', constraint: 'floless.model-snap-constraint/v1',
|
|
6
|
+
});
|
|
7
|
+
export const MODEL_SNAP_KIND_ORDER = Object.freeze([
|
|
8
|
+
'origin', 'semantic-endpoint', 'semantic-intersection', 'semantic-grid-intersection', 'semantic-level',
|
|
9
|
+
'semantic-midpoint', 'semantic-center', 'semantic-axis', 'mesh-vertex', 'mesh-edge-midpoint',
|
|
10
|
+
'mesh-edge-nearest', 'surface', 'free-point',
|
|
11
|
+
]);
|
|
12
|
+
export const MODEL_SNAP_SOLVER_KINDS = Object.freeze(['perpendicular', 'parallel', 'extension']);
|
|
13
|
+
export const MODEL_SNAP_REFUSAL_CODES = Object.freeze([
|
|
14
|
+
'outside-radius', 'occluded', 'filtered', 'work-plane', 'degenerate', 'near-parallel',
|
|
15
|
+
'outside-extent', 'over-budget', 'stale',
|
|
16
|
+
]);
|
|
17
|
+
export const MODEL_SNAP_LIMITS_V1 = Object.freeze({
|
|
18
|
+
acquisitionRadiusCssPx: 12, distanceTieCssPx: 0.25, workPlaneToleranceMm: 0.1,
|
|
19
|
+
directionMinLength: 1e-9, nearParallelCrossLength: 1e-8,
|
|
20
|
+
extensionSourceLengths: 10, extensionMaximumMm: 100000,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const MAX_COORD = 1e12, MAX_CSS = 1e7, MAX_GENERATION = 0xffffffff;
|
|
24
|
+
const own = (v, k) => Object.prototype.hasOwnProperty.call(v, k);
|
|
25
|
+
const object = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
26
|
+
const finite = Number.isFinite;
|
|
27
|
+
const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
28
|
+
const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
29
|
+
const norm = (v) => Math.hypot(v[0], v[1], v[2]);
|
|
30
|
+
const close = (a, b, eps) => Math.abs(a - b) <= eps;
|
|
31
|
+
const pointClose = (a, b, eps) => a.every((n, i) => Math.abs(n - b[i]) <= eps);
|
|
32
|
+
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
33
|
+
const verdict = (errors) => Object.freeze({ ok: errors.length === 0, errors: Object.freeze(errors) });
|
|
34
|
+
const error = (errors, path, text) => errors.push(`${path}: ${text}`);
|
|
35
|
+
function fields(value, allowed, required, path, errors) {
|
|
36
|
+
if (!object(value)) { error(errors, path, 'must be an object'); return false; }
|
|
37
|
+
for (const key of Object.keys(value)) if (!allowed.includes(key)) error(errors, `${path}.${key}`, 'is not allowed');
|
|
38
|
+
for (const key of required) if (!own(value, key)) error(errors, `${path}.${key}`, 'is required');
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
function text(value, path, errors, max = 256) { if (typeof value !== 'string' || value.length < 1 || value.length > max) error(errors, path, `must be a non-empty string of at most ${max} characters`); }
|
|
42
|
+
function integer(value, path, errors, min = 0, max = MAX_GENERATION) { if (!Number.isSafeInteger(value) || value < min || value > max) error(errors, path, `must be an integer from ${min} to ${max}`); }
|
|
43
|
+
function number(value, path, errors, min = -MAX_COORD, max = MAX_COORD) { if (!finite(value) || value < min || value > max) error(errors, path, `must be finite and from ${min} to ${max}`); }
|
|
44
|
+
function tuple(value, size, path, errors, min = -MAX_COORD, max = MAX_COORD) {
|
|
45
|
+
if (!Array.isArray(value) || value.length !== size) { error(errors, path, `must contain exactly ${size} finite numbers`); return false; }
|
|
46
|
+
value.forEach((v, i) => number(v, `${path}[${i}]`, errors, min, max)); return value.every(finite);
|
|
47
|
+
}
|
|
48
|
+
function unit(value, path, errors) { if (tuple(value, 3, path, errors, -1, 1) && !close(norm(value), 1, 1e-7)) error(errors, path, 'must be a normalized unit vector'); }
|
|
49
|
+
function digest(value, path, errors) { if (typeof value !== 'string' || !/^[0-9a-f]{64}$/.test(value)) error(errors, path, 'must be a lowercase SHA-256 digest'); }
|
|
50
|
+
function generation(value, path, errors) {
|
|
51
|
+
if (!fields(value, ['projectUuid', 'authority', 'revisionId', 'sourceDigest', 'epoch'], ['projectUuid', 'authority', 'revisionId', 'sourceDigest', 'epoch'], path, errors)) return;
|
|
52
|
+
text(value.projectUuid, `${path}.projectUuid`, errors, 128); text(value.authority, `${path}.authority`, errors, 64);
|
|
53
|
+
text(value.revisionId, `${path}.revisionId`, errors, 256); digest(value.sourceDigest, `${path}.sourceDigest`, errors); integer(value.epoch, `${path}.epoch`, errors);
|
|
54
|
+
}
|
|
55
|
+
function frame(value, path, errors) {
|
|
56
|
+
if (!fields(value, ['schemaVersion', 'frameId', 'originMm', 'xAxis', 'yAxis', 'zAxis'], ['schemaVersion', 'frameId', 'originMm', 'xAxis', 'yAxis', 'zAxis'], path, errors)) return;
|
|
57
|
+
if (value.schemaVersion !== 'floless.model-frame/v1') error(errors, `${path}.schemaVersion`, 'must equal floless.model-frame/v1');
|
|
58
|
+
text(value.frameId, `${path}.frameId`, errors, 256); tuple(value.originMm, 3, `${path}.originMm`, errors);
|
|
59
|
+
unit(value.xAxis, `${path}.xAxis`, errors); unit(value.yAxis, `${path}.yAxis`, errors); unit(value.zAxis, `${path}.zAxis`, errors);
|
|
60
|
+
if ([value.xAxis, value.yAxis, value.zAxis].every((v) => Array.isArray(v) && v.length === 3 && v.every(finite))) {
|
|
61
|
+
if ([dot(value.xAxis, value.yAxis), dot(value.xAxis, value.zAxis), dot(value.yAxis, value.zAxis)].some((v) => Math.abs(v) > 1e-8)) error(errors, path, 'axes must be mutually orthogonal');
|
|
62
|
+
if (!pointClose(cross(value.xAxis, value.yAxis), value.zAxis, 1e-7)) error(errors, path, 'axes must be right-handed');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function sortedPair(value, path, errors) {
|
|
66
|
+
if (!Array.isArray(value) || value.length !== 2) { error(errors, path, 'must contain two source indices'); return; }
|
|
67
|
+
integer(value[0], `${path}[0]`, errors, 0, 0x7fffffff); integer(value[1], `${path}[1]`, errors, 0, 0x7fffffff);
|
|
68
|
+
if (Number.isInteger(value[0]) && Number.isInteger(value[1]) && value[0] >= value[1]) error(errors, path, 'must be strictly ascending');
|
|
69
|
+
}
|
|
70
|
+
function priority(value, path, errors) {
|
|
71
|
+
if (!value || typeof value !== 'object') return;
|
|
72
|
+
if (own(value, 'priority')) error(errors, `${path}.priority`, 'is forbidden; precedence is the canonical kind order');
|
|
73
|
+
for (const [key, child] of Object.entries(value)) priority(child, `${path}.${key}`, errors);
|
|
74
|
+
}
|
|
75
|
+
function providerRef(value, path, errors) {
|
|
76
|
+
if (!object(value) || !['steel-feature', 'revit-mesh', 'signed-semantic-feature', 'session'].includes(value.type)) { error(errors, path, 'must be a discriminated provider reference'); return; }
|
|
77
|
+
if (value.type === 'steel-feature') {
|
|
78
|
+
if (!fields(value, ['type', 'generation', 'domainId'], ['type', 'generation', 'domainId'], path, errors)) return;
|
|
79
|
+
generation(value.generation, `${path}.generation`, errors); text(value.domainId, `${path}.domainId`, errors, 512); return;
|
|
80
|
+
}
|
|
81
|
+
if (value.type === 'signed-semantic-feature') {
|
|
82
|
+
if (!fields(value, ['type', 'generation', 'receiptDigest', 'stableFeatureId'], ['type', 'generation', 'receiptDigest', 'stableFeatureId'], path, errors)) return;
|
|
83
|
+
generation(value.generation, `${path}.generation`, errors); digest(value.receiptDigest, `${path}.receiptDigest`, errors); text(value.stableFeatureId, `${path}.stableFeatureId`, errors, 512); return;
|
|
84
|
+
}
|
|
85
|
+
if (value.type === 'session') {
|
|
86
|
+
if (!fields(value, ['type', 'generation', 'opaqueId'], ['type', 'generation', 'opaqueId'], path, errors)) return;
|
|
87
|
+
generation(value.generation, `${path}.generation`, errors); text(value.opaqueId, `${path}.opaqueId`, errors, 512); return;
|
|
88
|
+
}
|
|
89
|
+
const allowed = ['type', 'generation', 'manifestRoot', 'tileSha256', 'providerEntityId', 'nodeIndexPath', 'primitiveIndex', 'triangleOrdinal', 'sourceIndices', 'featureSchemaVersion', 'featureSignature'];
|
|
90
|
+
if (!fields(value, allowed, allowed, path, errors)) return;
|
|
91
|
+
generation(value.generation, `${path}.generation`, errors); digest(value.manifestRoot, `${path}.manifestRoot`, errors); digest(value.tileSha256, `${path}.tileSha256`, errors);
|
|
92
|
+
text(value.providerEntityId, `${path}.providerEntityId`, errors, 512); text(value.featureSchemaVersion, `${path}.featureSchemaVersion`, errors, 128); digest(value.featureSignature, `${path}.featureSignature`, errors);
|
|
93
|
+
if (!Array.isArray(value.nodeIndexPath) || value.nodeIndexPath.length < 1 || value.nodeIndexPath.length > 64) error(errors, `${path}.nodeIndexPath`, 'must contain 1 to 64 node indices');
|
|
94
|
+
else value.nodeIndexPath.forEach((n, i) => integer(n, `${path}.nodeIndexPath[${i}]`, errors, 0, 0x7fffffff));
|
|
95
|
+
integer(value.primitiveIndex, `${path}.primitiveIndex`, errors, 0, 0x7fffffff); integer(value.triangleOrdinal, `${path}.triangleOrdinal`, errors, 0, 0x7fffffff);
|
|
96
|
+
if (!Array.isArray(value.sourceIndices) || value.sourceIndices.length !== 3) error(errors, `${path}.sourceIndices`, 'must preserve three authenticated source indices in winding order');
|
|
97
|
+
else { value.sourceIndices.forEach((n, i) => integer(n, `${path}.sourceIndices[${i}]`, errors, 0, 0x7fffffff)); if (new Set(value.sourceIndices).size !== 3) error(errors, `${path}.sourceIndices`, 'must contain three distinct indices'); }
|
|
98
|
+
}
|
|
99
|
+
function feature(value, path, errors) {
|
|
100
|
+
if (!object(value) || !['source-vertex', 'triangle-corner', 'source-edge', 'triangle-edge', 'surface', 'semantic'].includes(value.type)) { error(errors, path, 'must be a discriminated feature locator'); return; }
|
|
101
|
+
if (value.type === 'source-vertex') {
|
|
102
|
+
if (fields(value, ['type', 'featureOrdinal'], ['type', 'featureOrdinal'], path, errors)) integer(value.featureOrdinal, `${path}.featureOrdinal`, errors, 0, 0x7fffffff);
|
|
103
|
+
} else if (value.type === 'triangle-corner') {
|
|
104
|
+
if (fields(value, ['type', 'triangleOrdinal', 'featureOrdinal'], ['type', 'triangleOrdinal', 'featureOrdinal'], path, errors)) { integer(value.triangleOrdinal, `${path}.triangleOrdinal`, errors, 0, 0x7fffffff); integer(value.featureOrdinal, `${path}.featureOrdinal`, errors, 0, 2); }
|
|
105
|
+
} else if (value.type === 'source-edge') {
|
|
106
|
+
if (fields(value, ['type', 'sourceIndexPair'], ['type', 'sourceIndexPair'], path, errors)) sortedPair(value.sourceIndexPair, `${path}.sourceIndexPair`, errors);
|
|
107
|
+
} else if (value.type === 'triangle-edge') {
|
|
108
|
+
if (fields(value, ['type', 'triangleOrdinal', 'featureOrdinal'], ['type', 'triangleOrdinal', 'featureOrdinal'], path, errors)) { integer(value.triangleOrdinal, `${path}.triangleOrdinal`, errors, 0, 0x7fffffff); integer(value.featureOrdinal, `${path}.featureOrdinal`, errors, 0, 2); }
|
|
109
|
+
} else if (value.type === 'surface') {
|
|
110
|
+
if (fields(value, ['type', 'triangleOrdinal'], ['type', 'triangleOrdinal'], path, errors)) integer(value.triangleOrdinal, `${path}.triangleOrdinal`, errors, 0, 0x7fffffff);
|
|
111
|
+
} else if (fields(value, ['type', 'stableFeatureId'], ['type', 'stableFeatureId'], path, errors)) text(value.stableFeatureId, `${path}.stableFeatureId`, errors, 512);
|
|
112
|
+
}
|
|
113
|
+
function decodeFloat64Hex(value) {
|
|
114
|
+
if (typeof value !== 'string' || !/^[0-9A-F]{16}$/.test(value)) return null;
|
|
115
|
+
const bytes = new Uint8Array(8); for (let i = 0; i < 8; i++) bytes[i] = Number.parseInt(value.slice(i * 2, i * 2 + 2), 16);
|
|
116
|
+
return new DataView(bytes.buffer).getFloat64(0, false);
|
|
117
|
+
}
|
|
118
|
+
function primitive(value, path, errors) {
|
|
119
|
+
if (!object(value) || !['point', 'segment', 'line', 'arc', 'circle', 'plane', 'triangle'].includes(value.type)) { error(errors, path, 'must be a discriminated canonical primitive'); return; }
|
|
120
|
+
if (value.type === 'point') { if (fields(value, ['type', 'pointMm'], ['type', 'pointMm'], path, errors)) tuple(value.pointMm, 3, `${path}.pointMm`, errors); return; }
|
|
121
|
+
if (value.type === 'segment') {
|
|
122
|
+
if (fields(value, ['type', 'startMm', 'endMm'], ['type', 'startMm', 'endMm'], path, errors)) {
|
|
123
|
+
tuple(value.startMm, 3, `${path}.startMm`, errors); tuple(value.endMm, 3, `${path}.endMm`, errors);
|
|
124
|
+
if (Array.isArray(value.startMm) && Array.isArray(value.endMm) && norm(value.endMm.map((n, i) => n - value.startMm[i])) < MODEL_SNAP_LIMITS_V1.directionMinLength) error(errors, path, 'finite segment must be non-degenerate');
|
|
125
|
+
} return;
|
|
126
|
+
}
|
|
127
|
+
if (value.type === 'line') { if (fields(value, ['type', 'originMm', 'direction'], ['type', 'originMm', 'direction'], path, errors)) { tuple(value.originMm, 3, `${path}.originMm`, errors); unit(value.direction, `${path}.direction`, errors); } return; }
|
|
128
|
+
if (value.type === 'plane') { if (fields(value, ['type', 'originMm', 'normal'], ['type', 'originMm', 'normal'], path, errors)) { tuple(value.originMm, 3, `${path}.originMm`, errors); unit(value.normal, `${path}.normal`, errors); } return; }
|
|
129
|
+
if (value.type === 'circle') { if (fields(value, ['type', 'centerMm', 'normal', 'radiusMm'], ['type', 'centerMm', 'normal', 'radiusMm'], path, errors)) { tuple(value.centerMm, 3, `${path}.centerMm`, errors); unit(value.normal, `${path}.normal`, errors); number(value.radiusMm, `${path}.radiusMm`, errors, Number.MIN_VALUE, MAX_COORD); } return; }
|
|
130
|
+
if (value.type === 'arc') {
|
|
131
|
+
if (fields(value, ['type', 'centerMm', 'normal', 'radiusMm', 'startDirection', 'sweepRadians'], ['type', 'centerMm', 'normal', 'radiusMm', 'startDirection', 'sweepRadians'], path, errors)) {
|
|
132
|
+
tuple(value.centerMm, 3, `${path}.centerMm`, errors); unit(value.normal, `${path}.normal`, errors); unit(value.startDirection, `${path}.startDirection`, errors);
|
|
133
|
+
number(value.radiusMm, `${path}.radiusMm`, errors, Number.MIN_VALUE, MAX_COORD); number(value.sweepRadians, `${path}.sweepRadians`, errors, -Math.PI * 2, Math.PI * 2);
|
|
134
|
+
if (finite(value.sweepRadians) && Math.abs(value.sweepRadians) < MODEL_SNAP_LIMITS_V1.directionMinLength) error(errors, `${path}.sweepRadians`, 'must be non-zero');
|
|
135
|
+
if (Array.isArray(value.normal) && Array.isArray(value.startDirection) && Math.abs(dot(value.normal, value.startDirection)) > 1e-8) error(errors, path, 'arc start direction must be perpendicular to its normal');
|
|
136
|
+
} return;
|
|
137
|
+
}
|
|
138
|
+
const allowed = ['type', 'verticesMm', 'sourceIndices', 'triangleOrdinal', 'barycentricHex', 'fallbackPointMm'];
|
|
139
|
+
if (!fields(value, allowed, allowed, path, errors)) return;
|
|
140
|
+
if (!Array.isArray(value.verticesMm) || value.verticesMm.length !== 3) error(errors, `${path}.verticesMm`, 'must contain three authenticated vertices');
|
|
141
|
+
else value.verticesMm.forEach((p, i) => tuple(p, 3, `${path}.verticesMm[${i}]`, errors));
|
|
142
|
+
if (!Array.isArray(value.sourceIndices) || value.sourceIndices.length !== 3) error(errors, `${path}.sourceIndices`, 'must contain three authenticated source indices');
|
|
143
|
+
else { value.sourceIndices.forEach((n, i) => integer(n, `${path}.sourceIndices[${i}]`, errors, 0, 0x7fffffff)); if (new Set(value.sourceIndices).size !== 3) error(errors, `${path}.sourceIndices`, 'must preserve a non-degenerate winding'); }
|
|
144
|
+
integer(value.triangleOrdinal, `${path}.triangleOrdinal`, errors, 0, 0x7fffffff); tuple(value.fallbackPointMm, 3, `${path}.fallbackPointMm`, errors);
|
|
145
|
+
if (!Array.isArray(value.barycentricHex) || value.barycentricHex.length !== 3) error(errors, `${path}.barycentricHex`, 'must contain three uppercase big-endian float64 values');
|
|
146
|
+
else {
|
|
147
|
+
const weights = value.barycentricHex.map(decodeFloat64Hex);
|
|
148
|
+
if (weights.some((n) => n === null || !finite(n))) error(errors, `${path}.barycentricHex`, 'must contain finite uppercase big-endian float64 values');
|
|
149
|
+
else {
|
|
150
|
+
if (weights.some((n) => n < -1e-9 || n > 1 + 1e-9) || Math.abs(weights.reduce((s, n) => s + n, 0) - 1) > 1e-9) error(errors, `${path}.barycentricHex`, 'weights must be within tolerance and sum to one');
|
|
151
|
+
if (value.verticesMm?.length === 3 && value.verticesMm.every((p) => Array.isArray(p) && p.length === 3 && p.every(finite)) && value.fallbackPointMm?.length === 3) {
|
|
152
|
+
const expected = [0, 1, 2].map((axis) => value.verticesMm.reduce((sum, point, i) => sum + point[axis] * weights[i], 0));
|
|
153
|
+
if (!pointClose(expected, value.fallbackPointMm, 0.1)) error(errors, `${path}.fallbackPointMm`, 'must match authenticated triangle interpolation within 0.1 mm');
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (value.verticesMm?.length === 3) {
|
|
158
|
+
const ab = value.verticesMm[1].map((n, i) => n - value.verticesMm[0][i]), ac = value.verticesMm[2].map((n, i) => n - value.verticesMm[0][i]);
|
|
159
|
+
if (norm(cross(ab, ac)) < MODEL_SNAP_LIMITS_V1.directionMinLength) error(errors, path, 'authenticated triangle winding must be non-degenerate');
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function anchor(value, path, errors) { if (fields(value, ['pointMm', 'providerRef'], ['pointMm'], path, errors)) { tuple(value.pointMm, 3, `${path}.pointMm`, errors); if (own(value, 'providerRef')) providerRef(value.providerRef, `${path}.providerRef`, errors); } }
|
|
163
|
+
function queryInto(value, path, errors) {
|
|
164
|
+
priority(value, path, errors);
|
|
165
|
+
const allowed = ['schemaVersion', 'generation', 'pointerCssPx', 'viewportCssPx', 'raySource', 'ray', 'enabledKinds', 'mode', 'firstAnchor', 'activeFrame'];
|
|
166
|
+
if (!fields(value, allowed, allowed.filter((key) => key !== 'firstAnchor'), path, errors)) return;
|
|
167
|
+
if (value.schemaVersion !== MODEL_SNAP_SCHEMA.query) error(errors, `${path}.schemaVersion`, `must equal ${MODEL_SNAP_SCHEMA.query}`);
|
|
168
|
+
generation(value.generation, `${path}.generation`, errors); tuple(value.pointerCssPx, 2, `${path}.pointerCssPx`, errors, -MAX_CSS, MAX_CSS); tuple(value.viewportCssPx, 2, `${path}.viewportCssPx`, errors, 1, MAX_CSS);
|
|
169
|
+
if (value.raySource !== 'camera-port') error(errors, `${path}.raySource`, 'must equal camera-port');
|
|
170
|
+
if (fields(value.ray, ['originMm', 'direction'], ['originMm', 'direction'], `${path}.ray`, errors)) { tuple(value.ray.originMm, 3, `${path}.ray.originMm`, errors); unit(value.ray.direction, `${path}.ray.direction`, errors); }
|
|
171
|
+
if (!Array.isArray(value.enabledKinds) || value.enabledKinds.length < 1 || value.enabledKinds.length > MODEL_SNAP_KIND_ORDER.length) error(errors, `${path}.enabledKinds`, 'must contain canonical snap kinds');
|
|
172
|
+
else {
|
|
173
|
+
const ranks = value.enabledKinds.map((kind, i) => { if (!MODEL_SNAP_KIND_ORDER.includes(kind)) error(errors, `${path}.enabledKinds[${i}]`, 'is not a canonical snap kind'); return MODEL_SNAP_KIND_ORDER.indexOf(kind); });
|
|
174
|
+
if (new Set(value.enabledKinds).size !== value.enabledKinds.length) error(errors, `${path}.enabledKinds`, 'must be unique');
|
|
175
|
+
if (ranks.some((rank, i) => i > 0 && rank <= ranks[i - 1])) error(errors, `${path}.enabledKinds`, 'must follow canonical kind order');
|
|
176
|
+
}
|
|
177
|
+
if (!['3d', 'work-plane'].includes(value.mode)) error(errors, `${path}.mode`, 'must be 3d or work-plane');
|
|
178
|
+
if (own(value, 'firstAnchor')) anchor(value.firstAnchor, `${path}.firstAnchor`, errors); frame(value.activeFrame, `${path}.activeFrame`, errors);
|
|
179
|
+
}
|
|
180
|
+
export function validateModelSnapQuery(value) { const errors = []; queryInto(value, '$', errors); return verdict(errors); }
|
|
181
|
+
function candidateInto(value, path, errors) {
|
|
182
|
+
priority(value, path, errors);
|
|
183
|
+
if (!fields(value, ['schemaVersion', 'generation', 'candidateId', 'kind', 'providerRef', 'feature', 'primitive'], ['schemaVersion', 'generation', 'candidateId', 'kind', 'providerRef', 'feature', 'primitive'], path, errors)) return;
|
|
184
|
+
if (value.schemaVersion !== MODEL_SNAP_SCHEMA.candidate) error(errors, `${path}.schemaVersion`, `must equal ${MODEL_SNAP_SCHEMA.candidate}`);
|
|
185
|
+
generation(value.generation, `${path}.generation`, errors); text(value.candidateId, `${path}.candidateId`, errors, 256);
|
|
186
|
+
if (!MODEL_SNAP_KIND_ORDER.includes(value.kind)) error(errors, `${path}.kind`, 'is not a canonical snap kind');
|
|
187
|
+
providerRef(value.providerRef, `${path}.providerRef`, errors); feature(value.feature, `${path}.feature`, errors); primitive(value.primitive, `${path}.primitive`, errors);
|
|
188
|
+
if (value.providerRef?.generation && !same(value.generation, value.providerRef.generation)) error(errors, `${path}.providerRef.generation`, 'must equal candidate generation');
|
|
189
|
+
const semantic = String(value.kind).startsWith('semantic-');
|
|
190
|
+
if (semantic && !['steel-feature', 'signed-semantic-feature'].includes(value.providerRef?.type)) error(errors, `${path}.providerRef.type`, 'semantic kinds require an authenticated semantic provider reference');
|
|
191
|
+
if (semantic && value.feature?.type !== 'semantic') error(errors, `${path}.feature.type`, 'semantic kinds require a signed stable feature id');
|
|
192
|
+
if (value.providerRef?.type === 'signed-semantic-feature' && value.feature?.stableFeatureId !== value.providerRef.stableFeatureId) error(errors, `${path}.feature.stableFeatureId`, 'must equal the signed provider feature id');
|
|
193
|
+
if (String(value.kind).startsWith('mesh-') || value.kind === 'surface') {
|
|
194
|
+
if (value.providerRef?.type !== 'revit-mesh') error(errors, `${path}.providerRef.type`, 'mesh kinds require a signed Revit mesh reference');
|
|
195
|
+
if (value.primitive?.type !== 'triangle') error(errors, `${path}.primitive.type`, 'mesh kinds require an authenticated triangle primitive');
|
|
196
|
+
if (value.providerRef?.triangleOrdinal !== value.primitive?.triangleOrdinal || !same(value.providerRef?.sourceIndices, value.primitive?.sourceIndices)) error(errors, `${path}.primitive`, 'must agree with the signed mesh triangle receipt');
|
|
197
|
+
if (value.feature?.type === 'source-vertex' && !value.primitive?.sourceIndices?.includes(value.feature.featureOrdinal)) error(errors, `${path}.feature.featureOrdinal`, 'must identify a source vertex in the authenticated triangle');
|
|
198
|
+
if (value.feature?.type === 'source-edge' && !value.feature.sourceIndexPair?.every((index) => value.primitive?.sourceIndices?.includes(index))) error(errors, `${path}.feature.sourceIndexPair`, 'must identify an edge in the authenticated triangle');
|
|
199
|
+
if (['triangle-corner', 'triangle-edge', 'surface'].includes(value.feature?.type) && value.feature.triangleOrdinal !== value.primitive?.triangleOrdinal) error(errors, `${path}.feature.triangleOrdinal`, 'must equal the authenticated triangle ordinal');
|
|
200
|
+
}
|
|
201
|
+
if (value.kind === 'mesh-vertex' && !['source-vertex', 'triangle-corner'].includes(value.feature?.type)) error(errors, `${path}.feature.type`, 'mesh-vertex requires a vertex feature ordinal');
|
|
202
|
+
if (['mesh-edge-midpoint', 'mesh-edge-nearest'].includes(value.kind) && !['source-edge', 'triangle-edge'].includes(value.feature?.type)) error(errors, `${path}.feature.type`, 'mesh edge kinds require an edge locator');
|
|
203
|
+
if (value.kind === 'surface' && value.feature?.type !== 'surface') error(errors, `${path}.feature.type`, 'surface requires a triangle ordinal');
|
|
204
|
+
}
|
|
205
|
+
export function validateModelSnapCandidate(value) { const errors = []; candidateInto(value, '$', errors); return verdict(errors); }
|
|
206
|
+
function pointOnPrimitive(point, p) {
|
|
207
|
+
if (!Array.isArray(point) || !object(p)) return false;
|
|
208
|
+
if (p.type === 'point') return pointClose(point, p.pointMm, 0.1);
|
|
209
|
+
if (p.type === 'segment') { const d = p.endMm.map((n, i) => n - p.startMm[i]), q = point.map((n, i) => n - p.startMm[i]), dd = dot(d, d); if (dd <= 0) return false; const t = dot(q, d) / dd; return t >= -1e-9 && t <= 1 + 1e-9 && pointClose(point, p.startMm.map((n, i) => n + d[i] * t), 0.1); }
|
|
210
|
+
if (p.type === 'line') { const q = point.map((n, i) => n - p.originMm[i]), t = dot(q, p.direction); return pointClose(point, p.originMm.map((n, i) => n + p.direction[i] * t), 0.1); }
|
|
211
|
+
if (p.type === 'plane') return Math.abs(dot(point.map((n, i) => n - p.originMm[i]), p.normal)) <= 0.1;
|
|
212
|
+
if (p.type === 'circle' || p.type === 'arc') { const q = point.map((n, i) => n - p.centerMm[i]); return Math.abs(dot(q, p.normal)) <= 0.1 && Math.abs(norm(q) - p.radiusMm) <= 0.1; }
|
|
213
|
+
if (p.type === 'triangle') return pointClose(point, p.fallbackPointMm, 0.1);
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
function resultInto(value, path, errors) {
|
|
217
|
+
priority(value, path, errors);
|
|
218
|
+
if (!object(value) || !['acquired', 'refused'].includes(value.status)) { error(errors, path, 'must be a discriminated acquired or refused result'); return; }
|
|
219
|
+
if (value.status === 'refused') {
|
|
220
|
+
if (!fields(value, ['schemaVersion', 'status', 'generation', 'code', 'message'], ['schemaVersion', 'status', 'generation', 'code', 'message'], path, errors)) return;
|
|
221
|
+
if (value.schemaVersion !== MODEL_SNAP_SCHEMA.result) error(errors, `${path}.schemaVersion`, `must equal ${MODEL_SNAP_SCHEMA.result}`);
|
|
222
|
+
generation(value.generation, `${path}.generation`, errors); if (!MODEL_SNAP_REFUSAL_CODES.includes(value.code)) error(errors, `${path}.code`, 'is not a canonical refusal code'); text(value.message, `${path}.message`, errors, 1024); return;
|
|
223
|
+
}
|
|
224
|
+
const allowed = ['schemaVersion', 'status', 'generation', 'candidateId', 'pointMm', 'projectedCssPx', 'distanceCssPx', 'kind', 'providerRef', 'guides'];
|
|
225
|
+
if (!fields(value, allowed, allowed, path, errors)) return;
|
|
226
|
+
if (value.schemaVersion !== MODEL_SNAP_SCHEMA.result) error(errors, `${path}.schemaVersion`, `must equal ${MODEL_SNAP_SCHEMA.result}`);
|
|
227
|
+
generation(value.generation, `${path}.generation`, errors); text(value.candidateId, `${path}.candidateId`, errors, 256); tuple(value.pointMm, 3, `${path}.pointMm`, errors); tuple(value.projectedCssPx, 2, `${path}.projectedCssPx`, errors, -MAX_CSS, MAX_CSS); number(value.distanceCssPx, `${path}.distanceCssPx`, errors, 0, MODEL_SNAP_LIMITS_V1.acquisitionRadiusCssPx);
|
|
228
|
+
if (!MODEL_SNAP_KIND_ORDER.includes(value.kind)) error(errors, `${path}.kind`, 'is not a canonical snap kind'); providerRef(value.providerRef, `${path}.providerRef`, errors);
|
|
229
|
+
if (value.providerRef?.generation && !same(value.generation, value.providerRef.generation)) error(errors, `${path}.providerRef.generation`, 'must equal result generation');
|
|
230
|
+
if (!Array.isArray(value.guides) || value.guides.length > 16) error(errors, `${path}.guides`, 'must contain at most 16 canonical guide primitives');
|
|
231
|
+
else value.guides.forEach((guide, i) => { primitive(guide, `${path}.guides[${i}]`, errors); if (!pointOnPrimitive(value.pointMm, guide)) error(errors, `${path}.guides[${i}]`, 'must pass through the acquired point'); });
|
|
232
|
+
}
|
|
233
|
+
export function validateModelSnapResult(value) { const errors = []; resultInto(value, '$', errors); return verdict(errors); }
|
|
234
|
+
function constraintInto(value, path, errors) {
|
|
235
|
+
priority(value, path, errors);
|
|
236
|
+
const allowed = ['schemaVersion', 'query', 'solverKind', 'firstAnchorMm', 'target', 'activeFrame', 'workPlane', 'extentPolicy'];
|
|
237
|
+
if (!fields(value, allowed, allowed, path, errors)) return;
|
|
238
|
+
if (value.schemaVersion !== MODEL_SNAP_SCHEMA.constraint) error(errors, `${path}.schemaVersion`, `must equal ${MODEL_SNAP_SCHEMA.constraint}`);
|
|
239
|
+
queryInto(value.query, `${path}.query`, errors); if (!MODEL_SNAP_SOLVER_KINDS.includes(value.solverKind)) error(errors, `${path}.solverKind`, 'must be perpendicular, parallel, or extension');
|
|
240
|
+
tuple(value.firstAnchorMm, 3, `${path}.firstAnchorMm`, errors); primitive(value.target, `${path}.target`, errors); frame(value.activeFrame, `${path}.activeFrame`, errors);
|
|
241
|
+
if (value.workPlane !== null) { primitive(value.workPlane, `${path}.workPlane`, errors); if (value.workPlane?.type !== 'plane') error(errors, `${path}.workPlane.type`, 'must be a plane or null'); }
|
|
242
|
+
if (!['finite', 'infinite'].includes(value.extentPolicy)) error(errors, `${path}.extentPolicy`, 'must be finite or infinite');
|
|
243
|
+
if (value.solverKind === 'extension' && value.target?.type !== 'segment') error(errors, `${path}.target.type`, 'extension requires a finite source segment');
|
|
244
|
+
if (value.solverKind !== 'extension' && !['segment', 'line', 'arc', 'circle'].includes(value.target?.type)) error(errors, `${path}.target.type`, 'contextual solver requires a linear or curved target');
|
|
245
|
+
}
|
|
246
|
+
export function validateModelSnapConstraint(value) { const errors = []; constraintInto(value, '$', errors); return verdict(errors); }
|
|
247
|
+
export function validateModelSnapSemanticsV1(value, type) {
|
|
248
|
+
if (type === 'query') return validateModelSnapQuery(value);
|
|
249
|
+
if (type === 'candidate') return validateModelSnapCandidate(value);
|
|
250
|
+
if (type === 'result') return validateModelSnapResult(value);
|
|
251
|
+
if (type === 'constraint') return validateModelSnapConstraint(value);
|
|
252
|
+
return verdict(['$: unknown model snap receipt type']);
|
|
253
|
+
}
|
|
254
|
+
export function validateModelSnapExchange({ query, candidate, result }) {
|
|
255
|
+
const q = validateModelSnapQuery(query), c = candidate ? validateModelSnapCandidate(candidate) : verdict([]), r = validateModelSnapResult(result);
|
|
256
|
+
const errors = [...q.errors.map((e) => `query${e.slice(1)}`), ...c.errors.map((e) => `candidate${e.slice(1)}`), ...r.errors.map((e) => `result${e.slice(1)}`)];
|
|
257
|
+
if (q.ok && r.ok && !same(query.generation, result.generation)) error(errors, 'result.generation', 'must equal query generation');
|
|
258
|
+
if (q.ok && r.ok && result.status === 'acquired' && !query.enabledKinds.includes(result.kind)) error(errors, 'result.kind', 'must be enabled by the query');
|
|
259
|
+
if (candidate && c.ok && r.ok && result.status === 'acquired') {
|
|
260
|
+
if (!same(candidate.generation, result.generation)) error(errors, 'result.generation', 'must equal candidate generation');
|
|
261
|
+
if (candidate.candidateId !== result.candidateId) error(errors, 'result.candidateId', 'must equal acquired candidate id');
|
|
262
|
+
if (candidate.kind !== result.kind) error(errors, 'result.kind', 'must equal acquired candidate kind');
|
|
263
|
+
if (!same(candidate.providerRef, result.providerRef)) error(errors, 'result.providerRef', 'must equal acquired candidate provider reference');
|
|
264
|
+
if (!pointOnPrimitive(result.pointMm, candidate.primitive)) error(errors, 'result.pointMm', 'must lie on the acquired candidate primitive');
|
|
265
|
+
}
|
|
266
|
+
return verdict(errors);
|
|
267
|
+
}
|