selva-compute 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.
- package/LICENSE.md +21 -0
- package/README.md +110 -0
- package/dist/base-DbB0Ggdq.d.cts +118 -0
- package/dist/base-DbB0Ggdq.d.ts +118 -0
- package/dist/chunk-24EXIE4G.js +3 -0
- package/dist/chunk-24EXIE4G.js.map +1 -0
- package/dist/chunk-5DJRUPGI.cjs +2 -0
- package/dist/chunk-5DJRUPGI.cjs.map +1 -0
- package/dist/chunk-AEQTQHPY.js +2 -0
- package/dist/chunk-AEQTQHPY.js.map +1 -0
- package/dist/chunk-JJLRDYYP.js +2 -0
- package/dist/chunk-JJLRDYYP.js.map +1 -0
- package/dist/chunk-OXD76DAK.js +2 -0
- package/dist/chunk-OXD76DAK.js.map +1 -0
- package/dist/chunk-P57VU27W.cjs +3 -0
- package/dist/chunk-P57VU27W.cjs.map +1 -0
- package/dist/chunk-PNG3L5TM.cjs +2 -0
- package/dist/chunk-PNG3L5TM.cjs.map +1 -0
- package/dist/chunk-TVCJBLSW.cjs +2 -0
- package/dist/chunk-TVCJBLSW.cjs.map +1 -0
- package/dist/core.cjs +2 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +114 -0
- package/dist/core.d.ts +114 -0
- package/dist/core.js +2 -0
- package/dist/core.js.map +1 -0
- package/dist/files.cjs +2 -0
- package/dist/files.cjs.map +1 -0
- package/dist/files.d.cts +34 -0
- package/dist/files.d.ts +34 -0
- package/dist/files.js +2 -0
- package/dist/files.js.map +1 -0
- package/dist/grasshopper.cjs +2 -0
- package/dist/grasshopper.cjs.map +1 -0
- package/dist/grasshopper.d.cts +741 -0
- package/dist/grasshopper.d.ts +741 -0
- package/dist/grasshopper.js +2 -0
- package/dist/grasshopper.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/schemas-5LuPKgX2.d.cts +202 -0
- package/dist/schemas-5LuPKgX2.d.ts +202 -0
- package/dist/types-SwbLAMW8.d.cts +27 -0
- package/dist/types-SwbLAMW8.d.ts +27 -0
- package/dist/types-r00wVwfo.d.cts +77 -0
- package/dist/types-r00wVwfo.d.ts +77 -0
- package/dist/visualization.cjs +2 -0
- package/dist/visualization.cjs.map +1 -0
- package/dist/visualization.d.cts +202 -0
- package/dist/visualization.d.ts +202 -0
- package/dist/visualization.js +2 -0
- package/dist/visualization.js.map +1 -0
- package/package.json +117 -0
|
@@ -0,0 +1,741 @@
|
|
|
1
|
+
import { C as ComputeServerStats } from './base-DbB0Ggdq.cjs';
|
|
2
|
+
export { R as RhinoComputeError } from './base-DbB0Ggdq.cjs';
|
|
3
|
+
import { d as DataTreeDefault, O as OutputParamSchema, I as InputParamSchema, c as GrasshopperComputeConfig, a as DataTree, b as GrasshopperComputeResponse, C as ComputeConfig, e as DataTreePath } from './schemas-5LuPKgX2.cjs';
|
|
4
|
+
export { D as DataItem, G as GrasshopperRequestSchema, R as RhinoModelUnit } from './schemas-5LuPKgX2.cjs';
|
|
5
|
+
import * as THREE from 'three';
|
|
6
|
+
import { a as FileBaseInfo } from './types-SwbLAMW8.cjs';
|
|
7
|
+
import { M as MeshExtractionOptions } from './types-r00wVwfo.cjs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Input and output parameter types
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Output types supported from Grasshopper/Rhino Compute
|
|
15
|
+
*/
|
|
16
|
+
type OutputType = 'System.String' | 'System.Double' | 'System.Int32' | 'System.Boolean' | 'Rhino.Geometry.Point3d' | 'Rhino.Geometry.Line' | 'Rhino.Geometry.Circle' | 'Rhino.Geometry.Arc' | 'Rhino.Geometry.NurbsCurve' | 'Rhino.Geometry.Brep' | 'Rhino.Geometry.Mesh' | 'Rhino.Geometry.Vector3d' | 'Rhino.Geometry.Plane' | 'Rhino.Geometry.Box' | string;
|
|
17
|
+
/**
|
|
18
|
+
* Union type for all possible default value types
|
|
19
|
+
*/
|
|
20
|
+
type DefaultValue<T> = T | T[] | DataTreeDefault<T> | undefined | null;
|
|
21
|
+
/**
|
|
22
|
+
* Base properties common to all processed input types.
|
|
23
|
+
* Note: `groupName` and `id` require the custom Rhino Compute branch.
|
|
24
|
+
*/
|
|
25
|
+
interface BaseInputType {
|
|
26
|
+
description: string;
|
|
27
|
+
name: string;
|
|
28
|
+
nickname: string | null;
|
|
29
|
+
treeAccess: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Name of the group this parameter belongs to.
|
|
32
|
+
* @requires Custom branch of compute.rhino3d
|
|
33
|
+
*/
|
|
34
|
+
groupName?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Unique identifier for the parameter.
|
|
37
|
+
* @requires Custom branch of compute.rhino3d
|
|
38
|
+
*/
|
|
39
|
+
id?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Numeric input type (Number or Integer)
|
|
43
|
+
*/
|
|
44
|
+
interface NumericInputType extends BaseInputType {
|
|
45
|
+
paramType: 'Number' | 'Integer';
|
|
46
|
+
minimum?: number | null;
|
|
47
|
+
maximum?: number | null;
|
|
48
|
+
atLeast?: number | null;
|
|
49
|
+
atMost?: number | null;
|
|
50
|
+
stepSize?: number | null;
|
|
51
|
+
default: DefaultValue<number>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Text input type
|
|
55
|
+
*/
|
|
56
|
+
interface TextInputType extends BaseInputType {
|
|
57
|
+
paramType: 'Text';
|
|
58
|
+
default: DefaultValue<string>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Boolean input type
|
|
62
|
+
*/
|
|
63
|
+
interface BooleanInputType extends BaseInputType {
|
|
64
|
+
paramType: 'Boolean';
|
|
65
|
+
default: DefaultValue<boolean>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Geometry input type (generic geometry)
|
|
69
|
+
*/
|
|
70
|
+
interface GeometryInputType extends BaseInputType {
|
|
71
|
+
paramType: 'Geometry';
|
|
72
|
+
default: DefaultValue<object | string>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* ValueList input type (dropdown/select)
|
|
76
|
+
*/
|
|
77
|
+
interface ValueListInputType extends BaseInputType {
|
|
78
|
+
paramType: 'ValueList';
|
|
79
|
+
values: Record<string, string>;
|
|
80
|
+
default?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* File input type
|
|
84
|
+
*/
|
|
85
|
+
interface FileInputType extends BaseInputType {
|
|
86
|
+
paramType: 'File';
|
|
87
|
+
acceptedFormats?: string[];
|
|
88
|
+
default: DefaultValue<object | string>;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Discriminated union of all input parameter types
|
|
92
|
+
*/
|
|
93
|
+
type InputParam = NumericInputType | BooleanInputType | TextInputType | ValueListInputType | GeometryInputType | FileInputType;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Parsed data structures for processed Grasshopper input/output
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Parsed input/output structure with raw schemas
|
|
101
|
+
*/
|
|
102
|
+
interface GrasshopperParsedIORaw {
|
|
103
|
+
inputs: InputParamSchema[];
|
|
104
|
+
outputs: OutputParamSchema[];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Parsed input/output structure with processed types
|
|
108
|
+
*/
|
|
109
|
+
interface GrasshopperParsedIO {
|
|
110
|
+
inputs: InputParam[];
|
|
111
|
+
outputs: OutputParamSchema[];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* GrasshopperClient provides a simple API for interacting with a Rhino Compute server and grasshopper.
|
|
116
|
+
*
|
|
117
|
+
* @public This is the recommended high-level API for Rhino Compute operations.
|
|
118
|
+
*
|
|
119
|
+
* **Security Warning:**
|
|
120
|
+
* Using this client in a browser environment exposes your server URL and API key to users.
|
|
121
|
+
* For production, use this library server-side or proxy requests through your own backend.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const client = await GrasshopperClient.create({
|
|
126
|
+
* serverUrl: 'http://localhost:6500',
|
|
127
|
+
* apiKey: 'your-api-key'
|
|
128
|
+
* });
|
|
129
|
+
*
|
|
130
|
+
* try {
|
|
131
|
+
* const result = await client.solve(definitionUrl, { x: 1, y: 2 });
|
|
132
|
+
* } finally {
|
|
133
|
+
* await client.dispose(); // Clean up resources
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
declare class GrasshopperClient {
|
|
138
|
+
private readonly config;
|
|
139
|
+
readonly serverStats: ComputeServerStats;
|
|
140
|
+
private disposed;
|
|
141
|
+
private constructor();
|
|
142
|
+
/**
|
|
143
|
+
* Creates and initializes a GrasshopperClient with server validation.
|
|
144
|
+
*
|
|
145
|
+
* @throws {RhinoComputeError} with code NETWORK_ERROR if server is offline
|
|
146
|
+
* @throws {RhinoComputeError} with code INVALID_CONFIG if configuration is invalid
|
|
147
|
+
*/
|
|
148
|
+
static create(config: GrasshopperComputeConfig): Promise<GrasshopperClient>;
|
|
149
|
+
/**
|
|
150
|
+
* Gets the client's configuration.
|
|
151
|
+
* Useful for passing to lower-level functions.
|
|
152
|
+
*/
|
|
153
|
+
getConfig(): GrasshopperComputeConfig;
|
|
154
|
+
/**
|
|
155
|
+
* Get input/output parameters of a Grasshopper definition.
|
|
156
|
+
*/
|
|
157
|
+
getIO(definition: string | Uint8Array): Promise<GrasshopperParsedIO>;
|
|
158
|
+
getRawIO(definition: string | Uint8Array): Promise<GrasshopperParsedIORaw>;
|
|
159
|
+
/**
|
|
160
|
+
* Run a compute job with a Grasshopper definition.
|
|
161
|
+
*
|
|
162
|
+
* @throws {RhinoComputeError} with code INVALID_INPUT if definition is empty
|
|
163
|
+
* @throws {RhinoComputeError} with code NETWORK_ERROR if server is offline
|
|
164
|
+
* @throws {RhinoComputeError} with code COMPUTATION_ERROR if computation fails
|
|
165
|
+
*/
|
|
166
|
+
solve(definition: string | Uint8Array, dataTree: DataTree[]): Promise<GrasshopperComputeResponse>;
|
|
167
|
+
/**
|
|
168
|
+
* Disposes of client resources.
|
|
169
|
+
* Call this when you're done using the client.
|
|
170
|
+
*/
|
|
171
|
+
dispose(): Promise<void>;
|
|
172
|
+
/**
|
|
173
|
+
* Ensures the client hasn't been disposed.
|
|
174
|
+
*/
|
|
175
|
+
private ensureNotDisposed;
|
|
176
|
+
/**
|
|
177
|
+
* Validates and normalizes a compute configuration.
|
|
178
|
+
*
|
|
179
|
+
* @throws {RhinoComputeError} with code INVALID_CONFIG if configuration is invalid
|
|
180
|
+
*/
|
|
181
|
+
private normalizeComputeConfig;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
interface ParsedContext {
|
|
185
|
+
[key: string]: any;
|
|
186
|
+
}
|
|
187
|
+
interface GetValuesOptions {
|
|
188
|
+
parseValues?: boolean;
|
|
189
|
+
rhino?: any;
|
|
190
|
+
/**
|
|
191
|
+
* If true, only include values of type System.String in the result.
|
|
192
|
+
* Non-string types are filtered out.
|
|
193
|
+
*/
|
|
194
|
+
stringOnly?: boolean;
|
|
195
|
+
}
|
|
196
|
+
interface GetValuesResult<T = ParsedContext> {
|
|
197
|
+
values: T;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* High-level wrapper for interacting with Grasshopper Compute responses.
|
|
202
|
+
*
|
|
203
|
+
* This class exposes a clean, consistent API for accessing parsed values,
|
|
204
|
+
* geometry, and produced files. It is designed to be the primary interface
|
|
205
|
+
* when working with Grasshopper results in client applications.
|
|
206
|
+
*/
|
|
207
|
+
declare class GrasshopperResponseProcessor {
|
|
208
|
+
private readonly response;
|
|
209
|
+
private readonly debug;
|
|
210
|
+
/**
|
|
211
|
+
* Store the compute response for reuse.
|
|
212
|
+
*/
|
|
213
|
+
constructor(response: GrasshopperComputeResponse, debug?: boolean);
|
|
214
|
+
/**
|
|
215
|
+
* Extract all values in the response.
|
|
216
|
+
*
|
|
217
|
+
* @typeParam T - Expected structure of the return value. Defaults to a simple key/value map. (later cast as needed)
|
|
218
|
+
* @param byId - If true, keys are parameter IDs; if false, keys are parameter names.
|
|
219
|
+
* @param options - Controls parsing behavior such as Rhino geometry decoding.
|
|
220
|
+
* @returns Parsed Grasshopper output values.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* const processor = new GrasshopperResponseProcessor(response);
|
|
225
|
+
* const { values } = processor.getValues();
|
|
226
|
+
* ```
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```ts
|
|
230
|
+
* const { values } = processor.getValues(true); // keyed by param ID
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
getValues<T = ParsedContext>(byId?: boolean, options?: GetValuesOptions): GetValuesResult<T>;
|
|
234
|
+
/**
|
|
235
|
+
* Retrieve a specific value using the parameter name.
|
|
236
|
+
*
|
|
237
|
+
* @param paramName - Human-readable parameter name from the Grasshopper definition.
|
|
238
|
+
* @param options - Parsing configuration (e.g. disable parsing or enable Rhino).
|
|
239
|
+
* @returns Single parsed value, array of values, or undefined if the parameter is absent.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```ts
|
|
243
|
+
* const schema = processor.getValueByParamName('Schema');
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
getValueByParamName(paramName: string, options?: GetValuesOptions): any;
|
|
247
|
+
/**
|
|
248
|
+
* Retrieve a specific value using the parameter ID.
|
|
249
|
+
*
|
|
250
|
+
* @param paramId - Parameter GUID from the Grasshopper definition.
|
|
251
|
+
* @param options - Parsing configuration (e.g. disable parsing or enable Rhino).
|
|
252
|
+
* @returns Parsed value, array of values, or undefined if not present.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```ts
|
|
256
|
+
* const output = processor.getValueByParamId('a4be1c1e-23f9-4c27-b942-7f3bb2c45c6f');
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
getValueByParamId(paramId: string, options?: GetValuesOptions): any;
|
|
260
|
+
/**
|
|
261
|
+
* Convert all geometry results into Three.js mesh objects.
|
|
262
|
+
*
|
|
263
|
+
* This uses internal helpers to decode Rhino geometry into Three.js
|
|
264
|
+
* primitives such as meshes and lines, making them ready for rendering.
|
|
265
|
+
*
|
|
266
|
+
* All processing options (scaling, positioning, compression, etc.) can be customized.
|
|
267
|
+
* The processor's debug flag is merged with options - explicit options take precedence.
|
|
268
|
+
*
|
|
269
|
+
* **Note:** This method dynamically imports three.js visualization modules. Ensure
|
|
270
|
+
* three.js is installed as a peer dependency if you use this feature.
|
|
271
|
+
*
|
|
272
|
+
* @param options - Configuration for mesh extraction and parsing. Overrides processor's debug flag if provided.
|
|
273
|
+
* @returns Promise resolving to an array of Three.js mesh objects.
|
|
274
|
+
* @throws {RhinoComputeError} If three.js visualization module cannot be loaded.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* const meshes = await processor.extractMeshesFromResponse();
|
|
279
|
+
* scene.add(...meshes);
|
|
280
|
+
* ```
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```ts
|
|
284
|
+
* const meshes = await processor.extractMeshesFromResponse({
|
|
285
|
+
* debug: true,
|
|
286
|
+
* allowScaling: true,
|
|
287
|
+
* allowAutoPosition: false,
|
|
288
|
+
* parsing: {
|
|
289
|
+
* mergeByMaterial: false,
|
|
290
|
+
* applyTransforms: true,
|
|
291
|
+
* debug: true,
|
|
292
|
+
* },
|
|
293
|
+
* });
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
extractMeshesFromResponse(options?: MeshExtractionOptions): Promise<THREE.Mesh<THREE.BufferGeometry<THREE.NormalBufferAttributes, THREE.BufferGeometryEventMap>, THREE.Material | THREE.Material[], THREE.Object3DEventMap>[]>;
|
|
297
|
+
/**
|
|
298
|
+
* Extract internal file data structures from the response.
|
|
299
|
+
* This includes Grasshopper-generated textures, JSON exports,
|
|
300
|
+
* CAD formats, or any file structure packaged in the response.
|
|
301
|
+
*
|
|
302
|
+
* @returns Raw file data entries.
|
|
303
|
+
*/
|
|
304
|
+
private getFileData;
|
|
305
|
+
/**
|
|
306
|
+
* Download all files generated by Grasshopper, optionally including
|
|
307
|
+
* additional user-provided files.
|
|
308
|
+
*
|
|
309
|
+
* Files are grouped under the specified folder name when downloaded.
|
|
310
|
+
*
|
|
311
|
+
* @param folderName - Name for the download directory.
|
|
312
|
+
* @param additionalFiles - Extra files to package (single file, array, or null).
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* ```ts
|
|
316
|
+
* processor.getAndDownloadFiles('gh-output');
|
|
317
|
+
* ```
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* ```ts
|
|
321
|
+
* const extra = { name: 'notes.txt', data: 'Example' };
|
|
322
|
+
* processor.getAndDownloadFiles('project', extra);
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
getAndDownloadFiles(folderName: string, additionalFiles?: FileBaseInfo[] | FileBaseInfo | null): void;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Runs a Rhino Compute job using the provided tree prototypes and Grasshopper definition.
|
|
330
|
+
*
|
|
331
|
+
* @public Use this for direct compute control. For high-level API, use `GrasshopperClient.solve()`.
|
|
332
|
+
*
|
|
333
|
+
* @param dataTree - An array of `DataTree` objects representing the input data for the compute job.
|
|
334
|
+
* @param definition - The Grasshopper definition, which can be:
|
|
335
|
+
* - A URL string (e.g., 'https://example.com/definition.gh')
|
|
336
|
+
* - A base64-encoded string of the .gh file
|
|
337
|
+
* - A plain string (will be base64-encoded)
|
|
338
|
+
* - A Uint8Array of the .gh file (will be base64-encoded)
|
|
339
|
+
* @param config - Compute configuration (server URL, API key, etc.)
|
|
340
|
+
* @param options - Optional compute options (timeout, cachesolve, model units, tolerances, etc.).
|
|
341
|
+
* @returns An object containing the compute result and extracted file data.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* // Using a URL
|
|
345
|
+
* await solveGrasshopperDefinition(trees, 'https://example.com/definition.gh', config);
|
|
346
|
+
*
|
|
347
|
+
* // Using a base64 string
|
|
348
|
+
* await solveGrasshopperDefinition(trees, 'UEsDBBQAAAAIAL...', config);
|
|
349
|
+
*
|
|
350
|
+
* // Using binary data
|
|
351
|
+
* const fileData = new Uint8Array([...]);
|
|
352
|
+
* await solveGrasshopperDefinition(trees, fileData, config);
|
|
353
|
+
*/
|
|
354
|
+
declare function solveGrasshopperDefinition(dataTree: DataTree[], definition: string | Uint8Array, config: GrasshopperComputeConfig): Promise<GrasshopperComputeResponse>;
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Fetches raw input/output schemas from a Grasshopper definition.
|
|
358
|
+
* Returns unprocessed data exactly as received from the Rhino Compute API (camelCased).
|
|
359
|
+
*
|
|
360
|
+
* @param definition - The Grasshopper definition (URL, base64 string, or Uint8Array)
|
|
361
|
+
* @param config - Compute configuration (server URL, API key, etc.)
|
|
362
|
+
* @returns Raw inputs and outputs with no type processing
|
|
363
|
+
* @throws {RhinoComputeError} If fetch fails or response is invalid
|
|
364
|
+
*
|
|
365
|
+
* @public Use `fetchParsedDefinitionIO()` for processed, type-safe inputs
|
|
366
|
+
*/
|
|
367
|
+
declare function fetchDefinitionIO(definition: string | Uint8Array, config: ComputeConfig): Promise<GrasshopperParsedIORaw>;
|
|
368
|
+
/**
|
|
369
|
+
* Fetches and processes input/output schemas from a Grasshopper definition.
|
|
370
|
+
* Returns strongly-typed, validated input parameters ready for use.
|
|
371
|
+
*
|
|
372
|
+
* @public This is the recommended way to fetch definition I/O schemas.
|
|
373
|
+
*
|
|
374
|
+
* @param definition - The Grasshopper definition (URL, base64 string, or Uint8Array)
|
|
375
|
+
* @param config - Compute configuration (server URL, API key, etc.)
|
|
376
|
+
* @returns Processed inputs with discriminated union types and outputs
|
|
377
|
+
* @throws {RhinoComputeError} If fetch fails or response is invalid
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
380
|
+
* ```typescript
|
|
381
|
+
* const { inputs, outputs } = await fetchParsedDefinitionIO(
|
|
382
|
+
* 'https://example.com/definition.gh',
|
|
383
|
+
* { serverUrl: 'https://compute.rhino3d.com', apiKey: 'YOUR_KEY' }
|
|
384
|
+
* );
|
|
385
|
+
*
|
|
386
|
+
* // Inputs are now strongly typed
|
|
387
|
+
* inputs.forEach(input => {
|
|
388
|
+
* if (input.paramType === 'Number') {
|
|
389
|
+
* console.log(input.minimum, input.maximum); // TypeScript knows these exist
|
|
390
|
+
* }
|
|
391
|
+
* });
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
declare function fetchParsedDefinitionIO(definition: string | Uint8Array, config: ComputeConfig): Promise<GrasshopperParsedIO>;
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Processes a raw input parameter schema and converts it into a typed InputParam object.
|
|
398
|
+
*
|
|
399
|
+
* @internal This is an internal processor. Use `fetchParsedDefinitionIO()` to get processed inputs instead.
|
|
400
|
+
*
|
|
401
|
+
* This function handles the transformation of raw input parameter data from Grasshopper into
|
|
402
|
+
* a structured, type-safe format. It performs validation, type-specific processing, and error
|
|
403
|
+
* handling for various parameter types including numeric, boolean, text, geometry, point, and line inputs.
|
|
404
|
+
*
|
|
405
|
+
* @param rawInput - The raw input parameter schema to process
|
|
406
|
+
* @returns A fully processed and typed InputParam object with appropriate type-specific properties
|
|
407
|
+
*
|
|
408
|
+
* @throws {RhinoComputeError} When an unknown paramType is encountered
|
|
409
|
+
* @throws {Error} Re-throws any non-RhinoComputeError exceptions
|
|
410
|
+
*
|
|
411
|
+
* @remarks
|
|
412
|
+
* The function performs the following operations:
|
|
413
|
+
* - Extracts base properties common to all input types
|
|
414
|
+
* - Preprocesses the raw input data
|
|
415
|
+
* - Applies type-specific validation and transformation
|
|
416
|
+
* - Handles errors gracefully by creating safe default values for validation errors
|
|
417
|
+
*
|
|
418
|
+
* Supported parameter types:
|
|
419
|
+
* - `Number` and `Integer`: Numeric inputs with optional min/max constraints
|
|
420
|
+
* - `Boolean`: Boolean flag inputs
|
|
421
|
+
* - `Text`: String inputs
|
|
422
|
+
* - `Geometry`: Generic geometry objects
|
|
423
|
+
* - `Point`: 3D point objects
|
|
424
|
+
* - `Line`: Line objects
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* ```typescript
|
|
428
|
+
* const rawInput = {
|
|
429
|
+
* name: 'Length',
|
|
430
|
+
* paramType: 'Number',
|
|
431
|
+
* minimum: 0,
|
|
432
|
+
* maximum: 100,
|
|
433
|
+
* default: 50
|
|
434
|
+
* };
|
|
435
|
+
* const processedInput = processInput(rawInput);
|
|
436
|
+
* ```
|
|
437
|
+
*/
|
|
438
|
+
declare function processInput(rawInput: InputParamSchema): InputParam;
|
|
439
|
+
/**
|
|
440
|
+
* Processes raw Grasshopper input schemas into strongly-typed TypeScript interfaces.
|
|
441
|
+
*
|
|
442
|
+
* @internal This is an internal batch processor. Use `fetchParsedDefinitionIO()` to get processed inputs instead.
|
|
443
|
+
*
|
|
444
|
+
* Transforms each raw input parameter by:
|
|
445
|
+
* - Normalizing default values (flattening data trees, parsing primitives)
|
|
446
|
+
* - Applying type-specific parsing (Number, Text, Boolean, Geometry, etc.)
|
|
447
|
+
* - Validating constraints (min/max, required fields)
|
|
448
|
+
* - Converting to discriminated union types for type safety
|
|
449
|
+
*
|
|
450
|
+
* @param rawInputs - Array of raw input schemas from Rhino Compute API
|
|
451
|
+
* @returns Array of processed, strongly-typed input parameters
|
|
452
|
+
*
|
|
453
|
+
* @remarks
|
|
454
|
+
* - Empty data trees are converted to `undefined`
|
|
455
|
+
* - Single values are extracted from arrays when appropriate
|
|
456
|
+
* - Tree structures are preserved for list/tree access parameters
|
|
457
|
+
* - Invalid inputs fall back to safe defaults with console warnings
|
|
458
|
+
*
|
|
459
|
+
* @example
|
|
460
|
+
* ```typescript
|
|
461
|
+
* const rawInputs = [
|
|
462
|
+
* { paramType: 'Number', name: 'radius', minimum: 0, default: 10 },
|
|
463
|
+
* { paramType: 'Text', name: 'label', default: 'Hello' }
|
|
464
|
+
* ];
|
|
465
|
+
*
|
|
466
|
+
* const processed = processInputs(rawInputs);
|
|
467
|
+
* // Result: [
|
|
468
|
+
* // { paramType: 'Number', name: 'radius', minimum: 0, default: 10, ... },
|
|
469
|
+
* // { paramType: 'Text', name: 'label', default: 'Hello', ... }
|
|
470
|
+
* // ]
|
|
471
|
+
*
|
|
472
|
+
* // Now type-safe:
|
|
473
|
+
* if (processed[0].paramType === 'Number') {
|
|
474
|
+
* console.log(processed[0].minimum); // TypeScript knows this exists
|
|
475
|
+
* }
|
|
476
|
+
* ```
|
|
477
|
+
*
|
|
478
|
+
* @see {@link processInput} for individual input processing logic
|
|
479
|
+
* @see {@link preProcessRawInput} for default value normalization
|
|
480
|
+
*/
|
|
481
|
+
declare function processInputs(rawInputs: InputParamSchema[]): InputParam[];
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Value types that can be stored in a DataTree
|
|
485
|
+
*/
|
|
486
|
+
type DataTreeValue = string | number | boolean | object | null;
|
|
487
|
+
/**
|
|
488
|
+
* Simple data item for compute requests (not to be confused with DataItem interface for responses).
|
|
489
|
+
* Note: While TypeScript defines this as string, Rhino Compute accepts boolean/number primitives in JSON.
|
|
490
|
+
*/
|
|
491
|
+
interface ComputeDataItem {
|
|
492
|
+
data: string | boolean | number;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* InnerTree data structure for compute requests.
|
|
496
|
+
*/
|
|
497
|
+
type ComputeInnerTreeData = {
|
|
498
|
+
[path in DataTreePath]: ComputeDataItem[];
|
|
499
|
+
};
|
|
500
|
+
/**
|
|
501
|
+
* Standalone TreeBuilder class for constructing Grasshopper TreeBuilder structures.
|
|
502
|
+
* Does not depend on RhinoCompute library.
|
|
503
|
+
*
|
|
504
|
+
* @example
|
|
505
|
+
* ```ts
|
|
506
|
+
* const tree = new TreeBuilder('MyParam')
|
|
507
|
+
* .append([0], [1, 2, 3])
|
|
508
|
+
* .append([1], [4, 5])
|
|
509
|
+
* .toComputeFormat();
|
|
510
|
+
* ```
|
|
511
|
+
*/
|
|
512
|
+
declare class TreeBuilder {
|
|
513
|
+
private innerTree;
|
|
514
|
+
private paramName;
|
|
515
|
+
constructor(paramName: string);
|
|
516
|
+
/**
|
|
517
|
+
* Append values to a specific path in the tree.
|
|
518
|
+
*
|
|
519
|
+
* @param path - Array of integers representing the branch path (e.g., [0], [0, 1])
|
|
520
|
+
* @param items - Values to append at this path
|
|
521
|
+
* @returns this for method chaining
|
|
522
|
+
*/
|
|
523
|
+
append(path: number[], items: DataTreeValue[]): this;
|
|
524
|
+
/**
|
|
525
|
+
* Append a single value to a path.
|
|
526
|
+
*
|
|
527
|
+
* @param path - Branch path
|
|
528
|
+
* @param item - Single value to append
|
|
529
|
+
* @returns this for method chaining
|
|
530
|
+
*/
|
|
531
|
+
appendSingle(path: number[], item: DataTreeValue): this;
|
|
532
|
+
/**
|
|
533
|
+
* Set values from a DataTreeDefault structure.
|
|
534
|
+
* Replaces any existing tree data.
|
|
535
|
+
*
|
|
536
|
+
* @param treeData - TreeBuilder structure with path keys like "{0;1}"
|
|
537
|
+
* @returns this for method chaining
|
|
538
|
+
*/
|
|
539
|
+
fromDataTreeDefault(treeData: DataTreeDefault): this;
|
|
540
|
+
/**
|
|
541
|
+
* Append flattened values to path [0].
|
|
542
|
+
* Useful for simple flat inputs.
|
|
543
|
+
*
|
|
544
|
+
* @param values - Single value or array of values
|
|
545
|
+
* @returns this for method chaining
|
|
546
|
+
*/
|
|
547
|
+
appendFlat(values: DataTreeValue | DataTreeValue[]): this;
|
|
548
|
+
/**
|
|
549
|
+
* Get the flattened list of all values in the tree.
|
|
550
|
+
*
|
|
551
|
+
* @returns Array of all values across all branches
|
|
552
|
+
*/
|
|
553
|
+
flatten(): DataTreeValue[];
|
|
554
|
+
/**
|
|
555
|
+
* Get all paths in the tree.
|
|
556
|
+
*
|
|
557
|
+
* @returns Array of path strings
|
|
558
|
+
*/
|
|
559
|
+
getPaths(): DataTreePath[];
|
|
560
|
+
/**
|
|
561
|
+
* Get values at a specific path.
|
|
562
|
+
*
|
|
563
|
+
* @param path - Path to retrieve values from
|
|
564
|
+
* @returns Array of values or undefined if path doesn't exist
|
|
565
|
+
*/
|
|
566
|
+
getPath(path: number[]): DataTreeValue[] | undefined;
|
|
567
|
+
/**
|
|
568
|
+
* Convert to format compatible with Grasshopper Compute API.
|
|
569
|
+
*
|
|
570
|
+
* @returns InnerTree object ready for compute
|
|
571
|
+
*/
|
|
572
|
+
toComputeFormat(): DataTree;
|
|
573
|
+
/**
|
|
574
|
+
* Get the raw InnerTree data structure.
|
|
575
|
+
*
|
|
576
|
+
* @returns InnerTree data
|
|
577
|
+
*/
|
|
578
|
+
getInnerTree(): ComputeInnerTreeData;
|
|
579
|
+
/**
|
|
580
|
+
* Get the parameter name.
|
|
581
|
+
*
|
|
582
|
+
* @returns Parameter name
|
|
583
|
+
*/
|
|
584
|
+
getParamName(): string;
|
|
585
|
+
/**
|
|
586
|
+
* Create DataTrees from an array of InputParam definitions.
|
|
587
|
+
* Handles tree access, numeric constraints, and value parsing.
|
|
588
|
+
*
|
|
589
|
+
* @param inputs - Array of input parameter definitions
|
|
590
|
+
* @returns Array of InnerTree instances ready for compute
|
|
591
|
+
*
|
|
592
|
+
* @example
|
|
593
|
+
* ```ts
|
|
594
|
+
* const trees = TreeBuilder.fromInputParams(inputs);
|
|
595
|
+
* ```
|
|
596
|
+
*/
|
|
597
|
+
static fromInputParams(inputs: InputParam[]): DataTree[];
|
|
598
|
+
/**
|
|
599
|
+
* Create a TreeBuilder from a single InputParam.
|
|
600
|
+
*
|
|
601
|
+
* @param input - Input parameter definition
|
|
602
|
+
* @returns InnerTree ready for compute or undefined if value is invalid
|
|
603
|
+
*/
|
|
604
|
+
static fromInputParam(input: InputParam): DataTree | undefined;
|
|
605
|
+
/**
|
|
606
|
+
* Set or replace a parameter value within a TreeBuilder or InnerTree array.
|
|
607
|
+
*
|
|
608
|
+
* Supports both high-level `DataTree[]` instances and low-level `InnerTree[]` format.
|
|
609
|
+
*
|
|
610
|
+
* **Architecture Note:**
|
|
611
|
+
* - Use with `DataTree[]` when building/modifying before computation
|
|
612
|
+
* - Use with `InnerTree[]` when modifying compute API results
|
|
613
|
+
* - `DataTree` is the high-level builder; `InnerTree` is the Rhino Compute format
|
|
614
|
+
*
|
|
615
|
+
* @overload For TreeBuilder instances (high-level builder)
|
|
616
|
+
* @param trees - Array of TreeBuilder instances to modify
|
|
617
|
+
* @param paramName - The parameter name to set or replace
|
|
618
|
+
* @param newValue - The new value (scalar, array, or TreeBuilder structure)
|
|
619
|
+
* @returns A new/modified TreeBuilder array with the updated parameter
|
|
620
|
+
*
|
|
621
|
+
* @overload For compiled InnerTree (low-level API format)
|
|
622
|
+
* @param trees - The compiled InnerTree array (typically from `client.solve()`)
|
|
623
|
+
* @param paramName - The parameter name to set or replace
|
|
624
|
+
* @param newValue - The new value (scalar, array, or TreeBuilder structure)
|
|
625
|
+
* @returns A new/modified InnerTree array with the updated parameter
|
|
626
|
+
*
|
|
627
|
+
* @example
|
|
628
|
+
* ```ts
|
|
629
|
+
* // With TreeBuilder instances (high-level)
|
|
630
|
+
* let trees = [new TreeBuilder('X'), new TreeBuilder('Y')];
|
|
631
|
+
* trees = TreeBuilder.replaceTreeValue(trees, 'X', 42);
|
|
632
|
+
* const result = await client.solve(definitionUrl,
|
|
633
|
+
* trees.map(t => t.toComputeFormat())
|
|
634
|
+
* );
|
|
635
|
+
* ```
|
|
636
|
+
*
|
|
637
|
+
* @example
|
|
638
|
+
* ```ts
|
|
639
|
+
* // With InnerTree format (low-level, from API)
|
|
640
|
+
* let trees = await client.solve(definitionUrl, initialInputs);
|
|
641
|
+
* trees = TreeBuilder.replaceTreeValue(trees, 'X', 42);
|
|
642
|
+
* trees = TreeBuilder.replaceTreeValue(trees, 'Y', [1, 2, 3]);
|
|
643
|
+
* ```
|
|
644
|
+
*/
|
|
645
|
+
static replaceTreeValue(trees: TreeBuilder[], paramName: string, newValue: DataTreeValue): TreeBuilder[];
|
|
646
|
+
static replaceTreeValue(trees: DataTree[], paramName: string, newValue: DataTreeValue): DataTree[];
|
|
647
|
+
/**
|
|
648
|
+
* Extract a value from a TreeBuilder or InnerTree array by parameter name.
|
|
649
|
+
*
|
|
650
|
+
* Automatically unwraps single values for convenience.
|
|
651
|
+
* Works with both high-level `DataTree[]` instances and low-level `InnerTree[]` format.
|
|
652
|
+
*
|
|
653
|
+
* **Architecture Note:**
|
|
654
|
+
* - Use with `DataTree[]` to read builder instances
|
|
655
|
+
* - Use with `InnerTree[]` to read compute API responses
|
|
656
|
+
* - Return behavior is consistent across both formats
|
|
657
|
+
*
|
|
658
|
+
* **Return Value Behavior:**
|
|
659
|
+
* - Single value → unwrapped (returns `5` not `[5]`)
|
|
660
|
+
* - Multiple values → array of values
|
|
661
|
+
* - Not found → `null`
|
|
662
|
+
*
|
|
663
|
+
* @overload For TreeBuilder instances
|
|
664
|
+
* @param trees - Array of TreeBuilder instances to read from
|
|
665
|
+
* @param paramName - The parameter name to retrieve
|
|
666
|
+
* @returns The unwrapped value, array of values, or null if parameter not found
|
|
667
|
+
*
|
|
668
|
+
* @overload For compiled InnerTree
|
|
669
|
+
* @param trees - The compiled InnerTree array (typically from `client.solve()`)
|
|
670
|
+
* @param paramName - The parameter name to retrieve
|
|
671
|
+
* @returns The unwrapped value, array of values, or null if parameter not found
|
|
672
|
+
*
|
|
673
|
+
* @example
|
|
674
|
+
* ```ts
|
|
675
|
+
* // With TreeBuilder instances
|
|
676
|
+
* const trees = [new TreeBuilder('X'), new TreeBuilder('Y')];
|
|
677
|
+
* trees[0].appendFlat(42);
|
|
678
|
+
* const x = TreeBuilder.getTreeValue(trees, 'X'); // Returns 42
|
|
679
|
+
* ```
|
|
680
|
+
*
|
|
681
|
+
* @example
|
|
682
|
+
* ```ts
|
|
683
|
+
* // With InnerTree from compute results
|
|
684
|
+
* const result = await client.solve(definitionUrl, inputs);
|
|
685
|
+
* const x = TreeBuilder.getTreeValue(result, 'X'); // Returns 42 (not [42])
|
|
686
|
+
* const points = TreeBuilder.getTreeValue(result, 'Points'); // Returns [point1, point2, ...]
|
|
687
|
+
* ```
|
|
688
|
+
*/
|
|
689
|
+
static getTreeValue(trees: TreeBuilder[], paramName: string): DataTreeValue | null;
|
|
690
|
+
static getTreeValue(trees: DataTree[], paramName: string): DataTreeValue | null;
|
|
691
|
+
/**
|
|
692
|
+
* Parse a TreeBuilder path string like "{0;1;2}" into [0, 1, 2].
|
|
693
|
+
*
|
|
694
|
+
* @param pathStr - Path string
|
|
695
|
+
* @returns Array of path indices
|
|
696
|
+
*/
|
|
697
|
+
static parsePathString(pathStr: string): number[];
|
|
698
|
+
/**
|
|
699
|
+
* Format a path array into TreeBuilder path string format.
|
|
700
|
+
*
|
|
701
|
+
* @param path - Path as number array
|
|
702
|
+
* @returns Formatted path string like "{0;1;2}"
|
|
703
|
+
*/
|
|
704
|
+
static formatPathString(path: number[]): DataTreePath;
|
|
705
|
+
/**
|
|
706
|
+
* Apply numeric constraints to all tree values.
|
|
707
|
+
*/
|
|
708
|
+
private applyNumericConstraints;
|
|
709
|
+
/**
|
|
710
|
+
* Serialize a value for compute requests.
|
|
711
|
+
* Preserves booleans and numbers as primitives for proper Grasshopper parameter handling.
|
|
712
|
+
*/
|
|
713
|
+
private static serializeValue;
|
|
714
|
+
/**
|
|
715
|
+
* Deserialize a value back to its original type.
|
|
716
|
+
* Handles both string-encoded values and primitive values.
|
|
717
|
+
*/
|
|
718
|
+
private static deserializeValue;
|
|
719
|
+
/**
|
|
720
|
+
* Check if a value is valid for inclusion in a DataTree.
|
|
721
|
+
*/
|
|
722
|
+
private static hasValidValue;
|
|
723
|
+
/**
|
|
724
|
+
* Check if value is a TreeBuilder structure.
|
|
725
|
+
*/
|
|
726
|
+
private static isDataTreeStructure;
|
|
727
|
+
/**
|
|
728
|
+
* Check if input is numeric type.
|
|
729
|
+
*/
|
|
730
|
+
private static isNumericInput;
|
|
731
|
+
/**
|
|
732
|
+
* Process array of values based on input type.
|
|
733
|
+
*/
|
|
734
|
+
private static processValues;
|
|
735
|
+
/**
|
|
736
|
+
* Clamp numeric value to constraints.
|
|
737
|
+
*/
|
|
738
|
+
private static clampValue;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
export { type BooleanInputType, ComputeConfig, DataTree, DataTreeDefault, type DataTreeValue, type GeometryInputType, GrasshopperClient, GrasshopperComputeConfig, GrasshopperComputeResponse, type GrasshopperParsedIO, GrasshopperResponseProcessor, type InputParam, InputParamSchema, type NumericInputType, OutputParamSchema, type OutputType, type TextInputType, TreeBuilder, type ValueListInputType, fetchDefinitionIO, fetchParsedDefinitionIO, processInput, processInputs, solveGrasshopperDefinition };
|