(()=>{let e=new Map,t=new Map,s=!1;function n(e){s||window.parent===window?self.postMessage(e):window.parent.postMessage(e,"*")}"undefined"==typeof window&&(window={},s=!0);let r=0;self.syscall=async(e,...s)=>await new Promise(((a,o)=>{r++,t.set(r,{resolve:a,reject:o}),n({type:"syscall",id:r,name:e,args:s})}));let a=new Map;self.require=e=>a.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)=>{n({type:"log",level:e,message:t})}),!1),self.addEventListener("message",(s=>{(async()=>{let r=s.data;switch(r.type){case"load":let s=new Function(`return (${r.code})["default"]`);e.set(r.name,s()),n({type:"inited",name:r.name});break;case"load-dependency":let o=new Function(`return ${r.code}`)();a.set(r.name,o),n({type:"dependency-inited",name:r.name});break;case"invoke":let l=e.get(r.name);if(!l)throw new Error(`Function not loaded: ${r.name}`);try{let e=await Promise.resolve(l(...r.args||[]));n({type:"result",id:r.id,result:e})}catch(e){n({type:"result",id:r.id,error:e.message,stack:e.stack})}break;case"syscall-response":let i=r.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),r.error?c.reject(new Error(r.error)):c.resolve(r.result)}})().catch((e=>{throw e}))}))})();
//# sourceMappingURL=sandbox_worker.c7c31278.js.map
