@metamesh/generator-sdk 0.5.2 → 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 +14 -0
- package/README.md +156 -152
- package/dist/authoring.d.ts +57 -0
- package/dist/authoring.d.ts.map +1 -0
- package/dist/authoring.js +33 -0
- package/dist/authoring.js.map +1 -0
- package/dist/contracts.d.ts +34 -99
- package/dist/contracts.d.ts.map +1 -1
- package/dist/execute-generator.d.ts +22 -28
- package/dist/execute-generator.d.ts.map +1 -1
- package/dist/execute-generator.js +27 -32
- package/dist/execute-generator.js.map +1 -1
- package/dist/generated-parts.d.ts +1 -2
- package/dist/generated-parts.d.ts.map +1 -1
- package/dist/generated-parts.js +7 -31
- package/dist/generated-parts.js.map +1 -1
- package/dist/generator-module.d.ts +18 -40
- package/dist/generator-module.d.ts.map +1 -1
- package/dist/generator-module.js +4 -111
- package/dist/generator-module.js.map +1 -1
- package/dist/generator-package/constants.d.ts +2 -2
- package/dist/generator-package/constants.js +2 -2
- package/dist/generator-package/schemas/definition.schema.d.ts +3 -0
- package/dist/generator-package/schemas/definition.schema.d.ts.map +1 -1
- package/dist/generator-package/schemas/manifest.schema.d.ts +5 -8422
- package/dist/generator-package/schemas/manifest.schema.d.ts.map +1 -1
- package/dist/generator-package/schemas/parameter.schema.d.ts +7 -0
- package/dist/generator-package/schemas/parameter.schema.d.ts.map +1 -1
- package/dist/generator-package/schemas/parameter.schema.js +2 -0
- package/dist/generator-package/schemas/parameter.schema.js.map +1 -1
- package/dist/generator-package/schemas/preset.schema.d.ts +2 -13
- package/dist/generator-package/schemas/preset.schema.d.ts.map +1 -1
- package/dist/generator-package/schemas/preset.schema.js.map +1 -1
- package/dist/generator-package/validate-definition.d.ts.map +1 -1
- package/dist/generator-package/validate-definition.js +18 -0
- package/dist/generator-package/validate-definition.js.map +1 -1
- package/dist/generator-package/validate-manifest.d.ts.map +1 -1
- package/dist/generator-package/validate-manifest.js +2 -13
- package/dist/generator-package/validate-manifest.js.map +1 -1
- package/dist/generator-services.d.ts +1 -1
- package/dist/generator-services.d.ts.map +1 -1
- package/dist/index.d.ts +8 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -6
- package/dist/index.js.map +1 -1
- package/dist/parameter-contracts.d.ts +121 -0
- package/dist/parameter-contracts.d.ts.map +1 -0
- package/dist/parameter-contracts.js +2 -0
- package/dist/parameter-contracts.js.map +1 -0
- package/dist/parameters/issues.d.ts +14 -0
- package/dist/parameters/issues.d.ts.map +1 -0
- package/dist/parameters/issues.js +262 -0
- package/dist/parameters/issues.js.map +1 -0
- package/dist/parameters/preparation.d.ts +13 -0
- package/dist/parameters/preparation.d.ts.map +1 -0
- package/dist/parameters/preparation.js +35 -0
- package/dist/parameters/preparation.js.map +1 -0
- package/dist/parameters/recovery.d.ts +10 -0
- package/dist/parameters/recovery.d.ts.map +1 -0
- package/dist/parameters/recovery.js +124 -0
- package/dist/parameters/recovery.js.map +1 -0
- package/dist/parameters/strict.d.ts +30 -0
- package/dist/parameters/strict.d.ts.map +1 -0
- package/dist/parameters/strict.js +116 -0
- package/dist/parameters/strict.js.map +1 -0
- package/dist/parameters/values.d.ts +13 -0
- package/dist/parameters/values.d.ts.map +1 -0
- package/dist/parameters/values.js +73 -0
- package/dist/parameters/values.js.map +1 -0
- package/dist/parameters.d.ts +7 -69
- package/dist/parameters.d.ts.map +1 -1
- package/dist/parameters.js +5 -592
- package/dist/parameters.js.map +1 -1
- package/dist/parse-generator-module.d.ts +29 -0
- package/dist/parse-generator-module.d.ts.map +1 -0
- package/dist/parse-generator-module.js +137 -0
- package/dist/parse-generator-module.js.map +1 -0
- package/dist/runtime.d.ts +10 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +5 -0
- package/dist/runtime.js.map +1 -0
- package/dist/worker-contracts.d.ts +80 -0
- package/dist/worker-contracts.d.ts.map +1 -0
- package/dist/worker-contracts.js +12 -0
- package/dist/worker-contracts.js.map +1 -0
- package/package.json +14 -1
- package/dist/prepared-generator-module.d.ts +0 -24
- package/dist/prepared-generator-module.d.ts.map +0 -1
- package/dist/prepared-generator-module.js +0 -124
- package/dist/prepared-generator-module.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @metamesh/generator-sdk
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b1b97b9: Replace `ModelTimings.renderUploadMs` with optional `viewportPrepareMs` and `firstDrawMs` to
|
|
8
|
+
distinguish viewport preparation from the elapsed time to first draw submission. Consumers must
|
|
9
|
+
read the new fields; the combined metric is removed.
|
|
10
|
+
|
|
11
|
+
## 0.6.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- Replace format-1 validation/generation with exact format-2 prepare/build modules targeting runtime 2.0.0. Add opaque one-use preparation capture, lean authoring and host subpaths, integer numeric declarations, and canonical manufacturing output without normals.
|
|
16
|
+
|
|
3
17
|
## 0.5.2
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,51 +1,43 @@
|
|
|
1
1
|
# `@metamesh/generator-sdk`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Runtime-neutral contracts and helpers for Generators, hosts, and workers.
|
|
4
4
|
|
|
5
|
-
> **Preview:** `0.x` releases may
|
|
6
|
-
>
|
|
7
|
-
> after an explicit `1.0.0` review.
|
|
5
|
+
> **Preview:** `0.x` minor releases may break compatibility. Patches remain compatible within the
|
|
6
|
+
> same minor line. Stable support requires an explicit `1.0.0` review.
|
|
8
7
|
|
|
9
|
-
Install
|
|
8
|
+
Install a published release from npm:
|
|
10
9
|
|
|
11
10
|
```bash
|
|
12
11
|
pnpm add @metamesh/generator-sdk
|
|
13
12
|
```
|
|
14
13
|
|
|
15
|
-
The
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
The root provides lightweight authoring contracts and helpers with explicit TypeScript interfaces.
|
|
15
|
+
It has no Zod, modeling, renderer, browser, or Worker dependencies.
|
|
16
|
+
Use the supported subpaths for host responsibilities:
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
| Entry | Responsibility |
|
|
19
|
+
| ------------- | ------------------------------------------------------------------------------- |
|
|
20
|
+
| Root | Definitions, presets, preparation/module authoring, parameter and service types |
|
|
21
|
+
| `/parameters` | Defaults, normalization, strict codecs, schema issues |
|
|
22
|
+
| `/runtime` | Evaluated module parsing, execution, mesh DTO parsing, Worker envelopes |
|
|
23
|
+
| `/packages` | Package, catalog and installation trust parsing |
|
|
24
|
+
| `/fonts` | Standalone font selection contract |
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
change package generation contracts. Omitted overrides preserve generated colors.
|
|
27
|
-
|
|
28
|
-
Zod is the only runtime dependency. The [public entry point](https://github.com/JasonKoolman/metamesh/blob/main/packages/generator-sdk/src/index.ts) owns exact exports;
|
|
29
|
-
strict schemas own accepted boundary data. Hosts own package delivery and execution.
|
|
26
|
+
Definitions remain callback-free and serializable. Preparation/build state is local to execution;
|
|
27
|
+
Studio owns persistence and the Modeling engine owns modeling and manufacturing finalization.
|
|
30
28
|
|
|
31
29
|
## Parameter definitions
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
`
|
|
35
|
-
|
|
36
|
-
`
|
|
37
|
-
equality/inequality, numeric comparisons, and `choice-set` membership through `contains`.
|
|
31
|
+
Parameters use a `type` discriminant: `number`, `slider`, `boolean`, `select`, `choice-set`, `color`,
|
|
32
|
+
`text`, `font`, `svg`, `profile`, or homogeneous `array`. Sliders require `min`, `max`, and `step`;
|
|
33
|
+
numbers may omit them. Visibility uses serializable `ConditionExpression` values with `all`, `any`,
|
|
34
|
+
`not`, equality/inequality, numeric comparisons, and choice-set membership (`contains`).
|
|
38
35
|
|
|
39
36
|
Define controls once, then normalize saved values or strictly parse boundary values:
|
|
40
37
|
|
|
41
38
|
```ts
|
|
42
|
-
import {
|
|
43
|
-
|
|
44
|
-
defineGenerator,
|
|
45
|
-
EMPTY_SVG_PARAMETER_DEFAULT,
|
|
46
|
-
prepareParameters,
|
|
47
|
-
type GeneratorParams,
|
|
48
|
-
} from "@metamesh/generator-sdk";
|
|
39
|
+
import { defineGenerator, type GeneratorParams } from "@metamesh/generator-sdk";
|
|
40
|
+
import { createParamCodec, prepareParameters } from "@metamesh/generator-sdk/parameters";
|
|
49
41
|
|
|
50
42
|
const definition = defineGenerator({
|
|
51
43
|
id: "sleeve",
|
|
@@ -65,14 +57,16 @@ const workerValues: unknown = { outerDiameter: 24, boreDiameter: 10 };
|
|
|
65
57
|
const strictParameters = createParamCodec(definition).parse(workerValues);
|
|
66
58
|
```
|
|
67
59
|
|
|
68
|
-
Normalization drops unknown
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
60
|
+
Normalization drops unknown keys, restores missing or invalid values from declared defaults,
|
|
61
|
+
clamps numbers, and returns a fresh frozen map. Strict codecs reject missing, unknown, invalid, or
|
|
62
|
+
noncanonical values and return cloned frozen structured values. `prepareParameters()` normalizes
|
|
63
|
+
once and returns the map with schema issues. Execution aggregates Generator preparation issues
|
|
64
|
+
separately. Definitions accept only
|
|
65
|
+
canonical types. SVG values are strings limited to 256 KiB each and 512 KiB per normalized Project.
|
|
74
66
|
|
|
75
67
|
```ts
|
|
68
|
+
import { EMPTY_SVG_PARAMETER_DEFAULT } from "@metamesh/generator-sdk/parameters";
|
|
69
|
+
|
|
76
70
|
const profile = {
|
|
77
71
|
id: "profile",
|
|
78
72
|
label: "Profile",
|
|
@@ -81,11 +75,12 @@ const profile = {
|
|
|
81
75
|
} as const;
|
|
82
76
|
```
|
|
83
77
|
|
|
84
|
-
Choice
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
`
|
|
88
|
-
|
|
78
|
+
### Choice sets and arrays
|
|
79
|
+
|
|
80
|
+
Choice sets have uniquely valued options and a default selection array. `minSelections` and
|
|
81
|
+
`maxSelections` optionally bound its size. Normalization orders valid selections by option
|
|
82
|
+
declaration; duplicate or invalid selections recover to the canonical default. `{ param: "outputs", contains: "nut" }`
|
|
83
|
+
must reference a choice set and one of its declared options.
|
|
89
84
|
|
|
90
85
|
Array definitions declare `items.type` as `number` or `string`. They may constrain `minItems` and
|
|
91
86
|
`maxItems`; number items may also declare `min`, `max`, `step`, and `unit`. Array-valued controls are
|
|
@@ -106,58 +101,49 @@ const points = {
|
|
|
106
101
|
Groups are ordered sections with stable IDs, user-facing labels, optional descriptions, and an
|
|
107
102
|
optional `collapsed` default. Parameters without a group render in Studio's General section.
|
|
108
103
|
|
|
104
|
+
### Fonts and text
|
|
105
|
+
|
|
109
106
|
Font parameters use a `FontSelection` default with immutable `faceId`, SHA-256 `revision`, and
|
|
110
107
|
integer `weight`. Structural validation does not require the font to be available locally. Valid
|
|
111
|
-
unavailable references survive codecs, presets, and persistence. Studio prepares the
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
`withTextFonts(services.text, callback)` binds these services for `textContours()` and
|
|
116
|
-
`textMetrics()` in compiled code. The SDK and Geometry keep their small structural text contracts
|
|
117
|
-
compatible without importing each other's runtime. Font parameters and prepared text services require
|
|
118
|
-
runtime `1.2.0` or later. Package format remains 1.
|
|
119
|
-
|
|
120
|
-
`GeneratorDefinition` is callback-free, JSON-safe metadata used by forms, manifests, persistence,
|
|
121
|
-
and normalization. Its `min`, `max`, options, and other field constraints are portable
|
|
122
|
-
data. `defineGenerator()` preserves literal IDs and select options so `GeneratorParams`,
|
|
123
|
-
`GeneratorParamId`, `GeneratorIssue`, validators, defaults, and presets derive from the definition.
|
|
124
|
-
Keep derived-value, cross-parameter, warning, and geometry checks in a separate TypeScript
|
|
125
|
-
validator:
|
|
126
|
-
|
|
127
|
-
```ts
|
|
128
|
-
import { defineValidator } from "@metamesh/generator-sdk";
|
|
108
|
+
unavailable references survive codecs, presets, and persistence. Studio prepares declared fonts before the Generator's `prepare(parameters, services)` callback.
|
|
109
|
+
`services.text.layout(text, { font, fontSize })` returns exact vector paths and measurements in
|
|
110
|
+
millimetres. Keep that layout in the preparation value when checks and construction both need it.
|
|
111
|
+
Imported `textSection(layout)` consumes it during build. No ambient font provider is bound.
|
|
129
112
|
|
|
130
|
-
|
|
131
|
-
return parameters.outerDiameter - parameters.boreDiameter < 2
|
|
132
|
-
? [{ severity: "error", parameterId: "boreDiameter", message: "Leave at least a 1 mm wall." }]
|
|
133
|
-
: [];
|
|
134
|
-
});
|
|
135
|
-
```
|
|
113
|
+
### Validation and bounds
|
|
136
114
|
|
|
137
|
-
`
|
|
138
|
-
|
|
139
|
-
|
|
115
|
+
`GeneratorDefinition` is callback-free, JSON-safe metadata for forms, manifests, persistence, and
|
|
116
|
+
normalization. `defineGenerator()` preserves literal IDs/options; `GeneratorParams` and
|
|
117
|
+
`GeneratorIssue` derive exact parameter types and issue IDs from that definition. Use
|
|
140
118
|
`definePresets(definition, presets)` to require complete definition-derived preset values.
|
|
141
119
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
120
|
+
Per-field constraints belong in the definition. Cross-parameter, warning, manufacturing and geometry
|
|
121
|
+
constraints belong in `prepare`, alongside the dimensions and samples that `build` will consume.
|
|
122
|
+
A successful result is `{ ok: true, value, issues }`; an invalid result is `{ ok: false, issues }`.
|
|
123
|
+
Successful preparation may contain warnings but no errors. Invalid preparation requires an error,
|
|
124
|
+
and prevents build and native shape construction.
|
|
125
|
+
|
|
126
|
+
Numeric parameters and numeric array items may declare `integer: true`. Their defaults and supplied
|
|
127
|
+
bounds must be integers. Strict codecs reject fractions; saved fractions recover to the declared
|
|
128
|
+
default. Numeric array recovery replaces the invalid array with its default. `step` only describes
|
|
129
|
+
the control increment and does not imply integer values.
|
|
148
130
|
|
|
149
|
-
|
|
150
|
-
|
|
131
|
+
Schema editors receive only the definition and never rewrite validators. Manifests remain
|
|
132
|
+
callback-free. Preparation receives normalized, frozen parameters; malformed issue output is a
|
|
133
|
+
runtime error. Combined validation retains at most 100 issues, prioritizing errors over warnings
|
|
134
|
+
and preserving retained order. The reporting limit cannot hide a blocking error.
|
|
135
|
+
|
|
136
|
+
Use `getDefaultParameters(definition)` for a fresh frozen defaults map. IDs are bounded safe keys.
|
|
137
|
+
Package manifests, definitions, descriptors, conditions, and nested parameter objects reject unknown fields.
|
|
151
138
|
Definitions are bounded to 64 groups and 256 parameters, arrays to 1,024 items, options to 512,
|
|
152
139
|
presets to 256, and condition composition to 8 levels with 32 children per node.
|
|
153
140
|
|
|
154
141
|
### Editable side profiles
|
|
155
142
|
|
|
156
|
-
A `profile` declares an open side outline as a versioned `ProfileValue`.
|
|
157
|
-
|
|
158
|
-
`
|
|
159
|
-
|
|
160
|
-
shape; hosts must write resolved tangents into the controls when editing automatic points.
|
|
143
|
+
A `profile` declares an open side outline as a versioned `ProfileValue`. Start/end anchors carry
|
|
144
|
+
normalized `radius` and upward `height` coordinates, plus editing `mode` (`auto`, `smooth`, or
|
|
145
|
+
`corner`). Segments are `line` or `cubic`, with cubic `control1` and `control2` points. Coordinates
|
|
146
|
+
define the shape; hosts must resolve automatic tangents into those control points.
|
|
161
147
|
|
|
162
148
|
```ts
|
|
163
149
|
const sideProfile = {
|
|
@@ -197,8 +183,7 @@ bindings leaves the editor in normalized coordinates.
|
|
|
197
183
|
`cloneProfileValue()` returns a fresh deeply frozen value, and `profileValuesEqual()` compares both
|
|
198
184
|
shape and editing intent. Normalization, strict codecs, defaults, and presets clone every nested
|
|
199
185
|
profile object. Invalid saved profiles recover to the declared default; strict boundaries reject
|
|
200
|
-
them. Profiles cannot be condition operands.
|
|
201
|
-
package format remains `1`.
|
|
186
|
+
them. Profiles cannot be condition operands. All executable packages use format `2` and runtime major `2`.
|
|
202
187
|
|
|
203
188
|
### Curve resolution
|
|
204
189
|
|
|
@@ -221,88 +206,107 @@ const curveDeviation = {
|
|
|
221
206
|
} as const;
|
|
222
207
|
```
|
|
223
208
|
|
|
224
|
-
Multiple controls
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
affects, including shared curves across several parts. Studio does not infer part overrides from
|
|
231
|
-
mesh IDs. Resolution requests exceeding model complexity
|
|
232
|
-
limits must fail explicitly instead of silently coarsening geometry.
|
|
233
|
-
|
|
234
|
-
Packages declaring this role require runtime `1.3.0` or later and retain package format `1` and the
|
|
235
|
-
existing five module exports. Definitions without the role retain their existing behavior.
|
|
209
|
+
Multiple controls may have this role. Each requires `unit: "mm"`, a positive `default`, and an
|
|
210
|
+
explicit positive `min`; numeric bounds and step rules still apply. Lower values request closer
|
|
211
|
+
approximation through the Generator's `GeometryResolution` policy; exact counts remain available
|
|
212
|
+
for matched topology. Hosts show authored labels in definition order and edit the saved parameters
|
|
213
|
+
used by both preview and manufacturing. Generators determine affected curves and parts; Studio
|
|
214
|
+
does not infer overrides from mesh IDs. Requests beyond complexity limits must fail explicitly.
|
|
236
215
|
|
|
237
216
|
## Compiled module and output boundary
|
|
238
217
|
|
|
239
|
-
`defineGeneratorModule()`
|
|
240
|
-
|
|
218
|
+
`defineGeneratorModule()` creates the five-field format-2 surface. Preparation resolves the model
|
|
219
|
+
once; build receives that exact value. Imported modeling helpers bind to the host's synchronous build:
|
|
241
220
|
|
|
242
221
|
```ts
|
|
243
|
-
|
|
222
|
+
import { defineGeneratorModule, definePreparation, prepared } from "@metamesh/generator-sdk";
|
|
223
|
+
import { tube } from "@metamesh/modeling";
|
|
224
|
+
|
|
225
|
+
const prepareSleeve = definePreparation(definition, (parameters, { invalid }) => {
|
|
226
|
+
if (parameters.boreDiameter >= parameters.outerDiameter)
|
|
227
|
+
return invalid("boreDiameter", "The bore must be smaller than the outside diameter.");
|
|
228
|
+
return prepared({
|
|
229
|
+
outerRadius: parameters.outerDiameter / 2,
|
|
230
|
+
innerRadius: parameters.boreDiameter / 2,
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
const runtime = defineGeneratorModule({
|
|
244
234
|
definition,
|
|
245
|
-
|
|
246
|
-
|
|
235
|
+
prepare: prepareSleeve,
|
|
236
|
+
build: (dimensions) => tube({ ...dimensions, height: 20 }),
|
|
247
237
|
});
|
|
248
238
|
|
|
249
|
-
export const { formatVersion,
|
|
239
|
+
export const { formatVersion, generatorId, version, prepare, build } = runtime;
|
|
250
240
|
```
|
|
251
241
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
`
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
242
|
+
`definePreparation(definition, callback)` infers readonly parameter values, prepared data and
|
|
243
|
+
`PreparationServices<typeof definition>`. Its second callback argument retains `services.text`
|
|
244
|
+
and adds `invalid(parameterId, message)` and `invalid(issue)`, with allowed IDs checked directly at
|
|
245
|
+
each argument. Destructure `{ invalid }` or call `services.invalid(...)`. A warning alone cannot
|
|
246
|
+
produce failed preparation.
|
|
247
|
+
|
|
248
|
+
The helper returns a preparation wrapper that accepts parameters and optional host `GeneratorServices`.
|
|
249
|
+
Omitting services uses `UNPREPARED_GENERATOR_SERVICES` for parameter-only probes; requesting
|
|
250
|
+
text through that provider fails explicitly. Hosts pass their prepared services.
|
|
251
|
+
It adds the scoped helper for each callback invocation, preserving the exact callback result and
|
|
252
|
+
prepared value without traversal or freezing. The callback itself is not returned unchanged.
|
|
253
|
+
`prepared(value)` remains the successful-value helper. Standalone global `invalid` accepts literal
|
|
254
|
+
IDs or existing error issues; the host checks their IDs against the definition at the runtime
|
|
255
|
+
boundary.
|
|
256
|
+
|
|
257
|
+
The root helper has no decoder or Modeling runtime dependency. Modeling owns `ModelingContext`
|
|
258
|
+
and `BuildOutput`; SDK context/output generics preserve author typing without importing them.
|
|
259
|
+
Prepared values are opaque local data: the SDK does not traverse, clone, serialize or freeze them.
|
|
260
|
+
Preparation must not acquire live modeling resources. Prepared values are never persisted,
|
|
261
|
+
transferred to the UI, or reused between requests.
|
|
262
|
+
|
|
263
|
+
Hosts import `parseGeneratorModule`, `prepareGenerator` and `executeGenerator` from `/runtime`.
|
|
264
|
+
The parser requires exactly the five exports above and matching manifest identity. Evaluated
|
|
265
|
+
preparation captures an opaque value in a one-use build closure; there is no raw prepared-value
|
|
266
|
+
invocation lane. Callback results must be synchronous. The host checks the own-data preparation
|
|
267
|
+
wrapper and bounded structured issues while leaving the value opaque.
|
|
268
|
+
|
|
269
|
+
Studio's authored source surface accepts `build` and optional `prepare`. Its compiler supplies
|
|
270
|
+
identity and `prepareIdentity(definition)` when preparation is omitted, then passes the resulting
|
|
271
|
+
five-field module through this same parser and executor. Compiled packages always include `prepare`.
|
|
272
|
+
|
|
273
|
+
`prepareGenerator` normalizes once and either returns `invalid` or a prepared result containing
|
|
274
|
+
`build(context)`. Use that closure inside `engine.build()` so one engine owns modeling, mesh
|
|
275
|
+
validation, limits, measurements and cleanup. `executeGenerator` accepts a context directly and
|
|
276
|
+
returns abstract build output; it does not finalize geometry. Hosts preparing asynchronous services
|
|
277
|
+
first may supply their `/parameters` `PreparedParameters` result as `parameterState` to reuse it.
|
|
278
|
+
|
|
279
|
+
`parseGeneratedParts(parts, limits)` strictly checks the final transferable DTO. The host supplies
|
|
280
|
+
its complete limits; the SDK does not own a duplicate default resource policy. Canonical parts have
|
|
281
|
+
unique IDs, Float32 positions, Uint32 indices and optional six-digit colors. Normals belong to
|
|
282
|
+
viewport presentation. Geometric/manufacturing validation belongs to the shared engine.
|
|
283
|
+
|
|
284
|
+
Package format `1`, runtime major `1`, retired `validate/generate` module exports and extra exports
|
|
285
|
+
reject explicitly. No compatibility adapter or preparation cache remains.
|
|
294
286
|
|
|
295
287
|
## Worker boundary
|
|
296
288
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
289
|
+
Worker requests/responses are `/runtime` contracts containing structured data and transferable
|
|
290
|
+
arrays, never live modeling handles. Validation issues are normal outcomes; callback, Worker and
|
|
291
|
+
exporter exceptions use error envelopes. Finalized previews carry revision identity, bounds,
|
|
292
|
+
warnings and optional statistics. Manufacturing exports serialize the requested finalized revision,
|
|
293
|
+
including appearance overrides, without running preparation/build again.
|
|
294
|
+
|
|
295
|
+
Successful generation envelopes include `sentAt`, the sender's high-resolution epoch milliseconds
|
|
296
|
+
captured immediately before transfer. Hosts use `/runtime` `parseGenerationSentAt()` to reject
|
|
297
|
+
missing, inherited, accessor, or nonfinite timestamps before measuring transfer latency. Worker
|
|
298
|
+
clock construction and receiver timings belong to the host.
|
|
299
|
+
|
|
300
|
+
`ModelTimings.prepareMs` measures Generator preparation; `viewportPrepareMs` measures host viewport
|
|
301
|
+
preparation. `firstDrawMs` starts when viewport preparation ends and measures elapsed time through
|
|
302
|
+
every part's first draw submission, including render scheduling and buffer upload. Viewport fields
|
|
303
|
+
are optional until the host records completion. First draw does not measure GPU completion.
|
|
304
|
+
`totalMs` is request-to-completion elapsed time, including scheduling between stages, rather than
|
|
305
|
+
the sum of stage timings. Studio reports request-to-delivery time until viewport completion.
|
|
306
|
+
|
|
307
|
+
`MeshTopologyMode` is host policy rather than a Generator parameter. Both compiled and authored
|
|
308
|
+
models use the same engine finalization and limits. Studio's runtime contract owns request lifecycle,
|
|
309
|
+
revision retention and export recovery.
|
|
306
310
|
|
|
307
311
|
## Development
|
|
308
312
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { GeneratorDefinition, GeneratorIssue, GeneratorParams, GeneratorPreset, ParameterIssue } from "./contracts.js";
|
|
2
|
+
import type { Preparation } from "./generator-module.js";
|
|
3
|
+
import { type GeneratorServices } from "./generator-services.js";
|
|
4
|
+
/** Captures literal IDs and options; the host validates serializable metadata. */
|
|
5
|
+
export declare function defineGenerator<const D extends GeneratorDefinition>(definition: D): D;
|
|
6
|
+
/** Contextually types complete presets from the same definition as the controls. */
|
|
7
|
+
export declare function definePresets<const D extends GeneratorDefinition, const Presets extends readonly GeneratorPreset<NoInfer<D>>[]>(_definition: D, presets: Presets): Presets;
|
|
8
|
+
/** Successful worker-local preparation. The value is never cloned or inspected. */
|
|
9
|
+
export declare function prepared<P>(value: P): {
|
|
10
|
+
readonly ok: true;
|
|
11
|
+
readonly value: P;
|
|
12
|
+
readonly issues: readonly [];
|
|
13
|
+
};
|
|
14
|
+
/** Failed preparation attributed to a literal parameter ID or an existing error issue. */
|
|
15
|
+
export declare function invalid<const Id extends string>(parameterId: Id, message: string): {
|
|
16
|
+
readonly ok: false;
|
|
17
|
+
readonly issues: readonly [
|
|
18
|
+
{
|
|
19
|
+
readonly severity: "error";
|
|
20
|
+
readonly parameterId: Id;
|
|
21
|
+
readonly message: string;
|
|
22
|
+
}
|
|
23
|
+
];
|
|
24
|
+
};
|
|
25
|
+
export declare function invalid<const Issue extends ParameterIssue & {
|
|
26
|
+
readonly severity: "error";
|
|
27
|
+
}>(issue: Issue): {
|
|
28
|
+
readonly ok: false;
|
|
29
|
+
readonly issues: readonly [Issue];
|
|
30
|
+
};
|
|
31
|
+
/** Definition-bound error reporting plus the host's unchanged text service. */
|
|
32
|
+
export interface PreparationServices<D extends GeneratorDefinition> extends GeneratorServices {
|
|
33
|
+
/** Reports one error using a declared parameter ID or an existing definition-bound issue. */
|
|
34
|
+
readonly invalid: {
|
|
35
|
+
<const Id extends D["parameters"][number]["id"]>(parameterId: Id, message: string): {
|
|
36
|
+
readonly ok: false;
|
|
37
|
+
readonly issues: readonly [
|
|
38
|
+
{
|
|
39
|
+
readonly severity: "error";
|
|
40
|
+
readonly parameterId: Id;
|
|
41
|
+
readonly message: string;
|
|
42
|
+
}
|
|
43
|
+
];
|
|
44
|
+
};
|
|
45
|
+
<const Issue extends GeneratorIssue<D> & {
|
|
46
|
+
readonly severity: "error";
|
|
47
|
+
}>(issue: Issue): {
|
|
48
|
+
readonly ok: false;
|
|
49
|
+
readonly issues: readonly [Issue];
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** Wraps preparation with definition-bound services while preserving its exact result and value. */
|
|
54
|
+
export declare function definePreparation<const D extends GeneratorDefinition, Result extends Preparation<NoInfer<D>, unknown>>(_definition: D, callback: (parameters: GeneratorParams<NoInfer<D>>, services: PreparationServices<NoInfer<D>>) => Result): (parameters: GeneratorParams<D>, services?: GeneratorServices) => Result;
|
|
55
|
+
/** Parameter-only preparation is useful for models with no derived dimensions. */
|
|
56
|
+
export declare function prepareIdentity<const D extends GeneratorDefinition>(_definition: D): (parameters: GeneratorParams<D>) => ReturnType<typeof prepared<GeneratorParams<D>>>;
|
|
57
|
+
//# sourceMappingURL=authoring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authoring.d.ts","sourceRoot":"","sources":["../src/authoring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,eAAe,EACf,cAAc,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAiC,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEhG,kFAAkF;AAClF,wBA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AAC,SAAS,mBAAmB,EACjE,WAAW,EAAE,CAAC,GACb,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,OAAO,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAGrF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { UNPREPARED_GENERATOR_SERVICES } from "./generator-services.js";
|
|
2
|
+
/** Captures literal IDs and options; the host validates serializable metadata. */
|
|
3
|
+
export function defineGenerator(definition) {
|
|
4
|
+
return definition;
|
|
5
|
+
}
|
|
6
|
+
/** Contextually types complete presets from the same definition as the controls. */
|
|
7
|
+
export function definePresets(_definition, presets) {
|
|
8
|
+
return presets;
|
|
9
|
+
}
|
|
10
|
+
/** Successful worker-local preparation. The value is never cloned or inspected. */
|
|
11
|
+
export function prepared(value) {
|
|
12
|
+
return { ok: true, value, issues: [] };
|
|
13
|
+
}
|
|
14
|
+
export function invalid(issueOrId, message) {
|
|
15
|
+
if (typeof issueOrId === "string") {
|
|
16
|
+
if (typeof message !== "string")
|
|
17
|
+
throw new TypeError("Invalid preparation needs an error message.");
|
|
18
|
+
return { ok: false, issues: [{ severity: "error", parameterId: issueOrId, message }] };
|
|
19
|
+
}
|
|
20
|
+
if (issueOrId === null || typeof issueOrId !== "object" || issueOrId.severity !== "error")
|
|
21
|
+
throw new TypeError("Invalid preparation requires an error issue.");
|
|
22
|
+
return { ok: false, issues: [issueOrId] };
|
|
23
|
+
}
|
|
24
|
+
/** Wraps preparation with definition-bound services while preserving its exact result and value. */
|
|
25
|
+
export function definePreparation(_definition, callback) {
|
|
26
|
+
return (parameters, services = UNPREPARED_GENERATOR_SERVICES) => callback(parameters, { ...services, invalid });
|
|
27
|
+
}
|
|
28
|
+
/** Parameter-only preparation is useful for models with no derived dimensions. */
|
|
29
|
+
export function prepareIdentity(_definition) {
|
|
30
|
+
void _definition;
|
|
31
|
+
return prepared;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMapp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