@snaptrude/plugin-core 0.11.0-rc.1 → 1.0.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 (226) hide show
  1. package/AGENTS.md +4 -0
  2. package/CHANGELOG.md +176 -14
  3. package/api-manifest.json +872 -49
  4. package/dist/api/analysis/daylight.d.ts +5 -5
  5. package/dist/api/analysis/solar.d.ts +2 -2
  6. package/dist/api/core/camera/index.d.ts +447 -0
  7. package/dist/api/core/camera/index.d.ts.map +1 -1
  8. package/dist/api/core/geom/create/index.d.ts +942 -101
  9. package/dist/api/core/geom/create/index.d.ts.map +1 -1
  10. package/dist/api/core/geom/query/brep.d.ts +59 -2
  11. package/dist/api/core/geom/query/brep.d.ts.map +1 -1
  12. package/dist/api/core/geom/query/curve.d.ts +59 -35
  13. package/dist/api/core/geom/query/curve.d.ts.map +1 -1
  14. package/dist/api/core/geom/query/edge.d.ts +2 -2
  15. package/dist/api/core/geom/query/face.d.ts +105 -0
  16. package/dist/api/core/geom/query/face.d.ts.map +1 -1
  17. package/dist/api/core/geom/update/contour.d.ts +10 -2
  18. package/dist/api/core/geom/update/contour.d.ts.map +1 -1
  19. package/dist/api/core/geom/update/curve.d.ts +5 -5
  20. package/dist/api/core/geom/update/profile.d.ts +3 -1
  21. package/dist/api/core/geom/update/profile.d.ts.map +1 -1
  22. package/dist/api/core/handles/index.d.ts +4 -2
  23. package/dist/api/core/handles/index.d.ts.map +1 -1
  24. package/dist/api/core/index.d.ts +4 -4
  25. package/dist/api/core/index.d.ts.map +1 -1
  26. package/dist/api/core/io/import/index.d.ts +3 -1
  27. package/dist/api/core/io/import/index.d.ts.map +1 -1
  28. package/dist/api/core/layers.d.ts +377 -255
  29. package/dist/api/core/layers.d.ts.map +1 -1
  30. package/dist/api/core/mode/index.d.ts +19 -7
  31. package/dist/api/core/mode/index.d.ts.map +1 -1
  32. package/dist/api/core/proposals/index.d.ts +4 -3
  33. package/dist/api/core/proposals/index.d.ts.map +1 -1
  34. package/dist/api/core/storeys/index.d.ts +17 -2
  35. package/dist/api/core/storeys/index.d.ts.map +1 -1
  36. package/dist/api/core/storeys/layers.d.ts +408 -0
  37. package/dist/api/core/storeys/layers.d.ts.map +1 -0
  38. package/dist/api/core/tags.d.ts +84 -3
  39. package/dist/api/core/tags.d.ts.map +1 -1
  40. package/dist/api/core/zoom/index.d.ts +13 -0
  41. package/dist/api/core/zoom/index.d.ts.map +1 -1
  42. package/dist/api/design/bim.d.ts +299 -0
  43. package/dist/api/design/bim.d.ts.map +1 -0
  44. package/dist/api/design/boolean/index.d.ts +2 -0
  45. package/dist/api/design/boolean/index.d.ts.map +1 -1
  46. package/dist/api/design/catalog.d.ts +320 -0
  47. package/dist/api/design/catalog.d.ts.map +1 -0
  48. package/dist/api/design/create/bulk-items.d.ts +269 -0
  49. package/dist/api/design/create/bulk-items.d.ts.map +1 -0
  50. package/dist/api/design/create/grids.d.ts +132 -0
  51. package/dist/api/design/create/grids.d.ts.map +1 -0
  52. package/dist/api/design/create/index.d.ts +753 -102
  53. package/dist/api/design/create/index.d.ts.map +1 -1
  54. package/dist/api/design/create/opening-fields.d.ts +38 -0
  55. package/dist/api/design/create/opening-fields.d.ts.map +1 -0
  56. package/dist/api/design/delete/index.d.ts +7 -20
  57. package/dist/api/design/delete/index.d.ts.map +1 -1
  58. package/dist/api/design/dimensions.d.ts +427 -0
  59. package/dist/api/design/dimensions.d.ts.map +1 -0
  60. package/dist/api/design/doors/index.d.ts +24 -23
  61. package/dist/api/design/doors/index.d.ts.map +1 -1
  62. package/dist/api/design/family.d.ts +1446 -0
  63. package/dist/api/design/family.d.ts.map +1 -0
  64. package/dist/api/design/grids.d.ts +237 -0
  65. package/dist/api/design/grids.d.ts.map +1 -0
  66. package/dist/api/design/index.d.ts +30 -0
  67. package/dist/api/design/index.d.ts.map +1 -1
  68. package/dist/api/design/networks.d.ts +1703 -0
  69. package/dist/api/design/networks.d.ts.map +1 -0
  70. package/dist/api/design/query/geometry/index.d.ts +33 -5
  71. package/dist/api/design/query/geometry/index.d.ts.map +1 -1
  72. package/dist/api/design/query/grids.d.ts +287 -0
  73. package/dist/api/design/query/grids.d.ts.map +1 -0
  74. package/dist/api/design/query/index.d.ts +143 -36
  75. package/dist/api/design/query/index.d.ts.map +1 -1
  76. package/dist/api/design/query/spaces.d.ts +5 -66
  77. package/dist/api/design/query/spaces.d.ts.map +1 -1
  78. package/dist/api/design/selection/index.d.ts +12 -12
  79. package/dist/api/design/types/index.d.ts +40 -24
  80. package/dist/api/design/types/index.d.ts.map +1 -1
  81. package/dist/api/design/update/index.d.ts +412 -8
  82. package/dist/api/design/update/index.d.ts.map +1 -1
  83. package/dist/api/design/windows/index.d.ts +8 -8
  84. package/dist/api/design/windows/index.d.ts.map +1 -1
  85. package/dist/api/entity/buildableEnvelope.d.ts +84 -2
  86. package/dist/api/entity/buildableEnvelope.d.ts.map +1 -1
  87. package/dist/api/entity/referenceLine.d.ts +13 -1
  88. package/dist/api/entity/referenceLine.d.ts.map +1 -1
  89. package/dist/api/entity/space.d.ts +12 -15
  90. package/dist/api/entity/space.d.ts.map +1 -1
  91. package/dist/api/entity/story.d.ts +4 -4
  92. package/dist/api/presentation/aiInspiration.d.ts +24 -24
  93. package/dist/api/presentation/annotate.d.ts +38 -22
  94. package/dist/api/presentation/annotate.d.ts.map +1 -1
  95. package/dist/api/presentation/camera.d.ts +265 -0
  96. package/dist/api/presentation/camera.d.ts.map +1 -0
  97. package/dist/api/presentation/drawingContract.d.ts +32 -0
  98. package/dist/api/presentation/drawingContract.d.ts.map +1 -0
  99. package/dist/api/presentation/drawings.d.ts +3523 -0
  100. package/dist/api/presentation/drawings.d.ts.map +1 -0
  101. package/dist/api/presentation/export.d.ts +23 -5
  102. package/dist/api/presentation/export.d.ts.map +1 -1
  103. package/dist/api/presentation/graphics.d.ts +419 -0
  104. package/dist/api/presentation/graphics.d.ts.map +1 -0
  105. package/dist/api/presentation/index.d.ts +66 -12
  106. package/dist/api/presentation/index.d.ts.map +1 -1
  107. package/dist/api/presentation/placedViews.d.ts +117 -51
  108. package/dist/api/presentation/placedViews.d.ts.map +1 -1
  109. package/dist/api/presentation/sections.d.ts +461 -0
  110. package/dist/api/presentation/sections.d.ts.map +1 -0
  111. package/dist/api/presentation/shapes.d.ts +2 -2
  112. package/dist/api/presentation/sheets.d.ts +175 -37
  113. package/dist/api/presentation/sheets.d.ts.map +1 -1
  114. package/dist/api/presentation/standards.d.ts +590 -0
  115. package/dist/api/presentation/standards.d.ts.map +1 -0
  116. package/dist/api/presentation/viewPresets.d.ts +222 -0
  117. package/dist/api/presentation/viewPresets.d.ts.map +1 -0
  118. package/dist/api/presentation/views.d.ts +144 -9
  119. package/dist/api/presentation/views.d.ts.map +1 -1
  120. package/dist/api/presentation/walkthroughs.d.ts +1350 -0
  121. package/dist/api/presentation/walkthroughs.d.ts.map +1 -0
  122. package/dist/api/program/departments.d.ts +58 -2
  123. package/dist/api/program/departments.d.ts.map +1 -1
  124. package/dist/api/program/index.d.ts +16 -6
  125. package/dist/api/program/index.d.ts.map +1 -1
  126. package/dist/api/program/labels.d.ts +355 -0
  127. package/dist/api/program/labels.d.ts.map +1 -0
  128. package/dist/api/program/metadata.d.ts +328 -0
  129. package/dist/api/program/metadata.d.ts.map +1 -0
  130. package/dist/api/program/site.d.ts +4 -4
  131. package/dist/api/program/spreadsheet.d.ts +267 -4
  132. package/dist/api/program/spreadsheet.d.ts.map +1 -1
  133. package/dist/api/workspace/index.d.ts +49 -2
  134. package/dist/api/workspace/index.d.ts.map +1 -1
  135. package/dist/errors/codes.d.ts +5 -8
  136. package/dist/errors/codes.d.ts.map +1 -1
  137. package/dist/handles.d.ts +32 -3
  138. package/dist/handles.d.ts.map +1 -1
  139. package/dist/index.cjs +6534 -2865
  140. package/dist/index.cjs.map +1 -1
  141. package/dist/index.d.ts +2 -0
  142. package/dist/index.d.ts.map +1 -1
  143. package/dist/index.js +6118 -2857
  144. package/dist/index.js.map +1 -1
  145. package/dist/massParameters.d.ts +287 -0
  146. package/dist/massParameters.d.ts.map +1 -0
  147. package/dist/massParameters.ops.d.ts +138 -0
  148. package/dist/massParameters.ops.d.ts.map +1 -0
  149. package/package.json +2 -1
  150. package/scripts/check-dist-fresh.mjs +22 -0
  151. package/scripts/generate-manifest.mjs +5 -0
  152. package/scripts/generate-manifest.test.mjs +14 -3
  153. package/src/api/core/camera/index.ts +429 -1
  154. package/src/api/core/geom/create/index.ts +1037 -102
  155. package/src/api/core/geom/query/brep.ts +60 -2
  156. package/src/api/core/geom/query/curve.ts +26 -2
  157. package/src/api/core/geom/query/edge.ts +2 -2
  158. package/src/api/core/geom/query/face.ts +109 -4
  159. package/src/api/core/geom/update/contour.ts +10 -2
  160. package/src/api/core/geom/update/profile.ts +2 -0
  161. package/src/api/core/handles/index.ts +3 -2
  162. package/src/api/core/index.ts +4 -4
  163. package/src/api/core/io/import/index.ts +11 -3
  164. package/src/api/core/layers.ts +380 -173
  165. package/src/api/core/mode/index.ts +19 -7
  166. package/src/api/core/proposals/index.ts +4 -3
  167. package/src/api/core/storeys/index.ts +19 -2
  168. package/src/api/core/storeys/layers.ts +339 -0
  169. package/src/api/core/tags.ts +76 -0
  170. package/src/api/core/zoom/index.ts +13 -0
  171. package/src/api/design/bim.ts +210 -0
  172. package/src/api/design/boolean/index.ts +2 -0
  173. package/src/api/design/catalog.ts +203 -0
  174. package/src/api/design/create/bulk-items.ts +294 -0
  175. package/src/api/design/create/grids.ts +137 -0
  176. package/src/api/design/create/index.ts +824 -141
  177. package/src/api/design/create/opening-fields.ts +40 -0
  178. package/src/api/design/delete/index.ts +6 -20
  179. package/src/api/design/dimensions.ts +453 -0
  180. package/src/api/design/doors/index.ts +64 -41
  181. package/src/api/design/family.ts +1342 -0
  182. package/src/api/design/grids.ts +237 -0
  183. package/src/api/design/index.ts +49 -4
  184. package/src/api/design/networks.ts +607 -0
  185. package/src/api/design/query/geometry/index.ts +35 -4
  186. package/src/api/design/query/grids.ts +197 -0
  187. package/src/api/design/query/index.ts +105 -5
  188. package/src/api/design/query/spaces.ts +0 -68
  189. package/src/api/design/types/index.ts +31 -24
  190. package/src/api/design/update/index.ts +398 -4
  191. package/src/api/design/windows/index.ts +40 -22
  192. package/src/api/entity/buildableEnvelope.ts +77 -2
  193. package/src/api/entity/referenceLine.ts +25 -12
  194. package/src/api/entity/space.ts +0 -2
  195. package/src/api/presentation/annotate.ts +90 -58
  196. package/src/api/presentation/camera.ts +289 -0
  197. package/src/api/presentation/drawingContract.ts +70 -0
  198. package/src/api/presentation/drawings.ts +1179 -0
  199. package/src/api/presentation/export.ts +32 -6
  200. package/src/api/presentation/graphics.ts +324 -0
  201. package/src/api/presentation/index.ts +73 -14
  202. package/src/api/presentation/placedViews.ts +120 -57
  203. package/src/api/presentation/sections.ts +420 -0
  204. package/src/api/presentation/sheets.ts +182 -37
  205. package/src/api/presentation/standards.ts +445 -0
  206. package/src/api/presentation/viewPresets.ts +241 -0
  207. package/src/api/presentation/views.ts +81 -10
  208. package/src/api/presentation/walkthroughs.ts +1201 -0
  209. package/src/api/program/departments.ts +54 -2
  210. package/src/api/program/index.ts +16 -6
  211. package/src/api/program/labels.ts +332 -0
  212. package/src/api/program/metadata.ts +364 -0
  213. package/src/api/program/spreadsheet.ts +282 -0
  214. package/src/api/workspace/index.ts +51 -2
  215. package/src/errors/codes.ts +9 -30
  216. package/src/handles.ts +42 -3
  217. package/src/index.ts +2 -0
  218. package/src/massParameters.ops.ts +246 -0
  219. package/src/massParameters.ts +427 -0
  220. package/test/drawingContract.test.mjs +288 -0
  221. package/test/errors.test.mjs +1 -4
  222. package/test/massParameters.test.mjs +952 -0
  223. package/test/paperPensContract.test.mjs +75 -0
  224. package/test/presentationViewSettings.test.mjs +85 -0
  225. package/api-manifest.full.json +0 -6928
  226. package/snaptrude-plugin-core-0.11.0.tgz +0 -0
@@ -10,13 +10,16 @@ import { PluginApiReturn } from "../../types"
10
10
  * Teams are **read-only** here (no create/invite/delete in v1, a deliberate
11
11
  * safety decision); there are no folders in v1. A `projectId` is the project's
12
12
  * floorkey. Plan limits are enforced by the backend — a limit rejection surfaces
13
- * as a normal host error. It also carries the workspace-level mode switch for
13
+ * as a normal host error. It also carries the workspace-level mode switches for
14
14
  * Present mode ({@linkcode PluginWorkspaceApi.openPresentMode} /
15
- * {@linkcode PluginWorkspaceApi.closePresentMode}).
15
+ * {@linkcode PluginWorkspaceApi.closePresentMode}) and Program mode
16
+ * ({@linkcode PluginWorkspaceApi.openProgramMode} /
17
+ * {@linkcode PluginWorkspaceApi.closeProgramMode}).
16
18
  *
17
19
  * - {@linkcode PluginWorkspaceApi.projects} — Create, copy, list, read & rename projects
18
20
  * - {@linkcode PluginWorkspaceApi.teams} — Read teams and their members
19
21
  * - {@linkcode PluginWorkspaceApi.openPresentMode} / {@linkcode PluginWorkspaceApi.closePresentMode} — Open/close the Present-mode documentation editor
22
+ * - {@linkcode PluginWorkspaceApi.openProgramMode} / {@linkcode PluginWorkspaceApi.closeProgramMode} — Open/close the Program tab (the spreadsheet the `program.spreadsheet.*` calls run in)
20
23
  */
21
24
  export abstract class PluginWorkspaceApi {
22
25
  /** Projects — create, copy, list, read & rename. See {@linkcode PluginWorkspaceProjectsApi}. */
@@ -68,6 +71,52 @@ export abstract class PluginWorkspaceApi {
68
71
  */
69
72
  public abstract closePresentMode(): PluginApiReturn<void>
70
73
 
74
+ /**
75
+ * Open Program mode — the Program tab the `program.spreadsheet.*` calls run in.
76
+ *
77
+ * Runs the top bar's own Program-button sequence (remember the preference,
78
+ * open or re-link the paired Program window) and resolves only once that tab
79
+ * has connected to the editor over its channel, so a `program.spreadsheet.*`
80
+ * call issued right after this resolves finds the tab open. The open happens
81
+ * outside a user gesture, so the browser may block the pop-up; the editor
82
+ * then shows its "Allow pop-up to continue" modal and this call keeps waiting
83
+ * (up to ~90s) for the user to confirm. Idempotent — resolves immediately
84
+ * when the Program tab is already connected, and is a no-op when the plugin is
85
+ * itself running in the Program tab. Write-gated.
86
+ *
87
+ * @throws `PRECONDITION_FAILED` if the user dismisses the pop-up modal or the
88
+ * Program tab does not connect within the timeout.
89
+ *
90
+ * @examplePrompt Open program mode
91
+ * @examplePrompt Open the Program tab so I can build a custom sheet
92
+ * @examplePrompt Switch to the program spreadsheet
93
+ *
94
+ * # Example
95
+ * ```ts
96
+ * await snaptrude.workspace.openProgramMode()
97
+ * const { sheets } = await snaptrude.program.spreadsheet.listSheets()
98
+ * ```
99
+ */
100
+ public abstract openProgramMode(): PluginApiReturn<void>
101
+
102
+ /**
103
+ * Close the Program tab.
104
+ *
105
+ * Idempotent — a no-op when no Program tab is connected. Write-gated, like
106
+ * {@linkcode PluginWorkspaceApi.openProgramMode}.
107
+ *
108
+ * @throws `PRECONDITION_FAILED` if the tab is still connected after ~15s.
109
+ *
110
+ * @examplePrompt Close program mode
111
+ * @examplePrompt Close the Program tab
112
+ *
113
+ * # Example
114
+ * ```ts
115
+ * await snaptrude.workspace.closeProgramMode()
116
+ * ```
117
+ */
118
+ public abstract closeProgramMode(): PluginApiReturn<void>
119
+
71
120
  constructor() {}
72
121
  }
73
122
 
@@ -5,13 +5,10 @@
5
5
  * APPEND-ONLY: codes are a published contract; never rename or remove one.
6
6
  * Handle-resolution failures deliberately collapse to ONE code
7
7
  * (`HANDLE_INVALID`) so error responses cannot be used as an existence /
8
- * ownership oracle (PLUGIN_HANDLE_MIGRATION_HLD §6) — with one deliberate
9
- * exception: `HANDLE_STALE` marks a handle the caller legitimately held that a
10
- * parametric resolution (merge / split / rebuild) has since retired — a
11
- * lifetime fact about the caller's own write-scoped handle, not an oracle
12
- * (forged / never-issued ids still collapse to `HANDLE_INVALID`).
13
- * `HANDLE_KIND_MISMATCH` stays distinct because the kind is information the
14
- * caller already holds.
8
+ * ownership oracle (PLUGIN_HANDLE_MIGRATION_HLD §6). `HANDLE_KIND_MISMATCH`
9
+ * stays distinct because the kind is information the caller already holds.
10
+ * `HANDLE_STALE` is the one deliberate exception: a handle the caller
11
+ * legitimately held whose entity was since retired (deleted or rebuilt).
15
12
  */
16
13
  export const PLUGIN_ERROR_CODES = [
17
14
  "VALIDATION",
@@ -37,12 +34,9 @@ export const PLUGIN_ERROR_CODES = [
37
34
  "NO_ACTIVE_STRUCTURE",
38
35
  "NO_ELIGIBLE_ELEMENTS",
39
36
  "PROPOSAL_SWITCH_BLOCKED",
40
- "HANDLE_STALE",
41
- "KIND_HIDDEN_IN_MODE",
42
- "MERGED_INTO_EXISTING",
43
- "BLOCKED_IN_BIM",
44
37
  "INTERNAL",
45
38
  "UNKNOWN",
39
+ "HANDLE_STALE",
46
40
  ] as const
47
41
 
48
42
  export type PluginErrorCode = (typeof PLUGIN_ERROR_CODES)[number]
@@ -94,6 +88,10 @@ export const CODE_META: Record<PluginErrorCode, CodeMeta> = {
94
88
  hintTemplate: "Re-query the entity; do not cache handles across undo/reload.",
95
89
  },
96
90
  HANDLE_KIND_MISMATCH: { category: "handle" },
91
+ HANDLE_STALE: {
92
+ category: "handle",
93
+ hintTemplate: "The entity was deleted or rebuilt; re-query it for a fresh handle.",
94
+ },
97
95
  RESOURCE_QUOTA_EXCEEDED: {
98
96
  category: "quota",
99
97
  hintTemplate: "Release unused handles (core.handles.release) or use scopes.",
@@ -132,25 +130,6 @@ export const CODE_META: Record<PluginErrorCode, CodeMeta> = {
132
130
  category: "execution",
133
131
  hintTemplate: "Wait for the in-canvas agent run to finish, then retry.",
134
132
  },
135
- HANDLE_STALE: {
136
- category: "handle",
137
- hintTemplate:
138
- "The entity was retired by a parametric resolution (merge/split/rebuild); re-query for its successor.",
139
- },
140
- KIND_HIDDEN_IN_MODE: {
141
- category: "execution",
142
- hintTemplate:
143
- "This entity kind has no representation in the current mode/LOD; switch mode or target a visible kind.",
144
- },
145
- MERGED_INTO_EXISTING: {
146
- category: "execution",
147
- hintTemplate:
148
- "The created geometry merged into an existing entity; use the surviving handles from details.",
149
- },
150
- BLOCKED_IN_BIM: {
151
- category: "execution",
152
- hintTemplate: "This operation is unavailable in BIM mode; switch to Design and retry.",
153
- },
154
133
  INTERNAL: {
155
134
  category: "internal",
156
135
  hintTemplate: "Host-side fault. Report with errorId.",
package/src/handles.ts CHANGED
@@ -115,6 +115,19 @@ export type UnderlayHandle = EntityId<"underlay">
115
115
  */
116
116
  export type TerrainHandle = EntityId<"terrain">
117
117
 
118
+ /**
119
+ * A **dimension line** — one measurement annotation left behind by the Measuring
120
+ * Tape tool (NOT a width/height/depth property; see `design.dimensions`).
121
+ * Entity-style: the token IS the raw engine dimension id (`dim_…`), resolved live
122
+ * host-side from the dimension-line registry (`getDimensionLineMap()`) — not via
123
+ * `ComponentUtility.FindComponentById`, which does not index dimension lines (a
124
+ * dimension line is not a Component). No arena, no quota, stable across
125
+ * undo/redo and across reloads (the record persists with the project). Returned
126
+ * by `design.dimensions.create` and consumed by every other
127
+ * `design.dimensions.*` method.
128
+ */
129
+ export type DimensionHandle = EntityId<"dimension">
130
+
118
131
  /**
119
132
  * A handle to an **asynchronous import job** (today: a DWG → Forge conversion, which
120
133
  * can take minutes). Returned immediately by `core.io.import.dwg`; poll it via
@@ -132,8 +145,17 @@ export type Vec3Handle = Handle<"vec3">
132
145
  export type QuatHandle = Handle<"quat">
133
146
  export type LineHandle = Handle<"line">
134
147
  export type ArcHandle = Handle<"arc">
135
- /** A curve is a line or an arc — its handle is one of those kinds. */
136
- export type CurveHandle = LineHandle | ArcHandle
148
+ /**
149
+ * A NURBS curve value handle (open B-spline curve). Minted by
150
+ * `core.geom.create.splineFromPoints` / `splineFromControlPoints`, and returned by
151
+ * `edge.getCurve`, `profile.listCurves` and `update.curve.reverse` for a spline run;
152
+ * accepted everywhere a {@linkcode CurveHandle} is (profileFromCurves, query.curve.*).
153
+ * Closed spline loops never exist as a single handle — a closed run is built
154
+ * directly as a profile via `core.geom.create.profileFromSplinePoints`.
155
+ */
156
+ export type SplineHandle = Handle<"spline">
157
+ /** A curve is a line, an arc, or a spline — its handle is one of those kinds. */
158
+ export type CurveHandle = LineHandle | ArcHandle | SplineHandle
137
159
  /**
138
160
  * A circle value handle. A circle is a CLOSED curve — it deliberately does NOT
139
161
  * join {@linkcode CurveHandle} (it has no stable start/end and would break the
@@ -233,12 +255,29 @@ export const ImportJobHandle = z
233
255
  .min(1)
234
256
  .transform((s) => s as ImportJobHandle)
235
257
 
258
+ /**
259
+ * {@linkcode DimensionHandle} is an entity-style handle — the raw `dim_…` engine
260
+ * id, validated only as a non-empty string (no `"<kind>_"` prefix enforcement),
261
+ * resolved live host-side against the dimension-line registry (existence
262
+ * enforced there, as `HANDLE_INVALID`).
263
+ */
264
+ export const DimensionHandle = z
265
+ .string()
266
+ .min(1)
267
+ .transform((s) => s as DimensionHandle)
268
+
236
269
  // Value-kind handle schemas (all-handle model, §11).
237
270
  export const Vec3Handle = handleSchema("vec3")
238
271
  export const QuatHandle = handleSchema("quat")
239
272
  export const LineHandle = handleSchema("line")
240
273
  export const ArcHandle = handleSchema("arc")
241
- export const CurveHandle = z.union([LineHandle, ArcHandle])
274
+ export const SplineHandle = handleSchema("spline")
275
+ // Explicitly typed (rather than inferred): the inferred union type prints its
276
+ // three fully-expanded member schemas into handles.d.ts, which is served to
277
+ // agents whole and has a size budget. ZodUnion (not ZodType) keeps `.options`.
278
+ export const CurveHandle: z.ZodUnion<
279
+ readonly [typeof LineHandle, typeof ArcHandle, typeof SplineHandle]
280
+ > = z.union([LineHandle, ArcHandle, SplineHandle])
242
281
  export const CircleHandle = handleSchema("circle")
243
282
 
244
283
  // BREP topology handle schemas (§2A.2.1). Prefix-shape validation only; existence,
package/src/index.ts CHANGED
@@ -2,4 +2,6 @@ export * from "./api"
2
2
  export * from "./types"
3
3
  export * from "./host-utils"
4
4
  export * from "./handles"
5
+ export * from "./massParameters"
6
+ export * from "./massParameters.ops"
5
7
  export * from "./errors"
@@ -0,0 +1,246 @@
1
+ import * as z from "zod"
2
+ import {
3
+ ContourRecord,
4
+ CurveRecord,
5
+ LoftOptions,
6
+ MAX_LOFT_SECTIONS,
7
+ MAX_PATH_CURVES,
8
+ MAX_SWEEP_PATH_POINTS,
9
+ SweepAlongCurveRecordOptions,
10
+ SweepOptions,
11
+ XYZ,
12
+ } from "./massParameters"
13
+ import type { CurveKind, SurfaceKind } from "./massParameters"
14
+
15
+ /**
16
+ * The **operation half** of a mass creation-parameter record: which edge or
17
+ * face of the recipe's solid a kernel step used, the step itself, and the
18
+ * values a `design.update.parameters` patch may carry.
19
+ *
20
+ * Split out of `massParameters.ts` so that each file stays under the size limit
21
+ * at which the agent runtime still serves a type module in ONE whole read (the
22
+ * record module alone had grown past it). Do not merge the two back. It is
23
+ * re-exported from there and from the package root, so every import path keeps
24
+ * working.
25
+ *
26
+ * Everything here is **pure JSON** by construction, exactly as in
27
+ * {@linkcode MassParametersRecord}: plain objects, numbers and arrays only, one
28
+ * `{x, y, z}` point shape, no class instances.
29
+ */
30
+
31
+ /** Maximum kernel operations chained onto one recipe. */
32
+ export const MAX_OPERATIONS = 8
33
+ /** Maximum edges one fillet/chamfer operation may select. */
34
+ export const MAX_OPERATION_EDGES = 64
35
+ /** Maximum faces one shell operation may open. */
36
+ export const MAX_OPERATION_FACES = 32
37
+ /** Maximum rows in a variable-fillet radius law. */
38
+ export const MAX_FILLET_LAW_SAMPLES = 32
39
+
40
+ // `XYZ` and the record schemas below are resolved through `z.lazy`: this module
41
+ // and `massParameters.ts` re-export each other, and this one is evaluated first,
42
+ // so their consts are not yet initialised while these schemas are built. The
43
+ // closures run at parse time, when both modules are live.
44
+ const At: z.ZodType<XYZ, XYZ> = z.lazy(() => XYZ)
45
+
46
+ /**
47
+ * Which EDGE of the input solid an operation used: its index in
48
+ * `core.geom.query.brep.listEdges` order at authoring time, the indices of the
49
+ * two faces it lies between, and its curve kind. This is topology, not
50
+ * coordinates — it survives a scalar edit of the base recipe (which moves every
51
+ * edge) and trips on a reorder or a topology change. Read-only: to blend a
52
+ * different edge, re-select it on the new shape and re-apply the operation.
53
+ */
54
+ export type EdgeSelector = {
55
+ index: number
56
+ faces: [number, number]
57
+ curve: CurveKind
58
+ /** Where the edge sits INSIDE its solid: its midpoint in the record's own
59
+ * frame, divided by the solid's bounding-box extent — a ratio per axis,
60
+ * never a length, so it survives a scalar edit that scales the whole shape.
61
+ * Written only when the discriminators above cannot tell two edges apart. A
62
+ * tiebreak, never a coordinate fingerprint: a replay checks it within 0.02 of
63
+ * the solid's own box and refuses on a miss — it never searches for a better
64
+ * candidate. */
65
+ at?: XYZ
66
+ }
67
+
68
+ /**
69
+ * Which FACE of the input solid an operation used: its index in
70
+ * `core.geom.query.brep.listFaces` order, its surface kind, and the number of
71
+ * edges in its outer loop. Read-only, like {@linkcode EdgeSelector}.
72
+ */
73
+ export type FaceSelector = {
74
+ index: number
75
+ kind: SurfaceKind
76
+ edgeCount: number
77
+ /** The face's centroid under the same normalisation and the same tiebreak
78
+ * rule as {@linkcode EdgeSelector}'s `at` — written only where the
79
+ * discriminators above cannot separate two faces, which on a freeform solid
80
+ * (every face answers `"spline"`) is the common case. */
81
+ at?: XYZ
82
+ }
83
+
84
+ /** The input solid's topology at authoring time — the counts a replay checks first. */
85
+ export type TopologyCounts = { faceCount: number; edgeCount: number }
86
+
87
+ /**
88
+ * One kernel operation applied to the base recipe's solid, in order. `input`
89
+ * pins the topology the operation was authored against, so a base edit that
90
+ * changes the topology is refused rather than mis-applied.
91
+ *
92
+ * Edit one by patching the whole list back:
93
+ * `design.update.parameters(mass, { operations })`.
94
+ */
95
+ export type OperationRecord =
96
+ | {
97
+ op: "fillet"
98
+ edges: EdgeSelector[]
99
+ radius: number
100
+ /** Radius at the far end of the blend contour, internal length units — a
101
+ * linear variable blend from `radius`. One edge, and never with `radii`. */
102
+ endRadius?: number
103
+ /** The blend's radius law instead: `position` is normalised arc length
104
+ * along the blend contour (a ratio 0..1, never converted), `radius` is
105
+ * internal length units. 2..32 rows, strictly increasing `position`.
106
+ * One edge, and never with `endRadius`. */
107
+ radii?: { position: number; radius: number }[]
108
+ input: TopologyCounts
109
+ }
110
+ | { op: "chamfer"; edges: EdgeSelector[]; distance: number; input: TopologyCounts }
111
+ | { op: "shell"; openFaces: FaceSelector[]; thickness: number; input: TopologyCounts }
112
+ | { op: "offset"; distance: number; input: TopologyCounts }
113
+
114
+ /**
115
+ * One value of a `MassParametersPatch` — whatever a record's `values` key (or
116
+ * `operations`) may hold. Each key you send replaces that value whole — a
117
+ * scalar, a point, a list or a record (`contour`, `profile`, `sections`,
118
+ * `path`, `options`, `operations`) alike — so send the complete value you read.
119
+ */
120
+ export type ParameterPatchValue =
121
+ | number
122
+ | XYZ
123
+ | XYZ[]
124
+ | ContourRecord
125
+ | ContourRecord[]
126
+ | CurveRecord[]
127
+ | LoftOptions
128
+ | SweepOptions
129
+ | SweepAlongCurveRecordOptions
130
+ | OperationRecord[]
131
+
132
+ const FaceIndex = z.number().int().nonnegative()
133
+
134
+ /** See {@linkcode EdgeSelector}. */
135
+ export const EdgeSelector: z.ZodType<EdgeSelector, EdgeSelector> = z.strictObject({
136
+ index: FaceIndex,
137
+ faces: z.tuple([FaceIndex, FaceIndex]),
138
+ curve: z.enum(["line", "arc", "circle", "spline"]),
139
+ at: At.optional(),
140
+ })
141
+
142
+ /** See {@linkcode FaceSelector}. */
143
+ export const FaceSelector: z.ZodType<FaceSelector, FaceSelector> = z.strictObject({
144
+ index: FaceIndex,
145
+ kind: z.enum(["plane", "cylinder", "cone", "sphere", "torus", "spline"]),
146
+ edgeCount: z.number().int().positive(),
147
+ at: At.optional(),
148
+ })
149
+
150
+ /** See {@linkcode TopologyCounts}. */
151
+ export const TopologyCounts: z.ZodType<TopologyCounts, TopologyCounts> = z.strictObject({
152
+ faceCount: z.number().int().positive(),
153
+ edgeCount: z.number().int().positive(),
154
+ })
155
+
156
+ /** One row of a variable fillet's radius law. See {@linkcode OperationRecord}. */
157
+ const FilletLawRow = z.strictObject({
158
+ position: z.number().finite().min(0).max(1),
159
+ radius: z.number().finite().positive(),
160
+ })
161
+
162
+ /**
163
+ * See {@linkcode OperationRecord}.
164
+ *
165
+ * A variable fillet — `endRadius` or `radii` — names ONE edge: the law is a
166
+ * property of the blend contour that edge belongs to, and `position` is measured
167
+ * from that edge's start, so a second edge would have no origin. The two forms
168
+ * are mutually exclusive and `radii` rows run strictly forward.
169
+ */
170
+ export const OperationRecord: z.ZodType<OperationRecord, OperationRecord> = z
171
+ .discriminatedUnion("op", [
172
+ z.strictObject({
173
+ op: z.literal("fillet"),
174
+ edges: z.array(EdgeSelector).min(1).max(MAX_OPERATION_EDGES),
175
+ radius: z.number().finite().positive(),
176
+ endRadius: z.number().finite().positive().optional(),
177
+ radii: z.array(FilletLawRow).min(2).max(MAX_FILLET_LAW_SAMPLES).optional(),
178
+ input: TopologyCounts,
179
+ }),
180
+ z.strictObject({
181
+ op: z.literal("chamfer"),
182
+ edges: z.array(EdgeSelector).min(1).max(MAX_OPERATION_EDGES),
183
+ distance: z.number().finite().positive(),
184
+ input: TopologyCounts,
185
+ }),
186
+ z.strictObject({
187
+ op: z.literal("shell"),
188
+ openFaces: z.array(FaceSelector).min(1).max(MAX_OPERATION_FACES),
189
+ thickness: z.number().finite().positive(),
190
+ input: TopologyCounts,
191
+ }),
192
+ z.strictObject({
193
+ op: z.literal("offset"),
194
+ distance: z
195
+ .number()
196
+ .finite()
197
+ .refine((value) => value !== 0, { message: "distance must be non-zero" }),
198
+ input: TopologyCounts,
199
+ }),
200
+ ])
201
+ .superRefine((operation, ctx) => {
202
+ if (operation.op !== "fillet") return
203
+ const { edges, endRadius, radii } = operation
204
+ if (endRadius === undefined && radii === undefined) return
205
+ if (endRadius !== undefined && radii !== undefined) {
206
+ ctx.addIssue({
207
+ code: "custom",
208
+ message: "endRadius is mutually exclusive with radii",
209
+ })
210
+ }
211
+ if (edges.length !== 1) {
212
+ ctx.addIssue({
213
+ code: "custom",
214
+ message: "a variable fillet names exactly one edge — the blend contour it runs along",
215
+ })
216
+ }
217
+ if (radii?.some((row, i) => i > 0 && row.position <= radii[i - 1].position)) {
218
+ ctx.addIssue({
219
+ code: "custom",
220
+ message: "radii positions must strictly increase",
221
+ })
222
+ }
223
+ })
224
+
225
+ /**
226
+ * One value of a parameter patch. See {@linkcode ParameterPatchValue}.
227
+ *
228
+ * Deliberately a CLOSED union of the shapes a record's `values` actually hold —
229
+ * no `z.unknown()`, nothing recursive: an unrecognised value is a VALIDATION at
230
+ * the wire, not a silent write of nonsense onto a mass. It only ever widens, so
231
+ * every value it accepted before it still accepts.
232
+ */
233
+ export const ParameterPatchValue: z.ZodType<ParameterPatchValue, ParameterPatchValue> = z.lazy(() =>
234
+ z.union([
235
+ z.number().finite(),
236
+ XYZ,
237
+ z.array(XYZ).max(MAX_SWEEP_PATH_POINTS),
238
+ ContourRecord,
239
+ z.array(ContourRecord).max(MAX_LOFT_SECTIONS),
240
+ z.array(CurveRecord).max(MAX_PATH_CURVES),
241
+ LoftOptions,
242
+ SweepOptions,
243
+ SweepAlongCurveRecordOptions,
244
+ z.array(OperationRecord).max(MAX_OPERATIONS),
245
+ ]),
246
+ )