@phala/phala-cli
Version:
CLI for Managing Phala Cloud Services
110 lines (106 loc) • 68.1 kB
JavaScript
#!/usr/bin/env bun
import{a as we,b as r}from"./chunk-A4IAJHG6.js";import{Command as so}from"commander";import Se from"chalk";var ke=Se.hex("#cdfa50"),Ee=ke(`
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28C0\u28E0\u28E4\u28E4\u28E4\u28C0\u2840\u2800\u2880\u28C0\u28E4\u28E4\u28C0\u2840\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2880\u28F4\u287F\u281B\u2809\u2801\u2800\u2808\u2809\u281B\u283F\u281B\u2809\u2809\u2809\u2809\u2819\u2837\u28C4\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28A0\u28FF\u280B\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2818\u28E7\u2800\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28C0\u28FF\u2847\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28B8\u28C6\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2880\u28F4\u281E\u281B\u2809\u2819\u2803\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2808\u2809\u281B\u28B6\u28C4\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28A0\u28FF\u2803\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2808\u28FF\u28E6\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28B8\u28FF\u2840\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28A0\u28FF\u28FF\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2838\u28FF\u28F7\u28C4\u2840\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28C0\u28F4\u28FF\u28FF\u287F\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2819\u28BF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u281F\u2800\u2800\u28C0\u28F4\u28F6\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u281F\u2801\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2809\u281B\u283B\u283F\u283F\u283F\u283F\u2803\u2800\u2880\u28FE\u28FF\u28FF\u28FF\u283F\u283F\u283F\u283F\u283F\u283F\u283F\u283F\u283F\u283F\u281B\u280B\u2801\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28FE\u28FF\u287F\u280B\u2801\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2880\u28C0\u2864\u2824\u2824\u2834\u2812\u2812\u2812\u2812\u2812\u28BF\u287F\u2813\u2812\u2812\u2822\u2824\u2824\u2824\u28C0\u28C0\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28FE\u28EF\u28C0\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2801\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28C0\u28E8\u28FF\u28E6\u28E4\u28C0\u2840\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28BB\u28FF\u28FF\u28FF\u28FF\u28FF\u28F6\u28F6\u28F6\u28F6\u28F6\u28F6\u28F6\u28F6\u28F6\u28F6\u28F6\u28F6\u28FE\u28FF\u28FF\u28FF\u28FF\u28FF\u284F\u2809\u281B\u28FF\u28C6\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2818\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u2800\u2800\u28C0\u28C0\u28C0\u28C0\u2878\u283F\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u2800\u2800\u2800\u28F8\u287F\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2839\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u2800\u28B8\u28FF\u28FF\u28FF\u28FF\u2847\u2800\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u2803\u2880\u28E0\u28F4\u287F\u2803\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2819\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u283F\u2887\u28C0\u28C0\u28C0\u28C0\u28F8\u28FF\u28FF\u28FF\u28FF\u28FF\u287F\u283F\u283F\u281B\u281B\u2801\u2800\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2860\u2800\u2800\u2800\u2800\u2808\u283B\u28BF\u28FF\u28FF\u28FF\u2800\u28B8\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u287F\u280B\u2800\u2800\u2800\u2800\u2820\u28C4\u2800\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28B8\u28C6\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2809\u281B\u283F\u283F\u28FF\u28FF\u28FF\u28FF\u28FF\u283F\u281F\u280B\u2801\u2800\u2800\u2800\u2800\u2800\u2800\u28C0\u28FE\u2800\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2819\u283B\u28B6\u28E6\u28E4\u28C4\u28C0\u28C0\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28C0\u28C0\u28C0\u28E4\u28F4\u28F6\u283F\u281B\u2801\u2800\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2808\u2809\u2819\u281B\u283B\u283F\u283F\u283F\u283F\u28BF\u28FF\u28FF\u28FF\u283F\u283F\u283F\u283F\u281F\u281B\u281B\u2809\u2801\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800
`),mo=ke(`
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28C0\u28E0\u28E4\u28E4\u28E4\u28C0\u2840\u2800\u2880\u28C0\u28E4\u28E4\u28C0\u2840\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2880\u28F4\u287F\u281B\u2809\u2801\u2800\u2808\u2809\u281B\u283F\u281B\u2809\u2809\u2809\u2809\u2819\u2837\u28C4\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28A0\u28FF\u280B\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2818\u28E7\u2800\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28C0\u28FF\u2847\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28B8\u28C6\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2880\u28F4\u281E\u281B\u2809\u2819\u2803\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2808\u2809\u281B\u28B6\u28C4\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28A0\u28FF\u2803\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2808\u28FF\u28E6\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28B8\u28FF\u2840\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28A0\u28FF\u28FF\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2838\u28FF\u28F7\u28C4\u2840\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28C0\u28F4\u28FF\u28FF\u287F\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2819\u28BF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u281F\u2800\u2800\u28C0\u28F4\u28F6\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u281F\u2801\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2809\u281B\u283B\u283F\u283F\u283F\u283F\u2803\u2800\u2880\u28FE\u28FF\u28FF\u28FF\u283F\u283F\u283F\u283F\u283F\u283F\u283F\u283F\u283F\u283F\u281B\u280B\u2801\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28FE\u28FF\u287F\u280B\u2801\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2880\u28C0\u2864\u2824\u2824\u2834\u2812\u2812\u2812\u2812\u2812\u28BF\u287F\u2813\u2812\u2812\u2822\u2824\u2824\u2824\u28C0\u28C0\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28FE\u28EF\u28C0\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2801\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28C0\u28E8\u28FF\u28E6\u28E4\u28C0\u2840\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28BB\u28FF\u28FF\u28FF\u28FF\u28FF\u28F6\u28F6\u28F6\u28F6\u28F6\u28F6\u28F6\u28F6\u28F6\u28F6\u28F6\u28F6\u28FE\u28FF\u28FF\u28FF\u28FF\u28FF\u284F\u2809\u281B\u28FF\u28C6\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2818\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u2800\u2800\u28C0\u28C0\u28C0\u28C0\u2878\u283F\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u2800\u2800\u2800\u28F8\u287F\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2839\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u2800\u28B8\u28FF\u28FF\u28FF\u28FF\u2847\u2800\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u2803\u2880\u28E0\u28F4\u287F\u2803\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2819\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u283F\u2887\u28C0\u28C0\u28C0\u28C0\u28F8\u28FF\u28FF\u28FF\u28FF\u28FF\u287F\u283F\u283F\u281B\u281B\u2801\u2800\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2860\u2800\u2800\u2800\u2800\u2808\u283B\u28BF\u28FF\u28FF\u28FF\u2800\u28B8\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u287F\u280B\u2800\u2800\u2800\u2800\u2820\u28C4\u2800\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28B8\u28C6\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2809\u281B\u283F\u283F\u28FF\u28FF\u28FF\u28FF\u28FF\u283F\u281F\u280B\u2801\u2800\u2800\u2800\u2800\u2800\u2800\u28C0\u28FE\u2800\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2819\u283B\u28B6\u28E6\u28E4\u28C4\u28C0\u28C0\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u28C0\u28C0\u28C0\u28E4\u28F4\u28F6\u283F\u281B\u2801\u2800\u2800\u2800\u2800\u2800\u2800\u2800
\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2808\u2809\u2819\u281B\u283B\u283F\u283F\u283F\u283F\u28BF\u28FF\u28FF\u28FF\u283F\u283F\u283F\u283F\u281F\u281B\u281B\u2809\u2801\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800
`),co=Se.cyan("PHALA TEE CLOUD CLI");import{Command as dr}from"commander";import{Command as cr}from"commander";import $ from"fs";import me from"path";import I from"os";import W from"crypto";var N=me.join(I.homedir(),".phala-cloud"),O=me.join(N,"api-key"),ae=me.join(N,"docker-credentials.json");function be(){if(!$.existsSync(N))try{$.mkdirSync(N,{recursive:!0})}catch(t){throw r.error(`Failed to create directory ${N}:`,t),t}}function _e(){let t=[I.hostname(),I.platform(),I.arch(),I.cpus()[0]?.model||"",I.userInfo().username],e=W.createHash("sha256");return e.update(t.join("|")),e.digest()}function xe(t){try{let e=_e(),o=W.randomBytes(16),n=W.createCipheriv("aes-256-cbc",e.slice(0,32),o),i=n.update(t,"utf8","hex");return i+=n.final("hex"),o.toString("hex")+":"+i}catch(e){throw r.error("Encryption failed:",e),new Error("Failed to encrypt data")}}function $e(t){try{let e=_e(),o=t.split(":");if(o.length!==2)throw new Error("Invalid encrypted format");let n=Buffer.from(o[0],"hex"),i=o[1],a=W.createDecipheriv("aes-256-cbc",e.slice(0,32),n),m=a.update(i,"hex","utf8");return m+=a.final("utf8"),m}catch(e){throw r.error("Decryption failed:",e),new Error("Failed to decrypt data")}}async function Pe(t){be();try{let e=xe(t);$.writeFileSync(O,e,{mode:384})}catch(e){throw r.error("Failed to save API key:",e),e}}async function X(){try{if($.existsSync(O)){let t=$.readFileSync(O,"utf8").trim();return $e(t)}return null}catch(t){return r.error("Failed to read API key:",t),null}}async function U(){try{$.existsSync(O)?($.unlinkSync(O),r.success("API key removed successfully.")):r.warn("No API key found to remove.")}catch(t){throw r.error("Failed to remove API key:",t),t}}async function De(t){be();try{t.password=xe(t.password),$.writeFileSync(ae,JSON.stringify(t,null,2),{mode:384}),r.success("Docker credentials saved successfully.")}catch(e){throw r.error("Failed to save Docker credentials:",e),e}}async function x(){try{if($.existsSync(ae)){let t=$.readFileSync(ae,"utf8"),e=JSON.parse(t);return e.password&&(e.password=$e(e.password)),e}return null}catch(t){return r.error("Failed to read Docker credentials:",t),null}}import pr from"prompts";import Wt from"axios";var ce=process.env.CLOUD_API_URL||"https://cloud-api.phala.network",T=process.env.CLOUD_URL||"https://cloud.phala.network",Ie="0.0.1",pe="https://hub.docker.com/v2",Te="phalanetwork/tappd-simulator:latest",L=1,z=2048,j=20,C={USER_INFO:"/api/v1/auth/me",TEEPODS:"/api/v1/teepods?enabled=true",TEEPOD_IMAGES:t=>`/api/v1/teepods/${t}/images`,CVMS:t=>`/api/v1/cvms?user_id=${t}`,CVM_BY_APP_ID:t=>`/api/v1/cvms/app_${t}`,CVM_START:t=>`/api/v1/cvms/app_${t}/start`,CVM_STOP:t=>`/api/v1/cvms/app_${t}/stop`,CVM_RESTART:t=>`/api/v1/cvms/app_${t}/restart`,CVM_LOGS:t=>`/api/v1/cvms/app_${t}/logs`,CVM_FROM_CONFIGURATION:"/api/v1/cvms/from_cvm_configuration",CVM_PUBKEY:"/api/v1/cvms/pubkey/from_cvm_configuration",CVM_UPGRADE:t=>`/api/v1/cvms/app_${t}/compose`,CVM_ATTESTATION:t=>`/api/v1/cvms/app_${t}/attestation`,CVM_RESIZE:t=>`/api/v1/cvms/app_${t}/resources`},Fe=`version: '3.8'
services:
postgres:
image: postgres:15
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
- POSTGRES_DB=eliza
volumes:
- postgres-data:/var/lib/postgresql/data
ports:
- "127.0.0.1:5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
restart: always
eliza:
image: {{imageName}}:{{tag}}
container_name: elizav2
command: bun run start
stdin_open: true
tty: true
volumes:
- /var/run/tappd.sock:/var/run/tappd.sock
environment:
{{#each envVars}} - {{{this}}}
{{/each}}
ports:
- "3000:3000"
- "5173:5173"
depends_on:
postgres:
condition: service_healthy
restart: always
networks:
- eliza-network
networks:
eliza-network:
driver: bridge
volumes:
postgres-data:`,Ae=`version: '3.8'
services:
app:
image: {{imageName}}:{{tag}}
container_name: app
volumes:
- /var/run/tappd.sock:/var/run/tappd.sock
environment:
{{#each envVars}} - {{{this}}}
{{/each}}
restart: always
`;function le(t){try{return JSON.stringify(t)}catch(e){return e instanceof Error&&e.message.includes("cyclic")?"[Cyclic Object]":String(t)}}var ue=class{client;apiKey=null;constructor(e){r.debug(`Creating API client with base URL: ${e}`),this.client=Wt.create({baseURL:e,headers:{"Content-Type":"application/json","User-Agent":`tee-cloud-cli/${Ie}`}}),this.client.interceptors.request.use(async o=>{if(!this.apiKey){if(this.apiKey=await X(),!this.apiKey)throw new Error('API key not found. Please set an API key first with "phala auth login"');r.debug(`API key loaded: ${this.apiKey.substring(0,5)}...`)}return o.headers["X-API-Key"]=this.apiKey,r.debug(`Making request to: ${o.baseURL}${o.url}`),o}),this.client.interceptors.response.use(o=>(r.debug(`Received successful response from: ${o.config.url}`),o),o=>{if(o.response){let{status:n,data:i}=o.response;r.debug(`Received error response: ${n} - ${le(i)}`),n===401?r.error("Authentication failed. Please check your API key."):n===403?r.error("You do not have permission to perform this action."):n===404?r.error("Resource not found."):r.error(`API Error (${n}): ${i.message||le(i)}`)}else o.request?(r.error("No response received from the server. Please check your internet connection."),r.debug(`Request details: ${le(o.request).substring(0,200)}...`)):r.error(`Error: ${o.message}`);return Promise.reject(o)})}async get(e,o){try{return r.debug(`GET request to: ${e}`),(await this.client.get(e,o)).data}catch(n){throw r.debug(`GET request failed: ${n instanceof Error?n.message:String(n)}`),n}}async post(e,o,n){try{return r.debug(`POST request to: ${e}`),(await this.client.post(e,o,n)).data}catch(i){throw r.debug(`POST request failed: ${i instanceof Error?i.message:String(i)}`),i}}async put(e,o,n){try{return r.debug(`PUT request to: ${e}`),(await this.client.put(e,o,n)).data}catch(i){throw r.debug(`PUT request failed: ${i instanceof Error?i.message:String(i)}`),i}}async delete(e,o){try{return r.debug(`DELETE request to: ${e}`),(await this.client.delete(e,o)).data}catch(n){throw r.debug(`DELETE request failed: ${n instanceof Error?n.message:String(n)}`),n}}async patch(e,o,n){try{return r.debug(`PATCH request to: ${e}`),(await this.client.patch(e,o,n)).data}catch(i){throw r.debug(`PATCH request failed: ${i instanceof Error?i.message:String(i)}`),i}}};r.debug(`Initializing API client with URL: ${ce}`);var w=new ue(ce);import{z as s}from"zod";import{INVALID as Xt,ParseStatus as Qt,ZodIssueCode as F,ZodParsedType as Me,ZodType as er,addIssueToContext as A,z as Ve}from"zod";var tr="ZodDecimal",rr=/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/,G=class extends er{_parse(e){if(e.data!==null&&typeof e.data=="object"&&"toNumber"in e.data&&(e.data=e.data.toNumber()),this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==Me.number){let a=this._getOrReturnCtx(e);return A(a,{code:F.invalid_type,expected:Me.number,received:a.parsedType}),Xt}let n,i=new Qt;for(let a of this._def.checks)if(a.kind==="precision"){let m=e.data.toString().match(rr);Math.max((m[1]?m[1].length:0)-(m[2]?parseInt(m[2],10):0),0)>a.value&&(n=this._getOrReturnCtx(e,n),A(n,{code:F.custom,message:a.message,params:{precision:a.value}}),i.dirty())}else a.kind==="wholeNumber"?e.data.toString().split(".")[0].length>a.value&&(n=this._getOrReturnCtx(e,n),A(n,{code:F.custom,message:a.message,params:{wholeNumber:a.value}}),i.dirty()):a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(n=this._getOrReturnCtx(e,n),A(n,{code:F.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),i.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(n=this._getOrReturnCtx(e,n),A(n,{code:F.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),i.dirty()):a.kind==="finite"&&(Number.isFinite(e.data)||(n=this._getOrReturnCtx(e,n),A(n,{code:F.not_finite,message:a.message}),i.dirty()));return{status:i.value,value:e.data}}setLimit(e,o,n,i){return new G({...this._def,checks:[...this._def.checks,{kind:e,value:o,inclusive:n,message:i}]})}_addCheck(e){return new G({...this._def,checks:[...this._def.checks,e]})}lte(e,o){return this.setLimit("max",e,!0,o)}lt(e,o){return this.setLimit("max",e,!1,o)}max=this.lte;gt(e,o){return this.setLimit("min",e,!1,o)}gte(e,o){return this.setLimit("min",e,!0,o)}min=this.gte;precision(e,o){return this._addCheck({kind:"precision",value:e,message:o})}wholeNumber(e,o){return this._addCheck({kind:"wholeNumber",value:e,message:o})}get minValue(){let e=null;for(let o of this._def.checks)o.kind==="min"&&(e===null||o.value>e)&&(e=o.value);return e}get maxValue(){let e=null;for(let o of this._def.checks)o.kind==="max"&&(e===null||o.value<e)&&(e=o.value);return e}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:e})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:e})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:e})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:e})}finite(e){return this._addCheck({kind:"finite",message:e})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:e})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:e})}get isFinite(){let e=null,o=null;for(let n of this._def.checks){if(n.kind==="finite")return!0;n.kind==="min"?(o===null||n.value>o)&&(o=n.value):n.kind==="max"&&(e===null||n.value<e)&&(e=n.value)}return Number.isFinite(o)&&Number.isFinite(e)}},B=G;we(B,"create",e=>new G({checks:[],typeName:tr,coerce:e?.coerce??!1}));var Re=Ve.object({template:Ve.string().min(1,"Template cannot be empty")});var or=s.object({password:s.string(),registry:s.string().nullable(),username:s.string()}),nr=s.object({docker_compose_file:s.string(),docker_config:or.optional(),features:s.array(s.string()),kms_enabled:s.boolean(),manifest_version:s.number(),name:s.string(),public_logs:s.boolean(),public_sysinfo:s.boolean(),runner:s.string().optional(),salt:s.string().nullable().optional(),tproxy_enabled:s.boolean(),version:s.string().optional()}),sr=s.object({name:s.string(),image:s.string(),compose_file:nr,vcpu:s.number(),memory:s.number(),disk_size:s.number(),ports:s.array(s.any())}),ir=s.object({id:s.string(),name:s.string(),status:s.string(),uptime:s.string(),app_url:s.string(),app_id:s.string(),instance_id:s.string(),configuration:sr,exited_at:s.string(),boot_progress:s.string(),boot_error:s.string(),shutdown_progress:s.string(),image_version:s.string()}),ar=s.object({id:s.number(),username:s.string()}),mr=s.object({id:s.number(),name:s.string()}),de=s.object({hosted:ir,name:s.string(),managed_user:ar,node:mr,listed:s.boolean(),status:s.string(),in_progress:s.boolean(),dapp_dashboard_url:s.string().nullable(),syslog_endpoint:s.string(),allow_upgrade:s.boolean()}),Ne=s.object({id:s.number(),name:s.string(),status:s.string(),teepod_id:s.number(),teepod:s.object({id:s.number(),name:s.string()}),user_id:s.number(),app_id:s.string(),vm_uuid:s.string().nullable(),instance_id:s.string().nullable(),app_url:s.string().nullable(),base_image:s.string(),vcpu:s.number(),memory:s.number(),disk_size:s.number(),manifest_version:s.number(),version:s.string(),runner:s.string(),docker_compose_file:s.string(),features:s.array(s.string()).nullable(),created_at:s.string(),encrypted_env_pubkey:s.string()}),Oe=s.object({app_env_encrypt_pubkey:s.string(),app_id_salt:s.string()}),Ue=s.object({id:s.number(),teepod_id:s.number(),teepod:s.object({id:s.number(),name:s.string()}),name:s.string(),status:s.string(),in_progress:s.boolean(),app_id:s.string(),vm_uuid:s.string(),instance_id:s.string(),vcpu:s.number(),memory:s.number(),disk_size:s.number(),base_image:s.string(),encrypted_env_pubkey:s.string(),listed:s.boolean(),project_id:s.string(),project_type:s.string().nullable()}),Le=s.object({username:s.string(),email:s.string(),credits:B.create({coerce:!0}),role:s.string(),avatar:s.string(),flag_reset_password:s.boolean(),team_name:s.string(),team_tier:s.string(),trial_ended_at:s.string().nullable()}),Ro=s.array(de),ze=s.object({detail:s.string()}),No=s.object({key:s.string(),value:s.string()}),je=s.object({id:s.number(),name:s.string(),status:s.string()}),Be=s.object({name:s.string(),description:s.string().optional()});function Ge(t){try{return JSON.stringify(t)}catch(e){return e instanceof Error&&e.message.includes("cyclic")?"[Cyclic Object]":String(t)}}async function q(){try{r.debug(`Fetching user info from ${C.USER_INFO}`);let t=await w.get(C.USER_INFO);r.debug(`Received response: ${Ge(t)}`);try{return Le.parse(t)}catch(e){throw r.error(`Failed to parse user info response: ${e}`),r.debug(`Response structure: ${Ge(t)}`),e}}catch(t){throw r.error(`Failed to get user info: ${t instanceof Error?t.message:String(t)}`),new Error(`Failed to get user info: ${t instanceof Error?t.message:String(t)}`)}}var qe=new cr().name("login").description("Set the API key for authentication").argument("[api-key]","Phala Cloud API key to set").action(async t=>{try{if(!t)t=(await pr({type:"password",name:"apiKey",message:"Enter your API key:",validate:async o=>{if(o.length===0)return"API key cannot be empty";try{if(await Pe(o),!(await q()).username)return await U(),"Invalid API key"}catch{return"Invalid API key"}return!0}})).apiKey;else if(!(await q()).username)return await U(),"Invalid API key";r.success("API key validated and saved successfully"),r.info(`
You can check your authentication status with "phala auth status"`)}catch(e){r.error(`Failed to set API key: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}});import{Command as lr}from"commander";var Ke=new lr().name("logout").description("Remove the stored API key").action(async()=>{try{await U(),r.success("API key removed successfully")}catch(t){r.error(`Failed to remove API key: ${t instanceof Error?t.message:String(t)}`),process.exit(1)}});import{Command as ur}from"commander";var He=new ur().name("status").description("Check authentication status").option("-j, --json","Output in JSON format").option("-d, --debug","Enable debug output").action(async t=>{try{t.debug&&(process.env.DEBUG="true");let e=await X();if(!e){r.warn('Not authenticated. Please set an API key with "phala auth login"');return}r.debug(`Using API key: ${e.substring(0,5)}...`);let o=r.startSpinner("Checking authentication status");try{let n=await q();if(o.stop(!0),t.json){console.log(JSON.stringify(n,null,2));return}r.success(`Authenticated as ${n.username}`),r.break();let i={Username:n.username,Email:n.email,Role:n.role,Team:`${n.team_name} (${n.team_tier})`,Credits:`$${n.credits}`};n.trial_ended_at&&(i["Trial Ended At"]=n.trial_ended_at),console.table(i)}catch(n){o.stop(!1),r.error("Authentication failed. Your API key may be invalid or expired."),r.info('Please set a new API key with "phala auth login"'),t.debug&&r.debug(`Error details: ${n instanceof Error?n.message:String(n)}`)}}catch(e){r.error(`Failed to check authentication status: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}});var Ze=new dr().name("auth").description("Authenticate with Phala Cloud").addCommand(qe).addCommand(Ke).addCommand(He);import{Command as hr}from"commander";import{Command as fr}from"commander";import{z as Je}from"zod";async function M(){try{let t=await w.get(C.TEEPODS);return Je.array(je).parse(t)}catch(t){throw new Error(`Failed to get TEEPods: ${t instanceof Error?t.message:String(t)}`)}}async function Q(t){try{let e=await w.get(C.TEEPOD_IMAGES(t));return Je.array(Be).parse(e)}catch(e){throw new Error(`Failed to get TEEPod images: ${e instanceof Error?e.message:String(e)}`)}}var Ye=new fr().name("list").description("List available TEEPods").action(async()=>{try{let t=r.startSpinner("Fetching TEEPods"),e=await M();if(t.stop(!0),e.length===0){r.info("No TEEPods found");return}r.info("Available TEEPods:"),r.table(e,["id","name","status"])}catch(t){r.error(`Failed to list TEEPods: ${t instanceof Error?t.message:String(t)}`),process.exit(1)}});import{Command as gr}from"commander";import yr from"inquirer";var We=new gr().name("images").description("List available images for a TEEPod").option("-t, --teepod-id <teepodId>","TEEPod ID").action(async t=>{try{let e=r.startSpinner(`Fetching images for TEEPod ${t.teepodId}`);if(!t.teepodId){let n=r.startSpinner("Fetching available TEEPods"),i=await M();n.stop(!0),i.length===0&&(r.error("No TEEPods available. Please try again later."),process.exit(1));let{selectedTeepodId:a}=await yr.prompt([{type:"list",name:"selectedTeepodId",message:"Select a TEEPod:",choices:i.map(m=>({name:`${m.name} (${m.status})`,value:m.id}))}]);t.teepodId=a}let o=await Q(t.teepodId);if(e.stop(!0),o.length===0){r.info(`No images found for TEEPod ${t.teepodId}`);return}r.info(`Available images for TEEPod ${t.teepodId}:`),r.table(o,["name","description"])}catch(e){r.error(`Failed to list images: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}});var Xe=new hr().name("teepods").description("TEEPod management commands").addCommand(Ye).addCommand(We);import{Command as Fr}from"commander";import{Command as _r}from"commander";import{execa as tt}from"execa";import D from"fs";import fe from"path";import rt from"axios";import vr from"handlebars";import{exec as wr,spawn as Sr}from"child_process";import{promisify as kr}from"util";import Er from"os";import Cr from"inquirer";import Qe from"fs";import et from"path";function E(t,e=process.cwd()){let o=et.resolve(e,t);if(!Qe.existsSync(o))throw new Error(`File not found at ${o}`);return!0}async function V(t,e,o="file",n=process.cwd()){return(await Cr.prompt([{type:"input",name:o,message:t,default:e,validate:a=>{let m=et.resolve(n,a);return Qe.existsSync(m)?!0:`File not found at ${m}`}}]))[o]}var ee=kr(wr),ot=".phala-cloud/logs",br=".phala-cloud/compose",nt=10,h=class{username;image;registry;constructor(e,o,n){this.image=e,this.username=o||"",this.registry=n||""}ensureLogsDir(){let e=fe.resolve(ot);D.existsSync(e)||D.mkdirSync(e,{recursive:!0})}getLogFilePath(e){let o=new Date().toISOString().replace(/[:.]/g,"-");return fe.resolve(ot,`${this.image}-${e}-${o}.log`)}getSystemArchitecture(){let e=Er.arch();switch(e){case"arm":case"arm64":return"arm64";case"x64":return"amd64";default:return e}}spawnProcess(e,o,n){return new Promise((i,a)=>{let m=Sr(e,o),c=this.getLogFilePath(n);this.ensureLogsDir();let p=D.createWriteStream(c,{flags:"a"}),f=[],d=(u,y=!1)=>{let l=u.toString().split(`
`);p.write(u),l.forEach(g=>{g.trim()&&(f.push(g),f.length>nt&&f.shift(),console.clear(),console.log(`Latest ${nt} lines (full log at ${c}):`),console.log("-".repeat(50)),f.forEach(k=>{y?console.error(k):console.log(k)}))})};m.stdout.on("data",u=>d(u)),m.stderr.on("data",u=>d(u,!0)),m.on("close",u=>{p.end(),u===0?(console.log(`
Operation completed. Full log available at: ${c}`),i()):a(new Error(`Process exited with code ${u}. Check log file: ${c}`))}),m.on("error",u=>{p.end(),a(u)})})}setCredentials(e,o){this.username=e,o&&(this.registry=o)}async buildImage(e,o){try{let n=this.getSystemArchitecture(),i=`${this.username}/${this.image}:${o}`,a=r.startSpinner(`Building Docker image ${this.username}/${this.image}:${o}`);E(e);let m=["build","-t",i,"-f",e];return n==="arm64"&&(console.log("Detected arm64 architecture, using --platform linux/amd64"),m.push("--platform","linux/amd64")),m.push("."),await this.spawnProcess("docker",m,"build"),a.stop(!0,`Docker image ${i} built successfully`),!0}catch(n){return r.error(`Failed to build Docker image: ${n instanceof Error?n.message:String(n)}`),!1}}async pushImage(e){try{let o=r.startSpinner(`Pushing Docker image ${this.username}/${this.image}:${e} to Docker Hub`);if(!await x())throw o.stop(!1),new Error('Docker credentials not found. Please log in first with "phala docker login"');let i=`${this.username}/${this.image}:${e}`;return console.log(`Pushing image ${i} to Docker Hub...`),await this.spawnProcess("docker",["push",i],"push"),o.stop(!0,`Docker image ${i} pushed successfully`),!0}catch(o){return r.error(`Failed to push Docker image: ${o instanceof Error?o.message:String(o)}`),!1}}async listTags(){try{let e=r.startSpinner(`Listing tags for ${this.username}/${this.image}`),o=await rt.get(`${pe}/repositories/${this.username}/${this.image}/tags`);if(!o.data||!o.data.results)throw e.stop(!1),new Error("Failed to get tags from Docker Hub");let n=o.data.results.map(i=>i.name);return e.stop(!0,`Found ${n.length} tags`),n}catch(e){return r.error(`Failed to list tags: ${e instanceof Error?e.message:String(e)}`),[]}}async deleteTag(e){try{let o=r.startSpinner(`Deleting tag ${this.username}/${this.image}:${e}`),n=await x();if(!n)throw o.stop(!1),new Error('Docker credentials not found. Please log in first with "phala docker login"');let i=await rt.delete(`${pe}/repositories/${this.username}/${this.image}/tags/${e}`,{auth:{username:n.username,password:n.password}});return o.stop(!0,"Tag deleted successfully"),!0}catch(o){return r.error(`Failed to delete tag: ${o instanceof Error?o.message:String(o)}`),!1}}async login(e,o,n){try{let i=r.startSpinner(`Logging in to Docker Hub as ${e}`);return await tt("docker",["login",...n?[n]:[],"-u",e,"--password-stdin"],{input:o}),i.stop(!0,"Logged in to Docker Hub successfully"),!0}catch(i){return r.error(`Failed to login to Docker Hub: ${i instanceof Error?i.message:String(i)}`),!1}}async buildComposeFile(e,o,n){if(!this.username)throw new Error("Docker Hub username is required for building compose file");let i=n=="eliza"?Fe:Ae,a=Re.parse({template:i}),m=br;D.existsSync(m)||(r.info(`Creating directory: ${m}`),D.mkdirSync(m,{recursive:!0}));let c=[];o&&(c=D.readFileSync(o,"utf-8").split(`
`).filter(l=>l&&!l.startsWith("#")).map(l=>{let g=l.indexOf("#");return g>0&&(l=l.substring(0,g).trim()),l.trim()}).filter(l=>l.includes("=")).map(l=>{let[g,k]=l.split("=",2),v=g.trim();return(k?k.trim():"")===""?null:`${v}=${v}`}).filter(Boolean));let p=`${this.username}/${this.image}`,d=vr.compile(a.template,{noEscape:!0})({imageName:p,tag:e,envVars:c.map(y=>y.replace(/=.*/,"=${"+y.split("=")[0]+"}"))}),u=fe.join(m,`${this.image}-${e}-tee-compose.yaml`);return D.writeFileSync(u,d),r.success(`Backup of docker compose file created at: ${u}`),u}async runComposeLocally(e,o){try{let n=r.startSpinner(`Running Docker Compose file at ${e}
- If you run with the simulator, set DSTACK_SIMULATOR_ENDPOINT to http://host.docker.internal:8090`);E(e);let i=["-f",e,"up","-d"];return o&&(E(o),i.splice(2,0,"--env-file",o)),await tt("docker-compose",i),n.stop(!0,"Docker Compose file running successfully"),!0}catch(n){return r.error(`Failed to run Docker Compose file: ${n instanceof Error?n.message:String(n)}`),!1}}async runSimulator(e){try{r.info(`Running TEE simulator with image ${e}`),r.info("Pulling latest simulator image..."),await ee(`docker pull ${e}`),r.info("Starting simulator in background...");let{stdout:o}=await ee(`docker run -d --name tee-simulator --rm -p 8090:8090 ${e}`),n=o.trim();return r.success(`TEE simulator running successfully. Container ID: ${n}`),r.info(`
Useful commands:`),r.info(`- View logs: docker logs -f ${n}`),r.info(`- Stop simulator: docker stop ${n}`),!0}catch(o){return r.error(`Failed to run TEE simulator: ${o instanceof Error?o.message:String(o)}`),!1}}async stopSimulator(){try{let e=r.startSpinner("Stopping TEE simulator...");return await ee("docker stop tee-simulator"),e.stop(!0,"TEE simulator stopped successfully"),!0}catch(e){return r.error(`Failed to stop TEE simulator: ${e instanceof Error?e.message:String(e)}`),!1}}static async listLocalImages(){try{let{stdout:e}=await ee('docker images --format "{{.Repository}}:{{.Tag}}"');return e.split(`
`).filter(n=>n&&!n.includes("<none>")).map(n=>{let[i,a]=n.split(":"),m=i.split("/");return{name:m.length>1?m[1]:i,tag:a}})}catch(e){return r.error(`Failed to list local Docker images: ${e instanceof Error?e.message:String(e)}`),[]}}};import st from"prompts";var it=new _r().name("login").description("Login to Docker Hub").option("-u, --username <username>","Docker Hub username").option("-p, --password <password>","Docker Hub password").option("-r, --registry <registry>","Docker registry URL").action(async t=>{try{let e=t.username,o=t.password,n=t.registry;if(!e){let m=await st({type:"text",name:"username",message:"Enter your Docker Hub username:",validate:c=>c.length>0?!0:"Username cannot be empty"});m.username||(r.error("Username is required"),process.exit(1)),e=m.username}if(!o){let m=await st({type:"password",name:"password",message:"Enter your Docker Hub password:",validate:c=>c.length>0?!0:"Password cannot be empty"});m.password||(r.error("Password is required"),process.exit(1)),o=m.password}await new h("",e,n).login(e,o,n)||(r.error("Failed to login to Docker Hub"),process.exit(1)),await De({username:e,password:o,registry:n||null}),r.success("Logged in to Docker Hub successfully")}catch(e){r.error(`Failed to login to Docker Hub: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}});import{Command as xr}from"commander";import at from"path";import mt from"inquirer";import $r from"fs";var ct=new xr().name("build").description("Build a Docker image").option("-i, --image <image>","Image name").option("-t, --tag <tag>","Image tag").option("-f, --file <file>","Path to Dockerfile","Dockerfile").action(async t=>{try{let e=await x();if(e||(r.error('Docker credentials not found. Please login first with "phala docker login"'),process.exit(1)),!t.image){let m=await mt.prompt([{type:"input",name:"image",message:"Enter the Docker image name:",validate:c=>c.trim()?!0:"Image name is required"}]);t.image=m.image}if(!t.tag){let m=await mt.prompt([{type:"input",name:"tag",message:"Enter the Docker image tag:",default:"latest",validate:c=>c.trim()?!0:"Tag is required"}]);t.tag=m.tag}let o=at.resolve(process.cwd(),t.file);$r.existsSync(o)||(r.info(`Default Dockerfile not found at ${o}`),t.file=await V("Enter the path to your Dockerfile:","Dockerfile","file"));let n=at.resolve(process.cwd(),t.file);await new h(t.image,e.username,e.registry).buildImage(n,t.tag)||(r.error("Failed to build Docker image"),process.exit(1)),r.success(`Docker image ${e.username}/${t.image}:${t.tag} built successfully`)}catch(e){r.error(`Failed to build Docker image: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}});import{Command as Pr}from"commander";import pt from"inquirer";var lt=new Pr().name("push").description("Push a Docker image to Docker Hub").option("-i, --image <image>","Image name").option("-t, --tag <tag>","Image tag").action(async t=>{try{let e=await x();e||(r.error('Docker credentials not found. Please login first with "phala docker login"'),process.exit(1));let o=t.image,n=t.tag;if(!o||!n){let m=await h.listLocalImages();if(m.length===0&&(r.error('No local Docker images found. Please build an image first with "phala docker build"'),process.exit(1)),!o){let c=Array.from(new Set(m.map(f=>f.name))),{selectedImage:p}=await pt.prompt([{type:"list",name:"selectedImage",message:"Select an image to push:",choices:c}]);o=p}if(!n){let c=m.filter(f=>f.name===o).map(f=>f.tag);c.length===0&&(r.error(`No tags found for image ${o}`),process.exit(1));let{selectedTag:p}=await pt.prompt([{type:"list",name:"selectedTag",message:`Select a tag for ${o}:`,choices:c}]);n=p}}await new h(o,e.username,e.registry).pushImage(n)||(r.error("Failed to push Docker image"),process.exit(1)),r.success(`Docker image ${e.username}/${o}:${n} pushed successfully`)}catch(e){r.error(`Failed to push Docker image: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}});import{Command as Dr}from"commander";var ut=new Dr().name("tags").description("List tags for a Docker image").requiredOption("-i, --image <image>","Image name").option("-j, --json","Output in JSON format").action(async t=>{try{let e=await x();e||(r.error('Docker credentials not found. Please login first with "teecloud docker login"'),process.exit(1));let n=await new h(t.image,e.username,e.registry).listTags();if(n.length===0){r.info(`No tags found for image ${e.username}/${t.image}`);return}if(t.json){console.log(JSON.stringify(n,null,2));return}r.info(`Tags for image ${e.username}/${t.image}:`),n.forEach(i=>{r.info(`- ${i}`)})}catch(e){r.error(`Failed to list tags: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}});import{Command as Ir}from"commander";import te from"inquirer";import dt from"fs";import ft from"path";var gt=new Ir().name("run").description("Run a Docker Compose setup").option("-c, --compose <compose>","Path to docker-compose.yml file").option("-e, --env-file <env-file>","Path to environment variables file").option("--skip-env","Skip environment variables file prompt",!0).action(async t=>{try{let e=t.compose,o=t.env;if(e)try{E(e)}catch{r.error(`File not found: ${e}`),process.exit(1)}else{let a=ft.join(process.cwd(),"docker-compose.yml");if(dt.existsSync(a)){let{useDefault:c}=await te.prompt([{type:"confirm",name:"useDefault",message:"Use docker-compose.yml in current directory?",default:!0}]);c&&(e=a)}if(!e){let{composePath:c}=await te.prompt([{type:"input",name:"composePath",message:"Enter path to docker-compose.yml file:",validate:p=>E(p)?!0:"File not found"}]);e=c}}if(!o&&!t.skipEnv){let a=ft.join(process.cwd(),".env");if(dt.existsSync(a)){let{useDefault:c}=await te.prompt([{type:"confirm",name:"useDefault",message:"Use .env file in current directory?",default:!0}]);c&&(o=a)}if(!o){let{envPath:c}=await te.prompt([{type:"input",name:"envPath",message:"Enter path to environment variables file:",validate:p=>{try{return E(p),!0}catch{return`File not found: ${p}`}}}]);o=c}}let n=new h("");if(o){try{E(o)}catch{r.error(`File not found: ${o}`),process.exit(1)}r.info(`Running Docker Compose with compose file: ${e} and env file: ${o}`)}else r.info(`Running Docker Compose with compose file: ${e} without env file`);await n.runComposeLocally(e,o)||(r.error("Failed to run Docker Compose"),process.exit(1)),r.success("Docker Compose is running")}catch(e){r.error(`Failed to run Docker Compose: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}});import{Command as Tr}from"commander";import b from"inquirer";import K from"fs";import re from"path";var yt=new Tr().name("generate").description("Generate a Docker Compose file").option("-i, --image <image>","Docker image name to use in the compose file").option("-t, --tag <tag>","Docker image tag to use in the compose file").option("-e, --env-file <envFile>","Path to environment variables file").option("-o, --output <output>","Output path for generated docker-compose.yml").option("--template <template>","Template to use for the generated docker-compose.yml").option("--manual","Skip automatic image detection and enter image/tag manually").action(async t=>{try{let e=await x();(!e||!e.username)&&(r.error("Docker Hub username not found. Please login first with `tcc docker login`"),process.exit(1));let o=t.image||"",n=t.tag||"";if((!o||!n)&&!t.manual)try{r.info("Detecting local Docker images...");let p=await h.listLocalImages();if(p.length===0)r.warn("No local Docker images found. You will need to enter image details manually.");else{let f=new Map;if(p.forEach(d=>{f.has(d.name)||f.set(d.name,[]),f.get(d.name)?.push(d.tag)}),o&&!n){let d=f.get(o)||[];if(d.length>0){let{imageTag:u}=await b.prompt([{type:"list",name:"imageTag",message:`Select a tag for ${o}:`,choices:[...d,new b.Separator,"[ Enter manually ]"]}]);u!=="[ Enter manually ]"&&(n=u)}else r.warn(`No tags found for image ${o}. You will need to enter the tag manually.`)}else if(!o){let d=Array.from(f.keys()),{imageName:u}=await b.prompt([{type:"list",name:"imageName",message:"Select a Docker image:",choices:[...d,new b.Separator,"[ Enter manually ]"]}]);if(u!=="[ Enter manually ]"){o=u;let y=f.get(u)||[],{imageTag:l}=await b.prompt([{type:"list",name:"imageTag",message:"Select a tag:",choices:[...y,new b.Separator,"[ Enter manually ]"]}]);l!=="[ Enter manually ]"&&(n=l)}}}}catch(p){r.warn(`Failed to detect local images: ${p instanceof Error?p.message:String(p)}`),r.info("Continuing with manual input...")}if(!o){let{inputImage:p}=await b.prompt([{type:"input",name:"inputImage",message:"Enter Docker image name:",validate:f=>f.trim()?!0:"Image name cannot be empty"}]);o=p}if(!n){let{inputTag:p}=await b.prompt([{type:"input",name:"inputTag",message:`Enter tag for image ${o}:`,validate:f=>f.trim()?!0:"Tag cannot be empty"}]);n=p}let i=t.envFile;if(i)try{E(i)}catch{r.error(`File not found: ${i}`),process.exit(1)}else{let p=re.join(process.cwd(),".env");if(K.existsSync(p)){let{useDefault:d}=await b.prompt([{type:"confirm",name:"useDefault",message:"Use .env file in current directory?",default:!0}]);d&&(i=p)}if(!i){let{envPath:d}=await b.prompt([{type:"input",name:"envPath",message:"Enter path to environment variables file:",validate:u=>{try{return E(u),!0}catch{return`File not found: ${u}`}}}]);i=d}}let a=t.output;if(!a&&(a=re.join(process.cwd(),"docker-compose.yml"),K.existsSync(a))){let{confirmOverwrite:p}=await b.prompt([{type:"confirm",name:"confirmOverwrite",message:`File ${a} already exists. Overwrite?`,default:!1}]);if(!p){let{customPath:f}=await b.prompt([{type:"input",name:"customPath",message:"Enter alternative output path:",default:re.join(process.cwd(),`${o}-${n}-compose.yml`)}]);a=f}}let m=new h(o,e.username,e.registry);i?r.info(`Generating Docker Compose file for ${o}:${n} using env file: ${i}`):r.info(`Generating Docker Compose file for ${o}:${n} without env file`);let c=await m.buildComposeFile(n,i,t.template);if(c!==a){let p=re.dirname(a);K.existsSync(p)||(r.info(`Creating directory: ${p}`),K.mkdirSync(p,{recursive:!0})),K.copyFileSync(c,a)}r.success(`Docker Compose file generated successfully: ${a}`)}catch(e){r.error(`Failed to generate Docker Compose file: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}});var ht=new Fr().name("docker").description("Login to Docker Hub and manage Docker images").addCommand(it).addCommand(ct).addCommand(lt).addCommand(ut).addCommand(gt).addCommand(yt);import{Command as Vr}from"commander";import{Command as Ar}from"commander";var Ct=new Ar().name("start").description("Start the TEE simulator").option("-i, --image <image>","Simulator image",Te).action(async t=>{try{await new h("").runSimulator(t.image)||(r.error("Failed to start TEE simulator"),process.exit(1))}catch(e){r.error(`Failed to start TEE simulator: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}});import{Command as Mr}from"commander";var vt=new Mr().name("stop").description("Stop the TEE simulator").action(async()=>{try{await new h("").stopSimulator()||(r.error("Failed to stop TEE simulator"),process.exit(1))}catch(t){r.error(`Failed to stop TEE simulator: ${t instanceof Error?t.message:String(t)}`),process.exit(1)}});var wt=new Vr().name("simulator").description("TEE simulator commands").addCommand(Ct).addCommand(vt);import{Command as jr}from"commander";import{Command as Ur}from"commander";import H from"fs";import St from"path";import Rr from"os";var oe=St.join(Rr.homedir(),".phala-cloud"),ye=St.join(oe,"config.json"),ge={apiUrl:"https://cloud-api.phala.network",cloudUrl:"https://cloud.phala.network",defaultTeepodId:3,defaultImage:"dstack-dev-0.3.5",defaultVcpu:1,defaultMemory:2048,defaultDiskSize:20};function Nr(){if(!H.existsSync(oe))try{H.mkdirSync(oe,{recursive:!0})}catch(t){throw r.error(`Failed to create directory ${oe}:`,t),t}}function ne(){try{if(H.existsSync(ye)){let t=H.readFileSync(ye,"utf8");return{...ge,...JSON.parse(t)}}return ge}catch(t){return r.error("Failed to load configuration:",t),ge}}function Or(t){Nr();try{H.writeFileSync(ye,JSON.stringify({...ne(),...t},null,2),{mode:384}),r.success("Configuration saved successfully.")}catch(e){throw r.error("Failed to save configuration:",e),e}}function kt(t){return ne()[t]}function Et(t,e){let o=ne();o[t]=e,Or(o)}function bt(){return ne()}var _t=new Ur().name("get").description("Get a configuration value").argument("<key>","Configuration key").action(t=>{try{let e=kt(t);e===void 0&&(r.error(`Configuration key '${t}' not found`),process.exit(1)),r.info(`${t}: ${JSON.stringify(e)}`)}catch(e){r.error(`Failed to get configuration value: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}});import{Command as Lr}from"commander";var xt=new Lr().name("set").description("Set a configuration value").argument("<key>","Configuration key").argument("<value>","Configuration value").action((t,e)=>{try{let o=e;if(e.startsWith("{")||e.startsWith("[")||e==="true"||e==="false"||!isNaN(Number(e)))try{o=JSON.parse(e)}catch{}Et(t,o),r.success(`Configuration value for '${t}' set successfully`)}catch(o){r.error(`Failed to set configuration value: ${o instanceof Error?o.message:String(o)}`),process.exit(1)}});import{Command as zr}from"commander";var $t=new zr().name("list").description("List all configuration values").option("-j, --json","Output in JSON format").action(t=>{try{let e=bt();if(t.json){console.log(JSON.stringify(e,null,2));return}r.info("Configuration values:");for(let[o,n]of Object.entries(e))r.info(`${o}: ${JSON.stringify(n)}`)}catch(e){r.error(`Failed to list configuration values: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}});var Pt=new jr().name("config").description("Manage your local configuration").addCommand(_t).addCommand(xt).addCommand($t);import{Command as no}from"commander";import{Command as Br}from"commander";import{z as Dt}from"zod";async function he(){try{let t=await w.get(C.CVMS(0));return Dt.array(de).parse(t)}catch(t){throw new Error(`Failed to get CVMs: ${t instanceof Error?t.message:String(t)}`)}}async function R(t){try{let e=await w.get(C.CVM_BY_APP_ID(t));return Ue.parse(e)}catch(e){throw new Error(`Failed to get CVM by App ID: ${e instanceof Error?e.message:String(e)}`)}}async function It(t){try{let e=await w.post(C.CVM_PUBKEY,t);return Oe.parse(e)}catch(e){throw new Error(`Failed to get pubkey from CVM: ${e instanceof Error?e.message:String(e)}`)}}async function Tt(t){try{let e=await w.post(C.CVM_FROM_CONFIGURATION,t);return Ne.parse(e)}catch(e){throw e instanceof Dt.ZodError?(console.error("Schema validation error:",JSON.stringify(e.errors,null,2)),console.error("API response:",JSON.stringify(e.format(),null,2)),new Error(`Response validation failed: ${JSON.stringify(e.errors)}`)):new Error(`Failed to create CVM: ${e instanceof Error?e.message:String(e)}`)}}async function Ft(t){try{return await w.post(C.CVM_START(t)),!0}catch(e){throw new Error(`Failed to start CVM: ${e instanceof Error?e.message: