(()=>{let e=new Map,t=new Map;function s(e){"undefined"!=typeof window&&window.parent!==window?window.parent.postMessage(e,"*"):self.postMessage(e)}let n=0;self.syscall=async(e,...r)=>await new Promise(((a,o)=>{n++,t.set(n,{resolve:a,reject:o}),s({type:"syscall",id:n,name:e,args:r})}));let r=new Map;self.require=e=>r.get(e),self.console=new class{constructor(e,t=!0){this.print=t,this.callback=e}log(...e){this.push("log",e)}warn(...e){this.push("warn",e)}error(...e){this.push("error",e)}info(...e){this.push("info",e)}push(e,t){this.callback(e,this.logMessage(t)),this.print&&console[e](...t)}logMessage(e){let t=[];for(let s of e)switch(typeof s){case"string":case"number":t.push(""+s);break;case"undefined":t.push("undefined");break;default:try{let e=JSON.stringify(s,null,2);e.length>500&&(e=e.substring(0,500)+"..."),t.push(e)}catch{t.push("[circular object]")}}return t.join(" ")}}(((e,t)=>{s({type:"log",level:e,message:t})}),!1),self.addEventListener("message",(n=>{(async()=>{let a=n.data;switch(a.type){case"load":let n=new Function(`return (${a.code})["default"]`);e.set(a.name,n()),s({type:"inited",name:a.name});break;case"load-dependency":let o=new Function(`return ${a.code}`)();r.set(a.name,o),s({type:"dependency-inited",name:a.name});break;case"invoke":let l=e.get(a.name);if(!l)throw new Error(`Function not loaded: ${a.name}`);try{let e=await Promise.resolve(l(...a.args||[]));s({type:"result",id:a.id,result:e})}catch(e){s({type:"result",id:a.id,error:e.message,stack:e.stack})}break;case"syscall-response":let i=a.id;const c=t.get(i);if(!c)throw console.log("Current outstanding requests",t,"looking up",i),Error("Invalid request id");t.delete(i),a.error?c.reject(new Error(a.error)):c.resolve(a.result)}})().catch((e=>{throw e}))}))})();
//# sourceMappingURL=sandbox_worker.1fe6c99c.js.map
