@snaptrude/plugin-core 0.6.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.
- package/CHANGELOG.md +21 -0
- package/api-manifest.full.json +511 -10
- package/api-manifest.json +529 -4
- package/dist/api/core/index.d.ts +5 -0
- package/dist/api/core/index.d.ts.map +1 -1
- package/dist/api/core/proposals/index.d.ts +475 -0
- package/dist/api/core/proposals/index.d.ts.map +1 -0
- package/dist/api/design/create/index.d.ts +209 -0
- package/dist/api/design/create/index.d.ts.map +1 -1
- package/dist/api/design/doors/index.d.ts +159 -0
- package/dist/api/design/doors/index.d.ts.map +1 -1
- package/dist/api/design/furniture/index.d.ts +34 -5
- package/dist/api/design/furniture/index.d.ts.map +1 -1
- package/dist/api/design/index.d.ts +83 -0
- package/dist/api/design/index.d.ts.map +1 -1
- package/dist/api/design/lock.d.ts +26 -0
- package/dist/api/design/lock.d.ts.map +1 -1
- package/dist/api/design/materials/index.d.ts +159 -2
- package/dist/api/design/materials/index.d.ts.map +1 -1
- package/dist/api/design/query/index.d.ts +115 -5
- package/dist/api/design/query/index.d.ts.map +1 -1
- package/dist/api/design/selection/index.d.ts +2 -2
- package/dist/api/design/transform/index.d.ts +83 -2
- package/dist/api/design/transform/index.d.ts.map +1 -1
- package/dist/api/design/update/index.d.ts +168 -0
- package/dist/api/design/update/index.d.ts.map +1 -1
- package/dist/api/design/windows/index.d.ts +113 -2
- package/dist/api/design/windows/index.d.ts.map +1 -1
- package/dist/api/entity/story.d.ts +101 -7
- package/dist/api/entity/story.d.ts.map +1 -1
- package/dist/api/presentation/import.d.ts +49 -4
- package/dist/api/presentation/import.d.ts.map +1 -1
- package/dist/api/presentation/views.d.ts +210 -5
- package/dist/api/presentation/views.d.ts.map +1 -1
- package/dist/api/program/areas.d.ts +42 -12
- package/dist/api/program/areas.d.ts.map +1 -1
- package/dist/api/program/index.d.ts +3 -11
- package/dist/api/program/index.d.ts.map +1 -1
- package/dist/api/program/layout.d.ts +186 -11
- package/dist/api/program/layout.d.ts.map +1 -1
- package/dist/errors/codes.d.ts +34 -0
- package/dist/errors/codes.d.ts.map +1 -0
- package/dist/errors/envelope.d.ts +56 -0
- package/dist/errors/envelope.d.ts.map +1 -0
- package/dist/errors/index.d.ts +6 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/plugin-error.d.ts +69 -0
- package/dist/errors/plugin-error.d.ts.map +1 -0
- package/dist/host-utils.d.ts +4 -0
- package/dist/host-utils.d.ts.map +1 -1
- package/dist/index.cjs +1624 -1028
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1546 -1025
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/scripts/generate-manifest.test.mjs +77 -0
- package/src/api/core/index.ts +5 -0
- package/src/api/core/proposals/index.ts +509 -0
- package/src/api/design/create/index.ts +249 -0
- package/src/api/design/doors/index.ts +168 -0
- package/src/api/design/furniture/index.ts +36 -5
- package/src/api/design/index.ts +87 -0
- package/src/api/design/lock.ts +27 -0
- package/src/api/design/materials/index.ts +182 -2
- package/src/api/design/query/index.ts +81 -0
- package/src/api/design/transform/index.ts +74 -2
- package/src/api/design/update/index.ts +167 -0
- package/src/api/design/windows/index.ts +128 -2
- package/src/api/entity/story.ts +105 -7
- package/src/api/presentation/import.ts +45 -4
- package/src/api/presentation/views.ts +221 -5
- package/src/api/program/areas.ts +34 -12
- package/src/api/program/index.ts +3 -11
- package/src/api/program/layout.ts +195 -11
- package/src/errors/codes.ts +136 -0
- package/src/errors/envelope.ts +75 -0
- package/src/errors/index.ts +21 -0
- package/src/errors/plugin-error.ts +134 -0
- package/src/host-utils.ts +4 -0
- package/src/index.ts +1 -0
- package/test/errors.test.mjs +184 -0
package/src/api/program/areas.ts
CHANGED
|
@@ -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
|
|
21
|
-
*
|
|
22
|
-
*
|
|
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
|
|
146
|
-
* | `builtUp` | `number` | Total
|
|
147
|
-
* | `excluded` | `number` | Total
|
|
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` |
|
|
181
|
-
* | `builtUp` | `number` |
|
|
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
|
-
* | `
|
|
209
|
-
* | `
|
|
210
|
-
* | `
|
|
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(),
|
package/src/api/program/index.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
-
*
|
|
13
|
-
*
|
|
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
|
-
*
|
|
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)
|
|
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
|
|
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
|
-
*
|
|
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
|
|
47
|
-
*
|
|
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
|
|
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
|
|
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
|
+
>
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The closed error-code registry — the single source of truth for every error
|
|
3
|
+
* that crosses the plugin wire (host → worker) or is minted client-side.
|
|
4
|
+
*
|
|
5
|
+
* APPEND-ONLY: codes are a published contract; never rename or remove one.
|
|
6
|
+
* Handle-resolution failures deliberately collapse to ONE code
|
|
7
|
+
* (`HANDLE_INVALID`) so error responses cannot be used as an existence /
|
|
8
|
+
* ownership oracle (PLUGIN_HANDLE_MIGRATION_HLD §6). `HANDLE_KIND_MISMATCH`
|
|
9
|
+
* stays distinct because the kind is information the caller already holds.
|
|
10
|
+
*/
|
|
11
|
+
export const PLUGIN_ERROR_CODES = [
|
|
12
|
+
"VALIDATION",
|
|
13
|
+
"INVALID_RPC_FORMAT",
|
|
14
|
+
"METHOD_NOT_FOUND",
|
|
15
|
+
"METHOD_NOT_PERMITTED",
|
|
16
|
+
"HANDLE_INVALID",
|
|
17
|
+
"HANDLE_KIND_MISMATCH",
|
|
18
|
+
"RESOURCE_QUOTA_EXCEEDED",
|
|
19
|
+
"RATE_LIMITED",
|
|
20
|
+
"PRECONDITION_FAILED",
|
|
21
|
+
"OPERATION_FAILED",
|
|
22
|
+
"TIMEOUT",
|
|
23
|
+
"CALL_TIMEOUT",
|
|
24
|
+
"TRANSPORT_LOST",
|
|
25
|
+
"PLUGIN_NOT_READY",
|
|
26
|
+
"PLUGIN_TERMINATED",
|
|
27
|
+
"RESULT_NOT_SERIALIZABLE",
|
|
28
|
+
"RESULT_TOO_LARGE",
|
|
29
|
+
"BATCH_PARTIAL",
|
|
30
|
+
"STORY_UPDATE_FAILED",
|
|
31
|
+
"STORY_HEIGHT_REJECTED",
|
|
32
|
+
"NO_ACTIVE_STRUCTURE",
|
|
33
|
+
"NO_ELIGIBLE_ELEMENTS",
|
|
34
|
+
"PROPOSAL_SWITCH_BLOCKED",
|
|
35
|
+
"INTERNAL",
|
|
36
|
+
"UNKNOWN",
|
|
37
|
+
] as const
|
|
38
|
+
|
|
39
|
+
export type PluginErrorCode = (typeof PLUGIN_ERROR_CODES)[number]
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A known code, or a string outside the union — a plugin built against an
|
|
43
|
+
* older SDK may receive codes a newer host appended. Keeps autocomplete for
|
|
44
|
+
* known codes while staying open on the wire (forward compatibility).
|
|
45
|
+
*/
|
|
46
|
+
export type WirePluginErrorCode = PluginErrorCode | (string & {})
|
|
47
|
+
|
|
48
|
+
export type PluginErrorCategory =
|
|
49
|
+
| "validation"
|
|
50
|
+
| "not_found"
|
|
51
|
+
| "permission"
|
|
52
|
+
| "handle"
|
|
53
|
+
| "quota"
|
|
54
|
+
| "timeout"
|
|
55
|
+
| "transport"
|
|
56
|
+
| "lifecycle"
|
|
57
|
+
| "execution"
|
|
58
|
+
| "internal"
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Client-side metadata for a code. NOT carried on the wire — every field is a
|
|
62
|
+
* pure function of the code, and this table ships inside plugin-core, so both
|
|
63
|
+
* endpoints derive it locally.
|
|
64
|
+
*/
|
|
65
|
+
export interface CodeMeta {
|
|
66
|
+
/** Family of the code; picks the `PluginError` sugar subclass. */
|
|
67
|
+
category: PluginErrorCategory
|
|
68
|
+
/** Fallback `hint` when the throw site provides none. */
|
|
69
|
+
hintTemplate?: string
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const CODE_META: Record<PluginErrorCode, CodeMeta> = {
|
|
73
|
+
VALIDATION: {
|
|
74
|
+
category: "validation",
|
|
75
|
+
hintTemplate: "Check details.issues for the failing argument.",
|
|
76
|
+
},
|
|
77
|
+
INVALID_RPC_FORMAT: { category: "validation" },
|
|
78
|
+
METHOD_NOT_FOUND: {
|
|
79
|
+
category: "not_found",
|
|
80
|
+
hintTemplate: "Check details.didYouMean for a close match.",
|
|
81
|
+
},
|
|
82
|
+
METHOD_NOT_PERMITTED: { category: "permission" },
|
|
83
|
+
HANDLE_INVALID: {
|
|
84
|
+
category: "handle",
|
|
85
|
+
hintTemplate: "Re-query the entity; do not cache handles across undo/reload.",
|
|
86
|
+
},
|
|
87
|
+
HANDLE_KIND_MISMATCH: { category: "handle" },
|
|
88
|
+
RESOURCE_QUOTA_EXCEEDED: {
|
|
89
|
+
category: "quota",
|
|
90
|
+
hintTemplate: "Release unused handles (core.handles.release) or use scopes.",
|
|
91
|
+
},
|
|
92
|
+
RATE_LIMITED: {
|
|
93
|
+
category: "quota",
|
|
94
|
+
hintTemplate: "Wait details.retryAfterMs before retrying.",
|
|
95
|
+
},
|
|
96
|
+
PRECONDITION_FAILED: { category: "execution" },
|
|
97
|
+
OPERATION_FAILED: { category: "execution" },
|
|
98
|
+
TIMEOUT: { category: "timeout" },
|
|
99
|
+
CALL_TIMEOUT: { category: "timeout" },
|
|
100
|
+
TRANSPORT_LOST: { category: "transport" },
|
|
101
|
+
PLUGIN_NOT_READY: { category: "lifecycle" },
|
|
102
|
+
PLUGIN_TERMINATED: { category: "lifecycle" },
|
|
103
|
+
RESULT_NOT_SERIALIZABLE: { category: "execution" },
|
|
104
|
+
RESULT_TOO_LARGE: { category: "execution" },
|
|
105
|
+
BATCH_PARTIAL: { category: "execution" },
|
|
106
|
+
STORY_UPDATE_FAILED: {
|
|
107
|
+
category: "execution",
|
|
108
|
+
hintTemplate: "The storey update could not be applied; re-read the storey and retry.",
|
|
109
|
+
},
|
|
110
|
+
STORY_HEIGHT_REJECTED: {
|
|
111
|
+
category: "execution",
|
|
112
|
+
hintTemplate: "The requested height was out of range; pick a value within the storey's limits.",
|
|
113
|
+
},
|
|
114
|
+
NO_ACTIVE_STRUCTURE: {
|
|
115
|
+
category: "execution",
|
|
116
|
+
hintTemplate: "Activate a structure before running this operation.",
|
|
117
|
+
},
|
|
118
|
+
NO_ELIGIBLE_ELEMENTS: {
|
|
119
|
+
category: "execution",
|
|
120
|
+
hintTemplate: "The storey has no elements eligible for this operation.",
|
|
121
|
+
},
|
|
122
|
+
PROPOSAL_SWITCH_BLOCKED: {
|
|
123
|
+
category: "execution",
|
|
124
|
+
hintTemplate: "Wait for the in-canvas agent run to finish, then retry.",
|
|
125
|
+
},
|
|
126
|
+
INTERNAL: {
|
|
127
|
+
category: "internal",
|
|
128
|
+
hintTemplate: "Host-side fault. Report with errorId.",
|
|
129
|
+
},
|
|
130
|
+
UNKNOWN: { category: "internal" },
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Narrow an arbitrary string to a member of the closed code union. */
|
|
134
|
+
export function isPluginErrorCode(value: string): value is PluginErrorCode {
|
|
135
|
+
return (PLUGIN_ERROR_CODES as readonly string[]).includes(value)
|
|
136
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { WirePluginErrorCode } from "./codes"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Structured error payload carried on the `{success: false}` branch of the RPC
|
|
5
|
+
* wire result, next to the legacy `error: string` field (additive — old
|
|
6
|
+
* clients ignore it, old hosts never set it).
|
|
7
|
+
*
|
|
8
|
+
* Errors cross the worker boundary as THIS plain object, never as a thrown
|
|
9
|
+
* class: Comlink's throw transfer strips subclasses and custom fields and
|
|
10
|
+
* leaks host stacks. plugin-client reconstructs a typed `PluginError` from it
|
|
11
|
+
* (`fromEnvelope`).
|
|
12
|
+
*/
|
|
13
|
+
export const ERROR_ENVELOPE_VERSION = 1 as const
|
|
14
|
+
|
|
15
|
+
export interface ErrorEnvelope {
|
|
16
|
+
envelopeVersion: typeof ERROR_ENVELOPE_VERSION
|
|
17
|
+
code: WirePluginErrorCode
|
|
18
|
+
/**
|
|
19
|
+
* Human-readable failure description. For INTERNAL/UNKNOWN this is a GENERIC
|
|
20
|
+
* message — the real message and stack stay host-side, logged under
|
|
21
|
+
* `errorId` (the worker is untrusted; internals must not leak).
|
|
22
|
+
*/
|
|
23
|
+
message: string
|
|
24
|
+
/**
|
|
25
|
+
* Per-occurrence id. For INTERNAL the host logs the real message and stack
|
|
26
|
+
* under this id (the sanitized message would otherwise be an undebuggable
|
|
27
|
+
* dead end). Other codes carry the id only to identify the occurrence in
|
|
28
|
+
* bug reports — the host does not log them. Client-minted ids carry a `c-`
|
|
29
|
+
* prefix.
|
|
30
|
+
*/
|
|
31
|
+
errorId: string
|
|
32
|
+
/** Structured, JSON-safe, code-specific data (issues / retryAfterMs / didYouMean / handles…). */
|
|
33
|
+
details?: Record<string, unknown>
|
|
34
|
+
/**
|
|
35
|
+
* Wire id of the single primary offending handle, when the failure is
|
|
36
|
+
* handle-scoped. Multiple offenders go in `details.handles: string[]`.
|
|
37
|
+
* May echo ONLY ids the caller itself supplied (anti-oracle rule).
|
|
38
|
+
*/
|
|
39
|
+
handle?: string
|
|
40
|
+
/** Dotted method path of the failed call (e.g. "design.boolean.union"). */
|
|
41
|
+
methodPath?: string
|
|
42
|
+
/** Machine-actionable fix suggestion (written for LLM plugin authors). */
|
|
43
|
+
hint?: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Structural guard for a wire value claiming to be an `ErrorEnvelope`.
|
|
48
|
+
*
|
|
49
|
+
* Checks shape only — deliberately does NOT reject codes outside the known
|
|
50
|
+
* union, so envelopes from a newer host still pass (forward compatibility).
|
|
51
|
+
*/
|
|
52
|
+
export function isErrorEnvelope(value: unknown): value is ErrorEnvelope {
|
|
53
|
+
if (typeof value !== "object" || value === null) return false
|
|
54
|
+
const record = value as Record<string, unknown>
|
|
55
|
+
return (
|
|
56
|
+
record.envelopeVersion === ERROR_ENVELOPE_VERSION &&
|
|
57
|
+
typeof record.code === "string" &&
|
|
58
|
+
typeof record.message === "string" &&
|
|
59
|
+
typeof record.errorId === "string"
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let idCounter = 0
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Mint a per-occurrence error id. Uses `crypto.randomUUID` when available
|
|
67
|
+
* (browser main thread and workers both have it); falls back to a
|
|
68
|
+
* counter+random suffix — uniqueness within a session is all that is needed.
|
|
69
|
+
*/
|
|
70
|
+
export function newErrorId(prefix = ""): string {
|
|
71
|
+
const cryptoApi = (globalThis as { crypto?: { randomUUID?: () => string } }).crypto
|
|
72
|
+
if (cryptoApi?.randomUUID) return `${prefix}${cryptoApi.randomUUID()}`
|
|
73
|
+
idCounter += 1
|
|
74
|
+
return `${prefix}${Date.now().toString(36)}-${idCounter}-${Math.random().toString(36).slice(2, 10)}`
|
|
75
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { PLUGIN_ERROR_CODES, CODE_META, isPluginErrorCode } from "./codes"
|
|
2
|
+
export type { PluginErrorCode, WirePluginErrorCode, PluginErrorCategory, CodeMeta } from "./codes"
|
|
3
|
+
|
|
4
|
+
export { ERROR_ENVELOPE_VERSION, isErrorEnvelope, newErrorId } from "./envelope"
|
|
5
|
+
export type { ErrorEnvelope } from "./envelope"
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
PluginError,
|
|
9
|
+
PluginValidationError,
|
|
10
|
+
PluginNotFoundError,
|
|
11
|
+
PluginPermissionError,
|
|
12
|
+
PluginHandleError,
|
|
13
|
+
PluginQuotaError,
|
|
14
|
+
PluginTimeoutError,
|
|
15
|
+
PluginTransportError,
|
|
16
|
+
PluginLifecycleError,
|
|
17
|
+
PluginExecutionError,
|
|
18
|
+
PluginInternalError,
|
|
19
|
+
fromEnvelope,
|
|
20
|
+
makeClientEnvelope,
|
|
21
|
+
} from "./plugin-error"
|