@snaptrude/plugin-core 0.5.0 → 0.7.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.
Files changed (134) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/api-manifest.full.json +2644 -542
  3. package/api-manifest.json +2606 -424
  4. package/dist/api/analysis/heatmaps.d.ts +234 -0
  5. package/dist/api/analysis/heatmaps.d.ts.map +1 -0
  6. package/dist/api/analysis/illuminance.d.ts +145 -0
  7. package/dist/api/analysis/illuminance.d.ts.map +1 -0
  8. package/dist/api/analysis/index.d.ts +44 -0
  9. package/dist/api/analysis/index.d.ts.map +1 -0
  10. package/dist/api/analysis/shadows.d.ts +165 -0
  11. package/dist/api/analysis/shadows.d.ts.map +1 -0
  12. package/dist/api/analysis/sunlightHours.d.ts +208 -0
  13. package/dist/api/analysis/sunlightHours.d.ts.map +1 -0
  14. package/dist/api/analysis/sunpath.d.ts +80 -0
  15. package/dist/api/analysis/sunpath.d.ts.map +1 -0
  16. package/dist/api/core/index.d.ts +10 -0
  17. package/dist/api/core/index.d.ts.map +1 -1
  18. package/dist/api/core/io/import/index.d.ts +392 -0
  19. package/dist/api/core/io/import/index.d.ts.map +1 -0
  20. package/dist/api/core/io/index.d.ts +35 -0
  21. package/dist/api/core/io/index.d.ts.map +1 -0
  22. package/dist/api/core/io/job/index.d.ts +139 -0
  23. package/dist/api/core/io/job/index.d.ts.map +1 -0
  24. package/dist/api/core/io/query/index.d.ts +74 -0
  25. package/dist/api/core/io/query/index.d.ts.map +1 -0
  26. package/dist/api/core/io/terrain/index.d.ts +206 -0
  27. package/dist/api/core/io/terrain/index.d.ts.map +1 -0
  28. package/dist/api/core/io/underlay/index.d.ts +286 -0
  29. package/dist/api/core/io/underlay/index.d.ts.map +1 -0
  30. package/dist/api/core/layers.d.ts +7 -7
  31. package/dist/api/core/proposals/index.d.ts +475 -0
  32. package/dist/api/core/proposals/index.d.ts.map +1 -0
  33. package/dist/api/design/create/index.d.ts +218 -0
  34. package/dist/api/design/create/index.d.ts.map +1 -1
  35. package/dist/api/design/doors/index.d.ts +159 -0
  36. package/dist/api/design/doors/index.d.ts.map +1 -1
  37. package/dist/api/design/furniture/index.d.ts +34 -5
  38. package/dist/api/design/furniture/index.d.ts.map +1 -1
  39. package/dist/api/design/index.d.ts +83 -0
  40. package/dist/api/design/index.d.ts.map +1 -1
  41. package/dist/api/design/lock.d.ts +26 -0
  42. package/dist/api/design/lock.d.ts.map +1 -1
  43. package/dist/api/design/materials/index.d.ts +159 -2
  44. package/dist/api/design/materials/index.d.ts.map +1 -1
  45. package/dist/api/design/query/index.d.ts +115 -5
  46. package/dist/api/design/query/index.d.ts.map +1 -1
  47. package/dist/api/design/query/spaces.d.ts +3 -3
  48. package/dist/api/design/selection/index.d.ts +144 -0
  49. package/dist/api/design/selection/index.d.ts.map +1 -1
  50. package/dist/api/design/transform/index.d.ts +83 -2
  51. package/dist/api/design/transform/index.d.ts.map +1 -1
  52. package/dist/api/design/update/index.d.ts +168 -0
  53. package/dist/api/design/update/index.d.ts.map +1 -1
  54. package/dist/api/design/windows/index.d.ts +113 -2
  55. package/dist/api/design/windows/index.d.ts.map +1 -1
  56. package/dist/api/entity/space.d.ts +2 -2
  57. package/dist/api/entity/story.d.ts +101 -7
  58. package/dist/api/entity/story.d.ts.map +1 -1
  59. package/dist/api/index.d.ts +5 -0
  60. package/dist/api/index.d.ts.map +1 -1
  61. package/dist/api/presentation/import.d.ts +49 -4
  62. package/dist/api/presentation/import.d.ts.map +1 -1
  63. package/dist/api/presentation/views.d.ts +210 -5
  64. package/dist/api/presentation/views.d.ts.map +1 -1
  65. package/dist/api/program/areas.d.ts +42 -12
  66. package/dist/api/program/areas.d.ts.map +1 -1
  67. package/dist/api/program/index.d.ts +3 -11
  68. package/dist/api/program/index.d.ts.map +1 -1
  69. package/dist/api/program/layout.d.ts +186 -11
  70. package/dist/api/program/layout.d.ts.map +1 -1
  71. package/dist/api/program/site.d.ts +84 -0
  72. package/dist/api/program/site.d.ts.map +1 -1
  73. package/dist/errors/codes.d.ts +34 -0
  74. package/dist/errors/codes.d.ts.map +1 -0
  75. package/dist/errors/envelope.d.ts +56 -0
  76. package/dist/errors/envelope.d.ts.map +1 -0
  77. package/dist/errors/index.d.ts +6 -0
  78. package/dist/errors/index.d.ts.map +1 -0
  79. package/dist/errors/plugin-error.d.ts +69 -0
  80. package/dist/errors/plugin-error.d.ts.map +1 -0
  81. package/dist/handles.d.ts +33 -0
  82. package/dist/handles.d.ts.map +1 -1
  83. package/dist/host-utils.d.ts +4 -0
  84. package/dist/host-utils.d.ts.map +1 -1
  85. package/dist/index.cjs +1942 -998
  86. package/dist/index.cjs.map +1 -1
  87. package/dist/index.d.ts +1 -0
  88. package/dist/index.d.ts.map +1 -1
  89. package/dist/index.js +1810 -994
  90. package/dist/index.js.map +1 -1
  91. package/package.json +2 -1
  92. package/scripts/generate-manifest.test.mjs +103 -4
  93. package/src/api/analysis/heatmaps.ts +256 -0
  94. package/src/api/analysis/illuminance.ts +155 -0
  95. package/src/api/analysis/index.ts +46 -0
  96. package/src/api/analysis/shadows.ts +183 -0
  97. package/src/api/analysis/sunlightHours.ts +211 -0
  98. package/src/api/analysis/sunpath.ts +83 -0
  99. package/src/api/core/index.ts +10 -0
  100. package/src/api/core/io/import/index.ts +432 -0
  101. package/src/api/core/io/index.ts +37 -0
  102. package/src/api/core/io/job/index.ts +140 -0
  103. package/src/api/core/io/query/index.ts +71 -0
  104. package/src/api/core/io/terrain/index.ts +214 -0
  105. package/src/api/core/io/underlay/index.ts +295 -0
  106. package/src/api/core/proposals/index.ts +509 -0
  107. package/src/api/design/create/index.ts +258 -0
  108. package/src/api/design/doors/index.ts +168 -0
  109. package/src/api/design/erase/index.ts +1 -1
  110. package/src/api/design/furniture/index.ts +36 -5
  111. package/src/api/design/index.ts +87 -0
  112. package/src/api/design/lock.ts +27 -0
  113. package/src/api/design/materials/index.ts +182 -2
  114. package/src/api/design/query/index.ts +81 -0
  115. package/src/api/design/selection/index.ts +129 -0
  116. package/src/api/design/transform/index.ts +74 -2
  117. package/src/api/design/update/index.ts +167 -0
  118. package/src/api/design/windows/index.ts +128 -2
  119. package/src/api/entity/story.ts +105 -7
  120. package/src/api/index.ts +5 -0
  121. package/src/api/presentation/import.ts +45 -4
  122. package/src/api/presentation/views.ts +221 -5
  123. package/src/api/program/areas.ts +34 -12
  124. package/src/api/program/index.ts +3 -11
  125. package/src/api/program/layout.ts +195 -11
  126. package/src/api/program/site.ts +93 -0
  127. package/src/errors/codes.ts +136 -0
  128. package/src/errors/envelope.ts +75 -0
  129. package/src/errors/index.ts +21 -0
  130. package/src/errors/plugin-error.ts +134 -0
  131. package/src/handles.ts +46 -0
  132. package/src/host-utils.ts +4 -0
  133. package/src/index.ts +1 -0
  134. package/test/errors.test.mjs +184 -0
@@ -6,12 +6,12 @@ import { PluginApiReturn } from "../../types"
6
6
  *
7
7
  * A **view** is a saved camera/plan: a sheet-ready 2D plan or a saved 3D view.
8
8
  * A plugin can list and read views, capture them to images, activate one (move
9
- * the camera to it), and save the current camera as a new view.
9
+ * the camera to it), save the current camera as a new view, and read/update a
10
+ * view's display settings (background, color mode, axis, edges, labels).
10
11
  *
11
- * `list`/`get`/`getActive`/`capture` are reads; `setActive`/`create` are writes
12
- * (a view is a camera bookmark — not geometry). Members typed optional (`?`) are
13
- * authored ahead of the host: declared for plugins/codegen but not yet on the
14
- * live discovery surface until the host lands them.
12
+ * `list`/`get`/`getActive`/`capture`/`getSettings` are reads;
13
+ * `setActive`/`create`/`updateSettings` are writes (a view is a camera bookmark
14
+ * not geometry).
15
15
  *
16
16
  * Accessed via `snaptrude.presentation.views`.
17
17
  */
@@ -153,6 +153,85 @@ export abstract class PluginPresentationViewsApi {
153
153
  name?: string,
154
154
  options?: { kind?: "view" | "sitePlan" },
155
155
  ): PluginApiReturn<PluginPresentationViewsCreateResult>
156
+
157
+ /**
158
+ * Read a saved view's display settings (background, color mode, axis, edges,
159
+ * labels).
160
+ *
161
+ * @param viewId - The id of the view to read settings for.
162
+ * @returns The view's {@linkcode PluginPresentationViewSettings}, or `null` if
163
+ * no view has that id.
164
+ *
165
+ * @examplePrompt What color mode is the Ground Floor view using?
166
+ * @examplePrompt Get the display settings for this view
167
+ * @examplePrompt Does the site plan view show axes and labels?
168
+ * @examplePrompt Read the background color of the active view
169
+ *
170
+ * # Example
171
+ * ```ts
172
+ * const settings = await snaptrude.presentation.views.getSettings("view_123")
173
+ * if (settings) console.log(settings.colorMode, settings.backgroundColor)
174
+ * ```
175
+ */
176
+ public abstract getSettings(
177
+ viewId: string,
178
+ ): PluginApiReturn<PluginPresentationViewsGetSettingsResult>
179
+
180
+ /**
181
+ * Update a saved view's display settings (partial patch — only the fields you
182
+ * pass change).
183
+ *
184
+ * Persists and broadcasts the change; if the view is currently active, the
185
+ * scene updates live. **Not Ctrl+Z-undoable** — view-metadata edits publish
186
+ * directly and do not land on the local undo stack; this matches how the
187
+ * product's own view-settings UI behaves.
188
+ *
189
+ * Label patch semantics (mirroring the product, which stores no label
190
+ * selection while labels are off):
191
+ *
192
+ * - `{ showLabels: true }` alone turns labels on; if the view has no stored
193
+ * selection, the product defaults (`objectLabels`, `areas`) are applied —
194
+ * labels are never "on" with an empty selection (the product has no such
195
+ * state; labels render only while the selection is non-empty).
196
+ * - `{ labels: [...] }` alone sets the selection **and turns labels on**.
197
+ * - `{ showLabels: false }` turns labels off and **clears the stored
198
+ * selection** — a later read returns `labels: []`.
199
+ * - `{ showLabels: false, labels: [...] }` with a non-empty list is
200
+ * contradictory and **rejected** (nothing is silently discarded).
201
+ * - `{ showLabels: true, labels: [] }` is likewise contradictory and
202
+ * **rejected** — pass a non-empty list, or omit `labels` to get the
203
+ * defaults.
204
+ *
205
+ * `colorMode` accepts the `tag:<categoryId>` scheme strings returned by
206
+ * {@linkcode PluginPresentationViewsApi.getSettings}, so read-then-write
207
+ * round-trips a tag-based color scheme unchanged.
208
+ *
209
+ * @param viewId - The id of the view to update.
210
+ * @param settings - A partial {@linkcode PluginPresentationViewSettings}; any
211
+ * omitted field is left unchanged.
212
+ * @returns The updated view's `id`.
213
+ * @throws If writes are disabled, no view has the given id, or the patch is
214
+ * contradictory (`showLabels: false` with a non-empty `labels`, or
215
+ * `showLabels: true` with an explicitly empty `labels` list).
216
+ *
217
+ * @examplePrompt Switch this view to monochrome color mode
218
+ * @examplePrompt Turn off the axis in the Ground Floor view
219
+ * @examplePrompt Set the background of the active view to white
220
+ * @examplePrompt Show area labels on this view
221
+ * @examplePrompt Enable hidden-line mode for the section view
222
+ *
223
+ * # Example
224
+ * ```ts
225
+ * await snaptrude.presentation.views.updateSettings("view_123", {
226
+ * colorMode: "monochrome",
227
+ * showAxis: false,
228
+ * })
229
+ * ```
230
+ */
231
+ public abstract updateSettings(
232
+ viewId: string,
233
+ settings: Partial<PluginPresentationViewSettings>,
234
+ ): PluginApiReturn<PluginPresentationViewsUpdateSettingsResult>
156
235
  }
157
236
 
158
237
  /**
@@ -301,3 +380,140 @@ export const PluginPresentationViewsCreateResult = PluginPresentationView
301
380
  export type PluginPresentationViewsCreateResult = z.infer<
302
381
  typeof PluginPresentationViewsCreateResult
303
382
  >
383
+
384
+ /**
385
+ * How the scene is colored in a view.
386
+ *
387
+ * | Value | Meaning |
388
+ * |---|---|
389
+ * | `monochrome` | Flat single-tone shading |
390
+ * | `texture` | Material textures/colors |
391
+ * | `department` | Colored by department |
392
+ * | `tag:<categoryId>` | Colored by a project tag category (e.g. `tag:ZONE`) |
393
+ *
394
+ * The `tag:<categoryId>` form carries the product's tag-based color schemes
395
+ * losslessly — reading a view that uses one returns the `tag:` string as-is,
396
+ * and writing it back preserves the scheme (read-then-write is safe).
397
+ */
398
+ export const PluginPresentationViewColorMode = z.union([
399
+ z.enum(["monochrome", "texture", "department"]),
400
+ z.templateLiteral(["tag:", z.string()]),
401
+ ])
402
+ export type PluginPresentationViewColorMode = z.infer<
403
+ typeof PluginPresentationViewColorMode
404
+ >
405
+
406
+ /**
407
+ * A category of on-canvas labels a view can show.
408
+ *
409
+ * | Value | Meaning |
410
+ * |---|---|
411
+ * | `objectLabels` | Per-object name labels |
412
+ * | `areas` | Area/room labels |
413
+ * | `department` | Department labels |
414
+ */
415
+ export const PluginPresentationViewLabel = z.enum([
416
+ "objectLabels",
417
+ "areas",
418
+ "department",
419
+ ])
420
+ export type PluginPresentationViewLabel = z.infer<
421
+ typeof PluginPresentationViewLabel
422
+ >
423
+
424
+ /**
425
+ * A view's display settings.
426
+ *
427
+ * | Property | Type | Description |
428
+ * |---|---|---|
429
+ * | `backgroundColor` | `string` | Canvas background as a hex color (e.g. `#ffffff`) |
430
+ * | `colorMode` | {@linkcode PluginPresentationViewColorMode} | How the scene is colored (including `tag:<categoryId>` schemes) |
431
+ * | `showAxis` | `boolean` | Whether the X/Y/Z axes are shown |
432
+ * | `showEdges` | `boolean` | Whether edges are shown; `false` = hidden-line rendering |
433
+ * | `showLabels` | `boolean` | Master label switch — whether on-canvas labels are shown at all. `true` always pairs with a non-empty `labels` selection (labels render only while the selection is non-empty; there is no labels-on-with-empty-selection state) |
434
+ * | `labels` | {@linkcode PluginPresentationViewLabel}`[]` | Which label categories are selected. When `showLabels` is `false` the view stores no selection and this reads `[]` |
435
+ */
436
+ export const PluginPresentationViewSettings = z.object({
437
+ backgroundColor: z.string(),
438
+ colorMode: PluginPresentationViewColorMode,
439
+ showAxis: z.boolean(),
440
+ showEdges: z.boolean(),
441
+ showLabels: z.boolean(),
442
+ labels: z.array(PluginPresentationViewLabel),
443
+ })
444
+ export type PluginPresentationViewSettings = z.infer<
445
+ typeof PluginPresentationViewSettings
446
+ >
447
+
448
+ /**
449
+ * Arguments for {@linkcode PluginPresentationViewsApi.getSettings}.
450
+ *
451
+ * | Property | Type | Description |
452
+ * |---|---|---|
453
+ * | `id` | `string` | The id of the view to read settings for |
454
+ */
455
+ export const PluginPresentationViewsGetSettingsArgs = z.object({
456
+ id: z.string(),
457
+ })
458
+ export type PluginPresentationViewsGetSettingsArgs = z.infer<
459
+ typeof PluginPresentationViewsGetSettingsArgs
460
+ >
461
+
462
+ /**
463
+ * Result of {@linkcode PluginPresentationViewsApi.getSettings} — the settings,
464
+ * or `null` when no view has that id.
465
+ */
466
+ export const PluginPresentationViewsGetSettingsResult =
467
+ PluginPresentationViewSettings.nullable()
468
+ export type PluginPresentationViewsGetSettingsResult = z.infer<
469
+ typeof PluginPresentationViewsGetSettingsResult
470
+ >
471
+
472
+ /**
473
+ * Arguments for {@linkcode PluginPresentationViewsApi.updateSettings}. The
474
+ * `settings` patch is partial — any omitted field is left unchanged. A patch
475
+ * pairing `showLabels: false` with a non-empty `labels` list, or
476
+ * `showLabels: true` with an explicitly empty `labels` list, is rejected as
477
+ * contradictory (see the method JSDoc for the full label patch semantics).
478
+ *
479
+ * | Property | Type | Description |
480
+ * |---|---|---|
481
+ * | `id` | `string` | The id of the view to update |
482
+ * | `settings` | `Partial<`{@linkcode PluginPresentationViewSettings}`>` | The fields to change |
483
+ */
484
+ export const PluginPresentationViewsUpdateSettingsArgs = z
485
+ .object({
486
+ id: z.string(),
487
+ settings: PluginPresentationViewSettings.partial(),
488
+ })
489
+ .refine(
490
+ (v) =>
491
+ !(v.settings.showLabels === false && (v.settings.labels?.length ?? 0) > 0),
492
+ {
493
+ message:
494
+ "Contradictory patch: labels cannot be set while showLabels is false",
495
+ },
496
+ )
497
+ .refine(
498
+ (v) =>
499
+ !(
500
+ v.settings.showLabels === true &&
501
+ v.settings.labels !== undefined &&
502
+ v.settings.labels.length === 0
503
+ ),
504
+ {
505
+ message:
506
+ "Contradictory patch: showLabels cannot be true with an explicitly empty labels list — pass a non-empty list, or omit labels to apply the defaults",
507
+ },
508
+ )
509
+ export type PluginPresentationViewsUpdateSettingsArgs = z.infer<
510
+ typeof PluginPresentationViewsUpdateSettingsArgs
511
+ >
512
+
513
+ /** Result of {@linkcode PluginPresentationViewsApi.updateSettings} — the updated view's id. */
514
+ export const PluginPresentationViewsUpdateSettingsResult = z.object({
515
+ id: z.string(),
516
+ })
517
+ export type PluginPresentationViewsUpdateSettingsResult = z.infer<
518
+ typeof PluginPresentationViewsUpdateSettingsResult
519
+ >
@@ -1,6 +1,7 @@
1
1
  import * as z from "zod"
2
2
  import { PluginApiReturn } from "../../types"
3
3
  import { PluginAreaUnit } from "./metrics"
4
+ import { PluginAreaClass } from "../entity/space"
4
5
  import { ComponentHandle } from "../../handles"
5
6
 
6
7
  /**
@@ -12,15 +13,25 @@ import { ComponentHandle } from "../../handles"
12
13
  * department-allocation lens (targets vs allocated area per department); this
13
14
  * namespace is the whole-program area/FAR summary and its groupings.
14
15
  *
16
+ * **Net vs gross:** the `carpet` / `builtUp` / `excluded` figures are the three
17
+ * area *classes* — every space's whole footprint lands in exactly one, chosen
18
+ * by its `areaClass` (see {@linkcode PluginProgramAreaMember.areaClass}). In UI
19
+ * terms `carpet` is the **Net Internal Area** (Σ of `NET`-classed spaces), and
20
+ * `builtUp` is the **Gross External Area** (Σ of `GROSS`-classed spaces) — so
21
+ * "net" and "gross" are the plain-English synonyms for `carpet` and `builtUp`.
22
+ * These are not wall-thickness carpet-vs-super-built-up; there is no common-area
23
+ * math. Note the summary also folds in non-mass elements (floors count as NET,
24
+ * slabs as GROSS), so **summing `listMembers` spaces does not reconcile to the
25
+ * summary totals**.
26
+ *
15
27
  * `achievedFar` is **derived and read-only** — computed from built-up area and
16
28
  * site area. `targetFar` is the goal you set (via {@linkcode
17
29
  * PluginProgramAreasApi.update}); the two are the same ratio, one measured and
18
30
  * one intended. The surface speaks **FAR only** — there is no FSI alias.
19
31
  *
20
- * Reads return plain records and never throw. The write member typed as optional
21
- * (`?`) is **authored ahead of the host** declared so plugins and codegen can
22
- * see the shape, but kept out of the discovery manifest until the host lands it
23
- * (at which point it is promoted to a required `abstract` member).
32
+ * Reads return plain records and never throw. The only write
33
+ * {@linkcode PluginProgramAreasApi.update}is a non-undoable settings write
34
+ * for the FAR inputs.
24
35
  *
25
36
  * Accessed via `snaptrude.program.areas`.
26
37
  */
@@ -38,6 +49,8 @@ export abstract class PluginProgramAreasApi {
38
49
  *
39
50
  * @examplePrompt What's my FAR right now?
40
51
  * @examplePrompt Give me the program area summary
52
+ * @examplePrompt What is my net internal area vs gross external area?
53
+ * @examplePrompt How much net and gross area do I have?
41
54
  * @examplePrompt How much built-up area have I used against the site area?
42
55
  * @examplePrompt Am I within my FAR target?
43
56
  *
@@ -62,6 +75,7 @@ export abstract class PluginProgramAreasApi {
62
75
  * (empty when the program has no spaces).
63
76
  *
64
77
  * @examplePrompt Break down the area by storey
78
+ * @examplePrompt Break down net vs gross area by storey
65
79
  * @examplePrompt Show the area rollup per department
66
80
  * @examplePrompt Group the built-up area by building
67
81
  *
@@ -92,6 +106,7 @@ export abstract class PluginProgramAreasApi {
92
106
  * array (empty when the group is missing or empty).
93
107
  *
94
108
  * @examplePrompt List the spaces on this storey with their areas
109
+ * @examplePrompt Which spaces are net and which are gross on this storey?
95
110
  * @examplePrompt What rooms are in the Bedrooms department bucket?
96
111
  * @examplePrompt Break the storey area down into individual spaces
97
112
  *
@@ -142,9 +157,9 @@ export abstract class PluginProgramAreasApi {
142
157
  * |---|---|---|
143
158
  * | `count` | `number` | Number of spaces in the program (a count, not an area) |
144
159
  * | `hiddenCount` | `number` | Number of those spaces that are currently hidden |
145
- * | `carpet` | `number` | Total carpet area in `areaUnit` |
146
- * | `builtUp` | `number` | Total built-up area in `areaUnit` |
147
- * | `excluded` | `number` | Total excluded area in `areaUnit` |
160
+ * | `carpet` | `number` | Total **Net Internal Area** ("net") — Σ `NET`-classed spaces + floors — in `areaUnit` |
161
+ * | `builtUp` | `number` | Total **Gross External Area** ("gross") — Σ `GROSS`-classed spaces + slabs — in `areaUnit` |
162
+ * | `excluded` | `number` | Total **Excluded Area** — Σ `EXCLUDED`-classed spaces — in `areaUnit` |
148
163
  * | `farBuiltUp` | `number` | Built-up area that counts toward FAR, in `areaUnit` |
149
164
  * | `siteArea` | `number` | Site/plot area in `areaUnit` |
150
165
  * | `achievedFar` | `number \| null` | Derived FAR (`farBuiltUp / siteArea`); `null` when site area or target FAR is unset |
@@ -177,8 +192,8 @@ export type PluginProgramAreaSummary = z.infer<typeof PluginProgramAreaSummary>
177
192
  * | `groupId` | `string` | Stable id of the group (e.g. storey id, department id) |
178
193
  * | `name` | `string` | Display name of the group |
179
194
  * | `color` | `string` | CSS hex color string for the group |
180
- * | `carpet` | `number` | Carpet area for this group |
181
- * | `builtUp` | `number` | Built-up area for this group |
195
+ * | `carpet` | `number` | Net Internal Area ("net") for this group |
196
+ * | `builtUp` | `number` | Gross External Area ("gross") for this group |
182
197
  * | `excluded` | `number` | Excluded area for this group |
183
198
  * | `count` | `number` | Number of spaces in this group |
184
199
  * | `targetArea` | `number` | Target area for this group, in `targetUnit` |
@@ -201,18 +216,25 @@ export type PluginProgramAreaGroup = z.infer<typeof PluginProgramAreaGroup>
201
216
  * A single space within an area group. Area figures are in the program's area
202
217
  * unit (see {@linkcode PluginProgramAreaSummary.areaUnit}).
203
218
  *
219
+ * `areaClass` is the space's effective classification — it decides which of the
220
+ * three buckets the space's whole footprint lands in: `NET` → `carpet` ("net"),
221
+ * `GROSS` → `builtUp` ("gross"), `EXCLUDED` → `excluded`. So for any one member
222
+ * exactly one of `carpet` / `builtUp` / `excluded` is non-zero.
223
+ *
204
224
  * | Property | Type | Description |
205
225
  * |---|---|---|
206
226
  * | `id` | `ComponentHandle` | `Component.id` of the space (never a mesh handle) |
207
227
  * | `label` | `string` | Display label of the space |
208
- * | `carpet` | `number` | Carpet area of the space |
209
- * | `builtUp` | `number` | Built-up area of the space |
210
- * | `excluded` | `number` | Excluded area of the space |
228
+ * | `areaClass` | {@linkcode PluginAreaClass} | Effective area class `"NET"` (→ `carpet`), `"GROSS"` (→ `builtUp`), or `"EXCLUDED"` |
229
+ * | `carpet` | `number` | Net area of the space (non-zero when `areaClass` is `"NET"`) |
230
+ * | `builtUp` | `number` | Gross area of the space (non-zero when `areaClass` is `"GROSS"`) |
231
+ * | `excluded` | `number` | Excluded area of the space (non-zero when `areaClass` is `"EXCLUDED"`) |
211
232
  * | `isVisible` | `boolean` | Whether the space is currently visible |
212
233
  */
213
234
  export const PluginProgramAreaMember = z.object({
214
235
  id: ComponentHandle,
215
236
  label: z.string(),
237
+ areaClass: PluginAreaClass,
216
238
  carpet: z.number(),
217
239
  builtUp: z.number(),
218
240
  excluded: z.number(),
@@ -19,7 +19,7 @@ import { PluginProgramAreasApi } from "./areas"
19
19
  *
20
20
  * - {@linkcode PluginProgramApi.departments} — Read & edit program departments (groupings + targets)
21
21
  * - {@linkcode PluginProgramApi.adjacency} — Read & compute the department/space adjacency matrix
22
- * - {@linkcode PluginProgramApi.layout} — Arrange/pack spaces in the envelope (authored ahead)
22
+ * - {@linkcode PluginProgramApi.layout} — Arrange/pack spaces in the envelope
23
23
  * - {@linkcode PluginProgramApi.metrics} — Read the area-program summary
24
24
  * - {@linkcode PluginProgramApi.areas} — FAR / built-up-area rollup and groupings
25
25
  * - {@linkcode PluginProgramApi.spreadsheet} — Render program data to sheets and read it back
@@ -27,11 +27,6 @@ import { PluginProgramAreasApi } from "./areas"
27
27
  * - {@linkcode PluginProgramApi.cores} — Read & trigger vertical-circulation cores
28
28
  * - {@linkcode PluginProgramApi.classification} — Classification catalog + display tags
29
29
  *
30
- * Sub-namespaces typed as optional (`?`) are **authored ahead of the host** —
31
- * declared so plugins and codegen can see the shape, but not required of host
32
- * implementations and kept out of the discovery manifest until the host lands
33
- * them (at which point they are promoted to required `abstract` members).
34
- *
35
30
  * Accessed via `snaptrude.program`.
36
31
  */
37
32
  export abstract class PluginProgramApi {
@@ -39,11 +34,8 @@ export abstract class PluginProgramApi {
39
34
  public abstract departments: PluginProgramDepartmentsApi
40
35
  /** Adjacency matrix — read & compute proximity relationships. See {@linkcode PluginProgramAdjacencyApi}. */
41
36
  public abstract adjacency: PluginProgramAdjacencyApi
42
- /**
43
- * Arrange/pack spaces in the envelope. See {@linkcode PluginProgramLayoutApi}.
44
- * _(authored ahead — optional until the host lands it next increment.)_
45
- */
46
- public layout?: PluginProgramLayoutApi
37
+ /** Arrange/pack spaces in the envelope (async job family). See {@linkcode PluginProgramLayoutApi}. */
38
+ public abstract layout: PluginProgramLayoutApi
47
39
  /** Area-program summary — targets vs allocated area. See {@linkcode PluginProgramMetricsApi}. */
48
40
  public abstract metrics: PluginProgramMetricsApi
49
41
  /** FAR / built-up-area rollup and groupings. See {@linkcode PluginProgramAreasApi}. */
@@ -9,8 +9,20 @@ import { PluginApiReturn } from "../../types"
9
9
  * three of the space-planning workflow that starts with
10
10
  * {@linkcode PluginProgramAdjacencyApi} (`program.adjacency`).
11
11
  *
12
- * _(Authored ahead both methods are optional until the host lands them in
13
- * the next increment, and are kept out of the discovery manifest until then.)_
12
+ * Both {@linkcode PluginProgramLayoutApi.arrange} and
13
+ * {@linkcode PluginProgramLayoutApi.pack} run as an **asynchronous backend
14
+ * job** on the space-solver service:
15
+ *
16
+ * 1. `arrange` / `pack` start the job and **return immediately** — they do
17
+ * not wait for the layout.
18
+ * 2. Poll {@linkcode PluginProgramLayoutApi.getState} until `status` is no
19
+ * longer `"running"` — a run can take up to 20 minutes.
20
+ * 3. {@linkcode PluginProgramLayoutApi.cancel} aborts an in-flight run.
21
+ *
22
+ * `arrange` produces several candidate layouts and **auto-commits the first
23
+ * solution** as one undoable edit (there is no interactive solution-review
24
+ * over the plugin boundary); `pack` re-shapes and applies its single result
25
+ * directly. Both are **Pro-plan-gated**, matching the product UI.
14
26
  *
15
27
  * Accessed via `snaptrude.program.layout`.
16
28
  */
@@ -19,7 +31,29 @@ export abstract class PluginProgramLayoutApi {
19
31
 
20
32
  /**
21
33
  * Arrange the spaces inside the envelope using the computed adjacency data.
22
- * _(Authored ahead — optional until the host lands.)_
34
+ *
35
+ * Starts the backend job and **returns immediately** — poll
36
+ * {@linkcode PluginProgramLayoutApi.getState} until `status` leaves
37
+ * `"running"` (a run can take up to 20 minutes). The solver produces
38
+ * several candidate layouts; this **auto-commits the first solution** as one
39
+ * undoable edit (no interactive review over the plugin boundary). Starting a
40
+ * run while one is in flight replaces it.
41
+ *
42
+ * With no `options`, operates on the eligible Room/Department masses on the
43
+ * active storey and auto-detects the single buildable envelope there.
44
+ *
45
+ * @param options - Optional {@linkcode PluginProgramLayoutRunArgs} — the
46
+ * space / department masses to arrange and the envelope to fit them in.
47
+ * Omitted fields fall back to the active-storey defaults.
48
+ * @returns A {@linkcode PluginProgramLayoutRunResult} — `{ success: true }`
49
+ * when the job was started. Solver failures surface through
50
+ * {@linkcode PluginProgramLayoutApi.getState} (`status: "inactive"`), not
51
+ * as a rejected call.
52
+ * @throws When the project is not on a Pro plan.
53
+ * @throws When a `spaceId` / `departmentId` / `envelopeId` does not resolve.
54
+ * @throws When more than one envelope is on the active storey and none was
55
+ * given (ambiguous).
56
+ * @throws When plugin writes are disabled.
23
57
  *
24
58
  * @examplePrompt Arrange the rooms in the envelope
25
59
  * @examplePrompt Lay out the departments inside the building envelope
@@ -28,14 +62,43 @@ export abstract class PluginProgramLayoutApi {
28
62
  * # Example
29
63
  * ```ts
30
64
  * const { success, error } = await snaptrude.program.layout.arrange()
31
- * if (!success) console.log("Arrange failed:", error)
65
+ * if (!success) throw new Error(error)
66
+ * // poll until the layout is applied
67
+ * let job = await snaptrude.program.layout.getState()
68
+ * while (job?.status === "running") {
69
+ * await new Promise((r) => setTimeout(r, 5000))
70
+ * job = await snaptrude.program.layout.getState()
71
+ * }
32
72
  * ```
33
73
  */
34
- public arrange?: () => PluginApiReturn<PluginProgramLayoutRunResult>
74
+ public abstract arrange(
75
+ options?: PluginProgramLayoutRunArgs,
76
+ ): PluginApiReturn<PluginProgramLayoutRunResult>
35
77
 
36
78
  /**
37
79
  * Pack the spaces into the envelope (a tighter fit than arrange).
38
- * _(Authored ahead — optional until the host lands.)_
80
+ *
81
+ * Like {@linkcode PluginProgramLayoutApi.arrange}, this starts the backend
82
+ * job and **returns immediately** — poll
83
+ * {@linkcode PluginProgramLayoutApi.getState} until `status` leaves
84
+ * `"running"` (up to 20 minutes). Pack re-shapes mass geometry to fit and
85
+ * **applies its single result directly** (no solution review). Starting a
86
+ * run while one is in flight replaces it.
87
+ *
88
+ * With no `options`, operates on the eligible Room/Department masses on the
89
+ * active storey and auto-detects the single buildable envelope there.
90
+ *
91
+ * @param options - Optional {@linkcode PluginProgramLayoutRunArgs} — same
92
+ * shape as `arrange`; omitted fields fall back to the active-storey
93
+ * defaults.
94
+ * @returns A {@linkcode PluginProgramLayoutRunResult} — `{ success: true }`
95
+ * when the job was started. Solver failures surface through
96
+ * {@linkcode PluginProgramLayoutApi.getState} (`status: "inactive"`).
97
+ * @throws When the project is not on a Pro plan.
98
+ * @throws When a `spaceId` / `departmentId` / `envelopeId` does not resolve.
99
+ * @throws When more than one envelope is on the active storey and none was
100
+ * given (ambiguous).
101
+ * @throws When plugin writes are disabled.
39
102
  *
40
103
  * @examplePrompt Pack the rooms into the envelope
41
104
  * @examplePrompt Fit the program spaces tightly into the building
@@ -43,20 +106,99 @@ export abstract class PluginProgramLayoutApi {
43
106
  *
44
107
  * # Example
45
108
  * ```ts
46
- * const { success, error } = await snaptrude.program.layout.pack()
47
- * if (!success) console.log("Pack failed:", error)
109
+ * const { success } = await snaptrude.program.layout.pack({ envelopeId: "be_..." })
110
+ * let job = await snaptrude.program.layout.getState()
111
+ * while (job?.status === "running") {
112
+ * await new Promise((r) => setTimeout(r, 5000))
113
+ * job = await snaptrude.program.layout.getState()
114
+ * }
115
+ * ```
116
+ */
117
+ public abstract pack(
118
+ options?: PluginProgramLayoutRunArgs,
119
+ ): PluginApiReturn<PluginProgramLayoutRunResult>
120
+
121
+ /**
122
+ * Get the state of the layout run.
123
+ *
124
+ * The polling read for the async job started by
125
+ * {@linkcode PluginProgramLayoutApi.arrange} /
126
+ * {@linkcode PluginProgramLayoutApi.pack}. `status` values:
127
+ *
128
+ * | Status | Meaning |
129
+ * |---|---|
130
+ * | `"running"` | A run is in flight — keep polling |
131
+ * | `"active"` | The run finished and its layout is applied to the model |
132
+ * | `"inactive"` | A run finished without applying a layout (the solver failed or found no solution) |
133
+ *
134
+ * @returns A {@linkcode PluginProgramLayoutStateResult} with the run
135
+ * `status`, or `null` when no run result is available (never ran or was
136
+ * cancelled).
137
+ *
138
+ * @examplePrompt Is the arrange done?
139
+ * @examplePrompt Check the status of the layout run
140
+ * @examplePrompt Did the pack finish?
141
+ *
142
+ * # Example
143
+ * ```ts
144
+ * const job = await snaptrude.program.layout.getState()
145
+ * if (job?.status === "active") console.log("layout applied")
146
+ * ```
147
+ */
148
+ public abstract getState(): PluginApiReturn<PluginProgramLayoutStateResult>
149
+
150
+ /**
151
+ * Cancel the in-flight layout run.
152
+ *
153
+ * Aborts the backend job and discards any pending solution. A no-op
154
+ * (returns `false`) when nothing is running.
155
+ *
156
+ * @returns `true` when a run was cancelled, `false` when nothing was
157
+ * running.
158
+ * @throws When plugin writes are disabled.
159
+ *
160
+ * @examplePrompt Cancel the arrange
161
+ * @examplePrompt Stop the running layout job
162
+ * @examplePrompt Abort the pack in envelope
163
+ *
164
+ * # Example
165
+ * ```ts
166
+ * await snaptrude.program.layout.cancel()
48
167
  * ```
49
168
  */
50
- public pack?: () => PluginApiReturn<PluginProgramLayoutRunResult>
169
+ public abstract cancel(): PluginApiReturn<boolean>
51
170
  }
52
171
 
172
+ /**
173
+ * Arguments for {@linkcode PluginProgramLayoutApi.arrange} /
174
+ * {@linkcode PluginProgramLayoutApi.pack}. All fields are optional — omitted
175
+ * fields fall back to the eligible masses and the single envelope on the
176
+ * active storey.
177
+ *
178
+ * | Property | Type | Description |
179
+ * |---|---|---|
180
+ * | `spaceIds` | `string[] \| undefined` | Component ids of the Room masses to lay out |
181
+ * | `departmentIds` | `string[] \| undefined` | Component ids of the Department masses to lay out |
182
+ * | `envelopeId` | `string \| undefined` | The envelope to fit into — a mass component id or a buildable-envelope handle (`be_…`); omit to auto-detect the single envelope on the active storey |
183
+ */
184
+ export const PluginProgramLayoutRunArgs = z.object({
185
+ spaceIds: z.array(z.string()).optional(),
186
+ departmentIds: z.array(z.string()).optional(),
187
+ envelopeId: z.string().optional(),
188
+ })
189
+ export type PluginProgramLayoutRunArgs = z.infer<
190
+ typeof PluginProgramLayoutRunArgs
191
+ >
192
+
53
193
  /**
54
194
  * Result of {@linkcode PluginProgramLayoutApi.arrange} /
55
- * {@linkcode PluginProgramLayoutApi.pack}.
195
+ * {@linkcode PluginProgramLayoutApi.pack} — reports whether the run was
196
+ * **started**, not whether the layout finished (poll
197
+ * {@linkcode PluginProgramLayoutApi.getState} for completion).
56
198
  *
57
199
  * | Property | Type | Description |
58
200
  * |---|---|---|
59
- * | `success` | `boolean` | Whether the layout run completed |
201
+ * | `success` | `boolean` | Whether the layout run was started |
60
202
  * | `error` | `string \| undefined` | Failure reason when `success` is `false` |
61
203
  */
62
204
  export const PluginProgramLayoutRunResult = z.object({
@@ -66,3 +208,45 @@ export const PluginProgramLayoutRunResult = z.object({
66
208
  export type PluginProgramLayoutRunResult = z.infer<
67
209
  typeof PluginProgramLayoutRunResult
68
210
  >
211
+
212
+ /**
213
+ * The status of a layout run.
214
+ *
215
+ * | Value | Meaning |
216
+ * |---|---|
217
+ * | `"running"` | A run is in flight — keep polling |
218
+ * | `"active"` | The run finished and its layout is applied to the model |
219
+ * | `"inactive"` | A run finished without applying a layout (the solver failed or found no solution) |
220
+ */
221
+ export const PluginProgramLayoutJobStatus = z.enum([
222
+ "running",
223
+ "active",
224
+ "inactive",
225
+ ])
226
+ export type PluginProgramLayoutJobStatus = z.infer<
227
+ typeof PluginProgramLayoutJobStatus
228
+ >
229
+
230
+ /**
231
+ * The state of a layout run.
232
+ *
233
+ * | Property | Type | Description |
234
+ * |---|---|---|
235
+ * | `status` | {@linkcode PluginProgramLayoutJobStatus} | `"running"` \| `"active"` \| `"inactive"` |
236
+ */
237
+ export const PluginProgramLayoutJobState = z.object({
238
+ status: PluginProgramLayoutJobStatus,
239
+ })
240
+ export type PluginProgramLayoutJobState = z.infer<
241
+ typeof PluginProgramLayoutJobState
242
+ >
243
+
244
+ /**
245
+ * Result of {@linkcode PluginProgramLayoutApi.getState} — the run state, or
246
+ * `null` when no run result is available (never ran or was cancelled).
247
+ */
248
+ export const PluginProgramLayoutStateResult =
249
+ PluginProgramLayoutJobState.nullable()
250
+ export type PluginProgramLayoutStateResult = z.infer<
251
+ typeof PluginProgramLayoutStateResult
252
+ >