vast-ai-provisioner 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- import"dotenv/config";import{program as e}from"@commander-js/extra-typings";import{existsSync as t}from"fs";import{fileURLToPath as o}from"url";import{filesize as n}from"filesize";import{sprintf as a}from"sprintf-js";import{resolve as s,dirname as r,join as i}from"path";import{readFile as c,readdir as p}from"fs/promises";import{ExitPromptError as l}from"@inquirer/core";import m from"@npmcli/package-json";import{formatDistanceToNow as d,fromUnixTime as f}from"date-fns";import{select as h,confirm as u,checkbox as y}from"@inquirer/prompts";import g from"lodash.uniq";import w from"chalk";import{interpolateRgb as _}from"d3-interpolate";const $="https://console.vast.ai/api/v0",x=/rtx\s*5[0-9]{3}/i,S=()=>s(r(o(import.meta.url)),".."),b=e=>e?e.map(e=>` "${e}"`).join("\n"):"",v=async e=>{const t=await fetch(e);return parseInt(t.headers.get("Content-Length")??"0",10)},I=async e=>{const t=new Map,o=await p(e),n=(await Promise.all(o.map(t=>c(i(e,t),"utf-8")))).map(e=>JSON.parse(e));for(let e=0;e<o.length;e++)t.set(o[e],n[e]);return t},T=(e,t)=>{const o=t.reduce((e,t)=>e<t.search.totalHour?e:t.search.totalHour,100),s=t.reduce((e,t)=>e>t.search.totalHour?e:t.search.totalHour,0);return t.filter(e=>!x.test(e.gpu_name)).filter(t=>t.search.totalHour<=e.maxHourlyCost).map(e=>{const t=n(1e6*e.gpu_ram,{exponent:3,round:0,roundingMethod:"floor"}),r=_("#00ff00","#ff0000")((e.search.totalHour-o)/(s-o)).replace("rgb(","").replace(")","").split(",").map(e=>parseInt(e,10)),i=`#${((1<<24)+(r[0]<<16)+(r[1]<<8)+r[2]).toString(16).slice(1)}`;return{name:a("%-6s %-12s %-16s %8s %s",t,e.gpu_name,e.geolocation,`${Math.floor(e.inet_down)} Mbps`,w.bgHex(i)(`$${e.search.totalHour.toFixed(3)}/hr`)),value:e}})},P=async e=>{try{const o=await(async e=>{try{const o=i(S(),"templates");let n;if(e.template)n=i(o,`${e.template}.json`);else{const e=await I(o),t=await h({message:"Please choose a template to deploy.",choices:Array.from(e.entries().map(([e,t])=>({name:t.description?`${t.name} - ${t.description}`:t.name,value:e})))});n=i(o,t)}if(!t(n))throw new Error(`Unable to find template at ${n}!`);return JSON.parse(await c(n,"utf-8"))}catch(e){console.error(e),process.exit(1)}})(e),a=await(async e=>{try{const t=i(S(),"modules");console.log("Reading module JSON from ./modules");const o=await I(t);console.log("Fetching file sizes...");const a=Array.from(await Promise.all(o.entries().map(async([,t])=>{if(t.template!==e.name)return[];t.fileSizes=new Map,t.totalSize=0;for(const[,e]of Object.entries(t.files))for(const o of e){const e=await v(o);t.fileSizes.set(o,e),t.totalSize+=e}return[{name:`${t.name} (${n(t.totalSize)})`,value:t}]}))).flat();return a.length?await y({loop:!1,message:"Please choose the modules you would like to include.",choices:a}):[]}catch(e){console.error(e),process.exit(1)}})(o),s=await(async e=>{try{const t=await fetch(`${$}/search/asks`,{method:"PUT",body:JSON.stringify({q:{type:"on-demand",verified:{eq:!0},rentable:{eq:!0},rented:{eq:!1},num_gpus:{eq:1},gpu_ram:{gte:1024*e.minVram},inet_down:{gte:1e3},direct_port_count:{lte:e.maxPorts},limit:25,order:[["dph_total","asc"],["inet_down","asc"]]}}),headers:{Accept:"application/json","Content-Type":"application/json"},redirect:"follow"}),{offers:o}=await t.json();return o}catch(e){console.error(e),process.exit(1)}})(e),r=await h({message:"Choose the instance you would like to request.",choices:T(e,s),loop:!1});let p=o.size;if(a.length){const e=[];for(const t of a)for(const[o,n]of t.fileSizes.entries())e.includes(o)||(e.push(o),p+=n)}p/=1e9,p=Math.ceil(p),p*=1e9;const l=r.search.diskHour*(p/1e10),m=`$${(r.search.gpuCostPerHour+l).toFixed(3)}/hr`,w=`$${l.toFixed(3)}/hr`,_=`\nTemplate: ${o.name}\nModules:\n${a.map(e=>` * ${e.name} (${n(e.totalSize)})`).join("\n")}\nDisk Size: ${n(p)}\n\nAre you SURE you want create the instance?\n\nIt will be automatically destroyed in ${d(f(r.end_date))}.\n\nYou will be charged ${m} while it is running and ${w} while it is stopped!\n\nIt is YOUR responsibility to make sure that it has been stopped or destroyed correctly!\n`;if(!await u({message:_,default:!1}))return console.log("Exiting because user declined to deploy.");console.log(`Deploying ${o.name} to instance ${r}...`);const x={...o.environment};o.script&&(x.PROVISIONER_SCRIPT=await(async(e,o)=>{try{const n=i(S(),"scripts",e.script);if(!t(n))throw new Error(`Could not find script at ${n}!`);let a=await c(n,"utf-8");if(e.fileTypes.length&&o.length){const t=Object.fromEntries(e.fileTypes.map(e=>[e,[]]));for(const n of o)for(const o of e.fileTypes)t[o]=g([...t[o],...n.files[o]??[]]);for(const o of e.fileTypes)t[o].length&&(a=a.replace(`{{ ${o.toUpperCase()} }}`,b(t[o])))}const s=new FormData;s.append("api_dev_key",process.env.PASTEBIN_API_KEY),s.append("api_option","paste"),s.append("api_paste_code",a),s.append("api_paste_private","1"),s.append("api_paste_format","bash"),s.append("api_paste_name","provision.sh"),s.append("api_paste_expire_date","10M");const r=await fetch("https://pastebin.com/api/api_post.php",{method:"POST",body:s});return(await r.text()).replace("pastebin.com/","pastebin.com/raw/")}catch(e){console.error(e),process.exit(1)}})(o,a));const P={extra_env:x,disk:p/1e9,target_state:"running",cancel_unavail:!0,vm:!1};o.hash?P.template_hash_id=o.hash:o.tag&&(P.image=o.tag,P.runtype=o.runType);const A=await fetch(`${$}/asks/${r.id}`,{method:"PUT",headers:{Authorization:`Bearer ${process.env.VAST_API_KEY}`,Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(P)}),E=await A.json();E.success?console.log(`Instance ${E.new_contract} created!`):console.log("Failed to create instance!"),console.log("\nPress Ctrl-D to stop the instance, or Ctrl-C to destroy it..."),process.stdin.resume(),process.on("SIGQUIT",async()=>{if(!E.new_contract)return console.error("No instance to stop! Exiting..."),process.exit(0);try{await fetch(`${$}/instances/${E.new_contract}`,{method:"PUT",headers:{Authorization:`Bearer ${process.env.VAST_API_KEY}`,"Content-Type":"application/json"},body:JSON.stringify({state:"stopped"})}),console.log(`Instance ${E.new_contract} stopped! Exiting...`),process.exit(0)}catch(e){console.error(e),process.exit(1)}}),process.on("SIGINT",async()=>{if(!E.new_contract)return console.error("No instance to destroy! Exiting..."),process.exit(0);try{await fetch(`${$}/instances/${E.new_contract}`,{headers:{Authorization:`Bearer ${process.env.VAST_API_KEY}`,"Content-Type":"application/json"},method:"DELETE"}),console.log(`Instance ${E.new_contract} destroyed! Exiting...`),process.exit(0)}catch(e){console.error(e),process.exit(1)}})}catch(e){e instanceof l?console.log("User requested cancellation of the provisioning process..."):console.error(e)}};try{const{name:t,version:o,description:n}=await(async()=>(await m.load(S()))?.content)();await e.name(t).version(o).description(n).argument("[template]","Specify template to deploy").option("--min-vram <gb>","Min. amount of GPU VRAM in GB",e=>parseInt(e,10),16).option("--max-hourly-cost <cost>","Max. instance cost in $/hr",e=>parseInt(e,10),1).option("--max-ports <count>","Max. number of ports on machine",e=>parseInt(e,10),1e3).action((e,t)=>P({template:e,...t})).parseAsync()}catch(e){console.error(e),process.exit(1)}
1
+ import{program as e}from"@commander-js/extra-typings";import{existsSync as t}from"node:fs";import{fileURLToPath as o}from"node:url";import{filesize as n}from"filesize";import{sprintf as r}from"sprintf-js";import{resolve as a,join as s,dirname as i}from"node:path";import{readFile as c,readdir as p}from"node:fs/promises";import{ExitPromptError as l}from"@inquirer/core";import m from"@npmcli/package-json";import{formatDistanceToNow as d,fromUnixTime as f}from"date-fns";import{select as h,confirm as u,checkbox as y}from"@inquirer/prompts";import g from"lodash.uniq";import w from"chalk";import{interpolateRgb as _}from"d3-interpolate";const $="https://console.vast.ai/api/v0",x=/rtx\s*5[0-9]{3}/i,v=()=>a(i(o(import.meta.url)),".."),S=e=>e?e.map(e=>` "${e}"`).join("\n"):"",E=async e=>{const t=await fetch(e);return parseInt(t.headers.get("Content-Length")??"0",10)},I=async e=>{const t=new Map,o=await p(e),n=(await Promise.all(o.map(t=>c(s(e,t),"utf-8")))).map(e=>JSON.parse(e));for(let e=0;e<o.length;e++)t.set(o[e],n[e]);return t},T=(e,t)=>{const o=t.reduce((e,t)=>e<t.search.totalHour?e:t.search.totalHour,100),a=t.reduce((e,t)=>e>t.search.totalHour?e:t.search.totalHour,0);return t.filter(e=>!x.test(e.gpu_name)).filter(t=>t.search.totalHour<=(e.maxHourlyCost??1e3)).map(e=>{const t=n(1e6*e.gpu_ram,{exponent:3,round:0,roundingMethod:"floor"}),s=_("#00ff00","#ff0000")((e.search.totalHour-o)/(a-o)).replace("rgb(","").replace(")","").split(",").map(e=>parseInt(e,10)),i=`#${((1<<24)+(s[0]<<16)+(s[1]<<8)+s[2]).toString(16).slice(1)}`;return{name:r("%-6s %-12s %-16s %8s %s",t,e.gpu_name,e.geolocation,`${Math.floor(e.inet_down)} Mbps`,w.bgHex(i)(`$${e.search.totalHour.toFixed(3)}/hr`)),value:e}})},P=async e=>{try{const o=await(async e=>{try{const o=s(v(),"templates");let n;if(e.template)n=s(o,`${e.template}.json`);else{const e=await I(o),t=await h({message:"Please choose a template to deploy.",choices:Array.from(e.entries().map(([e,t])=>({name:t.description?`${t.name} - ${t.description}`:t.name,value:e})))});n=s(o,t)}if(!t(n))throw new Error(`Unable to find template at ${n}!`);return JSON.parse(await c(n,"utf-8"))}catch(e){console.error(e),process.exit(1)}})(e),r=await(async e=>{try{const t=s(v(),"modules");console.log("Reading module JSON from ./modules");const o=await I(t);console.log("Fetching file sizes...");const r=Array.from(await Promise.all(o.entries().map(async([,t])=>{if(t.template!==e.name)return[];t.fileSizes=new Map,t.totalSize=0;for(const[,e]of Object.entries(t.files))if(e)for(const o of e){const e=await E(o);t.fileSizes.set(o,e),t.totalSize+=e}return[{name:`${t.name} (${n(t.totalSize)})`,value:t}]}))).flat();return r.length?await y({loop:!1,message:"Please choose the modules you would like to include.",choices:r}):[]}catch(e){console.error(e),process.exit(1)}})(o),a=await(async e=>{try{const t=await fetch(`${$}/search/asks`,{method:"PUT",body:JSON.stringify({q:{type:"on-demand",verified:{eq:!0},rentable:{eq:!0},rented:{eq:!1},num_gpus:{eq:1},gpu_ram:{gte:1024*(e.minVram??16)},inet_down:{gte:1e3},direct_port_count:{lte:e.maxPorts},limit:25,order:[["dph_total","asc"],["inet_down","asc"]]}}),headers:{Accept:"application/json","Content-Type":"application/json"},redirect:"follow"}),{offers:o}=await t.json();return o}catch(e){console.error(e),process.exit(1)}})(e),i=await h({message:"Choose the instance you would like to request.",choices:T(e,a),loop:!1});let p=o.size;if(r.length){const e=[];for(const t of r)for(const[o,n]of t.fileSizes.entries())e.includes(o)||(e.push(o),p+=n)}p/=1e9,p=Math.ceil(p),p*=1e9;const l=i.search.diskHour*(p/1e10),m=`$${(i.search.gpuCostPerHour+l).toFixed(3)}/hr`,w=`$${l.toFixed(3)}/hr`,_=`\nTemplate: ${o.name}\nModules:\n${r.map(e=>` * ${e.name} (${n(e.totalSize)})`).join("\n")}\nDisk Size: ${n(p)}\n\nAre you SURE you want create the instance?\n\nIt will be automatically destroyed in ${d(f(i.end_date))}.\n\nYou will be charged ${m} while it is running and ${w} while it is stopped!\n\nIt is YOUR responsibility to make sure that it has been stopped or destroyed correctly!\n`;if(!await u({message:_,default:!1}))return console.log("Exiting because user declined to deploy.");console.log(`Deploying ${o.name} to instance ${i}...`);const x={...o.environment};o.script&&(x.PROVISIONER_SCRIPT=await(async(e,o)=>{try{if(!e.script)throw new Error("No template script!");const n=s(v(),"scripts",e.script);if(!t(n))throw new Error(`Could not find script at ${n}!`);let r=await c(n,"utf-8");if(e.fileTypes.length&&o.length){const t=Object.fromEntries(e.fileTypes.map(e=>[e,[]]));for(const n of o)for(const o of e.fileTypes)t[o]&&(t[o]=g([...t[o],...n.files[o]??[]]));for(const o of e.fileTypes)t[o]?.length&&(r=r.replace(`{{ ${o.toUpperCase()} }}`,S(t[o])))}const a=new FormData;if(!process.env.PASTEBIN_API_KEY)throw new Error("Must provide PASTEBIN_API_KEY env var!");a.append("api_dev_key",process.env.PASTEBIN_API_KEY),a.append("api_option","paste"),a.append("api_paste_code",r),a.append("api_paste_private","1"),a.append("api_paste_format","bash"),a.append("api_paste_name","provision.sh"),a.append("api_paste_expire_date","10M");const i=await fetch("https://pastebin.com/api/api_post.php",{method:"POST",body:a});return(await i.text()).replace("pastebin.com/","pastebin.com/raw/")}catch(e){console.error(e),process.exit(1)}})(o,r));const P={extra_env:x,disk:p/1e9,target_state:"running",cancel_unavail:!0,vm:!1};o.hash?P.template_hash_id=o.hash:o.tag&&(P.image=o.tag,P.runtype=o.runType);const b=await fetch(`${$}/asks/${i.id}`,{method:"PUT",headers:{Authorization:`Bearer ${process.env.VAST_API_KEY}`,Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(P)}),A=await b.json();A.success?console.log(`Instance ${A.new_contract} created!`):console.log("Failed to create instance!"),console.log("\nPress Ctrl-D to stop the instance, or Ctrl-C to destroy it..."),process.stdin.resume(),process.on("SIGQUIT",async()=>{if(!A.new_contract)return console.error("No instance to stop! Exiting..."),process.exit(0);try{await fetch(`${$}/instances/${A.new_contract}`,{method:"PUT",headers:{Authorization:`Bearer ${process.env.VAST_API_KEY}`,"Content-Type":"application/json"},body:JSON.stringify({state:"stopped"})}),console.log(`Instance ${A.new_contract} stopped! Exiting...`),process.exit(0)}catch(e){console.error(e),process.exit(1)}}),process.on("SIGINT",async()=>{if(!A.new_contract)return console.error("No instance to destroy! Exiting..."),process.exit(0);try{await fetch(`${$}/instances/${A.new_contract}`,{headers:{Authorization:`Bearer ${process.env.VAST_API_KEY}`,"Content-Type":"application/json"},method:"DELETE"}),console.log(`Instance ${A.new_contract} destroyed! Exiting...`),process.exit(0)}catch(e){console.error(e),process.exit(1)}})}catch(e){e instanceof l?console.log("User requested cancellation of the provisioning process..."):console.error(e)}};try{process.loadEnvFile()}catch(e){e instanceof Error&&console.error(e.message)}try{const{name:t,version:o,description:n}=await(async()=>(await m.load(v()))?.content)();await e.name(t??"vast-ai-provisioner").version(o??"0.1.0").description(n??"").argument("[template]","Specify template to deploy").option("--min-vram <gb>","Min. amount of GPU VRAM in GB",e=>parseInt(e,10),16).option("--max-hourly-cost <cost>","Max. instance cost in $/hr",e=>parseInt(e,10),1).option("--max-ports <count>","Max. number of ports on machine",e=>parseInt(e,10),1e3).action((e,t)=>P({template:e,...t})).parseAsync()}catch(e){console.error(e),process.exit(1)}
@@ -0,0 +1 @@
1
+ export {};
@@ -47,8 +47,8 @@ export type CreateInstanceResponse = {
47
47
  success: boolean;
48
48
  };
49
49
  export type ProvisionOptions = {
50
- maxHourlyCost?: number;
51
- maxPorts?: number;
52
- minVram?: number;
50
+ maxHourlyCost: number;
51
+ maxPorts: number;
52
+ minVram: number;
53
53
  template?: string;
54
54
  };
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/ayan4m1/vast-ai-provisioner/main/module.schema.json",
3
+ "name": "Flux 2.D",
4
+ "template": "ComfyUI",
5
+ "files": {
6
+ "diffusion_models": [
7
+ "https://huggingface.co/gguf-org/flux2-dev-gguf/resolve/main/flux2-dev-iq4_xs.gguf"
8
+ ],
9
+ "text_encoder_models": [
10
+ "https://huggingface.co/gguf-org/flux2-dev-gguf/resolve/main/cow-mistral3-small-iq4_xs.gguf"
11
+ ],
12
+ "vae_models": [
13
+ "https://huggingface.co/gguf-org/flux2-dev-gguf/resolve/main/pig_flux2_vae_fp32-f16.gguf"
14
+ ],
15
+ "nodes": ["https://github.com/city96/ComfyUI-GGUF"],
16
+ "workflows": [
17
+ "https://raw.githubusercontent.com/ayan4m1/vast-ai-provisioner/main/workflows/flux2-gguf.json"
18
+ ]
19
+ }
20
+ }
package/package.json CHANGED
@@ -10,49 +10,48 @@
10
10
  }
11
11
  },
12
12
  "dependencies": {
13
- "@commander-js/extra-typings": "^14.0.0",
14
- "@inquirer/core": "^10.1.14",
15
- "@inquirer/prompts": "^7.6.0",
16
- "@npmcli/package-json": "^6.2.0",
17
- "chalk": "^5.4.1",
18
- "commander": "^14.0.0",
13
+ "@commander-js/extra-typings": "^15.0.0",
14
+ "@inquirer/core": "^12.0.4",
15
+ "@inquirer/prompts": "^8.7.3",
16
+ "@npmcli/package-json": "^8.0.0",
17
+ "chalk": "^6.0.1",
18
+ "commander": "^15.0.0",
19
19
  "d3-interpolate": "^3.0.1",
20
- "date-fns": "^4.1.0",
21
- "dotenv": "^17.2.0",
22
- "filesize": "^11.0.0",
20
+ "date-fns": "^4.4.0",
21
+ "filesize": "^11.0.25",
23
22
  "lodash.uniq": "^4.5.0",
24
23
  "sprintf-js": "^1.1.3"
25
24
  },
26
25
  "description": "Deploy a ComfyUI instance to Vast.ai with one click",
27
26
  "devDependencies": {
28
- "@commitlint/config-conventional": "^19.8.1",
29
- "@commitlint/cz-commitlint": "^19.8.1",
30
- "@eslint/js": "^9.30.1",
31
- "@rollup/plugin-terser": "^0.4.4",
32
- "@rollup/plugin-typescript": "^12.1.4",
27
+ "@commitlint/config-conventional": "^21.2.3",
28
+ "@commitlint/cz-commitlint": "^21.2.3",
29
+ "@eslint/js": "9.39.5",
30
+ "@rollup/plugin-terser": "^1.0.0",
31
+ "@rollup/plugin-typescript": "^12.3.0",
33
32
  "@types/d3-interpolate": "^3",
34
33
  "@types/eslint__js": "^8.42.3",
35
34
  "@types/lodash.uniq": "^4",
36
- "@types/node": "24.0.10",
35
+ "@types/node": "26.6.4",
37
36
  "@types/npmcli__package-json": "^4.0.4",
38
37
  "@types/sprintf-js": "^1",
39
- "commitizen": "^4.3.1",
40
- "commitlint": "^19.8.1",
41
- "eslint": "^9.30.1",
42
- "eslint-config-prettier": "^10.1.5",
43
- "eslint-import-resolver-typescript": "^4.4.4",
44
- "eslint-plugin-import-x": "^4.16.1",
45
- "eslint-plugin-prettier": "^5.5.1",
38
+ "commitizen": "^4.3.2",
39
+ "commitlint": "^21.2.3",
40
+ "eslint": "^9.39.1",
41
+ "eslint-config-prettier": "^10.1.8",
42
+ "eslint-import-resolver-typescript": "^4.4.5",
43
+ "eslint-plugin-import-x": "^4.17.1",
44
+ "eslint-plugin-prettier": "^5.5.6",
46
45
  "husky": "^9.1.7",
47
46
  "inquirer": "9",
48
- "lint-staged": "^16.1.2",
49
- "prettier": "^3.6.2",
50
- "rollup": "^4.44.2",
51
- "rollup-plugin-auto-external": "^2.0.0",
52
- "semantic-release": "^24.2.7",
47
+ "lint-staged": "^17.6.0",
48
+ "prettier": "^3.9.9",
49
+ "rollup": "^4.64.2",
50
+ "rollup-plugin-node-externals": "^9.0.1",
51
+ "semantic-release": "^25.0.9",
53
52
  "tslib": "^2.8.1",
54
- "typescript": "^5.8.3",
55
- "typescript-eslint": "^8.35.1"
53
+ "typescript": "^6.0.3",
54
+ "typescript-eslint": "^8.71.1"
56
55
  },
57
56
  "engines": {
58
57
  "node": ">=22"
@@ -68,7 +67,7 @@
68
67
  "main": "n/a",
69
68
  "module": "lib/index.js",
70
69
  "name": "vast-ai-provisioner",
71
- "packageManager": "yarn@4.9.4",
70
+ "packageManager": "yarn@4.11.0",
72
71
  "repository": {
73
72
  "type": "git",
74
73
  "url": "git+https://github.com/ayan4m1/vast-ai-provisioner.git"
@@ -82,5 +81,5 @@
82
81
  },
83
82
  "type": "module",
84
83
  "types": "lib/index.d.ts",
85
- "version": "1.0.1"
84
+ "version": "1.1.0"
86
85
  }
package/lib/index.d.ts DELETED
@@ -1 +0,0 @@
1
- import 'dotenv/config';
File without changes