selva-compute 1.2.0 → 1.3.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.
@@ -0,0 +1,2 @@
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 _chunkFB4LUGFJcjs = require('./chunk-FB4LUGFJ.cjs');var _chunkMTDJ3VNBcjs = require('./chunk-MTDJ3VNB.cjs');_chunkMTDJ3VNBcjs.h.call(void 0, );_chunkMTDJ3VNBcjs.f.call(void 0, );_chunkMTDJ3VNBcjs.l.call(void 0, );var T=class e{constructor(r){_chunkMTDJ3VNBcjs.c.call(void 0, this,"config");_chunkMTDJ3VNBcjs.c.call(void 0, this,"serverStats");_chunkMTDJ3VNBcjs.c.call(void 0, this,"disposed",!1);this.config=this.normalizeComputeConfig(r),this.serverStats=new (0, _chunkMTDJ3VNBcjs.n)(this.config.serverUrl,this.config.apiKey)}static async create(r){let t=new e(r);if(!await t.serverStats.isServerOnline())throw new (0, _chunkMTDJ3VNBcjs.e)("Rhino Compute server is not online",_chunkMTDJ3VNBcjs.d.NETWORK_ERROR,{context:{serverUrl:t.config.serverUrl}});return t}getConfig(){return this.ensureNotDisposed(),{...this.config}}async getIO(r){return this.ensureNotDisposed(),P(r,this.config)}async getRawIO(r){return this.ensureNotDisposed(),b(r,this.config)}async solve(r,t){this.ensureNotDisposed();try{if(typeof r=="string"&&!_optionalChain([r, 'optionalAccess', _2 => _2.trim, 'call', _3 => _3()]))throw new (0, _chunkMTDJ3VNBcjs.e)("Definition URL/content is required",_chunkMTDJ3VNBcjs.d.INVALID_INPUT,{context:{receivedUrl:r}});if(r instanceof Uint8Array&&r.length===0)throw new (0, _chunkMTDJ3VNBcjs.e)("Definition content is empty",_chunkMTDJ3VNBcjs.d.INVALID_INPUT);if(!await this.serverStats.isServerOnline())throw new (0, _chunkMTDJ3VNBcjs.e)("Rhino Compute server is not online",_chunkMTDJ3VNBcjs.d.NETWORK_ERROR,{context:{serverUrl:this.config.serverUrl}});let n=await C(t,r,this.config);if(n&&typeof n=="object"&&"message"in n&&!("fileData"in n))throw new (0, _chunkMTDJ3VNBcjs.e)(n.message||"Computation failed",_chunkMTDJ3VNBcjs.d.COMPUTATION_ERROR,{context:{definition:typeof r=="string"&&r.length<200?r:"...content...",inputs:t}});return n}catch(n){throw this.config.debug&&_chunkMTDJ3VNBcjs.i.call(void 0, ).error("Compute failed:",n),n instanceof _chunkMTDJ3VNBcjs.e?n:new (0, _chunkMTDJ3VNBcjs.e)(n instanceof Error?n.message:String(n),_chunkMTDJ3VNBcjs.d.COMPUTATION_ERROR,{context:{definition:typeof r=="string"&&r.length<200?r:"...content...",inputs:t},originalError:n instanceof Error?n:new Error(String(n))})}}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, _chunkMTDJ3VNBcjs.e)("GrasshopperClient has been disposed and cannot be used",_chunkMTDJ3VNBcjs.d.INVALID_STATE)}normalizeComputeConfig(r){if(!_optionalChain([r, 'access', _4 => _4.serverUrl, 'optionalAccess', _5 => _5.trim, 'call', _6 => _6()]))throw new (0, _chunkMTDJ3VNBcjs.e)("serverUrl is required",_chunkMTDJ3VNBcjs.d.INVALID_CONFIG,{context:{receivedServerUrl:r.serverUrl}});try{new URL(r.serverUrl)}catch (e2){throw new (0, _chunkMTDJ3VNBcjs.e)("serverUrl must be a valid URL",_chunkMTDJ3VNBcjs.d.INVALID_CONFIG,{context:{receivedServerUrl:r.serverUrl}})}if(r.serverUrl===""||r.serverUrl==="https://compute.rhino3d.com/")throw new (0, _chunkMTDJ3VNBcjs.e)("serverUrl must be set to your Compute server URL. The default public endpoint is not allowed.",_chunkMTDJ3VNBcjs.d.INVALID_CONFIG,{context:{receivedServerUrl:r.serverUrl}});return{...r,serverUrl:r.serverUrl.replace(/\/+$/,""),apiKey:r.apiKey,authToken:r.authToken,debug:_nullishCoalesce(r.debug, () => (!1)),suppressClientSideWarning:r.suppressClientSideWarning}}};var L=async(e,r=null)=>{try{return await K(e,r)}catch(t){throw new (0, _chunkMTDJ3VNBcjs.e)("Failed to extract files from compute response",_chunkMTDJ3VNBcjs.d.INVALID_STATE,{context:{originalError:t instanceof Error?t.message:String(t)},originalError:t instanceof Error?t:void 0})}},S= exports.c =async(e,r,t=null)=>{if(typeof document>"u"||typeof Blob>"u")throw new (0, _chunkMTDJ3VNBcjs.e)("File download functionality is only available in browser environments. This function requires the DOM API (document, Blob).",_chunkMTDJ3VNBcjs.d.BROWSER_ONLY,{context:{environment:typeof window<"u"?"browser (SSR)":"Node.js",documentAvailable:typeof document<"u",blobAvailable:typeof Blob<"u"}});try{let n=await K(e,t);await ie(n,r)}catch(n){throw n instanceof _chunkMTDJ3VNBcjs.e?n:new (0, _chunkMTDJ3VNBcjs.e)("Failed to download files from compute response",_chunkMTDJ3VNBcjs.d.INVALID_STATE,{context:{originalError:n instanceof Error?n.message:String(n)},originalError:n instanceof Error?n:void 0})}},K=async(e,r)=>{let t=[];if(e.forEach(n=>{let a=`${n.fileName}${n.fileType}`;if(n.subFolder&&n.subFolder.trim()!==""&&(a=`${n.subFolder}/${a}`),n.isBase64Encoded===!0&&n.data){let o=_chunkFB4LUGFJcjs.c.call(void 0, n.data);t.push({fileName:`${n.fileName}${n.fileType}`,content:new Uint8Array(o.buffer),path:a})}else n.isBase64Encoded===!1&&n.data&&t.push({fileName:`${n.fileName}${n.fileType}`,content:n.data,path:a})}),r){let n=Array.isArray(r)?r:[r],a=await Promise.all(n.map(async o=>{try{let s=await fetch(o.filePath);if(!s.ok)return _chunkMTDJ3VNBcjs.i.call(void 0, ).warn(`Failed to fetch additional file from URL: ${o.filePath}`),null;let u=await(await s.blob()).arrayBuffer();return{fileName:o.fileName,content:new Uint8Array(u),path:o.fileName}}catch(s){return _chunkMTDJ3VNBcjs.i.call(void 0, ).error(`Error fetching additional file from URL: ${o.filePath}`,s),null}}));t.push(...a.filter(o=>o!==null))}return t};async function ie(e,r){let{zipSync:t,strToU8:n}=await Promise.resolve().then(() => _interopRequireWildcard(require("fflate"))),a={};e.forEach(i=>{a[i.path]=typeof i.content=="string"?n(i.content):i.content});let o=t(a,{level:6}),s=new Blob([o],{type:"application/zip"});ue(s,`${r}.zip`)}function ue(e,r){if(typeof document>"u")throw new (0, _chunkMTDJ3VNBcjs.e)("saveFile requires a browser environment with DOM API access.",_chunkMTDJ3VNBcjs.d.BROWSER_ONLY,{context:{function:"saveFile",requiredAPI:"document"}});let t=document.createElement("a");t.href=URL.createObjectURL(e),t.download=r,t.click(),URL.revokeObjectURL(t.href)}var v=new Map;function Y(e,r){v.set(e,r)}Y("Rhino.Geometry.Point3d",(e,r)=>{let t=r;return!t||typeof t.X!="number"?null:new e.Point([t.X,t.Y,t.Z])});Y("Rhino.Geometry.Line",(e,r)=>{let t=r;return!t||!t.From||!t.To?null:new e.Line([t.From.X,t.From.Y,t.From.Z],[t.To.X,t.To.Y,t.To.Z])});function le(e){if(v.has(e))return v.get(e);for(let[r,t]of v)if(e.startsWith(r))return t}function pe(e){return!e||typeof e!="object"?null:_nullishCoalesce(_nullishCoalesce(e.data, () => (e.value)), () => (null))}function J(e,r,t){let n=le(r);if(n)try{return n(t,e)}catch(a){_chunkMTDJ3VNBcjs.i.call(void 0, ).warn(`Failed to decode Rhino type ${r}:`,a)}try{let a=pe(e);if(a)return t.CommonObject.decode(a)}catch(a){return _chunkMTDJ3VNBcjs.i.call(void 0, ).warn(`Failed to decode ${r} with CommonObject:`,a),{__decodeError:!0,type:r,raw:e}}return e}var D={STRING:"System.String",INT:"System.Int32",DOUBLE:"System.Double",BOOL:"System.Boolean"},fe="Rhino.Geometry.",me=["WebDisplay"],ce="FileData";function de(e){return me.some(r=>e.includes(r))}function X(e){if(typeof e!="string")return e;let r=e.trim();if(!(r.startsWith("{")||r.startsWith("[")||r.startsWith('"')))return e;try{let n=JSON.parse(r);if(typeof n=="string")try{return JSON.parse(n)}catch (e3){return n}return n}catch (e4){return e}}function ye(e,r,t){switch(r){case D.STRING:return typeof e!="string"?e:e.replace(/^"(.*)"$/,"$1");case D.INT:return Number.parseInt(e,10);case D.DOUBLE:return Number.parseFloat(e);case D.BOOL:return String(e).toLowerCase()==="true";default:return t&&r.startsWith(fe)?J(e,r,t):e}}function Z(e,r,t,n){if(de(r))return null;if(typeof e!="string")return e;let a=t?X(e):e;return ye(a,r,n)}function w(e,r){for(let t of Object.values(e))if(Array.isArray(t))for(let n of t)r(n)}function H(e,r=!1,t={}){let{parseValues:n=!0,rhino:a,stringOnly:o=!1}=t,s={};for(let i of e.values)w(i.InnerTree,u=>{if(o&&u.type!==D.STRING)return;let p=r?u.id:i.ParamName;if(!p)return;let c=Z(u.data,u.type,n,a);s[p]===void 0?s[p]=c:Array.isArray(s[p])?s[p].push(c):s[p]=[s[p],c]});return{values:s}}function _(e){let r=[];for(let t of e.values)w(t.InnerTree,n=>{if(!n.type.includes(ce))return;let a=X(n.data);a&&a.fileName&&a.fileType&&a.data&&typeof a.isBase64Encoded=="boolean"&&typeof a.subFolder=="string"&&r.push(a)});return r}function B(e,r,t={}){let{parseValues:n=!0,rhino:a,stringOnly:o=!1}=t,s;if("byName"in r?s=e.values.find(u=>u.ParamName===r.byName):s=e.values.find(u=>{let p=!1;return w(u.InnerTree,c=>{c.id===r.byId&&(p=!0)}),p}),!s)return;let i=[];if(w(s.InnerTree,u=>{if("byId"in r&&u.id!==r.byId||o&&u.type!==D.STRING)return;let p=Z(u.data,u.type,n,a);i.push(p)}),i.length!==0)return i.length===1?i[0]:i}var I=class{constructor(r,t=!1){this.response=r;this.debug=t}getValues(r=!1,t={}){return H(this.response,r,t)}getValueByParamName(r,t){return B(this.response,{byName:r},t)}getValueByParamId(r,t){return B(this.response,{byId:r},t)}async extractMeshesFromResponse(r){let t={debug:this.debug,...r};try{let{getThreeMeshesFromComputeResponse:n}=await Promise.resolve().then(() => _interopRequireWildcard(require("./visualization.cjs")));return n(this.response,t)}catch(n){let{RhinoComputeError:a,ErrorCodes:o}=(_chunkMTDJ3VNBcjs.h.call(void 0, ),_chunkMTDJ3VNBcjs.b.call(void 0, _chunkMTDJ3VNBcjs.g));throw new a("Failed to load three.js visualization module. Ensure three.js is installed as a peer dependency.",o.INVALID_STATE,{context:{originalError:n instanceof Error?n.message:String(n)}})}}getFileData(){return _(this.response)}getAndDownloadFiles(r,t){let n=this.getFileData();S(n,r,t)}};_chunkMTDJ3VNBcjs.l.call(void 0, );function A(e,r){r||typeof window<"u"&&_chunkMTDJ3VNBcjs.i.call(void 0, ).warn(`Warning: ${e} is running on the client side. For better performance and security, consider running this on the server side.`)}async function C(e,r,t){t.debug&&A("solveGrasshopperDefinition",t.suppressClientSideWarning);let n=M(r,e);he(n,t);let a=await _chunkMTDJ3VNBcjs.m.call(void 0, "grasshopper",n,t);return"pointer"in a&&delete a.pointer,a}function M(e,r){let t={algo:null,pointer:null,values:r};return e instanceof Uint8Array?t.algo=_chunkFB4LUGFJcjs.d.call(void 0, e):e.startsWith("http")?t.pointer=e:_chunkFB4LUGFJcjs.b.call(void 0, e)?t.algo=e:t.algo=_chunkFB4LUGFJcjs.a.call(void 0, e),t}function he(e,r){r.cachesolve!==null&&(e.cachesolve=r.cachesolve),r.modelunits!==null&&(e.modelunits=r.modelunits),r.angletolerance!==null&&(e.angletolerance=r.angletolerance),r.absolutetolerance!==null&&(e.absolutetolerance=r.absolutetolerance),r.dataversion!==null&&(e.dataversion=r.dataversion)}_chunkMTDJ3VNBcjs.h.call(void 0, );function Q(e){if(typeof e.default!="object"||e.default===null)return;if(!("innerTree"in e.default)){_chunkMTDJ3VNBcjs.i.call(void 0, ).warn("Unexpected structure in input.default:",e.default),e.default=null;return}let r=e.default.innerTree;if(Object.keys(r).length===0){e.default=void 0;return}if(e.treeAccess||e.atMost&&e.atMost>1){let n={};for(let[a,o]of Object.entries(r))n[a]=o.map(s=>{if(typeof s.data=="string"){if(s.type==="System.Double"||s.type==="System.Int32"){let i=Number(s.data);return Number.isNaN(i)?s.data:i}if(s.type==="System.Boolean")return s.data.toLowerCase()==="true";if(s.type.startsWith("Rhino.Geometry")||s.type==="System.String")try{return JSON.parse(s.data)}catch (e5){return s.data}}return s.data});e.default=n;return}let t=[];for(let n of Object.values(r))Array.isArray(n)&&n.forEach(a=>{a&&typeof a=="object"&&"data"in a&&t.push(a.data)});t.length===0?e.default=void 0:t.length===1?e.default=t[0]:e.default=t}_chunkMTDJ3VNBcjs.h.call(void 0, );function R(e,r){let{transform:t,setUndefinedOnEmpty:n=!0}=r;if(!(e.default===void 0||e.default===null))if(Array.isArray(e.default)){let a=e.default.map(t).filter(o=>o!==null);e.default=a.length>0?a:void 0}else{let a=t(e.default);a!==null?e.default=a:n&&(e.default=void 0)}}function ge(){return e=>{if(typeof e=="number")return e;if(typeof e=="string"){let r=Number(e.trim());return Number.isNaN(r)?null:r}return null}}function Te(){return e=>{if(typeof e=="boolean")return e;if(typeof e=="string"){let r=e.toLowerCase();if(r==="true")return!0;if(r==="false")return!1;throw new Error(`Invalid boolean string: "${e}"`)}return null}}function be(){return e=>typeof e=="string"?e.startsWith('"')&&e.endsWith('"')||e.startsWith('"')?e.slice(1,-1):e:null}function De(){return e=>{if(typeof e=="string"){let r=e.trim();return r.startsWith('"')&&r.endsWith('"')&&(r=r.slice(1,-1).trim()),r}return null}}function Ie(e){R(e,{transform:De(),setUndefinedOnEmpty:!1})}function xe(e="unknown"){return r=>{if(typeof r=="object"&&r!==null)return r;if(typeof r=="string"&&r.trim()!=="")try{let t=JSON.parse(r);return typeof t=="object"&&t!==null?t:(_chunkMTDJ3VNBcjs.i.call(void 0, ).warn(`Parsed value for input ${e} is not an object`),null)}catch(t){return _chunkMTDJ3VNBcjs.i.call(void 0, ).warn(`Failed to parse object value "${r}" for input ${e}`,t),null}return null}}function ee(e,r,t){let n=Number(e.toFixed(r));return Math.abs(e-n)<t?n:e}function Ce(e,r=1e-8){if(!Number.isFinite(e)||e===0)return .1;let t=Math.abs(e);if(t>=1){let y=String(e).split(".")[1];if(y&&y.length>0){let h=Math.min(y.length,12),g=Math.pow(10,-h),U=Number(g.toFixed(h));return Math.abs(U-g)<r?U:g}return 1}let n=String(e),a=n.toLowerCase().match(/e(-?\d+)/);if(a){let G=Number(a[1]);if(G<0||n.toLowerCase().includes("e-")){let y=Math.abs(G),h=Math.pow(10,-y),g=Number(h.toFixed(y));return Math.abs(g-h)<r?g:h}return .1}let o=12,i=t.toFixed(o).replace(/0+$/,""),u=Math.min((i.split(".")[1]||"").length,o);if(u===0)return .1;let p=Math.pow(10,-u),c=Number(p.toFixed(u));return Math.abs(c-p)<r?c:p}function re(e,r=1e-8){let t=e.paramType==="Integer";if(R(e,{transform:ge()}),t){Array.isArray(e.default)?e.default=e.default.map(o=>typeof o=="number"?Math.round(o):o):typeof e.default=="number"&&(e.default=Math.round(e.default)),e.stepSize=1;return}let n=Array.isArray(e.default)?e.default[0]:e.default,a;if(typeof n=="number"&&Number.isFinite(n)&&n!==0?a=n:typeof e.minimum=="number"&&Number.isFinite(e.minimum)&&e.minimum!==0?a=e.minimum:typeof e.maximum=="number"&&Number.isFinite(e.maximum)&&e.maximum!==0&&(a=e.maximum),a!==void 0?e.stepSize=Ce(a,r):e.stepSize=.1,typeof e.stepSize=="number"){let o=0,s=String(e.stepSize),i=s.toLowerCase().match(/e(-?\d+)/);if(i?o=Math.abs(Number(i[1])):o=_nullishCoalesce(_optionalChain([s, 'access', _7 => _7.split, 'call', _8 => _8("."), 'access', _9 => _9[1], 'optionalAccess', _10 => _10.length]), () => (0)),o===0&&typeof n=="number"&&n!==0&&Math.abs(n)<1){let u=Math.ceil(-Math.log10(Math.abs(n)));Number.isFinite(u)&&u>0&&(o=u)}o=Math.min(Math.max(o,0),12),Array.isArray(e.default)?e.default=e.default.map(u=>typeof u=="number"?ee(u,o,r):u):typeof e.default=="number"&&(e.default=ee(e.default,o,r))}}function Pe(e){try{R(e,{transform:Te(),setUndefinedOnEmpty:!1})}catch(r){throw r instanceof Error?new (0, _chunkMTDJ3VNBcjs.e)(r.message):r}}function Se(e){R(e,{transform:be(),setUndefinedOnEmpty:!1})}function te(e){R(e,{transform:xe(e.nickname||"unnamed"),setUndefinedOnEmpty:!0})}function Re(e){if(!e.values||typeof e.values!="object"||Object.keys(e.values).length===0)throw _chunkMTDJ3VNBcjs.e.missingValues(e.nickname||"unnamed","ValueList");if(e.default!==void 0&&e.default!==null){let r=String(e.default).toLowerCase();Object.keys(e.values).some(n=>n.toLowerCase()===r)||_chunkMTDJ3VNBcjs.i.call(void 0, ).warn(`ValueList input "${e.nickname||"unnamed"}" default value "${e.default}" is not in available values`)}}var ne={Number:re,Integer:re,Boolean:Pe,Text:Se,ValueList:Re,Geometry:te,File:te,Color:Ie};_chunkMTDJ3VNBcjs.l.call(void 0, );function Ne(e,r){switch(e.paramType){case"Number":case"Integer":return{...r,paramType:e.paramType,minimum:e.minimum,maximum:e.maximum,atLeast:e.atLeast,atMost:e.atMost,default:e.atMost>1?[0]:0};case"Boolean":return{...r,paramType:"Boolean",default:e.atMost>1?[!1]:!1};case"Text":return{...r,paramType:"Text",default:e.atMost>1?[""]:""};case"ValueList":return{...r,paramType:"ValueList",values:_nullishCoalesce(e.values, () => ({})),default:e.atMost>1?[e.default]:e.default};case"File":return{...r,paramType:"File",default:e.atMost>1?[null]:null};case"Color":return{...r,paramType:"Color",default:e.atMost>1?["0, 0, 0"]:"0, 0, 0"};default:return{...r,paramType:"Geometry",default:e.atMost>1?[null]:null}}}function N(e){let r={description:e.description,name:e.name,nickname:e.nickname,treeAccess:e.treeAccess,groupName:_nullishCoalesce(e.groupName, () => ("")),id:e.id};try{Q(e);let t=ne[e.paramType];if(!t)throw _chunkMTDJ3VNBcjs.e.unknownParamType(e.paramType,e.name);switch(t(e),e.paramType){case"Number":case"Integer":return{...r,paramType:e.paramType,minimum:e.minimum,maximum:e.maximum,atLeast:e.atLeast,atMost:e.atMost,stepSize:e.stepSize,default:e.default};case"Boolean":return{...r,paramType:"Boolean",default:e.default};case"Text":return{...r,paramType:"Text",default:e.default};case"ValueList":return{...r,paramType:"ValueList",values:e.values,default:e.default};case"Geometry":return{...r,paramType:e.paramType,default:e.default};case"File":return{...r,paramType:e.paramType,acceptedFormats:e.acceptedFormats,default:e.default};case"Color":return{...r,paramType:"Color",default:e.default};default:throw _chunkMTDJ3VNBcjs.e.unknownParamType(e.paramType,e.name)}}catch(t){if(t instanceof _chunkMTDJ3VNBcjs.e)return _chunkMTDJ3VNBcjs.i.call(void 0, ).error(`Validation error for input ${e.name||"unknown"}:`,t.message),Ne(e,r);throw new (0, _chunkMTDJ3VNBcjs.e)(t instanceof Error?t.message:String(t),"VALIDATION_ERROR",{context:{paramName:e.name,paramType:e.paramType},originalError:t instanceof Error?t:new Error(String(t))})}}function x(e){return e.map(r=>N(r))}async function b(e,r){let t=M(e,[]),n={};t.algo&&(n.algo=t.algo),t.pointer&&(n.pointer=t.pointer);let a=await _chunkMTDJ3VNBcjs.m.call(void 0, "io",n,r);if(!a||typeof a!="object")throw new (0, _chunkMTDJ3VNBcjs.e)("Invalid IO response structure",_chunkMTDJ3VNBcjs.d.INVALID_INPUT,{context:{response:a,definition:e}});let o=_chunkMTDJ3VNBcjs.p.call(void 0, a,{deep:!0});return{inputs:o.inputs,outputs:o.outputs}}async function P(e,r){A("fetchParsedDefinitionIO",r.suppressClientSideWarning);let{inputs:t,outputs:n}=await b(e,r);return{inputs:x(t),outputs:n}}var O=class e{constructor(r){_chunkMTDJ3VNBcjs.c.call(void 0, this,"innerTree");_chunkMTDJ3VNBcjs.c.call(void 0, this,"paramName");this.paramName=r,this.innerTree={}}append(r,t){let n=e.formatPathString(r);this.innerTree[n]||(this.innerTree[n]=[]);let a=t.map(o=>({data:e.serializeValue(o)}));return this.innerTree[n].push(...a),this}appendSingle(r,t){return this.append(r,[t])}fromDataTreeDefault(r){this.innerTree={};for(let[t,n]of Object.entries(r)){if(!Array.isArray(n))continue;let a=e.parsePathString(t);this.append(a,n)}return this}appendFlat(r){let t=Array.isArray(r)?r:[r];return this.append([0],t)}flatten(){let r=[];for(let t of Object.values(this.innerTree))if(Array.isArray(t))for(let n of t)r.push(e.deserializeValue(n.data));return r}getPaths(){return Object.keys(this.innerTree)}getPath(r){let t=e.formatPathString(r),n=this.innerTree[t];if(n)return n.map(a=>e.deserializeValue(a.data))}toComputeFormat(){return{ParamName:this.paramName,InnerTree:this.innerTree}}getInnerTree(){return this.innerTree}getParamName(){return this.paramName}static fromInputParams(r){return r.filter(t=>e.hasValidValue(t.default)).map(t=>{let n=new e(t.nickname||"unnamed"),a=t.default;if(t.treeAccess&&e.isDataTreeStructure(a))n.fromDataTreeDefault(a),e.isNumericInput(t)&&n.applyNumericConstraints(t.minimum,t.maximum,t.nickname||"unnamed");else{let o=Array.isArray(a)?a:[a],s=e.processValues(o,t);n.appendFlat(s)}return n.toComputeFormat()})}static fromInputParam(r){return e.hasValidValue(r.default)?e.fromInputParams([r])[0]:void 0}static replaceTreeValue(r,t,n){if(r.length>0&&r[0]instanceof e){let o=r,s=o.findIndex(u=>u.getParamName()===t),i=new e(t);return typeof n=="object"&&n!==null&&!Array.isArray(n)&&e.isDataTreeStructure(n)?i.fromDataTreeDefault(n):(Array.isArray(n),i.appendFlat(n)),s!==-1?o[s]=i:o.push(i),o}else{let o=r,s=o.findIndex(p=>p.ParamName===t),i=new e(t);typeof n=="object"&&n!==null&&!Array.isArray(n)&&e.isDataTreeStructure(n)?i.fromDataTreeDefault(n):(Array.isArray(n),i.appendFlat(n));let u=i.toComputeFormat();return s!==-1?o[s]=u:o.push(u),o}}static getTreeValue(r,t){if(r.length>0&&r[0]instanceof e){let o=r.find(i=>i.getParamName()===t);if(!o)return null;let s=o.flatten();return s.length===0?null:s.length===1?s[0]:s}else{let o=r.find(p=>p.ParamName===t);if(!o)return null;let s=o.InnerTree;if(!s)return null;let i=Object.keys(s)[0];if(!i)return null;let u=s[i];if(Array.isArray(u)){if(u.length===1){let p=_optionalChain([u, 'access', _11 => _11[0], 'optionalAccess', _12 => _12.data]);return p!==void 0?e.deserializeValue(p):null}return u.map(p=>_optionalChain([p, 'optionalAccess', _13 => _13.data])!==void 0?e.deserializeValue(p.data):null).filter(p=>p!==null)}return _optionalChain([u, 'optionalAccess', _14 => _14.data])!==void 0?e.deserializeValue(u.data):u}}static parsePathString(r){let t=r.match(/^\{([\d;]+)\}$/);return t?t[1].split(";").map(Number):(_chunkMTDJ3VNBcjs.i.call(void 0, ).warn(`Invalid TreeBuilder path format: ${r}, using [0]`),[0])}static formatPathString(r){return`{${r.join(";")}}`}applyNumericConstraints(r,t,n){for(let a of Object.values(this.innerTree))if(Array.isArray(a))for(let o of a){let s=e.deserializeValue(o.data);if(typeof s=="number"){let i=e.clampValue(s,r,t,n);o.data=e.serializeValue(i)}}}static serializeValue(r){return typeof r=="boolean"||typeof r=="number"||typeof r=="string"?r:typeof r=="object"&&r!==null?JSON.stringify(r):String(r)}static deserializeValue(r){if(typeof r=="boolean"||typeof r=="number"||typeof r!="string")return r;if(r.startsWith("{")||r.startsWith("["))try{return JSON.parse(r)}catch (e6){return r}return isNaN(Number(r))?r==="true"?!0:r==="false"?!1:r:Number(r)}static hasValidValue(r){return r==null?!1:typeof r=="string"?!0:!(Array.isArray(r)&&r.length===0||typeof r=="object"&&!Array.isArray(r)&&Object.keys(r).length===0)}static isDataTreeStructure(r){return typeof r!="object"||r===null||Array.isArray(r)?!1:Object.entries(r).every(([t,n])=>typeof t=="string"&&/^\{[\d;]+\}$/.test(t)&&Array.isArray(n))}static isNumericInput(r){return r.paramType==="Number"||r.paramType==="Integer"}static processValues(r,t){return r.map(n=>e.isNumericInput(t)&&typeof n=="number"?e.clampValue(n,t.minimum,t.maximum,t.nickname||"unnamed"):n).filter(n=>n!=null)}static clampValue(r,t,n,a){let o=r;return t!=null&&o<t&&(_chunkMTDJ3VNBcjs.i.call(void 0, ).warn(`${a}: ${r} below min ${t}, clamping`),o=t),n!=null&&o>n&&(_chunkMTDJ3VNBcjs.i.call(void 0, ).warn(`${a}: ${r} above max ${n}, clamping`),o=n),o}};exports.a = T; exports.b = L; exports.c = S; exports.d = I; exports.e = C; exports.f = N; exports.g = x; exports.h = b; exports.i = P; exports.j = O;
2
+ //# sourceMappingURL=chunk-5H6EJVX3.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/chunk-YBPIKW2A.cjs","../src/features/grasshopper/client/grasshopper-client.ts","../src/features/grasshopper/file-handling/handle-files.ts"],"names":["init_errors","init_base","init_logger","GrasshopperClient","_GrasshopperClient","config","__publicField","ComputeServerStats","client","RhinoComputeError","ErrorCodes","definition","fetchParsedDefinitionIO","fetchDefinitionIO","dataTree","result","solveGrasshopperDefinition","error","getLogger","extractFilesFromComputeResponse","downloadableFiles","additionalFiles","processFiles","err","downloadFileData","fileFoldername","processedFiles","createAndDownloadZip","dataItems","item","filePath"],"mappings":"AAAA,2/BAA6D,wDAAkH,iCCA/KA,CAAAA,CACAC,iCAAAA,CAAAA,CACAC,iCAAAA,CAAAA,CA8BA,IAAqBC,CAAAA,CAArB,MAAqBC,CAAkB,CAK9B,WAAA,CAAYC,CAAAA,CAAkC,CAJtDC,iCAAAA,IAAA,CAAiB,QAAA,CAAA,CACjBA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e,OAAO,IAAA,CAAS,GAAA,CACtD,MAAM,IAAIZ,wBAAAA,CACT,6HAAA,CACAC,mBAAAA,CAAW,YAAA,CACX,CACC,OAAA,CAAS,CACR,WAAA,CAAa,OAAO,MAAA,CAAW,GAAA,CAAc,eAAA,CAAkB,SAAA,CAC/D,iBAAA,CAAmB,OAAO,QAAA,CAAa,GAAA,CACvC,aAAA,CAAe,OAAO,IAAA,CAAS,GAChC,CACD,CACD,CAAA,CAGD,GAAI,CACH,IAAMgB,CAAAA,CAAiB,MAAMJ,CAAAA,CAAaF,CAAAA,CAAmBC,CAAe,CAAA,CAC5E,MAAMM,EAAAA,CAAqBD,CAAAA,CAAgBD,CAAc,CAC1D,CAAA,KAAA,CAASF,CAAAA,CAAK,CAEb,MAAIA,EAAAA,WAAed,mBAAAA,CACZc,CAAAA,CAED,IAAId,wBAAAA,CACT,gDAAA,CACAC,mBAAAA,CAAW,aAAA,CACX,CACC,OAAA,CAAS,CAAE,aAAA,CAAea,EAAAA,WAAe,KAAA,CAAQA,CAAAA,CAAI,OAAA,CAAU,MAAA,CAAOA,CAAG,CAAE,CAAA,CAC3E,aAAA,CAAeA,EAAAA,WAAe,KAAA,CAAQA,CAAAA,CAAM,KAAA,CAC7C,CACD,CACD,CACD,CAAA,CAUMD,CAAAA,CAAe,KAAA,CACpBM,CAAAA,CACAP,CAAAA,CAAAA,EAC8B,CAC9B,IAAMK,CAAAA,CAAkC,CAAC,CAAA,CA0BzC,EAAA,CAvBAE,CAAAA,CAAU,OAAA,CAASC,CAAAA,EAAS,CAC3B,IAAIC,CAAAA,CAAW,CAAA,EAAA","file":"/home/runner/work/selva-compute/selva-compute/dist/chunk-YBPIKW2A.cjs","sourcesContent":[null,"import { ErrorCodes } from '@/core/errors';\nimport { RhinoComputeError } from '@/core/errors/base';\nimport { getLogger } from '@/core/utils/logger';\nimport ComputeServerStats from '@/core/server/compute-server-stats';\nimport { ComputeConfig } from '@/core/types';\n\nimport { fetchDefinitionIO, fetchParsedDefinitionIO, solveGrasshopperDefinition } from '..';\nimport { GrasshopperComputeConfig, GrasshopperComputeResponse, DataTree } from '../types';\n\n/**\n * GrasshopperClient provides a simple API for interacting with a Rhino Compute server and grasshopper.\n *\n * @public This is the recommended high-level API for Rhino Compute operations.\n *\n * **Security Warning:**\n * Using this client in a browser environment exposes your server URL and API key to users.\n * For production, use this library server-side or proxy requests through your own backend.\n *\n * @example\n * ```typescript\n * const client = await GrasshopperClient.create({\n * serverUrl: 'http://localhost:6500',\n * apiKey: 'your-api-key'\n * });\n *\n * try {\n * const result = await client.solve(definitionUrl, { x: 1, y: 2 });\n * } finally {\n * await client.dispose(); // Clean up resources\n * }\n * ```\n */\nexport default class GrasshopperClient {\n\tprivate readonly config: GrasshopperComputeConfig;\n\tpublic readonly serverStats: ComputeServerStats;\n\tprivate disposed = false;\n\n\tprivate constructor(config: GrasshopperComputeConfig) {\n\t\tthis.config = this.normalizeComputeConfig(config);\n\t\tthis.serverStats = new ComputeServerStats(this.config.serverUrl, this.config.apiKey);\n\t}\n\n\t/**\n\t * Creates and initializes a GrasshopperClient with server validation.\n\t *\n\t * @throws {RhinoComputeError} with code NETWORK_ERROR if server is offline\n\t * @throws {RhinoComputeError} with code INVALID_CONFIG if configuration is invalid\n\t */\n\tstatic async create(config: GrasshopperComputeConfig): Promise<GrasshopperClient> {\n\t\tconst client = new GrasshopperClient(config);\n\n\t\t// Check server is online before returning\n\t\tif (!(await client.serverStats.isServerOnline())) {\n\t\t\tthrow new RhinoComputeError('Rhino Compute server is not online', ErrorCodes.NETWORK_ERROR, {\n\t\t\t\tcontext: { serverUrl: client.config.serverUrl }\n\t\t\t});\n\t\t}\n\n\t\treturn client;\n\t}\n\n\t/**\n\t * Gets the client's configuration.\n\t * Useful for passing to lower-level functions.\n\t */\n\tpublic getConfig(): GrasshopperComputeConfig {\n\t\tthis.ensureNotDisposed();\n\t\treturn { ...this.config };\n\t}\n\n\t/**\n\t * Get input/output parameters of a Grasshopper definition.\n\t */\n\tpublic async getIO(definition: string | Uint8Array) {\n\t\tthis.ensureNotDisposed();\n\t\treturn fetchParsedDefinitionIO(definition, this.config);\n\t}\n\n\tpublic async getRawIO(definition: string | Uint8Array) {\n\t\tthis.ensureNotDisposed();\n\t\treturn fetchDefinitionIO(definition, this.config);\n\t}\n\n\t/**\n\t * Run a compute job with a Grasshopper definition.\n\t *\n\t * @throws {RhinoComputeError} with code INVALID_INPUT if definition is empty\n\t * @throws {RhinoComputeError} with code NETWORK_ERROR if server is offline\n\t * @throws {RhinoComputeError} with code COMPUTATION_ERROR if computation fails\n\t */\n\tpublic async solve(\n\t\tdefinition: string | Uint8Array,\n\t\tdataTree: DataTree[]\n\t): Promise<GrasshopperComputeResponse> {\n\t\tthis.ensureNotDisposed();\n\n\t\ttry {\n\t\t\t// Validate inputs\n\t\t\tif (typeof definition === 'string' && !definition?.trim()) {\n\t\t\t\tthrow new RhinoComputeError(\n\t\t\t\t\t'Definition URL/content is required',\n\t\t\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t\t\t{\n\t\t\t\t\t\tcontext: { receivedUrl: definition }\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} else if (definition instanceof Uint8Array && definition.length === 0) {\n\t\t\t\tthrow new RhinoComputeError('Definition content is empty', ErrorCodes.INVALID_INPUT);\n\t\t\t}\n\n\t\t\t// Check server\n\t\t\tif (!(await this.serverStats.isServerOnline())) {\n\t\t\t\tthrow new RhinoComputeError(\n\t\t\t\t\t'Rhino Compute server is not online',\n\t\t\t\t\tErrorCodes.NETWORK_ERROR,\n\t\t\t\t\t{ context: { serverUrl: this.config.serverUrl } }\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Run computation\n\t\t\tconst result = await solveGrasshopperDefinition(dataTree, definition, this.config);\n\n\t\t\t// Check for errors\n\t\t\tif (result && typeof result === 'object' && 'message' in result && !('fileData' in result)) {\n\t\t\t\tthrow new RhinoComputeError(\n\t\t\t\t\t(result as { message: string }).message || 'Computation failed',\n\t\t\t\t\tErrorCodes.COMPUTATION_ERROR,\n\t\t\t\t\t{\n\t\t\t\t\t\tcontext: {\n\t\t\t\t\t\t\tdefinition:\n\t\t\t\t\t\t\t\ttypeof definition === 'string' && definition.length < 200\n\t\t\t\t\t\t\t\t\t? definition\n\t\t\t\t\t\t\t\t\t: '...content...',\n\t\t\t\t\t\t\tinputs: dataTree\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tif (this.config.debug) {\n\t\t\t\tgetLogger().error('Compute failed:', error);\n\t\t\t}\n\n\t\t\tif (error instanceof RhinoComputeError) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t\tErrorCodes.COMPUTATION_ERROR,\n\t\t\t\t{\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\tdefinition:\n\t\t\t\t\t\t\ttypeof definition === 'string' && definition.length < 200\n\t\t\t\t\t\t\t\t? definition\n\t\t\t\t\t\t\t\t: '...content...',\n\t\t\t\t\t\tinputs: dataTree\n\t\t\t\t\t},\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}\n\n\t/**\n\t * Disposes of client resources.\n\t * Call this when you're done using the client.\n\t */\n\tpublic async dispose(): Promise<void> {\n\t\tif (this.disposed) return;\n\n\t\tthis.disposed = true;\n\n\t\t// If serverStats has a dispose method, call it\n\t\tif ('dispose' in this.serverStats && typeof this.serverStats.dispose === 'function') {\n\t\t\tawait this.serverStats.dispose();\n\t\t}\n\n\t\t// Clear any cached data or connections if needed\n\t}\n\n\t/**\n\t * Ensures the client 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'GrasshopperClient has been disposed and cannot be used',\n\t\t\t\tErrorCodes.INVALID_STATE\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Validates and normalizes a compute configuration.\n\t *\n\t * @throws {RhinoComputeError} with code INVALID_CONFIG if configuration is invalid\n\t */\n\tprivate normalizeComputeConfig<T extends ComputeConfig | GrasshopperComputeConfig>(config: T): T {\n\t\tif (!config.serverUrl?.trim()) {\n\t\t\tthrow new RhinoComputeError('serverUrl is required', ErrorCodes.INVALID_CONFIG, {\n\t\t\t\tcontext: { receivedServerUrl: config.serverUrl }\n\t\t\t});\n\t\t}\n\n\t\t// Validate URL format\n\t\ttry {\n\t\t\tnew URL(config.serverUrl);\n\t\t} catch {\n\t\t\tthrow new RhinoComputeError('serverUrl must be a valid URL', ErrorCodes.INVALID_CONFIG, {\n\t\t\t\tcontext: { receivedServerUrl: config.serverUrl }\n\t\t\t});\n\t\t}\n\n\t\t// Validate that it's not the default public endpoint\n\t\tif (config.serverUrl === '' || config.serverUrl === 'https://compute.rhino3d.com/') {\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t'serverUrl must be set to your Compute server URL. The default public endpoint is not allowed.',\n\t\t\t\tErrorCodes.INVALID_CONFIG,\n\t\t\t\t{ context: { receivedServerUrl: config.serverUrl } }\n\t\t\t);\n\t\t}\n\n\t\treturn {\n\t\t\t...config,\n\t\t\tserverUrl: config.serverUrl.replace(/\\/+$/, ''), // Remove trailing slashes\n\t\t\tapiKey: config.apiKey,\n\t\t\tauthToken: config.authToken,\n\t\t\tdebug: config.debug ?? false,\n\t\t\tsuppressClientSideWarning: config.suppressClientSideWarning\n\t\t} as T;\n\t}\n}\n","import { RhinoComputeError, ErrorCodes, getLogger } from '@/core';\nimport { decodeBase64ToBinary } from '@/core/utils/encoding';\n\nimport { FileBaseInfo, FileData, ProcessedFile } from './types';\n\n/**\n * Extracts and processes files from compute response data without downloading them.\n * Returns an array of ProcessedFile objects that can be used programmatically.\n *\n * @param downloadableFiles - An array of FileData items from the compute response.\n * @param additionalFiles - Optional additional files to include (fetched from URLs).\n * @returns A Promise resolving to an array of ProcessedFile objects.\n * @throws Will throw an error if file processing fails.\n *\n * @example\n * const files = await extractFilesFromComputeResponse(fileData);\n * files.forEach(file => {\n * console.log(`File: ${file.fileName}, Size: ${file.content.length}`);\n * });\n */\nexport const extractFilesFromComputeResponse = async (\n\tdownloadableFiles: FileData[],\n\tadditionalFiles: FileBaseInfo[] | FileBaseInfo | null = null\n): Promise<ProcessedFile[]> => {\n\ttry {\n\t\treturn await processFiles(downloadableFiles, additionalFiles);\n\t} catch (err) {\n\t\tthrow new RhinoComputeError(\n\t\t\t'Failed to extract files from compute response',\n\t\t\tErrorCodes.INVALID_STATE,\n\t\t\t{\n\t\t\t\tcontext: { originalError: err instanceof Error ? err.message : String(err) },\n\t\t\t\toriginalError: err instanceof Error ? err : undefined\n\t\t\t}\n\t\t);\n\t}\n};\n\n/**\n * Downloads files from a compute response as a ZIP archive.\n * Packages multiple files into a single ZIP file and triggers a browser download.\n *\n * @param downloadableFiles - An array of FileData items from the compute response.\n * @param additionalFiles - Optional additional files to include in the ZIP (fetched from URLs).\n * @param fileFoldername - The name of the ZIP file (without extension).\n * @throws Will throw an error if the file handling or download fails.\n *\n * @example\n * await downloadDataFromComputeResponse(fileData, null, 'my-export');\n * // Downloads 'my-export.zip'\n */\nexport const downloadFileData = async (\n\tdownloadableFiles: FileData[],\n\tfileFoldername: string,\n\tadditionalFiles: FileBaseInfo[] | FileBaseInfo | null = null\n): Promise<void> => {\n\t// Check if we're in a browser environment\n\tif (typeof document === 'undefined' || typeof Blob === 'undefined') {\n\t\tthrow new RhinoComputeError(\n\t\t\t'File download functionality is only available in browser environments. This function requires the DOM API (document, Blob).',\n\t\t\tErrorCodes.BROWSER_ONLY,\n\t\t\t{\n\t\t\t\tcontext: {\n\t\t\t\t\tenvironment: typeof window !== 'undefined' ? 'browser (SSR)' : 'Node.js',\n\t\t\t\t\tdocumentAvailable: typeof document !== 'undefined',\n\t\t\t\t\tblobAvailable: typeof Blob !== 'undefined'\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\ttry {\n\t\tconst processedFiles = await processFiles(downloadableFiles, additionalFiles);\n\t\tawait createAndDownloadZip(processedFiles, fileFoldername);\n\t} catch (err) {\n\t\t// Re-throw if it's already a RhinoComputeError\n\t\tif (err instanceof RhinoComputeError) {\n\t\t\tthrow err;\n\t\t}\n\t\tthrow new RhinoComputeError(\n\t\t\t'Failed to download files from compute response',\n\t\t\tErrorCodes.INVALID_STATE,\n\t\t\t{\n\t\t\t\tcontext: { originalError: err instanceof Error ? err.message : String(err) },\n\t\t\t\toriginalError: err instanceof Error ? err : undefined\n\t\t\t}\n\t\t);\n\t}\n};\n\n/**\n * Processes files from compute response data and additional files.\n * Converts base64-encoded data to binary and fetches additional files from URLs.\n *\n * @param dataItems - An array of FileData items to process.\n * @param additionalFiles - Optional additional files to fetch and include.\n * @returns A Promise resolving to an array of ProcessedFile objects.\n */\nconst processFiles = async (\n\tdataItems: FileData[],\n\tadditionalFiles: FileBaseInfo[] | FileBaseInfo | null\n): Promise<ProcessedFile[]> => {\n\tconst processedFiles: ProcessedFile[] = [];\n\n\t// Process compute response files\n\tdataItems.forEach((item) => {\n\t\tlet filePath = `${item.fileName}${item.fileType}`;\n\n\t\tif (item.subFolder && item.subFolder.trim() !== '') {\n\t\t\tfilePath = `${item.subFolder}/${filePath}`;\n\t\t}\n\n\t\tif (item.isBase64Encoded === true && item.data) {\n\t\t\tconst bites = decodeBase64ToBinary(item.data);\n\t\t\tprocessedFiles.push({\n\t\t\t\tfileName: `${item.fileName}${item.fileType}`,\n\t\t\t\tcontent: new Uint8Array(bites.buffer),\n\t\t\t\tpath: filePath\n\t\t\t});\n\t\t} else if (item.isBase64Encoded === false && item.data) {\n\t\t\tprocessedFiles.push({\n\t\t\t\tfileName: `${item.fileName}${item.fileType}`,\n\t\t\t\tcontent: item.data,\n\t\t\t\tpath: filePath\n\t\t\t});\n\t\t}\n\t});\n\n\tif (additionalFiles) {\n\t\tconst filesArray = Array.isArray(additionalFiles) ? additionalFiles : [additionalFiles];\n\t\tconst additionalProcessed = await Promise.all(\n\t\t\tfilesArray.map(async (file) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst response = await fetch(file.filePath);\n\t\t\t\t\tif (!response.ok) {\n\t\t\t\t\t\tgetLogger().warn(`Failed to fetch additional file from URL: ${file.filePath}`);\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tconst fileBlob = await response.blob();\n\t\t\t\t\tconst arrayBuffer = await fileBlob.arrayBuffer();\n\t\t\t\t\treturn {\n\t\t\t\t\t\tfileName: file.fileName,\n\t\t\t\t\t\tcontent: new Uint8Array(arrayBuffer),\n\t\t\t\t\t\tpath: file.fileName\n\t\t\t\t\t} as ProcessedFile;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tgetLogger().error(`Error fetching additional file from URL: ${file.filePath}`, error);\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t})\n\t\t);\n\n\t\tprocessedFiles.push(...additionalProcessed.filter((f): f is ProcessedFile => f !== null));\n\t}\n\n\treturn processedFiles;\n};\n\n/**\n * Creates a ZIP archive from processed files and triggers a browser download.\n *\n * @param files - An array of ProcessedFile objects to include in the ZIP.\n * @param zipName - The name of the ZIP file (without extension).\n * @returns A Promise that resolves when the ZIP is generated and download is triggered.\n */\nasync function createAndDownloadZip(files: ProcessedFile[], zipName: string): Promise<void> {\n\tconst { zipSync, strToU8 } = await import('fflate');\n\n\t// Convert files to fflate format\n\tconst zipData: Record<string, Uint8Array> = {};\n\tfiles.forEach((file) => {\n\t\tzipData[file.path] = typeof file.content === 'string' ? strToU8(file.content) : file.content;\n\t});\n\n\tconst zipped = zipSync(zipData, { level: 6 });\n\n\tconst blob = new Blob([zipped as BlobPart], { type: 'application/zip' });\n\tsaveFile(blob, `${zipName}.zip`);\n}\n\n/**\n * Saves a Blob object as a file in the user's browser.\n *\n * @param blob - The Blob object representing the file content.\n * @param filename - The name to give the downloaded file (including extension).\n * @throws {RhinoComputeError} If not running in a browser environment.\n */\nfunction saveFile(blob: Blob, filename: string) {\n\tif (typeof document === 'undefined') {\n\t\tthrow new RhinoComputeError(\n\t\t\t'saveFile requires a browser environment with DOM API access.',\n\t\t\tErrorCodes.BROWSER_ONLY,\n\t\t\t{\n\t\t\t\tcontext: { function: 'saveFile', requiredAPI: 'document' }\n\t\t\t}\n\t\t);\n\t}\n\n\tconst a = document.createElement('a');\n\ta.href = URL.createObjectURL(blob);\n\ta.download = filename;\n\ta.click();\n\tURL.revokeObjectURL(a.href);\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/chunk-5H6EJVX3.cjs","../src/features/grasshopper/client/grasshopper-client.ts","../src/features/grasshopper/file-handling/handle-files.ts"],"names":["init_errors","init_base","init_logger","GrasshopperClient","_GrasshopperClient","config","__publicField","ComputeServerStats","client","RhinoComputeError","ErrorCodes","definition","fetchParsedDefinitionIO","fetchDefinitionIO","dataTree","result","solveGrasshopperDefinition","error","getLogger","extractFilesFromComputeResponse","downloadableFiles","additionalFiles","processFiles","err","downloadFileData","fileFoldername","processedFiles","createAndDownloadZip","dataItems","item","filePath"],"mappings":"AAAA,2/BAA6D,wDAAyH,iCCAtLA,CAAAA,CACAC,iCAAAA,CAAAA,CACAC,iCAAAA,CAAAA,CA8BA,IAAqBC,CAAAA,CAArB,MAAqBC,CAAkB,CAK9B,WAAA,CAAYC,CAAAA,CAAkC,CAJtDC,iCAAAA,IAAA,CAAiB,QAAA,CAAA,CACjBA,iCAAAA,IAAA,CAAgB,aAAA,CAAA,CAChBA,iCAAAA,IAAA,CAAQ,UAAA,CAAW,CAAA,CAAA,CAAA,CAGlB,IAAA,CAAK,MAAA,CAAS,IAAA,CAAK,sBAAA,CAAuBD,CAAM,CAAA,CAChD,IAAA,CAAK,WAAA,CAAc,IAAIE,wBAAAA,CAAmB,IAAA,CAAK,MAAA,CAAO,SAAA,CAAW,IAAA,CAAK,MAAA,CAAO,MA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AAA,CAGD,GAAI,CACH,IAAMgB,CAAAA,CAAiB,MAAMJ,CAAAA,CAAaF,CAAAA,CAAmBC,CAAe,CAAA,CAC5E,MAAMM,EAAAA,CAAqBD,CAAAA,CAAgBD,CAAc,CAC1D,CAAA,KAAA,CAASF,CAAAA,CAAK,CAEb,MAAIA,EAAAA,WAAed,mBAAAA,CACZc,CAAAA,CAED,IAAId,wBAAAA,CACT,gDAAA,CACAC,mBAAAA,CAAW,aAAA,CACX,CACC,OAAA,CAAS,CAAE,aAAA,CAAea,EAAAA,WAAe,KAAA,CAAQA,CAAAA,CAAI,OAAA,CAAU,MAAA,CAAOA,CAAG,CAAE,CAAA,CAC3E,aAAA,CAAeA,EAAAA,WAAe,KAAA,CAAQA,CAAAA,CAAM,KAAA,CAC7C,CACD,CACD,CACD,CAAA,CAUMD,CAAAA,CAAe,KAAA,CACpBM,CAAAA,CACAP,CAAAA,CAAAA,EAC8B,CAC9B,IAAMK,CAAAA,CAAkC,CAAC,CAAA,CA0BzC,EAAA,CAvBAE,CAAAA,CAAU,OAAA,CAASC,CAAAA,EAAS,CAC3B,IAAIC,CAAAA,CAAW,CAAA,EAAA","file":"/home/runner/work/selva-compute/selva-compute/dist/chunk-5H6EJVX3.cjs","sourcesContent":[null,"import { ErrorCodes } from '@/core/errors';\nimport { RhinoComputeError } from '@/core/errors/base';\nimport { getLogger } from '@/core/utils/logger';\nimport ComputeServerStats from '@/core/server/compute-server-stats';\nimport { ComputeConfig } from '@/core/types';\n\nimport { fetchDefinitionIO, fetchParsedDefinitionIO, solveGrasshopperDefinition } from '..';\nimport { GrasshopperComputeConfig, GrasshopperComputeResponse, DataTree } from '../types';\n\n/**\n * GrasshopperClient provides a simple API for interacting with a Rhino Compute server and grasshopper.\n *\n * @public This is the recommended high-level API for Rhino Compute operations.\n *\n * **Security Warning:**\n * Using this client in a browser environment exposes your server URL and API key to users.\n * For production, use this library server-side or proxy requests through your own backend.\n *\n * @example\n * ```typescript\n * const client = await GrasshopperClient.create({\n * serverUrl: 'http://localhost:6500',\n * apiKey: 'your-api-key'\n * });\n *\n * try {\n * const result = await client.solve(definitionUrl, { x: 1, y: 2 });\n * } finally {\n * await client.dispose(); // Clean up resources\n * }\n * ```\n */\nexport default class GrasshopperClient {\n\tprivate readonly config: GrasshopperComputeConfig;\n\tpublic readonly serverStats: ComputeServerStats;\n\tprivate disposed = false;\n\n\tprivate constructor(config: GrasshopperComputeConfig) {\n\t\tthis.config = this.normalizeComputeConfig(config);\n\t\tthis.serverStats = new ComputeServerStats(this.config.serverUrl, this.config.apiKey);\n\t}\n\n\t/**\n\t * Creates and initializes a GrasshopperClient with server validation.\n\t *\n\t * @throws {RhinoComputeError} with code NETWORK_ERROR if server is offline\n\t * @throws {RhinoComputeError} with code INVALID_CONFIG if configuration is invalid\n\t */\n\tstatic async create(config: GrasshopperComputeConfig): Promise<GrasshopperClient> {\n\t\tconst client = new GrasshopperClient(config);\n\n\t\t// Check server is online before returning\n\t\tif (!(await client.serverStats.isServerOnline())) {\n\t\t\tthrow new RhinoComputeError('Rhino Compute server is not online', ErrorCodes.NETWORK_ERROR, {\n\t\t\t\tcontext: { serverUrl: client.config.serverUrl }\n\t\t\t});\n\t\t}\n\n\t\treturn client;\n\t}\n\n\t/**\n\t * Gets the client's configuration.\n\t * Useful for passing to lower-level functions.\n\t */\n\tpublic getConfig(): GrasshopperComputeConfig {\n\t\tthis.ensureNotDisposed();\n\t\treturn { ...this.config };\n\t}\n\n\t/**\n\t * Get input/output parameters of a Grasshopper definition.\n\t */\n\tpublic async getIO(definition: string | Uint8Array) {\n\t\tthis.ensureNotDisposed();\n\t\treturn fetchParsedDefinitionIO(definition, this.config);\n\t}\n\n\tpublic async getRawIO(definition: string | Uint8Array) {\n\t\tthis.ensureNotDisposed();\n\t\treturn fetchDefinitionIO(definition, this.config);\n\t}\n\n\t/**\n\t * Run a compute job with a Grasshopper definition.\n\t *\n\t * @throws {RhinoComputeError} with code INVALID_INPUT if definition is empty\n\t * @throws {RhinoComputeError} with code NETWORK_ERROR if server is offline\n\t * @throws {RhinoComputeError} with code COMPUTATION_ERROR if computation fails\n\t */\n\tpublic async solve(\n\t\tdefinition: string | Uint8Array,\n\t\tdataTree: DataTree[]\n\t): Promise<GrasshopperComputeResponse> {\n\t\tthis.ensureNotDisposed();\n\n\t\ttry {\n\t\t\t// Validate inputs\n\t\t\tif (typeof definition === 'string' && !definition?.trim()) {\n\t\t\t\tthrow new RhinoComputeError(\n\t\t\t\t\t'Definition URL/content is required',\n\t\t\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t\t\t{\n\t\t\t\t\t\tcontext: { receivedUrl: definition }\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} else if (definition instanceof Uint8Array && definition.length === 0) {\n\t\t\t\tthrow new RhinoComputeError('Definition content is empty', ErrorCodes.INVALID_INPUT);\n\t\t\t}\n\n\t\t\t// Check server\n\t\t\tif (!(await this.serverStats.isServerOnline())) {\n\t\t\t\tthrow new RhinoComputeError(\n\t\t\t\t\t'Rhino Compute server is not online',\n\t\t\t\t\tErrorCodes.NETWORK_ERROR,\n\t\t\t\t\t{ context: { serverUrl: this.config.serverUrl } }\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Run computation\n\t\t\tconst result = await solveGrasshopperDefinition(dataTree, definition, this.config);\n\n\t\t\t// Check for errors\n\t\t\tif (result && typeof result === 'object' && 'message' in result && !('fileData' in result)) {\n\t\t\t\tthrow new RhinoComputeError(\n\t\t\t\t\t(result as { message: string }).message || 'Computation failed',\n\t\t\t\t\tErrorCodes.COMPUTATION_ERROR,\n\t\t\t\t\t{\n\t\t\t\t\t\tcontext: {\n\t\t\t\t\t\t\tdefinition:\n\t\t\t\t\t\t\t\ttypeof definition === 'string' && definition.length < 200\n\t\t\t\t\t\t\t\t\t? definition\n\t\t\t\t\t\t\t\t\t: '...content...',\n\t\t\t\t\t\t\tinputs: dataTree\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tif (this.config.debug) {\n\t\t\t\tgetLogger().error('Compute failed:', error);\n\t\t\t}\n\n\t\t\tif (error instanceof RhinoComputeError) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t\tErrorCodes.COMPUTATION_ERROR,\n\t\t\t\t{\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\tdefinition:\n\t\t\t\t\t\t\ttypeof definition === 'string' && definition.length < 200\n\t\t\t\t\t\t\t\t? definition\n\t\t\t\t\t\t\t\t: '...content...',\n\t\t\t\t\t\tinputs: dataTree\n\t\t\t\t\t},\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}\n\n\t/**\n\t * Disposes of client resources.\n\t * Call this when you're done using the client.\n\t */\n\tpublic async dispose(): Promise<void> {\n\t\tif (this.disposed) return;\n\n\t\tthis.disposed = true;\n\n\t\t// If serverStats has a dispose method, call it\n\t\tif ('dispose' in this.serverStats && typeof this.serverStats.dispose === 'function') {\n\t\t\tawait this.serverStats.dispose();\n\t\t}\n\n\t\t// Clear any cached data or connections if needed\n\t}\n\n\t/**\n\t * Ensures the client 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'GrasshopperClient has been disposed and cannot be used',\n\t\t\t\tErrorCodes.INVALID_STATE\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Validates and normalizes a compute configuration.\n\t *\n\t * @throws {RhinoComputeError} with code INVALID_CONFIG if configuration is invalid\n\t */\n\tprivate normalizeComputeConfig<T extends ComputeConfig | GrasshopperComputeConfig>(config: T): T {\n\t\tif (!config.serverUrl?.trim()) {\n\t\t\tthrow new RhinoComputeError('serverUrl is required', ErrorCodes.INVALID_CONFIG, {\n\t\t\t\tcontext: { receivedServerUrl: config.serverUrl }\n\t\t\t});\n\t\t}\n\n\t\t// Validate URL format\n\t\ttry {\n\t\t\tnew URL(config.serverUrl);\n\t\t} catch {\n\t\t\tthrow new RhinoComputeError('serverUrl must be a valid URL', ErrorCodes.INVALID_CONFIG, {\n\t\t\t\tcontext: { receivedServerUrl: config.serverUrl }\n\t\t\t});\n\t\t}\n\n\t\t// Validate that it's not the default public endpoint\n\t\tif (config.serverUrl === '' || config.serverUrl === 'https://compute.rhino3d.com/') {\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t'serverUrl must be set to your Compute server URL. The default public endpoint is not allowed.',\n\t\t\t\tErrorCodes.INVALID_CONFIG,\n\t\t\t\t{ context: { receivedServerUrl: config.serverUrl } }\n\t\t\t);\n\t\t}\n\n\t\treturn {\n\t\t\t...config,\n\t\t\tserverUrl: config.serverUrl.replace(/\\/+$/, ''), // Remove trailing slashes\n\t\t\tapiKey: config.apiKey,\n\t\t\tauthToken: config.authToken,\n\t\t\tdebug: config.debug ?? false,\n\t\t\tsuppressClientSideWarning: config.suppressClientSideWarning\n\t\t} as T;\n\t}\n}\n","import { RhinoComputeError, ErrorCodes, getLogger } from '@/core';\nimport { decodeBase64ToBinary } from '@/core/utils/encoding';\n\nimport { FileBaseInfo, FileData, ProcessedFile } from './types';\n\n/**\n * Extracts and processes files from compute response data without downloading them.\n * Returns an array of ProcessedFile objects that can be used programmatically.\n *\n * @param downloadableFiles - An array of FileData items from the compute response.\n * @param additionalFiles - Optional additional files to include (fetched from URLs).\n * @returns A Promise resolving to an array of ProcessedFile objects.\n * @throws Will throw an error if file processing fails.\n *\n * @example\n * const files = await extractFilesFromComputeResponse(fileData);\n * files.forEach(file => {\n * console.log(`File: ${file.fileName}, Size: ${file.content.length}`);\n * });\n */\nexport const extractFilesFromComputeResponse = async (\n\tdownloadableFiles: FileData[],\n\tadditionalFiles: FileBaseInfo[] | FileBaseInfo | null = null\n): Promise<ProcessedFile[]> => {\n\ttry {\n\t\treturn await processFiles(downloadableFiles, additionalFiles);\n\t} catch (err) {\n\t\tthrow new RhinoComputeError(\n\t\t\t'Failed to extract files from compute response',\n\t\t\tErrorCodes.INVALID_STATE,\n\t\t\t{\n\t\t\t\tcontext: { originalError: err instanceof Error ? err.message : String(err) },\n\t\t\t\toriginalError: err instanceof Error ? err : undefined\n\t\t\t}\n\t\t);\n\t}\n};\n\n/**\n * Downloads files from a compute response as a ZIP archive.\n * Packages multiple files into a single ZIP file and triggers a browser download.\n *\n * @param downloadableFiles - An array of FileData items from the compute response.\n * @param additionalFiles - Optional additional files to include in the ZIP (fetched from URLs).\n * @param fileFoldername - The name of the ZIP file (without extension).\n * @throws Will throw an error if the file handling or download fails.\n *\n * @example\n * await downloadDataFromComputeResponse(fileData, null, 'my-export');\n * // Downloads 'my-export.zip'\n */\nexport const downloadFileData = async (\n\tdownloadableFiles: FileData[],\n\tfileFoldername: string,\n\tadditionalFiles: FileBaseInfo[] | FileBaseInfo | null = null\n): Promise<void> => {\n\t// Check if we're in a browser environment\n\tif (typeof document === 'undefined' || typeof Blob === 'undefined') {\n\t\tthrow new RhinoComputeError(\n\t\t\t'File download functionality is only available in browser environments. This function requires the DOM API (document, Blob).',\n\t\t\tErrorCodes.BROWSER_ONLY,\n\t\t\t{\n\t\t\t\tcontext: {\n\t\t\t\t\tenvironment: typeof window !== 'undefined' ? 'browser (SSR)' : 'Node.js',\n\t\t\t\t\tdocumentAvailable: typeof document !== 'undefined',\n\t\t\t\t\tblobAvailable: typeof Blob !== 'undefined'\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\ttry {\n\t\tconst processedFiles = await processFiles(downloadableFiles, additionalFiles);\n\t\tawait createAndDownloadZip(processedFiles, fileFoldername);\n\t} catch (err) {\n\t\t// Re-throw if it's already a RhinoComputeError\n\t\tif (err instanceof RhinoComputeError) {\n\t\t\tthrow err;\n\t\t}\n\t\tthrow new RhinoComputeError(\n\t\t\t'Failed to download files from compute response',\n\t\t\tErrorCodes.INVALID_STATE,\n\t\t\t{\n\t\t\t\tcontext: { originalError: err instanceof Error ? err.message : String(err) },\n\t\t\t\toriginalError: err instanceof Error ? err : undefined\n\t\t\t}\n\t\t);\n\t}\n};\n\n/**\n * Processes files from compute response data and additional files.\n * Converts base64-encoded data to binary and fetches additional files from URLs.\n *\n * @param dataItems - An array of FileData items to process.\n * @param additionalFiles - Optional additional files to fetch and include.\n * @returns A Promise resolving to an array of ProcessedFile objects.\n */\nconst processFiles = async (\n\tdataItems: FileData[],\n\tadditionalFiles: FileBaseInfo[] | FileBaseInfo | null\n): Promise<ProcessedFile[]> => {\n\tconst processedFiles: ProcessedFile[] = [];\n\n\t// Process compute response files\n\tdataItems.forEach((item) => {\n\t\tlet filePath = `${item.fileName}${item.fileType}`;\n\n\t\tif (item.subFolder && item.subFolder.trim() !== '') {\n\t\t\tfilePath = `${item.subFolder}/${filePath}`;\n\t\t}\n\n\t\tif (item.isBase64Encoded === true && item.data) {\n\t\t\tconst bites = decodeBase64ToBinary(item.data);\n\t\t\tprocessedFiles.push({\n\t\t\t\tfileName: `${item.fileName}${item.fileType}`,\n\t\t\t\tcontent: new Uint8Array(bites.buffer),\n\t\t\t\tpath: filePath\n\t\t\t});\n\t\t} else if (item.isBase64Encoded === false && item.data) {\n\t\t\tprocessedFiles.push({\n\t\t\t\tfileName: `${item.fileName}${item.fileType}`,\n\t\t\t\tcontent: item.data,\n\t\t\t\tpath: filePath\n\t\t\t});\n\t\t}\n\t});\n\n\tif (additionalFiles) {\n\t\tconst filesArray = Array.isArray(additionalFiles) ? additionalFiles : [additionalFiles];\n\t\tconst additionalProcessed = await Promise.all(\n\t\t\tfilesArray.map(async (file) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst response = await fetch(file.filePath);\n\t\t\t\t\tif (!response.ok) {\n\t\t\t\t\t\tgetLogger().warn(`Failed to fetch additional file from URL: ${file.filePath}`);\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tconst fileBlob = await response.blob();\n\t\t\t\t\tconst arrayBuffer = await fileBlob.arrayBuffer();\n\t\t\t\t\treturn {\n\t\t\t\t\t\tfileName: file.fileName,\n\t\t\t\t\t\tcontent: new Uint8Array(arrayBuffer),\n\t\t\t\t\t\tpath: file.fileName\n\t\t\t\t\t} as ProcessedFile;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tgetLogger().error(`Error fetching additional file from URL: ${file.filePath}`, error);\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t})\n\t\t);\n\n\t\tprocessedFiles.push(...additionalProcessed.filter((f): f is ProcessedFile => f !== null));\n\t}\n\n\treturn processedFiles;\n};\n\n/**\n * Creates a ZIP archive from processed files and triggers a browser download.\n *\n * @param files - An array of ProcessedFile objects to include in the ZIP.\n * @param zipName - The name of the ZIP file (without extension).\n * @returns A Promise that resolves when the ZIP is generated and download is triggered.\n */\nasync function createAndDownloadZip(files: ProcessedFile[], zipName: string): Promise<void> {\n\tconst { zipSync, strToU8 } = await import('fflate');\n\n\t// Convert files to fflate format\n\tconst zipData: Record<string, Uint8Array> = {};\n\tfiles.forEach((file) => {\n\t\tzipData[file.path] = typeof file.content === 'string' ? strToU8(file.content) : file.content;\n\t});\n\n\tconst zipped = zipSync(zipData, { level: 6 });\n\n\tconst blob = new Blob([zipped as BlobPart], { type: 'application/zip' });\n\tsaveFile(blob, `${zipName}.zip`);\n}\n\n/**\n * Saves a Blob object as a file in the user's browser.\n *\n * @param blob - The Blob object representing the file content.\n * @param filename - The name to give the downloaded file (including extension).\n * @throws {RhinoComputeError} If not running in a browser environment.\n */\nfunction saveFile(blob: Blob, filename: string) {\n\tif (typeof document === 'undefined') {\n\t\tthrow new RhinoComputeError(\n\t\t\t'saveFile requires a browser environment with DOM API access.',\n\t\t\tErrorCodes.BROWSER_ONLY,\n\t\t\t{\n\t\t\t\tcontext: { function: 'saveFile', requiredAPI: 'document' }\n\t\t\t}\n\t\t);\n\t}\n\n\tconst a = document.createElement('a');\n\ta.href = URL.createObjectURL(blob);\n\ta.download = filename;\n\ta.click();\n\tURL.revokeObjectURL(a.href);\n}\n"]}
@@ -0,0 +1,3 @@
1
+ var f=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var A=(t,e,r)=>e in t?f(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var E=(t,e)=>()=>(t&&(e=t(t=0)),e);var L=(t,e)=>{for(var r in e)f(t,r,{get:e[r],enumerable:!0})},k=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of b(e))!_.call(t,n)&&n!==r&&f(t,n,{get:()=>e[n],enumerable:!(o=$(e,n))||o.enumerable});return t};var G=t=>k(f({},"__esModule",{value:!0}),t);var R=(t,e,r)=>A(t,typeof e!="symbol"?e+"":e,r);var i,v=E(()=>{"use strict";i={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 c,C=E(()=>{"use strict";v();c=class t extends Error{constructor(r,o="UNKNOWN_ERROR",n){super(r);R(this,"code");R(this,"statusCode");R(this,"context");R(this,"originalError");this.name="RhinoComputeError",this.code=o,this.statusCode=n?.statusCode,this.context=n?.context,this.originalError=n?.originalError,"cause"in Error.prototype&&Object.defineProperty(this,"cause",{value:n?.originalError,enumerable:!0})}static validation(r,o,n){return new t(`Input "${r}": ${o}`,i.VALIDATION_ERROR,{context:{inputName:r,reason:o,...n}})}static missingValues(r,o,n){return new t(`Input "${r}" has no values defined${o?` (expected ${o})`:""}`,i.INVALID_INPUT,{context:{inputName:r,expectedType:o,...n}})}static invalidDefault(r,o,n,a){return new t(`ValueList input "${r}" default value "${o}" is not in available values`,i.VALIDATION_ERROR,{context:{inputName:r,defaultValue:o,availableValues:n,...a}})}static unknownParamType(r,o,n){return new t(`Unknown paramType: ${r}`,i.VALIDATION_ERROR,{context:{receivedParamType:r,paramName:o,...n}})}static invalidStructure(r,o,n){return new t(`Invalid input structure for "${r}" (expected ${o})`,i.INVALID_INPUT,{context:{inputName:r,expectedStructure:o,...n}})}}});var U={};L(U,{ErrorCodes:()=>i,RhinoComputeError:()=>c});var N=E(()=>{"use strict";C();v()});function d(){return O}function S(t){t===null?O=new w:"debug"in t&&"info"in t&&"warn"in t&&"error"in t?O=t:O=new y}function M(){S(new y)}var w,y,O,T=E(()=>{"use strict";w=class{debug(){}info(){}warn(){}error(){}},y=class{debug(e,...r){console.debug(e,...r)}info(e,...r){console.info(e,...r)}warn(e,...r){console.warn(e,...r)}error(e,...r){console.error(e,...r)}},O=new w});N();T();function D(t,e,r,o,n,a){let{status:u,statusText:l}=t,p={url:e,requestId:r,method:"POST",requestSize:o,serverUrl:n},m={401:{message:`HTTP ${u}: ${l}`,code:i.AUTH_ERROR},403:{message:`HTTP ${u}: ${l}`,code:i.AUTH_ERROR},404:{message:`Endpoint not found: ${e}`,code:i.NETWORK_ERROR},413:{message:`Request too large: ${(o/1024).toFixed(2)}KB`,code:i.VALIDATION_ERROR},429:{message:"Rate limit exceeded",code:i.NETWORK_ERROR},500:{message:`Server error: ${a||l}`,code:i.COMPUTATION_ERROR},502:{message:`Service unavailable: ${l}`,code:i.NETWORK_ERROR},503:{message:`Service unavailable: ${l}`,code:i.NETWORK_ERROR},504:{message:`Service unavailable: ${l}`,code:i.NETWORK_ERROR}}[u]||{message:`HTTP ${u}: ${l}`,code:i.UNKNOWN_ERROR};throw new c(m.message,m.code,{statusCode:u,context:p})}function K(t,e){let r=e.replace(/\/+$/,""),o=t.replace(/^\/+/,"");return`${r}/${o}`}function P(t){try{let e=new URL(t).host;return/^(localhost|127\.0\.0\.1|::1)(:\d+)?$/i.test(e)}catch{return/(localhost|127\.0\.0\.1)/i.test(t)}}function V(t,e){let r={"X-Request-ID":t,"Content-Type":"application/json",...e.authToken&&{Authorization:e.authToken},...e.apiKey&&{RhinoComputeKey:e.apiKey}};return!e.apiKey&&!P(e.serverUrl)&&d().warn(`\u26A0\uFE0F [Rhino Compute] Request [${t}] targets remote server (${e.serverUrl}) but no API key is configured. Requests may fail or be rate-limited.`),r}function H(){return`${Date.now()}-${Math.random().toString(36).substring(2,11)}`}function g(t,e){e&&d().debug(t)}async function W(t,e,r,o,n,a,u){let l=Math.round(performance.now()-a);if(!t.ok){let p=await t.text();if(u&&(g(`\u274C Request [${r}] failed with HTTP ${t.status} in ${l}ms`,!0),g(` URL: ${e}`,!0),g(` Status: ${t.status} ${t.statusText}`,!0),p&&g(` Response body: ${p.substring(0,500)}${p.length>500?"...":""}`,!0)),t.status===500)try{let s=JSON.parse(p);if(s?.values&&(s.errors||s.warnings))return u&&(g(`\u26A0\uFE0F Request [${r}] completed with Grasshopper errors in ${l}ms`,!0),s.errors?.length>0&&g(` Errors: ${JSON.stringify(s.errors,null,2)}`,!0),s.warnings?.length>0&&g(` Warnings: ${JSON.stringify(s.warnings,null,2)}`,!0)),s;s?.Message?p=`${s.ExceptionType?s.ExceptionType+": ":""}${s.Message}
2
+ ${s.StackTrace||""}`:s?.error&&(p=typeof s.error=="string"?s.error:JSON.stringify(s.error,null,2))}catch(s){u&&g(` Failed to parse error body as JSON: ${s}`,!0)}D(t,e,r,o,n,p)}g(`\u2705 Request [${r}] completed in ${l}ms`,u);try{return await t.json()}catch(p){throw new c("Failed to parse JSON response",i.NETWORK_ERROR,{statusCode:t.status,context:{url:e,requestId:r},originalError:p instanceof Error?p:new Error(String(p))})}}async function F(t,e,r){let o=H(),n=JSON.stringify(e),a=n.length,u=K(t,r.serverUrl);if(r.debug){let s=(a/1024).toFixed(2),m=a>1e5?"\u26A0\uFE0F":"\u{1F680}";g(`${m} Starting compute request [${o}]: ${t} (${s}KB)`,!0)}let l=new AbortController,p=r.timeoutMs?setTimeout(()=>l.abort(),r.timeoutMs):null;try{let s=performance.now(),m=await fetch(u,{method:"POST",body:n,headers:V(o,r),signal:l.signal});return await W(m,u,o,a,r.serverUrl,s,r.debug)}catch(s){throw s instanceof Error&&s.name==="AbortError"&&r.timeoutMs?new c(`Request timed out after ${r.timeoutMs}ms`,i.TIMEOUT_ERROR,{context:{serverUrl:r.serverUrl,timeoutMs:r.timeoutMs,url:u,requestId:o,args:e}}):s instanceof TypeError?new c(`Network error: ${s.message}`,i.NETWORK_ERROR,{context:{serverUrl:r.serverUrl,url:u,requestId:o,endpoint:t},originalError:s}):s instanceof c?s:new c(s instanceof Error?s.message:String(s),i.UNKNOWN_ERROR,{context:{endpoint:t,requestId:o},originalError:s instanceof Error?s:new Error(String(s))})}finally{p!==null&&clearTimeout(p)}}N();T();var h=class{constructor(e,r){R(this,"serverUrl");R(this,"apiKey");R(this,"disposed",!1);R(this,"activeMonitors",new Set);R(this,"activeTimeouts",new Set);if(!e?.trim())throw new c("serverUrl is required",i.INVALID_CONFIG,{context:{serverUrl:e}});if(!e.match(/^https?:\/\//))throw new c(`Invalid serverUrl: "${e}". Must start with "http://" or "https://". For example: "http://localhost:5000" or "https://example.com"`,i.INVALID_CONFIG,{context:{serverUrl:e}});try{new URL(e)}catch(o){throw new c(`Invalid serverUrl: "${e}". Must be a valid URL. Received error: ${o instanceof Error?o.message:String(o)}`,i.INVALID_CONFIG,{context:{serverUrl:e},originalError:o instanceof Error?o:void 0})}this.apiKey=r,this.serverUrl=e.replace(/\/+$/,"")}buildHeaders(){let e={"Content-Type":"application/json"};return this.apiKey&&(e.RhinoComputeKey=this.apiKey),e}async isServerOnline(){this.ensureNotDisposed();let e=`${this.serverUrl}/healthcheck`,r={headers:this.buildHeaders(),method:"GET"};try{return(await fetch(e,r)).ok}catch(o){return d().debug("[ComputeServerStats] Fetch error:",o),!1}}async getActiveChildren(){this.ensureNotDisposed();try{let e=await fetch(`${this.serverUrl}/activechildren`,{headers:this.buildHeaders()});if(!e.ok)return d().warn("[ComputeServerStats] Failed to fetch active children:",e.status),null;let r=await e.text(),o=parseInt(r.trim(),10);return isNaN(o)?(d().warn("[ComputeServerStats] Invalid active children response:",r),null):o}catch(e){return d().warn("[ComputeServerStats] Error fetching active children:",e),null}}async getVersion(){this.ensureNotDisposed();try{let e=await fetch(`${this.serverUrl}/version`,{headers:this.buildHeaders()});if(!e.ok)return d().warn("[ComputeServerStats] Failed to fetch version:",e.status),null;try{let r=await e.json();return{rhino:r.rhino??"",compute:r.compute??"",git_sha:r.git_sha??null}}catch{return{rhino:await e.text(),compute:"",git_sha:null}}}catch(e){return d().warn("[ComputeServerStats] Error fetching version:",e),null}}async getServerStats(){if(this.ensureNotDisposed(),!await this.isServerOnline())return{isOnline:!1};let[r,o]=await Promise.all([this.getVersion(),this.getActiveChildren()]);return{isOnline:!0,...r&&{version:r},...o!==null&&{activeChildren:o}}}monitor(e,r=5e3){this.ensureNotDisposed();let o=!0,n=null;d().info(`\u{1F504} Starting server stats monitoring every ${r}ms`);let a=async()=>{if(n!==null&&(this.activeTimeouts.delete(n),n=null),!o||this.disposed)return;let l=await this.getServerStats();!o||this.disposed||(e(l),o&&!this.disposed&&(n=setTimeout(()=>{a()},r),this.activeTimeouts.add(n)))},u=()=>{o=!1,n!==null&&(clearTimeout(n),this.activeTimeouts.delete(n),n=null),this.activeMonitors.delete(u)};return this.activeMonitors.add(u),a(),u}async dispose(){if(!this.disposed){this.disposed=!0;for(let e of this.activeMonitors)e();this.activeMonitors.clear();for(let e of this.activeTimeouts)clearTimeout(e);this.activeTimeouts.clear()}}ensureNotDisposed(){if(this.disposed)throw new c("ComputeServerStats has been disposed and cannot be used",i.INVALID_STATE,{context:{disposed:this.disposed}})}};C();v();T();function x(t,e={}){let{preserveSpaces:r=!1}=e,o=t.trim();return r?(o=o.charAt(0).toLowerCase()+o.slice(1).replace(/[-_](.)/g,(n,a)=>a?a.toUpperCase():""),o):(o=o.replace(/^[A-Z]/,n=>n.toLowerCase()).replace(/[\s-_]+(.)?/g,(n,a)=>a?a.toUpperCase():""),o)}function I(t,e={}){return!t||typeof t!="object"?t:Array.isArray(t)?e.deep?t.map(r=>I(r,e)):t:Object.keys(t).reduce((r,o)=>{let n=x(o,{preserveSpaces:e.preserveSpaces}),a=t[o];return r[n]=e.deep?I(a,e):a,r},{})}export{L as a,G as b,R as c,i as d,c as e,C as f,U as g,N as h,d as i,S as j,M as k,T as l,F as m,h as n,x as o,I as p};
3
+ //# sourceMappingURL=chunk-BL2RNK2F.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/errors/error-codes.ts","../src/core/errors/base.ts","../src/core/errors/index.ts","../src/core/utils/logger.ts","../src/core/compute-fetch/compute-fetch.ts","../src/core/server/compute-server-stats.ts","../src/core/index.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 * Error handling - explicit public API\n */\n\nexport { RhinoComputeError } from './base';\nexport { ErrorCodes } from './error-codes';\nexport type { ErrorCode } from './error-codes';\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 'selva-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 'selva-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 } 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// 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 errorMap: Record<number, { message: string; code: string }> = {\n\t\t401: { message: `HTTP ${status}: ${statusText}`, code: ErrorCodes.AUTH_ERROR },\n\t\t403: { message: `HTTP ${status}: ${statusText}`, code: ErrorCodes.AUTH_ERROR },\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// 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// 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).\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 * pointer: { url: 'https://example.com/definition.gh' },\n * values: [{ ParamName: 'x', InnerTree: { '0': [{ type: 'System.Double', data: 10 }] } }]\n * },\n * { serverUrl: 'https://my-server.com', debug: true, timeoutMs: 30000 }\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\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 controller = new AbortController();\n\tconst timeoutId = config.timeoutMs\n\t\t? setTimeout(() => controller.abort(), config.timeoutMs)\n\t\t: null;\n\n\ttry {\n\t\tconst startTime = performance.now();\n\t\tconst response = await fetch(fullUrl, {\n\t\t\tmethod: 'POST',\n\t\t\tbody,\n\t\t\theaders: buildHeaders(requestId, config),\n\t\t\tsignal: controller.signal\n\t\t});\n\n\t\treturn await handleResponse(\n\t\t\tresponse,\n\t\t\tfullUrl,\n\t\t\trequestId,\n\t\t\trequestSize,\n\t\t\tconfig.serverUrl,\n\t\t\tstartTime,\n\t\t\tconfig.debug\n\t\t);\n\t} catch (error) {\n\t\tif (error instanceof Error && error.name === 'AbortError' && config.timeoutMs) {\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t`Request timed out after ${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: config.serverUrl,\n\t\t\t\t\t\ttimeoutMs: config.timeoutMs,\n\t\t\t\t\t\turl: fullUrl,\n\t\t\t\t\t\trequestId,\n\t\t\t\t\t\targs\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\n\t\t// Handle fetch errors (network issues, connection refused, etc.)\n\t\tif (error instanceof TypeError) {\n\t\t\tthrow new RhinoComputeError(`Network error: ${error.message}`, ErrorCodes.NETWORK_ERROR, {\n\t\t\t\tcontext: {\n\t\t\t\t\tserverUrl: config.serverUrl,\n\t\t\t\t\turl: fullUrl,\n\t\t\t\t\trequestId,\n\t\t\t\t\tendpoint\n\t\t\t\t},\n\t\t\t\toriginalError: error\n\t\t\t});\n\t\t}\n\n\t\t// Wrap any unhandled errors\n\t\tif (error instanceof RhinoComputeError) {\n\t\t\tthrow error;\n\t\t}\n\n\t\tthrow new RhinoComputeError(\n\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\tErrorCodes.UNKNOWN_ERROR,\n\t\t\t{\n\t\t\t\tcontext: { endpoint, requestId },\n\t\t\t\toriginalError: error instanceof Error ? error : new Error(String(error))\n\t\t\t}\n\t\t);\n\t} finally {\n\t\tif (timeoutId !== null) clearTimeout(timeoutId);\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\tconst _stats = await this.getServerStats();\n\n\t\t\t// Check again after async operation to prevent race condition\n\t\t\tif (!active || this.disposed) return;\n\n\t\t\tcallback(_stats);\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 * Core utilities and configuration for selva-compute\n *\n * This module provides the foundational building blocks for the library, including:\n * - **Networking**: Type-safe HTTP wrappers for the Rhino Compute API\n * - **Server Monitoring**: Health checks and telemetry monitoring\n * - **Error Handling**: Specialized error classes for API and network failures\n * - **Logging**: Configurable debug and production logging\n *\n * @example Performing a low-level compute request\n * ```typescript\n * import { fetchRhinoCompute, RhinoComputeError } from 'selva-compute/core';\n *\n * try {\n * const data = await fetchRhinoCompute('rhino/health', null, config);\n * console.log('Server is healthy:', data);\n * } catch (error) {\n * if (error instanceof RhinoComputeError) {\n * console.error(`API Error [${error.code}]: ${error.message}`);\n * }\n * }\n * ```\n *\n * @example Monitoring server status\n * ```typescript\n * import { ComputeServerStats } from 'selva-compute/core';\n *\n * const stats = new ComputeServerStats(serverUrl, apiKey);\n * if (await stats.isServerOnline()) {\n * const info = await stats.getServerStats();\n * console.log(`Compute Version: ${info.version}`);\n * }\n * await stats.dispose();\n * ```\n *\n * @module core\n */\n\n// ============================================================================\n// COMPUTE FETCH (Low-level HTTP client)\n// ============================================================================\n\nexport { fetchRhinoCompute } from './compute-fetch/compute-fetch';\n\n// =========================\n// Server Stats\n// =========================\n\nexport { ComputeServerStats } from './server';\n\n// ============================================================================\n// ERROR HANDLING\n// ============================================================================\n\nexport { RhinoComputeError } from './errors/base';\nexport { ErrorCodes } from './errors/error-codes';\nexport type { ErrorCode } from './errors/error-codes';\n\n// ============================================================================\n// UTILITIES\n// ============================================================================\n\n// Logging\nexport type { Logger } from './utils/logger';\nexport { setLogger, enableDebugLogging, getLogger } from './utils/logger';\n\n// Configuration\nexport type { ComputeConfig, RhinoModelUnit } from './types';\n\n// String utilities\nexport { toCamelCase, camelcaseKeys } from './utils/camel-case';\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":"ukBAAA,IAAaA,EAAbC,EAAAC,EAAA,kBAAaF,EAAa,CACzB,cAAe,gBACf,WAAY,aACZ,iBAAkB,mBAClB,kBAAmB,oBACnB,cAAe,gBACf,WAAY,aACZ,cAAe,gBACf,cAAe,gBACf,cAAe,gBACf,eAAgB,iBAChB,aAAc,eACd,kBAAmB,oBACnB,eAAgB,gBACjB,ICdA,IAOaG,EAPbC,EAAAC,EAAA,kBAAAC,IAOaH,EAAN,MAAMI,UAA0B,KAAM,CAM5C,YACCC,EACAC,EAAe,gBACfC,EACC,CACD,MAAMF,CAAO,EAVdG,EAAA,KAAgB,QAChBA,EAAA,KAAgB,cAChBA,EAAA,KAAgB,WAChBA,EAAA,KAAgB,iBAQf,KAAK,KAAO,oBACZ,KAAK,KAAOF,EACZ,KAAK,WAAaC,GAAS,WAC3B,KAAK,QAAUA,GAAS,QACxB,KAAK,cAAgBA,GAAS,cAG1B,UAAW,MAAM,WACpB,OAAO,eAAe,KAAM,QAAS,CACpC,MAAOA,GAAS,cAChB,WAAY,EACb,CAAC,CAEH,CASA,OAAO,WAAWE,EAAmBC,EAAgBC,EAAmC,CACvF,OAAO,IAAIP,EAAkB,UAAUK,CAAS,MAAMC,CAAM,GAAIE,EAAW,iBAAkB,CAC5F,QAAS,CAAE,UAA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A,CAAC,CACF,CACD","names":["ErrorCodes","init_error_codes","__esmMin","RhinoComputeError","init_base","__esmMin","init_error_codes","_RhinoComputeError","message","code","options","__publicField","inputName","reason","context","ErrorCodes","expectedType","defaultValue","availableValues","paramType","paramName","expectedStructure","errors_exports","__export","ErrorCodes","RhinoComputeError","init_errors","__esmMin","init_base","init_error_codes","getLogger","internalLogger","setLogger","logger","NoOpLogger","ConsoleLogger","enableDebugLogging","init_logger","__esmMin","message","args","init_errors","init_logger","throwHttpError","response","fullUrl","requestId","requestSize","serverUrl","errorBody","status","statusText","context","error","ErrorCodes","RhinoComputeError","buildUrl","endpoint","base","path","isLocalhost","host","buildHeaders","config","headers","getLogger","generateRequestId","log","message","debug","handleResponse","startTime","responseTime","parsed","e","fetchRhinoCompute","args","body","sizeKb","emoji","controller","timeoutId","init_errors","init_logger","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","init_base","init_error_codes","init_logger","toCamelCase","str","options","preserveSpaces","s","_","c","m","camelcaseKeys","obj","item","result","key","camelKey","value"]}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _chunkPE2FMBXDcjs = require('./chunk-PE2FMBXD.cjs');function v(t){return Buffer.from(t,"utf-8").toString("base64")}function A(t){if(!t||t.trim().length===0)return!1;try{return Buffer.from(t,"base64").toString("base64")===t}catch (e2){return!1}}function C(t){if(typeof globalThis.atob=="function")return Uint8Array.from(globalThis.atob(t),l=>l.charCodeAt(0));if(typeof globalThis.Buffer=="function")return globalThis.Buffer.from(t,"base64");let{RhinoComputeError:r,ErrorCodes:e}=(_chunkPE2FMBXDcjs.h.call(void 0, ),_chunkPE2FMBXDcjs.b.call(void 0, _chunkPE2FMBXDcjs.g));throw new r("Base64 decoding not supported in this environment.",e.INVALID_STATE,{context:{environmentInfo:"atob or Buffer not available"}})}function S(t){if(t==null){let{RhinoComputeError:n,ErrorCodes:o}=(_chunkPE2FMBXDcjs.h.call(void 0, ),_chunkPE2FMBXDcjs.b.call(void 0, _chunkPE2FMBXDcjs.g));throw new n("Input bytes must not be null or undefined",o.INVALID_INPUT,{context:{receivedValue:t}})}let r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=t;e.length>=3&&e[0]===239&&e[1]===187&&e[2]===191&&(e=e.slice(3));let l=e.byteLength,y=l%3,s=l-y,h="",i,d,c,u,a;for(let n=0;n<s;n+=3){let o=e[n]!==void 0?e[n]:0,b=e[n+1]!==void 0?e[n+1]:0,g=e[n+2]!==void 0?e[n+2]:0,f=o<<16|b<<8|g;if(i=(f&16515072)>>18,d=(f&258048)>>12,c=(f&4032)>>6,u=f&63,typeof r!="string")throw new Error("encodings must be a string");if(typeof i!="number"||i<0||i>=r.length)throw new Error("Invalid index a");if(typeof d!="number"||d<0||d>=r.length)throw new Error("Invalid index b");if(typeof c!="number"||c<0||c>=r.length)throw new Error("Invalid index c");if(typeof u!="number"||u<0||u>=r.length)throw new Error("Invalid index d");let p=r[i],m=r[d],w=r[c],B=r[u];if(p===void 0||m===void 0||w===void 0||B===void 0)throw new Error("Invalid encoding index");h+=p+m+w+B}if(y===1){if(a=e[s],a===void 0)throw new Error("'chunk' must not be undefined");i=(a&252)>>2,d=(a&3)<<4;let n=r[i],o=r[d];if(n===void 0||o===void 0)throw new Error("Invalid encoding index");h+=`${n+o}==`}else if(y===2){let n=_nullishCoalesce(e[s], () => (0)),o=e[s+1]!==void 0?e[s+1]:0;if(typeof n!="number"||n<0||n>255||typeof o!="number"||o<0||o>255)throw new Error("Invalid byte1");a=n<<8|o,i=(a&64512)>>10,d=(a&1008)>>4,c=(a&15)<<2;let b=r[i],g=r[d],f=r[c];if(b===void 0||g===void 0||f===void 0)throw new Error("Invalid encoding index");h+=`${b+g+f}=`}return h}exports.a = v; exports.b = A; exports.c = C; exports.d = S;
2
- //# sourceMappingURL=chunk-QCHPQ22Y.cjs.map
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _chunkMTDJ3VNBcjs = require('./chunk-MTDJ3VNB.cjs');function v(t){return Buffer.from(t,"utf-8").toString("base64")}function A(t){if(!t||t.trim().length===0)return!1;try{return Buffer.from(t,"base64").toString("base64")===t}catch (e2){return!1}}function C(t){if(typeof globalThis.atob=="function")return Uint8Array.from(globalThis.atob(t),l=>l.charCodeAt(0));if(typeof globalThis.Buffer=="function")return globalThis.Buffer.from(t,"base64");let{RhinoComputeError:r,ErrorCodes:e}=(_chunkMTDJ3VNBcjs.h.call(void 0, ),_chunkMTDJ3VNBcjs.b.call(void 0, _chunkMTDJ3VNBcjs.g));throw new r("Base64 decoding not supported in this environment.",e.INVALID_STATE,{context:{environmentInfo:"atob or Buffer not available"}})}function S(t){if(t==null){let{RhinoComputeError:n,ErrorCodes:o}=(_chunkMTDJ3VNBcjs.h.call(void 0, ),_chunkMTDJ3VNBcjs.b.call(void 0, _chunkMTDJ3VNBcjs.g));throw new n("Input bytes must not be null or undefined",o.INVALID_INPUT,{context:{receivedValue:t}})}let r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=t;e.length>=3&&e[0]===239&&e[1]===187&&e[2]===191&&(e=e.slice(3));let l=e.byteLength,y=l%3,s=l-y,h="",i,d,c,u,a;for(let n=0;n<s;n+=3){let o=e[n]!==void 0?e[n]:0,b=e[n+1]!==void 0?e[n+1]:0,g=e[n+2]!==void 0?e[n+2]:0,f=o<<16|b<<8|g;if(i=(f&16515072)>>18,d=(f&258048)>>12,c=(f&4032)>>6,u=f&63,typeof r!="string")throw new Error("encodings must be a string");if(typeof i!="number"||i<0||i>=r.length)throw new Error("Invalid index a");if(typeof d!="number"||d<0||d>=r.length)throw new Error("Invalid index b");if(typeof c!="number"||c<0||c>=r.length)throw new Error("Invalid index c");if(typeof u!="number"||u<0||u>=r.length)throw new Error("Invalid index d");let p=r[i],m=r[d],w=r[c],B=r[u];if(p===void 0||m===void 0||w===void 0||B===void 0)throw new Error("Invalid encoding index");h+=p+m+w+B}if(y===1){if(a=e[s],a===void 0)throw new Error("'chunk' must not be undefined");i=(a&252)>>2,d=(a&3)<<4;let n=r[i],o=r[d];if(n===void 0||o===void 0)throw new Error("Invalid encoding index");h+=`${n+o}==`}else if(y===2){let n=_nullishCoalesce(e[s], () => (0)),o=e[s+1]!==void 0?e[s+1]:0;if(typeof n!="number"||n<0||n>255||typeof o!="number"||o<0||o>255)throw new Error("Invalid byte1");a=n<<8|o,i=(a&64512)>>10,d=(a&1008)>>4,c=(a&15)<<2;let b=r[i],g=r[d],f=r[c];if(b===void 0||g===void 0||f===void 0)throw new Error("Invalid encoding index");h+=`${b+g+f}=`}return h}exports.a = v; exports.b = A; exports.c = C; exports.d = S;
2
+ //# sourceMappingURL=chunk-FB4LUGFJ.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/chunk-QCHPQ22Y.cjs","../src/core/utils/encoding.ts"],"names":["encodeStringToBase64","str","isBase64","decodeBase64ToBinary","base64File","c","RhinoComputeError","ErrorCodes","base64ByteArray","bytes","encodings","inputBytes","byteLength","byteRemainder","mainLength","base64","a","b","d","chunk","i","byte1","byte2","byte3","innerChunk","charA","charB","charC","charD"],"mappings":"AAAA,qOAAsD,SCQtCA,CAAAA,CAAqBC,CAAAA,CAAqB,CACzD,OAAO,MAAA,CAAO,IAAA,CAAKA,CAAAA,CAAK,OAAO,CAAA,CAAE,QAAA,CAAS,QAAQ,CACnD,CAsBO,SAASC,CAAAA,CAASD,CAAAA,CAAsB,CAC9C,EAAA,CAAI,CAACA,CAAAA,EAAOA,CAAAA,CAAI,IA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AAUU,CAAAA,CAAQC,CAAAA,CAAQC,CAAAA,CAAQC,CACnC,CAGA,EAAA,CAAIf,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,IAAMM,CAAAA,CAAQf,CAAAA,CAAUM,CAAC,CAAA,CACnBU,CAAAA,CAAQhB,CAAAA,CAAUO,CAAC,CAAA,CAEzB,EAAA,CAAIQ,CAAAA,GAAU,KAAA,CAAA,EAAaC,CAAAA,GAAU,KAAA,CAAA,CACpC,MAAM,IAAI,KAAA,CAAM,wBAAwB,CAAA,CAGzCX,CAAAA,EAAU,CAAA,EAAA","file":"/home/runner/work/selva-compute/selva-compute/dist/chunk-QCHPQ22Y.cjs","sourcesContent":[null,"/**\n * Encodes a string to base64 (Node 20+ safe)\n *\n * @internal Internal encoding helper — kept internal to `selva-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 `selva-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 `selva-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.trim().length === 0) return false;\n\ttry {\n\t\treturn Buffer.from(str, 'base64').toString('base64') === str;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Decodes a base64 string to binary data (Uint8Array)\n *\n * @internal Internal encoding helper — kept internal to `selva-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\tif (typeof globalThis.atob === 'function') {\n\t\treturn Uint8Array.from(globalThis.atob(base64File), (c) => c.charCodeAt(0));\n\t}\n\tif (typeof (globalThis as any).Buffer === 'function') {\n\t\t// Buffer.from returns a Uint8Array-compatible Buffer\n\t\treturn (globalThis as any).Buffer.from(base64File, 'base64');\n\t}\n\n\t// Import here to avoid circular dependencies at top level\n\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\tconst { RhinoComputeError, ErrorCodes } = require('./../../core/errors');\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 `selva-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\t// Import here to avoid circular dependencies at top level\n\t\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\t\tconst { RhinoComputeError, ErrorCodes } = require('./../../core/errors');\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// Import here to avoid circular dependencies at top level\n\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\tconst { getLogger } = require('./logger');\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"]}
1
+ {"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/chunk-FB4LUGFJ.cjs","../src/core/utils/encoding.ts"],"names":["encodeStringToBase64","str","isBase64","decodeBase64ToBinary","base64File","c","RhinoComputeError","ErrorCodes","base64ByteArray","bytes","encodings","inputBytes","byteLength","byteRemainder","mainLength","base64","a","b","d","chunk","i","byte1","byte2","byte3","innerChunk","charA","charB","charC","charD"],"mappings":"AAAA,qOAAsD,SCQtCA,CAAAA,CAAqBC,CAAAA,CAAqB,CACzD,OAAO,MAAA,CAAO,IAAA,CAAKA,CAAAA,CAAK,OAAO,CAAA,CAAE,QAAA,CAAS,QAAQ,CACnD,CAsBO,SAASC,CAAAA,CAASD,CAAAA,CAAsB,CAC9C,EAAA,CAAI,CAACA,CAAAA,EAAOA,CAAAA,CAAI,IAAA,CAAK,CAAA,CAAE,MAAA,GAAW,CAAA,CAAG,MAAO,CAAA,CAAA,CAC5C,GAAI,CACH,OAAO,MAAA,CAAO,IAAA,CAAKA,CAAAA,CAAK,QAAQ,CAAA,CAAE,QAAA,CAAS,QAAQ,CAAA,GAAMA,CAC1D,CAAA,UAAQ,CACP,MAAO,CAAA,CACR,CACD,CAWO,SAASE,CAAAA,CAAqBC,CAAAA,CAAgC,CACpE,EAAA,CAAI,OAAO,UAAA,CAAW,IAAA,EAAS,UAAA,CAC9B,OAAO,UAAA,CAAW,IAAA,CAAK,UAAA,CAAW,IAAA,CAAKA,CAAU,CAAA,CAAIC,CAAAA,EAAMA,CAAAA,CAAE,UAAA,CAAW,CAAC,CAAC,CAAA,CAE3E,EAAA,CAAI,OAAQ,UAAA,CAAmB,MAAA,EAAW,UAAA,C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A,CAAA,EAAaC,CAAAA,GAAU,KAAA,CAAA,CACpC,MAAM,IAAI,KAAA,CAAM,wBAAwB,CAAA,CAGzCX,CAAAA,EAAU,CAAA,EAAA","file":"/home/runner/work/selva-compute/selva-compute/dist/chunk-FB4LUGFJ.cjs","sourcesContent":[null,"/**\n * Encodes a string to base64 (Node 20+ safe)\n *\n * @internal Internal encoding helper — kept internal to `selva-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 `selva-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 `selva-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.trim().length === 0) return false;\n\ttry {\n\t\treturn Buffer.from(str, 'base64').toString('base64') === str;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Decodes a base64 string to binary data (Uint8Array)\n *\n * @internal Internal encoding helper — kept internal to `selva-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\tif (typeof globalThis.atob === 'function') {\n\t\treturn Uint8Array.from(globalThis.atob(base64File), (c) => c.charCodeAt(0));\n\t}\n\tif (typeof (globalThis as any).Buffer === 'function') {\n\t\t// Buffer.from returns a Uint8Array-compatible Buffer\n\t\treturn (globalThis as any).Buffer.from(base64File, 'base64');\n\t}\n\n\t// Import here to avoid circular dependencies at top level\n\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\tconst { RhinoComputeError, ErrorCodes } = require('./../../core/errors');\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 `selva-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\t// Import here to avoid circular dependencies at top level\n\t\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\t\tconst { RhinoComputeError, ErrorCodes } = require('./../../core/errors');\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// Import here to avoid circular dependencies at top level\n\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\tconst { getLogger } = require('./logger');\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"]}
@@ -0,0 +1,3 @@
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 f=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var A=(t,e,r)=>e in t?f(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var E=(t,e)=>()=>(t&&(e=t(t=0)),e);var L=(t,e)=>{for(var r in e)f(t,r,{get:e[r],enumerable:!0})},k=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of b(e))!_.call(t,n)&&n!==r&&f(t,n,{get:()=>e[n],enumerable:!(o=$(e,n))||o.enumerable});return t};var G=t=>k(f({},"__esModule",{value:!0}),t);var R=(t,e,r)=>A(t,typeof e!="symbol"?e+"":e,r);var i,v=E(()=>{"use strict";i= exports.d ={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 c,C= exports.f =E(()=>{"use strict";v();c= exports.e =class t extends Error{constructor(r,o="UNKNOWN_ERROR",n){super(r);R(this,"code");R(this,"statusCode");R(this,"context");R(this,"originalError");this.name="RhinoComputeError",this.code=o,this.statusCode=_optionalChain([n, 'optionalAccess', _2 => _2.statusCode]),this.context=_optionalChain([n, 'optionalAccess', _3 => _3.context]),this.originalError=_optionalChain([n, 'optionalAccess', _4 => _4.originalError]),"cause"in Error.prototype&&Object.defineProperty(this,"cause",{value:_optionalChain([n, 'optionalAccess', _5 => _5.originalError]),enumerable:!0})}static validation(r,o,n){return new t(`Input "${r}": ${o}`,i.VALIDATION_ERROR,{context:{inputName:r,reason:o,...n}})}static missingValues(r,o,n){return new t(`Input "${r}" has no values defined${o?` (expected ${o})`:""}`,i.INVALID_INPUT,{context:{inputName:r,expectedType:o,...n}})}static invalidDefault(r,o,n,a){return new t(`ValueList input "${r}" default value "${o}" is not in available values`,i.VALIDATION_ERROR,{context:{inputName:r,defaultValue:o,availableValues:n,...a}})}static unknownParamType(r,o,n){return new t(`Unknown paramType: ${r}`,i.VALIDATION_ERROR,{context:{receivedParamType:r,paramName:o,...n}})}static invalidStructure(r,o,n){return new t(`Invalid input structure for "${r}" (expected ${o})`,i.INVALID_INPUT,{context:{inputName:r,expectedStructure:o,...n}})}}});var U={};L(U,{ErrorCodes:()=>i,RhinoComputeError:()=>c});var N=E(()=>{"use strict";C();v()});function d(){return O}function S(t){t===null?O=new w:"debug"in t&&"info"in t&&"warn"in t&&"error"in t?O=t:O=new y}function M(){S(new y)}var w,y,O,T= exports.l =E(()=>{"use strict";w=class{debug(){}info(){}warn(){}error(){}},y=class{debug(e,...r){console.debug(e,...r)}info(e,...r){console.info(e,...r)}warn(e,...r){console.warn(e,...r)}error(e,...r){console.error(e,...r)}},O=new w});N();T();function D(t,e,r,o,n,a){let{status:u,statusText:l}=t,p={url:e,requestId:r,method:"POST",requestSize:o,serverUrl:n},m={401:{message:`HTTP ${u}: ${l}`,code:i.AUTH_ERROR},403:{message:`HTTP ${u}: ${l}`,code:i.AUTH_ERROR},404:{message:`Endpoint not found: ${e}`,code:i.NETWORK_ERROR},413:{message:`Request too large: ${(o/1024).toFixed(2)}KB`,code:i.VALIDATION_ERROR},429:{message:"Rate limit exceeded",code:i.NETWORK_ERROR},500:{message:`Server error: ${a||l}`,code:i.COMPUTATION_ERROR},502:{message:`Service unavailable: ${l}`,code:i.NETWORK_ERROR},503:{message:`Service unavailable: ${l}`,code:i.NETWORK_ERROR},504:{message:`Service unavailable: ${l}`,code:i.NETWORK_ERROR}}[u]||{message:`HTTP ${u}: ${l}`,code:i.UNKNOWN_ERROR};throw new c(m.message,m.code,{statusCode:u,context:p})}function K(t,e){let r=e.replace(/\/+$/,""),o=t.replace(/^\/+/,"");return`${r}/${o}`}function P(t){try{let e=new URL(t).host;return/^(localhost|127\.0\.0\.1|::1)(:\d+)?$/i.test(e)}catch (e2){return/(localhost|127\.0\.0\.1)/i.test(t)}}function V(t,e){let r={"X-Request-ID":t,"Content-Type":"application/json",...e.authToken&&{Authorization:e.authToken},...e.apiKey&&{RhinoComputeKey:e.apiKey}};return!e.apiKey&&!P(e.serverUrl)&&d().warn(`\u26A0\uFE0F [Rhino Compute] Request [${t}] targets remote server (${e.serverUrl}) but no API key is configured. Requests may fail or be rate-limited.`),r}function H(){return`${Date.now()}-${Math.random().toString(36).substring(2,11)}`}function g(t,e){e&&d().debug(t)}async function W(t,e,r,o,n,a,u){let l=Math.round(performance.now()-a);if(!t.ok){let p=await t.text();if(u&&(g(`\u274C Request [${r}] failed with HTTP ${t.status} in ${l}ms`,!0),g(` URL: ${e}`,!0),g(` Status: ${t.status} ${t.statusText}`,!0),p&&g(` Response body: ${p.substring(0,500)}${p.length>500?"...":""}`,!0)),t.status===500)try{let s=JSON.parse(p);if(_optionalChain([s, 'optionalAccess', _6 => _6.values])&&(s.errors||s.warnings))return u&&(g(`\u26A0\uFE0F Request [${r}] completed with Grasshopper errors in ${l}ms`,!0),_optionalChain([s, 'access', _7 => _7.errors, 'optionalAccess', _8 => _8.length])>0&&g(` Errors: ${JSON.stringify(s.errors,null,2)}`,!0),_optionalChain([s, 'access', _9 => _9.warnings, 'optionalAccess', _10 => _10.length])>0&&g(` Warnings: ${JSON.stringify(s.warnings,null,2)}`,!0)),s;_optionalChain([s, 'optionalAccess', _11 => _11.Message])?p=`${s.ExceptionType?s.ExceptionType+": ":""}${s.Message}
2
+ ${s.StackTrace||""}`:_optionalChain([s, 'optionalAccess', _12 => _12.error])&&(p=typeof s.error=="string"?s.error:JSON.stringify(s.error,null,2))}catch(s){u&&g(` Failed to parse error body as JSON: ${s}`,!0)}D(t,e,r,o,n,p)}g(`\u2705 Request [${r}] completed in ${l}ms`,u);try{return await t.json()}catch(p){throw new c("Failed to parse JSON response",i.NETWORK_ERROR,{statusCode:t.status,context:{url:e,requestId:r},originalError:p instanceof Error?p:new Error(String(p))})}}async function F(t,e,r){let o=H(),n=JSON.stringify(e),a=n.length,u=K(t,r.serverUrl);if(r.debug){let s=(a/1024).toFixed(2),m=a>1e5?"\u26A0\uFE0F":"\u{1F680}";g(`${m} Starting compute request [${o}]: ${t} (${s}KB)`,!0)}let l=new AbortController,p=r.timeoutMs?setTimeout(()=>l.abort(),r.timeoutMs):null;try{let s=performance.now(),m=await fetch(u,{method:"POST",body:n,headers:V(o,r),signal:l.signal});return await W(m,u,o,a,r.serverUrl,s,r.debug)}catch(s){throw s instanceof Error&&s.name==="AbortError"&&r.timeoutMs?new c(`Request timed out after ${r.timeoutMs}ms`,i.TIMEOUT_ERROR,{context:{serverUrl:r.serverUrl,timeoutMs:r.timeoutMs,url:u,requestId:o,args:e}}):s instanceof TypeError?new c(`Network error: ${s.message}`,i.NETWORK_ERROR,{context:{serverUrl:r.serverUrl,url:u,requestId:o,endpoint:t},originalError:s}):s instanceof c?s:new c(s instanceof Error?s.message:String(s),i.UNKNOWN_ERROR,{context:{endpoint:t,requestId:o},originalError:s instanceof Error?s:new Error(String(s))})}finally{p!==null&&clearTimeout(p)}}N();T();var h=class{constructor(e,r){R(this,"serverUrl");R(this,"apiKey");R(this,"disposed",!1);R(this,"activeMonitors",new Set);R(this,"activeTimeouts",new Set);if(!_optionalChain([e, 'optionalAccess', _13 => _13.trim, 'call', _14 => _14()]))throw new c("serverUrl is required",i.INVALID_CONFIG,{context:{serverUrl:e}});if(!e.match(/^https?:\/\//))throw new c(`Invalid serverUrl: "${e}". Must start with "http://" or "https://". For example: "http://localhost:5000" or "https://example.com"`,i.INVALID_CONFIG,{context:{serverUrl:e}});try{new URL(e)}catch(o){throw new c(`Invalid serverUrl: "${e}". Must be a valid URL. Received error: ${o instanceof Error?o.message:String(o)}`,i.INVALID_CONFIG,{context:{serverUrl:e},originalError:o instanceof Error?o:void 0})}this.apiKey=r,this.serverUrl=e.replace(/\/+$/,"")}buildHeaders(){let e={"Content-Type":"application/json"};return this.apiKey&&(e.RhinoComputeKey=this.apiKey),e}async isServerOnline(){this.ensureNotDisposed();let e=`${this.serverUrl}/healthcheck`,r={headers:this.buildHeaders(),method:"GET"};try{return(await fetch(e,r)).ok}catch(o){return d().debug("[ComputeServerStats] Fetch error:",o),!1}}async getActiveChildren(){this.ensureNotDisposed();try{let e=await fetch(`${this.serverUrl}/activechildren`,{headers:this.buildHeaders()});if(!e.ok)return d().warn("[ComputeServerStats] Failed to fetch active children:",e.status),null;let r=await e.text(),o=parseInt(r.trim(),10);return isNaN(o)?(d().warn("[ComputeServerStats] Invalid active children response:",r),null):o}catch(e){return d().warn("[ComputeServerStats] Error fetching active children:",e),null}}async getVersion(){this.ensureNotDisposed();try{let e=await fetch(`${this.serverUrl}/version`,{headers:this.buildHeaders()});if(!e.ok)return d().warn("[ComputeServerStats] Failed to fetch version:",e.status),null;try{let r=await e.json();return{rhino:_nullishCoalesce(r.rhino, () => ("")),compute:_nullishCoalesce(r.compute, () => ("")),git_sha:_nullishCoalesce(r.git_sha, () => (null))}}catch (e3){return{rhino:await e.text(),compute:"",git_sha:null}}}catch(e){return d().warn("[ComputeServerStats] Error fetching version:",e),null}}async getServerStats(){if(this.ensureNotDisposed(),!await this.isServerOnline())return{isOnline:!1};let[r,o]=await Promise.all([this.getVersion(),this.getActiveChildren()]);return{isOnline:!0,...r&&{version:r},...o!==null&&{activeChildren:o}}}monitor(e,r=5e3){this.ensureNotDisposed();let o=!0,n=null;d().info(`\u{1F504} Starting server stats monitoring every ${r}ms`);let a=async()=>{if(n!==null&&(this.activeTimeouts.delete(n),n=null),!o||this.disposed)return;let l=await this.getServerStats();!o||this.disposed||(e(l),o&&!this.disposed&&(n=setTimeout(()=>{a()},r),this.activeTimeouts.add(n)))},u=()=>{o=!1,n!==null&&(clearTimeout(n),this.activeTimeouts.delete(n),n=null),this.activeMonitors.delete(u)};return this.activeMonitors.add(u),a(),u}async dispose(){if(!this.disposed){this.disposed=!0;for(let e of this.activeMonitors)e();this.activeMonitors.clear();for(let e of this.activeTimeouts)clearTimeout(e);this.activeTimeouts.clear()}}ensureNotDisposed(){if(this.disposed)throw new c("ComputeServerStats has been disposed and cannot be used",i.INVALID_STATE,{context:{disposed:this.disposed}})}};C();v();T();function x(t,e={}){let{preserveSpaces:r=!1}=e,o=t.trim();return r?(o=o.charAt(0).toLowerCase()+o.slice(1).replace(/[-_](.)/g,(n,a)=>a?a.toUpperCase():""),o):(o=o.replace(/^[A-Z]/,n=>n.toLowerCase()).replace(/[\s-_]+(.)?/g,(n,a)=>a?a.toUpperCase():""),o)}function I(t,e={}){return!t||typeof t!="object"?t:Array.isArray(t)?e.deep?t.map(r=>I(r,e)):t:Object.keys(t).reduce((r,o)=>{let n=x(o,{preserveSpaces:e.preserveSpaces}),a=t[o];return r[n]=e.deep?I(a,e):a,r},{})}exports.a = L; exports.b = G; exports.c = R; exports.d = i; exports.e = c; exports.f = C; exports.g = U; exports.h = N; exports.i = d; exports.j = S; exports.k = M; exports.l = T; exports.m = F; exports.n = h; exports.o = x; exports.p = I;
3
+ //# sourceMappingURL=chunk-MTDJ3VNB.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/chunk-PE2FMBXD.cjs","../src/core/errors/error-codes.ts","../src/core/errors/base.ts","../src/core/server/compute-server-stats.ts"],"names":["ErrorCodes","init_error_codes","__esmMin","RhinoComputeError","init_base","_RhinoComputeError","message","code","options","__publicField","inputName","reason","context"],"mappings":"AAAA,qrBAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,wBAAwB,CAAC,IAAI,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B,YAAA,CAAA,CAChBA,CAAAA,CAAA,IAAA,CAAgB,SAAA,CAAA,CAChBA,CAAAA,CAAA,IAAA,CAAgB,eAAA,CAAA,CAQf,IAAA,CAAK,IAAA,CAAO,mBAAA,CACZ,IAAA,CAAK,IAAA,CAAOF,CAAAA,CACZ,IAAA,CAAK,UAAA,iBAAaC,CAAAA,6BAAS,YAAA,CAC3B,IAAA,CAAK,OAAA,iBAAUA,CAAAA,6BAAS,SAAA,CACxB,IAAA,CAAK,aAAA,iBAAgBA,CAAAA,6BAAS,eAAA,CAG1B,OAAA,GAAW,KAAA,CAAM,SAAA,EACpB,MAAA,CAAO,cAAA,CAAe,IAAA,CAAM,OAAA,CAAS,CACpC,KAAA,iBAAOA,CAAAA,6BAAS,eAAA,CAChB,UAAA,CAAY,CAAA,CACb,CAAC,CAEH,CASA,OAAO,UAAA,CAAWE,CAAAA,CAAmBC,CAAAA,CAAgBC,CAAAA,CAAmC,CACvF,OAAO,IAAIP,CAAAA,CAAkB,CAAA,OAAA,EAAUK,CAAS,CAAA,GAAA,EAAMC,CAAM,CAAA,CAAA;ACPb","file":"/home/runner/work/selva-compute/selva-compute/dist/chunk-PE2FMBXD.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\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\tconst _stats = await this.getServerStats();\n\n\t\t\t// Check again after async operation to prevent race condition\n\t\t\tif (!active || this.disposed) return;\n\n\t\t\tcallback(_stats);\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"]}
1
+ {"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/chunk-MTDJ3VNB.cjs","../src/core/errors/error-codes.ts","../src/core/errors/base.ts","../src/core/server/compute-server-stats.ts"],"names":["ErrorCodes","init_error_codes","__esmMin","RhinoComputeError","init_base","_RhinoComputeError","message","code","options","__publicField","inputName","reason","context"],"mappings":"AAAA,qrBAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,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,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,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,CA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es = {\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\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\tconst _stats = await this.getServerStats();\n\n\t\t\t// Check again after async operation to prevent race condition\n\t\t\tif (!active || this.disposed) return;\n\n\t\t\tcallback(_stats);\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"]}
@@ -1,2 +1,2 @@
1
- import{b as x,g as E,h as I}from"./chunk-MK3M76VN.js";function v(t){return Buffer.from(t,"utf-8").toString("base64")}function A(t){if(!t||t.trim().length===0)return!1;try{return Buffer.from(t,"base64").toString("base64")===t}catch{return!1}}function C(t){if(typeof globalThis.atob=="function")return Uint8Array.from(globalThis.atob(t),l=>l.charCodeAt(0));if(typeof globalThis.Buffer=="function")return globalThis.Buffer.from(t,"base64");let{RhinoComputeError:r,ErrorCodes:e}=(I(),x(E));throw new r("Base64 decoding not supported in this environment.",e.INVALID_STATE,{context:{environmentInfo:"atob or Buffer not available"}})}function S(t){if(t==null){let{RhinoComputeError:n,ErrorCodes:o}=(I(),x(E));throw new n("Input bytes must not be null or undefined",o.INVALID_INPUT,{context:{receivedValue:t}})}let r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=t;e.length>=3&&e[0]===239&&e[1]===187&&e[2]===191&&(e=e.slice(3));let l=e.byteLength,y=l%3,s=l-y,h="",i,d,c,u,a;for(let n=0;n<s;n+=3){let o=e[n]!==void 0?e[n]:0,b=e[n+1]!==void 0?e[n+1]:0,g=e[n+2]!==void 0?e[n+2]:0,f=o<<16|b<<8|g;if(i=(f&16515072)>>18,d=(f&258048)>>12,c=(f&4032)>>6,u=f&63,typeof r!="string")throw new Error("encodings must be a string");if(typeof i!="number"||i<0||i>=r.length)throw new Error("Invalid index a");if(typeof d!="number"||d<0||d>=r.length)throw new Error("Invalid index b");if(typeof c!="number"||c<0||c>=r.length)throw new Error("Invalid index c");if(typeof u!="number"||u<0||u>=r.length)throw new Error("Invalid index d");let p=r[i],m=r[d],w=r[c],B=r[u];if(p===void 0||m===void 0||w===void 0||B===void 0)throw new Error("Invalid encoding index");h+=p+m+w+B}if(y===1){if(a=e[s],a===void 0)throw new Error("'chunk' must not be undefined");i=(a&252)>>2,d=(a&3)<<4;let n=r[i],o=r[d];if(n===void 0||o===void 0)throw new Error("Invalid encoding index");h+=`${n+o}==`}else if(y===2){let n=e[s]??0,o=e[s+1]!==void 0?e[s+1]:0;if(typeof n!="number"||n<0||n>255||typeof o!="number"||o<0||o>255)throw new Error("Invalid byte1");a=n<<8|o,i=(a&64512)>>10,d=(a&1008)>>4,c=(a&15)<<2;let b=r[i],g=r[d],f=r[c];if(b===void 0||g===void 0||f===void 0)throw new Error("Invalid encoding index");h+=`${b+g+f}=`}return h}export{v as a,A as b,C as c,S as d};
2
- //# sourceMappingURL=chunk-WD3ENUAA.js.map
1
+ import{b as x,g as E,h as I}from"./chunk-BL2RNK2F.js";function v(t){return Buffer.from(t,"utf-8").toString("base64")}function A(t){if(!t||t.trim().length===0)return!1;try{return Buffer.from(t,"base64").toString("base64")===t}catch{return!1}}function C(t){if(typeof globalThis.atob=="function")return Uint8Array.from(globalThis.atob(t),l=>l.charCodeAt(0));if(typeof globalThis.Buffer=="function")return globalThis.Buffer.from(t,"base64");let{RhinoComputeError:r,ErrorCodes:e}=(I(),x(E));throw new r("Base64 decoding not supported in this environment.",e.INVALID_STATE,{context:{environmentInfo:"atob or Buffer not available"}})}function S(t){if(t==null){let{RhinoComputeError:n,ErrorCodes:o}=(I(),x(E));throw new n("Input bytes must not be null or undefined",o.INVALID_INPUT,{context:{receivedValue:t}})}let r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=t;e.length>=3&&e[0]===239&&e[1]===187&&e[2]===191&&(e=e.slice(3));let l=e.byteLength,y=l%3,s=l-y,h="",i,d,c,u,a;for(let n=0;n<s;n+=3){let o=e[n]!==void 0?e[n]:0,b=e[n+1]!==void 0?e[n+1]:0,g=e[n+2]!==void 0?e[n+2]:0,f=o<<16|b<<8|g;if(i=(f&16515072)>>18,d=(f&258048)>>12,c=(f&4032)>>6,u=f&63,typeof r!="string")throw new Error("encodings must be a string");if(typeof i!="number"||i<0||i>=r.length)throw new Error("Invalid index a");if(typeof d!="number"||d<0||d>=r.length)throw new Error("Invalid index b");if(typeof c!="number"||c<0||c>=r.length)throw new Error("Invalid index c");if(typeof u!="number"||u<0||u>=r.length)throw new Error("Invalid index d");let p=r[i],m=r[d],w=r[c],B=r[u];if(p===void 0||m===void 0||w===void 0||B===void 0)throw new Error("Invalid encoding index");h+=p+m+w+B}if(y===1){if(a=e[s],a===void 0)throw new Error("'chunk' must not be undefined");i=(a&252)>>2,d=(a&3)<<4;let n=r[i],o=r[d];if(n===void 0||o===void 0)throw new Error("Invalid encoding index");h+=`${n+o}==`}else if(y===2){let n=e[s]??0,o=e[s+1]!==void 0?e[s+1]:0;if(typeof n!="number"||n<0||n>255||typeof o!="number"||o<0||o>255)throw new Error("Invalid byte1");a=n<<8|o,i=(a&64512)>>10,d=(a&1008)>>4,c=(a&15)<<2;let b=r[i],g=r[d],f=r[c];if(b===void 0||g===void 0||f===void 0)throw new Error("Invalid encoding index");h+=`${b+g+f}=`}return h}export{v as a,A as b,C as c,S as d};
2
+ //# sourceMappingURL=chunk-RGHW3SLU.js.map