@selvajs/compute 1.5.1 → 1.5.2-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/README.md +12 -8
- package/dist/chunk-2D74PNQU.cjs +2 -0
- package/dist/chunk-2D74PNQU.cjs.map +1 -0
- package/dist/chunk-5465MDT4.cjs +2 -0
- package/dist/chunk-5465MDT4.cjs.map +1 -0
- package/dist/chunk-DADFXYBV.js +2 -0
- package/dist/chunk-DADFXYBV.js.map +1 -0
- package/dist/chunk-MZGKJZVP.cjs +2 -0
- package/dist/chunk-MZGKJZVP.cjs.map +1 -0
- package/dist/chunk-RHULSS7S.js +3 -0
- package/dist/chunk-RHULSS7S.js.map +1 -0
- package/dist/chunk-VWOEUM7C.cjs +3 -0
- package/dist/chunk-VWOEUM7C.cjs.map +1 -0
- package/dist/chunk-XIBQV4XW.js +2 -0
- package/dist/chunk-XIBQV4XW.js.map +1 -0
- package/dist/chunk-XLHA5YPH.js +2 -0
- package/dist/chunk-XLHA5YPH.js.map +1 -0
- package/dist/core.cjs +1 -1
- package/dist/core.d.cts +3 -21
- package/dist/core.d.ts +3 -21
- package/dist/core.js +1 -1
- package/dist/errors-CiA83qw2.d.cts +510 -0
- package/dist/errors-CiA83qw2.d.ts +510 -0
- package/dist/grasshopper.cjs +1 -1
- package/dist/grasshopper.d.cts +75 -142
- package/dist/grasshopper.d.ts +75 -142
- package/dist/grasshopper.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -5
- package/dist/index.d.ts +3 -5
- package/dist/index.js +1 -1
- package/dist/visualization-3HFOMXUY.cjs +2 -0
- package/dist/visualization-3HFOMXUY.cjs.map +1 -0
- package/dist/visualization-XXHESVUI.js +2 -0
- package/dist/visualization-XXHESVUI.js.map +1 -0
- package/dist/visualization.cjs +1 -1
- package/dist/visualization.cjs.map +1 -1
- package/dist/visualization.d.cts +1 -76
- package/dist/visualization.d.ts +1 -76
- package/dist/visualization.js +1 -1
- package/dist/visualization.js.map +1 -1
- package/package.json +1 -1
- package/LICENSE.md +0 -21
- package/dist/base-dtik4Dlu.d.cts +0 -138
- package/dist/base-dtik4Dlu.d.ts +0 -138
- package/dist/chunk-FRSLCR7G.cjs +0 -2
- package/dist/chunk-FRSLCR7G.cjs.map +0 -1
- package/dist/chunk-IJZNCO5X.cjs +0 -3
- package/dist/chunk-IJZNCO5X.cjs.map +0 -1
- package/dist/chunk-LNIUUPA5.cjs +0 -2
- package/dist/chunk-LNIUUPA5.cjs.map +0 -1
- package/dist/chunk-PZ4HZLFJ.js +0 -2
- package/dist/chunk-PZ4HZLFJ.js.map +0 -1
- package/dist/chunk-VK2TSW7S.js +0 -3
- package/dist/chunk-VK2TSW7S.js.map +0 -1
- package/dist/chunk-WXQGTKU6.js +0 -2
- package/dist/chunk-WXQGTKU6.js.map +0 -1
- package/dist/schemas-Ct7lU-IH.d.cts +0 -247
- package/dist/schemas-Ct7lU-IH.d.ts +0 -247
- package/dist/types-B24K2LG4.d.cts +0 -85
- package/dist/types-B24K2LG4.d.ts +0 -85
package/dist/base-dtik4Dlu.d.ts
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ComputeServerStats provides methods to query Rhino Compute server statistics.
|
|
3
|
-
*
|
|
4
|
-
* @public Use this for server health monitoring and statistics.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* const stats = new ComputeServerStats('http://localhost:6500', 'your-api-key');
|
|
9
|
-
*
|
|
10
|
-
* try {
|
|
11
|
-
* const isOnline = await stats.isServerOnline();
|
|
12
|
-
* const children = await stats.getActiveChildren();
|
|
13
|
-
* const version = await stats.getVersion();
|
|
14
|
-
*
|
|
15
|
-
* // Or get everything at once
|
|
16
|
-
* const allStats = await stats.getServerStats();
|
|
17
|
-
* } finally {
|
|
18
|
-
* await stats.dispose(); // Clean up resources
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
declare class ComputeServerStats {
|
|
23
|
-
private readonly serverUrl;
|
|
24
|
-
private readonly apiKey?;
|
|
25
|
-
private disposed;
|
|
26
|
-
private activeMonitors;
|
|
27
|
-
private activeTimeouts;
|
|
28
|
-
/**
|
|
29
|
-
* @param serverUrl - Base URL of the Rhino Compute server with http:// or https:// scheme (e.g., 'http://localhost:6500')
|
|
30
|
-
* @param apiKey - Optional API key for authentication
|
|
31
|
-
*/
|
|
32
|
-
constructor(serverUrl: string, apiKey?: string);
|
|
33
|
-
/**
|
|
34
|
-
* Build request headers with optional API key.
|
|
35
|
-
*/
|
|
36
|
-
private buildHeaders;
|
|
37
|
-
/**
|
|
38
|
-
* Check if the server is online.
|
|
39
|
-
*/
|
|
40
|
-
isServerOnline(): Promise<boolean>;
|
|
41
|
-
/**
|
|
42
|
-
* Get the number of active child processes on the server.
|
|
43
|
-
*
|
|
44
|
-
* @returns Number of active children, or null if unavailable
|
|
45
|
-
*/
|
|
46
|
-
getActiveChildren(): Promise<number | null>;
|
|
47
|
-
/**
|
|
48
|
-
* Get the server version information.
|
|
49
|
-
*
|
|
50
|
-
* @returns Version object with rhino, compute, and git_sha, or null if unavailable
|
|
51
|
-
*/
|
|
52
|
-
getVersion(): Promise<{
|
|
53
|
-
rhino: string;
|
|
54
|
-
compute: string;
|
|
55
|
-
git_sha: string | null;
|
|
56
|
-
} | null>;
|
|
57
|
-
/**
|
|
58
|
-
* Get comprehensive server statistics.
|
|
59
|
-
* Fetches all available server information in parallel.
|
|
60
|
-
*
|
|
61
|
-
* @returns Object containing server status and available stats
|
|
62
|
-
*/
|
|
63
|
-
getServerStats(): Promise<{
|
|
64
|
-
isOnline: boolean;
|
|
65
|
-
version?: {
|
|
66
|
-
rhino: string;
|
|
67
|
-
compute: string;
|
|
68
|
-
git_sha: string | null;
|
|
69
|
-
};
|
|
70
|
-
activeChildren?: number;
|
|
71
|
-
}>;
|
|
72
|
-
/**
|
|
73
|
-
* Continuously monitor server stats at specified interval.
|
|
74
|
-
*
|
|
75
|
-
* @param callback - Function called with stats on each interval
|
|
76
|
-
* @param intervalMs - Milliseconds between checks (default: 5000)
|
|
77
|
-
* @returns Function to stop monitoring
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```typescript
|
|
81
|
-
* const stopMonitoring = stats.monitor((data) => {
|
|
82
|
-
* console.log('Server stats:', data);
|
|
83
|
-
* }, 3000);
|
|
84
|
-
*
|
|
85
|
-
* // Later...
|
|
86
|
-
* stopMonitoring();
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
|
-
monitor(callback: (stats: Awaited<ReturnType<typeof this.getServerStats>>) => void, intervalMs?: number): () => void;
|
|
90
|
-
/**
|
|
91
|
-
* Disposes of all resources and stops all active monitors.
|
|
92
|
-
* Call this when you're done using the stats instance.
|
|
93
|
-
*/
|
|
94
|
-
dispose(): Promise<void>;
|
|
95
|
-
/**
|
|
96
|
-
* Ensures the instance hasn't been disposed.
|
|
97
|
-
*/
|
|
98
|
-
private ensureNotDisposed;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Simplified error for Rhino Compute operations
|
|
103
|
-
*
|
|
104
|
-
* @public Use this for error handling with error codes and context.
|
|
105
|
-
*/
|
|
106
|
-
declare class RhinoComputeError extends Error {
|
|
107
|
-
readonly code: string;
|
|
108
|
-
readonly statusCode?: number;
|
|
109
|
-
readonly context?: Record<string, unknown>;
|
|
110
|
-
readonly originalError?: Error;
|
|
111
|
-
constructor(message: string, code?: string, options?: {
|
|
112
|
-
statusCode?: number;
|
|
113
|
-
context?: Record<string, unknown>;
|
|
114
|
-
originalError?: Error;
|
|
115
|
-
});
|
|
116
|
-
/**
|
|
117
|
-
* Create a generic validation error with custom reason
|
|
118
|
-
*/
|
|
119
|
-
static validation(inputName: string, reason: string, context?: Record<string, unknown>): RhinoComputeError;
|
|
120
|
-
/**
|
|
121
|
-
* Create an error for missing/empty values
|
|
122
|
-
*/
|
|
123
|
-
static missingValues(inputName: string, expectedType?: string, context?: Record<string, unknown>): RhinoComputeError;
|
|
124
|
-
/**
|
|
125
|
-
* Create an error for invalid default value in value list
|
|
126
|
-
*/
|
|
127
|
-
static invalidDefault(inputName: string, defaultValue: unknown, availableValues: unknown[], context?: Record<string, unknown>): RhinoComputeError;
|
|
128
|
-
/**
|
|
129
|
-
* Create an error for unknown parameter type
|
|
130
|
-
*/
|
|
131
|
-
static unknownParamType(paramType: string, paramName?: string, context?: Record<string, unknown>): RhinoComputeError;
|
|
132
|
-
/**
|
|
133
|
-
* Create an error for invalid input structure
|
|
134
|
-
*/
|
|
135
|
-
static invalidStructure(inputName: string, expectedStructure: string, context?: Record<string, unknown>): RhinoComputeError;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export { ComputeServerStats as C, RhinoComputeError as R };
|
package/dist/chunk-FRSLCR7G.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkLNIUUPA5cjs = require('./chunk-LNIUUPA5.cjs');var _chunkIJZNCO5Xcjs = require('./chunk-IJZNCO5X.cjs');function L(t){let e=new WeakSet,r=n=>{if(n==null)return JSON.stringify(n);if(typeof n=="number")return Number.isFinite(n)?String(n):JSON.stringify(null);if(typeof n=="string"||typeof n=="boolean")return JSON.stringify(n);if(typeof n=="bigint")return JSON.stringify(n.toString());if(n instanceof Uint8Array){let o=n.length>64?Array.from(n.slice(0,32)).concat(Array.from(n.slice(-32))):Array.from(n);return JSON.stringify({__u8:!0,len:n.length,sample:o})}return Array.isArray(n)?`[${n.map(r).join(",")}]`:typeof n=="object"?e.has(n)?JSON.stringify("[Circular]"):(e.add(n),`{${Object.keys(n).sort().map(a=>`${JSON.stringify(a)}:${r(n[a])}`).join(",")}}`):JSON.stringify(null)};return r(t)}function J(t){let e=2166136261;for(let r=0;r<t.length;r++)e^=t.charCodeAt(r),e=e+((e<<1)+(e<<4)+(e<<7)+(e<<8)+(e<<24))>>>0;return e.toString(16).padStart(8,"0")}function v(t,e){let r=typeof t=="string"?t:L({__u8:!0,len:t.length});return J(`${r}|${L(e)}`)}var h=class{constructor(e,r,n={}){_chunkIJZNCO5Xcjs.b.call(void 0, this,"executor");_chunkIJZNCO5Xcjs.b.call(void 0, this,"baseConfig");_chunkIJZNCO5Xcjs.b.call(void 0, this,"mode");_chunkIJZNCO5Xcjs.b.call(void 0, this,"maxConcurrent");_chunkIJZNCO5Xcjs.b.call(void 0, this,"timeoutMs");_chunkIJZNCO5Xcjs.b.call(void 0, this,"retry");_chunkIJZNCO5Xcjs.b.call(void 0, this,"cacheEnabled");_chunkIJZNCO5Xcjs.b.call(void 0, this,"cacheMax");_chunkIJZNCO5Xcjs.b.call(void 0, this,"cacheTtl");_chunkIJZNCO5Xcjs.b.call(void 0, this,"cache",new Map);_chunkIJZNCO5Xcjs.b.call(void 0, this,"onStart");_chunkIJZNCO5Xcjs.b.call(void 0, this,"onSettle");_chunkIJZNCO5Xcjs.b.call(void 0, this,"onSuperseded");_chunkIJZNCO5Xcjs.b.call(void 0, this,"subscribers",new Set);_chunkIJZNCO5Xcjs.b.call(void 0, this,"inFlight",new Set);_chunkIJZNCO5Xcjs.b.call(void 0, this,"pendingForLatestWins",null);_chunkIJZNCO5Xcjs.b.call(void 0, this,"fifoQueue",[]);_chunkIJZNCO5Xcjs.b.call(void 0, this,"_lastResult",null);_chunkIJZNCO5Xcjs.b.call(void 0, this,"_lastError",null);_chunkIJZNCO5Xcjs.b.call(void 0, this,"_lastDurationMs",null);_chunkIJZNCO5Xcjs.b.call(void 0, this,"disposed",!1);this.executor=e,this.baseConfig=r,this.mode=_nullishCoalesce(n.mode, () => ("latest-wins")),this.maxConcurrent=Math.max(1,_nullishCoalesce(n.maxConcurrent, () => ((this.mode==="parallel"?4:1)))),this.timeoutMs=n.timeoutMs,this.retry=n.retry;let o=n.cache;this.cacheEnabled=o!==void 0&&o!==!1;let s=typeof o=="object"?o:{};this.cacheMax=_nullishCoalesce(s.maxEntries, () => (50)),this.cacheTtl=_nullishCoalesce(s.ttlMs, () => (0)),this.onStart=n.onStart,this.onSettle=n.onSettle,this.onSuperseded=n.onSuperseded}get isSolving(){return this.inFlight.size>0}get hasPending(){return this.pendingForLatestWins!==null||this.fifoQueue.length>0}get inFlightCount(){return this.inFlight.size}get queueDepth(){return this.fifoQueue.length+(this.pendingForLatestWins?1:0)}get lastResult(){return this._lastResult}get lastError(){return this._lastError}get lastDurationMs(){return this._lastDurationMs}subscribe(e){return this.subscribers.add(e),()=>this.subscribers.delete(e)}notify(){for(let e of this.subscribers)try{e()}catch(r){_chunkIJZNCO5Xcjs.e.call(void 0, ).error("[SolveScheduler] subscriber threw:",r)}}solve(e,r,n){if(this.disposed)return Promise.reject(new (0, _chunkIJZNCO5Xcjs.d)("SolveScheduler has been disposed and cannot be used",_chunkIJZNCO5Xcjs.c.INVALID_STATE));let o=v(e,r),s={key:o,enqueuedAt:Date.now(),startedAt:null};if(this.cacheEnabled){let a=this.readCache(o);if(a){let i={status:"success",response:a,durationMs:0,fromCache:!0};return this._lastResult=a,this._lastError=null,this._lastDurationMs=0,this.runHook(this.onStart,s),this.runHook(this.onSettle,s,i),this.notify(),Promise.resolve(a)}}return new Promise((a,i)=>{let u={definition:e,dataTree:r,ctx:s,resolve:a,reject:i,externalSignal:_optionalChain([n, 'optionalAccess', _2 => _2.signal])};if(_optionalChain([u, 'access', _3 => _3.externalSignal, 'optionalAccess', _4 => _4.aborted])){i(this.makeAbortError(s));return}this.enqueue(u)})}enqueue(e){switch(this.mode){case"latest-wins":{this.pendingForLatestWins&&(this.supersede(this.pendingForLatestWins),this.pendingForLatestWins=null);for(let r of this.inFlight)this.supersede(r),r.controller.abort();this.inFlight.size===0?this.execute(e):this.pendingForLatestWins=e;break}case"queue":{this.inFlight.size<this.maxConcurrent?this.execute(e):this.fifoQueue.push(e);break}case"parallel":{this.inFlight.size<this.maxConcurrent?this.execute(e):this.fifoQueue.push(e);break}}this.notify()}async execute(e){let r=new AbortController,n={...e,controller:r};this.inFlight.add(n),e.ctx.startedAt=Date.now();let o=()=>r.abort();_optionalChain([e, 'access', _5 => _5.externalSignal, 'optionalAccess', _6 => _6.addEventListener, 'call', _7 => _7("abort",o,{once:!0})]),this.runHook(this.onStart,e.ctx),this.notify();let s=performance.now();try{let a={...this.baseConfig,signal:r.signal,...this.timeoutMs!==void 0&&{timeoutMs:this.timeoutMs},...this.retry!==void 0&&{retry:this.retry}},i=await this.executor(e.definition,e.dataTree,a),u=performance.now()-s;this.cacheEnabled&&this.writeCache(e.ctx.key,i),this._lastResult=i,this._lastError=null,this._lastDurationMs=u,e.resolve(i),this.runHook(this.onSettle,e.ctx,{status:"success",response:i,durationMs:u,fromCache:!1})}catch(a){let i=performance.now()-s,u=a instanceof _chunkIJZNCO5Xcjs.d?a:new (0, _chunkIJZNCO5Xcjs.d)(a instanceof Error?a.message:String(a),_chunkIJZNCO5Xcjs.c.UNKNOWN_ERROR,{originalError:a instanceof Error?a:new Error(String(a))});this._lastError=u,this._lastDurationMs=i,e.reject(u),this.runHook(this.onSettle,e.ctx,{status:"error",error:u,durationMs:i})}finally{_optionalChain([e, 'access', _8 => _8.externalSignal, 'optionalAccess', _9 => _9.removeEventListener, 'call', _10 => _10("abort",o)]),this.inFlight.delete(n),this.drainNext(),this.notify()}}drainNext(){if(!this.disposed){if(this.mode==="latest-wins"){if(this.pendingForLatestWins&&this.inFlight.size===0){let e=this.pendingForLatestWins;this.pendingForLatestWins=null,this.execute(e)}return}for(;this.fifoQueue.length>0&&this.inFlight.size<this.maxConcurrent;){let e=this.fifoQueue.shift();this.execute(e)}}}supersede(e){let r=new (0, _chunkIJZNCO5Xcjs.d)("Superseded by newer solve",_chunkIJZNCO5Xcjs.c.UNKNOWN_ERROR,{context:{key:e.ctx.key,enqueuedAt:e.ctx.enqueuedAt}});e.reject(r),this.runHook(this.onSuperseded,e.ctx)}makeAbortError(e){return new (0, _chunkIJZNCO5Xcjs.d)("Request aborted by caller",_chunkIJZNCO5Xcjs.c.UNKNOWN_ERROR,{context:{key:e.key,enqueuedAt:e.enqueuedAt}})}cancelAll(){for(this.pendingForLatestWins&&(this.pendingForLatestWins.reject(this.makeAbortError(this.pendingForLatestWins.ctx)),this.pendingForLatestWins=null);this.fifoQueue.length>0;){let e=this.fifoQueue.shift();e.reject(this.makeAbortError(e.ctx))}for(let e of this.inFlight)e.controller.abort();this.notify()}readCache(e){if(!this.cacheEnabled)return null;let r=this.cache.get(e);return r?this.cacheTtl>0&&Date.now()-r.insertedAt>this.cacheTtl?(this.cache.delete(e),null):(this.cache.delete(e),this.cache.set(e,r),r.response):null}writeCache(e,r){if(this.cacheEnabled)for(this.cache.set(e,{response:r,insertedAt:Date.now()});this.cache.size>this.cacheMax;){let n=this.cache.keys().next().value;if(n===void 0)break;this.cache.delete(n)}}clearCache(){this.cache.clear()}dispose(){this.disposed||(this.disposed=!0,this.cancelAll(),this.subscribers.clear(),this.cache.clear())}runHook(e,...r){if(e)try{e(...r)}catch(n){_chunkIJZNCO5Xcjs.e.call(void 0, ).error("[SolveScheduler] hook threw:",n)}}};var T=class t{constructor(e){_chunkIJZNCO5Xcjs.b.call(void 0, this,"config");_chunkIJZNCO5Xcjs.b.call(void 0, this,"serverStats");_chunkIJZNCO5Xcjs.b.call(void 0, this,"disposed",!1);this.config=this.normalizeComputeConfig(e),this.serverStats=new (0, _chunkIJZNCO5Xcjs.i)(this.config.serverUrl,this.config.apiKey)}static async create(e){let r=new t(e);if(!await r.serverStats.isServerOnline())throw new (0, _chunkIJZNCO5Xcjs.d)("Rhino Compute server is not online",_chunkIJZNCO5Xcjs.c.NETWORK_ERROR,{context:{serverUrl:r.config.serverUrl}});return r}getConfig(){return this.ensureNotDisposed(),{...this.config}}async getIO(e){return this.ensureNotDisposed(),R(e,this.config)}async getRawIO(e){return this.ensureNotDisposed(),S(e,this.config)}async solve(e,r,n){this.ensureNotDisposed();try{if(typeof e=="string"&&!_optionalChain([e, 'optionalAccess', _11 => _11.trim, 'call', _12 => _12()]))throw new (0, _chunkIJZNCO5Xcjs.d)("Definition URL/content is required",_chunkIJZNCO5Xcjs.c.INVALID_INPUT,{context:{receivedUrl:e}});if(e instanceof Uint8Array&&e.length===0)throw new (0, _chunkIJZNCO5Xcjs.d)("Definition content is empty",_chunkIJZNCO5Xcjs.c.INVALID_INPUT);let o={...this.config,..._optionalChain([n, 'optionalAccess', _13 => _13.signal])!==void 0&&{signal:n.signal},..._optionalChain([n, 'optionalAccess', _14 => _14.timeoutMs])!==void 0&&{timeoutMs:n.timeoutMs},..._optionalChain([n, 'optionalAccess', _15 => _15.retry])!==void 0&&{retry:n.retry}},s=await x(r,e,o);if(s&&typeof s=="object"&&"message"in s&&!("fileData"in s))throw new (0, _chunkIJZNCO5Xcjs.d)(s.message||"Computation failed",_chunkIJZNCO5Xcjs.c.COMPUTATION_ERROR,{context:{definition:typeof e=="string"&&e.length<200?e:"...content...",inputs:r}});return s}catch(o){throw this.config.debug&&_chunkIJZNCO5Xcjs.e.call(void 0, ).error("Compute failed:",o),o instanceof _chunkIJZNCO5Xcjs.d?o:new (0, _chunkIJZNCO5Xcjs.d)(o instanceof Error?o.message:String(o),_chunkIJZNCO5Xcjs.c.COMPUTATION_ERROR,{context:{definition:typeof e=="string"&&e.length<200?e:"...content...",inputs:r},originalError:o instanceof Error?o:new Error(String(o))})}}createScheduler(e){this.ensureNotDisposed();let r=(n,o,s)=>x(o,n,s);return new h(r,this.config,e)}async dispose(){this.disposed||(this.disposed=!0,"dispose"in this.serverStats&&typeof this.serverStats.dispose=="function"&&await this.serverStats.dispose())}ensureNotDisposed(){if(this.disposed)throw new (0, _chunkIJZNCO5Xcjs.d)("GrasshopperClient has been disposed and cannot be used",_chunkIJZNCO5Xcjs.c.INVALID_STATE)}normalizeComputeConfig(e){if(!_optionalChain([e, 'access', _16 => _16.serverUrl, 'optionalAccess', _17 => _17.trim, 'call', _18 => _18()]))throw new (0, _chunkIJZNCO5Xcjs.d)("serverUrl is required",_chunkIJZNCO5Xcjs.c.INVALID_CONFIG,{context:{receivedServerUrl:e.serverUrl}});try{new URL(e.serverUrl)}catch (e2){throw new (0, _chunkIJZNCO5Xcjs.d)("serverUrl must be a valid URL",_chunkIJZNCO5Xcjs.c.INVALID_CONFIG,{context:{receivedServerUrl:e.serverUrl}})}if(e.serverUrl===""||e.serverUrl==="https://compute.rhino3d.com/")throw new (0, _chunkIJZNCO5Xcjs.d)("serverUrl must be set to your Compute server URL. The default public endpoint is not allowed.",_chunkIJZNCO5Xcjs.c.INVALID_CONFIG,{context:{receivedServerUrl:e.serverUrl}});return{...e,serverUrl:e.serverUrl.replace(/\/+$/,""),apiKey:e.apiKey,authToken:e.authToken,debug:_nullishCoalesce(e.debug, () => (!1)),suppressClientSideWarning:e.suppressClientSideWarning}}};var M=async(t,e=null)=>{try{return await K(t,e)}catch(r){throw new (0, _chunkIJZNCO5Xcjs.d)("Failed to extract files from compute response",_chunkIJZNCO5Xcjs.c.INVALID_STATE,{context:{originalError:r instanceof Error?r.message:String(r)},originalError:r instanceof Error?r:void 0})}},P= exports.e =async(t,e,r=null)=>{if(typeof document>"u"||typeof Blob>"u")throw new (0, _chunkIJZNCO5Xcjs.d)("File download functionality is only available in browser environments. This function requires the DOM API (document, Blob).",_chunkIJZNCO5Xcjs.c.BROWSER_ONLY,{context:{environment:typeof window<"u"?"browser (SSR)":"Node.js",documentAvailable:typeof document<"u",blobAvailable:typeof Blob<"u"}});try{let n=await K(t,r);await ae(n,e)}catch(n){throw n instanceof _chunkIJZNCO5Xcjs.d?n:new (0, _chunkIJZNCO5Xcjs.d)("Failed to download files from compute response",_chunkIJZNCO5Xcjs.c.INVALID_STATE,{context:{originalError:n instanceof Error?n.message:String(n)},originalError:n instanceof Error?n:void 0})}},K=async(t,e)=>{let r=[];if(t.forEach(n=>{let o=`${n.fileName}${n.fileType}`;if(n.subFolder&&n.subFolder.trim()!==""&&(o=`${n.subFolder}/${o}`),n.isBase64Encoded===!0&&n.data){let s=_chunkLNIUUPA5cjs.c.call(void 0, n.data);r.push({fileName:`${n.fileName}${n.fileType}`,content:new Uint8Array(s.buffer),path:o})}else n.isBase64Encoded===!1&&n.data&&r.push({fileName:`${n.fileName}${n.fileType}`,content:n.data,path:o})}),e){let n=Array.isArray(e)?e:[e],o=await Promise.all(n.map(async s=>{try{let a=await fetch(s.filePath);if(!a.ok)return _chunkIJZNCO5Xcjs.e.call(void 0, ).warn(`Failed to fetch additional file from URL: ${s.filePath}`),null;let u=await(await a.blob()).arrayBuffer();return{fileName:s.fileName,content:new Uint8Array(u),path:s.fileName}}catch(a){return _chunkIJZNCO5Xcjs.e.call(void 0, ).error(`Error fetching additional file from URL: ${s.filePath}`,a),null}}));r.push(...o.filter(s=>s!==null))}return r};async function ae(t,e){let{zipSync:r,strToU8:n}=await Promise.resolve().then(() => _interopRequireWildcard(require("fflate"))),o={};t.forEach(i=>{o[i.path]=typeof i.content=="string"?n(i.content):i.content});let s=r(o,{level:6}),a=new Blob([s],{type:"application/zip"});ie(a,`${e}.zip`)}function ie(t,e){if(typeof document>"u")throw new (0, _chunkIJZNCO5Xcjs.d)("saveFile requires a browser environment with DOM API access.",_chunkIJZNCO5Xcjs.c.BROWSER_ONLY,{context:{function:"saveFile",requiredAPI:"document"}});let r=document.createElement("a");r.href=URL.createObjectURL(t),r.download=e,r.click(),URL.revokeObjectURL(r.href)}var A=new Map;function H(t,e){A.set(t,e)}H("Rhino.Geometry.Point3d",(t,e)=>{let r=e;return!r||typeof r.X!="number"?null:new t.Point([r.X,r.Y,r.Z])});H("Rhino.Geometry.Line",(t,e)=>{let r=e;return!r||!r.From||!r.To?null:new t.Line([r.From.X,r.From.Y,r.From.Z],[r.To.X,r.To.Y,r.To.Z])});function ue(t){if(A.has(t))return A.get(t);for(let[e,r]of A)if(t.startsWith(e))return r}function le(t){return!t||typeof t!="object"?null:_nullishCoalesce(_nullishCoalesce(t.data, () => (t.value)), () => (null))}function Y(t,e,r){let n=ue(e);if(n)try{return n(r,t)}catch(o){_chunkIJZNCO5Xcjs.e.call(void 0, ).warn(`Failed to decode Rhino type ${e}:`,o)}try{let o=le(t);if(o)return r.CommonObject.decode(o)}catch(o){return _chunkIJZNCO5Xcjs.e.call(void 0, ).warn(`Failed to decode ${e} with CommonObject:`,o),{__decodeError:!0,type:e,raw:t}}return t}var C={STRING:"System.String",INT:"System.Int32",DOUBLE:"System.Double",BOOL:"System.Boolean"},pe="Rhino.Geometry.",ce=["WebDisplay"],fe="FileData";function me(t){return ce.some(e=>t.includes(e))}function Q(t){if(typeof t!="string")return t;let e=t.trim();if(!(e.startsWith("{")||e.startsWith("[")||e.startsWith('"')))return t;try{let n=JSON.parse(e);if(typeof n=="string")try{return JSON.parse(n)}catch (e3){return n}return n}catch (e4){return t}}function de(t,e,r){switch(e){case C.STRING:return typeof t!="string"?t:t.replace(/^"(.*)"$/,"$1");case C.INT:return Number.parseInt(t,10);case C.DOUBLE:return Number.parseFloat(t);case C.BOOL:return String(t).toLowerCase()==="true";default:return r&&e.startsWith(pe)?Y(t,e,r):t}}function X(t,e,r,n){if(me(e))return null;if(typeof t!="string")return t;let o=r?Q(t):t;return de(o,e,n)}function E(t,e){for(let r of Object.values(t))if(Array.isArray(r))for(let n of r)e(n)}function Z(t,e=!1,r={}){let{parseValues:n=!0,rhino:o,stringOnly:s=!1}=r,a={};for(let i of t.values)E(i.InnerTree,u=>{if(s&&u.type!==C.STRING)return;let c=e?u.id:i.ParamName;if(!c)return;let d=X(u.data,u.type,n,o);a[c]===void 0?a[c]=d:Array.isArray(a[c])?a[c].push(d):a[c]=[a[c],d]});return{values:a}}function ee(t){let e=[];for(let r of t.values)E(r.InnerTree,n=>{if(!n.type.includes(fe))return;let o=Q(n.data);o&&o.fileName&&o.fileType&&"data"in o&&typeof o.isBase64Encoded=="boolean"&&typeof o.subFolder=="string"&&e.push(o)});return e}function k(t,e,r={}){let{parseValues:n=!0,rhino:o,stringOnly:s=!1}=r,a;if("byName"in e?a=t.values.find(u=>u.ParamName===e.byName):a=t.values.find(u=>{let c=!1;return E(u.InnerTree,d=>{d.id===e.byId&&(c=!0)}),c}),!a)return;let i=[];if(E(a.InnerTree,u=>{if("byId"in e&&u.id!==e.byId||s&&u.type!==C.STRING)return;let c=X(u.data,u.type,n,o);i.push(c)}),i.length!==0)return i.length===1?i[0]:i}var I=class{constructor(e,r=!1){this.response=e;this.debug=r}getValues(e=!1,r={}){return Z(this.response,e,r)}getValueByParamName(e,r){return k(this.response,{byName:e},r)}getValueByParamId(e,r){return k(this.response,{byId:e},r)}async extractMeshesFromResponse(e){let r={debug:this.debug,...e},n;try{({getThreeMeshesFromComputeResponse:n}=await Promise.resolve().then(() => _interopRequireWildcard(require("./visualization.cjs"))))}catch(o){throw new (0, _chunkIJZNCO5Xcjs.d)("Failed to load three.js visualization module. Ensure three.js is installed as a peer dependency.",_chunkIJZNCO5Xcjs.c.INVALID_STATE,{context:{originalError:o instanceof Error?o.message:String(o)}})}return n(this.response,r)}getFileData(){return ee(this.response)}getAndDownloadFiles(e,r){let n=this.getFileData();P(n,e,r)}};function V(t,e){e||typeof window<"u"&&_chunkIJZNCO5Xcjs.e.call(void 0, ).warn(`Warning: ${t} is running on the client side. For better performance and security, consider running this on the server side.`)}async function x(t,e,r){r.debug&&V("solveGrasshopperDefinition",r.suppressClientSideWarning);let n=B(e,t);he(n,r);let o=await _chunkIJZNCO5Xcjs.h.call(void 0, "grasshopper",n,r);return"pointer"in o&&delete o.pointer,o}function B(t,e){let r={algo:null,pointer:null,values:e};return t instanceof Uint8Array?r.algo=_chunkLNIUUPA5cjs.d.call(void 0, t):/^https?:\/\//i.test(t)?r.pointer=t:_chunkLNIUUPA5cjs.b.call(void 0, t)?r.algo=t:r.algo=_chunkLNIUUPA5cjs.a.call(void 0, t),r}function he(t,e){e.cachesolve!=null&&(t.cachesolve=e.cachesolve),e.modelunits!=null&&(t.modelunits=e.modelunits),e.angletolerance!=null&&(t.angletolerance=e.angletolerance),e.absolutetolerance!=null&&(t.absolutetolerance=e.absolutetolerance),e.dataversion!=null&&(t.dataversion=e.dataversion)}function te(t){if(typeof t.default!="object"||t.default===null)return;if(!("innerTree"in t.default)){_chunkIJZNCO5Xcjs.e.call(void 0, ).warn("Unexpected structure in input.default:",t.default),t.default=null;return}let e=t.default.innerTree;if(Object.keys(e).length===0){t.default=void 0;return}if(t.treeAccess||t.atMost&&t.atMost>1){let n={};for(let[o,s]of Object.entries(e))n[o]=s.map(a=>{if(typeof a.data=="string"){if(a.type==="System.Double"||a.type==="System.Int32"){let i=Number(a.data);return Number.isNaN(i)?a.data:i}if(a.type==="System.Boolean")return a.data.toLowerCase()==="true";if(a.type.startsWith("Rhino.Geometry")||a.type==="System.String")try{return JSON.parse(a.data)}catch (e5){return a.data}}return a.data});t.default=n;return}let r=[];for(let n of Object.values(e))Array.isArray(n)&&n.forEach(o=>{o&&typeof o=="object"&&"data"in o&&r.push(o.data)});r.length===0?t.default=void 0:r.length===1?t.default=r[0]:t.default=r}function O(t,e){let{transform:r,setUndefinedOnEmpty:n=!0}=e;if(!(t.default===void 0||t.default===null))if(Array.isArray(t.default)){let o=t.default.map(r).filter(s=>s!==null);t.default=o.length>0?o:void 0}else{let o=r(t.default);o!==null?t.default=o:n&&(t.default=void 0)}}function ye(){return t=>{if(typeof t=="number")return t;if(typeof t=="string"){let e=Number(t.trim());return Number.isNaN(e)?null:e}return null}}function ge(){return t=>{if(typeof t=="boolean")return t;if(typeof t=="string"){let e=t.toLowerCase();if(e==="true")return!0;if(e==="false")return!1;throw new Error(`Invalid boolean string: "${t}"`)}return null}}function be(){return t=>typeof t=="string"?t.startsWith('"')&&t.endsWith('"')||t.startsWith('"')?t.slice(1,-1):t:null}function Te(){return t=>{if(typeof t=="string"){let e=t.trim();return e.startsWith('"')&&e.endsWith('"')&&(e=e.slice(1,-1).trim()),e}return null}}function xe(t){O(t,{transform:Te(),setUndefinedOnEmpty:!1})}function Se(t="unknown"){return e=>{if(typeof e=="object"&&e!==null)return e;if(typeof e=="string"&&e.trim()!=="")try{let r=JSON.parse(e);return typeof r=="object"&&r!==null?r:(_chunkIJZNCO5Xcjs.e.call(void 0, ).warn(`Parsed value for input ${t} is not an object`),null)}catch(r){return _chunkIJZNCO5Xcjs.e.call(void 0, ).warn(`Failed to parse object value "${e}" for input ${t}`,r),null}return null}}function re(t,e,r){let n=Number(t.toFixed(e));return Math.abs(t-n)<r?n:t}function Ce(t,e=1e-8){if(!Number.isFinite(t)||t===0)return .1;let r=Math.abs(t);if(r>=1){let y=String(t).split(".")[1];if(y&&y.length>0){let g=Math.min(y.length,12),b=Math.pow(10,-g),U=Number(b.toFixed(g));return Math.abs(U-b)<e?U:b}return 1}let n=String(t),o=n.toLowerCase().match(/e(-?\d+)/);if(o){let G=Number(o[1]);if(G<0||n.toLowerCase().includes("e-")){let y=Math.abs(G),g=Math.pow(10,-y),b=Number(g.toFixed(y));return Math.abs(b-g)<e?b:g}return .1}let s=12,i=r.toFixed(s).replace(/0+$/,""),u=Math.min((i.split(".")[1]||"").length,s);if(u===0)return .1;let c=Math.pow(10,-u),d=Number(c.toFixed(u));return Math.abs(d-c)<e?d:c}function ne(t,e=1e-8){let r=t.paramType==="Integer";if(O(t,{transform:ye()}),r){Array.isArray(t.default)?t.default=t.default.map(s=>typeof s=="number"?Math.round(s):s):typeof t.default=="number"&&(t.default=Math.round(t.default)),t.stepSize=1;return}let n=Array.isArray(t.default)?t.default[0]:t.default,o;if(typeof n=="number"&&Number.isFinite(n)&&n!==0?o=n:typeof t.minimum=="number"&&Number.isFinite(t.minimum)&&t.minimum!==0?o=t.minimum:typeof t.maximum=="number"&&Number.isFinite(t.maximum)&&t.maximum!==0&&(o=t.maximum),o!==void 0?t.stepSize=Ce(o,e):t.stepSize=.1,typeof t.stepSize=="number"){let s=0,a=String(t.stepSize),i=a.toLowerCase().match(/e(-?\d+)/);if(i?s=Math.abs(Number(i[1])):s=_nullishCoalesce(_optionalChain([a, 'access', _19 => _19.split, 'call', _20 => _20("."), 'access', _21 => _21[1], 'optionalAccess', _22 => _22.length]), () => (0)),s===0&&typeof n=="number"&&n!==0&&Math.abs(n)<1){let u=Math.ceil(-Math.log10(Math.abs(n)));Number.isFinite(u)&&u>0&&(s=u)}s=Math.min(Math.max(s,0),12),Array.isArray(t.default)?t.default=t.default.map(u=>typeof u=="number"?re(u,s,e):u):typeof t.default=="number"&&(t.default=re(t.default,s,e))}}function Ie(t){try{O(t,{transform:ge(),setUndefinedOnEmpty:!1})}catch(e){throw e instanceof Error?new (0, _chunkIJZNCO5Xcjs.d)(e.message):e}}function De(t){O(t,{transform:be(),setUndefinedOnEmpty:!1})}function oe(t){O(t,{transform:Se(t.nickname||"unnamed"),setUndefinedOnEmpty:!0})}function ve(t){if(!t.values||typeof t.values!="object"||Object.keys(t.values).length===0)throw _chunkIJZNCO5Xcjs.d.missingValues(t.nickname||"unnamed","ValueList");if(t.default!==void 0&&t.default!==null){let e=String(t.default).toLowerCase();Object.keys(t.values).some(n=>n.toLowerCase()===e)||_chunkIJZNCO5Xcjs.e.call(void 0, ).warn(`ValueList input "${t.nickname||"unnamed"}" default value "${t.default}" is not in available values`)}}var se={Number:ne,Integer:ne,Boolean:Ie,Text:De,ValueList:ve,Geometry:oe,File:oe,Color:xe};function Re(t,e){let r=(_nullishCoalesce(t.atMost, () => (1)))>1;switch(t.paramType){case"Number":case"Integer":return{...e,paramType:t.paramType,minimum:t.minimum,maximum:t.maximum,atLeast:t.atLeast,atMost:t.atMost,default:r?[0]:0};case"Boolean":return{...e,paramType:"Boolean",default:r?[!1]:!1};case"Text":return{...e,paramType:"Text",default:r?[""]:""};case"ValueList":return{...e,paramType:"ValueList",values:_nullishCoalesce(t.values, () => ({})),default:r?[t.default]:t.default};case"File":return{...e,paramType:"File",default:r?[null]:null};case"Color":return{...e,paramType:"Color",default:r?["0, 0, 0"]:"0, 0, 0"};default:return{...e,paramType:"Geometry",default:r?[null]:null}}}function F(t){let e={description:t.description,name:t.name,nickname:t.nickname,treeAccess:t.treeAccess,groupName:_nullishCoalesce(t.groupName, () => ("")),id:t.id};try{te(t);let r=se[t.paramType];if(!r)throw _chunkIJZNCO5Xcjs.d.unknownParamType(t.paramType,t.name);switch(r(t),t.paramType){case"Number":case"Integer":return{...e,paramType:t.paramType,minimum:t.minimum,maximum:t.maximum,atLeast:t.atLeast,atMost:t.atMost,stepSize:t.stepSize,default:t.default};case"Boolean":return{...e,paramType:"Boolean",default:t.default};case"Text":return{...e,paramType:"Text",default:t.default};case"ValueList":return{...e,paramType:"ValueList",values:t.values,default:t.default};case"Geometry":return{...e,paramType:t.paramType,default:t.default};case"File":return{...e,paramType:t.paramType,acceptedFormats:t.acceptedFormats,default:t.default};case"Color":return{...e,paramType:"Color",default:t.default};default:throw _chunkIJZNCO5Xcjs.d.unknownParamType(t.paramType,t.name)}}catch(r){if(r instanceof _chunkIJZNCO5Xcjs.d)return _chunkIJZNCO5Xcjs.e.call(void 0, ).error(`Validation error for input ${t.name||"unknown"}:`,r.message),Re(t,e);throw new (0, _chunkIJZNCO5Xcjs.d)(r instanceof Error?r.message:String(r),"VALIDATION_ERROR",{context:{paramName:t.name,paramType:t.paramType},originalError:r instanceof Error?r:new Error(String(r))})}}function D(t){return t.map(e=>F(e))}async function S(t,e){let r=B(t,[]),n={};if(r.algo&&(n.algo=r.algo),r.pointer&&(n.pointer=r.pointer),!n.algo&&!n.pointer)throw new (0, _chunkIJZNCO5Xcjs.d)("Definition must resolve to either a URL pointer or base64 algo",_chunkIJZNCO5Xcjs.c.INVALID_INPUT,{context:{definition:t}});let o=await _chunkIJZNCO5Xcjs.h.call(void 0, "io",n,e);if(!o||typeof o!="object")throw new (0, _chunkIJZNCO5Xcjs.d)("Invalid IO response structure",_chunkIJZNCO5Xcjs.c.INVALID_INPUT,{context:{response:o,definition:t}});let s=_chunkIJZNCO5Xcjs.k.call(void 0, o,{deep:!0});return{inputs:s.inputs,outputs:s.outputs}}async function R(t,e){V("fetchParsedDefinitionIO",e.suppressClientSideWarning);let{inputs:r,outputs:n}=await S(t,e);return{inputs:D(r),outputs:n}}var w=class t{constructor(e){_chunkIJZNCO5Xcjs.b.call(void 0, this,"innerTree");_chunkIJZNCO5Xcjs.b.call(void 0, this,"paramName");this.paramName=e,this.innerTree={}}append(e,r){let n=t.formatPathString(e);this.innerTree[n]||(this.innerTree[n]=[]);let o=r.map(s=>({data:t.serializeValue(s)}));return this.innerTree[n].push(...o),this}appendSingle(e,r){return this.append(e,[r])}fromDataTreeDefault(e){this.innerTree={};for(let[r,n]of Object.entries(e)){if(!Array.isArray(n))continue;let o=t.parsePathString(r);this.append(o,n)}return this}appendFlat(e){let r=Array.isArray(e)?e:[e];return this.append([0],r)}flatten(){let e=[];for(let r of Object.values(this.innerTree))if(Array.isArray(r))for(let n of r)e.push(t.deserializeValue(n.data));return e}getPaths(){return Object.keys(this.innerTree)}getPath(e){let r=t.formatPathString(e),n=this.innerTree[r];if(n)return n.map(o=>t.deserializeValue(o.data))}toComputeFormat(){return{ParamName:this.paramName,InnerTree:this.innerTree}}getInnerTree(){return this.innerTree}getParamName(){return this.paramName}static fromInputParams(e){return e.filter(r=>t.hasValidValue(r.default)).map(r=>{let n=new t(r.nickname||"unnamed"),o=r.default;if(r.treeAccess&&t.isDataTreeStructure(o))n.fromDataTreeDefault(o),t.isNumericInput(r)&&n.applyNumericConstraints(r.minimum,r.maximum,r.nickname||"unnamed");else{let s=Array.isArray(o)?o:[o],a=t.processValues(s,r);n.appendFlat(a)}return n.toComputeFormat()})}static fromInputParam(e){return t.hasValidValue(e.default)?t.fromInputParams([e])[0]:void 0}static replaceTreeValue(e,r,n){if(e.length>0&&e[0]instanceof t){let s=e,a=s.findIndex(u=>u.getParamName()===r),i=new t(r);return typeof n=="object"&&n!==null&&!Array.isArray(n)&&t.isDataTreeStructure(n)?i.fromDataTreeDefault(n):(Array.isArray(n),i.appendFlat(n)),a!==-1?s[a]=i:s.push(i),s}else{let s=e,a=s.findIndex(c=>c.ParamName===r),i=new t(r);typeof n=="object"&&n!==null&&!Array.isArray(n)&&t.isDataTreeStructure(n)?i.fromDataTreeDefault(n):(Array.isArray(n),i.appendFlat(n));let u=i.toComputeFormat();return a!==-1?s[a]=u:s.push(u),s}}static getTreeValue(e,r){if(e.length>0&&e[0]instanceof t){let s=e.find(i=>i.getParamName()===r);if(!s)return null;let a=s.flatten();return a.length===0?null:a.length===1?a[0]:a}else{let s=e.find(c=>c.ParamName===r);if(!s)return null;let a=s.InnerTree;if(!a)return null;let i=Object.keys(a)[0];if(!i)return null;let u=a[i];if(Array.isArray(u)){if(u.length===1){let c=_optionalChain([u, 'access', _23 => _23[0], 'optionalAccess', _24 => _24.data]);return c!==void 0?t.deserializeValue(c):null}return u.map(c=>_optionalChain([c, 'optionalAccess', _25 => _25.data])!==void 0?t.deserializeValue(c.data):null).filter(c=>c!==null)}return _optionalChain([u, 'optionalAccess', _26 => _26.data])!==void 0?t.deserializeValue(u.data):u}}static parsePathString(e){let r=e.match(/^\{([\d;]*)\}$/);return r?r[1]===""?[]:r[1].split(";").map(Number):(_chunkIJZNCO5Xcjs.e.call(void 0, ).warn(`Invalid TreeBuilder path format: ${e}, using [0]`),[0])}static formatPathString(e){return`{${e.join(";")}}`}applyNumericConstraints(e,r,n){for(let o of Object.values(this.innerTree))if(Array.isArray(o))for(let s of o){let a=t.deserializeValue(s.data);if(typeof a=="number"){let i=t.clampValue(a,e,r,n);s.data=t.serializeValue(i)}}}static serializeValue(e){return typeof e=="boolean"||typeof e=="number"||typeof e=="string"?e:typeof e=="object"&&e!==null?JSON.stringify(e):String(e)}static deserializeValue(e){if(typeof e=="boolean"||typeof e=="number"||typeof e!="string")return e;if(e.startsWith("{")||e.startsWith("["))try{return JSON.parse(e)}catch (e6){return e}return isNaN(Number(e))?e==="true"?!0:e==="false"?!1:e:Number(e)}static hasValidValue(e){return e==null?!1:typeof e=="string"?!0:!(Array.isArray(e)&&e.length===0||typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length===0)}static isDataTreeStructure(e){return typeof e!="object"||e===null||Array.isArray(e)?!1:Object.entries(e).every(([r,n])=>typeof r=="string"&&/^\{[\d;]+\}$/.test(r)&&Array.isArray(n))}static isNumericInput(e){return e.paramType==="Number"||e.paramType==="Integer"}static processValues(e,r){return e.map(n=>t.isNumericInput(r)&&typeof n=="number"?t.clampValue(n,r.minimum,r.maximum,r.nickname||"unnamed"):n).filter(n=>n!=null)}static clampValue(e,r,n,o){let s=e;return r!=null&&s<r&&(_chunkIJZNCO5Xcjs.e.call(void 0, ).warn(`${o}: ${e} below min ${r}, clamping`),s=r),n!=null&&s>n&&(_chunkIJZNCO5Xcjs.e.call(void 0, ).warn(`${o}: ${e} above max ${n}, clamping`),s=n),s}};exports.a = v; exports.b = h; exports.c = T; exports.d = M; exports.e = P; exports.f = I; exports.g = x; exports.h = F; exports.i = D; exports.j = S; exports.k = R; exports.l = w;
|
|
2
|
-
//# sourceMappingURL=chunk-FRSLCR7G.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/chunk-FRSLCR7G.cjs","../src/features/grasshopper/scheduler/stable-hash.ts"],"names":["stableStringify","value","seen","stringify","v","sample","k"],"mappings":"AAAA,2/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CAAK,GAAG,CAAC,CAAA,CAAA,CAAA,CAElC,OAAOC,CAAAA,EAAM,QAAA,CACZF,CAAAA,CAAK,GAAA,CAAIE,CAAW,CAAA,CAAU,IAAA,CAAK,SAAA,CAAU,YAAY,CAAA,CAAA,CAC7DF,CAAAA,CAAK,GAAA,CAAIE,CAAW,CAAA,CAGb,CAAA,CAAA,EAFM,MAAA,CAAO,IAAA,CAAKA,CAAW,CAAA,CAAE,IAAA,CAAK,CAAA,CACxB,GAAA,CAAKE,CAAAA,EAAM,CAAA,EAAA","file":"/home/runner/work/selva-compute/selva-compute/dist/chunk-FRSLCR7G.cjs","sourcesContent":[null,"/**\n * Stable hashing helpers for solve dedupe / cache keys.\n *\n * @internal\n */\n\n/**\n * Deterministic JSON stringify — keys are sorted at every object level so\n * `{a:1,b:2}` and `{b:2,a:1}` produce the same string. Handles circular\n * references safely (replaces with a sentinel) and non-finite numbers.\n */\nexport function stableStringify(value: unknown): string {\n\tconst seen = new WeakSet<object>();\n\n\tconst stringify = (v: unknown): string => {\n\t\tif (v === null || v === undefined) return JSON.stringify(v);\n\t\tif (typeof v === 'number') {\n\t\t\treturn Number.isFinite(v) ? String(v) : JSON.stringify(null);\n\t\t}\n\t\tif (typeof v === 'string' || typeof v === 'boolean') return JSON.stringify(v);\n\t\tif (typeof v === 'bigint') return JSON.stringify(v.toString());\n\t\tif (v instanceof Uint8Array) {\n\t\t\t// Hash bytes by length + a sample to avoid stringifying multi-MB buffers fully\n\t\t\tconst sample = v.length > 64 ? Array.from(v.slice(0, 32)).concat(Array.from(v.slice(-32))) : Array.from(v);\n\t\t\treturn JSON.stringify({ __u8: true, len: v.length, sample });\n\t\t}\n\t\tif (Array.isArray(v)) {\n\t\t\treturn `[${v.map(stringify).join(',')}]`;\n\t\t}\n\t\tif (typeof v === 'object') {\n\t\t\tif (seen.has(v as object)) return JSON.stringify('[Circular]');\n\t\t\tseen.add(v as object);\n\t\t\tconst keys = Object.keys(v as object).sort();\n\t\t\tconst parts = keys.map((k) => `${JSON.stringify(k)}:${stringify((v as any)[k])}`);\n\t\t\treturn `{${parts.join(',')}}`;\n\t\t}\n\t\t// Fallback for functions, symbols, etc.\n\t\treturn JSON.stringify(null);\n\t};\n\n\treturn stringify(value);\n}\n\n/**\n * 32-bit FNV-1a hash. Fast, no deps, good enough for dedupe/cache keys.\n * Returns an unsigned hex string.\n */\nexport function fnv1a(input: string): string {\n\tlet hash = 0x811c9dc5;\n\tfor (let i = 0; i < input.length; i++) {\n\t\thash ^= input.charCodeAt(i);\n\t\thash = (hash + ((hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24))) >>> 0;\n\t}\n\treturn hash.toString(16).padStart(8, '0');\n}\n\n/**\n * Hash a (definition, dataTree) pair into a short stable key.\n * For Uint8Array definitions we use length + endpoint bytes rather than the\n * full content to keep hashing cheap.\n */\nexport function hashSolveInput(definition: string | Uint8Array, dataTree: unknown): string {\n\tconst defKey =\n\t\ttypeof definition === 'string'\n\t\t\t? definition\n\t\t\t: stableStringify({ __u8: true, len: definition.length });\n\treturn fnv1a(`${defKey}|${stableStringify(dataTree)}`);\n}\n"]}
|
package/dist/chunk-IJZNCO5X.cjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var S=Object.defineProperty;var $=(e,r,t)=>r in e?S(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var W=(e,r)=>{for(var t in r)S(e,t,{get:r[t],enumerable:!0})};var R=(e,r,t)=>$(e,typeof r!="symbol"?r+"":r,t);var a={NETWORK_ERROR:"NETWORK_ERROR",AUTH_ERROR:"AUTH_ERROR",VALIDATION_ERROR:"VALIDATION_ERROR",COMPUTATION_ERROR:"COMPUTATION_ERROR",TIMEOUT_ERROR:"TIMEOUT_ERROR",CORS_ERROR:"CORS_ERROR",UNKNOWN_ERROR:"UNKNOWN_ERROR",INVALID_STATE:"INVALID_STATE",INVALID_INPUT:"INVALID_INPUT",INVALID_CONFIG:"INVALID_CONFIG",BROWSER_ONLY:"BROWSER_ONLY",ENVIRONMENT_ERROR:"ENVIRONMENT_ERROR",ENCODING_ERROR:"ENCODING_ERROR"};var d=class e extends Error{constructor(t,n="UNKNOWN_ERROR",s){super(t);R(this,"code");R(this,"statusCode");R(this,"context");R(this,"originalError");this.name="RhinoComputeError",this.code=n,this.statusCode=_optionalChain([s, 'optionalAccess', _2 => _2.statusCode]),this.context=_optionalChain([s, 'optionalAccess', _3 => _3.context]),this.originalError=_optionalChain([s, 'optionalAccess', _4 => _4.originalError]),"cause"in Error.prototype&&Object.defineProperty(this,"cause",{value:_optionalChain([s, 'optionalAccess', _5 => _5.originalError]),enumerable:!0})}static validation(t,n,s){return new e(`Input "${t}": ${n}`,a.VALIDATION_ERROR,{context:{inputName:t,reason:n,...s}})}static missingValues(t,n,s){return new e(`Input "${t}" has no values defined${n?` (expected ${n})`:""}`,a.INVALID_INPUT,{context:{inputName:t,expectedType:n,...s}})}static invalidDefault(t,n,s,i){return new e(`ValueList input "${t}" default value "${n}" is not in available values`,a.VALIDATION_ERROR,{context:{inputName:t,defaultValue:n,availableValues:s,...i}})}static unknownParamType(t,n,s){return new e(`Unknown paramType: ${t}`,a.VALIDATION_ERROR,{context:{receivedParamType:t,paramName:n,...s}})}static invalidStructure(t,n,s){return new e(`Invalid input structure for "${t}" (expected ${n})`,a.INVALID_INPUT,{context:{inputName:t,expectedStructure:n,...s}})}};var v=class{debug(){}info(){}warn(){}error(){}},O=class{debug(r,...t){console.debug(r,...t)}info(r,...t){console.info(r,...t)}warn(r,...t){console.warn(r,...t)}error(r,...t){console.error(r,...t)}},b=new v;function p(){return b}function N(e){e===null?b=new v:"debug"in e&&"info"in e&&"warn"in e&&"error"in e?b=e:b=new O}function _(){N(new O)}var y={attempts:0,baseDelayMs:500,maxDelayMs:3e4,retryOn429:!0},I=new Set([502,503,504]);function k(e){return e?{attempts:_nullishCoalesce(e.attempts, () => (y.attempts)),baseDelayMs:_nullishCoalesce(e.baseDelayMs, () => (y.baseDelayMs)),maxDelayMs:_nullishCoalesce(e.maxDelayMs, () => (y.maxDelayMs)),retryOn429:_nullishCoalesce(e.retryOn429, () => (y.retryOn429))}:y}function M(e){if(!e)return null;let r=Number(e);if(Number.isFinite(r)&&r>=0)return r*1e3;let t=Date.parse(e);if(Number.isFinite(t)){let n=t-Date.now();return n>0?n:0}return null}function w(e,r){let t=r.baseDelayMs*Math.pow(2,e),n=Math.random()*r.baseDelayMs;return Math.min(t+n,r.maxDelayMs)}function x(e,r){return new Promise((t,n)=>{if(_optionalChain([r, 'optionalAccess', _6 => _6.aborted])){n(new DOMException("Aborted","AbortError"));return}let s=setTimeout(()=>{_optionalChain([r, 'optionalAccess', _7 => _7.removeEventListener, 'call', _8 => _8("abort",i)]),t()},e),i=()=>{clearTimeout(s),n(new DOMException("Aborted","AbortError"))};_optionalChain([r, 'optionalAccess', _9 => _9.addEventListener, 'call', _10 => _10("abort",i,{once:!0})])})}function L(e,r,t,n,s,i){let{status:c,statusText:o}=e,l={url:r,requestId:t,method:"POST",requestSize:n,serverUrl:s},u=i?` \u2014 ${i.slice(0,200)}`:"",m={401:{message:`HTTP ${c}: ${o}${u}`,code:a.AUTH_ERROR},403:{message:`HTTP ${c}: ${o}${u}`,code:a.AUTH_ERROR},404:{message:`Endpoint not found: ${r}`,code:a.NETWORK_ERROR},413:{message:`Request too large: ${(n/1024).toFixed(2)}KB`,code:a.VALIDATION_ERROR},429:{message:"Rate limit exceeded",code:a.NETWORK_ERROR},500:{message:`Server error: ${i||o}`,code:a.COMPUTATION_ERROR},502:{message:`Service unavailable: ${o}`,code:a.NETWORK_ERROR},503:{message:`Service unavailable: ${o}`,code:a.NETWORK_ERROR},504:{message:`Service unavailable: ${o}`,code:a.NETWORK_ERROR}}[c]||{message:`HTTP ${c}: ${o}`,code:a.UNKNOWN_ERROR};throw new d(m.message,m.code,{statusCode:c,context:l})}function D(e,r){let t=r.replace(/\/+$/,""),n=e.replace(/^\/+/,"");return`${t}/${n}`}function U(e){try{let r=new URL(e).host;return/^(localhost|127\.0\.0\.1|::1)(:\d+)?$/i.test(r)}catch (e2){return/(localhost|127\.0\.0\.1)/i.test(e)}}function q(e,r){let t={"X-Request-ID":e,"Content-Type":"application/json",...r.authToken&&{Authorization:r.authToken},...r.apiKey&&{RhinoComputeKey:r.apiKey}};return!r.apiKey&&!U(r.serverUrl)&&p().warn(`\u26A0\uFE0F [Rhino Compute] Request [${e}] targets remote server (${r.serverUrl}) but no API key is configured. Requests may fail or be rate-limited.`),t}function K(){return`${Date.now()}-${Math.random().toString(36).substring(2,11)}`}function f(e,r){r&&p().debug(e)}function P(e,r){let t=[],n=()=>{};if(e&&t.push(e),r&&r>0)if(typeof AbortSignal<"u"&&typeof AbortSignal.timeout=="function")t.push(AbortSignal.timeout(r));else{let o=new AbortController,l=setTimeout(()=>o.abort(),r);n=()=>clearTimeout(l),t.push(o.signal)}if(t.length===0)return{signal:void 0,cleanup:n};if(t.length===1)return{signal:t[0],cleanup:n};if(typeof AbortSignal<"u"&&typeof AbortSignal.any=="function")return{signal:AbortSignal.any(t),cleanup:n};let s=new AbortController,i=()=>s.abort();for(let o of t){if(o.aborted){s.abort();break}o.addEventListener("abort",i,{once:!0})}let c=n;return n=()=>{c();for(let o of t)o.removeEventListener("abort",i)},{signal:s.signal,cleanup:n}}async function F(e,r,t,n,s,i,c){let o=Math.round(performance.now()-i);if(!e.ok){let l=await e.text();if(c&&(f(`\u274C Request [${t}] failed with HTTP ${e.status} in ${o}ms`,!0),f(` URL: ${r}`,!0),f(` Status: ${e.status} ${e.statusText}`,!0),l&&f(` Response body: ${l.substring(0,500)}${l.length>500?"...":""}`,!0)),e.status===500)try{let u=JSON.parse(l);if(_optionalChain([u, 'optionalAccess', _11 => _11.values])&&(u.errors||u.warnings))return c&&(f(`\u26A0\uFE0F Request [${t}] completed with Grasshopper errors in ${o}ms`,!0),_optionalChain([u, 'access', _12 => _12.errors, 'optionalAccess', _13 => _13.length])>0&&f(` Errors: ${JSON.stringify(u.errors,null,2)}`,!0),_optionalChain([u, 'access', _14 => _14.warnings, 'optionalAccess', _15 => _15.length])>0&&f(` Warnings: ${JSON.stringify(u.warnings,null,2)}`,!0)),u;_optionalChain([u, 'optionalAccess', _16 => _16.Message])?l=`${u.ExceptionType?u.ExceptionType+": ":""}${u.Message}
|
|
2
|
-
${u.StackTrace||""}`:_optionalChain([u, 'optionalAccess', _17 => _17.error])&&(l=typeof u.error=="string"?u.error:JSON.stringify(u.error,null,2))}catch(u){c&&f(` Failed to parse error body as JSON: ${u}`,!0)}L(e,r,t,n,s,l)}f(`\u2705 Request [${t}] completed in ${o}ms`,c);try{return await e.json()}catch(l){throw new d("Failed to parse JSON response",a.NETWORK_ERROR,{statusCode:e.status,context:{url:r,requestId:t},originalError:l instanceof Error?l:new Error(String(l))})}}async function H(e,r,t,n){let{signal:s,cleanup:i}=P(e.config.signal,e.config.timeoutMs),c=performance.now();try{let o=await fetch(e.fullUrl,{method:"POST",body:e.body,headers:e.headers,signal:s});if((I.has(o.status)||r.retryOn429&&o.status===429)&&t<n-1){let m=_nullishCoalesce(M(o.headers.get("Retry-After")), () => (w(t,r)));return await o.text().catch(()=>{}),{ok:!1,retry:!0,delayMs:m,cause:new d(`HTTP ${o.status} ${o.statusText} (will retry)`,a.NETWORK_ERROR,{statusCode:o.status,context:{requestId:e.requestId}})}}return{ok:!0,value:await F(o,e.fullUrl,e.requestId,e.requestSize,e.config.serverUrl,c,e.config.debug)}}catch(o){if(o instanceof Error&&(o.name==="AbortError"||o.name==="TimeoutError")){if(_optionalChain([e, 'access', _18 => _18.config, 'access', _19 => _19.signal, 'optionalAccess', _20 => _20.aborted])===!0)return{ok:!1,retry:!1,cause:new d("Request aborted by caller",a.UNKNOWN_ERROR,{context:{endpoint:e.endpoint,requestId:e.requestId,requestSize:e.requestSize},originalError:o})};let u=new d(`Request timed out after ${e.config.timeoutMs}ms`,a.TIMEOUT_ERROR,{context:{serverUrl:e.config.serverUrl,timeoutMs:e.config.timeoutMs,url:e.fullUrl,requestId:e.requestId,endpoint:e.endpoint,requestSize:e.requestSize}});return t<n-1?{ok:!1,retry:!0,delayMs:w(t,r),cause:u}:{ok:!1,retry:!1,cause:u}}if(o instanceof TypeError){let l=new d(`Network error: ${o.message}`,a.NETWORK_ERROR,{context:{serverUrl:e.config.serverUrl,url:e.fullUrl,requestId:e.requestId,endpoint:e.endpoint,requestSize:e.requestSize},originalError:o});return t<n-1?{ok:!1,retry:!0,delayMs:w(t,r),cause:l}:{ok:!1,retry:!1,cause:l}}if(o instanceof d){let l=o.statusCode;return l!==void 0&&(I.has(l)||r.retryOn429&&l===429)&&t<n-1?{ok:!1,retry:!0,delayMs:w(t,r),cause:o}:{ok:!1,retry:!1,cause:o}}return{ok:!1,retry:!1,cause:new d(o instanceof Error?o.message:String(o),a.UNKNOWN_ERROR,{context:{endpoint:e.endpoint,requestId:e.requestId},originalError:o instanceof Error?o:new Error(String(o))})}}finally{i()}}async function V(e,r,t){let n=K(),s=JSON.stringify(r),i=s.length,c=D(e,t.serverUrl),o=q(n,t),l=k(t.retry),u=l.attempts+1;if(t.debug){let h=(i/1024).toFixed(2),g=i>1e5?"\u26A0\uFE0F":"\u{1F680}";f(`${g} Starting compute request [${n}]: ${e} (${h}KB)`,!0)}let T={endpoint:e,body:s,requestSize:i,fullUrl:c,requestId:n,headers:o,config:t},m=null;for(let h=0;h<u;h++){let g=await H(T,l,h,u);if(g.ok)return g.value;if(!g.retry)throw g.cause;m=g.cause,t.debug&&f(`\u{1F501} Request [${n}] retrying after ${g.delayMs}ms (attempt ${h+2}/${u}): ${g.cause.message}`,!0);try{await x(g.delayMs,t.signal)}catch (e3){throw new d("Request aborted by caller",a.UNKNOWN_ERROR,{context:{endpoint:e,requestId:n,requestSize:i},originalError:m})}}throw _nullishCoalesce(m, () => (new d("Unknown error after retries",a.UNKNOWN_ERROR,{context:{endpoint:e,requestId:n,requestSize:i}})))}var E=class{constructor(r,t){R(this,"serverUrl");R(this,"apiKey");R(this,"disposed",!1);R(this,"activeMonitors",new Set);R(this,"activeTimeouts",new Set);if(!_optionalChain([r, 'optionalAccess', _21 => _21.trim, 'call', _22 => _22()]))throw new d("serverUrl is required",a.INVALID_CONFIG,{context:{serverUrl:r}});if(!r.match(/^https?:\/\//))throw new d(`Invalid serverUrl: "${r}". Must start with "http://" or "https://". For example: "http://localhost:5000" or "https://example.com"`,a.INVALID_CONFIG,{context:{serverUrl:r}});try{new URL(r)}catch(n){throw new d(`Invalid serverUrl: "${r}". Must be a valid URL. Received error: ${n instanceof Error?n.message:String(n)}`,a.INVALID_CONFIG,{context:{serverUrl:r},originalError:n instanceof Error?n:void 0})}this.apiKey=t,this.serverUrl=r.replace(/\/+$/,"")}buildHeaders(){let r={"Content-Type":"application/json"};return this.apiKey&&(r.RhinoComputeKey=this.apiKey),r}async isServerOnline(){this.ensureNotDisposed();let r=`${this.serverUrl}/healthcheck`,t={headers:this.buildHeaders(),method:"GET"};try{return(await fetch(r,t)).ok}catch(n){return p().debug("[ComputeServerStats] Fetch error:",n),!1}}async getActiveChildren(){this.ensureNotDisposed();try{let r=await fetch(`${this.serverUrl}/activechildren`,{headers:this.buildHeaders()});if(!r.ok)return p().warn("[ComputeServerStats] Failed to fetch active children:",r.status),null;let t=await r.text(),n=parseInt(t.trim(),10);return isNaN(n)?(p().warn("[ComputeServerStats] Invalid active children response:",t),null):n}catch(r){return p().warn("[ComputeServerStats] Error fetching active children:",r),null}}async getVersion(){this.ensureNotDisposed();try{let r=await fetch(`${this.serverUrl}/version`,{headers:this.buildHeaders()});if(!r.ok)return p().warn("[ComputeServerStats] Failed to fetch version:",r.status),null;try{let t=await r.json();return{rhino:_nullishCoalesce(t.rhino, () => ("")),compute:_nullishCoalesce(t.compute, () => ("")),git_sha:_nullishCoalesce(t.git_sha, () => (null))}}catch (e4){return{rhino:await r.text(),compute:"",git_sha:null}}}catch(r){return p().warn("[ComputeServerStats] Error fetching version:",r),null}}async getServerStats(){if(this.ensureNotDisposed(),!await this.isServerOnline())return{isOnline:!1};let[t,n]=await Promise.all([this.getVersion(),this.getActiveChildren()]);return{isOnline:!0,...t&&{version:t},...n!==null&&{activeChildren:n}}}monitor(r,t=5e3){this.ensureNotDisposed();let n=!0,s=null;p().info(`\u{1F504} Starting server stats monitoring every ${t}ms`);let i=async()=>{if(s!==null&&(this.activeTimeouts.delete(s),s=null),!(!n||this.disposed)){try{let o=await this.getServerStats();if(!n||this.disposed)return;try{r(o)}catch(l){p().error("[ComputeServerStats] Monitor callback threw:",l)}}catch(o){p().error("[ComputeServerStats] Failed to fetch stats during monitor:",o)}n&&!this.disposed&&(s=setTimeout(()=>{i()},t),this.activeTimeouts.add(s))}},c=()=>{n=!1,s!==null&&(clearTimeout(s),this.activeTimeouts.delete(s),s=null),this.activeMonitors.delete(c)};return this.activeMonitors.add(c),i(),c}async dispose(){if(!this.disposed){this.disposed=!0;for(let r of this.activeMonitors)r();this.activeMonitors.clear();for(let r of this.activeTimeouts)clearTimeout(r);this.activeTimeouts.clear()}}ensureNotDisposed(){if(this.disposed)throw new d("ComputeServerStats has been disposed and cannot be used",a.INVALID_STATE,{context:{disposed:this.disposed}})}};function A(e,r={}){let{preserveSpaces:t=!1}=r,n=e.trim();return t?(n=n.charAt(0).toLowerCase()+n.slice(1).replace(/[-_](.)/g,(s,i)=>i?i.toUpperCase():""),n):(n=n.replace(/^[A-Z]/,s=>s.toLowerCase()).replace(/[\s-_]+(.)?/g,(s,i)=>i?i.toUpperCase():""),n)}function C(e,r={}){return!e||typeof e!="object"?e:Array.isArray(e)?r.deep?e.map(t=>C(t,r)):e:Object.keys(e).reduce((t,n)=>{let s=A(n,{preserveSpaces:r.preserveSpaces}),i=e[n];return t[s]=r.deep?C(i,r):i,t},{})}exports.a = W; exports.b = R; exports.c = a; exports.d = d; exports.e = p; exports.f = N; exports.g = _; exports.h = V; exports.i = E; exports.j = A; exports.k = C;
|
|
3
|
-
//# sourceMappingURL=chunk-IJZNCO5X.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/chunk-IJZNCO5X.cjs","../src/core/errors/error-codes.ts","../src/core/errors/base.ts","../src/core/compute-fetch/compute-fetch.ts"],"names":["ErrorCodes","RhinoComputeError","_RhinoComputeError","message","code","options","__publicField","inputName","reason","context"],"mappings":"AAAA,qrBAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAA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BC,CAAAA,CAAgBC,CAAAA,CAAmC,CACvF,OAAO,IAAIP,CAAAA,CAAkB,CAAA,OAAA,EAAUK,CAAS,CAAA,GAAA,EAAMC,CAAM,CAAA,CAAA;AC2Wd","file":"/home/runner/work/selva-compute/selva-compute/dist/chunk-IJZNCO5X.cjs","sourcesContent":[null,"export const ErrorCodes = {\n\tNETWORK_ERROR: 'NETWORK_ERROR',\n\tAUTH_ERROR: 'AUTH_ERROR',\n\tVALIDATION_ERROR: 'VALIDATION_ERROR',\n\tCOMPUTATION_ERROR: 'COMPUTATION_ERROR',\n\tTIMEOUT_ERROR: 'TIMEOUT_ERROR',\n\tCORS_ERROR: 'CORS_ERROR',\n\tUNKNOWN_ERROR: 'UNKNOWN_ERROR',\n\tINVALID_STATE: 'INVALID_STATE',\n\tINVALID_INPUT: 'INVALID_INPUT',\n\tINVALID_CONFIG: 'INVALID_CONFIG',\n\tBROWSER_ONLY: 'BROWSER_ONLY',\n\tENVIRONMENT_ERROR: 'ENVIRONMENT_ERROR',\n\tENCODING_ERROR: 'ENCODING_ERROR'\n} as const;\n\nexport type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];\n","import { ErrorCodes } from './error-codes';\n\n/**\n * Simplified error for Rhino Compute operations\n *\n * @public Use this for error handling with error codes and context.\n */\nexport class RhinoComputeError extends Error {\n\tpublic readonly code: string;\n\tpublic readonly statusCode?: number;\n\tpublic readonly context?: Record<string, unknown>;\n\tpublic readonly originalError?: Error;\n\n\tconstructor(\n\t\tmessage: string,\n\t\tcode: string = 'UNKNOWN_ERROR',\n\t\toptions?: { statusCode?: number; context?: Record<string, unknown>; originalError?: Error }\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'RhinoComputeError';\n\t\tthis.code = code;\n\t\tthis.statusCode = options?.statusCode;\n\t\tthis.context = options?.context;\n\t\tthis.originalError = options?.originalError;\n\n\t\t// Support error chaining (Node.js 16.9+, TypeScript 4.6+)\n\t\tif ('cause' in Error.prototype) {\n\t\t\tObject.defineProperty(this, 'cause', {\n\t\t\t\tvalue: options?.originalError,\n\t\t\t\tenumerable: true\n\t\t\t});\n\t\t}\n\t}\n\n\t// ============================================================================\n\t// Static Validation Error Helpers\n\t// ============================================================================\n\n\t/**\n\t * Create a generic validation error with custom reason\n\t */\n\tstatic validation(inputName: string, reason: string, context?: Record<string, unknown>) {\n\t\treturn new RhinoComputeError(`Input \"${inputName}\": ${reason}`, ErrorCodes.VALIDATION_ERROR, {\n\t\t\tcontext: { inputName, reason, ...context }\n\t\t});\n\t}\n\n\t/**\n\t * Create an error for missing/empty values\n\t */\n\tstatic missingValues(inputName: string, expectedType?: string, context?: Record<string, unknown>) {\n\t\treturn new RhinoComputeError(\n\t\t\t`Input \"${inputName}\" has no values defined${expectedType ? ` (expected ${expectedType})` : ''}`,\n\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t{ context: { inputName, expectedType, ...context } }\n\t\t);\n\t}\n\n\t/**\n\t * Create an error for invalid default value in value list\n\t */\n\tstatic invalidDefault(\n\t\tinputName: string,\n\t\tdefaultValue: unknown,\n\t\tavailableValues: unknown[],\n\t\tcontext?: Record<string, unknown>\n\t) {\n\t\treturn new RhinoComputeError(\n\t\t\t`ValueList input \"${inputName}\" default value \"${defaultValue}\" is not in available values`,\n\t\t\tErrorCodes.VALIDATION_ERROR,\n\t\t\t{ context: { inputName, defaultValue, availableValues, ...context } }\n\t\t);\n\t}\n\n\t/**\n\t * Create an error for unknown parameter type\n\t */\n\tstatic unknownParamType(paramType: string, paramName?: string, context?: Record<string, unknown>) {\n\t\treturn new RhinoComputeError(`Unknown paramType: ${paramType}`, ErrorCodes.VALIDATION_ERROR, {\n\t\t\tcontext: { receivedParamType: paramType, paramName, ...context }\n\t\t});\n\t}\n\n\t/**\n\t * Create an error for invalid input structure\n\t */\n\tstatic invalidStructure(\n\t\tinputName: string,\n\t\texpectedStructure: string,\n\t\tcontext?: Record<string, unknown>\n\t) {\n\t\treturn new RhinoComputeError(\n\t\t\t`Invalid input structure for \"${inputName}\" (expected ${expectedStructure})`,\n\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t{ context: { inputName, expectedStructure, ...context } }\n\t\t);\n\t}\n}\n","import { RhinoComputeError, ErrorCodes } from '../errors';\nimport { getLogger } from '../utils/logger';\n\nimport type { ComputeConfig, RetryPolicy } from '../types';\nimport type {\n\tGrasshopperComputeConfig,\n\tGrasshopperComputeResponse,\n\tIoResponseSchema\n} from '@/features/grasshopper/types';\n\n/**\n * Valid endpoints for Rhino Compute (improved response type handling).\n */\nexport type Endpoint = 'grasshopper' | 'io' | string;\n\nexport type EndpointResponseMap = {\n\tgrasshopper: GrasshopperComputeResponse;\n\tio: IoResponseSchema;\n};\n\nexport type ComputeResponseFor<E extends string> = E extends keyof EndpointResponseMap\n\t? EndpointResponseMap[E]\n\t: unknown;\n\n// ============================================================================\n// Retry Policy\n// ============================================================================\n\nconst DEFAULT_RETRY: Required<RetryPolicy> = {\n\tattempts: 0,\n\tbaseDelayMs: 500,\n\tmaxDelayMs: 30_000,\n\tretryOn429: true\n};\n\nconst RETRYABLE_STATUS = new Set([502, 503, 504]);\n\nfunction resolveRetryPolicy(policy: RetryPolicy | undefined): Required<RetryPolicy> {\n\tif (!policy) return DEFAULT_RETRY;\n\treturn {\n\t\tattempts: policy.attempts ?? DEFAULT_RETRY.attempts,\n\t\tbaseDelayMs: policy.baseDelayMs ?? DEFAULT_RETRY.baseDelayMs,\n\t\tmaxDelayMs: policy.maxDelayMs ?? DEFAULT_RETRY.maxDelayMs,\n\t\tretryOn429: policy.retryOn429 ?? DEFAULT_RETRY.retryOn429\n\t};\n}\n\n/**\n * Parse a Retry-After header value (seconds-int or HTTP-date) into ms.\n * Returns null if the header is missing or unparseable.\n */\nfunction parseRetryAfter(headerValue: string | null): number | null {\n\tif (!headerValue) return null;\n\tconst seconds = Number(headerValue);\n\tif (Number.isFinite(seconds) && seconds >= 0) return seconds * 1000;\n\tconst dateMs = Date.parse(headerValue);\n\tif (Number.isFinite(dateMs)) {\n\t\tconst delta = dateMs - Date.now();\n\t\treturn delta > 0 ? delta : 0;\n\t}\n\treturn null;\n}\n\nfunction backoffDelay(attempt: number, policy: Required<RetryPolicy>): number {\n\tconst exponential = policy.baseDelayMs * Math.pow(2, attempt);\n\tconst jitter = Math.random() * policy.baseDelayMs;\n\treturn Math.min(exponential + jitter, policy.maxDelayMs);\n}\n\nfunction sleep(ms: number, signal?: AbortSignal): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tif (signal?.aborted) {\n\t\t\treject(new DOMException('Aborted', 'AbortError'));\n\t\t\treturn;\n\t\t}\n\t\tconst id = setTimeout(() => {\n\t\t\tsignal?.removeEventListener('abort', onAbort);\n\t\t\tresolve();\n\t\t}, ms);\n\t\tconst onAbort = () => {\n\t\t\tclearTimeout(id);\n\t\t\treject(new DOMException('Aborted', 'AbortError'));\n\t\t};\n\t\tsignal?.addEventListener('abort', onAbort, { once: true });\n\t});\n}\n\n// ============================================================================\n// Error Handling\n// ============================================================================\n\nfunction throwHttpError(\n\tresponse: Response,\n\tfullUrl: string,\n\trequestId: string,\n\trequestSize: number,\n\tserverUrl: string,\n\terrorBody: string\n): never {\n\tconst { status, statusText } = response;\n\tconst context = { url: fullUrl, requestId, method: 'POST', requestSize, serverUrl };\n\n\tconst bodyHint = errorBody ? ` — ${errorBody.slice(0, 200)}` : '';\n\tconst errorMap: Record<number, { message: string; code: string }> = {\n\t\t401: {\n\t\t\tmessage: `HTTP ${status}: ${statusText}${bodyHint}`,\n\t\t\tcode: ErrorCodes.AUTH_ERROR\n\t\t},\n\t\t403: {\n\t\t\tmessage: `HTTP ${status}: ${statusText}${bodyHint}`,\n\t\t\tcode: ErrorCodes.AUTH_ERROR\n\t\t},\n\t\t404: { message: `Endpoint not found: ${fullUrl}`, code: ErrorCodes.NETWORK_ERROR },\n\t\t413: {\n\t\t\tmessage: `Request too large: ${(requestSize / 1024).toFixed(2)}KB`,\n\t\t\tcode: ErrorCodes.VALIDATION_ERROR\n\t\t},\n\t\t429: { message: 'Rate limit exceeded', code: ErrorCodes.NETWORK_ERROR },\n\t\t500: {\n\t\t\tmessage: `Server error: ${errorBody || statusText}`,\n\t\t\tcode: ErrorCodes.COMPUTATION_ERROR\n\t\t},\n\t\t502: { message: `Service unavailable: ${statusText}`, code: ErrorCodes.NETWORK_ERROR },\n\t\t503: { message: `Service unavailable: ${statusText}`, code: ErrorCodes.NETWORK_ERROR },\n\t\t504: { message: `Service unavailable: ${statusText}`, code: ErrorCodes.NETWORK_ERROR }\n\t};\n\n\tconst error = errorMap[status] || {\n\t\tmessage: `HTTP ${status}: ${statusText}`,\n\t\tcode: ErrorCodes.UNKNOWN_ERROR\n\t};\n\n\tthrow new RhinoComputeError(error.message, error.code, { statusCode: status, context });\n}\n\n// ============================================================================\n// Request Helpers\n// ============================================================================\n\nfunction buildUrl(endpoint: string, serverUrl: string): string {\n\tconst base = serverUrl.replace(/\\/+$/, '');\n\tconst path = endpoint.replace(/^\\/+/, '');\n\treturn `${base}/${path}`;\n}\n\nfunction isLocalhost(serverUrl: string): boolean {\n\ttry {\n\t\tconst host = new URL(serverUrl).host;\n\t\treturn /^(localhost|127\\.0\\.0\\.1|::1)(:\\d+)?$/i.test(host);\n\t} catch {\n\t\treturn /(localhost|127\\.0\\.0\\.1)/i.test(serverUrl);\n\t}\n}\n\nfunction buildHeaders(requestId: string, config: ComputeConfig): HeadersInit {\n\tconst headers: HeadersInit = {\n\t\t'X-Request-ID': requestId,\n\t\t'Content-Type': 'application/json',\n\t\t...(config.authToken && { Authorization: config.authToken }),\n\t\t...(config.apiKey && { RhinoComputeKey: config.apiKey })\n\t};\n\n\tif (!config.apiKey && !isLocalhost(config.serverUrl)) {\n\t\tgetLogger().warn(\n\t\t\t`⚠️ [Rhino Compute] Request [${requestId}] targets remote server (${config.serverUrl}) but no API key is configured. Requests may fail or be rate-limited.`\n\t\t);\n\t}\n\n\treturn headers;\n}\n\nfunction generateRequestId(): string {\n\treturn `${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;\n}\n\nfunction log(message: string, debug?: boolean): void {\n\tif (debug) getLogger().debug(message);\n}\n\n/**\n * Compose a caller-supplied AbortSignal with an optional timeout. Returns a\n * combined signal, or `undefined` if neither was given.\n *\n * Uses `AbortSignal.timeout` (not setTimeout) so the timer is not throttled\n * when the tab is hidden. Falls back to a manual timer for older runtimes.\n */\nfunction composeSignal(\n\tcallerSignal: AbortSignal | undefined,\n\ttimeoutMs: number | undefined\n): { signal: AbortSignal | undefined; cleanup: () => void } {\n\tconst signals: AbortSignal[] = [];\n\tlet cleanup = () => {};\n\n\tif (callerSignal) signals.push(callerSignal);\n\n\tif (timeoutMs && timeoutMs > 0) {\n\t\tif (typeof AbortSignal !== 'undefined' && typeof AbortSignal.timeout === 'function') {\n\t\t\tsignals.push(AbortSignal.timeout(timeoutMs));\n\t\t} else {\n\t\t\t// Fallback for runtimes without AbortSignal.timeout\n\t\t\tconst ctrl = new AbortController();\n\t\t\tconst id = setTimeout(() => ctrl.abort(), timeoutMs);\n\t\t\tcleanup = () => clearTimeout(id);\n\t\t\tsignals.push(ctrl.signal);\n\t\t}\n\t}\n\n\tif (signals.length === 0) return { signal: undefined, cleanup };\n\tif (signals.length === 1) return { signal: signals[0], cleanup };\n\n\tif (typeof AbortSignal !== 'undefined' && typeof (AbortSignal as any).any === 'function') {\n\t\treturn { signal: (AbortSignal as any).any(signals) as AbortSignal, cleanup };\n\t}\n\n\t// Manual composition fallback\n\tconst ctrl = new AbortController();\n\tconst onAbort = () => ctrl.abort();\n\tfor (const s of signals) {\n\t\tif (s.aborted) {\n\t\t\tctrl.abort();\n\t\t\tbreak;\n\t\t}\n\t\ts.addEventListener('abort', onAbort, { once: true });\n\t}\n\tconst prevCleanup = cleanup;\n\tcleanup = () => {\n\t\tprevCleanup();\n\t\tfor (const s of signals) s.removeEventListener('abort', onAbort);\n\t};\n\treturn { signal: ctrl.signal, cleanup };\n}\n\n// ============================================================================\n// Response Processing\n// ============================================================================\n\nasync function handleResponse(\n\tresponse: Response,\n\tfullUrl: string,\n\trequestId: string,\n\trequestSize: number,\n\tserverUrl: string,\n\tstartTime: number,\n\tdebug?: boolean\n): Promise<any> {\n\tconst responseTime = Math.round(performance.now() - startTime);\n\n\tif (!response.ok) {\n\t\t// Read body once and reuse\n\t\tlet errorBody = await response.text();\n\n\t\t// Enhanced logging for errors\n\t\tif (debug) {\n\t\t\tlog(\n\t\t\t\t`❌ Request [${requestId}] failed with HTTP ${response.status} in ${responseTime}ms`,\n\t\t\t\ttrue\n\t\t\t);\n\t\t\tlog(` URL: ${fullUrl}`, true);\n\t\t\tlog(` Status: ${response.status} ${response.statusText}`, true);\n\t\t\tif (errorBody) {\n\t\t\t\tlog(\n\t\t\t\t\t` Response body: ${errorBody.substring(0, 500)}${errorBody.length > 500 ? '...' : ''}`,\n\t\t\t\t\ttrue\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Check if it's a valid compute response with errors/warnings\n\t\tif (response.status === 500) {\n\t\t\ttry {\n\t\t\t\tconst parsed = JSON.parse(errorBody);\n\t\t\t\t// If it has values, it's a partial success with errors\n\t\t\t\tif (parsed?.values && (parsed.errors || parsed.warnings)) {\n\t\t\t\t\tif (debug) {\n\t\t\t\t\t\tlog(\n\t\t\t\t\t\t\t`⚠️ Request [${requestId}] completed with Grasshopper errors in ${responseTime}ms`,\n\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (parsed.errors?.length > 0) {\n\t\t\t\t\t\t\tlog(` Errors: ${JSON.stringify(parsed.errors, null, 2)}`, true);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (parsed.warnings?.length > 0) {\n\t\t\t\t\t\t\tlog(` Warnings: ${JSON.stringify(parsed.warnings, null, 2)}`, true);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn parsed;\n\t\t\t\t}\n\n\t\t\t\t// If it's a raw exception from the server (like ArgumentException), include it in the error message\n\t\t\t\tif (parsed?.Message) {\n\t\t\t\t\terrorBody = `${parsed.ExceptionType ? parsed.ExceptionType + ': ' : ''}${parsed.Message}\\n${parsed.StackTrace || ''}`;\n\t\t\t\t} else if (parsed?.error) {\n\t\t\t\t\terrorBody =\n\t\t\t\t\t\ttypeof parsed.error === 'string' ? parsed.error : JSON.stringify(parsed.error, null, 2);\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tif (debug) {\n\t\t\t\t\tlog(` Failed to parse error body as JSON: ${e}`, true);\n\t\t\t\t}\n\t\t\t\t// Not valid JSON, proceed with HTTP error\n\t\t\t}\n\t\t}\n\n\t\tthrowHttpError(response, fullUrl, requestId, requestSize, serverUrl, errorBody);\n\t}\n\n\tlog(`✅ Request [${requestId}] completed in ${responseTime}ms`, debug);\n\n\ttry {\n\t\treturn await response.json();\n\t} catch (error) {\n\t\tthrow new RhinoComputeError('Failed to parse JSON response', ErrorCodes.NETWORK_ERROR, {\n\t\t\tstatusCode: response.status,\n\t\t\tcontext: {\n\t\t\t\turl: fullUrl,\n\t\t\t\trequestId\n\t\t\t},\n\t\t\toriginalError: error instanceof Error ? error : new Error(String(error))\n\t\t});\n\t}\n}\n\n// ============================================================================\n// Single attempt\n// ============================================================================\n\ninterface AttemptContext {\n\tendpoint: string;\n\tbody: string;\n\trequestSize: number;\n\tfullUrl: string;\n\trequestId: string;\n\theaders: HeadersInit;\n\tconfig: ComputeConfig | GrasshopperComputeConfig;\n}\n\ninterface AttemptResult {\n\tok: true;\n\tvalue: any;\n}\n\ninterface AttemptRetry {\n\tok: false;\n\tretry: true;\n\tdelayMs: number;\n\tcause: RhinoComputeError;\n}\n\ninterface AttemptFatal {\n\tok: false;\n\tretry: false;\n\tcause: RhinoComputeError;\n}\n\nasync function attemptFetch(\n\tctx: AttemptContext,\n\tretryPolicy: Required<RetryPolicy>,\n\tattempt: number,\n\ttotalAttempts: number\n): Promise<AttemptResult | AttemptRetry | AttemptFatal> {\n\tconst { signal, cleanup } = composeSignal(ctx.config.signal, ctx.config.timeoutMs);\n\tconst startTime = performance.now();\n\n\ttry {\n\t\tconst response = await fetch(ctx.fullUrl, {\n\t\t\tmethod: 'POST',\n\t\t\tbody: ctx.body,\n\t\t\theaders: ctx.headers,\n\t\t\tsignal\n\t\t});\n\n\t\t// 429 with Retry-After or retryable 5xx → maybe retry\n\t\tconst isRetryableStatus =\n\t\t\tRETRYABLE_STATUS.has(response.status) ||\n\t\t\t(retryPolicy.retryOn429 && response.status === 429);\n\n\t\tif (isRetryableStatus && attempt < totalAttempts - 1) {\n\t\t\tconst retryAfterMs = parseRetryAfter(response.headers.get('Retry-After'));\n\t\t\tconst delayMs = retryAfterMs ?? backoffDelay(attempt, retryPolicy);\n\t\t\t// Drain the body so the connection can be reused\n\t\t\tawait response.text().catch(() => {});\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\tretry: true,\n\t\t\t\tdelayMs,\n\t\t\t\tcause: new RhinoComputeError(\n\t\t\t\t\t`HTTP ${response.status} ${response.statusText} (will retry)`,\n\t\t\t\t\tErrorCodes.NETWORK_ERROR,\n\t\t\t\t\t{ statusCode: response.status, context: { requestId: ctx.requestId } }\n\t\t\t\t)\n\t\t\t};\n\t\t}\n\n\t\tconst value = await handleResponse(\n\t\t\tresponse,\n\t\t\tctx.fullUrl,\n\t\t\tctx.requestId,\n\t\t\tctx.requestSize,\n\t\t\tctx.config.serverUrl,\n\t\t\tstartTime,\n\t\t\tctx.config.debug\n\t\t);\n\t\treturn { ok: true, value };\n\t} catch (error) {\n\t\t// Caller-aborted vs timeout-aborted distinction\n\t\tif (error instanceof Error && (error.name === 'AbortError' || error.name === 'TimeoutError')) {\n\t\t\tconst callerAborted = ctx.config.signal?.aborted === true;\n\n\t\t\tif (callerAborted) {\n\t\t\t\t// Caller cancellation is never retried — propagate immediately\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\tretry: false,\n\t\t\t\t\tcause: new RhinoComputeError('Request aborted by caller', ErrorCodes.UNKNOWN_ERROR, {\n\t\t\t\t\t\tcontext: {\n\t\t\t\t\t\t\tendpoint: ctx.endpoint,\n\t\t\t\t\t\t\trequestId: ctx.requestId,\n\t\t\t\t\t\t\trequestSize: ctx.requestSize\n\t\t\t\t\t\t},\n\t\t\t\t\t\toriginalError: error\n\t\t\t\t\t})\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Timeout — retryable up to attempts limit\n\t\t\tconst fatal = new RhinoComputeError(\n\t\t\t\t`Request timed out after ${ctx.config.timeoutMs}ms`,\n\t\t\t\tErrorCodes.TIMEOUT_ERROR,\n\t\t\t\t{\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\tserverUrl: ctx.config.serverUrl,\n\t\t\t\t\t\ttimeoutMs: ctx.config.timeoutMs,\n\t\t\t\t\t\turl: ctx.fullUrl,\n\t\t\t\t\t\trequestId: ctx.requestId,\n\t\t\t\t\t\tendpoint: ctx.endpoint,\n\t\t\t\t\t\trequestSize: ctx.requestSize\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t);\n\t\t\tif (attempt < totalAttempts - 1) {\n\t\t\t\treturn { ok: false, retry: true, delayMs: backoffDelay(attempt, retryPolicy), cause: fatal };\n\t\t\t}\n\t\t\treturn { ok: false, retry: false, cause: fatal };\n\t\t}\n\n\t\t// Network error (TypeError) — retryable\n\t\tif (error instanceof TypeError) {\n\t\t\tconst fatal = new RhinoComputeError(\n\t\t\t\t`Network error: ${error.message}`,\n\t\t\t\tErrorCodes.NETWORK_ERROR,\n\t\t\t\t{\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\tserverUrl: ctx.config.serverUrl,\n\t\t\t\t\t\turl: ctx.fullUrl,\n\t\t\t\t\t\trequestId: ctx.requestId,\n\t\t\t\t\t\tendpoint: ctx.endpoint,\n\t\t\t\t\t\trequestSize: ctx.requestSize\n\t\t\t\t\t},\n\t\t\t\t\toriginalError: error\n\t\t\t\t}\n\t\t\t);\n\t\t\tif (attempt < totalAttempts - 1) {\n\t\t\t\treturn { ok: false, retry: true, delayMs: backoffDelay(attempt, retryPolicy), cause: fatal };\n\t\t\t}\n\t\t\treturn { ok: false, retry: false, cause: fatal };\n\t\t}\n\n\t\t// RhinoComputeError thrown from handleResponse — already has full context.\n\t\t// Retryable only if it carries a retryable status code.\n\t\tif (error instanceof RhinoComputeError) {\n\t\t\tconst status = error.statusCode;\n\t\t\tconst retryable =\n\t\t\t\tstatus !== undefined &&\n\t\t\t\t(RETRYABLE_STATUS.has(status) || (retryPolicy.retryOn429 && status === 429));\n\t\t\tif (retryable && attempt < totalAttempts - 1) {\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\tretry: true,\n\t\t\t\t\tdelayMs: backoffDelay(attempt, retryPolicy),\n\t\t\t\t\tcause: error\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn { ok: false, retry: false, cause: error };\n\t\t}\n\n\t\t// Unknown — wrap and don't retry\n\t\treturn {\n\t\t\tok: false,\n\t\t\tretry: false,\n\t\t\tcause: new RhinoComputeError(\n\t\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t\tErrorCodes.UNKNOWN_ERROR,\n\t\t\t\t{\n\t\t\t\t\tcontext: { endpoint: ctx.endpoint, requestId: ctx.requestId },\n\t\t\t\t\toriginalError: error instanceof Error ? error : new Error(String(error))\n\t\t\t\t}\n\t\t\t)\n\t\t};\n\t} finally {\n\t\tcleanup();\n\t}\n}\n\n// ============================================================================\n// Main Function\n// ============================================================================\n\n/**\n * Generic Rhino Compute fetch function.\n * Sends a POST request to any Compute endpoint with pre-prepared arguments.\n *\n * Use this for advanced, low-level control over compute requests. For most use cases, prefer higher-level APIs.\n *\n * @typeParam E - The endpoint name (e.g., 'grasshopper', 'io'). Determines the response type for better type safety.\n * @param endpoint - The Compute API endpoint (e.g., 'grasshopper', 'io', 'mesh').\n * @param args - Pre-prepared arguments for the request body.\n * @param config - Compute configuration (server URL, API key, timeout, debug, retry, signal).\n * @returns The parsed JSON response from the server, typed according to the endpoint.\n *\n * @example\n * // Basic usage for the Grasshopper endpoint:\n * const response = await fetchRhinoCompute(\n * 'grasshopper',\n * { ... },\n * {\n * serverUrl: 'https://my-server.com',\n * debug: true,\n * timeoutMs: 30_000,\n * retry: { attempts: 2 },\n * signal: controller.signal,\n * }\n * );\n */\nexport async function fetchRhinoCompute<E extends Endpoint>(\n\tendpoint: E,\n\targs: Record<string, any>,\n\tconfig: ComputeConfig | GrasshopperComputeConfig\n): Promise<ComputeResponseFor<E>> {\n\tconst requestId = generateRequestId();\n\tconst body = JSON.stringify(args);\n\tconst requestSize = body.length;\n\tconst fullUrl = buildUrl(endpoint, config.serverUrl);\n\tconst headers = buildHeaders(requestId, config);\n\tconst retryPolicy = resolveRetryPolicy(config.retry);\n\tconst totalAttempts = retryPolicy.attempts + 1;\n\n\tif (config.debug) {\n\t\tconst sizeKb = (requestSize / 1024).toFixed(2);\n\t\tconst emoji = requestSize > 100000 ? '⚠️' : '🚀';\n\t\tlog(`${emoji} Starting compute request [${requestId}]: ${endpoint} (${sizeKb}KB)`, true);\n\t}\n\n\tconst ctx: AttemptContext = {\n\t\tendpoint,\n\t\tbody,\n\t\trequestSize,\n\t\tfullUrl,\n\t\trequestId,\n\t\theaders,\n\t\tconfig\n\t};\n\n\tlet lastError: RhinoComputeError | null = null;\n\n\tfor (let attempt = 0; attempt < totalAttempts; attempt++) {\n\t\tconst result = await attemptFetch(ctx, retryPolicy, attempt, totalAttempts);\n\n\t\tif (result.ok) return result.value as ComputeResponseFor<E>;\n\n\t\tif (!result.retry) throw result.cause;\n\n\t\tlastError = result.cause;\n\t\tif (config.debug) {\n\t\t\tlog(\n\t\t\t\t`🔁 Request [${requestId}] retrying after ${result.delayMs}ms (attempt ${attempt + 2}/${totalAttempts}): ${result.cause.message}`,\n\t\t\t\ttrue\n\t\t\t);\n\t\t}\n\n\t\ttry {\n\t\t\tawait sleep(result.delayMs, config.signal);\n\t\t} catch {\n\t\t\t// Caller cancelled during backoff\n\t\t\tthrow new RhinoComputeError('Request aborted by caller', ErrorCodes.UNKNOWN_ERROR, {\n\t\t\t\tcontext: { endpoint, requestId, requestSize },\n\t\t\t\toriginalError: lastError\n\t\t\t});\n\t\t}\n\t}\n\n\t// Exhausted retries — throw the last seen error\n\tthrow (\n\t\tlastError ??\n\t\tnew RhinoComputeError('Unknown error after retries', ErrorCodes.UNKNOWN_ERROR, {\n\t\t\tcontext: { endpoint, requestId, requestSize }\n\t\t})\n\t);\n}\n"]}
|
package/dist/chunk-LNIUUPA5.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _chunkIJZNCO5Xcjs = require('./chunk-IJZNCO5X.cjs');function v(r){return Buffer.from(r,"utf-8").toString("base64")}function T(r){return!r||r.length<2||r.length%4!==0?!1:/^[A-Za-z0-9+/]+={0,2}$/.test(r)}function S(r){if(typeof globalThis.Buffer=="function"){let e=globalThis.Buffer.from(r,"base64");return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}if(typeof globalThis.atob=="function"){let e=globalThis.atob(r),n=new Uint8Array(e.length);for(let a=0;a<e.length;a++)n[a]=e.charCodeAt(a)&255;return n}throw new (0, _chunkIJZNCO5Xcjs.d)("Base64 decoding not supported in this environment.",_chunkIJZNCO5Xcjs.c.INVALID_STATE,{context:{environmentInfo:"atob or Buffer not available"}})}function C(r){if(r==null)throw new (0, _chunkIJZNCO5Xcjs.d)("Input bytes must not be null or undefined",_chunkIJZNCO5Xcjs.c.INVALID_INPUT,{context:{receivedValue:r}});let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=r;n.length>=3&&n[0]===239&&n[1]===187&&n[2]===191&&(n=n.slice(3));let a=n.byteLength,y=a%3,u=a-y,b="",o,i,c,l,d;for(let t=0;t<u;t+=3){let f=n[t]!==void 0?n[t]:0,h=n[t+1]!==void 0?n[t+1]:0,g=n[t+2]!==void 0?n[t+2]:0,s=f<<16|h<<8|g;if(o=(s&16515072)>>18,i=(s&258048)>>12,c=(s&4032)>>6,l=s&63,typeof e!="string")throw new Error("encodings must be a string");if(typeof o!="number"||o<0||o>=e.length)throw new Error("Invalid index a");if(typeof i!="number"||i<0||i>=e.length)throw new Error("Invalid index b");if(typeof c!="number"||c<0||c>=e.length)throw new Error("Invalid index c");if(typeof l!="number"||l<0||l>=e.length)throw new Error("Invalid index d");let w=e[o],B=e[i],x=e[c],I=e[l];if(w===void 0||B===void 0||x===void 0||I===void 0)throw new Error("Invalid encoding index");b+=w+B+x+I}if(y===1){if(d=n[u],d===void 0)throw new Error("'chunk' must not be undefined");o=(d&252)>>2,i=(d&3)<<4;let t=e[o],f=e[i];if(t===void 0||f===void 0)throw new Error("Invalid encoding index");b+=`${t+f}==`}else if(y===2){let t=_nullishCoalesce(n[u], () => (0)),f=n[u+1]!==void 0?n[u+1]:0;if(typeof t!="number"||t<0||t>255||typeof f!="number"||f<0||f>255)throw new Error("Invalid byte1");d=t<<8|f,o=(d&64512)>>10,i=(d&1008)>>4,c=(d&15)<<2;let h=e[o],g=e[i],s=e[c];if(h===void 0||g===void 0||s===void 0)throw new Error("Invalid encoding index");b+=`${h+g+s}=`}return b}exports.a = v; exports.b = T; exports.c = S; exports.d = C;
|
|
2
|
-
//# sourceMappingURL=chunk-LNIUUPA5.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/chunk-LNIUUPA5.cjs","../src/core/utils/encoding.ts"],"names":["encodeStringToBase64","str","isBase64","decodeBase64ToBinary","base64File","buf","binary","bytes","i","RhinoComputeError","ErrorCodes","base64ByteArray","encodings","inputBytes","byteLength","byteRemainder","mainLength","base64","a","b","d","chunk","byte1","byte2","byte3","innerChunk","charA","charB","charC","charD"],"mappings":"AAAA,qOAA+C,SCY/BA,CAAAA,CAAqBC,C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AAA,GAAU,KAAA,CAAA,EAAaC,CAAAA,GAAU,KAAA,CAAA,EAAaC,CAAAA,GAAU,KAAA,CAAA,EAAaC,CAAAA,GAAU,KAAA,CAAA,CAClF,MAAM,IAAI,KAAA,CAAM,wBAAwB,CAAA,CAGzCZ,CAAAA,EAAUS,CAAAA,CAAQC,CAAAA,CAAQC,CAAAA,CAAQC,CACnC,CAGA,EAAA,CAAId,CAAAA,GAAkB,CAAA,CAAG,CAGxB,EAAA,CAFAM,CAAAA,CAAQR,CAAAA,CAAWG,CAAU,CAAA,CAEzBK,CAAAA,GAAU,KAAA,CAAA,CACb,MAAM,IAAI,KAAA,CAAM,+BAA+B,CAAA,CAGhDH,CAAAA,CAAAA,CAAKG,CAAAA,CAAQ,GAAA,CAAA,EAAQ,CAAA,CACrBF,CAAAA,CAAAA,CAAKE,CAAAA,CAAQ,CAAA,CAAA,EAAM,CAAA,CAEnB,IAAMK,CAAAA,CAAQd,CAAAA,CAAUM,CAAC,CAAA,CACnBS,CAAAA,CAAQf,CAAAA,CAAUO,CAAC,CAAA,CAEzB,EAAA,CAAIO,CAAAA,GAAU,KAAA,CAAA,EAAaC,CAAAA,GAAU,KAAA,CAAA,CACpC,MAAM,IAAI,KAAA,CAAM,wBAAwB,CAAA,CAGzCV,CAAAA,EAAU,CAAA,EAAA","file":"/home/runner/work/selva-compute/selva-compute/dist/chunk-LNIUUPA5.cjs","sourcesContent":[null,"import { RhinoComputeError } from '../errors/base';\nimport { ErrorCodes } from '../errors/error-codes';\nimport { getLogger } from './logger';\n\n/**\n * Encodes a string to base64 (Node 20+ safe)\n *\n * @internal Internal encoding helper — kept internal to `@selvajs/compute`.\n *\n * @param str - String to encode\n * @returns Base64 encoded string\n */\nexport function encodeStringToBase64(str: string): string {\n\treturn Buffer.from(str, 'utf-8').toString('base64');\n}\n\n/**\n * Decodes a base64 string to a UTF-8 string (Node 20+ safe)\n *\n * @internal Internal encoding helper — kept internal to `@selvajs/compute`.\n *\n * @param base64Str - Base64 encoded string\n * @returns Decoded UTF-8 string\n */\nexport function decodeBase64ToString(base64Str: string): string {\n\treturn Buffer.from(base64Str, 'base64').toString('utf-8');\n}\n\n/**\n * Checks if a string is valid base64\n *\n * @internal Internal encoding helper — kept internal to `@selvajs/compute`.\n *\n * @param str - String to check\n * @returns True if the string is valid base64\n */\nexport function isBase64(str: string): boolean {\n\tif (!str || str.length < 2) return false;\n\t// Length must be a multiple of 4, only alphabet chars + at most 2 trailing '='\n\tif (str.length % 4 !== 0) return false;\n\treturn /^[A-Za-z0-9+/]+={0,2}$/.test(str);\n}\n\n/**\n * Decodes a base64 string to binary data (Uint8Array)\n *\n * @internal Internal encoding helper — kept internal to `@selvajs/compute`.\n *\n * @param base64File - Base64 encoded string\n * @returns Decoded binary data as Uint8Array\n * @throws {RhinoComputeError} If base64 decoding is not supported in this environment.\n */\nexport function decodeBase64ToBinary(base64File: string): Uint8Array {\n\t// Prefer Buffer in Node — it's faster and avoids the latin-1 string detour\n\t// that atob + charCodeAt requires.\n\tif (typeof (globalThis as any).Buffer === 'function') {\n\t\tconst buf = (globalThis as any).Buffer.from(base64File, 'base64');\n\t\treturn new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);\n\t}\n\tif (typeof globalThis.atob === 'function') {\n\t\tconst binary = globalThis.atob(base64File);\n\t\tconst bytes = new Uint8Array(binary.length);\n\t\tfor (let i = 0; i < binary.length; i++) {\n\t\t\tbytes[i] = binary.charCodeAt(i) & 0xff;\n\t\t}\n\t\treturn bytes;\n\t}\n\n\tthrow new RhinoComputeError(\n\t\t'Base64 decoding not supported in this environment.',\n\t\tErrorCodes.INVALID_STATE,\n\t\t{ context: { environmentInfo: 'atob or Buffer not available' } }\n\t);\n}\n\n/**\n * Encodes binary data (Uint8Array) to base64 string\n *\n * @internal Internal encoding helper — kept internal to `@selvajs/compute`.\n *\n * Source: https://github.com/mcneel/compute.rhino3d.appserver/blob/92c95a3b1d076a4d4a5360214ffd27c46425ff03/src/examples/convert/scriptjs\n * https://gist.github.com/jonleighton/958841\n *\n * MIT LICENSE\n * Copyright 2011 Jon Leighton\n * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\nexport function base64ByteArray(bytes: Uint8Array | null | undefined): string {\n\tif (bytes === null || bytes === undefined) {\n\t\tthrow new RhinoComputeError(\n\t\t\t'Input bytes must not be null or undefined',\n\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t{ context: { receivedValue: bytes } }\n\t\t);\n\t}\n\n\tconst encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n\n\tlet inputBytes = bytes;\n\n\t// strip bom (Byte Order Mark)\n\tif (\n\t\tinputBytes.length >= 3 &&\n\t\tinputBytes[0] === 239 &&\n\t\tinputBytes[1] === 187 &&\n\t\tinputBytes[2] === 191\n\t) {\n\t\tinputBytes = inputBytes.slice(3);\n\t}\n\n\tconst byteLength = inputBytes.byteLength;\n\tconst byteRemainder = byteLength % 3;\n\tconst mainLength = byteLength - byteRemainder;\n\n\tlet base64 = '';\n\tlet a, b, c, d;\n\tlet chunk;\n\n\t// Main loop deals with bytes in chunks of 3\n\tfor (let i = 0; i < mainLength; i += 3) {\n\t\t// Combine the three bytes into a single integer\n\n\t\tconst byte1 = inputBytes[i] !== undefined ? inputBytes[i] : 0;\n\t\tconst byte2 = inputBytes[i + 1] !== undefined ? inputBytes[i + 1] : 0;\n\t\tconst byte3 = inputBytes[i + 2] !== undefined ? inputBytes[i + 2] : 0;\n\n\t\tconst innerChunk = (byte1 << 16) | (byte2 << 8) | byte3;\n\n\t\t// Use bitmasks to extract 6-bit segments from the triplet\n\t\ta = (innerChunk & 16515072) >> 18;\n\t\tb = (innerChunk & 258048) >> 12;\n\t\tc = (innerChunk & 4032) >> 6;\n\t\td = innerChunk & 63;\n\n\t\t// Convert the raw binary segments to the appropriate ASCII encoding\n\t\tif (typeof encodings !== 'string') {\n\t\t\tthrow new Error('encodings must be a string');\n\t\t}\n\n\t\tif (typeof a !== 'number' || a < 0 || a >= encodings.length) {\n\t\t\tthrow new Error('Invalid index a');\n\t\t}\n\n\t\tif (typeof b !== 'number' || b < 0 || b >= encodings.length) {\n\t\t\tthrow new Error('Invalid index b');\n\t\t}\n\n\t\tif (typeof c !== 'number' || c < 0 || c >= encodings.length) {\n\t\t\tthrow new Error('Invalid index c');\n\t\t}\n\n\t\tif (typeof d !== 'number' || d < 0 || d >= encodings.length) {\n\t\t\tthrow new Error('Invalid index d');\n\t\t}\n\n\t\tconst charA = encodings[a];\n\t\tconst charB = encodings[b];\n\t\tconst charC = encodings[c];\n\t\tconst charD = encodings[d];\n\n\t\tif (charA === undefined || charB === undefined || charC === undefined || charD === undefined) {\n\t\t\tthrow new Error('Invalid encoding index');\n\t\t}\n\n\t\tbase64 += charA + charB + charC + charD;\n\t}\n\n\t// Deal with the remaining bytes and padding\n\tif (byteRemainder === 1) {\n\t\tchunk = inputBytes[mainLength];\n\n\t\tif (chunk === undefined) {\n\t\t\tthrow new Error(\"'chunk' must not be undefined\");\n\t\t}\n\n\t\ta = (chunk & 252) >> 2;\n\t\tb = (chunk & 3) << 4;\n\n\t\tconst charA = encodings[a];\n\t\tconst charB = encodings[b];\n\n\t\tif (charA === undefined || charB === undefined) {\n\t\t\tthrow new Error('Invalid encoding index');\n\t\t}\n\n\t\tbase64 += `${charA + charB}==`;\n\t} else if (byteRemainder === 2) {\n\t\tconst byte1 = inputBytes[mainLength] ?? 0;\n\t\tconst byte2 = inputBytes[mainLength + 1] !== undefined ? inputBytes[mainLength + 1] : 0;\n\n\t\tif (\n\t\t\ttypeof byte1 !== 'number' ||\n\t\t\tbyte1 < 0 ||\n\t\t\tbyte1 > 255 ||\n\t\t\ttypeof byte2 !== 'number' ||\n\t\t\tbyte2 < 0 ||\n\t\t\tbyte2 > 255\n\t\t) {\n\t\t\tthrow new Error('Invalid byte1');\n\t\t}\n\n\t\tchunk = (byte1 << 8) | byte2;\n\n\t\ta = (chunk & 64512) >> 10;\n\t\tb = (chunk & 1008) >> 4;\n\t\tc = (chunk & 15) << 2;\n\n\t\tconst charA = encodings[a];\n\t\tconst charB = encodings[b];\n\t\tconst charC = encodings[c];\n\n\t\tif (charA === undefined || charB === undefined || charC === undefined) {\n\t\t\tthrow new Error('Invalid encoding index');\n\t\t}\n\n\t\tbase64 += `${charA + charB + charC}=`;\n\t}\n\n\treturn base64;\n}\n\n/**\n * Convert base64 string to rhino object\n *\n * @internal Internal helper for decoding Rhino objects — not public API.\n *\n * Source: https://github.com/mcneel/compute.rhino3d.appserver/blob/92c95a3b1d076a4d4a5360214ffd27c46425ff03/src/examples/convert/scriptjs\n * @param rhino is the rhino module form rhino3dm. Since not properly typed its not used here.\n * @param item\n * @returns\n */\nexport function base64ToRhinoObject(\n\trhino: any,\n\titem: {\n\t\ttype: string;\n\t\tdata: string;\n\t}\n) {\n\t//Make a type definition for this?\n\tlet decodata: null | object = null;\n\ttry {\n\t\tdecodata = JSON.parse(item.data);\n\t} catch (error) {\n\t\tdecodata = item;\n\t\tgetLogger().warn('Failed to parse JSON, returning original data:', error, item);\n\t}\n\tif (item.type === 'System.String') {\n\t\ttry {\n\t\t\treturn rhino.DracoCompression.decompressBase64String(decodata);\n\t\t} catch (error) {\n\t\t\tgetLogger().error('Failed to decompress Draco base64 string:', error);\n\t\t}\n\t} else if (\n\t\ttypeof decodata === 'object' &&\n\t\tObject.prototype.hasOwnProperty.call(decodata, 'opennurbs')\n\t) {\n\t\treturn rhino.CommonObject.decode(decodata);\n\t} else if (typeof decodata === 'object') {\n\t\ttry {\n\t\t\treturn rhino.CommonObject.decode(decodata);\n\t\t} catch (error) {\n\t\t\tgetLogger().error('Failed to decode Rhino object:', error);\n\t\t}\n\t}\n}\n"]}
|
package/dist/chunk-PZ4HZLFJ.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{c as p,d as m}from"./chunk-VK2TSW7S.js";function v(r){return Buffer.from(r,"utf-8").toString("base64")}function T(r){return!r||r.length<2||r.length%4!==0?!1:/^[A-Za-z0-9+/]+={0,2}$/.test(r)}function S(r){if(typeof globalThis.Buffer=="function"){let e=globalThis.Buffer.from(r,"base64");return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}if(typeof globalThis.atob=="function"){let e=globalThis.atob(r),n=new Uint8Array(e.length);for(let a=0;a<e.length;a++)n[a]=e.charCodeAt(a)&255;return n}throw new m("Base64 decoding not supported in this environment.",p.INVALID_STATE,{context:{environmentInfo:"atob or Buffer not available"}})}function C(r){if(r==null)throw new m("Input bytes must not be null or undefined",p.INVALID_INPUT,{context:{receivedValue:r}});let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=r;n.length>=3&&n[0]===239&&n[1]===187&&n[2]===191&&(n=n.slice(3));let a=n.byteLength,y=a%3,u=a-y,b="",o,i,c,l,d;for(let t=0;t<u;t+=3){let f=n[t]!==void 0?n[t]:0,h=n[t+1]!==void 0?n[t+1]:0,g=n[t+2]!==void 0?n[t+2]:0,s=f<<16|h<<8|g;if(o=(s&16515072)>>18,i=(s&258048)>>12,c=(s&4032)>>6,l=s&63,typeof e!="string")throw new Error("encodings must be a string");if(typeof o!="number"||o<0||o>=e.length)throw new Error("Invalid index a");if(typeof i!="number"||i<0||i>=e.length)throw new Error("Invalid index b");if(typeof c!="number"||c<0||c>=e.length)throw new Error("Invalid index c");if(typeof l!="number"||l<0||l>=e.length)throw new Error("Invalid index d");let w=e[o],B=e[i],x=e[c],I=e[l];if(w===void 0||B===void 0||x===void 0||I===void 0)throw new Error("Invalid encoding index");b+=w+B+x+I}if(y===1){if(d=n[u],d===void 0)throw new Error("'chunk' must not be undefined");o=(d&252)>>2,i=(d&3)<<4;let t=e[o],f=e[i];if(t===void 0||f===void 0)throw new Error("Invalid encoding index");b+=`${t+f}==`}else if(y===2){let t=n[u]??0,f=n[u+1]!==void 0?n[u+1]:0;if(typeof t!="number"||t<0||t>255||typeof f!="number"||f<0||f>255)throw new Error("Invalid byte1");d=t<<8|f,o=(d&64512)>>10,i=(d&1008)>>4,c=(d&15)<<2;let h=e[o],g=e[i],s=e[c];if(h===void 0||g===void 0||s===void 0)throw new Error("Invalid encoding index");b+=`${h+g+s}=`}return b}export{v as a,T as b,S as c,C as d};
|
|
2
|
-
//# sourceMappingURL=chunk-PZ4HZLFJ.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/utils/encoding.ts"],"sourcesContent":["import { RhinoComputeError } from '../errors/base';\nimport { ErrorCodes } from '../errors/error-codes';\nimport { getLogger } from './logger';\n\n/**\n * Encodes a string to base64 (Node 20+ safe)\n *\n * @internal Internal encoding helper — kept internal to `@selvajs/compute`.\n *\n * @param str - String to encode\n * @returns Base64 encoded string\n */\nexport function encodeStringToBase64(str: string): string {\n\treturn Buffer.from(str, 'utf-8').toString('base64');\n}\n\n/**\n * Decodes a base64 string to a UTF-8 string (Node 20+ safe)\n *\n * @internal Internal encoding helper — kept internal to `@selvajs/compute`.\n *\n * @param base64Str - Base64 encoded string\n * @returns Decoded UTF-8 string\n */\nexport function decodeBase64ToString(base64Str: string): string {\n\treturn Buffer.from(base64Str, 'base64').toString('utf-8');\n}\n\n/**\n * Checks if a string is valid base64\n *\n * @internal Internal encoding helper — kept internal to `@selvajs/compute`.\n *\n * @param str - String to check\n * @returns True if the string is valid base64\n */\nexport function isBase64(str: string): boolean {\n\tif (!str || str.length < 2) return false;\n\t// Length must be a multiple of 4, only alphabet chars + at most 2 trailing '='\n\tif (str.length % 4 !== 0) return false;\n\treturn /^[A-Za-z0-9+/]+={0,2}$/.test(str);\n}\n\n/**\n * Decodes a base64 string to binary data (Uint8Array)\n *\n * @internal Internal encoding helper — kept internal to `@selvajs/compute`.\n *\n * @param base64File - Base64 encoded string\n * @returns Decoded binary data as Uint8Array\n * @throws {RhinoComputeError} If base64 decoding is not supported in this environment.\n */\nexport function decodeBase64ToBinary(base64File: string): Uint8Array {\n\t// Prefer Buffer in Node — it's faster and avoids the latin-1 string detour\n\t// that atob + charCodeAt requires.\n\tif (typeof (globalThis as any).Buffer === 'function') {\n\t\tconst buf = (globalThis as any).Buffer.from(base64File, 'base64');\n\t\treturn new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);\n\t}\n\tif (typeof globalThis.atob === 'function') {\n\t\tconst binary = globalThis.atob(base64File);\n\t\tconst bytes = new Uint8Array(binary.length);\n\t\tfor (let i = 0; i < binary.length; i++) {\n\t\t\tbytes[i] = binary.charCodeAt(i) & 0xff;\n\t\t}\n\t\treturn bytes;\n\t}\n\n\tthrow new RhinoComputeError(\n\t\t'Base64 decoding not supported in this environment.',\n\t\tErrorCodes.INVALID_STATE,\n\t\t{ context: { environmentInfo: 'atob or Buffer not available' } }\n\t);\n}\n\n/**\n * Encodes binary data (Uint8Array) to base64 string\n *\n * @internal Internal encoding helper — kept internal to `@selvajs/compute`.\n *\n * Source: https://github.com/mcneel/compute.rhino3d.appserver/blob/92c95a3b1d076a4d4a5360214ffd27c46425ff03/src/examples/convert/scriptjs\n * https://gist.github.com/jonleighton/958841\n *\n * MIT LICENSE\n * Copyright 2011 Jon Leighton\n * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\nexport function base64ByteArray(bytes: Uint8Array | null | undefined): string {\n\tif (bytes === null || bytes === undefined) {\n\t\tthrow new RhinoComputeError(\n\t\t\t'Input bytes must not be null or undefined',\n\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t{ context: { receivedValue: bytes } }\n\t\t);\n\t}\n\n\tconst encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n\n\tlet inputBytes = bytes;\n\n\t// strip bom (Byte Order Mark)\n\tif (\n\t\tinputBytes.length >= 3 &&\n\t\tinputBytes[0] === 239 &&\n\t\tinputBytes[1] === 187 &&\n\t\tinputBytes[2] === 191\n\t) {\n\t\tinputBytes = inputBytes.slice(3);\n\t}\n\n\tconst byteLength = inputBytes.byteLength;\n\tconst byteRemainder = byteLength % 3;\n\tconst mainLength = byteLength - byteRemainder;\n\n\tlet base64 = '';\n\tlet a, b, c, d;\n\tlet chunk;\n\n\t// Main loop deals with bytes in chunks of 3\n\tfor (let i = 0; i < mainLength; i += 3) {\n\t\t// Combine the three bytes into a single integer\n\n\t\tconst byte1 = inputBytes[i] !== undefined ? inputBytes[i] : 0;\n\t\tconst byte2 = inputBytes[i + 1] !== undefined ? inputBytes[i + 1] : 0;\n\t\tconst byte3 = inputBytes[i + 2] !== undefined ? inputBytes[i + 2] : 0;\n\n\t\tconst innerChunk = (byte1 << 16) | (byte2 << 8) | byte3;\n\n\t\t// Use bitmasks to extract 6-bit segments from the triplet\n\t\ta = (innerChunk & 16515072) >> 18;\n\t\tb = (innerChunk & 258048) >> 12;\n\t\tc = (innerChunk & 4032) >> 6;\n\t\td = innerChunk & 63;\n\n\t\t// Convert the raw binary segments to the appropriate ASCII encoding\n\t\tif (typeof encodings !== 'string') {\n\t\t\tthrow new Error('encodings must be a string');\n\t\t}\n\n\t\tif (typeof a !== 'number' || a < 0 || a >= encodings.length) {\n\t\t\tthrow new Error('Invalid index a');\n\t\t}\n\n\t\tif (typeof b !== 'number' || b < 0 || b >= encodings.length) {\n\t\t\tthrow new Error('Invalid index b');\n\t\t}\n\n\t\tif (typeof c !== 'number' || c < 0 || c >= encodings.length) {\n\t\t\tthrow new Error('Invalid index c');\n\t\t}\n\n\t\tif (typeof d !== 'number' || d < 0 || d >= encodings.length) {\n\t\t\tthrow new Error('Invalid index d');\n\t\t}\n\n\t\tconst charA = encodings[a];\n\t\tconst charB = encodings[b];\n\t\tconst charC = encodings[c];\n\t\tconst charD = encodings[d];\n\n\t\tif (charA === undefined || charB === undefined || charC === undefined || charD === undefined) {\n\t\t\tthrow new Error('Invalid encoding index');\n\t\t}\n\n\t\tbase64 += charA + charB + charC + charD;\n\t}\n\n\t// Deal with the remaining bytes and padding\n\tif (byteRemainder === 1) {\n\t\tchunk = inputBytes[mainLength];\n\n\t\tif (chunk === undefined) {\n\t\t\tthrow new Error(\"'chunk' must not be undefined\");\n\t\t}\n\n\t\ta = (chunk & 252) >> 2;\n\t\tb = (chunk & 3) << 4;\n\n\t\tconst charA = encodings[a];\n\t\tconst charB = encodings[b];\n\n\t\tif (charA === undefined || charB === undefined) {\n\t\t\tthrow new Error('Invalid encoding index');\n\t\t}\n\n\t\tbase64 += `${charA + charB}==`;\n\t} else if (byteRemainder === 2) {\n\t\tconst byte1 = inputBytes[mainLength] ?? 0;\n\t\tconst byte2 = inputBytes[mainLength + 1] !== undefined ? inputBytes[mainLength + 1] : 0;\n\n\t\tif (\n\t\t\ttypeof byte1 !== 'number' ||\n\t\t\tbyte1 < 0 ||\n\t\t\tbyte1 > 255 ||\n\t\t\ttypeof byte2 !== 'number' ||\n\t\t\tbyte2 < 0 ||\n\t\t\tbyte2 > 255\n\t\t) {\n\t\t\tthrow new Error('Invalid byte1');\n\t\t}\n\n\t\tchunk = (byte1 << 8) | byte2;\n\n\t\ta = (chunk & 64512) >> 10;\n\t\tb = (chunk & 1008) >> 4;\n\t\tc = (chunk & 15) << 2;\n\n\t\tconst charA = encodings[a];\n\t\tconst charB = encodings[b];\n\t\tconst charC = encodings[c];\n\n\t\tif (charA === undefined || charB === undefined || charC === undefined) {\n\t\t\tthrow new Error('Invalid encoding index');\n\t\t}\n\n\t\tbase64 += `${charA + charB + charC}=`;\n\t}\n\n\treturn base64;\n}\n\n/**\n * Convert base64 string to rhino object\n *\n * @internal Internal helper for decoding Rhino objects — not public API.\n *\n * Source: https://github.com/mcneel/compute.rhino3d.appserver/blob/92c95a3b1d076a4d4a5360214ffd27c46425ff03/src/examples/convert/scriptjs\n * @param rhino is the rhino module form rhino3dm. Since not properly typed its not used here.\n * @param item\n * @returns\n */\nexport function base64ToRhinoObject(\n\trhino: any,\n\titem: {\n\t\ttype: string;\n\t\tdata: string;\n\t}\n) {\n\t//Make a type definition for this?\n\tlet decodata: null | object = null;\n\ttry {\n\t\tdecodata = JSON.parse(item.data);\n\t} catch (error) {\n\t\tdecodata = item;\n\t\tgetLogger().warn('Failed to parse JSON, returning original data:', error, item);\n\t}\n\tif (item.type === 'System.String') {\n\t\ttry {\n\t\t\treturn rhino.DracoCompression.decompressBase64String(decodata);\n\t\t} catch (error) {\n\t\t\tgetLogger().error('Failed to decompress Draco base64 string:', error);\n\t\t}\n\t} else if (\n\t\ttypeof decodata === 'object' &&\n\t\tObject.prototype.hasOwnProperty.call(decodata, 'opennurbs')\n\t) {\n\t\treturn rhino.CommonObject.decode(decodata);\n\t} else if (typeof decodata === 'object') {\n\t\ttry {\n\t\t\treturn rhino.CommonObject.decode(decodata);\n\t\t} catch (error) {\n\t\t\tgetLogger().error('Failed to decode Rhino object:', error);\n\t\t}\n\t}\n}\n"],"mappings":"+CAYO,SAASA,EAAqBC,EAAqB,CACzD,OAAO,OAAO,KAAKA,EAAK,OAAO,EAAE,SAAS,QAAQ,CACnD,CAsBO,SAASC,EAASC,EAAsB,CAG9C,MAFI,CAACA,GAAOA,EAAI,OAAS,GAErBA,EAAI,OAAS,IAAM,EAAU,GAC1B,yBAAyB,KAAKA,CAAG,CACzC,CAWO,SAASC,EAAqBC,EAAgC,CAGpE,GAAI,OAAQ,WAAmB,QAAW,WAAY,CACrD,IAAMC,EAAO,WAAmB,OAAO,KAAKD,EAAY,QAAQ,EAChE,OAAO,IAAI,WAAWC,EAAI,OAAQA,EAAI,WAAYA,EAAI,UAAU,CACjE,CACA,GAAI,OAAO,WAAW,MAAS,WAAY,CAC1C,IAAMC,EAAS,WAAW,KAAKF,CAAU,EACnCG,EAAQ,IAAI,WAAWD,EAAO,MAAM,EAC1C,QAASE,EAAI,EAAGA,EAAIF,EAAO,OAAQE,IAClCD,EAAMC,CAAC,EAAIF,EAAO,WAAWE,CAAC,EAAI,IAEnC,OAAOD,CACR,CAEA,MAAM,IAAIE,EACT,qDACAC,EAAW,cACX,CAAE,QAAS,CAAE,gBAAiB,8BAA+B,CAAE,CAChE,CACD,CAgBO,SAASC,EAAgBJ,EAA8C,CAC7E,GAAIA,GAAU,KACb,MAAM,IAAIE,EACT,4CACAC,EAAW,cACX,CAAE,QAAS,CAAE,cAAeH,CAAM,CAAE,CACrC,EAGD,IAAMK,E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zB,GAAIM,IAAU,QAAaC,IAAU,QAAaC,IAAU,QAAaC,IAAU,OAClF,MAAM,IAAI,MAAM,wBAAwB,EAGzCZ,GAAUS,EAAQC,EAAQC,EAAQC,CACnC,CAGA,GAAId,IAAkB,EAAG,CAGxB,GAFAM,EAAQR,EAAWG,CAAU,EAEzBK,IAAU,OACb,MAAM,IAAI,MAAM,+BAA+B,EAGhDH,GAAKG,EAAQ,MAAQ,EACrBF,GAAKE,EAAQ,IAAM,EAEnB,IAAMK,EAAQd,EAAUM,CAAC,EACnBS,EAAQf,EAAUO,CAAC,EAEzB,GAAIO,IAAU,QAAaC,IAAU,OACpC,MAAM,IAAI,MAAM,wBAAwB,EAGzCV,GAAU,GAAGS,EAAQC,CAAK,IAC3B,SAAWZ,IAAkB,EAAG,CAC/B,IAAMO,EAAQT,EAAWG,CAAU,GAAK,EAClCO,EAAQV,EAAWG,EAAa,CAAC,IAAM,OAAYH,EAAWG,EAAa,CAAC,EAAI,EAEtF,GACC,OAAOM,GAAU,UACjBA,EAAQ,GACRA,EAAQ,KACR,OAAOC,GAAU,UACjBA,EAAQ,GACRA,EAAQ,IAER,MAAM,IAAI,MAAM,eAAe,EAGhCF,EAASC,GAAS,EAAKC,EAEvBL,GAAKG,EAAQ,QAAU,GACvBF,GAAKE,EAAQ,OAAS,EACtB,GAAKA,EAAQ,KAAO,EAEpB,IAAMK,EAAQd,EAAUM,CAAC,EACnBS,EAAQf,EAAUO,CAAC,EACnBS,EAAQhB,EAAU,CAAC,EAEzB,GAAIc,IAAU,QAAaC,IAAU,QAAaC,IAAU,OAC3D,MAAM,IAAI,MAAM,wBAAwB,EAGzCX,GAAU,GAAGS,EAAQC,EAAQC,CAAK,GACnC,CAEA,OAAOX,CACR","names":["encodeStringToBase64","str","isBase64","str","decodeBase64ToBinary","base64File","buf","binary","bytes","i","RhinoComputeError","ErrorCodes","base64ByteArray","encodings","inputBytes","byteLength","byteRemainder","mainLength","base64","a","b","d","chunk","byte1","byte2","byte3","innerChunk","charA","charB","charC","charD"]}
|
package/dist/chunk-VK2TSW7S.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
var S=Object.defineProperty;var $=(e,r,t)=>r in e?S(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var W=(e,r)=>{for(var t in r)S(e,t,{get:r[t],enumerable:!0})};var R=(e,r,t)=>$(e,typeof r!="symbol"?r+"":r,t);var a={NETWORK_ERROR:"NETWORK_ERROR",AUTH_ERROR:"AUTH_ERROR",VALIDATION_ERROR:"VALIDATION_ERROR",COMPUTATION_ERROR:"COMPUTATION_ERROR",TIMEOUT_ERROR:"TIMEOUT_ERROR",CORS_ERROR:"CORS_ERROR",UNKNOWN_ERROR:"UNKNOWN_ERROR",INVALID_STATE:"INVALID_STATE",INVALID_INPUT:"INVALID_INPUT",INVALID_CONFIG:"INVALID_CONFIG",BROWSER_ONLY:"BROWSER_ONLY",ENVIRONMENT_ERROR:"ENVIRONMENT_ERROR",ENCODING_ERROR:"ENCODING_ERROR"};var d=class e extends Error{constructor(t,n="UNKNOWN_ERROR",s){super(t);R(this,"code");R(this,"statusCode");R(this,"context");R(this,"originalError");this.name="RhinoComputeError",this.code=n,this.statusCode=s?.statusCode,this.context=s?.context,this.originalError=s?.originalError,"cause"in Error.prototype&&Object.defineProperty(this,"cause",{value:s?.originalError,enumerable:!0})}static validation(t,n,s){return new e(`Input "${t}": ${n}`,a.VALIDATION_ERROR,{context:{inputName:t,reason:n,...s}})}static missingValues(t,n,s){return new e(`Input "${t}" has no values defined${n?` (expected ${n})`:""}`,a.INVALID_INPUT,{context:{inputName:t,expectedType:n,...s}})}static invalidDefault(t,n,s,i){return new e(`ValueList input "${t}" default value "${n}" is not in available values`,a.VALIDATION_ERROR,{context:{inputName:t,defaultValue:n,availableValues:s,...i}})}static unknownParamType(t,n,s){return new e(`Unknown paramType: ${t}`,a.VALIDATION_ERROR,{context:{receivedParamType:t,paramName:n,...s}})}static invalidStructure(t,n,s){return new e(`Invalid input structure for "${t}" (expected ${n})`,a.INVALID_INPUT,{context:{inputName:t,expectedStructure:n,...s}})}};var v=class{debug(){}info(){}warn(){}error(){}},O=class{debug(r,...t){console.debug(r,...t)}info(r,...t){console.info(r,...t)}warn(r,...t){console.warn(r,...t)}error(r,...t){console.error(r,...t)}},b=new v;function p(){return b}function N(e){e===null?b=new v:"debug"in e&&"info"in e&&"warn"in e&&"error"in e?b=e:b=new O}function _(){N(new O)}var y={attempts:0,baseDelayMs:500,maxDelayMs:3e4,retryOn429:!0},I=new Set([502,503,504]);function k(e){return e?{attempts:e.attempts??y.attempts,baseDelayMs:e.baseDelayMs??y.baseDelayMs,maxDelayMs:e.maxDelayMs??y.maxDelayMs,retryOn429:e.retryOn429??y.retryOn429}:y}function M(e){if(!e)return null;let r=Number(e);if(Number.isFinite(r)&&r>=0)return r*1e3;let t=Date.parse(e);if(Number.isFinite(t)){let n=t-Date.now();return n>0?n:0}return null}function w(e,r){let t=r.baseDelayMs*Math.pow(2,e),n=Math.random()*r.baseDelayMs;return Math.min(t+n,r.maxDelayMs)}function x(e,r){return new Promise((t,n)=>{if(r?.aborted){n(new DOMException("Aborted","AbortError"));return}let s=setTimeout(()=>{r?.removeEventListener("abort",i),t()},e),i=()=>{clearTimeout(s),n(new DOMException("Aborted","AbortError"))};r?.addEventListener("abort",i,{once:!0})})}function L(e,r,t,n,s,i){let{status:c,statusText:o}=e,l={url:r,requestId:t,method:"POST",requestSize:n,serverUrl:s},u=i?` \u2014 ${i.slice(0,200)}`:"",m={401:{message:`HTTP ${c}: ${o}${u}`,code:a.AUTH_ERROR},403:{message:`HTTP ${c}: ${o}${u}`,code:a.AUTH_ERROR},404:{message:`Endpoint not found: ${r}`,code:a.NETWORK_ERROR},413:{message:`Request too large: ${(n/1024).toFixed(2)}KB`,code:a.VALIDATION_ERROR},429:{message:"Rate limit exceeded",code:a.NETWORK_ERROR},500:{message:`Server error: ${i||o}`,code:a.COMPUTATION_ERROR},502:{message:`Service unavailable: ${o}`,code:a.NETWORK_ERROR},503:{message:`Service unavailable: ${o}`,code:a.NETWORK_ERROR},504:{message:`Service unavailable: ${o}`,code:a.NETWORK_ERROR}}[c]||{message:`HTTP ${c}: ${o}`,code:a.UNKNOWN_ERROR};throw new d(m.message,m.code,{statusCode:c,context:l})}function D(e,r){let t=r.replace(/\/+$/,""),n=e.replace(/^\/+/,"");return`${t}/${n}`}function U(e){try{let r=new URL(e).host;return/^(localhost|127\.0\.0\.1|::1)(:\d+)?$/i.test(r)}catch{return/(localhost|127\.0\.0\.1)/i.test(e)}}function q(e,r){let t={"X-Request-ID":e,"Content-Type":"application/json",...r.authToken&&{Authorization:r.authToken},...r.apiKey&&{RhinoComputeKey:r.apiKey}};return!r.apiKey&&!U(r.serverUrl)&&p().warn(`\u26A0\uFE0F [Rhino Compute] Request [${e}] targets remote server (${r.serverUrl}) but no API key is configured. Requests may fail or be rate-limited.`),t}function K(){return`${Date.now()}-${Math.random().toString(36).substring(2,11)}`}function f(e,r){r&&p().debug(e)}function P(e,r){let t=[],n=()=>{};if(e&&t.push(e),r&&r>0)if(typeof AbortSignal<"u"&&typeof AbortSignal.timeout=="function")t.push(AbortSignal.timeout(r));else{let o=new AbortController,l=setTimeout(()=>o.abort(),r);n=()=>clearTimeout(l),t.push(o.signal)}if(t.length===0)return{signal:void 0,cleanup:n};if(t.length===1)return{signal:t[0],cleanup:n};if(typeof AbortSignal<"u"&&typeof AbortSignal.any=="function")return{signal:AbortSignal.any(t),cleanup:n};let s=new AbortController,i=()=>s.abort();for(let o of t){if(o.aborted){s.abort();break}o.addEventListener("abort",i,{once:!0})}let c=n;return n=()=>{c();for(let o of t)o.removeEventListener("abort",i)},{signal:s.signal,cleanup:n}}async function F(e,r,t,n,s,i,c){let o=Math.round(performance.now()-i);if(!e.ok){let l=await e.text();if(c&&(f(`\u274C Request [${t}] failed with HTTP ${e.status} in ${o}ms`,!0),f(` URL: ${r}`,!0),f(` Status: ${e.status} ${e.statusText}`,!0),l&&f(` Response body: ${l.substring(0,500)}${l.length>500?"...":""}`,!0)),e.status===500)try{let u=JSON.parse(l);if(u?.values&&(u.errors||u.warnings))return c&&(f(`\u26A0\uFE0F Request [${t}] completed with Grasshopper errors in ${o}ms`,!0),u.errors?.length>0&&f(` Errors: ${JSON.stringify(u.errors,null,2)}`,!0),u.warnings?.length>0&&f(` Warnings: ${JSON.stringify(u.warnings,null,2)}`,!0)),u;u?.Message?l=`${u.ExceptionType?u.ExceptionType+": ":""}${u.Message}
|
|
2
|
-
${u.StackTrace||""}`:u?.error&&(l=typeof u.error=="string"?u.error:JSON.stringify(u.error,null,2))}catch(u){c&&f(` Failed to parse error body as JSON: ${u}`,!0)}L(e,r,t,n,s,l)}f(`\u2705 Request [${t}] completed in ${o}ms`,c);try{return await e.json()}catch(l){throw new d("Failed to parse JSON response",a.NETWORK_ERROR,{statusCode:e.status,context:{url:r,requestId:t},originalError:l instanceof Error?l:new Error(String(l))})}}async function H(e,r,t,n){let{signal:s,cleanup:i}=P(e.config.signal,e.config.timeoutMs),c=performance.now();try{let o=await fetch(e.fullUrl,{method:"POST",body:e.body,headers:e.headers,signal:s});if((I.has(o.status)||r.retryOn429&&o.status===429)&&t<n-1){let m=M(o.headers.get("Retry-After"))??w(t,r);return await o.text().catch(()=>{}),{ok:!1,retry:!0,delayMs:m,cause:new d(`HTTP ${o.status} ${o.statusText} (will retry)`,a.NETWORK_ERROR,{statusCode:o.status,context:{requestId:e.requestId}})}}return{ok:!0,value:await F(o,e.fullUrl,e.requestId,e.requestSize,e.config.serverUrl,c,e.config.debug)}}catch(o){if(o instanceof Error&&(o.name==="AbortError"||o.name==="TimeoutError")){if(e.config.signal?.aborted===!0)return{ok:!1,retry:!1,cause:new d("Request aborted by caller",a.UNKNOWN_ERROR,{context:{endpoint:e.endpoint,requestId:e.requestId,requestSize:e.requestSize},originalError:o})};let u=new d(`Request timed out after ${e.config.timeoutMs}ms`,a.TIMEOUT_ERROR,{context:{serverUrl:e.config.serverUrl,timeoutMs:e.config.timeoutMs,url:e.fullUrl,requestId:e.requestId,endpoint:e.endpoint,requestSize:e.requestSize}});return t<n-1?{ok:!1,retry:!0,delayMs:w(t,r),cause:u}:{ok:!1,retry:!1,cause:u}}if(o instanceof TypeError){let l=new d(`Network error: ${o.message}`,a.NETWORK_ERROR,{context:{serverUrl:e.config.serverUrl,url:e.fullUrl,requestId:e.requestId,endpoint:e.endpoint,requestSize:e.requestSize},originalError:o});return t<n-1?{ok:!1,retry:!0,delayMs:w(t,r),cause:l}:{ok:!1,retry:!1,cause:l}}if(o instanceof d){let l=o.statusCode;return l!==void 0&&(I.has(l)||r.retryOn429&&l===429)&&t<n-1?{ok:!1,retry:!0,delayMs:w(t,r),cause:o}:{ok:!1,retry:!1,cause:o}}return{ok:!1,retry:!1,cause:new d(o instanceof Error?o.message:String(o),a.UNKNOWN_ERROR,{context:{endpoint:e.endpoint,requestId:e.requestId},originalError:o instanceof Error?o:new Error(String(o))})}}finally{i()}}async function V(e,r,t){let n=K(),s=JSON.stringify(r),i=s.length,c=D(e,t.serverUrl),o=q(n,t),l=k(t.retry),u=l.attempts+1;if(t.debug){let h=(i/1024).toFixed(2),g=i>1e5?"\u26A0\uFE0F":"\u{1F680}";f(`${g} Starting compute request [${n}]: ${e} (${h}KB)`,!0)}let T={endpoint:e,body:s,requestSize:i,fullUrl:c,requestId:n,headers:o,config:t},m=null;for(let h=0;h<u;h++){let g=await H(T,l,h,u);if(g.ok)return g.value;if(!g.retry)throw g.cause;m=g.cause,t.debug&&f(`\u{1F501} Request [${n}] retrying after ${g.delayMs}ms (attempt ${h+2}/${u}): ${g.cause.message}`,!0);try{await x(g.delayMs,t.signal)}catch{throw new d("Request aborted by caller",a.UNKNOWN_ERROR,{context:{endpoint:e,requestId:n,requestSize:i},originalError:m})}}throw m??new d("Unknown error after retries",a.UNKNOWN_ERROR,{context:{endpoint:e,requestId:n,requestSize:i}})}var E=class{constructor(r,t){R(this,"serverUrl");R(this,"apiKey");R(this,"disposed",!1);R(this,"activeMonitors",new Set);R(this,"activeTimeouts",new Set);if(!r?.trim())throw new d("serverUrl is required",a.INVALID_CONFIG,{context:{serverUrl:r}});if(!r.match(/^https?:\/\//))throw new d(`Invalid serverUrl: "${r}". Must start with "http://" or "https://". For example: "http://localhost:5000" or "https://example.com"`,a.INVALID_CONFIG,{context:{serverUrl:r}});try{new URL(r)}catch(n){throw new d(`Invalid serverUrl: "${r}". Must be a valid URL. Received error: ${n instanceof Error?n.message:String(n)}`,a.INVALID_CONFIG,{context:{serverUrl:r},originalError:n instanceof Error?n:void 0})}this.apiKey=t,this.serverUrl=r.replace(/\/+$/,"")}buildHeaders(){let r={"Content-Type":"application/json"};return this.apiKey&&(r.RhinoComputeKey=this.apiKey),r}async isServerOnline(){this.ensureNotDisposed();let r=`${this.serverUrl}/healthcheck`,t={headers:this.buildHeaders(),method:"GET"};try{return(await fetch(r,t)).ok}catch(n){return p().debug("[ComputeServerStats] Fetch error:",n),!1}}async getActiveChildren(){this.ensureNotDisposed();try{let r=await fetch(`${this.serverUrl}/activechildren`,{headers:this.buildHeaders()});if(!r.ok)return p().warn("[ComputeServerStats] Failed to fetch active children:",r.status),null;let t=await r.text(),n=parseInt(t.trim(),10);return isNaN(n)?(p().warn("[ComputeServerStats] Invalid active children response:",t),null):n}catch(r){return p().warn("[ComputeServerStats] Error fetching active children:",r),null}}async getVersion(){this.ensureNotDisposed();try{let r=await fetch(`${this.serverUrl}/version`,{headers:this.buildHeaders()});if(!r.ok)return p().warn("[ComputeServerStats] Failed to fetch version:",r.status),null;try{let t=await r.json();return{rhino:t.rhino??"",compute:t.compute??"",git_sha:t.git_sha??null}}catch{return{rhino:await r.text(),compute:"",git_sha:null}}}catch(r){return p().warn("[ComputeServerStats] Error fetching version:",r),null}}async getServerStats(){if(this.ensureNotDisposed(),!await this.isServerOnline())return{isOnline:!1};let[t,n]=await Promise.all([this.getVersion(),this.getActiveChildren()]);return{isOnline:!0,...t&&{version:t},...n!==null&&{activeChildren:n}}}monitor(r,t=5e3){this.ensureNotDisposed();let n=!0,s=null;p().info(`\u{1F504} Starting server stats monitoring every ${t}ms`);let i=async()=>{if(s!==null&&(this.activeTimeouts.delete(s),s=null),!(!n||this.disposed)){try{let o=await this.getServerStats();if(!n||this.disposed)return;try{r(o)}catch(l){p().error("[ComputeServerStats] Monitor callback threw:",l)}}catch(o){p().error("[ComputeServerStats] Failed to fetch stats during monitor:",o)}n&&!this.disposed&&(s=setTimeout(()=>{i()},t),this.activeTimeouts.add(s))}},c=()=>{n=!1,s!==null&&(clearTimeout(s),this.activeTimeouts.delete(s),s=null),this.activeMonitors.delete(c)};return this.activeMonitors.add(c),i(),c}async dispose(){if(!this.disposed){this.disposed=!0;for(let r of this.activeMonitors)r();this.activeMonitors.clear();for(let r of this.activeTimeouts)clearTimeout(r);this.activeTimeouts.clear()}}ensureNotDisposed(){if(this.disposed)throw new d("ComputeServerStats has been disposed and cannot be used",a.INVALID_STATE,{context:{disposed:this.disposed}})}};function A(e,r={}){let{preserveSpaces:t=!1}=r,n=e.trim();return t?(n=n.charAt(0).toLowerCase()+n.slice(1).replace(/[-_](.)/g,(s,i)=>i?i.toUpperCase():""),n):(n=n.replace(/^[A-Z]/,s=>s.toLowerCase()).replace(/[\s-_]+(.)?/g,(s,i)=>i?i.toUpperCase():""),n)}function C(e,r={}){return!e||typeof e!="object"?e:Array.isArray(e)?r.deep?e.map(t=>C(t,r)):e:Object.keys(e).reduce((t,n)=>{let s=A(n,{preserveSpaces:r.preserveSpaces}),i=e[n];return t[s]=r.deep?C(i,r):i,t},{})}export{W as a,R as b,a as c,d,p as e,N as f,_ as g,V as h,E as i,A as j,C as k};
|
|
3
|
-
//# sourceMappingURL=chunk-VK2TSW7S.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/errors/error-codes.ts","../src/core/errors/base.ts","../src/core/utils/logger.ts","../src/core/compute-fetch/compute-fetch.ts","../src/core/server/compute-server-stats.ts","../src/core/utils/camel-case.ts"],"sourcesContent":["export const ErrorCodes = {\n\tNETWORK_ERROR: 'NETWORK_ERROR',\n\tAUTH_ERROR: 'AUTH_ERROR',\n\tVALIDATION_ERROR: 'VALIDATION_ERROR',\n\tCOMPUTATION_ERROR: 'COMPUTATION_ERROR',\n\tTIMEOUT_ERROR: 'TIMEOUT_ERROR',\n\tCORS_ERROR: 'CORS_ERROR',\n\tUNKNOWN_ERROR: 'UNKNOWN_ERROR',\n\tINVALID_STATE: 'INVALID_STATE',\n\tINVALID_INPUT: 'INVALID_INPUT',\n\tINVALID_CONFIG: 'INVALID_CONFIG',\n\tBROWSER_ONLY: 'BROWSER_ONLY',\n\tENVIRONMENT_ERROR: 'ENVIRONMENT_ERROR',\n\tENCODING_ERROR: 'ENCODING_ERROR'\n} as const;\n\nexport type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];\n","import { ErrorCodes } from './error-codes';\n\n/**\n * Simplified error for Rhino Compute operations\n *\n * @public Use this for error handling with error codes and context.\n */\nexport class RhinoComputeError extends Error {\n\tpublic readonly code: string;\n\tpublic readonly statusCode?: number;\n\tpublic readonly context?: Record<string, unknown>;\n\tpublic readonly originalError?: Error;\n\n\tconstructor(\n\t\tmessage: string,\n\t\tcode: string = 'UNKNOWN_ERROR',\n\t\toptions?: { statusCode?: number; context?: Record<string, unknown>; originalError?: Error }\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'RhinoComputeError';\n\t\tthis.code = code;\n\t\tthis.statusCode = options?.statusCode;\n\t\tthis.context = options?.context;\n\t\tthis.originalError = options?.originalError;\n\n\t\t// Support error chaining (Node.js 16.9+, TypeScript 4.6+)\n\t\tif ('cause' in Error.prototype) {\n\t\t\tObject.defineProperty(this, 'cause', {\n\t\t\t\tvalue: options?.originalError,\n\t\t\t\tenumerable: true\n\t\t\t});\n\t\t}\n\t}\n\n\t// ============================================================================\n\t// Static Validation Error Helpers\n\t// ============================================================================\n\n\t/**\n\t * Create a generic validation error with custom reason\n\t */\n\tstatic validation(inputName: string, reason: string, context?: Record<string, unknown>) {\n\t\treturn new RhinoComputeError(`Input \"${inputName}\": ${reason}`, ErrorCodes.VALIDATION_ERROR, {\n\t\t\tcontext: { inputName, reason, ...context }\n\t\t});\n\t}\n\n\t/**\n\t * Create an error for missing/empty values\n\t */\n\tstatic missingValues(inputName: string, expectedType?: string, context?: Record<string, unknown>) {\n\t\treturn new RhinoComputeError(\n\t\t\t`Input \"${inputName}\" has no values defined${expectedType ? ` (expected ${expectedType})` : ''}`,\n\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t{ context: { inputName, expectedType, ...context } }\n\t\t);\n\t}\n\n\t/**\n\t * Create an error for invalid default value in value list\n\t */\n\tstatic invalidDefault(\n\t\tinputName: string,\n\t\tdefaultValue: unknown,\n\t\tavailableValues: unknown[],\n\t\tcontext?: Record<string, unknown>\n\t) {\n\t\treturn new RhinoComputeError(\n\t\t\t`ValueList input \"${inputName}\" default value \"${defaultValue}\" is not in available values`,\n\t\t\tErrorCodes.VALIDATION_ERROR,\n\t\t\t{ context: { inputName, defaultValue, availableValues, ...context } }\n\t\t);\n\t}\n\n\t/**\n\t * Create an error for unknown parameter type\n\t */\n\tstatic unknownParamType(paramType: string, paramName?: string, context?: Record<string, unknown>) {\n\t\treturn new RhinoComputeError(`Unknown paramType: ${paramType}`, ErrorCodes.VALIDATION_ERROR, {\n\t\t\tcontext: { receivedParamType: paramType, paramName, ...context }\n\t\t});\n\t}\n\n\t/**\n\t * Create an error for invalid input structure\n\t */\n\tstatic invalidStructure(\n\t\tinputName: string,\n\t\texpectedStructure: string,\n\t\tcontext?: Record<string, unknown>\n\t) {\n\t\treturn new RhinoComputeError(\n\t\t\t`Invalid input structure for \"${inputName}\" (expected ${expectedStructure})`,\n\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t{ context: { inputName, expectedStructure, ...context } }\n\t\t);\n\t}\n}\n","/**\n * Logger interface for structured logging\n *\n * @public Implement this interface to provide custom logging behavior.\n */\nexport interface Logger {\n\tdebug(message: string, ...args: unknown[]): void;\n\tinfo(message: string, ...args: unknown[]): void;\n\twarn(message: string, ...args: unknown[]): void;\n\terror(message: string, ...args: unknown[]): void;\n}\n\n/**\n * No-op logger implementation (default)\n * @internal\n */\nclass NoOpLogger implements Logger {\n\tdebug(): void {}\n\tinfo(): void {}\n\twarn(): void {}\n\terror(): void {}\n}\n\n/**\n * Console logger implementation\n * @internal\n */\nclass ConsoleLogger implements Logger {\n\tdebug(message: string, ...args: unknown[]): void {\n\t\tconsole.debug(message, ...args);\n\t}\n\n\tinfo(message: string, ...args: unknown[]): void {\n\t\tconsole.info(message, ...args);\n\t}\n\n\twarn(message: string, ...args: unknown[]): void {\n\t\tconsole.warn(message, ...args);\n\t}\n\n\terror(message: string, ...args: unknown[]): void {\n\t\tconsole.error(message, ...args);\n\t}\n}\n\n/**\n * Internal logger instance\n * @internal\n */\nlet internalLogger: Logger = new NoOpLogger();\n\n/**\n * Get the current logger instance\n *\n * @returns The current logger instance\n */\nexport function getLogger(): Logger {\n\treturn internalLogger;\n}\n\n/**\n * Set a custom logger instance\n *\n * @public Use this to configure custom logging behavior.\n *\n * @param logger - Custom logger implementation or null to disable logging\n *\n * @example\n * ```typescript\n * import { setLogger } from '@selvajs/compute';\n *\n * // Enable console logging\n * setLogger(console);\n *\n * // Use a custom logger\n * setLogger({\n * debug: (msg, ...args) => myLogger.debug(msg, ...args),\n * info: (msg, ...args) => myLogger.info(msg, ...args),\n * warn: (msg, ...args) => myLogger.warn(msg, ...args),\n * error: (msg, ...args) => myLogger.error(msg, ...args)\n * });\n *\n * // Disable logging\n * setLogger(null);\n * ```\n */\nexport function setLogger(logger: Logger | Console | null): void {\n\tif (logger === null) {\n\t\tinternalLogger = new NoOpLogger();\n\t} else if ('debug' in logger && 'info' in logger && 'warn' in logger && 'error' in logger) {\n\t\tinternalLogger = logger as Logger;\n\t} else {\n\t\tinternalLogger = new ConsoleLogger();\n\t}\n}\n\n/**\n * Enable debug logging to console\n *\n * @public Convenience method to enable console logging.\n *\n * @example\n * ```typescript\n * import { enableDebugLogging } from '@selvajs/compute';\n *\n * enableDebugLogging();\n * ```\n */\nexport function enableDebugLogging(): void {\n\tsetLogger(new ConsoleLogger());\n}\n","import { RhinoComputeError, ErrorCodes } from '../errors';\nimport { getLogger } from '../utils/logger';\n\nimport type { ComputeConfig, RetryPolicy } from '../types';\nimport type {\n\tGrasshopperComputeConfig,\n\tGrasshopperComputeResponse,\n\tIoResponseSchema\n} from '@/features/grasshopper/types';\n\n/**\n * Valid endpoints for Rhino Compute (improved response type handling).\n */\nexport type Endpoint = 'grasshopper' | 'io' | string;\n\nexport type EndpointResponseMap = {\n\tgrasshopper: GrasshopperComputeResponse;\n\tio: IoResponseSchema;\n};\n\nexport type ComputeResponseFor<E extends string> = E extends keyof EndpointResponseMap\n\t? EndpointResponseMap[E]\n\t: unknown;\n\n// ============================================================================\n// Retry Policy\n// ============================================================================\n\nconst DEFAULT_RETRY: Required<RetryPolicy> = {\n\tattempts: 0,\n\tbaseDelayMs: 500,\n\tmaxDelayMs: 30_000,\n\tretryOn429: true\n};\n\nconst RETRYABLE_STATUS = new Set([502, 503, 504]);\n\nfunction resolveRetryPolicy(policy: RetryPolicy | undefined): Required<RetryPolicy> {\n\tif (!policy) return DEFAULT_RETRY;\n\treturn {\n\t\tattempts: policy.attempts ?? DEFAULT_RETRY.attempts,\n\t\tbaseDelayMs: policy.baseDelayMs ?? DEFAULT_RETRY.baseDelayMs,\n\t\tmaxDelayMs: policy.maxDelayMs ?? DEFAULT_RETRY.maxDelayMs,\n\t\tretryOn429: policy.retryOn429 ?? DEFAULT_RETRY.retryOn429\n\t};\n}\n\n/**\n * Parse a Retry-After header value (seconds-int or HTTP-date) into ms.\n * Returns null if the header is missing or unparseable.\n */\nfunction parseRetryAfter(headerValue: string | null): number | null {\n\tif (!headerValue) return null;\n\tconst seconds = Number(headerValue);\n\tif (Number.isFinite(seconds) && seconds >= 0) return seconds * 1000;\n\tconst dateMs = Date.parse(headerValue);\n\tif (Number.isFinite(dateMs)) {\n\t\tconst delta = dateMs - Date.now();\n\t\treturn delta > 0 ? delta : 0;\n\t}\n\treturn null;\n}\n\nfunction backoffDelay(attempt: number, policy: Required<RetryPolicy>): number {\n\tconst exponential = policy.baseDelayMs * Math.pow(2, attempt);\n\tconst jitter = Math.random() * policy.baseDelayMs;\n\treturn Math.min(exponential + jitter, policy.maxDelayMs);\n}\n\nfunction sleep(ms: number, signal?: AbortSignal): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tif (signal?.aborted) {\n\t\t\treject(new DOMException('Aborted', 'AbortError'));\n\t\t\treturn;\n\t\t}\n\t\tconst id = setTimeout(() => {\n\t\t\tsignal?.removeEventListener('abort', onAbort);\n\t\t\tresolve();\n\t\t}, ms);\n\t\tconst onAbort = () => {\n\t\t\tclearTimeout(id);\n\t\t\treject(new DOMException('Aborted', 'AbortError'));\n\t\t};\n\t\tsignal?.addEventListener('abort', onAbort, { once: true });\n\t});\n}\n\n// ============================================================================\n// Error Handling\n// ============================================================================\n\nfunction throwHttpError(\n\tresponse: Response,\n\tfullUrl: string,\n\trequestId: string,\n\trequestSize: number,\n\tserverUrl: string,\n\terrorBody: string\n): never {\n\tconst { status, statusText } = response;\n\tconst context = { url: fullUrl, requestId, method: 'POST', requestSize, serverUrl };\n\n\tconst bodyHint = errorBody ? ` — ${errorBody.slice(0, 200)}` : '';\n\tconst errorMap: Record<number, { message: string; code: string }> = {\n\t\t401: {\n\t\t\tmessage: `HTTP ${status}: ${statusText}${bodyHint}`,\n\t\t\tcode: ErrorCodes.AUTH_ERROR\n\t\t},\n\t\t403: {\n\t\t\tmessage: `HTTP ${status}: ${statusText}${bodyHint}`,\n\t\t\tcode: ErrorCodes.AUTH_ERROR\n\t\t},\n\t\t404: { message: `Endpoint not found: ${fullUrl}`, code: ErrorCodes.NETWORK_ERROR },\n\t\t413: {\n\t\t\tmessage: `Request too large: ${(requestSize / 1024).toFixed(2)}KB`,\n\t\t\tcode: ErrorCodes.VALIDATION_ERROR\n\t\t},\n\t\t429: { message: 'Rate limit exceeded', code: ErrorCodes.NETWORK_ERROR },\n\t\t500: {\n\t\t\tmessage: `Server error: ${errorBody || statusText}`,\n\t\t\tcode: ErrorCodes.COMPUTATION_ERROR\n\t\t},\n\t\t502: { message: `Service unavailable: ${statusText}`, code: ErrorCodes.NETWORK_ERROR },\n\t\t503: { message: `Service unavailable: ${statusText}`, code: ErrorCodes.NETWORK_ERROR },\n\t\t504: { message: `Service unavailable: ${statusText}`, code: ErrorCodes.NETWORK_ERROR }\n\t};\n\n\tconst error = errorMap[status] || {\n\t\tmessage: `HTTP ${status}: ${statusText}`,\n\t\tcode: ErrorCodes.UNKNOWN_ERROR\n\t};\n\n\tthrow new RhinoComputeError(error.message, error.code, { statusCode: status, context });\n}\n\n// ============================================================================\n// Request Helpers\n// ============================================================================\n\nfunction buildUrl(endpoint: string, serverUrl: string): string {\n\tconst base = serverUrl.replace(/\\/+$/, '');\n\tconst path = endpoint.replace(/^\\/+/, '');\n\treturn `${base}/${path}`;\n}\n\nfunction isLocalhost(serverUrl: string): boolean {\n\ttry {\n\t\tconst host = new URL(serverUrl).host;\n\t\treturn /^(localhost|127\\.0\\.0\\.1|::1)(:\\d+)?$/i.test(host);\n\t} catch {\n\t\treturn /(localhost|127\\.0\\.0\\.1)/i.test(serverUrl);\n\t}\n}\n\nfunction buildHeaders(requestId: string, config: ComputeConfig): HeadersInit {\n\tconst headers: HeadersInit = {\n\t\t'X-Request-ID': requestId,\n\t\t'Content-Type': 'application/json',\n\t\t...(config.authToken && { Authorization: config.authToken }),\n\t\t...(config.apiKey && { RhinoComputeKey: config.apiKey })\n\t};\n\n\tif (!config.apiKey && !isLocalhost(config.serverUrl)) {\n\t\tgetLogger().warn(\n\t\t\t`⚠️ [Rhino Compute] Request [${requestId}] targets remote server (${config.serverUrl}) but no API key is configured. Requests may fail or be rate-limited.`\n\t\t);\n\t}\n\n\treturn headers;\n}\n\nfunction generateRequestId(): string {\n\treturn `${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;\n}\n\nfunction log(message: string, debug?: boolean): void {\n\tif (debug) getLogger().debug(message);\n}\n\n/**\n * Compose a caller-supplied AbortSignal with an optional timeout. Returns a\n * combined signal, or `undefined` if neither was given.\n *\n * Uses `AbortSignal.timeout` (not setTimeout) so the timer is not throttled\n * when the tab is hidden. Falls back to a manual timer for older runtimes.\n */\nfunction composeSignal(\n\tcallerSignal: AbortSignal | undefined,\n\ttimeoutMs: number | undefined\n): { signal: AbortSignal | undefined; cleanup: () => void } {\n\tconst signals: AbortSignal[] = [];\n\tlet cleanup = () => {};\n\n\tif (callerSignal) signals.push(callerSignal);\n\n\tif (timeoutMs && timeoutMs > 0) {\n\t\tif (typeof AbortSignal !== 'undefined' && typeof AbortSignal.timeout === 'function') {\n\t\t\tsignals.push(AbortSignal.timeout(timeoutMs));\n\t\t} else {\n\t\t\t// Fallback for runtimes without AbortSignal.timeout\n\t\t\tconst ctrl = new AbortController();\n\t\t\tconst id = setTimeout(() => ctrl.abort(), timeoutMs);\n\t\t\tcleanup = () => clearTimeout(id);\n\t\t\tsignals.push(ctrl.signal);\n\t\t}\n\t}\n\n\tif (signals.length === 0) return { signal: undefined, cleanup };\n\tif (signals.length === 1) return { signal: signals[0], cleanup };\n\n\tif (typeof AbortSignal !== 'undefined' && typeof (AbortSignal as any).any === 'function') {\n\t\treturn { signal: (AbortSignal as any).any(signals) as AbortSignal, cleanup };\n\t}\n\n\t// Manual composition fallback\n\tconst ctrl = new AbortController();\n\tconst onAbort = () => ctrl.abort();\n\tfor (const s of signals) {\n\t\tif (s.aborted) {\n\t\t\tctrl.abort();\n\t\t\tbreak;\n\t\t}\n\t\ts.addEventListener('abort', onAbort, { once: true });\n\t}\n\tconst prevCleanup = cleanup;\n\tcleanup = () => {\n\t\tprevCleanup();\n\t\tfor (const s of signals) s.removeEventListener('abort', onAbort);\n\t};\n\treturn { signal: ctrl.signal, cleanup };\n}\n\n// ============================================================================\n// Response Processing\n// ============================================================================\n\nasync function handleResponse(\n\tresponse: Response,\n\tfullUrl: string,\n\trequestId: string,\n\trequestSize: number,\n\tserverUrl: string,\n\tstartTime: number,\n\tdebug?: boolean\n): Promise<any> {\n\tconst responseTime = Math.round(performance.now() - startTime);\n\n\tif (!response.ok) {\n\t\t// Read body once and reuse\n\t\tlet errorBody = await response.text();\n\n\t\t// Enhanced logging for errors\n\t\tif (debug) {\n\t\t\tlog(\n\t\t\t\t`❌ Request [${requestId}] failed with HTTP ${response.status} in ${responseTime}ms`,\n\t\t\t\ttrue\n\t\t\t);\n\t\t\tlog(` URL: ${fullUrl}`, true);\n\t\t\tlog(` Status: ${response.status} ${response.statusText}`, true);\n\t\t\tif (errorBody) {\n\t\t\t\tlog(\n\t\t\t\t\t` Response body: ${errorBody.substring(0, 500)}${errorBody.length > 500 ? '...' : ''}`,\n\t\t\t\t\ttrue\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Check if it's a valid compute response with errors/warnings\n\t\tif (response.status === 500) {\n\t\t\ttry {\n\t\t\t\tconst parsed = JSON.parse(errorBody);\n\t\t\t\t// If it has values, it's a partial success with errors\n\t\t\t\tif (parsed?.values && (parsed.errors || parsed.warnings)) {\n\t\t\t\t\tif (debug) {\n\t\t\t\t\t\tlog(\n\t\t\t\t\t\t\t`⚠️ Request [${requestId}] completed with Grasshopper errors in ${responseTime}ms`,\n\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (parsed.errors?.length > 0) {\n\t\t\t\t\t\t\tlog(` Errors: ${JSON.stringify(parsed.errors, null, 2)}`, true);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (parsed.warnings?.length > 0) {\n\t\t\t\t\t\t\tlog(` Warnings: ${JSON.stringify(parsed.warnings, null, 2)}`, true);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn parsed;\n\t\t\t\t}\n\n\t\t\t\t// If it's a raw exception from the server (like ArgumentException), include it in the error message\n\t\t\t\tif (parsed?.Message) {\n\t\t\t\t\terrorBody = `${parsed.ExceptionType ? parsed.ExceptionType + ': ' : ''}${parsed.Message}\\n${parsed.StackTrace || ''}`;\n\t\t\t\t} else if (parsed?.error) {\n\t\t\t\t\terrorBody =\n\t\t\t\t\t\ttypeof parsed.error === 'string' ? parsed.error : JSON.stringify(parsed.error, null, 2);\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tif (debug) {\n\t\t\t\t\tlog(` Failed to parse error body as JSON: ${e}`, true);\n\t\t\t\t}\n\t\t\t\t// Not valid JSON, proceed with HTTP error\n\t\t\t}\n\t\t}\n\n\t\tthrowHttpError(response, fullUrl, requestId, requestSize, serverUrl, errorBody);\n\t}\n\n\tlog(`✅ Request [${requestId}] completed in ${responseTime}ms`, debug);\n\n\ttry {\n\t\treturn await response.json();\n\t} catch (error) {\n\t\tthrow new RhinoComputeError('Failed to parse JSON response', ErrorCodes.NETWORK_ERROR, {\n\t\t\tstatusCode: response.status,\n\t\t\tcontext: {\n\t\t\t\turl: fullUrl,\n\t\t\t\trequestId\n\t\t\t},\n\t\t\toriginalError: error instanceof Error ? error : new Error(String(error))\n\t\t});\n\t}\n}\n\n// ============================================================================\n// Single attempt\n// ============================================================================\n\ninterface AttemptContext {\n\tendpoint: string;\n\tbody: string;\n\trequestSize: number;\n\tfullUrl: string;\n\trequestId: string;\n\theaders: HeadersInit;\n\tconfig: ComputeConfig | GrasshopperComputeConfig;\n}\n\ninterface AttemptResult {\n\tok: true;\n\tvalue: any;\n}\n\ninterface AttemptRetry {\n\tok: false;\n\tretry: true;\n\tdelayMs: number;\n\tcause: RhinoComputeError;\n}\n\ninterface AttemptFatal {\n\tok: false;\n\tretry: false;\n\tcause: RhinoComputeError;\n}\n\nasync function attemptFetch(\n\tctx: AttemptContext,\n\tretryPolicy: Required<RetryPolicy>,\n\tattempt: number,\n\ttotalAttempts: number\n): Promise<AttemptResult | AttemptRetry | AttemptFatal> {\n\tconst { signal, cleanup } = composeSignal(ctx.config.signal, ctx.config.timeoutMs);\n\tconst startTime = performance.now();\n\n\ttry {\n\t\tconst response = await fetch(ctx.fullUrl, {\n\t\t\tmethod: 'POST',\n\t\t\tbody: ctx.body,\n\t\t\theaders: ctx.headers,\n\t\t\tsignal\n\t\t});\n\n\t\t// 429 with Retry-After or retryable 5xx → maybe retry\n\t\tconst isRetryableStatus =\n\t\t\tRETRYABLE_STATUS.has(response.status) ||\n\t\t\t(retryPolicy.retryOn429 && response.status === 429);\n\n\t\tif (isRetryableStatus && attempt < totalAttempts - 1) {\n\t\t\tconst retryAfterMs = parseRetryAfter(response.headers.get('Retry-After'));\n\t\t\tconst delayMs = retryAfterMs ?? backoffDelay(attempt, retryPolicy);\n\t\t\t// Drain the body so the connection can be reused\n\t\t\tawait response.text().catch(() => {});\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\tretry: true,\n\t\t\t\tdelayMs,\n\t\t\t\tcause: new RhinoComputeError(\n\t\t\t\t\t`HTTP ${response.status} ${response.statusText} (will retry)`,\n\t\t\t\t\tErrorCodes.NETWORK_ERROR,\n\t\t\t\t\t{ statusCode: response.status, context: { requestId: ctx.requestId } }\n\t\t\t\t)\n\t\t\t};\n\t\t}\n\n\t\tconst value = await handleResponse(\n\t\t\tresponse,\n\t\t\tctx.fullUrl,\n\t\t\tctx.requestId,\n\t\t\tctx.requestSize,\n\t\t\tctx.config.serverUrl,\n\t\t\tstartTime,\n\t\t\tctx.config.debug\n\t\t);\n\t\treturn { ok: true, value };\n\t} catch (error) {\n\t\t// Caller-aborted vs timeout-aborted distinction\n\t\tif (error instanceof Error && (error.name === 'AbortError' || error.name === 'TimeoutError')) {\n\t\t\tconst callerAborted = ctx.config.signal?.aborted === true;\n\n\t\t\tif (callerAborted) {\n\t\t\t\t// Caller cancellation is never retried — propagate immediately\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\tretry: false,\n\t\t\t\t\tcause: new RhinoComputeError('Request aborted by caller', ErrorCodes.UNKNOWN_ERROR, {\n\t\t\t\t\t\tcontext: {\n\t\t\t\t\t\t\tendpoint: ctx.endpoint,\n\t\t\t\t\t\t\trequestId: ctx.requestId,\n\t\t\t\t\t\t\trequestSize: ctx.requestSize\n\t\t\t\t\t\t},\n\t\t\t\t\t\toriginalError: error\n\t\t\t\t\t})\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Timeout — retryable up to attempts limit\n\t\t\tconst fatal = new RhinoComputeError(\n\t\t\t\t`Request timed out after ${ctx.config.timeoutMs}ms`,\n\t\t\t\tErrorCodes.TIMEOUT_ERROR,\n\t\t\t\t{\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\tserverUrl: ctx.config.serverUrl,\n\t\t\t\t\t\ttimeoutMs: ctx.config.timeoutMs,\n\t\t\t\t\t\turl: ctx.fullUrl,\n\t\t\t\t\t\trequestId: ctx.requestId,\n\t\t\t\t\t\tendpoint: ctx.endpoint,\n\t\t\t\t\t\trequestSize: ctx.requestSize\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t);\n\t\t\tif (attempt < totalAttempts - 1) {\n\t\t\t\treturn { ok: false, retry: true, delayMs: backoffDelay(attempt, retryPolicy), cause: fatal };\n\t\t\t}\n\t\t\treturn { ok: false, retry: false, cause: fatal };\n\t\t}\n\n\t\t// Network error (TypeError) — retryable\n\t\tif (error instanceof TypeError) {\n\t\t\tconst fatal = new RhinoComputeError(\n\t\t\t\t`Network error: ${error.message}`,\n\t\t\t\tErrorCodes.NETWORK_ERROR,\n\t\t\t\t{\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\tserverUrl: ctx.config.serverUrl,\n\t\t\t\t\t\turl: ctx.fullUrl,\n\t\t\t\t\t\trequestId: ctx.requestId,\n\t\t\t\t\t\tendpoint: ctx.endpoint,\n\t\t\t\t\t\trequestSize: ctx.requestSize\n\t\t\t\t\t},\n\t\t\t\t\toriginalError: error\n\t\t\t\t}\n\t\t\t);\n\t\t\tif (attempt < totalAttempts - 1) {\n\t\t\t\treturn { ok: false, retry: true, delayMs: backoffDelay(attempt, retryPolicy), cause: fatal };\n\t\t\t}\n\t\t\treturn { ok: false, retry: false, cause: fatal };\n\t\t}\n\n\t\t// RhinoComputeError thrown from handleResponse — already has full context.\n\t\t// Retryable only if it carries a retryable status code.\n\t\tif (error instanceof RhinoComputeError) {\n\t\t\tconst status = error.statusCode;\n\t\t\tconst retryable =\n\t\t\t\tstatus !== undefined &&\n\t\t\t\t(RETRYABLE_STATUS.has(status) || (retryPolicy.retryOn429 && status === 429));\n\t\t\tif (retryable && attempt < totalAttempts - 1) {\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\tretry: true,\n\t\t\t\t\tdelayMs: backoffDelay(attempt, retryPolicy),\n\t\t\t\t\tcause: error\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn { ok: false, retry: false, cause: error };\n\t\t}\n\n\t\t// Unknown — wrap and don't retry\n\t\treturn {\n\t\t\tok: false,\n\t\t\tretry: false,\n\t\t\tcause: new RhinoComputeError(\n\t\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t\tErrorCodes.UNKNOWN_ERROR,\n\t\t\t\t{\n\t\t\t\t\tcontext: { endpoint: ctx.endpoint, requestId: ctx.requestId },\n\t\t\t\t\toriginalError: error instanceof Error ? error : new Error(String(error))\n\t\t\t\t}\n\t\t\t)\n\t\t};\n\t} finally {\n\t\tcleanup();\n\t}\n}\n\n// ============================================================================\n// Main Function\n// ============================================================================\n\n/**\n * Generic Rhino Compute fetch function.\n * Sends a POST request to any Compute endpoint with pre-prepared arguments.\n *\n * Use this for advanced, low-level control over compute requests. For most use cases, prefer higher-level APIs.\n *\n * @typeParam E - The endpoint name (e.g., 'grasshopper', 'io'). Determines the response type for better type safety.\n * @param endpoint - The Compute API endpoint (e.g., 'grasshopper', 'io', 'mesh').\n * @param args - Pre-prepared arguments for the request body.\n * @param config - Compute configuration (server URL, API key, timeout, debug, retry, signal).\n * @returns The parsed JSON response from the server, typed according to the endpoint.\n *\n * @example\n * // Basic usage for the Grasshopper endpoint:\n * const response = await fetchRhinoCompute(\n * 'grasshopper',\n * { ... },\n * {\n * serverUrl: 'https://my-server.com',\n * debug: true,\n * timeoutMs: 30_000,\n * retry: { attempts: 2 },\n * signal: controller.signal,\n * }\n * );\n */\nexport async function fetchRhinoCompute<E extends Endpoint>(\n\tendpoint: E,\n\targs: Record<string, any>,\n\tconfig: ComputeConfig | GrasshopperComputeConfig\n): Promise<ComputeResponseFor<E>> {\n\tconst requestId = generateRequestId();\n\tconst body = JSON.stringify(args);\n\tconst requestSize = body.length;\n\tconst fullUrl = buildUrl(endpoint, config.serverUrl);\n\tconst headers = buildHeaders(requestId, config);\n\tconst retryPolicy = resolveRetryPolicy(config.retry);\n\tconst totalAttempts = retryPolicy.attempts + 1;\n\n\tif (config.debug) {\n\t\tconst sizeKb = (requestSize / 1024).toFixed(2);\n\t\tconst emoji = requestSize > 100000 ? '⚠️' : '🚀';\n\t\tlog(`${emoji} Starting compute request [${requestId}]: ${endpoint} (${sizeKb}KB)`, true);\n\t}\n\n\tconst ctx: AttemptContext = {\n\t\tendpoint,\n\t\tbody,\n\t\trequestSize,\n\t\tfullUrl,\n\t\trequestId,\n\t\theaders,\n\t\tconfig\n\t};\n\n\tlet lastError: RhinoComputeError | null = null;\n\n\tfor (let attempt = 0; attempt < totalAttempts; attempt++) {\n\t\tconst result = await attemptFetch(ctx, retryPolicy, attempt, totalAttempts);\n\n\t\tif (result.ok) return result.value as ComputeResponseFor<E>;\n\n\t\tif (!result.retry) throw result.cause;\n\n\t\tlastError = result.cause;\n\t\tif (config.debug) {\n\t\t\tlog(\n\t\t\t\t`🔁 Request [${requestId}] retrying after ${result.delayMs}ms (attempt ${attempt + 2}/${totalAttempts}): ${result.cause.message}`,\n\t\t\t\ttrue\n\t\t\t);\n\t\t}\n\n\t\ttry {\n\t\t\tawait sleep(result.delayMs, config.signal);\n\t\t} catch {\n\t\t\t// Caller cancelled during backoff\n\t\t\tthrow new RhinoComputeError('Request aborted by caller', ErrorCodes.UNKNOWN_ERROR, {\n\t\t\t\tcontext: { endpoint, requestId, requestSize },\n\t\t\t\toriginalError: lastError\n\t\t\t});\n\t\t}\n\t}\n\n\t// Exhausted retries — throw the last seen error\n\tthrow (\n\t\tlastError ??\n\t\tnew RhinoComputeError('Unknown error after retries', ErrorCodes.UNKNOWN_ERROR, {\n\t\t\tcontext: { endpoint, requestId, requestSize }\n\t\t})\n\t);\n}\n","import { RhinoComputeError, ErrorCodes } from '../errors';\nimport { getLogger } from '../utils/logger';\n\n/**\n * ComputeServerStats provides methods to query Rhino Compute server statistics.\n *\n * @public Use this for server health monitoring and statistics.\n *\n * @example\n * ```typescript\n * const stats = new ComputeServerStats('http://localhost:6500', 'your-api-key');\n *\n * try {\n * const isOnline = await stats.isServerOnline();\n * const children = await stats.getActiveChildren();\n * const version = await stats.getVersion();\n *\n * // Or get everything at once\n * const allStats = await stats.getServerStats();\n * } finally {\n * await stats.dispose(); // Clean up resources\n * }\n * ```\n */\nexport default class ComputeServerStats {\n\tprivate readonly serverUrl: string;\n\tprivate readonly apiKey?: string;\n\tprivate disposed = false;\n\tprivate activeMonitors: Set<() => void> = new Set();\n\tprivate activeTimeouts: Set<ReturnType<typeof setTimeout>> = new Set();\n\n\t/**\n\t * @param serverUrl - Base URL of the Rhino Compute server with http:// or https:// scheme (e.g., 'http://localhost:6500')\n\t * @param apiKey - Optional API key for authentication\n\t */\n\tconstructor(serverUrl: string, apiKey?: string) {\n\t\tif (!serverUrl?.trim()) {\n\t\t\tthrow new RhinoComputeError('serverUrl is required', ErrorCodes.INVALID_CONFIG, {\n\t\t\t\tcontext: { serverUrl }\n\t\t\t});\n\t\t}\n\n\t\t// Validate URL has http:// or https:// scheme\n\t\tif (!serverUrl.match(/^https?:\\/\\//)) {\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t`Invalid serverUrl: \"${serverUrl}\". Must start with \"http://\" or \"https://\". ` +\n\t\t\t\t\t`For example: \"http://localhost:5000\" or \"https://example.com\"`,\n\t\t\t\tErrorCodes.INVALID_CONFIG,\n\t\t\t\t{ context: { serverUrl } }\n\t\t\t);\n\t\t}\n\n\t\ttry {\n\t\t\tnew URL(serverUrl);\n\t\t} catch (err) {\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t`Invalid serverUrl: \"${serverUrl}\". Must be a valid URL. ` +\n\t\t\t\t\t`Received error: ${err instanceof Error ? err.message : String(err)}`,\n\t\t\t\tErrorCodes.INVALID_CONFIG,\n\t\t\t\t{\n\t\t\t\t\tcontext: { serverUrl },\n\t\t\t\t\toriginalError: err instanceof Error ? err : undefined\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\n\t\tthis.apiKey = apiKey;\n\t\tthis.serverUrl = serverUrl.replace(/\\/+$/, '');\n\t}\n\n\t/**\n\t * Build request headers with optional API key.\n\t */\n\tprivate buildHeaders(): HeadersInit {\n\t\tconst headers: HeadersInit = {\n\t\t\t'Content-Type': 'application/json'\n\t\t};\n\n\t\tif (this.apiKey) {\n\t\t\theaders['RhinoComputeKey'] = this.apiKey;\n\t\t}\n\n\t\treturn headers;\n\t}\n\n\t/**\n\t * Check if the server is online.\n\t */\n\tpublic async isServerOnline(): Promise<boolean> {\n\t\tthis.ensureNotDisposed();\n\n\t\tconst url = `${this.serverUrl}/healthcheck`;\n\t\tconst init: RequestInit = { headers: this.buildHeaders(), method: 'GET' };\n\n\t\ttry {\n\t\t\tconst response = await fetch(url, init);\n\n\t\t\treturn response.ok;\n\t\t} catch (err) {\n\t\t\tgetLogger().debug('[ComputeServerStats] Fetch error:', err);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Get the number of active child processes on the server.\n\t *\n\t * @returns Number of active children, or null if unavailable\n\t */\n\tpublic async getActiveChildren(): Promise<number | null> {\n\t\tthis.ensureNotDisposed();\n\n\t\ttry {\n\t\t\tconst response = await fetch(`${this.serverUrl}/activechildren`, {\n\t\t\t\theaders: this.buildHeaders()\n\t\t\t});\n\t\t\tif (!response.ok) {\n\t\t\t\tgetLogger().warn('[ComputeServerStats] Failed to fetch active children:', response.status);\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst text = await response.text();\n\t\t\tconst count = parseInt(text.trim(), 10);\n\n\t\t\tif (isNaN(count)) {\n\t\t\t\tgetLogger().warn('[ComputeServerStats] Invalid active children response:', text);\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn count;\n\t\t} catch (err) {\n\t\t\tgetLogger().warn('[ComputeServerStats] Error fetching active children:', err);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Get the server version information.\n\t *\n\t * @returns Version object with rhino, compute, and git_sha, or null if unavailable\n\t */\n\tpublic async getVersion(): Promise<{\n\t\trhino: string;\n\t\tcompute: string;\n\t\tgit_sha: string | null;\n\t} | null> {\n\t\tthis.ensureNotDisposed();\n\n\t\ttry {\n\t\t\tconst response = await fetch(`${this.serverUrl}/version`, {\n\t\t\t\theaders: this.buildHeaders()\n\t\t\t});\n\n\t\t\tif (!response.ok) {\n\t\t\t\tgetLogger().warn('[ComputeServerStats] Failed to fetch version:', response.status);\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst json = await response.json();\n\t\t\t\treturn {\n\t\t\t\t\trhino: json.rhino ?? '',\n\t\t\t\t\tcompute: json.compute ?? '',\n\t\t\t\t\tgit_sha: json.git_sha ?? null\n\t\t\t\t};\n\t\t\t} catch {\n\t\t\t\t// Fallback: parse as plain text\n\t\t\t\tconst text = await response.text();\n\t\t\t\treturn { rhino: text, compute: '', git_sha: null };\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tgetLogger().warn('[ComputeServerStats] Error fetching version:', err);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Get comprehensive server statistics.\n\t * Fetches all available server information in parallel.\n\t *\n\t * @returns Object containing server status and available stats\n\t */\n\tpublic async getServerStats(): Promise<{\n\t\tisOnline: boolean;\n\t\tversion?: { rhino: string; compute: string; git_sha: string | null };\n\t\tactiveChildren?: number;\n\t}> {\n\t\tthis.ensureNotDisposed();\n\n\t\tconst isOnline = await this.isServerOnline();\n\n\t\tif (!isOnline) {\n\t\t\treturn { isOnline: false };\n\t\t}\n\n\t\tconst [version, activeChildren] = await Promise.all([\n\t\t\tthis.getVersion(),\n\t\t\tthis.getActiveChildren()\n\t\t]);\n\n\t\treturn {\n\t\t\tisOnline: true,\n\t\t\t...(version && { version }),\n\t\t\t...(activeChildren !== null && { activeChildren })\n\t\t};\n\t}\n\n\t/**\n\t * Continuously monitor server stats at specified interval.\n\t *\n\t * @param callback - Function called with stats on each interval\n\t * @param intervalMs - Milliseconds between checks (default: 5000)\n\t * @returns Function to stop monitoring\n\t *\n\t * @example\n\t * ```typescript\n\t * const stopMonitoring = stats.monitor((data) => {\n\t * console.log('Server stats:', data);\n\t * }, 3000);\n\t *\n\t * // Later...\n\t * stopMonitoring();\n\t * ```\n\t */\n\tpublic monitor(\n\t\tcallback: (stats: Awaited<ReturnType<typeof this.getServerStats>>) => void,\n\t\tintervalMs: number = 5000\n\t): () => void {\n\t\tthis.ensureNotDisposed();\n\n\t\tlet active = true;\n\t\tlet currentTimeoutId: ReturnType<typeof setTimeout> | null = null;\n\n\t\tgetLogger().info(`🔄 Starting server stats monitoring every ${intervalMs}ms`);\n\n\t\tconst check = async () => {\n\t\t\t// Clear current timeout from tracking since it has fired\n\t\t\tif (currentTimeoutId !== null) {\n\t\t\t\tthis.activeTimeouts.delete(currentTimeoutId);\n\t\t\t\tcurrentTimeoutId = null;\n\t\t\t}\n\n\t\t\tif (!active || this.disposed) return;\n\n\t\t\ttry {\n\t\t\t\tconst _stats = await this.getServerStats();\n\n\t\t\t\t// Check again after async operation to prevent race condition\n\t\t\t\tif (!active || this.disposed) return;\n\n\t\t\t\ttry {\n\t\t\t\t\tcallback(_stats);\n\t\t\t\t} catch (err) {\n\t\t\t\t\tgetLogger().error('[ComputeServerStats] Monitor callback threw:', err);\n\t\t\t\t}\n\t\t\t} catch (err) {\n\t\t\t\tgetLogger().error('[ComputeServerStats] Failed to fetch stats during monitor:', err);\n\t\t\t}\n\n\t\t\tif (active && !this.disposed) {\n\t\t\t\tcurrentTimeoutId = setTimeout(() => void check(), intervalMs);\n\t\t\t\tthis.activeTimeouts.add(currentTimeoutId);\n\t\t\t}\n\t\t};\n\n\t\tconst stopMonitoring = () => {\n\t\t\tactive = false;\n\n\t\t\t// Clear any pending timeout\n\t\t\tif (currentTimeoutId !== null) {\n\t\t\t\tclearTimeout(currentTimeoutId);\n\t\t\t\tthis.activeTimeouts.delete(currentTimeoutId);\n\t\t\t\tcurrentTimeoutId = null;\n\t\t\t}\n\n\t\t\tthis.activeMonitors.delete(stopMonitoring);\n\t\t};\n\n\t\tthis.activeMonitors.add(stopMonitoring);\n\n\t\t// Explicitly mark as fire-and-forget since we don't need to await the initial call\n\t\tvoid check();\n\n\t\treturn stopMonitoring;\n\t}\n\n\t/**\n\t * Disposes of all resources and stops all active monitors.\n\t * Call this when you're done using the stats instance.\n\t */\n\tpublic async dispose(): Promise<void> {\n\t\tif (this.disposed) return;\n\n\t\tthis.disposed = true;\n\n\t\t// Stop all active monitors (this will also clear their timeouts)\n\t\tfor (const stopMonitor of this.activeMonitors) {\n\t\t\tstopMonitor();\n\t\t}\n\t\tthis.activeMonitors.clear();\n\n\t\t// Clear any remaining timeouts (defensive cleanup)\n\t\tfor (const timeoutId of this.activeTimeouts) {\n\t\t\tclearTimeout(timeoutId);\n\t\t}\n\t\tthis.activeTimeouts.clear();\n\t}\n\n\t/**\n\t * Ensures the instance hasn't been disposed.\n\t */\n\tprivate ensureNotDisposed(): void {\n\t\tif (this.disposed) {\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t'ComputeServerStats has been disposed and cannot be used',\n\t\t\t\tErrorCodes.INVALID_STATE,\n\t\t\t\t{ context: { disposed: this.disposed } }\n\t\t\t);\n\t\t}\n\t}\n}\n","/**\n * Converts a string to camelCase.\n * @param str - The string to convert\n * @param options - Options object\n * - preserveSpaces: If true, spaces are preserved (default: false)\n */\nexport function toCamelCase(str: string, options: { preserveSpaces?: boolean } = {}): string {\n\tconst { preserveSpaces = false } = options;\n\tlet s = str.trim();\n\tif (!preserveSpaces) {\n\t\t// Remove spaces, dashes, and underscores, camelCase the next letter\n\t\ts = s\n\t\t\t.replace(/^[A-Z]/, (m) => m.toLowerCase())\n\t\t\t.replace(/[\\s-_]+(.)?/g, (_, c) => (c ? c.toUpperCase() : ''));\n\t\treturn s;\n\t} else {\n\t\t// Only camelCase after dashes/underscores, preserve spaces\n\t\ts =\n\t\t\ts.charAt(0).toLowerCase() +\n\t\t\ts.slice(1).replace(/[-_](.)/g, (_, c) => (c ? c.toUpperCase() : ''));\n\t\treturn s;\n\t}\n}\n\n/**\n * Recursively converts all object keys to camelCase.\n * @param obj - The object to process\n * @param options - Options object\n * - deep: If true, process deeply\n * - preserveSpaces: If true, spaces are preserved in keys\n * @returns The new object with camelCased keys\n * @internal\n */\nexport function camelcaseKeys(\n\tobj: unknown,\n\toptions: { deep?: boolean; preserveSpaces?: boolean } = {}\n): unknown {\n\tif (!obj || typeof obj !== 'object') {\n\t\treturn obj;\n\t}\n\n\tif (Array.isArray(obj)) {\n\t\treturn options.deep ? obj.map((item) => camelcaseKeys(item, options)) : obj;\n\t}\n\n\treturn Object.keys(obj).reduce(\n\t\t(result, key) => {\n\t\t\tconst camelKey = toCamelCase(key, { preserveSpaces: options.preserveSpaces });\n\t\t\tconst value = (obj as any)[key];\n\t\t\t(result as any)[camelKey] = options.deep ? camelcaseKeys(value, options) : value;\n\t\t\treturn result;\n\t\t},\n\t\t{} as Record<string, unknown>\n\t);\n}\n"],"mappings":"kOAAO,IAAMA,EAAa,CACzB,cAAe,gBACf,WAAY,aACZ,iBAAkB,mBAClB,kBAAmB,oBACnB,cAAe,gBACf,WAAY,aACZ,cAAe,gBACf,cAAe,gBACf,cAAe,gBACf,eAAgB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,QAAQ,SAAWG,GAAMA,EAAE,YAAY,CAAC,EACxC,QAAQ,eAAgB,CAACF,EAAGC,IAAOA,EAAIA,EAAE,YAAY,EAAI,EAAG,EACvDF,EAQT,CAWO,SAASI,EACfC,EACAP,EAAwD,CAAC,EAC/C,CACV,MAAI,CAACO,GAAO,OAAOA,GAAQ,SACnBA,EAGJ,MAAM,QAAQA,CAAG,EACbP,EAAQ,KAAOO,EAAI,IAAKC,GAASF,EAAcE,EAAMR,CAAO,CAAC,EAAIO,EAGlE,OAAO,KAAKA,CAAG,EAAE,OACvB,CAACE,EAAQC,IAAQ,CAChB,IAAMC,EAAWb,EAAYY,EAAK,CAAE,eAAgBV,EAAQ,cAAe,CAAC,EACtEY,EAASL,EAAYG,CAAG,EAC9B,OAACD,EAAeE,CAAQ,EAAIX,EAAQ,KAAOM,EAAcM,EAAOZ,CAAO,EAAIY,EACpEH,CACR,EACA,CAAC,CACF,CACD","names":["ErrorCodes","RhinoComputeError","_RhinoComputeError","message","code","options","__publicField","inputName","reason","context","ErrorCodes","expectedType","defaultValue","availableValues","paramType","paramName","expectedStructure","NoOpLogger","ConsoleLogger","message","args","internalLogger","getLogger","setLogger","logger","enableDebugLogging","DEFAULT_RETRY","RETRYABLE_STATUS","resolveRetryPolicy","policy","parseRetryAfter","headerValue","seconds","dateMs","delta","backoffDelay","attempt","exponential","jitter","sleep","ms","signal","resolve","reject","id","onAbort","throwHttpError","response","fullUrl","requestId","requestSize","serverUrl","errorBody","status","statusText","context","bodyHint","error","ErrorCodes","RhinoComputeError","buildUrl","endpoint","base","path","isLocalhost","host","buildHeaders","config","headers","getLogger","generateRequestId","log","message","debug","composeSignal","callerSignal","timeoutMs","signals","cleanup","ctrl","s","prevCleanup","handleResponse","startTime","responseTime","parsed","e","attemptFetch","ctx","retryPolicy","totalAttempts","delayMs","fatal","fetchRhinoCompute","args","body","sizeKb","emoji","lastError","result","ComputeServerStats","serverUrl","apiKey","__publicField","RhinoComputeError","ErrorCodes","err","headers","url","init","getLogger","response","text","count","json","version","activeChildren","callback","intervalMs","active","currentTimeoutId","check","_stats","stopMonitoring","stopMonitor","timeoutId","toCamelCase","str","options","preserveSpaces","s","_","c","m","camelcaseKeys","obj","item","result","key","camelKey","value"]}
|