@thatopen/services 0.35.0 → 0.35.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/README.md +66 -66
  2. package/dist/cli.js.map +1 -1
  3. package/dist/index.cjs.js.map +1 -1
  4. package/dist/index.es.js.map +1 -1
  5. package/dist/vite-env.d.ts +1 -1
  6. package/docs/ai-quickstart.md +548 -548
  7. package/docs/builtin/paths.json +130 -130
  8. package/docs/cli/create.md +29 -29
  9. package/docs/cli/local-server.md +38 -38
  10. package/docs/cli/login.md +32 -32
  11. package/docs/cli/mcp.md +46 -46
  12. package/docs/cli/publish.md +31 -31
  13. package/docs/cli/run.md +26 -26
  14. package/docs/cli/serve.md +43 -43
  15. package/docs/cli/swap.md +30 -30
  16. package/docs/cloud/GaussianSplatConverter.md +43 -43
  17. package/docs/cloud/PointCloudConverter.md +53 -53
  18. package/docs/flow-architecture.md +393 -393
  19. package/docs/flow-plugin-guide.md +354 -354
  20. package/docs/platform-token.md +81 -81
  21. package/docs/rate-limits.md +133 -133
  22. package/docs/recipes-guide.md +243 -243
  23. package/docs/revit-collab-quickstart.md +445 -445
  24. package/docs/rhino-interop-quickstart.md +387 -387
  25. package/docs/sheet-sets-guide.md +69 -69
  26. package/package.json +1 -1
  27. package/resources/AGENTS.md +57 -57
  28. package/src/built-in/CDEManager/example.ts +214 -214
  29. package/src/built-in/CDEManager/examples/FileEditing/example.ts +226 -226
  30. package/src/built-in/CDEManager/examples/FileMoves/example.ts +186 -186
  31. package/src/built-in/CDEManager/examples/FileOperations/example.ts +295 -295
  32. package/src/built-in/CDEManager/examples/FileTransfers/example.ts +210 -210
  33. package/src/built-in/CDEManager/examples/FolderManagement/example.ts +230 -230
  34. package/src/built-in/CDEManager/examples/MetadataSchema/example.ts +230 -230
  35. package/src/built-in/CDEManager/examples/MetadataViews/example.ts +166 -166
  36. package/src/built-in/CDEManager/examples/ProjectConfig/example.ts +177 -177
  37. package/src/built-in/ClashesManager/example.ts +283 -283
  38. package/src/built-in/GISManager/example.ts +355 -355
  39. package/src/built-in/ProjectManager/example.ts +124 -124
  40. package/src/built-in/UIManager/src/app/example.ts +97 -97
  41. package/src/built-in/UIManager/src/app/examples/AppState/example.ts +140 -140
  42. package/src/built-in/UIManager/src/app/examples/Banner/example.ts +159 -159
  43. package/src/built-in/UIManager/src/app/examples/Contexts/example.ts +123 -123
  44. package/src/built-in/UIManager/src/app/examples/FileDrop/example.ts +124 -124
  45. package/src/built-in/UIManager/src/app/examples/FloatingLayout/example.ts +90 -90
  46. package/src/built-in/UIManager/src/app/examples/Modal/example.ts +163 -163
  47. package/src/built-in/UIManager/src/app/examples/Notifications/example.ts +133 -133
  48. package/src/built-in/UIManager/src/app/examples/ProjectFileStorage/example.ts +150 -150
  49. package/src/built-in/UIManager/src/app/examples/Sidebar/example.ts +105 -105
  50. package/src/built-in/UIManager/src/clashes-panel/example.ts +183 -183
  51. package/src/built-in/UIManager/src/gis-panel/example.ts +163 -163
  52. package/src/built-in/UIManager/src/gis-properties-panel/example.ts +168 -168
  53. package/src/built-in/UIManager/src/git-history-panel/example.ts +70 -70
  54. package/src/built-in/UIManager/src/map-panel/example.ts +189 -189
  55. package/src/built-in/UIManager/src/models-list/example.ts +181 -181
  56. package/src/built-in/UIManager/src/settings-panel/example.ts +303 -303
  57. package/src/built-in/UIManager/src/topics-panel/example.ts +170 -170
  58. package/src/built-in/UIManager/src/viewer/example.ts +182 -182
  59. package/src/built-in/UIManager/src/viewer-toolbar/example.ts +376 -376
  60. package/src/built-in/index.ts +2995 -2995
  61. package/src/cli/templates/app/README.md +250 -250
  62. package/src/cli/templates/app/index.html +35 -35
  63. package/src/cli/templates/app/package.json +32 -32
  64. package/src/cli/templates/app/src/app.ts +37 -37
  65. package/src/cli/templates/app/src/assets/tool-placeholder.ts +50 -50
  66. package/src/cli/templates/app/src/bim-components/CloudRunner/index.ts +95 -95
  67. package/src/cli/templates/app/src/bim-components/CloudRunner/src/index.ts +1 -1
  68. package/src/cli/templates/app/src/bim-components/CloudRunner/src/types.ts +5 -5
  69. package/src/cli/templates/app/src/bim-components/index.ts +1 -1
  70. package/src/cli/templates/app/src/globals.ts +1 -1
  71. package/src/cli/templates/app/src/main.history.ts +191 -191
  72. package/src/cli/templates/app/src/main.ts +226 -226
  73. package/src/cli/templates/app/src/setups/channel.ts +76 -76
  74. package/src/cli/templates/app/src/setups/reality-capture/lib/hidden-tiles-plugin.ts +88 -88
  75. package/src/cli/templates/app/src/setups/reality-capture/lib/point-tile-plugin.ts +166 -166
  76. package/src/cli/templates/app/src/setups/reality-capture/lib/render-frame.ts +31 -31
  77. package/src/cli/templates/app/src/setups/reality-capture/lib/splat-tile-plugin.ts +51 -51
  78. package/src/cli/templates/app/src/setups/reality-capture-viewer.ts +1383 -1383
  79. package/src/cli/templates/app/src/ui-components/app-info-section/index.ts +26 -26
  80. package/src/cli/templates/app/src/ui-components/app-info-section/src/index.ts +1 -1
  81. package/src/cli/templates/app/src/ui-components/app-info-section/src/types.ts +15 -15
  82. package/src/cli/templates/app/src/ui-components/cloud-runner-section/index.ts +37 -37
  83. package/src/cli/templates/app/src/ui-components/cloud-runner-section/src/index.ts +1 -1
  84. package/src/cli/templates/app/src/ui-components/cloud-runner-section/src/types.ts +14 -14
  85. package/src/cli/templates/app/src/ui-components/index.ts +2 -2
  86. package/src/cli/templates/app/tsconfig.json +16 -16
  87. package/src/cli/templates/app/vite.config.js +57 -57
  88. package/src/cli/templates/cloud-component/README.md +205 -205
  89. package/src/cli/templates/cloud-component/_thatopen +5 -5
  90. package/src/cli/templates/cloud-component/declarations.json +4 -4
  91. package/src/cli/templates/cloud-component/package.json +21 -21
  92. package/src/cli/templates/cloud-component/src/main.ts +70 -70
  93. package/src/cli/templates/cloud-component/tsconfig.json +16 -16
  94. package/src/cli/templates/cloud-component/vite.config.js +46 -46
  95. package/src/cli/templates/shared/AGENTS.md +8 -8
  96. package/src/cli/templates/shared/CLAUDE.md +1 -1
  97. package/src/cli/templates/shared/_gitignore +5 -5
  98. package/src/core/examples/.env.example +7 -7
  99. package/src/core/examples/apps.ts +67 -67
  100. package/src/core/examples/batch-reads.ts +99 -99
  101. package/src/core/examples/channel.ts +65 -65
  102. package/src/core/examples/components.ts +91 -91
  103. package/src/core/examples/execution.ts +75 -75
  104. package/src/core/examples/file-metadata.ts +94 -94
  105. package/src/core/examples/files.ts +81 -81
  106. package/src/core/examples/folders.ts +82 -82
  107. package/src/core/examples/hidden-files.ts +88 -88
  108. package/src/core/examples/history.ts +103 -103
  109. package/src/core/examples/icons.ts +68 -68
  110. package/src/core/examples/permissions.ts +87 -87
@@ -1,226 +1,226 @@
1
- import * as THREE from "three";
2
- import * as OBC from "@thatopen/components";
3
- import * as OBF from "@thatopen/components-front";
4
- import * as FRAGS from "@thatopen/fragments";
5
- // Inlines the fragments worker so it runs inside the platform's sandboxed iframe.
6
- import "@thatopen/fragments/inline";
7
- import * as BUI from "@thatopen/ui";
8
- import * as MARKERJS from "@markerjs/markerjs3";
9
- import { PlatformClient, UIManager } from "@thatopen/services";
10
- import { setAppContext } from "./app";
11
- import { setupChannel } from "./setups/channel";
12
-
13
- // ─── A2 migration — PHASES 1+2: boot on UIManager + re-dock panels ───────────
14
- // Juan consolidated the old AppManager (layout) + ViewportsManager (viewport)
15
- // built-ins into the single UIManager built-in, which ships `top-app` (shell +
16
- // layout) and `top-viewer` (deferred-PEN viewport). This boots the bim-viewer on
17
- // that model.
18
- // Phase 1 — top-app shell hosting one top-viewer + auto-load. [done]
19
- // Phase 2 — re-dock the side panels (tree/properties/files/data/objects/
20
- // settings) into top-app's layouts + sidebar. [this file]
21
- // Phase 3 — the viewer-overlay tools (fps/HUD/gizmo/bottom toolbar/measure +
22
- // clip handles) that mount over the canvas. [next]
23
- // The pre-A2 rich main is preserved at `main.rich.ts.bak`.
24
- async function main() {
25
- const client = PlatformClient.fromPlatformContext();
26
-
27
- // Brand accent (purple) — drives layout-selector active state, dividers, etc.
28
- document.documentElement.style.setProperty("--bim-ui_accent-base", "#6528d7");
29
-
30
- // The dev `thatopen serve` wrapper HTML doesn't zero the UA body margin (8px),
31
- // which insets the whole app inside the platform iframe. Kill it here so it's
32
- // fixed in both dev and production regardless of the host page.
33
- document.body.style.margin = "0";
34
-
35
- // UIManager must be in the setup call: it registers the platform web
36
- // components (top-app, top-viewer, top-viewer-tools, …) before the DOM renders.
37
- const { components } = await client.setup<OBC.Components>(
38
- { OBC, OBF, BUI, THREE, FRAGS, MARKERJS },
39
- { uuid: UIManager.uuid },
40
- );
41
- components.get(UIManager).init();
42
-
43
- // The platform channel, pre-wired (see ./setups/channel.ts): external tools
44
- // of this account (an MCP server, a CLI, a plugin) can command this app, and
45
- // other open tabs of it are reachable for collaboration. Joined HERE, before
46
- // any await the boot can park on (the world, project data): a stalled fetch
47
- // further down must not leave the app unreachable — and silently so, since a
48
- // join that is never requested also never gets to time out loudly. It only
49
- // exists inside the platform iframe, so a failure is a warning, never a boot
50
- // error.
51
- try {
52
- setupChannel(client, components);
53
- } catch (error) {
54
- console.warn("[channel] unavailable outside the platform:", error);
55
- }
56
-
57
- // One STABLE top-viewer node, returned by reference so re-rendering top-app
58
- // (when we add the panels below) reuses it instead of disposing/recreating
59
- // its world. No <top-viewer-tools>: the bim-viewer mounts its own tabbed
60
- // visibility/inspect toolbar (see below), so the platform default would just
61
- // duplicate it.
62
- const viewerEl = document.createElement("top-viewer");
63
- // Frame the viewport to match the side panels (BUI bim-panel host = 1px border
64
- // + 0.75rem radius). top-viewer's host is already overflow:hidden, so the
65
- // radius clips the canvas corners; border-box keeps the 1px inside the grid
66
- // area. Done here (not in top-viewer) so the CDE's top-file-viewer, which draws
67
- // its own frame, never double-borders.
68
- viewerEl.style.border = "1px solid var(--bim-ui_bg-contrast-20)";
69
- viewerEl.style.borderRadius = "0.75rem";
70
- viewerEl.style.boxSizing = "border-box";
71
-
72
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
- const app = document.createElement("top-app") as any;
74
-
75
- app.setup = (waitUntil: (p: Promise<void>, label?: string) => void) => {
76
- waitUntil(
77
- (async () => {
78
- const fragments = components.get(OBC.FragmentsManager);
79
- const workerUrl = await FRAGS.FragmentsModels.getWorker();
80
- fragments.init(await FRAGS.toClassicWorker(workerUrl), {
81
- classicWorker: true,
82
- });
83
- })(),
84
- "Fragments Core",
85
- );
86
- return { components, client };
87
- };
88
-
89
- // Mount minimally first (viewer only) so top-viewer creates the world; the
90
- // panels + their tools are built once that world exists (below).
91
- app.elements = { viewer: () => BUI.html`${viewerEl}` };
92
- app.layouts = {
93
- Main: {
94
- label: "Main",
95
- icon: "solar:3d-square-bold",
96
- template: `"viewer" 1fr / 1fr`,
97
- },
98
- };
99
- app.layout = "Main";
100
-
101
- const container = document.getElementById("that-open-app") ?? document.body;
102
- container.appendChild(app);
103
-
104
- // Wait for top-viewer's world to exist before building world-dependent panels.
105
- // The viewer tool suite + dynamic-anchor pivot dot are now baked into
106
- // <top-viewer> (setupViewerTools), so the app no longer wires them.
107
- await firstWorld(components.get(OBC.Worlds));
108
-
109
- // Platform client + project data for the AppManager-shim consumers
110
- // (CloudRunner, data-table-panel, app-info-section).
111
- const projectId: string | undefined = client?.context?.projectId;
112
- let projectData;
113
- try {
114
- // Bounded: this request carries no AbortSignal, so a stalled response
115
- // parked everything below it for good (that is how the app once ended up
116
- // booted but with no panels and, before the channel moved up top, deaf to
117
- // external tools). Past the deadline the app boots without project data —
118
- // the same degraded path the catch below already provides.
119
- if (projectId) {
120
- projectData = await Promise.race([
121
- client.getProjectData(projectId),
122
- new Promise<undefined>((resolve) => {
123
- setTimeout(() => resolve(undefined), 20_000);
124
- }),
125
- ]);
126
- }
127
- } catch {
128
- /* dev/no-project → consumers degrade gracefully */
129
- }
130
- setAppContext(client, projectData);
131
-
132
- // Pluggable loaders for <top-models-list>. The built-in ships the lightweight
133
- // defaults (.frag load, IFC→fragments convert); heavy/app-specific loaders are
134
- // registered here so they stay OUT of the built-in's bundle. The reality-capture
135
- // .3tz viewer pulls Spark + 3d-tiles-renderer, so it's lazy-imported app-side
136
- // and plugged in via the loader registry. Alignment persists through the panel's
137
- // app-data via the loader context (getAlignment/setAlignment).
138
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
139
- let rcViewer: any = null;
140
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
141
- const modelLoaders: Record<string, any> = {
142
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
143
- "3tz": async (fileId: string, ctx: any) => {
144
- if (!rcViewer) {
145
- const { realityCaptureViewer } = await import(
146
- "./setups/reality-capture-viewer"
147
- );
148
- rcViewer = realityCaptureViewer(ctx.components, client);
149
- }
150
- const saved = ctx.getAlignment(fileId) as number[] | undefined;
151
- await rcViewer.loadIntoWorld(fileId, {
152
- keepPostproduction: true,
153
- transform: saved ? new THREE.Matrix4().fromArray(saved) : undefined,
154
- onTransformChange: (m: THREE.Matrix4) =>
155
- ctx.setAlignment(fileId, m.toArray()),
156
- });
157
- },
158
- };
159
-
160
- // Re-dock: the stable viewer + the panels, under the bim-viewer's named layouts
161
- // with the activity-bar sidebar (Explorer · Assets · Data · Settings). All panels
162
- // are now built-ins that self-wire from top-app's componentsContext/clientContext
163
- // — no `components` plumbing in the app.
164
- app.elements = {
165
- viewer: () => BUI.html`${viewerEl}`,
166
- tree: () => BUI.html`<top-model-tree></top-model-tree>`,
167
- properties: () => BUI.html`<top-properties-panel></top-properties-panel>`,
168
- files: () =>
169
- BUI.html`<top-models-list .loaders=${modelLoaders}></top-models-list>`,
170
- dataTable: () => BUI.html`<top-data-table-panel></top-data-table-panel>`,
171
- objects: () => BUI.html`<top-objects-panel></top-objects-panel>`,
172
- settings: () => BUI.html`<top-settings-panel></top-settings-panel>`,
173
- };
174
- // No `label` → the sidebar renders icon-only activity-bar buttons (matching
175
- // the pre-A2 look), background only on the active one.
176
- app.layouts = {
177
- Explorer: {
178
- icon: "mdi:file-tree",
179
- template: `"tree viewer" 1fr "properties viewer" 1fr / 22rem 1fr`,
180
- },
181
- Assets: {
182
- icon: "mdi:folder-multiple-outline",
183
- template: `"files viewer" 1fr "objects viewer" 1fr / 22rem 1fr`,
184
- },
185
- Data: {
186
- icon: "mdi:table",
187
- template: `"dataTable viewer" 1fr / 22rem 1fr`,
188
- },
189
- Settings: {
190
- icon: "mdi:cog",
191
- template: `"settings viewer" 1fr / 22rem 1fr`,
192
- },
193
- };
194
- app.layout = "Explorer";
195
- app.sidebar = true;
196
-
197
- // ── Viewer toolbar — now a built-in slotted INTO <top-viewer> (it consumes the
198
- // world + components contexts top-viewer provides). The rich bottom toolbar +
199
- // active-tool HUD + clip/measure/walkthrough tools all live in
200
- // <top-viewer-toolbar>; the side panels share the SAME tool singletons via
201
- // components.get (OBC.Component-wrapped).
202
- viewerEl.appendChild(document.createElement("top-viewer-toolbar"));
203
-
204
- // Navigation gizmo is now baked into <top-viewer> (setupViewerTools), so the
205
- // app no longer mounts it. (Cascade: the rest of the overlay tools follow.)
206
-
207
- // No auto-load: the viewer opens empty. Users add models from the Assets
208
- // (files) panel — top-models-list loads the .frag they pick into the world.
209
- }
210
-
211
- /** Resolves with the first world once it exists (top-viewer creates it async). */
212
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
213
- function firstWorld(worlds: any): Promise<any> {
214
- const existing = [...worlds.list.values()][0];
215
- if (existing) return Promise.resolve(existing);
216
- return new Promise((resolve) => {
217
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
218
- const handler = ({ value }: any) => {
219
- worlds.list.onItemSet.remove(handler);
220
- resolve(value);
221
- };
222
- worlds.list.onItemSet.add(handler);
223
- });
224
- }
225
-
226
- main().catch(console.error);
1
+ import * as THREE from "three";
2
+ import * as OBC from "@thatopen/components";
3
+ import * as OBF from "@thatopen/components-front";
4
+ import * as FRAGS from "@thatopen/fragments";
5
+ // Inlines the fragments worker so it runs inside the platform's sandboxed iframe.
6
+ import "@thatopen/fragments/inline";
7
+ import * as BUI from "@thatopen/ui";
8
+ import * as MARKERJS from "@markerjs/markerjs3";
9
+ import { PlatformClient, UIManager } from "@thatopen/services";
10
+ import { setAppContext } from "./app";
11
+ import { setupChannel } from "./setups/channel";
12
+
13
+ // ─── A2 migration — PHASES 1+2: boot on UIManager + re-dock panels ───────────
14
+ // Juan consolidated the old AppManager (layout) + ViewportsManager (viewport)
15
+ // built-ins into the single UIManager built-in, which ships `top-app` (shell +
16
+ // layout) and `top-viewer` (deferred-PEN viewport). This boots the bim-viewer on
17
+ // that model.
18
+ // Phase 1 — top-app shell hosting one top-viewer + auto-load. [done]
19
+ // Phase 2 — re-dock the side panels (tree/properties/files/data/objects/
20
+ // settings) into top-app's layouts + sidebar. [this file]
21
+ // Phase 3 — the viewer-overlay tools (fps/HUD/gizmo/bottom toolbar/measure +
22
+ // clip handles) that mount over the canvas. [next]
23
+ // The pre-A2 rich main is preserved at `main.rich.ts.bak`.
24
+ async function main() {
25
+ const client = PlatformClient.fromPlatformContext();
26
+
27
+ // Brand accent (purple) — drives layout-selector active state, dividers, etc.
28
+ document.documentElement.style.setProperty("--bim-ui_accent-base", "#6528d7");
29
+
30
+ // The dev `thatopen serve` wrapper HTML doesn't zero the UA body margin (8px),
31
+ // which insets the whole app inside the platform iframe. Kill it here so it's
32
+ // fixed in both dev and production regardless of the host page.
33
+ document.body.style.margin = "0";
34
+
35
+ // UIManager must be in the setup call: it registers the platform web
36
+ // components (top-app, top-viewer, top-viewer-tools, …) before the DOM renders.
37
+ const { components } = await client.setup<OBC.Components>(
38
+ { OBC, OBF, BUI, THREE, FRAGS, MARKERJS },
39
+ { uuid: UIManager.uuid },
40
+ );
41
+ components.get(UIManager).init();
42
+
43
+ // The platform channel, pre-wired (see ./setups/channel.ts): external tools
44
+ // of this account (an MCP server, a CLI, a plugin) can command this app, and
45
+ // other open tabs of it are reachable for collaboration. Joined HERE, before
46
+ // any await the boot can park on (the world, project data): a stalled fetch
47
+ // further down must not leave the app unreachable — and silently so, since a
48
+ // join that is never requested also never gets to time out loudly. It only
49
+ // exists inside the platform iframe, so a failure is a warning, never a boot
50
+ // error.
51
+ try {
52
+ setupChannel(client, components);
53
+ } catch (error) {
54
+ console.warn("[channel] unavailable outside the platform:", error);
55
+ }
56
+
57
+ // One STABLE top-viewer node, returned by reference so re-rendering top-app
58
+ // (when we add the panels below) reuses it instead of disposing/recreating
59
+ // its world. No <top-viewer-tools>: the bim-viewer mounts its own tabbed
60
+ // visibility/inspect toolbar (see below), so the platform default would just
61
+ // duplicate it.
62
+ const viewerEl = document.createElement("top-viewer");
63
+ // Frame the viewport to match the side panels (BUI bim-panel host = 1px border
64
+ // + 0.75rem radius). top-viewer's host is already overflow:hidden, so the
65
+ // radius clips the canvas corners; border-box keeps the 1px inside the grid
66
+ // area. Done here (not in top-viewer) so the CDE's top-file-viewer, which draws
67
+ // its own frame, never double-borders.
68
+ viewerEl.style.border = "1px solid var(--bim-ui_bg-contrast-20)";
69
+ viewerEl.style.borderRadius = "0.75rem";
70
+ viewerEl.style.boxSizing = "border-box";
71
+
72
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
+ const app = document.createElement("top-app") as any;
74
+
75
+ app.setup = (waitUntil: (p: Promise<void>, label?: string) => void) => {
76
+ waitUntil(
77
+ (async () => {
78
+ const fragments = components.get(OBC.FragmentsManager);
79
+ const workerUrl = await FRAGS.FragmentsModels.getWorker();
80
+ fragments.init(await FRAGS.toClassicWorker(workerUrl), {
81
+ classicWorker: true,
82
+ });
83
+ })(),
84
+ "Fragments Core",
85
+ );
86
+ return { components, client };
87
+ };
88
+
89
+ // Mount minimally first (viewer only) so top-viewer creates the world; the
90
+ // panels + their tools are built once that world exists (below).
91
+ app.elements = { viewer: () => BUI.html`${viewerEl}` };
92
+ app.layouts = {
93
+ Main: {
94
+ label: "Main",
95
+ icon: "solar:3d-square-bold",
96
+ template: `"viewer" 1fr / 1fr`,
97
+ },
98
+ };
99
+ app.layout = "Main";
100
+
101
+ const container = document.getElementById("that-open-app") ?? document.body;
102
+ container.appendChild(app);
103
+
104
+ // Wait for top-viewer's world to exist before building world-dependent panels.
105
+ // The viewer tool suite + dynamic-anchor pivot dot are now baked into
106
+ // <top-viewer> (setupViewerTools), so the app no longer wires them.
107
+ await firstWorld(components.get(OBC.Worlds));
108
+
109
+ // Platform client + project data for the AppManager-shim consumers
110
+ // (CloudRunner, data-table-panel, app-info-section).
111
+ const projectId: string | undefined = client?.context?.projectId;
112
+ let projectData;
113
+ try {
114
+ // Bounded: this request carries no AbortSignal, so a stalled response
115
+ // parked everything below it for good (that is how the app once ended up
116
+ // booted but with no panels and, before the channel moved up top, deaf to
117
+ // external tools). Past the deadline the app boots without project data —
118
+ // the same degraded path the catch below already provides.
119
+ if (projectId) {
120
+ projectData = await Promise.race([
121
+ client.getProjectData(projectId),
122
+ new Promise<undefined>((resolve) => {
123
+ setTimeout(() => resolve(undefined), 20_000);
124
+ }),
125
+ ]);
126
+ }
127
+ } catch {
128
+ /* dev/no-project → consumers degrade gracefully */
129
+ }
130
+ setAppContext(client, projectData);
131
+
132
+ // Pluggable loaders for <top-models-list>. The built-in ships the lightweight
133
+ // defaults (.frag load, IFC→fragments convert); heavy/app-specific loaders are
134
+ // registered here so they stay OUT of the built-in's bundle. The reality-capture
135
+ // .3tz viewer pulls Spark + 3d-tiles-renderer, so it's lazy-imported app-side
136
+ // and plugged in via the loader registry. Alignment persists through the panel's
137
+ // app-data via the loader context (getAlignment/setAlignment).
138
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
139
+ let rcViewer: any = null;
140
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
141
+ const modelLoaders: Record<string, any> = {
142
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
143
+ "3tz": async (fileId: string, ctx: any) => {
144
+ if (!rcViewer) {
145
+ const { realityCaptureViewer } = await import(
146
+ "./setups/reality-capture-viewer"
147
+ );
148
+ rcViewer = realityCaptureViewer(ctx.components, client);
149
+ }
150
+ const saved = ctx.getAlignment(fileId) as number[] | undefined;
151
+ await rcViewer.loadIntoWorld(fileId, {
152
+ keepPostproduction: true,
153
+ transform: saved ? new THREE.Matrix4().fromArray(saved) : undefined,
154
+ onTransformChange: (m: THREE.Matrix4) =>
155
+ ctx.setAlignment(fileId, m.toArray()),
156
+ });
157
+ },
158
+ };
159
+
160
+ // Re-dock: the stable viewer + the panels, under the bim-viewer's named layouts
161
+ // with the activity-bar sidebar (Explorer · Assets · Data · Settings). All panels
162
+ // are now built-ins that self-wire from top-app's componentsContext/clientContext
163
+ // — no `components` plumbing in the app.
164
+ app.elements = {
165
+ viewer: () => BUI.html`${viewerEl}`,
166
+ tree: () => BUI.html`<top-model-tree></top-model-tree>`,
167
+ properties: () => BUI.html`<top-properties-panel></top-properties-panel>`,
168
+ files: () =>
169
+ BUI.html`<top-models-list .loaders=${modelLoaders}></top-models-list>`,
170
+ dataTable: () => BUI.html`<top-data-table-panel></top-data-table-panel>`,
171
+ objects: () => BUI.html`<top-objects-panel></top-objects-panel>`,
172
+ settings: () => BUI.html`<top-settings-panel></top-settings-panel>`,
173
+ };
174
+ // No `label` → the sidebar renders icon-only activity-bar buttons (matching
175
+ // the pre-A2 look), background only on the active one.
176
+ app.layouts = {
177
+ Explorer: {
178
+ icon: "mdi:file-tree",
179
+ template: `"tree viewer" 1fr "properties viewer" 1fr / 22rem 1fr`,
180
+ },
181
+ Assets: {
182
+ icon: "mdi:folder-multiple-outline",
183
+ template: `"files viewer" 1fr "objects viewer" 1fr / 22rem 1fr`,
184
+ },
185
+ Data: {
186
+ icon: "mdi:table",
187
+ template: `"dataTable viewer" 1fr / 22rem 1fr`,
188
+ },
189
+ Settings: {
190
+ icon: "mdi:cog",
191
+ template: `"settings viewer" 1fr / 22rem 1fr`,
192
+ },
193
+ };
194
+ app.layout = "Explorer";
195
+ app.sidebar = true;
196
+
197
+ // ── Viewer toolbar — now a built-in slotted INTO <top-viewer> (it consumes the
198
+ // world + components contexts top-viewer provides). The rich bottom toolbar +
199
+ // active-tool HUD + clip/measure/walkthrough tools all live in
200
+ // <top-viewer-toolbar>; the side panels share the SAME tool singletons via
201
+ // components.get (OBC.Component-wrapped).
202
+ viewerEl.appendChild(document.createElement("top-viewer-toolbar"));
203
+
204
+ // Navigation gizmo is now baked into <top-viewer> (setupViewerTools), so the
205
+ // app no longer mounts it. (Cascade: the rest of the overlay tools follow.)
206
+
207
+ // No auto-load: the viewer opens empty. Users add models from the Assets
208
+ // (files) panel — top-models-list loads the .frag they pick into the world.
209
+ }
210
+
211
+ /** Resolves with the first world once it exists (top-viewer creates it async). */
212
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
213
+ function firstWorld(worlds: any): Promise<any> {
214
+ const existing = [...worlds.list.values()][0];
215
+ if (existing) return Promise.resolve(existing);
216
+ return new Promise((resolve) => {
217
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
218
+ const handler = ({ value }: any) => {
219
+ worlds.list.onItemSet.remove(handler);
220
+ resolve(value);
221
+ };
222
+ worlds.list.onItemSet.add(handler);
223
+ });
224
+ }
225
+
226
+ main().catch(console.error);
@@ -1,76 +1,76 @@
1
- /**
2
- * The platform channel, pre-wired: typed commands that an external tool (an
3
- * MCP server, a CLI, a desktop LLM, a plugin) can send this app while it runs,
4
- * and a collaboration room where every open tab of this app hears the others.
5
- *
6
- * The app never opens a socket. The platform shell owns the one connection and
7
- * relays over `postMessage`; `client.channel` is the typed layer on top. That
8
- * also means this only works inside the platform iframe — `setupChannel` is
9
- * called from a try/catch in `main.ts` so the app still boots anywhere else.
10
- *
11
- * To extend: add a command to {@link AppCommands} and handle it below. What a
12
- * handler returns is sent back to whoever asked; throw and they get the error.
13
- * Full walkthrough: `node_modules/@thatopen/services/src/core/examples/channel.ts`.
14
- */
15
- import * as OBC from "@thatopen/components";
16
- import { PlatformClient } from "@thatopen/services";
17
-
18
- /**
19
- * The contract with external tools. Each command names its payload and, when
20
- * the caller waits for an answer, its reply. A command without `reply` is a
21
- * notification. This type is the whole API an MCP server sees: keep it honest.
22
- */
23
- export type AppCommands = {
24
- /** Liveness check — answer whoever is probing that this app is listening. */
25
- ping: { payload: { echo?: string } | undefined; reply: { pong: true; echo?: string } };
26
- /** The ids of the models currently loaded in the viewer. */
27
- "get-loaded-models": { payload: undefined; reply: { models: string[] } };
28
- };
29
-
30
- /** Events tabs of this app send each other. Events, so no replies. */
31
- export type AppCollabEvents = {
32
- /** Sent once on join, so other tabs can log or greet. Replace with your own. */
33
- hello: { at: number };
34
- };
35
-
36
- /**
37
- * Wires both rooms and joins them at boot. Joining is what makes the app
38
- * reachable — until then, nothing arrives. If you'd rather listen only when
39
- * the user opts in, move the `join()` calls behind a button.
40
- */
41
- export function setupChannel(
42
- client: PlatformClient,
43
- components: OBC.Components,
44
- ) {
45
- // Commands from every kind of external tool of this account. Narrow with
46
- // `client.channel.external<AppCommands>("mcp")` to hear one kind only.
47
- const external = client.channel.external<AppCommands>();
48
-
49
- external.on("ping", (payload) => ({ pong: true as const, echo: payload?.echo }));
50
-
51
- external.on("get-loaded-models", () => {
52
- const fragments = components.get(OBC.FragmentsManager);
53
- return { models: [...fragments.list.keys()] };
54
- });
55
-
56
- // Collaboration: other users' tabs of this same app, across accounts.
57
- const collab = client.channel.collab<AppCollabEvents>();
58
- collab.on("hello", (event, { from }) => {
59
- console.log(`[channel] tab ${from} joined the collaboration`, event);
60
- });
61
- collab.onPeerLeft(({ from }) => {
62
- console.log(`[channel] tab ${from} left the collaboration`);
63
- });
64
-
65
- // Fire-and-forget joins: the app is usable with or without the channel, so
66
- // a failure is a warning, never a boot error.
67
- external
68
- .join()
69
- .catch((error) => console.warn("[channel] external join failed:", error));
70
- collab
71
- .join()
72
- .then(() => collab.send("hello", { at: Date.now() }))
73
- .catch((error) => console.warn("[channel] collab join failed:", error));
74
-
75
- return { external, collab };
76
- }
1
+ /**
2
+ * The platform channel, pre-wired: typed commands that an external tool (an
3
+ * MCP server, a CLI, a desktop LLM, a plugin) can send this app while it runs,
4
+ * and a collaboration room where every open tab of this app hears the others.
5
+ *
6
+ * The app never opens a socket. The platform shell owns the one connection and
7
+ * relays over `postMessage`; `client.channel` is the typed layer on top. That
8
+ * also means this only works inside the platform iframe — `setupChannel` is
9
+ * called from a try/catch in `main.ts` so the app still boots anywhere else.
10
+ *
11
+ * To extend: add a command to {@link AppCommands} and handle it below. What a
12
+ * handler returns is sent back to whoever asked; throw and they get the error.
13
+ * Full walkthrough: `node_modules/@thatopen/services/src/core/examples/channel.ts`.
14
+ */
15
+ import * as OBC from "@thatopen/components";
16
+ import { PlatformClient } from "@thatopen/services";
17
+
18
+ /**
19
+ * The contract with external tools. Each command names its payload and, when
20
+ * the caller waits for an answer, its reply. A command without `reply` is a
21
+ * notification. This type is the whole API an MCP server sees: keep it honest.
22
+ */
23
+ export type AppCommands = {
24
+ /** Liveness check — answer whoever is probing that this app is listening. */
25
+ ping: { payload: { echo?: string } | undefined; reply: { pong: true; echo?: string } };
26
+ /** The ids of the models currently loaded in the viewer. */
27
+ "get-loaded-models": { payload: undefined; reply: { models: string[] } };
28
+ };
29
+
30
+ /** Events tabs of this app send each other. Events, so no replies. */
31
+ export type AppCollabEvents = {
32
+ /** Sent once on join, so other tabs can log or greet. Replace with your own. */
33
+ hello: { at: number };
34
+ };
35
+
36
+ /**
37
+ * Wires both rooms and joins them at boot. Joining is what makes the app
38
+ * reachable — until then, nothing arrives. If you'd rather listen only when
39
+ * the user opts in, move the `join()` calls behind a button.
40
+ */
41
+ export function setupChannel(
42
+ client: PlatformClient,
43
+ components: OBC.Components,
44
+ ) {
45
+ // Commands from every kind of external tool of this account. Narrow with
46
+ // `client.channel.external<AppCommands>("mcp")` to hear one kind only.
47
+ const external = client.channel.external<AppCommands>();
48
+
49
+ external.on("ping", (payload) => ({ pong: true as const, echo: payload?.echo }));
50
+
51
+ external.on("get-loaded-models", () => {
52
+ const fragments = components.get(OBC.FragmentsManager);
53
+ return { models: [...fragments.list.keys()] };
54
+ });
55
+
56
+ // Collaboration: other users' tabs of this same app, across accounts.
57
+ const collab = client.channel.collab<AppCollabEvents>();
58
+ collab.on("hello", (event, { from }) => {
59
+ console.log(`[channel] tab ${from} joined the collaboration`, event);
60
+ });
61
+ collab.onPeerLeft(({ from }) => {
62
+ console.log(`[channel] tab ${from} left the collaboration`);
63
+ });
64
+
65
+ // Fire-and-forget joins: the app is usable with or without the channel, so
66
+ // a failure is a warning, never a boot error.
67
+ external
68
+ .join()
69
+ .catch((error) => console.warn("[channel] external join failed:", error));
70
+ collab
71
+ .join()
72
+ .then(() => collab.send("hello", { at: Date.now() }))
73
+ .catch((error) => console.warn("[channel] collab join failed:", error));
74
+
75
+ return { external, collab };
76
+ }