phala
Version:
CLI for Managing Phala Cloud Services
20 lines • 114 kB
JavaScript
import { createRequire } from 'module';const require = createRequire(import.meta.url);
var qr=Object.create;var Gt=Object.defineProperty;var $r=Object.getOwnPropertyDescriptor;var Or=Object.getOwnPropertyNames;var Nr=Object.getPrototypeOf,zr=Object.prototype.hasOwnProperty;var St=(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 rt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ur=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Or(t))!zr.call(e,s)&&s!==n&&Gt(e,s,{get:()=>t[s],enumerable:!(r=$r(t,s))||r.enumerable});return e};var Lr=(e,t,n)=>(n=e!=null?qr(Nr(e)):{},Ur(t||!e||!e.__esModule?Gt(n,"default",{value:e,enumerable:!0}):n,e));var Wt=rt((ru,Bt)=>{var De=1e3,Ve=De*60,Me=Ve*60,ze=Me*24,Fr=ze*7,Dr=ze*365.25;Bt.exports=function(e,t){t=t||{};var n=typeof e;if(n==="string"&&e.length>0)return Vr(e);if(n==="number"&&isFinite(e))return t.long?Kr(e):Mr(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function Vr(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*Dr;case"weeks":case"week":case"w":return n*Fr;case"days":case"day":case"d":return n*ze;case"hours":case"hour":case"hrs":case"hr":case"h":return n*Me;case"minutes":case"minute":case"mins":case"min":case"m":return n*Ve;case"seconds":case"second":case"secs":case"sec":case"s":return n*De;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}}}function Mr(e){var t=Math.abs(e);return t>=ze?Math.round(e/ze)+"d":t>=Me?Math.round(e/Me)+"h":t>=Ve?Math.round(e/Ve)+"m":t>=De?Math.round(e/De)+"s":e+"ms"}function Kr(e){var t=Math.abs(e);return t>=ze?lt(e,t,ze,"day"):t>=Me?lt(e,t,Me,"hour"):t>=Ve?lt(e,t,Ve,"minute"):t>=De?lt(e,t,De,"second"):e+" ms"}function lt(e,t,n,r){var s=t>=n*1.5;return Math.round(e/n)+" "+r+(s?"s":"")}});var kt=rt((su,Xt)=>{function Hr(e){n.debug=n,n.default=n,n.coerce=u,n.disable=a,n.enable=s,n.enabled=o,n.humanize=Wt(),n.destroy=f,Object.keys(e).forEach(m=>{n[m]=e[m]}),n.names=[],n.skips=[],n.formatters={};function t(m){let d=0;for(let h=0;h<m.length;h++)d=(d<<5)-d+m.charCodeAt(h),d|=0;return n.colors[Math.abs(d)%n.colors.length]}n.selectColor=t;function n(m){let d,h=null,_,k;function R(...O){if(!R.enabled)return;let se=R,fe=Number(new Date),je=fe-(d||fe);se.diff=je,se.prev=d,se.curr=fe,d=fe,O[0]=n.coerce(O[0]),typeof O[0]!="string"&&O.unshift("%O");let Se=0;O[0]=O[0].replace(/%([a-zA-Z%])/g,(Fe,ct)=>{if(Fe==="%%")return"%";Se++;let Ht=n.formatters[ct];if(typeof Ht=="function"){let Pr=O[Se];Fe=Ht.call(se,Pr),O.splice(Se,1),Se--}return Fe}),n.formatArgs.call(se,O),(se.log||n.log).apply(se,O)}return R.namespace=m,R.useColors=n.useColors(),R.color=n.selectColor(m),R.extend=r,R.destroy=n.destroy,Object.defineProperty(R,"enabled",{enumerable:!0,configurable:!1,get:()=>h!==null?h:(_!==n.namespaces&&(_=n.namespaces,k=n.enabled(m)),k),set:O=>{h=O}}),typeof n.init=="function"&&n.init(R),R}function r(m,d){let h=n(this.namespace+(typeof d>"u"?":":d)+m);return h.log=this.log,h}function s(m){n.save(m),n.namespaces=m,n.names=[],n.skips=[];let d=(typeof m=="string"?m:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(let h of d)h[0]==="-"?n.skips.push(h.slice(1)):n.names.push(h)}function i(m,d){let h=0,_=0,k=-1,R=0;for(;h<m.length;)if(_<d.length&&(d[_]===m[h]||d[_]==="*"))d[_]==="*"?(k=_,R=h,_++):(h++,_++);else if(k!==-1)_=k+1,R++,h=R;else return!1;for(;_<d.length&&d[_]==="*";)_++;return _===d.length}function a(){let m=[...n.names,...n.skips.map(d=>"-"+d)].join(",");return n.enable(""),m}function o(m){for(let d of n.skips)if(i(m,d))return!1;for(let d of n.names)if(i(m,d))return!0;return!1}function u(m){return m instanceof Error?m.stack||m.message:m}function f(){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}Xt.exports=Hr});var Jt=rt((ce,ut)=>{ce.formatArgs=Br;ce.save=Wr;ce.load=Xr;ce.useColors=Gr;ce.storage=Jr();ce.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`."))}})();ce.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 Gr(){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 Br(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+ut.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,s=>{s!=="%%"&&(n++,s==="%c"&&(r=n))}),e.splice(r,0,t)}ce.log=console.debug||console.log||(()=>{});function Wr(e){try{e?ce.storage.setItem("debug",e):ce.storage.removeItem("debug")}catch{}}function Xr(){let e;try{e=ce.storage.getItem("debug")||ce.storage.getItem("DEBUG")}catch{}return!e&&typeof process<"u"&&"env"in process&&(e=process.env.DEBUG),e}function Jr(){try{return localStorage}catch{}}ut.exports=kt()(ce);var{formatters:Zr}=ut.exports;Zr.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}});var Qt=rt((B,mt)=>{var Qr=St("tty"),pt=St("util");B.init=as;B.log=ns;B.formatArgs=es;B.save=rs;B.load=ss;B.useColors=Yr;B.destroy=pt.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");B.colors=[6,2,3,4,5,1];try{let e=St("supports-color");e&&(e.stderr||e).level>=2&&(B.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{}B.inspectOpts=Object.keys(process.env).filter(e=>/^debug_/i.test(e)).reduce((e,t)=>{let n=t.substring(6).toLowerCase().replace(/_([a-z])/g,(s,i)=>i.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 Yr(){return"colors"in B.inspectOpts?!!B.inspectOpts.colors:Qr.isatty(process.stderr.fd)}function es(e){let{namespace:t,useColors:n}=this;if(n){let r=this.color,s="\x1B[3"+(r<8?r:"8;5;"+r),i=` ${s};1m${t} \x1B[0m`;e[0]=i+e[0].split(`
`).join(`
`+i),e.push(s+"m+"+mt.exports.humanize(this.diff)+"\x1B[0m")}else e[0]=ts()+t+" "+e[0]}function ts(){return B.inspectOpts.hideDate?"":new Date().toISOString()+" "}function ns(...e){return process.stderr.write(pt.formatWithOptions(B.inspectOpts,...e)+`
`)}function rs(e){e?process.env.DEBUG=e:delete process.env.DEBUG}function ss(){return process.env.DEBUG}function as(e){e.inspectOpts={};let t=Object.keys(B.inspectOpts);for(let n=0;n<t.length;n++)e.inspectOpts[t[n]]=B.inspectOpts[t[n]]}mt.exports=kt()(B);var{formatters:Zt}=mt.exports;Zt.o=function(e){return this.inspectOpts.colors=this.useColors,pt.inspect(e,this.inspectOpts).split(`
`).map(t=>t.trim()).join(" ")};Zt.O=function(e){return this.inspectOpts.colors=this.useColors,pt.inspect(e,this.inspectOpts)}});var Yt=rt((au,Et)=>{typeof process>"u"||process.type==="renderer"||process.browser===!0||process.__nwjs?Et.exports=Jt():Et.exports=Qt()});var gn=Lr(Yt(),1);import{ofetch as os}from"ofetch";function en(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(s){s(n)}),(r=e.get("*"))&&r.slice().map(function(s){s(t,n)})}}}import{z as W}from"zod";import{z as $}from"zod";import{z as qe}from"zod";import{z as S}from"zod";import{z as l}from"zod";import{z as p}from"zod";import{z as xe}from"zod";import{anvil as rn,base as sn,mainnet as an}from"viem/chains";import{z as b}from"zod";import{z as M}from"zod";import{z as X}from"zod";import{z as He}from"zod";import{z as Ge}from"zod";import{z as g}from"zod";import{z as x}from"zod";import{z as w}from"zod";import Oa from"crypto";import{z as ge}from"zod";import{z as _e}from"zod";import{z as Q}from"zod";import{z as Y}from"zod";import{z as ee}from"zod";import{z as bo}from"zod";import{z as Be}from"zod";import{z as de}from"zod";import{z as cn}from"zod";import{z as Ie}from"zod";import{z as Re}from"zod";import{z as oe}from"zod";import{z as ln}from"zod";import{z as ot}from"zod";import{z as Ye}from"zod";import{z as Le}from"zod";import{z as P}from"zod";import{z as fi}from"zod";import{z as bi}from"zod";import{z as T}from"zod";import{z as Ae}from"zod";import{z as Pi}from"zod";import{z as V}from"zod";import{z as y}from"zod";import{z as Te}from"zod";import{z as Rt}from"zod";import{z as ne}from"zod";import{z as ar}from"zod";import{z as ke}from"zod";import{z as le}from"zod";import{z as $e}from"zod";import{z as xt}from"zod";import{z as jt}from"zod";import{z as Ue}from"zod";import{z as Z}from"zod";import{z as N}from"zod";import{z as C}from"zod";import{z}from"zod";import{z as I}from"zod";import{z as K}from"zod";import{createPublicClient as jp,createWalletClient as Pp,http as qp,parseEventLogs as $p,parseEther as Op}from"viem";import{privateKeyToAccount as zp}from"viem/accounts";import{x25519 as cu}from"@noble/curves/ed25519";import{keccak256 as Dp,toBytes as Vp,toHex as Mp}from"viem";import{isHex as Hp}from"viem";import{createPublicClient as Bp,createWalletClient as Wp,http as Xp,custom as Jp}from"viem";import{privateKeyToAccount as Qp}from"viem/accounts";import{z as U}from"zod";import{createPublicClient as rm,createWalletClient as sm,http as am,parseEventLogs as om,parseEther as im}from"viem";import{privateKeyToAccount as lm}from"viem/accounts";import{z as L}from"zod";import{createPublicClient as fm,createWalletClient as gm,http as hm,parseEther as bm}from"viem";import{privateKeyToAccount as ym}from"viem/accounts";import{z as F}from"zod";import{createPublicClient as km,createWalletClient as Em,http as Am,parseEther as Im}from"viem";import{privateKeyToAccount as xm}from"viem/accounts";import{z as D}from"zod";import{createPublicClient as $m,createWalletClient as Om,http as Nm,parseEther as zm}from"viem";import{privateKeyToAccount as Lm}from"viem/accounts";import{z as We}from"zod";import{createPublicClient as Km,http as Hm}from"viem";import{createPublicClient as Wm,http as Xm}from"viem";import{createPublicClient as Zm,http as Qm}from"viem";import{createPublicClient as ed,http as td}from"viem";import{z as Xe}from"zod";import{z as we}from"zod";import{z as el}from"zod";import{z as Je}from"zod";import{z as A}from"zod";import{z as ht}from"zod";import{z as et}from"zod";import{z as me}from"zod";import{z as H}from"zod";import{z as j}from"zod";import{z as st}from"zod";import{z as J}from"zod";import{z as Ze}from"zod";import{z as te}from"zod";import{z as pe}from"zod";import{z as mn}from"zod";import{z as dn}from"zod";import{z as Ee}from"zod";import{z as G}from"zod";import{z as dt}from"zod";import{z as ft}from"zod";import{z as ae}from"zod";import{z as E}from"zod";import{secp256k1 as mu}from"@noble/curves/secp256k1";var is=W.object({detail:W.union([W.string(),W.array(W.object({msg:W.string(),type:W.string().optional(),ctx:W.record(W.unknown()).optional(),loc:W.array(W.union([W.string(),W.number()])).optional(),input:W.unknown().optional()}).passthrough()),W.record(W.unknown())]).optional(),type:W.string().optional(),code:W.string().optional()});function cs(e){if(!e||typeof e!="object")return;let t=e.request_id;return typeof t=="string"?t:void 0}function ls(e){return e?.headers?.get("X-Request-ID")??void 0}function tn(e){if(typeof e!="string")return;let t=e.trim().toUpperCase();return t.length>0?t:void 0}var he=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)}},At=class at extends he{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=cs(t.data),r=ls(t.response),s=n??r,i=tn(t.options?.method),a=is.safeParse(t.data);if(a.success){let u=a.data.detail??(t.data&&typeof t.data=="object"&&"error_code"in t.data?t.data:void 0);return new at(t.message,{status:t.status??void 0,statusText:t.statusText??void 0,data:t.data,request:t.request??void 0,requestMethod:i,response:t.response??void 0,detail:u,code:a.data.code??void 0,type:a.data.type??void 0,requestId:s})}if(t.cause?.name==="TimeoutError"||t.message?.includes("[TimeoutError]")){let u="Request timed out. The server did not respond in time.";return new at(u,{status:0,statusText:"Request Timeout",data:t.data,request:t.request??void 0,requestMethod:i,response:t.response??void 0,detail:u,code:"TIMEOUT",requestId:s})}return new at(t.message,{status:t.status??void 0,statusText:t.statusText??void 0,data:t.data,request:t.request??void 0,requestMethod:i,response:t.response??void 0,detail:t.data?.detail||t.message||"Unknown API error",code:t.status?.toString()??void 0,requestId:s})}static fromError(t,n,r){return new at(t.message,{request:n??void 0,requestMethod:tn(r),detail:t.message})}},us=class extends he{constructor(e,t){super(e,t),this.isValidationError=!0,this.validationErrors=t.validationErrors}},ps=class extends he{constructor(){super(...arguments),this.isAuthError=!0}},hn=class extends he{constructor(){super(...arguments),this.isBusinessError=!0}},ms=class extends he{constructor(){super(...arguments),this.isServerError=!0}},ds=class extends he{constructor(){super(...arguments),this.isUnknownError=!0}};function fs(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 bn(e){if(!Array.isArray(e))return{errors:[],message:typeof e=="string"?e:"Validation error"};let t=e.map((s,i)=>{let a=fs(s.loc),o=a;return a==="unknown"&&s.type&&(o=s.type==="missing"?"required field":s.type),{field:o,message:s.msg,type:s.type,context:s.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 gs(e){return e===422?"validation":e===401||e===403?"auth":e>=400&&e<500?"business":e>=500?"server":"unknown"}function hs(e,t,n){if(e===422&&Array.isArray(t)){let{message:r}=bn(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 bs(e){let t=e.status??0,n=e.statusText??"Unknown Error",r=e.detail,s=ys(r);if(s)return new vs(s.message,{status:t,statusText:n,detail:r,requestId:s.request_id??e.requestId,request:e.request,requestMethod:e.requestMethod,data:e.data,errorCode:s.error_code,structuredDetails:s.details,suggestions:s.suggestions,links:s.links});let i=gs(t),a=hs(t,r,e.message),o={status:t,statusText:n,detail:r,requestId:e.requestId,request:e.request,requestMethod:e.requestMethod,data:e.data,code:e.code};if(i==="validation"&&Array.isArray(r)){let{errors:u}=bn(r);return new us(a,{...o,validationErrors:u})}return i==="auth"?new ps(a,o):i==="business"?new hn(a,o):i==="server"?new ms(a,o):new ds(a,o)}var vs=class extends hn{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 ys(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}var bt=["2025-10-28","2026-01-21","2026-05-22","2026-06-23"],_s="2026-06-23",Ke=(0,gn.default)("phala::api-client");function ws(e){return Object.entries(e).map(([t,n])=>` -H "${t}: ${n}"`).join(`
`)}function Cs(e){return e?` -d '${(typeof e=="string"?e:JSON.stringify(e,null,2)).replace(/'/g,"\\'")}'`:""}function nn(e,t,n,r){let s=[];n.forEach((o,u)=>{s.push(`${u}: ${o}`)});let i=s.join(`
`),a=typeof r=="string"?r:JSON.stringify(r,null,2);return[`< HTTP/1.1 ${e} ${t}`,i?`< ${i.replace(/\n/g,`
< `)}`:"","",a].filter(Boolean).join(`
`)}var Ss=class vn{constructor(t={}){this.emitter=en();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",s=t.version&&bt.includes(t.version)?t.version:_s;this.config={...t,apiKey:n,baseURL:r,version:s};let{apiKey:i,baseURL:a,timeout:o,headers:u,useCookieAuth:f,onResponseError:m,...d}=this.config,h={"X-Phala-Version":s,"Content-Type":"application/json"};u&&typeof u=="object"&&Object.entries(u).forEach(([_,k])=>{typeof k=="string"&&(h[_]=k)}),!f&&i&&(h["X-API-Key"]=i),this.fetchInstance=os.create({baseURL:a,timeout:o||6e4,headers:h,...f?{credentials:"include"}:{},...d,onRequest({request:_,options:k}){if(k.body instanceof FormData){let R=k.headers;R instanceof Headers?R.delete("content-type"):R&&typeof R=="object"&&!Array.isArray(R)&&(delete R["Content-Type"],delete R["content-type"])}if(Ke.enabled){let R=k.method||"GET",O=typeof _=="string"?_:_.url,se=O.startsWith("http")?O:`${a}${O}`,fe={};k.headers&&typeof k.headers=="object"&&Object.entries(k.headers).forEach(([Se,Pe])=>{typeof Pe=="string"&&(fe[Se]=Pe)});let je=[`> curl -X ${R} "${se}"`,ws(fe),k.body?Cs(k.body):""].filter(Boolean).join(`
`);Ke(`
=== REQUEST ===
%s
`,je)}},onResponse({request:_,response:k,options:R}){if(Ke.enabled){let O=R.method||"GET",se=typeof _=="string"?_:_.url;Ke(`
=== RESPONSE [%s %s] (%dms) ===
%s
`,O,se,k.headers.get("x-response-time")||"?",nn(k.status,k.statusText,k.headers,k._data))}},onResponseError:({request:_,response:k,options:R})=>{if(Ke.enabled){console.warn(`HTTP ${k.status}: ${k.url}`);let O=R.method||"GET",se=typeof _=="string"?_:_.url;Ke(`
=== ERROR RESPONSE [%s %s] ===
%s
`,O,se,nn(k.status,k.statusText,k.headers,k._data))}m&&m({request:_,response:k,options:R})}})}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=s=>{n(s),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 s=this.convertToRequestError(r);throw this.emitError(s)}}async requestFull(t,n){try{let r=n?.method||"GET",s=await this.fetchInstance.raw(t,{...n,method:r,ignoreResponseError:!0});return{status:s.status,statusText:s.statusText,headers:s.headers,data:s._data,ok:s.ok}}catch(r){let s=this.convertToRequestError(r);throw this.emitError(s)}}async get(t,n){try{return await this.fetchInstance(t,{...n,method:"GET"})}catch(r){let s=this.convertToRequestError(r);throw this.emitError(s)}}buildRequestOptions(t,n,r){let s={...r,method:t,body:n};if(n instanceof FormData){let i=s.headers;s.headers={...i,"Content-Type":""}}return s}async post(t,n,r){try{return await this.fetchInstance(t,this.buildRequestOptions("POST",n,r))}catch(s){let i=this.convertToRequestError(s);throw this.emitError(i)}}async put(t,n,r){try{return await this.fetchInstance(t,this.buildRequestOptions("PUT",n,r))}catch(s){let i=this.convertToRequestError(s);throw this.emitError(i)}}async patch(t,n,r){try{return await this.fetchInstance(t,this.buildRequestOptions("PATCH",n,r))}catch(s){let i=this.convertToRequestError(s);throw this.emitError(i)}}async delete(t,n){try{return await this.fetchInstance(t,{...n,method:"DELETE"})}catch(r){let s=this.convertToRequestError(r);throw this.emitError(s)}}convertToRequestError(t){return t&&typeof t=="object"&&"data"in t?At.fromFetchError(t):t instanceof Error?At.fromError(t):new At("Unknown error occurred",{detail:"Unknown error occurred"})}emitError(t){let n=bs(t);return this.emitter.emit("error",n),n}async safeRequest(t){try{return{success:!0,data:await t()}}catch(n){if(n instanceof he)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 vn({...this.config,version:t})}extend(t){let n=typeof t=="function"?t(this):t,r=Object.create(this);for(let[s,i]of Object.entries(n))typeof i=="function"&&(r[s]=(...a)=>i(this,...a));return r}};function ks(e={}){return new Ss(e)}var Es=$.object({username:$.string(),email:$.string(),role:$.enum(["admin","user"]),avatar:$.string(),email_verified:$.boolean(),totp_enabled:$.boolean(),has_backup_codes:$.boolean(),flag_has_password:$.boolean()}).passthrough(),As=$.object({id:$.string(),name:$.string(),slug:$.string().nullable(),tier:$.string(),role:$.string(),avatar:$.string().nullable().optional()}).passthrough(),Is=$.object({balance:$.string().or($.number()),granted_balance:$.string().or($.number()),is_post_paid:$.boolean(),outstanding_amount:$.string().or($.number()).nullable()}).passthrough(),Rs=$.object({user:Es,workspace:As,credits:Is}).passthrough(),xs=qe.object({username:qe.string(),email:qe.string(),credits:qe.number(),granted_credits:qe.number(),avatar:qe.string(),team_name:qe.string(),team_tier:qe.string()}).passthrough();function Ts(e){return e==="2025-10-28"?xs:Rs}async function yn(e,t){let n=await e.get("/auth/me");return t?.schema===!1?n:(t?.schema||Ts(e.config.version)).parse(n)}async function js(e,t){try{return{success:!0,data:await yn(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 _n={[an.id]:an,[sn.id]:sn,[rn.id]:rn},Ps=xe.object({id:xe.string(),slug:xe.string().nullable(),url:xe.string(),version:xe.string(),chain_id:xe.number().nullable(),kms_contract_address:xe.string().nullable().transform(e=>e),gateway_app_id:xe.string().nullable().transform(e=>e),k256_pubkey:xe.string().nullable().optional()}).passthrough(),be=Ps.transform(e=>{if(e.chain_id!=null){let t=_n[e.chain_id];if(t)return{...e,chain:t}}return e}),wn=p.union([p.number(),p.string()]),qs=p.object({id:p.string(),name:p.string(),status:p.string(),uptime:p.string(),app_url:p.string().nullable(),app_id:p.string(),instance_id:p.string().nullable(),configuration:p.any().optional(),exited_at:p.string().nullable(),boot_progress:p.string().nullable(),boot_error:p.string().nullable(),shutdown_progress:p.string().nullable(),image_version:p.string().nullable()}),$s=p.object({id:wn,username:p.string()}),Cn=p.object({id:p.number(),name:p.string(),region_identifier:p.string().nullable().optional()}),Pt=p.object({vcpu:p.number(),memory:p.number(),disk_size:p.number(),gpu_count:p.number().default(0)}),qt=p.object({app:p.string(),instance:p.string()}),Os=p.object({hosted:qs,name:p.string(),managed_user:$s.nullable(),node:Cn.nullable(),listed:p.boolean().default(!1),status:p.string(),in_progress:p.boolean().default(!1),dapp_dashboard_url:p.string().nullable(),syslog_endpoint:p.string().nullable(),allow_upgrade:p.boolean().default(!1),project_id:p.string().nullable(),project_type:p.string().nullable(),billing_period:p.string().nullable(),kms_info:be.nullable(),vcpu:p.number().nullable(),memory:p.number().nullable(),disk_size:p.number().nullable(),gateway_domain:p.string().nullable(),public_urls:p.array(qt),machine_info:Pt.nullable().optional(),updated_at:p.string().nullable().optional()}),Sn=p.object({id:wn,name:p.string(),status:p.string(),in_progress:p.boolean().optional().default(!1),teepod_id:p.number().nullable(),teepod:Cn.optional().nullable(),app_id:p.string(),vm_uuid:p.string().nullable(),instance_id:p.string().nullable(),vcpu:p.number(),memory:p.number(),disk_size:p.number(),base_image:p.string().nullable(),encrypted_env_pubkey:p.string().nullable(),listed:p.boolean().optional().default(!1),project_id:p.string().optional().nullable(),project_type:p.string().optional().nullable(),instance_type:p.string().optional().nullable(),public_sysinfo:p.boolean().optional().default(!1),public_logs:p.boolean().optional().default(!1),dapp_dashboard_url:p.string().optional().nullable(),syslog_endpoint:p.string().optional().nullable(),kms_info:be.optional().nullable(),contract_address:p.string().optional().nullable(),deployer_address:p.string().optional().nullable(),scheduled_delete_at:p.string().optional().nullable(),public_urls:p.array(qt).optional().default([]),gateway_domain:p.string().optional().nullable(),machine_info:Pt.optional().nullable(),updated_at:p.string().optional().nullable()}),Ns=p.object({items:p.array(Os),total:p.number(),page:p.number(),page_size:p.number(),pages:p.number()}),zs=l.enum(["skip","hourly","monthly"]),Us=l.enum(["phala","ethereum","base","legacy"]),$t=l.object({object_type:l.literal("user"),id:l.string().nullable().optional(),username:l.string().nullable().optional(),avatar_url:l.string().nullable().optional()}),Ot=l.object({object_type:l.literal("workspace"),id:l.string(),name:l.string(),slug:l.string().nullable().optional(),avatar_url:l.string().nullable().optional()}),Ls=l.object({instance_type:l.string().nullable().optional(),vcpu:l.number().int().nullable().optional(),memory_in_gb:l.number().nullable().optional(),disk_in_gb:l.number().int().nullable().optional(),gpus:l.number().int().nullable().optional(),compute_billing_price:l.string().nullable().optional(),billing_period:zs.nullable().optional()}),Fs=l.object({total:l.string().nullable().optional(),compute:l.string().nullable().optional(),disk:l.string().nullable().optional()}),Ds=l.object({order_id:l.string(),status:l.string(),pricing_plan:l.string().nullable().optional(),commitment_days:l.number().int().nullable().optional(),agreed_hourly_rate:l.string().nullable().optional(),hourly_billing_start_time:l.string().nullable().optional(),activated_at:l.string().nullable().optional(),completed_at:l.string().nullable().optional(),cancelled_at:l.string().nullable().optional(),decoupled_at:l.string().nullable().optional(),sku_code:l.string().nullable().optional(),sku_display_name:l.string().nullable().optional()}),Vs=l.object({name:l.string().nullable().optional(),version:l.string().nullable().optional(),is_dev:l.boolean().nullable().optional(),os_image_hash:l.string().nullable().optional()}),Ms=l.object({chain_id:l.number().int().nullable().optional(),dstack_kms_address:l.string().nullable().optional(),dstack_app_address:l.string().nullable().optional(),deployer_address:l.string().nullable().optional(),rpc_endpoint:l.string().nullable().optional(),encrypted_env_pubkey:l.string().nullable().optional()}),Ks=Ms.transform(e=>{if(e.chain_id!=null){let t=_n[e.chain_id];if(t)return{...e,chain:t}}return e}),Hs=l.object({target:l.string().nullable().optional(),started_at:l.string().nullable().optional(),correlation_id:l.string().nullable().optional()}),Gs=l.object({base_domain:l.string().nullable().optional(),cname:l.string().nullable().optional()}),Bs=l.object({serial:l.string().nullable().optional(),stdout:l.string().nullable().optional(),stderr:l.string().nullable().optional(),container_log_base:l.string().nullable().optional()}),kn=l.object({device_id:l.string(),algorithm_version:l.string(),enabled:l.boolean()}),En=l.object({object_type:l.literal("node"),id:l.number().int().nullable().optional(),name:l.string().nullable().optional(),region:l.string().nullable().optional(),device_id:l.string().nullable().optional(),device_ids:l.array(kn).default([]),ppid:l.string().nullable().optional(),status:l.string().nullable().optional(),version:l.string().nullable().optional()});var it=l.object({id:l.string(),name:l.string(),app_id:l.string().nullable().optional(),vm_uuid:l.string().nullable().optional(),instance_id:l.string().nullable().optional(),resource:Ls,node_info:En.nullable().optional(),os:Vs.nullable().optional(),kms_type:Us.nullable().optional(),kms_info:Ks.nullable().optional(),status:l.string(),in_progress:l.boolean().optional().default(!1),progress:Hs.nullable().optional(),compose_hash:l.string().nullable().optional(),docker_compose_hash:l.string().nullable().optional(),pre_launch_script_hash:l.string().nullable().optional(),gateway:Gs,logs:Bs.optional().default({}),services:l.array(l.record(l.any())).optional().default([]),endpoints:l.array(qt).nullable().optional(),public_logs:l.boolean().optional(),public_sysinfo:l.boolean().optional(),public_tcbinfo:l.boolean().optional(),gateway_enabled:l.boolean().optional(),secure_time:l.boolean().optional(),listed:l.boolean().optional().default(!1),storage_fs:l.string().optional(),workspace:Ot.nullable().optional(),creator:$t.nullable().optional(),created_at:l.string().nullable().optional(),deleted_at:l.string().nullable().optional(),project_type:l.string().nullable().optional(),hourly_rate:Fs.nullable().optional(),billing_interval:l.string().nullable().optional(),gpu_rental_order:Ds.nullable().optional()}),gt=it.extend({id:l.string()}),Ws=it.extend({compose_file:l.union([l.record(l.any()),l.string()]).nullable().optional()}),Xs=gt.extend({compose_file:l.union([l.record(l.any()),l.string()]).nullable().optional()}),An=l.object({items:l.array(it),total:l.number(),page:l.number(),page_size:l.number(),pages:l.number()}),Js=An.extend({items:l.array(gt)});function In(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 Rn(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 xn(e,t){function n(a,o){return r(a,o)}async function r(a,o){In(o);let u=await t(a);return o?.schema===!1?u:(o?.schema||e).parse(u)}function s(a,o){return i(a,o)}async function i(a,o){let u=Rn(o);if(u)return u;let f=await(async()=>{try{return{success:!0,data:await t(a)}}catch(d){return d&&typeof d=="object"&&"status"in d?{success:!1,error:d}:d&&typeof d=="object"&&"issues"in d?{success:!1,error:d}:{success:!1,error:{name:"Error",message:d instanceof Error?d.message:String(d)}}}})();return f.success?o?.schema===!1?{success:!0,data:f.data}:(o?.schema||e).safeParse(f.data):f}return{action:n,safeAction:s}}function v(e,t){function n(a,...o){let[u,f]=o;return r(a,u,f)}async function r(a,o,u){In(u);let f=await t(a,o);return u?.schema===!1?f:(u?.schema||e).parse(f)}function s(a,...o){let[u,f]=o;return i(a,u,f)}async function i(a,o,u){let f=Rn(u);if(f)return f;let m=await(async()=>{try{return{success:!0,data:await t(a,o)}}catch(h){return h&&typeof h=="object"&&"status"in h?{success:!1,error:h}:h&&typeof h=="object"&&"issues"in h?{success:!1,error:h}:{success:!1,error:{name:"Error",message:h instanceof Error?h.message:String(h)}}}})();return m.success?u?.schema===!1?{success:!0,data:m.data}:(u?.schema||e).safeParse(m.data):m}return{action:n,safeAction:s}}var Zs=S.object({name:S.string(),is_dev:S.boolean(),version:S.union([S.tuple([S.number(),S.number(),S.number()]),S.tuple([S.number(),S.number(),S.number(),S.number()])]),os_image_hash:S.string().nullable().optional()}).passthrough(),Tn=S.object({teepod_id:S.number(),name:S.string(),listed:S.boolean(),resource_score:S.number(),remaining_vcpu:S.number(),remaining_memory:S.number(),remaining_cvm_slots:S.number(),images:S.array(Zs),support_onchain_kms:S.boolean().optional(),fmspc:S.string().nullable().optional(),device_id:S.string().nullable().optional(),device_ids:S.array(kn).default([]),region_identifier:S.string().nullable().optional(),default_kms:S.string().nullable().optional(),kms_list:S.array(S.string()).default([])}).passthrough(),jn=S.object({max_instances:S.number().nullable().optional(),max_vcpu:S.number().nullable().optional(),max_memory:S.number().nullable().optional(),max_disk:S.number().nullable().optional()}).passthrough(),Qs=S.object({tier:S.string(),capacity:jn,nodes:S.array(Tn),kms_list:S.array(be)}).passthrough(),{action:Ys,safeAction:ea}=xn(Qs,async e=>await e.get("/teepods/available")),tt=b.union([b.number(),b.string()]),nt=b.string(),ta=b.object({has_reserved_gpus:b.boolean(),reserved_gpu_count:b.number(),has_public_gpus:b.boolean(),public_gpu_count:b.number()}).passthrough(),Pn=b.object({id:tt,slug:b.string().nullable().optional(),url:b.string(),version:b.string().nullable().optional(),kms_type:b.string(),chain_id:b.number().nullable().optional(),kms_contract_id:tt.nullable().optional(),kms_contract_address:b.string().nullable().optional(),gateway_app_id:b.string().nullable().optional(),supported_os_images:b.array(b.string()).default([])}).passthrough(),qn=b.object({teepod_id:b.number(),kms_id:tt,kms_type:b.string(),kms_contract_id:tt.nullable().optional(),kms_contract_address:b.string().nullable().optional(),supported_os_images:b.array(b.string()).default([])}).passthrough(),$n=b.object({id:tt,teepod_id:b.number().nullable().optional(),kms_contract_id:tt,rpc_url:b.string().nullable().optional(),domain_suffix:b.string().nullable().optional(),enabled:b.boolean()}).passthrough(),na=Pn.extend({id:nt,kms_contract_id:nt.nullable().optional()}),ra=qn.extend({kms_id:nt,kms_contract_id:nt.nullable().optional()}),sa=$n.extend({id:nt,kms_contract_id:nt}),aa=b.object({id:b.string(),name:b.string(),vcpu:b.number(),memory_mb:b.number(),default_disk_size_gb:b.number(),requires_gpu:b.boolean(),requires_gpu_count:b.number(),family:b.string().nullable().optional(),display_order:b.number().nullable().optional()}).passthrough(),On=b.object({tier:b.string(),capacity:jn,nodes:b.array(Tn),kms_nodes:b.array(Pn),node_kms_relations:b.array(qn),gateway_nodes:b.array($n),instance_types:b.array(aa),gpu_availability:ta}).passthrough(),oa=On.extend({kms_nodes:b.array(na),node_kms_relations:b.array(ra),gateway_nodes:b.array(sa)});function Nn(e){return e==="2026-01-21"?On:oa}async function ia(e,t){let n=await e.get("/teepods/cvm-create-resources");return t?.schema===!1?n:(t?.schema||Nn(e.config.version)).parse(n)}async function ca(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||Nn(e.config.version)).parse(n)}}catch(n){return{success:!1,error:n}}}var zn=M.object({id:M.string(),name:M.string(),description:M.string(),vcpu:M.number(),memory_mb:M.number(),hourly_rate:M.string(),requires_gpu:M.boolean(),default_disk_size_gb:M.number().default(20),family:M.string().nullable()}).passthrough(),la=M.object({name:M.string(),items:M.array(zn),total:M.number()}).strict(),ua=M.object({result:M.array(la)}).strict(),pa=M.object({items:M.array(zn),total:M.number(),family:M.string()}).strict(),ma=M.object({family:M.string()}).strict(),{action:da,safeAction:fa}=v(ua,async e=>await e.get("/instance-types")),{action:ga,safeAction:ha}=v(pa,async(e,t)=>{let n=ma.parse(t);return await e.get(`/instance-types/${n.family}`)}),Un=X.object({id:X.string(),name:X.string(),slug:X.string().nullable(),avatar_url:X.string().nullable().optional(),tier:X.string(),role:X.string(),is_default:X.boolean(),created_at:X.string(),confidential_models_enabled:X.boolean().optional(),billing_status:X.enum(["active","suspended","abandoned"]).default("active"),suspended_at:X.string().nullable().optional()}).passthrough(),ba=X.object({has_more:X.boolean(),next_cursor:X.string().nullable(),total:X.number().nullable()}).passthrough(),va=X.object({data:X.array(Un),pagination:ba}).passthrough(),{action:ya,safeAction:_a}=v(va,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:wa,safeAction:Ca}=v(Un,async(e,t)=>await e.get(`/workspaces/${t}`));function Ln(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)}var re=He.object({id:He.string().optional(),uuid:He.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:He.string().optional(),instance_id:He.string().optional(),name:He.string().refine(Ln,{message:"Name must be 5-63 characters, start with letter, and contain only letters/numbers/hyphens"}).optional()}),ue=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"}),Sa=ue(re),q=Sa.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,s;return n.test(t)?s=t.replace(/-/g,""):r.test(t)?s=`app_${t}`:s=t,{cvmId:s}}),ka=q;function Ea(e){return e==="2025-10-28"?Sn:e==="2026-01-21"?Ws:Xs}async function Fn(e,t){let{cvmId:n}=ka.parse(t),r=await e.get(`/cvms/${n}`);return Ea(e.config.version).parse(r)}async function vt(e,t){try{return{success:!0,data:await Fn(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 Aa=Ge.object({page:Ge.number().int().min(1).optional(),page_size:Ge.number().int().min(1).optional(),family:Ge.enum(["all","cpu","gpu"]).optional(),instance_types:Ge.array(Ge.string()).optional()}).strict();function Ia(e){return e==="2025-10-28"?Ns:e==="2026-01-21"?An:Js}async function Dn(e,t){let n=Aa.parse(t??{}),r=await e.get("/cvms/paginated",{params:n});return Ia(e.config.version).parse(r)}async function Nt(e,t){try{return{success:!0,data:await Dn(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 on=200*1024;function Vn(e,t,n){let r=new TextEncoder,s=e?r.encode(e).byteLength:0,i=t?r.encode(t).byteLength:0,a=s+i;if(a>on){let o=on/1024,u=Math.ceil(a/1024);n.addIssue({code:x.ZodIssueCode.custom,message:`Combined size of docker_compose_file and pre_launch_script must not exceed ${o}KB (current: ${u}KB)`})}}var Mn=x.object({allowed_envs:x.array(x.string()).optional(),docker_compose_file:x.string(),features:x.array(x.string()).optional(),name:x.string().optional(),manifest_version:x.number().optional(),runner:x.string().optional(),kms_enabled:x.boolean().optional(),gateway_enabled:x.boolean().optional(),tproxy_enabled:x.boolean().optional(),local_key_provider_enabled:x.boolean().optional(),key_provider:x.enum(["none","kms","local","tpm"]).optional(),key_provider_id:x.string().optional(),public_logs:x.boolean().optional(),public_sysinfo:x.boolean().optional(),public_tcbinfo:x.boolean().optional(),no_instance_id:x.boolean().optional(),secure_time:x.boolean().optional(),port_policy:x.object({ports:x.array(x.object({port:x.number().int().min(1).max(65535),pp:x.boolean()})),restrict_mode:x.boolean()}).optional(),storage_fs:x.enum(["ext4","zfs"]).optional(),swap_size:x.string().optional(),pre_launch_script:x.string().optional(),env_pubkey:x.string().optional(),salt:x.string().optional().nullable()}).passthrough().superRefine((e,t)=>{Vn(e.docker_compose_file,e.pre_launch_script,t)}),Ra=g.object({app_id:g.string().nullable().optional(),app_env_encrypt_pubkey:g.string().nullable().optional(),compose_hash:g.string(),kms_info:be.nullable().optional(),fmspc:g.string().nullable().optional(),device_id:g.string().nullable().optional(),os_image_hash:g.string().nullable().optional(),instance_type:g.string().nullable().optional(),teepod_id:g.number().nullable().optional(),node_id:g.number().nullable().optional(),kms_id:g.string().nullable().optional(),kms_contract_id:g.union([g.string(),g.number()]).nullable().optional()}).passthrough().transform(e=>{if("teepod_id"in e&&e.teepod_id!==void 0){let{teepod_id:t,...n}=e;return{...n,node_id:t}}return e}),It="Name must be 5-63 characters, start with letter, and contain only letters/numbers/hyphens",xa=g.object({node_id:g.number().optional(),teepod_id:g.number().optional(),region:g.string().optional(),name:g.string().min(5,It).max(63,It).refine(e=>Ln(e),It),instance_type:g.string().optional(),image:g.string().optional(),vcpu:g.number().optional(),memory:g.number().optional(),disk_size:g.number().optional(),compose_file:g.object({allowed_envs:g.array(g.string()).optional(),pre_launch_script:g.string().optional(),docker_compose_file:g.string().optional(),name:g.string().optional().default(""),kms_enabled:g.boolean().optional(),gateway_enabled:g.boolean().optional(),tproxy_enabled:g.boolean().optional(),local_key_provider_enabled:g.boolean().optional(),key_provider:g.enum(["none","kms","local","tpm"]).optional(),key_provider_id:g.string().optional(),public_logs:g.boolean().optional(),public_sysinfo:g.boolean().optional(),public_tcbinfo:g.boolean().optional(),no_instance_id:g.boolean().optional(),secure_time:g.boolean().optional(),storage_fs:g.enum(["ext4","zfs"]).optional(),swap_size:g.string().optional(),port_policy:g.object({ports:g.array(g.object({port:g.number(),pp:g.boolean()})),restrict_mode:g.boolean()}).optional()}).passthrough().superRefine((e,t)=>{Vn(e.docker_compose_file,e.pre_launch_script,t)}),listed:g.boolean().optional(),kms_id:g.string().optional(),kms:g.enum(["PHALA","ETHEREUM","BASE"]).optional(),kms_contract:g.string().optional(),kms_contract_id:g.union([g.string(),g.number()]).optional(),key_provider_mode:g.enum(["kms","local"]).optional(),skip_gateway:g.boolean().optional(),env_keys:g.array(g.string()).optional(),nonce:g.number().optional(),app_id:g.string().optional()}).passthrough().transform(e=>!e.instance_type&&!e.vcpu&&!e.memory?{...e,instance_type:"tdx.small"}:e);function Ta(e){if(!e.compose_file)return e;let t={...e.compose_file};return typeof t.gateway_enabled=="boolean"&&typeof t.tproxy_enabled=="boolean"?delete t.tproxy_enabled:typeof t.tproxy_enabled=="boolean"&&typeof t.gateway_enabled>"u"&&(t.gateway_enabled=t.tproxy_enabled,delete t.tproxy_enabled,(typeof window<"u"?window.console:globalThis.console)&&console.warn("[phala/cloud] tproxy_enabled is deprecated, please use gateway_enabled instead. See docs for migration.")),{...e,compose_file:t}}var{action:ja,safeAction:Pa}=v(Ra,async(e,t)=>{let n=xa.parse(t),r=Ta(n);return typeof r.teepod_id=="number"&&typeof r.node_id!="number"&&console.warn("[phala/cloud] teepod_id is deprecated, please use node_id instead."),await e.post("/cvms/provision",r)}),Kn=w.object({name:w.string(),status:w.string(),teepod_id:w.number(),teepod:w.object({id:w.number(),name:w.string()}).nullable(),app_id:w.string().nullable(),vm_uuid:w.string().nullable(),instance_id:w.string().nullable(),app_url:w.string().nullable().default(null),base_image:w.string().nullable(),vcpu:w.number(),memory:w.number(),disk_size:w.number(),manifest_version:w.number().nullable().default(2),version:w.string().nullable().default("1.0.0"),runner:w.string().nullable().default("docker-compose"),docker_compose_file:w.string().nullable(),features:w.array(w.string()).nullable().default(["kms","tproxy-net"]),created_at:w.string(),encrypted_env_pubkey:w.string().nullable().optional(),app_auth_contract_address:w.string().nullable().optional(),deployer_address:w.string().nullable().optional()}).passthrough(),Hn=Kn.extend({id:w.number(),user_id:w.number().nullable()}),Gn=Kn.extend({id:w.string(),user_id:w.string().nullable()}),Nu=w.union([Hn,Gn]);var zu=w.object({encrypted_env:w.string().optional().nullable(),app_id:w.string(),compose_hash:w.string(),kms_id:w.string().optional(),kms_contract_id:w.union([w.string(),w.number()]).optional(),contract_address:w.string().optional(),deployer_address:w.string().optional(),env_keys:w.array(w.string()).optional().nullable()}).passthrough();function qa(e){return e==="2026-01-21"?Hn:Gn}async function Bn(e,t){let n=await e.post("/cvms",t);return qa(e.config.version).parse(n)}async function $a(e,t){try{return{success:!0,data:await Bn(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)}}}}function Tt(e){return e==null?e:Array.isArray(e)?e.map(Tt):e&&typeof e=="object"&&e.constructor===Object?Object.keys(e).sort().reduce((t,n)=>{let r=e[n];return t[n]=Tt(r),t},{}):e}function Wn(e){let t={...e};return t.runner==="bash"&&"docker_compose_file"in t?delete t.docker_compose_file:t.runner==="docker-compose"&&"bash_script"in t&&delete t.bash_script,"pre_launch_script"in t&&!t.pre_launch_script&&delete t.pre_launch_script,t}function Xn(e){let t=Tt(e),n=JSON.stringify(t,null,4);return n=n.replace(/": /g,'":'),n}function Na(e){let t=Wn(e),n=Xn(t);return Oa.createHash("sha256").update(n,"utf8").digest("hex")}function za(e){let t=e;return{...e,getHash:()=>Na(t),toString:()=>Xn(Wn(t))}}var Ua=Mn.transform(e=>za(e)),La=q,{action:Fa,safeAction:Da}=v(Ua,async(e,t)=>{let{cvmId:n}=La.parse(t);return await e.get(`/cvms/${n}/compose_file`)}),Va=ge.object({id:ge.string().optional(),uuid:ge.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).optional(),app_id:ge.string().refine(e=>!e.startsWith("app_")&&e.length===40,"app_id should be 40 characters without prefix").transform(e=>e.startsWith("app_")?e:`app_${e}`).optional(),instance_id:ge.string().refine(e=>!e.startsWith("instance_")&&e.length===40,"instance_id should be 40 characters without prefix").transform(e=>e.startsWith("instance_")?e:`instance_${e}`).optional(),app_compose:Mn,update_env_vars:ge.boolean().optional().nullable()}).refine(e=>!!(e.id||e.uuid||e.app_id||e.instance_id),"One of id, uuid, app_id, or instance_id must be provided").transform(e=>({cvmId:e.id||e.uuid||e.app_id||e.instance_id,request:{...e.app_compose,update_env_vars:e.update_env_vars},_raw:e})),Ma=ge.object({app_id:ge.string().nullable(),device_id:ge.string().nullable(),compose_hash:ge.string(),kms_info:be.nullable().optional(),compose_hash_registered:ge.boolean().optional().default(!1),compose_unchanged:ge.boolean().optional().default(!1)}).passthrough(),{action:Ka,safeAction:Ha}=v(Ma,async(e,t)=>{let n=Va.parse(t);return await e.post(`/cvms/${n.cvmId}/compose_file/provision`,n.request)}),Ga=_e.object({id:_e.string().optional(),uuid:_e.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).optional(),app_id:_e.string().refine(e=>!e.startsWith("app_")&&e.length===40,"app_id should be 40 characters without prefix").transform(e=>e.startsWith("app_")?e:`app_${e}`).optional(),instance_id:_e.string().refine(e=>!e.startsWith("instance_")&&e.length===40,"instance_id should be 40 characters without prefix").transform(e=>e.startsWith("instance_")?e:`instance_${e}`).optional(),compose_hash:_e.string().min(1,"Compose hash is required"),encrypted_env:_e.string().optional(),env_keys:_e.array(_e.string()).optional(),update_env_vars:_e.boolean().optional().nullable()}).refine(e=>!!(e.id||e.uuid||e.app_id||e.instance_id),"One of id, uuid, app_id, or instance_id must be provided").transform(e=>({cvmId:e.id||e.uuid||e.app_id||e.in