UNPKG

phala

Version:
58 lines (55 loc) 31.7 kB
var Te=Object.defineProperty;var we=(r,t,n)=>t in r?Te(r,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[t]=n;var re=(r,t,n)=>(we(r,typeof t!="symbol"?t+"":t,n),n);import b from"chalk";function Re(r){let t=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|");return r.replace(new RegExp(t,"g"),"")}function D(r){return Re(r).length}function z(r,t){if(!r)return[""];if(D(r)<=t)return[r];let n=[],o="",s=0,a=r.split(/(\s+)/).filter(c=>c.trim().length>0);for(let c of a){let C=D(c);if(C>t){o&&(n.push(o),o="",s=0),n.push(c);continue}s+C+(s>0?1:0)>t?(n.push(o),o=c,s=C):o?(o=`${o} ${c}`,s+=C+1):(o=c,s=C)}return o&&n.push(o),n}var p={error:(r,...t)=>{console.error(b.red("\u2717"),b.red(r),...t)},warn:(r,...t)=>{console.log(b.yellow("\u26A0"),b.yellow(r),...t)},info:(r,...t)=>{console.log(b.blue("\u2139"),b.blue(r),...t)},success:(r,...t)=>{console.log(b.green("\u2713"),b.green(r),...t)},debug:(r,...t)=>{process.env.DEBUG&&console.log(b.gray("\u{1F50D}"),b.gray(r),...t)},table:(r,t)=>{if(r.length===0){console.log(b.yellow("No data to display"));return}if(t)if(typeof t[0]=="string"){let n=t.map(o=>({key:o,header:o.charAt(0).toUpperCase()+o.slice(1)}));Z(r,{columns:n,borderStyle:"rounded",headerStyle:o=>b.cyan.bold(o)})}else Z(r,{columns:t,borderStyle:"rounded",headerStyle:n=>b.cyan.bold(n)});else Z(r,{borderStyle:"rounded",headerStyle:n=>b.cyan.bold(n)})},keyValueTable:(r,t)=>{let o={...{borderStyle:"rounded",enableTextWrapping:!0,maxDepth:2,formatKeys:!0,keyFormatter:y=>{let k=["URL","ID","API","UI","URI","CPU","GPU","RAM","JSON","XML","HTML","HTTP","HTTPS","SSH","FTP","IP","TCP","UDP","DNS","SSL","TLS","SQL","VCPU","CVM","TEE","IO"],S={teepod:"TEEPod",dstack:"Dstack"},w;y.includes("_")?w=y.split("_").map(T=>T.charAt(0).toUpperCase()+T.slice(1).toLowerCase()).join(" "):y.includes("-")?w=y.split("-").map(T=>T.charAt(0).toUpperCase()+T.slice(1).toLowerCase()).join(" "):w=y.charAt(0).toUpperCase()+y.slice(1).replace(/([a-z])([A-Z])/g,"$1 $2");for(let T of k){let I=new RegExp(`\\b${T.toLowerCase()}\\b`,"gi");w=w.replace(I,T)}for(let[T,I]of Object.entries(S)){let B=new RegExp(`\\b${T}\\b`,"gi");w=w.replace(B,I)}return w},valueFormatter:y=>String(y??"")},...t},{include:s,exclude:a,keyFormatter:c,valueFormatter:C,formatKeys:R,keyWidth:x,valueWidth:E,borderStyle:$,enableTextWrapping:m,maxDepth:u}=o,l=Object.keys(r);if(s&&(l=l.filter(y=>s.includes(y))),a&&(l=l.filter(y=>!a.includes(y))),l.length===0){console.log(b.yellow("No properties to display"));return}let g=l.map(y=>{let k=r[y],S;return k==null?S="":typeof k=="object"&&!Array.isArray(k)?S=ne(k,0,u):Array.isArray(k)?k.length===0?S="[]":typeof k[0]=="object"?S=`[${k.length} items]`:S=`[${k.join(", ")}]`:S=String(k),C&&(S=C(k,y)),{key:R&&c?b.cyan.bold(c(y)):b.cyan.bold(y),value:S}}),h=oe(),i=x,d=E;if(i||(i=Math.max(...g.map(y=>D(y.key)),10),i=Math.min(i,Math.floor(h/3))),!d){d=Math.max(...g.map(S=>D(S.value)),10),d+=3;let y=7,k=h-i-y;d=Math.min(d,k)}let f=Ee($),M=`${f.topLeft}${f.horizontal.repeat(i+2)}${f.topT}${f.horizontal.repeat(d+2)}${f.topRight}`,A=`${f.leftT}${f.horizontal.repeat(i+2)}${f.cross}${f.horizontal.repeat(d+2)}${f.rightT}`;console.log(M),console.log(A),g.forEach((y,k)=>{let S=m?z(y.key,i):[y.key],w=m?z(y.value,d):[y.value],T=Math.max(S.length,w.length);for(let I=0;I<T;I++){let B=S[I]||"",te=w[I]||"",xe=B+" ".repeat(Math.max(0,i-D(B))),Se=te+" ".repeat(Math.max(0,d-D(te)));console.log(`${f.vertical} ${xe} ${f.vertical} ${Se} ${f.vertical}`)}k<g.length-1&&console.log(`${f.leftT}${f.horizontal.repeat(i+2)}${f.cross}${f.horizontal.repeat(d+2)}${f.rightT}`)});let K=`${f.bottomLeft}${f.horizontal.repeat(i+2)}${f.bottomT}${f.horizontal.repeat(d+2)}${f.bottomRight}`;console.log(K)},startSpinner:r=>(process.stdout.write(`${b.blue("\u27F3")} ${r}... `),{stop:(t=!0,n)=>{let o=t?b.green("\u2713"):b.red("\u2717"),s=n?`: ${n}`:"";console.log(`${o}${s}`)}}),break(){console.log("")}};function ne(r,t,n){if(t>=n)return"[Nested Object]";if(r==null)return"";if(Array.isArray(r))return r.length===0?"[]":`[${r.length} items]`;let o=[];for(let[s,a]of Object.entries(r))a==null?o.push(`${s}: `):typeof a=="object"?o.push(`${s}: ${ne(a,t+1,n)}`):o.push(`${s}: ${a}`);return o.join(", ")}function Ee(r="single"){return{single:{topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",leftT:"\u251C",rightT:"\u2524",topT:"\u252C",bottomT:"\u2534",cross:"\u253C"},double:{topLeft:"\u2554",topRight:"\u2557",bottomLeft:"\u255A",bottomRight:"\u255D",horizontal:"\u2550",vertical:"\u2551",leftT:"\u2560",rightT:"\u2563",topT:"\u2566",bottomT:"\u2569",cross:"\u256C"},rounded:{topLeft:"\u256D",topRight:"\u256E",bottomLeft:"\u2570",bottomRight:"\u256F",horizontal:"\u2500",vertical:"\u2502",leftT:"\u251C",rightT:"\u2524",topT:"\u252C",bottomT:"\u2534",cross:"\u253C"}}[r]}function oe(){return process.stdout.columns||80}function Pe(r,t,n={}){let o=oe(),s=n.borderChars??3,c=(n.additionalBorderWidth??1)+t.length*s,C=o-c,R={},x=0,E=0;for(let u of t){let l=u.key;if(u.fixedWidth!==void 0){R[l]=u.fixedWidth,x+=u.fixedWidth;continue}let g=u.minWidth??u.header.length,h;u.getWidth?h=Math.max(g,u.header.length,...r.map(i=>u.getWidth(i))):u.getValue?h=Math.max(g,u.header.length,...r.map(i=>String(u.getValue(i)||"").length)):h=Math.max(g,u.header.length,...r.map(i=>String(i[u.key]||"").length)),R[l]=h,x+=h,E+=u.weight??1}let $=Math.max(0,C-x);if($>0&&E>0)for(let u of t){let l=u.key;if(u.fixedWidth===void 0&&u.weight){let g=Math.floor($*(u.weight/E));R[l]+=g}}let m=Object.values(R).reduce((u,l)=>u+l,0)+c;if(m>o){let u=C/(m-c),l={};for(let g of t){let h=g.key,i=g.minWidth??g.header.length;l[h]=Math.max(i,Math.floor(R[h]*u))}return l}return R}function Z(r,t={}){if(t.keyValueMode&&r.length===1){let m=r[0],u=[];t.columns||(t.columns=Object.keys(m).map(l=>({key:l,header:l.charAt(0).toUpperCase()+l.slice(1).replace(/([A-Z])/g," $1")})));for(let l of t.columns){let g=String(l.key),h;if(l.accessor)h=l.accessor(m);else if(typeof l.key=="string"&&l.key.includes(".")){let i=l.key.split("."),d=m;for(let f of i){if(d==null){h="";break}d=d[f]}h=d}else h=m[l.key];l.formatter&&(h=l.formatter(h)),u.push({key:l.header||g,value:h})}r=u,t.columns=[{key:"key",minWidth:15},{key:"value",minWidth:20}]}if(r.length===0){console.log(b.yellow("No data to display"));return}let o={...{includeHeaders:!0,border:!0,borderStyle:"single",headerStyle:m=>b.bold(m),cellStyle:m=>m,enableTextWrapping:!0},...t},s=o.columns;if(s)s=s.map(m=>({...m,enableTextWrapping:m.enableTextWrapping!==void 0?m.enableTextWrapping:o.enableTextWrapping}));else{let m=r[0];s=Object.keys(m).map(u=>({key:u,header:u.charAt(0).toUpperCase()+u.slice(1),enableTextWrapping:o.enableTextWrapping}))}let c={single:{topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",leftT:"\u251C",rightT:"\u2524",topT:"\u252C",bottomT:"\u2534",cross:"\u253C"},double:{topLeft:"\u2554",topRight:"\u2557",bottomLeft:"\u255A",bottomRight:"\u255D",horizontal:"\u2550",vertical:"\u2551",leftT:"\u2560",rightT:"\u2563",topT:"\u2566",bottomT:"\u2569",cross:"\u256C"},rounded:{topLeft:"\u256D",topRight:"\u256E",bottomLeft:"\u2570",bottomRight:"\u256F",horizontal:"\u2500",vertical:"\u2502",leftT:"\u251C",rightT:"\u2524",topT:"\u252C",bottomT:"\u2534",cross:"\u253C"}}[o.borderStyle],C=s.map(m=>({key:m.key,header:m.header||String(m.key),minWidth:m.minWidth||3,weight:m.weight,enableTextWrapping:m.enableTextWrapping,getValue:m.accessor?u=>m.accessor(u):u=>{if(typeof m.key=="string"&&m.key.includes(".")){let l=m.key.split("."),g=u;for(let h of l){if(g==null)return"";g=g[h]}return g??""}return u[m.key]??""}})),R=Pe(r,C),x=s.map((m,u)=>({...m,width:R[C[u].key]})),E=x.map(m=>m.header||String(m.key)),$=(m,u)=>{let l=x.map(i=>{let d;if(i.accessor)d=i.accessor(m);else if(typeof i.key=="string"&&i.key.includes(".")){let M=i.key.split("."),A=m;for(let K of M){if(A==null){d="";break}A=A[K]}d=A??""}else d=m[i.key]??"";let f=i.formatter?i.formatter(d):String(d||"");return i.enableTextWrapping?{lines:z(f,i.width),key:String(i.key)}:{lines:[f.length>i.width?f.substring(0,i.width-1)+"\u2026":f],key:String(i.key)}}),g=Math.max(...l.map(i=>i.lines.length)),h=[];for(let i=0;i<g;i++){let d=l.map((f,M)=>{let A=f.lines[i]||"";return o.cellStyle(A.padEnd(x[M].width),u,f.key)});h.push(d)}return h};if(o.border){let m=c.topLeft+x.map(l=>c.horizontal.repeat(l.width+2)).join(c.topT)+c.topRight;if(console.log(m),o.includeHeaders){let l=x.map((i,d)=>({lines:i.enableTextWrapping?z(E[d],i.width):[E[d]],width:i.width})),g=Math.max(...l.map(i=>i.lines.length));for(let i=0;i<g;i++){let d=c.vertical+l.map(f=>{let M=f.lines[i]||"";return" "+o.headerStyle(M.padEnd(f.width))+" "}).join(c.vertical)+c.vertical;console.log(d)}let h=c.leftT+x.map(i=>c.horizontal.repeat(i.width+2)).join(c.cross)+c.rightT;console.log(h)}r.forEach((l,g)=>{let h=$(l,g);if(h.forEach(i=>{console.log(c.vertical+i.map(d=>` ${d} `).join(c.vertical)+c.vertical)}),g<r.length-1&&h.length>1){let i=c.leftT+x.map(d=>c.horizontal.repeat(d.width+2)).join(c.cross)+c.rightT;console.log(i)}});let u=c.bottomLeft+x.map(l=>c.horizontal.repeat(l.width+2)).join(c.bottomT)+c.bottomRight;console.log(u)}else{if(o.includeHeaders){let m=x.map((g,h)=>({lines:g.enableTextWrapping?z(E[h],g.width):[E[h]],width:g.width})),u=Math.max(...m.map(g=>g.lines.length));for(let g=0;g<u;g++){let h=m.map(i=>{let d=i.lines[g]||"";return o.headerStyle(d.padEnd(i.width))}).join(" ");console.log(h)}let l=x.map(g=>"\u2500".repeat(g.width)).join(" ");console.log(l)}r.forEach((m,u)=>{let l=$(m,u);l.forEach(g=>{console.log(g.join(" "))}),u<r.length-1&&l.length>1&&console.log("")})}console.log(`Total: ${r.length} rows`)}import $e from"axios";import P from"node:fs";import H from"node:path";import L from"node:os";import G from"node:crypto";var F=H.join(L.homedir(),".phala-cloud"),U=H.join(F,"api-key"),q=H.join(F,"docker-credentials.json");function se(){if(!P.existsSync(F))try{P.mkdirSync(F,{recursive:!0})}catch(r){throw p.error(`Failed to create directory ${F}:`,r),r}}function ie(){let r=[L.hostname(),L.platform(),L.arch(),L.cpus()[0]?.model||"",L.userInfo().username],t=G.createHash("sha256");return t.update(r.join("|")),t.digest()}function Ae(r){try{let t=ie(),n=G.randomBytes(16),o=G.createCipheriv("aes-256-cbc",t.slice(0,32),n),s=o.update(r,"utf8","hex");return s+=o.final("hex"),n.toString("hex")+":"+s}catch(t){throw p.error("Encryption failed:",t),new Error("Failed to encrypt data")}}function Ie(r){try{let t=ie(),n=r.split(":");if(n.length!==2)throw new Error("Invalid encrypted format");let o=Buffer.from(n[0],"hex"),s=n[1],a=G.createDecipheriv("aes-256-cbc",t.slice(0,32),o),c=a.update(s,"hex","utf8");return c+=a.final("utf8"),c}catch(t){throw p.error("Decryption failed:",t),new Error("Failed to decrypt data")}}async function ot(r){se();try{let t=Ae(r);P.writeFileSync(U,t,{mode:384})}catch(t){throw p.error("Failed to save API key:",t),t}}async function ae(){try{if(P.existsSync(U)){let r=P.readFileSync(U,"utf8").trim();return Ie(r)}return null}catch(r){return p.error("Failed to read API key:",r),null}}async function st(){try{P.existsSync(U)?(P.unlinkSync(U),p.success("API key removed successfully.")):p.warn("No API key found to remove.")}catch(r){throw p.error("Failed to remove API key:",r),r}}async function it(r){se();try{P.writeFileSync(q,JSON.stringify(r,null,2),{mode:384}),p.success("Docker information saved successfully.")}catch(t){throw p.error("Failed to save Docker information:",t),t}}async function at(){try{if(P.existsSync(q)){let r=P.readFileSync(q,"utf8");return JSON.parse(r)}return null}catch(r){return p.error("Failed to read Docker credentials:",r),null}}var Y=process.env.CLOUD_API_URL||"https://cloud-api.phala.network",lt=process.env.CLOUD_URL||"https://cloud.phala.network",ce="0.0.1";var pt="phalanetwork/tappd-simulator:latest",mt=2,ut=4096,gt=40,dt="dstack-0.3.6",v={USER_INFO:"/api/v1/auth/me",TEEPODS:"/api/v1/teepods/available",TEEPOD_IMAGES:r=>`/api/v1/teepods/${r}/images`,CVMS:r=>`/api/v1/cvms?user_id=${r}`,CVM_BY_APP_ID:r=>`/api/v1/cvms/app_${r}`,CVM_NETWORK:r=>`/api/v1/cvms/app_${r}/network`,CVM_START:r=>`/api/v1/cvms/app_${r}/start`,CVM_STOP:r=>`/api/v1/cvms/app_${r}/stop`,CVM_RESTART:r=>`/api/v1/cvms/app_${r}/restart`,CVM_LOGS:r=>`/api/v1/cvms/app_${r}/logs`,CVM_FROM_CONFIGURATION:"/api/v1/cvms/from_cvm_configuration",CVM_PUBKEY:"/api/v1/cvms/pubkey/from_cvm_configuration",CVM_UPGRADE:r=>`/api/v1/cvms/app_${r}/compose`,CVM_ATTESTATION:r=>`/api/v1/cvms/app_${r}/attestation`,CVM_RESIZE:r=>`/api/v1/cvms/app_${r}/resources`,CVM_COMPOSE:r=>`/api/v1/cvms/${r}/compose`,REPLICATE_CVM:r=>`/api/v1/cvms/${r}/replicas`},ft=`version: '3.8' services: postgres: image: ankane/pgvector:latest environment: - POSTGRES_PASSWORD=postgres - POSTGRES_USER=postgres - POSTGRES_DB=eliza - PGDATA=/var/lib/postgresql/data/pgdata volumes: - postgres-data:/var/lib/postgresql/data:rw ports: - '127.0.0.1:5432:5432' healthcheck: test: ['CMD-SHELL', 'pg_isready -U $\${POSTGRES_USER} -d $\${POSTGRES_DB}'] interval: 5s timeout: 5s retries: 5 restart: always networks: - eliza-network eliza: image: {{imageName}} command: bun run start volumes: - /var/run/tappd.sock:/var/run/tappd.sock environment: {{#each envVars}} - {{{this}}} {{/each}} ports: - '3000:3000' - '50000-50100:50000-50100/udp' depends_on: postgres: condition: service_healthy restart: always networks: - eliza-network networks: eliza-network: driver: bridge volumes: postgres-data:`,ht=`version: '3.8' services: app: image: {{imageName}} container_name: app volumes: - /var/run/tappd.sock:/var/run/tappd.sock environment: {{#each envVars}} - {{{this}}} {{/each}} restart: always `;function J(r){try{return JSON.stringify(r)}catch(t){return t instanceof Error&&t.message.includes("cyclic")?"[Cyclic Object]":String(r)}}var X=class{client;apiKey=null;constructor(t){p.debug(`Creating API client with base URL: ${t}`),this.client=$e.create({baseURL:t,headers:{"Content-Type":"application/json","User-Agent":`tee-cloud-cli/${ce}`}}),this.client.interceptors.request.use(async n=>{if(!this.apiKey){if(this.apiKey=await ae(),!this.apiKey)throw new Error('API key not found. Please set an API key first with "phala auth login"');p.debug(`API key loaded: ${this.apiKey.substring(0,5)}...`)}return n.headers["X-API-Key"]=this.apiKey,p.debug(`Making request to: ${n.baseURL}${n.url}`),n}),this.client.interceptors.response.use(n=>(p.debug(`Received successful response from: ${n.config.url}`),n),n=>{if(n.response){let{status:o,data:s}=n.response;p.debug(`Received error response: ${o} - ${J(s)}`),o===401?p.error("Authentication failed. Please check your API key."):o===403?p.error("You do not have permission to perform this action."):o===404?p.error("Resource not found."):p.error(`API Error (${o}): ${s.message||J(s)}`)}else n.request?(p.error("No response received from the server. Please check your internet connection."),p.debug(`Request details: ${J(n.request).substring(0,200)}...`)):p.error(`Error: ${n.message}`);return Promise.reject(n)})}async get(t,n){try{return p.debug(`GET request to: ${t}`),(await this.client.get(t,n)).data}catch(o){throw p.debug(`GET request failed: ${o instanceof Error?o.message:String(o)}`),o}}async post(t,n,o){try{return p.debug(`POST request to: ${t}`),(await this.client.post(t,n,o)).data}catch(s){throw p.debug(`POST request failed: ${s instanceof Error?s.message:String(s)}`),s}}async put(t,n,o){try{return p.debug(`PUT request to: ${t}`),(await this.client.put(t,n,o)).data}catch(s){throw p.debug(`PUT request failed: ${s instanceof Error?s.message:String(s)}`),s}}async delete(t,n){try{return p.debug(`DELETE request to: ${t}`),(await this.client.delete(t,n)).data}catch(o){throw p.debug(`DELETE request failed: ${o instanceof Error?o.message:String(o)}`),o}}async patch(t,n,o){try{return p.debug(`PATCH request to: ${t}`),(await this.client.patch(t,n,o)).data}catch(s){throw p.debug(`PATCH request failed: ${s instanceof Error?s.message:String(s)}`),s}}};p.debug(`Initializing API client with URL: ${Y}`);var _=new X(Y);import{z as e}from"zod";import{INVALID as Me,ParseStatus as De,ZodIssueCode as O,ZodParsedType as le,ZodType as Le,addIssueToContext as V,z as pe}from"zod";var Oe="ZodDecimal",Ve=/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/,j=class extends Le{_parse(t){if(t.data!==null&&typeof t.data=="object"&&"toNumber"in t.data&&(t.data=t.data.toNumber()),this._def.coerce&&(t.data=Number(t.data)),this._getType(t)!==le.number){let a=this._getOrReturnCtx(t);return V(a,{code:O.invalid_type,expected:le.number,received:a.parsedType}),Me}let o,s=new De;for(let a of this._def.checks)if(a.kind==="precision"){let c=t.data.toString().match(Ve);Math.max((c[1]?c[1].length:0)-(c[2]?parseInt(c[2],10):0),0)>a.value&&(o=this._getOrReturnCtx(t,o),V(o,{code:O.custom,message:a.message,params:{precision:a.value}}),s.dirty())}else a.kind==="wholeNumber"?t.data.toString().split(".")[0].length>a.value&&(o=this._getOrReturnCtx(t,o),V(o,{code:O.custom,message:a.message,params:{wholeNumber:a.value}}),s.dirty()):a.kind==="min"?(a.inclusive?t.data<a.value:t.data<=a.value)&&(o=this._getOrReturnCtx(t,o),V(o,{code:O.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),s.dirty()):a.kind==="max"?(a.inclusive?t.data>a.value:t.data>=a.value)&&(o=this._getOrReturnCtx(t,o),V(o,{code:O.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),s.dirty()):a.kind==="finite"&&(Number.isFinite(t.data)||(o=this._getOrReturnCtx(t,o),V(o,{code:O.not_finite,message:a.message}),s.dirty()));return{status:s.value,value:t.data}}setLimit(t,n,o,s){return new j({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:o,message:s}]})}_addCheck(t){return new j({...this._def,checks:[...this._def.checks,t]})}lte(t,n){return this.setLimit("max",t,!0,n)}lt(t,n){return this.setLimit("max",t,!1,n)}max=this.lte;gt(t,n){return this.setLimit("min",t,!1,n)}gte(t,n){return this.setLimit("min",t,!0,n)}min=this.gte;precision(t,n){return this._addCheck({kind:"precision",value:t,message:n})}wholeNumber(t,n){return this._addCheck({kind:"wholeNumber",value:t,message:n})}get minValue(){let t=null;for(let n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxValue(){let t=null;for(let n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:t})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:t})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:t})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:t})}finite(t){return this._addCheck({kind:"finite",message:t})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:t})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:t})}get isFinite(){let t=null,n=null;for(let o of this._def.checks){if(o.kind==="finite")return!0;o.kind==="min"?(n===null||o.value>n)&&(n=o.value):o.kind==="max"&&(t===null||o.value<t)&&(t=o.value)}return Number.isFinite(n)&&Number.isFinite(t)}},N=j;re(N,"create",t=>new j({checks:[],typeName:Oe,coerce:t?.coerce??!1}));var It=pe.object({template:pe.string().min(1,"Template cannot be empty")});var Ne=e.object({password:e.string(),registry:e.string().nullable(),username:e.string()}),ze=e.object({docker_compose_file:e.string(),docker_config:Ne.optional(),features:e.array(e.string()),kms_enabled:e.boolean(),manifest_version:e.number(),name:e.string(),public_logs:e.boolean(),public_sysinfo:e.boolean(),runner:e.string().optional(),salt:e.string().nullable().optional(),tproxy_enabled:e.boolean(),version:e.string().optional()}),Fe=e.object({name:e.string(),image:e.string(),compose_file:ze.nullable(),vcpu:e.number(),memory:e.number(),disk_size:e.number(),ports:e.array(e.any())}),Ue=e.object({id:e.string(),name:e.string(),status:e.string(),uptime:e.string(),app_url:e.string(),app_id:e.string(),instance_id:e.string(),configuration:Fe,exited_at:e.string(),boot_progress:e.string(),boot_error:e.string(),shutdown_progress:e.string(),image_version:e.string()}),je=e.object({id:e.number(),username:e.string()}),We=e.object({id:e.number(),name:e.string(),region_identifier:e.string().optional()}),Q=e.object({hosted:Ue,name:e.string(),managed_user:je,node:We,listed:e.boolean(),status:e.string(),in_progress:e.boolean(),dapp_dashboard_url:e.string().nullable(),syslog_endpoint:e.string(),allow_upgrade:e.boolean()}),W=e.object({id:e.number(),name:e.string(),status:e.string(),teepod_id:e.number().nullable(),teepod:e.object({id:e.number(),name:e.string()}).nullable(),user_id:e.number(),app_id:e.string(),vm_uuid:e.string().nullable(),instance_id:e.string().nullable(),app_url:e.string().nullable(),base_image:e.string(),vcpu:e.number(),memory:e.number(),disk_size:e.number(),manifest_version:e.number(),version:e.string(),runner:e.string(),docker_compose_file:e.string(),features:e.array(e.string()).nullable(),created_at:e.string(),encrypted_env_pubkey:e.string()}),me=e.object({app_env_encrypt_pubkey:e.string(),app_id_salt:e.string()}),ue=e.object({id:e.number(),teepod_id:e.number().nullable(),teepod:e.object({id:e.number(),name:e.string()}).nullable(),name:e.string(),status:e.string(),in_progress:e.boolean(),app_id:e.string(),vm_uuid:e.string(),instance_id:e.string().nullable(),vcpu:e.number(),memory:e.number(),disk_size:e.number(),base_image:e.string(),encrypted_env_pubkey:e.string(),listed:e.boolean(),project_id:e.string(),project_type:e.string().nullable()}),ge=e.object({username:e.string(),email:e.string(),credits:N.create({coerce:!0}),granted_credits:N.create({coerce:!0}),role:e.string(),avatar:e.string(),flag_reset_password:e.boolean(),team_name:e.string(),team_tier:e.string(),trial_ended_at:e.string().nullable()}),Ot=e.array(Q),de=e.object({detail:e.string()}),Vt=e.object({key:e.string(),value:e.string()}),ee=e.object({name:e.string(),description:e.string().optional(),version:e.array(e.number()).optional(),is_dev:e.boolean().optional(),os_image_hash:e.string().nullable().optional(),rootfs_hash:e.string().optional(),shared_ro:e.boolean().optional(),cmdline:e.string().optional(),kernel:e.string().optional(),initrd:e.string().optional(),hda:e.string().nullable().optional(),rootfs:e.string().optional(),bios:e.string().optional()}),Be=e.object({teepod_id:e.number().nullable(),id:e.number().optional(),name:e.string(),listed:e.boolean().optional(),resource_score:e.number().optional(),remaining_vcpu:e.number().optional(),remaining_memory:e.number().optional(),remaining_cvm_slots:e.number().optional(),images:e.array(ee).optional(),region_identifier:e.string().optional(),dedicated_for_team_id:e.number().nullable().optional(),support_onchain_kms:e.boolean().optional(),fmspc:e.string().nullable().optional(),device_id:e.string().nullable().optional()}),Ge=e.object({max_instances:e.number().nullable(),max_vcpu:e.number().nullable(),max_memory:e.number().nullable(),max_disk:e.number().nullable()}),Ke=e.object({id:e.string(),url:e.string(),version:e.string(),chain_id:e.number(),kms_contract_address:e.string(),gateway_app_id:e.string()}),fe=e.object({tier:e.string(),capacity:Ge,nodes:e.array(Be),kms_list:e.array(Ke).optional()}),he=e.object({is_online:e.boolean(),is_public:e.boolean(),error:e.string().nullable(),internal_ip:e.string(),latest_handshake:e.string(),public_urls:e.array(e.object({app:e.string(),instance:e.string()}))}),ye=e.object({compose_file:e.object({bash_script:e.string().nullable(),docker_compose_file:e.string(),docker_config:e.object({password:e.string(),registry:e.string().nullable(),username:e.string()}),features:e.array(e.string()),kms_enabled:e.boolean(),manifest_version:e.number(),name:e.string(),pre_launch_script:e.string(),public_logs:e.boolean(),public_sysinfo:e.boolean(),runner:e.string(),salt:e.string(),tproxy_enabled:e.boolean(),version:e.string()}),env_pubkey:e.string(),salt:e.string()}),be=e.object({id:e.number(),name:e.string(),status:e.string(),teepod_id:e.number(),teepod:e.object({id:e.number(),name:e.string()}),user_id:e.number(),app_id:e.string(),vm_uuid:e.string(),instance_id:e.string().nullable(),app_url:e.string().nullable(),base_image:e.string(),vcpu:e.number(),memory:e.number(),disk_size:e.number(),manifest_version:e.number(),version:e.string().nullable(),runner:e.string(),docker_compose_file:e.string(),features:e.array(e.string()).nullable(),created_at:e.string(),encrypted_env_pubkey:e.string()}),ve=e.object({is_online:e.boolean(),is_public:e.boolean(),error:e.string().nullable(),app_certificates:e.array(e.object({subject:e.object({common_name:e.string().nullable(),organization:e.string().nullable(),country:e.string().nullable(),state:e.string().nullable().optional(),locality:e.string().nullable().optional()}),issuer:e.object({common_name:e.string().nullable(),organization:e.string().nullable(),country:e.string().nullable()}),serial_number:e.string(),not_before:e.string(),not_after:e.string(),version:e.string(),fingerprint:e.string(),signature_algorithm:e.string(),sans:e.string().nullable(),is_ca:e.boolean(),position_in_chain:e.number(),quote:e.string().nullable()})).nullable(),tcb_info:e.object({mrtd:e.string(),rootfs_hash:e.string(),rtmr0:e.string(),rtmr1:e.string(),rtmr2:e.string(),rtmr3:e.string(),event_log:e.array(e.object({imr:e.number(),event_type:e.number(),digest:e.string(),event:e.string(),event_payload:e.string()}))}).nullable(),compose_file:e.string().nullable()});function _e(r){try{return JSON.stringify(r)}catch(t){return t instanceof Error&&t.message.includes("cyclic")?"[Cyclic Object]":String(r)}}async function Bt(){try{p.debug(`Fetching user info from ${v.USER_INFO}`);let r=await _.get(v.USER_INFO);p.debug(`Received response: ${_e(r)}`);try{return ge.parse(r)}catch(t){throw p.error(`Failed to parse user info response: ${t}`),p.debug(`Response structure: ${_e(r)}`),t}}catch(r){throw p.error(`Failed to get user info: ${r instanceof Error?r.message:String(r)}`),new Error(`Failed to get user info: ${r instanceof Error?r.message:String(r)}`)}}import Ze from"inquirer";import{z as Ce}from"zod";async function ke(){try{let r=await _.get(v.CVMS(0));return Ce.array(Q).parse(r)}catch(r){throw new Error(`Failed to get CVMs: ${r instanceof Error?r.message:String(r)}`)}}async function er(r){let n=(await ke()).find(o=>o.hosted?.app_id===r||`app_${o.hosted?.app_id}`===r);if(!n)p.error(`CVM with App ID app_${r} not detected`),process.exit(1);else return p.success(`CVM with App ID app_${r} detected`),n.hosted?.app_id||""}async function tr(r){try{let t=await _.get(v.CVM_BY_APP_ID(r));return ue.parse(t)}catch(t){throw new Error(`Failed to get CVM by App ID: ${t instanceof Error?t.message:String(t)}`)}}async function rr(r){try{let t=await _.post(v.CVM_PUBKEY,r);return me.parse(t)}catch(t){throw new Error(`Failed to get pubkey from CVM: ${t instanceof Error?t.message:String(t)}`)}}async function nr(r){try{let t=await _.get(v.CVM_NETWORK(r));return he.parse(t)}catch(t){throw new Error(`Failed to get network information for CVM: ${t instanceof Error?t.message:String(t)}`)}}async function or(r){try{let t=await _.post(v.CVM_FROM_CONFIGURATION,r);return W.parse(t)}catch(t){throw t instanceof Ce.ZodError?(p.error("Schema validation error:",JSON.stringify(t.errors,null,2)),p.error("API response:",JSON.stringify(t.format(),null,2)),new Error(`Response validation failed: ${JSON.stringify(t.errors)}`)):new Error(`Failed to create CVM: ${t instanceof Error?t.message:String(t)}`)}}async function sr(r){try{let t=await _.post(v.CVM_START(r));return W.parse(t)}catch(t){throw new Error(`Failed to start CVM: ${t instanceof Error?t.message:String(t)}`)}}async function ir(r){try{let t=await _.post(v.CVM_STOP(r));return W.parse(t)}catch(t){throw new Error(`Failed to stop CVM: ${t instanceof Error?t.message:String(t)}`)}}async function ar(r){try{let t=await _.post(v.CVM_RESTART(r));return W.parse(t)}catch(t){throw new Error(`Failed to restart CVM: ${t instanceof Error?t.message:String(t)}`)}}async function cr(r,t){try{let n=await _.put(v.CVM_UPGRADE(r),t);return de.parse(n)}catch(n){throw new Error(`Failed to upgrade CVM: ${n instanceof Error?n.message:String(n)}`)}}async function lr(r){try{return await _.delete(v.CVM_BY_APP_ID(r)),!0}catch(t){throw new Error(`Failed to delete CVM: ${t instanceof Error?t.message:String(t)}`)}}async function pr(r){try{return await _.put(v.CVM_BY_APP_ID(r.app_id),r)}catch(t){throw new Error(`Failed to update CVM: ${t instanceof Error?t.message:String(t)}`)}}async function mr(){let r=p.startSpinner("Fetching available CVMs"),t=await ke();if(r.stop(!0),!t||t.length===0){p.info("No CVMs found for your account");return}let n=t.map(s=>{let a=s.hosted?.app_id||s.hosted?.id,c=s.name||s.hosted?.name,C=s.status||s.hosted?.status;return{name:`${c||"Unnamed"} (${a}) - Status: ${C||"Unknown"}`,value:a}}),{selectedCvm:o}=await Ze.prompt([{type:"list",name:"selectedCvm",message:"Select a CVM:",choices:n}]);return o}async function ur(r){try{let t=await _.get(v.CVM_ATTESTATION(r));try{return ve.parse(t)}catch(n){return p.debug(`Validation error: ${n instanceof Error?n.message:String(n)}`),{is_online:!!t?.is_online,is_public:!!t?.is_public,error:typeof t?.error=="string"?t.error:null,app_certificates:Array.isArray(t?.app_certificates)?t.app_certificates:null,tcb_info:t?.tcb_info||null,compose_file:typeof t?.compose_file=="string"?t.compose_file:null}}}catch(t){throw new Error(`Failed to get attestation information: ${t instanceof Error?t.message:String(t)}`)}}async function gr(r){try{let t=await _.get(v.CVM_COMPOSE(r));return ye.parse(t)}catch(t){throw new Error(`Failed to get CVM compose config: ${t instanceof Error?t.message:String(t)}`)}}async function dr(r,t){try{let n=await _.post(v.REPLICATE_CVM(r),t);return be.parse(n)}catch(n){throw new Error(`Failed to replicate CVM: ${n instanceof Error?n.message:String(n)}`)}}async function fr(r,t,n,o,s){try{let a={};if(t!==void 0&&(a.vcpu=t),n!==void 0&&(a.memory=n),o!==void 0&&(a.disk_size=o),s!==void 0&&(a.allow_restart=s),Object.keys(a).length===0)throw new Error("At least one resource parameter must be provided");return await _.patch(v.CVM_RESIZE(r),a),!0}catch(a){throw new Error(`Failed to resize CVM: ${a instanceof Error?a.message:String(a)}`)}}import{z as qe}from"zod";async function He(){try{let r=await _.get(v.TEEPODS);return fe.parse(r)}catch(r){throw new Error(`Failed to get TEEPods: ${r instanceof Error?r.message:String(r)}`)}}async function Tr(r){try{let n=(await He()).nodes.find(s=>s.teepod_id===Number(r));if(n&&n.images&&n.images.length>0)return n.images;let o=await _.get(v.TEEPOD_IMAGES(r));return qe.array(ee).parse(o)}catch(t){throw new Error(`Failed to get TEEPod images: ${t instanceof Error?t.message:String(t)}`)}}export{p as a,ot as b,ae as c,st as d,it as e,at as f,lt as g,pt as h,mt as i,ut as j,gt as k,dt as l,ft as m,ht as n,X as o,_ as p,It as q,Ne as r,ze as s,Fe as t,Ue as u,je as v,We as w,Q as x,W as y,me as z,ue as A,ge as B,Ot as C,de as D,Vt as E,ee as F,Be as G,Ge as H,Ke as I,fe as J,he as K,ye as L,be as M,ve as N,Bt as O,ke as P,er as Q,tr as R,rr as S,nr as T,or as U,sr as V,ir as W,ar as X,cr as Y,lr as Z,pr as _,mr as $,ur as aa,gr as ba,dr as ca,fr as da,He as ea,Tr as fa}; //# sourceMappingURL=chunk-6GN3UXCF.js.map