UNPKG

phala

Version:
24 lines 388 kB
#!/usr/bin/env node import { createRequire } from 'module';const require = createRequire(import.meta.url); var Lg=Object.create;var $i=Object.defineProperty;var Ng=Object.getOwnPropertyDescriptor;var Og=Object.getOwnPropertyNames;var jg=Object.getPrototypeOf,Fg=Object.prototype.hasOwnProperty;var ka=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var ur=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Vg=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Og(t))!Fg.call(e,o)&&o!==n&&$i(e,o,{get:()=>t[o],enumerable:!(r=Ng(t,o))||r.enumerable});return e};var Hg=(e,t,n)=>(n=e!=null?Lg(jg(e)):{},Vg(t||!e||!e.__esModule?$i(n,"default",{value:e,enumerable:!0}):n,e));var Di=ur((wA,Ti)=>{var Sn=1e3,kn=Sn*60,In=kn*60,sn=In*24,zg=sn*7,Kg=sn*365.25;Ti.exports=function(e,t){t=t||{};var n=typeof e;if(n==="string"&&e.length>0)return qg(e);if(n==="number"&&isFinite(e))return t.long?Bg(e):Gg(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function qg(e){if(e=String(e),!(e.length>100)){var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(t){var n=parseFloat(t[1]),r=(t[2]||"ms").toLowerCase();switch(r){case"years":case"year":case"yrs":case"yr":case"y":return n*Kg;case"weeks":case"week":case"w":return n*zg;case"days":case"day":case"d":return n*sn;case"hours":case"hour":case"hrs":case"hr":case"h":return n*In;case"minutes":case"minute":case"mins":case"min":case"m":return n*kn;case"seconds":case"second":case"secs":case"sec":case"s":return n*Sn;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}}}function Gg(e){var t=Math.abs(e);return t>=sn?Math.round(e/sn)+"d":t>=In?Math.round(e/In)+"h":t>=kn?Math.round(e/kn)+"m":t>=Sn?Math.round(e/Sn)+"s":e+"ms"}function Bg(e){var t=Math.abs(e);return t>=sn?Wr(e,t,sn,"day"):t>=In?Wr(e,t,In,"hour"):t>=kn?Wr(e,t,kn,"minute"):t>=Sn?Wr(e,t,Sn,"second"):e+" ms"}function Wr(e,t,n,r){var o=t>=n*1.5;return Math.round(e/n)+" "+r+(o?"s":"")}});var Ia=ur((_A,Mi)=>{function Wg(e){n.debug=n,n.default=n,n.coerce=c,n.disable=s,n.enable=o,n.enabled=i,n.humanize=Di(),n.destroy=l,Object.keys(e).forEach(p=>{n[p]=e[p]}),n.names=[],n.skips=[],n.formatters={};function t(p){let u=0;for(let f=0;f<p.length;f++)u=(u<<5)-u+p.charCodeAt(f),u|=0;return n.colors[Math.abs(u)%n.colors.length]}n.selectColor=t;function n(p){let u,f=null,d,h;function g(...y){if(!g.enabled)return;let k=g,_=Number(new Date),E=_-(u||_);k.diff=E,k.prev=u,k.curr=_,u=_,y[0]=n.coerce(y[0]),typeof y[0]!="string"&&y.unshift("%O");let S=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(I,x)=>{if(I==="%%")return"%";S++;let U=n.formatters[x];if(typeof U=="function"){let M=y[S];I=U.call(k,M),y.splice(S,1),S--}return I}),n.formatArgs.call(k,y),(k.log||n.log).apply(k,y)}return g.namespace=p,g.useColors=n.useColors(),g.color=n.selectColor(p),g.extend=r,g.destroy=n.destroy,Object.defineProperty(g,"enabled",{enumerable:!0,configurable:!1,get:()=>f!==null?f:(d!==n.namespaces&&(d=n.namespaces,h=n.enabled(p)),h),set:y=>{f=y}}),typeof n.init=="function"&&n.init(g),g}function r(p,u){let f=n(this.namespace+(typeof u>"u"?":":u)+p);return f.log=this.log,f}function o(p){n.save(p),n.namespaces=p,n.names=[],n.skips=[];let u=(typeof p=="string"?p:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(let f of u)f[0]==="-"?n.skips.push(f.slice(1)):n.names.push(f)}function a(p,u){let f=0,d=0,h=-1,g=0;for(;f<p.length;)if(d<u.length&&(u[d]===p[f]||u[d]==="*"))u[d]==="*"?(h=d,g=f,d++):(f++,d++);else if(h!==-1)d=h+1,g++,f=g;else return!1;for(;d<u.length&&u[d]==="*";)d++;return d===u.length}function s(){let p=[...n.names,...n.skips.map(u=>"-"+u)].join(",");return n.enable(""),p}function i(p){for(let u of n.skips)if(a(p,u))return!1;for(let u of n.names)if(a(p,u))return!0;return!1}function c(p){return p instanceof Error?p.stack||p.message:p}function l(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return n.enable(n.load()),n}Mi.exports=Wg});var Ui=ur((Ye,Jr)=>{Ye.formatArgs=Yg;Ye.save=Xg;Ye.load=Zg;Ye.useColors=Jg;Ye.storage=Qg();Ye.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();Ye.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Jg(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let e;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Yg(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+Jr.exports.humanize(this.diff),!this.useColors)return;let t="color: "+this.color;e.splice(1,0,t,"color: inherit");let n=0,r=0;e[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(n++,o==="%c"&&(r=n))}),e.splice(r,0,t)}Ye.log=console.debug||console.log||(()=>{});function Xg(e){try{e?Ye.storage.setItem("debug",e):Ye.storage.removeItem("debug")}catch{}}function Zg(){let e;try{e=Ye.storage.getItem("debug")||Ye.storage.getItem("DEBUG")}catch{}return!e&&typeof process<"u"&&"env"in process&&(e=process.env.DEBUG),e}function Qg(){try{return localStorage}catch{}}Jr.exports=Ia()(Ye);var{formatters:eh}=Jr.exports;eh.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}});var Ni=ur((Ie,Xr)=>{var th=ka("tty"),Yr=ka("util");Ie.init=ch;Ie.log=ah;Ie.formatArgs=rh;Ie.save=sh;Ie.load=ih;Ie.useColors=nh;Ie.destroy=Yr.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");Ie.colors=[6,2,3,4,5,1];try{let e=ka("supports-color");e&&(e.stderr||e).level>=2&&(Ie.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221])}catch{}Ie.inspectOpts=Object.keys(process.env).filter(e=>/^debug_/i.test(e)).reduce((e,t)=>{let n=t.substring(6).toLowerCase().replace(/_([a-z])/g,(o,a)=>a.toUpperCase()),r=process.env[t];return/^(yes|on|true|enabled)$/i.test(r)?r=!0:/^(no|off|false|disabled)$/i.test(r)?r=!1:r==="null"?r=null:r=Number(r),e[n]=r,e},{});function nh(){return"colors"in Ie.inspectOpts?!!Ie.inspectOpts.colors:th.isatty(process.stderr.fd)}function rh(e){let{namespace:t,useColors:n}=this;if(n){let r=this.color,o="\x1B[3"+(r<8?r:"8;5;"+r),a=` ${o};1m${t} \x1B[0m`;e[0]=a+e[0].split(` `).join(` `+a),e.push(o+"m+"+Xr.exports.humanize(this.diff)+"\x1B[0m")}else e[0]=oh()+t+" "+e[0]}function oh(){return Ie.inspectOpts.hideDate?"":new Date().toISOString()+" "}function ah(...e){return process.stderr.write(Yr.formatWithOptions(Ie.inspectOpts,...e)+` `)}function sh(e){e?process.env.DEBUG=e:delete process.env.DEBUG}function ih(){return process.env.DEBUG}function ch(e){e.inspectOpts={};let t=Object.keys(Ie.inspectOpts);for(let n=0;n<t.length;n++)e.inspectOpts[t[n]]=Ie.inspectOpts[t[n]]}Xr.exports=Ia()(Ie);var{formatters:Li}=Xr.exports;Li.o=function(e){return this.inspectOpts.colors=this.useColors,Yr.inspect(e,this.inspectOpts).split(` `).map(t=>t.trim()).join(" ")};Li.O=function(e){return this.inspectOpts.colors=this.useColors,Yr.inspect(e,this.inspectOpts)}});var Oi=ur((SA,Ea)=>{typeof process>"u"||process.type==="renderer"||process.browser===!0||process.__nwjs?Ea.exports=Ui():Ea.exports=Ni()});import{readFileSync as lA}from"fs";import{dirname as mA,join as pA}from"path";import{fileURLToPath as uA}from"url";import{ZodError as dS}from"zod";import Qn from"chalk";var Ac=Hg(Oi(),1);import{ofetch as $h}from"ofetch";function ji(e){return{all:e=e||new Map,on:function(t,n){var r=e.get(t);r?r.push(n):e.set(t,[n])},off:function(t,n){var r=e.get(t);r&&(n?r.splice(r.indexOf(n)>>>0,1):e.set(t,[]))},emit:function(t,n){var r=e.get(t);r&&r.slice().map(function(o){o(n)}),(r=e.get("*"))&&r.slice().map(function(o){o(t,n)})}}}import{z as Ee}from"zod";import{z as me}from"zod";import{z as qt}from"zod";import{z as K}from"zod";import{z as w}from"zod";import{z as R}from"zod";import{z as Dt}from"zod";import{anvil as oc,base as ac,mainnet as sc}from"viem/chains";import{z as T}from"zod";import{z as Ce}from"zod";import{z as Ae}from"zod";import{z as An}from"zod";import{z as Rn}from"zod";import{z as P}from"zod";import{z as ee}from"zod";import{z as F}from"zod";import Qy from"crypto";import{z as ct}from"zod";import{z as ft}from"zod";import{z as Te}from"zod";import{z as De}from"zod";import{z as Me}from"zod";import{z as Dv}from"zod";import{z as Pn}from"zod";import{z as rt}from"zod";import{z as ic}from"zod";import{z as kt}from"zod";import{z as It}from"zod";import{z as Ge}from"zod";import{z as cc}from"zod";import{z as vr}from"zod";import{z as Un}from"zod";import{z as ln}from"zod";import{z as se}from"zod";import{z as kb}from"zod";import{z as Eb}from"zod";import{z as re}from"zod";import{z as _t}from"zod";import{z as Fb}from"zod";import{z as be}from"zod";import{z as N}from"zod";import{z as Mt}from"zod";import{z as La}from"zod";import{z as Fe}from"zod";import{z as yl}from"zod";import{z as Ct}from"zod";import{z as Xe}from"zod";import{z as Gt}from"zod";import{z as Na}from"zod";import{z as Va}from"zod";import{z as cn}from"zod";import{z as $e}from"zod";import{z as pe}from"zod";import{z as H}from"zod";import{z as de}from"zod";import{z as Y}from"zod";import{z as _e}from"zod";import{createPublicClient as pc,createWalletClient as BC,http as Oa,parseEventLogs as WC,parseEther as uc}from"viem";import{privateKeyToAccount as JC}from"viem/accounts";import{x25519 as Aa}from"@noble/curves/ed25519";function lh(e){return e=e.startsWith("0x")?e.slice(2):e,new Uint8Array(e.match(/.{1,2}/g)?.map(t=>parseInt(t,16))??[])}function mh(e){return Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("")}async function je(e,t){let n=JSON.stringify({env:e}),r=Aa.utils.randomPrivateKey(),o=Aa.getPublicKey(r),a=lh(t),s=Aa.getSharedSecret(r,a),i=await crypto.subtle.importKey("raw",new Uint8Array(s),{name:"AES-GCM",length:256},!0,["encrypt"]),c=crypto.getRandomValues(new Uint8Array(12)),l=await crypto.subtle.encrypt({name:"AES-GCM",iv:c},i,new TextEncoder().encode(n)),p=new Uint8Array(o.length+c.length+l.byteLength);return p.set(o),p.set(c,o.length),p.set(new Uint8Array(l),o.length+c.length),mh(p)}import{keccak256 as YC,toBytes as to,toHex as XC}from"viem";import{isHex as dc}from"viem";import{createPublicClient as nP,createWalletClient as rP,http as oP,custom as aP}from"viem";import{privateKeyToAccount as iP}from"viem/accounts";import{z as ge}from"zod";import{createPublicClient as fc,createWalletClient as cw,http as ja,parseEventLogs as lw,parseEther as gc}from"viem";import{privateKeyToAccount as mw}from"viem/accounts";import{z as he}from"zod";import{createPublicClient as hc,createWalletClient as gw,http as yc,parseEther as vc}from"viem";import{privateKeyToAccount as hw}from"viem/accounts";import{z as ye}from"zod";import{createPublicClient as bc,createWalletClient as Cw,http as Cc,parseEther as wc}from"viem";import{privateKeyToAccount as ww}from"viem/accounts";import{z as ve}from"zod";import{createPublicClient as _c,createWalletClient as Iw,http as Sc,parseEther as kc}from"viem";import{privateKeyToAccount as Ew}from"viem/accounts";import{z as xn}from"zod";import{createPublicClient as xw,http as $w}from"viem";import{createPublicClient as kP,http as IP}from"viem";import{createPublicClient as AP,http as RP}from"viem";import{createPublicClient as Tw,http as Dw}from"viem";import{z as $n}from"zod";import{z as gt}from"zod";import{z as Fw}from"zod";import{z as Tn}from"zod";import{z as W}from"zod";import{z as oo}from"zod";import{z as Ln}from"zod";import{z as nt}from"zod";import{z as Se}from"zod";import{z as oe}from"zod";import{z as gr}from"zod";import{z as xe}from"zod";import{z as Dn}from"zod";import{z as Ue}from"zod";import{z as tt}from"zod";import{z as Ic}from"zod";import{z as br}from"zod";import{z as wt}from"zod";import{z as ke}from"zod";import{z as no}from"zod";import{z as ro}from"zod";import{z as qe}from"zod";import{z as q}from"zod";function ph(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ra(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function dr(e,...t){if(!ph(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Pa(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Fi(e,t){dr(e);let n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function Vi(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function xa(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}var uh=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function dh(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function fh(e){for(let t=0;t<e.length;t++)e[t]=dh(e[t]);return e}var $a=uh?e=>e:fh;function gh(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Ta(e){return typeof e=="string"&&(e=gh(e)),dr(e),e}var Zr=class{};function Hi(e){let t=r=>e().update(Ta(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}var Qr=BigInt(4294967295),zi=BigInt(32);function hh(e,t=!1){return t?{h:Number(e&Qr),l:Number(e>>zi&Qr)}:{h:Number(e>>zi&Qr)|0,l:Number(e&Qr)|0}}function Ki(e,t=!1){let n=e.length,r=new Uint32Array(n),o=new Uint32Array(n);for(let a=0;a<n;a++){let{h:s,l:i}=hh(e[a],t);[r[a],o[a]]=[s,i]}return[r,o]}var qi=(e,t,n)=>e<<n|t>>>32-n,Gi=(e,t,n)=>t<<n|e>>>32-n,Bi=(e,t,n)=>t<<n-32|e>>>64-n,Wi=(e,t,n)=>e<<n-32|t>>>64-n;var yh=BigInt(0),fr=BigInt(1),vh=BigInt(2),bh=BigInt(7),Ch=BigInt(256),wh=BigInt(113),Xi=[],Zi=[],Qi=[];for(let e=0,t=fr,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],Xi.push(2*(5*r+n)),Zi.push((e+1)*(e+2)/2%64);let o=yh;for(let a=0;a<7;a++)t=(t<<fr^(t>>bh)*wh)%Ch,t&vh&&(o^=fr<<(fr<<BigInt(a))-fr);Qi.push(o)}var ec=Ki(Qi,!0),_h=ec[0],Sh=ec[1],Ji=(e,t,n)=>n>32?Bi(e,t,n):qi(e,t,n),Yi=(e,t,n)=>n>32?Wi(e,t,n):Gi(e,t,n);function kh(e,t=24){let n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let s=0;s<10;s++)n[s]=e[s]^e[s+10]^e[s+20]^e[s+30]^e[s+40];for(let s=0;s<10;s+=2){let i=(s+8)%10,c=(s+2)%10,l=n[c],p=n[c+1],u=Ji(l,p,1)^n[i],f=Yi(l,p,1)^n[i+1];for(let d=0;d<50;d+=10)e[s+d]^=u,e[s+d+1]^=f}let o=e[2],a=e[3];for(let s=0;s<24;s++){let i=Zi[s],c=Ji(o,a,i),l=Yi(o,a,i),p=Xi[s];o=e[p],a=e[p+1],e[p]=c,e[p+1]=l}for(let s=0;s<50;s+=10){for(let i=0;i<10;i++)n[i]=e[s+i];for(let i=0;i<10;i++)e[s+i]^=~n[(i+2)%10]&n[(i+4)%10]}e[0]^=_h[r],e[1]^=Sh[r]}xa(n)}var Da=class e extends Zr{constructor(t,n,r,o=!1,a=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=t,this.suffix=n,this.outputLen=r,this.enableXOF=o,this.rounds=a,Ra(r),!(0<t&&t<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=Vi(this.state)}clone(){return this._cloneInto()}keccak(){$a(this.state32),kh(this.state32,this.rounds),$a(this.state32),this.posOut=0,this.pos=0}update(t){Pa(this),t=Ta(t),dr(t);let{blockLen:n,state:r}=this,o=t.length;for(let a=0;a<o;){let s=Math.min(n-this.pos,o-a);for(let i=0;i<s;i++)r[this.pos++]^=t[a++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:t,suffix:n,pos:r,blockLen:o}=this;t[r]^=n,(n&128)!==0&&r===o-1&&this.keccak(),t[o-1]^=128,this.keccak()}writeInto(t){Pa(this,!1),dr(t),this.finish();let n=this.state,{blockLen:r}=this;for(let o=0,a=t.length;o<a;){this.posOut>=r&&this.keccak();let s=Math.min(r-this.posOut,a-o);t.set(n.subarray(this.posOut,this.posOut+s),o),this.posOut+=s,o+=s}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return Ra(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(Fi(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,xa(this.state)}_cloneInto(t){let{blockLen:n,suffix:r,outputLen:o,rounds:a,enableXOF:s}=this;return t||(t=new e(n,r,o,s,a)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=a,t.suffix=r,t.outputLen=o,t.enableXOF=s,t.destroyed=this.destroyed,t}},Ih=(e,t,n)=>Hi(()=>new Da(t,e,n));var tc=Ih(1,136,256/8);import{secp256k1 as Eh}from"@noble/curves/secp256k1";function Ah(e){if((e.startsWith("0x")||e.startsWith("0X"))&&(e=e.slice(2)),e.length%2!==0||!/^[0-9a-fA-F]*$/.test(e))return null;let t=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)t[n/2]=parseInt(e.substr(n,2),16);return t}function Rh(e){return Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}function Ph(...e){let t=e.reduce((o,a)=>o+a.length,0),n=new Uint8Array(t),r=0;for(let o of e)n.set(o,r),r+=o.length;return n}function xh(e,t){try{let n=t.slice(0,64),r=t[64],o=Eh.Signature.fromCompact(n).addRecoveryBit(r).recoverPublicKey(e);return"0x"+Rh(o.toRawBytes(!0))}catch(n){return console.error("signature verification failed:",n),null}}function Ma(e,t,n){if(t.length!==65)return null;let r=Ah(n);if(!r)return null;let o=new TextEncoder().encode("dstack-env-encrypt-pubkey"),a=new TextEncoder().encode(":"),s=Ph(o,a,r,e);return xh(tc(s),t)}var Th=Ee.object({detail:Ee.union([Ee.string(),Ee.array(Ee.object({msg:Ee.string(),type:Ee.string().optional(),ctx:Ee.record(Ee.unknown()).optional(),loc:Ee.array(Ee.union([Ee.string(),Ee.number()])).optional(),input:Ee.unknown().optional()}).passthrough()),Ee.record(Ee.unknown())]).optional(),type:Ee.string().optional(),code:Ee.string().optional()});function Dh(e){if(!e||typeof e!="object")return;let t=e.request_id;return typeof t=="string"?t:void 0}function Mh(e){return e?.headers?.get("X-Request-ID")??void 0}function nc(e){if(typeof e!="string")return;let t=e.trim().toUpperCase();return t.length>0?t:void 0}var lt=class extends Error{constructor(e,t){super(e),this.name=this.constructor.name,this.status=t.status,this.statusText=t.statusText,this.detail=t.detail,this.requestId=t.requestId,this.request=t.request,this.requestMethod=t.requestMethod,this.data=t.data,this.code=t.code,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}},yr=class hr extends lt{constructor(t,n){super(t,{status:n?.status??0,statusText:n?.statusText??"Unknown Error",detail:n?.detail||t,requestId:n?.requestId,request:n?.request,requestMethod:n?.requestMethod,data:n?.data,code:n?.code}),this.name="RequestError",this.isRequestError=!0,this.data=n?.data,this.request=n?.request,this.requestMethod=n?.requestMethod,this.response=n?.response,this.type=n?.type}static fromFetchError(t){let n=Dh(t.data),r=Mh(t.response),o=n??r,a=nc(t.options?.method),s=Th.safeParse(t.data);if(s.success){let c=s.data.detail??(t.data&&typeof t.data=="object"&&"error_code"in t.data?t.data:void 0);return new hr(t.message,{status:t.status??void 0,statusText:t.statusText??void 0,data:t.data,request:t.request??void 0,requestMethod:a,response:t.response??void 0,detail:c,code:s.data.code??void 0,type:s.data.type??void 0,requestId:o})}if(t.cause?.name==="TimeoutError"||t.message?.includes("[TimeoutError]")){let c="Request timed out. The server did not respond in time.";return new hr(c,{status:0,statusText:"Request Timeout",data:t.data,request:t.request??void 0,requestMethod:a,response:t.response??void 0,detail:c,code:"TIMEOUT",requestId:o})}return new hr(t.message,{status:t.status??void 0,statusText:t.statusText??void 0,data:t.data,request:t.request??void 0,requestMethod:a,response:t.response??void 0,detail:t.data?.detail||t.message||"Unknown API error",code:t.status?.toString()??void 0,requestId:o})}static fromError(t,n,r){return new hr(t.message,{request:n??void 0,requestMethod:nc(r),detail:t.message})}},Rc=class extends lt{constructor(e,t){super(e,t),this.isValidationError=!0,this.validationErrors=t.validationErrors}},Uh=class extends lt{constructor(){super(...arguments),this.isAuthError=!0}},ao=class extends lt{constructor(){super(...arguments),this.isBusinessError=!0}},Lh=class extends lt{constructor(){super(...arguments),this.isServerError=!0}},Nh=class extends lt{constructor(){super(...arguments),this.isUnknownError=!0}};function Oh(e){if(!e||!Array.isArray(e))return"unknown";let t=e.filter(n=>typeof n=="string"?!["body","query","path","header"].includes(n):!0);return t.length>0?t.join("."):"unknown"}function Pc(e){if(!Array.isArray(e))return{errors:[],message:typeof e=="string"?e:"Validation error"};let t=e.map((o,a)=>{let s=Oh(o.loc),i=s;return s==="unknown"&&o.type&&(i=o.type==="missing"?"required field":o.type),{field:i,message:o.msg,type:o.type,context:o.ctx}}),n=t.length,r=n===1?`Validation failed: ${t[0].message}`:`Validation failed (${n} issue${n>1?"s":""})`;return{errors:t,message:r}}function jh(e){return e===422?"validation":e===401||e===403?"auth":e>=400&&e<500?"business":e>=500?"server":"unknown"}function Fh(e,t,n){if(e===422&&Array.isArray(t)){let{message:r}=Pc(t);return r}if(typeof t=="string")return t;if(t&&typeof t=="object"&&"message"in t){let r=t.message;if(typeof r=="string")return r}return n}function Vh(e){let t=e.status??0,n=e.statusText??"Unknown Error",r=e.detail,o=Kh(r);if(o)return new yt(o.message,{status:t,statusText:n,detail:r,requestId:o.request_id??e.requestId,request:e.request,requestMethod:e.requestMethod,data:e.data,errorCode:o.error_code,structuredDetails:o.details,suggestions:o.suggestions,links:o.links});let a=jh(t),s=Fh(t,r,e.message),i={status:t,statusText:n,detail:r,requestId:e.requestId,request:e.request,requestMethod:e.requestMethod,data:e.data,code:e.code};if(a==="validation"&&Array.isArray(r)){let{errors:c}=Pc(r);return new Rc(s,{...i,validationErrors:c})}return a==="auth"?new Uh(s,i):a==="business"?new ao(s,i):a==="server"?new Lh(s,i):new Nh(s,i)}function Hh(e,t){let{numbered:n=!0,indent:r=2,showFields:o=!0}=t??{},a=" ".repeat(r);return e.map((s,i)=>{let c=n?`${i+1}. `:"\u2022 ",l=o?`${s.field}: `:"";return`${a}${c}${l}${s.message}`}).join(` `)}function so(e,t){let{showFields:n=!0,showType:r=!1}=t??{},o=[];return r&&o.push(`[${e.constructor.name.toUpperCase()}]`),o.push(e.message),e instanceof Rc&&e.validationErrors.length>0&&(o.push(""),o.push(Hh(e.validationErrors,{showFields:n}))),o.join(` `)}function zh(e){if(e==null)return"";if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e)}catch{return String(e)}}var yt=class extends ao{constructor(e,t){super(e,t),this.isResourceError=!0,this.errorCode=t.errorCode,this.structuredDetails=t.structuredDetails,this.suggestions=t.suggestions,this.links=t.links}};function Kh(e){if(!e||typeof e!="object")return null;let t=e;return t.error_code&&typeof t.error_code=="string"&&t.message&&typeof t.message=="string"?{error_code:t.error_code,message:t.message,request_id:typeof t.request_id=="string"?t.request_id:void 0,details:t.details,suggestions:t.suggestions,links:t.links}:null}function Bt(e,t){let{showErrorCode:n=!0,showSuggestions:r=!0,showLinks:o=!0}=t??{},a=[];return n&&e.errorCode?a.push(`Error [${e.errorCode}]: ${e.message}`):a.push(e.message),e.requestId&&a.push(`Request ID: ${e.requestId}`),e.structuredDetails&&e.structuredDetails.length>0&&(a.push(""),a.push("Details:"),e.structuredDetails.forEach(s=>{s.message?a.push(` - ${s.message}`):s.field&&s.value!==void 0&&a.push(` - ${s.field}: ${zh(s.value)}`)})),r&&e.suggestions&&e.suggestions.length>0&&(a.push(""),a.push("Suggestions:"),e.suggestions.forEach(s=>{a.push(` - ${s}`)})),o&&e.links&&e.links.length>0&&(a.push(""),a.push("Learn more:"),e.links.forEach(s=>{a.push(` - ${s.label}: ${s.url}`)})),a.join(` `)}var mn=["2025-10-28","2026-01-21","2026-05-22","2026-06-23"],qh="2026-06-23",En=(0,Ac.default)("phala::api-client");function Gh(e){return Object.entries(e).map(([t,n])=>` -H "${t}: ${n}"`).join(` `)}function Bh(e){return e?` -d '${(typeof e=="string"?e:JSON.stringify(e,null,2)).replace(/'/g,"\\'")}'`:""}function rc(e,t,n,r){let o=[];n.forEach((i,c)=>{o.push(`${c}: ${i}`)});let a=o.join(` `),s=typeof r=="string"?r:JSON.stringify(r,null,2);return[`< HTTP/1.1 ${e} ${t}`,a?`< ${a.replace(/\n/g,` < `)}`:"","",s].filter(Boolean).join(` `)}var Wh=class xc{constructor(t={}){this.emitter=ji();let n=t.apiKey||process?.env?.PHALA_CLOUD_API_KEY,r=t.baseURL||process?.env?.PHALA_CLOUD_API_PREFIX||"https://cloud-api.phala.com/api/v1",o=t.version&&mn.includes(t.version)?t.version:qh;this.config={...t,apiKey:n,baseURL:r,version:o};let{apiKey:a,baseURL:s,timeout:i,headers:c,useCookieAuth:l,onResponseError:p,...u}=this.config,f={"X-Phala-Version":o,"Content-Type":"application/json"};c&&typeof c=="object"&&Object.entries(c).forEach(([d,h])=>{typeof h=="string"&&(f[d]=h)}),!l&&a&&(f["X-API-Key"]=a),this.fetchInstance=$h.create({baseURL:s,timeout:i||6e4,headers:f,...l?{credentials:"include"}:{},...u,onRequest({request:d,options:h}){if(h.body instanceof FormData){let g=h.headers;g instanceof Headers?g.delete("content-type"):g&&typeof g=="object"&&!Array.isArray(g)&&(delete g["Content-Type"],delete g["content-type"])}if(En.enabled){let g=h.method||"GET",y=typeof d=="string"?d:d.url,k=y.startsWith("http")?y:`${s}${y}`,_={};h.headers&&typeof h.headers=="object"&&Object.entries(h.headers).forEach(([S,b])=>{typeof b=="string"&&(_[S]=b)});let E=[`> curl -X ${g} "${k}"`,Gh(_),h.body?Bh(h.body):""].filter(Boolean).join(` `);En(` === REQUEST === %s `,E)}},onResponse({request:d,response:h,options:g}){if(En.enabled){let y=g.method||"GET",k=typeof d=="string"?d:d.url;En(` === RESPONSE [%s %s] (%dms) === %s `,y,k,h.headers.get("x-response-time")||"?",rc(h.status,h.statusText,h.headers,h._data))}},onResponseError:({request:d,response:h,options:g})=>{if(En.enabled){console.warn(`HTTP ${h.status}: ${h.url}`);let y=g.method||"GET",k=typeof d=="string"?d:d.url;En(` === ERROR RESPONSE [%s %s] === %s `,y,k,rc(h.status,h.statusText,h.headers,h._data))}p&&p({request:d,response:h,options:g})}})}get raw(){return this.fetchInstance}on(t,n){this.emitter.on(t,n)}off(t,n){this.emitter.off(t,n)}once(t,n){let r=o=>{n(o),this.emitter.off(t,r)};this.emitter.on(t,r)}async request(t,n){try{let r=n?.method||"GET";return await this.fetchInstance(t,{...n,method:r})}catch(r){let o=this.convertToRequestError(r);throw this.emitError(o)}}async requestFull(t,n){try{let r=n?.method||"GET",o=await this.fetchInstance.raw(t,{...n,method:r,ignoreResponseError:!0});return{status:o.status,statusText:o.statusText,headers:o.headers,data:o._data,ok:o.ok}}catch(r){let o=this.convertToRequestError(r);throw this.emitError(o)}}async get(t,n){try{return await this.fetchInstance(t,{...n,method:"GET"})}catch(r){let o=this.convertToRequestError(r);throw this.emitError(o)}}buildRequestOptions(t,n,r){let o={...r,method:t,body:n};if(n instanceof FormData){let a=o.headers;o.headers={...a,"Content-Type":""}}return o}async post(t,n,r){try{return await this.fetchInstance(t,this.buildRequestOptions("POST",n,r))}catch(o){let a=this.convertToRequestError(o);throw this.emitError(a)}}async put(t,n,r){try{return await this.fetchInstance(t,this.buildRequestOptions("PUT",n,r))}catch(o){let a=this.convertToRequestError(o);throw this.emitError(a)}}async patch(t,n,r){try{return await this.fetchInstance(t,this.buildRequestOptions("PATCH",n,r))}catch(o){let a=this.convertToRequestError(o);throw this.emitError(a)}}async delete(t,n){try{return await this.fetchInstance(t,{...n,method:"DELETE"})}catch(r){let o=this.convertToRequestError(r);throw this.emitError(o)}}convertToRequestError(t){return t&&typeof t=="object"&&"data"in t?yr.fromFetchError(t):t instanceof Error?yr.fromError(t):new yr("Unknown error occurred",{detail:"Unknown error occurred"})}emitError(t){let n=Vh(t);return this.emitter.emit("error",n),n}async safeRequest(t){try{return{success:!0,data:await t()}}catch(n){if(n instanceof lt)return{success:!1,error:n};let r=this.convertToRequestError(n);return this.emitError(r),{success:!1,error:r}}}async safeGet(t,n){return this.safeRequest(()=>this.get(t,n))}async safePost(t,n,r){return this.safeRequest(()=>this.post(t,n,r))}async safePut(t,n,r){return this.safeRequest(()=>this.put(t,n,r))}async safePatch(t,n,r){return this.safeRequest(()=>this.patch(t,n,r))}async safeDelete(t,n){return this.safeRequest(()=>this.delete(t,n))}async safeRequestMethod(t,n){return this.safeRequest(()=>this.request(t,n))}async safeRequestFull(t,n){return this.safeRequest(()=>this.requestFull(t,n))}withVersion(t){return new xc({...this.config,version:t})}extend(t){let n=typeof t=="function"?t(this):t,r=Object.create(this);for(let[o,a]of Object.entries(n))typeof a=="function"&&(r[o]=(...s)=>a(this,...s));return r}};function Jh(e={}){return new Wh(e)}var Yh=me.object({username:me.string(),email:me.string(),role:me.enum(["admin","user"]),avatar:me.string(),email_verified:me.boolean(),totp_enabled:me.boolean(),has_backup_codes:me.boolean(),flag_has_password:me.boolean()}).passthrough(),Xh=me.object({id:me.string(),name:me.string(),slug:me.string().nullable(),tier:me.string(),role:me.string(),avatar:me.string().nullable().optional()}).passthrough(),Zh=me.object({balance:me.string().or(me.number()),granted_balance:me.string().or(me.number()),is_post_paid:me.boolean(),outstanding_amount:me.string().or(me.number()).nullable()}).passthrough(),Qh=me.object({user:Yh,workspace:Xh,credits:Zh}).passthrough(),ey=qt.object({username:qt.string(),email:qt.string(),credits:qt.number(),granted_credits:qt.number(),avatar:qt.string(),team_name:qt.string(),team_tier:qt.string()}).passthrough();function ty(e){return e==="2025-10-28"?ey:Qh}async function $c(e,t){let n=await e.get("/auth/me");return t?.schema===!1?n:(t?.schema||ty(e.config.version)).parse(n)}async function Ve(e,t){try{return{success:!0,data:await $c(e,t)}}catch(n){return n&&typeof n=="object"&&("status"in n||"issues"in n)?{success:!1,error:n}:{success:!1,error:{name:"Error",message:n instanceof Error?n.message:String(n)}}}}var At={[sc.id]:sc,[ac.id]:ac,[oc.id]:oc},ny=Dt.object({id:Dt.string(),slug:Dt.string().nullable(),url:Dt.string(),version:Dt.string(),chain_id:Dt.number().nullable(),kms_contract_address:Dt.string().nullable().transform(e=>e),gateway_app_id:Dt.string().nullable().transform(e=>e),k256_pubkey:Dt.string().nullable().optional()}).passthrough(),mt=ny.transform(e=>{if(e.chain_id!=null){let t=At[e.chain_id];if(t)return{...e,chain:t}}return e}),Tc=R.union([R.number(),R.string()]),ry=R.object({id:R.string(),name:R.string(),status:R.string(),uptime:R.string(),app_url:R.string().nullable(),app_id:R.string(),instance_id:R.string().nullable(),configuration:R.any().optional(),exited_at:R.string().nullable(),boot_progress:R.string().nullable(),boot_error:R.string().nullable(),shutdown_progress:R.string().nullable(),image_version:R.string().nullable()}),oy=R.object({id:Tc,username:R.string()}),Dc=R.object({id:R.number(),name:R.string(),region_identifier:R.string().nullable().optional()}),Ha=R.object({vcpu:R.number(),memory:R.number(),disk_size:R.number(),gpu_count:R.number().default(0)}),za=R.object({app:R.string(),instance:R.string()}),Mc=R.object({hosted:ry,name:R.string(),managed_user:oy.nullable(),node:Dc.nullable(),listed:R.boolean().default(!1),status:R.string(),in_progress:R.boolean().default(!1),dapp_dashboard_url:R.string().nullable(),syslog_endpoint:R.string().nullable(),allow_upgrade:R.boolean().default(!1),project_id:R.string().nullable(),project_type:R.string().nullable(),billing_period:R.string().nullable(),kms_info:mt.nullable(),vcpu:R.number().nullable(),memory:R.number().nullable(),disk_size:R.number().nullable(),gateway_domain:R.string().nullable(),public_urls:R.array(za),machine_info:Ha.nullable().optional(),updated_at:R.string().nullable().optional()}),Uc=R.object({id:Tc,name:R.string(),status:R.string(),in_progress:R.boolean().optional().default(!1),teepod_id:R.number().nullable(),teepod:Dc.optional().nullable(),app_id:R.string(),vm_uuid:R.string().nullable(),instance_id:R.string().nullable(),vcpu:R.number(),memory:R.number(),disk_size:R.number(),base_image:R.string().nullable(),encrypted_env_pubkey:R.string().nullable(),listed:R.boolean().optional().default(!1),project_id:R.string().optional().nullable(),project_type:R.string().optional().nullable(),instance_type:R.string().optional().nullable(),public_sysinfo:R.boolean().optional().default(!1),public_logs:R.boolean().optional().default(!1),dapp_dashboard_url:R.string().optional().nullable(),syslog_endpoint:R.string().optional().nullable(),kms_info:mt.optional().nullable(),contract_address:R.string().optional().nullable(),deployer_address:R.string().optional().nullable(),scheduled_delete_at:R.string().optional().nullable(),public_urls:R.array(za).optional().default([]),gateway_domain:R.string().optional().nullable(),machine_info:Ha.optional().nullable(),updated_at:R.string().optional().nullable()}),ay=R.object({items:R.array(Mc),total:R.number(),page:R.number(),page_size:R.number(),pages:R.number()}),sy=w.enum(["skip","hourly","monthly"]),iy=w.enum(["phala","ethereum","base","legacy"]),Ka=w.object({object_type:w.literal("user"),id:w.string().nullable().optional(),username:w.string().nullable().optional(),avatar_url:w.string().nullable().optional()}),qa=w.object({object_type:w.literal("workspace"),id:w.string(),name:w.string(),slug:w.string().nullable().optional(),avatar_url:w.string().nullable().optional()}),cy=w.object({instance_type:w.string().nullable().optional(),vcpu:w.number().int().nullable().optional(),memory_in_gb:w.number().nullable().optional(),disk_in_gb:w.number().int().nullable().optional(),gpus:w.number().int().nullable().optional(),compute_billing_price:w.string().nullable().optional(),billing_period:sy.nullable().optional()}),ly=w.object({total:w.string().nullable().optional(),compute:w.string().nullable().optional(),disk:w.string().nullable().optional()}),my=w.object({order_id:w.string(),status:w.string(),pricing_plan:w.string().nullable().optional(),commitment_days:w.number().int().nullable().optional(),agreed_hourly_rate:w.string().nullable().optional(),hourly_billing_start_time:w.string().nullable().optional(),activated_at:w.string().nullable().optional(),completed_at:w.string().nullable().optional(),cancelled_at:w.string().nullable().optional(),decoupled_at:w.string().nullable().optional(),sku_code:w.string().nullable().optional(),sku_display_name:w.string().nullable().optional()}),py=w.object({name:w.string().nullable().optional(),version:w.string().nullable().optional(),is_dev:w.boolean().nullable().optional(),os_image_hash:w.string().nullable().optional()}),uy=w.object({chain_id:w.number().int().nullable().optional(),dstack_kms_address:w.string().nullable().optional(),dstack_app_address:w.string().nullable().optional(),deployer_address:w.string().nullable().optional(),rpc_endpoint:w.string().nullable().optional(),encrypted_env_pubkey:w.string().nullable().optional()}),dy=uy.transform(e=>{if(e.chain_id!=null){let t=At[e.chain_id];if(t)return{...e,chain:t}}return e}),fy=w.object({target:w.string().nullable().optional(),started_at:w.string().nullable().optional(),correlation_id:w.string().nullable().optional()}),gy=w.object({base_domain:w.string().nullable().optional(),cname:w.string().nullable().optional()}),hy=w.object({serial:w.string().nullable().optional(),stdout:w.string().nullable().optional(),stderr:w.string().nullable().optional(),container_log_base:w.string().nullable().optional()}),Lc=w.object({device_id:w.string(),algorithm_version:w.string(),enabled:w.boolean()}),Nc=w.object({object_type:w.literal("node"),id:w.number().int().nullable().optional(),name:w.string().nullable().optional(),region:w.string().nullable().optional(),device_id:w.string().nullable().optional(),device_ids:w.array(Lc).default([]),ppid:w.string().nullable().optional(),status:w.string().nullable().optional(),version:w.string().nullable().optional()});var Nn=w.object({id:w.string(),name:w.string(),app_id:w.string().nullable().optional(),vm_uuid:w.string().nullable().optional(),instance_id:w.string().nullable().optional(),resource:cy,node_info:Nc.nullable().optional(),os:py.nullable().optional(),kms_type:iy.nullable().optional(),kms_info:dy.nullable().optional(),status:w.string(),in_progress:w.boolean().optional().default(!1),progress:fy.nullable().optional(),compose_hash:w.string().nullable().optional(),docker_compose_hash:w.string().nullable().optional(),pre_launch_script_hash:w.string().nullable().optional(),gateway:gy,logs:hy.optional().default({}),services:w.array(w.record(w.any())).optional().default([]),endpoints:w.array(za).nullable().optional(),public_logs:w.boolean().optional(),public_sysinfo:w.boolean().optional(),public_tcbinfo:w.boolean().optional(),gateway_enabled:w.boolean().optional(),secure_time:w.boolean().optional(),listed:w.boolean().optional().default(!1),storage_fs:w.string().optional(),workspace:qa.nullable().optional(),creator:Ka.nullable().optional(),created_at:w.string().nullable().optional(),deleted_at:w.string().nullable().optional(),project_type:w.string().nullable().optional(),hourly_rate:ly.nullable().optional(),billing_interval:w.string().nullable().optional(),gpu_rental_order:my.nullable().optional()}),Cr=Nn.extend({id:w.string()}),yy=Nn.extend({compose_file:w.union([w.record(w.any()),w.string()]).nullable().optional()}),vy=Cr.extend({compose_file:w.union([w.record(w.any()),w.string()]).nullable().optional()}),Oc=w.object({items:w.array(Nn),total:w.number(),page:w.number(),page_size:w.number(),pages:w.number()}),by=Oc.extend({items:w.array(Cr)});function jc(e){if(e?.schema!==void 0&&e?.schema!==!1&&(typeof e.schema!="object"||e.schema===null||!("parse"in e.schema)||typeof e.schema.parse!="function"))throw new Error("Invalid schema: must be a Zod schema object, false, or undefined")}function Fc(e){if(e?.schema!==void 0&&e?.schema!==!1&&(typeof e.schema!="object"||e.schema===null||!("parse"in e.schema)||typeof e.schema.parse!="function"))return{success:!1,error:{name:"ZodError",message:"Invalid schema: must be a Zod schema object, false, or undefined",issues:[{code:"invalid_type",expected:"object",received:typeof e.schema,path:["schema"],message:"Invalid schema: must be a Zod schema object, false, or undefined"}]}}}function Vc(e,t){function n(s,i){return r(s,i)}async function r(s,i){jc(i);let c=await t(s);return i?.schema===!1?c:(i?.schema||e).parse(c)}function o(s,i){return a(s,i)}async function a(s,i){let c=Fc(i);if(c)return c;let l=await(async()=>{try{return{success:!0,data:await t(s)}}catch(u){return u&&typeof u=="object"&&"status"in u?{success:!1,error:u}:u&&typeof u=="object"&&"issues"in u?{success:!1,error:u}:{success:!1,error:{name:"Error",message:u instanceof Error?u.message:String(u)}}}})();return l.success?i?.schema===!1?{success:!0,data:l.data}:(i?.schema||e).safeParse(l.data):l}return{action:n,safeAction:o}}function L(e,t){function n(s,...i){let[c,l]=i;return r(s,c,l)}async function r(s,i,c){jc(c);let l=await t(s,i);return c?.schema===!1?l:(c?.schema||e).parse(l)}function o(s,...i){let[c,l]=i;return a(s,c,l)}async function a(s,i,c){let l=Fc(c);if(l)return l;let p=await(async()=>{try{return{success:!0,data:await t(s,i)}}catch(f){return f&&typeof f=="object"&&"status"in f?{success:!1,error:f}:f&&typeof f=="object"&&"issues"in f?{success:!1,error:f}:{success:!1,error:{name:"Error",message:f instanceof Error?f.message:String(f)}}}})();return p.success?c?.schema===!1?{success:!0,data:p.data}:(c?.schema||e).safeParse(p.data):p}return{action:n,safeAction:o}}var Cy=K.object({name:K.string(),is_dev:K.boolean(),version:K.union([K.tuple([K.number(),K.number(),K.number()]),K.tuple([K.number(),K.number(),K.number(),K.number()])]),os_image_hash:K.string().nullable().optional()}).passthrough(),Hc=K.object({teepod_id:K.number(),name:K.string(),listed:K.boolean(),resource_score:K.number(),remaining_vcpu:K.number(),remaining_memory:K.number(),remaining_cvm_slots:K.number(),images:K.array(Cy),support_onchain_kms:K.boolean().optional(),fmspc:K.string().nullable().optional(),device_id:K.string().nullable().optional(),device_ids:K.array(Lc).default([]),region_identifier:K.string().nullable().optional(),default_kms:K.string().nullable().optional(),kms_list:K.array(K.string()).default([])}).passthrough(),zc=K.object({max_instances:K.number().nullable().optional(),max_vcpu:K.number().nullable().optional(),max_memory:K.number().nullable().optional(),max_disk:K.number().nullable().optional()}).passthrough(),wy=K.object({tier:K.string(),capacity:zc,nodes:K.array(Hc),kms_list:K.array(mt)}).passthrough(),{action:_y,safeAction:Ut}=Vc(wy,async e=>await e.get("/teepods/available")),On=T.union([T.number(),T.string()]),jn=T.string(),Sy=T.object({has_reserved_gpus:T.boolean(),reserved_gpu_count:T.number(),has_public_gpus:T.boolean(),public_gpu_count:T.number()}).passthrough(),Kc=T.object({id:On,slug:T.string().nullable().optional(),url:T.string(),version:T.string().nullable().optional(),kms_type:T.string(),chain_id:T.number().nullable().optional(),kms_contract_id:On.nullable().optional(),kms_contract_address:T.string().nullable().optional(),gateway_app_id:T.string().nullable().optional(),supported_os_images:T.array(T.string()).default([])}).passthrough(),qc=T.object({teepod_id:T.number(),kms_id:On,kms_type:T.string(),kms_contract_id:On.nullable().optional(),kms_contract_address:T.string().nullable().optional(),supported_os_images:T.array(T.string()).default([])}).passthrough(),Gc=T.object({id:On,teepod_id:T.number().nullable().optional(),kms_contract_id:On,rpc_url:T.string().nullable().optional(),domain_suffix:T.string().nullable().optional(),enabled:T.boolean()}).passthrough(),ky=Kc.extend({id:jn,kms_contract_id:jn.nullable().optional()}),Iy=qc.extend({kms_id:jn,kms_contract_id:jn.nullable().optional()}),Ey=Gc.extend({id:jn,kms_contract_id:jn}),Ay=T.object({id:T.string(),name:T.string(),vcpu:T.number(),memory_mb:T.number(),default_disk_size_gb:T.number(),requires_gpu:T.boolean(),requires_gpu_count:T.number(),family:T.string().nullable().optional(),display_order:T.number().nullable().optional()}).passthrough(),Bc=T.object({tier:T.string(),capacity:zc,nodes:T.array(Hc),kms_nodes:T.array(Kc),node_kms_relations:T.array(qc),gateway_nodes:T.array(Gc),instance_types:T.array(Ay),gpu_availability:Sy}).passthrough(),Ry=Bc.extend({kms_nodes:T.array(ky),node_kms_relations:T.array(Iy),gateway_nodes:T.array(Ey)});function Wc(e){return e==="2026-01-21"?Bc:Ry}async function Py(e,t){let n=await e.get("/teepods/cvm-create-resources");return t?.schema===!1?n:(t?.schema||Wc(e.config.version)).parse(n)}async function xy(e,t){try{let n=await e.get("/teepods/cvm-create-resources");return t?.schema===!1?{success:!0,data:n}:{success:!0,data:(t?.schema||Wc(e.config.version)).parse(n)}}catch(n){return{success:!1,error:n}}}var Jc=Ce.object({id:Ce.string(),name:Ce.string(),description:Ce.string(),vcpu:Ce.number(),memory_mb:Ce.number(),hourly_rate:Ce.string(),requires_gpu:Ce.boolean(),default_disk_size_gb:Ce.number().default(20),family:Ce.string().nullable()}).passthrough(),$y=Ce.object({name:Ce.string(),items:Ce.array(Jc),total:Ce.number()}).strict(),Ty=Ce.object({result:Ce.array($y)}).strict(),Dy=Ce.object({items:Ce.array(Jc),total:Ce.number(),family:Ce.string()}).strict(),My=Ce.object({family:Ce.string()}).strict(),{action:Ga,safeAction:Uy}=L(Ty,async e=>await e.get("/instance-types")),{action:Ba,safeAction:Ly}=L(Dy,async(e,t)=>{let n=My.parse(t);return await e.get(`/instance-types/${n.family}`)}),Yc=Ae.object({id:Ae.string(),name:Ae.string(),slug:Ae.string().nullable(),avatar_url:Ae.string().nullable().optional(),tier:Ae.string(),role:Ae.string(),is_default:Ae.boolean(),created_at:Ae.string(),confidential_models_enabled:Ae.boolean().optional(),billing_status:Ae.enum(["active","suspended","abandoned"]).default("active"),suspended_at:Ae.string().nullable().optional()}).passthrough(),Ny=Ae.object({has_more:Ae.boolean(),next_cursor:Ae.string().nullable(),total:Ae.number().nullable()}).passthrough(),Oy=Ae.object({data:Ae.array(Yc),pagination:Ny}).passthrough(),{action:jy,safeAction:Fy}=L(Oy,async(e,t)=>{let n=new URLSearchParams;t?.cursor&&n.append("cursor",t.cursor),t?.limit&&n.append("limit",t.limit.toString());let r=n.toString()?`/workspaces?${n.toString()}`:"/workspaces";return await e.get(r)}),{action:Vy,safeAction:Hy}=L(Yc,async(e,t)=>await e.get(`/workspaces/${t}`));function Fn(e){return typeof e!="string"||e.length<5||e.length>63?!1:/^[a-zA-Z](?!.*--)([a-zA-Z0-9-]*[a-zA-Z0-9])?$/.test(e)}function Xc(e){if(typeof e!="string")return eo();let t=e;return t=t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),t=t.replace(/_/g,"-"),t=t.replace(/[^a-z0-9\s-]/gi,"-").replace(/\s+/g,"-"),t=t.replace(/-+/g,"-").replace(/^-+/,"").replace(/-+$/,""),t.length===0||(/^\d/.test(t)&&(t=`dstack-app-${t}`),t.length<5&&(t=`dstack-app-${t}`),t=t.slice(0,63).replace(/-+$/,""),t.length===0)||!Fn(t)?eo():t}function eo(){let e=Date.now().toString(36),t=Math.random().toString(36).substring(2,6);return`dstack-app-${e}-${t}`}var He=An.object({id:An.string().optional(),uuid:An.string().regex(/^[0-9a-f]{8}[-]?[0-9a-f]{4}[-]?4[0-9a-f]{3}[-]?[89ab][0-9a-f]{3}[-]?[0-9a-f]{12}$/i,"Invalid UUID format").optional(),app_id:An.string().optional(),instance_id:An.string().optional(),name:An.string().refine(Fn,{message:"Name must be 5-63 characters, start with letter, and contain only letters/numbers/hyphens"}).optional()}),Ze=e=>e.refine(t=>{let n=t;return!!(n.id||n.uuid||n.app_id||n.instance_id||n.name)},{message:"One of id, uuid, app_id, instance_id, or name must be provided"}),zy=Ze(He),z=zy.transform(e=>{let t;if(e.id)t=e.id;else if(e.uuid)t=e.uuid;else if(e.app_id)t=e.app_id;else if(e.instance_id)t=e.instance_id;else{if(e.name)return{cvmId:e.name};throw new Error("No valid identifier provided")}let n=/^[0-9a-f]{8}[-]?[0-9a-f]{4}[-]?4[0-9a-f]{3}[-]?[89ab][0-9a-f]{3}[-]?[0-9a-f]{12}$/i,r=/^[0-9a-f]{40}$/i,o;return n.test(t)?o=t.replace(/-/g,""):r.test(t)?o=`app_${t}`:o=t,{cvmId:o}}),Ky=z;function qy(e){return e==="2025-10-28"?Uc:e==="2026-01-21"?yy:vy}async function Zc(e,t){let{cvmId:n}=Ky.parse(t),r=await e.get(`/cvms/${n}`);return qy(e.config.version).parse(r)}async function G(e,t){try{return{success:!0,data:await Zc(e,t)}}catch(n){return n&&typeof n=="object"&&("status"in n||"issues"in n)?{success:!1,error:n}:{success:!1,error:{name:"Error",message:n instanceof Error?n.message:String(n)}}}}var Gy=Rn.object({page:Rn.number().int().min(1).optional(),page_size:Rn.number().int().min(1).optional(),family:Rn.enum(["all","cpu","gpu"]).optional(),instance_types:Rn.array(Rn.string()).optional()}).strict();function By(e){return e==="2025-10-28"?ay:e==="2026-01-21"?Oc:by}async function Qc(e,t){let n=Gy.parse(t??{}),r=await e.get("/cvms/paginated",{params:n});return By(e.config.version).parse(r)}async function _r(e,t){try{return{success:!0,data:await Qc(e,t)}}catch(n){return n&&typeof n=="object"&&("status"in n||"issues"in n)?{success:!1,error:n}:{success:!1,error:{name:"Error",message:n instanceof Error?n.message:String(n)}}}}var wr=200*1024;function el(e,t,n){let r=new TextEncoder,o=e?r.encode(e).byteLength:0,a=t?r.encode(t).byteLength:0,s=o+a;if(s>wr){let i=wr/1024,c=Math.ceil(s/1024);n.addIssue({code:ee.ZodIssueCode.custom,message:`Combined size of docker_compose_file and pre_launch_script must not exceed ${i}KB (current: ${c}KB)`})}}var tl=ee.object({allowed_envs:ee.array(ee.string()).optional(),docker_compose_file:ee.string(),features:ee.array(ee.string()).optional(),name:ee.string().optional(),manifest_version:ee.number().optional(),runner:ee.string().optional(),kms_enabled:ee.boolean().optional(),gateway_enabled:ee.boolean().optional(),tproxy_enabled:ee.boolean().optional(),local_key_provider_enabled:ee.boolean().optional(),key_provider:ee.enum(["none","kms","local","tpm"]).optional(),key_provider_id:ee.string().optional(),public_logs:ee.boolean().optional(),public_sysinfo:ee.boolean().optional(),public_tcbinfo:ee.boolean().optional(),no_instance_id:ee.boolean().optional(),secure_time:ee.boolean().optional(),port_