@selvajs/compute 1.5.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 (45) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +106 -0
  3. package/dist/base-dtik4Dlu.d.cts +138 -0
  4. package/dist/base-dtik4Dlu.d.ts +138 -0
  5. package/dist/chunk-FRSLCR7G.cjs +2 -0
  6. package/dist/chunk-FRSLCR7G.cjs.map +1 -0
  7. package/dist/chunk-IJZNCO5X.cjs +3 -0
  8. package/dist/chunk-IJZNCO5X.cjs.map +1 -0
  9. package/dist/chunk-LNIUUPA5.cjs +2 -0
  10. package/dist/chunk-LNIUUPA5.cjs.map +1 -0
  11. package/dist/chunk-PZ4HZLFJ.js +2 -0
  12. package/dist/chunk-PZ4HZLFJ.js.map +1 -0
  13. package/dist/chunk-VK2TSW7S.js +3 -0
  14. package/dist/chunk-VK2TSW7S.js.map +1 -0
  15. package/dist/chunk-WXQGTKU6.js +2 -0
  16. package/dist/chunk-WXQGTKU6.js.map +1 -0
  17. package/dist/core.cjs +2 -0
  18. package/dist/core.cjs.map +1 -0
  19. package/dist/core.d.cts +140 -0
  20. package/dist/core.d.ts +140 -0
  21. package/dist/core.js +2 -0
  22. package/dist/core.js.map +1 -0
  23. package/dist/grasshopper.cjs +2 -0
  24. package/dist/grasshopper.cjs.map +1 -0
  25. package/dist/grasshopper.d.cts +1014 -0
  26. package/dist/grasshopper.d.ts +1014 -0
  27. package/dist/grasshopper.js +2 -0
  28. package/dist/grasshopper.js.map +1 -0
  29. package/dist/index.cjs +2 -0
  30. package/dist/index.cjs.map +1 -0
  31. package/dist/index.d.cts +6 -0
  32. package/dist/index.d.ts +6 -0
  33. package/dist/index.js +2 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/schemas-Ct7lU-IH.d.cts +247 -0
  36. package/dist/schemas-Ct7lU-IH.d.ts +247 -0
  37. package/dist/types-B24K2LG4.d.cts +85 -0
  38. package/dist/types-B24K2LG4.d.ts +85 -0
  39. package/dist/visualization.cjs +2 -0
  40. package/dist/visualization.cjs.map +1 -0
  41. package/dist/visualization.d.cts +205 -0
  42. package/dist/visualization.d.ts +205 -0
  43. package/dist/visualization.js +2 -0
  44. package/dist/visualization.js.map +1 -0
  45. package/package.json +122 -0
@@ -0,0 +1,1014 @@
1
+ import { R as RhinoComputeError, C as ComputeServerStats } from './base-dtik4Dlu.js';
2
+ import { b as DataTreeDefault, O as OutputParamSchema, f as InputParamSchema, R as RetryPolicy, d as GrasshopperComputeResponse, a as DataTree, G as GrasshopperComputeConfig, C as ComputeConfig, c as DataTreePath } from './schemas-Ct7lU-IH.js';
3
+ export { D as DataItem, e as GrasshopperRequestSchema, I as InnerTreeData, g as RhinoModelUnit } from './schemas-Ct7lU-IH.js';
4
+ import * as THREE from 'three';
5
+ import { M as MeshExtractionOptions } from './types-B24K2LG4.js';
6
+
7
+ /**
8
+ * Input and output parameter types
9
+ */
10
+
11
+ /**
12
+ * Output types supported from Grasshopper/Rhino Compute
13
+ */
14
+ 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;
15
+ /**
16
+ * Union type for all possible default value types
17
+ */
18
+ type DefaultValue<T> = T | T[] | DataTreeDefault<T> | undefined | null;
19
+ /**
20
+ * Base properties common to all processed input types.
21
+ * Note: `groupName` and `id` require the custom Rhino Compute branch.
22
+ */
23
+ interface BaseInputType {
24
+ description: string;
25
+ name: string;
26
+ nickname: string | null;
27
+ treeAccess: boolean;
28
+ /**
29
+ * Name of the group this parameter belongs to.
30
+ * @requires Custom branch of compute.rhino3d
31
+ */
32
+ groupName?: string;
33
+ /**
34
+ * Unique identifier for the parameter.
35
+ * @requires Custom branch of compute.rhino3d
36
+ */
37
+ id?: string;
38
+ }
39
+ /**
40
+ * Numeric input type (Number or Integer)
41
+ */
42
+ interface NumericInputType extends BaseInputType {
43
+ paramType: 'Number' | 'Integer';
44
+ minimum?: number | null;
45
+ maximum?: number | null;
46
+ atLeast?: number | null;
47
+ atMost?: number | null;
48
+ stepSize?: number | null;
49
+ default: DefaultValue<number>;
50
+ }
51
+ /**
52
+ * Text input type
53
+ */
54
+ interface TextInputType extends BaseInputType {
55
+ paramType: 'Text';
56
+ default: DefaultValue<string>;
57
+ }
58
+ /**
59
+ * Boolean input type
60
+ */
61
+ interface BooleanInputType extends BaseInputType {
62
+ paramType: 'Boolean';
63
+ default: DefaultValue<boolean>;
64
+ }
65
+ /**
66
+ * Geometry input type (generic geometry)
67
+ */
68
+ interface GeometryInputType extends BaseInputType {
69
+ paramType: 'Geometry';
70
+ default: DefaultValue<object | string>;
71
+ }
72
+ /**
73
+ * ValueList input type (dropdown/select)
74
+ */
75
+ interface ValueListInputType extends BaseInputType {
76
+ paramType: 'ValueList';
77
+ values: Record<string, string>;
78
+ default?: string;
79
+ }
80
+ /**
81
+ * File input type
82
+ */
83
+ interface FileInputType extends BaseInputType {
84
+ paramType: 'File';
85
+ acceptedFormats?: string[];
86
+ default: DefaultValue<object | string>;
87
+ }
88
+ /**
89
+ * Color input type (stored as hex string)
90
+ */
91
+ interface ColorInputType extends BaseInputType {
92
+ paramType: 'Color';
93
+ default: DefaultValue<string>;
94
+ }
95
+ /**
96
+ * Discriminated union of all input parameter types
97
+ */
98
+ type InputParam = NumericInputType | BooleanInputType | TextInputType | ValueListInputType | GeometryInputType | FileInputType | ColorInputType;
99
+
100
+ /**
101
+ * Parsed data structures for processed Grasshopper input/output
102
+ */
103
+
104
+ /**
105
+ * Parsed input/output structure with raw schemas
106
+ */
107
+ interface GrasshopperParsedIORaw {
108
+ inputs: InputParamSchema[];
109
+ outputs: OutputParamSchema[];
110
+ }
111
+ /**
112
+ * Parsed input/output structure with processed types
113
+ */
114
+ interface GrasshopperParsedIO {
115
+ inputs: InputParam[];
116
+ outputs: OutputParamSchema[];
117
+ }
118
+
119
+ /**
120
+ * Scheduling mode — controls how concurrent `solve()` calls interact.
121
+ *
122
+ * - `latest-wins`: One in flight at a time. New calls supersede any pending
123
+ * call (in-flight one is aborted). Optimal for slider scrubs / live UIs.
124
+ * - `queue`: FIFO queue. Each solve runs to completion. Concurrency capped
125
+ * by `maxConcurrent`. Use for "submit job" flows where every request matters.
126
+ * - `parallel`: No scheduling — calls run concurrently up to `maxConcurrent`.
127
+ * Closest to plain `client.solve()` but with shared cancel/state.
128
+ */
129
+ type SchedulerMode = 'latest-wins' | 'queue' | 'parallel';
130
+ interface CacheOptions {
131
+ /** Maximum entries kept in the LRU. Default: 50. */
132
+ maxEntries?: number;
133
+ /** Time-to-live in ms. Set to `0` for no expiry (default). */
134
+ ttlMs?: number;
135
+ }
136
+ interface SolveSchedulerOptions {
137
+ mode?: SchedulerMode;
138
+ maxConcurrent?: number;
139
+ timeoutMs?: number;
140
+ retry?: RetryPolicy;
141
+ /** Enable response caching keyed by hash of (definition, dataTree). */
142
+ cache?: boolean | CacheOptions;
143
+ /** Lifecycle hooks — fired in order. Errors thrown by hooks are logged, not rethrown. */
144
+ onStart?: (ctx: SolveContext) => void;
145
+ onSettle?: (ctx: SolveContext, result: SolveResult) => void;
146
+ onSuperseded?: (ctx: SolveContext) => void;
147
+ }
148
+ interface SolveContext {
149
+ /** Stable hash of (definition, dataTree). */
150
+ key: string;
151
+ /** Wall-clock timestamp when scheduler.solve() was called. */
152
+ enqueuedAt: number;
153
+ /** Wall-clock timestamp when execution actually started (after queueing). */
154
+ startedAt: number | null;
155
+ }
156
+ type SolveResult = {
157
+ status: 'success';
158
+ response: GrasshopperComputeResponse;
159
+ durationMs: number;
160
+ fromCache: boolean;
161
+ } | {
162
+ status: 'error';
163
+ error: RhinoComputeError;
164
+ durationMs: number;
165
+ } | {
166
+ status: 'superseded';
167
+ };
168
+ /**
169
+ * Adapter for the underlying solve function. Lets the scheduler be tested
170
+ * without a real Compute server, and decouples it from the client class.
171
+ */
172
+ type SolveExecutor = (definition: string | Uint8Array, dataTree: DataTree[], config: GrasshopperComputeConfig) => Promise<GrasshopperComputeResponse>;
173
+ /**
174
+ * Robust scheduler for Grasshopper solves.
175
+ *
176
+ * Sits between your application code and the underlying compute call,
177
+ * adding:
178
+ * - Configurable scheduling (latest-wins for sliders, queue for jobs)
179
+ * - In-flight cancellation (per-call signal + cancelAll)
180
+ * - Optional response caching for repeated inputs
181
+ * - Lifecycle hooks for UI indicators (start / settle / superseded)
182
+ * - State observability via subscribe()
183
+ *
184
+ * Multiple schedulers can share a single GrasshopperClient — typically one
185
+ * per UI surface (e.g. one for slider scrubs, one for long-running submits).
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * const scheduler = client.createScheduler({ mode: 'latest-wins', timeoutMs: 30_000 });
190
+ *
191
+ * // From a slider handler:
192
+ * scheduler.solve(definition, tree).then((result) => {
193
+ * updateMeshes(result);
194
+ * }).catch((err) => {
195
+ * if (err.code !== 'SUPERSEDED') showError(err);
196
+ * });
197
+ *
198
+ * // From a UI binding:
199
+ * scheduler.subscribe(() => {
200
+ * showSpinner = scheduler.isSolving;
201
+ * });
202
+ * ```
203
+ */
204
+ declare class SolveScheduler {
205
+ private readonly executor;
206
+ private readonly baseConfig;
207
+ private readonly mode;
208
+ private readonly maxConcurrent;
209
+ private readonly timeoutMs;
210
+ private readonly retry;
211
+ private readonly cacheEnabled;
212
+ private readonly cacheMax;
213
+ private readonly cacheTtl;
214
+ private readonly cache;
215
+ private readonly onStart?;
216
+ private readonly onSettle?;
217
+ private readonly onSuperseded?;
218
+ private readonly subscribers;
219
+ private readonly inFlight;
220
+ private pendingForLatestWins;
221
+ private readonly fifoQueue;
222
+ private _lastResult;
223
+ private _lastError;
224
+ private _lastDurationMs;
225
+ private disposed;
226
+ constructor(executor: SolveExecutor, baseConfig: GrasshopperComputeConfig, options?: SolveSchedulerOptions);
227
+ get isSolving(): boolean;
228
+ get hasPending(): boolean;
229
+ get inFlightCount(): number;
230
+ get queueDepth(): number;
231
+ get lastResult(): GrasshopperComputeResponse | null;
232
+ get lastError(): RhinoComputeError | null;
233
+ get lastDurationMs(): number | null;
234
+ subscribe(listener: () => void): () => void;
235
+ private notify;
236
+ /**
237
+ * Schedule a solve. Returns a promise that:
238
+ * - Resolves with the compute response on success.
239
+ * - Rejects with `RhinoComputeError` on failure.
240
+ * - Rejects with `code: ErrorCodes.UNKNOWN_ERROR` and `message: 'Superseded'`
241
+ * when the call was canceled because newer values arrived (latest-wins mode).
242
+ *
243
+ * Caller-supplied `signal` cancels just this call (rejects with abort error).
244
+ */
245
+ solve(definition: string | Uint8Array, dataTree: DataTree[], options?: {
246
+ signal?: AbortSignal;
247
+ }): Promise<GrasshopperComputeResponse>;
248
+ private enqueue;
249
+ private execute;
250
+ private drainNext;
251
+ private supersede;
252
+ private makeAbortError;
253
+ /** Cancel everything — in-flight and pending. */
254
+ cancelAll(): void;
255
+ private readCache;
256
+ private writeCache;
257
+ clearCache(): void;
258
+ dispose(): void;
259
+ private runHook;
260
+ }
261
+
262
+ /**
263
+ * Hash a (definition, dataTree) pair into a short stable key.
264
+ * For Uint8Array definitions we use length + endpoint bytes rather than the
265
+ * full content to keep hashing cheap.
266
+ */
267
+ declare function hashSolveInput(definition: string | Uint8Array, dataTree: unknown): string;
268
+
269
+ /**
270
+ * Per-call options that override the client's default ComputeConfig values.
271
+ *
272
+ * Use these for per-request control without mutating the client config:
273
+ * - `signal` — cancel a specific solve (e.g. when a slider value is superseded)
274
+ * - `timeoutMs` — extend timeout for a long-running solve, or pass `0` to disable
275
+ * - `retry` — override retry policy for this call only
276
+ */
277
+ interface SolveOptions {
278
+ signal?: AbortSignal;
279
+ timeoutMs?: number;
280
+ retry?: RetryPolicy;
281
+ }
282
+ /**
283
+ * GrasshopperClient provides a simple API for interacting with a Rhino Compute server and grasshopper.
284
+ *
285
+ * @public This is the recommended high-level API for Rhino Compute operations.
286
+ *
287
+ * **Security Warning:**
288
+ * Using this client in a browser environment exposes your server URL and API key to users.
289
+ * For production, use this library server-side or proxy requests through your own backend.
290
+ *
291
+ * @example
292
+ * ```typescript
293
+ * const client = await GrasshopperClient.create({
294
+ * serverUrl: 'http://localhost:6500',
295
+ * apiKey: 'your-api-key'
296
+ * });
297
+ *
298
+ * try {
299
+ * const result = await client.solve(definitionUrl, { x: 1, y: 2 });
300
+ * } finally {
301
+ * await client.dispose(); // Clean up resources
302
+ * }
303
+ * ```
304
+ */
305
+ declare class GrasshopperClient {
306
+ private readonly config;
307
+ readonly serverStats: ComputeServerStats;
308
+ private disposed;
309
+ private constructor();
310
+ /**
311
+ * Creates and initializes a GrasshopperClient with server validation.
312
+ *
313
+ * @throws {RhinoComputeError} with code NETWORK_ERROR if server is offline
314
+ * @throws {RhinoComputeError} with code INVALID_CONFIG if configuration is invalid
315
+ */
316
+ static create(config: GrasshopperComputeConfig): Promise<GrasshopperClient>;
317
+ /**
318
+ * Gets the client's configuration.
319
+ * Useful for passing to lower-level functions.
320
+ */
321
+ getConfig(): GrasshopperComputeConfig;
322
+ /**
323
+ * Get input/output parameters of a Grasshopper definition.
324
+ */
325
+ getIO(definition: string | Uint8Array): Promise<GrasshopperParsedIO>;
326
+ getRawIO(definition: string | Uint8Array): Promise<GrasshopperParsedIORaw>;
327
+ /**
328
+ * Run a compute job with a Grasshopper definition.
329
+ *
330
+ * @throws {RhinoComputeError} with code INVALID_INPUT if definition is empty
331
+ * @throws {RhinoComputeError} with code NETWORK_ERROR if server is offline
332
+ * @throws {RhinoComputeError} with code COMPUTATION_ERROR if computation fails
333
+ */
334
+ solve(definition: string | Uint8Array, dataTree: DataTree[], options?: SolveOptions): Promise<GrasshopperComputeResponse>;
335
+ /**
336
+ * Create a scheduler bound to this client. Use a scheduler for any UI surface
337
+ * that fires solves frequently (sliders, live editors) or that needs cancel
338
+ * semantics, response caching, or state observability.
339
+ *
340
+ * Multiple schedulers can be created from a single client — typically one per
341
+ * UI surface so their queues stay independent.
342
+ *
343
+ * @example
344
+ * ```ts
345
+ * const sliderScheduler = client.createScheduler({ mode: 'latest-wins' });
346
+ * const submitScheduler = client.createScheduler({ mode: 'queue', timeoutMs: 0, retry: { attempts: 1 } });
347
+ * ```
348
+ */
349
+ createScheduler(options?: SolveSchedulerOptions): SolveScheduler;
350
+ /**
351
+ * Disposes of client resources.
352
+ * Call this when you're done using the client.
353
+ */
354
+ dispose(): Promise<void>;
355
+ /**
356
+ * Ensures the client hasn't been disposed.
357
+ */
358
+ private ensureNotDisposed;
359
+ /**
360
+ * Validates and normalizes a compute configuration.
361
+ *
362
+ * @throws {RhinoComputeError} with code INVALID_CONFIG if configuration is invalid
363
+ */
364
+ private normalizeComputeConfig;
365
+ }
366
+
367
+ /**
368
+ * Represents raw file data from Grasshopper/Rhino Compute response.
369
+ *
370
+ * This type encapsulates file output from compute operations, with metadata
371
+ * for processing (decoding, naming, organization). Files are typically combined
372
+ * with additional files and packaged into a ZIP archive for download.
373
+ *
374
+ * @see {@link ProcessedFile} for the normalized format after processing
375
+ * @see {@link extractFilesFromComputeResponse} for extraction from compute responses
376
+ */
377
+ type FileData = {
378
+ /** Base filename without extension (e.g., "model") */
379
+ fileName: string;
380
+ /** File content as a base64-encoded or plain string, depending on {@link IsBase64Encoded} */
381
+ data: string;
382
+ /** File extension including the dot (e.g., ".3dm", ".json"). Appended to {@link FileName} to create the full filename */
383
+ fileType: string;
384
+ /** Whether {@link Data} is base64-encoded. If true, must be decoded to binary before use. If false, can be used as a plain text string */
385
+ isBase64Encoded: boolean;
386
+ /** Directory path for organizing the file in archive structures (e.g., ZIP). Typically empty string for root-level files, or a path like "subfolder/nested" */
387
+ subFolder: string;
388
+ };
389
+ /**
390
+ * Represents a normalized, processed file ready for consumption or archival.
391
+ *
392
+ * This is the unified intermediate format produced by processing both {@link FileData}
393
+ * and {@link FileBaseInfo}. Files in this format are ready to be packaged into archives
394
+ * (e.g., ZIP files) or returned to callers for programmatic use.
395
+ *
396
+ * @see {@link FileData} for raw compute response files
397
+ * @see {@link FileBaseInfo} for external file references
398
+ */
399
+ type ProcessedFile = {
400
+ /** Full filename including extension (e.g., "model.3dm") */
401
+ fileName: string;
402
+ /** File content as either binary data or text. Binary format (Uint8Array) is used for decoded base64 or fetched binary files; text format is used for plain text content */
403
+ content: Uint8Array | string;
404
+ /** File path for archive organization (e.g., "subfolder/model.3dm"). Used when creating ZIP archives or other hierarchical structures */
405
+ path: string;
406
+ };
407
+ /**
408
+ * Represents a reference to an external file to be included in file operations.
409
+ *
410
+ * This type is used to specify additional files (beyond compute response files)
411
+ * that should be fetched and included when processing files. The file is fetched
412
+ * from the provided URL and processed as a {@link ProcessedFile}.
413
+ *
414
+ *
415
+ * @see {@link FileData} for files from compute responses
416
+ * @see {@link processFiles} for how FileBaseInfo is processed (fetched and converted)
417
+ */
418
+ type FileBaseInfo = {
419
+ /** Destination filename for the file in the archive or result set (e.g., "additional-data.json") */
420
+ fileName: string;
421
+ /** URL to fetch the file from. Must be accessible from the runtime environment */
422
+ filePath: string;
423
+ };
424
+
425
+ interface ParsedContext {
426
+ [key: string]: any;
427
+ }
428
+ interface GetValuesOptions {
429
+ parseValues?: boolean;
430
+ rhino?: any;
431
+ /**
432
+ * If true, only include values of type System.String in the result.
433
+ * Non-string types are filtered out.
434
+ */
435
+ stringOnly?: boolean;
436
+ }
437
+ interface GetValuesResult<T = ParsedContext> {
438
+ values: T;
439
+ }
440
+
441
+ /**
442
+ * High-level wrapper for interacting with Grasshopper Compute responses.
443
+ *
444
+ * This class exposes a clean, consistent API for accessing parsed values,
445
+ * geometry, and produced files. It is designed to be the primary interface
446
+ * when working with Grasshopper results in client applications.
447
+ */
448
+ declare class GrasshopperResponseProcessor {
449
+ private readonly response;
450
+ private readonly debug;
451
+ /**
452
+ * Store the compute response for reuse.
453
+ */
454
+ constructor(response: GrasshopperComputeResponse, debug?: boolean);
455
+ /**
456
+ * Extract all values in the response.
457
+ *
458
+ * @typeParam T - Expected structure of the return value. Defaults to a simple key/value map. (later cast as needed)
459
+ * @param byId - If true, keys are parameter IDs; if false, keys are parameter names.
460
+ * @param options - Controls parsing behavior such as Rhino geometry decoding.
461
+ * @returns Parsed Grasshopper output values.
462
+ *
463
+ * **Note:** Using `byId` only works with the custom VektorNode rhino.compute branch.
464
+ *
465
+ * @example
466
+ * ```ts
467
+ * const processor = new GrasshopperResponseProcessor(response);
468
+ * const { values } = processor.getValues();
469
+ * ```
470
+ *
471
+ * @example
472
+ * ```ts
473
+ * const { values } = processor.getValues(true); // keyed by param ID
474
+ * ```
475
+ */
476
+ getValues<T = ParsedContext>(byId?: boolean, options?: GetValuesOptions): GetValuesResult<T>;
477
+ /**
478
+ * Retrieve a specific value using the parameter name.
479
+ *
480
+ * @param paramName - Human-readable parameter name from the Grasshopper definition.
481
+ * @param options - Parsing configuration (e.g. disable parsing or enable Rhino).
482
+ * @returns Single parsed value, array of values, or undefined if the parameter is absent.
483
+ *
484
+ * @example
485
+ * ```ts
486
+ * const schema = processor.getValueByParamName('Schema');
487
+ * ```
488
+ */
489
+ getValueByParamName(paramName: string, options?: GetValuesOptions): any;
490
+ /**
491
+ * Retrieve a specific value using the parameter ID.
492
+ *
493
+ * @param paramId - Parameter GUID from the Grasshopper definition.
494
+ * @param options - Parsing configuration (e.g. disable parsing or enable Rhino).
495
+ * @returns Parsed value, array of values, or undefined if not present.
496
+ *
497
+ * @example
498
+ * ```ts
499
+ * const output = processor.getValueByParamId('a4be1c1e-23f9-4c27-b942-7f3bb2c45c6f');
500
+ * ```
501
+ */
502
+ getValueByParamId(paramId: string, options?: GetValuesOptions): any;
503
+ /**
504
+ * Convert all geometry results into Three.js mesh objects.
505
+ *
506
+ * This uses internal helpers to decode Rhino geometry into Three.js
507
+ * primitives such as meshes and lines, making them ready for rendering.
508
+ *
509
+ * All processing options (scaling, positioning, compression, etc.) can be customized.
510
+ * The processor's debug flag is merged with options - explicit options take precedence.
511
+ *
512
+ * **Note:** This only works when using the **Selva Display** component in Grasshopper, and requires the custom branch of rhino.compute from VektorNode. This method dynamically imports three.js visualization modules. Ensure three.js is installed as a peer dependency if you use this feature.
513
+ *
514
+ * @param options - Configuration for mesh extraction and parsing. Overrides processor's debug flag if provided.
515
+ * @returns Promise resolving to an array of Three.js mesh objects.
516
+ * @throws {RhinoComputeError} If three.js visualization module cannot be loaded.
517
+ *
518
+ * @example
519
+ * ```ts
520
+ * const meshes = await processor.extractMeshesFromResponse();
521
+ * scene.add(...meshes);
522
+ * ```
523
+ *
524
+ * @example
525
+ * ```ts
526
+ * const meshes = await processor.extractMeshesFromResponse({
527
+ * debug: true,
528
+ * allowScaling: true,
529
+ * allowAutoPosition: false,
530
+ * parsing: {
531
+ * mergeByMaterial: false,
532
+ * applyTransforms: true,
533
+ * debug: true,
534
+ * },
535
+ * });
536
+ * ```
537
+ */
538
+ extractMeshesFromResponse(options?: MeshExtractionOptions): Promise<THREE.Mesh<THREE.BufferGeometry<THREE.NormalBufferAttributes, THREE.BufferGeometryEventMap>, THREE.Material | THREE.Material[], THREE.Object3DEventMap>[]>;
539
+ /**
540
+ * Extract internal file data structures from the response.
541
+ * This includes Grasshopper-generated textures, JSON exports,
542
+ * CAD formats, or any file structure packaged in the response.
543
+ *
544
+ * **Note:** This only works when using the **Block to File** and **Geometry To File** components from the Selva plugin in Grasshopper, and requires the custom branch of rhino.compute from VektorNode.
545
+ *
546
+ * @returns Raw file data entries.
547
+ */
548
+ private getFileData;
549
+ /**
550
+ * Download all files generated by Grasshopper, optionally including
551
+ * additional user-provided files.
552
+ *
553
+ * Files are grouped under the specified folder name when downloaded.
554
+ *
555
+ * @param folderName - Name for the download directory.
556
+ * @param additionalFiles - Extra files to package (single file, array, or null).
557
+ *
558
+ * @example
559
+ * ```ts
560
+ * processor.getAndDownloadFiles('gh-output');
561
+ * ```
562
+ *
563
+ * @example
564
+ * ```ts
565
+ * const extra = { name: 'notes.txt', data: 'Example' };
566
+ * processor.getAndDownloadFiles('project', extra);
567
+ * ```
568
+ */
569
+ getAndDownloadFiles(folderName: string, additionalFiles?: FileBaseInfo[] | FileBaseInfo | null): void;
570
+ }
571
+
572
+ /**
573
+ * Runs a Rhino Compute job using the provided tree prototypes and Grasshopper definition.
574
+ *
575
+ * @public Use this for direct compute control. For high-level API, use `GrasshopperClient.solve()`.
576
+ *
577
+ * @param dataTree - An array of `DataTree` objects representing the input data for the compute job.
578
+ * @param definition - The Grasshopper definition, which can be:
579
+ * - A URL string (e.g., 'https://example.com/definition.gh')
580
+ * - A base64-encoded string of the .gh file
581
+ * - A plain string (will be base64-encoded)
582
+ * - A Uint8Array of the .gh file (will be base64-encoded)
583
+ * @param config - Compute configuration (server URL, API key, etc. along with optional timeout, units, etc.)
584
+ * @returns An object containing the compute result and extracted file data.
585
+ *
586
+ * @example
587
+ * // Using a URL
588
+ * await solveGrasshopperDefinition(trees, 'https://example.com/definition.gh', config);
589
+ *
590
+ * // Using a base64 string
591
+ * await solveGrasshopperDefinition(trees, 'UEsDBBQAAAAIAL...', config);
592
+ *
593
+ * // Using binary data
594
+ * const fileData = new Uint8Array([...]);
595
+ * await solveGrasshopperDefinition(trees, fileData, config);
596
+ */
597
+ declare function solveGrasshopperDefinition(dataTree: DataTree[], definition: string | Uint8Array, config: GrasshopperComputeConfig): Promise<GrasshopperComputeResponse>;
598
+
599
+ /**
600
+ * Fetches raw input/output schemas from a Grasshopper definition.
601
+ * Returns unprocessed data exactly as received from the Rhino Compute API (camelCased).
602
+ *
603
+ * @param definition - The Grasshopper definition (URL, base64 string, or Uint8Array)
604
+ * @param config - Compute configuration (server URL, API key, etc.)
605
+ * @returns Raw inputs and outputs with no type processing
606
+ * @throws {RhinoComputeError} If fetch fails or response is invalid
607
+ *
608
+ * @public Use `fetchParsedDefinitionIO()` for processed, type-safe inputs
609
+ */
610
+ declare function fetchDefinitionIO(definition: string | Uint8Array, config: ComputeConfig): Promise<GrasshopperParsedIORaw>;
611
+ /**
612
+ * Fetches and processes input/output schemas from a Grasshopper definition.
613
+ * Returns strongly-typed, validated input parameters ready for use.
614
+ *
615
+ * @public This is the recommended way to fetch definition I/O schemas.
616
+ *
617
+ * @param definition - The Grasshopper definition (URL, base64 string, or Uint8Array)
618
+ * @param config - Compute configuration (server URL, API key, etc.)
619
+ * @returns Processed inputs with discriminated union types and outputs
620
+ * @throws {RhinoComputeError} If fetch fails or response is invalid
621
+ *
622
+ * @example
623
+ * ```typescript
624
+ * const { inputs, outputs } = await fetchParsedDefinitionIO(
625
+ * 'https://example.com/definition.gh',
626
+ * { serverUrl: 'https://compute.rhino3d.com', apiKey: 'YOUR_KEY' }
627
+ * );
628
+ *
629
+ * // Inputs are now strongly typed
630
+ * inputs.forEach(input => {
631
+ * if (input.paramType === 'Number') {
632
+ * console.log(input.minimum, input.maximum); // TypeScript knows these exist
633
+ * }
634
+ * });
635
+ * ```
636
+ */
637
+ declare function fetchParsedDefinitionIO(definition: string | Uint8Array, config: ComputeConfig): Promise<GrasshopperParsedIO>;
638
+
639
+ /**
640
+ * Processes a raw input parameter schema and converts it into a typed InputParam object.
641
+ *
642
+ * @internal This is an internal processor. Use `fetchParsedDefinitionIO()` to get processed inputs instead.
643
+ *
644
+ * This function handles the transformation of raw input parameter data from Grasshopper into
645
+ * a structured, type-safe format. It performs validation, type-specific processing, and error
646
+ * handling for various parameter types including numeric, boolean, text, geometry, point, and line inputs.
647
+ *
648
+ * @param rawInput - The raw input parameter schema to process
649
+ * @returns A fully processed and typed InputParam object with appropriate type-specific properties
650
+ *
651
+ * @throws {RhinoComputeError} When an unknown paramType is encountered
652
+ * @throws {Error} Re-throws any non-RhinoComputeError exceptions
653
+ *
654
+ * @remarks
655
+ * The function performs the following operations:
656
+ * - Extracts base properties common to all input types
657
+ * - Preprocesses the raw input data
658
+ * - Applies type-specific validation and transformation
659
+ * - Handles errors gracefully by creating safe default values for validation errors
660
+ *
661
+ * Supported parameter types:
662
+ * - `Number` and `Integer`: Numeric inputs with optional min/max constraints
663
+ * - `Boolean`: Boolean flag inputs
664
+ * - `Text`: String inputs
665
+ * - `Geometry`: Generic geometry objects
666
+ * - `Point`: 3D point objects
667
+ * - `Line`: Line objects
668
+ *
669
+ * @example
670
+ * ```typescript
671
+ * const rawInput = {
672
+ * name: 'Length',
673
+ * paramType: 'Number',
674
+ * minimum: 0,
675
+ * maximum: 100,
676
+ * default: 50
677
+ * };
678
+ * const processedInput = processInput(rawInput);
679
+ * ```
680
+ */
681
+ declare function processInput(rawInput: InputParamSchema): InputParam;
682
+ /**
683
+ * Processes raw Grasshopper input schemas into strongly-typed TypeScript interfaces.
684
+ *
685
+ * @internal This is an internal batch processor. Use `fetchParsedDefinitionIO()` to get processed inputs instead.
686
+ *
687
+ * Transforms each raw input parameter by:
688
+ * - Normalizing default values (flattening data trees, parsing primitives)
689
+ * - Applying type-specific parsing (Number, Text, Boolean, Geometry, etc.)
690
+ * - Validating constraints (min/max, required fields)
691
+ * - Converting to discriminated union types for type safety
692
+ *
693
+ * @param rawInputs - Array of raw input schemas from Rhino Compute API
694
+ * @returns Array of processed, strongly-typed input parameters
695
+ *
696
+ * @remarks
697
+ * - Empty data trees are converted to `undefined`
698
+ * - Single values are extracted from arrays when appropriate
699
+ * - Tree structures are preserved for list/tree access parameters
700
+ * - Invalid inputs fall back to safe defaults with console warnings
701
+ *
702
+ * @example
703
+ * ```typescript
704
+ * const rawInputs = [
705
+ * { paramType: 'Number', name: 'radius', minimum: 0, default: 10 },
706
+ * { paramType: 'Text', name: 'label', default: 'Hello' }
707
+ * ];
708
+ *
709
+ * const processed = processInputs(rawInputs);
710
+ * // Result: [
711
+ * // { paramType: 'Number', name: 'radius', minimum: 0, default: 10, ... },
712
+ * // { paramType: 'Text', name: 'label', default: 'Hello', ... }
713
+ * // ]
714
+ *
715
+ * // Now type-safe:
716
+ * if (processed[0].paramType === 'Number') {
717
+ * console.log(processed[0].minimum); // TypeScript knows this exists
718
+ * }
719
+ * ```
720
+ *
721
+ * @see {@link processInput} for individual input processing logic
722
+ */
723
+ declare function processInputs(rawInputs: InputParamSchema[]): InputParam[];
724
+
725
+ /**
726
+ * Value types that can be stored in a DataTree
727
+ */
728
+ type DataTreeValue = string | number | boolean | object | null;
729
+ /**
730
+ * Simple data item for compute requests (not to be confused with DataItem interface for responses).
731
+ * Note: While TypeScript defines this as string, Rhino Compute accepts boolean/number primitives in JSON.
732
+ */
733
+ interface ComputeDataItem {
734
+ data: string | boolean | number;
735
+ }
736
+ /**
737
+ * InnerTree data structure for compute requests.
738
+ */
739
+ type ComputeInnerTreeData = {
740
+ [path in DataTreePath]: ComputeDataItem[];
741
+ };
742
+ /**
743
+ * Standalone TreeBuilder class for constructing Grasshopper TreeBuilder structures.
744
+ * Does not depend on RhinoCompute library.
745
+ *
746
+ * @example
747
+ * ```ts
748
+ * const tree = new TreeBuilder('MyParam')
749
+ * .append([0], [1, 2, 3])
750
+ * .append([1], [4, 5])
751
+ * .toComputeFormat();
752
+ * ```
753
+ */
754
+ declare class TreeBuilder {
755
+ private innerTree;
756
+ private paramName;
757
+ constructor(paramName: string);
758
+ /**
759
+ * Append values to a specific path in the tree.
760
+ *
761
+ * @param path - Array of integers representing the branch path (e.g., [0], [0, 1])
762
+ * @param items - Values to append at this path
763
+ * @returns this for method chaining
764
+ */
765
+ append(path: number[], items: DataTreeValue[]): this;
766
+ /**
767
+ * Append a single value to a path.
768
+ *
769
+ * @param path - Branch path
770
+ * @param item - Single value to append
771
+ * @returns this for method chaining
772
+ */
773
+ appendSingle(path: number[], item: DataTreeValue): this;
774
+ /**
775
+ * Set values from a DataTreeDefault structure.
776
+ * Replaces any existing tree data.
777
+ *
778
+ * @param treeData - TreeBuilder structure with path keys like "{0;1}"
779
+ * @returns this for method chaining
780
+ */
781
+ fromDataTreeDefault(treeData: DataTreeDefault): this;
782
+ /**
783
+ * Append flattened values to path [0].
784
+ * Useful for simple flat inputs.
785
+ *
786
+ * @param values - Single value or array of values
787
+ * @returns this for method chaining
788
+ */
789
+ appendFlat(values: DataTreeValue | DataTreeValue[]): this;
790
+ /**
791
+ * Get the flattened list of all values in the tree.
792
+ *
793
+ * @returns Array of all values across all branches
794
+ */
795
+ flatten(): DataTreeValue[];
796
+ /**
797
+ * Get all paths in the tree.
798
+ *
799
+ * @returns Array of path strings
800
+ */
801
+ getPaths(): DataTreePath[];
802
+ /**
803
+ * Get values at a specific path.
804
+ *
805
+ * @param path - Path to retrieve values from
806
+ * @returns Array of values or undefined if path doesn't exist
807
+ */
808
+ getPath(path: number[]): DataTreeValue[] | undefined;
809
+ /**
810
+ * Convert to format compatible with Grasshopper Compute API.
811
+ *
812
+ * @returns InnerTree object ready for compute
813
+ */
814
+ toComputeFormat(): DataTree;
815
+ /**
816
+ * Get the raw InnerTree data structure.
817
+ *
818
+ * @returns InnerTree data
819
+ */
820
+ getInnerTree(): ComputeInnerTreeData;
821
+ /**
822
+ * Get the parameter name.
823
+ *
824
+ * @returns Parameter name
825
+ */
826
+ getParamName(): string;
827
+ /**
828
+ * Create DataTrees from an array of InputParam definitions.
829
+ * Handles tree access, numeric constraints, and value parsing.
830
+ *
831
+ * @param inputs - Array of input parameter definitions
832
+ * @returns Array of InnerTree instances ready for compute
833
+ *
834
+ * @example
835
+ * ```ts
836
+ * const trees = TreeBuilder.fromInputParams(inputs);
837
+ * ```
838
+ */
839
+ static fromInputParams(inputs: InputParam[]): DataTree[];
840
+ /**
841
+ * Create a TreeBuilder from a single InputParam.
842
+ *
843
+ * @param input - Input parameter definition
844
+ * @returns InnerTree ready for compute or undefined if value is invalid
845
+ */
846
+ static fromInputParam(input: InputParam): DataTree | undefined;
847
+ /**
848
+ * Set or replace a parameter value within a TreeBuilder or InnerTree array.
849
+ *
850
+ * Supports both high-level `DataTree[]` instances and low-level `InnerTree[]` format.
851
+ *
852
+ * **Architecture Note:**
853
+ * - Use with `DataTree[]` when building/modifying before computation
854
+ * - Use with `InnerTree[]` when modifying compute API results
855
+ * - `DataTree` is the high-level builder; `InnerTree` is the Rhino Compute format
856
+ *
857
+ * @overload For TreeBuilder instances (high-level builder)
858
+ * @param trees - Array of TreeBuilder instances to modify
859
+ * @param paramName - The parameter name to set or replace
860
+ * @param newValue - The new value (scalar, array, or TreeBuilder structure)
861
+ * @returns A new/modified TreeBuilder array with the updated parameter
862
+ *
863
+ * @overload For compiled InnerTree (low-level API format)
864
+ * @param trees - The compiled InnerTree array (typically from `client.solve()`)
865
+ * @param paramName - The parameter name to set or replace
866
+ * @param newValue - The new value (scalar, array, or TreeBuilder structure)
867
+ * @returns A new/modified InnerTree array with the updated parameter
868
+ *
869
+ * @example
870
+ * ```ts
871
+ * // With TreeBuilder instances (high-level)
872
+ * let trees = [new TreeBuilder('X'), new TreeBuilder('Y')];
873
+ * trees = TreeBuilder.replaceTreeValue(trees, 'X', 42);
874
+ * const result = await client.solve(definitionUrl,
875
+ * trees.map(t => t.toComputeFormat())
876
+ * );
877
+ * ```
878
+ *
879
+ * @example
880
+ * ```ts
881
+ * // With InnerTree format (low-level, from API)
882
+ * let trees = await client.solve(definitionUrl, initialInputs);
883
+ * trees = TreeBuilder.replaceTreeValue(trees, 'X', 42);
884
+ * trees = TreeBuilder.replaceTreeValue(trees, 'Y', [1, 2, 3]);
885
+ * ```
886
+ */
887
+ static replaceTreeValue(trees: TreeBuilder[], paramName: string, newValue: DataTreeValue): TreeBuilder[];
888
+ static replaceTreeValue(trees: DataTree[], paramName: string, newValue: DataTreeValue): DataTree[];
889
+ /**
890
+ * Extract a value from a TreeBuilder or InnerTree array by parameter name.
891
+ *
892
+ * Automatically unwraps single values for convenience.
893
+ * Works with both high-level `DataTree[]` instances and low-level `InnerTree[]` format.
894
+ *
895
+ * **Architecture Note:**
896
+ * - Use with `DataTree[]` to read builder instances
897
+ * - Use with `InnerTree[]` to read compute API responses
898
+ * - Return behavior is consistent across both formats
899
+ *
900
+ * **Return Value Behavior:**
901
+ * - Single value → unwrapped (returns `5` not `[5]`)
902
+ * - Multiple values → array of values
903
+ * - Not found → `null`
904
+ *
905
+ * @overload For TreeBuilder instances
906
+ * @param trees - Array of TreeBuilder instances to read from
907
+ * @param paramName - The parameter name to retrieve
908
+ * @returns The unwrapped value, array of values, or null if parameter not found
909
+ *
910
+ * @overload For compiled InnerTree
911
+ * @param trees - The compiled InnerTree array (typically from `client.solve()`)
912
+ * @param paramName - The parameter name to retrieve
913
+ * @returns The unwrapped value, array of values, or null if parameter not found
914
+ *
915
+ * @example
916
+ * ```ts
917
+ * // With TreeBuilder instances
918
+ * const trees = [new TreeBuilder('X'), new TreeBuilder('Y')];
919
+ * trees[0].appendFlat(42);
920
+ * const x = TreeBuilder.getTreeValue(trees, 'X'); // Returns 42
921
+ * ```
922
+ *
923
+ * @example
924
+ * ```ts
925
+ * // With InnerTree from compute results
926
+ * const result = await client.solve(definitionUrl, inputs);
927
+ * const x = TreeBuilder.getTreeValue(result, 'X'); // Returns 42 (not [42])
928
+ * const points = TreeBuilder.getTreeValue(result, 'Points'); // Returns [point1, point2, ...]
929
+ * ```
930
+ */
931
+ static getTreeValue(trees: TreeBuilder[], paramName: string): DataTreeValue | null;
932
+ static getTreeValue(trees: DataTree[], paramName: string): DataTreeValue | null;
933
+ /**
934
+ * Parse a TreeBuilder path string like "{0;1;2}" into [0, 1, 2].
935
+ *
936
+ * @param pathStr - Path string
937
+ * @returns Array of path indices
938
+ */
939
+ static parsePathString(pathStr: string): number[];
940
+ /**
941
+ * Format a path array into TreeBuilder path string format.
942
+ *
943
+ * @param path - Path as number array
944
+ * @returns Formatted path string like "{0;1;2}"
945
+ */
946
+ static formatPathString(path: number[]): DataTreePath;
947
+ /**
948
+ * Apply numeric constraints to all tree values.
949
+ */
950
+ private applyNumericConstraints;
951
+ /**
952
+ * Serialize a value for compute requests.
953
+ * Preserves booleans and numbers as primitives for proper Grasshopper parameter handling.
954
+ */
955
+ private static serializeValue;
956
+ /**
957
+ * Deserialize a value back to its original type.
958
+ * Handles both string-encoded values and primitive values.
959
+ */
960
+ private static deserializeValue;
961
+ /**
962
+ * Check if a value is valid for inclusion in a DataTree.
963
+ */
964
+ private static hasValidValue;
965
+ /**
966
+ * Check if value is a TreeBuilder structure.
967
+ */
968
+ private static isDataTreeStructure;
969
+ /**
970
+ * Check if input is numeric type.
971
+ */
972
+ private static isNumericInput;
973
+ /**
974
+ * Process array of values based on input type.
975
+ */
976
+ private static processValues;
977
+ /**
978
+ * Clamp numeric value to constraints.
979
+ */
980
+ private static clampValue;
981
+ }
982
+
983
+ /**
984
+ * Extracts and processes files from compute response data without downloading them.
985
+ * Returns an array of ProcessedFile objects that can be used programmatically.
986
+ *
987
+ * @param downloadableFiles - An array of FileData items from the compute response.
988
+ * @param additionalFiles - Optional additional files to include (fetched from URLs).
989
+ * @returns A Promise resolving to an array of ProcessedFile objects.
990
+ * @throws Will throw an error if file processing fails.
991
+ *
992
+ * @example
993
+ * const files = await extractFilesFromComputeResponse(fileData);
994
+ * files.forEach(file => {
995
+ * console.log(`File: ${file.fileName}, Size: ${file.content.length}`);
996
+ * });
997
+ */
998
+ declare const extractFilesFromComputeResponse: (downloadableFiles: FileData[], additionalFiles?: FileBaseInfo[] | FileBaseInfo | null) => Promise<ProcessedFile[]>;
999
+ /**
1000
+ * Downloads files from a compute response as a ZIP archive.
1001
+ * Packages multiple files into a single ZIP file and triggers a browser download.
1002
+ *
1003
+ * @param downloadableFiles - An array of FileData items from the compute response.
1004
+ * @param additionalFiles - Optional additional files to include in the ZIP (fetched from URLs).
1005
+ * @param fileFoldername - The name of the ZIP file (without extension).
1006
+ * @throws Will throw an error if the file handling or download fails.
1007
+ *
1008
+ * @example
1009
+ * await downloadDataFromComputeResponse(fileData, null, 'my-export');
1010
+ * // Downloads 'my-export.zip'
1011
+ */
1012
+ declare const downloadFileData: (downloadableFiles: FileData[], fileFoldername: string, additionalFiles?: FileBaseInfo[] | FileBaseInfo | null) => Promise<void>;
1013
+
1014
+ export { type BooleanInputType, type CacheOptions, ComputeConfig, DataTree, DataTreeDefault, DataTreePath, type DataTreeValue, type DefaultValue, type FileBaseInfo, type FileData, type FileInputType, type GeometryInputType, type GetValuesOptions, type GetValuesResult, GrasshopperClient, GrasshopperComputeConfig, GrasshopperComputeResponse, type GrasshopperParsedIO, type GrasshopperParsedIORaw, GrasshopperResponseProcessor, type InputParam, InputParamSchema, type NumericInputType, OutputParamSchema, type OutputType, type ParsedContext, type ProcessedFile, RetryPolicy, RhinoComputeError, type SchedulerMode, type SolveContext, type SolveExecutor, type SolveOptions, type SolveResult, SolveScheduler, type SolveSchedulerOptions, type TextInputType, TreeBuilder, type ValueListInputType, downloadFileData, extractFilesFromComputeResponse, fetchDefinitionIO, fetchParsedDefinitionIO, hashSolveInput, processInput, processInputs, solveGrasshopperDefinition };