@selvajs/compute 1.5.3 → 2.0.0-beta.1
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/dist/chunk-3FH7FKLG.cjs +2 -0
- package/dist/chunk-3FH7FKLG.cjs.map +1 -0
- package/dist/chunk-DELOBV2Q.js +2 -0
- package/dist/chunk-DELOBV2Q.js.map +1 -0
- package/dist/chunk-GTTKNF4G.js +4 -0
- package/dist/chunk-GTTKNF4G.js.map +1 -0
- package/dist/chunk-JFLD2UCY.cjs +2 -0
- package/dist/chunk-JFLD2UCY.cjs.map +1 -0
- package/dist/chunk-MA6YB3YZ.cjs +4 -0
- package/dist/chunk-MA6YB3YZ.cjs.map +1 -0
- package/dist/chunk-MKW2KTPT.js +2 -0
- package/dist/chunk-MKW2KTPT.js.map +1 -0
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +10 -15
- package/dist/core.d.ts +10 -15
- package/dist/core.js +1 -1
- package/dist/grasshopper.cjs +1 -1
- package/dist/grasshopper.cjs.map +1 -1
- package/dist/grasshopper.d.cts +77 -101
- package/dist/grasshopper.d.ts +77 -101
- package/dist/grasshopper.js +1 -1
- package/dist/handle-files-DsrxHKHP.d.cts +262 -0
- package/dist/handle-files-DsrxHKHP.d.ts +262 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/{types-Dfeei0dD.d.cts → types-CJ092lxB.d.cts} +116 -73
- package/dist/types-D1SkNje_.d.cts +87 -0
- package/dist/types-D1SkNje_.d.ts +87 -0
- package/dist/{types-Dfeei0dD.d.ts → types-XCUrJGby.d.ts} +116 -73
- package/dist/visualization-GU7JIB4V.cjs +2 -0
- package/dist/visualization-GU7JIB4V.cjs.map +1 -0
- package/dist/visualization-WIUVT2FZ.js +2 -0
- package/dist/visualization.cjs +1 -1
- package/dist/visualization.cjs.map +1 -1
- package/dist/visualization.d.cts +16 -21
- package/dist/visualization.d.ts +16 -21
- package/dist/visualization.js +1 -1
- package/package.json +18 -7
- package/dist/chunk-GZYSQSLH.cjs +0 -2
- package/dist/chunk-GZYSQSLH.cjs.map +0 -1
- package/dist/chunk-JZYEMZZ5.js +0 -2
- package/dist/chunk-JZYEMZZ5.js.map +0 -1
- package/dist/chunk-OEDLGVIQ.js +0 -2
- package/dist/chunk-OEDLGVIQ.js.map +0 -1
- package/dist/chunk-OW6HV6QP.js +0 -2
- package/dist/chunk-OW6HV6QP.js.map +0 -1
- package/dist/chunk-RBNF6MNH.cjs +0 -3
- package/dist/chunk-RBNF6MNH.cjs.map +0 -1
- package/dist/chunk-SVEXPGHW.cjs +0 -2
- package/dist/chunk-SVEXPGHW.cjs.map +0 -1
- package/dist/chunk-XBIEAJBK.js +0 -3
- package/dist/chunk-XBIEAJBK.js.map +0 -1
- package/dist/chunk-ZRQRYG6F.cjs +0 -2
- package/dist/chunk-ZRQRYG6F.cjs.map +0 -1
- package/dist/errors-CEy4nM1J.d.cts +0 -149
- package/dist/errors-CEy4nM1J.d.ts +0 -149
- package/dist/types-COCuQEMk.d.cts +0 -93
- package/dist/types-COCuQEMk.d.ts +0 -93
- package/dist/visualization-ENMBHWIN.js +0 -2
- package/dist/visualization-TBPFFBFU.cjs +0 -2
- package/dist/visualization-TBPFFBFU.cjs.map +0 -1
- /package/dist/{visualization-ENMBHWIN.js.map → visualization-WIUVT2FZ.js.map} +0 -0
package/dist/grasshopper.d.cts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { R as RhinoComputeError, C as ComputeServerStats } from './
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { R as RhinoComputeError, C as ComputeServerStats, F as FileBaseInfo } from './handle-files-DsrxHKHP.cjs';
|
|
2
|
+
export { b as FileData, P as ProcessedFile, d as downloadFileData, e as extractFilesFromComputeResponse } from './handle-files-DsrxHKHP.cjs';
|
|
3
|
+
import { R as RetryPolicy, C as ComputeConfig } from './types-D1SkNje_.cjs';
|
|
4
|
+
export { a as RhinoModelUnit } from './types-D1SkNje_.cjs';
|
|
5
|
+
import { f as GrasshopperComputeResponse, a as DataTree, e as GrasshopperComputeConfig, g as GrasshopperParsedIO, h as GrasshopperParsedIORaw, M as MeshExtractionOptions, k as InputParamSchema, j as InputParam, b as DataTreeDefault, c as DataTreePath } from './types-CJ092lxB.cjs';
|
|
6
|
+
export { B as BooleanInputType, D as DataItem, d as DefaultValue, F as FileInputType, G as GeometryInputType, i as GrasshopperRequestSchema, I as InnerTreeData, N as NumericInputType, O as OutputParamSchema, l as OutputType, T as TextInputType, V as ValueListInputType } from './types-CJ092lxB.cjs';
|
|
4
7
|
import * as THREE from 'three';
|
|
5
|
-
import { M as MeshExtractionOptions } from './types-COCuQEMk.cjs';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Scheduling mode — controls how concurrent `solve()` calls interact.
|
|
@@ -28,6 +30,18 @@ interface SolveSchedulerOptions {
|
|
|
28
30
|
retry?: RetryPolicy;
|
|
29
31
|
/** Enable response caching keyed by hash of (definition, dataTree). */
|
|
30
32
|
cache?: boolean | CacheOptions;
|
|
33
|
+
/**
|
|
34
|
+
* Reuse the server's definition cache key so a large (base64/binary)
|
|
35
|
+
* definition is uploaded once and subsequent solves reference it by
|
|
36
|
+
* `pointer` instead of re-sending the full payload. Hugely cheaper for
|
|
37
|
+
* multi-MB definitions on a live UI (slider scrubs, etc.).
|
|
38
|
+
*
|
|
39
|
+
* Requires a `cacheKeyExecutor` to be supplied (the client wires one). Has no
|
|
40
|
+
* effect for URL-pointer definitions (already a reference). On a server-side
|
|
41
|
+
* cache miss the executor transparently falls back to a full upload, so this
|
|
42
|
+
* is safe to leave on. Default: `true` when a `cacheKeyExecutor` is present.
|
|
43
|
+
*/
|
|
44
|
+
reuseServerDefinitionCache?: boolean;
|
|
31
45
|
/** Lifecycle hooks — fired in order. Errors thrown by hooks are logged, not rethrown. */
|
|
32
46
|
onStart?: (ctx: SolveContext) => void;
|
|
33
47
|
onSettle?: (ctx: SolveContext, result: SolveResult) => void;
|
|
@@ -58,6 +72,22 @@ type SolveResult = {
|
|
|
58
72
|
* without a real Compute server, and decouples it from the client class.
|
|
59
73
|
*/
|
|
60
74
|
type SolveExecutor = (definition: string | Uint8Array, dataTree: DataTree[], config: GrasshopperComputeConfig) => Promise<GrasshopperComputeResponse>;
|
|
75
|
+
/**
|
|
76
|
+
* Cache-key-aware executor. When `cacheKey` is provided, the executor solves by
|
|
77
|
+
* reference (`pointer: cacheKey`) and falls back to a full upload on a server
|
|
78
|
+
* cache miss. Always reports the (possibly refreshed) `cacheKey` so the
|
|
79
|
+
* scheduler can update its definition→key map, plus whether the fast path
|
|
80
|
+
* `missed` (for telemetry). When `cacheKey` is null it's a first solve — upload
|
|
81
|
+
* fully and capture the key the server assigns.
|
|
82
|
+
*
|
|
83
|
+
* Supplied by the client (which owns the solve primitives); the scheduler stays
|
|
84
|
+
* decoupled from the transport.
|
|
85
|
+
*/
|
|
86
|
+
type CacheKeyExecutor = (definition: string | Uint8Array, dataTree: DataTree[], cacheKey: string | null, config: GrasshopperComputeConfig) => Promise<{
|
|
87
|
+
response: GrasshopperComputeResponse;
|
|
88
|
+
cacheKey: string | null;
|
|
89
|
+
missed: boolean;
|
|
90
|
+
}>;
|
|
61
91
|
/**
|
|
62
92
|
* Robust scheduler for Grasshopper solves.
|
|
63
93
|
*
|
|
@@ -100,6 +130,11 @@ declare class SolveScheduler {
|
|
|
100
130
|
private readonly cacheMax;
|
|
101
131
|
private readonly cacheTtl;
|
|
102
132
|
private readonly cache;
|
|
133
|
+
/** Optional cache-key-aware executor and whether server-def-cache reuse is on. */
|
|
134
|
+
private readonly cacheKeyExecutor?;
|
|
135
|
+
private readonly reuseServerDefinitionCache;
|
|
136
|
+
/** definition identity → server cache key (`pointer`) learned from past solves. */
|
|
137
|
+
private readonly serverCacheKeys;
|
|
103
138
|
private readonly onStart?;
|
|
104
139
|
private readonly onSettle?;
|
|
105
140
|
private readonly onSuperseded?;
|
|
@@ -111,7 +146,7 @@ declare class SolveScheduler {
|
|
|
111
146
|
private _lastError;
|
|
112
147
|
private _lastDurationMs;
|
|
113
148
|
private disposed;
|
|
114
|
-
constructor(executor: SolveExecutor, baseConfig: GrasshopperComputeConfig, options?: SolveSchedulerOptions);
|
|
149
|
+
constructor(executor: SolveExecutor, baseConfig: GrasshopperComputeConfig, options?: SolveSchedulerOptions, cacheKeyExecutor?: CacheKeyExecutor);
|
|
115
150
|
get isSolving(): boolean;
|
|
116
151
|
get hasPending(): boolean;
|
|
117
152
|
get inFlightCount(): number;
|
|
@@ -137,9 +172,36 @@ declare class SolveScheduler {
|
|
|
137
172
|
}): Promise<GrasshopperComputeResponse>;
|
|
138
173
|
private enqueue;
|
|
139
174
|
private execute;
|
|
175
|
+
/**
|
|
176
|
+
* Run the solve, using the server-definition-cache fast path when it's
|
|
177
|
+
* enabled and the definition is reusable. Learns/updates the definition's
|
|
178
|
+
* server cache key from the result so later solves can reference it.
|
|
179
|
+
*/
|
|
180
|
+
private runExecutor;
|
|
140
181
|
private drainNext;
|
|
141
182
|
private supersede;
|
|
142
183
|
private makeAbortError;
|
|
184
|
+
/**
|
|
185
|
+
* Settle a pending/in-flight item exactly once with an error.
|
|
186
|
+
*
|
|
187
|
+
* A solve promise can be settled from four concurrent sources — the executor
|
|
188
|
+
* resolving, the executor rejecting, `supersede`, and `cancelAll` — and a JS
|
|
189
|
+
* promise silently ignores a second settle. This guard is the single place the
|
|
190
|
+
* settle-once invariant lives: it makes the *first* settle win and reports
|
|
191
|
+
* whether this call was that winner, so callers fire their own hook only when
|
|
192
|
+
* they actually settled. Any new settle path must go through here (or
|
|
193
|
+
* {@link settleSuccess}) so the guard can't be forgotten.
|
|
194
|
+
*
|
|
195
|
+
* @returns `true` if this call settled the item; `false` if it was already settled.
|
|
196
|
+
*/
|
|
197
|
+
private settleError;
|
|
198
|
+
/**
|
|
199
|
+
* Settle a pending/in-flight item exactly once with a successful response.
|
|
200
|
+
* The success counterpart to {@link settleError}; see it for the invariant.
|
|
201
|
+
*
|
|
202
|
+
* @returns `true` if this call settled the item; `false` if it was already settled.
|
|
203
|
+
*/
|
|
204
|
+
private settleSuccess;
|
|
143
205
|
private isAbortLikeError;
|
|
144
206
|
private normalizeExecutionError;
|
|
145
207
|
/** Cancel everything — in-flight and pending. */
|
|
@@ -250,64 +312,6 @@ declare class GrasshopperClient {
|
|
|
250
312
|
private normalizeComputeConfig;
|
|
251
313
|
}
|
|
252
314
|
|
|
253
|
-
/**
|
|
254
|
-
* Represents raw file data from Grasshopper/Rhino Compute response.
|
|
255
|
-
*
|
|
256
|
-
* This type encapsulates file output from compute operations, with metadata
|
|
257
|
-
* for processing (decoding, naming, organization). Files are typically combined
|
|
258
|
-
* with additional files and packaged into a ZIP archive for download.
|
|
259
|
-
*
|
|
260
|
-
* @see {@link ProcessedFile} for the normalized format after processing
|
|
261
|
-
* @see {@link extractFilesFromComputeResponse} for extraction from compute responses
|
|
262
|
-
*/
|
|
263
|
-
type FileData = {
|
|
264
|
-
/** Base filename without extension (e.g., "model") */
|
|
265
|
-
fileName: string;
|
|
266
|
-
/** File content as a base64-encoded or plain string, depending on {@link IsBase64Encoded} */
|
|
267
|
-
data: string;
|
|
268
|
-
/** File extension including the dot (e.g., ".3dm", ".json"). Appended to {@link FileName} to create the full filename */
|
|
269
|
-
fileType: string;
|
|
270
|
-
/** 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 */
|
|
271
|
-
isBase64Encoded: boolean;
|
|
272
|
-
/** 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" */
|
|
273
|
-
subFolder: string;
|
|
274
|
-
};
|
|
275
|
-
/**
|
|
276
|
-
* Represents a normalized, processed file ready for consumption or archival.
|
|
277
|
-
*
|
|
278
|
-
* This is the unified intermediate format produced by processing both {@link FileData}
|
|
279
|
-
* and {@link FileBaseInfo}. Files in this format are ready to be packaged into archives
|
|
280
|
-
* (e.g., ZIP files) or returned to callers for programmatic use.
|
|
281
|
-
*
|
|
282
|
-
* @see {@link FileData} for raw compute response files
|
|
283
|
-
* @see {@link FileBaseInfo} for external file references
|
|
284
|
-
*/
|
|
285
|
-
type ProcessedFile = {
|
|
286
|
-
/** Full filename including extension (e.g., "model.3dm") */
|
|
287
|
-
fileName: string;
|
|
288
|
-
/** 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 */
|
|
289
|
-
content: Uint8Array | string;
|
|
290
|
-
/** File path for archive organization (e.g., "subfolder/model.3dm"). Used when creating ZIP archives or other hierarchical structures */
|
|
291
|
-
path: string;
|
|
292
|
-
};
|
|
293
|
-
/**
|
|
294
|
-
* Represents a reference to an external file to be included in file operations.
|
|
295
|
-
*
|
|
296
|
-
* This type is used to specify additional files (beyond compute response files)
|
|
297
|
-
* that should be fetched and included when processing files. The file is fetched
|
|
298
|
-
* from the provided URL and processed as a {@link ProcessedFile}.
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
* @see {@link FileData} for files from compute responses
|
|
302
|
-
* @see {@link processFiles} for how FileBaseInfo is processed (fetched and converted)
|
|
303
|
-
*/
|
|
304
|
-
type FileBaseInfo = {
|
|
305
|
-
/** Destination filename for the file in the archive or result set (e.g., "additional-data.json") */
|
|
306
|
-
fileName: string;
|
|
307
|
-
/** URL to fetch the file from. Must be accessible from the runtime environment */
|
|
308
|
-
filePath: string;
|
|
309
|
-
};
|
|
310
|
-
|
|
311
315
|
interface ParsedContext {
|
|
312
316
|
[key: string]: any;
|
|
313
317
|
}
|
|
@@ -423,7 +427,7 @@ declare class GrasshopperResponseProcessor {
|
|
|
423
427
|
* });
|
|
424
428
|
* ```
|
|
425
429
|
*/
|
|
426
|
-
extractMeshesFromResponse(options?: MeshExtractionOptions): Promise<THREE.Mesh<THREE.BufferGeometry<THREE.NormalBufferAttributes, THREE.BufferGeometryEventMap>, THREE.Material | THREE.Material[], THREE.Object3DEventMap>[]>;
|
|
430
|
+
extractMeshesFromResponse(options?: MeshExtractionOptions): Promise<THREE.Mesh<THREE.BufferGeometry<THREE.NormalBufferAttributes, THREE.BufferGeometryEventMap>, THREE.Material<THREE.MaterialEventMap> | THREE.Material<THREE.MaterialEventMap>[], THREE.Object3DEventMap>[]>;
|
|
427
431
|
/**
|
|
428
432
|
* Extract internal file data structures from the response.
|
|
429
433
|
* This includes Grasshopper-generated textures, JSON exports,
|
|
@@ -459,7 +463,14 @@ declare class GrasshopperResponseProcessor {
|
|
|
459
463
|
|
|
460
464
|
/**
|
|
461
465
|
* Hash definition and data tree into a stable cache key.
|
|
462
|
-
*
|
|
466
|
+
*
|
|
467
|
+
* The definition is the *identity* of what we solve, so a binary definition is
|
|
468
|
+
* hashed over its full content (`fnv1aBytes`) — a length-only or sampled key
|
|
469
|
+
* would let two different `.gh` files collide and serve one's cached solve for
|
|
470
|
+
* the other. `.gh` files are small enough that a single linear pass is
|
|
471
|
+
* negligible. (Note this differs from `stableStringify`'s sampled handling of a
|
|
472
|
+
* `Uint8Array` found *inside* the dataTree, where sampling is a deliberate
|
|
473
|
+
* per-solve perf tradeoff.)
|
|
463
474
|
*/
|
|
464
475
|
declare function hashSolveInput(definition: string | Uint8Array, dataTree: unknown): string;
|
|
465
476
|
|
|
@@ -872,10 +883,6 @@ declare class TreeBuilder {
|
|
|
872
883
|
* Check if a value is valid for inclusion in a DataTree.
|
|
873
884
|
*/
|
|
874
885
|
private static hasValidValue;
|
|
875
|
-
/**
|
|
876
|
-
* Check if value is a TreeBuilder structure.
|
|
877
|
-
*/
|
|
878
|
-
private static isDataTreeStructure;
|
|
879
886
|
/**
|
|
880
887
|
* Check if input is numeric type.
|
|
881
888
|
*/
|
|
@@ -890,35 +897,4 @@ declare class TreeBuilder {
|
|
|
890
897
|
private static clampValue;
|
|
891
898
|
}
|
|
892
899
|
|
|
893
|
-
|
|
894
|
-
* Extracts and processes files from compute response data without downloading them.
|
|
895
|
-
* Returns an array of ProcessedFile objects that can be used programmatically.
|
|
896
|
-
*
|
|
897
|
-
* @param downloadableFiles - An array of FileData items from the compute response.
|
|
898
|
-
* @param additionalFiles - Optional additional files to include (fetched from URLs).
|
|
899
|
-
* @returns A Promise resolving to an array of ProcessedFile objects.
|
|
900
|
-
* @throws Will throw an error if file processing fails.
|
|
901
|
-
*
|
|
902
|
-
* @example
|
|
903
|
-
* const files = await extractFilesFromComputeResponse(fileData);
|
|
904
|
-
* files.forEach(file => {
|
|
905
|
-
* console.log(`File: ${file.fileName}, Size: ${file.content.length}`);
|
|
906
|
-
* });
|
|
907
|
-
*/
|
|
908
|
-
declare const extractFilesFromComputeResponse: (downloadableFiles: FileData[], additionalFiles?: FileBaseInfo[] | FileBaseInfo | null) => Promise<ProcessedFile[]>;
|
|
909
|
-
/**
|
|
910
|
-
* Downloads files from a compute response as a ZIP archive.
|
|
911
|
-
* Packages multiple files into a single ZIP file and triggers a browser download.
|
|
912
|
-
*
|
|
913
|
-
* @param downloadableFiles - An array of FileData items from the compute response.
|
|
914
|
-
* @param additionalFiles - Optional additional files to include in the ZIP (fetched from URLs).
|
|
915
|
-
* @param fileFoldername - The name of the ZIP file (without extension).
|
|
916
|
-
* @throws Will throw an error if the file handling or download fails.
|
|
917
|
-
*
|
|
918
|
-
* @example
|
|
919
|
-
* await downloadDataFromComputeResponse(fileData, null, 'my-export');
|
|
920
|
-
* // Downloads 'my-export.zip'
|
|
921
|
-
*/
|
|
922
|
-
declare const downloadFileData: (downloadableFiles: FileData[], fileFoldername: string, additionalFiles?: FileBaseInfo[] | FileBaseInfo | null) => Promise<void>;
|
|
923
|
-
|
|
924
|
-
export { type CacheOptions, ComputeConfig, DataTree, DataTreeDefault, DataTreePath, type DataTreeValue, type FileBaseInfo, type FileData, type GetValuesOptions, type GetValuesResult, GrasshopperClient, GrasshopperComputeConfig, GrasshopperComputeResponse, GrasshopperParsedIO, GrasshopperParsedIORaw, GrasshopperResponseProcessor, InputParam, InputParamSchema, type ParsedContext, type ProcessedFile, RetryPolicy, RhinoComputeError, type SchedulerMode, type SolveContext, type SolveExecutor, type SolveOptions, type SolveResult, SolveScheduler, type SolveSchedulerOptions, TreeBuilder, downloadFileData, extractFilesFromComputeResponse, fetchDefinitionIO, fetchParsedDefinitionIO, hashSolveInput, processInput, processInputs, solveGrasshopperDefinition };
|
|
900
|
+
export { type CacheOptions, ComputeConfig, DataTree, DataTreeDefault, DataTreePath, type DataTreeValue, FileBaseInfo, type GetValuesOptions, type GetValuesResult, GrasshopperClient, GrasshopperComputeConfig, GrasshopperComputeResponse, GrasshopperParsedIO, GrasshopperParsedIORaw, GrasshopperResponseProcessor, InputParam, InputParamSchema, type ParsedContext, RetryPolicy, RhinoComputeError, type SchedulerMode, type SolveContext, type SolveExecutor, type SolveOptions, type SolveResult, SolveScheduler, type SolveSchedulerOptions, TreeBuilder, fetchDefinitionIO, fetchParsedDefinitionIO, hashSolveInput, processInput, processInputs, solveGrasshopperDefinition };
|
package/dist/grasshopper.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { R as RhinoComputeError, C as ComputeServerStats } from './
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { R as RhinoComputeError, C as ComputeServerStats, F as FileBaseInfo } from './handle-files-DsrxHKHP.js';
|
|
2
|
+
export { b as FileData, P as ProcessedFile, d as downloadFileData, e as extractFilesFromComputeResponse } from './handle-files-DsrxHKHP.js';
|
|
3
|
+
import { R as RetryPolicy, C as ComputeConfig } from './types-D1SkNje_.js';
|
|
4
|
+
export { a as RhinoModelUnit } from './types-D1SkNje_.js';
|
|
5
|
+
import { f as GrasshopperComputeResponse, a as DataTree, e as GrasshopperComputeConfig, g as GrasshopperParsedIO, h as GrasshopperParsedIORaw, M as MeshExtractionOptions, k as InputParamSchema, j as InputParam, b as DataTreeDefault, c as DataTreePath } from './types-XCUrJGby.js';
|
|
6
|
+
export { B as BooleanInputType, D as DataItem, d as DefaultValue, F as FileInputType, G as GeometryInputType, i as GrasshopperRequestSchema, I as InnerTreeData, N as NumericInputType, O as OutputParamSchema, l as OutputType, T as TextInputType, V as ValueListInputType } from './types-XCUrJGby.js';
|
|
4
7
|
import * as THREE from 'three';
|
|
5
|
-
import { M as MeshExtractionOptions } from './types-COCuQEMk.js';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Scheduling mode — controls how concurrent `solve()` calls interact.
|
|
@@ -28,6 +30,18 @@ interface SolveSchedulerOptions {
|
|
|
28
30
|
retry?: RetryPolicy;
|
|
29
31
|
/** Enable response caching keyed by hash of (definition, dataTree). */
|
|
30
32
|
cache?: boolean | CacheOptions;
|
|
33
|
+
/**
|
|
34
|
+
* Reuse the server's definition cache key so a large (base64/binary)
|
|
35
|
+
* definition is uploaded once and subsequent solves reference it by
|
|
36
|
+
* `pointer` instead of re-sending the full payload. Hugely cheaper for
|
|
37
|
+
* multi-MB definitions on a live UI (slider scrubs, etc.).
|
|
38
|
+
*
|
|
39
|
+
* Requires a `cacheKeyExecutor` to be supplied (the client wires one). Has no
|
|
40
|
+
* effect for URL-pointer definitions (already a reference). On a server-side
|
|
41
|
+
* cache miss the executor transparently falls back to a full upload, so this
|
|
42
|
+
* is safe to leave on. Default: `true` when a `cacheKeyExecutor` is present.
|
|
43
|
+
*/
|
|
44
|
+
reuseServerDefinitionCache?: boolean;
|
|
31
45
|
/** Lifecycle hooks — fired in order. Errors thrown by hooks are logged, not rethrown. */
|
|
32
46
|
onStart?: (ctx: SolveContext) => void;
|
|
33
47
|
onSettle?: (ctx: SolveContext, result: SolveResult) => void;
|
|
@@ -58,6 +72,22 @@ type SolveResult = {
|
|
|
58
72
|
* without a real Compute server, and decouples it from the client class.
|
|
59
73
|
*/
|
|
60
74
|
type SolveExecutor = (definition: string | Uint8Array, dataTree: DataTree[], config: GrasshopperComputeConfig) => Promise<GrasshopperComputeResponse>;
|
|
75
|
+
/**
|
|
76
|
+
* Cache-key-aware executor. When `cacheKey` is provided, the executor solves by
|
|
77
|
+
* reference (`pointer: cacheKey`) and falls back to a full upload on a server
|
|
78
|
+
* cache miss. Always reports the (possibly refreshed) `cacheKey` so the
|
|
79
|
+
* scheduler can update its definition→key map, plus whether the fast path
|
|
80
|
+
* `missed` (for telemetry). When `cacheKey` is null it's a first solve — upload
|
|
81
|
+
* fully and capture the key the server assigns.
|
|
82
|
+
*
|
|
83
|
+
* Supplied by the client (which owns the solve primitives); the scheduler stays
|
|
84
|
+
* decoupled from the transport.
|
|
85
|
+
*/
|
|
86
|
+
type CacheKeyExecutor = (definition: string | Uint8Array, dataTree: DataTree[], cacheKey: string | null, config: GrasshopperComputeConfig) => Promise<{
|
|
87
|
+
response: GrasshopperComputeResponse;
|
|
88
|
+
cacheKey: string | null;
|
|
89
|
+
missed: boolean;
|
|
90
|
+
}>;
|
|
61
91
|
/**
|
|
62
92
|
* Robust scheduler for Grasshopper solves.
|
|
63
93
|
*
|
|
@@ -100,6 +130,11 @@ declare class SolveScheduler {
|
|
|
100
130
|
private readonly cacheMax;
|
|
101
131
|
private readonly cacheTtl;
|
|
102
132
|
private readonly cache;
|
|
133
|
+
/** Optional cache-key-aware executor and whether server-def-cache reuse is on. */
|
|
134
|
+
private readonly cacheKeyExecutor?;
|
|
135
|
+
private readonly reuseServerDefinitionCache;
|
|
136
|
+
/** definition identity → server cache key (`pointer`) learned from past solves. */
|
|
137
|
+
private readonly serverCacheKeys;
|
|
103
138
|
private readonly onStart?;
|
|
104
139
|
private readonly onSettle?;
|
|
105
140
|
private readonly onSuperseded?;
|
|
@@ -111,7 +146,7 @@ declare class SolveScheduler {
|
|
|
111
146
|
private _lastError;
|
|
112
147
|
private _lastDurationMs;
|
|
113
148
|
private disposed;
|
|
114
|
-
constructor(executor: SolveExecutor, baseConfig: GrasshopperComputeConfig, options?: SolveSchedulerOptions);
|
|
149
|
+
constructor(executor: SolveExecutor, baseConfig: GrasshopperComputeConfig, options?: SolveSchedulerOptions, cacheKeyExecutor?: CacheKeyExecutor);
|
|
115
150
|
get isSolving(): boolean;
|
|
116
151
|
get hasPending(): boolean;
|
|
117
152
|
get inFlightCount(): number;
|
|
@@ -137,9 +172,36 @@ declare class SolveScheduler {
|
|
|
137
172
|
}): Promise<GrasshopperComputeResponse>;
|
|
138
173
|
private enqueue;
|
|
139
174
|
private execute;
|
|
175
|
+
/**
|
|
176
|
+
* Run the solve, using the server-definition-cache fast path when it's
|
|
177
|
+
* enabled and the definition is reusable. Learns/updates the definition's
|
|
178
|
+
* server cache key from the result so later solves can reference it.
|
|
179
|
+
*/
|
|
180
|
+
private runExecutor;
|
|
140
181
|
private drainNext;
|
|
141
182
|
private supersede;
|
|
142
183
|
private makeAbortError;
|
|
184
|
+
/**
|
|
185
|
+
* Settle a pending/in-flight item exactly once with an error.
|
|
186
|
+
*
|
|
187
|
+
* A solve promise can be settled from four concurrent sources — the executor
|
|
188
|
+
* resolving, the executor rejecting, `supersede`, and `cancelAll` — and a JS
|
|
189
|
+
* promise silently ignores a second settle. This guard is the single place the
|
|
190
|
+
* settle-once invariant lives: it makes the *first* settle win and reports
|
|
191
|
+
* whether this call was that winner, so callers fire their own hook only when
|
|
192
|
+
* they actually settled. Any new settle path must go through here (or
|
|
193
|
+
* {@link settleSuccess}) so the guard can't be forgotten.
|
|
194
|
+
*
|
|
195
|
+
* @returns `true` if this call settled the item; `false` if it was already settled.
|
|
196
|
+
*/
|
|
197
|
+
private settleError;
|
|
198
|
+
/**
|
|
199
|
+
* Settle a pending/in-flight item exactly once with a successful response.
|
|
200
|
+
* The success counterpart to {@link settleError}; see it for the invariant.
|
|
201
|
+
*
|
|
202
|
+
* @returns `true` if this call settled the item; `false` if it was already settled.
|
|
203
|
+
*/
|
|
204
|
+
private settleSuccess;
|
|
143
205
|
private isAbortLikeError;
|
|
144
206
|
private normalizeExecutionError;
|
|
145
207
|
/** Cancel everything — in-flight and pending. */
|
|
@@ -250,64 +312,6 @@ declare class GrasshopperClient {
|
|
|
250
312
|
private normalizeComputeConfig;
|
|
251
313
|
}
|
|
252
314
|
|
|
253
|
-
/**
|
|
254
|
-
* Represents raw file data from Grasshopper/Rhino Compute response.
|
|
255
|
-
*
|
|
256
|
-
* This type encapsulates file output from compute operations, with metadata
|
|
257
|
-
* for processing (decoding, naming, organization). Files are typically combined
|
|
258
|
-
* with additional files and packaged into a ZIP archive for download.
|
|
259
|
-
*
|
|
260
|
-
* @see {@link ProcessedFile} for the normalized format after processing
|
|
261
|
-
* @see {@link extractFilesFromComputeResponse} for extraction from compute responses
|
|
262
|
-
*/
|
|
263
|
-
type FileData = {
|
|
264
|
-
/** Base filename without extension (e.g., "model") */
|
|
265
|
-
fileName: string;
|
|
266
|
-
/** File content as a base64-encoded or plain string, depending on {@link IsBase64Encoded} */
|
|
267
|
-
data: string;
|
|
268
|
-
/** File extension including the dot (e.g., ".3dm", ".json"). Appended to {@link FileName} to create the full filename */
|
|
269
|
-
fileType: string;
|
|
270
|
-
/** 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 */
|
|
271
|
-
isBase64Encoded: boolean;
|
|
272
|
-
/** 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" */
|
|
273
|
-
subFolder: string;
|
|
274
|
-
};
|
|
275
|
-
/**
|
|
276
|
-
* Represents a normalized, processed file ready for consumption or archival.
|
|
277
|
-
*
|
|
278
|
-
* This is the unified intermediate format produced by processing both {@link FileData}
|
|
279
|
-
* and {@link FileBaseInfo}. Files in this format are ready to be packaged into archives
|
|
280
|
-
* (e.g., ZIP files) or returned to callers for programmatic use.
|
|
281
|
-
*
|
|
282
|
-
* @see {@link FileData} for raw compute response files
|
|
283
|
-
* @see {@link FileBaseInfo} for external file references
|
|
284
|
-
*/
|
|
285
|
-
type ProcessedFile = {
|
|
286
|
-
/** Full filename including extension (e.g., "model.3dm") */
|
|
287
|
-
fileName: string;
|
|
288
|
-
/** 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 */
|
|
289
|
-
content: Uint8Array | string;
|
|
290
|
-
/** File path for archive organization (e.g., "subfolder/model.3dm"). Used when creating ZIP archives or other hierarchical structures */
|
|
291
|
-
path: string;
|
|
292
|
-
};
|
|
293
|
-
/**
|
|
294
|
-
* Represents a reference to an external file to be included in file operations.
|
|
295
|
-
*
|
|
296
|
-
* This type is used to specify additional files (beyond compute response files)
|
|
297
|
-
* that should be fetched and included when processing files. The file is fetched
|
|
298
|
-
* from the provided URL and processed as a {@link ProcessedFile}.
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
* @see {@link FileData} for files from compute responses
|
|
302
|
-
* @see {@link processFiles} for how FileBaseInfo is processed (fetched and converted)
|
|
303
|
-
*/
|
|
304
|
-
type FileBaseInfo = {
|
|
305
|
-
/** Destination filename for the file in the archive or result set (e.g., "additional-data.json") */
|
|
306
|
-
fileName: string;
|
|
307
|
-
/** URL to fetch the file from. Must be accessible from the runtime environment */
|
|
308
|
-
filePath: string;
|
|
309
|
-
};
|
|
310
|
-
|
|
311
315
|
interface ParsedContext {
|
|
312
316
|
[key: string]: any;
|
|
313
317
|
}
|
|
@@ -423,7 +427,7 @@ declare class GrasshopperResponseProcessor {
|
|
|
423
427
|
* });
|
|
424
428
|
* ```
|
|
425
429
|
*/
|
|
426
|
-
extractMeshesFromResponse(options?: MeshExtractionOptions): Promise<THREE.Mesh<THREE.BufferGeometry<THREE.NormalBufferAttributes, THREE.BufferGeometryEventMap>, THREE.Material | THREE.Material[], THREE.Object3DEventMap>[]>;
|
|
430
|
+
extractMeshesFromResponse(options?: MeshExtractionOptions): Promise<THREE.Mesh<THREE.BufferGeometry<THREE.NormalBufferAttributes, THREE.BufferGeometryEventMap>, THREE.Material<THREE.MaterialEventMap> | THREE.Material<THREE.MaterialEventMap>[], THREE.Object3DEventMap>[]>;
|
|
427
431
|
/**
|
|
428
432
|
* Extract internal file data structures from the response.
|
|
429
433
|
* This includes Grasshopper-generated textures, JSON exports,
|
|
@@ -459,7 +463,14 @@ declare class GrasshopperResponseProcessor {
|
|
|
459
463
|
|
|
460
464
|
/**
|
|
461
465
|
* Hash definition and data tree into a stable cache key.
|
|
462
|
-
*
|
|
466
|
+
*
|
|
467
|
+
* The definition is the *identity* of what we solve, so a binary definition is
|
|
468
|
+
* hashed over its full content (`fnv1aBytes`) — a length-only or sampled key
|
|
469
|
+
* would let two different `.gh` files collide and serve one's cached solve for
|
|
470
|
+
* the other. `.gh` files are small enough that a single linear pass is
|
|
471
|
+
* negligible. (Note this differs from `stableStringify`'s sampled handling of a
|
|
472
|
+
* `Uint8Array` found *inside* the dataTree, where sampling is a deliberate
|
|
473
|
+
* per-solve perf tradeoff.)
|
|
463
474
|
*/
|
|
464
475
|
declare function hashSolveInput(definition: string | Uint8Array, dataTree: unknown): string;
|
|
465
476
|
|
|
@@ -872,10 +883,6 @@ declare class TreeBuilder {
|
|
|
872
883
|
* Check if a value is valid for inclusion in a DataTree.
|
|
873
884
|
*/
|
|
874
885
|
private static hasValidValue;
|
|
875
|
-
/**
|
|
876
|
-
* Check if value is a TreeBuilder structure.
|
|
877
|
-
*/
|
|
878
|
-
private static isDataTreeStructure;
|
|
879
886
|
/**
|
|
880
887
|
* Check if input is numeric type.
|
|
881
888
|
*/
|
|
@@ -890,35 +897,4 @@ declare class TreeBuilder {
|
|
|
890
897
|
private static clampValue;
|
|
891
898
|
}
|
|
892
899
|
|
|
893
|
-
|
|
894
|
-
* Extracts and processes files from compute response data without downloading them.
|
|
895
|
-
* Returns an array of ProcessedFile objects that can be used programmatically.
|
|
896
|
-
*
|
|
897
|
-
* @param downloadableFiles - An array of FileData items from the compute response.
|
|
898
|
-
* @param additionalFiles - Optional additional files to include (fetched from URLs).
|
|
899
|
-
* @returns A Promise resolving to an array of ProcessedFile objects.
|
|
900
|
-
* @throws Will throw an error if file processing fails.
|
|
901
|
-
*
|
|
902
|
-
* @example
|
|
903
|
-
* const files = await extractFilesFromComputeResponse(fileData);
|
|
904
|
-
* files.forEach(file => {
|
|
905
|
-
* console.log(`File: ${file.fileName}, Size: ${file.content.length}`);
|
|
906
|
-
* });
|
|
907
|
-
*/
|
|
908
|
-
declare const extractFilesFromComputeResponse: (downloadableFiles: FileData[], additionalFiles?: FileBaseInfo[] | FileBaseInfo | null) => Promise<ProcessedFile[]>;
|
|
909
|
-
/**
|
|
910
|
-
* Downloads files from a compute response as a ZIP archive.
|
|
911
|
-
* Packages multiple files into a single ZIP file and triggers a browser download.
|
|
912
|
-
*
|
|
913
|
-
* @param downloadableFiles - An array of FileData items from the compute response.
|
|
914
|
-
* @param additionalFiles - Optional additional files to include in the ZIP (fetched from URLs).
|
|
915
|
-
* @param fileFoldername - The name of the ZIP file (without extension).
|
|
916
|
-
* @throws Will throw an error if the file handling or download fails.
|
|
917
|
-
*
|
|
918
|
-
* @example
|
|
919
|
-
* await downloadDataFromComputeResponse(fileData, null, 'my-export');
|
|
920
|
-
* // Downloads 'my-export.zip'
|
|
921
|
-
*/
|
|
922
|
-
declare const downloadFileData: (downloadableFiles: FileData[], fileFoldername: string, additionalFiles?: FileBaseInfo[] | FileBaseInfo | null) => Promise<void>;
|
|
923
|
-
|
|
924
|
-
export { type CacheOptions, ComputeConfig, DataTree, DataTreeDefault, DataTreePath, type DataTreeValue, type FileBaseInfo, type FileData, type GetValuesOptions, type GetValuesResult, GrasshopperClient, GrasshopperComputeConfig, GrasshopperComputeResponse, GrasshopperParsedIO, GrasshopperParsedIORaw, GrasshopperResponseProcessor, InputParam, InputParamSchema, type ParsedContext, type ProcessedFile, RetryPolicy, RhinoComputeError, type SchedulerMode, type SolveContext, type SolveExecutor, type SolveOptions, type SolveResult, SolveScheduler, type SolveSchedulerOptions, TreeBuilder, downloadFileData, extractFilesFromComputeResponse, fetchDefinitionIO, fetchParsedDefinitionIO, hashSolveInput, processInput, processInputs, solveGrasshopperDefinition };
|
|
900
|
+
export { type CacheOptions, ComputeConfig, DataTree, DataTreeDefault, DataTreePath, type DataTreeValue, FileBaseInfo, type GetValuesOptions, type GetValuesResult, GrasshopperClient, GrasshopperComputeConfig, GrasshopperComputeResponse, GrasshopperParsedIO, GrasshopperParsedIORaw, GrasshopperResponseProcessor, InputParam, InputParamSchema, type ParsedContext, RetryPolicy, RhinoComputeError, type SchedulerMode, type SolveContext, type SolveExecutor, type SolveOptions, type SolveResult, SolveScheduler, type SolveSchedulerOptions, TreeBuilder, fetchDefinitionIO, fetchParsedDefinitionIO, hashSolveInput, processInput, processInputs, solveGrasshopperDefinition };
|
package/dist/grasshopper.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as d,b as e,c as f,d as g,e as h,f as i,g as j,h as k,i as l,j as m}from"./chunk-DELOBV2Q.js";import{d as a,q as b,r as c}from"./chunk-GTTKNF4G.js";export{g as GrasshopperClient,h as GrasshopperResponseProcessor,a as RhinoComputeError,f as SolveScheduler,m as TreeBuilder,c as downloadFileData,b as extractFilesFromComputeResponse,k as fetchDefinitionIO,l as fetchParsedDefinitionIO,e as hashSolveInput,i as processInput,j as processInputs,d as solveGrasshopperDefinition};
|
|
2
2
|
//# sourceMappingURL=grasshopper.js.map
|